map-transform 0.5.6 → 1.0.1
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 +130 -53
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/operations/alt.js +21 -23
- package/dist/operations/alt.js.map +1 -1
- package/dist/operations/apply.js +8 -5
- package/dist/operations/apply.js.map +1 -1
- package/dist/operations/concat.d.ts +2 -1
- package/dist/operations/concat.js +34 -11
- package/dist/operations/concat.js.map +1 -1
- package/dist/operations/directionals.d.ts +1 -1
- package/dist/operations/directionals.js +10 -5
- package/dist/operations/directionals.js.map +1 -1
- package/dist/operations/getSet.js +58 -28
- package/dist/operations/getSet.js.map +1 -1
- package/dist/operations/lookup.d.ts +3 -1
- package/dist/operations/lookup.js +27 -31
- package/dist/operations/lookup.js.map +1 -1
- package/dist/operations/merge.d.ts +2 -1
- package/dist/operations/merge.js +1 -1
- package/dist/operations/merge.js.map +1 -1
- package/dist/operations/modify.js +4 -7
- package/dist/operations/modify.js.map +1 -1
- package/dist/operations/pipe.js +4 -4
- package/dist/operations/pipe.js.map +1 -1
- package/dist/operations/props.js +107 -67
- package/dist/operations/props.js.map +1 -1
- package/dist/operations/transform.js +6 -12
- package/dist/operations/transform.js.map +1 -1
- package/dist/transformers/compare.js +17 -8
- package/dist/transformers/compare.js.map +1 -1
- package/dist/transformers/explode.d.ts +2 -3
- package/dist/transformers/explode.js +6 -7
- package/dist/transformers/explode.js.map +1 -1
- package/dist/transformers/index.d.ts +1 -0
- package/dist/transformers/index.js +2 -1
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/merge.d.ts +2 -2
- package/dist/transformers/merge.js +9 -4
- package/dist/transformers/merge.js.map +1 -1
- package/dist/transformers/sort.js +5 -5
- package/dist/transformers/sort.js.map +1 -1
- package/dist/utils/definitionHelpers.js +4 -4
- package/dist/utils/definitionHelpers.js.map +1 -1
- package/dist/utils/is.d.ts +2 -0
- package/dist/utils/is.js +2 -0
- package/dist/utils/is.js.map +1 -1
- package/dist/utils/modifyOperationObject.js +9 -10
- package/dist/utils/modifyOperationObject.js.map +1 -1
- package/dist/utils/stateHelpers.d.ts +26 -3
- package/dist/utils/stateHelpers.js +14 -7
- package/dist/utils/stateHelpers.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ npm install map-transform
|
|
|
46
46
|
- Map objects won't be mapped over an array by default. You have to specify
|
|
47
47
|
`$iterate: true`
|
|
48
48
|
- The `alt` operation now accepts any type of pipeline, but not a helper
|
|
49
|
-
function, and all alternative pipelines must be given as arguments to `alt
|
|
49
|
+
function, and all alternative pipelines must be given as arguments to `alt`
|
|
50
50
|
- The root path prefix is changed from `$` to `^^`
|
|
51
51
|
- The `.rev()` method on `mapTransform()` has been removed, and instead you pass
|
|
52
52
|
in `{ rev: true }` as the second argument to the regular method
|
|
@@ -422,7 +422,7 @@ const def6 = [
|
|
|
422
422
|
custom transformers for this case, but their implementations are not provided.)
|
|
423
423
|
|
|
424
424
|
**A note on arrays:** In a transform pipeline, the default behavior is to treat
|
|
425
|
-
an array as any other data. The array will be passed on to a `transform
|
|
425
|
+
an array as any other data. The array will be passed on to a `transform`
|
|
426
426
|
operation, the entire array will be set on a path, etc. This also means that a
|
|
427
427
|
mapping object will be applied to the entire array if nothing else is specified.
|
|
428
428
|
In the example above, we have set `$iterate: true` on the mapping object, to
|
|
@@ -551,7 +551,7 @@ Operations may be used as steps in a transform pipeline.
|
|
|
551
551
|
|
|
552
552
|
#### `transform(transformFn, transformFnRev)` operation
|
|
553
553
|
|
|
554
|
-
The simple beauty of the `transform
|
|
554
|
+
The simple beauty of the `transform` operation, is that it will apply whatever
|
|
555
555
|
function (transformer) you provide it with to the data at that point in the
|
|
556
556
|
pipeline. It's up to you to write the function that does the transformation – or
|
|
557
557
|
use one of [the transformers that comes with MapTransform](#transformers).
|
|
@@ -559,7 +559,7 @@ use one of [the transformers that comes with MapTransform](#transformers).
|
|
|
559
559
|
You may supply a second transformer (`transformFnRev`), that will be used when
|
|
560
560
|
[reverse mapping](#reverse-mapping). If you only supplies one transformer, it
|
|
561
561
|
will be used in both directions. You may supply `null` for either of these, to
|
|
562
|
-
make it uni-directional, but it might be clearer to use `fwd
|
|
562
|
+
make it uni-directional, but it might be clearer to use `fwd` or `rev`
|
|
563
563
|
operations for this.
|
|
564
564
|
|
|
565
565
|
The transformers you write for the transform operation are a function that
|
|
@@ -754,8 +754,8 @@ value from your transformer will simply mean that it is replaced with
|
|
|
754
754
|
`undefined`.
|
|
755
755
|
|
|
756
756
|
The filter operation only accepts one argument, which is applied in both
|
|
757
|
-
directions through the pipeline. You'll have to use `fwd
|
|
758
|
-
|
|
757
|
+
directions through the pipeline. You'll have to use `fwd` or `rev` operations to
|
|
758
|
+
make it uni-directional.
|
|
759
759
|
|
|
760
760
|
Transformers passed to the filter operation should also be pure, but
|
|
761
761
|
could, when it is expected and absolutely necessary, rely on anything outside
|
|
@@ -803,14 +803,14 @@ You may also set `$direction: 'fwd'` or `$direction: 'rev'` on the object, to
|
|
|
803
803
|
have it filter in one direction only.
|
|
804
804
|
|
|
805
805
|
See
|
|
806
|
-
[the `transform
|
|
807
|
-
|
|
806
|
+
[the `transform` operation](#transformtransformfn-transformfnrev-operation) for
|
|
807
|
+
more on how defining as an object works.
|
|
808
808
|
|
|
809
809
|
#### `ifelse(conditionFn, truePipeline, falsePipeline)` operation
|
|
810
810
|
|
|
811
|
-
The `ifelse
|
|
812
|
-
|
|
813
|
-
`falsePipeline`. See [the `filter
|
|
811
|
+
The `ifelse` operation will run the `truePipeline` if the `conditionFn` results
|
|
812
|
+
in something truthy, JavaScript style, otherwise it will run the
|
|
813
|
+
`falsePipeline`. See [the `filter` operation](#filterconditionFn-operation)
|
|
814
814
|
for more on the requirements for the `conditionFn`.
|
|
815
815
|
|
|
816
816
|
Both `truePipeline` and `falsePipeline` are optional, in case you only need to
|
|
@@ -1015,15 +1015,15 @@ order, with the last being run first. The first pipeline is always run, though,
|
|
|
1015
1015
|
as it is common practice to let the first be a `get` that acts like a `set` in
|
|
1016
1016
|
reverse. This may be confusing, but will usually just be naturally when you
|
|
1017
1017
|
don't think too much about it. See
|
|
1018
|
-
[the `get
|
|
1019
|
-
|
|
1018
|
+
[the `get` and `set` operations](#getpath-and-setpath-operation) for more on how
|
|
1019
|
+
`get` works in reverse.
|
|
1020
1020
|
|
|
1021
1021
|
`alt` will behave a bit differently when you give only one pipeline: The
|
|
1022
1022
|
pipeline will be run if the curent value is `undefined`, but skipped otherwise.
|
|
1023
1023
|
This is different from the multi-pipeline behavor, where the first is always run
|
|
1024
1024
|
and the rest is only run if the previous returns `undefined`.
|
|
1025
1025
|
|
|
1026
|
-
You may also define an alt operation as an object:
|
|
1026
|
+
You may also define an alt operation as an operation object:
|
|
1027
1027
|
|
|
1028
1028
|
```javascript
|
|
1029
1029
|
const def11asObject = {
|
|
@@ -1046,33 +1046,66 @@ direction only.
|
|
|
1046
1046
|
|
|
1047
1047
|
#### `concat(pipeline, pipeline, ...)` operation
|
|
1048
1048
|
|
|
1049
|
-
The `concat
|
|
1049
|
+
The `concat` operation will flatten the result of every pipeline it is given
|
|
1050
1050
|
into one array. A pipeline that does not return an array will simple have its
|
|
1051
|
-
return value appended to the array.
|
|
1051
|
+
return value appended to the array. Even when there's only one pipeline, its
|
|
1052
|
+
value will be forced to an array. `undefined` will be filtered away from the
|
|
1053
|
+
returned array.
|
|
1052
1054
|
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1055
|
+
In reverse, the value (array) will be set on the first pipeline, and the rest of
|
|
1056
|
+
the pipelines will be given an empty array. The results of all the pipelines
|
|
1057
|
+
will be merged.
|
|
1058
|
+
|
|
1059
|
+
If `concat` is not given any pipelines, it will return an empty array going
|
|
1060
|
+
forward, and an empty object in reverse. The reason for the empty object is that
|
|
1061
|
+
the normal behavior for concat is to get with paths from an object, and with
|
|
1062
|
+
no paths, we can't set any props, so an empty object is the best we can do.
|
|
1063
|
+
|
|
1064
|
+
> **Note:** This operation is destructive, in that the result from running it
|
|
1065
|
+
> forward cannot reproduce the original data when run in reverse. Only the data
|
|
1066
|
+
> fetched by the given pipelines will be preserved, and the merged arrays cannot
|
|
1067
|
+
> be unmerged.
|
|
1056
1068
|
|
|
1057
1069
|
```javascript
|
|
1058
|
-
{
|
|
1059
|
-
|
|
1070
|
+
import { concat } from 'map-transform'
|
|
1071
|
+
|
|
1072
|
+
const def39 = {
|
|
1073
|
+
id: 'data.id',
|
|
1074
|
+
users: concat('data.users', 'data.admins'),
|
|
1060
1075
|
}
|
|
1061
1076
|
```
|
|
1062
1077
|
|
|
1063
|
-
|
|
1078
|
+
You may also define a concat operation as an operation object:
|
|
1079
|
+
|
|
1080
|
+
```javascript
|
|
1081
|
+
const def39asObject = {
|
|
1082
|
+
id: 'data.id',
|
|
1083
|
+
users: { $concat: ['data.users', 'data.admins'] },
|
|
1084
|
+
}
|
|
1085
|
+
```
|
|
1086
|
+
|
|
1087
|
+
#### `concatRev(pipeline, pipeline, ...)` operation
|
|
1088
|
+
|
|
1089
|
+
The `concatRev` operation is the exact oposite of the `concat` operation,
|
|
1090
|
+
meaning that it will exhibit the same behavior in reverse as `concat` does
|
|
1091
|
+
going forward, and vice versa. See the description of
|
|
1092
|
+
[the `concat` operation](#concatpipeline-pipeline--operation) for more
|
|
1093
|
+
details.
|
|
1094
|
+
|
|
1095
|
+
Note that `concatRev` does not have an operation object notation, but `concat`
|
|
1096
|
+
will honor the [flipped mode](#flipping-a-transform-object).
|
|
1064
1097
|
|
|
1065
1098
|
#### `merge(pipeline, pipeline, ...)` operation
|
|
1066
1099
|
|
|
1067
|
-
`merge
|
|
1068
|
-
|
|
1100
|
+
`merge` will run all given pipelines and deep merge their results. Conflicts are
|
|
1101
|
+
resolved by prioritizing results from the rightmost of the conflicting
|
|
1069
1102
|
pipelines.
|
|
1070
1103
|
|
|
1071
1104
|
> Editors note: We need examples here.
|
|
1072
1105
|
|
|
1073
1106
|
#### `modify(pipeline)` operation
|
|
1074
1107
|
|
|
1075
|
-
Use the `modify
|
|
1108
|
+
Use the `modify` operation when you want the pipeline to modify an object,
|
|
1076
1109
|
instead of replacing it.
|
|
1077
1110
|
|
|
1078
1111
|
Example:
|
|
@@ -1104,7 +1137,7 @@ const response = {
|
|
|
1104
1137
|
}
|
|
1105
1138
|
```
|
|
1106
1139
|
|
|
1107
|
-
Had we ran this without the `modify
|
|
1140
|
+
Had we ran this without the `modify` operation, the returned object would only
|
|
1108
1141
|
have the `data` prop, as no props from the source data will be set in the target
|
|
1109
1142
|
data, unless they are "picked up" by dot notation paths.
|
|
1110
1143
|
|
|
@@ -1129,6 +1162,24 @@ const def34c = {
|
|
|
1129
1162
|
}
|
|
1130
1163
|
```
|
|
1131
1164
|
|
|
1165
|
+
The `$modify` flag may also be set on a path:
|
|
1166
|
+
|
|
1167
|
+
```javascript
|
|
1168
|
+
const def34d = {
|
|
1169
|
+
'content.$modify': 'response',
|
|
1170
|
+
'content.data': 'response.data.deeply.placed.items',
|
|
1171
|
+
}
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
This is the way to set it for reverse direction:
|
|
1175
|
+
|
|
1176
|
+
```javascript
|
|
1177
|
+
const def34e = {
|
|
1178
|
+
response: '$modify',
|
|
1179
|
+
'response.data.deeply.placed.items': 'data',
|
|
1180
|
+
}
|
|
1181
|
+
```
|
|
1182
|
+
|
|
1132
1183
|
Note that setting a path like this, is only available when the `modify`
|
|
1133
1184
|
operation is defined as an operation object.
|
|
1134
1185
|
|
|
@@ -1136,10 +1187,10 @@ operation is defined as an operation object.
|
|
|
1136
1187
|
|
|
1137
1188
|
All operations in MapTransform will apply in both directions, although some of
|
|
1138
1189
|
them may behave a bit different dependending on the direction. If you want an
|
|
1139
|
-
operation to only apply in one direction, you need to wrap it in a `fwd
|
|
1140
|
-
`rev
|
|
1190
|
+
operation to only apply in one direction, you need to wrap it in a `fwd` or
|
|
1191
|
+
`rev` operation. The `fwd` operation will only apply its pipeline when we're
|
|
1141
1192
|
going forward, i.e. mapping in the normal direction, and its pipeline will be
|
|
1142
|
-
skipped when we're mapping in reverse. The `rev
|
|
1193
|
+
skipped when we're mapping in reverse. The `rev` operation will only apply its
|
|
1143
1194
|
pipeline when we're mapping in reverse.
|
|
1144
1195
|
|
|
1145
1196
|
The value in the pipeline will be untouched when we are encountering an
|
|
@@ -1174,15 +1225,15 @@ at the description of
|
|
|
1174
1225
|
|
|
1175
1226
|
#### `divide(fwdPipeline, revPipeline)` operation
|
|
1176
1227
|
|
|
1177
|
-
`divide
|
|
1178
|
-
|
|
1228
|
+
`divide` is `fwd` and `rev` operations combined, where the first argument is a
|
|
1229
|
+
pipeline to use when going forward and the second when going in reverse.
|
|
1179
1230
|
|
|
1180
|
-
See [`fwd
|
|
1231
|
+
See [`fwd` and `rev`](#fwdpipeline-and-revpipeline-operation) for more details.
|
|
1181
1232
|
|
|
1182
1233
|
#### `get(path)` and `set(path)` operation
|
|
1183
1234
|
|
|
1184
|
-
Both the `get
|
|
1185
|
-
|
|
1235
|
+
Both the `get` and `set` operations accepts a dot notation path to act on. The
|
|
1236
|
+
get operation will pull the data at the path from the data currently in the
|
|
1186
1237
|
pipeline, and replace the value in the pipeline with it. The set operation will
|
|
1187
1238
|
take what ever's in the pipeline and set it on the given path at a new object.
|
|
1188
1239
|
|
|
@@ -1285,23 +1336,33 @@ const def16b = divide(root('meta.section'), plug())
|
|
|
1285
1336
|
|
|
1286
1337
|
#### `plug()` operation
|
|
1287
1338
|
|
|
1288
|
-
The `plug
|
|
1339
|
+
The `plug` operation simply clears the value in the pipeline - it plugs it.
|
|
1289
1340
|
The value will be set to `undefined` regardless of what has happened before that
|
|
1290
|
-
point. Any `alt
|
|
1341
|
+
point. Any `alt` operations etc. coming after the plug will still have an
|
|
1291
1342
|
effect.
|
|
1292
1343
|
|
|
1293
1344
|
This main use case for this is to clear the value going one way. E.g. if you
|
|
1294
1345
|
need a value when you map in reverse, but don't want it going forward, plug it
|
|
1295
1346
|
with `fwd(plug())`. You will also need it in a pipeline where the only operation
|
|
1296
|
-
is uni-directional (i.e. using `fwd
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1347
|
+
is uni-directional (i.e. using `fwd` or `rev`). An empty pipeline (which is what
|
|
1348
|
+
a uni-directional pipeline will be in the other direction), will return the data
|
|
1349
|
+
you give it, which is usually not what you want in these cases. The solution is
|
|
1350
|
+
to plug it in the other direction.
|
|
1300
1351
|
|
|
1301
1352
|
You could have accomplished the same with `transform(value(undefined))`, but
|
|
1302
|
-
this will not work when `state.noDefaults` is `true`. `plug
|
|
1353
|
+
this will not work when `state.noDefaults` is `true`. `plug` will do its trick
|
|
1303
1354
|
in all cases.
|
|
1304
1355
|
|
|
1356
|
+
#### `lookdown({ arrayPath, propPath, matchSeveral })` operation
|
|
1357
|
+
|
|
1358
|
+
The `lookdown` operation is the exact oposite of `lookup`, and the name is
|
|
1359
|
+
marelly word-play on that. See
|
|
1360
|
+
[the `lookup` operation](#lookup-arraypath-proppath-matchseveral-operation)
|
|
1361
|
+
for more on how it works, just reverse the directions.
|
|
1362
|
+
|
|
1363
|
+
Note that `lookdown` does not have an operation object notation, but `lookup`
|
|
1364
|
+
will honor the [flipped mode](#flipping-a-transform-object).
|
|
1365
|
+
|
|
1305
1366
|
#### `lookup({ arrayPath, propPath, matchSeveral })` operation
|
|
1306
1367
|
|
|
1307
1368
|
`lookup` will take the value in the pipeline and replace it with the first
|
|
@@ -1312,10 +1373,11 @@ returned. Default is `false`.
|
|
|
1312
1373
|
|
|
1313
1374
|
In reverse, the `propPath` will simply be used as a get path, getting the prop
|
|
1314
1375
|
of the objects out of the objects, so to speak. (In the future, MapTransform
|
|
1315
|
-
_might_ support setting the items back on the `arrayPath` in reverse.)
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
[flipped mode](#flipping-a-transform-object)
|
|
1376
|
+
_might_ support setting the items back on the `arrayPath` in reverse.)
|
|
1377
|
+
|
|
1378
|
+
> **Note:** When `lookup` is called within a transform object in
|
|
1379
|
+
> [flipped mode](#flipping-a-transform-object), it will behave in the opposite
|
|
1380
|
+
> way, looking up in reverse mode and extracting `propPath` going forward.
|
|
1319
1381
|
|
|
1320
1382
|
Example:
|
|
1321
1383
|
|
|
@@ -1362,8 +1424,8 @@ values in the pipeline.
|
|
|
1362
1424
|
|
|
1363
1425
|
This is a transformer intended for use with the `filter` operation. You
|
|
1364
1426
|
pass a dot notation `path` and a `match` value (string, number, boolean, `null`
|
|
1365
|
-
or `undefined`) to `compare
|
|
1366
|
-
`filter
|
|
1427
|
+
or `undefined`) to `compare`, and it returns a function that you can pass to
|
|
1428
|
+
`filter` for filtering away data that does not not have the value set at the
|
|
1367
1429
|
provided path.
|
|
1368
1430
|
|
|
1369
1431
|
As an alternative to `match`, you may specify a `matchPath`, which is a dot
|
|
@@ -1483,7 +1545,7 @@ When used outside of an iteration, it always returns `0`.
|
|
|
1483
1545
|
|
|
1484
1546
|
This is the exact opposite of the `explode` helper, imploding going forward and
|
|
1485
1547
|
exploding in reverse. See
|
|
1486
|
-
[the documentation for `explode
|
|
1548
|
+
[the documentation for `explode`](#explode-transformer) for how this works.
|
|
1487
1549
|
|
|
1488
1550
|
#### `logical({ path, operator })` transformer
|
|
1489
1551
|
|
|
@@ -1590,6 +1652,15 @@ one object. Merging happens from left to right, so the props of the last object
|
|
|
1590
1652
|
will have priority. However, `undefined` values will never overwrite another
|
|
1591
1653
|
value.
|
|
1592
1654
|
|
|
1655
|
+
In reverse, the pipeline data will be provided to every pipeline in `path`, as
|
|
1656
|
+
there is no way of splitting up the "original" data. In most cases the pipeline
|
|
1657
|
+
data will be set on the props they were "originally" fetched and merged from.
|
|
1658
|
+
|
|
1659
|
+
> **Note:** This transformer is destructive, in that the result from running it
|
|
1660
|
+
> forward cannot reproduce the original data when run in reverse. Only the data
|
|
1661
|
+
> fetched by the given pipelines will be preserved, and the merged object cannot
|
|
1662
|
+
> be unmerged.
|
|
1663
|
+
|
|
1593
1664
|
```javascript
|
|
1594
1665
|
import mapTransform, { transform, transformers } from 'map-transform'
|
|
1595
1666
|
const { merge } = transformers
|
|
@@ -1616,10 +1687,16 @@ const def38b = {
|
|
|
1616
1687
|
}
|
|
1617
1688
|
```
|
|
1618
1689
|
|
|
1690
|
+
#### `mergeRev({path})` transformer
|
|
1691
|
+
|
|
1692
|
+
The `mergeRev` transformer has the opposite behavior of the `merge` transformer,
|
|
1693
|
+
in that it will do forward what `merge` does in reverse, and vice versa. See
|
|
1694
|
+
[the `merge` transformer](#mergepath-transformer) for more details.
|
|
1695
|
+
|
|
1619
1696
|
#### `not(value)` transformer
|
|
1620
1697
|
|
|
1621
|
-
`not
|
|
1622
|
-
when value is falsy. This is useful for making the `filter
|
|
1698
|
+
`not` will return `false` when the value in the pipeline is truthy, and `true`
|
|
1699
|
+
when value is falsy. This is useful for making the `filter` operation do the
|
|
1623
1700
|
opposite of what the filter transformer implies.
|
|
1624
1701
|
|
|
1625
1702
|
Here we filter _away_ all data where role is set to 'admin':
|
|
@@ -1878,13 +1955,13 @@ same goes for flipped transform objects if you want to forward transform.
|
|
|
1878
1955
|
|
|
1879
1956
|
MapTransform will try its best to map the data to the shape you want, and will
|
|
1880
1957
|
always set all properties, even though the mapping you defined result in
|
|
1881
|
-
`undefined`. You may include `alt
|
|
1958
|
+
`undefined`. You may include `alt` operations to provide default or fallback
|
|
1882
1959
|
values for these cases.
|
|
1883
1960
|
|
|
1884
1961
|
But sometimes, you only want the data that is actually present in the source
|
|
1885
1962
|
data, without defaults or properties set to `undefined`. You may accomplish this
|
|
1886
1963
|
by setting `state.noDefaults` to true, either by setting in on the initial state
|
|
1887
|
-
given to `mapTransform()
|
|
1964
|
+
given to `mapTransform()` or by setting the `$noDefaults` flag on a transform
|
|
1888
1965
|
object (will set `noDefaults` on the state for everything happening within that
|
|
1889
1966
|
transform object).
|
|
1890
1967
|
|
|
@@ -1966,7 +2043,7 @@ versions, and should not be used in custom transformers:
|
|
|
1966
2043
|
- `target`: The target object at the current point. When setting on a path, the
|
|
1967
2044
|
setting will happen on this target.
|
|
1968
2045
|
|
|
1969
|
-
Note that you may provide the `mapTransform()
|
|
2046
|
+
Note that you may provide the `mapTransform()` function with an initial state
|
|
1970
2047
|
object as its second argument. Only `rev`, `noDefaults`, and `target` will be
|
|
1971
2048
|
passed on from the state object you provide.
|
|
1972
2049
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ import type { TransformDefinition, DataMapper, Options, InitialState } from './t
|
|
|
2
2
|
import transformers from './transformers/index.js';
|
|
3
3
|
import iterate from './operations/iterate.js';
|
|
4
4
|
export { default as apply } from './operations/apply.js';
|
|
5
|
-
export {
|
|
5
|
+
export { concat, concatRev } from './operations/concat.js';
|
|
6
6
|
export { default as alt } from './operations/alt.js';
|
|
7
7
|
export { fwd, rev, divide } from './operations/directionals.js';
|
|
8
8
|
export { default as filter } from './operations/filter.js';
|
|
9
9
|
export { get, set } from './operations/getSet.js';
|
|
10
10
|
export { default as ifelse } from './operations/ifelse.js';
|
|
11
|
-
export {
|
|
11
|
+
export { lookup, lookdown } from './operations/lookup.js';
|
|
12
12
|
export { default as merge } from './operations/merge.js';
|
|
13
13
|
export { default as modify } from './operations/modify.js';
|
|
14
14
|
export { default as plug } from './operations/plug.js';
|
package/dist/index.js
CHANGED
|
@@ -3,13 +3,13 @@ import { populateState, getStateValue, noopNext } from './utils/stateHelpers.js'
|
|
|
3
3
|
import transformers from './transformers/index.js';
|
|
4
4
|
import iterate from './operations/iterate.js';
|
|
5
5
|
export { default as apply } from './operations/apply.js';
|
|
6
|
-
export {
|
|
6
|
+
export { concat, concatRev } from './operations/concat.js';
|
|
7
7
|
export { default as alt } from './operations/alt.js';
|
|
8
8
|
export { fwd, rev, divide } from './operations/directionals.js';
|
|
9
9
|
export { default as filter } from './operations/filter.js';
|
|
10
10
|
export { get, set } from './operations/getSet.js';
|
|
11
11
|
export { default as ifelse } from './operations/ifelse.js';
|
|
12
|
-
export {
|
|
12
|
+
export { lookup, lookdown } from './operations/lookup.js';
|
|
13
13
|
export { default as merge } from './operations/merge.js';
|
|
14
14
|
export { default as modify } from './operations/modify.js';
|
|
15
15
|
export { default as plug } from './operations/plug.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAChF,OAAO,YAAY,MAAM,yBAAyB,CAAA;AAClD,OAAO,OAAO,MAAM,yBAAyB,CAAA;AAE7C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAChF,OAAO,YAAY,MAAM,yBAAyB,CAAA;AAClD,OAAO,OAAO,MAAM,yBAAyB,CAAA;AAE7C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAA;A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
|
|
2
|
+
import { setValueFromState, popContext, isNonvalueState, setStateValue, } from '../utils/stateHelpers.js';
|
|
3
3
|
import { defToOperations } from '../utils/definitionHelpers.js';
|
|
4
4
|
import { noopNext } from '../utils/stateHelpers.js';
|
|
5
5
|
const pipeIfArray = (def) => Array.isArray(def) ? pipe(def, true) : def;
|
|
6
|
-
|
|
6
|
+
const isUntouched = (afterState, beforeState) => beforeState.value === afterState.value;
|
|
7
|
+
async function runAltPipeline(pipeline, state) {
|
|
8
|
+
const afterState = await pipeline(state);
|
|
9
|
+
return isUntouched(afterState, state)
|
|
10
|
+
? setStateValue(afterState, undefined)
|
|
11
|
+
: afterState;
|
|
12
|
+
}
|
|
13
|
+
function createOneAltPipeline(def, index, hasOnlyOneAlt) {
|
|
7
14
|
return (options) => {
|
|
8
|
-
const
|
|
15
|
+
const pipeline = pipeIfArray(defToOperations(def, options))(options)(noopNext);
|
|
16
|
+
const isFirst = !hasOnlyOneAlt && index === 0;
|
|
17
|
+
const { nonvalues } = options;
|
|
9
18
|
return (next) => async (state) => {
|
|
10
19
|
const nextState = await next(state);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (isFirst) {
|
|
14
|
-
const thisState = await operation(options)(noopNext)(nextState);
|
|
15
|
-
return isNonvalueState(thisState, nonvalues)
|
|
16
|
-
? { ...thisState, context: [...nextState.context, nextState.value] }
|
|
17
|
-
: thisState;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
if (isNonvalueState(nextState, nonvalues)) {
|
|
21
|
-
const thisState = await operation(options)(noopNext)(removeLastContext(setStateValue(nextState, getLastContext(nextState))));
|
|
22
|
-
return isNonvalueState(thisState, nonvalues)
|
|
23
|
-
? setValueFromState(nextState, thisState)
|
|
24
|
-
: thisState;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return nextState;
|
|
28
|
-
}
|
|
20
|
+
if (!isFirst && !isNonvalueState(nextState, nonvalues)) {
|
|
21
|
+
return nextState;
|
|
29
22
|
}
|
|
23
|
+
const beforeState = isFirst ? nextState : popContext(nextState);
|
|
24
|
+
const afterState = await runAltPipeline(pipeline, beforeState);
|
|
25
|
+
return isNonvalueState(afterState, nonvalues)
|
|
26
|
+
? setValueFromState(nextState, afterState, isFirst)
|
|
27
|
+
: afterState;
|
|
30
28
|
};
|
|
31
29
|
};
|
|
32
30
|
}
|
|
33
31
|
export default function alt(...defs) {
|
|
34
|
-
const
|
|
35
|
-
return defs.map((def, index) =>
|
|
32
|
+
const hasOnlyOneAlt = defs.length === 1;
|
|
33
|
+
return defs.map((def, index) => createOneAltPipeline(def, index, hasOnlyOneAlt));
|
|
36
34
|
}
|
|
37
35
|
//# sourceMappingURL=alt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alt.js","sourceRoot":"","sources":["../../src/operations/alt.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"alt.js","sourceRoot":"","sources":["../../src/operations/alt.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAUnD,MAAM,WAAW,GAAG,CAAC,GAA4B,EAAE,EAAE,CACnD,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;AAK5C,MAAM,WAAW,GAAG,CAAC,UAAiB,EAAE,WAAkB,EAAE,EAAE,CAC5D,WAAW,CAAC,KAAK,KAAK,UAAU,CAAC,KAAK,CAAA;AAcxC,KAAK,UAAU,cAAc,CAAC,QAAqB,EAAE,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Aa,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAA;IACvC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAC7B,oBAAoB,CAAC,GAAG,EAAE,KAAK,EAAE,aAAa,CAAC,CAChD,CAAA;AACH,CAAC"}
|
package/dist/operations/apply.js
CHANGED
|
@@ -10,6 +10,13 @@ function setPipeline(id, operation, options) {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
const removeFlip = ({ flip, ...state }) => state;
|
|
13
|
+
function prepareAndSetPipeline(pipelineId, pipeline, options) {
|
|
14
|
+
if (typeof pipeline !== 'function' && pipeline) {
|
|
15
|
+
setPipeline(pipelineId, () => () => noopNext, options);
|
|
16
|
+
const operation = defToOperation(pipeline, options)(options);
|
|
17
|
+
setPipeline(pipelineId, () => operation, options);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
13
20
|
export default function apply(pipelineId) {
|
|
14
21
|
return (options) => {
|
|
15
22
|
const pipeline = getPipeline(pipelineId, options);
|
|
@@ -19,11 +26,7 @@ export default function apply(pipelineId) {
|
|
|
19
26
|
: 'Failed to apply pipeline. No id provided';
|
|
20
27
|
throw new Error(message);
|
|
21
28
|
}
|
|
22
|
-
|
|
23
|
-
setPipeline(pipelineId, () => () => noopNext, options);
|
|
24
|
-
const operation = defToOperation(pipeline, options)(options);
|
|
25
|
-
setPipeline(pipelineId, () => operation, options);
|
|
26
|
-
}
|
|
29
|
+
prepareAndSetPipeline(pipelineId, pipeline, options);
|
|
27
30
|
return (next) => {
|
|
28
31
|
const operation = getPipeline(pipelineId, options);
|
|
29
32
|
const fn = typeof operation === 'function'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/operations/apply.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/operations/apply.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,c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,CAAC,UAAU,CAAC,qBAAqB;gBACtE,CAAC,CAAC,0CAA0C,CAAA;YAC9C,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;SACzB;QAED,qBAAqB,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;QAEpD,OAAO,CAAC,IAAI,EAAE,EAAE;YAEd,MAAM,SAAS,GAAG,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;YAClD,MAAM,EAAE,GACN,OAAO,SAAS,KAAK,UAAU;gBAC7B,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC;gBAC9B,CAAC,CAAC,SAAS,CAAA;YACf,IAAI,EAAE,EAAE;gBAIN,WAAW,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;aACjD;YAED,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE;gBACrB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,CAAA;gBACnC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;YACnD,CAAC,CAAA;QACH,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { Operation, TransformDefinition } from '../types.js';
|
|
2
|
-
export
|
|
2
|
+
export declare function concat(...defs: TransformDefinition[]): Operation;
|
|
3
|
+
export declare function concatRev(...defs: TransformDefinition[]): Operation;
|
|
@@ -1,19 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mergeStates } from './merge.js';
|
|
2
|
+
import { setStateValue, getStateValue, revFromState, flipState, } from '../utils/stateHelpers.js';
|
|
2
3
|
import { defToOperation } from '../utils/definitionHelpers.js';
|
|
3
4
|
import { noopNext } from '../utils/stateHelpers.js';
|
|
4
5
|
const merge = (left, right) => Array.isArray(right) ? [...left, ...right] : [...left, right];
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
async function getAndMergeArrays(state, fns) {
|
|
7
|
+
let nextValue = [];
|
|
8
|
+
for (const fn of fns) {
|
|
9
|
+
const value = getStateValue(await fn(state));
|
|
10
|
+
nextValue = merge(nextValue, value);
|
|
11
|
+
}
|
|
12
|
+
return setStateValue(state, nextValue.filter((val) => val !== undefined));
|
|
13
|
+
}
|
|
14
|
+
async function setArrayOnFirstOperation(state, fns) {
|
|
15
|
+
let valueState = await fns[0](state);
|
|
16
|
+
for (const fn of fns.slice(1)) {
|
|
17
|
+
const thisState = await fn(setStateValue(state, []));
|
|
18
|
+
valueState = mergeStates(valueState, thisState);
|
|
19
|
+
}
|
|
20
|
+
return valueState;
|
|
21
|
+
}
|
|
22
|
+
function concatPipelines(defs, flip) {
|
|
23
|
+
return (options) => {
|
|
7
24
|
const fns = defs.map((def) => defToOperation(def, options)(options)(noopNext));
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
if (fns.length === 0) {
|
|
26
|
+
return (next) => async (state) => setStateValue(await next(state), revFromState(state, flip) ? {} : []);
|
|
27
|
+
}
|
|
28
|
+
return (next) => async function doConcat(state) {
|
|
29
|
+
const nextState = flipState(await next(state), flip);
|
|
30
|
+
return revFromState(nextState)
|
|
31
|
+
? setArrayOnFirstOperation(nextState, fns)
|
|
32
|
+
: getAndMergeArrays(nextState, fns);
|
|
16
33
|
};
|
|
17
34
|
};
|
|
18
35
|
}
|
|
36
|
+
export function concat(...defs) {
|
|
37
|
+
return concatPipelines(defs, false);
|
|
38
|
+
}
|
|
39
|
+
export function concatRev(...defs) {
|
|
40
|
+
return concatPipelines(defs, true);
|
|
41
|
+
}
|
|
19
42
|
//# sourceMappingURL=concat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concat.js","sourceRoot":"","sources":["../../src/operations/concat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"concat.js","sourceRoot":"","sources":["../../src/operations/concat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,SAAS,GACV,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAQnD,MAAM,KAAK,GAAG,CAAO,IAAS,EAAE,KAAc,EAAE,EAAE,CAChD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,CAAA;AAI/D,KAAK,UAAU,iBAAiB,CAAC,KAAY,EAAE,GAAkB;IAC/D,IAAI,SAAS,GAAc,EAAE,CAAA;IAC7B,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE;QACpB,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;QAC5C,SAAS,GAAG,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;KACpC;IACD,OAAO,aAAa,CAClB,KAAK,EACL,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,SAAS,CAAC,CAC7C,CAAA;AACH,CAAC;AAID,KAAK,UAAU,wBAAwB,CAAC,KAAY,EAAE,GAAkB;IACtE,IAAI,UAAU,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IACpC,KAAK,MAAM,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QAC7B,MAAM,SAAS,GAAG,MAAM,EAAE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AE,IAAI,CAAC,CAAA;AACpC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { TransformDefinition, Operation } from '../types.js';
|
|
2
2
|
export declare function fwd(def: TransformDefinition): Operation;
|
|
3
3
|
export declare function rev(def: TransformDefinition): Operation;
|
|
4
|
-
export declare function divide(fwdDef: TransformDefinition, revDef: TransformDefinition): Operation;
|
|
4
|
+
export declare function divide(fwdDef: TransformDefinition, revDef: TransformDefinition, honorFlip?: boolean): Operation;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { defToOperation } from '../utils/definitionHelpers.js';
|
|
2
|
-
import
|
|
3
|
-
const applyInDirection = (def,
|
|
2
|
+
import { revFromState } from '../utils/stateHelpers.js';
|
|
3
|
+
const applyInDirection = (def, shouldRunRev) => (options) => (next) => {
|
|
4
4
|
const fn = defToOperation(def, options)(options)(next);
|
|
5
|
-
return async
|
|
5
|
+
return async function applyFwdOrRev(state) {
|
|
6
|
+
return !!state.rev === shouldRunRev ? await fn(state) : await next(state);
|
|
7
|
+
};
|
|
6
8
|
};
|
|
7
9
|
export function fwd(def) {
|
|
8
10
|
return applyInDirection(def, false);
|
|
@@ -10,11 +12,14 @@ export function fwd(def) {
|
|
|
10
12
|
export function rev(def) {
|
|
11
13
|
return applyInDirection(def, true);
|
|
12
14
|
}
|
|
13
|
-
export function divide(fwdDef, revDef) {
|
|
15
|
+
export function divide(fwdDef, revDef, honorFlip = false) {
|
|
14
16
|
return (options) => (next) => {
|
|
15
17
|
const fwdFn = defToOperation(fwdDef, options)(options)(next);
|
|
16
18
|
const revFn = defToOperation(revDef, options)(options)(next);
|
|
17
|
-
return async
|
|
19
|
+
return async function applyDivide(state) {
|
|
20
|
+
const isRev = honorFlip ? revFromState(state) : !!state.rev;
|
|
21
|
+
return isRev ? await revFn(state) : await fwdFn(state);
|
|
22
|
+
};
|
|
18
23
|
};
|
|
19
24
|
}
|
|
20
25
|
//# sourceMappingURL=directionals.js.map
|