@fragno-dev/core 0.0.6 → 0.0.7
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/.turbo/turbo-build.log +41 -37
- package/.turbo/turbo-test.log +297 -0
- package/CHANGELOG.md +8 -0
- package/dist/api/api.d.ts +1 -1
- package/dist/api/api.js +1 -1
- package/dist/{api-CBDGZiLC.d.ts → api-CAPyac52.d.ts} +3 -3
- package/dist/api-CAPyac52.d.ts.map +1 -0
- package/dist/{api-DgHfYjq2.js → api-DuzjjCT4.js} +2 -2
- package/dist/{api-DgHfYjq2.js.map → api-DuzjjCT4.js.map} +1 -1
- package/dist/client/client.d.ts +2 -2
- package/dist/client/client.js +4 -4
- package/dist/client/client.svelte.d.ts +14 -14
- package/dist/client/client.svelte.d.ts.map +1 -1
- package/dist/client/client.svelte.js +4 -4
- package/dist/client/react.d.ts +12 -12
- package/dist/client/react.d.ts.map +1 -1
- package/dist/client/react.js +6 -8
- package/dist/client/react.js.map +1 -1
- package/dist/client/solid.d.ts +45 -0
- package/dist/client/solid.d.ts.map +1 -0
- package/dist/client/solid.js +110 -0
- package/dist/client/solid.js.map +1 -0
- package/dist/client/vanilla.d.ts +21 -21
- package/dist/client/vanilla.d.ts.map +1 -1
- package/dist/client/vanilla.js +4 -4
- package/dist/client/vue.d.ts +14 -14
- package/dist/client/vue.d.ts.map +1 -1
- package/dist/client/vue.js +4 -4
- package/dist/{client-DWjxKDnE.js → client-C_Oc8hpD.js} +7 -10
- package/dist/{client-DWjxKDnE.js.map → client-C_Oc8hpD.js.map} +1 -1
- package/dist/{client-B6s-lTFe.d.ts → client-DdpPMlXL.d.ts} +73 -50
- package/dist/client-DdpPMlXL.d.ts.map +1 -0
- package/dist/integrations/react-ssr.js +1 -1
- package/dist/mod.d.ts +2 -2
- package/dist/mod.js +16 -6
- package/dist/mod.js.map +1 -1
- package/dist/{route-Bp6eByhz.js → route-Dq62lXqB.js} +6 -6
- package/dist/route-Dq62lXqB.js.map +1 -0
- package/dist/{ssr-tJHqcNSw.js → ssr-BAhbA_3q.js} +2 -2
- package/dist/{ssr-tJHqcNSw.js.map → ssr-BAhbA_3q.js.map} +1 -1
- package/package.json +22 -5
- package/src/api/fragment.ts +31 -13
- package/src/api/request-middleware.test.ts +3 -3
- package/src/api/request-output-context.ts +3 -3
- package/src/api/route.ts +1 -8
- package/src/client/client-error.test.ts +17 -1
- package/src/client/solid.test.ts +840 -0
- package/src/client/solid.ts +261 -0
- package/tsdown.config.ts +1 -0
- package/vitest.config.ts +10 -7
- package/dist/api-CBDGZiLC.d.ts.map +0 -1
- package/dist/client-B6s-lTFe.d.ts.map +0 -1
- package/dist/route-Bp6eByhz.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as OutputContext, d as RequestBodyType, l as InferOr, m as MaybeExtractPathParamsOrWiden, n as HTTPMethod, r as NonGetHTTPMethod, t as FragnoRouteConfig, u as StatusCode } from "./api-CAPyac52.js";
|
|
2
2
|
import { ReadableAtom, Store } from "nanostores";
|
|
3
3
|
import { FetcherStore, MutatorStore } from "@nanostores/query";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
@@ -10,22 +10,21 @@ interface RouteFactoryContext<TConfig, TDeps, TServices> {
|
|
|
10
10
|
deps: TDeps;
|
|
11
11
|
services: TServices;
|
|
12
12
|
}
|
|
13
|
-
type RouteFactory<TConfig, TDeps, TServices, TRoutes extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> = (context: RouteFactoryContext<TConfig, TDeps, TServices>) => TRoutes;
|
|
13
|
+
type RouteFactory<TConfig, TDeps, TServices, TRoutes$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> = (context: RouteFactoryContext<TConfig, TDeps, TServices>) => TRoutes$1;
|
|
14
14
|
type AnyRouteOrFactory = AnyFragnoRouteConfig | RouteFactory<any, any, any, any>;
|
|
15
|
-
type FlattenRouteFactories<T extends readonly AnyRouteOrFactory[]> = T extends readonly [infer First, ...infer Rest extends readonly AnyRouteOrFactory[]] ? First extends RouteFactory<any, any, any, infer TRoutes> ? [...TRoutes, ...FlattenRouteFactories<Rest>] : [First, ...FlattenRouteFactories<Rest>] : [];
|
|
16
|
-
declare function defineRoute<const TMethod extends HTTPMethod, const TPath extends string, const TOutputSchema extends StandardSchemaV1 | undefined, const TErrorCode extends string = string, const TQueryParameters extends string = string>(config: FragnoRouteConfig<TMethod, TPath, undefined, TOutputSchema, TErrorCode, TQueryParameters> & {
|
|
15
|
+
type FlattenRouteFactories<T$1 extends readonly AnyRouteOrFactory[]> = T$1 extends readonly [infer First, ...infer Rest extends readonly AnyRouteOrFactory[]] ? First extends RouteFactory<any, any, any, infer TRoutes> ? [...TRoutes, ...FlattenRouteFactories<Rest>] : [First, ...FlattenRouteFactories<Rest>] : [];
|
|
16
|
+
declare function defineRoute<const TMethod$1 extends HTTPMethod, const TPath$1 extends string, const TOutputSchema extends StandardSchemaV1 | undefined, const TErrorCode extends string = string, const TQueryParameters extends string = string>(config: FragnoRouteConfig<TMethod$1, TPath$1, undefined, TOutputSchema, TErrorCode, TQueryParameters> & {
|
|
17
17
|
inputSchema?: undefined;
|
|
18
|
-
}): FragnoRouteConfig<TMethod, TPath, undefined, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
19
|
-
declare function defineRoute<const TMethod extends HTTPMethod, const TPath extends string, const TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1 | undefined, const TErrorCode extends string = string, const TQueryParameters extends string = string>(config: FragnoRouteConfig<TMethod, TPath, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters> & {
|
|
18
|
+
}): FragnoRouteConfig<TMethod$1, TPath$1, undefined, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
19
|
+
declare function defineRoute<const TMethod$1 extends HTTPMethod, const TPath$1 extends string, const TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1 | undefined, const TErrorCode extends string = string, const TQueryParameters extends string = string>(config: FragnoRouteConfig<TMethod$1, TPath$1, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters> & {
|
|
20
20
|
inputSchema: TInputSchema;
|
|
21
|
-
}): FragnoRouteConfig<TMethod, TPath, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
22
|
-
|
|
23
|
-
declare function defineRoutes<TConfig = EmptyObject, TDeps = EmptyObject, TServices = EmptyObject>(): {
|
|
21
|
+
}): FragnoRouteConfig<TMethod$1, TPath$1, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
22
|
+
declare function defineRoutes<TConfig = {}, TDeps = {}, TServices = {}>(): {
|
|
24
23
|
create: <const TRoutes extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]>(fn: (context: RouteFactoryContext<TConfig, TDeps, TServices>) => TRoutes) => RouteFactory<TConfig, TDeps, TServices, TRoutes>;
|
|
25
24
|
};
|
|
26
25
|
//#endregion
|
|
27
26
|
//#region src/api/request-middleware.d.ts
|
|
28
|
-
type FragnoMiddlewareCallback<TRoutes extends readonly AnyFragnoRouteConfig[], TDeps, TServices extends Record<string, unknown>> = (inputContext: RequestMiddlewareInputContext<TRoutes>, outputContext: RequestMiddlewareOutputContext<TDeps, TServices>) => Promise<Response | undefined> | Response | undefined;
|
|
27
|
+
type FragnoMiddlewareCallback<TRoutes$1 extends readonly AnyFragnoRouteConfig[], TDeps, TServices extends Record<string, unknown>> = (inputContext: RequestMiddlewareInputContext<TRoutes$1>, outputContext: RequestMiddlewareOutputContext<TDeps, TServices>) => Promise<Response | undefined> | Response | undefined;
|
|
29
28
|
interface RequestMiddlewareOptions {
|
|
30
29
|
path: string;
|
|
31
30
|
method: HTTPMethod;
|
|
@@ -40,16 +39,16 @@ declare class RequestMiddlewareOutputContext<const TDeps, const TServices extend
|
|
|
40
39
|
get deps(): TDeps;
|
|
41
40
|
get services(): TServices;
|
|
42
41
|
}
|
|
43
|
-
declare class RequestMiddlewareInputContext<const TRoutes extends readonly AnyFragnoRouteConfig[]> {
|
|
42
|
+
declare class RequestMiddlewareInputContext<const TRoutes$1 extends readonly AnyFragnoRouteConfig[]> {
|
|
44
43
|
#private;
|
|
45
|
-
constructor(routes: TRoutes, options: RequestMiddlewareOptions);
|
|
44
|
+
constructor(routes: TRoutes$1, options: RequestMiddlewareOptions);
|
|
46
45
|
get path(): string;
|
|
47
46
|
get method(): HTTPMethod;
|
|
48
47
|
get pathParams(): Record<string, string>;
|
|
49
48
|
get queryParams(): URLSearchParams;
|
|
50
49
|
get inputSchema(): StandardSchemaV1 | undefined;
|
|
51
50
|
get outputSchema(): StandardSchemaV1 | undefined;
|
|
52
|
-
ifMatchesRoute: <const TMethod extends HTTPMethod, const TPath extends ExtractRoutePath<TRoutes>, const TRoute extends ExtractRouteByPath<TRoutes, TPath, TMethod> = ExtractRouteByPath<TRoutes, TPath, TMethod>>(method: TMethod, path: TPath, handler: (...args: Parameters<TRoute["handler"]>) => Promise<Response | undefined | void> | Response | undefined | void) => Promise<Response | undefined>;
|
|
51
|
+
ifMatchesRoute: <const TMethod extends HTTPMethod, const TPath extends ExtractRoutePath<TRoutes$1>, const TRoute extends ExtractRouteByPath<TRoutes$1, TPath, TMethod> = ExtractRouteByPath<TRoutes$1, TPath, TMethod>>(method: TMethod, path: TPath, handler: (...args: Parameters<TRoute["handler"]>) => Promise<Response | undefined | void> | Response | undefined | void) => Promise<Response | undefined>;
|
|
53
52
|
}
|
|
54
53
|
//#endregion
|
|
55
54
|
//#region src/api/fragment.d.ts
|
|
@@ -71,6 +70,29 @@ type ReactRouterHandlers = {
|
|
|
71
70
|
request: Request;
|
|
72
71
|
}) => Promise<Response>;
|
|
73
72
|
};
|
|
73
|
+
type SolidStartHandlers = {
|
|
74
|
+
GET: (args: {
|
|
75
|
+
request: Request;
|
|
76
|
+
}) => Promise<Response>;
|
|
77
|
+
POST: (args: {
|
|
78
|
+
request: Request;
|
|
79
|
+
}) => Promise<Response>;
|
|
80
|
+
PUT: (args: {
|
|
81
|
+
request: Request;
|
|
82
|
+
}) => Promise<Response>;
|
|
83
|
+
DELETE: (args: {
|
|
84
|
+
request: Request;
|
|
85
|
+
}) => Promise<Response>;
|
|
86
|
+
PATCH: (args: {
|
|
87
|
+
request: Request;
|
|
88
|
+
}) => Promise<Response>;
|
|
89
|
+
HEAD: (args: {
|
|
90
|
+
request: Request;
|
|
91
|
+
}) => Promise<Response>;
|
|
92
|
+
OPTIONS: (args: {
|
|
93
|
+
request: Request;
|
|
94
|
+
}) => Promise<Response>;
|
|
95
|
+
};
|
|
74
96
|
type StandardHandlers = {
|
|
75
97
|
GET: (req: Request) => Promise<Response>;
|
|
76
98
|
POST: (req: Request) => Promise<Response>;
|
|
@@ -85,27 +107,28 @@ type HandlersByFramework = {
|
|
|
85
107
|
"react-router": ReactRouterHandlers;
|
|
86
108
|
"next-js": StandardHandlers;
|
|
87
109
|
"svelte-kit": StandardHandlers;
|
|
110
|
+
"solid-start": SolidStartHandlers;
|
|
88
111
|
};
|
|
89
112
|
type FullstackFrameworks = keyof HandlersByFramework;
|
|
90
|
-
interface FragnoInstantiatedFragment<TRoutes extends readonly AnyFragnoRouteConfig[] = [], TDeps =
|
|
91
|
-
config: FragnoFragmentSharedConfig<TRoutes>;
|
|
113
|
+
interface FragnoInstantiatedFragment<TRoutes$1 extends readonly AnyFragnoRouteConfig[] = [], TDeps = {}, TServices extends Record<string, unknown> = Record<string, unknown>> {
|
|
114
|
+
config: FragnoFragmentSharedConfig<TRoutes$1>;
|
|
92
115
|
deps: TDeps;
|
|
93
116
|
services: TServices;
|
|
94
117
|
handlersFor: <T extends FullstackFrameworks>(framework: T) => HandlersByFramework[T];
|
|
95
118
|
handler: (req: Request) => Promise<Response>;
|
|
96
119
|
mountRoute: string;
|
|
97
|
-
withMiddleware: (handler: FragnoMiddlewareCallback<TRoutes, TDeps, TServices>) => FragnoInstantiatedFragment<TRoutes, TDeps, TServices>;
|
|
120
|
+
withMiddleware: (handler: FragnoMiddlewareCallback<TRoutes$1, TDeps, TServices>) => FragnoInstantiatedFragment<TRoutes$1, TDeps, TServices>;
|
|
98
121
|
}
|
|
99
|
-
interface FragnoFragmentSharedConfig<TRoutes extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> {
|
|
122
|
+
interface FragnoFragmentSharedConfig<TRoutes$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> {
|
|
100
123
|
name: string;
|
|
101
|
-
routes: TRoutes;
|
|
124
|
+
routes: TRoutes$1;
|
|
102
125
|
}
|
|
103
|
-
interface FragmentDefinition<TConfig, TDeps =
|
|
126
|
+
interface FragmentDefinition<TConfig, TDeps = {}, TServices extends Record<string, unknown> = {}> {
|
|
104
127
|
name: string;
|
|
105
128
|
dependencies?: (config: TConfig) => TDeps;
|
|
106
129
|
services?: (config: TConfig, deps: TDeps) => TServices;
|
|
107
130
|
}
|
|
108
|
-
declare class FragmentBuilder<TConfig, TDeps =
|
|
131
|
+
declare class FragmentBuilder<TConfig, TDeps = {}, TServices extends Record<string, unknown> = {}> {
|
|
109
132
|
#private;
|
|
110
133
|
constructor(definition: FragmentDefinition<TConfig, TDeps, TServices>);
|
|
111
134
|
get definition(): FragmentDefinition<TConfig, TDeps, TServices>;
|
|
@@ -181,13 +204,13 @@ declare const STORE_SYMBOL: unique symbol;
|
|
|
181
204
|
/**
|
|
182
205
|
* Extract only GET routes from a library config's routes array
|
|
183
206
|
*/
|
|
184
|
-
type ExtractGetRoutes<T extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> = { [K in keyof T]: T[K] extends FragnoRouteConfig<infer Method, infer Path, infer Input, infer Output, infer ErrorCode, infer QueryParams> ? Method extends "GET" ? FragnoRouteConfig<Method, Path, Input, Output, ErrorCode, QueryParams> : never : never }[number][];
|
|
207
|
+
type ExtractGetRoutes<T$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> = { [K in keyof T$1]: T$1[K] extends FragnoRouteConfig<infer Method, infer Path, infer Input, infer Output, infer ErrorCode, infer QueryParams> ? Method extends "GET" ? FragnoRouteConfig<Method, Path, Input, Output, ErrorCode, QueryParams> : never : never }[number][];
|
|
185
208
|
/**
|
|
186
209
|
* Extract the path from a route configuration for a given method
|
|
187
210
|
*/
|
|
188
|
-
type ExtractRoutePath<T extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[], TExpectedMethod extends HTTPMethod = HTTPMethod> = { [K in keyof T]: T[K] extends FragnoRouteConfig<infer Method, infer Path, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string> ? Method extends TExpectedMethod ? Path : never : never }[number];
|
|
189
|
-
type ExtractGetRoutePaths<T extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> = ExtractRoutePath<T, "GET">;
|
|
190
|
-
type ExtractNonGetRoutePaths<T extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> = ExtractRoutePath<T, NonGetHTTPMethod>;
|
|
211
|
+
type ExtractRoutePath<T$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[], TExpectedMethod extends HTTPMethod = HTTPMethod> = { [K in keyof T$1]: T$1[K] extends FragnoRouteConfig<infer Method, infer Path, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string> ? Method extends TExpectedMethod ? Path : never : never }[number];
|
|
212
|
+
type ExtractGetRoutePaths<T$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> = ExtractRoutePath<T$1, "GET">;
|
|
213
|
+
type ExtractNonGetRoutePaths<T$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> = ExtractRoutePath<T$1, NonGetHTTPMethod>;
|
|
191
214
|
/**
|
|
192
215
|
* Extract the route configuration type(s) for a given path from a routes array.
|
|
193
216
|
* Optionally narrow by HTTP method via the third type parameter.
|
|
@@ -195,52 +218,52 @@ type ExtractNonGetRoutePaths<T extends readonly FragnoRouteConfig<HTTPMethod, st
|
|
|
195
218
|
* Defaults to extracting all methods for the matching path, producing a union
|
|
196
219
|
* if multiple methods exist for the same path.
|
|
197
220
|
*/
|
|
198
|
-
type ExtractRouteByPath<TRoutes extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[], TPath extends string, TMethod extends HTTPMethod = HTTPMethod> = { [K in keyof TRoutes]: TRoutes[K] extends FragnoRouteConfig<infer M, TPath, infer Input, infer Output, infer ErrorCode, infer QueryParams> ? M extends TMethod ? FragnoRouteConfig<M, TPath, Input, Output, ErrorCode, QueryParams> : never : never }[number];
|
|
221
|
+
type ExtractRouteByPath<TRoutes$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[], TPath$1 extends string, TMethod$1 extends HTTPMethod = HTTPMethod> = { [K in keyof TRoutes$1]: TRoutes$1[K] extends FragnoRouteConfig<infer M, TPath$1, infer Input, infer Output, infer ErrorCode, infer QueryParams> ? M extends TMethod$1 ? FragnoRouteConfig<M, TPath$1, Input, Output, ErrorCode, QueryParams> : never : never }[number];
|
|
199
222
|
/**
|
|
200
223
|
* Extract the output schema type for a specific route path from a routes array
|
|
201
224
|
*/
|
|
202
|
-
type ExtractOutputSchemaForPath<TRoutes extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined>[], TPath extends string> = { [K in keyof TRoutes]: TRoutes[K] extends FragnoRouteConfig<infer Method, TPath, StandardSchemaV1 | undefined, infer Output> ? Method extends "GET" ? Output : never : never }[number];
|
|
225
|
+
type ExtractOutputSchemaForPath<TRoutes$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined>[], TPath$1 extends string> = { [K in keyof TRoutes$1]: TRoutes$1[K] extends FragnoRouteConfig<infer Method, TPath$1, StandardSchemaV1 | undefined, infer Output> ? Method extends "GET" ? Output : never : never }[number];
|
|
203
226
|
/**
|
|
204
227
|
* Check if a path exists as a GET route in the routes array
|
|
205
228
|
*/
|
|
206
|
-
type IsValidGetRoutePath<TRoutes extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[], TPath extends string> = TPath extends ExtractGetRoutePaths<TRoutes> ? true : false;
|
|
229
|
+
type IsValidGetRoutePath<TRoutes$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[], TPath$1 extends string> = TPath$1 extends ExtractGetRoutePaths<TRoutes$1> ? true : false;
|
|
207
230
|
/**
|
|
208
231
|
* Utility type to ensure only valid GET route paths can be used
|
|
209
232
|
*/
|
|
210
|
-
type ValidateGetRoutePath<TRoutes extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[], TPath extends string> = TPath extends ExtractGetRoutePaths<TRoutes> ? TPath : `Error: Path '${TPath}' is not a valid GET route. Available GET routes: ${ExtractGetRoutePaths<TRoutes>}`;
|
|
233
|
+
type ValidateGetRoutePath<TRoutes$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[], TPath$1 extends string> = TPath$1 extends ExtractGetRoutePaths<TRoutes$1> ? TPath$1 : `Error: Path '${TPath$1}' is not a valid GET route. Available GET routes: ${ExtractGetRoutePaths<TRoutes$1>}`;
|
|
211
234
|
/**
|
|
212
235
|
* Helper type to check if a routes array has any GET routes
|
|
213
236
|
*/
|
|
214
|
-
type HasGetRoutes<T extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> = ExtractGetRoutePaths<T> extends never ? false : true;
|
|
215
|
-
type ObjectContainingStoreField<T extends object> = T extends Store ? T : { [K in keyof T]: T[K] extends Store ? { [P in K]: T[P] } & Partial<Omit<T, K>> : never }[keyof T] extends never ? never : T;
|
|
216
|
-
type FragnoStoreData<T extends object> = {
|
|
217
|
-
obj: T;
|
|
237
|
+
type HasGetRoutes<T$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[]> = ExtractGetRoutePaths<T$1> extends never ? false : true;
|
|
238
|
+
type ObjectContainingStoreField<T$1 extends object> = T$1 extends Store ? T$1 : { [K in keyof T$1]: T$1[K] extends Store ? { [P in K]: T$1[P] } & Partial<Omit<T$1, K>> : never }[keyof T$1] extends never ? never : T$1;
|
|
239
|
+
type FragnoStoreData<T$1 extends object> = {
|
|
240
|
+
obj: T$1;
|
|
218
241
|
[STORE_SYMBOL]: true;
|
|
219
242
|
};
|
|
220
|
-
type FragnoClientHookData<TMethod extends HTTPMethod, TPath extends string, TOutputSchema extends StandardSchemaV1, TErrorCode extends string, TQueryParameters extends string> = {
|
|
221
|
-
route: FragnoRouteConfig<TMethod, TPath, StandardSchemaV1 | undefined, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
243
|
+
type FragnoClientHookData<TMethod$1 extends HTTPMethod, TPath$1 extends string, TOutputSchema extends StandardSchemaV1, TErrorCode extends string, TQueryParameters extends string> = {
|
|
244
|
+
route: FragnoRouteConfig<TMethod$1, TPath$1, StandardSchemaV1 | undefined, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
222
245
|
query(args?: {
|
|
223
|
-
path?: MaybeExtractPathParamsOrWiden<TPath, string>;
|
|
246
|
+
path?: MaybeExtractPathParamsOrWiden<TPath$1, string>;
|
|
224
247
|
query?: Record<TQueryParameters, string>;
|
|
225
248
|
}): Promise<StandardSchemaV1.InferOutput<TOutputSchema>>;
|
|
226
249
|
store(args?: {
|
|
227
|
-
path?: MaybeExtractPathParamsOrWiden<TPath, string | ReadableAtom<string>>;
|
|
250
|
+
path?: MaybeExtractPathParamsOrWiden<TPath$1, string | ReadableAtom<string>>;
|
|
228
251
|
query?: Record<TQueryParameters, string | ReadableAtom<string>>;
|
|
229
252
|
}): FetcherStore<StandardSchemaV1.InferOutput<TOutputSchema>, FragnoClientError<TErrorCode>>;
|
|
230
253
|
[GET_HOOK_SYMBOL]: true;
|
|
231
254
|
} & {
|
|
232
255
|
readonly _outputSchema?: TOutputSchema;
|
|
233
256
|
};
|
|
234
|
-
type FragnoClientMutatorData<TMethod extends NonGetHTTPMethod, TPath extends string, TInputSchema extends StandardSchemaV1 | undefined, TOutputSchema extends StandardSchemaV1 | undefined, TErrorCode extends string, TQueryParameters extends string> = {
|
|
235
|
-
route: FragnoRouteConfig<TMethod, TPath, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
257
|
+
type FragnoClientMutatorData<TMethod$1 extends NonGetHTTPMethod, TPath$1 extends string, TInputSchema extends StandardSchemaV1 | undefined, TOutputSchema extends StandardSchemaV1 | undefined, TErrorCode extends string, TQueryParameters extends string> = {
|
|
258
|
+
route: FragnoRouteConfig<TMethod$1, TPath$1, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
236
259
|
mutateQuery(args?: {
|
|
237
260
|
body?: InferOr<TInputSchema, undefined>;
|
|
238
|
-
path?: MaybeExtractPathParamsOrWiden<TPath, string>;
|
|
261
|
+
path?: MaybeExtractPathParamsOrWiden<TPath$1, string>;
|
|
239
262
|
query?: Record<TQueryParameters, string>;
|
|
240
263
|
}): Promise<InferOr<TOutputSchema, undefined>>;
|
|
241
264
|
mutatorStore: MutatorStore<{
|
|
242
265
|
body?: InferOr<TInputSchema, undefined>;
|
|
243
|
-
path?: MaybeExtractPathParamsOrWiden<TPath, string | ReadableAtom<string>>;
|
|
266
|
+
path?: MaybeExtractPathParamsOrWiden<TPath$1, string | ReadableAtom<string>>;
|
|
244
267
|
query?: Record<TQueryParameters, string | ReadableAtom<string>>;
|
|
245
268
|
}, InferOr<TOutputSchema, undefined>, FragnoClientError<TErrorCode>>;
|
|
246
269
|
[MUTATOR_HOOK_SYMBOL]: true;
|
|
@@ -248,10 +271,10 @@ type FragnoClientMutatorData<TMethod extends NonGetHTTPMethod, TPath extends str
|
|
|
248
271
|
readonly _inputSchema?: TInputSchema;
|
|
249
272
|
readonly _outputSchema?: TOutputSchema;
|
|
250
273
|
};
|
|
251
|
-
declare function buildUrl<TPath extends string>(config: {
|
|
274
|
+
declare function buildUrl<TPath$1 extends string>(config: {
|
|
252
275
|
baseUrl?: string;
|
|
253
276
|
mountRoute: string;
|
|
254
|
-
path: TPath;
|
|
277
|
+
path: TPath$1;
|
|
255
278
|
}, params: {
|
|
256
279
|
pathParams?: Record<string, string | ReadableAtom<string>>;
|
|
257
280
|
queryParams?: Record<string, string | ReadableAtom<string>>;
|
|
@@ -265,12 +288,12 @@ declare function buildUrl<TPath extends string>(config: {
|
|
|
265
288
|
* @param params
|
|
266
289
|
* @returns
|
|
267
290
|
*/
|
|
268
|
-
declare function getCacheKey<TMethod extends HTTPMethod, TPath extends string>(method: TMethod, path: TPath, params?: {
|
|
291
|
+
declare function getCacheKey<TMethod$1 extends HTTPMethod, TPath$1 extends string>(method: TMethod$1, path: TPath$1, params?: {
|
|
269
292
|
pathParams?: Record<string, string | ReadableAtom<string>>;
|
|
270
293
|
queryParams?: Record<string, string | ReadableAtom<string>>;
|
|
271
294
|
}): (string | ReadableAtom<string>)[];
|
|
272
|
-
declare function isGetHook<TPath extends string, TOutputSchema extends StandardSchemaV1, TErrorCode extends string, TQueryParameters extends string>(hook: unknown): hook is FragnoClientHookData<"GET", TPath, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
273
|
-
declare function isMutatorHook<TMethod extends NonGetHTTPMethod, TPath extends string, TInputSchema extends StandardSchemaV1 | undefined, TOutputSchema extends StandardSchemaV1 | undefined, TErrorCode extends string, TQueryParameters extends string>(hook: unknown): hook is FragnoClientMutatorData<TMethod, TPath, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
295
|
+
declare function isGetHook<TPath$1 extends string, TOutputSchema extends StandardSchemaV1, TErrorCode extends string, TQueryParameters extends string>(hook: unknown): hook is FragnoClientHookData<"GET", TPath$1, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
296
|
+
declare function isMutatorHook<TMethod$1 extends NonGetHTTPMethod, TPath$1 extends string, TInputSchema extends StandardSchemaV1 | undefined, TOutputSchema extends StandardSchemaV1 | undefined, TErrorCode extends string, TQueryParameters extends string>(hook: unknown): hook is FragnoClientMutatorData<TMethod$1, TPath$1, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
274
297
|
declare function isStore<TStore extends Store>(obj: unknown): obj is FragnoStoreData<TStore>;
|
|
275
298
|
type OnErrorRetryFn = (opts: {
|
|
276
299
|
error: unknown;
|
|
@@ -285,11 +308,11 @@ type CreateHookOptions = {
|
|
|
285
308
|
*/
|
|
286
309
|
onErrorRetry?: OnErrorRetryFn | null;
|
|
287
310
|
};
|
|
288
|
-
type OnInvalidateFn<TPath extends string> = (invalidate: <TInnerPath extends string>(method: HTTPMethod, path: TInnerPath, params: {
|
|
311
|
+
type OnInvalidateFn<TPath$1 extends string> = (invalidate: <TInnerPath extends string>(method: HTTPMethod, path: TInnerPath, params: {
|
|
289
312
|
pathParams?: MaybeExtractPathParamsOrWiden<TInnerPath, string>;
|
|
290
313
|
queryParams?: Record<string, string>;
|
|
291
314
|
}) => void, params: {
|
|
292
|
-
pathParams: MaybeExtractPathParamsOrWiden<TPath, string>;
|
|
315
|
+
pathParams: MaybeExtractPathParamsOrWiden<TPath$1, string>;
|
|
293
316
|
queryParams?: Record<string, string>;
|
|
294
317
|
}) => void;
|
|
295
318
|
type CacheLine = {
|
|
@@ -299,7 +322,7 @@ type CacheLine = {
|
|
|
299
322
|
created: number;
|
|
300
323
|
expires: number;
|
|
301
324
|
};
|
|
302
|
-
declare class ClientBuilder<TRoutes extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[], TFragmentConfig extends FragnoFragmentSharedConfig<TRoutes>> {
|
|
325
|
+
declare class ClientBuilder<TRoutes$1 extends readonly FragnoRouteConfig<HTTPMethod, string, StandardSchemaV1 | undefined, StandardSchemaV1 | undefined, string, string>[], TFragmentConfig extends FragnoFragmentSharedConfig<TRoutes$1>> {
|
|
303
326
|
#private;
|
|
304
327
|
constructor(publicConfig: FragnoPublicClientConfig, fragmentConfig: TFragmentConfig);
|
|
305
328
|
get cacheEntries(): Readonly<Record<string, CacheLine>>;
|
|
@@ -311,5 +334,5 @@ declare class ClientBuilder<TRoutes extends readonly FragnoRouteConfig<HTTPMetho
|
|
|
311
334
|
}
|
|
312
335
|
declare function createClientBuilder<TConfig, TDeps, TServices extends Record<string, unknown>, const TRoutesOrFactories extends readonly AnyRouteOrFactory[]>(fragmentDefinition: FragmentBuilder<TConfig, TDeps, TServices>, publicConfig: FragnoPublicClientConfig, routesOrFactories: TRoutesOrFactories): ClientBuilder<FlattenRouteFactories<TRoutesOrFactories>, FragnoFragmentSharedConfig<FlattenRouteFactories<TRoutesOrFactories>>>;
|
|
313
336
|
//#endregion
|
|
314
|
-
export {
|
|
315
|
-
//# sourceMappingURL=client-
|
|
337
|
+
export { FragmentBuilder as A, RouteFactoryContext as B, FragnoClientApiError as C, FragnoClientFetchNetworkError as D, FragnoClientFetchError as E, createFragment as F, defineRoutes as H, defineFragment as I, AnyRouteOrFactory as L, FragnoInstantiatedFragment as M, FragnoPublicClientConfig as N, FragnoClientUnknownApiError as O, FragnoPublicConfig as P, FlattenRouteFactories as R, isStore as S, FragnoClientFetchAbortError as T, defineRoute as V, buildUrl as _, ExtractGetRoutes as a, isGetHook as b, ExtractRouteByPath as c, FragnoClientMutatorData as d, FragnoStoreData as f, ValidateGetRoutePath as g, ObjectContainingStoreField as h, ExtractGetRoutePaths as i, FragnoFragmentSharedConfig as j, FragnoErrorOptions as k, ExtractRoutePath as l, IsValidGetRoutePath as m, ClientBuilder as n, ExtractNonGetRoutePaths as o, HasGetRoutes as p, CreateHookOptions as r, ExtractOutputSchemaForPath as s, CacheLine as t, FragnoClientHookData as u, createClientBuilder as v, FragnoClientError as w, isMutatorHook as x, getCacheKey as y, RouteFactory as z };
|
|
338
|
+
//# sourceMappingURL=client-DdpPMlXL.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-DdpPMlXL.d.ts","names":[],"sources":["../src/api/route.ts","../src/api/request-middleware.ts","../src/api/fragment.ts","../src/client/client-error.ts","../src/client/client.ts"],"sourcesContent":[],"mappings":";;;;;;KAIY,oBAAA,GAAuB,kBAAkB;UAEpC;UACP;QACF;EAJI,QAAA,EAKA,SALA;AAEZ;AACU,KAKE,YALF,CAAA,OAAA,EAAA,KAAA,EAAA,SAAA,EAAA,kBAAA,SASiB,iBATjB,CAUN,UAVM,EAAA,MAAA,EAYN,gBAZM,GAAA,SAAA,EAaN,gBAbM,GAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAAA,CAAA,GAAA,CAAA,OAAA,EAiBI,mBAjBJ,CAiBwB,OAjBxB,EAiBiC,KAjBjC,EAiBwC,SAjBxC,CAAA,EAAA,GAiBuD,SAjBvD;AACF,KAmBI,iBAAA,GAAoB,oBAnBxB,GAmB+C,YAnB/C,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA;AACI,KAoBA,qBApBA,CAAA,YAAA,SAoByC,iBApBzC,EA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pgBN,CEogBqB,KFpgBrB,CAAA,CAAA,EEqgBR,uBFrgBQ,CEsgBT,gBFtgBS;EAAA;EEugBT,KFvgB6B,EEwgB7B,kBFxgB6B,CEwgBV,eFxgBU,CAAA,QAAA,CAAA,EEwgBiB,KFxgBjB,CAAA,CAAA,aAAA,CAAA,EEygB7B,kBFzgB6B,CEygBV,eFzgBU,CAAA,QAAA,CAAA,EEygBiB,KFzgBjB,CAAA,CAAA,cAAA,CAAA,EE0gB7B,WF1gB6B,CE0gBjB,kBF1gBiB,CE0gBE,eF1gBF,CAAA,QAAA,CAAA,EE0gB6B,KF1gB7B,CAAA,CAAA,YAAA,CAAA,CAAA,CAAA,MAAA,CAAA,EE2gB7B,WF3gB6B,CE2gBjB,kBF3gBiB,CE2gBE,eF3gBF,CAAA,QAAA,CAAA,EE2gB6B,KF3gB7B,CAAA,CAAA,iBAAA,CAAA,CAAA,CAAA,MAAA,CAAA,CAAA;;AAAD,iBEq8BhB,mBFr8BgB,CAAA,OAAA,EAAA,KAAA,EAAA,kBEw8BZ,MFx8BY,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,iCAAA,SEy8BY,iBFz8BZ,EAAA,CAAA,CAAA,kBAAA,EE28BV,eF38BU,CE28BM,OF38BN,EE28Be,KF38Bf,EE28BsB,SF38BtB,CAAA,EAAA,YAAA,EE48BhB,wBF58BgB,EAAA,iBAAA,EE68BX,kBF78BW,CAAA,EE88B7B,aF98B6B,CE+8B9B,qBF/8B8B,CE+8BR,kBF/8BQ,CAAA,EEg9B9B,0BFh9B8B,CEg9BH,qBFh9BG,CEg9BmB,kBFh9BnB,CAAA,CAAA,CAAA"}
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { FragnoRouteConfig } from "./api-
|
|
2
|
-
import {
|
|
1
|
+
import { t as FragnoRouteConfig } from "./api-CAPyac52.js";
|
|
2
|
+
import { A as FragmentBuilder, B as RouteFactoryContext, F as createFragment, H as defineRoutes, I as defineFragment, L as AnyRouteOrFactory, M as FragnoInstantiatedFragment, N as FragnoPublicClientConfig, P as FragnoPublicConfig, R as FlattenRouteFactories, V as defineRoute, j as FragnoFragmentSharedConfig, z as RouteFactory } from "./client-DdpPMlXL.js";
|
|
3
3
|
export { type AnyRouteOrFactory, type FlattenRouteFactories, FragmentBuilder, type FragnoFragmentSharedConfig, type FragnoInstantiatedFragment, type FragnoPublicClientConfig, type FragnoPublicConfig, type FragnoRouteConfig, type RouteFactory, type RouteFactoryContext, createFragment, defineFragment, defineRoute, defineRoutes };
|
package/dist/mod.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FragnoApiError } from "./api-
|
|
2
|
-
import {
|
|
1
|
+
import { n as FragnoApiError } from "./api-DuzjjCT4.js";
|
|
2
|
+
import { a as RequestOutputContext, i as OutputContext, n as defineRoutes, o as RequestInputContext, r as resolveRouteFactories, s as getMountRoute, t as defineRoute } from "./route-Dq62lXqB.js";
|
|
3
3
|
import { addRoute, createRouter, findRoute } from "rou3";
|
|
4
4
|
|
|
5
5
|
//#region src/api/request-middleware.ts
|
|
@@ -47,15 +47,13 @@ var RequestMiddlewareInputContext = class {
|
|
|
47
47
|
}
|
|
48
48
|
ifMatchesRoute = async (method, path, handler) => {
|
|
49
49
|
if (this.path !== path || this.method !== method) return;
|
|
50
|
-
|
|
50
|
+
return handler(await RequestInputContext.fromRequest({
|
|
51
51
|
request: this.#options.request,
|
|
52
52
|
method: this.#options.method,
|
|
53
53
|
path,
|
|
54
54
|
pathParams: this.pathParams,
|
|
55
55
|
inputSchema: this.#route.inputSchema
|
|
56
|
-
});
|
|
57
|
-
const outputContext = new RequestOutputContext(this.#route.outputSchema);
|
|
58
|
-
return handler(inputContext, outputContext);
|
|
56
|
+
}), new RequestOutputContext(this.#route.outputSchema));
|
|
59
57
|
};
|
|
60
58
|
};
|
|
61
59
|
|
|
@@ -116,6 +114,9 @@ function createFragment(fragmentDefinition, config, routesOrFactories, fragnoCon
|
|
|
116
114
|
},
|
|
117
115
|
handlersFor: (framework) => {
|
|
118
116
|
const handler = fragment.handler;
|
|
117
|
+
if (framework === "h3" || framework === "nuxt") throw new Error(`To get handlers for h3, use the 'fromWebHandler' utility function:
|
|
118
|
+
import { fromWebHandler } from "h3";
|
|
119
|
+
export default fromWebHandler(myFragment().handler);`);
|
|
119
120
|
return {
|
|
120
121
|
astro: { ALL: handler },
|
|
121
122
|
"react-router": {
|
|
@@ -139,6 +140,15 @@ function createFragment(fragmentDefinition, config, routesOrFactories, fragnoCon
|
|
|
139
140
|
PATCH: handler,
|
|
140
141
|
HEAD: handler,
|
|
141
142
|
OPTIONS: handler
|
|
143
|
+
},
|
|
144
|
+
"solid-start": {
|
|
145
|
+
GET: ({ request }) => handler(request),
|
|
146
|
+
POST: ({ request }) => handler(request),
|
|
147
|
+
PUT: ({ request }) => handler(request),
|
|
148
|
+
DELETE: ({ request }) => handler(request),
|
|
149
|
+
PATCH: ({ request }) => handler(request),
|
|
150
|
+
HEAD: ({ request }) => handler(request),
|
|
151
|
+
OPTIONS: ({ request }) => handler(request)
|
|
142
152
|
}
|
|
143
153
|
}[framework];
|
|
144
154
|
},
|
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","names":["#deps","#services","#options","#route","route","#definition","middlewareHandler:\n | FragnoMiddlewareCallback<FlattenRouteFactories<TRoutesOrFactories>, TDeps, TServices>\n | undefined","fragment: FragnoInstantiatedFragment<\n FlattenRouteFactories<TRoutesOrFactories>,\n TDeps,\n TServices\n >"],"sources":["../src/api/request-middleware.ts","../src/api/fragment.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { ExtractRouteByPath, ExtractRoutePath } from \"../client/client\";\nimport type { HTTPMethod } from \"./api\";\nimport type { ExtractPathParams } from \"./internal/path\";\nimport type { RequestBodyType } from \"./request-input-context\";\nimport type { AnyFragnoRouteConfig } from \"./route\";\nimport { RequestInputContext } from \"./request-input-context\";\nimport { OutputContext, RequestOutputContext } from \"./request-output-context\";\n\nexport type FragnoMiddlewareCallback<\n TRoutes extends readonly AnyFragnoRouteConfig[],\n TDeps,\n TServices extends Record<string, unknown>,\n> = (\n inputContext: RequestMiddlewareInputContext<TRoutes>,\n outputContext: RequestMiddlewareOutputContext<TDeps, TServices>,\n) => Promise<Response | undefined> | Response | undefined;\n\nexport interface RequestMiddlewareOptions {\n path: string;\n method: HTTPMethod;\n pathParams?: Record<string, string>;\n searchParams: URLSearchParams;\n body: RequestBodyType;\n request: Request;\n}\n\nexport class RequestMiddlewareOutputContext<\n const TDeps,\n const TServices extends Record<string, unknown>,\n> extends OutputContext<unknown, string> {\n readonly #deps: TDeps;\n readonly #services: TServices;\n\n constructor(deps: TDeps, services: TServices) {\n super();\n this.#deps = deps;\n this.#services = services;\n }\n\n get deps(): TDeps {\n return this.#deps;\n }\n\n get services(): TServices {\n return this.#services;\n }\n}\n\nexport class RequestMiddlewareInputContext<const TRoutes extends readonly AnyFragnoRouteConfig[]> {\n readonly #options: RequestMiddlewareOptions;\n readonly #route: TRoutes[number];\n\n constructor(routes: TRoutes, options: RequestMiddlewareOptions) {\n this.#options = options;\n\n const route = routes.find(\n (route) => route.path === options.path && route.method === options.method,\n );\n\n if (!route) {\n throw new Error(`Route not found: ${options.path} ${options.method}`);\n }\n\n this.#route = route;\n }\n\n get path(): string {\n return this.#options.path;\n }\n\n get method(): HTTPMethod {\n return this.#options.method;\n }\n\n get pathParams(): Record<string, string> {\n return this.#options.pathParams ?? {};\n }\n\n get queryParams(): URLSearchParams {\n return this.#options.searchParams;\n }\n\n get inputSchema(): StandardSchemaV1 | undefined {\n return this.#route.inputSchema;\n }\n\n get outputSchema(): StandardSchemaV1 | undefined {\n return this.#route.outputSchema;\n }\n\n // Defined as a field so that `this` reference stays in tact when destructuring\n ifMatchesRoute = async <\n const TMethod extends HTTPMethod,\n const TPath extends ExtractRoutePath<TRoutes>,\n const TRoute extends ExtractRouteByPath<TRoutes, TPath, TMethod> = ExtractRouteByPath<\n TRoutes,\n TPath,\n TMethod\n >,\n >(\n method: TMethod,\n path: TPath,\n handler: (\n ...args: Parameters<TRoute[\"handler\"]>\n ) => Promise<Response | undefined | void> | Response | undefined | void,\n ): Promise<Response | undefined> => {\n if (this.path !== path || this.method !== method) {\n return undefined;\n }\n\n // TODO(Wilco): We should support reading/modifying headers here.\n const inputContext = await RequestInputContext.fromRequest({\n request: this.#options.request,\n method: this.#options.method,\n path: path,\n pathParams: this.pathParams as ExtractPathParams<TPath>,\n inputSchema: this.#route.inputSchema,\n });\n\n const outputContext = new RequestOutputContext(this.#route.outputSchema);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (handler as any)(inputContext, outputContext);\n };\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { type FragnoRouteConfig, type HTTPMethod } from \"./api\";\nimport { FragnoApiError } from \"./error\";\nimport { getMountRoute } from \"./internal/route\";\nimport { addRoute, createRouter, findRoute } from \"rou3\";\nimport { RequestInputContext } from \"./request-input-context\";\nimport type { ExtractPathParams } from \"./internal/path\";\nimport { RequestOutputContext } from \"./request-output-context\";\nimport {\n type EmptyObject,\n type AnyFragnoRouteConfig,\n type AnyRouteOrFactory,\n type FlattenRouteFactories,\n resolveRouteFactories,\n} from \"./route\";\nimport {\n RequestMiddlewareInputContext,\n RequestMiddlewareOutputContext,\n type FragnoMiddlewareCallback,\n} from \"./request-middleware\";\n\nexport interface FragnoPublicConfig {\n mountRoute?: string;\n}\n\nexport interface FragnoPublicClientConfig {\n mountRoute?: string;\n baseUrl?: string;\n}\n\ntype AstroHandlers = {\n ALL: (req: Request) => Promise<Response>;\n};\n\ntype ReactRouterHandlers = {\n loader: (args: { request: Request }) => Promise<Response>;\n action: (args: { request: Request }) => Promise<Response>;\n};\n\ntype StandardHandlers = {\n GET: (req: Request) => Promise<Response>;\n POST: (req: Request) => Promise<Response>;\n PUT: (req: Request) => Promise<Response>;\n DELETE: (req: Request) => Promise<Response>;\n PATCH: (req: Request) => Promise<Response>;\n HEAD: (req: Request) => Promise<Response>;\n OPTIONS: (req: Request) => Promise<Response>;\n};\n\ntype HandlersByFramework = {\n astro: AstroHandlers;\n \"react-router\": ReactRouterHandlers;\n \"next-js\": StandardHandlers;\n \"svelte-kit\": StandardHandlers;\n};\n\ntype FullstackFrameworks = keyof HandlersByFramework;\n\nexport interface FragnoInstantiatedFragment<\n TRoutes extends readonly AnyFragnoRouteConfig[] = [],\n TDeps = EmptyObject,\n TServices extends Record<string, unknown> = Record<string, unknown>,\n> {\n config: FragnoFragmentSharedConfig<TRoutes>;\n deps: TDeps;\n services: TServices;\n handlersFor: <T extends FullstackFrameworks>(framework: T) => HandlersByFramework[T];\n handler: (req: Request) => Promise<Response>;\n mountRoute: string;\n withMiddleware: (\n handler: FragnoMiddlewareCallback<TRoutes, TDeps, TServices>,\n ) => FragnoInstantiatedFragment<TRoutes, TDeps, TServices>;\n}\n\nexport interface FragnoFragmentSharedConfig<\n TRoutes extends readonly FragnoRouteConfig<\n HTTPMethod,\n string,\n StandardSchemaV1 | undefined,\n StandardSchemaV1 | undefined,\n string,\n string\n >[],\n> {\n name: string;\n routes: TRoutes;\n}\n\nexport type AnyFragnoFragmentSharedConfig = FragnoFragmentSharedConfig<\n readonly AnyFragnoRouteConfig[]\n>;\n\ninterface FragmentDefinition<\n TConfig,\n TDeps = EmptyObject,\n TServices extends Record<string, unknown> = EmptyObject,\n> {\n name: string;\n dependencies?: (config: TConfig) => TDeps;\n services?: (config: TConfig, deps: TDeps) => TServices;\n}\n\nexport class FragmentBuilder<\n TConfig,\n TDeps = EmptyObject,\n TServices extends Record<string, unknown> = EmptyObject,\n> {\n #definition: FragmentDefinition<TConfig, TDeps, TServices>;\n\n constructor(definition: FragmentDefinition<TConfig, TDeps, TServices>) {\n this.#definition = definition;\n }\n\n get definition() {\n return this.#definition;\n }\n\n withDependencies<TNewDeps>(\n fn: (config: TConfig) => TNewDeps,\n ): FragmentBuilder<TConfig, TNewDeps, TServices> {\n return new FragmentBuilder<TConfig, TNewDeps, TServices>({\n ...this.#definition,\n dependencies: fn,\n } as FragmentDefinition<TConfig, TNewDeps, TServices>);\n }\n\n withServices<TNewServices extends Record<string, unknown>>(\n fn: (config: TConfig, deps: TDeps) => TNewServices,\n ): FragmentBuilder<TConfig, TDeps, TNewServices> {\n return new FragmentBuilder<TConfig, TDeps, TNewServices>({\n ...this.#definition,\n services: fn,\n } as FragmentDefinition<TConfig, TDeps, TNewServices>);\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport function defineFragment<TConfig = {}>(name: string): FragmentBuilder<TConfig> {\n return new FragmentBuilder({\n name,\n });\n}\n\nexport function createFragment<\n TConfig,\n TDeps,\n TServices extends Record<string, unknown>,\n const TRoutesOrFactories extends readonly AnyRouteOrFactory[],\n>(\n fragmentDefinition: FragmentBuilder<TConfig, TDeps, TServices>,\n config: TConfig,\n routesOrFactories: TRoutesOrFactories,\n fragnoConfig: FragnoPublicConfig = {},\n): FragnoInstantiatedFragment<FlattenRouteFactories<TRoutesOrFactories>, TDeps, TServices> {\n const definition = fragmentDefinition.definition;\n\n const dependencies = definition.dependencies ? definition.dependencies(config) : ({} as TDeps);\n const services = definition.services\n ? definition.services(config, dependencies)\n : ({} as TServices);\n\n const context = { config, deps: dependencies, services };\n const routes = resolveRouteFactories(context, routesOrFactories);\n\n const mountRoute = getMountRoute({\n name: definition.name,\n mountRoute: fragnoConfig.mountRoute,\n });\n\n const router =\n createRouter<\n FragnoRouteConfig<\n HTTPMethod,\n string,\n StandardSchemaV1 | undefined,\n StandardSchemaV1 | undefined,\n string,\n string\n >\n >();\n\n let middlewareHandler:\n | FragnoMiddlewareCallback<FlattenRouteFactories<TRoutesOrFactories>, TDeps, TServices>\n | undefined;\n\n for (const routeConfig of routes) {\n addRoute(router, routeConfig.method.toUpperCase(), routeConfig.path, routeConfig);\n }\n\n const fragment: FragnoInstantiatedFragment<\n FlattenRouteFactories<TRoutesOrFactories>,\n TDeps,\n TServices\n > = {\n mountRoute,\n config: {\n name: definition.name,\n routes,\n },\n services,\n deps: dependencies,\n withMiddleware: (handler) => {\n if (middlewareHandler) {\n throw new Error(\"Middleware already set\");\n }\n\n middlewareHandler = handler;\n\n return fragment;\n },\n handlersFor: <T extends FullstackFrameworks>(framework: T): HandlersByFramework[T] => {\n const handler = fragment.handler;\n const allHandlers = {\n astro: { ALL: handler },\n \"react-router\": {\n loader: ({ request }: { request: Request }) => handler(request),\n action: ({ request }: { request: Request }) => handler(request),\n },\n \"next-js\": {\n GET: handler,\n POST: handler,\n PUT: handler,\n DELETE: handler,\n PATCH: handler,\n HEAD: handler,\n OPTIONS: handler,\n },\n \"svelte-kit\": {\n GET: handler,\n POST: handler,\n PUT: handler,\n DELETE: handler,\n PATCH: handler,\n HEAD: handler,\n OPTIONS: handler,\n },\n } satisfies HandlersByFramework;\n\n return allHandlers[framework];\n },\n handler: async (req: Request) => {\n const url = new URL(req.url);\n const pathname = url.pathname;\n\n const matchRoute = pathname.startsWith(mountRoute) ? pathname.slice(mountRoute.length) : null;\n\n if (matchRoute === null) {\n return Response.json(\n {\n error:\n `Fragno: Route for '${definition.name}' not found. Is the fragment mounted on the right route? ` +\n `Expecting: '${mountRoute}'.`,\n code: \"ROUTE_NOT_FOUND\",\n },\n { status: 404 },\n );\n }\n\n const route = findRoute(router, req.method, matchRoute);\n\n if (!route) {\n return Response.json(\n { error: `Fragno: Route for '${definition.name}' not found`, code: \"ROUTE_NOT_FOUND\" },\n { status: 404 },\n );\n }\n\n const { handler, inputSchema, outputSchema, path } = route.data;\n\n const outputContext = new RequestOutputContext(outputSchema);\n\n if (middlewareHandler) {\n const middlewareInputContext = new RequestMiddlewareInputContext(routes, {\n method: req.method as HTTPMethod,\n path,\n pathParams: route.params,\n searchParams: new URL(req.url).searchParams,\n body: req.body,\n request: req,\n });\n\n const middlewareOutputContext = new RequestMiddlewareOutputContext(dependencies, services);\n\n try {\n const middlewareResult = await middlewareHandler(\n middlewareInputContext,\n middlewareOutputContext,\n );\n if (middlewareResult !== undefined) {\n return middlewareResult;\n }\n } catch (error) {\n console.error(\"Error in middleware\", error);\n\n if (error instanceof FragnoApiError) {\n // TODO: If a validation error occurs in middleware (when calling `await input.valid()`)\n // the processing is short-circuited and a potential `catch` block around the call\n // to `input.valid()` in the actual handler will not be executed.\n return error.toResponse();\n }\n\n return Response.json(\n { error: \"Internal server error\", code: \"INTERNAL_SERVER_ERROR\" },\n { status: 500 },\n );\n }\n }\n\n const inputContext = await RequestInputContext.fromRequest({\n request: req,\n method: req.method,\n path,\n pathParams: (route.params ?? {}) as ExtractPathParams<typeof path>,\n inputSchema,\n });\n\n try {\n const result = await handler(inputContext, outputContext);\n return result;\n } catch (error) {\n console.error(\"Error in handler\", error);\n\n if (error instanceof FragnoApiError) {\n return error.toResponse();\n }\n\n return Response.json(\n { error: \"Internal server error\", code: \"INTERNAL_SERVER_ERROR\" },\n { status: 500 },\n );\n }\n },\n };\n\n return fragment;\n}\n"],"mappings":";;;;;AA2BA,IAAa,iCAAb,cAGU,cAA+B;CACvC,CAASA;CACT,CAASC;CAET,YAAY,MAAa,UAAqB;AAC5C,SAAO;AACP,QAAKD,OAAQ;AACb,QAAKC,WAAY;;CAGnB,IAAI,OAAc;AAChB,SAAO,MAAKD;;CAGd,IAAI,WAAsB;AACxB,SAAO,MAAKC;;;AAIhB,IAAa,gCAAb,MAAkG;CAChG,CAASC;CACT,CAASC;CAET,YAAY,QAAiB,SAAmC;AAC9D,QAAKD,UAAW;EAEhB,MAAM,QAAQ,OAAO,MAClB,YAAUE,QAAM,SAAS,QAAQ,QAAQA,QAAM,WAAW,QAAQ,OACpE;AAED,MAAI,CAAC,MACH,OAAM,IAAI,MAAM,oBAAoB,QAAQ,KAAK,GAAG,QAAQ,SAAS;AAGvE,QAAKD,QAAS;;CAGhB,IAAI,OAAe;AACjB,SAAO,MAAKD,QAAS;;CAGvB,IAAI,SAAqB;AACvB,SAAO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AAM;GAE3D,MAAM,gBAAgB,IAAI,qBAAqB,aAAa;AAE5D,OAAI,mBAAmB;IACrB,MAAM,yBAAyB,IAAI,8BAA8B,QAAQ;KACvE,QAAQ,IAAI;KACZ;KACA,YAAY,MAAM;KAClB,cAAc,IAAI,IAAI,IAAI,IAAI,CAAC;KAC/B,MAAM,IAAI;KACV,SAAS;KACV,CAAC;IAEF,MAAM,0BAA0B,IAAI,+BAA+B,cAAc,SAAS;AAE1F,QAAI;KACF,MAAM,mBAAmB,MAAM,kBAC7B,wBACA,wBACD;AACD,SAAI,qBAAqB,OACvB,QAAO;aAEF,OAAO;AACd,aAAQ,MAAM,uBAAuB,MAAM;AAE3C,SAAI,iBAAiB,eAInB,QAAO,MAAM,YAAY;AAG3B,YAAO,SAAS,KACd;MAAE,OAAO;MAAyB,MAAM;MAAyB,EACjE,EAAE,QAAQ,KAAK,CAChB;;;GAIL,MAAM,eAAe,MAAM,oBAAoB,YAAY;IACzD,SAAS;IACT,QAAQ,IAAI;IACZ;IACA,YAAa,MAAM,UAAU,EAAE;IAC/B;IACD,CAAC;AAEF,OAAI;AAEF,WADe,MAAM,QAAQ,cAAc,cAAc;YAElD,OAAO;AACd,YAAQ,MAAM,oBAAoB,MAAM;AAExC,QAAI,iBAAiB,eACnB,QAAO,MAAM,YAAY;AAG3B,WAAO,SAAS,KACd;KAAE,OAAO;KAAyB,MAAM;KAAyB,EACjE,EAAE,QAAQ,KAAK,CAChB;;;EAGN;AAED,QAAO"}
|
|
1
|
+
{"version":3,"file":"mod.js","names":["#deps","#services","#options","#route","route","#definition","middlewareHandler:\n | FragnoMiddlewareCallback<FlattenRouteFactories<TRoutesOrFactories>, TDeps, TServices>\n | undefined","fragment: FragnoInstantiatedFragment<\n FlattenRouteFactories<TRoutesOrFactories>,\n TDeps,\n TServices\n >"],"sources":["../src/api/request-middleware.ts","../src/api/fragment.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { ExtractRouteByPath, ExtractRoutePath } from \"../client/client\";\nimport type { HTTPMethod } from \"./api\";\nimport type { ExtractPathParams } from \"./internal/path\";\nimport type { RequestBodyType } from \"./request-input-context\";\nimport type { AnyFragnoRouteConfig } from \"./route\";\nimport { RequestInputContext } from \"./request-input-context\";\nimport { OutputContext, RequestOutputContext } from \"./request-output-context\";\n\nexport type FragnoMiddlewareCallback<\n TRoutes extends readonly AnyFragnoRouteConfig[],\n TDeps,\n TServices extends Record<string, unknown>,\n> = (\n inputContext: RequestMiddlewareInputContext<TRoutes>,\n outputContext: RequestMiddlewareOutputContext<TDeps, TServices>,\n) => Promise<Response | undefined> | Response | undefined;\n\nexport interface RequestMiddlewareOptions {\n path: string;\n method: HTTPMethod;\n pathParams?: Record<string, string>;\n searchParams: URLSearchParams;\n body: RequestBodyType;\n request: Request;\n}\n\nexport class RequestMiddlewareOutputContext<\n const TDeps,\n const TServices extends Record<string, unknown>,\n> extends OutputContext<unknown, string> {\n readonly #deps: TDeps;\n readonly #services: TServices;\n\n constructor(deps: TDeps, services: TServices) {\n super();\n this.#deps = deps;\n this.#services = services;\n }\n\n get deps(): TDeps {\n return this.#deps;\n }\n\n get services(): TServices {\n return this.#services;\n }\n}\n\nexport class RequestMiddlewareInputContext<const TRoutes extends readonly AnyFragnoRouteConfig[]> {\n readonly #options: RequestMiddlewareOptions;\n readonly #route: TRoutes[number];\n\n constructor(routes: TRoutes, options: RequestMiddlewareOptions) {\n this.#options = options;\n\n const route = routes.find(\n (route) => route.path === options.path && route.method === options.method,\n );\n\n if (!route) {\n throw new Error(`Route not found: ${options.path} ${options.method}`);\n }\n\n this.#route = route;\n }\n\n get path(): string {\n return this.#options.path;\n }\n\n get method(): HTTPMethod {\n return this.#options.method;\n }\n\n get pathParams(): Record<string, string> {\n return this.#options.pathParams ?? {};\n }\n\n get queryParams(): URLSearchParams {\n return this.#options.searchParams;\n }\n\n get inputSchema(): StandardSchemaV1 | undefined {\n return this.#route.inputSchema;\n }\n\n get outputSchema(): StandardSchemaV1 | undefined {\n return this.#route.outputSchema;\n }\n\n // Defined as a field so that `this` reference stays in tact when destructuring\n ifMatchesRoute = async <\n const TMethod extends HTTPMethod,\n const TPath extends ExtractRoutePath<TRoutes>,\n const TRoute extends ExtractRouteByPath<TRoutes, TPath, TMethod> = ExtractRouteByPath<\n TRoutes,\n TPath,\n TMethod\n >,\n >(\n method: TMethod,\n path: TPath,\n handler: (\n ...args: Parameters<TRoute[\"handler\"]>\n ) => Promise<Response | undefined | void> | Response | undefined | void,\n ): Promise<Response | undefined> => {\n if (this.path !== path || this.method !== method) {\n return undefined;\n }\n\n // TODO(Wilco): We should support reading/modifying headers here.\n const inputContext = await RequestInputContext.fromRequest({\n request: this.#options.request,\n method: this.#options.method,\n path: path,\n pathParams: this.pathParams as ExtractPathParams<TPath>,\n inputSchema: this.#route.inputSchema,\n });\n\n const outputContext = new RequestOutputContext(this.#route.outputSchema);\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (handler as any)(inputContext, outputContext);\n };\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { type FragnoRouteConfig, type HTTPMethod } from \"./api\";\nimport { FragnoApiError } from \"./error\";\nimport { getMountRoute } from \"./internal/route\";\nimport { addRoute, createRouter, findRoute } from \"rou3\";\nimport { RequestInputContext } from \"./request-input-context\";\nimport type { ExtractPathParams } from \"./internal/path\";\nimport { RequestOutputContext } from \"./request-output-context\";\nimport {\n type AnyFragnoRouteConfig,\n type AnyRouteOrFactory,\n type FlattenRouteFactories,\n resolveRouteFactories,\n} from \"./route\";\nimport {\n RequestMiddlewareInputContext,\n RequestMiddlewareOutputContext,\n type FragnoMiddlewareCallback,\n} from \"./request-middleware\";\n\nexport interface FragnoPublicConfig {\n mountRoute?: string;\n}\n\nexport interface FragnoPublicClientConfig {\n mountRoute?: string;\n baseUrl?: string;\n}\n\ntype AstroHandlers = {\n ALL: (req: Request) => Promise<Response>;\n};\n\ntype ReactRouterHandlers = {\n loader: (args: { request: Request }) => Promise<Response>;\n action: (args: { request: Request }) => Promise<Response>;\n};\n\ntype SolidStartHandlers = {\n GET: (args: { request: Request }) => Promise<Response>;\n POST: (args: { request: Request }) => Promise<Response>;\n PUT: (args: { request: Request }) => Promise<Response>;\n DELETE: (args: { request: Request }) => Promise<Response>;\n PATCH: (args: { request: Request }) => Promise<Response>;\n HEAD: (args: { request: Request }) => Promise<Response>;\n OPTIONS: (args: { request: Request }) => Promise<Response>;\n};\n\ntype StandardHandlers = {\n GET: (req: Request) => Promise<Response>;\n POST: (req: Request) => Promise<Response>;\n PUT: (req: Request) => Promise<Response>;\n DELETE: (req: Request) => Promise<Response>;\n PATCH: (req: Request) => Promise<Response>;\n HEAD: (req: Request) => Promise<Response>;\n OPTIONS: (req: Request) => Promise<Response>;\n};\n\ntype HandlersByFramework = {\n astro: AstroHandlers;\n \"react-router\": ReactRouterHandlers;\n \"next-js\": StandardHandlers;\n \"svelte-kit\": StandardHandlers;\n \"solid-start\": SolidStartHandlers;\n};\n\ntype FullstackFrameworks = keyof HandlersByFramework;\n\nexport interface FragnoInstantiatedFragment<\n TRoutes extends readonly AnyFragnoRouteConfig[] = [],\n TDeps = {},\n TServices extends Record<string, unknown> = Record<string, unknown>,\n> {\n config: FragnoFragmentSharedConfig<TRoutes>;\n deps: TDeps;\n services: TServices;\n handlersFor: <T extends FullstackFrameworks>(framework: T) => HandlersByFramework[T];\n handler: (req: Request) => Promise<Response>;\n mountRoute: string;\n withMiddleware: (\n handler: FragnoMiddlewareCallback<TRoutes, TDeps, TServices>,\n ) => FragnoInstantiatedFragment<TRoutes, TDeps, TServices>;\n}\n\nexport interface FragnoFragmentSharedConfig<\n TRoutes extends readonly FragnoRouteConfig<\n HTTPMethod,\n string,\n StandardSchemaV1 | undefined,\n StandardSchemaV1 | undefined,\n string,\n string\n >[],\n> {\n name: string;\n routes: TRoutes;\n}\n\nexport type AnyFragnoFragmentSharedConfig = FragnoFragmentSharedConfig<\n readonly AnyFragnoRouteConfig[]\n>;\n\ninterface FragmentDefinition<TConfig, TDeps = {}, TServices extends Record<string, unknown> = {}> {\n name: string;\n dependencies?: (config: TConfig) => TDeps;\n services?: (config: TConfig, deps: TDeps) => TServices;\n}\n\nexport class FragmentBuilder<TConfig, TDeps = {}, TServices extends Record<string, unknown> = {}> {\n #definition: FragmentDefinition<TConfig, TDeps, TServices>;\n\n constructor(definition: FragmentDefinition<TConfig, TDeps, TServices>) {\n this.#definition = definition;\n }\n\n get definition() {\n return this.#definition;\n }\n\n withDependencies<TNewDeps>(\n fn: (config: TConfig) => TNewDeps,\n ): FragmentBuilder<TConfig, TNewDeps, TServices> {\n return new FragmentBuilder<TConfig, TNewDeps, TServices>({\n ...this.#definition,\n dependencies: fn,\n } as FragmentDefinition<TConfig, TNewDeps, TServices>);\n }\n\n withServices<TNewServices extends Record<string, unknown>>(\n fn: (config: TConfig, deps: TDeps) => TNewServices,\n ): FragmentBuilder<TConfig, TDeps, TNewServices> {\n return new FragmentBuilder<TConfig, TDeps, TNewServices>({\n ...this.#definition,\n services: fn,\n } as FragmentDefinition<TConfig, TDeps, TNewServices>);\n }\n}\n\nexport function defineFragment<TConfig = {}>(name: string): FragmentBuilder<TConfig> {\n return new FragmentBuilder({\n name,\n });\n}\n\nexport function createFragment<\n TConfig,\n TDeps,\n TServices extends Record<string, unknown>,\n const TRoutesOrFactories extends readonly AnyRouteOrFactory[],\n>(\n fragmentDefinition: FragmentBuilder<TConfig, TDeps, TServices>,\n config: TConfig,\n routesOrFactories: TRoutesOrFactories,\n fragnoConfig: FragnoPublicConfig = {},\n): FragnoInstantiatedFragment<FlattenRouteFactories<TRoutesOrFactories>, TDeps, TServices> {\n const definition = fragmentDefinition.definition;\n\n const dependencies = definition.dependencies ? definition.dependencies(config) : ({} as TDeps);\n const services = definition.services\n ? definition.services(config, dependencies)\n : ({} as TServices);\n\n const context = { config, deps: dependencies, services };\n const routes = resolveRouteFactories(context, routesOrFactories);\n\n const mountRoute = getMountRoute({\n name: definition.name,\n mountRoute: fragnoConfig.mountRoute,\n });\n\n const router =\n createRouter<\n FragnoRouteConfig<\n HTTPMethod,\n string,\n StandardSchemaV1 | undefined,\n StandardSchemaV1 | undefined,\n string,\n string\n >\n >();\n\n let middlewareHandler:\n | FragnoMiddlewareCallback<FlattenRouteFactories<TRoutesOrFactories>, TDeps, TServices>\n | undefined;\n\n for (const routeConfig of routes) {\n addRoute(router, routeConfig.method.toUpperCase(), routeConfig.path, routeConfig);\n }\n\n const fragment: FragnoInstantiatedFragment<\n FlattenRouteFactories<TRoutesOrFactories>,\n TDeps,\n TServices\n > = {\n mountRoute,\n config: {\n name: definition.name,\n routes,\n },\n services,\n deps: dependencies,\n withMiddleware: (handler) => {\n if (middlewareHandler) {\n throw new Error(\"Middleware already set\");\n }\n\n middlewareHandler = handler;\n\n return fragment;\n },\n handlersFor: <T extends FullstackFrameworks>(framework: T): HandlersByFramework[T] => {\n const handler = fragment.handler;\n\n // LLMs hallucinate these values sometimes, solution isn't obvious so we throw this error\n // @ts-expect-error TS2367\n if (framework === \"h3\" || framework === \"nuxt\") {\n throw new Error(`To get handlers for h3, use the 'fromWebHandler' utility function:\n import { fromWebHandler } from \"h3\";\n export default fromWebHandler(myFragment().handler);`);\n }\n const allHandlers = {\n astro: { ALL: handler },\n \"react-router\": {\n loader: ({ request }: { request: Request }) => handler(request),\n action: ({ request }: { request: Request }) => handler(request),\n },\n \"next-js\": {\n GET: handler,\n POST: handler,\n PUT: handler,\n DELETE: handler,\n PATCH: handler,\n HEAD: handler,\n OPTIONS: handler,\n },\n \"svelte-kit\": {\n GET: handler,\n POST: handler,\n PUT: handler,\n DELETE: handler,\n PATCH: handler,\n HEAD: handler,\n OPTIONS: handler,\n },\n \"solid-start\": {\n GET: ({ request }: { request: Request }) => handler(request),\n POST: ({ request }: { request: Request }) => handler(request),\n PUT: ({ request }: { request: Request }) => handler(request),\n DELETE: ({ request }: { request: Request }) => handler(request),\n PATCH: ({ request }: { request: Request }) => handler(request),\n HEAD: ({ request }: { request: Request }) => handler(request),\n OPTIONS: ({ request }: { request: Request }) => handler(request),\n },\n } satisfies HandlersByFramework;\n\n return allHandlers[framework];\n },\n handler: async (req: Request) => {\n const url = new URL(req.url);\n const pathname = url.pathname;\n\n const matchRoute = pathname.startsWith(mountRoute) ? pathname.slice(mountRoute.length) : null;\n\n if (matchRoute === null) {\n return Response.json(\n {\n error:\n `Fragno: Route for '${definition.name}' not found. Is the fragment mounted on the right route? ` +\n `Expecting: '${mountRoute}'.`,\n code: \"ROUTE_NOT_FOUND\",\n },\n { status: 404 },\n );\n }\n\n const route = findRoute(router, req.method, matchRoute);\n\n if (!route) {\n return Response.json(\n { error: `Fragno: Route for '${definition.name}' not found`, code: \"ROUTE_NOT_FOUND\" },\n { status: 404 },\n );\n }\n\n const { handler, inputSchema, outputSchema, path } = route.data;\n\n const outputContext = new RequestOutputContext(outputSchema);\n\n if (middlewareHandler) {\n const middlewareInputContext = new RequestMiddlewareInputContext(routes, {\n method: req.method as HTTPMethod,\n path,\n pathParams: route.params,\n searchParams: new URL(req.url).searchParams,\n body: req.body,\n request: req,\n });\n\n const middlewareOutputContext = new RequestMiddlewareOutputContext(dependencies, services);\n\n try {\n const middlewareResult = await middlewareHandler(\n middlewareInputContext,\n middlewareOutputContext,\n );\n if (middlewareResult !== undefined) {\n return middlewareResult;\n }\n } catch (error) {\n console.error(\"Error in middleware\", error);\n\n if (error instanceof FragnoApiError) {\n // TODO: If a validation error occurs in middleware (when calling `await input.valid()`)\n // the processing is short-circuited and a potential `catch` block around the call\n // to `input.valid()` in the actual handler will not be executed.\n return error.toResponse();\n }\n\n return Response.json(\n { error: \"Internal server error\", code: \"INTERNAL_SERVER_ERROR\" },\n { status: 500 },\n );\n }\n }\n\n const inputContext = await RequestInputContext.fromRequest({\n request: req,\n method: req.method,\n path,\n pathParams: (route.params ?? {}) as ExtractPathParams<typeof path>,\n inputSchema,\n });\n\n try {\n const result = await handler(inputContext, outputContext);\n return result;\n } catch (error) {\n console.error(\"Error in handler\", error);\n\n if (error instanceof FragnoApiError) {\n return error.toResponse();\n }\n\n return Response.json(\n { error: \"Internal server error\", code: \"INTERNAL_SERVER_ERROR\" },\n { status: 500 },\n );\n }\n },\n };\n\n return fragment;\n}\n"],"mappings":";;;;;AA2BA,IAAa,iCAAb,cAGU,cAA+B;CACvC,CAASA;CACT,CAASC;CAET,YAAY,MAAa,UAAqB;AAC5C,SAAO;AACP,QAAKD,OAAQ;AACb,QAAKC,WAAY;;CAGnB,IAAI,OAAc;AAChB,SAAO,MAAKD;;CAGd,IAAI,WAAsB;AACxB,SAAO,MAAKC;;;AAIhB,IAAa,gCAAb,MAAkG;CAChG,CAASC;CACT,CAASC;CAET,YAAY,QAAiB,SAAmC;AAC9D,QAAKD,UAAW;EAEhB,MAAM,QAAQ,OAAO,MAClB,YAAUE,QAAM,SAAS,QAAQ,QAAQA,QAAM,WAAW,QAAQ,OACpE;AAED,MAAI,CAAC,MACH,OAAM,IAAI,MAAM,oBAAoB,QAAQ,KAAK,GAAG,QAAQ,SAAS;AAGvE,QAAKD,QAAS;;CAGhB,IAAI,OAAe;AACjB,SAAO,MAAKD,QAAS;;CAGvB,IAAI,SAAqB;AACvB,SAAO,MAAKA,QAAS;;CAGvB,IAAI,aAAqC;AACvC,SAAO,MAAKA,QAAS,cAAc,EAAE;;CAGvC,IAAI,cAA+B;AACjC,SAAO,MAAKA,QAAS;;CAGvB,IAAI,cAA4C;AAC9C,SAAO,MAAKC,MAAO;;CAGrB,IAAI,eAA6C;AAC/C,SAAO,MAAKA,MAAO;;CAIrB,iBAAiB,OASf,QACA,MACA,YAGkC;AAClC,MAAI,KAAK,SAAS,QAAQ,KAAK,WAAW,OACxC;AAeF,SAAQ,QAXa,MAAM,oBAAoB,YAAY;GACzD,SAAS,MAAKD,QAAS;GACvB,QAAQ,MAAKA,QAAS;GAChB;GACN,YAAY,KAAK;GACjB,aAAa,MAAKC,MAAO;GAC1B,CAAC,EAEoB,IAAI,qBAAqB,MAAKA,MAAO,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Ac,IAAI,IAAI,IAAI,IAAI,CAAC;KAC/B,MAAM,IAAI;KACV,SAAS;KACV,CAAC;IAEF,MAAM,0BAA0B,IAAI,+BAA+B,cAAc,SAAS;AAE1F,QAAI;KACF,MAAM,mBAAmB,MAAM,kBAC7B,wBACA,wBACD;AACD,SAAI,qBAAqB,OACvB,QAAO;aAEF,OAAO;AACd,aAAQ,MAAM,uBAAuB,MAAM;AAE3C,SAAI,iBAAiB,eAInB,QAAO,MAAM,YAAY;AAG3B,YAAO,SAAS,KACd;MAAE,OAAO;MAAyB,MAAM;MAAyB,EACjE,EAAE,QAAQ,KAAK,CAChB;;;GAIL,MAAM,eAAe,MAAM,oBAAoB,YAAY;IACzD,SAAS;IACT,QAAQ,IAAI;IACZ;IACA,YAAa,MAAM,UAAU,EAAE;IAC/B;IACD,CAAC;AAEF,OAAI;AAEF,WADe,MAAM,QAAQ,cAAc,cAAc;YAElD,OAAO;AACd,YAAQ,MAAM,oBAAoB,MAAM;AAExC,QAAI,iBAAiB,eACnB,QAAO,MAAM,YAAY;AAG3B,WAAO,SAAS,KACd;KAAE,OAAO;KAAyB,MAAM;KAAyB,EACjE,EAAE,QAAQ,KAAK,CAChB;;;EAGN;AAED,QAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FragnoApiValidationError } from "./api-
|
|
1
|
+
import { r as FragnoApiValidationError } from "./api-DuzjjCT4.js";
|
|
2
2
|
|
|
3
3
|
//#region src/api/internal/route.ts
|
|
4
4
|
function getMountRoute(opts) {
|
|
@@ -216,14 +216,14 @@ var OutputContext = class {
|
|
|
216
216
|
*/
|
|
217
217
|
error({ message, code }, initOrStatus, headers) {
|
|
218
218
|
if (typeof initOrStatus === "undefined") return Response.json({
|
|
219
|
-
|
|
219
|
+
message,
|
|
220
220
|
code
|
|
221
221
|
}, {
|
|
222
222
|
status: 500,
|
|
223
223
|
headers
|
|
224
224
|
});
|
|
225
225
|
if (typeof initOrStatus === "number") return Response.json({
|
|
226
|
-
|
|
226
|
+
message,
|
|
227
227
|
code
|
|
228
228
|
}, {
|
|
229
229
|
status: initOrStatus,
|
|
@@ -231,7 +231,7 @@ var OutputContext = class {
|
|
|
231
231
|
});
|
|
232
232
|
const mergedHeaders = mergeHeaders(initOrStatus.headers, headers);
|
|
233
233
|
return Response.json({
|
|
234
|
-
|
|
234
|
+
message,
|
|
235
235
|
code
|
|
236
236
|
}, {
|
|
237
237
|
status: initOrStatus.status,
|
|
@@ -327,5 +327,5 @@ function defineRoutes() {
|
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
//#endregion
|
|
330
|
-
export {
|
|
331
|
-
//# sourceMappingURL=route-
|
|
330
|
+
export { RequestOutputContext as a, OutputContext as i, defineRoutes as n, RequestInputContext as o, resolveRouteFactories as r, getMountRoute as s, defineRoute as t };
|
|
331
|
+
//# sourceMappingURL=route-Dq62lXqB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-Dq62lXqB.js","names":["#path","#method","#pathParams","#searchParams","#body","#inputSchema","#shouldValidateInput","#validateInput","#aborted","#closed","#responseReadable","#writer","#encoder","#abortSubscribers","mergedHeaders","#outputSchema","routes: any[]"],"sources":["../src/api/internal/route.ts","../src/api/request-input-context.ts","../src/api/internal/response-stream.ts","../src/api/request-output-context.ts","../src/api/route.ts"],"sourcesContent":["export function getMountRoute(opts: { mountRoute?: string; name: string }) {\n const mountRoute = opts.mountRoute ?? `/api/${opts.name}`;\n\n if (mountRoute.endsWith(\"/\")) {\n return mountRoute.slice(0, -1);\n }\n\n return mountRoute;\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { ExtractPathParams } from \"./internal/path\";\nimport { FragnoApiValidationError, type HTTPMethod } from \"./api\";\n\nexport type RequestBodyType =\n | unknown // JSON\n | FormData\n | Blob\n | null\n | undefined;\n\nexport class RequestInputContext<\n TPath extends string = string,\n TInputSchema extends StandardSchemaV1 | undefined = undefined,\n> {\n readonly #path: TPath;\n readonly #method: string;\n readonly #pathParams: ExtractPathParams<TPath>;\n readonly #searchParams: URLSearchParams;\n readonly #body: RequestBodyType;\n readonly #inputSchema: TInputSchema | undefined;\n readonly #shouldValidateInput: boolean;\n\n constructor(config: {\n path: TPath;\n method: string;\n pathParams: ExtractPathParams<TPath>;\n searchParams: URLSearchParams;\n body: RequestBodyType;\n\n request?: Request;\n inputSchema?: TInputSchema;\n shouldValidateInput?: boolean;\n }) {\n this.#path = config.path;\n this.#method = config.method;\n this.#pathParams = config.pathParams;\n this.#searchParams = config.searchParams;\n this.#body = config.body;\n this.#inputSchema = config.inputSchema;\n this.#shouldValidateInput = config.shouldValidateInput ?? true;\n }\n\n /**\n * Create a RequestContext from a Request object for server-side handling\n */\n static async fromRequest<\n TPath extends string,\n TInputSchema extends StandardSchemaV1 | undefined = undefined,\n >(config: {\n request: Request;\n method: string;\n path: TPath;\n pathParams: ExtractPathParams<TPath>;\n inputSchema?: TInputSchema;\n shouldValidateInput?: boolean;\n }): Promise<RequestInputContext<TPath, TInputSchema>> {\n const url = new URL(config.request.url);\n\n // Clone the request to avoid consuming the body stream\n // TODO: Probably we should just cache the result instead\n const request = config.request.clone();\n\n // TODO: Support other body types other than json\n const json = request.body instanceof ReadableStream ? await request.json() : undefined;\n\n return new RequestInputContext({\n method: config.method,\n path: config.path,\n pathParams: config.pathParams,\n searchParams: url.searchParams,\n body: json,\n inputSchema: config.inputSchema,\n shouldValidateInput: config.shouldValidateInput,\n });\n }\n\n /**\n * Create a RequestContext for server-side rendering contexts (no Request object)\n */\n static fromSSRContext<\n TPath extends string,\n TInputSchema extends StandardSchemaV1 | undefined = undefined,\n >(\n config:\n | {\n method: \"GET\";\n path: TPath;\n pathParams: ExtractPathParams<TPath>;\n searchParams?: URLSearchParams;\n }\n | {\n method: Exclude<HTTPMethod, \"GET\">;\n path: TPath;\n pathParams: ExtractPathParams<TPath>;\n searchParams?: URLSearchParams;\n body: RequestBodyType;\n inputSchema?: TInputSchema;\n },\n ): RequestInputContext<TPath, TInputSchema> {\n return new RequestInputContext({\n method: config.method,\n path: config.path,\n pathParams: config.pathParams,\n searchParams: config.searchParams ?? new URLSearchParams(),\n body: \"body\" in config ? config.body : undefined,\n inputSchema: \"inputSchema\" in config ? config.inputSchema : undefined,\n shouldValidateInput: false, // No input validation in SSR context\n });\n }\n\n // TODO(Wilco): We should support reading/modifying headers here.\n /**\n * The HTTP method as string (e.g., `GET`, `POST`)\n */\n get method(): string {\n return this.#method;\n }\n /**\n * The matched route path (e.g., `/users/:id`)\n * @remarks `string`\n */\n get path(): TPath {\n return this.#path;\n }\n /**\n * Extracted path parameters as object (e.g., `{ id: '123' }`)\n * @remarks `Record<string, string>`\n */\n get pathParams(): ExtractPathParams<TPath> {\n return this.#pathParams;\n }\n /**\n * [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) object for query parameters\n * @remarks `URLSearchParams`\n */\n get query(): URLSearchParams {\n return this.#searchParams;\n }\n // TODO: Should probably remove this\n /**\n * @internal\n */\n get rawBody(): RequestBodyType {\n return this.#body;\n }\n /**\n * Input validation context (only if inputSchema is defined)\n * @remarks `InputContext`\n */\n get input(): TInputSchema extends undefined\n ? undefined\n : {\n schema: TInputSchema;\n valid: () => Promise<\n TInputSchema extends StandardSchemaV1\n ? StandardSchemaV1.InferOutput<TInputSchema>\n : unknown\n >;\n } {\n if (!this.#inputSchema) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return undefined as any;\n }\n\n return {\n schema: this.#inputSchema,\n valid: async () => {\n if (!this.#shouldValidateInput) {\n // In SSR context, return the body directly without validation\n return this.#body;\n }\n\n return this.#validateInput();\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n }\n\n async #validateInput(): Promise<\n TInputSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TInputSchema> : never\n > {\n if (!this.#inputSchema) {\n throw new Error(\"No input schema defined for this route\");\n }\n\n if (this.#body instanceof FormData || this.#body instanceof Blob) {\n throw new Error(\"Schema validation is only supported for JSON data, not FormData or Blob\");\n }\n\n const result = await this.#inputSchema[\"~standard\"].validate(this.#body);\n\n if (result.issues) {\n throw new FragnoApiValidationError(\"Validation failed\", result.issues);\n }\n\n return result.value as TInputSchema extends StandardSchemaV1\n ? StandardSchemaV1.InferOutput<TInputSchema>\n : never;\n }\n}\n","/**\n * @module\n * Stream utility.\n *\n * Modified from honojs/hono\n * Original source: https://github.com/honojs/hono/blob/0e3db674ad3f40be215a55a18062dd8e387ce525/src/utils/stream.ts\n * License: MIT\n * Date obtained: August 28 2025\n * Copyright (c) 2021-present Yusuke Wada and Hono contributors\n */\n\ntype Error<Message extends string> = { __errorMessage: Message };\n\nexport class ResponseStream<TArray> {\n #writer: WritableStreamDefaultWriter<Uint8Array>;\n #encoder: TextEncoder;\n #abortSubscribers: (() => void | Promise<void>)[] = [];\n #responseReadable: ReadableStream;\n\n #aborted: boolean = false;\n #closed: boolean = false;\n\n /**\n * Whether the stream has been aborted.\n */\n get aborted(): boolean {\n return this.#aborted;\n }\n\n /**\n * Whether the stream has been closed normally.\n */\n get closed(): boolean {\n return this.#closed;\n }\n\n /**\n * The readable stream that the response is piped to.\n */\n get responseReadable(): ReadableStream {\n return this.#responseReadable;\n }\n\n constructor(writable: WritableStream, readable: ReadableStream) {\n this.#writer = writable.getWriter();\n this.#encoder = new TextEncoder();\n const reader = readable.getReader();\n\n // in case the user disconnects, let the reader know to cancel\n // this in-turn results in responseReadable being closed\n // and writeSSE method no longer blocks indefinitely\n this.#abortSubscribers.push(async () => {\n await reader.cancel();\n });\n\n this.#responseReadable = new ReadableStream({\n async pull(controller) {\n const { done, value } = await reader.read();\n if (done) {\n controller.close();\n } else {\n controller.enqueue(value);\n }\n },\n cancel: () => {\n this.abort();\n },\n });\n }\n\n async writeRaw(input: Uint8Array | string): Promise<void> {\n try {\n if (typeof input === \"string\") {\n input = this.#encoder.encode(input);\n }\n await this.#writer.write(input);\n } catch {\n // Do nothing.\n }\n }\n\n write(\n input: TArray extends (infer U)[]\n ? U\n : Error<\"To use a streaming response, outputSchema must be an array.\">,\n ): Promise<void> {\n return this.writeRaw(JSON.stringify(input) + \"\\n\");\n }\n\n sleep(ms: number): Promise<unknown> {\n return new Promise((res) => setTimeout(res, ms));\n }\n\n async close() {\n try {\n await this.#writer.close();\n } catch {\n // Do nothing. If you want to handle errors, create a stream by yourself.\n } finally {\n this.#closed = true;\n }\n }\n\n onAbort(listener: () => void | Promise<void>) {\n this.#abortSubscribers.push(listener);\n }\n\n /**\n * Abort the stream.\n * You can call this method when stream is aborted by external event.\n */\n abort() {\n if (!this.aborted) {\n this.#aborted = true;\n this.#abortSubscribers.forEach((subscriber) => subscriber());\n }\n }\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { ContentlessStatusCode, StatusCode } from \"../http/http-status\";\nimport { ResponseStream } from \"./internal/response-stream\";\nimport type { InferOrUnknown } from \"../util/types-util\";\n\nexport type ResponseData = string | ArrayBuffer | ReadableStream | Uint8Array<ArrayBuffer>;\n\ninterface ResponseInit<T extends StatusCode = StatusCode> {\n headers?: HeadersInit;\n status?: T;\n statusText?: string;\n}\n\n/**\n * Utility function to merge headers from multiple sources.\n * Later headers override earlier ones.\n */\nfunction mergeHeaders(...headerSources: (HeadersInit | undefined)[]): HeadersInit | undefined {\n const mergedHeaders = new Headers();\n\n for (const headerSource of headerSources) {\n if (!headerSource) continue;\n\n if (headerSource instanceof Headers) {\n for (const [key, value] of headerSource.entries()) {\n mergedHeaders.set(key, value);\n }\n } else if (Array.isArray(headerSource)) {\n for (const [key, value] of headerSource) {\n mergedHeaders.set(key, value);\n }\n } else {\n for (const [key, value] of Object.entries(headerSource)) {\n mergedHeaders.set(key, value);\n }\n }\n }\n\n return mergedHeaders;\n}\n\nexport abstract class OutputContext<const TOutput, const TErrorCode extends string> {\n /**\n * Creates an error response.\n *\n * Shortcut for `throw new FragnoApiError(...)`\n */\n error(\n { message, code }: { message: string; code: TErrorCode },\n initOrStatus?: ResponseInit | StatusCode,\n headers?: HeadersInit,\n ): Response {\n if (typeof initOrStatus === \"undefined\") {\n return Response.json({ message: message, code }, { status: 500, headers });\n }\n\n if (typeof initOrStatus === \"number\") {\n return Response.json({ message: message, code }, { status: initOrStatus, headers });\n }\n\n const mergedHeaders = mergeHeaders(initOrStatus.headers, headers);\n return Response.json(\n { message: message, code },\n { status: initOrStatus.status, headers: mergedHeaders },\n );\n }\n\n empty(\n initOrStatus?: ResponseInit<ContentlessStatusCode> | ContentlessStatusCode,\n headers?: HeadersInit,\n ): Response {\n const defaultHeaders = {};\n\n if (typeof initOrStatus === \"undefined\") {\n const mergedHeaders = mergeHeaders(defaultHeaders, headers);\n return Response.json(null, {\n status: 201,\n headers: mergedHeaders,\n });\n }\n\n if (typeof initOrStatus === \"number\") {\n const mergedHeaders = mergeHeaders(defaultHeaders, headers);\n return Response.json(null, {\n status: initOrStatus,\n headers: mergedHeaders,\n });\n }\n\n const mergedHeaders = mergeHeaders(defaultHeaders, initOrStatus.headers, headers);\n return Response.json(null, {\n status: initOrStatus.status,\n headers: mergedHeaders,\n });\n }\n\n json(object: TOutput, initOrStatus?: ResponseInit | StatusCode, headers?: HeadersInit): Response {\n if (typeof initOrStatus === \"undefined\") {\n return Response.json(object, {\n status: 200,\n headers,\n });\n }\n\n if (typeof initOrStatus === \"number\") {\n return Response.json(object, {\n status: initOrStatus,\n headers,\n });\n }\n\n const mergedHeaders = mergeHeaders(initOrStatus.headers, headers);\n return Response.json(object, {\n status: initOrStatus.status,\n headers: mergedHeaders,\n });\n }\n\n jsonStream = (\n cb: (stream: ResponseStream<TOutput>) => void | Promise<void>,\n {\n onError,\n headers,\n }: {\n onError?: (error: Error, stream: ResponseStream<TOutput>) => void | Promise<void>;\n headers?: HeadersInit;\n } = {},\n ): Response => {\n // Note: this is intentionally an arrow function (=>) to keep `this` context.\n const defaultHeaders = {\n \"content-type\": \"application/x-ndjson; charset=utf-8\",\n \"transfer-encoding\": \"chunked\",\n \"cache-control\": \"no-cache\",\n };\n\n const { readable, writable } = new TransformStream();\n const stream = new ResponseStream(writable, readable);\n\n (async () => {\n try {\n await cb(stream);\n } catch (e) {\n if (e === undefined) {\n // If reading is canceled without a reason value (e.g. by StreamingApi)\n // then the .pipeTo() promise will reject with undefined.\n // In this case, do nothing because the stream is already closed.\n } else if (e instanceof Error && onError) {\n await onError(e, stream);\n } else {\n console.error(e);\n }\n } finally {\n stream.close();\n }\n })();\n\n return new Response(stream.responseReadable, {\n status: 200,\n headers: mergeHeaders(defaultHeaders, headers),\n });\n };\n}\n\nexport class RequestOutputContext<\n const TOutputSchema extends StandardSchemaV1 | undefined = undefined,\n const TErrorCode extends string = string,\n> extends OutputContext<InferOrUnknown<TOutputSchema>, TErrorCode> {\n // eslint-disable-next-line no-unused-private-class-members\n #outputSchema?: TOutputSchema;\n\n constructor(outputSchema?: TOutputSchema) {\n super();\n this.#outputSchema = outputSchema;\n }\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { FragnoRouteConfig, HTTPMethod } from \"./api\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyFragnoRouteConfig = FragnoRouteConfig<HTTPMethod, string, any, any, any, any>;\n\nexport interface RouteFactoryContext<TConfig, TDeps, TServices> {\n config: TConfig;\n deps: TDeps;\n services: TServices;\n}\n\nexport type RouteFactory<\n TConfig,\n TDeps,\n TServices,\n TRoutes extends readonly FragnoRouteConfig<\n HTTPMethod,\n string,\n StandardSchemaV1 | undefined,\n StandardSchemaV1 | undefined,\n string,\n string\n >[],\n> = (context: RouteFactoryContext<TConfig, TDeps, TServices>) => TRoutes;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyRouteOrFactory = AnyFragnoRouteConfig | RouteFactory<any, any, any, any>;\n\nexport type FlattenRouteFactories<T extends readonly AnyRouteOrFactory[]> = T extends readonly [\n infer First,\n ...infer Rest extends readonly AnyRouteOrFactory[],\n]\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n First extends RouteFactory<any, any, any, infer TRoutes>\n ? [...TRoutes, ...FlattenRouteFactories<Rest>]\n : [First, ...FlattenRouteFactories<Rest>]\n : [];\n\n// Helper to resolve route factories into routes\nexport function resolveRouteFactories<\n TConfig,\n TDeps,\n TServices,\n const TRoutesOrFactories extends readonly AnyRouteOrFactory[],\n>(\n context: RouteFactoryContext<TConfig, TDeps, TServices>,\n routesOrFactories: TRoutesOrFactories,\n): FlattenRouteFactories<TRoutesOrFactories> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const routes: any[] = [];\n\n for (const item of routesOrFactories) {\n if (typeof item === \"function\") {\n // It's a route factory\n const factoryRoutes = item(context);\n routes.push(...factoryRoutes);\n } else {\n // It's a direct route\n routes.push(item);\n }\n }\n\n return routes as FlattenRouteFactories<TRoutesOrFactories>;\n}\n\n// TODO(Wilco): Do these overloads actually do anything?\n// TODO(Wilco): ValidPath<T> should be added back in here.\n\n// Overload for routes without inputSchema\nexport function defineRoute<\n const TMethod extends HTTPMethod,\n const TPath extends string,\n const TOutputSchema extends StandardSchemaV1 | undefined,\n const TErrorCode extends string = string,\n const TQueryParameters extends string = string,\n>(\n config: FragnoRouteConfig<\n TMethod,\n TPath,\n undefined,\n TOutputSchema,\n TErrorCode,\n TQueryParameters\n > & { inputSchema?: undefined },\n): FragnoRouteConfig<TMethod, TPath, undefined, TOutputSchema, TErrorCode, TQueryParameters>;\n\n// Overload for routes with inputSchema\nexport function defineRoute<\n const TMethod extends HTTPMethod,\n const TPath extends string,\n const TInputSchema extends StandardSchemaV1,\n const TOutputSchema extends StandardSchemaV1 | undefined,\n const TErrorCode extends string = string,\n const TQueryParameters extends string = string,\n>(\n config: FragnoRouteConfig<\n TMethod,\n TPath,\n TInputSchema,\n TOutputSchema,\n TErrorCode,\n TQueryParameters\n > & { inputSchema: TInputSchema },\n): FragnoRouteConfig<TMethod, TPath, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters>;\n\n// implementation\nexport function defineRoute<\n const TMethod extends HTTPMethod,\n const TPath extends string,\n const TInputSchema extends StandardSchemaV1 | undefined,\n const TOutputSchema extends StandardSchemaV1 | undefined,\n const TErrorCode extends string = string,\n const TQueryParameters extends string = string,\n>(\n config: FragnoRouteConfig<\n TMethod,\n TPath,\n TInputSchema,\n TOutputSchema,\n TErrorCode,\n TQueryParameters\n >,\n): FragnoRouteConfig<TMethod, TPath, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters> {\n return config;\n}\n\nexport function defineRoutes<TConfig = {}, TDeps = {}, TServices = {}>() {\n return {\n create: <\n const TRoutes extends readonly FragnoRouteConfig<\n HTTPMethod,\n string,\n StandardSchemaV1 | undefined,\n StandardSchemaV1 | undefined,\n string,\n string\n >[],\n >(\n fn: (context: RouteFactoryContext<TConfig, TDeps, TServices>) => TRoutes,\n ): RouteFactory<TConfig, TDeps, TServices, TRoutes> => {\n return fn;\n },\n };\n}\n"],"mappings":";;;AAAA,SAAgB,cAAc,MAA6C;CACzE,MAAM,aAAa,KAAK,cAAc,QAAQ,KAAK;AAEnD,KAAI,WAAW,SAAS,IAAI,CAC1B,QAAO,WAAW,MAAM,GAAG,GAAG;AAGhC,QAAO;;;;;ACIT,IAAa,sBAAb,MAAa,oBAGX;CACA,CAASA;CACT,CAASC;CACT,CAASC;CACT,CAASC;CACT,CAASC;CACT,CAASC;CACT,CAASC;CAET,YAAY,QAUT;AACD,QAAKN,OAAQ,OAAO;AACpB,QAAKC,SAAU,OAAO;AACtB,QAAKC,aAAc,OAAO;AAC1B,QAAKC,eAAgB,OAAO;AAC5B,QAAKC,OAAQ,OAAO;AACpB,QAAKC,cAAe,OAAO;AAC3B,QAAKC,sBAAuB,OAAO,uBAAuB;;;;;CAM5D,aAAa,YAGX,QAOoD;EACpD,MAAM,MAAM,IAAI,IAAI,OAAO,QAAQ,IAAI;EAIvC,MAAM,UAAU,OAAO,QAAQ,OAAO;EAGtC,MAAM,OAAO,QAAQ,gBAAgB,iBAAiB,MAAM,QA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
@@ -44,5 +44,5 @@ async function getFinalStoreValues() {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
//#endregion
|
|
47
|
-
export {
|
|
48
|
-
//# sourceMappingURL=ssr-
|
|
47
|
+
export { getInitialData as a, getFinalStoreValues as i, addStore as n, hydrateFromWindow as o, cleanStores as r, SSR_ENABLED as t };
|
|
48
|
+
//# sourceMappingURL=ssr-BAhbA_3q.js.map
|