@xyo-network/node-abstract 5.3.20 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/node-abstract",
3
- "version": "5.3.20",
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,35 +30,53 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
- "!**/*.test.*"
35
+ "!**/*.test.*",
36
+ "README.md"
37
37
  ],
38
38
  "dependencies": {
39
- "@xyo-network/account-model": "~5.3.20",
40
- "@xyo-network/boundwitness-model": "~5.3.20",
41
- "@xyo-network/boundwitness-wrapper": "~5.3.20",
42
- "@xyo-network/manifest-model": "~5.3.20",
43
- "@xyo-network/module-abstract": "~5.3.20",
44
- "@xyo-network/module-model": "~5.3.20",
45
- "@xyo-network/node-model": "~5.3.20",
46
- "@xyo-network/payload-builder": "~5.3.20",
47
- "@xyo-network/payload-model": "~5.3.20"
39
+ "@xyo-network/boundwitness-model": "~5.3.24",
40
+ "@xyo-network/account-model": "~5.3.24",
41
+ "@xyo-network/boundwitness-wrapper": "~5.3.24",
42
+ "@xyo-network/manifest-model": "~5.3.24",
43
+ "@xyo-network/node-model": "~5.3.24",
44
+ "@xyo-network/module-abstract": "~5.3.24",
45
+ "@xyo-network/module-model": "~5.3.24",
46
+ "@xyo-network/payload-builder": "~5.3.24",
47
+ "@xyo-network/payload-model": "~5.3.24"
48
48
  },
49
49
  "devDependencies": {
50
- "@xylabs/sdk-js": "^5.0.90",
51
- "@xylabs/ts-scripts-common": "~7.5.6",
52
- "@xylabs/ts-scripts-yarn3": "~7.5.6",
53
- "@xylabs/tsconfig": "~7.5.6",
50
+ "@opentelemetry/api": "^1.9.1",
51
+ "@types/node": "^25.5.0",
52
+ "@xylabs/sdk-js": "^5.0.93",
53
+ "@xylabs/ts-scripts-common": "~7.6.16",
54
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
55
+ "@xylabs/tsconfig": "~7.6.16",
56
+ "acorn": "^8.16.0",
57
+ "axios": "^1.14.0",
58
+ "esbuild": "^0.28.0",
59
+ "ethers": "^6.16.0",
60
+ "tslib": "^2.8.1",
54
61
  "typescript": "~5.9.3",
55
- "zod": "^4.3.6"
62
+ "zod": "^4.3.6",
63
+ "@xyo-network/account-model": "~5.3.24",
64
+ "@xyo-network/boundwitness-wrapper": "~5.3.24",
65
+ "@xyo-network/boundwitness-model": "~5.3.24",
66
+ "@xyo-network/manifest-model": "~5.3.24",
67
+ "@xyo-network/module-abstract": "~5.3.24",
68
+ "@xyo-network/payload-builder": "~5.3.24",
69
+ "@xyo-network/module-model": "~5.3.24",
70
+ "@xyo-network/payload-model": "~5.3.24",
71
+ "@xyo-network/node-model": "~5.3.24"
56
72
  },
57
73
  "peerDependencies": {
58
74
  "@xylabs/sdk-js": "^5",
75
+ "ethers": "^6",
76
+ "tslib": "^2.8.1",
59
77
  "zod": "^4"
60
78
  },
61
79
  "publishConfig": {
62
80
  "access": "public"
63
81
  }
64
- }
82
+ }
@@ -1,255 +0,0 @@
1
- import type { Address, Promisable } from '@xylabs/sdk-js'
2
- import { assertEx, globallyUnique } from '@xylabs/sdk-js'
3
- import type { AccountInstance } from '@xyo-network/account-model'
4
- import type { QueryBoundWitness } from '@xyo-network/boundwitness-model'
5
- import { QueryBoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
6
- import type { ModuleManifestPayload, NodeManifestPayload } from '@xyo-network/manifest-model'
7
- import { NodeManifestPayloadSchema } from '@xyo-network/manifest-model'
8
- import { AbstractModuleInstance } from '@xyo-network/module-abstract'
9
- import type {
10
- AddressPayload,
11
- ModuleConfig,
12
- ModuleIdentifier,
13
- ModuleInstance,
14
- ModuleQueryHandlerResult,
15
- ModuleQueryResult,
16
- QueryableModule,
17
- } from '@xyo-network/module-model'
18
- import { AddressSchema } from '@xyo-network/module-model'
19
- import type {
20
- AttachableNodeInstance,
21
- ChildCertification,
22
- ChildCertificationFields,
23
- NodeAttachedQuery,
24
- NodeAttachQuery,
25
- NodeCertifyQuery,
26
- NodeDetachQuery,
27
- NodeInstance,
28
- NodeModule,
29
- NodeModuleEventData,
30
- NodeParams,
31
- NodeQueries,
32
- NodeRegisteredQuery,
33
- } from '@xyo-network/node-model'
34
- import {
35
- ChildCertificationSchema,
36
- NodeAttachedQuerySchema,
37
- NodeAttachQuerySchema,
38
- NodeCertifyQuerySchema,
39
- NodeConfigSchema,
40
- NodeDetachQuerySchema,
41
- NodeRegisteredQuerySchema,
42
- } from '@xyo-network/node-model'
43
- import { PayloadBuilder } from '@xyo-network/payload-builder'
44
- import { type Payload, type Schema } from '@xyo-network/payload-model'
45
-
46
- export abstract class AbstractNode<TParams extends NodeParams = NodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>
47
- extends AbstractModuleInstance<TParams, TEventData>
48
- implements
49
- AttachableNodeInstance<TParams, TEventData>,
50
- QueryableModule<TParams, TEventData>,
51
- NodeInstance<TParams, TEventData>,
52
- ModuleInstance<TParams, TEventData>,
53
- NodeModule<TParams, TEventData> {
54
- static override readonly configSchemas: Schema[] = [...super.configSchemas, NodeConfigSchema]
55
- static override readonly defaultConfigSchema: Schema = NodeConfigSchema
56
- static override readonly uniqueName = globallyUnique('AbstractNode', AbstractNode, 'xyo')
57
-
58
- private readonly isNode = true
59
-
60
- override get queries(): Schema[] {
61
- return [
62
- NodeAttachQuerySchema,
63
- NodeCertifyQuerySchema,
64
- NodeDetachQuerySchema,
65
- NodeAttachedQuerySchema,
66
- NodeRegisteredQuerySchema,
67
- ...super.queries,
68
- ]
69
- }
70
-
71
- static isNode(mod: unknown) {
72
- return (mod as AbstractNode).isNode
73
- }
74
-
75
- async attach(id: ModuleIdentifier, external?: boolean): Promise<Address | undefined> {
76
- this._noOverride('attach')
77
- return await this.attachHandler(id, external)
78
- }
79
-
80
- async attachQuery(id: ModuleIdentifier, external?: boolean, account?: AccountInstance): Promise<ModuleQueryResult<AddressPayload>> {
81
- this._noOverride('attachQuery')
82
- const queryPayload: NodeAttachQuery = {
83
- external, id, schema: NodeAttachQuerySchema,
84
- }
85
- return await this.sendQueryRaw(queryPayload, [], account)
86
- }
87
-
88
- async attached(): Promise<Address[]> {
89
- this._noOverride('attached')
90
- return await this.attachedHandler()
91
- }
92
-
93
- async attachedHandler(): Promise<Address[]> {
94
- return [...(await this.attachedPublicModules()).map(mod => mod.address), ...(await this.attachedPrivateModules()).map(mod => mod.address)]
95
- }
96
-
97
- async attachedQuery(account?: AccountInstance): Promise<ModuleQueryResult<AddressPayload>> {
98
- this._noOverride('attachedQuery')
99
- const queryPayload: NodeAttachedQuery = { schema: NodeAttachedQuerySchema }
100
- return await this.sendQueryRaw(queryPayload, [], account)
101
- }
102
-
103
- async certify(id: ModuleIdentifier): Promise<ChildCertificationFields | undefined> {
104
- this._noOverride('certify')
105
- return await this.certifyHandler(id)
106
- }
107
-
108
- async certifyQuery(id: ModuleIdentifier, account?: AccountInstance): Promise<ModuleQueryResult<ChildCertification>> {
109
- const queryPayload: NodeCertifyQuery = { id, schema: NodeCertifyQuerySchema }
110
- return await this.sendQueryRaw(queryPayload, [], account)
111
- }
112
-
113
- async detach(id: ModuleIdentifier): Promise<Address | undefined> {
114
- this._noOverride('detach')
115
- return await this.detachHandler(id)
116
- }
117
-
118
- async detachQuery(id: ModuleIdentifier, account?: AccountInstance): Promise<ModuleQueryResult<AddressPayload>> {
119
- this._noOverride('detachQuery')
120
- const queryPayload: NodeDetachQuery = { id, schema: NodeDetachQuerySchema }
121
- return await this.sendQueryRaw(queryPayload, [], account)
122
- }
123
-
124
- override async manifest(maxDepth = 10, ignoreAddresses: Address[] = []): Promise<ModuleManifestPayload> {
125
- return await this.manifestHandler(maxDepth, ignoreAddresses)
126
- }
127
-
128
- override async privateChildren(): Promise<ModuleInstance[]> {
129
- return await this.attachedPrivateModules()
130
- }
131
-
132
- override async publicChildren(): Promise<ModuleInstance[]> {
133
- return await this.attachedPublicModules()
134
- }
135
-
136
- async registered(): Promise<Address[]> {
137
- this._noOverride('registered')
138
- return await this.registeredHandler()
139
- }
140
-
141
- async registeredQuery(account?: AccountInstance): Promise<ModuleQueryResult<AddressPayload>> {
142
- this._noOverride('registeredQuery')
143
- const queryPayload: NodeRegisteredQuery = { schema: NodeRegisteredQuerySchema }
144
- return await this.sendQueryRaw(queryPayload, [], account)
145
- }
146
-
147
- protected async attachedPrivateModules(maxDepth = 1): Promise<ModuleInstance[]> {
148
- return (await (this.resolvePrivate('*', { maxDepth }) ?? [])).filter(mod => mod.address !== this.address)
149
- }
150
-
151
- protected async attachedPublicModules(maxDepth = 1): Promise<ModuleInstance[]> {
152
- return (await (this.downResolver.resolve('*', { direction: 'down', maxDepth }) ?? [])).filter(mod => mod.address !== this.address)
153
- }
154
-
155
- protected override async generateConfigAndAddress(maxDepth = 10): Promise<Payload[]> {
156
- const childMods = await this.attachedPublicModules(maxDepth)
157
- // console.log(`childMods: ${toSafeJsonString(childMods)}`)
158
- const childModAddresses = childMods.map(mod => new PayloadBuilder<AddressPayload>({ schema: AddressSchema }).fields({ address: mod.address }).build())
159
-
160
- return [...(await super.generateConfigAndAddress(maxDepth)), ...childModAddresses]
161
- }
162
-
163
- protected override async manifestHandler(maxDepth = 10, ignoreAddresses: Address[] = []): Promise<ModuleManifestPayload> {
164
- const cachedResult = this._cachedManifests.get(maxDepth)
165
- if (cachedResult) {
166
- return cachedResult
167
- }
168
-
169
- const manifest: NodeManifestPayload = { ...(await super.manifestHandler(maxDepth, ignoreAddresses)), schema: NodeManifestPayloadSchema }
170
- const newIgnoreAddresses = [...ignoreAddresses, this.address]
171
-
172
- const notThisModule = (mod: ModuleInstance) => mod.address !== this.address && !ignoreAddresses.includes(mod.address)
173
- const toManifest = (mod: ModuleInstance) => mod.manifest(maxDepth - 1, newIgnoreAddresses)
174
-
175
- const publicChildren = await this.publicChildren()
176
- const publicModuleManifests = await Promise.all(publicChildren.filter(notThisModule).map(toManifest))
177
- if (publicModuleManifests.length > 0) {
178
- manifest.modules = manifest.modules ?? {}
179
- manifest.modules.public = publicModuleManifests
180
- }
181
-
182
- this._cachedManifests.set(maxDepth, manifest)
183
-
184
- return manifest
185
- }
186
-
187
- // eslint-disable-next-line max-statements
188
- protected override async queryHandler<T extends QueryBoundWitness = QueryBoundWitness, TConfig extends ModuleConfig = ModuleConfig>(
189
- query: T,
190
- payloads?: Payload[],
191
- queryConfig?: TConfig,
192
- ): Promise<ModuleQueryHandlerResult> {
193
- const wrapper = QueryBoundWitnessWrapper.parseQuery<NodeQueries>(query, payloads)
194
- const queryPayload = await wrapper.getQuery()
195
- assertEx(await this.queryable(query, payloads, queryConfig), () => 'Module is not queryable with the provided query')
196
- const resultPayloads: Payload[] = []
197
- switch (queryPayload.schema) {
198
- case NodeAttachQuerySchema: {
199
- const typedQueryPayload = queryPayload as NodeAttachQuery
200
- const address = await this.attachHandler(typedQueryPayload.id, typedQueryPayload.external)
201
- if (address) {
202
- const payload = new PayloadBuilder<AddressPayload>({ schema: AddressSchema }).fields({ address }).build()
203
- resultPayloads.push(payload)
204
- }
205
- break
206
- }
207
- case NodeCertifyQuerySchema: {
208
- const typedQueryPayload = queryPayload as NodeCertifyQuery
209
- const fields = await this.certifyHandler(typedQueryPayload.id)
210
- if (fields) {
211
- const payload = new PayloadBuilder<ChildCertification>({ schema: ChildCertificationSchema }).fields(fields).build()
212
- resultPayloads.push(payload)
213
- }
214
- break
215
- }
216
- case NodeDetachQuerySchema: {
217
- const typedQueryPayload = queryPayload as NodeDetachQuery
218
- const address = await this.detachHandler(typedQueryPayload.id)
219
- if (address) {
220
- const payload = new PayloadBuilder<AddressPayload>({ schema: AddressSchema }).fields({ address }).build()
221
- resultPayloads.push(payload)
222
- }
223
- break
224
- }
225
- case NodeAttachedQuerySchema: {
226
- const addresses = await this.attachedHandler()
227
- for (const address of addresses) {
228
- const payload = new PayloadBuilder<AddressPayload>({ schema: AddressSchema }).fields({ address }).build()
229
- resultPayloads.push(payload)
230
- }
231
- break
232
- }
233
- case NodeRegisteredQuerySchema: {
234
- const addresses = await this.registeredHandler()
235
- for (const address of addresses) {
236
- const payload = new PayloadBuilder<AddressPayload>({ schema: AddressSchema }).fields({ address }).build()
237
- resultPayloads.push(payload)
238
- }
239
- break
240
- }
241
- default: {
242
- return await super.queryHandler(query, payloads)
243
- }
244
- }
245
- return resultPayloads
246
- }
247
-
248
- abstract attachHandler(id: ModuleIdentifier, external?: boolean): Promisable<Address | undefined>
249
-
250
- abstract certifyHandler(id: ModuleIdentifier): Promisable<ChildCertificationFields | undefined>
251
-
252
- abstract detachHandler(id: ModuleIdentifier): Promisable<Address | undefined>
253
-
254
- abstract registeredHandler(): Promisable<Address[]>
255
- }
@@ -1,23 +0,0 @@
1
- import type { ModuleInstance } from '@xyo-network/module-model'
2
- import type { NodeInstance } from '@xyo-network/node-model'
3
- import { asNodeInstance } from '@xyo-network/node-model'
4
-
5
- export const attachedPrivateModules = async (node: NodeInstance, maxDepth = 1): Promise<ModuleInstance[]> => {
6
- const remainingDepth = maxDepth - 1
7
- const mods: ModuleInstance[] = []
8
- const publicChildren = await node.privateChildren()
9
- mods.push(...publicChildren)
10
-
11
- if (remainingDepth > 0) {
12
- await Promise.all(
13
- publicChildren.map(async (mod) => {
14
- const node = asNodeInstance(mod)
15
- if (node) {
16
- const children = await attachedPrivateModules(node, remainingDepth)
17
- mods.push(...children)
18
- }
19
- }),
20
- )
21
- }
22
- return mods
23
- }
@@ -1,23 +0,0 @@
1
- import type { ModuleInstance } from '@xyo-network/module-model'
2
- import type { NodeInstance } from '@xyo-network/node-model'
3
- import { asNodeInstance } from '@xyo-network/node-model'
4
-
5
- export const attachedPublicModules = async (node: NodeInstance, maxDepth = 1): Promise<ModuleInstance[]> => {
6
- const remainingDepth = maxDepth - 1
7
- const mods: ModuleInstance[] = []
8
- const publicChildren = await node.publicChildren()
9
- mods.push(...publicChildren)
10
-
11
- if (remainingDepth > 0) {
12
- await Promise.all(
13
- publicChildren.map(async (mod) => {
14
- const node = asNodeInstance(mod)
15
- if (node) {
16
- const children = await attachedPublicModules(node, remainingDepth)
17
- mods.push(...children)
18
- }
19
- }),
20
- )
21
- }
22
- return mods
23
- }
@@ -1,7 +0,0 @@
1
- import { attachedPrivateModules } from './attachedPrivateModules.ts'
2
- import { attachedPublicModules } from './attachedPublicModules.ts'
3
-
4
- export const NodeHelper = {
5
- attachedPrivateModules,
6
- attachedPublicModules,
7
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './AbstractNode.ts'
2
- export * from './NodeHelper/index.ts'