@xyo-network/sentinel 2.84.6 → 2.84.8
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 +3 -0
- package/dist/browser/MemorySentinel.d.cts.map +1 -1
- package/dist/browser/MemorySentinel.d.mts +3 -0
- package/dist/browser/MemorySentinel.d.mts.map +1 -1
- package/dist/browser/MemorySentinel.d.ts +3 -0
- package/dist/browser/MemorySentinel.d.ts.map +1 -1
- package/dist/browser/SentinelIntervalAutomationWrapper.d.cts +11 -1
- package/dist/browser/SentinelIntervalAutomationWrapper.d.cts.map +1 -1
- package/dist/browser/SentinelIntervalAutomationWrapper.d.mts +11 -1
- package/dist/browser/SentinelIntervalAutomationWrapper.d.mts.map +1 -1
- package/dist/browser/SentinelIntervalAutomationWrapper.d.ts +11 -1
- package/dist/browser/SentinelIntervalAutomationWrapper.d.ts.map +1 -1
- package/dist/browser/SentinelRunner.d.cts +1 -2
- package/dist/browser/SentinelRunner.d.cts.map +1 -1
- package/dist/browser/SentinelRunner.d.mts +1 -2
- package/dist/browser/SentinelRunner.d.mts.map +1 -1
- package/dist/browser/SentinelRunner.d.ts +1 -2
- package/dist/browser/SentinelRunner.d.ts.map +1 -1
- package/dist/browser/index.cjs +148 -110
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +0 -1
- package/dist/browser/index.d.cts.map +1 -1
- package/dist/browser/index.d.mts +0 -1
- package/dist/browser/index.d.mts.map +1 -1
- package/dist/browser/index.d.ts +0 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +143 -103
- package/dist/browser/index.js.map +1 -1
- package/dist/node/MemorySentinel.d.cts +3 -0
- package/dist/node/MemorySentinel.d.cts.map +1 -1
- package/dist/node/MemorySentinel.d.mts +3 -0
- package/dist/node/MemorySentinel.d.mts.map +1 -1
- package/dist/node/MemorySentinel.d.ts +3 -0
- package/dist/node/MemorySentinel.d.ts.map +1 -1
- package/dist/node/SentinelIntervalAutomationWrapper.d.cts +11 -1
- package/dist/node/SentinelIntervalAutomationWrapper.d.cts.map +1 -1
- package/dist/node/SentinelIntervalAutomationWrapper.d.mts +11 -1
- package/dist/node/SentinelIntervalAutomationWrapper.d.mts.map +1 -1
- package/dist/node/SentinelIntervalAutomationWrapper.d.ts +11 -1
- package/dist/node/SentinelIntervalAutomationWrapper.d.ts.map +1 -1
- package/dist/node/SentinelRunner.d.cts +1 -2
- package/dist/node/SentinelRunner.d.cts.map +1 -1
- package/dist/node/SentinelRunner.d.mts +1 -2
- package/dist/node/SentinelRunner.d.mts.map +1 -1
- package/dist/node/SentinelRunner.d.ts +1 -2
- package/dist/node/SentinelRunner.d.ts.map +1 -1
- package/dist/node/index.cjs +150 -114
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +0 -1
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.mts +0 -1
- package/dist/node/index.d.mts.map +1 -1
- package/dist/node/index.d.ts +0 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +145 -103
- package/dist/node/index.js.map +1 -1
- package/package.json +18 -18
- package/src/MemorySentinel.ts +28 -5
- package/src/SentinelIntervalAutomationWrapper.ts +41 -18
- package/src/SentinelRunner.ts +27 -19
- package/src/Wrapper.ts +2 -2
- package/src/index.ts +0 -1
- package/dist/browser/Automation.d.cts +0 -71
- package/dist/browser/Automation.d.cts.map +0 -1
- package/dist/browser/Automation.d.mts +0 -71
- package/dist/browser/Automation.d.mts.map +0 -1
- package/dist/browser/Automation.d.ts +0 -71
- package/dist/browser/Automation.d.ts.map +0 -1
- package/dist/node/Automation.d.cts +0 -71
- package/dist/node/Automation.d.cts.map +0 -1
- package/dist/node/Automation.d.mts +0 -71
- package/dist/node/Automation.d.mts.map +0 -1
- package/dist/node/Automation.d.ts +0 -71
- package/dist/node/Automation.d.ts.map +0 -1
- package/src/Automation.ts +0 -55
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PayloadWrapper } from '@xyo-network/payload-wrapper';
|
|
2
|
-
import { SentinelIntervalAutomationPayload } from '
|
|
2
|
+
import { SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model';
|
|
3
3
|
export declare class SentinelIntervalAutomationWrapper<T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload> extends PayloadWrapper<T> {
|
|
4
4
|
constructor(payload: T);
|
|
5
5
|
protected get frequencyMillis(): number;
|
|
@@ -7,5 +7,15 @@ export declare class SentinelIntervalAutomationWrapper<T extends SentinelInterva
|
|
|
7
7
|
next(): this;
|
|
8
8
|
protected checkEnd(): void;
|
|
9
9
|
protected consumeRemaining(count?: number): void;
|
|
10
|
+
/**
|
|
11
|
+
* Sets the remaining of the wrapped automation
|
|
12
|
+
* @param remaining The remaining time in milliseconds
|
|
13
|
+
*/
|
|
14
|
+
protected setRemaining(remaining: number): void;
|
|
15
|
+
/**
|
|
16
|
+
* Sets the start of the wrapped automation
|
|
17
|
+
* @param start The start time in milliseconds
|
|
18
|
+
*/
|
|
19
|
+
protected setStart(start: number): void;
|
|
10
20
|
}
|
|
11
21
|
//# sourceMappingURL=SentinelIntervalAutomationWrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentinelIntervalAutomationWrapper.d.ts","sourceRoot":"","sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"SentinelIntervalAutomationWrapper.d.ts","sourceRoot":"","sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAA;AAE/E,qBAAa,iCAAiC,CAC5C,CAAC,SAAS,iCAAiC,GAAG,iCAAiC,CAC/E,SAAQ,cAAc,CAAC,CAAC,CAAC;gBACb,OAAO,EAAE,CAAC;IAItB,SAAS,KAAK,eAAe,WAqB5B;IAED,SAAS,KAAK,SAAS,WAEtB;IAED,IAAI;IAWJ,SAAS,CAAC,QAAQ;IAMlB,SAAS,CAAC,gBAAgB,CAAC,KAAK,SAAI;IAMpC;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM;IAIxC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;CAGjC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PayloadWrapper } from '@xyo-network/payload-wrapper';
|
|
2
|
-
import { SentinelIntervalAutomationPayload } from '
|
|
2
|
+
import { SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model';
|
|
3
3
|
export declare class SentinelIntervalAutomationWrapper<T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload> extends PayloadWrapper<T> {
|
|
4
4
|
constructor(payload: T);
|
|
5
5
|
protected get frequencyMillis(): number;
|
|
@@ -7,5 +7,15 @@ export declare class SentinelIntervalAutomationWrapper<T extends SentinelInterva
|
|
|
7
7
|
next(): this;
|
|
8
8
|
protected checkEnd(): void;
|
|
9
9
|
protected consumeRemaining(count?: number): void;
|
|
10
|
+
/**
|
|
11
|
+
* Sets the remaining of the wrapped automation
|
|
12
|
+
* @param remaining The remaining time in milliseconds
|
|
13
|
+
*/
|
|
14
|
+
protected setRemaining(remaining: number): void;
|
|
15
|
+
/**
|
|
16
|
+
* Sets the start of the wrapped automation
|
|
17
|
+
* @param start The start time in milliseconds
|
|
18
|
+
*/
|
|
19
|
+
protected setStart(start: number): void;
|
|
10
20
|
}
|
|
11
21
|
//# sourceMappingURL=SentinelIntervalAutomationWrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentinelIntervalAutomationWrapper.d.ts","sourceRoot":"","sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"SentinelIntervalAutomationWrapper.d.ts","sourceRoot":"","sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAA;AAE/E,qBAAa,iCAAiC,CAC5C,CAAC,SAAS,iCAAiC,GAAG,iCAAiC,CAC/E,SAAQ,cAAc,CAAC,CAAC,CAAC;gBACb,OAAO,EAAE,CAAC;IAItB,SAAS,KAAK,eAAe,WAqB5B;IAED,SAAS,KAAK,SAAS,WAEtB;IAED,IAAI;IAWJ,SAAS,CAAC,QAAQ;IAMlB,SAAS,CAAC,gBAAgB,CAAC,KAAK,SAAI;IAMpC;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM;IAIxC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;CAGjC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
import { SentinelInstance } from '@xyo-network/sentinel-model';
|
|
4
|
-
import { SentinelAutomationPayload } from './Automation';
|
|
3
|
+
import { SentinelAutomationPayload, SentinelInstance } from '@xyo-network/sentinel-model';
|
|
5
4
|
export type OnSentinelRunnerTriggerResult = (result: Payload[]) => void;
|
|
6
5
|
export declare class SentinelRunner {
|
|
7
6
|
protected _automations: Record<string, SentinelAutomationPayload>;
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAEL,yBAAyB,EACzB,gBAAgB,EAEjB,MAAM,6BAA6B,CAAA;AAIpC,MAAM,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEvE,qBAAa,cAAc;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAK;IACtE,SAAS,CAAC,eAAe,EAAE,6BAA6B,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACpC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;gBAE1C,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,yBAAyB,EAAE,EAAE,eAAe,CAAC,EAAE,6BAA6B;IAMlI,IAAI,WAAW,8CAEd;IAED,OAAO,KAAK,IAAI,GASf;IAEK,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;IAO/D,IAAI,CAAC,IAAI,EAAE,MAAM;IAIX,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO;IAKzC,SAAS;IAKH,OAAO;IAKP,KAAK;IAwBX,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
import { SentinelInstance } from '@xyo-network/sentinel-model';
|
|
4
|
-
import { SentinelAutomationPayload } from './Automation';
|
|
3
|
+
import { SentinelAutomationPayload, SentinelInstance } from '@xyo-network/sentinel-model';
|
|
5
4
|
export type OnSentinelRunnerTriggerResult = (result: Payload[]) => void;
|
|
6
5
|
export declare class SentinelRunner {
|
|
7
6
|
protected _automations: Record<string, SentinelAutomationPayload>;
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAEL,yBAAyB,EACzB,gBAAgB,EAEjB,MAAM,6BAA6B,CAAA;AAIpC,MAAM,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEvE,qBAAa,cAAc;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAK;IACtE,SAAS,CAAC,eAAe,EAAE,6BAA6B,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACpC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;gBAE1C,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,yBAAyB,EAAE,EAAE,eAAe,CAAC,EAAE,6BAA6B;IAMlI,IAAI,WAAW,8CAEd;IAED,OAAO,KAAK,IAAI,GASf;IAEK,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;IAO/D,IAAI,CAAC,IAAI,EAAE,MAAM;IAIX,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO;IAKzC,SAAS;IAKH,OAAO;IAKP,KAAK;IAwBX,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
-
import { SentinelInstance } from '@xyo-network/sentinel-model';
|
|
4
|
-
import { SentinelAutomationPayload } from './Automation';
|
|
3
|
+
import { SentinelAutomationPayload, SentinelInstance } from '@xyo-network/sentinel-model';
|
|
5
4
|
export type OnSentinelRunnerTriggerResult = (result: Payload[]) => void;
|
|
6
5
|
export declare class SentinelRunner {
|
|
7
6
|
protected _automations: Record<string, SentinelAutomationPayload>;
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAEL,yBAAyB,EACzB,gBAAgB,EAEjB,MAAM,6BAA6B,CAAA;AAIpC,MAAM,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEvE,qBAAa,cAAc;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAK;IACtE,SAAS,CAAC,eAAe,EAAE,6BAA6B,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACpC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;gBAE1C,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,yBAAyB,EAAE,EAAE,eAAe,CAAC,EAAE,6BAA6B;IAMlI,IAAI,WAAW,8CAEd;IAED,OAAO,KAAK,IAAI,GASf;IAEK,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;IAO/D,IAAI,CAAC,IAAI,EAAE,MAAM;IAIX,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO;IAKzC,SAAS;IAKH,OAAO;IAKP,KAAK;IAwBX,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -22,85 +22,23 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var src_exports = {};
|
|
23
23
|
__export(src_exports, {
|
|
24
24
|
MemorySentinel: () => MemorySentinel,
|
|
25
|
-
SentinelAutomationSchema: () => SentinelAutomationSchema,
|
|
26
|
-
SentinelEventAutomationSchema: () => SentinelEventAutomationSchema,
|
|
27
|
-
SentinelIntervalAutomationSchema: () => SentinelIntervalAutomationSchema,
|
|
28
25
|
SentinelIntervalAutomationWrapper: () => SentinelIntervalAutomationWrapper,
|
|
29
26
|
SentinelRunner: () => SentinelRunner,
|
|
30
|
-
SentinelWrapper: () => SentinelWrapper
|
|
31
|
-
isSentinelIntervalAutomation: () => isSentinelIntervalAutomation
|
|
27
|
+
SentinelWrapper: () => SentinelWrapper
|
|
32
28
|
});
|
|
33
29
|
module.exports = __toCommonJS(src_exports);
|
|
34
30
|
|
|
35
|
-
// src/Automation.ts
|
|
36
|
-
var import_payload_model = require("@xyo-network/payload-model");
|
|
37
|
-
var SentinelAutomationSchema = "network.xyo.automation";
|
|
38
|
-
var SentinelIntervalAutomationSchema = "network.xyo.automation.interval";
|
|
39
|
-
var SentinelEventAutomationSchema = "network.xyo.automation.event";
|
|
40
|
-
var isSentinelIntervalAutomation = (0, import_payload_model.isPayloadOfSchemaType)(SentinelIntervalAutomationSchema);
|
|
41
|
-
|
|
42
31
|
// src/MemorySentinel.ts
|
|
43
32
|
var import_promise = require("@xylabs/promise");
|
|
44
33
|
var import_diviner_model = require("@xyo-network/diviner-model");
|
|
45
34
|
var import_sentinel_abstract = require("@xyo-network/sentinel-abstract");
|
|
46
|
-
var
|
|
35
|
+
var import_sentinel_model2 = require("@xyo-network/sentinel-model");
|
|
47
36
|
var import_witness_model = require("@xyo-network/witness-model");
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
let index = 0;
|
|
54
|
-
let previousResults = {};
|
|
55
|
-
while (index < job.tasks.length) {
|
|
56
|
-
const generatedPayloads = await this.generateResults(job.tasks[index], previousResults, inPayloads);
|
|
57
|
-
previousResults = generatedPayloads;
|
|
58
|
-
index++;
|
|
59
|
-
}
|
|
60
|
-
return Object.values(previousResults).flat();
|
|
61
|
-
}
|
|
62
|
-
async generateResults(tasks, previousResults, inPayloads) {
|
|
63
|
-
const results = await Promise.allSettled(
|
|
64
|
-
tasks == null ? void 0 : tasks.map(async (task) => {
|
|
65
|
-
const witness = (0, import_witness_model.asWitnessInstance)(task.module);
|
|
66
|
-
const input = task.input ?? false;
|
|
67
|
-
const inPayloadsFound = input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input));
|
|
68
|
-
if (witness) {
|
|
69
|
-
return [witness.address, await witness.observe(inPayloadsFound)];
|
|
70
|
-
}
|
|
71
|
-
const diviner = (0, import_diviner_model.asDivinerInstance)(task.module);
|
|
72
|
-
if (diviner) {
|
|
73
|
-
return [diviner.address, await diviner.divine(inPayloadsFound)];
|
|
74
|
-
}
|
|
75
|
-
throw Error("Unsupported module type");
|
|
76
|
-
})
|
|
77
|
-
);
|
|
78
|
-
const finalResult = {};
|
|
79
|
-
results.filter(import_promise.fulfilled).forEach((result) => {
|
|
80
|
-
const [address, payloads] = result.value;
|
|
81
|
-
finalResult[address] = finalResult[address] ?? [];
|
|
82
|
-
finalResult[address].push(...payloads);
|
|
83
|
-
});
|
|
84
|
-
if (this.throwErrors) {
|
|
85
|
-
const errors = results.filter(import_promise.rejected).map((result) => result.reason);
|
|
86
|
-
if (errors.length > 0) {
|
|
87
|
-
throw Error("At least one module failed");
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return finalResult;
|
|
91
|
-
}
|
|
92
|
-
async inputAddresses(input) {
|
|
93
|
-
if (Array.isArray(input)) {
|
|
94
|
-
return (await Promise.all(input.map(async (inputItem) => await this.inputAddresses(inputItem)))).flat();
|
|
95
|
-
} else {
|
|
96
|
-
const resolved = await this.resolve(input);
|
|
97
|
-
return resolved ? [resolved.address] : [];
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
processPreviousResults(payloads, inputs) {
|
|
101
|
-
return inputs.map((input) => payloads[input] ?? []).flat();
|
|
102
|
-
}
|
|
103
|
-
};
|
|
37
|
+
|
|
38
|
+
// src/SentinelRunner.ts
|
|
39
|
+
var import_assert = require("@xylabs/assert");
|
|
40
|
+
var import_payload_wrapper2 = require("@xyo-network/payload-wrapper");
|
|
41
|
+
var import_sentinel_model = require("@xyo-network/sentinel-model");
|
|
104
42
|
|
|
105
43
|
// src/SentinelIntervalAutomationWrapper.ts
|
|
106
44
|
var import_payload_wrapper = require("@xyo-network/payload-wrapper");
|
|
@@ -111,44 +49,68 @@ var SentinelIntervalAutomationWrapper = class extends import_payload_wrapper.Pay
|
|
|
111
49
|
get frequencyMillis() {
|
|
112
50
|
const frequency = this.jsonPayload().frequency;
|
|
113
51
|
if (frequency === void 0)
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
|
|
52
|
+
return Number.POSITIVE_INFINITY;
|
|
53
|
+
const frequencyUnits = this.jsonPayload().frequencyUnits;
|
|
54
|
+
switch (frequencyUnits ?? "hour") {
|
|
55
|
+
case "second": {
|
|
117
56
|
return frequency * 1e3;
|
|
118
|
-
|
|
57
|
+
}
|
|
58
|
+
case "minute": {
|
|
119
59
|
return frequency * 60 * 1e3;
|
|
120
|
-
|
|
60
|
+
}
|
|
61
|
+
case "hour": {
|
|
121
62
|
return frequency * 60 * 60 * 1e3;
|
|
122
|
-
|
|
63
|
+
}
|
|
64
|
+
case "day": {
|
|
123
65
|
return frequency * 24 * 60 * 60 * 1e3;
|
|
66
|
+
}
|
|
67
|
+
default: {
|
|
68
|
+
return Number.POSITIVE_INFINITY;
|
|
69
|
+
}
|
|
124
70
|
}
|
|
125
71
|
}
|
|
126
72
|
get remaining() {
|
|
127
|
-
return this.
|
|
73
|
+
return this.jsonPayload().remaining ?? Number.POSITIVE_INFINITY;
|
|
128
74
|
}
|
|
129
75
|
next() {
|
|
130
|
-
|
|
76
|
+
var _a;
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
const previousStart = ((_a = this.jsonPayload()) == null ? void 0 : _a.start) ?? now;
|
|
79
|
+
const start = Math.max(previousStart, now);
|
|
80
|
+
const nextStart = start + this.frequencyMillis;
|
|
81
|
+
this.setStart(nextStart);
|
|
131
82
|
this.consumeRemaining();
|
|
132
83
|
this.checkEnd();
|
|
133
84
|
return this;
|
|
134
85
|
}
|
|
135
86
|
checkEnd() {
|
|
136
|
-
if (this.jsonPayload().start > (this.jsonPayload().end ??
|
|
137
|
-
this.
|
|
87
|
+
if (this.jsonPayload().start > (this.jsonPayload().end ?? Number.POSITIVE_INFINITY)) {
|
|
88
|
+
this.setStart(Number.POSITIVE_INFINITY);
|
|
138
89
|
}
|
|
139
90
|
}
|
|
140
91
|
consumeRemaining(count = 1) {
|
|
141
|
-
const remaining = this.remaining - count;
|
|
142
|
-
this.
|
|
143
|
-
if (remaining <= 0)
|
|
144
|
-
this.
|
|
145
|
-
|
|
92
|
+
const remaining = Math.max(this.remaining - count, 0);
|
|
93
|
+
this.setRemaining(remaining);
|
|
94
|
+
if (remaining <= 0)
|
|
95
|
+
this.setStart(Number.POSITIVE_INFINITY);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Sets the remaining of the wrapped automation
|
|
99
|
+
* @param remaining The remaining time in milliseconds
|
|
100
|
+
*/
|
|
101
|
+
setRemaining(remaining) {
|
|
102
|
+
this.obj.remaining = remaining;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Sets the start of the wrapped automation
|
|
106
|
+
* @param start The start time in milliseconds
|
|
107
|
+
*/
|
|
108
|
+
setStart(start) {
|
|
109
|
+
this.obj.start = start;
|
|
146
110
|
}
|
|
147
111
|
};
|
|
148
112
|
|
|
149
113
|
// src/SentinelRunner.ts
|
|
150
|
-
var import_assert = require("@xylabs/assert");
|
|
151
|
-
var import_payload_wrapper2 = require("@xyo-network/payload-wrapper");
|
|
152
114
|
var SentinelRunner = class {
|
|
153
115
|
_automations = {};
|
|
154
116
|
onTriggerResult;
|
|
@@ -157,17 +119,17 @@ var SentinelRunner = class {
|
|
|
157
119
|
constructor(sentinel, automations, onTriggerResult) {
|
|
158
120
|
this.sentinel = sentinel;
|
|
159
121
|
this.onTriggerResult = onTriggerResult;
|
|
160
|
-
|
|
122
|
+
if (automations)
|
|
123
|
+
for (const automation of automations)
|
|
124
|
+
this.add(automation);
|
|
161
125
|
}
|
|
162
126
|
get automations() {
|
|
163
127
|
return this._automations;
|
|
164
128
|
}
|
|
165
129
|
get next() {
|
|
166
130
|
return Object.values(this._automations).reduce((previous, current) => {
|
|
167
|
-
if (isSentinelIntervalAutomation(current)) {
|
|
168
|
-
|
|
169
|
-
return current.start < ((previous == null ? void 0 : previous.start) ?? Infinity) ? current : previous;
|
|
170
|
-
}
|
|
131
|
+
if ((0, import_sentinel_model.isSentinelIntervalAutomation)(current) && (0, import_sentinel_model.isSentinelIntervalAutomation)(previous)) {
|
|
132
|
+
return current.start < ((previous == null ? void 0 : previous.start) ?? Number.POSITIVE_INFINITY) ? current : previous;
|
|
171
133
|
}
|
|
172
134
|
return current;
|
|
173
135
|
}, void 0);
|
|
@@ -196,20 +158,22 @@ var SentinelRunner = class {
|
|
|
196
158
|
await this.start();
|
|
197
159
|
}
|
|
198
160
|
async start() {
|
|
161
|
+
await Promise.resolve();
|
|
199
162
|
(0, import_assert.assertEx)(this.timeoutId === void 0, "Already started");
|
|
200
163
|
const automation = this.next;
|
|
201
|
-
if (isSentinelIntervalAutomation(automation)) {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
this.timeoutId = setTimeout(
|
|
207
|
-
|
|
208
|
-
this.
|
|
164
|
+
if ((0, import_sentinel_model.isSentinelIntervalAutomation)(automation)) {
|
|
165
|
+
const now = Date.now();
|
|
166
|
+
const start = Math.max(automation.start ?? now, now);
|
|
167
|
+
const delay = Math.max(start - now, 0);
|
|
168
|
+
if (delay < Number.POSITIVE_INFINITY) {
|
|
169
|
+
this.timeoutId = setTimeout(async () => {
|
|
170
|
+
try {
|
|
171
|
+
await this.trigger(automation);
|
|
172
|
+
this.stop();
|
|
173
|
+
} finally {
|
|
209
174
|
await this.start();
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
);
|
|
175
|
+
}
|
|
176
|
+
}, delay);
|
|
213
177
|
}
|
|
214
178
|
}
|
|
215
179
|
}
|
|
@@ -233,28 +197,104 @@ var SentinelRunner = class {
|
|
|
233
197
|
await this.add(wrapper.jsonPayload(), false);
|
|
234
198
|
const triggerResult = await this.sentinel.report();
|
|
235
199
|
(_a = this.onTriggerResult) == null ? void 0 : _a.call(this, triggerResult);
|
|
236
|
-
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// src/MemorySentinel.ts
|
|
204
|
+
var MemorySentinel = class extends import_sentinel_abstract.AbstractSentinel {
|
|
205
|
+
static configSchemas = [import_sentinel_model2.SentinelConfigSchema];
|
|
206
|
+
runner;
|
|
207
|
+
async reportHandler(inPayloads = []) {
|
|
208
|
+
await this.started("throw");
|
|
209
|
+
const job = await this.jobPromise;
|
|
210
|
+
let index = 0;
|
|
211
|
+
let previousResults = {};
|
|
212
|
+
while (index < job.tasks.length) {
|
|
213
|
+
const generatedPayloads = await this.generateResults(job.tasks[index], previousResults, inPayloads);
|
|
214
|
+
previousResults = generatedPayloads;
|
|
215
|
+
index++;
|
|
216
|
+
}
|
|
217
|
+
return Object.values(previousResults).flat();
|
|
218
|
+
}
|
|
219
|
+
async start(timeout) {
|
|
220
|
+
var _a;
|
|
221
|
+
if (await super.start(timeout)) {
|
|
222
|
+
if ((((_a = this.config.automations) == null ? void 0 : _a.length) ?? 0) > 0) {
|
|
223
|
+
this.runner = new SentinelRunner(this, this.config.automations);
|
|
224
|
+
await this.runner.start();
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
async stop(timeout) {
|
|
231
|
+
if (this.runner) {
|
|
232
|
+
this.runner.stop();
|
|
233
|
+
this.runner = void 0;
|
|
234
|
+
}
|
|
235
|
+
return await super.stop(timeout);
|
|
236
|
+
}
|
|
237
|
+
async generateResults(tasks, previousResults, inPayloads) {
|
|
238
|
+
const results = await Promise.allSettled(
|
|
239
|
+
tasks == null ? void 0 : tasks.map(async (task) => {
|
|
240
|
+
const witness = (0, import_witness_model.asWitnessInstance)(task.module);
|
|
241
|
+
const input = task.input ?? false;
|
|
242
|
+
const inPayloadsFound = input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input));
|
|
243
|
+
if (witness) {
|
|
244
|
+
return [witness.address, await witness.observe(inPayloadsFound)];
|
|
245
|
+
}
|
|
246
|
+
const diviner = (0, import_diviner_model.asDivinerInstance)(task.module);
|
|
247
|
+
if (diviner) {
|
|
248
|
+
return [diviner.address, await diviner.divine(inPayloadsFound)];
|
|
249
|
+
}
|
|
250
|
+
throw new Error("Unsupported module type");
|
|
251
|
+
})
|
|
252
|
+
);
|
|
253
|
+
const finalResult = {};
|
|
254
|
+
for (const result of results.filter(import_promise.fulfilled)) {
|
|
255
|
+
const [address, payloads] = result.value;
|
|
256
|
+
finalResult[address] = finalResult[address] ?? [];
|
|
257
|
+
finalResult[address].push(...payloads);
|
|
258
|
+
}
|
|
259
|
+
if (this.throwErrors) {
|
|
260
|
+
const errors = results.filter(import_promise.rejected).map((result) => result.reason);
|
|
261
|
+
if (errors.length > 0) {
|
|
262
|
+
throw new Error("At least one module failed");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return finalResult;
|
|
266
|
+
}
|
|
267
|
+
async inputAddresses(input) {
|
|
268
|
+
if (Array.isArray(input)) {
|
|
269
|
+
return (await Promise.all(input.map(async (inputItem) => await this.inputAddresses(inputItem)))).flat();
|
|
270
|
+
} else {
|
|
271
|
+
const resolved = await this.resolve(input);
|
|
272
|
+
return resolved ? [resolved.address] : [];
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
processPreviousResults(payloads, inputs) {
|
|
276
|
+
return inputs.flatMap((input) => payloads[input] ?? []);
|
|
237
277
|
}
|
|
238
278
|
};
|
|
239
279
|
|
|
240
280
|
// src/Wrapper.ts
|
|
241
281
|
var import_module_wrapper = require("@xyo-network/module-wrapper");
|
|
242
|
-
var
|
|
282
|
+
var import_sentinel_model3 = require("@xyo-network/sentinel-model");
|
|
243
283
|
(0, import_module_wrapper.constructableModuleWrapper)();
|
|
244
284
|
var SentinelWrapper = class extends import_module_wrapper.ModuleWrapper {
|
|
245
|
-
static instanceIdentityCheck =
|
|
246
|
-
static moduleIdentityCheck =
|
|
247
|
-
static requiredQueries = [
|
|
285
|
+
static instanceIdentityCheck = import_sentinel_model3.isSentinelInstance;
|
|
286
|
+
static moduleIdentityCheck = import_sentinel_model3.isSentinelModule;
|
|
287
|
+
static requiredQueries = [import_sentinel_model3.SentinelReportQuerySchema, ...super.requiredQueries];
|
|
248
288
|
archivists() {
|
|
249
|
-
throw Error("Not supported");
|
|
289
|
+
throw new Error("Not supported");
|
|
250
290
|
}
|
|
251
291
|
async report(payloads) {
|
|
252
|
-
const queryPayload = { schema:
|
|
292
|
+
const queryPayload = { schema: import_sentinel_model3.SentinelReportQuerySchema };
|
|
253
293
|
const result = await this.sendQuery(queryPayload, payloads);
|
|
254
294
|
return result;
|
|
255
295
|
}
|
|
256
296
|
witnesses() {
|
|
257
|
-
throw Error("Not supported");
|
|
297
|
+
throw new Error("Not supported");
|
|
258
298
|
}
|
|
259
299
|
};
|
|
260
300
|
|
|
@@ -264,13 +304,9 @@ __reExport(src_exports, require("@xyo-network/sentinel-model"), module.exports);
|
|
|
264
304
|
// Annotate the CommonJS export names for ESM import in node:
|
|
265
305
|
0 && (module.exports = {
|
|
266
306
|
MemorySentinel,
|
|
267
|
-
SentinelAutomationSchema,
|
|
268
|
-
SentinelEventAutomationSchema,
|
|
269
|
-
SentinelIntervalAutomationSchema,
|
|
270
307
|
SentinelIntervalAutomationWrapper,
|
|
271
308
|
SentinelRunner,
|
|
272
309
|
SentinelWrapper,
|
|
273
|
-
isSentinelIntervalAutomation,
|
|
274
310
|
...require("@xyo-network/sentinel-abstract"),
|
|
275
311
|
...require("@xyo-network/sentinel-model")
|
|
276
312
|
});
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\nimport { Task } from '@xyo-network/sentinel-model'\n\nexport type SentinelAutomationSchema = 'network.xyo.automation'\nexport const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'\n\nexport type SentinelIntervalAutomationSchema = 'network.xyo.automation.interval'\nexport const SentinelIntervalAutomationSchema: SentinelIntervalAutomationSchema = 'network.xyo.automation.interval'\n\nexport type SentinelEventAutomationSchema = 'network.xyo.automation.event'\nexport const SentinelEventAutomationSchema: SentinelEventAutomationSchema = 'network.xyo.automation.event'\n\nexport type SentinelBaseAutomationPayload<T extends Payload> = Payload<\n {\n tasks?: Task[]\n type?: 'interval' | 'event'\n } & T\n>\n\n/** Settings for an Interval Automation */\nexport type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{\n /** Epoch after which any reoccurrence stops */\n end?: number\n\n /** Time between triggers [non-repeating if undefined] */\n frequency?: number\n\n /** Units for frequency field [hour if undefined] */\n frequencyUnits?: 'second' | 'minute' | 'hour' | 'day'\n\n /** Remaining triggers [infinite if undefined] */\n remaining?: number\n\n schema: SentinelIntervalAutomationSchema\n\n /** Epoch of the next trigger */\n start: number\n\n /** The type of automation */\n type: 'interval'\n}>\n\nexport const isSentinelIntervalAutomation = isPayloadOfSchemaType<SentinelIntervalAutomationPayload>(SentinelIntervalAutomationSchema)\n\n/** Settings for an Event Automation */\nexport type SentinelEventAutomationPayload = SentinelBaseAutomationPayload<{\n schema: SentinelEventAutomationSchema\n type: 'event'\n}>\n\n/** Settings for an Automation */\nexport type SentinelAutomationPayload = Payload<\n SentinelIntervalAutomationPayload | SentinelEventAutomationPayload,\n SentinelAutomationSchema | SentinelIntervalAutomationSchema | SentinelEventAutomationSchema\n>\n","import { Address } from '@xylabs/hex'\nimport { fulfilled, rejected } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport {\n ResolvedTask,\n SentinelConfig,\n SentinelConfigSchema,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\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: ResolvedTask[],\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 const inPayloadsFound =\n input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n if (witness) {\n return [witness.address, await witness.observe(inPayloadsFound)]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n return [diviner.address, await diviner.divine(inPayloadsFound)]\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 if (this.throwErrors) {\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 }\n return finalResult\n }\n\n private async inputAddresses(input: string | string[]): Promise<string[]> {\n if (Array.isArray(input)) {\n return (await Promise.all(input.map(async (inputItem) => await this.inputAddresses(inputItem)))).flat()\n } else {\n const resolved = await this.resolve(input)\n return resolved ? [resolved.address] : []\n }\n }\n\n private processPreviousResults(payloads: Record<string, Payload[]>, inputs: string[]) {\n return inputs.map((input) => payloads[input] ?? []).flat()\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.jsonPayload().frequency\n if (frequency === undefined) return Infinity\n switch (this.jsonPayload().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.jsonPayload().start = this.jsonPayload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.jsonPayload().start > (this.jsonPayload().end ?? Infinity)) {\n this.jsonPayload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.jsonPayload().remaining = remaining\n\n if (remaining <= 0) {\n this.jsonPayload().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 { isSentinelIntervalAutomation, 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<SentinelAutomationPayload | undefined>((previous, current) => {\n if (isSentinelIntervalAutomation(current)) {\n if (isSentinelIntervalAutomation(previous)) {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }\n return current\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 (isSentinelIntervalAutomation(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.jsonPayload(), 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;AAAA;AAAA;;;ACAA,2BAA+C;AAIxC,IAAM,2BAAqD;AAG3D,IAAM,mCAAqE;AAG3E,IAAM,gCAA+D;AAgCrE,IAAM,mCAA+B,4CAAyD,gCAAgC;;;ACzCrI,qBAAoC;AACpC,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,IAA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;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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/MemorySentinel.ts","../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts","../../src/Wrapper.ts"],"sourcesContent":["export * 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 { Address } from '@xylabs/hex'\nimport { fulfilled, rejected } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport {\n ResolvedTask,\n SentinelConfig,\n SentinelConfigSchema,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nimport { SentinelRunner } from './SentinelRunner'\n\nexport type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>\n\nexport class MemorySentinel<\n TParams extends MemorySentinelParams = MemorySentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override configSchemas = [SentinelConfigSchema]\n\n private runner?: SentinelRunner\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n 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 override async start(timeout?: number | undefined): Promise<boolean> {\n if (await super.start(timeout)) {\n if ((this.config.automations?.length ?? 0) > 0) {\n this.runner = new SentinelRunner(this, this.config.automations)\n await this.runner.start()\n }\n return true\n }\n return false\n }\n\n override async stop(timeout?: number | undefined): Promise<boolean> {\n if (this.runner) {\n this.runner.stop()\n this.runner = undefined\n }\n return await super.stop(timeout)\n }\n\n private async generateResults(\n tasks: ResolvedTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n 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 const inPayloadsFound =\n input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n if (witness) {\n return [witness.address, await witness.observe(inPayloadsFound)]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n return [diviner.address, await diviner.divine(inPayloadsFound)]\n }\n throw new Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n for (const result of results.filter(fulfilled)) {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n }\n if (this.throwErrors) {\n const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw new Error('At least one module failed')\n }\n }\n return finalResult\n }\n\n private async inputAddresses(input: string | string[]): Promise<string[]> {\n if (Array.isArray(input)) {\n return (await Promise.all(input.map(async (inputItem) => await this.inputAddresses(inputItem)))).flat()\n } else {\n const resolved = await this.resolve(input)\n return resolved ? [resolved.address] : []\n }\n }\n\n private processPreviousResults(payloads: Record<string, Payload[]>, inputs: string[]) {\n return inputs.flatMap((input) => payloads[input] ?? [])\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport {\n isSentinelIntervalAutomation,\n SentinelAutomationPayload,\n SentinelInstance,\n SentinelIntervalAutomationPayload,\n} from '@xyo-network/sentinel-model'\n\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n if (automations) for (const automation of automations) this.add(automation)\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n // eslint-disable-next-line unicorn/no-array-reduce\n return Object.values(this._automations).reduce<SentinelAutomationPayload | undefined>((previous, current) => {\n if (isSentinelIntervalAutomation(current) && isSentinelIntervalAutomation(previous)) {\n return current.start < (previous?.start ?? Number.POSITIVE_INFINITY) ? current : previous\n }\n return current\n // eslint-disable-next-line unicorn/no-useless-undefined\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n // NOTE: Keep async to match module start signature\n await Promise.resolve()\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (isSentinelIntervalAutomation(automation)) {\n const now = Date.now()\n const start = Math.max(automation.start ?? now, now)\n const delay = Math.max(start - now, 0)\n if (delay < Number.POSITIVE_INFINITY) {\n this.timeoutId = setTimeout(async () => {\n try {\n // Run the automation\n await this.trigger(automation)\n this.stop()\n } finally {\n // No matter what start the next automation\n await this.start()\n }\n }, delay)\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.jsonPayload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n // await this.start()\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.jsonPayload().frequency\n if (frequency === undefined) return Number.POSITIVE_INFINITY\n const frequencyUnits = this.jsonPayload().frequencyUnits\n switch (frequencyUnits ?? 'hour') {\n case 'second': {\n return frequency * 1000\n }\n case 'minute': {\n return frequency * 60 * 1000\n }\n case 'hour': {\n return frequency * 60 * 60 * 1000\n }\n case 'day': {\n return frequency * 24 * 60 * 60 * 1000\n }\n default: {\n return Number.POSITIVE_INFINITY\n }\n }\n }\n\n protected get remaining() {\n return this.jsonPayload().remaining ?? Number.POSITIVE_INFINITY\n }\n\n next() {\n const now = Date.now()\n const previousStart = this.jsonPayload()?.start ?? now\n const start = Math.max(previousStart, now)\n const nextStart = start + this.frequencyMillis\n this.setStart(nextStart)\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.jsonPayload().start > (this.jsonPayload().end ?? Number.POSITIVE_INFINITY)) {\n this.setStart(Number.POSITIVE_INFINITY)\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = Math.max(this.remaining - count, 0)\n this.setRemaining(remaining)\n if (remaining <= 0) this.setStart(Number.POSITIVE_INFINITY)\n }\n\n /**\n * Sets the remaining of the wrapped automation\n * @param remaining The remaining time in milliseconds\n */\n protected setRemaining(remaining: number) {\n this.obj.remaining = remaining\n }\n\n /**\n * Sets the start of the wrapped automation\n * @param start The start time in milliseconds\n */\n protected setStart(start: number) {\n this.obj.start = start\n }\n}\n","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 new 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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ACpF,WAAO,OAAO,QAAQ,CAAC,UAAU,SAAS,KAAK,KAAK,CAAC,CAAC;AAAA,EACxD;AACF;;;AG5GA,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,IAAI,MAAM,eAAe;AAAA,EACjC;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,IAAI,MAAM,eAAe;AAAA,EACjC;AACF;;;AJ/BA,wBAAc,2CAJd;AAKA,wBAAc,wCALd;","names":["import_sentinel_model","import_payload_wrapper","import_sentinel_model"]}
|
package/dist/node/index.d.cts
CHANGED
|
@@ -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,kBAAkB,CAAA;AAChC,cAAc,qCAAqC,CAAA;AACnD,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA"}
|
package/dist/node/index.d.mts
CHANGED
|
@@ -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,kBAAkB,CAAA;AAChC,cAAc,qCAAqC,CAAA;AACnD,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA"}
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/index.d.ts.map
CHANGED
|
@@ -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,kBAAkB,CAAA;AAChC,cAAc,qCAAqC,CAAA;AACnD,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA"}
|