@worker-protocol/schemas 0.1.0 → 0.1.2
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 +96 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @worker-protocol/schemas
|
|
2
|
+
|
|
3
|
+
The Zod objects that generate the worker-protocol JSON Schemas, and the way to consume them from
|
|
4
|
+
TypeScript.
|
|
5
|
+
|
|
6
|
+
**worker-protocol is an open specification for Workers that can be seen, operated and given work by
|
|
7
|
+
people who did not build them.** HTTP and JSON Schema, no runtime. A *Worker* is any process that
|
|
8
|
+
does work on its own — a Cloudflare Worker, an Azure Function, a Convex app, a cron job in Python
|
|
9
|
+
over Postgres — and it describes itself in a Descriptor served at `/.well-known/worker-protocol`,
|
|
10
|
+
which is the one address this protocol fixes. Everything else is declared in that document.
|
|
11
|
+
|
|
12
|
+
The JSON Schemas are the normative artifact of that specification: they say what a request and a
|
|
13
|
+
response carry, and the prose defers to them. The objects in this package are the source those
|
|
14
|
+
schemas are generated from, so anyone validating or typing one of those documents works from the
|
|
15
|
+
same line the specification was published from, rather than retyping it and drifting.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm i @worker-protocol/schemas zod
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`zod` is a peer dependency (`^4.5.4`) so that your project and this package share one instance:
|
|
24
|
+
`z.infer` against an object from somewhere else is a type that does not match.
|
|
25
|
+
|
|
26
|
+
## Reading a document somebody served you
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { descriptor, EDITION } from "@worker-protocol/schemas";
|
|
30
|
+
import type * as z from "zod";
|
|
31
|
+
|
|
32
|
+
export type Descriptor = z.infer<typeof descriptor>;
|
|
33
|
+
|
|
34
|
+
const response = await fetch(new URL(".well-known/worker-protocol", baseUrl));
|
|
35
|
+
const worker: Descriptor = descriptor.parse(await response.json());
|
|
36
|
+
|
|
37
|
+
// DESC-23: the edition this Worker speaks. A reader that does not hold its MAJOR reads nothing
|
|
38
|
+
// and says so, rather than failing a Worker for a surface added after the reader was built.
|
|
39
|
+
if (worker.edition.split(".")[0] !== EDITION.split(".")[0]) {
|
|
40
|
+
throw new Error(`this reader holds edition ${EDITION}; the Worker declares ${worker.edition}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (const [name, entry] of Object.entries(worker.capabilities)) {
|
|
44
|
+
console.log(name, entry.address);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Every document this protocol defines is here and parses the same way: `health`, `error`, the page
|
|
49
|
+
envelope, a metric bucket, a Task, an Alert, an Activity, a Nudge.
|
|
50
|
+
|
|
51
|
+
## What is exported
|
|
52
|
+
|
|
53
|
+
| Group | Objects |
|
|
54
|
+
|---|---|
|
|
55
|
+
| The Descriptor | `descriptor`, `capabilityEntry`, `skillDeclaration`, `healthEntry`, `metricsEntry`, `actionsEntry`, `tasksEntry`, `alertsEntry`, `nudgesEntry`, `activityEntry`, `eventsEntry` |
|
|
56
|
+
| Names and addresses | `capabilityName`, `vendorCapabilityName`, `qualifiedName`, `address` |
|
|
57
|
+
| Health | `health`, `healthCheck`, `healthStatus` |
|
|
58
|
+
| Refusals and paging | `error`, `rejectCodes`, `retryCodes`, `page` |
|
|
59
|
+
| Metrics | `metricDeclaration`, `metricDimension`, `metricGranularity`, `metricBucket`, `metricPage`, `timeZone`, `INSTANT`, `DIMENSION_NAME` |
|
|
60
|
+
| Actions | `actionDeclaration`, `idempotencyDeclaration` |
|
|
61
|
+
| Tasks | `taskTypeDeclaration`, `task`, `taskPage` |
|
|
62
|
+
| Alerts, Activity, Nudges | `alert`, `alertSeverity`, `alertPage`, `activity`, `activityState`, `activityPage`, `nudge` |
|
|
63
|
+
| Events | `eventTypeDeclaration`, `eventDestination` |
|
|
64
|
+
| The edition and the ids | `EDITION`, `schemaId`, `SCHEMA_ID_BASE`, `registry` |
|
|
65
|
+
|
|
66
|
+
`EDITION` is the edition of worker-protocol these objects encode, and it is **not** this package's
|
|
67
|
+
version and cannot be read off it. A package version is SemVer and moves when the code moves; an
|
|
68
|
+
edition moves when the protocol does, and a patch release of this package never changes what a
|
|
69
|
+
Worker must send.
|
|
70
|
+
|
|
71
|
+
## What this package deliberately does not do
|
|
72
|
+
|
|
73
|
+
**Nothing here carries behavior of its own.** Every constraint below the surface encodes a rule the
|
|
74
|
+
specification already states, and each one cites the rule id it encodes, so a conformance report can
|
|
75
|
+
name the rule rather than the file. Where the specification has not decided something, the object is
|
|
76
|
+
deliberately permissive and says so in a comment: a schema that overstates is worse than one that
|
|
77
|
+
admits a hole, because the schema is the normative artifact.
|
|
78
|
+
|
|
79
|
+
It also looks inside nothing that belongs to a Worker. A Task's payload, an Action's input and
|
|
80
|
+
result, an event's data are the Worker's own and are declared by that Worker in its own Descriptor —
|
|
81
|
+
this protocol has no data model, and there is no object here that describes one.
|
|
82
|
+
|
|
83
|
+
## Related packages
|
|
84
|
+
|
|
85
|
+
- `@worker-protocol/hono` — the protocol's surface as Hono routes, and `mount()`: implement an
|
|
86
|
+
interface and get every address, header, envelope and refusal this protocol fixes.
|
|
87
|
+
- `@worker-protocol/client` — `consume()`: read a Worker, and take work from it.
|
|
88
|
+
- `@worker-protocol/conformance` — point it at a Worker's base URL, get a report of what it complies
|
|
89
|
+
with.
|
|
90
|
+
|
|
91
|
+
## License and name
|
|
92
|
+
|
|
93
|
+
Apache-2.0, patent grant included — implement the protocol in any product, commercial or not,
|
|
94
|
+
without asking anyone. The name is not part of that grant (Apache-2.0 §6): a claim that something
|
|
95
|
+
*speaks worker-protocol* is one this project vouches for, and the conformance tool is how it is
|
|
96
|
+
earned.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@worker-protocol/schemas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"workerProtocolEdition": "0.1",
|
|
5
5
|
"description": "The Zod objects that generate the worker-protocol JSON Schemas, and the way to consume them from TypeScript",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/rowing-tech/worker-protocol.git",
|
|
10
10
|
"directory": "packages/schemas"
|
|
11
11
|
},
|
|
12
|
-
"homepage": "https://github.com/rowing-tech/worker-protocol#readme",
|
|
12
|
+
"homepage": "https://github.com/rowing-tech/worker-protocol/tree/main/packages/schemas#readme",
|
|
13
13
|
"bugs": "https://github.com/rowing-tech/worker-protocol/issues",
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|