@spfn/core 0.3.0-beta.1 → 0.3.0-beta.11

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 (69) hide show
  1. package/README.md +301 -26
  2. package/dist/app-config/index.d.ts +96 -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/config/index.d.ts +0 -63
  9. package/dist/config/index.js +12 -12
  10. package/dist/config/index.js.map +1 -1
  11. package/dist/contract/index.d.ts +5 -4
  12. package/dist/db/index.d.ts +201 -34
  13. package/dist/db/index.js +294 -158
  14. package/dist/db/index.js.map +1 -1
  15. package/dist/{define-middleware-DfDP39Nq.d.ts → define-middleware-CVKgqo8S.d.ts} +1 -1
  16. package/dist/env/loader.js +24 -1
  17. package/dist/env/loader.js.map +1 -1
  18. package/dist/errors/index.js +1 -381
  19. package/dist/errors/index.js.map +1 -1
  20. package/dist/event/sse/client.d.ts +15 -2
  21. package/dist/event/sse/client.js +38 -2
  22. package/dist/event/sse/client.js.map +1 -1
  23. package/dist/job/index.d.ts +48 -3
  24. package/dist/job/index.js +118 -40
  25. package/dist/job/index.js.map +1 -1
  26. package/dist/logger/index.js +0 -12
  27. package/dist/logger/index.js.map +1 -1
  28. package/dist/middleware/index.d.ts +6 -2
  29. package/dist/middleware/index.js +7 -388
  30. package/dist/middleware/index.js.map +1 -1
  31. package/dist/nextjs/index.d.ts +73 -6
  32. package/dist/nextjs/index.js +40 -1
  33. package/dist/nextjs/index.js.map +1 -1
  34. package/dist/nextjs/server.d.ts +35 -2
  35. package/dist/nextjs/server.js +14 -0
  36. package/dist/nextjs/server.js.map +1 -1
  37. package/dist/ops/index.d.ts +115 -14
  38. package/dist/ops/index.js +339 -15
  39. package/dist/ops/index.js.map +1 -1
  40. package/dist/route/index.d.ts +5 -3
  41. package/dist/route/index.js +1 -1
  42. package/dist/route/index.js.map +1 -1
  43. package/dist/{router-ukNdAZcN.d.ts → route-builder-2ani2jEI.d.ts} +3 -126
  44. package/dist/router-DJdpwuB6.d.ts +127 -0
  45. package/dist/server/index.d.ts +130 -11
  46. package/dist/server/index.js +714 -70
  47. package/dist/server/index.js.map +1 -1
  48. package/dist/{types-Bvvig_tT.d.ts → types-ClQVomgV.d.ts} +1 -1
  49. package/dist/{types-9oszaJqp.d.ts → types-yv6z_mK7.d.ts} +122 -3
  50. package/docs/file-upload.md +195 -333
  51. package/package.json +14 -8
  52. package/src/cache/README.md +330 -0
  53. package/src/codegen/README.md +516 -0
  54. package/src/config/README.md +326 -0
  55. package/src/contract/README.md +326 -0
  56. package/src/db/README.md +589 -0
  57. package/src/db/manager/README.md +500 -0
  58. package/src/db/schema/README.md +354 -0
  59. package/src/db/transaction/README.md +822 -0
  60. package/src/env/README.md +651 -0
  61. package/src/errors/README.md +429 -0
  62. package/src/event/README.md +741 -0
  63. package/src/job/README.md +613 -0
  64. package/src/logger/README.md +321 -0
  65. package/src/middleware/README.md +634 -0
  66. package/src/nextjs/README.md +649 -0
  67. package/src/route/README.md +744 -0
  68. package/src/security/README.md +100 -0
  69. package/src/server/README.md +704 -0
@@ -1,4 +1,4 @@
1
- import { b as RouteAuthProfile } from './router-ukNdAZcN.js';
1
+ import { b as RouteAuthProfile } from './route-builder-2ani2jEI.js';
2
2
  import { HttpMethod } from './route/types.js';
3
3
 
4
4
  /**
@@ -62,13 +62,112 @@ type InferRouteInput<TRoute> = TRoute extends RouteDef<infer TInput, any, any> ?
62
62
  * ```
63
63
  */
64
64
  type InferRouteOutput<TRoute> = TRoute extends RouteDef<any, any, infer TResponse> ? TResponse : never;
65
+ /**
66
+ * True only for `any`.
67
+ *
68
+ * `any` satisfies both branches of a conditional type, so a router whose routes are
69
+ * unresolved (`Router<any>`) would otherwise flatten into "every name exists" and
70
+ * accept a misspelled route name. A route record that is not known contributes no
71
+ * names instead.
72
+ */
73
+ type IsAny<T> = 0 extends (1 & T) ? true : false;
74
+ /**
75
+ * True when `T` is a union of two or more members.
76
+ */
77
+ type IsUnion<T, TCopy = T> = T extends unknown ? ([TCopy] extends [T] ? false : true) : false;
78
+ /**
79
+ * One leaf of a router tree: the name a route is registered under, its definition, and
80
+ * the path it was reached by.
81
+ *
82
+ * A route is identified by its own key whatever depth it sits at — `registerRoutes`
83
+ * mounts a nested route under that key, and the contract collector reports a collision
84
+ * on it. Nesting groups the source; it does not qualify the name. The trail is carried
85
+ * so that one name reached through two branches stays two leaves.
86
+ */
87
+ interface RouteLeaf<TName extends PropertyKey, TDef, TTrail extends PropertyKey[]> {
88
+ name: TName;
89
+ def: TDef;
90
+ trail: TTrail;
91
+ }
92
+ /** Decrements the nesting budget; `PrevDepth[0]` is `never`, which ends the walk. */
93
+ type PrevDepth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
94
+ /**
95
+ * How many levels of nesting are followed.
96
+ *
97
+ * A budget rather than open recursion: a router type that refers to itself would
98
+ * otherwise never terminate, and TypeScript would report an instantiation-depth error
99
+ * in whichever component happened to read a route type. A route below the budget is not
100
+ * visible to these types; ten levels is far past any hand-written tree.
101
+ */
102
+ type MaxNesting = 10;
103
+ /**
104
+ * Collect every route in a route record as a leaf, descending into nested routers
105
+ * exactly as `registerRoutes` does.
106
+ */
107
+ type RouteLeaves<TRoutes, TTrail extends PropertyKey[] = [], TDepth extends number = MaxNesting> = [
108
+ TDepth
109
+ ] extends [never] ? never : IsAny<TRoutes> extends true ? never : {
110
+ [K in keyof TRoutes]-?: RouteLeafOf<K, Exclude<TRoutes[K], undefined>, [...TTrail, K], TDepth>;
111
+ }[keyof TRoutes];
112
+ /**
113
+ * A nested router contributes its own leaves; anything else is a leaf.
114
+ *
115
+ * `{ _routes: ... }` is the runtime's own test for a router (`isRouter`), and a
116
+ * `RouteDef` carries `handler`, `_input` and `_response` but never `_routes`, so a
117
+ * route cannot be mistaken for a router.
118
+ */
119
+ type RouteLeafOf<TName extends PropertyKey, TValue, TTrail extends PropertyKey[], TDepth extends number> = TValue extends {
120
+ _routes: infer TNested;
121
+ } ? RouteLeaves<TNested, TTrail, PrevDepth[TDepth]> : RouteLeaf<TName, TValue, TTrail>;
122
+ /** Every name the tree declares. */
123
+ type LeafNames<TLeaves> = Extract<TLeaves extends RouteLeaf<infer TName, any, any> ? TName : never, PropertyKey>;
124
+ /**
125
+ * The leaves declaring exactly this name.
126
+ *
127
+ * Exactly, not assignably: a record typed `Record<string, RouteDef>` contributes the
128
+ * name `string`, which every literal name is assignable to, and a loose sibling must
129
+ * not make each of its siblings look doubly declared.
130
+ */
131
+ type LeavesNamed<TLeaves, TName extends PropertyKey> = TLeaves extends RouteLeaf<infer TLeafName, any, any> ? [TLeafName] extends [TName] ? [TName] extends [TLeafName] ? TLeaves : never : never : never;
132
+ /** The definition a leaf carries. */
133
+ type LeafDef<TLeaves> = TLeaves extends RouteLeaf<any, infer TDef, any> ? TDef : never;
134
+ /** Where a leaf was found — one distinct trail per place the name is declared. */
135
+ type LeafTrail<TLeaves> = TLeaves extends RouteLeaf<any, any, infer TTrail> ? TTrail : never;
136
+ /**
137
+ * Flatten the leaves into one namespace of name → definition.
138
+ *
139
+ * A name that two branches both declare is left out rather than resolved to one of
140
+ * them: the tree gives it no single meaning, and picking a winner silently would hand
141
+ * a component another route's types. Naming it then fails the `K` constraint on
142
+ * `RouterOutput`/`RouterInput`, on the line that named it. Two places is counted by
143
+ * trail, so one slot holding a union of route definitions stays one route and still
144
+ * infers the union.
145
+ *
146
+ * The result is a fresh mapped type, so no key carries an optional or readonly modifier
147
+ * out of the source record — a route key that turned optional would change what
148
+ * `InferRouteInput` returns for it.
149
+ */
150
+ type FlattenLeaves<TLeaves> = {
151
+ [TName in LeafNames<TLeaves> as UnambiguousName<TLeaves, TName>]: LeafDef<LeavesNamed<TLeaves, TName>>;
152
+ };
153
+ /** The name itself when one place declares it, and nothing when two do. */
154
+ type UnambiguousName<TLeaves, TName extends PropertyKey> = IsUnion<LeafTrail<LeavesNamed<TLeaves, TName>>> extends true ? never : TName;
65
155
  /**
66
156
  * Extract routes from Router type
67
- * Router<TRoutes> has routes in `_routes` property
157
+ *
158
+ * `Router<TRoutes>` holds its routes in `_routes`, and a value in that record is either
159
+ * a route or another router. Nested routers are flattened away, so every route appears
160
+ * here under its own name at one level — the same set of names the server registers.
161
+ *
162
+ * Exported so that the typed client (`Client`, in `./builder`) names a route the same
163
+ * way `RouterOutput` and `RouterInput` do; the two must not diverge, or a route would
164
+ * type in one place and not the other. It stays internal to the package: the
165
+ * `@spfn/core/nextjs` entry point exports a fixed list of type names, and this is not
166
+ * one of them.
68
167
  */
69
168
  type ExtractRoutes<TRouter> = TRouter extends {
70
169
  _routes: infer TRoutes;
71
- } ? TRoutes : TRouter;
170
+ } ? FlattenLeaves<RouteLeaves<TRoutes>> : FlattenLeaves<RouteLeaves<TRouter>>;
72
171
  /**
73
172
  * Extract output type for a specific route from router
74
173
  *
@@ -88,6 +187,23 @@ type ExtractRoutes<TRouter> = TRouter extends {
88
187
  * // Extract item type from paginated response
89
188
  * type Example = RouterOutput<AppRouter, 'listExamples'>['items'][number];
90
189
  * ```
190
+ *
191
+ * A route declared inside a nested router is named the same way. The server registers
192
+ * a nested route under its own key, so `K` is the flat set of route names in the tree
193
+ * and the depth the route was declared at never appears here:
194
+ *
195
+ * ```typescript
196
+ * const appRouter = defineRouter({
197
+ * getRoot,
198
+ * examples: defineRouter({ listExamples, createExample }),
199
+ * });
200
+ *
201
+ * type ListData = RouterOutput<typeof appRouter, 'listExamples'>;
202
+ * ```
203
+ *
204
+ * Two branches declaring the same name make that name ambiguous, and it is left out of
205
+ * `K` rather than resolved to one of them — naming it is a compile error here instead
206
+ * of the wrong route's types reaching a component.
91
207
  */
92
208
  type RouterOutput<TRouter, K extends keyof ExtractRoutes<TRouter>> = InferRouteOutput<ExtractRoutes<TRouter>[K]>;
93
209
  /**
@@ -106,6 +222,9 @@ type RouterOutput<TRouter, K extends keyof ExtractRoutes<TRouter>> = InferRouteO
106
222
  * // ...
107
223
  * }
108
224
  * ```
225
+ *
226
+ * `K` is the flat set of route names, so a route declared inside a nested router is
227
+ * named by its own key here too — see {@link RouterOutput}.
109
228
  */
110
229
  type RouterInput<TRouter, K extends keyof ExtractRoutes<TRouter>> = InferRouteInput<ExtractRoutes<TRouter>[K]>;
111
230
  /**
@@ -247,4 +366,4 @@ interface CallOptions {
247
366
  };
248
367
  }
249
368
 
250
- export type { ApiConfig as A, CallOptions as C, InferRouteInput as I, RequestInterceptor as R, SetCookie as S, ResponseInterceptor as a, InferRouteOutput as b, CookieOptions as c, RouterInput as d, RouterOutput as e, StructuredInput as f };
369
+ export type { ApiConfig as A, CallOptions as C, ExtractRoutes as E, InferRouteInput as I, RequestInterceptor as R, SetCookie as S, ResponseInterceptor as a, InferRouteOutput as b, CookieOptions as c, RouterInput as d, RouterOutput as e, StructuredInput as f };