mnemonica 1.4.8 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FOR_HUMANS.md +95 -31
- package/README.md +10 -9
- package/SKILL.md +4 -4
- package/build/api/hooks/hookTypes.d.ts +2 -0
- package/build/api/hooks/hookTypes.js +25 -0
- package/build/api/hooks/index.d.ts +2 -1
- package/build/api/hooks/index.js +6 -2
- package/build/api/hooks/registerHook.d.ts +1 -1
- package/build/api/hooks/registerHook.js +4 -15
- package/build/api/hooks/unregisterHook.d.ts +2 -0
- package/build/api/hooks/unregisterHook.js +18 -0
- package/build/api/index.d.ts +4 -3
- package/build/api/index.js +2 -1
- package/build/api/types/compileNewModificatorFunctionBody.d.ts +4 -2
- package/build/api/types/compileNewModificatorFunctionBody.js +16 -7
- package/build/api/types/index.d.ts +2 -2
- package/build/api/types/index.js +21 -18
- package/build/api/utils/index.d.ts +1 -2
- package/build/api/utils/index.js +37 -13
- package/build/descriptors/types/index.js +19 -12
- package/build/index.d.ts +25 -17
- package/build/index.js +35 -50
- package/build/types/index.d.ts +242 -225
- package/build/types/index.js +1 -1
- package/docs/UTILS.md +4 -5
- package/docs/async-constructors.md +32 -13
- package/docs/hott-correspondence.md +1 -1
- package/docs/typed-lookup.md +31 -37
- package/module/index.js +2 -0
- package/package.json +2 -2
- package/src/api/hooks/hookTypes.ts +37 -0
- package/src/api/hooks/index.ts +8 -1
- package/src/api/hooks/registerHook.ts +6 -19
- package/src/api/hooks/unregisterHook.ts +36 -0
- package/src/api/index.ts +2 -0
- package/src/api/types/compileNewModificatorFunctionBody.ts +79 -18
- package/src/api/types/index.ts +64 -54
- package/src/api/utils/index.ts +5 -51
- package/src/descriptors/types/index.ts +31 -22
- package/src/index.ts +271 -161
- package/src/types/index.ts +812 -590
package/FOR_HUMANS.md
CHANGED
|
@@ -238,11 +238,11 @@ const SomeType = define('SomeType', function (opts) {
|
|
|
238
238
|
Object.assign(this, opts);
|
|
239
239
|
});
|
|
240
240
|
|
|
241
|
-
// A named function as the
|
|
242
|
-
// the type name is taken from
|
|
241
|
+
// A named function or class as the first argument also works —
|
|
242
|
+
// the type name is taken from its .name, and the config comes second
|
|
243
243
|
const AnotherType = define(function AnotherType(opts) {
|
|
244
244
|
Object.assign(this, opts);
|
|
245
|
-
});
|
|
245
|
+
}, { strictChain: false });
|
|
246
246
|
```
|
|
247
247
|
|
|
248
248
|
Note what does **not** work: passing an *anonymous* function as the first
|
|
@@ -279,11 +279,9 @@ reference.
|
|
|
279
279
|
// Define nested types
|
|
280
280
|
SomeType.define('SubType', function (opts) {
|
|
281
281
|
this.other = opts.other;
|
|
282
|
-
}, {
|
|
283
|
-
description: 'SomeSubType Constructor'
|
|
284
282
|
});
|
|
285
283
|
|
|
286
|
-
// Or using assignment
|
|
284
|
+
// Or using assignment, instead of the define() above
|
|
287
285
|
SomeType.SubType = function (opts) {
|
|
288
286
|
this.other = opts.other;
|
|
289
287
|
};
|
|
@@ -316,7 +314,7 @@ Extract all inherited properties into a flat object:
|
|
|
316
314
|
```js
|
|
317
315
|
const { utils: { extract } } = require('mnemonica');
|
|
318
316
|
const extracted = extract(subInstance);
|
|
319
|
-
// Result: { data,
|
|
317
|
+
// Result: { data, other, some } — and description, when SubType is made by assignment
|
|
320
318
|
```
|
|
321
319
|
|
|
322
320
|
---
|
|
@@ -471,7 +469,10 @@ import {
|
|
|
471
469
|
IDEF, // Base constructor function type
|
|
472
470
|
LazyDef, // Zero-arg callback returning a constructor (for lazy())
|
|
473
471
|
constructorOptions, // Type config options (strictChain, blockErrors, etc.)
|
|
472
|
+
DefineConfig, // what define() takes as config: the options, a boolean or a function
|
|
474
473
|
hooksTypes, // 'preCreation' | 'postCreation' | 'creationError'
|
|
474
|
+
hookName, // hooksTypes and the short names 'pre' | 'post' | 'error'
|
|
475
|
+
HookMethods, // registerHook / unregisterHook / on / off of a type or collection
|
|
475
476
|
hook, // Hook callback type (untyped — collection-wide handlers)
|
|
476
477
|
typedHook, // Hook callback typed by hookType + parent/instance pair
|
|
477
478
|
typedHookOpts, // Hook options object typed per hookType
|
|
@@ -479,7 +480,7 @@ import {
|
|
|
479
480
|
} from 'mnemonica';
|
|
480
481
|
```
|
|
481
482
|
|
|
482
|
-
Additional types available: `Constructor`, `TypeConstructor`, `TypeConstructorBase`, `Proto`, `ProtoFlat`, `InstanceResult`, `Merge`, `IDefinitorInstance`, `DecoratedClass`, `hooksOpts`, `WithHookRegister`, `HookableConstructor`, `TypesCollection`, `TypeLookup`, `LookupResult`, `RegistryOf`, `MnemonicaModule`, `TypeAbsorber`, and the `TypeRegistry` interface (for augmentation). See [`src/types/index.ts`](./src/types/index.ts) for full definitions.
|
|
483
|
+
Additional types available: `CtorParameter`, `Constructor`, `AnyConstructor`, `TypeConstructor`, `TypeConstructorBase`, `Proto`, `ProtoFlat`, `InstanceResult`, `Merge`, `IDefinitorInstance`, `DecoratedClass`, `hooksOpts`, `deliveredHookOpts`, `WithHookRegister`, `HookableConstructor`, `TypesCollection`, `TypeLookup`, `LookupResult`, `FreeLookupResult`, `RegistryOf`, `RegistryEntry`, `AsyncRegistryEntry`, `LookedUpConstructor`, `LookedUpInstance`, `MnemonicaModule`, `TypeAbsorber`, `CreationError`, `ErrorProps`, and the `TypeRegistry` interface (for augmentation). See [`src/types/index.ts`](./src/types/index.ts) for full definitions.
|
|
483
484
|
|
|
484
485
|
### Generic Type Patterns
|
|
485
486
|
|
|
@@ -518,7 +519,7 @@ const AsyncType = define('AsyncType', async function (this: UserData, data: stri
|
|
|
518
519
|
});
|
|
519
520
|
|
|
520
521
|
// With explicit unchain option (no return required)
|
|
521
|
-
const AsyncTypeNoReturn = define('
|
|
522
|
+
const AsyncTypeNoReturn = define('AsyncTypeNoReturn', async function () {
|
|
522
523
|
// No return needed
|
|
523
524
|
}, { unchain: true });
|
|
524
525
|
```
|
|
@@ -546,7 +547,17 @@ const AsyncTypeNoReturn = define('AsyncType', async function () {
|
|
|
546
547
|
|
|
547
548
|
#### `define(typeName, constructHandler, config?)`
|
|
548
549
|
|
|
549
|
-
Defines a new type constructor. Returns a TypeClass.
|
|
550
|
+
Defines a new type constructor. Returns a TypeClass. Three forms, the same for
|
|
551
|
+
the free `define`, a collection and a type:
|
|
552
|
+
|
|
553
|
+
| Form | Type name |
|
|
554
|
+
|---|---|
|
|
555
|
+
| `define(typeName, constructHandler, config?)` | `typeName` |
|
|
556
|
+
| `define(typeName, config?)` | `typeName`, with no handler |
|
|
557
|
+
| `define(constructHandler, config?)` | the function's or class's own `.name` |
|
|
558
|
+
|
|
559
|
+
The config is always the last argument: nothing after it is read, and
|
|
560
|
+
TypeScript reports it as an error.
|
|
550
561
|
|
|
551
562
|
```js
|
|
552
563
|
const MyType = define('MyType', function (data) {
|
|
@@ -558,9 +569,9 @@ const MyType = define('MyType', function (data) {
|
|
|
558
569
|
```
|
|
559
570
|
|
|
560
571
|
**Parameters:**
|
|
561
|
-
- `typeName` (string): Name of the type. Must be non-empty, start with an uppercase letter, and must not be one of the reserved names `Mnemonica` or `Mnemosyne`. May be a nested path (`'Parent.Child'`) to define a subtype under an existing type.
|
|
562
|
-
- `constructHandler` (Function): Constructor function
|
|
563
|
-
- `config` (object, optional): Configuration options
|
|
572
|
+
- `typeName` (string): Name of the type. Must be non-empty, start with an uppercase letter, and must not be one of the reserved names `Mnemonica` or `Mnemosyne`. May be a nested path (`'Parent.Child'`) to define a subtype under an existing type. Without it, the first argument is a *named* function or class; an anonymous one throws `TYPENAME_MUST_BE_A_STRING`.
|
|
573
|
+
- `constructHandler` (Function): Constructor function or class
|
|
574
|
+
- `config` (object, boolean or function, optional): [Configuration options](#configuration-options)
|
|
564
575
|
|
|
565
576
|
#### `lazy(typeName, callback, config?)`
|
|
566
577
|
|
|
@@ -603,7 +614,7 @@ const SubType = MyType.lazy('SubType', () => function (data) {
|
|
|
603
614
|
**Parameters:**
|
|
604
615
|
- `typeName` (string, required): Name of the type. The unnamed form was removed — the callback is never called at definition time, so there is nothing to derive a name from.
|
|
605
616
|
- `callback` (Function): Zero-arg sync function returning the constructor; called once per construction.
|
|
606
|
-
- `config` (object, optional): Configuration options
|
|
617
|
+
- `config` (object, boolean or function, optional): [Configuration options](#configuration-options)
|
|
607
618
|
|
|
608
619
|
#### `lookup(typeNestedPath)`
|
|
609
620
|
|
|
@@ -649,7 +660,11 @@ Then include the generated types in your project. See [`docs/typed-lookup.md`](.
|
|
|
649
660
|
|
|
650
661
|
#### `apply(entity, Constructor, args?)`
|
|
651
662
|
|
|
652
|
-
Applies a constructor to an entity with an array of arguments.
|
|
663
|
+
Applies a constructor to an entity with an array of arguments. Here, and in
|
|
664
|
+
`call` and `bind`, the constructor is what `define()`, `lookup()` or
|
|
665
|
+
`@decorate()` gives, and the entity is a mnemonica instance: a plain object,
|
|
666
|
+
class or function in their place throws `WRONG_MODIFICATION_PATTERN`. A plain
|
|
667
|
+
function as the constructor is also a compile error.
|
|
653
668
|
|
|
654
669
|
```js
|
|
655
670
|
const { apply } = require('mnemonica');
|
|
@@ -712,6 +727,20 @@ registerHook(MyType, 'postCreation', (opts) => {
|
|
|
712
727
|
});
|
|
713
728
|
```
|
|
714
729
|
|
|
730
|
+
#### `unregisterHook(Constructor, hookType, callback)`
|
|
731
|
+
|
|
732
|
+
Removes exactly the given callback, matched by reference, and returns whether
|
|
733
|
+
it was registered:
|
|
734
|
+
|
|
735
|
+
```js
|
|
736
|
+
const { registerHook, unregisterHook } = require('mnemonica');
|
|
737
|
+
|
|
738
|
+
const onCreated = (hookData) => { /* … */ };
|
|
739
|
+
registerHook(MyType, 'postCreation', onCreated);
|
|
740
|
+
unregisterHook(MyType, 'postCreation', onCreated); // true
|
|
741
|
+
unregisterHook(MyType, 'postCreation', onCreated); // false
|
|
742
|
+
```
|
|
743
|
+
|
|
715
744
|
---
|
|
716
745
|
|
|
717
746
|
### Type Reference
|
|
@@ -725,9 +754,11 @@ For advanced TypeScript usage, the following types are exported from `mnemonica`
|
|
|
725
754
|
| `TypeConstructor<T>` | Registry-stored constructor type | What an augmented `TypeRegistry` maps paths to |
|
|
726
755
|
| `TypeClass` | Base type constructor | `const MyType: TypeClass = define(...)` |
|
|
727
756
|
| `DecoratedClass<T>` | Decorated class type | `@decorate() class MyClass {}` (see [`docs/decorate.md`](./docs/decorate.md)) |
|
|
728
|
-
| `IDefinitorInstance<N, R, Registry, Path, Parent>` | Constructor with subtypes | Returned by `define()` with `.define()` method; `Parent` types hook callbacks' `existentInstance` |
|
|
757
|
+
| `IDefinitorInstance<N, R, Registry, Path, Parent, Args, New>` | Constructor with subtypes | Returned by `define()` with `.define()` method; `Parent` types hook callbacks' `existentInstance`, `Args` the construction arguments, `New` what `new` gives (the instance, or its Promise for an async handler) |
|
|
729
758
|
| `constructorOptions` | Configuration options | `{ strictChain: true, blockErrors: true }` |
|
|
730
759
|
| `hooksTypes` | Hook type literals | `'preCreation' \| 'postCreation' \| 'creationError'` |
|
|
760
|
+
| `hookName` | Hook types and their short names | `hooksTypes \| 'pre' \| 'post' \| 'error'` |
|
|
761
|
+
| `HookMethods<P, T>` | Registering methods of a type or collection | `registerHook` / `unregisterHook` / `on` / `off` |
|
|
731
762
|
| `hook` | Hook callback type (stored/invoked) | `(opts: deliveredHookOpts) => unknown` — the payload callbacks receive |
|
|
732
763
|
| `hooksOpts` | Hook options object (invokeHook input) | Carries `creator`; HookInvocation converts it to the delivered payload |
|
|
733
764
|
| `deliveredHookOpts` | Delivered hook payload | What `HookInvocation.build()` hands to callbacks; NOT split per hook — `inheritedInstance` and `throwModificationError` are both optional (a manual `invokeHook` may deliver a partial payload) |
|
|
@@ -770,7 +801,7 @@ Creates a new **isolated** types collection. Types defined in one collection are
|
|
|
770
801
|
|
|
771
802
|
> **Important:** Collections have **no global registry**. Once you create one, you must pass the pointer around yourself. If you lose the reference, the collection and its types are unreachable. This is boilerplate you pay for isolation.
|
|
772
803
|
>
|
|
773
|
-
> Every collection **does** carry a name — for lineage exports (`utils.lineage` reports `type.collection`). Name it explicitly with `createTypesCollection({ name: '
|
|
804
|
+
> Every collection **does** carry a name — for lineage exports (`utils.lineage` reports `type.collection`). Name it explicitly with `createTypesCollection({ name: 'widgets' })`; unnamed collections get an automatic unique one (`collection_1`, `collection_2`, … in creation order; the default collection exports as `'defaultTypes'`). `name` is a collection option only — `define('T', fn, { name: 'x' })` is rejected with a readable error.
|
|
774
805
|
|
|
775
806
|
```js
|
|
776
807
|
const { createTypesCollection } = require('mnemonica');
|
|
@@ -791,26 +822,37 @@ const FoundType = myCollection.lookup('MyType');
|
|
|
791
822
|
interface TypesCollection {
|
|
792
823
|
// Define a new type in this collection
|
|
793
824
|
define: TypeAbsorber;
|
|
794
|
-
|
|
825
|
+
|
|
826
|
+
// Define a type whose constructor is resolved per construction
|
|
827
|
+
lazy: LazyAbsorber;
|
|
828
|
+
|
|
829
|
+
// Class decorator bound to this collection: .decorate() or .decorate(config)
|
|
830
|
+
decorate: (config?: constructorOptions) => ClassDecorator;
|
|
831
|
+
|
|
795
832
|
// Look up a type by its nested path (e.g., 'TypeName.SubType')
|
|
796
833
|
lookup: (path: string) => TypeClass | undefined;
|
|
797
834
|
|
|
798
835
|
// Register a hook for all types in this collection
|
|
799
|
-
// (
|
|
800
|
-
registerHook(hookType:
|
|
836
|
+
// (opts are split per hookType; instance fields are object — narrow with instanceof lookup(...))
|
|
837
|
+
registerHook<HT extends hookName>(hookType: HT, callback: typedHook<HT>): void;
|
|
838
|
+
on<HT extends hookName>(hookType: HT, callback: typedHook<HT>): void; // the same function
|
|
839
|
+
|
|
840
|
+
// Remove a callback; true when it was registered
|
|
841
|
+
unregisterHook(hookType: hookName, callback: AnyHookCallback): boolean;
|
|
842
|
+
off(hookType: hookName, callback: AnyHookCallback): boolean; // the same function
|
|
801
843
|
|
|
802
844
|
// Invoke hooks manually (advanced usage)
|
|
803
|
-
invokeHook(hookType: hooksTypes, opts: hooksOpts):
|
|
845
|
+
invokeHook(hookType: hooksTypes, opts: hooksOpts): Set<unknown>;
|
|
804
846
|
|
|
805
847
|
// Register a flow checker that runs after the hook callbacks,
|
|
806
848
|
// receiving their invocation results
|
|
807
|
-
registerFlowChecker(callback: () => unknown): void;
|
|
849
|
+
registerFlowChecker(callback: (opts: object) => unknown): void;
|
|
808
850
|
|
|
809
851
|
// Map of all types defined in this collection
|
|
810
852
|
subtypes: Map<string, TypeClass>;
|
|
811
853
|
|
|
812
854
|
// Registered hooks for this collection
|
|
813
|
-
hooks: Record<string, hook
|
|
855
|
+
hooks: Record<string, Set<hook>>;
|
|
814
856
|
}
|
|
815
857
|
```
|
|
816
858
|
|
|
@@ -841,8 +883,7 @@ const FoundType = myCollection.lookup('MyType');
|
|
|
841
883
|
|
|
842
884
|
Only known option keys are applied to a collection: unknown keys are
|
|
843
885
|
silently dropped, and a value whose type does not match the option's default
|
|
844
|
-
falls back to that default.
|
|
845
|
-
it is not part of the collection-level defaults and is ignored here.
|
|
886
|
+
falls back to that default.
|
|
846
887
|
|
|
847
888
|
#### `getProps(instance)` / `setProps(instance, values)`
|
|
848
889
|
|
|
@@ -1034,7 +1075,7 @@ explicit `<T>` cast is required for ordinary use.
|
|
|
1034
1075
|
| `utils.extract(instance)` | `Extracted<T>` — plain user-field object |
|
|
1035
1076
|
| `utils.pick(instance, 'a', 'b')` | `{ a: T['a'], b: T['b'] }` |
|
|
1036
1077
|
| `utils.clone(instance)` | `T` |
|
|
1037
|
-
| `utils.fork(instance)` | `(this: object, ...
|
|
1078
|
+
| `utils.fork(instance)` | `ForkInvoker<T>` — `(this: object \| void, ...forkArgs: unknown[]) => T` |
|
|
1038
1079
|
| `utils.parent(instance, path?)` | `object \| null` (no path); `object \| undefined` (path form) |
|
|
1039
1080
|
| `utils.sibling(instance)` | `SiblingAccessor` |
|
|
1040
1081
|
| `utils.merge(A, B, ...args)` | `InstanceResult<Merge<B, A>>` |
|
|
@@ -1127,6 +1168,23 @@ defaultTypes.registerHook('postCreation', (hookData) => {
|
|
|
1127
1168
|
});
|
|
1128
1169
|
```
|
|
1129
1170
|
|
|
1171
|
+
#### `unregisterHook(hookType, callback)`, `on` and `off`
|
|
1172
|
+
|
|
1173
|
+
On types and on collections. `unregisterHook` removes exactly the given
|
|
1174
|
+
callback, by reference, and returns whether it was registered. `on` and `off`
|
|
1175
|
+
are `registerHook` and `unregisterHook` under short names. All four take the
|
|
1176
|
+
full hook names or the short ones: `pre` (`preCreation`), `post`
|
|
1177
|
+
(`postCreation`) and `error` (`creationError`). A callback may remove itself
|
|
1178
|
+
while it runs.
|
|
1179
|
+
|
|
1180
|
+
```js
|
|
1181
|
+
const logCreated = (hookData) => {
|
|
1182
|
+
console.log('Created:', hookData.inheritedInstance.constructor.name);
|
|
1183
|
+
};
|
|
1184
|
+
MyType.on('post', logCreated);
|
|
1185
|
+
MyType.off('post', logCreated); // true
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1130
1188
|
#### `collection.registerFlowChecker(callback)`
|
|
1131
1189
|
|
|
1132
1190
|
Register a flow checker that runs after the hook callbacks of one
|
|
@@ -1296,7 +1354,8 @@ const {
|
|
|
1296
1354
|
|
|
1297
1355
|
## Configuration Options
|
|
1298
1356
|
|
|
1299
|
-
Pass options as the
|
|
1357
|
+
Pass options as the last argument to `define()`, after the handler or, with no
|
|
1358
|
+
handler, after the name:
|
|
1300
1359
|
|
|
1301
1360
|
```js
|
|
1302
1361
|
define('SomeType', function () {}, {
|
|
@@ -1304,8 +1363,7 @@ define('SomeType', function () {}, {
|
|
|
1304
1363
|
blockErrors: true, // Disallow construction if error in prototype chain
|
|
1305
1364
|
submitStack: false, // Collect stack trace as __stack__ property
|
|
1306
1365
|
unchain: false, // Ensure await new Constructor() resolves to the instance
|
|
1307
|
-
ModificationConstructor: fn
|
|
1308
|
-
asClass: false // Force class mode (auto-detected by default)
|
|
1366
|
+
ModificationConstructor: fn // Custom modification constructor
|
|
1309
1367
|
});
|
|
1310
1368
|
```
|
|
1311
1369
|
|
|
@@ -1317,8 +1375,14 @@ define('SomeType', function () {}, {
|
|
|
1317
1375
|
| `blockErrors` | `boolean` | `true` | If `true`, prevents construction when errors exist in the prototype chain. |
|
|
1318
1376
|
| `submitStack` | `boolean` | `false` | If `true`, collects stack trace and stores as `__stack__` property on instances. |
|
|
1319
1377
|
| `unchain` | `boolean` | `false` | For async constructors: `false` (default) requires the construction to resolve to its instance; `true` drops the chain on a non-object result — that value is the result. |
|
|
1320
|
-
| `
|
|
1321
|
-
|
|
1378
|
+
| `ModificationConstructor` | `Function` | built-in | Factory of the function that wires the prototype chain of a new instance. |
|
|
1379
|
+
|
|
1380
|
+
In the config place `true` / `false` is `strictChain` alone, and a function after
|
|
1381
|
+
the handler is `ModificationConstructor` alone:
|
|
1382
|
+
|
|
1383
|
+
```js
|
|
1384
|
+
define('SomeType', function () {}, false); // { strictChain: false }
|
|
1385
|
+
```
|
|
1322
1386
|
|
|
1323
1387
|
### What `strictChain` actually guards
|
|
1324
1388
|
|
package/README.md
CHANGED
|
@@ -178,13 +178,13 @@ const engineer = new alice.Employee({ role: 'Engineer' });
|
|
|
178
178
|
SuperAdminType
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
-
In mnemonica
|
|
181
|
+
In mnemonica:
|
|
182
182
|
|
|
183
|
-
-
|
|
184
|
-
-
|
|
185
|
-
-
|
|
183
|
+
- **A subtype cannot be created from the wrong parent** — `strictChain: true` (the default) rejects the construction.
|
|
184
|
+
- **Every construction gets its own prototype level.** `instance.constructor.prototype` is that exact level of the chain: a member added to it is seen by that instance and by everything constructed from it, and by no other instance. Assigning a new object to `instance.constructor.prototype` does not change the existing chain.
|
|
185
|
+
- **One handler may define several types.** The types stay distinct, and so do the levels of their instances; only the handler's own `.prototype` object is shared. A root instance has that object in its chain, so a member added to it later is seen by existing instances too; a subtype gets a copy of its members at construction (see [`docs/prototype-chain.md`](./docs/prototype-chain.md#root-and-subtype-differ-here)).
|
|
186
186
|
|
|
187
|
-
These
|
|
187
|
+
These rules are not arbitrary. They are runtime enforcement of the identity-as-path discipline that HoTT inspired: a path is determined by its endpoints and the specific steps taken, not by arbitrary identifications.
|
|
188
188
|
|
|
189
189
|
---
|
|
190
190
|
|
|
@@ -217,8 +217,9 @@ const ResponseData = PageData.define('ResponseData', function (this: { statusCod
|
|
|
217
217
|
// Hook: validate at each transition
|
|
218
218
|
defaultTypes.registerHook('preCreation', (hookData) => {
|
|
219
219
|
if (hookData.TypeName === 'PageData') {
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
// existentInstance is the parent: the RouteData this page is made from
|
|
221
|
+
const { pagePath } = hookData.existentInstance as { pagePath?: string };
|
|
222
|
+
if (!pagePath) throw new Error('PageData requires pagePath');
|
|
222
223
|
}
|
|
223
224
|
});
|
|
224
225
|
|
|
@@ -286,7 +287,7 @@ The full API reference — every signature, config option, hook data shape, the
|
|
|
286
287
|
|
|
287
288
|
| Area | Where |
|
|
288
289
|
|---|---|
|
|
289
|
-
| Core API: `define`, `lazy`, `lookup`, `apply`/`call`/`bind`, `decorate`, `getProps`/`setProps`, `registerHook` | [`FOR_HUMANS.md`](./FOR_HUMANS.md) API reference |
|
|
290
|
+
| Core API: `define`, `lazy`, `lookup`, `apply`/`call`/`bind`, `decorate`, `getProps`/`setProps`, `registerHook`/`unregisterHook` | [`FOR_HUMANS.md`](./FOR_HUMANS.md) API reference |
|
|
290
291
|
| Instance utilities (`utils.extract`, `pick`, `parent`, `fork`, `exception`, …) | [`docs/UTILS.md`](./docs/UTILS.md) |
|
|
291
292
|
| Typed `lookup()`/`define()` — builder, bridge, tactica | [`docs/typed-lookup.md`](./docs/typed-lookup.md) |
|
|
292
293
|
| `@decorate()` class-based definitions | [`docs/decorate.md`](./docs/decorate.md) |
|
|
@@ -363,7 +364,7 @@ surrounding toolchain.
|
|
|
363
364
|
4. [`.ai/PROTOTYPE-CHAIN.md`](https://github.com/wentout/mnemonica/blob/master/.ai/PROTOTYPE-CHAIN.md) — the exact chain shape, the construction pipeline, and how subtype lookup walks it
|
|
364
365
|
5. [`.ai/`](https://github.com/wentout/mnemonica/tree/master/.ai) — the focused `rules-*.md` files (define patterns, type system, hooks, errors, testing, style) and session notes from prior agents
|
|
365
366
|
|
|
366
|
-
The full TypeScript source is in [`src/`](./src/) (
|
|
367
|
+
The full TypeScript source is in [`src/`](./src/) (shipped in the npm package too, beside the compiled output in `build/` and `module/`).
|
|
367
368
|
|
|
368
369
|
---
|
|
369
370
|
|
package/SKILL.md
CHANGED
|
@@ -177,10 +177,10 @@ almost always one of:
|
|
|
177
177
|
|
|
178
178
|
| Need | API | Read |
|
|
179
179
|
|---|---|---|
|
|
180
|
-
| Declare / find types | `define`, `lazy`, `lookup`, `createTypesCollection
|
|
181
|
-
| Construct on an existing
|
|
182
|
-
| React to construction | `
|
|
183
|
-
| Async constructors | `await new Type(…)`, `unchain` | [docs/async-constructors.md](./docs/async-constructors.md) |
|
|
180
|
+
| Declare / find types | `define('Name', handler, config?)`, `define(NamedFnOrClass, config?)`, `define('Name', config?)`; `lazy`, `lookup`, `createTypesCollection`. The config is always last | [FOR_HUMANS.md](./FOR_HUMANS.md) API reference |
|
|
181
|
+
| Construct on an existing mnemonica instance | `apply`, `call`, `bind` — mnemonica constructors only | [FOR_HUMANS.md](./FOR_HUMANS.md) |
|
|
182
|
+
| React to construction | `Type.on('pre' \| 'post' \| 'error', cb)`, `Type.off(…)` — short for `registerHook` / `unregisterHook` with `'preCreation'` / `'postCreation'` / `'creationError'`; the same on collections | [FOR_HUMANS.md](./FOR_HUMANS.md) |
|
|
183
|
+
| Async constructors | `await new Type(…)`, typed as a Promise for an `async function` handler; `unchain` | [docs/async-constructors.md](./docs/async-constructors.md) |
|
|
184
184
|
| Type config | `strictChain`, `blockErrors`, … | [FOR_HUMANS.md](./FOR_HUMANS.md) |
|
|
185
185
|
| Read lineage / data | `getProps`, `utils.extract`, `pick`, `parent`, `fork` | [docs/UTILS.md](./docs/UTILS.md) |
|
|
186
186
|
| What sits under an instance | — | [docs/prototype-chain.md](./docs/prototype-chain.md) |
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveHookType = void 0;
|
|
4
|
+
const errors_1 = require("../../descriptors/errors");
|
|
5
|
+
const { WRONG_HOOK_TYPE, MISSING_HOOK_CALLBACK, } = errors_1.ErrorsTypes;
|
|
6
|
+
const hookTypes = new Map([
|
|
7
|
+
['preCreation', 'preCreation'],
|
|
8
|
+
['postCreation', 'postCreation'],
|
|
9
|
+
['creationError', 'creationError'],
|
|
10
|
+
['pre', 'preCreation'],
|
|
11
|
+
['post', 'postCreation'],
|
|
12
|
+
['error', 'creationError'],
|
|
13
|
+
]);
|
|
14
|
+
const resolveHookType = function (name, cb) {
|
|
15
|
+
const hookType = hookTypes.get(name);
|
|
16
|
+
if (hookType === undefined) {
|
|
17
|
+
throw new WRONG_HOOK_TYPE;
|
|
18
|
+
}
|
|
19
|
+
if (typeof cb !== 'function') {
|
|
20
|
+
throw new MISSING_HOOK_CALLBACK;
|
|
21
|
+
}
|
|
22
|
+
return hookType;
|
|
23
|
+
};
|
|
24
|
+
exports.resolveHookType = resolveHookType;
|
|
25
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaG9va1R5cGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FwaS9ob29rcy9ob29rVHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsWUFBWSxDQUFDOzs7QUFJYixxREFBdUQ7QUFDdkQsTUFBTSxFQUNMLGVBQWUsRUFDZixxQkFBcUIsR0FDckIsR0FBRyxvQkFBVyxDQUFDO0FBSWhCLE1BQU0sU0FBUyxHQUFHLElBQUksR0FBRyxDQUFzQjtJQUM5QyxDQUFFLGFBQWEsRUFBRSxhQUFhLENBQUU7SUFDaEMsQ0FBRSxjQUFjLEVBQUUsY0FBYyxDQUFFO0lBQ2xDLENBQUUsZUFBZSxFQUFFL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HlwZXM+KCBbXG5cdFsgJ3ByZUNyZWF0aW9uJywgJ3ByZUNyZWF0aW9uJyBdLFxuXHRbICdwb3N0Q3JlYXRpb24nLCAncG9zdENyZWF0aW9uJyBdLFxuXHRbICdjcmVhdGlvbkVycm9yJywgJ2NyZWF0aW9uRXJyb3InIF0sXG5cdFsgJ3ByZScsICdwcmVDcmVhdGlvbicgXSxcblx0WyAncG9zdCcsICdwb3N0Q3JlYXRpb24nIF0sXG5cdFsgJ2Vycm9yJywgJ2NyZWF0aW9uRXJyb3InIF0sXG5dICk7XG5cbi8vIFRoZSBjaGVja3MgcmVnaXN0ZXJIb29rIGFuZCB1bnJlZ2lzdGVySG9vayBzaGFyZTogd2hpY2ggaG9vayB0eXBlIHRoZSBnaXZlblxuLy8gbmFtZSBtZWFucywgYW5kIHRoYXQgdGhlcmUgaXMgYSBjYWxsYmFjay5cbmV4cG9ydCBjb25zdCByZXNvbHZlSG9va1R5cGUgPSBmdW5jdGlvbiAoIG5hbWU6IHN0cmluZywgY2I6IHVua25vd24gKTogaG9va3NUeXBlcyB7XG5cblx0Y29uc3QgaG9va1R5cGUgPSBob29rVHlwZXMuZ2V0KCBuYW1lICk7XG5cblx0aWYgKCBob29rVHlwZSA9PT0gdW5kZWZpbmVkICkge1xuXHRcdHRocm93IG5ldyBXUk9OR19IT09LX1RZUEU7XG5cdH1cblxuXHRpZiAoIHR5cGVvZiBjYiAhPT0gJ2Z1bmN0aW9uJyApIHtcblx0XHR0aHJvdyBuZXcgTUlTU0lOR19IT09LX0NBTExCQUNLO1xuXHR9XG5cblx0cmV0dXJuIGhvb2tUeXBlO1xufTtcbiJdfQ==
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { invokeHook } from './invokeHook';
|
|
2
|
-
export { registerHook } from './registerHook';
|
|
2
|
+
export { registerHook, registerHook as on } from './registerHook';
|
|
3
|
+
export { unregisterHook, unregisterHook as off } from './unregisterHook';
|
|
3
4
|
export { registerFlowChecker } from './flowCheckers';
|
package/build/api/hooks/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerFlowChecker = exports.registerHook = exports.invokeHook = void 0;
|
|
3
|
+
exports.registerFlowChecker = exports.off = exports.unregisterHook = exports.on = exports.registerHook = exports.invokeHook = void 0;
|
|
4
4
|
var invokeHook_1 = require("./invokeHook");
|
|
5
5
|
Object.defineProperty(exports, "invokeHook", { enumerable: true, get: function () { return invokeHook_1.invokeHook; } });
|
|
6
6
|
var registerHook_1 = require("./registerHook");
|
|
7
7
|
Object.defineProperty(exports, "registerHook", { enumerable: true, get: function () { return registerHook_1.registerHook; } });
|
|
8
|
+
Object.defineProperty(exports, "on", { enumerable: true, get: function () { return registerHook_1.registerHook; } });
|
|
9
|
+
var unregisterHook_1 = require("./unregisterHook");
|
|
10
|
+
Object.defineProperty(exports, "unregisterHook", { enumerable: true, get: function () { return unregisterHook_1.unregisterHook; } });
|
|
11
|
+
Object.defineProperty(exports, "off", { enumerable: true, get: function () { return unregisterHook_1.unregisterHook; } });
|
|
8
12
|
var flowCheckers_1 = require("./flowCheckers");
|
|
9
13
|
Object.defineProperty(exports, "registerFlowChecker", { enumerable: true, get: function () { return flowCheckers_1.registerFlowChecker; } });
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXBpL2hvb2tzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLFlBQVksQ0FBQzs7O0FBRWIsMkNBQTBDO0FBQWpDLHdHQUFBLFVBQVUsT0FBQTtBQUNuQiwrQ0FHd0I7QUFGdkIsNEdBQUEsWUFBWSxPQUFBO0FBQ1osa0dBQUEsWUFBWSxPQUFNO0FBRW5CLG1EQUcwQjtBQUZ6QixnSEFBQSxjQUFjLE9BQUE7QUFDZCxxR0FBQSxjQUFjLE9BQU87QUFFdEIsK0NBQXFEO0FBQTVDLG1IQUFBLG1CQUFtQixPQUFBIiwic291cmNlc0NvbnRlbnQiOlsiJ3VzZSBzdHJpY3QnO1xuXG5leHBvcnQgeyBpbnZva2VIb29rIH0gZnJvbSAnLi9pbnZva2VIb29rJztcbmV4cG9ydCB7XG5cdHJlZ2lzdGVySG9vayxcblx0cmVnaXN0ZXJIb29rIGFzIG9uXG59IGZyb20gJy4vcmVnaXN0ZXJIb29rJztcbmV4cG9ydCB7XG5cdHVucmVnaXN0ZXJIb29rLFxuXHR1bnJlZ2lzdGVySG9vayBhcyBvZmZcbn0gZnJvbSAnLi91bnJlZ2lzdGVySG9vayc7XG5leHBvcnQgeyByZWdpc3RlckZsb3dDaGVja2VyIH0gZnJvbSAnLi9mbG93Q2hlY2tlcnMnO1xuXG4iXX0=
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Hookable, hook } from '../../types';
|
|
2
|
-
export declare const registerHook: (this: Hookable,
|
|
2
|
+
export declare const registerHook: (this: Hookable, name: string, cb: hook) => void;
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerHook = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
'preCreation',
|
|
8
|
-
'postCreation',
|
|
9
|
-
'creationError',
|
|
10
|
-
];
|
|
11
|
-
const registerHook = function (hookType, cb) {
|
|
12
|
-
if (!hooksTypes.includes(hookType)) {
|
|
13
|
-
throw new WRONG_HOOK_TYPE;
|
|
14
|
-
}
|
|
15
|
-
if (typeof cb !== 'function') {
|
|
16
|
-
throw new MISSING_HOOK_CALLBACK;
|
|
17
|
-
}
|
|
4
|
+
const hookTypes_1 = require("./hookTypes");
|
|
5
|
+
const registerHook = function (name, cb) {
|
|
6
|
+
const hookType = (0, hookTypes_1.resolveHookType)(name, cb);
|
|
18
7
|
if (!this.hooks[hookType]) {
|
|
19
8
|
this.hooks[hookType] = new Set([cb]);
|
|
20
9
|
}
|
|
@@ -23,4 +12,4 @@ const registerHook = function (hookType, cb) {
|
|
|
23
12
|
}
|
|
24
13
|
};
|
|
25
14
|
exports.registerHook = registerHook;
|
|
26
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVnaXN0ZXJIb29rLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FwaS9ob29rcy9yZWdpc3Rlckhvb2sudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsWUFBWSxDQUFDOzs7QUFNYiwyQ0FBOEM7QUFFdkMsTUFBTSxZQUFZLEdBQUcsVUFBMkIsSUFBWSxFQUFFLEVBQVE7SUFFNUUsTUFBTSxRQUFRLEdBQUcsSUFBQSwyQkFBZSxFQUMvQixJQUFJLEVBQ0osRUFBRSxDQUNGLENBQUM7SUFFRixJQUFLLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBRSxRQUFRLENBQUUsRUFBRyxDQUFDO1FBQy9CLElBQUksQ0FBQyxLQUFLLENBQUUsUUFBUSxDQUFFLEdBQUcsSUFBSSxHQUFHLENBQUUsQ0FBRSxFQUFFLENBQUUsQ0FBRSxDQUFDO0lBQzVDLENBQUM7U0FBTSxDQUFDO1FBQ1AsSUFBSSxDQUFDLEtBQUssQ0FBRSxRQUFRLENBQUUsQ0FBQyxHQUFHLENBQUUsRUFBRSxDQUFFLENBQUM7SUFDbEMsQ0FBQztBQUVGLENBQUMsQ0FBQztBQWJXLFFBQUEsWUFBWSxnQkFhdkIiLCJzb3VyY2VzQ29udGVudCI6WyIndXNlIHN0cmljdCc7XG5cbmltcG9ydCB0eXBlIHtcblx0SG9va2FibGUsIGhvb2tcbn0gZnJvbSAnLi4vLi4vdHlwZXMnO1xuXG5pbXBvcnQgeyByZXNvbHZlSG9va1R5cGUgfSBmcm9tICcuL2hvb2tUeXBlcyc7XG5cbmV4cG9ydCBjb25zdCByZWdpc3Rlckhvb2sgPSBmdW5jdGlvbiAoIHRoaXM6IEhvb2thYmxlLCBuYW1lOiBzdHJpbmcsIGNiOiBob29rICkge1xuXG5cdGNvbnN0IGhvb2tUeXBlID0gcmVzb2x2ZUhvb2tUeXBlKFxuXHRcdG5hbWUsXG5cdFx0Y2Jcblx0KTtcblxuXHRpZiAoICF0aGlzLmhvb2tzWyBob29rVHlwZSBdICkge1xuXHRcdHRoaXMuaG9va3NbIGhvb2tUeXBlIF0gPSBuZXcgU2V0KCBbIGNiIF0gKTtcblx0fSBlbHNlIHtcblx0XHR0aGlzLmhvb2tzWyBob29rVHlwZSBdLmFkZCggY2IgKTtcblx0fVxuXG59O1xuIl19
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unregisterHook = void 0;
|
|
4
|
+
const hookTypes_1 = require("./hookTypes");
|
|
5
|
+
const unregisterHook = function (name, cb) {
|
|
6
|
+
const hookType = (0, hookTypes_1.resolveHookType)(name, cb);
|
|
7
|
+
const callbacks = this.hooks[hookType];
|
|
8
|
+
if (callbacks === undefined) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const removed = callbacks.delete(cb);
|
|
12
|
+
if (callbacks.size === 0) {
|
|
13
|
+
Reflect.deleteProperty(this.hooks, hookType);
|
|
14
|
+
}
|
|
15
|
+
return removed;
|
|
16
|
+
};
|
|
17
|
+
exports.unregisterHook = unregisterHook;
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5yZWdpc3Rlckhvb2suanMiLCJzb3VyY2VSb290IjoiI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UgZXhhY3QgY2FsbGJhY2sgaXMgcmVtb3ZlZDogYSBTZXQgaG9sZHMgaXQgYnkgcmVmZXJlbmNlLlxuZXhwb3J0IGNvbnN0IHVucmVnaXN0ZXJIb29rID0gZnVuY3Rpb24gKCB0aGlzOiBIb29rYWJsZSwgbmFtZTogc3RyaW5nLCBjYjogaG9vayApOiBib29sZWFuIHtcblxuXHRjb25zdCBob29rVHlwZSA9IHJlc29sdmVIb29rVHlwZShcblx0XHRuYW1lLFxuXHRcdGNiXG5cdCk7XG5cblx0Y29uc3QgY2FsbGJhY2tzID0gdGhpcy5ob29rc1sgaG9va1R5cGUgXTtcblx0aWYgKCBjYWxsYmFja3MgPT09IHVuZGVmaW5lZCApIHtcblx0XHRyZXR1cm4gZmFsc2U7XG5cdH1cblxuXHRjb25zdCByZW1vdmVkID0gY2FsbGJhY2tzLmRlbGV0ZSggY2IgKTtcblxuXHQvLyB0aGUgbGFzdCBvbmUgb3V0OiBhbiBlbXB0eSBlbnRyeSB3b3VsZCBzdGlsbCBydW4gdGhlIGZsb3cgY2hlY2tlclxuXHQvLyBvbiBldmVyeSBjb25zdHJ1Y3Rpb24gKHNlZSBpbnZva2VIb29rKVxuXHRpZiAoIGNhbGxiYWNrcy5zaXplID09PSAwICkge1xuXHRcdFJlZmxlY3QuZGVsZXRlUHJvcGVydHkoXG5cdFx0XHR0aGlzLmhvb2tzLFxuXHRcdFx0aG9va1R5cGVcblx0XHQpO1xuXHR9XG5cblx0cmV0dXJuIHJlbW92ZWQ7XG5cbn07XG4iXX0=
|
package/build/api/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export * as errors from './errors';
|
|
2
2
|
export declare const hooks: {
|
|
3
3
|
invokeHook: (this: import("../types").Hookable, hookType: string, opts: import("..").hooksOpts) => Set<unknown>;
|
|
4
|
-
registerHook: (this: import("../types").Hookable,
|
|
4
|
+
registerHook: (this: import("../types").Hookable, name: string, cb: import("..").hook) => void;
|
|
5
|
+
unregisterHook: (this: import("../types").Hookable, name: string, cb: import("..").hook) => boolean;
|
|
5
6
|
registerFlowChecker: (this: import("../types").Hookable, cb: import("../types").FlowChecker) => void;
|
|
6
7
|
};
|
|
7
8
|
export declare const types: {
|
|
8
|
-
define: (this: unknown, subtypes: import("./types").TypesMap, TypeOrTypeName: string | import("../types").DefineNewableOrCallable, constructHandlerOrConfig?: import("../types").DefineNewableOrCallable | object, config?: object) => import("..").TypeClass;
|
|
9
|
-
lazy: (this: unknown, subtypes: import("./types").TypesMap, TypeName: string, getter?: import("..").LazyDef<object>, config?: object) => import("..").TypeClass;
|
|
9
|
+
define: (this: unknown, subtypes: import("./types").TypesMap, TypeOrTypeName: string | import("../types").DefineNewableOrCallable, constructHandlerOrConfig?: import("../types").DefineNewableOrCallable | object | boolean, config?: object | boolean) => import("..").TypeClass;
|
|
10
|
+
lazy: (this: unknown, subtypes: import("./types").TypesMap, TypeName: string, getter?: import("..").LazyDef<object>, config?: object | boolean) => import("..").TypeClass;
|
|
10
11
|
lookup: (this: import("./types").TypesMap, TypeNestedPath: string) => import("..").TypeClass | undefined;
|
|
11
12
|
};
|
package/build/api/index.js
CHANGED
|
@@ -40,6 +40,7 @@ exports.errors = __importStar(require("./errors"));
|
|
|
40
40
|
exports.hooks = {
|
|
41
41
|
invokeHook: hooks_1.invokeHook,
|
|
42
42
|
registerHook: hooks_1.registerHook,
|
|
43
|
+
unregisterHook: hooks_1.unregisterHook,
|
|
43
44
|
registerFlowChecker: hooks_1.registerFlowChecker,
|
|
44
45
|
};
|
|
45
46
|
exports.types = {
|
|
@@ -47,4 +48,4 @@ exports.types = {
|
|
|
47
48
|
lazy: types_1.lazy,
|
|
48
49
|
lookup: types_1.lookup,
|
|
49
50
|
};
|
|
50
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
51
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6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emonicaConstructor } from '../../types';
|
|
1
2
|
export interface ConstructHandler extends CallableFunction {
|
|
2
3
|
(this: object, ...args: unknown[]): unknown;
|
|
3
4
|
prototype: object;
|
|
@@ -13,6 +14,7 @@ export interface CallableCandidate extends CallableFunction {
|
|
|
13
14
|
}
|
|
14
15
|
export declare const isCallableCandidate: (value: unknown) => value is CallableCandidate;
|
|
15
16
|
export declare function classifyConstructHandler(FunctionName: string, handler: CallableCandidate): asserts handler is ConstructHandler;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
export declare const isClass: (fn: ConstructHandler) => fn is ConstructHandler & ClassConstructHandler;
|
|
18
|
+
type ModificationBody = MnemonicaConstructor;
|
|
19
|
+
declare const compileNewModificatorFunctionBody: (FunctionName: string) => (ConstructHandler: ConstructHandler, CreationHandler: CreationHandler, SymbolConstructorName: symbol) => () => ModificationBody;
|
|
18
20
|
export default compileNewModificatorFunctionBody;
|