@hulla/api-tanstack-start 0.0.0-stage → 2.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/dist/index.d.ts +33 -0
- package/dist/index.js +44 -0
- package/package.json +47 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { FetchServerErrorInput } from "@hulla/api/fetch";
|
|
2
|
+
import { Awaitable, ServerAdapter, ServerContextInput, ServerExecutableFor } from "@hulla/api/server";
|
|
3
|
+
import { Contract } from "@hulla/api";
|
|
4
|
+
//#region src/server.d.ts
|
|
5
|
+
type TanStackStartRouteParams = Readonly<Record<string, string | undefined>>;
|
|
6
|
+
type TanStackStartHandlerInput<StartContext = unknown, Params extends TanStackStartRouteParams = TanStackStartRouteParams> = {
|
|
7
|
+
readonly context: StartContext;
|
|
8
|
+
readonly params: Params;
|
|
9
|
+
readonly request: Request;
|
|
10
|
+
};
|
|
11
|
+
type TanStackStartRouteHandler<StartContext = unknown, Params extends TanStackStartRouteParams = TanStackStartRouteParams> = (input: TanStackStartHandlerInput<StartContext, Params>) => Promise<Response>;
|
|
12
|
+
type TanStackStartAdapterContext<StartContext, Params extends TanStackStartRouteParams> = {
|
|
13
|
+
readonly request: Request;
|
|
14
|
+
readonly startContext: StartContext;
|
|
15
|
+
readonly startParams: Params;
|
|
16
|
+
};
|
|
17
|
+
type TanStackStartServerErrorInput<StartContext = unknown, Params extends TanStackStartRouteParams = TanStackStartRouteParams> = Omit<FetchServerErrorInput<TanStackStartHandlerInput<StartContext, Params>>, 'handlerContext'> & {
|
|
18
|
+
readonly startContext: StartContext;
|
|
19
|
+
readonly startParams: Params;
|
|
20
|
+
};
|
|
21
|
+
type TanStackStartServerOptions<StartContext = unknown, Params extends TanStackStartRouteParams = TanStackStartRouteParams> = {
|
|
22
|
+
readonly onError?: ((input: TanStackStartServerErrorInput<StartContext, Params>) => Awaitable<Response | undefined | void>) | undefined;
|
|
23
|
+
};
|
|
24
|
+
type TanStackStartContextInput<ContractType extends Contract = Contract, StartContext = unknown, Params extends TanStackStartRouteParams = TanStackStartRouteParams> = ServerContextInput<ContractType> & TanStackStartAdapterContext<StartContext, Params>;
|
|
25
|
+
type TanStackStartRouteMethod = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
|
|
26
|
+
type TanStackStartRouteHandlers<StartContext = unknown, Params extends TanStackStartRouteParams = TanStackStartRouteParams> = Readonly<Partial<Record<TanStackStartRouteMethod, TanStackStartRouteHandler<StartContext, Params>>>>;
|
|
27
|
+
type TanStackStartAdapter<StartContext = unknown, Params extends TanStackStartRouteParams = TanStackStartRouteParams> = ServerAdapter<'tanstack-start', TanStackStartAdapterContext<StartContext, Params>> & {
|
|
28
|
+
readonly mount: <const ContractType extends Contract, const Context extends object>(implementation: ServerExecutableFor<ContractType, Context, 'tanstack-start', TanStackStartAdapterContext<StartContext, Params>>, options?: TanStackStartServerOptions<StartContext, Params>) => TanStackStartRouteHandlers<StartContext, Params>;
|
|
29
|
+
};
|
|
30
|
+
/** Creates a TanStack Start adapter with native context and mounting operations. */
|
|
31
|
+
declare function tanStackStartAdapter<StartContext = unknown, Params extends TanStackStartRouteParams = TanStackStartRouteParams>(options?: TanStackStartServerOptions<StartContext, Params>): TanStackStartAdapter<StartContext, Params>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { type TanStackStartAdapter, type TanStackStartContextInput, type TanStackStartHandlerInput, type TanStackStartRouteHandler, type TanStackStartRouteHandlers, type TanStackStartRouteMethod, type TanStackStartRouteParams, type TanStackStartServerErrorInput, type TanStackStartServerOptions, tanStackStartAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createAdapterRuntime } from "@hulla/api/adapters";
|
|
2
|
+
import { createFetchHandler } from "@hulla/api/fetch";
|
|
3
|
+
import { createServerAdapter } from "@hulla/api/server";
|
|
4
|
+
|
|
5
|
+
//#region src/server.ts
|
|
6
|
+
/** Creates the method-handler map mounted by a TanStack Start wildcard server route. */
|
|
7
|
+
function createServerRouteHandlers(implementation, options) {
|
|
8
|
+
const configured = options ?? {};
|
|
9
|
+
const runtime = createAdapterRuntime(implementation);
|
|
10
|
+
const unsupported = runtime.routes.filter((route) => route.method === "QUERY");
|
|
11
|
+
if (unsupported.length > 0) throw new TypeError(`TanStack Start server routes do not support QUERY routes: ${unsupported.map((route) => route.key.join(".")).join(", ")}`);
|
|
12
|
+
const fetchHandler = createFetchHandler(implementation, {
|
|
13
|
+
contextAdapter: "tanstack-start",
|
|
14
|
+
contextInput: (_request, input) => ({
|
|
15
|
+
startContext: input.context,
|
|
16
|
+
startParams: input.params
|
|
17
|
+
}),
|
|
18
|
+
...configured.onError === void 0 ? {} : { onError: ({ handlerContext, ...input }) => configured.onError?.({
|
|
19
|
+
...input,
|
|
20
|
+
startContext: handlerContext.context,
|
|
21
|
+
startParams: handlerContext.params
|
|
22
|
+
}) }
|
|
23
|
+
});
|
|
24
|
+
const handler = (input) => fetchHandler(input.request, input);
|
|
25
|
+
const handlers = {};
|
|
26
|
+
for (const route of runtime.routes) handlers[route.method] = handler;
|
|
27
|
+
return handlers;
|
|
28
|
+
}
|
|
29
|
+
let tanStackStartAdapterValue;
|
|
30
|
+
function createTanStackStartAdapter(defaults) {
|
|
31
|
+
return createServerAdapter("tanstack-start", { mount: (implementation, options) => createServerRouteHandlers(implementation, options === void 0 ? defaults : {
|
|
32
|
+
...defaults,
|
|
33
|
+
...options
|
|
34
|
+
}) });
|
|
35
|
+
}
|
|
36
|
+
/** Creates a TanStack Start adapter with native context and mounting operations. */
|
|
37
|
+
function tanStackStartAdapter(options) {
|
|
38
|
+
if (options !== void 0) return createTanStackStartAdapter({ ...options });
|
|
39
|
+
tanStackStartAdapterValue ??= createTanStackStartAdapter({});
|
|
40
|
+
return tanStackStartAdapterValue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { tanStackStartAdapter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hulla/api-tanstack-start",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "TanStack Start server route integration for @hulla/api",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/hulladev/api.git",
|
|
9
|
+
"directory": "packages/tanstack-start"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public",
|
|
24
|
+
"registry": "https://registry.npmjs.org/"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsdown",
|
|
28
|
+
"clean": "rm -rf dist coverage",
|
|
29
|
+
"test": "bun run build && vitest run",
|
|
30
|
+
"test:coverage": "bun run build && vitest run --coverage",
|
|
31
|
+
"test:watch": "vitest",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@hulla/api": "2.0.1",
|
|
36
|
+
"@tanstack/react-router": "^1.170.32",
|
|
37
|
+
"@tanstack/react-start": "^1.168.49",
|
|
38
|
+
"@types/react": "^19.2.18",
|
|
39
|
+
"@types/react-dom": "^19.2.5",
|
|
40
|
+
"react": "^19.2.8",
|
|
41
|
+
"react-dom": "^19.2.8",
|
|
42
|
+
"vite": "^8.2.2",
|
|
43
|
+
"zod": "^4.4.3"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@hulla/api": "^2.0.1",
|
|
47
|
+
"@tanstack/react-start": "^1.160.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/README.md
DELETED