@owlmeans/route 0.1.18-rc.3 → 0.1.18-rc.30
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 +211 -43
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/route/SKILL.md +68 -14
- package/build/consts.d.ts +5 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +5 -0
- package/build/consts.js.map +1 -1
- package/build/helper.d.ts +2 -2
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js.map +1 -1
- package/build/model.d.ts +3 -3
- package/build/model.d.ts.map +1 -1
- package/build/model.js +5 -10
- package/build/model.js.map +1 -1
- package/build/types.d.ts +41 -16
- package/build/types.d.ts.map +1 -1
- package/build/utils/route.d.ts +25 -5
- package/build/utils/route.d.ts.map +1 -1
- package/build/utils/route.js +68 -67
- package/build/utils/route.js.map +1 -1
- package/build/utils/service.d.ts +1 -0
- package/build/utils/service.d.ts.map +1 -1
- package/build/utils/service.js +2 -1
- package/build/utils/service.js.map +1 -1
- package/package.json +2 -2
- package/src/consts.ts +5 -0
- package/src/helper.ts +2 -2
- package/src/model.ts +9 -15
- package/src/types.ts +44 -16
- package/src/utils/route.ts +101 -71
- package/src/utils/service.ts +2 -1
- package/build/.gitkeep +0 -0
package/README.md
CHANGED
|
@@ -1,78 +1,246 @@
|
|
|
1
1
|
# @owlmeans/route
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The route declaration vocabulary for OwlMeans entrypoints. An app imports it in its shared contract
|
|
4
|
+
package, next to `@owlmeans/entrypoint`, to state for each entrypoint the URL segment, parent,
|
|
5
|
+
HTTP method, app type (backend or frontend) and transport identifier. It is not a
|
|
6
|
+
router and serves nothing: server binding is `@owlmeans/server-route` / `@owlmeans/server-app`,
|
|
7
|
+
client binding is `@owlmeans/client-route` / `@owlmeans/client-entrypoint`, UI routing is
|
|
8
|
+
`@owlmeans/router`. Application code usually reads addresses through the entrypoint accessors
|
|
9
|
+
(`path()`, `mount()`, `address()`) rather than through this package's `./utils`.
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- `RouteMethod` enum covers HTTP verbs; `RouteProtocols` covers `http`/`ws`
|
|
10
|
-
- This package is a dependency of `@owlmeans/module` — you rarely use it directly unless defining module-level routes
|
|
11
|
+
A `RouteDeclaration` is plain, immutable data: its `path` is the segment the route contributes under
|
|
12
|
+
its parent, and it is never rewritten. Where the route actually answers — the full path, the mount
|
|
13
|
+
under a service base, the host and scheme — is computed on demand from the declaration plus the
|
|
14
|
+
context that asks, so the same declaration serves a server and a browser alike.
|
|
11
15
|
|
|
12
16
|
## Installation
|
|
13
17
|
|
|
14
18
|
```bash
|
|
15
|
-
bun add @owlmeans/route
|
|
19
|
+
bun add @owlmeans/route@^0.1.18-rc.29
|
|
16
20
|
```
|
|
17
21
|
|
|
22
|
+
## Concepts
|
|
23
|
+
|
|
24
|
+
- **Declaration** — the `RouteDeclaration` a `route()` call produces: `alias`, `path` (the segment
|
|
25
|
+
under `parent`), `type`, `method`, `protocol`, opaque `protocolOptions`, and service coordinates.
|
|
26
|
+
- **Model** — `RouteModel` is `{ route: RouteDeclaration }` and nothing more. `protocol()` and
|
|
27
|
+
`openProtocol()` from `@owlmeans/entrypoint` take it as their first argument.
|
|
28
|
+
- **Marker** — `backend()`, `frontend()` and `socket()` return `Partial<RouteOptions>` that set the
|
|
29
|
+
app type and built-in protocol; a transport package may provide another marker.
|
|
30
|
+
- **Parent** — a route nests under another entrypoint. Pass the parent protocol object
|
|
31
|
+
(`parent: storyProtocols.base`); the declaration stores only its alias.
|
|
32
|
+
- **Service** — `service` names the configured service (`cfg.services`) that answers the route.
|
|
33
|
+
Without it the route belongs to the asking context's own service or the default one of its type.
|
|
34
|
+
- **Protocol** — `RouteProtocols` contains the built-in HTTP and WebSocket identifiers. A backend
|
|
35
|
+
transport package may supply another string identifier and owns its opaque option data.
|
|
36
|
+
|
|
18
37
|
## Usage
|
|
19
38
|
|
|
20
|
-
|
|
39
|
+
### A backend protocol tree
|
|
21
40
|
|
|
22
|
-
|
|
23
|
-
import { route, frontend, backend, socket, RouteMethod } from '@owlmeans/route'
|
|
24
|
-
import { module } from '@owlmeans/module'
|
|
41
|
+
Aliases stay private to the declaration module; the exported value is a tree of protocol objects.
|
|
25
42
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
```ts
|
|
44
|
+
import { contract, protocol } from '@owlmeans/entrypoint'
|
|
45
|
+
import { backend, route, RouteMethod } from '@owlmeans/route'
|
|
46
|
+
import { DEFAULT_GUARD } from '@owlmeans/auth-common'
|
|
47
|
+
import { InvoiceSchema, CreateInvoiceBodySchema } from './schemas.js'
|
|
30
48
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
const aliases = {
|
|
50
|
+
base: 'my-app:api:invoice:base',
|
|
51
|
+
list: 'my-app:api:invoice:list',
|
|
52
|
+
create: 'my-app:api:invoice:create',
|
|
53
|
+
} as const
|
|
35
54
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
55
|
+
const base = protocol(route(aliases.base, '/invoice', backend()), contract(), {
|
|
56
|
+
guards: DEFAULT_GUARD,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
export const invoiceProtocols = {
|
|
60
|
+
base,
|
|
61
|
+
list: protocol(
|
|
62
|
+
route(aliases.list, '/', backend({ parent: base, method: RouteMethod.GET })),
|
|
63
|
+
contract(InvoiceSchema),
|
|
64
|
+
),
|
|
65
|
+
create: protocol(
|
|
66
|
+
route(aliases.create, '/', backend({ parent: base, method: RouteMethod.POST })),
|
|
67
|
+
contract(CreateInvoiceBodySchema, InvoiceSchema),
|
|
68
|
+
),
|
|
69
|
+
} as const
|
|
40
70
|
```
|
|
41
71
|
|
|
42
|
-
|
|
72
|
+
`invoiceProtocols.create` resolves to `/invoice` on the backend service, answering `POST`, and
|
|
73
|
+
inherits the guard declared on `base`.
|
|
43
74
|
|
|
44
|
-
###
|
|
75
|
+
### Path params, screens and default children
|
|
45
76
|
|
|
46
|
-
|
|
77
|
+
Path params use the `:name` form and are typed through `contract.request`. `frontend()` marks a
|
|
78
|
+
screen; `default: true` marks the child screen shown at the parent's path.
|
|
47
79
|
|
|
48
|
-
|
|
80
|
+
```ts
|
|
81
|
+
import { contract, openProtocol, protocol, typed } from '@owlmeans/entrypoint'
|
|
82
|
+
import { backend, frontend, route, RouteMethod } from '@owlmeans/route'
|
|
83
|
+
import type { ProjectParams, Project, RenameProject } from './types.js'
|
|
84
|
+
import { ProjectParamsSchema, RenameProjectSchema } from './schemas.js'
|
|
49
85
|
|
|
50
|
-
|
|
86
|
+
const aliases = {
|
|
87
|
+
base: 'my-app:api:project:base',
|
|
88
|
+
rename: 'my-app:api:project:rename',
|
|
89
|
+
web: 'my-app:web:project:base',
|
|
90
|
+
dashboard: 'my-app:web:project:dashboard',
|
|
91
|
+
overview: 'my-app:web:project:overview',
|
|
92
|
+
} as const
|
|
51
93
|
|
|
52
|
-
|
|
94
|
+
const base = openProtocol(route(aliases.base, '/project', backend()))
|
|
95
|
+
const web = openProtocol(route(aliases.web, '/project/:projectId', frontend()))
|
|
53
96
|
|
|
54
|
-
|
|
97
|
+
export const projectProtocols = {
|
|
98
|
+
base,
|
|
99
|
+
rename: protocol(
|
|
100
|
+
route(aliases.rename, '/:id/rename', backend({ parent: base, method: RouteMethod.PATCH })),
|
|
101
|
+
contract.request(
|
|
102
|
+
{ params: typed<ProjectParams>(ProjectParamsSchema), body: typed<RenameProject>(RenameProjectSchema) },
|
|
103
|
+
typed<Project>(),
|
|
104
|
+
),
|
|
105
|
+
),
|
|
106
|
+
web: {
|
|
107
|
+
base: web,
|
|
108
|
+
dashboard: openProtocol(route(aliases.dashboard, '/dashboard', frontend({ parent: web }))),
|
|
109
|
+
overview: openProtocol(route(aliases.overview, '/', frontend({ parent: web, default: true }))),
|
|
110
|
+
},
|
|
111
|
+
} as const
|
|
112
|
+
```
|
|
55
113
|
|
|
56
|
-
###
|
|
114
|
+
### Sockets, custom protocols and other services
|
|
57
115
|
|
|
58
|
-
|
|
116
|
+
`socket()` is `backend()` with a different protocol. A route pointed at another service carries
|
|
117
|
+
`service`. Adapter packages may add their own protocol and opaque `protocolOptions`; route does not
|
|
118
|
+
define their semantics.
|
|
59
119
|
|
|
60
|
-
|
|
120
|
+
```ts
|
|
121
|
+
import { contract, openProtocol, protocol, typed } from '@owlmeans/entrypoint'
|
|
122
|
+
import { route, socket } from '@owlmeans/route'
|
|
123
|
+
import type { ProjectParams, StoryUpdate } from './types.js'
|
|
124
|
+
import { ProjectParamsSchema } from './schemas.js'
|
|
61
125
|
|
|
62
|
-
|
|
63
|
-
|
|
126
|
+
const aliases = {
|
|
127
|
+
updates: 'my-app:api:update:base',
|
|
128
|
+
story: 'my-app:api:update:story',
|
|
129
|
+
} as const
|
|
130
|
+
|
|
131
|
+
const updates = openProtocol(route(aliases.updates, '/update'))
|
|
132
|
+
|
|
133
|
+
export const storyProtocols = {
|
|
134
|
+
updates,
|
|
135
|
+
// WebSocket subscription under /update
|
|
136
|
+
story: protocol(
|
|
137
|
+
route(aliases.story, '/story/:id', socket({ parent: updates })),
|
|
138
|
+
contract.request({ params: typed<ProjectParams>(ProjectParamsSchema) }, typed<StoryUpdate>()),
|
|
139
|
+
),
|
|
140
|
+
} as const
|
|
64
141
|
```
|
|
65
142
|
|
|
66
|
-
###
|
|
143
|
+
### Reading where a route answers
|
|
144
|
+
|
|
145
|
+
Once protocols are registered on a context, the entrypoint accessors answer address questions. The
|
|
146
|
+
`./utils` helpers are the same functions over a bare declaration.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { AppType } from '@owlmeans/context'
|
|
150
|
+
import { service } from '@owlmeans/config'
|
|
151
|
+
import { resolveAddress, resolveMount } from '@owlmeans/route/utils'
|
|
152
|
+
import { invoiceProtocols } from 'my-app-common'
|
|
153
|
+
|
|
154
|
+
// Config side: the service the backend routes resolve against
|
|
155
|
+
const cfg = service({ service: 'my-app-api', type: AppType.Backend, host: 'localhost', port: 8080, base: 'api' }, baseCfg)
|
|
67
156
|
|
|
68
|
-
|
|
69
|
-
|
|
157
|
+
// Runtime side, through the registered entrypoint
|
|
158
|
+
const entrypoint = context.entrypoint(invoiceProtocols.create)
|
|
159
|
+
entrypoint.path() // '/invoice'
|
|
160
|
+
entrypoint.mount() // '/api/invoice'
|
|
161
|
+
entrypoint.address() // { host: 'localhost', port: 8080, base: 'api', secure: true, protocol: 'http' }
|
|
162
|
+
entrypoint.isLocal() // true inside the my-app-api process
|
|
163
|
+
|
|
164
|
+
// Same answers from a declaration
|
|
165
|
+
const declaration = invoiceProtocols.create.route.route
|
|
166
|
+
resolveMount(context, declaration)
|
|
167
|
+
resolveAddress(context, declaration)
|
|
70
168
|
```
|
|
71
169
|
|
|
72
|
-
##
|
|
170
|
+
## API
|
|
171
|
+
|
|
172
|
+
### `@owlmeans/route`
|
|
173
|
+
|
|
174
|
+
| Symbol | Kind | Purpose |
|
|
175
|
+
|--------|------|---------|
|
|
176
|
+
| `route(alias, path, opts?)` | function | Build a `RouteModel`; `opts` is `RouteOptions` or a parent alias string |
|
|
177
|
+
| `createRoute(alias, path, opts?)` | function | Build the bare `RouteDeclaration` (parent reference collapsed to its alias) |
|
|
178
|
+
| `makeRouteModel(declaration)` | function | Wrap a declaration as `{ route }` |
|
|
179
|
+
| `backend(opts?, method?)` | function | Mark `AppType.Backend`; `opts` is options, a parent alias or `null`; `method` is a `RouteMethod` or more options |
|
|
180
|
+
| `frontend(opts?, default?)` | function | Mark `AppType.Frontend`; `default` is a boolean flag or more options |
|
|
181
|
+
| `socket(opts?, secondary?)` | function | `backend()` with `protocol: RouteProtocols.SOCKET` |
|
|
182
|
+
| `service(alias, opts?)` | function | Set `service` on `opts` (mutated and returned) |
|
|
183
|
+
| `rtype(type, opts?)` | function | Set an arbitrary `AppType`; the primitive behind `backend()` / `frontend()` |
|
|
184
|
+
| `normalizePath(path)` | function | Trim whitespace and one leading and trailing `/` |
|
|
185
|
+
| `RouteMethod` | enum | `GET = 'get'`, `POST = 'post'`, `PATCH = 'patch'`, `PUT = 'put'`, `DELETE = 'delete'` |
|
|
186
|
+
| `RouteProtocols` | enum | Generic built-ins: `WEB = 'http'`, `SOCKET = 'ws'` |
|
|
187
|
+
| `SEP` | const | Path separator `'/'` |
|
|
188
|
+
| `PARAM` | const | Path param prefix `':'` |
|
|
189
|
+
| `BasicRoute` | interface | `type`, `service?`, `host?`, `port?`, `base?`, `internalHost?`, `internalPort?` |
|
|
190
|
+
| `RouteDeclaration` | interface | `BasicRoute` + `alias`, `path`, `parent?`, `default?`, `method?`, `protocol?`, transport-owned `protocolOptions?`, `secure?`, `timeout?` |
|
|
191
|
+
| `RouteOptions` | interface | `Partial<RouteDeclaration>` whose `parent` is a `RouteParent` |
|
|
192
|
+
| `RouteParent` | type | `string \| EntrypointReference` |
|
|
193
|
+
| `RouteModel` | interface | `{ route: RouteDeclaration }` |
|
|
194
|
+
| `RouteAddress` | interface | `{ host, port?, base?, secure, protocol }` |
|
|
195
|
+
| `CommonServiceRoute` | interface | A service entry: `BasicRoute` + `service`, `home?`, `default?` |
|
|
196
|
+
| `ResolvedServiceRoute` | interface | A service entry that names its `host` |
|
|
197
|
+
|
|
198
|
+
### `@owlmeans/route/utils`
|
|
199
|
+
|
|
200
|
+
The first six take `(context, declaration)`; the other four are pure and take no context.
|
|
201
|
+
|
|
202
|
+
| Symbol | Kind | Purpose |
|
|
203
|
+
|--------|------|---------|
|
|
204
|
+
| `resolvePath(context, route)` | function | Every ancestor's segment, then this one |
|
|
205
|
+
| `resolveMount(context, route)` | function | Service `base` + the full path |
|
|
206
|
+
| `resolveService(context, route)` | function | The named service, else the default of the route's type, else the first of that type |
|
|
207
|
+
| `resolveAddress(context, route)` | function | The `RouteAddress`; a hop over the service's internal host is never TLS |
|
|
208
|
+
| `isLocalRoute(context, route)` | function | Does the route belong to the context's own service |
|
|
209
|
+
| `getParentRoute(context, route)` | function | The parent declaration, with parentship-cycle detection |
|
|
210
|
+
| `overrideParams(route, overrides?, filter?)` | function | Fill only blank fields of `route` from `overrides`; mutates, returns nothing |
|
|
211
|
+
| `prependBase(route, path)` | function | `path` prefixed with `route.base` when set |
|
|
212
|
+
| `isServiceRoute(obj?)` | type guard | Is `obj` a `CommonServiceRoute` with a known `AppType` |
|
|
213
|
+
| `isServiceRouteResolved(route)` | type guard | Does the service entry name a host |
|
|
214
|
+
| `CreateRouteSignature<R>` | interface | Call signature shared by `route()` and `createRoute()` |
|
|
215
|
+
|
|
216
|
+
## Common pitfalls
|
|
217
|
+
|
|
218
|
+
- Pass the parent protocol object in route options, never an exported alias string. Keep aliases
|
|
219
|
+
private to the declaration module and export a `*Protocols` tree.
|
|
220
|
+
- The positional marker forms (`backend(parent, method)`, `frontend(parent, true)`) accept a parent
|
|
221
|
+
only as an alias string: a protocol object in first position is spread into the options and
|
|
222
|
+
overwrites the child's alias. Pass protocols as `{ parent }`.
|
|
223
|
+
- `path` is only this route's segment. Do not repeat the parent's path in it; `resolvePath()` joins
|
|
224
|
+
the chain.
|
|
225
|
+
- Custom transport options are opaque here. Validate them through the package that owns the
|
|
226
|
+
protocol.
|
|
227
|
+
- Do not pass a context to the pure `./utils` helpers: `overrideParams(ctx, decl)` writes route
|
|
228
|
+
fields into the context object instead of resolving anything.
|
|
229
|
+
- A mis-wired tree (no `cfg.services`, a service without a host, a parentship cycle) throws
|
|
230
|
+
`SyntaxError` when an address is resolved. Fix the config; do not catch it.
|
|
231
|
+
- `transportAlias` and `EntrypointTransport` live in `@owlmeans/entrypoint`, not here. A route only
|
|
232
|
+
names its protocol.
|
|
233
|
+
|
|
234
|
+
## Related packages
|
|
73
235
|
|
|
74
|
-
- [`@owlmeans/
|
|
75
|
-
|
|
236
|
+
- [`@owlmeans/entrypoint`](../entrypoint) — `protocol()` / `openProtocol()` consume a `RouteModel` and
|
|
237
|
+
expose `path()`, `mount()`, `address()`, `isLocal()`
|
|
238
|
+
- [`@owlmeans/context`](../context) — `AppType`, `EntrypointReference` and the registry the address helpers walk
|
|
239
|
+
- [`@owlmeans/config`](../config) — `service()` declares the service entries routes resolve against
|
|
240
|
+
- [`@owlmeans/server-route`](../server-route) — server-side route model; re-exported by
|
|
241
|
+
[`@owlmeans/server-app`](../server-app) as `broute`
|
|
242
|
+
- [`@owlmeans/client-route`](../client-route) — marks a route as client-side and extracts its params
|
|
243
|
+
- [`@owlmeans/socket`](../socket) — the SOCKET transport contracts
|
|
76
244
|
|
|
77
245
|
<!-- owlmeans:agent-guidance:start -->
|
|
78
246
|
## Agent guidance
|
|
@@ -82,7 +250,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
82
250
|
your project's skill store (`.agents/skills/`):
|
|
83
251
|
|
|
84
252
|
```sh
|
|
85
|
-
npx @owlmeans/agent-skills
|
|
253
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.33
|
|
86
254
|
```
|
|
87
255
|
|
|
88
256
|
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/route",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18-rc.30",
|
|
5
|
+
"generatedAt": "2026-09-22T17:39:02.537Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: route
|
|
3
|
-
description: How to use @owlmeans/route — route
|
|
3
|
+
description: How to use @owlmeans/route — transport-neutral route declarations, frontend/backend/socket markers, HTTP methods, extensible protocol identifiers, and address helpers. Auto-invoked when importing route helpers or defining an entrypoint's URL path.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
@@ -8,43 +8,97 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/route
|
|
9
9
|
|
|
10
10
|
**Layer:** Core
|
|
11
|
-
**Install:** `"@owlmeans/route": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/route": "^0.1.18-rc.30"` in `dependencies`
|
|
12
12
|
|
|
13
13
|
## Key Exports
|
|
14
14
|
|
|
15
15
|
| Export | Description |
|
|
16
16
|
|--------|-------------|
|
|
17
|
-
| `route(alias, path, options?)` |
|
|
18
|
-
| `frontend(options?)` | Mark a route as a React page (web only) |
|
|
19
|
-
| `
|
|
20
|
-
| `
|
|
21
|
-
|
|
|
17
|
+
| `route(alias, path, options?)` | Build a route model — `path` is the segment contributed under `parent` |
|
|
18
|
+
| `frontend(options?, default?)` | Mark a route as a React page (web only) |
|
|
19
|
+
| `backend(options?, method?)` | Mark a route as a backend endpoint |
|
|
20
|
+
| `socket(options?, secondary?)` | A backend route answering over `RouteProtocols.SOCKET` |
|
|
21
|
+
| `service(alias, options?)` | Point a route at a named service |
|
|
22
|
+
| `RouteMethod` | enum of GET, POST, PUT, PATCH, DELETE |
|
|
23
|
+
| `RouteProtocols` | built-in WEB (`http`) and SOCKET (`ws`) identifiers |
|
|
24
|
+
| `RouteProtocol` | a built-in or package-owned transport identifier |
|
|
25
|
+
| `rtype(type, options?)` | The primitive `frontend()` / `backend()` are built from |
|
|
26
|
+
| `createRoute(alias, path, opts?)` / `makeRouteModel(decl)` | The declaration and its wrapper, when you need them apart |
|
|
27
|
+
| `BasicRoute` | `{ type, service?, host?, port?, base?, internalHost?, internalPort? }` |
|
|
28
|
+
| `RouteDeclaration` | The immutable declaration `route()` produces |
|
|
29
|
+
| `RouteOptions` | `Partial<RouteDeclaration>` — what the marker helpers return |
|
|
30
|
+
| `RouteModel` | `{ route }` — the model wrapping a declaration |
|
|
31
|
+
| `RouteAddress` | `{ host, port, base, secure, protocol }` — where a route answers |
|
|
32
|
+
| `CommonServiceRoute` / `ResolvedServiceRoute` | A service entry, and one that knows its host |
|
|
33
|
+
| `normalizePath(path)`, `SEP`, `PARAM` | Path primitives |
|
|
34
|
+
|
|
35
|
+
## Declaration and model
|
|
36
|
+
|
|
37
|
+
`route()` returns a `RouteModel` that does nothing but **wrap an immutable `RouteDeclaration`**. The
|
|
38
|
+
declaration is plain data an application ships in its contract package: `path` stays the segment this
|
|
39
|
+
route contributes under its parent and is never rewritten, and the model carries no state of its own.
|
|
40
|
+
Where the route answers is worked out on demand, against the context that asks — which is what lets
|
|
41
|
+
the same declaration serve a client and a server at once.
|
|
42
|
+
|
|
43
|
+
## Protocol ownership
|
|
44
|
+
|
|
45
|
+
A route names the protocol it answers on, and an application binds one by registering a transport
|
|
46
|
+
service under `transportAlias(protocol)`. So the protocol is what decides whether a call travels as
|
|
47
|
+
an HTTP request, a socket frame or a package-owned transport — the call site never says. Both
|
|
48
|
+
`transportAlias` and `EntrypointTransport` are exported by `@owlmeans/entrypoint`; this package only
|
|
49
|
+
stores an opaque protocol identifier and `protocolOptions`. The package defining a custom protocol
|
|
50
|
+
owns its marker, option type, validation and transport; the generic route package does not describe
|
|
51
|
+
that transport's implementation semantics.
|
|
22
52
|
|
|
23
53
|
## Subpath Exports
|
|
24
54
|
|
|
25
|
-
|
|
55
|
+
`./utils` holds two kinds of helper, and their signatures differ. The six that answer *where* a
|
|
56
|
+
route lives take `(context, declaration)`, because that is a question about the asking context. The
|
|
57
|
+
other four are pure functions over a declaration or a service entry and take **no context**.
|
|
58
|
+
Passing one to them resolves nothing: `overrideParams(ctx, decl)` writes route fields straight into
|
|
59
|
+
the context object instead.
|
|
60
|
+
|
|
61
|
+
| Helper | Signature | Answers |
|
|
62
|
+
|--------|-----------|---------|
|
|
63
|
+
| `resolvePath` | `(context, route)` | Every ancestor's segment, then this one |
|
|
64
|
+
| `resolveMount` | `(context, route)` | `base` + the full path — what a server mounts and a client requests |
|
|
65
|
+
| `resolveService` | `(context, route)` | The service the declaration answers on: the one it names, else the default of its app type, else the first of that type |
|
|
66
|
+
| `resolveAddress` | `(context, route)` | The `RouteAddress`; a hop over a service's INTERNAL host is never TLS |
|
|
67
|
+
| `isLocalRoute` | `(context, route)` | Does the route belong to the service the asking context IS? |
|
|
68
|
+
| `getParentRoute` | `(context, route)` | The parent declaration, with parentship-cycle detection |
|
|
69
|
+
| `overrideParams` | `(route, overrides?, filter?)` | Fill in **only the blank** fields of `route` from `overrides`; `filter` narrows it to the listed keys. Mutates `route` and returns nothing |
|
|
70
|
+
| `prependBase` | `(route, path)` | `path` prefixed with `route.base`, or `path` when there is no base |
|
|
71
|
+
| `isServiceRoute` | `(obj?)` | Type guard: is this a service entry (`type` + `service`, `type` a known `AppType`)? |
|
|
72
|
+
| `isServiceRouteResolved` | `(route)` | Type guard: does that service entry name a host? |
|
|
73
|
+
|
|
74
|
+
Application code rarely calls these directly — `@owlmeans/entrypoint` exposes them as `path()`,
|
|
75
|
+
`mount()`, `service()`, `address()` and `isLocal()` on the entrypoint itself.
|
|
26
76
|
|
|
27
77
|
## Usage
|
|
28
78
|
|
|
29
79
|
```typescript
|
|
30
80
|
import { route, frontend, RouteMethod } from '@owlmeans/route'
|
|
31
|
-
import {
|
|
81
|
+
import { contract, openProtocol, protocol, typed } from '@owlmeans/entrypoint'
|
|
32
82
|
|
|
33
83
|
// Server route
|
|
34
|
-
|
|
84
|
+
protocol(
|
|
35
85
|
route(manager.back.project.create, '/create', {
|
|
36
86
|
parent: manager.back.project.base,
|
|
37
87
|
method: RouteMethod.POST,
|
|
38
|
-
})
|
|
88
|
+
}),
|
|
89
|
+
contract(typed<Project>()),
|
|
39
90
|
)
|
|
40
91
|
|
|
41
92
|
// Web route — frontend() marks it as a React page
|
|
42
|
-
|
|
93
|
+
openProtocol(
|
|
43
94
|
route(HOME, '/', frontend({ default: true, parent: BASE }))
|
|
44
95
|
)
|
|
45
96
|
```
|
|
46
97
|
|
|
47
98
|
## Depends On
|
|
48
99
|
|
|
49
|
-
- `@owlmeans/
|
|
50
|
-
|
|
100
|
+
- `@owlmeans/context` — `AppType`, and the entrypoint registry the address helpers walk
|
|
101
|
+
|
|
102
|
+
That is the only dependency. The address helpers signal a mis-wired route tree by throwing
|
|
103
|
+
`SyntaxError` — an unconfigured service, an unresolved host, a parentship cycle — so the process
|
|
104
|
+
crashes on a wiring mistake instead of serving a wrong URL.
|
package/build/consts.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ export declare enum RouteMethod {
|
|
|
7
7
|
}
|
|
8
8
|
export declare const SEP = "/";
|
|
9
9
|
export declare const PARAM = ":";
|
|
10
|
+
/**
|
|
11
|
+
* How a route is carried. The protocol picks the transport that answers it — an application binds
|
|
12
|
+
* one by registering a service under `transportAlias(protocol)` — so a caller writes `call()` and
|
|
13
|
+
* never learns which transport carried the work.
|
|
14
|
+
*/
|
|
10
15
|
export declare enum RouteProtocols {
|
|
11
16
|
WEB = "http",
|
|
12
17
|
SOCKET = "ws"
|
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,WAAW;IACrB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED,eAAO,MAAM,GAAG,MAAM,CAAA;AAEtB,eAAO,MAAM,KAAK,MAAM,CAAA;AAExB,oBAAY,cAAc;IACxB,GAAG,SAAS;IACZ,MAAM,OAAO;CACd"}
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,WAAW;IACrB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED,eAAO,MAAM,GAAG,MAAM,CAAA;AAEtB,eAAO,MAAM,KAAK,MAAM,CAAA;AAExB;;;;GAIG;AACH,oBAAY,cAAc;IACxB,GAAG,SAAS;IACZ,MAAM,OAAO;CACd"}
|
package/build/consts.js
CHANGED
|
@@ -8,6 +8,11 @@ export var RouteMethod;
|
|
|
8
8
|
})(RouteMethod || (RouteMethod = {}));
|
|
9
9
|
export const SEP = '/';
|
|
10
10
|
export const PARAM = ':';
|
|
11
|
+
/**
|
|
12
|
+
* How a route is carried. The protocol picks the transport that answers it — an application binds
|
|
13
|
+
* one by registering a service under `transportAlias(protocol)` — so a caller writes `call()` and
|
|
14
|
+
* never learns which transport carried the work.
|
|
15
|
+
*/
|
|
11
16
|
export var RouteProtocols;
|
|
12
17
|
(function (RouteProtocols) {
|
|
13
18
|
RouteProtocols["WEB"] = "http";
|
package/build/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,0BAAW,CAAA;IACX,4BAAa,CAAA;IACb,8BAAe,CAAA;IACf,0BAAW,CAAA;IACX,gCAAiB,CAAA;AACnB,CAAC,EANW,WAAW,KAAX,WAAW,QAMtB;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;AAEtB,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,CAAA;AAExB,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,8BAAY,CAAA;IACZ,+BAAa,CAAA;AACf,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB"}
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,0BAAW,CAAA;IACX,4BAAa,CAAA;IACb,8BAAe,CAAA;IACf,0BAAW,CAAA;IACX,gCAAiB,CAAA;AACnB,CAAC,EANW,WAAW,KAAX,WAAW,QAMtB;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;AAEtB,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,CAAA;AAExB;;;;GAIG;AACH,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,8BAAY,CAAA;IACZ,+BAAa,CAAA;AACf,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB"}
|
package/build/helper.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AppType } from '@owlmeans/context';
|
|
2
2
|
import { RouteMethod } from './consts.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { RouteModel, RouteOptions } from './types.js';
|
|
4
4
|
import type { CreateRouteSignature } from './utils/types.js';
|
|
5
|
-
export declare const route: CreateRouteSignature<
|
|
5
|
+
export declare const route: CreateRouteSignature<RouteModel>;
|
|
6
6
|
export declare const normalizePath: (path: string) => string;
|
|
7
7
|
export declare const rtype: (type: AppType, opts?: RouteOptions | string) => Partial<RouteOptions>;
|
|
8
8
|
export declare const backend: (opts?: RouteOptions | string | null, method?: RouteOptions | RouteMethod) => Partial<RouteOptions>;
|
package/build/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAuB,MAAM,aAAa,CAAA;AAE9D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAuB,MAAM,aAAa,CAAA;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAE5D,eAAO,MAAM,KAAK,EAAE,oBAAoB,CAAC,UAAU,CACH,CAAA;AAEhD,eAAO,MAAM,aAAa,SAAU,MAAM,KAAG,MAM5C,CAAA;AAED,eAAO,MAAM,KAAK,SAAU,OAAO,SAAS,YAAY,GAAG,MAAM,KAAG,OAAO,CAAC,YAAY,CAEvF,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,YAAY,GAAG,MAAM,GAAG,IAAI,WAAW,YAAY,GAAG,WAAW,KAAG,OAAO,CAAC,YAAY,CAQtH,CAAA;AAED,eAAO,MAAM,OAAO,YAAa,MAAM,SAAS,OAAO,CAAC,YAAY,CAAC,KAAG,OAAO,CAAC,YAAY,CAI3F,CAAA;AAED,eAAO,MAAM,MAAM,UAAW,YAAY,GAAG,MAAM,GAAG,IAAI,cAAc,YAAY,KAAG,OAAO,CAAC,YAAY,CAM1G,CAAA;AAED,eAAO,MAAM,QAAQ,UAAW,YAAY,GAAG,MAAM,GAAG,IAAI,QAAQ,YAAY,GAAG,OAAO,KAAG,OAAO,CAAC,YAAY,CAQhH,CAAA"}
|
package/build/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAe,cAAc,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAIxD,MAAM,CAAC,MAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"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"}
|
package/build/model.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RouteDeclaration, RouteModel } from './types.js';
|
|
2
2
|
import type { CreateRouteSignature } from './utils/types.js';
|
|
3
|
-
export declare const makeRouteModel: (route:
|
|
4
|
-
export declare const createRoute: CreateRouteSignature<
|
|
3
|
+
export declare const makeRouteModel: (route: RouteDeclaration) => RouteModel;
|
|
4
|
+
export declare const createRoute: CreateRouteSignature<RouteDeclaration>;
|
|
5
5
|
//# sourceMappingURL=model.d.ts.map
|
package/build/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAG5D,eAAO,MAAM,cAAc,UAAW,gBAAgB,KAAG,UAAyB,CAAA;AAElF,eAAO,MAAM,WAAW,EAAE,oBAAoB,CAAC,gBAAgB,CAY9D,CAAA"}
|
package/build/model.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import { resolve } from './utils/route.js';
|
|
2
1
|
import { AppType } from '@owlmeans/context';
|
|
3
|
-
export const makeRouteModel = (route) => {
|
|
4
|
-
const model = {
|
|
5
|
-
route,
|
|
6
|
-
resolve: ctx => resolve(route)(ctx)
|
|
7
|
-
};
|
|
8
|
-
return model;
|
|
9
|
-
};
|
|
2
|
+
export const makeRouteModel = (route) => ({ route });
|
|
10
3
|
export const createRoute = (alias, path, opts) => {
|
|
4
|
+
const options = typeof opts === 'string' ? { parent: opts } : opts;
|
|
5
|
+
const { parent, ...rest } = options ?? {};
|
|
11
6
|
const route = {
|
|
12
7
|
alias,
|
|
13
8
|
type: AppType.Backend,
|
|
14
9
|
path,
|
|
15
|
-
|
|
16
|
-
...(typeof
|
|
10
|
+
...rest,
|
|
11
|
+
...(parent == null ? {} : { parent: typeof parent === 'string' ? parent : parent.alias }),
|
|
17
12
|
};
|
|
18
13
|
return route;
|
|
19
14
|
};
|
package/build/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAE3C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAuB,EAAc,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAElF,MAAM,CAAC,MAAM,WAAW,GAA2C,CAAC,KAAK,EAAE,IAAI,EAAE,IAAK,EAAE,EAAE;IACxF,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;IAClE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE,CAAA;IACzC,MAAM,KAAK,GAAqB;QAC9B,KAAK;QACL,IAAI,EAAE,OAAO,CAAC,OAAO;QACrB,IAAI;QACJ,GAAG,IAAI;QACP,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;KAC1F,CAAA;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
package/build/types.d.ts
CHANGED
|
@@ -1,35 +1,60 @@
|
|
|
1
|
-
import type { AppType,
|
|
1
|
+
import type { AppType, EntrypointReference } from '@owlmeans/context';
|
|
2
2
|
import type { RouteProtocols, RouteMethod } from './consts';
|
|
3
|
-
|
|
3
|
+
/** A built-in or package-owned transport identifier. */
|
|
4
|
+
export type RouteProtocol = RouteProtocols | (string & {});
|
|
5
|
+
export interface BasicRoute {
|
|
6
|
+
type: AppType;
|
|
7
|
+
service?: string;
|
|
8
|
+
host?: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
base?: string;
|
|
11
|
+
internalHost?: string;
|
|
12
|
+
internalPort?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The plain, declarative half of a route — what a `route()` call produces and what an application
|
|
16
|
+
* ships in its contract package. It is never rewritten: `path` stays the segment this route
|
|
17
|
+
* contributes under its parent, and the address is worked out on demand against a context.
|
|
18
|
+
*/
|
|
19
|
+
export interface RouteDeclaration extends BasicRoute {
|
|
4
20
|
alias: string;
|
|
5
21
|
path: string;
|
|
6
22
|
parent?: string;
|
|
7
23
|
default?: boolean;
|
|
8
24
|
method?: RouteMethod;
|
|
9
|
-
protocol?:
|
|
25
|
+
protocol?: RouteProtocol;
|
|
10
26
|
secure?: boolean;
|
|
27
|
+
/** Transport-owned declaration data. The package defining `protocol` owns and validates it. */
|
|
28
|
+
protocolOptions?: unknown;
|
|
29
|
+
/** How long a caller waits for an answer, in milliseconds, when the transport supports it. */
|
|
30
|
+
timeout?: number;
|
|
11
31
|
}
|
|
12
32
|
export interface CommonServiceRoute extends BasicRoute {
|
|
13
33
|
home?: string;
|
|
14
34
|
service: string;
|
|
15
35
|
default?: boolean;
|
|
16
36
|
}
|
|
17
|
-
export interface BasicRoute {
|
|
18
|
-
type: AppType;
|
|
19
|
-
service?: string;
|
|
20
|
-
host?: string;
|
|
21
|
-
port?: number;
|
|
22
|
-
base?: string;
|
|
23
|
-
resolved: boolean;
|
|
24
|
-
}
|
|
25
37
|
export interface ResolvedServiceRoute extends CommonServiceRoute {
|
|
26
38
|
host: string;
|
|
27
|
-
resolved: true;
|
|
28
39
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
/** Where a route actually answers, once its service has been picked. */
|
|
41
|
+
export interface RouteAddress {
|
|
42
|
+
host: string;
|
|
43
|
+
port?: number;
|
|
44
|
+
base?: string;
|
|
45
|
+
secure: boolean;
|
|
46
|
+
protocol: RouteProtocol;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The model wrapping a declaration. It carries no resolution state of its own — every address
|
|
50
|
+
* question is answered from the declaration plus the context that asks.
|
|
51
|
+
*/
|
|
52
|
+
export interface RouteModel {
|
|
53
|
+
route: RouteDeclaration;
|
|
32
54
|
}
|
|
33
|
-
export
|
|
55
|
+
export type RouteParent = string | EntrypointReference;
|
|
56
|
+
export interface RouteOptions extends Omit<Partial<RouteDeclaration>, 'parent'> {
|
|
57
|
+
/** A parent protocol is preferred in application declarations; strings remain adapter input. */
|
|
58
|
+
parent?: RouteParent;
|
|
34
59
|
}
|
|
35
60
|
//# sourceMappingURL=types.d.ts.map
|