@orpc/server 0.0.0-next.c099c92 → 0.0.0-next.c0afbea
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 +120 -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/adapters/hono/index.mjs +32 -0
- 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 -18
- 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 +269 -0
- package/dist/index.d.ts +269 -0
- package/dist/{index.js → index.mjs} +76 -124
- package/dist/plugins/index.d.mts +31 -0
- package/dist/plugins/index.d.ts +31 -0
- package/dist/plugins/index.mjs +103 -0
- package/dist/shared/server.CM3tWr3C.d.mts +75 -0
- package/dist/shared/server.CMrS28Go.mjs +346 -0
- package/dist/shared/server.CPteJIPP.d.mts +143 -0
- package/dist/shared/server.CPteJIPP.d.ts +143 -0
- package/dist/shared/server.CSZRzcSW.mjs +158 -0
- package/dist/shared/server.Cq3B6PoL.mjs +28 -0
- package/dist/shared/server.DmW25ynm.d.ts +75 -0
- package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
- package/package.json +36 -24
- 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/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 -17
- package/dist/src/implementer.d.ts +0 -28
- 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
@@ -1,29 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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";
|
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.CMrS28Go.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, p as unlazyRouter } from './shared/server.CMrS28Go.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';
|
21
8
|
|
22
|
-
|
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 = {
|
9
|
+
const DEFAULT_CONFIG = {
|
27
10
|
initialInputValidationIndex: 0,
|
28
11
|
initialOutputValidationIndex: 0
|
29
12
|
};
|
@@ -34,9 +17,8 @@ function fallbackConfig(key, value) {
|
|
34
17
|
return value;
|
35
18
|
}
|
36
19
|
|
37
|
-
// src/middleware-decorated.ts
|
38
20
|
function decorateMiddleware(middleware) {
|
39
|
-
const decorated = middleware;
|
21
|
+
const decorated = (...args) => middleware(...args);
|
40
22
|
decorated.mapInput = (mapInput) => {
|
41
23
|
const mapped = decorateMiddleware(
|
42
24
|
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
@@ -46,10 +28,14 @@ function decorateMiddleware(middleware) {
|
|
46
28
|
decorated.concat = (concatMiddleware, mapInput) => {
|
47
29
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
48
30
|
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
49
|
-
const
|
50
|
-
|
51
|
-
|
52
|
-
|
31
|
+
const merged = middleware({
|
32
|
+
...options,
|
33
|
+
next: (...[nextOptions1]) => mapped({
|
34
|
+
...options,
|
35
|
+
context: { ...options.context, ...nextOptions1?.context },
|
36
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
37
|
+
}, input, output, ...rest)
|
38
|
+
}, input, output, ...rest);
|
53
39
|
return merged;
|
54
40
|
});
|
55
41
|
return concatted;
|
@@ -57,30 +43,28 @@ function decorateMiddleware(middleware) {
|
|
57
43
|
return decorated;
|
58
44
|
}
|
59
45
|
|
60
|
-
|
61
|
-
import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
|
62
|
-
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
46
|
+
class DecoratedProcedure extends Procedure {
|
63
47
|
errors(errors) {
|
64
|
-
return new
|
48
|
+
return new DecoratedProcedure({
|
65
49
|
...this["~orpc"],
|
66
50
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
67
51
|
});
|
68
52
|
}
|
69
53
|
meta(meta) {
|
70
|
-
return new
|
54
|
+
return new DecoratedProcedure({
|
71
55
|
...this["~orpc"],
|
72
56
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
73
57
|
});
|
74
58
|
}
|
75
59
|
route(route) {
|
76
|
-
return new
|
60
|
+
return new DecoratedProcedure({
|
77
61
|
...this["~orpc"],
|
78
62
|
route: mergeRoute(this["~orpc"].route, route)
|
79
63
|
});
|
80
64
|
}
|
81
65
|
use(middleware, mapInput) {
|
82
66
|
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
83
|
-
return new
|
67
|
+
return new DecoratedProcedure({
|
84
68
|
...this["~orpc"],
|
85
69
|
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
86
70
|
});
|
@@ -89,9 +73,13 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
|
89
73
|
* Make this procedure callable (works like a function while still being a procedure).
|
90
74
|
*/
|
91
75
|
callable(...rest) {
|
92
|
-
return
|
93
|
-
|
94
|
-
|
76
|
+
return new Proxy(createProcedureClient(this, ...rest), {
|
77
|
+
get: (target, key) => {
|
78
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
79
|
+
},
|
80
|
+
has: (target, key) => {
|
81
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
82
|
+
}
|
95
83
|
});
|
96
84
|
}
|
97
85
|
/**
|
@@ -100,10 +88,9 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
|
100
88
|
actionable(...rest) {
|
101
89
|
return this.callable(...rest);
|
102
90
|
}
|
103
|
-
}
|
91
|
+
}
|
104
92
|
|
105
|
-
|
106
|
-
var Builder = class _Builder {
|
93
|
+
class Builder {
|
107
94
|
"~orpc";
|
108
95
|
constructor(def) {
|
109
96
|
this["~orpc"] = def;
|
@@ -114,7 +101,7 @@ var Builder = class _Builder {
|
|
114
101
|
$config(config) {
|
115
102
|
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
116
103
|
const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
|
117
|
-
return new
|
104
|
+
return new Builder({
|
118
105
|
...this["~orpc"],
|
119
106
|
config,
|
120
107
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
@@ -125,7 +112,7 @@ var Builder = class _Builder {
|
|
125
112
|
* Reset initial context
|
126
113
|
*/
|
127
114
|
$context() {
|
128
|
-
return new
|
115
|
+
return new Builder({
|
129
116
|
...this["~orpc"],
|
130
117
|
middlewares: [],
|
131
118
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
@@ -136,7 +123,7 @@ var Builder = class _Builder {
|
|
136
123
|
* Reset initial meta
|
137
124
|
*/
|
138
125
|
$meta(initialMeta) {
|
139
|
-
return new
|
126
|
+
return new Builder({
|
140
127
|
...this["~orpc"],
|
141
128
|
meta: initialMeta
|
142
129
|
});
|
@@ -145,48 +132,54 @@ var Builder = class _Builder {
|
|
145
132
|
* Reset initial route
|
146
133
|
*/
|
147
134
|
$route(initialRoute) {
|
148
|
-
return new
|
135
|
+
return new Builder({
|
149
136
|
...this["~orpc"],
|
150
137
|
route: initialRoute
|
151
138
|
});
|
152
139
|
}
|
140
|
+
$input(initialInputSchema) {
|
141
|
+
return new Builder({
|
142
|
+
...this["~orpc"],
|
143
|
+
inputSchema: initialInputSchema
|
144
|
+
});
|
145
|
+
}
|
153
146
|
middleware(middleware) {
|
154
147
|
return decorateMiddleware(middleware);
|
155
148
|
}
|
156
149
|
errors(errors) {
|
157
|
-
return new
|
150
|
+
return new Builder({
|
158
151
|
...this["~orpc"],
|
159
|
-
errorMap:
|
152
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
160
153
|
});
|
161
154
|
}
|
162
155
|
use(middleware, mapInput) {
|
163
156
|
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
164
|
-
return new
|
157
|
+
return new Builder({
|
165
158
|
...this["~orpc"],
|
166
159
|
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
167
160
|
});
|
168
161
|
}
|
169
162
|
meta(meta) {
|
170
|
-
return new
|
163
|
+
return new Builder({
|
171
164
|
...this["~orpc"],
|
172
|
-
meta:
|
165
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
173
166
|
});
|
174
167
|
}
|
175
168
|
route(route) {
|
176
|
-
return new
|
169
|
+
return new Builder({
|
177
170
|
...this["~orpc"],
|
178
|
-
route:
|
171
|
+
route: mergeRoute(this["~orpc"].route, route)
|
179
172
|
});
|
180
173
|
}
|
181
174
|
input(schema) {
|
182
|
-
return new
|
175
|
+
return new Builder({
|
183
176
|
...this["~orpc"],
|
184
177
|
inputSchema: schema,
|
185
178
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
186
179
|
});
|
187
180
|
}
|
188
181
|
output(schema) {
|
189
|
-
return new
|
182
|
+
return new Builder({
|
190
183
|
...this["~orpc"],
|
191
184
|
outputSchema: schema,
|
192
185
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
@@ -199,43 +192,38 @@ var Builder = class _Builder {
|
|
199
192
|
});
|
200
193
|
}
|
201
194
|
prefix(prefix) {
|
202
|
-
return new
|
195
|
+
return new Builder({
|
203
196
|
...this["~orpc"],
|
204
197
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
205
198
|
});
|
206
199
|
}
|
207
200
|
tag(...tags) {
|
208
|
-
return new
|
201
|
+
return new Builder({
|
209
202
|
...this["~orpc"],
|
210
203
|
tags: mergeTags(this["~orpc"].tags, tags)
|
211
204
|
});
|
212
205
|
}
|
213
206
|
router(router) {
|
214
|
-
return
|
207
|
+
return enhanceRouter(router, this["~orpc"]);
|
215
208
|
}
|
216
209
|
lazy(loader) {
|
217
|
-
return
|
210
|
+
return enhanceRouter(lazy(loader), this["~orpc"]);
|
218
211
|
}
|
219
|
-
}
|
220
|
-
|
212
|
+
}
|
213
|
+
const os = new Builder({
|
221
214
|
config: {},
|
222
215
|
route: {},
|
223
216
|
meta: {},
|
224
217
|
errorMap: {},
|
225
|
-
inputSchema: void 0,
|
226
|
-
outputSchema: void 0,
|
227
218
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
228
219
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
229
220
|
middlewares: []
|
230
221
|
});
|
231
222
|
|
232
|
-
// src/context.ts
|
233
223
|
function mergeContext(context, other) {
|
234
224
|
return { ...context, ...other };
|
235
225
|
}
|
236
226
|
|
237
|
-
// src/implementer.ts
|
238
|
-
import { isContractProcedure } from "@orpc/contract";
|
239
227
|
function implementerInternal(contract, config, middlewares) {
|
240
228
|
if (isContractProcedure(contract)) {
|
241
229
|
const impl2 = new Builder({
|
@@ -249,6 +237,9 @@ function implementerInternal(contract, config, middlewares) {
|
|
249
237
|
}
|
250
238
|
const impl = new Proxy(contract, {
|
251
239
|
get: (target, key) => {
|
240
|
+
if (typeof key !== "string") {
|
241
|
+
return Reflect.get(target, key);
|
242
|
+
}
|
252
243
|
let method;
|
253
244
|
if (key === "middleware") {
|
254
245
|
method = (mid) => decorateMiddleware(mid);
|
@@ -262,23 +253,27 @@ function implementerInternal(contract, config, middlewares) {
|
|
262
253
|
};
|
263
254
|
} else if (key === "router") {
|
264
255
|
method = (router) => {
|
265
|
-
const adapted =
|
256
|
+
const adapted = enhanceRouter(router, {
|
266
257
|
middlewares,
|
267
|
-
errorMap: {}
|
258
|
+
errorMap: {},
|
259
|
+
prefix: void 0,
|
260
|
+
tags: void 0
|
268
261
|
});
|
269
|
-
return
|
262
|
+
return setHiddenRouterContract(adapted, contract);
|
270
263
|
};
|
271
264
|
} else if (key === "lazy") {
|
272
265
|
method = (loader) => {
|
273
|
-
const adapted =
|
266
|
+
const adapted = enhanceRouter(lazy(loader), {
|
274
267
|
middlewares,
|
275
|
-
errorMap: {}
|
268
|
+
errorMap: {},
|
269
|
+
prefix: void 0,
|
270
|
+
tags: void 0
|
276
271
|
});
|
277
|
-
return
|
272
|
+
return setHiddenRouterContract(adapted, contract);
|
278
273
|
};
|
279
274
|
}
|
280
|
-
const next =
|
281
|
-
if (!next
|
275
|
+
const next = getContractRouter(target, [key]);
|
276
|
+
if (!next) {
|
282
277
|
return method ?? next;
|
283
278
|
}
|
284
279
|
const nextImpl = implementerInternal(next, config, middlewares);
|
@@ -321,28 +316,21 @@ function implement(contract, config = {}) {
|
|
321
316
|
return impl;
|
322
317
|
}
|
323
318
|
|
324
|
-
|
325
|
-
function call(procedure, input, ...rest) {
|
326
|
-
return createProcedureClient(procedure, ...rest)(input);
|
327
|
-
}
|
328
|
-
|
329
|
-
// src/router-client.ts
|
330
|
-
function createRouterClient(router, ...rest) {
|
319
|
+
function createRouterClient(router, ...[options]) {
|
331
320
|
if (isProcedure(router)) {
|
332
|
-
const caller = createProcedureClient(router,
|
321
|
+
const caller = createProcedureClient(router, options);
|
333
322
|
return caller;
|
334
323
|
}
|
335
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(
|
324
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
|
336
325
|
const recursive = new Proxy(procedureCaller, {
|
337
326
|
get(target, key) {
|
338
327
|
if (typeof key !== "string") {
|
339
328
|
return Reflect.get(target, key);
|
340
329
|
}
|
341
|
-
const next =
|
330
|
+
const next = getRouter(router, [key]);
|
342
331
|
if (!next) {
|
343
332
|
return Reflect.get(target, key);
|
344
333
|
}
|
345
|
-
const [options] = rest;
|
346
334
|
return createRouterClient(next, {
|
347
335
|
...options,
|
348
336
|
path: [...options?.path ?? [], key]
|
@@ -352,40 +340,4 @@ function createRouterClient(router, ...rest) {
|
|
352
340
|
return recursive;
|
353
341
|
}
|
354
342
|
|
355
|
-
|
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
|
343
|
+
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.CM3tWr3C.mjs';
|
2
|
+
export { C as CompositePlugin } from '../shared/server.CM3tWr3C.mjs';
|
3
|
+
import { Value } from '@orpc/shared';
|
4
|
+
import { C as Context } from '../shared/server.CPteJIPP.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 | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
+
allowMethods?: readonly string[];
|
13
|
+
allowHeaders?: readonly string[];
|
14
|
+
maxAge?: number;
|
15
|
+
credentials?: boolean;
|
16
|
+
exposeHeaders?: readonly string[];
|
17
|
+
}
|
18
|
+
declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
19
|
+
private readonly options;
|
20
|
+
constructor(options?: 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.DmW25ynm.js';
|
2
|
+
export { C as CompositePlugin } from '../shared/server.DmW25ynm.js';
|
3
|
+
import { Value } from '@orpc/shared';
|
4
|
+
import { C as Context } from '../shared/server.CPteJIPP.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 | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
+
allowMethods?: readonly string[];
|
13
|
+
allowHeaders?: readonly string[];
|
14
|
+
maxAge?: number;
|
15
|
+
credentials?: boolean;
|
16
|
+
exposeHeaders?: readonly string[];
|
17
|
+
}
|
18
|
+
declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
19
|
+
private readonly options;
|
20
|
+
constructor(options?: 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,103 @@
|
|
1
|
+
export { C as CompositePlugin } from '../shared/server.Q6ZmnTgO.mjs';
|
2
|
+
import { value } from '@orpc/shared';
|
3
|
+
|
4
|
+
class CORSPlugin {
|
5
|
+
options;
|
6
|
+
constructor(options = {}) {
|
7
|
+
const defaults = {
|
8
|
+
origin: (origin) => origin,
|
9
|
+
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
10
|
+
};
|
11
|
+
this.options = {
|
12
|
+
...defaults,
|
13
|
+
...options
|
14
|
+
};
|
15
|
+
}
|
16
|
+
init(options) {
|
17
|
+
options.rootInterceptors ??= [];
|
18
|
+
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
19
|
+
if (interceptorOptions.request.method === "OPTIONS") {
|
20
|
+
const resHeaders = {};
|
21
|
+
if (this.options.maxAge !== void 0) {
|
22
|
+
resHeaders["access-control-max-age"] = this.options.maxAge.toString();
|
23
|
+
}
|
24
|
+
if (this.options.allowMethods?.length) {
|
25
|
+
resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
|
26
|
+
}
|
27
|
+
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
|
28
|
+
if (Array.isArray(allowHeaders) && allowHeaders.length) {
|
29
|
+
resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
|
30
|
+
} else if (typeof allowHeaders === "string") {
|
31
|
+
resHeaders["access-control-allow-headers"] = allowHeaders;
|
32
|
+
}
|
33
|
+
return {
|
34
|
+
matched: true,
|
35
|
+
response: {
|
36
|
+
status: 204,
|
37
|
+
headers: resHeaders,
|
38
|
+
body: void 0
|
39
|
+
}
|
40
|
+
};
|
41
|
+
}
|
42
|
+
return interceptorOptions.next();
|
43
|
+
});
|
44
|
+
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
45
|
+
const result = await interceptorOptions.next();
|
46
|
+
if (!result.matched) {
|
47
|
+
return result;
|
48
|
+
}
|
49
|
+
const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
|
50
|
+
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
51
|
+
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
52
|
+
if (allowedOriginArr.includes("*")) {
|
53
|
+
result.response.headers["access-control-allow-origin"] = "*";
|
54
|
+
} else {
|
55
|
+
if (allowedOriginArr.includes(origin)) {
|
56
|
+
result.response.headers["access-control-allow-origin"] = origin;
|
57
|
+
}
|
58
|
+
result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
|
59
|
+
}
|
60
|
+
const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
|
61
|
+
const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
|
62
|
+
if (allowedTimingOriginArr.includes("*")) {
|
63
|
+
result.response.headers["timing-allow-origin"] = "*";
|
64
|
+
} else if (allowedTimingOriginArr.includes(origin)) {
|
65
|
+
result.response.headers["timing-allow-origin"] = origin;
|
66
|
+
}
|
67
|
+
if (this.options.credentials) {
|
68
|
+
result.response.headers["access-control-allow-credentials"] = "true";
|
69
|
+
}
|
70
|
+
if (this.options.exposeHeaders?.length) {
|
71
|
+
result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
|
72
|
+
}
|
73
|
+
return result;
|
74
|
+
});
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
class ResponseHeadersPlugin {
|
79
|
+
init(options) {
|
80
|
+
options.rootInterceptors ??= [];
|
81
|
+
options.rootInterceptors.push(async (interceptorOptions) => {
|
82
|
+
const headers = new Headers();
|
83
|
+
interceptorOptions.context.resHeaders = headers;
|
84
|
+
const result = await interceptorOptions.next();
|
85
|
+
if (!result.matched) {
|
86
|
+
return result;
|
87
|
+
}
|
88
|
+
const responseHeaders = result.response.headers;
|
89
|
+
for (const [key, value] of headers) {
|
90
|
+
if (Array.isArray(responseHeaders[key])) {
|
91
|
+
responseHeaders[key].push(value);
|
92
|
+
} else if (responseHeaders[key] !== void 0) {
|
93
|
+
responseHeaders[key] = [responseHeaders[key], value];
|
94
|
+
} else {
|
95
|
+
responseHeaders[key] = value;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
return result;
|
99
|
+
});
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
export { CORSPlugin, ResponseHeadersPlugin };
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.CPteJIPP.mjs';
|
5
|
+
import { ORPCError } from '@orpc/client';
|
6
|
+
|
7
|
+
type StandardParams = Record<string, string>;
|
8
|
+
type StandardMatchResult = {
|
9
|
+
path: readonly string[];
|
10
|
+
procedure: AnyProcedure;
|
11
|
+
params?: StandardParams;
|
12
|
+
} | undefined;
|
13
|
+
interface StandardMatcher {
|
14
|
+
init(router: AnyRouter): void;
|
15
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
16
|
+
}
|
17
|
+
interface StandardCodec {
|
18
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
19
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
20
|
+
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
|
+
}
|
22
|
+
|
23
|
+
type StandardHandleOptions<T extends Context> = {
|
24
|
+
prefix?: HTTPPath;
|
25
|
+
} & (Record<never, never> extends T ? {
|
26
|
+
context?: T;
|
27
|
+
} : {
|
28
|
+
context: T;
|
29
|
+
});
|
30
|
+
type StandardHandleResult = {
|
31
|
+
matched: true;
|
32
|
+
response: StandardResponse;
|
33
|
+
} | {
|
34
|
+
matched: false;
|
35
|
+
response: undefined;
|
36
|
+
};
|
37
|
+
type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
|
38
|
+
context: T;
|
39
|
+
request: StandardLazyRequest;
|
40
|
+
};
|
41
|
+
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
+
plugins?: HandlerPlugin<TContext>[];
|
43
|
+
/**
|
44
|
+
* Interceptors at the request level, helpful when you want catch errors
|
45
|
+
*/
|
46
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
47
|
+
/**
|
48
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
49
|
+
*/
|
50
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
51
|
+
/**
|
52
|
+
*
|
53
|
+
* Interceptors for procedure client.
|
54
|
+
*/
|
55
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
56
|
+
}
|
57
|
+
declare class StandardHandler<T extends Context> {
|
58
|
+
private readonly matcher;
|
59
|
+
private readonly codec;
|
60
|
+
private readonly options;
|
61
|
+
private readonly plugin;
|
62
|
+
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
+
handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
64
|
+
}
|
65
|
+
|
66
|
+
interface HandlerPlugin<TContext extends Context> {
|
67
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
+
}
|
69
|
+
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
+
private readonly plugins;
|
71
|
+
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
73
|
+
}
|
74
|
+
|
75
|
+
export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerInterceptorOptions as a, type StandardHandlerOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
|