@xyo-network/sentinel-memory 3.8.0 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/index.d.ts +51 -4
- package/dist/neutral/index.mjs +3 -3
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +17 -17
- package/src/SentinelRunner.ts +4 -3
- package/dist/neutral/MemorySentinel.d.ts +0 -17
- package/dist/neutral/MemorySentinel.d.ts.map +0 -1
- package/dist/neutral/SentinelIntervalAutomationWrapper.d.ts +0 -21
- package/dist/neutral/SentinelIntervalAutomationWrapper.d.ts.map +0 -1
- package/dist/neutral/SentinelRunner.d.ts +0 -22
- package/dist/neutral/SentinelRunner.d.ts.map +0 -1
- package/dist/neutral/index.d.ts.map +0 -1
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,4 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { AnyConfigSchema } from '@xyo-network/module-model';
|
|
2
|
+
import { Schema, Payload } from '@xyo-network/payload-model';
|
|
3
|
+
import { AbstractSentinel } from '@xyo-network/sentinel-abstract';
|
|
4
|
+
import { SentinelConfig, SentinelParams, SentinelModuleEventData, SentinelInstance, SentinelIntervalAutomationPayload, SentinelAutomationPayload } from '@xyo-network/sentinel-model';
|
|
5
|
+
import { PayloadWrapper } from '@xyo-network/payload-wrapper';
|
|
6
|
+
|
|
7
|
+
type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>;
|
|
8
|
+
declare class MemorySentinel<TParams extends MemorySentinelParams = MemorySentinelParams, TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>> extends AbstractSentinel<TParams, TEventData> {
|
|
9
|
+
static readonly configSchemas: Schema[];
|
|
10
|
+
static readonly defaultConfigSchema: Schema;
|
|
11
|
+
private runner?;
|
|
12
|
+
reportHandler(inPayloads?: Payload[]): Promise<Payload[]>;
|
|
13
|
+
start(timeout?: number | undefined): Promise<boolean>;
|
|
14
|
+
stop(timeout?: number | undefined): Promise<boolean>;
|
|
15
|
+
private inputAddresses;
|
|
16
|
+
private processPreviousResults;
|
|
17
|
+
private runJob;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare class SentinelIntervalAutomationWrapper<T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload> extends PayloadWrapper<T> {
|
|
21
|
+
constructor(payload: T);
|
|
22
|
+
protected get frequencyMillis(): number;
|
|
23
|
+
protected get remaining(): number;
|
|
24
|
+
next(): this;
|
|
25
|
+
protected checkEnd(): void;
|
|
26
|
+
protected consumeRemaining(count?: number): void;
|
|
27
|
+
protected setRemaining(remaining: number): void;
|
|
28
|
+
protected setStart(start: number): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type OnSentinelRunnerTriggerResult = (result: Payload[]) => void;
|
|
32
|
+
declare class SentinelRunner {
|
|
33
|
+
protected _automations: Record<string, SentinelAutomationPayload>;
|
|
34
|
+
protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined;
|
|
35
|
+
protected sentinel: SentinelInstance;
|
|
36
|
+
protected timeoutId?: NodeJS.Timeout | string | number;
|
|
37
|
+
constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult);
|
|
38
|
+
get automations(): Record<string, SentinelAutomationPayload>;
|
|
39
|
+
private get next();
|
|
40
|
+
add(automation: SentinelAutomationPayload, restart?: boolean): Promise<Lowercase<string>>;
|
|
41
|
+
find(hash: string): [string, SentinelAutomationPayload] | undefined;
|
|
42
|
+
remove(hash: string, restart?: boolean): void;
|
|
43
|
+
removeAll(): void;
|
|
44
|
+
restart(): void;
|
|
45
|
+
start(): void;
|
|
46
|
+
stop(): void;
|
|
47
|
+
update(hash: string, automation: SentinelAutomationPayload, restart?: boolean): Promise<void>;
|
|
48
|
+
private trigger;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { MemorySentinel, type MemorySentinelParams, type OnSentinelRunnerTriggerResult, SentinelIntervalAutomationWrapper, SentinelRunner };
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -153,13 +153,13 @@ var SentinelRunner = class {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
async update(hash, automation, restart = true) {
|
|
156
|
-
|
|
156
|
+
this.remove(hash, false);
|
|
157
157
|
await this.add(automation, false);
|
|
158
|
-
if (restart)
|
|
158
|
+
if (restart) this.restart();
|
|
159
159
|
}
|
|
160
160
|
async trigger(automation) {
|
|
161
161
|
const wrapper = new SentinelIntervalAutomationWrapper(automation);
|
|
162
|
-
|
|
162
|
+
this.remove(await wrapper.dataHash(), false);
|
|
163
163
|
wrapper.next();
|
|
164
164
|
await this.add(wrapper.payload, false);
|
|
165
165
|
const triggerResult = await this.sentinel.report();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/MemorySentinel.ts","../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["import type { Address } from '@xylabs/hex'\nimport { fulfilled, rejected } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport type { AnyConfigSchema, ModuleIdentifier } from '@xyo-network/module-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport type {\n ResolvedTask,\n SentinelConfig,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport {\n asSentinelInstance,\n SentinelConfigSchema,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nimport { SentinelRunner } from './SentinelRunner.ts'\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, mod: 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\n ? inPayloads\n : input === false\n ? []\n : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n const witness = asWitnessInstance(task.mod)\n if (witness) {\n await this.emit('taskStart', {\n address: witness.address, inPayloads: inPayloadsFound, mod: this,\n })\n const observed = await witness.observe(inPayloadsFound)\n this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`)\n await this.emit('taskEnd', {\n address: witness.address, inPayloads: inPayloadsFound, mod: this, outPayloads: observed,\n })\n return [witness.address, observed]\n }\n const diviner = asDivinerInstance(task.mod)\n if (diviner) {\n await this.emit('taskStart', {\n address: diviner.address, inPayloads: inPayloadsFound, mod: this,\n })\n const divined = await diviner.divine(inPayloadsFound)\n this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`)\n await this.emit('taskEnd', {\n address: diviner.address, inPayloads: inPayloadsFound, mod: this, outPayloads: divined,\n })\n return [diviner.address, divined]\n }\n const sentinel = asSentinelInstance(task.mod)\n if (sentinel) {\n await this.emit('taskStart', {\n address: sentinel.address, inPayloads: inPayloadsFound, mod: this,\n })\n const reported = await sentinel.report(inPayloadsFound)\n this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`)\n await this.emit('taskEnd', {\n address: sentinel.address, inPayloads: inPayloadsFound, mod: this, outPayloads: reported,\n })\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', {\n finalResult, inPayloads, mod: this,\n })\n return finalResult\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { forget } from '@xylabs/forget'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { Payload } from '@xyo-network/payload-model'\nimport type {\n SentinelAutomationPayload,\n SentinelInstance,\n SentinelIntervalAutomationPayload,\n} from '@xyo-network/sentinel-model'\nimport { isSentinelIntervalAutomation } from '@xyo-network/sentinel-model'\n\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper.ts'\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) this.restart()\n return hash\n }\n\n find(hash: string) {\n return Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) 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 type { 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 'millis': {\n return frequency\n }\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,SAAS,WAAW,gBAAgB;AACpC,SAAS,yBAAyB;AAGlC,SAAS,wBAAwB;AAQjC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;;;ACjBlC,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAO/B,SAAS,oCAAoC;;;ACT7C,SAAS,sBAAsB;AAGxB,IAAM,oCAAN,cAEG,eAAkB;AAAA,EAC1B,YAAY,SAAY;AACtB,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAc,kBAAkB;AAC9B,UAAM,YAAY,KAAK,QAAQ;AAC/B,QAAI,cAAc,OAAW,QAAO,OAAO;AAC3C,UAAM,iBAAiB,KAAK,QAAQ;AACpC,YAAQ,kBAAkB,QAAQ;AAAA,MAChC,KAAK,UAAU;AACb,eAAO;AAAA,MACT;AAAA,MACA,KAAK,UAAU;AACb,eAAO,YAAY;AAAA,MACrB;AAAA,MACA,KAAK,UAAU;AACb,eAAO,YAAY,KAAK;AAAA,MAC1B;AAAA,MACA,K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K,KAAK,aAAa;AAAA,YAC3B,SAAS,SAAS;AAAA,YAAS,YAAY;AAAA,YAAiB,KAAK;AAAA,UAC/D,CAAC;AACD,gBAAM,WAAW,MAAM,SAAS,OAAO,eAAe;AACtD,eAAK,QAAQ,MAAM,aAAa,SAAS,EAAE,MAAM,KAAK,UAAU,QAAQ,CAAC,EAAE;AAC3E,gBAAM,KAAK,KAAK,WAAW;AAAA,YACzB,SAAS,SAAS;AAAA,YAAS,YAAY;AAAA,YAAiB,KAAK;AAAA,YAAM,aAAa;AAAA,UAClF,CAAC;AACD,iBAAO,CAAC,SAAS,SAAS,QAAQ;AAAA,QACpC;AACA,cAAM,IAAI,MAAM,yBAAyB;AAAA,MAC3C,CAAC;AAAA,IACH;AACA,UAAM,cAA0C,CAAC;AACjD,eAAW,UAAU,QAAQ,OAAO,SAAS,GAAG;AAC9C,YAAM,CAAC,SAAS,QAAQ,IAAI,OAAO;AACnC,kBAAY,OAAO,IAAI,YAAY,OAAO,KAAK,CAAC;AAChD,kBAAY,OAAO,EAAE,KAAK,GAAG,QAAQ;AAAA,IACvC;AACA,QAAI,KAAK,aAAa;AACpB,YAAM,SAAS,QAAQ,OAAO,QAAQ,EAAE,IAAI,YAAU,OAAO,MAAM;AACnE,UAAI,OAAO,SAAS,GAAG;AACrB,cAAM,IAAI,MAAM,4BAA4B;AAAA,MAC9C;AAAA,IACF;AACA,SAAK,QAAQ,MAAM,wBAAwB,KAAK,UAAU,WAAW,CAAC,EAAE;AACxE,UAAM,KAAK,KAAK,UAAU;AAAA,MACxB;AAAA,MAAa;AAAA,MAAY,KAAK;AAAA,IAChC,CAAC;AACD,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/MemorySentinel.ts","../../src/SentinelRunner.ts","../../src/SentinelIntervalAutomationWrapper.ts"],"sourcesContent":["import type { Address } from '@xylabs/hex'\nimport { fulfilled, rejected } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport type { AnyConfigSchema, ModuleIdentifier } from '@xyo-network/module-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport type {\n ResolvedTask,\n SentinelConfig,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n} from '@xyo-network/sentinel-model'\nimport {\n asSentinelInstance,\n SentinelConfigSchema,\n} from '@xyo-network/sentinel-model'\nimport { asWitnessInstance } from '@xyo-network/witness-model'\n\nimport { SentinelRunner } from './SentinelRunner.ts'\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, mod: 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\n ? inPayloads\n : input === false\n ? []\n : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n const witness = asWitnessInstance(task.mod)\n if (witness) {\n await this.emit('taskStart', {\n address: witness.address, inPayloads: inPayloadsFound, mod: this,\n })\n const observed = await witness.observe(inPayloadsFound)\n this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`)\n await this.emit('taskEnd', {\n address: witness.address, inPayloads: inPayloadsFound, mod: this, outPayloads: observed,\n })\n return [witness.address, observed]\n }\n const diviner = asDivinerInstance(task.mod)\n if (diviner) {\n await this.emit('taskStart', {\n address: diviner.address, inPayloads: inPayloadsFound, mod: this,\n })\n const divined = await diviner.divine(inPayloadsFound)\n this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`)\n await this.emit('taskEnd', {\n address: diviner.address, inPayloads: inPayloadsFound, mod: this, outPayloads: divined,\n })\n return [diviner.address, divined]\n }\n const sentinel = asSentinelInstance(task.mod)\n if (sentinel) {\n await this.emit('taskStart', {\n address: sentinel.address, inPayloads: inPayloadsFound, mod: this,\n })\n const reported = await sentinel.report(inPayloadsFound)\n this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`)\n await this.emit('taskEnd', {\n address: sentinel.address, inPayloads: inPayloadsFound, mod: this, outPayloads: reported,\n })\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', {\n finalResult, inPayloads, mod: this,\n })\n return finalResult\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { forget } from '@xylabs/forget'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { Payload } from '@xyo-network/payload-model'\nimport type {\n SentinelAutomationPayload,\n SentinelInstance,\n SentinelIntervalAutomationPayload,\n} from '@xyo-network/sentinel-model'\nimport { isSentinelIntervalAutomation } from '@xyo-network/sentinel-model'\n\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper.ts'\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 // eslint-disable-next-line sonarjs/no-async-constructor\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) this.restart()\n return hash\n }\n\n find(hash: string) {\n return Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) 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 this.remove(hash, false)\n await this.add(automation, false)\n if (restart) this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n 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 type { 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 'millis': {\n return frequency\n }\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,SAAS,WAAW,gBAAgB;AACpC,SAAS,yBAAyB;AAGlC,SAAS,wBAAwB;AAQjC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;;;ACjBlC,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,sBAAs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AO,SAAS,GAAG;AACrB,cAAM,IAAI,MAAM,4BAA4B;AAAA,MAC9C;AAAA,IACF;AACA,SAAK,QAAQ,MAAM,wBAAwB,KAAK,UAAU,WAAW,CAAC,EAAE;AACxE,UAAM,KAAK,KAAK,UAAU;AAAA,MACxB;AAAA,MAAa;AAAA,MAAY,KAAK;AAAA,IAChC,CAAC;AACD,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/sentinel-memory",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.2",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -33,27 +33,27 @@
|
|
|
33
33
|
"@xylabs/forget": "^4.5.1",
|
|
34
34
|
"@xylabs/hex": "^4.5.1",
|
|
35
35
|
"@xylabs/promise": "^4.5.1",
|
|
36
|
-
"@xyo-network/diviner-model": "^3.8.
|
|
37
|
-
"@xyo-network/module-model": "^3.8.
|
|
38
|
-
"@xyo-network/payload-builder": "^3.8.
|
|
39
|
-
"@xyo-network/payload-model": "^3.8.
|
|
40
|
-
"@xyo-network/payload-wrapper": "^3.8.
|
|
41
|
-
"@xyo-network/sentinel-abstract": "^3.8.
|
|
42
|
-
"@xyo-network/sentinel-model": "^3.8.
|
|
43
|
-
"@xyo-network/witness-model": "^3.8.
|
|
36
|
+
"@xyo-network/diviner-model": "^3.8.2",
|
|
37
|
+
"@xyo-network/module-model": "^3.8.2",
|
|
38
|
+
"@xyo-network/payload-builder": "^3.8.2",
|
|
39
|
+
"@xyo-network/payload-model": "^3.8.2",
|
|
40
|
+
"@xyo-network/payload-wrapper": "^3.8.2",
|
|
41
|
+
"@xyo-network/sentinel-abstract": "^3.8.2",
|
|
42
|
+
"@xyo-network/sentinel-model": "^3.8.2",
|
|
43
|
+
"@xyo-network/witness-model": "^3.8.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@xylabs/delay": "^4.5.1",
|
|
47
|
-
"@xylabs/ts-scripts-yarn3": "^
|
|
48
|
-
"@xylabs/tsconfig": "^
|
|
47
|
+
"@xylabs/ts-scripts-yarn3": "^5.0.22",
|
|
48
|
+
"@xylabs/tsconfig": "^5.0.22",
|
|
49
49
|
"@xylabs/vitest-extended": "^4.5.1",
|
|
50
|
-
"@xyo-network/abstract-witness": "^3.8.
|
|
51
|
-
"@xyo-network/archivist-memory": "^3.8.
|
|
52
|
-
"@xyo-network/id-payload-plugin": "^3.8.
|
|
53
|
-
"@xyo-network/node-memory": "^3.8.
|
|
54
|
-
"@xyo-network/witness-adhoc": "^3.8.
|
|
50
|
+
"@xyo-network/abstract-witness": "^3.8.2",
|
|
51
|
+
"@xyo-network/archivist-memory": "^3.8.2",
|
|
52
|
+
"@xyo-network/id-payload-plugin": "^3.8.2",
|
|
53
|
+
"@xyo-network/node-memory": "^3.8.2",
|
|
54
|
+
"@xyo-network/witness-adhoc": "^3.8.2",
|
|
55
55
|
"typescript": "^5.7.3",
|
|
56
|
-
"vitest": "^3.0.
|
|
56
|
+
"vitest": "^3.0.5"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
package/src/SentinelRunner.ts
CHANGED
|
@@ -22,6 +22,7 @@ export class SentinelRunner {
|
|
|
22
22
|
constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {
|
|
23
23
|
this.sentinel = sentinel
|
|
24
24
|
this.onTriggerResult = onTriggerResult
|
|
25
|
+
// eslint-disable-next-line sonarjs/no-async-constructor
|
|
25
26
|
if (automations) for (const automation of automations) forget(this.add(automation))
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -97,14 +98,14 @@ export class SentinelRunner {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
async update(hash: string, automation: SentinelAutomationPayload, restart = true) {
|
|
100
|
-
|
|
101
|
+
this.remove(hash, false)
|
|
101
102
|
await this.add(automation, false)
|
|
102
|
-
if (restart)
|
|
103
|
+
if (restart) this.restart()
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
private async trigger(automation: SentinelIntervalAutomationPayload) {
|
|
106
107
|
const wrapper = new SentinelIntervalAutomationWrapper(automation)
|
|
107
|
-
|
|
108
|
+
this.remove(await wrapper.dataHash(), false)
|
|
108
109
|
wrapper.next()
|
|
109
110
|
await this.add(wrapper.payload, false)
|
|
110
111
|
const triggerResult = await this.sentinel.report()
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AnyConfigSchema } from '@xyo-network/module-model';
|
|
2
|
-
import type { Payload, Schema } from '@xyo-network/payload-model';
|
|
3
|
-
import { AbstractSentinel } from '@xyo-network/sentinel-abstract';
|
|
4
|
-
import type { SentinelConfig, SentinelInstance, SentinelModuleEventData, SentinelParams } from '@xyo-network/sentinel-model';
|
|
5
|
-
export type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<TConfig>;
|
|
6
|
-
export declare class MemorySentinel<TParams extends MemorySentinelParams = MemorySentinelParams, TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>> extends AbstractSentinel<TParams, TEventData> {
|
|
7
|
-
static readonly configSchemas: Schema[];
|
|
8
|
-
static readonly defaultConfigSchema: Schema;
|
|
9
|
-
private runner?;
|
|
10
|
-
reportHandler(inPayloads?: Payload[]): Promise<Payload[]>;
|
|
11
|
-
start(timeout?: number | undefined): Promise<boolean>;
|
|
12
|
-
stop(timeout?: number | undefined): Promise<boolean>;
|
|
13
|
-
private inputAddresses;
|
|
14
|
-
private processPreviousResults;
|
|
15
|
-
private runJob;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=MemorySentinel.d.ts.map
|
|
@@ -1 +0,0 @@
|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yo-network/payload-wrapper';
|
|
2
|
-
import type { SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model';
|
|
3
|
-
export declare class SentinelIntervalAutomationWrapper<T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload> extends PayloadWrapper<T> {
|
|
4
|
-
constructor(payload: T);
|
|
5
|
-
protected get frequencyMillis(): number;
|
|
6
|
-
protected get remaining(): number;
|
|
7
|
-
next(): this;
|
|
8
|
-
protected checkEnd(): void;
|
|
9
|
-
protected consumeRemaining(count?: number): void;
|
|
10
|
-
/**
|
|
11
|
-
* Sets the remaining of the wrapped automation
|
|
12
|
-
* @param remaining The remaining time in milliseconds
|
|
13
|
-
*/
|
|
14
|
-
protected setRemaining(remaining: number): void;
|
|
15
|
-
/**
|
|
16
|
-
* Sets the start of the wrapped automation
|
|
17
|
-
* @param start The start time in milliseconds
|
|
18
|
-
*/
|
|
19
|
-
protected setStart(start: number): void;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=SentinelIntervalAutomationWrapper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SentinelIntervalAutomationWrapper.d.ts","sourceRoot":"","sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAA;AAEpF,qBAAa,iCAAiC,CAC5C,CAAC,SAAS,iCAAiC,GAAG,iCAAiC,CAC/E,SAAQ,cAAc,CAAC,CAAC,CAAC;gBACb,OAAO,EAAE,CAAC;IAItB,SAAS,KAAK,eAAe,WAwB5B;IAED,SAAS,KAAK,SAAS,WAEtB;IAED,IAAI;IAWJ,SAAS,CAAC,QAAQ;IAMlB,SAAS,CAAC,gBAAgB,CAAC,KAAK,SAAI;IAMpC;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM;IAIxC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;CAGjC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Payload } from '@xyo-network/payload-model';
|
|
2
|
-
import type { SentinelAutomationPayload, SentinelInstance } from '@xyo-network/sentinel-model';
|
|
3
|
-
export type OnSentinelRunnerTriggerResult = (result: Payload[]) => void;
|
|
4
|
-
export declare class SentinelRunner {
|
|
5
|
-
protected _automations: Record<string, SentinelAutomationPayload>;
|
|
6
|
-
protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined;
|
|
7
|
-
protected sentinel: SentinelInstance;
|
|
8
|
-
protected timeoutId?: NodeJS.Timeout | string | number;
|
|
9
|
-
constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult);
|
|
10
|
-
get automations(): Record<string, SentinelAutomationPayload>;
|
|
11
|
-
private get next();
|
|
12
|
-
add(automation: SentinelAutomationPayload, restart?: boolean): Promise<Lowercase<string>>;
|
|
13
|
-
find(hash: string): [string, SentinelAutomationPayload] | undefined;
|
|
14
|
-
remove(hash: string, restart?: boolean): void;
|
|
15
|
-
removeAll(): void;
|
|
16
|
-
restart(): void;
|
|
17
|
-
start(): void;
|
|
18
|
-
stop(): void;
|
|
19
|
-
update(hash: string, automation: SentinelAutomationPayload, restart?: boolean): Promise<void>;
|
|
20
|
-
private trigger;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=SentinelRunner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAEjB,MAAM,6BAA6B,CAAA;AAKpC,MAAM,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEvE,qBAAa,cAAc;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAK;IACtE,SAAS,CAAC,eAAe,EAAE,6BAA6B,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACpC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;gBAE1C,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,yBAAyB,EAAE,EAAE,eAAe,CAAC,EAAE,6BAA6B;IAMlI,IAAI,WAAW,8CAEd;IAED,OAAO,KAAK,IAAI,GASf;IAEK,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;IAO/D,IAAI,CAAC,IAAI,EAAE,MAAM;IAIjB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO;IAKnC,SAAS;IAKT,OAAO;IAKP,KAAK;IAuBL,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,wCAAwC,CAAA;AACtD,cAAc,qBAAqB,CAAA"}
|