@xyo-network/sentinel 2.72.9 → 2.73.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/docs.json +68671 -37045
  2. package/dist/index.d.mts +291 -0
  3. package/dist/index.d.ts +291 -0
  4. package/dist/index.js +323 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +298 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +41 -29
  9. package/src/AbstractSentinel.ts +1 -1
  10. package/tsup.config.ts +16 -0
  11. package/dist/cjs/AbstractSentinel.js +0 -125
  12. package/dist/cjs/AbstractSentinel.js.map +0 -1
  13. package/dist/cjs/Automation.js +0 -5
  14. package/dist/cjs/Automation.js.map +0 -1
  15. package/dist/cjs/MemorySentinel.js +0 -50
  16. package/dist/cjs/MemorySentinel.js.map +0 -1
  17. package/dist/cjs/SentinelIntervalAutomationWrapper.js +0 -51
  18. package/dist/cjs/SentinelIntervalAutomationWrapper.js.map +0 -1
  19. package/dist/cjs/SentinelRunner.js +0 -102
  20. package/dist/cjs/SentinelRunner.js.map +0 -1
  21. package/dist/cjs/Wrapper.js +0 -29
  22. package/dist/cjs/Wrapper.js.map +0 -1
  23. package/dist/cjs/index.js +0 -11
  24. package/dist/cjs/index.js.map +0 -1
  25. package/dist/esm/AbstractSentinel.js +0 -98
  26. package/dist/esm/AbstractSentinel.js.map +0 -1
  27. package/dist/esm/Automation.js +0 -2
  28. package/dist/esm/Automation.js.map +0 -1
  29. package/dist/esm/MemorySentinel.js +0 -41
  30. package/dist/esm/MemorySentinel.js.map +0 -1
  31. package/dist/esm/SentinelIntervalAutomationWrapper.js +0 -44
  32. package/dist/esm/SentinelIntervalAutomationWrapper.js.map +0 -1
  33. package/dist/esm/SentinelRunner.js +0 -86
  34. package/dist/esm/SentinelRunner.js.map +0 -1
  35. package/dist/esm/Wrapper.js +0 -20
  36. package/dist/esm/Wrapper.js.map +0 -1
  37. package/dist/esm/index.js +0 -8
  38. package/dist/esm/index.js.map +0 -1
  39. package/dist/types/AbstractSentinel.d.ts +0 -22
  40. package/dist/types/AbstractSentinel.d.ts.map +0 -1
  41. package/dist/types/Automation.d.ts +0 -28
  42. package/dist/types/Automation.d.ts.map +0 -1
  43. package/dist/types/MemorySentinel.d.ts +0 -11
  44. package/dist/types/MemorySentinel.d.ts.map +0 -1
  45. package/dist/types/SentinelIntervalAutomationWrapper.d.ts +0 -11
  46. package/dist/types/SentinelIntervalAutomationWrapper.d.ts.map +0 -1
  47. package/dist/types/SentinelRunner.d.ts +0 -24
  48. package/dist/types/SentinelRunner.d.ts.map +0 -1
  49. package/dist/types/Wrapper.d.ts +0 -14
  50. package/dist/types/Wrapper.d.ts.map +0 -1
  51. package/dist/types/index.d.ts +0 -8
  52. package/dist/types/index.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/AbstractSentinel.ts","../src/Automation.ts","../src/MemorySentinel.ts","../src/SentinelIntervalAutomationWrapper.ts","../src/SentinelRunner.ts","../src/Wrapper.ts","../src/index.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { uniq } from '@xylabs/lodash'\nimport { AbstractArchivingModule, asArchivistInstance } from '@xyo-network/archivist'\nimport { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'\nimport { BoundWitness, isBoundWitness, notBoundWitness } from '@xyo-network/boundwitness-model'\nimport { ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n CustomSentinelInstance,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n SentinelQueryBase,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { isWitnessInstance, WitnessInstance } from '@xyo-network/witness'\n\nexport abstract class AbstractSentinel<\n TParams extends SentinelParams = SentinelParams,\n TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,\n >\n extends AbstractArchivingModule<TParams, TEventData>\n implements CustomSentinelInstance<TParams, TEventData>\n{\n history: BoundWitness[] = []\n\n override get queries(): string[] {\n return [SentinelReportQuerySchema, ...super.queries]\n }\n\n protected override get _queryAccountPaths(): Record<SentinelQueryBase['schema'], string> {\n return {\n 'network.xyo.query.sentinel.report': '1/1',\n }\n }\n\n addArchivist(address: string[]) {\n this.config.archivists = uniq([...address, ...(this.config.archivists ?? [])])\n }\n\n addWitness(address: string[]) {\n this.config.witnesses = uniq([...address, ...(this.config.witnesses ?? [])])\n }\n\n async archivists() {\n this.logger?.debug(`archivists:config:archivist: ${this.config?.archivists?.length}`)\n const namesOrAddresses = this.config?.archivists\n ? Array.isArray(this.config.archivists)\n ? this.config?.archivists\n : [this.config.archivists]\n : undefined\n this.logger?.debug(`archivist:namesOrAddresses: ${namesOrAddresses?.length}`)\n const result = [\n ...(await this.resolve(namesOrAddresses ? { address: namesOrAddresses } : undefined)),\n ...(await this.resolve(namesOrAddresses ? { name: namesOrAddresses } : undefined)),\n ].map((module) => assertEx(asArchivistInstance(module), 'Tried to resolve a non-archivist as an archivist'))\n\n if (namesOrAddresses && namesOrAddresses.length !== result.length) {\n this.logger?.warn(`Not all archivists found [Requested: ${namesOrAddresses.length}, Found: ${result.length}]`)\n }\n\n this.logger?.debug(`archivists:result: ${result?.length}`)\n\n return result\n }\n\n removeArchivist(address: string[]) {\n this.config.archivists = (this.config.archivists ?? []).filter((archivist) => !address.includes(archivist))\n }\n\n removeWitness(address: string[]) {\n this.config.witnesses = (this.config.witnesses ?? []).filter((witness) => !address.includes(witness))\n }\n\n async report(inPayloads?: Payload[]): Promise<Payload[]> {\n this._noOverride('report')\n await this.emit('reportStart', { inPayloads, module: this })\n const payloads = await this.reportHandler(inPayloads)\n this.logger?.debug(`report:payloads: ${JSON.stringify(payloads, null, 2)}`)\n const outPayloads = payloads.filter(notBoundWitness)\n const boundwitnesses = payloads.filter(isBoundWitness)\n const boundwitness = boundwitnesses.find((bw) => bw.addresses.includes(this.address))\n await this.emit('reportEnd', { boundwitness, inPayloads, module: this, outPayloads })\n return payloads\n }\n\n async witnesses() {\n this.logger?.debug(`witnesses:config:witnesses: ${this.config?.witnesses?.length}`)\n const namesOrAddresses = this.config?.witnesses\n ? Array.isArray(this.config.witnesses)\n ? this.config?.witnesses\n : [this.config.witnesses]\n : undefined\n this.logger?.debug(`witnesses:namesOrAddresses: ${namesOrAddresses?.length}`)\n const result = namesOrAddresses\n ? [\n ...(await this.resolve<WitnessInstance>({ address: namesOrAddresses }, { identity: isWitnessInstance })),\n ...(await this.resolve<WitnessInstance>({ name: namesOrAddresses }, { identity: isWitnessInstance })),\n ]\n : await this.resolve<WitnessInstance>(undefined, { identity: isWitnessInstance })\n\n if (namesOrAddresses && namesOrAddresses.length !== result.length) {\n this.logger?.warn(`Not all witnesses found [Requested: ${namesOrAddresses.length}, Found: ${result.length}]`)\n }\n result.map((item) => {\n this.logger?.debug(`witnesses:result: ${item.config.schema}`)\n })\n\n return result\n }\n\n protected override async queryHandler<T extends QueryBoundWitness = QueryBoundWitness, TConfig extends ModuleConfig = ModuleConfig>(\n query: T,\n payloads?: Payload[],\n queryConfig?: TConfig,\n ): Promise<ModuleQueryHandlerResult> {\n const wrapper = QueryBoundWitnessWrapper.parseQuery<SentinelQueryBase>(query, payloads)\n const queryPayload = await wrapper.getQuery()\n assertEx(this.queryable(query, payloads, queryConfig))\n const resultPayloads: Payload[] = []\n switch (queryPayload.schema) {\n case SentinelReportQuerySchema: {\n resultPayloads.push(...(await this.report(payloads)))\n break\n }\n default: {\n return super.queryHandler(query, payloads)\n }\n }\n return resultPayloads\n }\n\n abstract reportHandler(payloads?: Payload[]): Promise<Payload[]>\n}\n","import { AnyObject } from '@xyo-network/core'\nimport { Payload } from '@xyo-network/payload-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 type?: 'interval' | 'change'\n /** @field The list of witnesses to invoke [all if undefined] */\n witnesses?: string[]\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 { assertEx } from '@xylabs/assert'\nimport { fulfilled, rejected } from '@xylabs/promise'\nimport { handleError } from '@xyo-network/error'\nimport { AnyConfigSchema } from '@xyo-network/module'\nimport { Payload } from '@xyo-network/payload-model'\nimport {\n SentinelConfig,\n SentinelConfigSchema,\n SentinelInstance,\n SentinelModuleEventData,\n SentinelParams,\n SentinelReportQuerySchema,\n} from '@xyo-network/sentinel-model'\nimport { WitnessInstance } from '@xyo-network/witness'\n\nimport { AbstractSentinel } from './AbstractSentinel'\n\nexport type MemorySentinelParams<TConfig extends AnyConfigSchema<SentinelConfig> = AnyConfigSchema<SentinelConfig>> = SentinelParams<\n AnyConfigSchema<TConfig>\n>\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(payloads: Payload[] = []): Promise<Payload[]> {\n await this.started('throw')\n const errors: Error[] = []\n const allWitnesses = [...(await this.witnesses())]\n const resultPayloads: Payload[] = []\n\n try {\n const [generatedPayloads, generatedErrors] = await this.generateResults(allWitnesses)\n const combinedPayloads = [...generatedPayloads, ...payloads]\n resultPayloads.push(...combinedPayloads)\n errors.push(...generatedErrors)\n } catch (ex) {\n handleError(ex, (error) => {\n errors.push(error)\n })\n }\n\n const [boundWitness] = await this.bindQueryResult({ schema: SentinelReportQuerySchema }, resultPayloads)\n this.history.push(assertEx(boundWitness))\n return [boundWitness, ...resultPayloads]\n }\n\n private async generateResults(witnesses: WitnessInstance[]): Promise<[Payload[], Error[]]> {\n const results = await Promise.allSettled(witnesses?.map((witness) => witness.observe()))\n const payloads = results\n .filter(fulfilled)\n .map((result) => result.value)\n .flat()\n const errors = results\n .filter(rejected)\n .map((result) => result.reason)\n .flat()\n return [payloads, errors]\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'\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'\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 './AbstractSentinel'\nexport * from './Automation'\nexport * from './MemorySentinel'\nexport * from './SentinelIntervalAutomationWrapper'\nexport * from './SentinelRunner'\nexport * from './Wrapper'\nexport * from '@xyo-network/sentinel-model'\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY;AACrB,SAAS,yBAAyB,2BAA2B;AAC7D,SAA4B,gCAAgC;AAC5D,SAAuB,gBAAgB,uBAAuB;AAG9D;AAAA,EAME;AAAA,OACK;A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AAU,GAAG,KAAK;AAClD,YAAQ,KAAK;AACb,UAAM,KAAK,IAAI,QAAQ,QAAQ,GAAG,KAAK;AACvC,UAAM,gBAAgB,MAAM,KAAK,SAAS,OAAO;AACjD,SAAK,kBAAkB,aAAa;AACpC,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;;;ACrGA,SAAS,4BAA4B,qBAAqB;AAE1D;AAAA,EACE;AAAA,EACA;AAAA,EAIA,6BAAAC;AAAA,OACK;AAGP,2BAA2B;AACpB,IAAM,kBAAN,cACG,cAEV;AAAA,EACE,OAAgB,wBAAwB;AAAA,EACxC,OAAgB,sBAAsB;AAAA,EACtC,OAAgB,kBAAkB,CAACA,4BAA2B,GAAG,MAAM,eAAe;AAAA,EAEtF,aAA2C;AACzC,UAAM,MAAM,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,OAAO,UAA0C;AACrD,UAAM,eAAoC,EAAE,QAAQA,2BAA0B;AAC9E,UAAM,SAAS,MAAM,KAAK,UAAU,cAAc,QAAQ;AAC1D,WAAO;AAAA,EACT;AAAA,EAEA,YAAwC;AACtC,UAAM,MAAM,eAAe;AAAA,EAC7B;AACF;;;AC7BA,cAAc;","names":["assertEx","SentinelReportQuerySchema","SentinelReportQuerySchema","assertEx","assertEx","PayloadWrapper","PayloadWrapper","assertEx","SentinelReportQuerySchema"]}
package/package.json CHANGED
@@ -10,48 +10,61 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^2.9.3",
14
- "@xylabs/promise": "^2.9.3",
15
- "@xyo-network/archivist": "~2.72.9",
16
- "@xyo-network/boundwitness-builder": "~2.72.9",
17
- "@xyo-network/boundwitness-model": "~2.72.9",
18
- "@xyo-network/core": "~2.72.9",
19
- "@xyo-network/error": "~2.72.9",
20
- "@xyo-network/module": "~2.72.9",
21
- "@xyo-network/payload-model": "~2.72.9",
22
- "@xyo-network/payload-wrapper": "~2.72.9",
23
- "@xyo-network/sentinel-model": "~2.72.9",
24
- "@xyo-network/witness": "~2.72.9",
25
- "lodash": "^4.17.21"
13
+ "@xylabs/assert": "^2.10.7",
14
+ "@xylabs/lodash": "^2.10.7",
15
+ "@xylabs/promise": "^2.10.7",
16
+ "@xyo-network/archivist": "~2.73.1",
17
+ "@xyo-network/boundwitness-builder": "~2.73.1",
18
+ "@xyo-network/boundwitness-model": "~2.73.1",
19
+ "@xyo-network/core": "~2.73.1",
20
+ "@xyo-network/error": "~2.73.1",
21
+ "@xyo-network/module": "~2.73.1",
22
+ "@xyo-network/payload-model": "~2.73.1",
23
+ "@xyo-network/payload-wrapper": "~2.73.1",
24
+ "@xyo-network/sentinel-model": "~2.73.1",
25
+ "@xyo-network/witness": "~2.73.1"
26
26
  },
27
27
  "description": "Primary SDK for using XYO Protocol 2.0",
28
28
  "devDependencies": {
29
- "@types/lodash": "^4.14.198",
30
- "@xylabs/ts-scripts-yarn3": "^2.19.3",
31
- "@xylabs/tsconfig": "^2.19.3",
29
+ "@xylabs/ts-scripts-yarn3": "^2.19.5",
30
+ "@xylabs/tsconfig": "^2.19.5",
31
+ "publint": "^0.2.2",
32
+ "tsup": "^7.2.0",
32
33
  "typescript": "^5.2.2"
33
34
  },
34
- "browser": "dist/esm/index.js",
35
+ "scripts": {
36
+ "package-compile": "tsup && publint",
37
+ "package-recompile": "tsup && publint"
38
+ },
35
39
  "docs": "dist/docs.json",
40
+ "types": "dist/index.d.ts",
36
41
  "exports": {
37
42
  ".": {
38
- "node": {
39
- "import": "./dist/esm/index.js",
40
- "require": "./dist/cjs/index.js"
41
- },
42
- "browser": {
43
- "import": "./dist/esm/index.js",
44
- "require": "./dist/cjs/index.js"
43
+ "require": {
44
+ "types": "./dist/index.d.ts",
45
+ "default": "./dist/index.js"
45
46
  },
46
- "default": "./dist/esm/index.js"
47
+ "import": {
48
+ "types": "./dist/index.d.mts",
49
+ "default": "./dist/index.mjs"
50
+ }
47
51
  },
48
52
  "./dist/docs.json": {
49
53
  "default": "./dist/docs.json"
50
54
  },
55
+ "./cjs": {
56
+ "default": "./dist/index.js"
57
+ },
58
+ "./docs": {
59
+ "default": "./dist/docs.json"
60
+ },
61
+ "./esm": {
62
+ "default": "./dist/index.mjs"
63
+ },
51
64
  "./package.json": "./package.json"
52
65
  },
53
- "main": "dist/cjs/index.js",
54
- "module": "dist/esm/index.js",
66
+ "main": "dist/index.js",
67
+ "module": "dist/index.mjs",
55
68
  "homepage": "https://xyo.network",
56
69
  "license": "LGPL-3.0",
57
70
  "publishConfig": {
@@ -62,6 +75,5 @@
62
75
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
63
76
  },
64
77
  "sideEffects": false,
65
- "types": "dist/types/index.d.ts",
66
- "version": "2.72.9"
78
+ "version": "2.73.1"
67
79
  }
@@ -1,4 +1,5 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
+ import { uniq } from '@xylabs/lodash'
2
3
  import { AbstractArchivingModule, asArchivistInstance } from '@xyo-network/archivist'
3
4
  import { QueryBoundWitness, QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'
4
5
  import { BoundWitness, isBoundWitness, notBoundWitness } from '@xyo-network/boundwitness-model'
@@ -13,7 +14,6 @@ import {
13
14
  SentinelReportQuerySchema,
14
15
  } from '@xyo-network/sentinel-model'
15
16
  import { isWitnessInstance, WitnessInstance } from '@xyo-network/witness'
16
- import uniq from 'lodash/uniq'
17
17
 
18
18
  export abstract class AbstractSentinel<
19
19
  TParams extends SentinelParams = SentinelParams,
package/tsup.config.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'tsup'
2
+
3
+ // eslint-disable-next-line import/no-default-export
4
+ export default defineConfig({
5
+ bundle: true,
6
+ cjsInterop: true,
7
+ clean: true,
8
+ dts: {
9
+ entry: ['src/index.ts'],
10
+ },
11
+ entry: ['src/index.ts'],
12
+ format: ['cjs', 'esm'],
13
+ sourcemap: true,
14
+ splitting: false,
15
+ tsconfig: 'tsconfig.json',
16
+ })
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractSentinel = void 0;
4
- const tslib_1 = require("tslib");
5
- const assert_1 = require("@xylabs/assert");
6
- const archivist_1 = require("@xyo-network/archivist");
7
- const boundwitness_builder_1 = require("@xyo-network/boundwitness-builder");
8
- const boundwitness_model_1 = require("@xyo-network/boundwitness-model");
9
- const sentinel_model_1 = require("@xyo-network/sentinel-model");
10
- const witness_1 = require("@xyo-network/witness");
11
- const uniq_1 = tslib_1.__importDefault(require("lodash/uniq"));
12
- class AbstractSentinel extends archivist_1.AbstractArchivingModule {
13
- constructor() {
14
- super(...arguments);
15
- this.history = [];
16
- }
17
- get queries() {
18
- return [sentinel_model_1.SentinelReportQuerySchema, ...super.queries];
19
- }
20
- get _queryAccountPaths() {
21
- return {
22
- 'network.xyo.query.sentinel.report': '1/1',
23
- };
24
- }
25
- addArchivist(address) {
26
- var _a;
27
- this.config.archivists = (0, uniq_1.default)([...address, ...((_a = this.config.archivists) !== null && _a !== void 0 ? _a : [])]);
28
- }
29
- addWitness(address) {
30
- var _a;
31
- this.config.witnesses = (0, uniq_1.default)([...address, ...((_a = this.config.witnesses) !== null && _a !== void 0 ? _a : [])]);
32
- }
33
- archivists() {
34
- var _a, _b, _c, _d, _e, _f, _g, _h;
35
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
36
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`archivists:config:archivist: ${(_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.archivists) === null || _c === void 0 ? void 0 : _c.length}`);
37
- const namesOrAddresses = ((_d = this.config) === null || _d === void 0 ? void 0 : _d.archivists)
38
- ? Array.isArray(this.config.archivists)
39
- ? (_e = this.config) === null || _e === void 0 ? void 0 : _e.archivists
40
- : [this.config.archivists]
41
- : undefined;
42
- (_f = this.logger) === null || _f === void 0 ? void 0 : _f.debug(`archivist:namesOrAddresses: ${namesOrAddresses === null || namesOrAddresses === void 0 ? void 0 : namesOrAddresses.length}`);
43
- const result = [
44
- ...(yield this.resolve(namesOrAddresses ? { address: namesOrAddresses } : undefined)),
45
- ...(yield this.resolve(namesOrAddresses ? { name: namesOrAddresses } : undefined)),
46
- ].map((module) => (0, assert_1.assertEx)((0, archivist_1.asArchivistInstance)(module), 'Tried to resolve a non-archivist as an archivist'));
47
- if (namesOrAddresses && namesOrAddresses.length !== result.length) {
48
- (_g = this.logger) === null || _g === void 0 ? void 0 : _g.warn(`Not all archivists found [Requested: ${namesOrAddresses.length}, Found: ${result.length}]`);
49
- }
50
- (_h = this.logger) === null || _h === void 0 ? void 0 : _h.debug(`archivists:result: ${result === null || result === void 0 ? void 0 : result.length}`);
51
- return result;
52
- });
53
- }
54
- removeArchivist(address) {
55
- var _a;
56
- this.config.archivists = ((_a = this.config.archivists) !== null && _a !== void 0 ? _a : []).filter((archivist) => !address.includes(archivist));
57
- }
58
- removeWitness(address) {
59
- var _a;
60
- this.config.witnesses = ((_a = this.config.witnesses) !== null && _a !== void 0 ? _a : []).filter((witness) => !address.includes(witness));
61
- }
62
- report(inPayloads) {
63
- var _a;
64
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
65
- this._noOverride('report');
66
- yield this.emit('reportStart', { inPayloads, module: this });
67
- const payloads = yield this.reportHandler(inPayloads);
68
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`report:payloads: ${JSON.stringify(payloads, null, 2)}`);
69
- const outPayloads = payloads.filter(boundwitness_model_1.notBoundWitness);
70
- const boundwitnesses = payloads.filter(boundwitness_model_1.isBoundWitness);
71
- const boundwitness = boundwitnesses.find((bw) => bw.addresses.includes(this.address));
72
- yield this.emit('reportEnd', { boundwitness, inPayloads, module: this, outPayloads });
73
- return payloads;
74
- });
75
- }
76
- witnesses() {
77
- var _a, _b, _c, _d, _e, _f, _g;
78
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
79
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`witnesses:config:witnesses: ${(_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.witnesses) === null || _c === void 0 ? void 0 : _c.length}`);
80
- const namesOrAddresses = ((_d = this.config) === null || _d === void 0 ? void 0 : _d.witnesses)
81
- ? Array.isArray(this.config.witnesses)
82
- ? (_e = this.config) === null || _e === void 0 ? void 0 : _e.witnesses
83
- : [this.config.witnesses]
84
- : undefined;
85
- (_f = this.logger) === null || _f === void 0 ? void 0 : _f.debug(`witnesses:namesOrAddresses: ${namesOrAddresses === null || namesOrAddresses === void 0 ? void 0 : namesOrAddresses.length}`);
86
- const result = namesOrAddresses
87
- ? [
88
- ...(yield this.resolve({ address: namesOrAddresses }, { identity: witness_1.isWitnessInstance })),
89
- ...(yield this.resolve({ name: namesOrAddresses }, { identity: witness_1.isWitnessInstance })),
90
- ]
91
- : yield this.resolve(undefined, { identity: witness_1.isWitnessInstance });
92
- if (namesOrAddresses && namesOrAddresses.length !== result.length) {
93
- (_g = this.logger) === null || _g === void 0 ? void 0 : _g.warn(`Not all witnesses found [Requested: ${namesOrAddresses.length}, Found: ${result.length}]`);
94
- }
95
- result.map((item) => {
96
- var _a;
97
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`witnesses:result: ${item.config.schema}`);
98
- });
99
- return result;
100
- });
101
- }
102
- queryHandler(query, payloads, queryConfig) {
103
- const _super = Object.create(null, {
104
- queryHandler: { get: () => super.queryHandler }
105
- });
106
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
107
- const wrapper = boundwitness_builder_1.QueryBoundWitnessWrapper.parseQuery(query, payloads);
108
- const queryPayload = yield wrapper.getQuery();
109
- (0, assert_1.assertEx)(this.queryable(query, payloads, queryConfig));
110
- const resultPayloads = [];
111
- switch (queryPayload.schema) {
112
- case sentinel_model_1.SentinelReportQuerySchema: {
113
- resultPayloads.push(...(yield this.report(payloads)));
114
- break;
115
- }
116
- default: {
117
- return _super.queryHandler.call(this, query, payloads);
118
- }
119
- }
120
- return resultPayloads;
121
- });
122
- }
123
- }
124
- exports.AbstractSentinel = AbstractSentinel;
125
- //# sourceMappingURL=AbstractSentinel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AbstractSentinel.js","sourceRoot":"","sources":["../../src/AbstractSentinel.ts"],"names":[],"mappings":";;;;AAAA,2CAAyC;AACzC,sDAAqF;AACrF,4EAA+F;AAC/F,wEAA+F;AAG/F,gEAOoC;AACpC,kDAAyE;AACzE,+DAA8B;AAE9B,MAAsB,gBAIpB,SAAQ,mCAA4C;IAJtD;;QAOE,YAAO,GAAmB,EAAE,CAAA;IA6G9B,CAAC;IA3GC,IAAa,OAAO;QAClB,OAAO,CAAC,0CAAyB,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAAA;IACtD,CAAC;IAED,IAAuB,kBAAkB;QACvC,OAAO;YACL,mCAAmC,EAAE,KAAK;SAC3C,CAAA;IACH,CAAC;IAED,YAAY,CAAC,OAAiB;;QAC5B,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,IAAA,cAAI,EAAC,CAAC,GAAG,OAAO,EAAE,GAAG,CAAC,MAAA,IAAI,CAAC,MAAM,CAAC,UAAU,mCAAI,EAAE,CAAC,CAAC,CAAC,CAAA;IAChF,CAAC;IAED,UAAU,CAAC,OAAiB;;QAC1B,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,IAAA,cAAI,EAAC,CAAC,GAAG,OAAO,EAAE,GAAG,CAAC,MAAA,IAAI,CAAC,MAAM,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC,CAAC,CAAA;IAC9E,CAAC;IAEK,UAAU;;;YACd,MAAA,IAAI,CAAC,MAAM,0CAAE,KAAK,CAAC,gCAAgC,MAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,UAAU,0CAAE,MAAM,EAAE,CAAC,CAAA;YACrF,MAAM,gBAAgB,GAAG,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,UAAU;gBAC9C,CAAC,CAAC,KAAK,CAAC,OAAO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,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;;gBAClB,MAAA,IAAI,CAAC,MAAM,0CAAE,KAAK,CAAC,qBAAqB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;YAC/D,CAAC,CAAC,CAAA;YAEF,OAAO,MAAM,CAAA;;KACd;IAEwB,YAAY,CACnC,KAAQ,EACR,QAAoB,EACpB,WAAqB;;;;;YAErB,MAAM,OAAO,GAAG,+CAAwB,CAAC,UAAU,CAAoB,KAAK,EAAE,QAAQ,CAAC,CAAA;YACvF,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAA;YAC7C,IAAA,iBAAQ,EAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAA;YACtD,MAAM,cAAc,GAAc,EAAE,CAAA;YACpC,QAAQ,YAAY,CAAC,MAAM,EAAE;gBAC3B,KAAK,0CAAyB,CAAC,CAAC;oBAC9B,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;oBACrD,MAAK;iBACN;gBACD,OAAO,CAAC,CAAC;oBACP,OAAO,OAAM,YAAY,YAAC,KAAK,EAAE,QAAQ,EAAC;iBAC3C;aACF;YACD,OAAO,cAAc,CAAA;QACvB,CAAC;KAAA;CAGF;AApHD,4CAoHC"}
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SentinelAutomationSchema = void 0;
4
- exports.SentinelAutomationSchema = 'network.xyo.automation';
5
- //# sourceMappingURL=Automation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Automation.js","sourceRoot":"","sources":["../../src/Automation.ts"],"names":[],"mappings":";;;AAIa,QAAA,wBAAwB,GAA6B,wBAAwB,CAAA"}
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemorySentinel = void 0;
4
- const tslib_1 = require("tslib");
5
- const assert_1 = require("@xylabs/assert");
6
- const promise_1 = require("@xylabs/promise");
7
- const error_1 = require("@xyo-network/error");
8
- const sentinel_model_1 = require("@xyo-network/sentinel-model");
9
- const AbstractSentinel_1 = require("./AbstractSentinel");
10
- class MemorySentinel extends AbstractSentinel_1.AbstractSentinel {
11
- reportHandler(payloads = []) {
12
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- yield this.started('throw');
14
- const errors = [];
15
- const allWitnesses = [...(yield this.witnesses())];
16
- const resultPayloads = [];
17
- try {
18
- const [generatedPayloads, generatedErrors] = yield this.generateResults(allWitnesses);
19
- const combinedPayloads = [...generatedPayloads, ...payloads];
20
- resultPayloads.push(...combinedPayloads);
21
- errors.push(...generatedErrors);
22
- }
23
- catch (ex) {
24
- (0, error_1.handleError)(ex, (error) => {
25
- errors.push(error);
26
- });
27
- }
28
- const [boundWitness] = yield this.bindQueryResult({ schema: sentinel_model_1.SentinelReportQuerySchema }, resultPayloads);
29
- this.history.push((0, assert_1.assertEx)(boundWitness));
30
- return [boundWitness, ...resultPayloads];
31
- });
32
- }
33
- generateResults(witnesses) {
34
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
35
- const results = yield Promise.allSettled(witnesses === null || witnesses === void 0 ? void 0 : witnesses.map((witness) => witness.observe()));
36
- const payloads = results
37
- .filter(promise_1.fulfilled)
38
- .map((result) => result.value)
39
- .flat();
40
- const errors = results
41
- .filter(promise_1.rejected)
42
- .map((result) => result.reason)
43
- .flat();
44
- return [payloads, errors];
45
- });
46
- }
47
- }
48
- exports.MemorySentinel = MemorySentinel;
49
- MemorySentinel.configSchemas = [sentinel_model_1.SentinelConfigSchema];
50
- //# sourceMappingURL=MemorySentinel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MemorySentinel.js","sourceRoot":"","sources":["../../src/MemorySentinel.ts"],"names":[],"mappings":";;;;AAAA,2CAAyC;AACzC,6CA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,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;YACxF,MAAM,QAAQ,GAAG,OAAO;iBACrB,MAAM,CAAC,mBAAS,CAAC;iBACjB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;iBAC7B,IAAI,EAAE,CAAA;YACT,MAAM,MAAM,GAAG,OAAO;iBACnB,MAAM,CAAC,kBAAQ,CAAC;iBAChB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;iBAC9B,IAAI,EAAE,CAAA;YACT,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QAC3B,CAAC;KAAA;;AAvCH,wCAwCC;AApCiB,4BAAa,GAAG,CAAC,qCAAoB,CAAC,CAAA"}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SentinelIntervalAutomationWrapper = void 0;
4
- const payload_wrapper_1 = require("@xyo-network/payload-wrapper");
5
- class SentinelIntervalAutomationWrapper extends payload_wrapper_1.PayloadWrapper {
6
- constructor(payload) {
7
- super(payload);
8
- }
9
- get frequencyMillis() {
10
- var _a;
11
- const frequency = this.payload().frequency;
12
- if (frequency === undefined)
13
- return Infinity;
14
- switch ((_a = this.payload().frequencyUnits) !== null && _a !== void 0 ? _a : 'hour') {
15
- case 'second':
16
- return frequency * 1000;
17
- case 'minute':
18
- return frequency * 60 * 1000;
19
- case 'hour':
20
- return frequency * 60 * 60 * 1000;
21
- case 'day':
22
- return frequency * 24 * 60 * 60 * 1000;
23
- }
24
- }
25
- get remaining() {
26
- var _a;
27
- //if remaining is not defined, we assume Infinity
28
- return (_a = this.payload().remaining) !== null && _a !== void 0 ? _a : Infinity;
29
- }
30
- next() {
31
- this.payload().start = this.payload().start + this.frequencyMillis;
32
- this.consumeRemaining();
33
- this.checkEnd();
34
- return this;
35
- }
36
- checkEnd() {
37
- var _a;
38
- if (this.payload().start > ((_a = this.payload().end) !== null && _a !== void 0 ? _a : Infinity)) {
39
- this.payload().start = Infinity;
40
- }
41
- }
42
- consumeRemaining(count = 1) {
43
- const remaining = this.remaining - count;
44
- this.payload().remaining = remaining;
45
- if (remaining <= 0) {
46
- this.payload().start = Infinity;
47
- }
48
- }
49
- }
50
- exports.SentinelIntervalAutomationWrapper = SentinelIntervalAutomationWrapper;
51
- //# sourceMappingURL=SentinelIntervalAutomationWrapper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SentinelIntervalAutomationWrapper.js","sourceRoot":"","sources":["../../src/SentinelIntervalAutomationWrapper.ts"],"names":[],"mappings":";;;AAAA,kEAA6D;AAI7D,MAAa,iCAEX,SAAQ,gCAAiB;IACzB,YAAY,OAAU;QACpB,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;IAED,IAAc,eAAe;;QAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,CAAA;QAC1C,IAAI,SAAS,KAAK,SAAS;YAAE,OAAO,QAAQ,CAAA;QAC5C,QAAQ,MAAA,IAAI,CAAC,OAAO,EAAE,CAAC,cAAc,mCAAI,MAAM,EAAE;YAC/C,KAAK,QAAQ;gBACX,OAAO,SAAS,GAAG,IAAI,CAAA;YACzB,KAAK,QAAQ;gBACX,OAAO,SAAS,GAAG,EAAE,GAAG,IAAI,CAAA;YAC9B,KAAK,MAAM;gBACT,OAAO,SAAS,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;YACnC,KAAK,KAAK;gBACR,OAAO,SAAS,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;SACzC;IACH,CAAC;IAED,IAAc,SAAS;;QACrB,iDAAiD;QACjD,OAAO,MAAA,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,mCAAI,QAAQ,CAAA;IAC7C,CAAC;IAED,IAAI;QACF,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,eAAe,CAAA;QAClE,IAAI,CAAC,gBAAgB,EAAE,CAAA;QACvB,IAAI,CAAC,QAAQ,EAAE,CAAA;QACf,OAAO,IAAI,CAAA;IACb,CAAC;IAES,QAAQ;;QAChB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,GAAG,CAAC,MAAA,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,mCAAI,QAAQ,CAAC,EAAE;YAC3D,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,GAAG,QAAQ,CAAA;SAChC;IACH,CAAC;IAES,gBAAgB,CAAC,KAAK,GAAG,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;QACxC,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,GAAG,SAAS,CAAA;QAEpC,IAAI,SAAS,IAAI,CAAC,EAAE;YAClB,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,GAAG,QAAQ,CAAA;SAChC;IACH,CAAC;CACF;AAhDD,8EAgDC"}
@@ -1,102 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SentinelRunner = void 0;
4
- const tslib_1 = require("tslib");
5
- const assert_1 = require("@xylabs/assert");
6
- const payload_wrapper_1 = require("@xyo-network/payload-wrapper");
7
- const SentinelIntervalAutomationWrapper_1 = require("./SentinelIntervalAutomationWrapper");
8
- class SentinelRunner {
9
- constructor(sentinel, automations, onTriggerResult) {
10
- this._automations = {};
11
- this.sentinel = sentinel;
12
- this.onTriggerResult = onTriggerResult;
13
- automations === null || automations === void 0 ? void 0 : automations.forEach((automation) => this.add(automation));
14
- }
15
- get automations() {
16
- return this._automations;
17
- }
18
- get next() {
19
- return Object.values(this._automations).reduce((previous, current) => {
20
- var _a;
21
- if (current.type === 'interval') {
22
- return current.start < ((_a = previous === null || previous === void 0 ? void 0 : previous.start) !== null && _a !== void 0 ? _a : Infinity) ? current : previous;
23
- }
24
- }, undefined);
25
- }
26
- add(automation, restart = true) {
27
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
28
- const hash = yield payload_wrapper_1.PayloadWrapper.hashAsync(automation);
29
- this._automations[hash] = automation;
30
- if (restart)
31
- yield this.restart();
32
- return hash;
33
- });
34
- }
35
- find(hash) {
36
- Object.entries(this._automations).find(([key]) => key === hash);
37
- }
38
- remove(hash, restart = true) {
39
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
40
- delete this._automations[hash];
41
- if (restart)
42
- yield this.restart();
43
- });
44
- }
45
- removeAll() {
46
- this.stop();
47
- this._automations = {};
48
- }
49
- restart() {
50
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
51
- this.stop();
52
- yield this.start();
53
- });
54
- }
55
- start() {
56
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
57
- (0, assert_1.assertEx)(this.timeoutId === undefined, 'Already started');
58
- const automation = this.next;
59
- if (automation) {
60
- const delay = automation.start - Date.now();
61
- if (delay < 0) {
62
- //automation is due, just do it
63
- yield this.trigger(automation);
64
- }
65
- else {
66
- this.timeoutId = setTimeout(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
67
- this.timeoutId = undefined;
68
- yield this.start();
69
- }), delay > 0 ? delay : 0);
70
- }
71
- }
72
- });
73
- }
74
- stop() {
75
- if (this.timeoutId) {
76
- clearTimeout(this.timeoutId);
77
- this.timeoutId = undefined;
78
- }
79
- }
80
- update(hash, automation, restart = true) {
81
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
82
- yield this.remove(hash, false);
83
- yield this.add(automation, false);
84
- if (restart)
85
- yield this.restart();
86
- });
87
- }
88
- trigger(automation) {
89
- var _a;
90
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
91
- const wrapper = new SentinelIntervalAutomationWrapper_1.SentinelIntervalAutomationWrapper(automation);
92
- yield this.remove(yield wrapper.hashAsync(), false);
93
- wrapper.next();
94
- yield this.add(wrapper.payload(), false);
95
- const triggerResult = yield this.sentinel.report();
96
- (_a = this.onTriggerResult) === null || _a === void 0 ? void 0 : _a.call(this, triggerResult);
97
- yield this.start();
98
- });
99
- }
100
- }
101
- exports.SentinelRunner = SentinelRunner;
102
- //# sourceMappingURL=SentinelRunner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SentinelRunner.js","sourceRoot":"","sources":["../../src/SentinelRunner.ts"],"names":[],"mappings":";;;;AAAA,2CAAyC;AAEzC,kEAA6D;AAI7D,2FAAuF;AAIvF,MAAa,cAAc;IAMzB,YAAY,QAA0B,EAAE,WAAyC,EAAE,eAA+C;QALxH,iBAAY,GAA8C,EAAE,CAAA;QAMpE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAA;IAC5D,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;IAED,IAAY,IAAI;QACd,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAgD,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE;;YAClH,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE;gBAC/B,OAAO,OAAO,CAAC,KAAK,GAAG,CAAC,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK,mCAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAA;aAC1E;QACH,CAAC,EAAE,SAAS,CAAC,CAAA;IACf,CAAC;IAEK,GAAG,CAAC,UAAqC,EAAE,OAAO,GAAG,IAAI;;YAC7D,MAAM,IAAI,GAAG,MAAM,gCA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CAAA;wBAC1B,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;oBACpB,CAAC,CAAA,EACD,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACtB,CAAA;iBACF;aACF;QACH,CAAC;KAAA;IAED,IAAI;QACF,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;SAC3B;IACH,CAAC;IAEK,MAAM,CAAC,IAAY,EAAE,UAAqC,EAAE,OAAO,GAAG,IAAI;;YAC9E,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YAC9B,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;YACjC,IAAI,OAAO;gBAAE,MAAM,IAAI,CAAC,OAAO,EAAE,CAAA;QACnC,CAAC;KAAA;IAEa,OAAO,CAAC,UAA6C;;;YACjE,MAAM,OAAO,GAAG,IAAI,qEAAiC,CAAC,UAAU,CAAC,CAAA;YACjE,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,OAAO,CAAC,SAAS,EAAE,EAAE,KAAK,CAAC,CAAA;YACnD,OAAO,CAAC,IAAI,EAAE,CAAA;YACd,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAA;YACxC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAA;YAClD,MAAA,IAAI,CAAC,eAAe,qDAAG,aAAa,CAAC,CAAA;YACrC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;;KACnB;CACF;AA5FD,wCA4FC"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var _a, _b;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.SentinelWrapper = void 0;
5
- const tslib_1 = require("tslib");
6
- const module_1 = require("@xyo-network/module");
7
- const sentinel_model_1 = require("@xyo-network/sentinel-model");
8
- (0, module_1.constructableModuleWrapper)();
9
- class SentinelWrapper extends (_b = module_1.ModuleWrapper) {
10
- archivists() {
11
- throw Error('Not supported');
12
- }
13
- report(payloads) {
14
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
- const queryPayload = { schema: sentinel_model_1.SentinelReportQuerySchema };
16
- const result = yield this.sendQuery(queryPayload, payloads);
17
- return result;
18
- });
19
- }
20
- witnesses() {
21
- throw Error('Not supported');
22
- }
23
- }
24
- exports.SentinelWrapper = SentinelWrapper;
25
- _a = SentinelWrapper;
26
- SentinelWrapper.instanceIdentityCheck = sentinel_model_1.isSentinelInstance;
27
- SentinelWrapper.moduleIdentityCheck = sentinel_model_1.isSentinelModule;
28
- SentinelWrapper.requiredQueries = [sentinel_model_1.SentinelReportQuerySchema, ...Reflect.get(_b, "requiredQueries", _a)];
29
- //# sourceMappingURL=Wrapper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Wrapper.js","sourceRoot":"","sources":["../../src/Wrapper.ts"],"names":[],"mappings":";;;;;AACA,gDAA+E;AAE/E,gEAOoC;AAGpC,IAAA,mCAA0B,GAAE,CAAA;AAC5B,MAAa,eACX,SAAQ,MAAA,sBAAa,CAAS;IAO9B,UAAU;QACR,MAAM,KAAK,CAAC,eAAe,CAAC,CAAA;IAC9B,CAAC;IAEK,MAAM,CAAC,QAAoB;;YAC/B,MAAM,YAAY,GAAwB,EAAE,MAAM,EAAE,0CAAyB,EAAE,CAAA;YAC/E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;YAC3D,OAAO,MAAM,CAAA;QACf,CAAC;KAAA;IAED,SAAS;QACP,MAAM,KAAK,CAAC,eAAe,CAAC,CAAA;IAC9B,CAAC;;AApBH,0CAqBC;;AAjBiB,qCAAqB,GAAG,mCAAkB,AAArB,CAAqB;AAC1C,mCAAmB,GAAG,iCAAgB,AAAnB,CAAmB;AACtC,+BAAe,GAAG,CAAC,0CAAyB,EAAE,GAAG,sCAAqB,CAAC,AAAxD,CAAwD"}
package/dist/cjs/index.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./AbstractSentinel"), exports);
5
- tslib_1.__exportStar(require("./Automation"), exports);
6
- tslib_1.__exportStar(require("./MemorySentinel"), exports);
7
- tslib_1.__exportStar(require("./SentinelIntervalAutomationWrapper"), exports);
8
- tslib_1.__exportStar(require("./SentinelRunner"), exports);
9
- tslib_1.__exportStar(require("./Wrapper"), exports);
10
- tslib_1.__exportStar(require("@xyo-network/sentinel-model"), exports);
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAkC;AAClC,uDAA4B;AAC5B,2DAAgC;AAChC,8EAAmD;AACnD,2DAAgC;AAChC,oDAAyB;AACzB,sEAA2C"}