@xyo-network/sentinel 2.74.4 → 2.75.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 (130) hide show
  1. package/dist/browser/AbstractSentinel.cjs +113 -0
  2. package/dist/browser/AbstractSentinel.cjs.map +1 -0
  3. package/dist/browser/AbstractSentinel.d.mts.map +1 -0
  4. package/dist/browser/AbstractSentinel.d.ts.map +1 -0
  5. package/dist/browser/AbstractSentinel.js +94 -0
  6. package/dist/browser/AbstractSentinel.js.map +1 -0
  7. package/dist/browser/Automation.cjs +27 -0
  8. package/dist/browser/Automation.cjs.map +1 -0
  9. package/dist/browser/Automation.d.mts.map +1 -0
  10. package/dist/browser/Automation.d.ts.map +1 -0
  11. package/dist/browser/Automation.js +6 -0
  12. package/dist/browser/Automation.js.map +1 -0
  13. package/dist/browser/MemorySentinel.cjs +149 -0
  14. package/dist/browser/MemorySentinel.cjs.map +1 -0
  15. package/dist/browser/MemorySentinel.d.mts.map +1 -0
  16. package/dist/browser/MemorySentinel.d.ts.map +1 -0
  17. package/dist/browser/MemorySentinel.js +133 -0
  18. package/dist/browser/MemorySentinel.js.map +1 -0
  19. package/dist/browser/SentinelIntervalAutomationWrapper.cjs +68 -0
  20. package/dist/browser/SentinelIntervalAutomationWrapper.cjs.map +1 -0
  21. package/dist/browser/SentinelIntervalAutomationWrapper.d.mts.map +1 -0
  22. package/dist/browser/SentinelIntervalAutomationWrapper.d.ts.map +1 -0
  23. package/dist/browser/SentinelIntervalAutomationWrapper.js +47 -0
  24. package/dist/browser/SentinelIntervalAutomationWrapper.js.map +1 -0
  25. package/dist/browser/SentinelRunner.cjs +157 -0
  26. package/dist/browser/SentinelRunner.cjs.map +1 -0
  27. package/dist/browser/SentinelRunner.d.mts.map +1 -0
  28. package/dist/browser/SentinelRunner.d.ts.map +1 -0
  29. package/dist/browser/SentinelRunner.js +136 -0
  30. package/dist/browser/SentinelRunner.js.map +1 -0
  31. package/dist/browser/Wrapper.cjs +45 -0
  32. package/dist/browser/Wrapper.cjs.map +1 -0
  33. package/dist/browser/Wrapper.d.mts.map +1 -0
  34. package/dist/browser/Wrapper.d.ts.map +1 -0
  35. package/dist/browser/Wrapper.js +28 -0
  36. package/dist/browser/Wrapper.js.map +1 -0
  37. package/dist/{index.js → browser/index.cjs} +1 -11
  38. package/dist/browser/index.cjs.map +1 -0
  39. package/dist/browser/index.d.mts.map +1 -0
  40. package/dist/browser/index.d.ts.map +1 -0
  41. package/dist/{index.mjs → browser/index.js} +1 -1
  42. package/dist/browser/index.js.map +1 -0
  43. package/dist/node/AbstractSentinel.d.mts +22 -0
  44. package/dist/node/AbstractSentinel.d.mts.map +1 -0
  45. package/dist/node/AbstractSentinel.d.ts +22 -0
  46. package/dist/node/AbstractSentinel.d.ts.map +1 -0
  47. package/dist/node/AbstractSentinel.js +115 -0
  48. package/dist/node/AbstractSentinel.js.map +1 -0
  49. package/dist/node/AbstractSentinel.mjs +93 -0
  50. package/dist/node/AbstractSentinel.mjs.map +1 -0
  51. package/dist/node/Automation.d.mts +28 -0
  52. package/dist/node/Automation.d.mts.map +1 -0
  53. package/dist/node/Automation.d.ts +28 -0
  54. package/dist/node/Automation.d.ts.map +1 -0
  55. package/dist/node/Automation.js +29 -0
  56. package/dist/node/Automation.js.map +1 -0
  57. package/dist/node/Automation.mjs +5 -0
  58. package/dist/node/Automation.mjs.map +1 -0
  59. package/dist/node/MemorySentinel.d.mts +10 -0
  60. package/dist/node/MemorySentinel.d.mts.map +1 -0
  61. package/dist/node/MemorySentinel.d.ts +10 -0
  62. package/dist/node/MemorySentinel.d.ts.map +1 -0
  63. package/dist/node/MemorySentinel.js +61 -0
  64. package/dist/node/MemorySentinel.js.map +1 -0
  65. package/dist/node/MemorySentinel.mjs +40 -0
  66. package/dist/node/MemorySentinel.mjs.map +1 -0
  67. package/dist/node/SentinelIntervalAutomationWrapper.d.mts +11 -0
  68. package/dist/node/SentinelIntervalAutomationWrapper.d.mts.map +1 -0
  69. package/dist/node/SentinelIntervalAutomationWrapper.d.ts +11 -0
  70. package/dist/node/SentinelIntervalAutomationWrapper.d.ts.map +1 -0
  71. package/dist/node/SentinelIntervalAutomationWrapper.js +70 -0
  72. package/dist/node/SentinelIntervalAutomationWrapper.js.map +1 -0
  73. package/dist/node/SentinelIntervalAutomationWrapper.mjs +46 -0
  74. package/dist/node/SentinelIntervalAutomationWrapper.mjs.map +1 -0
  75. package/dist/node/SentinelRunner.d.mts +24 -0
  76. package/dist/node/SentinelRunner.d.mts.map +1 -0
  77. package/dist/node/SentinelRunner.d.ts +24 -0
  78. package/dist/node/SentinelRunner.d.ts.map +1 -0
  79. package/dist/node/SentinelRunner.js +114 -0
  80. package/dist/node/SentinelRunner.js.map +1 -0
  81. package/dist/node/SentinelRunner.mjs +90 -0
  82. package/dist/node/SentinelRunner.mjs.map +1 -0
  83. package/dist/node/Wrapper.d.mts +14 -0
  84. package/dist/node/Wrapper.d.mts.map +1 -0
  85. package/dist/node/Wrapper.d.ts +14 -0
  86. package/dist/node/Wrapper.d.ts.map +1 -0
  87. package/dist/node/Wrapper.js +47 -0
  88. package/dist/node/Wrapper.js.map +1 -0
  89. package/dist/node/Wrapper.mjs +27 -0
  90. package/dist/node/Wrapper.mjs.map +1 -0
  91. package/dist/node/index.d.mts +8 -0
  92. package/dist/node/index.d.mts.map +1 -0
  93. package/dist/node/index.d.ts +8 -0
  94. package/dist/node/index.d.ts.map +1 -0
  95. package/dist/node/index.js +35 -0
  96. package/dist/node/index.js.map +1 -0
  97. package/dist/node/index.mjs +8 -0
  98. package/dist/node/index.mjs.map +1 -0
  99. package/package.json +37 -34
  100. package/dist/AbstractSentinel.d.mts.map +0 -1
  101. package/dist/AbstractSentinel.d.ts.map +0 -1
  102. package/dist/Automation.d.mts.map +0 -1
  103. package/dist/Automation.d.ts.map +0 -1
  104. package/dist/MemorySentinel.d.mts.map +0 -1
  105. package/dist/MemorySentinel.d.ts.map +0 -1
  106. package/dist/SentinelIntervalAutomationWrapper.d.mts.map +0 -1
  107. package/dist/SentinelIntervalAutomationWrapper.d.ts.map +0 -1
  108. package/dist/SentinelRunner.d.mts.map +0 -1
  109. package/dist/SentinelRunner.d.ts.map +0 -1
  110. package/dist/Wrapper.d.mts.map +0 -1
  111. package/dist/Wrapper.d.ts.map +0 -1
  112. package/dist/docs.json +0 -63876
  113. package/dist/index.d.mts.map +0 -1
  114. package/dist/index.d.ts.map +0 -1
  115. package/dist/index.js.map +0 -1
  116. package/dist/index.mjs.map +0 -1
  117. /package/dist/{AbstractSentinel.d.mts → browser/AbstractSentinel.d.mts} +0 -0
  118. /package/dist/{AbstractSentinel.d.ts → browser/AbstractSentinel.d.ts} +0 -0
  119. /package/dist/{Automation.d.mts → browser/Automation.d.mts} +0 -0
  120. /package/dist/{Automation.d.ts → browser/Automation.d.ts} +0 -0
  121. /package/dist/{MemorySentinel.d.mts → browser/MemorySentinel.d.mts} +0 -0
  122. /package/dist/{MemorySentinel.d.ts → browser/MemorySentinel.d.ts} +0 -0
  123. /package/dist/{SentinelIntervalAutomationWrapper.d.mts → browser/SentinelIntervalAutomationWrapper.d.mts} +0 -0
  124. /package/dist/{SentinelIntervalAutomationWrapper.d.ts → browser/SentinelIntervalAutomationWrapper.d.ts} +0 -0
  125. /package/dist/{SentinelRunner.d.mts → browser/SentinelRunner.d.mts} +0 -0
  126. /package/dist/{SentinelRunner.d.ts → browser/SentinelRunner.d.ts} +0 -0
  127. /package/dist/{Wrapper.d.mts → browser/Wrapper.d.mts} +0 -0
  128. /package/dist/{Wrapper.d.ts → browser/Wrapper.d.ts} +0 -0
  129. /package/dist/{index.d.mts → browser/index.d.mts} +0 -0
  130. /package/dist/{index.d.ts → browser/index.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/MemorySentinel.ts","../../src/AbstractSentinel.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { fulfilled, rejected } from '@xylabs/promise'\nimport { handleError } from '@xyo-network/error'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n SentinelConfig,\n SentinelConfigSchema,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { WitnessInstance } from '@xyo-network/witness'\n\nimport { AbstractSentinel } from './AbstractSentinel'\n\nexport type MemorySentinelParams<TConfig extends SentinelConfig = 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(payloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n const errors: Error[] = []\n const allWitnesses = [...(await this.witnesses())]\n const resultPayloads: Payload[] = []\n\n try {\n const [generatedPayloads, generatedErrors] = await this.generateResults(allWitnesses)\n const combinedPayloads = [...generatedPayloads, ...payloads]\n resultPayloads.push(...combinedPayloads)\n errors.push(...generatedErrors)\n } catch (ex) {\n handleError(ex, (error) => {\n errors.push(error)\n })\n }\n\n const [boundWitness] = await this.bindQueryResult({ schema: SentinelReportQuerySchema }, resultPayloads)\n this.history.push(assertEx(boundWitness))\n return [boundWitness, ...resultPayloads]\n }\n\n private async generateResults(witnesses: WitnessInstance[]): Promise<[Payload[], Error[]]> {\n const results = await Promise.allSettled(witnesses?.map((witness) => witness.observe()))\n const payloads = results\n .filter(fulfilled)\n .map((result) => result.value)\n .flat()\n const errors = results\n .filter(rejected)\n .map((result) => result.reason)\n .flat()\n return [payloads, errors]\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { uniq } from '@xylabs/lodash'\nimport { AbstractArchivingModule, asArchivistInstance } from '@xyo-network/archivist'\nimport { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'\nimport { BoundWitness, isBoundWitness, notBoundWitness } from '@xyo-network/boundwitness-model'\nimport { ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n CustomSentinelInstance,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n SentinelQueryBase,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { isWitnessInstance, WitnessInstance } from '@xyo-network/witness'\n\nexport abstract class AbstractSentinel<\n TParams extends SentinelParams = SentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n >\n extends AbstractArchivingModule<TParams, TEventData>\n implements CustomSentinelInstance<TParams, TEventData>\n{\n history: BoundWitness[] = []\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 addArchivist(address: string[]) {\n this.config.archivists = uniq([...address, ...(this.config.archivists ?? [])])\n }\n\n addWitness(address: string[]) {\n this.config.witnesses = uniq([...address, ...(this.config.witnesses ?? [])])\n }\n\n async archivists() {\n this.logger?.debug(`archivists:config:archivist: ${this.config?.archivists?.length}`)\n const namesOrAddresses = this.config?.archivists\n ? Array.isArray(this.config.archivists)\n ? this.config?.archivists\n : [this.config.archivists]\n : undefined\n this.logger?.debug(`archivist:namesOrAddresses: ${namesOrAddresses?.length}`)\n const result = [\n ...(await this.resolve(namesOrAddresses ? { address: namesOrAddresses } : undefined)),\n ...(await this.resolve(namesOrAddresses ? { name: namesOrAddresses } : undefined)),\n ].map((module) => assertEx(asArchivistInstance(module), 'Tried to resolve a non-archivist as an archivist'))\n\n if (namesOrAddresses && namesOrAddresses.length !== result.length) {\n this.logger?.warn(`Not all archivists found [Requested: ${namesOrAddresses.length}, Found: ${result.length}]`)\n }\n\n this.logger?.debug(`archivists:result: ${result?.length}`)\n\n return result\n }\n\n removeArchivist(address: string[]) {\n this.config.archivists = (this.config.archivists ?? []).filter((archivist) => !address.includes(archivist))\n }\n\n removeWitness(address: string[]) {\n this.config.witnesses = (this.config.witnesses ?? []).filter((witness) => !address.includes(witness))\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 outPayloads = payloads.filter(notBoundWitness)\n const boundwitnesses = payloads.filter(isBoundWitness)\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 async witnesses() {\n this.logger?.debug(`witnesses:config:witnesses: ${this.config?.witnesses?.length}`)\n const namesOrAddresses = this.config?.witnesses\n ? Array.isArray(this.config.witnesses)\n ? this.config?.witnesses\n : [this.config.witnesses]\n : undefined\n this.logger?.debug(`witnesses:namesOrAddresses: ${namesOrAddresses?.length}`)\n const result = namesOrAddresses\n ? [\n ...(await this.resolve<WitnessInstance>({ address: namesOrAddresses }, { identity: isWitnessInstance })),\n ...(await this.resolve<WitnessInstance>({ name: namesOrAddresses }, { identity: isWitnessInstance })),\n ]\n : await this.resolve<WitnessInstance>(undefined, { identity: isWitnessInstance })\n\n if (namesOrAddresses && namesOrAddresses.length !== result.length) {\n this.logger?.warn(`Not all witnesses found [Requested: ${namesOrAddresses.length}, Found: ${result.length}]`)\n }\n result.map((item) => {\n this.logger?.debug(`witnesses:result: ${item.config.schema}`)\n })\n\n return result\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"],"mappings":";AAAA,SAAS,YAAAA,iBAAgB;AACzB,SAAS,WAAW,gBAAgB;AACpC,SAAS,mBAAmB;AAE5B;AAAA,EAEE;AAAA,EAIA,6BAAAC;AAAA,OACK;;;ACXP,SAAS,gBAAgB;AACzB,SAAS,YAAY;AACrB,SAAS,yBAAyB,2BAA2B;AAC7D,SAA4B,gCAAgC;AAC5D,SAAuB,gBAAgB,uBAAuB;AAG9D;AAAA,EAME;AAAA,OACK;AACP,SAAS,yBAA0C;AAE5C,IAAe,mBAAf,cAIG,wBAEV;AAAA,EACE,UAA0B,CAAC;AAAA,EAE3B,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,aAAa,SAAmB;AAC9B,SAAK,OAAO,aAAa,KAAK,CAAC,GAAG,SAAS,GAAI,KAAK,OAAO,cAAc,CAAC,CAAE,CAAC;AAAA,EAC/E;AAAA,EAEA,WAAW,SAAmB;AAC5B,SAAK,OAAO,YAAY,KAAK,CAAC,GAAG,SAAS,GAAI,KAAK,OAAO,aAAa,CAAC,CAAE,CAAC;AAAA,EAC7E;AAAA,EAEA,MAAM,aAAa;AACjB,SAAK,QAAQ,MAAM,gCAAgC,KAAK,QAAQ,YAAY,MAAM,EAAE;AACpF,UAAM,mBAAmB,KAAK,QAAQ,aAClC,MAAM,QAAQ,KAAK,OAAO,UAAU,IAClC,KAAK,QAAQ,aACb,CAAC,KAAK,OAAO,UAAU,IACzB;AACJ,SAAK,QAAQ,MAAM,+BAA+B,k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;AACA,WAAO;AAAA,EACT;AAGF;;;ADnHO,IAAM,iBAAN,cAGG,iBAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,oBAAoB;AAAA,EAErD,MAAM,cAAc,WAAsB,CAAC,GAAuB;AAChE,UAAM,KAAK,QAAQ,OAAO;AAC1B,UAAM,SAAkB,CAAC;AACzB,UAAM,eAAe,CAAC,GAAI,MAAM,KAAK,UAAU,CAAE;AACjD,UAAM,iBAA4B,CAAC;AAEnC,QAAI;AACF,YAAM,CAAC,mBAAmB,eAAe,IAAI,MAAM,KAAK,gBAAgB,YAAY;AACpF,YAAM,mBAAmB,CAAC,GAAG,mBAAmB,GAAG,QAAQ;AAC3D,qBAAe,KAAK,GAAG,gBAAgB;AACvC,aAAO,KAAK,GAAG,eAAe;AAAA,IAChC,SAAS,IAAI;AACX,kBAAY,IAAI,CAAC,UAAU;AACzB,eAAO,KAAK,KAAK;AAAA,MACnB,CAAC;AAAA,IACH;AAEA,UAAM,CAAC,YAAY,IAAI,MAAM,KAAK,gBAAgB,EAAE,QAAQC,2BAA0B,GAAG,cAAc;AACvG,SAAK,QAAQ,KAAKC,UAAS,YAAY,CAAC;AACxC,WAAO,CAAC,cAAc,GAAG,cAAc;AAAA,EACzC;AAAA,EAEA,MAAc,gBAAgB,WAA6D;AACzF,UAAM,UAAU,MAAM,QAAQ,WAAW,WAAW,IAAI,CAAC,YAAY,QAAQ,QAAQ,CAAC,CAAC;AACvF,UAAM,WAAW,QACd,OAAO,SAAS,EAChB,IAAI,CAAC,WAAW,OAAO,KAAK,EAC5B,KAAK;AACR,UAAM,SAAS,QACZ,OAAO,QAAQ,EACf,IAAI,CAAC,WAAW,OAAO,MAAM,EAC7B,KAAK;AACR,WAAO,CAAC,UAAU,MAAM;AAAA,EAC1B;AACF;","names":["assertEx","SentinelReportQuerySchema","SentinelReportQuerySchema","assertEx"]}
@@ -0,0 +1,68 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/SentinelIntervalAutomationWrapper.ts
21
+ var SentinelIntervalAutomationWrapper_exports = {};
22
+ __export(SentinelIntervalAutomationWrapper_exports, {
23
+ SentinelIntervalAutomationWrapper: () => SentinelIntervalAutomationWrapper
24
+ });
25
+ module.exports = __toCommonJS(SentinelIntervalAutomationWrapper_exports);
26
+ var import_payload_wrapper = require("@xyo-network/payload-wrapper");
27
+ var SentinelIntervalAutomationWrapper = class extends import_payload_wrapper.PayloadWrapper {
28
+ constructor(payload) {
29
+ super(payload);
30
+ }
31
+ get frequencyMillis() {
32
+ const frequency = this.payload().frequency;
33
+ if (frequency === void 0)
34
+ return Infinity;
35
+ switch (this.payload().frequencyUnits ?? "hour") {
36
+ case "second":
37
+ return frequency * 1e3;
38
+ case "minute":
39
+ return frequency * 60 * 1e3;
40
+ case "hour":
41
+ return frequency * 60 * 60 * 1e3;
42
+ case "day":
43
+ return frequency * 24 * 60 * 60 * 1e3;
44
+ }
45
+ }
46
+ get remaining() {
47
+ return this.payload().remaining ?? Infinity;
48
+ }
49
+ next() {
50
+ this.payload().start = this.payload().start + this.frequencyMillis;
51
+ this.consumeRemaining();
52
+ this.checkEnd();
53
+ return this;
54
+ }
55
+ checkEnd() {
56
+ if (this.payload().start > (this.payload().end ?? Infinity)) {
57
+ this.payload().start = Infinity;
58
+ }
59
+ }
60
+ consumeRemaining(count = 1) {
61
+ const remaining = this.remaining - count;
62
+ this.payload().remaining = remaining;
63
+ if (remaining <= 0) {
64
+ this.payload().start = Infinity;
65
+ }
66
+ }
67
+ };
68
+ //# sourceMappingURL=SentinelIntervalAutomationWrapper.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA+B;AAIxB,IAAM,oCAAN,cAEG,sCAAkB;AAAA,EAC1B,YAAY,SAAY;AACtB,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAc,kBAAkB;AAC9B,UAAM,YAAY,KAAK,QAAQ,E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AS,WAGtB;IAED,IAAI;IAOJ,SAAS,CAAC,QAAQ;IAMlB,SAAS,CAAC,gBAAgB,CAAC,KAAK,SAAI;CAQrC"}
@@ -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;AAE7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAA;AAEhE,qBAAa,iCAAiC,CAC5C,CAAC,SAAS,iCAAiC,GAAG,iCAAiC,CAC/E,SAAQ,cAAc,CAAC,CAAC,CAAC;gBACb,OAAO,EAAE,CAAC;IAItB,SAAS,KAAK,eAAe,WAa5B;IAED,SAAS,KAAK,SAAS,WAGtB;IAED,IAAI;IAOJ,SAAS,CAAC,QAAQ;IAMlB,SAAS,CAAC,gBAAgB,CAAC,KAAK,SAAI;CAQrC"}
@@ -0,0 +1,47 @@
1
+ // src/SentinelIntervalAutomationWrapper.ts
2
+ import { PayloadWrapper } from "@xyo-network/payload-wrapper";
3
+ var SentinelIntervalAutomationWrapper = class extends PayloadWrapper {
4
+ constructor(payload) {
5
+ super(payload);
6
+ }
7
+ get frequencyMillis() {
8
+ const frequency = this.payload().frequency;
9
+ if (frequency === void 0)
10
+ return Infinity;
11
+ switch (this.payload().frequencyUnits ?? "hour") {
12
+ case "second":
13
+ return frequency * 1e3;
14
+ case "minute":
15
+ return frequency * 60 * 1e3;
16
+ case "hour":
17
+ return frequency * 60 * 60 * 1e3;
18
+ case "day":
19
+ return frequency * 24 * 60 * 60 * 1e3;
20
+ }
21
+ }
22
+ get remaining() {
23
+ return this.payload().remaining ?? Infinity;
24
+ }
25
+ next() {
26
+ this.payload().start = this.payload().start + this.frequencyMillis;
27
+ this.consumeRemaining();
28
+ this.checkEnd();
29
+ return this;
30
+ }
31
+ checkEnd() {
32
+ if (this.payload().start > (this.payload().end ?? Infinity)) {
33
+ this.payload().start = Infinity;
34
+ }
35
+ }
36
+ consumeRemaining(count = 1) {
37
+ const remaining = this.remaining - count;
38
+ this.payload().remaining = remaining;
39
+ if (remaining <= 0) {
40
+ this.payload().start = Infinity;
41
+ }
42
+ }
43
+ };
44
+ export {
45
+ SentinelIntervalAutomationWrapper
46
+ };
47
+ //# sourceMappingURL=SentinelIntervalAutomationWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["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"],"mappings":";AAAA,SAAS,sBAAsB;AAIxB,IAAM,oCAAN,cAEG,eAAkB;AAAA,EAC1B,YAAY,SAAY;AACtB,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAc,kBAAkB;AAC9B,UAAM,YAAY,KAAK,QAAQ,EAAE;AACjC,QAAI,cAAc;AAAW,aAAO;AACpC,YAAQ,KAAK,QAAQ,EAAE,kBAAkB,QAAQ;AAAA,MAC/C,KAAK;AACH,eAAO,YAAY;AAAA,MACrB,KAAK;AACH,eAAO,YAAY,KAAK;AAAA,MAC1B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK;AAAA,MAC/B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK,KAAK;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,IAAc,YAAY;AAExB,WAAO,KAAK,QAAQ,EAAE,aAAa;AAAA,EACrC;AAAA,EAEA,OAAO;AACL,SAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,EAAE,QAAQ,KAAK;AACnD,SAAK,iBAAiB;AACtB,SAAK,SAAS;AACd,WAAO;AAAA,EACT;AAAA,EAEU,WAAW;AACnB,QAAI,KAAK,QAAQ,EAAE,SAAS,KAAK,QAAQ,EAAE,OAAO,WAAW;AAC3D,WAAK,QAAQ,EAAE,QAAQ;AAAA,IACzB;AAAA,EACF;AAAA,EAEU,iBAAiB,QAAQ,GAAG;AACpC,UAAM,YAAY,KAAK,YAAY;AACnC,SAAK,QAAQ,EAAE,YAAY;AAE3B,QAAI,aAAa,GAAG;AAClB,WAAK,QAAQ,EAAE,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,157 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/SentinelRunner.ts
21
+ var SentinelRunner_exports = {};
22
+ __export(SentinelRunner_exports, {
23
+ SentinelRunner: () => SentinelRunner
24
+ });
25
+ module.exports = __toCommonJS(SentinelRunner_exports);
26
+ var import_assert = require("@xylabs/assert");
27
+ var import_payload_wrapper2 = require("@xyo-network/payload-wrapper");
28
+
29
+ // src/SentinelIntervalAutomationWrapper.ts
30
+ var import_payload_wrapper = require("@xyo-network/payload-wrapper");
31
+ var SentinelIntervalAutomationWrapper = class extends import_payload_wrapper.PayloadWrapper {
32
+ constructor(payload) {
33
+ super(payload);
34
+ }
35
+ get frequencyMillis() {
36
+ const frequency = this.payload().frequency;
37
+ if (frequency === void 0)
38
+ return Infinity;
39
+ switch (this.payload().frequencyUnits ?? "hour") {
40
+ case "second":
41
+ return frequency * 1e3;
42
+ case "minute":
43
+ return frequency * 60 * 1e3;
44
+ case "hour":
45
+ return frequency * 60 * 60 * 1e3;
46
+ case "day":
47
+ return frequency * 24 * 60 * 60 * 1e3;
48
+ }
49
+ }
50
+ get remaining() {
51
+ return this.payload().remaining ?? Infinity;
52
+ }
53
+ next() {
54
+ this.payload().start = this.payload().start + this.frequencyMillis;
55
+ this.consumeRemaining();
56
+ this.checkEnd();
57
+ return this;
58
+ }
59
+ checkEnd() {
60
+ if (this.payload().start > (this.payload().end ?? Infinity)) {
61
+ this.payload().start = Infinity;
62
+ }
63
+ }
64
+ consumeRemaining(count = 1) {
65
+ const remaining = this.remaining - count;
66
+ this.payload().remaining = remaining;
67
+ if (remaining <= 0) {
68
+ this.payload().start = Infinity;
69
+ }
70
+ }
71
+ };
72
+
73
+ // src/SentinelRunner.ts
74
+ var SentinelRunner = class {
75
+ _automations = {};
76
+ onTriggerResult;
77
+ sentinel;
78
+ timeoutId;
79
+ constructor(sentinel, automations, onTriggerResult) {
80
+ this.sentinel = sentinel;
81
+ this.onTriggerResult = onTriggerResult;
82
+ automations?.forEach((automation) => this.add(automation));
83
+ }
84
+ get automations() {
85
+ return this._automations;
86
+ }
87
+ get next() {
88
+ return Object.values(this._automations).reduce((previous, current) => {
89
+ if (current.type === "interval") {
90
+ return current.start < (previous?.start ?? Infinity) ? current : previous;
91
+ }
92
+ }, void 0);
93
+ }
94
+ async add(automation, restart = true) {
95
+ const hash = await import_payload_wrapper2.PayloadWrapper.hashAsync(automation);
96
+ this._automations[hash] = automation;
97
+ if (restart)
98
+ await this.restart();
99
+ return hash;
100
+ }
101
+ find(hash) {
102
+ Object.entries(this._automations).find(([key]) => key === hash);
103
+ }
104
+ async remove(hash, restart = true) {
105
+ delete this._automations[hash];
106
+ if (restart)
107
+ await this.restart();
108
+ }
109
+ removeAll() {
110
+ this.stop();
111
+ this._automations = {};
112
+ }
113
+ async restart() {
114
+ this.stop();
115
+ await this.start();
116
+ }
117
+ async start() {
118
+ (0, import_assert.assertEx)(this.timeoutId === void 0, "Already started");
119
+ const automation = this.next;
120
+ if (automation) {
121
+ const delay = automation.start - Date.now();
122
+ if (delay < 0) {
123
+ await this.trigger(automation);
124
+ } else {
125
+ this.timeoutId = setTimeout(
126
+ async () => {
127
+ this.timeoutId = void 0;
128
+ await this.start();
129
+ },
130
+ delay > 0 ? delay : 0
131
+ );
132
+ }
133
+ }
134
+ }
135
+ stop() {
136
+ if (this.timeoutId) {
137
+ clearTimeout(this.timeoutId);
138
+ this.timeoutId = void 0;
139
+ }
140
+ }
141
+ async update(hash, automation, restart = true) {
142
+ await this.remove(hash, false);
143
+ await this.add(automation, false);
144
+ if (restart)
145
+ await this.restart();
146
+ }
147
+ async trigger(automation) {
148
+ const wrapper = new SentinelIntervalAutomationWrapper(automation);
149
+ await this.remove(await wrapper.hashAsync(), false);
150
+ wrapper.next();
151
+ await this.add(wrapper.payload(), false);
152
+ const triggerResult = await this.sentinel.report();
153
+ this.onTriggerResult?.(triggerResult);
154
+ await this.start();
155
+ }
156
+ };
157
+ //# sourceMappingURL=SentinelRunner.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["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 { 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAA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Ed;IAED,OAAO,KAAK,IAAI,GAMf;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;IAoBX,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
@@ -0,0 +1,136 @@
1
+ // src/SentinelRunner.ts
2
+ import { assertEx } from "@xylabs/assert";
3
+ import { PayloadWrapper as PayloadWrapper2 } from "@xyo-network/payload-wrapper";
4
+
5
+ // src/SentinelIntervalAutomationWrapper.ts
6
+ import { PayloadWrapper } from "@xyo-network/payload-wrapper";
7
+ var SentinelIntervalAutomationWrapper = class extends PayloadWrapper {
8
+ constructor(payload) {
9
+ super(payload);
10
+ }
11
+ get frequencyMillis() {
12
+ const frequency = this.payload().frequency;
13
+ if (frequency === void 0)
14
+ return Infinity;
15
+ switch (this.payload().frequencyUnits ?? "hour") {
16
+ case "second":
17
+ return frequency * 1e3;
18
+ case "minute":
19
+ return frequency * 60 * 1e3;
20
+ case "hour":
21
+ return frequency * 60 * 60 * 1e3;
22
+ case "day":
23
+ return frequency * 24 * 60 * 60 * 1e3;
24
+ }
25
+ }
26
+ get remaining() {
27
+ return this.payload().remaining ?? Infinity;
28
+ }
29
+ next() {
30
+ this.payload().start = this.payload().start + this.frequencyMillis;
31
+ this.consumeRemaining();
32
+ this.checkEnd();
33
+ return this;
34
+ }
35
+ checkEnd() {
36
+ if (this.payload().start > (this.payload().end ?? Infinity)) {
37
+ this.payload().start = Infinity;
38
+ }
39
+ }
40
+ consumeRemaining(count = 1) {
41
+ const remaining = this.remaining - count;
42
+ this.payload().remaining = remaining;
43
+ if (remaining <= 0) {
44
+ this.payload().start = Infinity;
45
+ }
46
+ }
47
+ };
48
+
49
+ // src/SentinelRunner.ts
50
+ var SentinelRunner = class {
51
+ _automations = {};
52
+ onTriggerResult;
53
+ sentinel;
54
+ timeoutId;
55
+ constructor(sentinel, automations, onTriggerResult) {
56
+ this.sentinel = sentinel;
57
+ this.onTriggerResult = onTriggerResult;
58
+ automations?.forEach((automation) => this.add(automation));
59
+ }
60
+ get automations() {
61
+ return this._automations;
62
+ }
63
+ get next() {
64
+ return Object.values(this._automations).reduce((previous, current) => {
65
+ if (current.type === "interval") {
66
+ return current.start < (previous?.start ?? Infinity) ? current : previous;
67
+ }
68
+ }, void 0);
69
+ }
70
+ async add(automation, restart = true) {
71
+ const hash = await PayloadWrapper2.hashAsync(automation);
72
+ this._automations[hash] = automation;
73
+ if (restart)
74
+ await this.restart();
75
+ return hash;
76
+ }
77
+ find(hash) {
78
+ Object.entries(this._automations).find(([key]) => key === hash);
79
+ }
80
+ async remove(hash, restart = true) {
81
+ delete this._automations[hash];
82
+ if (restart)
83
+ await this.restart();
84
+ }
85
+ removeAll() {
86
+ this.stop();
87
+ this._automations = {};
88
+ }
89
+ async restart() {
90
+ this.stop();
91
+ await this.start();
92
+ }
93
+ async start() {
94
+ assertEx(this.timeoutId === void 0, "Already started");
95
+ const automation = this.next;
96
+ if (automation) {
97
+ const delay = automation.start - Date.now();
98
+ if (delay < 0) {
99
+ await this.trigger(automation);
100
+ } else {
101
+ this.timeoutId = setTimeout(
102
+ async () => {
103
+ this.timeoutId = void 0;
104
+ await this.start();
105
+ },
106
+ delay > 0 ? delay : 0
107
+ );
108
+ }
109
+ }
110
+ }
111
+ stop() {
112
+ if (this.timeoutId) {
113
+ clearTimeout(this.timeoutId);
114
+ this.timeoutId = void 0;
115
+ }
116
+ }
117
+ async update(hash, automation, restart = true) {
118
+ await this.remove(hash, false);
119
+ await this.add(automation, false);
120
+ if (restart)
121
+ await this.restart();
122
+ }
123
+ async trigger(automation) {
124
+ const wrapper = new SentinelIntervalAutomationWrapper(automation);
125
+ await this.remove(await wrapper.hashAsync(), false);
126
+ wrapper.next();
127
+ await this.add(wrapper.payload(), false);
128
+ const triggerResult = await this.sentinel.report();
129
+ this.onTriggerResult?.(triggerResult);
130
+ await this.start();
131
+ }
132
+ };
133
+ export {
134
+ SentinelRunner
135
+ };
136
+ //# sourceMappingURL=SentinelRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["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 { 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"],"mappings":";AAAA,SAAS,gBAAgB;AAEzB,SAAS,kBAAAA,uBAAsB;;;ACF/B,SAAS,sBAAsB;AAIxB,IAAM,oCAAN,cAEG,eAAkB;AAAA,EAC1B,YAAY,SAAY;AACtB,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAc,kBAAkB;AAC9B,UAAM,YAAY,KAAK,QAAQ,EAAE;AACjC,QAAI,cAAc;AAAW,aAAO;AACpC,YAAQ,KAAK,QAAQ,EAAE,kBAAkB,QAAQ;AAAA,MAC/C,KAAK;AACH,eAAO,YAAY;AAAA,MACrB,KAAK;AACH,eAAO,YAAY,KAAK;AAAA,MAC1B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK;AAAA,MAC/B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK,KAAK;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,IAAc,YAAY;AAExB,WAAO,KAAK,QAAQ,EAAE,aAAa;AAAA,EACrC;AAAA,EAEA,OAAO;AACL,SAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,EAAE,QAAQ,KAAK;AACnD,SAAK,iBAAiB;AACtB,SAAK,SAAS;AACd,WAAO;AAAA,EACT;AAAA,EAEU,WAAW;AACnB,QAAI,KAAK,QAAQ,EAAE,SAAS,KAAK,QAAQ,EAAE,OAAO,WAAW;AAC3D,WAAK,QAAQ,EAAE,QAAQ;AAAA,IACzB;AAAA,EACF;AAAA,EAEU,iBAAiB,QAAQ,GAAG;AACpC,UAAM,YAAY,KAAK,YAAY;AACnC,SAAK,QAAQ,EAAE,YAAY;AAE3B,QAAI,aAAa,GAAG;AAClB,WAAK,QAAQ,EAAE,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;;;AD1CO,IAAM,iBAAN,MAAqB;AAAA,EAChB,eAA0D,CAAC;AAAA,EAC3D;AAAA,EACA;AAAA,EACA;AAA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UACf,YAAY;AACV,iBAAK,YAAY;AACjB,kBAAM,KAAK,MAAM;AAAA,UACnB;AAAA,UACA,QAAQ,IAAI,QAAQ;AAAA,QACtB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,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;AACnE,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,SAAK,kBAAkB,aAAa;AACpC,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;","names":["PayloadWrapper","PayloadWrapper"]}
@@ -0,0 +1,45 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/Wrapper.ts
21
+ var Wrapper_exports = {};
22
+ __export(Wrapper_exports, {
23
+ SentinelWrapper: () => SentinelWrapper
24
+ });
25
+ module.exports = __toCommonJS(Wrapper_exports);
26
+ var import_module = require("@xyo-network/module");
27
+ var import_sentinel_model = require("@xyo-network/sentinel-model");
28
+ (0, import_module.constructableModuleWrapper)();
29
+ var SentinelWrapper = class extends import_module.ModuleWrapper {
30
+ static instanceIdentityCheck = import_sentinel_model.isSentinelInstance;
31
+ static moduleIdentityCheck = import_sentinel_model.isSentinelModule;
32
+ static requiredQueries = [import_sentinel_model.SentinelReportQuerySchema, ...super.requiredQueries];
33
+ archivists() {
34
+ throw Error("Not supported");
35
+ }
36
+ async report(payloads) {
37
+ const queryPayload = { schema: import_sentinel_model.SentinelReportQuerySchema };
38
+ const result = await this.sendQuery(queryPayload, payloads);
39
+ return result;
40
+ }
41
+ witnesses() {
42
+ throw Error("Not supported");
43
+ }
44
+ };
45
+ //# sourceMappingURL=Wrapper.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Wrapper.ts"],"sourcesContent":["import { ArchivistInstance } from '@xyo-network/archivist'\nimport { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module'\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'\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;AACA,oBAA0D;AAE1D,4BAOO;AAAA,IAGP,0CAA2B;AACpB,IAAM,kBAAN,cACG,4BAEV;AAAA,EACE,OAAgB,wBAAwB;AAAA,EACxC,OAAgB,sBAAsB;AAAA,EACtC,OAAgB,kBAAkB,CAAC,iDAA2B,GAAG,MAAM,eAAe;AAAA,EAEtF,aAA2C;AACzC,UAAM,MAAM,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,UAA0C;AACrD,UAAM,eAAoC,EAAE,QAAQ,gDAA0B;AAC9E,UAAM,SAAS,MAAM,KAAK,UAAU,cAAc,QAAQ;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;","names":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../src/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAA8B,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAGL,gBAAgB,EAChB,cAAc,EAGf,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAGtD,qBAAa,eAAe,CAAC,OAAO,SAAS,cAAc,GAAG,cAAc,CAC1E,SAAQ,aAAa,CAAC,OAAO,CAC7B,YAAW,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAgB,qBAAqB,kEAAqB;IAC1D,OAAgB,mBAAmB,gEAAmB;IACtD,OAAgB,eAAe,WAAwD;IAEvF,UAAU,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAIpC,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAMtD,SAAS,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CAGxC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../src/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAA8B,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAGL,gBAAgB,EAChB,cAAc,EAGf,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAGtD,qBAAa,eAAe,CAAC,OAAO,SAAS,cAAc,GAAG,cAAc,CAC1E,SAAQ,aAAa,CAAC,OAAO,CAC7B,YAAW,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAgB,qBAAqB,kEAAqB;IAC1D,OAAgB,mBAAmB,gEAAmB;IACtD,OAAgB,eAAe,WAAwD;IAEvF,UAAU,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAIpC,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAMtD,SAAS,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CAGxC"}
@@ -0,0 +1,28 @@
1
+ // src/Wrapper.ts
2
+ import { constructableModuleWrapper, ModuleWrapper } from "@xyo-network/module";
3
+ import {
4
+ isSentinelInstance,
5
+ isSentinelModule,
6
+ SentinelReportQuerySchema
7
+ } from "@xyo-network/sentinel-model";
8
+ constructableModuleWrapper();
9
+ var SentinelWrapper = class extends ModuleWrapper {
10
+ static instanceIdentityCheck = isSentinelInstance;
11
+ static moduleIdentityCheck = isSentinelModule;
12
+ static requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries];
13
+ archivists() {
14
+ throw Error("Not supported");
15
+ }
16
+ async report(payloads) {
17
+ const queryPayload = { schema: SentinelReportQuerySchema };
18
+ const result = await this.sendQuery(queryPayload, payloads);
19
+ return result;
20
+ }
21
+ witnesses() {
22
+ throw Error("Not supported");
23
+ }
24
+ };
25
+ export {
26
+ SentinelWrapper
27
+ };
28
+ //# sourceMappingURL=Wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Wrapper.ts"],"sourcesContent":["import { ArchivistInstance } from '@xyo-network/archivist'\nimport { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module'\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'\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":";AACA,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;","names":[]}
@@ -310,14 +310,4 @@ var SentinelWrapper = class extends import_module.ModuleWrapper {
310
310
 
311
311
  // src/index.ts
312
312
  __reExport(src_exports, require("@xyo-network/sentinel-model"), module.exports);
313
- // Annotate the CommonJS export names for ESM import in node:
314
- 0 && (module.exports = {
315
- AbstractSentinel,
316
- MemorySentinel,
317
- SentinelAutomationSchema,
318
- SentinelIntervalAutomationWrapper,
319
- SentinelRunner,
320
- SentinelWrapper,
321
- ...require("@xyo-network/sentinel-model")
322
- });
323
- //# sourceMappingURL=index.js.map
313
+ //# sourceMappingURL=index.cjs.map