@xyo-network/sentinel 2.75.0 → 2.75.2
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.
- package/dist/browser/AbstractSentinel.d.cts +22 -0
- package/dist/browser/AbstractSentinel.d.cts.map +1 -0
- package/dist/browser/AbstractSentinel.js +2 -3
- package/dist/browser/AbstractSentinel.js.map +1 -1
- package/dist/browser/Automation.d.cts +28 -0
- package/dist/browser/Automation.d.cts.map +1 -0
- package/dist/browser/Automation.js +1 -2
- package/dist/browser/Automation.js.map +1 -1
- package/dist/browser/MemorySentinel.d.cts +10 -0
- package/dist/browser/MemorySentinel.d.cts.map +1 -0
- package/dist/browser/MemorySentinel.js +6 -99
- package/dist/browser/MemorySentinel.js.map +1 -1
- package/dist/browser/SentinelIntervalAutomationWrapper.d.cts +11 -0
- package/dist/browser/SentinelIntervalAutomationWrapper.d.cts.map +1 -0
- package/dist/browser/SentinelIntervalAutomationWrapper.js +2 -3
- package/dist/browser/SentinelIntervalAutomationWrapper.js.map +1 -1
- package/dist/browser/SentinelRunner.d.cts +24 -0
- package/dist/browser/SentinelRunner.d.cts.map +1 -0
- package/dist/browser/SentinelRunner.js +4 -50
- package/dist/browser/SentinelRunner.js.map +1 -1
- package/dist/browser/Wrapper.d.cts +14 -0
- package/dist/browser/Wrapper.d.cts.map +1 -0
- package/dist/browser/Wrapper.js +2 -3
- package/dist/browser/Wrapper.js.map +1 -1
- package/dist/browser/index.d.cts +8 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.js +6 -296
- package/dist/browser/index.js.map +1 -1
- package/dist/docs.json +63876 -0
- package/dist/node/AbstractSentinel.d.cts +22 -0
- package/dist/node/AbstractSentinel.d.cts.map +1 -0
- package/dist/node/AbstractSentinel.js +19 -13
- package/dist/node/AbstractSentinel.js.map +1 -1
- package/dist/node/AbstractSentinel.mjs +18 -13
- package/dist/node/AbstractSentinel.mjs.map +1 -1
- package/dist/node/Automation.d.cts +28 -0
- package/dist/node/Automation.d.cts.map +1 -0
- package/dist/node/Automation.js +3 -1
- package/dist/node/Automation.js.map +1 -1
- package/dist/node/Automation.mjs +2 -1
- package/dist/node/Automation.mjs.map +1 -1
- package/dist/node/MemorySentinel.d.cts +10 -0
- package/dist/node/MemorySentinel.d.cts.map +1 -0
- package/dist/node/MemorySentinel.js +104 -8
- package/dist/node/MemorySentinel.js.map +1 -1
- package/dist/node/MemorySentinel.mjs +104 -7
- package/dist/node/MemorySentinel.mjs.map +1 -1
- package/dist/node/SentinelIntervalAutomationWrapper.d.cts +11 -0
- package/dist/node/SentinelIntervalAutomationWrapper.d.cts.map +1 -0
- package/dist/node/SentinelIntervalAutomationWrapper.js +4 -2
- package/dist/node/SentinelIntervalAutomationWrapper.js.map +1 -1
- package/dist/node/SentinelIntervalAutomationWrapper.mjs +3 -2
- package/dist/node/SentinelIntervalAutomationWrapper.mjs.map +1 -1
- package/dist/node/SentinelRunner.d.cts +24 -0
- package/dist/node/SentinelRunner.d.cts.map +1 -0
- package/dist/node/SentinelRunner.js +56 -8
- package/dist/node/SentinelRunner.js.map +1 -1
- package/dist/node/SentinelRunner.mjs +54 -7
- package/dist/node/SentinelRunner.mjs.map +1 -1
- package/dist/node/Wrapper.d.cts +14 -0
- package/dist/node/Wrapper.d.cts.map +1 -0
- package/dist/node/Wrapper.js +4 -2
- package/dist/node/Wrapper.js.map +1 -1
- package/dist/node/Wrapper.mjs +3 -2
- package/dist/node/Wrapper.mjs.map +1 -1
- package/dist/node/index.d.cts +8 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.js +305 -12
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +301 -6
- package/dist/node/index.mjs.map +1 -1
- package/package.json +17 -17
|
@@ -1,12 +1,109 @@
|
|
|
1
|
-
|
|
1
|
+
// src/MemorySentinel.ts
|
|
2
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
2
3
|
import { fulfilled, rejected } from "@xylabs/promise";
|
|
3
4
|
import { handleError } from "@xyo-network/error";
|
|
4
5
|
import {
|
|
5
6
|
SentinelConfigSchema,
|
|
7
|
+
SentinelReportQuerySchema as SentinelReportQuerySchema2
|
|
8
|
+
} from "@xyo-network/sentinel-model";
|
|
9
|
+
|
|
10
|
+
// src/AbstractSentinel.ts
|
|
11
|
+
import { assertEx } from "@xylabs/assert";
|
|
12
|
+
import { uniq } from "@xylabs/lodash";
|
|
13
|
+
import { AbstractArchivingModule, asArchivistInstance } from "@xyo-network/archivist";
|
|
14
|
+
import { QueryBoundWitnessWrapper } from "@xyo-network/boundwitness-builder";
|
|
15
|
+
import { isBoundWitness, notBoundWitness } from "@xyo-network/boundwitness-model";
|
|
16
|
+
import {
|
|
6
17
|
SentinelReportQuerySchema
|
|
7
18
|
} from "@xyo-network/sentinel-model";
|
|
8
|
-
import {
|
|
9
|
-
class
|
|
19
|
+
import { isWitnessInstance } from "@xyo-network/witness";
|
|
20
|
+
var AbstractSentinel = class extends AbstractArchivingModule {
|
|
21
|
+
history = [];
|
|
22
|
+
get queries() {
|
|
23
|
+
return [SentinelReportQuerySchema, ...super.queries];
|
|
24
|
+
}
|
|
25
|
+
get _queryAccountPaths() {
|
|
26
|
+
return {
|
|
27
|
+
"network.xyo.query.sentinel.report": "1/1"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
addArchivist(address) {
|
|
31
|
+
this.config.archivists = uniq([...address, ...this.config.archivists ?? []]);
|
|
32
|
+
}
|
|
33
|
+
addWitness(address) {
|
|
34
|
+
this.config.witnesses = uniq([...address, ...this.config.witnesses ?? []]);
|
|
35
|
+
}
|
|
36
|
+
async archivists() {
|
|
37
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
38
|
+
(_c = this.logger) == null ? void 0 : _c.debug(`archivists:config:archivist: ${(_b = (_a = this.config) == null ? void 0 : _a.archivists) == null ? void 0 : _b.length}`);
|
|
39
|
+
const namesOrAddresses = ((_d = this.config) == null ? void 0 : _d.archivists) ? Array.isArray(this.config.archivists) ? (_e = this.config) == null ? void 0 : _e.archivists : [this.config.archivists] : void 0;
|
|
40
|
+
(_f = this.logger) == null ? void 0 : _f.debug(`archivist:namesOrAddresses: ${namesOrAddresses == null ? void 0 : namesOrAddresses.length}`);
|
|
41
|
+
const result = [
|
|
42
|
+
...await this.resolve(namesOrAddresses ? { address: namesOrAddresses } : void 0),
|
|
43
|
+
...await this.resolve(namesOrAddresses ? { name: namesOrAddresses } : void 0)
|
|
44
|
+
].map((module) => assertEx(asArchivistInstance(module), "Tried to resolve a non-archivist as an archivist"));
|
|
45
|
+
if (namesOrAddresses && namesOrAddresses.length !== result.length) {
|
|
46
|
+
(_g = this.logger) == null ? void 0 : _g.warn(`Not all archivists found [Requested: ${namesOrAddresses.length}, Found: ${result.length}]`);
|
|
47
|
+
}
|
|
48
|
+
(_h = this.logger) == null ? void 0 : _h.debug(`archivists:result: ${result == null ? void 0 : result.length}`);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
removeArchivist(address) {
|
|
52
|
+
this.config.archivists = (this.config.archivists ?? []).filter((archivist) => !address.includes(archivist));
|
|
53
|
+
}
|
|
54
|
+
removeWitness(address) {
|
|
55
|
+
this.config.witnesses = (this.config.witnesses ?? []).filter((witness) => !address.includes(witness));
|
|
56
|
+
}
|
|
57
|
+
async report(inPayloads) {
|
|
58
|
+
var _a;
|
|
59
|
+
this._noOverride("report");
|
|
60
|
+
await this.emit("reportStart", { inPayloads, module: this });
|
|
61
|
+
const payloads = await this.reportHandler(inPayloads);
|
|
62
|
+
(_a = this.logger) == null ? void 0 : _a.debug(`report:payloads: ${JSON.stringify(payloads, null, 2)}`);
|
|
63
|
+
const outPayloads = payloads.filter(notBoundWitness);
|
|
64
|
+
const boundwitnesses = payloads.filter(isBoundWitness);
|
|
65
|
+
const boundwitness = boundwitnesses.find((bw) => bw.addresses.includes(this.address));
|
|
66
|
+
await this.emit("reportEnd", { boundwitness, inPayloads, module: this, outPayloads });
|
|
67
|
+
return payloads;
|
|
68
|
+
}
|
|
69
|
+
async witnesses() {
|
|
70
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
71
|
+
(_c = this.logger) == null ? void 0 : _c.debug(`witnesses:config:witnesses: ${(_b = (_a = this.config) == null ? void 0 : _a.witnesses) == null ? void 0 : _b.length}`);
|
|
72
|
+
const namesOrAddresses = ((_d = this.config) == null ? void 0 : _d.witnesses) ? Array.isArray(this.config.witnesses) ? (_e = this.config) == null ? void 0 : _e.witnesses : [this.config.witnesses] : void 0;
|
|
73
|
+
(_f = this.logger) == null ? void 0 : _f.debug(`witnesses:namesOrAddresses: ${namesOrAddresses == null ? void 0 : namesOrAddresses.length}`);
|
|
74
|
+
const result = namesOrAddresses ? [
|
|
75
|
+
...await this.resolve({ address: namesOrAddresses }, { identity: isWitnessInstance }),
|
|
76
|
+
...await this.resolve({ name: namesOrAddresses }, { identity: isWitnessInstance })
|
|
77
|
+
] : await this.resolve(void 0, { identity: isWitnessInstance });
|
|
78
|
+
if (namesOrAddresses && namesOrAddresses.length !== result.length) {
|
|
79
|
+
(_g = this.logger) == null ? void 0 : _g.warn(`Not all witnesses found [Requested: ${namesOrAddresses.length}, Found: ${result.length}]`);
|
|
80
|
+
}
|
|
81
|
+
result.map((item) => {
|
|
82
|
+
var _a2;
|
|
83
|
+
(_a2 = this.logger) == null ? void 0 : _a2.debug(`witnesses:result: ${item.config.schema}`);
|
|
84
|
+
});
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
async queryHandler(query, payloads, queryConfig) {
|
|
88
|
+
const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads);
|
|
89
|
+
const queryPayload = await wrapper.getQuery();
|
|
90
|
+
assertEx(this.queryable(query, payloads, queryConfig));
|
|
91
|
+
const resultPayloads = [];
|
|
92
|
+
switch (queryPayload.schema) {
|
|
93
|
+
case SentinelReportQuerySchema: {
|
|
94
|
+
resultPayloads.push(...await this.report(payloads));
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
default: {
|
|
98
|
+
return super.queryHandler(query, payloads);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return resultPayloads;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/MemorySentinel.ts
|
|
106
|
+
var MemorySentinel = class extends AbstractSentinel {
|
|
10
107
|
static configSchemas = [SentinelConfigSchema];
|
|
11
108
|
async reportHandler(payloads = []) {
|
|
12
109
|
await this.started("throw");
|
|
@@ -23,17 +120,17 @@ class MemorySentinel extends AbstractSentinel {
|
|
|
23
120
|
errors.push(error);
|
|
24
121
|
});
|
|
25
122
|
}
|
|
26
|
-
const [boundWitness] = await this.bindQueryResult({ schema:
|
|
27
|
-
this.history.push(
|
|
123
|
+
const [boundWitness] = await this.bindQueryResult({ schema: SentinelReportQuerySchema2 }, resultPayloads);
|
|
124
|
+
this.history.push(assertEx2(boundWitness));
|
|
28
125
|
return [boundWitness, ...resultPayloads];
|
|
29
126
|
}
|
|
30
127
|
async generateResults(witnesses) {
|
|
31
|
-
const results = await Promise.allSettled(witnesses
|
|
128
|
+
const results = await Promise.allSettled(witnesses == null ? void 0 : witnesses.map((witness) => witness.observe()));
|
|
32
129
|
const payloads = results.filter(fulfilled).map((result) => result.value).flat();
|
|
33
130
|
const errors = results.filter(rejected).map((result) => result.reason).flat();
|
|
34
131
|
return [payloads, errors];
|
|
35
132
|
}
|
|
36
|
-
}
|
|
133
|
+
};
|
|
37
134
|
export {
|
|
38
135
|
MemorySentinel
|
|
39
136
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/MemorySentinel.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"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,WAAW,gBAAgB;AACpC,SAAS,mBAAmB;AAE5B;AAAA,EAEE;AAAA,EAIA;AAAA,OACK;AAGP,SAAS,wBAAwB;AAI1B,MAAM,uBAGH,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,QAAQ,0BAA0B,GAAG,cAAc;AACvG,SAAK,QAAQ,KAAK,SAAS,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":[]}
|
|
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[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AN,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,uCAAW,IAAI,CAAC,YAAY,QAAQ,QAAQ,EAAE;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","_a","SentinelReportQuerySchema","assertEx"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PayloadWrapper } from '@xyo-network/payload-wrapper';
|
|
2
|
+
import { SentinelIntervalAutomationPayload } from './Automation';
|
|
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
|
+
//# 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;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"}
|
|
@@ -16,13 +16,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/SentinelIntervalAutomationWrapper.ts
|
|
19
21
|
var SentinelIntervalAutomationWrapper_exports = {};
|
|
20
22
|
__export(SentinelIntervalAutomationWrapper_exports, {
|
|
21
23
|
SentinelIntervalAutomationWrapper: () => SentinelIntervalAutomationWrapper
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(SentinelIntervalAutomationWrapper_exports);
|
|
24
26
|
var import_payload_wrapper = require("@xyo-network/payload-wrapper");
|
|
25
|
-
|
|
27
|
+
var SentinelIntervalAutomationWrapper = class extends import_payload_wrapper.PayloadWrapper {
|
|
26
28
|
constructor(payload) {
|
|
27
29
|
super(payload);
|
|
28
30
|
}
|
|
@@ -62,7 +64,7 @@ class SentinelIntervalAutomationWrapper extends import_payload_wrapper.PayloadWr
|
|
|
62
64
|
this.payload().start = Infinity;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
|
-
}
|
|
67
|
+
};
|
|
66
68
|
// Annotate the CommonJS export names for ESM import in node:
|
|
67
69
|
0 && (module.exports = {
|
|
68
70
|
SentinelIntervalAutomationWrapper
|
|
@@ -1 +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":"
|
|
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,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":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// src/SentinelIntervalAutomationWrapper.ts
|
|
1
2
|
import { PayloadWrapper } from "@xyo-network/payload-wrapper";
|
|
2
|
-
|
|
3
|
+
var SentinelIntervalAutomationWrapper = class extends PayloadWrapper {
|
|
3
4
|
constructor(payload) {
|
|
4
5
|
super(payload);
|
|
5
6
|
}
|
|
@@ -39,7 +40,7 @@ class SentinelIntervalAutomationWrapper extends PayloadWrapper {
|
|
|
39
40
|
this.payload().start = Infinity;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
|
-
}
|
|
43
|
+
};
|
|
43
44
|
export {
|
|
44
45
|
SentinelIntervalAutomationWrapper
|
|
45
46
|
};
|
|
@@ -1 +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,
|
|
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,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
+
import { SentinelInstance } from '@xyo-network/sentinel-model';
|
|
4
|
+
import { SentinelAutomationPayload } from './Automation';
|
|
5
|
+
export type OnSentinelRunnerTriggerResult = (result: Payload[]) => void;
|
|
6
|
+
export declare class SentinelRunner {
|
|
7
|
+
protected _automations: Record<string, SentinelAutomationPayload>;
|
|
8
|
+
protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined;
|
|
9
|
+
protected sentinel: SentinelInstance;
|
|
10
|
+
protected timeoutId?: NodeJS.Timeout | string | number;
|
|
11
|
+
constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult);
|
|
12
|
+
get automations(): Record<string, SentinelAutomationPayload>;
|
|
13
|
+
private get next();
|
|
14
|
+
add(automation: SentinelAutomationPayload, restart?: boolean): Promise<string>;
|
|
15
|
+
find(hash: string): void;
|
|
16
|
+
remove(hash: string, restart?: boolean): Promise<void>;
|
|
17
|
+
removeAll(): void;
|
|
18
|
+
restart(): Promise<void>;
|
|
19
|
+
start(): Promise<void>;
|
|
20
|
+
stop(): void;
|
|
21
|
+
update(hash: string, automation: SentinelAutomationPayload, restart?: boolean): Promise<void>;
|
|
22
|
+
private trigger;
|
|
23
|
+
}
|
|
24
|
+
//# 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,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAE9D,OAAO,EAAE,yBAAyB,EAAqC,MAAM,cAAc,CAAA;AAG3F,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,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"}
|
|
@@ -16,15 +16,62 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/SentinelRunner.ts
|
|
19
21
|
var SentinelRunner_exports = {};
|
|
20
22
|
__export(SentinelRunner_exports, {
|
|
21
23
|
SentinelRunner: () => SentinelRunner
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(SentinelRunner_exports);
|
|
24
26
|
var import_assert = require("@xylabs/assert");
|
|
27
|
+
var import_payload_wrapper2 = require("@xyo-network/payload-wrapper");
|
|
28
|
+
|
|
29
|
+
// src/SentinelIntervalAutomationWrapper.ts
|
|
25
30
|
var import_payload_wrapper = require("@xyo-network/payload-wrapper");
|
|
26
|
-
var
|
|
27
|
-
|
|
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 {
|
|
28
75
|
_automations = {};
|
|
29
76
|
onTriggerResult;
|
|
30
77
|
sentinel;
|
|
@@ -32,7 +79,7 @@ class SentinelRunner {
|
|
|
32
79
|
constructor(sentinel, automations, onTriggerResult) {
|
|
33
80
|
this.sentinel = sentinel;
|
|
34
81
|
this.onTriggerResult = onTriggerResult;
|
|
35
|
-
automations
|
|
82
|
+
automations == null ? void 0 : automations.forEach((automation) => this.add(automation));
|
|
36
83
|
}
|
|
37
84
|
get automations() {
|
|
38
85
|
return this._automations;
|
|
@@ -40,12 +87,12 @@ class SentinelRunner {
|
|
|
40
87
|
get next() {
|
|
41
88
|
return Object.values(this._automations).reduce((previous, current) => {
|
|
42
89
|
if (current.type === "interval") {
|
|
43
|
-
return current.start < (previous
|
|
90
|
+
return current.start < ((previous == null ? void 0 : previous.start) ?? Infinity) ? current : previous;
|
|
44
91
|
}
|
|
45
92
|
}, void 0);
|
|
46
93
|
}
|
|
47
94
|
async add(automation, restart = true) {
|
|
48
|
-
const hash = await
|
|
95
|
+
const hash = await import_payload_wrapper2.PayloadWrapper.hashAsync(automation);
|
|
49
96
|
this._automations[hash] = automation;
|
|
50
97
|
if (restart)
|
|
51
98
|
await this.restart();
|
|
@@ -98,15 +145,16 @@ class SentinelRunner {
|
|
|
98
145
|
await this.restart();
|
|
99
146
|
}
|
|
100
147
|
async trigger(automation) {
|
|
101
|
-
|
|
148
|
+
var _a;
|
|
149
|
+
const wrapper = new SentinelIntervalAutomationWrapper(automation);
|
|
102
150
|
await this.remove(await wrapper.hashAsync(), false);
|
|
103
151
|
wrapper.next();
|
|
104
152
|
await this.add(wrapper.payload(), false);
|
|
105
153
|
const triggerResult = await this.sentinel.report();
|
|
106
|
-
this.onTriggerResult
|
|
154
|
+
(_a = this.onTriggerResult) == null ? void 0 : _a.call(this, triggerResult);
|
|
107
155
|
await this.start();
|
|
108
156
|
}
|
|
109
|
-
}
|
|
157
|
+
};
|
|
110
158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
111
159
|
0 && (module.exports = {
|
|
112
160
|
SentinelRunner
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/SentinelRunner.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"],"mappings":"
|
|
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;AAAA;AAAA;AAAA,oBAAyB;AAEzB,IAAAA,0BAA+B;;;ACF/B,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,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;A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aAAa,KAAK;AACxB,QAAI,YAAY;AACd,YAAM,QAAQ,WAAW,QAAQ,KAAK,IAAI;AAC1C,UAAI,QAAQ,GAAG;AAEb,cAAM,KAAK,QAAQ,UAAU;AAAA,MAC/B,OAAO;AACL,aAAK,YAAY;AAAA,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;AA7FvE;AA8FI,UAAM,UAAU,IAAI,kCAAkC,UAAU;AAChE,UAAM,KAAK,OAAO,MAAM,QAAQ,UAAU,GAAG,KAAK;AAClD,YAAQ,KAAK;AACb,UAAM,KAAK,IAAI,QAAQ,QAAQ,GAAG,KAAK;AACvC,UAAM,gBAAgB,MAAM,KAAK,SAAS,OAAO;AACjD,eAAK,oBAAL,8BAAuB;AACvB,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;","names":["import_payload_wrapper"]}
|
|
@@ -1,7 +1,53 @@
|
|
|
1
|
+
// src/SentinelRunner.ts
|
|
1
2
|
import { assertEx } from "@xylabs/assert";
|
|
3
|
+
import { PayloadWrapper as PayloadWrapper2 } from "@xyo-network/payload-wrapper";
|
|
4
|
+
|
|
5
|
+
// src/SentinelIntervalAutomationWrapper.ts
|
|
2
6
|
import { PayloadWrapper } from "@xyo-network/payload-wrapper";
|
|
3
|
-
|
|
4
|
-
|
|
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 {
|
|
5
51
|
_automations = {};
|
|
6
52
|
onTriggerResult;
|
|
7
53
|
sentinel;
|
|
@@ -9,7 +55,7 @@ class SentinelRunner {
|
|
|
9
55
|
constructor(sentinel, automations, onTriggerResult) {
|
|
10
56
|
this.sentinel = sentinel;
|
|
11
57
|
this.onTriggerResult = onTriggerResult;
|
|
12
|
-
automations
|
|
58
|
+
automations == null ? void 0 : automations.forEach((automation) => this.add(automation));
|
|
13
59
|
}
|
|
14
60
|
get automations() {
|
|
15
61
|
return this._automations;
|
|
@@ -17,12 +63,12 @@ class SentinelRunner {
|
|
|
17
63
|
get next() {
|
|
18
64
|
return Object.values(this._automations).reduce((previous, current) => {
|
|
19
65
|
if (current.type === "interval") {
|
|
20
|
-
return current.start < (previous
|
|
66
|
+
return current.start < ((previous == null ? void 0 : previous.start) ?? Infinity) ? current : previous;
|
|
21
67
|
}
|
|
22
68
|
}, void 0);
|
|
23
69
|
}
|
|
24
70
|
async add(automation, restart = true) {
|
|
25
|
-
const hash = await
|
|
71
|
+
const hash = await PayloadWrapper2.hashAsync(automation);
|
|
26
72
|
this._automations[hash] = automation;
|
|
27
73
|
if (restart)
|
|
28
74
|
await this.restart();
|
|
@@ -75,15 +121,16 @@ class SentinelRunner {
|
|
|
75
121
|
await this.restart();
|
|
76
122
|
}
|
|
77
123
|
async trigger(automation) {
|
|
124
|
+
var _a;
|
|
78
125
|
const wrapper = new SentinelIntervalAutomationWrapper(automation);
|
|
79
126
|
await this.remove(await wrapper.hashAsync(), false);
|
|
80
127
|
wrapper.next();
|
|
81
128
|
await this.add(wrapper.payload(), false);
|
|
82
129
|
const triggerResult = await this.sentinel.report();
|
|
83
|
-
this.onTriggerResult
|
|
130
|
+
(_a = this.onTriggerResult) == null ? void 0 : _a.call(this, triggerResult);
|
|
84
131
|
await this.start();
|
|
85
132
|
}
|
|
86
|
-
}
|
|
133
|
+
};
|
|
87
134
|
export {
|
|
88
135
|
SentinelRunner
|
|
89
136
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/SentinelRunner.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"],"mappings":"AAAA,SAAS,gBAAgB;AAEzB,SAAS,sBAAsB;
|
|
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;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L,aAAK,YAAY;AAAA,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;AA7FvE;AA8FI,UAAM,UAAU,IAAI,kCAAkC,UAAU;AAChE,UAAM,KAAK,OAAO,MAAM,QAAQ,UAAU,GAAG,KAAK;AAClD,YAAQ,KAAK;AACb,UAAM,KAAK,IAAI,QAAQ,QAAQ,GAAG,KAAK;AACvC,UAAM,gBAAgB,MAAM,KAAK,SAAS,OAAO;AACjD,eAAK,oBAAL,8BAAuB;AACvB,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;","names":["PayloadWrapper","PayloadWrapper"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ArchivistInstance } from '@xyo-network/archivist';
|
|
2
|
+
import { ModuleWrapper } from '@xyo-network/module';
|
|
3
|
+
import { Payload } from '@xyo-network/payload-model';
|
|
4
|
+
import { SentinelInstance, SentinelModule } from '@xyo-network/sentinel-model';
|
|
5
|
+
import { WitnessInstance } from '@xyo-network/witness';
|
|
6
|
+
export declare class SentinelWrapper<TModule extends SentinelModule = SentinelModule> extends ModuleWrapper<TModule> implements SentinelInstance<TModule['params']> {
|
|
7
|
+
static instanceIdentityCheck: import("@xyo-network/object").ObjectTypeCheck<SentinelInstance>;
|
|
8
|
+
static moduleIdentityCheck: import("@xyo-network/module").ModuleTypeCheck<SentinelModule>;
|
|
9
|
+
static requiredQueries: string[];
|
|
10
|
+
archivists(): Promise<ArchivistInstance[]>;
|
|
11
|
+
report(payloads?: Payload[]): Promise<Payload[]>;
|
|
12
|
+
witnesses(): Promise<WitnessInstance[]>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=Wrapper.d.ts.map
|
|
@@ -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"}
|
package/dist/node/Wrapper.js
CHANGED
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/Wrapper.ts
|
|
19
21
|
var Wrapper_exports = {};
|
|
20
22
|
__export(Wrapper_exports, {
|
|
21
23
|
SentinelWrapper: () => SentinelWrapper
|
|
@@ -24,7 +26,7 @@ module.exports = __toCommonJS(Wrapper_exports);
|
|
|
24
26
|
var import_module = require("@xyo-network/module");
|
|
25
27
|
var import_sentinel_model = require("@xyo-network/sentinel-model");
|
|
26
28
|
(0, import_module.constructableModuleWrapper)();
|
|
27
|
-
|
|
29
|
+
var SentinelWrapper = class extends import_module.ModuleWrapper {
|
|
28
30
|
static instanceIdentityCheck = import_sentinel_model.isSentinelInstance;
|
|
29
31
|
static moduleIdentityCheck = import_sentinel_model.isSentinelModule;
|
|
30
32
|
static requiredQueries = [import_sentinel_model.SentinelReportQuerySchema, ...super.requiredQueries];
|
|
@@ -39,7 +41,7 @@ class SentinelWrapper extends import_module.ModuleWrapper {
|
|
|
39
41
|
witnesses() {
|
|
40
42
|
throw Error("Not supported");
|
|
41
43
|
}
|
|
42
|
-
}
|
|
44
|
+
};
|
|
43
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
46
|
0 && (module.exports = {
|
|
45
47
|
SentinelWrapper
|
package/dist/node/Wrapper.js.map
CHANGED
|
@@ -1 +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":"
|
|
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":[]}
|