@xyo-network/node-view 2.107.6 → 2.109.0
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/dist/browser/index.cjs +13 -13
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +13 -13
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/index.cjs +13 -13
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +13 -13
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/index.cjs +13 -13
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +13 -13
- package/dist/node/index.js.map +1 -1
- package/package.json +8 -8
- package/src/ViewNode.ts +10 -10
package/dist/browser/index.cjs
CHANGED
|
@@ -105,31 +105,31 @@ var ViewNode = class extends import_node_memory.MemoryNode {
|
|
|
105
105
|
}
|
|
106
106
|
async attachUsingAddress(address) {
|
|
107
107
|
const attached = await this.attached();
|
|
108
|
-
const mods = this.registeredModules().filter((
|
|
109
|
-
const existingModule = mods.find((
|
|
108
|
+
const mods = this.registeredModules().filter((mod2) => attached.includes(mod2.address));
|
|
109
|
+
const existingModule = mods.find((mod2) => mod2.address === address);
|
|
110
110
|
(0, import_assert.assertEx)(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`);
|
|
111
|
-
const
|
|
112
|
-
|
|
111
|
+
const mod = (0, import_assert.assertEx)(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`);
|
|
112
|
+
mod.addParent(this);
|
|
113
113
|
const args = {
|
|
114
|
-
|
|
115
|
-
name:
|
|
114
|
+
mod,
|
|
115
|
+
name: mod.modName
|
|
116
116
|
};
|
|
117
117
|
await this.emit("moduleAttached", args);
|
|
118
|
-
this._limitedResolver.add(
|
|
119
|
-
if ((0, import_node_model.isNodeModule)(
|
|
118
|
+
this._limitedResolver.add(mod);
|
|
119
|
+
if ((0, import_node_model.isNodeModule)(mod)) {
|
|
120
120
|
const attachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleAttached", args2), "attachedListener");
|
|
121
121
|
const detachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleDetached", args2), "detachedListener");
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
mod.on("moduleAttached", attachedListener);
|
|
123
|
+
mod.on("moduleDetached", detachedListener);
|
|
124
124
|
}
|
|
125
125
|
return address;
|
|
126
126
|
}
|
|
127
127
|
async attachedPublicModules() {
|
|
128
|
-
return (await this._limitedResolver.resolve("*")).filter((
|
|
128
|
+
return (await this._limitedResolver.resolve("*")).filter((mod) => mod.address !== this.address);
|
|
129
129
|
}
|
|
130
130
|
async detachUsingAddress(address) {
|
|
131
|
-
const
|
|
132
|
-
this._limitedResolver.remove(
|
|
131
|
+
const mod = (0, import_assert.assertEx)(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`);
|
|
132
|
+
this._limitedResolver.remove(mod.address);
|
|
133
133
|
return address;
|
|
134
134
|
}
|
|
135
135
|
async startHandler() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/ViewNode.ts"],"sourcesContent":["export * from './ViewNode'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/ViewNode.ts"],"sourcesContent":["export * from './ViewNode'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const mod = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`)\n\n mod.addParent(this)\n\n const args = { mod, name: mod.modName }\n await this.emit('moduleAttached', args)\n\n this._limitedResolver.add(mod)\n\n if (isNodeModule(mod)) {\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)\n mod.on('moduleDetached', detachedListener)\n }\n\n return address\n }\n\n protected override async attachedPublicModules(): Promise<ModuleInstance[]> {\n return (await this._limitedResolver.resolve('*')).filter((mod) => mod.address !== this.address)\n }\n\n protected override async detachUsingAddress(address: Address) {\n const mod = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`)\n this._limitedResolver.remove(mod.address)\n return address\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n await this.build()\n return true\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AAGvB,0BASO;AACP,6BAAqC;AACrC,yBAA6C;AAC7C,wBAUO;AAEP,yBAAsB;AAEf,IAAMA,uBAAuB;AAa7B,IAAMC,WAAN,cACGC,8BAAAA;EA5CV,OA4CUA;;;EAGR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeH;;EAC5E,OAAyBI,sBAA8BJ;EACvD,OAAyBK,SAAS;IAAE,GAAGC;EAA0B;EAEzDC,cAAc,IAAIC,yBAAAA;EAClBC,SAAS;EACTC,mBAAmB,IAAIC,4CAAqB;IAAEC,MAAM;EAAK,CAAA;EAEjE,IAAIC,MAAM;AACR,WAAO,KAAKC,OAAOD;EACrB;EAEA,IAAaE,UAAoB;AAC/B,UAAMC,oBAAoB,oBAAIC,IAAY;MAACC;MAAuBC;MAAuBC;KAA0B;AACnH,UAAML,UAAoB;SAAI,MAAMA;;AACpC,WAAOA,QAAQM,OAAO,CAACC,UAAU,CAACN,kBAAkBO,IAAID,KAAAA,CAAAA;EAC1D;EAEA,IAAIE,SAAS;AACX,WAAO,KAAKV,OAAOU;EACrB;EAEA,MAAMC,QAAQ;AACZ,WAAO,MAAM,KAAKlB,YAAYmB,aAAa,YAAA;AACzC,YAAMF,aAASG,kCAAe,MAAM,MAAMC,QAAQ,KAAKJ,MAAM,CAAA;AAC7D,UAAIA,QAAQ;AACV,cAAMK,QAAQC,IACZ,KAAKjB,IAAIkB,IAAI,OAAOC,OAAAA;AAClB,gBAAMC,oCAAiBC,qBAAqBV,QAAQQ,IAAI,IAAI;QAC9D,CAAA,CAAA;AAEF,aAAKvB,SAAS;MAChB;IACF,CAAA;EACF;EAOA,MAAemB,QACbO,aAAiD,KACjDC,UAAkC,CAAC,GACL;AAC9B,QAAI,CAAC,KAAK3B,QAAQ;AACh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AkBD,IAAAA;AAElC,SAAK5C,iBAAiB8C,IAAIlB,GAAAA;AAE1B,YAAImB,gCAAanB,GAAAA,GAAM;AACrB,YAAMoB,mBAAgE,8BAAOJ,UAC3E,MAAM,KAAKC,KAAK,kBAAkBD,KAAAA,GADkC;AAGtE,YAAMK,mBAAgE,8BAAOL,UAC3E,MAAM,KAAKC,KAAK,kBAAkBD,KAAAA,GADkC;AAGtEhB,UAAIsB,GAAG,kBAAkBF,gBAAAA;AACzBpB,UAAIsB,GAAG,kBAAkBD,gBAAAA;IAC3B;AAEA,WAAOlB;EACT;EAEA,MAAyBoB,wBAAmD;AAC1E,YAAQ,MAAM,KAAKnD,iBAAiBkB,QAAQ,GAAA,GAAMP,OAAO,CAACiB,QAAQA,IAAIG,YAAY,KAAKA,OAAO;EAChG;EAEA,MAAyBqB,mBAAmBrB,SAAkB;AAC5D,UAAMH,UAAMa,wBAAS,MAAM,KAAKY,aAAanC,QAAQa,OAAAA,GAAU,MAAM,WAAWA,OAAAA,8BAAqC;AACrH,SAAK/B,iBAAiBsD,OAAO1B,IAAIG,OAAO;AACxC,WAAOA;EACT;EAEA,MAAyBwB,eAAiC;AACxD,UAAM,MAAMA,aAAAA;AACZ,UAAM,KAAKxC,MAAK;AAChB,WAAO;EACT;AACF;","names":["ViewNodeConfigSchema","ViewNode","MemoryNode","configSchemas","defaultConfigSchema","labels","ModuleLimitationViewLabel","_buildMutex","Mutex","_built","_limitedResolver","SimpleModuleResolver","root","ids","config","queries","disallowedQueries","Set","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","filter","query","has","source","build","runExclusive","asNodeInstance","resolve","Promise","all","map","id","MemoryNodeHelper","attachToExistingNode","idOrFilter","options","mods","mod","find","modName","address","isAddressModuleFilter","exists","isNameModuleFilter","name","attachUsingAddress","attached","registeredModules","includes","existingModule","assertEx","registeredModuleMap","addParent","args","emit","add","isNodeModule","attachedListener","detachedListener","on","attachedPublicModules","detachUsingAddress","downResolver","remove","startHandler"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -80,31 +80,31 @@ var ViewNode = class extends MemoryNode {
|
|
|
80
80
|
}
|
|
81
81
|
async attachUsingAddress(address) {
|
|
82
82
|
const attached = await this.attached();
|
|
83
|
-
const mods = this.registeredModules().filter((
|
|
84
|
-
const existingModule = mods.find((
|
|
83
|
+
const mods = this.registeredModules().filter((mod2) => attached.includes(mod2.address));
|
|
84
|
+
const existingModule = mods.find((mod2) => mod2.address === address);
|
|
85
85
|
assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`);
|
|
86
|
-
const
|
|
87
|
-
|
|
86
|
+
const mod = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`);
|
|
87
|
+
mod.addParent(this);
|
|
88
88
|
const args = {
|
|
89
|
-
|
|
90
|
-
name:
|
|
89
|
+
mod,
|
|
90
|
+
name: mod.modName
|
|
91
91
|
};
|
|
92
92
|
await this.emit("moduleAttached", args);
|
|
93
|
-
this._limitedResolver.add(
|
|
94
|
-
if (isNodeModule(
|
|
93
|
+
this._limitedResolver.add(mod);
|
|
94
|
+
if (isNodeModule(mod)) {
|
|
95
95
|
const attachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleAttached", args2), "attachedListener");
|
|
96
96
|
const detachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleDetached", args2), "detachedListener");
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
mod.on("moduleAttached", attachedListener);
|
|
98
|
+
mod.on("moduleDetached", detachedListener);
|
|
99
99
|
}
|
|
100
100
|
return address;
|
|
101
101
|
}
|
|
102
102
|
async attachedPublicModules() {
|
|
103
|
-
return (await this._limitedResolver.resolve("*")).filter((
|
|
103
|
+
return (await this._limitedResolver.resolve("*")).filter((mod) => mod.address !== this.address);
|
|
104
104
|
}
|
|
105
105
|
async detachUsingAddress(address) {
|
|
106
|
-
const
|
|
107
|
-
this._limitedResolver.remove(
|
|
106
|
+
const mod = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`);
|
|
107
|
+
this._limitedResolver.remove(mod.address);
|
|
108
108
|
return address;
|
|
109
109
|
}
|
|
110
110
|
async startHandler() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ViewNode.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const module = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered modules`)\n\n module.addParent(this)\n\n const args = { module, name: module.modName }\n await this.emit('moduleAttached', args)\n\n this._limitedResolver.add(module)\n\n if (isNodeModule(module)) {\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 module.on('moduleAttached', attachedListener)\n module.on('moduleDetached', detachedListener)\n }\n\n return address\n }\n\n protected override async attachedPublicModules(): Promise<ModuleInstance[]> {\n return (await this._limitedResolver.resolve('*')).filter((module) => module.address !== this.address)\n }\n\n protected override async detachUsingAddress(address: Address) {\n const module = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`)\n this._limitedResolver.remove(module.address)\n return address\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n await this.build()\n return true\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AAGvB,SAEEC,uBACAC,oBAKAC,iCACK;AACP,SAASC,4BAA4B;AACrC,SAASC,YAAYC,wBAAwB;AAC7C,SACEC,gBAEAC,cACAC,uBAEAC,uBAGAC,iCACK;AAEP,SAASC,aAAa;AAEf,IAAMC,uBAAuB;AAa7B,IAAMC,WAAN,cACGC,WAAAA;EA5CV,OA4CUA;;;EAGR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeH;;EAC5E,OAAyBI,sBAA8BJ;EACvD,OAAyBK,SAAS;IAAE,GAAGC;EAA0B;EAEzDC,cAAc,IAAIC,MAAAA;EAClBC,SAAS;EACTC,mBAAmB,IAAIC,qBAAqB;IAAEC,MAA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;EAEA,MAAyBsB,mBAAmBtB,SAAkB;AAC5D,UAAMW,SAASD,SAAS,MAAM,KAAKa,aAAapC,QAAQa,OAAAA,GAAU,MAAM,WAAWA,OAAAA,8BAAqC;AACxH,SAAK/B,iBAAiBuD,OAAOb,OAAOX,OAAO;AAC3C,WAAOA;EACT;EAEA,MAAyByB,eAAiC;AACxD,UAAM,MAAMA,aAAAA;AACZ,UAAM,KAAKzC,MAAK;AAChB,WAAO;EACT;AACF;","names":["assertEx","exists","isAddressModuleFilter","isNameModuleFilter","ModuleLimitationViewLabel","SimpleModuleResolver","MemoryNode","MemoryNodeHelper","asNodeInstance","isNodeModule","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","Mutex","ViewNodeConfigSchema","ViewNode","MemoryNode","configSchemas","defaultConfigSchema","labels","ModuleLimitationViewLabel","_buildMutex","Mutex","_built","_limitedResolver","SimpleModuleResolver","root","ids","config","queries","disallowedQueries","Set","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","filter","query","has","source","build","runExclusive","asNodeInstance","resolve","Promise","all","map","id","MemoryNodeHelper","attachToExistingNode","idOrFilter","options","mods","mod","find","modName","address","isAddressModuleFilter","exists","isNameModuleFilter","name","attachUsingAddress","attached","registeredModules","includes","existingModule","assertEx","module","registeredModuleMap","addParent","args","emit","add","isNodeModule","attachedListener","detachedListener","on","attachedPublicModules","detachUsingAddress","downResolver","remove","startHandler"]}
|
|
1
|
+
{"version":3,"sources":["../../src/ViewNode.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const mod = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`)\n\n mod.addParent(this)\n\n const args = { mod, name: mod.modName }\n await this.emit('moduleAttached', args)\n\n this._limitedResolver.add(mod)\n\n if (isNodeModule(mod)) {\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)\n mod.on('moduleDetached', detachedListener)\n }\n\n return address\n }\n\n protected override async attachedPublicModules(): Promise<ModuleInstance[]> {\n return (await this._limitedResolver.resolve('*')).filter((mod) => mod.address !== this.address)\n }\n\n protected override async detachUsingAddress(address: Address) {\n const mod = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`)\n this._limitedResolver.remove(mod.address)\n return address\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n await this.build()\n return true\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AAGvB,SAEEC,uBACAC,oBAKAC,iCACK;AACP,SAASC,4BAA4B;AACrC,SAASC,YAAYC,wBAAwB;AAC7C,SACEC,gBAEAC,cACAC,uBAEAC,uBAGAC,iCACK;AAEP,SAASC,aAAa;AAEf,IAAMC,uBAAuB;AAa7B,IAAMC,WAAN,cACGC,WAAAA;EA5CV,OA4CUA;;;EAGR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeH;;EAC5E,OAAyBI,sBAA8BJ;EACvD,OAAyBK,SAAS;IAAE,GAAGC;EAA0B;EAEzDC,cAAc,IAAIC,MAAAA;EAClBC,SAAS;EACTC,mBAAmB,IAAIC,qBAAqB;IAAEC,MAAM;EAAK,CAAA;EAEjE,IAAIC,MAAM;AACR,WAAO,KAAKC,OAAOD;EACrB;EAEA,IAAaE,UAAoB;AAC/B,UAAMC,oBAAoB,oBAAIC,IAAY;MAACC;MAAuBC;MAAuBC;KAA0B;AACnH,UAAML,UAAoB;SAAI,MAAMA;;AACpC,WAAOA,QAAQM,OAAO,CAACC,UAAU,CAACN,kBAAkBO,IAAID,KAAAA,CAAAA;EAC1D;EAEA,IAAIE,SAAS;AACX,WAAO,KAAKV,OAAOU;EACrB;EAEA,MAAMC,QAAQ;AACZ,WAAO,MAAM,KAAKlB,YAAYmB,aAAa,YAAA;AACzC,YAAMF,SAASG,eAAe,MAAM,MAAMC,QAAQ,KAAKJ,MAAM,CAAA;AAC7D,UAAIA,QAAQ;A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AAWA,gBAAgBV,WAAWU,gBAAgBT,OAAAA,kCAAyCA,OAAAA,GAAU;AACzI,UAAMH,MAAMa,SAAS,KAAKC,oBAAoBX,OAAAA,GAAU,MAAM,WAAWA,OAAAA,gCAAuC;AAEhHH,QAAIe,UAAU,IAAI;AAElB,UAAMC,OAAO;MAAEhB;MAAKO,MAAMP,IAAIE;IAAQ;AACtC,UAAM,KAAKe,KAAK,kBAAkBD,IAAAA;AAElC,SAAK5C,iBAAiB8C,IAAIlB,GAAAA;AAE1B,QAAImB,aAAanB,GAAAA,GAAM;AACrB,YAAMoB,mBAAgE,8BAAOJ,UAC3E,MAAM,KAAKC,KAAK,kBAAkBD,KAAAA,GADkC;AAGtE,YAAMK,mBAAgE,8BAAOL,UAC3E,MAAM,KAAKC,KAAK,kBAAkBD,KAAAA,GADkC;AAGtEhB,UAAIsB,GAAG,kBAAkBF,gBAAAA;AACzBpB,UAAIsB,GAAG,kBAAkBD,gBAAAA;IAC3B;AAEA,WAAOlB;EACT;EAEA,MAAyBoB,wBAAmD;AAC1E,YAAQ,MAAM,KAAKnD,iBAAiBkB,QAAQ,GAAA,GAAMP,OAAO,CAACiB,QAAQA,IAAIG,YAAY,KAAKA,OAAO;EAChG;EAEA,MAAyBqB,mBAAmBrB,SAAkB;AAC5D,UAAMH,MAAMa,SAAS,MAAM,KAAKY,aAAanC,QAAQa,OAAAA,GAAU,MAAM,WAAWA,OAAAA,8BAAqC;AACrH,SAAK/B,iBAAiBsD,OAAO1B,IAAIG,OAAO;AACxC,WAAOA;EACT;EAEA,MAAyBwB,eAAiC;AACxD,UAAM,MAAMA,aAAAA;AACZ,UAAM,KAAKxC,MAAK;AAChB,WAAO;EACT;AACF;","names":["assertEx","exists","isAddressModuleFilter","isNameModuleFilter","ModuleLimitationViewLabel","SimpleModuleResolver","MemoryNode","MemoryNodeHelper","asNodeInstance","isNodeModule","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","Mutex","ViewNodeConfigSchema","ViewNode","MemoryNode","configSchemas","defaultConfigSchema","labels","ModuleLimitationViewLabel","_buildMutex","Mutex","_built","_limitedResolver","SimpleModuleResolver","root","ids","config","queries","disallowedQueries","Set","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","filter","query","has","source","build","runExclusive","asNodeInstance","resolve","Promise","all","map","id","MemoryNodeHelper","attachToExistingNode","idOrFilter","options","mods","mod","find","modName","address","isAddressModuleFilter","exists","isNameModuleFilter","name","attachUsingAddress","attached","registeredModules","includes","existingModule","assertEx","registeredModuleMap","addParent","args","emit","add","isNodeModule","attachedListener","detachedListener","on","attachedPublicModules","detachUsingAddress","downResolver","remove","startHandler"]}
|
package/dist/neutral/index.cjs
CHANGED
|
@@ -105,31 +105,31 @@ var ViewNode = class extends import_node_memory.MemoryNode {
|
|
|
105
105
|
}
|
|
106
106
|
async attachUsingAddress(address) {
|
|
107
107
|
const attached = await this.attached();
|
|
108
|
-
const mods = this.registeredModules().filter((
|
|
109
|
-
const existingModule = mods.find((
|
|
108
|
+
const mods = this.registeredModules().filter((mod2) => attached.includes(mod2.address));
|
|
109
|
+
const existingModule = mods.find((mod2) => mod2.address === address);
|
|
110
110
|
(0, import_assert.assertEx)(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`);
|
|
111
|
-
const
|
|
112
|
-
|
|
111
|
+
const mod = (0, import_assert.assertEx)(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`);
|
|
112
|
+
mod.addParent(this);
|
|
113
113
|
const args = {
|
|
114
|
-
|
|
115
|
-
name:
|
|
114
|
+
mod,
|
|
115
|
+
name: mod.modName
|
|
116
116
|
};
|
|
117
117
|
await this.emit("moduleAttached", args);
|
|
118
|
-
this._limitedResolver.add(
|
|
119
|
-
if ((0, import_node_model.isNodeModule)(
|
|
118
|
+
this._limitedResolver.add(mod);
|
|
119
|
+
if ((0, import_node_model.isNodeModule)(mod)) {
|
|
120
120
|
const attachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleAttached", args2), "attachedListener");
|
|
121
121
|
const detachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleDetached", args2), "detachedListener");
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
mod.on("moduleAttached", attachedListener);
|
|
123
|
+
mod.on("moduleDetached", detachedListener);
|
|
124
124
|
}
|
|
125
125
|
return address;
|
|
126
126
|
}
|
|
127
127
|
async attachedPublicModules() {
|
|
128
|
-
return (await this._limitedResolver.resolve("*")).filter((
|
|
128
|
+
return (await this._limitedResolver.resolve("*")).filter((mod) => mod.address !== this.address);
|
|
129
129
|
}
|
|
130
130
|
async detachUsingAddress(address) {
|
|
131
|
-
const
|
|
132
|
-
this._limitedResolver.remove(
|
|
131
|
+
const mod = (0, import_assert.assertEx)(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`);
|
|
132
|
+
this._limitedResolver.remove(mod.address);
|
|
133
133
|
return address;
|
|
134
134
|
}
|
|
135
135
|
async startHandler() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/ViewNode.ts"],"sourcesContent":["export * from './ViewNode'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/ViewNode.ts"],"sourcesContent":["export * from './ViewNode'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const mod = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`)\n\n mod.addParent(this)\n\n const args = { mod, name: mod.modName }\n await this.emit('moduleAttached', args)\n\n this._limitedResolver.add(mod)\n\n if (isNodeModule(mod)) {\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)\n mod.on('moduleDetached', detachedListener)\n }\n\n return address\n }\n\n protected override async attachedPublicModules(): Promise<ModuleInstance[]> {\n return (await this._limitedResolver.resolve('*')).filter((mod) => mod.address !== this.address)\n }\n\n protected override async detachUsingAddress(address: Address) {\n const mod = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`)\n this._limitedResolver.remove(mod.address)\n return address\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n await this.build()\n return true\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AAGvB,0BASO;AACP,6BAAqC;AACrC,yBAA6C;AAC7C,wBAUO;AAEP,yBAAsB;AAEf,IAAMA,uBAAuB;AAa7B,IAAMC,WAAN,cACGC,8BAAAA;EA5CV,OA4CUA;;;EAGR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeH;;EAC5E,OAAyBI,sBAA8BJ;EACvD,OAAyBK,SAAS;IAAE,GAAGC;EAA0B;EAEzDC,cAAc,IAAIC,yBAAAA;EAClBC,SAAS;EACTC,mBAAmB,IAAIC,4CAAqB;IAAEC,MAAM;EAAK,CAAA;EAEjE,IAAIC,MAAM;AACR,WAAO,KAAKC,OAAOD;EACrB;EAEA,IAAaE,UAAoB;AAC/B,UAAMC,oBAAoB,oBAAIC,IAAY;MAACC;MAAuBC;MAAuBC;KAA0B;AACnH,UAAML,UAAoB;SAAI,MAAMA;;AACpC,WAAOA,QAAQM,OAAO,CAACC,UAAU,CAACN,kBAAkBO,IAAID,KAAAA,CAAAA;EAC1D;EAEA,IAAIE,SAAS;AACX,WAAO,KAAKV,OAAOU;EACrB;EAEA,MAAMC,QAAQ;AACZ,WAAO,MAAM,KAAKlB,YAAYmB,aAAa,YAAA;AACzC,YAAMF,aAASG,kCAAe,MAAM,MAAMC,QAAQ,KAAKJ,MAAM,CAAA;AAC7D,UAAIA,QAAQ;AACV,cAAMK,QAAQC,IACZ,KAAKjB,IAAIkB,IAAI,OAAOC,OAAAA;AAClB,gBAAMC,oCAAiBC,qBAAqBV,QAAQQ,IAAI,IAAI;QAC9D,CAAA,CAAA;AAEF,aAAKvB,SAAS;MAChB;IACF,CAAA;EACF;EAOA,MAAemB,QACbO,aAAiD,KACjDC,UAAkC,CAAC,GACL;AAC9B,QAAI,CAAC,KAAK3B,QAAQ;AAChB,YAAM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AAAA;AAElC,SAAK5C,iBAAiB8C,IAAIlB,GAAAA;AAE1B,YAAImB,gCAAanB,GAAAA,GAAM;AACrB,YAAMoB,mBAAgE,8BAAOJ,UAC3E,MAAM,KAAKC,KAAK,kBAAkBD,KAAAA,GADkC;AAGtE,YAAMK,mBAAgE,8BAAOL,UAC3E,MAAM,KAAKC,KAAK,kBAAkBD,KAAAA,GADkC;AAGtEhB,UAAIsB,GAAG,kBAAkBF,gBAAAA;AACzBpB,UAAIsB,GAAG,kBAAkBD,gBAAAA;IAC3B;AAEA,WAAOlB;EACT;EAEA,MAAyBoB,wBAAmD;AAC1E,YAAQ,MAAM,KAAKnD,iBAAiBkB,QAAQ,GAAA,GAAMP,OAAO,CAACiB,QAAQA,IAAIG,YAAY,KAAKA,OAAO;EAChG;EAEA,MAAyBqB,mBAAmBrB,SAAkB;AAC5D,UAAMH,UAAMa,wBAAS,MAAM,KAAKY,aAAanC,QAAQa,OAAAA,GAAU,MAAM,WAAWA,OAAAA,8BAAqC;AACrH,SAAK/B,iBAAiBsD,OAAO1B,IAAIG,OAAO;AACxC,WAAOA;EACT;EAEA,MAAyBwB,eAAiC;AACxD,UAAM,MAAMA,aAAAA;AACZ,UAAM,KAAKxC,MAAK;AAChB,WAAO;EACT;AACF;","names":["ViewNodeConfigSchema","ViewNode","MemoryNode","configSchemas","defaultConfigSchema","labels","ModuleLimitationViewLabel","_buildMutex","Mutex","_built","_limitedResolver","SimpleModuleResolver","root","ids","config","queries","disallowedQueries","Set","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","filter","query","has","source","build","runExclusive","asNodeInstance","resolve","Promise","all","map","id","MemoryNodeHelper","attachToExistingNode","idOrFilter","options","mods","mod","find","modName","address","isAddressModuleFilter","exists","isNameModuleFilter","name","attachUsingAddress","attached","registeredModules","includes","existingModule","assertEx","registeredModuleMap","addParent","args","emit","add","isNodeModule","attachedListener","detachedListener","on","attachedPublicModules","detachUsingAddress","downResolver","remove","startHandler"]}
|
package/dist/neutral/index.js
CHANGED
|
@@ -80,31 +80,31 @@ var ViewNode = class extends MemoryNode {
|
|
|
80
80
|
}
|
|
81
81
|
async attachUsingAddress(address) {
|
|
82
82
|
const attached = await this.attached();
|
|
83
|
-
const mods = this.registeredModules().filter((
|
|
84
|
-
const existingModule = mods.find((
|
|
83
|
+
const mods = this.registeredModules().filter((mod2) => attached.includes(mod2.address));
|
|
84
|
+
const existingModule = mods.find((mod2) => mod2.address === address);
|
|
85
85
|
assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`);
|
|
86
|
-
const
|
|
87
|
-
|
|
86
|
+
const mod = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`);
|
|
87
|
+
mod.addParent(this);
|
|
88
88
|
const args = {
|
|
89
|
-
|
|
90
|
-
name:
|
|
89
|
+
mod,
|
|
90
|
+
name: mod.modName
|
|
91
91
|
};
|
|
92
92
|
await this.emit("moduleAttached", args);
|
|
93
|
-
this._limitedResolver.add(
|
|
94
|
-
if (isNodeModule(
|
|
93
|
+
this._limitedResolver.add(mod);
|
|
94
|
+
if (isNodeModule(mod)) {
|
|
95
95
|
const attachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleAttached", args2), "attachedListener");
|
|
96
96
|
const detachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleDetached", args2), "detachedListener");
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
mod.on("moduleAttached", attachedListener);
|
|
98
|
+
mod.on("moduleDetached", detachedListener);
|
|
99
99
|
}
|
|
100
100
|
return address;
|
|
101
101
|
}
|
|
102
102
|
async attachedPublicModules() {
|
|
103
|
-
return (await this._limitedResolver.resolve("*")).filter((
|
|
103
|
+
return (await this._limitedResolver.resolve("*")).filter((mod) => mod.address !== this.address);
|
|
104
104
|
}
|
|
105
105
|
async detachUsingAddress(address) {
|
|
106
|
-
const
|
|
107
|
-
this._limitedResolver.remove(
|
|
106
|
+
const mod = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`);
|
|
107
|
+
this._limitedResolver.remove(mod.address);
|
|
108
108
|
return address;
|
|
109
109
|
}
|
|
110
110
|
async startHandler() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ViewNode.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const module = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered modules`)\n\n module.addParent(this)\n\n const args = { module, name: module.modName }\n await this.emit('moduleAttached', args)\n\n this._limitedResolver.add(module)\n\n if (isNodeModule(module)) {\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 module.on('moduleAttached', attachedListener)\n module.on('moduleDetached', detachedListener)\n }\n\n return address\n }\n\n protected override async attachedPublicModules(): Promise<ModuleInstance[]> {\n return (await this._limitedResolver.resolve('*')).filter((module) => module.address !== this.address)\n }\n\n protected override async detachUsingAddress(address: Address) {\n const module = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`)\n this._limitedResolver.remove(module.address)\n return address\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n await this.build()\n return true\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AAGvB,SAEEC,uBACAC,oBAKAC,iCACK;AACP,SAASC,4BAA4B;AACrC,SAASC,YAAYC,wBAAwB;AAC7C,SACEC,gBAEAC,cACAC,uBAEAC,uBAGAC,iCACK;AAEP,SAASC,aAAa;AAEf,IAAMC,uBAAuB;AAa7B,IAAMC,WAAN,cACGC,WAAAA;EA5CV,OA4CUA;;;EAGR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeH;;EAC5E,OAAyBI,sBAA8BJ;EACvD,OAAyBK,SAAS;IAAE,GAAGC;EAA0B;EAEzDC,cAAc,IAAIC,MAAAA;EAClBC,SAAS;EACTC,mBAAmB,IAAIC,qBAAqB;IAAEC,MAAM;EAA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,MAAyBsB,mBAAmBtB,SAAkB;AAC5D,UAAMW,SAASD,SAAS,MAAM,KAAKa,aAAapC,QAAQa,OAAAA,GAAU,MAAM,WAAWA,OAAAA,8BAAqC;AACxH,SAAK/B,iBAAiBuD,OAAOb,OAAOX,OAAO;AAC3C,WAAOA;EACT;EAEA,MAAyByB,eAAiC;AACxD,UAAM,MAAMA,aAAAA;AACZ,UAAM,KAAKzC,MAAK;AAChB,WAAO;EACT;AACF;","names":["assertEx","exists","isAddressModuleFilter","isNameModuleFilter","ModuleLimitationViewLabel","SimpleModuleResolver","MemoryNode","MemoryNodeHelper","asNodeInstance","isNodeModule","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","Mutex","ViewNodeConfigSchema","ViewNode","MemoryNode","configSchemas","defaultConfigSchema","labels","ModuleLimitationViewLabel","_buildMutex","Mutex","_built","_limitedResolver","SimpleModuleResolver","root","ids","config","queries","disallowedQueries","Set","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","filter","query","has","source","build","runExclusive","asNodeInstance","resolve","Promise","all","map","id","MemoryNodeHelper","attachToExistingNode","idOrFilter","options","mods","mod","find","modName","address","isAddressModuleFilter","exists","isNameModuleFilter","name","attachUsingAddress","attached","registeredModules","includes","existingModule","assertEx","module","registeredModuleMap","addParent","args","emit","add","isNodeModule","attachedListener","detachedListener","on","attachedPublicModules","detachUsingAddress","downResolver","remove","startHandler"]}
|
|
1
|
+
{"version":3,"sources":["../../src/ViewNode.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const mod = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`)\n\n mod.addParent(this)\n\n const args = { mod, name: mod.modName }\n await this.emit('moduleAttached', args)\n\n this._limitedResolver.add(mod)\n\n if (isNodeModule(mod)) {\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)\n mod.on('moduleDetached', detachedListener)\n }\n\n return address\n }\n\n protected override async attachedPublicModules(): Promise<ModuleInstance[]> {\n return (await this._limitedResolver.resolve('*')).filter((mod) => mod.address !== this.address)\n }\n\n protected override async detachUsingAddress(address: Address) {\n const mod = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`)\n this._limitedResolver.remove(mod.address)\n return address\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n await this.build()\n return true\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AAGvB,SAEEC,uBACAC,oBAKAC,iCACK;AACP,SAASC,4BAA4B;AACrC,SAASC,YAAYC,wBAAwB;AAC7C,SACEC,gBAEAC,cACAC,uBAEAC,uBAGAC,iCACK;AAEP,SAASC,aAAa;AAEf,IAAMC,uBAAuB;AAa7B,IAAMC,WAAN,cACGC,WAAAA;EA5CV,OA4CUA;;;EAGR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeH;;EAC5E,OAAyBI,sBAA8BJ;EACvD,OAAyBK,SAAS;IAAE,GAAGC;EAA0B;EAEzDC,cAAc,IAAIC,MAAAA;EAClBC,SAAS;EACTC,mBAAmB,IAAIC,qBAAqB;IAAEC,MAAM;EAAK,CAAA;EAEjE,IAAIC,MAAM;AACR,WAAO,KAAKC,OAAOD;EACrB;EAEA,IAAaE,UAAoB;AAC/B,UAAMC,oBAAoB,oBAAIC,IAAY;MAACC;MAAuBC;MAAuBC;KAA0B;AACnH,UAAML,UAAoB;SAAI,MAAMA;;AACpC,WAAOA,QAAQM,OAAO,CAACC,UAAU,CAACN,kBAAkBO,IAAID,KAAAA,CAAAA;EAC1D;EAEA,IAAIE,SAAS;AACX,WAAO,KAAKV,OAAOU;EACrB;EAEA,MAAMC,QAAQ;AACZ,WAAO,MAAM,KAAKlB,YAAYmB,aAAa,YAAA;AACzC,YAAMF,SAASG,eAAe,MAAM,MAAMC,QAAQ,KAAKJ,MAAM,CAAA;AAC7D,UAAIA,QAAQ;AACV,cA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gBAAgBV,WAAWU,gBAAgBT,OAAAA,kCAAyCA,OAAAA,GAAU;AACzI,UAAMH,MAAMa,SAAS,KAAKC,oBAAoBX,OAAAA,GAAU,MAAM,WAAWA,OAAAA,gCAAuC;AAEhHH,QAAIe,UAAU,IAAI;AAElB,UAAMC,OAAO;MAAEhB;MAAKO,MAAMP,IAAIE;IAAQ;AACtC,UAAM,KAAKe,KAAK,kBAAkBD,IAAAA;AAElC,SAAK5C,iBAAiB8C,IAAIlB,GAAAA;AAE1B,QAAImB,aAAanB,GAAAA,GAAM;AACrB,YAAMoB,mBAAgE,8BAAOJ,UAC3E,MAAM,KAAKC,KAAK,kBAAkBD,KAAAA,GADkC;AAGtE,YAAMK,mBAAgE,8BAAOL,UAC3E,MAAM,KAAKC,KAAK,kBAAkBD,KAAAA,GADkC;AAGtEhB,UAAIsB,GAAG,kBAAkBF,gBAAAA;AACzBpB,UAAIsB,GAAG,kBAAkBD,gBAAAA;IAC3B;AAEA,WAAOlB;EACT;EAEA,MAAyBoB,wBAAmD;AAC1E,YAAQ,MAAM,KAAKnD,iBAAiBkB,QAAQ,GAAA,GAAMP,OAAO,CAACiB,QAAQA,IAAIG,YAAY,KAAKA,OAAO;EAChG;EAEA,MAAyBqB,mBAAmBrB,SAAkB;AAC5D,UAAMH,MAAMa,SAAS,MAAM,KAAKY,aAAanC,QAAQa,OAAAA,GAAU,MAAM,WAAWA,OAAAA,8BAAqC;AACrH,SAAK/B,iBAAiBsD,OAAO1B,IAAIG,OAAO;AACxC,WAAOA;EACT;EAEA,MAAyBwB,eAAiC;AACxD,UAAM,MAAMA,aAAAA;AACZ,UAAM,KAAKxC,MAAK;AAChB,WAAO;EACT;AACF;","names":["assertEx","exists","isAddressModuleFilter","isNameModuleFilter","ModuleLimitationViewLabel","SimpleModuleResolver","MemoryNode","MemoryNodeHelper","asNodeInstance","isNodeModule","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","Mutex","ViewNodeConfigSchema","ViewNode","MemoryNode","configSchemas","defaultConfigSchema","labels","ModuleLimitationViewLabel","_buildMutex","Mutex","_built","_limitedResolver","SimpleModuleResolver","root","ids","config","queries","disallowedQueries","Set","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","filter","query","has","source","build","runExclusive","asNodeInstance","resolve","Promise","all","map","id","MemoryNodeHelper","attachToExistingNode","idOrFilter","options","mods","mod","find","modName","address","isAddressModuleFilter","exists","isNameModuleFilter","name","attachUsingAddress","attached","registeredModules","includes","existingModule","assertEx","registeredModuleMap","addParent","args","emit","add","isNodeModule","attachedListener","detachedListener","on","attachedPublicModules","detachUsingAddress","downResolver","remove","startHandler"]}
|
package/dist/node/index.cjs
CHANGED
|
@@ -99,31 +99,31 @@ var _ViewNode = class _ViewNode extends import_node_memory.MemoryNode {
|
|
|
99
99
|
}
|
|
100
100
|
async attachUsingAddress(address) {
|
|
101
101
|
const attached = await this.attached();
|
|
102
|
-
const mods = this.registeredModules().filter((
|
|
103
|
-
const existingModule = mods.find((
|
|
102
|
+
const mods = this.registeredModules().filter((mod2) => attached.includes(mod2.address));
|
|
103
|
+
const existingModule = mods.find((mod2) => mod2.address === address);
|
|
104
104
|
(0, import_assert.assertEx)(!existingModule, () => `Module [${(existingModule == null ? void 0 : existingModule.modName) ?? (existingModule == null ? void 0 : existingModule.address)}] already attached at address [${address}]`);
|
|
105
|
-
const
|
|
106
|
-
|
|
105
|
+
const mod = (0, import_assert.assertEx)(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`);
|
|
106
|
+
mod.addParent(this);
|
|
107
107
|
const args = {
|
|
108
|
-
|
|
109
|
-
name:
|
|
108
|
+
mod,
|
|
109
|
+
name: mod.modName
|
|
110
110
|
};
|
|
111
111
|
await this.emit("moduleAttached", args);
|
|
112
|
-
this._limitedResolver.add(
|
|
113
|
-
if ((0, import_node_model.isNodeModule)(
|
|
112
|
+
this._limitedResolver.add(mod);
|
|
113
|
+
if ((0, import_node_model.isNodeModule)(mod)) {
|
|
114
114
|
const attachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleAttached", args2), "attachedListener");
|
|
115
115
|
const detachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleDetached", args2), "detachedListener");
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
mod.on("moduleAttached", attachedListener);
|
|
117
|
+
mod.on("moduleDetached", detachedListener);
|
|
118
118
|
}
|
|
119
119
|
return address;
|
|
120
120
|
}
|
|
121
121
|
async attachedPublicModules() {
|
|
122
|
-
return (await this._limitedResolver.resolve("*")).filter((
|
|
122
|
+
return (await this._limitedResolver.resolve("*")).filter((mod) => mod.address !== this.address);
|
|
123
123
|
}
|
|
124
124
|
async detachUsingAddress(address) {
|
|
125
|
-
const
|
|
126
|
-
this._limitedResolver.remove(
|
|
125
|
+
const mod = (0, import_assert.assertEx)(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`);
|
|
126
|
+
this._limitedResolver.remove(mod.address);
|
|
127
127
|
return address;
|
|
128
128
|
}
|
|
129
129
|
async startHandler() {
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/ViewNode.ts"],"sourcesContent":["export * from './ViewNode'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/ViewNode.ts"],"sourcesContent":["export * from './ViewNode'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const mod = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`)\n\n mod.addParent(this)\n\n const args = { mod, name: mod.modName }\n await this.emit('moduleAttached', args)\n\n this._limitedResolver.add(mod)\n\n if (isNodeModule(mod)) {\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)\n mod.on('moduleDetached', detachedListener)\n }\n\n return address\n }\n\n protected override async attachedPublicModules(): Promise<ModuleInstance[]> {\n return (await this._limitedResolver.resolve('*')).filter((mod) => mod.address !== this.address)\n }\n\n protected override async detachUsingAddress(address: Address) {\n const mod = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`)\n this._limitedResolver.remove(mod.address)\n return address\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n await this.build()\n return true\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AAGvB,0BASO;AACP,6BAAqC;AACrC,yBAA6C;AAC7C,wBAUO;AAEP,yBAAsB;AAEf,IAAMA,uBAAuB;AAa7B,IAAMC,YAAN,MAAMA,kBACHC,8BAAAA;EAOAC,cAAc,IAAIC,yBAAAA;EAClBC,SAAS;EACTC,mBAAmB,IAAIC,4CAAqB;IAAEC,MAAM;EAAK,CAAA;EAEjE,IAAIC,MAAM;AACR,WAAO,KAAKC,OAAOD;EACrB;EAEA,IAAaE,UAAoB;AAC/B,UAAMC,oBAAoB,oBAAIC,IAAY;MAACC;MAAuBC;MAAuBC;KAA0B;AACnH,UAAML,UAAoB;SAAI,MAAMA;;AACpC,WAAOA,QAAQM,OAAO,CAACC,UAAU,CAACN,kBAAkBO,IAAID,KAAAA,CAAAA;EAC1D;EAEA,IAAIE,SAAS;AACX,WAAO,KAAKV,OAAOU;EACrB;EAEA,MAAMC,QAAQ;AACZ,WAAO,MAAM,KAAKlB,YAAYmB,aAAa,YAAA;AACzC,YAAMF,aAASG,kCAAe,MAAM,MAAMC,QAAQ,KAAKJ,MAAM,CAAA;AAC7D,UAAIA,QAAQ;AACV,cAAMK,QAAQC,IACZ,KAAKjB,IAAIkB,IAAI,OAAOC,OAAAA;AAClB,gBAAMC,oCAAiBC,qBAAqBV,QAAQQ,IAAI,IAAI;QAC9D,CAAA,CAAA;AAEF,aAAKvB,SAAS;MAChB;IACF,CAAA;EACF;EAOA,MAAemB,QACbO,aAAiD,KACjDC,UAAkC,CAAC,GACL;AAC9B,QAAI,CAAC,KAAK3B,QAAQ;AAChB,YAAM,KAAKgB,MAAK;IAClB;AACA,UAAMY,OAAO,MAAM,KAAK3B,iBA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ImB,gCAAanB,GAAAA,GAAM;AACrB,YAAMoB,mBAAgE,8BAAOJ,UAC3E,MAAM,KAAKC,KAAK,kBAAkBD,KAAAA,GADkC;AAGtE,YAAMK,mBAAgE,8BAAOL,UAC3E,MAAM,KAAKC,KAAK,kBAAkBD,KAAAA,GADkC;AAGtEhB,UAAIsB,GAAG,kBAAkBF,gBAAAA;AACzBpB,UAAIsB,GAAG,kBAAkBD,gBAAAA;IAC3B;AAEA,WAAOlB;EACT;EAEA,MAAyBoB,wBAAmD;AAC1E,YAAQ,MAAM,KAAKnD,iBAAiBkB,QAAQ,GAAA,GAAMP,OAAO,CAACiB,QAAQA,IAAIG,YAAY,KAAKA,OAAO;EAChG;EAEA,MAAyBqB,mBAAmBrB,SAAkB;AAC5D,UAAMH,UAAMa,wBAAS,MAAM,KAAKY,aAAanC,QAAQa,OAAAA,GAAU,MAAM,WAAWA,OAAAA,8BAAqC;AACrH,SAAK/B,iBAAiBsD,OAAO1B,IAAIG,OAAO;AACxC,WAAOA;EACT;EAEA,MAAyBwB,eAAiC;AACxD,UAAM,MAAMA,aAAAA;AACZ,UAAM,KAAKxC,MAAK;AAChB,WAAO;EACT;AACF;AAlHUnB;AAGR,cAJWD,WAIc6D,iBAA0B;KAAI,iCAAMA;EAAe9D;;AAC5E,cALWC,WAKc8D,uBAA8B/D;AACvD,cANWC,WAMc+D,UAAS;EAAE,GAAGC;AAA0B;AAN5D,IAAMhE,WAAN;","names":["ViewNodeConfigSchema","ViewNode","MemoryNode","_buildMutex","Mutex","_built","_limitedResolver","SimpleModuleResolver","root","ids","config","queries","disallowedQueries","Set","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","filter","query","has","source","build","runExclusive","asNodeInstance","resolve","Promise","all","map","id","MemoryNodeHelper","attachToExistingNode","idOrFilter","options","mods","mod","find","modName","address","isAddressModuleFilter","exists","isNameModuleFilter","name","attachUsingAddress","attached","registeredModules","includes","existingModule","assertEx","registeredModuleMap","addParent","args","emit","add","isNodeModule","attachedListener","detachedListener","on","attachedPublicModules","detachUsingAddress","downResolver","remove","startHandler","configSchemas","defaultConfigSchema","labels","ModuleLimitationViewLabel"]}
|
package/dist/node/index.js
CHANGED
|
@@ -74,31 +74,31 @@ var _ViewNode = class _ViewNode extends MemoryNode {
|
|
|
74
74
|
}
|
|
75
75
|
async attachUsingAddress(address) {
|
|
76
76
|
const attached = await this.attached();
|
|
77
|
-
const mods = this.registeredModules().filter((
|
|
78
|
-
const existingModule = mods.find((
|
|
77
|
+
const mods = this.registeredModules().filter((mod2) => attached.includes(mod2.address));
|
|
78
|
+
const existingModule = mods.find((mod2) => mod2.address === address);
|
|
79
79
|
assertEx(!existingModule, () => `Module [${(existingModule == null ? void 0 : existingModule.modName) ?? (existingModule == null ? void 0 : existingModule.address)}] already attached at address [${address}]`);
|
|
80
|
-
const
|
|
81
|
-
|
|
80
|
+
const mod = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`);
|
|
81
|
+
mod.addParent(this);
|
|
82
82
|
const args = {
|
|
83
|
-
|
|
84
|
-
name:
|
|
83
|
+
mod,
|
|
84
|
+
name: mod.modName
|
|
85
85
|
};
|
|
86
86
|
await this.emit("moduleAttached", args);
|
|
87
|
-
this._limitedResolver.add(
|
|
88
|
-
if (isNodeModule(
|
|
87
|
+
this._limitedResolver.add(mod);
|
|
88
|
+
if (isNodeModule(mod)) {
|
|
89
89
|
const attachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleAttached", args2), "attachedListener");
|
|
90
90
|
const detachedListener = /* @__PURE__ */ __name(async (args2) => await this.emit("moduleDetached", args2), "detachedListener");
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
mod.on("moduleAttached", attachedListener);
|
|
92
|
+
mod.on("moduleDetached", detachedListener);
|
|
93
93
|
}
|
|
94
94
|
return address;
|
|
95
95
|
}
|
|
96
96
|
async attachedPublicModules() {
|
|
97
|
-
return (await this._limitedResolver.resolve("*")).filter((
|
|
97
|
+
return (await this._limitedResolver.resolve("*")).filter((mod) => mod.address !== this.address);
|
|
98
98
|
}
|
|
99
99
|
async detachUsingAddress(address) {
|
|
100
|
-
const
|
|
101
|
-
this._limitedResolver.remove(
|
|
100
|
+
const mod = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`);
|
|
101
|
+
this._limitedResolver.remove(mod.address);
|
|
102
102
|
return address;
|
|
103
103
|
}
|
|
104
104
|
async startHandler() {
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ViewNode.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const module = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered modules`)\n\n module.addParent(this)\n\n const args = { module, name: module.modName }\n await this.emit('moduleAttached', args)\n\n this._limitedResolver.add(module)\n\n if (isNodeModule(module)) {\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 module.on('moduleAttached', attachedListener)\n module.on('moduleDetached', detachedListener)\n }\n\n return address\n }\n\n protected override async attachedPublicModules(): Promise<ModuleInstance[]> {\n return (await this._limitedResolver.resolve('*')).filter((module) => module.address !== this.address)\n }\n\n protected override async detachUsingAddress(address: Address) {\n const module = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`)\n this._limitedResolver.remove(module.address)\n return address\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n await this.build()\n return true\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AAGvB,SAEEC,uBACAC,oBAKAC,iCACK;AACP,SAASC,4BAA4B;AACrC,SAASC,YAAYC,wBAAwB;AAC7C,SACEC,gBAEAC,cACAC,uBAEAC,uBAGAC,iCACK;AAEP,SAASC,aAAa;AAEf,IAAMC,uBAAuB;AAa7B,IAAMC,YAAN,MAAMA,kBACHC,WAAAA;EAOAC,cAAc,IAAIC,MAAAA;EAClBC,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CAAC+B,WAAWA,OAAOX,YAAY,KAAKA,OAAO;EACtG;EAEA,MAAyBsB,mBAAmBtB,SAAkB;AAC5D,UAAMW,SAASD,SAAS,MAAM,KAAKa,aAAapC,QAAQa,OAAAA,GAAU,MAAM,WAAWA,OAAAA,8BAAqC;AACxH,SAAK/B,iBAAiBuD,OAAOb,OAAOX,OAAO;AAC3C,WAAOA;EACT;EAEA,MAAyByB,eAAiC;AACxD,UAAM,MAAMA,aAAAA;AACZ,UAAM,KAAKzC,MAAK;AAChB,WAAO;EACT;AACF;AAlHUnB;AAGR,cAJWD,WAIc8D,iBAA0B;KAAI,iCAAMA;EAAe/D;;AAC5E,cALWC,WAKc+D,uBAA8BhE;AACvD,cANWC,WAMcgE,UAAS;EAAE,GAAGC;AAA0B;AAN5D,IAAMjE,WAAN;","names":["assertEx","exists","isAddressModuleFilter","isNameModuleFilter","ModuleLimitationViewLabel","SimpleModuleResolver","MemoryNode","MemoryNodeHelper","asNodeInstance","isNodeModule","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","Mutex","ViewNodeConfigSchema","ViewNode","MemoryNode","_buildMutex","Mutex","_built","_limitedResolver","SimpleModuleResolver","root","ids","config","queries","disallowedQueries","Set","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","filter","query","has","source","build","runExclusive","asNodeInstance","resolve","Promise","all","map","id","MemoryNodeHelper","attachToExistingNode","idOrFilter","options","mods","mod","find","modName","address","isAddressModuleFilter","exists","isNameModuleFilter","name","attachUsingAddress","attached","registeredModules","includes","existingModule","assertEx","module","registeredModuleMap","addParent","args","emit","add","isNodeModule","attachedListener","detachedListener","on","attachedPublicModules","detachUsingAddress","downResolver","remove","startHandler","configSchemas","defaultConfigSchema","labels","ModuleLimitationViewLabel"]}
|
|
1
|
+
{"version":3,"sources":["../../src/ViewNode.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { Address } from '@xylabs/hex'\nimport { EventListener } from '@xyo-network/module-events'\nimport {\n AnyConfigSchema,\n isAddressModuleFilter,\n isNameModuleFilter,\n ModuleFilter,\n ModuleFilterOptions,\n ModuleIdentifier,\n ModuleInstance,\n ModuleLimitationViewLabel,\n} from '@xyo-network/module-model'\nimport { SimpleModuleResolver } from '@xyo-network/module-resolver'\nimport { MemoryNode, MemoryNodeHelper } from '@xyo-network/node-memory'\nimport {\n asNodeInstance,\n AttachableNodeInstance,\n isNodeModule,\n NodeAttachQuerySchema,\n NodeConfig,\n NodeDetachQuerySchema,\n NodeModuleEventData,\n NodeParams,\n NodeRegisteredQuerySchema,\n} from '@xyo-network/node-model'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Mutex } from 'async-mutex'\n\nexport const ViewNodeConfigSchema = 'network.xyo.node.view.config' as const\nexport type ViewNodeConfigSchema = typeof ViewNodeConfigSchema\n\nexport type ViewNodeConfig = NodeConfig<\n {\n ids: ModuleIdentifier[]\n source: ModuleIdentifier\n },\n ViewNodeConfigSchema\n>\n\nexport type ViewNodeParams = NodeParams<AnyConfigSchema<ViewNodeConfig>>\n\nexport class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventData extends NodeModuleEventData = NodeModuleEventData>\n extends MemoryNode<TParams, TEventData>\n implements AttachableNodeInstance\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ViewNodeConfigSchema]\n static override readonly defaultConfigSchema: Schema = ViewNodeConfigSchema\n static override readonly labels = { ...ModuleLimitationViewLabel }\n\n private _buildMutex = new Mutex()\n private _built = false\n private _limitedResolver = new SimpleModuleResolver({ root: this })\n\n get ids() {\n return this.config.ids\n }\n\n override get queries(): Schema[] {\n const disallowedQueries = new Set<Schema>([NodeAttachQuerySchema, NodeDetachQuerySchema, NodeRegisteredQuerySchema])\n const queries: Schema[] = [...super.queries]\n return queries.filter((query) => !disallowedQueries.has(query))\n }\n\n get source() {\n return this.config.source\n }\n\n async build() {\n return await this._buildMutex.runExclusive(async () => {\n const source = asNodeInstance(await super.resolve(this.source))\n if (source) {\n await Promise.all(\n this.ids.map(async (id) => {\n await MemoryNodeHelper.attachToExistingNode(source, id, this)\n }),\n )\n this._built = true\n }\n })\n }\n\n /** @deprecated do not pass undefined. If trying to get all, pass '*' */\n override async resolve(): Promise<ModuleInstance[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(all: '*', options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(filter: ModuleFilter, options?: ModuleFilterOptions<T>): Promise<T[]>\n override async resolve<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promise<T | undefined>\n override async resolve<T extends ModuleInstance = ModuleInstance>(\n idOrFilter: ModuleFilter<T> | ModuleIdentifier = '*',\n options: ModuleFilterOptions<T> = {},\n ): Promise<T | T[] | undefined> {\n if (!this._built) {\n await this.build()\n }\n const mods = await this._limitedResolver.resolve('*')\n if (idOrFilter === '*') {\n return mods as unknown as T[]\n }\n switch (typeof idOrFilter) {\n case 'string': {\n const mod = mods.find((mod) => mod.modName === idOrFilter || mod.address === idOrFilter)\n return mod as unknown as T\n }\n case 'object': {\n if (isAddressModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.address.map(async (address) => await this.resolve(address, options)))).filter(exists)\n } else if (isNameModuleFilter(idOrFilter)) {\n return (await Promise.all(idOrFilter.name.map(async (name) => await this.resolve(name, options)))).filter(exists)\n }\n return []\n }\n }\n }\n\n protected override async attachUsingAddress(address: Address) {\n const attached = await this.attached()\n const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))\n const existingModule = mods.find((mod) => mod.address === address)\n assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)\n const mod = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`)\n\n mod.addParent(this)\n\n const args = { mod, name: mod.modName }\n await this.emit('moduleAttached', args)\n\n this._limitedResolver.add(mod)\n\n if (isNodeModule(mod)) {\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)\n mod.on('moduleDetached', detachedListener)\n }\n\n return address\n }\n\n protected override async attachedPublicModules(): Promise<ModuleInstance[]> {\n return (await this._limitedResolver.resolve('*')).filter((mod) => mod.address !== this.address)\n }\n\n protected override async detachUsingAddress(address: Address) {\n const mod = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`)\n this._limitedResolver.remove(mod.address)\n return address\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n await this.build()\n return true\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AAGvB,SAEEC,uBACAC,oBAKAC,iCACK;AACP,SAASC,4BAA4B;AACrC,SAASC,YAAYC,wBAAwB;AAC7C,SACEC,gBAEAC,cACAC,uBAEAC,uBAGAC,iCACK;AAEP,SAASC,aAAa;AAEf,IAAMC,uBAAuB;AAa7B,IAAMC,YAAN,MAAMA,kBACHC,WAAAA;EAOAC,cAAc,IAAIC,MAAAA;EAClBC,SAAS;EACTC,mBAAmB,IAAIC,qBAAqB;IAAEC,MAAM;EAAK,CAAA;EAEjE,IAAIC,MAAM;AACR,WAAO,KAAKC,OAAOD;EACrB;EAEA,IAAaE,UAAoB;AAC/B,UAAMC,oBAAoB,oBAAIC,IAAY;MAACC;MAAuBC;MAAuBC;KAA0B;AACnH,UAAML,UAAoB;SAAI,MAAMA;;AACpC,WAAOA,QAAQM,OAAO,CAACC,UAAU,CAACN,kBAAkBO,IAAID,KAAAA,CAAAA;EAC1D;EAEA,IAAIE,SAAS;AACX,WAAO,KAAKV,OAAOU;EACrB;EAEA,MAAMC,QAAQ;AACZ,WAAO,MAAM,KAAKlB,YAAYmB,aAAa,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,uBAA8B/D;AACvD,cANWC,WAMc+D,UAAS;EAAE,GAAGC;AAA0B;AAN5D,IAAMhE,WAAN;","names":["assertEx","exists","isAddressModuleFilter","isNameModuleFilter","ModuleLimitationViewLabel","SimpleModuleResolver","MemoryNode","MemoryNodeHelper","asNodeInstance","isNodeModule","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","Mutex","ViewNodeConfigSchema","ViewNode","MemoryNode","_buildMutex","Mutex","_built","_limitedResolver","SimpleModuleResolver","root","ids","config","queries","disallowedQueries","Set","NodeAttachQuerySchema","NodeDetachQuerySchema","NodeRegisteredQuerySchema","filter","query","has","source","build","runExclusive","asNodeInstance","resolve","Promise","all","map","id","MemoryNodeHelper","attachToExistingNode","idOrFilter","options","mods","mod","find","modName","address","isAddressModuleFilter","exists","isNameModuleFilter","name","attachUsingAddress","attached","registeredModules","includes","existingModule","assertEx","registeredModuleMap","addParent","args","emit","add","isNodeModule","attachedListener","detachedListener","on","attachedPublicModules","detachUsingAddress","downResolver","remove","startHandler","configSchemas","defaultConfigSchema","labels","ModuleLimitationViewLabel"]}
|
package/package.json
CHANGED
|
@@ -13,18 +13,18 @@
|
|
|
13
13
|
"@xylabs/assert": "^3.5.2",
|
|
14
14
|
"@xylabs/exists": "^3.5.2",
|
|
15
15
|
"@xylabs/hex": "^3.5.2",
|
|
16
|
-
"@xyo-network/module-events": "^2.
|
|
17
|
-
"@xyo-network/module-model": "^2.
|
|
18
|
-
"@xyo-network/module-resolver": "^2.
|
|
19
|
-
"@xyo-network/node-memory": "^2.
|
|
20
|
-
"@xyo-network/node-model": "^2.
|
|
21
|
-
"@xyo-network/payload-model": "^2.
|
|
16
|
+
"@xyo-network/module-events": "^2.109.0",
|
|
17
|
+
"@xyo-network/module-model": "^2.109.0",
|
|
18
|
+
"@xyo-network/module-resolver": "^2.109.0",
|
|
19
|
+
"@xyo-network/node-memory": "^2.109.0",
|
|
20
|
+
"@xyo-network/node-model": "^2.109.0",
|
|
21
|
+
"@xyo-network/payload-model": "^2.109.0",
|
|
22
22
|
"async-mutex": "^0.5.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@xylabs/ts-scripts-yarn3": "^3.11.12",
|
|
26
26
|
"@xylabs/tsconfig": "^3.11.12",
|
|
27
|
-
"typescript": "^5.5.
|
|
27
|
+
"typescript": "^5.5.3"
|
|
28
28
|
},
|
|
29
29
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
30
30
|
"types": "dist/node/index.d.ts",
|
|
@@ -65,6 +65,6 @@
|
|
|
65
65
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
66
66
|
},
|
|
67
67
|
"sideEffects": false,
|
|
68
|
-
"version": "2.
|
|
68
|
+
"version": "2.109.0",
|
|
69
69
|
"type": "module"
|
|
70
70
|
}
|
package/src/ViewNode.ts
CHANGED
|
@@ -118,36 +118,36 @@ export class ViewNode<TParams extends ViewNodeParams = ViewNodeParams, TEventDat
|
|
|
118
118
|
const mods = this.registeredModules().filter((mod) => attached.includes(mod.address))
|
|
119
119
|
const existingModule = mods.find((mod) => mod.address === address)
|
|
120
120
|
assertEx(!existingModule, () => `Module [${existingModule?.modName ?? existingModule?.address}] already attached at address [${address}]`)
|
|
121
|
-
const
|
|
121
|
+
const mod = assertEx(this.registeredModuleMap[address], () => `Module [${address}] not found in registered mods`)
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
mod.addParent(this)
|
|
124
124
|
|
|
125
|
-
const args = {
|
|
125
|
+
const args = { mod, name: mod.modName }
|
|
126
126
|
await this.emit('moduleAttached', args)
|
|
127
127
|
|
|
128
|
-
this._limitedResolver.add(
|
|
128
|
+
this._limitedResolver.add(mod)
|
|
129
129
|
|
|
130
|
-
if (isNodeModule(
|
|
130
|
+
if (isNodeModule(mod)) {
|
|
131
131
|
const attachedListener: EventListener<TEventData['moduleAttached']> = async (args: TEventData['moduleAttached']) =>
|
|
132
132
|
await this.emit('moduleAttached', args)
|
|
133
133
|
|
|
134
134
|
const detachedListener: EventListener<TEventData['moduleDetached']> = async (args: TEventData['moduleDetached']) =>
|
|
135
135
|
await this.emit('moduleDetached', args)
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
mod.on('moduleAttached', attachedListener)
|
|
138
|
+
mod.on('moduleDetached', detachedListener)
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
return address
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
protected override async attachedPublicModules(): Promise<ModuleInstance[]> {
|
|
145
|
-
return (await this._limitedResolver.resolve('*')).filter((
|
|
145
|
+
return (await this._limitedResolver.resolve('*')).filter((mod) => mod.address !== this.address)
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
protected override async detachUsingAddress(address: Address) {
|
|
149
|
-
const
|
|
150
|
-
this._limitedResolver.remove(
|
|
149
|
+
const mod = assertEx(await this.downResolver.resolve(address), () => `Module [${address}] not found in down resolver`)
|
|
150
|
+
this._limitedResolver.remove(mod.address)
|
|
151
151
|
return address
|
|
152
152
|
}
|
|
153
153
|
|