@xyo-network/sentinel 2.75.15 → 2.75.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/docs.json +155 -155
  2. package/package.json +28 -28
  3. package/dist/browser/AbstractSentinel.cjs +0 -89
  4. package/dist/browser/AbstractSentinel.cjs.map +0 -1
  5. package/dist/browser/AbstractSentinel.js +0 -70
  6. package/dist/browser/AbstractSentinel.js.map +0 -1
  7. package/dist/browser/Automation.cjs +0 -27
  8. package/dist/browser/Automation.cjs.map +0 -1
  9. package/dist/browser/Automation.js +0 -6
  10. package/dist/browser/Automation.js.map +0 -1
  11. package/dist/browser/MemorySentinel.cjs +0 -125
  12. package/dist/browser/MemorySentinel.cjs.map +0 -1
  13. package/dist/browser/MemorySentinel.js +0 -109
  14. package/dist/browser/MemorySentinel.js.map +0 -1
  15. package/dist/browser/SentinelIntervalAutomationWrapper.cjs +0 -68
  16. package/dist/browser/SentinelIntervalAutomationWrapper.cjs.map +0 -1
  17. package/dist/browser/SentinelIntervalAutomationWrapper.js +0 -47
  18. package/dist/browser/SentinelIntervalAutomationWrapper.js.map +0 -1
  19. package/dist/browser/SentinelRunner.cjs +0 -157
  20. package/dist/browser/SentinelRunner.cjs.map +0 -1
  21. package/dist/browser/SentinelRunner.js +0 -136
  22. package/dist/browser/SentinelRunner.js.map +0 -1
  23. package/dist/browser/Wrapper.cjs +0 -45
  24. package/dist/browser/Wrapper.cjs.map +0 -1
  25. package/dist/browser/Wrapper.js +0 -28
  26. package/dist/browser/Wrapper.js.map +0 -1
  27. package/dist/node/AbstractSentinel.js +0 -95
  28. package/dist/node/AbstractSentinel.js.map +0 -1
  29. package/dist/node/AbstractSentinel.mjs +0 -72
  30. package/dist/node/AbstractSentinel.mjs.map +0 -1
  31. package/dist/node/Automation.js +0 -31
  32. package/dist/node/Automation.js.map +0 -1
  33. package/dist/node/Automation.mjs +0 -6
  34. package/dist/node/Automation.mjs.map +0 -1
  35. package/dist/node/MemorySentinel.js +0 -131
  36. package/dist/node/MemorySentinel.js.map +0 -1
  37. package/dist/node/MemorySentinel.mjs +0 -111
  38. package/dist/node/MemorySentinel.mjs.map +0 -1
  39. package/dist/node/SentinelIntervalAutomationWrapper.js +0 -72
  40. package/dist/node/SentinelIntervalAutomationWrapper.js.map +0 -1
  41. package/dist/node/SentinelIntervalAutomationWrapper.mjs +0 -47
  42. package/dist/node/SentinelIntervalAutomationWrapper.mjs.map +0 -1
  43. package/dist/node/SentinelRunner.js +0 -162
  44. package/dist/node/SentinelRunner.js.map +0 -1
  45. package/dist/node/SentinelRunner.mjs +0 -137
  46. package/dist/node/SentinelRunner.mjs.map +0 -1
  47. package/dist/node/Wrapper.js +0 -49
  48. package/dist/node/Wrapper.js.map +0 -1
  49. package/dist/node/Wrapper.mjs +0 -28
  50. package/dist/node/Wrapper.mjs.map +0 -1
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/SentinelIntervalAutomationWrapper.ts
21
- var SentinelIntervalAutomationWrapper_exports = {};
22
- __export(SentinelIntervalAutomationWrapper_exports, {
23
- SentinelIntervalAutomationWrapper: () => SentinelIntervalAutomationWrapper
24
- });
25
- module.exports = __toCommonJS(SentinelIntervalAutomationWrapper_exports);
26
- var import_payload_wrapper = require("@xyo-network/payload-wrapper");
27
- var SentinelIntervalAutomationWrapper = class extends import_payload_wrapper.PayloadWrapper {
28
- constructor(payload) {
29
- super(payload);
30
- }
31
- get frequencyMillis() {
32
- const frequency = this.payload().frequency;
33
- if (frequency === void 0)
34
- return Infinity;
35
- switch (this.payload().frequencyUnits ?? "hour") {
36
- case "second":
37
- return frequency * 1e3;
38
- case "minute":
39
- return frequency * 60 * 1e3;
40
- case "hour":
41
- return frequency * 60 * 60 * 1e3;
42
- case "day":
43
- return frequency * 24 * 60 * 60 * 1e3;
44
- }
45
- }
46
- get remaining() {
47
- return this.payload().remaining ?? Infinity;
48
- }
49
- next() {
50
- this.payload().start = this.payload().start + this.frequencyMillis;
51
- this.consumeRemaining();
52
- this.checkEnd();
53
- return this;
54
- }
55
- checkEnd() {
56
- if (this.payload().start > (this.payload().end ?? Infinity)) {
57
- this.payload().start = Infinity;
58
- }
59
- }
60
- consumeRemaining(count = 1) {
61
- const remaining = this.remaining - count;
62
- this.payload().remaining = remaining;
63
- if (remaining <= 0) {
64
- this.payload().start = Infinity;
65
- }
66
- }
67
- };
68
- //# sourceMappingURL=SentinelIntervalAutomationWrapper.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.payload().frequency\n if (frequency === undefined) return Infinity\n switch (this.payload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.payload().start = this.payload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload().start > (this.payload().end ?? Infinity)) {\n this.payload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.payload().remaining = remaining\n\n if (remaining <= 0) {\n this.payload().start = Infinity\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA+B;AAIxB,IAAM,oCAAN,cAEG,sCAAkB;AAAA,EAC1B,YAAY,SAAY;AACtB,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAc,kBAAkB;AAC9B,UAAM,YAAY,KAAK,QAAQ,EAAE;AACjC,QAAI,cAAc;AAAW,aAAO;AACpC,YAAQ,KAAK,QAAQ,EAAE,kBAAkB,QAAQ;AAAA,MAC/C,KAAK;AACH,eAAO,YAAY;AAAA,MACrB,KAAK;AACH,eAAO,YAAY,KAAK;AAAA,MAC1B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK;AAAA,MAC/B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK,KAAK;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,IAAc,YAAY;AAExB,WAAO,KAAK,QAAQ,EAAE,aAAa;AAAA,EACrC;AAAA,EAEA,OAAO;AACL,SAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,EAAE,QAAQ,KAAK;AACnD,SAAK,iBAAiB;AACtB,SAAK,SAAS;AACd,WAAO;AAAA,EACT;AAAA,EAEU,WAAW;AACnB,QAAI,KAAK,QAAQ,EAAE,SAAS,KAAK,QAAQ,EAAE,OAAO,WAAW;AAC3D,WAAK,QAAQ,EAAE,QAAQ;AAAA,IACzB;AAAA,EACF;AAAA,EAEU,iBAAiB,QAAQ,GAAG;AACpC,UAAM,YAAY,KAAK,YAAY;AACnC,SAAK,QAAQ,EAAE,YAAY;AAE3B,QAAI,aAAa,GAAG;AAClB,WAAK,QAAQ,EAAE,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
@@ -1,47 +0,0 @@
1
- // src/SentinelIntervalAutomationWrapper.ts
2
- import { PayloadWrapper } from "@xyo-network/payload-wrapper";
3
- var SentinelIntervalAutomationWrapper = class extends PayloadWrapper {
4
- constructor(payload) {
5
- super(payload);
6
- }
7
- get frequencyMillis() {
8
- const frequency = this.payload().frequency;
9
- if (frequency === void 0)
10
- return Infinity;
11
- switch (this.payload().frequencyUnits ?? "hour") {
12
- case "second":
13
- return frequency * 1e3;
14
- case "minute":
15
- return frequency * 60 * 1e3;
16
- case "hour":
17
- return frequency * 60 * 60 * 1e3;
18
- case "day":
19
- return frequency * 24 * 60 * 60 * 1e3;
20
- }
21
- }
22
- get remaining() {
23
- return this.payload().remaining ?? Infinity;
24
- }
25
- next() {
26
- this.payload().start = this.payload().start + this.frequencyMillis;
27
- this.consumeRemaining();
28
- this.checkEnd();
29
- return this;
30
- }
31
- checkEnd() {
32
- if (this.payload().start > (this.payload().end ?? Infinity)) {
33
- this.payload().start = Infinity;
34
- }
35
- }
36
- consumeRemaining(count = 1) {
37
- const remaining = this.remaining - count;
38
- this.payload().remaining = remaining;
39
- if (remaining <= 0) {
40
- this.payload().start = Infinity;
41
- }
42
- }
43
- };
44
- export {
45
- SentinelIntervalAutomationWrapper
46
- };
47
- //# sourceMappingURL=SentinelIntervalAutomationWrapper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.payload().frequency\n if (frequency === undefined) return Infinity\n switch (this.payload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.payload().start = this.payload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload().start > (this.payload().end ?? Infinity)) {\n this.payload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.payload().remaining = remaining\n\n if (remaining <= 0) {\n this.payload().start = Infinity\n }\n }\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAIxB,IAAM,oCAAN,cAEG,eAAkB;AAAA,EAC1B,YAAY,SAAY;AACtB,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAc,kBAAkB;AAC9B,UAAM,YAAY,KAAK,QAAQ,EAAE;AACjC,QAAI,cAAc;AAAW,aAAO;AACpC,YAAQ,KAAK,QAAQ,EAAE,kBAAkB,QAAQ;AAAA,MAC/C,KAAK;AACH,eAAO,YAAY;AAAA,MACrB,KAAK;AACH,eAAO,YAAY,KAAK;AAAA,MAC1B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK;AAAA,MAC/B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK,KAAK;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,IAAc,YAAY;AAExB,WAAO,KAAK,QAAQ,EAAE,aAAa;AAAA,EACrC;AAAA,EAEA,OAAO;AACL,SAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,EAAE,QAAQ,KAAK;AACnD,SAAK,iBAAiB;AACtB,SAAK,SAAS;AACd,WAAO;AAAA,EACT;AAAA,EAEU,WAAW;AACnB,QAAI,KAAK,QAAQ,EAAE,SAAS,KAAK,QAAQ,EAAE,OAAO,WAAW;AAC3D,WAAK,QAAQ,EAAE,QAAQ;AAAA,IACzB;AAAA,EACF;AAAA,EAEU,iBAAiB,QAAQ,GAAG;AACpC,UAAM,YAAY,KAAK,YAAY;AACnC,SAAK,QAAQ,EAAE,YAAY;AAE3B,QAAI,aAAa,GAAG;AAClB,WAAK,QAAQ,EAAE,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
@@ -1,157 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/SentinelRunner.ts
21
- var SentinelRunner_exports = {};
22
- __export(SentinelRunner_exports, {
23
- SentinelRunner: () => SentinelRunner
24
- });
25
- module.exports = __toCommonJS(SentinelRunner_exports);
26
- var import_assert = require("@xylabs/assert");
27
- var import_payload_wrapper2 = require("@xyo-network/payload-wrapper");
28
-
29
- // src/SentinelIntervalAutomationWrapper.ts
30
- var import_payload_wrapper = require("@xyo-network/payload-wrapper");
31
- var SentinelIntervalAutomationWrapper = class extends import_payload_wrapper.PayloadWrapper {
32
- constructor(payload) {
33
- super(payload);
34
- }
35
- get frequencyMillis() {
36
- const frequency = this.payload().frequency;
37
- if (frequency === void 0)
38
- return Infinity;
39
- switch (this.payload().frequencyUnits ?? "hour") {
40
- case "second":
41
- return frequency * 1e3;
42
- case "minute":
43
- return frequency * 60 * 1e3;
44
- case "hour":
45
- return frequency * 60 * 60 * 1e3;
46
- case "day":
47
- return frequency * 24 * 60 * 60 * 1e3;
48
- }
49
- }
50
- get remaining() {
51
- return this.payload().remaining ?? Infinity;
52
- }
53
- next() {
54
- this.payload().start = this.payload().start + this.frequencyMillis;
55
- this.consumeRemaining();
56
- this.checkEnd();
57
- return this;
58
- }
59
- checkEnd() {
60
- if (this.payload().start > (this.payload().end ?? Infinity)) {
61
- this.payload().start = Infinity;
62
- }
63
- }
64
- consumeRemaining(count = 1) {
65
- const remaining = this.remaining - count;
66
- this.payload().remaining = remaining;
67
- if (remaining <= 0) {
68
- this.payload().start = Infinity;
69
- }
70
- }
71
- };
72
-
73
- // src/SentinelRunner.ts
74
- var SentinelRunner = class {
75
- _automations = {};
76
- onTriggerResult;
77
- sentinel;
78
- timeoutId;
79
- constructor(sentinel, automations, onTriggerResult) {
80
- this.sentinel = sentinel;
81
- this.onTriggerResult = onTriggerResult;
82
- automations?.forEach((automation) => this.add(automation));
83
- }
84
- get automations() {
85
- return this._automations;
86
- }
87
- get next() {
88
- return Object.values(this._automations).reduce((previous, current) => {
89
- if (current.type === "interval") {
90
- return current.start < (previous?.start ?? Infinity) ? current : previous;
91
- }
92
- }, void 0);
93
- }
94
- async add(automation, restart = true) {
95
- const hash = await import_payload_wrapper2.PayloadWrapper.hashAsync(automation);
96
- this._automations[hash] = automation;
97
- if (restart)
98
- await this.restart();
99
- return hash;
100
- }
101
- find(hash) {
102
- Object.entries(this._automations).find(([key]) => key === hash);
103
- }
104
- async remove(hash, restart = true) {
105
- delete this._automations[hash];
106
- if (restart)
107
- await this.restart();
108
- }
109
- removeAll() {
110
- this.stop();
111
- this._automations = {};
112
- }
113
- async restart() {
114
- this.stop();
115
- await this.start();
116
- }
117
- async start() {
118
- (0, import_assert.assertEx)(this.timeoutId === void 0, "Already started");
119
- const automation = this.next;
120
- if (automation) {
121
- const delay = automation.start - Date.now();
122
- if (delay < 0) {
123
- await this.trigger(automation);
124
- } else {
125
- this.timeoutId = setTimeout(
126
- async () => {
127
- this.timeoutId = void 0;
128
- await this.start();
129
- },
130
- delay > 0 ? delay : 0
131
- );
132
- }
133
- }
134
- }
135
- stop() {
136
- if (this.timeoutId) {
137
- clearTimeout(this.timeoutId);
138
- this.timeoutId = void 0;
139
- }
140
- }
141
- async update(hash, automation, restart = true) {
142
- await this.remove(hash, false);
143
- await this.add(automation, false);
144
- if (restart)
145
- await this.restart();
146
- }
147
- async trigger(automation) {
148
- const wrapper = new SentinelIntervalAutomationWrapper(automation);
149
- await this.remove(await wrapper.hashAsync(), false);
150
- wrapper.next();
151
- await this.add(wrapper.payload(), false);
152
- const triggerResult = await this.sentinel.report();
153
- this.onTriggerResult?.(triggerResult);
154
- await this.start();
155
- }
156
- };
157
- //# sourceMappingURL=SentinelRunner.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nimport { SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation'\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n automations?.forEach((automation) => this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n return Object.values(this._automations).reduce<SentinelIntervalAutomationPayload | undefined>((previous, current) => {\n if (current.type === 'interval') {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (automation) {\n const delay = automation.start - Date.now()\n if (delay < 0) {\n //automation is due, just do it\n await this.trigger(automation)\n } else {\n this.timeoutId = setTimeout(\n async () => {\n this.timeoutId = undefined\n await this.start()\n },\n delay > 0 ? delay : 0,\n )\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.payload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n await this.start()\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.payload().frequency\n if (frequency === undefined) return Infinity\n switch (this.payload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.payload().start = this.payload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload().start > (this.payload().end ?? Infinity)) {\n this.payload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.payload().remaining = remaining\n\n if (remaining <= 0) {\n this.payload().start = Infinity\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AAEzB,IAAAA,0BAA+B;;;ACF/B,6BAA+B;AAIxB,IAAM,oCAAN,cAEG,sCAAkB;AAAA,EAC1B,YAAY,SAAY;AACtB,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAc,kBAAkB;AAC9B,UAAM,YAAY,KAAK,QAAQ,EAAE;AACjC,QAAI,cAAc;AAAW,aAAO;AACpC,YAAQ,KAAK,QAAQ,EAAE,kBAAkB,QAAQ;AAAA,MAC/C,KAAK;AACH,eAAO,YAAY;AAAA,MACrB,KAAK;AACH,eAAO,YAAY,KAAK;AAAA,MAC1B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK;AAAA,MAC/B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK,KAAK;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,IAAc,YAAY;AAExB,WAAO,KAAK,QAAQ,EAAE,aAAa;AAAA,EACrC;AAAA,EAEA,OAAO;AACL,SAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,EAAE,QAAQ,KAAK;AACnD,SAAK,iBAAiB;AACtB,SAAK,SAAS;AACd,WAA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from "@xylabs/assert";
3
- import { PayloadWrapper as PayloadWrapper2 } from "@xyo-network/payload-wrapper";
4
-
5
- // src/SentinelIntervalAutomationWrapper.ts
6
- import { PayloadWrapper } from "@xyo-network/payload-wrapper";
7
- var SentinelIntervalAutomationWrapper = class extends PayloadWrapper {
8
- constructor(payload) {
9
- super(payload);
10
- }
11
- get frequencyMillis() {
12
- const frequency = this.payload().frequency;
13
- if (frequency === void 0)
14
- return Infinity;
15
- switch (this.payload().frequencyUnits ?? "hour") {
16
- case "second":
17
- return frequency * 1e3;
18
- case "minute":
19
- return frequency * 60 * 1e3;
20
- case "hour":
21
- return frequency * 60 * 60 * 1e3;
22
- case "day":
23
- return frequency * 24 * 60 * 60 * 1e3;
24
- }
25
- }
26
- get remaining() {
27
- return this.payload().remaining ?? Infinity;
28
- }
29
- next() {
30
- this.payload().start = this.payload().start + this.frequencyMillis;
31
- this.consumeRemaining();
32
- this.checkEnd();
33
- return this;
34
- }
35
- checkEnd() {
36
- if (this.payload().start > (this.payload().end ?? Infinity)) {
37
- this.payload().start = Infinity;
38
- }
39
- }
40
- consumeRemaining(count = 1) {
41
- const remaining = this.remaining - count;
42
- this.payload().remaining = remaining;
43
- if (remaining <= 0) {
44
- this.payload().start = Infinity;
45
- }
46
- }
47
- };
48
-
49
- // src/SentinelRunner.ts
50
- var SentinelRunner = class {
51
- _automations = {};
52
- onTriggerResult;
53
- sentinel;
54
- timeoutId;
55
- constructor(sentinel, automations, onTriggerResult) {
56
- this.sentinel = sentinel;
57
- this.onTriggerResult = onTriggerResult;
58
- automations?.forEach((automation) => this.add(automation));
59
- }
60
- get automations() {
61
- return this._automations;
62
- }
63
- get next() {
64
- return Object.values(this._automations).reduce((previous, current) => {
65
- if (current.type === "interval") {
66
- return current.start < (previous?.start ?? Infinity) ? current : previous;
67
- }
68
- }, void 0);
69
- }
70
- async add(automation, restart = true) {
71
- const hash = await PayloadWrapper2.hashAsync(automation);
72
- this._automations[hash] = automation;
73
- if (restart)
74
- await this.restart();
75
- return hash;
76
- }
77
- find(hash) {
78
- Object.entries(this._automations).find(([key]) => key === hash);
79
- }
80
- async remove(hash, restart = true) {
81
- delete this._automations[hash];
82
- if (restart)
83
- await this.restart();
84
- }
85
- removeAll() {
86
- this.stop();
87
- this._automations = {};
88
- }
89
- async restart() {
90
- this.stop();
91
- await this.start();
92
- }
93
- async start() {
94
- assertEx(this.timeoutId === void 0, "Already started");
95
- const automation = this.next;
96
- if (automation) {
97
- const delay = automation.start - Date.now();
98
- if (delay < 0) {
99
- await this.trigger(automation);
100
- } else {
101
- this.timeoutId = setTimeout(
102
- async () => {
103
- this.timeoutId = void 0;
104
- await this.start();
105
- },
106
- delay > 0 ? delay : 0
107
- );
108
- }
109
- }
110
- }
111
- stop() {
112
- if (this.timeoutId) {
113
- clearTimeout(this.timeoutId);
114
- this.timeoutId = void 0;
115
- }
116
- }
117
- async update(hash, automation, restart = true) {
118
- await this.remove(hash, false);
119
- await this.add(automation, false);
120
- if (restart)
121
- await this.restart();
122
- }
123
- async trigger(automation) {
124
- const wrapper = new SentinelIntervalAutomationWrapper(automation);
125
- await this.remove(await wrapper.hashAsync(), false);
126
- wrapper.next();
127
- await this.add(wrapper.payload(), false);
128
- const triggerResult = await this.sentinel.report();
129
- this.onTriggerResult?.(triggerResult);
130
- await this.start();
131
- }
132
- };
133
- export {
134
- SentinelRunner
135
- };
136
- //# sourceMappingURL=SentinelRunner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nimport { SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation'\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n automations?.forEach((automation) => this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n return Object.values(this._automations).reduce<SentinelIntervalAutomationPayload | undefined>((previous, current) => {\n if (current.type === 'interval') {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (automation) {\n const delay = automation.start - Date.now()\n if (delay < 0) {\n //automation is due, just do it\n await this.trigger(automation)\n } else {\n this.timeoutId = setTimeout(\n async () => {\n this.timeoutId = undefined\n await this.start()\n },\n delay > 0 ? delay : 0,\n )\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.payload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n await this.start()\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.payload().frequency\n if (frequency === undefined) return Infinity\n switch (this.payload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.payload().start = this.payload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload().start > (this.payload().end ?? Infinity)) {\n this.payload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.payload().remaining = remaining\n\n if (remaining <= 0) {\n this.payload().start = Infinity\n }\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAEzB,SAAS,kBAAAA,uBAAsB;;;ACF/B,SAAS,sBAAsB;AAIxB,IAAM,oCAAN,cAEG,eAAkB;AAAA,EAC1B,YAAY,SAAY;AACtB,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAc,kBAAkB;AAC9B,UAAM,YAAY,KAAK,QAAQ,EAAE;AACjC,QAAI,cAAc;AAAW,aAAO;AACpC,YAAQ,KAAK,QAAQ,EAAE,kBAAkB,QAAQ;AAAA,MAC/C,KAAK;AACH,eAAO,YAAY;AAAA,MACrB,KAAK;AACH,eAAO,YAAY,KAAK;AAAA,MAC1B,KAAK;AACH,eAAO,YAAY,KAAK,KAAK;AAAA,MAC/B,KAAK;AACH,e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;AAClD,YAAQ,KAAK;AACb,UAAM,KAAK,IAAI,QAAQ,QAAQ,GAAG,KAAK;AACvC,UAAM,gBAAgB,MAAM,KAAK,SAAS,OAAO;AACjD,SAAK,kBAAkB,aAAa;AACpC,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;","names":["PayloadWrapper","PayloadWrapper"]}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/Wrapper.ts
21
- var Wrapper_exports = {};
22
- __export(Wrapper_exports, {
23
- SentinelWrapper: () => SentinelWrapper
24
- });
25
- module.exports = __toCommonJS(Wrapper_exports);
26
- var import_module_wrapper = require("@xyo-network/module-wrapper");
27
- var import_sentinel_model = require("@xyo-network/sentinel-model");
28
- (0, import_module_wrapper.constructableModuleWrapper)();
29
- var SentinelWrapper = class extends import_module_wrapper.ModuleWrapper {
30
- static instanceIdentityCheck = import_sentinel_model.isSentinelInstance;
31
- static moduleIdentityCheck = import_sentinel_model.isSentinelModule;
32
- static requiredQueries = [import_sentinel_model.SentinelReportQuerySchema, ...super.requiredQueries];
33
- archivists() {
34
- throw Error("Not supported");
35
- }
36
- async report(payloads) {
37
- const queryPayload = { schema: import_sentinel_model.SentinelReportQuerySchema };
38
- const result = await this.sendQuery(queryPayload, payloads);
39
- return result;
40
- }
41
- witnesses() {
42
- throw Error("Not supported");
43
- }
44
- };
45
- //# sourceMappingURL=Wrapper.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/Wrapper.ts"],"sourcesContent":["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;AACA,4BAA0D;AAE1D,4BAOO;AAAA,IAGP,kDAA2B;AACpB,IAAM,kBAAN,cACG,oCAEV;AAAA,EACE,OAAgB,wBAAwB;AAAA,EACxC,OAAgB,sBAAsB;AAAA,EACtC,OAAgB,kBAAkB,CAAC,iDAA2B,GAAG,MAAM,eAAe;AAAA,EAEtF,aAA2C;AACzC,UAAM,MAAM,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,UAA0C;AACrD,UAAM,eAAoC,EAAE,QAAQ,gDAA0B;AAC9E,UAAM,SAAS,MAAM,KAAK,UAAU,cAAc,QAAQ;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;","names":[]}
@@ -1,28 +0,0 @@
1
- // src/Wrapper.ts
2
- import { constructableModuleWrapper, ModuleWrapper } from "@xyo-network/module-wrapper";
3
- import {
4
- isSentinelInstance,
5
- isSentinelModule,
6
- SentinelReportQuerySchema
7
- } from "@xyo-network/sentinel-model";
8
- constructableModuleWrapper();
9
- var SentinelWrapper = class extends ModuleWrapper {
10
- static instanceIdentityCheck = isSentinelInstance;
11
- static moduleIdentityCheck = isSentinelModule;
12
- static requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries];
13
- archivists() {
14
- throw Error("Not supported");
15
- }
16
- async report(payloads) {
17
- const queryPayload = { schema: SentinelReportQuerySchema };
18
- const result = await this.sendQuery(queryPayload, payloads);
19
- return result;
20
- }
21
- witnesses() {
22
- throw Error("Not supported");
23
- }
24
- };
25
- export {
26
- SentinelWrapper
27
- };
28
- //# sourceMappingURL=Wrapper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/Wrapper.ts"],"sourcesContent":["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":";AACA,SAAS,4BAA4B,qBAAqB;AAE1D;AAAA,EACE;AAAA,EACA;AAAA,EAIA;AAAA,OACK;AAGP,2BAA2B;AACpB,IAAM,kBAAN,cACG,cAEV;AAAA,EACE,OAAgB,wBAAwB;AAAA,EACxC,OAAgB,sBAAsB;AAAA,EACtC,OAAgB,kBAAkB,CAAC,2BAA2B,GAAG,MAAM,eAAe;AAAA,EAEtF,aAA2C;AACzC,UAAM,MAAM,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,UAA0C;AACrD,UAAM,eAAoC,EAAE,QAAQ,0BAA0B;AAC9E,UAAM,SAAS,MAAM,KAAK,UAAU,cAAc,QAAQ;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;","names":[]}
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/AbstractSentinel.ts
21
- var AbstractSentinel_exports = {};
22
- __export(AbstractSentinel_exports, {
23
- AbstractSentinel: () => AbstractSentinel
24
- });
25
- module.exports = __toCommonJS(AbstractSentinel_exports);
26
- var import_assert = require("@xylabs/assert");
27
- var import_lodash = require("@xylabs/lodash");
28
- var import_boundwitness_builder = require("@xyo-network/boundwitness-builder");
29
- var import_boundwitness_model = require("@xyo-network/boundwitness-model");
30
- var import_module_abstract = require("@xyo-network/module-abstract");
31
- var import_sentinel_model = require("@xyo-network/sentinel-model");
32
- var import_witness_model = require("@xyo-network/witness-model");
33
- var AbstractSentinel = class extends import_module_abstract.AbstractModuleInstance {
34
- history = [];
35
- get queries() {
36
- return [import_sentinel_model.SentinelReportQuerySchema, ...super.queries];
37
- }
38
- get _queryAccountPaths() {
39
- return {
40
- "network.xyo.query.sentinel.report": "1/1"
41
- };
42
- }
43
- addWitness(address) {
44
- this.config.witnesses = (0, import_lodash.uniq)([...address, ...this.config.witnesses ?? []]);
45
- }
46
- async report(inPayloads) {
47
- this._noOverride("report");
48
- await this.emit("reportStart", { inPayloads, module: this });
49
- const payloads = await this.reportHandler(inPayloads);
50
- const outPayloads = payloads.filter(import_boundwitness_model.notBoundWitness);
51
- const boundwitnesses = payloads.filter(import_boundwitness_model.isBoundWitness);
52
- const boundwitness = boundwitnesses.find((bw) => bw.addresses.includes(this.address));
53
- await this.emit("reportEnd", { boundwitness, inPayloads, module: this, outPayloads });
54
- return payloads;
55
- }
56
- async witnesses() {
57
- var _a, _b, _c, _d, _e, _f, _g;
58
- (_c = this.logger) == null ? void 0 : _c.debug(`witnesses:config:witnesses: ${(_b = (_a = this.config) == null ? void 0 : _a.witnesses) == null ? void 0 : _b.length}`);
59
- const namesOrAddresses = ((_d = this.config) == null ? void 0 : _d.witnesses) ? Array.isArray(this.config.witnesses) ? (_e = this.config) == null ? void 0 : _e.witnesses : [this.config.witnesses] : void 0;
60
- (_f = this.logger) == null ? void 0 : _f.debug(`witnesses:namesOrAddresses: ${namesOrAddresses == null ? void 0 : namesOrAddresses.length}`);
61
- const result = namesOrAddresses ? [
62
- ...await this.resolve({ address: namesOrAddresses }, { identity: import_witness_model.isWitnessInstance }),
63
- ...await this.resolve({ name: namesOrAddresses }, { identity: import_witness_model.isWitnessInstance })
64
- ] : await this.resolve(void 0, { identity: import_witness_model.isWitnessInstance });
65
- if (namesOrAddresses && namesOrAddresses.length !== result.length) {
66
- (_g = this.logger) == null ? void 0 : _g.warn(`Not all witnesses found [Requested: ${namesOrAddresses.length}, Found: ${result.length}]`);
67
- }
68
- result.map((item) => {
69
- var _a2;
70
- (_a2 = this.logger) == null ? void 0 : _a2.debug(`witnesses:result: ${item.config.schema}`);
71
- });
72
- return result;
73
- }
74
- async queryHandler(query, payloads, queryConfig) {
75
- const wrapper = import_boundwitness_builder.QueryBoundWitnessWrapper.parseQuery(query, payloads);
76
- const queryPayload = await wrapper.getQuery();
77
- (0, import_assert.assertEx)(this.queryable(query, payloads, queryConfig));
78
- const resultPayloads = [];
79
- switch (queryPayload.schema) {
80
- case import_sentinel_model.SentinelReportQuerySchema: {
81
- resultPayloads.push(...await this.report(payloads));
82
- break;
83
- }
84
- default: {
85
- return super.queryHandler(query, payloads);
86
- }
87
- }
88
- return resultPayloads;
89
- }
90
- };
91
- // Annotate the CommonJS export names for ESM import in node:
92
- 0 && (module.exports = {
93
- AbstractSentinel
94
- });
95
- //# sourceMappingURL=AbstractSentinel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/AbstractSentinel.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { uniq } from '@xylabs/lodash'\nimport { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'\nimport { BoundWitness, isBoundWitness, notBoundWitness } from '@xyo-network/boundwitness-model'\nimport { AbstractModuleInstance } from '@xyo-network/module-abstract'\nimport { ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n CustomSentinelInstance,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n SentinelQueryBase,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { isWitnessInstance, WitnessInstance } from '@xyo-network/witness-model'\n\nexport abstract class AbstractSentinel<\n TParams extends SentinelParams = SentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n >\n extends AbstractModuleInstance<TParams, TEventData>\n implements CustomSentinelInstance<TParams, TEventData>\n{\n history: BoundWitness[] = []\n\n override get queries(): string[] {\n return [SentinelReportQuerySchema, ...super.queries]\n }\n\n protected override get _queryAccountPaths(): Record<SentinelQueryBase['schema'], string> {\n return {\n 'network.xyo.query.sentinel.report': '1/1',\n }\n }\n\n addWitness(address: string[]) {\n this.config.witnesses = uniq([...address, ...(this.config.witnesses ?? [])])\n }\n\n async report(inPayloads?: Payload[]): Promise<Payload[]> {\n this._noOverride('report')\n await this.emit('reportStart', { inPayloads, module: this })\n const payloads = await this.reportHandler(inPayloads)\n //this.logger?.debug(`report:payloads: ${JSON.stringify(payloads, null, 2)}`)\n const outPayloads = payloads.filter(notBoundWitness)\n const boundwitnesses = payloads.filter(isBoundWitness)\n const boundwitness = boundwitnesses.find((bw) => bw.addresses.includes(this.address))\n await this.emit('reportEnd', { boundwitness, inPayloads, module: this, outPayloads })\n return payloads\n }\n\n async witnesses() {\n this.logger?.debug(`witnesses:config:witnesses: ${this.config?.witnesses?.length}`)\n const namesOrAddresses = this.config?.witnesses\n ? Array.isArray(this.config.witnesses)\n ? this.config?.witnesses\n : [this.config.witnesses]\n : undefined\n this.logger?.debug(`witnesses:namesOrAddresses: ${namesOrAddresses?.length}`)\n const result = namesOrAddresses\n ? [\n ...(await this.resolve<WitnessInstance>({ address: namesOrAddresses }, { identity: isWitnessInstance })),\n ...(await this.resolve<WitnessInstance>({ name: namesOrAddresses }, { identity: isWitnessInstance })),\n ]\n : await this.resolve<WitnessInstance>(undefined, { identity: isWitnessInstance })\n\n if (namesOrAddresses && namesOrAddresses.length !== result.length) {\n this.logger?.warn(`Not all witnesses found [Requested: ${namesOrAddresses.length}, Found: ${result.length}]`)\n }\n result.map((item) => {\n this.logger?.debug(`witnesses:result: ${item.config.schema}`)\n })\n\n return result\n }\n\n protected override async queryHandler<T extends QueryBoundWitness = QueryBoundWitness, TConfig extends ModuleConfig = ModuleConfig>(\n query: T,\n payloads?: Payload[],\n queryConfig?: TConfig,\n ): Promise<ModuleQueryHandlerResult> {\n const wrapper = QueryBoundWitnessWrapper.parseQuery<SentinelQueryBase>(query, payloads)\n const queryPayload = await wrapper.getQuery()\n assertEx(this.queryable(query, payloads, queryConfig))\n const resultPayloads: Payload[] = []\n switch (queryPayload.schema) {\n case SentinelReportQuerySchema: {\n resultPayloads.push(...(await this.report(payloads)))\n break\n }\n default: {\n return super.queryHandler(query, payloads)\n }\n }\n return resultPayloads\n }\n\n abstract reportHandler(payloads?: Payload[]): Promise<Payload[]>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AACzB,oBAAqB;AACrB,kCAA4D;AAC5D,gCAA8D;AAC9D,6BAAuC;AAGvC,4BAOO;AACP,2BAAmD;AAE5C,IAAe,mBAAf,cAIG,8CAEV;AAAA,EACE,UAA0B,CAAC;AAAA,EAE3B,IAAa,UAAoB;AAC/B,WAAO,CAAC,iDAA2B,GAAG,MAAM,OAAO;AAAA,EACrD;AAAA,EAEA,IAAuB,qBAAkE;AACvF,WAAO;AAAA,MACL,qCAAqC;AAAA,IACvC;AAAA,EACF;AAAA,EAEA,WAAW,SAAmB;AAC5B,SAAK,OAAO,gBAAY,oBAAK,CAAC,GAAG,SAAS,GAAI,KAAK,OAAO,aAAa,CAAC,CAAE,CAAC;AAAA,EAC7E;AAAA,EAEA,MAAM,OAAO,YAA4C;AACvD,SAAK,YAAY,QAAQ;AACzB,UAAM,KAAK,KAAK,eAAe,EAAE,YAAY,QAAQ,KAAK,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