@owlmeans/job 0.1.18-rc.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.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @owlmeans/job
2
+
3
+ Browser-safe application job contracts. The package defines a closed `JobView`, public query and
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.
6
+
7
+ ```typescript
8
+ import { declareJobEntrypoints } from '@owlmeans/job'
9
+
10
+ export const reportJobs = declareJobEntrypoints('report-jobs', {
11
+ path: '/reports/jobs',
12
+ parent: api.reports.base,
13
+ })
14
+ ```
15
+
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`.
20
+
21
+ <!-- owlmeans:agent-guidance:start -->
22
+ ## Agent guidance
23
+
24
+ This package ships embedded agent skills under `agent-meta/`. After installing your
25
+ `@owlmeans/*` packages, run the OwlMeans agent-skills installer to place them into
26
+ your project's skill store (`.agents/skills/`):
27
+
28
+ ```sh
29
+ npx @owlmeans/agent-skills@^0.1.18-rc.30
30
+ ```
31
+
32
+ The embedded files are version-matched to this package release. Do not edit them
33
+ directly — they are regenerated on each publish. To contribute guidance edits,
34
+ open a PR against the source monorepo.
35
+ <!-- owlmeans:agent-guidance:end -->
@@ -0,0 +1,16 @@
1
+ {
2
+ "schemaVersion": 2,
3
+ "package": "@owlmeans/job",
4
+ "version": "0.1.18-rc.0",
5
+ "generatedAt": "2026-09-18T22:22:24.014Z",
6
+ "canonicalRepo": "https://github.com/owlmeans/common",
7
+ "entries": [
8
+ {
9
+ "kind": "skill",
10
+ "name": "job",
11
+ "category": "package-specific",
12
+ "file": "skills/job/SKILL.md",
13
+ "canonicalPath": ".agents/skills/job/SKILL.md"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: job
3
+ description: How to model UI-visible application jobs with the browser-safe @owlmeans/job contract, schemas and abstract HTTP/WS entrypoints. Auto-invoked when sharing job status between a server and browser without exposing queue mechanics.
4
+ user-invocable: false
5
+ ---
6
+ <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
7
+
8
+ # @owlmeans/job
9
+
10
+ **Layer:** Shared domain contract
11
+ **Install:** `"@owlmeans/job": "^0.1.18-rc.0"` in `dependencies`
12
+
13
+ Use this package only when jobs are part of the application's domain—for example, an operator
14
+ screen that manages imports or an account screen that follows an export. It is not a queue API.
15
+
16
+ ## Boundary
17
+
18
+ `JobView` is the only shape allowed across the browser boundary. It contains:
19
+
20
+ - opaque `id` and application-owned `kind`;
21
+ - normalized `JobViewStatus`;
22
+ - bounded public progress, summary, metadata, result and error;
23
+ - `cancellable` and public timestamps.
24
+
25
+ It deliberately has no queue name, processor name, technical id, payload, ownership field,
26
+ credential, retry/lock option, driver state or stack trace. Its schemas are closed against extra
27
+ top-level fields.
28
+
29
+ ## Entrypoints
30
+
31
+ ```typescript
32
+ import { declareJobEntrypoints } from '@owlmeans/job'
33
+
34
+ export const reportJobs = declareJobEntrypoints('report-jobs', {
35
+ path: '/reports/jobs',
36
+ parent: api.reports.base,
37
+ })
38
+ ```
39
+
40
+ The returned `base`, `list`, `get`, `cancel` and `watch` declarations use only ordinary guarded
41
+ HTTP/WS routes. They carry no queue transport options. Aliases are derived with
42
+ `jobEntrypointAliases(root)` so client and server agree without importing backend code.
43
+
44
+ Public list filters are closed to `status`, `kind`, `page` and `size`. Do not add arbitrary
45
+ criteria or technical fields to the shared query. A product-specific filter belongs in a safe
46
+ domain field and must be translated by the server policy.
47
+
48
+ ## Required halves
49
+
50
+ - Bind the declarations with `@owlmeans/server-job` and a mandatory `JobExposurePolicy` that
51
+ authenticates, scopes, resolves opaque ids, allowlists output and approves cancellation.
52
+ - Consume them with `@owlmeans/client-job`, which stores only `JobView` and `JobViewEvent`.
53
+ - Keep `@owlmeans/queue` and its driver in backend packages only.
54
+
55
+ ## Key exports
56
+
57
+ | Export | Purpose |
58
+ |---|---|
59
+ | `JobView` / `JobViewStatus` | Public application job model |
60
+ | `JobViewSchema` / `JobViewListSchema` | Closed response validation |
61
+ | `JobListQuery` / `JobListQuerySchema` | Closed public filtering |
62
+ | `JobViewEvent` / `JOB_EVENT` | Sanitized socket frames |
63
+ | `declareJobEntrypoints` | Abstract HTTP/WS protocol group |
64
+ | `jobEntrypointAliases` | Stable derived aliases |
65
+
66
+ ## Related
67
+
68
+ - `server-job` — backend mapper and policy bridge
69
+ - `client-job` — browser store and hooks
70
+ - `route` — generic routes remain transport-agnostic
@@ -0,0 +1,11 @@
1
+ export declare const DEFAULT_JOB_ROOT = "jobs";
2
+ export declare const DEFAULT_JOB_PATH = "/jobs";
3
+ export declare const JOB_EVENT = "job-event";
4
+ export declare enum JobViewStatus {
5
+ Queued = "queued",
6
+ Running = "running",
7
+ Succeeded = "succeeded",
8
+ Failed = "failed",
9
+ Cancelled = "cancelled"
10
+ }
11
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,SAAS,CAAA;AACtC,eAAO,MAAM,gBAAgB,UAAU,CAAA;AACvC,eAAO,MAAM,SAAS,cAAc,CAAA;AAEpC,oBAAY,aAAa;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,SAAS,cAAc;CACxB"}
@@ -0,0 +1,12 @@
1
+ export const DEFAULT_JOB_ROOT = 'jobs';
2
+ export const DEFAULT_JOB_PATH = '/jobs';
3
+ export const JOB_EVENT = 'job-event';
4
+ export var JobViewStatus;
5
+ (function (JobViewStatus) {
6
+ JobViewStatus["Queued"] = "queued";
7
+ JobViewStatus["Running"] = "running";
8
+ JobViewStatus["Succeeded"] = "succeeded";
9
+ JobViewStatus["Failed"] = "failed";
10
+ JobViewStatus["Cancelled"] = "cancelled";
11
+ })(JobViewStatus || (JobViewStatus = {}));
12
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAA;AACtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AACvC,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAA;AAEpC,MAAM,CAAN,IAAY,aAMX;AAND,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,oCAAmB,CAAA;IACnB,wCAAuB,CAAA;IACvB,kCAAiB,CAAA;IACjB,wCAAuB,CAAA;AACzB,CAAC,EANW,aAAa,KAAb,aAAa,QAMxB"}
@@ -0,0 +1,5 @@
1
+ import type { JobEntrypointAliases, JobEntrypointOptions, JobEntrypoints } from './types.js';
2
+ export declare const jobEntrypointAliases: (root?: string) => JobEntrypointAliases;
3
+ /** Declare the sanitized job projection surface shared by an API and its client. */
4
+ export declare const declareJobEntrypoints: (root?: string, opts?: JobEntrypointOptions) => JobEntrypoints;
5
+ //# sourceMappingURL=entrypoints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoints.d.ts","sourceRoot":"","sources":["../src/entrypoints.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,oBAAoB,EAAE,oBAAoB,EAAE,cAAc,EAC3D,MAAM,YAAY,CAAA;AAGnB,eAAO,MAAM,oBAAoB,UAAU,MAAM,KAAsB,oBAMrE,CAAA;AAEF,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,UAC1B,MAAM,SAA4B,oBAAoB,KAC3D,cA8BF,CAAA"}
@@ -0,0 +1,29 @@
1
+ import { DEFAULT_GUARD } from '@owlmeans/auth-common';
2
+ import { contract, openProtocol, protocol, typed } from '@owlmeans/entrypoint';
3
+ import { backend, route, RouteMethod, socket } from '@owlmeans/route';
4
+ import { DEFAULT_JOB_PATH, DEFAULT_JOB_ROOT } from './consts.js';
5
+ import { JobListQuerySchema, JobViewListSchema, JobViewSchema } from './schemas.js';
6
+ export const jobEntrypointAliases = (root = DEFAULT_JOB_ROOT) => ({
7
+ base: root,
8
+ list: `${root}:list`,
9
+ get: `${root}:get`,
10
+ cancel: `${root}:cancel`,
11
+ watch: `${root}:watch`,
12
+ });
13
+ /** Declare the sanitized job projection surface shared by an API and its client. */
14
+ export const declareJobEntrypoints = (root = DEFAULT_JOB_ROOT, opts) => {
15
+ const aliases = jobEntrypointAliases(root);
16
+ const base = {
17
+ ...(opts?.parent != null ? { parent: opts.parent } : {}),
18
+ ...(opts?.service != null ? { service: opts.service } : {}),
19
+ };
20
+ const guarded = opts?.guard === null ? undefined : { guards: opts?.guard ?? DEFAULT_GUARD };
21
+ return {
22
+ base: openProtocol(route(aliases.base, opts?.path ?? DEFAULT_JOB_PATH, backend(base)), guarded),
23
+ list: protocol(route(aliases.list, '/', backend({ parent: aliases.base })), contract.request({ query: typed(JobListQuerySchema) }, typed(JobViewListSchema))),
24
+ watch: protocol(route(aliases.watch, '/watch', socket({ parent: aliases.base })), contract(typed())),
25
+ get: protocol(route(aliases.get, '/:id', backend({ parent: aliases.base })), contract.request({ params: typed() }, typed(JobViewSchema))),
26
+ cancel: protocol(route(aliases.cancel, '/:id', backend({ parent: aliases.base, method: RouteMethod.DELETE })), contract.request({ params: typed() }, typed(JobViewSchema))),
27
+ };
28
+ };
29
+ //# sourceMappingURL=entrypoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoints.js","sourceRoot":"","sources":["../src/entrypoints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,sBAAsB,C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.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA"}
package/build/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './consts.js';
2
+ export * from './types.js';
3
+ export * from './schemas.js';
4
+ export * from './entrypoints.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { JSONSchemaType } from 'ajv';
2
+ import type { JobListQuery, JobView } from './types.js';
3
+ /** Closed public shape: broker payloads, stack traces and ownership fields have nowhere to land. */
4
+ export declare const JobViewSchema: JSONSchemaType<JobView>;
5
+ export declare const JobViewListSchema: JSONSchemaType<import("@owlmeans/resource").ListResult<JobView>>;
6
+ export declare const JobListQuerySchema: JSONSchemaType<JobListQuery>;
7
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAGzC,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAKvD,oGAAoG;AACpG,eAAO,MAAM,aAAa,EAuCV,cAAc,CAAC,OAAO,CAAC,CAAA;AAEvC,eAAO,MAAM,iBAAiB,kEAAkC,CAAA;AAEhE,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,YAAY,CAS3D,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { createListSchema } from '@owlmeans/resource';
2
+ import { JobViewStatus } from './consts.js';
3
+ const optionalNumber = { type: 'number', nullable: true };
4
+ const optionalString = { type: 'string', nullable: true };
5
+ /** Closed public shape: broker payloads, stack traces and ownership fields have nowhere to land. */
6
+ export const JobViewSchema = {
7
+ type: 'object',
8
+ properties: {
9
+ id: { type: 'string' },
10
+ kind: { type: 'string', maxLength: 128 },
11
+ status: { type: 'string', enum: Object.values(JobViewStatus) },
12
+ progress: {
13
+ type: 'object',
14
+ nullable: true,
15
+ properties: {
16
+ percent: optionalNumber,
17
+ done: optionalNumber,
18
+ total: optionalNumber,
19
+ message: { type: 'string', maxLength: 512, nullable: true },
20
+ },
21
+ required: [],
22
+ additionalProperties: false,
23
+ },
24
+ summary: { type: 'string', maxLength: 2048, nullable: true },
25
+ metadata: { type: 'object', required: [], additionalProperties: true, nullable: true },
26
+ result: {},
27
+ error: {
28
+ type: 'object',
29
+ nullable: true,
30
+ properties: {
31
+ type: { type: 'string', maxLength: 128 },
32
+ message: { type: 'string', maxLength: 2048 },
33
+ },
34
+ required: ['type', 'message'],
35
+ additionalProperties: false,
36
+ },
37
+ cancellable: { type: 'boolean' },
38
+ createdAt: { type: 'string', format: 'date-time' },
39
+ updatedAt: { type: 'string', format: 'date-time' },
40
+ startedAt: optionalString,
41
+ finishedAt: optionalString,
42
+ },
43
+ required: ['id', 'kind', 'status', 'cancellable', 'createdAt', 'updatedAt'],
44
+ additionalProperties: false,
45
+ };
46
+ export const JobViewListSchema = createListSchema(JobViewSchema);
47
+ export const JobListQuerySchema = {
48
+ type: 'object',
49
+ properties: {
50
+ status: { type: 'string', enum: Object.values(JobViewStatus), nullable: true },
51
+ kind: { type: 'string', maxLength: 128, nullable: true },
52
+ page: { type: 'number', minimum: 0, nullable: true },
53
+ size: { type: 'number', minimum: 1, maximum: 100, nullable: true },
54
+ },
55
+ additionalProperties: false,
56
+ };
57
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schem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CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE;KACnE;IACD,oBAAoB,EAAE,KAAK;CAC5B,CAAA"}
@@ -0,0 +1,77 @@
1
+ import type { EntrypointProtocol, OpenRequest, OpenValue } from '@owlmeans/entrypoint';
2
+ import type { ResourceRecord } from '@owlmeans/resource';
3
+ import type { RouteParent } from '@owlmeans/route';
4
+ import type { JobViewStatus } from './consts.js';
5
+ export type JobJson = null | boolean | number | string | JobJson[] | {
6
+ [key: string]: JobJson;
7
+ };
8
+ export interface JobProgressView {
9
+ percent?: number;
10
+ done?: number;
11
+ total?: number;
12
+ message?: string;
13
+ }
14
+ export interface PublicJobError {
15
+ type: string;
16
+ message: string;
17
+ }
18
+ /** The only application-job shape allowed across a browser boundary. */
19
+ export interface JobView extends ResourceRecord {
20
+ id: string;
21
+ kind: string;
22
+ status: JobViewStatus;
23
+ progress?: JobProgressView;
24
+ summary?: string;
25
+ metadata?: Record<string, JobJson>;
26
+ result?: JobJson;
27
+ error?: PublicJobError;
28
+ cancellable: boolean;
29
+ createdAt: string;
30
+ updatedAt: string;
31
+ startedAt?: string;
32
+ finishedAt?: string;
33
+ }
34
+ export type JobViewEvent = {
35
+ type: 'upsert';
36
+ job: JobView;
37
+ } | {
38
+ type: 'remove';
39
+ id: string;
40
+ };
41
+ export interface JobListQuery {
42
+ status?: JobViewStatus;
43
+ kind?: string;
44
+ page?: number;
45
+ size?: number;
46
+ }
47
+ export interface JobEntrypointAliases {
48
+ base: string;
49
+ list: string;
50
+ get: string;
51
+ cancel: string;
52
+ watch: string;
53
+ }
54
+ export interface JobEntrypoints {
55
+ base: EntrypointProtocol<OpenRequest, OpenValue>;
56
+ list: EntrypointProtocol<{
57
+ query: JobListQuery;
58
+ }, unknown>;
59
+ get: EntrypointProtocol<{
60
+ params: {
61
+ id: string;
62
+ };
63
+ }, unknown>;
64
+ cancel: EntrypointProtocol<{
65
+ params: {
66
+ id: string;
67
+ };
68
+ }, unknown>;
69
+ watch: EntrypointProtocol<OpenRequest, void>;
70
+ }
71
+ export interface JobEntrypointOptions {
72
+ path?: string;
73
+ parent?: RouteParent;
74
+ service?: string;
75
+ guard?: string | null;
76
+ }
77
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,MAAM,MAAM,OAAO,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAA;AAE/F,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wEAAwE;AACxE,MAAM,WAAW,OAAQ,SAAQ,cAAc;IAC7C,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,aAAa,CAAA;IACrB,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC,MAAM,CAAC,EAAE,OAAO,CAA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AED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB"}
package/build/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@owlmeans/job",
3
+ "version": "0.1.18-rc.0",
4
+ "license": "MIT",
5
+ "description": "Browser-safe application job projections, schemas and entrypoint contracts.",
6
+ "type": "module",
7
+ "scripts": {
8
+ "build": "tsc -b",
9
+ "watch": "tsc -b -w --preserveWatchOutput --pretty",
10
+ "test": "bun test ./tests"
11
+ },
12
+ "main": "build/index.js",
13
+ "module": "build/index.js",
14
+ "types": "build/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./build/index.js",
18
+ "require": "./build/index.js",
19
+ "default": "./build/index.js",
20
+ "module": "./build/index.js",
21
+ "types": "./build/index.d.ts"
22
+ }
23
+ },
24
+ "dependencies": {
25
+ "@owlmeans/auth-common": "^0.1.18-rc.30",
26
+ "@owlmeans/entrypoint": "^0.1.18-rc.29",
27
+ "@owlmeans/resource": "^0.1.18-rc.28",
28
+ "@owlmeans/route": "^0.1.18-rc.27"
29
+ },
30
+ "devDependencies": {
31
+ "@owlmeans/dep-config": "workspace:*",
32
+ "@types/bun": "^1.4.0",
33
+ "ajv": "^8.17.1",
34
+ "typescript": "^7.0.2"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ }
39
+ }
package/src/consts.ts ADDED
@@ -0,0 +1,11 @@
1
+ export const DEFAULT_JOB_ROOT = 'jobs'
2
+ export const DEFAULT_JOB_PATH = '/jobs'
3
+ export const JOB_EVENT = 'job-event'
4
+
5
+ export enum JobViewStatus {
6
+ Queued = 'queued',
7
+ Running = 'running',
8
+ Succeeded = 'succeeded',
9
+ Failed = 'failed',
10
+ Cancelled = 'cancelled',
11
+ }
@@ -0,0 +1,53 @@
1
+ import { DEFAULT_GUARD } from '@owlmeans/auth-common'
2
+ import { contract, openProtocol, protocol, typed } from '@owlmeans/entrypoint'
3
+ import { backend, route, RouteMethod, socket } from '@owlmeans/route'
4
+ import type { RouteOptions } from '@owlmeans/route'
5
+ import { DEFAULT_JOB_PATH, DEFAULT_JOB_ROOT } from './consts.js'
6
+ import { JobListQuerySchema, JobViewListSchema, JobViewSchema } from './schemas.js'
7
+ import type {
8
+ JobEntrypointAliases, JobEntrypointOptions, JobEntrypoints, JobListQuery, JobView,
9
+ } from './types.js'
10
+ import type { ListResult } from '@owlmeans/resource'
11
+
12
+ export const jobEntrypointAliases = (root: string = DEFAULT_JOB_ROOT): JobEntrypointAliases => ({
13
+ base: root,
14
+ list: `${root}:list`,
15
+ get: `${root}:get`,
16
+ cancel: `${root}:cancel`,
17
+ watch: `${root}:watch`,
18
+ })
19
+
20
+ /** Declare the sanitized job projection surface shared by an API and its client. */
21
+ export const declareJobEntrypoints = (
22
+ root: string = DEFAULT_JOB_ROOT, opts?: JobEntrypointOptions
23
+ ): JobEntrypoints => {
24
+ const aliases = jobEntrypointAliases(root)
25
+ const base: Partial<RouteOptions> = {
26
+ ...(opts?.parent != null ? { parent: opts.parent } : {}),
27
+ ...(opts?.service != null ? { service: opts.service } : {}),
28
+ }
29
+ const guarded = opts?.guard === null ? undefined : { guards: opts?.guard ?? DEFAULT_GUARD }
30
+
31
+ return {
32
+ base: openProtocol(route(aliases.base, opts?.path ?? DEFAULT_JOB_PATH, backend(base)), guarded),
33
+ list: protocol(
34
+ route(aliases.list, '/', backend({ parent: aliases.base })),
35
+ contract.request(
36
+ { query: typed<JobListQuery>(JobListQuerySchema) },
37
+ typed<ListResult<JobView>>(JobViewListSchema)
38
+ )
39
+ ),
40
+ watch: protocol(
41
+ route(aliases.watch, '/watch', socket({ parent: aliases.base })),
42
+ contract(typed<void>())
43
+ ),
44
+ get: protocol(
45
+ route(aliases.get, '/:id', backend({ parent: aliases.base })),
46
+ contract.request({ params: typed<{ id: string }>() }, typed<JobView>(JobViewSchema))
47
+ ),
48
+ cancel: protocol(
49
+ route(aliases.cancel, '/:id', backend({ parent: aliases.base, method: RouteMethod.DELETE })),
50
+ contract.request({ params: typed<{ id: string }>() }, typed<JobView>(JobViewSchema))
51
+ ),
52
+ }
53
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './consts.js'
2
+ export * from './types.js'
3
+ export * from './schemas.js'
4
+ export * from './entrypoints.js'
package/src/schemas.ts ADDED
@@ -0,0 +1,62 @@
1
+ import type { JSONSchemaType } from 'ajv'
2
+ import { createListSchema } from '@owlmeans/resource'
3
+ import { JobViewStatus } from './consts.js'
4
+ import type { JobListQuery, JobView } from './types.js'
5
+
6
+ const optionalNumber = { type: 'number', nullable: true } as const
7
+ const optionalString = { type: 'string', nullable: true } as const
8
+
9
+ /** Closed public shape: broker payloads, stack traces and ownership fields have nowhere to land. */
10
+ export const JobViewSchema = {
11
+ type: 'object',
12
+ properties: {
13
+ id: { type: 'string' },
14
+ kind: { type: 'string', maxLength: 128 },
15
+ status: { type: 'string', enum: Object.values(JobViewStatus) },
16
+ progress: {
17
+ type: 'object',
18
+ nullable: true,
19
+ properties: {
20
+ percent: optionalNumber,
21
+ done: optionalNumber,
22
+ total: optionalNumber,
23
+ message: { type: 'string', maxLength: 512, nullable: true },
24
+ },
25
+ required: [],
26
+ additionalProperties: false,
27
+ },
28
+ summary: { type: 'string', maxLength: 2048, nullable: true },
29
+ metadata: { type: 'object', required: [], additionalProperties: true, nullable: true },
30
+ result: {},
31
+ error: {
32
+ type: 'object',
33
+ nullable: true,
34
+ properties: {
35
+ type: { type: 'string', maxLength: 128 },
36
+ message: { type: 'string', maxLength: 2048 },
37
+ },
38
+ required: ['type', 'message'],
39
+ additionalProperties: false,
40
+ },
41
+ cancellable: { type: 'boolean' },
42
+ createdAt: { type: 'string', format: 'date-time' },
43
+ updatedAt: { type: 'string', format: 'date-time' },
44
+ startedAt: optionalString,
45
+ finishedAt: optionalString,
46
+ },
47
+ required: ['id', 'kind', 'status', 'cancellable', 'createdAt', 'updatedAt'],
48
+ additionalProperties: false,
49
+ } as unknown as JSONSchemaType<JobView>
50
+
51
+ export const JobViewListSchema = createListSchema(JobViewSchema)
52
+
53
+ export const JobListQuerySchema: JSONSchemaType<JobListQuery> = {
54
+ type: 'object',
55
+ properties: {
56
+ status: { type: 'string', enum: Object.values(JobViewStatus), nullable: true },
57
+ kind: { type: 'string', maxLength: 128, nullable: true },
58
+ page: { type: 'number', minimum: 0, nullable: true },
59
+ size: { type: 'number', minimum: 1, maximum: 100, nullable: true },
60
+ },
61
+ additionalProperties: false,
62
+ }
package/src/types.ts ADDED
@@ -0,0 +1,69 @@
1
+ import type { EntrypointProtocol, OpenRequest, OpenValue } from '@owlmeans/entrypoint'
2
+ import type { ResourceRecord } from '@owlmeans/resource'
3
+ import type { RouteParent } from '@owlmeans/route'
4
+ import type { JobViewStatus } from './consts.js'
5
+
6
+ export type JobJson = null | boolean | number | string | JobJson[] | { [key: string]: JobJson }
7
+
8
+ export interface JobProgressView {
9
+ percent?: number
10
+ done?: number
11
+ total?: number
12
+ message?: string
13
+ }
14
+
15
+ export interface PublicJobError {
16
+ type: string
17
+ message: string
18
+ }
19
+
20
+ /** The only application-job shape allowed across a browser boundary. */
21
+ export interface JobView extends ResourceRecord {
22
+ id: string
23
+ kind: string
24
+ status: JobViewStatus
25
+ progress?: JobProgressView
26
+ summary?: string
27
+ metadata?: Record<string, JobJson>
28
+ result?: JobJson
29
+ error?: PublicJobError
30
+ cancellable: boolean
31
+ createdAt: string
32
+ updatedAt: string
33
+ startedAt?: string
34
+ finishedAt?: string
35
+ }
36
+
37
+ export type JobViewEvent =
38
+ | { type: 'upsert', job: JobView }
39
+ | { type: 'remove', id: string }
40
+
41
+ export interface JobListQuery {
42
+ status?: JobViewStatus
43
+ kind?: string
44
+ page?: number
45
+ size?: number
46
+ }
47
+
48
+ export interface JobEntrypointAliases {
49
+ base: string
50
+ list: string
51
+ get: string
52
+ cancel: string
53
+ watch: string
54
+ }
55
+
56
+ export interface JobEntrypoints {
57
+ base: EntrypointProtocol<OpenRequest, OpenValue>
58
+ list: EntrypointProtocol<{ query: JobListQuery }, unknown>
59
+ get: EntrypointProtocol<{ params: { id: string } }, unknown>
60
+ cancel: EntrypointProtocol<{ params: { id: string } }, unknown>
61
+ watch: EntrypointProtocol<OpenRequest, void>
62
+ }
63
+
64
+ export interface JobEntrypointOptions {
65
+ path?: string
66
+ parent?: RouteParent
67
+ service?: string
68
+ guard?: string | null
69
+ }
@@ -0,0 +1,45 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import Ajv from 'ajv'
3
+ import addFormats from 'ajv-formats'
4
+ import { protocols } from '@owlmeans/entrypoint'
5
+ import { RouteProtocols } from '@owlmeans/route'
6
+ import {
7
+ declareJobEntrypoints, JobViewListSchema, JobViewSchema, JobViewStatus,
8
+ } from '../src/index.js'
9
+
10
+ const compiler = () => addFormats(new Ajv({ strict: false }))
11
+
12
+ describe('@owlmeans/job — browser-safe job projections', () => {
13
+ test('the closed public schema accepts a safe view and rejects broker fields', () => {
14
+ const validate = compiler().compile(JobViewSchema)
15
+ const view = {
16
+ id: 'opaque-1', kind: 'report', status: JobViewStatus.Running,
17
+ progress: { percent: 40, message: 'Rendering' }, cancellable: true,
18
+ createdAt: '2026-09-18T10:00:00.000Z', updatedAt: '2026-09-18T10:01:00.000Z',
19
+ }
20
+
21
+ expect(validate(view)).toBe(true)
22
+ expect(validate({ ...view, queue: 'internal', data: { accessToken: 'secret' } })).toBe(false)
23
+ })
24
+
25
+ test('the list envelope compiles and keeps each item closed', () => {
26
+ const validate = compiler().compile(JobViewListSchema)
27
+ const item = {
28
+ id: 'opaque-1', kind: 'report', status: JobViewStatus.Succeeded, cancellable: false,
29
+ createdAt: '2026-09-18T10:00:00.000Z', updatedAt: '2026-09-18T10:01:00.000Z',
30
+ }
31
+
32
+ expect(validate({ items: [item], total: 1 })).toBe(true)
33
+ expect(validate({ items: [{ ...item, failedReason: 'raw stack' }], total: 1 })).toBe(false)
34
+ })
35
+
36
+ test('the shared route contract is HTTP/WS only and carries no broker address', () => {
37
+ const tree = declareJobEntrypoints('exports', { service: 'api' })
38
+ const declarations = protocols(tree).map(entrypoint => entrypoint.route.route)
39
+
40
+ expect(declarations.map(route => route.protocol)).toEqual([
41
+ undefined, undefined, RouteProtocols.SOCKET, undefined, undefined,
42
+ ])
43
+ expect(declarations.every(route => route.protocolOptions == null)).toBe(true)
44
+ })
45
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": [
3
+ "@owlmeans/dep-config/tsconfig.base.json"
4
+ ],
5
+ "compilerOptions": {
6
+ "rootDir": "./src/",
7
+ "outDir": "./build/"
8
+ },
9
+ "exclude": [
10
+ "./dist/**/*",
11
+ "./build/**/*",
12
+ "./tests/**/*",
13
+ "./*.ts"
14
+ ]
15
+ }