@tanstack/start-client-core 1.142.8 → 1.142.9

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,5 +1,5 @@
1
1
  import { getStartContext } from "@tanstack/start-storage-context";
2
- import { createIsomorphicFn } from "./createIsomorphicFn.js";
2
+ import { createIsomorphicFn } from "@tanstack/start-fn-stubs";
3
3
  const getGlobalStartContext = createIsomorphicFn().client(() => void 0).server(() => {
4
4
  const context = getStartContext().contextAfterGlobalMiddlewares;
5
5
  if (!context) {
@@ -1 +1 @@
1
- {"version":3,"file":"getGlobalStartContext.js","sources":["../../src/getGlobalStartContext.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createIsomorphicFn } from './createIsomorphicFn'\nimport type { AssignAllServerRequestContext } from './createMiddleware'\nimport type { Expand, Register } from '@tanstack/router-core'\n\nexport const getGlobalStartContext: () =>\n | Expand<AssignAllServerRequestContext<Register, []>>\n | undefined = createIsomorphicFn()\n .client(() => undefined)\n .server(() => {\n const context = getStartContext().contextAfterGlobalMiddlewares\n if (!context) {\n throw new Error(\n `Global context not set yet, you are calling getGlobalStartContext() before the global middlewares are applied.`,\n )\n }\n return context\n })\n"],"names":[],"mappings":";;AAKO,MAAM,wBAEG,qBACb,OAAO,MAAM,MAAS,EACtB,OAAO,MAAM;AACZ,QAAM,UAAU,kBAAkB;AAClC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACA,SAAO;AACT,CAAC;"}
1
+ {"version":3,"file":"getGlobalStartContext.js","sources":["../../src/getGlobalStartContext.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createIsomorphicFn } from '@tanstack/start-fn-stubs'\nimport type { AssignAllServerRequestContext } from './createMiddleware'\nimport type { Expand, Register } from '@tanstack/router-core'\n\nexport const getGlobalStartContext: () =>\n | Expand<AssignAllServerRequestContext<Register, []>>\n | undefined = createIsomorphicFn()\n .client(() => undefined)\n .server(() => {\n const context = getStartContext().contextAfterGlobalMiddlewares\n if (!context) {\n throw new Error(\n `Global context not set yet, you are calling getGlobalStartContext() before the global middlewares are applied.`,\n )\n }\n return context\n })\n"],"names":[],"mappings":";;AAKO,MAAM,wBAEG,qBACb,OAAO,MAAM,MAAS,EACtB,OAAO,MAAM;AACZ,QAAM,UAAU,kBAAkB;AAClC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACA,SAAO;AACT,CAAC;"}
@@ -1,5 +1,5 @@
1
1
  import { getStartContext } from "@tanstack/start-storage-context";
2
- import { createIsomorphicFn } from "./createIsomorphicFn.js";
2
+ import { createIsomorphicFn } from "@tanstack/start-fn-stubs";
3
3
  const getRouterInstance = createIsomorphicFn().client(() => window.__TSR_ROUTER__).server(() => getStartContext().getRouter());
4
4
  export {
5
5
  getRouterInstance
@@ -1 +1 @@
1
- {"version":3,"file":"getRouterInstance.js","sources":["../../src/getRouterInstance.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createIsomorphicFn } from './createIsomorphicFn'\nimport type { Awaitable, RegisteredRouter } from '@tanstack/router-core'\n\nexport const getRouterInstance: () => Awaitable<RegisteredRouter> =\n createIsomorphicFn()\n .client(() => window.__TSR_ROUTER__!)\n .server(() => getStartContext().getRouter())\n"],"names":[],"mappings":";;AAIO,MAAM,oBACX,mBAAA,EACG,OAAO,MAAM,OAAO,cAAe,EACnC,OAAO,MAAM,gBAAA,EAAkB,WAAW;"}
1
+ {"version":3,"file":"getRouterInstance.js","sources":["../../src/getRouterInstance.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createIsomorphicFn } from '@tanstack/start-fn-stubs'\nimport type { Awaitable, RegisteredRouter } from '@tanstack/router-core'\n\nexport const getRouterInstance: () => Awaitable<RegisteredRouter> =\n createIsomorphicFn()\n .client(() => window.__TSR_ROUTER__!)\n .server(() => getStartContext().getRouter())\n"],"names":[],"mappings":";;AAIO,MAAM,oBACX,mBAAA,EACG,OAAO,MAAM,OAAO,cAAe,EACnC,OAAO,MAAM,gBAAA,EAAkB,WAAW;"}
@@ -1,5 +1,5 @@
1
1
  import { getStartContext } from "@tanstack/start-storage-context";
2
- import { createServerOnlyFn } from "./envOnly.js";
2
+ import { createServerOnlyFn } from "@tanstack/start-fn-stubs";
3
3
  const getStartContextServerOnly = createServerOnlyFn(getStartContext);
4
4
  export {
5
5
  getStartContextServerOnly
@@ -1 +1 @@
1
- {"version":3,"file":"getStartContextServerOnly.js","sources":["../../src/getStartContextServerOnly.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createServerOnlyFn } from './envOnly'\n\nexport const getStartContextServerOnly = createServerOnlyFn(getStartContext)\n"],"names":[],"mappings":";;AAGO,MAAM,4BAA4B,mBAAmB,eAAe;"}
1
+ {"version":3,"file":"getStartContextServerOnly.js","sources":["../../src/getStartContextServerOnly.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createServerOnlyFn } from '@tanstack/start-fn-stubs'\n\nexport const getStartContextServerOnly = createServerOnlyFn(getStartContext)\n"],"names":[],"mappings":";;AAGO,MAAM,4BAA4B,mBAAmB,eAAe;"}
@@ -1,5 +1,5 @@
1
1
  import { getStartContext } from "@tanstack/start-storage-context";
2
- import { createIsomorphicFn } from "./createIsomorphicFn.js";
2
+ import { createIsomorphicFn } from "@tanstack/start-fn-stubs";
3
3
  const getStartOptions = createIsomorphicFn().client(() => window.__TSS_START_OPTIONS__).server(() => getStartContext().startOptions);
4
4
  export {
5
5
  getStartOptions
@@ -1 +1 @@
1
- {"version":3,"file":"getStartOptions.js","sources":["../../src/getStartOptions.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createIsomorphicFn } from './createIsomorphicFn'\nimport type { AnyStartInstanceOptions } from './createStart'\n\nexport const getStartOptions: () => AnyStartInstanceOptions | undefined =\n createIsomorphicFn()\n .client(() => window.__TSS_START_OPTIONS__)\n .server(() => getStartContext().startOptions)\n"],"names":[],"mappings":";;AAIO,MAAM,kBACX,qBACG,OAAO,MAAM,OAAO,qBAAqB,EACzC,OAAO,MAAM,gBAAA,EAAkB,YAAY;"}
1
+ {"version":3,"file":"getStartOptions.js","sources":["../../src/getStartOptions.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createIsomorphicFn } from '@tanstack/start-fn-stubs'\nimport type { AnyStartInstanceOptions } from './createStart'\n\nexport const getStartOptions: () => AnyStartInstanceOptions | undefined =\n createIsomorphicFn()\n .client(() => window.__TSS_START_OPTIONS__)\n .server(() => getStartContext().startOptions)\n"],"names":[],"mappings":";;AAIO,MAAM,kBACX,qBACG,OAAO,MAAM,OAAO,qBAAqB,EACzC,OAAO,MAAM,gBAAA,EAAkB,YAAY;"}
@@ -1,7 +1,6 @@
1
1
  export type { JsonResponse } from '@tanstack/router-core/ssr/client';
2
2
  export { hydrate, json, mergeHeaders } from '@tanstack/router-core/ssr/client';
3
- export { createIsomorphicFn, type IsomorphicFn, type ServerOnlyFn, type ClientOnlyFn, type IsomorphicFnBase, } from './createIsomorphicFn.js';
4
- export { createServerOnlyFn, createClientOnlyFn } from './envOnly.js';
3
+ export { createIsomorphicFn, createServerOnlyFn, createClientOnlyFn, type IsomorphicFn, type ServerOnlyFn, type ClientOnlyFn, type IsomorphicFnBase, } from '@tanstack/start-fn-stubs';
5
4
  export { createServerFn } from './createServerFn.js';
6
5
  export { createMiddleware, type IntersectAllValidatorInputs, type IntersectAllValidatorOutputs, type FunctionMiddlewareServerFn, type AnyFunctionMiddleware, type FunctionMiddlewareOptions, type FunctionMiddlewareWithTypes, type FunctionMiddlewareValidator, type FunctionMiddlewareServer, type FunctionMiddlewareAfterClient, type FunctionMiddlewareAfterServer, type FunctionMiddleware, type FunctionMiddlewareAfterMiddleware, type FunctionMiddlewareClientFnOptions, type FunctionMiddlewareClientFnResult, type FunctionMiddlewareClientNextFn, type FunctionClientResultWithContext, type AssignAllClientContextBeforeNext, type AssignAllMiddleware, type FunctionMiddlewareAfterValidator, type FunctionMiddlewareClientFn, type FunctionMiddlewareServerFnResult, type FunctionMiddlewareClient, type FunctionMiddlewareServerFnOptions, type FunctionMiddlewareServerNextFn, type FunctionServerResultWithContext, type AnyRequestMiddleware, type RequestMiddlewareOptions, type RequestMiddlewareWithTypes, type RequestMiddlewareServer, type RequestMiddlewareAfterServer, type RequestMiddleware, type RequestMiddlewareAfterMiddleware, type RequestServerFn, type RequestMiddlewareServerFnResult, type RequestServerOptions, type RequestServerNextFn, type RequestServerNextFnOptions, type RequestServerResult, } from './createMiddleware.js';
7
6
  export type { CompiledFetcherFnOptions, CompiledFetcherFn, Fetcher, RscStream, FetcherBaseOptions, ServerFn, ServerFnCtx, MiddlewareFn, ServerFnMiddlewareOptions, ServerFnMiddlewareResult, ServerFnBuilder, ServerFnBaseOptions, NextFn, Method, OptionalFetcher, RequiredFetcher, } from './createServerFn.js';
package/dist/esm/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { hydrate, json, mergeHeaders } from "@tanstack/router-core/ssr/client";
2
- import { createIsomorphicFn } from "./createIsomorphicFn.js";
3
- import { createClientOnlyFn, createServerOnlyFn } from "./envOnly.js";
2
+ import { createClientOnlyFn, createIsomorphicFn, createServerOnlyFn } from "@tanstack/start-fn-stubs";
4
3
  import { applyMiddleware, createServerFn, execValidator, executeMiddleware, flattenMiddlewares } from "./createServerFn.js";
5
4
  import { createMiddleware } from "./createMiddleware.js";
6
5
  import { TSS_FORMDATA_CONTEXT, TSS_SERVER_FUNCTION, X_TSS_RAW_RESPONSE, X_TSS_SERIALIZED } from "./constants.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/start-client-core",
3
- "version": "1.142.8",
3
+ "version": "1.142.9",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -66,8 +66,9 @@
66
66
  "seroval": "^1.4.1",
67
67
  "tiny-invariant": "^1.3.3",
68
68
  "tiny-warning": "^1.0.3",
69
- "@tanstack/router-core": "1.142.8",
70
- "@tanstack/start-storage-context": "1.142.8"
69
+ "@tanstack/start-fn-stubs": "1.142.9",
70
+ "@tanstack/start-storage-context": "1.142.8",
71
+ "@tanstack/router-core": "1.142.8"
71
72
  },
72
73
  "scripts": {
73
74
  "clean": "rimraf ./dist && rimraf ./coverage",
@@ -1,5 +1,5 @@
1
1
  import { getStartContext } from '@tanstack/start-storage-context'
2
- import { createIsomorphicFn } from './createIsomorphicFn'
2
+ import { createIsomorphicFn } from '@tanstack/start-fn-stubs'
3
3
  import type { AssignAllServerRequestContext } from './createMiddleware'
4
4
  import type { Expand, Register } from '@tanstack/router-core'
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { getStartContext } from '@tanstack/start-storage-context'
2
- import { createIsomorphicFn } from './createIsomorphicFn'
2
+ import { createIsomorphicFn } from '@tanstack/start-fn-stubs'
3
3
  import type { Awaitable, RegisteredRouter } from '@tanstack/router-core'
4
4
 
5
5
  export const getRouterInstance: () => Awaitable<RegisteredRouter> =
@@ -1,4 +1,4 @@
1
1
  import { getStartContext } from '@tanstack/start-storage-context'
2
- import { createServerOnlyFn } from './envOnly'
2
+ import { createServerOnlyFn } from '@tanstack/start-fn-stubs'
3
3
 
4
4
  export const getStartContextServerOnly = createServerOnlyFn(getStartContext)
@@ -1,5 +1,5 @@
1
1
  import { getStartContext } from '@tanstack/start-storage-context'
2
- import { createIsomorphicFn } from './createIsomorphicFn'
2
+ import { createIsomorphicFn } from '@tanstack/start-fn-stubs'
3
3
  import type { AnyStartInstanceOptions } from './createStart'
4
4
 
5
5
  export const getStartOptions: () => AnyStartInstanceOptions | undefined =
package/src/index.tsx CHANGED
@@ -4,12 +4,13 @@ export { hydrate, json, mergeHeaders } from '@tanstack/router-core/ssr/client'
4
4
 
5
5
  export {
6
6
  createIsomorphicFn,
7
+ createServerOnlyFn,
8
+ createClientOnlyFn,
7
9
  type IsomorphicFn,
8
10
  type ServerOnlyFn,
9
11
  type ClientOnlyFn,
10
12
  type IsomorphicFnBase,
11
- } from './createIsomorphicFn'
12
- export { createServerOnlyFn, createClientOnlyFn } from './envOnly'
13
+ } from '@tanstack/start-fn-stubs'
13
14
  export { createServerFn } from './createServerFn'
14
15
  export {
15
16
  createMiddleware,
@@ -1,12 +0,0 @@
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;
@@ -1,12 +0,0 @@
1
- function createIsomorphicFn() {
2
- return {
3
- server: () => ({ client: () => () => {
4
- } }),
5
- client: () => ({ server: () => () => {
6
- } })
7
- };
8
- }
9
- export {
10
- createIsomorphicFn
11
- };
12
- //# sourceMappingURL=createIsomorphicFn.js.map
@@ -1 +0,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;"}
@@ -1,4 +0,0 @@
1
- type EnvOnlyFn = <TFn extends (...args: Array<any>) => any>(fn: TFn) => TFn;
2
- export declare const createServerOnlyFn: EnvOnlyFn;
3
- export declare const createClientOnlyFn: EnvOnlyFn;
4
- export {};
@@ -1,7 +0,0 @@
1
- const createServerOnlyFn = (fn) => fn;
2
- const createClientOnlyFn = (fn) => fn;
3
- export {
4
- createClientOnlyFn,
5
- createServerOnlyFn
6
- };
7
- //# sourceMappingURL=envOnly.js.map
@@ -1 +0,0 @@
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;"}
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,41 +0,0 @@
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 DELETED
@@ -1,9 +0,0 @@
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
@@ -1,72 +0,0 @@
1
- import { expectTypeOf, test } from 'vitest'
2
- import { createIsomorphicFn } from '../createIsomorphicFn'
3
-
4
- test('createIsomorphicFn with no implementations', () => {
5
- const fn = createIsomorphicFn()
6
-
7
- expectTypeOf(fn).toBeCallableWith()
8
- expectTypeOf(fn).returns.toBeUndefined()
9
-
10
- expectTypeOf(fn).toHaveProperty('server')
11
- expectTypeOf(fn).toHaveProperty('client')
12
- })
13
-
14
- test('createIsomorphicFn with server implementation', () => {
15
- const fn = createIsomorphicFn().server(() => 'data')
16
-
17
- expectTypeOf(fn).toBeCallableWith()
18
- expectTypeOf(fn).returns.toEqualTypeOf<string | undefined>()
19
-
20
- expectTypeOf(fn).toHaveProperty('client')
21
- expectTypeOf(fn).not.toHaveProperty('server')
22
- })
23
-
24
- test('createIsomorphicFn with client implementation', () => {
25
- const fn = createIsomorphicFn().client(() => 'data')
26
-
27
- expectTypeOf(fn).toBeCallableWith()
28
- expectTypeOf(fn).returns.toEqualTypeOf<string | undefined>()
29
-
30
- expectTypeOf(fn).toHaveProperty('server')
31
- expectTypeOf(fn).not.toHaveProperty('client')
32
- })
33
-
34
- test('createIsomorphicFn with server and client implementation', () => {
35
- const fn = createIsomorphicFn()
36
- .server(() => 'data')
37
- .client(() => 'data')
38
-
39
- expectTypeOf(fn).toBeCallableWith()
40
- expectTypeOf(fn).returns.toEqualTypeOf<string>()
41
-
42
- expectTypeOf(fn).not.toHaveProperty('server')
43
- expectTypeOf(fn).not.toHaveProperty('client')
44
- })
45
-
46
- test('createIsomorphicFn with varying returns', () => {
47
- const fn = createIsomorphicFn()
48
- .server(() => 'data')
49
- .client(() => 1)
50
- expectTypeOf(fn).toBeCallableWith()
51
- expectTypeOf(fn).returns.toEqualTypeOf<string | number>()
52
- })
53
-
54
- test('createIsomorphicFn with arguments', () => {
55
- const fn = createIsomorphicFn()
56
- .server((a: number, b: string) => 'data')
57
- .client((...args) => {
58
- expectTypeOf(args).toEqualTypeOf<[number, string]>()
59
- return 1
60
- })
61
- expectTypeOf(fn).toBeCallableWith(1, 'a')
62
- expectTypeOf(fn).returns.toEqualTypeOf<string | number>()
63
-
64
- const fn2 = createIsomorphicFn()
65
- .client((a: number, b: string) => 'data')
66
- .server((...args) => {
67
- expectTypeOf(args).toEqualTypeOf<[number, string]>()
68
- return 1
69
- })
70
- expectTypeOf(fn2).toBeCallableWith(1, 'a')
71
- expectTypeOf(fn2).returns.toEqualTypeOf<string | number>()
72
- })
@@ -1,34 +0,0 @@
1
- import { expectTypeOf, test } from 'vitest'
2
- import { createClientOnlyFn, createServerOnlyFn } from '../envOnly'
3
-
4
- const inputFn = () => 'output'
5
-
6
- const genericInputFn = <T>(input: T) => input
7
-
8
- function overloadedFn(input: string): string
9
- function overloadedFn(input: number): number
10
- function overloadedFn(input: any) {
11
- return input
12
- }
13
-
14
- test("createClientOnlyFn returns the function it's given", () => {
15
- const outputFn = createClientOnlyFn(inputFn)
16
- expectTypeOf(outputFn).toEqualTypeOf<typeof inputFn>()
17
-
18
- const genericOutputFn = createClientOnlyFn(genericInputFn)
19
- expectTypeOf(genericOutputFn).toEqualTypeOf<typeof genericInputFn>()
20
-
21
- const overloadedOutputFn = createClientOnlyFn(overloadedFn)
22
- expectTypeOf(overloadedOutputFn).toEqualTypeOf<typeof overloadedFn>()
23
- })
24
-
25
- test("createServerOnlyFn returns the function it's given", () => {
26
- const outputFn = createServerOnlyFn(inputFn)
27
- expectTypeOf(outputFn).toEqualTypeOf<typeof inputFn>()
28
-
29
- const genericOutputFn = createServerOnlyFn(genericInputFn)
30
- expectTypeOf(genericOutputFn).toEqualTypeOf<typeof genericInputFn>()
31
-
32
- const overloadedOutputFn = createServerOnlyFn(overloadedFn)
33
- expectTypeOf(overloadedOutputFn).toEqualTypeOf<typeof overloadedFn>()
34
- })