@valbuild/core 0.99.0 → 0.100.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/declarations/src/index.d.ts +5 -0
  2. package/dist/declarations/src/initVal.d.ts +2 -0
  3. package/dist/declarations/src/schema/array.d.ts +16 -13
  4. package/dist/declarations/src/schema/boolean.d.ts +2 -1
  5. package/dist/declarations/src/schema/date.d.ts +2 -1
  6. package/dist/declarations/src/schema/datetime.d.ts +2 -1
  7. package/dist/declarations/src/schema/file.d.ts +2 -1
  8. package/dist/declarations/src/schema/image.d.ts +2 -1
  9. package/dist/declarations/src/schema/index.d.ts +22 -0
  10. package/dist/declarations/src/schema/keyOf.d.ts +2 -1
  11. package/dist/declarations/src/schema/literal.d.ts +2 -1
  12. package/dist/declarations/src/schema/number.d.ts +2 -1
  13. package/dist/declarations/src/schema/object.d.ts +2 -1
  14. package/dist/declarations/src/schema/record.d.ts +59 -5
  15. package/dist/declarations/src/schema/richtext.d.ts +2 -1
  16. package/dist/declarations/src/schema/route.d.ts +2 -1
  17. package/dist/declarations/src/schema/string.d.ts +2 -1
  18. package/dist/declarations/src/schema/union.d.ts +9 -1
  19. package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
  20. package/dist/declarations/src/selector/index.d.ts +3 -2
  21. package/dist/declarations/src/source/index.d.ts +3 -2
  22. package/dist/declarations/src/source/json.d.ts +73 -0
  23. package/dist/{index-233a49d6.cjs.dev.js → index-202e48a3.cjs.dev.js} +750 -310
  24. package/dist/{index-11f47a61.cjs.prod.js → index-92ba715b.cjs.prod.js} +750 -310
  25. package/dist/{index-d152e3e2.esm.js → index-c9241d81.esm.js} +750 -310
  26. package/dist/valbuild-core.cjs.dev.js +1 -1
  27. package/dist/valbuild-core.cjs.prod.js +1 -1
  28. package/dist/valbuild-core.esm.js +1 -1
  29. package/package.json +1 -1
  30. package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
  31. package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
  32. package/patch/dist/valbuild-core-patch.esm.js +2 -2
@@ -652,6 +652,13 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
652
652
  value: function hidden() {
653
653
  return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, true, this.description);
654
654
  }
655
+ }, {
656
+ key: "executeCustomValidateAt",
657
+ value: function executeCustomValidateAt(path, src) {
658
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
659
+ path: path
660
+ });
661
+ }
655
662
  }, {
656
663
  key: "executeSerialize",
657
664
  value: function executeSerialize() {
@@ -900,6 +907,13 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
900
907
  value: function raw() {
901
908
  return new StringSchema(this.options, this.opt, true, this.customValidateFunctions, this.renderInput, this.isReadonly, this.isHidden, this.description);
902
909
  }
910
+ }, {
911
+ key: "executeCustomValidateAt",
912
+ value: function executeCustomValidateAt(path, src) {
913
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
914
+ path: path
915
+ });
916
+ }
903
917
  }, {
904
918
  key: "executeSerialize",
905
919
  value: function executeSerialize() {
@@ -1116,6 +1130,13 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
1116
1130
  value: function hidden() {
1117
1131
  return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
1118
1132
  }
1133
+ }, {
1134
+ key: "executeCustomValidateAt",
1135
+ value: function executeCustomValidateAt(path, src) {
1136
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1137
+ path: path
1138
+ });
1139
+ }
1119
1140
  }, {
1120
1141
  key: "executeSerialize",
1121
1142
  value: function executeSerialize() {
@@ -1175,27 +1196,28 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1175
1196
  var isReadonly = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1176
1197
  var isHidden = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
1177
1198
  var description = arguments.length > 5 ? arguments[5] : undefined;
1199
+ var renderInput = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
1178
1200
  _classCallCheck(this, ArraySchema);
1179
1201
  _this = _callSuper(this, ArraySchema);
1180
- _defineProperty(_this, "renderInput", null);
1181
1202
  _this.item = item;
1182
1203
  _this.opt = opt;
1183
1204
  _this.customValidateFunctions = customValidateFunctions;
1184
1205
  _this.isReadonly = isReadonly;
1185
1206
  _this.isHidden = isHidden;
1186
1207
  _this.description = description;
1208
+ _this.renderInput = renderInput;
1187
1209
  return _this;
1188
1210
  }
1189
1211
  _inherits(ArraySchema, _Schema);
1190
1212
  return _createClass(ArraySchema, [{
1191
1213
  key: "describe",
1192
1214
  value: function describe(description) {
1193
- return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined);
1215
+ return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.renderInput);
1194
1216
  }
1195
1217
  }, {
1196
1218
  key: "validate",
1197
1219
  value: function validate(validationFunction) {
1198
- return new ArraySchema(this.item, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description);
1220
+ return new ArraySchema(this.item, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description, this.renderInput);
1199
1221
  }
1200
1222
  }, {
1201
1223
  key: "executeValidate",
@@ -1262,17 +1284,24 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1262
1284
  }, {
1263
1285
  key: "nullable",
1264
1286
  value: function nullable() {
1265
- return new ArraySchema(this.item, true, [], this.isReadonly, this.isHidden, this.description);
1287
+ return new ArraySchema(this.item, true, [], this.isReadonly, this.isHidden, this.description, this.renderInput);
1266
1288
  }
1267
1289
  }, {
1268
1290
  key: "readonly",
1269
1291
  value: function readonly() {
1270
- return new ArraySchema(this.item, this.opt, this.customValidateFunctions, true, this.isHidden, this.description);
1292
+ return new ArraySchema(this.item, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput);
1271
1293
  }
1272
1294
  }, {
1273
1295
  key: "hidden",
1274
1296
  value: function hidden() {
1275
- return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
1297
+ return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput);
1298
+ }
1299
+ }, {
1300
+ key: "executeCustomValidateAt",
1301
+ value: function executeCustomValidateAt(path, src) {
1302
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1303
+ path: path
1304
+ });
1276
1305
  }
1277
1306
  }, {
1278
1307
  key: "executeSerialize",
@@ -1352,8 +1381,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1352
1381
  }, {
1353
1382
  key: "render",
1354
1383
  value: function render(input) {
1355
- this.renderInput = input;
1356
- return this;
1384
+ return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, input);
1357
1385
  }
1358
1386
  }]);
1359
1387
  }(Schema);
@@ -1463,6 +1491,13 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
1463
1491
  value: function hidden() {
1464
1492
  return new LiteralSchema(this.value, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
1465
1493
  }
1494
+ }, {
1495
+ key: "executeCustomValidateAt",
1496
+ value: function executeCustomValidateAt(path, src) {
1497
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1498
+ path: path
1499
+ });
1500
+ }
1466
1501
  }, {
1467
1502
  key: "executeSerialize",
1468
1503
  value: function executeSerialize() {
@@ -1821,6 +1856,64 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1821
1856
  value: function hidden() {
1822
1857
  return new UnionSchema(this.key, this.items, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
1823
1858
  }
1859
+ }, {
1860
+ key: "executeCustomValidateAt",
1861
+ value: function executeCustomValidateAt(path, src) {
1862
+ var errors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1863
+ path: path
1864
+ });
1865
+ // A tagged union's variants share the union's path, so `Internal.resolvePath`
1866
+ // stops here and a variant's OWN validator would never be reached. Dispatch
1867
+ // into the variant this value takes — the union is the only node that knows
1868
+ // which one that is.
1869
+ var matched = this.matchedVariant(src);
1870
+ if (matched) {
1871
+ errors.push.apply(errors, _toConsumableArray(matched["executeCustomValidateAt"](path, src)));
1872
+ }
1873
+ return errors;
1874
+ }
1875
+
1876
+ /**
1877
+ * The variant schema a value takes, for a TAGGED union (string `key`). `null`
1878
+ * for a literal union (its variants are leaves with nothing to descend into) or
1879
+ * when the value matches none of them — a structural error `executeValidate`
1880
+ * already reports.
1881
+ */
1882
+ }, {
1883
+ key: "matchedVariant",
1884
+ value: function matchedVariant(src) {
1885
+ var key = this.key;
1886
+ if (typeof key !== "string" || !Array.isArray(this.items)) {
1887
+ return null;
1888
+ }
1889
+ if (src === null || _typeof(src) !== "object" || Array.isArray(src)) {
1890
+ return null;
1891
+ }
1892
+ var tag = src[key];
1893
+ if (typeof tag !== "string") {
1894
+ return null;
1895
+ }
1896
+ var objectSchemas = this.items;
1897
+ var _iterator4 = _createForOfIteratorHelper(objectSchemas),
1898
+ _step4;
1899
+ try {
1900
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1901
+ var item = _step4.value;
1902
+ if (!(item instanceof ObjectSchema)) {
1903
+ continue;
1904
+ }
1905
+ var tagSchema = item["items"][key];
1906
+ if (tagSchema instanceof LiteralSchema && tagSchema["value"] === tag) {
1907
+ return item;
1908
+ }
1909
+ }
1910
+ } catch (err) {
1911
+ _iterator4.e(err);
1912
+ } finally {
1913
+ _iterator4.f();
1914
+ }
1915
+ return null;
1916
+ }
1824
1917
  }, {
1825
1918
  key: "executeSerialize",
1826
1919
  value: function executeSerialize() {
@@ -2132,6 +2225,13 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2132
2225
  value: function hidden() {
2133
2226
  return new ImageSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, true, this.description);
2134
2227
  }
2228
+ }, {
2229
+ key: "executeCustomValidateAt",
2230
+ value: function executeCustomValidateAt(path, src) {
2231
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
2232
+ path: path
2233
+ });
2234
+ }
2135
2235
  }, {
2136
2236
  key: "executeSerialize",
2137
2237
  value: function executeSerialize() {
@@ -2307,6 +2407,13 @@ var RouteSchema = /*#__PURE__*/function (_Schema) {
2307
2407
  value: function hidden() {
2308
2408
  return new RouteSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
2309
2409
  }
2410
+ }, {
2411
+ key: "executeCustomValidateAt",
2412
+ value: function executeCustomValidateAt(path, src) {
2413
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
2414
+ path: path
2415
+ });
2416
+ }
2310
2417
  }, {
2311
2418
  key: "executeSerialize",
2312
2419
  value: function executeSerialize() {
@@ -2845,6 +2952,13 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2845
2952
  value: function hidden() {
2846
2953
  return new RichTextSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
2847
2954
  }
2955
+ }, {
2956
+ key: "executeCustomValidateAt",
2957
+ value: function executeCustomValidateAt(path, src) {
2958
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
2959
+ path: path
2960
+ });
2961
+ }
2848
2962
  }, {
2849
2963
  key: "executeSerialize",
2850
2964
  value: function executeSerialize() {
@@ -2894,6 +3008,290 @@ var richtext = function richtext(options) {
2894
3008
  return new RichTextSchema(options !== null && options !== void 0 ? options : {});
2895
3009
  };
2896
3010
 
3011
+ function _regeneratorDefine(e, r, n, t) {
3012
+ var i = Object.defineProperty;
3013
+ try {
3014
+ i({}, "", {});
3015
+ } catch (e) {
3016
+ i = 0;
3017
+ }
3018
+ _regeneratorDefine = function (e, r, n, t) {
3019
+ function o(r, n) {
3020
+ _regeneratorDefine(e, r, function (e) {
3021
+ return this._invoke(r, n, e);
3022
+ });
3023
+ }
3024
+ r ? i ? i(e, r, {
3025
+ value: n,
3026
+ enumerable: !t,
3027
+ configurable: !t,
3028
+ writable: !t
3029
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
3030
+ }, _regeneratorDefine(e, r, n, t);
3031
+ }
3032
+
3033
+ function _regenerator() {
3034
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3035
+ var e,
3036
+ t,
3037
+ r = "function" == typeof Symbol ? Symbol : {},
3038
+ n = r.iterator || "@@iterator",
3039
+ o = r.toStringTag || "@@toStringTag";
3040
+ function i(r, n, o, i) {
3041
+ var c = n && n.prototype instanceof Generator ? n : Generator,
3042
+ u = Object.create(c.prototype);
3043
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
3044
+ var i,
3045
+ c,
3046
+ u,
3047
+ f = 0,
3048
+ p = o || [],
3049
+ y = !1,
3050
+ G = {
3051
+ p: 0,
3052
+ n: 0,
3053
+ v: e,
3054
+ a: d,
3055
+ f: d.bind(e, 4),
3056
+ d: function (t, r) {
3057
+ return i = t, c = 0, u = e, G.n = r, a;
3058
+ }
3059
+ };
3060
+ function d(r, n) {
3061
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
3062
+ var o,
3063
+ i = p[t],
3064
+ d = G.p,
3065
+ l = i[2];
3066
+ 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));
3067
+ }
3068
+ if (o || r > 1) return a;
3069
+ throw y = !0, n;
3070
+ }
3071
+ return function (o, p, l) {
3072
+ if (f > 1) throw TypeError("Generator is already running");
3073
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
3074
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
3075
+ try {
3076
+ if (f = 2, i) {
3077
+ if (c || (o = "next"), t = i[o]) {
3078
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
3079
+ if (!t.done) return t;
3080
+ u = t.value, c < 2 && (c = 0);
3081
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
3082
+ i = e;
3083
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
3084
+ } catch (t) {
3085
+ i = e, c = 1, u = t;
3086
+ } finally {
3087
+ f = 1;
3088
+ }
3089
+ }
3090
+ return {
3091
+ value: t,
3092
+ done: y
3093
+ };
3094
+ };
3095
+ }(r, o, i), !0), u;
3096
+ }
3097
+ var a = {};
3098
+ function Generator() {}
3099
+ function GeneratorFunction() {}
3100
+ function GeneratorFunctionPrototype() {}
3101
+ t = Object.getPrototypeOf;
3102
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
3103
+ return this;
3104
+ }), t),
3105
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
3106
+ function f(e) {
3107
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
3108
+ }
3109
+ 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 () {
3110
+ return this;
3111
+ }), _regeneratorDefine(u, "toString", function () {
3112
+ return "[object Generator]";
3113
+ }), (_regenerator = function () {
3114
+ return {
3115
+ w: i,
3116
+ m: f
3117
+ };
3118
+ })();
3119
+ }
3120
+
3121
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
3122
+ try {
3123
+ var i = n[a](c),
3124
+ u = i.value;
3125
+ } catch (n) {
3126
+ return void e(n);
3127
+ }
3128
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
3129
+ }
3130
+ function _asyncToGenerator(n) {
3131
+ return function () {
3132
+ var t = this,
3133
+ e = arguments;
3134
+ return new Promise(function (r, o) {
3135
+ var a = n.apply(t, e);
3136
+ function _next(n) {
3137
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
3138
+ }
3139
+ function _throw(n) {
3140
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
3141
+ }
3142
+ _next(void 0);
3143
+ });
3144
+ };
3145
+ }
3146
+
3147
+ /**
3148
+ * The string used as the `_type` discriminator of a {@link JsonSource}.
3149
+ */
3150
+ var JSON_VAL_EXTENSION_TAG = "json";
3151
+
3152
+ /**
3153
+ * The lazy import thunk a {@link JsonSource} carries at runtime. It is NOT part
3154
+ * of the {@link JsonSource} type because `Source` must stay JSON-serializable
3155
+ * (it is sent over the wire as `Json`); the thunk is a runtime-only detail,
3156
+ * read via {@link getJsonImport}.
3157
+ */
3158
+
3159
+ /**
3160
+ * A JSON source represents a record/router entry whose value is stored in a
3161
+ * separate `*.val.json` file and loaded lazily via a dynamic `import()` thunk.
3162
+ *
3163
+ * This is what `c.json(() => import("./entry.val.json"))` returns.
3164
+ *
3165
+ * The *type* is a pure-JSON marker (`{ _type: "json", patch_id? }`) so that
3166
+ * `Source` stays JSON-serializable. At runtime the value additionally carries a
3167
+ * lazy import thunk (read via {@link getJsonImport}); over the wire only the
3168
+ * marker is sent.
3169
+ *
3170
+ * The phantom type parameter `T` is the (loosened, see {@link JsonOf}) type of
3171
+ * the value the JSON file resolves to. It is covariant: a `JsonSource` of a
3172
+ * narrower value type is assignable to a `JsonSource` of a wider one.
3173
+ */
3174
+
3175
+ function json(importThunk) {
3176
+ return _defineProperty(_defineProperty({}, VAL_EXTENSION, JSON_VAL_EXTENSION_TAG), "_import", importThunk);
3177
+ }
3178
+ function isJson(obj) {
3179
+ return _typeof(obj) === "object" && obj !== null && VAL_EXTENSION in obj && obj[VAL_EXTENSION] === JSON_VAL_EXTENSION_TAG;
3180
+ }
3181
+
3182
+ /**
3183
+ * Reads the runtime-only lazy import thunk from a {@link JsonSource}. Returns
3184
+ * `undefined` for a transport marker (sent over the wire without the thunk).
3185
+ */
3186
+ function getJsonImport(source) {
3187
+ var candidate = source._import;
3188
+ return typeof candidate === "function" ? candidate : undefined;
3189
+ }
3190
+
3191
+ /**
3192
+ * Recursively resolves every {@link JsonSource} marker in a source tree by
3193
+ * invoking its lazy import thunk, returning a fully-inlined source. This backs
3194
+ * the eager `fetchVal`/`useVal` path (load everything).
3195
+ *
3196
+ * Markers without a runtime thunk (transport markers received over the wire)
3197
+ * are left as-is — there is nothing to load from them locally. Other branded
3198
+ * leaf sources (file/image/remote/richtext) are returned untouched.
3199
+ */
3200
+ function resolveJsonValues(_x) {
3201
+ return _resolveJsonValues.apply(this, arguments);
3202
+ }
3203
+
3204
+ /**
3205
+ * Loosens a (strict) schema source type `T` into the type that a
3206
+ * `resolveJsonModule` import of the backing `*.val.json` can actually satisfy.
3207
+ *
3208
+ * Why this is needed: TypeScript widens literals when it infers the type of a
3209
+ * JSON module (e.g. `"a"` becomes `string`, `1` becomes `number`, and a branded
3210
+ * `_type: "file"` becomes `_type: string`). A strict schema type (with literal
3211
+ * unions, `RawString` brands, etc.) would therefore reject a perfectly valid
3212
+ * JSON file. `JsonOf<T>` performs the same widening at the type level so the
3213
+ * JSON content typechecks against the schema as strictly as JSON allows. Runtime
3214
+ * validation enforces the rest.
3215
+ *
3216
+ * The transform distributes over unions and recurses through objects/arrays,
3217
+ * preserving structure while widening every leaf literal. Val object-unions are
3218
+ * always discriminated, so distribute-and-recurse is sufficient (the discriminant
3219
+ * literal widens to its base type, but the per-variant shape stays distinct and a
3220
+ * concrete JSON value still matches exactly one variant).
3221
+ */
3222
+ function _resolveJsonValues() {
3223
+ _resolveJsonValues = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(source) {
3224
+ var thunk, loaded, entries;
3225
+ return _regenerator().w(function (_context2) {
3226
+ while (1) switch (_context2.n) {
3227
+ case 0:
3228
+ if (!isJson(source)) {
3229
+ _context2.n = 3;
3230
+ break;
3231
+ }
3232
+ thunk = getJsonImport(source);
3233
+ if (thunk) {
3234
+ _context2.n = 1;
3235
+ break;
3236
+ }
3237
+ return _context2.a(2, source);
3238
+ case 1:
3239
+ _context2.n = 2;
3240
+ return thunk();
3241
+ case 2:
3242
+ loaded = _context2.v["default"];
3243
+ return _context2.a(2, resolveJsonValues(loaded));
3244
+ case 3:
3245
+ if (!Array.isArray(source)) {
3246
+ _context2.n = 4;
3247
+ break;
3248
+ }
3249
+ return _context2.a(2, Promise.all(source.map(function (item) {
3250
+ return resolveJsonValues(item);
3251
+ })));
3252
+ case 4:
3253
+ if (!(source !== null && _typeof(source) === "object")) {
3254
+ _context2.n = 7;
3255
+ break;
3256
+ }
3257
+ if (!(VAL_EXTENSION in source)) {
3258
+ _context2.n = 5;
3259
+ break;
3260
+ }
3261
+ return _context2.a(2, source);
3262
+ case 5:
3263
+ _context2.n = 6;
3264
+ return Promise.all(Object.entries(source).map(/*#__PURE__*/function () {
3265
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref2) {
3266
+ var _ref4, key, value, _t, _t2;
3267
+ return _regenerator().w(function (_context) {
3268
+ while (1) switch (_context.n) {
3269
+ case 0:
3270
+ _ref4 = _slicedToArray(_ref2, 2), key = _ref4[0], value = _ref4[1];
3271
+ _t = key;
3272
+ _context.n = 1;
3273
+ return resolveJsonValues(value);
3274
+ case 1:
3275
+ _t2 = _context.v;
3276
+ return _context.a(2, [_t, _t2]);
3277
+ }
3278
+ }, _callee);
3279
+ }));
3280
+ return function (_x2) {
3281
+ return _ref3.apply(this, arguments);
3282
+ };
3283
+ }()));
3284
+ case 6:
3285
+ entries = _context2.v;
3286
+ return _context2.a(2, Object.fromEntries(entries));
3287
+ case 7:
3288
+ return _context2.a(2, source);
3289
+ }
3290
+ }, _callee2);
3291
+ }));
3292
+ return _resolveJsonValues.apply(this, arguments);
3293
+ }
3294
+
2897
3295
  var RegEx = /^(https?:\/\/[^/]+)\/file\/p\/([^/]+)\/b\/([^/]+)\/v\/([^/]+)\/h\/([^/]+)\/f\/([^/]+)\/p\/(.+)$/;
2898
3296
  function splitRemoteRef(ref) {
2899
3297
  if (ref[0] === "/") {
@@ -2935,6 +3333,20 @@ function splitRemoteRef(ref) {
2935
3333
  };
2936
3334
  }
2937
3335
 
3336
+ /**
3337
+ * The source type of a `.jsonValues()` record: every entry value is EITHER a
3338
+ * lazily loaded {@link JsonSource} whose resolved content is the (loosened, see
3339
+ * {@link JsonOf}) item type, OR the item value written inline.
3340
+ *
3341
+ * Inline values are accepted by the TYPE on purpose: hand-authoring an entry
3342
+ * directly in the `.val.ts` (or copying one in from a non-jsonValues record) is
3343
+ * the natural first thing to write, and a type error there is a dead end — the
3344
+ * author cannot see what to write instead. Validation reports the inline entry
3345
+ * (`jsonValues:extract-entry`) and `val validate --fix` moves it into its own
3346
+ * `*.val.json`, so the mistake is caught and repaired instead of blocking
3347
+ * authoring.
3348
+ */
3349
+
2938
3350
  var RecordSchema = /*#__PURE__*/function (_Schema) {
2939
3351
  function RecordSchema(item) {
2940
3352
  var _this;
@@ -2946,9 +3358,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2946
3358
  var isReadonly = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
2947
3359
  var isHidden = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
2948
3360
  var description = arguments.length > 8 ? arguments[8] : undefined;
3361
+ var isJsonValues = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : false;
3362
+ var renderInput = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : null;
2949
3363
  _classCallCheck(this, RecordSchema);
2950
3364
  _this = _callSuper(this, RecordSchema);
2951
- _defineProperty(_this, "renderInput", null);
2952
3365
  _this.item = item;
2953
3366
  _this.opt = opt;
2954
3367
  _this.customValidateFunctions = customValidateFunctions;
@@ -2958,18 +3371,20 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2958
3371
  _this.isReadonly = isReadonly;
2959
3372
  _this.isHidden = isHidden;
2960
3373
  _this.description = description;
3374
+ _this.isJsonValues = isJsonValues;
3375
+ _this.renderInput = renderInput;
2961
3376
  return _this;
2962
3377
  }
2963
3378
  _inherits(RecordSchema, _Schema);
2964
3379
  return _createClass(RecordSchema, [{
2965
3380
  key: "describe",
2966
3381
  value: function describe(description) {
2967
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined);
3382
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.isJsonValues, this.renderInput);
2968
3383
  }
2969
3384
  }, {
2970
3385
  key: "validate",
2971
3386
  value: function validate(validationFunction) {
2972
- return new RecordSchema(this.item, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description);
3387
+ return new RecordSchema(this.item, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.isJsonValues, this.renderInput);
2973
3388
  }
2974
3389
  }, {
2975
3390
  key: "executeValidate",
@@ -3084,7 +3499,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3084
3499
  _this2.markKeyErrorsAtPath(entryErr, subPath);
3085
3500
  }
3086
3501
  error = _this2.mergeValidationErrors(error, entryErr);
3087
- } else {
3502
+ } else if (_this2.isJsonValues && isJson(elem)) ; else {
3503
+ // Falls through for a jsonValues record whose entry content is inlined
3504
+ // (loaded in the UI, or hand-authored): same as a plain record — validate
3505
+ // the value against the item schema.
3088
3506
  var subError = _this2.item["executeValidate"](subPath, elem);
3089
3507
  error = _this2.mergeValidationErrors(error, subError);
3090
3508
  }
@@ -3325,29 +3743,61 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3325
3743
  }, {
3326
3744
  key: "nullable",
3327
3745
  value: function nullable() {
3328
- return new RecordSchema(this.item, true, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description);
3746
+ return new RecordSchema(this.item, true, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.isJsonValues, this.renderInput);
3329
3747
  }
3330
3748
  }, {
3331
3749
  key: "readonly",
3332
3750
  value: function readonly() {
3333
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, true, this.isHidden, this.description);
3751
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, true, this.isHidden, this.description, this.isJsonValues, this.renderInput);
3334
3752
  }
3335
3753
  }, {
3336
3754
  key: "hidden",
3337
3755
  value: function hidden() {
3338
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, true, this.description);
3756
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, true, this.description, this.isJsonValues, this.renderInput);
3339
3757
  }
3340
3758
  }, {
3341
3759
  key: "router",
3342
3760
  value: function router(_router) {
3343
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description);
3761
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.isJsonValues, this.renderInput);
3344
3762
  }
3345
3763
  }, {
3346
3764
  key: "remote",
3347
3765
  value: function remote() {
3348
3766
  return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions ? _objectSpread2(_objectSpread2({}, this.mediaOptions), {}, {
3349
3767
  remote: true
3350
- }) : undefined, this.isReadonly, this.isHidden, this.description);
3768
+ }) : undefined, this.isReadonly, this.isHidden, this.description, this.isJsonValues, this.renderInput);
3769
+ }
3770
+
3771
+ /**
3772
+ * Store each entry's value in its own lazily-loaded `*.val.json` file instead
3773
+ * of inlining it in the `.val.ts` module. Entry values become
3774
+ * {@link JsonSource} thunks (`c.json(() => import("./entry.val.json"))`),
3775
+ * which lets the runtime, the Studio and validation work one entry at a time
3776
+ * so a record/router can scale to many thousands of entries.
3777
+ *
3778
+ * Not supported on image/file galleries (`s.images()` / `s.files()`).
3779
+ *
3780
+ * Only supported on a module's ROOT record/router — a `.jsonValues()` record
3781
+ * nested inside an object/array/record is rejected at startup with a module
3782
+ * error, because the single-entry fetch endpoint, the Studio's content
3783
+ * substitution and content validation are all root-only.
3784
+ */
3785
+ }, {
3786
+ key: "jsonValues",
3787
+ value: function jsonValues() {
3788
+ if (this.mediaOptions) {
3789
+ throw new Error(".jsonValues() cannot be used with image/file galleries (s.images()/s.files())");
3790
+ }
3791
+ if (this.customValidateFunctions.length > 0) {
3792
+ // `.jsonValues()` changes the source shape to JsonSource entries, so a
3793
+ // validator typed against the previous Src cannot be carried over. Refusing
3794
+ // is the point: silently dropping it left the developer looking at a
3795
+ // `.validate(...)` in their source file that never ran anywhere.
3796
+ throw new Error(".jsonValues() must come BEFORE .validate(): a validator added first is typed against the un-lazy source shape and cannot be carried over. Write s.record(...).jsonValues().validate(...) instead.");
3797
+ }
3798
+ return new RecordSchema(this.item, this.opt,
3799
+ // Empty by construction: the guard above rejects any that were registered.
3800
+ [], this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, true, this.renderInput);
3351
3801
  }
3352
3802
  }, {
3353
3803
  key: "getRouterValidations",
@@ -3391,6 +3841,13 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3391
3841
  }
3392
3842
  return false;
3393
3843
  }
3844
+ }, {
3845
+ key: "executeCustomValidateAt",
3846
+ value: function executeCustomValidateAt(path, src) {
3847
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
3848
+ path: path
3849
+ });
3850
+ }
3394
3851
  }, {
3395
3852
  key: "executeSerialize",
3396
3853
  value: function executeSerialize() {
@@ -3402,6 +3859,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3402
3859
  opt: this.opt,
3403
3860
  router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId(),
3404
3861
  customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
3862
+ jsonValues: this.isJsonValues ? true : undefined,
3405
3863
  readonly: this.isReadonly,
3406
3864
  hidden: this.isHidden,
3407
3865
  description: this.description
@@ -3417,6 +3875,18 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3417
3875
  }
3418
3876
  return result;
3419
3877
  }
3878
+
3879
+ /**
3880
+ * Validate the loaded content of a single `.jsonValues()` entry against the
3881
+ * item schema. The server calls this once it has loaded the backing
3882
+ * `*.val.json` for an entry (the deep validation that `executeValidate`
3883
+ * defers).
3884
+ */
3885
+ }, {
3886
+ key: "validateJsonEntryContent",
3887
+ value: function validateJsonEntryContent(path, content) {
3888
+ return this.item["executeValidate"](path, content);
3889
+ }
3420
3890
  }, {
3421
3891
  key: "executeRender",
3422
3892
  value: function executeRender(sourcePath, src) {
@@ -3429,6 +3899,13 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3429
3899
  if (itemSrc === null || itemSrc === undefined) {
3430
3900
  continue;
3431
3901
  }
3902
+ if (isJson(itemSrc)) {
3903
+ // An un-loaded `.jsonValues()` entry: an opaque marker, not the item this
3904
+ // schema describes. Skipping it is what makes rendering a partially
3905
+ // loaded record work — the result comes out covering exactly the loaded
3906
+ // keys, and the caller renders a placeholder for the rest.
3907
+ continue;
3908
+ }
3432
3909
  var subPath = unsafeCreateSourcePath(sourcePath, _key);
3433
3910
  var itemResult = this.item["executeRender"](subPath, itemSrc);
3434
3911
  for (var keyS in itemResult) {
@@ -3446,49 +3923,55 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3446
3923
  message: "Unknown layout type: " + layout
3447
3924
  };
3448
3925
  }
3449
- try {
3450
- res[sourcePath] = {
3451
- status: "success",
3452
- data: {
3453
- layout: "list",
3454
- parent: "record",
3455
- items: Object.entries(src).map(function (_ref14) {
3456
- var _ref15 = _slicedToArray(_ref14, 2),
3457
- key = _ref15[0],
3458
- val = _ref15[1];
3459
- // NB NB: display is actually defined by the user
3460
- var _prepare = prepare({
3461
- key: key,
3462
- val: val
3463
- }),
3464
- title = _prepare.title,
3465
- subtitle = _prepare.subtitle,
3466
- image = _prepare.image;
3467
- return [key, {
3468
- title: title,
3469
- subtitle: subtitle,
3470
- image: image
3471
- }];
3472
- })
3473
- }
3474
- };
3475
- } catch (e) {
3476
- res[sourcePath] = {
3477
- status: "error",
3478
- message: e instanceof Error ? e.message : "Unknown error"
3479
- };
3926
+ var items = [];
3927
+ for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
3928
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
3929
+ _key3 = _Object$entries$_i[0],
3930
+ val = _Object$entries$_i[1];
3931
+ if (isJson(val)) {
3932
+ continue; // as above: nothing to select from an un-loaded entry
3933
+ }
3934
+ // Per KEY, not per record: `select` is user code, and one entry whose
3935
+ // data trips it up must not take out the whole list.
3936
+ try {
3937
+ // NB NB: display is actually defined by the user
3938
+ var _prepare = prepare({
3939
+ key: _key3,
3940
+ val: val
3941
+ }),
3942
+ title = _prepare.title,
3943
+ subtitle = _prepare.subtitle,
3944
+ image = _prepare.image;
3945
+ items.push([_key3, {
3946
+ title: title,
3947
+ subtitle: subtitle,
3948
+ image: image
3949
+ }]);
3950
+ } catch (e) {
3951
+ res[unsafeCreateSourcePath(sourcePath, _key3)] = {
3952
+ status: "error",
3953
+ message: e instanceof Error ? e.message : "Unknown error"
3954
+ };
3955
+ }
3480
3956
  }
3957
+ res[sourcePath] = {
3958
+ status: "success",
3959
+ data: {
3960
+ layout: "list",
3961
+ parent: "record",
3962
+ items: items
3963
+ }
3964
+ };
3481
3965
  }
3482
3966
  return res;
3483
3967
  }
3484
3968
  }, {
3485
3969
  key: "render",
3486
3970
  value: function render(input) {
3487
- this.renderInput = {
3971
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.isJsonValues, {
3488
3972
  layout: input.as,
3489
3973
  select: input.select
3490
- };
3491
- return this;
3974
+ });
3492
3975
  }
3493
3976
  }]);
3494
3977
  }(Schema);
@@ -3603,6 +4086,13 @@ function resolvePath(path, valModule, schema) {
3603
4086
  }
3604
4087
  resolvedSource = resolvedSource[part];
3605
4088
  resolvedSchema = resolvedSchema instanceof RecordSchema ? (_resolvedSchema2 = resolvedSchema) === null || _resolvedSchema2 === void 0 ? void 0 : _resolvedSchema2["item"] : resolvedSchema.item;
4089
+ // A `.jsonValues()` entry value is a lazily-loaded JsonSource marker. We
4090
+ // can resolve the entry itself (schema is now `item`), but we cannot
4091
+ // descend deeper until the backing `*.val.json` content has been loaded
4092
+ // and substituted into the source tree (done by the UI/server layer).
4093
+ if (isJson(resolvedSource) && parts.length > 0) {
4094
+ throw Error("Cannot resolve path into a jsonValues entry until its content is loaded. Path: ".concat(path));
4095
+ }
3606
4096
  } else if (isObjectSchema(resolvedSchema)) {
3607
4097
  if (_typeof(resolvedSource) !== "object") {
3608
4098
  throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
@@ -3807,6 +4297,16 @@ function safeResolvePath(path, valModule, schema) {
3807
4297
  }
3808
4298
  resolvedSource = resolvedSource[part];
3809
4299
  resolvedSchema = resolvedSchema instanceof RecordSchema ? (_resolvedSchema4 = resolvedSchema) === null || _resolvedSchema4 === void 0 ? void 0 : _resolvedSchema4["item"] : resolvedSchema.item;
4300
+ // jsonValues entry: cannot descend deeper until the backing `*.val.json`
4301
+ // content is loaded into the source tree.
4302
+ if (isJson(resolvedSource) && parts.length > 0) {
4303
+ return {
4304
+ v: {
4305
+ status: "error",
4306
+ message: "Cannot resolve path into a jsonValues entry until its content is loaded. Path: ".concat(path)
4307
+ }
4308
+ };
4309
+ }
3810
4310
  } else if (isObjectSchema(resolvedSchema)) {
3811
4311
  if (resolvedSource === undefined) {
3812
4312
  return {
@@ -4142,6 +4642,13 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
4142
4642
  min: _min
4143
4643
  }), this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description);
4144
4644
  }
4645
+ }, {
4646
+ key: "executeCustomValidateAt",
4647
+ value: function executeCustomValidateAt(path, src) {
4648
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
4649
+ path: path
4650
+ });
4651
+ }
4145
4652
  }, {
4146
4653
  key: "executeSerialize",
4147
4654
  value: function executeSerialize() {
@@ -4256,6 +4763,13 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
4256
4763
  value: function hidden() {
4257
4764
  return new BooleanSchema(this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
4258
4765
  }
4766
+ }, {
4767
+ key: "executeCustomValidateAt",
4768
+ value: function executeCustomValidateAt(path, src) {
4769
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
4770
+ path: path
4771
+ });
4772
+ }
4259
4773
  }, {
4260
4774
  key: "executeSerialize",
4261
4775
  value: function executeSerialize() {
@@ -4450,6 +4964,13 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
4450
4964
  value: function hidden() {
4451
4965
  return new KeyOfSchema(this.schema, this.sourcePath, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
4452
4966
  }
4967
+ }, {
4968
+ key: "executeCustomValidateAt",
4969
+ value: function executeCustomValidateAt(path, src) {
4970
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
4971
+ path: path
4972
+ });
4973
+ }
4453
4974
  }, {
4454
4975
  key: "executeSerialize",
4455
4976
  value: function executeSerialize() {
@@ -4695,6 +5216,13 @@ var DateSchema = /*#__PURE__*/function (_Schema) {
4695
5216
  value: function hidden() {
4696
5217
  return new DateSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
4697
5218
  }
5219
+ }, {
5220
+ key: "executeCustomValidateAt",
5221
+ value: function executeCustomValidateAt(path, src) {
5222
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
5223
+ path: path
5224
+ });
5225
+ }
4698
5226
  }, {
4699
5227
  key: "executeSerialize",
4700
5228
  value: function executeSerialize() {
@@ -4892,6 +5420,13 @@ var DateTimeSchema = /*#__PURE__*/function (_Schema) {
4892
5420
  value: function hidden() {
4893
5421
  return new DateTimeSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
4894
5422
  }
5423
+ }, {
5424
+ key: "executeCustomValidateAt",
5425
+ value: function executeCustomValidateAt(path, src) {
5426
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
5427
+ path: path
5428
+ });
5429
+ }
4895
5430
  }, {
4896
5431
  key: "executeSerialize",
4897
5432
  value: function executeSerialize() {
@@ -5133,7 +5668,8 @@ var initVal = function initVal(config) {
5133
5668
  define: define,
5134
5669
  remote: initRemote(),
5135
5670
  file: initFile(config),
5136
- image: initImage(config)
5671
+ image: initImage(config),
5672
+ json: json
5137
5673
  },
5138
5674
  s: s,
5139
5675
  config: config
@@ -5160,160 +5696,6 @@ function modules(config, modules) {
5160
5696
  };
5161
5697
  }
5162
5698
 
5163
- function _regeneratorValues(e) {
5164
- if (null != e) {
5165
- var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"],
5166
- r = 0;
5167
- if (t) return t.call(e);
5168
- if ("function" == typeof e.next) return e;
5169
- if (!isNaN(e.length)) return {
5170
- next: function () {
5171
- return e && r >= e.length && (e = void 0), {
5172
- value: e && e[r++],
5173
- done: !e
5174
- };
5175
- }
5176
- };
5177
- }
5178
- throw new TypeError(typeof e + " is not iterable");
5179
- }
5180
-
5181
- function _regeneratorDefine(e, r, n, t) {
5182
- var i = Object.defineProperty;
5183
- try {
5184
- i({}, "", {});
5185
- } catch (e) {
5186
- i = 0;
5187
- }
5188
- _regeneratorDefine = function (e, r, n, t) {
5189
- function o(r, n) {
5190
- _regeneratorDefine(e, r, function (e) {
5191
- return this._invoke(r, n, e);
5192
- });
5193
- }
5194
- r ? i ? i(e, r, {
5195
- value: n,
5196
- enumerable: !t,
5197
- configurable: !t,
5198
- writable: !t
5199
- }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
5200
- }, _regeneratorDefine(e, r, n, t);
5201
- }
5202
-
5203
- function _regenerator() {
5204
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
5205
- var e,
5206
- t,
5207
- r = "function" == typeof Symbol ? Symbol : {},
5208
- n = r.iterator || "@@iterator",
5209
- o = r.toStringTag || "@@toStringTag";
5210
- function i(r, n, o, i) {
5211
- var c = n && n.prototype instanceof Generator ? n : Generator,
5212
- u = Object.create(c.prototype);
5213
- return _regeneratorDefine(u, "_invoke", function (r, n, o) {
5214
- var i,
5215
- c,
5216
- u,
5217
- f = 0,
5218
- p = o || [],
5219
- y = !1,
5220
- G = {
5221
- p: 0,
5222
- n: 0,
5223
- v: e,
5224
- a: d,
5225
- f: d.bind(e, 4),
5226
- d: function (t, r) {
5227
- return i = t, c = 0, u = e, G.n = r, a;
5228
- }
5229
- };
5230
- function d(r, n) {
5231
- for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
5232
- var o,
5233
- i = p[t],
5234
- d = G.p,
5235
- l = i[2];
5236
- 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));
5237
- }
5238
- if (o || r > 1) return a;
5239
- throw y = !0, n;
5240
- }
5241
- return function (o, p, l) {
5242
- if (f > 1) throw TypeError("Generator is already running");
5243
- for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
5244
- i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
5245
- try {
5246
- if (f = 2, i) {
5247
- if (c || (o = "next"), t = i[o]) {
5248
- if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
5249
- if (!t.done) return t;
5250
- u = t.value, c < 2 && (c = 0);
5251
- } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
5252
- i = e;
5253
- } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
5254
- } catch (t) {
5255
- i = e, c = 1, u = t;
5256
- } finally {
5257
- f = 1;
5258
- }
5259
- }
5260
- return {
5261
- value: t,
5262
- done: y
5263
- };
5264
- };
5265
- }(r, o, i), !0), u;
5266
- }
5267
- var a = {};
5268
- function Generator() {}
5269
- function GeneratorFunction() {}
5270
- function GeneratorFunctionPrototype() {}
5271
- t = Object.getPrototypeOf;
5272
- var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
5273
- return this;
5274
- }), t),
5275
- u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
5276
- function f(e) {
5277
- return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
5278
- }
5279
- 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 () {
5280
- return this;
5281
- }), _regeneratorDefine(u, "toString", function () {
5282
- return "[object Generator]";
5283
- }), (_regenerator = function () {
5284
- return {
5285
- w: i,
5286
- m: f
5287
- };
5288
- })();
5289
- }
5290
-
5291
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
5292
- try {
5293
- var i = n[a](c),
5294
- u = i.value;
5295
- } catch (n) {
5296
- return void e(n);
5297
- }
5298
- i.done ? t(u) : Promise.resolve(u).then(r, o);
5299
- }
5300
- function _asyncToGenerator(n) {
5301
- return function () {
5302
- var t = this,
5303
- e = arguments;
5304
- return new Promise(function (r, o) {
5305
- var a = n.apply(t, e);
5306
- function _next(n) {
5307
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
5308
- }
5309
- function _throw(n) {
5310
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
5311
- }
5312
- _next(void 0);
5313
- });
5314
- };
5315
- }
5316
-
5317
5699
  /**
5318
5700
  * From: https://github.com/kawanet/sha256-uint8array/commit/a035f83824c319d01ca1e7559fdcf1632c0cd6c4
5319
5701
  *
@@ -5659,6 +6041,29 @@ function getTextEncoder() {
5659
6041
  }
5660
6042
  return textEncoder;
5661
6043
  }
6044
+ function errorMessage(e) {
6045
+ // NOT `e instanceof Error`. Val modules are evaluated inside a `node:vm`
6046
+ // context, so an error thrown from inside the sandbox is built from THAT
6047
+ // realm's Error constructor and fails the instanceof check - and
6048
+ // JSON.stringify flattens it to "{}", throwing away the only useful part.
6049
+ // Duck-type the message instead (the same reason the schema check below
6050
+ // avoids `instanceof Schema`).
6051
+ if (_typeof(e) === "object" && e !== null && "message" in e) {
6052
+ var message = e.message;
6053
+ if (typeof message === "string") {
6054
+ return message;
6055
+ }
6056
+ }
6057
+ if (typeof e === "string") {
6058
+ return e;
6059
+ }
6060
+ try {
6061
+ var _JSON$stringify;
6062
+ return (_JSON$stringify = JSON.stringify(e)) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : String(e);
6063
+ } catch (_unused) {
6064
+ return String(e);
6065
+ }
6066
+ }
5662
6067
  function hash(input) {
5663
6068
  if (_typeof(input) === "object") {
5664
6069
  return hashObject(input);
@@ -5713,127 +6118,159 @@ function extractValModules(_x) {
5713
6118
  }
5714
6119
  function _extractValModules() {
5715
6120
  _extractValModules = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(valModules) {
5716
- var moduleErrors, addModuleError, sources, schemas, serializedSchemas, configSha, sourcesSha, baseSha, schemaSha, _loop, _ret, moduleIdx;
5717
- return _regenerator().w(function (_context2) {
5718
- while (1) switch (_context2.n) {
6121
+ var moduleErrors, addModuleError, sources, schemas, serializedSchemas, configSha, sourcesSha, baseSha, schemaSha, moduleIdx, module, at, value, path, schema, source, serializedSchema, pathM, _t, _t2;
6122
+ return _regenerator().w(function (_context) {
6123
+ while (1) switch (_context.p = _context.n) {
5719
6124
  case 0:
5720
- moduleErrors = [];
5721
- addModuleError = function addModuleError(message, index, path) {
5722
- moduleErrors[index] = {
6125
+ moduleErrors = []; // NOTE: push (not index assignment) - a sparse array makes consumers that
6126
+ // use Array.prototype.find (which visits holes) crash on undefined entries.
6127
+ addModuleError = function addModuleError(message, path) {
6128
+ moduleErrors.push({
5723
6129
  message: message,
5724
6130
  path: path
5725
- };
6131
+ });
5726
6132
  };
5727
6133
  sources = {};
5728
6134
  schemas = {};
5729
6135
  serializedSchemas = {};
5730
6136
  configSha = hash(JSON.stringify(valModules.config));
5731
6137
  sourcesSha = "";
5732
- baseSha = configSha;
5733
- schemaSha = configSha;
5734
- _loop = /*#__PURE__*/_regenerator().m(function _loop(moduleIdx) {
5735
- var module;
5736
- return _regenerator().w(function (_context) {
5737
- while (1) switch (_context.n) {
5738
- case 0:
5739
- module = valModules.modules[moduleIdx];
5740
- if (module.def) {
5741
- _context.n = 1;
5742
- break;
5743
- }
5744
- addModuleError("val.modules is missing 'def' property", moduleIdx);
5745
- return _context.a(2, 0);
5746
- case 1:
5747
- if (!(typeof module.def !== "function")) {
5748
- _context.n = 2;
5749
- break;
5750
- }
5751
- addModuleError("val.modules 'def' property is not a function", moduleIdx);
5752
- return _context.a(2, 0);
5753
- case 2:
5754
- _context.n = 3;
5755
- return module.def().then(function (value) {
5756
- if (!value) {
5757
- addModuleError("val.modules 'def' did not return a value", moduleIdx);
5758
- return;
5759
- }
5760
- if (!value["default"]) {
5761
- addModuleError("val.modules 'def' did not return a default export", moduleIdx);
5762
- return;
5763
- }
5764
- var path = getValPath(value["default"]);
5765
- if (path === undefined) {
5766
- addModuleError("path is undefined", moduleIdx);
5767
- return;
5768
- }
5769
- var schema = getSchema(value["default"]);
5770
- if (schema === undefined) {
5771
- addModuleError("schema in path '".concat(path, "' is undefined"), moduleIdx, path);
5772
- return;
5773
- }
5774
- // Avoid `schema instanceof Schema` — the editor SPA and the host
5775
- // Next.js bundle each ship their own copy of @valbuild/core, so the
5776
- // `Schema` class identity differs between them and the instanceof
5777
- // check would fail for cross-bundle modules. The executeSerialize
5778
- // check below is the actual contract we depend on.
5779
- if (typeof schema["executeSerialize"] !== "function") {
5780
- addModuleError("schema.serialize in path '".concat(path, "' is not a function"), moduleIdx, path);
5781
- return;
5782
- }
5783
- var source = getSource(value["default"]);
5784
- if (source === undefined) {
5785
- addModuleError("source in ".concat(path, " is undefined"), moduleIdx, path);
5786
- return;
5787
- }
5788
- var serializedSchema;
5789
- try {
5790
- serializedSchema = schema["executeSerialize"]();
5791
- } catch (e) {
5792
- var message = e instanceof Error ? e.message : JSON.stringify(e);
5793
- addModuleError("Could not serialize module: '".concat(path, "'. Error: ").concat(message), moduleIdx, path);
5794
- return;
5795
- }
5796
- var pathM = path;
5797
- sources[pathM] = source;
5798
- schemas[pathM] = schema;
5799
- serializedSchemas[pathM] = serializedSchema;
5800
- sourcesSha = hash(sourcesSha + JSON.stringify({
5801
- path: path,
5802
- source: source
5803
- }));
5804
- baseSha = hash(baseSha + JSON.stringify({
5805
- path: path,
5806
- schema: serializedSchema,
5807
- source: source,
5808
- modulesErrors: moduleErrors
5809
- }));
5810
- schemaSha = hash(schemaSha + JSON.stringify(serializedSchema));
5811
- });
5812
- case 3:
5813
- return _context.a(2);
5814
- }
5815
- }, _loop);
5816
- });
6138
+ baseSha = configSha; // NOTE: schemaSha is deliberately NOT seeded with configSha. It is compared
6139
+ // across bundles (the server extracts from the Node bundle, the editor SPA
6140
+ // from the browser bundle) to detect that a new version has been deployed.
6141
+ // The config contains values that are not part of the schema and that differ
6142
+ // between those two bundles - most notably the documented
6143
+ // `gitCommit: process.env.VERCEL_GIT_COMMIT_SHA` / `gitBranch`, which are
6144
+ // server-only env vars and therefore `undefined` in the browser. Seeding with
6145
+ // them made the two sides disagree on every production load.
6146
+ schemaSha = "";
5817
6147
  moduleIdx = 0;
5818
6148
  case 1:
5819
6149
  if (!(moduleIdx < valModules.modules.length)) {
5820
- _context2.n = 4;
6150
+ _context.n = 18;
6151
+ break;
6152
+ }
6153
+ module = valModules.modules[moduleIdx]; // NOTE: `at index N` refers to the module's position in the val.modules
6154
+ // array, which is all we can name when the module never loaded.
6155
+ at = "at index ".concat(moduleIdx);
6156
+ if (module.def) {
6157
+ _context.n = 2;
5821
6158
  break;
5822
6159
  }
5823
- return _context2.d(_regeneratorValues(_loop(moduleIdx)), 2);
6160
+ addModuleError("val.modules ".concat(at, " is missing 'def' property"));
6161
+ return _context.a(3, 17);
5824
6162
  case 2:
5825
- _ret = _context2.v;
5826
- if (!(_ret === 0)) {
5827
- _context2.n = 3;
6163
+ if (!(typeof module.def !== "function")) {
6164
+ _context.n = 3;
5828
6165
  break;
5829
6166
  }
5830
- return _context2.a(3, 3);
6167
+ addModuleError("val.modules ".concat(at, " 'def' property is not a function"));
6168
+ return _context.a(3, 17);
5831
6169
  case 3:
6170
+ value = void 0;
6171
+ _context.p = 4;
6172
+ _context.n = 5;
6173
+ return module.def();
6174
+ case 5:
6175
+ value = _context.v;
6176
+ _context.n = 7;
6177
+ break;
6178
+ case 6:
6179
+ _context.p = 6;
6180
+ _t = _context.v;
6181
+ // A module that throws while importing (a syntax error, a throwing
6182
+ // top-level statement, a missing file) has to be reported like any other
6183
+ // module error. Letting it reject aborts the whole extraction, which on
6184
+ // the server means ValOps.initSources rejects and /stat, /schema and
6185
+ // /sources/~ all fail opaquely instead of naming the broken module.
6186
+ addModuleError("val.modules 'def' ".concat(at, " could not be loaded. Error: ").concat(errorMessage(_t)));
6187
+ return _context.a(3, 17);
6188
+ case 7:
6189
+ if (value) {
6190
+ _context.n = 8;
6191
+ break;
6192
+ }
6193
+ addModuleError("val.modules 'def' ".concat(at, " did not return a value"));
6194
+ return _context.a(3, 17);
6195
+ case 8:
6196
+ if (value["default"]) {
6197
+ _context.n = 9;
6198
+ break;
6199
+ }
6200
+ addModuleError("val.modules 'def' ".concat(at, " did not return a default export"));
6201
+ return _context.a(3, 17);
6202
+ case 9:
6203
+ path = getValPath(value["default"]);
6204
+ if (!(path === undefined)) {
6205
+ _context.n = 10;
6206
+ break;
6207
+ }
6208
+ addModuleError("path is undefined for val.modules 'def' ".concat(at));
6209
+ return _context.a(3, 17);
6210
+ case 10:
6211
+ schema = getSchema(value["default"]);
6212
+ if (!(schema === undefined)) {
6213
+ _context.n = 11;
6214
+ break;
6215
+ }
6216
+ addModuleError("schema in path '".concat(path, "' is undefined"), path);
6217
+ return _context.a(3, 17);
6218
+ case 11:
6219
+ if (!(typeof schema["executeSerialize"] !== "function")) {
6220
+ _context.n = 12;
6221
+ break;
6222
+ }
6223
+ addModuleError("schema.serialize in path '".concat(path, "' is not a function"), path);
6224
+ return _context.a(3, 17);
6225
+ case 12:
6226
+ source = getSource(value["default"]);
6227
+ if (!(source === undefined)) {
6228
+ _context.n = 13;
6229
+ break;
6230
+ }
6231
+ addModuleError("source in ".concat(path, " is undefined"), path);
6232
+ return _context.a(3, 17);
6233
+ case 13:
6234
+ serializedSchema = void 0;
6235
+ _context.p = 14;
6236
+ serializedSchema = schema["executeSerialize"]();
6237
+ _context.n = 16;
6238
+ break;
6239
+ case 15:
6240
+ _context.p = 15;
6241
+ _t2 = _context.v;
6242
+ addModuleError("Could not serialize module: '".concat(path, "'. Error: ").concat(errorMessage(_t2)), path);
6243
+ return _context.a(3, 17);
6244
+ case 16:
6245
+ pathM = path;
6246
+ sources[pathM] = source;
6247
+ schemas[pathM] = schema;
6248
+ serializedSchemas[pathM] = serializedSchema;
6249
+ sourcesSha = hash(sourcesSha + JSON.stringify({
6250
+ path: path,
6251
+ source: source
6252
+ }));
6253
+ baseSha = hash(baseSha + JSON.stringify({
6254
+ path: path,
6255
+ schema: serializedSchema,
6256
+ source: source,
6257
+ modulesErrors: moduleErrors
6258
+ }));
6259
+ // The PATH is part of the schema set, not just the schema: renaming a
6260
+ // module while leaving its schema byte-identical still changes which paths
6261
+ // exist, and an open client keyed its schema cache by the old path. Hashing
6262
+ // the schema alone left this SHA unchanged, so with no commitSha to fall
6263
+ // back on the client never refetched /schema.
6264
+ schemaSha = hash(schemaSha + JSON.stringify({
6265
+ path: path,
6266
+ schema: serializedSchema
6267
+ }));
6268
+ case 17:
5832
6269
  moduleIdx++;
5833
- _context2.n = 1;
6270
+ _context.n = 1;
5834
6271
  break;
5835
- case 4:
5836
- return _context2.a(2, {
6272
+ case 18:
6273
+ return _context.a(2, {
5837
6274
  sources: sources,
5838
6275
  schemas: schemas,
5839
6276
  serializedSchemas: serializedSchemas,
@@ -5844,7 +6281,7 @@ function _extractValModules() {
5844
6281
  moduleErrors: moduleErrors
5845
6282
  });
5846
6283
  }
5847
- }, _callee);
6284
+ }, _callee, null, [[14, 15], [4, 6]]);
5848
6285
  }));
5849
6286
  return _extractValModules.apply(this, arguments);
5850
6287
  }
@@ -6758,7 +7195,7 @@ function deserializeSchema(serialized) {
6758
7195
  return schema;
6759
7196
  }
6760
7197
  function deserializeSchemaImpl(serialized) {
6761
- var _serialized$options, _serialized$options2, _serialized$accept, _serialized$directory, _serialized$remote;
7198
+ var _serialized$options, _serialized$options2, _serialized$accept, _serialized$directory, _serialized$remote, _serialized$jsonValue;
6762
7199
  switch (serialized.type) {
6763
7200
  case "string":
6764
7201
  return new StringSchema(_objectSpread2(_objectSpread2({}, serialized.options), {}, {
@@ -6807,7 +7244,7 @@ function deserializeSchemaImpl(serialized) {
6807
7244
  directory: (_serialized$directory = serialized.directory) !== null && _serialized$directory !== void 0 ? _serialized$directory : "/public/val",
6808
7245
  remote: (_serialized$remote = serialized.remote) !== null && _serialized$remote !== void 0 ? _serialized$remote : false,
6809
7246
  altSchema: serialized.alt ? deserializeSchema(serialized.alt) : undefined
6810
- } : undefined, false, false, serialized.description);
7247
+ } : undefined, false, false, serialized.description, (_serialized$jsonValue = serialized.jsonValues) !== null && _serialized$jsonValue !== void 0 ? _serialized$jsonValue : false);
6811
7248
  case "keyOf":
6812
7249
  return new KeyOfSchema(serialized.schema, serialized.path, serialized.opt, [], false, false, serialized.description);
6813
7250
  case "route":
@@ -7126,6 +7563,9 @@ var Internal = {
7126
7563
  },
7127
7564
  isVal: isVal,
7128
7565
  isFile: isFile,
7566
+ isJson: isJson,
7567
+ getJsonImport: getJsonImport,
7568
+ resolveJsonValues: resolveJsonValues,
7129
7569
  createValPathOfItem: createValPathOfItem,
7130
7570
  getSHA256Hash: getSHA256Hash,
7131
7571
  initSchema: initSchema,