map-transform 1.6.0-rc.5 → 1.6.0-rc.7
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 +114 -117
- package/dist/legacy/operations/apply.js +4 -8
- package/dist/legacy/operations/apply.js.map +1 -1
- package/dist/legacy/performance/apply.d.ts +1 -0
- package/dist/legacy/performance/apply.js +50 -0
- package/dist/legacy/performance/apply.js.map +1 -0
- package/dist/legacy/types.d.ts +4 -0
- package/dist/legacy/utils/cloneOptions.d.ts +3 -2
- package/dist/legacy/utils/cloneOptions.js +7 -6
- package/dist/legacy/utils/cloneOptions.js.map +1 -1
- package/dist/legacy/utils/definitionHelpers.js +10 -8
- package/dist/legacy/utils/definitionHelpers.js.map +1 -1
- package/dist/legacy/utils/internalOptions.d.ts +2 -0
- package/dist/legacy/utils/internalOptions.js +7 -0
- package/dist/legacy/utils/internalOptions.js.map +1 -0
- package/dist/legacy/utils/prepareOptions.d.ts +2 -2
- package/dist/legacy/utils/prepareOptions.js +11 -1
- package/dist/legacy/utils/prepareOptions.js.map +1 -1
- package/dist/legacy/utils/preparedPipelines.d.ts +3 -3
- package/dist/legacy/utils/preparedPipelines.js +12 -7
- package/dist/legacy/utils/preparedPipelines.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ Some highlighted features:
|
|
|
18
18
|
transforming objects or array of values, or for object props and primite
|
|
19
19
|
values.
|
|
20
20
|
- By defining how to transform data from one object to another, you implicitly
|
|
21
|
-
define how to transform the other way – from the target to the original
|
|
22
|
-
|
|
21
|
+
define how to transform the other way – from the target to the original (with
|
|
22
|
+
some gotchas).
|
|
23
23
|
|
|
24
24
|
## Getting started
|
|
25
25
|
|
|
@@ -33,9 +33,8 @@ older node versions, among other breaking changes. We expect to still support
|
|
|
33
33
|
node versions from v20, but might also drop anything below v22, depending on the
|
|
34
34
|
state of the node world at the time we release our v2.0.
|
|
35
35
|
|
|
36
|
-
> [!NOTE]
|
|
37
|
-
>
|
|
38
|
-
> on how to
|
|
36
|
+
> [!NOTE] This package is native [ESM](https://nodejs.org/api/esm.html). See
|
|
37
|
+
> this guide on how to
|
|
39
38
|
> [convert to or use ESM packages](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
|
|
40
39
|
|
|
41
40
|
### Installing
|
|
@@ -105,8 +104,8 @@ const source2 = await mapper(target, { rev: true })
|
|
|
105
104
|
```
|
|
106
105
|
|
|
107
106
|
You may improve this with pipelines, expressed through arrays. For instance,
|
|
108
|
-
retrieve the `content` object first, so you don't have to write the entire
|
|
109
|
-
|
|
107
|
+
retrieve the `content` object first, so you don't have to write the entire path
|
|
108
|
+
for every attribute:
|
|
110
109
|
|
|
111
110
|
```javascript
|
|
112
111
|
const def = [
|
|
@@ -176,9 +175,9 @@ await mapTransform(def)(source, { target }) // We're reusing `def` from the prev
|
|
|
176
175
|
// }
|
|
177
176
|
```
|
|
178
177
|
|
|
179
|
-
Finally, if you're using the same `options` across several `mapTransform`
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
Finally, if you're using the same `options` across several `mapTransform` calls,
|
|
179
|
+
you may gain some optimization by preparing the options up front. Do this with
|
|
180
|
+
the exported `prepareOptions` function like so:
|
|
182
181
|
|
|
183
182
|
```javascript
|
|
184
183
|
import mapTransform, { prepareOptions, transform } from 'map-transform'
|
|
@@ -194,11 +193,12 @@ await mapTransform(def2, preppedOptions)(source)
|
|
|
194
193
|
```
|
|
195
194
|
|
|
196
195
|
Most of the preparations are still done just-in-time, but when it's done once,
|
|
197
|
-
it won't happen again on the next call.
|
|
196
|
+
it won't happen again on the next call. `prepareOptions` is idempotent, so
|
|
197
|
+
passing already prepared options to `mapTransform` -- or calling
|
|
198
|
+
`prepareOptions` on them again -- costs nothing.
|
|
198
199
|
|
|
199
|
-
> [!NOTE]
|
|
200
|
-
>
|
|
201
|
-
> changes.
|
|
200
|
+
> [!NOTE] We are preparing for an upcoming 2.0 version, which will include
|
|
201
|
+
> breaking changes.
|
|
202
202
|
>
|
|
203
203
|
> The biggest change will be that we drop support for the approach where
|
|
204
204
|
> operation functions can be used directly in the pipelines. Instead, the only
|
|
@@ -216,17 +216,16 @@ it won't happen again on the next call.
|
|
|
216
216
|
> Note that these function have some breaking changes and are not to be
|
|
217
217
|
> considered stable until the 2.0 version.
|
|
218
218
|
>
|
|
219
|
-
> We have also rewritten this README to focus on object notations first, and
|
|
220
|
-
>
|
|
221
|
-
>
|
|
222
|
-
>
|
|
219
|
+
> We have also rewritten this README to focus on object notations first, and the
|
|
220
|
+
> functional approach second. We have tried to mention what has changed in the
|
|
221
|
+
> new `mapTransformSync` and `mapTransformAsync`, but there might still be gaps
|
|
222
|
+
> in the documentation here.
|
|
223
223
|
|
|
224
224
|
### The mutation object
|
|
225
225
|
|
|
226
226
|
Think of a mutation object as a description of the object structure you want.
|
|
227
227
|
|
|
228
|
-
> [!NOTE]
|
|
229
|
-
> Mutation objects were previously called "transform objects", and
|
|
228
|
+
> [!NOTE] Mutation objects were previously called "transform objects", and
|
|
230
229
|
> "mapping objects" before that. We're changing our terminalogy to keep in line
|
|
231
230
|
> with the [Integreat project](https://github.com/integreat-io/integreat), where
|
|
232
231
|
> MapTransform originally started and was spawned out from.
|
|
@@ -308,9 +307,8 @@ as its value, this mutation object will be iterated by default (no need to set
|
|
|
308
307
|
the `$iterate` property). This does not happen to pipelines, paths, or
|
|
309
308
|
operations.
|
|
310
309
|
|
|
311
|
-
> [!NOTE]
|
|
312
|
-
>
|
|
313
|
-
> new `mapTransformSync` and `mapTransformAsync` exports.
|
|
310
|
+
> [!NOTE] This automatic iteration will disappear in v2.0 and is also removed in
|
|
311
|
+
> the new `mapTransformSync` and `mapTransformAsync` exports.
|
|
314
312
|
|
|
315
313
|
#### Values on the mutation object
|
|
316
314
|
|
|
@@ -389,10 +387,10 @@ MapTransform will treat `undefined` as a "non-value" in several ways:
|
|
|
389
387
|
return an empty array (not `[undefined]`)
|
|
390
388
|
|
|
391
389
|
This is not the case for `null`, though. MapTransform treats `null` as a value,
|
|
392
|
-
an _intended nothing_. To change this behavior,
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
390
|
+
an _intended nothing_. To change this behavior, set
|
|
391
|
+
`nonvalues: [undefined, null]` on the `options` object passed to MapTransform.
|
|
392
|
+
This will essentially make MapTransform treat `null` the same way as
|
|
393
|
+
`undefined`.
|
|
396
394
|
|
|
397
395
|
You could in principle include any primitive value in `nonvalues` and it will be
|
|
398
396
|
treated as `undefined`, e.g. an empty string or the number `0`.
|
|
@@ -471,8 +469,8 @@ const def = {
|
|
|
471
469
|
}
|
|
472
470
|
```
|
|
473
471
|
|
|
474
|
-
If you prefer, you may modify deeper down in the object structure by setting
|
|
475
|
-
|
|
472
|
+
If you prefer, you may modify deeper down in the object structure by setting the
|
|
473
|
+
`$modify` flag at the end of a path:
|
|
476
474
|
|
|
477
475
|
```javascript
|
|
478
476
|
const def = {
|
|
@@ -541,10 +539,10 @@ here.)
|
|
|
541
539
|
**A note on arrays:** In a transform pipeline, the default behavior is to treat
|
|
542
540
|
an array as any other data. The array will be passed on to a `transform`
|
|
543
541
|
operation, the entire array will be set on a path, etc. This also means that a
|
|
544
|
-
mutation object will be applied to the entire array if nothing else is
|
|
545
|
-
In the example above, we have set `$iterate: true` on the mutation
|
|
546
|
-
signal that we want the mutation to be applied to each item of any
|
|
547
|
-
also [the `iterate` operation](#iteratepipeline-operation) for more.
|
|
542
|
+
mutation object will be applied to the entire array if nothing else is
|
|
543
|
+
specified. In the example above, we have set `$iterate: true` on the mutation
|
|
544
|
+
object, to signal that we want the mutation to be applied to each item of any
|
|
545
|
+
array. See also [the `iterate` operation](#iteratepipeline-operation) for more.
|
|
548
546
|
|
|
549
547
|
> Editors note: We should think through how we use the word "pipeline", as it is
|
|
550
548
|
> sometimes ment to refer to an array of operations that a value may be
|
|
@@ -614,10 +612,10 @@ getting the structure right when transforming in reverse mode. When running
|
|
|
614
612
|
in `{ tags: { id: ['news', 'sports'] } }`.
|
|
615
613
|
|
|
616
614
|
When a path with bracket notation meets `undefined` or any other
|
|
617
|
-
[nonvalue](#a-note-on-undefined-and-null), an empty array will be returned,
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
615
|
+
[nonvalue](#a-note-on-undefined-and-null), an empty array will be returned, as
|
|
616
|
+
you have stated that you expect an array. The only exception from this is when
|
|
617
|
+
[`state.noDefaults` is `true`](#mapping-without-defaults), in which case you'll
|
|
618
|
+
get `undefined`.
|
|
621
619
|
|
|
622
620
|
It may not always be straight forward how MapTransform should set on a path with
|
|
623
621
|
array notation, but it will again do its best. When there is no other
|
|
@@ -632,8 +630,8 @@ expect, as long as you use the brackets notation to guide MapTransform.
|
|
|
632
630
|
Finally, you may include index numbers between the brackets, to only get a
|
|
633
631
|
specific item. `tags[0].id` would get `'news'` from the data above. Use a
|
|
634
632
|
negative number to count from the end (`-1` being the last item). The index
|
|
635
|
-
version of the brackets notation won't return an array (as expected), unless
|
|
636
|
-
|
|
633
|
+
version of the brackets notation won't return an array (as expected), unless the
|
|
634
|
+
item at the index is another array (a sub-array).
|
|
637
635
|
|
|
638
636
|
When setting with an index bracket notation, you'll get an array where the
|
|
639
637
|
bracket notation is, with one item at the index you've specified.
|
|
@@ -671,13 +669,13 @@ data from anywhere in the data structure, be it in `content` or when iterating
|
|
|
671
669
|
through `tags[]`.
|
|
672
670
|
|
|
673
671
|
There is a gotcha here, for both parent and root paths, relating to what data
|
|
674
|
-
you're moving up in, as you are mutating the data as you move "down". The
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
672
|
+
you're moving up in, as you are mutating the data as you move "down". The short
|
|
673
|
+
answer is that you're moving in the mutated data – if you are mutating it. Say
|
|
674
|
+
you have a pipeline where you first mutate the data on the level you're at with
|
|
675
|
+
a mutation object. The following steps in the pipeline will relate to the
|
|
676
|
+
mutated object, and if you move into the mutated data with a path, and then go
|
|
677
|
+
up again with a parent path, you are moving up in the mutated data. But if you
|
|
678
|
+
instead just move into the data without mutating it, moving up with a parent
|
|
681
679
|
path will give you the original data – there's nothing else, as you have not
|
|
682
680
|
mutated it.
|
|
683
681
|
|
|
@@ -719,9 +717,8 @@ object.
|
|
|
719
717
|
|
|
720
718
|
> Editor's note: We need examples.
|
|
721
719
|
|
|
722
|
-
> [!NOTE]
|
|
723
|
-
>
|
|
724
|
-
> the future.
|
|
720
|
+
> [!NOTE] Setting on parent and root paths is currently not supported, but may
|
|
721
|
+
> be in the future.
|
|
725
722
|
|
|
726
723
|
#### Setting on a path
|
|
727
724
|
|
|
@@ -824,8 +821,8 @@ you don't have to try to run the returned mapper function with any data to
|
|
|
824
821
|
discover the mistake.
|
|
825
822
|
|
|
826
823
|
The `transform` operation object also accepts `$iterate: true`, which will apply
|
|
827
|
-
the transformer to every item in an array, should the data in the pipeline be
|
|
828
|
-
|
|
824
|
+
the transformer to every item in an array, should the data in the pipeline be an
|
|
825
|
+
array. You may also set `$direction: 'fwd'` or `$direction: 'rev'` to have it
|
|
829
826
|
transform in one direction only.
|
|
830
827
|
|
|
831
828
|
There are a few useful shorthands for the operation objects, like
|
|
@@ -925,11 +922,10 @@ of a `toAge` function, you could instead write a curried `yearsSince` function,
|
|
|
925
922
|
that would accept the current date (or any date) as the first argument. This
|
|
926
923
|
would be a truly pure function.
|
|
927
924
|
|
|
928
|
-
> [!NOTE]
|
|
929
|
-
>
|
|
930
|
-
>
|
|
931
|
-
>
|
|
932
|
-
> in v2.0, but is still available to the regular MapTransform function.
|
|
925
|
+
> [!NOTE] When you provide a transform function directly to a transform
|
|
926
|
+
> operation, MapTransform will not provide any property object, so you should
|
|
927
|
+
> call the outer function yourself with any relevant props. This option will be
|
|
928
|
+
> removed in v2.0, but is still available to the regular MapTransform function.
|
|
933
929
|
|
|
934
930
|
#### `filter` operation
|
|
935
931
|
|
|
@@ -939,17 +935,18 @@ what data to filter out. The operation may be specified in one of two ways:
|
|
|
939
935
|
1. The "traditional" way is to define it just like the `transform` operation,
|
|
940
936
|
with a transform id and props on the operation object as props for the
|
|
941
937
|
transformer. `filter` will just use the transformer you give it, and force
|
|
942
|
-
whatever it returns to a boolean. When the transformer returns something
|
|
943
|
-
the value is kept, and when it returns something falsy, the value is
|
|
944
|
-
JavaScript rules will be used to force the return value to a
|
|
945
|
-
`undefined`, `null`, `0`, and empty string `""` will be
|
|
938
|
+
whatever it returns to a boolean. When the transformer returns something
|
|
939
|
+
truthy, the value is kept, and when it returns something falsy, the value is
|
|
940
|
+
removed. JavaScript rules will be used to force the return value to a
|
|
941
|
+
boolean, meaning `undefined`, `null`, `0`, and empty string `""` will be
|
|
942
|
+
treated as `false`.
|
|
946
943
|
|
|
947
944
|
2. The "new" way is to set a pipeline on `$filter`. This pipeline will then be
|
|
948
|
-
run just like the transformer in the first case, and the value it returns
|
|
949
|
-
be forced to a boolean. Not the you may not provide a path string as a
|
|
950
|
-
here, as that would be treated as the "traditional" approach with a
|
|
951
|
-
id. Instead you will have to wrap a path in an array, to make it
|
|
952
|
-
a pipeline, like `['path.to.wherever']`.
|
|
945
|
+
run just like the transformer in the first case, and the value it returns
|
|
946
|
+
will be forced to a boolean. Not the you may not provide a path string as a
|
|
947
|
+
pipeline here, as that would be treated as the "traditional" approach with a
|
|
948
|
+
transformer id. Instead you will have to wrap a path in an array, to make it
|
|
949
|
+
clear that it's a pipeline, like `['path.to.wherever']`.
|
|
953
950
|
|
|
954
951
|
When filtering an array, the transformer or pipeline is applied to each data
|
|
955
952
|
item in the array, like you would expect of a filter function, and a new array
|
|
@@ -1184,8 +1181,8 @@ Note that the implementation of the two transformer functions is omitted from
|
|
|
1184
1181
|
this example.
|
|
1185
1182
|
|
|
1186
1183
|
To apply the pipeline to each item in an array, set `$iterate: true` on the
|
|
1187
|
-
`apply` operation object. You may also set `$direction: 'fwd'` or
|
|
1188
|
-
|
|
1184
|
+
`apply` operation object. You may also set `$direction: 'fwd'` or $direction:
|
|
1185
|
+
'rev'` to have it apply in one direction only.
|
|
1189
1186
|
|
|
1190
1187
|
As an alternative to the `apply` operation object, you may call the `apply`
|
|
1191
1188
|
operation function, but remember that this option will go away in v2.0.
|
|
@@ -1247,10 +1244,10 @@ the operation object. You may also set `$direction: 'fwd'` or
|
|
|
1247
1244
|
|
|
1248
1245
|
There's a special case of the `alt` operation for backward compability, that may
|
|
1249
1246
|
be removed in MapTransform v2.0. With only one pipeline, the operation will
|
|
1250
|
-
first check if the current value is `undefined`. If it is, it will run the
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1247
|
+
first check if the current value is `undefined`. If it is, it will run the one
|
|
1248
|
+
pipeline and return its value. If it's not, nothing happens. This is different
|
|
1249
|
+
from the multi-pipeline behavior, where the first is always run and the rest is
|
|
1250
|
+
only run if the previous returns `undefined`.
|
|
1254
1251
|
|
|
1255
1252
|
As an alternative to the `alt` operation object, you may call the `alt`
|
|
1256
1253
|
operation function, but remember that this option will go away in v2.0.
|
|
@@ -1287,10 +1284,10 @@ If there are no pipelines, the operation will return an empty array.
|
|
|
1287
1284
|
|
|
1288
1285
|
The `array` operation also supports `$iterate` and `$direction`.
|
|
1289
1286
|
|
|
1290
|
-
When going in reverse, the array operation will run each pipeline in reverse
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1287
|
+
When going in reverse, the array operation will run each pipeline in reverse on
|
|
1288
|
+
the item in the array matching the position of the pipeline. The result of a
|
|
1289
|
+
pipeline will be given to the next as a target. This is the closest we can get
|
|
1290
|
+
to recreating the original data.
|
|
1294
1291
|
|
|
1295
1292
|
To reverse the direction, so that we create an array in reverse mode, set
|
|
1296
1293
|
`$flip: true` on the operation object.
|
|
@@ -1312,8 +1309,8 @@ what array items to set on which pipeline.
|
|
|
1312
1309
|
|
|
1313
1310
|
If `concat` is not given any pipelines, it will return an empty array going
|
|
1314
1311
|
forward, and an empty object in reverse. The reason for the empty object is that
|
|
1315
|
-
the normal behavior for concat is to get with paths from an object, and with
|
|
1316
|
-
|
|
1312
|
+
the normal behavior for concat is to get with paths from an object, and with no
|
|
1313
|
+
paths, we can't set any props, so an empty object is the best we can do.
|
|
1317
1314
|
|
|
1318
1315
|
> **Note:** This operation is destructive, in that the result from running it
|
|
1319
1316
|
> forward cannot reproduce the original data when run in reverse. Only the data
|
|
@@ -1344,8 +1341,8 @@ const def = {
|
|
|
1344
1341
|
#### `concatRev` operation
|
|
1345
1342
|
|
|
1346
1343
|
The `concatRev` operation is the exact opposite of the `concat` operation,
|
|
1347
|
-
meaning that it will exhibit the same behavior in reverse as `concat` does
|
|
1348
|
-
|
|
1344
|
+
meaning that it will exhibit the same behavior in reverse as `concat` does going
|
|
1345
|
+
forward, and vice versa. See the description of
|
|
1349
1346
|
[the `concat` operation](#concat-operation) for more details.
|
|
1350
1347
|
|
|
1351
1348
|
`concatRev` is available as an operation object with `$concatRev`.
|
|
@@ -1380,8 +1377,8 @@ const def = modify({
|
|
|
1380
1377
|
})
|
|
1381
1378
|
```
|
|
1382
1379
|
|
|
1383
|
-
`def34` will in effect set the values placed at a deep path on the `data`
|
|
1384
|
-
|
|
1380
|
+
`def34` will in effect set the values placed at a deep path on the `data` prop.
|
|
1381
|
+
Giving this an object like:
|
|
1385
1382
|
|
|
1386
1383
|
```javascript
|
|
1387
1384
|
const response = {
|
|
@@ -1415,8 +1412,8 @@ There aren operation functions for this as well, but these will be removed in
|
|
|
1415
1412
|
MapTransform v2.0. If you want an operation to only apply in one direction, you
|
|
1416
1413
|
need to wrap it in a `fwd` or `rev` operation. The `fwd` operation will only
|
|
1417
1414
|
apply its pipeline when we're going forward, i.e. mapping in the normal
|
|
1418
|
-
direction, and its pipeline will be skipped when we're mapping in reverse.
|
|
1419
|
-
|
|
1415
|
+
direction, and its pipeline will be skipped when we're mapping in reverse. The
|
|
1416
|
+
`rev` operation will only apply its pipeline when we're mapping in reverse.
|
|
1420
1417
|
|
|
1421
1418
|
The value in the pipeline will be untouched when we are encountering an
|
|
1422
1419
|
operation that is not intended for the direction we are currently going in.
|
|
@@ -1520,8 +1517,8 @@ items without the root operation.
|
|
|
1520
1517
|
|
|
1521
1518
|
#### `plug` operation
|
|
1522
1519
|
|
|
1523
|
-
The `plug` operation simply clears the value in the pipeline - it plugs it.
|
|
1524
|
-
|
|
1520
|
+
The `plug` operation simply clears the value in the pipeline - it plugs it. The
|
|
1521
|
+
value will be set to `undefined` regardless of what has happened before that
|
|
1525
1522
|
point. Any `alt` operations etc. coming after the plug will still have an
|
|
1526
1523
|
effect.
|
|
1527
1524
|
|
|
@@ -1627,8 +1624,8 @@ your own transformers.
|
|
|
1627
1624
|
#### `bucket` transformer
|
|
1628
1625
|
|
|
1629
1626
|
The `bucket` transformer will split an array out in buckets based on condition
|
|
1630
|
-
pipelines (pipelines that will return truthy for the items that belong in
|
|
1631
|
-
|
|
1627
|
+
pipelines (pipelines that will return truthy for the items that belong in a
|
|
1628
|
+
certain bucket) or by size (how many items from the array to put in a bucket).
|
|
1632
1629
|
There's also an alternative way of using `groupByPath` (see below).
|
|
1633
1630
|
|
|
1634
1631
|
Here's an example using condition pipelines:
|
|
@@ -1690,9 +1687,9 @@ set a `condition` property to a pipeline that will return truthy for the items
|
|
|
1690
1687
|
that belong in the bucket.
|
|
1691
1688
|
|
|
1692
1689
|
Each item is tested against the bucket condition in the order the buckets are
|
|
1693
|
-
defined, and will be placed in the first bucket that matches. You may have
|
|
1694
|
-
|
|
1695
|
-
|
|
1690
|
+
defined, and will be placed in the first bucket that matches. You may have a
|
|
1691
|
+
bucket without a condition or size, which will serve as a catch-all bucket, and
|
|
1692
|
+
should therefore be placed last.
|
|
1696
1693
|
|
|
1697
1694
|
Here's an example of distributing to buckets by size:
|
|
1698
1695
|
|
|
@@ -1711,9 +1708,9 @@ const mappedData = await mapTransform(def)(data)
|
|
|
1711
1708
|
// }
|
|
1712
1709
|
```
|
|
1713
1710
|
|
|
1714
|
-
When distributing based on size, you set `size` to the
|
|
1715
|
-
|
|
1716
|
-
|
|
1711
|
+
When distributing based on size, you set `size` to the number of items you want
|
|
1712
|
+
to put in this bucket. You may also combine `condition` and `size`, to get the
|
|
1713
|
+
provided number of items matching the condition.
|
|
1717
1714
|
|
|
1718
1715
|
As an alternative to specifying `buckets`, you may provide a path or a pipeline
|
|
1719
1716
|
in `groupByPath`. The transformer will then fetch the value from this path or
|
|
@@ -1754,8 +1751,8 @@ const def1 = [
|
|
|
1754
1751
|
```
|
|
1755
1752
|
|
|
1756
1753
|
Actually, youcan also drop the `path` if you just want to compare the value in
|
|
1757
|
-
the pipeline with the `match` value, but it's more common to filter objects
|
|
1758
|
-
|
|
1754
|
+
the pipeline with the `match` value, but it's more common to filter objects by
|
|
1755
|
+
one of it's properties.
|
|
1759
1756
|
|
|
1760
1757
|
If you need to match the value at the path with another value in the data, you
|
|
1761
1758
|
may use `matchPath` instead of `match`. This will be a dot notation path,
|
|
@@ -1774,8 +1771,8 @@ elements in an array, and `exists` requires any value besides `undefined`.
|
|
|
1774
1771
|
Dates are compared using their milliseconds since epoc (1970-01-01) numeric
|
|
1775
1772
|
values.
|
|
1776
1773
|
|
|
1777
|
-
If the `path` points to an array, compare returns `true` if any of the items
|
|
1778
|
-
|
|
1774
|
+
If the `path` points to an array, compare returns `true` if any of the items in
|
|
1775
|
+
the array is a match.
|
|
1779
1776
|
|
|
1780
1777
|
Set `not: true` to reverse the result of the comparison.
|
|
1781
1778
|
|
|
@@ -1823,8 +1820,8 @@ await mapTransform(def)(data)
|
|
|
1823
1820
|
#### `fixed` transformer
|
|
1824
1821
|
|
|
1825
1822
|
The data given to the fixed transformer, will be inserted in the pipeline,
|
|
1826
|
-
replacing any data that is already there. The data may be an object, a string,
|
|
1827
|
-
|
|
1823
|
+
replacing any data that is already there. The data may be an object, a string, a
|
|
1824
|
+
number, a boolean, `null`, or `undefined – or an array of any of these.
|
|
1828
1825
|
|
|
1829
1826
|
This is almost the same behavior as
|
|
1830
1827
|
[the `value` transformer](#value-transformer), which is more commonly used,
|
|
@@ -1835,8 +1832,8 @@ values that should be set no matter what.
|
|
|
1835
1832
|
#### `flatten` transformer
|
|
1836
1833
|
|
|
1837
1834
|
Will flatten an array in the pipeline. The default is to flatten one layer deep,
|
|
1838
|
-
but this may be changed by setting the `depth` property to the wanted number
|
|
1839
|
-
|
|
1835
|
+
but this may be changed by setting the `depth` property to the wanted number of
|
|
1836
|
+
levels.
|
|
1840
1837
|
|
|
1841
1838
|
Example:
|
|
1842
1839
|
|
|
@@ -2051,9 +2048,9 @@ used.
|
|
|
2051
2048
|
|
|
2052
2049
|
You may also specify an `includePath` or `excludePath`. These are dot notation
|
|
2053
2050
|
paths to arrays of strings, and will be used instead of `include` or `exclude`.
|
|
2054
|
-
If `include` or `exclude` are also provided, they will be used as default
|
|
2055
|
-
|
|
2056
|
-
|
|
2051
|
+
If `include` or `exclude` are also provided, they will be used as default values
|
|
2052
|
+
when the corresponding path yields no value. Note that "no value" here means
|
|
2053
|
+
`undefined`, and we don't support custom non-values here yet.
|
|
2057
2054
|
|
|
2058
2055
|
When given an array of object, each object will be projected. When given
|
|
2059
2056
|
anything that is not an object, `undefined` will be returned.
|
|
@@ -2238,8 +2235,8 @@ be the one used in forward mode.
|
|
|
2238
2235
|
|
|
2239
2236
|
In some cases, the reverse transform is more complex than the forward transform.
|
|
2240
2237
|
For that reason, there is a `$flip` property that may be set to `true` on a
|
|
2241
|
-
mutation object, to indicate that it is defined from the reverse perspective
|
|
2242
|
-
|
|
2238
|
+
mutation object, to indicate that it is defined from the reverse perspective and
|
|
2239
|
+
should be "flipped" before transforming data with it.
|
|
2243
2240
|
|
|
2244
2241
|
A flipped mutation object will – in forward mode – get with the properties on
|
|
2245
2242
|
the object and set with the paths in the value. The order of paths and
|
|
@@ -2354,9 +2351,9 @@ mapper2({ id: 'cust4' }, { rev: true })
|
|
|
2354
2351
|
### The state object
|
|
2355
2352
|
|
|
2356
2353
|
MapTransform uses a state object internally to pass on data, context, target,
|
|
2357
|
-
etc., between pipelines and operations. You may encounter this state object
|
|
2358
|
-
|
|
2359
|
-
|
|
2354
|
+
etc., between pipelines and operations. You may encounter this state object when
|
|
2355
|
+
you write your own transformers, as it is passed to the transformer function as
|
|
2356
|
+
the second argument (the current pipeline value is the first).
|
|
2360
2357
|
|
|
2361
2358
|
Most of the props on the state object should be regarded as MapTransform
|
|
2362
2359
|
internals and subject to change without notice, but a few props are good to know
|
|
@@ -2365,8 +2362,8 @@ and might also be necessary to make your transformer work the way you want:
|
|
|
2365
2362
|
- `rev`: When this is `true`, we are in reverse mode, so if your transformer
|
|
2366
2363
|
should work differently depending on direction, you should check this prop.
|
|
2367
2364
|
- `flip`: When `true`, we are being called from a mutation object in
|
|
2368
|
-
[flip mode](#flipping-a-mutation-object), meaning that the mutation object
|
|
2369
|
-
|
|
2365
|
+
[flip mode](#flipping-a-mutation-object), meaning that the mutation object is
|
|
2366
|
+
defined from the perspective of the reverse mode. This will not affect most
|
|
2370
2367
|
transformers, as we will treat the direction the same regardless of how the
|
|
2371
2368
|
mutation object is defined, but there are cases where you want to xor `rev`
|
|
2372
2369
|
and `flip` to get the direction. The guiding principle here is what "feels
|
|
@@ -2401,10 +2398,10 @@ useful when storing the definitions in a database, transferring it over http(s),
|
|
|
2401
2398
|
etc.
|
|
2402
2399
|
|
|
2403
2400
|
We are now favoring operation object notations, and the "old" operation
|
|
2404
|
-
functions will be removed in MapTransform v2.0, in line with the goal of
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2401
|
+
functions will be removed in MapTransform v2.0, in line with the goal of being
|
|
2402
|
+
able to express all definitions as JSON-friendly objects. With a set of commonly
|
|
2403
|
+
shared transformers passed to `mapTransform()` on the `options` object, storing
|
|
2404
|
+
and sharing definitions over JSON is quite trivial. This is how we use
|
|
2408
2405
|
MapTransform in [Integreat](https://github.com/integreat-io/integreat), which it
|
|
2409
2406
|
was initially written for.
|
|
2410
2407
|
|
|
@@ -2447,8 +2444,8 @@ Data given to and returned from MapTransform is typed as `unknown`, as we can't
|
|
|
2447
2444
|
know what it will be, and to signal that it should be typed by the user. We
|
|
2448
2445
|
would have loved to provide a typed return value based on the definition given
|
|
2449
2446
|
to `mapTransform`, but that is a task we have not been able to prioritize yet,
|
|
2450
|
-
and frankly we're not sure if it is at all possible. If you have the stomack
|
|
2451
|
-
|
|
2447
|
+
and frankly we're not sure if it is at all possible. If you have the stomack for
|
|
2448
|
+
this, please create an issue with an outline of how you would do this. :)
|
|
2452
2449
|
|
|
2453
2450
|
## Running the tests
|
|
2454
2451
|
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { noopNext } from '../utils/stateHelpers.js';
|
|
2
2
|
import { getPreparedPipeline } from '../utils/preparedPipelines.js';
|
|
3
|
+
import { toInternalOptions } from '../utils/internalOptions.js';
|
|
3
4
|
const getPipelineDef = (pipelineId, pipelines) => (typeof pipelineId === 'string' || typeof pipelineId === 'symbol') &&
|
|
4
5
|
pipelines
|
|
5
6
|
? pipelines[pipelineId]
|
|
6
7
|
: undefined;
|
|
7
8
|
const removeFlip = ({ flip, ...state }) => state;
|
|
8
|
-
function markPipelineAsNeeded(pipelineId, options) {
|
|
9
|
-
if (!options.neededPipelineIds) {
|
|
10
|
-
options.neededPipelineIds = new Set();
|
|
11
|
-
}
|
|
12
|
-
options.neededPipelineIds.add(pipelineId);
|
|
13
|
-
}
|
|
14
9
|
const createApplyFn = (next, options, pipelineId) => async (state) => {
|
|
15
10
|
const fn = getPreparedPipeline(pipelineId, options);
|
|
16
11
|
if (typeof fn !== 'function') {
|
|
@@ -32,9 +27,10 @@ export default function apply(pipelineId) {
|
|
|
32
27
|
: 'Failed to apply pipeline. No id provided';
|
|
33
28
|
throw new Error(message);
|
|
34
29
|
}
|
|
35
|
-
|
|
30
|
+
const internalOptions = toInternalOptions(options);
|
|
31
|
+
internalOptions.neededPipelineIds.add(pipelineId);
|
|
36
32
|
return (next) => {
|
|
37
|
-
return createApplyFn(next,
|
|
33
|
+
return createApplyFn(next, internalOptions, pipelineId);
|
|
38
34
|
};
|
|
39
35
|
};
|
|
40
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/legacy/operations/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/legacy/operations/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAW/D,MAAM,cAAc,GAAG,CACrB,UAA2B,EAC3B,SAAuD,EACvD,EAAE,CACF,CAAC,OAAO,UAAU,KAAK,QAAQ,IAAI,OAAO,UAAU,KAAK,QAAQ,CAAC;IAClE,SAAS;IACP,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC;IACvB,CAAC,CAAC,SAAS,CAAA;AAEf,MAAM,UAAU,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,EAAS,EAAE,EAAE,CAAC,KAAK,CAAA;AAEvD,MAAM,aAAa,GACjB,CAAC,IAAiB,EAAE,OAAwB,EAAE,UAA2B,EAAE,EAAE,CAC7E,KAAK,EAAE,KAAY,EAAE,EAAE;IAGrB,MAAM,EAAE,GAA0B,mBAAmB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IAC1E,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,qBAAqB,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAC9D,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,CAAA;IACnC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAA;AACrD,CAAC,CAAA;AAEH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,UAA2B;IACvD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QACnC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,6BAA6B,MAAM,CAAC,UAAU,CAAC,iBAAiB,CACjE,CAAA;QACH,CAAC;QACD,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;QACtD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,OAAO,GAAG,UAAU;gBACxB,CAAC,CAAC,6BAA6B,MAAM,CAAC,UAAU,CAAC,qBAAqB;gBACtE,CAAC,CAAC,0CAA0C,CAAA;YAC9C,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;QAC1B,CAAC;QAGD,MAAM,eAAe,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAClD,eAAe,CAAC,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QAEjD,OAAO,CAAC,IAAI,EAAE,EAAE;YACd,OAAO,aAAa,CAAC,IAAI,EAAE,eAAe,EAAE,UAAU,CAAC,CAAA;QACzD,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import mapTransform from '../../index.js';
|
|
4
|
+
import items from '../data/items.js';
|
|
5
|
+
test('should apply pipeline for every item', async () => {
|
|
6
|
+
const pipelines = {
|
|
7
|
+
castItem: {
|
|
8
|
+
key: 'id',
|
|
9
|
+
name: 'title',
|
|
10
|
+
customer: 'customerId',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
const def = ['items', { $apply: 'castItem', $iterate: true }];
|
|
14
|
+
const data = items;
|
|
15
|
+
const fn = mapTransform(def, { pipelines });
|
|
16
|
+
const start = Date.now();
|
|
17
|
+
const ret = (await fn(data));
|
|
18
|
+
const end = Date.now();
|
|
19
|
+
assert.equal(ret.length, 10000);
|
|
20
|
+
assert.equal(ret[0].key, '1');
|
|
21
|
+
assert.equal(ret[0].name, 'Item 1');
|
|
22
|
+
assert.equal(ret[0].customer, '2');
|
|
23
|
+
console.log(`### Apply took ${end - start} ms`);
|
|
24
|
+
});
|
|
25
|
+
test('should apply pipeline applying another pipeline for every item', async () => {
|
|
26
|
+
const pipelines = {
|
|
27
|
+
castItem: [{ $apply: 'setProps' }, { $apply: 'setCustomer' }],
|
|
28
|
+
setProps: {
|
|
29
|
+
$modify: true,
|
|
30
|
+
key: 'id',
|
|
31
|
+
name: 'title',
|
|
32
|
+
},
|
|
33
|
+
setCustomer: {
|
|
34
|
+
$modify: true,
|
|
35
|
+
customer: 'customerId',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
const def = ['items', { $apply: 'castItem', $iterate: true }];
|
|
39
|
+
const data = items;
|
|
40
|
+
const fn = mapTransform(def, { pipelines });
|
|
41
|
+
const start = Date.now();
|
|
42
|
+
const ret = (await fn(data));
|
|
43
|
+
const end = Date.now();
|
|
44
|
+
assert.equal(ret.length, 10000);
|
|
45
|
+
assert.equal(ret[0].key, '1');
|
|
46
|
+
assert.equal(ret[0].name, 'Item 1');
|
|
47
|
+
assert.equal(ret[0].customer, '2');
|
|
48
|
+
console.log(`### Apply nested took ${end - start} ms`);
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/legacy/performance/apply.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACv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EAAE,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;QAC7D,QAAQ,EAAE;YACR,OAAO,EAAE,IAAI;YACb,GAAG,EAAE,IAAI;YACT,IAAI,EAAE,OAAO;SACd;QACD,WAAW,EAAE;YACX,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,YAAY;SACvB;KACF,CAAA;IACD,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAC7D,MAAM,IAAI,GAAG,KAAK,CAAA;IAClB,MAAM,EAAE,GAAG,YAAY,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,CAAC,CAAA;IAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAExB,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAW,CAAA;IAEtC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACtB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IAC/B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAC7B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IACnC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IAElC,OAAO,CAAC,GAAG,CAAC,yBAAyB,GAAG,GAAG,KAAK,KAAK,CAAC,CAAA;AACxD,CAAC,CAAC,CAAA"}
|
package/dist/legacy/types.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ export interface Options {
|
|
|
28
28
|
modifyGetValue?: (value: unknown, state: State, options: Options) => unknown;
|
|
29
29
|
preparedPipelines?: Map<string | symbol, Operation>;
|
|
30
30
|
}
|
|
31
|
+
export interface InternalOptions extends Options {
|
|
32
|
+
neededPipelineIds: Set<string | symbol>;
|
|
33
|
+
preparedPipelines: Map<string | symbol, Operation>;
|
|
34
|
+
}
|
|
31
35
|
export type DataMapper<T extends InitialState | undefined = State> = (data: unknown, state?: T) => Promise<unknown>;
|
|
32
36
|
export type AsyncDataMapperWithState = (data: unknown, state: State) => Promise<unknown>;
|
|
33
37
|
export type DataMapperWithState = (data: unknown, state: State) => unknown;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { Options } from '../types.js';
|
|
2
|
-
export declare function
|
|
1
|
+
import type { Options, InternalOptions } from '../types.js';
|
|
2
|
+
export declare function toInternalOptions(options: Options): InternalOptions;
|
|
3
|
+
export declare function cloneOptions(options: InternalOptions, changes?: Pick<Options, 'nonvalues'>): InternalOptions;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
export function toInternalOptions(options) {
|
|
2
|
+
const internalOptions = options;
|
|
3
|
+
internalOptions.neededPipelineIds ??= new Set();
|
|
4
|
+
internalOptions.preparedPipelines ??= new Map();
|
|
5
|
+
return internalOptions;
|
|
6
|
+
}
|
|
1
7
|
export function cloneOptions(options, changes = {}) {
|
|
2
|
-
return {
|
|
3
|
-
...options,
|
|
4
|
-
...changes,
|
|
5
|
-
neededPipelineIds: (options.neededPipelineIds ??= new Set()),
|
|
6
|
-
preparedPipelines: (options.preparedPipelines ??= new Map()),
|
|
7
|
-
};
|
|
8
|
+
return { ...options, ...changes };
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=cloneOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloneOptions.js","sourceRoot":"","sources":["../../../src/legacy/utils/cloneOptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cloneOptions.js","sourceRoot":"","sources":["../../../src/legacy/utils/cloneOptions.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,MAAM,eAAe,GAAG,OAA0B,CAAA;IAClD,eAAe,CAAC,iBAAiB,KAAK,IAAI,GAAG,EAAmB,CAAA;IAChE,eAAe,CAAC,iBAAiB,KAAK,IAAI,GAAG,EAA8B,CAAA;IAC3E,OAAO,eAAe,CAAA;AACxB,CAAC;AAQD,MAAM,UAAU,YAAY,CAC1B,OAAwB,EACxB,UAAsC,EAAE;IAExC,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,EAAE,CAAA;AACnC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getStateValue, setStateValue } from './stateHelpers.js';
|
|
2
2
|
import modifyOperationObject from './modifyOperationObject.js';
|
|
3
|
-
import {
|
|
3
|
+
import { toInternalOptions } from './internalOptions.js';
|
|
4
4
|
import { noopNext } from './stateHelpers.js';
|
|
5
5
|
import { isObject } from '../../utils/is.js';
|
|
6
6
|
import { get } from '../operations/getSet.js';
|
|
@@ -92,7 +92,7 @@ function createFilterOperation(def, options) {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
const setNoneValuesOnOptions = (options, nonvalues) => Array.isArray(nonvalues)
|
|
95
|
-
?
|
|
95
|
+
? { ...options, nonvalues: nonvalues.map(unescapeValue) }
|
|
96
96
|
: options;
|
|
97
97
|
const createAltOperation = (def, options) => {
|
|
98
98
|
const { $alt: defs, $undefined: nonvalues } = def;
|
|
@@ -173,26 +173,28 @@ function nextStateMapperFromObject(defRaw, options) {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
export function defToNextStateMappers(def, options) {
|
|
176
|
+
const internalOptions = toInternalOptions(options);
|
|
176
177
|
if (isPipeline(def)) {
|
|
177
|
-
return def.flatMap((def) => defToNextStateMappers(def,
|
|
178
|
+
return def.flatMap((def) => defToNextStateMappers(def, internalOptions));
|
|
178
179
|
}
|
|
179
180
|
else if (isObject(def)) {
|
|
180
|
-
return nextStateMapperFromObject(def,
|
|
181
|
+
return nextStateMapperFromObject(def, internalOptions);
|
|
181
182
|
}
|
|
182
183
|
else if (isPath(def)) {
|
|
183
|
-
return get(def).map((op) => op(
|
|
184
|
+
return get(def).map((op) => op(internalOptions));
|
|
184
185
|
}
|
|
185
186
|
else if (isOperation(def)) {
|
|
186
|
-
return def(
|
|
187
|
+
return def(internalOptions);
|
|
187
188
|
}
|
|
188
189
|
else {
|
|
189
190
|
return () => async (value) => value;
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
export function defToNextStateMapper(def, options) {
|
|
194
|
+
const internalOptions = toInternalOptions(options);
|
|
193
195
|
const nextStateMappers = isPipeline(def)
|
|
194
|
-
? pipe(def)(
|
|
195
|
-
: defToNextStateMappers(def,
|
|
196
|
+
? pipe(def)(internalOptions)
|
|
197
|
+
: defToNextStateMappers(def, internalOptions);
|
|
196
198
|
if (Array.isArray(nextStateMappers)) {
|
|
197
199
|
return pipeNext(nextStateMappers);
|
|
198
200
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitionHelpers.js","sourceRoot":"","sources":["../../../src/legacy/utils/definitionHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,qBAAqB,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"definitionHelpers.js","sourceRoot":"","sources":["../../../src/legacy/utils/definitionHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,qBAAqB,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;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B,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;AAC7D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internalOptions.js","sourceRoot":"","sources":["../../../src/legacy/utils/internalOptions.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,MAAM,eAAe,GAAG,OAA0B,CAAA;IAClD,eAAe,CAAC,iBAAiB,KAAK,IAAI,GAAG,EAAmB,CAAA;IAChE,eAAe,CAAC,iBAAiB,KAAK,IAAI,GAAG,EAA8B,CAAA;IAC3E,OAAO,eAAe,CAAA;AACxB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Options } from '../types.js';
|
|
1
|
+
import type { Options, InternalOptions } from '../types.js';
|
|
2
2
|
export { getPreparedPipeline, preparePipelines } from './preparedPipelines.js';
|
|
3
|
-
export declare function prepareOptions(options: Options):
|
|
3
|
+
export declare function prepareOptions(options: Options): InternalOptions;
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import transformers from '../transformers/index.js';
|
|
2
2
|
export { getPreparedPipeline, preparePipelines } from './preparedPipelines.js';
|
|
3
|
+
const isPrepared = Symbol('isPrepared');
|
|
3
4
|
export function prepareOptions(options) {
|
|
4
|
-
|
|
5
|
+
if (Reflect.get(options, isPrepared)) {
|
|
6
|
+
return options;
|
|
7
|
+
}
|
|
8
|
+
const preppedOptions = {
|
|
5
9
|
...options,
|
|
6
10
|
transformers: { ...transformers, ...options.transformers },
|
|
7
11
|
nonvalues: options.nonvalues ?? [undefined],
|
|
12
|
+
neededPipelineIds: options.neededPipelineIds ?? new Set(),
|
|
8
13
|
preparedPipelines: options.preparedPipelines ?? new Map(),
|
|
9
14
|
};
|
|
15
|
+
Object.defineProperty(preppedOptions, isPrepared, {
|
|
16
|
+
value: true,
|
|
17
|
+
enumerable: false,
|
|
18
|
+
});
|
|
19
|
+
return preppedOptions;
|
|
10
20
|
}
|
|
11
21
|
//# sourceMappingURL=prepareOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareOptions.js","sourceRoot":"","sources":["../../../src/legacy/utils/prepareOptions.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,0BAA0B,CAAA;AAGnD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"prepareOptions.js","sourceRoot":"","sources":["../../../src/legacy/utils/prepareOptions.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,0BAA0B,CAAA;AAGnD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAK9E,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;AAkBvC,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC;QACrC,OAAO,OAA0B,CAAA;IACnC,CAAC;IACD,MAAM,cAAc,GAAG;QACrB,GAAG,OAAO;QACV,YAAY,EAAE,EAAE,GAAG,YAAY,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE;QAC1D,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC;QAC3C,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,IAAI,GAAG,EAAmB;QAC1E,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,IAAI,GAAG,EAAE;KAC1D,CAAA;IACD,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,UAAU,EAAE;QAChD,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,KAAK;KAClB,CAAC,CAAA;IACF,OAAO,cAAc,CAAA;AACvB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Operation,
|
|
2
|
-
export declare function getPreparedPipeline(pipelineId: string | symbol, options:
|
|
3
|
-
export declare function preparePipelines(options:
|
|
1
|
+
import type { Operation, InternalOptions } from '../types.js';
|
|
2
|
+
export declare function getPreparedPipeline(pipelineId: string | symbol, options: InternalOptions): Operation | undefined;
|
|
3
|
+
export declare function preparePipelines(options: InternalOptions): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defToNextStateMapper } from './definitionHelpers.js';
|
|
2
2
|
import { noopNext } from './stateHelpers.js';
|
|
3
3
|
export function getPreparedPipeline(pipelineId, options) {
|
|
4
|
-
const
|
|
4
|
+
const { preparedPipelines } = options;
|
|
5
5
|
const prepared = preparedPipelines.get(pipelineId);
|
|
6
6
|
if (prepared) {
|
|
7
7
|
return prepared;
|
|
@@ -14,17 +14,22 @@ export function getPreparedPipeline(pipelineId, options) {
|
|
|
14
14
|
preparedPipelines.set(pipelineId, pipeline);
|
|
15
15
|
return pipeline;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
let stateMapper;
|
|
18
|
+
preparedPipelines.set(pipelineId, () => () => (state) => stateMapper(state));
|
|
19
|
+
try {
|
|
20
|
+
stateMapper = defToNextStateMapper(pipeline, options)(noopNext);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
preparedPipelines.delete(pipelineId);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
18
26
|
const operation = () => () => stateMapper;
|
|
19
27
|
preparedPipelines.set(pipelineId, operation);
|
|
20
28
|
return operation;
|
|
21
29
|
}
|
|
22
30
|
export function preparePipelines(options) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
for (const key of neededPipelineIds) {
|
|
26
|
-
getPreparedPipeline(key, options);
|
|
27
|
-
}
|
|
31
|
+
for (const key of options.neededPipelineIds) {
|
|
32
|
+
getPreparedPipeline(key, options);
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
//# sourceMappingURL=preparedPipelines.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preparedPipelines.js","sourceRoot":"","sources":["../../../src/legacy/utils/preparedPipelines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"preparedPipelines.js","sourceRoot":"","sources":["../../../src/legacy/utils/preparedPipelines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAiB5C,MAAM,UAAU,mBAAmB,CACjC,UAA2B,EAC3B,OAAwB;IAExB,MAAM,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAA;IACrC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAClD,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,CAAA;IAChD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QAEnC,iBAAiB,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QAC3C,OAAO,QAAQ,CAAA;IACjB,CAAC;IAOD,IAAI,WAAwB,CAAA;IAC5B,iBAAiB,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA;IAC5E,IAAI,CAAC;QACH,WAAW,GAAG,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAA;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iBAAiB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QACpC,MAAM,KAAK,CAAA;IACb,CAAC;IAED,MAAM,SAAS,GAAc,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,CAAA;IACpD,iBAAiB,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;IAC5C,OAAO,SAAS,CAAA;AAClB,CAAC;AAQD,MAAM,UAAU,gBAAgB,CAAC,OAAwB;IACvD,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;QAC5C,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "map-transform",
|
|
3
|
-
"version": "1.6.0-rc.
|
|
3
|
+
"version": "1.6.0-rc.7",
|
|
4
4
|
"description": "Map and transform objects with mapping definitions",
|
|
5
5
|
"author": "Kjell-Morten Bratsberg Thorsen <kjellmorten@integreat.io>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
},
|
|
58
58
|
"homepage": "https://github.com/integreat-io/map-transform#readme",
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"deepmerge-ts": "^8.0.
|
|
60
|
+
"deepmerge-ts": "^8.0.2",
|
|
61
61
|
"map-any": "^1.0.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@integreat/ts-dev-setup": "^10.0.0",
|
|
65
65
|
"@types/deep-freeze": "^0.1.5",
|
|
66
|
-
"@types/node": "^26.
|
|
66
|
+
"@types/node": "^26.4.0",
|
|
67
67
|
"@types/sinon": "^22.0.0",
|
|
68
68
|
"deep-freeze": "0.0.1",
|
|
69
69
|
"sinon": "^22.1.0"
|