@fragno-dev/core 0.0.1
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 +61 -0
- package/.turbo/turbo-types$colon$check.log +2 -0
- package/dist/api/api.d.ts +2 -0
- package/dist/api/api.js +3 -0
- package/dist/api-CBDGZiLC.d.ts +278 -0
- package/dist/api-CBDGZiLC.d.ts.map +1 -0
- package/dist/api-DgHfYjq2.js +54 -0
- package/dist/api-DgHfYjq2.js.map +1 -0
- package/dist/client/client.d.ts +3 -0
- package/dist/client/client.js +6 -0
- package/dist/client/client.svelte.d.ts +33 -0
- package/dist/client/client.svelte.d.ts.map +1 -0
- package/dist/client/client.svelte.js +123 -0
- package/dist/client/client.svelte.js.map +1 -0
- package/dist/client/react.d.ts +58 -0
- package/dist/client/react.d.ts.map +1 -0
- package/dist/client/react.js +80 -0
- package/dist/client/react.js.map +1 -0
- package/dist/client/vanilla.d.ts +61 -0
- package/dist/client/vanilla.d.ts.map +1 -0
- package/dist/client/vanilla.js +136 -0
- package/dist/client/vanilla.js.map +1 -0
- package/dist/client/vue.d.ts +39 -0
- package/dist/client/vue.d.ts.map +1 -0
- package/dist/client/vue.js +108 -0
- package/dist/client/vue.js.map +1 -0
- package/dist/client-DWjxKDnE.js +703 -0
- package/dist/client-DWjxKDnE.js.map +1 -0
- package/dist/client-XFdAy-IQ.d.ts +287 -0
- package/dist/client-XFdAy-IQ.d.ts.map +1 -0
- package/dist/integrations/astro.d.ts +18 -0
- package/dist/integrations/astro.d.ts.map +1 -0
- package/dist/integrations/astro.js +16 -0
- package/dist/integrations/astro.js.map +1 -0
- package/dist/integrations/next-js.d.ts +15 -0
- package/dist/integrations/next-js.d.ts.map +1 -0
- package/dist/integrations/next-js.js +17 -0
- package/dist/integrations/next-js.js.map +1 -0
- package/dist/integrations/react-ssr.d.ts +19 -0
- package/dist/integrations/react-ssr.d.ts.map +1 -0
- package/dist/integrations/react-ssr.js +38 -0
- package/dist/integrations/react-ssr.js.map +1 -0
- package/dist/integrations/svelte-kit.d.ts +21 -0
- package/dist/integrations/svelte-kit.d.ts.map +1 -0
- package/dist/integrations/svelte-kit.js +18 -0
- package/dist/integrations/svelte-kit.js.map +1 -0
- package/dist/mod.d.ts +3 -0
- package/dist/mod.js +177 -0
- package/dist/mod.js.map +1 -0
- package/dist/route-Bp6eByhz.js +331 -0
- package/dist/route-Bp6eByhz.js.map +1 -0
- package/dist/ssr-tJHqcNSw.js +48 -0
- package/dist/ssr-tJHqcNSw.js.map +1 -0
- package/package.json +127 -0
- package/src/api/api.test.ts +140 -0
- package/src/api/api.ts +106 -0
- package/src/api/error.ts +47 -0
- package/src/api/fragment.test.ts +509 -0
- package/src/api/fragment.ts +277 -0
- package/src/api/internal/path-runtime.test.ts +121 -0
- package/src/api/internal/path-type.test.ts +602 -0
- package/src/api/internal/path.ts +322 -0
- package/src/api/internal/response-stream.ts +118 -0
- package/src/api/internal/route.test.ts +56 -0
- package/src/api/internal/route.ts +9 -0
- package/src/api/request-input-context.test.ts +437 -0
- package/src/api/request-input-context.ts +201 -0
- package/src/api/request-middleware.test.ts +544 -0
- package/src/api/request-middleware.ts +126 -0
- package/src/api/request-output-context.test.ts +626 -0
- package/src/api/request-output-context.ts +175 -0
- package/src/api/route.test.ts +176 -0
- package/src/api/route.ts +152 -0
- package/src/client/client-builder.test.ts +264 -0
- package/src/client/client-error.test.ts +15 -0
- package/src/client/client-error.ts +141 -0
- package/src/client/client-types.test.ts +493 -0
- package/src/client/client.ssr.test.ts +173 -0
- package/src/client/client.svelte.test.ts +837 -0
- package/src/client/client.svelte.ts +278 -0
- package/src/client/client.test.ts +1690 -0
- package/src/client/client.ts +1035 -0
- package/src/client/component.test.svelte +21 -0
- package/src/client/internal/ndjson-streaming.test.ts +457 -0
- package/src/client/internal/ndjson-streaming.ts +248 -0
- package/src/client/react.test.ts +947 -0
- package/src/client/react.ts +241 -0
- package/src/client/vanilla.test.ts +867 -0
- package/src/client/vanilla.ts +265 -0
- package/src/client/vue.test.ts +754 -0
- package/src/client/vue.ts +242 -0
- package/src/http/http-status.ts +60 -0
- package/src/integrations/astro.ts +17 -0
- package/src/integrations/next-js.ts +31 -0
- package/src/integrations/react-ssr.ts +40 -0
- package/src/integrations/svelte-kit.ts +41 -0
- package/src/mod.ts +20 -0
- package/src/util/async.test.ts +85 -0
- package/src/util/async.ts +96 -0
- package/src/util/content-type.test.ts +136 -0
- package/src/util/content-type.ts +84 -0
- package/src/util/nanostores.test.ts +28 -0
- package/src/util/nanostores.ts +65 -0
- package/src/util/ssr.ts +75 -0
- package/src/util/types-util.ts +16 -0
- package/tsconfig.json +10 -0
- package/tsdown.config.ts +21 -0
- package/vitest.config.ts +10 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
[0m[2m[35m$[0m [2m[1mtsdown[0m
|
|
3
|
+
[34mℹ[39m tsdown [2mv0.15.4[22m powered by rolldown [2mv1.0.0-beta.40[22m
|
|
4
|
+
[34mℹ[39m Using tsdown config: [4m/Users/wilco/dev/fragno/packages/fragno/tsdown.config.ts[24m
|
|
5
|
+
[34mℹ[39m entry: [34msrc/mod.ts, src/client/client.svelte.ts, src/client/client.ts, src/client/react.ts, src/client/vanilla.ts, src/client/vue.ts, src/api/api.ts, src/integrations/astro.ts, src/integrations/next-js.ts, src/integrations/react-ssr.ts, src/integrations/svelte-kit.ts[39m
|
|
6
|
+
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
7
|
+
[34mℹ[39m Build start
|
|
8
|
+
[34mℹ[39m Cleaning 55 files
|
|
9
|
+
[34mℹ[39m [2mdist/[22m[1mmod.js[22m [2m 5.45 kB[22m [2m│ gzip: 1.63 kB[22m
|
|
10
|
+
[34mℹ[39m [2mdist/[22m[1mclient/client.svelte.js[22m [2m 3.30 kB[22m [2m│ gzip: 0.97 kB[22m
|
|
11
|
+
[34mℹ[39m [2mdist/[22m[1mclient/vanilla.js[22m [2m 3.29 kB[22m [2m│ gzip: 1.11 kB[22m
|
|
12
|
+
[34mℹ[39m [2mdist/[22m[1mclient/vue.js[22m [2m 2.85 kB[22m [2m│ gzip: 1.00 kB[22m
|
|
13
|
+
[34mℹ[39m [2mdist/[22m[1mclient/react.js[22m [2m 2.50 kB[22m [2m│ gzip: 0.93 kB[22m
|
|
14
|
+
[34mℹ[39m [2mdist/[22m[1mintegrations/react-ssr.js[22m [2m 1.26 kB[22m [2m│ gzip: 0.64 kB[22m
|
|
15
|
+
[34mℹ[39m [2mdist/[22m[1mclient/client.js[22m [2m 0.64 kB[22m [2m│ gzip: 0.22 kB[22m
|
|
16
|
+
[34mℹ[39m [2mdist/[22m[1mintegrations/svelte-kit.js[22m [2m 0.49 kB[22m [2m│ gzip: 0.26 kB[22m
|
|
17
|
+
[34mℹ[39m [2mdist/[22m[1mintegrations/next-js.js[22m [2m 0.41 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
18
|
+
[34mℹ[39m [2mdist/[22m[1mintegrations/astro.js[22m [2m 0.39 kB[22m [2m│ gzip: 0.25 kB[22m
|
|
19
|
+
[34mℹ[39m [2mdist/[22m[1mapi/api.js[22m [2m 0.15 kB[22m [2m│ gzip: 0.10 kB[22m
|
|
20
|
+
[34mℹ[39m [2mdist/[22mclient-DWjxKDnE.js.map [2m72.47 kB[22m [2m│ gzip: 16.35 kB[22m
|
|
21
|
+
[34mℹ[39m [2mdist/[22mroute-Bp6eByhz.js.map [2m24.82 kB[22m [2m│ gzip: 6.81 kB[22m
|
|
22
|
+
[34mℹ[39m [2mdist/[22mclient-DWjxKDnE.js [2m24.49 kB[22m [2m│ gzip: 6.18 kB[22m
|
|
23
|
+
[34mℹ[39m [2mdist/[22mclient-XFdAy-IQ.d.ts.map [2m16.15 kB[22m [2m│ gzip: 6.38 kB[22m
|
|
24
|
+
[34mℹ[39m [2mdist/[22mmod.js.map [2m15.78 kB[22m [2m│ gzip: 4.35 kB[22m
|
|
25
|
+
[34mℹ[39m [2mdist/[22mclient/vanilla.js.map [2m12.96 kB[22m [2m│ gzip: 3.58 kB[22m
|
|
26
|
+
[34mℹ[39m [2mdist/[22mclient/client.svelte.js.map [2m11.35 kB[22m [2m│ gzip: 2.76 kB[22m
|
|
27
|
+
[34mℹ[39m [2mdist/[22mclient/vue.js.map [2m10.12 kB[22m [2m│ gzip: 2.78 kB[22m
|
|
28
|
+
[34mℹ[39m [2mdist/[22mclient/react.js.map [2m 9.55 kB[22m [2m│ gzip: 3.02 kB[22m
|
|
29
|
+
[34mℹ[39m [2mdist/[22mroute-Bp6eByhz.js [2m 8.77 kB[22m [2m│ gzip: 2.63 kB[22m
|
|
30
|
+
[34mℹ[39m [2mdist/[22mapi-CBDGZiLC.d.ts.map [2m 8.23 kB[22m [2m│ gzip: 3.23 kB[22m
|
|
31
|
+
[34mℹ[39m [2mdist/[22mapi-DgHfYjq2.js.map [2m 5.54 kB[22m [2m│ gzip: 1.56 kB[22m
|
|
32
|
+
[34mℹ[39m [2mdist/[22mssr-tJHqcNSw.js.map [2m 2.96 kB[22m [2m│ gzip: 1.25 kB[22m
|
|
33
|
+
[34mℹ[39m [2mdist/[22mclient/vanilla.d.ts.map [2m 2.83 kB[22m [2m│ gzip: 1.08 kB[22m
|
|
34
|
+
[34mℹ[39m [2mdist/[22mclient/react.d.ts.map [2m 2.71 kB[22m [2m│ gzip: 1.17 kB[22m
|
|
35
|
+
[34mℹ[39m [2mdist/[22mclient/client.svelte.d.ts.map [2m 2.44 kB[22m [2m│ gzip: 1.00 kB[22m
|
|
36
|
+
[34mℹ[39m [2mdist/[22mclient/vue.d.ts.map [2m 2.22 kB[22m [2m│ gzip: 0.95 kB[22m
|
|
37
|
+
[34mℹ[39m [2mdist/[22mintegrations/react-ssr.js.map [2m 1.65 kB[22m [2m│ gzip: 0.84 kB[22m
|
|
38
|
+
[34mℹ[39m [2mdist/[22mintegrations/svelte-kit.js.map [2m 1.63 kB[22m [2m│ gzip: 0.58 kB[22m
|
|
39
|
+
[34mℹ[39m [2mdist/[22mssr-tJHqcNSw.js [2m 1.35 kB[22m [2m│ gzip: 0.60 kB[22m
|
|
40
|
+
[34mℹ[39m [2mdist/[22mintegrations/next-js.js.map [2m 1.30 kB[22m [2m│ gzip: 0.48 kB[22m
|
|
41
|
+
[34mℹ[39m [2mdist/[22mapi-DgHfYjq2.js [2m 1.06 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
42
|
+
[34mℹ[39m [2mdist/[22mintegrations/astro.js.map [2m 0.69 kB[22m [2m│ gzip: 0.39 kB[22m
|
|
43
|
+
[34mℹ[39m [2mdist/[22mintegrations/next-js.d.ts.map [2m 0.68 kB[22m [2m│ gzip: 0.38 kB[22m
|
|
44
|
+
[34mℹ[39m [2mdist/[22mintegrations/svelte-kit.d.ts.map [2m 0.68 kB[22m [2m│ gzip: 0.41 kB[22m
|
|
45
|
+
[34mℹ[39m [2mdist/[22mintegrations/astro.d.ts.map [2m 0.34 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
46
|
+
[34mℹ[39m [2mdist/[22mintegrations/react-ssr.d.ts.map [2m 0.23 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
47
|
+
[34mℹ[39m [2mdist/[22m[32m[1mclient/vanilla.d.ts[22m[39m [2m 3.53 kB[22m [2m│ gzip: 1.02 kB[22m
|
|
48
|
+
[34mℹ[39m [2mdist/[22m[32m[1mclient/react.d.ts[22m[39m [2m 3.34 kB[22m [2m│ gzip: 1.15 kB[22m
|
|
49
|
+
[34mℹ[39m [2mdist/[22m[32m[1mclient/client.svelte.d.ts[22m[39m [2m 2.74 kB[22m [2m│ gzip: 0.80 kB[22m
|
|
50
|
+
[34mℹ[39m [2mdist/[22m[32m[1mclient/vue.d.ts[22m[39m [2m 2.68 kB[22m [2m│ gzip: 0.90 kB[22m
|
|
51
|
+
[34mℹ[39m [2mdist/[22m[32m[1mclient/client.d.ts[22m[39m [2m 1.24 kB[22m [2m│ gzip: 0.32 kB[22m
|
|
52
|
+
[34mℹ[39m [2mdist/[22m[32m[1mintegrations/svelte-kit.d.ts[22m[39m [2m 0.81 kB[22m [2m│ gzip: 0.32 kB[22m
|
|
53
|
+
[34mℹ[39m [2mdist/[22m[32m[1mintegrations/react-ssr.d.ts[22m[39m [2m 0.78 kB[22m [2m│ gzip: 0.38 kB[22m
|
|
54
|
+
[34mℹ[39m [2mdist/[22m[32m[1mmod.d.ts[22m[39m [2m 0.68 kB[22m [2m│ gzip: 0.25 kB[22m
|
|
55
|
+
[34mℹ[39m [2mdist/[22m[32m[1mintegrations/next-js.d.ts[22m[39m [2m 0.63 kB[22m [2m│ gzip: 0.25 kB[22m
|
|
56
|
+
[34mℹ[39m [2mdist/[22m[32m[1mintegrations/astro.d.ts[22m[39m [2m 0.51 kB[22m [2m│ gzip: 0.28 kB[22m
|
|
57
|
+
[34mℹ[39m [2mdist/[22m[32m[1mapi/api.d.ts[22m[39m [2m 0.27 kB[22m [2m│ gzip: 0.14 kB[22m
|
|
58
|
+
[34mℹ[39m [2mdist/[22m[32mclient-XFdAy-IQ.d.ts[39m [2m19.93 kB[22m [2m│ gzip: 4.16 kB[22m
|
|
59
|
+
[34mℹ[39m [2mdist/[22m[32mapi-CBDGZiLC.d.ts[39m [2m12.17 kB[22m [2m│ gzip: 3.46 kB[22m
|
|
60
|
+
[34mℹ[39m 51 files, total: 313.05 kB
|
|
61
|
+
[32m✔[39m Build complete in [32m984ms[39m
|
package/dist/api/api.js
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/api/internal/path.d.ts
|
|
4
|
+
type SplitPath<T extends string> = T extends `${infer First}/${infer Rest}` ? First extends "" ? SplitPath<Rest> : [First, ...SplitPath<Rest>] : T extends "" ? [] : [T];
|
|
5
|
+
type ExtractParam<T extends string> = T extends `:${infer Name}` ? Name : T extends `**:${infer Name}` ? Name : T extends "**" ? "**" : never;
|
|
6
|
+
type ExtractParamsFromSegments<T extends readonly string[]> = T extends readonly [infer First, ...infer Rest] ? First extends string ? Rest extends readonly string[] ? ExtractParam<First> | ExtractParamsFromSegments<Rest> : ExtractParam<First> : never : never;
|
|
7
|
+
/**
|
|
8
|
+
* Type helper to extract path parameters from a const string path
|
|
9
|
+
*
|
|
10
|
+
* Supports:
|
|
11
|
+
* - Regular paths: "/path" -> never
|
|
12
|
+
* - Named parameters: "/path/:name" -> "name"
|
|
13
|
+
* - Wildcard paths: "/path/foo/**" -> "**"
|
|
14
|
+
* - Named wildcard paths: "/path/foo/**:name" -> "name"
|
|
15
|
+
* - String (narrows): string -> never
|
|
16
|
+
*/
|
|
17
|
+
type ExtractPathParams<T extends string, ValueType = string> = ExtractParamsFromSegments<SplitPath<T>> extends never ? Record<string, never> : Record<ExtractParamsFromSegments<SplitPath<T>>, ValueType>;
|
|
18
|
+
/**
|
|
19
|
+
* Same as @see ExtractPathParams, but returns `Record<string, ValueType>` when a string is
|
|
20
|
+
* passed in.
|
|
21
|
+
*/
|
|
22
|
+
type ExtractPathParamsOrWiden<T extends string, ValueType = string> = string extends T ? Record<string, ValueType> : ExtractPathParams<T, ValueType>;
|
|
23
|
+
/**
|
|
24
|
+
* Same as @see ExtractPathParamsOrWiden, but returns `undefined` when no path parameters in the
|
|
25
|
+
* const.
|
|
26
|
+
*/
|
|
27
|
+
type MaybeExtractPathParamsOrWiden<T extends string, ValueType = string> = HasPathParams<T> extends true ? ExtractPathParamsOrWiden<T, ValueType> : undefined;
|
|
28
|
+
type ExtractPathParamNames<T extends string> = ExtractParamsFromSegments<SplitPath<T>>;
|
|
29
|
+
type HasPathParams<T extends string> = ExtractPathParamNames<T> extends never ? false : true;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a query parameters type where the specified keys are hints (optional)
|
|
32
|
+
* and additional string keys are also allowed.
|
|
33
|
+
*
|
|
34
|
+
* This allows for flexible query parameter typing where:
|
|
35
|
+
* - All hinted parameters are optional
|
|
36
|
+
* - Additional parameters beyond the hints are allowed
|
|
37
|
+
* - Values can be of any specified type (defaults to string)
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* type MyQuery = QueryParamsHint<"page" | "limit", string>;
|
|
42
|
+
* // Allows: { page?: string, limit?: string, [key: string]: string }
|
|
43
|
+
*
|
|
44
|
+
* const query1: MyQuery = {}; // Valid - no params required
|
|
45
|
+
* const query2: MyQuery = { page: "1" }; // Valid - hinted param
|
|
46
|
+
* const query3: MyQuery = { page: "1", sort: "asc" }; // Valid - additional param
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
type QueryParamsHint<TQueryParameters extends string, ValueType = string> = Partial<Record<TQueryParameters, ValueType>> & Record<string, ValueType>;
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/api/request-input-context.d.ts
|
|
52
|
+
type RequestBodyType = unknown | FormData | Blob | null | undefined;
|
|
53
|
+
declare class RequestInputContext<TPath extends string = string, TInputSchema extends StandardSchemaV1 | undefined = undefined> {
|
|
54
|
+
#private;
|
|
55
|
+
constructor(config: {
|
|
56
|
+
path: TPath;
|
|
57
|
+
method: string;
|
|
58
|
+
pathParams: ExtractPathParams<TPath>;
|
|
59
|
+
searchParams: URLSearchParams;
|
|
60
|
+
body: RequestBodyType;
|
|
61
|
+
request?: Request;
|
|
62
|
+
inputSchema?: TInputSchema;
|
|
63
|
+
shouldValidateInput?: boolean;
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Create a RequestContext from a Request object for server-side handling
|
|
67
|
+
*/
|
|
68
|
+
static fromRequest<TPath extends string, TInputSchema extends StandardSchemaV1 | undefined = undefined>(config: {
|
|
69
|
+
request: Request;
|
|
70
|
+
method: string;
|
|
71
|
+
path: TPath;
|
|
72
|
+
pathParams: ExtractPathParams<TPath>;
|
|
73
|
+
inputSchema?: TInputSchema;
|
|
74
|
+
shouldValidateInput?: boolean;
|
|
75
|
+
}): Promise<RequestInputContext<TPath, TInputSchema>>;
|
|
76
|
+
/**
|
|
77
|
+
* Create a RequestContext for server-side rendering contexts (no Request object)
|
|
78
|
+
*/
|
|
79
|
+
static fromSSRContext<TPath extends string, TInputSchema extends StandardSchemaV1 | undefined = undefined>(config: {
|
|
80
|
+
method: "GET";
|
|
81
|
+
path: TPath;
|
|
82
|
+
pathParams: ExtractPathParams<TPath>;
|
|
83
|
+
searchParams?: URLSearchParams;
|
|
84
|
+
} | {
|
|
85
|
+
method: Exclude<HTTPMethod, "GET">;
|
|
86
|
+
path: TPath;
|
|
87
|
+
pathParams: ExtractPathParams<TPath>;
|
|
88
|
+
searchParams?: URLSearchParams;
|
|
89
|
+
body: RequestBodyType;
|
|
90
|
+
inputSchema?: TInputSchema;
|
|
91
|
+
}): RequestInputContext<TPath, TInputSchema>;
|
|
92
|
+
/**
|
|
93
|
+
* The HTTP method as string (e.g., `GET`, `POST`)
|
|
94
|
+
*/
|
|
95
|
+
get method(): string;
|
|
96
|
+
/**
|
|
97
|
+
* The matched route path (e.g., `/users/:id`)
|
|
98
|
+
* @remarks `string`
|
|
99
|
+
*/
|
|
100
|
+
get path(): TPath;
|
|
101
|
+
/**
|
|
102
|
+
* Extracted path parameters as object (e.g., `{ id: '123' }`)
|
|
103
|
+
* @remarks `Record<string, string>`
|
|
104
|
+
*/
|
|
105
|
+
get pathParams(): ExtractPathParams<TPath>;
|
|
106
|
+
/**
|
|
107
|
+
* [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) object for query parameters
|
|
108
|
+
* @remarks `URLSearchParams`
|
|
109
|
+
*/
|
|
110
|
+
get query(): URLSearchParams;
|
|
111
|
+
/**
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
get rawBody(): RequestBodyType;
|
|
115
|
+
/**
|
|
116
|
+
* Input validation context (only if inputSchema is defined)
|
|
117
|
+
* @remarks `InputContext`
|
|
118
|
+
*/
|
|
119
|
+
get input(): TInputSchema extends undefined ? undefined : {
|
|
120
|
+
schema: TInputSchema;
|
|
121
|
+
valid: () => Promise<TInputSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TInputSchema> : unknown>;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/http/http-status.d.ts
|
|
126
|
+
/**
|
|
127
|
+
* @module
|
|
128
|
+
* HTTP Status utility.
|
|
129
|
+
*
|
|
130
|
+
* Modified from honojs/hono
|
|
131
|
+
* Original source: https://github.com/honojs/hono/blob/0e3db674ad3f40be215a55a18062dd8e387ce525/src/utils/http-status.ts
|
|
132
|
+
* License: MIT
|
|
133
|
+
* Date obtained: August 28 2025
|
|
134
|
+
* Copyright (c) 2021-present Yusuke Wada and Hono contributors
|
|
135
|
+
*
|
|
136
|
+
*/
|
|
137
|
+
type InfoStatusCode = 100 | 101 | 102 | 103;
|
|
138
|
+
type SuccessStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;
|
|
139
|
+
type DeprecatedStatusCode = 305 | 306;
|
|
140
|
+
type RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | DeprecatedStatusCode | 307 | 308;
|
|
141
|
+
type ClientErrorStatusCode = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
|
|
142
|
+
type ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
143
|
+
/**
|
|
144
|
+
* If you want to use an unofficial status, use `UnofficialStatusCode`.
|
|
145
|
+
*/
|
|
146
|
+
type StatusCode = InfoStatusCode | SuccessStatusCode | RedirectStatusCode | ClientErrorStatusCode | ServerErrorStatusCode;
|
|
147
|
+
type ContentlessStatusCode = 101 | 204 | 205 | 304;
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/api/internal/response-stream.d.ts
|
|
150
|
+
/**
|
|
151
|
+
* @module
|
|
152
|
+
* Stream utility.
|
|
153
|
+
*
|
|
154
|
+
* Modified from honojs/hono
|
|
155
|
+
* Original source: https://github.com/honojs/hono/blob/0e3db674ad3f40be215a55a18062dd8e387ce525/src/utils/stream.ts
|
|
156
|
+
* License: MIT
|
|
157
|
+
* Date obtained: August 28 2025
|
|
158
|
+
* Copyright (c) 2021-present Yusuke Wada and Hono contributors
|
|
159
|
+
*/
|
|
160
|
+
type Error$1<Message extends string> = {
|
|
161
|
+
__errorMessage: Message;
|
|
162
|
+
};
|
|
163
|
+
declare class ResponseStream<TArray> {
|
|
164
|
+
#private;
|
|
165
|
+
/**
|
|
166
|
+
* Whether the stream has been aborted.
|
|
167
|
+
*/
|
|
168
|
+
get aborted(): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Whether the stream has been closed normally.
|
|
171
|
+
*/
|
|
172
|
+
get closed(): boolean;
|
|
173
|
+
/**
|
|
174
|
+
* The readable stream that the response is piped to.
|
|
175
|
+
*/
|
|
176
|
+
get responseReadable(): ReadableStream;
|
|
177
|
+
constructor(writable: WritableStream, readable: ReadableStream);
|
|
178
|
+
writeRaw(input: Uint8Array | string): Promise<void>;
|
|
179
|
+
write(input: TArray extends (infer U)[] ? U : Error$1<"To use a streaming response, outputSchema must be an array.">): Promise<void>;
|
|
180
|
+
sleep(ms: number): Promise<unknown>;
|
|
181
|
+
close(): Promise<void>;
|
|
182
|
+
onAbort(listener: () => void | Promise<void>): void;
|
|
183
|
+
/**
|
|
184
|
+
* Abort the stream.
|
|
185
|
+
* You can call this method when stream is aborted by external event.
|
|
186
|
+
*/
|
|
187
|
+
abort(): void;
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/util/types-util.d.ts
|
|
191
|
+
type InferOr<T, U> = T extends NonNullable<StandardSchemaV1> ? StandardSchemaV1.InferOutput<T> : T extends undefined ? U : U;
|
|
192
|
+
type InferOrUnknown<T> = InferOr<T, unknown>;
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/api/request-output-context.d.ts
|
|
195
|
+
interface ResponseInit<T extends StatusCode = StatusCode> {
|
|
196
|
+
headers?: HeadersInit;
|
|
197
|
+
status?: T;
|
|
198
|
+
statusText?: string;
|
|
199
|
+
}
|
|
200
|
+
declare abstract class OutputContext<const TOutput, const TErrorCode extends string> {
|
|
201
|
+
/**
|
|
202
|
+
* Creates an error response.
|
|
203
|
+
*
|
|
204
|
+
* Shortcut for `throw new FragnoApiError(...)`
|
|
205
|
+
*/
|
|
206
|
+
error({
|
|
207
|
+
message,
|
|
208
|
+
code
|
|
209
|
+
}: {
|
|
210
|
+
message: string;
|
|
211
|
+
code: TErrorCode;
|
|
212
|
+
}, initOrStatus?: ResponseInit | StatusCode, headers?: HeadersInit): Response;
|
|
213
|
+
empty(initOrStatus?: ResponseInit<ContentlessStatusCode> | ContentlessStatusCode, headers?: HeadersInit): Response;
|
|
214
|
+
json(object: TOutput, initOrStatus?: ResponseInit | StatusCode, headers?: HeadersInit): Response;
|
|
215
|
+
jsonStream: (cb: (stream: ResponseStream<TOutput>) => void | Promise<void>, {
|
|
216
|
+
onError,
|
|
217
|
+
headers
|
|
218
|
+
}?: {
|
|
219
|
+
onError?: (error: Error, stream: ResponseStream<TOutput>) => void | Promise<void>;
|
|
220
|
+
headers?: HeadersInit;
|
|
221
|
+
}) => Response;
|
|
222
|
+
}
|
|
223
|
+
declare class RequestOutputContext<const TOutputSchema extends StandardSchemaV1 | undefined = undefined, const TErrorCode extends string = string> extends OutputContext<InferOrUnknown<TOutputSchema>, TErrorCode> {
|
|
224
|
+
#private;
|
|
225
|
+
constructor(outputSchema?: TOutputSchema);
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/api/error.d.ts
|
|
229
|
+
declare class FragnoApiError extends Error {
|
|
230
|
+
#private;
|
|
231
|
+
constructor({
|
|
232
|
+
message,
|
|
233
|
+
code
|
|
234
|
+
}: {
|
|
235
|
+
message: string;
|
|
236
|
+
code: string;
|
|
237
|
+
}, status: StatusCode);
|
|
238
|
+
get status(): StatusCode;
|
|
239
|
+
get code(): string;
|
|
240
|
+
toResponse(): Response;
|
|
241
|
+
}
|
|
242
|
+
declare class FragnoApiValidationError extends FragnoApiError {
|
|
243
|
+
#private;
|
|
244
|
+
constructor(message: string, issues: readonly StandardSchemaV1.Issue[]);
|
|
245
|
+
get issues(): readonly StandardSchemaV1.Issue[];
|
|
246
|
+
toResponse(): Response;
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/api/api.d.ts
|
|
250
|
+
type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
|
|
251
|
+
type NonGetHTTPMethod = Exclude<HTTPMethod, "GET">;
|
|
252
|
+
type PathError<T extends string, TMessage extends string> = T & [`Error: ${TMessage}`];
|
|
253
|
+
/**
|
|
254
|
+
* A valid path string that:
|
|
255
|
+
* - Is non-empty
|
|
256
|
+
* - Starts with "/"
|
|
257
|
+
* - Is not just "/"
|
|
258
|
+
* - Does not end with "/"
|
|
259
|
+
*/
|
|
260
|
+
type ValidPath<T extends string = string> = T extends `/${infer Rest}` ? Rest extends "" ? PathError<T, "Path cannot be just '/'."> : T extends `${string}/` ? PathError<T, "Path cannot end with '/'."> : T : PathError<T, "Path must start with '/'.">;
|
|
261
|
+
interface FragnoRouteConfig<TMethod extends HTTPMethod, TPath extends string, TInputSchema extends StandardSchemaV1 | undefined, TOutputSchema extends StandardSchemaV1 | undefined, TErrorCode extends string = string, TQueryParameters extends string = string> {
|
|
262
|
+
method: TMethod;
|
|
263
|
+
path: TPath;
|
|
264
|
+
inputSchema?: TInputSchema;
|
|
265
|
+
outputSchema?: TOutputSchema;
|
|
266
|
+
errorCodes?: readonly TErrorCode[];
|
|
267
|
+
queryParameters?: readonly TQueryParameters[];
|
|
268
|
+
handler(inputCtx: RequestInputContext<TPath, TInputSchema>, outputCtx: RequestOutputContext<TOutputSchema, TErrorCode>): Promise<Response>;
|
|
269
|
+
}
|
|
270
|
+
declare function addRoute<TMethod extends HTTPMethod, TPath extends string, TOutputSchema extends StandardSchemaV1 | undefined, TErrorCode extends string = string, TQueryParameters extends string = string>(route: FragnoRouteConfig<TMethod, ValidPath<TPath>, undefined, TOutputSchema, TErrorCode, TQueryParameters> & {
|
|
271
|
+
inputSchema?: undefined;
|
|
272
|
+
}): FragnoRouteConfig<TMethod, TPath, undefined, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
273
|
+
declare function addRoute<TMethod extends HTTPMethod, TPath extends string, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1 | undefined, TErrorCode extends string = string, TQueryParameters extends string = string>(route: FragnoRouteConfig<TMethod, ValidPath<TPath>, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters> & {
|
|
274
|
+
inputSchema: TInputSchema;
|
|
275
|
+
}): FragnoRouteConfig<TMethod, TPath, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters>;
|
|
276
|
+
//#endregion
|
|
277
|
+
export { ExtractPathParamsOrWiden, FragnoApiError, FragnoApiValidationError, FragnoRouteConfig, HTTPMethod, HasPathParams, InferOr, MaybeExtractPathParamsOrWiden, NonGetHTTPMethod, OutputContext, QueryParamsHint, RequestBodyType, StatusCode, ValidPath, addRoute };
|
|
278
|
+
//# sourceMappingURL=api-CBDGZiLC.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-CBDGZiLC.d.ts","names":[],"sources":["../src/api/internal/path.ts","../src/api/request-input-context.ts","../src/http/http-status.ts","../src/api/internal/response-stream.ts","../src/util/types-util.ts","../src/api/request-output-context.ts","../src/api/error.ts","../src/api/api.ts"],"sourcesContent":[],"mappings":";;;KACK,8BAA8B,2CAC/B,mBACE,UAAU,SACT,UAAU,UAAU,SACvB,qBAEG;KAGF,iCAAiC,6BAClC,OACA,+BACE,OACA;KAKD,yDAAyD,oBAlBzD,KAAA,MAAA,EAAS,GAAA,KAAA,KAAA,IAsBV,KAt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,CAAA,GAAA;EAAA,WAAA,CAAA,EAAA,SAAA;IO0C3B,iBP1C2D,CO0CzC,OP1CyC,EO0ChC,KP1CgC,EAAA,SAAA,EO0Cd,aP1Cc,EO0CC,UP1CD,EO0Ca,gBP1Cb,CAAA;AAI1D,iBOyCY,QPzCZ,CAAA,gBO0Cc,UP1Cd,EAAA,cAAA,MAAA,EAAA,qBO4CmB,gBP5CnB,EAAA,sBO6CoB,gBP7CpB,GAAA,SAAA,EAAA,mBAAA,MAAA,GAAA,MAAA,EAAA,yBAAA,MAAA,GAAA,MAAA,CAAA,CAAA,KAAA,EOiDK,iBPjDL,COkDA,OPlDA,EOmDA,SPnDA,COmDU,KPnDV,CAAA,EOoDA,YPpDA,EOqDA,aPrDA,EOsDA,UPtDA,EOuDA,gBPvDA,CAAA,GAAA;aACE,EOwDW,YPxDX;IO0DH,iBPzDkB,COyDA,OPzDA,EOyDS,KPzDT,EOyDgB,YPzDhB,EOyD8B,aPzD9B,EOyD6C,UPzD7C,EOyDyD,gBPzDzD,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/api/error.ts
|
|
2
|
+
var FragnoApiError = class extends Error {
|
|
3
|
+
#status;
|
|
4
|
+
#code;
|
|
5
|
+
constructor({ message, code }, status) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "FragnoApiError";
|
|
8
|
+
this.#status = status;
|
|
9
|
+
this.#code = code;
|
|
10
|
+
}
|
|
11
|
+
get status() {
|
|
12
|
+
return this.#status;
|
|
13
|
+
}
|
|
14
|
+
get code() {
|
|
15
|
+
return this.#code;
|
|
16
|
+
}
|
|
17
|
+
toResponse() {
|
|
18
|
+
return Response.json({
|
|
19
|
+
message: this.message,
|
|
20
|
+
code: this.code
|
|
21
|
+
}, { status: this.status });
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var FragnoApiValidationError = class extends FragnoApiError {
|
|
25
|
+
#issues;
|
|
26
|
+
constructor(message, issues) {
|
|
27
|
+
super({
|
|
28
|
+
message,
|
|
29
|
+
code: "FRAGNO_VALIDATION_ERROR"
|
|
30
|
+
}, 400);
|
|
31
|
+
this.name = "FragnoApiValidationError";
|
|
32
|
+
this.#issues = issues;
|
|
33
|
+
}
|
|
34
|
+
get issues() {
|
|
35
|
+
return this.#issues;
|
|
36
|
+
}
|
|
37
|
+
toResponse() {
|
|
38
|
+
return Response.json({
|
|
39
|
+
message: this.message,
|
|
40
|
+
issues: this.#issues,
|
|
41
|
+
code: this.code
|
|
42
|
+
}, { status: this.status });
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/api/api.ts
|
|
48
|
+
function addRoute(route) {
|
|
49
|
+
return route;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { FragnoApiError, FragnoApiValidationError, addRoute };
|
|
54
|
+
//# sourceMappingURL=api-DgHfYjq2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-DgHfYjq2.js","names":["#status","#code","#issues"],"sources":["../src/api/error.ts","../src/api/api.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { StatusCode } from \"../http/http-status\";\n\nexport class FragnoApiError extends Error {\n readonly #status: StatusCode;\n readonly #code: string;\n\n constructor({ message, code }: { message: string; code: string }, status: StatusCode) {\n super(message);\n this.name = \"FragnoApiError\";\n this.#status = status;\n this.#code = code;\n }\n\n get status() {\n return this.#status;\n }\n\n get code() {\n return this.#code;\n }\n\n toResponse() {\n return Response.json({ message: this.message, code: this.code }, { status: this.status });\n }\n}\n\nexport class FragnoApiValidationError extends FragnoApiError {\n #issues: readonly StandardSchemaV1.Issue[];\n\n constructor(message: string, issues: readonly StandardSchemaV1.Issue[]) {\n super({ message, code: \"FRAGNO_VALIDATION_ERROR\" }, 400);\n this.name = \"FragnoApiValidationError\";\n this.#issues = issues;\n }\n\n get issues() {\n return this.#issues;\n }\n\n override toResponse() {\n return Response.json(\n { message: this.message, issues: this.#issues, code: this.code },\n { status: this.status },\n );\n }\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { RequestInputContext } from \"./request-input-context\";\nimport type { RequestOutputContext } from \"./request-output-context\";\n\nexport type HTTPMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\" | \"HEAD\" | \"OPTIONS\";\nexport type NonGetHTTPMethod = Exclude<HTTPMethod, \"GET\">;\n\n// Helper type to create branded error messages that are still assignable to string\ntype PathError<T extends string, TMessage extends string> = T & [`Error: ${TMessage}`];\n\n/**\n * A valid path string that:\n * - Is non-empty\n * - Starts with \"/\"\n * - Is not just \"/\"\n * - Does not end with \"/\"\n */\nexport type ValidPath<T extends string = string> = T extends `/${infer Rest}`\n ? Rest extends \"\"\n ? PathError<T, \"Path cannot be just '/'.\"> // Excludes \"/\"\n : T extends `${string}/`\n ? PathError<T, \"Path cannot end with '/'.\"> // Excludes paths ending with \"/\"\n : T\n : PathError<T, \"Path must start with '/'.\">; // Excludes paths not starting with \"/\"\n\nexport interface FragnoRouteConfig<\n TMethod extends HTTPMethod,\n TPath extends string,\n TInputSchema extends StandardSchemaV1 | undefined,\n TOutputSchema extends StandardSchemaV1 | undefined,\n TErrorCode extends string = string,\n TQueryParameters extends string = string,\n> {\n method: TMethod;\n path: TPath;\n inputSchema?: TInputSchema;\n outputSchema?: TOutputSchema;\n errorCodes?: readonly TErrorCode[];\n queryParameters?: readonly TQueryParameters[];\n handler(\n inputCtx: RequestInputContext<TPath, TInputSchema>,\n outputCtx: RequestOutputContext<TOutputSchema, TErrorCode>,\n ): Promise<Response>;\n}\n\n// Overload for routes without inputSchema\nexport function addRoute<\n TMethod extends HTTPMethod,\n TPath extends string,\n TOutputSchema extends StandardSchemaV1 | undefined,\n TErrorCode extends string = string,\n TQueryParameters extends string = string,\n>(\n route: FragnoRouteConfig<\n TMethod,\n ValidPath<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 addRoute<\n TMethod extends HTTPMethod,\n TPath extends string,\n TInputSchema extends StandardSchemaV1,\n TOutputSchema extends StandardSchemaV1 | undefined,\n TErrorCode extends string = string,\n TQueryParameters extends string = string,\n>(\n route: FragnoRouteConfig<\n TMethod,\n ValidPath<TPath>,\n TInputSchema,\n TOutputSchema,\n TErrorCode,\n TQueryParameters\n > & {\n inputSchema: TInputSchema;\n },\n): FragnoRouteConfig<TMethod, TPath, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters>;\n\n// Implementation\nexport function addRoute<\n TMethod extends HTTPMethod,\n TPath extends string,\n TInputSchema extends StandardSchemaV1 | undefined,\n TOutputSchema extends StandardSchemaV1 | undefined,\n TErrorCode extends string = string,\n TQueryParameters extends string = string,\n>(\n route: FragnoRouteConfig<\n TMethod,\n ValidPath<TPath>,\n TInputSchema,\n TOutputSchema,\n TErrorCode,\n TQueryParameters\n >,\n): FragnoRouteConfig<TMethod, TPath, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters> {\n return route;\n}\n\nexport { FragnoApiError, FragnoApiValidationError } from \"./error\";\n"],"mappings":";AAGA,IAAa,iBAAb,cAAoC,MAAM;CACxC,CAASA;CACT,CAASC;CAET,YAAY,EAAE,SAAS,QAA2C,QAAoB;AACpF,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,QAAKD,SAAU;AACf,QAAKC,OAAQ;;CAGf,IAAI,SAAS;AACX,SAAO,MAAKD;;CAGd,IAAI,OAAO;AACT,SAAO,MAAKC;;CAGd,aAAa;AACX,SAAO,SAAS,KAAK;GAAE,SAAS,KAAK;GAAS,MAAM,KAAK;GAAM,EAAE,EAAE,QAAQ,KAAK,QAAQ,CAAC;;;AAI7F,IAAa,2BAAb,cAA8C,eAAe;CAC3D;CAEA,YAAY,SAAiB,QAA2C;AACtE,QAAM;GAAE;GAAS,MAAM;GAA2B,EAAE,IAAI;AACxD,OAAK,OAAO;AACZ,QAAKC,SAAU;;CAGjB,IAAI,SAAS;AACX,SAAO,MAAKA;;CAGd,AAAS,aAAa;AACpB,SAAO,SAAS,KACd;GAAE,SAAS,KAAK;GAAS,QAAQ,MAAKA;GAAS,MAAM,KAAK;GAAM,EAChE,EAAE,QAAQ,KAAK,QAAQ,CACxB;;;;;;ACyCL,SAAgB,SAQd,OAQ8F;AAC9F,QAAO"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import "../api-CBDGZiLC.js";
|
|
2
|
+
import { CacheLine, ClientBuilder, CreateHookOptions, ExtractGetRoutePaths, ExtractGetRoutes, ExtractNonGetRoutePaths, ExtractOutputSchemaForPath, ExtractRouteByPath, ExtractRoutePath, FragnoClientApiError, FragnoClientError, FragnoClientFetchAbortError, FragnoClientFetchError, FragnoClientFetchNetworkError, FragnoClientHookData, FragnoClientMutatorData, FragnoClientUnknownApiError, FragnoErrorOptions, FragnoStoreData, HasGetRoutes, IsValidGetRoutePath, ObjectContainingStoreField, ValidateGetRoutePath, buildUrl, createClientBuilder, getCacheKey, isGetHook, isMutatorHook, isStore } from "../client-XFdAy-IQ.js";
|
|
3
|
+
export { CacheLine, ClientBuilder, CreateHookOptions, ExtractGetRoutePaths, ExtractGetRoutes, ExtractNonGetRoutePaths, ExtractOutputSchemaForPath, ExtractRouteByPath, ExtractRoutePath, FragnoClientApiError, FragnoClientError, FragnoClientFetchAbortError, FragnoClientFetchError, FragnoClientFetchNetworkError, FragnoClientHookData, FragnoClientMutatorData, FragnoClientUnknownApiError, FragnoErrorOptions, FragnoStoreData, HasGetRoutes, IsValidGetRoutePath, ObjectContainingStoreField, ValidateGetRoutePath, buildUrl, createClientBuilder, getCacheKey, isGetHook, isMutatorHook, isStore };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import "../api-DgHfYjq2.js";
|
|
2
|
+
import "../route-Bp6eByhz.js";
|
|
3
|
+
import { ClientBuilder, FragnoClientApiError, FragnoClientError, FragnoClientFetchAbortError, FragnoClientFetchError, FragnoClientFetchNetworkError, FragnoClientUnknownApiError, buildUrl, createClientBuilder, getCacheKey, isGetHook, isMutatorHook, isStore } from "../client-DWjxKDnE.js";
|
|
4
|
+
import "../ssr-tJHqcNSw.js";
|
|
5
|
+
|
|
6
|
+
export { ClientBuilder, FragnoClientApiError, FragnoClientError, FragnoClientFetchAbortError, FragnoClientFetchError, FragnoClientFetchNetworkError, FragnoClientUnknownApiError, buildUrl, createClientBuilder, getCacheKey, isGetHook, isMutatorHook, isStore };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { InferOr, MaybeExtractPathParamsOrWiden, NonGetHTTPMethod, QueryParamsHint } from "../api-CBDGZiLC.js";
|
|
2
|
+
import { FragnoClientError, FragnoClientHookData, FragnoClientMutatorData, FragnoStoreData } from "../client-XFdAy-IQ.js";
|
|
3
|
+
import { ReadableAtom } from "nanostores";
|
|
4
|
+
import { Readable } from "svelte/store";
|
|
5
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
|
|
7
|
+
//#region src/client/client.svelte.d.ts
|
|
8
|
+
|
|
9
|
+
type FragnoSvelteHook<_TMethod extends "GET", TPath extends string, TOutputSchema extends StandardSchemaV1, TErrorCode extends string, TQueryParameters extends string> = (args?: {
|
|
10
|
+
path?: MaybeExtractPathParamsOrWiden<TPath, string | Readable<string> | ReadableAtom<string>> | (() => string);
|
|
11
|
+
query?: QueryParamsHint<TQueryParameters, string | Readable<string> | ReadableAtom<string> | (() => string)>;
|
|
12
|
+
}) => {
|
|
13
|
+
data: Readable<InferOr<TOutputSchema, undefined>>;
|
|
14
|
+
loading: Readable<boolean>;
|
|
15
|
+
error: Readable<FragnoClientError<TErrorCode[number]> | undefined>;
|
|
16
|
+
};
|
|
17
|
+
type FragnoSvelteMutator<_TMethod extends NonGetHTTPMethod, TPath extends string, TInputSchema extends StandardSchemaV1 | undefined, TOutputSchema extends StandardSchemaV1 | undefined, TErrorCode extends string, TQueryParameters extends string> = () => {
|
|
18
|
+
mutate: (args: {
|
|
19
|
+
body?: InferOr<TInputSchema, undefined>;
|
|
20
|
+
path?: MaybeExtractPathParamsOrWiden<TPath, string | Readable<string> | ReadableAtom<string> | (() => string)>;
|
|
21
|
+
query?: QueryParamsHint<TQueryParameters, string | Readable<string> | ReadableAtom<string> | (() => string)>;
|
|
22
|
+
}) => Promise<InferOr<TOutputSchema, undefined>>;
|
|
23
|
+
loading: Readable<boolean | undefined>;
|
|
24
|
+
error: Readable<FragnoClientError<TErrorCode[number]> | undefined>;
|
|
25
|
+
data: Readable<InferOr<TOutputSchema, undefined>>;
|
|
26
|
+
};
|
|
27
|
+
declare function readableToAtom<T>(value: Readable<T>): ReadableAtom<T>;
|
|
28
|
+
declare function runeToAtom<T>(value: () => T): ReadableAtom<T>;
|
|
29
|
+
declare function createSvelteStore<T extends object>(hook: FragnoStoreData<T>): T;
|
|
30
|
+
declare function useFragno<T extends Record<string, unknown>>(clientObj: T): { [K in keyof T]: T[K] extends FragnoClientHookData<"GET", infer TPath, infer TOutputSchema, infer TErrorCode, infer TQueryParameters> ? FragnoSvelteHook<"GET", TPath, TOutputSchema, TErrorCode, TQueryParameters> : T[K] extends FragnoClientMutatorData<infer M, infer TPath, infer TInputSchema, infer TOutputSchema, infer TErrorCode, infer TQueryParameters> ? FragnoSvelteMutator<M, TPath, TInputSchema, TOutputSchema, TErrorCode, TQueryParameters> : T[K] extends FragnoStoreData<infer TStoreObj> ? TStoreObj : T[K] };
|
|
31
|
+
//#endregion
|
|
32
|
+
export { FragnoSvelteHook, FragnoSvelteMutator, createSvelteStore, readableToAtom, runeToAtom, useFragno };
|
|
33
|
+
//# sourceMappingURL=client.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.svelte.d.ts","names":[],"sources":["../../src/client/client.svelte.ts"],"sourcesContent":[],"mapp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AA,EAAA,KAAA,cAAA,EAAA,KAAA,WAAA,EAAA,KAAA,iBAAA,CAAA,GAgNhB,mBAhNgB,CAgNI,CAhNJ,EAgNO,KAhNP,EAgNc,YAhNd,EAgN4B,aAhN5B,EAgN2C,UAhN3C,EAgNuD,gBAhNvD,CAAA,GAiNhB,CAjNgB,CAiNd,CAjNc,CAAA,SAiNH,eAjNG,CAAA,KAAA,UAAA,CAAA,GAkNd,SAlNc,GAmNd,CAnNc,CAmNZ,CAnNY,CAAA"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import "../api-DgHfYjq2.js";
|
|
2
|
+
import "../route-Bp6eByhz.js";
|
|
3
|
+
import { isGetHook, isMutatorHook, isStore } from "../client-DWjxKDnE.js";
|
|
4
|
+
import "../ssr-tJHqcNSw.js";
|
|
5
|
+
import { atom } from "nanostores";
|
|
6
|
+
import { get, writable } from "svelte/store";
|
|
7
|
+
import { onDestroy } from "svelte";
|
|
8
|
+
|
|
9
|
+
//#region src/client/client.svelte.ts
|
|
10
|
+
function isReadable(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && "subscribe" in value;
|
|
12
|
+
}
|
|
13
|
+
function isCallable(value) {
|
|
14
|
+
return typeof value === "function";
|
|
15
|
+
}
|
|
16
|
+
function readableToAtom(value) {
|
|
17
|
+
const a = atom(get(value));
|
|
18
|
+
value.subscribe((newVal) => {
|
|
19
|
+
a.set(newVal);
|
|
20
|
+
});
|
|
21
|
+
return a;
|
|
22
|
+
}
|
|
23
|
+
function runeToAtom(value) {
|
|
24
|
+
const a = atom(value());
|
|
25
|
+
$effect(() => {
|
|
26
|
+
a.set(value());
|
|
27
|
+
});
|
|
28
|
+
return a;
|
|
29
|
+
}
|
|
30
|
+
function createSvelteHook(hook) {
|
|
31
|
+
return ({ path, query } = {}) => {
|
|
32
|
+
const pathParams = {};
|
|
33
|
+
const queryParams = {};
|
|
34
|
+
for (const [key, value] of Object.entries(path ?? {})) {
|
|
35
|
+
const v = value;
|
|
36
|
+
if (isCallable(v)) pathParams[key] = runeToAtom(v);
|
|
37
|
+
else pathParams[key] = isReadable(v) ? readableToAtom(v) : v;
|
|
38
|
+
}
|
|
39
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
40
|
+
const v = value;
|
|
41
|
+
if (isCallable(v)) queryParams[key] = runeToAtom(v);
|
|
42
|
+
else queryParams[key] = isReadable(v) ? readableToAtom(v) : v;
|
|
43
|
+
}
|
|
44
|
+
const store = hook.store({
|
|
45
|
+
path: pathParams,
|
|
46
|
+
query: queryParams
|
|
47
|
+
});
|
|
48
|
+
const data = writable(void 0);
|
|
49
|
+
const loading = writable(false);
|
|
50
|
+
const error = writable(void 0);
|
|
51
|
+
const unsubscribe = store.subscribe((updatedStoreValue) => {
|
|
52
|
+
data.set(updatedStoreValue.data);
|
|
53
|
+
loading.set(updatedStoreValue.loading);
|
|
54
|
+
error.set(updatedStoreValue.error);
|
|
55
|
+
});
|
|
56
|
+
onDestroy(() => {
|
|
57
|
+
unsubscribe();
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
data,
|
|
61
|
+
loading,
|
|
62
|
+
error
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function createSvelteMutator(hook) {
|
|
67
|
+
return () => {
|
|
68
|
+
const data = writable(void 0);
|
|
69
|
+
const loading = writable(void 0);
|
|
70
|
+
const error = writable(void 0);
|
|
71
|
+
const unsubscribe = hook.mutatorStore.subscribe((storeValue) => {
|
|
72
|
+
data.set(storeValue.data);
|
|
73
|
+
loading.set(storeValue.loading);
|
|
74
|
+
error.set(storeValue.error);
|
|
75
|
+
});
|
|
76
|
+
onDestroy(() => {
|
|
77
|
+
unsubscribe();
|
|
78
|
+
});
|
|
79
|
+
const mutate = async (args) => {
|
|
80
|
+
const { body, path, query } = args;
|
|
81
|
+
const pathParams = {};
|
|
82
|
+
const queryParams = {};
|
|
83
|
+
for (const [key, value] of Object.entries(path ?? {})) {
|
|
84
|
+
const v = value;
|
|
85
|
+
pathParams[key] = isReadable(v) ? readableToAtom(v) : v;
|
|
86
|
+
}
|
|
87
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
88
|
+
const v = value;
|
|
89
|
+
queryParams[key] = isReadable(v) ? readableToAtom(v) : v;
|
|
90
|
+
}
|
|
91
|
+
return hook.mutatorStore.mutate({
|
|
92
|
+
body,
|
|
93
|
+
path: pathParams,
|
|
94
|
+
query: queryParams
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
mutate,
|
|
99
|
+
loading,
|
|
100
|
+
error,
|
|
101
|
+
data
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function createSvelteStore(hook) {
|
|
106
|
+
return hook.obj;
|
|
107
|
+
}
|
|
108
|
+
function useFragno(clientObj) {
|
|
109
|
+
const result = {};
|
|
110
|
+
for (const key in clientObj) {
|
|
111
|
+
if (!Object.prototype.hasOwnProperty.call(clientObj, key)) continue;
|
|
112
|
+
const hook = clientObj[key];
|
|
113
|
+
if (isGetHook(hook)) result[key] = createSvelteHook(hook);
|
|
114
|
+
else if (isMutatorHook(hook)) result[key] = createSvelteMutator(hook);
|
|
115
|
+
else if (isStore(hook)) result[key] = createSvelteStore(hook);
|
|
116
|
+
else result[key] = hook;
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
export { createSvelteStore, readableToAtom, runeToAtom, useFragno };
|
|
123
|
+
//# sourceMappingURL=client.svelte.js.map
|