@xyo-network/sentinel 2.82.0-rc.1 → 2.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/Automation.d.cts +41 -13
- package/dist/browser/Automation.d.cts.map +1 -1
- package/dist/browser/Automation.d.mts +41 -13
- package/dist/browser/Automation.d.mts.map +1 -1
- package/dist/browser/Automation.d.ts +41 -13
- package/dist/browser/Automation.d.ts.map +1 -1
- package/dist/browser/SentinelRunner.d.cts.map +1 -1
- package/dist/browser/SentinelRunner.d.mts.map +1 -1
- package/dist/browser/SentinelRunner.d.ts.map +1 -1
- package/dist/browser/Wrapper.d.cts +1 -1
- package/dist/browser/Wrapper.d.cts.map +1 -1
- package/dist/browser/Wrapper.d.mts +1 -1
- package/dist/browser/Wrapper.d.mts.map +1 -1
- package/dist/browser/Wrapper.d.ts +1 -1
- package/dist/browser/Wrapper.d.ts.map +1 -1
- package/dist/browser/index.cjs +22 -12
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +22 -12
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Automation.d.cts +41 -13
- package/dist/node/Automation.d.cts.map +1 -1
- package/dist/node/Automation.d.mts +41 -13
- package/dist/node/Automation.d.mts.map +1 -1
- package/dist/node/Automation.d.ts +41 -13
- package/dist/node/Automation.d.ts.map +1 -1
- package/dist/node/SentinelRunner.d.cts.map +1 -1
- package/dist/node/SentinelRunner.d.mts.map +1 -1
- package/dist/node/SentinelRunner.d.ts.map +1 -1
- package/dist/node/Wrapper.d.cts +1 -1
- package/dist/node/Wrapper.d.cts.map +1 -1
- package/dist/node/Wrapper.d.mts +1 -1
- package/dist/node/Wrapper.d.mts.map +1 -1
- package/dist/node/Wrapper.d.ts +1 -1
- package/dist/node/Wrapper.d.ts.map +1 -1
- package/dist/node/index.js +25 -12
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +22 -12
- package/dist/node/index.mjs.map +1 -1
- package/package.json +23 -24
- package/src/Automation.ts +31 -15
- package/src/SentinelIntervalAutomationWrapper.ts +7 -7
- package/src/SentinelRunner.ts +9 -6
- package/typedoc.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Automation.ts","../../src/MemorySentinel.ts","../../src/SentinelIntervalAutomationWrapper.ts","../../src/SentinelRunner.ts","../../src/Wrapper.ts","../../src/index.ts"],"sourcesContent":["import { AnyObject } from '@xyo-network/core'\nimport { Payload } from '@xyo-network/payload-model'\nimport { Task } from '@xyo-network/sentinel-model'\n\nexport type SentinelAutomationSchema = 'network.xyo.automation'\nexport const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'\n\nexport type SentinelBaseAutomationPayload<T extends AnyObject = AnyObject> = Payload<\n T & {\n schema: SentinelAutomationSchema\n tasks?: Task[]\n type?: 'interval' | 'change'\n }\n>\n\nexport type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{\n /** @field epoch after which any reoccurrence stops */\n end?: number\n\n /** @field time between triggers [non-repeating if undefined] */\n frequency?: number\n\n /** @field units for frequency field [hour if undefined] */\n frequencyUnits?: 'second' | 'minute' | 'hour' | 'day'\n\n /** @field remaining triggers [infinite if undefined] */\n remaining?: number\n\n /** @field epoch of the next trigger */\n start: number\n\n type: 'interval'\n}>\n\nexport type SentinelChangeAutomationPayload = SentinelBaseAutomationPayload<{\n type: 'change'\n}>\n\nexport type SentinelAutomationPayload = SentinelIntervalAutomationPayload | SentinelChangeAutomationPayload\n","import { Address } from '@xylabs/hex'\nimport { fulfilled } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport {\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\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 configSchemas = [SentinelConfigSchema]\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\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.generateResults(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n return Object.values(previousResults).flat()\n }\n\n private async generateResults(\n tasks: ResolvedTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const witness = asWitnessInstance(task.module)\n const input = task.input ?? false\n const inPayloadsFound =\n input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n if (witness) {\n return [witness.address, await witness.observe(inPayloadsFound)]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n return [diviner.address, await diviner.divine(inPayloadsFound)]\n }\n throw Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n results.filter(fulfilled).forEach((result) => {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n })\n /*const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw Error('At least one module failed')\n }*/\n return finalResult\n }\n\n private async inputAddresses(input: string | string[]): Promise<string[]> {\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.map((input) => payloads[input] ?? []).flat()\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.payload().frequency\n if (frequency === undefined) return Infinity\n switch (this.payload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.payload().start = this.payload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload().start > (this.payload().end ?? Infinity)) {\n this.payload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.payload().remaining = remaining\n\n if (remaining <= 0) {\n this.payload().start = Infinity\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nimport { SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation'\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n automations?.forEach((automation) => this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n return Object.values(this._automations).reduce<SentinelIntervalAutomationPayload | undefined>((previous, current) => {\n if (current.type === 'interval') {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (automation) {\n const delay = automation.start - Date.now()\n if (delay < 0) {\n //automation is due, just do it\n await this.trigger(automation)\n } else {\n this.timeoutId = setTimeout(\n async () => {\n this.timeoutId = undefined\n await this.start()\n },\n delay > 0 ? delay : 0,\n )\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.payload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n await this.start()\n }\n}\n","import { ArchivistInstance } from '@xyo-network/archivist'\nimport { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module-wrapper'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n isSentinelInstance,\n isSentinelModule,\n SentinelInstance,\n SentinelModule,\n SentinelReportQuery,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { WitnessInstance } from '@xyo-network/witness-model'\n\nconstructableModuleWrapper()\nexport class SentinelWrapper<TModule extends SentinelModule = SentinelModule>\n extends ModuleWrapper<TModule>\n implements SentinelInstance<TModule['params']>\n{\n static override instanceIdentityCheck = isSentinelInstance\n static override moduleIdentityCheck = isSentinelModule\n static override requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries]\n\n archivists(): Promise<ArchivistInstance[]> {\n throw Error('Not supported')\n }\n\n async report(payloads?: Payload[]): Promise<Payload[]> {\n const queryPayload: SentinelReportQuery = { schema: SentinelReportQuerySchema }\n const result = await this.sendQuery(queryPayload, payloads)\n return result\n }\n\n witnesses(): Promise<WitnessInstance[]> {\n throw Error('Not supported')\n }\n}\n","export * from './Automation'\nexport * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\nexport * from './Wrapper'\nexport * from '@xyo-network/sentinel-abstract'\nexport * from '@xyo-network/sentinel-model'\n"],"mappings":";AAKO,IAAM,2BAAqD;;;ACJlE,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAGlC,SAAS,wBAAwB;AACjC;AAAA,EAGE;AAAA,OAIK;AACP,SAAS,yBAAyB;AAI3B,IAAM,iBAAN,cAGG,iBAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,oBAAoB;AAAA,EAErD,MAAM,cAAc,aAAwB,CAAC,GAAuB;AAClE,UAAM,KAAK,QAAQ,OAAO;AAC1B,UAAM,MAAM,MAAM,KAAK;AAEvB,QAAI,QAAQ;AACZ,QAAI,kBAA8C,CAAC;AACnD,WAAO,QAAQ,IAAI,MAAM,QAAQ;AAC/B,YAAM,oBAAoB,MAAM,KAAK,gBAAgB,IAAI,MAAM,KAAK,GA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A,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;;;AC9BA,cAAc;AACd,cAAc;","names":["PayloadWrapper","PayloadWrapper"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Automation.ts","../../src/MemorySentinel.ts","../../src/SentinelIntervalAutomationWrapper.ts","../../src/SentinelRunner.ts","../../src/Wrapper.ts","../../src/index.ts"],"sourcesContent":["import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\nimport { Task } from '@xyo-network/sentinel-model'\n\nexport type SentinelAutomationSchema = 'network.xyo.automation'\nexport const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'\n\nexport type SentinelIntervalAutomationSchema = 'network.xyo.automation.interval'\nexport const SentinelIntervalAutomationSchema: SentinelIntervalAutomationSchema = 'network.xyo.automation.interval'\n\nexport type SentinelEventAutomationSchema = 'network.xyo.automation.event'\nexport const SentinelEventAutomationSchema: SentinelEventAutomationSchema = 'network.xyo.automation.event'\n\nexport type SentinelBaseAutomationPayload<T extends Payload> = Payload<\n {\n tasks?: Task[]\n type?: 'interval' | 'event'\n } & T\n>\n\n/** Settings for an Interval Automation */\nexport type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{\n /** Epoch after which any reoccurrence stops */\n end?: number\n\n /** Time between triggers [non-repeating if undefined] */\n frequency?: number\n\n /** Units for frequency field [hour if undefined] */\n frequencyUnits?: 'second' | 'minute' | 'hour' | 'day'\n\n /** Remaining triggers [infinite if undefined] */\n remaining?: number\n\n schema: SentinelIntervalAutomationSchema\n\n /** Epoch of the next trigger */\n start: number\n\n /** The type of automation */\n type: 'interval'\n}>\n\nexport const isSentinelIntervalAutomation = isPayloadOfSchemaType<SentinelIntervalAutomationPayload>(SentinelIntervalAutomationSchema)\n\n/** Settings for an Event Automation */\nexport type SentinelEventAutomationPayload = SentinelBaseAutomationPayload<{\n schema: SentinelEventAutomationSchema\n type: 'event'\n}>\n\n/** Settings for an Automation */\nexport type SentinelAutomationPayload = Payload<\n SentinelIntervalAutomationPayload | SentinelEventAutomationPayload,\n SentinelAutomationSchema | SentinelIntervalAutomationSchema | SentinelEventAutomationSchema\n>\n","import { Address } from '@xylabs/hex'\nimport { fulfilled } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport {\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\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 configSchemas = [SentinelConfigSchema]\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\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.generateResults(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n return Object.values(previousResults).flat()\n }\n\n private async generateResults(\n tasks: ResolvedTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const witness = asWitnessInstance(task.module)\n const input = task.input ?? false\n const inPayloadsFound =\n input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n if (witness) {\n return [witness.address, await witness.observe(inPayloadsFound)]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n return [diviner.address, await diviner.divine(inPayloadsFound)]\n }\n throw Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n results.filter(fulfilled).forEach((result) => {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n })\n /*const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw Error('At least one module failed')\n }*/\n return finalResult\n }\n\n private async inputAddresses(input: string | string[]): Promise<string[]> {\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.map((input) => payloads[input] ?? []).flat()\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.jsonPayload().frequency\n if (frequency === undefined) return Infinity\n switch (this.jsonPayload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.jsonPayload().start = this.jsonPayload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.jsonPayload().start > (this.jsonPayload().end ?? Infinity)) {\n this.jsonPayload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.jsonPayload().remaining = remaining\n\n if (remaining <= 0) {\n this.jsonPayload().start = Infinity\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nimport { isSentinelIntervalAutomation, SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation'\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n automations?.forEach((automation) => this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n return Object.values(this._automations).reduce<SentinelAutomationPayload | undefined>((previous, current) => {\n if (isSentinelIntervalAutomation(current)) {\n if (isSentinelIntervalAutomation(previous)) {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }\n return current\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (isSentinelIntervalAutomation(automation)) {\n const delay = automation.start - Date.now()\n if (delay < 0) {\n //automation is due, just do it\n await this.trigger(automation)\n } else {\n this.timeoutId = setTimeout(\n async () => {\n this.timeoutId = undefined\n await this.start()\n },\n delay > 0 ? delay : 0,\n )\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.jsonPayload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n await this.start()\n }\n}\n","import { ArchivistInstance } from '@xyo-network/archivist'\nimport { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module-wrapper'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n isSentinelInstance,\n isSentinelModule,\n SentinelInstance,\n SentinelModule,\n SentinelReportQuery,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { WitnessInstance } from '@xyo-network/witness-model'\n\nconstructableModuleWrapper()\nexport class SentinelWrapper<TModule extends SentinelModule = SentinelModule>\n extends ModuleWrapper<TModule>\n implements SentinelInstance<TModule['params']>\n{\n static override instanceIdentityCheck = isSentinelInstance\n static override moduleIdentityCheck = isSentinelModule\n static override requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries]\n\n archivists(): Promise<ArchivistInstance[]> {\n throw Error('Not supported')\n }\n\n async report(payloads?: Payload[]): Promise<Payload[]> {\n const queryPayload: SentinelReportQuery = { schema: SentinelReportQuerySchema }\n const result = await this.sendQuery(queryPayload, payloads)\n return result\n }\n\n witnesses(): Promise<WitnessInstance[]> {\n throw Error('Not supported')\n }\n}\n","export * from './Automation'\nexport * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\nexport * from './Wrapper'\nexport * from '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AAkC,UAAU;AAChE,UAAM,KAAK,OAAO,MAAM,QAAQ,UAAU,GAAG,KAAK;AAClD,YAAQ,KAAK;AACb,UAAM,KAAK,IAAI,QAAQ,YAAY,GAAG,KAAK;AAC3C,UAAM,gBAAgB,MAAM,KAAK,SAAS,OAAO;AACjD,SAAK,kBAAkB,aAAa;AACpC,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;;;ACxGA,SAAS,4BAA4B,qBAAqB;AAE1D;AAAA,EACE;AAAA,EACA;AAAA,EAIA;AAAA,OACK;AAGP,2BAA2B;AACpB,IAAM,kBAAN,cACG,cAEV;AAAA,EACE,OAAgB,wBAAwB;AAAA,EACxC,OAAgB,sBAAsB;AAAA,EACtC,OAAgB,kBAAkB,CAAC,2BAA2B,GAAG,MAAM,eAAe;AAAA,EAEtF,aAA2C;AACzC,UAAM,MAAM,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,UAA0C;AACrD,UAAM,eAAoC,EAAE,QAAQ,0BAA0B;AAC9E,UAAM,SAAS,MAAM,KAAK,UAAU,cAAc,QAAQ;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;;;AC9BA,cAAc;AACd,cAAc;","names":["PayloadWrapper","PayloadWrapper"]}
|
|
@@ -1,28 +1,56 @@
|
|
|
1
|
-
import { AnyObject } from '@xyo-network/core';
|
|
2
1
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
2
|
import { Task } from '@xyo-network/sentinel-model';
|
|
4
3
|
export type SentinelAutomationSchema = 'network.xyo.automation';
|
|
5
4
|
export declare const SentinelAutomationSchema: SentinelAutomationSchema;
|
|
6
|
-
export type
|
|
7
|
-
|
|
5
|
+
export type SentinelIntervalAutomationSchema = 'network.xyo.automation.interval';
|
|
6
|
+
export declare const SentinelIntervalAutomationSchema: SentinelIntervalAutomationSchema;
|
|
7
|
+
export type SentinelEventAutomationSchema = 'network.xyo.automation.event';
|
|
8
|
+
export declare const SentinelEventAutomationSchema: SentinelEventAutomationSchema;
|
|
9
|
+
export type SentinelBaseAutomationPayload<T extends Payload> = Payload<{
|
|
8
10
|
tasks?: Task[];
|
|
9
|
-
type?: 'interval' | '
|
|
10
|
-
}>;
|
|
11
|
+
type?: 'interval' | 'event';
|
|
12
|
+
} & T>;
|
|
13
|
+
/** Settings for an Interval Automation */
|
|
11
14
|
export type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{
|
|
12
|
-
/**
|
|
15
|
+
/** Epoch after which any reoccurrence stops */
|
|
13
16
|
end?: number;
|
|
14
|
-
/**
|
|
17
|
+
/** Time between triggers [non-repeating if undefined] */
|
|
15
18
|
frequency?: number;
|
|
16
|
-
/**
|
|
19
|
+
/** Units for frequency field [hour if undefined] */
|
|
17
20
|
frequencyUnits?: 'second' | 'minute' | 'hour' | 'day';
|
|
18
|
-
/**
|
|
21
|
+
/** Remaining triggers [infinite if undefined] */
|
|
19
22
|
remaining?: number;
|
|
20
|
-
|
|
23
|
+
schema: SentinelIntervalAutomationSchema;
|
|
24
|
+
/** Epoch of the next trigger */
|
|
21
25
|
start: number;
|
|
26
|
+
/** The type of automation */
|
|
22
27
|
type: 'interval';
|
|
23
28
|
}>;
|
|
24
|
-
export
|
|
25
|
-
|
|
29
|
+
export declare const isSentinelIntervalAutomation: (x?: ({
|
|
30
|
+
schema: string;
|
|
31
|
+
} & import("@xyo-network/payload-model").PayloadFields) | null | undefined) => x is import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
32
|
+
tasks?: Task[] | undefined;
|
|
33
|
+
type?: "interval" | "event" | undefined;
|
|
34
|
+
} & {
|
|
35
|
+
/** Epoch after which any reoccurrence stops */
|
|
36
|
+
end?: number | undefined;
|
|
37
|
+
/** Time between triggers [non-repeating if undefined] */
|
|
38
|
+
frequency?: number | undefined;
|
|
39
|
+
/** Units for frequency field [hour if undefined] */
|
|
40
|
+
frequencyUnits?: "second" | "minute" | "hour" | "day" | undefined;
|
|
41
|
+
/** Remaining triggers [infinite if undefined] */
|
|
42
|
+
remaining?: number | undefined;
|
|
43
|
+
schema: SentinelIntervalAutomationSchema;
|
|
44
|
+
/** Epoch of the next trigger */
|
|
45
|
+
start: number;
|
|
46
|
+
/** The type of automation */
|
|
47
|
+
type: 'interval';
|
|
48
|
+
};
|
|
49
|
+
/** Settings for an Event Automation */
|
|
50
|
+
export type SentinelEventAutomationPayload = SentinelBaseAutomationPayload<{
|
|
51
|
+
schema: SentinelEventAutomationSchema;
|
|
52
|
+
type: 'event';
|
|
26
53
|
}>;
|
|
27
|
-
|
|
54
|
+
/** Settings for an Automation */
|
|
55
|
+
export type SentinelAutomationPayload = Payload<SentinelIntervalAutomationPayload | SentinelEventAutomationPayload, SentinelAutomationSchema | SentinelIntervalAutomationSchema | SentinelEventAutomationSchema>;
|
|
28
56
|
//# sourceMappingURL=Automation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Automation.d.ts","sourceRoot":"","sources":["../../src/Automation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Automation.d.ts","sourceRoot":"","sources":["../../src/Automation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAElD,MAAM,MAAM,wBAAwB,GAAG,wBAAwB,CAAA;AAC/D,eAAO,MAAM,wBAAwB,EAAE,wBAAmD,CAAA;AAE1F,MAAM,MAAM,gCAAgC,GAAG,iCAAiC,CAAA;AAChF,eAAO,MAAM,gCAAgC,EAAE,gCAAoE,CAAA;AAEnH,MAAM,MAAM,6BAA6B,GAAG,8BAA8B,CAAA;AAC1E,eAAO,MAAM,6BAA6B,EAAE,6BAA8D,CAAA;AAE1G,MAAM,MAAM,6BAA6B,CAAC,CAAC,SAAS,OAAO,IAAI,OAAO,CACpE;IACE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAA;IACd,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAA;CAC5B,GAAG,CAAC,CACN,CAAA;AAED,0CAA0C;AAC1C,MAAM,MAAM,iCAAiC,GAAG,6BAA6B,CAAC;IAC5E,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,oDAAoD;IACpD,cAAc,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAA;IAErD,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,MAAM,EAAE,gCAAgC,CAAA;IAExC,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAA;IAEb,6BAA6B;IAC7B,IAAI,EAAE,UAAU,CAAA;CACjB,CAAC,CAAA;AAEF,eAAO,MAAM,4BAA4B;;;;;;IArBvC,+CAA+C;;IAG/C,yDAAyD;;IAGzD,oDAAoD;;IAGpD,iDAAiD;;YAGzC,gCAAgC;IAExC,gCAAgC;WACzB,MAAM;IAEb,6BAA6B;UACvB,UAAU;CAGoH,CAAA;AAEtI,uCAAuC;AACvC,MAAM,MAAM,8BAA8B,GAAG,6BAA6B,CAAC;IACzE,MAAM,EAAE,6BAA6B,CAAA;IACrC,IAAI,EAAE,OAAO,CAAA;CACd,CAAC,CAAA;AAEF,iCAAiC;AACjC,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAC7C,iCAAiC,GAAG,8BAA8B,EAClE,wBAAwB,GAAG,gCAAgC,GAAG,6BAA6B,CAC5F,CAAA"}
|
|
@@ -1,28 +1,56 @@
|
|
|
1
|
-
import { AnyObject } from '@xyo-network/core';
|
|
2
1
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
2
|
import { Task } from '@xyo-network/sentinel-model';
|
|
4
3
|
export type SentinelAutomationSchema = 'network.xyo.automation';
|
|
5
4
|
export declare const SentinelAutomationSchema: SentinelAutomationSchema;
|
|
6
|
-
export type
|
|
7
|
-
|
|
5
|
+
export type SentinelIntervalAutomationSchema = 'network.xyo.automation.interval';
|
|
6
|
+
export declare const SentinelIntervalAutomationSchema: SentinelIntervalAutomationSchema;
|
|
7
|
+
export type SentinelEventAutomationSchema = 'network.xyo.automation.event';
|
|
8
|
+
export declare const SentinelEventAutomationSchema: SentinelEventAutomationSchema;
|
|
9
|
+
export type SentinelBaseAutomationPayload<T extends Payload> = Payload<{
|
|
8
10
|
tasks?: Task[];
|
|
9
|
-
type?: 'interval' | '
|
|
10
|
-
}>;
|
|
11
|
+
type?: 'interval' | 'event';
|
|
12
|
+
} & T>;
|
|
13
|
+
/** Settings for an Interval Automation */
|
|
11
14
|
export type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{
|
|
12
|
-
/**
|
|
15
|
+
/** Epoch after which any reoccurrence stops */
|
|
13
16
|
end?: number;
|
|
14
|
-
/**
|
|
17
|
+
/** Time between triggers [non-repeating if undefined] */
|
|
15
18
|
frequency?: number;
|
|
16
|
-
/**
|
|
19
|
+
/** Units for frequency field [hour if undefined] */
|
|
17
20
|
frequencyUnits?: 'second' | 'minute' | 'hour' | 'day';
|
|
18
|
-
/**
|
|
21
|
+
/** Remaining triggers [infinite if undefined] */
|
|
19
22
|
remaining?: number;
|
|
20
|
-
|
|
23
|
+
schema: SentinelIntervalAutomationSchema;
|
|
24
|
+
/** Epoch of the next trigger */
|
|
21
25
|
start: number;
|
|
26
|
+
/** The type of automation */
|
|
22
27
|
type: 'interval';
|
|
23
28
|
}>;
|
|
24
|
-
export
|
|
25
|
-
|
|
29
|
+
export declare const isSentinelIntervalAutomation: (x?: ({
|
|
30
|
+
schema: string;
|
|
31
|
+
} & import("@xyo-network/payload-model").PayloadFields) | null | undefined) => x is import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
32
|
+
tasks?: Task[] | undefined;
|
|
33
|
+
type?: "interval" | "event" | undefined;
|
|
34
|
+
} & {
|
|
35
|
+
/** Epoch after which any reoccurrence stops */
|
|
36
|
+
end?: number | undefined;
|
|
37
|
+
/** Time between triggers [non-repeating if undefined] */
|
|
38
|
+
frequency?: number | undefined;
|
|
39
|
+
/** Units for frequency field [hour if undefined] */
|
|
40
|
+
frequencyUnits?: "second" | "minute" | "hour" | "day" | undefined;
|
|
41
|
+
/** Remaining triggers [infinite if undefined] */
|
|
42
|
+
remaining?: number | undefined;
|
|
43
|
+
schema: SentinelIntervalAutomationSchema;
|
|
44
|
+
/** Epoch of the next trigger */
|
|
45
|
+
start: number;
|
|
46
|
+
/** The type of automation */
|
|
47
|
+
type: 'interval';
|
|
48
|
+
};
|
|
49
|
+
/** Settings for an Event Automation */
|
|
50
|
+
export type SentinelEventAutomationPayload = SentinelBaseAutomationPayload<{
|
|
51
|
+
schema: SentinelEventAutomationSchema;
|
|
52
|
+
type: 'event';
|
|
26
53
|
}>;
|
|
27
|
-
|
|
54
|
+
/** Settings for an Automation */
|
|
55
|
+
export type SentinelAutomationPayload = Payload<SentinelIntervalAutomationPayload | SentinelEventAutomationPayload, SentinelAutomationSchema | SentinelIntervalAutomationSchema | SentinelEventAutomationSchema>;
|
|
28
56
|
//# sourceMappingURL=Automation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Automation.d.ts","sourceRoot":"","sources":["../../src/Automation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Automation.d.ts","sourceRoot":"","sources":["../../src/Automation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAElD,MAAM,MAAM,wBAAwB,GAAG,wBAAwB,CAAA;AAC/D,eAAO,MAAM,wBAAwB,EAAE,wBAAmD,CAAA;AAE1F,MAAM,MAAM,gCAAgC,GAAG,iCAAiC,CAAA;AAChF,eAAO,MAA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@@ -1,28 +1,56 @@
|
|
|
1
|
-
import { AnyObject } from '@xyo-network/core';
|
|
2
1
|
import { Payload } from '@xyo-network/payload-model';
|
|
3
2
|
import { Task } from '@xyo-network/sentinel-model';
|
|
4
3
|
export type SentinelAutomationSchema = 'network.xyo.automation';
|
|
5
4
|
export declare const SentinelAutomationSchema: SentinelAutomationSchema;
|
|
6
|
-
export type
|
|
7
|
-
|
|
5
|
+
export type SentinelIntervalAutomationSchema = 'network.xyo.automation.interval';
|
|
6
|
+
export declare const SentinelIntervalAutomationSchema: SentinelIntervalAutomationSchema;
|
|
7
|
+
export type SentinelEventAutomationSchema = 'network.xyo.automation.event';
|
|
8
|
+
export declare const SentinelEventAutomationSchema: SentinelEventAutomationSchema;
|
|
9
|
+
export type SentinelBaseAutomationPayload<T extends Payload> = Payload<{
|
|
8
10
|
tasks?: Task[];
|
|
9
|
-
type?: 'interval' | '
|
|
10
|
-
}>;
|
|
11
|
+
type?: 'interval' | 'event';
|
|
12
|
+
} & T>;
|
|
13
|
+
/** Settings for an Interval Automation */
|
|
11
14
|
export type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{
|
|
12
|
-
/**
|
|
15
|
+
/** Epoch after which any reoccurrence stops */
|
|
13
16
|
end?: number;
|
|
14
|
-
/**
|
|
17
|
+
/** Time between triggers [non-repeating if undefined] */
|
|
15
18
|
frequency?: number;
|
|
16
|
-
/**
|
|
19
|
+
/** Units for frequency field [hour if undefined] */
|
|
17
20
|
frequencyUnits?: 'second' | 'minute' | 'hour' | 'day';
|
|
18
|
-
/**
|
|
21
|
+
/** Remaining triggers [infinite if undefined] */
|
|
19
22
|
remaining?: number;
|
|
20
|
-
|
|
23
|
+
schema: SentinelIntervalAutomationSchema;
|
|
24
|
+
/** Epoch of the next trigger */
|
|
21
25
|
start: number;
|
|
26
|
+
/** The type of automation */
|
|
22
27
|
type: 'interval';
|
|
23
28
|
}>;
|
|
24
|
-
export
|
|
25
|
-
|
|
29
|
+
export declare const isSentinelIntervalAutomation: (x?: ({
|
|
30
|
+
schema: string;
|
|
31
|
+
} & import("@xyo-network/payload-model").PayloadFields) | null | undefined) => x is import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
32
|
+
tasks?: Task[] | undefined;
|
|
33
|
+
type?: "interval" | "event" | undefined;
|
|
34
|
+
} & {
|
|
35
|
+
/** Epoch after which any reoccurrence stops */
|
|
36
|
+
end?: number | undefined;
|
|
37
|
+
/** Time between triggers [non-repeating if undefined] */
|
|
38
|
+
frequency?: number | undefined;
|
|
39
|
+
/** Units for frequency field [hour if undefined] */
|
|
40
|
+
frequencyUnits?: "second" | "minute" | "hour" | "day" | undefined;
|
|
41
|
+
/** Remaining triggers [infinite if undefined] */
|
|
42
|
+
remaining?: number | undefined;
|
|
43
|
+
schema: SentinelIntervalAutomationSchema;
|
|
44
|
+
/** Epoch of the next trigger */
|
|
45
|
+
start: number;
|
|
46
|
+
/** The type of automation */
|
|
47
|
+
type: 'interval';
|
|
48
|
+
};
|
|
49
|
+
/** Settings for an Event Automation */
|
|
50
|
+
export type SentinelEventAutomationPayload = SentinelBaseAutomationPayload<{
|
|
51
|
+
schema: SentinelEventAutomationSchema;
|
|
52
|
+
type: 'event';
|
|
26
53
|
}>;
|
|
27
|
-
|
|
54
|
+
/** Settings for an Automation */
|
|
55
|
+
export type SentinelAutomationPayload = Payload<SentinelIntervalAutomationPayload | SentinelEventAutomationPayload, SentinelAutomationSchema | SentinelIntervalAutomationSchema | SentinelEventAutomationSchema>;
|
|
28
56
|
//# sourceMappingURL=Automation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Automation.d.ts","sourceRoot":"","sources":["../../src/Automation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Automation.d.ts","sourceRoot":"","sources":["../../src/Automation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAC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BAA6B,CAAA;IACrC,IAAI,EAAE,OAAO,CAAA;CACd,CAAC,CAAA;AAEF,iCAAiC;AACjC,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAC7C,iCAAiC,GAAG,8BAA8B,EAClE,wBAAwB,GAAG,gCAAgC,GAAG,6BAA6B,CAC5F,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAE9D,OAAO,
|
|
1
|
+
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAE9D,OAAO,EAAgC,yBAAyB,EAAqC,MAAM,cAAc,CAAA;AAGzH,MAAM,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEvE,qBAAa,cAAc;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAK;IACtE,SAAS,CAAC,eAAe,EAAE,6BAA6B,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACpC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;gBAE1C,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,yBAAyB,EAAE,EAAE,eAAe,CAAC,EAAE,6BAA6B;IAMlI,IAAI,WAAW,8CAEd;IAED,OAAO,KAAK,IAAI,GASf;IAEK,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;IAO/D,IAAI,CAAC,IAAI,EAAE,MAAM;IAIX,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO;IAKzC,SAAS;IAKH,OAAO;IAKP,KAAK;IAoBX,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAE9D,OAAO,
|
|
1
|
+
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAE9D,OAAO,EAAgC,yBAAyB,EAAqC,MAAM,cAAc,CAAA;AAGzH,MAAM,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEvE,qBAAa,cAAc;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAK;IACtE,SAAS,CAAC,eAAe,EAAE,6BAA6B,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACpC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;gBAE1C,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,yBAAyB,EAAE,EAAE,eAAe,CAAC,EAAE,6BAA6B;IAMlI,IAAI,WAAW,8CAEd;IAED,OAAO,KAAK,IAAI,GASf;IAEK,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;IAO/D,IAAI,CAAC,IAAI,EAAE,MAAM;IAIX,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO;IAKzC,SAAS;IAKH,OAAO;IAKP,KAAK;IAoBX,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAE9D,OAAO,
|
|
1
|
+
{"version":3,"file":"SentinelRunner.d.ts","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAE9D,OAAO,EAAgC,yBAAyB,EAAqC,MAAM,cAAc,CAAA;AAGzH,MAAM,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAEvE,qBAAa,cAAc;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAK;IACtE,SAAS,CAAC,eAAe,EAAE,6BAA6B,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACpC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;gBAE1C,QAAQ,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,yBAAyB,EAAE,EAAE,eAAe,CAAC,EAAE,6BAA6B;IAMlI,IAAI,WAAW,8CAEd;IAED,OAAO,KAAK,IAAI,GASf;IAEK,GAAG,CAAC,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;IAO/D,IAAI,CAAC,IAAI,EAAE,MAAM;IAIX,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAO;IAKzC,SAAS;IAKH,OAAO;IAKP,KAAK;IAoBX,IAAI;IAOE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,OAAO,UAAO;YAMlE,OAAO;CAStB"}
|
package/dist/node/Wrapper.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ import { Payload } from '@xyo-network/payload-model';
|
|
|
4
4
|
import { SentinelInstance, SentinelModule } from '@xyo-network/sentinel-model';
|
|
5
5
|
import { WitnessInstance } from '@xyo-network/witness-model';
|
|
6
6
|
export declare class SentinelWrapper<TModule extends SentinelModule = SentinelModule> extends ModuleWrapper<TModule> implements SentinelInstance<TModule['params']> {
|
|
7
|
-
static instanceIdentityCheck: import("@xyo-network/object").
|
|
7
|
+
static instanceIdentityCheck: import("@xyo-network/object").TypeCheck<SentinelInstance>;
|
|
8
8
|
static moduleIdentityCheck: import("@xyo-network/module-model").ModuleTypeCheck<SentinelModule>;
|
|
9
9
|
static requiredQueries: string[];
|
|
10
10
|
archivists(): Promise<ArchivistInstance[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../src/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAA8B,aAAa,EAAE,MAAM,6BAA6B,CAAA;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAGL,gBAAgB,EAChB,cAAc,EAGf,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAG5D,qBAAa,eAAe,CAAC,OAAO,SAAS,cAAc,GAAG,cAAc,CAC1E,SAAQ,aAAa,CAAC,OAAO,CAC7B,YAAW,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAgB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../src/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAA8B,aAAa,EAAE,MAAM,6BAA6B,CAAA;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAGL,gBAAgB,EAChB,cAAc,EAGf,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAG5D,qBAAa,eAAe,CAAC,OAAO,SAAS,cAAc,GAAG,cAAc,CAC1E,SAAQ,aAAa,CAAC,OAAO,CAC7B,YAAW,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAgB,qBAAqB,4DAAqB;IAC1D,OAAgB,mBAAmB,sEAAmB;IACtD,OAAgB,eAAe,WAAwD;IAEvF,UAAU,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAIpC,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAMtD,SAAS,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CAGxC"}
|
package/dist/node/Wrapper.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { Payload } from '@xyo-network/payload-model';
|
|
|
4
4
|
import { SentinelInstance, SentinelModule } from '@xyo-network/sentinel-model';
|
|
5
5
|
import { WitnessInstance } from '@xyo-network/witness-model';
|
|
6
6
|
export declare class SentinelWrapper<TModule extends SentinelModule = SentinelModule> extends ModuleWrapper<TModule> implements SentinelInstance<TModule['params']> {
|
|
7
|
-
static instanceIdentityCheck: import("@xyo-network/object").
|
|
7
|
+
static instanceIdentityCheck: import("@xyo-network/object").TypeCheck<SentinelInstance>;
|
|
8
8
|
static moduleIdentityCheck: import("@xyo-network/module-model").ModuleTypeCheck<SentinelModule>;
|
|
9
9
|
static requiredQueries: string[];
|
|
10
10
|
archivists(): Promise<ArchivistInstance[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../src/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAA8B,aAAa,EAAE,MAAM,6BAA6B,CAAA;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAGL,gBAAgB,EAChB,cAAc,EAGf,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAG5D,qBAAa,eAAe,CAAC,OAAO,SAAS,cAAc,GAAG,cAAc,CAC1E,SAAQ,aAAa,CAAC,OAAO,CAC7B,YAAW,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAgB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../src/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAA8B,aAAa,EAAE,MAAM,6BAA6B,CAAA;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAGL,gBAAgB,EAChB,cAAc,EAGf,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAG5D,qBAAa,eAAe,CAAC,OAAO,SAAS,cAAc,GAAG,cAAc,CAC1E,SAAQ,aAAa,CAAC,OAAO,CAC7B,YAAW,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAgB,qBAAqB,4DAAqB;IAC1D,OAAgB,mBAAmB,sEAAmB;IACtD,OAAgB,eAAe,WAAwD;IAEvF,UAAU,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAIpC,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAMtD,SAAS,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CAGxC"}
|
package/dist/node/Wrapper.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Payload } from '@xyo-network/payload-model';
|
|
|
4
4
|
import { SentinelInstance, SentinelModule } from '@xyo-network/sentinel-model';
|
|
5
5
|
import { WitnessInstance } from '@xyo-network/witness-model';
|
|
6
6
|
export declare class SentinelWrapper<TModule extends SentinelModule = SentinelModule> extends ModuleWrapper<TModule> implements SentinelInstance<TModule['params']> {
|
|
7
|
-
static instanceIdentityCheck: import("@xyo-network/object").
|
|
7
|
+
static instanceIdentityCheck: import("@xyo-network/object").TypeCheck<SentinelInstance>;
|
|
8
8
|
static moduleIdentityCheck: import("@xyo-network/module-model").ModuleTypeCheck<SentinelModule>;
|
|
9
9
|
static requiredQueries: string[];
|
|
10
10
|
archivists(): Promise<ArchivistInstance[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../src/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAA8B,aAAa,EAAE,MAAM,6BAA6B,CAAA;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAGL,gBAAgB,EAChB,cAAc,EAGf,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAG5D,qBAAa,eAAe,CAAC,OAAO,SAAS,cAAc,GAAG,cAAc,CAC1E,SAAQ,aAAa,CAAC,OAAO,CAC7B,YAAW,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAgB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../src/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAA8B,aAAa,EAAE,MAAM,6BAA6B,CAAA;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAGL,gBAAgB,EAChB,cAAc,EAGf,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAG5D,qBAAa,eAAe,CAAC,OAAO,SAAS,cAAc,GAAG,cAAc,CAC1E,SAAQ,aAAa,CAAC,OAAO,CAC7B,YAAW,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAgB,qBAAqB,4DAAqB;IAC1D,OAAgB,mBAAmB,sEAAmB;IACtD,OAAgB,eAAe,WAAwD;IAEvF,UAAU,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAIpC,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAMtD,SAAS,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CAGxC"}
|
package/dist/node/index.js
CHANGED
|
@@ -23,14 +23,21 @@ var src_exports = {};
|
|
|
23
23
|
__export(src_exports, {
|
|
24
24
|
MemorySentinel: () => MemorySentinel,
|
|
25
25
|
SentinelAutomationSchema: () => SentinelAutomationSchema,
|
|
26
|
+
SentinelEventAutomationSchema: () => SentinelEventAutomationSchema,
|
|
27
|
+
SentinelIntervalAutomationSchema: () => SentinelIntervalAutomationSchema,
|
|
26
28
|
SentinelIntervalAutomationWrapper: () => SentinelIntervalAutomationWrapper,
|
|
27
29
|
SentinelRunner: () => SentinelRunner,
|
|
28
|
-
SentinelWrapper: () => SentinelWrapper
|
|
30
|
+
SentinelWrapper: () => SentinelWrapper,
|
|
31
|
+
isSentinelIntervalAutomation: () => isSentinelIntervalAutomation
|
|
29
32
|
});
|
|
30
33
|
module.exports = __toCommonJS(src_exports);
|
|
31
34
|
|
|
32
35
|
// src/Automation.ts
|
|
36
|
+
var import_payload_model = require("@xyo-network/payload-model");
|
|
33
37
|
var SentinelAutomationSchema = "network.xyo.automation";
|
|
38
|
+
var SentinelIntervalAutomationSchema = "network.xyo.automation.interval";
|
|
39
|
+
var SentinelEventAutomationSchema = "network.xyo.automation.event";
|
|
40
|
+
var isSentinelIntervalAutomation = (0, import_payload_model.isPayloadOfSchemaType)(SentinelIntervalAutomationSchema);
|
|
34
41
|
|
|
35
42
|
// src/MemorySentinel.ts
|
|
36
43
|
var import_promise = require("@xylabs/promise");
|
|
@@ -96,10 +103,10 @@ var SentinelIntervalAutomationWrapper = class extends import_payload_wrapper.Pay
|
|
|
96
103
|
super(payload);
|
|
97
104
|
}
|
|
98
105
|
get frequencyMillis() {
|
|
99
|
-
const frequency = this.
|
|
106
|
+
const frequency = this.jsonPayload().frequency;
|
|
100
107
|
if (frequency === void 0)
|
|
101
108
|
return Infinity;
|
|
102
|
-
switch (this.
|
|
109
|
+
switch (this.jsonPayload().frequencyUnits ?? "hour") {
|
|
103
110
|
case "second":
|
|
104
111
|
return frequency * 1e3;
|
|
105
112
|
case "minute":
|
|
@@ -114,21 +121,21 @@ var SentinelIntervalAutomationWrapper = class extends import_payload_wrapper.Pay
|
|
|
114
121
|
return this.payload().remaining ?? Infinity;
|
|
115
122
|
}
|
|
116
123
|
next() {
|
|
117
|
-
this.
|
|
124
|
+
this.jsonPayload().start = this.jsonPayload().start + this.frequencyMillis;
|
|
118
125
|
this.consumeRemaining();
|
|
119
126
|
this.checkEnd();
|
|
120
127
|
return this;
|
|
121
128
|
}
|
|
122
129
|
checkEnd() {
|
|
123
|
-
if (this.
|
|
124
|
-
this.
|
|
130
|
+
if (this.jsonPayload().start > (this.jsonPayload().end ?? Infinity)) {
|
|
131
|
+
this.jsonPayload().start = Infinity;
|
|
125
132
|
}
|
|
126
133
|
}
|
|
127
134
|
consumeRemaining(count = 1) {
|
|
128
135
|
const remaining = this.remaining - count;
|
|
129
|
-
this.
|
|
136
|
+
this.jsonPayload().remaining = remaining;
|
|
130
137
|
if (remaining <= 0) {
|
|
131
|
-
this.
|
|
138
|
+
this.jsonPayload().start = Infinity;
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
};
|
|
@@ -151,9 +158,12 @@ var SentinelRunner = class {
|
|
|
151
158
|
}
|
|
152
159
|
get next() {
|
|
153
160
|
return Object.values(this._automations).reduce((previous, current) => {
|
|
154
|
-
if (current
|
|
155
|
-
|
|
161
|
+
if (isSentinelIntervalAutomation(current)) {
|
|
162
|
+
if (isSentinelIntervalAutomation(previous)) {
|
|
163
|
+
return current.start < ((previous == null ? void 0 : previous.start) ?? Infinity) ? current : previous;
|
|
164
|
+
}
|
|
156
165
|
}
|
|
166
|
+
return current;
|
|
157
167
|
}, void 0);
|
|
158
168
|
}
|
|
159
169
|
async add(automation, restart = true) {
|
|
@@ -182,7 +192,7 @@ var SentinelRunner = class {
|
|
|
182
192
|
async start() {
|
|
183
193
|
(0, import_assert.assertEx)(this.timeoutId === void 0, "Already started");
|
|
184
194
|
const automation = this.next;
|
|
185
|
-
if (automation) {
|
|
195
|
+
if (isSentinelIntervalAutomation(automation)) {
|
|
186
196
|
const delay = automation.start - Date.now();
|
|
187
197
|
if (delay < 0) {
|
|
188
198
|
await this.trigger(automation);
|
|
@@ -214,7 +224,7 @@ var SentinelRunner = class {
|
|
|
214
224
|
const wrapper = new SentinelIntervalAutomationWrapper(automation);
|
|
215
225
|
await this.remove(await wrapper.hashAsync(), false);
|
|
216
226
|
wrapper.next();
|
|
217
|
-
await this.add(wrapper.
|
|
227
|
+
await this.add(wrapper.jsonPayload(), false);
|
|
218
228
|
const triggerResult = await this.sentinel.report();
|
|
219
229
|
(_a = this.onTriggerResult) == null ? void 0 : _a.call(this, triggerResult);
|
|
220
230
|
await this.start();
|
|
@@ -249,9 +259,12 @@ __reExport(src_exports, require("@xyo-network/sentinel-model"), module.exports);
|
|
|
249
259
|
0 && (module.exports = {
|
|
250
260
|
MemorySentinel,
|
|
251
261
|
SentinelAutomationSchema,
|
|
262
|
+
SentinelEventAutomationSchema,
|
|
263
|
+
SentinelIntervalAutomationSchema,
|
|
252
264
|
SentinelIntervalAutomationWrapper,
|
|
253
265
|
SentinelRunner,
|
|
254
266
|
SentinelWrapper,
|
|
267
|
+
isSentinelIntervalAutomation,
|
|
255
268
|
...require("@xyo-network/sentinel-abstract"),
|
|
256
269
|
...require("@xyo-network/sentinel-model")
|
|
257
270
|
});
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Automation.ts","../../src/MemorySentinel.ts","../../src/SentinelIntervalAutomationWrapper.ts","../../src/SentinelRunner.ts","../../src/Wrapper.ts"],"sourcesContent":["export * from './Automation'\nexport * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\nexport * from './Wrapper'\nexport * from '@xyo-network/sentinel-abstract'\nexport * from '@xyo-network/sentinel-model'\n","import { AnyObject } from '@xyo-network/core'\nimport { Payload } from '@xyo-network/payload-model'\nimport { Task } from '@xyo-network/sentinel-model'\n\nexport type SentinelAutomationSchema = 'network.xyo.automation'\nexport const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'\n\nexport type SentinelBaseAutomationPayload<T extends AnyObject = AnyObject> = Payload<\n T & {\n schema: SentinelAutomationSchema\n tasks?: Task[]\n type?: 'interval' | 'change'\n }\n>\n\nexport type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{\n /** @field epoch after which any reoccurrence stops */\n end?: number\n\n /** @field time between triggers [non-repeating if undefined] */\n frequency?: number\n\n /** @field units for frequency field [hour if undefined] */\n frequencyUnits?: 'second' | 'minute' | 'hour' | 'day'\n\n /** @field remaining triggers [infinite if undefined] */\n remaining?: number\n\n /** @field epoch of the next trigger */\n start: number\n\n type: 'interval'\n}>\n\nexport type SentinelChangeAutomationPayload = SentinelBaseAutomationPayload<{\n type: 'change'\n}>\n\nexport type SentinelAutomationPayload = SentinelIntervalAutomationPayload | SentinelChangeAutomationPayload\n","import { Address } from '@xylabs/hex'\nimport { fulfilled } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport {\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\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 configSchemas = [SentinelConfigSchema]\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\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.generateResults(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n return Object.values(previousResults).flat()\n }\n\n private async generateResults(\n tasks: ResolvedTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const witness = asWitnessInstance(task.module)\n const input = task.input ?? false\n const inPayloadsFound =\n input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n if (witness) {\n return [witness.address, await witness.observe(inPayloadsFound)]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n return [diviner.address, await diviner.divine(inPayloadsFound)]\n }\n throw Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n results.filter(fulfilled).forEach((result) => {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n })\n /*const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw Error('At least one module failed')\n }*/\n return finalResult\n }\n\n private async inputAddresses(input: string | string[]): Promise<string[]> {\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.map((input) => payloads[input] ?? []).flat()\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.payload().frequency\n if (frequency === undefined) return Infinity\n switch (this.payload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.payload().start = this.payload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.payload().start > (this.payload().end ?? Infinity)) {\n this.payload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.payload().remaining = remaining\n\n if (remaining <= 0) {\n this.payload().start = Infinity\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nimport { SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation'\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n automations?.forEach((automation) => this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n return Object.values(this._automations).reduce<SentinelIntervalAutomationPayload | undefined>((previous, current) => {\n if (current.type === 'interval') {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (automation) {\n const delay = automation.start - Date.now()\n if (delay < 0) {\n //automation is due, just do it\n await this.trigger(automation)\n } else {\n this.timeoutId = setTimeout(\n async () => {\n this.timeoutId = undefined\n await this.start()\n },\n delay > 0 ? delay : 0,\n )\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.payload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n await this.start()\n }\n}\n","import { ArchivistInstance } from '@xyo-network/archivist'\nimport { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module-wrapper'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n isSentinelInstance,\n isSentinelModule,\n SentinelInstance,\n SentinelModule,\n SentinelReportQuery,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { WitnessInstance } from '@xyo-network/witness-model'\n\nconstructableModuleWrapper()\nexport class SentinelWrapper<TModule extends SentinelModule = SentinelModule>\n extends ModuleWrapper<TModule>\n implements SentinelInstance<TModule['params']>\n{\n static override instanceIdentityCheck = isSentinelInstance\n static override moduleIdentityCheck = isSentinelModule\n static override requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries]\n\n archivists(): Promise<ArchivistInstance[]> {\n throw Error('Not supported')\n }\n\n async report(payloads?: Payload[]): Promise<Payload[]> {\n const queryPayload: SentinelReportQuery = { schema: SentinelReportQuerySchema }\n const result = await this.sendQuery(queryPayload, payloads)\n return result\n }\n\n witnesses(): Promise<WitnessInstance[]> {\n throw Error('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ACjD,eAAK,oBAAL,8BAAuB;AACvB,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;;;ACrGA,4BAA0D;AAE1D,IAAAC,yBAOO;AAAA,IAGP,kDAA2B;AACpB,IAAM,kBAAN,cACG,oCAEV;AAAA,EACE,OAAgB,wBAAwB;AAAA,EACxC,OAAgB,sBAAsB;AAAA,EACtC,OAAgB,kBAAkB,CAAC,kDAA2B,GAAG,MAAM,eAAe;AAAA,EAEtF,aAA2C;AACzC,UAAM,MAAM,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,UAA0C;AACrD,UAAM,eAAoC,EAAE,QAAQ,iDAA0B;AAC9E,UAAM,SAAS,MAAM,KAAK,UAAU,cAAc,QAAQ;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;;;AL9BA,wBAAc,2CALd;AAMA,wBAAc,wCANd;","names":["import_payload_wrapper","import_sentinel_model"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Automation.ts","../../src/MemorySentinel.ts","../../src/SentinelIntervalAutomationWrapper.ts","../../src/SentinelRunner.ts","../../src/Wrapper.ts"],"sourcesContent":["export * from './Automation'\nexport * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\nexport * from './Wrapper'\nexport * from '@xyo-network/sentinel-abstract'\nexport * from '@xyo-network/sentinel-model'\n","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\nimport { Task } from '@xyo-network/sentinel-model'\n\nexport type SentinelAutomationSchema = 'network.xyo.automation'\nexport const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'\n\nexport type SentinelIntervalAutomationSchema = 'network.xyo.automation.interval'\nexport const SentinelIntervalAutomationSchema: SentinelIntervalAutomationSchema = 'network.xyo.automation.interval'\n\nexport type SentinelEventAutomationSchema = 'network.xyo.automation.event'\nexport const SentinelEventAutomationSchema: SentinelEventAutomationSchema = 'network.xyo.automation.event'\n\nexport type SentinelBaseAutomationPayload<T extends Payload> = Payload<\n {\n tasks?: Task[]\n type?: 'interval' | 'event'\n } & T\n>\n\n/** Settings for an Interval Automation */\nexport type SentinelIntervalAutomationPayload = SentinelBaseAutomationPayload<{\n /** Epoch after which any reoccurrence stops */\n end?: number\n\n /** Time between triggers [non-repeating if undefined] */\n frequency?: number\n\n /** Units for frequency field [hour if undefined] */\n frequencyUnits?: 'second' | 'minute' | 'hour' | 'day'\n\n /** Remaining triggers [infinite if undefined] */\n remaining?: number\n\n schema: SentinelIntervalAutomationSchema\n\n /** Epoch of the next trigger */\n start: number\n\n /** The type of automation */\n type: 'interval'\n}>\n\nexport const isSentinelIntervalAutomation = isPayloadOfSchemaType<SentinelIntervalAutomationPayload>(SentinelIntervalAutomationSchema)\n\n/** Settings for an Event Automation */\nexport type SentinelEventAutomationPayload = SentinelBaseAutomationPayload<{\n schema: SentinelEventAutomationSchema\n type: 'event'\n}>\n\n/** Settings for an Automation */\nexport type SentinelAutomationPayload = Payload<\n SentinelIntervalAutomationPayload | SentinelEventAutomationPayload,\n SentinelAutomationSchema | SentinelIntervalAutomationSchema | SentinelEventAutomationSchema\n>\n","import { Address } from '@xylabs/hex'\nimport { fulfilled } from '@xylabs/promise'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { Payload } from '@xyo-network/payload-model'\nimport { AbstractSentinel } from '@xyo-network/sentinel-abstract'\nimport {\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\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 configSchemas = [SentinelConfigSchema]\n\n async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\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.generateResults(job.tasks[index], previousResults, inPayloads)\n previousResults = generatedPayloads\n index++\n }\n return Object.values(previousResults).flat()\n }\n\n private async generateResults(\n tasks: ResolvedTask[],\n previousResults: Record<Address, Payload[]>,\n inPayloads?: Payload[],\n ): Promise<Record<Address, Payload[]>> {\n const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(\n tasks?.map(async (task) => {\n const witness = asWitnessInstance(task.module)\n const input = task.input ?? false\n const inPayloadsFound =\n input === true ? inPayloads : input === false ? [] : this.processPreviousResults(previousResults, await this.inputAddresses(input))\n if (witness) {\n return [witness.address, await witness.observe(inPayloadsFound)]\n }\n const diviner = asDivinerInstance(task.module)\n if (diviner) {\n return [diviner.address, await diviner.divine(inPayloadsFound)]\n }\n throw Error('Unsupported module type')\n }),\n )\n const finalResult: Record<Address, Payload[]> = {}\n results.filter(fulfilled).forEach((result) => {\n const [address, payloads] = result.value\n finalResult[address] = finalResult[address] ?? []\n finalResult[address].push(...payloads)\n })\n /*const errors = results.filter(rejected).map((result) => result.reason)\n if (errors.length > 0) {\n throw Error('At least one module failed')\n }*/\n return finalResult\n }\n\n private async inputAddresses(input: string | string[]): Promise<string[]> {\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.map((input) => payloads[input] ?? []).flat()\n }\n}\n","import { PayloadWrapper } from '@xyo-network/payload-wrapper'\n\nimport { SentinelIntervalAutomationPayload } from './Automation'\n\nexport class SentinelIntervalAutomationWrapper<\n T extends SentinelIntervalAutomationPayload = SentinelIntervalAutomationPayload,\n> extends PayloadWrapper<T> {\n constructor(payload: T) {\n super(payload)\n }\n\n protected get frequencyMillis() {\n const frequency = this.jsonPayload().frequency\n if (frequency === undefined) return Infinity\n switch (this.jsonPayload().frequencyUnits ?? 'hour') {\n case 'second':\n return frequency * 1000\n case 'minute':\n return frequency * 60 * 1000\n case 'hour':\n return frequency * 60 * 60 * 1000\n case 'day':\n return frequency * 24 * 60 * 60 * 1000\n }\n }\n\n protected get remaining() {\n //if remaining is not defined, we assume Infinity\n return this.payload().remaining ?? Infinity\n }\n\n next() {\n this.jsonPayload().start = this.jsonPayload().start + this.frequencyMillis\n this.consumeRemaining()\n this.checkEnd()\n return this\n }\n\n protected checkEnd() {\n if (this.jsonPayload().start > (this.jsonPayload().end ?? Infinity)) {\n this.jsonPayload().start = Infinity\n }\n }\n\n protected consumeRemaining(count = 1) {\n const remaining = this.remaining - count\n this.jsonPayload().remaining = remaining\n\n if (remaining <= 0) {\n this.jsonPayload().start = Infinity\n }\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Payload } from '@xyo-network/payload-model'\nimport { PayloadWrapper } from '@xyo-network/payload-wrapper'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nimport { isSentinelIntervalAutomation, SentinelAutomationPayload, SentinelIntervalAutomationPayload } from './Automation'\nimport { SentinelIntervalAutomationWrapper } from './SentinelIntervalAutomationWrapper'\n\nexport type OnSentinelRunnerTriggerResult = (result: Payload[]) => void\n\nexport class SentinelRunner {\n protected _automations: Record<string, SentinelAutomationPayload> = {}\n protected onTriggerResult: OnSentinelRunnerTriggerResult | undefined\n protected sentinel: SentinelInstance\n protected timeoutId?: NodeJS.Timeout | string | number\n\n constructor(sentinel: SentinelInstance, automations?: SentinelAutomationPayload[], onTriggerResult?: OnSentinelRunnerTriggerResult) {\n this.sentinel = sentinel\n this.onTriggerResult = onTriggerResult\n automations?.forEach((automation) => this.add(automation))\n }\n\n get automations() {\n return this._automations\n }\n\n private get next() {\n return Object.values(this._automations).reduce<SentinelAutomationPayload | undefined>((previous, current) => {\n if (isSentinelIntervalAutomation(current)) {\n if (isSentinelIntervalAutomation(previous)) {\n return current.start < (previous?.start ?? Infinity) ? current : previous\n }\n }\n return current\n }, undefined)\n }\n\n async add(automation: SentinelAutomationPayload, restart = true) {\n const hash = await PayloadWrapper.hashAsync(automation)\n this._automations[hash] = automation\n if (restart) await this.restart()\n return hash\n }\n\n find(hash: string) {\n Object.entries(this._automations).find(([key]) => key === hash)\n }\n\n async remove(hash: string, restart = true) {\n delete this._automations[hash]\n if (restart) await this.restart()\n }\n\n removeAll() {\n this.stop()\n this._automations = {}\n }\n\n async restart() {\n this.stop()\n await this.start()\n }\n\n async start() {\n assertEx(this.timeoutId === undefined, 'Already started')\n const automation = this.next\n if (isSentinelIntervalAutomation(automation)) {\n const delay = automation.start - Date.now()\n if (delay < 0) {\n //automation is due, just do it\n await this.trigger(automation)\n } else {\n this.timeoutId = setTimeout(\n async () => {\n this.timeoutId = undefined\n await this.start()\n },\n delay > 0 ? delay : 0,\n )\n }\n }\n }\n\n stop() {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = undefined\n }\n }\n\n async update(hash: string, automation: SentinelAutomationPayload, restart = true) {\n await this.remove(hash, false)\n await this.add(automation, false)\n if (restart) await this.restart()\n }\n\n private async trigger(automation: SentinelIntervalAutomationPayload) {\n const wrapper = new SentinelIntervalAutomationWrapper(automation)\n await this.remove(await wrapper.hashAsync(), false)\n wrapper.next()\n await this.add(wrapper.jsonPayload(), false)\n const triggerResult = await this.sentinel.report()\n this.onTriggerResult?.(triggerResult)\n await this.start()\n }\n}\n","import { ArchivistInstance } from '@xyo-network/archivist'\nimport { constructableModuleWrapper, ModuleWrapper } from '@xyo-network/module-wrapper'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n isSentinelInstance,\n isSentinelModule,\n SentinelInstance,\n SentinelModule,\n SentinelReportQuery,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { WitnessInstance } from '@xyo-network/witness-model'\n\nconstructableModuleWrapper()\nexport class SentinelWrapper<TModule extends SentinelModule = SentinelModule>\n extends ModuleWrapper<TModule>\n implements SentinelInstance<TModule['params']>\n{\n static override instanceIdentityCheck = isSentinelInstance\n static override moduleIdentityCheck = isSentinelModule\n static override requiredQueries = [SentinelReportQuerySchema, ...super.requiredQueries]\n\n archivists(): Promise<ArchivistInstance[]> {\n throw Error('Not supported')\n }\n\n async report(payloads?: Payload[]): Promise<Payload[]> {\n const queryPayload: SentinelReportQuery = { schema: SentinelReportQuerySchema }\n const result = await this.sendQuery(queryPayload, payloads)\n return result\n }\n\n witnesses(): Promise<WitnessInstance[]> {\n throw Error('Not supported')\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAA+C;AAIxC,IAAM,2BAAqD;AAG3D,IAAM,mCAAqE;AAG3E,IAAM,gCAA+D;AAgCrE,IAAM,mCAA+B,4CAAyD,gCAAgC;;;ACzCrI,qBAA0B;AAC1B,2BAAkC;AAGlC,+BAAiC;AACjC,4BAOO;AACP,2BAAkC;AAI3B,IAAM,iBAAN,cAGG,0CAAsC;AAAA,EAC9C,OAAgB,gBAAgB,CAAC,0CAAoB;AAAA,EAErD,MAAM,cAAc,aAAwB,CAAC,GAAuB;AAClE,UAAM,KAAK,QAAQ,OAAO;AAC1B,UAAM,MAAM,MAAM,KAAK;AAEvB,QAAI,QAAQ;AACZ,QAAI,kBAA8C,CAAC;AACnD,WAAO,QAAQ,IAAI,MAAM,QAAQ;AAC/B,YAAM,oBAAoB,MAAM,KAAK,gBAAgB,IAAI,MAAM,KAAK,GAAG,iBAAiB,UAAU;AAClG,wBAAkB;AAClB;AAAA,IACF;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