@orpc/server 0.0.0-next.f56d2b3 → 0.0.0-next.f710cd7
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 +127 -0
- package/dist/adapters/fetch/index.d.mts +70 -0
- package/dist/adapters/fetch/index.d.ts +70 -0
- package/dist/adapters/fetch/index.mjs +105 -0
- package/dist/adapters/node/index.d.mts +69 -0
- package/dist/adapters/node/index.d.ts +69 -0
- package/dist/adapters/node/index.mjs +90 -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 +8 -0
- package/dist/index.d.mts +829 -0
- package/dist/index.d.ts +829 -0
- package/dist/index.mjs +471 -0
- package/dist/plugins/index.d.mts +156 -0
- package/dist/plugins/index.d.ts +156 -0
- package/dist/plugins/index.mjs +252 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.CN0534_m.d.mts +18 -0
- package/dist/shared/server.CjlA3NKP.d.ts +10 -0
- package/dist/shared/server.CuD15qZB.d.ts +18 -0
- package/dist/shared/server.D5fBlF9j.d.ts +74 -0
- package/dist/shared/server.DG7Tamti.mjs +367 -0
- package/dist/shared/server.DPWk5pjW.d.mts +192 -0
- package/dist/shared/server.DPWk5pjW.d.ts +192 -0
- package/dist/shared/server.DY7OKEoj.d.mts +74 -0
- package/dist/shared/server.DjgtLwKi.d.mts +10 -0
- package/dist/shared/server.qf03T-Xn.mjs +190 -0
- package/package.json +29 -31
- package/dist/chunk-ESTRJAOX.js +0 -299
- package/dist/chunk-KK4SDLC7.js +0 -320
- package/dist/chunk-WUOGVGWG.js +0 -1
- package/dist/fetch.js +0 -15
- package/dist/hono.js +0 -30
- package/dist/index.js +0 -391
- package/dist/next.js +0 -36
- package/dist/node.js +0 -87
- package/dist/src/adapters/fetch/index.d.ts +0 -6
- package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
- package/dist/src/adapters/fetch/super-json.d.ts +0 -12
- package/dist/src/adapters/fetch/types.d.ts +0 -21
- 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 -5
- package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
- package/dist/src/adapters/node/request-listener.d.ts +0 -28
- package/dist/src/adapters/node/types.d.ts +0 -22
- package/dist/src/builder-variants.d.ts +0 -74
- package/dist/src/builder.d.ts +0 -57
- package/dist/src/config.d.ts +0 -6
- package/dist/src/context.d.ts +0 -9
- package/dist/src/hidden.d.ts +0 -8
- package/dist/src/implementer-procedure.d.ts +0 -30
- package/dist/src/implementer-variants.d.ts +0 -16
- package/dist/src/implementer.d.ts +0 -27
- package/dist/src/index.d.ts +0 -21
- 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 -10
- package/dist/src/middleware-utils.d.ts +0 -5
- package/dist/src/middleware.d.ts +0 -37
- package/dist/src/procedure-client.d.ts +0 -20
- package/dist/src/procedure-decorated.d.ts +0 -21
- package/dist/src/procedure-utils.d.ts +0 -17
- package/dist/src/procedure.d.ts +0 -29
- package/dist/src/router-accessible-lazy.d.ts +0 -8
- package/dist/src/router-client.d.ts +0 -22
- package/dist/src/router.d.ts +0 -29
package/dist/index.js
DELETED
@@ -1,391 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
LAZY_LOADER_SYMBOL,
|
3
|
-
Procedure,
|
4
|
-
adaptRouter,
|
5
|
-
addMiddleware,
|
6
|
-
createAccessibleLazyRouter,
|
7
|
-
createLazyProcedureFormAnyLazy,
|
8
|
-
createProcedureClient,
|
9
|
-
deepSetLazyRouterPrefix,
|
10
|
-
flatLazy,
|
11
|
-
getLazyRouterPrefix,
|
12
|
-
getRouterChild,
|
13
|
-
getRouterContract,
|
14
|
-
isLazy,
|
15
|
-
isProcedure,
|
16
|
-
lazy,
|
17
|
-
middlewareOutputFn,
|
18
|
-
setRouterContract,
|
19
|
-
unlazy
|
20
|
-
} from "./chunk-KK4SDLC7.js";
|
21
|
-
|
22
|
-
// src/builder.ts
|
23
|
-
import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
|
24
|
-
|
25
|
-
// src/config.ts
|
26
|
-
var DEFAULT_CONFIG = {
|
27
|
-
initialInputValidationIndex: 0,
|
28
|
-
initialOutputValidationIndex: 0
|
29
|
-
};
|
30
|
-
function fallbackConfig(key, value) {
|
31
|
-
if (value === void 0) {
|
32
|
-
return DEFAULT_CONFIG[key];
|
33
|
-
}
|
34
|
-
return value;
|
35
|
-
}
|
36
|
-
|
37
|
-
// src/middleware-decorated.ts
|
38
|
-
function decorateMiddleware(middleware) {
|
39
|
-
const decorated = middleware;
|
40
|
-
decorated.mapInput = (mapInput) => {
|
41
|
-
const mapped = decorateMiddleware(
|
42
|
-
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
43
|
-
);
|
44
|
-
return mapped;
|
45
|
-
};
|
46
|
-
decorated.concat = (concatMiddleware, mapInput) => {
|
47
|
-
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
48
|
-
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
49
|
-
const next = async (...[nextOptions]) => {
|
50
|
-
return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
|
51
|
-
};
|
52
|
-
const merged = middleware({ ...options, next }, input, output, ...rest);
|
53
|
-
return merged;
|
54
|
-
});
|
55
|
-
return concatted;
|
56
|
-
};
|
57
|
-
return decorated;
|
58
|
-
}
|
59
|
-
|
60
|
-
// src/procedure-decorated.ts
|
61
|
-
import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
|
62
|
-
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
63
|
-
errors(errors) {
|
64
|
-
return new _DecoratedProcedure({
|
65
|
-
...this["~orpc"],
|
66
|
-
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
67
|
-
});
|
68
|
-
}
|
69
|
-
meta(meta) {
|
70
|
-
return new _DecoratedProcedure({
|
71
|
-
...this["~orpc"],
|
72
|
-
meta: mergeMeta(this["~orpc"].meta, meta)
|
73
|
-
});
|
74
|
-
}
|
75
|
-
route(route) {
|
76
|
-
return new _DecoratedProcedure({
|
77
|
-
...this["~orpc"],
|
78
|
-
route: mergeRoute(this["~orpc"].route, route)
|
79
|
-
});
|
80
|
-
}
|
81
|
-
use(middleware, mapInput) {
|
82
|
-
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
83
|
-
return new _DecoratedProcedure({
|
84
|
-
...this["~orpc"],
|
85
|
-
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
86
|
-
});
|
87
|
-
}
|
88
|
-
/**
|
89
|
-
* Make this procedure callable (works like a function while still being a procedure).
|
90
|
-
*/
|
91
|
-
callable(...rest) {
|
92
|
-
return Object.assign(createProcedureClient(this, ...rest), {
|
93
|
-
"~type": "Procedure",
|
94
|
-
"~orpc": this["~orpc"]
|
95
|
-
});
|
96
|
-
}
|
97
|
-
/**
|
98
|
-
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
99
|
-
*/
|
100
|
-
actionable(...rest) {
|
101
|
-
return this.callable(...rest);
|
102
|
-
}
|
103
|
-
};
|
104
|
-
|
105
|
-
// src/builder.ts
|
106
|
-
var Builder = class _Builder {
|
107
|
-
"~orpc";
|
108
|
-
constructor(def) {
|
109
|
-
this["~orpc"] = def;
|
110
|
-
}
|
111
|
-
/**
|
112
|
-
* Reset config
|
113
|
-
*/
|
114
|
-
$config(config) {
|
115
|
-
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
116
|
-
const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
|
117
|
-
return new _Builder({
|
118
|
-
...this["~orpc"],
|
119
|
-
config,
|
120
|
-
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
121
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
122
|
-
});
|
123
|
-
}
|
124
|
-
/**
|
125
|
-
* Reset initial context
|
126
|
-
*/
|
127
|
-
$context() {
|
128
|
-
return new _Builder({
|
129
|
-
...this["~orpc"],
|
130
|
-
middlewares: [],
|
131
|
-
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
132
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
|
133
|
-
});
|
134
|
-
}
|
135
|
-
/**
|
136
|
-
* Reset initial meta
|
137
|
-
*/
|
138
|
-
$meta(initialMeta) {
|
139
|
-
return new _Builder({
|
140
|
-
...this["~orpc"],
|
141
|
-
meta: initialMeta
|
142
|
-
});
|
143
|
-
}
|
144
|
-
/**
|
145
|
-
* Reset initial route
|
146
|
-
*/
|
147
|
-
$route(initialRoute) {
|
148
|
-
return new _Builder({
|
149
|
-
...this["~orpc"],
|
150
|
-
route: initialRoute
|
151
|
-
});
|
152
|
-
}
|
153
|
-
middleware(middleware) {
|
154
|
-
return decorateMiddleware(middleware);
|
155
|
-
}
|
156
|
-
errors(errors) {
|
157
|
-
return new _Builder({
|
158
|
-
...this["~orpc"],
|
159
|
-
errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
|
160
|
-
});
|
161
|
-
}
|
162
|
-
use(middleware, mapInput) {
|
163
|
-
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
164
|
-
return new _Builder({
|
165
|
-
...this["~orpc"],
|
166
|
-
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
167
|
-
});
|
168
|
-
}
|
169
|
-
meta(meta) {
|
170
|
-
return new _Builder({
|
171
|
-
...this["~orpc"],
|
172
|
-
meta: mergeMeta2(this["~orpc"].meta, meta)
|
173
|
-
});
|
174
|
-
}
|
175
|
-
route(route) {
|
176
|
-
return new _Builder({
|
177
|
-
...this["~orpc"],
|
178
|
-
route: mergeRoute2(this["~orpc"].route, route)
|
179
|
-
});
|
180
|
-
}
|
181
|
-
input(schema) {
|
182
|
-
return new _Builder({
|
183
|
-
...this["~orpc"],
|
184
|
-
inputSchema: schema,
|
185
|
-
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
186
|
-
});
|
187
|
-
}
|
188
|
-
output(schema) {
|
189
|
-
return new _Builder({
|
190
|
-
...this["~orpc"],
|
191
|
-
outputSchema: schema,
|
192
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
193
|
-
});
|
194
|
-
}
|
195
|
-
handler(handler) {
|
196
|
-
return new DecoratedProcedure({
|
197
|
-
...this["~orpc"],
|
198
|
-
handler
|
199
|
-
});
|
200
|
-
}
|
201
|
-
prefix(prefix) {
|
202
|
-
return new _Builder({
|
203
|
-
...this["~orpc"],
|
204
|
-
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
205
|
-
});
|
206
|
-
}
|
207
|
-
tag(...tags) {
|
208
|
-
return new _Builder({
|
209
|
-
...this["~orpc"],
|
210
|
-
tags: mergeTags(this["~orpc"].tags, tags)
|
211
|
-
});
|
212
|
-
}
|
213
|
-
router(router) {
|
214
|
-
return adaptRouter(router, this["~orpc"]);
|
215
|
-
}
|
216
|
-
lazy(loader) {
|
217
|
-
return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
|
218
|
-
}
|
219
|
-
};
|
220
|
-
var os = new Builder({
|
221
|
-
config: {},
|
222
|
-
route: {},
|
223
|
-
meta: {},
|
224
|
-
errorMap: {},
|
225
|
-
inputSchema: void 0,
|
226
|
-
outputSchema: void 0,
|
227
|
-
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
228
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
229
|
-
middlewares: []
|
230
|
-
});
|
231
|
-
|
232
|
-
// src/context.ts
|
233
|
-
function mergeContext(context, other) {
|
234
|
-
return { ...context, ...other };
|
235
|
-
}
|
236
|
-
|
237
|
-
// src/implementer.ts
|
238
|
-
import { isContractProcedure } from "@orpc/contract";
|
239
|
-
function implementerInternal(contract, config, middlewares) {
|
240
|
-
if (isContractProcedure(contract)) {
|
241
|
-
const impl2 = new Builder({
|
242
|
-
...contract["~orpc"],
|
243
|
-
config,
|
244
|
-
middlewares,
|
245
|
-
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
246
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
247
|
-
});
|
248
|
-
return impl2;
|
249
|
-
}
|
250
|
-
const impl = new Proxy(contract, {
|
251
|
-
get: (target, key) => {
|
252
|
-
let method;
|
253
|
-
if (key === "middleware") {
|
254
|
-
method = (mid) => decorateMiddleware(mid);
|
255
|
-
} else if (key === "use") {
|
256
|
-
method = (mid) => {
|
257
|
-
return implementerInternal(
|
258
|
-
contract,
|
259
|
-
config,
|
260
|
-
addMiddleware(middlewares, mid)
|
261
|
-
);
|
262
|
-
};
|
263
|
-
} else if (key === "router") {
|
264
|
-
method = (router) => {
|
265
|
-
const adapted = adaptRouter(router, {
|
266
|
-
middlewares,
|
267
|
-
errorMap: {}
|
268
|
-
});
|
269
|
-
return setRouterContract(adapted, contract);
|
270
|
-
};
|
271
|
-
} else if (key === "lazy") {
|
272
|
-
method = (loader) => {
|
273
|
-
const adapted = adaptRouter(flatLazy(lazy(loader)), {
|
274
|
-
middlewares,
|
275
|
-
errorMap: {}
|
276
|
-
});
|
277
|
-
return setRouterContract(adapted, contract);
|
278
|
-
};
|
279
|
-
}
|
280
|
-
const next = Reflect.get(target, key);
|
281
|
-
if (!next || typeof next !== "function" && typeof next !== "object") {
|
282
|
-
return method ?? next;
|
283
|
-
}
|
284
|
-
const nextImpl = implementerInternal(next, config, middlewares);
|
285
|
-
if (method) {
|
286
|
-
return new Proxy(method, {
|
287
|
-
get(_, key2) {
|
288
|
-
return Reflect.get(nextImpl, key2);
|
289
|
-
}
|
290
|
-
});
|
291
|
-
}
|
292
|
-
return nextImpl;
|
293
|
-
}
|
294
|
-
});
|
295
|
-
return impl;
|
296
|
-
}
|
297
|
-
function implement(contract, config = {}) {
|
298
|
-
const implInternal = implementerInternal(contract, config, []);
|
299
|
-
const impl = new Proxy(implInternal, {
|
300
|
-
get: (target, key) => {
|
301
|
-
let method;
|
302
|
-
if (key === "$context") {
|
303
|
-
method = () => impl;
|
304
|
-
} else if (key === "$config") {
|
305
|
-
method = (config2) => implement(contract, config2);
|
306
|
-
}
|
307
|
-
const next = Reflect.get(target, key);
|
308
|
-
if (!next || typeof next !== "function" && typeof next !== "object") {
|
309
|
-
return method ?? next;
|
310
|
-
}
|
311
|
-
if (method) {
|
312
|
-
return new Proxy(method, {
|
313
|
-
get(_, key2) {
|
314
|
-
return Reflect.get(next, key2);
|
315
|
-
}
|
316
|
-
});
|
317
|
-
}
|
318
|
-
return next;
|
319
|
-
}
|
320
|
-
});
|
321
|
-
return impl;
|
322
|
-
}
|
323
|
-
|
324
|
-
// src/procedure-utils.ts
|
325
|
-
function call(procedure, input, ...rest) {
|
326
|
-
return createProcedureClient(procedure, ...rest)(input);
|
327
|
-
}
|
328
|
-
|
329
|
-
// src/router-client.ts
|
330
|
-
function createRouterClient(router, ...rest) {
|
331
|
-
if (isProcedure(router)) {
|
332
|
-
const caller = createProcedureClient(router, ...rest);
|
333
|
-
return caller;
|
334
|
-
}
|
335
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
336
|
-
const recursive = new Proxy(procedureCaller, {
|
337
|
-
get(target, key) {
|
338
|
-
if (typeof key !== "string") {
|
339
|
-
return Reflect.get(target, key);
|
340
|
-
}
|
341
|
-
const next = getRouterChild(router, key);
|
342
|
-
if (!next) {
|
343
|
-
return Reflect.get(target, key);
|
344
|
-
}
|
345
|
-
const [options] = rest;
|
346
|
-
return createRouterClient(next, {
|
347
|
-
...options,
|
348
|
-
path: [...options?.path ?? [], key]
|
349
|
-
});
|
350
|
-
}
|
351
|
-
});
|
352
|
-
return recursive;
|
353
|
-
}
|
354
|
-
|
355
|
-
// src/index.ts
|
356
|
-
import { isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
|
357
|
-
export {
|
358
|
-
Builder,
|
359
|
-
DecoratedProcedure,
|
360
|
-
LAZY_LOADER_SYMBOL,
|
361
|
-
ORPCError,
|
362
|
-
Procedure,
|
363
|
-
ValidationError,
|
364
|
-
adaptRouter,
|
365
|
-
call,
|
366
|
-
createAccessibleLazyRouter,
|
367
|
-
createLazyProcedureFormAnyLazy,
|
368
|
-
createProcedureClient,
|
369
|
-
createRouterClient,
|
370
|
-
decorateMiddleware,
|
371
|
-
deepSetLazyRouterPrefix,
|
372
|
-
fallbackConfig,
|
373
|
-
flatLazy,
|
374
|
-
getLazyRouterPrefix,
|
375
|
-
getRouterChild,
|
376
|
-
getRouterContract,
|
377
|
-
implement,
|
378
|
-
implementerInternal,
|
379
|
-
isDefinedError,
|
380
|
-
isLazy,
|
381
|
-
isProcedure,
|
382
|
-
lazy,
|
383
|
-
mergeContext,
|
384
|
-
middlewareOutputFn,
|
385
|
-
os,
|
386
|
-
safe,
|
387
|
-
setRouterContract,
|
388
|
-
type,
|
389
|
-
unlazy
|
390
|
-
};
|
391
|
-
//# sourceMappingURL=index.js.map
|
package/dist/next.js
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
import "./chunk-WUOGVGWG.js";
|
2
|
-
import {
|
3
|
-
ORPCPayloadCodec,
|
4
|
-
ORPCProcedureMatcher,
|
5
|
-
RPCHandler,
|
6
|
-
super_json_exports
|
7
|
-
} from "./chunk-ESTRJAOX.js";
|
8
|
-
import "./chunk-KK4SDLC7.js";
|
9
|
-
|
10
|
-
// src/adapters/next/serve.ts
|
11
|
-
import { value } from "@orpc/shared";
|
12
|
-
function serve(handler, ...[options]) {
|
13
|
-
const main = async (req) => {
|
14
|
-
const context = await value(options?.context ?? {}, req);
|
15
|
-
const { matched, response } = await handler.handle(req, { ...options, context });
|
16
|
-
if (matched) {
|
17
|
-
return response;
|
18
|
-
}
|
19
|
-
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
20
|
-
};
|
21
|
-
return {
|
22
|
-
GET: main,
|
23
|
-
POST: main,
|
24
|
-
PUT: main,
|
25
|
-
PATCH: main,
|
26
|
-
DELETE: main
|
27
|
-
};
|
28
|
-
}
|
29
|
-
export {
|
30
|
-
ORPCPayloadCodec,
|
31
|
-
ORPCProcedureMatcher,
|
32
|
-
RPCHandler,
|
33
|
-
super_json_exports as SuperJSON,
|
34
|
-
serve
|
35
|
-
};
|
36
|
-
//# sourceMappingURL=next.js.map
|
package/dist/node.js
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCHandler
|
3
|
-
} from "./chunk-ESTRJAOX.js";
|
4
|
-
import "./chunk-KK4SDLC7.js";
|
5
|
-
|
6
|
-
// src/adapters/node/request-listener.ts
|
7
|
-
function createRequest(req, res) {
|
8
|
-
const controller = new AbortController();
|
9
|
-
res.on("close", () => {
|
10
|
-
controller.abort();
|
11
|
-
});
|
12
|
-
const method = req.method ?? "GET";
|
13
|
-
const headers = createHeaders(req);
|
14
|
-
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
15
|
-
const host = headers.get("Host") ?? "localhost";
|
16
|
-
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
17
|
-
const init = { method, headers, signal: controller.signal };
|
18
|
-
if (method !== "GET" && method !== "HEAD") {
|
19
|
-
init.body = new ReadableStream({
|
20
|
-
start(controller2) {
|
21
|
-
req.on("data", (chunk) => {
|
22
|
-
controller2.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
23
|
-
});
|
24
|
-
req.on("end", () => {
|
25
|
-
controller2.close();
|
26
|
-
});
|
27
|
-
}
|
28
|
-
});
|
29
|
-
init.duplex = "half";
|
30
|
-
}
|
31
|
-
return new Request(url, init);
|
32
|
-
}
|
33
|
-
function createHeaders(req) {
|
34
|
-
const headers = new Headers();
|
35
|
-
const rawHeaders = req.rawHeaders;
|
36
|
-
for (let i = 0; i < rawHeaders.length; i += 2) {
|
37
|
-
headers.append(rawHeaders[i], rawHeaders[i + 1]);
|
38
|
-
}
|
39
|
-
return headers;
|
40
|
-
}
|
41
|
-
async function sendResponse(res, response) {
|
42
|
-
const headers = {};
|
43
|
-
for (const [key, value] of response.headers) {
|
44
|
-
if (key in headers) {
|
45
|
-
if (Array.isArray(headers[key])) {
|
46
|
-
headers[key].push(value);
|
47
|
-
} else {
|
48
|
-
headers[key] = [headers[key], value];
|
49
|
-
}
|
50
|
-
} else {
|
51
|
-
headers[key] = value;
|
52
|
-
}
|
53
|
-
}
|
54
|
-
res.writeHead(response.status, headers);
|
55
|
-
if (response.body != null && res.req.method !== "HEAD") {
|
56
|
-
for await (const chunk of response.body) {
|
57
|
-
res.write(chunk);
|
58
|
-
}
|
59
|
-
}
|
60
|
-
res.end();
|
61
|
-
}
|
62
|
-
|
63
|
-
// src/adapters/node/orpc-handler.ts
|
64
|
-
var RPCHandler2 = class {
|
65
|
-
orpcFetchHandler;
|
66
|
-
constructor(router, options) {
|
67
|
-
this.orpcFetchHandler = new RPCHandler(router, options);
|
68
|
-
}
|
69
|
-
async handle(req, res, ...rest) {
|
70
|
-
const request = createRequest(req, res);
|
71
|
-
const result = await this.orpcFetchHandler.handle(request, ...rest);
|
72
|
-
if (result.matched === false) {
|
73
|
-
return { matched: false };
|
74
|
-
}
|
75
|
-
const context = rest[0]?.context ?? {};
|
76
|
-
await rest[0]?.beforeSend?.(result.response, context);
|
77
|
-
await sendResponse(res, result.response);
|
78
|
-
return { matched: true };
|
79
|
-
}
|
80
|
-
};
|
81
|
-
export {
|
82
|
-
RPCHandler2 as RPCHandler,
|
83
|
-
createHeaders,
|
84
|
-
createRequest,
|
85
|
-
sendResponse
|
86
|
-
};
|
87
|
-
//# sourceMappingURL=node.js.map
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import type { Hooks } from '@orpc/shared';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
import type { Router } from '../../router';
|
4
|
-
import type { FetchHandler, FetchHandleRest, FetchHandleResult } from './types';
|
5
|
-
import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
|
6
|
-
import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
|
7
|
-
export type RPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
|
8
|
-
signal?: AbortSignal;
|
9
|
-
}> & {
|
10
|
-
procedureMatcher?: PublicORPCProcedureMatcher;
|
11
|
-
payloadCodec?: PublicORPCPayloadCodec;
|
12
|
-
};
|
13
|
-
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
14
|
-
private readonly options?;
|
15
|
-
private readonly procedureMatcher;
|
16
|
-
private readonly payloadCodec;
|
17
|
-
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>> | undefined);
|
18
|
-
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
19
|
-
}
|
20
|
-
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { type HTTPMethod } from '@orpc/contract';
|
2
|
-
export declare class ORPCPayloadCodec {
|
3
|
-
/**
|
4
|
-
* If method is GET, the payload will be encoded as query string.
|
5
|
-
* If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
|
6
|
-
*/
|
7
|
-
encode(payload: unknown, method?: HTTPMethod, fallbackMethod?: HTTPMethod): {
|
8
|
-
query?: URLSearchParams;
|
9
|
-
body?: FormData | string;
|
10
|
-
headers?: Headers;
|
11
|
-
method: HTTPMethod;
|
12
|
-
};
|
13
|
-
decode(re: Request | Response): Promise<unknown>;
|
14
|
-
}
|
15
|
-
export type PublicORPCPayloadCodec = Pick<ORPCPayloadCodec, keyof ORPCPayloadCodec>;
|
16
|
-
//# sourceMappingURL=orpc-payload-codec.d.ts.map
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { AnyProcedure } from '../../procedure';
|
2
|
-
import type { AnyRouter } from '../../router';
|
3
|
-
export declare class ORPCProcedureMatcher {
|
4
|
-
private readonly router;
|
5
|
-
constructor(router: AnyRouter);
|
6
|
-
match(pathname: string): Promise<{
|
7
|
-
path: string[];
|
8
|
-
procedure: AnyProcedure;
|
9
|
-
} | undefined>;
|
10
|
-
}
|
11
|
-
export type PublicORPCProcedureMatcher = Pick<ORPCProcedureMatcher, keyof ORPCProcedureMatcher>;
|
12
|
-
//# sourceMappingURL=orpc-procedure-matcher.d.ts.map
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { Segment } from '@orpc/shared';
|
2
|
-
export type JSONExtraType = 'bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url';
|
3
|
-
export type JSONMeta = [JSONExtraType, Segment[]][];
|
4
|
-
export declare function serialize(value: unknown, segments?: Segment[], meta?: JSONMeta): {
|
5
|
-
data: unknown;
|
6
|
-
meta: JSONMeta;
|
7
|
-
};
|
8
|
-
export declare function deserialize({ data, meta, }: {
|
9
|
-
data: unknown;
|
10
|
-
meta: JSONMeta;
|
11
|
-
}): unknown;
|
12
|
-
//# sourceMappingURL=super-json.d.ts.map
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
export type FetchHandleOptions<T extends Context> = {
|
4
|
-
prefix?: HTTPPath;
|
5
|
-
} & (Record<never, never> extends T ? {
|
6
|
-
context?: T;
|
7
|
-
} : {
|
8
|
-
context: T;
|
9
|
-
});
|
10
|
-
export type FetchHandleRest<T extends Context> = [options: FetchHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
|
11
|
-
export type FetchHandleResult = {
|
12
|
-
matched: true;
|
13
|
-
response: Response;
|
14
|
-
} | {
|
15
|
-
matched: false;
|
16
|
-
response: undefined;
|
17
|
-
};
|
18
|
-
export interface FetchHandler<T extends Context> {
|
19
|
-
handle(request: Request, ...rest: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
20
|
-
}
|
21
|
-
//# sourceMappingURL=types.d.ts.map
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
import type { FetchHandleOptions, FetchHandler } from '../fetch';
|
4
|
-
import { type Value } from '@orpc/shared';
|
5
|
-
export type CreateMiddlewareOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
6
|
-
context?: Value<T, [HonoContext]>;
|
7
|
-
} : {
|
8
|
-
context: Value<T, [HonoContext]>;
|
9
|
-
});
|
10
|
-
export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (Record<never, never> extends T ? [] : never);
|
11
|
-
export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
|
12
|
-
//# sourceMappingURL=middleware.d.ts.map
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import type { NextRequest } from 'next/server';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
import type { FetchHandleOptions, FetchHandler } from '../fetch';
|
4
|
-
import { type Value } from '@orpc/shared';
|
5
|
-
export type ServeOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
6
|
-
context?: Value<T, [NextRequest]>;
|
7
|
-
} : {
|
8
|
-
context: Value<T, [NextRequest]>;
|
9
|
-
});
|
10
|
-
export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
|
11
|
-
export interface ServeResult {
|
12
|
-
GET(req: NextRequest): Promise<Response>;
|
13
|
-
POST(req: NextRequest): Promise<Response>;
|
14
|
-
PUT(req: NextRequest): Promise<Response>;
|
15
|
-
PATCH(req: NextRequest): Promise<Response>;
|
16
|
-
DELETE(req: NextRequest): Promise<Response>;
|
17
|
-
}
|
18
|
-
export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: ServeRest<T>): ServeResult;
|
19
|
-
//# sourceMappingURL=serve.d.ts.map
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { ServerResponse } from 'node:http';
|
2
|
-
import type { Context } from '../../context';
|
3
|
-
import type { Router } from '../../router';
|
4
|
-
import type { RPCHandlerOptions } from '../fetch/orpc-handler';
|
5
|
-
import type { RequestHandler, RequestHandleRest, RequestHandleResult } from './types';
|
6
|
-
import { type ExpressableIncomingMessage } from './request-listener';
|
7
|
-
export declare class RPCHandler<T extends Context> implements RequestHandler<T> {
|
8
|
-
private readonly orpcFetchHandler;
|
9
|
-
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
10
|
-
handle(req: ExpressableIncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>): Promise<RequestHandleResult>;
|
11
|
-
}
|
12
|
-
//# sourceMappingURL=orpc-handler.d.ts.map
|