@xyo-network/react-standard-node 7.5.7 → 7.5.11

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/react-standard-node",
3
- "version": "7.5.7",
3
+ "version": "7.5.11",
4
4
  "description": "Common React library for all XYO projects that use React",
5
5
  "keywords": [
6
6
  "xyo",
@@ -36,64 +36,175 @@
36
36
  },
37
37
  "./package.json": "./package.json"
38
38
  },
39
- "module": "dist/browser/index.mjs",
40
- "types": "dist/browser/index.d.ts",
41
39
  "files": [
42
40
  "dist",
43
- "src"
41
+ "README.md"
44
42
  ],
45
43
  "dependencies": {
46
- "@xylabs/react-async-effect": "~7.1.17",
47
- "@xylabs/react-hooks": "~7.1.17",
48
- "@xylabs/react-promise": "~7.1.17",
49
- "@xylabs/react-shared": "~7.1.17",
50
- "@xylabs/sdk-js": "~5.0.90",
51
- "@xyo-network/account-model": "~5.3.17",
52
- "@xyo-network/archivist-memory": "~5.3.17",
53
- "@xyo-network/archivist-model": "~5.3.17",
54
- "@xyo-network/archivist-storage": "~5.3.17",
55
- "@xyo-network/bridge-http": "~5.3.17",
56
- "@xyo-network/module-model": "~5.3.17",
57
- "@xyo-network/node-memory": "~5.3.17",
58
- "@xyo-network/node-model": "~5.3.17",
59
- "@xyo-network/payloadset-plugin": "~5.3.17",
60
- "@xyo-network/react-network": "7.5.7",
61
- "@xyo-network/react-node": "7.5.7",
62
- "@xyo-network/react-wallet": "7.5.7",
63
- "@xyo-network/sentinel-memory": "~5.3.17",
64
- "@xyo-network/sentinel-model": "~5.3.17",
65
- "@xyo-network/wallet-model": "~5.3.17",
66
- "@xyo-network/witness-model": "~5.3.17"
44
+ "@xyo-network/react-network": "~7.5.11",
45
+ "@xyo-network/react-node": "~7.5.11",
46
+ "@xyo-network/react-wallet": "~7.5.11"
67
47
  },
68
48
  "devDependencies": {
69
- "@mui/icons-material": "~7.3.9",
70
- "@mui/material": "~7.3.9",
49
+ "@bitauth/libauth": "~3.0.0",
50
+ "@emotion/react": "^11.14.0",
51
+ "@mui/icons-material": "^7.3.10",
52
+ "@mui/material": "^7.3.10",
53
+ "@mui/system": "^7.3.10",
54
+ "@mui/x-tree-view": "~8.27.2",
55
+ "@opentelemetry/api": "^1.9.1",
56
+ "@opentelemetry/sdk-trace-base": "^2.7.0",
57
+ "@scure/base": "~2.2.0",
58
+ "@scure/bip39": "~2.2.0",
59
+ "@types/node": "~25.6.0",
71
60
  "@types/react": "^19.2.14",
72
- "@xylabs/sdk-js": "~5.0.90",
73
- "@xylabs/ts-scripts-common": "~7.5.6",
74
- "@xylabs/ts-scripts-yarn3": "~7.5.6",
75
- "@xylabs/tsconfig": "~7.5.6",
76
- "@xylabs/tsconfig-dom": "~7.5.6",
77
- "@xylabs/tsconfig-react": "~7.5.6",
78
- "react": "^19.2.4",
79
- "react-dom": "^19.2.4",
80
- "react-router-dom": "^7.13.2",
81
- "storybook": "~10.3.3",
61
+ "@xylabs/react-async-effect": "~7.1.20",
62
+ "@xylabs/react-button": "~7.1.20",
63
+ "@xylabs/react-crypto": "~7.1.20",
64
+ "@xylabs/react-dialogs": "~7.1.20",
65
+ "@xylabs/react-flexbox": "~7.1.20",
66
+ "@xylabs/react-hooks": "~7.1.20",
67
+ "@xylabs/react-identicon": "~7.1.20",
68
+ "@xylabs/react-link": "~7.1.20",
69
+ "@xylabs/react-number-status": "~7.1.20",
70
+ "@xylabs/react-promise": "~7.1.20",
71
+ "@xylabs/react-quick-tip-button": "~7.1.20",
72
+ "@xylabs/react-select": "~7.1.20",
73
+ "@xylabs/react-shared": "~7.1.20",
74
+ "@xylabs/react-theme": "~7.1.20",
75
+ "@xylabs/sdk-js": "^5.0.100",
76
+ "@xylabs/threads": "~5.0.100",
77
+ "@xylabs/toolchain": "~7.11.9",
78
+ "@xylabs/tsconfig": "^7.11.9",
79
+ "@xylabs/tsconfig-dom": "^7.11.9",
80
+ "@xylabs/tsconfig-react": "~7.11.9",
81
+ "@xylabs/zod": "~5.0.100",
82
+ "@xyo-network/account": "~5.5.1",
83
+ "@xyo-network/account-model": "^5.5.1",
84
+ "@xyo-network/archivist-memory": "~5.5.5",
85
+ "@xyo-network/archivist-model": "^5.5.5",
86
+ "@xyo-network/archivist-storage": "~5.5.5",
87
+ "@xyo-network/boundwitness-builder": "^5.5.1",
88
+ "@xyo-network/boundwitness-model": "^5.5.1",
89
+ "@xyo-network/boundwitness-validator": "^5.5.1",
90
+ "@xyo-network/boundwitness-wrapper": "~5.5.1",
91
+ "@xyo-network/bridge-http": "~5.5.5",
92
+ "@xyo-network/config-payload-plugin": "~5.5.1",
93
+ "@xyo-network/manifest-model": "~5.5.1",
94
+ "@xyo-network/module-abstract": "^5.5.5",
95
+ "@xyo-network/module-model": "^5.5.5",
96
+ "@xyo-network/network": "~5.5.1",
97
+ "@xyo-network/node-memory": "~5.5.5",
98
+ "@xyo-network/node-model": "^5.5.5",
99
+ "@xyo-network/payload-builder": "^5.5.1",
100
+ "@xyo-network/payload-model": "^5.5.1",
101
+ "@xyo-network/payload-wrapper": "~5.5.1",
102
+ "@xyo-network/payloadset-plugin": "^5.5.5",
103
+ "@xyo-network/query-payload-plugin": "~5.5.1",
104
+ "@xyo-network/sentinel-memory": "^5.5.5",
105
+ "@xyo-network/sentinel-model": "^5.5.5",
106
+ "@xyo-network/wallet": "~5.5.1",
107
+ "@xyo-network/wallet-model": "^5.5.1",
108
+ "@xyo-network/witness-model": "^5.5.5",
109
+ "async-mutex": "^0.5.0",
110
+ "axios": "^1.15.2",
111
+ "bn.js": "^5.2.3",
112
+ "bowser": "^2.14.1",
113
+ "buffer": "^6.0.3",
114
+ "chalk": "^5.6.2",
115
+ "debug": "~4.4.3",
116
+ "esbuild": "~0.28.0",
117
+ "eslint": "^10.2.1",
118
+ "ethers": "^6.16.0",
119
+ "fast-deep-equal": "~3.1.3",
120
+ "hash-wasm": "~4.12.0",
121
+ "js-cookie": "~3.0.5",
122
+ "lru-cache": "^11.3.5",
123
+ "observable-fns": "~0.6.1",
124
+ "pako": "^2.1.0",
125
+ "react": "^19.2.5",
126
+ "react-dom": "^19.2.5",
127
+ "react-router-dom": "^7.14.2",
128
+ "spark-md5": "~3.0.2",
129
+ "store2": "~2.14.4",
82
130
  "typescript": "^5.9.3",
131
+ "wasm-feature-detect": "~1.8.0",
83
132
  "zod": "^4.3.6"
84
133
  },
85
134
  "peerDependencies": {
86
- "@mui/icons-material": ">=6 <8",
87
- "@mui/material": ">=6 <8",
88
- "axios": "~1",
89
- "ethers": "~6",
90
- "react": "^19",
91
- "react-dom": "^19",
92
- "react-router-dom": "^7",
93
- "zod": "^4"
135
+ "@emotion/react": "^11.14.0",
136
+ "@mui/icons-material": "^7.3.10",
137
+ "@mui/material": "^7.3.10",
138
+ "@mui/system": "^7.3.10",
139
+ "@mui/x-tree-view": "~8.27.2",
140
+ "@opentelemetry/api": "^1.9.1",
141
+ "@opentelemetry/sdk-trace-base": "^2.7.0",
142
+ "@scure/base": "~2.2.0",
143
+ "@scure/bip39": "~2.2.0",
144
+ "@xylabs/react-async-effect": "~7.1.20",
145
+ "@xylabs/react-button": "~7.1.20",
146
+ "@xylabs/react-crypto": "~7.1.20",
147
+ "@xylabs/react-flexbox": "~7.1.20",
148
+ "@xylabs/react-hooks": "~7.1.20",
149
+ "@xylabs/react-identicon": "~7.1.20",
150
+ "@xylabs/react-link": "~7.1.20",
151
+ "@xylabs/react-number-status": "~7.1.20",
152
+ "@xylabs/react-promise": "~7.1.20",
153
+ "@xylabs/react-quick-tip-button": "~7.1.20",
154
+ "@xylabs/react-select": "~7.1.20",
155
+ "@xylabs/react-shared": "~7.1.20",
156
+ "@xylabs/react-theme": "~7.1.20",
157
+ "@xylabs/sdk-js": "^5.0.100",
158
+ "@xylabs/tsconfig": "^7.11.9",
159
+ "@xylabs/tsconfig-dom": "^7.11.9",
160
+ "@xylabs/zod": "~5.0.100",
161
+ "@xyo-network/account": "~5.5.1",
162
+ "@xyo-network/account-model": "^5.5.1",
163
+ "@xyo-network/archivist-memory": "~5.5.5",
164
+ "@xyo-network/archivist-model": "^5.5.5",
165
+ "@xyo-network/archivist-storage": "~5.5.5",
166
+ "@xyo-network/boundwitness-builder": "^5.5.1",
167
+ "@xyo-network/boundwitness-model": "^5.5.1",
168
+ "@xyo-network/boundwitness-validator": "^5.5.1",
169
+ "@xyo-network/boundwitness-wrapper": "~5.5.1",
170
+ "@xyo-network/bridge-http": "~5.5.5",
171
+ "@xyo-network/config-payload-plugin": "~5.5.1",
172
+ "@xyo-network/manifest-model": "~5.5.1",
173
+ "@xyo-network/module-abstract": "^5.5.5",
174
+ "@xyo-network/module-model": "^5.5.5",
175
+ "@xyo-network/network": "~5.5.1",
176
+ "@xyo-network/node-memory": "~5.5.5",
177
+ "@xyo-network/node-model": "^5.5.5",
178
+ "@xyo-network/payload-builder": "^5.5.1",
179
+ "@xyo-network/payload-model": "^5.5.1",
180
+ "@xyo-network/payload-wrapper": "~5.5.1",
181
+ "@xyo-network/payloadset-plugin": "^5.5.5",
182
+ "@xyo-network/query-payload-plugin": "~5.5.1",
183
+ "@xyo-network/sentinel-memory": "^5.5.5",
184
+ "@xyo-network/sentinel-model": "^5.5.5",
185
+ "@xyo-network/wallet": "~5.5.1",
186
+ "@xyo-network/wallet-model": "^5.5.1",
187
+ "@xyo-network/witness-model": "^5.5.5",
188
+ "async-mutex": "^0.5.0",
189
+ "axios": "^1.15.2",
190
+ "bn.js": "^5.2.3",
191
+ "bowser": "^2.14.1",
192
+ "buffer": "^6.0.3",
193
+ "chalk": "^5.6.2",
194
+ "ethers": "^6.16.0",
195
+ "fast-deep-equal": "~3.1.3",
196
+ "js-cookie": "~3.0.5",
197
+ "lru-cache": "^11.3.5",
198
+ "pako": "^2.1.0",
199
+ "react": "^19.2.5",
200
+ "react-dom": "^19.2.5",
201
+ "react-router-dom": "^7.14.2",
202
+ "spark-md5": "~3.0.2",
203
+ "store2": "~2.14.4",
204
+ "zod": "^4.3.6"
94
205
  },
95
206
  "publishConfig": {
96
207
  "access": "public"
97
208
  },
98
209
  "docs": "dist/docs.json"
99
- }
210
+ }
@@ -1,49 +0,0 @@
1
- import { useAsyncEffect } from '@xylabs/react-async-effect'
2
- import { useNetwork } from '@xyo-network/react-network'
3
- import { useWeakNodeFromNode } from '@xyo-network/react-node'
4
- import type { PropsWithChildren } from 'react'
5
- import React, { useState } from 'react'
6
-
7
- import { useStandardNodes } from '../contexts/index.ts'
8
- import { useActiveNodeAddress } from '../hooks/index.ts'
9
-
10
- export interface ActiveStandardNodeProps extends PropsWithChildren {
11
- nodeNameOrAddress?: string
12
- }
13
-
14
- export const ActiveStandardNode: React.FC<ActiveStandardNodeProps> = ({ children, nodeNameOrAddress }) => {
15
- const { network } = useNetwork()
16
- const [node] = useWeakNodeFromNode(nodeNameOrAddress)
17
- const [activeRemoteNodeAddress, setActiveRemoteNodeAddress] = useState<string>()
18
- const { nodes } = useStandardNodes()
19
-
20
- const selectedNodeAddress = useActiveNodeAddress(network?.name)
21
-
22
- // Probably needs to rely on node events rather than provider values to ensure its registered
23
- useAsyncEffect(
24
- async (mounted) => {
25
- const nodeInstance = node?.deref()
26
- if (nodeInstance && selectedNodeAddress) {
27
- try {
28
- if ((await nodeInstance?.attached())?.includes(selectedNodeAddress)) {
29
- return
30
- }
31
- await nodeInstance?.attach(selectedNodeAddress, true)
32
-
33
- if (mounted()) {
34
- // cleanup
35
- if (activeRemoteNodeAddress) {
36
- await nodeInstance?.detach(activeRemoteNodeAddress)
37
- }
38
- setActiveRemoteNodeAddress(selectedNodeAddress)
39
- }
40
- } catch (e) {
41
- console.error('Error Attaching Selected Node Address', e)
42
- }
43
- }
44
- },
45
- [activeRemoteNodeAddress, node, selectedNodeAddress, nodes],
46
- )
47
-
48
- return <>{children}</>
49
- }
@@ -1 +0,0 @@
1
- export * from './ActiveStandardNode.tsx'
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { StandardNodesState } from './State.ts'
4
-
5
- export const StandardNodesContext = createContextEx<StandardNodesState>()
@@ -1,61 +0,0 @@
1
- import { useResetState } from '@xylabs/react-hooks'
2
- import { usePromise } from '@xylabs/react-promise'
3
- import { assertDefinedEx } from '@xylabs/sdk-js'
4
- import type { MemoryNode } from '@xyo-network/node-memory'
5
- import { useWalletContext } from '@xyo-network/react-wallet'
6
- import type { WalletInstance } from '@xyo-network/wallet-model'
7
- import type { PropsWithChildren } from 'react'
8
- import React, { useMemo } from 'react'
9
-
10
- import { BuildStandardNodes } from '../../lib/index.ts'
11
- import { StandardNodesContext } from './Context.ts'
12
- import type { StandardNodesState } from './State.ts'
13
-
14
- export type StandardNodesProviderProps = PropsWithChildren<{
15
- defaultRemoteNodes?: StandardNodesState['nodes']
16
- wallet?: WalletInstance | null
17
- }>
18
-
19
- export const StandardNodesProvider: React.FC<StandardNodesProviderProps> = ({
20
- children, defaultRemoteNodes, wallet,
21
- }) => {
22
- const [nodes, setNodes] = useResetState<StandardNodesState['nodes']>(defaultRemoteNodes)
23
-
24
- usePromise(async () => {
25
- if (wallet) {
26
- await BuildStandardNodes(wallet, (node: MemoryNode) => {
27
- setNodes((nodes) => {
28
- if (nodes?.find(existingNode => existingNode.config.name === node.config.name)) {
29
- return
30
- }
31
- return nodes ? [...nodes, node] : [node]
32
- })
33
- })
34
- }
35
- }, [wallet])
36
-
37
- const findAddressByName = (name?: string) => {
38
- const validNetworkName = assertDefinedEx(name, () => 'name was not defined')
39
- return nodes?.find(node => node.config.name === validNetworkName)?.address
40
- }
41
-
42
- const value: StandardNodesState = useMemo(() => ({
43
- findAddressByName,
44
- nodes,
45
- provided: true,
46
- }), [findAddressByName,
47
- nodes])
48
-
49
- return (
50
- <StandardNodesContext
51
- value={value}
52
- >
53
- {children}
54
- </StandardNodesContext>
55
- )
56
- }
57
-
58
- export const StandardNodesProviderWithWallet: React.FC<Omit<StandardNodesProviderProps, 'wallet'>> = (props) => {
59
- const { activeAccount } = useWalletContext()
60
- return <StandardNodesProvider wallet={activeAccount} {...props} />
61
- }
@@ -1,8 +0,0 @@
1
- import type { ContextExState } from '@xylabs/react-shared'
2
- import type { Address } from '@xylabs/sdk-js'
3
- import type { MemoryNode } from '@xyo-network/node-memory'
4
-
5
- export type StandardNodesState = ContextExState<{
6
- findAddressByName?: (name?: string) => Address | undefined
7
- nodes?: MemoryNode[]
8
- }>
@@ -1,4 +0,0 @@
1
- export * from './Context.ts'
2
- export * from './Providers.tsx'
3
- export * from './State.ts'
4
- export * from './use.ts'
@@ -1,5 +0,0 @@
1
- import { useContextEx } from '@xylabs/react-shared'
2
-
3
- import { StandardNodesContext } from './Context.ts'
4
-
5
- export const useStandardNodes = (required = false) => useContextEx(StandardNodesContext, 'StandardNodes', required)
@@ -1 +0,0 @@
1
- export * from './StandardRemoteNodes/index.ts'
@@ -1 +0,0 @@
1
- export * from './useActiveNodeAddress.ts'
@@ -1,17 +0,0 @@
1
- import { useProvidedNode } from '@xyo-network/react-node'
2
- import { useMemo } from 'react'
3
-
4
- import { useStandardNodes } from '../contexts/index.ts'
5
-
6
- export const useActiveNodeAddress = (networkName?: string) => {
7
- const [node] = useProvidedNode()
8
- const { nodes, findAddressByName } = useStandardNodes()
9
-
10
- const activeNodeAddress = useMemo(() => {
11
- if (node && nodes && findAddressByName && networkName) {
12
- return findAddressByName(networkName)
13
- }
14
- }, [findAddressByName, networkName, node, nodes])
15
-
16
- return activeNodeAddress
17
- }
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './components/index.ts'
2
- export * from './contexts/index.ts'
3
- export * from './hooks/index.ts'
4
- export * from './lib/index.ts'
@@ -1,120 +0,0 @@
1
- import { assertDefinedEx } from '@xylabs/sdk-js'
2
- import type { AccountInstance } from '@xyo-network/account-model'
3
- import type { MemoryArchivistConfig } from '@xyo-network/archivist-memory'
4
- import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'
5
- import { HttpBridge, HttpBridgeConfigSchema } from '@xyo-network/bridge-http'
6
- import type { AttachableModuleInstance } from '@xyo-network/module-model'
7
- import { MemoryNode } from '@xyo-network/node-memory'
8
- import { NodeConfigSchema } from '@xyo-network/node-model'
9
- import type { PayloadSetPluginResolver } from '@xyo-network/payloadset-plugin'
10
- import type { SentinelConfig } from '@xyo-network/sentinel-model'
11
- import type { AttachableWitnessInstance, WitnessModule } from '@xyo-network/witness-model'
12
-
13
- import { SentinelBuilder } from './SentinelBuilder.ts'
14
- import { StorageArchivistBuilder } from './StorageArchivistBuilder.ts'
15
-
16
- export interface MemoryNodeBuilderConfig {
17
- name?: string
18
- node?: MemoryNode
19
- }
20
-
21
- export class MemoryNodeBuilder {
22
- private _node: MemoryNode | undefined
23
-
24
- get node() {
25
- return assertDefinedEx(this._node, () => 'this._node was not defined upon create')
26
- }
27
-
28
- static async create({ name, node }: MemoryNodeBuilderConfig, account?: AccountInstance): Promise<MemoryNodeBuilder> {
29
- const instance = new this()
30
-
31
- const memoryNode: MemoryNode = node ?? (await MemoryNode.create({
32
- account,
33
- config: { name, schema: NodeConfigSchema },
34
- }))
35
- instance._node = memoryNode
36
- return instance
37
- }
38
-
39
- /** @deprecated - call specific method that corresponds to a type of archivist (i.e. addArchivistStorage) */
40
- async addArchivist(account: AccountInstance, moduleName?: string, namespace?: string) {
41
- await this.addArchivistStorage(account, moduleName, namespace)
42
- }
43
-
44
- async addArchivistMemory(moduleName?: string, account?: AccountInstance) {
45
- const config: MemoryArchivistConfig = { name: moduleName, schema: MemoryArchivistConfigSchema }
46
- const memoryArchivist = await MemoryArchivist.create({ account, config })
47
-
48
- await this.attach(memoryArchivist, true)
49
- }
50
-
51
- async addArchivistStorage(account: AccountInstance, moduleName?: string, namespace?: string) {
52
- const config = { name: moduleName, namespace }
53
- const { archivist } = await StorageArchivistBuilder.create(config, account, this.node)
54
-
55
- await this.attach(archivist, true)
56
- }
57
-
58
- async addBridge(apiDomain: string, moduleName = 'RemoteNodeBridge', account?: AccountInstance) {
59
- try {
60
- const bridge = await HttpBridge.create({
61
- account,
62
- config: {
63
- name: moduleName, client: { url: `${apiDomain}/node` }, schema: HttpBridgeConfigSchema, security: { allowAnonymous: true },
64
- },
65
- })
66
- await this.attach(bridge, true)
67
- } catch (e) {
68
- console.error('Error Creating Bridge', e)
69
- }
70
- }
71
-
72
- async addSentinel(config: SentinelConfig, account: AccountInstance) {
73
- const { sentinel } = await SentinelBuilder.create(config, account)
74
- await this.attach(sentinel, true, true)
75
- return sentinel
76
- }
77
-
78
- async addWitnesses(pluginSetResolver: PayloadSetPluginResolver, witnesses: (() => Promise<AttachableWitnessInstance>)[] = []) {
79
- await Promise.all(
80
- pluginSetResolver.witnesses().map(async (pluginSet, index) => {
81
- // Pass the prebuilt witness at the same index
82
- const witness = await witnesses?.[index]?.()
83
- if (witness) {
84
- try {
85
- await this.witnessCleanup(witness)
86
- await this.node.register(witness)
87
- await this.node.attach(witness.address, true)
88
- } catch (e) {
89
- console.error('Error attaching witness', JSON.stringify(pluginSet, null, 2), e)
90
- }
91
- }
92
- }),
93
- )
94
- }
95
-
96
- async attach(mod: AttachableModuleInstance, external?: boolean, safeAttach?: boolean) {
97
- try {
98
- if (safeAttach) {
99
- const existingModule = (await this.node.resolve(mod.address))
100
- if (existingModule) {
101
- await this.node.detach(existingModule.address)
102
- await this.node.unregister(existingModule)
103
- }
104
- }
105
- await this.node.register(mod)
106
- await this.node.attach(mod.address, external)
107
- } catch (e) {
108
- throw new Error(`Error adding ${mod.config.name ?? mod.address} to MemoryNode: ${e}`)
109
- }
110
- }
111
-
112
- private async witnessCleanup(witness: WitnessModule) {
113
- if ((await this.node.registered()).includes(witness.address)) {
114
- const existingWitness = await this.node.resolve(witness.address)
115
- if (existingWitness) {
116
- await this.node.unregister(existingWitness)
117
- }
118
- }
119
- }
120
- }
@@ -1,43 +0,0 @@
1
- import { assertDefinedEx } from '@xylabs/sdk-js'
2
- import type { AccountInstance } from '@xyo-network/account-model'
3
- import type { MemorySentinelParams } from '@xyo-network/sentinel-memory'
4
- import { MemorySentinel } from '@xyo-network/sentinel-memory'
5
- import type { SentinelConfig } from '@xyo-network/sentinel-model'
6
-
7
- export class SentinelBuilder {
8
- private _sentinel: MemorySentinel | undefined
9
-
10
- private account: AccountInstance
11
- private config: SentinelConfig
12
-
13
- protected constructor(
14
- config: SentinelConfig,
15
- account: AccountInstance,
16
- ) {
17
- assertDefinedEx(config, () => 'config was not defined')
18
- this.config = config
19
- this.account = account
20
- }
21
-
22
- get sentinel() {
23
- return assertDefinedEx(this._sentinel, () => 'this._sentinel not defined upon create')
24
- }
25
-
26
- static async create(config: SentinelConfig, account: AccountInstance): Promise<SentinelBuilder> {
27
- const instance = new this(config, account)
28
- instance._sentinel = await instance.buildSentinel()
29
- return instance
30
- }
31
-
32
- async buildSentinel() {
33
- const params = this.buildParams()
34
- return (await MemorySentinel.create(params)) as MemorySentinel
35
- }
36
-
37
- private buildParams(): MemorySentinelParams {
38
- return {
39
- account: this.account,
40
- config: this.config,
41
- }
42
- }
43
- }
@@ -1,73 +0,0 @@
1
- import { assertDefinedEx } from '@xylabs/sdk-js'
2
- import type { AccountInstance } from '@xyo-network/account-model'
3
- import type { ArchivistModuleInstance } from '@xyo-network/archivist-model'
4
- import { asArchivistInstance } from '@xyo-network/archivist-model'
5
- import type { StorageArchivistConfig } from '@xyo-network/archivist-storage'
6
- import { StorageArchivist, StorageArchivistConfigSchema } from '@xyo-network/archivist-storage'
7
- import type { MemoryNode } from '@xyo-network/node-memory'
8
- import { asNodeInstance } from '@xyo-network/node-model'
9
-
10
- export interface ArchivistBuilderConfig {
11
- name?: string
12
- namespace?: string
13
- }
14
- export class StorageArchivistBuilder {
15
- private _archivist: StorageArchivist | undefined
16
- private account: AccountInstance
17
- private config: ArchivistBuilderConfig
18
- private node?: MemoryNode
19
- private remoteArchivist: ArchivistModuleInstance | undefined
20
-
21
- protected constructor(
22
- config: ArchivistBuilderConfig,
23
- account: AccountInstance,
24
- node?: MemoryNode,
25
- ) {
26
- this.config = config
27
- this.account = account
28
- this.node = node
29
- }
30
-
31
- get archivist() {
32
- return assertDefinedEx(this._archivist, () => 'archivist was not defined upon create')
33
- }
34
-
35
- static async create(config: ArchivistBuilderConfig, account: AccountInstance, node: MemoryNode): Promise<StorageArchivistBuilder> {
36
- const instance = new this(config, account, node)
37
- instance.remoteArchivist = await instance.findParentArchivist()
38
- instance._archivist = await instance.buildArchivist()
39
- return instance
40
- }
41
-
42
- async buildArchivist() {
43
- const config = this.buildConfig()
44
- return (await StorageArchivist.create({ account: this.account, config })) as StorageArchivist
45
- }
46
-
47
- buildConfig(): StorageArchivistConfig {
48
- return {
49
- name: this.config.name,
50
- namespace: this.config.namespace,
51
- parents: {
52
- commit: this.remoteArchivist ? [this.remoteArchivist?.address] : undefined,
53
- read: this.remoteArchivist ? [this.remoteArchivist?.address] : undefined,
54
- },
55
- schema: StorageArchivistConfigSchema,
56
- storeParentReads: true,
57
- type: 'local',
58
- }
59
- }
60
-
61
- async findParentArchivist() {
62
- const node = asNodeInstance(this.node, 'node not defined', { required: true })
63
- const bridge = (await node.resolve('RemoteNodeBridge'))
64
- if (bridge) {
65
- try {
66
- const archivist = (await bridge.resolve('Archivist'))
67
- return asArchivistInstance(archivist)
68
- } catch {
69
- console.error('Error Resolving Parent Archivist', this.node?.config.name, this.config)
70
- }
71
- }
72
- }
73
- }
@@ -1,3 +0,0 @@
1
- export * from './MemoryNodeBuilder.ts'
2
- export * from './SentinelBuilder.ts'
3
- export * from './StorageArchivistBuilder.ts'