@valbuild/core 0.127.0 → 0.128.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.
@@ -3528,7 +3528,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
3528
3528
  *
3529
3529
  * @example
3530
3530
  * const schema = s
3531
- * .image({ accept: "image/webp", directory: "/public/val/images" })
3531
+ * .image({ accept: "image/webp", dir: "/public/val/images" })
3532
3532
  * .remote();
3533
3533
  * export default c.define("/example.val.ts", schema, {
3534
3534
  * path: "https://remote.val.build/file/p/my-project/b/01/v/1.0.0/h/8f2a1c/f/3b9d70/p/public/val/images/example.webp",
@@ -3707,6 +3707,10 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
3707
3707
  /**
3708
3708
  * The entries of the gallery this field points at, or null when it is a
3709
3709
  * standalone field.
3710
+ *
3711
+ * `AltSource` rather than a specific alt type: a field never reads an entry's
3712
+ * alt — it carries its own — so it only needs the entry keys and the
3713
+ * dimensions, and a gallery of any alt shape can back it.
3710
3714
  */
3711
3715
  }, {
3712
3716
  key: "galleryEntries",
@@ -5461,9 +5465,9 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5461
5465
  if (this.mediaOptions) {
5462
5466
  var checkFix = this.mediaOptions.type === "images" ? "images:check-unique-folder" : "files:check-unique-folder";
5463
5467
  var uniqueCheckError = {
5464
- message: "Gallery directory '".concat(this.mediaOptions.directory, "' must be unique across all galleries"),
5468
+ message: "Gallery directory '".concat(this.mediaOptions.dir, "' must be unique across all galleries"),
5465
5469
  value: {
5466
- directory: this.mediaOptions.directory,
5470
+ dir: this.mediaOptions.dir,
5467
5471
  type: this.mediaOptions.type
5468
5472
  },
5469
5473
  fixes: [checkFix]
@@ -5479,9 +5483,9 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5479
5483
  }
5480
5484
  var allFilesCheckFix = this.mediaOptions.type === "images" ? "images:check-all-files" : "files:check-all-files";
5481
5485
  var allFilesCheckError = {
5482
- message: "Directory '".concat(this.mediaOptions.directory, "' may have files not tracked by this gallery"),
5486
+ message: "Directory '".concat(this.mediaOptions.dir, "' may have files not tracked by this gallery"),
5483
5487
  value: {
5484
- directory: this.mediaOptions.directory,
5488
+ dir: this.mediaOptions.dir,
5485
5489
  type: this.mediaOptions.type
5486
5490
  },
5487
5491
  fixes: [allFilesCheckFix]
@@ -5642,13 +5646,13 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5642
5646
  return false;
5643
5647
  }
5644
5648
  var _this$mediaOptions = this.mediaOptions,
5645
- directory = _this$mediaOptions.directory,
5649
+ dir = _this$mediaOptions.dir,
5646
5650
  isRemote = _this$mediaOptions.remote,
5647
5651
  type = _this$mediaOptions.type;
5648
5652
  var mediaLabel = type === "images" ? "images" : "files";
5649
5653
  var checkRemoteFix = type === "images" ? "images:check-remote" : "files:check-remote";
5650
5654
  var isRemoteUrl = this.isRemoteUrl(key);
5651
- var isLocalPath = key === directory || key.startsWith(directory + "/");
5655
+ var isLocalPath = key === dir || key.startsWith(dir + "/");
5652
5656
  if (isRemote) {
5653
5657
  // When remote is enabled, accept either remote URLs or local paths
5654
5658
  if (isRemoteUrl) {
@@ -5663,9 +5667,9 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5663
5667
  }
5664
5668
  // Check that the file path in the remote URL matches our directory constraint
5665
5669
  var remotePath = "/" + remoteResult.filePath;
5666
- if (remotePath !== directory && !remotePath.startsWith(directory + "/")) {
5670
+ if (remotePath !== dir && !remotePath.startsWith(dir + "/")) {
5667
5671
  return _defineProperty({}, path, [{
5668
- message: "Remote file path '".concat(remotePath, "' is not in expected directory '").concat(directory, "'. Use Val tooling to upload ").concat(mediaLabel, " to the correct directory."),
5672
+ message: "Remote file path '".concat(remotePath, "' is not in expected directory '").concat(dir, "'. Use Val tooling to upload ").concat(mediaLabel, " to the correct directory."),
5669
5673
  value: key,
5670
5674
  fixes: [checkRemoteFix]
5671
5675
  }]);
@@ -5674,7 +5678,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5674
5678
  }
5675
5679
  if (!isLocalPath) {
5676
5680
  return _defineProperty({}, path, [{
5677
- message: "Expected a remote URL (https://...) or a local path starting with ".concat(directory, "/. Got: ").concat(key),
5681
+ message: "Expected a remote URL (https://...) or a local path starting with ".concat(dir, "/. Got: ").concat(key),
5678
5682
  value: key
5679
5683
  }]);
5680
5684
  }
@@ -5696,7 +5700,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5696
5700
  }
5697
5701
  if (!isLocalPath) {
5698
5702
  return _defineProperty({}, path, [{
5699
- message: "File path must be within the ".concat(directory, "/ directory. Got: ").concat(key),
5703
+ message: "File path must be within the ".concat(dir, "/ directory. Got: ").concat(key),
5700
5704
  value: key
5701
5705
  }]);
5702
5706
  }
@@ -5892,7 +5896,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5892
5896
  * Allow the files in this gallery to be stored on Val's remote content host
5893
5897
  * instead of in your repository.
5894
5898
  *
5895
- * For `s.images()` and `s.files()`, which are records of media. Remote is off
5899
+ * For `s.imageset()` and `s.fileset()`, which are records of media. Remote is off
5896
5900
  * until this is called.
5897
5901
  *
5898
5902
  * Each entry is then keyed by its URL on the content host rather than by a
@@ -5901,7 +5905,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5901
5905
  * upload it and rewrite the key.
5902
5906
  *
5903
5907
  * @example
5904
- * const schema = s.images({ directory: "/public/val/images" }).remote();
5908
+ * const schema = s.imageset({ dir: "/public/val/images" }).remote();
5905
5909
  * export default c.define("/content/images.val.ts", schema, {
5906
5910
  * "https://remote.val.build/file/p/my-project/b/01/v/1.0.0/h/8f2a1c/f/3b9d70/p/public/val/images/hero.webp":
5907
5911
  * {
@@ -5927,7 +5931,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5927
5931
  * which lets the runtime, the Studio and validation work one entry at a time
5928
5932
  * so a record/router can scale to many thousands of entries.
5929
5933
  *
5930
- * Not supported on image/file galleries (`s.images()` / `s.files()`).
5934
+ * Not supported on image/file galleries (`s.imageset()` / `s.fileset()`).
5931
5935
  *
5932
5936
  * Only supported on a module's ROOT record/router — a `.jsonValues()` record
5933
5937
  * nested inside an object/array/record is rejected at startup with a module
@@ -5952,7 +5956,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5952
5956
  key: "jsonValues",
5953
5957
  value: function jsonValues() {
5954
5958
  if (this.mediaOptions) {
5955
- throw new Error(".jsonValues() cannot be used with image/file galleries (s.images()/s.files())");
5959
+ throw new Error(".jsonValues() cannot be used with image/file galleries (s.imageset()/s.fileset())");
5956
5960
  }
5957
5961
  if (this.customValidateFunctions.length > 0) {
5958
5962
  // `.jsonValues()` changes the source shape to JsonSource entries, so a
@@ -5981,7 +5985,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5981
5985
  * bucket — instead of in the module.
5982
5986
  *
5983
5987
  * Available on every record-derived schema, which is `s.record()`,
5984
- * `s.router()`, `s.images()` and `s.files()` alike: a router is a
5988
+ * `s.router()`, `s.imageset()` and `s.fileset()` alike: a router is a
5985
5989
  * `RecordSchema` with a `ValRouter`, a gallery one with media options, so all
5986
5990
  * four get external storage from this one method.
5987
5991
  *
@@ -6136,7 +6140,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
6136
6140
  if (this.mediaOptions) {
6137
6141
  result.mediaType = this.mediaOptions.type;
6138
6142
  result.accept = this.mediaOptions.accept;
6139
- result.directory = this.mediaOptions.directory;
6143
+ result.dir = this.mediaOptions.dir;
6140
6144
  result.remote = this.mediaOptions.remote;
6141
6145
  if (this.mediaOptions.encode !== undefined) {
6142
6146
  result.encode = this.mediaOptions.encode;
@@ -9308,7 +9312,7 @@ function file(options) {
9308
9312
  }
9309
9313
 
9310
9314
  /**
9311
- * Options for s.files()
9315
+ * Options for s.fileset()
9312
9316
  */
9313
9317
 
9314
9318
  /**
@@ -9322,9 +9326,9 @@ function file(options) {
9322
9326
  *
9323
9327
  * @example
9324
9328
  * ```typescript
9325
- * const schema = s.files({
9329
+ * const schema = s.fileset({
9326
9330
  * accept: "application/pdf",
9327
- * directory: "/public/val/documents",
9331
+ * dir: "/public/val/documents",
9328
9332
  * });
9329
9333
  * export default c.define("/content/documents.val.ts", schema, {
9330
9334
  * "/public/val/documents/report.pdf": {
@@ -9333,15 +9337,15 @@ function file(options) {
9333
9337
  * });
9334
9338
  * ```
9335
9339
  */
9336
- var files = function files(options) {
9337
- var directory = options.directory;
9340
+ var fileset = function fileset(options) {
9341
+ var dir = options.dir;
9338
9342
  var itemSchema = new ObjectSchema({
9339
9343
  mimeType: new StringSchema({}, false)
9340
9344
  }, false);
9341
9345
  return new RecordSchema(itemSchema, false, [], null, null, {
9342
9346
  type: "files",
9343
9347
  accept: options.accept,
9344
- directory: directory,
9348
+ dir: dir,
9345
9349
  remote: false
9346
9350
  });
9347
9351
  };
@@ -10972,14 +10976,37 @@ function router(router, keyOrItem, maybeItem) {
10972
10976
  */
10973
10977
 
10974
10978
  /**
10975
- * Options for s.images()
10979
+ * What an entry's `alt` holds, for a given `alt` schema.
10980
+ *
10981
+ * This is the schema's own source type, not a second list that has to be kept
10982
+ * in step with `AltSchema`: `s.string()` gives `string`, `s.string().nullable()`
10983
+ * gives `string | null`, and `s.record(s.string())` gives
10984
+ * `Record<string, string>`.
10985
+ */
10986
+
10987
+ /** Every `alt` value any `AltSchema` can produce. */
10988
+
10989
+ /**
10990
+ * Options for s.imageset()
10976
10991
  */
10977
10992
 
10978
10993
  /**
10979
- * Metadata for an image entry in the images record
10994
+ * `alt` is optional only when it is the default schema.
10995
+ *
10996
+ * Naming a different `Alt` and then leaving `alt` out would make the fallback
10997
+ * in `imageset()` a lie — `Alt` would say `s.string()` while the value was a
10998
+ * nullable one. Requiring it in that case is what makes the fallback sound:
10999
+ * the branch that uses it is reachable only when `Alt` IS the default.
10980
11000
  */
10981
11001
 
10982
- // Item schema types for images (alt simplified to string | null for typing)
11002
+ /**
11003
+ * Metadata for an image entry in the images record.
11004
+ *
11005
+ * `alt` follows the schema's `alt` option, so it defaults to `string | null`
11006
+ * and becomes `string` under `s.string()` or `Record<string, string>` under
11007
+ * `s.record(s.string())`. Write `ImagesetEntryMetadata<AltSource>` where a
11008
+ * gallery of any alt shape is acceptable.
11009
+ */
10983
11010
 
10984
11011
  /**
10985
11012
  * Define a collection of images.
@@ -10990,9 +11017,9 @@ function router(router, keyOrItem, maybeItem) {
10990
11017
  *
10991
11018
  * @example
10992
11019
  * ```typescript
10993
- * const schema = s.images({
11020
+ * const schema = s.imageset({
10994
11021
  * accept: "image/webp",
10995
- * directory: "/public/val/images",
11022
+ * dir: "/public/val/images",
10996
11023
  * alt: s.string().minLength(4),
10997
11024
  * });
10998
11025
  * export default c.define("/content/images.val.ts", schema, {
@@ -11005,9 +11032,18 @@ function router(router, keyOrItem, maybeItem) {
11005
11032
  * });
11006
11033
  * ```
11007
11034
  */
11008
- var images = function images(options) {
11035
+ var imageset = function imageset(options) {
11009
11036
  var _options$alt, _options$accept;
11010
- var directory = options.directory;
11037
+ var dir = options.dir;
11038
+ // `options.alt` is `Alt | undefined`, and the fallback is exactly the schema
11039
+ // `Alt` defaults to when `alt` is omitted. TypeScript will not narrow a type
11040
+ // parameter from the absence of a value, so it cannot see that the two agree,
11041
+ // and the fallback is asserted here.
11042
+ //
11043
+ // Sound, not merely convenient: `ImagesetAltOption` makes `alt` REQUIRED
11044
+ // unless `Alt` is the default, so this branch is unreachable for any other
11045
+ // `Alt`. The one assertion in this file, and it replaces the wider one that
11046
+ // used to sit on the ObjectSchema below.
11011
11047
  var altSchema = (_options$alt = options.alt) !== null && _options$alt !== void 0 ? _options$alt : string().nullable();
11012
11048
  var itemSchema = new ObjectSchema({
11013
11049
  width: new NumberSchema(undefined, false),
@@ -11018,7 +11054,7 @@ var images = function images(options) {
11018
11054
  return new RecordSchema(itemSchema, false, [], null, null, {
11019
11055
  type: "images",
11020
11056
  accept: (_options$accept = options.accept) !== null && _options$accept !== void 0 ? _options$accept : "image/*",
11021
- directory: directory,
11057
+ dir: dir,
11022
11058
  remote: false,
11023
11059
  altSchema: altSchema,
11024
11060
  encode: options.encode
@@ -11050,7 +11086,7 @@ function initSchema() {
11050
11086
  keyOf: keyOf,
11051
11087
  record: record,
11052
11088
  file: file,
11053
- files: files,
11089
+ fileset: fileset,
11054
11090
  date: date,
11055
11091
  datetime: datetime,
11056
11092
  color: color,
@@ -11058,7 +11094,7 @@ function initSchema() {
11058
11094
  locale: locale,
11059
11095
  route: route,
11060
11096
  router: router,
11061
- images: images,
11097
+ imageset: imageset,
11062
11098
  settings: settings
11063
11099
  // i18n: i18n(locales),
11064
11100
  };
@@ -11900,7 +11936,7 @@ function _extractValModules() {
11900
11936
  * The one answer to that question. There used to be two — `hasRemoteFileSchema`
11901
11937
  * in the server, gating whether `/save` demands remote credentials, and
11902
11938
  * `findRequiredRemoteFiles` in the Studio, gating the `/remote/settings` fetch —
11903
- * and they disagreed about `s.images({ ... }).remote()`: the Studio's version
11939
+ * and they disagreed about `s.imageset({ ... }).remote()`: the Studio's version
11904
11940
  * counted a remote media record, the server's did not, because a media
11905
11941
  * collection serializes as a `record` of metadata rather than as an image
11906
11942
  * schema.
@@ -11940,7 +11976,7 @@ function hasRemoteFileSchema(schema) {
11940
11976
  return hasRemoteFileSchema(schema.item);
11941
11977
  } else if (schema.type === "record") {
11942
11978
  /**
11943
- * A media collection — `s.images()` / `s.files()` — is the case both of the
11979
+ * A media collection — `s.imageset()` / `s.fileset()` — is the case both of the
11944
11980
  * old functions were written around, and the one they disagreed on.
11945
11981
  *
11946
11982
  * It has no file or image schema inside it to find: `item` is an object of
@@ -12000,8 +12036,8 @@ function hasRemoteFileSchema(schema) {
12000
12036
  *
12001
12037
  * It is a walk over the SERIALIZED schema for the reasons given above, and for
12002
12038
  * one more that is specific to this question: the two cases most likely to be
12003
- * missed are invisible to a value type. A media collection (`s.images()` /
12004
- * `s.files()`) serializes as a record of metadata with no image schema inside
12039
+ * missed are invisible to a value type. A media collection (`s.imageset()` /
12040
+ * `s.fileset()`) serializes as a record of metadata with no image schema inside
12005
12041
  * it, and a richtext inline image lives in a constructor argument. A check
12006
12042
  * written against the item TYPE would silently pass both — and the gallery case
12007
12043
  * already has a data-loss incident attached to it (see above).
@@ -12384,7 +12420,7 @@ function deserializeSchema(serialized) {
12384
12420
  return schema;
12385
12421
  }
12386
12422
  function deserializeSchemaImpl(serialized) {
12387
- var _serialized$options, _serialized$options2, _serialized$render, _serialized$multiline, _serialized$render2, _serialized$render3, _serialized$render4, _serialized$render5, _serialized$render6, _serialized$render7, _serialized$render8, _serialized$accept, _serialized$directory, _serialized$remote, _serialized$jsonValue, _serialized$render0, _serialized$external, _serialized$render1, _serialized$render12, _serialized$render13, _serialized$render14, _serialized$render15, _serialized$render16, _serialized$render17;
12423
+ var _serialized$options, _serialized$options2, _serialized$render, _serialized$multiline, _serialized$render2, _serialized$render3, _serialized$render4, _serialized$render5, _serialized$render6, _serialized$render7, _serialized$render8, _serialized$accept, _serialized$dir, _serialized$remote, _serialized$jsonValue, _serialized$render0, _serialized$external, _serialized$render1, _serialized$render12, _serialized$render13, _serialized$render14, _serialized$render15, _serialized$render16, _serialized$render17;
12388
12424
  switch (serialized.type) {
12389
12425
  case "string":
12390
12426
  return new StringSchema(_objectSpread2(_objectSpread2({}, serialized.options), {}, {
@@ -12444,7 +12480,7 @@ function deserializeSchemaImpl(serialized) {
12444
12480
  return new RecordSchema(deserializeSchema(serialized.item), serialized.opt, [], null, serialized.key ? deserializeSchema(serialized.key) : null, serialized.mediaType ? {
12445
12481
  type: serialized.mediaType,
12446
12482
  accept: (_serialized$accept = serialized.accept) !== null && _serialized$accept !== void 0 ? _serialized$accept : "*/*",
12447
- directory: (_serialized$directory = serialized.directory) !== null && _serialized$directory !== void 0 ? _serialized$directory : "/public/val",
12483
+ dir: (_serialized$dir = serialized.dir) !== null && _serialized$dir !== void 0 ? _serialized$dir : "/public/val",
12448
12484
  remote: (_serialized$remote = serialized.remote) !== null && _serialized$remote !== void 0 ? _serialized$remote : false,
12449
12485
  altSchema: serialized.alt ? deserializeSchema(serialized.alt) : undefined
12450
12486
  } : undefined, false, false, serialized.description, (_serialized$jsonValue = serialized.jsonValues) !== null && _serialized$jsonValue !== void 0 ? _serialized$jsonValue : false,
@@ -13147,7 +13183,7 @@ function isPageRouter(routerId) {
13147
13183
 
13148
13184
  var corePackageJson = {
13149
13185
  name: "@valbuild/core",
13150
- version: "0.127.0",
13186
+ version: "0.128.0",
13151
13187
  "private": false,
13152
13188
  description: "Val - supercharged hard-coded content",
13153
13189
  repository: {