trpc-nuxt-module 3.6.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/LICENSE +201 -0
- package/README.md +115 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +72 -0
- package/dist/models/ExportReference.d.ts +6 -0
- package/dist/models/ModuleOptions.d.ts +10 -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 +8 -0
- package/dist/runtime/client/models/SubscriptionStatus.js +10 -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 +12 -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 +66 -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 +17 -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/getRequestSignal.d.ts +4 -0
- package/dist/runtime/server/services/getRequestSignal.js +11 -0
- package/dist/runtime/server/services/toIncomingMessage.d.ts +5 -0
- package/dist/runtime/server/services/toIncomingMessage.js +12 -0
- package/dist/runtime/server/services/toRequest.d.ts +4 -0
- package/dist/runtime/server/services/toRequest.js +20 -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 +114 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getRequestSignal } from "./getRequestSignal.js";
|
|
2
|
+
import { getRequestHost, getRequestProtocol, isMethod, readRawBody } from "h3";
|
|
3
|
+
//#region src/runtime/server/services/toRequest.ts
|
|
4
|
+
const PAYLOAD_METHODS = [
|
|
5
|
+
"DELETE",
|
|
6
|
+
"PATCH",
|
|
7
|
+
"POST",
|
|
8
|
+
"PUT"
|
|
9
|
+
];
|
|
10
|
+
const toRequest = async (event) => {
|
|
11
|
+
const body = isMethod(event, PAYLOAD_METHODS) ? await readRawBody(event, false) : void 0;
|
|
12
|
+
return new Request(`${getRequestProtocol(event)}://${getRequestHost(event)}${event.path}`, {
|
|
13
|
+
body: body && new Uint8Array(body),
|
|
14
|
+
headers: event.headers,
|
|
15
|
+
method: event.method,
|
|
16
|
+
signal: getRequestSignal(event)
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { toRequest };
|
|
@@ -0,0 +1,11 @@
|
|
|
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 };
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { defineWebSocketHandler } from "h3";`,
|
|
6
|
+
`import { useNitroApp } from "nitropack/runtime";`,
|
|
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 { hooks: nitroHooks } = useNitroApp();`,
|
|
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 };
|
|
@@ -0,0 +1,18 @@
|
|
|
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 "nitropack/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 };
|
package/package.json
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "trpc-nuxt-module",
|
|
3
|
+
"version": "3.6.0",
|
|
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
|
+
"keywords": [
|
|
6
|
+
"nitro",
|
|
7
|
+
"nuxt",
|
|
8
|
+
"nuxt-module",
|
|
9
|
+
"ssr",
|
|
10
|
+
"subscriptions",
|
|
11
|
+
"trpc",
|
|
12
|
+
"typescript",
|
|
13
|
+
"websocket"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/Esposter/Esposter/blob/main/packages/trpc-nuxt-module#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/Esposter/Esposter/issues"
|
|
18
|
+
},
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"author": "Jimmy Chen",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Esposter/Esposter.git"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"imports": {
|
|
32
|
+
"#src/*": "./src/*.ts"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
".": "./dist/index.js",
|
|
36
|
+
"./runtime/client/createTRPCNuxtClient": "./dist/runtime/client/createTRPCNuxtClient.js",
|
|
37
|
+
"./runtime/client/getMutationKey": "./dist/runtime/client/getMutationKey.js",
|
|
38
|
+
"./runtime/client/getQueryKey": "./dist/runtime/client/getQueryKey.js",
|
|
39
|
+
"./runtime/client/httpBatchLink": "./dist/runtime/client/httpBatchLink.js",
|
|
40
|
+
"./runtime/client/httpLink": "./dist/runtime/client/httpLink.js",
|
|
41
|
+
"./runtime/client/models/DecoratedMutation": "./dist/runtime/client/models/DecoratedMutation.js",
|
|
42
|
+
"./runtime/client/models/DecoratedProcedure": "./dist/runtime/client/models/DecoratedProcedure.js",
|
|
43
|
+
"./runtime/client/models/DecoratedQuery": "./dist/runtime/client/models/DecoratedQuery.js",
|
|
44
|
+
"./runtime/client/models/DecoratedRouterRecord": "./dist/runtime/client/models/DecoratedRouterRecord.js",
|
|
45
|
+
"./runtime/client/models/DecoratedSubscription": "./dist/runtime/client/models/DecoratedSubscription.js",
|
|
46
|
+
"./runtime/client/models/KeysOf": "./dist/runtime/client/models/KeysOf.js",
|
|
47
|
+
"./runtime/client/models/PickFrom": "./dist/runtime/client/models/PickFrom.js",
|
|
48
|
+
"./runtime/client/models/ProcedureNode": "./dist/runtime/client/models/ProcedureNode.js",
|
|
49
|
+
"./runtime/client/models/ProcedurePath": "./dist/runtime/client/models/ProcedurePath.js",
|
|
50
|
+
"./runtime/client/models/QueryAsyncData": "./dist/runtime/client/models/QueryAsyncData.js",
|
|
51
|
+
"./runtime/client/models/QueryError": "./dist/runtime/client/models/QueryError.js",
|
|
52
|
+
"./runtime/client/models/SubscriptionStatus": "./dist/runtime/client/models/SubscriptionStatus.js",
|
|
53
|
+
"./runtime/client/models/TRPCNuxtClient": "./dist/runtime/client/models/TRPCNuxtClient.js",
|
|
54
|
+
"./runtime/client/models/UseMutationOptions": "./dist/runtime/client/models/UseMutationOptions.js",
|
|
55
|
+
"./runtime/client/models/UseMutationReturn": "./dist/runtime/client/models/UseMutationReturn.js",
|
|
56
|
+
"./runtime/client/models/UseQuery": "./dist/runtime/client/models/UseQuery.js",
|
|
57
|
+
"./runtime/client/models/UseQueryOptions": "./dist/runtime/client/models/UseQueryOptions.js",
|
|
58
|
+
"./runtime/client/models/UseSubscriptionOptions": "./dist/runtime/client/models/UseSubscriptionOptions.js",
|
|
59
|
+
"./runtime/client/models/UseSubscriptionReturn": "./dist/runtime/client/models/UseSubscriptionReturn.js",
|
|
60
|
+
"./runtime/constants": "./dist/runtime/constants.js",
|
|
61
|
+
"./runtime/server/createTRPCEventHandler": "./dist/runtime/server/createTRPCEventHandler.js",
|
|
62
|
+
"./runtime/server/createTRPCWebSocketHandler": "./dist/runtime/server/createTRPCWebSocketHandler.js",
|
|
63
|
+
"./runtime/server/models/PeerWebSocketAdapter": "./dist/runtime/server/models/PeerWebSocketAdapter.js",
|
|
64
|
+
"./runtime/server/models/TRPCEventHandlerOptions": "./dist/runtime/server/models/TRPCEventHandlerOptions.js",
|
|
65
|
+
"./runtime/server/models/TRPCWebSocketConnection": "./dist/runtime/server/models/TRPCWebSocketConnection.js",
|
|
66
|
+
"./runtime/server/models/TRPCWebSocketHandler": "./dist/runtime/server/models/TRPCWebSocketHandler.js",
|
|
67
|
+
"./runtime/server/models/TRPCWebSocketHandlerOptions": "./dist/runtime/server/models/TRPCWebSocketHandlerOptions.js",
|
|
68
|
+
"./runtime/server/models/WebSocketServerAdapter": "./dist/runtime/server/models/WebSocketServerAdapter.js",
|
|
69
|
+
"./package.json": "./package.json"
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"bench": "vitest bench --run",
|
|
76
|
+
"build": "tsdown",
|
|
77
|
+
"format": "oxfmt",
|
|
78
|
+
"format:check": "oxfmt --check",
|
|
79
|
+
"lint": "eslint .",
|
|
80
|
+
"lint:fix": "eslint --fix .",
|
|
81
|
+
"test": "vitest",
|
|
82
|
+
"typecheck": "tsc"
|
|
83
|
+
},
|
|
84
|
+
"dependencies": {
|
|
85
|
+
"@esposter/shared": "3.6.0",
|
|
86
|
+
"@nuxt/kit": "^4.5.2",
|
|
87
|
+
"@nuxt/schema": "^4.5.2",
|
|
88
|
+
"ohash": "^2.0.12",
|
|
89
|
+
"type-fest": "^5.10.0"
|
|
90
|
+
},
|
|
91
|
+
"devDependencies": {
|
|
92
|
+
"@arethetypeswrong/core": "^0.18.5",
|
|
93
|
+
"@esposter/configuration": "3.6.0",
|
|
94
|
+
"@esposter/shared-node": "3.6.0",
|
|
95
|
+
"@nuxt/nitro-server": "^4.5.2",
|
|
96
|
+
"@nuxt/test-utils": "^4.3.2",
|
|
97
|
+
"@types/node": "^26.6.3",
|
|
98
|
+
"happy-dom": "^20.14.5",
|
|
99
|
+
"publint": "^0.3.24",
|
|
100
|
+
"superjson": "^2.2.6",
|
|
101
|
+
"tsdown": "^0.23.0",
|
|
102
|
+
"vitest": "^5.0.2",
|
|
103
|
+
"zod": "^4.6.5"
|
|
104
|
+
},
|
|
105
|
+
"peerDependencies": {
|
|
106
|
+
"@trpc/client": "^11.19.0",
|
|
107
|
+
"@trpc/server": "^11.19.0",
|
|
108
|
+
"crossws": "^0.4.12",
|
|
109
|
+
"h3": "^1.15.11",
|
|
110
|
+
"nuxt": "^4.5.2",
|
|
111
|
+
"vue": "^3.5.43"
|
|
112
|
+
},
|
|
113
|
+
"gitHead": "07f63a48503626e6f02f64e778a2e8e4838b55e2"
|
|
114
|
+
}
|