@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
@@ -1,250 +0,0 @@
1
- import { TSchema, Static } from '@sinclair/typebox';
2
- import { ErrorRegistry, ErrorRegistryInput } from '@spfn/core/errors';
3
- import { RouteDef, RouteInput } from '@spfn/core/route';
4
-
5
- /**
6
- * Convert File types in schema to actual File for client usage
7
- *
8
- * TypeBox File schemas become actual File objects on the client side.
9
- */
10
- type ConvertFileTypes<T> = T extends File ? File : T extends File[] ? File[] : T;
11
- /**
12
- * Extract form data input type with File support
13
- *
14
- * Maps schema types to runtime types, converting FileSchema to File.
15
- */
16
- type FormDataInput<T> = {
17
- [K in keyof T]: ConvertFileTypes<T[K]>;
18
- };
19
- /**
20
- * Extract structured input from RouteInput
21
- *
22
- * Converts TypeBox schemas to their static types for each input field.
23
- */
24
- type StructuredInput<TInput extends RouteInput> = {
25
- params: TInput['params'] extends TSchema ? Static<TInput['params']> : {};
26
- query: TInput['query'] extends TSchema ? Static<TInput['query']> : {};
27
- body: TInput['body'] extends TSchema ? Static<TInput['body']> : {};
28
- formData: TInput['formData'] extends TSchema ? FormDataInput<Static<TInput['formData']>> : {};
29
- headers: TInput['headers'] extends TSchema ? Static<TInput['headers']> : {};
30
- cookies: TInput['cookies'] extends TSchema ? Static<TInput['cookies']> : {};
31
- };
32
- /**
33
- * Infer route input type from RouteDef
34
- *
35
- * @example
36
- * ```typescript
37
- * // Server route definition
38
- * const getUser = route.get('/users/:id')
39
- * .input({ params: Type.Object({ id: Type.String() }) })
40
- * .handler(...);
41
- *
42
- * // Client: extract input type
43
- * type Input = InferRouteInput<typeof getUser>;
44
- * // { params: { id: string }, query: {}, body: {}, ... }
45
- * ```
46
- */
47
- type InferRouteInput<TRoute> = TRoute extends RouteDef<infer TInput, any, any> ? StructuredInput<TInput> : never;
48
- /**
49
- * Infer route output type from RouteDef
50
- *
51
- * @example
52
- * ```typescript
53
- * // Server route definition
54
- * const getUser = route.get('/users/:id')
55
- * .handler(async (c) => {
56
- * return { id: '1', name: 'John' };
57
- * });
58
- *
59
- * // Client: extract output type
60
- * type Output = InferRouteOutput<typeof getUser>;
61
- * // { id: string, name: string }
62
- * ```
63
- */
64
- type InferRouteOutput<TRoute> = TRoute extends RouteDef<any, any, infer TResponse> ? TResponse : never;
65
- /**
66
- * Extract routes from Router type
67
- * Router<TRoutes> has routes in `_routes` property
68
- */
69
- type ExtractRoutes<TRouter> = TRouter extends {
70
- _routes: infer TRoutes;
71
- } ? TRoutes : TRouter;
72
- /**
73
- * Extract output type for a specific route from router
74
- *
75
- * @example
76
- * ```typescript
77
- * import type { RouterOutput } from '@spfn/core/nextjs';
78
- * import type { AppRouter } from '@/server/router';
79
- *
80
- * // Get output type for a specific route
81
- * type ListData = RouterOutput<AppRouter, 'listExamples'>;
82
- *
83
- * // Use in props
84
- * interface Props {
85
- * data: RouterOutput<AppRouter, 'listExamples'>;
86
- * }
87
- *
88
- * // Extract item type from paginated response
89
- * type Example = RouterOutput<AppRouter, 'listExamples'>['items'][number];
90
- * ```
91
- */
92
- type RouterOutput<TRouter, K extends keyof ExtractRoutes<TRouter>> = InferRouteOutput<ExtractRoutes<TRouter>[K]>;
93
- /**
94
- * Extract input type for a specific route from router
95
- *
96
- * @example
97
- * ```typescript
98
- * import type { RouterInput } from '@spfn/core/nextjs';
99
- * import type { AppRouter } from '@/server/router';
100
- *
101
- * // Get input type for a specific route
102
- * type CreateInput = RouterInput<AppRouter, 'createExample'>;
103
- *
104
- * // Use in function parameter
105
- * function submitForm(data: RouterInput<AppRouter, 'createExample'>['body']) {
106
- * // ...
107
- * }
108
- * ```
109
- */
110
- type RouterInput<TRouter, K extends keyof ExtractRoutes<TRouter>> = InferRouteInput<ExtractRoutes<TRouter>[K]>;
111
- /**
112
- * Cookie options for setCookie
113
- */
114
- interface CookieOptions {
115
- httpOnly?: boolean;
116
- secure?: boolean;
117
- sameSite?: 'strict' | 'lax' | 'none';
118
- maxAge?: number;
119
- path?: string;
120
- domain?: string;
121
- }
122
- /**
123
- * Cookie to set in response
124
- */
125
- interface SetCookie {
126
- name: string;
127
- value: string;
128
- options?: CookieOptions;
129
- }
130
- /**
131
- * Request interceptor - called before fetch
132
- */
133
- type RequestInterceptor = (url: string, init: RequestInit) => Promise<RequestInit> | RequestInit;
134
- /**
135
- * Response interceptor - called after fetch
136
- */
137
- type ResponseInterceptor = (response: Response, body: any) => Promise<{
138
- response: Response;
139
- body: any;
140
- }> | {
141
- response: Response;
142
- body: any;
143
- };
144
- /**
145
- * Client configuration
146
- */
147
- interface ApiConfig {
148
- /**
149
- * Base URL for RPC endpoint
150
- *
151
- * @default '/api/rpc'
152
- * @example '/api/rpc', 'http://localhost:3000/api/rpc'
153
- */
154
- baseUrl?: string;
155
- /**
156
- * Default headers for all requests
157
- */
158
- headers?: Record<string, string>;
159
- /**
160
- * Request timeout in milliseconds
161
- *
162
- * @default env.SERVER_TIMEOUT (120000)
163
- */
164
- timeout?: number;
165
- /**
166
- * Custom fetch implementation
167
- */
168
- fetch?: typeof fetch;
169
- /**
170
- * Global request interceptor
171
- */
172
- onRequest?: RequestInterceptor;
173
- /**
174
- * Global response interceptor
175
- */
176
- onResponse?: ResponseInterceptor;
177
- /**
178
- * Custom error registry for deserialization
179
- *
180
- * Core HTTP errors are automatically registered. Use this to add your custom application errors.
181
- *
182
- * @example
183
- * ```typescript
184
- * import { errorRegistry } from '@spfn/core/errors';
185
- * import { authErrorRegistry } from '@myapp/auth/errors';
186
- * import { PaymentFailedError } from '@/server/errors';
187
- *
188
- * const api = createApi<AppRouter>({
189
- * errorRegistry: [errorRegistry, authErrorRegistry, PaymentFailedError]
190
- * });
191
- * ```
192
- */
193
- errorRegistry?: ErrorRegistry | ErrorRegistryInput[];
194
- /**
195
- * Enable debug logging
196
- *
197
- * @default false
198
- */
199
- debug?: boolean;
200
- }
201
- /**
202
- * Per-call options
203
- */
204
- interface CallOptions {
205
- /**
206
- * Request timeout in milliseconds
207
- * Overrides the global timeout set in ApiConfig
208
- */
209
- timeout?: number;
210
- /**
211
- * Additional headers for this request
212
- */
213
- headers?: Record<string, string>;
214
- /**
215
- * Override cookies for this request
216
- *
217
- * Note: Cookies are automatically forwarded by the proxy.
218
- * Use this only when you need to override them.
219
- */
220
- cookies?: Record<string, string>;
221
- /**
222
- * Request-specific interceptor
223
- */
224
- onRequest?: RequestInterceptor;
225
- /**
226
- * Response-specific interceptor
227
- */
228
- onResponse?: ResponseInterceptor;
229
- /**
230
- * Next.js-specific fetch options
231
- *
232
- * @example
233
- * // Time-based revalidation
234
- * { next: { revalidate: 60 } }
235
- *
236
- * // Disable cache
237
- * { cache: 'no-store' }
238
- *
239
- * // Tag-based revalidation
240
- * { next: { tags: ['users'] } }
241
- */
242
- fetchOptions?: RequestInit & {
243
- next?: {
244
- revalidate?: number | false;
245
- tags?: string[];
246
- };
247
- };
248
- }
249
-
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 };