@rimbu/deep 0.14.5 → 1.0.0-alpha.2

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 (86) hide show
  1. package/{src/deep.ts → dist/bun/deep.mts} +7 -7
  2. package/{src/index.ts → dist/bun/index.mts} +5 -5
  3. package/dist/bun/internal.mts +8 -0
  4. package/{src/match.ts → dist/bun/match.mts} +6 -6
  5. package/{src/patch.ts → dist/bun/patch.mts} +9 -4
  6. package/{src/path.ts → dist/bun/path.mts} +2 -2
  7. package/{src/selector.ts → dist/bun/selector.mts} +1 -1
  8. package/dist/cjs/deep.cjs +590 -0
  9. package/dist/cjs/index.cjs +663 -0
  10. package/dist/cjs/internal.cjs +583 -0
  11. package/dist/cjs/match.cjs +376 -0
  12. package/dist/cjs/patch.cjs +105 -0
  13. package/dist/cjs/path.cjs +585 -0
  14. package/dist/cjs/protected.cjs +18 -0
  15. package/dist/cjs/selector.cjs +581 -0
  16. package/dist/cjs/tuple.cjs +73 -0
  17. package/dist/{module/deep.js → esm/deep.mjs} +6 -6
  18. package/dist/esm/deep.mjs.map +1 -0
  19. package/dist/{module/index.js → esm/index.mjs} +5 -5
  20. package/dist/esm/index.mjs.map +1 -0
  21. package/dist/esm/internal.mjs +5 -0
  22. package/dist/esm/internal.mjs.map +1 -0
  23. package/dist/{module/match.js → esm/match.mjs} +21 -21
  24. package/dist/esm/match.mjs.map +1 -0
  25. package/dist/{module/patch.js → esm/patch.mjs} +5 -5
  26. package/dist/esm/patch.mjs.map +1 -0
  27. package/dist/{module/path.js → esm/path.mjs} +2 -2
  28. package/dist/esm/path.mjs.map +1 -0
  29. package/dist/esm/protected.mjs +2 -0
  30. package/dist/esm/protected.mjs.map +1 -0
  31. package/dist/{module/selector.js → esm/selector.mjs} +2 -2
  32. package/dist/esm/selector.mjs.map +1 -0
  33. package/dist/{module/tuple.js → esm/tuple.mjs} +1 -1
  34. package/dist/esm/tuple.mjs.map +1 -0
  35. package/dist/types/{deep.d.ts → deep.d.mts} +6 -6
  36. package/dist/types/{index.d.ts → index.d.mts} +5 -5
  37. package/dist/types/internal.d.mts +7 -0
  38. package/dist/types/{match.d.ts → match.d.mts} +3 -3
  39. package/dist/types/{patch.d.ts → patch.d.mts} +3 -3
  40. package/dist/types/{path.d.ts → path.d.mts} +2 -2
  41. package/dist/types/{selector.d.ts → selector.d.mts} +1 -1
  42. package/package.json +29 -23
  43. package/src/deep.mts +364 -0
  44. package/src/index.mts +23 -0
  45. package/src/internal.mts +8 -0
  46. package/src/match.mts +700 -0
  47. package/src/patch.mts +262 -0
  48. package/src/path.mts +430 -0
  49. package/src/protected.mts +30 -0
  50. package/src/selector.mts +90 -0
  51. package/src/tuple.mts +197 -0
  52. package/dist/main/deep.js +0 -211
  53. package/dist/main/deep.js.map +0 -1
  54. package/dist/main/index.js +0 -19
  55. package/dist/main/index.js.map +0 -1
  56. package/dist/main/internal.js +0 -9
  57. package/dist/main/internal.js.map +0 -1
  58. package/dist/main/match.js +0 -284
  59. package/dist/main/match.js.map +0 -1
  60. package/dist/main/patch.js +0 -133
  61. package/dist/main/patch.js.map +0 -1
  62. package/dist/main/path.js +0 -126
  63. package/dist/main/path.js.map +0 -1
  64. package/dist/main/protected.js +0 -3
  65. package/dist/main/protected.js.map +0 -1
  66. package/dist/main/selector.js +0 -40
  67. package/dist/main/selector.js.map +0 -1
  68. package/dist/main/tuple.js +0 -164
  69. package/dist/main/tuple.js.map +0 -1
  70. package/dist/module/deep.js.map +0 -1
  71. package/dist/module/index.js.map +0 -1
  72. package/dist/module/internal.js +0 -4
  73. package/dist/module/internal.js.map +0 -1
  74. package/dist/module/match.js.map +0 -1
  75. package/dist/module/patch.js.map +0 -1
  76. package/dist/module/path.js.map +0 -1
  77. package/dist/module/protected.js +0 -2
  78. package/dist/module/protected.js.map +0 -1
  79. package/dist/module/selector.js.map +0 -1
  80. package/dist/module/tuple.js.map +0 -1
  81. package/dist/types/internal.d.ts +0 -7
  82. package/src/internal.ts +0 -8
  83. /package/{src/protected.ts → dist/bun/protected.mts} +0 -0
  84. /package/{src/tuple.ts → dist/bun/tuple.mts} +0 -0
  85. /package/dist/types/{protected.d.ts → protected.d.mts} +0 -0
  86. /package/dist/types/{tuple.d.ts → tuple.d.mts} +0 -0
@@ -0,0 +1,30 @@
1
+ import type { IsAny, IsPlainObj } from '@rimbu/base';
2
+
3
+ /**
4
+ * A deep readonly typed version of given type T. Makes all properties or elements read only.
5
+ * It maps types using the following rules:
6
+ * - arrays and tuples become readonly counterparts, and all element types are wrapped in `Protected` if applicable
7
+ * - Maps of key type K and value type V become Maps of key type `Protected<K>` and value type `Protected<V>`
8
+ * - Sets of element type E become Sets of element type `Protected<E>`
9
+ * - Promises of value type E become Promises of value type `Protected<E>`
10
+ * - Objects that have only simple properties (no functions or iterators) will have all the properties as Protected if applicable
11
+ * - Any other type will not be mapped
12
+ * @typeparam T - the input type
13
+ */
14
+ export type Protected<T> = IsAny<T> extends true
15
+ ? // to prevent infinite recursion, any will be any
16
+ T
17
+ : T extends readonly any[] & infer A
18
+ ? // convert all keys to readonly and all values to `Protected`
19
+ { readonly [K in keyof A]: Protected<A[K]> }
20
+ : T extends Map<infer K, infer V>
21
+ ? ReadonlyMap<Protected<K>, Protected<V>>
22
+ : T extends Set<infer E>
23
+ ? ReadonlySet<Protected<E>>
24
+ : T extends Promise<infer E>
25
+ ? Promise<Protected<E>>
26
+ : IsPlainObj<T> extends true
27
+ ? // convert all keys to readonly and all values to `Protected`
28
+ { readonly [K in keyof T]: Protected<T[K]> }
29
+ : // nothing to do, just return `T`
30
+ T;
@@ -0,0 +1,90 @@
1
+ import type { IsAnyFunc, IsArray } from '@rimbu/base';
2
+ import { Deep, Path, type Protected } from './internal.mjs';
3
+
4
+ /**
5
+ * Type defining the allowed selectors on an object of type `T`.
6
+ * Selectors can be:
7
+ * - a path string into type `T`.
8
+ * - a function receiving a `Protected` version of type `T`, and returning an arbitrary value.
9
+ * - a tuple of `Selectors` for type `T`
10
+ * - an object where the property values are `Selectors` for type `T`.
11
+ * @typeparam T - the source value type.
12
+ */
13
+ export type Selector<T> =
14
+ | Path.Get<T>
15
+ | ((value: Protected<T>) => any)
16
+ | readonly Selector<T>[]
17
+ | { readonly [key: string | symbol]: Selector<T> };
18
+
19
+ export namespace Selector {
20
+ /**
21
+ * Type defining the shape of allowed selectors, used to improve compiler checking.
22
+ * @typeparam SL - the selector type
23
+ */
24
+ export type Shape<SL> = IsAnyFunc<SL> extends true
25
+ ? // functions are allowed, type provided by `Selector`
26
+ SL
27
+ : IsArray<SL> extends true
28
+ ? // ensure tuple type is preserved
29
+ readonly [...(SL extends readonly unknown[] ? SL : never)]
30
+ : SL extends { readonly [key: string | number | symbol]: unknown }
31
+ ? // ensure all object properties satisfy `Shape`
32
+ { readonly [K in keyof SL]: Selector.Shape<SL[K]> }
33
+ : // nothing to check
34
+ SL;
35
+
36
+ /**
37
+ * Type defining the result type of applying the SL selector type to the T value type.
38
+ * @typeparam T - the source value type
39
+ * @typeparam SL - the selector type
40
+ */
41
+ export type Result<T, SL> = Selector<T> extends SL
42
+ ? never
43
+ : SL extends (...args: any[]) => infer R
44
+ ? R
45
+ : SL extends string
46
+ ? Path.Result<T, SL>
47
+ : {
48
+ readonly [K in keyof SL]: Selector.Result<T, SL[K]>;
49
+ };
50
+ }
51
+
52
+ /**
53
+ * Returns the result of applying the given `selector` shape to the given `source` value.
54
+ * @typeparam T - the patch value type
55
+ * @typeparam SL - the selector shape type
56
+ * @param source - the source value to select from
57
+ * @param selector - a shape indicating the selection from the source values
58
+ * @example
59
+ * ```ts
60
+ * const item = { a: { b: 1, c: 'a' } };
61
+ * Deep.select(item, { q: 'a.c', y: ['a.b', 'a.c'], z: (v) => v.a.b + 1 });
62
+ * // => { q: 'a', y: [1, 'a'], z: 2 }
63
+ * ```
64
+ */
65
+ export function select<T, SL extends Selector<T>>(
66
+ source: T,
67
+ selector: Selector.Shape<SL>
68
+ ): Selector.Result<T, SL> {
69
+ if (typeof selector === 'function') {
70
+ // selector is function, resolve selector function
71
+ return (selector as any)(source as Protected<T>);
72
+ } else if (typeof selector === 'string') {
73
+ // selector is string path, get the value at the given path
74
+ return Deep.getAt(source, selector as Path.Get<T>) as any;
75
+ } else if (Array.isArray(selector)) {
76
+ // selector is tuple, get each tuple item value
77
+ return selector.map((s) => select(source, s)) as any;
78
+ }
79
+
80
+ // selector is object
81
+
82
+ const result: any = {};
83
+
84
+ for (const key in selector as any) {
85
+ // set each selected object key to the selector value
86
+ result[key] = select(source, (selector as any)[key]);
87
+ }
88
+
89
+ return result;
90
+ }
package/src/tuple.mts ADDED
@@ -0,0 +1,197 @@
1
+ import { Arr } from '@rimbu/base';
2
+ import type { Update } from '@rimbu/common';
3
+
4
+ /**
5
+ * A readonly array of fixed length and types.
6
+ */
7
+ export type Tuple<T extends Tuple.Source> = Readonly<T>;
8
+
9
+ export namespace Tuple {
10
+ /**
11
+ * A non-empty readonly array that can serve as a source for a Tuple.
12
+ */
13
+ export type NonEmptySource = readonly [unknown, ...unknown[]];
14
+
15
+ /**
16
+ * A readonly array that can serve as a source for a Tuple.
17
+ */
18
+ export type Source = readonly unknown[];
19
+
20
+ export type IsTuple<T> = T extends { length: infer L }
21
+ ? 0 extends L
22
+ ? false
23
+ : true
24
+ : false;
25
+
26
+ /**
27
+ * Returns the indices/keys that are in a tuple.
28
+ * @typeparam T - the input tuple type
29
+ */
30
+ export type KeysOf<T> = { [K in keyof T]: K }[keyof T & number];
31
+
32
+ /**
33
+ * Convenience method to type Tuple types
34
+ * @param values - the values of the tuple
35
+ * @example
36
+ * ```ts
37
+ * const t = Tuple.of(1, 'a', true)
38
+ * // type of t => Tuple<[number, string, boolean]>
39
+ * ```
40
+ */
41
+ export function of<T extends Tuple.NonEmptySource>(...values: T): Tuple<T> {
42
+ return values as any;
43
+ }
44
+
45
+ /**
46
+ * Returns the item at the given `index` in the givn `tuple`.
47
+ * @param tuple - the tuple to get the item from
48
+ * @param index - the index in of the tuple element
49
+ * @example
50
+ * ```ts
51
+ * const t = Tuple.of(1, 'a', true)
52
+ * console.log(Tuple.getIndex(t, 1))
53
+ * // => 'a'
54
+ * ```
55
+ */
56
+ export function getIndex<T extends Tuple.Source, K extends keyof T = keyof T>(
57
+ tuple: T,
58
+ index: K
59
+ ): T[K] {
60
+ return tuple[index];
61
+ }
62
+
63
+ /**
64
+ * Returns the first element of a Tuple.
65
+ * @param tuple - the source tuple
66
+ * @example
67
+ * ```ts
68
+ * const t = Tuple.of(1, 'a', true)
69
+ * console.log(Tuple.first(t))
70
+ * // => 1
71
+ * ```
72
+ */
73
+ export function first<T extends Tuple.Source>(tuple: T): T[0] {
74
+ return tuple[0];
75
+ }
76
+
77
+ /**
78
+ * Returns the second element of a Tuple.
79
+ * @param tuple - the source tuple
80
+ * @example
81
+ * ```ts
82
+ * const t = Tuple.of(1, 'a', true)
83
+ * console.log(Tuple.second(t))
84
+ * // => 'a'
85
+ * ```
86
+ */
87
+ export function second<T extends Tuple.Source>(tuple: T): T[1] {
88
+ return tuple[1];
89
+ }
90
+
91
+ /**
92
+ * Returns the last element of a Tuple.
93
+ * @param tuple - the source tuple
94
+ * @example
95
+ * ```ts
96
+ * const t = Tuple.of(1, 'a', true)
97
+ * console.log(Tuple.last(t))
98
+ * // => true
99
+ * ```
100
+ */
101
+ export function last<T extends readonly unknown[], R>(
102
+ tuple: readonly [...T, R]
103
+ ): R {
104
+ return tuple[tuple.length - 1] as any;
105
+ }
106
+
107
+ /**
108
+ * Returns a copy of the given `tuple` where the element at given `index` is updated with the
109
+ * given `updater`.
110
+ * @param tuple - the source tuple
111
+ * @param index - the index in the tuple
112
+ * @param updater - the updater for the value
113
+ * @example
114
+ * ```ts
115
+ * const t = Tuple.of(1, 'a', true)
116
+ * console.log(Tuple.updateAt(t, 1, 'b'))
117
+ * // => [1, 'b', true]
118
+ * ```
119
+ */
120
+ export function updateAt<T extends Tuple.Source, K extends keyof T = keyof T>(
121
+ tuple: T,
122
+ index: K,
123
+ updater: Update<T[K]>
124
+ ): T {
125
+ return Arr.update(tuple, index as number, updater) as T;
126
+ }
127
+
128
+ /**
129
+ * Returns the given `tuple` with the given `values` appended.
130
+ * @param tuple - the source tuple
131
+ * @param values - the values to append
132
+ * @example
133
+ * ```ts
134
+ * const t = Tuple.of(1, 'a')
135
+ * console.log(Tuple.append(t, true, 5))
136
+ * // => [1, 'a', true, 5]
137
+ * ```
138
+ */
139
+ export function append<
140
+ T extends Tuple.Source,
141
+ V extends readonly [unknown, ...unknown[]]
142
+ >(tuple: T, ...values: V): readonly [...T, ...V] {
143
+ return [...tuple, ...values];
144
+ }
145
+
146
+ /**
147
+ * Returns a Tuple containing the elements of given `tuple1` followed by the elements
148
+ * of given `tuple2`.
149
+ * @param tuple1 - the first Tuple
150
+ * @param tuple2 - the second Tuple
151
+ * @example
152
+ * ```ts
153
+ * const t1 = Tuple.of(1, 'a')
154
+ * const t2 = Tuple.of(true, 5)
155
+ * console.log(Tuple.concat(t1, t2))
156
+ * // => [1, 'a', true, 5]
157
+ * ```
158
+ */
159
+ export function concat<T1 extends Tuple.Source, T2 extends Tuple.Source>(
160
+ tuple1: T1,
161
+ tuple2: T2
162
+ ): readonly [...T1, ...T2] {
163
+ return tuple1.concat(tuple2) as any;
164
+ }
165
+
166
+ /**
167
+ * Returns a Tuple containing all but the last element of the given `tuple`.
168
+ * @param tuple - the source tuple
169
+ * @example
170
+ * ```ts
171
+ * const t = Tuple.of(1, 'a', true)
172
+ * console.log(Tuple.init(t))
173
+ * // => [1, 'a']
174
+ * ```
175
+ */
176
+ export function init<T extends readonly unknown[]>(
177
+ tuple: readonly [...T, unknown]
178
+ ): Readonly<T> {
179
+ return Arr.init(tuple) as any;
180
+ }
181
+
182
+ /**
183
+ * Returns a Tuple containing all but the first element of the given `tuple`.
184
+ * @param tuple - the source tuple
185
+ * @example
186
+ * ```ts
187
+ * const t = Tuple.of(1, 'a', true)
188
+ * console.log(Tuple.tail(t))
189
+ * // => ['a', true]
190
+ * ```
191
+ */
192
+ export function tail<T extends readonly [...unknown[]]>(
193
+ tuple: readonly [unknown, ...T]
194
+ ): Readonly<T> {
195
+ return Arr.tail(tuple) as any;
196
+ }
197
+ }
package/dist/main/deep.js DELETED
@@ -1,211 +0,0 @@
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
@@ -1 +0,0 @@
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,CAAoC,CAAC;AAC1D,CAAC;AAJD,8BAIC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,WAAW,CACzB,IAAO,EACP,SAAwD;IAExD,OAAO,UAAC,MAAM,IAAK,OAAA,eAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,SAAgB,CAAC,EAA5C,CAA4C,CAAC;AAClE,CAAC;AALD,kCAKC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,SAAS,CAAI,OAAiB;IAC5C,OAAO,UAAC,MAAM,IAAK,OAAA,eAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,EAA3B,CAA2B,CAAC;AACjD,CAAC;AAFD,8BAEC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,OAAO,CACrB,MAAS,EACT,IAAO,EACP,OAAiC;IAEjC,OAAO,eAAI,CAAC,KAAK,CAAC,eAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;AACvD,CAAC;AAND,0BAMC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,WAAW,CACzB,IAAO,EACP,OAAsC;IAEtC,OAAO,UAAC,MAAM,IAAK,OAAA,eAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,OAAc,CAAC,EAA1C,CAA0C,CAAC;AAChE,CAAC;AALD,kCAKC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,UAAU,CACxB,QAA4B;IAE5B,OAAO,UAAC,MAAM,IAAK,OAAA,eAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EAA7B,CAA6B,CAAC;AACnD,CAAC;AAJD,gCAIC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,QAAQ,CAKtB,MAAS,EACT,IAAO,EACP,QAA4B;IAE5B,OAAO,eAAI,CAAC,MAAM,CAAC,eAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,CAAC,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"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- /**
3
- * @packageDocumentation
4
- *
5
- * The `@rimbu/deep` package provides utilities to patch and match plain JavaScript objects.<br/>
6
- * <br/>
7
- * See the [Rimbu docs Deep overview page](/docs/deep/overview) for more information.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Deep = exports.Path = exports.Tuple = void 0;
11
- var tslib_1 = require("tslib");
12
- var tuple_1 = require("./tuple");
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;
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Deep = exports.Path = void 0;
4
- var tslib_1 = require("tslib");
5
- var path_1 = require("./path");
6
- Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return path_1.Path; } });
7
- var Deep = tslib_1.__importStar(require("./deep"));
8
- exports.Deep = Deep;
9
- //# sourceMappingURL=internal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":";;;;AACA,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AAKb,mDAA+B;AACtB,oBAAI"}