@xyo-network/module-factory-locator 3.6.9 → 3.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/index.mjs +32 -35
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +16 -16
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/ModuleFactoryLocator.ts
|
|
5
2
|
import { assertEx } from "@xylabs/assert";
|
|
6
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
hasAllLabels,
|
|
5
|
+
hasLabels,
|
|
6
|
+
registerCreatableModuleFactory
|
|
7
|
+
} from "@xyo-network/module-model";
|
|
7
8
|
|
|
8
9
|
// src/standardCreatableFactories.ts
|
|
9
10
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
@@ -32,24 +33,19 @@ var standardCreatableFactoriesList = [
|
|
|
32
33
|
MemorySentinel,
|
|
33
34
|
GenericPayloadDiviner
|
|
34
35
|
];
|
|
35
|
-
var standardCreatableFactories =
|
|
36
|
+
var standardCreatableFactories = () => {
|
|
36
37
|
return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true);
|
|
37
|
-
}
|
|
38
|
+
};
|
|
38
39
|
|
|
39
40
|
// src/ModuleFactoryLocator.ts
|
|
40
41
|
var ModuleFactoryLocator = class _ModuleFactoryLocator {
|
|
41
|
-
static {
|
|
42
|
-
__name(this, "ModuleFactoryLocator");
|
|
43
|
-
}
|
|
44
|
-
_registry;
|
|
45
|
-
_frozen;
|
|
46
42
|
constructor(_registry = standardCreatableFactories()) {
|
|
47
43
|
this._registry = _registry;
|
|
48
|
-
this._frozen = false;
|
|
49
44
|
}
|
|
45
|
+
_frozen = false;
|
|
50
46
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
* The current registry for the module factory
|
|
48
|
+
*/
|
|
53
49
|
get registry() {
|
|
54
50
|
return this._registry;
|
|
55
51
|
}
|
|
@@ -63,18 +59,19 @@ var ModuleFactoryLocator = class _ModuleFactoryLocator {
|
|
|
63
59
|
this._frozen = true;
|
|
64
60
|
}
|
|
65
61
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
* Locates a module factory that matches the supplied schema and labels
|
|
63
|
+
* @param schema The config schema for the module
|
|
64
|
+
* @param labels The labels for the module factory
|
|
65
|
+
* @returns A module factory that matches the supplied schema and labels or throws if one is not found
|
|
66
|
+
*/
|
|
71
67
|
locate(schema, labels) {
|
|
72
|
-
return assertEx(
|
|
68
|
+
return assertEx(
|
|
69
|
+
this.tryLocate(schema, labels),
|
|
70
|
+
() => `No module factory for the supplied ${`config schema [${schema}]`}${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`
|
|
71
|
+
);
|
|
73
72
|
}
|
|
74
73
|
merge(locator) {
|
|
75
|
-
const registry = {
|
|
76
|
-
...this.registry
|
|
77
|
-
};
|
|
74
|
+
const registry = { ...this.registry };
|
|
78
75
|
for (const schema in locator.registry) {
|
|
79
76
|
if (registry[schema]) {
|
|
80
77
|
registry[schema].push(...locator.registry[schema] ?? []);
|
|
@@ -85,19 +82,19 @@ var ModuleFactoryLocator = class _ModuleFactoryLocator {
|
|
|
85
82
|
return new _ModuleFactoryLocator(registry);
|
|
86
83
|
}
|
|
87
84
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
* Registers a single module factory (with optional tags) with the locator
|
|
86
|
+
* @param factory The factory to register
|
|
87
|
+
* @param labels The labels for the module factory
|
|
88
|
+
*/
|
|
92
89
|
register(factory, labels, primary = false) {
|
|
93
90
|
assertEx(!this._frozen, () => "Cannot register a module factory after the locator has been frozen");
|
|
94
91
|
registerCreatableModuleFactory(this._registry, factory, labels, primary);
|
|
95
92
|
return this;
|
|
96
93
|
}
|
|
97
94
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
* Registers multiple module factories with the locator
|
|
96
|
+
* @param factories The factories to register
|
|
97
|
+
*/
|
|
101
98
|
registerMany(factories) {
|
|
102
99
|
for (const factory of factories) {
|
|
103
100
|
this.register(factory);
|
|
@@ -105,11 +102,11 @@ var ModuleFactoryLocator = class _ModuleFactoryLocator {
|
|
|
105
102
|
return this;
|
|
106
103
|
}
|
|
107
104
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
* Tries to locate a module factory that matches the supplied schema and labels
|
|
106
|
+
* @param schema The config schema for the module
|
|
107
|
+
* @param labels The labels for the module factory
|
|
108
|
+
* @returns A module factory that matches the supplied schema and labels or undefined
|
|
109
|
+
*/
|
|
113
110
|
tryLocate(schema, labels) {
|
|
114
111
|
return labels ? this._registry[schema]?.filter(hasLabels).find((factory) => hasAllLabels(factory?.labels, labels)) ?? this._registry[schema]?.[0] : this._registry[schema]?.[0];
|
|
115
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport type {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n LabeledCreatableModuleFactory,\n Labels,\n} from '@xyo-network/module-model'\nimport {\n hasAllLabels,\n hasLabels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport type { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories.ts'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\n private _frozen = false\n\n constructor(protected readonly _registry: CreatableModuleRegistry = standardCreatableFactories()) {}\n\n /**\n * The current registry for the module factory\n */\n get registry(): Readonly<CreatableModuleRegistry> {\n return this._registry\n }\n\n static empty() {\n return new ModuleFactoryLocator({})\n }\n\n static standard() {\n return new ModuleFactoryLocator(standardCreatableFactories())\n }\n\n freeze() {\n this._frozen = true\n }\n\n /**\n * Locates a module factory that matches the supplied schema and labels\n * @param schema The config schema for the module\n * @param labels The labels for the module factory\n * @returns A module factory that matches the supplied schema and labels or throws if one is not found\n */\n locate(schema: string, labels?: Labels): CreatableModuleFactory | LabeledCreatableModuleFactory {\n return assertEx(\n this.tryLocate(schema, labels),\n () => `No module factory for the supplied ${`config schema [${schema}]`}${labels ? ` & labels [${JSON.stringify(labels)}]` : ''} registered`,\n )\n }\n\n merge(locator: ModuleFactoryLocator): ModuleFactoryLocator {\n const registry = { ...this.registry }\n for (const schema in locator.registry) {\n if (registry[schema]) {\n registry[schema].push(...(locator.registry[schema] ?? []))\n } else {\n registry[schema] = locator.registry[schema]\n }\n }\n return new ModuleFactoryLocator(registry)\n }\n\n /**\n * Registers a single module factory (with optional tags) with the locator\n * @param factory The factory to register\n * @param labels The labels for the module factory\n */\n register(factory: CreatableModuleFactory, labels?: Labels, primary: boolean | Schema | Schema[] = false): this {\n assertEx(!this._frozen, () => 'Cannot register a module factory after the locator has been frozen')\n registerCreatableModuleFactory(this._registry, factory, labels, primary)\n return this\n }\n\n /**\n * Registers multiple module factories with the locator\n * @param factories The factories to register\n */\n registerMany(factories: CreatableModuleFactory[]): this {\n for (const factory of factories) {\n this.register(factory)\n }\n return this\n }\n\n /**\n * Tries to locate a module factory that matches the supplied schema and labels\n * @param schema The config schema for the module\n * @param labels The labels for the module factory\n * @returns A module factory that matches the supplied schema and labels or undefined\n */\n tryLocate(schema: string, labels?: Labels): CreatableModuleFactory | LabeledCreatableModuleFactory | undefined {\n return labels\n // Find the first factory that has labels and has all the labels provided\n ? (this._registry[schema]?.filter(hasLabels).find(factory => hasAllLabels(factory?.labels, labels)) ?? this._registry[schema]?.[0])\n // Otherwise, return the first factory\n : this._registry[schema]?.[0]\n }\n}\n","import { MemoryArchivist } from '@xyo-network/archivist-memory'\nimport { ViewArchivist } from '@xyo-network/archivist-view'\nimport { HttpBridge } from '@xyo-network/bridge-http'\nimport { MemoryBoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-memory'\nimport { IdentityDiviner } from '@xyo-network/diviner-identity'\nimport { GenericPayloadDiviner } from '@xyo-network/diviner-payload-generic'\nimport { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport type { CreatableModuleFactory, LabeledCreatableModuleFactory } from '@xyo-network/module-model'\nimport { registerCreatableModuleFactories } from '@xyo-network/module-model'\nimport { MemoryNode } from '@xyo-network/node-memory'\nimport { ViewNode } from '@xyo-network/node-view'\nimport { MemorySentinel } from '@xyo-network/sentinel-memory'\nimport { AdhocWitness } from '@xyo-network/witness-adhoc'\n\n// order matters in this array. later items will register themselves as primary for schemas shared with earlier items\nexport const standardCreatableFactoriesList: (CreatableModuleFactory | LabeledCreatableModuleFactory)[] = [\n HttpBridge,\n ViewArchivist,\n ViewNode,\n AdhocWitness,\n MemoryPayloadDiviner,\n MemoryBoundWitnessDiviner,\n IdentityDiviner,\n MemoryArchivist,\n MemoryArchivist,\n MemoryNode,\n MemorySentinel,\n GenericPayloadDiviner,\n]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport type {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n LabeledCreatableModuleFactory,\n Labels,\n} from '@xyo-network/module-model'\nimport {\n hasAllLabels,\n hasLabels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport type { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories.ts'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\n private _frozen = false\n\n constructor(protected readonly _registry: CreatableModuleRegistry = standardCreatableFactories()) {}\n\n /**\n * The current registry for the module factory\n */\n get registry(): Readonly<CreatableModuleRegistry> {\n return this._registry\n }\n\n static empty() {\n return new ModuleFactoryLocator({})\n }\n\n static standard() {\n return new ModuleFactoryLocator(standardCreatableFactories())\n }\n\n freeze() {\n this._frozen = true\n }\n\n /**\n * Locates a module factory that matches the supplied schema and labels\n * @param schema The config schema for the module\n * @param labels The labels for the module factory\n * @returns A module factory that matches the supplied schema and labels or throws if one is not found\n */\n locate(schema: string, labels?: Labels): CreatableModuleFactory | LabeledCreatableModuleFactory {\n return assertEx(\n this.tryLocate(schema, labels),\n () => `No module factory for the supplied ${`config schema [${schema}]`}${labels ? ` & labels [${JSON.stringify(labels)}]` : ''} registered`,\n )\n }\n\n merge(locator: ModuleFactoryLocator): ModuleFactoryLocator {\n const registry = { ...this.registry }\n for (const schema in locator.registry) {\n if (registry[schema]) {\n registry[schema].push(...(locator.registry[schema] ?? []))\n } else {\n registry[schema] = locator.registry[schema]\n }\n }\n return new ModuleFactoryLocator(registry)\n }\n\n /**\n * Registers a single module factory (with optional tags) with the locator\n * @param factory The factory to register\n * @param labels The labels for the module factory\n */\n register(factory: CreatableModuleFactory, labels?: Labels, primary: boolean | Schema | Schema[] = false): this {\n assertEx(!this._frozen, () => 'Cannot register a module factory after the locator has been frozen')\n registerCreatableModuleFactory(this._registry, factory, labels, primary)\n return this\n }\n\n /**\n * Registers multiple module factories with the locator\n * @param factories The factories to register\n */\n registerMany(factories: CreatableModuleFactory[]): this {\n for (const factory of factories) {\n this.register(factory)\n }\n return this\n }\n\n /**\n * Tries to locate a module factory that matches the supplied schema and labels\n * @param schema The config schema for the module\n * @param labels The labels for the module factory\n * @returns A module factory that matches the supplied schema and labels or undefined\n */\n tryLocate(schema: string, labels?: Labels): CreatableModuleFactory | LabeledCreatableModuleFactory | undefined {\n return labels\n // Find the first factory that has labels and has all the labels provided\n ? (this._registry[schema]?.filter(hasLabels).find(factory => hasAllLabels(factory?.labels, labels)) ?? this._registry[schema]?.[0])\n // Otherwise, return the first factory\n : this._registry[schema]?.[0]\n }\n}\n","import { MemoryArchivist } from '@xyo-network/archivist-memory'\nimport { ViewArchivist } from '@xyo-network/archivist-view'\nimport { HttpBridge } from '@xyo-network/bridge-http'\nimport { MemoryBoundWitnessDiviner } from '@xyo-network/diviner-boundwitness-memory'\nimport { IdentityDiviner } from '@xyo-network/diviner-identity'\nimport { GenericPayloadDiviner } from '@xyo-network/diviner-payload-generic'\nimport { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport type { CreatableModuleFactory, LabeledCreatableModuleFactory } from '@xyo-network/module-model'\nimport { registerCreatableModuleFactories } from '@xyo-network/module-model'\nimport { MemoryNode } from '@xyo-network/node-memory'\nimport { ViewNode } from '@xyo-network/node-view'\nimport { MemorySentinel } from '@xyo-network/sentinel-memory'\nimport { AdhocWitness } from '@xyo-network/witness-adhoc'\n\n// order matters in this array. later items will register themselves as primary for schemas shared with earlier items\nexport const standardCreatableFactoriesList: (CreatableModuleFactory | LabeledCreatableModuleFactory)[] = [\n HttpBridge,\n ViewArchivist,\n ViewNode,\n AdhocWitness,\n MemoryPayloadDiviner,\n MemoryBoundWitnessDiviner,\n IdentityDiviner,\n MemoryArchivist,\n MemoryArchivist,\n MemoryNode,\n MemorySentinel,\n GenericPayloadDiviner,\n]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAOzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACXP,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,iCAAiC;AAC1C,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,4BAA4B;AAErC,SAAS,wCAAwC;AACjD,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC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AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAS,SAAiC,QAAiB,UAAuC,OAAa;AAC7G,aAAS,CAAC,KAAK,SAAS,MAAM,oEAAoE;AAClG,mCAA+B,KAAK,WAAW,SAAS,QAAQ,OAAO;AACvE,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAa,WAA2C;AACtD,eAAW,WAAW,WAAW;AAC/B,WAAK,SAAS,OAAO;AAAA,IACvB;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAU,QAAgB,QAAqF;AAC7G,WAAO,SAEF,KAAK,UAAU,MAAM,GAAG,OAAO,SAAS,EAAE,KAAK,aAAW,aAAa,SAAS,QAAQ,MAAM,CAAC,KAAK,KAAK,UAAU,MAAM,IAAI,CAAC,IAE/H,KAAK,UAAU,MAAM,IAAI,CAAC;AAAA,EAChC;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/module-factory-locator",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.11",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -29,25 +29,25 @@
|
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@xylabs/assert": "^4.
|
|
33
|
-
"@xyo-network/archivist-memory": "^3.6.
|
|
34
|
-
"@xyo-network/archivist-view": "^3.6.
|
|
35
|
-
"@xyo-network/bridge-http": "^3.6.
|
|
36
|
-
"@xyo-network/diviner-boundwitness-memory": "^3.6.
|
|
37
|
-
"@xyo-network/diviner-identity": "^3.6.
|
|
38
|
-
"@xyo-network/diviner-payload-generic": "^3.6.
|
|
39
|
-
"@xyo-network/diviner-payload-memory": "^3.6.
|
|
40
|
-
"@xyo-network/module-model": "^3.6.
|
|
41
|
-
"@xyo-network/node-memory": "^3.6.
|
|
42
|
-
"@xyo-network/node-view": "^3.6.
|
|
43
|
-
"@xyo-network/payload-model": "^3.6.
|
|
44
|
-
"@xyo-network/sentinel-memory": "^3.6.
|
|
45
|
-
"@xyo-network/witness-adhoc": "^3.6.
|
|
32
|
+
"@xylabs/assert": "^4.5.1",
|
|
33
|
+
"@xyo-network/archivist-memory": "^3.6.11",
|
|
34
|
+
"@xyo-network/archivist-view": "^3.6.11",
|
|
35
|
+
"@xyo-network/bridge-http": "^3.6.11",
|
|
36
|
+
"@xyo-network/diviner-boundwitness-memory": "^3.6.11",
|
|
37
|
+
"@xyo-network/diviner-identity": "^3.6.11",
|
|
38
|
+
"@xyo-network/diviner-payload-generic": "^3.6.11",
|
|
39
|
+
"@xyo-network/diviner-payload-memory": "^3.6.11",
|
|
40
|
+
"@xyo-network/module-model": "^3.6.11",
|
|
41
|
+
"@xyo-network/node-memory": "^3.6.11",
|
|
42
|
+
"@xyo-network/node-view": "^3.6.11",
|
|
43
|
+
"@xyo-network/payload-model": "^3.6.11",
|
|
44
|
+
"@xyo-network/sentinel-memory": "^3.6.11",
|
|
45
|
+
"@xyo-network/witness-adhoc": "^3.6.11"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@xylabs/ts-scripts-yarn3": "^4.2.6",
|
|
49
49
|
"@xylabs/tsconfig": "^4.2.6",
|
|
50
|
-
"typescript": "^5.7.
|
|
50
|
+
"typescript": "^5.7.3"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|