Skip to content

Commit

Permalink
feat(all): further split packages (stephenh#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 committed Dec 31, 2022
1 parent 033d015 commit 0594440
Show file tree
Hide file tree
Showing 63 changed files with 3,370 additions and 3,312 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# command: yarn install
# name: Yarn Install
- run:
command: rm -rf lib && yarn gen && yarn test || yarn test # TODO remove this hack, understand why test will fail in first run
command: yarn build_all && yarn gen && yarn test || yarn test # TODO remove this hack, understand why test will fail in first run
name: Test SDK
working_directory: packages/sdk
# - run:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:

- name: Create the docs directory locally in CI
run: yarn gen && yarn docs
working-directory: sdk
working-directory: packages/sdk

- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
branch: gh-pages
folder: sdk/docs
folder: packages/sdk/docs
6 changes: 6 additions & 0 deletions .ls-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ ignore:
- examples
- packages/sdk/src/tests/abis
- packages/sdk/src/tests/types
- packages/base/lib
- packages/base/node_modules
- packages/protos/lib
- packages/protos/node_modules
- packages/runtime/lib
- packages/runtime/node_modules
14 changes: 7 additions & 7 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
write_source_files(
name = "write_gen",
files = {
"packages/sdk/processor.proto": "//processor/protos:proto_file",
"packages/sdk/src/gen/chainquery/protos/chainquery.ts": "//chainquery/protos:chainquery_ts_proto",
"packages/sdk/src/gen/processor/protos/processor.ts": "//processor/protos:processor_ts_proto",
"packages/sdk/src/gen/service/price/protos/price.ts": "//service/price/protos:protos_ts_proto",
"packages/sdk/src/gen/google/protobuf/empty.ts": "//processor/protos:empty_ts_proto",
"packages/sdk/src/gen/google/protobuf/struct.ts": "//processor/protos:struct_ts_proto",
"packages/sdk/src/gen/google/protobuf/timestamp.ts": "//processor/protos:timestamp_ts_proto",
"packages/protos/processor.proto": "//processor/protos:proto_file",
"packages/protos/src/gen/chainquery/protos/chainquery.ts": "//chainquery/protos:chainquery_ts_proto",
"packages/protos/src/gen/processor/protos/processor.ts": "//processor/protos:processor_ts_proto",
"packages/protos/src/gen/service/price/protos/price.ts": "//service/price/protos:protos_ts_proto",
"packages/protos/src/gen/google/protobuf/empty.ts": "//processor/protos:empty_ts_proto",
"packages/protos/src/gen/google/protobuf/struct.ts": "//processor/protos:struct_ts_proto",
"packages/protos/src/gen/google/protobuf/timestamp.ts": "//processor/protos:timestamp_ts_proto",

"packages/runtime/processor_full.proto": "//processor/protos:proto_full_file",
"packages/runtime/src/gen/processor/protos/processor.ts": "//processor/protos:processor_ts_proto",
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@
"format": "prettier --write .",
"lint": "ls-lint && eslint .",
"postinstall": "git config --local include.path ../.github/.gitconfig && git config core.hooksPath .github/.githooks"
},
"engines": {
"node": ">=16"
}
}
12 changes: 6 additions & 6 deletions packages/base/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "@sentio/base",
"license": "Apache-2.0",
"version": "1.0.0-rc.5",
"version": "1.0.0",
"scripts": {
"compile": "tsc -p .",
"build": "yarn compile",
"build_all": "yarn lerna run --scope=@sentio/base build --include-dependencies",
"test": "jest"
},
"dependencies": {
"@sentio/protos": "^1.0.0"
},
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"files": [
"{lib,src}",
"!{lib,src}/tests",
"!**/*.test.{js,ts}"
],
"engines": {
"node": ">=16"
},
"gitHead": "8bec43cdc9e778d66a4154bc1be1f9276b680408"
]
}
3 changes: 2 additions & 1 deletion packages/base/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export {}
export * from './plugin'
export * from './state'
2 changes: 1 addition & 1 deletion packages/sdk/src/plugin.ts → packages/base/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from './gen'
import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos'

export interface Plugin {
name: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { assert } from 'chai'
import { MapStateStorage } from './state-storage'
import { ProcessorState } from './processor-state'
import { State, MapStateStorage } from './state'

describe('state storage tests', () => {
global.PROCESSOR_STATE = new ProcessorState()
State.reset()

test('test labels', async () => {
class TestState extends MapStateStorage<any> {
Expand All @@ -18,7 +17,7 @@ describe('state storage tests', () => {
TestState.INSTANCE.getOrSetValue('k2', 'v2')

assert(TestState.INSTANCE.getValues().length === 2)
assert(global.PROCESSOR_STATE.stateMap.size === 1)
assert(global.PROCESSOR_STATE.stateMap.keys().next().value === 'TestState')
assert(State.INSTANCE.stateMap.size === 1)
assert(State.INSTANCE.stateMap.keys().next().value === 'TestState')
})
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
export class State {
stateMap = new Map<string, any>()

static INSTANCE = new State()

static reset() {
State.INSTANCE = new State()
}
}

export abstract class StateStorage<T> {
// TODO learn how to define single instance for all subclasses

Expand All @@ -12,10 +22,10 @@ export abstract class StateStorage<T> {
}

getOrRegister(): T {
let metricState: T = global.PROCESSOR_STATE.stateMap.get(this.key())
let metricState: T = State.INSTANCE.stateMap.get(this.key())
if (!metricState) {
metricState = this.initValue()
global.PROCESSOR_STATE.stateMap.set(this.key(), metricState)
State.INSTANCE.stateMap.set(this.key(), metricState)
}
return metricState
}
Expand Down
3 changes: 0 additions & 3 deletions packages/base/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"inlineSources": true,
"rootDir": "./src",
"baseUrl": "./src",
"paths": {
"@sentio/sdk": ["."]
},
"outDir": "lib"
},
"exclude": ["lib"]
Expand Down
22 changes: 22 additions & 0 deletions packages/protos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@sentio/protos",
"license": "Apache-2.0",
"version": "1.0.0",
"scripts": {
"compile": "tsc -p .",
"clean": "tsc --build --clean",
"build": "yarn compile"
},
"dependencies": {
"google-protobuf": "^3.15.8",
"nice-grpc": "^2.0.0"
},
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"files": [
"{lib,src}",
"!{lib,src}/tests",
"!**/*.test.{js,ts}"
]
}
15 changes: 15 additions & 0 deletions packages/protos/src/builtin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Long from 'long'

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined

export type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>
Loading

0 comments on commit 0594440

Please sign in to comment.