@owlmeans/server-api 0.1.18-rc.16 → 0.1.18-rc.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 +2 -2
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-api/SKILL.md +138 -24
- package/build/errors.d.ts.map +1 -1
- package/build/errors.js.map +1 -1
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +10 -1
- package/build/helper.js.map +1 -1
- package/build/hold.d.ts.map +1 -1
- package/build/hold.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/protocol.d.ts +26 -0
- package/build/protocol.d.ts.map +1 -0
- package/build/protocol.js +41 -0
- package/build/protocol.js.map +1 -0
- package/build/server.d.ts.map +1 -1
- package/build/server.js.map +1 -1
- package/build/utils/context.d.ts.map +1 -1
- package/build/utils/error.d.ts.map +1 -1
- package/build/utils/guards.d.ts.map +1 -1
- package/build/utils/payload.d.ts.map +1 -1
- package/build/utils/server.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/helper.ts +10 -1
- package/src/index.ts +1 -0
- package/src/protocol.ts +104 -0
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Fastify-based HTTP/WebSocket server with handler wrappers for the OwlMeans entry
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
bun add @owlmeans/server-api
|
|
15
|
+
bun add @owlmeans/server-api@^0.1.18-rc.16
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
@@ -84,7 +84,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
84
84
|
your project's skill store (`.agents/skills/`):
|
|
85
85
|
|
|
86
86
|
```sh
|
|
87
|
-
npx @owlmeans/agent-skills
|
|
87
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.13
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/server-api",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-09-
|
|
4
|
+
"version": "0.1.18-rc.18",
|
|
5
|
+
"generatedAt": "2026-09-10T18:54:42.484Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: server-api
|
|
3
|
-
description: How to use @owlmeans/server-api — Fastify-based API server factory, request
|
|
3
|
+
description: How to use @owlmeans/server-api — typed protocol handlers, the Fastify-based API server factory, request pipeline, validation, holdApiPort() boot window, and error-to-status mapping. Auto-invoked when importing server-api types, writing protocol handlers, extending the middleware stack, or working out why a request answered the status it did.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
@@ -8,54 +8,154 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/server-api
|
|
9
9
|
|
|
10
10
|
**Layer:** Server
|
|
11
|
-
**Install:** `"@owlmeans/server-api": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/server-api": "^0.1.18-rc.18"` in `dependencies`
|
|
12
12
|
|
|
13
13
|
## Key Exports
|
|
14
14
|
|
|
15
15
|
| Export | Description |
|
|
16
16
|
|--------|-------------|
|
|
17
|
+
| `handlers<Context>()` | Build `body`, `params`, and `request` handlers inferred from an immutable protocol |
|
|
18
|
+
| `uploadedFile(request)` | Read Fastify multipart through the typed handler boundary |
|
|
17
19
|
| `createApiServer(alias)` | Factory for the Fastify-based API server |
|
|
18
20
|
| `appendApiServer(ctx, alias?)` | Register it and expose `ctx.getApiServer()` |
|
|
19
21
|
| `handleRequest` / `handleBody` / `handleParams` / `handleIntermediate` | Wrap an async function as an entrypoint handler |
|
|
20
|
-
| `extractUploadedFile(req)` | The multipart file behind a request |
|
|
21
|
-
| `holdApiPort(cfg,
|
|
22
|
-
| `ApiServer`, `Request`, `Response`
|
|
23
|
-
| `
|
|
24
|
-
|
|
|
22
|
+
| `extractUploadedFile(req)` | The multipart file behind a request, as `UploadedFile` |
|
|
23
|
+
| `holdApiPort(cfg, opts?)` | Own the app's port during boot; the caller awaits `hold.release()` before `listen()` |
|
|
24
|
+
| `ApiServer`, `ApiServerAppend`, `Request`, `Response`, `Config`, `Context` | Runtime and context shapes |
|
|
25
|
+
| `ApiPortHold`, `ApiPortHoldOptions` | The hold handle and its `{ okPath?, payload? }` options |
|
|
26
|
+
| `AuthFailedError` | Raised by the request pipeline when no guard matched or the matching guard refused — the only one of this package's own two errors the pipeline raises |
|
|
27
|
+
| `AccessError` | Its 403 counterpart, for a guard, gate or handler to throw when an established identity lacks the permission; the pipeline never raises it |
|
|
28
|
+
| `NoFileError` | For a handler to throw when `extractUploadedFile` finds no file; the pipeline never raises it |
|
|
29
|
+
| Constants | `DEFAULT_ALIAS` (`api-server`), `PORT` (`80`), `CLOSED_HOST` (`127.0.0.1`), `OPENED_HOST` (`0.0.0.0`) |
|
|
25
30
|
|
|
26
31
|
## Subpath Exports
|
|
27
32
|
|
|
28
33
|
- `./utils` — `handleError`, `authorize`, `provideRequest`, `executeResponse`, `populateContext`, `extractContext`, `canServeModule`, `createServerHandler`, `fixFormatDates`
|
|
29
34
|
|
|
30
|
-
## What this server mounts
|
|
31
|
-
|
|
32
|
-
`canServeModule` mounts a backend entrypoint only when the route belongs to this service AND its
|
|
33
|
-
protocol is one HTTP carries. `SOCKET` and `QUEUE` are excluded: a socket is upgraded elsewhere and
|
|
34
|
-
a queued job is taken off the broker by the worker, so mounting either here would answer the same
|
|
35
|
-
call twice. Adding a protocol means excluding it here as well as binding its transport.
|
|
36
|
-
|
|
37
35
|
## Usage
|
|
38
36
|
|
|
39
|
-
The server is normally constructed transparently by `@owlmeans/server-app#main()`. Use `server-api`
|
|
37
|
+
The server is normally constructed transparently by `@owlmeans/server-app#main()`. Use `server-api`
|
|
38
|
+
directly only when you need to register raw Fastify plugins or customize transport:
|
|
40
39
|
|
|
41
40
|
```typescript
|
|
42
41
|
import { appendApiServer } from '@owlmeans/server-api'
|
|
43
42
|
appendApiServer(context)
|
|
44
43
|
```
|
|
45
44
|
|
|
45
|
+
## Writing handlers
|
|
46
|
+
|
|
47
|
+
For a typed protocol, pass the declaration once and let `handlers<Context>()` infer every request
|
|
48
|
+
section and the response. `body` and `params` are available only when the protocol contract
|
|
49
|
+
declares that section; `request` receives the complete typed request plus alias/auth/entity/path
|
|
50
|
+
metadata.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const handle = handlers<Context>()
|
|
54
|
+
|
|
55
|
+
export const create = handle.body(item.create, async (payload, context, request) => {
|
|
56
|
+
const owner = request.entity?.id
|
|
57
|
+
return await context.resource<ItemResource>('item').create({ ...payload, owner })
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The result is a protocol-bound implementation consumed by `bind(protocol, implementation)` from
|
|
62
|
+
`@owlmeans/server-entrypoint` (both exports are available from `@owlmeans/server-app`). Throwing is
|
|
63
|
+
still the failure path; the wrapper resolves successful returns with `EntrypointOutcome.Ok`.
|
|
64
|
+
Use `uploadedFile(request)` when the protocol handler needs the Fastify multipart object.
|
|
65
|
+
|
|
66
|
+
For a legacy entrypoint, `handleRequest(fn)` gives the whole request, `handleBody<T>(fn)` the
|
|
67
|
+
validated body, `handleParams<T>(fn)` the validated URL params, and `handleIntermediate(fn)` a
|
|
68
|
+
function that returns a context (or `null` to leave the chain unchanged) instead of a value.
|
|
69
|
+
|
|
70
|
+
All handler forms resolve the handler's context the same
|
|
71
|
+
way: from the request when it arrived over HTTP, and from the entrypoint's own context otherwise —
|
|
72
|
+
the same handler runs unchanged when a queued job or a socket frame reaches it, and only the way it
|
|
73
|
+
was reached differs.
|
|
74
|
+
|
|
75
|
+
Throwing is the way to fail. A handler owns no status table; see the mapping below.
|
|
76
|
+
|
|
77
|
+
## What this server mounts
|
|
78
|
+
|
|
79
|
+
`canServeModule` mounts a backend entrypoint only when the route's type is `Backend`, the route
|
|
80
|
+
belongs to this service, its protocol is one HTTP carries, and the declaration has been elevated —
|
|
81
|
+
the last test is `isIntermediate` on the route model, which only a server route model has. `SOCKET`
|
|
82
|
+
and `QUEUE` are excluded: a socket is upgraded elsewhere and a queued job is taken off the broker by
|
|
83
|
+
the worker, so mounting either here would answer the same call twice. Adding a protocol means
|
|
84
|
+
excluding it here as well as binding its transport.
|
|
85
|
+
|
|
46
86
|
## Where a route is bound
|
|
47
87
|
|
|
48
88
|
Every route is registered at `entrypoint.mount()` — `base` plus every ancestor's segment, then this
|
|
49
89
|
one. A declaration states only the segment it contributes, so the full address takes the context the
|
|
50
90
|
entrypoint is registered in, and the table can therefore only be built once the context has resolved.
|
|
51
|
-
Intermediates are not bound as routes: they run in a `preHandler` hook
|
|
52
|
-
`entrypoint.route.match(request, entrypoint.mount())` against the same mounted path
|
|
53
|
-
context it produced down the chain.
|
|
91
|
+
Intermediates are not bound as routes: they run in a `preHandler` hook, each testing
|
|
92
|
+
`entrypoint.route.match(request, entrypoint.mount())` against the same mounted path and passing the
|
|
93
|
+
context it produced down the chain. Once one of them has answered, the rest are skipped.
|
|
54
94
|
|
|
55
95
|
A route is bound only when its entrypoint carries a `handle`. Guards and gates come from
|
|
56
96
|
`getGuards()` / `getGates()`, which include everything the ancestors declared, and they run before
|
|
57
97
|
the handler — a handler that re-checks them is duplicating an enforced rule.
|
|
58
98
|
|
|
99
|
+
## Guards, and the organization entity they resolve
|
|
100
|
+
|
|
101
|
+
`authorize` (`./utils`) runs the guard chain: each alias from `getGuards()` is asked to `match()`,
|
|
102
|
+
the first that does is asked to `handle()`, and a chain where none matches or the matching one
|
|
103
|
+
refuses raises `AuthFailedError`. The admitted `Auth` is hung on the raw request as `_auth`, which
|
|
104
|
+
`provideRequest` surfaces to the handler as `req.auth`.
|
|
105
|
+
|
|
106
|
+
Immediately after that, and only when the entrypoint has guards, `authorize` calls `attachEntity`
|
|
107
|
+
from `@owlmeans/auth-common`: the token names the organization by `entitySlug`, which is renameable,
|
|
108
|
+
so the entity is resolved once here rather than in every handler. The resolution is hung on the raw
|
|
109
|
+
request as `_entity` and reaches the handler as `req.entity` (`{ id, slug, iamKey }`), and
|
|
110
|
+
`attachEntity` also rewrites `req.auth.entitySlug` to the entity's current slug, so a request that
|
|
111
|
+
arrived under a retired name continues under the live one. It is a no-op where no entity resolver
|
|
112
|
+
service is registered, and it raises `AuthenFailed` when the token names an organization that does
|
|
113
|
+
not resolve.
|
|
114
|
+
|
|
115
|
+
Two consequences a handler has to work by: there is **no id on the token** — `req.auth` carries the
|
|
116
|
+
slug and nothing else about the organization, so `req.entity?.id` (or `entityKeyOf(req)` /
|
|
117
|
+
`requireEntityKey(req)` from `@owlmeans/auth-common`) is the value to key records by; and an
|
|
118
|
+
unguarded entrypoint gets neither `req.auth` nor `req.entity`, because the whole block is skipped
|
|
119
|
+
when `getGuards()` is empty.
|
|
120
|
+
|
|
121
|
+
## Request validation
|
|
122
|
+
|
|
123
|
+
The route schema is built from the entrypoint's `filter`: `querystring`, `params` and `headers`
|
|
124
|
+
always, `body` only for `POST`, `PATCH` and `PUT`, and `response` as declared. Bodies are consumed
|
|
125
|
+
as JSON, form-urlencoded or multipart.
|
|
126
|
+
|
|
127
|
+
Ajv is configured with `coerceTypes`, `useDefaults` and `removeAdditional` — so a query string
|
|
128
|
+
arrives typed, declared defaults are filled in, and **an undeclared property is dropped rather than
|
|
129
|
+
rejected**: a field missing in a handler is usually a field missing from the filter. `fixFormatDates`
|
|
130
|
+
rewrites `date-time` properties declared as objects into strings before compiling, so a schema
|
|
131
|
+
generated from a record type validates the JSON that actually arrives.
|
|
132
|
+
|
|
133
|
+
## The plugins the server registers
|
|
134
|
+
|
|
135
|
+
Registered on init, in this order — CORS, multipart, Helmet, raw body, middie — and worth knowing
|
|
136
|
+
because they set limits an app cannot see from its handler:
|
|
137
|
+
|
|
138
|
+
- **CORS** — `origin: '*'`, the full framework method set declared explicitly plus `HEAD` and
|
|
139
|
+
`OPTIONS`, and the `auth-token-refresh` header exposed so a browser client can read a rotated
|
|
140
|
+
token. The method list must stay explicit: a narrower default makes the browser reject every
|
|
141
|
+
`PUT`/`PATCH`/`DELETE` at preflight while server-to-server callers keep working.
|
|
142
|
+
- **Multipart** — fields attached to the body as key/values, at most 5 files of 5 MB each, over-size
|
|
143
|
+
uploads throwing rather than truncating.
|
|
144
|
+
- **Helmet**.
|
|
145
|
+
- **Raw body** on the `rawBody` request field, captured before anything else (`runFirst`) — that is
|
|
146
|
+
what a webhook signature check reads, since the parsed body cannot be re-serialized byte for byte.
|
|
147
|
+
- **middie**, last, for connect-style middleware.
|
|
148
|
+
|
|
149
|
+
The overall body limit is 20 MB.
|
|
150
|
+
|
|
151
|
+
## Listening
|
|
152
|
+
|
|
153
|
+
`listen()` resolves the socket from the service's own declaration, `cfg.services[cfg.service]`:
|
|
154
|
+
`internalPort ?? port ?? PORT`, and `OPENED_HOST` when `opened` is true, `CLOSED_HOST` otherwise. It
|
|
155
|
+
also installs a `SIGTERM` handler that closes the server and exits 0. Initialization is re-entrant:
|
|
156
|
+
an already-listening instance is closed and rebuilt, so re-initializing a context does not leave two
|
|
157
|
+
servers on one port.
|
|
158
|
+
|
|
59
159
|
## Holding the port through the boot
|
|
60
160
|
|
|
61
161
|
The server builds its route table from the entrypoints the context knows about, so it can only
|
|
@@ -76,6 +176,9 @@ await hold.release() // awaited — listen() binds on the next line
|
|
|
76
176
|
await ctx.getApiServer().listen()
|
|
77
177
|
```
|
|
78
178
|
|
|
179
|
+
`release()` awaits the actual close and force-closes keep-alive connections, so a supervisor's own
|
|
180
|
+
poller cannot hold the handover open.
|
|
181
|
+
|
|
79
182
|
Two rules the caller owns: a **bind failure is fatal and loud** — name it (EADDRINUSE above all)
|
|
80
183
|
and `process.exit(1)`, because carrying on ends the boot with nothing listening and nothing
|
|
81
184
|
holding the event loop, a clean exit 0 while a stale predecessor keeps serving; and a **failed
|
|
@@ -85,8 +188,8 @@ why.
|
|
|
85
188
|
## Error → HTTP status
|
|
86
189
|
|
|
87
190
|
`handleError` (`./utils`) is the single mapping from a thrown error to a status. Handlers own no
|
|
88
|
-
status table: they throw, and this decides. Two families
|
|
89
|
-
`
|
|
191
|
+
status table: they throw, and this decides. Two families are recognised — this package's own
|
|
192
|
+
`AuthFailedError` and `AccessError`, of which only `AuthFailedError` is raised by the pipeline, and
|
|
90
193
|
`AuthForbidden` / `AuthorizationError` from `@owlmeans/auth`, which is what guards and gates throw.
|
|
91
194
|
|
|
92
195
|
| Thrown | Status | Meaning |
|
|
@@ -101,11 +204,22 @@ unrecognised refusal answering 500 reports a refused request as a crashed server
|
|
|
101
204
|
tell "sign in again" from "the service is broken", and a consumer watching statuses concludes the
|
|
102
205
|
application fell over.
|
|
103
206
|
|
|
207
|
+
`AuthenFailed` — the error `attachEntity` raises inside this same pipeline when the token names an
|
|
208
|
+
organization that does not resolve — belongs to neither family: it extends `AuthManagerError`, not
|
|
209
|
+
`AuthorizationError`. It therefore falls through to **500**, not 401. Treat a 500 on a guarded
|
|
210
|
+
entrypoint as a candidate unresolvable organization entity, and give a gate or handler that wants a
|
|
211
|
+
401 there one of the two recognised families to throw.
|
|
212
|
+
|
|
104
213
|
The body is always `ResilientError.marshal(ResilientError.ensure(error)).message`, and nothing is
|
|
105
|
-
written when the reply was already sent.
|
|
214
|
+
written when the reply was already sent. An entrypoint that names a `fixer` gets that service
|
|
215
|
+
instead — it renders the error onto the reply itself and `handleError` never runs.
|
|
106
216
|
|
|
107
217
|
## Depends On
|
|
108
218
|
|
|
109
|
-
- `@owlmeans/context`, `@owlmeans/entrypoint`, `@owlmeans/route`
|
|
110
|
-
- `@owlmeans/auth` (the error family the guards throw), `@owlmeans/error`, `@owlmeans/api` (status constants)
|
|
111
|
-
- `fastify` (runtime)
|
|
219
|
+
- `@owlmeans/context`, `@owlmeans/entrypoint`, `@owlmeans/route`, `@owlmeans/server-context`, `@owlmeans/server-entrypoint`
|
|
220
|
+
- `@owlmeans/auth` (the error family the guards throw), `@owlmeans/auth-common`, `@owlmeans/error`, `@owlmeans/api` (status constants)
|
|
221
|
+
- `fastify` (runtime) with `@fastify/cors`, `@fastify/helmet`, `@fastify/middie`, `@fastify/multipart`, `fastify-raw-body`, `ajv-errors`
|
|
222
|
+
|
|
223
|
+
`ajv` and `ajv-formats` are **peer** dependencies, not runtime ones — the validator compiler is
|
|
224
|
+
built from them, so installing this package without also depending on both leaves unmet peers and a
|
|
225
|
+
server that cannot compile a route schema. Declare them alongside `@owlmeans/server-api`.
|
package/build/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAGxC,qBAAa,eAAgB,SAAQ,QAAQ;IAC3C,OAAuB,QAAQ,SAAoB;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAGxC,qBAAa,eAAgB,SAAQ,QAAQ;IAC3C,OAAuB,QAAQ,SAAoB;IAEnD,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,WAAY,SAAQ,QAAQ;IACvC,OAAuB,QAAQ,SAAsC;IAErE,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,WAAY,SAAQ,QAAQ;IACvC,OAAuB,QAAQ,SAAgB;IAE/C,cAGC;CACF"}
|
package/build/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.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CAAC,WAAW,CAAC,CAAA"}
|
package/build/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGlE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACzE,OAAO,KAAK,EAAU,OAAO,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGlE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACzE,OAAO,KAAK,EAAU,OAAO,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAevD,eAAO,MAAM,UAAU,EAAE,CAAC,CAAC,EACzB,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,GAAG,CAAC,KACxF,sBAAsB,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAahD,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,CAAC,CAAC,EAC3B,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,GAAG,CAAC,KAExF,sBAAsB,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAahD,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,CAC1B,OAAO,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,KAC7G,sBAAsB,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAWhD,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,CAC/B,OAAO,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,YAAY,CAAC,WAAW,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,KAC7G,sBAAsB,CAAC,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC,CAc3D,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAU,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,eAAe,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAItH,CAAA;AAED,MAAM,WAAW,YAAa,SAAQ,aAAa;CAAI"}
|
package/build/helper.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { assertContext } from '@owlmeans/context';
|
|
2
2
|
import { EntrypointOutcome } from '@owlmeans/entrypoint';
|
|
3
|
+
/**
|
|
4
|
+
* The context a handler runs against.
|
|
5
|
+
*
|
|
6
|
+
* The HTTP boundary hangs the request-scoped context on the raw Fastify request, so a handler
|
|
7
|
+
* reached that way gets it from there. A request that did not come from Fastify has no `original`
|
|
8
|
+
* at all — a queued call is rebuilt from an envelope, and a socket frame carries its own — so this
|
|
9
|
+
* has to fall back rather than dereference: these handlers are the same functions on every
|
|
10
|
+
* transport, and only the way they were reached differs.
|
|
11
|
+
*/
|
|
3
12
|
const _castContextFromOriginal = (req, def) => {
|
|
4
|
-
return req.original
|
|
13
|
+
return req.original?._ctx ?? def;
|
|
5
14
|
};
|
|
6
15
|
export const handleBody = handler => ref => async (req, res) => {
|
|
7
16
|
const ctx = assertContext(ref.ref?.ctx);
|
package/build/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAOxD,MAAM,wBAAwB,GAAG,CAAqE,GAAoB,EAAE,GAAM,EAAK,EAAE;IACvI,OAAO,GAAG,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAOxD;;;;;;;;GAQG;AACH,MAAM,wBAAwB,GAAG,CAAqE,GAAoB,EAAE,GAAM,EAAK,EAAE;IACvI,OAAO,GAAG,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,CAAA;AAClC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAE8B,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IACxF,MAAM,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAY,CAAA;IAClD,IAAI,CAAC;QACH,GAAG,CAAC,OAAO,CAAC,MAAM,OAAO,CACvB,GAAG,CAAC,IAAW,EACf,wBAAwB,CAAkB,GAAG,EAAE,GAAG,CAA8B,EAChF,GAAG,CACJ,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAA;IAC1B,CAAC;IAAC,OAAO,CAAC,EAAE,CA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+
{"version":3,"file":"hold.d.ts","sourceRoot":"","sources":["../src/hold.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAG5D,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,6FAA6F;IAC7F,OAAO,CAAC,EAAE,MAAM,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,WAAW,QACjB,YAAY,SAAQ,kBAAkB,KAC1C,OAAO,CAAC,WAAW,CA0BrB,CAAA"}
|
package/build/hold.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hold.js","sourceRoot":"","sources":["../src/hold.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAsB5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,GAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"hold.js","sourceRoot":"","sources":["../src/hold.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAsB5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,GAAiB,EAAE,IAAI,GAAuB,EAAE,EAC1B,EAAE;IACxB,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAA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O,EAAE,KAAK,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA,CAAC,CAAC;KAC9C,CAAA;AACH,CAAC,CAAA"}
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA"}
|
package/build/index.js
CHANGED
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BasicConfig, BasicContext } from '@owlmeans/context';
|
|
2
|
+
import type { BodyOf, EntrypointProtocolDeclaration, HandlerRequest, OpenValue, ParamsOf, RequestOf, ResponseOf } from '@owlmeans/entrypoint';
|
|
3
|
+
import type { BoundEntrypointHandler } from '@owlmeans/server-entrypoint';
|
|
4
|
+
type HandlerResponse<Response> = [Response] extends [undefined] ? void | undefined : Response;
|
|
5
|
+
type MaybePromise<Value> = Value | Promise<Value>;
|
|
6
|
+
type BodyProtocol<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends {
|
|
7
|
+
body: OpenValue;
|
|
8
|
+
} ? Protocol : never;
|
|
9
|
+
type ParamsProtocol<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends {
|
|
10
|
+
params: object;
|
|
11
|
+
} ? Protocol : never;
|
|
12
|
+
/**
|
|
13
|
+
* Make server handlers that infer request sections and response values from their protocol.
|
|
14
|
+
* The protocol is passed once; application callbacks never name request or reply generics.
|
|
15
|
+
*/
|
|
16
|
+
export declare const handlers: <Context extends BasicContext<BasicConfig>>() => {
|
|
17
|
+
body: <Protocol extends EntrypointProtocolDeclaration>(protocol: Protocol, handler: Protocol extends BodyProtocol<Protocol> ? (payload: BodyOf<Protocol>, context: Context, request: HandlerRequest<RequestOf<Protocol>>) => MaybePromise<HandlerResponse<ResponseOf<Protocol>>> : never) => BoundEntrypointHandler<Protocol>;
|
|
18
|
+
params: <Protocol extends EntrypointProtocolDeclaration>(protocol: Protocol, handler: Protocol extends ParamsProtocol<Protocol> ? (payload: ParamsOf<Protocol>, context: Context, request: HandlerRequest<RequestOf<Protocol>>) => MaybePromise<HandlerResponse<ResponseOf<Protocol>>> : never) => BoundEntrypointHandler<Protocol>;
|
|
19
|
+
request: <Protocol extends EntrypointProtocolDeclaration>(protocol: Protocol, handler: (request: HandlerRequest<RequestOf<Protocol>>, context: Context) => MaybePromise<HandlerResponse<ResponseOf<Protocol>>>) => BoundEntrypointHandler<Protocol>;
|
|
20
|
+
};
|
|
21
|
+
/** Access a Fastify-specific upload through an explicit boundary helper, never `request.original`. */
|
|
22
|
+
export declare const uploadedFile: (request: HandlerRequest<{
|
|
23
|
+
body: object;
|
|
24
|
+
}>) => Promise<import('@fastify/multipart').MultipartFile | undefined>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,KAAK,EACV,MAAM,EAAE,6BAA6B,EAAE,cAAc,EAAe,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAC/G,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAEzE,KAAK,eAAe,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,QAAQ,CAAA;AAC7F,KAAK,YAAY,CAAC,KAAK,IAAI,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;AACjD,KAAK,YAAY,CAAC,QAAQ,SAAS,6BAA6B,IAAI,SAAS,CAAC,QAAQ,CAAC,SAAS;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAC/G,QAAQ,GAAG,KAAK,CAAA;AACpB,KAAK,cAAc,CAAC,QAAQ,SAAS,6BAA6B,IAAI,SAAS,CAAC,QAAQ,CAAC,SAAS;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAChH,QAAQ,GAAG,KAAK,CAAA;AAyCpB;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,YAAY,CAAC,WAAW,CAAC;IAChE,IAAI,GAAG,QAAQ,SAAS,6BAA6B,YACzC,QAAQ,WACT,QAAQ,SAAS,YAAY,CAAC,QAAQ,CAAC,GAAG,CAC/C,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,EACzB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,KACzC,YAAY,CAAC,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,GACtD,KAAK,KACR,sBAAsB,CAAC,QAAQ,CAAC;IAKnC,MAAM,GAAG,QAAQ,SAAS,6BAA6B,YAC3C,QAAQ,WACT,QAAQ,SAAS,cAAc,CAAC,QAAQ,CAAC,GAAG,CACjD,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,KACzC,YAAY,CAAC,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,GACtD,KAAK,KACR,sBAAsB,CAAC,QAAQ,CAAC;IAKnC,OAAO,GAAG,QAAQ,SAAS,6BAA6B,YAC5C,QAAQ,WACT,CACP,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAC5C,OAAO,EAAE,OAAO,KACb,YAAY,CAAC,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,KACvD,sBAAsB,CAAC,QAAQ,CAAC;CACnC,CAAA;AAEF,sGAAsG;AACtG,eAAO,MAAM,YAAY,YACd,cAAc,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,KACxC,OAAO,CAAC,OAAO,oBAAoB,EAAE,aAAa,GAAG,SAAS,CAKhE,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { assertContext } from '@owlmeans/context';
|
|
2
|
+
import { EntrypointOutcome } from '@owlmeans/entrypoint';
|
|
3
|
+
const contextFor = (request, fallback) => {
|
|
4
|
+
const original = request.original;
|
|
5
|
+
if (original != null && typeof original === 'object' && '_ctx' in original) {
|
|
6
|
+
return original._ctx ?? fallback;
|
|
7
|
+
}
|
|
8
|
+
return fallback;
|
|
9
|
+
};
|
|
10
|
+
const bind = (protocol, execute) => ({
|
|
11
|
+
protocol,
|
|
12
|
+
bind: ref => async (request, response) => {
|
|
13
|
+
const fallback = assertContext(ref.ref?.ctx, protocol.alias);
|
|
14
|
+
try {
|
|
15
|
+
const typedRequest = request;
|
|
16
|
+
const value = await execute(typedRequest, contextFor(request, fallback));
|
|
17
|
+
response.resolve(value, EntrypointOutcome.Ok);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
response.reject(error);
|
|
21
|
+
}
|
|
22
|
+
return response.value;
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Make server handlers that infer request sections and response values from their protocol.
|
|
27
|
+
* The protocol is passed once; application callbacks never name request or reply generics.
|
|
28
|
+
*/
|
|
29
|
+
export const handlers = () => ({
|
|
30
|
+
body: (protocol, handler) => bind(protocol, (request, context) => handler(request.body, context, request)),
|
|
31
|
+
params: (protocol, handler) => bind(protocol, (request, context) => handler(request.params, context, request)),
|
|
32
|
+
request: (protocol, handler) => bind(protocol, handler),
|
|
33
|
+
});
|
|
34
|
+
/** Access a Fastify-specific upload through an explicit boundary helper, never `request.original`. */
|
|
35
|
+
export const uploadedFile = async (request) => {
|
|
36
|
+
const original = request.original;
|
|
37
|
+
if (original == null || typeof original !== 'object' || !('file' in original))
|
|
38
|
+
return undefined;
|
|
39
|
+
return original.file();
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAkBxD,MAAM,UAAU,GAAG,CACjB,OAAwB,EACxB,QAAiB,EACR,EAAE;IACX,MAAM,Q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EAClB,OAKS,EACyB,EAAE,CAAC,IAAI,CAAoB,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAC3F,OAEwD,CAAC,OAAO,CAAC,MAA4B,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAEpH,OAAO,EAAE,CACP,QAAkB,EAClB,OAGwD,EACtB,EAAE,CAAC,IAAI,CAAoB,QAAQ,EAAE,OAAO,CAAC;CAClF,CAAC,CAAA;AAEF,sGAAsG;AACtG,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,OAAyC,EACwB,EAAE;IACnE,MAAM,QAAQ,GAAI,OAA2B,CAAC,QAAQ,CAAA;IACtD,IAAI,QAAQ,IAAI,IAAI,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC;QAAE,OAAO,SAAS,CAAA;IAE/F,OAAQ,QAA6C,CAAC,IAAI,EAAE,CAAA;AAC9D,CAAC,CAAA"}
|
package/build/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAiC5D,KAAK,MAAM,GAAG,YAAY,CAAA;AAK1B,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAiC5D,KAAK,MAAM,GAAG,YAAY,CAAA;AAK1B,eAAO,MAAM,eAAe,UAAW,MAAM,KAAG,SAk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Aa,EAChB,EAAE;IACvB,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;IACtC,MAAM,OAAO,GAAG,GAA0B,CAAA;IAE1C,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;IAEhC,IAAI,OAAO,CAAC,YAAY,IAAI,IAAI,EAAE,CAAC;QACjC,OAAO,CAAC,YAAY,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACzD,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG3D,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG3D,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,OAAO,OAAO,WAAW,CAAC,KAAG,IAC/D,CAAA;AAEpC,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,OAAO,OAAO,QAAQ,CAAC,aAAa,MAAM,KAAG,CACxC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAK3C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAK3C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,UAAW,KAAK,SAAS,YAAY,SAe5D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAGnE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAM3E,KAAK,MAAM,GAAG,YAAY,CAAA;AAC1B,UAAU,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;CAAI;AAEzE,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAGnE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAM3E,KAAK,MAAM,GAAG,YAAY,CAAA;AAC1B,UAAU,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;CAAI;AAEzE,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,WAC3D,CAAC,UAAU,gBAAgB,CAAC,cAAc,CAAC,OAC/C,cAAc,SAAS,YAAY,KACvC,OAAO,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAmD/C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../src/utils/payload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAA;AAE1C,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../src/utils/payload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAA;AAE1C,eAAO,MAAM,cAAc,UAAW,MAAM,OAAO,OAAO,cAAc,OAAO,KAAG,eAejF,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,YAAY,gBAAgB,CAAC,CAAC,CAAC,SAAS,QAAQ,iBAAiB,OAAO,KAAG,OAuB3G,CAAA;AAGD,eAAO,MAAM,cAAc,WAAY,eAAe,oBAgBrD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/utils/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE3D,OAAO,KAAK,EAAgB,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAG5D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAQ3E,KAAK,MAAM,GAAG,YAAY,CAAA;AAC1B,KAAK,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;AAEpC,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/utils/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE3D,OAAO,KAAK,EAAgB,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAG5D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAQ3E,KAAK,MAAM,GAAG,YAAY,CAAA;AAC1B,KAAK,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;AAEpC,eAAO,MAAM,cAAc,YAAa,OAAO,UAAU,gBAAgB,KAAG,MAAM,IAAI,gBAAgB,CAAC,OAAO,CAe7G,CAAA;AAED,eAAO,MAAM,mBAAmB,WAAY,gBAAgB,CAAC,cAAc,CAAC,YAAY,MAAM,WAChF,cAAc,SAAS,YAAY,kBA0C9C,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/server-api",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
"@fastify/helmet": "^13.1.0",
|
|
33
33
|
"@fastify/middie": "^9.0.2",
|
|
34
34
|
"@fastify/multipart": "^9.0.1",
|
|
35
|
-
"@owlmeans/api": "^0.1.18-rc.
|
|
36
|
-
"@owlmeans/auth": "^0.1.18-rc.
|
|
37
|
-
"@owlmeans/auth-common": "^0.1.18-rc.
|
|
38
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
39
|
-
"@owlmeans/error": "^0.1.18-rc.
|
|
40
|
-
"@owlmeans/entrypoint": "^0.1.18-rc.
|
|
41
|
-
"@owlmeans/route": "^0.1.18-rc.
|
|
42
|
-
"@owlmeans/server-context": "^0.1.18-rc.
|
|
43
|
-
"@owlmeans/server-entrypoint": "^0.1.18-rc.
|
|
35
|
+
"@owlmeans/api": "^0.1.18-rc.14",
|
|
36
|
+
"@owlmeans/auth": "^0.1.18-rc.10",
|
|
37
|
+
"@owlmeans/auth-common": "^0.1.18-rc.14",
|
|
38
|
+
"@owlmeans/context": "^0.1.18-rc.9",
|
|
39
|
+
"@owlmeans/error": "^0.1.18-rc.9",
|
|
40
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.12",
|
|
41
|
+
"@owlmeans/route": "^0.1.18-rc.10",
|
|
42
|
+
"@owlmeans/server-context": "^0.1.18-rc.13",
|
|
43
|
+
"@owlmeans/server-entrypoint": "^0.1.18-rc.12",
|
|
44
44
|
"ajv-errors": "^3.0.0",
|
|
45
45
|
"fastify": "^5.0.0",
|
|
46
46
|
"fastify-raw-body": "^5.0.0",
|
package/src/helper.ts
CHANGED
|
@@ -8,8 +8,17 @@ import type { Config, Context } from './types.js'
|
|
|
8
8
|
import type { FastifyRequest } from 'fastify'
|
|
9
9
|
import type { MultipartFile } from '@fastify/multipart'
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The context a handler runs against.
|
|
13
|
+
*
|
|
14
|
+
* The HTTP boundary hangs the request-scoped context on the raw Fastify request, so a handler
|
|
15
|
+
* reached that way gets it from there. A request that did not come from Fastify has no `original`
|
|
16
|
+
* at all — a queued call is rebuilt from an envelope, and a socket frame carries its own — so this
|
|
17
|
+
* has to fall back rather than dereference: these handlers are the same functions on every
|
|
18
|
+
* transport, and only the way they were reached differs.
|
|
19
|
+
*/
|
|
11
20
|
const _castContextFromOriginal = <C extends BasicConfig, T extends BasicContext<C> = BasicContext<C>>(req: AbstractRequest, def: T): T => {
|
|
12
|
-
return req.original
|
|
21
|
+
return req.original?._ctx ?? def
|
|
13
22
|
}
|
|
14
23
|
|
|
15
24
|
export const handleBody: <T>(
|
package/src/index.ts
CHANGED
package/src/protocol.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { assertContext } from '@owlmeans/context'
|
|
2
|
+
import type { BasicConfig, BasicContext } from '@owlmeans/context'
|
|
3
|
+
import { EntrypointOutcome } from '@owlmeans/entrypoint'
|
|
4
|
+
import type {
|
|
5
|
+
BodyOf, EntrypointProtocolDeclaration, HandlerRequest, OpenRequest, OpenValue, ParamsOf, RequestOf, ResponseOf,
|
|
6
|
+
} from '@owlmeans/entrypoint'
|
|
7
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
8
|
+
import type { BoundEntrypointHandler } from '@owlmeans/server-entrypoint'
|
|
9
|
+
|
|
10
|
+
type HandlerResponse<Response> = [Response] extends [undefined] ? void | undefined : Response
|
|
11
|
+
type MaybePromise<Value> = Value | Promise<Value>
|
|
12
|
+
type BodyProtocol<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends { body: OpenValue }
|
|
13
|
+
? Protocol : never
|
|
14
|
+
type ParamsProtocol<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends { params: object }
|
|
15
|
+
? Protocol : never
|
|
16
|
+
|
|
17
|
+
interface ContextCarrier<Context> {
|
|
18
|
+
_ctx?: Context
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const contextFor = <Context extends BasicContext<BasicConfig>>(
|
|
22
|
+
request: AbstractRequest,
|
|
23
|
+
fallback: Context,
|
|
24
|
+
): Context => {
|
|
25
|
+
const original = request.original
|
|
26
|
+
if (original != null && typeof original === 'object' && '_ctx' in original) {
|
|
27
|
+
return (original as ContextCarrier<Context>)._ctx ?? fallback
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return fallback
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const bind = <Protocol extends EntrypointProtocolDeclaration, Context extends BasicContext<BasicConfig>>(
|
|
34
|
+
protocol: Protocol,
|
|
35
|
+
execute: (request: HandlerRequest<RequestOf<Protocol>>, context: Context) => MaybePromise<HandlerResponse<ResponseOf<Protocol>>>,
|
|
36
|
+
): BoundEntrypointHandler<Protocol> => ({
|
|
37
|
+
protocol,
|
|
38
|
+
bind: ref => async (request, response) => {
|
|
39
|
+
const fallback = assertContext<BasicConfig, Context>(ref.ref?.ctx, protocol.alias)
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const typedRequest = (request as HandlerRequest<OpenRequest>) as HandlerRequest<RequestOf<Protocol>>
|
|
43
|
+
const value = await execute(
|
|
44
|
+
typedRequest,
|
|
45
|
+
contextFor(request, fallback),
|
|
46
|
+
)
|
|
47
|
+
response.resolve(value as ResponseOf<Protocol>, EntrypointOutcome.Ok)
|
|
48
|
+
} catch (error) {
|
|
49
|
+
response.reject(error as Error)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return response.value
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Make server handlers that infer request sections and response values from their protocol.
|
|
58
|
+
* The protocol is passed once; application callbacks never name request or reply generics.
|
|
59
|
+
*/
|
|
60
|
+
export const handlers = <Context extends BasicContext<BasicConfig>>() => ({
|
|
61
|
+
body: <Protocol extends EntrypointProtocolDeclaration>(
|
|
62
|
+
protocol: Protocol,
|
|
63
|
+
handler: Protocol extends BodyProtocol<Protocol> ? (
|
|
64
|
+
payload: BodyOf<Protocol>,
|
|
65
|
+
context: Context,
|
|
66
|
+
request: HandlerRequest<RequestOf<Protocol>>,
|
|
67
|
+
) => MaybePromise<HandlerResponse<ResponseOf<Protocol>>>
|
|
68
|
+
: never,
|
|
69
|
+
): BoundEntrypointHandler<Protocol> => bind<Protocol, Context>(protocol, (request, context) =>
|
|
70
|
+
(handler as (
|
|
71
|
+
payload: BodyOf<Protocol>, context: Context, request: HandlerRequest<RequestOf<Protocol>>,
|
|
72
|
+
) => MaybePromise<HandlerResponse<ResponseOf<Protocol>>>)(request.body as BodyOf<Protocol>, context, request)),
|
|
73
|
+
|
|
74
|
+
params: <Protocol extends EntrypointProtocolDeclaration>(
|
|
75
|
+
protocol: Protocol,
|
|
76
|
+
handler: Protocol extends ParamsProtocol<Protocol> ? (
|
|
77
|
+
payload: ParamsOf<Protocol>,
|
|
78
|
+
context: Context,
|
|
79
|
+
request: HandlerRequest<RequestOf<Protocol>>,
|
|
80
|
+
) => MaybePromise<HandlerResponse<ResponseOf<Protocol>>>
|
|
81
|
+
: never,
|
|
82
|
+
): BoundEntrypointHandler<Protocol> => bind<Protocol, Context>(protocol, (request, context) =>
|
|
83
|
+
(handler as (
|
|
84
|
+
payload: ParamsOf<Protocol>, context: Context, request: HandlerRequest<RequestOf<Protocol>>,
|
|
85
|
+
) => MaybePromise<HandlerResponse<ResponseOf<Protocol>>>)(request.params as ParamsOf<Protocol>, context, request)),
|
|
86
|
+
|
|
87
|
+
request: <Protocol extends EntrypointProtocolDeclaration>(
|
|
88
|
+
protocol: Protocol,
|
|
89
|
+
handler: (
|
|
90
|
+
request: HandlerRequest<RequestOf<Protocol>>,
|
|
91
|
+
context: Context,
|
|
92
|
+
) => MaybePromise<HandlerResponse<ResponseOf<Protocol>>>,
|
|
93
|
+
): BoundEntrypointHandler<Protocol> => bind<Protocol, Context>(protocol, handler),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
/** Access a Fastify-specific upload through an explicit boundary helper, never `request.original`. */
|
|
97
|
+
export const uploadedFile = async (
|
|
98
|
+
request: HandlerRequest<{ body: object }>,
|
|
99
|
+
): Promise<import('@fastify/multipart').MultipartFile | undefined> => {
|
|
100
|
+
const original = (request as AbstractRequest).original
|
|
101
|
+
if (original == null || typeof original !== 'object' || !('file' in original)) return undefined
|
|
102
|
+
|
|
103
|
+
return (original as import('fastify').FastifyRequest).file()
|
|
104
|
+
}
|