@xyo-network/module-factory-locator 2.107.3 → 2.107.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,119 @@
1
- "use strict";var m=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var a=(e,r)=>m(e,"name",{value:r,configurable:!0});var L=(e,r)=>{for(var t in r)m(e,t,{get:r[t],enumerable:!0})},N=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of A(r))!F.call(e,s)&&s!==t&&m(e,s,{get:()=>r[s],enumerable:!(i=C(r,s))||i.enumerable});return e};var $=e=>N(m({},"__esModule",{value:!0}),e);var D={};L(D,{ModuleFactoryLocator:()=>p,standardCreatableFactories:()=>n,standardCreatableFactoriesList:()=>_});module.exports=$(D);var v=require("@xylabs/assert"),o=require("@xyo-network/module-model");var f=require("@xyo-network/archivist-memory"),y=require("@xyo-network/archivist-view"),d=require("@xyo-network/bridge-http"),c=require("@xyo-network/diviner-boundwitness-memory"),g=require("@xyo-network/diviner-identity"),l=require("@xyo-network/diviner-payload-memory"),h=require("@xyo-network/module-model"),u=require("@xyo-network/node-memory"),M=require("@xyo-network/node-view"),b=require("@xyo-network/sentinel-memory"),x=require("@xyo-network/witness-adhoc");var _=[d.HttpBridge,y.ViewArchivist,M.ViewNode,x.AdhocWitness,l.MemoryPayloadDiviner,c.MemoryBoundWitnessDiviner,g.IdentityDiviner,f.MemoryArchivist,f.MemoryArchivist,u.MemoryNode,b.MemorySentinel],n=a(()=>(0,h.registerCreatableModuleFactories)(_,{},!0),"standardCreatableFactories");var p=class{static{a(this,"ModuleFactoryLocator")}_registry;constructor(r=n()){this._registry=r}get registry(){return this._registry}locate(r,t){return(0,v.assertEx)(this.tryLocate(r,t),()=>`No module factory for the supplied ${`config schema [${r}]`}${t?` & labels [${JSON.stringify(t)}]`:""} registered`)}register(r,t,i=!1){return(0,o.registerCreatableModuleFactory)(this._registry,r,t,i),this}registerMany(r){for(let t of r)this.register(t);return this}tryLocate(r,t){return t?this._registry[r]?.filter(o.hasLabels).find(i=>(0,o.hasAllLabels)(i?.labels,t)):this._registry[r]?.[0]}};
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ ModuleFactoryLocator: () => ModuleFactoryLocator,
25
+ standardCreatableFactories: () => standardCreatableFactories,
26
+ standardCreatableFactoriesList: () => standardCreatableFactoriesList
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/ModuleFactoryLocator.ts
31
+ var import_assert = require("@xylabs/assert");
32
+ var import_module_model2 = require("@xyo-network/module-model");
33
+
34
+ // src/standardCreatableFactories.ts
35
+ var import_archivist_memory = require("@xyo-network/archivist-memory");
36
+ var import_archivist_view = require("@xyo-network/archivist-view");
37
+ var import_bridge_http = require("@xyo-network/bridge-http");
38
+ var import_diviner_boundwitness_memory = require("@xyo-network/diviner-boundwitness-memory");
39
+ var import_diviner_identity = require("@xyo-network/diviner-identity");
40
+ var import_diviner_payload_memory = require("@xyo-network/diviner-payload-memory");
41
+ var import_module_model = require("@xyo-network/module-model");
42
+ var import_node_memory = require("@xyo-network/node-memory");
43
+ var import_node_view = require("@xyo-network/node-view");
44
+ var import_sentinel_memory = require("@xyo-network/sentinel-memory");
45
+ var import_witness_adhoc = require("@xyo-network/witness-adhoc");
46
+ var standardCreatableFactoriesList = [
47
+ import_bridge_http.HttpBridge,
48
+ import_archivist_view.ViewArchivist,
49
+ import_node_view.ViewNode,
50
+ import_witness_adhoc.AdhocWitness,
51
+ import_diviner_payload_memory.MemoryPayloadDiviner,
52
+ import_diviner_boundwitness_memory.MemoryBoundWitnessDiviner,
53
+ import_diviner_identity.IdentityDiviner,
54
+ import_archivist_memory.MemoryArchivist,
55
+ import_archivist_memory.MemoryArchivist,
56
+ import_node_memory.MemoryNode,
57
+ import_sentinel_memory.MemorySentinel
58
+ ];
59
+ var standardCreatableFactories = /* @__PURE__ */ __name(() => {
60
+ return (0, import_module_model.registerCreatableModuleFactories)(standardCreatableFactoriesList, {}, true);
61
+ }, "standardCreatableFactories");
62
+
63
+ // src/ModuleFactoryLocator.ts
64
+ var ModuleFactoryLocator = class {
65
+ static {
66
+ __name(this, "ModuleFactoryLocator");
67
+ }
68
+ _registry;
69
+ constructor(_registry = standardCreatableFactories()) {
70
+ this._registry = _registry;
71
+ }
72
+ /**
73
+ * The current registry for the module factory
74
+ */
75
+ get registry() {
76
+ return this._registry;
77
+ }
78
+ /**
79
+ * Locates a module factory that matches the supplied schema and labels
80
+ * @param schema The config schema for the module
81
+ * @param labels The labels for the module factory
82
+ * @returns A module factory that matches the supplied schema and labels or throws if one is not found
83
+ */
84
+ locate(schema, labels) {
85
+ return (0, import_assert.assertEx)(this.tryLocate(schema, labels), () => `No module factory for the supplied ${`config schema [${schema}]`}${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`);
86
+ }
87
+ /**
88
+ * Registers a single module factory (with optional tags) with the locator
89
+ * @param factory The factory to register
90
+ * @param labels The labels for the module factory
91
+ */
92
+ register(factory, labels, primary = false) {
93
+ (0, import_module_model2.registerCreatableModuleFactory)(this._registry, factory, labels, primary);
94
+ return this;
95
+ }
96
+ /**
97
+ * Registers multiple module factories with the locator
98
+ * @param factories The factories to register
99
+ */
100
+ registerMany(factories) {
101
+ for (const factory of factories) {
102
+ this.register(factory);
103
+ }
104
+ return this;
105
+ }
106
+ /**
107
+ * Tries to locate a module factory that matches the supplied schema and labels
108
+ * @param schema The config schema for the module
109
+ * @param labels The labels for the module factory
110
+ * @returns A module factory that matches the supplied schema and labels or undefined
111
+ */
112
+ tryLocate(schema, labels) {
113
+ return labels ? (
114
+ // Find the first factory that has labels and has all the labels provided
115
+ this._registry[schema]?.filter(import_module_model2.hasLabels).find((factory) => (0, import_module_model2.hasAllLabels)(factory?.labels, labels))
116
+ ) : this._registry[schema]?.[0];
117
+ }
118
+ };
2
119
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["export * from './ModuleFactoryLocator'\nexport * from './standardCreatableFactories'\n","import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,+BAAAC,EAAA,mCAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAAyB,0BACzBC,EAQO,qCCTP,IAAAC,EAAgC,yCAChCC,EAA8B,uCAC9BC,EAA2B,oCAC3BC,EAA0C,oDAC1CC,EAAgC,yCAChCC,EAAqC,+CACrCC,EAAwG,qCACxGC,EAA2B,oCAC3BC,EAAyB,kCACzBC,EAA+B,wCAC/BC,EAA6B,sCAGtB,IAAMC,EAA6F,CACxGC,aACAC,gBACAC,WACAC,eACAC,uBACAC,4BACAC,kBACAC,kBACAA,kBACAC,aACAC,kBAGWC,EAA6BC,EAAA,OACjCC,oCAAiCb,EAAgC,CAAC,EAAG,EAAA,EADpC,8BDVnC,IAAMc,EAAN,KAAMA,CAjBb,MAiBaA,CAAAA,EAAAA,uCACXC,YAA+BC,EAAqCC,EAAAA,EAA8B,MAAnED,UAAAA,CAAoE,CAKnG,IAAIE,UAA8C,CAChD,OAAO,KAAKF,SACd,CAQAG,OAAOC,EAAgBC,EAAyE,CAC9F,SAAOC,YACL,KAAKC,UAAUH,EAAQC,CAAAA,EACvB,IAAM,sCAAsC,kBAAkBD,CAAAA,GAAS,GAAGC,EAAS,cAAcG,KAAKC,UAAUJ,CAAAA,CAAAA,IAAa,EAAA,aAAe,CAEhJ,CAOAK,SAASC,EAAiCN,EAAiBO,EAAuC,GAAa,CAC7GC,2CAA+B,KAAKb,UAAWW,EAASN,EAAQO,CAAAA,EACzD,IACT,CAMAE,aAAaC,EAA2C,CACtD,QAAWJ,KAAWI,EACpB,KAAKL,SAASC,CAAAA,EAEhB,OAAO,IACT,CAQAJ,UAAUH,EAAgBC,EAAqF,CAE7G,OAAOA,EAEH,KAAKL,UAAUI,CAAAA,GAASY,OAAOC,WAAAA,EAAWC,KAAMP,MAAYQ,gBAAaR,GAASN,OAAQA,CAAAA,CAAAA,EAE1F,KAAKL,UAAUI,CAAAA,IAAU,CAAA,CAC/B,CACF","names":["src_exports","__export","ModuleFactoryLocator","standardCreatableFactories","standardCreatableFactoriesList","__toCommonJS","import_assert","import_module_model","import_archivist_memory","import_archivist_view","import_bridge_http","import_diviner_boundwitness_memory","import_diviner_identity","import_diviner_payload_memory","import_module_model","import_node_memory","import_node_view","import_sentinel_memory","import_witness_adhoc","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","__name","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","filter","hasLabels","find","hasAllLabels"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["export * from './ModuleFactoryLocator'\nexport * from './standardCreatableFactories'\n","import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,oBAAyB;AACzB,IAAAA,uBAQO;;;ACTP,8BAAgC;AAChC,4BAA8B;AAC9B,yBAA2B;AAC3B,yCAA0C;AAC1C,8BAAgC;AAChC,oCAAqC;AACrC,0BAAwG;AACxG,yBAA2B;AAC3B,uBAAyB;AACzB,6BAA+B;AAC/B,2BAA6B;AAGtB,IAAMC,iCAA6F;EACxGC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAA;EACAC;EACAC;;AAGK,IAAMC,6BAA6B,6BAAA;AACxC,aAAOC,sDAAiCZ,gCAAgC,CAAC,GAAG,IAAA;AAC9E,GAF0C;;;ADVnC,IAAMa,uBAAN,MAAMA;EAjBb,OAiBaA;;;;EACXC,YAA+BC,YAAqCC,2BAAAA,GAA8B;SAAnED,YAAAA;EAAoE;;;;EAKnG,IAAIE,WAA8C;AAChD,WAAO,KAAKF;EACd;;;;;;;EAQAG,OAAOC,QAAgBC,QAAyE;AAC9F,eAAOC,wBACL,KAAKC,UAAUH,QAAQC,MAAAA,GACvB,MAAM,sCAAsC,kBAAkBD,MAAAA,GAAS,GAAGC,SAAS,cAAcG,KAAKC,UAAUJ,MAAAA,CAAAA,MAAa,EAAA,aAAe;EAEhJ;;;;;;EAOAK,SAASC,SAAiCN,QAAiBO,UAAuC,OAAa;AAC7GC,6DAA+B,KAAKb,WAAWW,SAASN,QAAQO,OAAAA;AAChE,WAAO;EACT;;;;;EAMAE,aAAaC,WAA2C;AACtD,eAAWJ,WAAWI,WAAW;AAC/B,WAAKL,SAASC,OAAAA;IAChB;AACA,WAAO;EACT;;;;;;;EAQAJ,UAAUH,QAAgBC,QAAqF;AAE7G,WAAOA;;MAEH,KAAKL,UAAUI,MAAAA,GAASY,OAAOC,8BAAAA,EAAWC,KAAK,CAACP,gBAAYQ,mCAAaR,SAASN,QAAQA,MAAAA,CAAAA;QAE1F,KAAKL,UAAUI,MAAAA,IAAU,CAAA;EAC/B;AACF;","names":["import_module_model","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","filter","hasLabels","find","hasAllLabels"]}
@@ -1,2 +1,98 @@
1
- var f=Object.defineProperty;var e=(o,r)=>f(o,"name",{value:r,configurable:!0});import{assertEx as x}from"@xylabs/assert";import{hasAllLabels as _,hasLabels as v,registerCreatableModuleFactory as C}from"@xyo-network/module-model";import{MemoryArchivist as s}from"@xyo-network/archivist-memory";import{ViewArchivist as n}from"@xyo-network/archivist-view";import{HttpBridge as p}from"@xyo-network/bridge-http";import{MemoryBoundWitnessDiviner as y}from"@xyo-network/diviner-boundwitness-memory";import{IdentityDiviner as d}from"@xyo-network/diviner-identity";import{MemoryPayloadDiviner as c}from"@xyo-network/diviner-payload-memory";import{registerCreatableModuleFactories as g}from"@xyo-network/module-model";import{MemoryNode as l}from"@xyo-network/node-memory";import{ViewNode as h}from"@xyo-network/node-view";import{MemorySentinel as u}from"@xyo-network/sentinel-memory";import{AdhocWitness as M}from"@xyo-network/witness-adhoc";var b=[p,n,h,M,c,y,d,s,s,l,u],m=e(()=>g(b,{},!0),"standardCreatableFactories");var a=class{static{e(this,"ModuleFactoryLocator")}_registry;constructor(r=m()){this._registry=r}get registry(){return this._registry}locate(r,t){return x(this.tryLocate(r,t),()=>`No module factory for the supplied ${`config schema [${r}]`}${t?` & labels [${JSON.stringify(t)}]`:""} registered`)}register(r,t,i=!1){return C(this._registry,r,t,i),this}registerMany(r){for(let t of r)this.register(t);return this}tryLocate(r,t){return t?this._registry[r]?.filter(v).find(i=>_(i?.labels,t)):this._registry[r]?.[0]}};export{a as ModuleFactoryLocator,m as standardCreatableFactories,b as standardCreatableFactoriesList};
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/ModuleFactoryLocator.ts
5
+ import { assertEx } from "@xylabs/assert";
6
+ import { hasAllLabels, hasLabels, registerCreatableModuleFactory } from "@xyo-network/module-model";
7
+
8
+ // src/standardCreatableFactories.ts
9
+ import { MemoryArchivist } from "@xyo-network/archivist-memory";
10
+ import { ViewArchivist } from "@xyo-network/archivist-view";
11
+ import { HttpBridge } from "@xyo-network/bridge-http";
12
+ import { MemoryBoundWitnessDiviner } from "@xyo-network/diviner-boundwitness-memory";
13
+ import { IdentityDiviner } from "@xyo-network/diviner-identity";
14
+ import { MemoryPayloadDiviner } from "@xyo-network/diviner-payload-memory";
15
+ import { registerCreatableModuleFactories } from "@xyo-network/module-model";
16
+ import { MemoryNode } from "@xyo-network/node-memory";
17
+ import { ViewNode } from "@xyo-network/node-view";
18
+ import { MemorySentinel } from "@xyo-network/sentinel-memory";
19
+ import { AdhocWitness } from "@xyo-network/witness-adhoc";
20
+ var standardCreatableFactoriesList = [
21
+ HttpBridge,
22
+ ViewArchivist,
23
+ ViewNode,
24
+ AdhocWitness,
25
+ MemoryPayloadDiviner,
26
+ MemoryBoundWitnessDiviner,
27
+ IdentityDiviner,
28
+ MemoryArchivist,
29
+ MemoryArchivist,
30
+ MemoryNode,
31
+ MemorySentinel
32
+ ];
33
+ var standardCreatableFactories = /* @__PURE__ */ __name(() => {
34
+ return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true);
35
+ }, "standardCreatableFactories");
36
+
37
+ // src/ModuleFactoryLocator.ts
38
+ var ModuleFactoryLocator = class {
39
+ static {
40
+ __name(this, "ModuleFactoryLocator");
41
+ }
42
+ _registry;
43
+ constructor(_registry = standardCreatableFactories()) {
44
+ this._registry = _registry;
45
+ }
46
+ /**
47
+ * The current registry for the module factory
48
+ */
49
+ get registry() {
50
+ return this._registry;
51
+ }
52
+ /**
53
+ * Locates a module factory that matches the supplied schema and labels
54
+ * @param schema The config schema for the module
55
+ * @param labels The labels for the module factory
56
+ * @returns A module factory that matches the supplied schema and labels or throws if one is not found
57
+ */
58
+ locate(schema, labels) {
59
+ return assertEx(this.tryLocate(schema, labels), () => `No module factory for the supplied ${`config schema [${schema}]`}${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`);
60
+ }
61
+ /**
62
+ * Registers a single module factory (with optional tags) with the locator
63
+ * @param factory The factory to register
64
+ * @param labels The labels for the module factory
65
+ */
66
+ register(factory, labels, primary = false) {
67
+ registerCreatableModuleFactory(this._registry, factory, labels, primary);
68
+ return this;
69
+ }
70
+ /**
71
+ * Registers multiple module factories with the locator
72
+ * @param factories The factories to register
73
+ */
74
+ registerMany(factories) {
75
+ for (const factory of factories) {
76
+ this.register(factory);
77
+ }
78
+ return this;
79
+ }
80
+ /**
81
+ * Tries to locate a module factory that matches the supplied schema and labels
82
+ * @param schema The config schema for the module
83
+ * @param labels The labels for the module factory
84
+ * @returns A module factory that matches the supplied schema and labels or undefined
85
+ */
86
+ tryLocate(schema, labels) {
87
+ return labels ? (
88
+ // Find the first factory that has labels and has all the labels provided
89
+ this._registry[schema]?.filter(hasLabels).find((factory) => hasAllLabels(factory?.labels, labels))
90
+ ) : this._registry[schema]?.[0];
91
+ }
92
+ };
93
+ export {
94
+ ModuleFactoryLocator,
95
+ standardCreatableFactories,
96
+ standardCreatableFactoriesList
97
+ };
2
98
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":"+EAAA,OAASA,YAAAA,MAAgB,iBACzB,OAGEC,gBAAAA,EACAC,aAAAA,EAGAC,kCAAAA,MACK,4BCTP,OAASC,mBAAAA,MAAuB,gCAChC,OAASC,iBAAAA,MAAqB,8BAC9B,OAASC,cAAAA,MAAkB,2BAC3B,OAASC,6BAAAA,MAAiC,2CAC1C,OAASC,mBAAAA,MAAuB,gCAChC,OAASC,wBAAAA,MAA4B,sCACrC,OAAgEC,oCAAAA,MAAwC,4BACxG,OAASC,cAAAA,MAAkB,2BAC3B,OAASC,YAAAA,MAAgB,yBACzB,OAASC,kBAAAA,MAAsB,+BAC/B,OAASC,gBAAAA,MAAoB,6BAGtB,IAAMC,EAA6F,CACxGC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAA,EACAC,EACAC,GAGWC,EAA6BC,EAAA,IACjCC,EAAiCb,EAAgC,CAAC,EAAG,EAAA,EADpC,8BDVnC,IAAMc,EAAN,KAAMA,CAjBb,MAiBaA,CAAAA,EAAAA,uCACXC,YAA+BC,EAAqCC,EAAAA,EAA8B,MAAnED,UAAAA,CAAoE,CAKnG,IAAIE,UAA8C,CAChD,OAAO,KAAKF,SACd,CAQAG,OAAOC,EAAgBC,EAAyE,CAC9F,OAAOC,EACL,KAAKC,UAAUH,EAAQC,CAAAA,EACvB,IAAM,sCAAsC,kBAAkBD,CAAAA,GAAS,GAAGC,EAAS,cAAcG,KAAKC,UAAUJ,CAAAA,CAAAA,IAAa,EAAA,aAAe,CAEhJ,CAOAK,SAASC,EAAiCN,EAAiBO,EAAuC,GAAa,CAC7GC,OAAAA,EAA+B,KAAKb,UAAWW,EAASN,EAAQO,CAAAA,EACzD,IACT,CAMAE,aAAaC,EAA2C,CACtD,QAAWJ,KAAWI,EACpB,KAAKL,SAASC,CAAAA,EAEhB,OAAO,IACT,CAQAJ,UAAUH,EAAgBC,EAAqF,CAE7G,OAAOA,EAEH,KAAKL,UAAUI,CAAAA,GAASY,OAAOC,CAAAA,EAAWC,KAAMP,GAAYQ,EAAaR,GAASN,OAAQA,CAAAA,CAAAA,EAE1F,KAAKL,UAAUI,CAAAA,IAAU,CAAA,CAC/B,CACF","names":["assertEx","hasAllLabels","hasLabels","registerCreatableModuleFactory","MemoryArchivist","ViewArchivist","HttpBridge","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryPayloadDiviner","registerCreatableModuleFactories","MemoryNode","ViewNode","MemorySentinel","AdhocWitness","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","__name","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","filter","hasLabels","find","hasAllLabels"]}
1
+ {"version":3,"sources":["../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAGEC,cACAC,WAGAC,sCACK;;;ACTP,SAASC,uBAAuB;AAChC,SAASC,qBAAqB;AAC9B,SAASC,kBAAkB;AAC3B,SAASC,iCAAiC;AAC1C,SAASC,uBAAuB;AAChC,SAASC,4BAA4B;AACrC,SAAgEC,wCAAwC;AACxG,SAASC,kBAAkB;AAC3B,SAASC,gBAAgB;AACzB,SAASC,sBAAsB;AAC/B,SAASC,oBAAoB;AAGtB,IAAMC,iCAA6F;EACxGC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAA;EACAC;EACAC;;AAGK,IAAMC,6BAA6B,6BAAA;AACxC,SAAOC,iCAAiCZ,gCAAgC,CAAC,GAAG,IAAA;AAC9E,GAF0C;;;ADVnC,IAAMa,uBAAN,MAAMA;EAjBb,OAiBaA;;;;EACXC,YAA+BC,YAAqCC,2BAAAA,GAA8B;SAAnED,YAAAA;EAAoE;;;;EAKnG,IAAIE,WAA8C;AAChD,WAAO,KAAKF;EACd;;;;;;;EAQAG,OAAOC,QAAgBC,QAAyE;AAC9F,WAAOC,SACL,KAAKC,UAAUH,QAAQC,MAAAA,GACvB,MAAM,sCAAsC,kBAAkBD,MAAAA,GAAS,GAAGC,SAAS,cAAcG,KAAKC,UAAUJ,MAAAA,CAAAA,MAAa,EAAA,aAAe;EAEhJ;;;;;;EAOAK,SAASC,SAAiCN,QAAiBO,UAAuC,OAAa;AAC7GC,mCAA+B,KAAKb,WAAWW,SAASN,QAAQO,OAAAA;AAChE,WAAO;EACT;;;;;EAMAE,aAAaC,WAA2C;AACtD,eAAWJ,WAAWI,WAAW;AAC/B,WAAKL,SAASC,OAAAA;IAChB;AACA,WAAO;EACT;;;;;;;EAQAJ,UAAUH,QAAgBC,QAAqF;AAE7G,WAAOA;;MAEH,KAAKL,UAAUI,MAAAA,GAASY,OAAOC,SAAAA,EAAWC,KAAK,CAACP,YAAYQ,aAAaR,SAASN,QAAQA,MAAAA,CAAAA;QAE1F,KAAKL,UAAUI,MAAAA,IAAU,CAAA;EAC/B;AACF;","names":["assertEx","hasAllLabels","hasLabels","registerCreatableModuleFactory","MemoryArchivist","ViewArchivist","HttpBridge","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryPayloadDiviner","registerCreatableModuleFactories","MemoryNode","ViewNode","MemorySentinel","AdhocWitness","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","filter","hasLabels","find","hasAllLabels"]}
@@ -1,2 +1,119 @@
1
- "use strict";var m=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var a=(e,r)=>m(e,"name",{value:r,configurable:!0});var L=(e,r)=>{for(var t in r)m(e,t,{get:r[t],enumerable:!0})},N=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of A(r))!F.call(e,s)&&s!==t&&m(e,s,{get:()=>r[s],enumerable:!(i=C(r,s))||i.enumerable});return e};var $=e=>N(m({},"__esModule",{value:!0}),e);var D={};L(D,{ModuleFactoryLocator:()=>p,standardCreatableFactories:()=>n,standardCreatableFactoriesList:()=>_});module.exports=$(D);var v=require("@xylabs/assert"),o=require("@xyo-network/module-model");var f=require("@xyo-network/archivist-memory"),y=require("@xyo-network/archivist-view"),d=require("@xyo-network/bridge-http"),c=require("@xyo-network/diviner-boundwitness-memory"),g=require("@xyo-network/diviner-identity"),l=require("@xyo-network/diviner-payload-memory"),h=require("@xyo-network/module-model"),u=require("@xyo-network/node-memory"),M=require("@xyo-network/node-view"),b=require("@xyo-network/sentinel-memory"),x=require("@xyo-network/witness-adhoc");var _=[d.HttpBridge,y.ViewArchivist,M.ViewNode,x.AdhocWitness,l.MemoryPayloadDiviner,c.MemoryBoundWitnessDiviner,g.IdentityDiviner,f.MemoryArchivist,f.MemoryArchivist,u.MemoryNode,b.MemorySentinel],n=a(()=>(0,h.registerCreatableModuleFactories)(_,{},!0),"standardCreatableFactories");var p=class{static{a(this,"ModuleFactoryLocator")}_registry;constructor(r=n()){this._registry=r}get registry(){return this._registry}locate(r,t){return(0,v.assertEx)(this.tryLocate(r,t),()=>`No module factory for the supplied ${`config schema [${r}]`}${t?` & labels [${JSON.stringify(t)}]`:""} registered`)}register(r,t,i=!1){return(0,o.registerCreatableModuleFactory)(this._registry,r,t,i),this}registerMany(r){for(let t of r)this.register(t);return this}tryLocate(r,t){return t?this._registry[r]?.filter(o.hasLabels).find(i=>(0,o.hasAllLabels)(i?.labels,t)):this._registry[r]?.[0]}};
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ ModuleFactoryLocator: () => ModuleFactoryLocator,
25
+ standardCreatableFactories: () => standardCreatableFactories,
26
+ standardCreatableFactoriesList: () => standardCreatableFactoriesList
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/ModuleFactoryLocator.ts
31
+ var import_assert = require("@xylabs/assert");
32
+ var import_module_model2 = require("@xyo-network/module-model");
33
+
34
+ // src/standardCreatableFactories.ts
35
+ var import_archivist_memory = require("@xyo-network/archivist-memory");
36
+ var import_archivist_view = require("@xyo-network/archivist-view");
37
+ var import_bridge_http = require("@xyo-network/bridge-http");
38
+ var import_diviner_boundwitness_memory = require("@xyo-network/diviner-boundwitness-memory");
39
+ var import_diviner_identity = require("@xyo-network/diviner-identity");
40
+ var import_diviner_payload_memory = require("@xyo-network/diviner-payload-memory");
41
+ var import_module_model = require("@xyo-network/module-model");
42
+ var import_node_memory = require("@xyo-network/node-memory");
43
+ var import_node_view = require("@xyo-network/node-view");
44
+ var import_sentinel_memory = require("@xyo-network/sentinel-memory");
45
+ var import_witness_adhoc = require("@xyo-network/witness-adhoc");
46
+ var standardCreatableFactoriesList = [
47
+ import_bridge_http.HttpBridge,
48
+ import_archivist_view.ViewArchivist,
49
+ import_node_view.ViewNode,
50
+ import_witness_adhoc.AdhocWitness,
51
+ import_diviner_payload_memory.MemoryPayloadDiviner,
52
+ import_diviner_boundwitness_memory.MemoryBoundWitnessDiviner,
53
+ import_diviner_identity.IdentityDiviner,
54
+ import_archivist_memory.MemoryArchivist,
55
+ import_archivist_memory.MemoryArchivist,
56
+ import_node_memory.MemoryNode,
57
+ import_sentinel_memory.MemorySentinel
58
+ ];
59
+ var standardCreatableFactories = /* @__PURE__ */ __name(() => {
60
+ return (0, import_module_model.registerCreatableModuleFactories)(standardCreatableFactoriesList, {}, true);
61
+ }, "standardCreatableFactories");
62
+
63
+ // src/ModuleFactoryLocator.ts
64
+ var ModuleFactoryLocator = class {
65
+ static {
66
+ __name(this, "ModuleFactoryLocator");
67
+ }
68
+ _registry;
69
+ constructor(_registry = standardCreatableFactories()) {
70
+ this._registry = _registry;
71
+ }
72
+ /**
73
+ * The current registry for the module factory
74
+ */
75
+ get registry() {
76
+ return this._registry;
77
+ }
78
+ /**
79
+ * Locates a module factory that matches the supplied schema and labels
80
+ * @param schema The config schema for the module
81
+ * @param labels The labels for the module factory
82
+ * @returns A module factory that matches the supplied schema and labels or throws if one is not found
83
+ */
84
+ locate(schema, labels) {
85
+ return (0, import_assert.assertEx)(this.tryLocate(schema, labels), () => `No module factory for the supplied ${`config schema [${schema}]`}${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`);
86
+ }
87
+ /**
88
+ * Registers a single module factory (with optional tags) with the locator
89
+ * @param factory The factory to register
90
+ * @param labels The labels for the module factory
91
+ */
92
+ register(factory, labels, primary = false) {
93
+ (0, import_module_model2.registerCreatableModuleFactory)(this._registry, factory, labels, primary);
94
+ return this;
95
+ }
96
+ /**
97
+ * Registers multiple module factories with the locator
98
+ * @param factories The factories to register
99
+ */
100
+ registerMany(factories) {
101
+ for (const factory of factories) {
102
+ this.register(factory);
103
+ }
104
+ return this;
105
+ }
106
+ /**
107
+ * Tries to locate a module factory that matches the supplied schema and labels
108
+ * @param schema The config schema for the module
109
+ * @param labels The labels for the module factory
110
+ * @returns A module factory that matches the supplied schema and labels or undefined
111
+ */
112
+ tryLocate(schema, labels) {
113
+ return labels ? (
114
+ // Find the first factory that has labels and has all the labels provided
115
+ this._registry[schema]?.filter(import_module_model2.hasLabels).find((factory) => (0, import_module_model2.hasAllLabels)(factory?.labels, labels))
116
+ ) : this._registry[schema]?.[0];
117
+ }
118
+ };
2
119
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["export * from './ModuleFactoryLocator'\nexport * from './standardCreatableFactories'\n","import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,+BAAAC,EAAA,mCAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAAyB,0BACzBC,EAQO,qCCTP,IAAAC,EAAgC,yCAChCC,EAA8B,uCAC9BC,EAA2B,oCAC3BC,EAA0C,oDAC1CC,EAAgC,yCAChCC,EAAqC,+CACrCC,EAAwG,qCACxGC,EAA2B,oCAC3BC,EAAyB,kCACzBC,EAA+B,wCAC/BC,EAA6B,sCAGtB,IAAMC,EAA6F,CACxGC,aACAC,gBACAC,WACAC,eACAC,uBACAC,4BACAC,kBACAC,kBACAA,kBACAC,aACAC,kBAGWC,EAA6BC,EAAA,OACjCC,oCAAiCb,EAAgC,CAAC,EAAG,EAAA,EADpC,8BDVnC,IAAMc,EAAN,KAAMA,CAjBb,MAiBaA,CAAAA,EAAAA,uCACXC,YAA+BC,EAAqCC,EAAAA,EAA8B,MAAnED,UAAAA,CAAoE,CAKnG,IAAIE,UAA8C,CAChD,OAAO,KAAKF,SACd,CAQAG,OAAOC,EAAgBC,EAAyE,CAC9F,SAAOC,YACL,KAAKC,UAAUH,EAAQC,CAAAA,EACvB,IAAM,sCAAsC,kBAAkBD,CAAAA,GAAS,GAAGC,EAAS,cAAcG,KAAKC,UAAUJ,CAAAA,CAAAA,IAAa,EAAA,aAAe,CAEhJ,CAOAK,SAASC,EAAiCN,EAAiBO,EAAuC,GAAa,CAC7GC,2CAA+B,KAAKb,UAAWW,EAASN,EAAQO,CAAAA,EACzD,IACT,CAMAE,aAAaC,EAA2C,CACtD,QAAWJ,KAAWI,EACpB,KAAKL,SAASC,CAAAA,EAEhB,OAAO,IACT,CAQAJ,UAAUH,EAAgBC,EAAqF,CAE7G,OAAOA,EAEH,KAAKL,UAAUI,CAAAA,GAASY,OAAOC,WAAAA,EAAWC,KAAMP,MAAYQ,gBAAaR,GAASN,OAAQA,CAAAA,CAAAA,EAE1F,KAAKL,UAAUI,CAAAA,IAAU,CAAA,CAC/B,CACF","names":["src_exports","__export","ModuleFactoryLocator","standardCreatableFactories","standardCreatableFactoriesList","__toCommonJS","import_assert","import_module_model","import_archivist_memory","import_archivist_view","import_bridge_http","import_diviner_boundwitness_memory","import_diviner_identity","import_diviner_payload_memory","import_module_model","import_node_memory","import_node_view","import_sentinel_memory","import_witness_adhoc","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","__name","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","filter","hasLabels","find","hasAllLabels"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["export * from './ModuleFactoryLocator'\nexport * from './standardCreatableFactories'\n","import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,oBAAyB;AACzB,IAAAA,uBAQO;;;ACTP,8BAAgC;AAChC,4BAA8B;AAC9B,yBAA2B;AAC3B,yCAA0C;AAC1C,8BAAgC;AAChC,oCAAqC;AACrC,0BAAwG;AACxG,yBAA2B;AAC3B,uBAAyB;AACzB,6BAA+B;AAC/B,2BAA6B;AAGtB,IAAMC,iCAA6F;EACxGC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAA;EACAC;EACAC;;AAGK,IAAMC,6BAA6B,6BAAA;AACxC,aAAOC,sDAAiCZ,gCAAgC,CAAC,GAAG,IAAA;AAC9E,GAF0C;;;ADVnC,IAAMa,uBAAN,MAAMA;EAjBb,OAiBaA;;;;EACXC,YAA+BC,YAAqCC,2BAAAA,GAA8B;SAAnED,YAAAA;EAAoE;;;;EAKnG,IAAIE,WAA8C;AAChD,WAAO,KAAKF;EACd;;;;;;;EAQAG,OAAOC,QAAgBC,QAAyE;AAC9F,eAAOC,wBACL,KAAKC,UAAUH,QAAQC,MAAAA,GACvB,MAAM,sCAAsC,kBAAkBD,MAAAA,GAAS,GAAGC,SAAS,cAAcG,KAAKC,UAAUJ,MAAAA,CAAAA,MAAa,EAAA,aAAe;EAEhJ;;;;;;EAOAK,SAASC,SAAiCN,QAAiBO,UAAuC,OAAa;AAC7GC,6DAA+B,KAAKb,WAAWW,SAASN,QAAQO,OAAAA;AAChE,WAAO;EACT;;;;;EAMAE,aAAaC,WAA2C;AACtD,eAAWJ,WAAWI,WAAW;AAC/B,WAAKL,SAASC,OAAAA;IAChB;AACA,WAAO;EACT;;;;;;;EAQAJ,UAAUH,QAAgBC,QAAqF;AAE7G,WAAOA;;MAEH,KAAKL,UAAUI,MAAAA,GAASY,OAAOC,8BAAAA,EAAWC,KAAK,CAACP,gBAAYQ,mCAAaR,SAASN,QAAQA,MAAAA,CAAAA;QAE1F,KAAKL,UAAUI,MAAAA,IAAU,CAAA;EAC/B;AACF;","names":["import_module_model","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","filter","hasLabels","find","hasAllLabels"]}
@@ -1,2 +1,98 @@
1
- var f=Object.defineProperty;var e=(o,r)=>f(o,"name",{value:r,configurable:!0});import{assertEx as x}from"@xylabs/assert";import{hasAllLabels as _,hasLabels as v,registerCreatableModuleFactory as C}from"@xyo-network/module-model";import{MemoryArchivist as s}from"@xyo-network/archivist-memory";import{ViewArchivist as n}from"@xyo-network/archivist-view";import{HttpBridge as p}from"@xyo-network/bridge-http";import{MemoryBoundWitnessDiviner as y}from"@xyo-network/diviner-boundwitness-memory";import{IdentityDiviner as d}from"@xyo-network/diviner-identity";import{MemoryPayloadDiviner as c}from"@xyo-network/diviner-payload-memory";import{registerCreatableModuleFactories as g}from"@xyo-network/module-model";import{MemoryNode as l}from"@xyo-network/node-memory";import{ViewNode as h}from"@xyo-network/node-view";import{MemorySentinel as u}from"@xyo-network/sentinel-memory";import{AdhocWitness as M}from"@xyo-network/witness-adhoc";var b=[p,n,h,M,c,y,d,s,s,l,u],m=e(()=>g(b,{},!0),"standardCreatableFactories");var a=class{static{e(this,"ModuleFactoryLocator")}_registry;constructor(r=m()){this._registry=r}get registry(){return this._registry}locate(r,t){return x(this.tryLocate(r,t),()=>`No module factory for the supplied ${`config schema [${r}]`}${t?` & labels [${JSON.stringify(t)}]`:""} registered`)}register(r,t,i=!1){return C(this._registry,r,t,i),this}registerMany(r){for(let t of r)this.register(t);return this}tryLocate(r,t){return t?this._registry[r]?.filter(v).find(i=>_(i?.labels,t)):this._registry[r]?.[0]}};export{a as ModuleFactoryLocator,m as standardCreatableFactories,b as standardCreatableFactoriesList};
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/ModuleFactoryLocator.ts
5
+ import { assertEx } from "@xylabs/assert";
6
+ import { hasAllLabels, hasLabels, registerCreatableModuleFactory } from "@xyo-network/module-model";
7
+
8
+ // src/standardCreatableFactories.ts
9
+ import { MemoryArchivist } from "@xyo-network/archivist-memory";
10
+ import { ViewArchivist } from "@xyo-network/archivist-view";
11
+ import { HttpBridge } from "@xyo-network/bridge-http";
12
+ import { MemoryBoundWitnessDiviner } from "@xyo-network/diviner-boundwitness-memory";
13
+ import { IdentityDiviner } from "@xyo-network/diviner-identity";
14
+ import { MemoryPayloadDiviner } from "@xyo-network/diviner-payload-memory";
15
+ import { registerCreatableModuleFactories } from "@xyo-network/module-model";
16
+ import { MemoryNode } from "@xyo-network/node-memory";
17
+ import { ViewNode } from "@xyo-network/node-view";
18
+ import { MemorySentinel } from "@xyo-network/sentinel-memory";
19
+ import { AdhocWitness } from "@xyo-network/witness-adhoc";
20
+ var standardCreatableFactoriesList = [
21
+ HttpBridge,
22
+ ViewArchivist,
23
+ ViewNode,
24
+ AdhocWitness,
25
+ MemoryPayloadDiviner,
26
+ MemoryBoundWitnessDiviner,
27
+ IdentityDiviner,
28
+ MemoryArchivist,
29
+ MemoryArchivist,
30
+ MemoryNode,
31
+ MemorySentinel
32
+ ];
33
+ var standardCreatableFactories = /* @__PURE__ */ __name(() => {
34
+ return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true);
35
+ }, "standardCreatableFactories");
36
+
37
+ // src/ModuleFactoryLocator.ts
38
+ var ModuleFactoryLocator = class {
39
+ static {
40
+ __name(this, "ModuleFactoryLocator");
41
+ }
42
+ _registry;
43
+ constructor(_registry = standardCreatableFactories()) {
44
+ this._registry = _registry;
45
+ }
46
+ /**
47
+ * The current registry for the module factory
48
+ */
49
+ get registry() {
50
+ return this._registry;
51
+ }
52
+ /**
53
+ * Locates a module factory that matches the supplied schema and labels
54
+ * @param schema The config schema for the module
55
+ * @param labels The labels for the module factory
56
+ * @returns A module factory that matches the supplied schema and labels or throws if one is not found
57
+ */
58
+ locate(schema, labels) {
59
+ return assertEx(this.tryLocate(schema, labels), () => `No module factory for the supplied ${`config schema [${schema}]`}${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`);
60
+ }
61
+ /**
62
+ * Registers a single module factory (with optional tags) with the locator
63
+ * @param factory The factory to register
64
+ * @param labels The labels for the module factory
65
+ */
66
+ register(factory, labels, primary = false) {
67
+ registerCreatableModuleFactory(this._registry, factory, labels, primary);
68
+ return this;
69
+ }
70
+ /**
71
+ * Registers multiple module factories with the locator
72
+ * @param factories The factories to register
73
+ */
74
+ registerMany(factories) {
75
+ for (const factory of factories) {
76
+ this.register(factory);
77
+ }
78
+ return this;
79
+ }
80
+ /**
81
+ * Tries to locate a module factory that matches the supplied schema and labels
82
+ * @param schema The config schema for the module
83
+ * @param labels The labels for the module factory
84
+ * @returns A module factory that matches the supplied schema and labels or undefined
85
+ */
86
+ tryLocate(schema, labels) {
87
+ return labels ? (
88
+ // Find the first factory that has labels and has all the labels provided
89
+ this._registry[schema]?.filter(hasLabels).find((factory) => hasAllLabels(factory?.labels, labels))
90
+ ) : this._registry[schema]?.[0];
91
+ }
92
+ };
93
+ export {
94
+ ModuleFactoryLocator,
95
+ standardCreatableFactories,
96
+ standardCreatableFactoriesList
97
+ };
2
98
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":"+EAAA,OAASA,YAAAA,MAAgB,iBACzB,OAGEC,gBAAAA,EACAC,aAAAA,EAGAC,kCAAAA,MACK,4BCTP,OAASC,mBAAAA,MAAuB,gCAChC,OAASC,iBAAAA,MAAqB,8BAC9B,OAASC,cAAAA,MAAkB,2BAC3B,OAASC,6BAAAA,MAAiC,2CAC1C,OAASC,mBAAAA,MAAuB,gCAChC,OAASC,wBAAAA,MAA4B,sCACrC,OAAgEC,oCAAAA,MAAwC,4BACxG,OAASC,cAAAA,MAAkB,2BAC3B,OAASC,YAAAA,MAAgB,yBACzB,OAASC,kBAAAA,MAAsB,+BAC/B,OAASC,gBAAAA,MAAoB,6BAGtB,IAAMC,EAA6F,CACxGC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAA,EACAC,EACAC,GAGWC,EAA6BC,EAAA,IACjCC,EAAiCb,EAAgC,CAAC,EAAG,EAAA,EADpC,8BDVnC,IAAMc,EAAN,KAAMA,CAjBb,MAiBaA,CAAAA,EAAAA,uCACXC,YAA+BC,EAAqCC,EAAAA,EAA8B,MAAnED,UAAAA,CAAoE,CAKnG,IAAIE,UAA8C,CAChD,OAAO,KAAKF,SACd,CAQAG,OAAOC,EAAgBC,EAAyE,CAC9F,OAAOC,EACL,KAAKC,UAAUH,EAAQC,CAAAA,EACvB,IAAM,sCAAsC,kBAAkBD,CAAAA,GAAS,GAAGC,EAAS,cAAcG,KAAKC,UAAUJ,CAAAA,CAAAA,IAAa,EAAA,aAAe,CAEhJ,CAOAK,SAASC,EAAiCN,EAAiBO,EAAuC,GAAa,CAC7GC,OAAAA,EAA+B,KAAKb,UAAWW,EAASN,EAAQO,CAAAA,EACzD,IACT,CAMAE,aAAaC,EAA2C,CACtD,QAAWJ,KAAWI,EACpB,KAAKL,SAASC,CAAAA,EAEhB,OAAO,IACT,CAQAJ,UAAUH,EAAgBC,EAAqF,CAE7G,OAAOA,EAEH,KAAKL,UAAUI,CAAAA,GAASY,OAAOC,CAAAA,EAAWC,KAAMP,GAAYQ,EAAaR,GAASN,OAAQA,CAAAA,CAAAA,EAE1F,KAAKL,UAAUI,CAAAA,IAAU,CAAA,CAC/B,CACF","names":["assertEx","hasAllLabels","hasLabels","registerCreatableModuleFactory","MemoryArchivist","ViewArchivist","HttpBridge","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryPayloadDiviner","registerCreatableModuleFactories","MemoryNode","ViewNode","MemorySentinel","AdhocWitness","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","__name","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","filter","hasLabels","find","hasAllLabels"]}
1
+ {"version":3,"sources":["../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAGEC,cACAC,WAGAC,sCACK;;;ACTP,SAASC,uBAAuB;AAChC,SAASC,qBAAqB;AAC9B,SAASC,kBAAkB;AAC3B,SAASC,iCAAiC;AAC1C,SAASC,uBAAuB;AAChC,SAASC,4BAA4B;AACrC,SAAgEC,wCAAwC;AACxG,SAASC,kBAAkB;AAC3B,SAASC,gBAAgB;AACzB,SAASC,sBAAsB;AAC/B,SAASC,oBAAoB;AAGtB,IAAMC,iCAA6F;EACxGC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAA;EACAC;EACAC;;AAGK,IAAMC,6BAA6B,6BAAA;AACxC,SAAOC,iCAAiCZ,gCAAgC,CAAC,GAAG,IAAA;AAC9E,GAF0C;;;ADVnC,IAAMa,uBAAN,MAAMA;EAjBb,OAiBaA;;;;EACXC,YAA+BC,YAAqCC,2BAAAA,GAA8B;SAAnED,YAAAA;EAAoE;;;;EAKnG,IAAIE,WAA8C;AAChD,WAAO,KAAKF;EACd;;;;;;;EAQAG,OAAOC,QAAgBC,QAAyE;AAC9F,WAAOC,SACL,KAAKC,UAAUH,QAAQC,MAAAA,GACvB,MAAM,sCAAsC,kBAAkBD,MAAAA,GAAS,GAAGC,SAAS,cAAcG,KAAKC,UAAUJ,MAAAA,CAAAA,MAAa,EAAA,aAAe;EAEhJ;;;;;;EAOAK,SAASC,SAAiCN,QAAiBO,UAAuC,OAAa;AAC7GC,mCAA+B,KAAKb,WAAWW,SAASN,QAAQO,OAAAA;AAChE,WAAO;EACT;;;;;EAMAE,aAAaC,WAA2C;AACtD,eAAWJ,WAAWI,WAAW;AAC/B,WAAKL,SAASC,OAAAA;IAChB;AACA,WAAO;EACT;;;;;;;EAQAJ,UAAUH,QAAgBC,QAAqF;AAE7G,WAAOA;;MAEH,KAAKL,UAAUI,MAAAA,GAASY,OAAOC,SAAAA,EAAWC,KAAK,CAACP,YAAYQ,aAAaR,SAASN,QAAQA,MAAAA,CAAAA;QAE1F,KAAKL,UAAUI,MAAAA,IAAU,CAAA;EAC/B;AACF;","names":["assertEx","hasAllLabels","hasLabels","registerCreatableModuleFactory","MemoryArchivist","ViewArchivist","HttpBridge","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryPayloadDiviner","registerCreatableModuleFactories","MemoryNode","ViewNode","MemorySentinel","AdhocWitness","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","filter","hasLabels","find","hasAllLabels"]}
@@ -1,2 +1,125 @@
1
- "use strict";var m=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var a=(e,r)=>m(e,"name",{value:r,configurable:!0});var F=(e,r)=>{for(var t in r)m(e,t,{get:r[t],enumerable:!0})},L=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of $(r))!D.call(e,i)&&i!==t&&m(e,i,{get:()=>r[i],enumerable:!(o=N(r,i))||o.enumerable});return e};var w=e=>L(m({},"__esModule",{value:!0}),e);var B={};F(B,{ModuleFactoryLocator:()=>d,standardCreatableFactories:()=>p,standardCreatableFactoriesList:()=>_});module.exports=w(B);var A=require("@xylabs/assert"),s=require("@xyo-network/module-model");var f=require("@xyo-network/archivist-memory"),l=require("@xyo-network/archivist-view"),y=require("@xyo-network/bridge-http"),h=require("@xyo-network/diviner-boundwitness-memory"),c=require("@xyo-network/diviner-identity"),u=require("@xyo-network/diviner-payload-memory"),b=require("@xyo-network/module-model"),x=require("@xyo-network/node-memory"),M=require("@xyo-network/node-view"),v=require("@xyo-network/sentinel-memory"),C=require("@xyo-network/witness-adhoc");var _=[y.HttpBridge,l.ViewArchivist,M.ViewNode,C.AdhocWitness,u.MemoryPayloadDiviner,h.MemoryBoundWitnessDiviner,c.IdentityDiviner,f.MemoryArchivist,f.MemoryArchivist,x.MemoryNode,v.MemorySentinel],p=a(()=>(0,b.registerCreatableModuleFactories)(_,{},!0),"standardCreatableFactories");var g=class g{_registry;constructor(r=p()){this._registry=r}get registry(){return this._registry}locate(r,t){return(0,A.assertEx)(this.tryLocate(r,t),()=>`No module factory for the supplied ${`config schema [${r}]`}${t?` & labels [${JSON.stringify(t)}]`:""} registered`)}register(r,t,o=!1){return(0,s.registerCreatableModuleFactory)(this._registry,r,t,o),this}registerMany(r){for(let t of r)this.register(t);return this}tryLocate(r,t){var o,i;return t?(o=this._registry[r])==null?void 0:o.filter(s.hasLabels).find(n=>(0,s.hasAllLabels)(n==null?void 0:n.labels,t)):(i=this._registry[r])==null?void 0:i[0]}};a(g,"ModuleFactoryLocator");var d=g;0&&(module.exports={ModuleFactoryLocator,standardCreatableFactories,standardCreatableFactoriesList});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ ModuleFactoryLocator: () => ModuleFactoryLocator,
25
+ standardCreatableFactories: () => standardCreatableFactories,
26
+ standardCreatableFactoriesList: () => standardCreatableFactoriesList
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/ModuleFactoryLocator.ts
31
+ var import_assert = require("@xylabs/assert");
32
+ var import_module_model2 = require("@xyo-network/module-model");
33
+
34
+ // src/standardCreatableFactories.ts
35
+ var import_archivist_memory = require("@xyo-network/archivist-memory");
36
+ var import_archivist_view = require("@xyo-network/archivist-view");
37
+ var import_bridge_http = require("@xyo-network/bridge-http");
38
+ var import_diviner_boundwitness_memory = require("@xyo-network/diviner-boundwitness-memory");
39
+ var import_diviner_identity = require("@xyo-network/diviner-identity");
40
+ var import_diviner_payload_memory = require("@xyo-network/diviner-payload-memory");
41
+ var import_module_model = require("@xyo-network/module-model");
42
+ var import_node_memory = require("@xyo-network/node-memory");
43
+ var import_node_view = require("@xyo-network/node-view");
44
+ var import_sentinel_memory = require("@xyo-network/sentinel-memory");
45
+ var import_witness_adhoc = require("@xyo-network/witness-adhoc");
46
+ var standardCreatableFactoriesList = [
47
+ import_bridge_http.HttpBridge,
48
+ import_archivist_view.ViewArchivist,
49
+ import_node_view.ViewNode,
50
+ import_witness_adhoc.AdhocWitness,
51
+ import_diviner_payload_memory.MemoryPayloadDiviner,
52
+ import_diviner_boundwitness_memory.MemoryBoundWitnessDiviner,
53
+ import_diviner_identity.IdentityDiviner,
54
+ import_archivist_memory.MemoryArchivist,
55
+ import_archivist_memory.MemoryArchivist,
56
+ import_node_memory.MemoryNode,
57
+ import_sentinel_memory.MemorySentinel
58
+ ];
59
+ var standardCreatableFactories = /* @__PURE__ */ __name(() => {
60
+ return (0, import_module_model.registerCreatableModuleFactories)(standardCreatableFactoriesList, {}, true);
61
+ }, "standardCreatableFactories");
62
+
63
+ // src/ModuleFactoryLocator.ts
64
+ var _ModuleFactoryLocator = class _ModuleFactoryLocator {
65
+ _registry;
66
+ constructor(_registry = standardCreatableFactories()) {
67
+ this._registry = _registry;
68
+ }
69
+ /**
70
+ * The current registry for the module factory
71
+ */
72
+ get registry() {
73
+ return this._registry;
74
+ }
75
+ /**
76
+ * Locates a module factory that matches the supplied schema and labels
77
+ * @param schema The config schema for the module
78
+ * @param labels The labels for the module factory
79
+ * @returns A module factory that matches the supplied schema and labels or throws if one is not found
80
+ */
81
+ locate(schema, labels) {
82
+ return (0, import_assert.assertEx)(this.tryLocate(schema, labels), () => `No module factory for the supplied ${`config schema [${schema}]`}${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`);
83
+ }
84
+ /**
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
+ */
89
+ register(factory, labels, primary = false) {
90
+ (0, import_module_model2.registerCreatableModuleFactory)(this._registry, factory, labels, primary);
91
+ return this;
92
+ }
93
+ /**
94
+ * Registers multiple module factories with the locator
95
+ * @param factories The factories to register
96
+ */
97
+ registerMany(factories) {
98
+ for (const factory of factories) {
99
+ this.register(factory);
100
+ }
101
+ return this;
102
+ }
103
+ /**
104
+ * Tries to locate a module factory that matches the supplied schema and labels
105
+ * @param schema The config schema for the module
106
+ * @param labels The labels for the module factory
107
+ * @returns A module factory that matches the supplied schema and labels or undefined
108
+ */
109
+ tryLocate(schema, labels) {
110
+ var _a, _b;
111
+ return labels ? (
112
+ // Find the first factory that has labels and has all the labels provided
113
+ (_a = this._registry[schema]) == null ? void 0 : _a.filter(import_module_model2.hasLabels).find((factory) => (0, import_module_model2.hasAllLabels)(factory == null ? void 0 : factory.labels, labels))
114
+ ) : (_b = this._registry[schema]) == null ? void 0 : _b[0];
115
+ }
116
+ };
117
+ __name(_ModuleFactoryLocator, "ModuleFactoryLocator");
118
+ var ModuleFactoryLocator = _ModuleFactoryLocator;
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ ModuleFactoryLocator,
122
+ standardCreatableFactories,
123
+ standardCreatableFactoriesList
124
+ });
2
125
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["export * from './ModuleFactoryLocator'\nexport * from './standardCreatableFactories'\n","import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,+BAAAC,EAAA,mCAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAAyB,0BACzBC,EAQO,qCCTP,IAAAC,EAAgC,yCAChCC,EAA8B,uCAC9BC,EAA2B,oCAC3BC,EAA0C,oDAC1CC,EAAgC,yCAChCC,EAAqC,+CACrCC,EAAwG,qCACxGC,EAA2B,oCAC3BC,EAAyB,kCACzBC,EAA+B,wCAC/BC,EAA6B,sCAGtB,IAAMC,EAA6F,CACxGC,aACAC,gBACAC,WACAC,eACAC,uBACAC,4BACAC,kBACAC,kBACAA,kBACAC,aACAC,kBAGWC,EAA6BC,EAAA,OACjCC,oCAAiCb,EAAgC,CAAC,EAAG,EAAA,EADpC,8BDVnC,IAAMc,EAAN,MAAMA,CAAAA,WACXC,YAA+BC,EAAqCC,EAAAA,EAA8B,MAAnED,UAAAA,CAAoE,CAKnG,IAAIE,UAA8C,CAChD,OAAO,KAAKF,SACd,CAQAG,OAAOC,EAAgBC,EAAyE,CAC9F,SAAOC,YACL,KAAKC,UAAUH,EAAQC,CAAAA,EACvB,IAAM,sCAAsC,kBAAkBD,CAAAA,GAAS,GAAGC,EAAS,cAAcG,KAAKC,UAAUJ,CAAAA,CAAAA,IAAa,EAAA,aAAe,CAEhJ,CAOAK,SAASC,EAAiCN,EAAiBO,EAAuC,GAAa,CAC7GC,2CAA+B,KAAKb,UAAWW,EAASN,EAAQO,CAAAA,EACzD,IACT,CAMAE,aAAaC,EAA2C,CACtD,QAAWJ,KAAWI,EACpB,KAAKL,SAASC,CAAAA,EAEhB,OAAO,IACT,CAQAJ,UAAUH,EAAgBC,EAAqF,CAnEjH,IAAAW,EAAAC,EAqEI,OAAOZ,GAEHW,EAAA,KAAKhB,UAAUI,CAAAA,IAAf,YAAAY,EAAwBE,OAAOC,aAAWC,KAAMT,MAAYU,gBAAaV,GAAAA,YAAAA,EAASN,OAAQA,CAAAA,IAE1FY,EAAA,KAAKjB,UAAUI,CAAAA,IAAf,YAAAa,EAAyB,EAC/B,CACF,EA1DanB,EAAAA,EAAAA,wBAAN,IAAMA,EAANwB","names":["src_exports","__export","ModuleFactoryLocator","standardCreatableFactories","standardCreatableFactoriesList","__toCommonJS","import_assert","import_module_model","import_archivist_memory","import_archivist_view","import_bridge_http","import_diviner_boundwitness_memory","import_diviner_identity","import_diviner_payload_memory","import_module_model","import_node_memory","import_node_view","import_sentinel_memory","import_witness_adhoc","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","__name","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","_a","_b","filter","hasLabels","find","hasAllLabels","_ModuleFactoryLocator"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["export * from './ModuleFactoryLocator'\nexport * from './standardCreatableFactories'\n","import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,oBAAyB;AACzB,IAAAA,uBAQO;;;ACTP,8BAAgC;AAChC,4BAA8B;AAC9B,yBAA2B;AAC3B,yCAA0C;AAC1C,8BAAgC;AAChC,oCAAqC;AACrC,0BAAwG;AACxG,yBAA2B;AAC3B,uBAAyB;AACzB,6BAA+B;AAC/B,2BAA6B;AAGtB,IAAMC,iCAA6F;EACxGC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAA;EACAC;EACAC;;AAGK,IAAMC,6BAA6B,6BAAA;AACxC,aAAOC,sDAAiCZ,gCAAgC,CAAC,GAAG,IAAA;AAC9E,GAF0C;;;ADVnC,IAAMa,wBAAN,MAAMA,sBAAAA;;EACXC,YAA+BC,YAAqCC,2BAAAA,GAA8B;SAAnED,YAAAA;EAAoE;;;;EAKnG,IAAIE,WAA8C;AAChD,WAAO,KAAKF;EACd;;;;;;;EAQAG,OAAOC,QAAgBC,QAAyE;AAC9F,eAAOC,wBACL,KAAKC,UAAUH,QAAQC,MAAAA,GACvB,MAAM,sCAAsC,kBAAkBD,MAAAA,GAAS,GAAGC,SAAS,cAAcG,KAAKC,UAAUJ,MAAAA,CAAAA,MAAa,EAAA,aAAe;EAEhJ;;;;;;EAOAK,SAASC,SAAiCN,QAAiBO,UAAuC,OAAa;AAC7GC,6DAA+B,KAAKb,WAAWW,SAASN,QAAQO,OAAAA;AAChE,WAAO;EACT;;;;;EAMAE,aAAaC,WAA2C;AACtD,eAAWJ,WAAWI,WAAW;AAC/B,WAAKL,SAASC,OAAAA;IAChB;AACA,WAAO;EACT;;;;;;;EAQAJ,UAAUH,QAAgBC,QAAqF;AAnEjH;AAqEI,WAAOA;;OAEH,UAAKL,UAAUI,MAAAA,MAAf,mBAAwBY,OAAOC,gCAAWC,KAAK,CAACP,gBAAYQ,mCAAaR,mCAASN,QAAQA,MAAAA;SAE1F,UAAKL,UAAUI,MAAAA,MAAf,mBAAyB;EAC/B;AACF;AA1DaN;AAAN,IAAMA,uBAAN;","names":["import_module_model","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","filter","hasLabels","find","hasAllLabels"]}
@@ -1,2 +1,98 @@
1
- var d=Object.defineProperty;var i=(p,r)=>d(p,"name",{value:r,configurable:!0});import{assertEx as _}from"@xylabs/assert";import{hasAllLabels as A,hasLabels as N,registerCreatableModuleFactory as $}from"@xyo-network/module-model";import{MemoryArchivist as a}from"@xyo-network/archivist-memory";import{ViewArchivist as g}from"@xyo-network/archivist-view";import{HttpBridge as l}from"@xyo-network/bridge-http";import{MemoryBoundWitnessDiviner as y}from"@xyo-network/diviner-boundwitness-memory";import{IdentityDiviner as h}from"@xyo-network/diviner-identity";import{MemoryPayloadDiviner as c}from"@xyo-network/diviner-payload-memory";import{registerCreatableModuleFactories as u}from"@xyo-network/module-model";import{MemoryNode as b}from"@xyo-network/node-memory";import{ViewNode as x}from"@xyo-network/node-view";import{MemorySentinel as M}from"@xyo-network/sentinel-memory";import{AdhocWitness as v}from"@xyo-network/witness-adhoc";var C=[l,g,x,v,c,y,h,a,a,b,M],n=i(()=>u(C,{},!0),"standardCreatableFactories");var s=class s{_registry;constructor(r=n()){this._registry=r}get registry(){return this._registry}locate(r,t){return _(this.tryLocate(r,t),()=>`No module factory for the supplied ${`config schema [${r}]`}${t?` & labels [${JSON.stringify(t)}]`:""} registered`)}register(r,t,e=!1){return $(this._registry,r,t,e),this}registerMany(r){for(let t of r)this.register(t);return this}tryLocate(r,t){var e,m;return t?(e=this._registry[r])==null?void 0:e.filter(N).find(o=>A(o==null?void 0:o.labels,t)):(m=this._registry[r])==null?void 0:m[0]}};i(s,"ModuleFactoryLocator");var f=s;export{f as ModuleFactoryLocator,n as standardCreatableFactories,C as standardCreatableFactoriesList};
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/ModuleFactoryLocator.ts
5
+ import { assertEx } from "@xylabs/assert";
6
+ import { hasAllLabels, hasLabels, registerCreatableModuleFactory } from "@xyo-network/module-model";
7
+
8
+ // src/standardCreatableFactories.ts
9
+ import { MemoryArchivist } from "@xyo-network/archivist-memory";
10
+ import { ViewArchivist } from "@xyo-network/archivist-view";
11
+ import { HttpBridge } from "@xyo-network/bridge-http";
12
+ import { MemoryBoundWitnessDiviner } from "@xyo-network/diviner-boundwitness-memory";
13
+ import { IdentityDiviner } from "@xyo-network/diviner-identity";
14
+ import { MemoryPayloadDiviner } from "@xyo-network/diviner-payload-memory";
15
+ import { registerCreatableModuleFactories } from "@xyo-network/module-model";
16
+ import { MemoryNode } from "@xyo-network/node-memory";
17
+ import { ViewNode } from "@xyo-network/node-view";
18
+ import { MemorySentinel } from "@xyo-network/sentinel-memory";
19
+ import { AdhocWitness } from "@xyo-network/witness-adhoc";
20
+ var standardCreatableFactoriesList = [
21
+ HttpBridge,
22
+ ViewArchivist,
23
+ ViewNode,
24
+ AdhocWitness,
25
+ MemoryPayloadDiviner,
26
+ MemoryBoundWitnessDiviner,
27
+ IdentityDiviner,
28
+ MemoryArchivist,
29
+ MemoryArchivist,
30
+ MemoryNode,
31
+ MemorySentinel
32
+ ];
33
+ var standardCreatableFactories = /* @__PURE__ */ __name(() => {
34
+ return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true);
35
+ }, "standardCreatableFactories");
36
+
37
+ // src/ModuleFactoryLocator.ts
38
+ var _ModuleFactoryLocator = class _ModuleFactoryLocator {
39
+ _registry;
40
+ constructor(_registry = standardCreatableFactories()) {
41
+ this._registry = _registry;
42
+ }
43
+ /**
44
+ * The current registry for the module factory
45
+ */
46
+ get registry() {
47
+ return this._registry;
48
+ }
49
+ /**
50
+ * Locates a module factory that matches the supplied schema and labels
51
+ * @param schema The config schema for the module
52
+ * @param labels The labels for the module factory
53
+ * @returns A module factory that matches the supplied schema and labels or throws if one is not found
54
+ */
55
+ locate(schema, labels) {
56
+ return assertEx(this.tryLocate(schema, labels), () => `No module factory for the supplied ${`config schema [${schema}]`}${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`);
57
+ }
58
+ /**
59
+ * Registers a single module factory (with optional tags) with the locator
60
+ * @param factory The factory to register
61
+ * @param labels The labels for the module factory
62
+ */
63
+ register(factory, labels, primary = false) {
64
+ registerCreatableModuleFactory(this._registry, factory, labels, primary);
65
+ return this;
66
+ }
67
+ /**
68
+ * Registers multiple module factories with the locator
69
+ * @param factories The factories to register
70
+ */
71
+ registerMany(factories) {
72
+ for (const factory of factories) {
73
+ this.register(factory);
74
+ }
75
+ return this;
76
+ }
77
+ /**
78
+ * Tries to locate a module factory that matches the supplied schema and labels
79
+ * @param schema The config schema for the module
80
+ * @param labels The labels for the module factory
81
+ * @returns A module factory that matches the supplied schema and labels or undefined
82
+ */
83
+ tryLocate(schema, labels) {
84
+ var _a, _b;
85
+ return labels ? (
86
+ // Find the first factory that has labels and has all the labels provided
87
+ (_a = this._registry[schema]) == null ? void 0 : _a.filter(hasLabels).find((factory) => hasAllLabels(factory == null ? void 0 : factory.labels, labels))
88
+ ) : (_b = this._registry[schema]) == null ? void 0 : _b[0];
89
+ }
90
+ };
91
+ __name(_ModuleFactoryLocator, "ModuleFactoryLocator");
92
+ var ModuleFactoryLocator = _ModuleFactoryLocator;
93
+ export {
94
+ ModuleFactoryLocator,
95
+ standardCreatableFactories,
96
+ standardCreatableFactoriesList
97
+ };
2
98
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":"+EAAA,OAASA,YAAAA,MAAgB,iBACzB,OAGEC,gBAAAA,EACAC,aAAAA,EAGAC,kCAAAA,MACK,4BCTP,OAASC,mBAAAA,MAAuB,gCAChC,OAASC,iBAAAA,MAAqB,8BAC9B,OAASC,cAAAA,MAAkB,2BAC3B,OAASC,6BAAAA,MAAiC,2CAC1C,OAASC,mBAAAA,MAAuB,gCAChC,OAASC,wBAAAA,MAA4B,sCACrC,OAAgEC,oCAAAA,MAAwC,4BACxG,OAASC,cAAAA,MAAkB,2BAC3B,OAASC,YAAAA,MAAgB,yBACzB,OAASC,kBAAAA,MAAsB,+BAC/B,OAASC,gBAAAA,MAAoB,6BAGtB,IAAMC,EAA6F,CACxGC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAA,EACAC,EACAC,GAGWC,EAA6BC,EAAA,IACjCC,EAAiCb,EAAgC,CAAC,EAAG,EAAA,EADpC,8BDVnC,IAAMc,EAAN,MAAMA,CAAAA,WACXC,YAA+BC,EAAqCC,EAAAA,EAA8B,MAAnED,UAAAA,CAAoE,CAKnG,IAAIE,UAA8C,CAChD,OAAO,KAAKF,SACd,CAQAG,OAAOC,EAAgBC,EAAyE,CAC9F,OAAOC,EACL,KAAKC,UAAUH,EAAQC,CAAAA,EACvB,IAAM,sCAAsC,kBAAkBD,CAAAA,GAAS,GAAGC,EAAS,cAAcG,KAAKC,UAAUJ,CAAAA,CAAAA,IAAa,EAAA,aAAe,CAEhJ,CAOAK,SAASC,EAAiCN,EAAiBO,EAAuC,GAAa,CAC7GC,OAAAA,EAA+B,KAAKb,UAAWW,EAASN,EAAQO,CAAAA,EACzD,IACT,CAMAE,aAAaC,EAA2C,CACtD,QAAWJ,KAAWI,EACpB,KAAKL,SAASC,CAAAA,EAEhB,OAAO,IACT,CAQAJ,UAAUH,EAAgBC,EAAqF,CAnEjH,IAAAW,EAAAC,EAqEI,OAAOZ,GAEHW,EAAA,KAAKhB,UAAUI,CAAAA,IAAf,YAAAY,EAAwBE,OAAOC,GAAWC,KAAMT,GAAYU,EAAaV,GAAAA,YAAAA,EAASN,OAAQA,CAAAA,IAE1FY,EAAA,KAAKjB,UAAUI,CAAAA,IAAf,YAAAa,EAAyB,EAC/B,CACF,EA1DanB,EAAAA,EAAAA,wBAAN,IAAMA,EAANwB","names":["assertEx","hasAllLabels","hasLabels","registerCreatableModuleFactory","MemoryArchivist","ViewArchivist","HttpBridge","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryPayloadDiviner","registerCreatableModuleFactories","MemoryNode","ViewNode","MemorySentinel","AdhocWitness","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","__name","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","_a","_b","filter","hasLabels","find","hasAllLabels","_ModuleFactoryLocator"]}
1
+ {"version":3,"sources":["../../src/ModuleFactoryLocator.ts","../../src/standardCreatableFactories.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport {\n CreatableModuleFactory,\n CreatableModuleRegistry,\n hasAllLabels,\n hasLabels,\n LabeledCreatableModuleFactory,\n Labels,\n registerCreatableModuleFactory,\n} from '@xyo-network/module-model'\nimport { Schema } from '@xyo-network/payload-model'\n\nimport { standardCreatableFactories } from './standardCreatableFactories'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\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 /**\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 /**\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 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 // If labels were provided\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))\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 { MemoryPayloadDiviner } from '@xyo-network/diviner-payload-memory'\nimport { CreatableModuleFactory, LabeledCreatableModuleFactory, 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]\n\nexport const standardCreatableFactories = () => {\n return registerCreatableModuleFactories(standardCreatableFactoriesList, {}, true)\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAGEC,cACAC,WAGAC,sCACK;;;ACTP,SAASC,uBAAuB;AAChC,SAASC,qBAAqB;AAC9B,SAASC,kBAAkB;AAC3B,SAASC,iCAAiC;AAC1C,SAASC,uBAAuB;AAChC,SAASC,4BAA4B;AACrC,SAAgEC,wCAAwC;AACxG,SAASC,kBAAkB;AAC3B,SAASC,gBAAgB;AACzB,SAASC,sBAAsB;AAC/B,SAASC,oBAAoB;AAGtB,IAAMC,iCAA6F;EACxGC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAA;EACAC;EACAC;;AAGK,IAAMC,6BAA6B,6BAAA;AACxC,SAAOC,iCAAiCZ,gCAAgC,CAAC,GAAG,IAAA;AAC9E,GAF0C;;;ADVnC,IAAMa,wBAAN,MAAMA,sBAAAA;;EACXC,YAA+BC,YAAqCC,2BAAAA,GAA8B;SAAnED,YAAAA;EAAoE;;;;EAKnG,IAAIE,WAA8C;AAChD,WAAO,KAAKF;EACd;;;;;;;EAQAG,OAAOC,QAAgBC,QAAyE;AAC9F,WAAOC,SACL,KAAKC,UAAUH,QAAQC,MAAAA,GACvB,MAAM,sCAAsC,kBAAkBD,MAAAA,GAAS,GAAGC,SAAS,cAAcG,KAAKC,UAAUJ,MAAAA,CAAAA,MAAa,EAAA,aAAe;EAEhJ;;;;;;EAOAK,SAASC,SAAiCN,QAAiBO,UAAuC,OAAa;AAC7GC,mCAA+B,KAAKb,WAAWW,SAASN,QAAQO,OAAAA;AAChE,WAAO;EACT;;;;;EAMAE,aAAaC,WAA2C;AACtD,eAAWJ,WAAWI,WAAW;AAC/B,WAAKL,SAASC,OAAAA;IAChB;AACA,WAAO;EACT;;;;;;;EAQAJ,UAAUH,QAAgBC,QAAqF;AAnEjH;AAqEI,WAAOA;;OAEH,UAAKL,UAAUI,MAAAA,MAAf,mBAAwBY,OAAOC,WAAWC,KAAK,CAACP,YAAYQ,aAAaR,mCAASN,QAAQA,MAAAA;SAE1F,UAAKL,UAAUI,MAAAA,MAAf,mBAAyB;EAC/B;AACF;AA1DaN;AAAN,IAAMA,uBAAN;","names":["assertEx","hasAllLabels","hasLabels","registerCreatableModuleFactory","MemoryArchivist","ViewArchivist","HttpBridge","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryPayloadDiviner","registerCreatableModuleFactories","MemoryNode","ViewNode","MemorySentinel","AdhocWitness","standardCreatableFactoriesList","HttpBridge","ViewArchivist","ViewNode","AdhocWitness","MemoryPayloadDiviner","MemoryBoundWitnessDiviner","IdentityDiviner","MemoryArchivist","MemoryNode","MemorySentinel","standardCreatableFactories","registerCreatableModuleFactories","ModuleFactoryLocator","constructor","_registry","standardCreatableFactories","registry","locate","schema","labels","assertEx","tryLocate","JSON","stringify","register","factory","primary","registerCreatableModuleFactory","registerMany","factories","filter","hasLabels","find","hasAllLabels"]}
package/package.json CHANGED
@@ -11,22 +11,22 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@xylabs/assert": "^3.5.1",
14
- "@xyo-network/archivist-memory": "~2.107.3",
15
- "@xyo-network/archivist-view": "~2.107.3",
16
- "@xyo-network/bridge-http": "~2.107.3",
17
- "@xyo-network/diviner-boundwitness-memory": "~2.107.3",
18
- "@xyo-network/diviner-identity": "~2.107.3",
19
- "@xyo-network/diviner-payload-memory": "~2.107.3",
20
- "@xyo-network/module-model": "~2.107.3",
21
- "@xyo-network/node-memory": "~2.107.3",
22
- "@xyo-network/node-view": "~2.107.3",
23
- "@xyo-network/payload-model": "~2.107.3",
24
- "@xyo-network/sentinel-memory": "~2.107.3",
25
- "@xyo-network/witness-adhoc": "~2.107.3"
14
+ "@xyo-network/archivist-memory": "~2.107.5",
15
+ "@xyo-network/archivist-view": "~2.107.5",
16
+ "@xyo-network/bridge-http": "~2.107.5",
17
+ "@xyo-network/diviner-boundwitness-memory": "~2.107.5",
18
+ "@xyo-network/diviner-identity": "~2.107.5",
19
+ "@xyo-network/diviner-payload-memory": "~2.107.5",
20
+ "@xyo-network/module-model": "~2.107.5",
21
+ "@xyo-network/node-memory": "~2.107.5",
22
+ "@xyo-network/node-view": "~2.107.5",
23
+ "@xyo-network/payload-model": "~2.107.5",
24
+ "@xyo-network/sentinel-memory": "~2.107.5",
25
+ "@xyo-network/witness-adhoc": "~2.107.5"
26
26
  },
27
27
  "devDependencies": {
28
- "@xylabs/ts-scripts-yarn3": "^3.11.9",
29
- "@xylabs/tsconfig": "^3.11.9",
28
+ "@xylabs/ts-scripts-yarn3": "^3.11.10",
29
+ "@xylabs/tsconfig": "^3.11.10",
30
30
  "typescript": "^5.5.2"
31
31
  },
32
32
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -68,6 +68,6 @@
68
68
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
69
69
  },
70
70
  "sideEffects": false,
71
- "version": "2.107.3",
71
+ "version": "2.107.5",
72
72
  "type": "module"
73
73
  }