@owlmeans/server-entrypoint 0.1.18-rc.8 → 0.1.18-rc.9
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 +6 -5
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-entrypoint/SKILL.md +26 -6
- package/build/entrypoint.d.ts +2 -2
- package/build/entrypoint.d.ts.map +1 -1
- package/build/entrypoint.js +8 -10
- package/build/entrypoint.js.map +1 -1
- package/build/helper.d.ts +7 -0
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +7 -5
- package/build/helper.js.map +1 -1
- package/build/types.d.ts +0 -4
- package/build/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/entrypoint.ts +10 -16
- package/src/helper.ts +7 -5
- package/src/types.ts +0 -4
package/README.md
CHANGED
|
@@ -23,16 +23,16 @@ Typical pattern — define entrypoints separately, elevate with handlers:
|
|
|
23
23
|
import { elevate, guard } from '@owlmeans/server-app'
|
|
24
24
|
import { handleBody, handleParams } from '@owlmeans/server-app'
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const appEntrypoints = [
|
|
27
27
|
entrypoint(route('project-create', '/projects', backend(RouteMethod.POST)), guard('auth')),
|
|
28
28
|
entrypoint(route('project-get', '/projects/:id', backend())),
|
|
29
29
|
]
|
|
30
30
|
|
|
31
|
-
elevate(
|
|
31
|
+
elevate(appEntrypoints, 'project-create', handleBody(async (payload, ctx) => {
|
|
32
32
|
return await ctx.project().create(payload)
|
|
33
33
|
}))
|
|
34
34
|
|
|
35
|
-
elevate(
|
|
35
|
+
elevate(appEntrypoints, 'project-get', handleParams(async (params, ctx) => {
|
|
36
36
|
return await ctx.project().get(params.id)
|
|
37
37
|
}))
|
|
38
38
|
```
|
|
@@ -41,7 +41,7 @@ elevate(appModules, 'project-get', handleParams(async (params, ctx) => {
|
|
|
41
41
|
|
|
42
42
|
### `elevate<R>(entrypoints, alias, handler?, opts?): ServerEntrypoint<R>[]`
|
|
43
43
|
|
|
44
|
-
|
|
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
45
|
|
|
46
46
|
### `entrypoint<R>(commonEntrypoint, handler?, opts?): ServerEntrypoint<R>`
|
|
47
47
|
|
|
@@ -54,7 +54,8 @@ Returns `EntrypointOptions` that require the named guard service to pass before
|
|
|
54
54
|
### `ServerEntrypoint<R>`
|
|
55
55
|
|
|
56
56
|
Extends `CommonEntrypoint` with:
|
|
57
|
-
- `route: ServerRouteModel<R>` —
|
|
57
|
+
- `route: ServerRouteModel<R>` — the server route declaration; `route.match(request, entrypoint.mount())`
|
|
58
|
+
answers whether a request hits it
|
|
58
59
|
- `handle: RefedEntrypointHandler<R>` — the attached handler
|
|
59
60
|
|
|
60
61
|
### `RefedEntrypointHandler<R>`
|
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.9",
|
|
5
|
+
"generatedAt": "2026-09-01T16:28:56.991Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: server-entrypoint
|
|
3
|
-
description: How to use @owlmeans/server-entrypoint — server-side
|
|
3
|
+
description: How to use @owlmeans/server-entrypoint — server-side entrypoints extending @owlmeans/entrypoint with handler attachment, intermediates and mount(). Auto-invoked when importing server-entrypoint types.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
@@ -8,16 +8,19 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/server-entrypoint
|
|
9
9
|
|
|
10
10
|
**Layer:** Server
|
|
11
|
-
**Install:** `"@owlmeans/server-entrypoint": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/server-entrypoint": "^0.1.18-rc.9"` in `dependencies`
|
|
12
12
|
|
|
13
13
|
## Key Exports
|
|
14
14
|
|
|
15
15
|
| Export | Description |
|
|
16
16
|
|--------|-------------|
|
|
17
|
-
| `ServerEntrypoint
|
|
18
|
-
| `
|
|
17
|
+
| `ServerEntrypoint<R>` | Server entrypoint interface — a `ServerRouteModel` plus a `handle` |
|
|
18
|
+
| `entrypoint(arg, handler?, opts?)` | Build a server entrypoint from a route model or an existing declaration |
|
|
19
|
+
| `elevate(entrypoints, alias, handler?, opts?)` | Attach a handler (or just guards) to a declared entrypoint |
|
|
20
|
+
| `guard(alias, opts?)` | Require a guard, returning server entrypoint options |
|
|
21
|
+
| `EntrypointOptions<R>` | Options for elevating: `handler`, `fixer`, `intermediate`, `routeOptions`, guards/gates/filter |
|
|
19
22
|
| `EntrypointRef` / `RefedEntrypointHandler` | Handler reference pattern |
|
|
20
|
-
|
|
|
23
|
+
| `FixerService` | Per-entrypoint error rendering (`handle(reply, error)`) |
|
|
21
24
|
|
|
22
25
|
## Usage
|
|
23
26
|
|
|
@@ -27,6 +30,23 @@ Most app code uses `elevate()` from `@owlmeans/server-app` (which builds on this
|
|
|
27
30
|
import type { ServerEntrypoint } from '@owlmeans/server-entrypoint'
|
|
28
31
|
```
|
|
29
32
|
|
|
33
|
+
Elevating is **idempotent** — elevating the same alias again simply replaces the element once more,
|
|
34
|
+
and an intermediate stays intermediate unless the new call says otherwise. Guards passed at
|
|
35
|
+
elevation are **unioned** with the ones the declaration already carries, so what the entrypoint
|
|
36
|
+
declared still applies.
|
|
37
|
+
|
|
38
|
+
## What a server registers
|
|
39
|
+
|
|
40
|
+
`mount()` is the address a server binds: `base` plus every ancestor's segment, then this one. The
|
|
41
|
+
declaration itself only ever states the segment it contributes, so composing the rest takes the
|
|
42
|
+
context the entrypoint is registered in — which is why route registration happens after `init()`,
|
|
43
|
+
never at declaration time.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
server.route({ url: entrypoint.mount(), method, handler })
|
|
47
|
+
entrypoint.route.match(request, entrypoint.mount()) // intermediates test the same mount
|
|
48
|
+
```
|
|
49
|
+
|
|
30
50
|
## Cross-Service URL Generation
|
|
31
51
|
|
|
32
52
|
Use `makeSecurityHelper` from `@owlmeans/config` to build URLs pointing at other services (OAuth redirect URIs, webhook callbacks, etc.):
|
|
@@ -34,7 +54,7 @@ Use `makeSecurityHelper` from `@owlmeans/config` to build URLs pointing at other
|
|
|
34
54
|
```typescript
|
|
35
55
|
import { makeSecurityHelper } from '@owlmeans/config'
|
|
36
56
|
const helper = makeSecurityHelper<Config, Context>(ctx)
|
|
37
|
-
const url = helper.makeUrl(
|
|
57
|
+
const url = helper.makeUrl(entrypoint.address(), '/callback')
|
|
38
58
|
```
|
|
39
59
|
|
|
40
60
|
## Depends On
|
package/build/entrypoint.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ServerRouteModel } from '@owlmeans/server-route';
|
|
2
2
|
import type { ServerEntrypoint, EntrypointOptions, RefedEntrypointHandler } from './types.js';
|
|
3
3
|
import type { CommonEntrypoint } from '@owlmeans/entrypoint';
|
|
4
|
-
import type {
|
|
5
|
-
export declare const entrypoint: <R>(arg: CommonEntrypoint | ServerRouteModel<R> |
|
|
4
|
+
import type { RouteModel } from '@owlmeans/route';
|
|
5
|
+
export declare const entrypoint: <R>(arg: CommonEntrypoint | ServerRouteModel<R> | RouteModel, handler?: RefedEntrypointHandler<R>, opts?: EntrypointOptions<R>) => ServerEntrypoint<R>;
|
|
6
6
|
//# sourceMappingURL=entrypoint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,eAAO,MAAM,UAAU,GAAI,CAAC,EAC1B,KAAK,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,UAAU,EAAE,UAAU,sBAAsB,CAAC,CAAC,CAAC,EAAE,OAAO,iBAAiB,CAAC,CAAC,CAAC,KACzH,gBAAgB,CAAC,CAAC,CAmCpB,CAAA"}
|
package/build/entrypoint.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { isEntrypoint, makeCommonEntrypoint } from './utils/entrypoint.js';
|
|
2
2
|
import { isServerRouteModel, route } from '@owlmeans/server-route';
|
|
3
|
-
import { prependBase } from '@owlmeans/route/utils';
|
|
4
3
|
export const entrypoint = (arg, handler, opts) => {
|
|
5
4
|
const entrypointHandle = { ref: undefined };
|
|
6
5
|
let _entrypoint;
|
|
7
6
|
if (isEntrypoint(arg)) {
|
|
8
|
-
|
|
7
|
+
// Elevating the same alias again is legal, so an intermediate route stays intermediate unless
|
|
8
|
+
// this call says otherwise.
|
|
9
|
+
const intermediate = opts?.intermediate
|
|
10
|
+
?? (isServerRouteModel(arg.route) ? arg.route.isIntermediate() : false);
|
|
11
|
+
const routeModel = route(arg.route, intermediate, opts?.routeOptions);
|
|
9
12
|
_entrypoint = arg;
|
|
10
13
|
_entrypoint.route = routeModel;
|
|
11
14
|
_entrypoint.filter = opts?.filter ?? arg.filter;
|
|
12
|
-
|
|
15
|
+
// Elevating adds guards, it never swaps them: what the entrypoint declared still applies.
|
|
16
|
+
_entrypoint.guards = [...new Set([...(arg.guards ?? []), ...(opts?.guards ?? [])])];
|
|
13
17
|
_entrypoint.gate = opts?.gate ?? arg.gate;
|
|
14
18
|
_entrypoint.gateParams = opts?.gateParams ?? arg.gateParams;
|
|
15
19
|
}
|
|
@@ -22,16 +26,10 @@ export const entrypoint = (arg, handler, opts) => {
|
|
|
22
26
|
_entrypoint = makeCommonEntrypoint(_route, { ...opts });
|
|
23
27
|
_entrypoint.route = _route;
|
|
24
28
|
}
|
|
25
|
-
_entrypoint.fixer = opts?.fixer;
|
|
29
|
+
_entrypoint.fixer = opts?.fixer ?? _entrypoint.fixer;
|
|
26
30
|
if (handler != null) {
|
|
27
31
|
_entrypoint.handle = handler(entrypointHandle);
|
|
28
32
|
}
|
|
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
33
|
entrypointHandle.ref = _entrypoint;
|
|
36
34
|
return _entrypoint;
|
|
37
35
|
};
|
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,
|
|
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,8FAA8F;QAC9F,4BAA4B;QAC5B,MAAM,YAAY,GAAG,IAAI,EAAE,YAAY;eAClC,CAAC,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;QACzE,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,CAAC,CAAA;QACrE,WAAW,GAAG,GAA0B,CAAA;QACxC,WAAW,CAAC,KAAK,GAAG,UAAU,CAAA;QAC9B,WAAW,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,GAAG,CAAC,MAAM,CAAA;QAC/C,0FAA0F;QAC1F,WAAW,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QACnF,WAAW,CAAC,IAAI,GAAG,IAAI,EAAE,IAAI,IAAI,GAAG,CAAC,IAAI,CAAA;QACzC,WAAW,CAAC,UAAU,GAAG,IAAI,EAAE,UAAU,IAAI,GAAG,CAAC,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,5 +1,12 @@
|
|
|
1
1
|
import type { ServerEntrypoint, EntrypointOptions, RefedEntrypointHandler } from './types.js';
|
|
2
2
|
import type { CommonEntrypoint } from '@owlmeans/entrypoint';
|
|
3
|
+
/**
|
|
4
|
+
* Replace the entrypoint declared under `alias` with its elevated counterpart. Elevating is
|
|
5
|
+
* idempotent — calling it again simply replaces the element once more, and the guards it brings
|
|
6
|
+
* are added to the ones already declared.
|
|
7
|
+
*
|
|
8
|
+
* @throws {SyntaxError} when no entrypoint carries the alias
|
|
9
|
+
*/
|
|
3
10
|
export declare const elevate: <R>(entrypoints: (CommonEntrypoint | ServerEntrypoint<R>)[], alias: string, handler?: RefedEntrypointHandler<R> | boolean | EntrypointOptions<R>, opts?: boolean | EntrypointOptions<R>) => ServerEntrypoint<R>[];
|
|
4
11
|
export declare const guard: <R>(guard: string, opts?: EntrypointOptions<R>) => EntrypointOptions<R>;
|
|
5
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,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;
|
|
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;AAG7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EACvB,aAAa,CAAC,gBAAgB,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,EACvD,OAAO,MAAM,EACb,UAAU,sBAAsB,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,EACpE,OAAO,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,KACpC,gBAAgB,CAAC,CAAC,CAAC,EAmBrB,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,iBAAiB,CAAC,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,CACjD,CAAA"}
|
package/build/helper.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { entrypoint } from './entrypoint.js';
|
|
2
|
-
import { isServerRouteModel } from '@owlmeans/server-route';
|
|
3
2
|
import { createBasicGuard } from './utils/helper.js';
|
|
3
|
+
/**
|
|
4
|
+
* Replace the entrypoint declared under `alias` with its elevated counterpart. Elevating is
|
|
5
|
+
* idempotent — calling it again simply replaces the element once more, and the guards it brings
|
|
6
|
+
* are added to the ones already declared.
|
|
7
|
+
*
|
|
8
|
+
* @throws {SyntaxError} when no entrypoint carries the alias
|
|
9
|
+
*/
|
|
4
10
|
export const elevate = (entrypoints, alias, handler, opts) => {
|
|
5
11
|
const idx = entrypoints.findIndex(({ route }) => route.route.alias === alias);
|
|
6
12
|
if (idx === -1) {
|
|
@@ -14,10 +20,6 @@ export const elevate = (entrypoints, alias, handler, opts) => {
|
|
|
14
20
|
opts = handler;
|
|
15
21
|
handler = undefined;
|
|
16
22
|
}
|
|
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
23
|
entrypoints[idx] = entrypoint(entrypoints[idx], handler, typeof opts === 'boolean' ? { intermediate: opts } : opts);
|
|
22
24
|
return entrypoints;
|
|
23
25
|
};
|
package/build/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAGpD;;;;;;GAMG;AACH,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;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"}
|
package/build/types.d.ts
CHANGED
|
@@ -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>;
|
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,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACxG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,MAAM,WAAW,gBAAgB,CAAC,CAAC,CAAE,SAAQ,gBAAgB;IAC3D,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,iBAAiB,CAAA;CAC1B;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,CAAE,SAAQ,uBAAuB;IACnE
|
|
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,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACxG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,MAAM,WAAW,gBAAgB,CAAC,CAAC,CAAE,SAAQ,gBAAgB;IAC3D,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,iBAAiB,CAAA;CAC1B;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,CAAE,SAAQ,uBAAuB;IACnE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,YAAY,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAA;CACrC;AAED,MAAM,WAAW,YAAa,SAAQ,OAAO;IAC3C,MAAM,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CAC5C;AAED,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,GAAG,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;CAC1B;AAED,MAAM,WAAW,sBAAsB,CAAC,CAAC,GAAG,EAAE;IAC5C,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAA;CAC3C"}
|
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.9",
|
|
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.7",
|
|
25
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.9",
|
|
26
|
+
"@owlmeans/route": "^0.1.18-rc.7",
|
|
27
|
+
"@owlmeans/server-route": "^0.1.18-rc.7"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@owlmeans/dep-config": "workspace:*",
|
package/src/entrypoint.ts
CHANGED
|
@@ -3,23 +3,26 @@ import type { ServerEntrypoint, EntrypointOptions, EntrypointRef, RefedEntrypoin
|
|
|
3
3
|
import { isEntrypoint, makeCommonEntrypoint } from './utils/entrypoint.js'
|
|
4
4
|
import { isServerRouteModel, route } from '@owlmeans/server-route'
|
|
5
5
|
import type { CommonEntrypoint } from '@owlmeans/entrypoint'
|
|
6
|
-
import type {
|
|
7
|
-
import type { BasicContext } from '@owlmeans/context'
|
|
8
|
-
import { prependBase } from '@owlmeans/route/utils'
|
|
6
|
+
import type { RouteModel } from '@owlmeans/route'
|
|
9
7
|
|
|
10
8
|
export const entrypoint = <R>(
|
|
11
|
-
arg: CommonEntrypoint | ServerRouteModel<R> |
|
|
9
|
+
arg: CommonEntrypoint | ServerRouteModel<R> | RouteModel, handler?: RefedEntrypointHandler<R>, opts?: EntrypointOptions<R>
|
|
12
10
|
): ServerEntrypoint<R> => {
|
|
13
11
|
const entrypointHandle: EntrypointRef<R> = { ref: undefined }
|
|
14
12
|
|
|
15
13
|
let _entrypoint: ServerEntrypoint<R>
|
|
16
14
|
|
|
17
15
|
if (isEntrypoint(arg)) {
|
|
18
|
-
|
|
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)
|
|
19
21
|
_entrypoint = arg as ServerEntrypoint<R>
|
|
20
22
|
_entrypoint.route = routeModel
|
|
21
23
|
_entrypoint.filter = opts?.filter ?? arg.filter
|
|
22
|
-
|
|
24
|
+
// Elevating adds guards, it never swaps them: what the entrypoint declared still applies.
|
|
25
|
+
_entrypoint.guards = [...new Set([...(arg.guards ?? []), ...(opts?.guards ?? [])])]
|
|
23
26
|
_entrypoint.gate = opts?.gate ?? arg.gate
|
|
24
27
|
_entrypoint.gateParams = opts?.gateParams ?? arg.gateParams
|
|
25
28
|
} else if (isServerRouteModel(arg)) {
|
|
@@ -31,20 +34,11 @@ export const entrypoint = <R>(
|
|
|
31
34
|
_entrypoint.route = _route
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
_entrypoint.fixer = opts?.fixer
|
|
37
|
+
_entrypoint.fixer = opts?.fixer ?? _entrypoint.fixer
|
|
35
38
|
if (handler != null) {
|
|
36
39
|
_entrypoint.handle = handler(entrypointHandle)
|
|
37
40
|
}
|
|
38
41
|
|
|
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
42
|
entrypointHandle.ref = _entrypoint
|
|
49
43
|
|
|
50
44
|
return _entrypoint
|
package/src/helper.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { ServerEntrypoint, EntrypointOptions, RefedEntrypointHandler } from './types.js'
|
|
2
2
|
import { entrypoint } from './entrypoint.js'
|
|
3
|
-
import { isServerRouteModel } from '@owlmeans/server-route'
|
|
4
3
|
import { createBasicGuard } from './utils/helper.js'
|
|
5
4
|
import type { CommonEntrypoint } from '@owlmeans/entrypoint'
|
|
6
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Replace the entrypoint declared under `alias` with its elevated counterpart. Elevating is
|
|
8
|
+
* idempotent — calling it again simply replaces the element once more, and the guards it brings
|
|
9
|
+
* are added to the ones already declared.
|
|
10
|
+
*
|
|
11
|
+
* @throws {SyntaxError} when no entrypoint carries the alias
|
|
12
|
+
*/
|
|
7
13
|
export const elevate = <R>(
|
|
8
14
|
entrypoints: (CommonEntrypoint | ServerEntrypoint<R>)[],
|
|
9
15
|
alias: string,
|
|
@@ -22,10 +28,6 @@ export const elevate = <R>(
|
|
|
22
28
|
opts = handler
|
|
23
29
|
handler = undefined
|
|
24
30
|
}
|
|
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
31
|
|
|
30
32
|
entrypoints[idx] = entrypoint(
|
|
31
33
|
entrypoints[idx], handler, typeof opts === 'boolean' ? { intermediate: opts } : opts
|
package/src/types.ts
CHANGED
|
@@ -9,10 +9,6 @@ export interface ServerEntrypoint<R> extends CommonEntrypoint {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface EntrypointOptions<R> extends CommonEntrypointOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Force entrypoint to be elevated even if it is already elevated
|
|
14
|
-
*/
|
|
15
|
-
force?: boolean
|
|
16
12
|
fixer?: string
|
|
17
13
|
intermediate?: boolean
|
|
18
14
|
routeOptions?: ServerRouteOptions<R>
|