@valbuild/core 0.12.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 (100) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/README.md +537 -0
  3. package/dist/createClass-012eebbf.esm.js +109 -0
  4. package/dist/createClass-a436dbfe.cjs.dev.js +116 -0
  5. package/dist/createClass-de7426aa.cjs.prod.js +116 -0
  6. package/dist/declarations/src/Json.d.ts +6 -0
  7. package/dist/declarations/src/expr/eval.d.ts +19 -0
  8. package/dist/declarations/src/expr/expr.d.ts +32 -0
  9. package/dist/declarations/src/expr/index.d.ts +3 -0
  10. package/dist/declarations/src/expr/parser.d.ts +8 -0
  11. package/dist/declarations/src/expr/tokenizer.d.ts +7 -0
  12. package/dist/declarations/src/fetchVal.d.ts +5 -0
  13. package/dist/declarations/src/fp/array.d.ts +8 -0
  14. package/dist/declarations/src/fp/index.d.ts +3 -0
  15. package/dist/declarations/src/fp/result.d.ts +67 -0
  16. package/dist/declarations/src/fp/util.d.ts +12 -0
  17. package/dist/declarations/src/index.d.ts +32 -0
  18. package/dist/declarations/src/initSchema.d.ts +57 -0
  19. package/dist/declarations/src/initVal.d.ts +39 -0
  20. package/dist/declarations/src/module.d.ts +38 -0
  21. package/dist/declarations/src/patch/deref.d.ts +13 -0
  22. package/dist/declarations/src/patch/index.d.ts +6 -0
  23. package/dist/declarations/src/patch/json.d.ts +11 -0
  24. package/dist/declarations/src/patch/operation.d.ts +59 -0
  25. package/dist/declarations/src/patch/ops.d.ts +40 -0
  26. package/dist/declarations/src/patch/parse.d.ts +19 -0
  27. package/dist/declarations/src/patch/patch.d.ts +6 -0
  28. package/dist/declarations/src/patch/util.d.ts +6 -0
  29. package/dist/declarations/src/schema/array.d.ts +18 -0
  30. package/dist/declarations/src/schema/boolean.d.ts +15 -0
  31. package/dist/declarations/src/schema/i18n.d.ts +21 -0
  32. package/dist/declarations/src/schema/image.d.ts +32 -0
  33. package/dist/declarations/src/schema/index.d.ts +23 -0
  34. package/dist/declarations/src/schema/literal.d.ts +17 -0
  35. package/dist/declarations/src/schema/number.d.ts +22 -0
  36. package/dist/declarations/src/schema/object.d.ts +25 -0
  37. package/dist/declarations/src/schema/oneOf.d.ts +22 -0
  38. package/dist/declarations/src/schema/richtext.d.ts +76 -0
  39. package/dist/declarations/src/schema/string.d.ts +22 -0
  40. package/dist/declarations/src/schema/union.d.ts +36 -0
  41. package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
  42. package/dist/declarations/src/selector/array.d.ts +17 -0
  43. package/dist/declarations/src/selector/boolean.d.ts +2 -0
  44. package/dist/declarations/src/selector/file.d.ts +9 -0
  45. package/dist/declarations/src/selector/i18n.d.ts +11 -0
  46. package/dist/declarations/src/selector/index.d.ts +81 -0
  47. package/dist/declarations/src/selector/number.d.ts +2 -0
  48. package/dist/declarations/src/selector/object.d.ts +10 -0
  49. package/dist/declarations/src/selector/primitive.d.ts +9 -0
  50. package/dist/declarations/src/selector/remote.d.ts +7 -0
  51. package/dist/declarations/src/selector/string.d.ts +2 -0
  52. package/dist/declarations/src/source/file.d.ts +23 -0
  53. package/dist/declarations/src/source/i18n.d.ts +29 -0
  54. package/dist/declarations/src/source/index.d.ts +33 -0
  55. package/dist/declarations/src/source/remote.d.ts +29 -0
  56. package/dist/declarations/src/val/array.d.ts +9 -0
  57. package/dist/declarations/src/val/index.d.ts +53 -0
  58. package/dist/declarations/src/val/object.d.ts +9 -0
  59. package/dist/declarations/src/val/primitive.d.ts +7 -0
  60. package/dist/index-2f1631cf.cjs.prod.js +1031 -0
  61. package/dist/index-55916dcd.esm.js +1000 -0
  62. package/dist/index-b49a2c60.cjs.dev.js +1031 -0
  63. package/dist/ops-6fae92a1.esm.js +12 -0
  64. package/dist/ops-87cdbafc.cjs.dev.js +14 -0
  65. package/dist/ops-ae4d1bc2.cjs.prod.js +14 -0
  66. package/dist/result-26f67b40.cjs.prod.js +299 -0
  67. package/dist/result-48320acd.cjs.dev.js +299 -0
  68. package/dist/result-b96df128.esm.js +279 -0
  69. package/dist/util-030d8a1f.cjs.prod.js +29 -0
  70. package/dist/util-18613e99.esm.js +26 -0
  71. package/dist/util-b213092b.cjs.dev.js +29 -0
  72. package/dist/valbuild-core.cjs.d.ts +2 -0
  73. package/dist/valbuild-core.cjs.d.ts.map +1 -0
  74. package/dist/valbuild-core.cjs.dev.js +1276 -0
  75. package/dist/valbuild-core.cjs.js +7 -0
  76. package/dist/valbuild-core.cjs.prod.js +1276 -0
  77. package/dist/valbuild-core.esm.js +1265 -0
  78. package/expr/dist/valbuild-core-expr.cjs.d.ts +2 -0
  79. package/expr/dist/valbuild-core-expr.cjs.d.ts.map +1 -0
  80. package/expr/dist/valbuild-core-expr.cjs.dev.js +18 -0
  81. package/expr/dist/valbuild-core-expr.cjs.js +7 -0
  82. package/expr/dist/valbuild-core-expr.cjs.prod.js +18 -0
  83. package/expr/dist/valbuild-core-expr.esm.js +3 -0
  84. package/expr/package.json +4 -0
  85. package/fp/dist/valbuild-core-fp.cjs.d.ts +2 -0
  86. package/fp/dist/valbuild-core-fp.cjs.d.ts.map +1 -0
  87. package/fp/dist/valbuild-core-fp.cjs.dev.js +13 -0
  88. package/fp/dist/valbuild-core-fp.cjs.js +7 -0
  89. package/fp/dist/valbuild-core-fp.cjs.prod.js +13 -0
  90. package/fp/dist/valbuild-core-fp.esm.js +2 -0
  91. package/fp/package.json +4 -0
  92. package/package.json +43 -0
  93. package/patch/dist/valbuild-core-patch.cjs.d.ts +2 -0
  94. package/patch/dist/valbuild-core-patch.cjs.d.ts.map +1 -0
  95. package/patch/dist/valbuild-core-patch.cjs.dev.js +443 -0
  96. package/patch/dist/valbuild-core-patch.cjs.js +7 -0
  97. package/patch/dist/valbuild-core-patch.cjs.prod.js +443 -0
  98. package/patch/dist/valbuild-core-patch.esm.js +431 -0
  99. package/patch/package.json +4 -0
  100. package/tsconfig.json +7 -0
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/expr/index";
2
+ //# sourceMappingURL=valbuild-core-expr.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valbuild-core-expr.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/expr/index.d.ts"],"names":[],"mappings":"AAAA"}
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-b49a2c60.cjs.dev.js');
6
+ require('../../dist/createClass-a436dbfe.cjs.dev.js');
7
+ require('../../dist/result-48320acd.cjs.dev.js');
8
+
9
+
10
+
11
+ exports.Call = expr_dist_valbuildCoreExpr.Call;
12
+ exports.Expr = expr_dist_valbuildCoreExpr.Expr;
13
+ exports.NilSym = expr_dist_valbuildCoreExpr.NilSym;
14
+ exports.StringLiteral = expr_dist_valbuildCoreExpr.StringLiteral;
15
+ exports.StringTemplate = expr_dist_valbuildCoreExpr.StringTemplate;
16
+ exports.Sym = expr_dist_valbuildCoreExpr.Sym;
17
+ exports.evaluate = expr_dist_valbuildCoreExpr.evaluate;
18
+ exports.parse = expr_dist_valbuildCoreExpr.parse;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./valbuild-core-expr.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./valbuild-core-expr.cjs.dev.js");
7
+ }
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-2f1631cf.cjs.prod.js');
6
+ require('../../dist/createClass-de7426aa.cjs.prod.js');
7
+ require('../../dist/result-26f67b40.cjs.prod.js');
8
+
9
+
10
+
11
+ exports.Call = expr_dist_valbuildCoreExpr.Call;
12
+ exports.Expr = expr_dist_valbuildCoreExpr.Expr;
13
+ exports.NilSym = expr_dist_valbuildCoreExpr.NilSym;
14
+ exports.StringLiteral = expr_dist_valbuildCoreExpr.StringLiteral;
15
+ exports.StringTemplate = expr_dist_valbuildCoreExpr.StringTemplate;
16
+ exports.Sym = expr_dist_valbuildCoreExpr.Sym;
17
+ exports.evaluate = expr_dist_valbuildCoreExpr.evaluate;
18
+ exports.parse = expr_dist_valbuildCoreExpr.parse;
@@ -0,0 +1,3 @@
1
+ export { C as Call, E as Expr, N as NilSym, q as StringLiteral, r as StringTemplate, s as Sym, t as evaluate, p as parse } from '../../dist/index-55916dcd.esm.js';
2
+ import '../../dist/createClass-012eebbf.esm.js';
3
+ import '../../dist/result-b96df128.esm.js';
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/valbuild-core-expr.cjs.js",
3
+ "module": "dist/valbuild-core-expr.esm.js"
4
+ }
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/fp/index";
2
+ //# sourceMappingURL=valbuild-core-fp.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valbuild-core-fp.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/fp/index.d.ts"],"names":[],"mappings":"AAAA"}
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var result = require('../../dist/result-48320acd.cjs.dev.js');
6
+ var util = require('../../dist/util-b213092b.cjs.dev.js');
7
+
8
+
9
+
10
+ exports.array = result.array;
11
+ exports.result = result.result;
12
+ exports.pipe = util.pipe;
13
+ exports.tap = util.tap;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./valbuild-core-fp.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./valbuild-core-fp.cjs.dev.js");
7
+ }
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var result = require('../../dist/result-26f67b40.cjs.prod.js');
6
+ var util = require('../../dist/util-030d8a1f.cjs.prod.js');
7
+
8
+
9
+
10
+ exports.array = result.array;
11
+ exports.result = result.result;
12
+ exports.pipe = util.pipe;
13
+ exports.tap = util.tap;
@@ -0,0 +1,2 @@
1
+ export { d as array, r as result } from '../../dist/result-b96df128.esm.js';
2
+ export { p as pipe, t as tap } from '../../dist/util-18613e99.esm.js';
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/valbuild-core-fp.cjs.js",
3
+ "module": "dist/valbuild-core-fp.esm.js"
4
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@valbuild/core",
3
+ "version": "0.12.0",
4
+ "scripts": {
5
+ "typecheck": "tsc --noEmit",
6
+ "test": "jest",
7
+ "analyze-trace": "npx tsc -p tsconfig.json --skipLibCheck --generateTrace trace; npx -p @typescript/analyze-trace analyze-trace trace; npx speedscope trace/trace.json"
8
+ },
9
+ "main": "dist/valbuild-core.cjs.js",
10
+ "module": "dist/valbuild-core.esm.js",
11
+ "exports": {
12
+ ".": {
13
+ "module": "./dist/valbuild-core.esm.js",
14
+ "default": "./dist/valbuild-core.cjs.js"
15
+ },
16
+ "./fp": {
17
+ "module": "./fp/dist/valbuild-core-fp.esm.js",
18
+ "default": "./fp/dist/valbuild-core-fp.cjs.js"
19
+ },
20
+ "./expr": {
21
+ "module": "./expr/dist/valbuild-core-expr.esm.js",
22
+ "default": "./expr/dist/valbuild-core-expr.cjs.js"
23
+ },
24
+ "./patch": {
25
+ "module": "./patch/dist/valbuild-core-patch.esm.js",
26
+ "default": "./patch/dist/valbuild-core-patch.cjs.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "types": "dist/valbuild-core.cjs.d.ts",
31
+ "preconstruct": {
32
+ "entrypoints": [
33
+ "./index.ts",
34
+ "./fp/index.ts",
35
+ "./patch/index.ts",
36
+ "./expr/index.ts"
37
+ ],
38
+ "exports": true
39
+ },
40
+ "dependencies": {
41
+ "ts-toolbelt": "^9.6.0"
42
+ }
43
+ }
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/patch/index";
2
+ //# sourceMappingURL=valbuild-core-patch.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valbuild-core-patch.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/patch/index.d.ts"],"names":[],"mappings":"AAAA"}
@@ -0,0 +1,443 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var createClass = require('../../dist/createClass-a436dbfe.cjs.dev.js');
6
+ var result = require('../../dist/result-48320acd.cjs.dev.js');
7
+ var util = require('../../dist/util-b213092b.cjs.dev.js');
8
+ var ops = require('../../dist/ops-87cdbafc.cjs.dev.js');
9
+
10
+ function isNotRoot(path) {
11
+ return result.isNonEmpty(path);
12
+ }
13
+ function deepEqual(a, b) {
14
+ if (a === b) {
15
+ return true;
16
+ }
17
+ if (createClass._typeof(a) === "object" && createClass._typeof(b) === "object" && a !== null && b !== null) {
18
+ if (Array.isArray(a) && Array.isArray(b)) {
19
+ if (a.length !== b.length) return false;
20
+ for (var i = 0; i < a.length; ++i) {
21
+ if (!deepEqual(a[i], b[i])) return false;
22
+ }
23
+ return true;
24
+ } else if (!Array.isArray(a) && !Array.isArray(b)) {
25
+ var aEntries = Object.entries(a);
26
+ // If the objects have a different amount of keys, they cannot be equal
27
+ if (aEntries.length !== Object.keys(b).length) return false;
28
+ for (var _i = 0, _aEntries = aEntries; _i < _aEntries.length; _i++) {
29
+ var _aEntries$_i = createClass._slicedToArray(_aEntries[_i], 2),
30
+ key = _aEntries$_i[0],
31
+ aValue = _aEntries$_i[1];
32
+ // b must be a JSON object, so the only way for the bValue to be
33
+ // undefined is if the key is unset
34
+ var bValue = b[key];
35
+ if (bValue === undefined) return false;
36
+ if (!deepEqual(aValue, bValue)) return false;
37
+ }
38
+ return true;
39
+ }
40
+ }
41
+ return false;
42
+ }
43
+ function deepClone(value) {
44
+ if (Array.isArray(value)) {
45
+ return value.map(deepClone);
46
+ } else if (createClass._typeof(value) === "object" && value !== null) {
47
+ return Object.fromEntries(Object.entries(value).map(function (_ref) {
48
+ var _ref2 = createClass._slicedToArray(_ref, 2),
49
+ key = _ref2[0],
50
+ value = _ref2[1];
51
+ return [key, deepClone(value)];
52
+ }));
53
+ } else {
54
+ return value;
55
+ }
56
+ }
57
+ function parseAndValidateArrayIndex(value) {
58
+ if (!/^(0|[1-9][0-9]*)$/g.test(value)) {
59
+ return result.err(new ops.PatchError("Invalid array index \"".concat(value, "\"")));
60
+ }
61
+ return result.ok(Number(value));
62
+ }
63
+
64
+ function parseAndValidateArrayInsertIndex(key, nodes) {
65
+ if (key === "-") {
66
+ return result.ok(nodes.length);
67
+ }
68
+ return util.pipe(parseAndValidateArrayIndex(key), result.filterOrElse(function (index) {
69
+ return index <= nodes.length;
70
+ }, function () {
71
+ return new ops.PatchError("Array index out of bounds");
72
+ }));
73
+ }
74
+ function parseAndValidateArrayInboundsIndex(key, nodes) {
75
+ return util.pipe(parseAndValidateArrayIndex(key), result.filterOrElse(function (index) {
76
+ return index < nodes.length;
77
+ }, function () {
78
+ return new ops.PatchError("Array index out of bounds");
79
+ }));
80
+ }
81
+ function replaceInNode(node, key, value) {
82
+ if (Array.isArray(node)) {
83
+ return util.pipe(parseAndValidateArrayInboundsIndex(key, node), result.map(function (index) {
84
+ var replaced = node[index];
85
+ node[index] = value;
86
+ return replaced;
87
+ }));
88
+ } else if (createClass._typeof(node) === "object" && node !== null) {
89
+ // Prototype pollution protection
90
+ if (Object.prototype.hasOwnProperty.call(node, key)) {
91
+ var _replaced = node[key];
92
+ node[key] = value;
93
+ return result.ok(_replaced);
94
+ } else {
95
+ return result.err(new ops.PatchError("Cannot replace object element which does not exist"));
96
+ }
97
+ }
98
+ return result.err(new ops.PatchError("Cannot replace in non-object/array"));
99
+ }
100
+ function replaceAtPath(document, path, value) {
101
+ if (isNotRoot(path)) {
102
+ return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref) {
103
+ var _ref2 = createClass._slicedToArray(_ref, 2),
104
+ node = _ref2[0],
105
+ key = _ref2[1];
106
+ return replaceInNode(node, key, value);
107
+ }), result.map(function (replaced) {
108
+ return [document, replaced];
109
+ }));
110
+ } else {
111
+ return result.ok([value, document]);
112
+ }
113
+ }
114
+ function getFromNode(node, key) {
115
+ if (Array.isArray(node)) {
116
+ return util.pipe(parseAndValidateArrayIndex(key), result.flatMap(function (index) {
117
+ if (index >= node.length) {
118
+ return result.err(new ops.PatchError("Array index out of bounds"));
119
+ } else {
120
+ return result.ok(node[index]);
121
+ }
122
+ }));
123
+ } else if (createClass._typeof(node) === "object" && node !== null) {
124
+ // Prototype pollution protection
125
+ if (Object.prototype.hasOwnProperty.call(node, key)) {
126
+ return result.ok(node[key]);
127
+ } else {
128
+ return result.ok(undefined);
129
+ }
130
+ }
131
+ return result.err(new ops.PatchError("Cannot access non-object/array"));
132
+ }
133
+ function getPointerFromPath(node, path) {
134
+ var targetNode = node;
135
+ var key = path[0];
136
+ for (var i = 0; i < path.length - 1; ++i, key = path[i]) {
137
+ var childNode = getFromNode(targetNode, key);
138
+ if (result.isErr(childNode)) {
139
+ return childNode;
140
+ }
141
+ if (childNode.value === undefined) {
142
+ return result.err(new ops.PatchError("Path refers to non-existing object/array"));
143
+ }
144
+ targetNode = childNode.value;
145
+ }
146
+ return result.ok([targetNode, key]);
147
+ }
148
+ function getAtPath(node, path) {
149
+ return util.pipe(path, result.flatMapReduce(function (node, key) {
150
+ return util.pipe(getFromNode(node, key), result.filterOrElse(function (childNode) {
151
+ return childNode !== undefined;
152
+ }, function () {
153
+ return new ops.PatchError("Path refers to non-existing object/array");
154
+ }));
155
+ }, node));
156
+ }
157
+ function removeFromNode(node, key) {
158
+ if (Array.isArray(node)) {
159
+ return util.pipe(parseAndValidateArrayInboundsIndex(key, node), result.map(function (index) {
160
+ var _node$splice = node.splice(index, 1),
161
+ _node$splice2 = createClass._slicedToArray(_node$splice, 1),
162
+ removed = _node$splice2[0];
163
+ return removed;
164
+ }));
165
+ } else if (createClass._typeof(node) === "object" && node !== null) {
166
+ // Prototype pollution protection
167
+ if (Object.prototype.hasOwnProperty.call(node, key)) {
168
+ var removed = node[key];
169
+ delete node[key];
170
+ return result.ok(removed);
171
+ }
172
+ }
173
+ return result.err(new ops.PatchError("Cannot remove from non-object/array"));
174
+ }
175
+ function removeAtPath(document, path) {
176
+ return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref3) {
177
+ var _ref4 = createClass._slicedToArray(_ref3, 2),
178
+ node = _ref4[0],
179
+ key = _ref4[1];
180
+ return removeFromNode(node, key);
181
+ }));
182
+ }
183
+ function addToNode(node, key, value) {
184
+ if (Array.isArray(node)) {
185
+ return util.pipe(parseAndValidateArrayInsertIndex(key, node), result.map(function (index) {
186
+ node.splice(index, 0, value);
187
+ return undefined;
188
+ }));
189
+ } else if (createClass._typeof(node) === "object" && node !== null) {
190
+ var _replaced2;
191
+ // Prototype pollution protection
192
+ if (Object.prototype.hasOwnProperty.call(node, key)) {
193
+ _replaced2 = node[key];
194
+ }
195
+ node[key] = value;
196
+ return result.ok(_replaced2);
197
+ }
198
+ return result.err(new ops.PatchError("Cannot add to non-object/array"));
199
+ }
200
+ function addAtPath(document, path, value) {
201
+ if (isNotRoot(path)) {
202
+ return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref5) {
203
+ var _ref6 = createClass._slicedToArray(_ref5, 2),
204
+ node = _ref6[0],
205
+ key = _ref6[1];
206
+ return addToNode(node, key, value);
207
+ }), result.map(function (replaced) {
208
+ return [document, replaced];
209
+ }));
210
+ } else {
211
+ return result.ok([value, document]);
212
+ }
213
+ }
214
+ function pickDocument(_ref7) {
215
+ var _ref8 = createClass._slicedToArray(_ref7, 1),
216
+ document = _ref8[0];
217
+ return document;
218
+ }
219
+ var JSONOps = /*#__PURE__*/function () {
220
+ function JSONOps() {
221
+ createClass._classCallCheck(this, JSONOps);
222
+ }
223
+ createClass._createClass(JSONOps, [{
224
+ key: "get",
225
+ value: function get(document, path) {
226
+ return getAtPath(document, path);
227
+ }
228
+ }, {
229
+ key: "add",
230
+ value: function add(document, path, value) {
231
+ return util.pipe(addAtPath(document, path, value), result.map(pickDocument));
232
+ }
233
+ }, {
234
+ key: "remove",
235
+ value: function remove(document, path) {
236
+ return util.pipe(removeAtPath(document, path), result.map(function () {
237
+ return document;
238
+ }));
239
+ }
240
+ }, {
241
+ key: "replace",
242
+ value: function replace(document, path, value) {
243
+ return util.pipe(replaceAtPath(document, path, value), result.map(pickDocument));
244
+ }
245
+ }, {
246
+ key: "move",
247
+ value: function move(document, from, path) {
248
+ return util.pipe(removeAtPath(document, from), result.flatMap(function (removed) {
249
+ return addAtPath(document, path, removed);
250
+ }), result.map(pickDocument));
251
+ }
252
+ }, {
253
+ key: "copy",
254
+ value: function copy(document, from, path) {
255
+ return util.pipe(getAtPath(document, from), result.flatMap(function (value) {
256
+ return addAtPath(document, path, deepClone(value));
257
+ }), result.map(pickDocument));
258
+ }
259
+ }, {
260
+ key: "test",
261
+ value: function test(document, path, value) {
262
+ return util.pipe(getAtPath(document, path), result.map(function (documentValue) {
263
+ return deepEqual(value, documentValue);
264
+ }));
265
+ }
266
+ }]);
267
+ return JSONOps;
268
+ }();
269
+
270
+ function parseJSONPointerReferenceToken(value) {
271
+ if (value.endsWith("~")) {
272
+ return undefined;
273
+ }
274
+ try {
275
+ return value.replace(/~./, function (escaped) {
276
+ switch (escaped) {
277
+ case "~0":
278
+ return "~";
279
+ case "~1":
280
+ return "/";
281
+ }
282
+ throw new Error();
283
+ });
284
+ } catch (e) {
285
+ return undefined;
286
+ }
287
+ }
288
+ function parseJSONPointer(pointer) {
289
+ if (pointer === "/") return result.ok([]);
290
+ if (!pointer.startsWith("/")) return result.err("JSON pointer must start with /");
291
+ var tokens = pointer.substring(1).split("/").map(parseJSONPointerReferenceToken);
292
+ if (tokens.every(function (token) {
293
+ return token !== undefined;
294
+ })) {
295
+ return result.ok(tokens);
296
+ } else {
297
+ return result.err("Invalid JSON pointer escape sequence");
298
+ }
299
+ }
300
+ function formatJSONPointerReferenceToken(key) {
301
+ return key.replace(/~/g, "~0").replace(/\//g, "~1");
302
+ }
303
+ function formatJSONPointer(path) {
304
+ return "/".concat(path.map(formatJSONPointerReferenceToken).join("/"));
305
+ }
306
+
307
+ /**
308
+ * A signifies an issue that makes a PatchJSON or an OperationJSON invalid.
309
+ * Unlike PatchError, a StaticPatchIssue indicates an issue with the patch
310
+ * document itself; it is independent of any document which the patch or
311
+ * might be applied to.
312
+ */
313
+
314
+ function prefixIssuePath(prefix, _ref) {
315
+ var path = _ref.path,
316
+ message = _ref.message;
317
+ return {
318
+ path: [prefix].concat(createClass._toConsumableArray(path)),
319
+ message: message
320
+ };
321
+ }
322
+ function createIssueAtPath(path) {
323
+ return function (message) {
324
+ return {
325
+ path: path,
326
+ message: message
327
+ };
328
+ };
329
+ }
330
+ function isProperPathPrefix(prefix, path) {
331
+ if (prefix.length >= path.length) {
332
+ // A proper prefix cannot be longer or have the same length as the path
333
+ return false;
334
+ }
335
+ for (var i = 0; i < prefix.length; ++i) {
336
+ if (prefix[i] !== path[i]) {
337
+ return false;
338
+ }
339
+ }
340
+ return true;
341
+ }
342
+ function parseOperation(operation) {
343
+ var path = parseJSONPointer(operation.path);
344
+ switch (operation.op) {
345
+ case "add":
346
+ case "replace":
347
+ case "test":
348
+ return util.pipe(path, result.mapErr(function (error) {
349
+ return [createIssueAtPath(["path"])(error)];
350
+ }), result.map(function (path) {
351
+ return {
352
+ op: operation.op,
353
+ path: path,
354
+ value: operation.value
355
+ };
356
+ }));
357
+ case "remove":
358
+ return util.pipe(path, result.filterOrElse(result.isNonEmpty, function () {
359
+ return "Cannot remove root";
360
+ }), result.mapErr(function (error) {
361
+ return [createIssueAtPath(["path"])(error)];
362
+ }), result.map(function (path) {
363
+ return {
364
+ op: operation.op,
365
+ path: path
366
+ };
367
+ }));
368
+ case "move":
369
+ return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.filterOrElse(result.isNonEmpty, function () {
370
+ return "Cannot move root";
371
+ }), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.filterOrElse(function (_ref2) {
372
+ var _ref3 = createClass._slicedToArray(_ref2, 2),
373
+ from = _ref3[0],
374
+ path = _ref3[1];
375
+ return !isProperPathPrefix(from, path);
376
+ }, function () {
377
+ return [createIssueAtPath(["from"])("Cannot be a proper prefix of path")];
378
+ }), result.map(function (_ref4) {
379
+ var _ref5 = createClass._slicedToArray(_ref4, 2),
380
+ from = _ref5[0],
381
+ path = _ref5[1];
382
+ return {
383
+ op: operation.op,
384
+ from: from,
385
+ path: path
386
+ };
387
+ }));
388
+ case "copy":
389
+ return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.map(function (_ref6) {
390
+ var _ref7 = createClass._slicedToArray(_ref6, 2),
391
+ from = _ref7[0],
392
+ path = _ref7[1];
393
+ return {
394
+ op: operation.op,
395
+ from: from,
396
+ path: path
397
+ };
398
+ }));
399
+ }
400
+ }
401
+ function parsePatch(patch) {
402
+ return util.pipe(patch.map(parseOperation).map(result.mapErr(result.map$1(function (error, index) {
403
+ return prefixIssuePath(index.toString(), error);
404
+ }))), result.all, result.mapErr(result.flatten));
405
+ }
406
+
407
+ function apply(document, ops$1, op) {
408
+ switch (op.op) {
409
+ case "add":
410
+ return ops$1.add(document, op.path, op.value);
411
+ case "remove":
412
+ return ops$1.remove(document, op.path);
413
+ case "replace":
414
+ return ops$1.replace(document, op.path, op.value);
415
+ case "move":
416
+ return ops$1.move(document, op.from, op.path);
417
+ case "copy":
418
+ return ops$1.copy(document, op.from, op.path);
419
+ case "test":
420
+ {
421
+ if (!ops$1.test(document, op.path, op.value)) {
422
+ return result.err(new ops.PatchError("Test failed"));
423
+ }
424
+ return result.ok(document);
425
+ }
426
+ }
427
+ }
428
+ function applyPatch(document, ops, patch) {
429
+ return util.pipe(patch, result.flatMapReduce(function (doc, op) {
430
+ return apply(doc, ops, op);
431
+ }, document));
432
+ }
433
+
434
+ exports.PatchError = ops.PatchError;
435
+ exports.JSONOps = JSONOps;
436
+ exports.applyPatch = applyPatch;
437
+ exports.deepClone = deepClone;
438
+ exports.deepEqual = deepEqual;
439
+ exports.formatJSONPointer = formatJSONPointer;
440
+ exports.isNotRoot = isNotRoot;
441
+ exports.parseAndValidateArrayIndex = parseAndValidateArrayIndex;
442
+ exports.parseJSONPointer = parseJSONPointer;
443
+ exports.parsePatch = parsePatch;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./valbuild-core-patch.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./valbuild-core-patch.cjs.dev.js");
7
+ }