mnemonica 1.4.8 → 1.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
1
  import type { TypeRegistry } from '../index';
2
2
  import type { constants } from '../constants';
3
- export type PropsType = Record<string, unknown>;
4
3
  export type IDEF<T, Args extends unknown[] = unknown[]> = {
5
4
  new (...args: Args): T;
6
5
  } | {
@@ -19,34 +18,12 @@ export interface DefineNewable extends NewableFunction {
19
18
  export type DefineNewableOrCallable = DefineNewable | DefineCallable;
20
19
  export interface InstanceConstructor extends NewableFunction {
21
20
  }
22
- export interface AnyHookCallback extends CallableFunction {
23
- (...args: never[]): unknown;
24
- }
25
- export interface UtilFunction extends CallableFunction {
26
- (...args: never[]): unknown;
27
- }
28
- export interface LookupSource {
29
- lookup(path: string): TypeClass | undefined;
30
- }
31
- export interface ThrowModificationError extends CallableFunction {
32
- (error: Error): void;
33
- }
34
- export interface ForkInvoker<T extends object> extends CallableFunction {
35
- (this: object | void, ...forkArgs: unknown[]): T;
36
- }
37
21
  export type ErrorMessageKey = 'BASE_ERROR_MESSAGE' | 'HANDLER_MUST_BE_A_FUNCTION' | 'WRONG_TYPE_DEFINITION' | 'WRONG_INSTANCE_INVOCATION' | 'WRONG_MODIFICATION_PATTERN' | 'ALREADY_DECLARED' | 'WRONG_ARGUMENTS_USED' | 'WRONG_HOOK_TYPE' | 'MISSING_HOOK_CALLBACK' | 'MISSING_CALLBACK_ARGUMENT' | 'OPTIONS_ERROR' | 'WRONG_STACK_CLEANER' | 'TYPENAME_MUST_BE_A_STRING';
38
22
  export type ErrorMessages = Record<ErrorMessageKey, string>;
39
- export interface hook extends CallableFunction {
40
- (opts: deliveredHookOpts): unknown;
41
- }
42
- export interface FlowChecker extends CallableFunction {
43
- (opts: object): unknown;
44
- }
45
23
  export interface MnemonicaErrorConstructor extends NewableFunction {
46
24
  new (addition?: string, stack?: string[]): MnemonicaError;
47
25
  readonly prototype: MnemonicaError;
48
26
  }
49
- export type ErrorsTypesMap = Record<string, MnemonicaErrorConstructor>;
50
27
  export type MnemonicaError = Error;
51
28
  export interface ErrorProps {
52
29
  args?: unknown[];
@@ -70,19 +47,22 @@ export interface TypeConstructorBase {
70
47
  new (...args: unknown[]): object;
71
48
  }
72
49
  export type AnyConstructor = new (...args: never[]) => unknown;
73
- export type InstanceOfTypeRegistry<K extends keyof TypeRegistry> = TypeRegistry[K] extends new (...args: never[]) => infer R ? R : never;
74
- export type LiteralKeysOf<T> = keyof T extends infer K ? K extends string ? string extends K ? never : K : never : never;
75
- export type ParentPath<K extends string> = K extends `${infer P}.${string}` ? P : never;
76
- export type AllParentPrefixes<K extends string> = K extends `${infer P}.${string}` ? P | AllParentPrefixes<P> : never;
77
- export type ChildKeysOf<P extends string> = {
78
- [K in keyof TypeRegistry]: K extends `${P}.${string}` ? K : never;
79
- }[keyof TypeRegistry];
80
- export type PathOfInstance<T extends object> = {
81
- [K in LiteralKeysOf<TypeRegistry>]: TypeRegistry[K] extends new (...args: never[]) => infer R ? T extends R ? K : never : never;
82
- }[LiteralKeysOf<TypeRegistry>];
83
- export type ParentPathOfInstance<T extends object> = {
84
- [K in LiteralKeysOf<TypeRegistry>]: TypeRegistry[K] extends new (...args: never[]) => infer R ? T extends R ? AllParentPrefixes<K> : never : never;
85
- }[LiteralKeysOf<TypeRegistry>];
50
+ export type Constructor<T = object> = new (...args: never[]) => T;
51
+ export type ConstructorName<T extends Constructor<object>> = T extends {
52
+ name: infer N;
53
+ } ? N extends string ? N : string : string;
54
+ export interface AnyHookCallback extends CallableFunction {
55
+ (...args: never[]): unknown;
56
+ }
57
+ export interface ThrowModificationError extends CallableFunction {
58
+ (error: Error): void;
59
+ }
60
+ export interface hook extends CallableFunction {
61
+ (opts: deliveredHookOpts): unknown;
62
+ }
63
+ export interface FlowChecker extends CallableFunction {
64
+ (opts: object): unknown;
65
+ }
86
66
  export type hooksTypes = 'preCreation' | 'postCreation' | 'creationError';
87
67
  export type hooksOpts<P = object, T = P> = {
88
68
  TypeName: string;
@@ -121,6 +101,12 @@ export interface typedHook<HT extends hooksTypes, P extends object = object, T e
121
101
  export type HookableConstructor<T extends object> = Constructor<T> & {
122
102
  registerHook(hookType: hooksTypes, cb: AnyHookCallback): void;
123
103
  };
104
+ export interface Hookable {
105
+ hooks: Record<string, Set<hook>>;
106
+ invokeHook(hookType: hooksTypes, opts: hooksOpts): Set<unknown>;
107
+ registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT>): void;
108
+ registerFlowChecker(cb: FlowChecker): void;
109
+ }
124
110
  export interface AddPropsCallback extends CallableFunction {
125
111
  (proto: object): void;
126
112
  }
@@ -177,6 +163,84 @@ export type CollectionDef = Hookable & {
177
163
  } & {
178
164
  [K in typeof constants.SymbolConfig]: CollectionConfig;
179
165
  };
166
+ export interface ThenSpec {
167
+ subtype: object;
168
+ args: unknown[];
169
+ name?: string;
170
+ }
171
+ export interface InstanceCreatorContext {
172
+ type: TypeDef;
173
+ TypeName: string;
174
+ existentInstance: object;
175
+ args: unknown[];
176
+ ModificationConstructor: ModificationConstructor;
177
+ ModificatorType: MnemonicaConstructor;
178
+ InstanceModificator: MnemonicaConstructor;
179
+ inheritedInstance: object | Promise<object>;
180
+ config: constructorOptions;
181
+ proto: object;
182
+ __proto_proto__?: object;
183
+ stack?: string[];
184
+ lazyFailed?: boolean;
185
+ lazyError?: unknown;
186
+ postHooksFired?: boolean;
187
+ getExistentAsyncStack(existentInstance: object): unknown;
188
+ postProcessing(continuationOf?: TypeDef): void;
189
+ makeAwaiter(type: TypeDef, then?: ThenSpec): Promise<object>;
190
+ addThen(then: ThenSpec): void;
191
+ invokePreHooks(): void;
192
+ invokePostHooks(): {
193
+ type: Set<unknown>;
194
+ collection: Set<unknown>;
195
+ };
196
+ throwModificationError(error: MnemonicaError): void;
197
+ }
198
+ export type InstanceInternalProps = {
199
+ __proto_proto__: object;
200
+ __args__: unknown[];
201
+ __collection__: CollectionDef;
202
+ __subtypes__: Map<string, object>;
203
+ __type__: TypeDef;
204
+ __parent__: object;
205
+ __stack__?: string;
206
+ __creator__: InstanceCreatorContext;
207
+ __timestamp__: number;
208
+ };
209
+ export type Props = InstanceInternalProps & {
210
+ __self__: InstanceInternalProps;
211
+ [key: string]: unknown;
212
+ };
213
+ export interface MnemonicaConstructor extends NewableFunction {
214
+ new (...args: unknown[]): object;
215
+ [key: symbol]: unknown;
216
+ }
217
+ export interface TypeDescriptorDefine extends CallableFunction {
218
+ (TypeOrTypeName: string | DefineNewableOrCallable, constructHandlerOrConfig?: DefineNewableOrCallable | object, config?: object): TypeClass;
219
+ }
220
+ export interface TypeDescriptorLazy extends CallableFunction {
221
+ (TypeName: string, getter: LazyDef<object>, config?: object): TypeClass;
222
+ }
223
+ export interface TypeDescriptorLookup extends CallableFunction {
224
+ (TypeNestedPath: string): TypeClass | undefined;
225
+ }
226
+ export type TypeDescriptorInstance = {
227
+ define: TypeDescriptorDefine;
228
+ lazy: TypeDescriptorLazy;
229
+ decorate: (config?: constructorOptions) => <U extends Constructor<object>>(cstr: U) => DecoratedClass<U>;
230
+ lookup: TypeDescriptorLookup;
231
+ subtypes: Map<string, object>;
232
+ TypeName: string;
233
+ collection: CollectionDef;
234
+ };
235
+ export interface LookupSource {
236
+ lookup(path: string): TypeClass | undefined;
237
+ }
238
+ export type InstanceOfTypeRegistry<K extends keyof TypeRegistry> = TypeRegistry[K] extends new (...args: never[]) => infer R ? R : never;
239
+ export type LiteralKeysOf<T> = keyof T extends infer K ? K extends string ? string extends K ? never : K : never : never;
240
+ export type AllParentPrefixes<K extends string> = K extends `${infer P}.${string}` ? P | AllParentPrefixes<P> : never;
241
+ export type ParentPathOfInstance<T extends object> = {
242
+ [K in LiteralKeysOf<TypeRegistry>]: TypeRegistry[K] extends new (...args: never[]) => infer R ? T extends R ? AllParentPrefixes<K> : never : never;
243
+ }[LiteralKeysOf<TypeRegistry>];
180
244
  export type GlobalRegistry = TypeRegistry & Record<string, TypeConstructorBase>;
181
245
  export type ExtractConstructorInstance<C> = C extends {
182
246
  new (...args: never[]): infer I;
@@ -194,13 +258,14 @@ export type ReplaceConstructorInstance<C, NewInstance extends object, CallConstr
194
258
  readonly prototype: NewInstance & {
195
259
  readonly constructor: ReplaceConstructorInstance<C, NewInstance, CallConstructs>;
196
260
  };
197
- } & (C extends {
198
- (...args: infer A2): unknown;
261
+ } & ReplacedCallSignature<C, NewInstance, CallConstructs> & Omit<C, 'prototype' | 'lookup'> : never;
262
+ export type ReplacedCallSignature<C, NewInstance extends object, CallConstructs extends boolean> = C extends {
263
+ (...args: infer A): unknown;
199
264
  } ? CallConstructs extends true ? {
200
- (...args: A2): ConstructResult<C, NewInstance>;
265
+ (...args: A): ConstructResult<C, NewInstance>;
201
266
  } : {
202
- (this: NewInstance, ...args: A2): ConstructResult<C, NewInstance>;
203
- } : unknown) & Omit<C, 'prototype' | 'lookup'> : never;
267
+ (this: NewInstance, ...args: A): ConstructResult<C, NewInstance>;
268
+ } : unknown;
204
269
  export type WithSubTypes<Instance extends object, Registry extends object, Path extends string> = Instance & SubTypeConstructors<Registry, Path>;
205
270
  export type AugmentedConstructor<Registry extends object, Path extends keyof Registry & string, CallConstructs extends boolean = false> = ReplaceConstructorInstance<Registry[Path], LookedUpInstance<Registry, Path>, CallConstructs>;
206
271
  export type LookedUpInstance<Registry extends object, Path extends string> = WithSubTypes<ExtractConstructorInstance<Registry[Path & keyof Registry]>, Registry, Path>;
@@ -232,7 +297,6 @@ export interface TypeLookup<T extends object = GlobalRegistry> extends CallableF
232
297
  }
233
298
  export type RegistryOf<T> = T extends IDefinitorInstance<object, InstanceResult<object>, infer Registry, string, object, never[]> ? Registry : T extends TypesCollection<infer Registry, object, string> ? Registry : T extends MnemonicaModule<infer Registry> ? Registry : never;
234
299
  export type RelativeKeys<Registry extends object, Path extends string> = Path extends '' ? keyof Registry & string : (keyof Registry extends infer K ? K extends `${Path}.${infer Child}` ? Child : never : never);
235
- export type FullKey<Registry extends object, Path extends string, K extends string> = Path extends '' ? K : Extract<keyof Registry & string, `${Path}.${K}`>;
236
300
  export type NestedTypeLookup<Registry extends object, Path extends string = ''> = (Path extends '' ? {
237
301
  <const K extends keyof Registry & string>(this: unknown, TypeNestedPath: K): LookedUpConstructor<Registry, K>;
238
302
  } : {
@@ -240,37 +304,64 @@ export type NestedTypeLookup<Registry extends object, Path extends string = ''>
240
304
  }) & {
241
305
  (this: unknown, TypeNestedPath: string): TypeClass | undefined;
242
306
  };
243
- export interface ThenSpec {
244
- subtype: object;
245
- args: unknown[];
246
- name?: string;
307
+ export interface RegistryEntry<F extends object, Path extends string = '', Parent extends object = object, Args extends unknown[] = unknown[]> extends _Internal_TC_<F, Args>, RegistryHolderBase<{}, F, Path> {
308
+ registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT, Parent, F>): void;
247
309
  }
248
- export interface InstanceCreatorContext {
249
- type: TypeDef;
250
- TypeName: string;
251
- existentInstance: object;
252
- args: unknown[];
253
- ModificationConstructor: ModificationConstructor;
254
- ModificatorType: MnemonicaConstructor;
255
- InstanceModificator: MnemonicaConstructor;
256
- inheritedInstance: object | Promise<object>;
257
- config: constructorOptions;
258
- proto: object;
259
- __proto_proto__?: object;
260
- stack?: string[];
261
- lazyFailed?: boolean;
262
- lazyError?: unknown;
263
- postHooksFired?: boolean;
264
- getExistentAsyncStack(existentInstance: object): unknown;
265
- postProcessing(continuationOf?: TypeDef): void;
266
- makeAwaiter(type: TypeDef, then?: ThenSpec): Promise<object>;
267
- addThen(then: ThenSpec): void;
268
- invokePreHooks(): void;
269
- invokePostHooks(): {
270
- type: Set<unknown>;
271
- collection: Set<unknown>;
310
+ export interface AsyncRegistryEntry<F extends object, Path extends string = '', Parent extends object = object, Args extends unknown[] = unknown[]> extends RegistryHolderBase<{}, F, Path> {
311
+ new (...args: Args): Promise<F>;
312
+ (this: F, ...args: Args): Promise<F>;
313
+ readonly prototype: F & {
314
+ readonly constructor: AsyncRegistryEntry<F, Path, Parent, Args>;
272
315
  };
273
- throwModificationError(error: MnemonicaError): void;
316
+ registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT, Parent, F>): void;
317
+ }
318
+ export type ChildPathOf<Path extends string, Name extends string> = Path extends '' ? Name : `${Path}.${Name}`;
319
+ export interface RegistryHolderBase<T extends object = {}, Parent extends object = object, Path extends string = ''> {
320
+ define<SubType extends object>(this: RegistryHolderBase<T, Parent, Path>, TypeOrTypeName: DefineNewableOrCallable, constructHandlerOrConfig?: IDEF<SubType> | object | boolean | DefineNewableOrCallable, configOrUndefined?: constructorOptions | DefineNewableOrCallable | boolean): IDefinitorInstance<SubType>;
321
+ define<const Name extends string, N extends object, Args extends unknown[] = unknown[], F extends Proto<Parent, N> = Proto<Parent, N>, ChildPath extends string = ChildPathOf<Path, Name>>(this: RegistryHolderBase<T, Parent, Path>, TypeName: Name, constructHandler: (this: N, ...args: Args) => PromiseLike<unknown>, config?: constructorOptions): IDefinitorInstance<F, InstanceResult<F>, T & Record<ChildPath, AsyncRegistryEntry<F, ChildPath, Parent, Args>>, ChildPath, Parent, Args>;
322
+ define<const Name extends string, N extends object, Args extends unknown[] = unknown[], F extends Proto<Parent, N> = Proto<Parent, N>, ChildPath extends string = ChildPathOf<Path, Name>>(this: RegistryHolderBase<T, Parent, Path>, TypeName: Name, constructHandler?: IDEF<N, Args>, config?: constructorOptions): IDefinitorInstance<F, InstanceResult<F>, T & Record<ChildPath, RegistryEntry<F, ChildPath, Parent, Args>>, ChildPath, Parent, Args>;
323
+ lazy<const Name extends string, N extends object, Args extends unknown[], F extends Proto<Parent, N> = Proto<Parent, N>, ChildPath extends string = ChildPathOf<Path, Name>>(this: RegistryHolderBase<T, Parent, Path>, TypeName: Name, getter: () => (this: N, ...args: Args) => PromiseLike<unknown>, config?: constructorOptions): IDefinitorInstance<F, InstanceResult<F>, T & Record<ChildPath, AsyncRegistryEntry<F, ChildPath, Parent, Args>>, ChildPath, Parent, Args>;
324
+ lazy<const Name extends string, N extends object, Args extends unknown[], F extends Proto<Parent, N> = Proto<Parent, N>, ChildPath extends string = ChildPathOf<Path, Name>>(this: RegistryHolderBase<T, Parent, Path>, TypeName: Name, getter: LazyDef<N, Args>, config?: constructorOptions): IDefinitorInstance<F, InstanceResult<F>, T & Record<ChildPath, RegistryEntry<F, ChildPath, Parent, Args>>, ChildPath, Parent, Args>;
325
+ }
326
+ export interface RegistryHolder<T extends object = {}, Parent extends object = object, Path extends string = ''> extends RegistryHolderBase<T, Parent, Path> {
327
+ lookup: NestedTypeLookup<T, Path>;
328
+ }
329
+ export interface IDefinitorInstance<N extends object, R extends InstanceResult<N> = InstanceResult<N>, Registry extends object = GlobalRegistry, Path extends string = '', Parent extends object = object, Args extends unknown[] = unknown[]> extends RegistryHolderBase<Registry, N, Path> {
330
+ TypeName: string;
331
+ prototype: N;
332
+ new (...args: Args): R;
333
+ (...args: unknown[]): IDefinitorInstance<R>;
334
+ lookup: TypeLookup<Registry>;
335
+ decorate: (config?: constructorOptions) => <U extends Constructor<object>>(cstr: U) => DecoratedClass<U, Registry>;
336
+ registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT, Parent, N>): void;
337
+ subtypes: SubtypesMap;
338
+ __type__?: TypeDef;
339
+ collection?: CollectionDef;
340
+ }
341
+ export interface TypeAbsorber extends CallableFunction {
342
+ <T extends object, Args extends unknown[] = unknown[]>(this: unknown, TypeOrTypeName: string | DefineNewableOrCallable, constructHandlerOrConfig?: IDEF<T, Args> | object | boolean | DefineNewableOrCallable, configOrUndefined?: constructorOptions | DefineNewableOrCallable | boolean): IDefinitorInstance<T, InstanceResult<T>, GlobalRegistry, '', object, Args>;
343
+ }
344
+ export interface LazyAbsorber extends CallableFunction {
345
+ <T extends object, Args extends unknown[] = unknown[]>(this: unknown, TypeName: string, getter: LazyDef<T, Args>, config?: constructorOptions): IDefinitorInstance<T, InstanceResult<T>, GlobalRegistry, '', object, Args>;
346
+ <T extends object, Args extends unknown[] = unknown[]>(this: unknown, source: RegistryHolderBase<object, object, string>, TypeName: string, getter: LazyDef<T, Args>, config?: constructorOptions): IDefinitorInstance<T, InstanceResult<T>, GlobalRegistry, '', object, Args>;
347
+ }
348
+ export interface TypesCollection<T extends object = {}, Parent extends object = object, Path extends string = ''> extends RegistryHolder<T, Parent, Path>, Hookable {
349
+ subtypes: SubtypesMap;
350
+ decorate(config?: constructorOptions): <U extends Constructor<object>>(cstr: U) => DecoratedClass<U, T & Record<ConstructorName<U>, RegistryEntry<InstanceType<U>, ConstructorName<U>>>>;
351
+ [key: string]: unknown;
352
+ }
353
+ export type CreateTypesCollectionFunction = <T extends object = {}, Parent extends object = object>(config?: constructorOptions) => TypesCollection<T, Parent>;
354
+ export type TypeClass = IDefinitorInstance<object>;
355
+ export type DecoratedClass<T extends Constructor<object>, Registry extends object = TypeRegistry> = T & Omit<IDefinitorInstance<InstanceType<T>, InstanceType<T>, Registry, ConstructorName<T>>, 'define' | 'lookup'> & (<U extends Constructor<object>>(target: U) => DecoratedClass<U, Registry>) & {
356
+ define: TypeAbsorber;
357
+ lookup: TypeLookup<Registry>;
358
+ };
359
+ export type PropsType = Record<string, unknown>;
360
+ export interface UtilFunction extends CallableFunction {
361
+ (...args: never[]): unknown;
362
+ }
363
+ export interface ForkInvoker<T extends object> extends CallableFunction {
364
+ (this: object | void, ...forkArgs: unknown[]): T;
274
365
  }
275
366
  export type Proto<P extends object, T extends object> = [
276
367
  Exclude<keyof P, keyof T>
@@ -281,9 +372,6 @@ export type ProtoFlat<P extends object, T extends object, L extends Exclude<keyo
281
372
  [key in L]: P[key];
282
373
  };
283
374
  export type MnemonicaInstanceMethodKeys = 'extract' | 'pick' | 'parent' | 'clone' | 'fork' | 'exception' | 'sibling';
284
- export type Flatten<F> = {
285
- [key in keyof F]: F[key];
286
- };
287
375
  export type Extracted<T extends object> = {
288
376
  [K in keyof T as K extends string ? (K extends MnemonicaInstanceMethodKeys ? never : K) : never]: T[K];
289
377
  } & {};
@@ -303,40 +391,6 @@ export interface EmptyParsed {
303
391
  joint: {};
304
392
  parent: undefined;
305
393
  }
306
- export type LineageValue = null | boolean | string | number | LineageValue[] | {
307
- $ref: string;
308
- } | {
309
- '$mnemonica': 'unsupported';
310
- kind: string;
311
- } | {
312
- [key: string]: LineageValue;
313
- };
314
- export interface LineageTypeRef {
315
- collection: string;
316
- path: string;
317
- }
318
- export interface LineageNode {
319
- type: LineageTypeRef;
320
- own: {
321
- [key: string]: LineageValue;
322
- };
323
- parent: string | null;
324
- args?: LineageValue;
325
- props?: {
326
- [key: string]: LineageValue;
327
- };
328
- }
329
- export interface LineageGraph {
330
- version: '1';
331
- heads: string[];
332
- nodes: {
333
- [id: string]: LineageNode;
334
- };
335
- }
336
- export interface LineageOptions {
337
- args?: boolean;
338
- props?: string[];
339
- }
340
394
  export interface SiblingAccessor {
341
395
  (SiblingTypeName: string): TypeClass | undefined;
342
396
  [key: string]: TypeClass | undefined;
@@ -355,109 +409,9 @@ export interface MnemonicaInstance<T extends object = object> {
355
409
  exception(error: Error, ...args: unknown[]): Error;
356
410
  readonly sibling: SiblingAccessor;
357
411
  }
358
- export type InstanceInternalProps = {
359
- __proto_proto__: object;
360
- __args__: unknown[];
361
- __collection__: CollectionDef;
362
- __subtypes__: Map<string, object>;
363
- __type__: TypeDef;
364
- __parent__: object;
365
- __stack__?: string;
366
- __creator__: InstanceCreatorContext;
367
- __timestamp__: number;
368
- };
369
- export type Props = InstanceInternalProps & {
370
- __self__: InstanceInternalProps;
371
- [key: string]: unknown;
372
- };
373
412
  export type InstanceResult<N extends object> = {
374
413
  [K in keyof N]: N[K];
375
414
  };
376
- export interface RegistryEntry<F extends object, Path extends string = '', Parent extends object = object, Args extends unknown[] = unknown[]> extends _Internal_TC_<F, Args>, RegistryHolderBase<{}, F, Path> {
377
- registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT, Parent, F>): void;
378
- }
379
- export interface AsyncRegistryEntry<F extends object, Path extends string = '', Parent extends object = object, Args extends unknown[] = unknown[]> extends RegistryHolderBase<{}, F, Path> {
380
- new (...args: Args): Promise<F>;
381
- (this: F, ...args: Args): Promise<F>;
382
- readonly prototype: F & {
383
- readonly constructor: AsyncRegistryEntry<F, Path, Parent, Args>;
384
- };
385
- registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT, Parent, F>): void;
386
- }
387
- export interface RegistryHolderBase<T extends object = {}, Parent extends object = object, Path extends string = ''> {
388
- define<SubType extends object>(this: RegistryHolderBase<T, Parent, Path>, TypeOrTypeName: DefineNewableOrCallable, constructHandlerOrConfig?: IDEF<SubType> | object | boolean | DefineNewableOrCallable, configOrUndefined?: constructorOptions | DefineNewableOrCallable | boolean): IDefinitorInstance<SubType>;
389
- define<const Name extends string, N extends object, Args extends unknown[] = unknown[], F extends Proto<Parent, N> = Proto<Parent, N>, ChildPath extends string = Path extends '' ? Name : `${Path}.${Name}`>(this: RegistryHolderBase<T, Parent, Path>, TypeName: Name, constructHandler: (this: N, ...args: Args) => PromiseLike<unknown>, config?: constructorOptions): IDefinitorInstance<F, InstanceResult<F>, T & Record<ChildPath, AsyncRegistryEntry<F, ChildPath, Parent, Args>>, ChildPath, Parent, Args>;
390
- define<const Name extends string, N extends object, Args extends unknown[] = unknown[], F extends Proto<Parent, N> = Proto<Parent, N>, ChildPath extends string = Path extends '' ? Name : `${Path}.${Name}`>(this: RegistryHolderBase<T, Parent, Path>, TypeName: Name, constructHandler?: IDEF<N, Args>, config?: constructorOptions): IDefinitorInstance<F, InstanceResult<F>, T & Record<ChildPath, RegistryEntry<F, ChildPath, Parent, Args>>, ChildPath, Parent, Args>;
391
- lazy<const Name extends string, N extends object, Args extends unknown[], F extends Proto<Parent, N> = Proto<Parent, N>, ChildPath extends string = Path extends '' ? Name : `${Path}.${Name}`>(this: RegistryHolderBase<T, Parent, Path>, TypeName: Name, getter: () => (this: N, ...args: Args) => PromiseLike<unknown>, config?: constructorOptions): IDefinitorInstance<F, InstanceResult<F>, T & Record<ChildPath, AsyncRegistryEntry<F, ChildPath, Parent, Args>>, ChildPath, Parent, Args>;
392
- lazy<const Name extends string, N extends object, Args extends unknown[], F extends Proto<Parent, N> = Proto<Parent, N>, ChildPath extends string = Path extends '' ? Name : `${Path}.${Name}`>(this: RegistryHolderBase<T, Parent, Path>, TypeName: Name, getter: LazyDef<N, Args>, config?: constructorOptions): IDefinitorInstance<F, InstanceResult<F>, T & Record<ChildPath, RegistryEntry<F, ChildPath, Parent, Args>>, ChildPath, Parent, Args>;
393
- }
394
- export interface RegistryHolder<T extends object = {}, Parent extends object = object, Path extends string = ''> extends RegistryHolderBase<T, Parent, Path> {
395
- lookup: NestedTypeLookup<T, Path>;
396
- }
397
- export interface IDefinitorInstance<N extends object, R extends InstanceResult<N> = InstanceResult<N>, Registry extends object = GlobalRegistry, Path extends string = '', Parent extends object = object, Args extends unknown[] = unknown[]> extends RegistryHolderBase<Registry, N, Path> {
398
- TypeName: string;
399
- prototype: N;
400
- new (...args: Args): R;
401
- (...args: unknown[]): IDefinitorInstance<R>;
402
- lookup: TypeLookup<Registry>;
403
- decorate: (config?: constructorOptions) => <U extends Constructor<object>>(cstr: U) => DecoratedClass<U, Registry>;
404
- registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT, Parent, N>): void;
405
- subtypes: SubtypesMap;
406
- __type__?: TypeDef;
407
- collection?: CollectionDef;
408
- }
409
- export interface TypeAbsorber extends CallableFunction {
410
- <T extends object, Args extends unknown[] = unknown[]>(this: unknown, TypeOrTypeName: string | DefineNewableOrCallable, constructHandlerOrConfig?: IDEF<T, Args> | object | boolean | DefineNewableOrCallable, configOrUndefined?: constructorOptions | DefineNewableOrCallable | boolean): IDefinitorInstance<T, InstanceResult<T>, GlobalRegistry, '', object, Args>;
411
- }
412
- export interface LazyAbsorber extends CallableFunction {
413
- <T extends object, Args extends unknown[] = unknown[]>(this: unknown, TypeName: string, getter: LazyDef<T, Args>, config?: constructorOptions): IDefinitorInstance<T, InstanceResult<T>, GlobalRegistry, '', object, Args>;
414
- <T extends object, Args extends unknown[] = unknown[]>(this: unknown, source: RegistryHolderBase<object, object, string>, TypeName: string, getter: LazyDef<T, Args>, config?: constructorOptions): IDefinitorInstance<T, InstanceResult<T>, GlobalRegistry, '', object, Args>;
415
- }
416
- export interface TypesCollection<T extends object = {}, Parent extends object = object, Path extends string = ''> extends RegistryHolder<T, Parent, Path>, Hookable {
417
- subtypes: SubtypesMap;
418
- decorate(config?: constructorOptions): <U extends Constructor<object>>(cstr: U) => DecoratedClass<U, T & Record<ConstructorName<U>, RegistryEntry<InstanceType<U>, ConstructorName<U>>>>;
419
- [key: string]: unknown;
420
- }
421
- export interface Hookable {
422
- hooks: Record<string, Set<hook>>;
423
- invokeHook(hookType: hooksTypes, opts: hooksOpts): Set<unknown>;
424
- registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT>): void;
425
- registerFlowChecker(cb: FlowChecker): void;
426
- }
427
- export type CreateTypesCollectionFunction = <T extends object = {}, Parent extends object = object>(config?: constructorOptions) => TypesCollection<T, Parent>;
428
- export type TypeClass = IDefinitorInstance<object>;
429
- export type TypeRegistryMap = Record<string, TypeConstructorBase>;
430
- export interface MnemonicaConstructor extends NewableFunction {
431
- new (...args: unknown[]): object;
432
- (this: object, ...args: unknown[]): unknown;
433
- [key: symbol]: unknown;
434
- }
435
- export interface TypeDescriptorDefine extends CallableFunction {
436
- (TypeOrTypeName: string | DefineNewableOrCallable, constructHandlerOrConfig?: DefineNewableOrCallable | object, config?: object): TypeClass;
437
- }
438
- export interface TypeDescriptorLazy extends CallableFunction {
439
- (TypeName: string, getter: LazyDef<object>, config?: object): TypeClass;
440
- }
441
- export interface TypeDescriptorLookup extends CallableFunction {
442
- (TypeNestedPath: string): TypeClass | undefined;
443
- }
444
- export type TypeDescriptorInstance = {
445
- define: TypeDescriptorDefine;
446
- lazy: TypeDescriptorLazy;
447
- decorate: (config?: constructorOptions) => <U extends Constructor<object>>(cstr: U) => DecoratedClass<U>;
448
- lookup: TypeDescriptorLookup;
449
- subtypes: Map<string, object>;
450
- TypeName: string;
451
- collection: CollectionDef;
452
- };
453
- export type Constructor<T = object> = new (...args: never[]) => T;
454
- export type ConstructorName<T extends Constructor<object>> = T extends {
455
- name: infer N;
456
- } ? N extends string ? N : string : string;
457
- export type DecoratedClass<T extends Constructor<object>, Registry extends object = TypeRegistry> = T & Omit<IDefinitorInstance<InstanceType<T>, InstanceType<T>, Registry, ConstructorName<T>>, 'define' | 'lookup'> & (<U extends Constructor<object>>(target: U) => DecoratedClass<U, Registry>) & {
458
- define: TypeAbsorber;
459
- lookup: TypeLookup<Registry>;
460
- };
461
415
  export type Merge<E extends object, T extends object> = {
462
416
  [K in keyof T | keyof E as K extends MnemonicaInstanceMethodKeys ? never : K]: K extends keyof T ? T[K] : E[K & keyof E];
463
417
  };
@@ -479,7 +433,9 @@ export interface UtilsCollection {
479
433
  clone<T extends object>(instance: T): T;
480
434
  fork<T extends object>(instance: T): ForkInvoker<T>;
481
435
  sibling(instance: object): SiblingAccessor;
482
- collectConstructors: (instance: object, flat?: boolean) => (DefineNewableOrCallable | string)[];
436
+ collectConstructors(instance: object, asSequence: true): string[];
437
+ collectConstructors(instance: object, asSequence?: false): Record<string, boolean>;
438
+ collectConstructors(instance: object, asSequence?: boolean): string[] | Record<string, boolean>;
483
439
  merge<A extends object, B extends object>(a: A, b: B, ...args: unknown[]): InstanceResult<Merge<B, A>>;
484
440
  parse<T extends object>(self: T): Parsed<T>;
485
441
  parse(self: null): EmptyParsed;
@@ -491,6 +447,40 @@ export interface UtilsCollection {
491
447
  toJSON<T extends object>(instance: T): string;
492
448
  [key: string]: UtilFunction;
493
449
  }
450
+ export type LineageValue = null | boolean | string | number | LineageValue[] | {
451
+ $ref: string;
452
+ } | {
453
+ '$mnemonica': 'unsupported';
454
+ kind: string;
455
+ } | {
456
+ [key: string]: LineageValue;
457
+ };
458
+ export interface LineageTypeRef {
459
+ collection: string;
460
+ path: string;
461
+ }
462
+ export interface LineageNode {
463
+ type: LineageTypeRef;
464
+ own: {
465
+ [key: string]: LineageValue;
466
+ };
467
+ parent: string | null;
468
+ args?: LineageValue;
469
+ props?: {
470
+ [key: string]: LineageValue;
471
+ };
472
+ }
473
+ export interface LineageGraph {
474
+ version: '1';
475
+ heads: string[];
476
+ nodes: {
477
+ [id: string]: LineageNode;
478
+ };
479
+ }
480
+ export interface LineageOptions {
481
+ args?: boolean;
482
+ props?: string[];
483
+ }
494
484
  export interface MnemonicaModule<Registry extends object = {}> extends RegistryHolder<Registry, object> {
495
485
  apply: ApplyFunction;
496
486
  call: CallFunction;