@tanstack/start-fn-stubs 1.142.8
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/esm/createIsomorphicFn.d.ts +12 -0
- package/dist/esm/createIsomorphicFn.js +12 -0
- package/dist/esm/createIsomorphicFn.js.map +1 -0
- package/dist/esm/envOnly.d.ts +4 -0
- package/dist/esm/envOnly.js +7 -0
- package/dist/esm/envOnly.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +59 -0
- package/src/createIsomorphicFn.ts +41 -0
- package/src/envOnly.ts +9 -0
- package/src/index.ts +9 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type IsomorphicFn<TArgs extends Array<any> = [], TServer = undefined, TClient = undefined> = (...args: TArgs) => TServer | TClient;
|
|
2
|
+
export interface ServerOnlyFn<TArgs extends Array<any>, TServer> extends IsomorphicFn<TArgs, TServer> {
|
|
3
|
+
client: <TClient>(clientImpl: (...args: TArgs) => TClient) => IsomorphicFn<TArgs, TServer, TClient>;
|
|
4
|
+
}
|
|
5
|
+
export interface ClientOnlyFn<TArgs extends Array<any>, TClient> extends IsomorphicFn<TArgs, undefined, TClient> {
|
|
6
|
+
server: <TServer>(serverImpl: (...args: TArgs) => TServer) => IsomorphicFn<TArgs, TServer, TClient>;
|
|
7
|
+
}
|
|
8
|
+
export interface IsomorphicFnBase extends IsomorphicFn {
|
|
9
|
+
server: <TArgs extends Array<any>, TServer>(serverImpl: (...args: TArgs) => TServer) => ServerOnlyFn<TArgs, TServer>;
|
|
10
|
+
client: <TArgs extends Array<any>, TClient>(clientImpl: (...args: TArgs) => TClient) => ClientOnlyFn<TArgs, TClient>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createIsomorphicFn(): IsomorphicFnBase;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createIsomorphicFn.js","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<TArgs extends Array<any>, TServer>\n extends IsomorphicFn<TArgs, TServer> {\n client: <TClient>(\n clientImpl: (...args: TArgs) => TClient,\n ) => IsomorphicFn<TArgs, TServer, TClient>\n}\n\nexport interface ClientOnlyFn<TArgs extends Array<any>, 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 extends IsomorphicFn {\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// this is a dummy function, it will be replaced by the transformer\n// if we use `createIsomorphicFn` in this library itself, vite tries to execute it before the transformer runs\n// therefore we must return a dummy function that allows calling `server` and `client` method chains.\nexport function createIsomorphicFn(): IsomorphicFnBase {\n return {\n server: () => ({ client: () => () => {} }),\n client: () => ({ server: () => () => {} }),\n } as any\n}\n"],"names":[],"mappings":"AAmCO,SAAS,qBAAuC;AACrD,SAAO;AAAA,IACL,QAAQ,OAAO,EAAE,QAAQ,MAAM,MAAM;AAAA,IAAC;IACtC,QAAQ,OAAO,EAAE,QAAQ,MAAM,MAAM;AAAA,IAAC,EAAA;AAAA,EAAE;AAE5C;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envOnly.js","sources":["../../src/envOnly.ts"],"sourcesContent":["type EnvOnlyFn = <TFn extends (...args: Array<any>) => any>(fn: TFn) => TFn\n\n// A function that will only be available in the server build\n// If called on the client, it will throw an error\nexport const createServerOnlyFn: EnvOnlyFn = (fn) => fn\n\n// A function that will only be available in the client build\n// If called on the server, it will throw an error\nexport const createClientOnlyFn: EnvOnlyFn = (fn) => fn\n"],"names":[],"mappings":"AAIO,MAAM,qBAAgC,CAAC,OAAO;AAI9C,MAAM,qBAAgC,CAAC,OAAO;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack/start-fn-stubs",
|
|
3
|
+
"version": "1.142.8",
|
|
4
|
+
"description": "Stub functions for TanStack Start isomorphic and environment-specific functions",
|
|
5
|
+
"author": "Tanner Linsley",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/TanStack/router.git",
|
|
10
|
+
"directory": "packages/start-fn-stubs"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://tanstack.com/start",
|
|
13
|
+
"funding": {
|
|
14
|
+
"type": "github",
|
|
15
|
+
"url": "https://github.com/sponsors/tannerlinsley"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"tanstack",
|
|
19
|
+
"start",
|
|
20
|
+
"isomorphic",
|
|
21
|
+
"server",
|
|
22
|
+
"client"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"clean": "rimraf ./dist && rimraf ./coverage",
|
|
26
|
+
"test": "pnpm test:eslint && pnpm test:types && pnpm test:build && pnpm test:unit",
|
|
27
|
+
"test:unit": "vitest",
|
|
28
|
+
"test:unit:dev": "vitest --watch",
|
|
29
|
+
"test:eslint": "eslint ./src",
|
|
30
|
+
"test:types": "pnpm run \"/^test:types:ts[0-9]{2}$/\"",
|
|
31
|
+
"test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js",
|
|
32
|
+
"test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js",
|
|
33
|
+
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js",
|
|
34
|
+
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js",
|
|
35
|
+
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js",
|
|
36
|
+
"test:types:ts59": "tsc",
|
|
37
|
+
"test:build": "publint --strict && attw --ignore-rules no-resolution --pack .",
|
|
38
|
+
"build": "vite build"
|
|
39
|
+
},
|
|
40
|
+
"type": "module",
|
|
41
|
+
"types": "dist/esm/index.d.ts",
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/esm/index.d.ts",
|
|
46
|
+
"default": "./dist/esm/index.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
51
|
+
"sideEffects": false,
|
|
52
|
+
"files": [
|
|
53
|
+
"dist",
|
|
54
|
+
"src"
|
|
55
|
+
],
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=22.12.0"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// a function that can have different implementations on the client and server.
|
|
2
|
+
// implementations not provided will default to a no-op function.
|
|
3
|
+
|
|
4
|
+
export type IsomorphicFn<
|
|
5
|
+
TArgs extends Array<any> = [],
|
|
6
|
+
TServer = undefined,
|
|
7
|
+
TClient = undefined,
|
|
8
|
+
> = (...args: TArgs) => TServer | TClient
|
|
9
|
+
|
|
10
|
+
export interface ServerOnlyFn<TArgs extends Array<any>, TServer>
|
|
11
|
+
extends IsomorphicFn<TArgs, TServer> {
|
|
12
|
+
client: <TClient>(
|
|
13
|
+
clientImpl: (...args: TArgs) => TClient,
|
|
14
|
+
) => IsomorphicFn<TArgs, TServer, TClient>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ClientOnlyFn<TArgs extends Array<any>, TClient>
|
|
18
|
+
extends IsomorphicFn<TArgs, undefined, TClient> {
|
|
19
|
+
server: <TServer>(
|
|
20
|
+
serverImpl: (...args: TArgs) => TServer,
|
|
21
|
+
) => IsomorphicFn<TArgs, TServer, TClient>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface IsomorphicFnBase extends IsomorphicFn {
|
|
25
|
+
server: <TArgs extends Array<any>, TServer>(
|
|
26
|
+
serverImpl: (...args: TArgs) => TServer,
|
|
27
|
+
) => ServerOnlyFn<TArgs, TServer>
|
|
28
|
+
client: <TArgs extends Array<any>, TClient>(
|
|
29
|
+
clientImpl: (...args: TArgs) => TClient,
|
|
30
|
+
) => ClientOnlyFn<TArgs, TClient>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// this is a dummy function, it will be replaced by the transformer
|
|
34
|
+
// if we use `createIsomorphicFn` in this library itself, vite tries to execute it before the transformer runs
|
|
35
|
+
// therefore we must return a dummy function that allows calling `server` and `client` method chains.
|
|
36
|
+
export function createIsomorphicFn(): IsomorphicFnBase {
|
|
37
|
+
return {
|
|
38
|
+
server: () => ({ client: () => () => {} }),
|
|
39
|
+
client: () => ({ server: () => () => {} }),
|
|
40
|
+
} as any
|
|
41
|
+
}
|
package/src/envOnly.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type EnvOnlyFn = <TFn extends (...args: Array<any>) => any>(fn: TFn) => TFn
|
|
2
|
+
|
|
3
|
+
// A function that will only be available in the server build
|
|
4
|
+
// If called on the client, it will throw an error
|
|
5
|
+
export const createServerOnlyFn: EnvOnlyFn = (fn) => fn
|
|
6
|
+
|
|
7
|
+
// A function that will only be available in the client build
|
|
8
|
+
// If called on the server, it will throw an error
|
|
9
|
+
export const createClientOnlyFn: EnvOnlyFn = (fn) => fn
|