@valbuild/core 0.61.0 → 0.62.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.
@@ -2,10 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-f2552460.cjs.prod.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-596f28bb.cjs.prod.js');
6
6
  var result = require('../../dist/result-26f67b40.cjs.prod.js');
7
7
  var util = require('../../dist/util-030d8a1f.cjs.prod.js');
8
- var ops = require('../../dist/ops-92570725.cjs.prod.js');
9
8
 
10
9
  function isNotRoot(path) {
11
10
  return result.isNonEmpty(path);
@@ -14,7 +13,7 @@ function deepEqual(a, b) {
14
13
  if (a === b) {
15
14
  return true;
16
15
  }
17
- if (index._typeof(a) === "object" && index._typeof(b) === "object" && a !== null && b !== null) {
16
+ if (expr_dist_valbuildCoreExpr._typeof(a) === "object" && expr_dist_valbuildCoreExpr._typeof(b) === "object" && a !== null && b !== null) {
18
17
  if (Array.isArray(a) && Array.isArray(b)) {
19
18
  if (a.length !== b.length) return false;
20
19
  for (var i = 0; i < a.length; ++i) {
@@ -26,7 +25,7 @@ function deepEqual(a, b) {
26
25
  // If the objects have a different amount of keys, they cannot be equal
27
26
  if (aEntries.length !== Object.keys(b).length) return false;
28
27
  for (var _i = 0, _aEntries = aEntries; _i < _aEntries.length; _i++) {
29
- var _aEntries$_i = index._slicedToArray(_aEntries[_i], 2),
28
+ var _aEntries$_i = expr_dist_valbuildCoreExpr._slicedToArray(_aEntries[_i], 2),
30
29
  key = _aEntries$_i[0],
31
30
  aValue = _aEntries$_i[1];
32
31
  // b must be a JSON object, so the only way for the bValue to be
@@ -43,9 +42,9 @@ function deepEqual(a, b) {
43
42
  function deepClone(value) {
44
43
  if (Array.isArray(value)) {
45
44
  return value.map(deepClone);
46
- } else if (index._typeof(value) === "object" && value !== null) {
45
+ } else if (expr_dist_valbuildCoreExpr._typeof(value) === "object" && value !== null) {
47
46
  return Object.fromEntries(Object.entries(value).map(function (_ref) {
48
- var _ref2 = index._slicedToArray(_ref, 2),
47
+ var _ref2 = expr_dist_valbuildCoreExpr._slicedToArray(_ref, 2),
49
48
  key = _ref2[0],
50
49
  value = _ref2[1];
51
50
  return [key, deepClone(value)];
@@ -56,14 +55,14 @@ function deepClone(value) {
56
55
  }
57
56
  function parseAndValidateArrayIndex(value) {
58
57
  if (!/^(0|[1-9][0-9]*)$/g.test(value)) {
59
- return result.err(new ops.PatchError("Invalid array index \"".concat(value, "\"")));
58
+ return result.err(new expr_dist_valbuildCoreExpr.PatchError("Invalid array index \"".concat(value, "\"")));
60
59
  }
61
60
  return result.ok(Number(value));
62
61
  }
63
62
  function sourceToPatchPath(sourcePath) {
64
- var _splitModuleIdAndModu = ops.splitModuleIdAndModulePath(sourcePath),
65
- _splitModuleIdAndModu2 = index._slicedToArray(_splitModuleIdAndModu, 2),
66
- modulePath = _splitModuleIdAndModu2[1];
63
+ var _splitModuleFilePathA = expr_dist_valbuildCoreExpr.splitModuleFilePathAndModulePath(sourcePath),
64
+ _splitModuleFilePathA2 = expr_dist_valbuildCoreExpr._slicedToArray(_splitModuleFilePathA, 2),
65
+ modulePath = _splitModuleFilePathA2[1];
67
66
  return modulePath.split(".").map(function (p) {
68
67
  return JSON.parse(p).toString();
69
68
  });
@@ -76,14 +75,14 @@ function parseAndValidateArrayInsertIndex(key, nodes) {
76
75
  return util.pipe(parseAndValidateArrayIndex(key), result.filterOrElse(function (index) {
77
76
  return index <= nodes.length;
78
77
  }, function () {
79
- return new ops.PatchError("Array index out of bounds");
78
+ return new expr_dist_valbuildCoreExpr.PatchError("Array index out of bounds");
80
79
  }));
81
80
  }
82
81
  function parseAndValidateArrayInboundsIndex(key, nodes) {
83
82
  return util.pipe(parseAndValidateArrayIndex(key), result.filterOrElse(function (index) {
84
83
  return index < nodes.length;
85
84
  }, function () {
86
- return new ops.PatchError("Array index out of bounds");
85
+ return new expr_dist_valbuildCoreExpr.PatchError("Array index out of bounds");
87
86
  }));
88
87
  }
89
88
  function replaceInNode(node, key, value) {
@@ -93,25 +92,22 @@ function replaceInNode(node, key, value) {
93
92
  node[index] = value;
94
93
  return replaced;
95
94
  }));
96
- } else if (index._typeof(node) === "object" && node !== null) {
95
+ } else if (expr_dist_valbuildCoreExpr._typeof(node) === "object" && node !== null) {
97
96
  // Prototype pollution protection
98
97
  if (Object.prototype.hasOwnProperty.call(node, key)) {
99
98
  var _replaced = node[key];
100
99
  node[key] = value;
101
100
  return result.ok(_replaced);
102
101
  } else {
103
- console.log({
104
- node: node
105
- });
106
- return result.err(new ops.PatchError("Cannot replace object element which does not exist"));
102
+ return result.err(new expr_dist_valbuildCoreExpr.PatchError("Cannot replace object element which does not exist"));
107
103
  }
108
104
  }
109
- return result.err(new ops.PatchError("Cannot replace in non-object/array"));
105
+ return result.err(new expr_dist_valbuildCoreExpr.PatchError("Cannot replace in non-object/array"));
110
106
  }
111
107
  function replaceAtPath(document, path, value) {
112
108
  if (isNotRoot(path)) {
113
109
  return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref) {
114
- var _ref2 = index._slicedToArray(_ref, 2),
110
+ var _ref2 = expr_dist_valbuildCoreExpr._slicedToArray(_ref, 2),
115
111
  node = _ref2[0],
116
112
  key = _ref2[1];
117
113
  return replaceInNode(node, key, value);
@@ -126,12 +122,12 @@ function getFromNode(node, key) {
126
122
  if (Array.isArray(node)) {
127
123
  return util.pipe(parseAndValidateArrayIndex(key), result.flatMap(function (index) {
128
124
  if (index >= node.length) {
129
- return result.err(new ops.PatchError("Array index out of bounds"));
125
+ return result.err(new expr_dist_valbuildCoreExpr.PatchError("Array index out of bounds"));
130
126
  } else {
131
127
  return result.ok(node[index]);
132
128
  }
133
129
  }));
134
- } else if (index._typeof(node) === "object" && node !== null) {
130
+ } else if (expr_dist_valbuildCoreExpr._typeof(node) === "object" && node !== null) {
135
131
  // Prototype pollution protection
136
132
  if (Object.prototype.hasOwnProperty.call(node, key)) {
137
133
  return result.ok(node[key]);
@@ -139,7 +135,7 @@ function getFromNode(node, key) {
139
135
  return result.ok(undefined);
140
136
  }
141
137
  }
142
- return result.err(new ops.PatchError("Cannot access non-object/array"));
138
+ return result.err(new expr_dist_valbuildCoreExpr.PatchError("Cannot access non-object/array"));
143
139
  }
144
140
  function getPointerFromPath(node, path) {
145
141
  var targetNode = node;
@@ -150,7 +146,7 @@ function getPointerFromPath(node, path) {
150
146
  return childNode;
151
147
  }
152
148
  if (childNode.value === undefined) {
153
- return result.err(new ops.PatchError("Path refers to non-existing object/array"));
149
+ return result.err(new expr_dist_valbuildCoreExpr.PatchError("Path refers to non-existing object/array"));
154
150
  }
155
151
  targetNode = childNode.value;
156
152
  }
@@ -161,19 +157,19 @@ function getAtPath(node, path) {
161
157
  return util.pipe(getFromNode(node, key), result.filterOrElse(function (childNode) {
162
158
  return childNode !== undefined;
163
159
  }, function () {
164
- return new ops.PatchError("Path refers to non-existing object/array");
160
+ return new expr_dist_valbuildCoreExpr.PatchError("Path refers to non-existing object/array");
165
161
  }));
166
162
  }, node));
167
163
  }
168
164
  function removeFromNode(node, key) {
169
165
  if (Array.isArray(node)) {
170
- return util.pipe(parseAndValidateArrayInboundsIndex(key, node), result.map(function (index$1) {
171
- var _node$splice = node.splice(index$1, 1),
172
- _node$splice2 = index._slicedToArray(_node$splice, 1),
166
+ return util.pipe(parseAndValidateArrayInboundsIndex(key, node), result.map(function (index) {
167
+ var _node$splice = node.splice(index, 1),
168
+ _node$splice2 = expr_dist_valbuildCoreExpr._slicedToArray(_node$splice, 1),
173
169
  removed = _node$splice2[0];
174
170
  return removed;
175
171
  }));
176
- } else if (index._typeof(node) === "object" && node !== null) {
172
+ } else if (expr_dist_valbuildCoreExpr._typeof(node) === "object" && node !== null) {
177
173
  // Prototype pollution protection
178
174
  if (Object.prototype.hasOwnProperty.call(node, key)) {
179
175
  var removed = node[key];
@@ -181,11 +177,11 @@ function removeFromNode(node, key) {
181
177
  return result.ok(removed);
182
178
  }
183
179
  }
184
- return result.err(new ops.PatchError("Cannot remove from non-object/array"));
180
+ return result.err(new expr_dist_valbuildCoreExpr.PatchError("Cannot remove from non-object/array"));
185
181
  }
186
182
  function removeAtPath(document, path) {
187
183
  return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref3) {
188
- var _ref4 = index._slicedToArray(_ref3, 2),
184
+ var _ref4 = expr_dist_valbuildCoreExpr._slicedToArray(_ref3, 2),
189
185
  node = _ref4[0],
190
186
  key = _ref4[1];
191
187
  return removeFromNode(node, key);
@@ -197,7 +193,7 @@ function addToNode(node, key, value) {
197
193
  node.splice(index, 0, value);
198
194
  return undefined;
199
195
  }));
200
- } else if (index._typeof(node) === "object" && node !== null) {
196
+ } else if (expr_dist_valbuildCoreExpr._typeof(node) === "object" && node !== null) {
201
197
  var _replaced2;
202
198
  // Prototype pollution protection
203
199
  if (Object.prototype.hasOwnProperty.call(node, key)) {
@@ -206,12 +202,12 @@ function addToNode(node, key, value) {
206
202
  node[key] = value;
207
203
  return result.ok(_replaced2);
208
204
  }
209
- return result.err(new ops.PatchError("Cannot add to non-object/array"));
205
+ return result.err(new expr_dist_valbuildCoreExpr.PatchError("Cannot add to non-object/array"));
210
206
  }
211
207
  function addAtPath(document, path, value) {
212
208
  if (isNotRoot(path)) {
213
209
  return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref5) {
214
- var _ref6 = index._slicedToArray(_ref5, 2),
210
+ var _ref6 = expr_dist_valbuildCoreExpr._slicedToArray(_ref5, 2),
215
211
  node = _ref6[0],
216
212
  key = _ref6[1];
217
213
  return addToNode(node, key, value);
@@ -223,15 +219,15 @@ function addAtPath(document, path, value) {
223
219
  }
224
220
  }
225
221
  function pickDocument(_ref7) {
226
- var _ref8 = index._slicedToArray(_ref7, 1),
222
+ var _ref8 = expr_dist_valbuildCoreExpr._slicedToArray(_ref7, 1),
227
223
  document = _ref8[0];
228
224
  return document;
229
225
  }
230
226
  var JSONOps = /*#__PURE__*/function () {
231
227
  function JSONOps() {
232
- index._classCallCheck(this, JSONOps);
228
+ expr_dist_valbuildCoreExpr._classCallCheck(this, JSONOps);
233
229
  }
234
- index._createClass(JSONOps, [{
230
+ expr_dist_valbuildCoreExpr._createClass(JSONOps, [{
235
231
  key: "get",
236
232
  value: function get(document, path) {
237
233
  return getAtPath(document, path);
@@ -326,7 +322,7 @@ function prefixIssuePath(prefix, _ref) {
326
322
  var path = _ref.path,
327
323
  message = _ref.message;
328
324
  return {
329
- path: [prefix].concat(index._toConsumableArray(path)),
325
+ path: [prefix].concat(expr_dist_valbuildCoreExpr._toConsumableArray(path)),
330
326
  message: message
331
327
  };
332
328
  }
@@ -391,14 +387,14 @@ function parseOperation(operation) {
391
387
  return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.filterOrElse(result.isNonEmpty, function () {
392
388
  return "Cannot move root";
393
389
  }), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.filterOrElse(function (_ref2) {
394
- var _ref3 = index._slicedToArray(_ref2, 2),
390
+ var _ref3 = expr_dist_valbuildCoreExpr._slicedToArray(_ref2, 2),
395
391
  from = _ref3[0],
396
392
  path = _ref3[1];
397
393
  return !isProperPathPrefix(from, path);
398
394
  }, function () {
399
395
  return [createIssueAtPath(["from"])("Cannot be a proper prefix of path")];
400
396
  }), result.map(function (_ref4) {
401
- var _ref5 = index._slicedToArray(_ref4, 2),
397
+ var _ref5 = expr_dist_valbuildCoreExpr._slicedToArray(_ref4, 2),
402
398
  from = _ref5[0],
403
399
  path = _ref5[1];
404
400
  return {
@@ -409,7 +405,7 @@ function parseOperation(operation) {
409
405
  }));
410
406
  case "copy":
411
407
  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) {
412
- var _ref7 = index._slicedToArray(_ref6, 2),
408
+ var _ref7 = expr_dist_valbuildCoreExpr._slicedToArray(_ref6, 2),
413
409
  from = _ref7[0],
414
410
  path = _ref7[1];
415
411
  return {
@@ -426,28 +422,28 @@ function parsePatch(patch) {
426
422
  }))), result.all, result.mapErr(result.flatten));
427
423
  }
428
424
 
429
- function apply(document, ops$1, op) {
425
+ function apply(document, ops, op) {
430
426
  switch (op.op) {
431
427
  case "add":
432
- return ops$1.add(document, op.path, op.value);
428
+ return ops.add(document, op.path, op.value);
433
429
  case "remove":
434
- return ops$1.remove(document, op.path);
430
+ return ops.remove(document, op.path);
435
431
  case "replace":
436
- return ops$1.replace(document, op.path, op.value);
432
+ return ops.replace(document, op.path, op.value);
437
433
  case "move":
438
- return ops$1.move(document, op.from, op.path);
434
+ return ops.move(document, op.from, op.path);
439
435
  case "copy":
440
- return ops$1.copy(document, op.from, op.path);
436
+ return ops.copy(document, op.from, op.path);
441
437
  case "test":
442
438
  {
443
- if (!ops$1.test(document, op.path, op.value)) {
444
- return result.err(new ops.PatchError("Test failed"));
439
+ if (!ops.test(document, op.path, op.value)) {
440
+ return result.err(new expr_dist_valbuildCoreExpr.PatchError("Test failed"));
445
441
  }
446
442
  return result.ok(document);
447
443
  }
448
444
  case "file":
449
445
  {
450
- return result.err(new ops.PatchError("Cannot apply a file patch here"));
446
+ return result.err(new expr_dist_valbuildCoreExpr.PatchError("Cannot apply a file patch here"));
451
447
  }
452
448
  }
453
449
  }
@@ -457,7 +453,7 @@ function applyPatch(document, ops, patch) {
457
453
  }, document));
458
454
  }
459
455
 
460
- exports.PatchError = ops.PatchError;
456
+ exports.PatchError = expr_dist_valbuildCoreExpr.PatchError;
461
457
  exports.JSONOps = JSONOps;
462
458
  exports.applyPatch = applyPatch;
463
459
  exports.deepClone = deepClone;
@@ -1,8 +1,7 @@
1
- import { e as _typeof, k as _slicedToArray, c as _createClass, a as _classCallCheck, w as _toConsumableArray } from '../../dist/index-051c34f3.esm.js';
2
- import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-b96df128.esm.js';
1
+ import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-316f5dd8.esm.js';
2
+ export { P as PatchError } from '../../dist/index-316f5dd8.esm.js';
3
+ import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-a8316efa.esm.js';
3
4
  import { p as pipe } from '../../dist/util-18613e99.esm.js';
4
- import { P as PatchError, s as splitModuleIdAndModulePath } from '../../dist/ops-9262cf01.esm.js';
5
- export { P as PatchError } from '../../dist/ops-9262cf01.esm.js';
6
5
 
7
6
  function isNotRoot(path) {
8
7
  return isNonEmpty(path);
@@ -58,9 +57,9 @@ function parseAndValidateArrayIndex(value) {
58
57
  return ok(Number(value));
59
58
  }
60
59
  function sourceToPatchPath(sourcePath) {
61
- var _splitModuleIdAndModu = splitModuleIdAndModulePath(sourcePath),
62
- _splitModuleIdAndModu2 = _slicedToArray(_splitModuleIdAndModu, 2),
63
- modulePath = _splitModuleIdAndModu2[1];
60
+ var _splitModuleFilePathA = splitModuleFilePathAndModulePath(sourcePath),
61
+ _splitModuleFilePathA2 = _slicedToArray(_splitModuleFilePathA, 2),
62
+ modulePath = _splitModuleFilePathA2[1];
64
63
  return modulePath.split(".").map(function (p) {
65
64
  return JSON.parse(p).toString();
66
65
  });
@@ -97,9 +96,6 @@ function replaceInNode(node, key, value) {
97
96
  node[key] = value;
98
97
  return ok(_replaced);
99
98
  } else {
100
- console.log({
101
- node: node
102
- });
103
99
  return err(new PatchError("Cannot replace object element which does not exist"));
104
100
  }
105
101
  }