mnemonica 1.4.9 → 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 +76 -13
- package/README.md +1 -1
- 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/index.d.ts +2 -2
- package/build/api/types/index.js +19 -16
- package/build/descriptors/types/index.js +19 -12
- package/build/index.d.ts +24 -10
- package/build/index.js +27 -24
- package/build/types/index.d.ts +66 -39
- package/build/types/index.js +1 -1
- package/docs/UTILS.md +1 -0
- package/docs/async-constructors.md +24 -8
- package/docs/typed-lookup.md +8 -8
- package/module/index.js +2 -0
- package/package.json +1 -1
- 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/index.ts +44 -33
- package/src/descriptors/types/index.ts +31 -22
- package/src/index.ts +251 -46
- package/src/types/index.ts +309 -80
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
|
|
@@ -469,7 +469,10 @@ import {
|
|
|
469
469
|
IDEF, // Base constructor function type
|
|
470
470
|
LazyDef, // Zero-arg callback returning a constructor (for lazy())
|
|
471
471
|
constructorOptions, // Type config options (strictChain, blockErrors, etc.)
|
|
472
|
+
DefineConfig, // what define() takes as config: the options, a boolean or a function
|
|
472
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
|
|
473
476
|
hook, // Hook callback type (untyped — collection-wide handlers)
|
|
474
477
|
typedHook, // Hook callback typed by hookType + parent/instance pair
|
|
475
478
|
typedHookOpts, // Hook options object typed per hookType
|
|
@@ -544,7 +547,17 @@ const AsyncTypeNoReturn = define('AsyncTypeNoReturn', async function () {
|
|
|
544
547
|
|
|
545
548
|
#### `define(typeName, constructHandler, config?)`
|
|
546
549
|
|
|
547
|
-
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.
|
|
548
561
|
|
|
549
562
|
```js
|
|
550
563
|
const MyType = define('MyType', function (data) {
|
|
@@ -556,9 +569,9 @@ const MyType = define('MyType', function (data) {
|
|
|
556
569
|
```
|
|
557
570
|
|
|
558
571
|
**Parameters:**
|
|
559
|
-
- `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.
|
|
560
|
-
- `constructHandler` (Function): Constructor function
|
|
561
|
-
- `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)
|
|
562
575
|
|
|
563
576
|
#### `lazy(typeName, callback, config?)`
|
|
564
577
|
|
|
@@ -601,7 +614,7 @@ const SubType = MyType.lazy('SubType', () => function (data) {
|
|
|
601
614
|
**Parameters:**
|
|
602
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.
|
|
603
616
|
- `callback` (Function): Zero-arg sync function returning the constructor; called once per construction.
|
|
604
|
-
- `config` (object, optional): Configuration options
|
|
617
|
+
- `config` (object, boolean or function, optional): [Configuration options](#configuration-options)
|
|
605
618
|
|
|
606
619
|
#### `lookup(typeNestedPath)`
|
|
607
620
|
|
|
@@ -647,7 +660,11 @@ Then include the generated types in your project. See [`docs/typed-lookup.md`](.
|
|
|
647
660
|
|
|
648
661
|
#### `apply(entity, Constructor, args?)`
|
|
649
662
|
|
|
650
|
-
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.
|
|
651
668
|
|
|
652
669
|
```js
|
|
653
670
|
const { apply } = require('mnemonica');
|
|
@@ -710,6 +727,20 @@ registerHook(MyType, 'postCreation', (opts) => {
|
|
|
710
727
|
});
|
|
711
728
|
```
|
|
712
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
|
+
|
|
713
744
|
---
|
|
714
745
|
|
|
715
746
|
### Type Reference
|
|
@@ -723,9 +754,11 @@ For advanced TypeScript usage, the following types are exported from `mnemonica`
|
|
|
723
754
|
| `TypeConstructor<T>` | Registry-stored constructor type | What an augmented `TypeRegistry` maps paths to |
|
|
724
755
|
| `TypeClass` | Base type constructor | `const MyType: TypeClass = define(...)` |
|
|
725
756
|
| `DecoratedClass<T>` | Decorated class type | `@decorate() class MyClass {}` (see [`docs/decorate.md`](./docs/decorate.md)) |
|
|
726
|
-
| `IDefinitorInstance<N, R, Registry, Path, Parent, Args>` | Constructor with subtypes | Returned by `define()` with `.define()` method; `Parent` types hook callbacks' `existentInstance`, `Args` the construction arguments |
|
|
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) |
|
|
727
758
|
| `constructorOptions` | Configuration options | `{ strictChain: true, blockErrors: true }` |
|
|
728
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` |
|
|
729
762
|
| `hook` | Hook callback type (stored/invoked) | `(opts: deliveredHookOpts) => unknown` — the payload callbacks receive |
|
|
730
763
|
| `hooksOpts` | Hook options object (invokeHook input) | Carries `creator`; HookInvocation converts it to the delivered payload |
|
|
731
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) |
|
|
@@ -801,7 +834,12 @@ interface TypesCollection {
|
|
|
801
834
|
|
|
802
835
|
// Register a hook for all types in this collection
|
|
803
836
|
// (opts are split per hookType; instance fields are object — narrow with instanceof lookup(...))
|
|
804
|
-
registerHook<HT extends
|
|
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
|
|
805
843
|
|
|
806
844
|
// Invoke hooks manually (advanced usage)
|
|
807
845
|
invokeHook(hookType: hooksTypes, opts: hooksOpts): Set<unknown>;
|
|
@@ -1130,6 +1168,23 @@ defaultTypes.registerHook('postCreation', (hookData) => {
|
|
|
1130
1168
|
});
|
|
1131
1169
|
```
|
|
1132
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
|
+
|
|
1133
1188
|
#### `collection.registerFlowChecker(callback)`
|
|
1134
1189
|
|
|
1135
1190
|
Register a flow checker that runs after the hook callbacks of one
|
|
@@ -1299,7 +1354,8 @@ const {
|
|
|
1299
1354
|
|
|
1300
1355
|
## Configuration Options
|
|
1301
1356
|
|
|
1302
|
-
Pass options as the
|
|
1357
|
+
Pass options as the last argument to `define()`, after the handler or, with no
|
|
1358
|
+
handler, after the name:
|
|
1303
1359
|
|
|
1304
1360
|
```js
|
|
1305
1361
|
define('SomeType', function () {}, {
|
|
@@ -1319,7 +1375,14 @@ define('SomeType', function () {}, {
|
|
|
1319
1375
|
| `blockErrors` | `boolean` | `true` | If `true`, prevents construction when errors exist in the prototype chain. |
|
|
1320
1376
|
| `submitStack` | `boolean` | `false` | If `true`, collects stack trace and stores as `__stack__` property on instances. |
|
|
1321
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. |
|
|
1322
|
-
| `ModificationConstructor` | `Function` | - |
|
|
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
|
+
```
|
|
1323
1386
|
|
|
1324
1387
|
### What `strictChain` actually guards
|
|
1325
1388
|
|
package/README.md
CHANGED
|
@@ -287,7 +287,7 @@ The full API reference — every signature, config option, hook data shape, the
|
|
|
287
287
|
|
|
288
288
|
| Area | Where |
|
|
289
289
|
|---|---|
|
|
290
|
-
| 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 |
|
|
291
291
|
| Instance utilities (`utils.extract`, `pick`, `parent`, `fork`, `exception`, …) | [`docs/UTILS.md`](./docs/UTILS.md) |
|
|
292
292
|
| Typed `lookup()`/`define()` — builder, bridge, tactica | [`docs/typed-lookup.md`](./docs/typed-lookup.md) |
|
|
293
293
|
| `@decorate()` class-based definitions | [`docs/decorate.md`](./docs/decorate.md) |
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaG9va1R5cGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vL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1RZUEU7XG5cdH1cblxuXHRpZiAoIHR5cGVvZiBjYiAhPT0gJ2Z1bmN0aW9uJyApIHtcblx0XHR0aHJvdyBuZXcgTUlTU0lOR19IT09LX0NBTExCQUNLO1xuXHR9XG5cblx0cmV0dXJuIGhvb2tUeXBlO1xufTtcbiJdfQ==
|
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5yZWdpc3Rlckhvb2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXBpL2hvb2tzL3VucmVnaXN0ZXJIb29rLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLFlBQVksQ0FBQzs7O0FBTWIsMkNBQThDO0FBSXZDLE1BQU0sY0FBYyxHQUFHLFVBQTJCLElBQVksRUFBRSxFQUFRO0lBRTlFLE1BQU0sUUFBUSxHQUFHLElBQUEsMkJBQWUsRUFDL0IsSUFBSSxFQUNKLEVBQUUsQ0FDRixDQUFDO0lBRUYsTUFBTSxTQUFTLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBRSxRQUFRLENBQUUsQ0FBQztJQUN6QyxJQUFLLFNBQVMsS0FBSyxTQUFTLEVBQUcsQ0FBQztRQUMvQixPQUFPLEtBQUssQ0FBQztJQUNkLENBQUM7SUFFRCxNQUFNLE9BQU8sR0FBRyxTQUFTLENBQUMsTUFBTSxDQUFFLEVBQUUsQ0FBRSxDQUFDO0lBSXZDLElBQUssU0FBUyxDQUFDLElBQUksS0FBSyxDQUFDLEVBQUcsQ0FBQztRQUM1QixPQUFPLENBQUMsY0FBYyxDQUNyQixJQUFJLENBQUMsS0FBSyxFQUNWLFFBQVEsQ0FDUixDQUFDO0lBQ0gsQ0FBQztJQUVELE9BQU8sT0FBTyxDQUFDO0FB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HkoXG5cdFx0XHR0aGlzLmhvb2tzLFxuXHRcdFx0aG9va1R5cGVcblx0XHQpO1xuXHR9XG5cblx0cmV0dXJuIHJlbW92ZWQ7XG5cbn07XG4iXX0=
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYXBpL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLFlBQVksQ0FBQzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBRWIsbUNBS2lCO0FBQ2pCLG1DQUlpQjtBQUVqQixtREFBbUM7QUFFdEIsUUFBQSxLQUFLLEdBQUc7SUFDcEIsVUFBVSxFQUFWLGtCQUFVO0lBQ1YsWUFBWSxFQUFaLG9CQUFZO0lBQ1osY0FBYyxFQUFkLHNCQUFjO0lBQ2QsbUJBQW1CLEVBQW5CLDJCQUFtQjtDQUNuQixDQUFDO0FBRVcsUUFBQSxLQUFLLEdBQUc7SUFDcEIsTUFBTSxFQUFOLGNBQU07SUFDTixJQUFJLEVBQUosWUFBSTtJQUNKLE1BQU0sRUFBTixjQUFNO0NBQ04sQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIid1c2Ugc3RyaWN0JztcblxuaW1wb3J0IHtcblx0aW52b2tlSG9vayxcblx0cmVnaXN0ZXJIb29rLFxuXHR1bnJlZ2lzdGVySG9vayxcblx0cmVnaXN0ZXJGbG93Q2hlY2tlcixcbn0gZnJvbSAnLi9ob29rcyc7XG5pbXBvcnQge1xuXHRkZWZpbmUsXG5cdGxhenksXG5cdGxvb2t1cCxcbn0gZnJvbSAnLi90eXBlcyc7XG5cbmV4cG9ydCAqIGFzIGVycm9ycyBmcm9tICcuL2Vycm9ycyc7XG5cbmV4cG9ydCBjb25zdCBob29rcyA9IHtcblx0aW52b2tlSG9vayxcblx0cmVnaXN0ZXJIb29rLFxuXHR1bnJlZ2lzdGVySG9vayxcblx0cmVnaXN0ZXJGbG93Q2hlY2tlcixcbn07XG5cbmV4cG9ydCBjb25zdCB0eXBlcyA9IHtcblx0ZGVmaW5lLFxuXHRsYXp5LFxuXHRsb29rdXAsXG59O1xuIl19
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TypeClass, DefineNewableOrCallable, LazyDef } from '../../types';
|
|
2
2
|
export type TypesMap = Map<string, object> & {};
|
|
3
|
-
export declare const define: (this: unknown, subtypes: TypesMap, TypeOrTypeName: string | DefineNewableOrCallable, constructHandlerOrConfig?: DefineNewableOrCallable | object, config?: object) => TypeClass;
|
|
4
|
-
export declare const lazy: (this: unknown, subtypes: TypesMap, TypeName: string, getter?: LazyDef<object>, config?: object) => TypeClass;
|
|
3
|
+
export declare const define: (this: unknown, subtypes: TypesMap, TypeOrTypeName: string | DefineNewableOrCallable, constructHandlerOrConfig?: DefineNewableOrCallable | object | boolean, config?: object | boolean) => TypeClass;
|
|
4
|
+
export declare const lazy: (this: unknown, subtypes: TypesMap, TypeName: string, getter?: LazyDef<object>, config?: object | boolean) => TypeClass;
|
|
5
5
|
export declare const lookup: (this: TypesMap, TypeNestedPath: string) => TypeClass | undefined;
|