@valbuild/core 0.16.0 → 0.18.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 +36 -9
- package/dist/declarations/src/initSchema.d.ts +8 -10
- package/dist/declarations/src/initVal.d.ts +3 -21
- package/dist/declarations/src/module.d.ts +2 -14
- package/dist/declarations/src/schema/image.d.ts +1 -1
- package/dist/declarations/src/schema/index.d.ts +3 -5
- package/dist/declarations/src/schema/keyOf.d.ts +23 -0
- package/dist/declarations/src/schema/record.d.ts +19 -0
- package/dist/declarations/src/schema/union.d.ts +1 -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-2fff5ca8.cjs.dev.js → index-486c7fbf.cjs.dev.js} +242 -54
- package/dist/{index-af761363.esm.js → index-4abf3a1f.esm.js} +189 -1
- package/dist/{index-cac9ecbd.cjs.prod.js → index-601a7d73.cjs.prod.js} +242 -54
- package/dist/{SelectorProxy-2af1b2b8.cjs.prod.js → index-8706c87e.cjs.prod.js} +25 -199
- package/dist/{SelectorProxy-873782a5.cjs.dev.js → index-a6e642dd.cjs.dev.js} +25 -199
- package/dist/{SelectorProxy-63c2d0e2.esm.js → index-a9235737.esm.js} +23 -195
- package/dist/{ops-1b6e0e35.cjs.prod.js → ops-0d09f8ee.cjs.prod.js} +258 -126
- package/dist/{ops-74661336.esm.js → ops-a2a295f8.esm.js} +195 -65
- package/dist/{ops-ea4827fc.cjs.dev.js → ops-f3015423.cjs.dev.js} +258 -126
- package/dist/valbuild-core.cjs.dev.js +784 -197
- package/dist/valbuild-core.cjs.prod.js +784 -197
- package/dist/valbuild-core.esm.js +719 -133
- 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 -3
- package/patch/dist/valbuild-core-patch.cjs.dev.js +24 -24
- package/patch/dist/valbuild-core-patch.cjs.prod.js +24 -24
- package/patch/dist/valbuild-core-patch.esm.js +3 -3
- package/src/ValApi.ts +85 -0
- package/src/expr/eval.test.ts +2 -2
- package/src/expr/eval.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 +46 -14
- package/src/initSchema.ts +17 -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/json.test.ts +0 -1
- package/src/schema/{i18n.ts → future/i18n.ts} +12 -10
- package/src/schema/{oneOf.ts → future/oneOf.ts} +19 -17
- package/src/schema/image.ts +1 -1
- package/src/schema/index.ts +16 -13
- package/src/schema/keyOf.ts +167 -0
- package/src/schema/record.ts +103 -0
- package/src/schema/union.ts +1 -1
- package/src/schema/validation.test.ts +195 -130
- package/src/selector/SelectorProxy.ts +15 -15
- 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/declarations/src/fetchVal.d.ts +0 -5
- package/dist/declarations/src/schema/i18n.d.ts +0 -22
- package/dist/declarations/src/schema/oneOf.d.ts +0 -23
@@ -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
|
-
var
|
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
11
|
exports.evaluate = expr_dist_valbuildCoreExpr.evaluate;
|
12
12
|
exports.parse = expr_dist_valbuildCoreExpr.parse;
|
13
|
-
exports.Call =
|
14
|
-
exports.Expr =
|
15
|
-
exports.NilSym =
|
16
|
-
exports.StringLiteral =
|
17
|
-
exports.StringTemplate =
|
18
|
-
exports.Sym =
|
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
|
-
var
|
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
11
|
exports.evaluate = expr_dist_valbuildCoreExpr.evaluate;
|
12
12
|
exports.parse = expr_dist_valbuildCoreExpr.parse;
|
13
|
-
exports.Call =
|
14
|
-
exports.Expr =
|
15
|
-
exports.NilSym =
|
16
|
-
exports.StringLiteral =
|
17
|
-
exports.StringTemplate =
|
18
|
-
exports.Sym =
|
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 { e as evaluate, p as parse } from '../../dist/index-
|
2
|
-
export { C as Call, E as Expr, N as NilSym,
|
1
|
+
export { e as evaluate, p as parse } from '../../dist/index-4abf3a1f.esm.js';
|
2
|
+
export { C as Call, E as Expr, N as NilSym, s as StringLiteral, t as StringTemplate, r as Sym } from '../../dist/index-a9235737.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.18.0",
|
4
4
|
"private": false,
|
5
5
|
"description": "Val - supercharged hard-coded content",
|
6
6
|
"scripts": {
|
@@ -39,8 +39,7 @@
|
|
39
39
|
],
|
40
40
|
"exports": true
|
41
41
|
},
|
42
|
-
"
|
43
|
-
"image-size": "^1.0.2",
|
42
|
+
"devDependencies": {
|
44
43
|
"ts-toolbelt": "^9.6.0"
|
45
44
|
}
|
46
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)];
|
@@ -62,7 +62,7 @@ function parseAndValidateArrayIndex(value) {
|
|
62
62
|
}
|
63
63
|
function sourceToPatchPath(sourcePath) {
|
64
64
|
var _splitModuleIdAndModu = ops.splitModuleIdAndModulePath(sourcePath),
|
65
|
-
_splitModuleIdAndModu2 =
|
65
|
+
_splitModuleIdAndModu2 = index._slicedToArray(_splitModuleIdAndModu, 2),
|
66
66
|
modulePath = _splitModuleIdAndModu2[1];
|
67
67
|
return modulePath.split(".").map(function (p) {
|
68
68
|
return JSON.parse(p).toString();
|
@@ -93,7 +93,7 @@ function replaceInNode(node, key, value) {
|
|
93
93
|
node[index] = value;
|
94
94
|
return replaced;
|
95
95
|
}));
|
96
|
-
} else if (
|
96
|
+
} else if (index._typeof(node) === "object" && node !== null) {
|
97
97
|
// Prototype pollution protection
|
98
98
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
99
99
|
var _replaced = node[key];
|
@@ -108,7 +108,7 @@ function replaceInNode(node, key, value) {
|
|
108
108
|
function replaceAtPath(document, path, value) {
|
109
109
|
if (isNotRoot(path)) {
|
110
110
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref) {
|
111
|
-
var _ref2 =
|
111
|
+
var _ref2 = index._slicedToArray(_ref, 2),
|
112
112
|
node = _ref2[0],
|
113
113
|
key = _ref2[1];
|
114
114
|
return replaceInNode(node, key, value);
|
@@ -128,7 +128,7 @@ function getFromNode(node, key) {
|
|
128
128
|
return result.ok(node[index]);
|
129
129
|
}
|
130
130
|
}));
|
131
|
-
} else if (
|
131
|
+
} else if (index._typeof(node) === "object" && node !== null) {
|
132
132
|
// Prototype pollution protection
|
133
133
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
134
134
|
return result.ok(node[key]);
|
@@ -164,13 +164,13 @@ function getAtPath(node, path) {
|
|
164
164
|
}
|
165
165
|
function removeFromNode(node, key) {
|
166
166
|
if (Array.isArray(node)) {
|
167
|
-
return util.pipe(parseAndValidateArrayInboundsIndex(key, node), result.map(function (index) {
|
168
|
-
var _node$splice = node.splice(index, 1),
|
169
|
-
_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),
|
170
170
|
removed = _node$splice2[0];
|
171
171
|
return removed;
|
172
172
|
}));
|
173
|
-
} else if (
|
173
|
+
} else if (index._typeof(node) === "object" && node !== null) {
|
174
174
|
// Prototype pollution protection
|
175
175
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
176
176
|
var removed = node[key];
|
@@ -182,7 +182,7 @@ function removeFromNode(node, key) {
|
|
182
182
|
}
|
183
183
|
function removeAtPath(document, path) {
|
184
184
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref3) {
|
185
|
-
var _ref4 =
|
185
|
+
var _ref4 = index._slicedToArray(_ref3, 2),
|
186
186
|
node = _ref4[0],
|
187
187
|
key = _ref4[1];
|
188
188
|
return removeFromNode(node, key);
|
@@ -194,7 +194,7 @@ function addToNode(node, key, value) {
|
|
194
194
|
node.splice(index, 0, value);
|
195
195
|
return undefined;
|
196
196
|
}));
|
197
|
-
} else if (
|
197
|
+
} else if (index._typeof(node) === "object" && node !== null) {
|
198
198
|
var _replaced2;
|
199
199
|
// Prototype pollution protection
|
200
200
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
@@ -208,7 +208,7 @@ function addToNode(node, key, value) {
|
|
208
208
|
function addAtPath(document, path, value) {
|
209
209
|
if (isNotRoot(path)) {
|
210
210
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref5) {
|
211
|
-
var _ref6 =
|
211
|
+
var _ref6 = index._slicedToArray(_ref5, 2),
|
212
212
|
node = _ref6[0],
|
213
213
|
key = _ref6[1];
|
214
214
|
return addToNode(node, key, value);
|
@@ -220,15 +220,15 @@ function addAtPath(document, path, value) {
|
|
220
220
|
}
|
221
221
|
}
|
222
222
|
function pickDocument(_ref7) {
|
223
|
-
var _ref8 =
|
223
|
+
var _ref8 = index._slicedToArray(_ref7, 1),
|
224
224
|
document = _ref8[0];
|
225
225
|
return document;
|
226
226
|
}
|
227
227
|
var JSONOps = /*#__PURE__*/function () {
|
228
228
|
function JSONOps() {
|
229
|
-
|
229
|
+
index._classCallCheck(this, JSONOps);
|
230
230
|
}
|
231
|
-
|
231
|
+
index._createClass(JSONOps, [{
|
232
232
|
key: "get",
|
233
233
|
value: function get(document, path) {
|
234
234
|
return getAtPath(document, path);
|
@@ -323,7 +323,7 @@ function prefixIssuePath(prefix, _ref) {
|
|
323
323
|
var path = _ref.path,
|
324
324
|
message = _ref.message;
|
325
325
|
return {
|
326
|
-
path: [prefix].concat(
|
326
|
+
path: [prefix].concat(index._toConsumableArray(path)),
|
327
327
|
message: message
|
328
328
|
};
|
329
329
|
}
|
@@ -377,14 +377,14 @@ function parseOperation(operation) {
|
|
377
377
|
return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.filterOrElse(result.isNonEmpty, function () {
|
378
378
|
return "Cannot move root";
|
379
379
|
}), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.filterOrElse(function (_ref2) {
|
380
|
-
var _ref3 =
|
380
|
+
var _ref3 = index._slicedToArray(_ref2, 2),
|
381
381
|
from = _ref3[0],
|
382
382
|
path = _ref3[1];
|
383
383
|
return !isProperPathPrefix(from, path);
|
384
384
|
}, function () {
|
385
385
|
return [createIssueAtPath(["from"])("Cannot be a proper prefix of path")];
|
386
386
|
}), result.map(function (_ref4) {
|
387
|
-
var _ref5 =
|
387
|
+
var _ref5 = index._slicedToArray(_ref4, 2),
|
388
388
|
from = _ref5[0],
|
389
389
|
path = _ref5[1];
|
390
390
|
return {
|
@@ -395,7 +395,7 @@ function parseOperation(operation) {
|
|
395
395
|
}));
|
396
396
|
case "copy":
|
397
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) {
|
398
|
-
var _ref7 =
|
398
|
+
var _ref7 = index._slicedToArray(_ref6, 2),
|
399
399
|
from = _ref7[0],
|
400
400
|
path = _ref7[1];
|
401
401
|
return {
|
@@ -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)];
|
@@ -62,7 +62,7 @@ function parseAndValidateArrayIndex(value) {
|
|
62
62
|
}
|
63
63
|
function sourceToPatchPath(sourcePath) {
|
64
64
|
var _splitModuleIdAndModu = ops.splitModuleIdAndModulePath(sourcePath),
|
65
|
-
_splitModuleIdAndModu2 =
|
65
|
+
_splitModuleIdAndModu2 = index._slicedToArray(_splitModuleIdAndModu, 2),
|
66
66
|
modulePath = _splitModuleIdAndModu2[1];
|
67
67
|
return modulePath.split(".").map(function (p) {
|
68
68
|
return JSON.parse(p).toString();
|
@@ -93,7 +93,7 @@ function replaceInNode(node, key, value) {
|
|
93
93
|
node[index] = value;
|
94
94
|
return replaced;
|
95
95
|
}));
|
96
|
-
} else if (
|
96
|
+
} else if (index._typeof(node) === "object" && node !== null) {
|
97
97
|
// Prototype pollution protection
|
98
98
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
99
99
|
var _replaced = node[key];
|
@@ -108,7 +108,7 @@ function replaceInNode(node, key, value) {
|
|
108
108
|
function replaceAtPath(document, path, value) {
|
109
109
|
if (isNotRoot(path)) {
|
110
110
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref) {
|
111
|
-
var _ref2 =
|
111
|
+
var _ref2 = index._slicedToArray(_ref, 2),
|
112
112
|
node = _ref2[0],
|
113
113
|
key = _ref2[1];
|
114
114
|
return replaceInNode(node, key, value);
|
@@ -128,7 +128,7 @@ function getFromNode(node, key) {
|
|
128
128
|
return result.ok(node[index]);
|
129
129
|
}
|
130
130
|
}));
|
131
|
-
} else if (
|
131
|
+
} else if (index._typeof(node) === "object" && node !== null) {
|
132
132
|
// Prototype pollution protection
|
133
133
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
134
134
|
return result.ok(node[key]);
|
@@ -164,13 +164,13 @@ function getAtPath(node, path) {
|
|
164
164
|
}
|
165
165
|
function removeFromNode(node, key) {
|
166
166
|
if (Array.isArray(node)) {
|
167
|
-
return util.pipe(parseAndValidateArrayInboundsIndex(key, node), result.map(function (index) {
|
168
|
-
var _node$splice = node.splice(index, 1),
|
169
|
-
_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),
|
170
170
|
removed = _node$splice2[0];
|
171
171
|
return removed;
|
172
172
|
}));
|
173
|
-
} else if (
|
173
|
+
} else if (index._typeof(node) === "object" && node !== null) {
|
174
174
|
// Prototype pollution protection
|
175
175
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
176
176
|
var removed = node[key];
|
@@ -182,7 +182,7 @@ function removeFromNode(node, key) {
|
|
182
182
|
}
|
183
183
|
function removeAtPath(document, path) {
|
184
184
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref3) {
|
185
|
-
var _ref4 =
|
185
|
+
var _ref4 = index._slicedToArray(_ref3, 2),
|
186
186
|
node = _ref4[0],
|
187
187
|
key = _ref4[1];
|
188
188
|
return removeFromNode(node, key);
|
@@ -194,7 +194,7 @@ function addToNode(node, key, value) {
|
|
194
194
|
node.splice(index, 0, value);
|
195
195
|
return undefined;
|
196
196
|
}));
|
197
|
-
} else if (
|
197
|
+
} else if (index._typeof(node) === "object" && node !== null) {
|
198
198
|
var _replaced2;
|
199
199
|
// Prototype pollution protection
|
200
200
|
if (Object.prototype.hasOwnProperty.call(node, key)) {
|
@@ -208,7 +208,7 @@ function addToNode(node, key, value) {
|
|
208
208
|
function addAtPath(document, path, value) {
|
209
209
|
if (isNotRoot(path)) {
|
210
210
|
return util.pipe(getPointerFromPath(document, path), result.flatMap(function (_ref5) {
|
211
|
-
var _ref6 =
|
211
|
+
var _ref6 = index._slicedToArray(_ref5, 2),
|
212
212
|
node = _ref6[0],
|
213
213
|
key = _ref6[1];
|
214
214
|
return addToNode(node, key, value);
|
@@ -220,15 +220,15 @@ function addAtPath(document, path, value) {
|
|
220
220
|
}
|
221
221
|
}
|
222
222
|
function pickDocument(_ref7) {
|
223
|
-
var _ref8 =
|
223
|
+
var _ref8 = index._slicedToArray(_ref7, 1),
|
224
224
|
document = _ref8[0];
|
225
225
|
return document;
|
226
226
|
}
|
227
227
|
var JSONOps = /*#__PURE__*/function () {
|
228
228
|
function JSONOps() {
|
229
|
-
|
229
|
+
index._classCallCheck(this, JSONOps);
|
230
230
|
}
|
231
|
-
|
231
|
+
index._createClass(JSONOps, [{
|
232
232
|
key: "get",
|
233
233
|
value: function get(document, path) {
|
234
234
|
return getAtPath(document, path);
|
@@ -323,7 +323,7 @@ function prefixIssuePath(prefix, _ref) {
|
|
323
323
|
var path = _ref.path,
|
324
324
|
message = _ref.message;
|
325
325
|
return {
|
326
|
-
path: [prefix].concat(
|
326
|
+
path: [prefix].concat(index._toConsumableArray(path)),
|
327
327
|
message: message
|
328
328
|
};
|
329
329
|
}
|
@@ -377,14 +377,14 @@ function parseOperation(operation) {
|
|
377
377
|
return util.pipe(result.allT([util.pipe(parseJSONPointer(operation.from), result.filterOrElse(result.isNonEmpty, function () {
|
378
378
|
return "Cannot move root";
|
379
379
|
}), result.mapErr(createIssueAtPath(["from"]))), util.pipe(path, result.mapErr(createIssueAtPath(["path"])))]), result.filterOrElse(function (_ref2) {
|
380
|
-
var _ref3 =
|
380
|
+
var _ref3 = index._slicedToArray(_ref2, 2),
|
381
381
|
from = _ref3[0],
|
382
382
|
path = _ref3[1];
|
383
383
|
return !isProperPathPrefix(from, path);
|
384
384
|
}, function () {
|
385
385
|
return [createIssueAtPath(["from"])("Cannot be a proper prefix of path")];
|
386
386
|
}), result.map(function (_ref4) {
|
387
|
-
var _ref5 =
|
387
|
+
var _ref5 = index._slicedToArray(_ref4, 2),
|
388
388
|
from = _ref5[0],
|
389
389
|
path = _ref5[1];
|
390
390
|
return {
|
@@ -395,7 +395,7 @@ function parseOperation(operation) {
|
|
395
395
|
}));
|
396
396
|
case "copy":
|
397
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) {
|
398
|
-
var _ref7 =
|
398
|
+
var _ref7 = index._slicedToArray(_ref6, 2),
|
399
399
|
from = _ref7[0],
|
400
400
|
path = _ref7[1];
|
401
401
|
return {
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { e as _typeof, f as _slicedToArray, c as _createClass, b as _classCallCheck, u as _toConsumableArray } from '../../dist/index-a9235737.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, s as splitModuleIdAndModulePath } from '../../dist/ops-
|
5
|
-
export { P as PatchError } from '../../dist/ops-
|
4
|
+
import { P as PatchError, s as splitModuleIdAndModulePath } from '../../dist/ops-a2a295f8.esm.js';
|
5
|
+
export { P as PatchError } from '../../dist/ops-a2a295f8.esm.js';
|
6
6
|
|
7
7
|
function isNotRoot(path) {
|
8
8
|
return isNonEmpty(path);
|
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
|
|