@valbuild/core 0.15.0 → 0.17.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 (133) hide show
  1. package/ROADMAP.md +106 -0
  2. package/dist/declarations/src/ValApi.d.ts +26 -0
  3. package/dist/declarations/src/expr/eval.d.ts +1 -1
  4. package/dist/declarations/src/future/fetchVal.d.ts +5 -0
  5. package/dist/declarations/src/index.d.ts +38 -9
  6. package/dist/declarations/src/initSchema.d.ts +2 -10
  7. package/dist/declarations/src/initVal.d.ts +3 -21
  8. package/dist/declarations/src/module.d.ts +2 -14
  9. package/dist/declarations/src/patch/index.d.ts +1 -1
  10. package/dist/declarations/src/patch/util.d.ts +2 -0
  11. package/dist/declarations/src/schema/array.d.ts +3 -2
  12. package/dist/declarations/src/schema/boolean.d.ts +3 -2
  13. package/dist/declarations/src/schema/image.d.ts +4 -3
  14. package/dist/declarations/src/schema/index.d.ts +8 -7
  15. package/dist/declarations/src/schema/keyOf.d.ts +23 -0
  16. package/dist/declarations/src/schema/literal.d.ts +3 -2
  17. package/dist/declarations/src/schema/number.d.ts +3 -2
  18. package/dist/declarations/src/schema/object.d.ts +3 -2
  19. package/dist/declarations/src/schema/record.d.ts +19 -0
  20. package/dist/declarations/src/schema/richtext.d.ts +3 -2
  21. package/dist/declarations/src/schema/string.d.ts +3 -2
  22. package/dist/declarations/src/schema/union.d.ts +4 -2
  23. package/dist/declarations/src/schema/validation/ValidationError.d.ts +14 -0
  24. package/dist/declarations/src/schema/validation/ValidationFix.d.ts +2 -0
  25. package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
  26. package/dist/declarations/src/selector/array.d.ts +2 -13
  27. package/dist/declarations/src/selector/file.d.ts +1 -4
  28. package/dist/declarations/src/selector/future/array.d.ts +17 -0
  29. package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
  30. package/dist/declarations/src/selector/future/file.d.ts +9 -0
  31. package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
  32. package/dist/declarations/src/selector/future/index.d.ts +81 -0
  33. package/dist/declarations/src/selector/future/number.d.ts +2 -0
  34. package/dist/declarations/src/selector/future/object.d.ts +10 -0
  35. package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
  36. package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
  37. package/dist/declarations/src/selector/future/string.d.ts +2 -0
  38. package/dist/declarations/src/selector/index.d.ts +5 -32
  39. package/dist/declarations/src/selector/object.d.ts +2 -9
  40. package/dist/declarations/src/selector/primitive.d.ts +3 -9
  41. package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
  42. package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
  43. package/dist/declarations/src/source/index.d.ts +4 -3
  44. package/dist/declarations/src/val/index.d.ts +2 -2
  45. package/dist/index-369caccf.esm.js +550 -0
  46. package/dist/{index-06df0a5b.esm.js → index-3e3e839e.esm.js} +190 -555
  47. package/dist/{index-9663f28a.cjs.dev.js → index-486c7fbf.cjs.dev.js} +224 -617
  48. package/dist/{index-b2270f8f.cjs.prod.js → index-601a7d73.cjs.prod.js} +224 -617
  49. package/dist/index-8706c87e.cjs.prod.js +582 -0
  50. package/dist/index-a6e642dd.cjs.dev.js +582 -0
  51. package/dist/ops-0d09f8ee.cjs.prod.js +684 -0
  52. package/dist/ops-23a5abb2.esm.js +671 -0
  53. package/dist/ops-f3015423.cjs.dev.js +684 -0
  54. package/dist/valbuild-core.cjs.dev.js +640 -633
  55. package/dist/valbuild-core.cjs.prod.js +640 -633
  56. package/dist/valbuild-core.esm.js +578 -572
  57. package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
  58. package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
  59. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  60. package/package.json +2 -2
  61. package/patch/dist/valbuild-core-patch.cjs.dev.js +32 -23
  62. package/patch/dist/valbuild-core-patch.cjs.prod.js +32 -23
  63. package/patch/dist/valbuild-core-patch.esm.js +12 -4
  64. package/src/ValApi.ts +85 -0
  65. package/src/expr/eval.test.ts +2 -2
  66. package/src/expr/eval.ts +2 -2
  67. package/src/expr/repl.ts +2 -2
  68. package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
  69. package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
  70. package/src/index.ts +51 -14
  71. package/src/initSchema.ts +11 -12
  72. package/src/initVal.ts +42 -52
  73. package/src/module.test.ts +40 -40
  74. package/src/module.ts +53 -43
  75. package/src/patch/deref.test.ts +1 -1
  76. package/src/patch/deref.ts +1 -1
  77. package/src/patch/index.ts +1 -0
  78. package/src/patch/json.test.ts +0 -1
  79. package/src/patch/util.ts +7 -0
  80. package/src/schema/array.ts +45 -4
  81. package/src/schema/boolean.ts +14 -3
  82. package/src/schema/{i18n.ts → future/i18n.ts} +15 -11
  83. package/src/schema/{oneOf.ts → future/oneOf.ts} +21 -18
  84. package/src/schema/image.ts +66 -6
  85. package/src/schema/index.ts +37 -13
  86. package/src/schema/keyOf.ts +167 -0
  87. package/src/schema/literal.ts +24 -3
  88. package/src/schema/number.ts +14 -3
  89. package/src/schema/object.ts +50 -7
  90. package/src/schema/record.ts +103 -0
  91. package/src/schema/richtext.ts +63 -3
  92. package/src/schema/string.ts +14 -3
  93. package/src/schema/union.ts +4 -3
  94. package/src/schema/validation/ValidationError.ts +16 -0
  95. package/src/schema/validation/ValidationFix.ts +6 -0
  96. package/src/schema/validation.test.ts +291 -0
  97. package/src/selector/SelectorProxy.ts +16 -16
  98. package/src/selector/array.ts +2 -26
  99. package/src/selector/file.ts +1 -9
  100. package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
  101. package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
  102. package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
  103. package/src/selector/future/SelectorProxy.ts +238 -0
  104. package/src/selector/future/array.ts +37 -0
  105. package/src/selector/future/boolean.ts +4 -0
  106. package/src/selector/future/file.ts +14 -0
  107. package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
  108. package/src/selector/future/index.ts +165 -0
  109. package/src/selector/future/number.ts +4 -0
  110. package/src/selector/future/object.ts +22 -0
  111. package/src/selector/future/primitive.ts +17 -0
  112. package/src/selector/{remote.ts → future/remote.ts} +1 -1
  113. package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
  114. package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
  115. package/src/selector/future/string.ts +4 -0
  116. package/src/selector/index.ts +4 -46
  117. package/src/selector/object.ts +2 -19
  118. package/src/selector/primitive.ts +3 -16
  119. package/src/source/{i18n.ts → future/i18n.ts} +2 -2
  120. package/src/source/{remote.ts → future/remote.ts} +3 -3
  121. package/src/source/index.ts +3 -2
  122. package/src/val/array.ts +1 -1
  123. package/src/val/index.ts +2 -2
  124. package/src/val/object.ts +1 -1
  125. package/dist/createClass-012eebbf.esm.js +0 -109
  126. package/dist/createClass-a436dbfe.cjs.dev.js +0 -116
  127. package/dist/createClass-de7426aa.cjs.prod.js +0 -116
  128. package/dist/declarations/src/fetchVal.d.ts +0 -5
  129. package/dist/declarations/src/schema/i18n.d.ts +0 -21
  130. package/dist/declarations/src/schema/oneOf.d.ts +0 -22
  131. package/dist/ops-6fae92a1.esm.js +0 -12
  132. package/dist/ops-87cdbafc.cjs.dev.js +0 -14
  133. package/dist/ops-ae4d1bc2.cjs.prod.js +0 -14
@@ -2,17 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-9663f28a.cjs.dev.js');
6
- require('../../dist/createClass-a436dbfe.cjs.dev.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-486c7fbf.cjs.dev.js');
6
+ var index = require('../../dist/index-a6e642dd.cjs.dev.js');
7
7
  require('../../dist/result-48320acd.cjs.dev.js');
8
8
 
9
9
 
10
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
11
  exports.evaluate = expr_dist_valbuildCoreExpr.evaluate;
18
12
  exports.parse = expr_dist_valbuildCoreExpr.parse;
13
+ exports.Call = index.Call;
14
+ exports.Expr = index.Expr;
15
+ exports.NilSym = index.NilSym;
16
+ exports.StringLiteral = index.StringLiteral;
17
+ exports.StringTemplate = index.StringTemplate;
18
+ exports.Sym = index.Sym;
@@ -2,17 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var expr_dist_valbuildCoreExpr = require('../../dist/index-b2270f8f.cjs.prod.js');
6
- require('../../dist/createClass-de7426aa.cjs.prod.js');
5
+ var expr_dist_valbuildCoreExpr = require('../../dist/index-601a7d73.cjs.prod.js');
6
+ var index = require('../../dist/index-8706c87e.cjs.prod.js');
7
7
  require('../../dist/result-26f67b40.cjs.prod.js');
8
8
 
9
9
 
10
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
11
  exports.evaluate = expr_dist_valbuildCoreExpr.evaluate;
18
12
  exports.parse = expr_dist_valbuildCoreExpr.parse;
13
+ exports.Call = index.Call;
14
+ exports.Expr = index.Expr;
15
+ exports.NilSym = index.NilSym;
16
+ exports.StringLiteral = index.StringLiteral;
17
+ exports.StringTemplate = index.StringTemplate;
18
+ exports.Sym = index.Sym;
@@ -1,3 +1,3 @@
1
- export { C as Call, E as Expr, N as NilSym, r as StringLiteral, s as StringTemplate, t as Sym, u as evaluate, q as parse } from '../../dist/index-06df0a5b.esm.js';
2
- import '../../dist/createClass-012eebbf.esm.js';
1
+ export { e as evaluate, p as parse } from '../../dist/index-3e3e839e.esm.js';
2
+ export { C as Call, E as Expr, N as NilSym, r as StringLiteral, s as StringTemplate, q as Sym } from '../../dist/index-369caccf.esm.js';
3
3
  import '../../dist/result-b96df128.esm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/core",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "private": false,
5
5
  "description": "Val - supercharged hard-coded content",
6
6
  "scripts": {
@@ -39,7 +39,7 @@
39
39
  ],
40
40
  "exports": true
41
41
  },
42
- "dependencies": {
42
+ "devDependencies": {
43
43
  "ts-toolbelt": "^9.6.0"
44
44
  }
45
45
  }
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createClass = require('../../dist/createClass-a436dbfe.cjs.dev.js');
5
+ var index = require('../../dist/index-a6e642dd.cjs.dev.js');
6
6
  var result = require('../../dist/result-48320acd.cjs.dev.js');
7
7
  var util = require('../../dist/util-b213092b.cjs.dev.js');
8
- var ops = require('../../dist/ops-87cdbafc.cjs.dev.js');
8
+ var ops = require('../../dist/ops-f3015423.cjs.dev.js');
9
9
 
10
10
  function isNotRoot(path) {
11
11
  return result.isNonEmpty(path);
@@ -14,7 +14,7 @@ function deepEqual(a, b) {
14
14
  if (a === b) {
15
15
  return true;
16
16
  }
17
- if (createClass._typeof(a) === "object" && createClass._typeof(b) === "object" && a !== null && b !== null) {
17
+ if (index._typeof(a) === "object" && index._typeof(b) === "object" && a !== null && b !== null) {
18
18
  if (Array.isArray(a) && Array.isArray(b)) {
19
19
  if (a.length !== b.length) return false;
20
20
  for (var i = 0; i < a.length; ++i) {
@@ -26,7 +26,7 @@ function deepEqual(a, b) {
26
26
  // If the objects have a different amount of keys, they cannot be equal
27
27
  if (aEntries.length !== Object.keys(b).length) return false;
28
28
  for (var _i = 0, _aEntries = aEntries; _i < _aEntries.length; _i++) {
29
- var _aEntries$_i = createClass._slicedToArray(_aEntries[_i], 2),
29
+ var _aEntries$_i = index._slicedToArray(_aEntries[_i], 2),
30
30
  key = _aEntries$_i[0],
31
31
  aValue = _aEntries$_i[1];
32
32
  // b must be a JSON object, so the only way for the bValue to be
@@ -43,9 +43,9 @@ function deepEqual(a, b) {
43
43
  function deepClone(value) {
44
44
  if (Array.isArray(value)) {
45
45
  return value.map(deepClone);
46
- } else if (createClass._typeof(value) === "object" && value !== null) {
46
+ } else if (index._typeof(value) === "object" && value !== null) {
47
47
  return Object.fromEntries(Object.entries(value).map(function (_ref) {
48
- var _ref2 = createClass._slicedToArray(_ref, 2),
48
+ var _ref2 = index._slicedToArray(_ref, 2),
49
49
  key = _ref2[0],
50
50
  value = _ref2[1];
51
51
  return [key, deepClone(value)];
@@ -60,6 +60,14 @@ function parseAndValidateArrayIndex(value) {
60
60
  }
61
61
  return result.ok(Number(value));
62
62
  }
63
+ function sourceToPatchPath(sourcePath) {
64
+ var _splitModuleIdAndModu = ops.splitModuleIdAndModulePath(sourcePath),
65
+ _splitModuleIdAndModu2 = index._slicedToArray(_splitModuleIdAndModu, 2),
66
+ modulePath = _splitModuleIdAndModu2[1];
67
+ return modulePath.split(".").map(function (p) {
68
+ return JSON.parse(p).toString();
69
+ });
70
+ }
63
71
 
64
72
  function parseAndValidateArrayInsertIndex(key, nodes) {
65
73
  if (key === "-") {
@@ -85,7 +93,7 @@ function replaceInNode(node, key, value) {
85
93
  node[index] = value;
86
94
  return replaced;
87
95
  }));
88
- } else if (createClass._typeof(node) === "object" && node !== null) {
96
+ } else if (index._typeof(node) === "object" && node !== null) {
89
97
  // Prototype pollution protection
90
98
  if (Object.prototype.hasOwnProperty.call(node, key)) {
91
99
  var _replaced = node[key];
@@ -100,7 +108,7 @@ function replaceInNode(node, key, value) {
100
108
  function replaceAtPath(document, path, value) {
101
109
  if (isNotRoot(path)) {
102
110
  return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref) {
103
- var _ref2 = createClass._slicedToArray(_ref, 2),
111
+ var _ref2 = index._slicedToArray(_ref, 2),
104
112
  node = _ref2[0],
105
113
  key = _ref2[1];
106
114
  return replaceInNode(node, key, value);
@@ -120,7 +128,7 @@ function getFromNode(node, key) {
120
128
  return result.ok(node[index]);
121
129
  }
122
130
  }));
123
- } else if (createClass._typeof(node) === "object" && node !== null) {
131
+ } else if (index._typeof(node) === "object" && node !== null) {
124
132
  // Prototype pollution protection
125
133
  if (Object.prototype.hasOwnProperty.call(node, key)) {
126
134
  return result.ok(node[key]);
@@ -156,13 +164,13 @@ function getAtPath(node, path) {
156
164
  }
157
165
  function removeFromNode(node, key) {
158
166
  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),
167
+ return util.pipe(parseAndValidateArrayInboundsIndex(key, node), result.map(function (index$1) {
168
+ var _node$splice = node.splice(index$1, 1),
169
+ _node$splice2 = index._slicedToArray(_node$splice, 1),
162
170
  removed = _node$splice2[0];
163
171
  return removed;
164
172
  }));
165
- } else if (createClass._typeof(node) === "object" && node !== null) {
173
+ } else if (index._typeof(node) === "object" && node !== null) {
166
174
  // Prototype pollution protection
167
175
  if (Object.prototype.hasOwnProperty.call(node, key)) {
168
176
  var removed = node[key];
@@ -174,7 +182,7 @@ function removeFromNode(node, key) {
174
182
  }
175
183
  function removeAtPath(document, path) {
176
184
  return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref3) {
177
- var _ref4 = createClass._slicedToArray(_ref3, 2),
185
+ var _ref4 = index._slicedToArray(_ref3, 2),
178
186
  node = _ref4[0],
179
187
  key = _ref4[1];
180
188
  return removeFromNode(node, key);
@@ -186,7 +194,7 @@ function addToNode(node, key, value) {
186
194
  node.splice(index, 0, value);
187
195
  return undefined;
188
196
  }));
189
- } else if (createClass._typeof(node) === "object" && node !== null) {
197
+ } else if (index._typeof(node) === "object" && node !== null) {
190
198
  var _replaced2;
191
199
  // Prototype pollution protection
192
200
  if (Object.prototype.hasOwnProperty.call(node, key)) {
@@ -200,7 +208,7 @@ function addToNode(node, key, value) {
200
208
  function addAtPath(document, path, value) {
201
209
  if (isNotRoot(path)) {
202
210
  return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref5) {
203
- var _ref6 = createClass._slicedToArray(_ref5, 2),
211
+ var _ref6 = index._slicedToArray(_ref5, 2),
204
212
  node = _ref6[0],
205
213
  key = _ref6[1];
206
214
  return addToNode(node, key, value);
@@ -212,15 +220,15 @@ function addAtPath(document, path, value) {
212
220
  }
213
221
  }
214
222
  function pickDocument(_ref7) {
215
- var _ref8 = createClass._slicedToArray(_ref7, 1),
223
+ var _ref8 = index._slicedToArray(_ref7, 1),
216
224
  document = _ref8[0];
217
225
  return document;
218
226
  }
219
227
  var JSONOps = /*#__PURE__*/function () {
220
228
  function JSONOps() {
221
- createClass._classCallCheck(this, JSONOps);
229
+ index._classCallCheck(this, JSONOps);
222
230
  }
223
- createClass._createClass(JSONOps, [{
231
+ index._createClass(JSONOps, [{
224
232
  key: "get",
225
233
  value: function get(document, path) {
226
234
  return getAtPath(document, path);
@@ -315,7 +323,7 @@ function prefixIssuePath(prefix, _ref) {
315
323
  var path = _ref.path,
316
324
  message = _ref.message;
317
325
  return {
318
- path: [prefix].concat(createClass._toConsumableArray(path)),
326
+ path: [prefix].concat(index._toConsumableArray(path)),
319
327
  message: message
320
328
  };
321
329
  }
@@ -369,14 +377,14 @@ function parseOperation(operation) {
369
377
  return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.filterOrElse(result.isNonEmpty, function () {
370
378
  return "Cannot move root";
371
379
  }), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.filterOrElse(function (_ref2) {
372
- var _ref3 = createClass._slicedToArray(_ref2, 2),
380
+ var _ref3 = index._slicedToArray(_ref2, 2),
373
381
  from = _ref3[0],
374
382
  path = _ref3[1];
375
383
  return !isProperPathPrefix(from, path);
376
384
  }, function () {
377
385
  return [createIssueAtPath(["from"])("Cannot be a proper prefix of path")];
378
386
  }), result.map(function (_ref4) {
379
- var _ref5 = createClass._slicedToArray(_ref4, 2),
387
+ var _ref5 = index._slicedToArray(_ref4, 2),
380
388
  from = _ref5[0],
381
389
  path = _ref5[1];
382
390
  return {
@@ -387,7 +395,7 @@ function parseOperation(operation) {
387
395
  }));
388
396
  case "copy":
389
397
  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),
398
+ var _ref7 = index._slicedToArray(_ref6, 2),
391
399
  from = _ref7[0],
392
400
  path = _ref7[1];
393
401
  return {
@@ -441,3 +449,4 @@ exports.isNotRoot = isNotRoot;
441
449
  exports.parseAndValidateArrayIndex = parseAndValidateArrayIndex;
442
450
  exports.parseJSONPointer = parseJSONPointer;
443
451
  exports.parsePatch = parsePatch;
452
+ exports.sourceToPatchPath = sourceToPatchPath;
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createClass = require('../../dist/createClass-de7426aa.cjs.prod.js');
5
+ var index = require('../../dist/index-8706c87e.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-ae4d1bc2.cjs.prod.js');
8
+ var ops = require('../../dist/ops-0d09f8ee.cjs.prod.js');
9
9
 
10
10
  function isNotRoot(path) {
11
11
  return result.isNonEmpty(path);
@@ -14,7 +14,7 @@ function deepEqual(a, b) {
14
14
  if (a === b) {
15
15
  return true;
16
16
  }
17
- if (createClass._typeof(a) === "object" && createClass._typeof(b) === "object" && a !== null && b !== null) {
17
+ if (index._typeof(a) === "object" && index._typeof(b) === "object" && a !== null && b !== null) {
18
18
  if (Array.isArray(a) && Array.isArray(b)) {
19
19
  if (a.length !== b.length) return false;
20
20
  for (var i = 0; i < a.length; ++i) {
@@ -26,7 +26,7 @@ function deepEqual(a, b) {
26
26
  // If the objects have a different amount of keys, they cannot be equal
27
27
  if (aEntries.length !== Object.keys(b).length) return false;
28
28
  for (var _i = 0, _aEntries = aEntries; _i < _aEntries.length; _i++) {
29
- var _aEntries$_i = createClass._slicedToArray(_aEntries[_i], 2),
29
+ var _aEntries$_i = index._slicedToArray(_aEntries[_i], 2),
30
30
  key = _aEntries$_i[0],
31
31
  aValue = _aEntries$_i[1];
32
32
  // b must be a JSON object, so the only way for the bValue to be
@@ -43,9 +43,9 @@ function deepEqual(a, b) {
43
43
  function deepClone(value) {
44
44
  if (Array.isArray(value)) {
45
45
  return value.map(deepClone);
46
- } else if (createClass._typeof(value) === "object" && value !== null) {
46
+ } else if (index._typeof(value) === "object" && value !== null) {
47
47
  return Object.fromEntries(Object.entries(value).map(function (_ref) {
48
- var _ref2 = createClass._slicedToArray(_ref, 2),
48
+ var _ref2 = index._slicedToArray(_ref, 2),
49
49
  key = _ref2[0],
50
50
  value = _ref2[1];
51
51
  return [key, deepClone(value)];
@@ -60,6 +60,14 @@ function parseAndValidateArrayIndex(value) {
60
60
  }
61
61
  return result.ok(Number(value));
62
62
  }
63
+ function sourceToPatchPath(sourcePath) {
64
+ var _splitModuleIdAndModu = ops.splitModuleIdAndModulePath(sourcePath),
65
+ _splitModuleIdAndModu2 = index._slicedToArray(_splitModuleIdAndModu, 2),
66
+ modulePath = _splitModuleIdAndModu2[1];
67
+ return modulePath.split(".").map(function (p) {
68
+ return JSON.parse(p).toString();
69
+ });
70
+ }
63
71
 
64
72
  function parseAndValidateArrayInsertIndex(key, nodes) {
65
73
  if (key === "-") {
@@ -85,7 +93,7 @@ function replaceInNode(node, key, value) {
85
93
  node[index] = value;
86
94
  return replaced;
87
95
  }));
88
- } else if (createClass._typeof(node) === "object" && node !== null) {
96
+ } else if (index._typeof(node) === "object" && node !== null) {
89
97
  // Prototype pollution protection
90
98
  if (Object.prototype.hasOwnProperty.call(node, key)) {
91
99
  var _replaced = node[key];
@@ -100,7 +108,7 @@ function replaceInNode(node, key, value) {
100
108
  function replaceAtPath(document, path, value) {
101
109
  if (isNotRoot(path)) {
102
110
  return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref) {
103
- var _ref2 = createClass._slicedToArray(_ref, 2),
111
+ var _ref2 = index._slicedToArray(_ref, 2),
104
112
  node = _ref2[0],
105
113
  key = _ref2[1];
106
114
  return replaceInNode(node, key, value);
@@ -120,7 +128,7 @@ function getFromNode(node, key) {
120
128
  return result.ok(node[index]);
121
129
  }
122
130
  }));
123
- } else if (createClass._typeof(node) === "object" && node !== null) {
131
+ } else if (index._typeof(node) === "object" && node !== null) {
124
132
  // Prototype pollution protection
125
133
  if (Object.prototype.hasOwnProperty.call(node, key)) {
126
134
  return result.ok(node[key]);
@@ -156,13 +164,13 @@ function getAtPath(node, path) {
156
164
  }
157
165
  function removeFromNode(node, key) {
158
166
  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),
167
+ return util.pipe(parseAndValidateArrayInboundsIndex(key, node), result.map(function (index$1) {
168
+ var _node$splice = node.splice(index$1, 1),
169
+ _node$splice2 = index._slicedToArray(_node$splice, 1),
162
170
  removed = _node$splice2[0];
163
171
  return removed;
164
172
  }));
165
- } else if (createClass._typeof(node) === "object" && node !== null) {
173
+ } else if (index._typeof(node) === "object" && node !== null) {
166
174
  // Prototype pollution protection
167
175
  if (Object.prototype.hasOwnProperty.call(node, key)) {
168
176
  var removed = node[key];
@@ -174,7 +182,7 @@ function removeFromNode(node, key) {
174
182
  }
175
183
  function removeAtPath(document, path) {
176
184
  return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref3) {
177
- var _ref4 = createClass._slicedToArray(_ref3, 2),
185
+ var _ref4 = index._slicedToArray(_ref3, 2),
178
186
  node = _ref4[0],
179
187
  key = _ref4[1];
180
188
  return removeFromNode(node, key);
@@ -186,7 +194,7 @@ function addToNode(node, key, value) {
186
194
  node.splice(index, 0, value);
187
195
  return undefined;
188
196
  }));
189
- } else if (createClass._typeof(node) === "object" && node !== null) {
197
+ } else if (index._typeof(node) === "object" && node !== null) {
190
198
  var _replaced2;
191
199
  // Prototype pollution protection
192
200
  if (Object.prototype.hasOwnProperty.call(node, key)) {
@@ -200,7 +208,7 @@ function addToNode(node, key, value) {
200
208
  function addAtPath(document, path, value) {
201
209
  if (isNotRoot(path)) {
202
210
  return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref5) {
203
- var _ref6 = createClass._slicedToArray(_ref5, 2),
211
+ var _ref6 = index._slicedToArray(_ref5, 2),
204
212
  node = _ref6[0],
205
213
  key = _ref6[1];
206
214
  return addToNode(node, key, value);
@@ -212,15 +220,15 @@ function addAtPath(document, path, value) {
212
220
  }
213
221
  }
214
222
  function pickDocument(_ref7) {
215
- var _ref8 = createClass._slicedToArray(_ref7, 1),
223
+ var _ref8 = index._slicedToArray(_ref7, 1),
216
224
  document = _ref8[0];
217
225
  return document;
218
226
  }
219
227
  var JSONOps = /*#__PURE__*/function () {
220
228
  function JSONOps() {
221
- createClass._classCallCheck(this, JSONOps);
229
+ index._classCallCheck(this, JSONOps);
222
230
  }
223
- createClass._createClass(JSONOps, [{
231
+ index._createClass(JSONOps, [{
224
232
  key: "get",
225
233
  value: function get(document, path) {
226
234
  return getAtPath(document, path);
@@ -315,7 +323,7 @@ function prefixIssuePath(prefix, _ref) {
315
323
  var path = _ref.path,
316
324
  message = _ref.message;
317
325
  return {
318
- path: [prefix].concat(createClass._toConsumableArray(path)),
326
+ path: [prefix].concat(index._toConsumableArray(path)),
319
327
  message: message
320
328
  };
321
329
  }
@@ -369,14 +377,14 @@ function parseOperation(operation) {
369
377
  return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.filterOrElse(result.isNonEmpty, function () {
370
378
  return "Cannot move root";
371
379
  }), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.filterOrElse(function (_ref2) {
372
- var _ref3 = createClass._slicedToArray(_ref2, 2),
380
+ var _ref3 = index._slicedToArray(_ref2, 2),
373
381
  from = _ref3[0],
374
382
  path = _ref3[1];
375
383
  return !isProperPathPrefix(from, path);
376
384
  }, function () {
377
385
  return [createIssueAtPath(["from"])("Cannot be a proper prefix of path")];
378
386
  }), result.map(function (_ref4) {
379
- var _ref5 = createClass._slicedToArray(_ref4, 2),
387
+ var _ref5 = index._slicedToArray(_ref4, 2),
380
388
  from = _ref5[0],
381
389
  path = _ref5[1];
382
390
  return {
@@ -387,7 +395,7 @@ function parseOperation(operation) {
387
395
  }));
388
396
  case "copy":
389
397
  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),
398
+ var _ref7 = index._slicedToArray(_ref6, 2),
391
399
  from = _ref7[0],
392
400
  path = _ref7[1];
393
401
  return {
@@ -441,3 +449,4 @@ exports.isNotRoot = isNotRoot;
441
449
  exports.parseAndValidateArrayIndex = parseAndValidateArrayIndex;
442
450
  exports.parseJSONPointer = parseJSONPointer;
443
451
  exports.parsePatch = parsePatch;
452
+ exports.sourceToPatchPath = sourceToPatchPath;
@@ -1,8 +1,8 @@
1
- import { b as _typeof, c as _slicedToArray, a as _createClass, _ as _classCallCheck, d as _toConsumableArray } from '../../dist/createClass-012eebbf.esm.js';
1
+ import { e as _typeof, j as _slicedToArray, c as _createClass, b as _classCallCheck, t as _toConsumableArray } from '../../dist/index-369caccf.esm.js';
2
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';
3
3
  import { p as pipe } from '../../dist/util-18613e99.esm.js';
4
- import { P as PatchError } from '../../dist/ops-6fae92a1.esm.js';
5
- export { P as PatchError } from '../../dist/ops-6fae92a1.esm.js';
4
+ import { P as PatchError, s as splitModuleIdAndModulePath } from '../../dist/ops-23a5abb2.esm.js';
5
+ export { P as PatchError } from '../../dist/ops-23a5abb2.esm.js';
6
6
 
7
7
  function isNotRoot(path) {
8
8
  return isNonEmpty(path);
@@ -57,6 +57,14 @@ function parseAndValidateArrayIndex(value) {
57
57
  }
58
58
  return ok(Number(value));
59
59
  }
60
+ function sourceToPatchPath(sourcePath) {
61
+ var _splitModuleIdAndModu = splitModuleIdAndModulePath(sourcePath),
62
+ _splitModuleIdAndModu2 = _slicedToArray(_splitModuleIdAndModu, 2),
63
+ modulePath = _splitModuleIdAndModu2[1];
64
+ return modulePath.split(".").map(function (p) {
65
+ return JSON.parse(p).toString();
66
+ });
67
+ }
60
68
 
61
69
  function parseAndValidateArrayInsertIndex(key, nodes) {
62
70
  if (key === "-") {
@@ -428,4 +436,4 @@ function applyPatch(document, ops, patch) {
428
436
  }, document));
429
437
  }
430
438
 
431
- export { JSONOps, applyPatch, deepClone, deepEqual, formatJSONPointer, isNotRoot, parseAndValidateArrayIndex, parseJSONPointer, parsePatch };
439
+ export { JSONOps, applyPatch, deepClone, deepEqual, formatJSONPointer, isNotRoot, parseAndValidateArrayIndex, parseJSONPointer, parsePatch, sourceToPatchPath };
package/src/ValApi.ts ADDED
@@ -0,0 +1,85 @@
1
+ import { ApiPatchResponse, ApiTreeResponse } from ".";
2
+ import { result } from "./fp";
3
+ import { PatchJSON } from "./patch";
4
+ import { ModuleId } from "./val";
5
+
6
+ type FetchError = { message: string; statusCode?: number };
7
+
8
+ // TODO: move this to internal, only reason this is here is that react, ui and server all depend on it
9
+ export class ValApi {
10
+ constructor(public host: string) {}
11
+
12
+ getDisableUrl() {
13
+ return `${this.host}/disable`;
14
+ }
15
+
16
+ postPatches(
17
+ moduleId: ModuleId,
18
+ patches: PatchJSON,
19
+ commit?: string,
20
+ headers?: Record<string, string> | undefined
21
+ ) {
22
+ let params = "";
23
+ if (commit) {
24
+ const p = new URLSearchParams();
25
+ p.set("commit", commit);
26
+ params = `?${p.toString()}`;
27
+ }
28
+ return fetch(`${this.host}/patches/~${moduleId}${params}`, {
29
+ headers: headers || {
30
+ "Content-Type": "application/json",
31
+ },
32
+ method: "POST",
33
+ body: JSON.stringify(patches),
34
+ }).then(parse<ApiPatchResponse>);
35
+ }
36
+
37
+ getSession() {
38
+ return fetch(`${this.host}/session`).then(
39
+ parse<{
40
+ mode: "proxy" | "local";
41
+ member_role: "owner" | "developer" | "editor";
42
+ }>
43
+ );
44
+ }
45
+
46
+ getModules({
47
+ patch = false,
48
+ includeSchema = false,
49
+ includeSource = false,
50
+ treePath = "/",
51
+ headers,
52
+ }: {
53
+ patch?: boolean;
54
+ includeSchema?: boolean;
55
+ includeSource?: boolean;
56
+ treePath?: string;
57
+ headers?: Record<string, string> | undefined;
58
+ }) {
59
+ const params = new URLSearchParams();
60
+ params.set("patch", patch.toString());
61
+ params.set("schema", includeSchema.toString());
62
+ params.set("source", includeSource.toString());
63
+ return fetch(`${this.host}/tree/~${treePath}?${params.toString()}`, {
64
+ headers,
65
+ }).then(parse<ApiTreeResponse>);
66
+ }
67
+ }
68
+
69
+ // TODO: validate
70
+ async function parse<T>(res: Response): Promise<result.Result<T, FetchError>> {
71
+ try {
72
+ if (res.ok) {
73
+ return result.ok(await res.json());
74
+ } else {
75
+ return result.err({
76
+ statusCode: res.status,
77
+ message: await res.text(),
78
+ });
79
+ }
80
+ } catch (err) {
81
+ return result.err({
82
+ message: err instanceof Error ? err.message : "Unknown error",
83
+ });
84
+ }
85
+ }
@@ -1,6 +1,6 @@
1
1
  import { pipe, result } from "../fp";
2
- import { Path } from "../selector";
3
- import { selectorToVal } from "../selector/SelectorProxy";
2
+ import { Path } from "../selector/future";
3
+ import { selectorToVal } from "../selector/future/SelectorProxy";
4
4
  import { Source } from "../source";
5
5
  import { evaluate } from "./eval";
6
6
  import { parse } from "./parser";
package/src/expr/eval.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  import { Call, Expr, StringLiteral, StringTemplate, Sym } from "./expr";
3
3
  import { Source } from "../source";
4
4
  import { result } from "../fp";
5
- import { Path, SourceOrExpr } from "../selector";
6
- import { newSelectorProxy } from "../selector/SelectorProxy";
5
+ import { Path, SourceOrExpr } from "../selector/future";
6
+ import { newSelectorProxy } from "../selector/future/SelectorProxy";
7
7
  import { isSerializedVal, SourcePath } from "../val";
8
8
  import { Json } from "../Json";
9
9
 
package/src/expr/repl.ts CHANGED
@@ -18,8 +18,8 @@ repl
18
18
  prompt: "β > ",
19
19
  eval: (
20
20
  cmd,
21
- context,
22
- filename,
21
+ _context,
22
+ _filename,
23
23
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
24
  callback: (arg0: any, arg1: any) => void
25
25
  ) => {