@xyo-network/module-model 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.
Files changed (88) hide show
  1. package/dist/neutral/Payload/Address.d.ts +1 -1
  2. package/dist/neutral/Payload/Address.d.ts.map +1 -1
  3. package/dist/neutral/Payload/ModuleState.d.ts +1 -1
  4. package/dist/neutral/Payload/ModuleState.d.ts.map +1 -1
  5. package/package.json +17 -17
  6. package/src/Config/Archiving.ts +0 -10
  7. package/src/Config/Config.ts +0 -29
  8. package/src/Config/Fields.ts +0 -47
  9. package/src/Config/Reentrancy.ts +0 -6
  10. package/src/Config/Security.ts +0 -15
  11. package/src/Config/index.ts +0 -5
  12. package/src/CreatableModule/CreatableModule.ts +0 -42
  13. package/src/CreatableModule/CreatableModuleRegistry.ts +0 -102
  14. package/src/CreatableModule/LabeledCreatableModule.ts +0 -20
  15. package/src/CreatableModule/LabeledCreatableModuleFactory.ts +0 -21
  16. package/src/CreatableModule/ModuleFactory.ts +0 -60
  17. package/src/CreatableModule/index.ts +0 -5
  18. package/src/DetailsError.ts +0 -13
  19. package/src/EventsModels/ModuleBusy.ts +0 -14
  20. package/src/EventsModels/ModuleError.ts +0 -14
  21. package/src/EventsModels/ModuleEventArgs.ts +0 -9
  22. package/src/EventsModels/ModuleEventData.ts +0 -8
  23. package/src/EventsModels/ModuleQueried.ts +0 -19
  24. package/src/EventsModels/index.ts +0 -5
  25. package/src/Labels/Labels.ts +0 -33
  26. package/src/Labels/index.ts +0 -2
  27. package/src/Labels/standard/View.ts +0 -4
  28. package/src/Labels/standard/index.ts +0 -1
  29. package/src/ModuleDescription.ts +0 -9
  30. package/src/ModuleFactoryLocatorInstance.ts +0 -47
  31. package/src/ModuleIdentifier.ts +0 -69
  32. package/src/ModuleIdentifierTransformer.ts +0 -9
  33. package/src/ModuleQueryHandlerResult.ts +0 -3
  34. package/src/ModuleQueryResult.ts +0 -8
  35. package/src/ModuleStatusReporter.ts +0 -3
  36. package/src/Payload/Address.ts +0 -37
  37. package/src/Payload/AddressPreviousHash.ts +0 -13
  38. package/src/Payload/Description.ts +0 -8
  39. package/src/Payload/ModuleState.ts +0 -29
  40. package/src/Payload/index.ts +0 -4
  41. package/src/Queries/Manifest.ts +0 -9
  42. package/src/Queries/ModuleAddress/Query.ts +0 -8
  43. package/src/Queries/ModuleAddress/index.ts +0 -1
  44. package/src/Queries/State.ts +0 -6
  45. package/src/Queries/Subscribe.ts +0 -21
  46. package/src/Queries/index.ts +0 -11
  47. package/src/QueryableModule/IsQueryableModuleFactory.ts +0 -34
  48. package/src/QueryableModule/QueryableModule.ts +0 -14
  49. package/src/QueryableModule/QueryableModuleFields.ts +0 -37
  50. package/src/QueryableModule/QueryableModuleFunctions.ts +0 -18
  51. package/src/QueryableModule/QueryableModuleParams.ts +0 -20
  52. package/src/QueryableModule/asQueryableModule.ts +0 -8
  53. package/src/QueryableModule/asQueryableModuleObject.ts +0 -8
  54. package/src/QueryableModule/index.ts +0 -9
  55. package/src/QueryableModule/isQueryableModule.ts +0 -20
  56. package/src/QueryableModule/isQueryableModuleObject.ts +0 -20
  57. package/src/ResolveHelper/ResolveHelper.ts +0 -213
  58. package/src/ResolveHelper/ResolveHelperStatic.ts +0 -9
  59. package/src/ResolveHelper/index.ts +0 -9
  60. package/src/ResolveHelper/model.ts +0 -1
  61. package/src/ResolveHelper/resolveAddressToInstance.ts +0 -94
  62. package/src/ResolveHelper/resolveAll.ts +0 -53
  63. package/src/ResolveHelper/resolveLocalNameToAddress.ts +0 -40
  64. package/src/ResolveHelper/resolveLocalNameToInstance.ts +0 -47
  65. package/src/ResolveHelper/resolvePathToAddress.ts +0 -15
  66. package/src/ResolveHelper/resolvePathToInstance.ts +0 -36
  67. package/src/ResolveHelper/traceModuleIdentifier.ts +0 -19
  68. package/src/ResolveHelper/transformModuleIdentifier.ts +0 -13
  69. package/src/cache.ts +0 -5
  70. package/src/index.ts +0 -20
  71. package/src/instance/Instance.ts +0 -68
  72. package/src/instance/ModuleFilter.ts +0 -33
  73. package/src/instance/ModuleInstanceParams.ts +0 -11
  74. package/src/instance/ModuleRepository.ts +0 -12
  75. package/src/instance/ModuleResolver.ts +0 -21
  76. package/src/instance/ObjectFilter.ts +0 -48
  77. package/src/instance/ObjectResolver.ts +0 -40
  78. package/src/instance/asModuleInstance.ts +0 -5
  79. package/src/instance/attachable/AttachableInstance.ts +0 -25
  80. package/src/instance/attachable/asAttachableInstance.ts +0 -5
  81. package/src/instance/attachable/index.ts +0 -3
  82. package/src/instance/attachable/isAttachableInstance.ts +0 -17
  83. package/src/instance/index.ts +0 -10
  84. package/src/instance/isModuleInstance.ts +0 -15
  85. package/src/lib/duplicateModules.ts +0 -14
  86. package/src/lib/index.ts +0 -2
  87. package/src/lib/serializable.ts +0 -30
  88. package/src/withModule.ts +0 -15
@@ -1,213 +0,0 @@
1
- /* eslint-disable max-statements */
2
- /* eslint-disable complexity */
3
- import type { Address, Logger } from '@xylabs/sdk-js'
4
- import {
5
- assertEx,
6
- exists,
7
- IdLogger,
8
- isAddress,
9
- isDefined, isString, isTruthy,
10
- } from '@xylabs/sdk-js'
11
-
12
- import type {
13
- ModuleFilterOptions, ModuleInstance, ModuleResolver,
14
- } from '../instance/index.ts'
15
- import { asModuleInstance } from '../instance/index.ts'
16
- import { duplicateModules } from '../lib/index.ts'
17
- import type { ModuleIdentifier } from '../ModuleIdentifier.ts'
18
- import type { ModuleIdentifierTransformer } from '../ModuleIdentifierTransformer.ts'
19
- import { ResolveHelperStatic } from './ResolveHelperStatic.ts'
20
- import { resolvePathToAddress } from './resolvePathToAddress.ts'
21
- import { traceModuleIdentifier } from './traceModuleIdentifier.ts'
22
- import { transformModuleIdentifier } from './transformModuleIdentifier.ts'
23
-
24
- /*
25
-
26
- Resolution rules
27
-
28
- 1. Resolution is always done from the perspective of the module whose resolve function was called.
29
-
30
- 2. Requesting '*' will return all the modules that the resolver can see. [limited by maxDepth]
31
-
32
- 3. Requesting a simple ModuleName (string w/o ':' separator) will return an immediate child that has that name.
33
-
34
- 4. Requesting a complex ModuleName (string w/ ':' separator) will resolve the first part and then recursively resolve
35
- the remaining name by calling the first part's resolved module's resolve with the remainder of the name.
36
-
37
- 5. Requesting an Address (string) will return the module with that address, regardless of how distant it is from the module. [limited by maxDepth]
38
-
39
- 6. Requesting a ModuleFilter will first request all the modules '*' and then filter them based on the filter settings. [Do we need this mode?]
40
-
41
- 7. When a string is passed as the ModuleIdentifier, do the following:
42
- Check if id is complex (contains a ':')
43
- a) If it is complex, go to #4 above
44
- b) Call isAddress in the id to see if it is a valid address.
45
- i) If it is a valid address, go to #5 above
46
- ii) If it is not a valid address, go to # 3 above
47
-
48
- 1: If someone were to name a module with a valid address, that name will not be resolvable.
49
- 2: If someone were to name a module with a string containing a ':', that name will not be resolvable.
50
-
51
- 8. Modules have two resolvers, up and down.
52
- a) Up Traversal
53
- i) Every module's upResolver also can call it's parent's upResolver
54
- ii) An upResolver also can see the parent's children's downResolvers
55
- iii) This means that when traversing upResolvers, you can traverse all the way up. [limited by maxDepth]
56
- iv) At any point of the up traversal, it can start traversing down to any immediate child, public or private.
57
- b) Down Traversal
58
- i) A down traversal is limited to the public children of the module. [The same as scope as calling the 'resolve' function]
59
-
60
- 9. An up or a down traversal counts against the maxDepth
61
-
62
- */
63
-
64
- export interface ResolveHelperConfig {
65
- address: Address
66
- dead?: boolean
67
- downResolver?: ModuleResolver
68
- logger?: Logger
69
- mod: ModuleInstance
70
- privateResolver?: ModuleResolver
71
- transformers: ModuleIdentifierTransformer[]
72
- upResolver?: ModuleResolver
73
- }
74
-
75
- export class ResolveHelper extends ResolveHelperStatic {
76
- static async resolve<T extends ModuleInstance = ModuleInstance>(
77
- config: ResolveHelperConfig,
78
- all: '*',
79
- options?: ModuleFilterOptions<T>,
80
- ): Promise<T[]>
81
- static async resolve<T extends ModuleInstance = ModuleInstance>(
82
- config: ResolveHelperConfig,
83
- id: ModuleIdentifier,
84
- options?: ModuleFilterOptions<T>,
85
- ): Promise<T | undefined>
86
- static async resolve<T extends ModuleInstance = ModuleInstance>(
87
- config: ResolveHelperConfig,
88
- id: ModuleIdentifier = '*',
89
- {
90
- maxDepth = 3, required = 'log', ...options
91
- }: ModuleFilterOptions<T> = {},
92
- ): Promise<T | T[] | undefined> {
93
- const {
94
- transformers, mod, logger = this.defaultLogger, dead = false, upResolver, downResolver, privateResolver,
95
- } = config
96
- const log = logger ? new IdLogger(logger, () => `ResolveHelper [${mod.id}][${id}]`) : undefined
97
-
98
- const downLocalOptions: ModuleFilterOptions<T> = {
99
- ...options, direction: 'down', maxDepth, required: false,
100
- }
101
- const upLocalOptions: ModuleFilterOptions<T> = { ...downLocalOptions, direction: 'up' }
102
-
103
- const childOptions: ModuleFilterOptions<T> = {
104
- ...options, maxDepth: maxDepth - 1, required: false,
105
- }
106
-
107
- const direction = options?.direction ?? 'all'
108
- const up = direction === 'up' || direction === 'all'
109
- const down = direction === 'down' || direction === 'all'
110
- let result: T | T[] | undefined
111
- log?.debug('start', id, maxDepth)
112
- if (id === '*') {
113
- if (dead) {
114
- log?.warn('failed [dead]', id)
115
- return []
116
- }
117
- const modules = [
118
- ...(down ? await (downResolver as ModuleResolver).resolve<T>('*', downLocalOptions) : []),
119
- ...(up ? await (upResolver as ModuleResolver).resolve<T>('*', upLocalOptions) : []),
120
- ].filter(duplicateModules)
121
-
122
- if (modules.length > 0) {
123
- log?.debug('modules [count]', modules.length)
124
- }
125
-
126
- if (maxDepth === 0) {
127
- return modules
128
- }
129
- const childModules = (await Promise.all(modules.map(async mod => await mod.resolve<T>('*', childOptions)))).flat().filter(duplicateModules)
130
- return [...modules, ...childModules, mod as T].filter(duplicateModules)
131
- } else {
132
- switch (typeof id) {
133
- case 'string': {
134
- if (dead) {
135
- return undefined
136
- }
137
-
138
- const resolvedId = assertEx((await resolvePathToAddress(mod, id, false, transformers)) ?? id, () => 'Invalid resolvedId')
139
-
140
- const resolvers = [
141
- [downResolver, downLocalOptions],
142
- [up ? upResolver : undefined, upLocalOptions],
143
- [up ? privateResolver : undefined, upLocalOptions],
144
- ].filter(([resolver]) => exists(resolver)) as [ModuleResolver, ModuleFilterOptions<T>][]
145
-
146
- for (const resolver of resolvers) {
147
- const [resolverInstance] = resolver
148
- if (!result) {
149
- result = await this.resolveModuleIdentifier<T>(resolverInstance, resolvedId)
150
- }
151
- }
152
-
153
- break
154
- }
155
- default: {
156
- break
157
- }
158
- }
159
- }
160
- this.validateRequiredResolve(required, result, id, logger)
161
- return result
162
- }
163
-
164
- // resolves a complex module path to addresses
165
- static async resolveModuleIdentifier<T extends ModuleInstance = ModuleInstance>(
166
- resolver: ModuleResolver,
167
- path: ModuleIdentifier,
168
- required?: boolean,
169
- ): Promise<T | undefined> {
170
- const parts = path.split(':')
171
- const first = parts.shift()
172
- const firstIsAddress = isAddress(first)
173
- const resolvedModule
174
- = (await resolver.resolve(first, { maxDepth: firstIsAddress ? 10 : 1 }))
175
- ?? (isString(first) ? await resolver.resolvePrivate(first, { maxDepth: firstIsAddress ? 10 : 1 }) : undefined)
176
- const finalModule = required ? assertEx(resolvedModule, () => `Failed to resolve [${first}] [${firstIsAddress}]`) : resolvedModule
177
- const firstModule = asModuleInstance(finalModule, () => `Resolved invalid module instance [${first}]`)
178
- return isDefined(firstModule) ? (parts.length > 0 ? await this.resolveModuleIdentifier<T>(firstModule, parts.join(':')) : firstModule as T) : undefined
179
- }
180
-
181
- // translates a complex module path to addresses
182
- static traceModuleIdentifier(resolver: ModuleResolver, path: ModuleIdentifier) {
183
- return traceModuleIdentifier(resolver, path)
184
- }
185
-
186
- static transformModuleIdentifier(identifier: ModuleIdentifier, transformers: ModuleIdentifierTransformer[] = ResolveHelper.transformers) {
187
- return transformModuleIdentifier(identifier, transformers)
188
- }
189
-
190
- static validateRequiredResolve(
191
- required: boolean | 'warn' | 'log',
192
- result: ModuleInstance[] | ModuleInstance | undefined,
193
- id: ModuleIdentifier,
194
- logger = this.defaultLogger,
195
- ) {
196
- const log = logger ? new IdLogger(logger, () => `validateRequiredResolve [${id}][${result}]`) : undefined
197
- if (isTruthy(required) && (result === undefined || (Array.isArray(result) && result.length > 0))) {
198
- switch (required) {
199
- case 'warn': {
200
- log?.warn('resolve failed', id)
201
- break
202
- }
203
- case 'log': {
204
- log?.log('resolve failed', id)
205
- break
206
- }
207
- default: {
208
- throw new Error(`resolve failed [${id}]`)
209
- }
210
- }
211
- }
212
- }
213
- }
@@ -1,9 +0,0 @@
1
- import type { Logger } from '@xylabs/sdk-js'
2
-
3
- import type { ModuleIdentifierTransformer } from '../ModuleIdentifierTransformer.ts'
4
-
5
- export class ResolveHelperStatic {
6
- static readonly defaultLogger?: Logger
7
- // eslint-disable-next-line sonarjs/public-static-readonly
8
- static transformers: ModuleIdentifierTransformer[] = []
9
- }
@@ -1,9 +0,0 @@
1
- export * from './model.ts'
2
- export * from './resolveAddressToInstance.ts'
3
- export * from './resolveAll.ts'
4
- export * from './ResolveHelper.ts'
5
- export * from './resolveLocalNameToAddress.ts'
6
- export * from './resolveLocalNameToInstance.ts'
7
- export * from './resolvePathToAddress.ts'
8
- export * from './resolvePathToInstance.ts'
9
- export * from './transformModuleIdentifier.ts'
@@ -1 +0,0 @@
1
- export type ModuleResolveDirection = 'all' | 'up' | 'down'
@@ -1,94 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
-
3
- import type { ModuleInstance } from '../instance/index.ts'
4
- import type { ModuleResolveDirection } from './model.ts'
5
-
6
- export const resolveAddressToInstanceDown = async (
7
- root: ModuleInstance,
8
- address: Address,
9
- includePrivate: boolean | undefined = undefined,
10
- ignore: Address[] = [],
11
- ): Promise<ModuleInstance | undefined> => {
12
- if (root.address === address) {
13
- return root
14
- }
15
- const cache = root.addressCache?.('up', !!includePrivate)
16
- const privateChildren = (includePrivate ? await root.privateChildren?.() : []) ?? []
17
- const publicChildren = (await root.publicChildren?.()) ?? []
18
- const children = [...privateChildren, ...publicChildren]
19
- for (const child of children) {
20
- const found = await resolveAddressToInstanceDown(child, address, includePrivate, ignore)
21
- if (found) {
22
- cache?.set(address, new WeakRef(found))
23
- return found
24
- }
25
- }
26
- cache?.set(address, null)
27
- }
28
-
29
- export const resolveAddressToInstanceSiblings = async (
30
- root: ModuleInstance,
31
- address: Address,
32
- includePrivate: boolean | undefined = undefined,
33
- ignore: Address[] = [],
34
- ): Promise<ModuleInstance | undefined> => {
35
- const siblings = (await root.siblings?.()) ?? []
36
- for (const sibling of siblings) {
37
- const found = await resolveAddressToInstanceDown(sibling, address, includePrivate, ignore)
38
- if (found) {
39
- return found
40
- }
41
- }
42
- }
43
-
44
- export const resolveAddressToInstanceUp = async (
45
- root: ModuleInstance,
46
- address: Address,
47
- includePrivate: boolean | undefined = undefined,
48
- ignore: Address[] = [],
49
- ): Promise<ModuleInstance | undefined> => {
50
- const cache = root.addressCache?.('up', includePrivate ?? true)
51
- const parents = (await root.parents?.()) ?? []
52
- for (const parent of parents) {
53
- const found = await resolveAddressToInstance(parent, address, includePrivate, ignore)
54
- if (found) {
55
- cache?.set(address, new WeakRef(found))
56
- return found
57
- }
58
- }
59
- cache?.set(address, null)
60
- }
61
-
62
- export const resolveAddressToInstanceAll = async (
63
- root: ModuleInstance,
64
- address: Address,
65
- includePrivate: boolean | undefined = undefined,
66
- ignore: Address[] = [],
67
- ): Promise<ModuleInstance | undefined> => {
68
- const cache = root.addressCache?.('all', !!includePrivate)
69
- const result
70
- = (await resolveAddressToInstanceDown(root, address, includePrivate ?? false, ignore))
71
- ?? (await resolveAddressToInstanceUp(root, address, includePrivate ?? true, ignore))
72
- cache?.set(address, result ? new WeakRef(result) : null)
73
- return result
74
- }
75
-
76
- export const resolveAddressToInstance = async (
77
- root: ModuleInstance,
78
- address: Address,
79
- includePrivate: boolean | undefined = undefined,
80
- ignore: Address[] = [],
81
- direction: ModuleResolveDirection = 'all',
82
- ): Promise<ModuleInstance | undefined> => {
83
- switch (direction) {
84
- case 'all': {
85
- return await resolveAddressToInstanceAll(root, address, includePrivate, ignore)
86
- }
87
- case 'up': {
88
- return await resolveAddressToInstanceUp(root, address, includePrivate ?? true, ignore)
89
- }
90
- case 'down': {
91
- return await resolveAddressToInstanceDown(root, address, includePrivate ?? false, ignore)
92
- }
93
- }
94
- }
@@ -1,53 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
-
3
- import type { ModuleInstance } from '../instance/index.ts'
4
- import { duplicateModules } from '../lib/index.ts'
5
-
6
- export const resolveAllUp = async (root: ModuleInstance, maxDepth = 10, exclude: Address[] = []): Promise<ModuleInstance[]> => {
7
- if (maxDepth === 0) {
8
- return [root].filter(mod => !exclude.includes(mod.address))
9
- }
10
- const parents = (await root.parents()).filter(mod => !exclude.includes(mod.address))
11
- return (
12
- maxDepth > 1
13
- ? [
14
- ...(await Promise.all(parents.map(async mod => await resolveAllUp(mod, maxDepth - 1, [...exclude, root.address])))).flat(),
15
- ...(await Promise.all(parents.map(async mod => await resolveAllDown(mod, maxDepth - 1, [...exclude, root.address], true)))).flat(),
16
- ...parents,
17
- root,
18
- ]
19
- : [...parents, root])
20
- .filter(mod => !exclude.includes(mod.address))
21
- .filter(duplicateModules)
22
- }
23
-
24
- export const resolveAllDown = async (
25
- root: ModuleInstance,
26
- maxDepth = 10,
27
- exclude: Address[] = [],
28
- includePrivate = false,
29
- ): Promise<ModuleInstance[]> => {
30
- if (maxDepth === 0) {
31
- return [root]
32
- }
33
- const children = (await root.publicChildren()).filter(mod => !exclude.includes(mod.address))
34
- const privateChildren = includePrivate ? (await root.privateChildren()).filter(mod => !exclude.includes(mod.address)) : []
35
- return (
36
- maxDepth > 1
37
- ? [
38
- ...children,
39
- ...(await Promise.all(children.map(child => resolveAllDown(child, maxDepth - 1, [...exclude, root.address])))).flat(),
40
- ...(await Promise.all(privateChildren.map(child => resolveAllDown(child, maxDepth - 1, [...exclude, root.address])))).flat(),
41
- root,
42
- ]
43
- : [...children, root])
44
- .filter(mod => !exclude.includes(mod.address))
45
- .filter(duplicateModules)
46
- }
47
-
48
- export const resolveAll = async (root: ModuleInstance, maxDepth = 10, exclude: Address[] = []): Promise<ModuleInstance[]> => {
49
- if (maxDepth === 0) {
50
- return [root]
51
- }
52
- return [...(await resolveAllUp(root, maxDepth, exclude)), ...(await resolveAllDown(root, maxDepth, exclude))].filter(duplicateModules)
53
- }
@@ -1,40 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
-
3
- import type { ModuleInstance } from '../instance/index.ts'
4
- import type { ModuleName } from '../ModuleIdentifier.ts'
5
- import type { ModuleResolveDirection } from './model.ts'
6
- import {
7
- resolveLocalNameToInstance,
8
- resolveLocalNameToInstanceAll,
9
- resolveLocalNameToInstanceDown,
10
- resolveLocalNameToInstanceUp,
11
- } from './resolveLocalNameToInstance.ts'
12
-
13
- export const resolveLocalNameToAddressUp = async (root: ModuleInstance, modName: ModuleName): Promise<Address | undefined> => {
14
- return (await resolveLocalNameToInstanceUp(root, modName))?.address
15
- }
16
-
17
- export const resolveLocalNameToAddressDown = async (
18
- root: ModuleInstance,
19
- modName: ModuleName,
20
- includePrivate: boolean | undefined = undefined,
21
- ): Promise<Address | undefined> => {
22
- return (await resolveLocalNameToInstanceDown(root, modName, includePrivate))?.address
23
- }
24
-
25
- export const resolveLocalNameToAddressAll = async (
26
- root: ModuleInstance,
27
- modName: ModuleName,
28
- includePrivate: boolean | undefined = undefined,
29
- ): Promise<Address | undefined> => {
30
- return (await resolveLocalNameToInstanceAll(root, modName, includePrivate))?.address
31
- }
32
-
33
- export const resolveLocalNameToAddress = async (
34
- root: ModuleInstance,
35
- modName: ModuleName,
36
- includePrivate: boolean | undefined = undefined,
37
- direction: ModuleResolveDirection = 'all',
38
- ): Promise<Address | undefined> => {
39
- return (await resolveLocalNameToInstance(root, modName, includePrivate, direction))?.address
40
- }
@@ -1,47 +0,0 @@
1
- import type { ModuleInstance } from '../instance/index.ts'
2
- import type { ModuleName } from '../ModuleIdentifier.ts'
3
- import type { ModuleResolveDirection } from './model.ts'
4
-
5
- export const resolveLocalNameToInstanceUp = async (root: ModuleInstance, modName: ModuleName): Promise<ModuleInstance | undefined> => {
6
- const parents = (await root.parents?.()) ?? []
7
- return parents.find(parent => parent.config.name === modName)
8
- }
9
-
10
- // since this is a modName, it only checks the children of the root module
11
- export const resolveLocalNameToInstanceDown = async (
12
- root: ModuleInstance,
13
- modName: ModuleName,
14
- includePrivate: boolean | undefined = undefined,
15
- ): Promise<ModuleInstance | undefined> => {
16
- const privateChildren = (includePrivate ? await root.privateChildren?.() : []) ?? []
17
- const publicChildren = (await root.publicChildren?.()) ?? []
18
- const children = [...privateChildren, ...publicChildren]
19
- return children.find(child => child.config.name === modName)
20
- }
21
-
22
- export const resolveLocalNameToInstanceAll = async (
23
- root: ModuleInstance,
24
- modName: ModuleName,
25
- includePrivate = false,
26
- ): Promise<ModuleInstance | undefined> => {
27
- return (await resolveLocalNameToInstanceDown(root, modName, includePrivate)) ?? (await resolveLocalNameToInstanceUp(root, modName))
28
- }
29
-
30
- export const resolveLocalNameToInstance = async (
31
- root: ModuleInstance,
32
- modName: ModuleName,
33
- includePrivate = false,
34
- direction: ModuleResolveDirection = 'all',
35
- ): Promise<ModuleInstance | undefined> => {
36
- switch (direction) {
37
- case 'all': {
38
- return await resolveLocalNameToInstanceAll(root, modName, includePrivate)
39
- }
40
- case 'up': {
41
- return await resolveLocalNameToInstanceUp(root, modName)
42
- }
43
- case 'down': {
44
- return await resolveLocalNameToInstanceDown(root, modName, includePrivate)
45
- }
46
- }
47
- }
@@ -1,15 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
-
3
- import type { ModuleInstance } from '../instance/index.ts'
4
- import type { ModuleIdentifierTransformer } from '../ModuleIdentifierTransformer.ts'
5
- import { ResolveHelperStatic } from './ResolveHelperStatic.ts'
6
- import { resolvePathToInstance } from './resolvePathToInstance.ts'
7
-
8
- export const resolvePathToAddress = async (
9
- root: ModuleInstance,
10
- path: string,
11
- includePrivate: boolean | undefined = undefined,
12
- transformers: ModuleIdentifierTransformer[] = ResolveHelperStatic.transformers,
13
- ): Promise<Address | undefined> => {
14
- return (await resolvePathToInstance(root, path, includePrivate, transformers))?.address
15
- }
@@ -1,36 +0,0 @@
1
- import { asAddress, assertEx } from '@xylabs/sdk-js'
2
-
3
- import type { ModuleInstance } from '../instance/index.ts'
4
- import { MODULE_PATH_SEPARATOR } from '../ModuleIdentifier.ts'
5
- import type { ModuleIdentifierTransformer } from '../ModuleIdentifierTransformer.ts'
6
- import { resolveAddressToInstance } from './resolveAddressToInstance.ts'
7
- import { ResolveHelperStatic } from './ResolveHelperStatic.ts'
8
- import { resolveLocalNameToAddress } from './resolveLocalNameToAddress.ts'
9
- import { transformModuleIdentifier } from './transformModuleIdentifier.ts'
10
-
11
- export const resolvePathToInstance = async (
12
- root: ModuleInstance,
13
- path: string,
14
- includePrivate: boolean | undefined = undefined,
15
- transformers: ModuleIdentifierTransformer[] = ResolveHelperStatic.transformers,
16
- ): Promise<ModuleInstance | undefined> => {
17
- const parts = path.split(MODULE_PATH_SEPARATOR)
18
- const first = await transformModuleIdentifier(
19
- assertEx(parts.shift(), () => `First part is invalid [${path}]`),
20
- transformers,
21
- )
22
-
23
- if (!first) {
24
- return undefined
25
- }
26
-
27
- const firstAddress = asAddress(first) ?? (await resolveLocalNameToAddress(root, first, includePrivate))
28
-
29
- if (firstAddress) {
30
- const firstModule = await resolveAddressToInstance(root, firstAddress, includePrivate)
31
- if (firstModule && parts.length > 0) {
32
- return resolvePathToInstance(firstModule, parts.join(MODULE_PATH_SEPARATOR))
33
- }
34
- return firstModule
35
- }
36
- }
@@ -1,19 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
- import { assertEx } from '@xylabs/sdk-js'
3
-
4
- import type { ModuleResolver } from '../instance/index.ts'
5
- import { asModuleInstance } from '../instance/index.ts'
6
- import type { ModuleIdentifier } from '../ModuleIdentifier.ts'
7
-
8
- export const traceModuleIdentifier = async (resolver: ModuleResolver, path: ModuleIdentifier): Promise<Address[]> => {
9
- const parts = path.split(':')
10
- const first = parts.shift()
11
- const firstModule = asModuleInstance(
12
- assertEx(await resolver.resolve(first, { maxDepth: 1 }), () => `Failed to resolve [${first}]`),
13
- () => `Resolved invalid module instance [${first}]`,
14
- )
15
- if (firstModule) {
16
- return parts.length > 0 ? [firstModule.address, ...(await traceModuleIdentifier(firstModule, parts.join(':')))] : [firstModule.address]
17
- }
18
- return []
19
- }
@@ -1,13 +0,0 @@
1
- import type { ModuleIdentifier } from '../ModuleIdentifier.ts'
2
- import type { ModuleIdentifierTransformer } from '../ModuleIdentifierTransformer.ts'
3
-
4
- export const transformModuleIdentifier = async (
5
- id: ModuleIdentifier,
6
- transformers: ModuleIdentifierTransformer[],
7
- ): Promise<ModuleIdentifier | undefined> => {
8
- let result: ModuleIdentifier | undefined = id
9
- for (const transformer of transformers) {
10
- result = await transformer.transform(id)
11
- }
12
- return result
13
- }
package/src/cache.ts DELETED
@@ -1,5 +0,0 @@
1
- export interface CacheConfig {
2
- max?: number
3
- maxSize?: number
4
- ttl?: number
5
- }
package/src/index.ts DELETED
@@ -1,20 +0,0 @@
1
- export * from './cache.ts'
2
- export * from './Config/index.ts'
3
- export * from './CreatableModule/index.ts'
4
- export * from './DetailsError.ts'
5
- export * from './EventsModels/index.ts'
6
- export * from './instance/index.ts'
7
- export * from './Labels/index.ts'
8
- export * from './lib/index.ts'
9
- export * from './ModuleDescription.ts'
10
- export * from './ModuleFactoryLocatorInstance.ts'
11
- export * from './ModuleIdentifier.ts'
12
- export * from './ModuleIdentifierTransformer.ts'
13
- export * from './ModuleQueryHandlerResult.ts'
14
- export * from './ModuleQueryResult.ts'
15
- export * from './ModuleStatusReporter.ts'
16
- export * from './Payload/index.ts'
17
- export * from './Queries/index.ts'
18
- export * from './QueryableModule/index.ts'
19
- export * from './ResolveHelper/index.ts'
20
- export * from './withModule.ts'
@@ -1,68 +0,0 @@
1
- import type {
2
- Address, CreatableStatus, Promisable,
3
- TypeCheck,
4
- } from '@xylabs/sdk-js'
5
- import { IsObjectFactory, toSafeJsonString } from '@xylabs/sdk-js'
6
- import type { AccountInstance } from '@xyo-network/account-model'
7
-
8
- import type { ModuleEventData } from '../EventsModels/index.ts'
9
- import type { ModuleIdentifier, ModuleName } from '../ModuleIdentifier.ts'
10
- import type {
11
- QueryableModule, QueryableModuleFunctions,
12
- QueryableModuleParams,
13
- } from '../QueryableModule/index.ts'
14
- import type { Direction } from './ObjectFilter.ts'
15
- import type { ObjectResolver } from './ObjectResolver.ts'
16
-
17
- export type ModulePipeLine = Lowercase<'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many'>
18
-
19
- export type ModuleStatus = CreatableStatus | 'wrapped' | 'proxy'
20
-
21
- export class DeadModuleError extends Error {
22
- error: Error | undefined
23
- id: ModuleIdentifier
24
- constructor(
25
- id: ModuleIdentifier,
26
- error: Error | undefined,
27
- msg = 'Dead Module Error',
28
- ) {
29
- super(`${msg} [${id}]: ${error?.message ?? toSafeJsonString(error)}`)
30
- this.id = id
31
- this.error = error
32
-
33
- // Set the prototype explicitly.
34
- Object.setPrototypeOf(this, DeadModuleError.prototype)
35
- }
36
- }
37
-
38
- export interface AddressToWeakInstanceCache {
39
- get: (address: Address) => WeakRef<ModuleInstance> | null
40
- set: (address: Address, instance: WeakRef<ModuleInstance> | null) => void
41
- }
42
-
43
- export interface ModuleFamilyFunctions {
44
- account?: AccountInstance
45
- addParent: (mod: ModuleInstance) => void
46
- addressCache?: (direction: Direction, includePrivate: boolean) => AddressToWeakInstanceCache | undefined
47
- modName?: ModuleName
48
- parents: () => Promisable<ModuleInstance[]>
49
- privateChildren: () => Promisable<ModuleInstance[]>
50
- publicChildren: () => Promisable<ModuleInstance[]>
51
- removeParent: (address: Address) => void
52
- siblings: () => Promisable<ModuleInstance[]>
53
- }
54
-
55
- export interface ModuleInstance<TParams extends QueryableModuleParams = QueryableModuleParams, TEventData extends ModuleEventData = ModuleEventData>
56
- extends QueryableModule<TParams, TEventData>,
57
- ObjectResolver<ModuleInstance>,
58
- QueryableModuleFunctions,
59
- ModuleFamilyFunctions {
60
- readonly pipeline?: ModulePipeLine
61
-
62
- // if the module has become non-functional, such as a broken bridge connection, this will be 'dead'
63
- readonly status: ModuleStatus | null
64
- }
65
-
66
- export type InstanceTypeCheck<T extends ModuleInstance = ModuleInstance> = TypeCheck<T>
67
-
68
- export class IsInstanceFactory<T extends ModuleInstance = ModuleInstance> extends IsObjectFactory<T> {}