@owlmeans/image-resource 0.1.18-rc.42 → 0.1.18-rc.43

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.
package/README.md CHANGED
@@ -1,47 +1,103 @@
1
1
  # @owlmeans/image-resource
2
2
 
3
- Image-specific type extensions for OwlMeans object storage — AJV schemas for image metadata.
4
-
5
- ## Overview
6
-
7
- - `ImageMeta` / `StoredImage` / `ImageData` — typed image record interfaces
8
- - `ImageMetaSchema` / `StoredImageSchema` / `ImageDataSchema` — AJV JSON schemas for validation
9
- - Extends `@owlmeans/storage-common` types with image semantics
3
+ Image-shaped names and AJV schemas over the stored-file types of `@owlmeans/storage-common`:
4
+ `ImageMeta`, `StoredImage`, `ImageData` and their schemas. An app uses it to type the record that
5
+ describes an image and to validate an image upload or response against a schema of its own, so a
6
+ signature says it carries an image rather than an arbitrary file. It registers no resource and
7
+ stores nothing: the bytes go to a bucket through `@owlmeans/storage-resource`, the describing record
8
+ goes to a database resource (`@owlmeans/mongo-resource`, `@owlmeans/postgres-resource`), and a
9
+ non-image file uses the `StoredFile*` types of `@owlmeans/storage-common` directly.
10
10
 
11
11
  ## Installation
12
12
 
13
13
  ```bash
14
- bun add @owlmeans/image-resource@^0.1.18-rc.42
14
+ bun add @owlmeans/image-resource@^0.1.18-rc.43
15
15
  ```
16
16
 
17
+ `ajv` is a peer dependency. Install `@owlmeans/storage-common` explicitly as well — the schemas are
18
+ built from its runtime values, and it is not a declared dependency of this package.
19
+
20
+ ## Concepts
21
+
22
+ - **Image meta** — `ImageMeta`, the descriptive fields of an image: `entityId?`, `sourceName?`,
23
+ `name?`, `title?`, `scopes`, `mimeType`, `alias`, `status` (`StoredFileStatus`).
24
+ - **Stored image** — `StoredImage`, the meta plus `instances`: a map of renditions (original,
25
+ thumbnail, converted format), each `{ size, alias, url }`.
26
+ - **Image data** — `ImageData`, the upload payload: the meta plus `format?` and `instances` whose
27
+ entries may carry `bytes` or `base64` (`StoredFileFormat`).
28
+ - **Bucket vs. record** — a bucket (`StorageResource`) only accepts an upload and returns a URL; the
29
+ record that answers criteria, sorting and paging lives in a database resource.
30
+
17
31
  ## Usage
18
32
 
33
+ ### Validate an upload or a response
34
+
35
+ ```typescript
36
+ import Ajv from 'ajv'
37
+ import { ImageDataSchema, StoredImageSchema } from '@owlmeans/image-resource'
38
+ import type { ImageData, StoredImage } from '@owlmeans/image-resource'
39
+
40
+ const ajv = new Ajv()
41
+ const validateUpload = ajv.compile<ImageData>(ImageDataSchema)
42
+ const validateImage = ajv.compile<StoredImage>(StoredImageSchema)
43
+
44
+ if (!validateUpload(payload)) {
45
+ throw new SyntaxError(ajv.errorsText(validateUpload.errors))
46
+ }
47
+ ```
48
+
49
+ The schemas set `additionalProperties: false`, so an extra field fails validation.
50
+
51
+ ### Keep image records in a database resource
52
+
19
53
  ```typescript
20
- import { StoredImageSchema, ImageDataSchema } from '@owlmeans/image-resource'
21
- import type { StoredImage, ImageData } from '@owlmeans/image-resource'
54
+ import type { Resource } from '@owlmeans/resource'
55
+ import type { StoredImage } from '@owlmeans/image-resource'
56
+
57
+ const images = ctx.resource<Resource<StoredImage>>('images')
58
+ const page = await images.list({ entityId, mimeType: { $startsWith: 'image/' } }, { sort: ['name'], size: 20 })
22
59
 
23
- // Use AJV schema for validation
24
- const validate = ajv.compile<StoredImage>(StoredImageSchema)
60
+ // Pick a rendition from the map; never derive one url from another
61
+ const thumbnailUrl = page.items[0]?.instances.thumbnail?.url
25
62
  ```
26
63
 
27
64
  ## API
28
65
 
29
66
  ### Types
30
67
 
31
- - `ImageMeta` — extends `StoredFileMeta` with image-specific fields
32
- - `StoredImage` — extends `StoredFile` for stored image records
33
- - `ImageData` — extends `StoredFileWithData` for image upload payloads
68
+ | Symbol | Extends | Purpose |
69
+ |---|---|---|
70
+ | `ImageMeta` | `StoredFileMeta` | descriptive fields of an image |
71
+ | `StoredImage` | `StoredFile` | a stored image with its `instances` renditions |
72
+ | `ImageData` | `StoredFileWithData` | an upload payload carrying bytes or base64 per instance |
34
73
 
35
74
  ### Schemas
36
75
 
37
- - `ImageMetaSchema: JSONSchemaType<ImageMeta>`
38
- - `StoredImageSchema: JSONSchemaType<StoredImage>`
39
- - `ImageDataSchema: JSONSchemaType<ImageData>`
76
+ | Symbol | Type | Built from |
77
+ |---|---|---|
78
+ | `ImageMetaSchema` | `JSONSchemaType<ImageMeta>` | `StoredFileMetaSchema` |
79
+ | `StoredImageSchema` | `JSONSchemaType<StoredImage>` | `StoredFileSchema` |
80
+ | `ImageDataSchema` | `JSONSchemaType<ImageData>` | `StoredFileWithDataSchema` |
81
+
82
+ Each copies the base schema's `properties` and `required` and closes the object.
83
+
84
+ ## Common pitfalls
85
+
86
+ - This package registers no resource — `ctx.resource('images')` needs a resource the app registered
87
+ with a database backend.
88
+ - A bucket accepts only `create`; listing or reading images goes through the record resource.
89
+ - `instances` keys are renditions; read the `url` of the one a screen needs instead of rebuilding a
90
+ url by string surgery.
91
+ - A missing `@owlmeans/storage-common` install fails at import, since the schemas spread its runtime
92
+ values.
93
+
94
+ ## Related packages
40
95
 
41
- ## Related Packages
96
+ - [`@owlmeans/storage-common`](../storage-common) — `StoredFileMeta`, `StoredFile`, `StoredFileWithData`, their schemas and enums
97
+ - [`@owlmeans/storage-resource`](../storage-resource) — the upload-only bucket resource that stores the bytes
98
+ - [`@owlmeans/resource`](../resource) — the `Resource<T>` contract the image record store implements
42
99
 
43
- - [`@owlmeans/storage-common`](../storage-common) — `StoredFileMeta`, `StoredFile`, `StoredFileWithData` base types
44
- - [`@owlmeans/storage-resource`](../storage-resource) — S3 resource used to persist images
100
+ The `image-resource` skill covers the same contract for agents.
45
101
 
46
102
  <!-- owlmeans:agent-guidance:start -->
47
103
  ## Agent guidance
@@ -51,7 +107,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
51
107
  your project's skill store (`.agents/skills/`):
52
108
 
53
109
  ```sh
54
- npx @owlmeans/agent-skills@^0.1.18-rc.49
110
+ npx @owlmeans/agent-skills@^0.1.18-rc.52
55
111
  ```
56
112
 
57
113
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/image-resource",
4
- "version": "0.1.18-rc.42",
5
- "generatedAt": "2026-10-05T21:03:06.393Z",
4
+ "version": "0.1.18-rc.43",
5
+ "generatedAt": "2026-10-08T21:27:54.300Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -8,7 +8,7 @@ user-invocable: false
8
8
  # @owlmeans/image-resource
9
9
 
10
10
  **Layer:** Infra
11
- **Install:** `"@owlmeans/image-resource": "^0.1.18-rc.42"` in `dependencies` (peer `ajv`)
11
+ **Install:** `"@owlmeans/image-resource": "^0.1.18-rc.43"` in `dependencies` (peer `ajv`)
12
12
 
13
13
  Types and schemas only — no resource is registered here. An image *is* a stored file
14
14
  ([[storage-common]]); this package gives that file image-shaped names so a signature says what it
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@owlmeans/image-resource",
3
3
  "type": "module",
4
- "version": "0.1.18-rc.42",
4
+ "version": "0.1.18-rc.43",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "build": "tsc -b",
@@ -24,7 +24,7 @@
24
24
  "ajv": "*"
25
25
  },
26
26
  "dependencies": {
27
- "@owlmeans/storage-resource": "^0.1.18-rc.43"
27
+ "@owlmeans/storage-resource": "^0.1.18-rc.44"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@owlmeans/dep-config": "workspace:*",