@rimbu/deep 2.0.0 → 2.0.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 (56) hide show
  1. package/README.md +37 -27
  2. package/dist/bun/deep.mts +2 -2
  3. package/dist/bun/match.mts +27 -25
  4. package/dist/bun/patch.mts +10 -9
  5. package/dist/bun/path.mts +94 -95
  6. package/dist/bun/protected.mts +18 -17
  7. package/dist/bun/selector.mts +22 -20
  8. package/dist/bun/tuple.mts +1 -1
  9. package/dist/cjs/deep.cjs +197 -576
  10. package/dist/cjs/deep.cjs.map +1 -0
  11. package/dist/cjs/deep.d.cts +284 -0
  12. package/dist/cjs/index.cjs +18 -662
  13. package/dist/cjs/index.cjs.map +1 -0
  14. package/dist/cjs/index.d.cts +18 -0
  15. package/dist/cjs/internal.cjs +8 -582
  16. package/dist/cjs/internal.cjs.map +1 -0
  17. package/dist/cjs/internal.d.cts +7 -0
  18. package/dist/cjs/match.cjs +250 -343
  19. package/dist/cjs/match.cjs.map +1 -0
  20. package/dist/cjs/match.d.cts +140 -0
  21. package/dist/cjs/patch.cjs +120 -93
  22. package/dist/cjs/patch.cjs.map +1 -0
  23. package/dist/cjs/patch.d.cts +89 -0
  24. package/dist/cjs/path.cjs +114 -573
  25. package/dist/cjs/path.cjs.map +1 -0
  26. package/dist/cjs/path.d.cts +199 -0
  27. package/dist/cjs/protected.cjs +2 -17
  28. package/dist/cjs/protected.cjs.map +1 -0
  29. package/dist/cjs/selector.cjs +32 -574
  30. package/dist/cjs/selector.cjs.map +1 -0
  31. package/dist/cjs/selector.d.cts +47 -0
  32. package/dist/cjs/tuple.cjs +162 -71
  33. package/dist/cjs/tuple.cjs.map +1 -0
  34. package/dist/esm/match.mjs.map +1 -1
  35. package/dist/esm/patch.mjs.map +1 -1
  36. package/dist/{types → esm}/path.d.mts +4 -1
  37. package/dist/esm/path.mjs.map +1 -1
  38. package/dist/esm/protected.d.mts +17 -0
  39. package/dist/esm/selector.mjs.map +1 -1
  40. package/dist/esm/tuple.d.mts +142 -0
  41. package/package.json +20 -14
  42. package/src/deep.mts +2 -2
  43. package/src/match.mts +27 -25
  44. package/src/patch.mts +10 -9
  45. package/src/path.mts +94 -95
  46. package/src/protected.mts +18 -17
  47. package/src/selector.mts +22 -20
  48. package/src/tuple.mts +1 -1
  49. /package/dist/{types/protected.d.mts → cjs/protected.d.cts} +0 -0
  50. /package/dist/{types/tuple.d.mts → cjs/tuple.d.cts} +0 -0
  51. /package/dist/{types → esm}/deep.d.mts +0 -0
  52. /package/dist/{types → esm}/index.d.mts +0 -0
  53. /package/dist/{types → esm}/internal.d.mts +0 -0
  54. /package/dist/{types → esm}/match.d.mts +0 -0
  55. /package/dist/{types → esm}/patch.d.mts +0 -0
  56. /package/dist/{types → esm}/selector.d.mts +0 -0
package/README.md CHANGED
@@ -8,44 +8,56 @@
8
8
 
9
9
  # @rimbu/deep
10
10
 
11
- Offers tools to use handle plain JS objects as immutable objects. The [`Patch` object](https://rimbu.org/docs/deep/patch) allows convenient immutable modification of simple objects. The [`Match` object](https://rimbu.org/docs/deep/match) allows easy matching on plain objects. The [`Path` object](https://rimbu.org/docs/deep/path) allows easy querying of nested values. The [`Immutable` type](https://rimbu.org/docs/deep/immutable) makes it easy to create plain objects that that have compile-time protection against mutation. The [`Tuple` type](https://rimbu.org/docs/deep/tuple) is a utility to have similar functionality as `as const` but less strict.
11
+ Welcome to `@rimbu/deep`! This package offers powerful tools to handle plain JavaScript objects as immutable objects, making your code more robust and maintainable.
12
12
 
13
- For complete documentation please visit the [Immutable Objects overview](https://rimbu.org/docs/deep/overview) in the _[Rimbu Docs](https://rimbu.org)_, or directly see the _[Rimbu Deep API Docs](https://rimbu.org/api/rimbu/deep)_.
13
+ ### Key Features:
14
14
 
15
- Or [Try Out Rimbu](https://codesandbox.io/s/github/vitoke/rimbu-sandbox/tree/main?previewwindow=console&view=split&editorsize=65&moduleview=1&module=/src/index.ts) in CodeSandBox.
15
+ - **Immutable Modification**: Use the [`Patch` object](https://rimbu.org/docs/deep/patch) for convenient and immutable modifications of simple objects.
16
+ - **Pattern Matching**: The [`Match` object](https://rimbu.org/docs/deep/match) allows easy pattern matching on plain objects.
17
+ - **Nested Value Querying**: Easily query nested values with the [`Path` object](https://rimbu.org/docs/deep/path).
18
+ - **Compile-Time Protection**: The [`Immutable` type](https://rimbu.org/docs/deep/immutable) helps create plain objects with compile-time protection against mutation.
19
+ - **Flexible Tuples**: The [`Tuple` type](https://rimbu.org/docs/deep/tuple) provides similar functionality to `as const` but with more flexibility.
20
+
21
+ ### Documentation
22
+
23
+ For complete documentation, please visit the [Immutable Objects overview](https://rimbu.org/docs/deep/overview) in the [Rimbu Docs](https://rimbu.org), or directly explore the [Rimbu Deep API Docs](https://rimbu.org/api/rimbu/deep).
24
+
25
+ ### Try It Out
26
+
27
+ Experience `@rimbu/deep` in action! [Try Out Rimbu](https://codesandbox.io/s/github/vitoke/rimbu-sandbox/tree/main?previewwindow=console&view=split&editorsize=65&moduleview=1&module=/src/index.ts) on CodeSandBox.
16
28
 
17
29
  ## Installation
18
30
 
19
31
  ### Compabitity
20
32
 
21
- - [`Node >= 16` ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?logo=node.js&logoColor=white)](https://nodejs.org)
33
+ - [`Node` ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?logo=node.js&logoColor=white)](https://nodejs.org)
22
34
  - [`Deno` ![Deno JS](https://img.shields.io/badge/deno%20js-000000?logo=deno&logoColor=white)](https://deno.com/runtime)
23
- - [`Bun >= 0.6.0` ![Bun](https://img.shields.io/badge/Bun-%23000000.svg?logoColor=white)](https://bun.sh/)
35
+ - [`Bun` ![Bun](https://img.shields.io/badge/Bun-%23000000.svg?logoColor=white)](https://bun.sh/)
24
36
  - `Web` ![HTML5](https://img.shields.io/badge/html5-%23E34F26.svg?logoColor=white)
25
37
 
26
- ### Yarn / NPM / Bun
27
-
28
- For convenience, all main types are also exported through [`@rimbu/core`](../core).
29
-
30
- To install this package only:
38
+ ### Package Managers
31
39
 
32
- For `yarn`:
40
+ **Yarn:**
33
41
 
34
- > `yarn add @rimbu/deep`
35
-
36
- For `npm`:
42
+ ```sh
43
+ yarn add @rimbu/deep
44
+ ```
37
45
 
38
- > `npm i @rimbu/deep`
46
+ **npm:**
39
47
 
40
- For `bun`:
48
+ ```sh
49
+ npm install @rimbu/deep
50
+ ```
41
51
 
42
- > `bun add @rimbu/deep`
52
+ **Bun:**
43
53
 
44
- ### Deno
54
+ ```sh
55
+ bun add @rimbu/deep
56
+ ```
45
57
 
46
- For Deno, the following approach is recommended:
58
+ ### Deno Setup
47
59
 
48
- In the root folder of your project, create or edit a file called `import_map.json` with the following contents (where you should replace `x.y.z` with the desired version of Rimbu):
60
+ Create or edit `import_map.json` in your project root:
49
61
 
50
62
  ```json
51
63
  {
@@ -55,7 +67,7 @@ In the root folder of your project, create or edit a file called `import_map.jso
55
67
  }
56
68
  ```
57
69
 
58
- **Note: The trailing slashes are important!**
70
+ _Replace `x.y.z` with the desired version._
59
71
 
60
72
  In this way you can use relative imports from Rimbu in your code, like so:
61
73
 
@@ -93,20 +105,18 @@ console.log(
93
105
 
94
106
  ## Author
95
107
 
96
- [Arvid Nicolaas](https://github.com/vitoke)
108
+ Created and maintained by [Arvid Nicolaas](https://github.com/vitoke).
97
109
 
98
110
  ## Contributing
99
111
 
100
- Feel very welcome to contribute to further improve Rimbu. Please read our [Contributing guide](https://github.com/rimbu-org/rimbu/blob/main/CONTRIBUTING.md).
112
+ We welcome contributions! Please read our [Contributing guide](https://github.com/rimbu-org/rimbu/blob/main/CONTRIBUTING.md).
101
113
 
102
114
  ## Contributors
103
115
 
104
116
  <img src = "https://contrib.rocks/image?repo=rimbu-org/rimbu"/>
105
117
 
106
- Made with [contributors-img](https://contrib.rocks).
118
+ _Made with [contributors-img](https://contrib.rocks)._
107
119
 
108
120
  ## License
109
121
 
110
- Licensed under the MIT License, Copyright © 2020-present Arvid Nicolaas.
111
-
112
- See [LICENSE](./LICENSE) for more information.
122
+ This project is licensed under the MIT License. See the [LICENSE](./LICENSE) for details.
package/dist/bun/deep.mts CHANGED
@@ -185,7 +185,7 @@ export function selectWith<T, SL extends Selector<T>>(
185
185
  export function selectAt<
186
186
  T,
187
187
  P extends Path.Get<T>,
188
- SL extends Selector<Path.Result<T, P>>
188
+ SL extends Selector<Path.Result<T, P>>,
189
189
  >(
190
190
  source: T,
191
191
  path: P,
@@ -211,7 +211,7 @@ export function selectAt<
211
211
  export function selectAtWith<
212
212
  T,
213
213
  P extends Path.Get<T>,
214
- SL extends Selector<Path.Result<T, P>>
214
+ SL extends Selector<Path.Result<T, P>>,
215
215
  >(
216
216
  path: P,
217
217
  selector: Selector.Shape<SL>
@@ -28,25 +28,31 @@ export namespace Match {
28
28
  * @typeparam P - the parent type
29
29
  * @typeparam R - the root object type
30
30
  */
31
- export type Entry<T, C, P, R> = IsAnyFunc<T> extends true
32
- ? // function can only be directly matched
33
- T
34
- : IsPlainObj<T> extends true
35
- ? // determine allowed match values for object
36
- Match.WithResult<T, P, R, Match.Obj<T, C, P, R>>
37
- : IsArray<T> extends true
38
- ? // determine allowed match values for array or tuple
39
- | Match.Arr<T, C, P, R>
40
- | Match.Entry<T[number & keyof T], C[number & keyof C], P, R>[]
41
- | Match.Func<
42
- T,
43
- P,
44
- R,
31
+ export type Entry<T, C, P, R> =
32
+ IsAnyFunc<T> extends true
33
+ ? // function can only be directly matched
34
+ T
35
+ : IsPlainObj<T> extends true
36
+ ? // determine allowed match values for object
37
+ Match.WithResult<T, P, R, Match.Obj<T, C, P, R>>
38
+ : IsArray<T> extends true
39
+ ? // determine allowed match values for array or tuple
45
40
  | Match.Arr<T, C, P, R>
46
- | Match.Entry<T[number & keyof T], C[number & keyof C], P, R>[]
47
- >
48
- : // only accept values with same interface
49
- Match.WithResult<T, P, R, { [K in keyof C]: C[K & keyof T] }>;
41
+ | Match.Entry<T[number & keyof T], C[number & keyof C], P, R>[]
42
+ | Match.Func<
43
+ T,
44
+ P,
45
+ R,
46
+ | Match.Arr<T, C, P, R>
47
+ | Match.Entry<
48
+ T[number & keyof T],
49
+ C[number & keyof C],
50
+ P,
51
+ R
52
+ >[]
53
+ >
54
+ : // only accept values with same interface
55
+ Match.WithResult<T, P, R, { [K in keyof C]: C[K & keyof T] }>;
50
56
 
51
57
  /**
52
58
  * The type that determines allowed matchers for objects.
@@ -136,7 +142,7 @@ export namespace Match {
136
142
  */
137
143
  export type CompoundForObj<T, C, P, R> = [
138
144
  Match.CompoundType,
139
- ...Match.Entry<T, C, P, R>[]
145
+ ...Match.Entry<T, C, P, R>[],
140
146
  ];
141
147
 
142
148
  /**
@@ -272,9 +278,7 @@ function matchEntry<T, C, P, R>(
272
278
  // already determined above that the source and matcher are not equal
273
279
 
274
280
  failureLog?.push(
275
- `value ${JSON.stringify(
276
- source
277
- )} does not match given matcher ${JSON.stringify(matcher)}`
281
+ `value ${JSON.stringify(source)} does not match given matcher ${JSON.stringify(matcher)}`
278
282
  );
279
283
 
280
284
  return false;
@@ -469,9 +473,7 @@ function matchPlainObj<T extends object, C, P, R>(
469
473
  // the source does not have the given key
470
474
 
471
475
  failureLog?.push(
472
- `key ${key} is specified in matcher but not present in value ${JSON.stringify(
473
- source
474
- )}`
476
+ `key ${key} is specified in matcher but not present in value ${JSON.stringify(source)}`
475
477
  );
476
478
 
477
479
  return false;
@@ -22,15 +22,16 @@ export namespace Patch {
22
22
  * @typeparam P - the parent type
23
23
  * @typeparam R - the root object type
24
24
  */
25
- export type Entry<T, C, P, R> = IsAnyFunc<T> extends true
26
- ? T
27
- : IsPlainObj<T> extends true
28
- ? Patch.WithResult<T, P, R, Patch.Obj<T, C, R>>
29
- : Tuple.IsTuple<T> extends true
30
- ? Patch.WithResult<T, P, R, T | Patch.Tup<T, C, R>>
31
- : IsArray<T> extends true
32
- ? Patch.WithResult<T, P, R, T>
33
- : Patch.WithResult<T, P, R, T>;
25
+ export type Entry<T, C, P, R> =
26
+ IsAnyFunc<T> extends true
27
+ ? T
28
+ : IsPlainObj<T> extends true
29
+ ? Patch.WithResult<T, P, R, Patch.Obj<T, C, R>>
30
+ : Tuple.IsTuple<T> extends true
31
+ ? Patch.WithResult<T, P, R, T | Patch.Tup<T, C, R>>
32
+ : IsArray<T> extends true
33
+ ? Patch.WithResult<T, P, R, T>
34
+ : Patch.WithResult<T, P, R, T>;
34
35
 
35
36
  /**
36
37
  * Either result type S, or a patch function with the value type, the parent type, and the root type.
package/dist/bun/path.mts CHANGED
@@ -36,7 +36,7 @@ export namespace Path {
36
36
  T,
37
37
  Write extends boolean,
38
38
  Maybe extends boolean,
39
- First extends boolean = false
39
+ First extends boolean = false,
40
40
  > = `${IsAnyFunc<T> extends true
41
41
  ? // functions can not be further decomposed
42
42
  ''
@@ -54,20 +54,21 @@ export namespace Path {
54
54
  T,
55
55
  Write extends boolean,
56
56
  Maybe extends boolean,
57
- First extends boolean
58
- > = Path.Internal.IsOptional<T> extends true
59
- ? // the value T may be null or undefined, check whether further chaining is allowed
60
- Write extends false
61
- ? // path is not used to write to, so optional chaining is allowed
62
- Path.Internal.Generic<Exclude<T, undefined | null>, Write, true>
63
- : // path can be written to, no optional chaining allowed
64
- never
65
- : // determine separator, and continue with non-optional value
66
- `${Path.Internal.Separator<
67
- First,
68
- Maybe,
69
- IsArray<T>
70
- >}${Path.Internal.NonOptional<T, Write, Maybe>}`;
57
+ First extends boolean,
58
+ > =
59
+ Path.Internal.IsOptional<T> extends true
60
+ ? // the value T may be null or undefined, check whether further chaining is allowed
61
+ Write extends false
62
+ ? // path is not used to write to, so optional chaining is allowed
63
+ Path.Internal.Generic<Exclude<T, undefined | null>, Write, true>
64
+ : // path can be written to, no optional chaining allowed
65
+ never
66
+ : // determine separator, and continue with non-optional value
67
+ `${Path.Internal.Separator<
68
+ First,
69
+ Maybe,
70
+ IsArray<T>
71
+ >}${Path.Internal.NonOptional<T, Write, Maybe>}`;
71
72
 
72
73
  /**
73
74
  * Determines the allowed paths into a non-optional value of type `T`.
@@ -76,25 +77,22 @@ export namespace Path {
76
77
  * @typeparam Maybe - if true the value at the current path is optional
77
78
  * @typeparam First - if true this is the root call
78
79
  */
79
- export type NonOptional<
80
- T,
81
- Write extends boolean,
82
- Maybe extends boolean
83
- > = Tuple.IsTuple<T> extends true
84
- ? // determine allowed paths for tuple
85
- Path.Internal.Tup<T, Write, Maybe>
86
- : T extends readonly any[]
87
- ? // determine allowed paths for array
88
- Write extends false
89
- ? // path is not writable so arrays are allowed
90
- Path.Internal.Arr<T>
91
- : // path is writable, no arrays allowed
92
- never
93
- : IsPlainObj<T> extends true
94
- ? // determine allowed paths for object
95
- Path.Internal.Obj<T, Write, Maybe>
96
- : // no match
97
- never;
80
+ export type NonOptional<T, Write extends boolean, Maybe extends boolean> =
81
+ Tuple.IsTuple<T> extends true
82
+ ? // determine allowed paths for tuple
83
+ Path.Internal.Tup<T, Write, Maybe>
84
+ : T extends readonly any[]
85
+ ? // determine allowed paths for array
86
+ Write extends false
87
+ ? // path is not writable so arrays are allowed
88
+ Path.Internal.Arr<T>
89
+ : // path is writable, no arrays allowed
90
+ never
91
+ : IsPlainObj<T> extends true
92
+ ? // determine allowed paths for object
93
+ Path.Internal.Obj<T, Write, Maybe>
94
+ : // no match
95
+ never;
98
96
 
99
97
  /**
100
98
  * Determines the allowed paths for a tuple. Since tuples have fixed types, they do not
@@ -104,11 +102,7 @@ export namespace Path {
104
102
  * @typeparam Maybe - if true the value at the current path is optional
105
103
  */
106
104
  export type Tup<T, Write extends boolean, Maybe extends boolean> = {
107
- [K in Tuple.KeysOf<T>]: `[${K}]${Path.Internal.Generic<
108
- T[K],
109
- Write,
110
- Maybe
111
- >}`;
105
+ [K in Tuple.KeysOf<T>]: `[${K}]${Path.Internal.Generic<T[K], Write, Maybe>}`;
112
106
  }[Tuple.KeysOf<T>];
113
107
 
114
108
  /**
@@ -143,7 +137,7 @@ export namespace Path {
143
137
  export type Separator<
144
138
  First extends boolean,
145
139
  Maybe extends boolean,
146
- IsArray extends boolean
140
+ IsArray extends boolean,
147
141
  > = Maybe extends true
148
142
  ? First extends true
149
143
  ? // first optional value cannot have separator
@@ -151,13 +145,13 @@ export namespace Path {
151
145
  : // non-first optional value must have separator
152
146
  '?.'
153
147
  : First extends true
154
- ? // first non-optional value has empty separator
155
- ''
156
- : IsArray extends true
157
- ? // array selectors do not have separator
158
- ''
159
- : // normal separator
160
- '.';
148
+ ? // first non-optional value has empty separator
149
+ ''
150
+ : IsArray extends true
151
+ ? // array selectors do not have separator
152
+ ''
153
+ : // normal separator
154
+ '.';
161
155
 
162
156
  /**
163
157
  * Determines whether the given type `T` is optional, that is, whether it can be null or undefined.
@@ -169,10 +163,10 @@ export namespace Path {
169
163
  ? // is optional
170
164
  True
171
165
  : null extends T
172
- ? // is optional
173
- True
174
- : // not optional
175
- False;
166
+ ? // is optional
167
+ True
168
+ : // not optional
169
+ False;
176
170
 
177
171
  /**
178
172
  * Returns type `T` if `Maybe` is false, `T | undefined` otherwise.
@@ -190,7 +184,7 @@ export namespace Path {
190
184
  */
191
185
  export type AppendIfNotEmpty<
192
186
  A extends string[],
193
- T extends string
187
+ T extends string,
194
188
  > = T extends ''
195
189
  ? // empty string, do not add
196
190
  A
@@ -224,23 +218,23 @@ export namespace Path {
224
218
  export type For<
225
219
  T,
226
220
  Tokens,
227
- Maybe extends boolean = Path.Internal.IsOptional<T>
221
+ Maybe extends boolean = Path.Internal.IsOptional<T>,
228
222
  > = Tokens extends []
229
223
  ? // no more token
230
224
  Path.Internal.MaybeValue<T, Maybe>
231
225
  : Path.Internal.IsOptional<T> extends true
232
- ? // T can be null or undefined, so continue with Maybe set to true
233
- Path.Result.For<Exclude<T, undefined | null>, Tokens, Maybe>
234
- : Tokens extends ['?.', infer Key, ...infer Rest]
235
- ? // optional chaining, process first part and set Maybe to true
236
- Path.Result.For<Path.Result.Part<T, Key, Maybe>, Rest, true>
237
- : Tokens extends ['.', infer Key, ...infer Rest]
238
- ? // normal chaining, process first part and continue
239
- Path.Result.For<Path.Result.Part<T, Key, false>, Rest, Maybe>
240
- : Tokens extends [infer Key, ...infer Rest]
241
- ? // process first part, and continue
242
- Path.Result.For<Path.Result.Part<T, Key, false>, Rest, Maybe>
243
- : never;
226
+ ? // T can be null or undefined, so continue with Maybe set to true
227
+ Path.Result.For<Exclude<T, undefined | null>, Tokens, Maybe>
228
+ : Tokens extends ['?.', infer Key, ...infer Rest]
229
+ ? // optional chaining, process first part and set Maybe to true
230
+ Path.Result.For<Path.Result.Part<T, Key, Maybe>, Rest, true>
231
+ : Tokens extends ['.', infer Key, ...infer Rest]
232
+ ? // normal chaining, process first part and continue
233
+ Path.Result.For<Path.Result.Part<T, Key, false>, Rest, Maybe>
234
+ : Tokens extends [infer Key, ...infer Rest]
235
+ ? // process first part, and continue
236
+ Path.Result.For<Path.Result.Part<T, Key, false>, Rest, Maybe>
237
+ : never;
244
238
 
245
239
  /**
246
240
  * Determines the result of getting the property/index `K` from type `T`, taking into
@@ -249,15 +243,16 @@ export namespace Path {
249
243
  * @typeparam K - the key to get from the source type
250
244
  * @typeparam Maybe - if true indicates that the path may be undefined
251
245
  */
252
- export type Part<T, K, Maybe extends boolean> = IsArray<T> extends true
253
- ? // for arrays, Maybe needs to be set to true to force optional chaining
254
- // for tuples, Maybe should be false
255
- Path.Internal.MaybeValue<
256
- T[K & keyof T],
257
- Tuple.IsTuple<T> extends true ? Maybe : true
258
- >
259
- : // Return the type at the given key, and take `Maybe` into account
260
- Path.Internal.MaybeValue<T[K & keyof T], Maybe>;
246
+ export type Part<T, K, Maybe extends boolean> =
247
+ IsArray<T> extends true
248
+ ? // for arrays, Maybe needs to be set to true to force optional chaining
249
+ // for tuples, Maybe should be false
250
+ Path.Internal.MaybeValue<
251
+ T[K & keyof T],
252
+ Tuple.IsTuple<T> extends true ? Maybe : true
253
+ >
254
+ : // Return the type at the given key, and take `Maybe` into account
255
+ Path.Internal.MaybeValue<T[K & keyof T], Maybe>;
261
256
 
262
257
  /**
263
258
  * Converts a path string into separate tokens in a string array.
@@ -268,31 +263,35 @@ export namespace Path {
268
263
  export type Tokenize<
269
264
  P extends string,
270
265
  Token extends string = '',
271
- Res extends string[] = []
266
+ Res extends string[] = [],
272
267
  > = P extends ''
273
268
  ? // no more input to process, return result
274
269
  Path.Internal.AppendIfNotEmpty<Res, Token>
275
270
  : P extends `[${infer Index}]${infer Rest}`
276
- ? // input is an array selector, append index to tokens. Continue with new token
277
- Tokenize<
278
- Rest,
279
- '',
280
- [...Path.Internal.AppendIfNotEmpty<Res, Token>, Index]
281
- >
282
- : P extends `?.${infer Rest}`
283
- ? // optional chaining, append to tokens. Continue with new token
284
- Tokenize<
285
- Rest,
286
- '',
287
- [...Path.Internal.AppendIfNotEmpty<Res, Token>, '?.']
288
- >
289
- : P extends `.${infer Rest}`
290
- ? // normal chaining, append to tokens. Continue with new token
291
- Tokenize<Rest, '', [...Path.Internal.AppendIfNotEmpty<Res, Token>, '.']>
292
- : P extends `${infer First}${infer Rest}`
293
- ? // process next character
294
- Tokenize<Rest, `${Token}${First}`, Res>
295
- : never;
271
+ ? // input is an array selector, append index to tokens. Continue with new token
272
+ Tokenize<
273
+ Rest,
274
+ '',
275
+ [...Path.Internal.AppendIfNotEmpty<Res, Token>, Index]
276
+ >
277
+ : P extends `?.${infer Rest}`
278
+ ? // optional chaining, append to tokens. Continue with new token
279
+ Tokenize<
280
+ Rest,
281
+ '',
282
+ [...Path.Internal.AppendIfNotEmpty<Res, Token>, '?.']
283
+ >
284
+ : P extends `.${infer Rest}`
285
+ ? // normal chaining, append to tokens. Continue with new token
286
+ Tokenize<
287
+ Rest,
288
+ '',
289
+ [...Path.Internal.AppendIfNotEmpty<Res, Token>, '.']
290
+ >
291
+ : P extends `${infer First}${infer Rest}`
292
+ ? // process next character
293
+ Tokenize<Rest, `${Token}${First}`, Res>
294
+ : never;
296
295
  }
297
296
 
298
297
  /**
@@ -11,20 +11,21 @@ import type { IsAny, IsPlainObj } from '@rimbu/base';
11
11
  * - Any other type will not be mapped
12
12
  * @typeparam T - the input type
13
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;
14
+ export type Protected<T> =
15
+ IsAny<T> extends true
16
+ ? // to prevent infinite recursion, any will be any
17
+ T
18
+ : T extends readonly any[] & infer A
19
+ ? // convert all keys to readonly and all values to `Protected`
20
+ { readonly [K in keyof A]: Protected<A[K]> }
21
+ : T extends Map<infer K, infer V>
22
+ ? ReadonlyMap<Protected<K>, Protected<V>>
23
+ : T extends Set<infer E>
24
+ ? ReadonlySet<Protected<E>>
25
+ : T extends Promise<infer E>
26
+ ? Promise<Protected<E>>
27
+ : IsPlainObj<T> extends true
28
+ ? // convert all keys to readonly and all values to `Protected`
29
+ { readonly [K in keyof T]: Protected<T[K]> }
30
+ : // nothing to do, just return `T`
31
+ T;
@@ -22,32 +22,34 @@ export namespace Selector {
22
22
  * Type defining the shape of allowed selectors, used to improve compiler checking.
23
23
  * @typeparam SL - the selector type
24
24
  */
25
- export type Shape<SL> = IsAnyFunc<SL> extends true
26
- ? // functions are allowed, type provided by `Selector`
27
- SL
28
- : IsArray<SL> extends true
29
- ? // ensure tuple type is preserved
30
- readonly [...(SL extends readonly unknown[] ? SL : never)]
31
- : SL extends { readonly [key: string | number | symbol]: unknown }
32
- ? // ensure all object properties satisfy `Shape`
33
- { readonly [K in keyof SL]: Selector.Shape<SL[K]> }
34
- : // nothing to check
35
- SL;
25
+ export type Shape<SL> =
26
+ IsAnyFunc<SL> extends true
27
+ ? // functions are allowed, type provided by `Selector`
28
+ SL
29
+ : IsArray<SL> extends true
30
+ ? // ensure tuple type is preserved
31
+ readonly [...(SL extends readonly unknown[] ? SL : never)]
32
+ : SL extends { readonly [key: string | number | symbol]: unknown }
33
+ ? // ensure all object properties satisfy `Shape`
34
+ { readonly [K in keyof SL]: Selector.Shape<SL[K]> }
35
+ : // nothing to check
36
+ SL;
36
37
 
37
38
  /**
38
39
  * Type defining the result type of applying the SL selector type to the T value type.
39
40
  * @typeparam T - the source value type
40
41
  * @typeparam SL - the selector type
41
42
  */
42
- export type Result<T, SL> = Selector<T> extends SL
43
- ? never
44
- : SL extends (...args: any[]) => infer R
45
- ? R
46
- : SL extends string
47
- ? Path.Result<T, SL>
48
- : {
49
- readonly [K in keyof SL]: Selector.Result<T, SL[K]>;
50
- };
43
+ export type Result<T, SL> =
44
+ Selector<T> extends SL
45
+ ? never
46
+ : SL extends (...args: any[]) => infer R
47
+ ? R
48
+ : SL extends string
49
+ ? Path.Result<T, SL>
50
+ : {
51
+ readonly [K in keyof SL]: Selector.Result<T, SL[K]>;
52
+ };
51
53
  }
52
54
 
53
55
  /**
@@ -138,7 +138,7 @@ export namespace Tuple {
138
138
  */
139
139
  export function append<
140
140
  T extends Tuple.Source,
141
- V extends readonly [unknown, ...unknown[]]
141
+ V extends readonly [unknown, ...unknown[]],
142
142
  >(tuple: T, ...values: V): readonly [...T, ...V] {
143
143
  return [...tuple, ...values];
144
144
  }