@xyo-network/node-memory 3.18.10 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,22 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result) __defProp(target, key, result);
9
+ return result;
10
+ };
11
+
1
12
  // src/MemoryNode.ts
2
13
  import { assertEx } from "@xylabs/assert";
3
14
  import { exists } from "@xylabs/exists";
4
15
  import { isAddress } from "@xylabs/hex";
5
16
  import { isDefined } from "@xylabs/typeof";
17
+ import {
18
+ creatableModule
19
+ } from "@xyo-network/module-model";
6
20
  import { AbstractNode } from "@xyo-network/node-abstract";
7
21
  import { isNodeModule } from "@xyo-network/node-model";
8
22
  import { Mutex } from "async-mutex";
@@ -186,6 +200,9 @@ var MemoryNode = class extends AbstractNode {
186
200
  })?.address;
187
201
  }
188
202
  };
203
+ MemoryNode = __decorateClass([
204
+ creatableModule()
205
+ ], MemoryNode);
189
206
 
190
207
  // src/NodeHelper/index.ts
191
208
  import { NodeHelper } from "@xyo-network/node-abstract";
@@ -211,7 +228,7 @@ var flatAttachAllToExistingNode = async (source, destination) => {
211
228
  var flatAttachChildToExistingNode = async (source, id, destination) => {
212
229
  assertEx2(id !== "*", () => "* is not a single child");
213
230
  const child = assertEx2(await source.resolve(id), () => `Module ${id} not found`);
214
- const attachableChild = asAttachableModuleInstance(child, () => `Module ${id} is not attachable`);
231
+ const attachableChild = asAttachableModuleInstance(child, () => `Module ${id} is not attachable`, { required: true });
215
232
  await destination.register?.(attachableChild);
216
233
  await destination.attach(child.address, true);
217
234
  return destination;
@@ -228,7 +245,7 @@ var attachToExistingNode = async (source, id, destination) => {
228
245
  return await flatAttachToExistingNode(source, first, destination);
229
246
  } else {
230
247
  const firstModule = await source.resolve(first);
231
- const firstNode = asNodeInstance(firstModule, () => "first part is not a node");
248
+ const firstNode = asNodeInstance(firstModule, () => "first part is not a node", { required: true });
232
249
  const newNode = await MemoryNode.create({ config: firstNode.config });
233
250
  await destination.register?.(newNode);
234
251
  await destination.attach(newNode.address, true);
@@ -239,7 +256,7 @@ var attachToExistingNode = async (source, id, destination) => {
239
256
 
240
257
  // src/NodeHelper/attachToNewNode.ts
241
258
  import { NodeConfigSchema } from "@xyo-network/node-model";
242
- var DEFAULT_NODE_PARAMS = { config: { schema: NodeConfigSchema } };
259
+ var DEFAULT_NODE_PARAMS = { config: { schema: NodeConfigSchema }, name: "MemoryNode" };
243
260
  var attachToNewNode = async (source, id, destinationParams = DEFAULT_NODE_PARAMS) => {
244
261
  const destination = await MemoryNode.create(destinationParams);
245
262
  return await attachToExistingNode(source, id, destination);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/MemoryNode.ts","../../src/NodeHelper/index.ts","../../src/NodeHelper/attachToExistingNode.ts","../../src/NodeHelper/flatAttachToExistingNode.ts","../../src/NodeHelper/attachToNewNode.ts","../../src/NodeHelper/flatAttachToNewNode.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport type { EventListener } from '@xylabs/events'\nimport { exists } from '@xylabs/exists'\nimport type { Address } from '@xylabs/hex'\nimport { isAddress } from '@xylabs/hex'\nimport type { Promisable } from '@xylabs/promise'\nimport { isDefined } from '@xylabs/typeof'\nimport type {\n AnyConfigSchema,\n AttachableModuleInstance,\n Module,\n ModuleIdentifier,\n ModuleInstance,\n ModuleResolverInstance,\n} from '@xyo-network/module-model'\nimport type { CompositeModuleResolver } from '@xyo-network/module-resolver'\nimport { AbstractNode } from '@xyo-network/node-abstract'\nimport type {\n AttachableNodeInstance, ChildCertificationFields,\n NodeConfig, NodeModuleEventData, NodeParams,\n} from '@xyo-network/node-model'\nimport { isNodeModule } from '@xyo-network/node-model'\nimport { Mutex } from 'async-mutex'\n\nexport type MemoryNodeParams = NodeParams<AnyConfigSchema<NodeConfig>>\n\nexport class MemoryNode<TParams extends MemoryNodeParams = MemoryNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends AbstractNode<TParams, TEventData>\n implements AttachableNodeInstance<TParams, TEventData> {\n protected registeredModuleMap: Partial<Record<Address, AttachableModuleInstance>> = {}\n\n private _attachMutex = new Mutex()\n\n private _attachedPrivateModules = new Set<Address>()\n private _attachedPublicModules = new Set<Address>()\n\n async attachHandler(id: ModuleIdentifier, external?: boolean) {\n await this.started('throw')\n return assertEx(\n isAddress(id) ? await this.attachUsingAddress(id as Address, external) : await this.attachUsingName(id, external),\n () => `Unable to locate module [${id}]`,\n )\n }\n\n async certifyHandler(id: ModuleIdentifier): Promise<ChildCertificationFields> {\n const child = (await this.publicChildren()).find(child => child.modName === id || child.address === id)\n if (child) {\n return { address: child.address, expiration: Date.now() + 1000 * 60 * 10 /* 10 minutes */ }\n }\n throw new Error(`Unable to certify child module [${id}]`)\n }\n\n async detachHandler(id: ModuleIdentifier) {\n await this.started('throw')\n return isAddress(id) ? await this.detachUsingAddress(id as Address) : await this.detachUsingName(id)\n }\n\n override async privateChildren(): Promise<ModuleInstance[]> {\n return [...(await this.attachedPrivateModules()), ...this.params.privateChildren ?? []]\n }\n\n override async publicChildren(): Promise<ModuleInstance[]> {\n return [...(await this.attachedPublicModules()), ...this.params.publicChildren ?? []]\n }\n\n async register(mod: AttachableModuleInstance) {\n await this.started('throw')\n if (this.registeredModuleMap[mod.address]) {\n if (this.registeredModuleMap[mod.address] === mod) {\n this.logger?.warn(`Module already registered at that address[${mod.address}]|${mod.id}|[${mod.config.schema}]`)\n } else {\n throw new Error(`Other module already registered at that address[${mod.address}]|${mod.id}|[${mod.config.schema}]`)\n }\n }\n this.registeredModuleMap[mod.address] = mod\n const args = { mod, name: mod.modName }\n await this.emit('moduleRegistered', args)\n }\n\n registeredHandler(): Promisable<Address[]> {\n return Promise.resolve(\n (Object.keys(this.registeredModuleMap) as Address[]).map((key) => {\n return key\n }),\n )\n }\n\n registeredModules(): AttachableModuleInstance[] {\n return Object.values(this.registeredModuleMap).map((value) => {\n return value\n }).filter(exists)\n }\n\n async unregister(mod: ModuleInstance): Promise<ModuleInstance> {\n await this.started('throw')\n // try to detach if it is attached\n try {\n await this.detach(mod.address)\n } catch {}\n delete this.registeredModuleMap[mod.address]\n const args = { mod, name: mod.modName }\n await this.emit('moduleUnregistered', args)\n return this\n }\n\n protected async attachUsingAddress(address: Address, external?: boolean) {\n return await this._attachMutex.runExclusive(async () => {\n const existingModule = await this.resolve(address)\n if (existingModule) {\n this.logger?.warn(`MemoryNode: Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n }\n const mod = assertEx(this.registeredModuleMap[address], () => `No Module Registered at address [${address}]`)\n\n if (this._attachedPublicModules.has(mod.address)) {\n this.logger?.warn(`Module [${mod.modName}] already attached at [${address}] (public)`)\n }\n if (this._attachedPrivateModules.has(mod.address)) {\n this.logger?.warn(`Module [${mod.modName}] already attached at [${address}] (private)`)\n }\n\n const notificationList = await this.getModulesToNotifyAbout(mod)\n\n // give it private access\n mod.upResolver.addResolver?.(this.privateResolver)\n\n // give it public access\n mod.upResolver.addResolver?.(this.downResolver as CompositeModuleResolver)\n\n // give it outside access\n mod.upResolver.addResolver?.(this.upResolver)\n\n if (external) {\n // expose it externally\n this._attachedPublicModules.add(mod.address)\n this.downResolver.addResolver(mod.downResolver as ModuleResolverInstance)\n } else {\n this._attachedPrivateModules.add(mod.address)\n this.privateResolver.addResolver(mod.downResolver as ModuleResolverInstance)\n }\n\n mod.addParent(this)\n\n const args = { mod, name: mod.modName }\n await this.emit('moduleAttached', args)\n\n if (isNodeModule(mod) && external) {\n const attachedListener: EventListener<TEventData['moduleAttached']> = async (args: TEventData['moduleAttached']) =>\n await this.emit('moduleAttached', args)\n\n const detachedListener: EventListener<TEventData['moduleDetached']> = async (args: TEventData['moduleDetached']) =>\n await this.emit('moduleDetached', args)\n\n mod.on('moduleAttached', attachedListener as EventListener)\n mod.on('moduleDetached', detachedListener as EventListener)\n }\n\n await this.notifyOfExistingModulesAttached(notificationList)\n\n return address\n })\n }\n\n protected async detachUsingAddress(address: Address) {\n const mod = assertEx(this.registeredModuleMap[address], () => `No Module Registered at address [${address}]`)\n\n const isAttachedPublic = this._attachedPublicModules.has(mod.address)\n const isAttachedPrivate = this._attachedPrivateModules.has(mod.address)\n\n assertEx(isAttachedPublic || isAttachedPrivate, () => `Module [${mod.modName}] not attached at [${address}]`)\n\n // remove inside access\n mod.upResolver?.removeResolver?.(this.privateResolver)\n\n // remove outside access\n mod.upResolver?.removeResolver?.(this.upResolver)\n\n // remove external exposure\n this.downResolver.removeResolver(mod.downResolver as ModuleResolverInstance)\n\n mod.removeParent(this.address)\n\n if (isAttachedPublic) {\n this._attachedPublicModules.delete(mod.address)\n }\n\n if (isAttachedPrivate) {\n this._attachedPrivateModules.delete(mod.address)\n }\n\n const args = { mod, name: mod.modName }\n await this.emit('moduleDetached', args)\n\n // notify of all sub node children detach\n if (isNodeModule(mod)) {\n const notificationList = await this.getModulesToNotifyAbout(mod)\n await this.notifyOfExistingModulesDetached(notificationList)\n }\n return address\n }\n\n protected override startHandler() {\n return super.startHandler()\n }\n\n private async attachUsingName(name: string, external?: boolean) {\n const address = this.registeredModuleAddressFromName(name)\n if (isDefined(address)) {\n return await this.attachUsingAddress(address, external)\n }\n }\n\n private async detachUsingName(name: string) {\n const address = this.registeredModuleAddressFromName(name)\n if (isDefined(address)) {\n return await this.detachUsingAddress(address)\n }\n }\n\n private async getModulesToNotifyAbout(node: ModuleInstance) {\n const notifiedAddresses: string[] = []\n // send attach events for all existing attached modules\n const childModules = await node.resolve('*', { direction: 'down' })\n return (\n childModules.map((child) => {\n // don't report self\n if (node.address === child.address) {\n return\n }\n\n // prevent loop\n if (notifiedAddresses.includes(child.address)) {\n return\n }\n\n notifiedAddresses.push(child.address)\n\n return child\n })\n ).filter(exists)\n }\n\n private async notifyOfExistingModulesAttached(childModules: Module[]) {\n await Promise.all(\n childModules.map(async (child) => {\n const args = { mod: child, name: child.modName }\n await this.emit('moduleAttached', args)\n }),\n )\n }\n\n private async notifyOfExistingModulesDetached(childModules: Module[]) {\n await Promise.all(\n childModules.map(async (child) => {\n const args = { mod: child, name: child.modName }\n await this.emit('moduleDetached', args)\n }),\n )\n }\n\n private registeredModuleAddressFromName(name: string) {\n return Object.values(this.registeredModuleMap).find((value) => {\n return value?.modName === name\n })?.address\n }\n}\n","import { NodeHelper } from '@xyo-network/node-abstract'\n\nimport { attachToExistingNode } from './attachToExistingNode.ts'\nimport { attachToNewNode } from './attachToNewNode.ts'\nimport {\n flatAttachAllToExistingNode, flatAttachChildToExistingNode, flatAttachToExistingNode,\n} from './flatAttachToExistingNode.ts'\nimport { flatAttachToNewNode } from './flatAttachToNewNode.ts'\n\nexport const MemoryNodeHelper = {\n ...NodeHelper,\n attachToExistingNode,\n attachToNewNode,\n flatAttachAllToExistingNode,\n flatAttachChildToExistingNode,\n flatAttachToExistingNode,\n flatAttachToNewNode,\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { ModuleIdentifier } from '@xyo-network/module-model'\nimport type { NodeInstance } from '@xyo-network/node-model'\nimport { asNodeInstance } from '@xyo-network/node-model'\n\nimport { MemoryNode } from '../MemoryNode.ts'\nimport { flatAttachToExistingNode } from './flatAttachToExistingNode.ts'\n\nexport const attachToExistingNode = async (source: NodeInstance, id: ModuleIdentifier, destination: NodeInstance): Promise<NodeInstance> => {\n const parts = id.split(':')\n const first = assertEx(parts.shift(), () => 'missing first part')\n if (parts.length === 0) {\n // this is an immediate child/children\n return await flatAttachToExistingNode(source, first, destination)\n } else {\n // all parts that are not the last should be nodes, build them and nest\n const firstModule = await source.resolve(first)\n const firstNode = asNodeInstance(firstModule, () => 'first part is not a node')\n const newNode = await MemoryNode.create({ config: firstNode.config })\n await destination.register?.(newNode)\n await destination.attach(newNode.address, true)\n await attachToExistingNode(firstNode, parts.join(':'), newNode)\n return destination\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport type { ModuleIdentifier } from '@xyo-network/module-model'\nimport { asAttachableModuleInstance } from '@xyo-network/module-model'\nimport type { NodeInstance } from '@xyo-network/node-model'\n\nexport const flatAttachAllToExistingNode = async (source: NodeInstance, destination: NodeInstance): Promise<NodeInstance> => {\n const children = (await source.publicChildren()).map(child => asAttachableModuleInstance(child)).filter(exists)\n await Promise.all(\n children.map(async (child) => {\n await destination.register?.(child)\n await destination.attach(child.address, true)\n }),\n )\n return destination\n}\n\nexport const flatAttachChildToExistingNode = async (source: NodeInstance, id: ModuleIdentifier, destination: NodeInstance): Promise<NodeInstance> => {\n assertEx(id !== '*', () => '* is not a single child')\n const child = assertEx(await source.resolve(id), () => `Module ${id} not found`)\n const attachableChild = asAttachableModuleInstance(child, () => `Module ${id} is not attachable`)\n await destination.register?.(attachableChild)\n await destination.attach(child.address, true)\n return destination\n}\n\nexport const flatAttachToExistingNode = async (source: NodeInstance, id: ModuleIdentifier, destination: NodeInstance): Promise<NodeInstance> => {\n return id === '*' ? await flatAttachAllToExistingNode(source, destination) : flatAttachChildToExistingNode(source, id, destination)\n}\n","import type { ModuleIdentifier } from '@xyo-network/module-model'\nimport type { NodeInstance } from '@xyo-network/node-model'\nimport { NodeConfigSchema } from '@xyo-network/node-model'\n\nimport type { MemoryNodeParams } from '../MemoryNode.ts'\nimport { MemoryNode } from '../MemoryNode.ts'\nimport { attachToExistingNode } from './attachToExistingNode.ts'\n\nconst DEFAULT_NODE_PARAMS = { config: { schema: NodeConfigSchema } }\n\nexport const attachToNewNode = async (\n source: NodeInstance,\n id: ModuleIdentifier,\n destinationParams: MemoryNodeParams = DEFAULT_NODE_PARAMS,\n): Promise<NodeInstance> => {\n const destination = await MemoryNode.create(destinationParams)\n return await attachToExistingNode(source, id, destination)\n}\n","import type { ModuleIdentifier } from '@xyo-network/module-model'\nimport type { NodeInstance } from '@xyo-network/node-model'\n\nimport type { MemoryNodeParams } from '../MemoryNode.ts'\nimport { MemoryNode } from '../MemoryNode.ts'\nimport { flatAttachToExistingNode } from './flatAttachToExistingNode.ts'\n\nexport const flatAttachToNewNode = async (\n source: NodeInstance,\n id: ModuleIdentifier,\n destinationParams: MemoryNodeParams,\n): Promise<NodeInstance> => {\n const destination = await MemoryNode.create(destinationParams)\n return await flatAttachToExistingNode(source, id, destination)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAEzB,SAAS,cAAc;AAEvB,SAAS,iBAAiB;AAE1B,SAAS,iBAAiB;AAU1B,SAAS,oBAAoB;AAK7B,SAAS,oBAAoB;AAC7B,SAAS,aAAa;AAIf,IAAM,aAAN,cACG,aAC+C;AAAA,EAC7C,sBAA0E,CAAC;AAAA,EAE7E,eAAe,IAAI,MAAM;AAAA,EAEzB,0BAA0B,oBAAI,IAAa;AAAA,EAC3C,yBAAyB,oBAAI,IAAa;AAAA,EAElD,MAAM,cAAc,IAAsB,UAAoB;AAC5D,UAAM,KAAK,QAAQ,OAAO;AAC1B,WAAO;AAAA,MACL,UAAU,EAAE,IAAI,MAAM,KAAK,mBAAmB,IAAe,QAAQ,IAAI,MAAM,KAAK,gBAAgB,IAAI,QAAQ;AAAA,MAChH,MAAM,4BAA4B,EAAE;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,MAAM,eAAe,IAAyD;AAC5E,UAAM,SAAS,MAAM,KAAK,eAAe,GAAG,KAAK,CAAAA,WAASA,OAAM,YAAY,MAAMA,OAAM,YAAY,EAAE;AACtG,QAAI,OAAO;AACT,aAAO;AAAA,QAAE,SAAS,MAAM;AAAA,QAAS,YAAY,KAAK,IAAI,IAAI,MAAO,KAAK;AAAA;AAAA,MAAoB;AAAA,IAC5F;AACA,UAAM,IAAI,MAAM,mCAAmC,EAAE,GAAG;AAAA,EAC1D;AAAA,EAEA,MAAM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QE,UAAS,MAAM,MAAM,GAAG,MAAM,oBAAoB;AAChE,MAAI,MAAM,WAAW,GAAG;AAEtB,WAAO,MAAM,yBAAyB,QAAQ,OAAO,WAAW;AAAA,EAClE,OAAO;AAEL,UAAM,cAAc,MAAM,OAAO,QAAQ,KAAK;AAC9C,UAAM,YAAY,eAAe,aAAa,MAAM,0BAA0B;AAC9E,UAAM,UAAU,MAAM,WAAW,OAAO,EAAE,QAAQ,UAAU,OAAO,CAAC;AACpE,UAAM,YAAY,WAAW,OAAO;AACpC,UAAM,YAAY,OAAO,QAAQ,SAAS,IAAI;AAC9C,UAAM,qBAAqB,WAAW,MAAM,KAAK,GAAG,GAAG,OAAO;AAC9D,WAAO;AAAA,EACT;AACF;;;AEtBA,SAAS,wBAAwB;AAMjC,IAAM,sBAAsB,EAAE,QAAQ,EAAE,QAAQ,iBAAiB,EAAE;AAE5D,IAAM,kBAAkB,OAC7B,QACA,IACA,oBAAsC,wBACZ;AAC1B,QAAM,cAAc,MAAM,WAAW,OAAO,iBAAiB;AAC7D,SAAO,MAAM,qBAAqB,QAAQ,IAAI,WAAW;AAC3D;;;ACVO,IAAM,sBAAsB,OACjC,QACA,IACA,sBAC0B;AAC1B,QAAM,cAAc,MAAM,WAAW,OAAO,iBAAiB;AAC7D,SAAO,MAAM,yBAAyB,QAAQ,IAAI,WAAW;AAC/D;;;AJLO,IAAM,mBAAmB;AAAA,EAC9B,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":["child","args","assertEx","assertEx","exists","assertEx"]}
1
+ {"version":3,"sources":["../../src/MemoryNode.ts","../../src/NodeHelper/index.ts","../../src/NodeHelper/attachToExistingNode.ts","../../src/NodeHelper/flatAttachToExistingNode.ts","../../src/NodeHelper/attachToNewNode.ts","../../src/NodeHelper/flatAttachToNewNode.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport type { EventListener } from '@xylabs/events'\nimport { exists } from '@xylabs/exists'\nimport type { Address } from '@xylabs/hex'\nimport { isAddress } from '@xylabs/hex'\nimport type { Promisable } from '@xylabs/promise'\nimport { isDefined } from '@xylabs/typeof'\nimport {\n type AnyConfigSchema,\n type AttachableModuleInstance,\n creatableModule,\n type Module,\n type ModuleIdentifier,\n type ModuleInstance,\n type ModuleResolverInstance,\n} from '@xyo-network/module-model'\nimport type { CompositeModuleResolver } from '@xyo-network/module-resolver'\nimport { AbstractNode } from '@xyo-network/node-abstract'\nimport type {\n ChildCertificationFields,\n NodeConfig, NodeModuleEventData, NodeParams,\n} from '@xyo-network/node-model'\nimport { isNodeModule } from '@xyo-network/node-model'\nimport { Mutex } from 'async-mutex'\n\nexport type MemoryNodeParams = NodeParams<AnyConfigSchema<NodeConfig>>\n\n@creatableModule()\nexport class MemoryNode<TParams extends MemoryNodeParams = MemoryNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends AbstractNode<TParams, TEventData> {\n protected registeredModuleMap: Partial<Record<Address, AttachableModuleInstance>> = {}\n\n private _attachMutex = new Mutex()\n\n private _attachedPrivateModules = new Set<Address>()\n private _attachedPublicModules = new Set<Address>()\n\n async attachHandler(id: ModuleIdentifier, external?: boolean) {\n await this.started('throw')\n return assertEx(\n isAddress(id) ? await this.attachUsingAddress(id as Address, external) : await this.attachUsingName(id, external),\n () => `Unable to locate module [${id}]`,\n )\n }\n\n async certifyHandler(id: ModuleIdentifier): Promise<ChildCertificationFields> {\n const child = (await this.publicChildren()).find(child => child.modName === id || child.address === id)\n if (child) {\n return { address: child.address, expiration: Date.now() + 1000 * 60 * 10 /* 10 minutes */ }\n }\n throw new Error(`Unable to certify child module [${id}]`)\n }\n\n async detachHandler(id: ModuleIdentifier) {\n await this.started('throw')\n return isAddress(id) ? await this.detachUsingAddress(id as Address) : await this.detachUsingName(id)\n }\n\n override async privateChildren(): Promise<ModuleInstance[]> {\n return [...(await this.attachedPrivateModules()), ...this.params.privateChildren ?? []]\n }\n\n override async publicChildren(): Promise<ModuleInstance[]> {\n return [...(await this.attachedPublicModules()), ...this.params.publicChildren ?? []]\n }\n\n async register(mod: AttachableModuleInstance) {\n await this.started('throw')\n if (this.registeredModuleMap[mod.address]) {\n if (this.registeredModuleMap[mod.address] === mod) {\n this.logger?.warn(`Module already registered at that address[${mod.address}]|${mod.id}|[${mod.config.schema}]`)\n } else {\n throw new Error(`Other module already registered at that address[${mod.address}]|${mod.id}|[${mod.config.schema}]`)\n }\n }\n this.registeredModuleMap[mod.address] = mod\n const args = { mod, name: mod.modName }\n await this.emit('moduleRegistered', args)\n }\n\n registeredHandler(): Promisable<Address[]> {\n return Promise.resolve(\n (Object.keys(this.registeredModuleMap) as Address[]).map((key) => {\n return key\n }),\n )\n }\n\n registeredModules(): AttachableModuleInstance[] {\n return Object.values(this.registeredModuleMap).map((value) => {\n return value\n }).filter(exists)\n }\n\n async unregister(mod: ModuleInstance): Promise<ModuleInstance> {\n await this.started('throw')\n // try to detach if it is attached\n try {\n await this.detach(mod.address)\n } catch {}\n delete this.registeredModuleMap[mod.address]\n const args = { mod, name: mod.modName }\n await this.emit('moduleUnregistered', args)\n return this\n }\n\n protected async attachUsingAddress(address: Address, external?: boolean) {\n return await this._attachMutex.runExclusive(async () => {\n const existingModule = await this.resolve(address)\n if (existingModule) {\n this.logger?.warn(`MemoryNode: Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n }\n const mod = assertEx(this.registeredModuleMap[address], () => `No Module Registered at address [${address}]`)\n\n if (this._attachedPublicModules.has(mod.address)) {\n this.logger?.warn(`Module [${mod.modName}] already attached at [${address}] (public)`)\n }\n if (this._attachedPrivateModules.has(mod.address)) {\n this.logger?.warn(`Module [${mod.modName}] already attached at [${address}] (private)`)\n }\n\n const notificationList = await this.getModulesToNotifyAbout(mod)\n\n // give it private access\n mod.upResolver.addResolver?.(this.privateResolver)\n\n // give it public access\n mod.upResolver.addResolver?.(this.downResolver as CompositeModuleResolver)\n\n // give it outside access\n mod.upResolver.addResolver?.(this.upResolver)\n\n if (external) {\n // expose it externally\n this._attachedPublicModules.add(mod.address)\n this.downResolver.addResolver(mod.downResolver as ModuleResolverInstance)\n } else {\n this._attachedPrivateModules.add(mod.address)\n this.privateResolver.addResolver(mod.downResolver as ModuleResolverInstance)\n }\n\n mod.addParent(this)\n\n const args = { mod, name: mod.modName }\n await this.emit('moduleAttached', args)\n\n if (isNodeModule(mod) && external) {\n const attachedListener: EventListener<TEventData['moduleAttached']> = async (args: TEventData['moduleAttached']) =>\n await this.emit('moduleAttached', args)\n\n const detachedListener: EventListener<TEventData['moduleDetached']> = async (args: TEventData['moduleDetached']) =>\n await this.emit('moduleDetached', args)\n\n mod.on('moduleAttached', attachedListener as EventListener)\n mod.on('moduleDetached', detachedListener as EventListener)\n }\n\n await this.notifyOfExistingModulesAttached(notificationList)\n\n return address\n })\n }\n\n protected async detachUsingAddress(address: Address) {\n const mod = assertEx(this.registeredModuleMap[address], () => `No Module Registered at address [${address}]`)\n\n const isAttachedPublic = this._attachedPublicModules.has(mod.address)\n const isAttachedPrivate = this._attachedPrivateModules.has(mod.address)\n\n assertEx(isAttachedPublic || isAttachedPrivate, () => `Module [${mod.modName}] not attached at [${address}]`)\n\n // remove inside access\n mod.upResolver?.removeResolver?.(this.privateResolver)\n\n // remove outside access\n mod.upResolver?.removeResolver?.(this.upResolver)\n\n // remove external exposure\n this.downResolver.removeResolver(mod.downResolver as ModuleResolverInstance)\n\n mod.removeParent(this.address)\n\n if (isAttachedPublic) {\n this._attachedPublicModules.delete(mod.address)\n }\n\n if (isAttachedPrivate) {\n this._attachedPrivateModules.delete(mod.address)\n }\n\n const args = { mod, name: mod.modName }\n await this.emit('moduleDetached', args)\n\n // notify of all sub node children detach\n if (isNodeModule(mod)) {\n const notificationList = await this.getModulesToNotifyAbout(mod)\n await this.notifyOfExistingModulesDetached(notificationList)\n }\n return address\n }\n\n protected override startHandler() {\n return super.startHandler()\n }\n\n private async attachUsingName(name: string, external?: boolean) {\n const address = this.registeredModuleAddressFromName(name)\n if (isDefined(address)) {\n return await this.attachUsingAddress(address, external)\n }\n }\n\n private async detachUsingName(name: string) {\n const address = this.registeredModuleAddressFromName(name)\n if (isDefined(address)) {\n return await this.detachUsingAddress(address)\n }\n }\n\n private async getModulesToNotifyAbout(node: ModuleInstance) {\n const notifiedAddresses: string[] = []\n // send attach events for all existing attached modules\n const childModules = await node.resolve('*', { direction: 'down' })\n return (\n childModules.map((child) => {\n // don't report self\n if (node.address === child.address) {\n return\n }\n\n // prevent loop\n if (notifiedAddresses.includes(child.address)) {\n return\n }\n\n notifiedAddresses.push(child.address)\n\n return child\n })\n ).filter(exists)\n }\n\n private async notifyOfExistingModulesAttached(childModules: Module[]) {\n await Promise.all(\n childModules.map(async (child) => {\n const args = { mod: child, name: child.modName }\n await this.emit('moduleAttached', args)\n }),\n )\n }\n\n private async notifyOfExistingModulesDetached(childModules: Module[]) {\n await Promise.all(\n childModules.map(async (child) => {\n const args = { mod: child, name: child.modName }\n await this.emit('moduleDetached', args)\n }),\n )\n }\n\n private registeredModuleAddressFromName(name: string) {\n return Object.values(this.registeredModuleMap).find((value) => {\n return value?.modName === name\n })?.address\n }\n}\n","import { NodeHelper } from '@xyo-network/node-abstract'\n\nimport { attachToExistingNode } from './attachToExistingNode.ts'\nimport { attachToNewNode } from './attachToNewNode.ts'\nimport {\n flatAttachAllToExistingNode, flatAttachChildToExistingNode, flatAttachToExistingNode,\n} from './flatAttachToExistingNode.ts'\nimport { flatAttachToNewNode } from './flatAttachToNewNode.ts'\n\nexport const MemoryNodeHelper = {\n ...NodeHelper,\n attachToExistingNode,\n attachToNewNode,\n flatAttachAllToExistingNode,\n flatAttachChildToExistingNode,\n flatAttachToExistingNode,\n flatAttachToNewNode,\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { ModuleIdentifier } from '@xyo-network/module-model'\nimport type { NodeInstance } from '@xyo-network/node-model'\nimport { asNodeInstance } from '@xyo-network/node-model'\n\nimport { MemoryNode } from '../MemoryNode.ts'\nimport { flatAttachToExistingNode } from './flatAttachToExistingNode.ts'\n\nexport const attachToExistingNode = async (source: NodeInstance, id: ModuleIdentifier, destination: NodeInstance): Promise<NodeInstance> => {\n const parts = id.split(':')\n const first = assertEx(parts.shift(), () => 'missing first part')\n if (parts.length === 0) {\n // this is an immediate child/children\n return await flatAttachToExistingNode(source, first, destination)\n } else {\n // all parts that are not the last should be nodes, build them and nest\n const firstModule = await source.resolve(first)\n const firstNode = asNodeInstance(firstModule, () => 'first part is not a node', { required: true })\n const newNode = await MemoryNode.create({ config: firstNode.config })\n await destination.register?.(newNode)\n await destination.attach(newNode.address, true)\n await attachToExistingNode(firstNode, parts.join(':'), newNode)\n return destination\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport type { ModuleIdentifier } from '@xyo-network/module-model'\nimport { asAttachableModuleInstance } from '@xyo-network/module-model'\nimport type { NodeInstance } from '@xyo-network/node-model'\n\nexport const flatAttachAllToExistingNode = async (source: NodeInstance, destination: NodeInstance): Promise<NodeInstance> => {\n const children = (await source.publicChildren()).map(child => asAttachableModuleInstance(child)).filter(exists)\n await Promise.all(\n children.map(async (child) => {\n await destination.register?.(child)\n await destination.attach(child.address, true)\n }),\n )\n return destination\n}\n\nexport const flatAttachChildToExistingNode = async (source: NodeInstance, id: ModuleIdentifier, destination: NodeInstance): Promise<NodeInstance> => {\n assertEx(id !== '*', () => '* is not a single child')\n const child = assertEx(await source.resolve(id), () => `Module ${id} not found`)\n const attachableChild = asAttachableModuleInstance(child, () => `Module ${id} is not attachable`, { required: true })\n await destination.register?.(attachableChild)\n await destination.attach(child.address, true)\n return destination\n}\n\nexport const flatAttachToExistingNode = async (source: NodeInstance, id: ModuleIdentifier, destination: NodeInstance): Promise<NodeInstance> => {\n return id === '*' ? await flatAttachAllToExistingNode(source, destination) : flatAttachChildToExistingNode(source, id, destination)\n}\n","import type { ModuleIdentifier } from '@xyo-network/module-model'\nimport type { NodeInstance } from '@xyo-network/node-model'\nimport { NodeConfigSchema } from '@xyo-network/node-model'\n\nimport type { MemoryNodeParams } from '../MemoryNode.ts'\nimport { MemoryNode } from '../MemoryNode.ts'\nimport { attachToExistingNode } from './attachToExistingNode.ts'\n\nconst DEFAULT_NODE_PARAMS = { config: { schema: NodeConfigSchema }, name: 'MemoryNode' }\n\nexport const attachToNewNode = async (\n source: NodeInstance,\n id: ModuleIdentifier,\n destinationParams: MemoryNodeParams = DEFAULT_NODE_PARAMS,\n): Promise<NodeInstance> => {\n const destination = await MemoryNode.create(destinationParams)\n return await attachToExistingNode(source, id, destination)\n}\n","import type { ModuleIdentifier } from '@xyo-network/module-model'\nimport type { NodeInstance } from '@xyo-network/node-model'\n\nimport type { MemoryNodeParams } from '../MemoryNode.ts'\nimport { MemoryNode } from '../MemoryNode.ts'\nimport { flatAttachToExistingNode } from './flatAttachToExistingNode.ts'\n\nexport const flatAttachToNewNode = async (\n source: NodeInstance,\n id: ModuleIdentifier,\n destinationParams: MemoryNodeParams,\n): Promise<NodeInstance> => {\n const destination = await MemoryNode.create(destinationParams)\n return await flatAttachToExistingNode(source, id, destination)\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAEzB,SAAS,cAAc;AAEvB,SAAS,iBAAiB;AAE1B,SAAS,iBAAiB;AAC1B;AAAA,EAGE;AAAA,OAKK;AAEP,SAAS,oBAAoB;AAK7B,SAAS,oBAAoB;AAC7B,SAAS,aAAa;AAKf,IAAM,aAAN,cACG,aAAkC;AAAA,EAChC,sBAA0E,CAAC;AAAA,EAE7E,eAAe,IAAI,MAAM;AAAA,EAEzB,0BAA0B,oBAAI,IAAa;AAAA,EAC3C,yBAAyB,oBAAI,IAAa;AAAA,EAElD,MAAM,cAAc,IAAsB,UAAoB;AAC5D,UAAM,KAAK,QAAQ,OAAO;AAC1B,WAAO;AAAA,MACL,UAAU,EAAE,IAAI,MAAM,KAAK,mBAAmB,IAAe,QAAQ,IAAI,MAAM,KAAK,gBAAgB,IAAI,Q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A,IACA,sBAC0B;AAC1B,QAAM,cAAc,MAAM,WAAW,OAAO,iBAAiB;AAC7D,SAAO,MAAM,yBAAyB,QAAQ,IAAI,WAAW;AAC/D;;;AJLO,IAAM,mBAAmB;AAAA,EAC9B,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":["child","args","assertEx","assertEx","exists","assertEx"]}
@@ -1,10 +1,10 @@
1
1
  import type { Address } from '@xylabs/hex';
2
2
  import type { Promisable } from '@xylabs/promise';
3
- import type { AnyConfigSchema, AttachableModuleInstance, ModuleIdentifier, ModuleInstance } from '@xyo-network/module-model';
3
+ import { type AnyConfigSchema, type AttachableModuleInstance, type ModuleIdentifier, type ModuleInstance } from '@xyo-network/module-model';
4
4
  import { AbstractNode } from '@xyo-network/node-abstract';
5
- import type { AttachableNodeInstance, ChildCertificationFields, NodeConfig, NodeModuleEventData, NodeParams } from '@xyo-network/node-model';
5
+ import type { ChildCertificationFields, NodeConfig, NodeModuleEventData, NodeParams } from '@xyo-network/node-model';
6
6
  export type MemoryNodeParams = NodeParams<AnyConfigSchema<NodeConfig>>;
7
- export declare class MemoryNode<TParams extends MemoryNodeParams = MemoryNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData> extends AbstractNode<TParams, TEventData> implements AttachableNodeInstance<TParams, TEventData> {
7
+ export declare class MemoryNode<TParams extends MemoryNodeParams = MemoryNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData> extends AbstractNode<TParams, TEventData> {
8
8
  protected registeredModuleMap: Partial<Record<Address, AttachableModuleInstance>>;
9
9
  private _attachMutex;
10
10
  private _attachedPrivateModules;
@@ -20,7 +20,7 @@ export declare class MemoryNode<TParams extends MemoryNodeParams = MemoryNodePar
20
20
  unregister(mod: ModuleInstance): Promise<ModuleInstance>;
21
21
  protected attachUsingAddress(address: Address, external?: boolean): Promise<Lowercase<string>>;
22
22
  protected detachUsingAddress(address: Address): Promise<Lowercase<string>>;
23
- protected startHandler(): Promise<boolean>;
23
+ protected startHandler(): Promise<void>;
24
24
  private attachUsingName;
25
25
  private detachUsingName;
26
26
  private getModulesToNotifyAbout;
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryNode.d.ts","sourceRoot":"","sources":["../../src/MemoryNode.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EACV,eAAe,EACf,wBAAwB,EAExB,gBAAgB,EAChB,cAAc,EAEf,MAAM,2BAA2B,CAAA;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EACV,sBAAsB,EAAE,wBAAwB,EAChD,UAAU,EAAE,mBAAmB,EAAE,UAAU,EAC5C,MAAM,yBAAyB,CAAA;AAIhC,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAA;AAEtE,qBAAa,UAAU,CAAC,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,EAAE,UAAU,SAAS,mBAAmB,GAAG,mBAAmB,CACvI,SAAQ,YAAY,CAAC,OAAO,EAAE,UAAU,CACxC,YAAW,sBAAsB,CAAC,OAAO,EAAE,UAAU,CAAC;IACtD,SAAS,CAAC,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAK;IAEtF,OAAO,CAAC,YAAY,CAAc;IAElC,OAAO,CAAC,uBAAuB,CAAqB;IACpD,OAAO,CAAC,sBAAsB,CAAqB;IAE7C,aAAa,CAAC,EAAE,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,OAAO;IAQtD,cAAc,CAAC,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAQvE,aAAa,CAAC,EAAE,EAAE,gBAAgB;IAKzB,e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AmB,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAK;IAEtF,OAAO,CAAC,YAAY,CAAc;IAElC,OAAO,CAAC,uBAAuB,CAAqB;IACpD,OAAO,CAAC,sBAAsB,CAAqB;IAE7C,aAAa,CAAC,EAAE,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,OAAO;IAQtD,cAAc,CAAC,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAQvE,aAAa,CAAC,EAAE,EAAE,gBAAgB;IAKzB,eAAe,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAI5C,cAAc,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAIpD,QAAQ,CAAC,GAAG,EAAE,wBAAwB;IAc5C,iBAAiB,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;IAQ1C,iBAAiB,IAAI,wBAAwB,EAAE;IAMzC,UAAU,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;cAY9C,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO;cAyDvD,kBAAkB,CAAC,OAAO,EAAE,OAAO;cAsChC,YAAY;YAIjB,eAAe;YAOf,eAAe;YAOf,uBAAuB;YAuBvB,+BAA+B;YAS/B,+BAA+B;IAS7C,OAAO,CAAC,+BAA+B;CAKxC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/node-memory",
3
- "version": "3.18.10",
3
+ "version": "4.0.1",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -29,22 +29,22 @@
29
29
  "module": "dist/neutral/index.mjs",
30
30
  "types": "dist/types/index.d.ts",
31
31
  "dependencies": {
32
- "@xylabs/assert": "^4.11.21",
33
- "@xylabs/exists": "^4.11.21",
34
- "@xylabs/hex": "^4.11.21",
35
- "@xylabs/promise": "^4.11.21",
36
- "@xylabs/typeof": "^4.11.21",
37
- "@xyo-network/module-model": "^3.18.10",
38
- "@xyo-network/node-abstract": "^3.18.10",
39
- "@xyo-network/node-model": "^3.18.10",
32
+ "@xylabs/assert": "^4.12.30",
33
+ "@xylabs/exists": "^4.12.30",
34
+ "@xylabs/hex": "^4.12.30",
35
+ "@xylabs/promise": "^4.12.30",
36
+ "@xylabs/typeof": "^4.12.30",
37
+ "@xyo-network/module-model": "^4.0.1",
38
+ "@xyo-network/node-abstract": "^4.0.1",
39
+ "@xyo-network/node-model": "^4.0.1",
40
40
  "async-mutex": "^0.5.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@xylabs/events": "^4.11.21",
44
- "@xylabs/ts-scripts-yarn3": "^6.5.8",
45
- "@xylabs/tsconfig": "^6.5.8",
46
- "@xyo-network/module-events": "^3.18.10",
47
- "@xyo-network/module-resolver": "^3.18.10",
43
+ "@xylabs/events": "^4.12.30",
44
+ "@xylabs/ts-scripts-yarn3": "^6.5.12",
45
+ "@xylabs/tsconfig": "^6.5.12",
46
+ "@xyo-network/module-events": "^4.0.1",
47
+ "@xyo-network/module-resolver": "^4.0.1",
48
48
  "typescript": "^5.8.3"
49
49
  },
50
50
  "publishConfig": {
package/src/MemoryNode.ts CHANGED
@@ -5,18 +5,19 @@ import type { Address } from '@xylabs/hex'
5
5
  import { isAddress } from '@xylabs/hex'
6
6
  import type { Promisable } from '@xylabs/promise'
7
7
  import { isDefined } from '@xylabs/typeof'
8
- import type {
9
- AnyConfigSchema,
10
- AttachableModuleInstance,
11
- Module,
12
- ModuleIdentifier,
13
- ModuleInstance,
14
- ModuleResolverInstance,
8
+ import {
9
+ type AnyConfigSchema,
10
+ type AttachableModuleInstance,
11
+ creatableModule,
12
+ type Module,
13
+ type ModuleIdentifier,
14
+ type ModuleInstance,
15
+ type ModuleResolverInstance,
15
16
  } from '@xyo-network/module-model'
16
17
  import type { CompositeModuleResolver } from '@xyo-network/module-resolver'
17
18
  import { AbstractNode } from '@xyo-network/node-abstract'
18
19
  import type {
19
- AttachableNodeInstance, ChildCertificationFields,
20
+ ChildCertificationFields,
20
21
  NodeConfig, NodeModuleEventData, NodeParams,
21
22
  } from '@xyo-network/node-model'
22
23
  import { isNodeModule } from '@xyo-network/node-model'
@@ -24,9 +25,9 @@ import { Mutex } from 'async-mutex'
24
25
 
25
26
  export type MemoryNodeParams = NodeParams<AnyConfigSchema<NodeConfig>>
26
27
 
28
+ @creatableModule()
27
29
  export class MemoryNode<TParams extends MemoryNodeParams = MemoryNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>
28
- extends AbstractNode<TParams, TEventData>
29
- implements AttachableNodeInstance<TParams, TEventData> {
30
+ extends AbstractNode<TParams, TEventData> {
30
31
  protected registeredModuleMap: Partial<Record<Address, AttachableModuleInstance>> = {}
31
32
 
32
33
  private _attachMutex = new Mutex()
@@ -15,7 +15,7 @@ export const attachToExistingNode = async (source: NodeInstance, id: ModuleIdent
15
15
  } else {
16
16
  // all parts that are not the last should be nodes, build them and nest
17
17
  const firstModule = await source.resolve(first)
18
- const firstNode = asNodeInstance(firstModule, () => 'first part is not a node')
18
+ const firstNode = asNodeInstance(firstModule, () => 'first part is not a node', { required: true })
19
19
  const newNode = await MemoryNode.create({ config: firstNode.config })
20
20
  await destination.register?.(newNode)
21
21
  await destination.attach(newNode.address, true)
@@ -6,7 +6,7 @@ import type { MemoryNodeParams } from '../MemoryNode.ts'
6
6
  import { MemoryNode } from '../MemoryNode.ts'
7
7
  import { attachToExistingNode } from './attachToExistingNode.ts'
8
8
 
9
- const DEFAULT_NODE_PARAMS = { config: { schema: NodeConfigSchema } }
9
+ const DEFAULT_NODE_PARAMS = { config: { schema: NodeConfigSchema }, name: 'MemoryNode' }
10
10
 
11
11
  export const attachToNewNode = async (
12
12
  source: NodeInstance,
@@ -18,7 +18,7 @@ export const flatAttachAllToExistingNode = async (source: NodeInstance, destinat
18
18
  export const flatAttachChildToExistingNode = async (source: NodeInstance, id: ModuleIdentifier, destination: NodeInstance): Promise<NodeInstance> => {
19
19
  assertEx(id !== '*', () => '* is not a single child')
20
20
  const child = assertEx(await source.resolve(id), () => `Module ${id} not found`)
21
- const attachableChild = asAttachableModuleInstance(child, () => `Module ${id} is not attachable`)
21
+ const attachableChild = asAttachableModuleInstance(child, () => `Module ${id} is not attachable`, { required: true })
22
22
  await destination.register?.(attachableChild)
23
23
  await destination.attach(child.address, true)
24
24
  return destination