@valbuild/core 0.97.7 → 0.99.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.
@@ -13,6 +13,16 @@ export type SerializedArraySchema = {
13
13
  hidden?: boolean;
14
14
  description?: string;
15
15
  };
16
+ type ArrayRenderInput<T extends Schema<SelectorSource>> = {
17
+ as: "list";
18
+ select: (input: {
19
+ val: RenderSelector<T>;
20
+ }) => {
21
+ title: string;
22
+ subtitle?: string | null;
23
+ image?: ImageSource | null;
24
+ };
25
+ };
16
26
  export declare class ArraySchema<T extends Schema<SelectorSource>, Src extends SelectorOfSchema<T>[] | null> extends Schema<Src> {
17
27
  private readonly item;
18
28
  private readonly opt;
@@ -20,7 +30,8 @@ export declare class ArraySchema<T extends Schema<SelectorSource>, Src extends S
20
30
  private readonly isReadonly;
21
31
  private readonly isHidden;
22
32
  private readonly description?;
23
- constructor(item: T, opt?: boolean, customValidateFunctions?: ((src: Src) => false | string)[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined);
33
+ private readonly renderInput;
34
+ constructor(item: T, opt?: boolean, customValidateFunctions?: ((src: Src) => false | string)[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, renderInput?: ArrayRenderInput<T> | null);
24
35
  describe(description: string | null): ArraySchema<T, Src>;
25
36
  validate(validationFunction: (src: Src) => false | string): ArraySchema<T, Src>;
26
37
  protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
@@ -29,17 +40,8 @@ export declare class ArraySchema<T extends Schema<SelectorSource>, Src extends S
29
40
  readonly(): ArraySchema<T, Src>;
30
41
  hidden(): ArraySchema<T, Src>;
31
42
  protected executeSerialize(): SerializedArraySchema;
32
- private renderInput;
33
43
  protected executeRender(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedRender;
34
- render(input: {
35
- as: "list";
36
- select: (input: {
37
- val: RenderSelector<T>;
38
- }) => {
39
- title: string;
40
- subtitle?: string | null;
41
- image?: ImageSource | null;
42
- };
43
- }): this;
44
+ render(input: ArrayRenderInput<T>): ArraySchema<T, Src>;
44
45
  }
45
46
  export declare const array: <S extends Schema<SelectorSource>>(schema: S) => ArraySchema<S, SelectorOfSchema<S>[]>;
47
+ export {};
@@ -30,6 +30,17 @@ export type SerializedRecordSchema = {
30
30
  hidden?: boolean;
31
31
  description?: string;
32
32
  };
33
+ type RecordRenderInput<T extends Schema<SelectorSource>> = {
34
+ layout: "list";
35
+ select: (input: {
36
+ key: string;
37
+ val: RenderSelector<T>;
38
+ }) => {
39
+ title: string;
40
+ subtitle?: string | null;
41
+ image?: ImageSource | RemoteSource<ImageMetadata> | null;
42
+ };
43
+ };
33
44
  export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Schema<string>, Src extends Record<SelectorOfSchema<K>, SelectorOfSchema<T>> | null> extends Schema<Src> {
34
45
  private readonly item;
35
46
  private readonly opt;
@@ -40,7 +51,8 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
40
51
  private readonly isReadonly;
41
52
  private readonly isHidden;
42
53
  private readonly description?;
43
- constructor(item: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], currentRouter?: ValRouter | null, keySchema?: Schema<string> | null, mediaOptions?: MediaOptions | undefined, isReadonly?: boolean, isHidden?: boolean, description?: string | undefined);
54
+ private readonly renderInput;
55
+ constructor(item: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], currentRouter?: ValRouter | null, keySchema?: Schema<string> | null, mediaOptions?: MediaOptions | undefined, isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, renderInput?: RecordRenderInput<T> | null);
44
56
  describe(description: string | null): RecordSchema<T, K, Src>;
45
57
  validate(validationFunction: (src: Src) => false | string): RecordSchema<T, K, Src>;
46
58
  protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
@@ -58,7 +70,6 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
58
70
  remote(): RecordSchema<T, K, Src>;
59
71
  private getRouterValidations;
60
72
  protected executeSerialize(): SerializedRecordSchema;
61
- private renderInput;
62
73
  protected executeRender(sourcePath: SourcePath | ModuleFilePath, src: Src): ReifiedRender;
63
74
  render(input: {
64
75
  as: "list";
@@ -70,7 +81,7 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
70
81
  subtitle?: string | null;
71
82
  image?: ImageSource | RemoteSource<ImageMetadata> | null;
72
83
  };
73
- }): this;
84
+ }): RecordSchema<T, K, Src>;
74
85
  }
75
86
  export declare function record<K extends Schema<string>, S extends Schema<SelectorSource>>(key: K, schema: S): RecordSchema<S, K, Record<SelectorOfSchema<K>, SelectorOfSchema<S>>>;
76
87
  export declare function record<S extends Schema<SelectorSource>>(schema: S): RecordSchema<S, Schema<string>, Record<string, SelectorOfSchema<S>>>;
@@ -1,2 +1,2 @@
1
- export declare const ValidationFix: readonly ["image:add-metadata", "image:check-metadata", "image:upload-remote", "image:download-remote", "image:check-remote", "images:check-remote", "file:add-metadata", "file:check-metadata", "file:upload-remote", "file:download-remote", "file:check-remote", "files:check-remote", "keyof:check-keys", "router:check-route", "images:check-unique-folder", "files:check-unique-folder", "images:check-all-files", "files:check-all-files"];
1
+ export declare const ValidationFix: readonly ["image:add-metadata", "image:check-metadata", "image:upload-remote", "image:download-remote", "image:check-remote", "images:check-remote", "images:upload-remote", "file:add-metadata", "file:check-metadata", "file:upload-remote", "file:download-remote", "file:check-remote", "files:check-remote", "files:upload-remote", "keyof:check-keys", "router:check-route", "images:check-unique-folder", "files:check-unique-folder", "images:check-all-files", "files:check-all-files"];
2
2
  export type ValidationFix = (typeof ValidationFix)[number];
@@ -1175,27 +1175,28 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1175
1175
  var isReadonly = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1176
1176
  var isHidden = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
1177
1177
  var description = arguments.length > 5 ? arguments[5] : undefined;
1178
+ var renderInput = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
1178
1179
  _classCallCheck(this, ArraySchema);
1179
1180
  _this = _callSuper(this, ArraySchema);
1180
- _defineProperty(_this, "renderInput", null);
1181
1181
  _this.item = item;
1182
1182
  _this.opt = opt;
1183
1183
  _this.customValidateFunctions = customValidateFunctions;
1184
1184
  _this.isReadonly = isReadonly;
1185
1185
  _this.isHidden = isHidden;
1186
1186
  _this.description = description;
1187
+ _this.renderInput = renderInput;
1187
1188
  return _this;
1188
1189
  }
1189
1190
  _inherits(ArraySchema, _Schema);
1190
1191
  return _createClass(ArraySchema, [{
1191
1192
  key: "describe",
1192
1193
  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);
1194
+ return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.renderInput);
1194
1195
  }
1195
1196
  }, {
1196
1197
  key: "validate",
1197
1198
  value: function validate(validationFunction) {
1198
- return new ArraySchema(this.item, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description);
1199
+ return new ArraySchema(this.item, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description, this.renderInput);
1199
1200
  }
1200
1201
  }, {
1201
1202
  key: "executeValidate",
@@ -1262,17 +1263,17 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1262
1263
  }, {
1263
1264
  key: "nullable",
1264
1265
  value: function nullable() {
1265
- return new ArraySchema(this.item, true, [], this.isReadonly, this.isHidden, this.description);
1266
+ return new ArraySchema(this.item, true, [], this.isReadonly, this.isHidden, this.description, this.renderInput);
1266
1267
  }
1267
1268
  }, {
1268
1269
  key: "readonly",
1269
1270
  value: function readonly() {
1270
- return new ArraySchema(this.item, this.opt, this.customValidateFunctions, true, this.isHidden, this.description);
1271
+ return new ArraySchema(this.item, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput);
1271
1272
  }
1272
1273
  }, {
1273
1274
  key: "hidden",
1274
1275
  value: function hidden() {
1275
- return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
1276
+ return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput);
1276
1277
  }
1277
1278
  }, {
1278
1279
  key: "executeSerialize",
@@ -1352,8 +1353,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1352
1353
  }, {
1353
1354
  key: "render",
1354
1355
  value: function render(input) {
1355
- this.renderInput = input;
1356
- return this;
1356
+ return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, input);
1357
1357
  }
1358
1358
  }]);
1359
1359
  }(Schema);
@@ -2946,9 +2946,9 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2946
2946
  var isReadonly = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
2947
2947
  var isHidden = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
2948
2948
  var description = arguments.length > 8 ? arguments[8] : undefined;
2949
+ var renderInput = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : null;
2949
2950
  _classCallCheck(this, RecordSchema);
2950
2951
  _this = _callSuper(this, RecordSchema);
2951
- _defineProperty(_this, "renderInput", null);
2952
2952
  _this.item = item;
2953
2953
  _this.opt = opt;
2954
2954
  _this.customValidateFunctions = customValidateFunctions;
@@ -2958,18 +2958,19 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2958
2958
  _this.isReadonly = isReadonly;
2959
2959
  _this.isHidden = isHidden;
2960
2960
  _this.description = description;
2961
+ _this.renderInput = renderInput;
2961
2962
  return _this;
2962
2963
  }
2963
2964
  _inherits(RecordSchema, _Schema);
2964
2965
  return _createClass(RecordSchema, [{
2965
2966
  key: "describe",
2966
2967
  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);
2968
+ 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.renderInput);
2968
2969
  }
2969
2970
  }, {
2970
2971
  key: "validate",
2971
2972
  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);
2973
+ 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.renderInput);
2973
2974
  }
2974
2975
  }, {
2975
2976
  key: "executeValidate",
@@ -3152,6 +3153,13 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3152
3153
  value: key
3153
3154
  }]);
3154
3155
  }
3156
+ // Local path in a remote gallery: needs to be uploaded to remote.
3157
+ var uploadRemoteFix = type === "images" ? "images:upload-remote" : "files:upload-remote";
3158
+ return _defineProperty({}, path, [{
3159
+ message: "Expected a remote ".concat(type === "images" ? "image" : "file", ", but got a local path. Use Val tooling (CLI --fix, VS Code extension, or Val Studio) to upload it. Got: ").concat(key),
3160
+ value: key,
3161
+ fixes: [uploadRemoteFix]
3162
+ }]);
3155
3163
  } else {
3156
3164
  // When remote is disabled, only accept local paths
3157
3165
  if (isRemoteUrl) {
@@ -3318,29 +3326,29 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3318
3326
  }, {
3319
3327
  key: "nullable",
3320
3328
  value: function nullable() {
3321
- return new RecordSchema(this.item, true, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description);
3329
+ return new RecordSchema(this.item, true, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.renderInput);
3322
3330
  }
3323
3331
  }, {
3324
3332
  key: "readonly",
3325
3333
  value: function readonly() {
3326
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, true, this.isHidden, this.description);
3334
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, true, this.isHidden, this.description, this.renderInput);
3327
3335
  }
3328
3336
  }, {
3329
3337
  key: "hidden",
3330
3338
  value: function hidden() {
3331
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, true, this.description);
3339
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, true, this.description, this.renderInput);
3332
3340
  }
3333
3341
  }, {
3334
3342
  key: "router",
3335
3343
  value: function router(_router) {
3336
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description);
3344
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.renderInput);
3337
3345
  }
3338
3346
  }, {
3339
3347
  key: "remote",
3340
3348
  value: function remote() {
3341
3349
  return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions ? _objectSpread2(_objectSpread2({}, this.mediaOptions), {}, {
3342
3350
  remote: true
3343
- }) : undefined, this.isReadonly, this.isHidden, this.description);
3351
+ }) : undefined, this.isReadonly, this.isHidden, this.description, this.renderInput);
3344
3352
  }
3345
3353
  }, {
3346
3354
  key: "getRouterValidations",
@@ -3445,10 +3453,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3445
3453
  data: {
3446
3454
  layout: "list",
3447
3455
  parent: "record",
3448
- items: Object.entries(src).map(function (_ref13) {
3449
- var _ref14 = _slicedToArray(_ref13, 2),
3450
- key = _ref14[0],
3451
- val = _ref14[1];
3456
+ items: Object.entries(src).map(function (_ref14) {
3457
+ var _ref15 = _slicedToArray(_ref14, 2),
3458
+ key = _ref15[0],
3459
+ val = _ref15[1];
3452
3460
  // NB NB: display is actually defined by the user
3453
3461
  var _prepare = prepare({
3454
3462
  key: key,
@@ -3477,11 +3485,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3477
3485
  }, {
3478
3486
  key: "render",
3479
3487
  value: function render(input) {
3480
- this.renderInput = {
3488
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, {
3481
3489
  layout: input.as,
3482
3490
  select: input.select
3483
- };
3484
- return this;
3491
+ });
3485
3492
  }
3486
3493
  }]);
3487
3494
  }(Schema);
@@ -5153,24 +5160,6 @@ function modules(config, modules) {
5153
5160
  };
5154
5161
  }
5155
5162
 
5156
- function _regeneratorValues(e) {
5157
- if (null != e) {
5158
- var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"],
5159
- r = 0;
5160
- if (t) return t.call(e);
5161
- if ("function" == typeof e.next) return e;
5162
- if (!isNaN(e.length)) return {
5163
- next: function () {
5164
- return e && r >= e.length && (e = void 0), {
5165
- value: e && e[r++],
5166
- done: !e
5167
- };
5168
- }
5169
- };
5170
- }
5171
- throw new TypeError(typeof e + " is not iterable");
5172
- }
5173
-
5174
5163
  function _regeneratorDefine(e, r, n, t) {
5175
5164
  var i = Object.defineProperty;
5176
5165
  try {
@@ -5640,10 +5629,11 @@ var getSHA256Hash = function getSHA256Hash(bits) {
5640
5629
  return createHash().update(bits).digest("hex");
5641
5630
  };
5642
5631
 
5643
- // Lazily constructed: this module is also evaluated inside the QuickJS
5644
- // sandbox (when user val modules import @valbuild/core), and that sandbox
5645
- // has no `TextEncoder` global. `hash()` is never called from inside the
5646
- // sandbox, so deferring construction avoids a ReferenceError at import time.
5632
+ // Lazily constructed: this module is also evaluated inside the `vm` sandbox
5633
+ // used by loadValModules (when user val modules import @valbuild/core), and
5634
+ // that sandbox has no `TextEncoder` global. `hash()` is never called from
5635
+ // inside the sandbox, so deferring construction avoids a ReferenceError at
5636
+ // import time.
5647
5637
  var textEncoder;
5648
5638
  function getTextEncoder() {
5649
5639
  if (!textEncoder) {
@@ -5651,6 +5641,29 @@ function getTextEncoder() {
5651
5641
  }
5652
5642
  return textEncoder;
5653
5643
  }
5644
+ function errorMessage(e) {
5645
+ // NOT `e instanceof Error`. Val modules are evaluated inside a `node:vm`
5646
+ // context, so an error thrown from inside the sandbox is built from THAT
5647
+ // realm's Error constructor and fails the instanceof check - and
5648
+ // JSON.stringify flattens it to "{}", throwing away the only useful part.
5649
+ // Duck-type the message instead (the same reason the schema check below
5650
+ // avoids `instanceof Schema`).
5651
+ if (_typeof(e) === "object" && e !== null && "message" in e) {
5652
+ var message = e.message;
5653
+ if (typeof message === "string") {
5654
+ return message;
5655
+ }
5656
+ }
5657
+ if (typeof e === "string") {
5658
+ return e;
5659
+ }
5660
+ try {
5661
+ var _JSON$stringify;
5662
+ return (_JSON$stringify = JSON.stringify(e)) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : String(e);
5663
+ } catch (_unused) {
5664
+ return String(e);
5665
+ }
5666
+ }
5654
5667
  function hash(input) {
5655
5668
  if (_typeof(input) === "object") {
5656
5669
  return hashObject(input);
@@ -5705,127 +5718,159 @@ function extractValModules(_x) {
5705
5718
  }
5706
5719
  function _extractValModules() {
5707
5720
  _extractValModules = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(valModules) {
5708
- var moduleErrors, addModuleError, sources, schemas, serializedSchemas, configSha, sourcesSha, baseSha, schemaSha, _loop, _ret, moduleIdx;
5709
- return _regenerator().w(function (_context2) {
5710
- while (1) switch (_context2.n) {
5721
+ var moduleErrors, addModuleError, sources, schemas, serializedSchemas, configSha, sourcesSha, baseSha, schemaSha, moduleIdx, module, at, value, path, schema, source, serializedSchema, pathM, _t, _t2;
5722
+ return _regenerator().w(function (_context) {
5723
+ while (1) switch (_context.p = _context.n) {
5711
5724
  case 0:
5712
- moduleErrors = [];
5713
- addModuleError = function addModuleError(message, index, path) {
5714
- moduleErrors[index] = {
5725
+ moduleErrors = []; // NOTE: push (not index assignment) - a sparse array makes consumers that
5726
+ // use Array.prototype.find (which visits holes) crash on undefined entries.
5727
+ addModuleError = function addModuleError(message, path) {
5728
+ moduleErrors.push({
5715
5729
  message: message,
5716
5730
  path: path
5717
- };
5731
+ });
5718
5732
  };
5719
5733
  sources = {};
5720
5734
  schemas = {};
5721
5735
  serializedSchemas = {};
5722
5736
  configSha = hash(JSON.stringify(valModules.config));
5723
5737
  sourcesSha = "";
5724
- baseSha = configSha;
5725
- schemaSha = configSha;
5726
- _loop = /*#__PURE__*/_regenerator().m(function _loop(moduleIdx) {
5727
- var module;
5728
- return _regenerator().w(function (_context) {
5729
- while (1) switch (_context.n) {
5730
- case 0:
5731
- module = valModules.modules[moduleIdx];
5732
- if (module.def) {
5733
- _context.n = 1;
5734
- break;
5735
- }
5736
- addModuleError("val.modules is missing 'def' property", moduleIdx);
5737
- return _context.a(2, 0);
5738
- case 1:
5739
- if (!(typeof module.def !== "function")) {
5740
- _context.n = 2;
5741
- break;
5742
- }
5743
- addModuleError("val.modules 'def' property is not a function", moduleIdx);
5744
- return _context.a(2, 0);
5745
- case 2:
5746
- _context.n = 3;
5747
- return module.def().then(function (value) {
5748
- if (!value) {
5749
- addModuleError("val.modules 'def' did not return a value", moduleIdx);
5750
- return;
5751
- }
5752
- if (!value["default"]) {
5753
- addModuleError("val.modules 'def' did not return a default export", moduleIdx);
5754
- return;
5755
- }
5756
- var path = getValPath(value["default"]);
5757
- if (path === undefined) {
5758
- addModuleError("path is undefined", moduleIdx);
5759
- return;
5760
- }
5761
- var schema = getSchema(value["default"]);
5762
- if (schema === undefined) {
5763
- addModuleError("schema in path '".concat(path, "' is undefined"), moduleIdx, path);
5764
- return;
5765
- }
5766
- // Avoid `schema instanceof Schema` — the editor SPA and the host
5767
- // Next.js bundle each ship their own copy of @valbuild/core, so the
5768
- // `Schema` class identity differs between them and the instanceof
5769
- // check would fail for cross-bundle modules. The executeSerialize
5770
- // check below is the actual contract we depend on.
5771
- if (typeof schema["executeSerialize"] !== "function") {
5772
- addModuleError("schema.serialize in path '".concat(path, "' is not a function"), moduleIdx, path);
5773
- return;
5774
- }
5775
- var source = getSource(value["default"]);
5776
- if (source === undefined) {
5777
- addModuleError("source in ".concat(path, " is undefined"), moduleIdx, path);
5778
- return;
5779
- }
5780
- var serializedSchema;
5781
- try {
5782
- serializedSchema = schema["executeSerialize"]();
5783
- } catch (e) {
5784
- var message = e instanceof Error ? e.message : JSON.stringify(e);
5785
- addModuleError("Could not serialize module: '".concat(path, "'. Error: ").concat(message), moduleIdx, path);
5786
- return;
5787
- }
5788
- var pathM = path;
5789
- sources[pathM] = source;
5790
- schemas[pathM] = schema;
5791
- serializedSchemas[pathM] = serializedSchema;
5792
- sourcesSha = hash(sourcesSha + JSON.stringify({
5793
- path: path,
5794
- source: source
5795
- }));
5796
- baseSha = hash(baseSha + JSON.stringify({
5797
- path: path,
5798
- schema: serializedSchema,
5799
- source: source,
5800
- modulesErrors: moduleErrors
5801
- }));
5802
- schemaSha = hash(schemaSha + JSON.stringify(serializedSchema));
5803
- });
5804
- case 3:
5805
- return _context.a(2);
5806
- }
5807
- }, _loop);
5808
- });
5738
+ baseSha = configSha; // NOTE: schemaSha is deliberately NOT seeded with configSha. It is compared
5739
+ // across bundles (the server extracts from the Node bundle, the editor SPA
5740
+ // from the browser bundle) to detect that a new version has been deployed.
5741
+ // The config contains values that are not part of the schema and that differ
5742
+ // between those two bundles - most notably the documented
5743
+ // `gitCommit: process.env.VERCEL_GIT_COMMIT_SHA` / `gitBranch`, which are
5744
+ // server-only env vars and therefore `undefined` in the browser. Seeding with
5745
+ // them made the two sides disagree on every production load.
5746
+ schemaSha = "";
5809
5747
  moduleIdx = 0;
5810
5748
  case 1:
5811
5749
  if (!(moduleIdx < valModules.modules.length)) {
5812
- _context2.n = 4;
5750
+ _context.n = 18;
5751
+ break;
5752
+ }
5753
+ module = valModules.modules[moduleIdx]; // NOTE: `at index N` refers to the module's position in the val.modules
5754
+ // array, which is all we can name when the module never loaded.
5755
+ at = "at index ".concat(moduleIdx);
5756
+ if (module.def) {
5757
+ _context.n = 2;
5813
5758
  break;
5814
5759
  }
5815
- return _context2.d(_regeneratorValues(_loop(moduleIdx)), 2);
5760
+ addModuleError("val.modules ".concat(at, " is missing 'def' property"));
5761
+ return _context.a(3, 17);
5816
5762
  case 2:
5817
- _ret = _context2.v;
5818
- if (!(_ret === 0)) {
5819
- _context2.n = 3;
5763
+ if (!(typeof module.def !== "function")) {
5764
+ _context.n = 3;
5820
5765
  break;
5821
5766
  }
5822
- return _context2.a(3, 3);
5767
+ addModuleError("val.modules ".concat(at, " 'def' property is not a function"));
5768
+ return _context.a(3, 17);
5823
5769
  case 3:
5770
+ value = void 0;
5771
+ _context.p = 4;
5772
+ _context.n = 5;
5773
+ return module.def();
5774
+ case 5:
5775
+ value = _context.v;
5776
+ _context.n = 7;
5777
+ break;
5778
+ case 6:
5779
+ _context.p = 6;
5780
+ _t = _context.v;
5781
+ // A module that throws while importing (a syntax error, a throwing
5782
+ // top-level statement, a missing file) has to be reported like any other
5783
+ // module error. Letting it reject aborts the whole extraction, which on
5784
+ // the server means ValOps.initSources rejects and /stat, /schema and
5785
+ // /sources/~ all fail opaquely instead of naming the broken module.
5786
+ addModuleError("val.modules 'def' ".concat(at, " could not be loaded. Error: ").concat(errorMessage(_t)));
5787
+ return _context.a(3, 17);
5788
+ case 7:
5789
+ if (value) {
5790
+ _context.n = 8;
5791
+ break;
5792
+ }
5793
+ addModuleError("val.modules 'def' ".concat(at, " did not return a value"));
5794
+ return _context.a(3, 17);
5795
+ case 8:
5796
+ if (value["default"]) {
5797
+ _context.n = 9;
5798
+ break;
5799
+ }
5800
+ addModuleError("val.modules 'def' ".concat(at, " did not return a default export"));
5801
+ return _context.a(3, 17);
5802
+ case 9:
5803
+ path = getValPath(value["default"]);
5804
+ if (!(path === undefined)) {
5805
+ _context.n = 10;
5806
+ break;
5807
+ }
5808
+ addModuleError("path is undefined for val.modules 'def' ".concat(at));
5809
+ return _context.a(3, 17);
5810
+ case 10:
5811
+ schema = getSchema(value["default"]);
5812
+ if (!(schema === undefined)) {
5813
+ _context.n = 11;
5814
+ break;
5815
+ }
5816
+ addModuleError("schema in path '".concat(path, "' is undefined"), path);
5817
+ return _context.a(3, 17);
5818
+ case 11:
5819
+ if (!(typeof schema["executeSerialize"] !== "function")) {
5820
+ _context.n = 12;
5821
+ break;
5822
+ }
5823
+ addModuleError("schema.serialize in path '".concat(path, "' is not a function"), path);
5824
+ return _context.a(3, 17);
5825
+ case 12:
5826
+ source = getSource(value["default"]);
5827
+ if (!(source === undefined)) {
5828
+ _context.n = 13;
5829
+ break;
5830
+ }
5831
+ addModuleError("source in ".concat(path, " is undefined"), path);
5832
+ return _context.a(3, 17);
5833
+ case 13:
5834
+ serializedSchema = void 0;
5835
+ _context.p = 14;
5836
+ serializedSchema = schema["executeSerialize"]();
5837
+ _context.n = 16;
5838
+ break;
5839
+ case 15:
5840
+ _context.p = 15;
5841
+ _t2 = _context.v;
5842
+ addModuleError("Could not serialize module: '".concat(path, "'. Error: ").concat(errorMessage(_t2)), path);
5843
+ return _context.a(3, 17);
5844
+ case 16:
5845
+ pathM = path;
5846
+ sources[pathM] = source;
5847
+ schemas[pathM] = schema;
5848
+ serializedSchemas[pathM] = serializedSchema;
5849
+ sourcesSha = hash(sourcesSha + JSON.stringify({
5850
+ path: path,
5851
+ source: source
5852
+ }));
5853
+ baseSha = hash(baseSha + JSON.stringify({
5854
+ path: path,
5855
+ schema: serializedSchema,
5856
+ source: source,
5857
+ modulesErrors: moduleErrors
5858
+ }));
5859
+ // The PATH is part of the schema set, not just the schema: renaming a
5860
+ // module while leaving its schema byte-identical still changes which paths
5861
+ // exist, and an open client keyed its schema cache by the old path. Hashing
5862
+ // the schema alone left this SHA unchanged, so with no commitSha to fall
5863
+ // back on the client never refetched /schema.
5864
+ schemaSha = hash(schemaSha + JSON.stringify({
5865
+ path: path,
5866
+ schema: serializedSchema
5867
+ }));
5868
+ case 17:
5824
5869
  moduleIdx++;
5825
- _context2.n = 1;
5870
+ _context.n = 1;
5826
5871
  break;
5827
- case 4:
5828
- return _context2.a(2, {
5872
+ case 18:
5873
+ return _context.a(2, {
5829
5874
  sources: sources,
5830
5875
  schemas: schemas,
5831
5876
  serializedSchemas: serializedSchemas,
@@ -5836,7 +5881,7 @@ function _extractValModules() {
5836
5881
  moduleErrors: moduleErrors
5837
5882
  });
5838
5883
  }
5839
- }, _callee);
5884
+ }, _callee, null, [[14, 15], [4, 6]]);
5840
5885
  }));
5841
5886
  return _extractValModules.apply(this, arguments);
5842
5887
  }