@rimbu/deep 2.0.3 → 2.0.5

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 CHANGED
@@ -8,7 +8,6 @@
8
8
  ![License](https://img.shields.io/github/license/rimbu-org/rimbu)
9
9
  ![Types Included](https://img.shields.io/badge/TypeScript-ready-blue)
10
10
  ![Node](https://img.shields.io/badge/Node-18+-6DA55F?logo=node.js&logoColor=white)
11
- ![Deno](https://shield.deno.dev/x/rimbu)
12
11
  ![Bun](https://img.shields.io/badge/Bun-%23000000.svg)
13
12
  ![ESM + CJS](https://img.shields.io/badge/modules-ESM%20%2B%20CJS-informational)
14
13
 
@@ -120,15 +119,15 @@ Try Rimbu (including `@rimbu/deep`) live in the browser using the
120
119
 
121
120
  From `@rimbu/deep`’s main entrypoint you have access to:
122
121
 
123
- | Name | Description |
124
- | ---------------------------- | -------------------------------------------------------------------------------------------------------- |
125
- | `Patch<T, C = T>` | Type describing allowed patch shapes for a value of type `T`. |
126
- | `Match<T, C = Partial<T>>` | Type describing allowed matchers for values of type `T`. |
127
- | `Path` | Namespace containing `Path.Get<T>`, `Path.Set<T>`, and `Path.Result<T, P>` utilities for string paths. |
128
- | `Selector<T>` | Type describing allowed selector shapes for values of type `T`. |
129
- | `Protected<T>` | Deeply readonly/“protected” view of `T` for compile‑time mutation safety. |
130
- | `Tuple<T extends Tuple.Source>` | Tuple wrapper with helper types and functions under the `Tuple` namespace. |
131
- | `Deep` | Convenience namespace exposing the main deep utilities (`patch`, `match`, `getAt`, `select`, etc.). |
122
+ | Name | Description |
123
+ | ------------------------------- | ------------------------------------------------------------------------------------------------------ |
124
+ | `Patch<T, C = T>` | Type describing allowed patch shapes for a value of type `T`. |
125
+ | `Match<T, C = Partial<T>>` | Type describing allowed matchers for values of type `T`. |
126
+ | `Path` | Namespace containing `Path.Get<T>`, `Path.Set<T>`, and `Path.Result<T, P>` utilities for string paths. |
127
+ | `Selector<T>` | Type describing allowed selector shapes for values of type `T`. |
128
+ | `Protected<T>` | Deeply readonly/“protected” view of `T` for compile‑time mutation safety. |
129
+ | `Tuple<T extends Tuple.Source>` | Tuple wrapper with helper types and functions under the `Tuple` namespace. |
130
+ | `Deep` | Convenience namespace exposing the main deep utilities (`patch`, `match`, `getAt`, `select`, etc.). |
132
131
 
133
132
  See the [Deep overview docs](https://rimbu.org/docs/deep/overview) and
134
133
  [API reference](https://rimbu.org/api/rimbu/deep) for the full surface.
@@ -296,16 +295,8 @@ npm install @rimbu/deep
296
295
  yarn add @rimbu/deep
297
296
  # or
298
297
  bun add @rimbu/deep
299
- ```
300
-
301
- ### Deno (import map)
302
-
303
- ```jsonc
304
- {
305
- "imports": {
306
- "@rimbu/": "https://deno.land/x/rimbu@<version>/"
307
- }
308
- }
298
+ # or
299
+ deno add npm:@rimbu/deep
309
300
  ```
310
301
 
311
302
  Then:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimbu/deep",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Tools to use handle plain JS objects as immutable objects",
5
5
  "keywords": [
6
6
  "immutable",
@@ -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,17 +52,11 @@
53
52
  ],
54
53
  "scripts": {
55
54
  "build": "yarn clean && yarn bundle",
56
- "build:deno": "yarn bundle:deno-prepare && yarn bundle:deno-convert && yarn bundle:deno-move && yarn bundle:deno-clean",
57
- "bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:bun",
58
- "bundle:bun": "node ../../config/bunnify.mjs -mode bun",
55
+ "bundle": "yarn bundle:cjs && yarn bundle:esm",
59
56
  "bundle:cjs": "yarn bundle:cjs-prepare && yarn bundle:cjs-build && yarn bundle:cjs-clean",
60
57
  "bundle:cjs-prepare": "node ../../config/bunnify.mjs -mode cjs",
61
58
  "bundle:cjs-build": "tsc -p tsconfig.cjs.json",
62
59
  "bundle:cjs-clean": "rimraf _cjs_prepare",
63
- "bundle:deno-prepare": "node ../../config/prepare-denoify.mjs",
64
- "bundle:deno-convert": "denoify --src _deno_prepare/src",
65
- "bundle:deno-move": "rimraf ../../deno_dist/deep && mv deno_dist ../../deno_dist/deep",
66
- "bundle:deno-clean": "rimraf _deno_prepare",
67
60
  "bundle:esm": "tsc --p tsconfig.esm.json",
68
61
  "clean": "rimraf dist",
69
62
  "extract-api": "tsx ../../config/api-extractor.ts config/api-extractor.main.json",
@@ -78,12 +71,12 @@
78
71
  "typecheck": "tsc"
79
72
  },
80
73
  "dependencies": {
81
- "@rimbu/base": "^2.0.3",
82
- "@rimbu/common": "^2.0.3",
83
- "tslib": "^2.6.2"
74
+ "@rimbu/base": "^2.0.5",
75
+ "@rimbu/common": "^2.0.5",
76
+ "tslib": "^2.8.1"
84
77
  },
85
78
  "publishConfig": {
86
79
  "access": "public"
87
80
  },
88
- "gitHead": "1c35dbdd9ce13aeba818b41eb20bab1e826b3e16"
81
+ "gitHead": "15fd7c44f369838a47d42532bcd9771d65d6f660"
89
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 };