@xyo-network/sentinel 2.75.18 → 2.76.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/dist/browser/AbstractSentinel.d.cts +4 -4
- package/dist/browser/AbstractSentinel.d.cts.map +1 -1
- package/dist/browser/AbstractSentinel.d.mts +4 -4
- package/dist/browser/AbstractSentinel.d.mts.map +1 -1
- package/dist/browser/AbstractSentinel.d.ts +4 -4
- package/dist/browser/AbstractSentinel.d.ts.map +1 -1
- package/dist/browser/Automation.d.cts +2 -2
- package/dist/browser/Automation.d.cts.map +1 -1
- package/dist/browser/Automation.d.mts +2 -2
- package/dist/browser/Automation.d.mts.map +1 -1
- package/dist/browser/Automation.d.ts +2 -2
- package/dist/browser/Automation.d.ts.map +1 -1
- package/dist/browser/MemorySentinel.d.cts +1 -1
- package/dist/browser/MemorySentinel.d.cts.map +1 -1
- package/dist/browser/MemorySentinel.d.mts +1 -1
- package/dist/browser/MemorySentinel.d.mts.map +1 -1
- package/dist/browser/MemorySentinel.d.ts +1 -1
- package/dist/browser/MemorySentinel.d.ts.map +1 -1
- package/dist/browser/index.cjs +64 -46
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +68 -51
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AbstractSentinel.d.cts +4 -4
- package/dist/node/AbstractSentinel.d.cts.map +1 -1
- package/dist/node/AbstractSentinel.d.mts +4 -4
- package/dist/node/AbstractSentinel.d.mts.map +1 -1
- package/dist/node/AbstractSentinel.d.ts +4 -4
- package/dist/node/AbstractSentinel.d.ts.map +1 -1
- package/dist/node/Automation.d.cts +2 -2
- package/dist/node/Automation.d.cts.map +1 -1
- package/dist/node/Automation.d.mts +2 -2
- package/dist/node/Automation.d.mts.map +1 -1
- package/dist/node/Automation.d.ts +2 -2
- package/dist/node/Automation.d.ts.map +1 -1
- package/dist/node/MemorySentinel.d.cts +1 -1
- package/dist/node/MemorySentinel.d.cts.map +1 -1
- package/dist/node/MemorySentinel.d.mts +1 -1
- package/dist/node/MemorySentinel.d.mts.map +1 -1
- package/dist/node/MemorySentinel.d.ts +1 -1
- package/dist/node/MemorySentinel.d.ts.map +1 -1
- package/dist/node/index.js +64 -48
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +68 -53
- package/dist/node/index.mjs.map +1 -1
- package/package.json +26 -32
- package/src/AbstractSentinel.ts +30 -28
- package/src/Automation.ts +2 -2
- package/src/MemorySentinel.ts +43 -36
- package/dist/docs.json +0 -60017
package/package.json
CHANGED
|
@@ -10,36 +10,33 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/assert": "^2.12.
|
|
14
|
-
"@xylabs/
|
|
15
|
-
"@
|
|
16
|
-
"@xyo-network/
|
|
17
|
-
"@xyo-network/boundwitness-
|
|
18
|
-
"@xyo-network/
|
|
19
|
-
"@xyo-network/
|
|
20
|
-
"@xyo-network/
|
|
21
|
-
"@xyo-network/module-
|
|
22
|
-
"@xyo-network/module-
|
|
23
|
-
"@xyo-network/
|
|
24
|
-
"@xyo-network/payload-
|
|
25
|
-
"@xyo-network/
|
|
26
|
-
"@xyo-network/
|
|
27
|
-
"@xyo-network/witness-model": "~2.75.18"
|
|
13
|
+
"@xylabs/assert": "^2.12.28",
|
|
14
|
+
"@xylabs/promise": "^2.12.28",
|
|
15
|
+
"@xyo-network/archivist": "~2.76.1",
|
|
16
|
+
"@xyo-network/boundwitness-builder": "~2.76.1",
|
|
17
|
+
"@xyo-network/boundwitness-model": "~2.76.1",
|
|
18
|
+
"@xyo-network/core": "~2.76.1",
|
|
19
|
+
"@xyo-network/diviner-model": "~2.76.1",
|
|
20
|
+
"@xyo-network/module-abstract": "~2.76.1",
|
|
21
|
+
"@xyo-network/module-model": "~2.76.1",
|
|
22
|
+
"@xyo-network/module-wrapper": "~2.76.1",
|
|
23
|
+
"@xyo-network/payload-model": "~2.76.1",
|
|
24
|
+
"@xyo-network/payload-wrapper": "~2.76.1",
|
|
25
|
+
"@xyo-network/sentinel-model": "~2.76.1",
|
|
26
|
+
"@xyo-network/witness-model": "~2.76.1"
|
|
28
27
|
},
|
|
29
28
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
30
29
|
"devDependencies": {
|
|
31
|
-
"@xylabs/delay": "^2.12.
|
|
32
|
-
"@xylabs/ts-scripts-yarn3": "^3.1.
|
|
33
|
-
"@xylabs/tsconfig": "^3.1.
|
|
34
|
-
"@xyo-network/abstract-witness": "~2.
|
|
35
|
-
"@xyo-network/account": "~2.
|
|
36
|
-
"@xyo-network/
|
|
37
|
-
"@xyo-network/
|
|
38
|
-
"@xyo-network/
|
|
39
|
-
"@xyo-network/
|
|
40
|
-
"@xyo-network/
|
|
41
|
-
"@xyo-network/node-system-info-plugin": "~2.75.18",
|
|
42
|
-
"@xyo-network/witnesses": "~2.75.18",
|
|
30
|
+
"@xylabs/delay": "^2.12.28",
|
|
31
|
+
"@xylabs/ts-scripts-yarn3": "^3.1.12",
|
|
32
|
+
"@xylabs/tsconfig": "^3.1.12",
|
|
33
|
+
"@xyo-network/abstract-witness": "~2.76.1",
|
|
34
|
+
"@xyo-network/account": "~2.76.1",
|
|
35
|
+
"@xyo-network/id-payload-plugin": "~2.76.1",
|
|
36
|
+
"@xyo-network/id-plugin": "~2.76.1",
|
|
37
|
+
"@xyo-network/node-memory": "~2.76.1",
|
|
38
|
+
"@xyo-network/node-system-info-plugin": "~2.76.1",
|
|
39
|
+
"@xyo-network/witnesses": "~2.76.1",
|
|
43
40
|
"typescript": "^5.2.2"
|
|
44
41
|
},
|
|
45
42
|
"docs": "dist/docs.json",
|
|
@@ -67,15 +64,12 @@
|
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
66
|
},
|
|
70
|
-
"./docs": {
|
|
71
|
-
"default": "./dist/docs.json"
|
|
72
|
-
},
|
|
73
67
|
"./package.json": "./package.json"
|
|
74
68
|
},
|
|
75
69
|
"main": "dist/node/index.js",
|
|
76
70
|
"module": "dist/node/index.mjs",
|
|
77
71
|
"homepage": "https://xyo.network",
|
|
78
|
-
"license": "LGPL-3.0",
|
|
72
|
+
"license": "LGPL-3.0-only",
|
|
79
73
|
"publishConfig": {
|
|
80
74
|
"access": "public"
|
|
81
75
|
},
|
|
@@ -84,5 +78,5 @@
|
|
|
84
78
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
85
79
|
},
|
|
86
80
|
"sideEffects": false,
|
|
87
|
-
"version": "2.
|
|
81
|
+
"version": "2.76.1"
|
|
88
82
|
}
|
package/src/AbstractSentinel.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { uniq } from '@xylabs/lodash'
|
|
3
2
|
import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-builder'
|
|
4
3
|
import { BoundWitness, isBoundWitness, notBoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model'
|
|
5
4
|
import { AbstractModuleInstance } from '@xyo-network/module-abstract'
|
|
@@ -7,13 +6,14 @@ import { ModuleConfig, ModuleQueryHandlerResult } from '@xyo-network/module-mode
|
|
|
7
6
|
import { Payload } from '@xyo-network/payload-model'
|
|
8
7
|
import {
|
|
9
8
|
CustomSentinelInstance,
|
|
9
|
+
ResolvedSentinelTask,
|
|
10
10
|
SentinelInstance,
|
|
11
|
+
SentinelJob,
|
|
11
12
|
SentinelModuleEventData,
|
|
12
13
|
SentinelParams,
|
|
13
14
|
SentinelQueryBase,
|
|
14
15
|
SentinelReportQuerySchema,
|
|
15
16
|
} from '@xyo-network/sentinel-model'
|
|
16
|
-
import { isWitnessInstance, WitnessInstance } from '@xyo-network/witness-model'
|
|
17
17
|
|
|
18
18
|
export abstract class AbstractSentinel<
|
|
19
19
|
TParams extends SentinelParams = SentinelParams,
|
|
@@ -23,6 +23,12 @@ export abstract class AbstractSentinel<
|
|
|
23
23
|
implements CustomSentinelInstance<TParams, TEventData>
|
|
24
24
|
{
|
|
25
25
|
history: BoundWitness[] = []
|
|
26
|
+
private _jobPromise?: Promise<SentinelJob>
|
|
27
|
+
|
|
28
|
+
get jobPromise() {
|
|
29
|
+
this._jobPromise = this._jobPromise ?? this.generateJob()
|
|
30
|
+
return this._jobPromise
|
|
31
|
+
}
|
|
26
32
|
|
|
27
33
|
override get queries(): string[] {
|
|
28
34
|
return [SentinelReportQuerySchema, ...super.queries]
|
|
@@ -34,10 +40,6 @@ export abstract class AbstractSentinel<
|
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
42
|
|
|
37
|
-
addWitness(address: string[]) {
|
|
38
|
-
this.config.witnesses = uniq([...address, ...(this.config.witnesses ?? [])])
|
|
39
|
-
}
|
|
40
|
-
|
|
41
43
|
async report(inPayloads?: Payload[]): Promise<Payload[]> {
|
|
42
44
|
this._noOverride('report')
|
|
43
45
|
await this.emit('reportStart', { inPayloads, module: this })
|
|
@@ -50,29 +52,29 @@ export abstract class AbstractSentinel<
|
|
|
50
52
|
return payloads
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
async
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
? [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
protected async generateJob() {
|
|
56
|
+
const job: SentinelJob = { tasks: [] }
|
|
57
|
+
let tasks: ResolvedSentinelTask[] = await Promise.all(
|
|
58
|
+
this.config.tasks.map(async (task) => ({
|
|
59
|
+
input: task.input ?? false,
|
|
60
|
+
module: assertEx(await this.resolve(task.module), `Unable to resolve task module [${task.module}]`),
|
|
61
|
+
})),
|
|
62
|
+
)
|
|
63
|
+
while (tasks.length) {
|
|
64
|
+
const previousTasks = job.tasks.length ? job.tasks[job.tasks.length - 1] : []
|
|
65
|
+
const newList =
|
|
66
|
+
//add all tasks that either require no previous input or have the previous input module already added
|
|
67
|
+
tasks.filter(
|
|
68
|
+
(task) =>
|
|
69
|
+
typeof task.input === 'boolean' ||
|
|
70
|
+
previousTasks.find((prevTask) => prevTask.module.address === task.input || prevTask.module.config.name === task.input),
|
|
71
|
+
)
|
|
72
|
+
assertEx(newList.length > 0, `Unable to generateJob [${tasks.length}]`)
|
|
73
|
+
job.tasks.push(newList)
|
|
74
|
+
//remove the tasks we just added
|
|
75
|
+
tasks = tasks.filter((task) => !newList.includes(task))
|
|
70
76
|
}
|
|
71
|
-
|
|
72
|
-
this.logger?.debug(`witnesses:result: ${item.config.schema}`)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
return result
|
|
77
|
+
return job
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
protected override async queryHandler<T extends QueryBoundWitness = QueryBoundWitness, TConfig extends ModuleConfig = ModuleConfig>(
|
package/src/Automation.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AnyObject } from '@xyo-network/core'
|
|
2
2
|
import { Payload } from '@xyo-network/payload-model'
|
|
3
|
+
import { SentinelTask } from '@xyo-network/sentinel-model'
|
|
3
4
|
|
|
4
5
|
export type SentinelAutomationSchema = 'network.xyo.automation'
|
|
5
6
|
export const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.automation'
|
|
@@ -7,9 +8,8 @@ export const SentinelAutomationSchema: SentinelAutomationSchema = 'network.xyo.a
|
|
|
7
8
|
export type SentinelBaseAutomationPayload<T extends AnyObject = AnyObject> = Payload<
|
|
8
9
|
T & {
|
|
9
10
|
schema: SentinelAutomationSchema
|
|
11
|
+
tasks?: SentinelTask[]
|
|
10
12
|
type?: 'interval' | 'change'
|
|
11
|
-
/** @field The list of witnesses to invoke [all if undefined] */
|
|
12
|
-
witnesses?: string[]
|
|
13
13
|
}
|
|
14
14
|
>
|
|
15
15
|
|
package/src/MemorySentinel.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/assert'
|
|
2
1
|
import { fulfilled, rejected } from '@xylabs/promise'
|
|
3
|
-
import {
|
|
2
|
+
import { Address } from '@xyo-network/core'
|
|
3
|
+
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
4
4
|
import { AnyConfigSchema } from '@xyo-network/module-model'
|
|
5
5
|
import { Payload } from '@xyo-network/payload-model'
|
|
6
6
|
import {
|
|
7
|
+
ResolvedSentinelTask,
|
|
7
8
|
SentinelConfig,
|
|
8
9
|
SentinelConfigSchema,
|
|
9
10
|
SentinelInstance,
|
|
10
11
|
SentinelModuleEventData,
|
|
11
12
|
SentinelParams,
|
|
12
|
-
SentinelReportQuerySchema,
|
|
13
13
|
} from '@xyo-network/sentinel-model'
|
|
14
|
-
import {
|
|
14
|
+
import { asWitnessInstance } from '@xyo-network/witness-model'
|
|
15
15
|
|
|
16
16
|
import { AbstractSentinel } from './AbstractSentinel'
|
|
17
17
|
|
|
@@ -23,42 +23,49 @@ export class MemorySentinel<
|
|
|
23
23
|
> extends AbstractSentinel<TParams, TEventData> {
|
|
24
24
|
static override configSchemas = [SentinelConfigSchema]
|
|
25
25
|
|
|
26
|
-
async reportHandler(
|
|
26
|
+
async reportHandler(inPayloads: Payload[] = []): Promise<Payload[]> {
|
|
27
27
|
await this.started('throw')
|
|
28
|
-
const
|
|
29
|
-
const allWitnesses = [...(await this.witnesses())]
|
|
30
|
-
const resultPayloads: Payload[] = []
|
|
28
|
+
const job = await this.jobPromise
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
} catch (ex) {
|
|
40
|
-
handleError(ex, (error) => {
|
|
41
|
-
errors.push(error)
|
|
42
|
-
})
|
|
30
|
+
let index = 0
|
|
31
|
+
let previousResults: Record<Address, Payload[]> = {}
|
|
32
|
+
while (index < job.tasks.length) {
|
|
33
|
+
const generatedPayloads = await this.generateResults(job.tasks[index], previousResults, inPayloads)
|
|
34
|
+
previousResults = generatedPayloads
|
|
35
|
+
index++
|
|
43
36
|
}
|
|
44
|
-
|
|
45
|
-
const [boundWitness] = await this.bindQueryResult({ schema: SentinelReportQuerySchema }, resultPayloads)
|
|
46
|
-
this.history.push(assertEx(boundWitness))
|
|
47
|
-
return [boundWitness, ...resultPayloads]
|
|
37
|
+
return Object.values(previousResults).flat()
|
|
48
38
|
}
|
|
49
39
|
|
|
50
|
-
private async generateResults(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
40
|
+
private async generateResults(
|
|
41
|
+
tasks: ResolvedSentinelTask[],
|
|
42
|
+
previousResults: Record<Address, Payload[]>,
|
|
43
|
+
inPayloads?: Payload[],
|
|
44
|
+
): Promise<Record<Address, Payload[]>> {
|
|
45
|
+
const results: PromiseSettledResult<[Address, Payload[]]>[] = await Promise.allSettled(
|
|
46
|
+
tasks?.map(async (task) => {
|
|
47
|
+
const witness = asWitnessInstance(task.module)
|
|
48
|
+
const input = task.input ?? false
|
|
49
|
+
if (witness) {
|
|
50
|
+
return [witness.address, await witness.observe(input === true ? inPayloads : input === false ? [] : previousResults[input])]
|
|
51
|
+
}
|
|
52
|
+
const diviner = asDivinerInstance(task.module)
|
|
53
|
+
if (diviner) {
|
|
54
|
+
return [diviner.address, await diviner.divine(input === true ? inPayloads : input === false ? [] : previousResults[input])]
|
|
55
|
+
}
|
|
56
|
+
throw Error('Unsupported module type')
|
|
57
|
+
}),
|
|
58
|
+
)
|
|
59
|
+
const finalResult: Record<Address, Payload[]> = {}
|
|
60
|
+
results.filter(fulfilled).forEach((result) => {
|
|
61
|
+
const [address, payloads] = result.value
|
|
62
|
+
finalResult[address] = finalResult[address] ?? []
|
|
63
|
+
finalResult[address].push(...payloads)
|
|
64
|
+
})
|
|
65
|
+
const errors = results.filter(rejected).map((result) => result.reason)
|
|
66
|
+
if (errors.length > 0) {
|
|
67
|
+
throw Error('At least one module failed')
|
|
68
|
+
}
|
|
69
|
+
return finalResult
|
|
63
70
|
}
|
|
64
71
|
}
|