@tanstack/start-fn-stubs
Advanced tools
+21
| MIT License | ||
| Copyright (c) 2021-present Tanner Linsley | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
@@ -8,3 +8,3 @@ export type IsomorphicFn<TArgs extends Array<any> = [], TServer = undefined, TClient = undefined> = (...args: TArgs) => TServer | TClient; | ||
| } | ||
| export interface IsomorphicFnBase extends IsomorphicFn { | ||
| export interface IsomorphicFnBase { | ||
| server: <TArgs extends Array<any>, TServer>(serverImpl: (...args: TArgs) => TServer) => ServerOnlyFn<TArgs, TServer>; | ||
@@ -11,0 +11,0 @@ client: <TArgs extends Array<any>, TClient>(clientImpl: (...args: TArgs) => TClient) => ClientOnlyFn<TArgs, TClient>; |
| function createIsomorphicFn() { | ||
| return { | ||
| const fn = () => void 0; | ||
| return Object.assign(fn, { | ||
| server: () => ({ client: () => () => { | ||
@@ -7,3 +8,3 @@ } }), | ||
| } }) | ||
| }; | ||
| }); | ||
| } | ||
@@ -10,0 +11,0 @@ export { |
@@ -1,1 +0,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;"} | ||
| {"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 {\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 const fn = () => undefined\n return Object.assign(fn, {\n server: () => ({ client: () => () => {} }),\n client: () => ({ server: () => () => {} }),\n }) as any\n}\n"],"names":[],"mappings":"AAmCO,SAAS,qBAAuC;AACrD,QAAM,KAAK,MAAM;AACjB,SAAO,OAAO,OAAO,IAAI;AAAA,IACvB,QAAQ,OAAO,EAAE,QAAQ,MAAM,MAAM;AAAA,IAAC;IACtC,QAAQ,OAAO,EAAE,QAAQ,MAAM,MAAM;AAAA,IAAC,EAAA;AAAA,EAAE,CACzC;AACH;"} |
+18
-18
| { | ||
| "name": "@tanstack/start-fn-stubs", | ||
| "version": "1.142.9", | ||
| "version": "1.143.8", | ||
| "description": "Stub functions for TanStack Start isomorphic and environment-specific functions", | ||
@@ -24,18 +24,2 @@ "author": "Tanner Linsley", | ||
| ], | ||
| "scripts": { | ||
| "clean": "rimraf ./dist && rimraf ./coverage", | ||
| "test": "pnpm test:eslint && pnpm test:types && pnpm test:build && pnpm test:unit", | ||
| "test:unit": "vitest", | ||
| "test:unit:dev": "vitest --watch", | ||
| "test:eslint": "eslint ./src", | ||
| "test:types": "pnpm run \"/^test:types:ts[0-9]{2}$/\"", | ||
| "test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js", | ||
| "test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js", | ||
| "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js", | ||
| "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js", | ||
| "test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js", | ||
| "test:types:ts59": "tsc", | ||
| "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", | ||
| "build": "vite build" | ||
| }, | ||
| "type": "module", | ||
@@ -59,3 +43,19 @@ "types": "dist/esm/index.d.ts", | ||
| "node": ">=22.12.0" | ||
| }, | ||
| "scripts": { | ||
| "clean": "rimraf ./dist && rimraf ./coverage", | ||
| "test": "pnpm test:eslint && pnpm test:types && pnpm test:build && pnpm test:unit", | ||
| "test:unit": "vitest", | ||
| "test:unit:dev": "vitest --watch", | ||
| "test:eslint": "eslint ./src", | ||
| "test:types": "pnpm run \"/^test:types:ts[0-9]{2}$/\"", | ||
| "test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js", | ||
| "test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js", | ||
| "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js", | ||
| "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js", | ||
| "test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js", | ||
| "test:types:ts59": "tsc", | ||
| "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .", | ||
| "build": "vite build" | ||
| } | ||
| } | ||
| } |
@@ -24,3 +24,3 @@ // a function that can have different implementations on the client and server. | ||
| export interface IsomorphicFnBase extends IsomorphicFn { | ||
| export interface IsomorphicFnBase { | ||
| server: <TArgs extends Array<any>, TServer>( | ||
@@ -38,6 +38,7 @@ serverImpl: (...args: TArgs) => TServer, | ||
| export function createIsomorphicFn(): IsomorphicFnBase { | ||
| return { | ||
| const fn = () => undefined | ||
| return Object.assign(fn, { | ||
| server: () => ({ client: () => () => {} }), | ||
| client: () => ({ server: () => () => {} }), | ||
| } as any | ||
| }) as any | ||
| } |
9647
14.21%14
7.69%98
2.08%