mnemonica 1.4.7 → 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,17 +258,22 @@ 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>;
207
- export type LookedUpConstructor<Registry extends object, Path extends keyof Registry & string, CallConstructs extends boolean = false> = RegistryHolderBase<Registry, ExtractConstructorInstance<Registry[Path]>, Path> & AugmentedConstructor<Registry, Path, CallConstructs> & {
272
+ declare const TypePathKey: unique symbol;
273
+ export type TypePathMark<Path extends string> = {
274
+ readonly [TypePathKey]?: Path;
275
+ };
276
+ export type LookedUpConstructor<Registry extends object, Path extends keyof Registry & string, CallConstructs extends boolean = false> = TypePathMark<Path> & RegistryHolderBase<Registry, ExtractConstructorInstance<Registry[Path]>, Path> & AugmentedConstructor<Registry, Path, CallConstructs> & {
208
277
  lookup: NestedTypeLookup<Registry, Path>;
209
278
  };
210
279
  export type WithHookRegister<C> = C extends {
@@ -228,7 +297,6 @@ export interface TypeLookup<T extends object = GlobalRegistry> extends CallableF
228
297
  }
229
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;
230
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);
231
- export type FullKey<Registry extends object, Path extends string, K extends string> = Path extends '' ? K : Extract<keyof Registry & string, `${Path}.${K}`>;
232
300
  export type NestedTypeLookup<Registry extends object, Path extends string = ''> = (Path extends '' ? {
233
301
  <const K extends keyof Registry & string>(this: unknown, TypeNestedPath: K): LookedUpConstructor<Registry, K>;
234
302
  } : {
@@ -236,37 +304,64 @@ export type NestedTypeLookup<Registry extends object, Path extends string = ''>
236
304
  }) & {
237
305
  (this: unknown, TypeNestedPath: string): TypeClass | undefined;
238
306
  };
239
- export interface ThenSpec {
240
- subtype: object;
241
- args: unknown[];
242
- 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;
243
309
  }
244
- export interface InstanceCreatorContext {
245
- type: TypeDef;
246
- TypeName: string;
247
- existentInstance: object;
248
- args: unknown[];
249
- ModificationConstructor: ModificationConstructor;
250
- ModificatorType: MnemonicaConstructor;
251
- InstanceModificator: MnemonicaConstructor;
252
- inheritedInstance: object | Promise<object>;
253
- config: constructorOptions;
254
- proto: object;
255
- __proto_proto__?: object;
256
- stack?: string[];
257
- lazyFailed?: boolean;
258
- lazyError?: unknown;
259
- postHooksFired?: boolean;
260
- getExistentAsyncStack(existentInstance: object): unknown;
261
- postProcessing(continuationOf?: TypeDef): void;
262
- makeAwaiter(type: TypeDef, then?: ThenSpec): Promise<object>;
263
- addThen(then: ThenSpec): void;
264
- invokePreHooks(): void;
265
- invokePostHooks(): {
266
- type: Set<unknown>;
267
- 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>;
268
315
  };
269
- 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;
270
365
  }
271
366
  export type Proto<P extends object, T extends object> = [
272
367
  Exclude<keyof P, keyof T>
@@ -277,9 +372,6 @@ export type ProtoFlat<P extends object, T extends object, L extends Exclude<keyo
277
372
  [key in L]: P[key];
278
373
  };
279
374
  export type MnemonicaInstanceMethodKeys = 'extract' | 'pick' | 'parent' | 'clone' | 'fork' | 'exception' | 'sibling';
280
- export type Flatten<F> = {
281
- [key in keyof F]: F[key];
282
- };
283
375
  export type Extracted<T extends object> = {
284
376
  [K in keyof T as K extends string ? (K extends MnemonicaInstanceMethodKeys ? never : K) : never]: T[K];
285
377
  } & {};
@@ -299,40 +391,6 @@ export interface EmptyParsed {
299
391
  joint: {};
300
392
  parent: undefined;
301
393
  }
302
- export type LineageValue = null | boolean | string | number | LineageValue[] | {
303
- $ref: string;
304
- } | {
305
- '$mnemonica': 'unsupported';
306
- kind: string;
307
- } | {
308
- [key: string]: LineageValue;
309
- };
310
- export interface LineageTypeRef {
311
- collection: string;
312
- path: string;
313
- }
314
- export interface LineageNode {
315
- type: LineageTypeRef;
316
- own: {
317
- [key: string]: LineageValue;
318
- };
319
- parent: string | null;
320
- args?: LineageValue;
321
- props?: {
322
- [key: string]: LineageValue;
323
- };
324
- }
325
- export interface LineageGraph {
326
- version: '1';
327
- heads: string[];
328
- nodes: {
329
- [id: string]: LineageNode;
330
- };
331
- }
332
- export interface LineageOptions {
333
- args?: boolean;
334
- props?: string[];
335
- }
336
394
  export interface SiblingAccessor {
337
395
  (SiblingTypeName: string): TypeClass | undefined;
338
396
  [key: string]: TypeClass | undefined;
@@ -351,109 +409,9 @@ export interface MnemonicaInstance<T extends object = object> {
351
409
  exception(error: Error, ...args: unknown[]): Error;
352
410
  readonly sibling: SiblingAccessor;
353
411
  }
354
- export type InstanceInternalProps = {
355
- __proto_proto__: object;
356
- __args__: unknown[];
357
- __collection__: CollectionDef;
358
- __subtypes__: Map<string, object>;
359
- __type__: TypeDef;
360
- __parent__: object;
361
- __stack__?: string;
362
- __creator__: InstanceCreatorContext;
363
- __timestamp__: number;
364
- };
365
- export type Props = InstanceInternalProps & {
366
- __self__: InstanceInternalProps;
367
- [key: string]: unknown;
368
- };
369
412
  export type InstanceResult<N extends object> = {
370
413
  [K in keyof N]: N[K];
371
414
  };
372
- 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> {
373
- registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT, Parent, F>): void;
374
- }
375
- export interface AsyncRegistryEntry<F extends object, Path extends string = '', Parent extends object = object, Args extends unknown[] = unknown[]> extends RegistryHolderBase<{}, F, Path> {
376
- new (...args: Args): Promise<F>;
377
- (this: F, ...args: Args): Promise<F>;
378
- readonly prototype: F & {
379
- readonly constructor: AsyncRegistryEntry<F, Path, Parent, Args>;
380
- };
381
- registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT, Parent, F>): void;
382
- }
383
- export interface RegistryHolderBase<T extends object = {}, Parent extends object = object, Path extends string = ''> {
384
- define<SubType extends object>(this: RegistryHolderBase<T, Parent, Path>, TypeOrTypeName: DefineNewableOrCallable, constructHandlerOrConfig?: IDEF<SubType> | object | boolean | DefineNewableOrCallable, configOrUndefined?: constructorOptions | DefineNewableOrCallable | boolean): IDefinitorInstance<SubType>;
385
- 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>;
386
- 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>;
387
- 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>;
388
- 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>;
389
- }
390
- export interface RegistryHolder<T extends object = {}, Parent extends object = object, Path extends string = ''> extends RegistryHolderBase<T, Parent, Path> {
391
- lookup: NestedTypeLookup<T, Path>;
392
- }
393
- 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> {
394
- TypeName: string;
395
- prototype: N;
396
- new (...args: Args): R;
397
- (...args: unknown[]): IDefinitorInstance<R>;
398
- lookup: TypeLookup<Registry>;
399
- decorate: (config?: constructorOptions) => <U extends Constructor<object>>(cstr: U) => DecoratedClass<U, Registry>;
400
- registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT, Parent, N>): void;
401
- subtypes: SubtypesMap;
402
- __type__?: TypeDef;
403
- collection?: CollectionDef;
404
- }
405
- export interface TypeAbsorber extends CallableFunction {
406
- <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>;
407
- }
408
- export interface LazyAbsorber extends CallableFunction {
409
- <T extends object, Args extends unknown[] = unknown[]>(this: unknown, TypeName: string, getter: LazyDef<T, Args>, config?: constructorOptions): IDefinitorInstance<T, InstanceResult<T>, GlobalRegistry, '', object, Args>;
410
- <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>;
411
- }
412
- export interface TypesCollection<T extends object = {}, Parent extends object = object, Path extends string = ''> extends RegistryHolder<T, Parent, Path>, Hookable {
413
- subtypes: SubtypesMap;
414
- decorate(config?: constructorOptions): <U extends Constructor<object>>(cstr: U) => DecoratedClass<U, T & Record<ConstructorName<U>, RegistryEntry<InstanceType<U>, ConstructorName<U>>>>;
415
- [key: string]: unknown;
416
- }
417
- export interface Hookable {
418
- hooks: Record<string, Set<hook>>;
419
- invokeHook(hookType: hooksTypes, opts: hooksOpts): Set<unknown>;
420
- registerHook<HT extends hooksTypes>(hookType: HT, cb: typedHook<HT>): void;
421
- registerFlowChecker(cb: FlowChecker): void;
422
- }
423
- export type CreateTypesCollectionFunction = <T extends object = {}, Parent extends object = object>(config?: constructorOptions) => TypesCollection<T, Parent>;
424
- export type TypeClass = IDefinitorInstance<object>;
425
- export type TypeRegistryMap = Record<string, TypeConstructorBase>;
426
- export interface MnemonicaConstructor extends NewableFunction {
427
- new (...args: unknown[]): object;
428
- (this: object, ...args: unknown[]): unknown;
429
- [key: symbol]: unknown;
430
- }
431
- export interface TypeDescriptorDefine extends CallableFunction {
432
- (TypeOrTypeName: string | DefineNewableOrCallable, constructHandlerOrConfig?: DefineNewableOrCallable | object, config?: object): TypeClass;
433
- }
434
- export interface TypeDescriptorLazy extends CallableFunction {
435
- (TypeName: string, getter: LazyDef<object>, config?: object): TypeClass;
436
- }
437
- export interface TypeDescriptorLookup extends CallableFunction {
438
- (TypeNestedPath: string): TypeClass | undefined;
439
- }
440
- export type TypeDescriptorInstance = {
441
- define: TypeDescriptorDefine;
442
- lazy: TypeDescriptorLazy;
443
- decorate: (config?: constructorOptions) => <U extends Constructor<object>>(cstr: U) => DecoratedClass<U>;
444
- lookup: TypeDescriptorLookup;
445
- subtypes: Map<string, object>;
446
- TypeName: string;
447
- collection: CollectionDef;
448
- };
449
- export type Constructor<T = object> = new (...args: never[]) => T;
450
- export type ConstructorName<T extends Constructor<object>> = T extends {
451
- name: infer N;
452
- } ? N extends string ? N : string : string;
453
- 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>) & {
454
- define: TypeAbsorber;
455
- lookup: TypeLookup<Registry>;
456
- };
457
415
  export type Merge<E extends object, T extends object> = {
458
416
  [K in keyof T | keyof E as K extends MnemonicaInstanceMethodKeys ? never : K]: K extends keyof T ? T[K] : E[K & keyof E];
459
417
  };
@@ -475,7 +433,9 @@ export interface UtilsCollection {
475
433
  clone<T extends object>(instance: T): T;
476
434
  fork<T extends object>(instance: T): ForkInvoker<T>;
477
435
  sibling(instance: object): SiblingAccessor;
478
- 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>;
479
439
  merge<A extends object, B extends object>(a: A, b: B, ...args: unknown[]): InstanceResult<Merge<B, A>>;
480
440
  parse<T extends object>(self: T): Parsed<T>;
481
441
  parse(self: null): EmptyParsed;
@@ -487,6 +447,40 @@ export interface UtilsCollection {
487
447
  toJSON<T extends object>(instance: T): string;
488
448
  [key: string]: UtilFunction;
489
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
+ }
490
484
  export interface MnemonicaModule<Registry extends object = {}> extends RegistryHolder<Registry, object> {
491
485
  apply: ApplyFunction;
492
486
  call: CallFunction;
@@ -523,3 +517,4 @@ export interface MnemonicaModule<Registry extends object = {}> extends RegistryH
523
517
  createTypesCollection: CreateTypesCollectionFunction;
524
518
  [key: string]: unknown;
525
519
  }
520
+ export {};