trpc-nuxt-module 4.1.2 → 4.2.0
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/package.json +5 -5
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -73
- package/dist/models/ExportReference.d.ts +0 -6
- package/dist/models/ModuleOptions.d.ts +0 -10
- package/dist/models/WebSocketOptions.d.ts +0 -8
- package/dist/runtime/client/createTRPCNuxtClient.d.ts +0 -6
- package/dist/runtime/client/createTRPCNuxtClient.js +0 -29
- package/dist/runtime/client/getMutationKey.d.ts +0 -4
- package/dist/runtime/client/getMutationKey.js +0 -5
- package/dist/runtime/client/getQueryKey.d.ts +0 -4
- package/dist/runtime/client/getQueryKey.js +0 -5
- package/dist/runtime/client/httpBatchLink.d.ts +0 -5
- package/dist/runtime/client/httpBatchLink.js +0 -9
- package/dist/runtime/client/httpLink.d.ts +0 -5
- package/dist/runtime/client/httpLink.js +0 -9
- package/dist/runtime/client/models/DecoratedMutation.d.ts +0 -11
- package/dist/runtime/client/models/DecoratedMutation.js +0 -1
- package/dist/runtime/client/models/DecoratedProcedure.d.ts +0 -8
- package/dist/runtime/client/models/DecoratedProcedure.js +0 -1
- package/dist/runtime/client/models/DecoratedQuery.d.ts +0 -10
- package/dist/runtime/client/models/DecoratedQuery.js +0 -1
- package/dist/runtime/client/models/DecoratedRouterRecord.d.ts +0 -11
- package/dist/runtime/client/models/DecoratedRouterRecord.js +0 -1
- package/dist/runtime/client/models/DecoratedSubscription.d.ts +0 -10
- package/dist/runtime/client/models/DecoratedSubscription.js +0 -1
- package/dist/runtime/client/models/KeysOf.d.ts +0 -3
- package/dist/runtime/client/models/KeysOf.js +0 -1
- package/dist/runtime/client/models/PickFrom.d.ts +0 -3
- package/dist/runtime/client/models/PickFrom.js +0 -1
- package/dist/runtime/client/models/ProcedureNode.d.ts +0 -6
- package/dist/runtime/client/models/ProcedureNode.js +0 -1
- package/dist/runtime/client/models/ProcedurePath.d.ts +0 -5
- package/dist/runtime/client/models/ProcedurePath.js +0 -1
- package/dist/runtime/client/models/QueryAsyncData.d.ts +0 -8
- package/dist/runtime/client/models/QueryAsyncData.js +0 -1
- package/dist/runtime/client/models/QueryError.d.ts +0 -5
- package/dist/runtime/client/models/QueryError.js +0 -1
- package/dist/runtime/client/models/SubscriptionStatus.d.ts +0 -9
- package/dist/runtime/client/models/SubscriptionStatus.js +0 -9
- package/dist/runtime/client/models/TRPCNuxtClient.d.ts +0 -5
- package/dist/runtime/client/models/TRPCNuxtClient.js +0 -1
- package/dist/runtime/client/models/UseMutationOptions.d.ts +0 -10
- package/dist/runtime/client/models/UseMutationOptions.js +0 -1
- package/dist/runtime/client/models/UseMutationReturn.d.ts +0 -9
- package/dist/runtime/client/models/UseMutationReturn.js +0 -1
- package/dist/runtime/client/models/UseQuery.d.ts +0 -8
- package/dist/runtime/client/models/UseQuery.js +0 -1
- package/dist/runtime/client/models/UseQueryOptions.d.ts +0 -11
- package/dist/runtime/client/models/UseQueryOptions.js +0 -1
- package/dist/runtime/client/models/UseSubscriptionOptions.d.ts +0 -7
- package/dist/runtime/client/models/UseSubscriptionOptions.js +0 -1
- package/dist/runtime/client/models/UseSubscriptionReturn.d.ts +0 -10
- package/dist/runtime/client/models/UseSubscriptionReturn.js +0 -1
- package/dist/runtime/client/services/getLinkFetch.d.ts +0 -4
- package/dist/runtime/client/services/getLinkFetch.js +0 -13
- package/dist/runtime/client/services/getProcedureKey.d.ts +0 -3
- package/dist/runtime/client/services/getProcedureKey.js +0 -5
- package/dist/runtime/client/services/mergeSignals.d.ts +0 -3
- package/dist/runtime/client/services/mergeSignals.js +0 -4
- package/dist/runtime/client/services/useProcedureMutation.d.ts +0 -8
- package/dist/runtime/client/services/useProcedureMutation.js +0 -23
- package/dist/runtime/client/services/useProcedureQuery.d.ts +0 -9
- package/dist/runtime/client/services/useProcedureQuery.js +0 -14
- package/dist/runtime/client/services/useProcedureSubscription.d.ts +0 -8
- package/dist/runtime/client/services/useProcedureSubscription.js +0 -68
- package/dist/runtime/constants.d.ts +0 -6
- package/dist/runtime/constants.js +0 -7
- package/dist/runtime/server/createTRPCEventHandler.d.ts +0 -6
- package/dist/runtime/server/createTRPCEventHandler.js +0 -31
- package/dist/runtime/server/createTRPCWebSocketHandler.d.ts +0 -6
- package/dist/runtime/server/createTRPCWebSocketHandler.js +0 -63
- package/dist/runtime/server/models/PeerWebSocketAdapter.d.ts +0 -19
- package/dist/runtime/server/models/PeerWebSocketAdapter.js +0 -37
- package/dist/runtime/server/models/TRPCEventHandlerOptions.d.ts +0 -11
- package/dist/runtime/server/models/TRPCEventHandlerOptions.js +0 -1
- package/dist/runtime/server/models/TRPCWebSocketConnection.d.ts +0 -7
- package/dist/runtime/server/models/TRPCWebSocketConnection.js +0 -1
- package/dist/runtime/server/models/TRPCWebSocketHandler.d.ts +0 -7
- package/dist/runtime/server/models/TRPCWebSocketHandler.js +0 -1
- package/dist/runtime/server/models/TRPCWebSocketHandlerOptions.d.ts +0 -13
- package/dist/runtime/server/models/TRPCWebSocketHandlerOptions.js +0 -1
- package/dist/runtime/server/models/WebSocketServerAdapter.d.ts +0 -8
- package/dist/runtime/server/models/WebSocketServerAdapter.js +0 -14
- package/dist/runtime/server/services/toIncomingMessage.d.ts +0 -5
- package/dist/runtime/server/services/toIncomingMessage.js +0 -12
- package/dist/services/getEventHandlerTemplate.js +0 -11
- package/dist/services/getImportStatement.js +0 -4
- package/dist/services/getWebSocketHandlerTemplate.js +0 -23
- package/dist/services/getWebSocketHooksTypeTemplate.js +0 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trpc-nuxt-module",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "tRPC for Nuxt — a Nuxt module that registers your router's HTTP and WebSocket handlers, fetches through the request event during SSR, and decorates the typed client with useQuery, useMutation and useSubscription over useAsyncData.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nitro",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"typecheck": "tsc"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@esposter/shared": "4.
|
|
85
|
+
"@esposter/shared": "4.2.0",
|
|
86
86
|
"@nuxt/kit": "npm:@nuxt/kit-nightly@5x",
|
|
87
87
|
"@nuxt/schema": "npm:@nuxt/schema-nightly@5x",
|
|
88
88
|
"ohash": "^2.0.12",
|
|
@@ -90,8 +90,8 @@
|
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@arethetypeswrong/core": "^0.18.5",
|
|
93
|
-
"@esposter/configuration": "4.
|
|
94
|
-
"@esposter/shared-node": "4.
|
|
93
|
+
"@esposter/configuration": "4.2.0",
|
|
94
|
+
"@esposter/shared-node": "4.2.0",
|
|
95
95
|
"@nuxt/nitro-server": "npm:@nuxt/nitro-server-nightly@5x",
|
|
96
96
|
"@nuxt/test-utils": "^4.3.3",
|
|
97
97
|
"@types/node": "^26.6.5",
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"nuxt": "npm:nuxt-nightly@5x",
|
|
111
111
|
"vue": "^3.5.44"
|
|
112
112
|
},
|
|
113
|
-
"gitHead": "
|
|
113
|
+
"gitHead": "fef4971cf6a621a2c1850f32fcec19ee4ec0de99"
|
|
114
114
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
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 };
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1,29 +0,0 @@
|
|
|
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 };
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1,9 +0,0 @@
|
|
|
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 };
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1,9 +0,0 @@
|
|
|
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 };
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,3 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useRequestEvent } from "nuxt/app";
|
|
2
|
-
import { checkIsServer } from "@esposter/shared";
|
|
3
|
-
import { fetchWithEvent } from "nitro/h3";
|
|
4
|
-
//#region src/runtime/client/services/getLinkFetch.ts
|
|
5
|
-
const getLinkFetch = () => {
|
|
6
|
-
if (checkIsServer()) {
|
|
7
|
-
const event = useRequestEvent();
|
|
8
|
-
if (event) return (url, options) => fetchWithEvent(event, url, options);
|
|
9
|
-
}
|
|
10
|
-
return (input, init) => fetch(new URL(input, window.location.href), init);
|
|
11
|
-
};
|
|
12
|
-
//#endregion
|
|
13
|
-
export { getLinkFetch };
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1,23 +0,0 @@
|
|
|
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 };
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1,14 +0,0 @@
|
|
|
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 };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { UseSubscriptionOptions } from "../models/UseSubscriptionOptions.js";
|
|
2
|
-
import { UseSubscriptionReturn } from "../models/UseSubscriptionReturn.js";
|
|
3
|
-
import { MaybeRefOrGetter } from "vue";
|
|
4
|
-
import { TRPCClientError, TRPCResolverDef, TRPCUntypedClient } from "@trpc/client";
|
|
5
|
-
import { AnyTRPCRouter } from "@trpc/server";
|
|
6
|
-
//#region src/runtime/client/services/useProcedureSubscription.d.ts
|
|
7
|
-
export declare const useProcedureSubscription: (client: TRPCUntypedClient<AnyTRPCRouter>, path: string, input: MaybeRefOrGetter<unknown>, { enabled, ...options }?: UseSubscriptionOptions<TRPCResolverDef>) => UseSubscriptionReturn<unknown, TRPCClientError<AnyTRPCRouter>>;
|
|
8
|
-
//#endregion
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { SubscriptionStatus } from "../models/SubscriptionStatus.js";
|
|
2
|
-
import { getCurrentScope, onScopeDispose, shallowRef, toValue, watch } from "vue";
|
|
3
|
-
import { checkIsServer } from "@esposter/shared";
|
|
4
|
-
//#region src/runtime/client/services/useProcedureSubscription.ts
|
|
5
|
-
const ConnectionStateSubscriptionStatusMap = {
|
|
6
|
-
connecting: SubscriptionStatus.Connecting,
|
|
7
|
-
idle: SubscriptionStatus.Idle,
|
|
8
|
-
pending: SubscriptionStatus.Pending
|
|
9
|
-
};
|
|
10
|
-
const useProcedureSubscription = (client, path, input, { enabled = true, ...options } = {}) => {
|
|
11
|
-
const data = shallowRef();
|
|
12
|
-
const error = shallowRef();
|
|
13
|
-
const status = shallowRef(SubscriptionStatus.Idle);
|
|
14
|
-
let unsubscribable;
|
|
15
|
-
const unsubscribe = () => {
|
|
16
|
-
unsubscribable?.unsubscribe();
|
|
17
|
-
unsubscribable = void 0;
|
|
18
|
-
status.value = SubscriptionStatus.Idle;
|
|
19
|
-
};
|
|
20
|
-
const subscribe = () => {
|
|
21
|
-
unsubscribable?.unsubscribe();
|
|
22
|
-
error.value = void 0;
|
|
23
|
-
status.value = SubscriptionStatus.Connecting;
|
|
24
|
-
unsubscribable = client.subscription(path, toValue(input), {
|
|
25
|
-
...options,
|
|
26
|
-
onComplete: () => {
|
|
27
|
-
status.value = SubscriptionStatus.Idle;
|
|
28
|
-
options.onComplete?.();
|
|
29
|
-
},
|
|
30
|
-
onConnectionStateChange: (state) => {
|
|
31
|
-
status.value = state.error ? SubscriptionStatus.Error : ConnectionStateSubscriptionStatusMap[state.state];
|
|
32
|
-
options.onConnectionStateChange?.(state);
|
|
33
|
-
},
|
|
34
|
-
onData: (value) => {
|
|
35
|
-
data.value = value;
|
|
36
|
-
options.onData?.(value);
|
|
37
|
-
},
|
|
38
|
-
onError: (newError) => {
|
|
39
|
-
error.value = newError;
|
|
40
|
-
status.value = SubscriptionStatus.Error;
|
|
41
|
-
options.onError?.(newError);
|
|
42
|
-
},
|
|
43
|
-
onStarted: (startedOptions) => {
|
|
44
|
-
status.value = SubscriptionStatus.Pending;
|
|
45
|
-
options.onStarted?.(startedOptions);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
if (!checkIsServer()) watch([() => toValue(input), () => toValue(enabled)], ([, isEnabled]) => {
|
|
50
|
-
if (isEnabled) subscribe();
|
|
51
|
-
else unsubscribe();
|
|
52
|
-
}, { immediate: true });
|
|
53
|
-
if (getCurrentScope()) onScopeDispose(() => {
|
|
54
|
-
unsubscribe();
|
|
55
|
-
});
|
|
56
|
-
return {
|
|
57
|
-
data,
|
|
58
|
-
error,
|
|
59
|
-
reset: () => {
|
|
60
|
-
data.value = void 0;
|
|
61
|
-
unsubscribe();
|
|
62
|
-
if (toValue(enabled)) subscribe();
|
|
63
|
-
},
|
|
64
|
-
status
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
//#endregion
|
|
68
|
-
export { useProcedureSubscription };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//#region src/runtime/constants.d.ts
|
|
2
|
-
export declare const DEFAULT_ENDPOINT = "/api/trpc";
|
|
3
|
-
export declare const MODULE_NAME = "trpc-nuxt-module";
|
|
4
|
-
export declare const WEBSOCKET_CLOSE_HOOK: `${typeof MODULE_NAME}:webSocket:close`;
|
|
5
|
-
export declare const WEBSOCKET_OPEN_HOOK: `${typeof MODULE_NAME}:webSocket:open`;
|
|
6
|
-
//#endregion
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
//#region src/runtime/constants.ts
|
|
2
|
-
const DEFAULT_ENDPOINT = "/api/trpc";
|
|
3
|
-
const MODULE_NAME = "trpc-nuxt-module";
|
|
4
|
-
const WEBSOCKET_CLOSE_HOOK = `${MODULE_NAME}:webSocket:close`;
|
|
5
|
-
const WEBSOCKET_OPEN_HOOK = `${MODULE_NAME}:webSocket:open`;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { DEFAULT_ENDPOINT, MODULE_NAME, WEBSOCKET_CLOSE_HOOK, WEBSOCKET_OPEN_HOOK };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { TRPCEventHandlerOptions } from "./models/TRPCEventHandlerOptions.js";
|
|
2
|
-
import { AnyTRPCRouter } from "@trpc/server";
|
|
3
|
-
import { EventHandler } from "nitro/h3";
|
|
4
|
-
//#region src/runtime/server/createTRPCEventHandler.d.ts
|
|
5
|
-
export declare const createTRPCEventHandler: <TRouter extends AnyTRPCRouter>({ createContext, endpoint, ...options }: TRPCEventHandlerOptions<TRouter>) => EventHandler;
|
|
6
|
-
//#endregion
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_ENDPOINT } from "../constants.js";
|
|
2
|
-
import { defineHandler } from "nitro/h3";
|
|
3
|
-
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
4
|
-
//#region src/runtime/server/createTRPCEventHandler.ts
|
|
5
|
-
const NULL_BODY_STATUSES = /* @__PURE__ */ new Set([
|
|
6
|
-
204,
|
|
7
|
-
205,
|
|
8
|
-
304
|
|
9
|
-
]);
|
|
10
|
-
const createTRPCEventHandler = ({ createContext, endpoint = DEFAULT_ENDPOINT, ...options }) => defineHandler(async (event) => {
|
|
11
|
-
const response = await fetchRequestHandler({
|
|
12
|
-
...options,
|
|
13
|
-
createContext: createContext && ((fetchCreateContextOptions) => createContext(event, fetchCreateContextOptions)),
|
|
14
|
-
endpoint,
|
|
15
|
-
req: event.req
|
|
16
|
-
});
|
|
17
|
-
const { status } = event.res;
|
|
18
|
-
if (!status) return response;
|
|
19
|
-
else if (!NULL_BODY_STATUSES.has(status)) return new Response(response.body, {
|
|
20
|
-
headers: response.headers,
|
|
21
|
-
status
|
|
22
|
-
});
|
|
23
|
-
const headers = new Headers(response.headers);
|
|
24
|
-
headers.delete("content-length");
|
|
25
|
-
return new Response(null, {
|
|
26
|
-
headers,
|
|
27
|
-
status
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
//#endregion
|
|
31
|
-
export { createTRPCEventHandler };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { TRPCWebSocketHandler } from "./models/TRPCWebSocketHandler.js";
|
|
2
|
-
import { TRPCWebSocketHandlerOptions } from "./models/TRPCWebSocketHandlerOptions.js";
|
|
3
|
-
import { AnyTRPCRouter } from "@trpc/server";
|
|
4
|
-
//#region src/runtime/server/createTRPCWebSocketHandler.d.ts
|
|
5
|
-
export declare const createTRPCWebSocketHandler: <TRouter extends AnyTRPCRouter>({ createContext, onClose, onOpen, ...options }: TRPCWebSocketHandlerOptions<TRouter>) => TRPCWebSocketHandler;
|
|
6
|
-
//#endregion
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { PeerWebSocketAdapter } from "./models/PeerWebSocketAdapter.js";
|
|
2
|
-
import { WebSocketServerAdapter } from "./models/WebSocketServerAdapter.js";
|
|
3
|
-
import { toIncomingMessage } from "./services/toIncomingMessage.js";
|
|
4
|
-
import { applyWSSHandler } from "@trpc/server/adapters/ws";
|
|
5
|
-
//#region src/runtime/server/createTRPCWebSocketHandler.ts
|
|
6
|
-
const createTRPCWebSocketHandler = ({ createContext, onClose, onOpen, ...options }) => {
|
|
7
|
-
const webSocketServer = new WebSocketServerAdapter();
|
|
8
|
-
const { broadcastReconnectNotification } = applyWSSHandler({
|
|
9
|
-
...options,
|
|
10
|
-
createContext,
|
|
11
|
-
wss: webSocketServer
|
|
12
|
-
});
|
|
13
|
-
const peerConnections = /* @__PURE__ */ new Map();
|
|
14
|
-
return {
|
|
15
|
-
broadcastReconnectNotification,
|
|
16
|
-
hooks: {
|
|
17
|
-
close: async (peer, { code, reason }) => {
|
|
18
|
-
const peerConnection = peerConnections.get(peer.id);
|
|
19
|
-
if (!peerConnection) return;
|
|
20
|
-
peerConnections.delete(peer.id);
|
|
21
|
-
peerConnection.client.receiveClose(code, reason);
|
|
22
|
-
await onClose?.({
|
|
23
|
-
context: await peerConnection.context,
|
|
24
|
-
peer
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
error: (peer, error) => {
|
|
28
|
-
peerConnections.get(peer.id)?.client.receiveError(error);
|
|
29
|
-
},
|
|
30
|
-
message: (peer, message) => {
|
|
31
|
-
peerConnections.get(peer.id)?.client.receiveMessage(message.text());
|
|
32
|
-
},
|
|
33
|
-
open: async (peer) => {
|
|
34
|
-
const client = new PeerWebSocketAdapter(peer);
|
|
35
|
-
const request = toIncomingMessage(peer);
|
|
36
|
-
const context = Promise.resolve(createContext({
|
|
37
|
-
info: {
|
|
38
|
-
accept: null,
|
|
39
|
-
calls: [],
|
|
40
|
-
connectionParams: null,
|
|
41
|
-
isBatchCall: false,
|
|
42
|
-
signal: new AbortController().signal,
|
|
43
|
-
type: "unknown",
|
|
44
|
-
url: new URL(peer.request.url)
|
|
45
|
-
},
|
|
46
|
-
req: request,
|
|
47
|
-
res: client
|
|
48
|
-
}));
|
|
49
|
-
peerConnections.set(peer.id, {
|
|
50
|
-
client,
|
|
51
|
-
context
|
|
52
|
-
});
|
|
53
|
-
webSocketServer.addConnection(client, request);
|
|
54
|
-
await onOpen?.({
|
|
55
|
-
context: await context,
|
|
56
|
-
peer
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
//#endregion
|
|
63
|
-
export { createTRPCWebSocketHandler };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
import { Peer } from "crossws";
|
|
3
|
-
//#region src/runtime/server/models/PeerWebSocketAdapter.d.ts
|
|
4
|
-
export declare class PeerWebSocketAdapter extends EventEmitter {
|
|
5
|
-
#private;
|
|
6
|
-
readonly CLOSED: number;
|
|
7
|
-
readonly CLOSING: number;
|
|
8
|
-
readonly CONNECTING: number;
|
|
9
|
-
readonly OPEN: number;
|
|
10
|
-
readyState: number;
|
|
11
|
-
constructor(peer: Peer);
|
|
12
|
-
close(code?: number, reason?: string): void;
|
|
13
|
-
receiveClose(code?: number, reason?: string): void;
|
|
14
|
-
receiveError(error: unknown): void;
|
|
15
|
-
receiveMessage(message: string): void;
|
|
16
|
-
send(data: string): void;
|
|
17
|
-
terminate(): void;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
//#region src/runtime/server/models/PeerWebSocketAdapter.ts
|
|
3
|
-
var PeerWebSocketAdapter = class extends EventEmitter {
|
|
4
|
-
CLOSED = WebSocket.CLOSED;
|
|
5
|
-
CLOSING = WebSocket.CLOSING;
|
|
6
|
-
CONNECTING = WebSocket.CONNECTING;
|
|
7
|
-
OPEN = WebSocket.OPEN;
|
|
8
|
-
readyState = WebSocket.OPEN;
|
|
9
|
-
#peer;
|
|
10
|
-
constructor(peer) {
|
|
11
|
-
super();
|
|
12
|
-
this.#peer = peer;
|
|
13
|
-
}
|
|
14
|
-
close(code, reason) {
|
|
15
|
-
this.readyState = WebSocket.CLOSING;
|
|
16
|
-
this.#peer.close(code, reason);
|
|
17
|
-
}
|
|
18
|
-
receiveClose(code, reason) {
|
|
19
|
-
this.readyState = WebSocket.CLOSED;
|
|
20
|
-
this.emit("close", code, reason);
|
|
21
|
-
}
|
|
22
|
-
receiveError(error) {
|
|
23
|
-
this.emit("error", error);
|
|
24
|
-
}
|
|
25
|
-
receiveMessage(message) {
|
|
26
|
-
this.emit("message", Buffer.from(message), false);
|
|
27
|
-
}
|
|
28
|
-
send(data) {
|
|
29
|
-
this.#peer.send(data);
|
|
30
|
-
}
|
|
31
|
-
terminate() {
|
|
32
|
-
this.readyState = WebSocket.CLOSING;
|
|
33
|
-
this.#peer.terminate();
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
//#endregion
|
|
37
|
-
export { PeerWebSocketAdapter };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AnyTRPCRouter, inferRouterContext } from "@trpc/server";
|
|
2
|
-
import { H3Event } from "nitro/h3";
|
|
3
|
-
import { FetchCreateContextFnOptions } from "@trpc/server/adapters/fetch";
|
|
4
|
-
import { Promisable } from "type-fest";
|
|
5
|
-
import { HTTPBaseHandlerOptions } from "@trpc/server/http";
|
|
6
|
-
//#region src/runtime/server/models/TRPCEventHandlerOptions.d.ts
|
|
7
|
-
export type TRPCEventHandlerOptions<TRouter extends AnyTRPCRouter> = HTTPBaseHandlerOptions<TRouter, Request> & {
|
|
8
|
-
createContext?: (event: H3Event, options: FetchCreateContextFnOptions) => Promisable<inferRouterContext<TRouter>>;
|
|
9
|
-
endpoint?: string;
|
|
10
|
-
};
|
|
11
|
-
//#endregion
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { TRPCWebSocketConnection } from "./TRPCWebSocketConnection.js";
|
|
2
|
-
import { AnyTRPCRouter, inferRouterContext } from "@trpc/server";
|
|
3
|
-
import { IncomingMessage } from "node:http";
|
|
4
|
-
import { CreateWSSContextFnOptions, WSSHandlerOptions } from "@trpc/server/adapters/ws";
|
|
5
|
-
import { Promisable } from "type-fest";
|
|
6
|
-
import { BaseHandlerOptions } from "@trpc/server/http";
|
|
7
|
-
//#region src/runtime/server/models/TRPCWebSocketHandlerOptions.d.ts
|
|
8
|
-
export type TRPCWebSocketHandlerOptions<TRouter extends AnyTRPCRouter> = BaseHandlerOptions<TRouter, IncomingMessage> & Pick<WSSHandlerOptions<TRouter>, "dangerouslyDisablePong" | "experimental_encoder" | "keepAlive" | "prefix"> & {
|
|
9
|
-
createContext: (options: CreateWSSContextFnOptions) => Promisable<inferRouterContext<TRouter>>;
|
|
10
|
-
onClose?: (connection: TRPCWebSocketConnection<inferRouterContext<TRouter>>) => Promisable<void>;
|
|
11
|
-
onOpen?: (connection: TRPCWebSocketConnection<inferRouterContext<TRouter>>) => Promisable<void>;
|
|
12
|
-
};
|
|
13
|
-
//#endregion
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
import { IncomingMessage } from "node:http";
|
|
3
|
-
//#region src/runtime/server/models/WebSocketServerAdapter.d.ts
|
|
4
|
-
export declare class WebSocketServerAdapter<TClient extends EventEmitter> extends EventEmitter {
|
|
5
|
-
readonly clients: Set<TClient>;
|
|
6
|
-
addConnection(client: TClient, request: IncomingMessage): void;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
//#region src/runtime/server/models/WebSocketServerAdapter.ts
|
|
3
|
-
var WebSocketServerAdapter = class extends EventEmitter {
|
|
4
|
-
clients = /* @__PURE__ */ new Set();
|
|
5
|
-
addConnection(client, request) {
|
|
6
|
-
this.clients.add(client);
|
|
7
|
-
client.once("close", () => {
|
|
8
|
-
this.clients.delete(client);
|
|
9
|
-
});
|
|
10
|
-
this.emit("connection", client, request);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
//#endregion
|
|
14
|
-
export { WebSocketServerAdapter };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { IncomingMessage } from "node:http";
|
|
2
|
-
import { Socket } from "node:net";
|
|
3
|
-
//#region src/runtime/server/services/toIncomingMessage.ts
|
|
4
|
-
const toIncomingMessage = ({ request }) => {
|
|
5
|
-
const incomingMessage = new IncomingMessage(new Socket());
|
|
6
|
-
const { pathname, search } = new URL(request.url);
|
|
7
|
-
incomingMessage.url = `${pathname}${search}`;
|
|
8
|
-
incomingMessage.headers = Object.fromEntries(request.headers);
|
|
9
|
-
return incomingMessage;
|
|
10
|
-
};
|
|
11
|
-
//#endregion
|
|
12
|
-
export { toIncomingMessage };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { MODULE_NAME } from "../runtime/constants.js";
|
|
2
|
-
import { getImportStatement } from "./getImportStatement.js";
|
|
3
|
-
//#region src/services/getEventHandlerTemplate.ts
|
|
4
|
-
const getEventHandlerTemplate = (router, endpoint, createContext) => [
|
|
5
|
-
`import { createTRPCEventHandler } from "${MODULE_NAME}/runtime/server/createTRPCEventHandler";`,
|
|
6
|
-
getImportStatement(router, "router"),
|
|
7
|
-
...createContext ? [getImportStatement(createContext, "createContext")] : [],
|
|
8
|
-
`export default createTRPCEventHandler({ ${createContext ? "createContext, " : ""}endpoint: ${JSON.stringify(endpoint)}, router });`
|
|
9
|
-
].join("\n");
|
|
10
|
-
//#endregion
|
|
11
|
-
export { getEventHandlerTemplate };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { MODULE_NAME } from "../runtime/constants.js";
|
|
2
|
-
import { getImportStatement } from "./getImportStatement.js";
|
|
3
|
-
//#region src/services/getWebSocketHandlerTemplate.ts
|
|
4
|
-
const getWebSocketHandlerTemplate = (router, { keepAlive }, createContext) => [
|
|
5
|
-
`import { useNitroHooks } from "nitro/app";`,
|
|
6
|
-
`import { defineWebSocketHandler } from "nitro/h3";`,
|
|
7
|
-
`import { WEBSOCKET_CLOSE_HOOK, WEBSOCKET_OPEN_HOOK } from "${MODULE_NAME}/runtime/constants";`,
|
|
8
|
-
`import { createTRPCWebSocketHandler } from "${MODULE_NAME}/runtime/server/createTRPCWebSocketHandler";`,
|
|
9
|
-
getImportStatement(router, "router"),
|
|
10
|
-
createContext ? getImportStatement(createContext, "createContext") : "const createContext = () => ({});",
|
|
11
|
-
`const nitroHooks = useNitroHooks();`,
|
|
12
|
-
`const { broadcastReconnectNotification, hooks } = createTRPCWebSocketHandler({`,
|
|
13
|
-
` createContext,`,
|
|
14
|
-
` keepAlive: ${JSON.stringify(keepAlive)},`,
|
|
15
|
-
` onClose: (connection) => nitroHooks.callHook(WEBSOCKET_CLOSE_HOOK, connection),`,
|
|
16
|
-
` onOpen: (connection) => nitroHooks.callHook(WEBSOCKET_OPEN_HOOK, connection),`,
|
|
17
|
-
` router,`,
|
|
18
|
-
`});`,
|
|
19
|
-
`nitroHooks.hook("close", broadcastReconnectNotification);`,
|
|
20
|
-
`export default defineWebSocketHandler(hooks);`
|
|
21
|
-
].join("\n");
|
|
22
|
-
//#endregion
|
|
23
|
-
export { getWebSocketHandlerTemplate };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { MODULE_NAME, WEBSOCKET_CLOSE_HOOK, WEBSOCKET_OPEN_HOOK } from "../runtime/constants.js";
|
|
2
|
-
//#region src/services/getWebSocketHooksTypeTemplate.ts
|
|
3
|
-
const getWebSocketHooksTypeTemplate = ({ from, name }) => {
|
|
4
|
-
const connectionType = `TRPCWebSocketConnection<inferRouterContext<typeof import(${JSON.stringify(from)})[${JSON.stringify(name)}]>>`;
|
|
5
|
-
return [
|
|
6
|
-
`import type { inferRouterContext } from "@trpc/server";`,
|
|
7
|
-
`import type { TRPCWebSocketConnection } from "${MODULE_NAME}/runtime/server/models/TRPCWebSocketConnection";`,
|
|
8
|
-
`declare module "nitro/types" {`,
|
|
9
|
-
` interface NitroRuntimeHooks {`,
|
|
10
|
-
` ${JSON.stringify(WEBSOCKET_CLOSE_HOOK)}: (connection: ${connectionType}) => Promise<void> | void;`,
|
|
11
|
-
` ${JSON.stringify(WEBSOCKET_OPEN_HOOK)}: (connection: ${connectionType}) => Promise<void> | void;`,
|
|
12
|
-
` }`,
|
|
13
|
-
`}`,
|
|
14
|
-
`export {};`
|
|
15
|
-
].join("\n");
|
|
16
|
-
};
|
|
17
|
-
//#endregion
|
|
18
|
-
export { getWebSocketHooksTypeTemplate };
|