@tanstack/start-fn-stubs 1.161.6 → 1.162.0
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.
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
//#region src/createIsomorphicFn.ts
|
|
2
2
|
function createIsomorphicFn() {
|
|
3
|
-
|
|
3
|
+
return createRuntimeFn(() => void 0);
|
|
4
|
+
}
|
|
5
|
+
function createRuntimeFn(fn, serverImpl) {
|
|
4
6
|
return Object.assign(fn, {
|
|
5
|
-
server: () =>
|
|
6
|
-
|
|
7
|
+
server: (nextServerImpl) => {
|
|
8
|
+
return createRuntimeFn(nextServerImpl, nextServerImpl);
|
|
9
|
+
},
|
|
10
|
+
client: (clientImpl) => {
|
|
11
|
+
return createRuntimeFn(serverImpl ?? clientImpl, serverImpl);
|
|
12
|
+
}
|
|
7
13
|
});
|
|
8
14
|
}
|
|
9
15
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createIsomorphicFn.js","names":[],"sources":["../../src/createIsomorphicFn.ts"],"sourcesContent":["// a function that can have different implementations on the client and server.\n// implementations not provided will default to a no-op function.\n\nexport type IsomorphicFn<\n TArgs extends Array<any> = [],\n TServer = undefined,\n TClient = undefined,\n> = (...args: TArgs) => TServer | TClient\n\nexport interface ServerOnlyFn<\n TArgs extends Array<any>,\n TServer,\n> extends IsomorphicFn<TArgs, TServer> {\n client: <TClient>(\n clientImpl: (...args: TArgs) => TClient,\n ) => IsomorphicFn<TArgs, TServer, TClient>\n}\n\nexport interface ClientOnlyFn<\n TArgs extends Array<any>,\n TClient,\n> extends IsomorphicFn<TArgs, undefined, TClient> {\n server: <TServer>(\n serverImpl: (...args: TArgs) => TServer,\n ) => IsomorphicFn<TArgs, TServer, TClient>\n}\n\nexport interface IsomorphicFnBase {\n server: <TArgs extends Array<any>, TServer>(\n serverImpl: (...args: TArgs) => TServer,\n ) => ServerOnlyFn<TArgs, TServer>\n client: <TArgs extends Array<any>, TClient>(\n clientImpl: (...args: TArgs) => TClient,\n ) => ClientOnlyFn<TArgs, TClient>\n}\n\n//
|
|
1
|
+
{"version":3,"file":"createIsomorphicFn.js","names":[],"sources":["../../src/createIsomorphicFn.ts"],"sourcesContent":["// a function that can have different implementations on the client and server.\n// implementations not provided will default to a no-op function.\n\nexport type IsomorphicFn<\n TArgs extends Array<any> = [],\n TServer = undefined,\n TClient = undefined,\n> = (...args: TArgs) => TServer | TClient\n\nexport interface ServerOnlyFn<\n TArgs extends Array<any>,\n TServer,\n> extends IsomorphicFn<TArgs, TServer> {\n client: <TClient>(\n clientImpl: (...args: TArgs) => TClient,\n ) => IsomorphicFn<TArgs, TServer, TClient>\n}\n\nexport interface ClientOnlyFn<\n TArgs extends Array<any>,\n TClient,\n> extends IsomorphicFn<TArgs, undefined, TClient> {\n server: <TServer>(\n serverImpl: (...args: TArgs) => TServer,\n ) => IsomorphicFn<TArgs, TServer, TClient>\n}\n\nexport interface IsomorphicFnBase {\n server: <TArgs extends Array<any>, TServer>(\n serverImpl: (...args: TArgs) => TServer,\n ) => ServerOnlyFn<TArgs, TServer>\n client: <TArgs extends Array<any>, TClient>(\n clientImpl: (...args: TArgs) => TClient,\n ) => ClientOnlyFn<TArgs, TClient>\n}\n\n// The Start compiler normally rewrites createIsomorphicFn() chains before they\n// run. Some package tests/build steps execute this stub uncompiled though, for\n// example while Vite loads server-side modules during a build.\n//\n// In those uncompiled contexts we need a real callable fallback, not just a\n// chain-shaped object. These contexts are server-side, so once a .server()\n// implementation is registered we keep using it even if .client() is chained\n// later. Client bundles still get the correct client/no-op implementation\n// because the compiler rewrites the original call chain before runtime.\nexport function createIsomorphicFn(): IsomorphicFnBase {\n return createRuntimeFn(() => undefined) as any\n}\n\ntype RuntimeFallbackFn = (() => any) & {\n server: (serverImpl: () => any) => RuntimeFallbackFn\n client: (clientImpl: () => any) => RuntimeFallbackFn\n}\n\nfunction createRuntimeFn(\n fn: () => any,\n serverImpl?: () => any,\n): RuntimeFallbackFn {\n return Object.assign(fn, {\n server: (nextServerImpl: () => any) => {\n return createRuntimeFn(nextServerImpl, nextServerImpl)\n },\n client: (clientImpl: () => any) => {\n return createRuntimeFn(serverImpl ?? clientImpl, serverImpl)\n },\n })\n}\n"],"mappings":";AA6CA,SAAgB,qBAAuC;AACrD,QAAO,sBAAsB,KAAA,EAAU;;AAQzC,SAAS,gBACP,IACA,YACmB;AACnB,QAAO,OAAO,OAAO,IAAI;EACvB,SAAS,mBAA8B;AACrC,UAAO,gBAAgB,gBAAgB,eAAe;;EAExD,SAAS,eAA0B;AACjC,UAAO,gBAAgB,cAAc,YAAY,WAAW;;EAE/D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/start-fn-stubs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.162.0",
|
|
4
4
|
"description": "Stub functions for TanStack Start isomorphic and environment-specific functions",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"test:unit:dev": "vitest --watch",
|
|
51
51
|
"test:eslint": "eslint ./src",
|
|
52
52
|
"test:types": "pnpm run \"/^test:types:ts[0-9]{2}$/\"",
|
|
53
|
-
"test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js",
|
|
54
53
|
"test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js",
|
|
55
54
|
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js",
|
|
56
55
|
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js",
|
|
57
56
|
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js",
|
|
58
|
-
"test:types:ts59": "tsc",
|
|
57
|
+
"test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js",
|
|
58
|
+
"test:types:ts60": "tsc",
|
|
59
59
|
"test:build": "publint --strict && attw --ignore-rules no-resolution --pack .",
|
|
60
60
|
"build": "vite build"
|
|
61
61
|
}
|
|
@@ -34,13 +34,34 @@ export interface IsomorphicFnBase {
|
|
|
34
34
|
) => ClientOnlyFn<TArgs, TClient>
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
//
|
|
37
|
+
// The Start compiler normally rewrites createIsomorphicFn() chains before they
|
|
38
|
+
// run. Some package tests/build steps execute this stub uncompiled though, for
|
|
39
|
+
// example while Vite loads server-side modules during a build.
|
|
40
|
+
//
|
|
41
|
+
// In those uncompiled contexts we need a real callable fallback, not just a
|
|
42
|
+
// chain-shaped object. These contexts are server-side, so once a .server()
|
|
43
|
+
// implementation is registered we keep using it even if .client() is chained
|
|
44
|
+
// later. Client bundles still get the correct client/no-op implementation
|
|
45
|
+
// because the compiler rewrites the original call chain before runtime.
|
|
40
46
|
export function createIsomorphicFn(): IsomorphicFnBase {
|
|
41
|
-
|
|
47
|
+
return createRuntimeFn(() => undefined) as any
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type RuntimeFallbackFn = (() => any) & {
|
|
51
|
+
server: (serverImpl: () => any) => RuntimeFallbackFn
|
|
52
|
+
client: (clientImpl: () => any) => RuntimeFallbackFn
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function createRuntimeFn(
|
|
56
|
+
fn: () => any,
|
|
57
|
+
serverImpl?: () => any,
|
|
58
|
+
): RuntimeFallbackFn {
|
|
42
59
|
return Object.assign(fn, {
|
|
43
|
-
server: (
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
server: (nextServerImpl: () => any) => {
|
|
61
|
+
return createRuntimeFn(nextServerImpl, nextServerImpl)
|
|
62
|
+
},
|
|
63
|
+
client: (clientImpl: () => any) => {
|
|
64
|
+
return createRuntimeFn(serverImpl ?? clientImpl, serverImpl)
|
|
65
|
+
},
|
|
66
|
+
})
|
|
46
67
|
}
|