map-transform 0.4.0-alpha.8 → 0.4.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +186 -40
  2. package/dist/functions/compare.d.ts +2 -1
  3. package/dist/functions/compare.js +26 -5
  4. package/dist/functions/compare.js.map +1 -1
  5. package/dist/functions/explode.js +4 -3
  6. package/dist/functions/explode.js.map +1 -1
  7. package/dist/functions/index.d.ts +4 -0
  8. package/dist/functions/index.js +4 -0
  9. package/dist/functions/index.js.map +1 -1
  10. package/dist/functions/indexFn.d.ts +2 -0
  11. package/dist/functions/indexFn.js +9 -0
  12. package/dist/functions/indexFn.js.map +1 -0
  13. package/dist/functions/joinSplit.d.ts +4 -4
  14. package/dist/functions/joinSplit.js +12 -4
  15. package/dist/functions/joinSplit.js.map +1 -1
  16. package/dist/functions/map.js +5 -4
  17. package/dist/functions/map.js.map +1 -1
  18. package/dist/functions/not.js +1 -1
  19. package/dist/functions/not.js.map +1 -1
  20. package/dist/functions/sort.d.ts +7 -0
  21. package/dist/functions/sort.js +33 -0
  22. package/dist/functions/sort.js.map +1 -0
  23. package/dist/functions/validate.js +2 -2
  24. package/dist/functions/validate.js.map +1 -1
  25. package/dist/functions/value.js +2 -2
  26. package/dist/functions/value.js.map +1 -1
  27. package/dist/index.d.ts +4 -1
  28. package/dist/index.js +8 -2
  29. package/dist/index.js.map +1 -1
  30. package/dist/operations/alt.d.ts +1 -1
  31. package/dist/operations/alt.js +28 -6
  32. package/dist/operations/alt.js.map +1 -1
  33. package/dist/operations/apply.js +10 -5
  34. package/dist/operations/apply.js.map +1 -1
  35. package/dist/operations/concat.js +9 -5
  36. package/dist/operations/concat.js.map +1 -1
  37. package/dist/operations/directionals.js +7 -6
  38. package/dist/operations/directionals.js.map +1 -1
  39. package/dist/operations/filter.js +5 -6
  40. package/dist/operations/filter.js.map +1 -1
  41. package/dist/operations/fixed.js +2 -4
  42. package/dist/operations/fixed.js.map +1 -1
  43. package/dist/operations/getSet.d.ts +3 -3
  44. package/dist/operations/getSet.js +139 -30
  45. package/dist/operations/getSet.js.map +1 -1
  46. package/dist/operations/ifelse.d.ts +1 -1
  47. package/dist/operations/ifelse.js +21 -10
  48. package/dist/operations/ifelse.js.map +1 -1
  49. package/dist/operations/iterate.d.ts +2 -1
  50. package/dist/operations/iterate.js +14 -10
  51. package/dist/operations/iterate.js.map +1 -1
  52. package/dist/operations/logical.d.ts +3 -0
  53. package/dist/operations/logical.js +17 -0
  54. package/dist/operations/logical.js.map +1 -0
  55. package/dist/operations/lookup.js +9 -5
  56. package/dist/operations/lookup.js.map +1 -1
  57. package/dist/operations/merge.js +9 -7
  58. package/dist/operations/merge.js.map +1 -1
  59. package/dist/operations/modify.js +13 -6
  60. package/dist/operations/modify.js.map +1 -1
  61. package/dist/operations/pipe.js +18 -17
  62. package/dist/operations/pipe.js.map +1 -1
  63. package/dist/operations/plug.js +1 -1
  64. package/dist/operations/plug.js.map +1 -1
  65. package/dist/operations/props.d.ts +2 -0
  66. package/dist/operations/props.js +114 -0
  67. package/dist/operations/props.js.map +1 -0
  68. package/dist/operations/root.js +3 -5
  69. package/dist/operations/root.js.map +1 -1
  70. package/dist/operations/transform.js +4 -2
  71. package/dist/operations/transform.js.map +1 -1
  72. package/dist/operations/value.js +2 -4
  73. package/dist/operations/value.js.map +1 -1
  74. package/dist/types.d.ts +39 -12
  75. package/dist/utils/array.d.ts +1 -0
  76. package/dist/utils/array.js +3 -1
  77. package/dist/utils/array.js.map +1 -1
  78. package/dist/utils/definitionHelpers.d.ts +3 -1
  79. package/dist/utils/definitionHelpers.js +72 -17
  80. package/dist/utils/definitionHelpers.js.map +1 -1
  81. package/dist/utils/escape.d.ts +2 -0
  82. package/dist/utils/escape.js +8 -0
  83. package/dist/utils/escape.js.map +1 -0
  84. package/dist/utils/is.d.ts +2 -0
  85. package/dist/utils/is.js +5 -1
  86. package/dist/utils/is.js.map +1 -1
  87. package/dist/utils/pathGetter.js +12 -3
  88. package/dist/utils/pathGetter.js.map +1 -1
  89. package/dist/utils/pathSetter.d.ts +1 -0
  90. package/dist/utils/pathSetter.js +16 -6
  91. package/dist/utils/pathSetter.js.map +1 -1
  92. package/dist/utils/stateHelpers.d.ts +30 -6
  93. package/dist/utils/stateHelpers.js +30 -14
  94. package/dist/utils/stateHelpers.js.map +1 -1
  95. package/dist/utils/xor.d.ts +1 -0
  96. package/dist/utils/xor.js +7 -0
  97. package/dist/utils/xor.js.map +1 -0
  98. package/package.json +6 -6
  99. package/ava-dist.config.cjs +0 -3
  100. package/ava.config.cjs +0 -5
  101. package/dist/functions/join.d.ts +0 -7
  102. package/dist/functions/join.js +0 -12
  103. package/dist/functions/join.js.map +0 -1
  104. package/dist/operations/mutate.d.ts +0 -2
  105. package/dist/operations/mutate.js +0 -80
  106. package/dist/operations/mutate.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "map-transform",
3
- "version": "0.4.0-alpha.8",
3
+ "version": "0.4.0-beta.0",
4
4
  "description": "Map and transform objects with mapping definitions",
5
5
  "author": "Kjell-Morten Bratsberg Thorsen <post@kjellmorten.no>",
6
6
  "license": "ISC",
@@ -36,17 +36,17 @@
36
36
  },
37
37
  "homepage": "https://github.com/integreat-io/map-transform#readme",
38
38
  "dependencies": {
39
- "@types/mustache": "^4.1.2",
40
- "ajv": "^6.12.6",
39
+ "@types/mustache": "^4.2.1",
40
+ "ajv": "^8.11.0",
41
41
  "deepmerge": "^4.2.2",
42
42
  "map-any": "^0.2.1",
43
43
  "mustache": "^4.2.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@integreat/ts-dev-setup": "^2.2.0",
46
+ "@integreat/ts-dev-setup": "^2.3.1",
47
47
  "@types/deep-freeze": "^0.1.2",
48
- "@types/sinon": "^10.0.11",
48
+ "@types/sinon": "^10.0.13",
49
49
  "deep-freeze": "0.0.1",
50
- "sinon": "^13.0.1"
50
+ "sinon": "^14.0.0"
51
51
  }
52
52
  }
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- files: ['dist/**/*.test.js'],
3
- }
package/ava.config.cjs DELETED
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- extensions: ['ts'],
3
- require: ['ts-node/register/transpile-only'],
4
- files: ['src/**/*.test.ts']
5
- }
@@ -1,7 +0,0 @@
1
- import { Operands, DataMapper } from '../types';
2
- interface Options extends Operands {
3
- path?: string | string[];
4
- sep?: string;
5
- }
6
- export default function join({ path, sep }: Options): DataMapper;
7
- export {};
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const pathGetter_1 = require("../utils/pathGetter");
4
- function join({ path = [], sep = ' ' }) {
5
- const getFns = [].concat(path).map(pathGetter_1.default);
6
- return (data) => {
7
- const values = getFns.map((fn) => fn(data));
8
- return values.filter((value) => typeof value !== 'undefined').join(sep);
9
- };
10
- }
11
- exports.default = join;
12
- //# sourceMappingURL=join.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"join.js","sourceRoot":"","sources":["../../src/functions/join.ts"],"names":[],"mappings":";;AACA,oDAAwC;AAOxC,SAAwB,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,GAAG,GAAG,EAAW;IAC5D,MAAM,MAAM,GAAI,EAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,oBAAM,CAAC,CAAA;IAExD,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;QAC3C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACzE,CAAC,CAAA;AACH,CAAC;AAPD,uBAOC"}
@@ -1,2 +0,0 @@
1
- import { Operation, MapObject } from '../types';
2
- export default function mutate(def: MapObject): Operation;
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const stateHelpers_1 = require("../utils/stateHelpers");
4
- const getSet_1 = require("./getSet");
5
- const directionals_1 = require("./directionals");
6
- const iterate_1 = require("./iterate");
7
- const plug_1 = require("./plug");
8
- const definitionHelpers_1 = require("../utils/definitionHelpers");
9
- const array_1 = require("../utils/array");
10
- const setIfPath = (map) => (typeof map === 'string' ? (0, getSet_1.set)(map) : map);
11
- const flipIfNeeded = (pipe, flip) => {
12
- const pipeline = flip ? pipe.slice().reverse().map(setIfPath) : pipe;
13
- return pipeline;
14
- };
15
- const shouldIterate = (def, path) => ((0, definitionHelpers_1.isMapObject)(def) && def['$iterate'] === true) || path.includes('[]');
16
- const extractRealPath = (path) => {
17
- const [realPath, index] = path.split('/');
18
- return [realPath, index !== undefined];
19
- };
20
- const setTargetOnState = (state, target) => ({
21
- ...state,
22
- target,
23
- });
24
- const runWithTarget = (options, state) => (prevState, operation) => operation(options)(setTargetOnState(state, prevState?.value));
25
- const revertTarget = ({ target, ...state }, originalState) => originalState.target ? setTargetOnState(state, originalState.target) : state;
26
- const run = (operations) => function (options) {
27
- const shouldSkip = (0, stateHelpers_1.shouldSkipMutation)(options);
28
- return (state) => shouldSkip(state)
29
- ? (0, stateHelpers_1.setStateValue)(state, undefined)
30
- : revertTarget(operations.reduce(runWithTarget(options, state), undefined) ||
31
- state, state);
32
- };
33
- const objectToMapFunction = (objectDef, flip, parentPath = '') => Object.entries(objectDef)
34
- .flatMap(([path, def]) => {
35
- if (!def || path.startsWith('$')) {
36
- return null;
37
- }
38
- const [realPath, revOnly] = extractRealPath(path);
39
- const nextPath = [parentPath, realPath].filter(Boolean).join('.');
40
- if ((0, definitionHelpers_1.isMapObject)(def) && !def.$iterate && !realPath.endsWith('[]')) {
41
- return objectToMapFunction(def, flip, nextPath);
42
- }
43
- else {
44
- const subPipeline = (0, definitionHelpers_1.isMapObject)(def)
45
- ? [runAndIterate(def, flip, shouldIterate(def, realPath))]
46
- : flipIfNeeded((0, array_1.ensureArray)(def), flip);
47
- const pipeline = (0, definitionHelpers_1.mapFunctionFromDef)([
48
- flip ? nextPath : null,
49
- ...subPipeline,
50
- flip ? null : (0, getSet_1.set)(nextPath),
51
- ]);
52
- return revOnly ? (0, directionals_1.divide)((0, plug_1.default)(), pipeline) : pipeline;
53
- }
54
- })
55
- .filter((pipeline) => !!pipeline);
56
- function runAndIterate(def, flip, doIterate) {
57
- const operations = objectToMapFunction(def, flip);
58
- return doIterate ? (0, iterate_1.default)(run(operations)) : run(operations);
59
- }
60
- function mutate(def) {
61
- if (Object.keys(def).length === 0) {
62
- return (_options) => (state) => (0, stateHelpers_1.setStateValue)(state, undefined);
63
- }
64
- const flip = def.$flip || false;
65
- const runMutation = runAndIterate(def, flip, shouldIterate(def, ''));
66
- return function mutateFn(options) {
67
- const dir = def.$direction;
68
- if (typeof dir === 'string') {
69
- if (dir === 'fwd' || dir === options.fwdAlias) {
70
- return (state) => !state.rev ? runMutation(options)(state) : state;
71
- }
72
- else if (dir === 'rev' || dir === options.revAlias) {
73
- return (state) => state.rev ? runMutation(options)(state) : state;
74
- }
75
- }
76
- return runMutation(options);
77
- };
78
- }
79
- exports.default = mutate;
80
- //# sourceMappingURL=mutate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mutate.js","sourceRoot":"","sources":["../../src/operations/mutate.ts"],"names":[],"mappings":";;AASA,wDAAyE;AACzE,qCAA8B;AAC9B,iDAAuC;AACvC,uCAA+B;AAC/B,iCAAyB;AACzB,kEAA4E;AAC5E,0CAA4C;AAE5C,MAAM,SAAS,GAAG,CAAC,GAAY,EAAE,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,YAAG,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAE9E,MAAM,YAAY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