@rimbu/deep 0.11.3 → 0.12.1

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.
Files changed (53) hide show
  1. package/dist/main/deep.js +211 -0
  2. package/dist/main/deep.js.map +1 -0
  3. package/dist/main/index.js +7 -9
  4. package/dist/main/index.js.map +1 -1
  5. package/dist/main/internal.js +6 -4
  6. package/dist/main/internal.js.map +1 -1
  7. package/dist/main/match.js +160 -199
  8. package/dist/main/match.js.map +1 -1
  9. package/dist/main/patch.js +101 -125
  10. package/dist/main/patch.js.map +1 -1
  11. package/dist/main/path.js +109 -62
  12. package/dist/main/path.js.map +1 -1
  13. package/dist/main/protected.js +0 -19
  14. package/dist/main/protected.js.map +1 -1
  15. package/dist/main/selector.js +40 -0
  16. package/dist/main/selector.js.map +1 -0
  17. package/dist/main/tuple.js.map +1 -1
  18. package/dist/module/deep.js +192 -0
  19. package/dist/module/deep.js.map +1 -0
  20. package/dist/module/index.js +9 -1
  21. package/dist/module/index.js.map +1 -1
  22. package/dist/module/internal.js +4 -4
  23. package/dist/module/internal.js.map +1 -1
  24. package/dist/module/match.js +159 -179
  25. package/dist/module/match.js.map +1 -1
  26. package/dist/module/patch.js +91 -112
  27. package/dist/module/patch.js.map +1 -1
  28. package/dist/module/path.js +99 -44
  29. package/dist/module/path.js.map +1 -1
  30. package/dist/module/protected.js +1 -17
  31. package/dist/module/protected.js.map +1 -1
  32. package/dist/module/selector.js +36 -0
  33. package/dist/module/selector.js.map +1 -0
  34. package/dist/module/tuple.js.map +1 -1
  35. package/dist/types/deep.d.ts +284 -0
  36. package/dist/types/index.d.ts +10 -1
  37. package/dist/types/internal.d.ts +7 -4
  38. package/dist/types/match.d.ts +74 -80
  39. package/dist/types/patch.d.ts +57 -50
  40. package/dist/types/path.d.ts +177 -34
  41. package/dist/types/protected.d.ts +1 -16
  42. package/dist/types/selector.d.ts +47 -0
  43. package/dist/types/tuple.d.ts +10 -0
  44. package/package.json +3 -3
  45. package/src/deep.ts +364 -0
  46. package/src/index.ts +14 -10
  47. package/src/internal.ts +7 -4
  48. package/src/match.ts +396 -212
  49. package/src/patch.ts +173 -176
  50. package/src/path.ts +400 -74
  51. package/src/protected.ts +14 -25
  52. package/src/selector.ts +90 -0
  53. package/src/tuple.ts +12 -0
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withType = exports.selectAtWith = exports.selectAt = exports.selectWith = exports.matchAtWith = exports.matchAt = exports.matchWith = exports.patchAtWith = exports.patchWith = exports.getAtWith = exports.protect = exports.select = exports.patchAt = exports.getAt = exports.patch = exports.match = void 0;
4
+ var internal_1 = require("./internal");
5
+ var match_1 = require("./match");
6
+ Object.defineProperty(exports, "match", { enumerable: true, get: function () { return match_1.match; } });
7
+ var patch_1 = require("./patch");
8
+ Object.defineProperty(exports, "patch", { enumerable: true, get: function () { return patch_1.patch; } });
9
+ var path_1 = require("./path");
10
+ Object.defineProperty(exports, "getAt", { enumerable: true, get: function () { return path_1.getAt; } });
11
+ Object.defineProperty(exports, "patchAt", { enumerable: true, get: function () { return path_1.patchAt; } });
12
+ var selector_1 = require("./selector");
13
+ Object.defineProperty(exports, "select", { enumerable: true, get: function () { return selector_1.select; } });
14
+ /**
15
+ * Returns the same value wrapped in the `Protected` type.
16
+ * @typeparam T - the source value type
17
+ * @param source - the value to wrap
18
+ * @note does not perform any runtime protection, it is only a utility to easily add the `Protected`
19
+ * type to a value
20
+ * @example
21
+ * ```ts
22
+ * const obj = Deep.protect({ a: 1, b: { c: true, d: [1] } })
23
+ * obj.a = 2 // compiler error: a is readonly
24
+ * obj.b.c = false // compiler error: c is readonly
25
+ * obj.b.d.push(2) // compiler error: d is a readonly array
26
+ * (obj as any).b.d.push(2) // will actually mutate the object
27
+ * ```
28
+ */
29
+ function protect(source) {
30
+ return source;
31
+ }
32
+ exports.protect = protect;
33
+ /**
34
+ * Returns a function that gets the value at the given string `path` inside an object.
35
+ * @typeparam T - the input value type
36
+ * @typeparam P - the string literal path type in the object
37
+ * @param path - the string path in the object
38
+ * @param source - the value from which to extract the path value
39
+ * @example
40
+ * ```ts
41
+ * const items = [{ a: { b: 1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
42
+ * items.map(Deep.getAtWith('a.c'));
43
+ * // => ['a', 'b']
44
+ * ```
45
+ */
46
+ function getAtWith(path) {
47
+ return function (source) { return internal_1.Deep.getAt(source, path); };
48
+ }
49
+ exports.getAtWith = getAtWith;
50
+ /**
51
+ * Returns a function that patches a given `source` with the given `patchItems`.
52
+ * @typeparam T - the patch value type
53
+ * @typeparam TE - utility type
54
+ * @typeparam TT - utility type
55
+ * @param patchItem - the `Patch` definition to update the given value of type `T` with.
56
+ * @param source - the value to use the given `patchItem` on.
57
+ * @example
58
+ * ```ts
59
+ * const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
60
+ * items.map(Deep.patchWith([{ a: v => v + 1 }]));
61
+ * // => [{ a: 2, b: 'a' }, { a: 3, b: 'b' }]
62
+ * ```
63
+ */
64
+ function patchWith(patchItem) {
65
+ return function (source) { return internal_1.Deep.patch(source, patchItem); };
66
+ }
67
+ exports.patchWith = patchWith;
68
+ /**
69
+ * Returns a function that patches a given `value` with the given `patchItems` at the given `path`.
70
+ * @typeparam T - the patch value type
71
+ * @typeparam P - the string literal path type in the object
72
+ * @typeparam TE - utility type
73
+ * @typeparam TT - utility type
74
+ * @param path - the string path in the object
75
+ * @param patchItem - the `Patch` definition to update the value at the given `path` in `T` with.
76
+ * @param source - the value to use the given `patchItem` on at the given `path`.
77
+ * @example
78
+ * ```ts
79
+ * const items = [{ a: { b: 1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
80
+ * items.map(Deep.patchAtWith('a', [{ b: (v) => v + 1 }]));
81
+ * // => [{ a: { b: 2, c: 'a' } }, { a: { b: 3, c: 'b' } }]
82
+ * ```
83
+ */
84
+ function patchAtWith(path, patchItem) {
85
+ return function (source) { return internal_1.Deep.patchAt(source, path, patchItem); };
86
+ }
87
+ exports.patchAtWith = patchAtWith;
88
+ /**
89
+ * Returns a function that matches a given `value` with the given `matcher`.
90
+ * @typeparam T - the patch value type
91
+ * @param matcher - a matcher object that matches input values.
92
+ * @param source - the value to use the given `patchItem` on at the given `path`.
93
+ * @example
94
+ * ```ts
95
+ * const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
96
+ * items.filter(Deep.matchWith({ a: 2 }));
97
+ * // => [{ a: 2, b: 'b' }]
98
+ * ```
99
+ */
100
+ function matchWith(matcher) {
101
+ return function (source) { return internal_1.Deep.match(source, matcher); };
102
+ }
103
+ exports.matchWith = matchWith;
104
+ /**
105
+ * Returns true if the given `value` object matches the given `matcher` at the given `path`, false otherwise.
106
+ * @typeparam T - the input value type
107
+ * @typeparam P - the string literal path type in the object
108
+ * @param source - the input value
109
+ * @param path - the string path in the object
110
+ * @param matcher - a matcher object or a function taking the matcher API and returning a match object
111
+ * @example
112
+ * ```ts
113
+ * const input = { a: 1, b: { c: true, d: 'a' } }
114
+ * Deep.matchAt(input, 'b', { c: true })
115
+ * // => true
116
+ * ```
117
+ */
118
+ function matchAt(source, path, matcher) {
119
+ return internal_1.Deep.match(internal_1.Deep.getAt(source, path), matcher);
120
+ }
121
+ exports.matchAt = matchAt;
122
+ /**
123
+ * Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
124
+ * @typeparam T - the patch value type
125
+ * @typeparam P - the string literal path type in the object
126
+ * @typeparam TE - utility type
127
+ * @param path - the string path in the object
128
+ * @param matcher - a matcher object that matches input values.
129
+ * @param source - the value to use the given `matcher` on at the given `path`.
130
+ * @example
131
+ * ```ts
132
+ * const items = [{ a: { b: 1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
133
+ * items.filter(Deep.matchAtWith('a.b', 2));
134
+ * // => [{ a: 2, b: 'b' }]
135
+ * ```
136
+ */
137
+ function matchAtWith(path, matcher) {
138
+ return function (source) { return internal_1.Deep.matchAt(source, path, matcher); };
139
+ }
140
+ exports.matchAtWith = matchAtWith;
141
+ /**
142
+ * Returns a function that selects a certain shape from a given `value` with the given `selector`.
143
+ * @typeparam T - the patch value type
144
+ * @typeparam SL - the selector shape type
145
+ * @param selector - a shape indicating the selection from the source values
146
+ * @param source - the value to use the given `selector` on.
147
+ * @example
148
+ * ```ts
149
+ * const items = [{ a: { b: 1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
150
+ * items.map(Deep.selectWith({ q: 'a.c', z: ['a.b', v => v.a.b + 1] as const }));
151
+ * // => [{ q: 'a', z: [1, 2] }, { q: 'b', z: [2, 3] }]
152
+ * ```
153
+ */
154
+ function selectWith(selector) {
155
+ return function (source) { return internal_1.Deep.select(source, selector); };
156
+ }
157
+ exports.selectWith = selectWith;
158
+ /**
159
+ * Returns the result of applying the given `selector` shape to the given `source` value.
160
+ * @typeparam T - the patch value type
161
+ * @typeparam P - the string literal path type in the object
162
+ * @typeparam SL - the selector shape type
163
+ * @param source - the source value to select from
164
+ * @param path - the string path in the object
165
+ * @param selector - a shape indicating the selection from the source value at the given path
166
+ * @example
167
+ * ```ts
168
+ * const item = { a: { b: 1, c: 'a' } };
169
+ * Deep.selectAt(item, 'a', { q: 'c', z: ['b', v => v.b + 1] as const });
170
+ * // => { q: 'a', z: [1, 2] }
171
+ * ```
172
+ */
173
+ function selectAt(source, path, selector) {
174
+ return internal_1.Deep.select(internal_1.Deep.getAt(source, path), selector);
175
+ }
176
+ exports.selectAt = selectAt;
177
+ /**
178
+ * Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
179
+ * @typeparam T - the patch value type
180
+ * @typeparam P - the string literal path type in the object
181
+ * @typeparam SL - the selector shape type
182
+ * @param path - the string path in the object
183
+ * @param selector - a shape indicating the selection from the source values
184
+ * @example
185
+ * ```ts
186
+ * const items = [{ a: { b: 1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
187
+ * items.map(Deep.selectAtWith('a', { q: 'c', z: ['b', v => v.b + 1] as const }));
188
+ * // => [{ q: 'a', z: [1, 2] }, { q: 'b', z: [2, 3] }]
189
+ * ```
190
+ */
191
+ function selectAtWith(path, selector) {
192
+ return function (source) { return internal_1.Deep.selectAt(source, path, selector); };
193
+ }
194
+ exports.selectAtWith = selectAtWith;
195
+ /**
196
+ * Returns a curried API with a known target type. This can be useful for using the methods in
197
+ * contexts where the target type can be inferred from the usage.
198
+ * @typeparam T - the target type
199
+ * @example
200
+ * ```ts
201
+ * const s = { a: 1, b: { c: 'a', d: true }}
202
+ * const upd = Deep.withType<typeof s>().patchWith([{ d: (v) => !v }])
203
+ * upd(s)
204
+ * // => { a: 1, b: { c: 'a', d: false }}
205
+ * ```
206
+ */
207
+ function withType() {
208
+ return internal_1.Deep;
209
+ }
210
+ exports.withType = withType;
211
+ //# sourceMappingURL=deep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep.js","sourceRoot":"","sources":["../../src/deep.ts"],"names":[],"mappings":";;;AACA,uCAAkC;AAElC,iCAA4C;AAAnC,8FAAA,KAAK,OAAA;AACd,iCAA4C;AAAnC,8FAAA,KAAK,OAAA;AACd,+BAAmD;AAA1C,6FAAA,KAAK,OAAA;AAAE,+FAAA,OAAO,OAAA;AACvB,uCAAmD;AAA1C,kGAAA,MAAM,OAAA;AAGf;;;;;;;;;;;;;;GAcG;AACH,SAAgB,OAAO,CAAI,MAAS;IAClC,OAAO,MAAsB,CAAC;AAChC,CAAC;AAFD,0BAEC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,SAAS,CACvB,IAAO;IAEP,OAAO,UAAC,MAAM,IAAK,OAAA,eAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,EAAxB,CAAwB,CAAC;AAC9C,CAAC;AAJD,8BAIC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CACvB,SAAwB;IAExB,OAAO,UAAC,MAAM,IAAK,OAAA,eAAI,CAAC,KAAK,CAAC,MAAM,EAAE,SAAgB,CAAC,EAApC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C,CAAC;AACzD,CAAC;AAVD,4BAUC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,YAAY,CAK1B,IAAO,EACP,QAA4B;IAE5B,OAAO,UAAC,MAAM,IAAK,OAAA,eAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,EAArC,CAAqC,CAAC;AAC3D,CAAC;AATD,oCASC;AAkID;;;;;;;;;;;GAWG;AACH,SAAgB,QAAQ;IACtB,OAAO,eAAI,CAAC;AACd,CAAC;AAFD,4BAEC"}
@@ -7,15 +7,13 @@
7
7
  * See the [Rimbu docs Deep overview page](/docs/deep/overview) for more information.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Tuple = exports.Protected = exports.Path = exports.Match = exports.match = exports.Patch = exports.patchNested = exports.patch = void 0;
11
- var internal_1 = require("./internal");
12
- Object.defineProperty(exports, "patch", { enumerable: true, get: function () { return internal_1.patch; } });
13
- Object.defineProperty(exports, "patchNested", { enumerable: true, get: function () { return internal_1.patchNested; } });
14
- Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return internal_1.Patch; } });
15
- Object.defineProperty(exports, "match", { enumerable: true, get: function () { return internal_1.match; } });
16
- Object.defineProperty(exports, "Match", { enumerable: true, get: function () { return internal_1.Match; } });
17
- Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return internal_1.Path; } });
18
- Object.defineProperty(exports, "Protected", { enumerable: true, get: function () { return internal_1.Protected; } });
10
+ exports.Deep = exports.Path = exports.Tuple = void 0;
11
+ var tslib_1 = require("tslib");
19
12
  var tuple_1 = require("./tuple");
20
13
  Object.defineProperty(exports, "Tuple", { enumerable: true, get: function () { return tuple_1.Tuple; } });
14
+ var internal_1 = require("./internal");
15
+ Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return internal_1.Path; } });
16
+ tslib_1.__exportStar(require("./deep"), exports);
17
+ var Deep = tslib_1.__importStar(require("./deep"));
18
+ exports.Deep = Deep;
21
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,uCAQoB;AAPlB,iGAAA,KAAK,OAAA;AACL,uGAAA,WAAW,OAAA;AACX,iGAAA,KAAK,OAAA;AACL,iGAAA,KAAK,OAAA;AACL,iGAAA,KAAK,OAAA;AACL,gGAAA,IAAI,OAAA;AACJ,qGAAA,SAAS,OAAA;AAGX,iCAAgC;AAAvB,8FAAA,KAAK,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;AAEH,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AAGd,uCAA6D;AAApD,gGAAA,IAAI,OAAA;AAEb,iDAAuB;AAEvB,mDAA+B;AAM7B,oBAAI"}
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Deep = exports.Path = void 0;
3
4
  var tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./protected"), exports);
5
- tslib_1.__exportStar(require("./match"), exports);
6
- tslib_1.__exportStar(require("./patch"), exports);
7
- tslib_1.__exportStar(require("./path"), exports);
5
+ var path_1 = require("./path");
6
+ Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return path_1.Path; } });
7
+ var match_1 = require("./match");
8
+ var Deep = tslib_1.__importStar(require("./deep"));
9
+ exports.Deep = Deep;
8
10
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAE5B,kDAAwB;AACxB,kDAAwB;AACxB,iDAAuB"}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":";;;;AACA,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,iCAAqC;AAIrC,mDAA+B;AACtB,oBAAI"}