@xyo-network/sentinel-memory 2.85.5

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 (64) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/browser/MemorySentinel.d.cts +16 -0
  4. package/dist/browser/MemorySentinel.d.cts.map +1 -0
  5. package/dist/browser/MemorySentinel.d.mts +16 -0
  6. package/dist/browser/MemorySentinel.d.mts.map +1 -0
  7. package/dist/browser/MemorySentinel.d.ts +16 -0
  8. package/dist/browser/MemorySentinel.d.ts.map +1 -0
  9. package/dist/browser/SentinelIntervalAutomationWrapper.d.cts +21 -0
  10. package/dist/browser/SentinelIntervalAutomationWrapper.d.cts.map +1 -0
  11. package/dist/browser/SentinelIntervalAutomationWrapper.d.mts +21 -0
  12. package/dist/browser/SentinelIntervalAutomationWrapper.d.mts.map +1 -0
  13. package/dist/browser/SentinelIntervalAutomationWrapper.d.ts +21 -0
  14. package/dist/browser/SentinelIntervalAutomationWrapper.d.ts.map +1 -0
  15. package/dist/browser/SentinelRunner.d.cts +23 -0
  16. package/dist/browser/SentinelRunner.d.cts.map +1 -0
  17. package/dist/browser/SentinelRunner.d.mts +23 -0
  18. package/dist/browser/SentinelRunner.d.mts.map +1 -0
  19. package/dist/browser/SentinelRunner.d.ts +23 -0
  20. package/dist/browser/SentinelRunner.d.ts.map +1 -0
  21. package/dist/browser/index.cjs +310 -0
  22. package/dist/browser/index.cjs.map +1 -0
  23. package/dist/browser/index.d.cts +2 -0
  24. package/dist/browser/index.d.cts.map +1 -0
  25. package/dist/browser/index.d.mts +2 -0
  26. package/dist/browser/index.d.mts.map +1 -0
  27. package/dist/browser/index.d.ts +2 -0
  28. package/dist/browser/index.d.ts.map +1 -0
  29. package/dist/browser/index.js +289 -0
  30. package/dist/browser/index.js.map +1 -0
  31. package/dist/node/MemorySentinel.d.cts +16 -0
  32. package/dist/node/MemorySentinel.d.cts.map +1 -0
  33. package/dist/node/MemorySentinel.d.mts +16 -0
  34. package/dist/node/MemorySentinel.d.mts.map +1 -0
  35. package/dist/node/MemorySentinel.d.ts +16 -0
  36. package/dist/node/MemorySentinel.d.ts.map +1 -0
  37. package/dist/node/SentinelIntervalAutomationWrapper.d.cts +21 -0
  38. package/dist/node/SentinelIntervalAutomationWrapper.d.cts.map +1 -0
  39. package/dist/node/SentinelIntervalAutomationWrapper.d.mts +21 -0
  40. package/dist/node/SentinelIntervalAutomationWrapper.d.mts.map +1 -0
  41. package/dist/node/SentinelIntervalAutomationWrapper.d.ts +21 -0
  42. package/dist/node/SentinelIntervalAutomationWrapper.d.ts.map +1 -0
  43. package/dist/node/SentinelRunner.d.cts +23 -0
  44. package/dist/node/SentinelRunner.d.cts.map +1 -0
  45. package/dist/node/SentinelRunner.d.mts +23 -0
  46. package/dist/node/SentinelRunner.d.mts.map +1 -0
  47. package/dist/node/SentinelRunner.d.ts +23 -0
  48. package/dist/node/SentinelRunner.d.ts.map +1 -0
  49. package/dist/node/index.cjs +322 -0
  50. package/dist/node/index.cjs.map +1 -0
  51. package/dist/node/index.d.cts +2 -0
  52. package/dist/node/index.d.cts.map +1 -0
  53. package/dist/node/index.d.mts +2 -0
  54. package/dist/node/index.d.mts.map +1 -0
  55. package/dist/node/index.d.ts +2 -0
  56. package/dist/node/index.d.ts.map +1 -0
  57. package/dist/node/index.js +297 -0
  58. package/dist/node/index.js.map +1 -0
  59. package/package.json +77 -0
  60. package/src/MemorySentinel.ts +128 -0
  61. package/src/SentinelIntervalAutomationWrapper.ts +76 -0
  62. package/src/SentinelRunner.ts +114 -0
  63. package/src/index.ts +1 -0
  64. package/typedoc.json +5 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/MemorySentinel.ts","../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["import { Address } from '@xylabs/hex'\nimport { fulfilled, rejected } from '@xylabs/promise'\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 asSentinelInstance,\n ResolvedTask,\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 { SentinelRunner } from './SentinelRunner'\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 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.generateResults(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 await 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 generateResults(\n tasks: ResolvedTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n this.logger?.debug(`generateResults:tasks: ${JSON.stringify(tasks.length)}`)\n this.logger?.debug(`generateResults:previous: ${JSON.stringify(previousResults)}`)\n this.logger?.debug(`generateResults: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 ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n const witness = asWitnessInstance(task.module)\n if (witness) {\n const observed = await witness.observe(inPayloadsFound)\n this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`)\n return [witness.address, observed]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n const divined = await diviner.divine(inPayloadsFound)\n this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`)\n return [diviner.address, divined]\n }\n const sentinel = asSentinelInstance(task.module)\n if (sentinel) {\n const reported = await sentinel.report(inPayloadsFound)\n this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`)\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 return finalResult\n }\n\n private async inputAddresses(input: string | string[]): Promise<string[]> {\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","import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport {\n isSentinelIntervalAutomation,\n SentinelAutomationPayload,\n SentinelInstance,\n SentinelIntervalAutomationPayload,\n} from '@xyo-network/sentinel-model'\n\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 if (automations) for (const automation of automations) 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 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 // NOTE: Keep async to match module start signature\n await Promise.resolve()\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 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 await 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.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.jsonPayload(), 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 { 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.jsonPayload().frequency\n if (frequency === undefined) return Number.POSITIVE_INFINITY\n const frequencyUnits = this.jsonPayload().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.jsonPayload().remaining ?? Number.POSITIVE_INFINITY\n }\n\n next() {\n const now = Date.now()\n const previousStart = this.jsonPayload()?.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.jsonPayload().start > (this.jsonPayload().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.obj.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.obj.start = start\n }\n}\n"],"mappings":";;;;AACA,SAASA,WAAWC,gBAAgB;AACpC,SAASC,yBAAyB;AAGlC,SAASC,wBAAwB;AACjC,SACEC,oBAGAC,4BAIK;AACP,SAASC,yBAAyB;;;ACflC,SAASC,gBAAgB;AAEzB,SAASC,kBAAAA,uBAAsB;AAC/B,SACEC,oCAIK;;;ACRP,SAASC,sBAAsB;AAGxB,IAAMC,oCAAN,cAEGC,eAAAA;EALV,OAKUA;;;EACRC,YAAYC,SAAY;AACtB,UAAMA,OAAAA;EACR;EAEA,IAAcC,kBAAkB;AAC9B,UAAMC,YAAY,KAAKC,YAAW,EAAGD;AACrC,QAAIA,cAAcE;AAAW,aAAOC,OAAOC;AAC3C,UAAMC,iBAAiB,KAAKJ,YAAW,EAAGI;AAC1C,YAAQA,kBAAkB,QAAA;MACxB,KAAK,UAAU;AACb,eAAOL,YAAY;MACrB;MACA,KAAK,UAAU;AACb,eAAOA,YAAY,KAAK;MAC1B;MACA,KAAK,QAAQ;AACX,eAAOA,YAAY,KAAK,KAAK;MAC/B;MACA,KAAK,OAAO;AACV,eAAOA,YAAY,KAAK,KAAK,KAAK;MACpC;MACA,SAAS;AACP,eAAOG,OAAOC;MAChB;IACF;EACF;EAEA,IAAcE,YAAY;AACxB,WAAO,KAAKL,YAAW,EAAGK,aAAaH,OAAOC;EAChD;EAEAG,OAAO;AACL,UAAM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,CAAA,CAAE;EACxD;AACF;","names":["fulfilled","rejected","asDivinerInstance","AbstractSentinel","asSentinelInstance","SentinelConfigSchema","asWitnessInstance","assertEx","PayloadWrapper","isSentinelIntervalAutomation","PayloadWrapper","SentinelIntervalAutomationWrapper","PayloadWrapper","constructor","payload","frequencyMillis","frequency","jsonPayload","undefined","Number","POSITIVE_INFINITY","frequencyUnits","remaining","next","now","Date","previousStart","start","Math","max","nextStart","setStart","consumeRemaining","checkEnd","end","count","setRemaining","obj","SentinelRunner","_automations","onTriggerResult","sentinel","timeoutId","constructor","automations","automation","add","next","Object","values","reduce","previous","current","isSentinelIntervalAutomation","start","Number","POSITIVE_INFINITY","undefined","restart","hash","PayloadWrapper","hashAsync","find","entries","key","remove","removeAll","stop","Promise","resolve","assertEx","now","Date","Math","max","delay","setTimeout","trigger","clearTimeout","update","wrapper","SentinelIntervalAutomationWrapper","jsonPayload","triggerResult","report","MemorySentinel","AbstractSentinel","configSchemas","SentinelConfigSchema","runner","reportHandler","inPayloads","started","logger","debug","JSON","stringify","job","jobPromise","index","previousResults","tasks","length","generatedPayloads","generateResults","result","Object","values","flat","start","timeout","config","automations","SentinelRunner","stop","undefined","results","Promise","allSettled","map","task","input","inPayloadsFound","processPreviousResults","inputAddresses","witness","asWitnessInstance","module","observed","observe","id","address","diviner","asDivinerInstance","divined","divine","sentinel","asSentinelInstance","reported","report","Error","finalResult","filter","fulfilled","payloads","value","push","throwErrors","errors","rejected","reason","Array","isArray","all","inputItem","resolved","resolve","inputs","flatMap"]}
@@ -0,0 +1,16 @@
1
+ import { AnyConfigSchema } from '@xyo-network/module-model';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ import { AbstractSentinel } from '@xyo-network/sentinel-abstract';
4
+ import { SentinelConfig, SentinelInstance, SentinelModuleEventData, SentinelParams } from '@xyo-network/sentinel-model';
5
+ export type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>;
6
+ export declare class MemorySentinel<TParams extends MemorySentinelParams = MemorySentinelParams, TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>> extends AbstractSentinel<TParams, TEventData> {
7
+ static configSchemas: string[];
8
+ private runner?;
9
+ reportHandler(inPayloads?: Payload[]): Promise<Payload[]>;
10
+ start(timeout?: number | undefined): Promise<boolean>;
11
+ stop(timeout?: number | undefined): Promise<boolean>;
12
+ private generateResults;
13
+ private inputAddresses;
14
+ private processPreviousResults;
15
+ }
16
+ //# sourceMappingURL=MemorySentinel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemorySentinel.d.ts","sourceRoot":"","sources":["../../src/MemorySentinel.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAGL,cAAc,EAEd,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACf,MAAM,6BAA6B,CAAA;AAKpC,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,eAAe,CAAC,cAAc,CAAC,GAAG,eAAe,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC,OAAO,CAAC,CAAA;AAE7I,qBAAa,cAAc,CACzB,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,EAC3D,UAAU,SAAS,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAC1H,SAAQ,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7C,OAAgB,aAAa,WAAyB;IAEtD,OAAO,CAAC,MAAM,CAAC,CAAgB;IAEzB,aAAa,CAAC,UAAU,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAiBpD,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAWrD,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;YAQrD,eAAe;YAkDf,cAAc;IAS5B,OAAO,CAAC,sBAAsB;CAG/B"}
@@ -0,0 +1,16 @@
1
+ import { AnyConfigSchema } from '@xyo-network/module-model';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ import { AbstractSentinel } from '@xyo-network/sentinel-abstract';
4
+ import { SentinelConfig, SentinelInstance, SentinelModuleEventData, SentinelParams } from '@xyo-network/sentinel-model';
5
+ export type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>;
6
+ export declare class MemorySentinel<TParams extends MemorySentinelParams = MemorySentinelParams, TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>> extends AbstractSentinel<TParams, TEventData> {
7
+ static configSchemas: string[];
8
+ private runner?;
9
+ reportHandler(inPayloads?: Payload[]): Promise<Payload[]>;
10
+ start(timeout?: number | undefined): Promise<boolean>;
11
+ stop(timeout?: number | undefined): Promise<boolean>;
12
+ private generateResults;
13
+ private inputAddresses;
14
+ private processPreviousResults;
15
+ }
16
+ //# sourceMappingURL=MemorySentinel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemorySentinel.d.ts","sourceRoot":"","sources":["../../src/MemorySentinel.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAGL,cAAc,EAEd,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACf,MAAM,6BAA6B,CAAA;AAKpC,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,eAAe,CAAC,cAAc,CAAC,GAAG,eAAe,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC,OAAO,CAAC,CAAA;AAE7I,qBAAa,cAAc,CACzB,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,EAC3D,UAAU,SAAS,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAC1H,SAAQ,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7C,OAAgB,aAAa,WAAyB;IAEtD,OAAO,CAAC,MAAM,CAAC,CAAgB;IAEzB,aAAa,CAAC,UAAU,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAiBpD,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAWrD,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;YAQrD,eAAe;YAkDf,cAAc;IAS5B,OAAO,CAAC,sBAAsB;CAG/B"}
@@ -0,0 +1,16 @@
1
+ import { AnyConfigSchema } from '@xyo-network/module-model';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ import { AbstractSentinel } from '@xyo-network/sentinel-abstract';
4
+ import { SentinelConfig, SentinelInstance, SentinelModuleEventData, SentinelParams } from '@xyo-network/sentinel-model';
5
+ export type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>;
6
+ export declare class MemorySentinel<TParams extends MemorySentinelParams = MemorySentinelParams, TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>> extends AbstractSentinel<TParams, TEventData> {
7
+ static configSchemas: string[];
8
+ private runner?;
9
+ reportHandler(inPayloads?: Payload[]): Promise<Payload[]>;
10
+ start(timeout?: number | undefined): Promise<boolean>;
11
+ stop(timeout?: number | undefined): Promise<boolean>;
12
+ private generateResults;
13
+ private inputAddresses;
14
+ private processPreviousResults;
15
+ }
16
+ //# sourceMappingURL=MemorySentinel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemorySentinel.d.ts","sourceRoot":"","sources":["../../src/MemorySentinel.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAGL,cAAc,EAEd,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACf,MAAM,6BAA6B,CAAA;AAKpC,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,eAAe,CAAC,cAAc,CAAC,GAAG,eAAe,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC,OAAO,CAAC,CAAA;AAE7I,qBAAa,cAAc,CACzB,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,EAC3D,UAAU,SAAS,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAC1H,SAAQ,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7C,OAAgB,aAAa,WAAyB;IAEtD,OAAO,CAAC,MAAM,CAAC,CAAgB;IAEzB,aAAa,CAAC,UAAU,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAiBpD,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAWrD,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;YAQrD,eAAe;YAkDf,cAAc;IAS5B,OAAO,CAAC,sBAAsB;CAG/B"}
@@ -0,0 +1,21 @@
1
+ import { PayloadWrapper } from '@xyo-network/payload-wrapper';
2
+ import { SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model';
3
+ export declare class SentinelIntervalAutomationWrapper<T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload> extends PayloadWrapper<T> {
4
+ constructor(payload: T);
5
+ protected get frequencyMillis(): number;
6
+ protected get remaining(): number;
7
+ next(): this;
8
+ protected checkEnd(): void;
9
+ protected consumeRemaining(count?: number): void;
10
+ /**
11
+ * Sets the remaining of the wrapped automation
12
+ * @param remaining The remaining time in milliseconds
13
+ */
14
+ protected setRemaining(remaining: number): void;
15
+ /**
16
+ * Sets the start of the wrapped automation
17
+ * @param start The start time in milliseconds
18
+ */
19
+ protected setStart(start: number): void;
20
+ }
21
+ //# sourceMappingURL=SentinelIntervalAutomationWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SentinelIntervalAutomationWrapper.d.ts","sourceRoot":"","sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAA;AAE/E,qBAAa,iCAAiC,CAC5C,CAAC,SAAS,iCAAiC,GAAG,iCAAiC,CAC/E,SAAQ,cAAc,CAAC,CAAC,CAAC;gBACb,OAAO,EAAE,CAAC;IAItB,SAAS,KAAK,eAAe,WAqB5B;IAED,SAAS,KAAK,SAAS,WAEtB;IAED,IAAI;IAWJ,SAAS,CAAC,QAAQ;IAMlB,SAAS,CAAC,gBAAgB,CAAC,KAAK,SAAI;IAMpC;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM;IAIxC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;CAGjC"}
@@ -0,0 +1,21 @@
1
+ import { PayloadWrapper } from '@xyo-network/payload-wrapper';
2
+ import { SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model';
3
+ export declare class SentinelIntervalAutomationWrapper<T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload> extends PayloadWrapper<T> {
4
+ constructor(payload: T);
5
+ protected get frequencyMillis(): number;
6
+ protected get remaining(): number;
7
+ next(): this;
8
+ protected checkEnd(): void;
9
+ protected consumeRemaining(count?: number): void;
10
+ /**
11
+ * Sets the remaining of the wrapped automation
12
+ * @param remaining The remaining time in milliseconds
13
+ */
14
+ protected setRemaining(remaining: number): void;
15
+ /**
16
+ * Sets the start of the wrapped automation
17
+ * @param start The start time in milliseconds
18
+ */
19
+ protected setStart(start: number): void;
20
+ }
21
+ //# sourceMappingURL=SentinelIntervalAutomationWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SentinelIntervalAutomationWrapper.d.ts","sourceRoot":"","sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAA;AAE/E,qBAAa,iCAAiC,CAC5C,CAAC,SAAS,iCAAiC,GAAG,iCAAiC,CAC/E,SAAQ,cAAc,CAAC,CAAC,CAAC;gBACb,OAAO,EAAE,CAAC;IAItB,SAAS,KAAK,eAAe,WAqB5B;IAED,SAAS,KAAK,SAAS,WAEtB;IAED,IAAI;IAWJ,SAAS,CAAC,QAAQ;IAMlB,SAAS,CAAC,gBAAgB,CAAC,KAAK,SAAI;IAMpC;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM;IAIxC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;CAGjC"}
@@ -0,0 +1,21 @@
1
+ import { PayloadWrapper } from '@xyo-network/payload-wrapper';
2
+ import { SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model';
3
+ export declare class SentinelIntervalAutomationWrapper<T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload> extends PayloadWrapper<T> {
4
+ constructor(payload: T);
5
+ protected get frequencyMillis(): number;
6
+ protected get remaining(): number;
7
+ next(): this;
8
+ protected checkEnd(): void;
9
+ protected consumeRemaining(count?: number): void;
10
+ /**
11
+ * Sets the remaining of the wrapped automation
12
+ * @param remaining The remaining time in milliseconds
13
+ */
14
+ protected setRemaining(remaining: number): void;
15
+ /**
16
+ * Sets the start of the wrapped automation
17
+ * @param start The start time in milliseconds
18
+ */
19
+ protected setStart(start: number): void;
20
+ }
21
+ //# sourceMappingURL=SentinelIntervalAutomationWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SentinelIntervalAutomationWrapper.d.ts","sourceRoot":"","sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAA;AAE/E,qBAAa,iCAAiC,CAC5C,CAAC,SAAS,iCAAiC,GAAG,iCAAiC,CAC/E,SAAQ,cAAc,CAAC,CAAC,CAAC;gBACb,OAAO,EAAE,CAAC;IAItB,SAAS,KAAK,eAAe,WAqB5B;IAED,SAAS,KAAK,SAAS,WAEtB;IAED,IAAI;IAWJ,SAAS,CAAC,QAAQ;IAMlB,SAAS,CAAC,gBAAgB,CAAC,KAAK,SAAI;IAMpC;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM;IAIxC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;CAGjC"}
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ import { SentinelAutomationPayload, SentinelInstance } from '@xyo-network/sentinel-model';
4
+ export type OnSentinelRunnerTriggerResult = (result: Payload[]) => void;
5
+ export declare class SentinelRunner {
6
+ protected _automations: Record<string, SentinelAutomationPayload>;
7
+ protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined;
8
+ protected sentinel: SentinelInstance;
9
+ protected timeoutId?: NodeJS.Timeout | string | number;
10
+ constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult);
11
+ get automations(): Record<string, SentinelAutomationPayload>;
12
+ private get next();
13
+ add(automation: SentinelAutomationPayload, restart?: boolean): Promise<string>;
14
+ find(hash: string): void;
15
+ remove(hash: string, restart?: boolean): Promise<void>;
16
+ removeAll(): void;
17
+ restart(): Promise<void>;
18
+ start(): Promise<void>;
19
+ stop(): void;
20
+ update(hash: string, automation: SentinelAutomationPayload, restart?: boolean): Promise<void>;
21
+ private trigger;
22
+ }
23
+ //# sourceMappingURL=SentinelRunner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAEL,yBAAyB,EACzB,gBAAgB,EAEjB,MAAM,6BAA6B,CAAA;AAIpC,MAAM,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEvE,qBAAa,cAAc;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAK;IACtE,SAAS,CAAC,eAAe,EAAE,6BAA6B,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACpC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;gBAE1C,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,yBAAyB,EAAE,EAAE,eAAe,CAAC,EAAE,6BAA6B;IAMlI,IAAI,WAAW,8CAEd;IAED,OAAO,KAAK,IAAI,GASf;IAEK,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;IAO/D,IAAI,CAAC,IAAI,EAAE,MAAM;IAIX,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO;IAKzC,SAAS;IAKH,OAAO;IAKP,KAAK;IAwBX,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ import { SentinelAutomationPayload, SentinelInstance } from '@xyo-network/sentinel-model';
4
+ export type OnSentinelRunnerTriggerResult = (result: Payload[]) => void;
5
+ export declare class SentinelRunner {
6
+ protected _automations: Record<string, SentinelAutomationPayload>;
7
+ protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined;
8
+ protected sentinel: SentinelInstance;
9
+ protected timeoutId?: NodeJS.Timeout | string | number;
10
+ constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult);
11
+ get automations(): Record<string, SentinelAutomationPayload>;
12
+ private get next();
13
+ add(automation: SentinelAutomationPayload, restart?: boolean): Promise<string>;
14
+ find(hash: string): void;
15
+ remove(hash: string, restart?: boolean): Promise<void>;
16
+ removeAll(): void;
17
+ restart(): Promise<void>;
18
+ start(): Promise<void>;
19
+ stop(): void;
20
+ update(hash: string, automation: SentinelAutomationPayload, restart?: boolean): Promise<void>;
21
+ private trigger;
22
+ }
23
+ //# sourceMappingURL=SentinelRunner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAEL,yBAAyB,EACzB,gBAAgB,EAEjB,MAAM,6BAA6B,CAAA;AAIpC,MAAM,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEvE,qBAAa,cAAc;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAK;IACtE,SAAS,CAAC,eAAe,EAAE,6BAA6B,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACpC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;gBAE1C,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,yBAAyB,EAAE,EAAE,eAAe,CAAC,EAAE,6BAA6B;IAMlI,IAAI,WAAW,8CAEd;IAED,OAAO,KAAK,IAAI,GASf;IAEK,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;IAO/D,IAAI,CAAC,IAAI,EAAE,MAAM;IAIX,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO;IAKzC,SAAS;IAKH,OAAO;IAKP,KAAK;IAwBX,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ import { SentinelAutomationPayload, SentinelInstance } from '@xyo-network/sentinel-model';
4
+ export type OnSentinelRunnerTriggerResult = (result: Payload[]) => void;
5
+ export declare class SentinelRunner {
6
+ protected _automations: Record<string, SentinelAutomationPayload>;
7
+ protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined;
8
+ protected sentinel: SentinelInstance;
9
+ protected timeoutId?: NodeJS.Timeout | string | number;
10
+ constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult);
11
+ get automations(): Record<string, SentinelAutomationPayload>;
12
+ private get next();
13
+ add(automation: SentinelAutomationPayload, restart?: boolean): Promise<string>;
14
+ find(hash: string): void;
15
+ remove(hash: string, restart?: boolean): Promise<void>;
16
+ removeAll(): void;
17
+ restart(): Promise<void>;
18
+ start(): Promise<void>;
19
+ stop(): void;
20
+ update(hash: string, automation: SentinelAutomationPayload, restart?: boolean): Promise<void>;
21
+ private trigger;
22
+ }
23
+ //# sourceMappingURL=SentinelRunner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAEL,yBAAyB,EACzB,gBAAgB,EAEjB,MAAM,6BAA6B,CAAA;AAIpC,MAAM,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEvE,qBAAa,cAAc;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAK;IACtE,SAAS,CAAC,eAAe,EAAE,6BAA6B,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACpC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;gBAE1C,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,yBAAyB,EAAE,EAAE,eAAe,CAAC,EAAE,6BAA6B;IAMlI,IAAI,WAAW,8CAEd;IAED,OAAO,KAAK,IAAI,GASf;IAEK,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;IAO/D,IAAI,CAAC,IAAI,EAAE,MAAM;IAIX,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO;IAKzC,SAAS;IAKH,OAAO;IAKP,KAAK;IAwBX,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
@@ -0,0 +1,322 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var __publicField = (obj, key, value) => {
22
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
23
+ return value;
24
+ };
25
+
26
+ // src/index.ts
27
+ var src_exports = {};
28
+ __export(src_exports, {
29
+ MemorySentinel: () => MemorySentinel
30
+ });
31
+ module.exports = __toCommonJS(src_exports);
32
+
33
+ // src/MemorySentinel.ts
34
+ var import_promise = require("@xylabs/promise");
35
+ var import_diviner_model = require("@xyo-network/diviner-model");
36
+ var import_sentinel_abstract = require("@xyo-network/sentinel-abstract");
37
+ var import_sentinel_model2 = require("@xyo-network/sentinel-model");
38
+ var import_witness_model = require("@xyo-network/witness-model");
39
+
40
+ // src/SentinelRunner.ts
41
+ var import_assert = require("@xylabs/assert");
42
+ var import_payload_wrapper2 = require("@xyo-network/payload-wrapper");
43
+ var import_sentinel_model = require("@xyo-network/sentinel-model");
44
+
45
+ // src/SentinelIntervalAutomationWrapper.ts
46
+ var import_payload_wrapper = require("@xyo-network/payload-wrapper");
47
+ var _SentinelIntervalAutomationWrapper = class _SentinelIntervalAutomationWrapper extends import_payload_wrapper.PayloadWrapper {
48
+ constructor(payload) {
49
+ super(payload);
50
+ }
51
+ get frequencyMillis() {
52
+ const frequency = this.jsonPayload().frequency;
53
+ if (frequency === void 0)
54
+ return Number.POSITIVE_INFINITY;
55
+ const frequencyUnits = this.jsonPayload().frequencyUnits;
56
+ switch (frequencyUnits ?? "hour") {
57
+ case "second": {
58
+ return frequency * 1e3;
59
+ }
60
+ case "minute": {
61
+ return frequency * 60 * 1e3;
62
+ }
63
+ case "hour": {
64
+ return frequency * 60 * 60 * 1e3;
65
+ }
66
+ case "day": {
67
+ return frequency * 24 * 60 * 60 * 1e3;
68
+ }
69
+ default: {
70
+ return Number.POSITIVE_INFINITY;
71
+ }
72
+ }
73
+ }
74
+ get remaining() {
75
+ return this.jsonPayload().remaining ?? Number.POSITIVE_INFINITY;
76
+ }
77
+ next() {
78
+ var _a;
79
+ const now = Date.now();
80
+ const previousStart = ((_a = this.jsonPayload()) == null ? void 0 : _a.start) ?? now;
81
+ const start = Math.max(previousStart, now);
82
+ const nextStart = start + this.frequencyMillis;
83
+ this.setStart(nextStart);
84
+ this.consumeRemaining();
85
+ this.checkEnd();
86
+ return this;
87
+ }
88
+ checkEnd() {
89
+ if (this.jsonPayload().start > (this.jsonPayload().end ?? Number.POSITIVE_INFINITY)) {
90
+ this.setStart(Number.POSITIVE_INFINITY);
91
+ }
92
+ }
93
+ consumeRemaining(count = 1) {
94
+ const remaining = Math.max(this.remaining - count, 0);
95
+ this.setRemaining(remaining);
96
+ if (remaining <= 0)
97
+ this.setStart(Number.POSITIVE_INFINITY);
98
+ }
99
+ /**
100
+ * Sets the remaining of the wrapped automation
101
+ * @param remaining The remaining time in milliseconds
102
+ */
103
+ setRemaining(remaining) {
104
+ this.obj.remaining = remaining;
105
+ }
106
+ /**
107
+ * Sets the start of the wrapped automation
108
+ * @param start The start time in milliseconds
109
+ */
110
+ setStart(start) {
111
+ this.obj.start = start;
112
+ }
113
+ };
114
+ __name(_SentinelIntervalAutomationWrapper, "SentinelIntervalAutomationWrapper");
115
+ var SentinelIntervalAutomationWrapper = _SentinelIntervalAutomationWrapper;
116
+
117
+ // src/SentinelRunner.ts
118
+ var _SentinelRunner = class _SentinelRunner {
119
+ _automations = {};
120
+ onTriggerResult;
121
+ sentinel;
122
+ timeoutId;
123
+ constructor(sentinel, automations, onTriggerResult) {
124
+ this.sentinel = sentinel;
125
+ this.onTriggerResult = onTriggerResult;
126
+ if (automations)
127
+ for (const automation of automations)
128
+ this.add(automation);
129
+ }
130
+ get automations() {
131
+ return this._automations;
132
+ }
133
+ get next() {
134
+ return Object.values(this._automations).reduce((previous, current) => {
135
+ if ((0, import_sentinel_model.isSentinelIntervalAutomation)(current) && (0, import_sentinel_model.isSentinelIntervalAutomation)(previous)) {
136
+ return current.start < ((previous == null ? void 0 : previous.start) ?? Number.POSITIVE_INFINITY) ? current : previous;
137
+ }
138
+ return current;
139
+ }, void 0);
140
+ }
141
+ async add(automation, restart = true) {
142
+ const hash = await import_payload_wrapper2.PayloadWrapper.hashAsync(automation);
143
+ this._automations[hash] = automation;
144
+ if (restart)
145
+ await this.restart();
146
+ return hash;
147
+ }
148
+ find(hash) {
149
+ Object.entries(this._automations).find(([key]) => key === hash);
150
+ }
151
+ async remove(hash, restart = true) {
152
+ delete this._automations[hash];
153
+ if (restart)
154
+ await this.restart();
155
+ }
156
+ removeAll() {
157
+ this.stop();
158
+ this._automations = {};
159
+ }
160
+ async restart() {
161
+ this.stop();
162
+ await this.start();
163
+ }
164
+ async start() {
165
+ await Promise.resolve();
166
+ (0, import_assert.assertEx)(this.timeoutId === void 0, "Already started");
167
+ const automation = this.next;
168
+ if ((0, import_sentinel_model.isSentinelIntervalAutomation)(automation)) {
169
+ const now = Date.now();
170
+ const start = Math.max(automation.start ?? now, now);
171
+ const delay = Math.max(start - now, 0);
172
+ if (delay < Number.POSITIVE_INFINITY) {
173
+ this.timeoutId = setTimeout(async () => {
174
+ try {
175
+ await this.trigger(automation);
176
+ this.stop();
177
+ } finally {
178
+ await this.start();
179
+ }
180
+ }, delay);
181
+ }
182
+ }
183
+ }
184
+ stop() {
185
+ if (this.timeoutId) {
186
+ clearTimeout(this.timeoutId);
187
+ this.timeoutId = void 0;
188
+ }
189
+ }
190
+ async update(hash, automation, restart = true) {
191
+ await this.remove(hash, false);
192
+ await this.add(automation, false);
193
+ if (restart)
194
+ await this.restart();
195
+ }
196
+ async trigger(automation) {
197
+ var _a;
198
+ const wrapper = new SentinelIntervalAutomationWrapper(automation);
199
+ await this.remove(await wrapper.hashAsync(), false);
200
+ wrapper.next();
201
+ await this.add(wrapper.jsonPayload(), false);
202
+ const triggerResult = await this.sentinel.report();
203
+ (_a = this.onTriggerResult) == null ? void 0 : _a.call(this, triggerResult);
204
+ }
205
+ };
206
+ __name(_SentinelRunner, "SentinelRunner");
207
+ var SentinelRunner = _SentinelRunner;
208
+
209
+ // src/MemorySentinel.ts
210
+ var _MemorySentinel = class _MemorySentinel extends import_sentinel_abstract.AbstractSentinel {
211
+ runner;
212
+ async reportHandler(inPayloads = []) {
213
+ var _a, _b;
214
+ await this.started("throw");
215
+ (_a = this.logger) == null ? void 0 : _a.debug(`reportHandler:in: ${JSON.stringify(inPayloads)}`);
216
+ const job = await this.jobPromise;
217
+ let index = 0;
218
+ let previousResults = {};
219
+ while (index < job.tasks.length) {
220
+ const generatedPayloads = await this.generateResults(job.tasks[index], previousResults, inPayloads);
221
+ previousResults = generatedPayloads;
222
+ index++;
223
+ }
224
+ const result = Object.values(previousResults).flat();
225
+ (_b = this.logger) == null ? void 0 : _b.debug(`reportHandler:out: ${JSON.stringify(result)}`);
226
+ return result;
227
+ }
228
+ async start(timeout) {
229
+ var _a;
230
+ if (await super.start(timeout)) {
231
+ if ((((_a = this.config.automations) == null ? void 0 : _a.length) ?? 0) > 0) {
232
+ this.runner = new SentinelRunner(this, this.config.automations);
233
+ await this.runner.start();
234
+ }
235
+ return true;
236
+ }
237
+ return false;
238
+ }
239
+ async stop(timeout) {
240
+ if (this.runner) {
241
+ this.runner.stop();
242
+ this.runner = void 0;
243
+ }
244
+ return await super.stop(timeout);
245
+ }
246
+ async generateResults(tasks, previousResults, inPayloads) {
247
+ var _a, _b, _c, _d;
248
+ (_a = this.logger) == null ? void 0 : _a.debug(`generateResults:tasks: ${JSON.stringify(tasks.length)}`);
249
+ (_b = this.logger) == null ? void 0 : _b.debug(`generateResults:previous: ${JSON.stringify(previousResults)}`);
250
+ (_c = this.logger) == null ? void 0 : _c.debug(`generateResults:in: ${JSON.stringify(inPayloads)}`);
251
+ const results = await Promise.allSettled(tasks == null ? void 0 : tasks.map(async (task) => {
252
+ var _a2, _b2, _c2;
253
+ const input = task.input ?? false;
254
+ const inPayloadsFound = input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input));
255
+ const witness = (0, import_witness_model.asWitnessInstance)(task.module);
256
+ if (witness) {
257
+ const observed = await witness.observe(inPayloadsFound);
258
+ (_a2 = this.logger) == null ? void 0 : _a2.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`);
259
+ return [
260
+ witness.address,
261
+ observed
262
+ ];
263
+ }
264
+ const diviner = (0, import_diviner_model.asDivinerInstance)(task.module);
265
+ if (diviner) {
266
+ const divined = await diviner.divine(inPayloadsFound);
267
+ (_b2 = this.logger) == null ? void 0 : _b2.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`);
268
+ return [
269
+ diviner.address,
270
+ divined
271
+ ];
272
+ }
273
+ const sentinel = (0, import_sentinel_model2.asSentinelInstance)(task.module);
274
+ if (sentinel) {
275
+ const reported = await sentinel.report(inPayloadsFound);
276
+ (_c2 = this.logger) == null ? void 0 : _c2.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`);
277
+ return [
278
+ sentinel.address,
279
+ reported
280
+ ];
281
+ }
282
+ throw new Error("Unsupported module type");
283
+ }));
284
+ const finalResult = {};
285
+ for (const result of results.filter(import_promise.fulfilled)) {
286
+ const [address, payloads] = result.value;
287
+ finalResult[address] = finalResult[address] ?? [];
288
+ finalResult[address].push(...payloads);
289
+ }
290
+ if (this.throwErrors) {
291
+ const errors = results.filter(import_promise.rejected).map((result) => result.reason);
292
+ if (errors.length > 0) {
293
+ throw new Error("At least one module failed");
294
+ }
295
+ }
296
+ (_d = this.logger) == null ? void 0 : _d.debug(`generateResults:out: ${JSON.stringify(finalResult)}`);
297
+ return finalResult;
298
+ }
299
+ async inputAddresses(input) {
300
+ if (Array.isArray(input)) {
301
+ return (await Promise.all(input.map(async (inputItem) => await this.inputAddresses(inputItem)))).flat();
302
+ } else {
303
+ const resolved = await this.resolve(input);
304
+ return resolved ? [
305
+ resolved.address
306
+ ] : [];
307
+ }
308
+ }
309
+ processPreviousResults(payloads, inputs) {
310
+ return inputs.flatMap((input) => payloads[input] ?? []);
311
+ }
312
+ };
313
+ __name(_MemorySentinel, "MemorySentinel");
314
+ __publicField(_MemorySentinel, "configSchemas", [
315
+ import_sentinel_model2.SentinelConfigSchema
316
+ ]);
317
+ var MemorySentinel = _MemorySentinel;
318
+ // Annotate the CommonJS export names for ESM import in node:
319
+ 0 && (module.exports = {
320
+ MemorySentinel
321
+ });
322
+ //# sourceMappingURL=index.cjs.map