@valbuild/core 0.121.0 → 0.125.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.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The reference stored for a file whose bytes live behind an external adapter.
3
+ *
4
+ * Deliberately the same shape of idea as a remote ref (`remote/splitRemoteRef`):
5
+ * a URL-ish string that **ends with the file's virtual path**, so the file's
6
+ * logical identity survives wherever its bytes happen to be.
7
+ *
8
+ * /api/val/external/documents/f/{fileHash}/p/public/val/documents/report_a1b2c.pdf
9
+ * \__________________________/ \________/ \_______________________________/
10
+ * route + label content the path a LOCAL file
11
+ * address would have had
12
+ *
13
+ * Three things follow from that shape, and each is load-bearing:
14
+ *
15
+ * - **`media.ts` needs no change.** `isRemote` is `!path.startsWith("/public")`,
16
+ * and this does not, so `Internal.mediaUrl` returns the ref as-is and Val's
17
+ * route serves it. The media rule that has been got wrong repeatedly is left
18
+ * exactly alone.
19
+ * - **Moving between storage modes is mechanical.** External → local reads the
20
+ * `public/…` suffix back out, fetches the bytes and writes them there; local →
21
+ * external uploads the file already at that path. Nothing is renamed.
22
+ * - **The filename is Val's, not the adapter's**, produced by the same
23
+ * `createFilename` a local or remote file uses — so the same bytes get the
24
+ * same name under all three storage modes.
25
+ */
26
+ export type ExternalFileRefParts = {
27
+ /** The `.external(label)` of the record the file belongs to. */
28
+ label: string;
29
+ /** SHA-256 of the bytes. Content-addressed, so a retried publish re-uses. */
30
+ fileHash: string;
31
+ /** The virtual path, WITHOUT a leading slash: `public/val/...`. */
32
+ filePath: `public/${string}`;
33
+ };
34
+ export declare function createExternalFileRef({ label, fileHash, filePath, }: {
35
+ label: string;
36
+ fileHash: string;
37
+ /** Accepts the path as it is written in a module: `/public/val/...`. */
38
+ filePath: string;
39
+ }): string;
40
+ export declare function splitExternalFileRef(ref: string): ({
41
+ status: "success";
42
+ } & ExternalFileRefParts) | {
43
+ status: "error";
44
+ error: string;
45
+ };
46
+ export declare function isExternalFileRef(ref: string): boolean;
@@ -1,8 +1,9 @@
1
+ import { ExternalRecordSrc } from "./external.js";
1
2
  import { JsonSource } from "./json.js";
2
3
  import { MediaSource } from "./media.js";
3
4
  import { RichTextOptions, RichTextSource } from "./richtext.js";
4
5
  import { SettingsSource } from "./settings.js";
5
- export type Source = SourcePrimitive | SourceObject | SourceArray | MediaSource | JsonSource | SettingsSource | RichTextSource<RichTextOptions>;
6
+ export type Source = SourcePrimitive | SourceObject | SourceArray | MediaSource | JsonSource | ExternalRecordSrc | SettingsSource | RichTextSource<RichTextOptions>;
6
7
  export type SourceObject = {
7
8
  [key in string]: Source;
8
9
  } & {
@@ -22,7 +23,7 @@ export type SourceObject = {
22
23
  export type SourceArray = readonly Source[];
23
24
  export type SourcePrimitive = string | number | boolean | null;
24
25
  export declare const VAL_EXTENSION: "_type";
25
- export declare function getValExtension(source: Source): false | "" | 0 | "json" | null | undefined;
26
+ export declare function getValExtension(source: Source): false | "" | 0 | "json" | "external" | null | undefined;
26
27
  /**
27
28
  * A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
28
29
  *