@protobase/cli 0.94.28 → 0.94.30

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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.94.28";
2
+ var version = "0.94.30";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.94.28",
3
+ "version": "0.94.30",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -43,13 +43,13 @@
43
43
  "dependencies": {
44
44
  "@better-auth/core": "^1.7.12",
45
45
  "@hono/node-server": "^2.1.3",
46
- "@protobase/config": "0.94.28",
47
- "@protobase/layout": "0.94.28",
48
- "@protobase/query": "0.94.28",
49
- "@protobase/schema": "0.94.28",
50
- "@protobase/server": "0.94.28",
51
- "@protobase/ui": "0.94.28",
52
- "@protobase/workflows": "0.94.28",
46
+ "@protobase/config": "0.94.30",
47
+ "@protobase/layout": "0.94.30",
48
+ "@protobase/query": "0.94.30",
49
+ "@protobase/schema": "0.94.30",
50
+ "@protobase/server": "0.94.30",
51
+ "@protobase/ui": "0.94.30",
52
+ "@protobase/workflows": "0.94.30",
53
53
  "@react-email/render": "^2.1.0",
54
54
  "@scalar/hono-api-reference": "^0.12.10",
55
55
  "@sentry/vite-plugin": "^11.10.0",
@@ -12,7 +12,9 @@ Uploaded files and images, where they are kept and how they are served.
12
12
  - [Type detection](../reference/files.md#how-the-type-is-decided): An upload's type is decided from its content, and a disguised file is refused.
13
13
  - [Your own types](../reference/files.md#your-own-types): An app names its own media types and their extensions, and files with them are stored and served as those types.
14
14
  - [File viewers](../reference/files.md#viewers): A plugin registers a viewer for a media type, and a file of that type opens in it in the app instead of downloading.
15
+ - [Image and PDF viewers](../reference/files.md#image-and-pdf-viewers): Two plugins an app can attach open stored images and PDFs in the app, loaded only when such a file opens.
15
16
  - [Signed downloads](../reference/files.md#downloads): Private files open through short-lived links that stop working once the record no longer holds the file.
17
+ - [Type and size fields](../reference/files.md#type-and-size-fields): Each file's media type and size are kept in columns of their own, for lists and aggregate queries, and serving reads the type from there.
16
18
  - [Derived fields](../reference/files.md#derived-fields): Width, height, size and type of each upload are written to other fields.
17
19
  - [Image variants and placeholders](../reference/files.md#image-variants-and-placeholders): Resized copies of uploaded images, and a blurred placeholder while they load.
18
20
  - [External URLs](../reference/files.md#external-urls): A file field can hold a link to a file on another site.
@@ -50,6 +50,8 @@ export const bikes = resource('bikes')
50
50
  | `.maxSize('10 MB')` | The largest upload, as bytes or text (`512 KiB`, `1.5 GB`); default 50 MB. |
51
51
  | `.public()` | Stored with the `public` provider, whose files anyone with the link may open. |
52
52
  | `.storage('archive')` | Stored with another provider; default `private`. |
53
+ | `.typeField('attachment_type')` | Each file's media type in that text field, which responses and downloads read, see [Type and size fields](#type-and-size-fields). |
54
+ | `.sizeField('attachment_size')` | Each file's size in bytes in that integer or bigint field, see [Type and size fields](#type-and-size-fields). |
53
55
  | `.derive({ field: processor })` | Values computed from each upload and written to other fields of the row, see [Derived fields](#derived-fields). |
54
56
  | `.placeholder('photo_placeholder')` | Each image's ThumbHash in that text field, drawn while the image loads, see [Image variants and placeholders](#image-variants-and-placeholders). |
55
57
  | `.variants({ card: { … } }, { original? })` | Resized copies of each image stored beside it, see [Image variants and placeholders](#image-variants-and-placeholders). |
@@ -66,7 +68,7 @@ private:1/2992db9c-776e-4d4e-9e0f-59d485fefaf9.jpg?name=bike+red.png&size=48211
66
68
  - The **scheme is the provider's name**, so a provider can move from local disk to a bucket without touching any row. Name the role (`archive`), not the vendor: the name is part of every stored value.
67
69
  - The **path** of an upload is `<tenant>/<random id>.<extension>`, with `_` for a resource without a tenant. Nothing in it comes from the row or from what the user typed, so renames and key changes need nothing.
68
70
  - The **query** holds the uploader's file name and the size in bytes, and for an image with [variants](#image-variants-and-placeholders) their names and extensions: `&variants=card.webp,thumb.webp`. A plain `{provider}:{path}`, such as `public:images/test.jpg` written by an import, is valid too; its name is its last path segment.
69
- - The **type is not stored**. It is the path's extension, looked up in one fixed table, which is also what downloads are served as.
71
+ - The **type is not stored** in the value. It is the path's extension, looked up in the built-in table and the app's [own types](#your-own-types), which is also what downloads are served as, unless the field has a [type field](#type-and-size-fields).
70
72
  - A field with `.externalUrls()` may hold an **https URL** instead, such as `https://images.example.com/listings/42.jpg`, see [External URLs](#external-urls).
71
73
 
72
74
  Responses carry each file field as an object, and the stored value stays the URI:
@@ -151,10 +153,10 @@ PROTOBASE_FILES_ARCHIVE=s3://acme-archive?endpoint=https://s3.fr-par.scw.cloud&r
151
153
  ```
152
154
 
153
155
  - **Credentials** never go in the URL. A provider set from the environment reads `PROTOBASE_FILES_<NAME>_ACCESS_KEY_ID` and `PROTOBASE_FILES_<NAME>_SECRET_ACCESS_KEY`, else `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY`, else `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, and the server does not start without a pair. In the config, pass `accessKeyId` and `secretAccessKey`, or leave them out for the `S3_` or `AWS_` pair. The key needs to read, write, list and delete objects in the bucket.
154
- - **Uploads** still go through Protobase's upload route, so types are checked and processors run; the body streams on to the bucket in parts, and an upload that fails stores nothing. Each object is stored with the type and disposition its path is served as. A bucket keeps the parts of an upload that never finished until they are aborted: R2 aborts them after 7 days, on Scaleway and AWS add a lifecycle rule that aborts incomplete multipart uploads after a day.
156
+ - **Uploads** still go through Protobase's upload route, so types are checked and processors run; the body streams on to the bucket in parts, and an upload that fails stores nothing. Each object is stored with the type its upload was decided to be, the app's [own types](#your-own-types) included, and the disposition that type is served with. A bucket keeps the parts of an upload that never finished until they are aborted: R2 aborts them after 7 days, on Scaleway and AWS add a lifecycle rule that aborts incomplete multipart uploads after a day.
155
157
  - **Private files** keep their signed `url`. A download checks the link and the row as above, then redirects with `302` to a presigned link to the bucket that lasts as long as the app's link, served with the same type and disposition. The bytes never pass through the app.
156
158
  - **Public files** are linked at `publicUrl` followed by the prefix and the path, such as `https://files.acme.com/public/_/2992db9c-….png`: the bucket's own public address, an R2 custom domain or a Scaleway public bucket. Without `publicUrl`, `/api/files/<provider>/<path>` redirects to a presigned link instead.
157
- - The bucket serves its files itself, so the `nosniff` and sandbox headers of the app's own downloads do not apply. The type always comes from the path's extension, never HTML, and the bucket is on another domain than the app. A page that `fetch`es file URLs, rather than showing them in `<img>` or linking them, needs CORS on the bucket.
159
+ - The bucket serves its files itself, so the `nosniff` and sandbox headers of the app's own downloads do not apply. The type is always the one the upload was decided to be, never HTML, and the bucket is on another domain than the app. A page that `fetch`es file URLs, rather than showing them in `<img>` or linking them, needs CORS on the bucket.
158
160
  - It runs on Bun, whose built-in S3 client it uses: `protobase-serve.js`, the `protobase` image, or the CLI started with Bun. On Node the first file operation fails.
159
161
 
160
162
  ## Uploading
@@ -211,6 +213,53 @@ A plugin, or the app's own `protobase.ui.tsx`, registers a viewer for a media ty
211
213
 
212
214
  The viewer gets the file and its **siblings**: the record's other files, and the files of the records of the same resource that point at the same records through filterable relations, read in one list call of at most 100 records. For attachments that each point at a task, the siblings of one are the other attachments of that task, so a report can show the images it names by file name.
213
215
 
216
+ ### Image and PDF viewers
217
+
218
+ Protobase brings no viewer of its own. Two plugins, each a package of its own, open images and PDFs in the app; an app that wants them installs them and extends its `protobase.ui.tsx` with them:
219
+
220
+ ```sh
221
+ npm install @protobase/image-viewer @protobase/pdf-viewer
222
+ ```
223
+
224
+ ```tsx
225
+ // protobase.ui.tsx
226
+ import { defineUi } from '@protobase/ui'
227
+ import imageViewer from '@protobase/image-viewer'
228
+ import pdfViewer from '@protobase/pdf-viewer'
229
+
230
+ export default defineUi({ extends: [imageViewer, pdfViewer] })
231
+ ```
232
+
233
+ Each viewer's code is a chunk of the app's build that loads only when such a file opens, so an app that extends them loads nothing more until then. On a phone both are as wide as the screen. A file a viewer cannot draw shows the Download button in its place.
234
+
235
+ - `@protobase/image-viewer` opens PNG, JPEG, GIF, WebP, AVIF and BMP, the images downloads serve inline: fitted to the page, with its size in pixels and an **Actual size** button that shows it pixel for pixel, scrolling in its own box when it is wider than the page. SVG stays a download.
236
+ - `@protobase/pdf-viewer` opens PDF files with an open-source PDF renderer that runs in a web worker: the pages one under the other, as wide as the page up to 60rem, each drawn when it comes within a screen of being shown and let go again once it is further away, so a long PDF holds only the pages around the screen. Scanned pages in JPEG 2000 or JBIG2 are drawn with the renderer's decoders, which the viewer brings. The renderer reads the file with `fetch`, so a PDF served from another origin than the app's, from a [bucket](#s3-compatible-buckets) or an [external URL](#external-urls)'s host, opens only when that host allows the app's origin with CORS; otherwise the viewer shows the Download button. <gap>The PDF viewer cannot select or search a page's text because a text layer is not implemented, so the page is an image and its text is read in the download.</gap> <gap>The PDF viewer cannot draw text that uses one of the renderer's predefined CMaps, as many Chinese, Japanese and Korean PDFs do whether or not they embed the font, because bringing those CMaps is not implemented, so such text is read in the download.</gap>
237
+
238
+ Each package also exports its viewer component (`ImageViewer`, `PdfViewer`), for an app that registers it for a type of its own in `fileViewers`.
239
+
240
+ ## Type and size fields
241
+
242
+ `.typeField()` and `.sizeField()` keep each file's media type and size in columns of their own, so a list can show them and SQL can count and sum by them:
243
+
244
+ ```ts
245
+ attachment: f.file().optional().typeField('attachment_type').sizeField('attachment_size'),
246
+ attachment_type: f.text().readOnly().optional(),
247
+ attachment_size: f.bigint().readOnly().optional(),
248
+ ```
249
+
250
+ ```sql
251
+ select attachment_type, count(*), sum(attachment_size) from attachments group by attachment_type
252
+ ```
253
+
254
+ - Both fields must be `readOnly()`, as [derived fields](#derived-fields) are: an upload writes them with the file in the same transaction, and clearing the file sets them to `null`. The type field is text; the size field an integer, or a bigint for files past 2 GB.
255
+ - An **upload** writes the type it was [decided](#how-the-type-is-decided) to be and its size in bytes.
256
+ - An **external URL** writes the type its extension names, the app's [own types](#your-own-types) included, and `null` when the table knows no such extension. Its size field stays `null`, since Protobase never fetches it.
257
+ - An **import** that writes rows itself may write both beside the value, such as the type of a file stored under a name with no extension. Leave a field `null` when the source does not say; never guess.
258
+ - **Responses** and [viewers](#viewers) take the file's `type` and `size` from these fields when the row holds them, else from the value.
259
+ - A **private download** is served as the type field's type when that is a type the app's table knows, so a file is never served as HTML; any other value is served by the path's extension. A public file has no row to read, so it is served by its path, and a bucket serves it with the type its upload was decided to be.
260
+
261
+ Files stored before a field declared them keep `null` until they are uploaded again or an import fills them.
262
+
214
263
  ## Derived fields
215
264
 
216
265
  `.derive({ field: processor })` computes values from each upload into other fields of the same resource. Those fields must be `readOnly()`, so only the upload sets them.
@@ -271,10 +320,10 @@ curl -X PATCH https://app.example.com/api/v1/products/42 -H "authorization: Bear
271
320
  ```
272
321
 
273
322
  - **What is taken**: an absolute `https://` URL with a host, without a user name or password, written without spaces or other characters a URL escapes. `http:`, `data:` and anything else is refused with `400`, as in a field without the option.
274
- - **The type** is the URL path's extension, from the same table as stored files, and must pass `.accept()`: an image field takes `…/front.jpg` and refuses `…/front` and `…/scan.pdf`. The name is the path's last segment.
275
- - **Stored as given**: the column holds the URL itself, and Protobase never fetches, uploads or copies it. It has no size, and responses link it as it is, as `url`, for whoever may read the row.
323
+ - **The type** is the URL path's extension, from the same table as stored files, the app's [own types](#your-own-types) included, and must pass `.accept()`: an image field takes `…/front.jpg` and refuses `…/front` and `…/scan.pdf`. The name is the path's last segment. A [type field](#type-and-size-fields) gets that type, and an import may write a better one there.
324
+ - **Stored as given**: the column holds the URL itself, and Protobase never fetches, uploads or copies it. It has no size unless an import wrote one in the [size field](#type-and-size-fields), and responses link it as it is, as `url`, for whoever may read the row.
276
325
  - **No variants**: every place an image is drawn, cards, tables, thumbnails, forms and the record page, uses the URL itself, and `fileUrl(file, 'card')` gives it too. Size the image at its source when it should be small.
277
- - **No ThumbHash**: a write through the API sets the field's derived fields and placeholder to `null`, since there are no bytes to compute them from; the image frame stays empty until the image loads. An import that writes the rows itself may write a placeholder beside the URL, and the admin app draws that one.
326
+ - **No ThumbHash**: a write through the API sets the field's derived fields, placeholder and size field to `null`, since there are no bytes to compute them from; the image frame stays empty until the image loads. An import that writes the rows itself may write a placeholder beside the URL, and the admin app draws that one.
278
327
  - **Nothing to delete**: replacing an upload with a URL schedules the upload's delete as any replacement does; a URL that is replaced or cleared schedules nothing.
279
328
  - The other site sees each viewer's IP address when it serves the image, and decides when it changes or disappears. The admin app draws it without a referrer, see [Image referrers](#image-referrers).
280
329
 
@@ -176,7 +176,7 @@ The create form and the record's form pick the members of the organization the s
176
176
 
177
177
  ## File viewers
178
178
 
179
- A file viewer shows files of one media type in the app, such as a report the app writes as JSON, instead of downloading them. A plugin registers it by the type, which the server must know: a built-in type, or one of the app's own in `files.types` (see [Your own types](files.md#your-own-types)).
179
+ A file viewer shows files of one media type in the app, such as a report the app writes as JSON, instead of downloading them. `@protobase/image-viewer` and `@protobase/pdf-viewer` are two such plugins for images and PDFs (see [Image and PDF viewers](files.md#image-and-pdf-viewers)). A plugin registers it by the type, which the server must know: a built-in type, or one of the app's own in `files.types` (see [Your own types](files.md#your-own-types)).
180
180
 
181
181
  ```tsx
182
182
  // protobase.ui.tsx