@sentio/runtime 2.13.7-rc.2 → 2.14.0-rc.1
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/full-service.d.ts +3 -0
- package/lib/full-service.js +3 -0
- package/lib/full-service.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +13 -0
- package/lib/gen/processor/protos/processor.js +56 -1
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/plugin.d.ts +6 -0
- package/lib/plugin.js +7 -1
- package/lib/plugin.js.map +1 -1
- package/lib/service.d.ts +0 -2
- package/lib/service.js +28 -27
- package/lib/service.js.map +1 -1
- package/lib/utils.js +3 -0
- package/lib/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/full-service.ts +3 -0
- package/src/gen/processor/protos/processor.ts +72 -2
- package/src/plugin.ts +8 -1
- package/src/service.ts +29 -26
- package/src/utils.ts +3 -0
package/lib/plugin.d.ts
CHANGED
@@ -4,6 +4,9 @@ export declare abstract class Plugin {
|
|
4
4
|
supportedHandlers: HandlerType[];
|
5
5
|
configure(config: ProcessConfigResponse): Promise<void>;
|
6
6
|
start(start: StartRequest): Promise<void>;
|
7
|
+
/**
|
8
|
+
* @deprecated The method should not be used, use ctx.states instead
|
9
|
+
*/
|
7
10
|
stateDiff(config: ProcessConfigResponse): boolean;
|
8
11
|
processBinding(request: DataBinding): Promise<ProcessResult>;
|
9
12
|
}
|
@@ -14,6 +17,9 @@ export declare class PluginManager {
|
|
14
17
|
register(plugin: Plugin): void;
|
15
18
|
configure(config: ProcessConfigResponse): Promise<void[]>;
|
16
19
|
start(start: StartRequest): Promise<void[]>;
|
20
|
+
/**
|
21
|
+
* @deprecated The method should not be used, use ctx.states instead
|
22
|
+
*/
|
17
23
|
stateDiff(config: ProcessConfigResponse): boolean;
|
18
24
|
processBinding(request: DataBinding): Promise<ProcessResult>;
|
19
25
|
}
|
package/lib/plugin.js
CHANGED
@@ -4,11 +4,14 @@ export class Plugin {
|
|
4
4
|
supportedHandlers = [];
|
5
5
|
async configure(config) { }
|
6
6
|
async start(start) { }
|
7
|
+
/**
|
8
|
+
* @deprecated The method should not be used, use ctx.states instead
|
9
|
+
*/
|
7
10
|
stateDiff(config) {
|
8
11
|
return false;
|
9
12
|
}
|
10
13
|
async processBinding(request) {
|
11
|
-
return ProcessResult.
|
14
|
+
return ProcessResult.create();
|
12
15
|
}
|
13
16
|
}
|
14
17
|
class PluginManager {
|
@@ -34,6 +37,9 @@ class PluginManager {
|
|
34
37
|
start(start) {
|
35
38
|
return Promise.all(this.plugins.map((plugin) => plugin.start(start)));
|
36
39
|
}
|
40
|
+
/**
|
41
|
+
* @deprecated The method should not be used, use ctx.states instead
|
42
|
+
*/
|
37
43
|
stateDiff(config) {
|
38
44
|
return this.plugins.some((plugin) => plugin.stateDiff(config));
|
39
45
|
}
|
package/lib/plugin.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmD,aAAa,EAAgB,MAAM,gBAAgB,CAAA;AAE7G,MAAM,OAAgB,MAAM;IAC1B,IAAI,CAAQ;IACZ,iBAAiB,GAAkB,EAAE,CAAA;IAErC,KAAK,CAAC,SAAS,CAAC,MAA6B,IAAkB,CAAC;IAChE,KAAK,CAAC,KAAK,CAAC,KAAmB,IAAkB,CAAC;
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmD,aAAa,EAAgB,MAAM,gBAAgB,CAAA;AAE7G,MAAM,OAAgB,MAAM;IAC1B,IAAI,CAAQ;IACZ,iBAAiB,GAAkB,EAAE,CAAA;IAErC,KAAK,CAAC,SAAS,CAAC,MAA6B,IAAkB,CAAC;IAChE,KAAK,CAAC,KAAK,CAAC,KAAmB,IAAkB,CAAC;IAElD;;OAEG;IACH,SAAS,CAAC,MAA6B;QACrC,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AC,CAAC,CAAA;IACvE,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,MAA6B;QACrC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;IAChE,CAAC;IAED,cAAc,CAAC,OAAoB;QACjC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QAC1D,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,iBAAiB,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;SACxD;QACD,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;;SA1CU,aAAa","sourcesContent":["import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult, StartRequest } from '@sentio/protos'\n\nexport abstract class Plugin {\n name: string\n supportedHandlers: HandlerType[] = []\n\n async configure(config: ProcessConfigResponse): Promise<void> {}\n async start(start: StartRequest): Promise<void> {}\n\n /**\n * @deprecated The method should not be used, use ctx.states instead\n */\n stateDiff(config: ProcessConfigResponse): boolean {\n return false\n }\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n return ProcessResult.create()\n }\n}\n\nexport class PluginManager {\n static INSTANCE = new PluginManager()\n\n plugins: Plugin[] = []\n typesToPlugin = new Map<HandlerType, Plugin>()\n\n register(plugin: Plugin) {\n if (this.plugins.find((p) => p.name === plugin.name)) {\n return\n }\n this.plugins.push(plugin)\n\n for (const handlerType of plugin.supportedHandlers) {\n const exsited = this.typesToPlugin.get(handlerType)\n if (exsited) {\n throw new Error(`Duplicate plugin for ${handlerType}: ${exsited.name} and ${plugin.name}`)\n }\n this.typesToPlugin.set(handlerType, plugin)\n }\n }\n\n configure(config: ProcessConfigResponse) {\n return Promise.all(this.plugins.map((plugin) => plugin.configure(config)))\n }\n\n start(start: StartRequest) {\n return Promise.all(this.plugins.map((plugin) => plugin.start(start)))\n }\n\n /**\n * @deprecated The method should not be used, use ctx.states instead\n */\n stateDiff(config: ProcessConfigResponse): boolean {\n return this.plugins.some((plugin) => plugin.stateDiff(config))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n const plugin = this.typesToPlugin.get(request.handlerType)\n if (!plugin) {\n throw new Error(`No plugin for ${request.handlerType}`)\n }\n return plugin.processBinding(request)\n }\n}\n"]}
|
package/lib/service.d.ts
CHANGED
@@ -2,12 +2,10 @@ import { CallContext } from 'nice-grpc';
|
|
2
2
|
import { DataBinding, ProcessBindingResponse, ProcessBindingsRequest, ProcessConfigRequest, ProcessConfigResponse, ProcessorServiceImplementation, ProcessResult, StartRequest, Empty } from '@sentio/protos';
|
3
3
|
export declare class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
4
4
|
private started;
|
5
|
-
private processorConfig;
|
6
5
|
private readonly loader;
|
7
6
|
private readonly shutdownHandler?;
|
8
7
|
constructor(loader: () => Promise<any>, shutdownHandler?: () => void);
|
9
8
|
getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse>;
|
10
|
-
configure(): Promise<void>;
|
11
9
|
start(request: StartRequest, context: CallContext): Promise<Empty>;
|
12
10
|
stop(request: Empty, context: CallContext): Promise<Empty>;
|
13
11
|
processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse>;
|
package/lib/service.js
CHANGED
@@ -7,7 +7,7 @@ BigInt.prototype.toJSON = function () {
|
|
7
7
|
};
|
8
8
|
export class ProcessorServiceImpl {
|
9
9
|
started = false;
|
10
|
-
processorConfig
|
10
|
+
// private processorConfig: ProcessConfigResponse
|
11
11
|
loader;
|
12
12
|
shutdownHandler;
|
13
13
|
constructor(loader, shutdownHandler) {
|
@@ -18,15 +18,18 @@ export class ProcessorServiceImpl {
|
|
18
18
|
if (!this.started) {
|
19
19
|
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.');
|
20
20
|
}
|
21
|
-
if (!this.processorConfig) {
|
22
|
-
|
23
|
-
}
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
this.processorConfig = ProcessConfigResponse.fromPartial({});
|
28
|
-
await PluginManager.INSTANCE.configure(this.processorConfig);
|
21
|
+
// if (!this.processorConfig) {
|
22
|
+
// throw new ServerError(Status.INTERNAL, 'Process config empty.')
|
23
|
+
// }
|
24
|
+
const newConfig = ProcessConfigResponse.create();
|
25
|
+
await PluginManager.INSTANCE.configure(newConfig);
|
26
|
+
return newConfig;
|
29
27
|
}
|
28
|
+
//
|
29
|
+
// async configure() {
|
30
|
+
// this.processorConfig = ProcessConfigResponse.fromPartial({})
|
31
|
+
// await PluginManager.INSTANCE.configure(this.processorConfig)
|
32
|
+
// }
|
30
33
|
async start(request, context) {
|
31
34
|
if (this.started) {
|
32
35
|
return {};
|
@@ -51,12 +54,11 @@ export class ProcessorServiceImpl {
|
|
51
54
|
throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e));
|
52
55
|
}
|
53
56
|
await PluginManager.INSTANCE.start(request);
|
54
|
-
try {
|
55
|
-
|
56
|
-
}
|
57
|
-
|
58
|
-
|
59
|
-
}
|
57
|
+
// try {
|
58
|
+
// await this.configure()
|
59
|
+
// } catch (e) {
|
60
|
+
// throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + errorString(e))
|
61
|
+
// }
|
60
62
|
this.started = true;
|
61
63
|
return {};
|
62
64
|
}
|
@@ -80,14 +82,13 @@ export class ProcessorServiceImpl {
|
|
80
82
|
throw e;
|
81
83
|
}
|
82
84
|
const result = mergeProcessResults(promise);
|
83
|
-
let updated = false
|
84
|
-
if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
|
85
|
-
|
86
|
-
|
87
|
-
}
|
85
|
+
// let updated = false
|
86
|
+
// if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
|
87
|
+
// await this.configure()
|
88
|
+
// updated = true
|
89
|
+
// }
|
88
90
|
return {
|
89
91
|
result,
|
90
|
-
configUpdated: updated,
|
91
92
|
};
|
92
93
|
}
|
93
94
|
async processBinding(request, options) {
|
@@ -98,14 +99,14 @@ export class ProcessorServiceImpl {
|
|
98
99
|
async *processBindingsStream(requests, context) {
|
99
100
|
for await (const request of requests) {
|
100
101
|
const result = await this.processBinding(request);
|
101
|
-
let updated = false
|
102
|
-
if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
|
103
|
-
|
104
|
-
|
105
|
-
}
|
102
|
+
// let updated = false
|
103
|
+
// if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
|
104
|
+
// await this.configure()
|
105
|
+
// updated = true
|
106
|
+
// }
|
106
107
|
yield {
|
107
108
|
result,
|
108
|
-
configUpdated:
|
109
|
+
configUpdated: result.states?.configUpdated || false,
|
109
110
|
};
|
110
111
|
}
|
111
112
|
}
|
package/lib/service.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE5D,OAAO,EAML,qBAAqB,GAKtB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAC5D;AAAC,MAAM,CAAC,SAAiB,CAAC,MAAM,GAAG;IAClC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;AACxB,CAAC,CAAA;AAED,MAAM,OAAO,oBAAoB;IACvB,OAAO,GAAG,KAAK,CAAA;
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE5D,OAAO,EAML,qBAAqB,GAKtB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,aAA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,CAAC,cAAc,CAAC,OAAoB,EAAE,OAAqB;QAC9D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;QACnE,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;QAC9C,OAAO,MAAM,CAAA;IACf,CAAC;IAED,KAAK,CAAC,CAAC,qBAAqB,CAAC,QAAoC,EAAE,OAAoB;QACrF,IAAI,KAAK,EAAE,MAAM,OAAO,IAAI,QAAQ,EAAE;YACpC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;YACjD,sBAAsB;YACtB,gEAAgE;YAChE,2BAA2B;YAC3B,mBAAmB;YACnB,IAAI;YACJ,MAAM;gBACJ,MAAM;gBACN,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,IAAI,KAAK;aACrD,CAAA;SACF;IACH,CAAC;CACF;AAED,SAAS,iBAAiB,CAAC,OAAsB,EAAE,WAAwB;IACzE,KAAK,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;QACtF,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACjB,CAAC,CAAC,WAAW,GAAG;gBACd,IAAI,EAAE,WAAW;aAClB,CAAA;QACH,CAAC,CAAC,CAAA;KACH;AACH,CAAC","sourcesContent":["import { CallContext, ServerError, Status } from 'nice-grpc'\n\nimport {\n DataBinding,\n HandlerType,\n ProcessBindingResponse,\n ProcessBindingsRequest,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessorServiceImplementation,\n ProcessResult,\n StartRequest,\n Empty,\n} from '@sentio/protos'\n\nimport { PluginManager } from './plugin.js'\nimport { errorString, mergeProcessResults } from './utils.js'\n;(BigInt.prototype as any).toJSON = function () {\n return this.toString()\n}\n\nexport class ProcessorServiceImpl implements ProcessorServiceImplementation {\n private started = false\n // private processorConfig: ProcessConfigResponse\n\n private readonly loader: () => Promise<any>\n\n private readonly shutdownHandler?: () => void\n\n constructor(loader: () => Promise<any>, shutdownHandler?: () => void) {\n this.loader = loader\n this.shutdownHandler = shutdownHandler\n }\n\n async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n // if (!this.processorConfig) {\n // throw new ServerError(Status.INTERNAL, 'Process config empty.')\n // }\n\n const newConfig = ProcessConfigResponse.create()\n await PluginManager.INSTANCE.configure(newConfig)\n return newConfig\n }\n\n //\n // async configure() {\n // this.processorConfig = ProcessConfigResponse.fromPartial({})\n // await PluginManager.INSTANCE.configure(this.processorConfig)\n // }\n\n async start(request: StartRequest, context: CallContext): Promise<Empty> {\n if (this.started) {\n return {}\n }\n\n try {\n // for (const plugin of ['@sentio/sdk', '@sentio/sdk/eth']) {\n // try {\n // await import(plugin)\n // } catch (e) {\n // console.error('Failed to load plugin: ', plugin)\n // }\n // }\n //\n // for (const plugin of ['@sentio/sdk/aptos', '@sentio/sdk/solana']) {\n // try {\n // await import(plugin)\n // } catch (e) {}\n // }\n\n await this.loader()\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n await PluginManager.INSTANCE.start(request)\n\n // try {\n // await this.configure()\n // } catch (e) {\n // throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + errorString(e))\n // }\n this.started = true\n return {}\n }\n\n async stop(request: Empty, context: CallContext): Promise<Empty> {\n console.log('Server Shutting down in 5 seconds')\n if (this.shutdownHandler) {\n setTimeout(this.shutdownHandler, 5000)\n }\n return {}\n }\n\n async processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const promises = request.bindings.map((binding) => this.processBinding(binding))\n let promise\n try {\n promise = await Promise.all(promises)\n } catch (e) {\n throw e\n }\n const result = mergeProcessResults(promise)\n\n // let updated = false\n // if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {\n // await this.configure()\n // updated = true\n // }\n\n return {\n result,\n }\n }\n\n async processBinding(request: DataBinding, options?: CallContext): Promise<ProcessResult> {\n const result = await PluginManager.INSTANCE.processBinding(request)\n recordRuntimeInfo(result, request.handlerType)\n return result\n }\n\n async *processBindingsStream(requests: AsyncIterable<DataBinding>, context: CallContext) {\n for await (const request of requests) {\n const result = await this.processBinding(request)\n // let updated = false\n // if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {\n // await this.configure()\n // updated = true\n // }\n yield {\n result,\n configUpdated: result.states?.configUpdated || false,\n }\n }\n }\n}\n\nfunction recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {\n for (const list of [results.gauges, results.counters, results.events, results.exports]) {\n list.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n }\n}\n"]}
|
package/lib/utils.js
CHANGED
@@ -6,6 +6,9 @@ export function mergeProcessResults(results) {
|
|
6
6
|
res.gauges = res.gauges.concat(r.gauges);
|
7
7
|
res.events = res.events.concat(r.events);
|
8
8
|
res.exports = res.exports.concat(r.exports);
|
9
|
+
res.states = {
|
10
|
+
configUpdated: res.states?.configUpdated || r.states?.configUpdated || false,
|
11
|
+
};
|
9
12
|
}
|
10
13
|
return res;
|
11
14
|
}
|
package/lib/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,MAAM,UAAU,mBAAmB,CAAC,OAAwB;IAC1D,MAAM,GAAG,GAAG,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IAEzC,KAAK,MAAM,CAAC,IAAI,O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Z,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAQ;IAClC,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,CAAA;AAC7B,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAA","sourcesContent":["import { ProcessResult } from '@sentio/protos'\n\nexport function mergeProcessResults(results: ProcessResult[]): ProcessResult {\n const res = ProcessResult.fromPartial({})\n\n for (const r of results) {\n res.counters = res.counters.concat(r.counters)\n res.gauges = res.gauges.concat(r.gauges)\n res.events = res.events.concat(r.events)\n res.exports = res.exports.concat(r.exports)\n res.states = {\n configUpdated: res.states?.configUpdated || r.states?.configUpdated || false,\n }\n }\n return res\n}\n\nexport function errorString(e: Error): string {\n return e.stack || e.message\n}\n\nexport const USER_PROCESSOR = 'user_processor'\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/runtime",
|
3
3
|
"license": "Apache-2.0",
|
4
|
-
"version": "2.
|
4
|
+
"version": "2.14.0-rc.1",
|
5
5
|
"dependencies": {
|
6
6
|
"command-line-args": "^5.2.1",
|
7
7
|
"command-line-usage": "^7.0.1",
|
@@ -16,7 +16,7 @@
|
|
16
16
|
"protobufjs": "^7.2.3",
|
17
17
|
"@grpc/grpc-js": "^1.8.14",
|
18
18
|
"prom-client": "^14.2.0",
|
19
|
-
"@sentio/protos": "^2.
|
19
|
+
"@sentio/protos": "^2.14.0-rc.1"
|
20
20
|
},
|
21
21
|
"devDependencies": {
|
22
22
|
"jest": "^29.5.0",
|
@@ -27,7 +27,7 @@
|
|
27
27
|
"tslib": "^2.5.0"
|
28
28
|
},
|
29
29
|
"peerDependencies": {
|
30
|
-
"@sentio/sdk": "^2.
|
30
|
+
"@sentio/sdk": "^2.14.0-rc.1"
|
31
31
|
},
|
32
32
|
"bin": {
|
33
33
|
"processor-runner": "./lib/processor-runner.js"
|
package/src/full-service.ts
CHANGED
@@ -76,6 +76,9 @@ export class FullProcessorServiceImpl implements ProcessorServiceImplementation
|
|
76
76
|
}
|
77
77
|
const result = await this.instance.processBindings(request, options)
|
78
78
|
this.adjustResult(result.result as ProcessResult)
|
79
|
+
if (!result.configUpdated && result.result?.states?.configUpdated) {
|
80
|
+
result.configUpdated = result.result?.states?.configUpdated
|
81
|
+
}
|
79
82
|
return result
|
80
83
|
}
|
81
84
|
|
@@ -534,7 +534,10 @@ export interface ProcessBindingsRequest {
|
|
534
534
|
}
|
535
535
|
|
536
536
|
export interface ProcessBindingResponse {
|
537
|
-
result:
|
537
|
+
result:
|
538
|
+
| ProcessResult
|
539
|
+
| undefined;
|
540
|
+
/** @deprecated */
|
538
541
|
configUpdated: boolean;
|
539
542
|
}
|
540
543
|
|
@@ -629,6 +632,10 @@ export interface DataBinding {
|
|
629
632
|
handlerIds: number[];
|
630
633
|
}
|
631
634
|
|
635
|
+
export interface StateResult {
|
636
|
+
configUpdated: boolean;
|
637
|
+
}
|
638
|
+
|
632
639
|
export interface ProcessResult {
|
633
640
|
gauges: GaugeResult[];
|
634
641
|
counters: CounterResult[];
|
@@ -636,6 +643,7 @@ export interface ProcessResult {
|
|
636
643
|
logs: LogResult[];
|
637
644
|
events: EventTrackingResult[];
|
638
645
|
exports: ExportResult[];
|
646
|
+
states: StateResult | undefined;
|
639
647
|
}
|
640
648
|
|
641
649
|
export interface RecordMetaData {
|
@@ -4511,8 +4519,59 @@ export const DataBinding = {
|
|
4511
4519
|
},
|
4512
4520
|
};
|
4513
4521
|
|
4522
|
+
function createBaseStateResult(): StateResult {
|
4523
|
+
return { configUpdated: false };
|
4524
|
+
}
|
4525
|
+
|
4526
|
+
export const StateResult = {
|
4527
|
+
encode(message: StateResult, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
|
4528
|
+
if (message.configUpdated === true) {
|
4529
|
+
writer.uint32(8).bool(message.configUpdated);
|
4530
|
+
}
|
4531
|
+
return writer;
|
4532
|
+
},
|
4533
|
+
|
4534
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): StateResult {
|
4535
|
+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
4536
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
4537
|
+
const message = createBaseStateResult();
|
4538
|
+
while (reader.pos < end) {
|
4539
|
+
const tag = reader.uint32();
|
4540
|
+
switch (tag >>> 3) {
|
4541
|
+
case 1:
|
4542
|
+
message.configUpdated = reader.bool();
|
4543
|
+
break;
|
4544
|
+
default:
|
4545
|
+
reader.skipType(tag & 7);
|
4546
|
+
break;
|
4547
|
+
}
|
4548
|
+
}
|
4549
|
+
return message;
|
4550
|
+
},
|
4551
|
+
|
4552
|
+
fromJSON(object: any): StateResult {
|
4553
|
+
return { configUpdated: isSet(object.configUpdated) ? Boolean(object.configUpdated) : false };
|
4554
|
+
},
|
4555
|
+
|
4556
|
+
toJSON(message: StateResult): unknown {
|
4557
|
+
const obj: any = {};
|
4558
|
+
message.configUpdated !== undefined && (obj.configUpdated = message.configUpdated);
|
4559
|
+
return obj;
|
4560
|
+
},
|
4561
|
+
|
4562
|
+
create(base?: DeepPartial<StateResult>): StateResult {
|
4563
|
+
return StateResult.fromPartial(base ?? {});
|
4564
|
+
},
|
4565
|
+
|
4566
|
+
fromPartial(object: DeepPartial<StateResult>): StateResult {
|
4567
|
+
const message = createBaseStateResult();
|
4568
|
+
message.configUpdated = object.configUpdated ?? false;
|
4569
|
+
return message;
|
4570
|
+
},
|
4571
|
+
};
|
4572
|
+
|
4514
4573
|
function createBaseProcessResult(): ProcessResult {
|
4515
|
-
return { gauges: [], counters: [], logs: [], events: [], exports: [] };
|
4574
|
+
return { gauges: [], counters: [], logs: [], events: [], exports: [], states: undefined };
|
4516
4575
|
}
|
4517
4576
|
|
4518
4577
|
export const ProcessResult = {
|
@@ -4532,6 +4591,9 @@ export const ProcessResult = {
|
|
4532
4591
|
for (const v of message.exports) {
|
4533
4592
|
ExportResult.encode(v!, writer.uint32(42).fork()).ldelim();
|
4534
4593
|
}
|
4594
|
+
if (message.states !== undefined) {
|
4595
|
+
StateResult.encode(message.states, writer.uint32(50).fork()).ldelim();
|
4596
|
+
}
|
4535
4597
|
return writer;
|
4536
4598
|
},
|
4537
4599
|
|
@@ -4557,6 +4619,9 @@ export const ProcessResult = {
|
|
4557
4619
|
case 5:
|
4558
4620
|
message.exports.push(ExportResult.decode(reader, reader.uint32()));
|
4559
4621
|
break;
|
4622
|
+
case 6:
|
4623
|
+
message.states = StateResult.decode(reader, reader.uint32());
|
4624
|
+
break;
|
4560
4625
|
default:
|
4561
4626
|
reader.skipType(tag & 7);
|
4562
4627
|
break;
|
@@ -4572,6 +4637,7 @@ export const ProcessResult = {
|
|
4572
4637
|
logs: Array.isArray(object?.logs) ? object.logs.map((e: any) => LogResult.fromJSON(e)) : [],
|
4573
4638
|
events: Array.isArray(object?.events) ? object.events.map((e: any) => EventTrackingResult.fromJSON(e)) : [],
|
4574
4639
|
exports: Array.isArray(object?.exports) ? object.exports.map((e: any) => ExportResult.fromJSON(e)) : [],
|
4640
|
+
states: isSet(object.states) ? StateResult.fromJSON(object.states) : undefined,
|
4575
4641
|
};
|
4576
4642
|
},
|
4577
4643
|
|
@@ -4602,6 +4668,7 @@ export const ProcessResult = {
|
|
4602
4668
|
} else {
|
4603
4669
|
obj.exports = [];
|
4604
4670
|
}
|
4671
|
+
message.states !== undefined && (obj.states = message.states ? StateResult.toJSON(message.states) : undefined);
|
4605
4672
|
return obj;
|
4606
4673
|
},
|
4607
4674
|
|
@@ -4616,6 +4683,9 @@ export const ProcessResult = {
|
|
4616
4683
|
message.logs = object.logs?.map((e) => LogResult.fromPartial(e)) || [];
|
4617
4684
|
message.events = object.events?.map((e) => EventTrackingResult.fromPartial(e)) || [];
|
4618
4685
|
message.exports = object.exports?.map((e) => ExportResult.fromPartial(e)) || [];
|
4686
|
+
message.states = (object.states !== undefined && object.states !== null)
|
4687
|
+
? StateResult.fromPartial(object.states)
|
4688
|
+
: undefined;
|
4619
4689
|
return message;
|
4620
4690
|
},
|
4621
4691
|
};
|
package/src/plugin.ts
CHANGED
@@ -6,11 +6,15 @@ export abstract class Plugin {
|
|
6
6
|
|
7
7
|
async configure(config: ProcessConfigResponse): Promise<void> {}
|
8
8
|
async start(start: StartRequest): Promise<void> {}
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @deprecated The method should not be used, use ctx.states instead
|
12
|
+
*/
|
9
13
|
stateDiff(config: ProcessConfigResponse): boolean {
|
10
14
|
return false
|
11
15
|
}
|
12
16
|
async processBinding(request: DataBinding): Promise<ProcessResult> {
|
13
|
-
return ProcessResult.
|
17
|
+
return ProcessResult.create()
|
14
18
|
}
|
15
19
|
}
|
16
20
|
|
@@ -43,6 +47,9 @@ export class PluginManager {
|
|
43
47
|
return Promise.all(this.plugins.map((plugin) => plugin.start(start)))
|
44
48
|
}
|
45
49
|
|
50
|
+
/**
|
51
|
+
* @deprecated The method should not be used, use ctx.states instead
|
52
|
+
*/
|
46
53
|
stateDiff(config: ProcessConfigResponse): boolean {
|
47
54
|
return this.plugins.some((plugin) => plugin.stateDiff(config))
|
48
55
|
}
|
package/src/service.ts
CHANGED
@@ -21,7 +21,7 @@ import { errorString, mergeProcessResults } from './utils.js'
|
|
21
21
|
|
22
22
|
export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
23
23
|
private started = false
|
24
|
-
private processorConfig: ProcessConfigResponse
|
24
|
+
// private processorConfig: ProcessConfigResponse
|
25
25
|
|
26
26
|
private readonly loader: () => Promise<any>
|
27
27
|
|
@@ -36,17 +36,21 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
36
36
|
if (!this.started) {
|
37
37
|
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
38
38
|
}
|
39
|
-
if (!this.processorConfig) {
|
40
|
-
|
41
|
-
}
|
42
|
-
return this.processorConfig
|
43
|
-
}
|
39
|
+
// if (!this.processorConfig) {
|
40
|
+
// throw new ServerError(Status.INTERNAL, 'Process config empty.')
|
41
|
+
// }
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
const newConfig = ProcessConfigResponse.create()
|
44
|
+
await PluginManager.INSTANCE.configure(newConfig)
|
45
|
+
return newConfig
|
48
46
|
}
|
49
47
|
|
48
|
+
//
|
49
|
+
// async configure() {
|
50
|
+
// this.processorConfig = ProcessConfigResponse.fromPartial({})
|
51
|
+
// await PluginManager.INSTANCE.configure(this.processorConfig)
|
52
|
+
// }
|
53
|
+
|
50
54
|
async start(request: StartRequest, context: CallContext): Promise<Empty> {
|
51
55
|
if (this.started) {
|
52
56
|
return {}
|
@@ -74,11 +78,11 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
74
78
|
|
75
79
|
await PluginManager.INSTANCE.start(request)
|
76
80
|
|
77
|
-
try {
|
78
|
-
|
79
|
-
} catch (e) {
|
80
|
-
|
81
|
-
}
|
81
|
+
// try {
|
82
|
+
// await this.configure()
|
83
|
+
// } catch (e) {
|
84
|
+
// throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + errorString(e))
|
85
|
+
// }
|
82
86
|
this.started = true
|
83
87
|
return {}
|
84
88
|
}
|
@@ -105,15 +109,14 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
105
109
|
}
|
106
110
|
const result = mergeProcessResults(promise)
|
107
111
|
|
108
|
-
let updated = false
|
109
|
-
if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
|
110
|
-
|
111
|
-
|
112
|
-
}
|
112
|
+
// let updated = false
|
113
|
+
// if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
|
114
|
+
// await this.configure()
|
115
|
+
// updated = true
|
116
|
+
// }
|
113
117
|
|
114
118
|
return {
|
115
119
|
result,
|
116
|
-
configUpdated: updated,
|
117
120
|
}
|
118
121
|
}
|
119
122
|
|
@@ -126,14 +129,14 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
126
129
|
async *processBindingsStream(requests: AsyncIterable<DataBinding>, context: CallContext) {
|
127
130
|
for await (const request of requests) {
|
128
131
|
const result = await this.processBinding(request)
|
129
|
-
let updated = false
|
130
|
-
if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
|
131
|
-
|
132
|
-
|
133
|
-
}
|
132
|
+
// let updated = false
|
133
|
+
// if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
|
134
|
+
// await this.configure()
|
135
|
+
// updated = true
|
136
|
+
// }
|
134
137
|
yield {
|
135
138
|
result,
|
136
|
-
configUpdated:
|
139
|
+
configUpdated: result.states?.configUpdated || false,
|
137
140
|
}
|
138
141
|
}
|
139
142
|
}
|
package/src/utils.ts
CHANGED
@@ -8,6 +8,9 @@ export function mergeProcessResults(results: ProcessResult[]): ProcessResult {
|
|
8
8
|
res.gauges = res.gauges.concat(r.gauges)
|
9
9
|
res.events = res.events.concat(r.events)
|
10
10
|
res.exports = res.exports.concat(r.exports)
|
11
|
+
res.states = {
|
12
|
+
configUpdated: res.states?.configUpdated || r.states?.configUpdated || false,
|
13
|
+
}
|
11
14
|
}
|
12
15
|
return res
|
13
16
|
}
|