@owlmeans/server-entrypoint 0.1.18-rc.13 → 0.1.18-rc.15
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 +21 -30
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-entrypoint/SKILL.md +17 -111
- package/build/entrypoint.js +2 -2
- package/build/entrypoint.js.map +1 -1
- package/build/helper.d.ts +4 -5
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +2 -16
- package/build/helper.js.map +1 -1
- package/build/index.d.ts +0 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +0 -2
- package/build/index.js.map +1 -1
- package/build/protocol.d.ts +6 -2
- package/build/protocol.d.ts.map +1 -1
- package/build/protocol.js +24 -2
- package/build/protocol.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +0 -2
- package/src/protocol.ts +47 -6
- package/src/entrypoint.ts +0 -45
- package/src/helper.ts +0 -72
- package/src/utils/entrypoint.ts +0 -3
- package/src/utils/helper.ts +0 -2
package/README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# @owlmeans/server-entrypoint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Server-side entrypoint system: binds shared protocol declarations to request handlers.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
- `
|
|
8
|
-
- `
|
|
9
|
-
-
|
|
10
|
-
- Used internally by `@owlmeans/server-app`'s `elevate` re-export
|
|
7
|
+
- `bind(protocol, handler?, opts?)` materializes one immutable protocol with its handler
|
|
8
|
+
- `bindAll(protocols, handlers?)` materializes a declaration collection
|
|
9
|
+
- Used by `@owlmeans/server-app` when assembling a server context
|
|
11
10
|
|
|
12
11
|
## Installation
|
|
13
12
|
|
|
@@ -17,39 +16,32 @@ bun add @owlmeans/server-entrypoint@^0.1.18-rc.10
|
|
|
17
16
|
|
|
18
17
|
## Usage
|
|
19
18
|
|
|
20
|
-
Typical pattern —
|
|
19
|
+
Typical pattern — declare protocols in `common`, bind them in `api`:
|
|
21
20
|
|
|
22
21
|
```typescript
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
22
|
+
import { bind } from '@owlmeans/server-entrypoint'
|
|
23
|
+
import { handlers } from '@owlmeans/server-api'
|
|
24
|
+
import { appEntrypoints as protocols } from 'my-app-common'
|
|
25
|
+
import type { Context } from 'my-app-backend'
|
|
25
26
|
|
|
27
|
+
const api = handlers<Context>()
|
|
26
28
|
const appEntrypoints = [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
bind(protocols.api.projectCreate, api.request(protocols.api.projectCreate, async (req, ctx) =>
|
|
30
|
+
ctx.project().create(req.body))),
|
|
31
|
+
bind(protocols.api.projectGet, api.params(protocols.api.projectGet, async (req, ctx) =>
|
|
32
|
+
ctx.project().get(req.params.id))),
|
|
29
33
|
]
|
|
30
|
-
|
|
31
|
-
elevate(appEntrypoints, 'project-create', handleBody(async (payload, ctx) => {
|
|
32
|
-
return await ctx.project().create(payload)
|
|
33
|
-
}))
|
|
34
|
-
|
|
35
|
-
elevate(appEntrypoints, 'project-get', handleParams(async (params, ctx) => {
|
|
36
|
-
return await ctx.project().get(params.id)
|
|
37
|
-
}))
|
|
38
34
|
```
|
|
39
35
|
|
|
40
36
|
## API
|
|
41
37
|
|
|
42
|
-
### `
|
|
43
|
-
|
|
44
|
-
Replaces the element carrying `alias` with its elevated counterpart, in place, attaching `handler`. Elevating the same alias again just replaces it again; guards passed here are added to the ones the entrypoint declared. Throws when no entrypoint carries the alias.
|
|
45
|
-
|
|
46
|
-
### `entrypoint<R>(commonEntrypoint, handler?, opts?): ServerEntrypoint<R>`
|
|
38
|
+
### `bind<Protocol>(protocol, handler?, opts?): ServerProtocolEntrypoint<Protocol>`
|
|
47
39
|
|
|
48
|
-
|
|
40
|
+
Materializes one immutable protocol declaration and attaches its protocol-bound implementation.
|
|
49
41
|
|
|
50
|
-
### `
|
|
42
|
+
### `bindAll(protocols, handlers?): ServerProtocolEntrypoint[]`
|
|
51
43
|
|
|
52
|
-
|
|
44
|
+
Materializes a flat declaration collection and pairs implementations by protocol reference.
|
|
53
45
|
|
|
54
46
|
### `ServerEntrypoint<R>`
|
|
55
47
|
|
|
@@ -64,9 +56,8 @@ A handler factory: `(ref: { ref?: { ctx?: Context } }) => EntrypointHandler`.
|
|
|
64
56
|
|
|
65
57
|
## Related Packages
|
|
66
58
|
|
|
67
|
-
- [`@owlmeans/entrypoint`](../entrypoint) —
|
|
68
|
-
- [`@owlmeans/server-api`](../server-api) — handler
|
|
69
|
-
- [`@owlmeans/server-app`](../server-app) — re-exports `elevate`, `entrypoint`, `guard`
|
|
59
|
+
- [`@owlmeans/entrypoint`](../entrypoint) — immutable protocol declarations
|
|
60
|
+
- [`@owlmeans/server-api`](../server-api) — typed handler factories used with `bind`
|
|
70
61
|
|
|
71
62
|
<!-- owlmeans:agent-guidance:start -->
|
|
72
63
|
## Agent guidance
|
|
@@ -76,7 +67,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
76
67
|
your project's skill store (`.agents/skills/`):
|
|
77
68
|
|
|
78
69
|
```sh
|
|
79
|
-
npx @owlmeans/agent-skills@^0.1.18-rc.
|
|
70
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.16
|
|
80
71
|
```
|
|
81
72
|
|
|
82
73
|
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-09-
|
|
4
|
+
"version": "0.1.18-rc.15",
|
|
5
|
+
"generatedAt": "2026-09-12T12:32:46.374Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,125 +1,31 @@
|
|
|
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.13"` in `dependencies`
|
|
10
|
+
Bind the imported protocol object to the implementation that serves it:
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
```ts
|
|
13
|
+
import { bind } from '@owlmeans/server-entrypoint'
|
|
14
|
+
import { handlers } from '@owlmeans/server-api'
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|--------|-------------|
|
|
17
|
-
| `bind(protocol, implementation?, opts?)` | Materialize a protocol and its protocol-bound handler |
|
|
18
|
-
| `ServerProtocolEntrypoint<P>` | The server module whose request/reply types come from `P` |
|
|
19
|
-
| `BoundEntrypointHandler<P>` | A handler implementation tied to exactly one protocol |
|
|
20
|
-
| `ServerEntrypoint<R>` | Server entrypoint interface — a common entrypoint whose `route` is a `ServerRouteModel` plus `handle` and an optional `fixer` |
|
|
21
|
-
| `entrypoint(arg, handler?, opts?)` | Build one from an existing declaration, a server route model, or a plain route model |
|
|
22
|
-
| `elevate(entrypoints, alias, handler?, opts?)` | Replace the declaration under `alias` in-place with its elevated counterpart |
|
|
23
|
-
| `guard(alias, opts?)` | Options that require a guard, ready to pass as `opts` |
|
|
24
|
-
| `EntrypointOptions<R>` | `fixer`, `intermediate`, `routeOptions`, plus everything a common entrypoint declares. `elevate()` reads only `route`-shaping and access keys from it — `intermediate`, `routeOptions`, `filter`, `guards`, `gate`, `gateParams`, `fixer`; `handle` and `sticky` are silently ignored there |
|
|
25
|
-
| `EntrypointRef<R>` / `RefedEntrypointHandler<R>` | `(ref) => handler` — the wrapper is handed a ref that resolves to the entrypoint being built, which is how a handler reaches its own `ctx` |
|
|
26
|
-
| `FixerService` | Per-entrypoint error rendering (`handle(reply, error)`), named by `opts.fixer` and resolved as a service |
|
|
16
|
+
const api = handlers<AppContext>()
|
|
27
17
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```typescript
|
|
35
|
-
import { bind, handlers } from '@owlmeans/server-app'
|
|
36
|
-
import { item } from 'project-common'
|
|
37
|
-
|
|
38
|
-
const handle = handlers<Context>()
|
|
39
|
-
export const getItem = handle.params(item.get, async ({ id }, context) =>
|
|
40
|
-
await context.resource<ItemResource>('item').load(id))
|
|
41
|
-
|
|
42
|
-
export const appEntrypoints = [bind(item.get, getItem)]
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Use `handle.body`, `handle.params`, or `handle.request` according to the protocol contract. A
|
|
46
|
-
body/params helper refuses a protocol that did not declare that section, and the callback return
|
|
47
|
-
must match the protocol response.
|
|
48
|
-
|
|
49
|
-
Most legacy app code uses `elevate()` from `@owlmeans/server-app`. Import directly only when
|
|
50
|
-
implementing custom entrypoint helpers.
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
import { elevate, guard } from '@owlmeans/server-entrypoint'
|
|
54
|
-
import type { ServerEntrypoint } from '@owlmeans/server-entrypoint'
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### elevate forms
|
|
58
|
-
|
|
59
|
-
The third argument is overloaded, and all four forms are legal:
|
|
60
|
-
|
|
61
|
-
```typescript
|
|
62
|
-
elevate(entrypoints, alias) // bare — make it a server entrypoint, nothing more
|
|
63
|
-
elevate(entrypoints, alias, handler) // attach a handler
|
|
64
|
-
elevate(entrypoints, alias, guard(DAUTH_GUARD)) // options only
|
|
65
|
-
elevate(entrypoints, alias, handler, true) // trailing boolean === { intermediate: true }
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
`DAUTH_GUARD` above is `@owlmeans/server-auth`'s `DEFAULT_ALIAS` (`auth`), re-exported under that
|
|
69
|
-
name by `@owlmeans/server-app`.
|
|
70
|
-
|
|
71
|
-
It throws `SyntaxError` when no entrypoint in the list carries that alias, and it mutates the array
|
|
72
|
-
it is given — the elevated entrypoint replaces the element, and the same array is returned.
|
|
73
|
-
|
|
74
|
-
**A handler only ever arrives as the third argument.** `elevate` passes the options through
|
|
75
|
-
`entrypoint()`, which on an already-declared entrypoint applies `route`, `filter`, `guards`, `gate`,
|
|
76
|
-
`gateParams`, `intermediate` and `fixer` and nothing else — so `elevate(list, ALIAS, { handle: fn })`
|
|
77
|
-
type-checks, drops the function, and leaves an entrypoint the server never binds.
|
|
78
|
-
|
|
79
|
-
Elevating is **idempotent**: elevating the same alias again simply replaces the element once more.
|
|
80
|
-
An entrypoint stays intermediate unless the new call says otherwise, guards passed at elevation are
|
|
81
|
-
**unioned** with the ones the declaration already carries (so what the entrypoint declared still
|
|
82
|
-
applies), and a `fixer` already set survives a call that does not name one.
|
|
83
|
-
|
|
84
|
-
The **bare** form only converts the declaration into a server entrypoint — a `ServerRouteModel`
|
|
85
|
-
that `canServeModule` recognises. It creates no route group: an entrypoint with no `handle` is never
|
|
86
|
-
bound as a route, guarded or not, and `intermediate` defaults to what the declaration already was
|
|
87
|
-
(`false` for a common declaration), so a bare elevate does not put it in the intermediate chain
|
|
88
|
-
either. A live intermediate is `elevate(list, ALIAS, handleIntermediate(fn), true)` — a handler plus
|
|
89
|
-
`true`, with `handleIntermediate` from `@owlmeans/server-api`.
|
|
90
|
-
|
|
91
|
-
A parent alias that carries only a `guard()` for its children needs no elevation at all:
|
|
92
|
-
`getGuards()` walks `parent()`, which resolves the alias against the context, and a registered
|
|
93
|
-
declaration answers there whether or not it was elevated. `gate()` is not in this package — it comes
|
|
94
|
-
from `@owlmeans/entrypoint`, and only `guard()` is defined here.
|
|
95
|
-
|
|
96
|
-
## What a server registers
|
|
97
|
-
|
|
98
|
-
`mount()` is the address a server binds: `base` plus every ancestor's segment, then this one. The
|
|
99
|
-
declaration itself only ever states the segment it contributes, so composing the rest takes the
|
|
100
|
-
context the entrypoint is registered in — which is why route registration happens after `init()`,
|
|
101
|
-
never at declaration time.
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
server.route({ url: entrypoint.mount(), method, handler })
|
|
105
|
-
entrypoint.route.match(request, entrypoint.mount()) // intermediates test the same mount
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
Guards and gates are read with `getGuards()` / `getGates()`, which include everything the ancestors
|
|
109
|
-
declared, and they run before the handler — a handler that re-checks them duplicates an enforced
|
|
110
|
-
rule.
|
|
111
|
-
|
|
112
|
-
## Cross-Service URL Generation
|
|
113
|
-
|
|
114
|
-
Use `makeSecurityHelper` from `@owlmeans/config` to build URLs pointing at other services (OAuth
|
|
115
|
-
redirect URIs, webhook callbacks, etc.):
|
|
116
|
-
|
|
117
|
-
```typescript
|
|
118
|
-
import { makeSecurityHelper } from '@owlmeans/config'
|
|
119
|
-
const helper = makeSecurityHelper<Config, Context>(ctx)
|
|
120
|
-
const url = helper.makeUrl(entrypoint.address(), '/callback')
|
|
18
|
+
export const entrypoints = [
|
|
19
|
+
bind(projectEntrypoints.create, api.body(projectEntrypoints.create, async (body, context) =>
|
|
20
|
+
context.projects.create(body)
|
|
21
|
+
)),
|
|
22
|
+
]
|
|
121
23
|
```
|
|
122
24
|
|
|
123
|
-
|
|
25
|
+
`bind(protocol, handler?, options?)` returns a `ServerProtocolEntrypoint<Protocol>`.
|
|
26
|
+
`bindAll(declarations, handlers?)` is for a flat protocol collection. A handler carries its
|
|
27
|
+
`protocol`, and a collection is matched by object identity; an alias is never used to find or
|
|
28
|
+
replace it. HTTP code should use `handlers<Context>()`; sockets use `connection(protocol, callback)`.
|
|
124
29
|
|
|
125
|
-
|
|
30
|
+
Do not create a mutable contextual declaration, use a compatibility entrypoint type, or attach a
|
|
31
|
+
handler with an alias. The declaration is shared data; the binding is its server-local runtime.
|
package/build/entrypoint.js
CHANGED
|
@@ -4,7 +4,7 @@ export const entrypoint = (arg, handler, opts) => {
|
|
|
4
4
|
const entrypointHandle = { ref: undefined };
|
|
5
5
|
let _entrypoint;
|
|
6
6
|
if (isEntrypoint(arg)) {
|
|
7
|
-
//
|
|
7
|
+
// Binding the same alias again is legal, so an intermediate route stays intermediate unless
|
|
8
8
|
// this call says otherwise.
|
|
9
9
|
const intermediate = opts?.intermediate
|
|
10
10
|
?? (isServerRouteModel(arg.route) ? arg.route.isIntermediate() : false);
|
|
@@ -12,7 +12,7 @@ export const entrypoint = (arg, handler, opts) => {
|
|
|
12
12
|
_entrypoint = arg;
|
|
13
13
|
_entrypoint.route = routeModel;
|
|
14
14
|
_entrypoint.filter = opts?.filter ?? arg.filter;
|
|
15
|
-
//
|
|
15
|
+
// Binding adds guards, it never swaps them: what the declaration carries still applies.
|
|
16
16
|
_entrypoint.guards = [...new Set([...(arg.guards ?? []), ...(opts?.guards ?? [])])];
|
|
17
17
|
_entrypoint.gate = opts?.gate ?? arg.gate;
|
|
18
18
|
_entrypoint.gateParams = opts?.gateParams ?? arg.gateParams;
|
package/build/entrypoint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entrypoint.js","sourceRoot":"","sources":["../src/entrypoint.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAC1E,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAIlE,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,GAAwD,EAAE,OAAmC,EAAE,IAA2B,EACrG,EAAE;IACvB,MAAM,gBAAgB,GAAqB,EAAE,GAAG,EAAE,SAAS,EAAE,CAAA;IAE7D,IAAI,WAAgC,CAAA;IAEpC,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,
|
|
1
|
+
{"version":3,"file":"entryp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UAAU,CAAA;IAC7D,CAAC;SAAM,IAAI,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,WAAW,GAAG,oBAAoB,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,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,IAAI,WAAW,CAAC,KAAK,CAAA;IACpD,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,WAAW,CAAC,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAChD,CAAC;IAED,gBAAgB,CAAC,GAAG,GAAG,WAAW,CAAA;IAElC,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA"}
|
package/build/helper.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { CommonEntrypoint
|
|
1
|
+
import type { ServerEntrypoint, EntrypointOptions, RefedEntrypointHandler } from './types.js';
|
|
2
|
+
import type { CommonEntrypoint } from '@owlmeans/entrypoint';
|
|
3
3
|
/**
|
|
4
|
-
* Replace the entrypoint declared under `alias` with its
|
|
4
|
+
* Replace the entrypoint declared under `alias` with its materialized counterpart. Replacement is
|
|
5
5
|
* idempotent — calling it again simply replaces the element once more, and the guards it brings
|
|
6
6
|
* are added to the ones already declared.
|
|
7
7
|
*
|
|
8
8
|
* @throws {SyntaxError} when no entrypoint carries the alias
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function elevate<R>(entrypoints: (CommonEntrypoint | ServerEntrypoint<R>)[], alias: string, handler?: RefedEntrypointHandler<R> | boolean | EntrypointOptions<R>, opts?: boolean | EntrypointOptions<R>): ServerEntrypoint<R>[];
|
|
10
|
+
export declare function replaceEntrypoint<R>(entrypoints: (CommonEntrypoint | ServerEntrypoint<R>)[], alias: string, handler?: RefedEntrypointHandler<R> | boolean | EntrypointOptions<R>, opts?: boolean | EntrypointOptions<R>): ServerEntrypoint<R>[];
|
|
12
11
|
export declare const guard: <R>(guard: string, opts?: EntrypointOptions<R>) => EntrypointOptions<R>;
|
|
13
12
|
//# sourceMappingURL=helper.d.ts.map
|
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,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAAE,iBAAiB,EAAE,sBAAsB,EAC5D,MAAM,YAAY,CAAA;AAGnB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,WAAW,EAAE,CAAC,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,EACvD,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,EACpE,IAAI,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,GACpC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAA;AA6BxB,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,SAAS,iBAAiB,CAAC,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,CACjD,CAAA"}
|
package/build/helper.js
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import { entrypoint } from './entrypoint.js';
|
|
2
|
-
import { bind } from './protocol.js';
|
|
3
2
|
import { createBasicGuard } from './utils/helper.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (typeof target !== 'string') {
|
|
7
|
-
return entrypoints.map((declaration) => {
|
|
8
|
-
if (!isEntrypointProtocol(declaration)) {
|
|
9
|
-
throw new SyntaxError('Protocol elevation accepts protocol declarations only');
|
|
10
|
-
}
|
|
11
|
-
const implementation = target.find(bound => bound.protocol === declaration);
|
|
12
|
-
return bind(declaration, implementation);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
const idx = entrypoints.findIndex((candidate) => !isEntrypointProtocol(candidate) && candidate.route.route.alias === target);
|
|
3
|
+
export function replaceEntrypoint(entrypoints, target, handler, opts) {
|
|
4
|
+
const idx = entrypoints.findIndex(candidate => candidate.route.route.alias === target);
|
|
16
5
|
if (idx === -1) {
|
|
17
6
|
throw new SyntaxError(`Entrypoint with alias ${target} not present`);
|
|
18
7
|
}
|
|
@@ -25,9 +14,6 @@ export function elevate(entrypoints, target, handler, opts) {
|
|
|
25
14
|
handler = undefined;
|
|
26
15
|
}
|
|
27
16
|
const declaration = entrypoints[idx];
|
|
28
|
-
if (isEntrypointProtocol(declaration)) {
|
|
29
|
-
throw new SyntaxError('String elevation accepts materialized entrypoints only');
|
|
30
|
-
}
|
|
31
17
|
entrypoints[idx] = entrypoint(declaration, handler, typeof opts === 'boolean' ? { intermediate: opts } : opts);
|
|
32
18
|
return entrypoints;
|
|
33
19
|
}
|
package/build/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAGA,OAAO,EA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ot":"","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"}
|
package/build/protocol.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { EntrypointProtocolDeclaration } from '@owlmeans/entrypoint';
|
|
2
|
-
import type { BoundEntrypointHandler, EntrypointOptions, ServerProtocolEntrypoint } from './types.js';
|
|
2
|
+
import type { BoundEntrypointHandler, EntrypointOptions, RefedEntrypointHandler, ServerProtocolEntrypoint } from './types.js';
|
|
3
|
+
type ServerBinding<Protocol extends EntrypointProtocolDeclaration> = BoundEntrypointHandler<Protocol> | RefedEntrypointHandler;
|
|
3
4
|
/** Bind one immutable protocol and, when present, its protocol-bound implementation. */
|
|
4
|
-
export declare const bind: <Protocol extends EntrypointProtocolDeclaration>(protocol: Protocol, 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 {};
|
|
5
9
|
//# sourceMappingURL=protocol.d.ts.map
|
package/build/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
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"}
|
package/build/protocol.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import { materializeEntrypoint } from '@owlmeans/entrypoint';
|
|
2
|
-
import {
|
|
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
|
+
};
|
|
3
20
|
/** Bind one immutable protocol and, when present, its protocol-bound implementation. */
|
|
4
21
|
export const bind = (protocol, implementation, options) => {
|
|
5
|
-
const
|
|
22
|
+
const handler = typeof implementation === 'function'
|
|
23
|
+
? implementation
|
|
24
|
+
: implementation?.bind;
|
|
25
|
+
const bound = Object.assign(bindMaterializedEntrypoint(materializeEntrypoint(protocol), handler, options), { protocol });
|
|
6
26
|
return bound;
|
|
7
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)));
|
|
8
30
|
//# sourceMappingURL=protocol.js.map
|
package/build/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAI5D,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAUlE,gGAAgG;AAChG,MAAM,0BAA0B,GAAG,CACjC,WAA6B,EAC7B,OAAmC,EACnC,OAA8B,E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AClD,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/server-entrypoint",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.15",
|
|
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.12",
|
|
25
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.15",
|
|
26
|
+
"@owlmeans/route": "^0.1.18-rc.13",
|
|
27
|
+
"@owlmeans/server-route": "^0.1.18-rc.13"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@owlmeans/dep-config": "workspace:*",
|
package/src/index.ts
CHANGED
package/src/protocol.ts
CHANGED
|
@@ -1,21 +1,62 @@
|
|
|
1
1
|
import { materializeEntrypoint } from '@owlmeans/entrypoint'
|
|
2
|
-
import type { EntrypointProtocolDeclaration } from '@owlmeans/entrypoint'
|
|
3
|
-
import { entrypoint } from './entrypoint.js'
|
|
4
2
|
import type {
|
|
5
|
-
|
|
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,
|
|
6
9
|
} from './types.js'
|
|
7
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
|
+
|
|
8
38
|
/** Bind one immutable protocol and, when present, its protocol-bound implementation. */
|
|
9
39
|
export const bind = <Protocol extends EntrypointProtocolDeclaration>(
|
|
10
40
|
protocol: Protocol,
|
|
11
|
-
implementation?:
|
|
41
|
+
implementation?: ServerBinding<Protocol>,
|
|
12
42
|
options?: EntrypointOptions<object>,
|
|
13
43
|
): ServerProtocolEntrypoint<Protocol> => {
|
|
14
|
-
const
|
|
44
|
+
const handler = typeof implementation === 'function'
|
|
45
|
+
? implementation
|
|
46
|
+
: implementation?.bind
|
|
47
|
+
const bound = Object.assign(bindMaterializedEntrypoint(
|
|
15
48
|
materializeEntrypoint(protocol),
|
|
16
|
-
|
|
49
|
+
handler,
|
|
17
50
|
options,
|
|
18
51
|
), { protocol })
|
|
19
52
|
|
|
20
53
|
return bound as ServerProtocolEntrypoint<Protocol>
|
|
21
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/entrypoint.ts
DELETED
|
@@ -1,45 +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 { RouteModel } from '@owlmeans/route'
|
|
7
|
-
|
|
8
|
-
export const entrypoint = <R>(
|
|
9
|
-
arg: CommonEntrypoint | ServerRouteModel<R> | RouteModel, handler?: RefedEntrypointHandler<R>, opts?: EntrypointOptions<R>
|
|
10
|
-
): ServerEntrypoint<R> => {
|
|
11
|
-
const entrypointHandle: EntrypointRef<R> = { ref: undefined }
|
|
12
|
-
|
|
13
|
-
let _entrypoint: ServerEntrypoint<R>
|
|
14
|
-
|
|
15
|
-
if (isEntrypoint(arg)) {
|
|
16
|
-
// Elevating the same alias again is legal, so an intermediate route stays intermediate unless
|
|
17
|
-
// this call says otherwise.
|
|
18
|
-
const intermediate = opts?.intermediate
|
|
19
|
-
?? (isServerRouteModel(arg.route) ? arg.route.isIntermediate() : false)
|
|
20
|
-
const routeModel = route(arg.route, intermediate, opts?.routeOptions)
|
|
21
|
-
_entrypoint = arg as ServerEntrypoint<R>
|
|
22
|
-
_entrypoint.route = routeModel
|
|
23
|
-
_entrypoint.filter = opts?.filter ?? arg.filter
|
|
24
|
-
// Elevating adds guards, it never swaps them: what the entrypoint declared still applies.
|
|
25
|
-
_entrypoint.guards = [...new Set([...(arg.guards ?? []), ...(opts?.guards ?? [])])]
|
|
26
|
-
_entrypoint.gate = opts?.gate ?? arg.gate
|
|
27
|
-
_entrypoint.gateParams = opts?.gateParams ?? arg.gateParams
|
|
28
|
-
} else if (isServerRouteModel(arg)) {
|
|
29
|
-
_entrypoint = makeCommonEntrypoint(arg, { ...opts }) as ServerEntrypoint<R>
|
|
30
|
-
_entrypoint.route = arg
|
|
31
|
-
} else {
|
|
32
|
-
const _route = route(arg, opts?.intermediate ?? false, opts?.routeOptions)
|
|
33
|
-
_entrypoint = makeCommonEntrypoint(_route, { ...opts }) as ServerEntrypoint<R>
|
|
34
|
-
_entrypoint.route = _route
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
_entrypoint.fixer = opts?.fixer ?? _entrypoint.fixer
|
|
38
|
-
if (handler != null) {
|
|
39
|
-
_entrypoint.handle = handler(entrypointHandle)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
entrypointHandle.ref = _entrypoint
|
|
43
|
-
|
|
44
|
-
return _entrypoint
|
|
45
|
-
}
|
package/src/helper.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BoundEntrypointHandler, ServerEntrypoint, EntrypointOptions, RefedEntrypointHandler,
|
|
3
|
-
ServerProtocolEntrypoint,
|
|
4
|
-
} from './types.js'
|
|
5
|
-
import { entrypoint } from './entrypoint.js'
|
|
6
|
-
import { bind } from './protocol.js'
|
|
7
|
-
import { createBasicGuard } from './utils/helper.js'
|
|
8
|
-
import { isEntrypointProtocol } from '@owlmeans/entrypoint'
|
|
9
|
-
import type { CommonEntrypoint, EntrypointProtocolDeclaration } from '@owlmeans/entrypoint'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Replace the entrypoint declared under `alias` with its elevated counterpart. Elevating is
|
|
13
|
-
* idempotent — calling it again simply replaces the element once more, and the guards it brings
|
|
14
|
-
* are added to the ones already declared.
|
|
15
|
-
*
|
|
16
|
-
* @throws {SyntaxError} when no entrypoint carries the alias
|
|
17
|
-
*/
|
|
18
|
-
export function elevate(
|
|
19
|
-
declarations: EntrypointProtocolDeclaration[],
|
|
20
|
-
implementations: readonly BoundEntrypointHandler<EntrypointProtocolDeclaration>[],
|
|
21
|
-
): ServerProtocolEntrypoint<EntrypointProtocolDeclaration>[]
|
|
22
|
-
export function elevate<R>(
|
|
23
|
-
entrypoints: (CommonEntrypoint | ServerEntrypoint<R>)[],
|
|
24
|
-
alias: string,
|
|
25
|
-
handler?: RefedEntrypointHandler<R> | boolean | EntrypointOptions<R>,
|
|
26
|
-
opts?: boolean | EntrypointOptions<R>
|
|
27
|
-
): ServerEntrypoint<R>[]
|
|
28
|
-
export function elevate(
|
|
29
|
-
entrypoints: (CommonEntrypoint | EntrypointProtocolDeclaration)[],
|
|
30
|
-
target: string | readonly BoundEntrypointHandler<EntrypointProtocolDeclaration>[],
|
|
31
|
-
handler?: RefedEntrypointHandler | boolean | EntrypointOptions<object>,
|
|
32
|
-
opts?: boolean | EntrypointOptions<object>,
|
|
33
|
-
): (ServerEntrypoint<object> | ServerProtocolEntrypoint<EntrypointProtocolDeclaration>)[] {
|
|
34
|
-
if (typeof target !== 'string') {
|
|
35
|
-
return entrypoints.map((declaration) => {
|
|
36
|
-
if (!isEntrypointProtocol(declaration)) {
|
|
37
|
-
throw new SyntaxError('Protocol elevation accepts protocol declarations only')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const implementation = target.find(bound => bound.protocol === declaration)
|
|
41
|
-
return bind(declaration, implementation)
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const idx = entrypoints.findIndex((candidate) =>
|
|
46
|
-
!isEntrypointProtocol(candidate) && candidate.route.route.alias === target)
|
|
47
|
-
if (idx === -1) {
|
|
48
|
-
throw new SyntaxError(`Entrypoint with alias ${target} not present`)
|
|
49
|
-
}
|
|
50
|
-
if (typeof handler === 'boolean') {
|
|
51
|
-
opts = handler
|
|
52
|
-
handler = undefined
|
|
53
|
-
}
|
|
54
|
-
if (typeof handler === 'object' && typeof handler !== 'function') {
|
|
55
|
-
opts = handler
|
|
56
|
-
handler = undefined
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const declaration = entrypoints[idx]
|
|
60
|
-
if (isEntrypointProtocol(declaration)) {
|
|
61
|
-
throw new SyntaxError('String elevation accepts materialized entrypoints only')
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
entrypoints[idx] = entrypoint(
|
|
65
|
-
declaration, handler, typeof opts === 'boolean' ? { intermediate: opts } : opts
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
return entrypoints as ServerEntrypoint<object>[]
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const guard = <R>(guard: string, opts?: EntrypointOptions<R>): EntrypointOptions<R> =>
|
|
72
|
-
({ ...createBasicGuard(guard, opts) })
|
package/src/utils/entrypoint.ts
DELETED
package/src/utils/helper.ts
DELETED