trpc-nuxt-module 4.2.0 → 4.3.1
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/README.md +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +73 -0
- package/dist/models/ExportReference.d.ts +6 -0
- package/dist/models/ModuleOptions.d.ts +10 -0
- package/dist/models/TrpcServerFetch.d.ts +4 -0
- package/dist/models/WebSocketOptions.d.ts +8 -0
- package/dist/runtime/client/createTRPCNuxtClient.d.ts +6 -0
- package/dist/runtime/client/createTRPCNuxtClient.js +29 -0
- package/dist/runtime/client/getMutationKey.d.ts +4 -0
- package/dist/runtime/client/getMutationKey.js +5 -0
- package/dist/runtime/client/getQueryKey.d.ts +4 -0
- package/dist/runtime/client/getQueryKey.js +5 -0
- package/dist/runtime/client/httpBatchLink.d.ts +5 -0
- package/dist/runtime/client/httpBatchLink.js +9 -0
- package/dist/runtime/client/httpLink.d.ts +5 -0
- package/dist/runtime/client/httpLink.js +9 -0
- package/dist/runtime/client/models/DecoratedMutation.d.ts +11 -0
- package/dist/runtime/client/models/DecoratedMutation.js +1 -0
- package/dist/runtime/client/models/DecoratedProcedure.d.ts +8 -0
- package/dist/runtime/client/models/DecoratedProcedure.js +1 -0
- package/dist/runtime/client/models/DecoratedQuery.d.ts +10 -0
- package/dist/runtime/client/models/DecoratedQuery.js +1 -0
- package/dist/runtime/client/models/DecoratedRouterRecord.d.ts +11 -0
- package/dist/runtime/client/models/DecoratedRouterRecord.js +1 -0
- package/dist/runtime/client/models/DecoratedSubscription.d.ts +10 -0
- package/dist/runtime/client/models/DecoratedSubscription.js +1 -0
- package/dist/runtime/client/models/KeysOf.d.ts +3 -0
- package/dist/runtime/client/models/KeysOf.js +1 -0
- package/dist/runtime/client/models/PickFrom.d.ts +3 -0
- package/dist/runtime/client/models/PickFrom.js +1 -0
- package/dist/runtime/client/models/ProcedureNode.d.ts +6 -0
- package/dist/runtime/client/models/ProcedureNode.js +1 -0
- package/dist/runtime/client/models/ProcedurePath.d.ts +5 -0
- package/dist/runtime/client/models/ProcedurePath.js +1 -0
- package/dist/runtime/client/models/QueryAsyncData.d.ts +8 -0
- package/dist/runtime/client/models/QueryAsyncData.js +1 -0
- package/dist/runtime/client/models/QueryError.d.ts +5 -0
- package/dist/runtime/client/models/QueryError.js +1 -0
- package/dist/runtime/client/models/SubscriptionStatus.d.ts +9 -0
- package/dist/runtime/client/models/SubscriptionStatus.js +9 -0
- package/dist/runtime/client/models/TRPCNuxtClient.d.ts +5 -0
- package/dist/runtime/client/models/TRPCNuxtClient.js +1 -0
- package/dist/runtime/client/models/UseMutationOptions.d.ts +10 -0
- package/dist/runtime/client/models/UseMutationOptions.js +1 -0
- package/dist/runtime/client/models/UseMutationReturn.d.ts +9 -0
- package/dist/runtime/client/models/UseMutationReturn.js +1 -0
- package/dist/runtime/client/models/UseQuery.d.ts +8 -0
- package/dist/runtime/client/models/UseQuery.js +1 -0
- package/dist/runtime/client/models/UseQueryOptions.d.ts +11 -0
- package/dist/runtime/client/models/UseQueryOptions.js +1 -0
- package/dist/runtime/client/models/UseSubscriptionOptions.d.ts +7 -0
- package/dist/runtime/client/models/UseSubscriptionOptions.js +1 -0
- package/dist/runtime/client/models/UseSubscriptionReturn.d.ts +10 -0
- package/dist/runtime/client/models/UseSubscriptionReturn.js +1 -0
- package/dist/runtime/client/services/getLinkFetch.d.ts +4 -0
- package/dist/runtime/client/services/getLinkFetch.js +25 -0
- package/dist/runtime/client/services/getProcedureKey.d.ts +3 -0
- package/dist/runtime/client/services/getProcedureKey.js +5 -0
- package/dist/runtime/client/services/mergeSignals.d.ts +3 -0
- package/dist/runtime/client/services/mergeSignals.js +4 -0
- package/dist/runtime/client/services/useProcedureMutation.d.ts +8 -0
- package/dist/runtime/client/services/useProcedureMutation.js +23 -0
- package/dist/runtime/client/services/useProcedureQuery.d.ts +9 -0
- package/dist/runtime/client/services/useProcedureQuery.js +14 -0
- package/dist/runtime/client/services/useProcedureSubscription.d.ts +8 -0
- package/dist/runtime/client/services/useProcedureSubscription.js +68 -0
- package/dist/runtime/client/services/useTrpcServerFetch.d.ts +4 -0
- package/dist/runtime/client/services/useTrpcServerFetch.js +8 -0
- package/dist/runtime/constants.d.ts +6 -0
- package/dist/runtime/constants.js +7 -0
- package/dist/runtime/server/createTRPCEventHandler.d.ts +6 -0
- package/dist/runtime/server/createTRPCEventHandler.js +31 -0
- package/dist/runtime/server/createTRPCWebSocketHandler.d.ts +6 -0
- package/dist/runtime/server/createTRPCWebSocketHandler.js +63 -0
- package/dist/runtime/server/models/PeerWebSocketAdapter.d.ts +19 -0
- package/dist/runtime/server/models/PeerWebSocketAdapter.js +37 -0
- package/dist/runtime/server/models/TRPCEventHandlerOptions.d.ts +11 -0
- package/dist/runtime/server/models/TRPCEventHandlerOptions.js +1 -0
- package/dist/runtime/server/models/TRPCWebSocketConnection.d.ts +7 -0
- package/dist/runtime/server/models/TRPCWebSocketConnection.js +1 -0
- package/dist/runtime/server/models/TRPCWebSocketHandler.d.ts +7 -0
- package/dist/runtime/server/models/TRPCWebSocketHandler.js +1 -0
- package/dist/runtime/server/models/TRPCWebSocketHandlerOptions.d.ts +13 -0
- package/dist/runtime/server/models/TRPCWebSocketHandlerOptions.js +1 -0
- package/dist/runtime/server/models/WebSocketServerAdapter.d.ts +8 -0
- package/dist/runtime/server/models/WebSocketServerAdapter.js +14 -0
- package/dist/runtime/server/services/toIncomingMessage.d.ts +5 -0
- package/dist/runtime/server/services/toIncomingMessage.js +12 -0
- package/dist/services/getEventHandlerTemplate.js +11 -0
- package/dist/services/getImportStatement.js +4 -0
- package/dist/services/getWebSocketHandlerTemplate.js +23 -0
- package/dist/services/getWebSocketHooksTypeTemplate.js +18 -0
- package/package.json +8 -13
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ const { data } = await $trpc.greeting.useQuery(name);
|
|
|
77
77
|
|
|
78
78
|
## <a name="documentation">📖 Documentation</a>
|
|
79
79
|
|
|
80
|
-
We highly recommend you take a look at the [documentation](https://
|
|
80
|
+
We highly recommend you take a look at the [documentation](https://github.com/Esposter/Esposter/tree/main/openspec/specs/trpc-nuxt-module) to level up. It covers the design and the upstream `trpc-nuxt` issues this module answers.
|
|
81
81
|
|
|
82
82
|
### Key exports
|
|
83
83
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModuleOptions } from "./models/ModuleOptions.js";
|
|
2
|
+
import { NuxtModule } from "@nuxt/schema";
|
|
3
|
+
//#region src/module.d.ts
|
|
4
|
+
declare module "@nuxt/schema" {
|
|
5
|
+
interface NuxtConfig {
|
|
6
|
+
trpc?: Partial<ModuleOptions>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
declare const trpcNuxtModule: NuxtModule<ModuleOptions>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { type ModuleOptions, trpcNuxtModule as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { DEFAULT_ENDPOINT, MODULE_NAME } from "./runtime/constants.js";
|
|
2
|
+
import { getEventHandlerTemplate } from "./services/getEventHandlerTemplate.js";
|
|
3
|
+
import { getWebSocketHandlerTemplate } from "./services/getWebSocketHandlerTemplate.js";
|
|
4
|
+
import { getWebSocketHooksTypeTemplate } from "./services/getWebSocketHooksTypeTemplate.js";
|
|
5
|
+
import { addImports, addServerHandler, addServerTemplate, addTypeTemplate, defineNuxtModule, resolvePath } from "@nuxt/kit";
|
|
6
|
+
//#region src/module.ts
|
|
7
|
+
const CLIENT_IMPORTS = [
|
|
8
|
+
"createTRPCNuxtClient",
|
|
9
|
+
"getMutationKey",
|
|
10
|
+
"getQueryKey",
|
|
11
|
+
"httpBatchLink",
|
|
12
|
+
"httpLink"
|
|
13
|
+
];
|
|
14
|
+
const EVENT_HANDLER_FILENAME = `#${MODULE_NAME}/eventHandler.mjs`;
|
|
15
|
+
const WEBSOCKET_HANDLER_FILENAME = `#${MODULE_NAME}/webSocketHandler.mjs`;
|
|
16
|
+
const trpcNuxtModule = defineNuxtModule({
|
|
17
|
+
defaults: { endpoint: DEFAULT_ENDPOINT },
|
|
18
|
+
meta: {
|
|
19
|
+
compatibility: { nuxt: ">=5.0.0-0" },
|
|
20
|
+
configKey: "trpc",
|
|
21
|
+
name: MODULE_NAME
|
|
22
|
+
},
|
|
23
|
+
async setup({ createContext, endpoint, router, webSocket }, nuxt) {
|
|
24
|
+
const resolvedRouter = {
|
|
25
|
+
...router,
|
|
26
|
+
from: await resolvePath(router.from)
|
|
27
|
+
};
|
|
28
|
+
const resolvedCreateContext = createContext && {
|
|
29
|
+
...createContext,
|
|
30
|
+
from: await resolvePath(createContext.from)
|
|
31
|
+
};
|
|
32
|
+
const routedEndpoint = `${nuxt.options.app.baseURL.replace(/\/$/u, "")}${endpoint}`;
|
|
33
|
+
addServerTemplate({
|
|
34
|
+
filename: EVENT_HANDLER_FILENAME,
|
|
35
|
+
getContents: () => getEventHandlerTemplate(resolvedRouter, routedEndpoint, resolvedCreateContext)
|
|
36
|
+
});
|
|
37
|
+
addServerHandler({
|
|
38
|
+
handler: EVENT_HANDLER_FILENAME,
|
|
39
|
+
route: `${endpoint}/**`
|
|
40
|
+
});
|
|
41
|
+
if (webSocket) {
|
|
42
|
+
nuxt.options.nitro.features = {
|
|
43
|
+
...nuxt.options.nitro.features,
|
|
44
|
+
websocket: true
|
|
45
|
+
};
|
|
46
|
+
addServerTemplate({
|
|
47
|
+
filename: WEBSOCKET_HANDLER_FILENAME,
|
|
48
|
+
getContents: () => getWebSocketHandlerTemplate(resolvedRouter, webSocket, resolvedCreateContext)
|
|
49
|
+
});
|
|
50
|
+
addServerHandler({
|
|
51
|
+
handler: WEBSOCKET_HANDLER_FILENAME,
|
|
52
|
+
lazy: true,
|
|
53
|
+
route: webSocket.endpoint
|
|
54
|
+
});
|
|
55
|
+
addTypeTemplate({
|
|
56
|
+
filename: `types/${MODULE_NAME}.d.ts`,
|
|
57
|
+
getContents: () => getWebSocketHooksTypeTemplate({
|
|
58
|
+
...resolvedRouter,
|
|
59
|
+
from: resolvedRouter.from.replace(/\.[cm]?ts$/u, "")
|
|
60
|
+
})
|
|
61
|
+
}, {
|
|
62
|
+
nitro: true,
|
|
63
|
+
nuxt: true
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
addImports(CLIENT_IMPORTS.map((name) => ({
|
|
67
|
+
from: `${MODULE_NAME}/runtime/client/${name}`,
|
|
68
|
+
name
|
|
69
|
+
})));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
//#endregion
|
|
73
|
+
export { trpcNuxtModule as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExportReference } from "./ExportReference.js";
|
|
2
|
+
import { WebSocketOptions } from "./WebSocketOptions.js";
|
|
3
|
+
//#region src/models/ModuleOptions.d.ts
|
|
4
|
+
export interface ModuleOptions {
|
|
5
|
+
createContext?: ExportReference;
|
|
6
|
+
endpoint: string;
|
|
7
|
+
router: ExportReference;
|
|
8
|
+
webSocket?: WebSocketOptions;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AnyTRPCRouter } from "@trpc/server";
|
|
2
|
+
import { WSSHandlerOptions } from "@trpc/server/adapters/ws";
|
|
3
|
+
//#region src/models/WebSocketOptions.d.ts
|
|
4
|
+
export interface WebSocketOptions {
|
|
5
|
+
endpoint: string;
|
|
6
|
+
keepAlive?: WSSHandlerOptions<AnyTRPCRouter>["keepAlive"];
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TRPCNuxtClient } from "./models/TRPCNuxtClient.js";
|
|
2
|
+
import { CreateTRPCClientOptions } from "@trpc/client";
|
|
3
|
+
import { AnyTRPCRouter } from "@trpc/server";
|
|
4
|
+
//#region src/runtime/client/createTRPCNuxtClient.d.ts
|
|
5
|
+
export declare const createTRPCNuxtClient: <TRouter extends AnyTRPCRouter>(options: CreateTRPCClientOptions<TRouter>) => TRPCNuxtClient<TRouter>;
|
|
6
|
+
//#endregion
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useProcedureMutation } from "./services/useProcedureMutation.js";
|
|
2
|
+
import { useProcedureQuery } from "./services/useProcedureQuery.js";
|
|
3
|
+
import { useProcedureSubscription } from "./services/useProcedureSubscription.js";
|
|
4
|
+
import { createTRPCUntypedClient } from "@trpc/client";
|
|
5
|
+
import { createTRPCRecursiveProxy } from "@trpc/server";
|
|
6
|
+
//#region src/runtime/client/createTRPCNuxtClient.ts
|
|
7
|
+
const createTRPCNuxtClient = (options) => {
|
|
8
|
+
const client = createTRPCUntypedClient(options);
|
|
9
|
+
return createTRPCRecursiveProxy(({ args: [first, second], path }) => {
|
|
10
|
+
const procedurePath = path.slice(0, -1);
|
|
11
|
+
const procedure = procedurePath.join(".");
|
|
12
|
+
switch (path.at(-1)) {
|
|
13
|
+
case "_def": return { path: procedurePath };
|
|
14
|
+
case "mutate": return client.mutation(procedure, first, second);
|
|
15
|
+
case "query": return client.query(procedure, first, second);
|
|
16
|
+
case "subscribe": return client.subscription(procedure, first, second);
|
|
17
|
+
case "useLazyQuery": return useProcedureQuery(client, procedure, first, {
|
|
18
|
+
...second,
|
|
19
|
+
lazy: true
|
|
20
|
+
});
|
|
21
|
+
case "useMutation": return useProcedureMutation(client, procedure, first);
|
|
22
|
+
case "useQuery": return useProcedureQuery(client, procedure, first, second);
|
|
23
|
+
case "useSubscription": return useProcedureSubscription(client, procedure, first, second);
|
|
24
|
+
default: throw new TypeError(`"${path.join(".")}" is not a procedure call`);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createTRPCNuxtClient };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HTTPBatchLinkOptions, TRPCLink } from "@trpc/client";
|
|
2
|
+
import { AnyTRPCRouter } from "@trpc/server";
|
|
3
|
+
//#region src/runtime/client/httpBatchLink.d.ts
|
|
4
|
+
export declare const httpBatchLink: <TRouter extends AnyTRPCRouter>(options: HTTPBatchLinkOptions<TRouter["_def"]["_config"]["$types"]>) => TRPCLink<TRouter>;
|
|
5
|
+
//#endregion
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getLinkFetch } from "./services/getLinkFetch.js";
|
|
2
|
+
import { httpBatchLink as httpBatchLink$1 } from "@trpc/client";
|
|
3
|
+
//#region src/runtime/client/httpBatchLink.ts
|
|
4
|
+
const httpBatchLink = (options) => httpBatchLink$1({
|
|
5
|
+
fetch: getLinkFetch(),
|
|
6
|
+
...options
|
|
7
|
+
});
|
|
8
|
+
//#endregion
|
|
9
|
+
export { httpBatchLink };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HTTPLinkOptions, TRPCLink } from "@trpc/client";
|
|
2
|
+
import { AnyTRPCRouter } from "@trpc/server";
|
|
3
|
+
//#region src/runtime/client/httpLink.d.ts
|
|
4
|
+
export declare const httpLink: <TRouter extends AnyTRPCRouter>(options: HTTPLinkOptions<TRouter["_def"]["_config"]["$types"]>) => TRPCLink<TRouter>;
|
|
5
|
+
//#endregion
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getLinkFetch } from "./services/getLinkFetch.js";
|
|
2
|
+
import { httpLink as httpLink$1 } from "@trpc/client";
|
|
3
|
+
//#region src/runtime/client/httpLink.ts
|
|
4
|
+
const httpLink = (options) => httpLink$1({
|
|
5
|
+
fetch: getLinkFetch(),
|
|
6
|
+
...options
|
|
7
|
+
});
|
|
8
|
+
//#endregion
|
|
9
|
+
export { httpLink };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { KeysOf } from "./KeysOf.js";
|
|
2
|
+
import { ProcedureNode } from "./ProcedureNode.js";
|
|
3
|
+
import { UseMutationOptions } from "./UseMutationOptions.js";
|
|
4
|
+
import { UseMutationReturn } from "./UseMutationReturn.js";
|
|
5
|
+
import { Resolver, TRPCResolverDef } from "@trpc/client";
|
|
6
|
+
//#region src/runtime/client/models/DecoratedMutation.d.ts
|
|
7
|
+
export interface DecoratedMutation<TDefinition extends TRPCResolverDef> extends ProcedureNode {
|
|
8
|
+
mutate: Resolver<TDefinition>;
|
|
9
|
+
useMutation: <TData = TDefinition["output"], TPickKeys extends KeysOf<TData> = KeysOf<TData>, TDefault = undefined>(options?: UseMutationOptions<TDefinition, TData, TPickKeys, TDefault>) => UseMutationReturn<TDefinition, TData, TPickKeys, TDefault>;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DecoratedMutation } from "./DecoratedMutation.js";
|
|
2
|
+
import { DecoratedQuery } from "./DecoratedQuery.js";
|
|
3
|
+
import { DecoratedSubscription } from "./DecoratedSubscription.js";
|
|
4
|
+
import { TRPCResolverDef } from "@trpc/client";
|
|
5
|
+
import { TRPCProcedureType } from "@trpc/server";
|
|
6
|
+
//#region src/runtime/client/models/DecoratedProcedure.d.ts
|
|
7
|
+
export type DecoratedProcedure<TType extends TRPCProcedureType, TDefinition extends TRPCResolverDef> = TType extends "query" ? DecoratedQuery<TDefinition> : TType extends "mutation" ? DecoratedMutation<TDefinition> : DecoratedSubscription<TDefinition>;
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ProcedureNode } from "./ProcedureNode.js";
|
|
2
|
+
import { UseQuery } from "./UseQuery.js";
|
|
3
|
+
import { Resolver, TRPCResolverDef } from "@trpc/client";
|
|
4
|
+
//#region src/runtime/client/models/DecoratedQuery.d.ts
|
|
5
|
+
export interface DecoratedQuery<TDefinition extends TRPCResolverDef> extends ProcedureNode {
|
|
6
|
+
query: Resolver<TDefinition>;
|
|
7
|
+
useLazyQuery: UseQuery<TDefinition>;
|
|
8
|
+
useQuery: UseQuery<TDefinition>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ProcedureNode } from "./ProcedureNode.js";
|
|
2
|
+
import { DecoratedProcedure } from "./DecoratedProcedure.js";
|
|
3
|
+
import { AnyTRPCProcedure, AnyTRPCRootTypes, TRPCRouterRecord, inferProcedureInput, inferTransformedProcedureOutput } from "@trpc/server";
|
|
4
|
+
//#region src/runtime/client/models/DecoratedRouterRecord.d.ts
|
|
5
|
+
export type DecoratedRouterRecord<TRoot extends AnyTRPCRootTypes, TRecord extends TRPCRouterRecord> = ProcedureNode & { readonly [TKey in keyof TRecord]: TRecord[TKey] extends AnyTRPCProcedure ? DecoratedProcedure<TRecord[TKey]["_def"]["type"], {
|
|
6
|
+
errorShape: TRoot["errorShape"];
|
|
7
|
+
input: inferProcedureInput<TRecord[TKey]>;
|
|
8
|
+
output: inferTransformedProcedureOutput<TRoot, TRecord[TKey]>;
|
|
9
|
+
transformer: TRoot["transformer"];
|
|
10
|
+
}> : TRecord[TKey] extends TRPCRouterRecord ? DecoratedRouterRecord<TRoot, TRecord[TKey]> : never; };
|
|
11
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { UseSubscriptionOptions } from "./UseSubscriptionOptions.js";
|
|
2
|
+
import { UseSubscriptionReturn } from "./UseSubscriptionReturn.js";
|
|
3
|
+
import { MaybeRefOrGetter } from "vue";
|
|
4
|
+
import { SubscriptionResolver, TRPCClientError, TRPCResolverDef } from "@trpc/client";
|
|
5
|
+
//#region src/runtime/client/models/DecoratedSubscription.d.ts
|
|
6
|
+
export interface DecoratedSubscription<TDefinition extends TRPCResolverDef> {
|
|
7
|
+
subscribe: SubscriptionResolver<TDefinition>;
|
|
8
|
+
useSubscription: (input: MaybeRefOrGetter<TDefinition["input"]>, options?: UseSubscriptionOptions<TDefinition>) => UseSubscriptionReturn<Parameters<NonNullable<UseSubscriptionOptions<TDefinition>["onData"]>>[0], TRPCClientError<TDefinition>>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
//#region src/runtime/client/models/PickFrom.d.ts
|
|
2
|
+
export type PickFrom<T, TKeys extends string[]> = T extends unknown[] ? T : T extends Record<string, unknown> ? keyof T extends TKeys[number] ? T : TKeys[number] extends never ? T : Pick<T, TKeys[number]> : T;
|
|
3
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KeysOf } from "./KeysOf.js";
|
|
2
|
+
import { PickFrom } from "./PickFrom.js";
|
|
3
|
+
import { QueryError } from "./QueryError.js";
|
|
4
|
+
import { AsyncData } from "nuxt/app";
|
|
5
|
+
import { TRPCResolverDef } from "@trpc/client";
|
|
6
|
+
//#region src/runtime/client/models/QueryAsyncData.d.ts
|
|
7
|
+
export type QueryAsyncData<TDefinition extends TRPCResolverDef, TData, TPickKeys extends KeysOf<TData>, TDefault> = AsyncData<PickFrom<TData, TPickKeys> | TDefault, QueryError<TDefinition> | undefined>;
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { NuxtError } from "nuxt/app";
|
|
2
|
+
import { TRPCClientErrorLike, TRPCResolverDef } from "@trpc/client";
|
|
3
|
+
//#region src/runtime/client/models/QueryError.d.ts
|
|
4
|
+
export type QueryError<TDefinition extends TRPCResolverDef> = NuxtError<TRPCClientErrorLike<TDefinition>["data"]>;
|
|
5
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/runtime/client/models/SubscriptionStatus.d.ts
|
|
2
|
+
export declare const SubscriptionStatus: {
|
|
3
|
+
readonly Connecting: "connecting";
|
|
4
|
+
readonly Error: "error";
|
|
5
|
+
readonly Idle: "idle";
|
|
6
|
+
readonly Pending: "pending";
|
|
7
|
+
};
|
|
8
|
+
export type SubscriptionStatus = (typeof SubscriptionStatus)[keyof typeof SubscriptionStatus];
|
|
9
|
+
//#endregion
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DecoratedRouterRecord } from "./DecoratedRouterRecord.js";
|
|
2
|
+
import { AnyTRPCRouter } from "@trpc/server";
|
|
3
|
+
//#region src/runtime/client/models/TRPCNuxtClient.d.ts
|
|
4
|
+
export type TRPCNuxtClient<TRouter extends AnyTRPCRouter> = DecoratedRouterRecord<TRouter["_def"]["_config"]["$types"], TRouter["_def"]["record"]>;
|
|
5
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { KeysOf } from "./KeysOf.js";
|
|
2
|
+
import { AsyncDataOptions } from "nuxt/app";
|
|
3
|
+
import { TRPCRequestOptions, TRPCResolverDef } from "@trpc/client";
|
|
4
|
+
import { Except } from "type-fest";
|
|
5
|
+
//#region src/runtime/client/models/UseMutationOptions.d.ts
|
|
6
|
+
export type UseMutationOptions<TDefinition extends TRPCResolverDef, TData = TDefinition["output"], TPickKeys extends KeysOf<TData> = KeysOf<TData>, TDefault = undefined> = Except<AsyncDataOptions<TDefinition["output"], TData, TPickKeys, TDefault>, "enabled" | "immediate" | "lazy" | "server" | "watch"> & {
|
|
7
|
+
mutationKey?: string;
|
|
8
|
+
trpc?: TRPCRequestOptions;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { KeysOf } from "./KeysOf.js";
|
|
2
|
+
import { PickFrom } from "./PickFrom.js";
|
|
3
|
+
import { QueryAsyncData } from "./QueryAsyncData.js";
|
|
4
|
+
import { TRPCResolverDef } from "@trpc/client";
|
|
5
|
+
//#region src/runtime/client/models/UseMutationReturn.d.ts
|
|
6
|
+
export type UseMutationReturn<TDefinition extends TRPCResolverDef, TData, TPickKeys extends KeysOf<TData>, TDefault> = QueryAsyncData<TDefinition, TData, TPickKeys, TDefault> & {
|
|
7
|
+
mutate: (input: TDefinition["input"]) => Promise<PickFrom<TData, TPickKeys> | TDefault>;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KeysOf } from "./KeysOf.js";
|
|
2
|
+
import { QueryAsyncData } from "./QueryAsyncData.js";
|
|
3
|
+
import { UseQueryOptions } from "./UseQueryOptions.js";
|
|
4
|
+
import { MaybeRefOrGetter } from "vue";
|
|
5
|
+
import { TRPCResolverDef } from "@trpc/client";
|
|
6
|
+
//#region src/runtime/client/models/UseQuery.d.ts
|
|
7
|
+
export type UseQuery<TDefinition extends TRPCResolverDef> = <TData = TDefinition["output"], TPickKeys extends KeysOf<TData> = KeysOf<TData>, TDefault = undefined>(input: MaybeRefOrGetter<TDefinition["input"]>, options?: UseQueryOptions<TDefinition, TData, TPickKeys, TDefault>) => QueryAsyncData<TDefinition, TData, TPickKeys, TDefault>;
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { KeysOf } from "./KeysOf.js";
|
|
2
|
+
import { AsyncDataOptions } from "nuxt/app";
|
|
3
|
+
import { TRPCRequestOptions, TRPCResolverDef } from "@trpc/client";
|
|
4
|
+
import { Except } from "type-fest";
|
|
5
|
+
//#region src/runtime/client/models/UseQueryOptions.d.ts
|
|
6
|
+
export type UseQueryOptions<TDefinition extends TRPCResolverDef, TData = TDefinition["output"], TPickKeys extends KeysOf<TData> = KeysOf<TData>, TDefault = undefined> = Except<AsyncDataOptions<TDefinition["output"], TData, TPickKeys, TDefault>, "watch"> & {
|
|
7
|
+
queryKey?: string;
|
|
8
|
+
trpc?: TRPCRequestOptions;
|
|
9
|
+
watch?: false | NonNullable<AsyncDataOptions<TDefinition["output"], TData, TPickKeys, TDefault>["watch"]>;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MaybeRefOrGetter } from "vue";
|
|
2
|
+
import { SubscriptionResolver, TRPCResolverDef } from "@trpc/client";
|
|
3
|
+
//#region src/runtime/client/models/UseSubscriptionOptions.d.ts
|
|
4
|
+
export type UseSubscriptionOptions<TDefinition extends TRPCResolverDef> = Parameters<SubscriptionResolver<TDefinition>>[1] & {
|
|
5
|
+
enabled?: MaybeRefOrGetter<boolean>;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SubscriptionStatus } from "./SubscriptionStatus.js";
|
|
2
|
+
import { ShallowRef } from "vue";
|
|
3
|
+
//#region src/runtime/client/models/UseSubscriptionReturn.d.ts
|
|
4
|
+
export interface UseSubscriptionReturn<TData, TError> {
|
|
5
|
+
data: ShallowRef<TData | undefined>;
|
|
6
|
+
error: ShallowRef<TError | undefined>;
|
|
7
|
+
reset: () => void;
|
|
8
|
+
status: ShallowRef<SubscriptionStatus>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useTrpcServerFetch } from "./useTrpcServerFetch.js";
|
|
2
|
+
import { useRequestEvent } from "nuxt/app";
|
|
3
|
+
import { checkIsServer } from "@esposter/shared";
|
|
4
|
+
import { fetchWithEvent, getProxyRequestHeaders } from "nitro/h3";
|
|
5
|
+
//#region src/runtime/client/services/getLinkFetch.ts
|
|
6
|
+
const getLinkFetch = () => {
|
|
7
|
+
if (checkIsServer()) {
|
|
8
|
+
const event = useRequestEvent();
|
|
9
|
+
if (event?.app) return (url, options) => fetchWithEvent(event, url, options);
|
|
10
|
+
if (event) {
|
|
11
|
+
const serverFetchInProcess = useTrpcServerFetch();
|
|
12
|
+
return (url, options) => {
|
|
13
|
+
const headers = new Headers(getProxyRequestHeaders(event, { host: true }));
|
|
14
|
+
for (const [name, value] of new Headers(options?.headers)) headers.set(name, value);
|
|
15
|
+
return serverFetchInProcess(new URL(url, event.url), {
|
|
16
|
+
...options,
|
|
17
|
+
headers
|
|
18
|
+
}, event.context);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return (input, init) => fetch(new URL(input, window.location.href), init);
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { getLinkFetch };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KeysOf } from "../models/KeysOf.js";
|
|
2
|
+
import { UseMutationOptions } from "../models/UseMutationOptions.js";
|
|
3
|
+
import { UseMutationReturn } from "../models/UseMutationReturn.js";
|
|
4
|
+
import { TRPCResolverDef, TRPCUntypedClient } from "@trpc/client";
|
|
5
|
+
import { AnyTRPCRouter } from "@trpc/server";
|
|
6
|
+
//#region src/runtime/client/services/useProcedureMutation.d.ts
|
|
7
|
+
export declare const useProcedureMutation: (client: TRPCUntypedClient<AnyTRPCRouter>, path: string, { mutationKey, trpc, ...options }?: UseMutationOptions<TRPCResolverDef>) => UseMutationReturn<TRPCResolverDef, unknown, KeysOf<unknown>, undefined>;
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getProcedureKey } from "./getProcedureKey.js";
|
|
2
|
+
import { mergeSignals } from "./mergeSignals.js";
|
|
3
|
+
import { useAsyncData } from "nuxt/app";
|
|
4
|
+
//#region src/runtime/client/services/useProcedureMutation.ts
|
|
5
|
+
const useProcedureMutation = (client, path, { mutationKey = getProcedureKey(path), trpc, ...options } = {}) => {
|
|
6
|
+
let mutationInput;
|
|
7
|
+
const asyncData = useAsyncData(mutationKey, (_nuxtApp, { signal }) => client.mutation(path, mutationInput, {
|
|
8
|
+
...trpc,
|
|
9
|
+
signal: mergeSignals(signal, trpc?.signal)
|
|
10
|
+
}), {
|
|
11
|
+
...options,
|
|
12
|
+
immediate: false,
|
|
13
|
+
server: false
|
|
14
|
+
});
|
|
15
|
+
return Object.assign(asyncData, { mutate: async (input) => {
|
|
16
|
+
mutationInput = input;
|
|
17
|
+
await asyncData.execute();
|
|
18
|
+
if (asyncData.error.value) throw asyncData.error.value;
|
|
19
|
+
else return asyncData.data.value;
|
|
20
|
+
} });
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { useProcedureMutation };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { KeysOf } from "../models/KeysOf.js";
|
|
2
|
+
import { QueryAsyncData } from "../models/QueryAsyncData.js";
|
|
3
|
+
import { UseQueryOptions } from "../models/UseQueryOptions.js";
|
|
4
|
+
import { MaybeRefOrGetter } from "vue";
|
|
5
|
+
import { TRPCResolverDef, TRPCUntypedClient } from "@trpc/client";
|
|
6
|
+
import { AnyTRPCRouter } from "@trpc/server";
|
|
7
|
+
//#region src/runtime/client/services/useProcedureQuery.d.ts
|
|
8
|
+
export declare const useProcedureQuery: (client: TRPCUntypedClient<AnyTRPCRouter>, path: string, input: MaybeRefOrGetter<unknown>, { queryKey, trpc, watch, ...options }?: UseQueryOptions<TRPCResolverDef>) => QueryAsyncData<TRPCResolverDef, unknown, KeysOf<unknown>, undefined>;
|
|
9
|
+
//#endregion
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getProcedureKey } from "./getProcedureKey.js";
|
|
2
|
+
import { mergeSignals } from "./mergeSignals.js";
|
|
3
|
+
import { useAsyncData } from "nuxt/app";
|
|
4
|
+
import { toValue } from "vue";
|
|
5
|
+
//#region src/runtime/client/services/useProcedureQuery.ts
|
|
6
|
+
const useProcedureQuery = (client, path, input, { queryKey, trpc, watch, ...options } = {}) => useAsyncData(() => queryKey ?? getProcedureKey(path, toValue(input)), (_nuxtApp, { signal }) => client.query(path, toValue(input), {
|
|
7
|
+
...trpc,
|
|
8
|
+
signal: mergeSignals(signal, trpc?.signal)
|
|
9
|
+
}), {
|
|
10
|
+
...options,
|
|
11
|
+
watch: watch === false ? void 0 : queryKey === void 0 ? watch : [...watch ?? [], () => toValue(input)]
|
|
12
|
+
});
|
|
13
|
+
//#endregion
|
|
14
|
+
export { useProcedureQuery };
|