@valbuild/core 0.143.0 → 0.145.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 (31) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/declarations/src/index.d.ts +16 -4
  3. package/dist/declarations/src/initSchema.d.ts +107 -26
  4. package/dist/declarations/src/initVal.d.ts +2 -2
  5. package/dist/declarations/src/mimeType/font.d.ts +2 -2
  6. package/dist/declarations/src/render.d.ts +39 -6
  7. package/dist/declarations/src/schema/file.d.ts +4 -4
  8. package/dist/declarations/src/schema/filedir.d.ts +83 -0
  9. package/dist/declarations/src/schema/font.d.ts +4 -4
  10. package/dist/declarations/src/schema/fontdir.d.ts +63 -0
  11. package/dist/declarations/src/schema/hasRemoteFileSchema.d.ts +3 -3
  12. package/dist/declarations/src/schema/image.d.ts +4 -4
  13. package/dist/declarations/src/schema/{imageset.d.ts → imagedir.d.ts} +63 -29
  14. package/dist/declarations/src/schema/number.d.ts +45 -5
  15. package/dist/declarations/src/schema/numberRules.d.ts +27 -0
  16. package/dist/declarations/src/schema/record.d.ts +17 -6
  17. package/dist/declarations/src/schema/video.d.ts +7 -7
  18. package/dist/declarations/src/schema/{videoset.d.ts → videodir.d.ts} +55 -27
  19. package/dist/declarations/src/source/media.d.ts +26 -3
  20. package/dist/{index-02a1ba06.esm.js → index-307b907e.esm.js} +601 -122
  21. package/dist/{index-46c72f01.cjs.prod.js → index-93763025.cjs.prod.js} +601 -122
  22. package/dist/{index-aac8c69c.cjs.dev.js → index-ee601322.cjs.dev.js} +601 -122
  23. package/dist/valbuild-core.cjs.dev.js +1 -1
  24. package/dist/valbuild-core.cjs.prod.js +1 -1
  25. package/dist/valbuild-core.esm.js +1 -1
  26. package/package.json +1 -1
  27. package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
  28. package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
  29. package/patch/dist/valbuild-core-patch.esm.js +2 -2
  30. package/dist/declarations/src/schema/fileset.d.ts +0 -57
  31. package/dist/declarations/src/schema/fontset.d.ts +0 -40
@@ -1,18 +1,29 @@
1
1
  import { Schema } from "./index.js";
2
- import type { SerializedRecordSchema } from "./record.js";
2
+ import type { MediaDir, SerializedRecordSchema } from "./record.js";
3
3
  import { RecordSchema } from "./record.js";
4
4
  import { ObjectSchema } from "./object.js";
5
5
  import { StringSchema } from "./string.js";
6
6
  import { NumberSchema } from "./number.js";
7
- import type { AltSchema, AltSource, AltSourceOf } from "./imageset.js";
7
+ import type { AltSchema, AltSource, AltSourceOf } from "./imagedir.js";
8
8
  import type { SerializedVideoSchema, VideoStreamOption } from "./video.js";
9
9
  import type { MediaHotspot, VideoCaptionSource, VideoPosterSource } from "../source/media.js";
10
10
  /**
11
- * Options for s.videoset()
11
+ * Options for `s.videodir(dir, options)`: everything but the directory, which
12
+ * is the first argument.
12
13
  */
13
- export type VideosetOptions<Accept extends `video/${string}`, Alt extends AltSchema = StringSchema<string | null>> = VideosetOptionsBase<Accept> & VideosetAltOption<Alt>;
14
- /** See `ImagesetAltOption`: `alt` is optional only when it is the default. */
15
- type VideosetAltOption<Alt extends AltSchema> = [
14
+ export type VideodirOptions<Accept extends `video/${string}`, Alt extends AltSchema = StringSchema<string | null>> = VideodirOptionsBase<Accept> & VideodirAltOption<Alt>;
15
+ /**
16
+ * Options for the deprecated `s.videoset(options)`, which took the directory
17
+ * as `dir`.
18
+ *
19
+ * @deprecated Use `s.videodir(dir, options)` and `VideodirOptions`.
20
+ */
21
+ export type VideosetOptions<Accept extends `video/${string}`, Alt extends AltSchema = StringSchema<string | null>> = VideodirOptions<Accept, Alt> & {
22
+ /** The directory where videos are stored. Must start with "/public". */
23
+ dir: MediaDir;
24
+ };
25
+ /** See `ImagedirAltOption`: `alt` is optional only when it is the default. */
26
+ type VideodirAltOption<Alt extends AltSchema> = [
16
27
  StringSchema<string | null>
17
28
  ] extends [Alt] ? {
18
29
  /**
@@ -26,25 +37,20 @@ type VideosetAltOption<Alt extends AltSchema> = [
26
37
  /** Description schema — required, because it is not the default one. */
27
38
  alt: Alt;
28
39
  };
29
- type VideosetOptionsBase<Accept extends `video/${string}`> = {
40
+ /** See `ImagedirOptionsArg`: the options are optional only when `alt` is. */
41
+ type VideodirOptionsArg<Accept extends `video/${string}`, Alt extends AltSchema> = [StringSchema<string | null>] extends [Alt] ? [options?: VideodirOptions<Accept, Alt>] : [options: VideodirOptions<Accept, Alt>];
42
+ type VideodirOptionsBase<Accept extends `video/${string}`> = {
30
43
  /**
31
44
  * What may be UPLOADED, in `<input accept>` syntax. Must be a video type.
32
45
  * Not checked against an HLS stream: see `VideoOptions.accept`.
33
46
  * @default "video/*"
34
47
  */
35
48
  accept?: Accept;
36
- /**
37
- * The directory where videos are stored. Must start with "/public".
38
- *
39
- * Required for the same reason it is on `s.imageset()`: it decides where
40
- * every upload in the set lands, and a default is a directory shared with
41
- * every other set that did not say.
42
- */
43
- dir: "/public" | `/public/${string}`;
44
49
  /**
45
50
  * Turn every upload into an HLS stream, in the browser. See
46
- * `VideoStreamOptions`. A field backed by this set (`s.video(videosVal)`)
47
- * inherits it, as it inherits `accept` and `dir`.
51
+ * `VideoStreamOptions`. A field backed by this directory
52
+ * (`s.video(videosVal)`) inherits it, as it inherits `accept` and the
53
+ * directory.
48
54
  */
49
55
  stream?: VideoStreamOption;
50
56
  };
@@ -63,7 +69,7 @@ type VideosetOptionsBase<Accept extends `video/${string}`> = {
63
69
  * The poster is also the set's thumbnail of the entry: there is no separate
64
70
  * still for the gallery, because two stills of one video would disagree.
65
71
  */
66
- export type VideosetEntryMetadata<Alt extends AltSource = string | null> = {
72
+ export type VideodirEntryMetadata<Alt extends AltSource = string | null> = {
67
73
  mimeType: string;
68
74
  width: number;
69
75
  height: number;
@@ -81,34 +87,38 @@ export type VideosetEntryMetadata<Alt extends AltSource = string | null> = {
81
87
  /** Overridden as a whole: a field with its own tracks has none of these. */
82
88
  captions?: readonly VideoCaptionSource[];
83
89
  };
84
- export type SerializedVideosetSchema = SerializedRecordSchema;
85
- type VideosetItemProps<Alt extends AltSchema> = {
90
+ /** @deprecated Use `VideodirEntryMetadata`. */
91
+ export type VideosetEntryMetadata<Alt extends AltSource = string | null> = VideodirEntryMetadata<Alt>;
92
+ export type SerializedVideodirSchema = SerializedRecordSchema;
93
+ /** @deprecated Use `SerializedVideodirSchema`. */
94
+ export type SerializedVideosetSchema = SerializedVideodirSchema;
95
+ type VideodirItemProps<Alt extends AltSchema> = {
86
96
  mimeType: StringSchema<string>;
87
97
  width: NumberSchema<number>;
88
98
  height: NumberSchema<number>;
89
99
  duration: NumberSchema<number>;
90
100
  alt: Alt;
91
101
  };
92
- type VideosetItemSrc<Alt extends AltSchema> = {
102
+ type VideodirItemSrc<Alt extends AltSchema> = {
93
103
  mimeType: string;
94
104
  width: number;
95
105
  height: number;
96
106
  duration: number;
97
107
  alt: AltSourceOf<Alt>;
98
108
  };
109
+ type VideodirSchema<Alt extends AltSchema> = RecordSchema<ObjectSchema<VideodirItemProps<Alt>, VideodirItemSrc<Alt>>, Schema<string>, Record<string, VideodirEntryMetadata<AltSourceOf<Alt>>>>;
99
110
  /**
100
- * Define a collection of videos — the video twin of `s.imageset()`.
111
+ * Define a directory of videos — the video twin of `s.imagedir()`.
101
112
  *
102
113
  * A field picks from it with `s.video(videosVal)`. An entry may hold the
103
114
  * description, poster, start and end, focal point and captions as defaults,
104
115
  * and a field overrides any of them by setting its own. Uploading in such a
105
- * field adds to the set. Call `.remote()` on the result
106
- * to store the set on Val Remote.
116
+ * field adds to the directory. Call `.remote()` on the result to store the
117
+ * videos on Val Remote.
107
118
  *
108
119
  * @example
109
120
  * ```typescript
110
- * const schema = s.videoset({
111
- * dir: "/public/val/videos",
121
+ * const schema = s.videodir("/public/val/videos", {
112
122
  * stream: { type: "hls" },
113
123
  * });
114
124
  * export default c.define("/content/videos.val.ts", schema, {
@@ -123,7 +133,25 @@ type VideosetItemSrc<Alt extends AltSchema> = {
123
133
  * });
124
134
  * ```
125
135
  */
126
- export declare const videoset: <Accept extends `video/${string}`, Alt extends AltSchema = StringSchema<string | null>>(options: VideosetOptions<Accept, Alt>) => RecordSchema<ObjectSchema<VideosetItemProps<Alt>, VideosetItemSrc<Alt>>, Schema<string>, Record<string, VideosetEntryMetadata<AltSourceOf<Alt>>>>;
136
+ export declare const videodir: <Accept extends `video/${string}`, Alt extends AltSchema = StringSchema<string | null>>(dir: MediaDir, ...[options]: VideodirOptionsArg<Accept, Alt>) => VideodirSchema<Alt>;
137
+ /**
138
+ * `s.videodir()` with `.remote()` applied: what `s.videodir` is under
139
+ * `files: { remote: true }`.
140
+ */
141
+ export declare const remoteVideodir: <Accept extends `video/${string}`, Alt extends AltSchema = StringSchema<string | null>>(dir: MediaDir, ...[options]: VideodirOptionsArg<Accept, Alt>) => VideodirSchema<Alt>;
142
+ /**
143
+ * Define a collection of videos.
144
+ *
145
+ * @deprecated Use `s.videodir(dir, options)`: the directory moved out of the
146
+ * options and into the first argument, and nothing else changed.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // was: s.videoset({ dir: "/public/val/videos", stream: { type: "hls" } })
151
+ * const schema = s.videodir("/public/val/videos", { stream: { type: "hls" } });
152
+ * ```
153
+ */
154
+ export declare const videoset: <Accept extends `video/${string}`, Alt extends AltSchema = StringSchema<string | null>>(options: VideosetOptions<Accept, Alt>) => VideodirSchema<Alt>;
127
155
  /**
128
156
  * The video schema a set's entry is hashed against, for a remote ref.
129
157
  *
@@ -81,7 +81,7 @@ export type VideoCaptionSource = {
81
81
  * What a video FIELD authors, on top of the file it names: the description,
82
82
  * the crop, the poster, the trim and the caption tracks.
83
83
  *
84
- * This is the whole value of a field picked from an `s.videoset()`
84
+ * This is the whole value of a field picked from an `s.videodir()`
85
85
  * (`s.video(videosetVal)`) — the mime type, size and length live in the set,
86
86
  * keyed by `path`, and repeating them here is how two copies of one fact get
87
87
  * to disagree. The poster, captions and times stay with the FIELD: one video
@@ -112,7 +112,7 @@ export type GalleryVideoSource = {
112
112
  /**
113
113
  * What one page chooses about a video — as opposed to what is true of the
114
114
  * file. A field (`s.video()`) carries these for itself; the entry of a set
115
- * (`s.videoset()`) carries them as DEFAULTS, which every field picked from the
115
+ * (`s.videodir()`) carries them as DEFAULTS, which every field picked from the
116
116
  * set starts from and may override key by key. See {@link fillFromGallery}.
117
117
  */
118
118
  export type VideoDefaults = Pick<GalleryVideoSource, "hotspot" | "posterTime" | "poster" | "startTime" | "endTime" | "captions">;
@@ -211,6 +211,27 @@ export type ResolvedVideo<S extends GalleryVideoSource = VideoSource> = Omit<S,
211
211
  * the poster's and the captions', which are not where an edit lands.
212
212
  */
213
213
  export declare function resolveVideo<S extends GalleryVideoSource>(src: S, videoUrl?: (src: S) => string): ResolvedVideo<S>;
214
+ /**
215
+ * The key of a gallery (an `s.imagedir()`, `s.filedir()` or `s.videodir()`)
216
+ * that a field's `path` names, or `null` when it names none.
217
+ *
218
+ * Usually the path IS the key. It is not for an image uploaded THROUGH an
219
+ * `s.image(remoteGallery)` field in the Studio, which stores the remote ref in
220
+ * the field and keys the entry by the local path inside it — so a path that is
221
+ * not a key falls back to that embedded path. Exact first, because a gallery
222
+ * can hold both shapes for one file, and the field then names the entry that
223
+ * IS its path.
224
+ *
225
+ * One implementation of the question, asked by everything that has to agree on
226
+ * the answer: reading a field (`galleryEntryOf`), validating it (`ImageSchema`
227
+ * and `FileSchema` ask whether the gallery has it), the Studio's reference
228
+ * scans and renames, and `val validate --fix` when it renames a key and has to
229
+ * find the fields that hold it.
230
+ *
231
+ * The embedded path is tried with its leading slash (how a key is written) and
232
+ * without (how `splitRemoteRef` returns it).
233
+ */
234
+ export declare function galleryKeyOf(path: string, isKey: (key: string) => boolean): string | null;
214
235
  /**
215
236
  * What a gallery entry holds as a DEFAULT for the fields picked from it, in
216
237
  * the groups a field overrides together.
@@ -226,7 +247,9 @@ export declare const GALLERY_DEFAULT_GROUPS: readonly (readonly string[])[];
226
247
  * gallery-backed or the gallery has no such entry.
227
248
  *
228
249
  * The double lookup is load-bearing: a remote gallery keys its entries by the
229
- * remote URL while the file itself stays on disk under its local path.
250
+ * remote URL while the file itself stays on disk under its local path, and an
251
+ * upload through the field does it the other way round (see
252
+ * {@link galleryKeyOf}).
230
253
  */
231
254
  export declare function galleryEntryOf(src: {
232
255
  readonly path: string;