@xyo-network/module-model 2.75.2 → 2.75.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/Config.js +2 -1
- package/dist/browser/Config.js.map +1 -1
- package/dist/browser/CreatableModule/CreatableModule.js +1 -0
- package/dist/browser/CreatableModule/CreatableModule.js.map +1 -1
- package/dist/browser/CreatableModule/CreatableModuleRegistry.js +3 -2
- package/dist/browser/CreatableModule/CreatableModuleRegistry.js.map +1 -1
- package/dist/browser/CreatableModule/LabeledCreatableModuleFactory.js +2 -1
- package/dist/browser/CreatableModule/LabeledCreatableModuleFactory.js.map +1 -1
- package/dist/browser/CreatableModule/ModuleFactory.js +4 -3
- package/dist/browser/CreatableModule/ModuleFactory.js.map +1 -1
- package/dist/browser/CreatableModule/ModuleFactoryLocator.js +19 -4
- package/dist/browser/CreatableModule/ModuleFactoryLocator.js.map +1 -1
- package/dist/browser/CreatableModule/index.js +169 -6
- package/dist/browser/CreatableModule/index.js.map +1 -1
- package/dist/browser/EventsModels/index.js +0 -5
- package/dist/browser/EventsModels/index.js.map +1 -1
- package/dist/browser/Labels/Labels.js +2 -1
- package/dist/browser/Labels/Labels.js.map +1 -1
- package/dist/browser/Labels/index.js +11 -1
- package/dist/browser/Labels/index.js.map +1 -1
- package/dist/browser/Queries/Describe/Payload.js +2 -1
- package/dist/browser/Queries/Describe/Payload.js.map +1 -1
- package/dist/browser/Queries/Describe/Query.js +2 -1
- package/dist/browser/Queries/Describe/Query.js.map +1 -1
- package/dist/browser/Queries/Describe/index.js +9 -2
- package/dist/browser/Queries/Describe/index.js.map +1 -1
- package/dist/browser/Queries/Discover.js +2 -1
- package/dist/browser/Queries/Discover.js.map +1 -1
- package/dist/browser/Queries/Manifest.js +2 -1
- package/dist/browser/Queries/Manifest.js.map +1 -1
- package/dist/browser/Queries/ModuleAddress/Payload.js +2 -1
- package/dist/browser/Queries/ModuleAddress/Payload.js.map +1 -1
- package/dist/browser/Queries/ModuleAddress/Query.js +2 -1
- package/dist/browser/Queries/ModuleAddress/Query.js.map +1 -1
- package/dist/browser/Queries/ModuleAddress/index.js +10 -2
- package/dist/browser/Queries/ModuleAddress/index.js.map +1 -1
- package/dist/browser/Queries/Subscribe.js +2 -1
- package/dist/browser/Queries/Subscribe.js.map +1 -1
- package/dist/browser/Queries/index.js +30 -5
- package/dist/browser/Queries/index.js.map +1 -1
- package/dist/browser/index.js +332 -13
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/instance/ModuleInstance.js +3 -2
- package/dist/browser/instance/ModuleInstance.js.map +1 -1
- package/dist/browser/instance/asModuleInstance.js +63 -2
- package/dist/browser/instance/asModuleInstance.js.map +1 -1
- package/dist/browser/instance/index.js +75 -4
- package/dist/browser/instance/index.js.map +1 -1
- package/dist/browser/instance/isModuleInstance.js +52 -4
- package/dist/browser/instance/isModuleInstance.js.map +1 -1
- package/dist/browser/lib/duplicateModules.js +2 -1
- package/dist/browser/lib/duplicateModules.js.map +1 -1
- package/dist/browser/lib/index.js +32 -2
- package/dist/browser/lib/index.js.map +1 -1
- package/dist/browser/lib/serializable.js +5 -4
- package/dist/browser/lib/serializable.js.map +1 -1
- package/dist/browser/module/IsModuleFactory.js +22 -4
- package/dist/browser/module/IsModuleFactory.js.map +1 -1
- package/dist/browser/module/asModule.js +50 -2
- package/dist/browser/module/asModule.js.map +1 -1
- package/dist/browser/module/asModuleObject.js +17 -2
- package/dist/browser/module/asModuleObject.js.map +1 -1
- package/dist/browser/module/index.js +60 -8
- package/dist/browser/module/index.js.map +1 -1
- package/dist/browser/module/isModule.js +38 -6
- package/dist/browser/module/isModule.js.map +1 -1
- package/dist/browser/module/isModuleObject.js +4 -3
- package/dist/browser/module/isModuleObject.js.map +1 -1
- package/dist/browser/withModule.js +63 -5
- package/dist/browser/withModule.js.map +1 -1
- package/dist/docs.json +1160 -1160
- package/package.json +17 -17
package/dist/browser/Config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Config.ts"],"sourcesContent":["import { AnyObject, WithAdditional } from '@xyo-network/core'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\nimport { Labels } from './Labels'\n\nexport type ModuleConfigSchema = 'network.xyo.module.config'\nexport const ModuleConfigSchema: ModuleConfigSchema = 'network.xyo.module.config'\n\nexport type AddressString = string\nexport type CosigningAddressSet = string[]\nexport type SchemaString = string\n\nexport type NameOrAddress = string\n\nexport interface IndividualArchivistConfig {\n readonly commit?: NameOrAddress\n readonly read?: NameOrAddress\n readonly write?: NameOrAddress\n}\n\nexport type ArchivistModuleConfig = NameOrAddress | IndividualArchivistConfig\n\nexport type ModuleConfig<\n TConfig extends Payload | void = void,\n TAdditionalParams extends AnyObject | void = void,\n TSchema extends Schema | void = void,\n> = Payload<\n WithAdditional<\n WithAdditional<\n {\n /** @field The path to use when creating the account */\n accountDerivationPath?: string\n\n /** @field The name/address of the Archivist to use for this module */\n readonly archivist?: ArchivistModuleConfig\n\n /**\n * @field The labels used for this module. If a label is specified, then the\n * ModuleFactoryLocator will attempt to find a ModuleFactory with the corresponding\n * labels to construct this module.\n */\n readonly labels?: Labels\n\n /** @field Friendly name of module (not collision resistent). Can be used to resolve module when registered/attached to Node. */\n readonly name?: string\n\n /** @field paging settings for queries */\n readonly paging?: Record<string, { size?: number }>\n\n /** @field The query schemas and allowed/disallowed addresses which are allowed to issue them against the module. If both allowed and disallowed is specified, then disallowed takes priority. */\n readonly security?: {\n /** @field Will the module process queries that have unsigned BoundWitness in query tuples */\n readonly allowAnonymous?: boolean\n\n /** @field If schema in record, then only these address sets can access query */\n readonly allowed?: Record<SchemaString, (AddressString | CosigningAddressSet)[]>\n\n /** @field If schema in record, then anyone except these addresses can access query */\n readonly disallowed?: Record<SchemaString, AddressString[]>\n }\n\n /** @field sign every query */\n readonly sign?: boolean\n\n /** @field Store the queries made to the module in an archivist if possible */\n readonly storeQueries?: boolean\n\n /** @field add a timestamp payload to every query */\n readonly timestamp?: boolean\n },\n TConfig\n >,\n TAdditionalParams\n >,\n TSchema extends Schema ? TSchema : TConfig extends Payload ? TConfig['schema'] : ModuleConfigSchema\n>\n\nexport type AnyConfigSchema<TConfig extends Omit<ModuleConfig, 'schema'> & { schema: string } = Omit<ModuleConfig, 'schema'> & { schema: string }> =\n ModuleConfig<\n WithAdditional<\n Omit<TConfig, 'schema'>,\n {\n schema: string\n }\n >\n >\n\nexport type OptionalConfigSchema<TConfig extends AnyConfigSchema<ModuleConfig> = AnyConfigSchema<ModuleConfig>> = Omit<TConfig, 'schema'> & {\n schema?: TConfig['schema']\n}\n\nexport type AnyModuleConfig = AnyConfigSchema<ModuleConfig>\n"],"mappings":"AAMO,
|
|
1
|
+
{"version":3,"sources":["../../src/Config.ts"],"sourcesContent":["import { AnyObject, WithAdditional } from '@xyo-network/core'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\nimport { Labels } from './Labels'\n\nexport type ModuleConfigSchema = 'network.xyo.module.config'\nexport const ModuleConfigSchema: ModuleConfigSchema = 'network.xyo.module.config'\n\nexport type AddressString = string\nexport type CosigningAddressSet = string[]\nexport type SchemaString = string\n\nexport type NameOrAddress = string\n\nexport interface IndividualArchivistConfig {\n readonly commit?: NameOrAddress\n readonly read?: NameOrAddress\n readonly write?: NameOrAddress\n}\n\nexport type ArchivistModuleConfig = NameOrAddress | IndividualArchivistConfig\n\nexport type ModuleConfig<\n TConfig extends Payload | void = void,\n TAdditionalParams extends AnyObject | void = void,\n TSchema extends Schema | void = void,\n> = Payload<\n WithAdditional<\n WithAdditional<\n {\n /** @field The path to use when creating the account */\n accountDerivationPath?: string\n\n /** @field The name/address of the Archivist to use for this module */\n readonly archivist?: ArchivistModuleConfig\n\n /**\n * @field The labels used for this module. If a label is specified, then the\n * ModuleFactoryLocator will attempt to find a ModuleFactory with the corresponding\n * labels to construct this module.\n */\n readonly labels?: Labels\n\n /** @field Friendly name of module (not collision resistent). Can be used to resolve module when registered/attached to Node. */\n readonly name?: string\n\n /** @field paging settings for queries */\n readonly paging?: Record<string, { size?: number }>\n\n /** @field The query schemas and allowed/disallowed addresses which are allowed to issue them against the module. If both allowed and disallowed is specified, then disallowed takes priority. */\n readonly security?: {\n /** @field Will the module process queries that have unsigned BoundWitness in query tuples */\n readonly allowAnonymous?: boolean\n\n /** @field If schema in record, then only these address sets can access query */\n readonly allowed?: Record<SchemaString, (AddressString | CosigningAddressSet)[]>\n\n /** @field If schema in record, then anyone except these addresses can access query */\n readonly disallowed?: Record<SchemaString, AddressString[]>\n }\n\n /** @field sign every query */\n readonly sign?: boolean\n\n /** @field Store the queries made to the module in an archivist if possible */\n readonly storeQueries?: boolean\n\n /** @field add a timestamp payload to every query */\n readonly timestamp?: boolean\n },\n TConfig\n >,\n TAdditionalParams\n >,\n TSchema extends Schema ? TSchema : TConfig extends Payload ? TConfig['schema'] : ModuleConfigSchema\n>\n\nexport type AnyConfigSchema<TConfig extends Omit<ModuleConfig, 'schema'> & { schema: string } = Omit<ModuleConfig, 'schema'> & { schema: string }> =\n ModuleConfig<\n WithAdditional<\n Omit<TConfig, 'schema'>,\n {\n schema: string\n }\n >\n >\n\nexport type OptionalConfigSchema<TConfig extends AnyConfigSchema<ModuleConfig> = AnyConfigSchema<ModuleConfig>> = Omit<TConfig, 'schema'> & {\n schema?: TConfig['schema']\n}\n\nexport type AnyModuleConfig = AnyConfigSchema<ModuleConfig>\n"],"mappings":";AAMO,IAAM,qBAAyC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/CreatableModule/CreatableModule.ts"],"sourcesContent":["import { AccountInstance } from '@xyo-network/account-model'\nimport { Logger } from '@xyo-network/logger'\n\nimport { ModuleInstance } from '../instance'\n\nexport type CreatableModuleFactory<T extends ModuleInstance = ModuleInstance> = Omit<Omit<CreatableModule<T>, 'new'>, 'create'> & {\n create<T extends ModuleInstance>(this: CreatableModuleFactory<T>, params?: T['params']): Promise<T>\n}\n\nexport interface CreatableModule<T extends ModuleInstance = ModuleInstance> {\n configSchema: string\n configSchemas: string[]\n defaultLogger?: Logger\n new (privateConstructorKey: string, params: T['params'], account: AccountInstance): T\n _noOverride(functionName: string): void\n create<T extends ModuleInstance>(this: CreatableModule<T>, params?: T['params']): Promise<T>\n factory<T extends ModuleInstance>(this: CreatableModule<T>, params?: T['params']): CreatableModuleFactory<T>\n}\n\n/**\n * Class annotation to be used to decorate Modules which support\n * an asynchronous creation pattern\n * @returns The decorated Module requiring it implement the members\n * of the CreatableModule as statics properties/methods\n */\nexport function creatableModule<TModule extends ModuleInstance = ModuleInstance>() {\n return <U extends CreatableModule<TModule>>(constructor: U) => {\n constructor\n }\n}\n"],"mappings":"AAyBO,SAAS,kBAAmE;AACjF,SAAO,CAAqC,gBAAmB;AAC7D;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/CreatableModule/CreatableModule.ts"],"sourcesContent":["import { AccountInstance } from '@xyo-network/account-model'\nimport { Logger } from '@xyo-network/logger'\n\nimport { ModuleInstance } from '../instance'\n\nexport type CreatableModuleFactory<T extends ModuleInstance = ModuleInstance> = Omit<Omit<CreatableModule<T>, 'new'>, 'create'> & {\n create<T extends ModuleInstance>(this: CreatableModuleFactory<T>, params?: T['params']): Promise<T>\n}\n\nexport interface CreatableModule<T extends ModuleInstance = ModuleInstance> {\n configSchema: string\n configSchemas: string[]\n defaultLogger?: Logger\n new (privateConstructorKey: string, params: T['params'], account: AccountInstance): T\n _noOverride(functionName: string): void\n create<T extends ModuleInstance>(this: CreatableModule<T>, params?: T['params']): Promise<T>\n factory<T extends ModuleInstance>(this: CreatableModule<T>, params?: T['params']): CreatableModuleFactory<T>\n}\n\n/**\n * Class annotation to be used to decorate Modules which support\n * an asynchronous creation pattern\n * @returns The decorated Module requiring it implement the members\n * of the CreatableModule as statics properties/methods\n */\nexport function creatableModule<TModule extends ModuleInstance = ModuleInstance>() {\n return <U extends CreatableModule<TModule>>(constructor: U) => {\n constructor\n }\n}\n"],"mappings":";AAyBO,SAAS,kBAAmE;AACjF,SAAO,CAAqC,gBAAmB;AAC7D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
// src/CreatableModule/CreatableModuleRegistry.ts
|
|
2
|
+
var toCreatableModuleRegistry = (dict) => {
|
|
2
3
|
return Object.entries(dict).reduce((registry, [schema, factory]) => {
|
|
3
4
|
registry[schema] = Array.isArray(factory) ? factory : [factory];
|
|
4
5
|
return registry;
|
|
5
6
|
}, {});
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
+
var assignCreatableModuleRegistry = (target = {}, ...sources) => {
|
|
8
9
|
sources.map(
|
|
9
10
|
(source) => Object.entries(source).map(([schema, factories]) => {
|
|
10
11
|
if (factories) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/CreatableModule/CreatableModuleRegistry.ts"],"sourcesContent":["import { CreatableModuleFactory } from './CreatableModule'\nimport { CreatableModuleDictionary } from './CreatableModuleDictionary'\nimport { LabeledCreatableModuleFactory } from './LabeledCreatableModuleFactory'\n\nexport interface CreatableModuleRegistry {\n [key: string]: (CreatableModuleFactory | LabeledCreatableModuleFactory)[] | undefined\n}\n\nexport const toCreatableModuleRegistry = (dict: CreatableModuleDictionary | CreatableModuleRegistry): CreatableModuleRegistry => {\n return Object.entries(dict).reduce((registry, [schema, factory]) => {\n registry[schema] = Array.isArray(factory) ? factory : [factory]\n return registry\n }, {} as CreatableModuleRegistry)\n}\n\nexport const assignCreatableModuleRegistry = (\n target: CreatableModuleRegistry = {},\n ...sources: CreatableModuleRegistry[]\n): CreatableModuleRegistry => {\n sources.map((source) =>\n Object.entries(source).map(([schema, factories]) => {\n if (factories) {\n const existingFactories = target[schema]\n target[schema] = existingFactories ? (target[schema] = [...existingFactories, ...factories]) : factories\n }\n }),\n )\n return target\n}\n"],"mappings":"AAQO,
|
|
1
|
+
{"version":3,"sources":["../../../src/CreatableModule/CreatableModuleRegistry.ts"],"sourcesContent":["import { CreatableModuleFactory } from './CreatableModule'\nimport { CreatableModuleDictionary } from './CreatableModuleDictionary'\nimport { LabeledCreatableModuleFactory } from './LabeledCreatableModuleFactory'\n\nexport interface CreatableModuleRegistry {\n [key: string]: (CreatableModuleFactory | LabeledCreatableModuleFactory)[] | undefined\n}\n\nexport const toCreatableModuleRegistry = (dict: CreatableModuleDictionary | CreatableModuleRegistry): CreatableModuleRegistry => {\n return Object.entries(dict).reduce((registry, [schema, factory]) => {\n registry[schema] = Array.isArray(factory) ? factory : [factory]\n return registry\n }, {} as CreatableModuleRegistry)\n}\n\nexport const assignCreatableModuleRegistry = (\n target: CreatableModuleRegistry = {},\n ...sources: CreatableModuleRegistry[]\n): CreatableModuleRegistry => {\n sources.map((source) =>\n Object.entries(source).map(([schema, factories]) => {\n if (factories) {\n const existingFactories = target[schema]\n target[schema] = existingFactories ? (target[schema] = [...existingFactories, ...factories]) : factories\n }\n }),\n )\n return target\n}\n"],"mappings":";AAQO,IAAM,4BAA4B,CAAC,SAAuF;AAC/H,SAAO,OAAO,QAAQ,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ,OAAO,MAAM;AAClE,aAAS,MAAM,IAAI,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO;AAC9D,WAAO;AAAA,EACT,GAAG,CAAC,CAA4B;AAClC;AAEO,IAAM,gCAAgC,CAC3C,SAAkC,CAAC,MAChC,YACyB;AAC5B,UAAQ;AAAA,IAAI,CAAC,WACX,OAAO,QAAQ,MAAM,EAAE,IAAI,CAAC,CAAC,QAAQ,SAAS,MAAM;AAClD,UAAI,WAAW;AACb,cAAM,oBAAoB,OAAO,MAAM;AACvC,eAAO,MAAM,IAAI,oBAAqB,OAAO,MAAM,IAAI,CAAC,GAAG,mBAAmB,GAAG,SAAS,IAAK;AAAA,MACjG;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/CreatableModule/LabeledCreatableModuleFactory.ts"],"sourcesContent":["import { ModuleInstance } from '../instance'\nimport { WithOptionalLabels } from '../Labels'\nimport { CreatableModuleFactory } from './CreatableModule'\n\nexport type LabeledCreatableModuleFactory<T extends ModuleInstance = ModuleInstance> = CreatableModuleFactory<T> & WithOptionalLabels\n\nexport const hasLabels = (factory: CreatableModuleFactory | LabeledCreatableModuleFactory): factory is LabeledCreatableModuleFactory => {\n return (factory as LabeledCreatableModuleFactory).labels !== undefined\n}\n"],"mappings":"AAMO,
|
|
1
|
+
{"version":3,"sources":["../../../src/CreatableModule/LabeledCreatableModuleFactory.ts"],"sourcesContent":["import { ModuleInstance } from '../instance'\nimport { WithOptionalLabels } from '../Labels'\nimport { CreatableModuleFactory } from './CreatableModule'\n\nexport type LabeledCreatableModuleFactory<T extends ModuleInstance = ModuleInstance> = CreatableModuleFactory<T> & WithOptionalLabels\n\nexport const hasLabels = (factory: CreatableModuleFactory | LabeledCreatableModuleFactory): factory is LabeledCreatableModuleFactory => {\n return (factory as LabeledCreatableModuleFactory).labels !== undefined\n}\n"],"mappings":";AAMO,IAAM,YAAY,CAAC,YAA8G;AACtI,SAAQ,QAA0C,WAAW;AAC/D;","names":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// src/CreatableModule/ModuleFactory.ts
|
|
1
2
|
import { assertEx } from "@xylabs/assert";
|
|
2
3
|
import { merge } from "@xylabs/lodash";
|
|
3
|
-
|
|
4
|
+
var ModuleFactory = class _ModuleFactory {
|
|
4
5
|
configSchemas;
|
|
5
6
|
creatableModule;
|
|
6
7
|
defaultLogger;
|
|
@@ -16,7 +17,7 @@ class ModuleFactory {
|
|
|
16
17
|
return this.configSchemas[0];
|
|
17
18
|
}
|
|
18
19
|
static withParams(creatableModule, params, labels = {}) {
|
|
19
|
-
return new
|
|
20
|
+
return new _ModuleFactory(creatableModule, params, labels);
|
|
20
21
|
}
|
|
21
22
|
_getRootFunction(funcName) {
|
|
22
23
|
let anyThis = this;
|
|
@@ -41,7 +42,7 @@ class ModuleFactory {
|
|
|
41
42
|
factory(_params) {
|
|
42
43
|
throw new Error("Method not implemented.");
|
|
43
44
|
}
|
|
44
|
-
}
|
|
45
|
+
};
|
|
45
46
|
export {
|
|
46
47
|
ModuleFactory
|
|
47
48
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/CreatableModule/ModuleFactory.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { merge } from '@xylabs/lodash'\nimport { Logger } from '@xyo-network/logger'\n\nimport { ModuleInstance } from '../instance'\nimport { Labels, WithOptionalLabels } from '../Labels'\nimport { CreatableModule, CreatableModuleFactory } from './CreatableModule'\n\nexport class ModuleFactory<TModule extends ModuleInstance> implements CreatableModuleFactory<TModule> {\n configSchemas: CreatableModuleFactory<TModule>['configSchemas']\n\n creatableModule: CreatableModule<TModule>\n\n defaultLogger?: Logger | undefined\n\n defaultParams?: Omit<TModule['params'], 'config'> & { config?: TModule['params']['config'] }\n\n labels?: Labels\n\n constructor(\n creatableModule: CreatableModule<TModule>,\n params?: Omit<TModule['params'], 'config'> & { config?: TModule['params']['config'] },\n labels: Labels = {},\n ) {\n this.creatableModule = creatableModule\n this.defaultParams = params\n this.configSchemas = creatableModule.configSchemas\n this.labels = Object.assign({}, (creatableModule as WithOptionalLabels).labels ?? {}, labels ?? {})\n }\n\n get configSchema(): string {\n return this.configSchemas[0]\n }\n\n static withParams<T extends ModuleInstance>(\n creatableModule: CreatableModule<T>,\n params?: Omit<T['params'], 'config'> & { config?: T['params']['config'] },\n labels: Labels = {},\n ) {\n return new ModuleFactory(creatableModule, params, labels)\n }\n\n _getRootFunction(funcName: string) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let anyThis = this as any\n while (anyThis.__proto__[funcName]) {\n anyThis = anyThis.__proto__\n }\n return anyThis[funcName]\n }\n\n _noOverride(functionName: string) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const thisFunc = (this as any)[functionName]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const rootFunc = this._getRootFunction(functionName)\n assertEx(thisFunc === rootFunc, `Override not allowed for [${functionName}] - override ${functionName}Handler instead`)\n }\n\n create<T extends ModuleInstance>(this: CreatableModuleFactory<T>, params?: TModule['params'] | undefined): Promise<T> {\n const factory = this as ModuleFactory<T>\n const schema = factory.creatableModule.configSchema\n const mergedParams: TModule['params'] = merge({}, factory.defaultParams, params, {\n config: merge({}, factory.defaultParams?.config, params?.config, { schema }),\n })\n return factory.creatableModule.create<T>(mergedParams)\n }\n\n factory<T extends ModuleInstance>(this: CreatableModule<T>, _params?: T['params'] | undefined): CreatableModuleFactory<T> {\n throw new Error('Method not implemented.')\n }\n}\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAOf,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../../src/CreatableModule/ModuleFactory.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { merge } from '@xylabs/lodash'\nimport { Logger } from '@xyo-network/logger'\n\nimport { ModuleInstance } from '../instance'\nimport { Labels, WithOptionalLabels } from '../Labels'\nimport { CreatableModule, CreatableModuleFactory } from './CreatableModule'\n\nexport class ModuleFactory<TModule extends ModuleInstance> implements CreatableModuleFactory<TModule> {\n configSchemas: CreatableModuleFactory<TModule>['configSchemas']\n\n creatableModule: CreatableModule<TModule>\n\n defaultLogger?: Logger | undefined\n\n defaultParams?: Omit<TModule['params'], 'config'> & { config?: TModule['params']['config'] }\n\n labels?: Labels\n\n constructor(\n creatableModule: CreatableModule<TModule>,\n params?: Omit<TModule['params'], 'config'> & { config?: TModule['params']['config'] },\n labels: Labels = {},\n ) {\n this.creatableModule = creatableModule\n this.defaultParams = params\n this.configSchemas = creatableModule.configSchemas\n this.labels = Object.assign({}, (creatableModule as WithOptionalLabels).labels ?? {}, labels ?? {})\n }\n\n get configSchema(): string {\n return this.configSchemas[0]\n }\n\n static withParams<T extends ModuleInstance>(\n creatableModule: CreatableModule<T>,\n params?: Omit<T['params'], 'config'> & { config?: T['params']['config'] },\n labels: Labels = {},\n ) {\n return new ModuleFactory(creatableModule, params, labels)\n }\n\n _getRootFunction(funcName: string) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let anyThis = this as any\n while (anyThis.__proto__[funcName]) {\n anyThis = anyThis.__proto__\n }\n return anyThis[funcName]\n }\n\n _noOverride(functionName: string) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const thisFunc = (this as any)[functionName]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const rootFunc = this._getRootFunction(functionName)\n assertEx(thisFunc === rootFunc, `Override not allowed for [${functionName}] - override ${functionName}Handler instead`)\n }\n\n create<T extends ModuleInstance>(this: CreatableModuleFactory<T>, params?: TModule['params'] | undefined): Promise<T> {\n const factory = this as ModuleFactory<T>\n const schema = factory.creatableModule.configSchema\n const mergedParams: TModule['params'] = merge({}, factory.defaultParams, params, {\n config: merge({}, factory.defaultParams?.config, params?.config, { schema }),\n })\n return factory.creatableModule.create<T>(mergedParams)\n }\n\n factory<T extends ModuleInstance>(this: CreatableModule<T>, _params?: T['params'] | undefined): CreatableModuleFactory<T> {\n throw new Error('Method not implemented.')\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAOf,IAAM,gBAAN,MAAM,eAAyF;AAAA,EACpG;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA,YACE,iBACA,QACA,SAAiB,CAAC,GAClB;AACA,SAAK,kBAAkB;AACvB,SAAK,gBAAgB;AACrB,SAAK,gBAAgB,gBAAgB;AACrC,SAAK,SAAS,OAAO,OAAO,CAAC,GAAI,gBAAuC,UAAU,CAAC,GAAG,UAAU,CAAC,CAAC;AAAA,EACpG;AAAA,EAEA,IAAI,eAAuB;AACzB,WAAO,KAAK,cAAc,CAAC;AAAA,EAC7B;AAAA,EAEA,OAAO,WACL,iBACA,QACA,SAAiB,CAAC,GAClB;AACA,WAAO,IAAI,eAAc,iBAAiB,QAAQ,MAAM;AAAA,EAC1D;AAAA,EAEA,iBAAiB,UAAkB;AAEjC,QAAI,UAAU;AACd,WAAO,QAAQ,UAAU,QAAQ,GAAG;AAClC,gBAAU,QAAQ;AAAA,IACpB;AACA,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEA,YAAY,cAAsB;AAEhC,UAAM,WAAY,KAAa,YAAY;AAE3C,UAAM,WAAW,KAAK,iBAAiB,YAAY;AACnD,aAAS,aAAa,UAAU,6BAA6B,YAAY,gBAAgB,YAAY,iBAAiB;AAAA,EACxH;AAAA,EAEA,OAAkE,QAAoD;AACpH,UAAM,UAAU;AAChB,UAAM,SAAS,QAAQ,gBAAgB;AACvC,UAAM,eAAkC,MAAM,CAAC,GAAG,QAAQ,eAAe,QAAQ;AAAA,MAC/E,QAAQ,MAAM,CAAC,GAAG,QAAQ,eAAe,QAAQ,QAAQ,QAAQ,EAAE,OAAO,CAAC;AAAA,IAC7E,CAAC;AACD,WAAO,QAAQ,gBAAgB,OAAU,YAAY;AAAA,EACvD;AAAA,EAEA,QAA4D,SAA8D;AACxH,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AACF;","names":[]}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
// src/CreatableModule/ModuleFactoryLocator.ts
|
|
1
2
|
import { assertEx } from "@xylabs/assert";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
// src/Labels/Labels.ts
|
|
5
|
+
var hasAllLabels = (source, required) => {
|
|
6
|
+
if (!required)
|
|
7
|
+
return true;
|
|
8
|
+
return Object.entries(required).every(([key, value]) => {
|
|
9
|
+
return source?.hasOwnProperty(key) && source?.[key] === value;
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/CreatableModule/LabeledCreatableModuleFactory.ts
|
|
14
|
+
var hasLabels = (factory) => {
|
|
15
|
+
return factory.labels !== void 0;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/CreatableModule/ModuleFactoryLocator.ts
|
|
19
|
+
var ModuleFactoryLocator = class {
|
|
5
20
|
constructor(_registry = {}) {
|
|
6
21
|
this._registry = _registry;
|
|
7
22
|
}
|
|
@@ -71,7 +86,7 @@ class ModuleFactoryLocator {
|
|
|
71
86
|
this._registry[schema]?.[0]
|
|
72
87
|
);
|
|
73
88
|
}
|
|
74
|
-
}
|
|
89
|
+
};
|
|
75
90
|
export {
|
|
76
91
|
ModuleFactoryLocator
|
|
77
92
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/CreatableModule/ModuleFactoryLocator.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\nimport { ModuleInstance } from '../instance'\nimport { hasAllLabels, Labels } from '../Labels'\nimport { CreatableModuleFactory } from './CreatableModule'\nimport { CreatableModuleRegistry } from './CreatableModuleRegistry'\nimport { hasLabels, LabeledCreatableModuleFactory } from './LabeledCreatableModuleFactory'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\n constructor(protected readonly _registry: CreatableModuleRegistry = {}) {}\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(this.tryLocate(schema, labels), () => {\n const configString = `config schema [${schema}]`\n const labelsString = labels ? ` & labels [${JSON.stringify(labels)}]` : ''\n return `No module factory for the supplied ${configString}${labelsString} registered`\n })\n }\n\n /**\n * Registers a single module factory (with optional tags) with the locator\n * @param additional Additional module factories to register\n */\n register<TModule extends ModuleInstance>(mod: CreatableModuleFactory<TModule>, labels?: Labels): this {\n mod.configSchemas.map((schema) => {\n const existingFactories = this._registry[schema]\n const factory: LabeledCreatableModuleFactory<TModule> = {\n // Destructure instance properties\n ...mod,\n // Copy static methods\n create: mod.create.bind(mod) as LabeledCreatableModuleFactory<TModule>['create'],\n // Merge module & supplied labels\n labels: Object.assign({}, (mod as LabeledCreatableModuleFactory).labels ?? {}, labels ?? {}),\n }\n this._registry[schema] = existingFactories ? [...existingFactories, factory] : [factory]\n })\n return this\n }\n\n /**\n * Registers multiple module factories with the locator\n * @param additional Additional module factories to register\n */\n registerMany(additional: CreatableModuleRegistry): this {\n Object.entries(additional).map(([schema, factories]) => {\n if (factories) {\n const existingFactories = this._registry[schema]\n this._registry[schema] = existingFactories ? [...existingFactories, ...factories] : factories\n }\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"],"mappings":"AAAA,SAAS,gBAAgB;
|
|
1
|
+
{"version":3,"sources":["../../../src/CreatableModule/ModuleFactoryLocator.ts","../../../src/Labels/Labels.ts","../../../src/CreatableModule/LabeledCreatableModuleFactory.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\nimport { ModuleInstance } from '../instance'\nimport { hasAllLabels, Labels } from '../Labels'\nimport { CreatableModuleFactory } from './CreatableModule'\nimport { CreatableModuleRegistry } from './CreatableModuleRegistry'\nimport { hasLabels, LabeledCreatableModuleFactory } from './LabeledCreatableModuleFactory'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\n constructor(protected readonly _registry: CreatableModuleRegistry = {}) {}\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(this.tryLocate(schema, labels), () => {\n const configString = `config schema [${schema}]`\n const labelsString = labels ? ` & labels [${JSON.stringify(labels)}]` : ''\n return `No module factory for the supplied ${configString}${labelsString} registered`\n })\n }\n\n /**\n * Registers a single module factory (with optional tags) with the locator\n * @param additional Additional module factories to register\n */\n register<TModule extends ModuleInstance>(mod: CreatableModuleFactory<TModule>, labels?: Labels): this {\n mod.configSchemas.map((schema) => {\n const existingFactories = this._registry[schema]\n const factory: LabeledCreatableModuleFactory<TModule> = {\n // Destructure instance properties\n ...mod,\n // Copy static methods\n create: mod.create.bind(mod) as LabeledCreatableModuleFactory<TModule>['create'],\n // Merge module & supplied labels\n labels: Object.assign({}, (mod as LabeledCreatableModuleFactory).labels ?? {}, labels ?? {}),\n }\n this._registry[schema] = existingFactories ? [...existingFactories, factory] : [factory]\n })\n return this\n }\n\n /**\n * Registers multiple module factories with the locator\n * @param additional Additional module factories to register\n */\n registerMany(additional: CreatableModuleRegistry): this {\n Object.entries(additional).map(([schema, factories]) => {\n if (factories) {\n const existingFactories = this._registry[schema]\n this._registry[schema] = existingFactories ? [...existingFactories, ...factories] : factories\n }\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","/**\n * Object used to represent labels identifying a resource.\n */\nexport interface Labels {\n [key: string]: string | undefined\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithLabels<T extends Labels = Labels> {\n labels: T\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithOptionalLabels<T extends Labels = Labels> {\n labels?: T\n}\n\n/**\n * Returns true if the source object has all the labels from the required set\n * @param source Source object to check against\n * @param required Set of labels to check for in source\n * @returns True of the source object has all the labels from the required set\n */\nexport const hasAllLabels = (source?: Labels, required?: Labels): boolean => {\n if (!required) return true\n return Object.entries(required).every(([key, value]) => {\n // eslint-disable-next-line no-prototype-builtins\n return source?.hasOwnProperty(key as keyof typeof source) && source?.[key as keyof typeof source] === value\n })\n}\n","import { ModuleInstance } from '../instance'\nimport { WithOptionalLabels } from '../Labels'\nimport { CreatableModuleFactory } from './CreatableModule'\n\nexport type LabeledCreatableModuleFactory<T extends ModuleInstance = ModuleInstance> = CreatableModuleFactory<T> & WithOptionalLabels\n\nexport const hasLabels = (factory: CreatableModuleFactory | LabeledCreatableModuleFactory): factory is LabeledCreatableModuleFactory => {\n return (factory as LabeledCreatableModuleFactory).labels !== undefined\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;;;AC2BlB,IAAM,eAAe,CAAC,QAAiB,aAA+B;AAC3E,MAAI,CAAC;AAAU,WAAO;AACtB,SAAO,OAAO,QAAQ,QAAQ,EAAE,MAAM,CAAC,CAAC,KAAK,KAAK,MAAM;AAEtD,WAAO,QAAQ,eAAe,GAA0B,KAAK,SAAS,GAA0B,MAAM;AAAA,EACxG,CAAC;AACH;;;AC3BO,IAAM,YAAY,CAAC,YAA8G;AACtI,SAAQ,QAA0C,WAAW;AAC/D;;;AFGO,IAAM,uBAAN,MAA2B;AAAA,EAChC,YAA+B,YAAqC,CAAC,GAAG;AAAzC;AAAA,EAA0C;AAAA;AAAA;AAAA;AAAA,EAKzE,IAAI,WAA8C;AAChD,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,QAAgB,QAAyE;AAC9F,WAAO,SAAS,KAAK,UAAU,QAAQ,MAAM,GAAG,MAAM;AACpD,YAAM,eAAe,kBAAkB,MAAM;AAC7C,YAAM,eAAe,SAAS,cAAc,KAAK,UAAU,MAAM,CAAC,MAAM;AACxE,aAAO,sCAAsC,YAAY,GAAG,YAAY;AAAA,IAC1E,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAyC,KAAsC,QAAuB;AACpG,QAAI,cAAc,IAAI,CAAC,WAAW;AAChC,YAAM,oBAAoB,KAAK,UAAU,MAAM;AAC/C,YAAM,UAAkD;AAAA;AAAA,QAEtD,GAAG;AAAA;AAAA,QAEH,QAAQ,IAAI,OAAO,KAAK,GAAG;AAAA;AAAA,QAE3B,QAAQ,OAAO,OAAO,CAAC,GAAI,IAAsC,UAAU,CAAC,GAAG,UAAU,CAAC,CAAC;AAAA,MAC7F;AACA,WAAK,UAAU,MAAM,IAAI,oBAAoB,CAAC,GAAG,mBAAmB,OAAO,IAAI,CAAC,OAAO;AAAA,IACzF,CAAC;AACD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAa,YAA2C;AACtD,WAAO,QAAQ,UAAU,EAAE,IAAI,CAAC,CAAC,QAAQ,SAAS,MAAM;AACtD,UAAI,WAAW;AACb,cAAM,oBAAoB,KAAK,UAAU,MAAM;AAC/C,aAAK,UAAU,MAAM,IAAI,oBAAoB,CAAC,GAAG,mBAAmB,GAAG,SAAS,IAAI;AAAA,MACtF;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAU,QAAgB,QAAqF;AAE7G,WAAO;AAAA;AAAA,MAEH,KAAK,UAAU,MAAM,GAAG,OAAO,SAAS,EAAE,KAAK,CAAC,YAAY,aAAa,SAAS,QAAQ,MAAM,CAAC;AAAA;AAAA;AAAA,MAEjG,KAAK,UAAU,MAAM,IAAI,CAAC;AAAA;AAAA,EAChC;AACF;","names":[]}
|
|
@@ -1,7 +1,170 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
// src/CreatableModule/CreatableModule.ts
|
|
2
|
+
function creatableModule() {
|
|
3
|
+
return (constructor) => {
|
|
4
|
+
constructor;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/CreatableModule/CreatableModuleRegistry.ts
|
|
9
|
+
var toCreatableModuleRegistry = (dict) => {
|
|
10
|
+
return Object.entries(dict).reduce((registry, [schema, factory]) => {
|
|
11
|
+
registry[schema] = Array.isArray(factory) ? factory : [factory];
|
|
12
|
+
return registry;
|
|
13
|
+
}, {});
|
|
14
|
+
};
|
|
15
|
+
var assignCreatableModuleRegistry = (target = {}, ...sources) => {
|
|
16
|
+
sources.map(
|
|
17
|
+
(source) => Object.entries(source).map(([schema, factories]) => {
|
|
18
|
+
if (factories) {
|
|
19
|
+
const existingFactories = target[schema];
|
|
20
|
+
target[schema] = existingFactories ? target[schema] = [...existingFactories, ...factories] : factories;
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
return target;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/CreatableModule/LabeledCreatableModuleFactory.ts
|
|
28
|
+
var hasLabels = (factory) => {
|
|
29
|
+
return factory.labels !== void 0;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/CreatableModule/ModuleFactory.ts
|
|
33
|
+
import { assertEx } from "@xylabs/assert";
|
|
34
|
+
import { merge } from "@xylabs/lodash";
|
|
35
|
+
var ModuleFactory = class _ModuleFactory {
|
|
36
|
+
configSchemas;
|
|
37
|
+
creatableModule;
|
|
38
|
+
defaultLogger;
|
|
39
|
+
defaultParams;
|
|
40
|
+
labels;
|
|
41
|
+
constructor(creatableModule2, params, labels = {}) {
|
|
42
|
+
this.creatableModule = creatableModule2;
|
|
43
|
+
this.defaultParams = params;
|
|
44
|
+
this.configSchemas = creatableModule2.configSchemas;
|
|
45
|
+
this.labels = Object.assign({}, creatableModule2.labels ?? {}, labels ?? {});
|
|
46
|
+
}
|
|
47
|
+
get configSchema() {
|
|
48
|
+
return this.configSchemas[0];
|
|
49
|
+
}
|
|
50
|
+
static withParams(creatableModule2, params, labels = {}) {
|
|
51
|
+
return new _ModuleFactory(creatableModule2, params, labels);
|
|
52
|
+
}
|
|
53
|
+
_getRootFunction(funcName) {
|
|
54
|
+
let anyThis = this;
|
|
55
|
+
while (anyThis.__proto__[funcName]) {
|
|
56
|
+
anyThis = anyThis.__proto__;
|
|
57
|
+
}
|
|
58
|
+
return anyThis[funcName];
|
|
59
|
+
}
|
|
60
|
+
_noOverride(functionName) {
|
|
61
|
+
const thisFunc = this[functionName];
|
|
62
|
+
const rootFunc = this._getRootFunction(functionName);
|
|
63
|
+
assertEx(thisFunc === rootFunc, `Override not allowed for [${functionName}] - override ${functionName}Handler instead`);
|
|
64
|
+
}
|
|
65
|
+
create(params) {
|
|
66
|
+
const factory = this;
|
|
67
|
+
const schema = factory.creatableModule.configSchema;
|
|
68
|
+
const mergedParams = merge({}, factory.defaultParams, params, {
|
|
69
|
+
config: merge({}, factory.defaultParams?.config, params?.config, { schema })
|
|
70
|
+
});
|
|
71
|
+
return factory.creatableModule.create(mergedParams);
|
|
72
|
+
}
|
|
73
|
+
factory(_params) {
|
|
74
|
+
throw new Error("Method not implemented.");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/CreatableModule/ModuleFactoryLocator.ts
|
|
79
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
80
|
+
|
|
81
|
+
// src/Labels/Labels.ts
|
|
82
|
+
var hasAllLabels = (source, required) => {
|
|
83
|
+
if (!required)
|
|
84
|
+
return true;
|
|
85
|
+
return Object.entries(required).every(([key, value]) => {
|
|
86
|
+
return source?.hasOwnProperty(key) && source?.[key] === value;
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/CreatableModule/ModuleFactoryLocator.ts
|
|
91
|
+
var ModuleFactoryLocator = class {
|
|
92
|
+
constructor(_registry = {}) {
|
|
93
|
+
this._registry = _registry;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The current registry for the module factory
|
|
97
|
+
*/
|
|
98
|
+
get registry() {
|
|
99
|
+
return this._registry;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Locates a module factory that matches the supplied schema and labels
|
|
103
|
+
* @param schema The config schema for the module
|
|
104
|
+
* @param labels The labels for the module factory
|
|
105
|
+
* @returns A module factory that matches the supplied schema and labels or throws if one is not found
|
|
106
|
+
*/
|
|
107
|
+
locate(schema, labels) {
|
|
108
|
+
return assertEx2(this.tryLocate(schema, labels), () => {
|
|
109
|
+
const configString = `config schema [${schema}]`;
|
|
110
|
+
const labelsString = labels ? ` & labels [${JSON.stringify(labels)}]` : "";
|
|
111
|
+
return `No module factory for the supplied ${configString}${labelsString} registered`;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Registers a single module factory (with optional tags) with the locator
|
|
116
|
+
* @param additional Additional module factories to register
|
|
117
|
+
*/
|
|
118
|
+
register(mod, labels) {
|
|
119
|
+
mod.configSchemas.map((schema) => {
|
|
120
|
+
const existingFactories = this._registry[schema];
|
|
121
|
+
const factory = {
|
|
122
|
+
// Destructure instance properties
|
|
123
|
+
...mod,
|
|
124
|
+
// Copy static methods
|
|
125
|
+
create: mod.create.bind(mod),
|
|
126
|
+
// Merge module & supplied labels
|
|
127
|
+
labels: Object.assign({}, mod.labels ?? {}, labels ?? {})
|
|
128
|
+
};
|
|
129
|
+
this._registry[schema] = existingFactories ? [...existingFactories, factory] : [factory];
|
|
130
|
+
});
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Registers multiple module factories with the locator
|
|
135
|
+
* @param additional Additional module factories to register
|
|
136
|
+
*/
|
|
137
|
+
registerMany(additional) {
|
|
138
|
+
Object.entries(additional).map(([schema, factories]) => {
|
|
139
|
+
if (factories) {
|
|
140
|
+
const existingFactories = this._registry[schema];
|
|
141
|
+
this._registry[schema] = existingFactories ? [...existingFactories, ...factories] : factories;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Tries to locate a module factory that matches the supplied schema and labels
|
|
148
|
+
* @param schema The config schema for the module
|
|
149
|
+
* @param labels The labels for the module factory
|
|
150
|
+
* @returns A module factory that matches the supplied schema and labels or undefined
|
|
151
|
+
*/
|
|
152
|
+
tryLocate(schema, labels) {
|
|
153
|
+
return labels ? (
|
|
154
|
+
// Find the first factory that has labels and has all the labels provided
|
|
155
|
+
this._registry[schema]?.filter(hasLabels).find((factory) => hasAllLabels(factory?.labels, labels))
|
|
156
|
+
) : (
|
|
157
|
+
// Otherwise, return the first factory
|
|
158
|
+
this._registry[schema]?.[0]
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
export {
|
|
163
|
+
ModuleFactory,
|
|
164
|
+
ModuleFactoryLocator,
|
|
165
|
+
assignCreatableModuleRegistry,
|
|
166
|
+
creatableModule,
|
|
167
|
+
hasLabels,
|
|
168
|
+
toCreatableModuleRegistry
|
|
169
|
+
};
|
|
7
170
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/CreatableModule/index.ts"],"sourcesContent":["export * from './CreatableModule'\nexport * from './CreatableModuleDictionary'\nexport * from './CreatableModuleRegistry'\nexport * from './LabeledCreatableModuleFactory'\nexport * from './ModuleFactory'\nexport * from './ModuleFactoryLocator'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/CreatableModule/CreatableModule.ts","../../../src/CreatableModule/CreatableModuleRegistry.ts","../../../src/CreatableModule/LabeledCreatableModuleFactory.ts","../../../src/CreatableModule/ModuleFactory.ts","../../../src/CreatableModule/ModuleFactoryLocator.ts","../../../src/Labels/Labels.ts"],"sourcesContent":["import { AccountInstance } from '@xyo-network/account-model'\nimport { Logger } from '@xyo-network/logger'\n\nimport { ModuleInstance } from '../instance'\n\nexport type CreatableModuleFactory<T extends ModuleInstance = ModuleInstance> = Omit<Omit<CreatableModule<T>, 'new'>, 'create'> & {\n create<T extends ModuleInstance>(this: CreatableModuleFactory<T>, params?: T['params']): Promise<T>\n}\n\nexport interface CreatableModule<T extends ModuleInstance = ModuleInstance> {\n configSchema: string\n configSchemas: string[]\n defaultLogger?: Logger\n new (privateConstructorKey: string, params: T['params'], account: AccountInstance): T\n _noOverride(functionName: string): void\n create<T extends ModuleInstance>(this: CreatableModule<T>, params?: T['params']): Promise<T>\n factory<T extends ModuleInstance>(this: CreatableModule<T>, params?: T['params']): CreatableModuleFactory<T>\n}\n\n/**\n * Class annotation to be used to decorate Modules which support\n * an asynchronous creation pattern\n * @returns The decorated Module requiring it implement the members\n * of the CreatableModule as statics properties/methods\n */\nexport function creatableModule<TModule extends ModuleInstance = ModuleInstance>() {\n return <U extends CreatableModule<TModule>>(constructor: U) => {\n constructor\n }\n}\n","import { CreatableModuleFactory } from './CreatableModule'\nimport { CreatableModuleDictionary } from './CreatableModuleDictionary'\nimport { LabeledCreatableModuleFactory } from './LabeledCreatableModuleFactory'\n\nexport interface CreatableModuleRegistry {\n [key: string]: (CreatableModuleFactory | LabeledCreatableModuleFactory)[] | undefined\n}\n\nexport const toCreatableModuleRegistry = (dict: CreatableModuleDictionary | CreatableModuleRegistry): CreatableModuleRegistry => {\n return Object.entries(dict).reduce((registry, [schema, factory]) => {\n registry[schema] = Array.isArray(factory) ? factory : [factory]\n return registry\n }, {} as CreatableModuleRegistry)\n}\n\nexport const assignCreatableModuleRegistry = (\n target: CreatableModuleRegistry = {},\n ...sources: CreatableModuleRegistry[]\n): CreatableModuleRegistry => {\n sources.map((source) =>\n Object.entries(source).map(([schema, factories]) => {\n if (factories) {\n const existingFactories = target[schema]\n target[schema] = existingFactories ? (target[schema] = [...existingFactories, ...factories]) : factories\n }\n }),\n )\n return target\n}\n","import { ModuleInstance } from '../instance'\nimport { WithOptionalLabels } from '../Labels'\nimport { CreatableModuleFactory } from './CreatableModule'\n\nexport type LabeledCreatableModuleFactory<T extends ModuleInstance = ModuleInstance> = CreatableModuleFactory<T> & WithOptionalLabels\n\nexport const hasLabels = (factory: CreatableModuleFactory | LabeledCreatableModuleFactory): factory is LabeledCreatableModuleFactory => {\n return (factory as LabeledCreatableModuleFactory).labels !== undefined\n}\n","import { assertEx } from '@xylabs/assert'\nimport { merge } from '@xylabs/lodash'\nimport { Logger } from '@xyo-network/logger'\n\nimport { ModuleInstance } from '../instance'\nimport { Labels, WithOptionalLabels } from '../Labels'\nimport { CreatableModule, CreatableModuleFactory } from './CreatableModule'\n\nexport class ModuleFactory<TModule extends ModuleInstance> implements CreatableModuleFactory<TModule> {\n configSchemas: CreatableModuleFactory<TModule>['configSchemas']\n\n creatableModule: CreatableModule<TModule>\n\n defaultLogger?: Logger | undefined\n\n defaultParams?: Omit<TModule['params'], 'config'> & { config?: TModule['params']['config'] }\n\n labels?: Labels\n\n constructor(\n creatableModule: CreatableModule<TModule>,\n params?: Omit<TModule['params'], 'config'> & { config?: TModule['params']['config'] },\n labels: Labels = {},\n ) {\n this.creatableModule = creatableModule\n this.defaultParams = params\n this.configSchemas = creatableModule.configSchemas\n this.labels = Object.assign({}, (creatableModule as WithOptionalLabels).labels ?? {}, labels ?? {})\n }\n\n get configSchema(): string {\n return this.configSchemas[0]\n }\n\n static withParams<T extends ModuleInstance>(\n creatableModule: CreatableModule<T>,\n params?: Omit<T['params'], 'config'> & { config?: T['params']['config'] },\n labels: Labels = {},\n ) {\n return new ModuleFactory(creatableModule, params, labels)\n }\n\n _getRootFunction(funcName: string) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let anyThis = this as any\n while (anyThis.__proto__[funcName]) {\n anyThis = anyThis.__proto__\n }\n return anyThis[funcName]\n }\n\n _noOverride(functionName: string) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const thisFunc = (this as any)[functionName]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const rootFunc = this._getRootFunction(functionName)\n assertEx(thisFunc === rootFunc, `Override not allowed for [${functionName}] - override ${functionName}Handler instead`)\n }\n\n create<T extends ModuleInstance>(this: CreatableModuleFactory<T>, params?: TModule['params'] | undefined): Promise<T> {\n const factory = this as ModuleFactory<T>\n const schema = factory.creatableModule.configSchema\n const mergedParams: TModule['params'] = merge({}, factory.defaultParams, params, {\n config: merge({}, factory.defaultParams?.config, params?.config, { schema }),\n })\n return factory.creatableModule.create<T>(mergedParams)\n }\n\n factory<T extends ModuleInstance>(this: CreatableModule<T>, _params?: T['params'] | undefined): CreatableModuleFactory<T> {\n throw new Error('Method not implemented.')\n }\n}\n","import { assertEx } from '@xylabs/assert'\n\nimport { ModuleInstance } from '../instance'\nimport { hasAllLabels, Labels } from '../Labels'\nimport { CreatableModuleFactory } from './CreatableModule'\nimport { CreatableModuleRegistry } from './CreatableModuleRegistry'\nimport { hasLabels, LabeledCreatableModuleFactory } from './LabeledCreatableModuleFactory'\n\n/**\n * A class which encapsulates the Service Locator Pattern for Module Factories\n */\nexport class ModuleFactoryLocator {\n constructor(protected readonly _registry: CreatableModuleRegistry = {}) {}\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(this.tryLocate(schema, labels), () => {\n const configString = `config schema [${schema}]`\n const labelsString = labels ? ` & labels [${JSON.stringify(labels)}]` : ''\n return `No module factory for the supplied ${configString}${labelsString} registered`\n })\n }\n\n /**\n * Registers a single module factory (with optional tags) with the locator\n * @param additional Additional module factories to register\n */\n register<TModule extends ModuleInstance>(mod: CreatableModuleFactory<TModule>, labels?: Labels): this {\n mod.configSchemas.map((schema) => {\n const existingFactories = this._registry[schema]\n const factory: LabeledCreatableModuleFactory<TModule> = {\n // Destructure instance properties\n ...mod,\n // Copy static methods\n create: mod.create.bind(mod) as LabeledCreatableModuleFactory<TModule>['create'],\n // Merge module & supplied labels\n labels: Object.assign({}, (mod as LabeledCreatableModuleFactory).labels ?? {}, labels ?? {}),\n }\n this._registry[schema] = existingFactories ? [...existingFactories, factory] : [factory]\n })\n return this\n }\n\n /**\n * Registers multiple module factories with the locator\n * @param additional Additional module factories to register\n */\n registerMany(additional: CreatableModuleRegistry): this {\n Object.entries(additional).map(([schema, factories]) => {\n if (factories) {\n const existingFactories = this._registry[schema]\n this._registry[schema] = existingFactories ? [...existingFactories, ...factories] : factories\n }\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","/**\n * Object used to represent labels identifying a resource.\n */\nexport interface Labels {\n [key: string]: string | undefined\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithLabels<T extends Labels = Labels> {\n labels: T\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithOptionalLabels<T extends Labels = Labels> {\n labels?: T\n}\n\n/**\n * Returns true if the source object has all the labels from the required set\n * @param source Source object to check against\n * @param required Set of labels to check for in source\n * @returns True of the source object has all the labels from the required set\n */\nexport const hasAllLabels = (source?: Labels, required?: Labels): boolean => {\n if (!required) return true\n return Object.entries(required).every(([key, value]) => {\n // eslint-disable-next-line no-prototype-builtins\n return source?.hasOwnProperty(key as keyof typeof source) && source?.[key as keyof typeof source] === value\n })\n}\n"],"mappings":"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","names":["creatableModule","assertEx","assertEx"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Labels/Labels.ts"],"sourcesContent":["/**\n * Object used to represent labels identifying a resource.\n */\nexport interface Labels {\n [key: string]: string | undefined\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithLabels<T extends Labels = Labels> {\n labels: T\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithOptionalLabels<T extends Labels = Labels> {\n labels?: T\n}\n\n/**\n * Returns true if the source object has all the labels from the required set\n * @param source Source object to check against\n * @param required Set of labels to check for in source\n * @returns True of the source object has all the labels from the required set\n */\nexport const hasAllLabels = (source?: Labels, required?: Labels): boolean => {\n if (!required) return true\n return Object.entries(required).every(([key, value]) => {\n // eslint-disable-next-line no-prototype-builtins\n return source?.hasOwnProperty(key as keyof typeof source) && source?.[key as keyof typeof source] === value\n })\n}\n"],"mappings":"AA2BO,
|
|
1
|
+
{"version":3,"sources":["../../../src/Labels/Labels.ts"],"sourcesContent":["/**\n * Object used to represent labels identifying a resource.\n */\nexport interface Labels {\n [key: string]: string | undefined\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithLabels<T extends Labels = Labels> {\n labels: T\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithOptionalLabels<T extends Labels = Labels> {\n labels?: T\n}\n\n/**\n * Returns true if the source object has all the labels from the required set\n * @param source Source object to check against\n * @param required Set of labels to check for in source\n * @returns True of the source object has all the labels from the required set\n */\nexport const hasAllLabels = (source?: Labels, required?: Labels): boolean => {\n if (!required) return true\n return Object.entries(required).every(([key, value]) => {\n // eslint-disable-next-line no-prototype-builtins\n return source?.hasOwnProperty(key as keyof typeof source) && source?.[key as keyof typeof source] === value\n })\n}\n"],"mappings":";AA2BO,IAAM,eAAe,CAAC,QAAiB,aAA+B;AAC3E,MAAI,CAAC;AAAU,WAAO;AACtB,SAAO,OAAO,QAAQ,QAAQ,EAAE,MAAM,CAAC,CAAC,KAAK,KAAK,MAAM;AAEtD,WAAO,QAAQ,eAAe,GAA0B,KAAK,SAAS,GAA0B,MAAM;AAAA,EACxG,CAAC;AACH;","names":[]}
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
// src/Labels/Labels.ts
|
|
2
|
+
var hasAllLabels = (source, required) => {
|
|
3
|
+
if (!required)
|
|
4
|
+
return true;
|
|
5
|
+
return Object.entries(required).every(([key, value]) => {
|
|
6
|
+
return source?.hasOwnProperty(key) && source?.[key] === value;
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
hasAllLabels
|
|
11
|
+
};
|
|
2
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Labels/
|
|
1
|
+
{"version":3,"sources":["../../../src/Labels/Labels.ts"],"sourcesContent":["/**\n * Object used to represent labels identifying a resource.\n */\nexport interface Labels {\n [key: string]: string | undefined\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithLabels<T extends Labels = Labels> {\n labels: T\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithOptionalLabels<T extends Labels = Labels> {\n labels?: T\n}\n\n/**\n * Returns true if the source object has all the labels from the required set\n * @param source Source object to check against\n * @param required Set of labels to check for in source\n * @returns True of the source object has all the labels from the required set\n */\nexport const hasAllLabels = (source?: Labels, required?: Labels): boolean => {\n if (!required) return true\n return Object.entries(required).every(([key, value]) => {\n // eslint-disable-next-line no-prototype-builtins\n return source?.hasOwnProperty(key as keyof typeof source) && source?.[key as keyof typeof source] === value\n })\n}\n"],"mappings":";AA2BO,IAAM,eAAe,CAAC,QAAiB,aAA+B;AAC3E,MAAI,CAAC;AAAU,WAAO;AACtB,SAAO,OAAO,QAAQ,QAAQ,EAAE,MAAM,CAAC,CAAC,KAAK,KAAK,MAAM;AAEtD,WAAO,QAAQ,eAAe,GAA0B,KAAK,SAAS,GAA0B,MAAM;AAAA,EACxG,CAAC;AACH;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/Queries/Describe/Payload.ts"],"sourcesContent":["import { Payload } from '@xyo-network/payload-model'\n\nimport { ModuleDescription } from '../../ModuleDescription'\n\nexport const ModuleDescriptionSchema = 'network.xyo.module.description'\nexport type ModuleDescriptionSchema = typeof ModuleDescriptionSchema\n\nexport type ModuleDescriptionPayload = Payload<ModuleDescription, ModuleDescriptionSchema>\n"],"mappings":"AAIO,
|
|
1
|
+
{"version":3,"sources":["../../../../src/Queries/Describe/Payload.ts"],"sourcesContent":["import { Payload } from '@xyo-network/payload-model'\n\nimport { ModuleDescription } from '../../ModuleDescription'\n\nexport const ModuleDescriptionSchema = 'network.xyo.module.description'\nexport type ModuleDescriptionSchema = typeof ModuleDescriptionSchema\n\nexport type ModuleDescriptionPayload = Payload<ModuleDescription, ModuleDescriptionSchema>\n"],"mappings":";AAIO,IAAM,0BAA0B;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/Queries/Describe/Query.ts"],"sourcesContent":["import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleDescribeQuerySchema = 'network.xyo.query.module.describe'\nexport const ModuleDescribeQuerySchema: ModuleDescribeQuerySchema = 'network.xyo.query.module.describe'\n\nexport type ModuleDescribeQuery = Query<{\n schema: ModuleDescribeQuerySchema\n}>\n"],"mappings":"AAGO,
|
|
1
|
+
{"version":3,"sources":["../../../../src/Queries/Describe/Query.ts"],"sourcesContent":["import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleDescribeQuerySchema = 'network.xyo.query.module.describe'\nexport const ModuleDescribeQuerySchema: ModuleDescribeQuerySchema = 'network.xyo.query.module.describe'\n\nexport type ModuleDescribeQuery = Query<{\n schema: ModuleDescribeQuerySchema\n}>\n"],"mappings":";AAGO,IAAM,4BAAuD;","names":[]}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/Queries/Describe/Payload.ts
|
|
2
|
+
var ModuleDescriptionSchema = "network.xyo.module.description";
|
|
3
|
+
|
|
4
|
+
// src/Queries/Describe/Query.ts
|
|
5
|
+
var ModuleDescribeQuerySchema = "network.xyo.query.module.describe";
|
|
6
|
+
export {
|
|
7
|
+
ModuleDescribeQuerySchema,
|
|
8
|
+
ModuleDescriptionSchema
|
|
9
|
+
};
|
|
3
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/Queries/Describe/
|
|
1
|
+
{"version":3,"sources":["../../../../src/Queries/Describe/Payload.ts","../../../../src/Queries/Describe/Query.ts"],"sourcesContent":["import { Payload } from '@xyo-network/payload-model'\n\nimport { ModuleDescription } from '../../ModuleDescription'\n\nexport const ModuleDescriptionSchema = 'network.xyo.module.description'\nexport type ModuleDescriptionSchema = typeof ModuleDescriptionSchema\n\nexport type ModuleDescriptionPayload = Payload<ModuleDescription, ModuleDescriptionSchema>\n","import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleDescribeQuerySchema = 'network.xyo.query.module.describe'\nexport const ModuleDescribeQuerySchema: ModuleDescribeQuerySchema = 'network.xyo.query.module.describe'\n\nexport type ModuleDescribeQuery = Query<{\n schema: ModuleDescribeQuerySchema\n}>\n"],"mappings":";AAIO,IAAM,0BAA0B;;;ACDhC,IAAM,4BAAuD;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Queries/Discover.ts"],"sourcesContent":["import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleDiscoverQuerySchema = 'network.xyo.query.module.discover'\nexport const ModuleDiscoverQuerySchema: ModuleDiscoverQuerySchema = 'network.xyo.query.module.discover'\n\nexport type ModuleDiscoverQuery = Query<{\n schema: ModuleDiscoverQuerySchema\n}>\n"],"mappings":"AAGO,
|
|
1
|
+
{"version":3,"sources":["../../../src/Queries/Discover.ts"],"sourcesContent":["import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleDiscoverQuerySchema = 'network.xyo.query.module.discover'\nexport const ModuleDiscoverQuerySchema: ModuleDiscoverQuerySchema = 'network.xyo.query.module.discover'\n\nexport type ModuleDiscoverQuery = Query<{\n schema: ModuleDiscoverQuerySchema\n}>\n"],"mappings":";AAGO,IAAM,4BAAuD;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Queries/Manifest.ts"],"sourcesContent":["import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleManifestQuerySchema = 'network.xyo.query.module.manifest'\nexport const ModuleManifestQuerySchema: ModuleManifestQuerySchema = 'network.xyo.query.module.manifest'\n\nexport type ModuleManifestQuery = Query<{\n schema: ModuleManifestQuerySchema\n}>\n"],"mappings":"AAGO,
|
|
1
|
+
{"version":3,"sources":["../../../src/Queries/Manifest.ts"],"sourcesContent":["import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleManifestQuerySchema = 'network.xyo.query.module.manifest'\nexport const ModuleManifestQuerySchema: ModuleManifestQuerySchema = 'network.xyo.query.module.manifest'\n\nexport type ModuleManifestQuery = Query<{\n schema: ModuleManifestQuerySchema\n}>\n"],"mappings":";AAGO,IAAM,4BAAuD;","names":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// src/Queries/ModuleAddress/Payload.ts
|
|
1
2
|
import { AddressSchema } from "@xyo-network/address-payload-plugin";
|
|
2
|
-
|
|
3
|
+
var AddressPreviousHashSchema = `${AddressSchema}.hash.previous`;
|
|
3
4
|
export {
|
|
4
5
|
AddressPreviousHashSchema
|
|
5
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/Queries/ModuleAddress/Payload.ts"],"sourcesContent":["import { AddressSchema } from '@xyo-network/address-payload-plugin'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport const AddressPreviousHashSchema = `${AddressSchema}.hash.previous`\nexport type AddressPreviousHashSchema = typeof AddressPreviousHashSchema\n\nexport type AddressPreviousHashPayload = Payload<{\n address: string\n previousHash?: string\n schema: AddressPreviousHashSchema\n}>\n"],"mappings":"AAAA,SAAS,qBAAqB;AAGvB,
|
|
1
|
+
{"version":3,"sources":["../../../../src/Queries/ModuleAddress/Payload.ts"],"sourcesContent":["import { AddressSchema } from '@xyo-network/address-payload-plugin'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport const AddressPreviousHashSchema = `${AddressSchema}.hash.previous`\nexport type AddressPreviousHashSchema = typeof AddressPreviousHashSchema\n\nexport type AddressPreviousHashPayload = Payload<{\n address: string\n previousHash?: string\n schema: AddressPreviousHashSchema\n}>\n"],"mappings":";AAAA,SAAS,qBAAqB;AAGvB,IAAM,4BAA4B,GAAG,aAAa;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/Queries/ModuleAddress/Query.ts"],"sourcesContent":["import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleAddressQuerySchema = 'network.xyo.query.module.address'\nexport const ModuleAddressQuerySchema: ModuleAddressQuerySchema = 'network.xyo.query.module.address'\n\nexport type ModuleAddressQuery = Query<{\n schema: ModuleAddressQuerySchema\n}>\n"],"mappings":"AAGO,
|
|
1
|
+
{"version":3,"sources":["../../../../src/Queries/ModuleAddress/Query.ts"],"sourcesContent":["import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleAddressQuerySchema = 'network.xyo.query.module.address'\nexport const ModuleAddressQuerySchema: ModuleAddressQuerySchema = 'network.xyo.query.module.address'\n\nexport type ModuleAddressQuery = Query<{\n schema: ModuleAddressQuerySchema\n}>\n"],"mappings":";AAGO,IAAM,2BAAqD;","names":[]}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/Queries/ModuleAddress/Payload.ts
|
|
2
|
+
import { AddressSchema } from "@xyo-network/address-payload-plugin";
|
|
3
|
+
var AddressPreviousHashSchema = `${AddressSchema}.hash.previous`;
|
|
4
|
+
|
|
5
|
+
// src/Queries/ModuleAddress/Query.ts
|
|
6
|
+
var ModuleAddressQuerySchema = "network.xyo.query.module.address";
|
|
7
|
+
export {
|
|
8
|
+
AddressPreviousHashSchema,
|
|
9
|
+
ModuleAddressQuerySchema
|
|
10
|
+
};
|
|
3
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/Queries/ModuleAddress/
|
|
1
|
+
{"version":3,"sources":["../../../../src/Queries/ModuleAddress/Payload.ts","../../../../src/Queries/ModuleAddress/Query.ts"],"sourcesContent":["import { AddressSchema } from '@xyo-network/address-payload-plugin'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport const AddressPreviousHashSchema = `${AddressSchema}.hash.previous`\nexport type AddressPreviousHashSchema = typeof AddressPreviousHashSchema\n\nexport type AddressPreviousHashPayload = Payload<{\n address: string\n previousHash?: string\n schema: AddressPreviousHashSchema\n}>\n","import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleAddressQuerySchema = 'network.xyo.query.module.address'\nexport const ModuleAddressQuerySchema: ModuleAddressQuerySchema = 'network.xyo.query.module.address'\n\nexport type ModuleAddressQuery = Query<{\n schema: ModuleAddressQuerySchema\n}>\n"],"mappings":";AAAA,SAAS,qBAAqB;AAGvB,IAAM,4BAA4B,GAAG,aAAa;;;ACAlD,IAAM,2BAAqD;","names":[]}
|