@valbuild/core 0.99.0 → 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>>>;
@@ -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",
@@ -3325,29 +3326,29 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3325
3326
  }, {
3326
3327
  key: "nullable",
3327
3328
  value: function nullable() {
3328
- 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);
3329
3330
  }
3330
3331
  }, {
3331
3332
  key: "readonly",
3332
3333
  value: function readonly() {
3333
- 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);
3334
3335
  }
3335
3336
  }, {
3336
3337
  key: "hidden",
3337
3338
  value: function hidden() {
3338
- 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);
3339
3340
  }
3340
3341
  }, {
3341
3342
  key: "router",
3342
3343
  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);
3344
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, this.renderInput);
3344
3345
  }
3345
3346
  }, {
3346
3347
  key: "remote",
3347
3348
  value: function remote() {
3348
3349
  return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions ? _objectSpread2(_objectSpread2({}, this.mediaOptions), {}, {
3349
3350
  remote: true
3350
- }) : undefined, this.isReadonly, this.isHidden, this.description);
3351
+ }) : undefined, this.isReadonly, this.isHidden, this.description, this.renderInput);
3351
3352
  }
3352
3353
  }, {
3353
3354
  key: "getRouterValidations",
@@ -3484,11 +3485,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
3484
3485
  }, {
3485
3486
  key: "render",
3486
3487
  value: function render(input) {
3487
- this.renderInput = {
3488
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, this.isHidden, this.description, {
3488
3489
  layout: input.as,
3489
3490
  select: input.select
3490
- };
3491
- return this;
3491
+ });
3492
3492
  }
3493
3493
  }]);
3494
3494
  }(Schema);
@@ -5160,24 +5160,6 @@ function modules(config, modules) {
5160
5160
  };
5161
5161
  }
5162
5162
 
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
5163
  function _regeneratorDefine(e, r, n, t) {
5182
5164
  var i = Object.defineProperty;
5183
5165
  try {
@@ -5659,6 +5641,29 @@ function getTextEncoder() {
5659
5641
  }
5660
5642
  return textEncoder;
5661
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
+ }
5662
5667
  function hash(input) {
5663
5668
  if (_typeof(input) === "object") {
5664
5669
  return hashObject(input);
@@ -5713,127 +5718,159 @@ function extractValModules(_x) {
5713
5718
  }
5714
5719
  function _extractValModules() {
5715
5720
  _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) {
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) {
5719
5724
  case 0:
5720
- moduleErrors = [];
5721
- addModuleError = function addModuleError(message, index, path) {
5722
- 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({
5723
5729
  message: message,
5724
5730
  path: path
5725
- };
5731
+ });
5726
5732
  };
5727
5733
  sources = {};
5728
5734
  schemas = {};
5729
5735
  serializedSchemas = {};
5730
5736
  configSha = hash(JSON.stringify(valModules.config));
5731
5737
  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
- });
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 = "";
5817
5747
  moduleIdx = 0;
5818
5748
  case 1:
5819
5749
  if (!(moduleIdx < valModules.modules.length)) {
5820
- _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;
5821
5758
  break;
5822
5759
  }
5823
- return _context2.d(_regeneratorValues(_loop(moduleIdx)), 2);
5760
+ addModuleError("val.modules ".concat(at, " is missing 'def' property"));
5761
+ return _context.a(3, 17);
5824
5762
  case 2:
5825
- _ret = _context2.v;
5826
- if (!(_ret === 0)) {
5827
- _context2.n = 3;
5763
+ if (!(typeof module.def !== "function")) {
5764
+ _context.n = 3;
5828
5765
  break;
5829
5766
  }
5830
- return _context2.a(3, 3);
5767
+ addModuleError("val.modules ".concat(at, " 'def' property is not a function"));
5768
+ return _context.a(3, 17);
5831
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:
5832
5869
  moduleIdx++;
5833
- _context2.n = 1;
5870
+ _context.n = 1;
5834
5871
  break;
5835
- case 4:
5836
- return _context2.a(2, {
5872
+ case 18:
5873
+ return _context.a(2, {
5837
5874
  sources: sources,
5838
5875
  schemas: schemas,
5839
5876
  serializedSchemas: serializedSchemas,
@@ -5844,7 +5881,7 @@ function _extractValModules() {
5844
5881
  moduleErrors: moduleErrors
5845
5882
  });
5846
5883
  }
5847
- }, _callee);
5884
+ }, _callee, null, [[14, 15], [4, 6]]);
5848
5885
  }));
5849
5886
  return _extractValModules.apply(this, arguments);
5850
5887
  }