@xyo-network/module-model 3.18.10 → 4.0.1

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 (52) hide show
  1. package/dist/neutral/index.mjs +9 -23
  2. package/dist/neutral/index.mjs.map +1 -1
  3. package/dist/types/Config/Config.d.ts +5 -4
  4. package/dist/types/Config/Config.d.ts.map +1 -1
  5. package/dist/types/CreatableModule/CreatableModule.d.ts +21 -13
  6. package/dist/types/CreatableModule/CreatableModule.d.ts.map +1 -1
  7. package/dist/types/CreatableModule/CreatableModuleRegistry.d.ts +2 -3
  8. package/dist/types/CreatableModule/CreatableModuleRegistry.d.ts.map +1 -1
  9. package/dist/types/CreatableModule/LabeledCreatableModuleFactory.d.ts +3 -4
  10. package/dist/types/CreatableModule/LabeledCreatableModuleFactory.d.ts.map +1 -1
  11. package/dist/types/CreatableModule/ModuleFactory.d.ts +8 -17
  12. package/dist/types/CreatableModule/ModuleFactory.d.ts.map +1 -1
  13. package/dist/types/EventsModels/ModuleEventArgs.d.ts.map +1 -1
  14. package/dist/types/ModuleIdentifier.d.ts.map +1 -1
  15. package/dist/types/ModuleParams.d.ts +4 -5
  16. package/dist/types/ModuleParams.d.ts.map +1 -1
  17. package/dist/types/ModuleStatusReporter.d.ts +2 -3
  18. package/dist/types/ModuleStatusReporter.d.ts.map +1 -1
  19. package/dist/types/instance/Instance.d.ts +2 -1
  20. package/dist/types/instance/Instance.d.ts.map +1 -1
  21. package/dist/types/instance/ModuleFilter.d.ts +3 -30
  22. package/dist/types/instance/ModuleFilter.d.ts.map +1 -1
  23. package/dist/types/instance/ModuleResolver.d.ts +1 -10
  24. package/dist/types/instance/ModuleResolver.d.ts.map +1 -1
  25. package/dist/types/instance/ObjectFilter.d.ts.map +1 -1
  26. package/dist/types/instance/asModuleInstance.d.ts +1 -10
  27. package/dist/types/instance/asModuleInstance.d.ts.map +1 -1
  28. package/dist/types/instance/attachable/AttachableInstance.d.ts +3 -1
  29. package/dist/types/instance/attachable/AttachableInstance.d.ts.map +1 -1
  30. package/dist/types/instance/attachable/asAttachableInstance.d.ts +1 -10
  31. package/dist/types/instance/attachable/asAttachableInstance.d.ts.map +1 -1
  32. package/dist/types/module/asModule.d.ts +1 -10
  33. package/dist/types/module/asModule.d.ts.map +1 -1
  34. package/dist/types/module/asModuleObject.d.ts +1 -10
  35. package/dist/types/module/asModuleObject.d.ts.map +1 -1
  36. package/dist/types/module/isModuleObject.d.ts +1 -10
  37. package/dist/types/module/isModuleObject.d.ts.map +1 -1
  38. package/dist/types/withModule.d.ts +2 -20
  39. package/dist/types/withModule.d.ts.map +1 -1
  40. package/package.json +20 -19
  41. package/src/Config/Config.ts +9 -7
  42. package/src/CreatableModule/CreatableModule.ts +27 -16
  43. package/src/CreatableModule/CreatableModuleRegistry.ts +3 -4
  44. package/src/CreatableModule/LabeledCreatableModuleFactory.ts +3 -4
  45. package/src/CreatableModule/ModuleFactory.ts +18 -34
  46. package/src/EventsModels/ModuleEventArgs.ts +2 -3
  47. package/src/ModuleIdentifier.ts +8 -8
  48. package/src/ModuleParams.ts +11 -18
  49. package/src/ModuleStatusReporter.ts +3 -3
  50. package/src/instance/Instance.ts +2 -1
  51. package/src/instance/ObjectFilter.ts +3 -3
  52. package/src/instance/attachable/AttachableInstance.ts +3 -1
@@ -1,15 +1,14 @@
1
1
  import type { Schema } from '@xyo-network/payload-model'
2
2
 
3
- import type { AttachableModuleInstance } from '../instance/index.ts'
4
3
  import type { Labels } from '../Labels/index.ts'
5
- import type { CreatableModuleFactory } from './CreatableModule.ts'
4
+ import type { CreatableModuleFactory, CreatableModuleInstance } from './CreatableModule.ts'
6
5
  import type { LabeledCreatableModuleFactory } from './LabeledCreatableModuleFactory.ts'
7
6
 
8
7
  export interface CreatableModuleRegistry {
9
8
  [key: Schema]: (CreatableModuleFactory | LabeledCreatableModuleFactory)[] | undefined
10
9
  }
11
10
 
12
- const buildModuleFactory = <TModule extends AttachableModuleInstance>(
11
+ const buildModuleFactory = <TModule extends CreatableModuleInstance>(
13
12
  mod: CreatableModuleFactory<TModule>,
14
13
  labels?: Labels,
15
14
  ): LabeledCreatableModuleFactory<TModule> => {
@@ -28,7 +27,7 @@ const buildModuleFactory = <TModule extends AttachableModuleInstance>(
28
27
  return factory
29
28
  }
30
29
 
31
- export const registerCreatableModuleFactory = <TModule extends AttachableModuleInstance>(
30
+ export const registerCreatableModuleFactory = <TModule extends CreatableModuleInstance>(
32
31
  registry: CreatableModuleRegistry,
33
32
  factory: CreatableModuleFactory<TModule> | LabeledCreatableModuleFactory<TModule>,
34
33
  labels?: Labels,
@@ -1,8 +1,7 @@
1
- import type { AttachableModuleInstance } from '../instance/index.ts'
2
1
  import type { WithOptionalLabels } from '../Labels/index.ts'
3
- import type { CreatableModuleFactory } from './CreatableModule.ts'
2
+ import type { CreatableModuleFactory, CreatableModuleInstance } from './CreatableModule.ts'
4
3
 
5
- export type LabeledCreatableModuleFactory<T extends AttachableModuleInstance | void = void> = CreatableModuleFactory<T> & WithOptionalLabels
4
+ export type LabeledCreatableModuleFactory<T extends CreatableModuleInstance = CreatableModuleInstance> = CreatableModuleFactory<T> & WithOptionalLabels
6
5
 
7
6
  export const hasLabels = (factory: CreatableModuleFactory | LabeledCreatableModuleFactory): factory is LabeledCreatableModuleFactory => {
8
7
  return (factory as LabeledCreatableModuleFactory).labels !== undefined
@@ -14,7 +13,7 @@ export const hasLabels = (factory: CreatableModuleFactory | LabeledCreatableModu
14
13
  * @returns The decorated Module requiring it implement the members
15
14
  * of the CreatableModule as statics properties/methods
16
15
  */
17
- export function labeledCreatableModuleFactory<TModule extends AttachableModuleInstance = AttachableModuleInstance>() {
16
+ export function labeledCreatableModuleFactory<TModule extends CreatableModuleInstance = CreatableModuleInstance>() {
18
17
  return <U extends LabeledCreatableModuleFactory<TModule>>(constructor: U) => {
19
18
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
20
19
  constructor
@@ -2,12 +2,13 @@ import { assertEx } from '@xylabs/assert'
2
2
  import type { Logger } from '@xylabs/logger'
3
3
  import type { Schema } from '@xyo-network/payload-model'
4
4
 
5
- import type { AttachableModuleInstance } from '../instance/index.ts'
6
5
  import type { Labels, WithOptionalLabels } from '../Labels/index.ts'
7
- import type { CreatableModule, CreatableModuleFactory } from './CreatableModule.ts'
6
+ import type {
7
+ CreatableModule, CreatableModuleFactory, CreatableModuleInstance,
8
+ } from './CreatableModule.ts'
8
9
 
9
- export class ModuleFactory<TModule extends AttachableModuleInstance> implements CreatableModuleFactory<TModule> {
10
- configSchemas: CreatableModuleFactory<TModule>['configSchemas']
10
+ export class ModuleFactory<TModule extends CreatableModuleInstance> implements CreatableModuleFactory<TModule> {
11
+ configSchemas: CreatableModule<TModule>['configSchemas']
11
12
 
12
13
  creatableModule: CreatableModule<TModule>
13
14
 
@@ -15,13 +16,13 @@ export class ModuleFactory<TModule extends AttachableModuleInstance> implements
15
16
 
16
17
  defaultLogger?: Logger
17
18
 
18
- defaultParams?: Omit<TModule['params'], 'config'> & { config?: Partial<TModule['params']['config']> }
19
+ defaultParams?: Partial<TModule['params']>
19
20
 
20
21
  labels?: Labels
21
22
 
22
23
  constructor(
23
24
  creatableModule: CreatableModule<TModule>,
24
- params?: Omit<TModule['params'], 'config'> & { config?: Partial<TModule['params']['config']> },
25
+ params?: Partial<TModule['params']>,
25
26
  labels: Labels = {},
26
27
  ) {
27
28
  this.creatableModule = creatableModule
@@ -32,45 +33,28 @@ export class ModuleFactory<TModule extends AttachableModuleInstance> implements
32
33
  this.labels = Object.assign({}, (creatableModule as WithOptionalLabels).labels ?? {}, labels ?? {})
33
34
  }
34
35
 
35
- static withParams<T extends AttachableModuleInstance>(
36
+ static withParams<T extends CreatableModuleInstance>(
36
37
  creatableModule: CreatableModule<T>,
37
- params?: Omit<T['params'], 'config'> & { config?: T['params']['config'] },
38
+ params?: Partial<T['params']>,
38
39
  labels: Labels = {},
39
40
  ) {
40
- return new ModuleFactory(creatableModule, params, labels)
41
+ return new ModuleFactory<T>(creatableModule, params, labels)
41
42
  }
42
43
 
43
- _getRootFunction(funcName: string) {
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
- let anyThis = this as any
46
- while (anyThis.__proto__[funcName]) {
47
- anyThis = anyThis.__proto__
48
- }
49
- return anyThis[funcName]
50
- }
51
-
52
- _noOverride(functionName: string) {
53
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
- const thisFunc = (this as any)[functionName]
55
-
56
- const rootFunc = this._getRootFunction(functionName)
57
- assertEx(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`)
58
- }
59
-
60
- create<T extends AttachableModuleInstance>(this: CreatableModuleFactory<T>, params: TModule['params']): Promise<T> {
61
- const factory = this as ModuleFactory<T>
62
- const schema = factory.creatableModule.defaultConfigSchema
44
+ create(this: CreatableModuleFactory<TModule>, params?: Partial<TModule['params']>): Promise<TModule> {
63
45
  const mergedParams: TModule['params'] = {
64
- ...factory.defaultParams,
46
+ ...this.defaultParams,
65
47
  ...params,
66
48
  config: {
67
- ...factory.defaultParams?.config, ...params.config, schema,
49
+ schema: this.creatableModule.defaultConfigSchema,
50
+ ...this.defaultParams?.config,
51
+ ...params?.config,
68
52
  },
69
53
  } as TModule['params']
70
- return factory.creatableModule.create<T>(mergedParams)
54
+ return this.creatableModule.create<TModule>(mergedParams)
71
55
  }
72
56
 
73
- factory<T extends AttachableModuleInstance>(this: CreatableModule<T>, _params?: T['params'] | undefined): CreatableModuleFactory<T> {
74
- throw new Error('Method not implemented.')
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)
75
59
  }
76
60
  }
@@ -1,8 +1,7 @@
1
1
  import type { EventArgs } from '@xylabs/events'
2
2
 
3
- export type ModuleEventArgs<TModule extends object = object, TArgs extends EventArgs | undefined = undefined> =
4
- TArgs extends EventArgs ?
5
- {
3
+ export type ModuleEventArgs<TModule extends object = object, TArgs extends EventArgs | undefined = undefined>
4
+ = TArgs extends EventArgs ? {
6
5
  mod: TModule
7
6
  } & TArgs
8
7
  : {
@@ -42,14 +42,14 @@ export const ReservedModuleIdentifierCharacters = new Set<ReservedModuleIdentifi
42
42
  // using Exclude to make this type not allowed to take a naked string
43
43
  export type ModuleName = Exclude<string, 'reserved-module-name-56487634'>
44
44
 
45
- export type ModuleIdentifier =
46
- | ColonPair<ModuleIdentifierPart>
47
- | ColonPair<ColonPair<ModuleIdentifierPart>>
48
- | ColonPair<ColonPair<ColonPair<ModuleIdentifierPart>>>
49
- | ColonPair<ColonPair<ColonPair<ColonPair<ModuleIdentifierPart>>>>
50
- | ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ModuleIdentifierPart>>>>>
51
- | ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ModuleIdentifierPart>>>>>>
52
- | ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ModuleIdentifierPart>>>>>>>
45
+ export type ModuleIdentifier
46
+ = | ColonPair<ModuleIdentifierPart>
47
+ | ColonPair<ColonPair<ModuleIdentifierPart>>
48
+ | ColonPair<ColonPair<ColonPair<ModuleIdentifierPart>>>
49
+ | ColonPair<ColonPair<ColonPair<ColonPair<ModuleIdentifierPart>>>>
50
+ | ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ModuleIdentifierPart>>>>>
51
+ | ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ModuleIdentifierPart>>>>>>
52
+ | ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ColonPair<ModuleIdentifierPart>>>>>>>
53
53
 
54
54
  export type ColonPair<T extends string> = `${T}:${T}` | T
55
55
 
@@ -1,5 +1,4 @@
1
- import type { BaseParams } from '@xylabs/base'
2
- import type { EmptyObject, WithAdditional } from '@xylabs/object'
1
+ import type { CreatableParams } from '@xylabs/creatable'
3
2
  import type { AccountInstance } from '@xyo-network/account-model'
4
3
 
5
4
  import type { AnyConfigSchema, ModuleConfig } from './Config/index.ts'
@@ -12,19 +11,13 @@ export type ModuleChildrenParams = {
12
11
  publicChildren?: ModuleInstance[]
13
12
  }
14
13
 
15
- export type ModuleParams<
16
- TConfig extends AnyConfigSchema<ModuleConfig> | void = void,
17
- TAdditionalParams extends EmptyObject | void = void,
18
- > = WithAdditional<
19
- BaseParams<{
20
- account?: AccountInstance | 'random'
21
- addToResolvers?: boolean
22
- additionalSigners?: AccountInstance[]
23
- allowNameResolution?: boolean
24
- config: TConfig extends AnyConfigSchema<ModuleConfig> ? TConfig : AnyConfigSchema<ModuleConfig>
25
- ephemeralQueryAccountEnabled?: boolean
26
- moduleIdentifierTransformers?: ModuleIdentifierTransformer[]
27
- statusReporter?: ModuleStatusReporter
28
- } & ModuleChildrenParams>,
29
- TAdditionalParams
30
- >
14
+ export interface ModuleParams<TConfig extends AnyConfigSchema<ModuleConfig> = AnyConfigSchema<ModuleConfig>> extends CreatableParams, ModuleChildrenParams {
15
+ account?: AccountInstance | 'random'
16
+ addToResolvers?: boolean
17
+ additionalSigners?: AccountInstance[]
18
+ allowNameResolution?: boolean
19
+ config: Partial<TConfig>
20
+ ephemeralQueryAccountEnabled?: boolean
21
+ moduleIdentifierTransformers?: ModuleIdentifierTransformer[]
22
+ statusReporter?: ModuleStatusReporter
23
+ }
@@ -1,5 +1,5 @@
1
+ import type { CreatableStatusReporter } from '@xylabs/creatable'
2
+
1
3
  import type { ModuleStatus } from './instance/index.ts'
2
4
 
3
- export interface ModuleStatusReporter {
4
- reportStatus: (name: string, status: ModuleStatus, progress?: number) => void
5
- }
5
+ export interface ModuleStatusReporter extends CreatableStatusReporter {}
@@ -1,3 +1,4 @@
1
+ import type { CreatableStatus } from '@xylabs/creatable'
1
2
  import type { Address } from '@xylabs/hex'
2
3
  import type { TypeCheck } from '@xylabs/object'
3
4
  import { IsObjectFactory, toJsonString } from '@xylabs/object'
@@ -13,7 +14,7 @@ import type { ObjectResolver } from './ObjectResolver.ts'
13
14
 
14
15
  export type ModulePipeLine = Lowercase<'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many'>
15
16
 
16
- export type ModuleStatus = 'started' | 'starting' | 'stopped' | 'stopping' | 'dead' | 'wrapped' | 'proxy'
17
+ export type ModuleStatus = CreatableStatus | 'wrapped' | 'proxy'
17
18
 
18
19
  export class DeadModuleError extends Error {
19
20
  constructor(
@@ -41,8 +41,8 @@ export interface QueryObjectFilter<T extends EmptyObject = AnyObject> extends Ob
41
41
  export const isQueryObjectFilter = <T extends EmptyObject = AnyObject>(value: unknown): value is QueryObjectFilter<T> =>
42
42
  (value as QueryObjectFilter<T>).query !== undefined
43
43
 
44
- export type AnyObjectFilter<T extends EmptyObject = AnyObject> = Partial<AddressObjectFilter<T>> &
45
- Partial<NameObjectFilter<T>> &
46
- Partial<QueryObjectFilter<T>>
44
+ export type AnyObjectFilter<T extends EmptyObject = AnyObject> = Partial<AddressObjectFilter<T>>
45
+ & Partial<NameObjectFilter<T>>
46
+ & Partial<QueryObjectFilter<T>>
47
47
 
48
48
  export type ObjectFilter<T extends EmptyObject> = ObjectFilterOptions<T> | AddressObjectFilter<T> | NameObjectFilter<T> | QueryObjectFilter<T>
@@ -1,3 +1,4 @@
1
+ import type { CreatableInstance } from '@xylabs/creatable'
1
2
  import type { TypeCheck } from '@xylabs/object'
2
3
  import { IsObjectFactory } from '@xylabs/object'
3
4
 
@@ -7,7 +8,8 @@ import type { ModuleInstance } from '../Instance.ts'
7
8
  import type { ModuleResolverInstance } from '../ModuleResolver.ts'
8
9
 
9
10
  export interface AttachableModuleInstance<TParams extends ModuleParams = ModuleParams, TEventData extends ModuleEventData = ModuleEventData>
10
- extends ModuleInstance<TParams, TEventData> {
11
+ extends ModuleInstance<TParams, TEventData>, CreatableInstance<TParams, TEventData> {
12
+ config: TParams['config']
11
13
  /* 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 */
12
14
  readonly downResolver: ModuleResolverInstance
13
15