@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.
- package/ROADMAP.md +106 -0
- package/dist/declarations/src/ValApi.d.ts +26 -0
- package/dist/declarations/src/expr/eval.d.ts +1 -1
- package/dist/declarations/src/future/fetchVal.d.ts +5 -0
- package/dist/declarations/src/index.d.ts +38 -9
- package/dist/declarations/src/initSchema.d.ts +2 -10
- package/dist/declarations/src/initVal.d.ts +3 -21
- package/dist/declarations/src/module.d.ts +2 -14
- package/dist/declarations/src/patch/index.d.ts +1 -1
- package/dist/declarations/src/patch/util.d.ts +2 -0
- package/dist/declarations/src/schema/array.d.ts +3 -2
- package/dist/declarations/src/schema/boolean.d.ts +3 -2
- package/dist/declarations/src/schema/image.d.ts +4 -3
- package/dist/declarations/src/schema/index.d.ts +8 -7
- package/dist/declarations/src/schema/keyOf.d.ts +23 -0
- package/dist/declarations/src/schema/literal.d.ts +3 -2
- package/dist/declarations/src/schema/number.d.ts +3 -2
- package/dist/declarations/src/schema/object.d.ts +3 -2
- package/dist/declarations/src/schema/record.d.ts +19 -0
- package/dist/declarations/src/schema/richtext.d.ts +3 -2
- package/dist/declarations/src/schema/string.d.ts +3 -2
- package/dist/declarations/src/schema/union.d.ts +4 -2
- package/dist/declarations/src/schema/validation/ValidationError.d.ts +14 -0
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +2 -0
- package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
- package/dist/declarations/src/selector/array.d.ts +2 -13
- package/dist/declarations/src/selector/file.d.ts +1 -4
- package/dist/declarations/src/selector/future/array.d.ts +17 -0
- package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
- package/dist/declarations/src/selector/future/file.d.ts +9 -0
- package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/selector/future/index.d.ts +81 -0
- package/dist/declarations/src/selector/future/number.d.ts +2 -0
- package/dist/declarations/src/selector/future/object.d.ts +10 -0
- package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
- package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
- package/dist/declarations/src/selector/future/string.d.ts +2 -0
- package/dist/declarations/src/selector/index.d.ts +5 -32
- package/dist/declarations/src/selector/object.d.ts +2 -9
- package/dist/declarations/src/selector/primitive.d.ts +3 -9
- package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
- package/dist/declarations/src/source/index.d.ts +4 -3
- package/dist/declarations/src/val/index.d.ts +2 -2
- package/dist/index-369caccf.esm.js +550 -0
- package/dist/{index-06df0a5b.esm.js → index-3e3e839e.esm.js} +190 -555
- package/dist/{index-9663f28a.cjs.dev.js → index-486c7fbf.cjs.dev.js} +224 -617
- package/dist/{index-b2270f8f.cjs.prod.js → index-601a7d73.cjs.prod.js} +224 -617
- package/dist/index-8706c87e.cjs.prod.js +582 -0
- package/dist/index-a6e642dd.cjs.dev.js +582 -0
- package/dist/ops-0d09f8ee.cjs.prod.js +684 -0
- package/dist/ops-23a5abb2.esm.js +671 -0
- package/dist/ops-f3015423.cjs.dev.js +684 -0
- package/dist/valbuild-core.cjs.dev.js +640 -633
- package/dist/valbuild-core.cjs.prod.js +640 -633
- package/dist/valbuild-core.esm.js +578 -572
- package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
- package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +2 -2
- package/patch/dist/valbuild-core-patch.cjs.dev.js +32 -23
- package/patch/dist/valbuild-core-patch.cjs.prod.js +32 -23
- package/patch/dist/valbuild-core-patch.esm.js +12 -4
- package/src/ValApi.ts +85 -0
- package/src/expr/eval.test.ts +2 -2
- package/src/expr/eval.ts +2 -2
- package/src/expr/repl.ts +2 -2
- package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
- package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
- package/src/index.ts +51 -14
- package/src/initSchema.ts +11 -12
- package/src/initVal.ts +42 -52
- package/src/module.test.ts +40 -40
- package/src/module.ts +53 -43
- package/src/patch/deref.test.ts +1 -1
- package/src/patch/deref.ts +1 -1
- package/src/patch/index.ts +1 -0
- package/src/patch/json.test.ts +0 -1
- package/src/patch/util.ts +7 -0
- package/src/schema/array.ts +45 -4
- package/src/schema/boolean.ts +14 -3
- package/src/schema/{i18n.ts → future/i18n.ts} +15 -11
- package/src/schema/{oneOf.ts → future/oneOf.ts} +21 -18
- package/src/schema/image.ts +66 -6
- package/src/schema/index.ts +37 -13
- package/src/schema/keyOf.ts +167 -0
- package/src/schema/literal.ts +24 -3
- package/src/schema/number.ts +14 -3
- package/src/schema/object.ts +50 -7
- package/src/schema/record.ts +103 -0
- package/src/schema/richtext.ts +63 -3
- package/src/schema/string.ts +14 -3
- package/src/schema/union.ts +4 -3
- package/src/schema/validation/ValidationError.ts +16 -0
- package/src/schema/validation/ValidationFix.ts +6 -0
- package/src/schema/validation.test.ts +291 -0
- package/src/selector/SelectorProxy.ts +16 -16
- package/src/selector/array.ts +2 -26
- package/src/selector/file.ts +1 -9
- package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
- package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
- package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
- package/src/selector/future/SelectorProxy.ts +238 -0
- package/src/selector/future/array.ts +37 -0
- package/src/selector/future/boolean.ts +4 -0
- package/src/selector/future/file.ts +14 -0
- package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
- package/src/selector/future/index.ts +165 -0
- package/src/selector/future/number.ts +4 -0
- package/src/selector/future/object.ts +22 -0
- package/src/selector/future/primitive.ts +17 -0
- package/src/selector/{remote.ts → future/remote.ts} +1 -1
- package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
- package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
- package/src/selector/future/string.ts +4 -0
- package/src/selector/index.ts +4 -46
- package/src/selector/object.ts +2 -19
- package/src/selector/primitive.ts +3 -16
- package/src/source/{i18n.ts → future/i18n.ts} +2 -2
- package/src/source/{remote.ts → future/remote.ts} +3 -3
- package/src/source/index.ts +3 -2
- package/src/val/array.ts +1 -1
- package/src/val/index.ts +2 -2
- package/src/val/object.ts +1 -1
- package/dist/createClass-012eebbf.esm.js +0 -109
- package/dist/createClass-a436dbfe.cjs.dev.js +0 -116
- package/dist/createClass-de7426aa.cjs.prod.js +0 -116
- package/dist/declarations/src/fetchVal.d.ts +0 -5
- package/dist/declarations/src/schema/i18n.d.ts +0 -21
- package/dist/declarations/src/schema/oneOf.d.ts +0 -22
- package/dist/ops-6fae92a1.esm.js +0 -12
- package/dist/ops-87cdbafc.cjs.dev.js +0 -14
- 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-
|
6
|
-
require('../../dist/
|
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-
|
6
|
-
require('../../dist/
|
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 {
|
2
|
-
|
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.
|
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
|
-
"
|
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
|
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-
|
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 (
|
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 =
|
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 (
|
46
|
+
} else if (index._typeof(value) === "object" && value !== null) {
|
47
47
|
return Object.fromEntries(Object.entries(value).map(function (_ref) {
|
48
|
-
var _ref2 =
|
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 (
|
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 =
|
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 (
|
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 =
|
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 (
|
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 =
|
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 (
|
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 =
|
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 =
|
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
|
-
|
229
|
+
index._classCallCheck(this, JSONOps);
|
222
230
|
}
|
223
|
-
|
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(
|
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 =
|
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 =
|
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 =
|
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
|
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-
|
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 (
|
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 =
|
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 (
|
46
|
+
} else if (index._typeof(value) === "object" && value !== null) {
|
47
47
|
return Object.fromEntries(Object.entries(value).map(function (_ref) {
|
48
|
-
var _ref2 =
|
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 (
|
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 =
|
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 (
|
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 =
|
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 (
|
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 =
|
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 (
|
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 =
|
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 =
|
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
|
-
|
229
|
+
index._classCallCheck(this, JSONOps);
|
222
230
|
}
|
223
|
-
|
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(
|
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 =
|
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 =
|
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 =
|
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 {
|
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-
|
5
|
-
export { P as PatchError } from '../../dist/ops-
|
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
|
+
}
|
package/src/expr/eval.test.ts
CHANGED
@@ -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
|
|