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