@xyo-network/sentinel-memory 3.6.9 → 3.6.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // src/MemorySentinel.ts
5
2
  import { fulfilled, rejected } from "@xylabs/promise";
6
3
  import { asDivinerInstance } from "@xyo-network/diviner-model";
7
4
  import { AbstractSentinel } from "@xyo-network/sentinel-abstract";
8
- import { asSentinelInstance, SentinelConfigSchema } from "@xyo-network/sentinel-model";
5
+ import {
6
+ asSentinelInstance,
7
+ SentinelConfigSchema
8
+ } from "@xyo-network/sentinel-model";
9
9
  import { asWitnessInstance } from "@xyo-network/witness-model";
10
10
 
11
11
  // src/SentinelRunner.ts
@@ -17,9 +17,6 @@ import { isSentinelIntervalAutomation } from "@xyo-network/sentinel-model";
17
17
  // src/SentinelIntervalAutomationWrapper.ts
18
18
  import { PayloadWrapper } from "@xyo-network/payload-wrapper";
19
19
  var SentinelIntervalAutomationWrapper = class extends PayloadWrapper {
20
- static {
21
- __name(this, "SentinelIntervalAutomationWrapper");
22
- }
23
20
  constructor(payload) {
24
21
  super(payload);
25
22
  }
@@ -69,16 +66,16 @@ var SentinelIntervalAutomationWrapper = class extends PayloadWrapper {
69
66
  if (remaining <= 0) this.setStart(Number.POSITIVE_INFINITY);
70
67
  }
71
68
  /**
72
- * Sets the remaining of the wrapped automation
73
- * @param remaining The remaining time in milliseconds
74
- */
69
+ * Sets the remaining of the wrapped automation
70
+ * @param remaining The remaining time in milliseconds
71
+ */
75
72
  setRemaining(remaining) {
76
73
  this.payload.remaining = remaining;
77
74
  }
78
75
  /**
79
- * Sets the start of the wrapped automation
80
- * @param start The start time in milliseconds
81
- */
76
+ * Sets the start of the wrapped automation
77
+ * @param start The start time in milliseconds
78
+ */
82
79
  setStart(start) {
83
80
  this.payload.start = start;
84
81
  }
@@ -86,9 +83,6 @@ var SentinelIntervalAutomationWrapper = class extends PayloadWrapper {
86
83
 
87
84
  // src/SentinelRunner.ts
88
85
  var SentinelRunner = class {
89
- static {
90
- __name(this, "SentinelRunner");
91
- }
92
86
  _automations = {};
93
87
  onTriggerResult;
94
88
  sentinel;
@@ -172,13 +166,7 @@ var SentinelRunner = class {
172
166
 
173
167
  // src/MemorySentinel.ts
174
168
  var MemorySentinel = class extends AbstractSentinel {
175
- static {
176
- __name(this, "MemorySentinel");
177
- }
178
- static configSchemas = [
179
- ...super.configSchemas,
180
- SentinelConfigSchema
181
- ];
169
+ static configSchemas = [...super.configSchemas, SentinelConfigSchema];
182
170
  static defaultConfigSchema = SentinelConfigSchema;
183
171
  runner;
184
172
  async reportHandler(inPayloads = []) {
@@ -218,87 +206,75 @@ var MemorySentinel = class extends AbstractSentinel {
218
206
  return (await Promise.all(input.map(async (inputItem) => await this.inputAddresses(inputItem)))).flat();
219
207
  } else {
220
208
  const resolved = await this.resolve(input);
221
- return resolved ? [
222
- resolved.address
223
- ] : [];
209
+ return resolved ? [resolved.address] : [];
224
210
  }
225
211
  }
226
212
  processPreviousResults(payloads, inputs) {
227
213
  return inputs.flatMap((input) => payloads[input] ?? []);
228
214
  }
229
215
  async runJob(tasks, previousResults, inPayloads) {
230
- await this.emit("jobStart", {
231
- inPayloads,
232
- mod: this
233
- });
216
+ await this.emit("jobStart", { inPayloads, mod: this });
234
217
  this.logger?.debug(`runJob:tasks: ${JSON.stringify(tasks.length)}`);
235
218
  this.logger?.debug(`runJob:previous: ${JSON.stringify(previousResults)}`);
236
219
  this.logger?.debug(`runJob:in: ${JSON.stringify(inPayloads)}`);
237
- const results = await Promise.allSettled(tasks?.map(async (task) => {
238
- const input = task.input ?? false;
239
- const inPayloadsFound = input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input));
240
- const witness = asWitnessInstance(task.mod);
241
- if (witness) {
242
- await this.emit("taskStart", {
243
- address: witness.address,
244
- inPayloads: inPayloadsFound,
245
- mod: this
246
- });
247
- const observed = await witness.observe(inPayloadsFound);
248
- this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`);
249
- await this.emit("taskEnd", {
250
- address: witness.address,
251
- inPayloads: inPayloadsFound,
252
- mod: this,
253
- outPayloads: observed
254
- });
255
- return [
256
- witness.address,
257
- observed
258
- ];
259
- }
260
- const diviner = asDivinerInstance(task.mod);
261
- if (diviner) {
262
- await this.emit("taskStart", {
263
- address: diviner.address,
264
- inPayloads: inPayloadsFound,
265
- mod: this
266
- });
267
- const divined = await diviner.divine(inPayloadsFound);
268
- this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`);
269
- await this.emit("taskEnd", {
270
- address: diviner.address,
271
- inPayloads: inPayloadsFound,
272
- mod: this,
273
- outPayloads: divined
274
- });
275
- return [
276
- diviner.address,
277
- divined
278
- ];
279
- }
280
- const sentinel = asSentinelInstance(task.mod);
281
- if (sentinel) {
282
- await this.emit("taskStart", {
283
- address: sentinel.address,
284
- inPayloads: inPayloadsFound,
285
- mod: this
286
- });
287
- const reported = await sentinel.report(inPayloadsFound);
288
- this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`);
289
- await this.emit("taskEnd", {
290
- address: sentinel.address,
291
- inPayloads: inPayloadsFound,
292
- mod: this,
293
- outPayloads: reported
294
- });
295
- return [
296
- sentinel.address,
297
- reported
298
- ];
299
- }
300
- throw new Error("Unsupported module type");
301
- }));
220
+ const results = await Promise.allSettled(
221
+ tasks?.map(async (task) => {
222
+ const input = task.input ?? false;
223
+ const inPayloadsFound = input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input));
224
+ const witness = asWitnessInstance(task.mod);
225
+ if (witness) {
226
+ await this.emit("taskStart", {
227
+ address: witness.address,
228
+ inPayloads: inPayloadsFound,
229
+ mod: this
230
+ });
231
+ const observed = await witness.observe(inPayloadsFound);
232
+ this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`);
233
+ await this.emit("taskEnd", {
234
+ address: witness.address,
235
+ inPayloads: inPayloadsFound,
236
+ mod: this,
237
+ outPayloads: observed
238
+ });
239
+ return [witness.address, observed];
240
+ }
241
+ const diviner = asDivinerInstance(task.mod);
242
+ if (diviner) {
243
+ await this.emit("taskStart", {
244
+ address: diviner.address,
245
+ inPayloads: inPayloadsFound,
246
+ mod: this
247
+ });
248
+ const divined = await diviner.divine(inPayloadsFound);
249
+ this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`);
250
+ await this.emit("taskEnd", {
251
+ address: diviner.address,
252
+ inPayloads: inPayloadsFound,
253
+ mod: this,
254
+ outPayloads: divined
255
+ });
256
+ return [diviner.address, divined];
257
+ }
258
+ const sentinel = asSentinelInstance(task.mod);
259
+ if (sentinel) {
260
+ await this.emit("taskStart", {
261
+ address: sentinel.address,
262
+ inPayloads: inPayloadsFound,
263
+ mod: this
264
+ });
265
+ const reported = await sentinel.report(inPayloadsFound);
266
+ this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`);
267
+ await this.emit("taskEnd", {
268
+ address: sentinel.address,
269
+ inPayloads: inPayloadsFound,
270
+ mod: this,
271
+ outPayloads: reported
272
+ });
273
+ return [sentinel.address, reported];
274
+ }
275
+ throw new Error("Unsupported module type");
276
+ })
277
+ );
302
278
  const finalResult = {};
303
279
  for (const result of results.filter(fulfilled)) {
304
280
  const [address, payloads] = result.value;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/MemorySentinel.ts","../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["import type { Address } from '@xylabs/hex'\nimport { fulfilled, rejected } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport type { AnyConfigSchema, ModuleIdentifier } from '@xyo-network/module-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport type {\n ResolvedTask,\n SentinelConfig,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport {\n asSentinelInstance,\n SentinelConfigSchema,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nimport { SentinelRunner } from './SentinelRunner.ts'\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 readonly configSchemas: Schema[] = [...super.configSchemas, SentinelConfigSchema]\n static override readonly defaultConfigSchema: Schema = SentinelConfigSchema\n\n private runner?: SentinelRunner\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n this.logger?.debug(`reportHandler:in: ${JSON.stringify(inPayloads)}`)\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.runJob(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n const result = Object.values(previousResults).flat()\n this.logger?.debug(`reportHandler:out: ${JSON.stringify(result)}`)\n return result\n }\n\n override async start(timeout?: number | undefined): Promise<boolean> {\n if (await super.start(timeout)) {\n if ((this.config.automations?.length ?? 0) > 0) {\n this.runner = new SentinelRunner(this, this.config.automations)\n this.runner.start()\n }\n return true\n }\n return false\n }\n\n override async stop(timeout?: number | undefined): Promise<boolean> {\n if (this.runner) {\n this.runner.stop()\n this.runner = undefined\n }\n return await super.stop(timeout)\n }\n\n private async inputAddresses(input: ModuleIdentifier | ModuleIdentifier[]): Promise<Address[]> {\n if (Array.isArray(input)) {\n return (await Promise.all(input.map(async inputItem => await this.inputAddresses(inputItem)))).flat()\n } else {\n const resolved = await this.resolve(input)\n return resolved ? [resolved.address] : []\n }\n }\n\n private processPreviousResults(payloads: Record<string, Payload[]>, inputs: string[]) {\n return inputs.flatMap(input => payloads[input] ?? [])\n }\n\n private async runJob(\n tasks: ResolvedTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n await this.emit('jobStart', { inPayloads, mod: this })\n this.logger?.debug(`runJob:tasks: ${JSON.stringify(tasks.length)}`)\n this.logger?.debug(`runJob:previous: ${JSON.stringify(previousResults)}`)\n this.logger?.debug(`runJob:in: ${JSON.stringify(inPayloads)}`)\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const input = task.input ?? false\n const inPayloadsFound\n = input === true\n ? inPayloads\n : input === false\n ? []\n : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n const witness = asWitnessInstance(task.mod)\n if (witness) {\n await this.emit('taskStart', {\n address: witness.address, inPayloads: inPayloadsFound, mod: this,\n })\n const observed = await witness.observe(inPayloadsFound)\n this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`)\n await this.emit('taskEnd', {\n address: witness.address, inPayloads: inPayloadsFound, mod: this, outPayloads: observed,\n })\n return [witness.address, observed]\n }\n const diviner = asDivinerInstance(task.mod)\n if (diviner) {\n await this.emit('taskStart', {\n address: diviner.address, inPayloads: inPayloadsFound, mod: this,\n })\n const divined = await diviner.divine(inPayloadsFound)\n this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`)\n await this.emit('taskEnd', {\n address: diviner.address, inPayloads: inPayloadsFound, mod: this, outPayloads: divined,\n })\n return [diviner.address, divined]\n }\n const sentinel = asSentinelInstance(task.mod)\n if (sentinel) {\n await this.emit('taskStart', {\n address: sentinel.address, inPayloads: inPayloadsFound, mod: this,\n })\n const reported = await sentinel.report(inPayloadsFound)\n this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`)\n await this.emit('taskEnd', {\n address: sentinel.address, inPayloads: inPayloadsFound, mod: this, outPayloads: reported,\n })\n return [sentinel.address, reported]\n }\n throw new Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n for (const result of results.filter(fulfilled)) {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n }\n if (this.throwErrors) {\n const errors = results.filter(rejected).map(result => result.reason)\n if (errors.length > 0) {\n throw new Error('At least one module failed')\n }\n }\n this.logger?.debug(`generateResults:out: ${JSON.stringify(finalResult)}`)\n await this.emit('jobEnd', {\n finalResult, inPayloads, mod: this,\n })\n return finalResult\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { forget } from '@xylabs/forget'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { Payload } from '@xyo-network/payload-model'\nimport type {\n SentinelAutomationPayload,\n SentinelInstance,\n SentinelIntervalAutomationPayload,\n} from '@xyo-network/sentinel-model'\nimport { isSentinelIntervalAutomation } from '@xyo-network/sentinel-model'\n\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper.ts'\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 if (automations) for (const automation of automations) forget(this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n // eslint-disable-next-line unicorn/no-array-reduce\n return Object.values(this._automations).reduce<SentinelAutomationPayload | undefined>((previous, current) => {\n if (isSentinelIntervalAutomation(current) && isSentinelIntervalAutomation(previous)) {\n return current.start < (previous?.start ?? Number.POSITIVE_INFINITY) ? current : previous\n }\n return current\n // eslint-disable-next-line unicorn/no-useless-undefined\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadBuilder.dataHash(automation)\n this._automations[hash] = automation\n if (restart) this.restart()\n return hash\n }\n\n find(hash: string) {\n return Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n restart() {\n this.stop()\n this.start()\n }\n\n start() {\n assertEx(this.timeoutId === undefined, () => 'Already started')\n const automation = this.next\n if (isSentinelIntervalAutomation(automation)) {\n const now = Date.now()\n const start = Math.max(automation.start ?? now, now)\n const delay = Math.max(start - now, 0)\n if (delay < Number.POSITIVE_INFINITY) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.timeoutId = setTimeout(async () => {\n try {\n // Run the automation\n await this.trigger(automation)\n this.stop()\n } finally {\n // No matter what start the next automation\n this.start()\n }\n }, delay)\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.dataHash(), 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 { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport type { SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model'\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 Number.POSITIVE_INFINITY\n const frequencyUnits = this.payload.frequencyUnits\n switch (frequencyUnits ?? 'hour') {\n case 'second': {\n return frequency * 1000\n }\n case 'minute': {\n return frequency * 60 * 1000\n }\n case 'hour': {\n return frequency * 60 * 60 * 1000\n }\n case 'day': {\n return frequency * 24 * 60 * 60 * 1000\n }\n default: {\n return Number.POSITIVE_INFINITY\n }\n }\n }\n\n protected get remaining() {\n return this.payload.remaining ?? Number.POSITIVE_INFINITY\n }\n\n next() {\n const now = Date.now()\n const previousStart = this.payload?.start ?? now\n const start = Math.max(previousStart, now)\n const nextStart = start + this.frequencyMillis\n this.setStart(nextStart)\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload.start > (this.payload.end ?? Number.POSITIVE_INFINITY)) {\n this.setStart(Number.POSITIVE_INFINITY)\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = Math.max(this.remaining - count, 0)\n this.setRemaining(remaining)\n if (remaining <= 0) this.setStart(Number.POSITIVE_INFINITY)\n }\n\n /**\n * Sets the remaining of the wrapped automation\n * @param remaining The remaining time in milliseconds\n */\n protected setRemaining(remaining: number) {\n this.payload.remaining = remaining\n }\n\n /**\n * Sets the start of the wrapped automation\n * @param start The start time in milliseconds\n */\n protected setStart(start: number) {\n this.payload.start = start\n }\n}\n"],"mappings":";;;;AACA,SAASA,WAAWC,gBAAgB;AACpC,SAASC,yBAAyB;AAGlC,SAASC,wBAAwB;AAQjC,SACEC,oBACAC,4BACK;AACP,SAASC,yBAAyB;;;ACjBlC,SAASC,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,sBAAsB;AAO/B,SAASC,oCAAoC;;;ACT7C,SAASC,sBAAsB;AAGxB,IAAMC,oCAAN,cAEGC,eAAAA;EALV,OAKUA;;;EACRC,YAAYC,SAAY;AACtB,UAAMA,OAAAA;EACR;EAEA,IAAcC,kBAAkB;AAC9B,UAAMC,YAAY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led","rejected","asDivinerInstance","AbstractSentinel","asSentinelInstance","SentinelConfigSchema","asWitnessInstance","assertEx","forget","PayloadBuilder","isSentinelIntervalAutomation","PayloadWrapper","SentinelIntervalAutomationWrapper","PayloadWrapper","constructor","payload","frequencyMillis","frequency","undefined","Number","POSITIVE_INFINITY","frequencyUnits","remaining","next","now","Date","previousStart","start","Math","max","nextStart","setStart","consumeRemaining","checkEnd","end","count","setRemaining","SentinelRunner","_automations","onTriggerResult","sentinel","timeoutId","constructor","automations","automation","forget","add","next","Object","values","reduce","previous","current","isSentinelIntervalAutomation","start","Number","POSITIVE_INFINITY","undefined","restart","hash","PayloadBuilder","dataHash","find","entries","key","remove","removeAll","stop","assertEx","now","Date","Math","max","delay","setTimeout","trigger","clearTimeout","update","wrapper","SentinelIntervalAutomationWrapper","payload","triggerResult","report","MemorySentinel","AbstractSentinel","configSchemas","SentinelConfigSchema","defaultConfigSchema","runner","reportHandler","inPayloads","started","logger","debug","JSON","stringify","job","jobPromise","index","previousResults","tasks","length","generatedPayloads","runJob","result","Object","values","flat","start","timeout","config","automations","SentinelRunner","stop","undefined","inputAddresses","input","Array","isArray","Promise","all","map","inputItem","resolved","resolve","address","processPreviousResults","payloads","inputs","flatMap","emit","mod","results","allSettled","task","inPayloadsFound","witness","asWitnessInstance","observed","observe","id","outPayloads","diviner","asDivinerInstance","divined","divine","sentinel","asSentinelInstance","reported","report","Error","finalResult","filter","fulfilled","value","push","throwErrors","errors","rejected","reason"]}
1
+ {"version":3,"sources":["../../src/MemorySentinel.ts","../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["import type { Address } from '@xylabs/hex'\nimport { fulfilled, rejected } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport type { AnyConfigSchema, ModuleIdentifier } from '@xyo-network/module-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport type {\n ResolvedTask,\n SentinelConfig,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport {\n asSentinelInstance,\n SentinelConfigSchema,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nimport { SentinelRunner } from './SentinelRunner.ts'\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 readonly configSchemas: Schema[] = [...super.configSchemas, SentinelConfigSchema]\n static override readonly defaultConfigSchema: Schema = SentinelConfigSchema\n\n private runner?: SentinelRunner\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n this.logger?.debug(`reportHandler:in: ${JSON.stringify(inPayloads)}`)\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.runJob(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n const result = Object.values(previousResults).flat()\n this.logger?.debug(`reportHandler:out: ${JSON.stringify(result)}`)\n return result\n }\n\n override async start(timeout?: number | undefined): Promise<boolean> {\n if (await super.start(timeout)) {\n if ((this.config.automations?.length ?? 0) > 0) {\n this.runner = new SentinelRunner(this, this.config.automations)\n this.runner.start()\n }\n return true\n }\n return false\n }\n\n override async stop(timeout?: number | undefined): Promise<boolean> {\n if (this.runner) {\n this.runner.stop()\n this.runner = undefined\n }\n return await super.stop(timeout)\n }\n\n private async inputAddresses(input: ModuleIdentifier | ModuleIdentifier[]): Promise<Address[]> {\n if (Array.isArray(input)) {\n return (await Promise.all(input.map(async inputItem => await this.inputAddresses(inputItem)))).flat()\n } else {\n const resolved = await this.resolve(input)\n return resolved ? [resolved.address] : []\n }\n }\n\n private processPreviousResults(payloads: Record<string, Payload[]>, inputs: string[]) {\n return inputs.flatMap(input => payloads[input] ?? [])\n }\n\n private async runJob(\n tasks: ResolvedTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n await this.emit('jobStart', { inPayloads, mod: this })\n this.logger?.debug(`runJob:tasks: ${JSON.stringify(tasks.length)}`)\n this.logger?.debug(`runJob:previous: ${JSON.stringify(previousResults)}`)\n this.logger?.debug(`runJob:in: ${JSON.stringify(inPayloads)}`)\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const input = task.input ?? false\n const inPayloadsFound\n = input === true\n ? inPayloads\n : input === false\n ? []\n : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n const witness = asWitnessInstance(task.mod)\n if (witness) {\n await this.emit('taskStart', {\n address: witness.address, inPayloads: inPayloadsFound, mod: this,\n })\n const observed = await witness.observe(inPayloadsFound)\n this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`)\n await this.emit('taskEnd', {\n address: witness.address, inPayloads: inPayloadsFound, mod: this, outPayloads: observed,\n })\n return [witness.address, observed]\n }\n const diviner = asDivinerInstance(task.mod)\n if (diviner) {\n await this.emit('taskStart', {\n address: diviner.address, inPayloads: inPayloadsFound, mod: this,\n })\n const divined = await diviner.divine(inPayloadsFound)\n this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`)\n await this.emit('taskEnd', {\n address: diviner.address, inPayloads: inPayloadsFound, mod: this, outPayloads: divined,\n })\n return [diviner.address, divined]\n }\n const sentinel = asSentinelInstance(task.mod)\n if (sentinel) {\n await this.emit('taskStart', {\n address: sentinel.address, inPayloads: inPayloadsFound, mod: this,\n })\n const reported = await sentinel.report(inPayloadsFound)\n this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`)\n await this.emit('taskEnd', {\n address: sentinel.address, inPayloads: inPayloadsFound, mod: this, outPayloads: reported,\n })\n return [sentinel.address, reported]\n }\n throw new Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n for (const result of results.filter(fulfilled)) {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n }\n if (this.throwErrors) {\n const errors = results.filter(rejected).map(result => result.reason)\n if (errors.length > 0) {\n throw new Error('At least one module failed')\n }\n }\n this.logger?.debug(`generateResults:out: ${JSON.stringify(finalResult)}`)\n await this.emit('jobEnd', {\n finalResult, inPayloads, mod: this,\n })\n return finalResult\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { forget } from '@xylabs/forget'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { Payload } from '@xyo-network/payload-model'\nimport type {\n SentinelAutomationPayload,\n SentinelInstance,\n SentinelIntervalAutomationPayload,\n} from '@xyo-network/sentinel-model'\nimport { isSentinelIntervalAutomation } from '@xyo-network/sentinel-model'\n\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper.ts'\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 if (automations) for (const automation of automations) forget(this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n // eslint-disable-next-line unicorn/no-array-reduce\n return Object.values(this._automations).reduce<SentinelAutomationPayload | undefined>((previous, current) => {\n if (isSentinelIntervalAutomation(current) && isSentinelIntervalAutomation(previous)) {\n return current.start < (previous?.start ?? Number.POSITIVE_INFINITY) ? current : previous\n }\n return current\n // eslint-disable-next-line unicorn/no-useless-undefined\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadBuilder.dataHash(automation)\n this._automations[hash] = automation\n if (restart) this.restart()\n return hash\n }\n\n find(hash: string) {\n return Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n restart() {\n this.stop()\n this.start()\n }\n\n start() {\n assertEx(this.timeoutId === undefined, () => 'Already started')\n const automation = this.next\n if (isSentinelIntervalAutomation(automation)) {\n const now = Date.now()\n const start = Math.max(automation.start ?? now, now)\n const delay = Math.max(start - now, 0)\n if (delay < Number.POSITIVE_INFINITY) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.timeoutId = setTimeout(async () => {\n try {\n // Run the automation\n await this.trigger(automation)\n this.stop()\n } finally {\n // No matter what start the next automation\n this.start()\n }\n }, delay)\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.dataHash(), 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 { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport type { SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model'\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 Number.POSITIVE_INFINITY\n const frequencyUnits = this.payload.frequencyUnits\n switch (frequencyUnits ?? 'hour') {\n case 'second': {\n return frequency * 1000\n }\n case 'minute': {\n return frequency * 60 * 1000\n }\n case 'hour': {\n return frequency * 60 * 60 * 1000\n }\n case 'day': {\n return frequency * 24 * 60 * 60 * 1000\n }\n default: {\n return Number.POSITIVE_INFINITY\n }\n }\n }\n\n protected get remaining() {\n return this.payload.remaining ?? Number.POSITIVE_INFINITY\n }\n\n next() {\n const now = Date.now()\n const previousStart = this.payload?.start ?? now\n const start = Math.max(previousStart, now)\n const nextStart = start + this.frequencyMillis\n this.setStart(nextStart)\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload.start > (this.payload.end ?? Number.POSITIVE_INFINITY)) {\n this.setStart(Number.POSITIVE_INFINITY)\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = Math.max(this.remaining - count, 0)\n this.setRemaining(remaining)\n if (remaining <= 0) this.setStart(Number.POSITIVE_INFINITY)\n }\n\n /**\n * Sets the remaining of the wrapped automation\n * @param remaining The remaining time in milliseconds\n */\n protected setRemaining(remaining: number) {\n this.payload.remaining = remaining\n }\n\n /**\n * Sets the start of the wrapped automation\n * @param start The start time in milliseconds\n */\n protected setStart(start: number) {\n this.payload.start = start\n }\n}\n"],"mappings":";AACA,SAAS,WAAW,gBAAgB;AACpC,SAAS,yBAAyB;AAGlC,SAAS,wBAAwB;AAQjC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;;;ACjBlC,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAO/B,SAAS,oCAAoC;;;ACT7C,SAAS,sBAAsB;AAGxB,IAAM,oCAAN,cAEG,eAAkB;AAAA,EAC1B,YAAY,SAAY;AACtB,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAc,kBAAkB;AAC9B,UAAM,YAAY,KAA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AChC,CAAC;AACD,WAAO;AAAA,EACT;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/sentinel-memory",
3
- "version": "3.6.9",
3
+ "version": "3.6.11",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -29,31 +29,31 @@
29
29
  "module": "dist/neutral/index.mjs",
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "dependencies": {
32
- "@xylabs/assert": "^4.4.34",
33
- "@xylabs/forget": "^4.4.34",
34
- "@xylabs/hex": "^4.4.34",
35
- "@xylabs/promise": "^4.4.34",
36
- "@xyo-network/diviner-model": "^3.6.9",
37
- "@xyo-network/module-model": "^3.6.9",
38
- "@xyo-network/payload-builder": "^3.6.9",
39
- "@xyo-network/payload-model": "^3.6.9",
40
- "@xyo-network/payload-wrapper": "^3.6.9",
41
- "@xyo-network/sentinel-abstract": "^3.6.9",
42
- "@xyo-network/sentinel-model": "^3.6.9",
43
- "@xyo-network/witness-model": "^3.6.9"
32
+ "@xylabs/assert": "^4.5.1",
33
+ "@xylabs/forget": "^4.5.1",
34
+ "@xylabs/hex": "^4.5.1",
35
+ "@xylabs/promise": "^4.5.1",
36
+ "@xyo-network/diviner-model": "^3.6.11",
37
+ "@xyo-network/module-model": "^3.6.11",
38
+ "@xyo-network/payload-builder": "^3.6.11",
39
+ "@xyo-network/payload-model": "^3.6.11",
40
+ "@xyo-network/payload-wrapper": "^3.6.11",
41
+ "@xyo-network/sentinel-abstract": "^3.6.11",
42
+ "@xyo-network/sentinel-model": "^3.6.11",
43
+ "@xyo-network/witness-model": "^3.6.11"
44
44
  },
45
45
  "devDependencies": {
46
- "@xylabs/delay": "^4.4.34",
46
+ "@xylabs/delay": "^4.5.1",
47
47
  "@xylabs/ts-scripts-yarn3": "^4.2.6",
48
48
  "@xylabs/tsconfig": "^4.2.6",
49
- "@xylabs/vitest-extended": "^4.4.34",
50
- "@xyo-network/abstract-witness": "^3.6.9",
51
- "@xyo-network/archivist-memory": "^3.6.9",
52
- "@xyo-network/id-payload-plugin": "^3.6.9",
53
- "@xyo-network/node-memory": "^3.6.9",
54
- "@xyo-network/witness-adhoc": "^3.6.9",
55
- "typescript": "^5.7.2",
56
- "vitest": "^2.1.8"
49
+ "@xylabs/vitest-extended": "^4.5.1",
50
+ "@xyo-network/abstract-witness": "^3.6.11",
51
+ "@xyo-network/archivist-memory": "^3.6.11",
52
+ "@xyo-network/id-payload-plugin": "^3.6.11",
53
+ "@xyo-network/node-memory": "^3.6.11",
54
+ "@xyo-network/witness-adhoc": "^3.6.11",
55
+ "typescript": "^5.7.3",
56
+ "vitest": "^3.0.4"
57
57
  },
58
58
  "publishConfig": {
59
59
  "access": "public"