@xyo-network/module-model 5.3.20 → 5.3.24

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 (88) hide show
  1. package/dist/neutral/Payload/Address.d.ts +1 -1
  2. package/dist/neutral/Payload/Address.d.ts.map +1 -1
  3. package/dist/neutral/Payload/ModuleState.d.ts +1 -1
  4. package/dist/neutral/Payload/ModuleState.d.ts.map +1 -1
  5. package/package.json +24 -14
  6. package/src/Config/Archiving.ts +0 -10
  7. package/src/Config/Config.ts +0 -29
  8. package/src/Config/Fields.ts +0 -47
  9. package/src/Config/Reentrancy.ts +0 -6
  10. package/src/Config/Security.ts +0 -15
  11. package/src/Config/index.ts +0 -5
  12. package/src/CreatableModule/CreatableModule.ts +0 -42
  13. package/src/CreatableModule/CreatableModuleRegistry.ts +0 -102
  14. package/src/CreatableModule/LabeledCreatableModule.ts +0 -20
  15. package/src/CreatableModule/LabeledCreatableModuleFactory.ts +0 -21
  16. package/src/CreatableModule/ModuleFactory.ts +0 -60
  17. package/src/CreatableModule/index.ts +0 -5
  18. package/src/DetailsError.ts +0 -13
  19. package/src/EventsModels/ModuleBusy.ts +0 -14
  20. package/src/EventsModels/ModuleError.ts +0 -14
  21. package/src/EventsModels/ModuleEventArgs.ts +0 -9
  22. package/src/EventsModels/ModuleEventData.ts +0 -8
  23. package/src/EventsModels/ModuleQueried.ts +0 -19
  24. package/src/EventsModels/index.ts +0 -5
  25. package/src/Labels/Labels.ts +0 -33
  26. package/src/Labels/index.ts +0 -2
  27. package/src/Labels/standard/View.ts +0 -4
  28. package/src/Labels/standard/index.ts +0 -1
  29. package/src/ModuleDescription.ts +0 -9
  30. package/src/ModuleFactoryLocatorInstance.ts +0 -47
  31. package/src/ModuleIdentifier.ts +0 -69
  32. package/src/ModuleIdentifierTransformer.ts +0 -9
  33. package/src/ModuleQueryHandlerResult.ts +0 -3
  34. package/src/ModuleQueryResult.ts +0 -8
  35. package/src/ModuleStatusReporter.ts +0 -3
  36. package/src/Payload/Address.ts +0 -37
  37. package/src/Payload/AddressPreviousHash.ts +0 -13
  38. package/src/Payload/Description.ts +0 -8
  39. package/src/Payload/ModuleState.ts +0 -29
  40. package/src/Payload/index.ts +0 -4
  41. package/src/Queries/Manifest.ts +0 -9
  42. package/src/Queries/ModuleAddress/Query.ts +0 -8
  43. package/src/Queries/ModuleAddress/index.ts +0 -1
  44. package/src/Queries/State.ts +0 -6
  45. package/src/Queries/Subscribe.ts +0 -21
  46. package/src/Queries/index.ts +0 -11
  47. package/src/QueryableModule/IsQueryableModuleFactory.ts +0 -34
  48. package/src/QueryableModule/QueryableModule.ts +0 -14
  49. package/src/QueryableModule/QueryableModuleFields.ts +0 -37
  50. package/src/QueryableModule/QueryableModuleFunctions.ts +0 -18
  51. package/src/QueryableModule/QueryableModuleParams.ts +0 -20
  52. package/src/QueryableModule/asQueryableModule.ts +0 -8
  53. package/src/QueryableModule/asQueryableModuleObject.ts +0 -8
  54. package/src/QueryableModule/index.ts +0 -9
  55. package/src/QueryableModule/isQueryableModule.ts +0 -20
  56. package/src/QueryableModule/isQueryableModuleObject.ts +0 -20
  57. package/src/ResolveHelper/ResolveHelper.ts +0 -213
  58. package/src/ResolveHelper/ResolveHelperStatic.ts +0 -9
  59. package/src/ResolveHelper/index.ts +0 -9
  60. package/src/ResolveHelper/model.ts +0 -1
  61. package/src/ResolveHelper/resolveAddressToInstance.ts +0 -94
  62. package/src/ResolveHelper/resolveAll.ts +0 -53
  63. package/src/ResolveHelper/resolveLocalNameToAddress.ts +0 -40
  64. package/src/ResolveHelper/resolveLocalNameToInstance.ts +0 -47
  65. package/src/ResolveHelper/resolvePathToAddress.ts +0 -15
  66. package/src/ResolveHelper/resolvePathToInstance.ts +0 -36
  67. package/src/ResolveHelper/traceModuleIdentifier.ts +0 -19
  68. package/src/ResolveHelper/transformModuleIdentifier.ts +0 -13
  69. package/src/cache.ts +0 -5
  70. package/src/index.ts +0 -20
  71. package/src/instance/Instance.ts +0 -68
  72. package/src/instance/ModuleFilter.ts +0 -33
  73. package/src/instance/ModuleInstanceParams.ts +0 -11
  74. package/src/instance/ModuleRepository.ts +0 -12
  75. package/src/instance/ModuleResolver.ts +0 -21
  76. package/src/instance/ObjectFilter.ts +0 -48
  77. package/src/instance/ObjectResolver.ts +0 -40
  78. package/src/instance/asModuleInstance.ts +0 -5
  79. package/src/instance/attachable/AttachableInstance.ts +0 -25
  80. package/src/instance/attachable/asAttachableInstance.ts +0 -5
  81. package/src/instance/attachable/index.ts +0 -3
  82. package/src/instance/attachable/isAttachableInstance.ts +0 -17
  83. package/src/instance/index.ts +0 -10
  84. package/src/instance/isModuleInstance.ts +0 -15
  85. package/src/lib/duplicateModules.ts +0 -14
  86. package/src/lib/index.ts +0 -2
  87. package/src/lib/serializable.ts +0 -30
  88. package/src/withModule.ts +0 -15
@@ -17,7 +17,7 @@ export type AddressPayload = Payload<AddressFields, AddressSchema>;
17
17
  */
18
18
  export declare const isAddressPayload: (x?: unknown | null) => x is AddressPayload;
19
19
  export declare const asAddressPayload: import("@xylabs/sdk-js").AsTypeFunction<AddressPayload>;
20
- export declare const asOptionalAddressPayload: (value: import("@xylabs/promise").AnyNonPromise) => AddressPayload | undefined;
20
+ export declare const asOptionalAddressPayload: (value: import("@xylabs/sdk-js").AnyNonPromise) => AddressPayload | undefined;
21
21
  export interface AddressChildFields extends AddressFields {
22
22
  /**
23
23
  * The derivation path of the child address
@@ -1 +1 @@
1
- {"version":3,"file":"Address.d.ts","sourceRoot":"","sources":["../../../src/Payload/Address.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAC4B,KAAK,OAAO,EAC9C,MAAM,4BAA4B,CAAA;AAEnC,eAAO,MAAM,aAAa;;CAAwC,CAAA;AAClE,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAEhD,eAAO,MAAM,kBAAkB;;CAA8C,CAAA;AAC7E,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IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAA"}
@@ -13,5 +13,5 @@ export type ModuleState<T extends StateDictionary = StateDictionary> = Payload<S
13
13
  export declare const isModuleState: <T extends StateDictionary = StateDictionary, TInput = unknown>(payload?: TInput) => payload is ModuleState<T> & TInput;
14
14
  export declare const isModuleStateWithSources: <T extends StateDictionary = StateDictionary, TInput = unknown>(payload?: TInput) => payload is WithSources<ModuleState<T>> & TInput;
15
15
  export declare const asModuleState: import("@xylabs/sdk-js").AsTypeFunction<ModuleState<StateDictionary>>;
16
- export declare const asOptionalModuleState: (value: import("@xylabs/promise").AnyNonPromise) => ModuleState<StateDictionary> | undefined;
16
+ export declare const asOptionalModuleState: (value: import("@xylabs/sdk-js").AnyNonPromise) => ModuleState<StateDictionary> | undefined;
17
17
  //# sourceMappingURL=ModuleState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModuleState.d.ts","sourceRoot":"","sources":["../../../src/Payload/ModuleState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAKtE,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;CAC/B;AACD,MAAM,WAAW,KAAK,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe;IAChE,KAAK,EAAE,CAAC,CAAA;CACT;AAED,eAAO,MAAM,iBAAiB;;CAA6C,CAAA;AAC3E,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAA;AAExD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAA;AAE3G,e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AE,UAAU,MAAM,KAAG,OAAO,IAAI,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,MAE/E,CAAA;AAED,eAAO,MAAM,aAAa,uEAAsE,CAAA;AAChG,eAAO,MAAM,qBAAqB,6FAA8E,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/module-model",
3
- "version": "5.3.20",
3
+ "version": "5.3.24",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,26 +30,36 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
- "!**/*.test.*"
35
+ "!**/*.test.*",
36
+ "README.md"
37
37
  ],
38
38
  "dependencies": {
39
- "@xyo-network/account-model": "~5.3.20",
40
- "@xyo-network/boundwitness-model": "~5.3.20",
41
- "@xyo-network/manifest-model": "~5.3.20",
42
- "@xyo-network/payload-model": "~5.3.20"
39
+ "@xyo-network/account-model": "~5.3.24",
40
+ "@xyo-network/manifest-model": "~5.3.24",
41
+ "@xyo-network/boundwitness-model": "~5.3.24",
42
+ "@xyo-network/payload-model": "~5.3.24"
43
43
  },
44
44
  "devDependencies": {
45
- "@xylabs/sdk-js": "^5.0.90",
46
- "@xylabs/ts-scripts-common": "~7.5.6",
47
- "@xylabs/ts-scripts-yarn3": "~7.5.6",
48
- "@xylabs/tsconfig": "~7.5.6",
49
- "@xylabs/vitest-extended": "~5.0.90",
45
+ "@opentelemetry/api": "^1.9.1",
46
+ "@types/node": "^25.5.0",
47
+ "@xylabs/sdk-js": "^5.0.93",
48
+ "@xylabs/ts-scripts-common": "~7.6.16",
49
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
50
+ "@xylabs/tsconfig": "~7.6.16",
51
+ "@xylabs/vitest-extended": "~5.0.93",
52
+ "acorn": "^8.16.0",
53
+ "axios": "^1.14.0",
54
+ "esbuild": "^0.28.0",
50
55
  "typescript": "~5.9.3",
56
+ "vite": "^8.0.3",
51
57
  "vitest": "~4.1.2",
52
- "zod": "^4.3.6"
58
+ "zod": "^4.3.6",
59
+ "@xyo-network/account-model": "~5.3.24",
60
+ "@xyo-network/manifest-model": "~5.3.24",
61
+ "@xyo-network/boundwitness-model": "~5.3.24",
62
+ "@xyo-network/payload-model": "~5.3.24"
53
63
  },
54
64
  "peerDependencies": {
55
65
  "@xylabs/sdk-js": "^5",
@@ -58,4 +68,4 @@
58
68
  "publishConfig": {
59
69
  "access": "public"
60
70
  }
61
- }
71
+ }
@@ -1,10 +0,0 @@
1
- import type { Schema } from '@xyo-network/payload-model'
2
-
3
- import type { ModuleIdentifier } from '../ModuleIdentifier.ts'
4
-
5
- export interface ArchivingModuleConfig {
6
- readonly archiving?: {
7
- readonly archivists?: ModuleIdentifier[]
8
- readonly queries?: Schema[]
9
- }
10
- }
@@ -1,29 +0,0 @@
1
- import type { EmptyObject } from '@xylabs/sdk-js'
2
- import {
3
- asSchema, type Payload, type Schema,
4
- } from '@xyo-network/payload-model'
5
-
6
- import type { ArchivingModuleConfig } from './Archiving.ts'
7
- import type { ModuleConfigFields } from './Fields.ts'
8
- import type { ArchivingReentrancyConfig } from './Reentrancy.ts'
9
-
10
- export const ModuleConfigSchema = asSchema('network.xyo.module.config', true)
11
- export type ModuleConfigSchema = typeof ModuleConfigSchema
12
-
13
- export type WithAdditional<T extends EmptyObject = EmptyObject, TAdditional extends EmptyObject = EmptyObject>
14
- = T & TAdditional
15
-
16
- export type ModuleConfig<TConfig extends EmptyObject | Payload = EmptyObject, TSchema extends Schema | void = void> = Payload<
17
- WithAdditional<ArchivingModuleConfig & ModuleConfigFields & ArchivingReentrancyConfig, TConfig>,
18
- TSchema extends void ? TConfig extends Payload ? TConfig['schema']
19
- : Schema : TSchema
20
- >
21
-
22
- export type AnyConfigSchema<TConfig extends Omit<ModuleConfig, 'schema'> & { schema: Schema } = Omit<ModuleConfig, 'schema'> & { schema: Schema }>
23
- = ModuleConfig<TConfig, Schema>
24
-
25
- export type OptionalConfigSchema<TConfig extends AnyConfigSchema<ModuleConfig> = AnyConfigSchema<ModuleConfig>> = Omit<TConfig, 'schema'> & {
26
- schema?: TConfig['schema']
27
- }
28
-
29
- export type AnyModuleConfig = AnyConfigSchema<ModuleConfig>
@@ -1,47 +0,0 @@
1
- import type { LogLevelValue, RetryConfig } from '@xylabs/sdk-js'
2
- import type { Schema } from '@xyo-network/payload-model'
3
-
4
- import type { Labels } from '../Labels/index.ts'
5
- import type { ModuleIdentifier, ModuleName } from '../ModuleIdentifier.ts'
6
- import type { ModuleSecurityConfig } from './Security.ts'
7
-
8
- export interface ModuleConfigFields {
9
- /** Limit to only these allowed queries */
10
- readonly allowedQueries?: Schema[]
11
-
12
- /** @field The name/address of the Archivist to use for this module */
13
- readonly archivist?: ModuleIdentifier
14
-
15
- /**
16
- * @field The labels used for this module. If a label is specified, then the
17
- * ModuleFactoryLocator will attempt to find a ModuleFactory with the corresponding
18
- * labels to construct this module.
19
- */
20
- readonly labels?: Labels
21
-
22
- readonly logLevel?: LogLevelValue
23
-
24
- /** @field Friendly name of module (not collision resistant). Can be used to resolve module when registered/attached to Node. */
25
- readonly name?: ModuleName
26
-
27
- /** @field paging settings for queries */
28
- readonly paging?: Record<string, { size?: number }>
29
-
30
- readonly retry?: RetryConfig
31
-
32
- /** @field The query schemas and allowed/disallowed addresses which are allowed to issue them against the module.
33
- * If both allowed and disallowed is specified, then disallowed takes priority. */
34
- readonly security?: ModuleSecurityConfig
35
-
36
- /** @field sign every query */
37
- readonly sign?: boolean
38
-
39
- /** @field Store the queries made to the module in an archivist if possible */
40
- readonly storeQueries?: boolean
41
-
42
- /** @field Time Budget setting for spans */
43
- readonly timeBudget?: number
44
-
45
- /** @field add a timestamp payload to every query */
46
- readonly timestamp?: boolean
47
- }
@@ -1,6 +0,0 @@
1
- export interface ArchivingReentrancyConfig {
2
- readonly reentrancy?: {
3
- action: 'skip' | 'wait'
4
- scope: 'global'
5
- }
6
- }
@@ -1,15 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
- import type { Schema } from '@xyo-network/payload-model'
3
-
4
- export type CosigningAddressSet = Address[]
5
-
6
- export interface ModuleSecurityConfig {
7
- /** @field Will the module process queries that have unsigned BoundWitness in query tuples */
8
- readonly allowAnonymous?: boolean
9
-
10
- /** @field If schema in record, then only these address sets can access query */
11
- readonly allowed?: Record<Schema, (Address | CosigningAddressSet)[]>
12
-
13
- /** @field If schema in record, then anyone except these addresses can access query */
14
- readonly disallowed?: Record<Schema, Address[]>
15
- }
@@ -1,5 +0,0 @@
1
- export * from './Archiving.ts'
2
- export * from './Config.ts'
3
- export * from './Fields.ts'
4
- export * from './Reentrancy.ts'
5
- export * from './Security.ts'
@@ -1,42 +0,0 @@
1
- import type {
2
- Creatable, CreatableInstance, Logger,
3
- } from '@xylabs/sdk-js'
4
- import type { Schema } from '@xyo-network/payload-model'
5
-
6
- import type { ModuleEventData } from '../EventsModels/index.ts'
7
- import type { AttachableModuleInstance } from '../instance/index.ts'
8
- import type { QueryableModuleParams } from '../QueryableModule/index.ts'
9
-
10
- export interface CreatableModuleInstance<TParams extends QueryableModuleParams = QueryableModuleParams, TEventData extends ModuleEventData = ModuleEventData>
11
- extends CreatableInstance<TParams, TEventData>, AttachableModuleInstance<TParams, TEventData> {}
12
-
13
- export interface CreatableModuleFactory<T extends CreatableModuleInstance = CreatableModuleInstance>
14
- extends Omit<CreatableModule<T>, 'create' | 'createHandler' | 'paramsHandler'> {
15
- creatableModule: CreatableModule<T>
16
- defaultParams?: Partial<T['params']>
17
-
18
- create(
19
- this: CreatableModuleFactory<T>,
20
- params?: Partial<T['params']>): Promise<T>
21
- }
22
-
23
- export interface CreatableModule<T extends CreatableModuleInstance = CreatableModuleInstance> extends Creatable<T> {
24
- configSchemas: Schema[]
25
- defaultConfigSchema: Schema
26
- defaultLogger?: Logger
27
- new(key: unknown, params: Partial<T['params']>): T
28
- factory(params?: Partial<T['params']>): CreatableModuleFactory<T>
29
- }
30
-
31
- /**
32
- * Class annotation to be used to decorate Modules which support
33
- * an asynchronous creation pattern
34
- * @returns The decorated Module requiring it implement the members
35
- * of the CreatableModule as statics properties/methods
36
- */
37
- export function creatableModule<TModule extends CreatableModuleInstance = CreatableModuleInstance>() {
38
- return <U extends CreatableModule<TModule>>(constructor: U) => {
39
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
40
- constructor
41
- }
42
- }
@@ -1,102 +0,0 @@
1
- import { isTruthy } from '@xylabs/sdk-js'
2
- import { asSchema, type Schema } from '@xyo-network/payload-model'
3
-
4
- import type { Labels } from '../Labels/index.ts'
5
- import type { CreatableModuleFactory, CreatableModuleInstance } from './CreatableModule.ts'
6
- import type { LabeledCreatableModuleFactory } from './LabeledCreatableModuleFactory.ts'
7
-
8
- export interface CreatableModuleRegistry {
9
- [key: Schema]: (CreatableModuleFactory | LabeledCreatableModuleFactory)[] | undefined
10
- }
11
-
12
- const buildModuleFactory = <TModule extends CreatableModuleInstance>(
13
- mod: CreatableModuleFactory<TModule>,
14
- labels?: Labels,
15
- ): LabeledCreatableModuleFactory<TModule> => {
16
- const factory: LabeledCreatableModuleFactory<TModule> = {
17
- // Destructure instance properties
18
- ...mod,
19
-
20
- configSchemas: mod.configSchemas,
21
- // Copy static methods
22
- create: mod.create.bind(mod) as LabeledCreatableModuleFactory<TModule>['create'],
23
-
24
- defaultConfigSchema: mod.defaultConfigSchema,
25
- // Merge module & supplied labels
26
- labels: { ...(mod as LabeledCreatableModuleFactory).labels, ...labels },
27
- }
28
- return factory
29
- }
30
-
31
- export const registerCreatableModuleFactory = <TModule extends CreatableModuleInstance>(
32
- registry: CreatableModuleRegistry,
33
- factory: CreatableModuleFactory<TModule> | LabeledCreatableModuleFactory<TModule>,
34
- labels?: Labels,
35
- /** register this as the primary factory for every schema it supports */
36
- primary: boolean | Schema | Schema[] = false,
37
- ) => {
38
- const primarySchemas
39
- = primary !== true && isTruthy(primary)
40
- ? Array.isArray(primary)
41
- ? primary
42
- : [primary]
43
- : []
44
-
45
- for (const primarySchema of primarySchemas) {
46
- if (!factory.configSchemas.includes(primarySchema)) {
47
- console.warn(`Primary schema ${primary} not found in factory configSchemas`)
48
- }
49
- }
50
-
51
- const isPrimaryForSchema = (schema: Schema) => {
52
- switch (typeof primary) {
53
- case 'boolean': {
54
- return primary
55
- }
56
- case 'string': {
57
- return schema === primary
58
- }
59
- case 'object': {
60
- if (Array.isArray(primary)) {
61
- return primary.includes(schema)
62
- }
63
- }
64
- }
65
- throw new Error(`Invalid primary value: ${primary}`)
66
- }
67
-
68
- const factoryClone: LabeledCreatableModuleFactory<TModule> = buildModuleFactory(factory, labels)
69
- // add the defaultConfigSchema as the first key in the registry
70
- registry[factory.defaultConfigSchema] = [factoryClone, ...(registry[factoryClone.defaultConfigSchema] ?? [])]
71
- for (const schema of factoryClone.configSchemas) {
72
- registry[schema] = isPrimaryForSchema(schema) ? [factoryClone, ...(registry[schema] ?? [])] : [...(registry[schema] ?? []), factoryClone]
73
- }
74
- }
75
-
76
- export const registerCreatableModuleFactories = (
77
- factories: (CreatableModuleFactory | LabeledCreatableModuleFactory)[],
78
- registry: CreatableModuleRegistry = {},
79
- primary = false,
80
- ) => {
81
- for (const factory of factories) {
82
- registerCreatableModuleFactory(registry, factory, undefined, primary)
83
- }
84
- return registry
85
- }
86
-
87
- /** @deprecated use registerCreatableModuleFactory instead */
88
- export const assignCreatableModuleRegistry = (
89
- target: CreatableModuleRegistry = {},
90
- ...sources: CreatableModuleRegistry[]
91
- ): CreatableModuleRegistry => {
92
- for (const source of sources)
93
- for (const [schemaString, factories] of Object.entries(source)) {
94
- const schema = asSchema(schemaString, true)
95
- if (factories) {
96
- const existingFactories = target[schema]
97
- target[schema] = [...existingFactories ?? [], ...factories]
98
- }
99
- }
100
-
101
- return target
102
- }
@@ -1,20 +0,0 @@
1
- import type { WithOptionalLabels } from '../Labels/index.ts'
2
- import type { CreatableModule, CreatableModuleInstance } from './CreatableModule.ts'
3
- import type { LabeledCreatableModuleFactory } from './LabeledCreatableModuleFactory.ts'
4
-
5
- export interface LabeledCreatableModule<T extends CreatableModuleInstance = CreatableModuleInstance> extends CreatableModule<T>, WithOptionalLabels {
6
- factory(params?: Partial<T['params']>): LabeledCreatableModuleFactory<T>
7
- }
8
-
9
- /**
10
- * Class annotation to be used to decorate Modules which support
11
- * an asynchronous creation pattern
12
- * @returns The decorated Module requiring it implement the members
13
- * of the CreatableModule as statics properties/methods
14
- */
15
- export function labeledCreatableModule<TModule extends CreatableModuleInstance = CreatableModuleInstance>() {
16
- return <U extends LabeledCreatableModule<TModule>>(constructor: U) => {
17
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
18
- constructor
19
- }
20
- }
@@ -1,21 +0,0 @@
1
- import type { WithOptionalLabels } from '../Labels/index.ts'
2
- import type { CreatableModuleFactory, CreatableModuleInstance } from './CreatableModule.ts'
3
-
4
- export type LabeledCreatableModuleFactory<T extends CreatableModuleInstance = CreatableModuleInstance> = CreatableModuleFactory<T> & WithOptionalLabels
5
-
6
- export const hasLabels = (factory: CreatableModuleFactory | LabeledCreatableModuleFactory): factory is LabeledCreatableModuleFactory => {
7
- return (factory as LabeledCreatableModuleFactory).labels !== undefined
8
- }
9
-
10
- /**
11
- * Class annotation to be used to decorate Modules which support
12
- * an asynchronous labeled creation factory pattern
13
- * @returns The decorated Module requiring it implement the members
14
- * of the CreatableModule as statics properties/methods
15
- */
16
- export function labeledCreatableModuleFactory<TModule extends CreatableModuleInstance = CreatableModuleInstance>() {
17
- return <U extends LabeledCreatableModuleFactory<TModule>>(constructor: U) => {
18
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
19
- constructor
20
- }
21
- }
@@ -1,60 +0,0 @@
1
- import type { Logger } from '@xylabs/sdk-js'
2
- import { assertEx } from '@xylabs/sdk-js'
3
- import type { Schema } from '@xyo-network/payload-model'
4
-
5
- import type { Labels, WithOptionalLabels } from '../Labels/index.ts'
6
- import type {
7
- CreatableModule, CreatableModuleFactory, CreatableModuleInstance,
8
- } from './CreatableModule.ts'
9
-
10
- export class ModuleFactory<TModule extends CreatableModuleInstance> implements CreatableModuleFactory<TModule> {
11
- configSchemas: CreatableModule<TModule>['configSchemas']
12
-
13
- creatableModule: CreatableModule<TModule>
14
-
15
- defaultConfigSchema: Schema
16
-
17
- defaultLogger?: Logger
18
-
19
- defaultParams?: Partial<TModule['params']>
20
-
21
- labels?: Labels
22
-
23
- constructor(
24
- creatableModule: CreatableModule<TModule>,
25
- params?: Partial<TModule['params']>,
26
- labels: Labels = {},
27
- ) {
28
- this.creatableModule = creatableModule
29
- this.defaultParams = params
30
- this.configSchemas = creatableModule.configSchemas
31
- this.defaultConfigSchema = creatableModule.defaultConfigSchema
32
- assertEx(this.configSchemas.includes(this.defaultConfigSchema), () => 'defaultConfigSchema must be in configSchemas')
33
- this.labels = Object.assign({}, (creatableModule as WithOptionalLabels).labels ?? {}, labels ?? {})
34
- }
35
-
36
- static withParams<T extends CreatableModuleInstance>(
37
- creatableModule: CreatableModule<T>,
38
- params?: Partial<T['params']>,
39
- labels: Labels = {},
40
- ) {
41
- return new ModuleFactory<T>(creatableModule, params, labels)
42
- }
43
-
44
- create(this: CreatableModuleFactory<TModule>, params?: Partial<TModule['params']>): Promise<TModule> {
45
- const mergedParams: TModule['params'] = {
46
- ...this.defaultParams,
47
- ...params,
48
- config: {
49
- schema: this.creatableModule.defaultConfigSchema,
50
- ...this.defaultParams?.config,
51
- ...params?.config,
52
- },
53
- } as TModule['params']
54
- return this.creatableModule.create<TModule>(mergedParams)
55
- }
56
-
57
- factory<T extends CreatableModuleInstance>(this: CreatableModuleFactory<T>, params?: Partial<T['params']>, labels: Labels = {}): CreatableModuleFactory<T> {
58
- return new ModuleFactory<T>(this.creatableModule, params, labels)
59
- }
60
- }
@@ -1,5 +0,0 @@
1
- export * from './CreatableModule.ts'
2
- export * from './CreatableModuleRegistry.ts'
3
- export * from './LabeledCreatableModule.ts'
4
- export * from './LabeledCreatableModuleFactory.ts'
5
- export * from './ModuleFactory.ts'
@@ -1,13 +0,0 @@
1
- import type { JsonValue } from '@xylabs/sdk-js'
2
-
3
- export class ModuleDetailsError extends Error {
4
- details?: JsonValue
5
- constructor(
6
- message: string,
7
- details?: JsonValue,
8
- ) {
9
- super(message)
10
- this.details = details
11
- this.name = 'ModuleError'
12
- }
13
- }
@@ -1,14 +0,0 @@
1
- import type { EventData } from '@xylabs/sdk-js'
2
-
3
- import type { ModuleEventArgs } from './ModuleEventArgs.ts'
4
-
5
- export type ModuleBusyEventArgs<TModule extends object = object> = ModuleEventArgs<
6
- TModule,
7
- {
8
- busy: boolean
9
- }
10
- >
11
-
12
- export interface ModuleBusyEventData<TModule extends object = object> extends EventData {
13
- moduleBusy: ModuleBusyEventArgs<TModule>
14
- }
@@ -1,14 +0,0 @@
1
- import type { EventData } from '@xylabs/sdk-js'
2
-
3
- import type { ModuleEventArgs } from './ModuleEventArgs.ts'
4
-
5
- export type ModuleErrorEventArgs<TModule extends object = object> = ModuleEventArgs<
6
- TModule,
7
- {
8
- error: Error
9
- }
10
- >
11
-
12
- export interface ModuleErrorEventData<TModule extends object = object> extends EventData {
13
- moduleError: ModuleErrorEventArgs<TModule>
14
- }
@@ -1,9 +0,0 @@
1
- import type { EventArgs } from '@xylabs/sdk-js'
2
-
3
- export type ModuleEventArgs<TModule extends object = object, TArgs extends EventArgs | undefined = undefined>
4
- = TArgs extends EventArgs ? {
5
- mod: TModule
6
- } & TArgs
7
- : {
8
- mod: TModule
9
- }
@@ -1,8 +0,0 @@
1
- import type { ModuleBusyEventData } from './ModuleBusy.ts'
2
- import type { ModuleErrorEventData } from './ModuleError.ts'
3
- import type { ModuleQueriedEventData } from './ModuleQueried.ts'
4
-
5
- export interface ModuleEventData<TModule extends object = object>
6
- extends ModuleQueriedEventData<TModule>,
7
- ModuleBusyEventData<TModule>,
8
- ModuleErrorEventData<TModule> {}
@@ -1,19 +0,0 @@
1
- import type { EventData } from '@xylabs/sdk-js'
2
- import type { QueryBoundWitness } from '@xyo-network/boundwitness-model'
3
- import type { Payload } from '@xyo-network/payload-model'
4
-
5
- import type { ModuleQueryResult } from '../ModuleQueryResult.ts'
6
- import type { ModuleEventArgs } from './ModuleEventArgs.ts'
7
-
8
- export type ModuleQueriedEventArgs<TModule extends object = object> = ModuleEventArgs<
9
- TModule,
10
- {
11
- payloads?: Payload[]
12
- query: QueryBoundWitness
13
- result: ModuleQueryResult
14
- }
15
- >
16
-
17
- export interface ModuleQueriedEventData<TModule extends object = object> extends EventData {
18
- moduleQueried: ModuleQueriedEventArgs<TModule>
19
- }
@@ -1,5 +0,0 @@
1
- export * from './ModuleBusy.ts'
2
- export * from './ModuleError.ts'
3
- export * from './ModuleEventArgs.ts'
4
- export * from './ModuleEventData.ts'
5
- export * from './ModuleQueried.ts'
@@ -1,33 +0,0 @@
1
- /**
2
- * Object used to represent labels identifying a resource.
3
- */
4
- export interface Labels {
5
- [key: string]: string | undefined
6
- }
7
-
8
- /**
9
- * Interface for objects that have labels.
10
- */
11
- export interface WithLabels<T extends Labels = Labels> {
12
- labels: T
13
- }
14
-
15
- /**
16
- * Interface for objects that have labels.
17
- */
18
- export interface WithOptionalLabels<T extends Labels = Labels> {
19
- labels?: T
20
- }
21
-
22
- /**
23
- * Returns true if the source object has all the labels from the required set
24
- * @param source Source object to check against
25
- * @param required Set of labels to check for in source
26
- * @returns True of the source object has all the labels from the required set
27
- */
28
- export const hasAllLabels = (source?: Labels, required?: Labels): boolean => {
29
- if (!required) return true
30
- return Object.entries(required).every(([key, value]) => {
31
- return source?.hasOwnProperty(key as keyof typeof source) && source?.[key as keyof typeof source] === value
32
- })
33
- }
@@ -1,2 +0,0 @@
1
- export * from './Labels.ts'
2
- export * from './standard/index.ts'
@@ -1,4 +0,0 @@
1
- export const ModuleLimitationLabelName = 'network.xyo.module.limitation'
2
- export type ModuleLimitationLabelName = typeof ModuleLimitationLabelName
3
-
4
- export const ModuleLimitationViewLabel = { ModuleLimitationLabelName: 'view' }
@@ -1 +0,0 @@
1
- export * from './View.ts'
@@ -1,9 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
-
3
- import type { ModuleName } from './ModuleIdentifier.ts'
4
- export interface ModuleDescription {
5
- address: Address
6
- children?: string[]
7
- name?: ModuleName
8
- queries: string[]
9
- }