@orpc/server 0.0.0-next.3826d73 → 0.0.0-next.3afb521
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 +118 -0
- package/dist/adapters/fetch/index.d.mts +26 -0
- package/dist/adapters/fetch/index.d.ts +26 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +19 -0
- package/dist/adapters/hono/index.d.ts +19 -0
- package/dist/{hono.js → adapters/hono/index.mjs} +11 -13
- package/dist/adapters/next/index.d.mts +26 -0
- package/dist/adapters/next/index.d.ts +26 -0
- package/dist/{next.js → adapters/next/index.mjs} +11 -13
- package/dist/adapters/node/index.d.mts +34 -0
- package/dist/adapters/node/index.d.ts +34 -0
- package/dist/adapters/node/index.mjs +31 -0
- package/dist/adapters/standard/index.d.mts +25 -0
- package/dist/adapters/standard/index.d.ts +25 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/index.d.mts +264 -0
- package/dist/index.d.ts +264 -0
- package/dist/{index.js → index.mjs} +54 -131
- package/dist/plugins/index.d.mts +31 -0
- package/dist/plugins/index.d.ts +31 -0
- package/dist/{chunk-XI6WGCB3.js → plugins/index.mjs} +16 -38
- package/dist/shared/server.3cSam35R.mjs +158 -0
- package/dist/{chunk-XXBE6CYD.js → shared/server.BFBhsdJr.mjs} +159 -193
- package/dist/shared/server.C99bm-AA.d.mts +143 -0
- package/dist/shared/server.C99bm-AA.d.ts +143 -0
- package/dist/shared/server.CjB_m7jG.mjs +28 -0
- package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
- package/dist/shared/server.SegZfF38.d.ts +77 -0
- package/dist/shared/server.rcYTv2pz.d.mts +77 -0
- package/package.json +29 -33
- package/dist/chunk-L4ESXQX7.js +0 -32
- package/dist/chunk-NXEANHUK.js +0 -351
- package/dist/fetch.js +0 -10
- 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 -51
- package/dist/src/adapters/standard/index.d.ts +0 -7
- 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/rpc-serializer.d.ts +0 -22
- package/dist/src/adapters/standard/types.d.ts +0 -20
- 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 -8
- package/dist/src/hidden.d.ts +0 -8
- package/dist/src/implementer-procedure.d.ts +0 -31
- package/dist/src/implementer-variants.d.ts +0 -17
- package/dist/src/implementer.d.ts +0 -28
- package/dist/src/index.d.ts +0 -24
- 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/plugins/base.d.ts +0 -13
- 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 -31
- package/dist/src/procedure-decorated.d.ts +0 -22
- package/dist/src/procedure-utils.d.ts +0 -18
- package/dist/src/procedure.d.ts +0 -30
- package/dist/src/router-accessible-lazy.d.ts +0 -8
- package/dist/src/router-client.d.ts +0 -11
- package/dist/src/router.d.ts +0 -30
- package/dist/src/utils.d.ts +0 -24
- package/dist/standard.js +0 -17
@@ -1,33 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
createContractedProcedure,
|
9
|
-
createLazyProcedureFormAnyLazy,
|
10
|
-
createProcedureClient,
|
11
|
-
deepSetLazyRouterPrefix,
|
12
|
-
eachAllContractProcedure,
|
13
|
-
eachContractProcedure,
|
14
|
-
flatLazy,
|
15
|
-
getLazyRouterPrefix,
|
16
|
-
getRouterChild,
|
17
|
-
getRouterContract,
|
18
|
-
isLazy,
|
19
|
-
isProcedure,
|
20
|
-
lazy,
|
21
|
-
middlewareOutputFn,
|
22
|
-
setRouterContract,
|
23
|
-
unlazy
|
24
|
-
} from "./chunk-XXBE6CYD.js";
|
1
|
+
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
|
2
|
+
export { ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
+
import { P as Procedure, d as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, f as isLazy, h as createAssertedLazyProcedure, g as getRouter } from './shared/server.BFBhsdJr.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, k as call, o as createAccessibleLazyRouter, b as createContractedProcedure, n as getHiddenRouterContract, j as getLazyMeta, m as middlewareOutputFn, r as resolveContractProcedures, a as toHttpPath, t as traverseContractProcedures, u as unlazy } from './shared/server.BFBhsdJr.mjs';
|
5
|
+
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
6
|
+
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
|
+
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
25
8
|
|
26
|
-
|
27
|
-
import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
|
28
|
-
|
29
|
-
// src/config.ts
|
30
|
-
var DEFAULT_CONFIG = {
|
9
|
+
const DEFAULT_CONFIG = {
|
31
10
|
initialInputValidationIndex: 0,
|
32
11
|
initialOutputValidationIndex: 0
|
33
12
|
};
|
@@ -38,7 +17,6 @@ function fallbackConfig(key, value) {
|
|
38
17
|
return value;
|
39
18
|
}
|
40
19
|
|
41
|
-
// src/middleware-decorated.ts
|
42
20
|
function decorateMiddleware(middleware) {
|
43
21
|
const decorated = middleware;
|
44
22
|
decorated.mapInput = (mapInput) => {
|
@@ -65,30 +43,28 @@ function decorateMiddleware(middleware) {
|
|
65
43
|
return decorated;
|
66
44
|
}
|
67
45
|
|
68
|
-
|
69
|
-
import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
|
70
|
-
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
46
|
+
class DecoratedProcedure extends Procedure {
|
71
47
|
errors(errors) {
|
72
|
-
return new
|
48
|
+
return new DecoratedProcedure({
|
73
49
|
...this["~orpc"],
|
74
50
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
75
51
|
});
|
76
52
|
}
|
77
53
|
meta(meta) {
|
78
|
-
return new
|
54
|
+
return new DecoratedProcedure({
|
79
55
|
...this["~orpc"],
|
80
56
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
81
57
|
});
|
82
58
|
}
|
83
59
|
route(route) {
|
84
|
-
return new
|
60
|
+
return new DecoratedProcedure({
|
85
61
|
...this["~orpc"],
|
86
62
|
route: mergeRoute(this["~orpc"].route, route)
|
87
63
|
});
|
88
64
|
}
|
89
65
|
use(middleware, mapInput) {
|
90
66
|
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
91
|
-
return new
|
67
|
+
return new DecoratedProcedure({
|
92
68
|
...this["~orpc"],
|
93
69
|
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
94
70
|
});
|
@@ -108,10 +84,9 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
|
108
84
|
actionable(...rest) {
|
109
85
|
return this.callable(...rest);
|
110
86
|
}
|
111
|
-
}
|
87
|
+
}
|
112
88
|
|
113
|
-
|
114
|
-
var Builder = class _Builder {
|
89
|
+
class Builder {
|
115
90
|
"~orpc";
|
116
91
|
constructor(def) {
|
117
92
|
this["~orpc"] = def;
|
@@ -122,7 +97,7 @@ var Builder = class _Builder {
|
|
122
97
|
$config(config) {
|
123
98
|
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
124
99
|
const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
|
125
|
-
return new
|
100
|
+
return new Builder({
|
126
101
|
...this["~orpc"],
|
127
102
|
config,
|
128
103
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
@@ -133,7 +108,7 @@ var Builder = class _Builder {
|
|
133
108
|
* Reset initial context
|
134
109
|
*/
|
135
110
|
$context() {
|
136
|
-
return new
|
111
|
+
return new Builder({
|
137
112
|
...this["~orpc"],
|
138
113
|
middlewares: [],
|
139
114
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
@@ -144,7 +119,7 @@ var Builder = class _Builder {
|
|
144
119
|
* Reset initial meta
|
145
120
|
*/
|
146
121
|
$meta(initialMeta) {
|
147
|
-
return new
|
122
|
+
return new Builder({
|
148
123
|
...this["~orpc"],
|
149
124
|
meta: initialMeta
|
150
125
|
});
|
@@ -153,7 +128,7 @@ var Builder = class _Builder {
|
|
153
128
|
* Reset initial route
|
154
129
|
*/
|
155
130
|
$route(initialRoute) {
|
156
|
-
return new
|
131
|
+
return new Builder({
|
157
132
|
...this["~orpc"],
|
158
133
|
route: initialRoute
|
159
134
|
});
|
@@ -162,39 +137,39 @@ var Builder = class _Builder {
|
|
162
137
|
return decorateMiddleware(middleware);
|
163
138
|
}
|
164
139
|
errors(errors) {
|
165
|
-
return new
|
140
|
+
return new Builder({
|
166
141
|
...this["~orpc"],
|
167
|
-
errorMap:
|
142
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
168
143
|
});
|
169
144
|
}
|
170
145
|
use(middleware, mapInput) {
|
171
146
|
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
172
|
-
return new
|
147
|
+
return new Builder({
|
173
148
|
...this["~orpc"],
|
174
149
|
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
175
150
|
});
|
176
151
|
}
|
177
152
|
meta(meta) {
|
178
|
-
return new
|
153
|
+
return new Builder({
|
179
154
|
...this["~orpc"],
|
180
|
-
meta:
|
155
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
181
156
|
});
|
182
157
|
}
|
183
158
|
route(route) {
|
184
|
-
return new
|
159
|
+
return new Builder({
|
185
160
|
...this["~orpc"],
|
186
|
-
route:
|
161
|
+
route: mergeRoute(this["~orpc"].route, route)
|
187
162
|
});
|
188
163
|
}
|
189
164
|
input(schema) {
|
190
|
-
return new
|
165
|
+
return new Builder({
|
191
166
|
...this["~orpc"],
|
192
167
|
inputSchema: schema,
|
193
168
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
194
169
|
});
|
195
170
|
}
|
196
171
|
output(schema) {
|
197
|
-
return new
|
172
|
+
return new Builder({
|
198
173
|
...this["~orpc"],
|
199
174
|
outputSchema: schema,
|
200
175
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
@@ -207,25 +182,25 @@ var Builder = class _Builder {
|
|
207
182
|
});
|
208
183
|
}
|
209
184
|
prefix(prefix) {
|
210
|
-
return new
|
185
|
+
return new Builder({
|
211
186
|
...this["~orpc"],
|
212
187
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
213
188
|
});
|
214
189
|
}
|
215
190
|
tag(...tags) {
|
216
|
-
return new
|
191
|
+
return new Builder({
|
217
192
|
...this["~orpc"],
|
218
193
|
tags: mergeTags(this["~orpc"].tags, tags)
|
219
194
|
});
|
220
195
|
}
|
221
196
|
router(router) {
|
222
|
-
return
|
197
|
+
return enhanceRouter(router, this["~orpc"]);
|
223
198
|
}
|
224
199
|
lazy(loader) {
|
225
|
-
return
|
200
|
+
return enhanceRouter(lazy(loader), this["~orpc"]);
|
226
201
|
}
|
227
|
-
}
|
228
|
-
|
202
|
+
}
|
203
|
+
const os = new Builder({
|
229
204
|
config: {},
|
230
205
|
route: {},
|
231
206
|
meta: {},
|
@@ -237,13 +212,10 @@ var os = new Builder({
|
|
237
212
|
middlewares: []
|
238
213
|
});
|
239
214
|
|
240
|
-
// src/context.ts
|
241
215
|
function mergeContext(context, other) {
|
242
216
|
return { ...context, ...other };
|
243
217
|
}
|
244
218
|
|
245
|
-
// src/implementer.ts
|
246
|
-
import { isContractProcedure } from "@orpc/contract";
|
247
219
|
function implementerInternal(contract, config, middlewares) {
|
248
220
|
if (isContractProcedure(contract)) {
|
249
221
|
const impl2 = new Builder({
|
@@ -257,6 +229,9 @@ function implementerInternal(contract, config, middlewares) {
|
|
257
229
|
}
|
258
230
|
const impl = new Proxy(contract, {
|
259
231
|
get: (target, key) => {
|
232
|
+
if (typeof key !== "string") {
|
233
|
+
return Reflect.get(target, key);
|
234
|
+
}
|
260
235
|
let method;
|
261
236
|
if (key === "middleware") {
|
262
237
|
method = (mid) => decorateMiddleware(mid);
|
@@ -270,23 +245,27 @@ function implementerInternal(contract, config, middlewares) {
|
|
270
245
|
};
|
271
246
|
} else if (key === "router") {
|
272
247
|
method = (router) => {
|
273
|
-
const adapted =
|
248
|
+
const adapted = enhanceRouter(router, {
|
274
249
|
middlewares,
|
275
|
-
errorMap: {}
|
250
|
+
errorMap: {},
|
251
|
+
prefix: void 0,
|
252
|
+
tags: void 0
|
276
253
|
});
|
277
|
-
return
|
254
|
+
return setHiddenRouterContract(adapted, contract);
|
278
255
|
};
|
279
256
|
} else if (key === "lazy") {
|
280
257
|
method = (loader) => {
|
281
|
-
const adapted =
|
258
|
+
const adapted = enhanceRouter(lazy(loader), {
|
282
259
|
middlewares,
|
283
|
-
errorMap: {}
|
260
|
+
errorMap: {},
|
261
|
+
prefix: void 0,
|
262
|
+
tags: void 0
|
284
263
|
});
|
285
|
-
return
|
264
|
+
return setHiddenRouterContract(adapted, contract);
|
286
265
|
};
|
287
266
|
}
|
288
|
-
const next =
|
289
|
-
if (!next
|
267
|
+
const next = getContractRouter(target, [key]);
|
268
|
+
if (!next) {
|
290
269
|
return method ?? next;
|
291
270
|
}
|
292
271
|
const nextImpl = implementerInternal(next, config, middlewares);
|
@@ -329,28 +308,21 @@ function implement(contract, config = {}) {
|
|
329
308
|
return impl;
|
330
309
|
}
|
331
310
|
|
332
|
-
|
333
|
-
function call(procedure, input, ...rest) {
|
334
|
-
return createProcedureClient(procedure, ...rest)(input);
|
335
|
-
}
|
336
|
-
|
337
|
-
// src/router-client.ts
|
338
|
-
function createRouterClient(router, ...rest) {
|
311
|
+
function createRouterClient(router, ...[options]) {
|
339
312
|
if (isProcedure(router)) {
|
340
|
-
const caller = createProcedureClient(router,
|
313
|
+
const caller = createProcedureClient(router, options);
|
341
314
|
return caller;
|
342
315
|
}
|
343
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(
|
316
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
|
344
317
|
const recursive = new Proxy(procedureCaller, {
|
345
318
|
get(target, key) {
|
346
319
|
if (typeof key !== "string") {
|
347
320
|
return Reflect.get(target, key);
|
348
321
|
}
|
349
|
-
const next =
|
322
|
+
const next = getRouter(router, [key]);
|
350
323
|
if (!next) {
|
351
324
|
return Reflect.get(target, key);
|
352
325
|
}
|
353
|
-
const [options] = rest;
|
354
326
|
return createRouterClient(next, {
|
355
327
|
...options,
|
356
328
|
path: [...options?.path ?? [], key]
|
@@ -360,53 +332,4 @@ function createRouterClient(router, ...rest) {
|
|
360
332
|
return recursive;
|
361
333
|
}
|
362
334
|
|
363
|
-
|
364
|
-
import { eventIterator, isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
|
365
|
-
import { getEventMeta, withEventMeta } from "@orpc/server-standard";
|
366
|
-
import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
|
367
|
-
export {
|
368
|
-
Builder,
|
369
|
-
DecoratedProcedure,
|
370
|
-
LAZY_LOADER_SYMBOL,
|
371
|
-
ORPCError,
|
372
|
-
Procedure,
|
373
|
-
ValidationError,
|
374
|
-
adaptRouter,
|
375
|
-
call,
|
376
|
-
convertPathToHttpPath,
|
377
|
-
createAccessibleLazyRouter,
|
378
|
-
createContractedProcedure,
|
379
|
-
createLazyProcedureFormAnyLazy,
|
380
|
-
createProcedureClient,
|
381
|
-
createRouterClient,
|
382
|
-
decorateMiddleware,
|
383
|
-
deepSetLazyRouterPrefix,
|
384
|
-
eachAllContractProcedure,
|
385
|
-
eachContractProcedure,
|
386
|
-
eventIterator,
|
387
|
-
fallbackConfig,
|
388
|
-
flatLazy,
|
389
|
-
getEventMeta,
|
390
|
-
getLazyRouterPrefix,
|
391
|
-
getRouterChild,
|
392
|
-
getRouterContract,
|
393
|
-
implement,
|
394
|
-
implementerInternal,
|
395
|
-
isDefinedError,
|
396
|
-
isLazy,
|
397
|
-
isProcedure,
|
398
|
-
lazy,
|
399
|
-
mergeContext,
|
400
|
-
middlewareOutputFn,
|
401
|
-
onError,
|
402
|
-
onFinish,
|
403
|
-
onStart,
|
404
|
-
onSuccess,
|
405
|
-
os,
|
406
|
-
safe,
|
407
|
-
setRouterContract,
|
408
|
-
type,
|
409
|
-
unlazy,
|
410
|
-
withEventMeta
|
411
|
-
};
|
412
|
-
//# sourceMappingURL=index.js.map
|
335
|
+
export { Builder, DecoratedProcedure, Procedure, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, mergeContext, os, setHiddenRouterContract };
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.rcYTv2pz.mjs';
|
2
|
+
export { C as CompositePlugin } from '../shared/server.rcYTv2pz.mjs';
|
3
|
+
import { Value } from '@orpc/shared';
|
4
|
+
import { C as Context } from '../shared/server.C99bm-AA.mjs';
|
5
|
+
import '@orpc/contract';
|
6
|
+
import '@orpc/standard-server';
|
7
|
+
import '@orpc/client';
|
8
|
+
|
9
|
+
interface CORSOptions<TContext extends Context> {
|
10
|
+
origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
+
timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
+
allowMethods?: string[];
|
13
|
+
allowHeaders?: string[];
|
14
|
+
maxAge?: number;
|
15
|
+
credentials?: boolean;
|
16
|
+
exposeHeaders?: string[];
|
17
|
+
}
|
18
|
+
declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
19
|
+
private readonly options;
|
20
|
+
constructor(options?: Partial<CORSOptions<TContext>>);
|
21
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
22
|
+
}
|
23
|
+
|
24
|
+
interface ResponseHeadersPluginContext {
|
25
|
+
resHeaders?: Headers;
|
26
|
+
}
|
27
|
+
declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
|
28
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
29
|
+
}
|
30
|
+
|
31
|
+
export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.SegZfF38.js';
|
2
|
+
export { C as CompositePlugin } from '../shared/server.SegZfF38.js';
|
3
|
+
import { Value } from '@orpc/shared';
|
4
|
+
import { C as Context } from '../shared/server.C99bm-AA.js';
|
5
|
+
import '@orpc/contract';
|
6
|
+
import '@orpc/standard-server';
|
7
|
+
import '@orpc/client';
|
8
|
+
|
9
|
+
interface CORSOptions<TContext extends Context> {
|
10
|
+
origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
+
timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
+
allowMethods?: string[];
|
13
|
+
allowHeaders?: string[];
|
14
|
+
maxAge?: number;
|
15
|
+
credentials?: boolean;
|
16
|
+
exposeHeaders?: string[];
|
17
|
+
}
|
18
|
+
declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
19
|
+
private readonly options;
|
20
|
+
constructor(options?: Partial<CORSOptions<TContext>>);
|
21
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
22
|
+
}
|
23
|
+
|
24
|
+
interface ResponseHeadersPluginContext {
|
25
|
+
resHeaders?: Headers;
|
26
|
+
}
|
27
|
+
declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
|
28
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
29
|
+
}
|
30
|
+
|
31
|
+
export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
@@ -1,23 +1,7 @@
|
|
1
|
-
|
2
|
-
|
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
|
-
beforeCreateProcedureClient(clientOptions, interceptorOptions) {
|
12
|
-
for (const plugin of this.plugins) {
|
13
|
-
plugin.beforeCreateProcedureClient?.(clientOptions, interceptorOptions);
|
14
|
-
}
|
15
|
-
}
|
16
|
-
};
|
1
|
+
export { C as CompositePlugin } from '../shared/server.Q6ZmnTgO.mjs';
|
2
|
+
import { value } from '@orpc/shared';
|
17
3
|
|
18
|
-
|
19
|
-
import { value } from "@orpc/shared";
|
20
|
-
var CORSPlugin = class {
|
4
|
+
class CORSPlugin {
|
21
5
|
options;
|
22
6
|
constructor(options) {
|
23
7
|
const defaults = {
|
@@ -30,8 +14,8 @@ var CORSPlugin = class {
|
|
30
14
|
};
|
31
15
|
}
|
32
16
|
init(options) {
|
33
|
-
options.
|
34
|
-
options.
|
17
|
+
options.rootInterceptors ??= [];
|
18
|
+
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
35
19
|
if (interceptorOptions.request.method === "OPTIONS") {
|
36
20
|
const resHeaders = {};
|
37
21
|
if (this.options.maxAge !== void 0) {
|
@@ -57,7 +41,7 @@ var CORSPlugin = class {
|
|
57
41
|
}
|
58
42
|
return interceptorOptions.next();
|
59
43
|
});
|
60
|
-
options.
|
44
|
+
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
61
45
|
const result = await interceptorOptions.next();
|
62
46
|
if (!result.matched) {
|
63
47
|
return result;
|
@@ -89,13 +73,12 @@ var CORSPlugin = class {
|
|
89
73
|
return result;
|
90
74
|
});
|
91
75
|
}
|
92
|
-
}
|
76
|
+
}
|
93
77
|
|
94
|
-
|
95
|
-
var ResponseHeadersPlugin = class {
|
78
|
+
class ResponseHeadersPlugin {
|
96
79
|
init(options) {
|
97
|
-
options.
|
98
|
-
options.
|
80
|
+
options.rootInterceptors ??= [];
|
81
|
+
options.rootInterceptors.push(async (interceptorOptions) => {
|
99
82
|
const headers = new Headers();
|
100
83
|
interceptorOptions.context.resHeaders = headers;
|
101
84
|
const result = await interceptorOptions.next();
|
@@ -103,23 +86,18 @@ var ResponseHeadersPlugin = class {
|
|
103
86
|
return result;
|
104
87
|
}
|
105
88
|
const responseHeaders = result.response.headers;
|
106
|
-
for (const [key,
|
89
|
+
for (const [key, value] of headers) {
|
107
90
|
if (Array.isArray(responseHeaders[key])) {
|
108
|
-
responseHeaders[key].push(
|
91
|
+
responseHeaders[key].push(value);
|
109
92
|
} else if (responseHeaders[key] !== void 0) {
|
110
|
-
responseHeaders[key] = [responseHeaders[key],
|
93
|
+
responseHeaders[key] = [responseHeaders[key], value];
|
111
94
|
} else {
|
112
|
-
responseHeaders[key] =
|
95
|
+
responseHeaders[key] = value;
|
113
96
|
}
|
114
97
|
}
|
115
98
|
return result;
|
116
99
|
});
|
117
100
|
}
|
118
|
-
}
|
101
|
+
}
|
119
102
|
|
120
|
-
export {
|
121
|
-
CompositePlugin,
|
122
|
-
CORSPlugin,
|
123
|
-
ResponseHeadersPlugin
|
124
|
-
};
|
125
|
-
//# sourceMappingURL=chunk-XI6WGCB3.js.map
|
103
|
+
export { CORSPlugin, ResponseHeadersPlugin };
|
@@ -0,0 +1,158 @@
|
|
1
|
+
import { ORPCError, toORPCError } from '@orpc/client';
|
2
|
+
import { intercept, trim, parseEmptyableJSON } from '@orpc/shared';
|
3
|
+
import { C as CompositePlugin } from './server.Q6ZmnTgO.mjs';
|
4
|
+
import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.BFBhsdJr.mjs';
|
5
|
+
|
6
|
+
class StandardHandler {
|
7
|
+
constructor(router, matcher, codec, options) {
|
8
|
+
this.matcher = matcher;
|
9
|
+
this.codec = codec;
|
10
|
+
this.options = options;
|
11
|
+
this.plugin = new CompositePlugin(options.plugins);
|
12
|
+
this.plugin.init(this.options);
|
13
|
+
this.matcher.init(router);
|
14
|
+
}
|
15
|
+
plugin;
|
16
|
+
handle(request, ...[options]) {
|
17
|
+
return intercept(
|
18
|
+
this.options.rootInterceptors ?? [],
|
19
|
+
{
|
20
|
+
request,
|
21
|
+
...options,
|
22
|
+
context: options?.context ?? {}
|
23
|
+
// context is optional only when all fields are optional so we can safely force it to have a context
|
24
|
+
},
|
25
|
+
async (interceptorOptions) => {
|
26
|
+
let isDecoding = false;
|
27
|
+
try {
|
28
|
+
return await intercept(
|
29
|
+
this.options.interceptors ?? [],
|
30
|
+
interceptorOptions,
|
31
|
+
async (interceptorOptions2) => {
|
32
|
+
const method = interceptorOptions2.request.method;
|
33
|
+
const url = interceptorOptions2.request.url;
|
34
|
+
const pathname = `/${trim(url.pathname.replace(interceptorOptions2.prefix ?? "", ""), "/")}`;
|
35
|
+
const match = await this.matcher.match(method, pathname);
|
36
|
+
if (!match) {
|
37
|
+
return { matched: false, response: void 0 };
|
38
|
+
}
|
39
|
+
const client = createProcedureClient(match.procedure, {
|
40
|
+
context: interceptorOptions2.context,
|
41
|
+
path: match.path,
|
42
|
+
interceptors: this.options.clientInterceptors
|
43
|
+
});
|
44
|
+
isDecoding = true;
|
45
|
+
const input = await this.codec.decode(request, match.params, match.procedure);
|
46
|
+
isDecoding = false;
|
47
|
+
const lastEventId = Array.isArray(request.headers["last-event-id"]) ? request.headers["last-event-id"].at(-1) : request.headers["last-event-id"];
|
48
|
+
const output = await client(input, { signal: request.signal, lastEventId });
|
49
|
+
const response = this.codec.encode(output, match.procedure);
|
50
|
+
return {
|
51
|
+
matched: true,
|
52
|
+
response
|
53
|
+
};
|
54
|
+
}
|
55
|
+
);
|
56
|
+
} catch (e) {
|
57
|
+
const error = isDecoding ? new ORPCError("BAD_REQUEST", {
|
58
|
+
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
59
|
+
cause: e
|
60
|
+
}) : toORPCError(e);
|
61
|
+
const response = this.codec.encodeError(error);
|
62
|
+
return {
|
63
|
+
matched: true,
|
64
|
+
response
|
65
|
+
};
|
66
|
+
}
|
67
|
+
}
|
68
|
+
);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
class RPCCodec {
|
73
|
+
constructor(serializer) {
|
74
|
+
this.serializer = serializer;
|
75
|
+
}
|
76
|
+
async decode(request, _params, _procedure) {
|
77
|
+
const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
|
78
|
+
return this.serializer.deserialize(serialized);
|
79
|
+
}
|
80
|
+
encode(output, _procedure) {
|
81
|
+
return {
|
82
|
+
status: 200,
|
83
|
+
headers: {},
|
84
|
+
body: this.serializer.serialize(output)
|
85
|
+
};
|
86
|
+
}
|
87
|
+
encodeError(error) {
|
88
|
+
return {
|
89
|
+
status: error.status,
|
90
|
+
headers: {},
|
91
|
+
body: this.serializer.serialize(error.toJSON())
|
92
|
+
};
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
class RPCMatcher {
|
97
|
+
tree = {};
|
98
|
+
pendingRouters = [];
|
99
|
+
init(router, path = []) {
|
100
|
+
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
101
|
+
const httpPath = toHttpPath(path2);
|
102
|
+
if (isProcedure(contract)) {
|
103
|
+
this.tree[httpPath] = {
|
104
|
+
path: path2,
|
105
|
+
contract,
|
106
|
+
procedure: contract,
|
107
|
+
// this mean dev not used contract-first so we can used contract as procedure directly
|
108
|
+
router
|
109
|
+
};
|
110
|
+
} else {
|
111
|
+
this.tree[httpPath] = {
|
112
|
+
path: path2,
|
113
|
+
contract,
|
114
|
+
procedure: void 0,
|
115
|
+
router
|
116
|
+
};
|
117
|
+
}
|
118
|
+
});
|
119
|
+
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
120
|
+
...option,
|
121
|
+
httpPathPrefix: toHttpPath(option.path)
|
122
|
+
})));
|
123
|
+
}
|
124
|
+
async match(_method, pathname) {
|
125
|
+
if (this.pendingRouters.length) {
|
126
|
+
const newPendingRouters = [];
|
127
|
+
for (const pendingRouter of this.pendingRouters) {
|
128
|
+
if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
129
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
130
|
+
this.init(router, pendingRouter.path);
|
131
|
+
} else {
|
132
|
+
newPendingRouters.push(pendingRouter);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
this.pendingRouters = newPendingRouters;
|
136
|
+
}
|
137
|
+
const match = this.tree[pathname];
|
138
|
+
if (!match) {
|
139
|
+
return void 0;
|
140
|
+
}
|
141
|
+
if (!match.procedure) {
|
142
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.router, match.path));
|
143
|
+
if (!isProcedure(maybeProcedure)) {
|
144
|
+
throw new Error(`
|
145
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.path)}.
|
146
|
+
Ensure that the procedure is correctly defined and matches the expected contract.
|
147
|
+
`);
|
148
|
+
}
|
149
|
+
match.procedure = createContractedProcedure(maybeProcedure, match.contract);
|
150
|
+
}
|
151
|
+
return {
|
152
|
+
path: match.path,
|
153
|
+
procedure: match.procedure
|
154
|
+
};
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
export { RPCCodec as R, StandardHandler as S, RPCMatcher as a };
|