@xyo-network/sentinel-memory 3.0.6 → 3.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemorySentinel.d.ts","sourceRoot":"","sources":["../../src/MemorySentinel.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,2BAA2B,CAAA;AAClF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAEV,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACf,MAAM,6BAA6B,CAAA;AASpC,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,eAAe,CAAC,cAAc,CAAC,GAAG,eAAe,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC,OAAO,CAAC,CAAA;AAE7I,qBAAa,cAAc,CACzB,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,EAC3D,UAAU,SAAS,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAC1H,SAAQ,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAiD;IACjG,gBAAyB,mBAAmB,EAAE,MAAM,CAAuB;IAE3E,OAAO,CAAC,MAAM,CAAC,CAAgB;IAEzB,aAAa,CAAC,UAAU,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAiBpD,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAWrD,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;YAQrD,cAAc;IAS5B,OAAO,CAAC,sBAAsB;YAIhB,MAAM;CA2ErB"}
@@ -0,0 +1,13 @@
1
+ import { PayloadWrapper } from '@xyo-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
+ protected setRemaining(remaining: number): void;
11
+ protected setStart(start: number): void;
12
+ }
13
+ //# sourceMappingURL=SentinelIntervalAutomationWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SentinelIntervalAutomationWrapper.d.ts","sourceRoot":"","sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,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,WAqB5B;IAED,SAAS,KAAK,SAAS,WAEtB;IAED,IAAI;IAWJ,SAAS,CAAC,QAAQ;IAMlB,SAAS,CAAC,gBAAgB,CAAC,KAAK,SAAI;IAUpC,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM;IAQxC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;CAGjC"}
@@ -0,0 +1,22 @@
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
@@ -0,0 +1 @@
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,51 +1,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 };
1
+ export * from './MemorySentinel.ts';
2
+ export * from './SentinelIntervalAutomationWrapper.ts';
3
+ export * from './SentinelRunner.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -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 } 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', { address: witness.address, inPayloads: inPayloadsFound, mod: 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, mod: this, outPayloads: observed })\n return [witness.address, observed]\n }\n const diviner = asDivinerInstance(task.mod)\n if (diviner) {\n await this.emit('taskStart', { address: diviner.address, inPayloads: inPayloadsFound, mod: 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, mod: this, outPayloads: divined })\n return [diviner.address, divined]\n }\n const sentinel = asSentinelInstance(task.mod)\n if (sentinel) {\n await this.emit('taskStart', { address: sentinel.address, inPayloads: inPayloadsFound, mod: 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, mod: 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, mod: 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 type { Payload } from '@xyo-network/payload-model'\nimport type {\n SentinelAutomationPayload,\n SentinelInstance,\n SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model'\nimport {\n isSentinelIntervalAutomation,\n} 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 '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;AAOjC,SACEC,oBACAC,4BACK;AACP,SAASC,yBAAyB;;;AChBlC,SAASC,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,sBAAsB;AAM/B,SACEC,oCACK;;;ACVP,SAASC,sBAAsB;AAGxB,IAAMC,oCAAN,cAEGC,eAAAA;EALV,OAKUA;;;EACRC,YAAYC,SAAY;AACtB,UAAMA,OAAAA;EACR;EAEA,IAAcC,kBAAkB;AAC9B,UAAMC,YAAY,KAAKF,QAAQE;AAC/B,QAAIA,cAAcC,OAAW,QAAOC,OAAOC;AAC3C,UAAMC,iBAAiB,KAAKN,QAAQM;AACpC,YAAQA,kBAAkB,QAAA;MACxB,KAAK,UAAU;AACb,eAAOJ,YAAY;MACrB;MACA,KAAK,UAAU;AACb,eAAOA,YAAY,KAAK;MAC1B;MACA,KAAK,QAAQ;AACX,eAAOA,YAAY,KAAK,KAAK;MAC/B;MACA,KAAK,OAAO;AACV,eAAOA,YAAY,KAAK,KAAK,KAAK;MACpC;MACA,SAAS;AACP,eAAOE,OAAOC;MAChB;IACF;EACF;EAEA,IAAcE,YAAY;AACxB,WAAO,KAAKP,QAAQO,aAAaH,OAAOC;EAC1C;EAEAG,OAAO;AACL,UAAMC,MA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AAY6C;UAAiBJ,KAAK;UAAMU,aAAaO;QAAS,CAAA;AACtH,eAAO;UAACF,SAASrB;UAASuB;;MAC5B;AACA,YAAM,IAAIE,MAAM,yBAAA;IAClB,CAAA,CAAA;AAEF,UAAMC,cAA0C,CAAC;AACjD,eAAW/C,UAAU4B,QAAQoB,OAAOC,SAAAA,GAAY;AAC9C,YAAM,CAAC5B,SAASE,QAAAA,IAAYvB,OAAOkD;AACnCH,kBAAY1B,OAAAA,IAAW0B,YAAY1B,OAAAA,KAAY,CAAA;AAC/C0B,kBAAY1B,OAAAA,EAAS8B,KAAI,GAAI5B,QAAAA;IAC/B;AACA,QAAI,KAAK6B,aAAa;AACpB,YAAMC,SAASzB,QAAQoB,OAAOM,QAAAA,EAAUrC,IAAIjB,CAAAA,WAAUA,OAAOuD,MAAM;AACnE,UAAIF,OAAOxD,SAAS,GAAG;AACrB,cAAM,IAAIiD,MAAM,4BAAA;MAClB;IACF;AACA,SAAK1D,QAAQC,MAAM,wBAAwBC,KAAKC,UAAUwD,WAAAA,CAAAA,EAAc;AACxE,UAAM,KAAKrB,KAAK,UAAU;MAAEqB;MAAa7D;MAAYyC,KAAK;IAAK,CAAA;AAC/D,WAAOoB;EACT;AACF;","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","configSchemas","SentinelConfigSchema","defaultConfigSchema","runner","reportHandler","inPayloads","started","logger","debug","JSON","stringify","job","jobPromise","index","previousResults","tasks","length","generatedPayloads","runJob","result","Object","values","flat","start","timeout","config","automations","SentinelRunner","stop","undefined","inputAddresses","input","Array","isArray","Promise","all","map","inputItem","resolved","resolve","address","processPreviousResults","payloads","inputs","flatMap","emit","mod","results","allSettled","task","inPayloadsFound","witness","asWitnessInstance","observed","observe","id","outPayloads","diviner","asDivinerInstance","divined","divine","sentinel","asSentinelInstance","reported","report","Error","finalResult","filter","fulfilled","value","push","throwErrors","errors","rejected","reason"]}
1
+ {"version":3,"sources":["../../src/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 '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;AAQjC,SACEC,oBACAC,4BACK;AACP,SAASC,yBAAyB;;;ACjBlC,SAASC,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,sBAAsB;AAO/B,SAASC,oCAAoC;;;ACT7C,SAASC,sBAAsB;AAGxB,IAAMC,oCAAN,cAEGC,eAAAA;EALV,OAKUA;;;EACRC,YAAYC,SAAY;AACtB,UAAMA,OAAAA;EACR;EAEA,IAAcC,kBAAkB;AAC9B,UAAMC,YAAY,KAAKF,QAAQE;AAC/B,QAAIA,cAAcC,OAAW,QAAOC,OAAOC;AAC3C,UAAMC,iBAAiB,KAAKN,QAAQM;AACpC,YAAQA,kBAAkB,QAAA;MACxB,KAAK,UAAU;AACb,eAAOJ,YAAY;MACrB;MACA,KAAK,UAAU;AACb,eAAOA,YAAY,KAAK;MAC1B;MACA,KAAK,QAAQ;AACX,eAAOA,YAAY,KAAK,KAAK;MAC/B;MACA,KAAK,OAAO;AACV,eAAOA,YAAY,KAAK,KAAK,KAAK;MACpC;MACA,SAAS;AACP,eAAOE,OAAOC;MAChB;IACF;EACF;EAEA,IAAcE,YAAY;AACxB,WAAO,KAAKP,QAAQO,aAAaH,OAAOC;EAC1C;EAEAG,OAAO;AACL,UAAMC,MAAMC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;UAAiBJ,KAAK;UAAMU,aAAaO;QAClF,CAAA;AACA,eAAO;UAACF,SAASrB;UAASuB;;MAC5B;AACA,YAAM,IAAIE,MAAM,yBAAA;IAClB,CAAA,CAAA;AAEF,UAAMC,cAA0C,CAAC;AACjD,eAAW/C,UAAU4B,QAAQoB,OAAOC,SAAAA,GAAY;AAC9C,YAAM,CAAC5B,SAASE,QAAAA,IAAYvB,OAAOkD;AACnCH,kBAAY1B,OAAAA,IAAW0B,YAAY1B,OAAAA,KAAY,CAAA;AAC/C0B,kBAAY1B,OAAAA,EAAS8B,KAAI,GAAI5B,QAAAA;IAC/B;AACA,QAAI,KAAK6B,aAAa;AACpB,YAAMC,SAASzB,QAAQoB,OAAOM,QAAAA,EAAUrC,IAAIjB,CAAAA,WAAUA,OAAOuD,MAAM;AACnE,UAAIF,OAAOxD,SAAS,GAAG;AACrB,cAAM,IAAIiD,MAAM,4BAAA;MAClB;IACF;AACA,SAAK1D,QAAQC,MAAM,wBAAwBC,KAAKC,UAAUwD,WAAAA,CAAAA,EAAc;AACxE,UAAM,KAAKrB,KAAK,UAAU;MACxBqB;MAAa7D;MAAYyC,KAAK;IAChC,CAAA;AACA,WAAOoB;EACT;AACF;","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","configSchemas","SentinelConfigSchema","defaultConfigSchema","runner","reportHandler","inPayloads","started","logger","debug","JSON","stringify","job","jobPromise","index","previousResults","tasks","length","generatedPayloads","runJob","result","Object","values","flat","start","timeout","config","automations","SentinelRunner","stop","undefined","inputAddresses","input","Array","isArray","Promise","all","map","inputItem","resolved","resolve","address","processPreviousResults","payloads","inputs","flatMap","emit","mod","results","allSettled","task","inPayloadsFound","witness","asWitnessInstance","observed","observe","id","outPayloads","diviner","asDivinerInstance","divined","divine","sentinel","asSentinelInstance","reported","report","Error","finalResult","filter","fulfilled","value","push","throwErrors","errors","rejected","reason"]}
package/package.json CHANGED
@@ -1,41 +1,24 @@
1
1
  {
2
2
  "name": "@xyo-network/sentinel-memory",
3
- "author": {
4
- "email": "support@xyo.network",
5
- "name": "XYO Development Team",
6
- "url": "https://xyo.network"
7
- },
3
+ "version": "3.0.8",
4
+ "description": "Primary SDK for using XYO Protocol 2.0",
5
+ "homepage": "https://xyo.network",
8
6
  "bugs": {
9
- "email": "support@xyo.network",
10
- "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
7
+ "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues",
8
+ "email": "support@xyo.network"
11
9
  },
12
- "dependencies": {
13
- "@xylabs/assert": "^4.0.2",
14
- "@xylabs/forget": "^4.0.2",
15
- "@xylabs/hex": "^4.0.2",
16
- "@xylabs/promise": "^4.0.2",
17
- "@xyo-network/diviner-model": "^3.0.6",
18
- "@xyo-network/module-model": "^3.0.6",
19
- "@xyo-network/payload-builder": "^3.0.6",
20
- "@xyo-network/payload-model": "^3.0.6",
21
- "@xyo-network/payload-wrapper": "^3.0.6",
22
- "@xyo-network/sentinel-abstract": "^3.0.6",
23
- "@xyo-network/sentinel-model": "^3.0.6",
24
- "@xyo-network/witness-model": "^3.0.6"
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
25
13
  },
26
- "description": "Primary SDK for using XYO Protocol 2.0",
27
- "devDependencies": {
28
- "@xylabs/delay": "^4.0.2",
29
- "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.30",
30
- "@xylabs/tsconfig": "^4.0.0-rc.30",
31
- "@xyo-network/abstract-witness": "^3.0.6",
32
- "@xyo-network/archivist-memory": "^3.0.6",
33
- "@xyo-network/id-payload-plugin": "^3.0.6",
34
- "@xyo-network/node-memory": "^3.0.6",
35
- "@xyo-network/witness-adhoc": "^3.0.6",
36
- "typescript": "^5.5.4"
14
+ "license": "LGPL-3.0-only",
15
+ "author": {
16
+ "name": "XYO Development Team",
17
+ "email": "support@xyo.network",
18
+ "url": "https://xyo.network"
37
19
  },
38
- "types": "dist/neutral/index.d.ts",
20
+ "sideEffects": false,
21
+ "type": "module",
39
22
  "exports": {
40
23
  ".": {
41
24
  "types": "./dist/neutral/index.d.ts",
@@ -44,16 +27,33 @@
44
27
  "./package.json": "./package.json"
45
28
  },
46
29
  "module": "dist/neutral/index.mjs",
47
- "homepage": "https://xyo.network",
48
- "license": "LGPL-3.0-only",
49
- "publishConfig": {
50
- "access": "public"
30
+ "types": "dist/neutral/index.d.ts",
31
+ "dependencies": {
32
+ "@xylabs/assert": "^4.0.3",
33
+ "@xylabs/forget": "^4.0.3",
34
+ "@xylabs/hex": "^4.0.3",
35
+ "@xylabs/promise": "^4.0.3",
36
+ "@xyo-network/diviner-model": "^3.0.8",
37
+ "@xyo-network/module-model": "^3.0.8",
38
+ "@xyo-network/payload-builder": "^3.0.8",
39
+ "@xyo-network/payload-model": "^3.0.8",
40
+ "@xyo-network/payload-wrapper": "^3.0.8",
41
+ "@xyo-network/sentinel-abstract": "^3.0.8",
42
+ "@xyo-network/sentinel-model": "^3.0.8",
43
+ "@xyo-network/witness-model": "^3.0.8"
51
44
  },
52
- "repository": {
53
- "type": "git",
54
- "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
45
+ "devDependencies": {
46
+ "@xylabs/delay": "^4.0.3",
47
+ "@xylabs/ts-scripts-yarn3": "^4.0.7",
48
+ "@xylabs/tsconfig": "^4.0.7",
49
+ "@xyo-network/abstract-witness": "^3.0.8",
50
+ "@xyo-network/archivist-memory": "^3.0.8",
51
+ "@xyo-network/id-payload-plugin": "^3.0.8",
52
+ "@xyo-network/node-memory": "^3.0.8",
53
+ "@xyo-network/witness-adhoc": "^3.0.8",
54
+ "typescript": "^5.5.4"
55
55
  },
56
- "sideEffects": false,
57
- "version": "3.0.6",
58
- "type": "module"
56
+ "publishConfig": {
57
+ "access": "public"
58
+ }
59
59
  }
@@ -9,7 +9,8 @@ import type {
9
9
  SentinelConfig,
10
10
  SentinelInstance,
11
11
  SentinelModuleEventData,
12
- SentinelParams } from '@xyo-network/sentinel-model'
12
+ SentinelParams,
13
+ } from '@xyo-network/sentinel-model'
13
14
  import {
14
15
  asSentinelInstance,
15
16
  SentinelConfigSchema,
@@ -98,26 +99,38 @@ export class MemorySentinel<
98
99
  : this.processPreviousResults(previousResults, await this.inputAddresses(input))
99
100
  const witness = asWitnessInstance(task.mod)
100
101
  if (witness) {
101
- await this.emit('taskStart', { address: witness.address, inPayloads: inPayloadsFound, mod: this })
102
+ await this.emit('taskStart', {
103
+ address: witness.address, inPayloads: inPayloadsFound, mod: this,
104
+ })
102
105
  const observed = await witness.observe(inPayloadsFound)
103
106
  this.logger?.debug(`observed [${witness.id}]: ${JSON.stringify(observed)}`)
104
- await this.emit('taskEnd', { address: witness.address, inPayloads: inPayloadsFound, mod: this, outPayloads: observed })
107
+ await this.emit('taskEnd', {
108
+ address: witness.address, inPayloads: inPayloadsFound, mod: this, outPayloads: observed,
109
+ })
105
110
  return [witness.address, observed]
106
111
  }
107
112
  const diviner = asDivinerInstance(task.mod)
108
113
  if (diviner) {
109
- await this.emit('taskStart', { address: diviner.address, inPayloads: inPayloadsFound, mod: this })
114
+ await this.emit('taskStart', {
115
+ address: diviner.address, inPayloads: inPayloadsFound, mod: this,
116
+ })
110
117
  const divined = await diviner.divine(inPayloadsFound)
111
118
  this.logger?.debug(`divined [${diviner.id}]: ${JSON.stringify(divined)}`)
112
- await this.emit('taskEnd', { address: diviner.address, inPayloads: inPayloadsFound, mod: this, outPayloads: divined })
119
+ await this.emit('taskEnd', {
120
+ address: diviner.address, inPayloads: inPayloadsFound, mod: this, outPayloads: divined,
121
+ })
113
122
  return [diviner.address, divined]
114
123
  }
115
124
  const sentinel = asSentinelInstance(task.mod)
116
125
  if (sentinel) {
117
- await this.emit('taskStart', { address: sentinel.address, inPayloads: inPayloadsFound, mod: this })
126
+ await this.emit('taskStart', {
127
+ address: sentinel.address, inPayloads: inPayloadsFound, mod: this,
128
+ })
118
129
  const reported = await sentinel.report(inPayloadsFound)
119
130
  this.logger?.debug(`reported [${sentinel.id}]: ${JSON.stringify(reported)}`)
120
- await this.emit('taskEnd', { address: sentinel.address, inPayloads: inPayloadsFound, mod: this, outPayloads: reported })
131
+ await this.emit('taskEnd', {
132
+ address: sentinel.address, inPayloads: inPayloadsFound, mod: this, outPayloads: reported,
133
+ })
121
134
  return [sentinel.address, reported]
122
135
  }
123
136
  throw new Error('Unsupported module type')
@@ -136,7 +149,9 @@ export class MemorySentinel<
136
149
  }
137
150
  }
138
151
  this.logger?.debug(`generateResults:out: ${JSON.stringify(finalResult)}`)
139
- await this.emit('jobEnd', { finalResult, inPayloads, mod: this })
152
+ await this.emit('jobEnd', {
153
+ finalResult, inPayloads, mod: this,
154
+ })
140
155
  return finalResult
141
156
  }
142
157
  }
@@ -5,10 +5,9 @@ import type { Payload } from '@xyo-network/payload-model'
5
5
  import type {
6
6
  SentinelAutomationPayload,
7
7
  SentinelInstance,
8
- SentinelIntervalAutomationPayload } from '@xyo-network/sentinel-model'
9
- import {
10
- isSentinelIntervalAutomation,
8
+ SentinelIntervalAutomationPayload,
11
9
  } from '@xyo-network/sentinel-model'
10
+ import { isSentinelIntervalAutomation } from '@xyo-network/sentinel-model'
12
11
 
13
12
  import { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper.ts'
14
13
 
package/xy.config.ts CHANGED
@@ -2,9 +2,7 @@ import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
2
  const config: XyTsupConfig = {
3
3
  compile: {
4
4
  browser: {},
5
- neutral: {
6
- src: true,
7
- },
5
+ neutral: { src: true },
8
6
  node: {},
9
7
  },
10
8
  }