@owlmeans/job 0.1.18-rc.9 → 0.1.18

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
@@ -2,7 +2,37 @@
2
2
 
3
3
  Browser-safe application job contracts. The package defines a closed `JobView`, public query and
4
4
  event schemas, and ordinary HTTP/WS entrypoint declarations. It has no queue dependency and carries
5
- no queue address, transport payload, ownership field, credential or raw failure.
5
+ no queue address, transport payload, ownership field, credential or raw failure. An app uses it when
6
+ jobs are part of its domain — an operator screen that manages imports, an account screen that
7
+ follows an export — and declares the job surface once in its shared (common) package. It is not a
8
+ queue API: enqueueing and processing work is `@owlmeans/queue` on the backend, and a backend-only
9
+ job that no screen shows needs no `@owlmeans/job` at all. The package's skill is `job`.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ bun add @owlmeans/job@^0.1.18
15
+ ```
16
+
17
+ Install `ajv` alongside it when the schemas are compiled in the consuming process.
18
+
19
+ ## Concepts
20
+
21
+ - **Job view** — `JobView`, the only job shape allowed across the browser boundary: opaque `id`,
22
+ application-owned `kind`, normalized `JobViewStatus`, bounded progress/summary/metadata/result,
23
+ a public `error`, `cancellable` and ISO timestamps.
24
+ - **Closed schema** — `JobViewSchema` rejects every top-level field it does not name, so a broker
25
+ payload, stack trace or ownership field has nowhere to land.
26
+ - **Job entrypoints** — one guarded group per root: `base` (open protocol carrying the guard),
27
+ `list` (`GET /`), `get` (`GET /:id`), `cancel` (`DELETE /:id`) and `watch` (socket `/watch`).
28
+ - **Aliases** — derived from the root by `jobEntrypointAliases(root)` (`<root>`, `<root>:list`, …),
29
+ so client and server agree without importing each other.
30
+ - **Job event** — `JobViewEvent`, a socket frame sent under `JOB_EVENT`: `upsert` with the whole
31
+ view, or `remove` with the opaque id.
32
+
33
+ ## Usage
34
+
35
+ ### Declare the job surface in the shared package
6
36
 
7
37
  ```typescript
8
38
  import { declareJobEntrypoints } from '@owlmeans/job'
@@ -13,10 +43,108 @@ export const reportJobs = declareJobEntrypoints('report-jobs', {
13
43
  })
14
44
  ```
15
45
 
16
- `JobView` exposes only an opaque id, application kind, normalized status, bounded progress,
17
- allowlisted metadata/result/error, cancellation availability and timestamps. The server maps its
18
- technical records with `@owlmeans/server-job`; the browser consumes views with
19
- `@owlmeans/client-job`.
46
+ `JobEntrypointOptions` takes `path` (default `DEFAULT_JOB_PATH`, `'/jobs'`), `parent`, `service`
47
+ and `guard`. The guard defaults to `DEFAULT_GUARD` from `@owlmeans/auth-common`; pass another guard
48
+ alias to change it, or `null` to declare the group unguarded.
49
+
50
+ ### Bind it on the server
51
+
52
+ The server half maps technical queue records into views through a mandatory exposure policy in
53
+ `@owlmeans/server-job`:
54
+
55
+ ```typescript
56
+ import { serveJobEntrypoints } from '@owlmeans/server-job'
57
+
58
+ export const reportJobHandlers = serveJobEntrypoints(reportJobs, { policy: reportJobPolicy })
59
+ ```
60
+
61
+ ### Consume it in the browser
62
+
63
+ `@owlmeans/client-job` stores only `JobView` and applies `JobViewEvent` frames:
64
+
65
+ ```tsx
66
+ import { JobViewStatus } from '@owlmeans/job'
67
+ import { useJobFeed, useJobs } from '@owlmeans/client-job'
68
+
69
+ const { seeded, connected, error } = useJobFeed({
70
+ root: 'report-jobs',
71
+ query: { status: JobViewStatus.Running, size: 50 },
72
+ })
73
+ const running = useJobs({ status: JobViewStatus.Running })
74
+ ```
75
+
76
+ ### Validate a view
77
+
78
+ ```typescript
79
+ import Ajv from 'ajv'
80
+ import addFormats from 'ajv-formats'
81
+ import { JobViewSchema, JobViewStatus } from '@owlmeans/job'
82
+
83
+ const validate = addFormats(new Ajv({ strict: false })).compile(JobViewSchema)
84
+
85
+ validate({
86
+ id: 'opaque-1', kind: 'report', status: JobViewStatus.Running,
87
+ progress: { percent: 40, message: 'Rendering' }, cancellable: true,
88
+ createdAt: '2026-09-18T10:00:00.000Z', updatedAt: '2026-09-18T10:01:00.000Z',
89
+ }) // true — the same object with a `queue` or `data` field is rejected
90
+ ```
91
+
92
+ ## API
93
+
94
+ ### Functions
95
+
96
+ | Symbol | Purpose |
97
+ |---|---|
98
+ | `declareJobEntrypoints(root?, opts?)` | `JobEntrypoints` group: `base`, `list`, `get`, `cancel`, `watch` (root defaults to `DEFAULT_JOB_ROOT`) |
99
+ | `jobEntrypointAliases(root?)` | `JobEntrypointAliases` derived from the root |
100
+
101
+ ### Schemas
102
+
103
+ | Symbol | Purpose |
104
+ |---|---|
105
+ | `JobViewSchema` | Closed `JSONSchemaType<JobView>` |
106
+ | `JobViewListSchema` | `ListResult<JobView>` envelope built with `createListSchema` |
107
+ | `JobListQuerySchema` | Closed query: `status`, `kind`, `page` (≥ 0), `size` (1–100) |
108
+
109
+ ### Constants
110
+
111
+ | Symbol | Value |
112
+ |---|---|
113
+ | `DEFAULT_JOB_ROOT` | `'jobs'` |
114
+ | `DEFAULT_JOB_PATH` | `'/jobs'` |
115
+ | `JOB_EVENT` | `'job-event'` — socket event name for `JobViewEvent` frames |
116
+ | `JobViewStatus` | enum: `Queued`, `Running`, `Succeeded`, `Failed`, `Cancelled` |
117
+
118
+ ### Types
119
+
120
+ | Symbol | Purpose |
121
+ |---|---|
122
+ | `JobView` | The public job record (extends `ResourceRecord`) |
123
+ | `JobProgressView` | `{ percent?, done?, total?, message? }` |
124
+ | `PublicJobError` | `{ type, message }` — never a raw failure |
125
+ | `JobJson` | JSON value allowed in `metadata` and `result` |
126
+ | `JobViewEvent` | `{ type: 'upsert', job }` \| `{ type: 'remove', id }` |
127
+ | `JobListQuery` | Public list filter |
128
+ | `JobEntrypoints`, `JobEntrypointAliases`, `JobEntrypointOptions` | The declared group, its aliases, declaration options |
129
+
130
+ ## Common pitfalls
131
+
132
+ - Do not widen `JobListQuery` with arbitrary criteria or technical fields; a product-specific filter
133
+ belongs in a safe domain field that the server policy translates.
134
+ - Do not put queue names, processor names, technical ids, payloads or credentials into `metadata` or
135
+ `result` — the schema is closed at the top level only, and those two are free-form JSON.
136
+ - Keep `@owlmeans/queue` and its driver out of browser and shared packages; this package is the only
137
+ job dependency a shared package needs.
138
+ - Client and server must use the same root, or the derived aliases will not meet.
139
+
140
+ ## Related packages
141
+
142
+ - [`@owlmeans/server-job`](../server-job) — binds the group to handlers through a `JobExposurePolicy`
143
+ - [`@owlmeans/client-job`](../client-job) — browser store, `useJobFeed`, `useJob`, `useJobs`
144
+ - [`@owlmeans/queue`](../queue) — the backend queue whose records the server maps into views
145
+ - [`@owlmeans/route`](../route) — the transport-agnostic routes the declarations use
146
+ - [`@owlmeans/entrypoint`](../entrypoint) — `protocol` / `contract` declarations
147
+ - [`@owlmeans/resource`](../resource) — `ListResult` and `createListSchema`
20
148
 
21
149
  <!-- owlmeans:agent-guidance:start -->
22
150
  ## Agent guidance
@@ -26,7 +154,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
26
154
  your project's skill store (`.agents/skills/`):
27
155
 
28
156
  ```sh
29
- npx @owlmeans/agent-skills@^0.1.18-rc.40
157
+ npx @owlmeans/agent-skills@^0.1.18
30
158
  ```
31
159
 
32
160
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
- "schemaVersion": 2,
2
+ "schemaVersion": 3,
3
3
  "package": "@owlmeans/job",
4
- "version": "0.1.18-rc.9",
5
- "generatedAt": "2026-09-25T21:19:37.984Z",
4
+ "version": "0.1.18",
5
+ "generatedAt": "2026-10-28T00:31:34.759Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -8,7 +8,7 @@ user-invocable: false
8
8
  # @owlmeans/job
9
9
 
10
10
  **Layer:** Shared domain contract
11
- **Install:** `"@owlmeans/job": "^0.1.18-rc.9"` in `dependencies`
11
+ **Install:** `"@owlmeans/job": "^0.1.18"` in `dependencies`
12
12
 
13
13
  Use this package only when jobs are part of the application's domain—for example, an operator
14
14
  screen that manages imports or an account screen that follows an export. It is not a queue API.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/job",
3
- "version": "0.1.18-rc.9",
3
+ "version": "0.1.18",
4
4
  "license": "MIT",
5
5
  "description": "Browser-safe application job projections, schemas and entrypoint contracts.",
6
6
  "type": "module",
@@ -22,15 +22,15 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@owlmeans/auth-common": "^0.1.18-rc.39",
26
- "@owlmeans/entrypoint": "^0.1.18-rc.37",
27
- "@owlmeans/resource": "^0.1.18-rc.36",
28
- "@owlmeans/route": "^0.1.18-rc.33"
25
+ "@owlmeans/auth-common": "^0.1.18",
26
+ "@owlmeans/entrypoint": "^0.1.18",
27
+ "@owlmeans/resource": "^0.1.18",
28
+ "@owlmeans/route": "^0.1.18"
29
29
  },
30
30
  "devDependencies": {
31
- "@owlmeans/dep-config": "workspace:*",
32
- "@types/bun": "^1.4.0",
33
- "ajv": "^8.17.1",
31
+ "@owlmeans/dep-config": "^0.1.18",
32
+ "@types/bun": "^1.4.2",
33
+ "ajv": "^8.20.0",
34
34
  "typescript": "^7.0.2"
35
35
  },
36
36
  "publishConfig": {