mutate-cow 5.0.0 → 7.0.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/README.md +8 -7
- package/package.json +10 -6
- package/{CowContext.mjs → src/index.js} +149 -26
- package/src/index.js.flow +114 -0
- package/{index.d.ts → types/index.d.ts} +23 -13
- package/bench.mjs +0 -74
- package/canClone.mjs +0 -40
- package/clone.mjs +0 -99
- package/constants.mjs +0 -23
- package/index.mjs +0 -14
- package/index.mjs.flow +0 -140
- package/index.test-d.ts +0 -60
- package/test.mjs +0 -715
package/clone.mjs
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023 Michael Wiencek
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license. A copy can be found
|
|
5
|
-
* in the file named "LICENSE" at the root directory of this distribution.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import canClone from './canClone.mjs';
|
|
9
|
-
import {
|
|
10
|
-
NON_CONFIGURABLE,
|
|
11
|
-
NON_CONFIGURABLE_AND_WRITABLE,
|
|
12
|
-
NON_WRITABLE,
|
|
13
|
-
} from './constants.mjs';
|
|
14
|
-
|
|
15
|
-
function isPrimitive(value) {
|
|
16
|
-
switch (typeof value) {
|
|
17
|
-
case 'bigint':
|
|
18
|
-
case 'boolean':
|
|
19
|
-
case 'number':
|
|
20
|
-
case 'string':
|
|
21
|
-
case 'symbol':
|
|
22
|
-
case 'undefined':
|
|
23
|
-
return true;
|
|
24
|
-
default:
|
|
25
|
-
return value === null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function restoreDescriptors(copy, changedDescriptors) {
|
|
30
|
-
for (let i = 0; i < changedDescriptors.length; i++) {
|
|
31
|
-
const [name, origDesc] = changedDescriptors[i];
|
|
32
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(copy, name);
|
|
33
|
-
if (descriptor) {
|
|
34
|
-
Object.assign(descriptor, origDesc);
|
|
35
|
-
Reflect.defineProperty(copy, name, descriptor);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default function clone(source, callbacks) {
|
|
41
|
-
if (isPrimitive(source)) {
|
|
42
|
-
return source;
|
|
43
|
-
}
|
|
44
|
-
canClone(source);
|
|
45
|
-
let changedDescriptors;
|
|
46
|
-
let copy;
|
|
47
|
-
if (Array.isArray(source)) {
|
|
48
|
-
copy = new Array(source.length);
|
|
49
|
-
} else {
|
|
50
|
-
copy = Object.create(Reflect.getPrototypeOf(source));
|
|
51
|
-
}
|
|
52
|
-
const ownNames = Object.getOwnPropertyNames(source);
|
|
53
|
-
for (let i = 0; i < ownNames.length; i++) {
|
|
54
|
-
const name = ownNames[i];
|
|
55
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(source, name);
|
|
56
|
-
const nonConfigurable = descriptor.configurable === false;
|
|
57
|
-
let origDesc;
|
|
58
|
-
if (nonConfigurable) {
|
|
59
|
-
descriptor.configurable = true;
|
|
60
|
-
origDesc = NON_CONFIGURABLE;
|
|
61
|
-
}
|
|
62
|
-
if (descriptor.writable === false) {
|
|
63
|
-
descriptor.writable = true;
|
|
64
|
-
origDesc = nonConfigurable
|
|
65
|
-
? NON_CONFIGURABLE_AND_WRITABLE
|
|
66
|
-
: NON_WRITABLE;
|
|
67
|
-
}
|
|
68
|
-
if (origDesc) {
|
|
69
|
-
if (!changedDescriptors) {
|
|
70
|
-
changedDescriptors = [];
|
|
71
|
-
}
|
|
72
|
-
changedDescriptors.push([name, origDesc]);
|
|
73
|
-
}
|
|
74
|
-
Reflect.defineProperty(copy, name, descriptor);
|
|
75
|
-
}
|
|
76
|
-
if (changedDescriptors) {
|
|
77
|
-
callbacks.push({
|
|
78
|
-
func: restoreDescriptors,
|
|
79
|
-
args: [copy, changedDescriptors],
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
if (Object.isFrozen(source)) {
|
|
83
|
-
callbacks.push({
|
|
84
|
-
func: Object.freeze,
|
|
85
|
-
args: [copy],
|
|
86
|
-
});
|
|
87
|
-
} else if (Object.isSealed(source)) {
|
|
88
|
-
callbacks.push({
|
|
89
|
-
func: Object.seal,
|
|
90
|
-
args: [copy],
|
|
91
|
-
});
|
|
92
|
-
} else if (!Reflect.isExtensible(source)) {
|
|
93
|
-
callbacks.push({
|
|
94
|
-
func: Reflect.preventExtensions,
|
|
95
|
-
args: [copy],
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return copy;
|
|
99
|
-
}
|
package/constants.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export const NON_CONFIGURABLE =
|
|
2
|
-
Object.freeze({configurable: false});
|
|
3
|
-
|
|
4
|
-
export const NON_WRITABLE =
|
|
5
|
-
Object.freeze({writable: false});
|
|
6
|
-
|
|
7
|
-
export const NON_CONFIGURABLE_AND_WRITABLE =
|
|
8
|
-
Object.freeze({
|
|
9
|
-
configurable: false,
|
|
10
|
-
writable: false,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const CONFIGURABLE_AND_WRITABLE =
|
|
14
|
-
Object.freeze({
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export const STATUS_NONE = 1;
|
|
20
|
-
|
|
21
|
-
export const STATUS_CHANGED = 2;
|
|
22
|
-
|
|
23
|
-
export const STATUS_REVOKED = 3;
|
package/index.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023 Michael Wiencek
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license. A copy can be found
|
|
5
|
-
* in the file named "LICENSE" at the root directory of this distribution.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import canClone from './canClone.mjs';
|
|
9
|
-
import CowContext from './CowContext.mjs';
|
|
10
|
-
|
|
11
|
-
export default function mutate(source) {
|
|
12
|
-
canClone(source);
|
|
13
|
-
return new CowContext(source, null, null, null);
|
|
14
|
-
}
|
package/index.mjs.flow
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// @flow strict
|
|
2
|
-
|
|
3
|
-
export type MutatableObject =
|
|
4
|
-
| interface {}
|
|
5
|
-
| {__proto__: null, ...};
|
|
6
|
-
|
|
7
|
-
export type KeyType<+T: mixed> =
|
|
8
|
-
T extends $ReadOnlyArray<mixed> ? number :
|
|
9
|
-
T extends {__proto__: null, ...} ? $Keys<T> :
|
|
10
|
-
T extends interface {} ? $Keys<T> :
|
|
11
|
-
empty;
|
|
12
|
-
export type KeyType2<+T, +K1: KeyType<T>> =
|
|
13
|
-
PropType<T, K1> extends $ReadOnlyArray<mixed> ? number :
|
|
14
|
-
PropType<T, K1> extends {__proto__: null, ...} ? $Keys<PropType<T, K1>> :
|
|
15
|
-
PropType<T, K1> extends interface {} ? $Keys<PropType<T, K1>> :
|
|
16
|
-
empty;
|
|
17
|
-
export type KeyType3<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>> =
|
|
18
|
-
PropType2<T, K1, K2> extends $ReadOnlyArray<mixed> ? number :
|
|
19
|
-
PropType2<T, K1, K2> extends {__proto__: null, ...} ? $Keys<PropType2<T, K1, K2>> :
|
|
20
|
-
PropType2<T, K1, K2> extends interface {} ? $Keys<PropType2<T, K1, K2>> :
|
|
21
|
-
empty;
|
|
22
|
-
export type KeyType4<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>> =
|
|
23
|
-
PropType3<T, K1, K2, K3> extends $ReadOnlyArray<mixed> ? number :
|
|
24
|
-
PropType3<T, K1, K2, K3> extends {__proto__: null, ...} ? $Keys<PropType3<T, K1, K2, K3>> :
|
|
25
|
-
PropType3<T, K1, K2, K3> extends interface {} ? $Keys<PropType3<T, K1, K2, K3>> :
|
|
26
|
-
empty;
|
|
27
|
-
export type KeyType5<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>, +K4: KeyType4<T, K1, K2, K3>> =
|
|
28
|
-
PropType4<T, K1, K2, K3, K4> extends $ReadOnlyArray<mixed> ? number :
|
|
29
|
-
PropType4<T, K1, K2, K3, K4> extends {__proto__: null, ...} ? $Keys<PropType4<T, K1, K2, K3, K4>> :
|
|
30
|
-
PropType4<T, K1, K2, K3, K4> extends interface {} ? $Keys<PropType4<T, K1, K2, K3, K4>> :
|
|
31
|
-
empty;
|
|
32
|
-
export type KeyType6<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>, +K4: KeyType4<T, K1, K2, K3>, +K5: KeyType5<T, K1, K2, K3, K4>> =
|
|
33
|
-
PropType5<T, K1, K2, K3, K4, K5> extends $ReadOnlyArray<mixed> ? number :
|
|
34
|
-
PropType5<T, K1, K2, K3, K4, K5> extends {__proto__: null, ...} ? $Keys<PropType5<T, K1, K2, K3, K4, K5>> :
|
|
35
|
-
PropType5<T, K1, K2, K3, K4, K5> extends interface {} ? $Keys<PropType5<T, K1, K2, K3, K4, K5>> :
|
|
36
|
-
empty;
|
|
37
|
-
export type KeyType7<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>, +K4: KeyType4<T, K1, K2, K3>, +K5: KeyType5<T, K1, K2, K3, K4>, +K6: KeyType6<T, K1, K2, K3, K4, K5>> =
|
|
38
|
-
PropType6<T, K1, K2, K3, K4, K5, K6> extends $ReadOnlyArray<mixed> ? number :
|
|
39
|
-
PropType6<T, K1, K2, K3, K4, K5, K6> extends {__proto__: null, ...} ? $Keys<PropType6<T, K1, K2, K3, K4, K5, K6>> :
|
|
40
|
-
PropType6<T, K1, K2, K3, K4, K5, K6> extends interface {} ? $Keys<PropType6<T, K1, K2, K3, K4, K5, K6>> :
|
|
41
|
-
empty;
|
|
42
|
-
export type KeyType8<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>, +K4: KeyType4<T, K1, K2, K3>, +K5: KeyType5<T, K1, K2, K3, K4>, +K6: KeyType6<T, K1, K2, K3, K4, K5>, +K7: KeyType7<T, K1, K2, K3, K4, K5, K6>> =
|
|
43
|
-
PropType7<T, K1, K2, K3, K4, K5, K6, K7> extends $ReadOnlyArray<mixed> ? number :
|
|
44
|
-
PropType7<T, K1, K2, K3, K4, K5, K6, K7> extends {__proto__: null, ...} ? $Keys<PropType7<T, K1, K2, K3, K4, K5, K6, K7>> :
|
|
45
|
-
PropType7<T, K1, K2, K3, K4, K5, K6, K7> extends interface {} ? $Keys<PropType7<T, K1, K2, K3, K4, K5, K6, K7>> :
|
|
46
|
-
empty;
|
|
47
|
-
|
|
48
|
-
export type PropType<+T: mixed, +K: KeyType<T>> =
|
|
49
|
-
T extends $ReadOnlyArray<infer V> ? V :
|
|
50
|
-
T extends {__proto__: null, ...} ? T[K] :
|
|
51
|
-
T extends interface {} ? T[K] :
|
|
52
|
-
empty;
|
|
53
|
-
export type PropType2<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>> =
|
|
54
|
-
PropType<PropType<T, K1>, K2>;
|
|
55
|
-
export type PropType3<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>> =
|
|
56
|
-
PropType<PropType2<T, K1, K2>, K3>;
|
|
57
|
-
export type PropType4<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>, +K4: KeyType4<T, K1, K2, K3>> =
|
|
58
|
-
PropType<PropType3<T, K1, K2, K3>, K4>;
|
|
59
|
-
export type PropType5<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>, +K4: KeyType4<T, K1, K2, K3>, +K5: KeyType5<T, K1, K2, K3, K4>> =
|
|
60
|
-
PropType<PropType4<T, K1, K2, K3, K4>, K5>;
|
|
61
|
-
export type PropType6<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>, +K4: KeyType4<T, K1, K2, K3>, +K5: KeyType5<T, K1, K2, K3, K4>, +K6: KeyType6<T, K1, K2, K3, K4, K5>> =
|
|
62
|
-
PropType<PropType5<T, K1, K2, K3, K4, K5>, K6>;
|
|
63
|
-
export type PropType7<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>, +K4: KeyType4<T, K1, K2, K3>, +K5: KeyType5<T, K1, K2, K3, K4>, +K6: KeyType6<T, K1, K2, K3, K4, K5>, +K7: KeyType7<T, K1, K2, K3, K4, K5, K6>> =
|
|
64
|
-
PropType<PropType6<T, K1, K2, K3, K4, K5, K6>, K7>;
|
|
65
|
-
export type PropType8<+T, +K1: KeyType<T>, +K2: KeyType2<T, K1>, +K3: KeyType3<T, K1, K2>, +K4: KeyType4<T, K1, K2, K3>, +K5: KeyType5<T, K1, K2, K3, K4>, +K6: KeyType6<T, K1, K2, K3, K4, K5>, +K7: KeyType7<T, K1, K2, K3, K4, K5, K6>, +K8: KeyType8<T, K1, K2, K3, K4, K5, K6, K7>> =
|
|
66
|
-
PropType<PropType7<T, K1, K2, K3, K4, K5, K6, K7>, K8>;
|
|
67
|
-
|
|
68
|
-
export type ShallowReadWrite<+T> =
|
|
69
|
-
T extends $ReadOnlyArray<infer V> ? Array<V> :
|
|
70
|
-
T extends {__proto__: null, ...} ? {__proto__: null, ...T} :
|
|
71
|
-
T extends {...} ? {...T} :
|
|
72
|
-
T;
|
|
73
|
-
|
|
74
|
-
export type CowRootContext<+R> = CowContext<R, R, null>;
|
|
75
|
-
|
|
76
|
-
export type CowAnyContext<+R> =
|
|
77
|
-
CowContext<mixed, R, CowAnyContext<R> | null>;
|
|
78
|
-
|
|
79
|
-
type $Get1<+T, +K1, +R, +ThisContext> =
|
|
80
|
-
CowContext<PropType<T, K1>, R, ThisContext>;
|
|
81
|
-
type $Get2<+T, +K1, +K2, +R, +ThisContext> =
|
|
82
|
-
CowContext<PropType2<T, K1, K2>, R, $Get1<T, K1, R, ThisContext>>;
|
|
83
|
-
type $Get3<+T, +K1, +K2, +K3, +R, +ThisContext> =
|
|
84
|
-
CowContext<PropType3<T, K1, K2, K3>, R, $Get2<T, K1, K2, R, ThisContext>>;
|
|
85
|
-
type $Get4<+T, +K1, +K2, +K3, +K4, +R, +ThisContext> =
|
|
86
|
-
CowContext<PropType4<T, K1, K2, K3, K4>, R, $Get3<T, K1, K2, K3, R, ThisContext>>;
|
|
87
|
-
type $Get5<+T, +K1, +K2, +K3, +K4, +K5, +R, +ThisContext> =
|
|
88
|
-
CowContext<PropType5<T, K1, K2, K3, K4, K5>, R, $Get4<T, K1, K2, K3, K4, R, ThisContext>>;
|
|
89
|
-
type $Get6<+T, +K1, +K2, +K3, +K4, +K5, +K6, +R, +ThisContext> =
|
|
90
|
-
CowContext<PropType6<T, K1, K2, K3, K4, K5, K6>, R, $Get5<T, K1, K2, K3, K4, K5, R, ThisContext>>;
|
|
91
|
-
type $Get7<+T, +K1, +K2, +K3, +K4, +K5, +K6, +K7, +R, +ThisContext> =
|
|
92
|
-
CowContext<PropType7<T, K1, K2, K3, K4, K5, K6, K7>, R, $Get6<T, K1, K2, K3, K4, K5, K6, R, ThisContext>>;
|
|
93
|
-
type $Get8<+T, +K1, +K2, +K3, +K4, +K5, +K6, +K7, +K8, +R, +ThisContext> =
|
|
94
|
-
CowContext<PropType8<T, K1, K2, K3, K4, K5, K6, K7, K8>, R, $Get7<T, K1, K2, K3, K4, K5, K6, K7, R, ThisContext>>;
|
|
95
|
-
|
|
96
|
-
declare export class CowContext<
|
|
97
|
-
+T: mixed,
|
|
98
|
-
+R: mixed = mixed,
|
|
99
|
-
+ParentContext: CowAnyContext<R> | null = CowAnyContext<R> | null,
|
|
100
|
-
> {
|
|
101
|
-
read(): T;
|
|
102
|
-
write(): ShallowReadWrite<T>;
|
|
103
|
-
get(): this;
|
|
104
|
-
get<K1: KeyType<T>>(prop1: K1): $Get1<T, K1, R, this>;
|
|
105
|
-
get<K1: KeyType<T>, K2: KeyType2<T, K1>>(prop1: K1, prop2: K2): $Get2<T, K1, K2, R, this>;
|
|
106
|
-
get<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>>(prop1: K1, prop2: K2, prop3: K3): $Get3<T, K1, K2, K3, R, this>;
|
|
107
|
-
get<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4): $Get4<T, K1, K2, K3, K4, R, this>;
|
|
108
|
-
get<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5): $Get5<T, K1, K2, K3, K4, K5, R, this>;
|
|
109
|
-
get<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>, K6: KeyType6<T, K1, K2, K3, K4, K5>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, prop6: K6): $Get6<T, K1, K2, K3, K4, K5, K6, R, this>;
|
|
110
|
-
get<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>, K6: KeyType6<T, K1, K2, K3, K4, K5>, K7: KeyType7<T, K1, K2, K3, K4, K5, K6>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, prop6: K6, prop7: K7): $Get7<T, K1, K2, K3, K4, K5, K6, K7, R, this>;
|
|
111
|
-
get<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>, K6: KeyType6<T, K1, K2, K3, K4, K5>, K7: KeyType7<T, K1, K2, K3, K4, K5, K6>, K8: KeyType8<T, K1, K2, K3, K4, K5, K6, K7>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, prop6: K6, prop7: K7, prop8: K8): $Get8<T, K1, K2, K3, K4, K5, K6, K7, K8, R, this>;
|
|
112
|
-
set(newValue: T): this;
|
|
113
|
-
set<K1: KeyType<T>>(prop1: K1, newValue: PropType<T, K1>): this;
|
|
114
|
-
set<K1: KeyType<T>, K2: KeyType2<T, K1>>(prop1: K1, prop2: K2, newValue: PropType2<T, K1, K2>): this;
|
|
115
|
-
set<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>>(prop1: K1, prop2: K2, prop3: K3, newValue: PropType3<T, K1, K2, K3>): this;
|
|
116
|
-
set<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, newValue: PropType4<T, K1, K2, K3, K4>): this;
|
|
117
|
-
set<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, newValue: PropType5<T, K1, K2, K3, K4, K5>): this;
|
|
118
|
-
set<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>, K6: KeyType6<T, K1, K2, K3, K4, K5>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, prop6: K6, newValue: PropType6<T, K1, K2, K3, K4, K5, K6>): this;
|
|
119
|
-
set<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>, K6: KeyType6<T, K1, K2, K3, K4, K5>, K7: KeyType7<T, K1, K2, K3, K4, K5, K6>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, prop6: K6, prop7: K7, newValue: PropType7<T, K1, K2, K3, K4, K5, K6, K7>): this;
|
|
120
|
-
set<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>, K6: KeyType6<T, K1, K2, K3, K4, K5>, K7: KeyType7<T, K1, K2, K3, K4, K5, K6>, K8: KeyType8<T, K1, K2, K3, K4, K5, K6, K7>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, prop6: K6, prop7: K7, prop8: K8, newValue: PropType8<T, K1, K2, K3, K4, K5, K6, K7, K8>): this;
|
|
121
|
-
update(updater: (this) => mixed): this;
|
|
122
|
-
update<K1: KeyType<T>>(prop1: K1, updater: ($Get1<T, K1, R, this>) => mixed): this;
|
|
123
|
-
update<K1: KeyType<T>, K2: KeyType2<T, K1>>(prop1: K1, prop2: K2, updater: ($Get2<T, K1, K2, R, this>) => mixed): this;
|
|
124
|
-
update<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>>(prop1: K1, prop2: K2, prop3: K3, updater: ($Get3<T, K1, K2, K3, R, this>) => mixed): this;
|
|
125
|
-
update<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, updater: ($Get4<T, K1, K2, K3, K4, R, this>) => mixed): this;
|
|
126
|
-
update<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, updater: ($Get5<T, K1, K2, K3, K4, K5, R, this>) => mixed): this;
|
|
127
|
-
update<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>, K6: KeyType6<T, K1, K2, K3, K4, K5>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, prop6: K6, updater: ($Get6<T, K1, K2, K3, K4, K5, K6, R, this>) => mixed): this;
|
|
128
|
-
update<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>, K6: KeyType6<T, K1, K2, K3, K4, K5>, K7: KeyType7<T, K1, K2, K3, K4, K5, K6>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, prop6: K6, prop7: K7, updater: ($Get7<T, K1, K2, K3, K4, K5, K6, K7, R, this>) => mixed): this;
|
|
129
|
-
update<K1: KeyType<T>, K2: KeyType2<T, K1>, K3: KeyType3<T, K1, K2>, K4: KeyType4<T, K1, K2, K3>, K5: KeyType5<T, K1, K2, K3, K4>, K6: KeyType6<T, K1, K2, K3, K4, K5>, K7: KeyType7<T, K1, K2, K3, K4, K5, K6>, K8: KeyType8<T, K1, K2, K3, K4, K5, K6, K7>>(prop1: K1, prop2: K2, prop3: K3, prop4: K4, prop5: K5, prop6: K6, prop7: K7, prop8: K8, updater: ($Get8<T, K1, K2, K3, K4, K5, K6, K7, K8, R, this>) => mixed): this;
|
|
130
|
-
parent(): ParentContext;
|
|
131
|
-
root(): CowRootContext<R>;
|
|
132
|
-
revoke(): void;
|
|
133
|
-
isRevoked(): boolean;
|
|
134
|
-
final(): T;
|
|
135
|
-
finalRoot(): R;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
declare export default function mutate<T: MutatableObject>(
|
|
139
|
-
source: T,
|
|
140
|
-
): CowRootContext<T>;
|
package/index.test-d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
expectType,
|
|
3
|
-
expectNotType,
|
|
4
|
-
expectError,
|
|
5
|
-
} from 'tsd';
|
|
6
|
-
|
|
7
|
-
import mutate, {
|
|
8
|
-
type CowContext,
|
|
9
|
-
type CowRootContext,
|
|
10
|
-
} from './index';
|
|
11
|
-
|
|
12
|
-
interface RoRoot {
|
|
13
|
-
readonly obj: RoValueContainer;
|
|
14
|
-
readonly arr: ReadonlyArray<RoValueContainer>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface RwRoot {
|
|
18
|
-
obj: RoValueContainer;
|
|
19
|
-
arr: ReadonlyArray<RoValueContainer>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface RoValueContainer {
|
|
23
|
-
readonly value: string;
|
|
24
|
-
readonly nested: RoValueContainer;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const _root: any = {
|
|
28
|
-
obj: {
|
|
29
|
-
value: '',
|
|
30
|
-
nested: null,
|
|
31
|
-
},
|
|
32
|
-
arr: [],
|
|
33
|
-
};
|
|
34
|
-
_root.obj.nested = _root.obj;
|
|
35
|
-
const root: RoRoot = _root;
|
|
36
|
-
|
|
37
|
-
const ctx = mutate(root);
|
|
38
|
-
|
|
39
|
-
expectType<RoRoot>(ctx.read());
|
|
40
|
-
expectNotType<RwRoot>(ctx.read());
|
|
41
|
-
|
|
42
|
-
expectType<RwRoot>(ctx.write());
|
|
43
|
-
expectNotType<RoRoot>(ctx.write());
|
|
44
|
-
|
|
45
|
-
type ObjContext = CowContext<RoValueContainer, RoRoot, CowRootContext<RoRoot>>;
|
|
46
|
-
|
|
47
|
-
expectType<CowRootContext<RoRoot>>(ctx.get());
|
|
48
|
-
expectType<ObjContext>(ctx.get('obj'));
|
|
49
|
-
expectType<never>(ctx.get('does', 'not', 'exist'));
|
|
50
|
-
|
|
51
|
-
expectType<CowRootContext<RoRoot>>(ctx.set('obj', 'value', ''));
|
|
52
|
-
expectType<CowRootContext<RoRoot>>(ctx.set('obj', 'nested', 'value', ''));
|
|
53
|
-
expectError(ctx.set('obj', 'value', 0));
|
|
54
|
-
expectError(ctx.set('obj', 'nested', 'value', 0));
|
|
55
|
-
expectError(ctx.set('does', 'not', 'exist'));
|
|
56
|
-
|
|
57
|
-
expectType<CowRootContext<RoRoot>>(ctx.update((rootCtx: CowRootContext<RoRoot>) => undefined));
|
|
58
|
-
expectType<CowRootContext<RoRoot>>(ctx.update('obj', (childCtx: ObjContext) => undefined));
|
|
59
|
-
expectError(ctx.update());
|
|
60
|
-
expectError(ctx.update('no', 'updater'));
|