@sentio/runtime 3.0.0-rc.6 → 3.0.0-rc.8

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,4 +1,7 @@
1
1
  import { createRequire as createRequireShim } from 'module'; const require = createRequireShim(import.meta.url);
2
+ import {
3
+ PluginManager
4
+ } from "./chunk-QHFSZVR5.js";
2
5
 
3
6
  // src/state.ts
4
7
  import { isMainThread, parentPort, threadId } from "node:worker_threads";
@@ -77,7 +80,9 @@ var TemplateInstanceState = class _TemplateInstanceState extends ListStateStorag
77
80
  if (!isMainThread) {
78
81
  parentPort?.postMessage({ event: "add_template_instance", value, from: threadId });
79
82
  }
80
- return super.addValue(value);
83
+ const ret = super.addValue(value);
84
+ PluginManager.INSTANCE.sendTemplateInstance(ret);
85
+ return ret;
81
86
  }
82
87
  };
83
88
  import("node:process").then((p) => p.stdout.write(""));
@@ -89,4 +94,4 @@ export {
89
94
  ListStateStorage,
90
95
  TemplateInstanceState
91
96
  };
92
- //# sourceMappingURL=chunk-6XHWJ2VS.js.map
97
+ //# sourceMappingURL=chunk-N3VEKOPD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state.ts"],"sourcesContent":["import { TemplateInstance } from '@sentio/protos'\nimport { isMainThread, parentPort, threadId } from 'node:worker_threads'\nimport { PluginManager } from './plugin.js'\n\nexport 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 unregister(): T {\n const value = State.INSTANCE.stateMap.get(this.key())\n State.INSTANCE.stateMap.delete(this.key())\n return value\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 if (oldValue !== value) {\n console.warn(key, 'has been registered twice, use the previous one')\n }\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\nexport class TemplateInstanceState extends ListStateStorage<TemplateInstance> {\n static INSTANCE = new TemplateInstanceState()\n\n constructor() {\n super()\n }\n\n override addValue(value: TemplateInstance): TemplateInstance {\n if (!isMainThread) {\n // I'm worker thread, should notice the main thread\n parentPort?.postMessage({ event: 'add_template_instance', value, from: threadId })\n }\n const ret = super.addValue(value)\n PluginManager.INSTANCE.sendTemplateInstance(ret)\n return ret\n }\n}\n;import(\"node:process\").then((p) => p.stdout.write(\"\"));"],"mappings":";;;;;;AACA,SAAS,cAAc,YAAY,gBAAgB;AAG5C,IAAM,QAAN,MAAM,OAAM;AAAA,EACjB,WAAW,oBAAI,IAAiB;AAAA,EAEhC,OAAO,WAAW,IAAI,OAAM;AAAA,EAE5B,OAAO,QAAQ;AACb,WAAM,WAAW,IAAI,OAAM;AAAA,EAC7B;AACF;AAEO,IAAe,eAAf,MAA+B;AAAA;AAAA,EAG1B,cAAc;AAAA,EAExB;AAAA,EAIA,MAAc;AACZ,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEA,gBAAmB;AACjB,QAAI,cAAiB,MAAM,SAAS,SAAS,IAAI,KAAK,IAAI,CAAC;AAC3D,QAAI,CA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3D,QAAI,CAAC,cAAc;AAEjB,kBAAY,YAAY,EAAE,OAAO,yBAAyB,OAAO,MAAM,SAAS,CAAC;AAAA,IACnF;AACA,UAAM,MAAM,MAAM,SAAS,KAAK;AAChC,kBAAc,SAAS,qBAAqB,GAAG;AAC/C,WAAO;AAAA,EACT;AACF;AACC,OAAO,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,EAAE,CAAC;","names":[]}
@@ -13991,6 +13991,12 @@ var PluginManager = class _PluginManager {
13991
13991
  });
13992
13992
  }
13993
13993
  }
13994
+ sendTemplateInstance(instance) {
13995
+ const store = this.dbContextLocalStorage.getStore();
13996
+ if (store && "sendTemplateRequest" in store) {
13997
+ store?.sendTemplateRequest([instance]);
13998
+ }
13999
+ }
13994
14000
  };
13995
14001
  import("node:process").then((p) => p.stdout.write(""));
13996
14002
 
@@ -16329,7 +16335,7 @@ var ProcessConfigResponse3 = {
16329
16335
  ContractConfig2.encode(v, writer.uint32(18).fork()).ldelim();
16330
16336
  }
16331
16337
  for (const v of message.templateInstances) {
16332
- TemplateInstance2.encode(v, writer.uint32(26).fork()).ldelim();
16338
+ TemplateInstance3.encode(v, writer.uint32(26).fork()).ldelim();
16333
16339
  }
16334
16340
  for (const v of message.accountConfigs) {
16335
16341
  AccountConfig2.encode(v, writer.uint32(34).fork()).ldelim();
@@ -16377,7 +16383,7 @@ var ProcessConfigResponse3 = {
16377
16383
  if (tag !== 26) {
16378
16384
  break;
16379
16385
  }
16380
- message.templateInstances.push(TemplateInstance2.decode(reader, reader.uint32()));
16386
+ message.templateInstances.push(TemplateInstance3.decode(reader, reader.uint32()));
16381
16387
  continue;
16382
16388
  case 4:
16383
16389
  if (tag !== 34) {
@@ -16422,7 +16428,7 @@ var ProcessConfigResponse3 = {
16422
16428
  config: isSet8(object.config) ? ProjectConfig2.fromJSON(object.config) : void 0,
16423
16429
  executionConfig: isSet8(object.executionConfig) ? ExecutionConfig2.fromJSON(object.executionConfig) : void 0,
16424
16430
  contractConfigs: globalThis.Array.isArray(object?.contractConfigs) ? object.contractConfigs.map((e) => ContractConfig2.fromJSON(e)) : [],
16425
- templateInstances: globalThis.Array.isArray(object?.templateInstances) ? object.templateInstances.map((e) => TemplateInstance2.fromJSON(e)) : [],
16431
+ templateInstances: globalThis.Array.isArray(object?.templateInstances) ? object.templateInstances.map((e) => TemplateInstance3.fromJSON(e)) : [],
16426
16432
  accountConfigs: globalThis.Array.isArray(object?.accountConfigs) ? object.accountConfigs.map((e) => AccountConfig2.fromJSON(e)) : [],
16427
16433
  metricConfigs: globalThis.Array.isArray(object?.metricConfigs) ? object.metricConfigs.map((e) => MetricConfig2.fromJSON(e)) : [],
16428
16434
  exportConfigs: globalThis.Array.isArray(object?.exportConfigs) ? object.exportConfigs.map((e) => ExportConfig2.fromJSON(e)) : [],
@@ -16442,7 +16448,7 @@ var ProcessConfigResponse3 = {
16442
16448
  obj.contractConfigs = message.contractConfigs.map((e) => ContractConfig2.toJSON(e));
16443
16449
  }
16444
16450
  if (message.templateInstances?.length) {
16445
- obj.templateInstances = message.templateInstances.map((e) => TemplateInstance2.toJSON(e));
16451
+ obj.templateInstances = message.templateInstances.map((e) => TemplateInstance3.toJSON(e));
16446
16452
  }
16447
16453
  if (message.accountConfigs?.length) {
16448
16454
  obj.accountConfigs = message.accountConfigs.map((e) => AccountConfig2.toJSON(e));
@@ -16469,7 +16475,7 @@ var ProcessConfigResponse3 = {
16469
16475
  message.config = object.config !== void 0 && object.config !== null ? ProjectConfig2.fromPartial(object.config) : void 0;
16470
16476
  message.executionConfig = object.executionConfig !== void 0 && object.executionConfig !== null ? ExecutionConfig2.fromPartial(object.executionConfig) : void 0;
16471
16477
  message.contractConfigs = object.contractConfigs?.map((e) => ContractConfig2.fromPartial(e)) || [];
16472
- message.templateInstances = object.templateInstances?.map((e) => TemplateInstance2.fromPartial(e)) || [];
16478
+ message.templateInstances = object.templateInstances?.map((e) => TemplateInstance3.fromPartial(e)) || [];
16473
16479
  message.accountConfigs = object.accountConfigs?.map((e) => AccountConfig2.fromPartial(e)) || [];
16474
16480
  message.metricConfigs = object.metricConfigs?.map((e) => MetricConfig2.fromPartial(e)) || [];
16475
16481
  message.exportConfigs = object.exportConfigs?.map((e) => ExportConfig2.fromPartial(e)) || [];
@@ -18069,7 +18075,7 @@ var ContractInfo2 = {
18069
18075
  function createBaseTemplateInstance2() {
18070
18076
  return { contract: void 0, startBlock: BigInt("0"), endBlock: BigInt("0"), templateId: 0, baseLabels: void 0 };
18071
18077
  }
18072
- var TemplateInstance2 = {
18078
+ var TemplateInstance3 = {
18073
18079
  encode(message, writer = import_minimal12.default.Writer.create()) {
18074
18080
  if (message.contract !== void 0) {
18075
18081
  ContractInfo2.encode(message.contract, writer.uint32(10).fork()).ldelim();
@@ -18168,7 +18174,7 @@ var TemplateInstance2 = {
18168
18174
  return obj;
18169
18175
  },
18170
18176
  create(base) {
18171
- return TemplateInstance2.fromPartial(base ?? {});
18177
+ return TemplateInstance3.fromPartial(base ?? {});
18172
18178
  },
18173
18179
  fromPartial(object) {
18174
18180
  const message = createBaseTemplateInstance2();
@@ -18186,7 +18192,7 @@ function createBaseStartRequest2() {
18186
18192
  var StartRequest3 = {
18187
18193
  encode(message, writer = import_minimal12.default.Writer.create()) {
18188
18194
  for (const v of message.templateInstances) {
18189
- TemplateInstance2.encode(v, writer.uint32(10).fork()).ldelim();
18195
+ TemplateInstance3.encode(v, writer.uint32(10).fork()).ldelim();
18190
18196
  }
18191
18197
  return writer;
18192
18198
  },
@@ -18201,7 +18207,7 @@ var StartRequest3 = {
18201
18207
  if (tag !== 10) {
18202
18208
  break;
18203
18209
  }
18204
- message.templateInstances.push(TemplateInstance2.decode(reader, reader.uint32()));
18210
+ message.templateInstances.push(TemplateInstance3.decode(reader, reader.uint32()));
18205
18211
  continue;
18206
18212
  }
18207
18213
  if ((tag & 7) === 4 || tag === 0) {
@@ -18213,13 +18219,13 @@ var StartRequest3 = {
18213
18219
  },
18214
18220
  fromJSON(object) {
18215
18221
  return {
18216
- templateInstances: globalThis.Array.isArray(object?.templateInstances) ? object.templateInstances.map((e) => TemplateInstance2.fromJSON(e)) : []
18222
+ templateInstances: globalThis.Array.isArray(object?.templateInstances) ? object.templateInstances.map((e) => TemplateInstance3.fromJSON(e)) : []
18217
18223
  };
18218
18224
  },
18219
18225
  toJSON(message) {
18220
18226
  const obj = {};
18221
18227
  if (message.templateInstances?.length) {
18222
- obj.templateInstances = message.templateInstances.map((e) => TemplateInstance2.toJSON(e));
18228
+ obj.templateInstances = message.templateInstances.map((e) => TemplateInstance3.toJSON(e));
18223
18229
  }
18224
18230
  return obj;
18225
18231
  },
@@ -18228,7 +18234,7 @@ var StartRequest3 = {
18228
18234
  },
18229
18235
  fromPartial(object) {
18230
18236
  const message = createBaseStartRequest2();
18231
- message.templateInstances = object.templateInstances?.map((e) => TemplateInstance2.fromPartial(e)) || [];
18237
+ message.templateInstances = object.templateInstances?.map((e) => TemplateInstance3.fromPartial(e)) || [];
18232
18238
  return message;
18233
18239
  }
18234
18240
  };
@@ -25770,4 +25776,4 @@ long/index.js:
25770
25776
  * SPDX-License-Identifier: Apache-2.0
25771
25777
  *)
25772
25778
  */
25773
- //# sourceMappingURL=chunk-OFR7W4ZG.js.map
25779
+ //# sourceMappingURL=chunk-QHFSZVR5.js.map