@rimbu/deep 2.0.1 → 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.
- package/README.md +37 -27
- package/dist/bun/deep.mts +2 -2
- package/dist/bun/match.mts +27 -25
- package/dist/bun/patch.mts +10 -9
- package/dist/bun/path.mts +94 -95
- package/dist/bun/protected.mts +18 -17
- package/dist/bun/selector.mts +22 -20
- package/dist/bun/tuple.mts +1 -1
- package/dist/cjs/deep.cjs +12 -12
- package/dist/cjs/deep.cjs.map +1 -1
- package/dist/cjs/match.cjs +1 -2
- package/dist/cjs/match.cjs.map +1 -1
- package/dist/cjs/patch.cjs +1 -2
- package/dist/cjs/patch.cjs.map +1 -1
- package/dist/cjs/path.cjs +3 -3
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +4 -1
- package/dist/cjs/selector.cjs +1 -2
- package/dist/cjs/selector.cjs.map +1 -1
- package/dist/esm/match.mjs.map +1 -1
- package/dist/esm/patch.mjs.map +1 -1
- package/dist/esm/path.d.mts +4 -1
- package/dist/esm/path.mjs.map +1 -1
- package/dist/esm/selector.mjs.map +1 -1
- package/package.json +7 -7
- package/src/deep.mts +2 -2
- package/src/match.mts +27 -25
- package/src/patch.mts +10 -9
- package/src/path.mts +94 -95
- package/src/protected.mts +18 -17
- package/src/selector.mts +22 -20
- package/src/tuple.mts +1 -1
package/README.md
CHANGED
|
@@ -8,44 +8,56 @@
|
|
|
8
8
|
|
|
9
9
|
# @rimbu/deep
|
|
10
10
|
|
|
11
|
-
|
|
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
|
-
|
|
13
|
+
### Key Features:
|
|
14
14
|
|
|
15
|
-
|
|
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
|
|
33
|
+
- [`Node` ](https://nodejs.org)
|
|
22
34
|
- [`Deno` ](https://deno.com/runtime)
|
|
23
|
-
- [`Bun
|
|
35
|
+
- [`Bun` ](https://bun.sh/)
|
|
24
36
|
- `Web` 
|
|
25
37
|
|
|
26
|
-
###
|
|
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
|
-
|
|
40
|
+
**Yarn:**
|
|
33
41
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
```sh
|
|
43
|
+
yarn add @rimbu/deep
|
|
44
|
+
```
|
|
37
45
|
|
|
38
|
-
|
|
46
|
+
**npm:**
|
|
39
47
|
|
|
40
|
-
|
|
48
|
+
```sh
|
|
49
|
+
npm install @rimbu/deep
|
|
50
|
+
```
|
|
41
51
|
|
|
42
|
-
|
|
52
|
+
**Bun:**
|
|
43
53
|
|
|
44
|
-
|
|
54
|
+
```sh
|
|
55
|
+
bun add @rimbu/deep
|
|
56
|
+
```
|
|
45
57
|
|
|
46
|
-
|
|
58
|
+
### Deno Setup
|
|
47
59
|
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
118
|
+
_Made with [contributors-img](https://contrib.rocks)._
|
|
107
119
|
|
|
108
120
|
## License
|
|
109
121
|
|
|
110
|
-
|
|
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>
|
package/dist/bun/match.mts
CHANGED
|
@@ -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> =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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;
|
package/dist/bun/patch.mts
CHANGED
|
@@ -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> =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
> =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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> =
|
|
253
|
-
|
|
254
|
-
// for
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
/**
|
package/dist/bun/protected.mts
CHANGED
|
@@ -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> =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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;
|
package/dist/bun/selector.mts
CHANGED
|
@@ -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> =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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> =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
/**
|
package/dist/bun/tuple.mts
CHANGED
|
@@ -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
|
}
|