@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.
Files changed (94) hide show
  1. package/README.md +343 -16
  2. package/dist/app-config/index.d.ts +134 -0
  3. package/dist/app-config/index.js +58 -0
  4. package/dist/app-config/index.js.map +1 -0
  5. package/dist/authz/index.js +1 -381
  6. package/dist/authz/index.js.map +1 -1
  7. package/dist/{boss-D16fO2oG.d.ts → boss-BiDCbbAQ.d.ts} +60 -7
  8. package/dist/codegen/index.d.ts +93 -15
  9. package/dist/codegen/index.js +626 -165
  10. package/dist/codegen/index.js.map +1 -1
  11. package/dist/config/index.d.ts +0 -63
  12. package/dist/config/index.js +15 -15
  13. package/dist/config/index.js.map +1 -1
  14. package/dist/contract/index.d.ts +40 -17
  15. package/dist/contract/index.js +147 -23
  16. package/dist/contract/index.js.map +1 -1
  17. package/dist/db/index.d.ts +201 -34
  18. package/dist/db/index.js +294 -158
  19. package/dist/db/index.js.map +1 -1
  20. package/dist/{define-middleware-DfDP39Nq.d.ts → define-middleware-CVKgqo8S.d.ts} +1 -1
  21. package/dist/env/index.d.ts +6 -442
  22. package/dist/env/index.js +13 -16
  23. package/dist/env/index.js.map +1 -1
  24. package/dist/env/loader.js +24 -1
  25. package/dist/env/loader.js.map +1 -1
  26. package/dist/error-TsUIjp_x.d.ts +157 -0
  27. package/dist/errors/index.js +1 -381
  28. package/dist/errors/index.js.map +1 -1
  29. package/dist/event/index.d.ts +5 -5
  30. package/dist/event/index.js +32 -1
  31. package/dist/event/index.js.map +1 -1
  32. package/dist/event/sse/client.d.ts +18 -4
  33. package/dist/event/sse/client.js +38 -2
  34. package/dist/event/sse/client.js.map +1 -1
  35. package/dist/event/sse/index.d.ts +5 -4
  36. package/dist/event/ws/client.d.ts +3 -2
  37. package/dist/event/ws/index.d.ts +4 -3
  38. package/dist/job/index.d.ts +48 -3
  39. package/dist/job/index.js +131 -52
  40. package/dist/job/index.js.map +1 -1
  41. package/dist/logger/index.js +0 -12
  42. package/dist/logger/index.js.map +1 -1
  43. package/dist/middleware/index.d.ts +6 -2
  44. package/dist/middleware/index.js +7 -388
  45. package/dist/middleware/index.js.map +1 -1
  46. package/dist/nextjs/index.d.ts +88 -8
  47. package/dist/nextjs/index.js +138 -62
  48. package/dist/nextjs/index.js.map +1 -1
  49. package/dist/nextjs/server.d.ts +45 -7
  50. package/dist/nextjs/server.js +14 -0
  51. package/dist/nextjs/server.js.map +1 -1
  52. package/dist/ops/index.d.ts +62 -43
  53. package/dist/ops/index.js +638 -97
  54. package/dist/ops/index.js.map +1 -1
  55. package/dist/registry-C2KQCh0m.d.ts +473 -0
  56. package/dist/route/index.d.ts +6 -3
  57. package/dist/route/index.js +97 -28
  58. package/dist/route/index.js.map +1 -1
  59. package/dist/route/types.d.ts +7 -1
  60. package/dist/{router-Qbssr11H.d.ts → route-builder-DRW-MSCJ.d.ts} +52 -127
  61. package/dist/router-4YoIy5fN.d.ts +172 -0
  62. package/dist/{token-manager-BT5EnUAR.d.ts → router-CysBmgv3.d.ts} +81 -127
  63. package/dist/server/index.d.ts +185 -14
  64. package/dist/server/index.js +883 -78
  65. package/dist/server/index.js.map +1 -1
  66. package/dist/surface/index.d.ts +115 -0
  67. package/dist/surface/index.js +1003 -0
  68. package/dist/surface/index.js.map +1 -0
  69. package/dist/token-manager-Ckjt2-qq.d.ts +122 -0
  70. package/dist/{types-D1c57Ko-.d.ts → types-5Rl11_Nb.d.ts} +43 -4
  71. package/dist/{types-ZQODsBft.d.ts → types-B8zAxFsE.d.ts} +2 -1
  72. package/dist/types-CxhPH4s_.d.ts +375 -0
  73. package/dist/{types-2AbaW4Ie.d.ts → types-W4u_S0lF.d.ts} +4 -3
  74. package/docs/file-upload.md +195 -333
  75. package/package.json +20 -9
  76. package/src/cache/README.md +330 -0
  77. package/src/codegen/README.md +634 -0
  78. package/src/config/README.md +333 -0
  79. package/src/contract/README.md +440 -0
  80. package/src/db/README.md +589 -0
  81. package/src/db/manager/README.md +500 -0
  82. package/src/db/schema/README.md +354 -0
  83. package/src/db/transaction/README.md +822 -0
  84. package/src/env/README.md +787 -0
  85. package/src/errors/README.md +429 -0
  86. package/src/event/README.md +789 -0
  87. package/src/job/README.md +613 -0
  88. package/src/logger/README.md +321 -0
  89. package/src/middleware/README.md +634 -0
  90. package/src/nextjs/README.md +688 -0
  91. package/src/route/README.md +763 -0
  92. package/src/security/README.md +100 -0
  93. package/src/server/README.md +704 -0
  94. 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 };