@sentio/runtime 2.61.0-rc.9 → 2.61.1-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.
@@ -1,7 +1,7 @@
1
1
  import { createRequire as createRequireShim } from 'module'; const require = createRequireShim(import.meta.url);
2
2
  import {
3
3
  setupLogger
4
- } from "./chunk-2LXJZQSF.js";
4
+ } from "./chunk-DPHTMNDV.js";
5
5
  import {
6
6
  ProcessorServiceImpl,
7
7
  configureEndpoints,
@@ -10,10 +10,10 @@ import {
10
10
  require_cjs,
11
11
  require_lib3 as require_lib,
12
12
  require_lib4 as require_lib2
13
- } from "./chunk-XIU7XZT7.js";
13
+ } from "./chunk-NVBA53K5.js";
14
14
  import {
15
15
  __toESM
16
- } from "./chunk-J4QKUO6L.js";
16
+ } from "./chunk-4M76KZSL.js";
17
17
 
18
18
  // src/service-worker.ts
19
19
  var import_nice_grpc = __toESM(require_lib(), 1);
@@ -1,4 +1,4 @@
1
- import { P as Plugin, c as DataBinding, d as ProcessResult, H as HandlerType } from './processor-Cbun9NKJ.js';
1
+ import { P as Plugin, c as DataBinding, d as ProcessResult, H as HandlerType } from './processor-DwZlMkFj.js';
2
2
  import { ProcessStreamResponse_Partitions, InitResponse, ProcessConfigResponse } from '@sentio/protos';
3
3
  import 'rxjs';
4
4
  import 'node:async_hooks';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
- "version": "2.61.0-rc.9",
3
+ "version": "2.61.1-rc.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
package/src/db-context.ts CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  DeepPartial,
7
7
  ProcessResult,
8
8
  ProcessStreamResponse,
9
- ProcessStreamResponseV2,
9
+ ProcessStreamResponseV3,
10
10
  TemplateInstance,
11
11
  TimeseriesResult
12
12
  } from '@sentio/protos'
@@ -257,7 +257,7 @@ export class StoreContext extends AbstractStoreContext {
257
257
  export class DataBindingContext extends AbstractStoreContext implements IDataBindingContext {
258
258
  constructor(
259
259
  readonly processId: number,
260
- readonly subject: Subject<DeepPartial<ProcessStreamResponseV2>>
260
+ readonly subject: Subject<DeepPartial<ProcessStreamResponseV3>>
261
261
  ) {
262
262
  super(processId)
263
263
  }
@@ -279,7 +279,7 @@ export class DataBindingContext extends AbstractStoreContext implements IDataBin
279
279
  })
280
280
  }
281
281
 
282
- doSend(resp: DeepPartial<ProcessStreamResponseV2>) {
282
+ doSend(resp: DeepPartial<ProcessStreamResponseV3>) {
283
283
  console.debug('sending db request, processId ', this.processId, 'opId', resp.dbRequest?.opId)
284
284
  this.subject.next({
285
285
  ...resp,
@@ -2,11 +2,9 @@ import { CallContext } from 'nice-grpc'
2
2
  import { createRequire } from 'module'
3
3
  // Different than the simple one which
4
4
  import {
5
- ConfigureHandlersRequest,
6
5
  DataBinding,
7
6
  ExecutionConfig,
8
7
  HandlerType,
9
- InitResponse,
10
8
  PreprocessStreamRequest,
11
9
  ProcessBindingsRequest,
12
10
  ProcessConfigRequest,
@@ -17,7 +15,7 @@ import {
17
15
  StartRequest
18
16
  } from './gen/processor/protos/processor.js'
19
17
 
20
- import { ConfigureHandlersResponse, DeepPartial, Empty, ProcessorV3ServiceImplementation } from '@sentio/protos'
18
+ import { DeepPartial, Empty, ProcessorV3ServiceImplementation, UpdateTemplatesRequest } from '@sentio/protos'
21
19
  import fs from 'fs-extra'
22
20
  import path from 'path'
23
21
  import os from 'os'
@@ -415,17 +413,12 @@ export class FullProcessorServiceV3Impl implements ProcessorV3ServiceImplementat
415
413
 
416
414
  constructor(readonly instance: ProcessorV3ServiceImplementation) {}
417
415
 
418
- async init(request: Empty, context: CallContext): Promise<DeepPartial<InitResponse>> {
419
- const resp = await this.instance.init(request, context)
420
- resp.executionConfig = ExecutionConfig.fromPartial(GLOBAL_CONFIG.execution)
421
- return resp
416
+ async start(request: StartRequest, context: CallContext): Promise<DeepPartial<Empty>> {
417
+ return this.instance.start(request, context)
422
418
  }
423
419
 
424
- async configureHandlers(
425
- request: ConfigureHandlersRequest,
426
- context: CallContext
427
- ): Promise<DeepPartial<ConfigureHandlersResponse>> {
428
- const config = await this.instance.configureHandlers(request, context)
420
+ async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<DeepPartial<ProcessConfigResponse>> {
421
+ const config = await this.instance.getConfig(request, context)
429
422
  this.patcher.patchConfig(config)
430
423
  return config
431
424
  }
@@ -440,4 +433,8 @@ export class FullProcessorServiceV3Impl implements ProcessorV3ServiceImplementat
440
433
  yield request
441
434
  }
442
435
  }
436
+
437
+ async updateTemplates(request: UpdateTemplatesRequest, context: CallContext): Promise<DeepPartial<Empty>> {
438
+ return this.instance.updateTemplates(request, context)
439
+ }
443
440
  }
@@ -680,7 +680,7 @@ export interface InitResponse {
680
680
  eventLogConfigs: EventLogConfig[];
681
681
  }
682
682
 
683
- export interface ConfigureHandlersRequest {
683
+ export interface UpdateTemplatesRequest {
684
684
  chainId: string;
685
685
  templateInstances: TemplateInstance[];
686
686
  }
@@ -999,7 +999,7 @@ export interface ProcessStreamResponse_Partitions_PartitionsEntry {
999
999
  value: ProcessStreamResponse_Partitions_Partition | undefined;
1000
1000
  }
1001
1001
 
1002
- export interface ProcessStreamResponseV2 {
1002
+ export interface ProcessStreamResponseV3 {
1003
1003
  processId: number;
1004
1004
  partitions?: ProcessStreamResponse_Partitions | undefined;
1005
1005
  dbRequest?: DBRequest | undefined;
@@ -4662,12 +4662,12 @@ export const InitResponse = {
4662
4662
  },
4663
4663
  };
4664
4664
 
4665
- function createBaseConfigureHandlersRequest(): ConfigureHandlersRequest {
4665
+ function createBaseUpdateTemplatesRequest(): UpdateTemplatesRequest {
4666
4666
  return { chainId: "", templateInstances: [] };
4667
4667
  }
4668
4668
 
4669
- export const ConfigureHandlersRequest = {
4670
- encode(message: ConfigureHandlersRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
4669
+ export const UpdateTemplatesRequest = {
4670
+ encode(message: UpdateTemplatesRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
4671
4671
  if (message.chainId !== "") {
4672
4672
  writer.uint32(10).string(message.chainId);
4673
4673
  }
@@ -4677,10 +4677,10 @@ export const ConfigureHandlersRequest = {
4677
4677
  return writer;
4678
4678
  },
4679
4679
 
4680
- decode(input: _m0.Reader | Uint8Array, length?: number): ConfigureHandlersRequest {
4680
+ decode(input: _m0.Reader | Uint8Array, length?: number): UpdateTemplatesRequest {
4681
4681
  const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
4682
4682
  let end = length === undefined ? reader.len : reader.pos + length;
4683
- const message = createBaseConfigureHandlersRequest();
4683
+ const message = createBaseUpdateTemplatesRequest();
4684
4684
  while (reader.pos < end) {
4685
4685
  const tag = reader.uint32();
4686
4686
  switch (tag >>> 3) {
@@ -4707,7 +4707,7 @@ export const ConfigureHandlersRequest = {
4707
4707
  return message;
4708
4708
  },
4709
4709
 
4710
- fromJSON(object: any): ConfigureHandlersRequest {
4710
+ fromJSON(object: any): UpdateTemplatesRequest {
4711
4711
  return {
4712
4712
  chainId: isSet(object.chainId) ? globalThis.String(object.chainId) : "",
4713
4713
  templateInstances: globalThis.Array.isArray(object?.templateInstances)
@@ -4716,7 +4716,7 @@ export const ConfigureHandlersRequest = {
4716
4716
  };
4717
4717
  },
4718
4718
 
4719
- toJSON(message: ConfigureHandlersRequest): unknown {
4719
+ toJSON(message: UpdateTemplatesRequest): unknown {
4720
4720
  const obj: any = {};
4721
4721
  if (message.chainId !== "") {
4722
4722
  obj.chainId = message.chainId;
@@ -4727,11 +4727,11 @@ export const ConfigureHandlersRequest = {
4727
4727
  return obj;
4728
4728
  },
4729
4729
 
4730
- create(base?: DeepPartial<ConfigureHandlersRequest>): ConfigureHandlersRequest {
4731
- return ConfigureHandlersRequest.fromPartial(base ?? {});
4730
+ create(base?: DeepPartial<UpdateTemplatesRequest>): UpdateTemplatesRequest {
4731
+ return UpdateTemplatesRequest.fromPartial(base ?? {});
4732
4732
  },
4733
- fromPartial(object: DeepPartial<ConfigureHandlersRequest>): ConfigureHandlersRequest {
4734
- const message = createBaseConfigureHandlersRequest();
4733
+ fromPartial(object: DeepPartial<UpdateTemplatesRequest>): UpdateTemplatesRequest {
4734
+ const message = createBaseUpdateTemplatesRequest();
4735
4735
  message.chainId = object.chainId ?? "";
4736
4736
  message.templateInstances = object.templateInstances?.map((e) => TemplateInstance.fromPartial(e)) || [];
4737
4737
  return message;
@@ -8881,7 +8881,7 @@ export const ProcessStreamResponse_Partitions_PartitionsEntry = {
8881
8881
  },
8882
8882
  };
8883
8883
 
8884
- function createBaseProcessStreamResponseV2(): ProcessStreamResponseV2 {
8884
+ function createBaseProcessStreamResponseV3(): ProcessStreamResponseV3 {
8885
8885
  return {
8886
8886
  processId: 0,
8887
8887
  partitions: undefined,
@@ -8892,8 +8892,8 @@ function createBaseProcessStreamResponseV2(): ProcessStreamResponseV2 {
8892
8892
  };
8893
8893
  }
8894
8894
 
8895
- export const ProcessStreamResponseV2 = {
8896
- encode(message: ProcessStreamResponseV2, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
8895
+ export const ProcessStreamResponseV3 = {
8896
+ encode(message: ProcessStreamResponseV3, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
8897
8897
  if (message.processId !== 0) {
8898
8898
  writer.uint32(8).int32(message.processId);
8899
8899
  }
@@ -8915,10 +8915,10 @@ export const ProcessStreamResponseV2 = {
8915
8915
  return writer;
8916
8916
  },
8917
8917
 
8918
- decode(input: _m0.Reader | Uint8Array, length?: number): ProcessStreamResponseV2 {
8918
+ decode(input: _m0.Reader | Uint8Array, length?: number): ProcessStreamResponseV3 {
8919
8919
  const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
8920
8920
  let end = length === undefined ? reader.len : reader.pos + length;
8921
- const message = createBaseProcessStreamResponseV2();
8921
+ const message = createBaseProcessStreamResponseV3();
8922
8922
  while (reader.pos < end) {
8923
8923
  const tag = reader.uint32();
8924
8924
  switch (tag >>> 3) {
@@ -8973,7 +8973,7 @@ export const ProcessStreamResponseV2 = {
8973
8973
  return message;
8974
8974
  },
8975
8975
 
8976
- fromJSON(object: any): ProcessStreamResponseV2 {
8976
+ fromJSON(object: any): ProcessStreamResponseV3 {
8977
8977
  return {
8978
8978
  processId: isSet(object.processId) ? globalThis.Number(object.processId) : 0,
8979
8979
  partitions: isSet(object.partitions) ? ProcessStreamResponse_Partitions.fromJSON(object.partitions) : undefined,
@@ -8984,7 +8984,7 @@ export const ProcessStreamResponseV2 = {
8984
8984
  };
8985
8985
  },
8986
8986
 
8987
- toJSON(message: ProcessStreamResponseV2): unknown {
8987
+ toJSON(message: ProcessStreamResponseV3): unknown {
8988
8988
  const obj: any = {};
8989
8989
  if (message.processId !== 0) {
8990
8990
  obj.processId = Math.round(message.processId);
@@ -9007,11 +9007,11 @@ export const ProcessStreamResponseV2 = {
9007
9007
  return obj;
9008
9008
  },
9009
9009
 
9010
- create(base?: DeepPartial<ProcessStreamResponseV2>): ProcessStreamResponseV2 {
9011
- return ProcessStreamResponseV2.fromPartial(base ?? {});
9010
+ create(base?: DeepPartial<ProcessStreamResponseV3>): ProcessStreamResponseV3 {
9011
+ return ProcessStreamResponseV3.fromPartial(base ?? {});
9012
9012
  },
9013
- fromPartial(object: DeepPartial<ProcessStreamResponseV2>): ProcessStreamResponseV2 {
9014
- const message = createBaseProcessStreamResponseV2();
9013
+ fromPartial(object: DeepPartial<ProcessStreamResponseV3>): ProcessStreamResponseV3 {
9014
+ const message = createBaseProcessStreamResponseV3();
9015
9015
  message.processId = object.processId ?? 0;
9016
9016
  message.partitions = (object.partitions !== undefined && object.partitions !== null)
9017
9017
  ? ProcessStreamResponse_Partitions.fromPartial(object.partitions)
@@ -15196,19 +15196,27 @@ export const ProcessorV3Definition = {
15196
15196
  name: "ProcessorV3",
15197
15197
  fullName: "processor.ProcessorV3",
15198
15198
  methods: {
15199
- init: {
15200
- name: "Init",
15201
- requestType: Empty,
15199
+ start: {
15200
+ name: "Start",
15201
+ requestType: StartRequest,
15202
+ requestStream: false,
15203
+ responseType: Empty,
15204
+ responseStream: false,
15205
+ options: {},
15206
+ },
15207
+ getConfig: {
15208
+ name: "GetConfig",
15209
+ requestType: ProcessConfigRequest,
15202
15210
  requestStream: false,
15203
- responseType: InitResponse,
15211
+ responseType: ProcessConfigResponse,
15204
15212
  responseStream: false,
15205
15213
  options: {},
15206
15214
  },
15207
- configureHandlers: {
15208
- name: "ConfigureHandlers",
15209
- requestType: ConfigureHandlersRequest,
15215
+ updateTemplates: {
15216
+ name: "UpdateTemplates",
15217
+ requestType: UpdateTemplatesRequest,
15210
15218
  requestStream: false,
15211
- responseType: ConfigureHandlersResponse,
15219
+ responseType: Empty,
15212
15220
  responseStream: false,
15213
15221
  options: {},
15214
15222
  },
@@ -15216,7 +15224,7 @@ export const ProcessorV3Definition = {
15216
15224
  name: "ProcessBindingsStream",
15217
15225
  requestType: ProcessStreamRequest,
15218
15226
  requestStream: true,
15219
- responseType: ProcessStreamResponseV2,
15227
+ responseType: ProcessStreamResponseV3,
15220
15228
  responseStream: true,
15221
15229
  options: {},
15222
15230
  },
@@ -15224,27 +15232,29 @@ export const ProcessorV3Definition = {
15224
15232
  } as const;
15225
15233
 
15226
15234
  export interface ProcessorV3ServiceImplementation<CallContextExt = {}> {
15227
- init(request: Empty, context: CallContext & CallContextExt): Promise<DeepPartial<InitResponse>>;
15228
- configureHandlers(
15229
- request: ConfigureHandlersRequest,
15235
+ start(request: StartRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Empty>>;
15236
+ getConfig(
15237
+ request: ProcessConfigRequest,
15230
15238
  context: CallContext & CallContextExt,
15231
- ): Promise<DeepPartial<ConfigureHandlersResponse>>;
15239
+ ): Promise<DeepPartial<ProcessConfigResponse>>;
15240
+ updateTemplates(request: UpdateTemplatesRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Empty>>;
15232
15241
  processBindingsStream(
15233
15242
  request: AsyncIterable<ProcessStreamRequest>,
15234
15243
  context: CallContext & CallContextExt,
15235
- ): ServerStreamingMethodResult<DeepPartial<ProcessStreamResponseV2>>;
15244
+ ): ServerStreamingMethodResult<DeepPartial<ProcessStreamResponseV3>>;
15236
15245
  }
15237
15246
 
15238
15247
  export interface ProcessorV3Client<CallOptionsExt = {}> {
15239
- init(request: DeepPartial<Empty>, options?: CallOptions & CallOptionsExt): Promise<InitResponse>;
15240
- configureHandlers(
15241
- request: DeepPartial<ConfigureHandlersRequest>,
15248
+ start(request: DeepPartial<StartRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
15249
+ getConfig(
15250
+ request: DeepPartial<ProcessConfigRequest>,
15242
15251
  options?: CallOptions & CallOptionsExt,
15243
- ): Promise<ConfigureHandlersResponse>;
15252
+ ): Promise<ProcessConfigResponse>;
15253
+ updateTemplates(request: DeepPartial<UpdateTemplatesRequest>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
15244
15254
  processBindingsStream(
15245
15255
  request: AsyncIterable<DeepPartial<ProcessStreamRequest>>,
15246
15256
  options?: CallOptions & CallOptionsExt,
15247
- ): AsyncIterable<ProcessStreamResponseV2>;
15257
+ ): AsyncIterable<ProcessStreamResponseV3>;
15248
15258
  }
15249
15259
 
15250
15260
  type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
@@ -2116,6 +2116,9 @@ export interface RequestLog {
2116
2116
  queryDuration: bigint;
2117
2117
  method: string;
2118
2118
  rpcNodeId: string;
2119
+ originUrl: string;
2120
+ endpointType: string;
2121
+ chainId: string;
2119
2122
  }
2120
2123
 
2121
2124
  function createBaseUsageTracker(): UsageTracker {
@@ -14903,6 +14906,9 @@ function createBaseRequestLog(): RequestLog {
14903
14906
  queryDuration: BigInt("0"),
14904
14907
  method: "",
14905
14908
  rpcNodeId: "",
14909
+ originUrl: "",
14910
+ endpointType: "",
14911
+ chainId: "",
14906
14912
  };
14907
14913
  }
14908
14914
 
@@ -14959,6 +14965,15 @@ export const RequestLog = {
14959
14965
  if (message.rpcNodeId !== "") {
14960
14966
  writer.uint32(122).string(message.rpcNodeId);
14961
14967
  }
14968
+ if (message.originUrl !== "") {
14969
+ writer.uint32(130).string(message.originUrl);
14970
+ }
14971
+ if (message.endpointType !== "") {
14972
+ writer.uint32(138).string(message.endpointType);
14973
+ }
14974
+ if (message.chainId !== "") {
14975
+ writer.uint32(146).string(message.chainId);
14976
+ }
14962
14977
  return writer;
14963
14978
  },
14964
14979
 
@@ -15074,6 +15089,27 @@ export const RequestLog = {
15074
15089
 
15075
15090
  message.rpcNodeId = reader.string();
15076
15091
  continue;
15092
+ case 16:
15093
+ if (tag !== 130) {
15094
+ break;
15095
+ }
15096
+
15097
+ message.originUrl = reader.string();
15098
+ continue;
15099
+ case 17:
15100
+ if (tag !== 138) {
15101
+ break;
15102
+ }
15103
+
15104
+ message.endpointType = reader.string();
15105
+ continue;
15106
+ case 18:
15107
+ if (tag !== 146) {
15108
+ break;
15109
+ }
15110
+
15111
+ message.chainId = reader.string();
15112
+ continue;
15077
15113
  }
15078
15114
  if ((tag & 7) === 4 || tag === 0) {
15079
15115
  break;
@@ -15100,6 +15136,9 @@ export const RequestLog = {
15100
15136
  queryDuration: isSet(object.queryDuration) ? BigInt(object.queryDuration) : BigInt("0"),
15101
15137
  method: isSet(object.method) ? globalThis.String(object.method) : "",
15102
15138
  rpcNodeId: isSet(object.rpcNodeId) ? globalThis.String(object.rpcNodeId) : "",
15139
+ originUrl: isSet(object.originUrl) ? globalThis.String(object.originUrl) : "",
15140
+ endpointType: isSet(object.endpointType) ? globalThis.String(object.endpointType) : "",
15141
+ chainId: isSet(object.chainId) ? globalThis.String(object.chainId) : "",
15103
15142
  };
15104
15143
  },
15105
15144
 
@@ -15150,6 +15189,15 @@ export const RequestLog = {
15150
15189
  if (message.rpcNodeId !== "") {
15151
15190
  obj.rpcNodeId = message.rpcNodeId;
15152
15191
  }
15192
+ if (message.originUrl !== "") {
15193
+ obj.originUrl = message.originUrl;
15194
+ }
15195
+ if (message.endpointType !== "") {
15196
+ obj.endpointType = message.endpointType;
15197
+ }
15198
+ if (message.chainId !== "") {
15199
+ obj.chainId = message.chainId;
15200
+ }
15153
15201
  return obj;
15154
15202
  },
15155
15203
 
@@ -15173,6 +15221,9 @@ export const RequestLog = {
15173
15221
  message.queryDuration = object.queryDuration ?? BigInt("0");
15174
15222
  message.method = object.method ?? "";
15175
15223
  message.rpcNodeId = object.rpcNodeId ?? "";
15224
+ message.originUrl = object.originUrl ?? "";
15225
+ message.endpointType = object.endpointType ?? "";
15226
+ message.chainId = object.chainId ?? "";
15176
15227
  return message;
15177
15228
  },
15178
15229
  };
package/src/plugin.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  DataBinding,
3
3
  HandlerType,
4
- InitResponse,
5
4
  PreparedData,
6
5
  PreprocessResult,
7
6
  ProcessConfigResponse,
8
7
  ProcessResult,
9
8
  ProcessStreamResponse_Partitions,
10
9
  ProcessStreamResponse_Partitions_Partition_SysValue,
11
- StartRequest
10
+ StartRequest,
11
+ UpdateTemplatesRequest
12
12
  } from '@sentio/protos'
13
13
  import { IStoreContext, StoreContext } from './db-context.js'
14
14
  import { AsyncLocalStorage } from 'node:async_hooks'
@@ -60,12 +60,6 @@ export abstract class Plugin {
60
60
  * method used by action server only
61
61
  */
62
62
  shutdownServer() {}
63
-
64
- /**
65
- * Initialize the plugin, for service v3.
66
- * @param config
67
- */
68
- async init(config: InitResponse): Promise<void> {}
69
63
  }
70
64
 
71
65
  export class PluginManager {
@@ -90,8 +84,10 @@ export class PluginManager {
90
84
  }
91
85
  }
92
86
 
93
- async configure(config: ProcessConfigResponse, forChainId?: string): Promise<void> {
94
- await Promise.all(this.plugins.map((plugin) => plugin.configure(config, forChainId)))
87
+ async configure(config: ProcessConfigResponse): Promise<void> {
88
+ for (const plugin of this.plugins) {
89
+ await plugin.configure(config)
90
+ }
95
91
  }
96
92
 
97
93
  start(start: StartRequest, actionServerPort?: number) {
@@ -149,7 +145,11 @@ export class PluginManager {
149
145
  })
150
146
  }
151
147
 
152
- async init(resp: InitResponse) {
153
- return Promise.all(this.plugins.map((plugin) => plugin.init(resp)))
148
+ async updateTemplates(request: UpdateTemplatesRequest) {
149
+ for (const plugin of this.plugins) {
150
+ await plugin.start({
151
+ templateInstances: request.templateInstances
152
+ })
153
+ }
154
154
  }
155
155
  }
package/src/service-v3.ts CHANGED
@@ -1,20 +1,19 @@
1
1
  import {
2
- ConfigureHandlersRequest,
3
- ConfigureHandlersResponse,
4
2
  DataBinding,
5
3
  DeepPartial,
6
4
  Empty,
7
5
  HandlerType,
8
- InitResponse,
6
+ ProcessConfigRequest,
9
7
  ProcessConfigResponse,
10
8
  ProcessorV3ServiceImplementation,
11
9
  ProcessResult,
12
10
  ProcessStreamRequest,
13
11
  ProcessStreamResponse,
14
- ProcessStreamResponseV2,
15
- StartRequest
12
+ ProcessStreamResponseV3,
13
+ StartRequest,
14
+ UpdateTemplatesRequest
16
15
  } from '@sentio/protos'
17
- import { CallContext } from 'nice-grpc'
16
+ import { CallContext, ServerError, Status } from 'nice-grpc'
18
17
  import { AsyncIterable } from 'ix'
19
18
  import { PluginManager } from './plugin.js'
20
19
  import { Subject } from 'rxjs'
@@ -26,6 +25,7 @@ import { processMetrics } from './metrics.js'
26
25
  import { recordRuntimeInfo } from './service.js'
27
26
  import { DataBindingContext } from './db-context.js'
28
27
  import { TemplateInstanceState } from './state.js'
28
+ import { freezeGlobalConfig } from './global-config.js'
29
29
 
30
30
  const { process_binding_count, process_binding_time, process_binding_error } = processMetrics
31
31
 
@@ -33,6 +33,7 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
33
33
  readonly enablePartition: boolean
34
34
  private readonly loader: () => Promise<any>
35
35
  private readonly shutdownHandler?: () => void
36
+ private started = false
36
37
 
37
38
  constructor(loader: () => Promise<any>, options?: any, shutdownHandler?: () => void) {
38
39
  this.loader = loader
@@ -41,18 +42,37 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
41
42
  this.enablePartition = options?.['enable-partition'] == true
42
43
  }
43
44
 
44
- async init(request: Empty, context: CallContext): Promise<DeepPartial<InitResponse>> {
45
- await this.loader()
46
- const resp = InitResponse.fromPartial({
47
- chainIds: []
48
- })
49
- await PluginManager.INSTANCE.init(resp)
50
- resp.chainIds = Array.from(new Set(resp.chainIds))
51
- return resp
45
+ async start(request: StartRequest, context: CallContext): Promise<Empty> {
46
+ if (this.started) {
47
+ return {}
48
+ }
49
+
50
+ freezeGlobalConfig()
51
+
52
+ try {
53
+ await this.loader()
54
+ } catch (e) {
55
+ throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))
56
+ }
57
+
58
+ await PluginManager.INSTANCE.start(request)
59
+
60
+ this.started = true
61
+ return {}
62
+ }
63
+
64
+ async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse> {
65
+ if (!this.started) {
66
+ throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
67
+ }
68
+
69
+ const newConfig = ProcessConfigResponse.fromPartial({})
70
+ await PluginManager.INSTANCE.configure(newConfig)
71
+ return newConfig
52
72
  }
53
73
 
54
74
  async *processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context: CallContext) {
55
- const subject = new Subject<DeepPartial<ProcessStreamResponseV2>>()
75
+ const subject = new Subject<DeepPartial<ProcessStreamResponseV3>>()
56
76
  this.handleRequests(requests, subject)
57
77
  .then(() => {
58
78
  subject.complete()
@@ -88,7 +108,7 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
88
108
  async handleRequest(
89
109
  request: ProcessStreamRequest,
90
110
  lastBinding: DataBinding | undefined,
91
- subject: Subject<DeepPartial<ProcessStreamResponseV2>>
111
+ subject: Subject<DeepPartial<ProcessStreamResponseV3>>
92
112
  ) {
93
113
  if (request.binding) {
94
114
  process_binding_count.add(1)
@@ -141,7 +161,7 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
141
161
  private startProcess(
142
162
  processId: number,
143
163
  binding: DataBinding,
144
- subject: Subject<DeepPartial<ProcessStreamResponseV2>>
164
+ subject: Subject<DeepPartial<ProcessStreamResponseV3>>
145
165
  ) {
146
166
  const context = this.contexts.new(processId, subject)
147
167
  const start = Date.now()
@@ -194,22 +214,9 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
194
214
  })
195
215
  }
196
216
 
197
- async configureHandlers(
198
- request: ConfigureHandlersRequest,
199
- context: CallContext
200
- ): Promise<DeepPartial<ConfigureHandlersResponse>> {
201
- await PluginManager.INSTANCE.start(
202
- StartRequest.fromPartial({
203
- templateInstances: request.templateInstances
204
- })
205
- )
206
-
207
- const newConfig = ProcessConfigResponse.fromPartial({})
208
- await PluginManager.INSTANCE.configure(newConfig, request.chainId)
209
- return {
210
- accountConfigs: newConfig.accountConfigs,
211
- contractConfigs: newConfig.contractConfigs
212
- }
217
+ async updateTemplates(request: UpdateTemplatesRequest, context: CallContext): Promise<DeepPartial<Empty>> {
218
+ await PluginManager.INSTANCE.updateTemplates(request)
219
+ return {}
213
220
  }
214
221
  }
215
222
 
@@ -220,7 +227,7 @@ class Contexts {
220
227
  return this.contexts.get(processId)
221
228
  }
222
229
 
223
- new(processId: number, subject: Subject<DeepPartial<ProcessStreamResponseV2>>) {
230
+ new(processId: number, subject: Subject<DeepPartial<ProcessStreamResponseV3>>) {
224
231
  const context = new DataBindingContext(processId, subject)
225
232
  this.contexts.set(processId, context)
226
233
  return context