@xyo-network/sentinel-memory 2.107.1 → 2.107.4

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.
@@ -1,2 +1,336 @@
1
- var v=Object.defineProperty;var A=Object.getPrototypeOf;var F=Reflect.get;var j=(o,t,s)=>t in o?v(o,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[t]=s;var f=(o,t)=>v(o,"name",{value:t,configurable:!0});var b=(o,t,s)=>j(o,typeof t!="symbol"?t+"":t,s);var J=(o,t,s)=>F(A(o),s,t);import{fulfilled as H,rejected as U}from"@xylabs/promise";import{asDivinerInstance as k}from"@xyo-network/diviner-model";import{AbstractSentinel as D}from"@xyo-network/sentinel-abstract";import{asSentinelInstance as C,SentinelConfigSchema as $}from"@xyo-network/sentinel-model";import{asWitnessInstance as B}from"@xyo-network/witness-model";import{assertEx as Y}from"@xylabs/assert";import{forget as _}from"@xylabs/forget";import{PayloadBuilder as q}from"@xyo-network/payload-builder";import{isSentinelIntervalAutomation as S}from"@xyo-network/sentinel-model";import{PayloadWrapper as V}from"@xyo-network/payload-wrapper";var N=class N extends V{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(){var i;let t=Date.now(),s=((i=this.payload)==null?void 0:i.start)??t,r=Math.max(s,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 s=Math.max(this.remaining-t,0);this.setRemaining(s),s<=0&&this.setStart(Number.POSITIVE_INFINITY)}setRemaining(t){this.payload.remaining=t}setStart(t){this.payload.start=t}};f(N,"SentinelIntervalAutomationWrapper");var y=N;var P=class P{_automations={};onTriggerResult;sentinel;timeoutId;constructor(t,s,e){if(this.sentinel=t,this.onTriggerResult=e,s)for(let r of s)_(this.add(r))}get automations(){return this._automations}get next(){return Object.values(this._automations).reduce((t,s)=>S(s)&&S(t)?s.start<((t==null?void 0:t.start)??Number.POSITIVE_INFINITY)?s:t:s,void 0)}async add(t,s=!0){let e=await q.dataHash(t);return this._automations[e]=t,s&&await this.restart(),e}find(t){Object.entries(this._automations).find(([s])=>s===t)}async remove(t,s=!0){delete this._automations[t],s&&await this.restart()}removeAll(){this.stop(),this._automations={}}restart(){this.stop(),this.start()}start(){Y(this.timeoutId===void 0,()=>"Already started");let t=this.next;if(S(t)){let s=Date.now(),e=Math.max(t.start??s,s),r=Math.max(e-s,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,s,e=!0){await this.remove(t,!1),await this.add(s,!1),e&&await this.restart()}async trigger(t){var r;let s=new y(t);await this.remove(await s.dataHash(),!1),s.next(),await this.add(s.payload,!1);let e=await this.sentinel.report();(r=this.onTriggerResult)==null||r.call(this,e)}};f(P,"SentinelRunner");var I=P;var h=class h extends D{runner;async reportHandler(t=[]){var g,p;await this.started("throw"),(g=this.logger)==null||g.debug(`reportHandler:in: ${JSON.stringify(t)}`);let s=await this.jobPromise,e=0,r={};for(;e<s.tasks.length;)r=await this.runJob(s.tasks[e],r,t),e++;let i=Object.values(r).flat();return(p=this.logger)==null||p.debug(`reportHandler:out: ${JSON.stringify(i)}`),i}async start(t){var s;return await super.start(t)?((((s=this.config.automations)==null?void 0:s.length)??0)>0&&(this.runner=new I(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 s=>await this.inputAddresses(s)))).flat();{let s=await this.resolve(t);return s?[s.address]:[]}}processPreviousResults(t,s){return s.flatMap(e=>t[e]??[])}async runJob(t,s,e){var g,p,w,T;await this.emit("jobStart",{inPayloads:e,module:this}),(g=this.logger)==null||g.debug(`runJob:tasks: ${JSON.stringify(t.length)}`),(p=this.logger)==null||p.debug(`runJob:previous: ${JSON.stringify(s)}`),(w=this.logger)==null||w.debug(`runJob:in: ${JSON.stringify(e)}`);let r=await Promise.allSettled(t==null?void 0:t.map(async u=>{var O,x,E;let d=u.input??!1,a=d===!0?e:d===!1?[]:this.processPreviousResults(s,await this.inputAddresses(d)),l=B(u.module);if(l){await this.emit("taskStart",{address:l.address,inPayloads:a,module:this});let n=await l.observe(a);return(O=this.logger)==null||O.debug(`observed [${l.id}]: ${JSON.stringify(n)}`),await this.emit("taskEnd",{address:l.address,inPayloads:a,module:this,outPayloads:n}),[l.address,n]}let m=k(u.module);if(m){await this.emit("taskStart",{address:m.address,inPayloads:a,module:this});let n=await m.divine(a);return(x=this.logger)==null||x.debug(`divined [${m.id}]: ${JSON.stringify(n)}`),await this.emit("taskEnd",{address:m.address,inPayloads:a,module:this,outPayloads:n}),[m.address,n]}let c=C(u.module);if(c){await this.emit("taskStart",{address:c.address,inPayloads:a,module:this});let n=await c.report(a);return(E=this.logger)==null||E.debug(`reported [${c.id}]: ${JSON.stringify(n)}`),await this.emit("taskEnd",{address:c.address,inPayloads:a,module:this,outPayloads:n}),[c.address,n]}throw new Error("Unsupported module type")})),i={};for(let u of r.filter(H)){let[d,a]=u.value;i[d]=i[d]??[],i[d].push(...a)}if(this.throwErrors&&r.filter(U).map(d=>d.reason).length>0)throw new Error("At least one module failed");return(T=this.logger)==null||T.debug(`generateResults:out: ${JSON.stringify(i)}`),await this.emit("jobEnd",{finalResult:i,inPayloads:e,module:this}),i}};f(h,"MemorySentinel"),b(h,"configSchemas",[...J(h,h,"configSchemas"),$]),b(h,"defaultConfigSchema",$);var R=h;export{R as MemorySentinel,y as SentinelIntervalAutomationWrapper,I as SentinelRunner};
1
+ var __defProp = Object.defineProperty;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __reflectGet = Reflect.get;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
8
+
9
+ // src/MemorySentinel.ts
10
+ import { fulfilled, rejected } from "@xylabs/promise";
11
+ import { asDivinerInstance } from "@xyo-network/diviner-model";
12
+ import { AbstractSentinel } from "@xyo-network/sentinel-abstract";
13
+ import { asSentinelInstance, SentinelConfigSchema } from "@xyo-network/sentinel-model";
14
+ import { asWitnessInstance } from "@xyo-network/witness-model";
15
+
16
+ // src/SentinelRunner.ts
17
+ import { assertEx } from "@xylabs/assert";
18
+ import { forget } from "@xylabs/forget";
19
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
20
+ import { isSentinelIntervalAutomation } from "@xyo-network/sentinel-model";
21
+
22
+ // src/SentinelIntervalAutomationWrapper.ts
23
+ import { PayloadWrapper } from "@xyo-network/payload-wrapper";
24
+ var _SentinelIntervalAutomationWrapper = class _SentinelIntervalAutomationWrapper extends PayloadWrapper {
25
+ constructor(payload) {
26
+ super(payload);
27
+ }
28
+ get frequencyMillis() {
29
+ const frequency = this.payload.frequency;
30
+ if (frequency === void 0) return Number.POSITIVE_INFINITY;
31
+ const frequencyUnits = this.payload.frequencyUnits;
32
+ switch (frequencyUnits ?? "hour") {
33
+ case "second": {
34
+ return frequency * 1e3;
35
+ }
36
+ case "minute": {
37
+ return frequency * 60 * 1e3;
38
+ }
39
+ case "hour": {
40
+ return frequency * 60 * 60 * 1e3;
41
+ }
42
+ case "day": {
43
+ return frequency * 24 * 60 * 60 * 1e3;
44
+ }
45
+ default: {
46
+ return Number.POSITIVE_INFINITY;
47
+ }
48
+ }
49
+ }
50
+ get remaining() {
51
+ return this.payload.remaining ?? Number.POSITIVE_INFINITY;
52
+ }
53
+ next() {
54
+ var _a;
55
+ const now = Date.now();
56
+ const previousStart = ((_a = this.payload) == null ? void 0 : _a.start) ?? now;
57
+ const start = Math.max(previousStart, now);
58
+ const nextStart = start + this.frequencyMillis;
59
+ this.setStart(nextStart);
60
+ this.consumeRemaining();
61
+ this.checkEnd();
62
+ return this;
63
+ }
64
+ checkEnd() {
65
+ if (this.payload.start > (this.payload.end ?? Number.POSITIVE_INFINITY)) {
66
+ this.setStart(Number.POSITIVE_INFINITY);
67
+ }
68
+ }
69
+ consumeRemaining(count = 1) {
70
+ const remaining = Math.max(this.remaining - count, 0);
71
+ this.setRemaining(remaining);
72
+ if (remaining <= 0) this.setStart(Number.POSITIVE_INFINITY);
73
+ }
74
+ /**
75
+ * Sets the remaining of the wrapped automation
76
+ * @param remaining The remaining time in milliseconds
77
+ */
78
+ setRemaining(remaining) {
79
+ this.payload.remaining = remaining;
80
+ }
81
+ /**
82
+ * Sets the start of the wrapped automation
83
+ * @param start The start time in milliseconds
84
+ */
85
+ setStart(start) {
86
+ this.payload.start = start;
87
+ }
88
+ };
89
+ __name(_SentinelIntervalAutomationWrapper, "SentinelIntervalAutomationWrapper");
90
+ var SentinelIntervalAutomationWrapper = _SentinelIntervalAutomationWrapper;
91
+
92
+ // src/SentinelRunner.ts
93
+ var _SentinelRunner = class _SentinelRunner {
94
+ _automations = {};
95
+ onTriggerResult;
96
+ sentinel;
97
+ timeoutId;
98
+ constructor(sentinel, automations, onTriggerResult) {
99
+ this.sentinel = sentinel;
100
+ this.onTriggerResult = onTriggerResult;
101
+ if (automations) for (const automation of automations) forget(this.add(automation));
102
+ }
103
+ get automations() {
104
+ return this._automations;
105
+ }
106
+ get next() {
107
+ return Object.values(this._automations).reduce((previous, current) => {
108
+ if (isSentinelIntervalAutomation(current) && isSentinelIntervalAutomation(previous)) {
109
+ return current.start < ((previous == null ? void 0 : previous.start) ?? Number.POSITIVE_INFINITY) ? current : previous;
110
+ }
111
+ return current;
112
+ }, void 0);
113
+ }
114
+ async add(automation, restart = true) {
115
+ const hash = await PayloadBuilder.dataHash(automation);
116
+ this._automations[hash] = automation;
117
+ if (restart) await this.restart();
118
+ return hash;
119
+ }
120
+ find(hash) {
121
+ Object.entries(this._automations).find(([key]) => key === hash);
122
+ }
123
+ async remove(hash, restart = true) {
124
+ delete this._automations[hash];
125
+ if (restart) await this.restart();
126
+ }
127
+ removeAll() {
128
+ this.stop();
129
+ this._automations = {};
130
+ }
131
+ restart() {
132
+ this.stop();
133
+ this.start();
134
+ }
135
+ start() {
136
+ assertEx(this.timeoutId === void 0, () => "Already started");
137
+ const automation = this.next;
138
+ if (isSentinelIntervalAutomation(automation)) {
139
+ const now = Date.now();
140
+ const start = Math.max(automation.start ?? now, now);
141
+ const delay = Math.max(start - now, 0);
142
+ if (delay < Number.POSITIVE_INFINITY) {
143
+ this.timeoutId = setTimeout(async () => {
144
+ try {
145
+ await this.trigger(automation);
146
+ this.stop();
147
+ } finally {
148
+ this.start();
149
+ }
150
+ }, delay);
151
+ }
152
+ }
153
+ }
154
+ stop() {
155
+ if (this.timeoutId) {
156
+ clearTimeout(this.timeoutId);
157
+ this.timeoutId = void 0;
158
+ }
159
+ }
160
+ async update(hash, automation, restart = true) {
161
+ await this.remove(hash, false);
162
+ await this.add(automation, false);
163
+ if (restart) await this.restart();
164
+ }
165
+ async trigger(automation) {
166
+ var _a;
167
+ const wrapper = new SentinelIntervalAutomationWrapper(automation);
168
+ await this.remove(await wrapper.dataHash(), false);
169
+ wrapper.next();
170
+ await this.add(wrapper.payload, false);
171
+ const triggerResult = await this.sentinel.report();
172
+ (_a = this.onTriggerResult) == null ? void 0 : _a.call(this, triggerResult);
173
+ }
174
+ };
175
+ __name(_SentinelRunner, "SentinelRunner");
176
+ var SentinelRunner = _SentinelRunner;
177
+
178
+ // src/MemorySentinel.ts
179
+ var _MemorySentinel = class _MemorySentinel extends AbstractSentinel {
180
+ runner;
181
+ async reportHandler(inPayloads = []) {
182
+ var _a, _b;
183
+ await this.started("throw");
184
+ (_a = this.logger) == null ? void 0 : _a.debug(`reportHandler:in: ${JSON.stringify(inPayloads)}`);
185
+ const job = await this.jobPromise;
186
+ let index = 0;
187
+ let previousResults = {};
188
+ while (index < job.tasks.length) {
189
+ const generatedPayloads = await this.runJob(job.tasks[index], previousResults, inPayloads);
190
+ previousResults = generatedPayloads;
191
+ index++;
192
+ }
193
+ const result = Object.values(previousResults).flat();
194
+ (_b = this.logger) == null ? void 0 : _b.debug(`reportHandler:out: ${JSON.stringify(result)}`);
195
+ return result;
196
+ }
197
+ async start(timeout) {
198
+ var _a;
199
+ if (await super.start(timeout)) {
200
+ if ((((_a = this.config.automations) == null ? void 0 : _a.length) ?? 0) > 0) {
201
+ this.runner = new SentinelRunner(this, this.config.automations);
202
+ this.runner.start();
203
+ }
204
+ return true;
205
+ }
206
+ return false;
207
+ }
208
+ async stop(timeout) {
209
+ if (this.runner) {
210
+ this.runner.stop();
211
+ this.runner = void 0;
212
+ }
213
+ return await super.stop(timeout);
214
+ }
215
+ async inputAddresses(input) {
216
+ if (Array.isArray(input)) {
217
+ return (await Promise.all(input.map(async (inputItem) => await this.inputAddresses(inputItem)))).flat();
218
+ } else {
219
+ const resolved = await this.resolve(input);
220
+ return resolved ? [
221
+ resolved.address
222
+ ] : [];
223
+ }
224
+ }
225
+ processPreviousResults(payloads, inputs) {
226
+ return inputs.flatMap((input) => payloads[input] ?? []);
227
+ }
228
+ async runJob(tasks, previousResults, inPayloads) {
229
+ var _a, _b, _c, _d;
230
+ await this.emit("jobStart", {
231
+ inPayloads,
232
+ module: this
233
+ });
234
+ (_a = this.logger) == null ? void 0 : _a.debug(`runJob:tasks: ${JSON.stringify(tasks.length)}`);
235
+ (_b = this.logger) == null ? void 0 : _b.debug(`runJob:previous: ${JSON.stringify(previousResults)}`);
236
+ (_c = this.logger) == null ? void 0 : _c.debug(`runJob:in: ${JSON.stringify(inPayloads)}`);
237
+ const results = await Promise.allSettled(tasks == null ? void 0 : tasks.map(async (task) => {
238
+ var _a2, _b2, _c2;
239
+ const input = task.input ?? false;
240
+ const inPayloadsFound = input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input));
241
+ const witness = asWitnessInstance(task.module);
242
+ if (witness) {
243
+ await this.emit("taskStart", {
244
+ address: witness.address,
245
+ inPayloads: inPayloadsFound,
246
+ module: this
247
+ });
248
+ const observed = await witness.observe(inPayloadsFound);
249
+ (_a2 = this.logger) == null ? void 0 : _a2.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`);
250
+ await this.emit("taskEnd", {
251
+ address: witness.address,
252
+ inPayloads: inPayloadsFound,
253
+ module: this,
254
+ outPayloads: observed
255
+ });
256
+ return [
257
+ witness.address,
258
+ observed
259
+ ];
260
+ }
261
+ const diviner = asDivinerInstance(task.module);
262
+ if (diviner) {
263
+ await this.emit("taskStart", {
264
+ address: diviner.address,
265
+ inPayloads: inPayloadsFound,
266
+ module: this
267
+ });
268
+ const divined = await diviner.divine(inPayloadsFound);
269
+ (_b2 = this.logger) == null ? void 0 : _b2.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`);
270
+ await this.emit("taskEnd", {
271
+ address: diviner.address,
272
+ inPayloads: inPayloadsFound,
273
+ module: this,
274
+ outPayloads: divined
275
+ });
276
+ return [
277
+ diviner.address,
278
+ divined
279
+ ];
280
+ }
281
+ const sentinel = asSentinelInstance(task.module);
282
+ if (sentinel) {
283
+ await this.emit("taskStart", {
284
+ address: sentinel.address,
285
+ inPayloads: inPayloadsFound,
286
+ module: this
287
+ });
288
+ const reported = await sentinel.report(inPayloadsFound);
289
+ (_c2 = this.logger) == null ? void 0 : _c2.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`);
290
+ await this.emit("taskEnd", {
291
+ address: sentinel.address,
292
+ inPayloads: inPayloadsFound,
293
+ module: this,
294
+ outPayloads: reported
295
+ });
296
+ return [
297
+ sentinel.address,
298
+ reported
299
+ ];
300
+ }
301
+ throw new Error("Unsupported module type");
302
+ }));
303
+ const finalResult = {};
304
+ for (const result of results.filter(fulfilled)) {
305
+ const [address, payloads] = result.value;
306
+ finalResult[address] = finalResult[address] ?? [];
307
+ finalResult[address].push(...payloads);
308
+ }
309
+ if (this.throwErrors) {
310
+ const errors = results.filter(rejected).map((result) => result.reason);
311
+ if (errors.length > 0) {
312
+ throw new Error("At least one module failed");
313
+ }
314
+ }
315
+ (_d = this.logger) == null ? void 0 : _d.debug(`generateResults:out: ${JSON.stringify(finalResult)}`);
316
+ await this.emit("jobEnd", {
317
+ finalResult,
318
+ inPayloads,
319
+ module: this
320
+ });
321
+ return finalResult;
322
+ }
323
+ };
324
+ __name(_MemorySentinel, "MemorySentinel");
325
+ __publicField(_MemorySentinel, "configSchemas", [
326
+ ...__superGet(_MemorySentinel, _MemorySentinel, "configSchemas"),
327
+ SentinelConfigSchema
328
+ ]);
329
+ __publicField(_MemorySentinel, "defaultConfigSchema", SentinelConfigSchema);
330
+ var MemorySentinel = _MemorySentinel;
331
+ export {
332
+ MemorySentinel,
333
+ SentinelIntervalAutomationWrapper,
334
+ SentinelRunner
335
+ };
2
336
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/MemorySentinel.ts","../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["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":"gSACA,OAASA,aAAAA,EAAWC,YAAAA,MAAgB,kBACpC,OAASC,qBAAAA,MAAyB,6BAGlC,OAASC,oBAAAA,MAAwB,iCACjC,OACEC,sBAAAA,EAGAC,wBAAAA,MAIK,8BACP,OAASC,qBAAAA,MAAyB,6BCflC,OAASC,YAAAA,MAAgB,iBACzB,OAASC,UAAAA,MAAc,iBACvB,OAASC,kBAAAA,MAAsB,+BAE/B,OACEC,gCAAAA,MAIK,8BCTP,OAASC,kBAAAA,MAAsB,+BAGxB,IAAMC,EAAN,MAAMA,UAEHC,CAAAA,CACRC,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,C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asSentinelInstance","SentinelConfigSchema","asWitnessInstance","assertEx","forget","PayloadBuilder","isSentinelIntervalAutomation","PayloadWrapper","SentinelIntervalAutomationWrapper","PayloadWrapper","constructor","payload","frequencyMillis","frequency","undefined","Number","POSITIVE_INFINITY","frequencyUnits","remaining","next","_a","now","Date","previousStart","start","nextStart","Math","max","setStart","consumeRemaining","checkEnd","end","count","setRemaining","_SentinelIntervalAutomationWrapper","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","_a","wrapper","SentinelIntervalAutomationWrapper","payload","triggerResult","report","_SentinelRunner","MemorySentinel","AbstractSentinel","runner","reportHandler","inPayloads","_a","_b","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","_c","_d","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","__publicField","configSchemas","__superGet","_MemorySentinel","SentinelConfigSchema","defaultConfigSchema"]}
1
+ {"version":3,"sources":["../../src/MemorySentinel.ts","../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["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":";;;;;;;;;AACA,SAASA,WAAWC,gBAAgB;AACpC,SAASC,yBAAyB;AAGlC,SAASC,wBAAwB;AACjC,SACEC,oBAGAC,4BAIK;AACP,SAASC,yBAAyB;;;ACflC,SAASC,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,sBAAsB;AAE/B,SACEC,oCAIK;;;ACTP,SAASC,sBAAsB;AAGxB,IAAMC,qCAAN,MAAMA,2CAEHC,eAAAA;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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AEwB;MAAahE;MAAYyC,QAAQ;IAAK,CAAA;AAClE,WAAOuB;EACT;AACF;AAlHUnE;AACR,cAJWD,iBAIc6E,iBAA0B;KAAI,6CAAMA;EAAeC;;AAC5E,cALW9E,iBAKc+E,uBAA8BD;AALlD,IAAM9E,iBAAN;","names":["fulfilled","rejected","asDivinerInstance","AbstractSentinel","asSentinelInstance","SentinelConfigSchema","asWitnessInstance","assertEx","forget","PayloadBuilder","isSentinelIntervalAutomation","PayloadWrapper","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","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","_a","_b","_c","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","configSchemas","SentinelConfigSchema","defaultConfigSchema"]}
package/package.json CHANGED
@@ -14,26 +14,26 @@
14
14
  "@xylabs/forget": "^3.5.1",
15
15
  "@xylabs/hex": "^3.5.1",
16
16
  "@xylabs/promise": "^3.5.1",
17
- "@xyo-network/diviner-model": "~2.107.1",
18
- "@xyo-network/module-model": "~2.107.1",
19
- "@xyo-network/payload-builder": "~2.107.1",
20
- "@xyo-network/payload-model": "~2.107.1",
21
- "@xyo-network/payload-wrapper": "~2.107.1",
22
- "@xyo-network/sentinel-abstract": "~2.107.1",
23
- "@xyo-network/sentinel-model": "~2.107.1",
24
- "@xyo-network/witness-model": "~2.107.1"
17
+ "@xyo-network/diviner-model": "~2.107.4",
18
+ "@xyo-network/module-model": "~2.107.4",
19
+ "@xyo-network/payload-builder": "~2.107.4",
20
+ "@xyo-network/payload-model": "~2.107.4",
21
+ "@xyo-network/payload-wrapper": "~2.107.4",
22
+ "@xyo-network/sentinel-abstract": "~2.107.4",
23
+ "@xyo-network/sentinel-model": "~2.107.4",
24
+ "@xyo-network/witness-model": "~2.107.4"
25
25
  },
26
26
  "description": "Primary SDK for using XYO Protocol 2.0",
27
27
  "devDependencies": {
28
28
  "@xylabs/delay": "^3.5.1",
29
- "@xylabs/ts-scripts-yarn3": "^3.11.9",
30
- "@xylabs/tsconfig": "^3.11.9",
31
- "@xyo-network/abstract-witness": "~2.107.1",
32
- "@xyo-network/account": "~2.107.1",
33
- "@xyo-network/archivist-memory": "~2.107.1",
34
- "@xyo-network/id-payload-plugin": "~2.107.1",
35
- "@xyo-network/node-memory": "~2.107.1",
36
- "@xyo-network/witness-adhoc": "~2.107.1",
29
+ "@xylabs/ts-scripts-yarn3": "^3.11.10",
30
+ "@xylabs/tsconfig": "^3.11.10",
31
+ "@xyo-network/abstract-witness": "~2.107.4",
32
+ "@xyo-network/account": "~2.107.4",
33
+ "@xyo-network/archivist-memory": "~2.107.4",
34
+ "@xyo-network/id-payload-plugin": "~2.107.4",
35
+ "@xyo-network/node-memory": "~2.107.4",
36
+ "@xyo-network/witness-adhoc": "~2.107.4",
37
37
  "typescript": "^5.5.2"
38
38
  },
39
39
  "types": "dist/node/index.d.ts",
@@ -74,6 +74,6 @@
74
74
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
75
75
  },
76
76
  "sideEffects": false,
77
- "version": "2.107.1",
77
+ "version": "2.107.4",
78
78
  "type": "module"
79
79
  }