@rimbu/deep 2.0.4 → 2.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimbu/deep",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Tools to use handle plain JS objects as immutable objects",
5
5
  "keywords": [
6
6
  "immutable",
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "https://github.com/rimbu-org/rimbu.git",
30
+ "url": "https://github.com/rimbu-org/rimbu",
31
31
  "directory": "packages/deep"
32
32
  },
33
33
  "type": "module",
@@ -36,7 +36,6 @@
36
36
  "types": "./dist/cjs/index.d.cts",
37
37
  "exports": {
38
38
  ".": {
39
- "bun": "./dist/bun/index.mts",
40
39
  "import": {
41
40
  "types": "./dist/esm/index.d.mts",
42
41
  "default": "./dist/esm/index.mjs"
@@ -53,8 +52,7 @@
53
52
  ],
54
53
  "scripts": {
55
54
  "build": "yarn clean && yarn bundle",
56
- "bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:bun",
57
- "bundle:bun": "node ../../config/bunnify.mjs -mode bun",
55
+ "bundle": "yarn bundle:cjs && yarn bundle:esm",
58
56
  "bundle:cjs": "yarn bundle:cjs-prepare && yarn bundle:cjs-build && yarn bundle:cjs-clean",
59
57
  "bundle:cjs-prepare": "node ../../config/bunnify.mjs -mode cjs",
60
58
  "bundle:cjs-build": "tsc -p tsconfig.cjs.json",
@@ -73,12 +71,12 @@
73
71
  "typecheck": "tsc"
74
72
  },
75
73
  "dependencies": {
76
- "@rimbu/base": "^2.0.4",
77
- "@rimbu/common": "^2.0.4",
74
+ "@rimbu/base": "^2.0.6",
75
+ "@rimbu/common": "^2.0.6",
78
76
  "tslib": "^2.8.1"
79
77
  },
80
78
  "publishConfig": {
81
79
  "access": "public"
82
80
  },
83
- "gitHead": "bc6bc82af86461c423ba459d6d9809efdd5ffd61"
81
+ "gitHead": "0d946ea05fda8261f1c55c3bcd6527ed793b90b5"
84
82
  }
package/dist/bun/deep.mts DELETED
@@ -1,364 +0,0 @@
1
- import type { Match, Patch, Path, Protected, Selector } from './internal.mts';
2
- import { Deep } from './internal.mts';
3
-
4
- export { match, type Match } from './match.mts';
5
- export { patch, type Patch } from './patch.mts';
6
- export { getAt, patchAt, type Path } from './path.mts';
7
- export type { Protected } from './protected.mts';
8
- export { select, type Selector } from './selector.mts';
9
-
10
- /**
11
- * Returns the same value wrapped in the `Protected` type.
12
- * @typeparam T - the source value type
13
- * @param source - the value to wrap
14
- * @note does not perform any runtime protection, it is only a utility to easily add the `Protected`
15
- * type to a value
16
- * @example
17
- * ```ts
18
- * const obj = Deep.protect({ a: 1, b: { c: true, d: [1] } })
19
- * obj.a = 2 // compiler error: a is readonly
20
- * obj.b.c = false // compiler error: c is readonly
21
- * obj.b.d.push(2) // compiler error: d is a readonly array
22
- * (obj as any).b.d.push(2) // will actually mutate the object
23
- * ```
24
- */
25
- export function protect<T>(source: T): Protected<T> {
26
- return source as Protected<T>;
27
- }
28
-
29
- /**
30
- * Returns a function that gets the value at the given string `path` inside an object.
31
- * @typeparam T - the input value type
32
- * @typeparam P - the string literal path type in the object
33
- * @param path - the string path in the object
34
- * @param source - the value from which to extract the path value
35
- * @example
36
- * ```ts
37
- * const items = [{ a: { b: 1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
38
- * items.map(Deep.getAtWith('a.c'));
39
- * // => ['a', 'b']
40
- * ```
41
- */
42
- export function getAtWith<T, P extends Path.Get<T>>(
43
- path: P
44
- ): (source: T) => Path.Result<T, P> {
45
- return (source) => Deep.getAt(source, path);
46
- }
47
-
48
- /**
49
- * Returns a function that patches a given `source` with the given `patchItems`.
50
- * @typeparam T - the patch value type
51
- * @typeparam TE - utility type
52
- * @typeparam TT - utility type
53
- * @param patchItem - the `Patch` definition to update the given value of type `T` with.
54
- * @param source - the value to use the given `patchItem` on.
55
- * @example
56
- * ```ts
57
- * const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
58
- * items.map(Deep.patchWith([{ a: v => v + 1 }]));
59
- * // => [{ a: 2, b: 'a' }, { a: 3, b: 'b' }]
60
- * ```
61
- */
62
- export function patchWith<T, TE extends T = T, TT = T>(
63
- patchItem: Patch<TT, TE>
64
- ): (source: TE) => T {
65
- return (source) => Deep.patch(source, patchItem as any);
66
- }
67
-
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
- export function patchAtWith<T, P extends Path.Set<T>, TE extends T = T, TT = T>(
85
- path: P,
86
- patchItem: Patch<Path.Result<TE, P>, Path.Result<TT, P>>
87
- ): (source: T) => T {
88
- return (source) => Deep.patchAt(source, path, patchItem as any);
89
- }
90
-
91
- /**
92
- * Returns a function that matches a given `value` with the given `matcher`.
93
- * @typeparam T - the input value type
94
- * @param matcher - a matcher object that matches input values.
95
- * @param source - the value to match (parameter of the returned function).
96
- * @example
97
- * ```ts
98
- * const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
99
- * items.filter(Deep.matchWith({ a: 2 }));
100
- * // => [{ a: 2, b: 'b' }]
101
- * ```
102
- */
103
- export function matchWith<T>(matcher: Match<T>): (source: T) => boolean {
104
- return (source) => Deep.match(source, matcher);
105
- }
106
-
107
- /**
108
- * Returns true if the given `value` object matches the given `matcher` at the given `path`, false otherwise.
109
- * @typeparam T - the input value type
110
- * @typeparam P - the string literal path type in the object
111
- * @param source - the input value
112
- * @param path - the string path in the object
113
- * @param matcher - a matcher object or a function taking the matcher API and returning a match object
114
- * @example
115
- * ```ts
116
- * const input = { a: 1, b: { c: true, d: 'a' } }
117
- * Deep.matchAt(input, 'b', { c: true })
118
- * // => true
119
- * ```
120
- */
121
- export function matchAt<T, P extends Path.Get<T>>(
122
- source: T,
123
- path: P,
124
- matcher: Match<Path.Result<T, P>>
125
- ): boolean {
126
- return Deep.match(Deep.getAt(source, path), matcher);
127
- }
128
-
129
- /**
130
- * Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
131
- * @typeparam T - the input value type
132
- * @typeparam P - the string literal path type in the object
133
- * @typeparam TE - utility type
134
- * @param path - the string path in the object
135
- * @param matcher - a matcher object that matches input values.
136
- * @param source - the value to use the given `matcher` on at the given `path`.
137
- * @example
138
- * ```ts
139
- * const items = [{ a: { b: 1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
140
- * items.filter(Deep.matchAtWith('a.b', 2));
141
- * // => [{ a: 2, b: 'b' }]
142
- * ```
143
- */
144
- export function matchAtWith<T, P extends Path.Get<T>, TE extends T = T>(
145
- path: P,
146
- matcher: Match<Path.Result<T & TE, P>>
147
- ): (source: T) => boolean {
148
- return (source) => Deep.matchAt(source, path, matcher as any);
149
- }
150
-
151
- /**
152
- * Returns a function that selects a certain shape from a given `value` with the given `selector`.
153
- * @typeparam T - the input value type
154
- * @typeparam SL - the selector shape type
155
- * @param selector - a shape indicating the selection from the source values
156
- * @param source - the value to use the given `selector` on.
157
- * @example
158
- * ```ts
159
- * const items = [{ a: { b: 1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
160
- * items.map(Deep.selectWith({ q: 'a.c', z: ['a.b', v => v.a.b + 1] as const }));
161
- * // => [{ q: 'a', z: [1, 2] }, { q: 'b', z: [2, 3] }]
162
- * ```
163
- */
164
- export function selectWith<T, SL extends Selector<T>>(
165
- selector: Selector.Shape<SL>
166
- ): (source: T) => Selector.Result<T, SL> {
167
- return (source) => Deep.select(source, selector);
168
- }
169
-
170
- /**
171
- * Returns the result of applying the given `selector` shape to the given `source` value.
172
- * @typeparam T - the input value type
173
- * @typeparam P - the string literal path type in the object
174
- * @typeparam SL - the selector shape type
175
- * @param source - the source value to select from
176
- * @param path - the string path in the object
177
- * @param selector - a shape indicating the selection from the source value at the given path
178
- * @example
179
- * ```ts
180
- * const item = { a: { b: 1, c: 'a' } };
181
- * Deep.selectAt(item, 'a', { q: 'c', z: ['b', v => v.b + 1] as const });
182
- * // => { q: 'a', z: [1, 2] }
183
- * ```
184
- */
185
- export function selectAt<
186
- T,
187
- P extends Path.Get<T>,
188
- SL extends Selector<Path.Result<T, P>>,
189
- >(
190
- source: T,
191
- path: P,
192
- selector: Selector.Shape<SL>
193
- ): Selector.Result<Path.Result<T, P>, SL> {
194
- return Deep.select(Deep.getAt(source, path), selector);
195
- }
196
-
197
- /**
198
- * Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
199
- * @typeparam T - the input value type
200
- * @typeparam P - the string literal path type in the object
201
- * @typeparam SL - the selector shape type
202
- * @param path - the string path in the object
203
- * @param selector - a shape indicating the selection from the source values
204
- * @example
205
- * ```ts
206
- * const items = [{ a: { b: 1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
207
- * items.map(Deep.selectAtWith('a', { q: 'c', z: ['b', v => v.b + 1] as const }));
208
- * // => [{ q: 'a', z: [1, 2] }, { q: 'b', z: [2, 3] }]
209
- * ```
210
- */
211
- export function selectAtWith<
212
- T,
213
- P extends Path.Get<T>,
214
- SL extends Selector<Path.Result<T, P>>,
215
- >(
216
- path: P,
217
- selector: Selector.Shape<SL>
218
- ): (source: T) => Selector.Result<Path.Result<T, P>, SL> {
219
- return (source) => Deep.selectAt(source, path, selector);
220
- }
221
-
222
- /**
223
- * Typed and curried Deep API, used in situations where the target type
224
- * is known but the value will be applied later.
225
- * @typeparam T - the target type
226
- * @example
227
- * ```ts
228
- * const s = { a: 1, b: { c: 'a', d: true }};
229
- * const upd = Deep.withType<typeof s>().patchWith([{ a: (v) => v + 1 }]);
230
- * upd(s);
231
- * // => { a: 2, b: { c: 'a', d: true }}
232
- * ```
233
- */
234
- export interface WithType<T> {
235
- /**
236
- * Returns a function that given an object returns the value at the given `path`.
237
- * @typeparam P - a Path in object type T
238
- * @param path - the path into the object
239
- * @example
240
- * ```ts
241
- * const value = { a: { b: { c: 5 } } }
242
- * const getValue = Deep.withType<typeof value>().getAtWith('a.b.c');
243
- * getValue(value);
244
- * // => 5
245
- * ```
246
- */
247
- getAtWith<P extends Path.Get<T>>(path: P): (source: T) => Path.Result<T, P>;
248
- /**
249
- * Returns a function that patches a given `value` with the given `patchItems`.
250
- * @typeparam TT - utility type
251
- * @param patchItem - the `Patch` definition to update the given value with
252
- * @param source - the value to use the given `patchItem` on.
253
- * @example
254
- * ```ts
255
- * const value = { a: 1, b: 'a' };
256
- * const upd = Deep.withType<typeof value>().patch([{ a: v => v + 1 }]);
257
- * upd(value);
258
- * // => { a: 2, b: 'a' }
259
- * ```
260
- */
261
- patchWith<TE extends T = T, TT = T>(
262
- patchItem: Patch<TT, TE>
263
- ): (source: TE) => T;
264
- /**
265
- * Returns a function that patches a given `value` with the given `patchItems` at the given `path`.
266
- * @typeparam P - the string literal path type in the object
267
- * @typeparam TT - utility type
268
- * @param path - the string path in the object
269
- * @param patchItem - the `Patch` definition to update the given value with
270
- * @param source - the value to use the given `patchItem` on at the given `path`.
271
- * @example
272
- * ```ts
273
- * const value = { a: { b: 1, c: 'a' } };
274
- * const upd = Deep.withType<typeof value>().patchAtWith('a', [{ b: (v) => v + 1 }])
275
- * upd(value);
276
- * // => { a: { b: 2, c: 'a' } }
277
- * ```
278
- */
279
- patchAtWith<P extends Path.Set<T>, TT = T>(
280
- path: P,
281
- patchItem: Patch<Path.Result<T, P>, Path.Result<TT, P>>
282
- ): (source: T) => T;
283
- /**
284
- * Returns a function that matches a given `value` with the given `matcher`.
285
- * @param matcher - a matcher object that matches input values.
286
- * @param source - the value to use the given `matcher` on.
287
- * @example
288
- * ```ts
289
- * const value = { a: 1, b: 'a' };
290
- * const m = Deep.withType<typeof value>().matchWith({ a: 1 });
291
- * m(value);
292
- * // => true
293
- * ```
294
- */
295
- matchWith(matcher: Match<T>): (source: T) => boolean;
296
- /**
297
- * Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
298
- * @typeparam P - the string literal path type in the object
299
- * @param path - the string path in the object
300
- * @param matcher - a matcher object that matches input values.
301
- * @param source - the value to use the given `matcher` on at the given `path`.
302
- * @example
303
- * ```ts
304
- * const items = [{ a: { b: 1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
305
- * items.filter(Deep.matchAtWith('a.b', 2));
306
- * // => [{ a: 2, b: 'b' }]
307
- * ```
308
- */
309
- matchAtWith<P extends Path.Get<T>>(
310
- path: P,
311
- matcher: Match<Path.Result<T, P>>
312
- ): (source: T) => boolean;
313
- /**
314
- * Returns a function that selects a certain shape from a given `value` with the given `selector`.
315
- * @typeparam SL - the selector shape type
316
- * @param selector - a shape indicating the selection from the source values
317
- * @param source - the value to use the given `selector` on.
318
- * @example
319
- * ```ts
320
- * const value = { a: { b: 1, c: 'a' } };
321
- * const sel = Deep.withType<typeof value>().selectWith({ q: 'a.b' });
322
- * sel(value);
323
- * // => { q: 1 }
324
- * ```
325
- */
326
- selectWith<SL extends Selector<T>>(
327
- selector: Selector.Shape<SL>
328
- ): (source: T) => Selector.Result<T, SL>;
329
- /**
330
- * Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
331
- * @typeparam P - the string literal path type in the object
332
- * @typeparam SL - the selector shape type
333
- * @param path - the string path in the object
334
- * @param selector - a shape indicating the selection from the source values
335
- * @param source - the value to use the given `selector` on at the given `path`.
336
- * @example
337
- * ```ts
338
- * const value = { a: { b: 1, c: 'a' } };
339
- * const sel = Deep.withType<typeof value>().selectAtWith('a', { q: 'b' });
340
- * sel(value);
341
- * // => { q: 1 }
342
- * ```
343
- */
344
- selectAtWith<P extends Path.Get<T>, SL extends Selector<Path.Result<T, P>>>(
345
- path: P,
346
- selector: Selector.Shape<SL>
347
- ): (source: T) => Selector.Result<Path.Result<T, P>, SL>;
348
- }
349
-
350
- /**
351
- * Returns a curried API with a known target type. This can be useful for using the methods in
352
- * contexts where the target type can be inferred from the usage.
353
- * @typeparam T - the target type
354
- * @example
355
- * ```ts
356
- * const s = { a: 1, b: { c: 'a', d: true }}
357
- * const upd = Deep.withType<typeof s>().patchWith([{ d: (v) => !v }])
358
- * upd(s)
359
- * // => { a: 1, b: { c: 'a', d: false }}
360
- * ```
361
- */
362
- export function withType<T>(): WithType<T> {
363
- return Deep;
364
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * The `@rimbu/deep` package provides utilities to patch and match plain JavaScript objects.<br/>
5
- * <br/>
6
- * See the [Rimbu docs Deep overview page](/docs/deep/overview) for more information.
7
- */
8
-
9
- export { Tuple } from './tuple.mts';
10
-
11
- export type { Protected, Patch } from './internal.mts';
12
- export { Path, type Selector, type Match } from './internal.mts';
13
-
14
- export * from './deep.mts';
15
-
16
- import * as Deep from './deep.mts';
17
- export {
18
- /**
19
- * Convenience namespace offering access to most common functions used in the `@rimbu/deep` package.
20
- * These are mainly utilities to patch and match plain JavaScript objects.
21
- */
22
- Deep,
23
- };
@@ -1,8 +0,0 @@
1
- export type { Protected } from './protected.mts';
2
- export { Path } from './path.mts';
3
- export { type Match } from './match.mts';
4
- export type { Patch } from './patch.mts';
5
- export type { Selector } from './selector.mts';
6
-
7
- import * as Deep from './deep.mts';
8
- export { Deep };