@sentio/runtime 2.0.0-rc.1 → 2.0.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/chain-config.js +1 -2
- package/lib/decode-benchmark.js +3 -6
- package/lib/decode-benchmark.js.map +1 -1
- package/lib/endpoints.js +1 -5
- package/lib/endpoints.js.map +1 -1
- package/lib/full-service.d.ts +7 -7
- package/lib/full-service.js +24 -22
- package/lib/full-service.js.map +1 -1
- package/lib/gen/google/protobuf/empty.d.ts +1 -1
- package/lib/gen/google/protobuf/empty.js +4 -8
- package/lib/gen/google/protobuf/empty.js.map +1 -1
- package/lib/gen/google/protobuf/struct.d.ts +1 -1
- package/lib/gen/google/protobuf/struct.js +27 -33
- package/lib/gen/google/protobuf/struct.js.map +1 -1
- package/lib/gen/google/protobuf/timestamp.d.ts +1 -1
- package/lib/gen/google/protobuf/timestamp.js +8 -12
- package/lib/gen/google/protobuf/timestamp.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +2 -5
- package/lib/gen/processor/protos/processor.js +570 -598
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.js +6 -9
- package/lib/index.js.map +1 -1
- package/lib/plugin.js +4 -9
- package/lib/plugin.js.map +1 -1
- package/lib/processor-runner.js +34 -32
- package/lib/processor-runner.js.map +1 -1
- package/lib/service.d.ts +2 -3
- package/lib/service.js +32 -38
- package/lib/service.js.map +1 -1
- package/lib/service.test.js.map +1 -1
- package/lib/state-storage.test.js.map +1 -1
- package/lib/state.js +4 -11
- package/lib/state.js.map +1 -1
- package/lib/utils.js +5 -10
- package/lib/utils.js.map +1 -1
- package/package.json +12 -10
- package/src/full-service.ts +23 -14
- package/src/gen/google/protobuf/empty.ts +1 -1
- package/src/gen/google/protobuf/struct.ts +1 -1
- package/src/gen/google/protobuf/timestamp.ts +1 -1
- package/src/gen/processor/protos/processor.ts +6 -18
- package/src/index.ts +6 -6
- package/src/processor-runner.ts +15 -9
- package/src/service.ts +20 -26
- package/lib/loader.d.ts +0 -5
- package/lib/loader.js +0 -30
- package/lib/loader.js.map +0 -1
- package/src/loader.ts +0 -24
package/package.json
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/runtime",
|
3
3
|
"license": "Apache-2.0",
|
4
|
-
"version": "2.0.0-rc.
|
4
|
+
"version": "2.0.0-rc.11",
|
5
5
|
"scripts": {
|
6
6
|
"compile": "tsc -p .",
|
7
7
|
"build": "yarn compile",
|
8
8
|
"build_all": "yarn lerna run --scope=@sentio/runtime build --include-dependencies",
|
9
|
-
"test": "jest",
|
10
|
-
"run": "ts-node --files src/processor-runner.ts --log-format=json",
|
11
|
-
"run-benchmark": "ts-node --files src/decode-benchmark.ts"
|
9
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules yarn jest",
|
10
|
+
"run": "ts-node-esm --files src/processor-runner.ts --log-format=json",
|
11
|
+
"run-benchmark": "ts-node-esm --files src/decode-benchmark.ts",
|
12
|
+
"start_ts": "ts-node-esm --files ./src/processor-runner.ts --log-format=json ../../../examples/x2y2/src/processor.ts",
|
13
|
+
"start_js": "ts-node-esm --files ./src/processor-runner.ts ../../../examples/x2y2/dist/lib.js"
|
12
14
|
},
|
13
15
|
"dependencies": {
|
14
|
-
"@sentio/protos": "^2.0.0-rc.
|
16
|
+
"@sentio/protos": "^2.0.0-rc.11",
|
15
17
|
"command-line-args": "^5.2.1",
|
16
18
|
"command-line-usage": "^6.1.3",
|
17
19
|
"fs-extra": "^11.0.0",
|
@@ -19,7 +21,6 @@
|
|
19
21
|
"nice-grpc": "^2.0.0",
|
20
22
|
"nice-grpc-client-middleware-retry": "^2.0.1",
|
21
23
|
"nice-grpc-error-details": "^0.1.4",
|
22
|
-
"p-queue": "^6.6.2",
|
23
24
|
"winston": "^3.8.2"
|
24
25
|
},
|
25
26
|
"devDependencies": {
|
@@ -34,13 +35,14 @@
|
|
34
35
|
"bin": {
|
35
36
|
"processor-runner": "./lib/processor-runner.js"
|
36
37
|
},
|
37
|
-
"
|
38
|
-
"
|
39
|
-
|
38
|
+
"type": "module",
|
39
|
+
"exports": {
|
40
|
+
".": "./lib/index.js"
|
41
|
+
},
|
40
42
|
"files": [
|
41
43
|
"{lib,src}",
|
42
44
|
"!{lib,src}/tests",
|
43
45
|
"!**/*.test.{js,ts}"
|
44
46
|
],
|
45
|
-
"gitHead": "
|
47
|
+
"gitHead": "0392ac911d914510f38cb4161f8eeceea2042ecf"
|
46
48
|
}
|
package/src/full-service.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
import { CallContext } from 'nice-grpc'
|
2
|
+
import { createRequire } from 'module'
|
3
|
+
const require = createRequire(import.meta.url)
|
2
4
|
|
3
5
|
// Different than the simple one which
|
4
6
|
import {
|
@@ -8,22 +10,29 @@ import {
|
|
8
10
|
ProcessConfigRequest,
|
9
11
|
ProcessorServiceImplementation,
|
10
12
|
StartRequest,
|
11
|
-
} from './gen/processor/protos/processor'
|
13
|
+
} from './gen/processor/protos/processor.js'
|
12
14
|
|
13
|
-
import { Empty } from '@sentio/protos
|
15
|
+
import { Empty } from '@sentio/protos'
|
14
16
|
import fs from 'fs-extra'
|
15
17
|
import * as assert from 'assert'
|
18
|
+
import path from 'path'
|
19
|
+
|
20
|
+
function locatePackageJson(pkgId: string) {
|
21
|
+
const m = require.resolve(pkgId)
|
22
|
+
|
23
|
+
let dir = path.dirname(m)
|
24
|
+
while (!fs.existsSync(path.join(dir, 'package.json'))) {
|
25
|
+
dir = path.dirname(dir)
|
26
|
+
}
|
27
|
+
const content = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')
|
28
|
+
return JSON.parse(content)
|
29
|
+
}
|
16
30
|
|
17
31
|
export class FullProcessorServiceImpl implements ProcessorServiceImplementation {
|
18
32
|
constructor(instance: ProcessorServiceImplementation) {
|
19
33
|
this.instance = instance
|
20
|
-
const
|
21
|
-
const
|
22
|
-
const sdkPackageJson = JSON.parse(sdkPackageJsonContent)
|
23
|
-
|
24
|
-
const runtimePackageJsonPath = require.resolve('@sentio/runtime/package.json')
|
25
|
-
const runtimePackageJsonContent = fs.readFileSync(runtimePackageJsonPath, 'utf-8')
|
26
|
-
const runtimePackageJson = JSON.parse(runtimePackageJsonContent)
|
34
|
+
const sdkPackageJson = locatePackageJson('@sentio/sdk')
|
35
|
+
const runtimePackageJson = locatePackageJson('@sentio/runtime')
|
27
36
|
|
28
37
|
console.log('Runtime version:', runtimePackageJson.version, 'SDK version:', sdkPackageJson.version)
|
29
38
|
|
@@ -62,11 +71,11 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
|
|
62
71
|
switch (dataBinding.handlerType) {
|
63
72
|
case HandlerType.APT_EVENT:
|
64
73
|
if (dataBinding.data?.aptEvent) {
|
65
|
-
const aptEvent = dataBinding.data.aptEvent
|
66
|
-
if (aptEvent.event && this.sdkMinorVersion < 40) {
|
67
|
-
|
68
|
-
|
69
|
-
}
|
74
|
+
// const aptEvent = dataBinding.data.aptEvent
|
75
|
+
// if (aptEvent.event && this.sdkMinorVersion < 40) {
|
76
|
+
// assert.ok(aptEvent.transaction, 'No Transaction')
|
77
|
+
// aptEvent.transaction.events = [aptEvent.event]
|
78
|
+
// }
|
70
79
|
}
|
71
80
|
break
|
72
81
|
case HandlerType.UNKNOWN:
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/* eslint-disable */
|
2
2
|
import Long from "long";
|
3
3
|
import type { CallContext, CallOptions } from "nice-grpc-common";
|
4
|
-
import _m0 from "protobufjs/minimal";
|
5
|
-
import { Empty } from "../../google/protobuf/empty";
|
6
|
-
import { Struct } from "../../google/protobuf/struct";
|
7
|
-
import { Timestamp } from "../../google/protobuf/timestamp";
|
4
|
+
import _m0 from "protobufjs/minimal.js";
|
5
|
+
import { Empty } from "../../google/protobuf/empty.js";
|
6
|
+
import { Struct } from "../../google/protobuf/struct.js";
|
7
|
+
import { Timestamp } from "../../google/protobuf/timestamp.js";
|
8
8
|
|
9
9
|
export enum MetricType {
|
10
10
|
UNKNOWN_TYPE = 0,
|
@@ -533,7 +533,6 @@ export interface Data_SolInstruction {
|
|
533
533
|
}
|
534
534
|
|
535
535
|
export interface Data_AptEvent {
|
536
|
-
event: { [key: string]: any } | undefined;
|
537
536
|
transaction: { [key: string]: any } | undefined;
|
538
537
|
}
|
539
538
|
|
@@ -3677,14 +3676,11 @@ export const Data_SolInstruction = {
|
|
3677
3676
|
};
|
3678
3677
|
|
3679
3678
|
function createBaseData_AptEvent(): Data_AptEvent {
|
3680
|
-
return {
|
3679
|
+
return { transaction: undefined };
|
3681
3680
|
}
|
3682
3681
|
|
3683
3682
|
export const Data_AptEvent = {
|
3684
3683
|
encode(message: Data_AptEvent, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
|
3685
|
-
if (message.event !== undefined) {
|
3686
|
-
Struct.encode(Struct.wrap(message.event), writer.uint32(10).fork()).ldelim();
|
3687
|
-
}
|
3688
3684
|
if (message.transaction !== undefined) {
|
3689
3685
|
Struct.encode(Struct.wrap(message.transaction), writer.uint32(18).fork()).ldelim();
|
3690
3686
|
}
|
@@ -3698,9 +3694,6 @@ export const Data_AptEvent = {
|
|
3698
3694
|
while (reader.pos < end) {
|
3699
3695
|
const tag = reader.uint32();
|
3700
3696
|
switch (tag >>> 3) {
|
3701
|
-
case 1:
|
3702
|
-
message.event = Struct.unwrap(Struct.decode(reader, reader.uint32()));
|
3703
|
-
break;
|
3704
3697
|
case 2:
|
3705
3698
|
message.transaction = Struct.unwrap(Struct.decode(reader, reader.uint32()));
|
3706
3699
|
break;
|
@@ -3713,22 +3706,17 @@ export const Data_AptEvent = {
|
|
3713
3706
|
},
|
3714
3707
|
|
3715
3708
|
fromJSON(object: any): Data_AptEvent {
|
3716
|
-
return {
|
3717
|
-
event: isObject(object.event) ? object.event : undefined,
|
3718
|
-
transaction: isObject(object.transaction) ? object.transaction : undefined,
|
3719
|
-
};
|
3709
|
+
return { transaction: isObject(object.transaction) ? object.transaction : undefined };
|
3720
3710
|
},
|
3721
3711
|
|
3722
3712
|
toJSON(message: Data_AptEvent): unknown {
|
3723
3713
|
const obj: any = {};
|
3724
|
-
message.event !== undefined && (obj.event = message.event);
|
3725
3714
|
message.transaction !== undefined && (obj.transaction = message.transaction);
|
3726
3715
|
return obj;
|
3727
3716
|
},
|
3728
3717
|
|
3729
3718
|
fromPartial(object: DeepPartial<Data_AptEvent>): Data_AptEvent {
|
3730
3719
|
const message = createBaseData_AptEvent();
|
3731
|
-
message.event = object.event ?? undefined;
|
3732
3720
|
message.transaction = object.transaction ?? undefined;
|
3733
3721
|
return message;
|
3734
3722
|
},
|
package/src/index.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export * from './plugin'
|
2
|
-
export * from './state'
|
3
|
-
export * from './utils'
|
4
|
-
export * from './endpoints'
|
5
|
-
export * from './chain-config'
|
6
|
-
export * from './service'
|
1
|
+
export * from './plugin.js'
|
2
|
+
export * from './state.js'
|
3
|
+
export * from './utils.js'
|
4
|
+
export * from './endpoints.js'
|
5
|
+
export * from './chain-config.js'
|
6
|
+
export * from './service.js'
|
package/src/processor-runner.ts
CHANGED
@@ -7,16 +7,15 @@ import * as util from 'util'
|
|
7
7
|
import commandLineArgs from 'command-line-args'
|
8
8
|
import { createServer } from 'nice-grpc'
|
9
9
|
import { createLogger, transports, format } from 'winston'
|
10
|
-
import {
|
10
|
+
import { compressionAlgorithms } from '@grpc/grpc-js'
|
11
11
|
|
12
12
|
import { ProcessorDefinition } from '@sentio/protos'
|
13
|
-
import { ProcessorServiceImpl } from './service'
|
14
|
-
import { State } from './state'
|
15
|
-
import { Endpoints } from './endpoints'
|
13
|
+
import { ProcessorServiceImpl } from './service.js'
|
14
|
+
import { State } from './state.js'
|
15
|
+
import { Endpoints } from './endpoints.js'
|
16
16
|
|
17
|
-
import {
|
18
|
-
import {
|
19
|
-
import { ChainConfig } from './chain-config'
|
17
|
+
import { FullProcessorServiceImpl } from './full-service.js'
|
18
|
+
import { ChainConfig } from './chain-config.js'
|
20
19
|
|
21
20
|
State.reset()
|
22
21
|
// Endpoints.reset()
|
@@ -92,10 +91,17 @@ if (options.debug) {
|
|
92
91
|
const server = createServer({
|
93
92
|
'grpc.max_send_message_length': 128 * 1024 * 1024,
|
94
93
|
'grpc.max_receive_message_length': 128 * 1024 * 1024,
|
95
|
-
'grpc.default_compression_algorithm':
|
94
|
+
'grpc.default_compression_algorithm': compressionAlgorithms.gzip,
|
96
95
|
})
|
97
96
|
|
98
|
-
const
|
97
|
+
// const m = await import(options.target)
|
98
|
+
// console.log(m)
|
99
|
+
|
100
|
+
const baseService = new ProcessorServiceImpl(async () => {
|
101
|
+
const m = await import(options.target)
|
102
|
+
console.log('module loaded')
|
103
|
+
return m
|
104
|
+
}, server.shutdown)
|
99
105
|
const service = new FullProcessorServiceImpl(baseService)
|
100
106
|
|
101
107
|
server.add(ProcessorDefinition, service)
|
package/src/service.ts
CHANGED
@@ -10,13 +10,11 @@ import {
|
|
10
10
|
ProcessorServiceImplementation,
|
11
11
|
ProcessResult,
|
12
12
|
StartRequest,
|
13
|
+
Empty,
|
13
14
|
} from '@sentio/protos'
|
14
15
|
|
15
|
-
import {
|
16
|
-
|
17
|
-
import { PluginManager } from './plugin'
|
18
|
-
import { errorString, mergeProcessResults } from './utils'
|
19
|
-
|
16
|
+
import { PluginManager } from './plugin.js'
|
17
|
+
import { errorString, mergeProcessResults } from './utils.js'
|
20
18
|
;(BigInt.prototype as any).toJSON = function () {
|
21
19
|
return this.toString()
|
22
20
|
}
|
@@ -25,11 +23,11 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
25
23
|
private started = false
|
26
24
|
private processorConfig: ProcessConfigResponse
|
27
25
|
|
28
|
-
private readonly loader: () =>
|
26
|
+
private readonly loader: () => Promise<any>
|
29
27
|
|
30
28
|
private readonly shutdownHandler?: () => void
|
31
29
|
|
32
|
-
constructor(loader: () =>
|
30
|
+
constructor(loader: () => Promise<any>, shutdownHandler?: () => void) {
|
33
31
|
this.loader = loader
|
34
32
|
this.shutdownHandler = shutdownHandler
|
35
33
|
}
|
@@ -55,25 +53,21 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
55
53
|
}
|
56
54
|
|
57
55
|
try {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
// } catch (e) {}
|
74
|
-
// }
|
75
|
-
|
76
|
-
this.loader()
|
56
|
+
for (const plugin of ['@sentio/sdk']) {
|
57
|
+
try {
|
58
|
+
await import(plugin)
|
59
|
+
} catch (e) {
|
60
|
+
console.error('Failed to load plugin: ', plugin)
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
for (const plugin of ['@sentio/sdk-aptos', '@sentio/sdk-solana']) {
|
65
|
+
try {
|
66
|
+
await import(plugin)
|
67
|
+
} catch (e) {}
|
68
|
+
}
|
69
|
+
|
70
|
+
await this.loader()
|
77
71
|
} catch (e) {
|
78
72
|
throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))
|
79
73
|
}
|
package/lib/loader.d.ts
DELETED
package/lib/loader.js
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.load = void 0;
|
4
|
-
function load(name) {
|
5
|
-
const req = eval('require');
|
6
|
-
try {
|
7
|
-
let path;
|
8
|
-
try {
|
9
|
-
path = req.resolve(name, { paths: [process.cwd()] });
|
10
|
-
}
|
11
|
-
catch {
|
12
|
-
path = req.resolve(name);
|
13
|
-
}
|
14
|
-
const module = { module: req(path), name, path };
|
15
|
-
console.log('Processor Load successfully');
|
16
|
-
return module;
|
17
|
-
}
|
18
|
-
catch (err) {
|
19
|
-
if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
|
20
|
-
// this error is expected
|
21
|
-
console.log("Couldn't load (expected): ", name);
|
22
|
-
return undefined;
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
throw err;
|
26
|
-
}
|
27
|
-
}
|
28
|
-
}
|
29
|
-
exports.load = load;
|
30
|
-
//# sourceMappingURL=loader.js.map
|
package/lib/loader.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";;;AAAA,SAAgB,IAAI,CAAC,IAAY;IAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;IAE3B,IAAI;QACF,IAAI,IAAY,CAAA;QAChB,IAAI;YACF,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;SACrD;QAAC,MAAM;YACN,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;SACzB;QAED,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QAChD,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAA;QAC1C,OAAO,MAAM,CAAA;KACd;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,uBAAuB,IAAI,GAAG,CAAC,EAAE;YAClF,yBAAyB;YACzB,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,IAAI,CAAC,CAAA;YAC/C,OAAO,SAAS,CAAA;SACjB;aAAM;YACL,MAAM,GAAG,CAAA;SACV;KACF;AACH,CAAC;AAvBD,oBAuBC","sourcesContent":["export function load(name: string): { module: any; name: string; path: string } | undefined {\n const req = eval('require')\n\n try {\n let path: string\n try {\n path = req.resolve(name, { paths: [process.cwd()] })\n } catch {\n path = req.resolve(name)\n }\n\n const module = { module: req(path), name, path }\n console.log('Processor Load successfully')\n return module\n } catch (err) {\n if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {\n // this error is expected\n console.log(\"Couldn't load (expected): \", name)\n return undefined\n } else {\n throw err\n }\n }\n}\n"]}
|
package/src/loader.ts
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
export function load(name: string): { module: any; name: string; path: string } | undefined {
|
2
|
-
const req = eval('require')
|
3
|
-
|
4
|
-
try {
|
5
|
-
let path: string
|
6
|
-
try {
|
7
|
-
path = req.resolve(name, { paths: [process.cwd()] })
|
8
|
-
} catch {
|
9
|
-
path = req.resolve(name)
|
10
|
-
}
|
11
|
-
|
12
|
-
const module = { module: req(path), name, path }
|
13
|
-
console.log('Processor Load successfully')
|
14
|
-
return module
|
15
|
-
} catch (err) {
|
16
|
-
if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
|
17
|
-
// this error is expected
|
18
|
-
console.log("Couldn't load (expected): ", name)
|
19
|
-
return undefined
|
20
|
-
} else {
|
21
|
-
throw err
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|