@orpc/server 0.0.0-next.ca29a36 → 0.0.0-next.cac5dd3
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 +28 -18
- package/dist/adapters/bun-ws/index.d.mts +35 -0
- package/dist/adapters/bun-ws/index.d.ts +35 -0
- package/dist/adapters/bun-ws/index.mjs +51 -0
- package/dist/adapters/crossws/index.d.mts +30 -0
- package/dist/adapters/crossws/index.d.ts +30 -0
- package/dist/adapters/crossws/index.mjs +51 -0
- package/dist/adapters/fetch/index.d.mts +78 -0
- package/dist/adapters/fetch/index.d.ts +78 -0
- package/dist/adapters/fetch/index.mjs +110 -0
- package/dist/adapters/node/index.d.mts +77 -0
- package/dist/adapters/node/index.d.ts +77 -0
- package/dist/adapters/node/index.mjs +95 -0
- package/dist/adapters/standard/index.d.mts +26 -0
- package/dist/adapters/standard/index.d.ts +26 -0
- package/dist/adapters/standard/index.mjs +7 -0
- package/dist/adapters/websocket/index.d.mts +27 -0
- package/dist/adapters/websocket/index.d.ts +27 -0
- package/dist/adapters/websocket/index.mjs +38 -0
- package/dist/adapters/ws/index.d.mts +28 -0
- package/dist/adapters/ws/index.d.ts +28 -0
- package/dist/adapters/ws/index.mjs +38 -0
- package/dist/index.d.mts +829 -0
- package/dist/index.d.ts +829 -0
- package/dist/index.mjs +474 -0
- package/dist/plugins/index.d.mts +156 -0
- package/dist/plugins/index.d.ts +156 -0
- package/dist/plugins/index.mjs +251 -0
- package/dist/shared/server.4FnxLwwr.mjs +186 -0
- package/dist/shared/server.BRoxSiSC.d.mts +12 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.BjiJH9Vo.d.ts +10 -0
- package/dist/shared/server.Cy1vfSiG.d.ts +12 -0
- package/dist/{chunk-MHVECKBC.js → shared/server.DG7Tamti.mjs} +170 -224
- package/dist/shared/server.DPWk5pjW.d.mts +192 -0
- package/dist/shared/server.DPWk5pjW.d.ts +192 -0
- package/dist/shared/server.QUe9N8P4.d.mts +10 -0
- package/dist/shared/server.YZzrREz9.d.ts +74 -0
- package/dist/shared/server.eWLxY3lq.d.mts +74 -0
- package/package.json +57 -39
- package/dist/chunk-MBMXGUNI.js +0 -32
- package/dist/chunk-NTHCS5CK.js +0 -182
- package/dist/chunk-TXHKQO7N.js +0 -120
- package/dist/fetch.js +0 -10
- package/dist/hono.js +0 -34
- package/dist/index.js +0 -413
- package/dist/next.js +0 -31
- package/dist/node.js +0 -31
- package/dist/plugins.js +0 -11
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
- package/dist/src/adapters/fetch/types.d.ts +0 -14
- package/dist/src/adapters/hono/index.d.ts +0 -3
- package/dist/src/adapters/hono/middleware.d.ts +0 -12
- package/dist/src/adapters/next/index.d.ts +0 -3
- package/dist/src/adapters/next/serve.d.ts +0 -19
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
- package/dist/src/adapters/node/types.d.ts +0 -22
- package/dist/src/adapters/standard/handler.d.ts +0 -53
- package/dist/src/adapters/standard/index.d.ts +0 -6
- package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
- package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
- package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
- package/dist/src/adapters/standard/types.d.ts +0 -21
- package/dist/src/builder-variants.d.ts +0 -75
- package/dist/src/builder.d.ts +0 -58
- package/dist/src/config.d.ts +0 -6
- package/dist/src/context.d.ts +0 -8
- package/dist/src/error.d.ts +0 -12
- package/dist/src/hidden.d.ts +0 -8
- package/dist/src/implementer-procedure.d.ts +0 -33
- package/dist/src/implementer-variants.d.ts +0 -18
- package/dist/src/implementer.d.ts +0 -29
- package/dist/src/index.d.ts +0 -25
- package/dist/src/lazy-utils.d.ts +0 -6
- package/dist/src/lazy.d.ts +0 -22
- package/dist/src/middleware-decorated.d.ts +0 -11
- package/dist/src/middleware-utils.d.ts +0 -5
- package/dist/src/middleware.d.ts +0 -38
- package/dist/src/plugins/base.d.ts +0 -11
- package/dist/src/plugins/cors.d.ts +0 -19
- package/dist/src/plugins/index.d.ts +0 -4
- package/dist/src/plugins/response-headers.d.ts +0 -10
- package/dist/src/procedure-client.d.ts +0 -33
- package/dist/src/procedure-decorated.d.ts +0 -24
- package/dist/src/procedure-utils.d.ts +0 -19
- package/dist/src/procedure.d.ts +0 -31
- package/dist/src/router-accessible-lazy.d.ts +0 -8
- package/dist/src/router-client.d.ts +0 -12
- package/dist/src/router.d.ts +0 -30
- package/dist/src/utils.d.ts +0 -24
- package/dist/standard.js +0 -13
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.cac5dd3",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -15,66 +15,84 @@
|
|
15
15
|
],
|
16
16
|
"exports": {
|
17
17
|
".": {
|
18
|
-
"types": "./dist/
|
19
|
-
"import": "./dist/index.
|
20
|
-
"default": "./dist/index.
|
18
|
+
"types": "./dist/index.d.mts",
|
19
|
+
"import": "./dist/index.mjs",
|
20
|
+
"default": "./dist/index.mjs"
|
21
21
|
},
|
22
22
|
"./plugins": {
|
23
|
-
"types": "./dist/
|
24
|
-
"import": "./dist/plugins.
|
25
|
-
"default": "./dist/plugins.
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
26
26
|
},
|
27
27
|
"./standard": {
|
28
|
-
"types": "./dist/
|
29
|
-
"import": "./dist/standard.
|
30
|
-
"default": "./dist/standard.
|
28
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
29
|
+
"import": "./dist/adapters/standard/index.mjs",
|
30
|
+
"default": "./dist/adapters/standard/index.mjs"
|
31
31
|
},
|
32
32
|
"./fetch": {
|
33
|
-
"types": "./dist/
|
34
|
-
"import": "./dist/fetch.
|
35
|
-
"default": "./dist/fetch.
|
33
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
34
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
35
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
36
36
|
},
|
37
|
-
"./
|
38
|
-
"types": "./dist/
|
39
|
-
"import": "./dist/
|
40
|
-
"default": "./dist/
|
37
|
+
"./node": {
|
38
|
+
"types": "./dist/adapters/node/index.d.mts",
|
39
|
+
"import": "./dist/adapters/node/index.mjs",
|
40
|
+
"default": "./dist/adapters/node/index.mjs"
|
41
41
|
},
|
42
|
-
"./
|
43
|
-
"types": "./dist/
|
44
|
-
"import": "./dist/
|
45
|
-
"default": "./dist/
|
42
|
+
"./websocket": {
|
43
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
44
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
45
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
46
46
|
},
|
47
|
-
"./
|
48
|
-
"types": "./dist/
|
49
|
-
"import": "./dist/
|
50
|
-
"default": "./dist/
|
47
|
+
"./crossws": {
|
48
|
+
"types": "./dist/adapters/crossws/index.d.mts",
|
49
|
+
"import": "./dist/adapters/crossws/index.mjs",
|
50
|
+
"default": "./dist/adapters/crossws/index.mjs"
|
51
|
+
},
|
52
|
+
"./ws": {
|
53
|
+
"types": "./dist/adapters/ws/index.d.mts",
|
54
|
+
"import": "./dist/adapters/ws/index.mjs",
|
55
|
+
"default": "./dist/adapters/ws/index.mjs"
|
51
56
|
},
|
52
|
-
"
|
53
|
-
"types": "./dist/
|
57
|
+
"./bun-ws": {
|
58
|
+
"types": "./dist/adapters/bun-ws/index.d.mts",
|
59
|
+
"import": "./dist/adapters/bun-ws/index.mjs",
|
60
|
+
"default": "./dist/adapters/bun-ws/index.mjs"
|
54
61
|
}
|
55
62
|
},
|
56
63
|
"files": [
|
57
|
-
"!**/*.map",
|
58
|
-
"!**/*.tsbuildinfo",
|
59
64
|
"dist"
|
60
65
|
],
|
61
66
|
"peerDependencies": {
|
62
|
-
"
|
63
|
-
"
|
67
|
+
"crossws": ">=0.3.4",
|
68
|
+
"ws": ">=8.18.1"
|
69
|
+
},
|
70
|
+
"peerDependenciesMeta": {
|
71
|
+
"crossws": {
|
72
|
+
"optional": true
|
73
|
+
},
|
74
|
+
"ws": {
|
75
|
+
"optional": true
|
76
|
+
}
|
64
77
|
},
|
65
78
|
"dependencies": {
|
66
|
-
"@orpc/client": "0.0.0-next.
|
67
|
-
"@orpc/
|
68
|
-
"@orpc/
|
69
|
-
"@orpc/standard-server
|
70
|
-
"@orpc/
|
71
|
-
"@orpc/standard-server-node": "0.0.0-next.
|
79
|
+
"@orpc/client": "0.0.0-next.cac5dd3",
|
80
|
+
"@orpc/shared": "0.0.0-next.cac5dd3",
|
81
|
+
"@orpc/contract": "0.0.0-next.cac5dd3",
|
82
|
+
"@orpc/standard-server": "0.0.0-next.cac5dd3",
|
83
|
+
"@orpc/standard-server-fetch": "0.0.0-next.cac5dd3",
|
84
|
+
"@orpc/standard-server-node": "0.0.0-next.cac5dd3",
|
85
|
+
"@orpc/standard-server-peer": "0.0.0-next.cac5dd3"
|
72
86
|
},
|
73
87
|
"devDependencies": {
|
74
|
-
"
|
88
|
+
"@types/ws": "^8.18.1",
|
89
|
+
"crossws": "^0.3.4",
|
90
|
+
"next": "^15.3.0",
|
91
|
+
"supertest": "^7.1.0",
|
92
|
+
"ws": "^8.18.1"
|
75
93
|
},
|
76
94
|
"scripts": {
|
77
|
-
"build": "
|
95
|
+
"build": "unbuild",
|
78
96
|
"build:watch": "pnpm run build --watch",
|
79
97
|
"type:check": "tsc -b"
|
80
98
|
}
|
package/dist/chunk-MBMXGUNI.js
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCCodec,
|
3
|
-
RPCMatcher,
|
4
|
-
StandardHandler
|
5
|
-
} from "./chunk-NTHCS5CK.js";
|
6
|
-
|
7
|
-
// src/adapters/fetch/rpc-handler.ts
|
8
|
-
import { toFetchResponse, toStandardRequest } from "@orpc/standard-server-fetch";
|
9
|
-
var RPCHandler = class {
|
10
|
-
standardHandler;
|
11
|
-
constructor(router, options) {
|
12
|
-
const matcher = options?.matcher ?? new RPCMatcher();
|
13
|
-
const codec = options?.codec ?? new RPCCodec();
|
14
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
15
|
-
}
|
16
|
-
async handle(request, ...rest) {
|
17
|
-
const standardRequest = toStandardRequest(request);
|
18
|
-
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
19
|
-
if (!result.matched) {
|
20
|
-
return result;
|
21
|
-
}
|
22
|
-
return {
|
23
|
-
matched: true,
|
24
|
-
response: toFetchResponse(result.response)
|
25
|
-
};
|
26
|
-
}
|
27
|
-
};
|
28
|
-
|
29
|
-
export {
|
30
|
-
RPCHandler
|
31
|
-
};
|
32
|
-
//# sourceMappingURL=chunk-MBMXGUNI.js.map
|
package/dist/chunk-NTHCS5CK.js
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
convertPathToHttpPath,
|
3
|
-
createContractedProcedure,
|
4
|
-
createProcedureClient,
|
5
|
-
eachContractProcedure,
|
6
|
-
getRouterChild,
|
7
|
-
isProcedure,
|
8
|
-
unlazy
|
9
|
-
} from "./chunk-MHVECKBC.js";
|
10
|
-
import {
|
11
|
-
CompositePlugin
|
12
|
-
} from "./chunk-TXHKQO7N.js";
|
13
|
-
|
14
|
-
// src/adapters/standard/handler.ts
|
15
|
-
import { ORPCError, toORPCError } from "@orpc/client";
|
16
|
-
import { intercept, trim } from "@orpc/shared";
|
17
|
-
var StandardHandler = class {
|
18
|
-
constructor(router, matcher, codec, options = {}) {
|
19
|
-
this.matcher = matcher;
|
20
|
-
this.codec = codec;
|
21
|
-
this.options = options;
|
22
|
-
this.plugin = new CompositePlugin(options.plugins);
|
23
|
-
this.plugin.init(this.options);
|
24
|
-
this.matcher.init(router);
|
25
|
-
}
|
26
|
-
plugin;
|
27
|
-
handle(request, ...[options]) {
|
28
|
-
return intercept(
|
29
|
-
this.options.rootInterceptors ?? [],
|
30
|
-
{
|
31
|
-
request,
|
32
|
-
...options,
|
33
|
-
context: options?.context ?? {}
|
34
|
-
// context is optional only when all fields are optional so we can safely force it to have a context
|
35
|
-
},
|
36
|
-
async (interceptorOptions) => {
|
37
|
-
let isDecoding = false;
|
38
|
-
try {
|
39
|
-
return await intercept(
|
40
|
-
this.options.interceptors ?? [],
|
41
|
-
interceptorOptions,
|
42
|
-
async (interceptorOptions2) => {
|
43
|
-
const method = interceptorOptions2.request.method;
|
44
|
-
const url = interceptorOptions2.request.url;
|
45
|
-
const pathname = `/${trim(url.pathname.replace(interceptorOptions2.prefix ?? "", ""), "/")}`;
|
46
|
-
const match = await this.matcher.match(method, pathname);
|
47
|
-
if (!match) {
|
48
|
-
return { matched: false, response: void 0 };
|
49
|
-
}
|
50
|
-
const client = createProcedureClient(match.procedure, {
|
51
|
-
context: interceptorOptions2.context,
|
52
|
-
path: match.path,
|
53
|
-
interceptors: this.options.clientInterceptors
|
54
|
-
});
|
55
|
-
isDecoding = true;
|
56
|
-
const input = await this.codec.decode(request, match.params, match.procedure);
|
57
|
-
isDecoding = false;
|
58
|
-
const lastEventId = Array.isArray(request.headers["last-event-id"]) ? request.headers["last-event-id"].at(-1) : request.headers["last-event-id"];
|
59
|
-
const output = await client(input, { signal: request.signal, lastEventId });
|
60
|
-
const response = this.codec.encode(output, match.procedure);
|
61
|
-
return {
|
62
|
-
matched: true,
|
63
|
-
response
|
64
|
-
};
|
65
|
-
}
|
66
|
-
);
|
67
|
-
} catch (e) {
|
68
|
-
const error = isDecoding ? new ORPCError("BAD_REQUEST", {
|
69
|
-
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
70
|
-
cause: e
|
71
|
-
}) : toORPCError(e);
|
72
|
-
const response = this.codec.encodeError(error);
|
73
|
-
return {
|
74
|
-
matched: true,
|
75
|
-
response
|
76
|
-
};
|
77
|
-
}
|
78
|
-
}
|
79
|
-
);
|
80
|
-
}
|
81
|
-
};
|
82
|
-
|
83
|
-
// src/adapters/standard/rpc-codec.ts
|
84
|
-
import { RPCSerializer } from "@orpc/client/rpc";
|
85
|
-
import { parseEmptyableJSON } from "@orpc/shared";
|
86
|
-
var RPCCodec = class {
|
87
|
-
serializer;
|
88
|
-
constructor(options = {}) {
|
89
|
-
this.serializer = options.serializer ?? new RPCSerializer();
|
90
|
-
}
|
91
|
-
async decode(request, _params, _procedure) {
|
92
|
-
const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
|
93
|
-
return this.serializer.deserialize(serialized);
|
94
|
-
}
|
95
|
-
encode(output, _procedure) {
|
96
|
-
return {
|
97
|
-
status: 200,
|
98
|
-
headers: {},
|
99
|
-
body: this.serializer.serialize(output)
|
100
|
-
};
|
101
|
-
}
|
102
|
-
encodeError(error) {
|
103
|
-
return {
|
104
|
-
status: error.status,
|
105
|
-
headers: {},
|
106
|
-
body: this.serializer.serialize(error.toJSON())
|
107
|
-
};
|
108
|
-
}
|
109
|
-
};
|
110
|
-
|
111
|
-
// src/adapters/standard/rpc-matcher.ts
|
112
|
-
var RPCMatcher = class {
|
113
|
-
tree = {};
|
114
|
-
pendingRouters = [];
|
115
|
-
init(router, path = []) {
|
116
|
-
const laziedOptions = eachContractProcedure({
|
117
|
-
router,
|
118
|
-
path
|
119
|
-
}, ({ path: path2, contract }) => {
|
120
|
-
const httpPath = convertPathToHttpPath(path2);
|
121
|
-
if (isProcedure(contract)) {
|
122
|
-
this.tree[httpPath] = {
|
123
|
-
path: path2,
|
124
|
-
contract,
|
125
|
-
procedure: contract,
|
126
|
-
// this mean dev not used contract-first so we can used contract as procedure directly
|
127
|
-
router
|
128
|
-
};
|
129
|
-
} else {
|
130
|
-
this.tree[httpPath] = {
|
131
|
-
path: path2,
|
132
|
-
contract,
|
133
|
-
procedure: void 0,
|
134
|
-
router
|
135
|
-
};
|
136
|
-
}
|
137
|
-
});
|
138
|
-
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
139
|
-
...option,
|
140
|
-
httpPathPrefix: convertPathToHttpPath(option.path)
|
141
|
-
})));
|
142
|
-
}
|
143
|
-
async match(_method, pathname) {
|
144
|
-
if (this.pendingRouters.length) {
|
145
|
-
const newPendingRouters = [];
|
146
|
-
for (const pendingRouter of this.pendingRouters) {
|
147
|
-
if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
148
|
-
const { default: router } = await unlazy(pendingRouter.lazied);
|
149
|
-
this.init(router, pendingRouter.path);
|
150
|
-
} else {
|
151
|
-
newPendingRouters.push(pendingRouter);
|
152
|
-
}
|
153
|
-
}
|
154
|
-
this.pendingRouters = newPendingRouters;
|
155
|
-
}
|
156
|
-
const match = this.tree[pathname];
|
157
|
-
if (!match) {
|
158
|
-
return void 0;
|
159
|
-
}
|
160
|
-
if (!match.procedure) {
|
161
|
-
const { default: maybeProcedure } = await unlazy(getRouterChild(match.router, ...match.path));
|
162
|
-
if (!isProcedure(maybeProcedure)) {
|
163
|
-
throw new Error(`
|
164
|
-
[Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.path)}.
|
165
|
-
Ensure that the procedure is correctly defined and matches the expected contract.
|
166
|
-
`);
|
167
|
-
}
|
168
|
-
match.procedure = createContractedProcedure(match.contract, maybeProcedure);
|
169
|
-
}
|
170
|
-
return {
|
171
|
-
path: match.path,
|
172
|
-
procedure: match.procedure
|
173
|
-
};
|
174
|
-
}
|
175
|
-
};
|
176
|
-
|
177
|
-
export {
|
178
|
-
StandardHandler,
|
179
|
-
RPCCodec,
|
180
|
-
RPCMatcher
|
181
|
-
};
|
182
|
-
//# sourceMappingURL=chunk-NTHCS5CK.js.map
|
package/dist/chunk-TXHKQO7N.js
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
// src/plugins/base.ts
|
2
|
-
var CompositePlugin = class {
|
3
|
-
constructor(plugins = []) {
|
4
|
-
this.plugins = plugins;
|
5
|
-
}
|
6
|
-
init(options) {
|
7
|
-
for (const plugin of this.plugins) {
|
8
|
-
plugin.init?.(options);
|
9
|
-
}
|
10
|
-
}
|
11
|
-
};
|
12
|
-
|
13
|
-
// src/plugins/cors.ts
|
14
|
-
import { value } from "@orpc/shared";
|
15
|
-
var CORSPlugin = class {
|
16
|
-
options;
|
17
|
-
constructor(options) {
|
18
|
-
const defaults = {
|
19
|
-
origin: (origin) => origin,
|
20
|
-
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
21
|
-
};
|
22
|
-
this.options = {
|
23
|
-
...defaults,
|
24
|
-
...options
|
25
|
-
};
|
26
|
-
}
|
27
|
-
init(options) {
|
28
|
-
options.rootInterceptors ??= [];
|
29
|
-
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
30
|
-
if (interceptorOptions.request.method === "OPTIONS") {
|
31
|
-
const resHeaders = {};
|
32
|
-
if (this.options.maxAge !== void 0) {
|
33
|
-
resHeaders["access-control-max-age"] = this.options.maxAge.toString();
|
34
|
-
}
|
35
|
-
if (this.options.allowMethods?.length) {
|
36
|
-
resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
|
37
|
-
}
|
38
|
-
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
|
39
|
-
if (Array.isArray(allowHeaders) && allowHeaders.length) {
|
40
|
-
resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
|
41
|
-
} else if (typeof allowHeaders === "string") {
|
42
|
-
resHeaders["access-control-allow-headers"] = allowHeaders;
|
43
|
-
}
|
44
|
-
return {
|
45
|
-
matched: true,
|
46
|
-
response: {
|
47
|
-
status: 204,
|
48
|
-
headers: resHeaders,
|
49
|
-
body: void 0
|
50
|
-
}
|
51
|
-
};
|
52
|
-
}
|
53
|
-
return interceptorOptions.next();
|
54
|
-
});
|
55
|
-
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
56
|
-
const result = await interceptorOptions.next();
|
57
|
-
if (!result.matched) {
|
58
|
-
return result;
|
59
|
-
}
|
60
|
-
const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
|
61
|
-
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
62
|
-
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
63
|
-
if (allowedOriginArr.includes("*")) {
|
64
|
-
result.response.headers["access-control-allow-origin"] = "*";
|
65
|
-
} else {
|
66
|
-
if (allowedOriginArr.includes(origin)) {
|
67
|
-
result.response.headers["access-control-allow-origin"] = origin;
|
68
|
-
}
|
69
|
-
result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
|
70
|
-
}
|
71
|
-
const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
|
72
|
-
const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
|
73
|
-
if (allowedTimingOriginArr.includes("*")) {
|
74
|
-
result.response.headers["timing-allow-origin"] = "*";
|
75
|
-
} else if (allowedTimingOriginArr.includes(origin)) {
|
76
|
-
result.response.headers["timing-allow-origin"] = origin;
|
77
|
-
}
|
78
|
-
if (this.options.credentials) {
|
79
|
-
result.response.headers["access-control-allow-credentials"] = "true";
|
80
|
-
}
|
81
|
-
if (this.options.exposeHeaders?.length) {
|
82
|
-
result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
|
83
|
-
}
|
84
|
-
return result;
|
85
|
-
});
|
86
|
-
}
|
87
|
-
};
|
88
|
-
|
89
|
-
// src/plugins/response-headers.ts
|
90
|
-
var ResponseHeadersPlugin = class {
|
91
|
-
init(options) {
|
92
|
-
options.rootInterceptors ??= [];
|
93
|
-
options.rootInterceptors.push(async (interceptorOptions) => {
|
94
|
-
const headers = new Headers();
|
95
|
-
interceptorOptions.context.resHeaders = headers;
|
96
|
-
const result = await interceptorOptions.next();
|
97
|
-
if (!result.matched) {
|
98
|
-
return result;
|
99
|
-
}
|
100
|
-
const responseHeaders = result.response.headers;
|
101
|
-
for (const [key, value2] of headers) {
|
102
|
-
if (Array.isArray(responseHeaders[key])) {
|
103
|
-
responseHeaders[key].push(value2);
|
104
|
-
} else if (responseHeaders[key] !== void 0) {
|
105
|
-
responseHeaders[key] = [responseHeaders[key], value2];
|
106
|
-
} else {
|
107
|
-
responseHeaders[key] = value2;
|
108
|
-
}
|
109
|
-
}
|
110
|
-
return result;
|
111
|
-
});
|
112
|
-
}
|
113
|
-
};
|
114
|
-
|
115
|
-
export {
|
116
|
-
CompositePlugin,
|
117
|
-
CORSPlugin,
|
118
|
-
ResponseHeadersPlugin
|
119
|
-
};
|
120
|
-
//# sourceMappingURL=chunk-TXHKQO7N.js.map
|
package/dist/fetch.js
DELETED
package/dist/hono.js
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCHandler
|
3
|
-
} from "./chunk-MBMXGUNI.js";
|
4
|
-
import "./chunk-NTHCS5CK.js";
|
5
|
-
import "./chunk-MHVECKBC.js";
|
6
|
-
import "./chunk-TXHKQO7N.js";
|
7
|
-
|
8
|
-
// src/adapters/hono/middleware.ts
|
9
|
-
import { value } from "@orpc/shared";
|
10
|
-
function createMiddleware(handler, ...[options]) {
|
11
|
-
return async (c, next) => {
|
12
|
-
const bodyProps = /* @__PURE__ */ new Set(["arrayBuffer", "blob", "formData", "json", "text"]);
|
13
|
-
const request = c.req.method === "GET" || c.req.method === "HEAD" ? c.req.raw : new Proxy(c.req.raw, {
|
14
|
-
// https://github.com/honojs/middleware/blob/main/packages/trpc-server/src/index.ts#L39
|
15
|
-
get(target, prop) {
|
16
|
-
if (bodyProps.has(prop)) {
|
17
|
-
return () => c.req[prop]();
|
18
|
-
}
|
19
|
-
return Reflect.get(target, prop, target);
|
20
|
-
}
|
21
|
-
});
|
22
|
-
const context = await value(options?.context ?? {}, c);
|
23
|
-
const { matched, response } = await handler.handle(request, { ...options, context });
|
24
|
-
if (matched) {
|
25
|
-
return c.newResponse(response.body, response);
|
26
|
-
}
|
27
|
-
await next();
|
28
|
-
};
|
29
|
-
}
|
30
|
-
export {
|
31
|
-
RPCHandler,
|
32
|
-
createMiddleware
|
33
|
-
};
|
34
|
-
//# sourceMappingURL=hono.js.map
|