@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.
Files changed (49) hide show
  1. package/lib/chain-config.js +1 -2
  2. package/lib/decode-benchmark.js +3 -6
  3. package/lib/decode-benchmark.js.map +1 -1
  4. package/lib/endpoints.js +1 -5
  5. package/lib/endpoints.js.map +1 -1
  6. package/lib/full-service.d.ts +7 -7
  7. package/lib/full-service.js +24 -22
  8. package/lib/full-service.js.map +1 -1
  9. package/lib/gen/google/protobuf/empty.d.ts +1 -1
  10. package/lib/gen/google/protobuf/empty.js +4 -8
  11. package/lib/gen/google/protobuf/empty.js.map +1 -1
  12. package/lib/gen/google/protobuf/struct.d.ts +1 -1
  13. package/lib/gen/google/protobuf/struct.js +27 -33
  14. package/lib/gen/google/protobuf/struct.js.map +1 -1
  15. package/lib/gen/google/protobuf/timestamp.d.ts +1 -1
  16. package/lib/gen/google/protobuf/timestamp.js +8 -12
  17. package/lib/gen/google/protobuf/timestamp.js.map +1 -1
  18. package/lib/gen/processor/protos/processor.d.ts +2 -5
  19. package/lib/gen/processor/protos/processor.js +570 -598
  20. package/lib/gen/processor/protos/processor.js.map +1 -1
  21. package/lib/index.d.ts +6 -6
  22. package/lib/index.js +6 -9
  23. package/lib/index.js.map +1 -1
  24. package/lib/plugin.js +4 -9
  25. package/lib/plugin.js.map +1 -1
  26. package/lib/processor-runner.js +34 -32
  27. package/lib/processor-runner.js.map +1 -1
  28. package/lib/service.d.ts +2 -3
  29. package/lib/service.js +32 -38
  30. package/lib/service.js.map +1 -1
  31. package/lib/service.test.js.map +1 -1
  32. package/lib/state-storage.test.js.map +1 -1
  33. package/lib/state.js +4 -11
  34. package/lib/state.js.map +1 -1
  35. package/lib/utils.js +5 -10
  36. package/lib/utils.js.map +1 -1
  37. package/package.json +12 -10
  38. package/src/full-service.ts +23 -14
  39. package/src/gen/google/protobuf/empty.ts +1 -1
  40. package/src/gen/google/protobuf/struct.ts +1 -1
  41. package/src/gen/google/protobuf/timestamp.ts +1 -1
  42. package/src/gen/processor/protos/processor.ts +6 -18
  43. package/src/index.ts +6 -6
  44. package/src/processor-runner.ts +15 -9
  45. package/src/service.ts +20 -26
  46. package/lib/loader.d.ts +0 -5
  47. package/lib/loader.js +0 -30
  48. package/lib/loader.js.map +0 -1
  49. package/src/loader.ts +0 -24
package/lib/index.d.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/lib/index.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./plugin"), exports);
5
- tslib_1.__exportStar(require("./state"), exports);
6
- tslib_1.__exportStar(require("./utils"), exports);
7
- tslib_1.__exportStar(require("./endpoints"), exports);
8
- tslib_1.__exportStar(require("./chain-config"), exports);
9
- tslib_1.__exportStar(require("./service"), exports);
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';
10
7
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB;AACxB,kDAAuB;AACvB,kDAAuB;AACvB,sDAA2B;AAC3B,yDAA8B;AAC9B,oDAAyB","sourcesContent":["export * from './plugin'\nexport * from './state'\nexport * from './utils'\nexport * from './endpoints'\nexport * from './chain-config'\nexport * from './service'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA","sourcesContent":["export * from './plugin.js'\nexport * from './state.js'\nexport * from './utils.js'\nexport * from './endpoints.js'\nexport * from './chain-config.js'\nexport * from './service.js'\n"]}
package/lib/plugin.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginManager = exports.Plugin = void 0;
4
- const protos_1 = require("@sentio/protos");
5
- class Plugin {
1
+ import { ProcessResult } from '@sentio/protos';
2
+ export class Plugin {
6
3
  name;
7
4
  supportedHandlers = [];
8
5
  async configure(config) { }
@@ -11,11 +8,10 @@ class Plugin {
11
8
  return false;
12
9
  }
13
10
  async processBinding(request) {
14
- return protos_1.ProcessResult.fromPartial({});
11
+ return ProcessResult.fromPartial({});
15
12
  }
16
13
  }
17
- exports.Plugin = Plugin;
18
- class PluginManager {
14
+ export class PluginManager {
19
15
  static INSTANCE = new PluginManager();
20
16
  plugins = [];
21
17
  typesToPlugin = new Map();
@@ -49,5 +45,4 @@ class PluginManager {
49
45
  return plugin.processBinding(request);
50
46
  }
51
47
  }
52
- exports.PluginManager = PluginManager;
53
48
  //# sourceMappingURL=plugin.js.map
package/lib/plugin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;AAAA,2CAA6G;AAE7G,MAAsB,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;IAClD,SAAS,CAAC,MAA6B;QACrC,OAAO,KAAK,CAAA;IACd,CAAC;IACD,KA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AAA;IACvE,CAAC;IAED,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;;AAvCH,sCAwCC","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 stateDiff(config: ProcessConfigResponse): boolean {\n return false\n }\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n return ProcessResult.fromPartial({})\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 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"]}
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;IAClD,SAAS,CAAC,MAA6B;QACrC,OAAO,KAAK,CAAA;IACd,CAAC;IACD,KAAK,CAAC,cAAc,CAAC,OAAoB;QACvC,OAAO,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IACtC,CAAC;CACF;AAED,MAAM,OAAO,aAAa;IACxB,MAAM,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAA;IAErC,OAAO,GAAa,EAAE,CAAA;IACtB,aAAa,GAAG,IAAI,GAAG,EAAuB,CAAA;IAE9C,QAAQ,CAAC,MAAc;QACrB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE;YACpD,OAAM;SACP;QACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAEzB,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,iBAAiB,EAAE;YAClD,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;YACnD,IAAI,OAAO,EAAE;gBACX,MAAM,IAAI,KAAK,CAAC,wBAAwB,WAAW,KAAK,OAAO,CAAC,IAAI,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;aAC3F;YACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;SAC5C;IACH,CAAC;IAED,SAAS,CAAC,MAA6B;QACrC,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC5E,CAAC;IAED,KAAK,CAAC,KAAmB;QACvB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACvE,CAAC;IAED,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","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 stateDiff(config: ProcessConfigResponse): boolean {\n return false\n }\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n return ProcessResult.fromPartial({})\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 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"]}
@@ -1,21 +1,17 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
7
- const util = tslib_1.__importStar(require("util"));
8
- const command_line_args_1 = tslib_1.__importDefault(require("command-line-args"));
9
- const nice_grpc_1 = require("nice-grpc");
10
- const winston_1 = require("winston");
11
- const compression_algorithms_1 = require("@grpc/grpc-js/build/src/compression-algorithms");
12
- const protos_1 = require("@sentio/protos");
13
- const service_1 = require("./service");
14
- const state_1 = require("./state");
15
- const endpoints_1 = require("./endpoints");
16
- const loader_1 = require("./loader");
17
- const full_service_1 = require("./full-service");
18
- state_1.State.reset();
2
+ import path from 'path';
3
+ import fs from 'fs-extra';
4
+ import * as util from 'util';
5
+ import commandLineArgs from 'command-line-args';
6
+ import { createServer } from 'nice-grpc';
7
+ import { createLogger, transports, format } from 'winston';
8
+ import { compressionAlgorithms } from '@grpc/grpc-js';
9
+ import { ProcessorDefinition } from '@sentio/protos';
10
+ import { ProcessorServiceImpl } from './service.js';
11
+ import { State } from './state.js';
12
+ import { Endpoints } from './endpoints.js';
13
+ import { FullProcessorServiceImpl } from './full-service.js';
14
+ State.reset();
19
15
  // Endpoints.reset()
20
16
  const optionDefinitions = [
21
17
  { name: 'target', type: String, defaultOption: true },
@@ -33,7 +29,7 @@ const optionDefinitions = [
33
29
  { name: 'log-format', type: String, defaultValue: 'console' },
34
30
  { name: 'debug', type: Boolean, defaultValue: false },
35
31
  ];
36
- const options = (0, command_line_args_1.default)(optionDefinitions, { partial: true });
32
+ const options = commandLineArgs(optionDefinitions, { partial: true });
37
33
  if (options['log-format'] === 'json') {
38
34
  const utilFormatter = {
39
35
  transform: (info) => {
@@ -44,9 +40,9 @@ if (options['log-format'] === 'json') {
44
40
  return info;
45
41
  },
46
42
  };
47
- const logger = (0, winston_1.createLogger)({
48
- format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }), utilFormatter, winston_1.format.errors({ stack: true }), winston_1.format.json()),
49
- transports: [new winston_1.transports.Console()],
43
+ const logger = createLogger({
44
+ format: format.combine(format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }), utilFormatter, format.errors({ stack: true }), format.json()),
45
+ transports: [new transports.Console()],
50
46
  });
51
47
  console.log = (...args) => logger.info.call(logger, ...args);
52
48
  console.info = (...args) => logger.info.call(logger, ...args);
@@ -57,29 +53,35 @@ if (options['log-format'] === 'json') {
57
53
  if (options.debug) {
58
54
  console.log('Starting with', options.target);
59
55
  }
60
- const fullPath = path_1.default.resolve(options['chains-config']);
61
- const chainsConfig = fs_extra_1.default.readJsonSync(fullPath);
56
+ const fullPath = path.resolve(options['chains-config']);
57
+ const chainsConfig = fs.readJsonSync(fullPath);
62
58
  // setProvider(chainsConfig, options.concurrency, options['use-chainserver'])
63
- endpoints_1.Endpoints.INSTANCE.concurrency = options.concurrency;
64
- endpoints_1.Endpoints.INSTANCE.chainQueryAPI = options['chainquery-server'];
65
- endpoints_1.Endpoints.INSTANCE.priceFeedAPI = options['pricefeed-server'];
59
+ Endpoints.INSTANCE.concurrency = options.concurrency;
60
+ Endpoints.INSTANCE.chainQueryAPI = options['chainquery-server'];
61
+ Endpoints.INSTANCE.priceFeedAPI = options['pricefeed-server'];
66
62
  for (const [id, config] of Object.entries(chainsConfig)) {
67
63
  const chainConfig = config;
68
64
  if (chainConfig.ChainServer) {
69
- endpoints_1.Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer);
65
+ Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer);
70
66
  }
71
67
  }
72
68
  if (options.debug) {
73
69
  console.log('Starting Server', options);
74
70
  }
75
- const server = (0, nice_grpc_1.createServer)({
71
+ const server = createServer({
76
72
  'grpc.max_send_message_length': 128 * 1024 * 1024,
77
73
  'grpc.max_receive_message_length': 128 * 1024 * 1024,
78
- 'grpc.default_compression_algorithm': compression_algorithms_1.CompressionAlgorithms.gzip,
74
+ 'grpc.default_compression_algorithm': compressionAlgorithms.gzip,
79
75
  });
80
- const baseService = new service_1.ProcessorServiceImpl(() => (0, loader_1.load)(options.target), server.shutdown);
81
- const service = new full_service_1.FullProcessorServiceImpl(baseService);
82
- server.add(protos_1.ProcessorDefinition, service);
76
+ // const m = await import(options.target)
77
+ // console.log(m)
78
+ const baseService = new ProcessorServiceImpl(async () => {
79
+ const m = await import(options.target);
80
+ console.log('module loaded');
81
+ return m;
82
+ }, server.shutdown);
83
+ const service = new FullProcessorServiceImpl(baseService);
84
+ server.add(ProcessorDefinition, service);
83
85
  server.listen('0.0.0.0:' + options.port);
84
86
  console.log('Processor Server Started');
85
87
  //# sourceMappingURL=process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pD,oCAAoC,EAAE,8CAAqB,CAAC,IAAI;CACjE,CAAC,CAAA;AAEF,MAAM,WAAW,GAAG,IAAI,8BAAoB,CAAC,GAAG,EAAE,CAAC,IAAA,aAAI,EAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;AACzF,MAAM,OAAO,GAAG,IAAI,uCAAwB,CAAC,WAAW,CAAC,CAAA;AAEzD,MAAM,CAAC,GAAG,CAAC,4BAAmB,EAAE,OAAO,CAAC,CAAA;AAExC,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path'\nimport fs from 'fs-extra'\nimport * as util from 'util'\n\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { createLogger, transports, format } from 'winston'\nimport { CompressionAlgorithms } from '@grpc/grpc-js/build/src/compression-algorithms'\n\nimport { ProcessorDefinition } from '@sentio/protos'\nimport { ProcessorServiceImpl } from './service'\nimport { State } from './state'\nimport { Endpoints } from './endpoints'\n\nimport { load } from './loader'\nimport { FullProcessorServiceImpl } from './full-service'\nimport { ChainConfig } from './chain-config'\n\nState.reset()\n// Endpoints.reset()\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n // { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n { name: 'chainquery-server', type: String, defaultValue: '' },\n { name: 'pricefeed-server', type: String, defaultValue: '' },\n { name: 'log-format', type: String, defaultValue: 'console' },\n { name: 'debug', type: Boolean, defaultValue: false },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nif (options['log-format'] === 'json') {\n const utilFormatter = {\n transform: (info: any) => {\n const args = info[Symbol.for('splat')]\n if (args) {\n info.message = util.format(info.message, ...args)\n }\n return info\n },\n }\n const logger = createLogger({\n format: format.combine(\n format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }),\n utilFormatter,\n format.errors({ stack: true }),\n format.json()\n ),\n transports: [new transports.Console()],\n })\n\n console.log = (...args) => logger.info.call(logger, ...args)\n console.info = (...args) => logger.info.call(logger, ...args)\n console.warn = (...args) => logger.warn.call(logger, ...args)\n console.error = (...args) => logger.error.call(logger, ...args)\n console.debug = (...args) => logger.debug.call(logger, ...args)\n}\nif (options.debug) {\n console.log('Starting with', options.target)\n}\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\n// setProvider(chainsConfig, options.concurrency, options['use-chainserver'])\nEndpoints.INSTANCE.concurrency = options.concurrency\nEndpoints.INSTANCE.chainQueryAPI = options['chainquery-server']\nEndpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']\n\nfor (const [id, config] of Object.entries(chainsConfig)) {\n const chainConfig = config as ChainConfig\n if (chainConfig.ChainServer) {\n Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)\n }\n}\n\nif (options.debug) {\n console.log('Starting Server', options)\n}\n\nconst server = createServer({\n 'grpc.max_send_message_length': 128 * 1024 * 1024,\n 'grpc.max_receive_message_length': 128 * 1024 * 1024,\n 'grpc.default_compression_algorithm': CompressionAlgorithms.gzip,\n})\n\nconst baseService = new ProcessorServiceImpl(() => load(options.target), server.shutdown)\nconst service = new FullProcessorServiceImpl(baseService)\n\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n\nconsole.log('Processor Server Started')\n"]}
1
+ {"version":3,"file":"processor-runner.js","sourceRoot":"","sources":["../src/processor-runner.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OA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AiB,EAAE,OAAO,CAAC,CAAA;CACxC;AAED,MAAM,MAAM,GAAG,YAAY,CAAC;IAC1B,8BAA8B,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI;IACjD,iCAAiC,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI;IACpD,oCAAoC,EAAE,qBAAqB,CAAC,IAAI;CACjE,CAAC,CAAA;AAEF,yCAAyC;AACzC,iBAAiB;AAEjB,MAAM,WAAW,GAAG,IAAI,oBAAoB,CAAC,KAAK,IAAI,EAAE;IACtD,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACtC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;IAC5B,OAAO,CAAC,CAAA;AACV,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;AACnB,MAAM,OAAO,GAAG,IAAI,wBAAwB,CAAC,WAAW,CAAC,CAAA;AAEzD,MAAM,CAAC,GAAG,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAA;AAExC,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path'\nimport fs from 'fs-extra'\nimport * as util from 'util'\n\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { createLogger, transports, format } from 'winston'\nimport { compressionAlgorithms } from '@grpc/grpc-js'\n\nimport { ProcessorDefinition } from '@sentio/protos'\nimport { ProcessorServiceImpl } from './service.js'\nimport { State } from './state.js'\nimport { Endpoints } from './endpoints.js'\n\nimport { FullProcessorServiceImpl } from './full-service.js'\nimport { ChainConfig } from './chain-config.js'\n\nState.reset()\n// Endpoints.reset()\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n // { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n { name: 'chainquery-server', type: String, defaultValue: '' },\n { name: 'pricefeed-server', type: String, defaultValue: '' },\n { name: 'log-format', type: String, defaultValue: 'console' },\n { name: 'debug', type: Boolean, defaultValue: false },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nif (options['log-format'] === 'json') {\n const utilFormatter = {\n transform: (info: any) => {\n const args = info[Symbol.for('splat')]\n if (args) {\n info.message = util.format(info.message, ...args)\n }\n return info\n },\n }\n const logger = createLogger({\n format: format.combine(\n format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }),\n utilFormatter,\n format.errors({ stack: true }),\n format.json()\n ),\n transports: [new transports.Console()],\n })\n\n console.log = (...args) => logger.info.call(logger, ...args)\n console.info = (...args) => logger.info.call(logger, ...args)\n console.warn = (...args) => logger.warn.call(logger, ...args)\n console.error = (...args) => logger.error.call(logger, ...args)\n console.debug = (...args) => logger.debug.call(logger, ...args)\n}\nif (options.debug) {\n console.log('Starting with', options.target)\n}\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\n// setProvider(chainsConfig, options.concurrency, options['use-chainserver'])\nEndpoints.INSTANCE.concurrency = options.concurrency\nEndpoints.INSTANCE.chainQueryAPI = options['chainquery-server']\nEndpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']\n\nfor (const [id, config] of Object.entries(chainsConfig)) {\n const chainConfig = config as ChainConfig\n if (chainConfig.ChainServer) {\n Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)\n }\n}\n\nif (options.debug) {\n console.log('Starting Server', options)\n}\n\nconst server = createServer({\n 'grpc.max_send_message_length': 128 * 1024 * 1024,\n 'grpc.max_receive_message_length': 128 * 1024 * 1024,\n 'grpc.default_compression_algorithm': compressionAlgorithms.gzip,\n})\n\n// const m = await import(options.target)\n// console.log(m)\n\nconst baseService = new ProcessorServiceImpl(async () => {\n const m = await import(options.target)\n console.log('module loaded')\n return m\n}, server.shutdown)\nconst service = new FullProcessorServiceImpl(baseService)\n\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n\nconsole.log('Processor Server Started')\n"]}
package/lib/service.d.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { CallContext } from 'nice-grpc';
2
- import { DataBinding, ProcessBindingResponse, ProcessBindingsRequest, ProcessConfigRequest, ProcessConfigResponse, ProcessorServiceImplementation, ProcessResult, StartRequest } from '@sentio/protos';
3
- import { Empty } from '@sentio/protos/lib/google/protobuf/empty';
2
+ import { DataBinding, ProcessBindingResponse, ProcessBindingsRequest, ProcessConfigRequest, ProcessConfigResponse, ProcessorServiceImplementation, ProcessResult, StartRequest, Empty } from '@sentio/protos';
4
3
  export declare class ProcessorServiceImpl implements ProcessorServiceImplementation {
5
4
  private started;
6
5
  private processorConfig;
7
6
  private readonly loader;
8
7
  private readonly shutdownHandler?;
9
- constructor(loader: () => void, shutdownHandler?: () => void);
8
+ constructor(loader: () => Promise<any>, shutdownHandler?: () => void);
10
9
  getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse>;
11
10
  configure(): Promise<void>;
12
11
  start(request: StartRequest, context: CallContext): Promise<Empty>;
package/lib/service.js CHANGED
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProcessorServiceImpl = void 0;
4
- const nice_grpc_1 = require("nice-grpc");
5
- const protos_1 = require("@sentio/protos");
6
- const plugin_1 = require("./plugin");
7
- const utils_1 = require("./utils");
1
+ import { ServerError, Status } from 'nice-grpc';
2
+ import { ProcessConfigResponse, } from '@sentio/protos';
3
+ import { PluginManager } from './plugin.js';
4
+ import { errorString, mergeProcessResults } from './utils.js';
8
5
  BigInt.prototype.toJSON = function () {
9
6
  return this.toString();
10
7
  };
11
- class ProcessorServiceImpl {
8
+ export class ProcessorServiceImpl {
12
9
  started = false;
13
10
  processorConfig;
14
11
  loader;
@@ -19,49 +16,47 @@ class ProcessorServiceImpl {
19
16
  }
20
17
  async getConfig(request, context) {
21
18
  if (!this.started) {
22
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service Not started.');
19
+ throw new ServerError(Status.UNAVAILABLE, 'Service Not started.');
23
20
  }
24
21
  if (!this.processorConfig) {
25
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'Process config empty.');
22
+ throw new ServerError(Status.INTERNAL, 'Process config empty.');
26
23
  }
27
24
  return this.processorConfig;
28
25
  }
29
26
  async configure() {
30
- this.processorConfig = protos_1.ProcessConfigResponse.fromPartial({});
31
- await plugin_1.PluginManager.INSTANCE.configure(this.processorConfig);
27
+ this.processorConfig = ProcessConfigResponse.fromPartial({});
28
+ await PluginManager.INSTANCE.configure(this.processorConfig);
32
29
  }
33
30
  async start(request, context) {
34
31
  if (this.started) {
35
32
  return {};
36
33
  }
37
34
  try {
38
- // for (const plugin of ['@sentio/sdk/lib/core/core-plugin', '@sentio/sdk/lib/core/eth-plugin']) {
39
- // try {
40
- // require(plugin)
41
- // } catch (e) {
42
- // console.error('Failed to load plugin: ', plugin)
43
- // }
44
- // }
45
- // for (const plugin of [
46
- // '@sentio/sdk/lib/core/sui-plugin',
47
- // '@sentio/sdk-aptos/lib/aptos-plugin',
48
- // '@sentio/sdk-solana/lib/solana-plugin',
49
- // ]) {
50
- // try {
51
- // require(plugin)
52
- // } catch (e) {}
53
- // }
54
- this.loader();
35
+ for (const plugin of ['@sentio/sdk']) {
36
+ try {
37
+ await import(plugin);
38
+ }
39
+ catch (e) {
40
+ console.error('Failed to load plugin: ', plugin);
41
+ }
42
+ }
43
+ for (const plugin of ['@sentio/sdk-aptos', '@sentio/sdk-solana']) {
44
+ try {
45
+ await import(plugin);
46
+ }
47
+ catch (e) { }
48
+ }
49
+ await this.loader();
55
50
  }
56
51
  catch (e) {
57
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Failed to load processor: ' + (0, utils_1.errorString)(e));
52
+ throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e));
58
53
  }
59
- await plugin_1.PluginManager.INSTANCE.start(request);
54
+ await PluginManager.INSTANCE.start(request);
60
55
  try {
61
56
  await this.configure();
62
57
  }
63
58
  catch (e) {
64
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'Failed to start processor : ' + (0, utils_1.errorString)(e));
59
+ throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + errorString(e));
65
60
  }
66
61
  this.started = true;
67
62
  return {};
@@ -75,12 +70,12 @@ class ProcessorServiceImpl {
75
70
  }
76
71
  async processBindings(request, options) {
77
72
  if (!this.started) {
78
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service Not started.');
73
+ throw new ServerError(Status.UNAVAILABLE, 'Service Not started.');
79
74
  }
80
75
  const promises = request.bindings.map((binding) => this.processBinding(binding));
81
- const result = (0, utils_1.mergeProcessResults)(await Promise.all(promises));
76
+ const result = mergeProcessResults(await Promise.all(promises));
82
77
  let updated = false;
83
- if (plugin_1.PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
78
+ if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
84
79
  await this.configure();
85
80
  updated = true;
86
81
  }
@@ -90,7 +85,7 @@ class ProcessorServiceImpl {
90
85
  };
91
86
  }
92
87
  async processBinding(request, options) {
93
- const result = await plugin_1.PluginManager.INSTANCE.processBinding(request);
88
+ const result = await PluginManager.INSTANCE.processBinding(request);
94
89
  recordRuntimeInfo(result, request.handlerType);
95
90
  return result;
96
91
  }
@@ -98,7 +93,7 @@ class ProcessorServiceImpl {
98
93
  for await (const request of requests) {
99
94
  const result = await this.processBinding(request);
100
95
  let updated = false;
101
- if (plugin_1.PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
96
+ if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
102
97
  await this.configure();
103
98
  updated = true;
104
99
  }
@@ -109,7 +104,6 @@ class ProcessorServiceImpl {
109
104
  }
110
105
  }
111
106
  }
112
- exports.ProcessorServiceImpl = ProcessorServiceImpl;
113
107
  function recordRuntimeInfo(results, handlerType) {
114
108
  for (const list of [results.gauges, results.counters, results.logs, results.events, results.exports]) {
115
109
  list.forEach((e) => {
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;AAAA,yCAA4D;AAE5D,2CAUuB;AAIvB,qCAAwC;AACxC,mCAEC;AAAC,MAAM,CAAC,SAAiB,CAAC,MAAM,GAAG;IAClC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;AACxB,CAAC,CAAA;AAED,MAAa,oBAAoB;IACvB,OAAO,GAAG,KAAK,CAAA;IACf,eAAe,CAAuB;IAE7B,MAAM,CAAY;IAElB,eAAe,CAAa;IAE7C,YAAY,MAAkB,EAAE,eAA4B;QAC1D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAA6B,EAAE,OAAoB;QACjE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,IAAI,uBAAW,CAAC,kBAAM,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAA;SAClE;QACD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,MAAM,IAAI,uBAAW,CAAC,kBAAM,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAA;SAChE;QACD,OAAO,IAAI,CAAC,eAAe,CAAA;IAC7B,CAAC;IAED,KAAK,CAAC,SAAS;QACb,IAAI,CAAC,eAAe,GAAG,8BAAqB,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;QAC5D,MAAM,sBAAa,CAAC,QA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CAAA;aACf;YACD,MAAM;gBACJ,MAAM;gBACN,aAAa,EAAE,OAAO;aACvB,CAAA;SACF;IACH,CAAC;CACF;AApHD,oDAoHC;AAED,SAAS,iBAAiB,CAAC,OAAsB,EAAE,WAAwB;IACzE,KAAK,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;QACpG,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} from '@sentio/protos'\n\nimport { Empty } from '@sentio/protos/lib/google/protobuf/empty'\n\nimport { PluginManager } from './plugin'\nimport { errorString, mergeProcessResults } from './utils'\n\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: () => void\n\n private readonly shutdownHandler?: () => void\n\n constructor(loader: () => void, 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 return this.processorConfig\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/lib/core/core-plugin', '@sentio/sdk/lib/core/eth-plugin']) {\n // try {\n // require(plugin)\n // } catch (e) {\n // console.error('Failed to load plugin: ', plugin)\n // }\n // }\n\n // for (const plugin of [\n // '@sentio/sdk/lib/core/sui-plugin',\n // '@sentio/sdk-aptos/lib/aptos-plugin',\n // '@sentio/sdk-solana/lib/solana-plugin',\n // ]) {\n // try {\n // require(plugin)\n // } catch (e) {}\n // }\n\n 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 const result = mergeProcessResults(await Promise.all(promises))\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 configUpdated: updated,\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: updated,\n }\n }\n }\n}\n\nfunction recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {\n for (const list of [results.gauges, results.counters, results.logs, results.events, results.exports]) {\n list.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n }\n}\n"]}
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;IACf,eAAe,CAAuB;IAE7B,MAAM,CAAoB;IAE1B,eAAe,CAAa;IAE7C,YAAY,MAA0B,EAAE,eAA4B;QAClE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAA6B,EAAE,OAAoB;QACjE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,WAAW,EAAE,sBAAsB,CAAC,CAAA;SAClE;QACD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAA;SAChE;QACD,OAAO,IAAI,CAAC,eAAe,CAAA;IAC7B,CAAC;IAED,KAAK,CAAC,SAAS;QACb,IAAI,CAAC,eAAe,GAAG,qBAAqB,CAAC,WAAW,C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,CAAA;YACjD,IAAI,OAAO,GAAG,KAAK,CAAA;YACnB,IAAI,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE;gBAC1D,MAAM,IAAI,CAAC,SAAS,EAAE,CAAA;gBACtB,OAAO,GAAG,IAAI,CAAA;aACf;YACD,MAAM;gBACJ,MAAM;gBACN,aAAa,EAAE,OAAO;aACvB,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,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;QACpG,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 return this.processorConfig\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']) {\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 const result = mergeProcessResults(await Promise.all(promises))\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 configUpdated: updated,\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: updated,\n }\n }\n }\n}\n\nfunction recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {\n for (const list of [results.gauges, results.counters, results.logs, results.events, results.exports]) {\n list.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"service.test.js","sourceRoot":"","sources":["../src/service.test.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAChD,iDAAyD;AAEzD,gEAA0F;AAC1F,qCAAgD;AAChD,+BAA6B;AAEhB,QAAA,YAAY,GAA6B,EAAE,CAAA;AAExD,gBAAgB;AAChB,IAAI,WAAwB,CAAA;AAE5B,MAAM,UAAW,SAAQ,eAAM;IAC7B,KAAK,CAAC,cAAc,CAAC,OAAoB;QACvC,WAAW,GAAG,OAAO,CAAA;QACrB,OAAO,yBAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IACtC,CAAC;IACD,iBAAiB,GAAG,CAAC,uBAAW,CAAC,OAAO,EAAE,uBAAW,CAAC,SAAS,CAAC,CAAA;CACjE;AAED,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,MAAM,WAAW,GAAG,IAAI,8BAAoB,CAAC,GAAG,EAAE;QAChD,sBAAa,CAAC,QAAQ,CAAC,OAAO,GAAG,EAAE,CAAA;QACnC,sBAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,UAAU,EAAE,CAAC,CAAA;IACnD,CAAC,CAAC,CAAA;IACF,MAAM,OAAO,GAAG,IAAI,uCAAwB,CAAC,WAAW,CAAC,CAAA;IAEzD,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,OAAO,CAAC,KAAK,CAAC,EAAE,iBAAiB,EAAE,EAAE,EAAE,EAAE,oBAAY,CAAC,CAAA;IAC9D,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,4BAA4B,EAAE,KAAK,IAAI,EA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IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;IAC7E,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;QACpD,MAAM,QAAQ,GAAgB;YAC5B,IAAI,EAAE;gBACJ,GAAG,EAAE,IAAI,UAAU,EAAE;gBACrB,QAAQ,EAAE;oBACR,KAAK,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE;oBACvB,WAAW,EAAE;wBACX,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;qBACnD;iBACF;aACF;YACD,WAAW,EAAE,uBAAW,CAAC,SAAS;YAClC,UAAU,EAAE,CAAC,CAAC,CAAC;SAChB,CAAA;QAED,OAAO,CAAC,eAAe,GAAG,EAAE,CAAA;QAC5B,MAAM,OAAO,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,oBAAY,CAAC,CAAA;QACrE,IAAA,aAAM,EAAC,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;IAC7E,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { ProcessorServiceImpl } from './service'\nimport { FullProcessorServiceImpl } from './full-service'\nimport { CallContext } from 'nice-grpc-common'\nimport { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor'\nimport { Plugin, PluginManager } from './plugin'\nimport { assert } from 'chai'\n\nexport const TEST_CONTEXT: CallContext = <CallContext>{}\n\n// TODO use mock\nlet testRequest: DataBinding\n\nclass TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n testRequest = request\n return ProcessResult.fromPartial({})\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.APT_EVENT]\n}\n\ndescribe('Test Service Compatibility', () => {\n const baseService = new ProcessorServiceImpl(() => {\n PluginManager.INSTANCE.plugins = []\n PluginManager.INSTANCE.register(new TestPlugin())\n })\n const service = new FullProcessorServiceImpl(baseService)\n\n beforeAll(async () => {\n await service.start({ templateInstances: [] }, TEST_CONTEXT)\n })\n\n test('Check transaction dispatch', async () => {\n const binding1: DataBinding = {\n data: {\n raw: new Uint8Array(),\n ethBlock: {\n block: {\n number: '0x1',\n },\n },\n },\n handlerType: HandlerType.UNKNOWN,\n handlerIds: [0],\n }\n\n await service.processBindings({ bindings: [binding1] }, TEST_CONTEXT)\n assert(testRequest.handlerType === HandlerType.UNKNOWN)\n assert((testRequest.data?.raw.length || 0) > 0)\n })\n\n test('Check < 1.40 aptos event dispatch', async () => {\n const binding1: DataBinding = {\n data: {\n raw: new Uint8Array(),\n aptEvent: {\n event: { key: 'value' },\n transaction: {\n events: [{ a: 'b' }, { c: 'd' }, { key: 'value' }],\n },\n },\n },\n handlerType: HandlerType.APT_EVENT,\n handlerIds: [0],\n }\n\n await service.processBindings({ bindings: [binding1] }, TEST_CONTEXT)\n assert((testRequest.data?.aptEvent?.transaction?.events.length || 0) === 1)\n })\n\n test('Check >= 1.40 aptos event dispatch', async () => {\n const binding1: DataBinding = {\n data: {\n raw: new Uint8Array(),\n aptEvent: {\n event: { key: 'value' },\n transaction: {\n events: [{ a: 'b' }, { c: 'd' }, { key: 'value' }],\n },\n },\n },\n handlerType: HandlerType.APT_EVENT,\n handlerIds: [0],\n }\n\n service.sdkMinorVersion = 40\n await service.processBindings({ bindings: [binding1] }, TEST_CONTEXT)\n assert((testRequest.data?.aptEvent?.transaction?.events.length || 0) === 3)\n })\n})\n"]}
1
+ {"version":3,"file":"service.test.js","sourceRoot":"","sources":["../src/service.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,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WAAW,CAAC,OAAO;YAChC,UAAU,EAAE,CAAC,CAAC,CAAC;SAChB,CAAA;QAED,MAAM,OAAO,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,YAAY,CAAC,CAAA;QACrE,MAAM,CAAC,WAAW,CAAC,WAAW,KAAK,WAAW,CAAC,OAAO,CAAC,CAAA;QACvD,MAAM,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { ProcessorServiceImpl } from './service.js'\nimport { FullProcessorServiceImpl } from './full-service.js'\nimport { CallContext } from 'nice-grpc-common'\nimport { DataBinding, HandlerType, ProcessResult } from './gen/processor/protos/processor.js'\nimport { Plugin, PluginManager } from './plugin.js'\nimport { assert } from 'chai'\n\nexport const TEST_CONTEXT: CallContext = <CallContext>{}\n\n// TODO use mock\nlet testRequest: DataBinding\n\nclass TestPlugin extends Plugin {\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n testRequest = request\n return ProcessResult.fromPartial({})\n }\n supportedHandlers = [HandlerType.UNKNOWN, HandlerType.APT_EVENT]\n}\n\ndescribe('Test Service Compatibility', () => {\n const baseService = new ProcessorServiceImpl(async () => {\n PluginManager.INSTANCE.plugins = []\n PluginManager.INSTANCE.register(new TestPlugin())\n })\n const service = new FullProcessorServiceImpl(baseService)\n\n beforeAll(async () => {\n await service.start({ templateInstances: [] }, TEST_CONTEXT)\n })\n\n test('Check transaction dispatch', async () => {\n const binding1: DataBinding = {\n data: {\n raw: new Uint8Array(),\n ethBlock: {\n block: {\n number: '0x1',\n },\n },\n },\n handlerType: HandlerType.UNKNOWN,\n handlerIds: [0],\n }\n\n await service.processBindings({ bindings: [binding1] }, TEST_CONTEXT)\n assert(testRequest.handlerType === HandlerType.UNKNOWN)\n assert((testRequest.data?.raw.length || 0) > 0)\n })\n})\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"state-storage.test.js","sourceRoot":"","sources":["../src/state-storage.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,mCAAgD;AAEhD,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,aAAK,CAAC,KAAK,EAAE,CAAA;IAEb,IAAI,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC7B,MAAM,SAAU,SAAQ,uBAAoB;YAC1C,MAAM,CAAC,QAAQ,GAAG,IAAI,SAAS,EAAE,CAAA;;QAEnC,MAAM,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAA;QAC5C,IAAA,aAAM,EAAC,CAAC,KAAK,SAAS,CAAC,CAAA;QAEvB,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QACrD,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;QAC5D,IAAA,aAAM,EAAC,EAAE,KAAK,EAAE,CAAC,CAAA;QACjB,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAE5C,IAAA,aAAM,EAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAA;QACnD,IAAA,aAAM,EAAC,aAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,CAAC,CAAA;QAC1C,IAAA,aAAM,EAAC,aAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,KAAK,WAAW,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { assert } from 'chai'\nimport { State, MapStateStorage } from './state'\n\ndescribe('state storage tests', () => {\n State.reset()\n\n test('test labels', async () => {\n class TestState extends MapStateStorage<any> {\n static INSTANCE = new TestState()\n }\n const m = TestState.INSTANCE.getOrRegister()\n assert(m !== undefined)\n\n const v1 = TestState.INSTANCE.getOrSetValue('k1', {})\n const v2 = TestState.INSTANCE.getOrSetValue('k1', { a: '' })\n assert(v1 === v2)\n TestState.INSTANCE.getOrSetValue('k2', 'v2')\n\n assert(TestState.INSTANCE.getValues().length === 2)\n assert(State.INSTANCE.stateMap.size === 1)\n assert(State.INSTANCE.stateMap.keys().next().value === 'TestState')\n })\n})\n"]}
1
+ {"version":3,"file":"state-storage.test.js","sourceRoot":"","sources":["../src/state-storage.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEnD,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,KAAK,CAAC,KAAK,EAAE,CAAA;IAEb,IAAI,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC7B,gBAAgB;QAChB,MAAM,SAAU,SAAQ,eAAoB;YAC1C,MAAM,CAAC,QAAQ,GAAG,IAAI,SAAS,EAAE,CAAA;;QAEnC,MAAM,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAA;QAC5C,MAAM,CAAC,CAAC,KAAK,SAAS,CAAC,CAAA;QAEvB,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QACrD,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;QAC5D,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;QACjB,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAE5C,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAA;QACnD,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,CAAC,CAAA;QAC1C,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,KAAK,WAAW,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { assert } from 'chai'\nimport { State, MapStateStorage } from './state.js'\n\ndescribe('state storage tests', () => {\n State.reset()\n\n test('test labels', async () => {\n // assert(false)\n class TestState extends MapStateStorage<any> {\n static INSTANCE = new TestState()\n }\n const m = TestState.INSTANCE.getOrRegister()\n assert(m !== undefined)\n\n const v1 = TestState.INSTANCE.getOrSetValue('k1', {})\n const v2 = TestState.INSTANCE.getOrSetValue('k1', { a: '' })\n assert(v1 === v2)\n TestState.INSTANCE.getOrSetValue('k2', 'v2')\n\n assert(TestState.INSTANCE.getValues().length === 2)\n assert(State.INSTANCE.stateMap.size === 1)\n assert(State.INSTANCE.stateMap.keys().next().value === 'TestState')\n })\n})\n"]}
package/lib/state.js CHANGED
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ListStateStorage = exports.MapStateStorage = exports.StateStorage = exports.State = void 0;
4
- class State {
1
+ export class State {
5
2
  stateMap = new Map();
6
3
  static INSTANCE = new State();
7
4
  static reset() {
8
5
  State.INSTANCE = new State();
9
6
  }
10
7
  }
11
- exports.State = State;
12
- class StateStorage {
8
+ export class StateStorage {
13
9
  // TODO learn how to define single instance for all subclasses
14
10
  constructor() {
15
11
  //
@@ -26,8 +22,7 @@ class StateStorage {
26
22
  return metricState;
27
23
  }
28
24
  }
29
- exports.StateStorage = StateStorage;
30
- class MapStateStorage extends StateStorage {
25
+ export class MapStateStorage extends StateStorage {
31
26
  initValue() {
32
27
  return new Map();
33
28
  }
@@ -50,8 +45,7 @@ class MapStateStorage extends StateStorage {
50
45
  return value;
51
46
  }
52
47
  }
53
- exports.MapStateStorage = MapStateStorage;
54
- class ListStateStorage extends StateStorage {
48
+ export class ListStateStorage extends StateStorage {
55
49
  initValue() {
56
50
  return [];
57
51
  }
@@ -64,5 +58,4 @@ class ListStateStorage extends StateStorage {
64
58
  return value;
65
59
  }
66
60
  }
67
- exports.ListStateStorage = ListStateStorage;
68
61
  //# sourceMappingURL=state.js.map
package/lib/state.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":";;;AAAA,MAAa,KAAK;IAChB,QAAQ,GAAG,IAAI,GAAG,EAAe,CAAA;IAEjC,MAAM,CAAC,QAAQ,GAAG,IAAI,KAAK,EAAE,CAAA;IAE7B,MAAM,CAAC,KAAK;QACV,KAAK,CAAC,QAAQ,GAAG,IAAI,KAAK,EAAE,CAAA;IAC9B,CAAC;;AAPH,sBAQC;AAED,MAAsB,YAAY;IAChC,8DAA8D;IAE9D;QACE,EAAE;IACJ,CAAC;IAID,GAAG;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAED,aAAa;QACX,IAAI,WAAW,GAAM,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAC5D,IAAI,CAAC,WAAW,EAAE;YAChB,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;YAC9B,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,CAAA;SACrD;QACD,OAAO,WAAW,CAAA;IACpB,CAAC;CACF;AArBD,oCAqBC;AAED,MAAsB,eAAmB,SAAQ,YAA4B;IAC3E,SAAS;QACP,OAAO,IAAI,GAAG,EAAa,CAAA;IAC7B,CAAC;IAED,QAAQ,CAAC,GAAW;QAClB,MAAM,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,CAAA;QAC9B,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACnB,CAAC;IAED,SAAS;QACP,MAAM,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,CAAA;QAC9B,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAA;IAC/B,CAAC;IAED,aAAa,CAAC,GAAW,EAAE,KAAQ;QACjC,MAAM,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,CAAA;QAC9B,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,QAAQ,EAAE;YACZ,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,iDAAiD,CAAC,CAAA;YACpE,OAAO,QAAQ,CAAA;SAChB;QACD,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACjB,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAzBD,0CAyBC;AAED,MAAsB,gBAAoB,SAAQ,YAAiB;IACjE,SAAS;QACP,OAAO,EAAE,CAAA;IACX,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,aAAa,EAAE,CAAA;IAC7B,CAAC;IAED,QAAQ,CAAC,KAAQ;QACf,MAAM,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,CAAA;QAC9B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACb,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAdD,4CAcC","sourcesContent":["export class State {\n stateMap = new Map<string, any>()\n\n static INSTANCE = new State()\n\n static reset() {\n State.INSTANCE = new State()\n }\n}\n\nexport abstract class StateStorage<T> {\n // TODO learn how to define single instance for all subclasses\n\n protected constructor() {\n //\n }\n\n abstract initValue(): T\n\n key(): string {\n return this.constructor.name\n }\n\n getOrRegister(): T {\n let metricState: T = State.INSTANCE.stateMap.get(this.key())\n if (!metricState) {\n metricState = this.initValue()\n State.INSTANCE.stateMap.set(this.key(), metricState)\n }\n return metricState\n }\n}\n\nexport abstract class MapStateStorage<T> extends StateStorage<Map<string, T>> {\n initValue() {\n return new Map<string, T>()\n }\n\n getValue(key: string): T | undefined {\n const m = this.getOrRegister()\n return m.get(key)\n }\n\n getValues(): T[] {\n const m = this.getOrRegister()\n return Array.from(m.values())\n }\n\n getOrSetValue(key: string, value: T): T {\n const m = this.getOrRegister()\n const oldValue = m.get(key)\n if (oldValue) {\n console.warn(key, 'has been registered twice, use the previous one')\n return oldValue\n }\n m.set(key, value)\n return value\n }\n}\n\nexport abstract class ListStateStorage<T> extends StateStorage<T[]> {\n initValue() {\n return []\n }\n\n getValues(): T[] {\n return this.getOrRegister()\n }\n\n addValue(value: T): T {\n const m = this.getOrRegister()\n m.push(value)\n return value\n }\n}\n"]}
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,KAAK;IAChB,QAAQ,GAAG,IAAI,GAAG,EAAe,CAAA;IAEjC,MAAM,CAAC,QAAQ,GAAG,IAAI,KAAK,EAAE,CAAA;IAE7B,MAAM,CAAC,KAAK;QACV,KAAK,CAAC,QAAQ,GAAG,IAAI,KAAK,EAAE,CAAA;IAC9B,CAAC;;AAGH,MAAM,OAAgB,YAAY;IAChC,8DAA8D;IAE9D;QACE,EAAE;IACJ,CAAC;IAID,GAAG;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAED,aAAa;QACX,IAAI,WAAW,GAAM,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAC5D,IAAI,CAAC,WAAW,EAAE;YAChB,WAAW,GAAG,IAAI,C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,OAAO,KAAK,CAAA;IACd,CAAC;CACF","sourcesContent":["export class State {\n stateMap = new Map<string, any>()\n\n static INSTANCE = new State()\n\n static reset() {\n State.INSTANCE = new State()\n }\n}\n\nexport abstract class StateStorage<T> {\n // TODO learn how to define single instance for all subclasses\n\n protected constructor() {\n //\n }\n\n abstract initValue(): T\n\n key(): string {\n return this.constructor.name\n }\n\n getOrRegister(): T {\n let metricState: T = State.INSTANCE.stateMap.get(this.key())\n if (!metricState) {\n metricState = this.initValue()\n State.INSTANCE.stateMap.set(this.key(), metricState)\n }\n return metricState\n }\n}\n\nexport abstract class MapStateStorage<T> extends StateStorage<Map<string, T>> {\n initValue() {\n return new Map<string, T>()\n }\n\n getValue(key: string): T | undefined {\n const m = this.getOrRegister()\n return m.get(key)\n }\n\n getValues(): T[] {\n const m = this.getOrRegister()\n return Array.from(m.values())\n }\n\n getOrSetValue(key: string, value: T): T {\n const m = this.getOrRegister()\n const oldValue = m.get(key)\n if (oldValue) {\n console.warn(key, 'has been registered twice, use the previous one')\n return oldValue\n }\n m.set(key, value)\n return value\n }\n}\n\nexport abstract class ListStateStorage<T> extends StateStorage<T[]> {\n initValue() {\n return []\n }\n\n getValues(): T[] {\n return this.getOrRegister()\n }\n\n addValue(value: T): T {\n const m = this.getOrRegister()\n m.push(value)\n return value\n }\n}\n"]}
package/lib/utils.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USER_PROCESSOR = exports.errorString = exports.mergeProcessResults = void 0;
4
- const protos_1 = require("@sentio/protos");
5
- function mergeProcessResults(results) {
6
- const res = protos_1.ProcessResult.fromPartial({});
1
+ import { ProcessResult } from '@sentio/protos';
2
+ export function mergeProcessResults(results) {
3
+ const res = ProcessResult.fromPartial({});
7
4
  for (const r of results) {
8
5
  res.counters = res.counters.concat(r.counters);
9
6
  res.gauges = res.gauges.concat(r.gauges);
@@ -13,10 +10,8 @@ function mergeProcessResults(results) {
13
10
  }
14
11
  return res;
15
12
  }
16
- exports.mergeProcessResults = mergeProcessResults;
17
- function errorString(e) {
13
+ export function errorString(e) {
18
14
  return e.stack || e.message;
19
15
  }
20
- exports.errorString = errorString;
21
- exports.USER_PROCESSOR = 'user_processor';
16
+ export const USER_PROCESSOR = 'user_processor';
22
17
  //# sourceMappingURL=utils.js.map
package/lib/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,2CAA8C;AAE9C,SAAgB,mBAAmB,CAAC,OAAwB;IAC1D,MAAM,GAAG,GAAG,sBAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IAEzC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;QACvB,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;QAC9C,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QACxC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAClC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QACxC,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;KAC5C;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAXD,kDAWC;AAED,SAAgB,WAAW,CAAC,CAAQ;IAClC,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,CAAA;AAC7B,CAAC;AAFD,kCAEC;AAEY,QAAA,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.logs = res.logs.concat(r.logs)\n res.events = res.events.concat(r.events)\n res.exports = res.exports.concat(r.exports)\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"]}
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,OAAO,EAAE;QACvB,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;QAC9C,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QACxC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAClC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QACxC,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;KAC5C;IACD,OAAO,GAAG,CAAA;AACZ,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.logs = res.logs.concat(r.logs)\n res.events = res.events.concat(r.events)\n res.exports = res.exports.concat(r.exports)\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"]}