@xyo-network/sentinel-memory 2.106.0-rc.5 → 2.107.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/SentinelIntervalAutomationWrapper.d.cts +0 -8
- package/dist/browser/SentinelIntervalAutomationWrapper.d.cts.map +1 -1
- package/dist/browser/SentinelIntervalAutomationWrapper.d.mts +0 -8
- package/dist/browser/SentinelIntervalAutomationWrapper.d.mts.map +1 -1
- package/dist/browser/SentinelIntervalAutomationWrapper.d.ts +0 -8
- package/dist/browser/SentinelIntervalAutomationWrapper.d.ts.map +1 -1
- package/dist/browser/SentinelRunner.d.cts +0 -1
- package/dist/browser/SentinelRunner.d.cts.map +1 -1
- package/dist/browser/SentinelRunner.d.mts +0 -1
- package/dist/browser/SentinelRunner.d.mts.map +1 -1
- package/dist/browser/SentinelRunner.d.ts +0 -1
- package/dist/browser/SentinelRunner.d.ts.map +1 -1
- package/dist/browser/index.cjs +1 -348
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +1 -327
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/SentinelIntervalAutomationWrapper.d.cts +0 -8
- package/dist/neutral/SentinelIntervalAutomationWrapper.d.cts.map +1 -1
- package/dist/neutral/SentinelIntervalAutomationWrapper.d.mts +0 -8
- package/dist/neutral/SentinelIntervalAutomationWrapper.d.mts.map +1 -1
- package/dist/neutral/SentinelIntervalAutomationWrapper.d.ts +0 -8
- package/dist/neutral/SentinelIntervalAutomationWrapper.d.ts.map +1 -1
- package/dist/neutral/SentinelRunner.d.cts +0 -1
- package/dist/neutral/SentinelRunner.d.cts.map +1 -1
- package/dist/neutral/SentinelRunner.d.mts +0 -1
- package/dist/neutral/SentinelRunner.d.mts.map +1 -1
- package/dist/neutral/SentinelRunner.d.ts +0 -1
- package/dist/neutral/SentinelRunner.d.ts.map +1 -1
- package/dist/neutral/index.cjs +1 -348
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +1 -327
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/SentinelIntervalAutomationWrapper.d.cts +0 -8
- package/dist/node/SentinelIntervalAutomationWrapper.d.cts.map +1 -1
- package/dist/node/SentinelIntervalAutomationWrapper.d.mts +0 -8
- package/dist/node/SentinelIntervalAutomationWrapper.d.mts.map +1 -1
- package/dist/node/SentinelIntervalAutomationWrapper.d.ts +0 -8
- package/dist/node/SentinelIntervalAutomationWrapper.d.ts.map +1 -1
- package/dist/node/SentinelRunner.d.cts +0 -1
- package/dist/node/SentinelRunner.d.cts.map +1 -1
- package/dist/node/SentinelRunner.d.mts +0 -1
- package/dist/node/SentinelRunner.d.mts.map +1 -1
- package/dist/node/SentinelRunner.d.ts +0 -1
- package/dist/node/SentinelRunner.d.ts.map +1 -1
- package/dist/node/index.cjs +1 -362
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +1 -335
- package/dist/node/index.js.map +1 -1
- package/package.json +19 -20
|
@@ -7,15 +7,7 @@ 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
10
|
protected setRemaining(remaining: number): void;
|
|
15
|
-
/**
|
|
16
|
-
* Sets the start of the wrapped automation
|
|
17
|
-
* @param start The start time in milliseconds
|
|
18
|
-
*/
|
|
19
11
|
protected setStart(start: number): void;
|
|
20
12
|
}
|
|
21
13
|
//# 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;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;
|
|
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;IAUpC,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM;IAQxC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;CAGjC"}
|
|
@@ -7,15 +7,7 @@ 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
10
|
protected setRemaining(remaining: number): void;
|
|
15
|
-
/**
|
|
16
|
-
* Sets the start of the wrapped automation
|
|
17
|
-
* @param start The start time in milliseconds
|
|
18
|
-
*/
|
|
19
11
|
protected setStart(start: number): void;
|
|
20
12
|
}
|
|
21
13
|
//# 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;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;
|
|
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;IAUpC,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM;IAQxC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;CAGjC"}
|
|
@@ -7,15 +7,7 @@ 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
10
|
protected setRemaining(remaining: number): void;
|
|
15
|
-
/**
|
|
16
|
-
* Sets the start of the wrapped automation
|
|
17
|
-
* @param start The start time in milliseconds
|
|
18
|
-
*/
|
|
19
11
|
protected setStart(start: number): void;
|
|
20
12
|
}
|
|
21
13
|
//# 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;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;
|
|
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;IAUpC,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM;IAQxC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;CAGjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,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;IAKT,OAAO;IAKP,KAAK;IAuBL,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,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;IAKT,OAAO;IAKP,KAAK;IAuBL,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,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;IAKT,OAAO;IAKP,KAAK;IAuBL,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -1,349 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/index.ts
|
|
22
|
-
var src_exports = {};
|
|
23
|
-
__export(src_exports, {
|
|
24
|
-
MemorySentinel: () => MemorySentinel,
|
|
25
|
-
SentinelIntervalAutomationWrapper: () => SentinelIntervalAutomationWrapper,
|
|
26
|
-
SentinelRunner: () => SentinelRunner
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(src_exports);
|
|
29
|
-
|
|
30
|
-
// src/MemorySentinel.ts
|
|
31
|
-
var import_promise = require("@xylabs/promise");
|
|
32
|
-
var import_diviner_model = require("@xyo-network/diviner-model");
|
|
33
|
-
var import_sentinel_abstract = require("@xyo-network/sentinel-abstract");
|
|
34
|
-
var import_sentinel_model2 = require("@xyo-network/sentinel-model");
|
|
35
|
-
var import_witness_model = require("@xyo-network/witness-model");
|
|
36
|
-
|
|
37
|
-
// src/SentinelRunner.ts
|
|
38
|
-
var import_assert = require("@xylabs/assert");
|
|
39
|
-
var import_forget = require("@xylabs/forget");
|
|
40
|
-
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
41
|
-
var import_sentinel_model = require("@xyo-network/sentinel-model");
|
|
42
|
-
|
|
43
|
-
// src/SentinelIntervalAutomationWrapper.ts
|
|
44
|
-
var import_payload_wrapper = require("@xyo-network/payload-wrapper");
|
|
45
|
-
var SentinelIntervalAutomationWrapper = class extends import_payload_wrapper.PayloadWrapper {
|
|
46
|
-
static {
|
|
47
|
-
__name(this, "SentinelIntervalAutomationWrapper");
|
|
48
|
-
}
|
|
49
|
-
constructor(payload) {
|
|
50
|
-
super(payload);
|
|
51
|
-
}
|
|
52
|
-
get frequencyMillis() {
|
|
53
|
-
const frequency = this.payload.frequency;
|
|
54
|
-
if (frequency === void 0) return Number.POSITIVE_INFINITY;
|
|
55
|
-
const frequencyUnits = this.payload.frequencyUnits;
|
|
56
|
-
switch (frequencyUnits ?? "hour") {
|
|
57
|
-
case "second": {
|
|
58
|
-
return frequency * 1e3;
|
|
59
|
-
}
|
|
60
|
-
case "minute": {
|
|
61
|
-
return frequency * 60 * 1e3;
|
|
62
|
-
}
|
|
63
|
-
case "hour": {
|
|
64
|
-
return frequency * 60 * 60 * 1e3;
|
|
65
|
-
}
|
|
66
|
-
case "day": {
|
|
67
|
-
return frequency * 24 * 60 * 60 * 1e3;
|
|
68
|
-
}
|
|
69
|
-
default: {
|
|
70
|
-
return Number.POSITIVE_INFINITY;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
get remaining() {
|
|
75
|
-
return this.payload.remaining ?? Number.POSITIVE_INFINITY;
|
|
76
|
-
}
|
|
77
|
-
next() {
|
|
78
|
-
const now = Date.now();
|
|
79
|
-
const previousStart = this.payload?.start ?? now;
|
|
80
|
-
const start = Math.max(previousStart, now);
|
|
81
|
-
const nextStart = start + this.frequencyMillis;
|
|
82
|
-
this.setStart(nextStart);
|
|
83
|
-
this.consumeRemaining();
|
|
84
|
-
this.checkEnd();
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
checkEnd() {
|
|
88
|
-
if (this.payload.start > (this.payload.end ?? Number.POSITIVE_INFINITY)) {
|
|
89
|
-
this.setStart(Number.POSITIVE_INFINITY);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
consumeRemaining(count = 1) {
|
|
93
|
-
const remaining = Math.max(this.remaining - count, 0);
|
|
94
|
-
this.setRemaining(remaining);
|
|
95
|
-
if (remaining <= 0) 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.payload.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.payload.start = start;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// src/SentinelRunner.ts
|
|
114
|
-
var SentinelRunner = class {
|
|
115
|
-
static {
|
|
116
|
-
__name(this, "SentinelRunner");
|
|
117
|
-
}
|
|
118
|
-
_automations = {};
|
|
119
|
-
onTriggerResult;
|
|
120
|
-
sentinel;
|
|
121
|
-
timeoutId;
|
|
122
|
-
constructor(sentinel, automations, onTriggerResult) {
|
|
123
|
-
this.sentinel = sentinel;
|
|
124
|
-
this.onTriggerResult = onTriggerResult;
|
|
125
|
-
if (automations) for (const automation of automations) (0, import_forget.forget)(this.add(automation));
|
|
126
|
-
}
|
|
127
|
-
get automations() {
|
|
128
|
-
return this._automations;
|
|
129
|
-
}
|
|
130
|
-
get next() {
|
|
131
|
-
return Object.values(this._automations).reduce((previous, current) => {
|
|
132
|
-
if ((0, import_sentinel_model.isSentinelIntervalAutomation)(current) && (0, import_sentinel_model.isSentinelIntervalAutomation)(previous)) {
|
|
133
|
-
return current.start < (previous?.start ?? Number.POSITIVE_INFINITY) ? current : previous;
|
|
134
|
-
}
|
|
135
|
-
return current;
|
|
136
|
-
}, void 0);
|
|
137
|
-
}
|
|
138
|
-
async add(automation, restart = true) {
|
|
139
|
-
const hash = await import_payload_builder.PayloadBuilder.dataHash(automation);
|
|
140
|
-
this._automations[hash] = automation;
|
|
141
|
-
if (restart) await this.restart();
|
|
142
|
-
return hash;
|
|
143
|
-
}
|
|
144
|
-
find(hash) {
|
|
145
|
-
Object.entries(this._automations).find(([key]) => key === hash);
|
|
146
|
-
}
|
|
147
|
-
async remove(hash, restart = true) {
|
|
148
|
-
delete this._automations[hash];
|
|
149
|
-
if (restart) await this.restart();
|
|
150
|
-
}
|
|
151
|
-
removeAll() {
|
|
152
|
-
this.stop();
|
|
153
|
-
this._automations = {};
|
|
154
|
-
}
|
|
155
|
-
restart() {
|
|
156
|
-
this.stop();
|
|
157
|
-
this.start();
|
|
158
|
-
}
|
|
159
|
-
start() {
|
|
160
|
-
(0, import_assert.assertEx)(this.timeoutId === void 0, () => "Already started");
|
|
161
|
-
const automation = this.next;
|
|
162
|
-
if ((0, import_sentinel_model.isSentinelIntervalAutomation)(automation)) {
|
|
163
|
-
const now = Date.now();
|
|
164
|
-
const start = Math.max(automation.start ?? now, now);
|
|
165
|
-
const delay = Math.max(start - now, 0);
|
|
166
|
-
if (delay < Number.POSITIVE_INFINITY) {
|
|
167
|
-
this.timeoutId = setTimeout(async () => {
|
|
168
|
-
try {
|
|
169
|
-
await this.trigger(automation);
|
|
170
|
-
this.stop();
|
|
171
|
-
} finally {
|
|
172
|
-
this.start();
|
|
173
|
-
}
|
|
174
|
-
}, delay);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
stop() {
|
|
179
|
-
if (this.timeoutId) {
|
|
180
|
-
clearTimeout(this.timeoutId);
|
|
181
|
-
this.timeoutId = void 0;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
async update(hash, automation, restart = true) {
|
|
185
|
-
await this.remove(hash, false);
|
|
186
|
-
await this.add(automation, false);
|
|
187
|
-
if (restart) await this.restart();
|
|
188
|
-
}
|
|
189
|
-
async trigger(automation) {
|
|
190
|
-
const wrapper = new SentinelIntervalAutomationWrapper(automation);
|
|
191
|
-
await this.remove(await wrapper.dataHash(), false);
|
|
192
|
-
wrapper.next();
|
|
193
|
-
await this.add(wrapper.payload, false);
|
|
194
|
-
const triggerResult = await this.sentinel.report();
|
|
195
|
-
this.onTriggerResult?.(triggerResult);
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
// src/MemorySentinel.ts
|
|
200
|
-
var MemorySentinel = class extends import_sentinel_abstract.AbstractSentinel {
|
|
201
|
-
static {
|
|
202
|
-
__name(this, "MemorySentinel");
|
|
203
|
-
}
|
|
204
|
-
static configSchemas = [
|
|
205
|
-
...super.configSchemas,
|
|
206
|
-
import_sentinel_model2.SentinelConfigSchema
|
|
207
|
-
];
|
|
208
|
-
static defaultConfigSchema = import_sentinel_model2.SentinelConfigSchema;
|
|
209
|
-
runner;
|
|
210
|
-
async reportHandler(inPayloads = []) {
|
|
211
|
-
await this.started("throw");
|
|
212
|
-
this.logger?.debug(`reportHandler:in: ${JSON.stringify(inPayloads)}`);
|
|
213
|
-
const job = await this.jobPromise;
|
|
214
|
-
let index = 0;
|
|
215
|
-
let previousResults = {};
|
|
216
|
-
while (index < job.tasks.length) {
|
|
217
|
-
const generatedPayloads = await this.runJob(job.tasks[index], previousResults, inPayloads);
|
|
218
|
-
previousResults = generatedPayloads;
|
|
219
|
-
index++;
|
|
220
|
-
}
|
|
221
|
-
const result = Object.values(previousResults).flat();
|
|
222
|
-
this.logger?.debug(`reportHandler:out: ${JSON.stringify(result)}`);
|
|
223
|
-
return result;
|
|
224
|
-
}
|
|
225
|
-
async start(timeout) {
|
|
226
|
-
if (await super.start(timeout)) {
|
|
227
|
-
if ((this.config.automations?.length ?? 0) > 0) {
|
|
228
|
-
this.runner = new SentinelRunner(this, this.config.automations);
|
|
229
|
-
this.runner.start();
|
|
230
|
-
}
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
async stop(timeout) {
|
|
236
|
-
if (this.runner) {
|
|
237
|
-
this.runner.stop();
|
|
238
|
-
this.runner = void 0;
|
|
239
|
-
}
|
|
240
|
-
return await super.stop(timeout);
|
|
241
|
-
}
|
|
242
|
-
async inputAddresses(input) {
|
|
243
|
-
if (Array.isArray(input)) {
|
|
244
|
-
return (await Promise.all(input.map(async (inputItem) => await this.inputAddresses(inputItem)))).flat();
|
|
245
|
-
} else {
|
|
246
|
-
const resolved = await this.resolve(input);
|
|
247
|
-
return resolved ? [
|
|
248
|
-
resolved.address
|
|
249
|
-
] : [];
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
processPreviousResults(payloads, inputs) {
|
|
253
|
-
return inputs.flatMap((input) => payloads[input] ?? []);
|
|
254
|
-
}
|
|
255
|
-
async runJob(tasks, previousResults, inPayloads) {
|
|
256
|
-
await this.emit("jobStart", {
|
|
257
|
-
inPayloads,
|
|
258
|
-
module: this
|
|
259
|
-
});
|
|
260
|
-
this.logger?.debug(`runJob:tasks: ${JSON.stringify(tasks.length)}`);
|
|
261
|
-
this.logger?.debug(`runJob:previous: ${JSON.stringify(previousResults)}`);
|
|
262
|
-
this.logger?.debug(`runJob:in: ${JSON.stringify(inPayloads)}`);
|
|
263
|
-
const results = await Promise.allSettled(tasks?.map(async (task) => {
|
|
264
|
-
const input = task.input ?? false;
|
|
265
|
-
const inPayloadsFound = input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input));
|
|
266
|
-
const witness = (0, import_witness_model.asWitnessInstance)(task.module);
|
|
267
|
-
if (witness) {
|
|
268
|
-
await this.emit("taskStart", {
|
|
269
|
-
address: witness.address,
|
|
270
|
-
inPayloads: inPayloadsFound,
|
|
271
|
-
module: this
|
|
272
|
-
});
|
|
273
|
-
const observed = await witness.observe(inPayloadsFound);
|
|
274
|
-
this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`);
|
|
275
|
-
await this.emit("taskEnd", {
|
|
276
|
-
address: witness.address,
|
|
277
|
-
inPayloads: inPayloadsFound,
|
|
278
|
-
module: this,
|
|
279
|
-
outPayloads: observed
|
|
280
|
-
});
|
|
281
|
-
return [
|
|
282
|
-
witness.address,
|
|
283
|
-
observed
|
|
284
|
-
];
|
|
285
|
-
}
|
|
286
|
-
const diviner = (0, import_diviner_model.asDivinerInstance)(task.module);
|
|
287
|
-
if (diviner) {
|
|
288
|
-
await this.emit("taskStart", {
|
|
289
|
-
address: diviner.address,
|
|
290
|
-
inPayloads: inPayloadsFound,
|
|
291
|
-
module: this
|
|
292
|
-
});
|
|
293
|
-
const divined = await diviner.divine(inPayloadsFound);
|
|
294
|
-
this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`);
|
|
295
|
-
await this.emit("taskEnd", {
|
|
296
|
-
address: diviner.address,
|
|
297
|
-
inPayloads: inPayloadsFound,
|
|
298
|
-
module: this,
|
|
299
|
-
outPayloads: divined
|
|
300
|
-
});
|
|
301
|
-
return [
|
|
302
|
-
diviner.address,
|
|
303
|
-
divined
|
|
304
|
-
];
|
|
305
|
-
}
|
|
306
|
-
const sentinel = (0, import_sentinel_model2.asSentinelInstance)(task.module);
|
|
307
|
-
if (sentinel) {
|
|
308
|
-
await this.emit("taskStart", {
|
|
309
|
-
address: sentinel.address,
|
|
310
|
-
inPayloads: inPayloadsFound,
|
|
311
|
-
module: this
|
|
312
|
-
});
|
|
313
|
-
const reported = await sentinel.report(inPayloadsFound);
|
|
314
|
-
this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`);
|
|
315
|
-
await this.emit("taskEnd", {
|
|
316
|
-
address: sentinel.address,
|
|
317
|
-
inPayloads: inPayloadsFound,
|
|
318
|
-
module: this,
|
|
319
|
-
outPayloads: reported
|
|
320
|
-
});
|
|
321
|
-
return [
|
|
322
|
-
sentinel.address,
|
|
323
|
-
reported
|
|
324
|
-
];
|
|
325
|
-
}
|
|
326
|
-
throw new Error("Unsupported module type");
|
|
327
|
-
}));
|
|
328
|
-
const finalResult = {};
|
|
329
|
-
for (const result of results.filter(import_promise.fulfilled)) {
|
|
330
|
-
const [address, payloads] = result.value;
|
|
331
|
-
finalResult[address] = finalResult[address] ?? [];
|
|
332
|
-
finalResult[address].push(...payloads);
|
|
333
|
-
}
|
|
334
|
-
if (this.throwErrors) {
|
|
335
|
-
const errors = results.filter(import_promise.rejected).map((result) => result.reason);
|
|
336
|
-
if (errors.length > 0) {
|
|
337
|
-
throw new Error("At least one module failed");
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
this.logger?.debug(`generateResults:out: ${JSON.stringify(finalResult)}`);
|
|
341
|
-
await this.emit("jobEnd", {
|
|
342
|
-
finalResult,
|
|
343
|
-
inPayloads,
|
|
344
|
-
module: this
|
|
345
|
-
});
|
|
346
|
-
return finalResult;
|
|
347
|
-
}
|
|
348
|
-
};
|
|
1
|
+
"use strict";var y=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var c=(i,t)=>y(i,"name",{value:t,configurable:!0});var R=(i,t)=>{for(var e in t)y(i,e,{get:t[e],enumerable:!0})},$=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _(t))!J.call(i,r)&&r!==e&&y(i,r,{get:()=>t[r],enumerable:!(s=E(t,r))||s.enumerable});return i};var A=i=>$(y({},"__esModule",{value:!0}),i);var F={};R(F,{MemorySentinel:()=>S,SentinelIntervalAutomationWrapper:()=>f,SentinelRunner:()=>g});module.exports=A(F);var w=require("@xylabs/promise"),v=require("@xyo-network/diviner-model"),O=require("@xyo-network/sentinel-abstract"),p=require("@xyo-network/sentinel-model"),x=require("@xyo-network/witness-model");var N=require("@xylabs/assert"),P=require("@xylabs/forget"),T=require("@xyo-network/payload-builder"),I=require("@xyo-network/sentinel-model");var b=require("@xyo-network/payload-wrapper");var f=class extends b.PayloadWrapper{static{c(this,"SentinelIntervalAutomationWrapper")}constructor(t){super(t)}get frequencyMillis(){let t=this.payload.frequency;if(t===void 0)return Number.POSITIVE_INFINITY;switch(this.payload.frequencyUnits??"hour"){case"second":return t*1e3;case"minute":return t*60*1e3;case"hour":return t*60*60*1e3;case"day":return t*24*60*60*1e3;default:return Number.POSITIVE_INFINITY}}get remaining(){return this.payload.remaining??Number.POSITIVE_INFINITY}next(){let t=Date.now(),e=this.payload?.start??t,r=Math.max(e,t)+this.frequencyMillis;return this.setStart(r),this.consumeRemaining(),this.checkEnd(),this}checkEnd(){this.payload.start>(this.payload.end??Number.POSITIVE_INFINITY)&&this.setStart(Number.POSITIVE_INFINITY)}consumeRemaining(t=1){let e=Math.max(this.remaining-t,0);this.setRemaining(e),e<=0&&this.setStart(Number.POSITIVE_INFINITY)}setRemaining(t){this.payload.remaining=t}setStart(t){this.payload.start=t}};var g=class{static{c(this,"SentinelRunner")}_automations={};onTriggerResult;sentinel;timeoutId;constructor(t,e,s){if(this.sentinel=t,this.onTriggerResult=s,e)for(let r of e)(0,P.forget)(this.add(r))}get automations(){return this._automations}get next(){return Object.values(this._automations).reduce((t,e)=>(0,I.isSentinelIntervalAutomation)(e)&&(0,I.isSentinelIntervalAutomation)(t)?e.start<(t?.start??Number.POSITIVE_INFINITY)?e:t:e,void 0)}async add(t,e=!0){let s=await T.PayloadBuilder.dataHash(t);return this._automations[s]=t,e&&await this.restart(),s}find(t){Object.entries(this._automations).find(([e])=>e===t)}async remove(t,e=!0){delete this._automations[t],e&&await this.restart()}removeAll(){this.stop(),this._automations={}}restart(){this.stop(),this.start()}start(){(0,N.assertEx)(this.timeoutId===void 0,()=>"Already started");let t=this.next;if((0,I.isSentinelIntervalAutomation)(t)){let e=Date.now(),s=Math.max(t.start??e,e),r=Math.max(s-e,0);r<Number.POSITIVE_INFINITY&&(this.timeoutId=setTimeout(async()=>{try{await this.trigger(t),this.stop()}finally{this.start()}},r))}}stop(){this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=void 0)}async update(t,e,s=!0){await this.remove(t,!1),await this.add(e,!1),s&&await this.restart()}async trigger(t){let e=new f(t);await this.remove(await e.dataHash(),!1),e.next(),await this.add(e.payload,!1);let s=await this.sentinel.report();this.onTriggerResult?.(s)}};var S=class extends O.AbstractSentinel{static{c(this,"MemorySentinel")}static configSchemas=[...super.configSchemas,p.SentinelConfigSchema];static defaultConfigSchema=p.SentinelConfigSchema;runner;async reportHandler(t=[]){await this.started("throw"),this.logger?.debug(`reportHandler:in: ${JSON.stringify(t)}`);let e=await this.jobPromise,s=0,r={};for(;s<e.tasks.length;)r=await this.runJob(e.tasks[s],r,t),s++;let o=Object.values(r).flat();return this.logger?.debug(`reportHandler:out: ${JSON.stringify(o)}`),o}async start(t){return await super.start(t)?((this.config.automations?.length??0)>0&&(this.runner=new g(this,this.config.automations),this.runner.start()),!0):!1}async stop(t){return this.runner&&(this.runner.stop(),this.runner=void 0),await super.stop(t)}async inputAddresses(t){if(Array.isArray(t))return(await Promise.all(t.map(async e=>await this.inputAddresses(e)))).flat();{let e=await this.resolve(t);return e?[e.address]:[]}}processPreviousResults(t,e){return e.flatMap(s=>t[s]??[])}async runJob(t,e,s){await this.emit("jobStart",{inPayloads:s,module:this}),this.logger?.debug(`runJob:tasks: ${JSON.stringify(t.length)}`),this.logger?.debug(`runJob:previous: ${JSON.stringify(e)}`),this.logger?.debug(`runJob:in: ${JSON.stringify(s)}`);let r=await Promise.allSettled(t?.map(async u=>{let d=u.input??!1,a=d===!0?s:d===!1?[]:this.processPreviousResults(e,await this.inputAddresses(d)),l=(0,x.asWitnessInstance)(u.module);if(l){await this.emit("taskStart",{address:l.address,inPayloads:a,module:this});let n=await l.observe(a);return this.logger?.debug(`observed [${l.id}]: ${JSON.stringify(n)}`),await this.emit("taskEnd",{address:l.address,inPayloads:a,module:this,outPayloads:n}),[l.address,n]}let h=(0,v.asDivinerInstance)(u.module);if(h){await this.emit("taskStart",{address:h.address,inPayloads:a,module:this});let n=await h.divine(a);return this.logger?.debug(`divined [${h.id}]: ${JSON.stringify(n)}`),await this.emit("taskEnd",{address:h.address,inPayloads:a,module:this,outPayloads:n}),[h.address,n]}let m=(0,p.asSentinelInstance)(u.module);if(m){await this.emit("taskStart",{address:m.address,inPayloads:a,module:this});let n=await m.report(a);return this.logger?.debug(`reported [${m.id}]: ${JSON.stringify(n)}`),await this.emit("taskEnd",{address:m.address,inPayloads:a,module:this,outPayloads:n}),[m.address,n]}throw new Error("Unsupported module type")})),o={};for(let u of r.filter(w.fulfilled)){let[d,a]=u.value;o[d]=o[d]??[],o[d].push(...a)}if(this.throwErrors&&r.filter(w.rejected).map(d=>d.reason).length>0)throw new Error("At least one module failed");return this.logger?.debug(`generateResults:out: ${JSON.stringify(o)}`),await this.emit("jobEnd",{finalResult:o,inPayloads:s,module:this}),o}};
|
|
349
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/MemorySentinel.ts","../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["export * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\n","import { Address } from '@xylabs/hex'\nimport { fulfilled, rejected } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema, ModuleIdentifier } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport {\n asSentinelInstance,\n ResolvedTask,\n SentinelConfig,\n SentinelConfigSchema,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nimport { SentinelRunner } from './SentinelRunner'\n\nexport type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>\n\nexport class MemorySentinel<\n TParams extends MemorySentinelParams = MemorySentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, SentinelConfigSchema]\n static override readonly defaultConfigSchema: Schema = SentinelConfigSchema\n\n private runner?: SentinelRunner\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n this.logger?.debug(`reportHandler:in: ${JSON.stringify(inPayloads)}`)\n const job = await this.jobPromise\n\n let index = 0\n let previousResults: Record<Address, Payload[]> = {}\n while (index < job.tasks.length) {\n const generatedPayloads = await this.runJob(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n const result = Object.values(previousResults).flat()\n this.logger?.debug(`reportHandler:out: ${JSON.stringify(result)}`)\n return result\n }\n\n override async start(timeout?: number | undefined): Promise<boolean> {\n if (await super.start(timeout)) {\n if ((this.config.automations?.length ?? 0) > 0) {\n this.runner = new SentinelRunner(this, this.config.automations)\n 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 inputAddresses(input: ModuleIdentifier | ModuleIdentifier[]): Promise<Address[]> {\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 private async runJob(\n tasks: ResolvedTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n await this.emit('jobStart', { inPayloads, module: this })\n this.logger?.debug(`runJob:tasks: ${JSON.stringify(tasks.length)}`)\n this.logger?.debug(`runJob:previous: ${JSON.stringify(previousResults)}`)\n this.logger?.debug(`runJob:in: ${JSON.stringify(inPayloads)}`)\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const input = task.input ?? false\n const inPayloadsFound =\n input === true ? inPayloads\n : input === false ? []\n : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n const witness = asWitnessInstance(task.module)\n if (witness) {\n await this.emit('taskStart', { address: witness.address, inPayloads: inPayloadsFound, module: this })\n const observed = await witness.observe(inPayloadsFound)\n this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`)\n await this.emit('taskEnd', { address: witness.address, inPayloads: inPayloadsFound, module: this, outPayloads: observed })\n return [witness.address, observed]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n await this.emit('taskStart', { address: diviner.address, inPayloads: inPayloadsFound, module: this })\n const divined = await diviner.divine(inPayloadsFound)\n this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`)\n await this.emit('taskEnd', { address: diviner.address, inPayloads: inPayloadsFound, module: this, outPayloads: divined })\n return [diviner.address, divined]\n }\n const sentinel = asSentinelInstance(task.module)\n if (sentinel) {\n await this.emit('taskStart', { address: sentinel.address, inPayloads: inPayloadsFound, module: this })\n const reported = await sentinel.report(inPayloadsFound)\n this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`)\n await this.emit('taskEnd', { address: sentinel.address, inPayloads: inPayloadsFound, module: this, outPayloads: reported })\n return [sentinel.address, reported]\n }\n throw new Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n for (const result of results.filter(fulfilled)) {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n }\n if (this.throwErrors) {\n const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw new Error('At least one module failed')\n }\n }\n this.logger?.debug(`generateResults:out: ${JSON.stringify(finalResult)}`)\n await this.emit('jobEnd', { finalResult, inPayloads, module: this })\n return finalResult\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { forget } from '@xylabs/forget'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload } from '@xyo-network/payload-model'\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) forget(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 PayloadBuilder.dataHash(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 restart() {\n this.stop()\n this.start()\n }\n\n start() {\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 // eslint-disable-next-line @typescript-eslint/no-misused-promises\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 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.dataHash(), false)\n wrapper.next()\n await this.add(wrapper.payload, false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n // await this.start()\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\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.payload.frequency\n if (frequency === undefined) return Number.POSITIVE_INFINITY\n const frequencyUnits = this.payload.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.payload.remaining ?? Number.POSITIVE_INFINITY\n }\n\n next() {\n const now = Date.now()\n const previousStart = this.payload?.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.payload.start > (this.payload.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.payload.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.payload.start = start\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACCA,qBAAoC;AACpC,2BAAkC;AAGlC,+BAAiC;AACjC,IAAAA,yBAQO;AACP,2BAAkC;;;ACflC,oBAAyB;AACzB,oBAAuB;AACvB,6BAA+B;AAE/B,4BAKO;;;ACTP,6BAA+B;AAGxB,IAAMC,oCAAN,cAEGC,sCAAAA;EALV,OAKUA;;;EACRC,YAAYC,SAAY;AACtB,UAAMA,OAAAA;EACR;EAEA,IAAcC,kBAAkB;AAC9B,UAAMC,YAAY,KAAKF,QAAQE;AAC/B,QAAIA,cAAcC,OAAW,QAAOC,OAAOC;AAC3C,UAAMC,iBAAiB,KAAKN,QAAQM;AACpC,YAAQA,kBAA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B;UAASmB;;MAC3B;AACA,YAAME,eAAWC,2CAAmBb,KAAKH,MAAM;AAC/C,UAAIe,UAAU;AACZ,cAAM,KAAKhB,KAAK,aAAa;UAAEL,SAASqB,SAASrB;UAASnC,YAAY6C;UAAiBJ,QAAQ;QAAK,CAAA;AACpG,cAAMiB,WAAW,MAAMF,SAASG,OAAOd,eAAAA;AACvC,aAAK3C,QAAQC,MAAM,aAAaqD,SAASN,EAAE,MAAM9C,KAAKC,UAAUqD,QAAAA,CAAAA,EAAW;AAC3E,cAAM,KAAKlB,KAAK,WAAW;UAAEL,SAASqB,SAASrB;UAASnC,YAAY6C;UAAiBJ,QAAQ;UAAMU,aAAaO;QAAS,CAAA;AACzH,eAAO;UAACF,SAASrB;UAASuB;;MAC5B;AACA,YAAM,IAAIE,MAAM,yBAAA;IAClB,CAAA,CAAA;AAEF,UAAMC,cAA0C,CAAC;AACjD,eAAW/C,UAAU4B,QAAQoB,OAAOC,wBAAAA,GAAY;AAC9C,YAAM,CAAC5B,SAASE,QAAAA,IAAYvB,OAAOkD;AACnCH,kBAAY1B,OAAAA,IAAW0B,YAAY1B,OAAAA,KAAY,CAAA;AAC/C0B,kBAAY1B,OAAAA,EAAS8B,KAAI,GAAI5B,QAAAA;IAC/B;AACA,QAAI,KAAK6B,aAAa;AACpB,YAAMC,SAASzB,QAAQoB,OAAOM,uBAAAA,EAAUrC,IAAI,CAACjB,WAAWA,OAAOuD,MAAM;AACrE,UAAIF,OAAOxD,SAAS,GAAG;AACrB,cAAM,IAAIiD,MAAM,4BAAA;MAClB;IACF;AACA,SAAK1D,QAAQC,MAAM,wBAAwBC,KAAKC,UAAUwD,WAAAA,CAAAA,EAAc;AACxE,UAAM,KAAKrB,KAAK,UAAU;MAAEqB;MAAa7D;MAAYyC,QAAQ;IAAK,CAAA;AAClE,WAAOoB;EACT;AACF;","names":["import_sentinel_model","SentinelIntervalAutomationWrapper","PayloadWrapper","constructor","payload","frequencyMillis","frequency","undefined","Number","POSITIVE_INFINITY","frequencyUnits","remaining","next","now","Date","previousStart","start","Math","max","nextStart","setStart","consumeRemaining","checkEnd","end","count","setRemaining","SentinelRunner","_automations","onTriggerResult","sentinel","timeoutId","constructor","automations","automation","forget","add","next","Object","values","reduce","previous","current","isSentinelIntervalAutomation","start","Number","POSITIVE_INFINITY","undefined","restart","hash","PayloadBuilder","dataHash","find","entries","key","remove","removeAll","stop","assertEx","now","Date","Math","max","delay","setTimeout","trigger","clearTimeout","update","wrapper","SentinelIntervalAutomationWrapper","payload","triggerResult","report","MemorySentinel","AbstractSentinel","configSchemas","SentinelConfigSchema","defaultConfigSchema","runner","reportHandler","inPayloads","started","logger","debug","JSON","stringify","job","jobPromise","index","previousResults","tasks","length","generatedPayloads","runJob","result","Object","values","flat","start","timeout","config","automations","SentinelRunner","stop","undefined","inputAddresses","input","Array","isArray","Promise","all","map","inputItem","resolved","resolve","address","processPreviousResults","payloads","inputs","flatMap","emit","module","results","allSettled","task","inPayloadsFound","witness","asWitnessInstance","observed","observe","id","outPayloads","diviner","asDivinerInstance","divined","divine","sentinel","asSentinelInstance","reported","report","Error","finalResult","filter","fulfilled","value","push","throwErrors","errors","rejected","reason"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/MemorySentinel.ts","../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["export * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\n","import { Address } from '@xylabs/hex'\nimport { fulfilled, rejected } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema, ModuleIdentifier } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport {\n asSentinelInstance,\n ResolvedTask,\n SentinelConfig,\n SentinelConfigSchema,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nimport { SentinelRunner } from './SentinelRunner'\n\nexport type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>\n\nexport class MemorySentinel<\n TParams extends MemorySentinelParams = MemorySentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n> extends AbstractSentinel<TParams, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, SentinelConfigSchema]\n static override readonly defaultConfigSchema: Schema = SentinelConfigSchema\n\n private runner?: SentinelRunner\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n this.logger?.debug(`reportHandler:in: ${JSON.stringify(inPayloads)}`)\n const job = await this.jobPromise\n\n let index = 0\n let previousResults: Record<Address, Payload[]> = {}\n while (index < job.tasks.length) {\n const generatedPayloads = await this.runJob(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n const result = Object.values(previousResults).flat()\n this.logger?.debug(`reportHandler:out: ${JSON.stringify(result)}`)\n return result\n }\n\n override async start(timeout?: number | undefined): Promise<boolean> {\n if (await super.start(timeout)) {\n if ((this.config.automations?.length ?? 0) > 0) {\n this.runner = new SentinelRunner(this, this.config.automations)\n 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 inputAddresses(input: ModuleIdentifier | ModuleIdentifier[]): Promise<Address[]> {\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 private async runJob(\n tasks: ResolvedTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n await this.emit('jobStart', { inPayloads, module: this })\n this.logger?.debug(`runJob:tasks: ${JSON.stringify(tasks.length)}`)\n this.logger?.debug(`runJob:previous: ${JSON.stringify(previousResults)}`)\n this.logger?.debug(`runJob:in: ${JSON.stringify(inPayloads)}`)\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const input = task.input ?? false\n const inPayloadsFound =\n input === true ? inPayloads\n : input === false ? []\n : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n const witness = asWitnessInstance(task.module)\n if (witness) {\n await this.emit('taskStart', { address: witness.address, inPayloads: inPayloadsFound, module: this })\n const observed = await witness.observe(inPayloadsFound)\n this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`)\n await this.emit('taskEnd', { address: witness.address, inPayloads: inPayloadsFound, module: this, outPayloads: observed })\n return [witness.address, observed]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n await this.emit('taskStart', { address: diviner.address, inPayloads: inPayloadsFound, module: this })\n const divined = await diviner.divine(inPayloadsFound)\n this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`)\n await this.emit('taskEnd', { address: diviner.address, inPayloads: inPayloadsFound, module: this, outPayloads: divined })\n return [diviner.address, divined]\n }\n const sentinel = asSentinelInstance(task.module)\n if (sentinel) {\n await this.emit('taskStart', { address: sentinel.address, inPayloads: inPayloadsFound, module: this })\n const reported = await sentinel.report(inPayloadsFound)\n this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`)\n await this.emit('taskEnd', { address: sentinel.address, inPayloads: inPayloadsFound, module: this, outPayloads: reported })\n return [sentinel.address, reported]\n }\n throw new Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n for (const result of results.filter(fulfilled)) {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n }\n if (this.throwErrors) {\n const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw new Error('At least one module failed')\n }\n }\n this.logger?.debug(`generateResults:out: ${JSON.stringify(finalResult)}`)\n await this.emit('jobEnd', { finalResult, inPayloads, module: this })\n return finalResult\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { forget } from '@xylabs/forget'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload } from '@xyo-network/payload-model'\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) forget(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 PayloadBuilder.dataHash(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 restart() {\n this.stop()\n this.start()\n }\n\n start() {\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 // eslint-disable-next-line @typescript-eslint/no-misused-promises\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 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.dataHash(), false)\n wrapper.next()\n await this.add(wrapper.payload, false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n // await this.start()\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\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.payload.frequency\n if (frequency === undefined) return Number.POSITIVE_INFINITY\n const frequencyUnits = this.payload.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.payload.remaining ?? Number.POSITIVE_INFINITY\n }\n\n next() {\n const now = Date.now()\n const previousStart = this.payload?.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.payload.start > (this.payload.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.payload.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.payload.start = start\n }\n}\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,sCAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAL,GCCA,IAAAM,EAAoC,2BACpCC,EAAkC,sCAGlCC,EAAiC,0CACjCC,EAQO,uCACPC,EAAkC,sCCflC,IAAAC,EAAyB,0BACzBC,EAAuB,0BACvBC,EAA+B,wCAE/BC,EAKO,uCCTP,IAAAC,EAA+B,wCAGxB,IAAMC,EAAN,cAEGC,gBAAAA,CALV,MAKUA,CAAAA,EAAAA,0CACRC,YAAYC,EAAY,CACtB,MAAMA,CAAAA,CACR,CAEA,IAAcC,iBAAkB,CAC9B,IAAMC,EAAY,KAAKF,QAAQE,UAC/B,GAAIA,IAAcC,OAAW,OAAOC,OAAOC,kBAE3C,OADuB,KAAKL,QAAQM,gBACV,OAAA,CACxB,IAAK,SACH,OAAOJ,EAAY,IAErB,IAAK,SACH,OAAOA,EAAY,GAAK,IAE1B,IA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IAAIE,MAAM,yBAAA,CAClB,CAAA,CAAA,EAEIC,EAA0C,CAAC,EACjD,QAAW/C,KAAU4B,EAAQoB,OAAOC,WAAAA,EAAY,CAC9C,GAAM,CAAC5B,EAASE,CAAAA,EAAYvB,EAAOkD,MACnCH,EAAY1B,CAAAA,EAAW0B,EAAY1B,CAAAA,GAAY,CAAA,EAC/C0B,EAAY1B,CAAAA,EAAS8B,KAAI,GAAI5B,CAAAA,CAC/B,CACA,GAAI,KAAK6B,aACQxB,EAAQoB,OAAOK,UAAAA,EAAUpC,IAAKjB,GAAWA,EAAOsD,MAAM,EAC1DxD,OAAS,EAClB,MAAM,IAAIgD,MAAM,4BAAA,EAGpB,YAAKzD,QAAQC,MAAM,wBAAwBC,KAAKC,UAAUuD,CAAAA,CAAAA,EAAc,EACxE,MAAM,KAAKrB,KAAK,SAAU,CAAEqB,YAAAA,EAAa5D,WAAAA,EAAYwC,OAAQ,IAAK,CAAA,EAC3DoB,CACT,CACF","names":["src_exports","__export","MemorySentinel","SentinelIntervalAutomationWrapper","SentinelRunner","__toCommonJS","import_promise","import_diviner_model","import_sentinel_abstract","import_sentinel_model","import_witness_model","import_assert","import_forget","import_payload_builder","import_sentinel_model","import_payload_wrapper","SentinelIntervalAutomationWrapper","PayloadWrapper","constructor","payload","frequencyMillis","frequency","undefined","Number","POSITIVE_INFINITY","frequencyUnits","remaining","next","now","Date","previousStart","start","nextStart","Math","max","setStart","consumeRemaining","checkEnd","end","count","setRemaining","SentinelRunner","_automations","onTriggerResult","sentinel","timeoutId","constructor","automations","automation","forget","add","next","Object","values","reduce","previous","current","isSentinelIntervalAutomation","start","Number","POSITIVE_INFINITY","undefined","restart","hash","PayloadBuilder","dataHash","find","entries","key","remove","removeAll","stop","assertEx","now","Date","Math","max","delay","setTimeout","trigger","clearTimeout","update","wrapper","SentinelIntervalAutomationWrapper","payload","triggerResult","report","MemorySentinel","AbstractSentinel","configSchemas","SentinelConfigSchema","defaultConfigSchema","runner","reportHandler","inPayloads","started","logger","debug","JSON","stringify","job","jobPromise","index","previousResults","tasks","length","runJob","result","Object","values","flat","start","timeout","config","automations","SentinelRunner","stop","undefined","inputAddresses","input","Array","isArray","Promise","all","map","inputItem","resolved","resolve","address","processPreviousResults","payloads","inputs","flatMap","emit","module","results","allSettled","task","inPayloadsFound","witness","asWitnessInstance","observed","observe","id","outPayloads","diviner","asDivinerInstance","divined","divine","sentinel","asSentinelInstance","reported","report","Error","finalResult","filter","fulfilled","value","push","throwErrors","rejected","reason"]}
|