@xyo-network/module-model 2.90.22 → 2.91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/browser/Config.d.cts +4 -4
  2. package/dist/browser/Config.d.cts.map +1 -1
  3. package/dist/browser/Config.d.mts +4 -4
  4. package/dist/browser/Config.d.mts.map +1 -1
  5. package/dist/browser/Config.d.ts +4 -4
  6. package/dist/browser/Config.d.ts.map +1 -1
  7. package/dist/browser/CreatableModule/LabeledCreatableModuleFactory.d.cts +4 -4
  8. package/dist/browser/CreatableModule/LabeledCreatableModuleFactory.d.mts +4 -4
  9. package/dist/browser/CreatableModule/LabeledCreatableModuleFactory.d.ts +4 -4
  10. package/dist/browser/EventsModels/ModuleEventArgs.d.cts.map +1 -1
  11. package/dist/browser/EventsModels/ModuleEventArgs.d.mts.map +1 -1
  12. package/dist/browser/EventsModels/ModuleEventArgs.d.ts.map +1 -1
  13. package/dist/browser/ModuleDescription.d.cts +4 -2
  14. package/dist/browser/ModuleDescription.d.cts.map +1 -1
  15. package/dist/browser/ModuleDescription.d.mts +4 -2
  16. package/dist/browser/ModuleDescription.d.mts.map +1 -1
  17. package/dist/browser/ModuleDescription.d.ts +4 -2
  18. package/dist/browser/ModuleDescription.d.ts.map +1 -1
  19. package/dist/browser/Queries/ModuleAddress/Payload.d.cts +2 -1
  20. package/dist/browser/Queries/ModuleAddress/Payload.d.cts.map +1 -1
  21. package/dist/browser/Queries/ModuleAddress/Payload.d.mts +2 -1
  22. package/dist/browser/Queries/ModuleAddress/Payload.d.mts.map +1 -1
  23. package/dist/browser/Queries/ModuleAddress/Payload.d.ts +2 -1
  24. package/dist/browser/Queries/ModuleAddress/Payload.d.ts.map +1 -1
  25. package/dist/browser/Queries/Subscribe.d.cts +2 -1
  26. package/dist/browser/Queries/Subscribe.d.cts.map +1 -1
  27. package/dist/browser/Queries/Subscribe.d.mts +2 -1
  28. package/dist/browser/Queries/Subscribe.d.mts.map +1 -1
  29. package/dist/browser/Queries/Subscribe.d.ts +2 -1
  30. package/dist/browser/Queries/Subscribe.d.ts.map +1 -1
  31. package/dist/browser/index.cjs +32 -1
  32. package/dist/browser/index.cjs.map +1 -1
  33. package/dist/browser/index.js +32 -1
  34. package/dist/browser/index.js.map +1 -1
  35. package/dist/browser/instance/ModuleInstance.d.cts +139 -6
  36. package/dist/browser/instance/ModuleInstance.d.cts.map +1 -1
  37. package/dist/browser/instance/ModuleInstance.d.mts +139 -6
  38. package/dist/browser/instance/ModuleInstance.d.mts.map +1 -1
  39. package/dist/browser/instance/ModuleInstance.d.ts +139 -6
  40. package/dist/browser/instance/ModuleInstance.d.ts.map +1 -1
  41. package/dist/browser/instance/ModuleRepository.d.cts +2 -1
  42. package/dist/browser/instance/ModuleRepository.d.cts.map +1 -1
  43. package/dist/browser/instance/ModuleRepository.d.mts +2 -1
  44. package/dist/browser/instance/ModuleRepository.d.mts.map +1 -1
  45. package/dist/browser/instance/ModuleRepository.d.ts +2 -1
  46. package/dist/browser/instance/ModuleRepository.d.ts.map +1 -1
  47. package/dist/browser/instance/asModuleInstance.d.cts +8 -8
  48. package/dist/browser/instance/asModuleInstance.d.mts +8 -8
  49. package/dist/browser/instance/asModuleInstance.d.ts +8 -8
  50. package/dist/browser/lib/duplicateModules.d.cts +4 -4
  51. package/dist/browser/lib/duplicateModules.d.mts +4 -4
  52. package/dist/browser/lib/duplicateModules.d.ts +4 -4
  53. package/dist/browser/module/ModuleFields.d.cts +2 -1
  54. package/dist/browser/module/ModuleFields.d.cts.map +1 -1
  55. package/dist/browser/module/ModuleFields.d.mts +2 -1
  56. package/dist/browser/module/ModuleFields.d.mts.map +1 -1
  57. package/dist/browser/module/ModuleFields.d.ts +2 -1
  58. package/dist/browser/module/ModuleFields.d.ts.map +1 -1
  59. package/dist/browser/module/asModule.d.cts +8 -8
  60. package/dist/browser/module/asModule.d.mts +8 -8
  61. package/dist/browser/module/asModule.d.ts +8 -8
  62. package/dist/browser/module/asModuleObject.d.cts +8 -8
  63. package/dist/browser/module/asModuleObject.d.mts +8 -8
  64. package/dist/browser/module/asModuleObject.d.ts +8 -8
  65. package/dist/browser/module/isModuleObject.d.cts +4 -4
  66. package/dist/browser/module/isModuleObject.d.mts +4 -4
  67. package/dist/browser/module/isModuleObject.d.ts +4 -4
  68. package/dist/browser/withModule.d.cts +8 -8
  69. package/dist/browser/withModule.d.mts +8 -8
  70. package/dist/browser/withModule.d.ts +8 -8
  71. package/dist/node/Config.d.cts +4 -4
  72. package/dist/node/Config.d.cts.map +1 -1
  73. package/dist/node/Config.d.mts +4 -4
  74. package/dist/node/Config.d.mts.map +1 -1
  75. package/dist/node/Config.d.ts +4 -4
  76. package/dist/node/Config.d.ts.map +1 -1
  77. package/dist/node/CreatableModule/LabeledCreatableModuleFactory.d.cts +4 -4
  78. package/dist/node/CreatableModule/LabeledCreatableModuleFactory.d.mts +4 -4
  79. package/dist/node/CreatableModule/LabeledCreatableModuleFactory.d.ts +4 -4
  80. package/dist/node/EventsModels/ModuleEventArgs.d.cts.map +1 -1
  81. package/dist/node/EventsModels/ModuleEventArgs.d.mts.map +1 -1
  82. package/dist/node/EventsModels/ModuleEventArgs.d.ts.map +1 -1
  83. package/dist/node/ModuleDescription.d.cts +4 -2
  84. package/dist/node/ModuleDescription.d.cts.map +1 -1
  85. package/dist/node/ModuleDescription.d.mts +4 -2
  86. package/dist/node/ModuleDescription.d.mts.map +1 -1
  87. package/dist/node/ModuleDescription.d.ts +4 -2
  88. package/dist/node/ModuleDescription.d.ts.map +1 -1
  89. package/dist/node/Queries/ModuleAddress/Payload.d.cts +2 -1
  90. package/dist/node/Queries/ModuleAddress/Payload.d.cts.map +1 -1
  91. package/dist/node/Queries/ModuleAddress/Payload.d.mts +2 -1
  92. package/dist/node/Queries/ModuleAddress/Payload.d.mts.map +1 -1
  93. package/dist/node/Queries/ModuleAddress/Payload.d.ts +2 -1
  94. package/dist/node/Queries/ModuleAddress/Payload.d.ts.map +1 -1
  95. package/dist/node/Queries/Subscribe.d.cts +2 -1
  96. package/dist/node/Queries/Subscribe.d.cts.map +1 -1
  97. package/dist/node/Queries/Subscribe.d.mts +2 -1
  98. package/dist/node/Queries/Subscribe.d.mts.map +1 -1
  99. package/dist/node/Queries/Subscribe.d.ts +2 -1
  100. package/dist/node/Queries/Subscribe.d.ts.map +1 -1
  101. package/dist/node/index.cjs +38 -1
  102. package/dist/node/index.cjs.map +1 -1
  103. package/dist/node/index.js +32 -1
  104. package/dist/node/index.js.map +1 -1
  105. package/dist/node/instance/ModuleInstance.d.cts +139 -6
  106. package/dist/node/instance/ModuleInstance.d.cts.map +1 -1
  107. package/dist/node/instance/ModuleInstance.d.mts +139 -6
  108. package/dist/node/instance/ModuleInstance.d.mts.map +1 -1
  109. package/dist/node/instance/ModuleInstance.d.ts +139 -6
  110. package/dist/node/instance/ModuleInstance.d.ts.map +1 -1
  111. package/dist/node/instance/ModuleRepository.d.cts +2 -1
  112. package/dist/node/instance/ModuleRepository.d.cts.map +1 -1
  113. package/dist/node/instance/ModuleRepository.d.mts +2 -1
  114. package/dist/node/instance/ModuleRepository.d.mts.map +1 -1
  115. package/dist/node/instance/ModuleRepository.d.ts +2 -1
  116. package/dist/node/instance/ModuleRepository.d.ts.map +1 -1
  117. package/dist/node/instance/asModuleInstance.d.cts +8 -8
  118. package/dist/node/instance/asModuleInstance.d.mts +8 -8
  119. package/dist/node/instance/asModuleInstance.d.ts +8 -8
  120. package/dist/node/lib/duplicateModules.d.cts +4 -4
  121. package/dist/node/lib/duplicateModules.d.mts +4 -4
  122. package/dist/node/lib/duplicateModules.d.ts +4 -4
  123. package/dist/node/module/ModuleFields.d.cts +2 -1
  124. package/dist/node/module/ModuleFields.d.cts.map +1 -1
  125. package/dist/node/module/ModuleFields.d.mts +2 -1
  126. package/dist/node/module/ModuleFields.d.mts.map +1 -1
  127. package/dist/node/module/ModuleFields.d.ts +2 -1
  128. package/dist/node/module/ModuleFields.d.ts.map +1 -1
  129. package/dist/node/module/asModule.d.cts +8 -8
  130. package/dist/node/module/asModule.d.mts +8 -8
  131. package/dist/node/module/asModule.d.ts +8 -8
  132. package/dist/node/module/asModuleObject.d.cts +8 -8
  133. package/dist/node/module/asModuleObject.d.mts +8 -8
  134. package/dist/node/module/asModuleObject.d.ts +8 -8
  135. package/dist/node/module/isModuleObject.d.cts +4 -4
  136. package/dist/node/module/isModuleObject.d.mts +4 -4
  137. package/dist/node/module/isModuleObject.d.ts +4 -4
  138. package/dist/node/withModule.d.cts +8 -8
  139. package/dist/node/withModule.d.mts +8 -8
  140. package/dist/node/withModule.d.ts +8 -8
  141. package/package.json +16 -16
  142. package/src/Config.ts +4 -4
  143. package/src/CreatableModule/ModuleFactoryLocator.ts +2 -2
  144. package/src/EventsModels/ModuleEventArgs.ts +3 -2
  145. package/src/ModuleDescription.ts +5 -2
  146. package/src/Queries/ModuleAddress/Payload.ts +2 -1
  147. package/src/Queries/Subscribe.ts +2 -1
  148. package/src/instance/ModuleInstance.ts +41 -6
  149. package/src/instance/ModuleRepository.ts +3 -1
  150. package/src/module/ModuleFields.ts +2 -1
@@ -34,6 +34,7 @@ __export(src_exports, {
34
34
  ModuleManifestQuerySchema: () => ModuleManifestQuerySchema,
35
35
  ModuleStateSchema: () => ModuleStateSchema,
36
36
  ModuleSubscribeQuerySchema: () => ModuleSubscribeQuerySchema,
37
+ ReservedModuleIdentifierCharacters: () => ReservedModuleIdentifierCharacters,
37
38
  WithFactory: () => WithFactory,
38
39
  asModule: () => asModule,
39
40
  asModuleInstance: () => asModuleInstance,
@@ -43,12 +44,17 @@ __export(src_exports, {
43
44
  duplicateModules: () => duplicateModules,
44
45
  hasAllLabels: () => hasAllLabels,
45
46
  hasLabels: () => hasLabels,
47
+ isAddressModuleFilter: () => isAddressModuleFilter,
46
48
  isModule: () => isModule,
49
+ isModuleIdentifierPart: () => isModuleIdentifierPart,
47
50
  isModuleInstance: () => isModuleInstance,
48
51
  isModuleObject: () => isModuleObject,
49
52
  isModuleResolver: () => isModuleResolver,
50
53
  isModuleState: () => isModuleState,
51
54
  isModuleStateWithMeta: () => isModuleStateWithMeta,
55
+ isNameModuleFilter: () => isNameModuleFilter,
56
+ isQueryModuleFilter: () => isQueryModuleFilter,
57
+ isReservedModuleIdentifierCharacter: () => isReservedModuleIdentifierCharacter,
52
58
  requiredModuleInstanceFunctions: () => requiredModuleInstanceFunctions,
53
59
  requiredModuleQueries: () => requiredModuleQueries,
54
60
  requiredModuleShape: () => requiredModuleShape,
@@ -234,7 +240,10 @@ var _ModuleFactoryLocator = class _ModuleFactoryLocator {
234
240
  */
235
241
  tryLocate(schema, labels) {
236
242
  var _a, _b;
237
- return labels ? (_a = this._registry[schema]) == null ? void 0 : _a.filter(hasLabels).find((factory4) => hasAllLabels(factory4 == null ? void 0 : factory4.labels, labels)) : (_b = this._registry[schema]) == null ? void 0 : _b[0];
243
+ return labels ? (
244
+ // Find the first factory that has labels and has all the labels provided
245
+ (_a = this._registry[schema]) == null ? void 0 : _a.filter(hasLabels).find((factory4) => hasAllLabels(factory4 == null ? void 0 : factory4.labels, labels))
246
+ ) : (_b = this._registry[schema]) == null ? void 0 : _b[0];
238
247
  }
239
248
  };
240
249
  __name(_ModuleFactoryLocator, "ModuleFactoryLocator");
@@ -336,6 +345,25 @@ var asModuleInstance = import_object5.AsObjectFactory.create(isModuleInstance);
336
345
 
337
346
  // src/instance/ModuleInstance.ts
338
347
  var import_object6 = require("@xylabs/object");
348
+ var ReservedModuleIdentifierCharacters = /* @__PURE__ */ new Set([
349
+ ":"
350
+ ]);
351
+ var isReservedModuleIdentifierCharacter = /* @__PURE__ */ __name((value) => {
352
+ return typeof value === "string" && value.length === 1 && ReservedModuleIdentifierCharacters.has(value);
353
+ }, "isReservedModuleIdentifierCharacter");
354
+ var isModuleIdentifierPart = /* @__PURE__ */ __name((value, falseAction = "none") => {
355
+ const result = typeof value === "string" && ![
356
+ ...value
357
+ ].some(isReservedModuleIdentifierCharacter);
358
+ switch (falseAction) {
359
+ case "throw": {
360
+ throw new Error(`Invalid ModuleIdentifierPart: ${value}`);
361
+ }
362
+ default: {
363
+ return result;
364
+ }
365
+ }
366
+ }, "isModuleIdentifierPart");
339
367
  var isModuleResolver = /* @__PURE__ */ __name((value) => {
340
368
  return typeof value.resolve === "function";
341
369
  }, "isModuleResolver");
@@ -343,6 +371,9 @@ var _IsInstanceFactory = class _IsInstanceFactory extends import_object6.IsObjec
343
371
  };
344
372
  __name(_IsInstanceFactory, "IsInstanceFactory");
345
373
  var IsInstanceFactory = _IsInstanceFactory;
374
+ var isAddressModuleFilter = /* @__PURE__ */ __name((value) => value.address !== void 0, "isAddressModuleFilter");
375
+ var isNameModuleFilter = /* @__PURE__ */ __name((value) => value.name !== void 0, "isNameModuleFilter");
376
+ var isQueryModuleFilter = /* @__PURE__ */ __name((value) => value.query !== void 0, "isQueryModuleFilter");
346
377
 
347
378
  // src/lib/duplicateModules.ts
348
379
  var duplicateModules = /* @__PURE__ */ __name((value, index, array) => {
@@ -422,6 +453,7 @@ var withModuleInstance = WithFactory.create(isModuleInstance);
422
453
  ModuleManifestQuerySchema,
423
454
  ModuleStateSchema,
424
455
  ModuleSubscribeQuerySchema,
456
+ ReservedModuleIdentifierCharacters,
425
457
  WithFactory,
426
458
  asModule,
427
459
  asModuleInstance,
@@ -431,12 +463,17 @@ var withModuleInstance = WithFactory.create(isModuleInstance);
431
463
  duplicateModules,
432
464
  hasAllLabels,
433
465
  hasLabels,
466
+ isAddressModuleFilter,
434
467
  isModule,
468
+ isModuleIdentifierPart,
435
469
  isModuleInstance,
436
470
  isModuleObject,
437
471
  isModuleResolver,
438
472
  isModuleState,
439
473
  isModuleStateWithMeta,
474
+ isNameModuleFilter,
475
+ isQueryModuleFilter,
476
+ isReservedModuleIdentifierCharacter,
440
477
  requiredModuleInstanceFunctions,
441
478
  requiredModuleQueries,
442
479
  requiredModuleShape,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/Config.ts","../../src/CreatableModule/CreatableModule.ts","../../src/CreatableModule/CreatableModuleRegistry.ts","../../src/CreatableModule/LabeledCreatableModuleFactory.ts","../../src/CreatableModule/ModuleFactory.ts","../../src/CreatableModule/ModuleFactoryLocator.ts","../../src/Labels/Labels.ts","../../src/instance/asModuleInstance.ts","../../src/instance/isModuleInstance.ts","../../src/module/asModule.ts","../../src/Queries/Describe/Payload.ts","../../src/Queries/Describe/Query.ts","../../src/Queries/Discover.ts","../../src/Queries/Manifest.ts","../../src/Queries/ModuleAddress/Payload.ts","../../src/Queries/ModuleAddress/Query.ts","../../src/Queries/Subscribe.ts","../../src/module/asModuleObject.ts","../../src/module/isModuleObject.ts","../../src/module/IsModuleFactory.ts","../../src/module/isModule.ts","../../src/instance/ModuleInstance.ts","../../src/lib/duplicateModules.ts","../../src/lib/serializable.ts","../../src/Payload/ModuleState.ts","../../src/withModule.ts"],"sourcesContent":["export * from './Config'\nexport * from './CreatableModule'\nexport * from './EventsModels'\nexport * from './instance'\nexport * from './Labels'\nexport * from './lib'\nexport * from './module'\nexport * from './ModuleDescription'\nexport * from './ModuleParams'\nexport * from './ModuleQueryHandlerResult'\nexport * from './ModuleQueryResult'\nexport * from './Payload'\nexport * from './Queries'\nexport * from './withModule'\n","import { Address } from '@xylabs/hex'\nimport { EmptyObject, WithAdditional } from '@xylabs/object'\nimport { RetryConfig } from '@xylabs/retry'\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 CosigningAddressSet = string[]\nexport type SchemaString = string\nexport type ModuleName = string\nexport type NameOrAddress = Address | ModuleName\n\nexport interface ArchivingModuleConfig {\n readonly archiving?: {\n readonly archivists?: NameOrAddress[]\n }\n}\n\nexport type ModuleConfig<TConfig extends EmptyObject | Payload | void = void, TSchema extends Schema | void = void> = Payload<\n WithAdditional<\n {\n /** @field The name/address of the Archivist to use for this module */\n readonly archivist?: NameOrAddress\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 readonly retry?: RetryConfig\n\n schema: TConfig extends Payload ? TConfig['schema'] : ModuleConfigSchema\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, (Address | CosigningAddressSet)[]>\n\n /** @field If schema in record, then anyone except these addresses can access query */\n readonly disallowed?: Record<SchemaString, Address[]>\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 } & ArchivingModuleConfig,\n TConfig\n >,\n TSchema\n>\n\nexport type AnyConfigSchema<TConfig extends Omit<ModuleConfig, 'schema'> & { schema: string } = Omit<ModuleConfig, 'schema'> & { schema: string }> =\n ModuleConfig<TConfig, string>\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","import { Logger } from '@xylabs/logger'\nimport { AccountInstance } from '@xyo-network/account-model'\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 // eslint-disable-next-line unicorn/no-array-reduce\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 '@xylabs/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?: Partial<TModule['params']['config']> }\n\n labels?: Labels\n\n constructor(\n creatableModule: CreatableModule<TModule>,\n params?: Omit<TModule['params'], 'config'> & { config?: Partial<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","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModuleInstance } from './isModuleInstance'\n\nexport const asModuleInstance = AsObjectFactory.create(isModuleInstance)\n","import { IsObjectFactory, ObjectTypeShape, TypeCheck } from '@xylabs/object'\n\nimport { isModule } from '../module'\nimport { ModuleInstance } from './ModuleInstance'\n\nexport const requiredModuleInstanceFunctions: ObjectTypeShape = {\n describe: 'function',\n discover: 'function',\n manifest: 'function',\n moduleAddress: 'function',\n}\n\n//we do not use IsInstanceFactory here to prevent a cycle\nconst factory = new IsObjectFactory<ModuleInstance>()\n\nexport const isModuleInstance: TypeCheck<ModuleInstance> = factory.create(requiredModuleInstanceFunctions, [isModule])\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModule } from './isModule'\n\nexport const asModule = AsObjectFactory.create(isModule)\n","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","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 maxDepth?: number\n schema: ModuleDiscoverQuerySchema\n}>\n","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 maxDepth?: number\n schema: ModuleManifestQuerySchema\n}>\n","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","import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleSubscribeQuerySchema = 'network.xyo.query.module.subscribe'\nexport const ModuleSubscribeQuerySchema: ModuleSubscribeQuerySchema = 'network.xyo.query.module.subscribe'\n\nexport interface ModuleSubscribeFilter {\n /** @field if specified, at least one of the schemas must be present in the boundwtness to generate a notification */\n schema?: string[]\n}\n\n//requests notification when a boundwitness is added to the modules chain that meets the filter criteria\nexport type ModuleSubscribeQuery = Query<{\n /** @field The address that will receive notifications */\n address: string\n /** @field A subscribe with a null for filter is an unsubscribe */\n filter?: ModuleSubscribeFilter | null\n /** @field The maximum events queued per send [may increase frequency] */\n maxQueue?: number\n schema: ModuleSubscribeQuerySchema\n}>\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModuleObject } from './isModuleObject'\n\nexport const asModuleObject = AsObjectFactory.create(isModuleObject)\n","import { IsObjectFactory, ObjectTypeShape } from '@xylabs/object'\n\nimport { Module } from './Module'\n\nexport const requiredModuleShape: ObjectTypeShape = {\n address: 'string',\n config: 'object',\n params: 'object',\n queries: 'array',\n query: 'function',\n queryable: 'function',\n}\n\nconst factory = new IsObjectFactory<Module>()\n\nexport const isModuleObject = factory.create(requiredModuleShape)\n","import { AnyObject, EmptyObject, TypeCheck } from '@xylabs/object'\n\nimport { asModuleObject } from './asModuleObject'\nimport { isModuleObject } from './isModuleObject'\nimport { Module } from './Module'\n\nexport type ModuleTypeCheck<T extends Module = Module> = TypeCheck<T>\n\nexport class IsModuleFactory<T extends Module = Module> {\n create(expectedQueries?: string[], additionalChecks?: TypeCheck<AnyObject | EmptyObject>[]): ModuleTypeCheck<T> {\n return (obj: unknown, config): obj is T => {\n const module = asModuleObject(obj)\n const result =\n isModuleObject(module, config) &&\n (expectedQueries?.reduce((prev, query) => prev && module.queries.includes(query), true) ?? true) &&\n //perform additional checks\n (additionalChecks?.reduce((prev, check) => prev && check(obj, config), true) ?? true)\n return result\n }\n }\n}\n","import { TypeCheck } from '@xylabs/object'\n\nimport { ModuleDiscoverQuerySchema } from '../Queries'\nimport { IsModuleFactory } from './IsModuleFactory'\nimport { isModuleObject } from './isModuleObject'\nimport { Module } from './Module'\n\nexport const requiredModuleQueries: string[] = [\n /* We need to update this once live module conform */\n //ModuleDescribeQuerySchema,\n //ModuleAddressQuerySchema,\n ModuleDiscoverQuerySchema,\n //ModuleManifestQuerySchema,\n //ModuleSubscribeQuerySchema,\n]\n\n//we do not use IsInstanceFactory here to prevent a cycle\nconst factory = new IsModuleFactory<Module>()\n\nexport const isModule: TypeCheck<Module> = factory.create(requiredModuleQueries, [isModuleObject])\n","import { IsObjectFactory, TypeCheck } from '@xylabs/object'\nimport { Promisable } from '@xylabs/promise'\n\nimport { ModuleEventData } from '../EventsModels'\nimport { Module, ModuleQueryFunctions } from '../module'\nimport { ModuleParams } from '../ModuleParams'\n\nexport type ModulePipeLine = 'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many'\n\nexport const isModuleResolver = (value?: unknown): value is ModuleResolver => {\n return typeof (value as Partial<ModuleResolver>).resolve === 'function'\n}\n\nexport interface ModuleResolver {\n resolve<T extends ModuleInstance = ModuleInstance>(filter?: ModuleFilter<T>, options?: ModuleFilterOptions<T>): Promisable<T[]>\n resolve<T extends ModuleInstance = ModuleInstance>(nameOrAddress: string, options?: ModuleFilterOptions<T>): Promisable<T | undefined>\n resolve<T extends ModuleInstance = ModuleInstance>(\n nameOrAddressOrFilter?: ModuleFilter<T> | string,\n options?: ModuleFilterOptions<T>,\n ): Promisable<T | T[] | undefined>\n}\n\nexport interface ModuleResolverInstance extends ModuleResolver {\n addResolver: (resolver: ModuleResolverInstance) => this\n removeResolver: (resolver: ModuleResolverInstance) => this\n}\n\nexport interface ModuleInstance<TParams extends ModuleParams = ModuleParams, TEventData extends ModuleEventData = ModuleEventData>\n extends Module<TParams, TEventData>,\n ModuleResolver,\n ModuleQueryFunctions {\n /* The resolver is a 'down' resolver. It can resolve the module or any children (if it is a node for example), that are in the module*/\n readonly downResolver: Omit<ModuleResolverInstance, 'resolve'>\n\n readonly pipeline?: ModulePipeLine\n\n /* The resolver is a 'up' resolver. It can resolve the parent or any children of the parent*/\n /* This is set by a NodeModule when attaching to the module */\n readonly upResolver: Omit<ModuleResolverInstance, 'resolve'>\n}\n\nexport type InstanceTypeCheck<T extends ModuleInstance = ModuleInstance> = TypeCheck<T>\n\nexport class IsInstanceFactory<T extends ModuleInstance = ModuleInstance> extends IsObjectFactory<T> {}\n\nexport interface ModuleFilterOptions<T extends ModuleInstance = ModuleInstance> {\n direction?: 'up' | 'down' | 'all'\n identity?: InstanceTypeCheck<T>\n maxDepth?: number\n visibility?: 'public' | 'private' | 'all'\n}\n\nexport interface AddressModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n address: string[]\n}\n\nexport interface NameModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n name: string[]\n}\n\nexport interface QueryModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n query: string[][]\n}\n\nexport type AnyModuleFilter<T extends ModuleInstance = ModuleInstance> = Partial<AddressModuleFilter<T>> &\n Partial<NameModuleFilter<T>> &\n Partial<QueryModuleFilter<T>>\n\nexport type ModuleFilter<T extends ModuleInstance = ModuleInstance> =\n | ModuleFilterOptions<T>\n | AddressModuleFilter<T>\n | NameModuleFilter<T>\n | QueryModuleFilter<T>\n","import { Module } from '../module'\n\n/**\n * Used to filter duplicates from an array of modules\n * @example: modulesArray.filter(duplicateModules)\n * @param value Current Module\n * @param index Current Module's index\n * @param array Module Array\n * @returns True if the Module's address is the first occurrence of\n * that address in the array, false otherwise\n */\nexport const duplicateModules = (value: Module, index: number, array: Module[]): value is Module => {\n return array.findIndex((v) => v.address === value.address) === index\n}\n","// Inspired by https://stackoverflow.com/a/49079549/2803259\n\nimport { every, isArray, isBoolean, isNull, isNumber, isPlainObject, isString, isUndefined, overSome } from '@xylabs/lodash'\n\nconst JSONPrimitiveChecks = [isUndefined, isNull, isBoolean, isNumber, isString]\nconst JSONComplexChecks = [isPlainObject, isArray]\n\nexport const serializable = (field: unknown, depth?: number): boolean | null => {\n let depthExceeded = false\n const decrementDepth = () => (depth ? depth-- : undefined)\n\n const recursiveSerializable = (field: unknown) => {\n if (depth !== undefined && depth < 1) {\n depthExceeded = true\n return false\n }\n\n // decrement during every recursion\n decrementDepth()\n\n const nestedSerializable = (field: unknown): boolean => overSome(JSONComplexChecks)(field) && every(field as object, recursiveSerializable)\n\n return overSome([...JSONPrimitiveChecks, nestedSerializable])(field)\n }\n\n const valid = recursiveSerializable(field)\n\n return depthExceeded ? null : valid\n}\n\nexport const serializableField = (field: unknown) => {\n return overSome([...JSONPrimitiveChecks, ...JSONComplexChecks])(field)\n}\n","import { isPayloadOfSchemaType, Payload, WithMeta } from '@xyo-network/payload-model'\n\nexport interface StateDictionary {\n [key: string]: string | number | undefined\n}\nexport interface State<T extends StateDictionary = StateDictionary> {\n state: T\n}\n\nexport const ModuleStateSchema = 'network.xyo.module.state' as const\nexport type ModuleStateSchema = typeof ModuleStateSchema\n\nexport type ModuleState<T extends StateDictionary = StateDictionary> = Payload<State<T>, ModuleStateSchema>\n\nexport const isModuleState = <T extends StateDictionary = StateDictionary>(payload?: Payload | null): payload is ModuleState<T> => {\n return isPayloadOfSchemaType<ModuleState<T>>(ModuleStateSchema)(payload)\n}\n\nexport const isModuleStateWithMeta = <T extends StateDictionary = StateDictionary>(payload?: Payload | null): payload is WithMeta<ModuleState<T>> => {\n return isPayloadOfSchemaType<WithMeta<ModuleState<T>>>(ModuleStateSchema)(payload)\n}\n","import { TypeCheck } from '@xylabs/object'\n\nimport { isModuleInstance } from './instance'\nimport { isModule } from './module'\n\nexport const WithFactory = {\n create: <T extends object>(typeCheck: TypeCheck<T>) => {\n return <R>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n module: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n closure: (module: T) => R,\n ): R | undefined => {\n return typeCheck(module) ? closure(module) : undefined\n }\n },\n}\n\nexport const withModule = WithFactory.create(isModule)\nexport const withModuleInstance = WithFactory.create(isModuleInstance)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACQO,IAAMA,qBAAyC;;;ACiB/C,SAASC,kBAAAA;AACd,SAAO,CAAqCC,gBAAAA;AAC1CA;EACF;AACF;AAJgBD;;;ACjBT,IAAME,4BAA4B,wBAACC,SAAAA;AAExC,SAAOC,OAAOC,QAAQF,IAAAA,EAAMG,OAAO,CAACC,UAAU,CAACC,QAAQC,QAAAA,MAAQ;AAC7DF,aAASC,MAAAA,IAAUE,MAAMC,QAAQF,QAAAA,IAAWA,WAAU;MAACA;;AACvD,WAAOF;EACT,GAAG,CAAC,CAAA;AACN,GANyC;AAQlC,IAAMK,gCAAgC,wBAC3CC,SAAkC,CAAC,MAChCC,YAAAA;AAEHA,UAAQC,IAAI,CAACC,WACXZ,OAAOC,QAAQW,MAAAA,EAAQD,IAAI,CAAC,CAACP,QAAQS,SAAAA,MAAU;AAC7C,QAAIA,WAAW;AACb,YAAMC,oBAAoBL,OAAOL,MAAAA;AACjCK,aAAOL,MAAAA,IAAUU,oBAAqBL,OAAOL,MAAAA,IAAU;WAAIU;WAAsBD;UAAcA;IACjG;EACF,CAAA,CAAA;AAEF,SAAOJ;AACT,GAb6C;;;ACVtC,IAAMM,YAAY,wBAACC,aAAAA;AACxB,SAAQA,SAA0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,sBAAgB;AAChB,aAAO;IACT;AAGAC,mBAAAA;AAEA,UAAMG,qBAAqB,wBAACN,eAA4BO,yBAASX,iBAAAA,EAAmBI,MAAAA,SAAUQ,sBAAMR,QAAiBK,qBAAAA,GAA1F;AAE3B,eAAOE,yBAAS;SAAIjB;MAAqBgB;KAAmB,EAAEN,MAAAA;EAChE,GAZ8B;AAc9B,QAAMS,QAAQJ,sBAAsBL,KAAAA;AAEpC,SAAOE,gBAAgB,OAAOO;AAChC,GArB4B;AAuBrB,IAAMC,oBAAoB,wBAACV,UAAAA;AAChC,aAAOO,yBAAS;OAAIjB;OAAwBM;GAAkB,EAAEI,KAAAA;AAClE,GAFiC;;;AC9BjC,2BAAyD;AASlD,IAAMW,oBAAoB;AAK1B,IAAMC,gBAAgB,wBAA8CC,YAAAA;AACzE,aAAOC,4CAAsCH,iBAAAA,EAAmBE,OAAAA;AAClE,GAF6B;AAItB,IAAME,wBAAwB,wBAA8CF,YAAAA;AACjF,aAAOC,4CAAgDH,iBAAAA,EAAmBE,OAAAA;AAC5E,GAFqC;;;ACb9B,IAAMG,cAAc;EACzBC,QAAQ,CAAmBC,cAAAA;AACzB,WAAO,CAELC,SAEAC,YAAAA;AAEA,aAAOF,UAAUC,OAAAA,IAAUC,QAAQD,OAAAA,IAAUE;IAC/C;EACF;AACF;AAEO,IAAMC,aAAaN,YAAYC,OAAOM,QAAAA;AACtC,IAAMC,qBAAqBR,YAAYC,OAAOQ,gBAAAA;","names":["ModuleConfigSchema","creatableModule","constructor","toCreatableModuleRegistry","dict","Object","entries","reduce","registry","schema","factory","Array","isArray","assignCreatableModuleRegistry","target","sources","map","source","factories","existingFactories","hasLabels","factory","labels","undefined","ModuleFactory","configSchemas","creatableModule","defaultLogger","defaultParams","labels","constructor","params","Object","assign","configSchema","withParams","_getRootFunction","funcName","anyThis","__proto__","_noOverride","functionName","thisFunc","rootFunc","assertEx","create","factory","schema","mergedParams","merge","config","_params","Error","import_assert","hasAllLabels","source","required","Object","entries","every","key","value","hasOwnProperty","ModuleFactoryLocator","constructor","_registry","registry","locate","schema","labels","assertEx","tryLocate","configString","labelsString","JSON","stringify","register","mod","configSchemas","map","existingFactories","factory","create","bind","Object","assign","registerMany","additional","entries","factories","filter","hasLabels","find","hasAllLabels","import_object","import_object","import_object","ModuleDescriptionSchema","ModuleDescribeQuerySchema","ModuleDiscoverQuerySchema","ModuleManifestQuerySchema","AddressPreviousHashSchema","AddressSchema","ModuleAddressQuerySchema","ModuleSubscribeQuerySchema","import_object","requiredModuleShape","address","config","params","queries","query","queryable","factory","IsObjectFactory","isModuleObject","create","asModuleObject","AsObjectFactory","create","isModuleObject","IsModuleFactory","create","expectedQueries","additionalChecks","obj","config","module","asModuleObject","result","isModuleObject","reduce","prev","query","queries","includes","check","requiredModuleQueries","ModuleDiscoverQuerySchema","factory","IsModuleFactory","isModule","create","isModuleObject","asModule","AsObjectFactory","create","isModule","requiredModuleInstanceFunctions","describe","discover","manifest","moduleAddress","factory","IsObjectFactory","isModuleInstance","create","isModule","asModuleInstance","AsObjectFactory","create","isModuleInstance","import_object","isModuleResolver","value","resolve","IsInstanceFactory","IsObjectFactory","duplicateModules","value","index","array","findIndex","v","address","import_lodash","JSONPrimitiveChecks","isUndefined","isNull","isBoolean","isNumber","isString","JSONComplexChecks","isPlainObject","isArray","serializable","field","depth","depthExceeded","decrementDepth","undefined","recursiveSerializable","nestedSerializable","overSome","every","valid","serializableField","ModuleStateSchema","isModuleState","payload","isPayloadOfSchemaType","isModuleStateWithMeta","WithFactory","create","typeCheck","module","closure","undefined","withModule","isModule","withModuleInstance","isModuleInstance"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Config.ts","../../src/CreatableModule/CreatableModule.ts","../../src/CreatableModule/CreatableModuleRegistry.ts","../../src/CreatableModule/LabeledCreatableModuleFactory.ts","../../src/CreatableModule/ModuleFactory.ts","../../src/CreatableModule/ModuleFactoryLocator.ts","../../src/Labels/Labels.ts","../../src/instance/asModuleInstance.ts","../../src/instance/isModuleInstance.ts","../../src/module/asModule.ts","../../src/Queries/Describe/Payload.ts","../../src/Queries/Describe/Query.ts","../../src/Queries/Discover.ts","../../src/Queries/Manifest.ts","../../src/Queries/ModuleAddress/Payload.ts","../../src/Queries/ModuleAddress/Query.ts","../../src/Queries/Subscribe.ts","../../src/module/asModuleObject.ts","../../src/module/isModuleObject.ts","../../src/module/IsModuleFactory.ts","../../src/module/isModule.ts","../../src/instance/ModuleInstance.ts","../../src/lib/duplicateModules.ts","../../src/lib/serializable.ts","../../src/Payload/ModuleState.ts","../../src/withModule.ts"],"sourcesContent":["export * from './Config'\nexport * from './CreatableModule'\nexport * from './EventsModels'\nexport * from './instance'\nexport * from './Labels'\nexport * from './lib'\nexport * from './module'\nexport * from './ModuleDescription'\nexport * from './ModuleParams'\nexport * from './ModuleQueryHandlerResult'\nexport * from './ModuleQueryResult'\nexport * from './Payload'\nexport * from './Queries'\nexport * from './withModule'\n","import { Address } from '@xylabs/hex'\nimport { EmptyObject, WithAdditional } from '@xylabs/object'\nimport { RetryConfig } from '@xylabs/retry'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\nimport { ModuleIdentifier, ModuleName } from './instance'\nimport { Labels } from './Labels'\n\nexport type ModuleConfigSchema = 'network.xyo.module.config'\nexport const ModuleConfigSchema: ModuleConfigSchema = 'network.xyo.module.config'\n\nexport type CosigningAddressSet = string[]\nexport type SchemaString = string\nexport type NameOrAddress = Address | ModuleName\n\nexport interface ArchivingModuleConfig {\n readonly archiving?: {\n readonly archivists?: ModuleIdentifier[]\n }\n}\n\nexport type ModuleConfig<TConfig extends EmptyObject | Payload | void = void, TSchema extends Schema | void = void> = Payload<\n WithAdditional<\n {\n /** @field The name/address of the Archivist to use for this module */\n readonly archivist?: ModuleIdentifier\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?: ModuleName\n\n /** @field paging settings for queries */\n readonly paging?: Record<string, { size?: number }>\n\n readonly retry?: RetryConfig\n\n schema: TConfig extends Payload ? TConfig['schema'] : ModuleConfigSchema\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, (Address | CosigningAddressSet)[]>\n\n /** @field If schema in record, then anyone except these addresses can access query */\n readonly disallowed?: Record<SchemaString, Address[]>\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 } & ArchivingModuleConfig,\n TConfig\n >,\n TSchema\n>\n\nexport type AnyConfigSchema<TConfig extends Omit<ModuleConfig, 'schema'> & { schema: string } = Omit<ModuleConfig, 'schema'> & { schema: string }> =\n ModuleConfig<TConfig, string>\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","import { Logger } from '@xylabs/logger'\nimport { AccountInstance } from '@xyo-network/account-model'\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 // eslint-disable-next-line unicorn/no-array-reduce\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 '@xylabs/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?: Partial<TModule['params']['config']> }\n\n labels?: Labels\n\n constructor(\n creatableModule: CreatableModule<TModule>,\n params?: Omit<TModule['params'], 'config'> & { config?: Partial<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","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModuleInstance } from './isModuleInstance'\n\nexport const asModuleInstance = AsObjectFactory.create(isModuleInstance)\n","import { IsObjectFactory, ObjectTypeShape, TypeCheck } from '@xylabs/object'\n\nimport { isModule } from '../module'\nimport { ModuleInstance } from './ModuleInstance'\n\nexport const requiredModuleInstanceFunctions: ObjectTypeShape = {\n describe: 'function',\n discover: 'function',\n manifest: 'function',\n moduleAddress: 'function',\n}\n\n//we do not use IsInstanceFactory here to prevent a cycle\nconst factory = new IsObjectFactory<ModuleInstance>()\n\nexport const isModuleInstance: TypeCheck<ModuleInstance> = factory.create(requiredModuleInstanceFunctions, [isModule])\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModule } from './isModule'\n\nexport const asModule = AsObjectFactory.create(isModule)\n","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","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 maxDepth?: number\n schema: ModuleDiscoverQuerySchema\n}>\n","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 maxDepth?: number\n schema: ModuleManifestQuerySchema\n}>\n","import { Address } from '@xylabs/hex'\nimport { 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: Address\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","import { Address } from '@xylabs/hex'\nimport { Query } from '@xyo-network/payload-model'\n\nexport type ModuleSubscribeQuerySchema = 'network.xyo.query.module.subscribe'\nexport const ModuleSubscribeQuerySchema: ModuleSubscribeQuerySchema = 'network.xyo.query.module.subscribe'\n\nexport interface ModuleSubscribeFilter {\n /** @field if specified, at least one of the schemas must be present in the boundwtness to generate a notification */\n schema?: string[]\n}\n\n//requests notification when a boundwitness is added to the modules chain that meets the filter criteria\nexport type ModuleSubscribeQuery = Query<{\n /** @field The address that will receive notifications */\n address: Address\n /** @field A subscribe with a null for filter is an unsubscribe */\n filter?: ModuleSubscribeFilter | null\n /** @field The maximum events queued per send [may increase frequency] */\n maxQueue?: number\n schema: ModuleSubscribeQuerySchema\n}>\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModuleObject } from './isModuleObject'\n\nexport const asModuleObject = AsObjectFactory.create(isModuleObject)\n","import { IsObjectFactory, ObjectTypeShape } from '@xylabs/object'\n\nimport { Module } from './Module'\n\nexport const requiredModuleShape: ObjectTypeShape = {\n address: 'string',\n config: 'object',\n params: 'object',\n queries: 'array',\n query: 'function',\n queryable: 'function',\n}\n\nconst factory = new IsObjectFactory<Module>()\n\nexport const isModuleObject = factory.create(requiredModuleShape)\n","import { AnyObject, EmptyObject, TypeCheck } from '@xylabs/object'\n\nimport { asModuleObject } from './asModuleObject'\nimport { isModuleObject } from './isModuleObject'\nimport { Module } from './Module'\n\nexport type ModuleTypeCheck<T extends Module = Module> = TypeCheck<T>\n\nexport class IsModuleFactory<T extends Module = Module> {\n create(expectedQueries?: string[], additionalChecks?: TypeCheck<AnyObject | EmptyObject>[]): ModuleTypeCheck<T> {\n return (obj: unknown, config): obj is T => {\n const module = asModuleObject(obj)\n const result =\n isModuleObject(module, config) &&\n (expectedQueries?.reduce((prev, query) => prev && module.queries.includes(query), true) ?? true) &&\n //perform additional checks\n (additionalChecks?.reduce((prev, check) => prev && check(obj, config), true) ?? true)\n return result\n }\n }\n}\n","import { TypeCheck } from '@xylabs/object'\n\nimport { ModuleDiscoverQuerySchema } from '../Queries'\nimport { IsModuleFactory } from './IsModuleFactory'\nimport { isModuleObject } from './isModuleObject'\nimport { Module } from './Module'\n\nexport const requiredModuleQueries: string[] = [\n /* We need to update this once live module conform */\n //ModuleDescribeQuerySchema,\n //ModuleAddressQuerySchema,\n ModuleDiscoverQuerySchema,\n //ModuleManifestQuerySchema,\n //ModuleSubscribeQuerySchema,\n]\n\n//we do not use IsInstanceFactory here to prevent a cycle\nconst factory = new IsModuleFactory<Module>()\n\nexport const isModule: TypeCheck<Module> = factory.create(requiredModuleQueries, [isModuleObject])\n","import { Address } from '@xylabs/hex'\nimport { IsObjectFactory, TypeCheck } from '@xylabs/object'\nimport { Promisable } from '@xylabs/promise'\n\nimport { ModuleEventData } from '../EventsModels'\nimport { Module, ModuleQueryFunctions } from '../module'\nimport { ModuleParams } from '../ModuleParams'\n\nexport type ModulePipeLine = Lowercase<'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many'>\n\nexport type ModuleName = string //Capitalize<string>\n\nexport type ModuleIdentifier = Address | ModuleName\n\nexport type ModuleIdentifierPart = Lowercase<string>\n\nexport type ReservedModuleIdentifierCharacter = ':'\nexport const ReservedModuleIdentifierCharacters = new Set<ReservedModuleIdentifierCharacter>([':'])\n\nexport const isReservedModuleIdentifierCharacter = (value: unknown): value is ReservedModuleIdentifierCharacter => {\n return typeof value === 'string' && value.length === 1 && ReservedModuleIdentifierCharacters.has(value as ReservedModuleIdentifierCharacter)\n}\n\nexport const isModuleIdentifierPart = (value: unknown, falseAction: 'throw' | 'none' = 'none'): value is ModuleIdentifierPart => {\n const result = typeof value === 'string' && ![...value].some(isReservedModuleIdentifierCharacter)\n switch (falseAction) {\n case 'throw': {\n throw new Error(`Invalid ModuleIdentifierPart: ${value}`)\n }\n default: {\n return result\n }\n }\n}\n\nexport const isModuleResolver = (value?: unknown): value is ModuleResolver => {\n return typeof (value as Partial<ModuleResolver>).resolve === 'function'\n}\n\nexport interface ModuleResolver {\n resolve<T extends ModuleInstance = ModuleInstance>(filter?: ModuleFilter<T>, options?: ModuleFilterOptions<T>): Promisable<T[]>\n resolve<T extends ModuleInstance = ModuleInstance>(nameOrAddress: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promisable<T | undefined>\n resolve<T extends ModuleInstance = ModuleInstance>(\n nameOrAddressOrFilter?: ModuleFilter<T> | ModuleIdentifier,\n options?: ModuleFilterOptions<T>,\n ): Promisable<T | T[] | undefined>\n}\n\nexport interface ModuleResolverInstance extends ModuleResolver {\n addResolver: (resolver: ModuleResolverInstance) => this\n removeResolver: (resolver: ModuleResolverInstance) => this\n}\n\nexport interface ModuleInstance<TParams extends ModuleParams = ModuleParams, TEventData extends ModuleEventData = ModuleEventData>\n extends Module<TParams, TEventData>,\n ModuleResolver,\n ModuleQueryFunctions {\n /* The resolver is a 'down' resolver. It can resolve the module or any children (if it is a node for example), that are in the module*/\n readonly downResolver: Omit<ModuleResolverInstance, 'resolve'>\n\n readonly pipeline?: ModulePipeLine\n\n /* The resolver is a 'up' resolver. It can resolve the parent or any children of the parent*/\n /* This is set by a NodeModule when attaching to the module */\n readonly upResolver: Omit<ModuleResolverInstance, 'resolve'>\n}\n\nexport type InstanceTypeCheck<T extends ModuleInstance = ModuleInstance> = TypeCheck<T>\n\nexport class IsInstanceFactory<T extends ModuleInstance = ModuleInstance> extends IsObjectFactory<T> {}\n\nexport type Direction = 'up' | 'down' | 'all'\nexport type Visibility = 'public' | 'private' | 'all'\n\nexport interface ModuleFilterOptions<T extends ModuleInstance = ModuleInstance> {\n direction?: Direction\n identity?: InstanceTypeCheck<T>\n maxDepth?: number\n visibility?: Visibility\n}\n\nexport interface AddressModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n address: Address[]\n}\n\nexport const isAddressModuleFilter = (value: unknown): value is AddressModuleFilter => (value as AddressModuleFilter).address !== undefined\n\nexport interface NameModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n name: string[]\n}\n\nexport const isNameModuleFilter = (value: unknown): value is NameModuleFilter => (value as NameModuleFilter).name !== undefined\n\nexport interface QueryModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n query: string[][]\n}\n\nexport const isQueryModuleFilter = (value: unknown): value is QueryModuleFilter => (value as QueryModuleFilter).query !== undefined\n\nexport type AnyModuleFilter<T extends ModuleInstance = ModuleInstance> = Partial<AddressModuleFilter<T>> &\n Partial<NameModuleFilter<T>> &\n Partial<QueryModuleFilter<T>>\n\nexport type ModuleFilter<T extends ModuleInstance = ModuleInstance> =\n | ModuleFilterOptions<T>\n | AddressModuleFilter<T>\n | NameModuleFilter<T>\n | QueryModuleFilter<T>\n","import { Module } from '../module'\n\n/**\n * Used to filter duplicates from an array of modules\n * @example: modulesArray.filter(duplicateModules)\n * @param value Current Module\n * @param index Current Module's index\n * @param array Module Array\n * @returns True if the Module's address is the first occurrence of\n * that address in the array, false otherwise\n */\nexport const duplicateModules = (value: Module, index: number, array: Module[]): value is Module => {\n return array.findIndex((v) => v.address === value.address) === index\n}\n","// Inspired by https://stackoverflow.com/a/49079549/2803259\n\nimport { every, isArray, isBoolean, isNull, isNumber, isPlainObject, isString, isUndefined, overSome } from '@xylabs/lodash'\n\nconst JSONPrimitiveChecks = [isUndefined, isNull, isBoolean, isNumber, isString]\nconst JSONComplexChecks = [isPlainObject, isArray]\n\nexport const serializable = (field: unknown, depth?: number): boolean | null => {\n let depthExceeded = false\n const decrementDepth = () => (depth ? depth-- : undefined)\n\n const recursiveSerializable = (field: unknown) => {\n if (depth !== undefined && depth < 1) {\n depthExceeded = true\n return false\n }\n\n // decrement during every recursion\n decrementDepth()\n\n const nestedSerializable = (field: unknown): boolean => overSome(JSONComplexChecks)(field) && every(field as object, recursiveSerializable)\n\n return overSome([...JSONPrimitiveChecks, nestedSerializable])(field)\n }\n\n const valid = recursiveSerializable(field)\n\n return depthExceeded ? null : valid\n}\n\nexport const serializableField = (field: unknown) => {\n return overSome([...JSONPrimitiveChecks, ...JSONComplexChecks])(field)\n}\n","import { isPayloadOfSchemaType, Payload, WithMeta } from '@xyo-network/payload-model'\n\nexport interface StateDictionary {\n [key: string]: string | number | undefined\n}\nexport interface State<T extends StateDictionary = StateDictionary> {\n state: T\n}\n\nexport const ModuleStateSchema = 'network.xyo.module.state' as const\nexport type ModuleStateSchema = typeof ModuleStateSchema\n\nexport type ModuleState<T extends StateDictionary = StateDictionary> = Payload<State<T>, ModuleStateSchema>\n\nexport const isModuleState = <T extends StateDictionary = StateDictionary>(payload?: Payload | null): payload is ModuleState<T> => {\n return isPayloadOfSchemaType<ModuleState<T>>(ModuleStateSchema)(payload)\n}\n\nexport const isModuleStateWithMeta = <T extends StateDictionary = StateDictionary>(payload?: Payload | null): payload is WithMeta<ModuleState<T>> => {\n return isPayloadOfSchemaType<WithMeta<ModuleState<T>>>(ModuleStateSchema)(payload)\n}\n","import { TypeCheck } from '@xylabs/object'\n\nimport { isModuleInstance } from './instance'\nimport { isModule } from './module'\n\nexport const WithFactory = {\n create: <T extends object>(typeCheck: TypeCheck<T>) => {\n return <R>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n module: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n closure: (module: T) => R,\n ): R | undefined => {\n return typeCheck(module) ? closure(module) : undefined\n }\n },\n}\n\nexport const withModule = WithFactory.create(isModule)\nexport const withModuleInstance = WithFactory.create(isModuleInstance)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACSO,IAAMA,qBAAyC;;;ACgB/C,SAASC,kBAAAA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AAOF,QAAQA,UAAUG,QAAzB;AAEvB,QAAMC,wBAAwB,wBAACL,WAAAA;AAC7B,QAAIC,UAAUG,UAAaH,QAAQ,GAAG;AACpCC,sBAAgB;AAChB,aAAO;IACT;AAGAC,mBAAAA;AAEA,UAAMG,qBAAqB,wBAACN,eAA4BO,yBAASX,iBAAAA,EAAmBI,MAAAA,SAAUQ,sBAAMR,QAAiBK,qBAAAA,GAA1F;AAE3B,eAAOE,yBAAS;SAAIjB;MAAqBgB;KAAmB,EAAEN,MAAAA;EAChE,GAZ8B;AAc9B,QAAMS,QAAQJ,sBAAsBL,KAAAA;AAEpC,SAAOE,gBAAgB,OAAOO;AAChC,GArB4B;AAuBrB,IAAMC,oBAAoB,wBAACV,UAAAA;AAChC,aAAOO,yBAAS;OAAIjB;OAAwBM;GAAkB,EAAEI,KAAAA;AAClE,GAFiC;;;AC9BjC,2BAAyD;AASlD,IAAMW,oBAAoB;AAK1B,IAAMC,gBAAgB,wBAA8CC,YAAAA;AACzE,aAAOC,4CAAsCH,iBAAAA,EAAmBE,OAAAA;AAClE,GAF6B;AAItB,IAAME,wBAAwB,wBAA8CF,YAAAA;AACjF,aAAOC,4CAAgDH,iBAAAA,EAAmBE,OAAAA;AAC5E,GAFqC;;;ACb9B,IAAMG,cAAc;EACzBC,QAAQ,CAAmBC,cAAAA;AACzB,WAAO,CAELC,SAEAC,YAAAA;AAEA,aAAOF,UAAUC,OAAAA,IAAUC,QAAQD,OAAAA,IAAUE;IAC/C;EACF;AACF;AAEO,IAAMC,aAAaN,YAAYC,OAAOM,QAAAA;AACtC,IAAMC,qBAAqBR,YAAYC,OAAOQ,gBAAAA;","names":["ModuleConfigSchema","creatableModule","constructor","toCreatableModuleRegistry","dict","Object","entries","reduce","registry","schema","factory","Array","isArray","assignCreatableModuleRegistry","target","sources","map","source","factories","existingFactories","hasLabels","factory","labels","undefined","ModuleFactory","configSchemas","creatableModule","defaultLogger","defaultParams","labels","constructor","params","Object","assign","configSchema","withParams","_getRootFunction","funcName","anyThis","__proto__","_noOverride","functionName","thisFunc","rootFunc","assertEx","create","factory","schema","mergedParams","merge","config","_params","Error","import_assert","hasAllLabels","source","required","Object","entries","every","key","value","hasOwnProperty","ModuleFactoryLocator","constructor","_registry","registry","locate","schema","labels","assertEx","tryLocate","configString","labelsString","JSON","stringify","register","mod","configSchemas","map","existingFactories","factory","create","bind","Object","assign","registerMany","additional","entries","factories","filter","hasLabels","find","hasAllLabels","import_object","import_object","import_object","ModuleDescriptionSchema","ModuleDescribeQuerySchema","ModuleDiscoverQuerySchema","ModuleManifestQuerySchema","AddressPreviousHashSchema","AddressSchema","ModuleAddressQuerySchema","ModuleSubscribeQuerySchema","import_object","requiredModuleShape","address","config","params","queries","query","queryable","factory","IsObjectFactory","isModuleObject","create","asModuleObject","AsObjectFactory","create","isModuleObject","IsModuleFactory","create","expectedQueries","additionalChecks","obj","config","module","asModuleObject","result","isModuleObject","reduce","prev","query","queries","includes","check","requiredModuleQueries","ModuleDiscoverQuerySchema","factory","IsModuleFactory","isModule","create","isModuleObject","asModule","AsObjectFactory","create","isModule","requiredModuleInstanceFunctions","describe","discover","manifest","moduleAddress","factory","IsObjectFactory","isModuleInstance","create","isModule","asModuleInstance","AsObjectFactory","create","isModuleInstance","import_object","ReservedModuleIdentifierCharacters","Set","isReservedModuleIdentifierCharacter","value","length","has","isModuleIdentifierPart","falseAction","result","some","Error","isModuleResolver","resolve","IsInstanceFactory","IsObjectFactory","isAddressModuleFilter","address","undefined","isNameModuleFilter","name","isQueryModuleFilter","query","duplicateModules","value","index","array","findIndex","v","address","import_lodash","JSONPrimitiveChecks","isUndefined","isNull","isBoolean","isNumber","isString","JSONComplexChecks","isPlainObject","isArray","serializable","field","depth","depthExceeded","decrementDepth","undefined","recursiveSerializable","nestedSerializable","overSome","every","valid","serializableField","ModuleStateSchema","isModuleState","payload","isPayloadOfSchemaType","isModuleStateWithMeta","WithFactory","create","typeCheck","module","closure","undefined","withModule","isModule","withModuleInstance","isModuleInstance"]}
@@ -175,7 +175,10 @@ var _ModuleFactoryLocator = class _ModuleFactoryLocator {
175
175
  */
176
176
  tryLocate(schema, labels) {
177
177
  var _a, _b;
178
- return labels ? (_a = this._registry[schema]) == null ? void 0 : _a.filter(hasLabels).find((factory4) => hasAllLabels(factory4 == null ? void 0 : factory4.labels, labels)) : (_b = this._registry[schema]) == null ? void 0 : _b[0];
178
+ return labels ? (
179
+ // Find the first factory that has labels and has all the labels provided
180
+ (_a = this._registry[schema]) == null ? void 0 : _a.filter(hasLabels).find((factory4) => hasAllLabels(factory4 == null ? void 0 : factory4.labels, labels))
181
+ ) : (_b = this._registry[schema]) == null ? void 0 : _b[0];
179
182
  }
180
183
  };
181
184
  __name(_ModuleFactoryLocator, "ModuleFactoryLocator");
@@ -277,6 +280,25 @@ var asModuleInstance = AsObjectFactory3.create(isModuleInstance);
277
280
 
278
281
  // src/instance/ModuleInstance.ts
279
282
  import { IsObjectFactory as IsObjectFactory3 } from "@xylabs/object";
283
+ var ReservedModuleIdentifierCharacters = /* @__PURE__ */ new Set([
284
+ ":"
285
+ ]);
286
+ var isReservedModuleIdentifierCharacter = /* @__PURE__ */ __name((value) => {
287
+ return typeof value === "string" && value.length === 1 && ReservedModuleIdentifierCharacters.has(value);
288
+ }, "isReservedModuleIdentifierCharacter");
289
+ var isModuleIdentifierPart = /* @__PURE__ */ __name((value, falseAction = "none") => {
290
+ const result = typeof value === "string" && ![
291
+ ...value
292
+ ].some(isReservedModuleIdentifierCharacter);
293
+ switch (falseAction) {
294
+ case "throw": {
295
+ throw new Error(`Invalid ModuleIdentifierPart: ${value}`);
296
+ }
297
+ default: {
298
+ return result;
299
+ }
300
+ }
301
+ }, "isModuleIdentifierPart");
280
302
  var isModuleResolver = /* @__PURE__ */ __name((value) => {
281
303
  return typeof value.resolve === "function";
282
304
  }, "isModuleResolver");
@@ -284,6 +306,9 @@ var _IsInstanceFactory = class _IsInstanceFactory extends IsObjectFactory3 {
284
306
  };
285
307
  __name(_IsInstanceFactory, "IsInstanceFactory");
286
308
  var IsInstanceFactory = _IsInstanceFactory;
309
+ var isAddressModuleFilter = /* @__PURE__ */ __name((value) => value.address !== void 0, "isAddressModuleFilter");
310
+ var isNameModuleFilter = /* @__PURE__ */ __name((value) => value.name !== void 0, "isNameModuleFilter");
311
+ var isQueryModuleFilter = /* @__PURE__ */ __name((value) => value.query !== void 0, "isQueryModuleFilter");
287
312
 
288
313
  // src/lib/duplicateModules.ts
289
314
  var duplicateModules = /* @__PURE__ */ __name((value, index, array) => {
@@ -362,6 +387,7 @@ export {
362
387
  ModuleManifestQuerySchema,
363
388
  ModuleStateSchema,
364
389
  ModuleSubscribeQuerySchema,
390
+ ReservedModuleIdentifierCharacters,
365
391
  WithFactory,
366
392
  asModule,
367
393
  asModuleInstance,
@@ -371,12 +397,17 @@ export {
371
397
  duplicateModules,
372
398
  hasAllLabels,
373
399
  hasLabels,
400
+ isAddressModuleFilter,
374
401
  isModule,
402
+ isModuleIdentifierPart,
375
403
  isModuleInstance,
376
404
  isModuleObject,
377
405
  isModuleResolver,
378
406
  isModuleState,
379
407
  isModuleStateWithMeta,
408
+ isNameModuleFilter,
409
+ isQueryModuleFilter,
410
+ isReservedModuleIdentifierCharacter,
380
411
  requiredModuleInstanceFunctions,
381
412
  requiredModuleQueries,
382
413
  requiredModuleShape,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Config.ts","../../src/CreatableModule/CreatableModule.ts","../../src/CreatableModule/CreatableModuleRegistry.ts","../../src/CreatableModule/LabeledCreatableModuleFactory.ts","../../src/CreatableModule/ModuleFactory.ts","../../src/CreatableModule/ModuleFactoryLocator.ts","../../src/Labels/Labels.ts","../../src/instance/asModuleInstance.ts","../../src/instance/isModuleInstance.ts","../../src/module/asModule.ts","../../src/Queries/Describe/Payload.ts","../../src/Queries/Describe/Query.ts","../../src/Queries/Discover.ts","../../src/Queries/Manifest.ts","../../src/Queries/ModuleAddress/Payload.ts","../../src/Queries/ModuleAddress/Query.ts","../../src/Queries/Subscribe.ts","../../src/module/asModuleObject.ts","../../src/module/isModuleObject.ts","../../src/module/IsModuleFactory.ts","../../src/module/isModule.ts","../../src/instance/ModuleInstance.ts","../../src/lib/duplicateModules.ts","../../src/lib/serializable.ts","../../src/Payload/ModuleState.ts","../../src/withModule.ts"],"sourcesContent":["import { Address } from '@xylabs/hex'\nimport { EmptyObject, WithAdditional } from '@xylabs/object'\nimport { RetryConfig } from '@xylabs/retry'\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 CosigningAddressSet = string[]\nexport type SchemaString = string\nexport type ModuleName = string\nexport type NameOrAddress = Address | ModuleName\n\nexport interface ArchivingModuleConfig {\n readonly archiving?: {\n readonly archivists?: NameOrAddress[]\n }\n}\n\nexport type ModuleConfig<TConfig extends EmptyObject | Payload | void = void, TSchema extends Schema | void = void> = Payload<\n WithAdditional<\n {\n /** @field The name/address of the Archivist to use for this module */\n readonly archivist?: NameOrAddress\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 readonly retry?: RetryConfig\n\n schema: TConfig extends Payload ? TConfig['schema'] : ModuleConfigSchema\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, (Address | CosigningAddressSet)[]>\n\n /** @field If schema in record, then anyone except these addresses can access query */\n readonly disallowed?: Record<SchemaString, Address[]>\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 } & ArchivingModuleConfig,\n TConfig\n >,\n TSchema\n>\n\nexport type AnyConfigSchema<TConfig extends Omit<ModuleConfig, 'schema'> & { schema: string } = Omit<ModuleConfig, 'schema'> & { schema: string }> =\n ModuleConfig<TConfig, string>\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","import { Logger } from '@xylabs/logger'\nimport { AccountInstance } from '@xyo-network/account-model'\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 // eslint-disable-next-line unicorn/no-array-reduce\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 '@xylabs/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?: Partial<TModule['params']['config']> }\n\n labels?: Labels\n\n constructor(\n creatableModule: CreatableModule<TModule>,\n params?: Omit<TModule['params'], 'config'> & { config?: Partial<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","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModuleInstance } from './isModuleInstance'\n\nexport const asModuleInstance = AsObjectFactory.create(isModuleInstance)\n","import { IsObjectFactory, ObjectTypeShape, TypeCheck } from '@xylabs/object'\n\nimport { isModule } from '../module'\nimport { ModuleInstance } from './ModuleInstance'\n\nexport const requiredModuleInstanceFunctions: ObjectTypeShape = {\n describe: 'function',\n discover: 'function',\n manifest: 'function',\n moduleAddress: 'function',\n}\n\n//we do not use IsInstanceFactory here to prevent a cycle\nconst factory = new IsObjectFactory<ModuleInstance>()\n\nexport const isModuleInstance: TypeCheck<ModuleInstance> = factory.create(requiredModuleInstanceFunctions, [isModule])\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModule } from './isModule'\n\nexport const asModule = AsObjectFactory.create(isModule)\n","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","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 maxDepth?: number\n schema: ModuleDiscoverQuerySchema\n}>\n","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 maxDepth?: number\n schema: ModuleManifestQuerySchema\n}>\n","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","import { Query } from '@xyo-network/payload-model'\n\nexport type ModuleSubscribeQuerySchema = 'network.xyo.query.module.subscribe'\nexport const ModuleSubscribeQuerySchema: ModuleSubscribeQuerySchema = 'network.xyo.query.module.subscribe'\n\nexport interface ModuleSubscribeFilter {\n /** @field if specified, at least one of the schemas must be present in the boundwtness to generate a notification */\n schema?: string[]\n}\n\n//requests notification when a boundwitness is added to the modules chain that meets the filter criteria\nexport type ModuleSubscribeQuery = Query<{\n /** @field The address that will receive notifications */\n address: string\n /** @field A subscribe with a null for filter is an unsubscribe */\n filter?: ModuleSubscribeFilter | null\n /** @field The maximum events queued per send [may increase frequency] */\n maxQueue?: number\n schema: ModuleSubscribeQuerySchema\n}>\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModuleObject } from './isModuleObject'\n\nexport const asModuleObject = AsObjectFactory.create(isModuleObject)\n","import { IsObjectFactory, ObjectTypeShape } from '@xylabs/object'\n\nimport { Module } from './Module'\n\nexport const requiredModuleShape: ObjectTypeShape = {\n address: 'string',\n config: 'object',\n params: 'object',\n queries: 'array',\n query: 'function',\n queryable: 'function',\n}\n\nconst factory = new IsObjectFactory<Module>()\n\nexport const isModuleObject = factory.create(requiredModuleShape)\n","import { AnyObject, EmptyObject, TypeCheck } from '@xylabs/object'\n\nimport { asModuleObject } from './asModuleObject'\nimport { isModuleObject } from './isModuleObject'\nimport { Module } from './Module'\n\nexport type ModuleTypeCheck<T extends Module = Module> = TypeCheck<T>\n\nexport class IsModuleFactory<T extends Module = Module> {\n create(expectedQueries?: string[], additionalChecks?: TypeCheck<AnyObject | EmptyObject>[]): ModuleTypeCheck<T> {\n return (obj: unknown, config): obj is T => {\n const module = asModuleObject(obj)\n const result =\n isModuleObject(module, config) &&\n (expectedQueries?.reduce((prev, query) => prev && module.queries.includes(query), true) ?? true) &&\n //perform additional checks\n (additionalChecks?.reduce((prev, check) => prev && check(obj, config), true) ?? true)\n return result\n }\n }\n}\n","import { TypeCheck } from '@xylabs/object'\n\nimport { ModuleDiscoverQuerySchema } from '../Queries'\nimport { IsModuleFactory } from './IsModuleFactory'\nimport { isModuleObject } from './isModuleObject'\nimport { Module } from './Module'\n\nexport const requiredModuleQueries: string[] = [\n /* We need to update this once live module conform */\n //ModuleDescribeQuerySchema,\n //ModuleAddressQuerySchema,\n ModuleDiscoverQuerySchema,\n //ModuleManifestQuerySchema,\n //ModuleSubscribeQuerySchema,\n]\n\n//we do not use IsInstanceFactory here to prevent a cycle\nconst factory = new IsModuleFactory<Module>()\n\nexport const isModule: TypeCheck<Module> = factory.create(requiredModuleQueries, [isModuleObject])\n","import { IsObjectFactory, TypeCheck } from '@xylabs/object'\nimport { Promisable } from '@xylabs/promise'\n\nimport { ModuleEventData } from '../EventsModels'\nimport { Module, ModuleQueryFunctions } from '../module'\nimport { ModuleParams } from '../ModuleParams'\n\nexport type ModulePipeLine = 'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many'\n\nexport const isModuleResolver = (value?: unknown): value is ModuleResolver => {\n return typeof (value as Partial<ModuleResolver>).resolve === 'function'\n}\n\nexport interface ModuleResolver {\n resolve<T extends ModuleInstance = ModuleInstance>(filter?: ModuleFilter<T>, options?: ModuleFilterOptions<T>): Promisable<T[]>\n resolve<T extends ModuleInstance = ModuleInstance>(nameOrAddress: string, options?: ModuleFilterOptions<T>): Promisable<T | undefined>\n resolve<T extends ModuleInstance = ModuleInstance>(\n nameOrAddressOrFilter?: ModuleFilter<T> | string,\n options?: ModuleFilterOptions<T>,\n ): Promisable<T | T[] | undefined>\n}\n\nexport interface ModuleResolverInstance extends ModuleResolver {\n addResolver: (resolver: ModuleResolverInstance) => this\n removeResolver: (resolver: ModuleResolverInstance) => this\n}\n\nexport interface ModuleInstance<TParams extends ModuleParams = ModuleParams, TEventData extends ModuleEventData = ModuleEventData>\n extends Module<TParams, TEventData>,\n ModuleResolver,\n ModuleQueryFunctions {\n /* The resolver is a 'down' resolver. It can resolve the module or any children (if it is a node for example), that are in the module*/\n readonly downResolver: Omit<ModuleResolverInstance, 'resolve'>\n\n readonly pipeline?: ModulePipeLine\n\n /* The resolver is a 'up' resolver. It can resolve the parent or any children of the parent*/\n /* This is set by a NodeModule when attaching to the module */\n readonly upResolver: Omit<ModuleResolverInstance, 'resolve'>\n}\n\nexport type InstanceTypeCheck<T extends ModuleInstance = ModuleInstance> = TypeCheck<T>\n\nexport class IsInstanceFactory<T extends ModuleInstance = ModuleInstance> extends IsObjectFactory<T> {}\n\nexport interface ModuleFilterOptions<T extends ModuleInstance = ModuleInstance> {\n direction?: 'up' | 'down' | 'all'\n identity?: InstanceTypeCheck<T>\n maxDepth?: number\n visibility?: 'public' | 'private' | 'all'\n}\n\nexport interface AddressModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n address: string[]\n}\n\nexport interface NameModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n name: string[]\n}\n\nexport interface QueryModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n query: string[][]\n}\n\nexport type AnyModuleFilter<T extends ModuleInstance = ModuleInstance> = Partial<AddressModuleFilter<T>> &\n Partial<NameModuleFilter<T>> &\n Partial<QueryModuleFilter<T>>\n\nexport type ModuleFilter<T extends ModuleInstance = ModuleInstance> =\n | ModuleFilterOptions<T>\n | AddressModuleFilter<T>\n | NameModuleFilter<T>\n | QueryModuleFilter<T>\n","import { Module } from '../module'\n\n/**\n * Used to filter duplicates from an array of modules\n * @example: modulesArray.filter(duplicateModules)\n * @param value Current Module\n * @param index Current Module's index\n * @param array Module Array\n * @returns True if the Module's address is the first occurrence of\n * that address in the array, false otherwise\n */\nexport const duplicateModules = (value: Module, index: number, array: Module[]): value is Module => {\n return array.findIndex((v) => v.address === value.address) === index\n}\n","// Inspired by https://stackoverflow.com/a/49079549/2803259\n\nimport { every, isArray, isBoolean, isNull, isNumber, isPlainObject, isString, isUndefined, overSome } from '@xylabs/lodash'\n\nconst JSONPrimitiveChecks = [isUndefined, isNull, isBoolean, isNumber, isString]\nconst JSONComplexChecks = [isPlainObject, isArray]\n\nexport const serializable = (field: unknown, depth?: number): boolean | null => {\n let depthExceeded = false\n const decrementDepth = () => (depth ? depth-- : undefined)\n\n const recursiveSerializable = (field: unknown) => {\n if (depth !== undefined && depth < 1) {\n depthExceeded = true\n return false\n }\n\n // decrement during every recursion\n decrementDepth()\n\n const nestedSerializable = (field: unknown): boolean => overSome(JSONComplexChecks)(field) && every(field as object, recursiveSerializable)\n\n return overSome([...JSONPrimitiveChecks, nestedSerializable])(field)\n }\n\n const valid = recursiveSerializable(field)\n\n return depthExceeded ? null : valid\n}\n\nexport const serializableField = (field: unknown) => {\n return overSome([...JSONPrimitiveChecks, ...JSONComplexChecks])(field)\n}\n","import { isPayloadOfSchemaType, Payload, WithMeta } from '@xyo-network/payload-model'\n\nexport interface StateDictionary {\n [key: string]: string | number | undefined\n}\nexport interface State<T extends StateDictionary = StateDictionary> {\n state: T\n}\n\nexport const ModuleStateSchema = 'network.xyo.module.state' as const\nexport type ModuleStateSchema = typeof ModuleStateSchema\n\nexport type ModuleState<T extends StateDictionary = StateDictionary> = Payload<State<T>, ModuleStateSchema>\n\nexport const isModuleState = <T extends StateDictionary = StateDictionary>(payload?: Payload | null): payload is ModuleState<T> => {\n return isPayloadOfSchemaType<ModuleState<T>>(ModuleStateSchema)(payload)\n}\n\nexport const isModuleStateWithMeta = <T extends StateDictionary = StateDictionary>(payload?: Payload | null): payload is WithMeta<ModuleState<T>> => {\n return isPayloadOfSchemaType<WithMeta<ModuleState<T>>>(ModuleStateSchema)(payload)\n}\n","import { TypeCheck } from '@xylabs/object'\n\nimport { isModuleInstance } from './instance'\nimport { isModule } from './module'\n\nexport const WithFactory = {\n create: <T extends object>(typeCheck: TypeCheck<T>) => {\n return <R>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n module: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n closure: (module: T) => R,\n ): R | undefined => {\n return typeCheck(module) ? closure(module) : undefined\n }\n },\n}\n\nexport const withModule = WithFactory.create(isModule)\nexport const withModuleInstance = WithFactory.create(isModuleInstance)\n"],"mappings":";;;;AAQO,IAAMA,qBAAyC;;;ACiB/C,SAASC,kBAAAA;AACd,SAAO,CAAqCC,gBAAAA;AAC1CA;EACF;AACF;AAJgBD;;;ACjBT,IAAME,4BAA4B,wBAACC,SAAAA;AAExC,SAAOC,OAAOC,QA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E,OAAAA;AAClE,GAF6B;AAItB,IAAME,wBAAwB,wBAA8CF,YAAAA;AACjF,SAAOC,sBAAgDH,iBAAAA,EAAmBE,OAAAA;AAC5E,GAFqC;;;ACb9B,IAAMG,cAAc;EACzBC,QAAQ,CAAmBC,cAAAA;AACzB,WAAO,CAELC,QAEAC,YAAAA;AAEA,aAAOF,UAAUC,MAAAA,IAAUC,QAAQD,MAAAA,IAAUE;IAC/C;EACF;AACF;AAEO,IAAMC,aAAaN,YAAYC,OAAOM,QAAAA;AACtC,IAAMC,qBAAqBR,YAAYC,OAAOQ,gBAAAA;","names":["ModuleConfigSchema","creatableModule","constructor","toCreatableModuleRegistry","dict","Object","entries","reduce","registry","schema","factory","Array","isArray","assignCreatableModuleRegistry","target","sources","map","source","factories","existingFactories","hasLabels","factory","labels","undefined","assertEx","merge","ModuleFactory","configSchemas","creatableModule","defaultLogger","defaultParams","labels","constructor","params","Object","assign","configSchema","withParams","_getRootFunction","funcName","anyThis","__proto__","_noOverride","functionName","thisFunc","rootFunc","assertEx","create","factory","schema","mergedParams","merge","config","_params","Error","assertEx","hasAllLabels","source","required","Object","entries","every","key","value","hasOwnProperty","ModuleFactoryLocator","constructor","_registry","registry","locate","schema","labels","assertEx","tryLocate","configString","labelsString","JSON","stringify","register","mod","configSchemas","map","existingFactories","factory","create","bind","Object","assign","registerMany","additional","entries","factories","filter","hasLabels","find","hasAllLabels","AsObjectFactory","IsObjectFactory","AsObjectFactory","ModuleDescriptionSchema","ModuleDescribeQuerySchema","ModuleDiscoverQuerySchema","ModuleManifestQuerySchema","AddressSchema","AddressPreviousHashSchema","ModuleAddressQuerySchema","ModuleSubscribeQuerySchema","AsObjectFactory","IsObjectFactory","requiredModuleShape","address","config","params","queries","query","queryable","factory","isModuleObject","create","asModuleObject","AsObjectFactory","create","isModuleObject","IsModuleFactory","create","expectedQueries","additionalChecks","obj","config","module","asModuleObject","result","isModuleObject","reduce","prev","query","queries","includes","check","requiredModuleQueries","ModuleDiscoverQuerySchema","factory","IsModuleFactory","isModule","create","isModuleObject","asModule","AsObjectFactory","create","isModule","requiredModuleInstanceFunctions","describe","discover","manifest","moduleAddress","factory","IsObjectFactory","isModuleInstance","create","isModule","asModuleInstance","AsObjectFactory","create","isModuleInstance","IsObjectFactory","isModuleResolver","value","resolve","IsInstanceFactory","IsObjectFactory","duplicateModules","value","index","array","findIndex","v","address","every","isArray","isBoolean","isNull","isNumber","isPlainObject","isString","isUndefined","overSome","JSONPrimitiveChecks","isUndefined","isNull","isBoolean","isNumber","isString","JSONComplexChecks","isPlainObject","isArray","serializable","field","depth","depthExceeded","decrementDepth","undefined","recursiveSerializable","nestedSerializable","overSome","every","valid","serializableField","isPayloadOfSchemaType","ModuleStateSchema","isModuleState","payload","isPayloadOfSchemaType","isModuleStateWithMeta","WithFactory","create","typeCheck","module","closure","undefined","withModule","isModule","withModuleInstance","isModuleInstance"]}
1
+ {"version":3,"sources":["../../src/Config.ts","../../src/CreatableModule/CreatableModule.ts","../../src/CreatableModule/CreatableModuleRegistry.ts","../../src/CreatableModule/LabeledCreatableModuleFactory.ts","../../src/CreatableModule/ModuleFactory.ts","../../src/CreatableModule/ModuleFactoryLocator.ts","../../src/Labels/Labels.ts","../../src/instance/asModuleInstance.ts","../../src/instance/isModuleInstance.ts","../../src/module/asModule.ts","../../src/Queries/Describe/Payload.ts","../../src/Queries/Describe/Query.ts","../../src/Queries/Discover.ts","../../src/Queries/Manifest.ts","../../src/Queries/ModuleAddress/Payload.ts","../../src/Queries/ModuleAddress/Query.ts","../../src/Queries/Subscribe.ts","../../src/module/asModuleObject.ts","../../src/module/isModuleObject.ts","../../src/module/IsModuleFactory.ts","../../src/module/isModule.ts","../../src/instance/ModuleInstance.ts","../../src/lib/duplicateModules.ts","../../src/lib/serializable.ts","../../src/Payload/ModuleState.ts","../../src/withModule.ts"],"sourcesContent":["import { Address } from '@xylabs/hex'\nimport { EmptyObject, WithAdditional } from '@xylabs/object'\nimport { RetryConfig } from '@xylabs/retry'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\nimport { ModuleIdentifier, ModuleName } from './instance'\nimport { Labels } from './Labels'\n\nexport type ModuleConfigSchema = 'network.xyo.module.config'\nexport const ModuleConfigSchema: ModuleConfigSchema = 'network.xyo.module.config'\n\nexport type CosigningAddressSet = string[]\nexport type SchemaString = string\nexport type NameOrAddress = Address | ModuleName\n\nexport interface ArchivingModuleConfig {\n readonly archiving?: {\n readonly archivists?: ModuleIdentifier[]\n }\n}\n\nexport type ModuleConfig<TConfig extends EmptyObject | Payload | void = void, TSchema extends Schema | void = void> = Payload<\n WithAdditional<\n {\n /** @field The name/address of the Archivist to use for this module */\n readonly archivist?: ModuleIdentifier\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?: ModuleName\n\n /** @field paging settings for queries */\n readonly paging?: Record<string, { size?: number }>\n\n readonly retry?: RetryConfig\n\n schema: TConfig extends Payload ? TConfig['schema'] : ModuleConfigSchema\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, (Address | CosigningAddressSet)[]>\n\n /** @field If schema in record, then anyone except these addresses can access query */\n readonly disallowed?: Record<SchemaString, Address[]>\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 } & ArchivingModuleConfig,\n TConfig\n >,\n TSchema\n>\n\nexport type AnyConfigSchema<TConfig extends Omit<ModuleConfig, 'schema'> & { schema: string } = Omit<ModuleConfig, 'schema'> & { schema: string }> =\n ModuleConfig<TConfig, string>\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","import { Logger } from '@xylabs/logger'\nimport { AccountInstance } from '@xyo-network/account-model'\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 // eslint-disable-next-line unicorn/no-array-reduce\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 '@xylabs/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?: Partial<TModule['params']['config']> }\n\n labels?: Labels\n\n constructor(\n creatableModule: CreatableModule<TModule>,\n params?: Omit<TModule['params'], 'config'> & { config?: Partial<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","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModuleInstance } from './isModuleInstance'\n\nexport const asModuleInstance = AsObjectFactory.create(isModuleInstance)\n","import { IsObjectFactory, ObjectTypeShape, TypeCheck } from '@xylabs/object'\n\nimport { isModule } from '../module'\nimport { ModuleInstance } from './ModuleInstance'\n\nexport const requiredModuleInstanceFunctions: ObjectTypeShape = {\n describe: 'function',\n discover: 'function',\n manifest: 'function',\n moduleAddress: 'function',\n}\n\n//we do not use IsInstanceFactory here to prevent a cycle\nconst factory = new IsObjectFactory<ModuleInstance>()\n\nexport const isModuleInstance: TypeCheck<ModuleInstance> = factory.create(requiredModuleInstanceFunctions, [isModule])\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModule } from './isModule'\n\nexport const asModule = AsObjectFactory.create(isModule)\n","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","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 maxDepth?: number\n schema: ModuleDiscoverQuerySchema\n}>\n","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 maxDepth?: number\n schema: ModuleManifestQuerySchema\n}>\n","import { Address } from '@xylabs/hex'\nimport { 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: Address\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","import { Address } from '@xylabs/hex'\nimport { Query } from '@xyo-network/payload-model'\n\nexport type ModuleSubscribeQuerySchema = 'network.xyo.query.module.subscribe'\nexport const ModuleSubscribeQuerySchema: ModuleSubscribeQuerySchema = 'network.xyo.query.module.subscribe'\n\nexport interface ModuleSubscribeFilter {\n /** @field if specified, at least one of the schemas must be present in the boundwtness to generate a notification */\n schema?: string[]\n}\n\n//requests notification when a boundwitness is added to the modules chain that meets the filter criteria\nexport type ModuleSubscribeQuery = Query<{\n /** @field The address that will receive notifications */\n address: Address\n /** @field A subscribe with a null for filter is an unsubscribe */\n filter?: ModuleSubscribeFilter | null\n /** @field The maximum events queued per send [may increase frequency] */\n maxQueue?: number\n schema: ModuleSubscribeQuerySchema\n}>\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport { isModuleObject } from './isModuleObject'\n\nexport const asModuleObject = AsObjectFactory.create(isModuleObject)\n","import { IsObjectFactory, ObjectTypeShape } from '@xylabs/object'\n\nimport { Module } from './Module'\n\nexport const requiredModuleShape: ObjectTypeShape = {\n address: 'string',\n config: 'object',\n params: 'object',\n queries: 'array',\n query: 'function',\n queryable: 'function',\n}\n\nconst factory = new IsObjectFactory<Module>()\n\nexport const isModuleObject = factory.create(requiredModuleShape)\n","import { AnyObject, EmptyObject, TypeCheck } from '@xylabs/object'\n\nimport { asModuleObject } from './asModuleObject'\nimport { isModuleObject } from './isModuleObject'\nimport { Module } from './Module'\n\nexport type ModuleTypeCheck<T extends Module = Module> = TypeCheck<T>\n\nexport class IsModuleFactory<T extends Module = Module> {\n create(expectedQueries?: string[], additionalChecks?: TypeCheck<AnyObject | EmptyObject>[]): ModuleTypeCheck<T> {\n return (obj: unknown, config): obj is T => {\n const module = asModuleObject(obj)\n const result =\n isModuleObject(module, config) &&\n (expectedQueries?.reduce((prev, query) => prev && module.queries.includes(query), true) ?? true) &&\n //perform additional checks\n (additionalChecks?.reduce((prev, check) => prev && check(obj, config), true) ?? true)\n return result\n }\n }\n}\n","import { TypeCheck } from '@xylabs/object'\n\nimport { ModuleDiscoverQuerySchema } from '../Queries'\nimport { IsModuleFactory } from './IsModuleFactory'\nimport { isModuleObject } from './isModuleObject'\nimport { Module } from './Module'\n\nexport const requiredModuleQueries: string[] = [\n /* We need to update this once live module conform */\n //ModuleDescribeQuerySchema,\n //ModuleAddressQuerySchema,\n ModuleDiscoverQuerySchema,\n //ModuleManifestQuerySchema,\n //ModuleSubscribeQuerySchema,\n]\n\n//we do not use IsInstanceFactory here to prevent a cycle\nconst factory = new IsModuleFactory<Module>()\n\nexport const isModule: TypeCheck<Module> = factory.create(requiredModuleQueries, [isModuleObject])\n","import { Address } from '@xylabs/hex'\nimport { IsObjectFactory, TypeCheck } from '@xylabs/object'\nimport { Promisable } from '@xylabs/promise'\n\nimport { ModuleEventData } from '../EventsModels'\nimport { Module, ModuleQueryFunctions } from '../module'\nimport { ModuleParams } from '../ModuleParams'\n\nexport type ModulePipeLine = Lowercase<'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many'>\n\nexport type ModuleName = string //Capitalize<string>\n\nexport type ModuleIdentifier = Address | ModuleName\n\nexport type ModuleIdentifierPart = Lowercase<string>\n\nexport type ReservedModuleIdentifierCharacter = ':'\nexport const ReservedModuleIdentifierCharacters = new Set<ReservedModuleIdentifierCharacter>([':'])\n\nexport const isReservedModuleIdentifierCharacter = (value: unknown): value is ReservedModuleIdentifierCharacter => {\n return typeof value === 'string' && value.length === 1 && ReservedModuleIdentifierCharacters.has(value as ReservedModuleIdentifierCharacter)\n}\n\nexport const isModuleIdentifierPart = (value: unknown, falseAction: 'throw' | 'none' = 'none'): value is ModuleIdentifierPart => {\n const result = typeof value === 'string' && ![...value].some(isReservedModuleIdentifierCharacter)\n switch (falseAction) {\n case 'throw': {\n throw new Error(`Invalid ModuleIdentifierPart: ${value}`)\n }\n default: {\n return result\n }\n }\n}\n\nexport const isModuleResolver = (value?: unknown): value is ModuleResolver => {\n return typeof (value as Partial<ModuleResolver>).resolve === 'function'\n}\n\nexport interface ModuleResolver {\n resolve<T extends ModuleInstance = ModuleInstance>(filter?: ModuleFilter<T>, options?: ModuleFilterOptions<T>): Promisable<T[]>\n resolve<T extends ModuleInstance = ModuleInstance>(nameOrAddress: ModuleIdentifier, options?: ModuleFilterOptions<T>): Promisable<T | undefined>\n resolve<T extends ModuleInstance = ModuleInstance>(\n nameOrAddressOrFilter?: ModuleFilter<T> | ModuleIdentifier,\n options?: ModuleFilterOptions<T>,\n ): Promisable<T | T[] | undefined>\n}\n\nexport interface ModuleResolverInstance extends ModuleResolver {\n addResolver: (resolver: ModuleResolverInstance) => this\n removeResolver: (resolver: ModuleResolverInstance) => this\n}\n\nexport interface ModuleInstance<TParams extends ModuleParams = ModuleParams, TEventData extends ModuleEventData = ModuleEventData>\n extends Module<TParams, TEventData>,\n ModuleResolver,\n ModuleQueryFunctions {\n /* The resolver is a 'down' resolver. It can resolve the module or any children (if it is a node for example), that are in the module*/\n readonly downResolver: Omit<ModuleResolverInstance, 'resolve'>\n\n readonly pipeline?: ModulePipeLine\n\n /* The resolver is a 'up' resolver. It can resolve the parent or any children of the parent*/\n /* This is set by a NodeModule when attaching to the module */\n readonly upResolver: Omit<ModuleResolverInstance, 'resolve'>\n}\n\nexport type InstanceTypeCheck<T extends ModuleInstance = ModuleInstance> = TypeCheck<T>\n\nexport class IsInstanceFactory<T extends ModuleInstance = ModuleInstance> extends IsObjectFactory<T> {}\n\nexport type Direction = 'up' | 'down' | 'all'\nexport type Visibility = 'public' | 'private' | 'all'\n\nexport interface ModuleFilterOptions<T extends ModuleInstance = ModuleInstance> {\n direction?: Direction\n identity?: InstanceTypeCheck<T>\n maxDepth?: number\n visibility?: Visibility\n}\n\nexport interface AddressModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n address: Address[]\n}\n\nexport const isAddressModuleFilter = (value: unknown): value is AddressModuleFilter => (value as AddressModuleFilter).address !== undefined\n\nexport interface NameModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n name: string[]\n}\n\nexport const isNameModuleFilter = (value: unknown): value is NameModuleFilter => (value as NameModuleFilter).name !== undefined\n\nexport interface QueryModuleFilter<T extends ModuleInstance = ModuleInstance> extends ModuleFilterOptions<T> {\n query: string[][]\n}\n\nexport const isQueryModuleFilter = (value: unknown): value is QueryModuleFilter => (value as QueryModuleFilter).query !== undefined\n\nexport type AnyModuleFilter<T extends ModuleInstance = ModuleInstance> = Partial<AddressModuleFilter<T>> &\n Partial<NameModuleFilter<T>> &\n Partial<QueryModuleFilter<T>>\n\nexport type ModuleFilter<T extends ModuleInstance = ModuleInstance> =\n | ModuleFilterOptions<T>\n | AddressModuleFilter<T>\n | NameModuleFilter<T>\n | QueryModuleFilter<T>\n","import { Module } from '../module'\n\n/**\n * Used to filter duplicates from an array of modules\n * @example: modulesArray.filter(duplicateModules)\n * @param value Current Module\n * @param index Current Module's index\n * @param array Module Array\n * @returns True if the Module's address is the first occurrence of\n * that address in the array, false otherwise\n */\nexport const duplicateModules = (value: Module, index: number, array: Module[]): value is Module => {\n return array.findIndex((v) => v.address === value.address) === index\n}\n","// Inspired by https://stackoverflow.com/a/49079549/2803259\n\nimport { every, isArray, isBoolean, isNull, isNumber, isPlainObject, isString, isUndefined, overSome } from '@xylabs/lodash'\n\nconst JSONPrimitiveChecks = [isUndefined, isNull, isBoolean, isNumber, isString]\nconst JSONComplexChecks = [isPlainObject, isArray]\n\nexport const serializable = (field: unknown, depth?: number): boolean | null => {\n let depthExceeded = false\n const decrementDepth = () => (depth ? depth-- : undefined)\n\n const recursiveSerializable = (field: unknown) => {\n if (depth !== undefined && depth < 1) {\n depthExceeded = true\n return false\n }\n\n // decrement during every recursion\n decrementDepth()\n\n const nestedSerializable = (field: unknown): boolean => overSome(JSONComplexChecks)(field) && every(field as object, recursiveSerializable)\n\n return overSome([...JSONPrimitiveChecks, nestedSerializable])(field)\n }\n\n const valid = recursiveSerializable(field)\n\n return depthExceeded ? null : valid\n}\n\nexport const serializableField = (field: unknown) => {\n return overSome([...JSONPrimitiveChecks, ...JSONComplexChecks])(field)\n}\n","import { isPayloadOfSchemaType, Payload, WithMeta } from '@xyo-network/payload-model'\n\nexport interface StateDictionary {\n [key: string]: string | number | undefined\n}\nexport interface State<T extends StateDictionary = StateDictionary> {\n state: T\n}\n\nexport const ModuleStateSchema = 'network.xyo.module.state' as const\nexport type ModuleStateSchema = typeof ModuleStateSchema\n\nexport type ModuleState<T extends StateDictionary = StateDictionary> = Payload<State<T>, ModuleStateSchema>\n\nexport const isModuleState = <T extends StateDictionary = StateDictionary>(payload?: Payload | null): payload is ModuleState<T> => {\n return isPayloadOfSchemaType<ModuleState<T>>(ModuleStateSchema)(payload)\n}\n\nexport const isModuleStateWithMeta = <T extends StateDictionary = StateDictionary>(payload?: Payload | null): payload is WithMeta<ModuleState<T>> => {\n return isPayloadOfSchemaType<WithMeta<ModuleState<T>>>(ModuleStateSchema)(payload)\n}\n","import { TypeCheck } from '@xylabs/object'\n\nimport { isModuleInstance } from './instance'\nimport { isModule } from './module'\n\nexport const WithFactory = {\n create: <T extends object>(typeCheck: TypeCheck<T>) => {\n return <R>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n module: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n closure: (module: T) => R,\n ): R | undefined => {\n return typeCheck(module) ? closure(module) : undefined\n }\n },\n}\n\nexport const withModule = WithFactory.create(isModule)\nexport const withModuleInstance = WithFactory.create(isModuleInstance)\n"],"mappings":";;;;AASO,IAAMA,qBAAyC;;;ACgB/C,SAASC,kBAAAA;AACd,SAAO,CAAqCC,gBAAAA;AAC1CA;EACF;AACF;AAJgBD;;;ACjBT,IAAME,4BAA4B,wBAACC,SAAAA;AAExC,SAAOC,OAAOC,QAAQF,IAAAA,EAAMG,OAAO,CAACC,UAAU,CAACC,QAAQC,QAAAA,MAAQ;AAC7DF,aAASC,MAAAA,IAAUE,MAAMC,QAAQF,QAAAA,IAAWA,WAAU;MAACA;;AACvD,WAAOF;EACT,GAAG,CAAC,CAAA;AACN,GANyC;AAQlC,IAAMK,gCAAgC,wBAC3CC,SAAkC,CAAC,MAChCC,YAAAA;AAEHA,UAAQC,IAAI,CAACC,WACXZ,OAAOC,QAAQW,MAAAA,EAAQD,IAAI,CAAC,CAACP,QAAQS,SAAAA,MAAU;AAC7C,QAAIA,WAAW;AACb,YAAMC,oBAAoBL,OAAOL,MAAAA;AACjCK,aAAOL,MAAAA,IAAUU,oBAAqBL,OAAOL,MAAAA,IAAU;WAAIU;WAAsBD;UAAcA;IACjG;EACF,CAAA,CAAA;AAEF,SAAOJ;AACT,GAb6C;;;ACVtC,IAAMM,YAAY,wBAACC,aAAAA;AACxB,SAAQA,SAA0CC,WAAWC;AAC/D,GAFyB;;;ACNzB,SAASC,gBAA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A,EAAmBE,OAAAA;AAClE,GAF6B;AAItB,IAAME,wBAAwB,wBAA8CF,YAAAA;AACjF,SAAOC,sBAAgDH,iBAAAA,EAAmBE,OAAAA;AAC5E,GAFqC;;;ACb9B,IAAMG,cAAc;EACzBC,QAAQ,CAAmBC,cAAAA;AACzB,WAAO,CAELC,QAEAC,YAAAA;AAEA,aAAOF,UAAUC,MAAAA,IAAUC,QAAQD,MAAAA,IAAUE;IAC/C;EACF;AACF;AAEO,IAAMC,aAAaN,YAAYC,OAAOM,QAAAA;AACtC,IAAMC,qBAAqBR,YAAYC,OAAOQ,gBAAAA;","names":["ModuleConfigSchema","creatableModule","constructor","toCreatableModuleRegistry","dict","Object","entries","reduce","registry","schema","factory","Array","isArray","assignCreatableModuleRegistry","target","sources","map","source","factories","existingFactories","hasLabels","factory","labels","undefined","assertEx","merge","ModuleFactory","configSchemas","creatableModule","defaultLogger","defaultParams","labels","constructor","params","Object","assign","configSchema","withParams","_getRootFunction","funcName","anyThis","__proto__","_noOverride","functionName","thisFunc","rootFunc","assertEx","create","factory","schema","mergedParams","merge","config","_params","Error","assertEx","hasAllLabels","source","required","Object","entries","every","key","value","hasOwnProperty","ModuleFactoryLocator","constructor","_registry","registry","locate","schema","labels","assertEx","tryLocate","configString","labelsString","JSON","stringify","register","mod","configSchemas","map","existingFactories","factory","create","bind","Object","assign","registerMany","additional","entries","factories","filter","hasLabels","find","hasAllLabels","AsObjectFactory","IsObjectFactory","AsObjectFactory","ModuleDescriptionSchema","ModuleDescribeQuerySchema","ModuleDiscoverQuerySchema","ModuleManifestQuerySchema","AddressSchema","AddressPreviousHashSchema","ModuleAddressQuerySchema","ModuleSubscribeQuerySchema","AsObjectFactory","IsObjectFactory","requiredModuleShape","address","config","params","queries","query","queryable","factory","isModuleObject","create","asModuleObject","AsObjectFactory","create","isModuleObject","IsModuleFactory","create","expectedQueries","additionalChecks","obj","config","module","asModuleObject","result","isModuleObject","reduce","prev","query","queries","includes","check","requiredModuleQueries","ModuleDiscoverQuerySchema","factory","IsModuleFactory","isModule","create","isModuleObject","asModule","AsObjectFactory","create","isModule","requiredModuleInstanceFunctions","describe","discover","manifest","moduleAddress","factory","IsObjectFactory","isModuleInstance","create","isModule","asModuleInstance","AsObjectFactory","create","isModuleInstance","IsObjectFactory","ReservedModuleIdentifierCharacters","Set","isReservedModuleIdentifierCharacter","value","length","has","isModuleIdentifierPart","falseAction","result","some","Error","isModuleResolver","resolve","IsInstanceFactory","IsObjectFactory","isAddressModuleFilter","address","undefined","isNameModuleFilter","name","isQueryModuleFilter","query","duplicateModules","value","index","array","findIndex","v","address","every","isArray","isBoolean","isNull","isNumber","isPlainObject","isString","isUndefined","overSome","JSONPrimitiveChecks","isUndefined","isNull","isBoolean","isNumber","isString","JSONComplexChecks","isPlainObject","isArray","serializable","field","depth","depthExceeded","decrementDepth","undefined","recursiveSerializable","nestedSerializable","overSome","every","valid","serializableField","isPayloadOfSchemaType","ModuleStateSchema","isModuleState","payload","isPayloadOfSchemaType","isModuleStateWithMeta","WithFactory","create","typeCheck","module","closure","undefined","withModule","isModule","withModuleInstance","isModuleInstance"]}