|
| 1 | +--- |
| 2 | +title: Seed File schema — Data Protocol reference |
| 3 | +navTitle: Seed File |
| 4 | +description: "A file / image / avatar / video / audio field stores an opaque sys_file id, and only an upload mints one." |
| 5 | +--- |
| 6 | + |
| 7 | +{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */} |
| 8 | + |
| 9 | +## Seed files — a file a package ships, written into a file field by a seed |
| 10 | + |
| 11 | +A `file` / `image` / `avatar` / `video` / `audio` field stores an opaque |
| 12 | +`sys_file` id (ADR-0104 D3 wave 2), and only an upload mints one. A seed has |
| 13 | +no upload, so a seed record names the file by the PATH the package ships it |
| 14 | +at instead, and the platform carries the bytes from there (#25779, ruled on |
| 15 | +hotclm#19: "the platform's seed loader should carry bundled fixture files; |
| 16 | +the app keeps `file` required"): |
| 17 | + |
| 18 | +1. **Authoring.** A record writes `seedFile('fixtures/nda-v1.pdf')` — the |
| 19 | + value `SeedFileReferenceSchema` — into a file-class field. The path |
| 20 | + is relative to the package root: the directory holding |
| 21 | + `objectstack.config.ts`, the root a declarative connector's file ref |
| 22 | + resolves against too. |
| 23 | +2. **Bundling.** `os build` / `os compile` reads every referenced file and |
| 24 | + writes its bytes into the dataset's `files` map |
| 25 | + (`SeedFileContentSchema`), keyed by the same path. The compiled |
| 26 | + artifact is what every boot reads — `os dev`, `os serve`, a published |
| 27 | + package, an artifact URL — so the bytes travel with the seed wherever it |
| 28 | + goes. A path that names no file fails the build. |
| 29 | +3. **Loading.** The seed loader stores the bytes as a `sys_file`, writes its |
| 30 | + id into the field, and has the written record own it — (object, record, |
| 31 | + field), the ownership an upload gets. A replay that finds the row still |
| 32 | + holding a file with the same bytes keeps it, so a boot does not mint a |
| 33 | + new file for an unchanged fixture. A reference whose bytes the dataset |
| 34 | + does not carry is refused, by row, naming the path. |
| 35 | + |
| 36 | +300 rows may name the same path: each row gets a file of its own, because a |
| 37 | +file has one owning field (ADR-0104 D3). |
| 38 | + |
| 39 | +<Callout type="info"> |
| 40 | +**Source:** `packages/spec/src/data/seed-file.zod.ts` |
| 41 | +</Callout> |
| 42 | + |
| 43 | +## TypeScript Usage |
| 44 | + |
| 45 | +```typescript |
| 46 | +import { SeedFileContentSchema, SeedFilePathSchema, SeedFileReferenceSchema } from '@objectstack/spec/data'; |
| 47 | +import type { SeedFileContent, SeedFilePath, SeedFileReference } from '@objectstack/spec/data'; |
| 48 | + |
| 49 | +// Validate data |
| 50 | +const result = SeedFileContentSchema.parse(data); |
| 51 | +``` |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +## SeedFileContent |
| 56 | + |
| 57 | +One bundled seed file: its bytes and what they must hash to |
| 58 | + |
| 59 | +### Properties |
| 60 | + |
| 61 | +| Property | Type | Required | Description | |
| 62 | +| :--- | :--- | :--- | :--- | |
| 63 | +| **contentType** | `string` | ✅ | MIME type the stored file carries | |
| 64 | +| **size** | `integer` | ✅ | Byte length of the file | |
| 65 | +| **sha256** | `string` | ✅ | SHA-256 of the bytes, lowercase hex — the loader refuses bytes that do not match it | |
| 66 | +| **data** | `string` | ✅ | The bytes, base64-encoded | |
| 67 | + |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## SeedFilePath |
| 72 | + |
| 73 | +Path of a file the package ships, relative to the package root (e.g. `fixtures/nda-v1.pdf`) |
| 74 | + |
| 75 | +**Type:** `string` |
| 76 | + |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## SeedFileReference |
| 81 | + |
| 82 | +A file the package ships, by package-relative path, written into a file field by a seed |
| 83 | + |
| 84 | +### Properties |
| 85 | + |
| 86 | +| Property | Type | Required | Description | |
| 87 | +| :--- | :--- | :--- | :--- | |
| 88 | +| **$file** | `string` | ✅ | Path of a file the package ships, relative to the package root (e.g. `fixtures/nda-v1.pdf`) | |
| 89 | +| **name** | `string` | optional | File name the stored file carries (what a download is saved as); defaults to the last segment of the path | |
| 90 | +| **contentType** | `string` | optional | MIME type of the file; defaults to the one `os build` infers from the path's extension | |
| 91 | + |
| 92 | + |
| 93 | +--- |
| 94 | + |
0 commit comments