@spfn/core 0.3.0-beta.2 → 0.3.0-beta.21
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 +343 -16
- package/dist/app-config/index.d.ts +134 -0
- package/dist/app-config/index.js +58 -0
- package/dist/app-config/index.js.map +1 -0
- package/dist/authz/index.js +1 -381
- package/dist/authz/index.js.map +1 -1
- package/dist/{boss-D16fO2oG.d.ts → boss-BiDCbbAQ.d.ts} +60 -7
- package/dist/codegen/index.d.ts +93 -15
- package/dist/codegen/index.js +626 -165
- package/dist/codegen/index.js.map +1 -1
- package/dist/config/index.d.ts +0 -63
- package/dist/config/index.js +15 -15
- package/dist/config/index.js.map +1 -1
- package/dist/contract/index.d.ts +40 -17
- package/dist/contract/index.js +147 -23
- package/dist/contract/index.js.map +1 -1
- package/dist/db/index.d.ts +201 -34
- package/dist/db/index.js +294 -158
- package/dist/db/index.js.map +1 -1
- package/dist/{define-middleware-DfDP39Nq.d.ts → define-middleware-CVKgqo8S.d.ts} +1 -1
- package/dist/env/index.d.ts +6 -442
- package/dist/env/index.js +13 -16
- package/dist/env/index.js.map +1 -1
- package/dist/env/loader.js +24 -1
- package/dist/env/loader.js.map +1 -1
- package/dist/error-TsUIjp_x.d.ts +157 -0
- package/dist/errors/index.js +1 -381
- package/dist/errors/index.js.map +1 -1
- package/dist/event/index.d.ts +5 -5
- package/dist/event/index.js +32 -1
- package/dist/event/index.js.map +1 -1
- package/dist/event/sse/client.d.ts +18 -4
- package/dist/event/sse/client.js +38 -2
- package/dist/event/sse/client.js.map +1 -1
- package/dist/event/sse/index.d.ts +5 -4
- package/dist/event/ws/client.d.ts +3 -2
- package/dist/event/ws/index.d.ts +4 -3
- package/dist/job/index.d.ts +48 -3
- package/dist/job/index.js +131 -52
- package/dist/job/index.js.map +1 -1
- package/dist/logger/index.js +0 -12
- package/dist/logger/index.js.map +1 -1
- package/dist/middleware/index.d.ts +6 -2
- package/dist/middleware/index.js +7 -388
- package/dist/middleware/index.js.map +1 -1
- package/dist/nextjs/index.d.ts +88 -8
- package/dist/nextjs/index.js +138 -62
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/server.d.ts +45 -7
- package/dist/nextjs/server.js +14 -0
- package/dist/nextjs/server.js.map +1 -1
- package/dist/ops/index.d.ts +62 -43
- package/dist/ops/index.js +638 -97
- package/dist/ops/index.js.map +1 -1
- package/dist/registry-C2KQCh0m.d.ts +473 -0
- package/dist/route/index.d.ts +6 -3
- package/dist/route/index.js +97 -28
- package/dist/route/index.js.map +1 -1
- package/dist/route/types.d.ts +7 -1
- package/dist/{router-Qbssr11H.d.ts → route-builder-DRW-MSCJ.d.ts} +52 -127
- package/dist/router-4YoIy5fN.d.ts +172 -0
- package/dist/{token-manager-BT5EnUAR.d.ts → router-CysBmgv3.d.ts} +81 -127
- package/dist/server/index.d.ts +185 -14
- package/dist/server/index.js +883 -78
- package/dist/server/index.js.map +1 -1
- package/dist/surface/index.d.ts +115 -0
- package/dist/surface/index.js +1003 -0
- package/dist/surface/index.js.map +1 -0
- package/dist/token-manager-Ckjt2-qq.d.ts +122 -0
- package/dist/{types-D1c57Ko-.d.ts → types-5Rl11_Nb.d.ts} +43 -4
- package/dist/{types-ZQODsBft.d.ts → types-B8zAxFsE.d.ts} +2 -1
- package/dist/types-CxhPH4s_.d.ts +375 -0
- package/dist/{types-2AbaW4Ie.d.ts → types-W4u_S0lF.d.ts} +4 -3
- package/docs/file-upload.md +195 -333
- package/package.json +20 -9
- package/src/cache/README.md +330 -0
- package/src/codegen/README.md +634 -0
- package/src/config/README.md +333 -0
- package/src/contract/README.md +440 -0
- package/src/db/README.md +589 -0
- package/src/db/manager/README.md +500 -0
- package/src/db/schema/README.md +354 -0
- package/src/db/transaction/README.md +822 -0
- package/src/env/README.md +787 -0
- package/src/errors/README.md +429 -0
- package/src/event/README.md +789 -0
- package/src/job/README.md +613 -0
- package/src/logger/README.md +321 -0
- package/src/middleware/README.md +634 -0
- package/src/nextjs/README.md +688 -0
- package/src/route/README.md +763 -0
- package/src/security/README.md +100 -0
- package/src/server/README.md +704 -0
- package/dist/types-9oszaJqp.d.ts +0 -250
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { MiddlewareHandler } from 'hono';
|
|
2
|
+
import { a as NamedMiddleware } from '../define-middleware-CVKgqo8S.js';
|
|
3
|
+
import { R as RouteDef } from '../route-builder-DRW-MSCJ.js';
|
|
4
|
+
import { R as Router } from '../router-4YoIy5fN.js';
|
|
5
|
+
import { c as SurfaceRouteBuilder, d as SurfaceCommand, b as SurfaceModule } from '../error-TsUIjp_x.js';
|
|
6
|
+
export { S as SurfaceEffect, g as SurfaceError, e as SurfaceManifest, a as SurfaceModuleCommand, f as SurfaceModuleDescriptor, h as collectSurfaceCommands, i as defineSurfaceModule } from '../error-TsUIjp_x.js';
|
|
7
|
+
import '@sinclair/typebox';
|
|
8
|
+
import 'hono/utils/http-status';
|
|
9
|
+
import '../route/types.js';
|
|
10
|
+
import '../types-5Rl11_Nb.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Command Surface
|
|
14
|
+
*
|
|
15
|
+
* A namespace of commands an app exposes to a caller that is not its own
|
|
16
|
+
* frontend — operators on `/_ops`, an issuer's signed tokens on `/_app`, any
|
|
17
|
+
* other machine caller on a namespace the app picks. An app develops the
|
|
18
|
+
* commands as ordinary routes; `defineSurface` turns them into a mountable
|
|
19
|
+
* package router that:
|
|
20
|
+
*
|
|
21
|
+
* - requires every route to carry the surface's namespace, applied by the
|
|
22
|
+
* surface's own `route`, so a command is recognizable by its path and can
|
|
23
|
+
* never shadow an app route;
|
|
24
|
+
* - injects the given auth middleware into every command, so a command
|
|
25
|
+
* reachable without authentication cannot be created by accident — there is
|
|
26
|
+
* no opt-out;
|
|
27
|
+
* - serves `GET <namespace>/_manifest`, the self-description a client
|
|
28
|
+
* discovers commands from, registered first so no command takes its URL.
|
|
29
|
+
* The manifest is the one route that may be public, and only when the
|
|
30
|
+
* surface says so: its commands stay behind auth regardless.
|
|
31
|
+
*
|
|
32
|
+
* What the path looks like after the namespace is the app's business, decided
|
|
33
|
+
* when the route is written — this factory does not audit its shape.
|
|
34
|
+
*
|
|
35
|
+
* The auth middleware lives with the app's auth stack (`@spfn/auth` ships
|
|
36
|
+
* `opsTokenAuth` and `signedTokenAuth`); core owns only the structure, so a
|
|
37
|
+
* surface has no opinion about how a credential is stored or verified.
|
|
38
|
+
* `@spfn/core/ops` is this factory fixed to `/_ops`.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { defineSurface } from '@spfn/core/surface';
|
|
43
|
+
* import { signedTokenAuth } from '@spfn/auth/server';
|
|
44
|
+
*
|
|
45
|
+
* export const app = defineSurface({
|
|
46
|
+
* namespace: '/_app',
|
|
47
|
+
* auth: signedTokenAuth({ keysUrl, iss, aud }),
|
|
48
|
+
* manifest: 'public',
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* export const pageAdd = app.route.post('/pages') // POST /_app/pages
|
|
52
|
+
* .input({ body: PageAddBody })
|
|
53
|
+
* .handler(async (c) => pagesRepository.add((await c.data()).body));
|
|
54
|
+
*
|
|
55
|
+
* // mounted like any package router, beside `/_ops`:
|
|
56
|
+
* export const appRouter = defineRouter({ ... }).packages([app.router({ pageAdd }), opsRouter]);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
type SurfaceMiddleware = NamedMiddleware<string> | MiddlewareHandler;
|
|
61
|
+
/**
|
|
62
|
+
* Build the guard for one command, or `undefined` for none. Called once per
|
|
63
|
+
* command when the router is built; the guard runs after `auth` and before the
|
|
64
|
+
* command's own middlewares.
|
|
65
|
+
*
|
|
66
|
+
* The command is the manifest entry, so its `effect` is there to read — a
|
|
67
|
+
* guard can be stricter for a `destructive` command than for a `read`.
|
|
68
|
+
*/
|
|
69
|
+
type SurfaceAuthorize = (command: SurfaceCommand) => SurfaceMiddleware | undefined;
|
|
70
|
+
interface SurfaceOptions {
|
|
71
|
+
/** Every command lives under it, e.g. `/_app`. Must be a plain absolute path. */
|
|
72
|
+
namespace: string;
|
|
73
|
+
/**
|
|
74
|
+
* The middleware that authenticates every command. Required — a surface
|
|
75
|
+
* without authentication is refused at definition time, not discovered in
|
|
76
|
+
* production.
|
|
77
|
+
*/
|
|
78
|
+
auth: NamedMiddleware<string>;
|
|
79
|
+
/** Per-command guard. Required when modules are mounted. */
|
|
80
|
+
authorize?: SurfaceAuthorize;
|
|
81
|
+
/**
|
|
82
|
+
* `'authenticated'` (default): the manifest carries `auth` like every
|
|
83
|
+
* command. `'public'`: it carries none and skips a global `auth`
|
|
84
|
+
* middleware, so a caller can discover commands before it holds a token.
|
|
85
|
+
*/
|
|
86
|
+
manifest?: 'authenticated' | 'public';
|
|
87
|
+
/** Capability modules this application explicitly chooses to expose here. */
|
|
88
|
+
modules?: readonly SurfaceModule[];
|
|
89
|
+
}
|
|
90
|
+
interface Surface {
|
|
91
|
+
/** The validated namespace, as given. */
|
|
92
|
+
readonly namespace: string;
|
|
93
|
+
/** `route` with the namespace applied. */
|
|
94
|
+
readonly route: SurfaceRouteBuilder;
|
|
95
|
+
/**
|
|
96
|
+
* Build the unmapped package router: the manifest first, then the
|
|
97
|
+
* secured commands, then the secured module commands.
|
|
98
|
+
*/
|
|
99
|
+
router<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(routes: TRoutes): Router<any>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Define a command surface on a namespace.
|
|
103
|
+
*
|
|
104
|
+
* The namespace, the auth middleware, and the `authorize` requirement are
|
|
105
|
+
* checked here; routes and modules when `router()` builds the package router.
|
|
106
|
+
* Every app command must declare its effect with
|
|
107
|
+
* `.effect('read' | 'write' | 'destructive')` — `router()` refuses one that
|
|
108
|
+
* does not, so a client is never handed a command it cannot classify.
|
|
109
|
+
* The router is an ordinary `Router` meant to be mounted with `.packages()`,
|
|
110
|
+
* so its routes stay out of the app's client types exactly like other
|
|
111
|
+
* package routes.
|
|
112
|
+
*/
|
|
113
|
+
declare function defineSurface(options: SurfaceOptions): Surface;
|
|
114
|
+
|
|
115
|
+
export { type Surface, type SurfaceAuthorize, SurfaceCommand, SurfaceModule, type SurfaceOptions, SurfaceRouteBuilder, defineSurface };
|