@xyo-network/diviner-payload-pointer-memory 5.3.22 → 5.3.24
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 +43 -47
- package/src/Diviner.ts +0 -73
- package/src/combineRules.ts +0 -43
- package/src/findPayload.ts +0 -76
- package/src/index.ts +0 -1
- package/src/spec/testUtil/Account/index.ts +0 -14
- package/src/spec/testUtil/Archivist/getArchivist.ts +0 -10
- package/src/spec/testUtil/Archivist/index.ts +0 -1
- package/src/spec/testUtil/Block/getNewBlock.ts +0 -38
- package/src/spec/testUtil/Block/index.ts +0 -2
- package/src/spec/testUtil/Block/insertBlock.ts +0 -11
- package/src/spec/testUtil/BoundWitness/getNewBoundWitness.ts +0 -25
- package/src/spec/testUtil/BoundWitness/index.ts +0 -1
- package/src/spec/testUtil/Diviner/getPayloadPointerDiviner.ts +0 -10
- package/src/spec/testUtil/Diviner/index.ts +0 -1
- package/src/spec/testUtil/Model/TestWeb3User.ts +0 -4
- package/src/spec/testUtil/Model/index.ts +0 -1
- package/src/spec/testUtil/Node/getTestNode.ts +0 -47
- package/src/spec/testUtil/Node/index.ts +0 -1
- package/src/spec/testUtil/Payload/getNewPayload.ts +0 -14
- package/src/spec/testUtil/Payload/index.ts +0 -2
- package/src/spec/testUtil/Payload/insertPayload.ts +0 -10
- package/src/spec/testUtil/Payload/schema.ts +0 -3
- package/src/spec/testUtil/Pointer/createPointer.ts +0 -41
- package/src/spec/testUtil/Pointer/index.ts +0 -1
- package/src/spec/testUtil/Schema/getTestSchemaName.ts +0 -8
- package/src/spec/testUtil/Schema/index.ts +0 -1
- package/src/spec/testUtil/index.ts +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/diviner-payload-pointer-memory",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.24",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -30,70 +30,66 @@
|
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
31
|
"files": [
|
|
32
32
|
"dist",
|
|
33
|
-
"src",
|
|
34
33
|
"!**/*.bench.*",
|
|
35
34
|
"!**/*.spec.*",
|
|
36
35
|
"!**/*.test.*",
|
|
37
36
|
"README.md"
|
|
38
37
|
],
|
|
39
38
|
"dependencies": {
|
|
40
|
-
"@xyo-network/archivist-model": "~5.3.
|
|
41
|
-
"@xyo-network/boundwitness-
|
|
42
|
-
"@xyo-network/diviner-abstract": "~5.3.
|
|
43
|
-
"@xyo-network/
|
|
44
|
-
"@xyo-network/diviner-
|
|
45
|
-
"@xyo-network/diviner-model": "~5.3.
|
|
46
|
-
"@xyo-network/diviner-payload-abstract": "~5.3.
|
|
47
|
-
"@xyo-network/diviner-payload-model": "~5.3.
|
|
48
|
-
"@xyo-network/
|
|
49
|
-
"@xyo-network/payload-
|
|
50
|
-
"@xyo-network/
|
|
39
|
+
"@xyo-network/archivist-model": "~5.3.24",
|
|
40
|
+
"@xyo-network/diviner-boundwitness-abstract": "~5.3.24",
|
|
41
|
+
"@xyo-network/diviner-abstract": "~5.3.24",
|
|
42
|
+
"@xyo-network/boundwitness-wrapper": "~5.3.24",
|
|
43
|
+
"@xyo-network/diviner-model": "~5.3.24",
|
|
44
|
+
"@xyo-network/diviner-payload-pointer-model": "~5.3.24",
|
|
45
|
+
"@xyo-network/diviner-payload-abstract": "~5.3.24",
|
|
46
|
+
"@xyo-network/diviner-payload-model": "~5.3.24",
|
|
47
|
+
"@xyo-network/payload-model": "~5.3.24",
|
|
48
|
+
"@xyo-network/payload-wrapper": "~5.3.24",
|
|
49
|
+
"@xyo-network/diviner-boundwitness-model": "~5.3.24"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
53
52
|
"@opentelemetry/api": "^1.9.1",
|
|
54
53
|
"@types/node": "^25.5.0",
|
|
55
54
|
"@types/uuid": "~11.0.0",
|
|
56
|
-
"@xylabs/sdk-js": "^5.0.
|
|
57
|
-
"@xylabs/ts-scripts-common": "~7.6.
|
|
58
|
-
"@xylabs/ts-scripts-
|
|
59
|
-
"@xylabs/tsconfig": "~7.6.
|
|
60
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
61
|
-
"@xyo-network/account": "~5.3.22",
|
|
62
|
-
"@xyo-network/account-model": "~5.3.22",
|
|
63
|
-
"@xyo-network/archivist-memory": "~5.3.22",
|
|
64
|
-
"@xyo-network/archivist-model": "~5.3.22",
|
|
65
|
-
"@xyo-network/boundwitness-builder": "~5.3.22",
|
|
66
|
-
"@xyo-network/boundwitness-model": "~5.3.22",
|
|
67
|
-
"@xyo-network/boundwitness-wrapper": "~5.3.22",
|
|
68
|
-
"@xyo-network/diviner-abstract": "~5.3.22",
|
|
69
|
-
"@xyo-network/diviner-boundwitness-abstract": "~5.3.22",
|
|
70
|
-
"@xyo-network/diviner-boundwitness-memory": "~5.3.22",
|
|
71
|
-
"@xyo-network/diviner-boundwitness-model": "~5.3.22",
|
|
72
|
-
"@xyo-network/diviner-model": "~5.3.22",
|
|
73
|
-
"@xyo-network/diviner-payload-abstract": "~5.3.22",
|
|
74
|
-
"@xyo-network/diviner-payload-generic": "~5.3.22",
|
|
75
|
-
"@xyo-network/diviner-payload-model": "~5.3.22",
|
|
76
|
-
"@xyo-network/diviner-payload-pointer-model": "~5.3.22",
|
|
77
|
-
"@xyo-network/node-memory": "~5.3.22",
|
|
78
|
-
"@xyo-network/node-model": "~5.3.22",
|
|
79
|
-
"@xyo-network/payload-builder": "~5.3.22",
|
|
80
|
-
"@xyo-network/payload-model": "~5.3.22",
|
|
81
|
-
"@xyo-network/payload-wrapper": "~5.3.22",
|
|
82
|
-
"@xyo-network/wallet": "~5.3.22",
|
|
83
|
-
"@xyo-network/wallet-model": "~5.3.22",
|
|
55
|
+
"@xylabs/sdk-js": "^5.0.93",
|
|
56
|
+
"@xylabs/ts-scripts-common": "~7.6.16",
|
|
57
|
+
"@xylabs/ts-scripts-pnpm": "~7.6.16",
|
|
58
|
+
"@xylabs/tsconfig": "~7.6.16",
|
|
59
|
+
"@xylabs/vitest-extended": "~5.0.93",
|
|
84
60
|
"acorn": "^8.16.0",
|
|
85
61
|
"axios": "^1.14.0",
|
|
86
|
-
"
|
|
87
|
-
"esbuild": "^0.27.4",
|
|
88
|
-
"eslint": "^10.1.0",
|
|
62
|
+
"esbuild": "^0.28.0",
|
|
89
63
|
"ethers": "^6.16.0",
|
|
90
|
-
"rollup": "^4.60.1",
|
|
91
64
|
"tslib": "^2.8.1",
|
|
92
65
|
"typescript": "~5.9.3",
|
|
93
66
|
"uuid": "~13.0.0",
|
|
94
67
|
"vite": "^8.0.3",
|
|
95
68
|
"vitest": "~4.1.2",
|
|
96
|
-
"zod": "^4.3.6"
|
|
69
|
+
"zod": "^4.3.6",
|
|
70
|
+
"@xyo-network/archivist-model": "~5.3.24",
|
|
71
|
+
"@xyo-network/archivist-memory": "~5.3.24",
|
|
72
|
+
"@xyo-network/account": "~5.3.24",
|
|
73
|
+
"@xyo-network/account-model": "~5.3.24",
|
|
74
|
+
"@xyo-network/boundwitness-builder": "~5.3.24",
|
|
75
|
+
"@xyo-network/boundwitness-wrapper": "~5.3.24",
|
|
76
|
+
"@xyo-network/diviner-abstract": "~5.3.24",
|
|
77
|
+
"@xyo-network/diviner-boundwitness-abstract": "~5.3.24",
|
|
78
|
+
"@xyo-network/boundwitness-model": "~5.3.24",
|
|
79
|
+
"@xyo-network/diviner-boundwitness-model": "~5.3.24",
|
|
80
|
+
"@xyo-network/diviner-model": "~5.3.24",
|
|
81
|
+
"@xyo-network/diviner-boundwitness-memory": "~5.3.24",
|
|
82
|
+
"@xyo-network/diviner-payload-abstract": "~5.3.24",
|
|
83
|
+
"@xyo-network/diviner-payload-model": "~5.3.24",
|
|
84
|
+
"@xyo-network/diviner-payload-generic": "~5.3.24",
|
|
85
|
+
"@xyo-network/node-memory": "~5.3.24",
|
|
86
|
+
"@xyo-network/payload-wrapper": "~5.3.24",
|
|
87
|
+
"@xyo-network/diviner-payload-pointer-model": "~5.3.24",
|
|
88
|
+
"@xyo-network/payload-builder": "~5.3.24",
|
|
89
|
+
"@xyo-network/node-model": "~5.3.24",
|
|
90
|
+
"@xyo-network/payload-model": "~5.3.24",
|
|
91
|
+
"@xyo-network/wallet": "~5.3.24",
|
|
92
|
+
"@xyo-network/wallet-model": "~5.3.24"
|
|
97
93
|
},
|
|
98
94
|
"peerDependencies": {
|
|
99
95
|
"@xylabs/sdk-js": "^5",
|
|
@@ -104,4 +100,4 @@
|
|
|
104
100
|
"publishConfig": {
|
|
105
101
|
"access": "public"
|
|
106
102
|
}
|
|
107
|
-
}
|
|
103
|
+
}
|
package/src/Diviner.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
-
import { AbstractDiviner } from '@xyo-network/diviner-abstract'
|
|
4
|
-
import type { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'
|
|
5
|
-
import type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'
|
|
6
|
-
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
7
|
-
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'
|
|
8
|
-
import type {
|
|
9
|
-
PayloadPointerDivinerParams,
|
|
10
|
-
PointerPayload,
|
|
11
|
-
} from '@xyo-network/diviner-payload-pointer-model'
|
|
12
|
-
import {
|
|
13
|
-
isPointerPayload,
|
|
14
|
-
PayloadPointerDivinerConfigSchema,
|
|
15
|
-
} from '@xyo-network/diviner-payload-pointer-model'
|
|
16
|
-
import type { Payload, Schema } from '@xyo-network/payload-model'
|
|
17
|
-
|
|
18
|
-
import { findPayload } from './findPayload.ts'
|
|
19
|
-
|
|
20
|
-
export class PayloadPointerDiviner<
|
|
21
|
-
TParams extends PayloadPointerDivinerParams = PayloadPointerDivinerParams,
|
|
22
|
-
TIn extends PointerPayload = PointerPayload,
|
|
23
|
-
TOut extends Payload = Payload,
|
|
24
|
-
TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<
|
|
25
|
-
DivinerInstance<TParams, TIn, TOut>,
|
|
26
|
-
TIn,
|
|
27
|
-
TOut
|
|
28
|
-
>,
|
|
29
|
-
> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
30
|
-
static override readonly configSchemas: Schema[] = [...super.configSchemas, PayloadPointerDivinerConfigSchema]
|
|
31
|
-
static override readonly defaultConfigSchema: Schema = PayloadPointerDivinerConfigSchema
|
|
32
|
-
|
|
33
|
-
protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {
|
|
34
|
-
const pointer = payloads?.find(isPointerPayload)
|
|
35
|
-
if (!pointer) return []
|
|
36
|
-
const archivist = await this.getConfigArchivist()
|
|
37
|
-
const boundWitnessDiviner = await this.getBoundWitnessDiviner()
|
|
38
|
-
const payloadDiviner = await this.getPayloadDiviner()
|
|
39
|
-
const result = (await findPayload(archivist, boundWitnessDiviner, payloadDiviner, pointer)) as TOut | undefined
|
|
40
|
-
return result ? [result] : []
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Returns the archivist instance for the given config
|
|
45
|
-
* @returns The archivist instance corresponding to the config
|
|
46
|
-
*/
|
|
47
|
-
private async getBoundWitnessDiviner(): Promise<BoundWitnessDiviner> {
|
|
48
|
-
const name = assertEx(this.config?.boundWitnessDiviner, () => 'Missing archivist in config')
|
|
49
|
-
const mod = assertEx(await this.resolve(name), () => `Config.boundWitnessDiviner module value of ${name} not resolved`)
|
|
50
|
-
const diviner = assertEx(asDivinerInstance(mod), () => `Module ${name} is not an BoundWitnessDiviner`)
|
|
51
|
-
return diviner as BoundWitnessDiviner
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Returns the archivist instance for the given config
|
|
56
|
-
* @returns The archivist instance corresponding to the config
|
|
57
|
-
*/
|
|
58
|
-
private async getConfigArchivist(): Promise<ArchivistInstance> {
|
|
59
|
-
const name = assertEx(this.config?.archivist, () => 'Missing archivist in config')
|
|
60
|
-
return assertEx(await this.archivistInstance(), () => `Config.archivist module value of ${name} not resolved`)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Returns the archivist instance for the given config
|
|
65
|
-
* @returns The archivist instance corresponding to the config
|
|
66
|
-
*/
|
|
67
|
-
private async getPayloadDiviner(): Promise<PayloadDiviner> {
|
|
68
|
-
const name = assertEx(this.config?.payloadDiviner, () => 'Missing payloadDiviner in config')
|
|
69
|
-
const mod = assertEx(await this.resolve(name), () => `Config.payloadDiviner module value of ${name} not resolved`)
|
|
70
|
-
const diviner = assertEx(asDivinerInstance(mod), () => `Module ${name} is not an PayloadDiviner`)
|
|
71
|
-
return diviner as PayloadDiviner
|
|
72
|
-
}
|
|
73
|
-
}
|
package/src/combineRules.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx, exists } from '@xylabs/sdk-js'
|
|
3
|
-
import type { Order } from '@xyo-network/diviner-payload-model'
|
|
4
|
-
import type {
|
|
5
|
-
PayloadRule,
|
|
6
|
-
PayloadSearchCriteria,
|
|
7
|
-
} from '@xyo-network/diviner-payload-pointer-model'
|
|
8
|
-
import {
|
|
9
|
-
isPayloadAddressRule,
|
|
10
|
-
isPayloadSchemaRule,
|
|
11
|
-
isPayloadSequenceOrderRule,
|
|
12
|
-
} from '@xyo-network/diviner-payload-pointer-model'
|
|
13
|
-
|
|
14
|
-
// TODO: Could make it so that composability is such that we:
|
|
15
|
-
// • AND first dimension of array
|
|
16
|
-
// • OR 2nd dimension of array
|
|
17
|
-
export const combineRules = (rules: PayloadRule[][]): PayloadSearchCriteria => {
|
|
18
|
-
const addresses = rules
|
|
19
|
-
.flat()
|
|
20
|
-
.filter(isPayloadAddressRule)
|
|
21
|
-
.map(r => r.address)
|
|
22
|
-
.filter(exists) as Address[]
|
|
23
|
-
|
|
24
|
-
const schemas = rules
|
|
25
|
-
.flat()
|
|
26
|
-
.filter(isPayloadSchemaRule)
|
|
27
|
-
.map(r => r.schema)
|
|
28
|
-
.filter(exists)
|
|
29
|
-
assertEx(schemas.length, () => 'At least one schema must be supplied')
|
|
30
|
-
|
|
31
|
-
const sequenceOrderRule = rules.flat().filter(isPayloadSequenceOrderRule).filter(exists)
|
|
32
|
-
assertEx(sequenceOrderRule.length < 2, () => 'Must not supply more than 1 direction/timestamp rule')
|
|
33
|
-
|
|
34
|
-
const order: Order = sequenceOrderRule[0]?.order || 'desc'
|
|
35
|
-
const cursor = sequenceOrderRule[0]?.sequence
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
addresses,
|
|
39
|
-
cursor,
|
|
40
|
-
order,
|
|
41
|
-
schemas,
|
|
42
|
-
}
|
|
43
|
-
}
|
package/src/findPayload.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
-
import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
|
|
3
|
-
import type { BoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-abstract'
|
|
4
|
-
import type { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'
|
|
5
|
-
import { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
|
|
6
|
-
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'
|
|
7
|
-
import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
|
|
8
|
-
import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
9
|
-
import type {
|
|
10
|
-
PayloadRule, PayloadSearchCriteria, PointerPayload,
|
|
11
|
-
} from '@xyo-network/diviner-payload-pointer-model'
|
|
12
|
-
import { isBoundWitnessPointer } from '@xyo-network/diviner-payload-pointer-model'
|
|
13
|
-
import type { Payload, Schema } from '@xyo-network/payload-model'
|
|
14
|
-
import { PayloadWrapper } from '@xyo-network/payload-wrapper'
|
|
15
|
-
|
|
16
|
-
import { combineRules } from './combineRules.ts'
|
|
17
|
-
|
|
18
|
-
const limit = 1
|
|
19
|
-
|
|
20
|
-
const createBoundWitnessFilterFromSearchCriteria = (searchCriteria: PayloadSearchCriteria): BoundWitnessDivinerQueryPayload[] => {
|
|
21
|
-
const {
|
|
22
|
-
addresses, order = 'desc', schemas, cursor,
|
|
23
|
-
} = searchCriteria
|
|
24
|
-
const query: BoundWitnessDivinerQueryPayload = {
|
|
25
|
-
addresses,
|
|
26
|
-
limit,
|
|
27
|
-
order,
|
|
28
|
-
payload_schemas: schemas,
|
|
29
|
-
schema: BoundWitnessDivinerQuerySchema,
|
|
30
|
-
}
|
|
31
|
-
if (cursor) query.cursor = cursor
|
|
32
|
-
return [query]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const createPayloadFilterFromSearchCriteria = (searchCriteria: PayloadSearchCriteria): Payload[] => {
|
|
36
|
-
const { order = 'desc', schemas } = searchCriteria
|
|
37
|
-
const query: PayloadDivinerQueryPayload = {
|
|
38
|
-
limit, order, schema: PayloadDivinerQuerySchema, schemas,
|
|
39
|
-
}
|
|
40
|
-
return [query]
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const findPayload = async (
|
|
44
|
-
archivist: ArchivistInstance,
|
|
45
|
-
boundWitnessDiviner: BoundWitnessDiviner,
|
|
46
|
-
payloadDiviner: PayloadDiviner,
|
|
47
|
-
pointer: PointerPayload,
|
|
48
|
-
): Promise<Payload | undefined> => {
|
|
49
|
-
const reference = pointer.reference as PayloadRule[][]
|
|
50
|
-
const searchCriteria = combineRules(reference)
|
|
51
|
-
const { addresses } = searchCriteria
|
|
52
|
-
const findWitnessedPayload = addresses?.length
|
|
53
|
-
const returnBoundWitness = isBoundWitnessPointer(pointer)
|
|
54
|
-
if (returnBoundWitness || findWitnessedPayload) {
|
|
55
|
-
const filter = createBoundWitnessFilterFromSearchCriteria(searchCriteria)
|
|
56
|
-
const result = await boundWitnessDiviner.divine(filter)
|
|
57
|
-
const bw = result?.[0] ? BoundWitnessWrapper.parse(result[0]) : undefined
|
|
58
|
-
if (bw) {
|
|
59
|
-
if (returnBoundWitness) return bw.payload
|
|
60
|
-
const { schemas, order = 'desc' } = searchCriteria
|
|
61
|
-
let payloadIndex = order === 'asc' ? 0 : bw.payloadHashes.length - 1
|
|
62
|
-
if (schemas) {
|
|
63
|
-
const schemaInSearchCriteria = (schema: Schema) => schemas.includes(schema)
|
|
64
|
-
payloadIndex = order === 'asc' ? bw.payloadSchemas.findIndex(schemaInSearchCriteria) : bw.payloadSchemas.findLastIndex(schemaInSearchCriteria)
|
|
65
|
-
}
|
|
66
|
-
const hash = bw.payloadHashes[payloadIndex]
|
|
67
|
-
const result = await archivist.get([hash])
|
|
68
|
-
return result?.[0] ? PayloadWrapper.wrap(result?.[0]).payload : undefined
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
// Find payload
|
|
72
|
-
const filter = createPayloadFilterFromSearchCriteria(searchCriteria)
|
|
73
|
-
const result = await payloadDiviner.divine(filter)
|
|
74
|
-
return result?.[0] ? PayloadWrapper.wrap(result?.[0]).payload : undefined
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Diviner.ts'
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Account } from '@xyo-network/account'
|
|
2
|
-
import type { AccountInstance } from '@xyo-network/account-model'
|
|
3
|
-
|
|
4
|
-
let _unitTestSigningAccount: Promise<AccountInstance> | undefined
|
|
5
|
-
// let _otherUnitTestSigningAccount: Promise<AccountInstance> | undefined
|
|
6
|
-
|
|
7
|
-
export const unitTestSigningAccount = () =>
|
|
8
|
-
(_unitTestSigningAccount
|
|
9
|
-
= _unitTestSigningAccount ?? Account.create({ phrase: 'draw seven setup planet bitter return old bronze neither nephew panel pelican' }))
|
|
10
|
-
/*
|
|
11
|
-
export const otherUnitTestSigningAccount = () =>
|
|
12
|
-
(_otherUnitTestSigningAccount
|
|
13
|
-
= _otherUnitTestSigningAccount ?? Account.create({ phrase: 'pitch rich dentist meadow few club place dirt push sustain innocent fix' }))
|
|
14
|
-
*/
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
-
import { asArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
|
-
import type { NodeInstance } from '@xyo-network/node-model'
|
|
5
|
-
|
|
6
|
-
import { ArchivistName } from '../Node/index.ts'
|
|
7
|
-
|
|
8
|
-
export const getArchivist = async (node: NodeInstance, name = ArchivistName): Promise<ArchivistInstance> => {
|
|
9
|
-
return assertEx(asArchivistInstance(await node.resolve(name)), () => `Could not find archivist with name ${name}`)
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getArchivist.ts'
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
2
|
-
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
3
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
4
|
-
|
|
5
|
-
import { unitTestSigningAccount } from '../Account/index.ts'
|
|
6
|
-
// import { getNewPayloads } from '../Payload/index.ts'
|
|
7
|
-
|
|
8
|
-
export const getNewBlock = async (...payloads: Payload[]): Promise<BoundWitness> => {
|
|
9
|
-
return (await (new BoundWitnessBuilder().signer(await unitTestSigningAccount()).payloads(payloads)).build())[0]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
export const getNewBlockWithPayloads = async (numPayloads = 1) => {
|
|
14
|
-
return getNewBlock(...(getNewPayloads(numPayloads)))
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const getNewBlocks = async (numBoundWitnesses = 1): Promise<Array<BoundWitness>> => {
|
|
18
|
-
const sequence = Array.from({ length: numBoundWitnesses }).fill(0)
|
|
19
|
-
return await Promise.all(
|
|
20
|
-
sequence.map(async () => {
|
|
21
|
-
return (await new BoundWitnessBuilder().witness(await unitTestSigningAccount()).build())[0]
|
|
22
|
-
}),
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const getNewBlocksWithPayloads = async (numBoundWitnesses = 1, numPayloads = 1): Promise<Array<BoundWitness>> => {
|
|
27
|
-
return await Promise.all(
|
|
28
|
-
Array.from({ length: numBoundWitnesses })
|
|
29
|
-
.fill(0)
|
|
30
|
-
.map(async () => {
|
|
31
|
-
return (
|
|
32
|
-
await (new BoundWitnessBuilder().witness(await unitTestSigningAccount()).payloads(getNewPayloads(numPayloads))).build()
|
|
33
|
-
)[0]
|
|
34
|
-
}),
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
*/
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
-
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
3
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
4
|
-
|
|
5
|
-
import { getNewBlock } from './getNewBlock.ts'
|
|
6
|
-
|
|
7
|
-
export const insertBlock = async (archivist: ArchivistInstance, boundWitnesses?: BoundWitness | BoundWitness[]): Promise<Payload[]> => {
|
|
8
|
-
boundWitnesses = boundWitnesses ?? (await getNewBlock())
|
|
9
|
-
const data = Array.isArray(boundWitnesses) ? boundWitnesses : [boundWitnesses]
|
|
10
|
-
return archivist.insert(data)
|
|
11
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { AccountInstance } from '@xyo-network/account-model'
|
|
2
|
-
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
3
|
-
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
4
|
-
import type { ModuleError, Payload } from '@xyo-network/payload-model'
|
|
5
|
-
|
|
6
|
-
import { unitTestSigningAccount } from '../Account/index.ts'
|
|
7
|
-
import { getNewPayloads } from '../Payload/index.ts'
|
|
8
|
-
|
|
9
|
-
export const getNewBoundWitness = async (signers?: AccountInstance[], payloads?: Payload[]): Promise<[BoundWitness, Payload[], ModuleError[]]> => {
|
|
10
|
-
return await (new BoundWitnessBuilder().payloads(payloads ?? (getNewPayloads(1))))
|
|
11
|
-
.signers(signers ?? [await unitTestSigningAccount()])
|
|
12
|
-
.build()
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const getNewBoundWitnesses = async (
|
|
16
|
-
signers?: AccountInstance[],
|
|
17
|
-
numBoundWitnesses = 1,
|
|
18
|
-
numPayloads = 1,
|
|
19
|
-
): Promise<[BoundWitness, Payload[], ModuleError[]][]> => {
|
|
20
|
-
const response: [BoundWitness, Payload[], ModuleError[]][] = []
|
|
21
|
-
for (let i = 0; i < numBoundWitnesses; i++) {
|
|
22
|
-
response.push(await getNewBoundWitness(signers ?? [await unitTestSigningAccount()], getNewPayloads(numPayloads)))
|
|
23
|
-
}
|
|
24
|
-
return response
|
|
25
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getNewBoundWitness.ts'
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
2
|
-
import type { NodeInstance } from '@xyo-network/node-model'
|
|
3
|
-
|
|
4
|
-
import type { PayloadPointerDiviner } from '../../../Diviner.ts'
|
|
5
|
-
import { getTestNode, PayloadPointerDivinerName } from '../Node/index.ts'
|
|
6
|
-
|
|
7
|
-
export const getPayloadPointerDiviner = async (node?: NodeInstance) => {
|
|
8
|
-
if (!node) node = await getTestNode()
|
|
9
|
-
return asDivinerInstance(await node?.resolve(PayloadPointerDivinerName)) as PayloadPointerDiviner
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getPayloadPointerDiviner.ts'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './TestWeb3User.ts'
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'
|
|
2
|
-
import { MemoryBoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-memory'
|
|
3
|
-
import { BoundWitnessDivinerConfigSchema } from '@xyo-network/diviner-boundwitness-model'
|
|
4
|
-
import { GenericPayloadDiviner, GenericPayloadDivinerConfigSchema } from '@xyo-network/diviner-payload-generic'
|
|
5
|
-
import type { PayloadPointerDivinerConfig } from '@xyo-network/diviner-payload-pointer-model'
|
|
6
|
-
import { PayloadPointerDivinerConfigSchema } from '@xyo-network/diviner-payload-pointer-model'
|
|
7
|
-
import { MemoryNode } from '@xyo-network/node-memory'
|
|
8
|
-
import type { NodeInstance } from '@xyo-network/node-model'
|
|
9
|
-
|
|
10
|
-
import { PayloadPointerDiviner } from '../../../Diviner.ts'
|
|
11
|
-
|
|
12
|
-
export const ArchivistName = 'Archivist'
|
|
13
|
-
export const BoundWitnessDivinerName = 'BoundWitnessDiviner'
|
|
14
|
-
export const PayloadDivinerName = 'PayloadDiviner'
|
|
15
|
-
export const PayloadPointerDivinerName = 'PayloadPointerDiviner'
|
|
16
|
-
|
|
17
|
-
export const getTestNode = async (): Promise<NodeInstance> => {
|
|
18
|
-
const node = await MemoryNode.create({ account: 'random' })
|
|
19
|
-
const archivist = await MemoryArchivist.create({ account: 'random', config: { schema: MemoryArchivistConfigSchema, name: ArchivistName } })
|
|
20
|
-
const payloadDiviner = await GenericPayloadDiviner.create({
|
|
21
|
-
account: 'random',
|
|
22
|
-
config: {
|
|
23
|
-
schema: GenericPayloadDivinerConfigSchema, name: PayloadDivinerName, archivist: ArchivistName,
|
|
24
|
-
},
|
|
25
|
-
})
|
|
26
|
-
const boundWitnessDiviner = await MemoryBoundWitnessDiviner.create({
|
|
27
|
-
account: 'random',
|
|
28
|
-
config: {
|
|
29
|
-
schema: BoundWitnessDivinerConfigSchema, name: BoundWitnessDivinerName, archivist: ArchivistName,
|
|
30
|
-
},
|
|
31
|
-
})
|
|
32
|
-
const config: PayloadPointerDivinerConfig = {
|
|
33
|
-
schema: PayloadPointerDivinerConfigSchema,
|
|
34
|
-
archivist: ArchivistName,
|
|
35
|
-
|
|
36
|
-
payloadDiviner: PayloadDivinerName,
|
|
37
|
-
boundWitnessDiviner: BoundWitnessDivinerName,
|
|
38
|
-
name: PayloadPointerDivinerName,
|
|
39
|
-
}
|
|
40
|
-
const payloadPointerDiviner = await PayloadPointerDiviner.create({ account: 'random', config })
|
|
41
|
-
const children = [archivist, payloadDiviner, boundWitnessDiviner, payloadPointerDiviner]
|
|
42
|
-
for (const child of children) {
|
|
43
|
-
await node.register(child)
|
|
44
|
-
await node.attach(child.address, true)
|
|
45
|
-
}
|
|
46
|
-
return node
|
|
47
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getTestNode.ts'
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
2
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
3
|
-
import { v4 as uuid } from 'uuid'
|
|
4
|
-
|
|
5
|
-
import { schema } from './schema.ts'
|
|
6
|
-
|
|
7
|
-
export const getNewPayload = (): Payload => {
|
|
8
|
-
const fields = { schema: 'network.xyo.id', salt: uuid() }
|
|
9
|
-
return new PayloadBuilder({ schema }).fields(fields).build()
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const getNewPayloads = (numPayloads: number) => {
|
|
13
|
-
return Array.from({ length: numPayloads }).fill(0).map(getNewPayload)
|
|
14
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
3
|
-
|
|
4
|
-
import { getNewPayload } from './getNewPayload.ts'
|
|
5
|
-
|
|
6
|
-
export const insertPayload = async (archivist: ArchivistInstance, payloads?: Payload | Payload[]): Promise<Payload[]> => {
|
|
7
|
-
const workingPayloads = payloads ?? getNewPayload()
|
|
8
|
-
const data = Array.isArray(workingPayloads) ? workingPayloads : [workingPayloads]
|
|
9
|
-
return await archivist.insert(data)
|
|
10
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Order } from '@xyo-network/diviner-payload-model'
|
|
2
|
-
import type {
|
|
3
|
-
PayloadAddressRule,
|
|
4
|
-
PayloadPointerPayload,
|
|
5
|
-
PayloadRule,
|
|
6
|
-
PayloadSchemaRule,
|
|
7
|
-
PayloadSequenceOrderRule,
|
|
8
|
-
} from '@xyo-network/diviner-payload-pointer-model'
|
|
9
|
-
import { PayloadPointerSchema } from '@xyo-network/diviner-payload-pointer-model'
|
|
10
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
11
|
-
import type { Schema, Sequence } from '@xyo-network/payload-model'
|
|
12
|
-
import { SequenceConstants } from '@xyo-network/payload-model'
|
|
13
|
-
|
|
14
|
-
export const createPointer = (
|
|
15
|
-
addresses: string[][] = [],
|
|
16
|
-
schemas: Schema[][] = [],
|
|
17
|
-
order: Order = 'desc',
|
|
18
|
-
sequence?: Sequence,
|
|
19
|
-
): PayloadPointerPayload => {
|
|
20
|
-
const reference: PayloadRule[][] = []
|
|
21
|
-
|
|
22
|
-
const schemaRules: PayloadSchemaRule[][] = schemas.map((rules) => {
|
|
23
|
-
return rules.map((schema) => {
|
|
24
|
-
return { schema }
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
if (schemaRules.length > 0) reference.push(...schemaRules)
|
|
28
|
-
|
|
29
|
-
const addressRules: PayloadAddressRule[][] = addresses.map((rules) => {
|
|
30
|
-
return rules.map((address) => {
|
|
31
|
-
return { address }
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
if (addressRules.length > 0) reference.push(...addressRules)
|
|
35
|
-
|
|
36
|
-
const sequenceOrderRule: PayloadSequenceOrderRule = { order }
|
|
37
|
-
if (sequence != SequenceConstants.minLocalSequence) sequenceOrderRule.sequence = sequence
|
|
38
|
-
reference.push([sequenceOrderRule])
|
|
39
|
-
|
|
40
|
-
return new PayloadBuilder<PayloadPointerPayload>({ schema: PayloadPointerSchema }).fields({ reference }).build()
|
|
41
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './createPointer.ts'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getTestSchemaName.ts'
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './Account/index.ts'
|
|
2
|
-
export * from './Archivist/index.ts'
|
|
3
|
-
export * from './Block/index.ts'
|
|
4
|
-
export * from './BoundWitness/index.ts'
|
|
5
|
-
export * from './Diviner/index.ts'
|
|
6
|
-
export * from './Model/index.ts'
|
|
7
|
-
export * from './Node/index.ts'
|
|
8
|
-
export * from './Payload/index.ts'
|
|
9
|
-
export * from './Pointer/index.ts'
|
|
10
|
-
export * from './Schema/index.ts'
|