@trpc/tanstack-react-query 11.1.3-alpha-tmp-tsdown.23 → 11.1.3-alpha-tmp-tsdown.26
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.cjs +465 -0
- package/dist/index.d.cts +420 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +420 -8
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +441 -4
- package/dist/index.mjs.map +1 -0
- package/package.json +13 -14
- package/dist/_virtual/rolldown_runtime.js +0 -30
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -7
- package/dist/internals/Context.d.mts +0 -28
- package/dist/internals/Context.d.mts.map +0 -1
- package/dist/internals/Context.d.ts +0 -28
- package/dist/internals/Context.d.ts.map +0 -1
- package/dist/internals/Context.js +0 -46
- package/dist/internals/Context.mjs +0 -46
- package/dist/internals/Context.mjs.map +0 -1
- package/dist/internals/createOptionsProxy.d.mts +0 -161
- package/dist/internals/createOptionsProxy.d.mts.map +0 -1
- package/dist/internals/createOptionsProxy.d.ts +0 -161
- package/dist/internals/createOptionsProxy.d.ts.map +0 -1
- package/dist/internals/createOptionsProxy.js +0 -111
- package/dist/internals/createOptionsProxy.mjs +0 -111
- package/dist/internals/createOptionsProxy.mjs.map +0 -1
- package/dist/internals/infiniteQueryOptions.d.mts +0 -55
- package/dist/internals/infiniteQueryOptions.d.mts.map +0 -1
- package/dist/internals/infiniteQueryOptions.d.ts +0 -55
- package/dist/internals/infiniteQueryOptions.d.ts.map +0 -1
- package/dist/internals/infiniteQueryOptions.js +0 -32
- package/dist/internals/infiniteQueryOptions.mjs +0 -32
- package/dist/internals/infiniteQueryOptions.mjs.map +0 -1
- package/dist/internals/mutationOptions.d.mts +0 -34
- package/dist/internals/mutationOptions.d.mts.map +0 -1
- package/dist/internals/mutationOptions.d.ts +0 -34
- package/dist/internals/mutationOptions.d.ts.map +0 -1
- package/dist/internals/mutationOptions.js +0 -34
- package/dist/internals/mutationOptions.mjs +0 -35
- package/dist/internals/mutationOptions.mjs.map +0 -1
- package/dist/internals/queryOptions.d.mts +0 -46
- package/dist/internals/queryOptions.d.mts.map +0 -1
- package/dist/internals/queryOptions.d.ts +0 -46
- package/dist/internals/queryOptions.d.ts.map +0 -1
- package/dist/internals/queryOptions.js +0 -35
- package/dist/internals/queryOptions.mjs +0 -35
- package/dist/internals/queryOptions.mjs.map +0 -1
- package/dist/internals/subscriptionOptions.d.mts +0 -66
- package/dist/internals/subscriptionOptions.d.mts.map +0 -1
- package/dist/internals/subscriptionOptions.d.ts +0 -66
- package/dist/internals/subscriptionOptions.d.ts.map +0 -1
- package/dist/internals/subscriptionOptions.js +0 -132
- package/dist/internals/subscriptionOptions.mjs +0 -131
- package/dist/internals/subscriptionOptions.mjs.map +0 -1
- package/dist/internals/types.d.mts +0 -84
- package/dist/internals/types.d.mts.map +0 -1
- package/dist/internals/types.d.ts +0 -84
- package/dist/internals/types.d.ts.map +0 -1
- package/dist/internals/utils.js +0 -89
- package/dist/internals/utils.mjs +0 -84
- package/dist/internals/utils.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptionOptions.mjs","names":["args: {\n subscribe: typeof TRPCUntypedClient.prototype.subscription;\n path: readonly string[];\n queryKey: TRPCQueryKey;\n opts?: AnyTRPCSubscriptionOptionsIn;\n}","_subscribe: ReturnType<TRPCSubscriptionOptions<any>>['subscribe']","opts: TRPCSubscriptionOptionsOut<TOutput, TError>","key: keyof $Result","callback: (prevState: $Result) => $Result","result: T","onTrackResult: (key: keyof T) => void"],"sources":["../../src/internals/subscriptionOptions.ts"],"sourcesContent":["import type { SkipToken } from '@tanstack/react-query';\nimport { hashKey, skipToken } from '@tanstack/react-query';\nimport type { TRPCClientErrorLike, TRPCUntypedClient } from '@trpc/client';\nimport type { TRPCConnectionState } from '@trpc/client/unstable-internals';\nimport type { Unsubscribable } from '@trpc/server/observable';\nimport type { inferAsyncIterableYield } from '@trpc/server/unstable-core-do-not-import';\nimport * as React from 'react';\nimport type {\n ResolverDef,\n TRPCQueryKey,\n TRPCQueryOptionsResult,\n} from './types';\nimport { createTRPCOptionsResult } from './utils';\n\ninterface BaseTRPCSubscriptionOptionsIn<TOutput, TError> {\n enabled?: boolean;\n onStarted?: () => void;\n onData?: (data: inferAsyncIterableYield<TOutput>) => void;\n onError?: (err: TError) => void;\n onConnectionStateChange?: (state: TRPCConnectionState<TError>) => void;\n}\n\ninterface UnusedSkipTokenTRPCSubscriptionOptionsIn<TOutput, TError> {\n onStarted?: () => void;\n onData?: (data: inferAsyncIterableYield<TOutput>) => void;\n onError?: (err: TError) => void;\n onConnectionStateChange?: (state: TRPCConnectionState<TError>) => void;\n}\n\ninterface TRPCSubscriptionOptionsOut<TOutput, TError>\n extends UnusedSkipTokenTRPCSubscriptionOptionsIn<TOutput, TError>,\n TRPCQueryOptionsResult {\n enabled: boolean;\n queryKey: TRPCQueryKey;\n subscribe: (\n innerOpts: UnusedSkipTokenTRPCSubscriptionOptionsIn<TOutput, TError>,\n ) => Unsubscribable;\n}\n\nexport interface TRPCSubscriptionOptions<TDef extends ResolverDef> {\n (\n input: TDef['input'],\n opts?: UnusedSkipTokenTRPCSubscriptionOptionsIn<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >,\n ): TRPCSubscriptionOptionsOut<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >;\n (\n input: TDef['input'] | SkipToken,\n opts?: BaseTRPCSubscriptionOptionsIn<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >,\n ): TRPCSubscriptionOptionsOut<\n inferAsyncIterableYield<TDef['output']>,\n TRPCClientErrorLike<TDef>\n >;\n}\nexport type TRPCSubscriptionStatus =\n | 'idle'\n | 'connecting'\n | 'pending'\n | 'error';\n\nexport interface TRPCSubscriptionBaseResult<TOutput, TError> {\n status: TRPCSubscriptionStatus;\n data: undefined | TOutput;\n error: null | TError;\n /**\n * Reset the subscription\n */\n reset: () => void;\n}\n\nexport interface TRPCSubscriptionIdleResult<TOutput>\n extends TRPCSubscriptionBaseResult<TOutput, null> {\n status: 'idle';\n data: undefined;\n error: null;\n}\n\nexport interface TRPCSubscriptionConnectingResult<TOutput, TError>\n extends TRPCSubscriptionBaseResult<TOutput, TError> {\n status: 'connecting';\n data: undefined | TOutput;\n error: TError | null;\n}\n\nexport interface TRPCSubscriptionPendingResult<TOutput>\n extends TRPCSubscriptionBaseResult<TOutput, undefined> {\n status: 'pending';\n data: TOutput | undefined;\n error: null;\n}\n\nexport interface TRPCSubscriptionErrorResult<TOutput, TError>\n extends TRPCSubscriptionBaseResult<TOutput, TError> {\n status: 'error';\n data: TOutput | undefined;\n error: TError;\n}\n\nexport type TRPCSubscriptionResult<TOutput, TError> =\n | TRPCSubscriptionIdleResult<TOutput>\n | TRPCSubscriptionConnectingResult<TOutput, TError>\n | TRPCSubscriptionErrorResult<TOutput, TError>\n | TRPCSubscriptionPendingResult<TOutput>;\n\ntype AnyTRPCSubscriptionOptionsIn =\n | BaseTRPCSubscriptionOptionsIn<unknown, unknown>\n | UnusedSkipTokenTRPCSubscriptionOptionsIn<unknown, unknown>;\n\ntype AnyTRPCSubscriptionOptionsOut = TRPCSubscriptionOptionsOut<\n unknown,\n unknown\n>;\n\n/**\n * @internal\n */\nexport const trpcSubscriptionOptions = (args: {\n subscribe: typeof TRPCUntypedClient.prototype.subscription;\n path: readonly string[];\n queryKey: TRPCQueryKey;\n opts?: AnyTRPCSubscriptionOptionsIn;\n}): AnyTRPCSubscriptionOptionsOut => {\n const { subscribe, path, queryKey, opts = {} } = args;\n const input = queryKey[1]?.input;\n const enabled = 'enabled' in opts ? !!opts.enabled : input !== skipToken;\n\n const _subscribe: ReturnType<TRPCSubscriptionOptions<any>>['subscribe'] = (\n innerOpts,\n ) => {\n return subscribe(path.join('.'), input ?? undefined, innerOpts);\n };\n\n return {\n ...opts,\n enabled,\n subscribe: _subscribe,\n queryKey,\n trpc: createTRPCOptionsResult({ path }),\n };\n};\n\nexport function useSubscription<TOutput, TError>(\n opts: TRPCSubscriptionOptionsOut<TOutput, TError>,\n): TRPCSubscriptionResult<TOutput, TError> {\n type $Result = TRPCSubscriptionResult<TOutput, TError>;\n\n const optsRef = React.useRef(opts);\n optsRef.current = opts;\n\n const trackedProps = React.useRef(new Set<keyof $Result>([]));\n\n const addTrackedProp = React.useCallback((key: keyof $Result) => {\n trackedProps.current.add(key);\n }, []);\n\n type Unsubscribe = () => void;\n const currentSubscriptionRef = React.useRef<Unsubscribe>(() => {\n // noop\n });\n\n const reset = React.useCallback((): void => {\n // unsubscribe from the previous subscription\n currentSubscriptionRef.current?.();\n\n updateState(getInitialState);\n if (!opts.enabled) {\n return;\n }\n const subscription = opts.subscribe({\n onStarted: () => {\n optsRef.current.onStarted?.();\n updateState((prev) => ({\n ...(prev as any),\n status: 'pending',\n error: null,\n }));\n },\n onData: (data) => {\n optsRef.current.onData?.(data);\n updateState((prev) => ({\n ...(prev as any),\n status: 'pending',\n data,\n error: null,\n }));\n },\n onError: (error) => {\n optsRef.current.onError?.(error);\n updateState((prev) => ({\n ...(prev as any),\n status: 'error',\n error,\n }));\n },\n onConnectionStateChange: (result) => {\n optsRef.current.onConnectionStateChange?.(result);\n updateState((prev) => {\n switch (result.state) {\n case 'connecting':\n return {\n ...prev,\n status: 'connecting',\n error: result.error,\n };\n case 'pending':\n // handled in onStarted\n return prev;\n case 'idle':\n return {\n ...prev,\n status: 'idle',\n data: undefined,\n error: null,\n };\n }\n });\n },\n });\n\n currentSubscriptionRef.current = () => {\n subscription.unsubscribe();\n };\n // eslint-disable-next-line react-hooks/react-compiler\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [hashKey(opts.queryKey), opts.enabled]);\n\n const getInitialState = React.useCallback((): $Result => {\n return opts.enabled\n ? {\n data: undefined,\n error: null,\n status: 'connecting',\n reset,\n }\n : {\n data: undefined,\n error: null,\n status: 'idle',\n reset,\n };\n }, [opts.enabled, reset]);\n\n const resultRef = React.useRef<$Result>(getInitialState());\n\n const [state, setState] = React.useState<$Result>(\n trackResult(resultRef.current, addTrackedProp),\n );\n\n state.reset = reset;\n\n const updateState = React.useCallback(\n (callback: (prevState: $Result) => $Result) => {\n const prev = resultRef.current;\n const next = (resultRef.current = callback(prev));\n\n let shouldUpdate = false;\n for (const key of trackedProps.current) {\n if (prev[key] !== next[key]) {\n shouldUpdate = true;\n break;\n }\n }\n if (shouldUpdate) {\n setState(trackResult(next, addTrackedProp));\n }\n },\n [addTrackedProp],\n );\n\n React.useEffect(() => {\n if (!opts.enabled) {\n return;\n }\n reset();\n\n return () => {\n currentSubscriptionRef.current?.();\n };\n }, [reset, opts.enabled]);\n\n return state;\n}\n\nfunction trackResult<T extends object>(\n result: T,\n onTrackResult: (key: keyof T) => void,\n): T {\n const trackedResult = new Proxy(result, {\n get(target, prop) {\n onTrackResult(prop as keyof T);\n return target[prop as keyof T];\n },\n });\n\n return trackedResult;\n}\n"],"mappings":"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"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { TRPCRequestOptions } from "@trpc/client";
|
|
2
|
-
import { InfiniteData } from "@tanstack/react-query";
|
|
3
|
-
|
|
4
|
-
//#region src/internals/types.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Turn a set of optional properties into required
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Turn a set of optional properties into required
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
type WithRequired<TObj, TKey extends keyof TObj> = TObj & { [P in TKey]-?: TObj[P] };
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
type ResolverDef = {
|
|
18
|
-
input: any;
|
|
19
|
-
output: any;
|
|
20
|
-
transformer: boolean;
|
|
21
|
-
errorShape: any;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
|
25
|
-
*/
|
|
26
|
-
type CursorInput = {
|
|
27
|
-
cursor?: any;
|
|
28
|
-
};
|
|
29
|
-
type OptionalCursorInput = CursorInput | void;
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
|
|
34
|
-
/**
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
|
|
38
|
-
/**
|
|
39
|
-
* @public
|
|
40
|
-
*/
|
|
41
|
-
interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
|
|
42
|
-
/**
|
|
43
|
-
* Opt out of SSR for this query by passing `ssr: false`
|
|
44
|
-
*/
|
|
45
|
-
ssr?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Opt out or into aborting request on unmount
|
|
48
|
-
*/
|
|
49
|
-
abortOnUnmount?: boolean;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
interface TRPCQueryBaseOptions {
|
|
55
|
-
/**
|
|
56
|
-
* tRPC-related options
|
|
57
|
-
*/
|
|
58
|
-
trpc?: TRPCReactRequestOptions;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @public
|
|
62
|
-
*/
|
|
63
|
-
interface TRPCQueryOptionsResult {
|
|
64
|
-
trpc: {
|
|
65
|
-
path: string;
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @public
|
|
70
|
-
*/
|
|
71
|
-
type QueryType = 'any' | 'infinite' | 'query';
|
|
72
|
-
/**
|
|
73
|
-
* @public
|
|
74
|
-
*/
|
|
75
|
-
type TRPCQueryKey = [readonly string[], {
|
|
76
|
-
input?: unknown;
|
|
77
|
-
type?: Exclude<QueryType, 'any'>;
|
|
78
|
-
}?];
|
|
79
|
-
/**
|
|
80
|
-
* @public
|
|
81
|
-
*/
|
|
82
|
-
type TRPCMutationKey = [readonly string[]]; //#endregion
|
|
83
|
-
export { ExtractCursorType, OptionalCursorInput, QueryType, ResolverDef, TRPCInfiniteData, TRPCMutationKey, TRPCQueryBaseOptions, TRPCQueryKey, TRPCQueryOptionsResult, TRPCReactRequestOptions, WithRequired };
|
|
84
|
-
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/internals/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;KAOY,sCAAsC,QAAQ,eAClD,SAAS,KAAK,IADtB;;;;AACQ,KAMI,WAAA,GANJ;EAAI,KAAK,EAAA,GAAA;EAAI,MAAC,EAAA,GAAA;EAAC,WAAA,EAAA,OAAA;;;;AAMvB;;KAUK,WAAA;;AAHL,CAAA;AAIY,KAAA,mBAAA,GAAsB,WAAA,GAAW,IAAA;;;;AAKjC,KAAA,iBAAiB,CAAA,MAAA,CAAA,GAAW,MAAX,SAA0B,WAA1B,GACzB,MADyB,CAAA,QAAA,CAAA,GAAA,OAAA;;;;AACzB,KAMQ,gBANR,CAAA,MAAA,EAAA,OAAA,CAAA,GAM4C,YAN5C,CAOF,OAPE,EAQF,WARE,CAQU,iBARV,CAQ4B,MAR5B,CAAA,CAAA,GAAA,IAAA,CAAA;AAAM;;;UAcO,uBAAA,SAEP,KAAK;EAVH;;;EACH,GACuB,CAAA,EAAA,OAAA;EAAM;;;EAFsB,cAAA,CAAA,EAAA,OAAA;;;;AAQ5D;AAEE,UAce,oBAAA,CAdf;EAAA;;AAAY;SAkBL;;;AAJT;;UAUiB,sBAAA;;IAAA,IAAA,EAAA,MAAA;;;;AASjB;;KAAY,SAAA;;AAKZ;;AAEoC,KAFxB,YAAA,GAEwB,CAAS,SAAjB,MAAA,EAAA,EAAO;;SAAP,QAAQ;GAMpC;;;;KAAY,eAAA"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { InfiniteData } from "@tanstack/react-query";
|
|
2
|
-
import { TRPCRequestOptions } from "@trpc/client";
|
|
3
|
-
|
|
4
|
-
//#region src/internals/types.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Turn a set of optional properties into required
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Turn a set of optional properties into required
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
type WithRequired<TObj, TKey extends keyof TObj> = TObj & { [P in TKey]-?: TObj[P] };
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
type ResolverDef = {
|
|
18
|
-
input: any;
|
|
19
|
-
output: any;
|
|
20
|
-
transformer: boolean;
|
|
21
|
-
errorShape: any;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
|
25
|
-
*/
|
|
26
|
-
type CursorInput = {
|
|
27
|
-
cursor?: any;
|
|
28
|
-
};
|
|
29
|
-
type OptionalCursorInput = CursorInput | void;
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
|
|
34
|
-
/**
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
|
|
38
|
-
/**
|
|
39
|
-
* @public
|
|
40
|
-
*/
|
|
41
|
-
interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
|
|
42
|
-
/**
|
|
43
|
-
* Opt out of SSR for this query by passing `ssr: false`
|
|
44
|
-
*/
|
|
45
|
-
ssr?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Opt out or into aborting request on unmount
|
|
48
|
-
*/
|
|
49
|
-
abortOnUnmount?: boolean;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
interface TRPCQueryBaseOptions {
|
|
55
|
-
/**
|
|
56
|
-
* tRPC-related options
|
|
57
|
-
*/
|
|
58
|
-
trpc?: TRPCReactRequestOptions;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @public
|
|
62
|
-
*/
|
|
63
|
-
interface TRPCQueryOptionsResult {
|
|
64
|
-
trpc: {
|
|
65
|
-
path: string;
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @public
|
|
70
|
-
*/
|
|
71
|
-
type QueryType = 'any' | 'infinite' | 'query';
|
|
72
|
-
/**
|
|
73
|
-
* @public
|
|
74
|
-
*/
|
|
75
|
-
type TRPCQueryKey = [readonly string[], {
|
|
76
|
-
input?: unknown;
|
|
77
|
-
type?: Exclude<QueryType, 'any'>;
|
|
78
|
-
}?];
|
|
79
|
-
/**
|
|
80
|
-
* @public
|
|
81
|
-
*/
|
|
82
|
-
type TRPCMutationKey = [readonly string[]]; //#endregion
|
|
83
|
-
export { ExtractCursorType, OptionalCursorInput, QueryType, ResolverDef, TRPCInfiniteData, TRPCMutationKey, TRPCQueryBaseOptions, TRPCQueryKey, TRPCQueryOptionsResult, TRPCReactRequestOptions, WithRequired };
|
|
84
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/internals/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;KAOY,sCAAsC,QAAQ,eAClD,SAAS,KAAK,IADtB;;;;AACQ,KAMI,WAAA,GANJ;EAAI,KAAK,EAAA,GAAA;EAAI,MAAC,EAAA,GAAA;EAAC,WAAA,EAAA,OAAA;;;;AAMvB;;KAUK,WAAA;;AAHL,CAAA;AAIY,KAAA,mBAAA,GAAsB,WAAA,GAAW,IAAA;;;;AAKjC,KAAA,iBAAiB,CAAA,MAAA,CAAA,GAAW,MAAX,SAA0B,WAA1B,GACzB,MADyB,CAAA,QAAA,CAAA,GAAA,OAAA;;;;AACzB,KAMQ,gBANR,CAAA,MAAA,EAAA,OAAA,CAAA,GAM4C,YAN5C,CAOF,OAPE,EAQF,WARE,CAQU,iBARV,CAQ4B,MAR5B,CAAA,CAAA,GAAA,IAAA,CAAA;AAAM;;;UAcO,uBAAA,SAEP,KAAK;EAVH;;;EACH,GACuB,CAAA,EAAA,OAAA;EAAM;;;EAFsB,cAAA,CAAA,EAAA,OAAA;;;;AAQ5D;AAEE,UAce,oBAAA,CAdf;EAAA;;AAAY;SAkBL;;;AAJT;;UAUiB,sBAAA;;IAAA,IAAA,EAAA,MAAA;;;;AASjB;;KAAY,SAAA;;AAKZ;;AAEoC,KAFxB,YAAA,GAEwB,CAAS,SAAjB,MAAA,EAAA,EAAO;;SAAP,QAAQ;GAMpC;;;;KAAY,eAAA"}
|
package/dist/internals/utils.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
-
const __tanstack_react_query = require_rolldown_runtime.__toESM(require("@tanstack/react-query"));
|
|
3
|
-
const __trpc_server_unstable_core_do_not_import = require_rolldown_runtime.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
|
4
|
-
|
|
5
|
-
//#region src/internals/utils.ts
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
function createTRPCOptionsResult(value) {
|
|
10
|
-
const path = value.path.join(".");
|
|
11
|
-
return { path };
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
function getClientArgs(queryKey, opts, infiniteParams) {
|
|
17
|
-
const path = queryKey[0];
|
|
18
|
-
let input = queryKey[1]?.input;
|
|
19
|
-
if (infiniteParams) input = {
|
|
20
|
-
...input ?? {},
|
|
21
|
-
...infiniteParams.pageParam !== void 0 ? { cursor: infiniteParams.pageParam } : {},
|
|
22
|
-
direction: infiniteParams.direction
|
|
23
|
-
};
|
|
24
|
-
return [
|
|
25
|
-
path.join("."),
|
|
26
|
-
input,
|
|
27
|
-
opts?.trpc
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
|
|
34
|
-
const queryCache = queryClient.getQueryCache();
|
|
35
|
-
const query = queryCache.build(queryClient, { queryKey });
|
|
36
|
-
query.setState({
|
|
37
|
-
data: [],
|
|
38
|
-
status: "success"
|
|
39
|
-
});
|
|
40
|
-
const aggregate = [];
|
|
41
|
-
for await (const value of asyncIterable) {
|
|
42
|
-
aggregate.push(value);
|
|
43
|
-
query.setState({ data: [...aggregate] });
|
|
44
|
-
}
|
|
45
|
-
return aggregate;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* To allow easy interactions with groups of related queries, such as
|
|
49
|
-
* invalidating all queries of a router, we use an array as the path when
|
|
50
|
-
* storing in tanstack query.
|
|
51
|
-
*
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
function getQueryKeyInternal(path, input, type) {
|
|
55
|
-
const splitPath = path.flatMap((part) => part.split("."));
|
|
56
|
-
if (!input && (!type || type === "any")) return splitPath.length ? [splitPath] : [];
|
|
57
|
-
if (type === "infinite" && (0, __trpc_server_unstable_core_do_not_import.isObject)(input) && ("direction" in input || "cursor" in input)) {
|
|
58
|
-
const { cursor: _, direction: __,...inputWithoutCursorAndDirection } = input;
|
|
59
|
-
return [splitPath, {
|
|
60
|
-
input: inputWithoutCursorAndDirection,
|
|
61
|
-
type: "infinite"
|
|
62
|
-
}];
|
|
63
|
-
}
|
|
64
|
-
return [splitPath, {
|
|
65
|
-
...typeof input !== "undefined" && input !== __tanstack_react_query.skipToken && { input },
|
|
66
|
-
...type && type !== "any" && { type }
|
|
67
|
-
}];
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* @internal
|
|
71
|
-
*/
|
|
72
|
-
function getMutationKeyInternal(path) {
|
|
73
|
-
const splitPath = path.flatMap((part) => part.split("."));
|
|
74
|
-
return splitPath.length ? [splitPath] : [];
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
function unwrapLazyArg(valueOrLazy) {
|
|
80
|
-
return (0, __trpc_server_unstable_core_do_not_import.isFunction)(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
exports.buildQueryFromAsyncIterable = buildQueryFromAsyncIterable;
|
|
85
|
-
exports.createTRPCOptionsResult = createTRPCOptionsResult;
|
|
86
|
-
exports.getClientArgs = getClientArgs;
|
|
87
|
-
exports.getMutationKeyInternal = getMutationKeyInternal;
|
|
88
|
-
exports.getQueryKeyInternal = getQueryKeyInternal;
|
|
89
|
-
exports.unwrapLazyArg = unwrapLazyArg;
|
package/dist/internals/utils.mjs
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { skipToken } from "@tanstack/react-query";
|
|
2
|
-
import { isFunction, isObject } from "@trpc/server/unstable-core-do-not-import";
|
|
3
|
-
|
|
4
|
-
//#region src/internals/utils.ts
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
function createTRPCOptionsResult(value) {
|
|
9
|
-
const path = value.path.join(".");
|
|
10
|
-
return { path };
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
function getClientArgs(queryKey, opts, infiniteParams) {
|
|
16
|
-
const path = queryKey[0];
|
|
17
|
-
let input = queryKey[1]?.input;
|
|
18
|
-
if (infiniteParams) input = {
|
|
19
|
-
...input ?? {},
|
|
20
|
-
...infiniteParams.pageParam !== void 0 ? { cursor: infiniteParams.pageParam } : {},
|
|
21
|
-
direction: infiniteParams.direction
|
|
22
|
-
};
|
|
23
|
-
return [
|
|
24
|
-
path.join("."),
|
|
25
|
-
input,
|
|
26
|
-
opts?.trpc
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
|
|
33
|
-
const queryCache = queryClient.getQueryCache();
|
|
34
|
-
const query = queryCache.build(queryClient, { queryKey });
|
|
35
|
-
query.setState({
|
|
36
|
-
data: [],
|
|
37
|
-
status: "success"
|
|
38
|
-
});
|
|
39
|
-
const aggregate = [];
|
|
40
|
-
for await (const value of asyncIterable) {
|
|
41
|
-
aggregate.push(value);
|
|
42
|
-
query.setState({ data: [...aggregate] });
|
|
43
|
-
}
|
|
44
|
-
return aggregate;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* To allow easy interactions with groups of related queries, such as
|
|
48
|
-
* invalidating all queries of a router, we use an array as the path when
|
|
49
|
-
* storing in tanstack query.
|
|
50
|
-
*
|
|
51
|
-
* @internal
|
|
52
|
-
*/
|
|
53
|
-
function getQueryKeyInternal(path, input, type) {
|
|
54
|
-
const splitPath = path.flatMap((part) => part.split("."));
|
|
55
|
-
if (!input && (!type || type === "any")) return splitPath.length ? [splitPath] : [];
|
|
56
|
-
if (type === "infinite" && isObject(input) && ("direction" in input || "cursor" in input)) {
|
|
57
|
-
const { cursor: _, direction: __,...inputWithoutCursorAndDirection } = input;
|
|
58
|
-
return [splitPath, {
|
|
59
|
-
input: inputWithoutCursorAndDirection,
|
|
60
|
-
type: "infinite"
|
|
61
|
-
}];
|
|
62
|
-
}
|
|
63
|
-
return [splitPath, {
|
|
64
|
-
...typeof input !== "undefined" && input !== skipToken && { input },
|
|
65
|
-
...type && type !== "any" && { type }
|
|
66
|
-
}];
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @internal
|
|
70
|
-
*/
|
|
71
|
-
function getMutationKeyInternal(path) {
|
|
72
|
-
const splitPath = path.flatMap((part) => part.split("."));
|
|
73
|
-
return splitPath.length ? [splitPath] : [];
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* @internal
|
|
77
|
-
*/
|
|
78
|
-
function unwrapLazyArg(valueOrLazy) {
|
|
79
|
-
return isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
//#endregion
|
|
83
|
-
export { buildQueryFromAsyncIterable, createTRPCOptionsResult, getClientArgs, getMutationKeyInternal, getQueryKeyInternal, unwrapLazyArg };
|
|
84
|
-
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":["value: {\n path: readonly string[];\n}","queryKey: TRPCQueryKey","opts: TOptions","infiniteParams?: {\n pageParam: any;\n direction: 'forward' | 'backward';\n }","asyncIterable: AsyncIterable<unknown>","queryClient: QueryClient","aggregate: unknown[]","path: readonly string[]","input?: unknown","type?: QueryType","valueOrLazy: T | (() => T)"],"sources":["../../src/internals/utils.ts"],"sourcesContent":["import { skipToken, type QueryClient } from '@tanstack/react-query';\nimport { isFunction, isObject } from '@trpc/server/unstable-core-do-not-import';\nimport type {\n QueryType,\n TRPCMutationKey,\n TRPCQueryKey,\n TRPCQueryOptionsResult,\n} from './types';\n\n/**\n * @internal\n */\nexport function createTRPCOptionsResult(value: {\n path: readonly string[];\n}): TRPCQueryOptionsResult['trpc'] {\n const path = value.path.join('.');\n\n return {\n path,\n };\n}\n\n/**\n * @internal\n */\nexport function getClientArgs<TOptions>(\n queryKey: TRPCQueryKey,\n opts: TOptions,\n infiniteParams?: {\n pageParam: any;\n direction: 'forward' | 'backward';\n },\n) {\n const path = queryKey[0];\n let input = queryKey[1]?.input;\n if (infiniteParams) {\n input = {\n ...(input ?? {}),\n ...(infiniteParams.pageParam !== undefined\n ? { cursor: infiniteParams.pageParam }\n : {}),\n direction: infiniteParams.direction,\n };\n }\n return [path.join('.'), input, (opts as any)?.trpc] as const;\n}\n\n/**\n * @internal\n */\nexport async function buildQueryFromAsyncIterable(\n asyncIterable: AsyncIterable<unknown>,\n queryClient: QueryClient,\n queryKey: TRPCQueryKey,\n) {\n const queryCache = queryClient.getQueryCache();\n\n const query = queryCache.build(queryClient, {\n queryKey,\n });\n\n query.setState({\n data: [],\n status: 'success',\n });\n\n const aggregate: unknown[] = [];\n for await (const value of asyncIterable) {\n aggregate.push(value);\n\n query.setState({\n data: [...aggregate],\n });\n }\n return aggregate;\n}\n\n/**\n * To allow easy interactions with groups of related queries, such as\n * invalidating all queries of a router, we use an array as the path when\n * storing in tanstack query.\n *\n * @internal\n */\nexport function getQueryKeyInternal(\n path: readonly string[],\n input?: unknown,\n type?: QueryType,\n): TRPCQueryKey {\n // Construct a query key that is easy to destructure and flexible for\n // partial selecting etc.\n // https://github.com/trpc/trpc/issues/3128\n\n // some parts of the path may be dot-separated, split them up\n const splitPath = path.flatMap((part) => part.split('.'));\n\n if (!input && (!type || type === 'any')) {\n // this matches also all mutations (see `getMutationKeyInternal`)\n\n // for `utils.invalidate()` to match all queries (including vanilla react-query)\n // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`\n return splitPath.length ? [splitPath] : ([] as unknown as TRPCQueryKey);\n }\n\n if (\n type === 'infinite' &&\n isObject(input) &&\n ('direction' in input || 'cursor' in input)\n ) {\n const {\n cursor: _,\n direction: __,\n ...inputWithoutCursorAndDirection\n } = input;\n return [\n splitPath,\n {\n input: inputWithoutCursorAndDirection,\n type: 'infinite',\n },\n ];\n }\n\n return [\n splitPath,\n {\n ...(typeof input !== 'undefined' &&\n input !== skipToken && { input: input }),\n ...(type && type !== 'any' && { type: type }),\n },\n ];\n}\n\n/**\n * @internal\n */\nexport function getMutationKeyInternal(\n path: readonly string[],\n): TRPCMutationKey {\n // some parts of the path may be dot-separated, split them up\n const splitPath = path.flatMap((part) => part.split('.'));\n\n return splitPath.length ? [splitPath] : ([] as unknown as TRPCMutationKey);\n}\n\n/**\n * @internal\n */\nexport function unwrapLazyArg<T>(valueOrLazy: T | (() => T)): T {\n return (isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy) as T;\n}\n"],"mappings":";;;;;;;AAYA,SAAgB,wBAAwBA,OAEL;CACjC,MAAM,OAAO,MAAM,KAAK,KAAK,IAAI;AAEjC,QAAO,EACL,KACD;AACF;;;;AAKD,SAAgB,cACdC,UACAC,MACAC,gBAIA;CACA,MAAM,OAAO,SAAS;CACtB,IAAI,QAAQ,SAAS,IAAI;AACzB,KAAI,eACF,SAAQ;EACN,GAAI,SAAS,CAAE;EACf,GAAI,eAAe,uBACf,EAAE,QAAQ,eAAe,UAAW,IACpC,CAAE;EACN,WAAW,eAAe;CAC3B;AAEH,QAAO;EAAC,KAAK,KAAK,IAAI;EAAE;EAAQ,MAAc;CAAK;AACpD;;;;AAKD,eAAsB,4BACpBC,eACAC,aACAJ,UACA;CACA,MAAM,aAAa,YAAY,eAAe;CAE9C,MAAM,QAAQ,WAAW,MAAM,aAAa,EAC1C,SACD,EAAC;AAEF,OAAM,SAAS;EACb,MAAM,CAAE;EACR,QAAQ;CACT,EAAC;CAEF,MAAMK,YAAuB,CAAE;AAC/B,YAAW,MAAM,SAAS,eAAe;AACvC,YAAU,KAAK,MAAM;AAErB,QAAM,SAAS,EACb,MAAM,CAAC,GAAG,SAAU,EACrB,EAAC;CACH;AACD,QAAO;AACR;;;;;;;;AASD,SAAgB,oBACdC,MACAC,OACAC,MACc;CAMd,MAAM,YAAY,KAAK,QAAQ,CAAC,SAAS,KAAK,MAAM,IAAI,CAAC;AAEzD,MAAK,WAAW,QAAQ,SAAS,OAK/B,QAAO,UAAU,SAAS,CAAC,SAAU,IAAI,CAAE;AAG7C,KACE,SAAS,cACT,SAAS,MAAM,KACd,eAAe,SAAS,YAAY,QACrC;EACA,MAAM,EACJ,QAAQ,GACR,WAAW,GACX,GAAG,gCACJ,GAAG;AACJ,SAAO,CACL,WACA;GACE,OAAO;GACP,MAAM;EACP,CACF;CACF;AAED,QAAO,CACL,WACA;EACE,UAAW,UAAU,eACnB,UAAU,aAAa,EAAS,MAAO;EACzC,GAAI,QAAQ,SAAS,SAAS,EAAQ,KAAM;CAC7C,CACF;AACF;;;;AAKD,SAAgB,uBACdF,MACiB;CAEjB,MAAM,YAAY,KAAK,QAAQ,CAAC,SAAS,KAAK,MAAM,IAAI,CAAC;AAEzD,QAAO,UAAU,SAAS,CAAC,SAAU,IAAI,CAAE;AAC5C;;;;AAKD,SAAgB,cAAiBG,aAA+B;AAC9D,QAAQ,WAAW,YAAY,GAAG,aAAa,GAAG;AACnD"}
|