Skip to content

Commit

Permalink
Add events package
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Aug 30, 2023
1 parent 797048a commit 9869949
Show file tree
Hide file tree
Showing 60 changed files with 2,023 additions and 2,035 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ The common packages provide shared code for the project:

- [@casimir/aws](common/aws): AWS helpers
- [@casimir/data](common/data): data schemas and operational workflows
- [@casimir/helpers](common/helpers): general utilities
- [@casimir/speculos](common/speculos): Ledger emulator helpers
- [@casimir/ssv](common/ssv): SSV helpers
- [@casimir/types](common/types): shared types
Expand Down
3 changes: 3 additions & 0 deletions common/aws/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export async function getSecret(id: string) {
}
)
)
if (!SecretString) {
throw new Error(`No secret found for ${id}`)
}
return SecretString
}

Expand Down
2 changes: 1 addition & 1 deletion common/data/src/providers/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as glue from '@aws-cdk/aws-glue-alpha'
import { JsonSchema } from '../interfaces/JsonSchema'
import { snakeCase } from '@casimir/helpers'
import { snakeCase } from '@casimir/format'

export type JsonType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null'
export type GlueType = glue.Type
Expand Down
1 change: 1 addition & 0 deletions common/events/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
15 changes: 15 additions & 0 deletions common/events/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@casimir/events",
"private": "true",
"main": "src/index.ts",
"scripts": {
"build": "echo '@casimir/events build not specified. Disregard this warning and any listed errors above if @casimir/events is not needed for the current project build.' && exit 0",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"ethers": "^5.7.2"
},
"devDependencies": {
"@types/node": "^17.0.38"
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { ethers } from 'ethers'
import { CasimirManager } from '@casimir/ethereum/build/@types'
import ICasimirManagerAbi from '@casimir/ethereum/build/abi/ICasimirManager.json'
import { GetEventsIterableInput } from '../interfaces/GetEventsIterableInput'

export function getEventsIterable(input: GetEventsIterableInput) {
export function getEventsIterable(input: {
ethereumUrl?: string
provider?: ethers.providers.JsonRpcProvider
managerAddress: string
events: string[]
}) {
const events = input.events
let provider: ethers.providers.JsonRpcProvider
if (input.provider) {
provider = input.provider
} else {
provider = new ethers.providers.JsonRpcProvider(input.ethereumUrl)
}
const provider = input.provider || new ethers.providers.JsonRpcProvider(input.ethereumUrl)
const manager = new ethers.Contract(input.managerAddress, ICasimirManagerAbi, provider) as ethers.Contract & CasimirManager

return (async function*() {
Expand Down
19 changes: 19 additions & 0 deletions common/events/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ESNext",
"strict": true,
"preserveConstEnums": true,
"noEmit": true,
"sourceMap": false,
"module": "CommonJS",
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"resolveJsonModule": true
},
"include": [
"./src/*"
]
}
1 change: 1 addition & 0 deletions common/fetch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
12 changes: 12 additions & 0 deletions common/fetch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@casimir/fetch",
"private": true,
"main": "src/index.ts",
"scripts": {
"build": "echo '@casimir/fetch build not specified. Disregard this warning and any listed errors above if @casimir/fetch is not needed for the current project build.' && exit 0",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@types/node": "^17.0.38"
}
}
28 changes: 28 additions & 0 deletions common/fetch/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Retry a fetch request
* @param {RequestInfo} info - URL string or request object
* @param {RequestInit} [init] - Request init options
* @param {number | undefined} retriesLeft - Number of retries left (default: 25)
* @returns {Promise<Response>} Response
* @example
* const response = await fetchRetry('https://example.com')
*/
export async function fetchRetry(info: RequestInfo, init?: RequestInit, retriesLeft: number | undefined = 25): Promise<Response> {
if (retriesLeft === 0) {
throw new Error('API request failed after maximum retries')
}

try {
const response = await fetch(info, init)
if (response.status !== 200) {
await new Promise(resolve => setTimeout(resolve, 5000))
console.log('Retrying fetch request to', info, init)
return await fetchRetry(info, init || {}, retriesLeft - 1)
}
return response
} catch (error) {
await new Promise(resolve => setTimeout(resolve, 5000))
console.log('Retrying fetch request to', info, init)
return await fetchRetry(info, init || {}, retriesLeft - 1)
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions common/format/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
12 changes: 12 additions & 0 deletions common/format/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@casimir/format",
"private": true,
"main": "src/index.ts",
"scripts": {
"build": "echo '@casimir/format build not specified. Disregard this warning and any listed errors above if @casimir/format is not needed for the current project build.' && exit 0",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@types/node": "^17.0.38"
}
}
55 changes: 55 additions & 0 deletions common/format/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Convert any string to camelCase.
* @param string - The input string
* @returns A camelCase string from the input string
*/
export function camelCase(string: string): string {
const words = string.split(/[\s_-]+/).map(word => {
return word.replace(/\w+/g, (word) => {
return word[0].toUpperCase() + word.slice(1).toLowerCase()
})
})
const result = words.join('')
return result[0].toLowerCase() + result.slice(1)
}

/**
* Convert any string to PascalCase
*
* @param string - The input string
* @returns A PascalCase string from the input string
*
*/
export function pascalCase(string: string): string {
const words = string.split(/[\s_-]+/).map(word => {
return word.replace(/\w+/g, (word) => {
return word[0].toUpperCase() + word.slice(1).toLowerCase()
})
})
const result = words.join('')
return result
}

/**
* Convert any string to snake_case.
* @param string - The input string
* @returns A snake_case string from the input string
*/
export function snakeCase(string: string): string {
return string.replace(/\W+/g, ' ')
.split(/ |\B(?=[A-Z])/)
.map(word => word.toLowerCase())
.join('_')
}

/**
* Convert any string to kebab-case.
* @param string - The input string
* @returns A kebab-case string from the input string
*/
export function kebabCase(string: string): string {
return string.replace(/\W+/g, ' ')
.split(/ |\B(?=[A-Z])/)
.map(word => word.toLowerCase())
.join('-')
}
21 changes: 21 additions & 0 deletions common/format/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ESNext",
"strict": true,
"preserveConstEnums": true,
"noEmit": true,
"sourceMap": false,
"module": "CommonJS",
"moduleResolution": "Node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true
},
"exclude": [
"node_modules"
],
"include": [
"./src/*"
]
}
2 changes: 0 additions & 2 deletions common/helpers/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions common/helpers/package.json

This file was deleted.

Loading

0 comments on commit 9869949

Please sign in to comment.