@xyo-network/sentinel 2.47.8 → 2.47.10

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.
@@ -1,8 +1,8 @@
1
- import { EmptyObject } from '@xyo-network/core';
1
+ import { AnyObject } from '@xyo-network/core';
2
2
  import { XyoPayload } from '@xyo-network/payload-model';
3
3
  export type SentinelAutomationSchema = 'network.xyo.automation';
4
4
  export declare const SentinelAutomationSchema: SentinelAutomationSchema;
5
- export type SentinelBaseAutomationPayload<T extends EmptyObject = EmptyObject> = XyoPayload<T & {
5
+ export type SentinelBaseAutomationPayload<T extends AnyObject = AnyObject> = XyoPayload<T & {
6
6
  schema: SentinelAutomationSchema;
7
7
  type?: 'interval' | 'change';
8
8
  /** @field The list of witnesses to invoke [all if undefined] */
@@ -1 +1 @@
1
- {"version":3,"file":"Automation.d.ts","sourceRoot":"","sources":["../../src/Automation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,MAAM,MAAM,wBAAwB,GAAG,wBAAwB,CAAA;AAC/D,eAAO,MAAM,wBAAwB,EAAE,wBAAmD,CAAA;AAE1F,MAAM,MAAM,6BAA6B,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,UAAU,CACzF,CAAC,GAAG;IACF,MAAM,EAAE,wBAAwB,CAAA;IAChC,IAAI,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAA;IAC5B,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB,CACF,CAAA;AAED,MAAM,MAAM,iCAAiC,GAAG,6BAA6B,CAAC;IAC5E,sDAAsD;IACtD,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,QAAQ,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AM,MAAM,+BAA+B,GAAG,6BAA6B,CAAC;IAC1E,IAAI,EAAE,QAAQ,CAAA;CACf,CAAC,CAAA;AAEF,MAAM,MAAM,yBAAyB,GAAG,iCAAiC,GAAG,+BAA+B,CAAA"}
package/package.json CHANGED
@@ -11,24 +11,24 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@xylabs/assert": "^2.7.1",
14
- "@xyo-network/account": "^2.47.8",
15
- "@xyo-network/archivist": "^2.47.8",
16
- "@xyo-network/archivist-wrapper": "^2.47.8",
17
- "@xyo-network/boundwitness-model": "^2.47.8",
18
- "@xyo-network/core": "^2.47.8",
19
- "@xyo-network/module": "^2.47.8",
20
- "@xyo-network/module-model": "^2.47.8",
21
- "@xyo-network/payload-model": "^2.47.8",
22
- "@xyo-network/payload-wrapper": "^2.47.8",
23
- "@xyo-network/promise": "^2.47.8",
24
- "@xyo-network/witness": "^2.47.8",
14
+ "@xyo-network/account": "^2.47.10",
15
+ "@xyo-network/archivist": "^2.47.10",
16
+ "@xyo-network/archivist-wrapper": "^2.47.10",
17
+ "@xyo-network/boundwitness-model": "^2.47.10",
18
+ "@xyo-network/core": "^2.47.10",
19
+ "@xyo-network/module": "^2.47.10",
20
+ "@xyo-network/module-model": "^2.47.10",
21
+ "@xyo-network/payload-model": "^2.47.10",
22
+ "@xyo-network/payload-wrapper": "^2.47.10",
23
+ "@xyo-network/promise": "^2.47.10",
24
+ "@xyo-network/witness": "^2.47.10",
25
25
  "lodash": "^4.17.21"
26
26
  },
27
27
  "description": "Primary SDK for using XYO Protocol 2.0",
28
28
  "devDependencies": {
29
29
  "@types/lodash": "^4.14.191",
30
- "@xylabs/ts-scripts-yarn3": "^2.14.16",
31
- "@xylabs/tsconfig": "^2.14.16",
30
+ "@xylabs/ts-scripts-yarn3": "^2.15.0",
31
+ "@xylabs/tsconfig": "^2.15.0",
32
32
  "typescript": "^4.9.5"
33
33
  },
34
34
  "browser": "dist/esm/index.js",
@@ -63,5 +63,5 @@
63
63
  },
64
64
  "sideEffects": false,
65
65
  "types": "dist/types/index.d.ts",
66
- "version": "2.47.8"
66
+ "version": "2.47.10"
67
67
  }
package/src/Automation.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { EmptyObject } from '@xyo-network/core'
1
+ import { AnyObject } from '@xyo-network/core'
2
2
  import { XyoPayload } from '@xyo-network/payload-model'
3
3
 
4
4
  export type SentinelAutomationSchema = 'network.xyo.automation'
5
5
  export const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'
6
6
 
7
- export type SentinelBaseAutomationPayload<T extends EmptyObject = EmptyObject> = XyoPayload<
7
+ export type SentinelBaseAutomationPayload<T extends AnyObject = AnyObject> = XyoPayload<
8
8
  T & {
9
9
  schema: SentinelAutomationSchema
10
10
  type?: 'interval' | 'change'
@@ -1,216 +0,0 @@
1
- import { AbstractArchivist, Archivist, MemoryArchivist } from '@xyo-network/archivist'
2
- import { XyoBoundWitness, XyoBoundWitnessSchema } from '@xyo-network/boundwitness-model'
3
- import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'
4
- import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
5
- import { Hasher } from '@xyo-network/core'
6
- import { IdWitness, IdWitnessConfigSchema } from '@xyo-network/id-plugin'
7
- import { CompositeModuleResolver, ModuleParams } from '@xyo-network/module'
8
- import { XyoNodeSystemInfoWitness, XyoNodeSystemInfoWitnessConfigSchema } from '@xyo-network/node-system-info-plugin'
9
- import { XyoPayload, XyoPayloadSchema } from '@xyo-network/payload-model'
10
- import { PayloadWrapper } from '@xyo-network/payload-wrapper'
11
- import { AbstractWitness } from '@xyo-network/witness'
12
- import { XyoAdhocWitness, XyoAdhocWitnessConfigSchema } from '@xyo-network/witnesses'
13
-
14
- import { AbstractSentinel } from '../AbstractSentinel'
15
- import { SentinelConfig, SentinelConfigSchema } from '../Config'
16
-
17
- describe('Sentinel', () => {
18
- test('all [simple sentinel send]', async () => {
19
- const archivist = await MemoryArchivist.create()
20
-
21
- const witnesses: AbstractWitness[] = [
22
- await IdWitness.create({ config: { salt: 'test', schema: IdWitnessConfigSchema } }),
23
- await XyoNodeSystemInfoWitness.create({
24
- config: {
25
- nodeValues: {
26
- osInfo: '*',
27
- },
28
- schema: XyoNodeSystemInfoWitnessConfigSchema,
29
- },
30
- }),
31
- ]
32
-
33
- const config: SentinelConfig = {
34
- archivists: [archivist.address],
35
- schema: SentinelConfigSchema,
36
- witnesses: witnesses.map((witness) => witness.address),
37
- }
38
-
39
- const resolver = new CompositeModuleResolver()
40
- resolver.add(archivist)
41
- witnesses.forEach((witness) => resolver.add(witness))
42
-
43
- const sentinel = await AbstractSentinel.create({ config, resolver })
44
- expect(await sentinel.getArchivists()).toBeArrayOfSize(1)
45
- expect(await sentinel.getWitnesses()).toBeArrayOfSize(2)
46
- const adhocWitness = await XyoAdhocWitness.create({
47
- config: {
48
- payload: {
49
- schema: 'network.xyo.test.array',
50
- testArray: [1, 2, 3],
51
- testBoolean: true,
52
- testNull: null,
53
- testNullObject: { t: null, x: undefined },
54
- testNumber: 5,
55
- testObject: { t: 1 },
56
- testSomeNullObject: { s: 1, t: null, x: undefined },
57
- testString: 'hi',
58
- testUndefined: undefined,
59
- },
60
- schema: XyoAdhocWitnessConfigSchema,
61
- },
62
- })
63
-
64
- const adhocObserved = await adhocWitness.observe([adhocWitness.config.payload])
65
-
66
- const report1Result = await sentinel.report(adhocObserved)
67
- const report1 = BoundWitnessWrapper.parse(report1Result[0])
68
- expect(report1.schemaName).toBe(XyoBoundWitnessSchema)
69
- expect(report1.payloadHashes).toBeArrayOfSize(3)
70
- const report2 = BoundWitnessWrapper.parse((await sentinel.report())[0])
71
- expect(report2.schemaName).toBeDefined()
72
- expect(report2.payloadHashes).toBeArrayOfSize(2)
73
- expect(report2.hash !== report1.hash).toBe(true)
74
- expect(report2.prev(sentinel.address)).toBeDefined()
75
- expect(report2.prev(sentinel.address)).toBe(report1.hash)
76
- expect(report1.valid).toBe(true)
77
- expect(report2.valid).toBe(true)
78
- })
79
- describe('report', () => {
80
- describe('reports witnesses when supplied in', () => {
81
- let archivistA: AbstractArchivist
82
- let archivistB: AbstractArchivist
83
- let witnessA: AbstractWitness
84
- let witnessB: AbstractWitness
85
- const assertSentinelReport = (sentinelReport: [XyoBoundWitness, XyoPayload[]]) => {
86
- expect(sentinelReport).toBeArrayOfSize(2)
87
- const [bw, payloads] = sentinelReport
88
- expect(new BoundWitnessValidator(bw).validate()).toBeArrayOfSize(0)
89
- expect(payloads).toBeArrayOfSize(2)
90
- }
91
- const assertArchivistStateMatchesSentinelReport = async (sentinelReport: [XyoBoundWitness, XyoPayload[]], archivists: Archivist[]) => {
92
- const [, payloads] = sentinelReport
93
- for (const archivist of archivists) {
94
- const archivistPayloads = await archivist.all?.()
95
- expect(archivistPayloads).toBeArrayOfSize(payloads.length + 1)
96
- const sentinelPayloads = payloads.map((payload) => {
97
- const wrapped = new PayloadWrapper(payload)
98
- return { ...payload, _hash: wrapped.hash, _timestamp: expect.toBeNumber() }
99
- })
100
- expect(archivistPayloads).toContainValues(sentinelPayloads)
101
- }
102
- }
103
- beforeEach(async () => {
104
- const paramsA = {
105
- config: {
106
- payload: { nonce: Math.floor(Math.random() * 9999999), schema: 'network.xyo.test' },
107
- schema: XyoAdhocWitnessConfigSchema,
108
- targetSchema: XyoPayloadSchema,
109
- },
110
- }
111
- const paramsB = {
112
- config: {
113
- payload: { nonce: Math.floor(Math.random() * 9999999), schema: 'network.xyo.test' },
114
- schema: XyoAdhocWitnessConfigSchema,
115
- targetSchema: XyoPayloadSchema,
116
- },
117
- }
118
- witnessA = await XyoAdhocWitness.create(paramsA)
119
- witnessB = await XyoAdhocWitness.create(paramsB)
120
- archivistA = await MemoryArchivist.create()
121
- archivistB = await MemoryArchivist.create()
122
- })
123
- it('config', async () => {
124
- const resolver = new CompositeModuleResolver()
125
- resolver.add([witnessA, witnessB, archivistA, archivistB])
126
- const params: ModuleParams<SentinelConfig> = {
127
- config: {
128
- archivists: [archivistA.address, archivistB.address],
129
- schema: 'network.xyo.sentinel.config',
130
- witnesses: [witnessA.address, witnessB.address],
131
- },
132
- resolver,
133
- }
134
- const sentinel = await AbstractSentinel.create(params)
135
- const result = await sentinel.report()
136
- assertSentinelReport(result)
137
- await assertArchivistStateMatchesSentinelReport(result, [archivistA, archivistB])
138
- })
139
- it('config & inline', async () => {
140
- const resolver = new CompositeModuleResolver()
141
- resolver.add([witnessA, archivistA, archivistB])
142
- const params: ModuleParams<SentinelConfig> = {
143
- config: {
144
- archivists: [archivistA.address, archivistB.address],
145
- schema: 'network.xyo.sentinel.config',
146
- witnesses: [witnessA.address],
147
- },
148
- resolver,
149
- }
150
- const sentinel = await AbstractSentinel.create(params)
151
- const observed = await witnessB.observe()
152
- expect(observed).toBeArrayOfSize(1)
153
- const result = await sentinel.report(observed)
154
- assertSentinelReport(result)
155
- await assertArchivistStateMatchesSentinelReport(result, [archivistA, archivistB])
156
- })
157
- it('inline', async () => {
158
- const resolver = new CompositeModuleResolver()
159
- resolver.add([archivistA, archivistB])
160
- const params: ModuleParams<SentinelConfig> = {
161
- config: {
162
- archivists: [archivistA.address, archivistB.address],
163
- schema: 'network.xyo.sentinel.config',
164
- witnesses: [],
165
- },
166
- resolver,
167
- }
168
- const sentinel = await AbstractSentinel.create(params)
169
- const observedA = await witnessA.observe()
170
- expect(observedA).toBeArrayOfSize(1)
171
- const observedB = await witnessB.observe()
172
- expect(observedB).toBeArrayOfSize(1)
173
- const result = await sentinel.report([...observedA, ...observedB])
174
- assertSentinelReport(result)
175
- expect((await archivistA.get([Hasher.hash(observedA[0])])).length).toBe(1)
176
- expect((await archivistA.get([Hasher.hash(observedB[0])])).length).toBe(1)
177
- expect((await archivistB.get([Hasher.hash(observedA[0])])).length).toBe(1)
178
- expect((await archivistB.get([Hasher.hash(observedB[0])])).length).toBe(1)
179
- await assertArchivistStateMatchesSentinelReport(result, [archivistA, archivistB])
180
- })
181
- it('reports errors', async () => {
182
- const paramsA = {
183
- config: {
184
- payload: { nonce: Math.floor(Math.random() * 9999999), schema: 'network.xyo.test' },
185
- schema: XyoAdhocWitnessConfigSchema,
186
- },
187
- }
188
- class FailingWitness extends XyoAdhocWitness {
189
- override async observe(): Promise<XyoPayload[]> {
190
- await Promise.reject(Error('observation failed'))
191
- return [{ schema: 'fake.result' }]
192
- }
193
- }
194
- const witnessA = await FailingWitness.create(paramsA)
195
-
196
- const resolver = new CompositeModuleResolver()
197
- resolver.add([witnessA, witnessB, archivistA, archivistB])
198
- const params: ModuleParams<SentinelConfig> = {
199
- config: {
200
- archivists: [archivistA.address, archivistB.address],
201
- onReportEnd(_, errors) {
202
- expect(errors?.length).toBe(1)
203
- expect(errors?.[0]?.message).toBe('observation failed')
204
- },
205
- schema: 'network.xyo.sentinel.config',
206
- witnesses: [witnessA.address, witnessB.address],
207
- },
208
- resolver,
209
- }
210
- const sentinel = await AbstractSentinel.create(params)
211
- await sentinel.report()
212
- return
213
- })
214
- })
215
- })
216
- })
@@ -1,48 +0,0 @@
1
- import { XyoBoundWitnessSchema } from '@xyo-network/boundwitness-model'
2
- import { CompositeModuleResolver } from '@xyo-network/module'
3
- import { IdSchema, IdWitness, IdWitnessConfigSchema } from '@xyo-network/plugins'
4
- import { AbstractWitness } from '@xyo-network/witness'
5
-
6
- import { AbstractSentinel } from '../AbstractSentinel'
7
- import { SentinelAutomationSchema, SentinelIntervalAutomationPayload } from '../Automation'
8
- import { SentinelConfig, SentinelConfigSchema } from '../Config'
9
- import { OnSentinelRunnerTriggerResult, SentinelRunner } from '../SentinelRunner'
10
-
11
- describe('SentinelRunner', () => {
12
- let sentinel: AbstractSentinel
13
- let config: SentinelConfig
14
-
15
- beforeEach(async () => {
16
- const witnesses: AbstractWitness[] = [await IdWitness.create({ config: { salt: 'test', schema: IdWitnessConfigSchema } })]
17
- const resolver = new CompositeModuleResolver()
18
- witnesses.forEach((witness) => resolver.add(witness))
19
-
20
- config = {
21
- schema: SentinelConfigSchema,
22
- witnesses: witnesses.map((witness) => witness.address),
23
- }
24
-
25
- sentinel = await AbstractSentinel.create({ config, resolver })
26
- })
27
-
28
- it('should output interval results', async () => {
29
- const intervalAutomation: SentinelIntervalAutomationPayload = {
30
- frequency: 1,
31
- frequencyUnits: 'minute',
32
- remaining: 1,
33
- schema: SentinelAutomationSchema,
34
- start: Date.now() - 1,
35
- type: 'interval',
36
- witnesses: config.witnesses,
37
- }
38
- const onTriggerResult: OnSentinelRunnerTriggerResult = (results) => {
39
- expect(results.length).toBe(2)
40
- expect(results[0]?.schema).toBe(XyoBoundWitnessSchema)
41
- expect(results[1].length).toBe(1)
42
- expect(results[1]?.[0].schema).toBe(IdSchema)
43
- }
44
-
45
- const runner = new SentinelRunner(sentinel, [intervalAutomation], onTriggerResult)
46
- await runner.start()
47
- })
48
- })