@xyo-network/sentinel 2.76.1 → 2.77.0

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 (48) hide show
  1. package/dist/browser/MemorySentinel.d.cts +1 -1
  2. package/dist/browser/MemorySentinel.d.cts.map +1 -1
  3. package/dist/browser/MemorySentinel.d.mts +1 -1
  4. package/dist/browser/MemorySentinel.d.mts.map +1 -1
  5. package/dist/browser/MemorySentinel.d.ts +1 -1
  6. package/dist/browser/MemorySentinel.d.ts.map +1 -1
  7. package/dist/browser/index.cjs +12 -82
  8. package/dist/browser/index.cjs.map +1 -1
  9. package/dist/browser/index.d.cts +1 -1
  10. package/dist/browser/index.d.cts.map +1 -1
  11. package/dist/browser/index.d.mts +1 -1
  12. package/dist/browser/index.d.mts.map +1 -1
  13. package/dist/browser/index.d.ts +1 -1
  14. package/dist/browser/index.d.ts.map +1 -1
  15. package/dist/browser/index.js +7 -79
  16. package/dist/browser/index.js.map +1 -1
  17. package/dist/node/MemorySentinel.d.cts +1 -1
  18. package/dist/node/MemorySentinel.d.cts.map +1 -1
  19. package/dist/node/MemorySentinel.d.mts +1 -1
  20. package/dist/node/MemorySentinel.d.mts.map +1 -1
  21. package/dist/node/MemorySentinel.d.ts +1 -1
  22. package/dist/node/MemorySentinel.d.ts.map +1 -1
  23. package/dist/node/index.d.cts +1 -1
  24. package/dist/node/index.d.cts.map +1 -1
  25. package/dist/node/index.d.mts +1 -1
  26. package/dist/node/index.d.mts.map +1 -1
  27. package/dist/node/index.d.ts +1 -1
  28. package/dist/node/index.d.ts.map +1 -1
  29. package/dist/node/index.js +13 -83
  30. package/dist/node/index.js.map +1 -1
  31. package/dist/node/index.mjs +7 -79
  32. package/dist/node/index.mjs.map +1 -1
  33. package/package.json +18 -20
  34. package/src/MemorySentinel.ts +1 -2
  35. package/src/index.ts +1 -1
  36. package/dist/browser/AbstractSentinel.d.cts +0 -17
  37. package/dist/browser/AbstractSentinel.d.cts.map +0 -1
  38. package/dist/browser/AbstractSentinel.d.mts +0 -17
  39. package/dist/browser/AbstractSentinel.d.mts.map +0 -1
  40. package/dist/browser/AbstractSentinel.d.ts +0 -17
  41. package/dist/browser/AbstractSentinel.d.ts.map +0 -1
  42. package/dist/node/AbstractSentinel.d.cts +0 -17
  43. package/dist/node/AbstractSentinel.d.cts.map +0 -1
  44. package/dist/node/AbstractSentinel.d.mts +0 -17
  45. package/dist/node/AbstractSentinel.d.mts.map +0 -1
  46. package/dist/node/AbstractSentinel.d.ts +0 -17
  47. package/dist/node/AbstractSentinel.d.ts.map +0 -1
  48. package/src/AbstractSentinel.ts +0 -102
@@ -1,8 +1,8 @@
1
- export * from './AbstractSentinel';
2
1
  export * from './Automation';
3
2
  export * from './MemorySentinel';
4
3
  export * from './SentinelIntervalAutomationWrapper';
5
4
  export * from './SentinelRunner';
6
5
  export * from './Wrapper';
6
+ export * from '@xyo-network/sentinel-abstract';
7
7
  export * from '@xyo-network/sentinel-model';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qCAAqC,CAAA;AACnD,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,6BAA6B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qCAAqC,CAAA;AACnD,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA"}
@@ -1,8 +1,8 @@
1
- export * from './AbstractSentinel';
2
1
  export * from './Automation';
3
2
  export * from './MemorySentinel';
4
3
  export * from './SentinelIntervalAutomationWrapper';
5
4
  export * from './SentinelRunner';
6
5
  export * from './Wrapper';
6
+ export * from '@xyo-network/sentinel-abstract';
7
7
  export * from '@xyo-network/sentinel-model';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qCAAqC,CAAA;AACnD,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,6BAA6B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qCAAqC,CAAA;AACnD,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA"}
@@ -1,8 +1,8 @@
1
- export * from './AbstractSentinel';
2
1
  export * from './Automation';
3
2
  export * from './MemorySentinel';
4
3
  export * from './SentinelIntervalAutomationWrapper';
5
4
  export * from './SentinelRunner';
6
5
  export * from './Wrapper';
6
+ export * from '@xyo-network/sentinel-abstract';
7
7
  export * from '@xyo-network/sentinel-model';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qCAAqC,CAAA;AACnD,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,6BAA6B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qCAAqC,CAAA;AACnD,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA"}
@@ -21,7 +21,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/index.ts
22
22
  var src_exports = {};
23
23
  __export(src_exports, {
24
- AbstractSentinel: () => AbstractSentinel,
25
24
  MemorySentinel: () => MemorySentinel,
26
25
  SentinelAutomationSchema: () => SentinelAutomationSchema,
27
26
  SentinelIntervalAutomationWrapper: () => SentinelIntervalAutomationWrapper,
@@ -30,87 +29,17 @@ __export(src_exports, {
30
29
  });
31
30
  module.exports = __toCommonJS(src_exports);
32
31
 
33
- // src/AbstractSentinel.ts
34
- var import_assert = require("@xylabs/assert");
35
- var import_boundwitness_builder = require("@xyo-network/boundwitness-builder");
36
- var import_boundwitness_model = require("@xyo-network/boundwitness-model");
37
- var import_module_abstract = require("@xyo-network/module-abstract");
38
- var import_sentinel_model = require("@xyo-network/sentinel-model");
39
- var AbstractSentinel = class extends import_module_abstract.AbstractModuleInstance {
40
- history = [];
41
- _jobPromise;
42
- get jobPromise() {
43
- this._jobPromise = this._jobPromise ?? this.generateJob();
44
- return this._jobPromise;
45
- }
46
- get queries() {
47
- return [import_sentinel_model.SentinelReportQuerySchema, ...super.queries];
48
- }
49
- get _queryAccountPaths() {
50
- return {
51
- "network.xyo.query.sentinel.report": "1/1"
52
- };
53
- }
54
- async report(inPayloads) {
55
- this._noOverride("report");
56
- await this.emit("reportStart", { inPayloads, module: this });
57
- const payloads = await this.reportHandler(inPayloads);
58
- const boundwitnesses = payloads.filter(import_boundwitness_model.isBoundWitness);
59
- const outPayloads = payloads.filter(import_boundwitness_model.notBoundWitness);
60
- const boundwitness = boundwitnesses.find((bw) => bw.addresses.includes(this.address));
61
- await this.emit("reportEnd", { boundwitness, inPayloads, module: this, outPayloads });
62
- return payloads;
63
- }
64
- async generateJob() {
65
- const job = { tasks: [] };
66
- let tasks = await Promise.all(
67
- this.config.tasks.map(async (task) => ({
68
- input: task.input ?? false,
69
- module: (0, import_assert.assertEx)(await this.resolve(task.module), `Unable to resolve task module [${task.module}]`)
70
- }))
71
- );
72
- while (tasks.length) {
73
- const previousTasks = job.tasks.length ? job.tasks[job.tasks.length - 1] : [];
74
- const newList = (
75
- //add all tasks that either require no previous input or have the previous input module already added
76
- tasks.filter(
77
- (task) => typeof task.input === "boolean" || previousTasks.find((prevTask) => prevTask.module.address === task.input || prevTask.module.config.name === task.input)
78
- )
79
- );
80
- (0, import_assert.assertEx)(newList.length > 0, `Unable to generateJob [${tasks.length}]`);
81
- job.tasks.push(newList);
82
- tasks = tasks.filter((task) => !newList.includes(task));
83
- }
84
- return job;
85
- }
86
- async queryHandler(query, payloads, queryConfig) {
87
- const wrapper = import_boundwitness_builder.QueryBoundWitnessWrapper.parseQuery(query, payloads);
88
- const queryPayload = await wrapper.getQuery();
89
- (0, import_assert.assertEx)(this.queryable(query, payloads, queryConfig));
90
- const resultPayloads = [];
91
- switch (queryPayload.schema) {
92
- case import_sentinel_model.SentinelReportQuerySchema: {
93
- resultPayloads.push(...await this.report(payloads));
94
- break;
95
- }
96
- default: {
97
- return super.queryHandler(query, payloads);
98
- }
99
- }
100
- return resultPayloads;
101
- }
102
- };
103
-
104
32
  // src/Automation.ts
105
33
  var SentinelAutomationSchema = "network.xyo.automation";
106
34
 
107
35
  // src/MemorySentinel.ts
108
36
  var import_promise = require("@xylabs/promise");
109
37
  var import_diviner_model = require("@xyo-network/diviner-model");
110
- var import_sentinel_model2 = require("@xyo-network/sentinel-model");
38
+ var import_sentinel_abstract = require("@xyo-network/sentinel-abstract");
39
+ var import_sentinel_model = require("@xyo-network/sentinel-model");
111
40
  var import_witness_model = require("@xyo-network/witness-model");
112
- var MemorySentinel = class extends AbstractSentinel {
113
- static configSchemas = [import_sentinel_model2.SentinelConfigSchema];
41
+ var MemorySentinel = class extends import_sentinel_abstract.AbstractSentinel {
42
+ static configSchemas = [import_sentinel_model.SentinelConfigSchema];
114
43
  async reportHandler(inPayloads = []) {
115
44
  await this.started("throw");
116
45
  const job = await this.jobPromise;
@@ -197,7 +126,7 @@ var SentinelIntervalAutomationWrapper = class extends import_payload_wrapper.Pay
197
126
  };
198
127
 
199
128
  // src/SentinelRunner.ts
200
- var import_assert2 = require("@xylabs/assert");
129
+ var import_assert = require("@xylabs/assert");
201
130
  var import_payload_wrapper2 = require("@xyo-network/payload-wrapper");
202
131
  var SentinelRunner = class {
203
132
  _automations = {};
@@ -243,7 +172,7 @@ var SentinelRunner = class {
243
172
  await this.start();
244
173
  }
245
174
  async start() {
246
- (0, import_assert2.assertEx)(this.timeoutId === void 0, "Already started");
175
+ (0, import_assert.assertEx)(this.timeoutId === void 0, "Already started");
247
176
  const automation = this.next;
248
177
  if (automation) {
249
178
  const delay = automation.start - Date.now();
@@ -286,17 +215,17 @@ var SentinelRunner = class {
286
215
 
287
216
  // src/Wrapper.ts
288
217
  var import_module_wrapper = require("@xyo-network/module-wrapper");
289
- var import_sentinel_model3 = require("@xyo-network/sentinel-model");
218
+ var import_sentinel_model2 = require("@xyo-network/sentinel-model");
290
219
  (0, import_module_wrapper.constructableModuleWrapper)();
291
220
  var SentinelWrapper = class extends import_module_wrapper.ModuleWrapper {
292
- static instanceIdentityCheck = import_sentinel_model3.isSentinelInstance;
293
- static moduleIdentityCheck = import_sentinel_model3.isSentinelModule;
294
- static requiredQueries = [import_sentinel_model3.SentinelReportQuerySchema, ...super.requiredQueries];
221
+ static instanceIdentityCheck = import_sentinel_model2.isSentinelInstance;
222
+ static moduleIdentityCheck = import_sentinel_model2.isSentinelModule;
223
+ static requiredQueries = [import_sentinel_model2.SentinelReportQuerySchema, ...super.requiredQueries];
295
224
  archivists() {
296
225
  throw Error("Not supported");
297
226
  }
298
227
  async report(payloads) {
299
- const queryPayload = { schema: import_sentinel_model3.SentinelReportQuerySchema };
228
+ const queryPayload = { schema: import_sentinel_model2.SentinelReportQuerySchema };
300
229
  const result = await this.sendQuery(queryPayload, payloads);
301
230
  return result;
302
231
  }
@@ -306,15 +235,16 @@ var SentinelWrapper = class extends import_module_wrapper.ModuleWrapper {
306
235
  };
307
236
 
308
237
  // src/index.ts
238
+ __reExport(src_exports, require("@xyo-network/sentinel-abstract"), module.exports);
309
239
  __reExport(src_exports, require("@xyo-network/sentinel-model"), module.exports);
310
240
  // Annotate the CommonJS export names for ESM import in node:
311
241
  0 && (module.exports = {
312
- AbstractSentinel,
313
242
  MemorySentinel,
314
243
  SentinelAutomationSchema,
315
244
  SentinelIntervalAutomationWrapper,
316
245
  SentinelRunner,
317
246
  SentinelWrapper,
247
+ ...require("@xyo-network/sentinel-abstract"),
318
248
  ...require("@xyo-network/sentinel-model")
319
249
  });
320
250
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/AbstractSentinel.ts","../../src/Automation.ts","../../src/MemorySentinel.ts","../../src/SentinelIntervalAutomationWrapper.ts","../../src/SentinelRunner.ts","../../src/Wrapper.ts"],"sourcesContent":["export * from './AbstractSentinel'\nexport * from './Automation'\nexport * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\nexport * from './Wrapper'\nexport * from '@xyo-network/sentinel-model'\n","import { assertEx } from '@xylabs/assert'\nimport { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'\nimport { BoundWitness, isBoundWitness, notBoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model'\nimport { AbstractModuleInstance } from '@xyo-network/module-abstract'\nimport { ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n CustomSentinelInstance,\n ResolvedSentinelTask,\n SentinelInstance,\n SentinelJob,\n SentinelModuleEventData,\n SentinelParams,\n SentinelQueryBase,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\n\nexport abstract class AbstractSentinel<\n TParams extends SentinelParams = SentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n >\n extends AbstractModuleInstance<TParams, TEventData>\n implements CustomSentinelInstance<TParams, TEventData>\n{\n history: BoundWitness[] = []\n private _jobPromise?: Promise<SentinelJob>\n\n get jobPromise() {\n this._jobPromise = this._jobPromise ?? this.generateJob()\n return this._jobPromise\n }\n\n override get queries(): string[] {\n return [SentinelReportQuerySchema, ...super.queries]\n }\n\n protected override get _queryAccountPaths(): Record<SentinelQueryBase['schema'], string> {\n return {\n 'network.xyo.query.sentinel.report': '1/1',\n }\n }\n\n async report(inPayloads?: Payload[]): Promise<Payload[]> {\n this._noOverride('report')\n await this.emit('reportStart', { inPayloads, module: this })\n const payloads = await this.reportHandler(inPayloads)\n //this.logger?.debug(`report:payloads: ${JSON.stringify(payloads, null, 2)}`)\n const boundwitnesses = payloads.filter(isBoundWitness)\n const outPayloads = payloads.filter(notBoundWitness)\n const boundwitness = boundwitnesses.find((bw) => bw.addresses.includes(this.address))\n await this.emit('reportEnd', { boundwitness, inPayloads, module: this, outPayloads })\n return payloads\n }\n\n protected async generateJob() {\n const job: SentinelJob = { tasks: [] }\n let tasks: ResolvedSentinelTask[] = await Promise.all(\n this.config.tasks.map(async (task) => ({\n input: task.input ?? false,\n module: assertEx(await this.resolve(task.module), `Unable to resolve task module [${task.module}]`),\n })),\n )\n while (tasks.length) {\n const previousTasks = job.tasks.length ? job.tasks[job.tasks.length - 1] : []\n const newList =\n //add all tasks that either require no previous input or have the previous input module already added\n tasks.filter(\n (task) =>\n typeof task.input === 'boolean' ||\n previousTasks.find((prevTask) => prevTask.module.address === task.input || prevTask.module.config.name === task.input),\n )\n assertEx(newList.length > 0, `Unable to generateJob [${tasks.length}]`)\n job.tasks.push(newList)\n //remove the tasks we just added\n tasks = tasks.filter((task) => !newList.includes(task))\n }\n return job\n }\n\n protected override async queryHandler<T extends QueryBoundWitness = QueryBoundWitness, TConfig extends ModuleConfig = ModuleConfig>(\n query: T,\n payloads?: Payload[],\n queryConfig?: TConfig,\n ): Promise<ModuleQueryHandlerResult> {\n const wrapper = QueryBoundWitnessWrapper.parseQuery<SentinelQueryBase>(query, payloads)\n const queryPayload = await wrapper.getQuery()\n assertEx(this.queryable(query, payloads, queryConfig))\n const resultPayloads: Payload[] = []\n switch (queryPayload.schema) {\n case SentinelReportQuerySchema: {\n resultPayloads.push(...(await this.report(payloads)))\n break\n }\n default: {\n return super.queryHandler(query, payloads)\n }\n }\n return resultPayloads\n }\n\n abstract reportHandler(payloads?: Payload[]): Promise<Payload[]>\n}\n","import { AnyObject } from '@xyo-network/core'\nimport { Payload } from '@xyo-network/payload-model'\nimport { SentinelTask } from '@xyo-network/sentinel-model'\n\nexport type SentinelAutomationSchema = 'network.xyo.automation'\nexport const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'\n\nexport type SentinelBaseAutomationPayload<T extends AnyObject = AnyObject> = Payload<\n T & {\n schema: SentinelAutomationSchema\n tasks?: SentinelTask[]\n type?: 'interval' | 'change'\n }\n>\n\nexport type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{\n /** @field epoch after which any reoccurrence stops */\n end?: number\n\n /** @field time between triggers [non-repeating if undefined] */\n frequency?: number\n\n /** @field units for frequency field [hour if undefined] */\n frequencyUnits?: 'second' | 'minute' | 'hour' | 'day'\n\n /** @field remaining triggers [infinite if undefined] */\n remaining?: number\n\n /** @field epoch of the next trigger */\n start: number\n\n type: 'interval'\n}>\n\nexport type SentinelChangeAutomationPayload = SentinelBaseAutomationPayload<{\n type: 'change'\n}>\n\nexport type SentinelAutomationPayload = SentinelIntervalAutomationPayload | SentinelChangeAutomationPayload\n","import { fulfilled, rejected } from '@xylabs/promise'\nimport { Address } from '@xyo-network/core'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n ResolvedSentinelTask,\n SentinelConfig,\n SentinelConfigSchema,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nimport { AbstractSentinel } from './AbstractSentinel'\n\nexport type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>\n\nexport class MemorySentinel<\n TParams extends MemorySentinelParams = MemorySentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [SentinelConfigSchema]\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n const job = await this.jobPromise\n\n let index = 0\n let previousResults: Record<Address, Payload[]> = {}\n while (index < job.tasks.length) {\n const generatedPayloads = await this.generateResults(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n return Object.values(previousResults).flat()\n }\n\n private async generateResults(\n tasks: ResolvedSentinelTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const witness = asWitnessInstance(task.module)\n const input = task.input ?? false\n if (witness) {\n return [witness.address, await witness.observe(input === true ? inPayloads : input === false ? [] : previousResults[input])]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n return [diviner.address, await diviner.divine(input === true ? inPayloads : input === false ? [] : previousResults[input])]\n }\n throw Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n results.filter(fulfilled).forEach((result) => {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n })\n const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw Error('At least one module failed')\n }\n return finalResult\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.payload().frequency\n if (frequency === undefined) return Infinity\n switch (this.payload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.payload().start = this.payload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload().start > (this.payload().end ?? Infinity)) {\n this.payload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.payload().remaining = remaining\n\n if (remaining <= 0) {\n this.payload().start = Infinity\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nimport { SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation'\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n automations?.forEach((automation) => this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n return Object.values(this._automations).reduce<SentinelIntervalAutomationPayload | undefined>((previous, current) => {\n if (current.type === 'interval') {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (automation) {\n const delay = automation.start - Date.now()\n if (delay < 0) {\n //automation is due, just do it\n await this.trigger(automation)\n } else {\n this.timeoutId = setTimeout(\n async () => {\n this.timeoutId = undefined\n await this.start()\n },\n delay > 0 ? delay : 0,\n )\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.payload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n await this.start()\n }\n}\n","import { ArchivistInstance } from '@xyo-network/archivist'\nimport { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module-wrapper'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n isSentinelInstance,\n isSentinelModule,\n SentinelInstance,\n SentinelModule,\n SentinelReportQuery,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { WitnessInstance } from '@xyo-network/witness-model'\n\nconstructableModuleWrapper()\nexport class SentinelWrapper<TModule extends SentinelModule = SentinelModule>\n extends ModuleWrapper<TModule>\n implements SentinelInstance<TModule['params']>\n{\n static override instanceIdentityCheck = isSentinelInstance\n static override moduleIdentityCheck = isSentinelModule\n static override requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries]\n\n archivists(): Promise<ArchivistInstance[]> {\n throw Error('Not supported')\n }\n\n async report(payloads?: Payload[]): Promise<Payload[]> {\n const queryPayload: SentinelReportQuery = { schema: SentinelReportQuerySchema }\n const result = await this.sendQuery(queryPayload, payloads)\n return result\n }\n\n witnesses(): Promise<WitnessInstance[]> {\n throw Error('Not supported')\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,kCAAyC;AACzC,gCAAiF;AACjF,6BAAuC;AAGvC,4BASO;AAEA,IAAe,mBAAf,cAIG,8CAEV;AAAA,EACE,UAA0B,CAAC;AAAA,EACnB;AAAA,EAER,IAAI,aAAa;AACf,SAAK,cAAc,KAAK,eAAe,KAAK,YAAY;AACxD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAa,UAAoB;AAC/B,WAAO,CAAC,iDAA2B,GAAG,MAAM,OAAO;AAAA,EACrD;AAAA,EAEA,IAAuB,qBAAkE;AACvF,WAAO;AAAA,MACL,qCAAqC;AAAA,IACvC;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,YAA4C;AACvD,SAAK,YAAY,QAAQ;AACzB,UAAM,KAAK,KAAK,eAAe,EAAE,YAAY,QAAQ,KAAK,CAAC;AAC3D,UAAM,WAAW,MAAM,KAAK,cAAc,UAAU;AAEpD,UAAM,iBAAiB,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AAAA,EACE,OAAgB,wBAAwB;AAAA,EACxC,OAAgB,sBAAsB;AAAA,EACtC,OAAgB,kBAAkB,CAAC,kDAA2B,GAAG,MAAM,eAAe;AAAA,EAEtF,aAA2C;AACzC,UAAM,MAAM,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,UAA0C;AACrD,UAAM,eAAoC,EAAE,QAAQ,iDAA0B;AAC9E,UAAM,SAAS,MAAM,KAAK,UAAU,cAAc,QAAQ;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;;;AN7BA,wBAAc,wCANd;","names":["import_sentinel_model","import_assert","import_payload_wrapper","import_sentinel_model"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Automation.ts","../../src/MemorySentinel.ts","../../src/SentinelIntervalAutomationWrapper.ts","../../src/SentinelRunner.ts","../../src/Wrapper.ts"],"sourcesContent":["export * from './Automation'\nexport * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\nexport * from './Wrapper'\nexport * from '@xyo-network/sentinel-abstract'\nexport * from '@xyo-network/sentinel-model'\n","import { AnyObject } from '@xyo-network/core'\nimport { Payload } from '@xyo-network/payload-model'\nimport { SentinelTask } from '@xyo-network/sentinel-model'\n\nexport type SentinelAutomationSchema = 'network.xyo.automation'\nexport const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'\n\nexport type SentinelBaseAutomationPayload<T extends AnyObject = AnyObject> = Payload<\n T & {\n schema: SentinelAutomationSchema\n tasks?: SentinelTask[]\n type?: 'interval' | 'change'\n }\n>\n\nexport type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{\n /** @field epoch after which any reoccurrence stops */\n end?: number\n\n /** @field time between triggers [non-repeating if undefined] */\n frequency?: number\n\n /** @field units for frequency field [hour if undefined] */\n frequencyUnits?: 'second' | 'minute' | 'hour' | 'day'\n\n /** @field remaining triggers [infinite if undefined] */\n remaining?: number\n\n /** @field epoch of the next trigger */\n start: number\n\n type: 'interval'\n}>\n\nexport type SentinelChangeAutomationPayload = SentinelBaseAutomationPayload<{\n type: 'change'\n}>\n\nexport type SentinelAutomationPayload = SentinelIntervalAutomationPayload | SentinelChangeAutomationPayload\n","import { fulfilled, rejected } from '@xylabs/promise'\nimport { Address } from '@xyo-network/core'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport {\n ResolvedSentinelTask,\n SentinelConfig,\n SentinelConfigSchema,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nexport type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>\n\nexport class MemorySentinel<\n TParams extends MemorySentinelParams = MemorySentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [SentinelConfigSchema]\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n const job = await this.jobPromise\n\n let index = 0\n let previousResults: Record<Address, Payload[]> = {}\n while (index < job.tasks.length) {\n const generatedPayloads = await this.generateResults(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n return Object.values(previousResults).flat()\n }\n\n private async generateResults(\n tasks: ResolvedSentinelTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const witness = asWitnessInstance(task.module)\n const input = task.input ?? false\n if (witness) {\n return [witness.address, await witness.observe(input === true ? inPayloads : input === false ? [] : previousResults[input])]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n return [diviner.address, await diviner.divine(input === true ? inPayloads : input === false ? [] : previousResults[input])]\n }\n throw Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n results.filter(fulfilled).forEach((result) => {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n })\n const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw Error('At least one module failed')\n }\n return finalResult\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.payload().frequency\n if (frequency === undefined) return Infinity\n switch (this.payload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.payload().start = this.payload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload().start > (this.payload().end ?? Infinity)) {\n this.payload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.payload().remaining = remaining\n\n if (remaining <= 0) {\n this.payload().start = Infinity\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nimport { SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation'\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n automations?.forEach((automation) => this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n return Object.values(this._automations).reduce<SentinelIntervalAutomationPayload | undefined>((previous, current) => {\n if (current.type === 'interval') {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (automation) {\n const delay = automation.start - Date.now()\n if (delay < 0) {\n //automation is due, just do it\n await this.trigger(automation)\n } else {\n this.timeoutId = setTimeout(\n async () => {\n this.timeoutId = undefined\n await this.start()\n },\n delay > 0 ? delay : 0,\n )\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.payload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n await this.start()\n }\n}\n","import { ArchivistInstance } from '@xyo-network/archivist'\nimport { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module-wrapper'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n isSentinelInstance,\n isSentinelModule,\n SentinelInstance,\n SentinelModule,\n SentinelReportQuery,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { WitnessInstance } from '@xyo-network/witness-model'\n\nconstructableModuleWrapper()\nexport class SentinelWrapper<TModule extends SentinelModule = SentinelModule>\n extends ModuleWrapper<TModule>\n implements SentinelInstance<TModule['params']>\n{\n static override instanceIdentityCheck = isSentinelInstance\n static override moduleIdentityCheck = isSentinelModule\n static override requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries]\n\n archivists(): Promise<ArchivistInstance[]> {\n throw Error('Not supported')\n }\n\n async report(payloads?: Payload[]): Promise<Payload[]> {\n const queryPayload: SentinelReportQuery = { schema: SentinelReportQuerySchema }\n const result = await this.sendQuery(queryPayload, payloads)\n return result\n }\n\n witnesses(): Promise<WitnessInstance[]> {\n throw Error('Not supported')\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,2BAAqD;;;ACLlE,qBAAoC;AAEpC,2BAAkC;AAGlC,+BAAiC;AACjC,4BAOO;AACP,2BAAkC;AAI3B,IAAM,iBAAN,cAGG,0CAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,0CAAoB;AAAA,EAErD,MAAM,cAAc,aAAwB,CAAC,GAAuB;AAClE,UAAM,KAAK,QAAQ,OAAO;AAC1B,UAAM,MAAM,MAAM,KAAK;AAEvB,QAAI,QAAQ;AACZ,QAAI,kBAA8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,OAAO;AACL,QAAI,KAAK,WAAW;AAClB,mBAAa,KAAK,SAAS;AAC3B,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,MAAc,YAAuC,UAAU,MAAM;AAChF,UAAM,KAAK,OAAO,MAAM,KAAK;AAC7B,UAAM,KAAK,IAAI,YAAY,KAAK;AAChC,QAAI;AAAS,YAAM,KAAK,QAAQ;AAAA,EAClC;AAAA,EAEA,MAAc,QAAQ,YAA+C;AA7FvE;AA8FI,UAAM,UAAU,IAAI,kCAAkC,UAAU;AAChE,UAAM,KAAK,OAAO,MAAM,QAAQ,UAAU,GAAG,KAAK;AAClD,YAAQ,KAAK;AACb,UAAM,KAAK,IAAI,QAAQ,QAAQ,GAAG,KAAK;AACvC,UAAM,gBAAgB,MAAM,KAAK,SAAS,OAAO;AACjD,eAAK,oBAAL,8BAAuB;AACvB,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;;;ACrGA,4BAA0D;AAE1D,IAAAC,yBAOO;AAAA,IAGP,kDAA2B;AACpB,IAAM,kBAAN,cACG,oCAEV;AAAA,EACE,OAAgB,wBAAwB;AAAA,EACxC,OAAgB,sBAAsB;AAAA,EACtC,OAAgB,kBAAkB,CAAC,kDAA2B,GAAG,MAAM,eAAe;AAAA,EAEtF,aAA2C;AACzC,UAAM,MAAM,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,UAA0C;AACrD,UAAM,eAAoC,EAAE,QAAQ,iDAA0B;AAC9E,UAAM,SAAS,MAAM,KAAK,UAAU,cAAc,QAAQ;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;;;AL9BA,wBAAc,2CALd;AAMA,wBAAc,wCANd;","names":["import_payload_wrapper","import_sentinel_model"]}
@@ -1,82 +1,10 @@
1
- // src/AbstractSentinel.ts
2
- import { assertEx } from "@xylabs/assert";
3
- import { QueryBoundWitnessWrapper } from "@xyo-network/boundwitness-builder";
4
- import { isBoundWitness, notBoundWitness } from "@xyo-network/boundwitness-model";
5
- import { AbstractModuleInstance } from "@xyo-network/module-abstract";
6
- import {
7
- SentinelReportQuerySchema
8
- } from "@xyo-network/sentinel-model";
9
- var AbstractSentinel = class extends AbstractModuleInstance {
10
- history = [];
11
- _jobPromise;
12
- get jobPromise() {
13
- this._jobPromise = this._jobPromise ?? this.generateJob();
14
- return this._jobPromise;
15
- }
16
- get queries() {
17
- return [SentinelReportQuerySchema, ...super.queries];
18
- }
19
- get _queryAccountPaths() {
20
- return {
21
- "network.xyo.query.sentinel.report": "1/1"
22
- };
23
- }
24
- async report(inPayloads) {
25
- this._noOverride("report");
26
- await this.emit("reportStart", { inPayloads, module: this });
27
- const payloads = await this.reportHandler(inPayloads);
28
- const boundwitnesses = payloads.filter(isBoundWitness);
29
- const outPayloads = payloads.filter(notBoundWitness);
30
- const boundwitness = boundwitnesses.find((bw) => bw.addresses.includes(this.address));
31
- await this.emit("reportEnd", { boundwitness, inPayloads, module: this, outPayloads });
32
- return payloads;
33
- }
34
- async generateJob() {
35
- const job = { tasks: [] };
36
- let tasks = await Promise.all(
37
- this.config.tasks.map(async (task) => ({
38
- input: task.input ?? false,
39
- module: assertEx(await this.resolve(task.module), `Unable to resolve task module [${task.module}]`)
40
- }))
41
- );
42
- while (tasks.length) {
43
- const previousTasks = job.tasks.length ? job.tasks[job.tasks.length - 1] : [];
44
- const newList = (
45
- //add all tasks that either require no previous input or have the previous input module already added
46
- tasks.filter(
47
- (task) => typeof task.input === "boolean" || previousTasks.find((prevTask) => prevTask.module.address === task.input || prevTask.module.config.name === task.input)
48
- )
49
- );
50
- assertEx(newList.length > 0, `Unable to generateJob [${tasks.length}]`);
51
- job.tasks.push(newList);
52
- tasks = tasks.filter((task) => !newList.includes(task));
53
- }
54
- return job;
55
- }
56
- async queryHandler(query, payloads, queryConfig) {
57
- const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads);
58
- const queryPayload = await wrapper.getQuery();
59
- assertEx(this.queryable(query, payloads, queryConfig));
60
- const resultPayloads = [];
61
- switch (queryPayload.schema) {
62
- case SentinelReportQuerySchema: {
63
- resultPayloads.push(...await this.report(payloads));
64
- break;
65
- }
66
- default: {
67
- return super.queryHandler(query, payloads);
68
- }
69
- }
70
- return resultPayloads;
71
- }
72
- };
73
-
74
1
  // src/Automation.ts
75
2
  var SentinelAutomationSchema = "network.xyo.automation";
76
3
 
77
4
  // src/MemorySentinel.ts
78
5
  import { fulfilled, rejected } from "@xylabs/promise";
79
6
  import { asDivinerInstance } from "@xyo-network/diviner-model";
7
+ import { AbstractSentinel } from "@xyo-network/sentinel-abstract";
80
8
  import {
81
9
  SentinelConfigSchema
82
10
  } from "@xyo-network/sentinel-model";
@@ -169,7 +97,7 @@ var SentinelIntervalAutomationWrapper = class extends PayloadWrapper {
169
97
  };
170
98
 
171
99
  // src/SentinelRunner.ts
172
- import { assertEx as assertEx2 } from "@xylabs/assert";
100
+ import { assertEx } from "@xylabs/assert";
173
101
  import { PayloadWrapper as PayloadWrapper2 } from "@xyo-network/payload-wrapper";
174
102
  var SentinelRunner = class {
175
103
  _automations = {};
@@ -215,7 +143,7 @@ var SentinelRunner = class {
215
143
  await this.start();
216
144
  }
217
145
  async start() {
218
- assertEx2(this.timeoutId === void 0, "Already started");
146
+ assertEx(this.timeoutId === void 0, "Already started");
219
147
  const automation = this.next;
220
148
  if (automation) {
221
149
  const delay = automation.start - Date.now();
@@ -261,18 +189,18 @@ import { constructableModuleWrapper, ModuleWrapper } from "@xyo-network/module-w
261
189
  import {
262
190
  isSentinelInstance,
263
191
  isSentinelModule,
264
- SentinelReportQuerySchema as SentinelReportQuerySchema2
192
+ SentinelReportQuerySchema
265
193
  } from "@xyo-network/sentinel-model";
266
194
  constructableModuleWrapper();
267
195
  var SentinelWrapper = class extends ModuleWrapper {
268
196
  static instanceIdentityCheck = isSentinelInstance;
269
197
  static moduleIdentityCheck = isSentinelModule;
270
- static requiredQueries = [SentinelReportQuerySchema2, ...super.requiredQueries];
198
+ static requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries];
271
199
  archivists() {
272
200
  throw Error("Not supported");
273
201
  }
274
202
  async report(payloads) {
275
- const queryPayload = { schema: SentinelReportQuerySchema2 };
203
+ const queryPayload = { schema: SentinelReportQuerySchema };
276
204
  const result = await this.sendQuery(queryPayload, payloads);
277
205
  return result;
278
206
  }
@@ -282,9 +210,9 @@ var SentinelWrapper = class extends ModuleWrapper {
282
210
  };
283
211
 
284
212
  // src/index.ts
213
+ export * from "@xyo-network/sentinel-abstract";
285
214
  export * from "@xyo-network/sentinel-model";
286
215
  export {
287
- AbstractSentinel,
288
216
  MemorySentinel,
289
217
  SentinelAutomationSchema,
290
218
  SentinelIntervalAutomationWrapper,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/AbstractSentinel.ts","../../src/Automation.ts","../../src/MemorySentinel.ts","../../src/SentinelIntervalAutomationWrapper.ts","../../src/SentinelRunner.ts","../../src/Wrapper.ts","../../src/index.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'\nimport { BoundWitness, isBoundWitness, notBoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model'\nimport { AbstractModuleInstance } from '@xyo-network/module-abstract'\nimport { ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n CustomSentinelInstance,\n ResolvedSentinelTask,\n SentinelInstance,\n SentinelJob,\n SentinelModuleEventData,\n SentinelParams,\n SentinelQueryBase,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\n\nexport abstract class AbstractSentinel<\n TParams extends SentinelParams = SentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n >\n extends AbstractModuleInstance<TParams, TEventData>\n implements CustomSentinelInstance<TParams, TEventData>\n{\n history: BoundWitness[] = []\n private _jobPromise?: Promise<SentinelJob>\n\n get jobPromise() {\n this._jobPromise = this._jobPromise ?? this.generateJob()\n return this._jobPromise\n }\n\n override get queries(): string[] {\n return [SentinelReportQuerySchema, ...super.queries]\n }\n\n protected override get _queryAccountPaths(): Record<SentinelQueryBase['schema'], string> {\n return {\n 'network.xyo.query.sentinel.report': '1/1',\n }\n }\n\n async report(inPayloads?: Payload[]): Promise<Payload[]> {\n this._noOverride('report')\n await this.emit('reportStart', { inPayloads, module: this })\n const payloads = await this.reportHandler(inPayloads)\n //this.logger?.debug(`report:payloads: ${JSON.stringify(payloads, null, 2)}`)\n const boundwitnesses = payloads.filter(isBoundWitness)\n const outPayloads = payloads.filter(notBoundWitness)\n const boundwitness = boundwitnesses.find((bw) => bw.addresses.includes(this.address))\n await this.emit('reportEnd', { boundwitness, inPayloads, module: this, outPayloads })\n return payloads\n }\n\n protected async generateJob() {\n const job: SentinelJob = { tasks: [] }\n let tasks: ResolvedSentinelTask[] = await Promise.all(\n this.config.tasks.map(async (task) => ({\n input: task.input ?? false,\n module: assertEx(await this.resolve(task.module), `Unable to resolve task module [${task.module}]`),\n })),\n )\n while (tasks.length) {\n const previousTasks = job.tasks.length ? job.tasks[job.tasks.length - 1] : []\n const newList =\n //add all tasks that either require no previous input or have the previous input module already added\n tasks.filter(\n (task) =>\n typeof task.input === 'boolean' ||\n previousTasks.find((prevTask) => prevTask.module.address === task.input || prevTask.module.config.name === task.input),\n )\n assertEx(newList.length > 0, `Unable to generateJob [${tasks.length}]`)\n job.tasks.push(newList)\n //remove the tasks we just added\n tasks = tasks.filter((task) => !newList.includes(task))\n }\n return job\n }\n\n protected override async queryHandler<T extends QueryBoundWitness = QueryBoundWitness, TConfig extends ModuleConfig = ModuleConfig>(\n query: T,\n payloads?: Payload[],\n queryConfig?: TConfig,\n ): Promise<ModuleQueryHandlerResult> {\n const wrapper = QueryBoundWitnessWrapper.parseQuery<SentinelQueryBase>(query, payloads)\n const queryPayload = await wrapper.getQuery()\n assertEx(this.queryable(query, payloads, queryConfig))\n const resultPayloads: Payload[] = []\n switch (queryPayload.schema) {\n case SentinelReportQuerySchema: {\n resultPayloads.push(...(await this.report(payloads)))\n break\n }\n default: {\n return super.queryHandler(query, payloads)\n }\n }\n return resultPayloads\n }\n\n abstract reportHandler(payloads?: Payload[]): Promise<Payload[]>\n}\n","import { AnyObject } from '@xyo-network/core'\nimport { Payload } from '@xyo-network/payload-model'\nimport { SentinelTask } from '@xyo-network/sentinel-model'\n\nexport type SentinelAutomationSchema = 'network.xyo.automation'\nexport const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'\n\nexport type SentinelBaseAutomationPayload<T extends AnyObject = AnyObject> = Payload<\n T & {\n schema: SentinelAutomationSchema\n tasks?: SentinelTask[]\n type?: 'interval' | 'change'\n }\n>\n\nexport type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{\n /** @field epoch after which any reoccurrence stops */\n end?: number\n\n /** @field time between triggers [non-repeating if undefined] */\n frequency?: number\n\n /** @field units for frequency field [hour if undefined] */\n frequencyUnits?: 'second' | 'minute' | 'hour' | 'day'\n\n /** @field remaining triggers [infinite if undefined] */\n remaining?: number\n\n /** @field epoch of the next trigger */\n start: number\n\n type: 'interval'\n}>\n\nexport type SentinelChangeAutomationPayload = SentinelBaseAutomationPayload<{\n type: 'change'\n}>\n\nexport type SentinelAutomationPayload = SentinelIntervalAutomationPayload | SentinelChangeAutomationPayload\n","import { fulfilled, rejected } from '@xylabs/promise'\nimport { Address } from '@xyo-network/core'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n ResolvedSentinelTask,\n SentinelConfig,\n SentinelConfigSchema,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nimport { AbstractSentinel } from './AbstractSentinel'\n\nexport type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>\n\nexport class MemorySentinel<\n TParams extends MemorySentinelParams = MemorySentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [SentinelConfigSchema]\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n const job = await this.jobPromise\n\n let index = 0\n let previousResults: Record<Address, Payload[]> = {}\n while (index < job.tasks.length) {\n const generatedPayloads = await this.generateResults(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n return Object.values(previousResults).flat()\n }\n\n private async generateResults(\n tasks: ResolvedSentinelTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const witness = asWitnessInstance(task.module)\n const input = task.input ?? false\n if (witness) {\n return [witness.address, await witness.observe(input === true ? inPayloads : input === false ? [] : previousResults[input])]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n return [diviner.address, await diviner.divine(input === true ? inPayloads : input === false ? [] : previousResults[input])]\n }\n throw Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n results.filter(fulfilled).forEach((result) => {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n })\n const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw Error('At least one module failed')\n }\n return finalResult\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.payload().frequency\n if (frequency === undefined) return Infinity\n switch (this.payload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.payload().start = this.payload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload().start > (this.payload().end ?? Infinity)) {\n this.payload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.payload().remaining = remaining\n\n if (remaining <= 0) {\n this.payload().start = Infinity\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nimport { SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation'\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n automations?.forEach((automation) => this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n return Object.values(this._automations).reduce<SentinelIntervalAutomationPayload | undefined>((previous, current) => {\n if (current.type === 'interval') {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (automation) {\n const delay = automation.start - Date.now()\n if (delay < 0) {\n //automation is due, just do it\n await this.trigger(automation)\n } else {\n this.timeoutId = setTimeout(\n async () => {\n this.timeoutId = undefined\n await this.start()\n },\n delay > 0 ? delay : 0,\n )\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.payload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n await this.start()\n }\n}\n","import { ArchivistInstance } from '@xyo-network/archivist'\nimport { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module-wrapper'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n isSentinelInstance,\n isSentinelModule,\n SentinelInstance,\n SentinelModule,\n SentinelReportQuery,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { WitnessInstance } from '@xyo-network/witness-model'\n\nconstructableModuleWrapper()\nexport class SentinelWrapper<TModule extends SentinelModule = SentinelModule>\n extends ModuleWrapper<TModule>\n implements SentinelInstance<TModule['params']>\n{\n static override instanceIdentityCheck = isSentinelInstance\n static override moduleIdentityCheck = isSentinelModule\n static override requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries]\n\n archivists(): Promise<ArchivistInstance[]> {\n throw Error('Not supported')\n }\n\n async report(payloads?: Payload[]): Promise<Payload[]> {\n const queryPayload: SentinelReportQuery = { schema: SentinelReportQuerySchema }\n const result = await this.sendQuery(queryPayload, payloads)\n return result\n }\n\n witnesses(): Promise<WitnessInstance[]> {\n throw Error('Not supported')\n }\n}\n","export * from './AbstractSentinel'\nexport * from './Automation'\nexport * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\nexport * from './Wrapper'\nexport * from '@xyo-network/sentinel-model'\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,gCAAgC;AACzC,SAAuB,gBAAgB,uBAA0C;AACjF,SAAS,8BAA8B;AAGvC;AAAA,EAQE;AAAA,OACK;AAEA,IAAe,mBAAf,cAIG,uBAEV;AAAA,EACE,UAA0B,CAAC;AAAA,EACnB;AAAA,EAER,IAAI,aAAa;AACf,SAAK,cAAc,KAAK,eAAe,KAAK,YAAY;AACxD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAa,UAAoB;AAC/B,WAAO,CAAC,2BAA2B,GAAG,MAAM,OAAO;AAAA,EACrD;AAAA,EAEA,IAAuB,qBAAkE;AACvF,WAAO;AAAA,MACL,qCAAqC;AAAA,IACvC;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,YAA4C;AACvD,SAAK,YAAY,QAAQ;AACzB,UAAM,KAAK,KAAK,eAAe,EAAE,YAAY,QAAQ,KAAK,CAAC;AAC3D,UAAM,WAAW,MAAM,KAAK,cAAc,UAAU;AAEpD,UAAM,iBAAiB,SAAS,OAAO,cAAc;AACrD,UAAM,cAAc,SAAS,OAAO,eAAe;AACnD,UAAM,eAAe,eAAe,KAAK,CAAC,OAAO,GAAG,UAAU,SAAS,KAAK,OAAO,CAAC;AACpF,UAAM,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AAsB;AAAA,EACtC,OAAgB,kBAAkB,CAACA,4BAA2B,GAAG,MAAM,eAAe;AAAA,EAEtF,aAA2C;AACzC,UAAM,MAAM,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,UAA0C;AACrD,UAAM,eAAoC,EAAE,QAAQA,2BAA0B;AAC9E,UAAM,SAAS,MAAM,KAAK,UAAU,cAAc,QAAQ;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;;;AC7BA,cAAc;","names":["assertEx","PayloadWrapper","PayloadWrapper","assertEx","SentinelReportQuerySchema"]}
1
+ {"version":3,"sources":["../../src/Automation.ts","../../src/MemorySentinel.ts","../../src/SentinelIntervalAutomationWrapper.ts","../../src/SentinelRunner.ts","../../src/Wrapper.ts","../../src/index.ts"],"sourcesContent":["import { AnyObject } from '@xyo-network/core'\nimport { Payload } from '@xyo-network/payload-model'\nimport { SentinelTask } from '@xyo-network/sentinel-model'\n\nexport type SentinelAutomationSchema = 'network.xyo.automation'\nexport const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'\n\nexport type SentinelBaseAutomationPayload<T extends AnyObject = AnyObject> = Payload<\n T & {\n schema: SentinelAutomationSchema\n tasks?: SentinelTask[]\n type?: 'interval' | 'change'\n }\n>\n\nexport type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{\n /** @field epoch after which any reoccurrence stops */\n end?: number\n\n /** @field time between triggers [non-repeating if undefined] */\n frequency?: number\n\n /** @field units for frequency field [hour if undefined] */\n frequencyUnits?: 'second' | 'minute' | 'hour' | 'day'\n\n /** @field remaining triggers [infinite if undefined] */\n remaining?: number\n\n /** @field epoch of the next trigger */\n start: number\n\n type: 'interval'\n}>\n\nexport type SentinelChangeAutomationPayload = SentinelBaseAutomationPayload<{\n type: 'change'\n}>\n\nexport type SentinelAutomationPayload = SentinelIntervalAutomationPayload | SentinelChangeAutomationPayload\n","import { fulfilled, rejected } from '@xylabs/promise'\nimport { Address } from '@xyo-network/core'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport {\n ResolvedSentinelTask,\n SentinelConfig,\n SentinelConfigSchema,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nexport type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>\n\nexport class MemorySentinel<\n TParams extends MemorySentinelParams = MemorySentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [SentinelConfigSchema]\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n const job = await this.jobPromise\n\n let index = 0\n let previousResults: Record<Address, Payload[]> = {}\n while (index < job.tasks.length) {\n const generatedPayloads = await this.generateResults(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n return Object.values(previousResults).flat()\n }\n\n private async generateResults(\n tasks: ResolvedSentinelTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const witness = asWitnessInstance(task.module)\n const input = task.input ?? false\n if (witness) {\n return [witness.address, await witness.observe(input === true ? inPayloads : input === false ? [] : previousResults[input])]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n return [diviner.address, await diviner.divine(input === true ? inPayloads : input === false ? [] : previousResults[input])]\n }\n throw Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n results.filter(fulfilled).forEach((result) => {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n })\n const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw Error('At least one module failed')\n }\n return finalResult\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.payload().frequency\n if (frequency === undefined) return Infinity\n switch (this.payload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.payload().start = this.payload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload().start > (this.payload().end ?? Infinity)) {\n this.payload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.payload().remaining = remaining\n\n if (remaining <= 0) {\n this.payload().start = Infinity\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nimport { SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation'\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n automations?.forEach((automation) => this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n return Object.values(this._automations).reduce<SentinelIntervalAutomationPayload | undefined>((previous, current) => {\n if (current.type === 'interval') {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (automation) {\n const delay = automation.start - Date.now()\n if (delay < 0) {\n //automation is due, just do it\n await this.trigger(automation)\n } else {\n this.timeoutId = setTimeout(\n async () => {\n this.timeoutId = undefined\n await this.start()\n },\n delay > 0 ? delay : 0,\n )\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.payload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n await this.start()\n }\n}\n","import { ArchivistInstance } from '@xyo-network/archivist'\nimport { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module-wrapper'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n isSentinelInstance,\n isSentinelModule,\n SentinelInstance,\n SentinelModule,\n SentinelReportQuery,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { WitnessInstance } from '@xyo-network/witness-model'\n\nconstructableModuleWrapper()\nexport class SentinelWrapper<TModule extends SentinelModule = SentinelModule>\n extends ModuleWrapper<TModule>\n implements SentinelInstance<TModule['params']>\n{\n static override instanceIdentityCheck = isSentinelInstance\n static override moduleIdentityCheck = isSentinelModule\n static override requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries]\n\n archivists(): Promise<ArchivistInstance[]> {\n throw Error('Not supported')\n }\n\n async report(payloads?: Payload[]): Promise<Payload[]> {\n const queryPayload: SentinelReportQuery = { schema: SentinelReportQuerySchema }\n const result = await this.sendQuery(queryPayload, payloads)\n return result\n }\n\n witnesses(): Promise<WitnessInstance[]> {\n throw Error('Not supported')\n }\n}\n","export * from './Automation'\nexport * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\nexport * from './Wrapper'\nexport * from '@xyo-network/sentinel-abstract'\nexport * from '@xyo-network/sentinel-model'\n"],"mappings":";AAKO,IAAM,2BAAqD;;;ACLlE,SAAS,WAAW,gBAAgB;AAEpC,SAAS,yBAAyB;AAGlC,SAAS,wBAAwB;AACjC;AAAA,EAGE;AAAA,OAIK;AACP,SAAS,yBAAyB;AAI3B,IAAM,iBAAN,cAGG,iBAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,oBAAoB;AAAA,EAErD,MAAM,cAAc,aAAwB,CAAC,GAAuB;AAClE,UAAM,KAAK,QAAQ,OAAO;AAC1B,UAAM,MAAM,MAAM,KAAK;AAEvB,QAAI,QAAQ;AACZ,QAAI,kBAA8C,CAAC;AACnD,WAAO,QAAQ,IAAI,MAAM,QAAQ;AAC/B,YAAM,oBAAoB,MAAM,KAAK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AAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,MAAc,YAAuC,UAAU,MAAM;AAChF,UAAM,KAAK,OAAO,MAAM,KAAK;AAC7B,UAAM,KAAK,IAAI,YAAY,KAAK;AAChC,QAAI;AAAS,YAAM,KAAK,QAAQ;AAAA,EAClC;AAAA,EAEA,MAAc,QAAQ,YAA+C;AA7FvE;AA8FI,UAAM,UAAU,IAAI,kCAAkC,UAAU;AAChE,UAAM,KAAK,OAAO,MAAM,QAAQ,UAAU,GAAG,KAAK;AAClD,YAAQ,KAAK;AACb,UAAM,KAAK,IAAI,QAAQ,QAAQ,GAAG,KAAK;AACvC,UAAM,gBAAgB,MAAM,KAAK,SAAS,OAAO;AACjD,eAAK,oBAAL,8BAAuB;AACvB,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;;;ACrGA,SAAS,4BAA4B,qBAAqB;AAE1D;AAAA,EACE;AAAA,EACA;AAAA,EAIA;AAAA,OACK;AAGP,2BAA2B;AACpB,IAAM,kBAAN,cACG,cAEV;AAAA,EACE,OAAgB,wBAAwB;AAAA,EACxC,OAAgB,sBAAsB;AAAA,EACtC,OAAgB,kBAAkB,CAAC,2BAA2B,GAAG,MAAM,eAAe;AAAA,EAEtF,aAA2C;AACzC,UAAM,MAAM,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,UAA0C;AACrD,UAAM,eAAoC,EAAE,QAAQ,0BAA0B;AAC9E,UAAM,SAAS,MAAM,KAAK,UAAU,cAAc,QAAQ;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;;;AC9BA,cAAc;AACd,cAAc;","names":["PayloadWrapper","PayloadWrapper"]}
package/package.json CHANGED
@@ -12,31 +12,29 @@
12
12
  "dependencies": {
13
13
  "@xylabs/assert": "^2.12.28",
14
14
  "@xylabs/promise": "^2.12.28",
15
- "@xyo-network/archivist": "~2.76.1",
16
- "@xyo-network/boundwitness-builder": "~2.76.1",
17
- "@xyo-network/boundwitness-model": "~2.76.1",
18
- "@xyo-network/core": "~2.76.1",
19
- "@xyo-network/diviner-model": "~2.76.1",
20
- "@xyo-network/module-abstract": "~2.76.1",
21
- "@xyo-network/module-model": "~2.76.1",
22
- "@xyo-network/module-wrapper": "~2.76.1",
23
- "@xyo-network/payload-model": "~2.76.1",
24
- "@xyo-network/payload-wrapper": "~2.76.1",
25
- "@xyo-network/sentinel-model": "~2.76.1",
26
- "@xyo-network/witness-model": "~2.76.1"
15
+ "@xyo-network/archivist": "~2.77.0",
16
+ "@xyo-network/core": "~2.77.0",
17
+ "@xyo-network/diviner-model": "~2.77.0",
18
+ "@xyo-network/module-model": "~2.77.0",
19
+ "@xyo-network/module-wrapper": "~2.77.0",
20
+ "@xyo-network/payload-model": "~2.77.0",
21
+ "@xyo-network/payload-wrapper": "~2.77.0",
22
+ "@xyo-network/sentinel-abstract": "~2.77.0",
23
+ "@xyo-network/sentinel-model": "~2.77.0",
24
+ "@xyo-network/witness-model": "~2.77.0"
27
25
  },
28
26
  "description": "Primary SDK for using XYO Protocol 2.0",
29
27
  "devDependencies": {
30
28
  "@xylabs/delay": "^2.12.28",
31
29
  "@xylabs/ts-scripts-yarn3": "^3.1.12",
32
30
  "@xylabs/tsconfig": "^3.1.12",
33
- "@xyo-network/abstract-witness": "~2.76.1",
34
- "@xyo-network/account": "~2.76.1",
35
- "@xyo-network/id-payload-plugin": "~2.76.1",
36
- "@xyo-network/id-plugin": "~2.76.1",
37
- "@xyo-network/node-memory": "~2.76.1",
38
- "@xyo-network/node-system-info-plugin": "~2.76.1",
39
- "@xyo-network/witnesses": "~2.76.1",
31
+ "@xyo-network/abstract-witness": "~2.77.0",
32
+ "@xyo-network/account": "~2.77.0",
33
+ "@xyo-network/id-payload-plugin": "~2.77.0",
34
+ "@xyo-network/id-plugin": "~2.77.0",
35
+ "@xyo-network/node-memory": "~2.77.0",
36
+ "@xyo-network/node-system-info-plugin": "~2.77.0",
37
+ "@xyo-network/witnesses": "~2.77.0",
40
38
  "typescript": "^5.2.2"
41
39
  },
42
40
  "docs": "dist/docs.json",
@@ -78,5 +76,5 @@
78
76
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
79
77
  },
80
78
  "sideEffects": false,
81
- "version": "2.76.1"
79
+ "version": "2.77.0"
82
80
  }
@@ -3,6 +3,7 @@ import { Address } from '@xyo-network/core'
3
3
  import { asDivinerInstance } from '@xyo-network/diviner-model'
4
4
  import { AnyConfigSchema } from '@xyo-network/module-model'
5
5
  import { Payload } from '@xyo-network/payload-model'
6
+ import { AbstractSentinel } from '@xyo-network/sentinel-abstract'
6
7
  import {
7
8
  ResolvedSentinelTask,
8
9
  SentinelConfig,
@@ -13,8 +14,6 @@ import {
13
14
  } from '@xyo-network/sentinel-model'
14
15
  import { asWitnessInstance } from '@xyo-network/witness-model'
15
16
 
16
- import { AbstractSentinel } from './AbstractSentinel'
17
-
18
17
  export type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>
19
18
 
20
19
  export class MemorySentinel<
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from './AbstractSentinel'
2
1
  export * from './Automation'
3
2
  export * from './MemorySentinel'
4
3
  export * from './SentinelIntervalAutomationWrapper'
5
4
  export * from './SentinelRunner'
6
5
  export * from './Wrapper'
6
+ export * from '@xyo-network/sentinel-abstract'
7
7
  export * from '@xyo-network/sentinel-model'
@@ -1,17 +0,0 @@
1
- import { BoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model';
2
- import { AbstractModuleInstance } from '@xyo-network/module-abstract';
3
- import { ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module-model';
4
- import { Payload } from '@xyo-network/payload-model';
5
- import { CustomSentinelInstance, SentinelInstance, SentinelJob, SentinelModuleEventData, SentinelParams, SentinelQueryBase } from '@xyo-network/sentinel-model';
6
- export declare abstract class AbstractSentinel<TParams extends SentinelParams = SentinelParams, TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>> extends AbstractModuleInstance<TParams, TEventData> implements CustomSentinelInstance<TParams, TEventData> {
7
- history: BoundWitness[];
8
- private _jobPromise?;
9
- get jobPromise(): Promise<SentinelJob>;
10
- get queries(): string[];
11
- protected get _queryAccountPaths(): Record<SentinelQueryBase['schema'], string>;
12
- report(inPayloads?: Payload[]): Promise<Payload[]>;
13
- protected generateJob(): Promise<SentinelJob>;
14
- protected queryHandler<T extends QueryBoundWitness = QueryBoundWitness, TConfig extends ModuleConfig = ModuleConfig>(query: T, payloads?: Payload[], queryConfig?: TConfig): Promise<ModuleQueryHandlerResult>;
15
- abstract reportHandler(payloads?: Payload[]): Promise<Payload[]>;
16
- }
17
- //# sourceMappingURL=AbstractSentinel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AbstractSentinel.d.ts","sourceRoot":"","sources":["../../src/AbstractSentinel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAmC,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAClH,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EACL,sBAAsB,EAEtB,gBAAgB,EAChB,WAAW,EACX,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EAElB,MAAM,6BAA6B,CAAA;AAEpC,8BAAsB,gBAAgB,CAClC,OAAO,SAAS,cAAc,GAAG,cAAc,EAC/C,UAAU,SAAS,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAE5H,SAAQ,sBAAsB,CAAC,OAAO,EAAE,UAAU,CAClD,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