@valbuild/core 0.97.0 → 0.97.1
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/dist/declarations/src/extractValModules.d.ts +27 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/selector/index.d.ts +0 -1
- package/dist/{index-96716d5d.cjs.dev.js → index-039896b7.cjs.dev.js} +499 -137
- package/dist/{index-f203e2fa.cjs.prod.js → index-4da4ac5a.cjs.prod.js} +499 -137
- package/dist/{index-50fd9c06.esm.js → index-8c26d8f4.esm.js} +499 -138
- package/dist/valbuild-core.cjs.dev.js +2 -1
- package/dist/valbuild-core.cjs.prod.js +2 -1
- package/dist/valbuild-core.esm.js +1 -1
- package/package.json +1 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
- package/patch/dist/valbuild-core-patch.esm.js +2 -2
|
@@ -276,23 +276,29 @@ function _inherits(t, e) {
|
|
|
276
276
|
}), e && _setPrototypeOf(t, e);
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
+
// Identity symbols are registered in the global Symbol registry so that
|
|
280
|
+
// multiple bundled copies of @valbuild/core (e.g. the editor SPA bundle vs.
|
|
281
|
+
// the host Next.js bundle) resolve to the same Symbol instance. Without
|
|
282
|
+
// this, a value produced by one copy reads as `undefined` when accessed
|
|
283
|
+
// via these keys from the other copy — extractValModules running in the
|
|
284
|
+
// SPA against `.val.ts` modules loaded from the host bundle was hitting
|
|
285
|
+
// this exact failure mode.
|
|
279
286
|
/**
|
|
280
287
|
* @internal
|
|
281
288
|
*/
|
|
282
|
-
var GetSchema = Symbol("GetSchema");
|
|
283
|
-
/**
|
|
289
|
+
var GetSchema = Symbol["for"]("@valbuild/core/GetSchema");
|
|
284
290
|
/**
|
|
285
291
|
* @internal
|
|
286
292
|
*/
|
|
287
|
-
var Path = Symbol("Path");
|
|
293
|
+
var Path = Symbol["for"]("@valbuild/core/Path");
|
|
288
294
|
/**
|
|
289
295
|
* @internal
|
|
290
296
|
*/
|
|
291
|
-
var GetSource = Symbol("GetSource");
|
|
297
|
+
var GetSource = Symbol["for"]("@valbuild/core/GetSource");
|
|
292
298
|
/**
|
|
293
299
|
* @internal
|
|
294
300
|
*/
|
|
295
|
-
var ValError = Symbol("ValError");
|
|
301
|
+
var ValError = Symbol["for"]("@valbuild/core/ValError");
|
|
296
302
|
var GenericSelector = /*#__PURE__*/_createClass(function GenericSelector(valOrExpr, path, schema, error) {
|
|
297
303
|
_classCallCheck(this, GenericSelector);
|
|
298
304
|
this[Path] = path;
|
|
@@ -5112,149 +5118,158 @@ function modules(config, modules) {
|
|
|
5112
5118
|
};
|
|
5113
5119
|
}
|
|
5114
5120
|
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
if (
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5121
|
+
function _regeneratorValues(e) {
|
|
5122
|
+
if (null != e) {
|
|
5123
|
+
var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"],
|
|
5124
|
+
r = 0;
|
|
5125
|
+
if (t) return t.call(e);
|
|
5126
|
+
if ("function" == typeof e.next) return e;
|
|
5127
|
+
if (!isNaN(e.length)) return {
|
|
5128
|
+
next: function () {
|
|
5129
|
+
return e && r >= e.length && (e = void 0), {
|
|
5130
|
+
value: e && e[r++],
|
|
5131
|
+
done: !e
|
|
5132
|
+
};
|
|
5133
|
+
}
|
|
5134
|
+
};
|
|
5127
5135
|
}
|
|
5128
|
-
|
|
5129
|
-
url: src[FILE_REF_PROP],
|
|
5130
|
-
metadata: src.metadata
|
|
5131
|
-
};
|
|
5136
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
5132
5137
|
}
|
|
5133
5138
|
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
this.message = message;
|
|
5137
|
-
});
|
|
5138
|
-
|
|
5139
|
-
/**
|
|
5140
|
-
* NOTE: MAY mutate the input document.
|
|
5141
|
-
*/
|
|
5142
|
-
|
|
5143
|
-
function derefPath(path) {
|
|
5144
|
-
var dereffedPath = [];
|
|
5145
|
-
var referencedPath = null;
|
|
5146
|
-
var _iterator = result._createForOfIteratorHelper(path),
|
|
5147
|
-
_step;
|
|
5139
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
5140
|
+
var i = Object.defineProperty;
|
|
5148
5141
|
try {
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5142
|
+
i({}, "", {});
|
|
5143
|
+
} catch (e) {
|
|
5144
|
+
i = 0;
|
|
5145
|
+
}
|
|
5146
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
5147
|
+
function o(r, n) {
|
|
5148
|
+
_regeneratorDefine(e, r, function (e) {
|
|
5149
|
+
return this._invoke(r, n, e);
|
|
5150
|
+
});
|
|
5151
|
+
}
|
|
5152
|
+
r ? i ? i(e, r, {
|
|
5153
|
+
value: n,
|
|
5154
|
+
enumerable: !t,
|
|
5155
|
+
configurable: !t,
|
|
5156
|
+
writable: !t
|
|
5157
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
5158
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
5159
|
+
}
|
|
5160
|
+
|
|
5161
|
+
function _regenerator() {
|
|
5162
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
5163
|
+
var e,
|
|
5164
|
+
t,
|
|
5165
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
5166
|
+
n = r.iterator || "@@iterator",
|
|
5167
|
+
o = r.toStringTag || "@@toStringTag";
|
|
5168
|
+
function i(r, n, o, i) {
|
|
5169
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
5170
|
+
u = Object.create(c.prototype);
|
|
5171
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
5172
|
+
var i,
|
|
5173
|
+
c,
|
|
5174
|
+
u,
|
|
5175
|
+
f = 0,
|
|
5176
|
+
p = o || [],
|
|
5177
|
+
y = !1,
|
|
5178
|
+
G = {
|
|
5179
|
+
p: 0,
|
|
5180
|
+
n: 0,
|
|
5181
|
+
v: e,
|
|
5182
|
+
a: d,
|
|
5183
|
+
f: d.bind(e, 4),
|
|
5184
|
+
d: function (t, r) {
|
|
5185
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
5164
5186
|
}
|
|
5165
|
-
}
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5187
|
+
};
|
|
5188
|
+
function d(r, n) {
|
|
5189
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
5190
|
+
var o,
|
|
5191
|
+
i = p[t],
|
|
5192
|
+
d = G.p,
|
|
5193
|
+
l = i[2];
|
|
5194
|
+
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
5169
5195
|
}
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
dereffedPath.push(segment);
|
|
5196
|
+
if (o || r > 1) return a;
|
|
5197
|
+
throw y = !0, n;
|
|
5173
5198
|
}
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5199
|
+
return function (o, p, l) {
|
|
5200
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
5201
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
5202
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
5203
|
+
try {
|
|
5204
|
+
if (f = 2, i) {
|
|
5205
|
+
if (c || (o = "next"), t = i[o]) {
|
|
5206
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
5207
|
+
if (!t.done) return t;
|
|
5208
|
+
u = t.value, c < 2 && (c = 0);
|
|
5209
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
5210
|
+
i = e;
|
|
5211
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
5212
|
+
} catch (t) {
|
|
5213
|
+
i = e, c = 1, u = t;
|
|
5214
|
+
} finally {
|
|
5215
|
+
f = 1;
|
|
5216
|
+
}
|
|
5217
|
+
}
|
|
5218
|
+
return {
|
|
5219
|
+
value: t,
|
|
5220
|
+
done: y
|
|
5221
|
+
};
|
|
5222
|
+
};
|
|
5223
|
+
}(r, o, i), !0), u;
|
|
5179
5224
|
}
|
|
5180
|
-
|
|
5225
|
+
var a = {};
|
|
5226
|
+
function Generator() {}
|
|
5227
|
+
function GeneratorFunction() {}
|
|
5228
|
+
function GeneratorFunctionPrototype() {}
|
|
5229
|
+
t = Object.getPrototypeOf;
|
|
5230
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
5231
|
+
return this;
|
|
5232
|
+
}), t),
|
|
5233
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
5234
|
+
function f(e) {
|
|
5235
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
5236
|
+
}
|
|
5237
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
5238
|
+
return this;
|
|
5239
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
5240
|
+
return "[object Generator]";
|
|
5241
|
+
}), (_regenerator = function () {
|
|
5242
|
+
return {
|
|
5243
|
+
w: i,
|
|
5244
|
+
m: f
|
|
5245
|
+
};
|
|
5246
|
+
})();
|
|
5181
5247
|
}
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
var dereferencedPatch = [];
|
|
5185
|
-
var _iterator3 = result._createForOfIteratorHelper(patch),
|
|
5186
|
-
_step3;
|
|
5248
|
+
|
|
5249
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
5187
5250
|
try {
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
if (result.isErr(maybeDerefRes)) {
|
|
5193
|
-
return maybeDerefRes;
|
|
5194
|
-
}
|
|
5195
|
-
var _maybeDerefRes$value = _slicedToArray(maybeDerefRes.value, 2),
|
|
5196
|
-
dereffedPath = _maybeDerefRes$value[0],
|
|
5197
|
-
referencedPath = _maybeDerefRes$value[1];
|
|
5198
|
-
if (referencedPath) {
|
|
5199
|
-
var maybeValue = ops.get(document, dereffedPath);
|
|
5200
|
-
if (result.isOk(maybeValue)) {
|
|
5201
|
-
var value = maybeValue.value;
|
|
5202
|
-
if (isFile(value)) {
|
|
5203
|
-
if (referencedPath.length > 0) {
|
|
5204
|
-
return result.err(new PatchError("Cannot sub-reference file reference at path: ".concat(dereffedPath.join("/"))));
|
|
5205
|
-
}
|
|
5206
|
-
if (typeof op.value !== "string") {
|
|
5207
|
-
return result.err(new PatchError("Expected base64 encoded string value for file reference, got ".concat(JSON.stringify(op.value))));
|
|
5208
|
-
}
|
|
5209
|
-
fileUpdates[value[FILE_REF_PROP]] = op.value;
|
|
5210
|
-
// } else if (isRemote(value)) {
|
|
5211
|
-
// if (!remotePatches[value[REMOTE_REF_PROP]]) {
|
|
5212
|
-
// remotePatches[value[REMOTE_REF_PROP]] = [];
|
|
5213
|
-
// }
|
|
5214
|
-
// remotePatches[value[REMOTE_REF_PROP]].push({
|
|
5215
|
-
// op: "replace",
|
|
5216
|
-
// path: referencedPath,
|
|
5217
|
-
// value: op.value,
|
|
5218
|
-
// });
|
|
5219
|
-
} else {
|
|
5220
|
-
return result.err(new PatchError("Unknown reference: ".concat(JSON.stringify(op), " at path: ").concat(dereffedPath.join("/"))));
|
|
5221
|
-
}
|
|
5222
|
-
} else {
|
|
5223
|
-
return maybeValue;
|
|
5224
|
-
}
|
|
5225
|
-
} else {
|
|
5226
|
-
dereferencedPatch.push(op);
|
|
5227
|
-
}
|
|
5228
|
-
} else if (op.op === "file") {
|
|
5229
|
-
if (!op.filePath.startsWith("/public")) {
|
|
5230
|
-
return result.err(new PatchError("Path must start with /public"));
|
|
5231
|
-
}
|
|
5232
|
-
if (typeof op.value !== "string") {
|
|
5233
|
-
return result.err(new PatchError("File operation must have a value that is typeof string. Found: ".concat(_typeof(op.value))));
|
|
5234
|
-
}
|
|
5235
|
-
fileUpdates[op.filePath] = op.value;
|
|
5236
|
-
} else {
|
|
5237
|
-
var _maybeDerefRes = derefPath(op.path);
|
|
5238
|
-
if (result.isErr(_maybeDerefRes)) {
|
|
5239
|
-
return _maybeDerefRes;
|
|
5240
|
-
}
|
|
5241
|
-
var _maybeDerefRes$value2 = _slicedToArray(_maybeDerefRes.value, 2),
|
|
5242
|
-
_referencedPath = _maybeDerefRes$value2[1];
|
|
5243
|
-
if (_referencedPath) {
|
|
5244
|
-
throw new Error("Unimplemented operation: ".concat(JSON.stringify(op)));
|
|
5245
|
-
}
|
|
5246
|
-
dereferencedPatch.push(op);
|
|
5247
|
-
}
|
|
5248
|
-
}
|
|
5249
|
-
} catch (err) {
|
|
5250
|
-
_iterator3.e(err);
|
|
5251
|
-
} finally {
|
|
5252
|
-
_iterator3.f();
|
|
5251
|
+
var i = n[a](c),
|
|
5252
|
+
u = i.value;
|
|
5253
|
+
} catch (n) {
|
|
5254
|
+
return void e(n);
|
|
5253
5255
|
}
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5256
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
5257
|
+
}
|
|
5258
|
+
function _asyncToGenerator(n) {
|
|
5259
|
+
return function () {
|
|
5260
|
+
var t = this,
|
|
5261
|
+
e = arguments;
|
|
5262
|
+
return new Promise(function (r, o) {
|
|
5263
|
+
var a = n.apply(t, e);
|
|
5264
|
+
function _next(n) {
|
|
5265
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
5266
|
+
}
|
|
5267
|
+
function _throw(n) {
|
|
5268
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
5269
|
+
}
|
|
5270
|
+
_next(void 0);
|
|
5271
|
+
});
|
|
5272
|
+
};
|
|
5258
5273
|
}
|
|
5259
5274
|
|
|
5260
5275
|
/**
|
|
@@ -5590,6 +5605,352 @@ var getSHA256Hash = function getSHA256Hash(bits) {
|
|
|
5590
5605
|
return createHash().update(bits).digest("hex");
|
|
5591
5606
|
};
|
|
5592
5607
|
|
|
5608
|
+
// Lazily constructed: this module is also evaluated inside the QuickJS
|
|
5609
|
+
// sandbox (when user val modules import @valbuild/core), and that sandbox
|
|
5610
|
+
// has no `TextEncoder` global. `hash()` is never called from inside the
|
|
5611
|
+
// sandbox, so deferring construction avoids a ReferenceError at import time.
|
|
5612
|
+
var textEncoder;
|
|
5613
|
+
function getTextEncoder() {
|
|
5614
|
+
if (!textEncoder) {
|
|
5615
|
+
textEncoder = new TextEncoder();
|
|
5616
|
+
}
|
|
5617
|
+
return textEncoder;
|
|
5618
|
+
}
|
|
5619
|
+
function hash(input) {
|
|
5620
|
+
if (_typeof(input) === "object") {
|
|
5621
|
+
return hashObject(input);
|
|
5622
|
+
}
|
|
5623
|
+
return getSHA256Hash(getTextEncoder().encode(input));
|
|
5624
|
+
}
|
|
5625
|
+
function hashObject(obj) {
|
|
5626
|
+
var collector = [];
|
|
5627
|
+
collectObjectRecursive(obj, collector);
|
|
5628
|
+
return getSHA256Hash(getTextEncoder().encode(collector.join("")));
|
|
5629
|
+
}
|
|
5630
|
+
function collectObjectRecursive(item, collector) {
|
|
5631
|
+
if (typeof item === "string") {
|
|
5632
|
+
collector.push("\"", item, "\"");
|
|
5633
|
+
return;
|
|
5634
|
+
} else if (typeof item === "number") {
|
|
5635
|
+
collector.push(item.toString());
|
|
5636
|
+
return;
|
|
5637
|
+
} else if (_typeof(item) === "object") {
|
|
5638
|
+
if (Array.isArray(item)) {
|
|
5639
|
+
collector.push("[");
|
|
5640
|
+
for (var i = 0; i < item.length; i++) {
|
|
5641
|
+
collectObjectRecursive(item[i], collector);
|
|
5642
|
+
if (i !== item.length - 1) collector.push(",");
|
|
5643
|
+
}
|
|
5644
|
+
collector.push("]");
|
|
5645
|
+
} else {
|
|
5646
|
+
collector.push("{");
|
|
5647
|
+
var keys = Object.keys(item).sort();
|
|
5648
|
+
keys.forEach(function (key, i) {
|
|
5649
|
+
collector.push("\"".concat(key, "\":"));
|
|
5650
|
+
collectObjectRecursive(item[key], collector);
|
|
5651
|
+
if (i !== keys.length - 1) collector.push(",");
|
|
5652
|
+
});
|
|
5653
|
+
collector.push("}");
|
|
5654
|
+
}
|
|
5655
|
+
return;
|
|
5656
|
+
} else {
|
|
5657
|
+
console.warn("Unknown type encountered when hashing object", _typeof(item), item);
|
|
5658
|
+
}
|
|
5659
|
+
}
|
|
5660
|
+
|
|
5661
|
+
/**
|
|
5662
|
+
* Extracts schemas and sources from a ValModules registry and computes the
|
|
5663
|
+
* deterministic SHAs that the server and client both use to detect changes.
|
|
5664
|
+
*
|
|
5665
|
+
* Used by ValOps on the server and by ValSyncEngine on the client so the
|
|
5666
|
+
* hash algorithm has a single source of truth.
|
|
5667
|
+
*/
|
|
5668
|
+
function extractValModules(_x) {
|
|
5669
|
+
return _extractValModules.apply(this, arguments);
|
|
5670
|
+
}
|
|
5671
|
+
function _extractValModules() {
|
|
5672
|
+
_extractValModules = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(valModules) {
|
|
5673
|
+
var moduleErrors, addModuleError, sources, schemas, serializedSchemas, configSha, sourcesSha, baseSha, schemaSha, _loop, _ret, moduleIdx;
|
|
5674
|
+
return _regenerator().w(function (_context2) {
|
|
5675
|
+
while (1) switch (_context2.n) {
|
|
5676
|
+
case 0:
|
|
5677
|
+
moduleErrors = [];
|
|
5678
|
+
addModuleError = function addModuleError(message, index, path) {
|
|
5679
|
+
moduleErrors[index] = {
|
|
5680
|
+
message: message,
|
|
5681
|
+
path: path
|
|
5682
|
+
};
|
|
5683
|
+
};
|
|
5684
|
+
sources = {};
|
|
5685
|
+
schemas = {};
|
|
5686
|
+
serializedSchemas = {};
|
|
5687
|
+
configSha = hash(JSON.stringify(valModules.config));
|
|
5688
|
+
sourcesSha = "";
|
|
5689
|
+
baseSha = configSha;
|
|
5690
|
+
schemaSha = configSha;
|
|
5691
|
+
_loop = /*#__PURE__*/_regenerator().m(function _loop(moduleIdx) {
|
|
5692
|
+
var module;
|
|
5693
|
+
return _regenerator().w(function (_context) {
|
|
5694
|
+
while (1) switch (_context.n) {
|
|
5695
|
+
case 0:
|
|
5696
|
+
module = valModules.modules[moduleIdx];
|
|
5697
|
+
if (module.def) {
|
|
5698
|
+
_context.n = 1;
|
|
5699
|
+
break;
|
|
5700
|
+
}
|
|
5701
|
+
addModuleError("val.modules is missing 'def' property", moduleIdx);
|
|
5702
|
+
return _context.a(2, 0);
|
|
5703
|
+
case 1:
|
|
5704
|
+
if (!(typeof module.def !== "function")) {
|
|
5705
|
+
_context.n = 2;
|
|
5706
|
+
break;
|
|
5707
|
+
}
|
|
5708
|
+
addModuleError("val.modules 'def' property is not a function", moduleIdx);
|
|
5709
|
+
return _context.a(2, 0);
|
|
5710
|
+
case 2:
|
|
5711
|
+
_context.n = 3;
|
|
5712
|
+
return module.def().then(function (value) {
|
|
5713
|
+
if (!value) {
|
|
5714
|
+
addModuleError("val.modules 'def' did not return a value", moduleIdx);
|
|
5715
|
+
return;
|
|
5716
|
+
}
|
|
5717
|
+
if (!value["default"]) {
|
|
5718
|
+
addModuleError("val.modules 'def' did not return a default export", moduleIdx);
|
|
5719
|
+
return;
|
|
5720
|
+
}
|
|
5721
|
+
var path = getValPath(value["default"]);
|
|
5722
|
+
if (path === undefined) {
|
|
5723
|
+
addModuleError("path is undefined", moduleIdx);
|
|
5724
|
+
return;
|
|
5725
|
+
}
|
|
5726
|
+
var schema = getSchema(value["default"]);
|
|
5727
|
+
if (schema === undefined) {
|
|
5728
|
+
addModuleError("schema in path '".concat(path, "' is undefined"), moduleIdx, path);
|
|
5729
|
+
return;
|
|
5730
|
+
}
|
|
5731
|
+
// Avoid `schema instanceof Schema` — the editor SPA and the host
|
|
5732
|
+
// Next.js bundle each ship their own copy of @valbuild/core, so the
|
|
5733
|
+
// `Schema` class identity differs between them and the instanceof
|
|
5734
|
+
// check would fail for cross-bundle modules. The executeSerialize
|
|
5735
|
+
// check below is the actual contract we depend on.
|
|
5736
|
+
if (typeof schema["executeSerialize"] !== "function") {
|
|
5737
|
+
addModuleError("schema.serialize in path '".concat(path, "' is not a function"), moduleIdx, path);
|
|
5738
|
+
return;
|
|
5739
|
+
}
|
|
5740
|
+
var source = getSource(value["default"]);
|
|
5741
|
+
if (source === undefined) {
|
|
5742
|
+
addModuleError("source in ".concat(path, " is undefined"), moduleIdx, path);
|
|
5743
|
+
return;
|
|
5744
|
+
}
|
|
5745
|
+
var serializedSchema;
|
|
5746
|
+
try {
|
|
5747
|
+
serializedSchema = schema["executeSerialize"]();
|
|
5748
|
+
} catch (e) {
|
|
5749
|
+
var message = e instanceof Error ? e.message : JSON.stringify(e);
|
|
5750
|
+
addModuleError("Could not serialize module: '".concat(path, "'. Error: ").concat(message), moduleIdx, path);
|
|
5751
|
+
return;
|
|
5752
|
+
}
|
|
5753
|
+
var pathM = path;
|
|
5754
|
+
sources[pathM] = source;
|
|
5755
|
+
schemas[pathM] = schema;
|
|
5756
|
+
serializedSchemas[pathM] = serializedSchema;
|
|
5757
|
+
sourcesSha = hash(sourcesSha + JSON.stringify({
|
|
5758
|
+
path: path,
|
|
5759
|
+
source: source
|
|
5760
|
+
}));
|
|
5761
|
+
baseSha = hash(baseSha + JSON.stringify({
|
|
5762
|
+
path: path,
|
|
5763
|
+
schema: serializedSchema,
|
|
5764
|
+
source: source,
|
|
5765
|
+
modulesErrors: moduleErrors
|
|
5766
|
+
}));
|
|
5767
|
+
schemaSha = hash(schemaSha + JSON.stringify(serializedSchema));
|
|
5768
|
+
});
|
|
5769
|
+
case 3:
|
|
5770
|
+
return _context.a(2);
|
|
5771
|
+
}
|
|
5772
|
+
}, _loop);
|
|
5773
|
+
});
|
|
5774
|
+
moduleIdx = 0;
|
|
5775
|
+
case 1:
|
|
5776
|
+
if (!(moduleIdx < valModules.modules.length)) {
|
|
5777
|
+
_context2.n = 4;
|
|
5778
|
+
break;
|
|
5779
|
+
}
|
|
5780
|
+
return _context2.d(_regeneratorValues(_loop(moduleIdx)), 2);
|
|
5781
|
+
case 2:
|
|
5782
|
+
_ret = _context2.v;
|
|
5783
|
+
if (!(_ret === 0)) {
|
|
5784
|
+
_context2.n = 3;
|
|
5785
|
+
break;
|
|
5786
|
+
}
|
|
5787
|
+
return _context2.a(3, 3);
|
|
5788
|
+
case 3:
|
|
5789
|
+
moduleIdx++;
|
|
5790
|
+
_context2.n = 1;
|
|
5791
|
+
break;
|
|
5792
|
+
case 4:
|
|
5793
|
+
return _context2.a(2, {
|
|
5794
|
+
sources: sources,
|
|
5795
|
+
schemas: schemas,
|
|
5796
|
+
serializedSchemas: serializedSchemas,
|
|
5797
|
+
baseSha: baseSha,
|
|
5798
|
+
schemaSha: schemaSha,
|
|
5799
|
+
sourcesSha: sourcesSha,
|
|
5800
|
+
configSha: configSha,
|
|
5801
|
+
moduleErrors: moduleErrors
|
|
5802
|
+
});
|
|
5803
|
+
}
|
|
5804
|
+
}, _callee);
|
|
5805
|
+
}));
|
|
5806
|
+
return _extractValModules.apply(this, arguments);
|
|
5807
|
+
}
|
|
5808
|
+
|
|
5809
|
+
var DEFAULT_VAL_REMOTE_HOST = "https://remote.val.build";
|
|
5810
|
+
function convertRemoteSource(src) {
|
|
5811
|
+
if (src !== null && src !== void 0 && src.patch_id) {
|
|
5812
|
+
var splitRemoteRefDataRes = splitRemoteRef(src[FILE_REF_PROP]);
|
|
5813
|
+
if (splitRemoteRefDataRes.status === "success") {
|
|
5814
|
+
return {
|
|
5815
|
+
url: "/api/val/files/" + splitRemoteRefDataRes.filePath + "?patch_id=".concat(src["patch_id"], "&remote=true&ref=").concat(encodeURIComponent(src[FILE_REF_PROP])),
|
|
5816
|
+
metadata: src.metadata
|
|
5817
|
+
};
|
|
5818
|
+
} else {
|
|
5819
|
+
console.warn("Internal Val error: failed to split remote ref: ".concat(src[FILE_REF_PROP], ". The data format is different than what is expected. Check Val versions for mismatches."), splitRemoteRefDataRes.error);
|
|
5820
|
+
}
|
|
5821
|
+
}
|
|
5822
|
+
return {
|
|
5823
|
+
url: src[FILE_REF_PROP],
|
|
5824
|
+
metadata: src.metadata
|
|
5825
|
+
};
|
|
5826
|
+
}
|
|
5827
|
+
|
|
5828
|
+
var PatchError = /*#__PURE__*/_createClass(function PatchError(message) {
|
|
5829
|
+
_classCallCheck(this, PatchError);
|
|
5830
|
+
this.message = message;
|
|
5831
|
+
});
|
|
5832
|
+
|
|
5833
|
+
/**
|
|
5834
|
+
* NOTE: MAY mutate the input document.
|
|
5835
|
+
*/
|
|
5836
|
+
|
|
5837
|
+
function derefPath(path) {
|
|
5838
|
+
var dereffedPath = [];
|
|
5839
|
+
var referencedPath = null;
|
|
5840
|
+
var _iterator = result._createForOfIteratorHelper(path),
|
|
5841
|
+
_step;
|
|
5842
|
+
try {
|
|
5843
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
5844
|
+
var segment = _step.value;
|
|
5845
|
+
if (segment.startsWith("$")) {
|
|
5846
|
+
var dereffedSegment = segment.slice(1);
|
|
5847
|
+
dereffedPath.push(dereffedSegment);
|
|
5848
|
+
referencedPath = [];
|
|
5849
|
+
var _iterator2 = result._createForOfIteratorHelper(path.slice(dereffedPath.length)),
|
|
5850
|
+
_step2;
|
|
5851
|
+
try {
|
|
5852
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
5853
|
+
var _segment = _step2.value;
|
|
5854
|
+
if (_segment.startsWith("$")) {
|
|
5855
|
+
return result.err(new PatchError("Cannot reference within reference: ".concat(_segment, ". Path: ").concat(path.join("/"))));
|
|
5856
|
+
}
|
|
5857
|
+
referencedPath.push(_segment);
|
|
5858
|
+
}
|
|
5859
|
+
} catch (err) {
|
|
5860
|
+
_iterator2.e(err);
|
|
5861
|
+
} finally {
|
|
5862
|
+
_iterator2.f();
|
|
5863
|
+
}
|
|
5864
|
+
break;
|
|
5865
|
+
} else {
|
|
5866
|
+
dereffedPath.push(segment);
|
|
5867
|
+
}
|
|
5868
|
+
}
|
|
5869
|
+
} catch (err) {
|
|
5870
|
+
_iterator.e(err);
|
|
5871
|
+
} finally {
|
|
5872
|
+
_iterator.f();
|
|
5873
|
+
}
|
|
5874
|
+
return result.ok([dereffedPath, referencedPath]);
|
|
5875
|
+
}
|
|
5876
|
+
function derefPatch(patch, document, ops) {
|
|
5877
|
+
var fileUpdates = {};
|
|
5878
|
+
var dereferencedPatch = [];
|
|
5879
|
+
var _iterator3 = result._createForOfIteratorHelper(patch),
|
|
5880
|
+
_step3;
|
|
5881
|
+
try {
|
|
5882
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
5883
|
+
var op = _step3.value;
|
|
5884
|
+
if (op.op === "replace") {
|
|
5885
|
+
var maybeDerefRes = derefPath(op.path);
|
|
5886
|
+
if (result.isErr(maybeDerefRes)) {
|
|
5887
|
+
return maybeDerefRes;
|
|
5888
|
+
}
|
|
5889
|
+
var _maybeDerefRes$value = _slicedToArray(maybeDerefRes.value, 2),
|
|
5890
|
+
dereffedPath = _maybeDerefRes$value[0],
|
|
5891
|
+
referencedPath = _maybeDerefRes$value[1];
|
|
5892
|
+
if (referencedPath) {
|
|
5893
|
+
var maybeValue = ops.get(document, dereffedPath);
|
|
5894
|
+
if (result.isOk(maybeValue)) {
|
|
5895
|
+
var value = maybeValue.value;
|
|
5896
|
+
if (isFile(value)) {
|
|
5897
|
+
if (referencedPath.length > 0) {
|
|
5898
|
+
return result.err(new PatchError("Cannot sub-reference file reference at path: ".concat(dereffedPath.join("/"))));
|
|
5899
|
+
}
|
|
5900
|
+
if (typeof op.value !== "string") {
|
|
5901
|
+
return result.err(new PatchError("Expected base64 encoded string value for file reference, got ".concat(JSON.stringify(op.value))));
|
|
5902
|
+
}
|
|
5903
|
+
fileUpdates[value[FILE_REF_PROP]] = op.value;
|
|
5904
|
+
// } else if (isRemote(value)) {
|
|
5905
|
+
// if (!remotePatches[value[REMOTE_REF_PROP]]) {
|
|
5906
|
+
// remotePatches[value[REMOTE_REF_PROP]] = [];
|
|
5907
|
+
// }
|
|
5908
|
+
// remotePatches[value[REMOTE_REF_PROP]].push({
|
|
5909
|
+
// op: "replace",
|
|
5910
|
+
// path: referencedPath,
|
|
5911
|
+
// value: op.value,
|
|
5912
|
+
// });
|
|
5913
|
+
} else {
|
|
5914
|
+
return result.err(new PatchError("Unknown reference: ".concat(JSON.stringify(op), " at path: ").concat(dereffedPath.join("/"))));
|
|
5915
|
+
}
|
|
5916
|
+
} else {
|
|
5917
|
+
return maybeValue;
|
|
5918
|
+
}
|
|
5919
|
+
} else {
|
|
5920
|
+
dereferencedPatch.push(op);
|
|
5921
|
+
}
|
|
5922
|
+
} else if (op.op === "file") {
|
|
5923
|
+
if (!op.filePath.startsWith("/public")) {
|
|
5924
|
+
return result.err(new PatchError("Path must start with /public"));
|
|
5925
|
+
}
|
|
5926
|
+
if (typeof op.value !== "string") {
|
|
5927
|
+
return result.err(new PatchError("File operation must have a value that is typeof string. Found: ".concat(_typeof(op.value))));
|
|
5928
|
+
}
|
|
5929
|
+
fileUpdates[op.filePath] = op.value;
|
|
5930
|
+
} else {
|
|
5931
|
+
var _maybeDerefRes = derefPath(op.path);
|
|
5932
|
+
if (result.isErr(_maybeDerefRes)) {
|
|
5933
|
+
return _maybeDerefRes;
|
|
5934
|
+
}
|
|
5935
|
+
var _maybeDerefRes$value2 = _slicedToArray(_maybeDerefRes.value, 2),
|
|
5936
|
+
_referencedPath = _maybeDerefRes$value2[1];
|
|
5937
|
+
if (_referencedPath) {
|
|
5938
|
+
throw new Error("Unimplemented operation: ".concat(JSON.stringify(op)));
|
|
5939
|
+
}
|
|
5940
|
+
dereferencedPatch.push(op);
|
|
5941
|
+
}
|
|
5942
|
+
}
|
|
5943
|
+
} catch (err) {
|
|
5944
|
+
_iterator3.e(err);
|
|
5945
|
+
} finally {
|
|
5946
|
+
_iterator3.f();
|
|
5947
|
+
}
|
|
5948
|
+
return result.ok({
|
|
5949
|
+
fileUpdates: fileUpdates,
|
|
5950
|
+
dereferencedPatch: dereferencedPatch
|
|
5951
|
+
});
|
|
5952
|
+
}
|
|
5953
|
+
|
|
5593
5954
|
var EXT_TO_MIME_TYPES = {
|
|
5594
5955
|
x3d: "application/vnd.hzn-3d-crossword",
|
|
5595
5956
|
"3gp": "video/3gpp",
|
|
@@ -6819,6 +7180,7 @@ exports._toConsumableArray = _toConsumableArray;
|
|
|
6819
7180
|
exports._typeof = _typeof;
|
|
6820
7181
|
exports.derefPatch = derefPatch;
|
|
6821
7182
|
exports.deserializeSchema = deserializeSchema;
|
|
7183
|
+
exports.extractValModules = extractValModules;
|
|
6822
7184
|
exports.getSourcePathFromRoute = getSourcePathFromRoute;
|
|
6823
7185
|
exports.initVal = initVal;
|
|
6824
7186
|
exports.modules = modules;
|