@owlmeans/server-entrypoint 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 +120 -41
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-entrypoint/SKILL.md +23 -26
- package/build/index.d.ts +1 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -2
- package/build/index.js.map +1 -1
- package/build/protocol.d.ts +9 -0
- package/build/protocol.d.ts.map +1 -0
- package/build/protocol.js +30 -0
- package/build/protocol.js.map +1 -0
- package/build/types.d.ts +10 -5
- package/build/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +1 -2
- package/src/protocol.ts +62 -0
- package/src/types.ts +14 -5
- package/build/entrypoint.d.ts +0 -6
- package/build/entrypoint.d.ts.map +0 -1
- package/build/entrypoint.js +0 -38
- package/build/entrypoint.js.map +0 -1
- package/build/helper.d.ts +0 -5
- package/build/helper.d.ts.map +0 -1
- package/build/helper.js +0 -25
- package/build/helper.js.map +0 -1
- package/build/utils/entrypoint.d.ts +0 -3
- package/build/utils/entrypoint.d.ts.map +0 -1
- package/build/utils/entrypoint.js +0 -3
- package/build/utils/entrypoint.js.map +0 -1
- package/build/utils/helper.d.ts +0 -2
- package/build/utils/helper.d.ts.map +0 -1
- package/build/utils/helper.js +0 -2
- package/build/utils/helper.js.map +0 -1
- package/src/entrypoint.ts +0 -51
- package/src/helper.ts +0 -38
- package/src/utils/entrypoint.ts +0 -3
- package/src/utils/helper.ts +0 -2
package/README.md
CHANGED
|
@@ -1,71 +1,150 @@
|
|
|
1
1
|
# @owlmeans/server-entrypoint
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
- `guard(alias, opts?)` creates `EntrypointOptions` requiring a named guard service
|
|
10
|
-
- Used internally by `@owlmeans/server-app`'s `elevate` re-export
|
|
3
|
+
Server-side entrypoint binding: turns an immutable protocol declaration from the shared package into
|
|
4
|
+
a server-local entrypoint that carries its route, guards, gate and handler. An application calls
|
|
5
|
+
`bind` / `bindAll` in its `entrypoints.ts` (often through the `@owlmeans/server-app` re-export) to
|
|
6
|
+
build the list it registers on the context. It does not write handlers — use `handlers<Context>()`
|
|
7
|
+
from `@owlmeans/server-api` for HTTP and `connection()` from `@owlmeans/server-socket` for sockets —
|
|
8
|
+
and a browser app binds the same protocols with `@owlmeans/client-entrypoint` instead.
|
|
11
9
|
|
|
12
10
|
## Installation
|
|
13
11
|
|
|
14
12
|
```bash
|
|
15
|
-
bun add @owlmeans/server-entrypoint
|
|
13
|
+
bun add @owlmeans/server-entrypoint@^0.1.18-rc.30
|
|
16
14
|
```
|
|
17
15
|
|
|
16
|
+
## Concepts
|
|
17
|
+
|
|
18
|
+
- **Protocol declaration** — the frozen `protocol()` / `openProtocol()` object from
|
|
19
|
+
`@owlmeans/entrypoint`, shared by callers and servers. It is data; binding never changes it.
|
|
20
|
+
- **Server entrypoint** — what `bind` returns: a materialized copy with a server route, merged
|
|
21
|
+
guards, gate, filter, optional fixer and handler, plus a `protocol` field pointing at its
|
|
22
|
+
declaration.
|
|
23
|
+
- **Bound handler** — `{ protocol, bind }`, produced by `handlers<Context>()` or `connection()`. It
|
|
24
|
+
is inseparable from the protocol whose request it accepts.
|
|
25
|
+
- **Group node** — a parent declaration (`base`) bound without a handler. It contributes the path
|
|
26
|
+
prefix, guards and gate its children inherit and is never mounted as a route itself.
|
|
27
|
+
- **Intermediate** — an entrypoint whose handler runs before matching routes and may replace the
|
|
28
|
+
request context; declared per route or forced with `{ intermediate: true }`.
|
|
29
|
+
|
|
18
30
|
## Usage
|
|
19
31
|
|
|
20
|
-
|
|
32
|
+
### Bind leaves and their parents
|
|
21
33
|
|
|
22
|
-
```
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
34
|
+
```ts
|
|
35
|
+
import { bind } from '@owlmeans/server-entrypoint'
|
|
36
|
+
import { handlers } from '@owlmeans/server-api'
|
|
37
|
+
import { projectProtocols } from 'my-app-common'
|
|
38
|
+
import type { Context } from './context.js'
|
|
25
39
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
const api = handlers<Context>()
|
|
41
|
+
|
|
42
|
+
export const serverBindings = [
|
|
43
|
+
bind(projectProtocols.base),
|
|
44
|
+
bind(projectProtocols.create, api.body(projectProtocols.create, async (body, context) =>
|
|
45
|
+
context.project().create(body))),
|
|
46
|
+
bind(projectProtocols.get, api.params(projectProtocols.get, async ({ id }, context) =>
|
|
47
|
+
context.project().load(id))),
|
|
29
48
|
]
|
|
49
|
+
```
|
|
30
50
|
|
|
31
|
-
|
|
32
|
-
return await ctx.project().create(payload)
|
|
33
|
-
}))
|
|
51
|
+
### Bind a flat collection
|
|
34
52
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```
|
|
53
|
+
`bindAll` pairs each declaration with the implementation whose `protocol` is the same object.
|
|
54
|
+
Declarations without an implementation are bound as group nodes. Flatten a tree with `protocols()`
|
|
55
|
+
only here, at the registration boundary.
|
|
39
56
|
|
|
40
|
-
|
|
57
|
+
```ts
|
|
58
|
+
import { bindAll } from '@owlmeans/server-entrypoint'
|
|
59
|
+
import { protocols } from '@owlmeans/entrypoint'
|
|
60
|
+
import * as project from './app/project.js'
|
|
41
61
|
|
|
42
|
-
|
|
62
|
+
export const projectBindings = bindAll(protocols(projectProtocols), [
|
|
63
|
+
project.list,
|
|
64
|
+
project.create,
|
|
65
|
+
project.get,
|
|
66
|
+
])
|
|
67
|
+
```
|
|
43
68
|
|
|
44
|
-
|
|
69
|
+
### Bind a tree by path
|
|
45
70
|
|
|
46
|
-
|
|
71
|
+
Larger services walk the protocol tree and look up the implementation at the same path, so a new or
|
|
72
|
+
renamed declaration stays type-checked at its binding site:
|
|
47
73
|
|
|
48
|
-
|
|
74
|
+
```ts
|
|
75
|
+
import { bind } from '@owlmeans/server-entrypoint'
|
|
76
|
+
import type { ServerEntrypoint } from '@owlmeans/server-entrypoint'
|
|
77
|
+
import { isEntrypointProtocol } from '@owlmeans/entrypoint'
|
|
78
|
+
import type { EntrypointTree } from '@owlmeans/entrypoint'
|
|
49
79
|
|
|
50
|
-
|
|
80
|
+
type Implementations = Record<string, unknown>
|
|
51
81
|
|
|
52
|
-
|
|
82
|
+
const bindTree = (tree: EntrypointTree, implementations: Implementations = {}): ServerEntrypoint<object>[] =>
|
|
83
|
+
Object.entries(tree).flatMap(([key, declaration]) => {
|
|
84
|
+
const implementation = implementations[key]
|
|
85
|
+
if (isEntrypointProtocol(declaration)) {
|
|
86
|
+
return [bind(declaration, implementation as never)]
|
|
87
|
+
}
|
|
88
|
+
return bindTree(declaration, (implementation ?? {}) as Implementations)
|
|
89
|
+
})
|
|
53
90
|
|
|
54
|
-
|
|
91
|
+
export const serverBindings = bindTree({ project: projectProtocols, invoice: invoiceProtocols }, {
|
|
92
|
+
project: { list: project.list, create: project.create, get: project.get },
|
|
93
|
+
invoice: { list: invoice.list, pay: invoice.pay },
|
|
94
|
+
})
|
|
95
|
+
```
|
|
55
96
|
|
|
56
|
-
|
|
57
|
-
- `route: ServerRouteModel<R>` — resolved server route
|
|
58
|
-
- `handle: RefedEntrypointHandler<R>` — the attached handler
|
|
97
|
+
### Server-local options
|
|
59
98
|
|
|
60
|
-
|
|
99
|
+
The third argument adjusts only the local binding. `guards` are merged with the declaration's,
|
|
100
|
+
`fixer` names a `FixerService` that answers errors instead of the default mapping, and
|
|
101
|
+
`intermediate` forces the entrypoint to run as an intermediate.
|
|
61
102
|
|
|
62
|
-
|
|
103
|
+
```ts
|
|
104
|
+
import { bind } from '@owlmeans/server-entrypoint'
|
|
63
105
|
|
|
64
|
-
|
|
106
|
+
export const serverBindings = [
|
|
107
|
+
bind(sessionProtocols.base, undefined, { intermediate: true }),
|
|
108
|
+
bind(invoiceProtocols.download, invoice.download, { fixer: MY_APP_DOWNLOAD_FIXER }),
|
|
109
|
+
]
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## API
|
|
65
113
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
114
|
+
| Symbol | Kind | Purpose |
|
|
115
|
+
|---|---|---|
|
|
116
|
+
| `bind(protocol, implementation?, options?)` | function | Materialize one declaration and attach a bound handler (or a `RefedEntrypointHandler`); returns `ServerProtocolEntrypoint<Protocol>` |
|
|
117
|
+
| `bindAll(declarations, implementations = [])` | function | Bind a flat declaration list, pairing implementations by `implementation.protocol === declaration` |
|
|
118
|
+
| `ServerEntrypoint<R>` | type | `CommonEntrypoint` with `route: ServerRouteModel<R>`, `handle: EntrypointHandler`, `fixer?` |
|
|
119
|
+
| `ServerProtocolEntrypoint<Protocol>` | type | `ServerEntrypoint<object>` plus `readonly protocol` |
|
|
120
|
+
| `BoundEntrypointHandler<Protocol>` | type | `{ readonly protocol, bind: RefedEntrypointHandler }` |
|
|
121
|
+
| `RefedEntrypointHandler<R>` | type | `(ref: EntrypointRef<R>) => EntrypointHandler`; the handler reads the bound entrypoint (and its context) from `ref.ref` |
|
|
122
|
+
| `EntrypointRef<R>` | type | `{ ref?: ServerEntrypoint<R> }` |
|
|
123
|
+
| `EntrypointOptions<R>` | type | `CommonEntrypointOptions` plus `fixer?`, `intermediate?`, `routeOptions?` |
|
|
124
|
+
| `FixerService` | type | Service with `handle(reply, error)` used when a binding names a `fixer` |
|
|
125
|
+
|
|
126
|
+
## Common pitfalls
|
|
127
|
+
|
|
128
|
+
- A handler carries its `protocol`, and collections match by object identity. Never attach, find or
|
|
129
|
+
replace a handler by alias.
|
|
130
|
+
- A decorated tree (`withOidcGuard(tree)`, `decorateEntrypoint(...)`) consists of new objects. Make
|
|
131
|
+
handlers from the same decorated protocols you bind, or `bindAll` will not pair them.
|
|
132
|
+
- Do not mutate a declaration or create a mutable contextual declaration; decorate the tree before
|
|
133
|
+
binding instead.
|
|
134
|
+
- Bind parent declarations too. A route whose parent is not registered loses its inherited path,
|
|
135
|
+
guards and gate.
|
|
136
|
+
- A binding without a handler is never mounted as an HTTP route — that is how group nodes work, and
|
|
137
|
+
also why a forgotten implementation shows up as a 404.
|
|
138
|
+
- HTTP handlers come from `handlers<Context>()`; socket handlers from `connection(protocol, callback)`.
|
|
139
|
+
|
|
140
|
+
## Related packages
|
|
141
|
+
|
|
142
|
+
- [`@owlmeans/entrypoint`](../entrypoint) — immutable protocol declarations
|
|
143
|
+
- [`@owlmeans/server-api`](../server-api) — `handlers<Context>()` for HTTP bindings
|
|
144
|
+
- [`@owlmeans/server-socket`](../server-socket) — `connection()` for socket bindings
|
|
145
|
+
- [`@owlmeans/server-route`](../server-route) — the server route model a binding carries
|
|
146
|
+
- [`@owlmeans/server-app`](../server-app) — re-exports `bind` / `bindAll` and registers the list
|
|
147
|
+
- [`@owlmeans/client-entrypoint`](../client-entrypoint) — the browser-side binding of the same protocols
|
|
69
148
|
|
|
70
149
|
<!-- owlmeans:agent-guidance:start -->
|
|
71
150
|
## Agent guidance
|
|
@@ -75,7 +154,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
75
154
|
your project's skill store (`.agents/skills/`):
|
|
76
155
|
|
|
77
156
|
```sh
|
|
78
|
-
npx @owlmeans/agent-skills
|
|
157
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.32
|
|
79
158
|
```
|
|
80
159
|
|
|
81
160
|
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-entrypoint",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18-rc.30",
|
|
5
|
+
"generatedAt": "2026-09-22T12:36:21.839Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,42 +1,39 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: server-entrypoint
|
|
3
|
-
description:
|
|
3
|
+
description: Bind immutable @owlmeans/entrypoint declarations to protocol-bound server implementations. Load when serving a shared API, socket, or queue entrypoint.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
7
7
|
|
|
8
8
|
# @owlmeans/server-entrypoint
|
|
9
9
|
|
|
10
|
-
**
|
|
11
|
-
**Install:** `"@owlmeans/server-entrypoint": "^0.1.18-rc.0"` in `dependencies`
|
|
10
|
+
**Install:** `bun add @owlmeans/server-entrypoint@^0.1.18-rc.30`
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
Bind the imported protocol object to the implementation that serves it:
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
| `EntrypointOptions` | Options for elevating with handler, fixer, intermediate |
|
|
19
|
-
| `EntrypointRef` / `RefedEntrypointHandler` | Handler reference pattern |
|
|
20
|
-
| Helpers | Attach handlers, hook into request lifecycle |
|
|
14
|
+
```ts
|
|
15
|
+
import { bind } from '@owlmeans/server-entrypoint'
|
|
16
|
+
import { handlers } from '@owlmeans/server-api'
|
|
21
17
|
|
|
22
|
-
|
|
18
|
+
const api = handlers<AppContext>()
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
export const serverBindings = [
|
|
21
|
+
bind(projectProtocols.create, api.body(projectProtocols.create, async (body, context) =>
|
|
22
|
+
context.projects.create(body)
|
|
23
|
+
)),
|
|
24
|
+
]
|
|
28
25
|
```
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```typescript
|
|
35
|
-
import { makeSecurityHelper } from '@owlmeans/config'
|
|
36
|
-
const helper = makeSecurityHelper<Config, Context>(ctx)
|
|
37
|
-
const url = helper.makeUrl(route, '/callback')
|
|
38
|
-
```
|
|
27
|
+
`bind(protocol, handler?, options?)` returns a `ServerProtocolEntrypoint<Protocol>`.
|
|
28
|
+
`bindAll(declarations, handlers?)` is for a flat protocol collection at a registration boundary. A handler carries its
|
|
29
|
+
`protocol`, and a collection is matched by object identity; an alias is never used to find or
|
|
30
|
+
replace it. HTTP code should use `handlers<Context>()`; sockets use `connection(protocol, callback)`.
|
|
39
31
|
|
|
40
|
-
|
|
32
|
+
The second argument is either a protocol-bound handler (from `handlers<Context>()` above, or a
|
|
33
|
+
library factory that returns one) or omitted entirely for a parent route. A plain callback passed
|
|
34
|
+
directly to `bind()` is NOT the same thing: it is treated as a ref handler and invoked once, at
|
|
35
|
+
bind time, with the entrypoint ref as its only argument — not per-request. Wrap it with
|
|
36
|
+
`handlers<Context>()` first.
|
|
41
37
|
|
|
42
|
-
|
|
38
|
+
Do not create a mutable contextual declaration, use a compatibility entrypoint type, or attach a
|
|
39
|
+
handler with an alias. The declaration is shared data; the binding is its server-local runtime.
|
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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EntrypointProtocolDeclaration } from '@owlmeans/entrypoint';
|
|
2
|
+
import type { BoundEntrypointHandler, EntrypointOptions, RefedEntrypointHandler, ServerProtocolEntrypoint } from './types.js';
|
|
3
|
+
type ServerBinding<Protocol extends EntrypointProtocolDeclaration> = BoundEntrypointHandler<Protocol> | RefedEntrypointHandler;
|
|
4
|
+
/** Bind one immutable protocol and, when present, its protocol-bound implementation. */
|
|
5
|
+
export declare const bind: <Protocol extends EntrypointProtocolDeclaration>(protocol: Protocol, implementation?: ServerBinding<Protocol>, options?: EntrypointOptions<object>) => ServerProtocolEntrypoint<Protocol>;
|
|
6
|
+
/** Bind a flat declaration collection and pair each protocol with its own implementation. */
|
|
7
|
+
export declare const bindAll: <Protocol extends EntrypointProtocolDeclaration>(declarations: readonly Protocol[], implementations?: readonly BoundEntrypointHandler<Protocol>[]) => ServerProtocolEntrypoint<Protocol>[];
|
|
8
|
+
export {};
|
|
9
|
+
//# 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,EACQ,6BAA6B,EAChD,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EACV,sBAAsB,EAAE,iBAAiB,EAAiB,sBAAsB,EAChF,wBAAwB,EACzB,MAAM,YAAY,CAAA;AAEnB,KAAK,aAAa,CAAC,QAAQ,SAAS,6BAA6B,IAC7D,sBAAsB,CAAC,QAAQ,CAAC,GAChC,sBAAsB,CAAA;AAyB1B,wFAAwF;AACxF,eAAO,MAAM,IAAI,GAAI,QAAQ,SAAS,6BAA6B,YACvD,QAAQ,mBACD,aAAa,CAAC,QAAQ,CAAC,YAC9B,iBAAiB,CAAC,MAAM,CAAC,KAClC,wBAAwB,CAAC,QAAQ,CAWnC,CAAA;AAED,6FAA6F;AAC7F,eAAO,MAAM,OAAO,GAAI,QAAQ,SAAS,6BAA6B,gBACtD,SAAS,QAAQ,EAAE,oBAChB,SAAS,sBAAsB,CAAC,QAAQ,CAAC,EAAE,KAC3D,wBAAwB,CAAC,QAAQ,CAAC,EAEpC,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { materializeEntrypoint } from '@owlmeans/entrypoint';
|
|
2
|
+
import { isServerRouteModel, route } from '@owlmeans/server-route';
|
|
3
|
+
/** Attach a server implementation to an entrypoint materialized from a protocol declaration. */
|
|
4
|
+
const bindMaterializedEntrypoint = (declaration, handler, options) => {
|
|
5
|
+
const ref = { ref: undefined };
|
|
6
|
+
const intermediate = options?.intermediate
|
|
7
|
+
?? (isServerRouteModel(declaration.route) ? declaration.route.isIntermediate() : false);
|
|
8
|
+
const bound = declaration;
|
|
9
|
+
bound.route = route(declaration.route, intermediate, options?.routeOptions);
|
|
10
|
+
bound.filter = options?.filter ?? declaration.filter;
|
|
11
|
+
bound.guards = [...new Set([...(declaration.guards ?? []), ...(options?.guards ?? [])])];
|
|
12
|
+
bound.gate = options?.gate ?? declaration.gate;
|
|
13
|
+
bound.gateParams = options?.gateParams ?? declaration.gateParams;
|
|
14
|
+
bound.fixer = options?.fixer ?? bound.fixer;
|
|
15
|
+
if (handler != null)
|
|
16
|
+
bound.handle = handler(ref);
|
|
17
|
+
ref.ref = bound;
|
|
18
|
+
return bound;
|
|
19
|
+
};
|
|
20
|
+
/** Bind one immutable protocol and, when present, its protocol-bound implementation. */
|
|
21
|
+
export const bind = (protocol, implementation, options) => {
|
|
22
|
+
const handler = typeof implementation === 'function'
|
|
23
|
+
? implementation
|
|
24
|
+
: implementation?.bind;
|
|
25
|
+
const bound = Object.assign(bindMaterializedEntrypoint(materializeEntrypoint(protocol), handler, options), { protocol });
|
|
26
|
+
return bound;
|
|
27
|
+
};
|
|
28
|
+
/** Bind a flat declaration collection and pair each protocol with its own implementation. */
|
|
29
|
+
export const bindAll = (declarations, implementations = []) => declarations.map(declaration => bind(declaration, implementations.find(implementation => implementation.protocol === declaration)));
|
|
30
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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G,OAAO,CAAC,GAAG,CAAC,CAAA;IAChD,GAAG,CAAC,GAAG,GAAG,KAAK,CAAA;IAEf,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,wFAAwF;AACxF,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,QAAkB,EAClB,cAAwC,EACxC,OAAmC,EACC,EAAE;IACtC,MAAM,OAAO,GAAG,OAAO,cAAc,KAAK,UAAU;QAClD,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,cAAc,EAAE,IAAI,CAAA;IACxB,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,0BAA0B,CACpD,qBAAqB,CAAC,QAAQ,CAAC,EAC/B,OAAO,EACP,OAAO,CACR,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;IAEhB,OAAO,KAA2C,CAAA;AACpD,CAAC,CAAA;AAED,6FAA6F;AAC7F,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,YAAiC,EACjC,eAAe,GAAgD,EAAE,EAC3B,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CACxE,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,cAAc,CAAC,QAAQ,KAAK,WAAW,CAAC,CAAC,CACnG,CAAA"}
|
package/build/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ServerRouteModel, ServerRouteOptions } from '@owlmeans/server-route';
|
|
2
|
-
import type { CommonEntrypoint, EntrypointHandler, CommonEntrypointOptions } from '@owlmeans/entrypoint';
|
|
2
|
+
import type { CommonEntrypoint, EntrypointHandler, CommonEntrypointOptions, EntrypointProtocolDeclaration } from '@owlmeans/entrypoint';
|
|
3
3
|
import type { Service } from '@owlmeans/context';
|
|
4
4
|
export interface ServerEntrypoint<R> extends CommonEntrypoint {
|
|
5
5
|
route: ServerRouteModel<R>;
|
|
@@ -7,10 +7,6 @@ export interface ServerEntrypoint<R> extends CommonEntrypoint {
|
|
|
7
7
|
handle: EntrypointHandler;
|
|
8
8
|
}
|
|
9
9
|
export interface EntrypointOptions<R> extends CommonEntrypointOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Force entrypoint to be elevated even if it is already elevated
|
|
12
|
-
*/
|
|
13
|
-
force?: boolean;
|
|
14
10
|
fixer?: string;
|
|
15
11
|
intermediate?: boolean;
|
|
16
12
|
routeOptions?: ServerRouteOptions<R>;
|
|
@@ -24,4 +20,13 @@ export interface EntrypointRef<R> {
|
|
|
24
20
|
export interface RefedEntrypointHandler<R = {}> {
|
|
25
21
|
(ref: EntrypointRef<R>): EntrypointHandler;
|
|
26
22
|
}
|
|
23
|
+
/** The server-local representation of a shared protocol declaration. */
|
|
24
|
+
export type ServerProtocolEntrypoint<Protocol extends EntrypointProtocolDeclaration> = ServerEntrypoint<object> & {
|
|
25
|
+
readonly protocol: Protocol;
|
|
26
|
+
};
|
|
27
|
+
/** A handler that is inseparable from the protocol whose request it accepts. */
|
|
28
|
+
export interface BoundEntrypointHandler<Protocol extends EntrypointProtocolDeclaration> {
|
|
29
|
+
readonly protocol: Protocol;
|
|
30
|
+
bind: RefedEntrypointHandler;
|
|
31
|
+
}
|
|
27
32
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAClF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAClF,OAAO,KAAK,EACV,gBAAgB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,6BAA6B,EAC5F,MAAM,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
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.30",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
25
|
-
"@owlmeans/entrypoint": "^0.1.18-rc.
|
|
26
|
-
"@owlmeans/route": "^0.1.18-rc.
|
|
27
|
-
"@owlmeans/server-route": "^0.1.18-rc.
|
|
24
|
+
"@owlmeans/context": "^0.1.18-rc.28",
|
|
25
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.31",
|
|
26
|
+
"@owlmeans/route": "^0.1.18-rc.29",
|
|
27
|
+
"@owlmeans/server-route": "^0.1.18-rc.28"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@owlmeans/dep-config": "workspace:*",
|
package/src/index.ts
CHANGED
package/src/protocol.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { materializeEntrypoint } from '@owlmeans/entrypoint'
|
|
2
|
+
import type {
|
|
3
|
+
CommonEntrypoint, EntrypointProtocolDeclaration,
|
|
4
|
+
} from '@owlmeans/entrypoint'
|
|
5
|
+
import { isServerRouteModel, route } from '@owlmeans/server-route'
|
|
6
|
+
import type {
|
|
7
|
+
BoundEntrypointHandler, EntrypointOptions, EntrypointRef, RefedEntrypointHandler, ServerEntrypoint,
|
|
8
|
+
ServerProtocolEntrypoint,
|
|
9
|
+
} from './types.js'
|
|
10
|
+
|
|
11
|
+
type ServerBinding<Protocol extends EntrypointProtocolDeclaration> =
|
|
12
|
+
| BoundEntrypointHandler<Protocol>
|
|
13
|
+
| RefedEntrypointHandler
|
|
14
|
+
|
|
15
|
+
/** Attach a server implementation to an entrypoint materialized from a protocol declaration. */
|
|
16
|
+
const bindMaterializedEntrypoint = <R>(
|
|
17
|
+
declaration: CommonEntrypoint,
|
|
18
|
+
handler?: RefedEntrypointHandler<R>,
|
|
19
|
+
options?: EntrypointOptions<R>,
|
|
20
|
+
): ServerEntrypoint<R> => {
|
|
21
|
+
const ref: EntrypointRef<R> = { ref: undefined }
|
|
22
|
+
const intermediate = options?.intermediate
|
|
23
|
+
?? (isServerRouteModel(declaration.route) ? declaration.route.isIntermediate() : false)
|
|
24
|
+
const bound = declaration as ServerEntrypoint<R>
|
|
25
|
+
|
|
26
|
+
bound.route = route(declaration.route, intermediate, options?.routeOptions)
|
|
27
|
+
bound.filter = options?.filter ?? declaration.filter
|
|
28
|
+
bound.guards = [...new Set([...(declaration.guards ?? []), ...(options?.guards ?? [])])]
|
|
29
|
+
bound.gate = options?.gate ?? declaration.gate
|
|
30
|
+
bound.gateParams = options?.gateParams ?? declaration.gateParams
|
|
31
|
+
bound.fixer = options?.fixer ?? bound.fixer
|
|
32
|
+
if (handler != null) bound.handle = handler(ref)
|
|
33
|
+
ref.ref = bound
|
|
34
|
+
|
|
35
|
+
return bound
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Bind one immutable protocol and, when present, its protocol-bound implementation. */
|
|
39
|
+
export const bind = <Protocol extends EntrypointProtocolDeclaration>(
|
|
40
|
+
protocol: Protocol,
|
|
41
|
+
implementation?: ServerBinding<Protocol>,
|
|
42
|
+
options?: EntrypointOptions<object>,
|
|
43
|
+
): ServerProtocolEntrypoint<Protocol> => {
|
|
44
|
+
const handler = typeof implementation === 'function'
|
|
45
|
+
? implementation
|
|
46
|
+
: implementation?.bind
|
|
47
|
+
const bound = Object.assign(bindMaterializedEntrypoint(
|
|
48
|
+
materializeEntrypoint(protocol),
|
|
49
|
+
handler,
|
|
50
|
+
options,
|
|
51
|
+
), { protocol })
|
|
52
|
+
|
|
53
|
+
return bound as ServerProtocolEntrypoint<Protocol>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Bind a flat declaration collection and pair each protocol with its own implementation. */
|
|
57
|
+
export const bindAll = <Protocol extends EntrypointProtocolDeclaration>(
|
|
58
|
+
declarations: readonly Protocol[],
|
|
59
|
+
implementations: readonly BoundEntrypointHandler<Protocol>[] = [],
|
|
60
|
+
): ServerProtocolEntrypoint<Protocol>[] => declarations.map(declaration =>
|
|
61
|
+
bind(declaration, implementations.find(implementation => implementation.protocol === declaration)),
|
|
62
|
+
)
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ServerRouteModel, ServerRouteOptions } from '@owlmeans/server-route'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
CommonEntrypoint, EntrypointHandler, CommonEntrypointOptions, EntrypointProtocolDeclaration,
|
|
4
|
+
} from '@owlmeans/entrypoint'
|
|
3
5
|
import type { Service } from '@owlmeans/context'
|
|
4
6
|
|
|
5
7
|
export interface ServerEntrypoint<R> extends CommonEntrypoint {
|
|
@@ -9,10 +11,6 @@ export interface ServerEntrypoint<R> extends CommonEntrypoint {
|
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
export interface EntrypointOptions<R> extends CommonEntrypointOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Force entrypoint to be elevated even if it is already elevated
|
|
14
|
-
*/
|
|
15
|
-
force?: boolean
|
|
16
14
|
fixer?: string
|
|
17
15
|
intermediate?: boolean
|
|
18
16
|
routeOptions?: ServerRouteOptions<R>
|
|
@@ -29,3 +27,14 @@ export interface EntrypointRef<R> {
|
|
|
29
27
|
export interface RefedEntrypointHandler<R = {}> {
|
|
30
28
|
(ref: EntrypointRef<R>): EntrypointHandler
|
|
31
29
|
}
|
|
30
|
+
|
|
31
|
+
/** The server-local representation of a shared protocol declaration. */
|
|
32
|
+
export type ServerProtocolEntrypoint<Protocol extends EntrypointProtocolDeclaration> = ServerEntrypoint<object> & {
|
|
33
|
+
readonly protocol: Protocol
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A handler that is inseparable from the protocol whose request it accepts. */
|
|
37
|
+
export interface BoundEntrypointHandler<Protocol extends EntrypointProtocolDeclaration> {
|
|
38
|
+
readonly protocol: Protocol
|
|
39
|
+
bind: RefedEntrypointHandler
|
|
40
|
+
}
|
package/build/entrypoint.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ServerRouteModel } from '@owlmeans/server-route';
|
|
2
|
-
import type { ServerEntrypoint, EntrypointOptions, RefedEntrypointHandler } from './types.js';
|
|
3
|
-
import type { CommonEntrypoint } from '@owlmeans/entrypoint';
|
|
4
|
-
import type { CommonRouteModel } from '@owlmeans/route';
|
|
5
|
-
export declare const entrypoint: <R>(arg: CommonEntrypoint | ServerRouteModel<R> | CommonRouteModel, handler?: RefedEntrypointHandler<R>, opts?: EntrypointOptions<R>) => ServerEntrypoint<R>;
|
|
6
|
-
//# sourceMappingURL=entrypoint.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../src/entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAiB,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAG5G,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIvD,eAAO,MAAM,UAAU,GAAI,CAAC,OACrB,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,YAAY,sBAAsB,CAAC,CAAC,CAAC,SAAS,iBAAiB,CAAC,CAAC,CAAC,KAC/H,gBAAgB,CAAC,CAAC,CAuCpB,CAAA"}
|
package/build/entrypoint.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { isEntrypoint, makeCommonEntrypoint } from './utils/entrypoint.js';
|
|
2
|
-
import { isServerRouteModel, route } from '@owlmeans/server-route';
|
|
3
|
-
import { prependBase } from '@owlmeans/route/utils';
|
|
4
|
-
export const entrypoint = (arg, handler, opts) => {
|
|
5
|
-
const entrypointHandle = { ref: undefined };
|
|
6
|
-
let _entrypoint;
|
|
7
|
-
if (isEntrypoint(arg)) {
|
|
8
|
-
const routeModel = route(arg.route, opts?.intermediate ?? false, opts?.routeOptions);
|
|
9
|
-
_entrypoint = arg;
|
|
10
|
-
_entrypoint.route = routeModel;
|
|
11
|
-
_entrypoint.filter = opts?.filter ?? arg.filter;
|
|
12
|
-
_entrypoint.guards = [...(arg.guards ?? []), ...(opts?.guards ?? [])];
|
|
13
|
-
_entrypoint.gate = opts?.gate ?? arg.gate;
|
|
14
|
-
_entrypoint.gateParams = opts?.gateParams ?? arg.gateParams;
|
|
15
|
-
}
|
|
16
|
-
else if (isServerRouteModel(arg)) {
|
|
17
|
-
_entrypoint = makeCommonEntrypoint(arg, { ...opts });
|
|
18
|
-
_entrypoint.route = arg;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
const _route = route(arg, opts?.intermediate ?? false, opts?.routeOptions);
|
|
22
|
-
_entrypoint = makeCommonEntrypoint(_route, { ...opts });
|
|
23
|
-
_entrypoint.route = _route;
|
|
24
|
-
}
|
|
25
|
-
_entrypoint.fixer = opts?.fixer;
|
|
26
|
-
if (handler != null) {
|
|
27
|
-
_entrypoint.handle = handler(entrypointHandle);
|
|
28
|
-
}
|
|
29
|
-
_entrypoint.reinitializeContext = (context) => {
|
|
30
|
-
const newEntrypoint = entrypoint(arg, handler, opts);
|
|
31
|
-
newEntrypoint.ctx = context;
|
|
32
|
-
return newEntrypoint;
|
|
33
|
-
};
|
|
34
|
-
_entrypoint.getPath = () => prependBase(_entrypoint.route.route);
|
|
35
|
-
entrypointHandle.ref = _entrypoint;
|
|
36
|
-
return _entrypoint;
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=entrypoint.js.map
|
package/build/entrypoint.js.map
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EAAE,CAAwB,CAAA;QAC3E,WAAW,CAAC,KAAK,GAAG,GAAG,CAAA;IACzB,CAAC;SAAM,CAAC;QACN,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,YAAY,IAAI,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,CAAA;QAC1E,WAAW,GAAG,oBAAoB,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE,CAAwB,CAAA;QAC9E,WAAW,CAAC,KAAK,GAAG,MAAM,CAAA;IAC5B,CAAC;IAED,WAAW,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,CAAA;IAC/B,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,WAAW,CAAC,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAChD,CAAC;IAED,WAAW,CAAC,mBAAmB,GAAG,CAAI,OAA0B,EAAE,EAAE;QAClE,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;QACpD,aAAa,CAAC,GAAG,GAAG,OAAO,CAAA;QAE3B,OAAO,aAAkB,CAAA;IAC3B,CAAC,CAAA;IAED,WAAW,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAEhE,gBAAgB,CAAC,GAAG,GAAG,WAAW,CAAA;IAElC,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA"}
|
package/build/helper.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ServerEntrypoint, EntrypointOptions, RefedEntrypointHandler } from './types.js';
|
|
2
|
-
import type { CommonEntrypoint } from '@owlmeans/entrypoint';
|
|
3
|
-
export declare const elevate: <R>(entrypoints: (CommonEntrypoint | ServerEntrypoint<R>)[], alias: string, handler?: RefedEntrypointHandler<R> | boolean | EntrypointOptions<R>, opts?: boolean | EntrypointOptions<R>) => ServerEntrypoint<R>[];
|
|
4
|
-
export declare const guard: <R>(guard: string, opts?: EntrypointOptions<R>) => EntrypointOptions<R>;
|
|
5
|
-
//# sourceMappingURL=helper.d.ts.map
|
package/build/helper.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAI7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D,eAAO,MAAM,OAAO,GAAI,CAAC,eACV,CAAC,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,SAChD,MAAM,YACH,sBAAsB,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,SAC7D,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,KACpC,gBAAgB,CAAC,CAAC,CAAC,EAuBrB,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,SAAS,iBAAiB,CAAC,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,CACjD,CAAA"}
|
package/build/helper.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { entrypoint } from './entrypoint.js';
|
|
2
|
-
import { isServerRouteModel } from '@owlmeans/server-route';
|
|
3
|
-
import { createBasicGuard } from './utils/helper.js';
|
|
4
|
-
export const elevate = (entrypoints, alias, handler, opts) => {
|
|
5
|
-
const idx = entrypoints.findIndex(({ route }) => route.route.alias === alias);
|
|
6
|
-
if (idx === -1) {
|
|
7
|
-
throw new SyntaxError(`Entrypoint with alias ${alias} not present`);
|
|
8
|
-
}
|
|
9
|
-
if (typeof handler === 'boolean') {
|
|
10
|
-
opts = handler;
|
|
11
|
-
handler = undefined;
|
|
12
|
-
}
|
|
13
|
-
if (typeof handler === 'object' && typeof handler !== 'function') {
|
|
14
|
-
opts = handler;
|
|
15
|
-
handler = undefined;
|
|
16
|
-
}
|
|
17
|
-
const force = typeof opts === 'object' && opts.force;
|
|
18
|
-
if (isServerRouteModel(entrypoints[idx].route) && !force) {
|
|
19
|
-
throw new SyntaxError(`Entrypoint with alias ${alias} is already elevated`);
|
|
20
|
-
}
|
|
21
|
-
entrypoints[idx] = entrypoint(entrypoints[idx], handler, typeof opts === 'boolean' ? { intermediate: opts } : opts);
|
|
22
|
-
return entrypoints;
|
|
23
|
-
};
|
|
24
|
-
export const guard = (guard, opts) => ({ ...createBasicGuard(guard, opts) });
|
|
25
|
-
//# sourceMappingURL=helper.js.map
|
package/build/helper.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAGpD,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,WAAuD,EACvD,KAAa,EACb,OAAoE,EACpE,IAAqC,EACd,EAAE;IACzB,MAAM,GAAG,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,CAAA;IAC7E,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,WAAW,CAAC,yBAAyB,KAAK,cAAc,CAAC,CAAA;IACrE,CAAC;IACD,IAAI,OAAO,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,IAAI,GAAG,OAAO,CAAA;QACd,OAAO,GAAG,SAAS,CAAA;IACrB,CAAC;IACD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QACjE,IAAI,GAAG,OAAO,CAAA;QACd,OAAO,GAAG,SAAS,CAAA;IACrB,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAA;IACpD,IAAI,kBAAkB,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QACzD,MAAM,IAAI,WAAW,CAAC,yBAAyB,KAAK,sBAAsB,CAAC,CAAA;IAC7E,CAAC;IAED,WAAW,CAAC,GAAG,CAAC,GAAG,UAAU,CAC3B,WAAW,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CACrF,CAAA;IAED,OAAO,WAAoC,CAAA;AAC7C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,CAAI,KAAa,EAAE,IAA2B,EAAwB,EAAE,CAC3F,CAAC,EAAE,GAAG,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../../src/utils/entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entrypoint.js","sourceRoot":"","sources":["../../src/utils/entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA"}
|
package/build/utils/helper.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../src/utils/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,gBAAgB,EAAE,MAAM,sBAAsB,CAAA"}
|
package/build/utils/helper.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/utils/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,gBAAgB,EAAE,MAAM,sBAAsB,CAAA"}
|
package/src/entrypoint.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { ServerRouteModel } from '@owlmeans/server-route'
|
|
2
|
-
import type { ServerEntrypoint, EntrypointOptions, EntrypointRef, RefedEntrypointHandler } from './types.js'
|
|
3
|
-
import { isEntrypoint, makeCommonEntrypoint } from './utils/entrypoint.js'
|
|
4
|
-
import { isServerRouteModel, route } from '@owlmeans/server-route'
|
|
5
|
-
import type { CommonEntrypoint } from '@owlmeans/entrypoint'
|
|
6
|
-
import type { CommonRouteModel } from '@owlmeans/route'
|
|
7
|
-
import type { BasicContext } from '@owlmeans/context'
|
|
8
|
-
import { prependBase } from '@owlmeans/route/utils'
|
|
9
|
-
|
|
10
|
-
export const entrypoint = <R>(
|
|
11
|
-
arg: CommonEntrypoint | ServerRouteModel<R> | CommonRouteModel, handler?: RefedEntrypointHandler<R>, opts?: EntrypointOptions<R>
|
|
12
|
-
): ServerEntrypoint<R> => {
|
|
13
|
-
const entrypointHandle: EntrypointRef<R> = { ref: undefined }
|
|
14
|
-
|
|
15
|
-
let _entrypoint: ServerEntrypoint<R>
|
|
16
|
-
|
|
17
|
-
if (isEntrypoint(arg)) {
|
|
18
|
-
const routeModel = route(arg.route, opts?.intermediate ?? false, opts?.routeOptions)
|
|
19
|
-
_entrypoint = arg as ServerEntrypoint<R>
|
|
20
|
-
_entrypoint.route = routeModel
|
|
21
|
-
_entrypoint.filter = opts?.filter ?? arg.filter
|
|
22
|
-
_entrypoint.guards = [...(arg.guards ?? []), ...(opts?.guards ?? [])]
|
|
23
|
-
_entrypoint.gate = opts?.gate ?? arg.gate
|
|
24
|
-
_entrypoint.gateParams = opts?.gateParams ?? arg.gateParams
|
|
25
|
-
} else if (isServerRouteModel(arg)) {
|
|
26
|
-
_entrypoint = makeCommonEntrypoint(arg, { ...opts }) as ServerEntrypoint<R>
|
|
27
|
-
_entrypoint.route = arg
|
|
28
|
-
} else {
|
|
29
|
-
const _route = route(arg, opts?.intermediate ?? false, opts?.routeOptions)
|
|
30
|
-
_entrypoint = makeCommonEntrypoint(_route, { ...opts }) as ServerEntrypoint<R>
|
|
31
|
-
_entrypoint.route = _route
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
_entrypoint.fixer = opts?.fixer
|
|
35
|
-
if (handler != null) {
|
|
36
|
-
_entrypoint.handle = handler(entrypointHandle)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
_entrypoint.reinitializeContext = <T>(context: BasicContext<any>) => {
|
|
40
|
-
const newEntrypoint = entrypoint(arg, handler, opts)
|
|
41
|
-
newEntrypoint.ctx = context
|
|
42
|
-
|
|
43
|
-
return newEntrypoint as T
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
_entrypoint.getPath = () => prependBase(_entrypoint.route.route)
|
|
47
|
-
|
|
48
|
-
entrypointHandle.ref = _entrypoint
|
|
49
|
-
|
|
50
|
-
return _entrypoint
|
|
51
|
-
}
|
package/src/helper.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ServerEntrypoint, EntrypointOptions, RefedEntrypointHandler } from './types.js'
|
|
2
|
-
import { entrypoint } from './entrypoint.js'
|
|
3
|
-
import { isServerRouteModel } from '@owlmeans/server-route'
|
|
4
|
-
import { createBasicGuard } from './utils/helper.js'
|
|
5
|
-
import type { CommonEntrypoint } from '@owlmeans/entrypoint'
|
|
6
|
-
|
|
7
|
-
export const elevate = <R>(
|
|
8
|
-
entrypoints: (CommonEntrypoint | ServerEntrypoint<R>)[],
|
|
9
|
-
alias: string,
|
|
10
|
-
handler?: RefedEntrypointHandler<R> | boolean | EntrypointOptions<R>,
|
|
11
|
-
opts?: boolean | EntrypointOptions<R>
|
|
12
|
-
): ServerEntrypoint<R>[] => {
|
|
13
|
-
const idx = entrypoints.findIndex(({ route }) => route.route.alias === alias)
|
|
14
|
-
if (idx === -1) {
|
|
15
|
-
throw new SyntaxError(`Entrypoint with alias ${alias} not present`)
|
|
16
|
-
}
|
|
17
|
-
if (typeof handler === 'boolean') {
|
|
18
|
-
opts = handler
|
|
19
|
-
handler = undefined
|
|
20
|
-
}
|
|
21
|
-
if (typeof handler === 'object' && typeof handler !== 'function') {
|
|
22
|
-
opts = handler
|
|
23
|
-
handler = undefined
|
|
24
|
-
}
|
|
25
|
-
const force = typeof opts === 'object' && opts.force
|
|
26
|
-
if (isServerRouteModel(entrypoints[idx].route) && !force) {
|
|
27
|
-
throw new SyntaxError(`Entrypoint with alias ${alias} is already elevated`)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
entrypoints[idx] = entrypoint(
|
|
31
|
-
entrypoints[idx], handler, typeof opts === 'boolean' ? { intermediate: opts } : opts
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
return entrypoints as ServerEntrypoint<R>[]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const guard = <R>(guard: string, opts?: EntrypointOptions<R>): EntrypointOptions<R> =>
|
|
38
|
-
({ ...createBasicGuard(guard, opts) })
|
package/src/utils/entrypoint.ts
DELETED
package/src/utils/helper.ts
DELETED