@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
@@ -1,561 +1,8 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
3
|
+
var index$1 = require('./index-8706c87e.cjs.prod.js');
|
4
4
|
var result = require('./result-26f67b40.cjs.prod.js');
|
5
5
|
|
6
|
-
function _defineProperty(obj, key, value) {
|
7
|
-
key = createClass._toPropertyKey(key);
|
8
|
-
if (key in obj) {
|
9
|
-
Object.defineProperty(obj, key, {
|
10
|
-
value: value,
|
11
|
-
enumerable: true,
|
12
|
-
configurable: true,
|
13
|
-
writable: true
|
14
|
-
});
|
15
|
-
} else {
|
16
|
-
obj[key] = value;
|
17
|
-
}
|
18
|
-
return obj;
|
19
|
-
}
|
20
|
-
|
21
|
-
function ownKeys(object, enumerableOnly) {
|
22
|
-
var keys = Object.keys(object);
|
23
|
-
if (Object.getOwnPropertySymbols) {
|
24
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
25
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
26
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
27
|
-
})), keys.push.apply(keys, symbols);
|
28
|
-
}
|
29
|
-
return keys;
|
30
|
-
}
|
31
|
-
function _objectSpread2(target) {
|
32
|
-
for (var i = 1; i < arguments.length; i++) {
|
33
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
34
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
35
|
-
_defineProperty(target, key, source[key]);
|
36
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
37
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
38
|
-
});
|
39
|
-
}
|
40
|
-
return target;
|
41
|
-
}
|
42
|
-
|
43
|
-
function _setPrototypeOf(o, p) {
|
44
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
45
|
-
o.__proto__ = p;
|
46
|
-
return o;
|
47
|
-
};
|
48
|
-
return _setPrototypeOf(o, p);
|
49
|
-
}
|
50
|
-
|
51
|
-
function _inherits(subClass, superClass) {
|
52
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
53
|
-
throw new TypeError("Super expression must either be null or a function");
|
54
|
-
}
|
55
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
56
|
-
constructor: {
|
57
|
-
value: subClass,
|
58
|
-
writable: true,
|
59
|
-
configurable: true
|
60
|
-
}
|
61
|
-
});
|
62
|
-
Object.defineProperty(subClass, "prototype", {
|
63
|
-
writable: false
|
64
|
-
});
|
65
|
-
if (superClass) _setPrototypeOf(subClass, superClass);
|
66
|
-
}
|
67
|
-
|
68
|
-
function _getPrototypeOf(o) {
|
69
|
-
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
70
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
71
|
-
};
|
72
|
-
return _getPrototypeOf(o);
|
73
|
-
}
|
74
|
-
|
75
|
-
function _isNativeReflectConstruct() {
|
76
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
77
|
-
if (Reflect.construct.sham) return false;
|
78
|
-
if (typeof Proxy === "function") return true;
|
79
|
-
try {
|
80
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
81
|
-
return true;
|
82
|
-
} catch (e) {
|
83
|
-
return false;
|
84
|
-
}
|
85
|
-
}
|
86
|
-
|
87
|
-
function _assertThisInitialized(self) {
|
88
|
-
if (self === void 0) {
|
89
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
90
|
-
}
|
91
|
-
return self;
|
92
|
-
}
|
93
|
-
|
94
|
-
function _possibleConstructorReturn(self, call) {
|
95
|
-
if (call && (typeof call === "object" || typeof call === "function")) {
|
96
|
-
return call;
|
97
|
-
} else if (call !== void 0) {
|
98
|
-
throw new TypeError("Derived constructors may only return object or undefined");
|
99
|
-
}
|
100
|
-
return _assertThisInitialized(self);
|
101
|
-
}
|
102
|
-
|
103
|
-
function _createSuper(Derived) {
|
104
|
-
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
105
|
-
return function _createSuperInternal() {
|
106
|
-
var Super = _getPrototypeOf(Derived),
|
107
|
-
result;
|
108
|
-
if (hasNativeReflectConstruct) {
|
109
|
-
var NewTarget = _getPrototypeOf(this).constructor;
|
110
|
-
result = Reflect.construct(Super, arguments, NewTarget);
|
111
|
-
} else {
|
112
|
-
result = Super.apply(this, arguments);
|
113
|
-
}
|
114
|
-
return _possibleConstructorReturn(this, result);
|
115
|
-
};
|
116
|
-
}
|
117
|
-
|
118
|
-
var Schema = /*#__PURE__*/function () {
|
119
|
-
function Schema() {
|
120
|
-
createClass._classCallCheck(this, Schema);
|
121
|
-
}
|
122
|
-
createClass._createClass(Schema, [{
|
123
|
-
key: "remote",
|
124
|
-
value: function remote() {
|
125
|
-
// TODO: Schema<never, "Cannot create remote schema from non-remote source.">
|
126
|
-
throw new Error("You need Val Ultra to use .remote()");
|
127
|
-
}
|
128
|
-
}]);
|
129
|
-
return Schema;
|
130
|
-
}();
|
131
|
-
|
132
|
-
// TODO: SourceError<"Could not determine type of Schema">
|
133
|
-
|
134
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
135
|
-
|
136
|
-
/**
|
137
|
-
* Selectors can be used to select parts of a Val module.
|
138
|
-
* Unlike queries, joins, aggregates etc is and will not be supported.
|
139
|
-
*
|
140
|
-
* They are designed to be be used as if they were "normal" JSON data,
|
141
|
-
* though some concessions had to be made because of TypeScript limitations.
|
142
|
-
*
|
143
|
-
* Selectors works equally on source content, defined in code, and remote content.
|
144
|
-
*
|
145
|
-
* @example
|
146
|
-
* // Select the title of a document
|
147
|
-
* const titles = useVal(docsVal.map((doc) => doc.title));
|
148
|
-
*
|
149
|
-
* @example
|
150
|
-
* // Match on a union type
|
151
|
-
* const titles = useVal(docsVal.map((doc) => doc.fold("type")({
|
152
|
-
* newsletter: (newsletter) => newsletter.title,
|
153
|
-
* email: (email) => email.subject,
|
154
|
-
* }));
|
155
|
-
*
|
156
|
-
*/
|
157
|
-
|
158
|
-
/**
|
159
|
-
* @internal
|
160
|
-
*/
|
161
|
-
var GetSchema = Symbol("GetSchema");
|
162
|
-
/**
|
163
|
-
/**
|
164
|
-
* @internal
|
165
|
-
*/
|
166
|
-
var Path = Symbol("Path");
|
167
|
-
/**
|
168
|
-
* @internal
|
169
|
-
*/
|
170
|
-
var SourceOrExpr = Symbol("SourceOrExpr");
|
171
|
-
/**
|
172
|
-
* @internal
|
173
|
-
*/
|
174
|
-
var ValError = Symbol("ValError");
|
175
|
-
var GenericSelector = /*#__PURE__*/function () {
|
176
|
-
function GenericSelector(valOrExpr, path, schema, error) {
|
177
|
-
createClass._classCallCheck(this, GenericSelector);
|
178
|
-
this[Path] = path;
|
179
|
-
this[SourceOrExpr] = valOrExpr;
|
180
|
-
this[ValError] = error;
|
181
|
-
this[GetSchema] = schema;
|
182
|
-
}
|
183
|
-
createClass._createClass(GenericSelector, [{
|
184
|
-
key: "assert",
|
185
|
-
value: function assert(schema, other) {
|
186
|
-
throw new Error("Not implemented");
|
187
|
-
}
|
188
|
-
}]);
|
189
|
-
return GenericSelector;
|
190
|
-
}();
|
191
|
-
|
192
|
-
/**
|
193
|
-
* Use this type to convert types that accepts both Source and Selectors
|
194
|
-
*
|
195
|
-
* An example would be where literals are supported like in most higher order functions (e.g. map in array)
|
196
|
-
**/
|
197
|
-
|
198
|
-
function getSchema(selector) {
|
199
|
-
return selector[GetSchema];
|
200
|
-
}
|
201
|
-
|
202
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
203
|
-
|
204
|
-
var Expr = /*#__PURE__*/createClass._createClass(function Expr(span) {
|
205
|
-
createClass._classCallCheck(this, Expr);
|
206
|
-
this.span = span;
|
207
|
-
});
|
208
|
-
var StringLiteral = /*#__PURE__*/function (_Expr) {
|
209
|
-
_inherits(StringLiteral, _Expr);
|
210
|
-
var _super = _createSuper(StringLiteral);
|
211
|
-
function StringLiteral(value, span) {
|
212
|
-
var _this;
|
213
|
-
createClass._classCallCheck(this, StringLiteral);
|
214
|
-
_this = _super.call(this, span);
|
215
|
-
_defineProperty(_assertThisInitialized(_this), "type", "StringLiteral");
|
216
|
-
_this.value = value;
|
217
|
-
return _this;
|
218
|
-
}
|
219
|
-
createClass._createClass(StringLiteral, [{
|
220
|
-
key: "transpile",
|
221
|
-
value: function transpile() {
|
222
|
-
return "'".concat(this.value, "'");
|
223
|
-
}
|
224
|
-
}]);
|
225
|
-
return StringLiteral;
|
226
|
-
}(Expr);
|
227
|
-
var Sym = /*#__PURE__*/function (_Expr2) {
|
228
|
-
_inherits(Sym, _Expr2);
|
229
|
-
var _super2 = _createSuper(Sym);
|
230
|
-
function Sym(value, span) {
|
231
|
-
var _this2;
|
232
|
-
createClass._classCallCheck(this, Sym);
|
233
|
-
_this2 = _super2.call(this, span);
|
234
|
-
_defineProperty(_assertThisInitialized(_this2), "type", "Sym");
|
235
|
-
_this2.value = value;
|
236
|
-
return _this2;
|
237
|
-
}
|
238
|
-
createClass._createClass(Sym, [{
|
239
|
-
key: "transpile",
|
240
|
-
value: function transpile() {
|
241
|
-
return this.value;
|
242
|
-
}
|
243
|
-
}]);
|
244
|
-
return Sym;
|
245
|
-
}(Expr);
|
246
|
-
var NilSym = new Sym("()");
|
247
|
-
var StringTemplate = /*#__PURE__*/function (_Expr3) {
|
248
|
-
_inherits(StringTemplate, _Expr3);
|
249
|
-
var _super3 = _createSuper(StringTemplate);
|
250
|
-
function StringTemplate(children, span) {
|
251
|
-
var _this3;
|
252
|
-
createClass._classCallCheck(this, StringTemplate);
|
253
|
-
_this3 = _super3.call(this, span);
|
254
|
-
_defineProperty(_assertThisInitialized(_this3), "type", "StringTemplate");
|
255
|
-
_this3.children = children;
|
256
|
-
return _this3;
|
257
|
-
}
|
258
|
-
createClass._createClass(StringTemplate, [{
|
259
|
-
key: "transpile",
|
260
|
-
value: function transpile() {
|
261
|
-
return "'".concat(this.children.map(function (child) {
|
262
|
-
if (child instanceof StringLiteral) {
|
263
|
-
return child.value;
|
264
|
-
} else {
|
265
|
-
return "${".concat(child.transpile(), "}");
|
266
|
-
}
|
267
|
-
}).join(""), "'");
|
268
|
-
}
|
269
|
-
}]);
|
270
|
-
return StringTemplate;
|
271
|
-
}(Expr);
|
272
|
-
var Call = /*#__PURE__*/function (_Expr4) {
|
273
|
-
_inherits(Call, _Expr4);
|
274
|
-
var _super4 = _createSuper(Call);
|
275
|
-
function Call(children, isAnon, span) {
|
276
|
-
var _this4;
|
277
|
-
createClass._classCallCheck(this, Call);
|
278
|
-
_this4 = _super4.call(this, span);
|
279
|
-
_defineProperty(_assertThisInitialized(_this4), "type", "Call");
|
280
|
-
_this4.children = children;
|
281
|
-
_this4.isAnon = isAnon;
|
282
|
-
return _this4;
|
283
|
-
}
|
284
|
-
createClass._createClass(Call, [{
|
285
|
-
key: "transpile",
|
286
|
-
value: function transpile() {
|
287
|
-
if (this.isAnon) {
|
288
|
-
return "!(".concat(this.children.map(function (child) {
|
289
|
-
return child.transpile();
|
290
|
-
}).join(" "), ")");
|
291
|
-
}
|
292
|
-
return "(".concat(this.children.map(function (child) {
|
293
|
-
return child.transpile();
|
294
|
-
}).join(" "), ")");
|
295
|
-
}
|
296
|
-
}]);
|
297
|
-
return Call;
|
298
|
-
}(Expr);
|
299
|
-
|
300
|
-
/* Branded extension types: file, remote, i18n */
|
301
|
-
var VAL_EXTENSION = "_type";
|
302
|
-
|
303
|
-
/**
|
304
|
-
* A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
|
305
|
-
*
|
306
|
-
* An example where this is useful is remote types, where the type of the remote source is known at compile time,
|
307
|
-
* but the value is not there before it is fetched.
|
308
|
-
*
|
309
|
-
* @example
|
310
|
-
* type Example<T> = string & PhantomType<T>;
|
311
|
-
*
|
312
|
-
**/
|
313
|
-
|
314
|
-
var FILE_REF_PROP = "_ref";
|
315
|
-
|
316
|
-
/**
|
317
|
-
* A file source represents the path to a (local) file.
|
318
|
-
*
|
319
|
-
* It will be resolved into a Asset object.
|
320
|
-
*
|
321
|
-
*/
|
322
|
-
|
323
|
-
function file(ref, metadata) {
|
324
|
-
var _ref;
|
325
|
-
return _ref = {}, _defineProperty(_ref, FILE_REF_PROP, ref), _defineProperty(_ref, VAL_EXTENSION, "file"), _defineProperty(_ref, "metadata", metadata), _ref;
|
326
|
-
}
|
327
|
-
function isFile(obj) {
|
328
|
-
return createClass._typeof(obj) === "object" && obj !== null && VAL_EXTENSION in obj && obj[VAL_EXTENSION] === "file" && FILE_REF_PROP in obj && typeof obj[FILE_REF_PROP] === "string";
|
329
|
-
}
|
330
|
-
|
331
|
-
var ImageSchema = /*#__PURE__*/function (_Schema) {
|
332
|
-
_inherits(ImageSchema, _Schema);
|
333
|
-
var _super = _createSuper(ImageSchema);
|
334
|
-
function ImageSchema(options) {
|
335
|
-
var _this;
|
336
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
337
|
-
createClass._classCallCheck(this, ImageSchema);
|
338
|
-
_this = _super.call(this);
|
339
|
-
_this.options = options;
|
340
|
-
_this.opt = opt;
|
341
|
-
return _this;
|
342
|
-
}
|
343
|
-
createClass._createClass(ImageSchema, [{
|
344
|
-
key: "validate",
|
345
|
-
value: function validate(src) {
|
346
|
-
throw new Error("Method not implemented.");
|
347
|
-
}
|
348
|
-
}, {
|
349
|
-
key: "match",
|
350
|
-
value: function match(src) {
|
351
|
-
// TODO:
|
352
|
-
return true;
|
353
|
-
}
|
354
|
-
}, {
|
355
|
-
key: "optional",
|
356
|
-
value: function optional() {
|
357
|
-
return new ImageSchema(this.options, true);
|
358
|
-
}
|
359
|
-
}, {
|
360
|
-
key: "serialize",
|
361
|
-
value: function serialize() {
|
362
|
-
return {
|
363
|
-
type: "image",
|
364
|
-
options: this.options,
|
365
|
-
opt: this.opt
|
366
|
-
};
|
367
|
-
}
|
368
|
-
}]);
|
369
|
-
return ImageSchema;
|
370
|
-
}(Schema);
|
371
|
-
var image = function image(options) {
|
372
|
-
return new ImageSchema(options);
|
373
|
-
};
|
374
|
-
var convertImageSource = function convertImageSource(src) {
|
375
|
-
var _src$metadata;
|
376
|
-
// TODO: /public should be configurable
|
377
|
-
return {
|
378
|
-
url: src[FILE_REF_PROP].slice("/public".length) + "?sha256=".concat((_src$metadata = src.metadata) === null || _src$metadata === void 0 ? void 0 : _src$metadata.sha256),
|
379
|
-
metadata: src.metadata
|
380
|
-
};
|
381
|
-
};
|
382
|
-
|
383
|
-
function isSerializedVal(val) {
|
384
|
-
return createClass._typeof(val) === "object" && val !== null && val !== undefined && ("val" in val || "valPath" in val);
|
385
|
-
}
|
386
|
-
function isVal(val) {
|
387
|
-
return createClass._typeof(val) === "object" && val !== null && val !== undefined && Path in val && "val" in val;
|
388
|
-
}
|
389
|
-
|
390
|
-
/**
|
391
|
-
* The path of the source value.
|
392
|
-
*
|
393
|
-
* @example
|
394
|
-
* '/app/blogs.0.text' // the text property of the first element of the /app/blogs module
|
395
|
-
*/
|
396
|
-
|
397
|
-
/**
|
398
|
-
* The path inside the module.
|
399
|
-
*
|
400
|
-
* @example
|
401
|
-
* '0."text"' // the text property of the first element of the module
|
402
|
-
*/
|
403
|
-
|
404
|
-
/**
|
405
|
-
* The id of the module.
|
406
|
-
*
|
407
|
-
* @example
|
408
|
-
* '/app/blogs' // the /app/blogs module
|
409
|
-
*/
|
410
|
-
|
411
|
-
function getValPath(valOrSelector) {
|
412
|
-
return valOrSelector[Path];
|
413
|
-
}
|
414
|
-
|
415
|
-
function hasOwn(obj, prop) {
|
416
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
417
|
-
}
|
418
|
-
function _andThen(f, source, path) {
|
419
|
-
if (source) {
|
420
|
-
return newSelectorProxy(f(newSelectorProxy(source, path)));
|
421
|
-
}
|
422
|
-
return newSelectorProxy(source, path);
|
423
|
-
}
|
424
|
-
function isSelector(source) {
|
425
|
-
return createClass._typeof(source) === "object" && source !== null && (SourceOrExpr in source || Path in source);
|
426
|
-
}
|
427
|
-
function newSelectorProxy(source, path, moduleSchema) {
|
428
|
-
var _ref;
|
429
|
-
if (createClass._typeof(source) === "object") {
|
430
|
-
if (isSelector(source)) {
|
431
|
-
return source;
|
432
|
-
} else if (isSerializedVal(source)) {
|
433
|
-
return newSelectorProxy(source.val, source.valPath);
|
434
|
-
}
|
435
|
-
}
|
436
|
-
if (source && source[FILE_REF_PROP] && source[VAL_EXTENSION] === "file") {
|
437
|
-
var fileRef = source[FILE_REF_PROP];
|
438
|
-
if (typeof fileRef !== "string") {
|
439
|
-
throw Error("Invalid file ref: " + fileRef);
|
440
|
-
}
|
441
|
-
return newSelectorProxy(convertImageSource(source), path, moduleSchema);
|
442
|
-
}
|
443
|
-
switch (createClass._typeof(source)) {
|
444
|
-
case "function":
|
445
|
-
case "symbol":
|
446
|
-
throw Error("Invalid selector type: ".concat(createClass._typeof(source), ": ").concat(source));
|
447
|
-
case "object":
|
448
|
-
// Handles both objects and arrays!
|
449
|
-
if (source !== null) {
|
450
|
-
return new Proxy(source, {
|
451
|
-
// TODO: see proxy docs if we want more traps
|
452
|
-
has: function has(target, prop) {
|
453
|
-
if (prop === SourceOrExpr) {
|
454
|
-
return true;
|
455
|
-
}
|
456
|
-
if (prop === Path) {
|
457
|
-
return true;
|
458
|
-
}
|
459
|
-
if (prop === "andThen") {
|
460
|
-
return true;
|
461
|
-
}
|
462
|
-
if (prop === GetSchema) {
|
463
|
-
return true;
|
464
|
-
}
|
465
|
-
return prop in target;
|
466
|
-
},
|
467
|
-
get: function get(target, prop) {
|
468
|
-
if (prop === SourceOrExpr) {
|
469
|
-
return source;
|
470
|
-
}
|
471
|
-
if (prop === Path) {
|
472
|
-
return path;
|
473
|
-
}
|
474
|
-
if (prop === GetSchema) {
|
475
|
-
return moduleSchema;
|
476
|
-
}
|
477
|
-
if (prop === "andThen") {
|
478
|
-
return function (f) {
|
479
|
-
return _andThen(f, source, path);
|
480
|
-
};
|
481
|
-
}
|
482
|
-
if (Array.isArray(target)) {
|
483
|
-
if (prop === "filter") {
|
484
|
-
return function (f) {
|
485
|
-
var filtered = target.map(function (a, i) {
|
486
|
-
return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
487
|
-
}).filter(function (a) {
|
488
|
-
if (f && f instanceof Schema) {
|
489
|
-
return f.match(unValify(a));
|
490
|
-
} else {
|
491
|
-
return unValify(f(a));
|
492
|
-
}
|
493
|
-
});
|
494
|
-
return newSelectorProxy(filtered, path, moduleSchema);
|
495
|
-
};
|
496
|
-
} else if (prop === "map") {
|
497
|
-
return function (f) {
|
498
|
-
var filtered = target.map(function (a, i) {
|
499
|
-
var valueOrSelector = f(newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy(i));
|
500
|
-
if (isSelector(valueOrSelector)) {
|
501
|
-
return valueOrSelector;
|
502
|
-
}
|
503
|
-
return newSelectorProxy(valueOrSelector);
|
504
|
-
});
|
505
|
-
return newSelectorProxy(filtered, path, moduleSchema);
|
506
|
-
};
|
507
|
-
}
|
508
|
-
}
|
509
|
-
if (Array.isArray(target) && prop === "length") {
|
510
|
-
return newSelectorProxy(target.length);
|
511
|
-
}
|
512
|
-
var reflectedValue = Reflect.get(target, prop);
|
513
|
-
if (hasOwn(source, prop)) {
|
514
|
-
if (!Number.isNaN(Number(prop))) {
|
515
|
-
return newSelectorProxy(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
516
|
-
}
|
517
|
-
return newSelectorProxy(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
|
518
|
-
}
|
519
|
-
return reflectedValue;
|
520
|
-
}
|
521
|
-
});
|
522
|
-
}
|
523
|
-
// intentional fallthrough
|
524
|
-
// eslint-disable-next-line no-fallthrough
|
525
|
-
default:
|
526
|
-
return _ref = {
|
527
|
-
eq: function eq(other) {
|
528
|
-
var otherValue = other;
|
529
|
-
if (isSelector(other)) {
|
530
|
-
otherValue = other[SourceOrExpr];
|
531
|
-
if (otherValue instanceof Expr) {
|
532
|
-
throw Error("TODO: Cannot evaluate equality with an Expr");
|
533
|
-
}
|
534
|
-
}
|
535
|
-
return newSelectorProxy(source === otherValue, undefined);
|
536
|
-
},
|
537
|
-
andThen: function andThen(f) {
|
538
|
-
return _andThen(f, source === undefined ? null : source, path);
|
539
|
-
}
|
540
|
-
}, _defineProperty(_ref, SourceOrExpr, source === undefined ? null : source), _defineProperty(_ref, Path, path), _defineProperty(_ref, GetSchema, moduleSchema), _ref;
|
541
|
-
}
|
542
|
-
}
|
543
|
-
function createValPathOfItem(arrayPath, prop) {
|
544
|
-
if (createClass._typeof(prop) === "symbol") {
|
545
|
-
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
546
|
-
}
|
547
|
-
return arrayPath && "".concat(arrayPath, ".").concat(JSON.stringify(prop));
|
548
|
-
}
|
549
|
-
|
550
|
-
// TODO: could we do .val on the objects instead?
|
551
|
-
function unValify(valueOrSelector) {
|
552
|
-
if (createClass._typeof(valueOrSelector) === "object" && (SourceOrExpr in valueOrSelector || Path in valueOrSelector)) {
|
553
|
-
var selectorValue = valueOrSelector[SourceOrExpr];
|
554
|
-
return selectorValue;
|
555
|
-
}
|
556
|
-
return valueOrSelector;
|
557
|
-
}
|
558
|
-
|
559
6
|
var WHITE_SPACE = ["\n", "\r", "\t", " "];
|
560
7
|
function tokenize(input) {
|
561
8
|
var tokens = [];
|
@@ -624,7 +71,7 @@ function tokenize(input) {
|
|
624
71
|
}
|
625
72
|
var cursorOffset = peek === "'" && !escaped ? 2 : _char === "$" && peek === "{" ? 3 : 1;
|
626
73
|
if (value) {
|
627
|
-
tokens.push(_objectSpread2({
|
74
|
+
tokens.push(index$1._objectSpread2({
|
628
75
|
type: "string",
|
629
76
|
span: [_start + 1, cursor - cursorOffset],
|
630
77
|
value: value
|
@@ -671,8 +118,8 @@ function tokenize(input) {
|
|
671
118
|
return [tokens, cursor];
|
672
119
|
}
|
673
120
|
|
674
|
-
var ParserError = /*#__PURE__*/
|
675
|
-
|
121
|
+
var ParserError = /*#__PURE__*/index$1._createClass(function ParserError(message, span) {
|
122
|
+
index$1._classCallCheck(this, ParserError);
|
676
123
|
this.message = message;
|
677
124
|
this.span = span;
|
678
125
|
});
|
@@ -684,7 +131,7 @@ function parseTokens(inputTokens) {
|
|
684
131
|
if (((_tokens$ = tokens[0]) === null || _tokens$ === void 0 ? void 0 : _tokens$.type) === "ws" && ((_tokens$2 = tokens[1]) === null || _tokens$2 === void 0 ? void 0 : _tokens$2.type) === ")" || ((_tokens$3 = tokens[0]) === null || _tokens$3 === void 0 ? void 0 : _tokens$3.type) === ")") {
|
685
132
|
slurpWs();
|
686
133
|
tokens.shift();
|
687
|
-
return result.ok(new Sym("()", [first.span[0], first.span[1] + 1]));
|
134
|
+
return result.ok(new index$1.Sym("()", [first.span[0], first.span[1] + 1]));
|
688
135
|
}
|
689
136
|
var args = [];
|
690
137
|
var completed = false;
|
@@ -705,7 +152,7 @@ function parseTokens(inputTokens) {
|
|
705
152
|
if ((last === null || last === void 0 ? void 0 : last.type) !== ")") {
|
706
153
|
return result.err(new ParserError("unbalanced parens: missing a ')'", [first.span[0], first.span[1] + 1]));
|
707
154
|
}
|
708
|
-
return result.ok(new Call(args, isAnon, [first.span[0], ((_args$slice$0$span = args.slice(-1)[0].span) === null || _args$slice$0$span === void 0 ? void 0 : _args$slice$0$span[1]) || -1]));
|
155
|
+
return result.ok(new index$1.Call(args, isAnon, [first.span[0], ((_args$slice$0$span = args.slice(-1)[0].span) === null || _args$slice$0$span === void 0 ? void 0 : _args$slice$0$span[1]) || -1]));
|
709
156
|
}
|
710
157
|
function slurpWs() {
|
711
158
|
while (((_tokens$9 = tokens[0]) === null || _tokens$9 === void 0 ? void 0 : _tokens$9.type) === "ws") {
|
@@ -736,7 +183,7 @@ function parseTokens(inputTokens) {
|
|
736
183
|
return _res2;
|
737
184
|
}
|
738
185
|
} else if ((nextToken === null || nextToken === void 0 ? void 0 : nextToken.type) === "string") {
|
739
|
-
children.push(new StringLiteral(nextToken.unescapedValue || nextToken.value || "", nextToken.span));
|
186
|
+
children.push(new index$1.StringLiteral(nextToken.unescapedValue || nextToken.value || "", nextToken.span));
|
740
187
|
}
|
741
188
|
}
|
742
189
|
var last = tokens.shift();
|
@@ -746,7 +193,7 @@ function parseTokens(inputTokens) {
|
|
746
193
|
} else if (last.type !== "'") {
|
747
194
|
return result.err(new ParserError("unbalanced string template: expected '''", last.span));
|
748
195
|
}
|
749
|
-
return result.ok(new StringTemplate(children, [first.span[0], last.span[1]]));
|
196
|
+
return result.ok(new index$1.StringTemplate(children, [first.span[0], last.span[1]]));
|
750
197
|
}
|
751
198
|
function slurpString(first) {
|
752
199
|
var _tokens$11, _tokens$12, _tokens$13;
|
@@ -756,13 +203,13 @@ function parseTokens(inputTokens) {
|
|
756
203
|
if (!last || !stringToken) {
|
757
204
|
throw Error("Unexpected error: stringToken or last is undefined");
|
758
205
|
}
|
759
|
-
return result.ok(new StringLiteral(stringToken.unescapedValue || stringToken.value || "", [first.span[0], last.span[1]]));
|
206
|
+
return result.ok(new index$1.StringLiteral(stringToken.unescapedValue || stringToken.value || "", [first.span[0], last.span[1]]));
|
760
207
|
} else if (((_tokens$13 = tokens[0]) === null || _tokens$13 === void 0 ? void 0 : _tokens$13.type) === "'") {
|
761
208
|
var _last2 = tokens.shift();
|
762
209
|
if (!_last2) {
|
763
210
|
throw Error("Unexpected error: last is undefined");
|
764
211
|
}
|
765
|
-
return result.ok(new StringLiteral("", [first.span[0], _last2.span[1]]));
|
212
|
+
return result.ok(new index$1.StringLiteral("", [first.span[0], _last2.span[1]]));
|
766
213
|
} else {
|
767
214
|
return slurpTemplate(first);
|
768
215
|
}
|
@@ -791,7 +238,7 @@ function parseTokens(inputTokens) {
|
|
791
238
|
if ((_first$value5 = first.value) !== null && _first$value5 !== void 0 && _first$value5.includes("{") || (_first$value6 = first.value) !== null && _first$value6 !== void 0 && _first$value6.includes("}")) {
|
792
239
|
return result.err(new ParserError("unexpected token: '{' and '}' are not allowed in tokens", first.span));
|
793
240
|
}
|
794
|
-
return result.ok(new Sym(first.value || "", first.span));
|
241
|
+
return result.ok(new index$1.Sym(first.value || "", first.span));
|
795
242
|
} else {
|
796
243
|
return result.err(new ParserError("expected '(', '!(' or literal or token".concat(first.value || first.type ? ", got: '".concat(first.value || first.type, "'") : ""), first.span));
|
797
244
|
}
|
@@ -809,19 +256,207 @@ function parseTokens(inputTokens) {
|
|
809
256
|
function parse(input) {
|
810
257
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
811
258
|
var _tokenize = tokenize(input),
|
812
|
-
_tokenize2 =
|
259
|
+
_tokenize2 = index$1._slicedToArray(_tokenize, 2),
|
813
260
|
tokens = _tokenize2[0];
|
814
261
|
_tokenize2[1]; // TODO: we can use cursor to improve error messages / spans
|
815
262
|
return parseTokens(tokens);
|
816
263
|
}
|
817
264
|
|
265
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
266
|
+
|
267
|
+
/**
|
268
|
+
* Selectors can be used to select parts of a Val module.
|
269
|
+
* Unlike queries, joins, aggregates etc is and will not be supported.
|
270
|
+
*
|
271
|
+
* They are designed to be be used as if they were "normal" JSON data,
|
272
|
+
* though some concessions had to be made because of TypeScript limitations.
|
273
|
+
*
|
274
|
+
* Selectors works equally on source content, defined in code, and remote content.
|
275
|
+
*
|
276
|
+
* @example
|
277
|
+
* // Select the title of a document
|
278
|
+
* const titles = useVal(docsVal.map((doc) => doc.title));
|
279
|
+
*
|
280
|
+
* @example
|
281
|
+
* // Match on a union type
|
282
|
+
* const titles = useVal(docsVal.map((doc) => doc.fold("type")({
|
283
|
+
* newsletter: (newsletter) => newsletter.title,
|
284
|
+
* email: (email) => email.subject,
|
285
|
+
* }));
|
286
|
+
*
|
287
|
+
*/
|
288
|
+
|
289
|
+
/**
|
290
|
+
* @internal
|
291
|
+
*/
|
292
|
+
var GetSchema = Symbol("GetSchema");
|
293
|
+
/**
|
294
|
+
/**
|
295
|
+
* @internal
|
296
|
+
*/
|
297
|
+
var Path = Symbol("Path");
|
298
|
+
/**
|
299
|
+
* @internal
|
300
|
+
*/
|
301
|
+
var SourceOrExpr = Symbol("SourceOrExpr");
|
302
|
+
|
303
|
+
/**
|
304
|
+
* Use this type to convert types that accepts both Source and Selectors
|
305
|
+
*
|
306
|
+
* An example would be where literals are supported like in most higher order functions (e.g. map in array)
|
307
|
+
**/
|
308
|
+
|
309
|
+
function hasOwn(obj, prop) {
|
310
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
311
|
+
}
|
312
|
+
function _andThen(f, source, path) {
|
313
|
+
if (source) {
|
314
|
+
return newSelectorProxy(f(newSelectorProxy(source, path)));
|
315
|
+
}
|
316
|
+
return newSelectorProxy(source, path);
|
317
|
+
}
|
318
|
+
function isSelector(source) {
|
319
|
+
return index$1._typeof(source) === "object" && source !== null && (SourceOrExpr in source || Path in source);
|
320
|
+
}
|
321
|
+
function newSelectorProxy(source, path, moduleSchema) {
|
322
|
+
var _ref;
|
323
|
+
if (index$1._typeof(source) === "object") {
|
324
|
+
if (isSelector(source)) {
|
325
|
+
return source;
|
326
|
+
} else if (index$1.isSerializedVal(source)) {
|
327
|
+
return newSelectorProxy(source.val, source.valPath);
|
328
|
+
}
|
329
|
+
}
|
330
|
+
if (source && source[index$1.FILE_REF_PROP] && source[index$1.VAL_EXTENSION] === "file") {
|
331
|
+
var fileRef = source[index$1.FILE_REF_PROP];
|
332
|
+
if (typeof fileRef !== "string") {
|
333
|
+
throw Error("Invalid file ref: " + fileRef);
|
334
|
+
}
|
335
|
+
return newSelectorProxy(index$1.convertFileSource(source), path, moduleSchema);
|
336
|
+
}
|
337
|
+
switch (index$1._typeof(source)) {
|
338
|
+
case "function":
|
339
|
+
case "symbol":
|
340
|
+
throw Error("Invalid selector type: ".concat(index$1._typeof(source), ": ").concat(source));
|
341
|
+
case "object":
|
342
|
+
// Handles both objects and arrays!
|
343
|
+
if (source !== null) {
|
344
|
+
return new Proxy(source, {
|
345
|
+
// TODO: see proxy docs if we want more traps
|
346
|
+
has: function has(target, prop) {
|
347
|
+
if (prop === SourceOrExpr) {
|
348
|
+
return true;
|
349
|
+
}
|
350
|
+
if (prop === Path) {
|
351
|
+
return true;
|
352
|
+
}
|
353
|
+
if (prop === "andThen") {
|
354
|
+
return true;
|
355
|
+
}
|
356
|
+
if (prop === GetSchema) {
|
357
|
+
return true;
|
358
|
+
}
|
359
|
+
return prop in target;
|
360
|
+
},
|
361
|
+
get: function get(target, prop) {
|
362
|
+
if (prop === SourceOrExpr) {
|
363
|
+
return source;
|
364
|
+
}
|
365
|
+
if (prop === Path) {
|
366
|
+
return path;
|
367
|
+
}
|
368
|
+
if (prop === GetSchema) {
|
369
|
+
return moduleSchema;
|
370
|
+
}
|
371
|
+
if (prop === "andThen") {
|
372
|
+
return function (f) {
|
373
|
+
return _andThen(f, source, path);
|
374
|
+
};
|
375
|
+
}
|
376
|
+
if (Array.isArray(target)) {
|
377
|
+
if (prop === "filter") {
|
378
|
+
return function (f) {
|
379
|
+
var filtered = target.map(function (a, i) {
|
380
|
+
return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
381
|
+
}).filter(function (a) {
|
382
|
+
if (f && f instanceof index$1.Schema) {
|
383
|
+
return f.assert(unValify(a));
|
384
|
+
} else {
|
385
|
+
return unValify(f(a));
|
386
|
+
}
|
387
|
+
});
|
388
|
+
return newSelectorProxy(filtered, path, moduleSchema);
|
389
|
+
};
|
390
|
+
} else if (prop === "map") {
|
391
|
+
return function (f) {
|
392
|
+
var filtered = target.map(function (a, i) {
|
393
|
+
var valueOrSelector = f(newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy(i));
|
394
|
+
if (isSelector(valueOrSelector)) {
|
395
|
+
return valueOrSelector;
|
396
|
+
}
|
397
|
+
return newSelectorProxy(valueOrSelector);
|
398
|
+
});
|
399
|
+
return newSelectorProxy(filtered, path, moduleSchema);
|
400
|
+
};
|
401
|
+
}
|
402
|
+
}
|
403
|
+
if (Array.isArray(target) && prop === "length") {
|
404
|
+
return newSelectorProxy(target.length);
|
405
|
+
}
|
406
|
+
var reflectedValue = Reflect.get(target, prop);
|
407
|
+
if (hasOwn(source, prop)) {
|
408
|
+
if (!Number.isNaN(Number(prop))) {
|
409
|
+
return newSelectorProxy(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
410
|
+
}
|
411
|
+
return newSelectorProxy(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
|
412
|
+
}
|
413
|
+
return reflectedValue;
|
414
|
+
}
|
415
|
+
});
|
416
|
+
}
|
417
|
+
// intentional fallthrough
|
418
|
+
// eslint-disable-next-line no-fallthrough
|
419
|
+
default:
|
420
|
+
return _ref = {
|
421
|
+
eq: function eq(other) {
|
422
|
+
var otherValue = other;
|
423
|
+
if (isSelector(other)) {
|
424
|
+
otherValue = other[SourceOrExpr];
|
425
|
+
if (otherValue instanceof index$1.Expr) {
|
426
|
+
throw Error("TODO: Cannot evaluate equality with an Expr");
|
427
|
+
}
|
428
|
+
}
|
429
|
+
return newSelectorProxy(source === otherValue, undefined);
|
430
|
+
},
|
431
|
+
andThen: function andThen(f) {
|
432
|
+
return _andThen(f, source === undefined ? null : source, path);
|
433
|
+
}
|
434
|
+
}, index$1._defineProperty(_ref, SourceOrExpr, source === undefined ? null : source), index$1._defineProperty(_ref, Path, path), index$1._defineProperty(_ref, GetSchema, moduleSchema), _ref;
|
435
|
+
}
|
436
|
+
}
|
437
|
+
function createValPathOfItem(arrayPath, prop) {
|
438
|
+
if (index$1._typeof(prop) === "symbol") {
|
439
|
+
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
440
|
+
}
|
441
|
+
return arrayPath && "".concat(arrayPath, ".").concat(JSON.stringify(prop));
|
442
|
+
}
|
443
|
+
|
444
|
+
// TODO: could we do .val on the objects instead?
|
445
|
+
function unValify(valueOrSelector) {
|
446
|
+
if (index$1._typeof(valueOrSelector) === "object" && (SourceOrExpr in valueOrSelector || Path in valueOrSelector)) {
|
447
|
+
var selectorValue = valueOrSelector[SourceOrExpr];
|
448
|
+
return selectorValue;
|
449
|
+
}
|
450
|
+
return valueOrSelector;
|
451
|
+
}
|
452
|
+
|
818
453
|
var EvalError = /*#__PURE__*/function () {
|
819
454
|
function EvalError(message, expr) {
|
820
|
-
|
455
|
+
index$1._classCallCheck(this, EvalError);
|
821
456
|
this.message = message;
|
822
457
|
this.expr = expr;
|
823
458
|
}
|
824
|
-
|
459
|
+
index$1._createClass(EvalError, [{
|
825
460
|
key: "toString",
|
826
461
|
value: function toString() {
|
827
462
|
return "".concat(this.message, " in: ").concat(this.expr.transpile());
|
@@ -839,13 +474,13 @@ function evaluateSync(expr, getSource, stack) {
|
|
839
474
|
}).join(", ");
|
840
475
|
}).join(" -> ")), expr);
|
841
476
|
}
|
842
|
-
if (expr instanceof Call) {
|
843
|
-
if (expr.children[0] instanceof Sym) {
|
477
|
+
if (expr instanceof index$1.Call) {
|
478
|
+
if (expr.children[0] instanceof index$1.Sym) {
|
844
479
|
if (expr.children[0].value === "val") {
|
845
480
|
if (expr.isAnon) {
|
846
481
|
throw new EvalError("cannot call 'val' as anonymous function", expr);
|
847
482
|
}
|
848
|
-
if (expr.children[1] instanceof StringLiteral) {
|
483
|
+
if (expr.children[1] instanceof index$1.StringLiteral) {
|
849
484
|
var _path = expr.children[1].value;
|
850
485
|
return newSelectorProxy(getSource(_path), _path);
|
851
486
|
} else {
|
@@ -863,7 +498,7 @@ function evaluateSync(expr, getSource, stack) {
|
|
863
498
|
}
|
864
499
|
try {
|
865
500
|
var serialized = JSON.parse(valObj);
|
866
|
-
if (isSerializedVal(serialized)) {
|
501
|
+
if (index$1.isSerializedVal(serialized)) {
|
867
502
|
return newSelectorProxy(serialized.val, serialized.valPath);
|
868
503
|
}
|
869
504
|
var parsedValue = newSelectorProxy(JSON.parse(valObj), valPath);
|
@@ -897,9 +532,9 @@ function evaluateSync(expr, getSource, stack) {
|
|
897
532
|
// anon functions:
|
898
533
|
var maybeFunction = obj[prop];
|
899
534
|
if (typeof maybeFunction !== "function") {
|
900
|
-
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required higher ordered function got ").concat(
|
535
|
+
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required higher ordered function got ").concat(index$1._typeof(obj[prop])), expr);
|
901
536
|
}
|
902
|
-
if (expr.children[0] instanceof Sym) {
|
537
|
+
if (expr.children[0] instanceof index$1.Sym) {
|
903
538
|
return maybeFunction(function () {
|
904
539
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
905
540
|
args[_key] = arguments[_key];
|
@@ -911,9 +546,9 @@ function evaluateSync(expr, getSource, stack) {
|
|
911
546
|
}
|
912
547
|
} else {
|
913
548
|
// non-anon functions:
|
914
|
-
if (expr.children[0] instanceof Sym) {
|
549
|
+
if (expr.children[0] instanceof index$1.Sym) {
|
915
550
|
if (expr.children[0].value === "val") {
|
916
|
-
if (expr.children[1] instanceof StringLiteral) {
|
551
|
+
if (expr.children[1] instanceof index$1.StringLiteral) {
|
917
552
|
var _path2 = expr.children[1].value;
|
918
553
|
return newSelectorProxy(getSource(_path2), _path2);
|
919
554
|
} else {
|
@@ -925,24 +560,24 @@ function evaluateSync(expr, getSource, stack) {
|
|
925
560
|
if (args.length > 0) {
|
926
561
|
var _maybeFunction = obj[prop];
|
927
562
|
if (typeof _maybeFunction !== "function") {
|
928
|
-
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required function got ").concat(
|
563
|
+
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required function got ").concat(index$1._typeof(obj[prop])), expr);
|
929
564
|
}
|
930
|
-
return _maybeFunction.apply(void 0,
|
565
|
+
return _maybeFunction.apply(void 0, index$1._toConsumableArray(args.map(function (arg) {
|
931
566
|
return evaluateSync(arg, getSource, stack);
|
932
567
|
})));
|
933
568
|
}
|
934
569
|
var maybeValue = obj[prop];
|
935
570
|
if (typeof maybeValue === "function") {
|
936
|
-
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required value got ").concat(
|
571
|
+
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required value got ").concat(index$1._typeof(obj[prop])), expr);
|
937
572
|
}
|
938
573
|
return maybeValue;
|
939
574
|
}
|
940
575
|
}
|
941
|
-
} else if (expr instanceof Sym) {
|
576
|
+
} else if (expr instanceof index$1.Sym) {
|
942
577
|
if (expr.value.startsWith("@")) {
|
943
578
|
var _stack$Number;
|
944
579
|
var _expr$value$slice$spl = expr.value.slice(2, -1).split(","),
|
945
|
-
_expr$value$slice$spl2 =
|
580
|
+
_expr$value$slice$spl2 = index$1._slicedToArray(_expr$value$slice$spl, 3),
|
946
581
|
i = _expr$value$slice$spl2[0],
|
947
582
|
j = _expr$value$slice$spl2[1],
|
948
583
|
rest = _expr$value$slice$spl2[2];
|
@@ -958,11 +593,11 @@ function evaluateSync(expr, getSource, stack) {
|
|
958
593
|
return newSelectorProxy(null);
|
959
594
|
}
|
960
595
|
return newSelectorProxy(expr.value);
|
961
|
-
} else if (expr instanceof StringLiteral) {
|
596
|
+
} else if (expr instanceof index$1.StringLiteral) {
|
962
597
|
return newSelectorProxy(expr.value);
|
963
|
-
} else if (expr instanceof StringTemplate) {
|
598
|
+
} else if (expr instanceof index$1.StringTemplate) {
|
964
599
|
return newSelectorProxy(expr.children.map(function (child) {
|
965
|
-
if (child instanceof Sym && child.value === "()") {
|
600
|
+
if (child instanceof index$1.Sym && child.value === "()") {
|
966
601
|
return "null";
|
967
602
|
}
|
968
603
|
var evalRes = evaluateSync(child, getSource, stack);
|
@@ -995,43 +630,15 @@ function evaluate(expr, source, stack) {
|
|
995
630
|
var index = /*#__PURE__*/Object.freeze({
|
996
631
|
__proto__: null,
|
997
632
|
parse: parse,
|
998
|
-
Call: Call,
|
999
|
-
Expr: Expr,
|
1000
|
-
NilSym: NilSym,
|
1001
|
-
StringLiteral: StringLiteral,
|
1002
|
-
StringTemplate: StringTemplate,
|
1003
|
-
Sym: Sym,
|
633
|
+
Call: index$1.Call,
|
634
|
+
Expr: index$1.Expr,
|
635
|
+
NilSym: index$1.NilSym,
|
636
|
+
StringLiteral: index$1.StringLiteral,
|
637
|
+
StringTemplate: index$1.StringTemplate,
|
638
|
+
Sym: index$1.Sym,
|
1004
639
|
evaluate: evaluate
|
1005
640
|
});
|
1006
641
|
|
1007
|
-
exports.Call = Call;
|
1008
|
-
exports.Expr = Expr;
|
1009
|
-
exports.FILE_REF_PROP = FILE_REF_PROP;
|
1010
|
-
exports.GenericSelector = GenericSelector;
|
1011
|
-
exports.ImageSchema = ImageSchema;
|
1012
|
-
exports.NilSym = NilSym;
|
1013
|
-
exports.Path = Path;
|
1014
|
-
exports.Schema = Schema;
|
1015
|
-
exports.SourceOrExpr = SourceOrExpr;
|
1016
|
-
exports.StringLiteral = StringLiteral;
|
1017
|
-
exports.StringTemplate = StringTemplate;
|
1018
|
-
exports.Sym = Sym;
|
1019
|
-
exports.VAL_EXTENSION = VAL_EXTENSION;
|
1020
|
-
exports._createSuper = _createSuper;
|
1021
|
-
exports._defineProperty = _defineProperty;
|
1022
|
-
exports._inherits = _inherits;
|
1023
|
-
exports._objectSpread2 = _objectSpread2;
|
1024
|
-
exports.convertImageSource = convertImageSource;
|
1025
|
-
exports.createValPathOfItem = createValPathOfItem;
|
1026
642
|
exports.evaluate = evaluate;
|
1027
|
-
exports.file = file;
|
1028
|
-
exports.getSchema = getSchema;
|
1029
|
-
exports.getValPath = getValPath;
|
1030
|
-
exports.image = image;
|
1031
643
|
exports.index = index;
|
1032
|
-
exports.isFile = isFile;
|
1033
|
-
exports.isSelector = isSelector;
|
1034
|
-
exports.isSerializedVal = isSerializedVal;
|
1035
|
-
exports.isVal = isVal;
|
1036
|
-
exports.newSelectorProxy = newSelectorProxy;
|
1037
644
|
exports.parse = parse;
|