@xyo-network/sentinel-memory 4.3.0 → 5.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/sentinel-memory",
3
- "version": "4.3.0",
3
+ "version": "5.0.1",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -28,35 +28,40 @@
28
28
  },
29
29
  "module": "dist/neutral/index.mjs",
30
30
  "types": "dist/neutral/index.d.ts",
31
+ "files": [
32
+ "dist",
33
+ "src"
34
+ ],
31
35
  "dependencies": {
32
- "@xylabs/assert": "^4.15.0",
33
- "@xylabs/base": "^4.15.0",
34
- "@xylabs/forget": "^4.15.0",
35
- "@xylabs/promise": "^4.15.0",
36
- "@xylabs/telemetry": "^4.15.0",
37
- "@xylabs/typeof": "^4.15.0",
38
- "@xyo-network/diviner-model": "^4.3.0",
39
- "@xyo-network/module-model": "^4.3.0",
40
- "@xyo-network/payload-builder": "^4.3.0",
41
- "@xyo-network/payload-model": "^4.3.0",
42
- "@xyo-network/payload-wrapper": "^4.3.0",
43
- "@xyo-network/sentinel-abstract": "^4.3.0",
44
- "@xyo-network/sentinel-model": "^4.3.0",
45
- "@xyo-network/witness-model": "^4.3.0"
36
+ "@xylabs/assert": "~5.0.3",
37
+ "@xylabs/base": "~5.0.3",
38
+ "@xylabs/forget": "~5.0.3",
39
+ "@xylabs/promise": "~5.0.3",
40
+ "@xylabs/telemetry": "~5.0.3",
41
+ "@xylabs/typeof": "~5.0.3",
42
+ "@xyo-network/diviner-model": "~5.0.1",
43
+ "@xyo-network/module-model": "~5.0.1",
44
+ "@xyo-network/payload-builder": "~5.0.1",
45
+ "@xyo-network/payload-model": "~5.0.1",
46
+ "@xyo-network/payload-wrapper": "~5.0.1",
47
+ "@xyo-network/sentinel-abstract": "~5.0.1",
48
+ "@xyo-network/sentinel-model": "~5.0.1",
49
+ "@xyo-network/witness-model": "~5.0.1"
46
50
  },
47
51
  "devDependencies": {
48
- "@xylabs/delay": "^4.15.0",
49
- "@xylabs/hex": "^4.15.0",
50
- "@xylabs/ts-scripts-yarn3": "^7.0.1",
51
- "@xylabs/tsconfig": "^7.0.1",
52
- "@xylabs/vitest-extended": "^4.15.0",
53
- "@xyo-network/abstract-witness": "^4.3.0",
54
- "@xyo-network/archivist-memory": "^4.3.0",
55
- "@xyo-network/id-payload-plugin": "^4.3.0",
56
- "@xyo-network/node-memory": "^4.3.0",
57
- "@xyo-network/witness-adhoc": "^4.3.0",
58
- "typescript": "^5.8.3",
59
- "vitest": "^3.2.4"
52
+ "@xylabs/creatable": "~5.0.3",
53
+ "@xylabs/delay": "~5.0.3",
54
+ "@xylabs/hex": "~5.0.3",
55
+ "@xylabs/ts-scripts-yarn3": "~7.1.0",
56
+ "@xylabs/tsconfig": "~7.1.0",
57
+ "@xylabs/vitest-extended": "~5.0.3",
58
+ "@xyo-network/abstract-witness": "~5.0.1",
59
+ "@xyo-network/archivist-memory": "~5.0.1",
60
+ "@xyo-network/id-payload-plugin": "~5.0.1",
61
+ "@xyo-network/node-memory": "~5.0.1",
62
+ "@xyo-network/witness-adhoc": "~5.0.1",
63
+ "typescript": "~5.9.2",
64
+ "vitest": "~3.2.4"
60
65
  },
61
66
  "publishConfig": {
62
67
  "access": "public"
@@ -0,0 +1,70 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import type { CreatableName } from '@xylabs/creatable'
4
+ import { MemoryArchivist } from '@xyo-network/archivist-memory'
5
+ import { MemoryNode } from '@xyo-network/node-memory'
6
+ import { PayloadSchema } from '@xyo-network/payload-model'
7
+ import type { ReportEndEventArgs, SentinelConfig } from '@xyo-network/sentinel-model'
8
+ import { SentinelConfigSchema } from '@xyo-network/sentinel-model'
9
+ import { AdhocWitness, AdhocWitnessConfigSchema } from '@xyo-network/witness-adhoc'
10
+ import {
11
+ describe, expect, test,
12
+ } from 'vitest'
13
+
14
+ import type { MemorySentinelParams } from '../MemorySentinel.ts'
15
+ import { MemorySentinel } from '../MemorySentinel.ts'
16
+
17
+ /**
18
+ * @group sentinel
19
+ * @group module
20
+ */
21
+
22
+ describe('Sentinel', () => {
23
+ test('report [resolve]', async () => {
24
+ const paramsA = {
25
+ config: {
26
+ payload: { nonce: Math.floor(Math.random() * 9_999_999), schema: 'network.xyo.test' },
27
+ schema: AdhocWitnessConfigSchema,
28
+ targetSchema: PayloadSchema,
29
+ },
30
+ }
31
+ const paramsB = {
32
+ config: {
33
+ payload: { nonce: Math.floor(Math.random() * 9_999_999), schema: 'network.xyo.test' },
34
+ schema: AdhocWitnessConfigSchema,
35
+ targetSchema: PayloadSchema,
36
+ },
37
+ }
38
+ const witnessA = (await AdhocWitness.create({ ...paramsA, account: 'random' })) as AdhocWitness
39
+ const witnessB = (await AdhocWitness.create({ ...paramsB, account: 'random' })) as AdhocWitness
40
+ const archivistA = await MemoryArchivist.create({ account: 'random' })
41
+ const archivistB = await MemoryArchivist.create({ account: 'random' })
42
+
43
+ const node = await MemoryNode.create({ account: 'random' })
44
+ await Promise.all(
45
+ [witnessA, witnessB, archivistA, archivistB].map(async (mod) => {
46
+ await node.register(mod)
47
+ await node.attach(mod.address)
48
+ }),
49
+ )
50
+ const params: MemorySentinelParams<SentinelConfig> = {
51
+ name: 'test-sentinel' as CreatableName,
52
+ account: 'random',
53
+ config: {
54
+ archiving: { archivists: [archivistA.address, archivistB.address] },
55
+ schema: SentinelConfigSchema,
56
+ synchronous: true,
57
+ tasks: [{ mod: witnessA.address }, { mod: witnessB.address }],
58
+ },
59
+ }
60
+ const sentinel = await MemorySentinel.create(params)
61
+ sentinel.on('reportEnd', (args) => {
62
+ const { outPayloads } = args as ReportEndEventArgs
63
+ expect(outPayloads?.length).toBe(2)
64
+ })
65
+ await node.register(sentinel)
66
+ await node.attach(sentinel.address)
67
+ const result = await sentinel.report()
68
+ expect(result?.length).toBe(3)
69
+ })
70
+ })
@@ -0,0 +1,54 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import { SentinelIntervalAutomationSchema } from '@xyo-network/sentinel-model'
4
+ import {
5
+ describe, expect, it,
6
+ } from 'vitest'
7
+
8
+ import { SentinelIntervalAutomationWrapper } from '../SentinelIntervalAutomationWrapper.ts'
9
+
10
+ /*
11
+ * @group sentinel
12
+ */
13
+ describe('SentinelIntervalAutomationWrapper', () => {
14
+ const frequency = 1
15
+ const frequencyUnits = 'second'
16
+ const schema = SentinelIntervalAutomationSchema
17
+ const type = 'interval'
18
+ const start = 0
19
+ describe('next', () => {
20
+ it('when more remains', () => {
21
+ const remaining = 2
22
+ const input = {
23
+ frequency, frequencyUnits, remaining, schema, start, type,
24
+ } as const
25
+ const sut = new SentinelIntervalAutomationWrapper(input)
26
+ const actual = sut.next().payload
27
+ expect(actual).toEqual({
28
+ ...input, remaining: 1, start: expect.any(Number),
29
+ })
30
+ })
31
+ it('with one remaining', () => {
32
+ const remaining = 1
33
+ const input = {
34
+ frequency, frequencyUnits, remaining, schema, start, type,
35
+ } as const
36
+ const sut = new SentinelIntervalAutomationWrapper(input)
37
+ const actual = sut.next().payload
38
+ expect(actual).toEqual({
39
+ ...input, remaining: 0, start: Number.POSITIVE_INFINITY,
40
+ })
41
+ })
42
+ it('with zero remaining', () => {
43
+ const remaining = 0
44
+ const input = {
45
+ frequency, frequencyUnits, remaining, schema, start, type,
46
+ } as const
47
+ const sut = new SentinelIntervalAutomationWrapper(input)
48
+ const actual = sut.next().payload
49
+ expect(actual).toEqual({
50
+ ...input, remaining: 0, start: Number.POSITIVE_INFINITY,
51
+ })
52
+ })
53
+ })
54
+ })
@@ -0,0 +1,95 @@
1
+ import '@xylabs/vitest-extended'
2
+
3
+ import { delay } from '@xylabs/delay'
4
+ import type { AbstractWitness } from '@xyo-network/abstract-witness'
5
+ import { IdSchema } from '@xyo-network/id-payload-plugin'
6
+ import { MemoryNode } from '@xyo-network/node-memory'
7
+ import type {
8
+ SentinelConfig,
9
+ SentinelIntervalAutomationPayload,
10
+ } from '@xyo-network/sentinel-model'
11
+ import {
12
+ SentinelConfigSchema,
13
+ SentinelIntervalAutomationSchema,
14
+ } from '@xyo-network/sentinel-model'
15
+ import type { AdhocWitnessConfig } from '@xyo-network/witness-adhoc'
16
+ import { AdhocWitness, AdhocWitnessConfigSchema } from '@xyo-network/witness-adhoc'
17
+ import {
18
+ beforeEach,
19
+ describe, expect, it,
20
+ } from 'vitest'
21
+
22
+ import { MemorySentinel } from '../MemorySentinel.ts'
23
+ import type { OnSentinelRunnerTriggerResult } from '../SentinelRunner.ts'
24
+ import { SentinelRunner } from '../SentinelRunner.ts'
25
+
26
+ /**
27
+ * @group sentinel
28
+ * @group module
29
+ */
30
+
31
+ describe('SentinelRunner', () => {
32
+ let sentinel: MemorySentinel
33
+ let config: SentinelConfig
34
+
35
+ beforeEach(async () => {
36
+ const node = (await MemoryNode.create({ account: 'random' })) as MemoryNode
37
+ const witnessModules: AbstractWitness[] = [
38
+ await AdhocWitness.create({
39
+ account: 'random',
40
+ config: { payload: { id: 1, schema: 'network.xyo.id' }, schema: AdhocWitnessConfigSchema } as AdhocWitnessConfig,
41
+ }),
42
+ ]
43
+ const witnesses = await Promise.all(
44
+ witnessModules.map(async (witness) => {
45
+ await node.register(witness)
46
+ await node.attach(witness.address)
47
+ return witness.address
48
+ }),
49
+ )
50
+
51
+ config = {
52
+ schema: SentinelConfigSchema,
53
+ synchronous: true,
54
+ tasks: witnesses.map(mod => ({ mod })),
55
+ }
56
+
57
+ sentinel = (await MemorySentinel.create({ account: 'random', config })) as MemorySentinel
58
+ await node.register(sentinel)
59
+ await node.attach(sentinel.address)
60
+ })
61
+
62
+ it('should output interval results', async () => {
63
+ let triggered = false
64
+ let timeoutCount = 100
65
+ const intervalAutomation: SentinelIntervalAutomationPayload = {
66
+ frequency: 1,
67
+ frequencyUnits: 'second',
68
+ remaining: 1,
69
+ schema: SentinelIntervalAutomationSchema,
70
+ start: Date.now() - 1,
71
+ type: 'interval',
72
+ }
73
+ const onTriggerResult: OnSentinelRunnerTriggerResult = (results) => {
74
+ triggered = true
75
+ expect(results.length).toBe(2)
76
+ expect(results[1]?.schema).toBe(IdSchema)
77
+ }
78
+
79
+ const runner = new SentinelRunner({
80
+ sentinel, automations: [intervalAutomation], onTriggerResult,
81
+ })
82
+ runner.start()
83
+ while (timeoutCount) {
84
+ if (triggered) {
85
+ runner.stop()
86
+ return
87
+ }
88
+ timeoutCount--
89
+ await delay(100)
90
+ }
91
+ // should never get here if succeeded
92
+ expect(false).toBe(true)
93
+ runner.stop()
94
+ })
95
+ })
package/xy.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
- const config: XyTsupConfig = {
3
- compile: {
4
- browser: {},
5
- neutral: { src: true },
6
- node: {},
7
- },
8
- }
9
-
10
- export default config