mnemonica 1.4.5 → 1.4.7
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 +1 -1
- package/README.md +1 -1
- package/build/api/types/TypeProxy.js +3 -3
- package/build/api/types/compileNewModificatorFunctionBody.js +1 -1
- package/build/api/types/createInstanceModificator.d.ts +1 -0
- package/build/api/types/createInstanceModificator.js +1 -1
- package/build/api/types/index.js +1 -1
- package/build/api/utils/index.d.ts +2 -2
- package/build/api/utils/index.js +9 -5
- package/build/constants/index.d.ts +3 -1
- package/build/constants/index.js +1 -1
- package/build/descriptors/types/index.js +4 -1
- package/build/index.d.ts +4 -4
- package/build/index.js +3 -3
- package/build/types/index.d.ts +29 -6
- package/build/types/index.js +1 -1
- package/build/utils/fork.js +6 -3
- package/build/utils/index.js +2 -2
- package/build/utils/lineage.js +2 -3
- package/docs/async-constructors.md +21 -0
- package/docs/typed-lookup.md +43 -1
- package/package.json +2 -2
- package/src/api/types/TypeProxy.ts +6 -4
- package/src/api/types/compileNewModificatorFunctionBody.ts +5 -1
- package/src/api/types/createInstanceModificator.ts +1 -2
- package/src/api/types/index.ts +4 -0
- package/src/api/utils/index.ts +15 -12
- package/src/constants/index.ts +3 -1
- package/src/descriptors/types/index.ts +3 -0
- package/src/index.ts +30 -34
- package/src/types/index.ts +111 -16
- package/src/utils/fork.ts +11 -4
- package/src/utils/index.ts +5 -6
- package/src/utils/lineage.ts +6 -7
package/src/utils/fork.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
getProps, Props
|
|
5
5
|
} from '../api/types/Props';
|
|
6
6
|
import { InstanceCreator } from '../api/types/InstanceCreator';
|
|
7
|
+
import { gatherLazyDefinition } from '../api/types/lazyDefinition';
|
|
7
8
|
import TypesUtils from '../api/utils/index';
|
|
8
9
|
import type { ForkInvoker } from '../types';
|
|
9
10
|
|
|
@@ -26,7 +27,7 @@ export const fork = <T extends object>(instance: T): ForkInvoker<T> => {
|
|
|
26
27
|
TypeName
|
|
27
28
|
} = type;
|
|
28
29
|
|
|
29
|
-
const result = function (this: object, ...forkArgs: unknown[]) {
|
|
30
|
+
const result = function (this: object | void, ...forkArgs: unknown[]) {
|
|
30
31
|
|
|
31
32
|
let forked;
|
|
32
33
|
const Constructor = isSubType ?
|
|
@@ -36,15 +37,21 @@ export const fork = <T extends object>(instance: T): ForkInvoker<T> => {
|
|
|
36
37
|
const args = forkArgs.length ? forkArgs : __args__;
|
|
37
38
|
|
|
38
39
|
|
|
39
|
-
if (this === __self__) {
|
|
40
|
+
if (this === __self__ || this === undefined) {
|
|
40
41
|
|
|
41
|
-
//
|
|
42
|
+
// Constructor is the parent instance (subtype proxy) or the collection,
|
|
43
|
+
// both indexed dynamically, so Constructor[TypeName] is unknown statically.
|
|
44
|
+
// At runtime it is always the registered type, since TypeName comes from
|
|
45
|
+
// this instance's own type; a guard would be an unreachable branch.
|
|
46
|
+
// @ts-expect-error -- the registered subtype is only dynamically indexed
|
|
42
47
|
forked = new (Constructor[ TypeName ])(...args);
|
|
43
48
|
} else {
|
|
44
49
|
// fork.call ? let's do it !
|
|
50
|
+
const wrappedInstance = reflectPrimitiveWrappers(this);
|
|
51
|
+
gatherLazyDefinition(type, wrappedInstance);
|
|
45
52
|
forked = new InstanceCreator(
|
|
46
53
|
type,
|
|
47
|
-
|
|
54
|
+
wrappedInstance,
|
|
48
55
|
args
|
|
49
56
|
);
|
|
50
57
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -50,12 +50,11 @@ const wrapThis = ( collection: object, method: WrappableMethod ) => {
|
|
|
50
50
|
: ( this !== collection ? this : undefined );
|
|
51
51
|
let wrapResult: unknown;
|
|
52
52
|
if ( new.target ) {
|
|
53
|
-
// wrapThis forwards `new`
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
instanceContext,
|
|
58
|
-
...args
|
|
53
|
+
// wrapThis forwards `new` with Reflect.construct: without a third
|
|
54
|
+
// argument new.target is method, exactly as in new method(...args)
|
|
55
|
+
wrapResult = Reflect.construct(
|
|
56
|
+
method,
|
|
57
|
+
[ instanceContext, ...args ]
|
|
59
58
|
);
|
|
60
59
|
} else {
|
|
61
60
|
wrapResult = method(
|
package/src/utils/lineage.ts
CHANGED
|
@@ -13,8 +13,6 @@ import {
|
|
|
13
13
|
} from '../api/types/Props';
|
|
14
14
|
import { constants } from '../constants';
|
|
15
15
|
|
|
16
|
-
const { SymbolConfig } = constants;
|
|
17
|
-
|
|
18
16
|
import type {
|
|
19
17
|
LineageGraph,
|
|
20
18
|
LineageNode,
|
|
@@ -181,11 +179,12 @@ export const lineage = ( instances: object[], options?: LineageOptions ): Lineag
|
|
|
181
179
|
const { __collection__: collection } = baseProps;
|
|
182
180
|
// every collection carries a name by construction (the default
|
|
183
181
|
// collection is 'defaultTypes', unnamed customs are auto-named), so
|
|
184
|
-
// no fallback is needed here
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const
|
|
182
|
+
// no fallback is needed here; CollectionDef types its SymbolConfig
|
|
183
|
+
// entry as CollectionConfig with that name. Read through constants
|
|
184
|
+
// directly: a local alias (const or destructured) widens the unique
|
|
185
|
+
// symbol to symbol and loses the typed key
|
|
186
|
+
const collectionConfig = collection[ constants.SymbolConfig ];
|
|
187
|
+
const collectionName: string = collectionConfig.name;
|
|
189
188
|
|
|
190
189
|
const node: LineageNode = {
|
|
191
190
|
type : {
|