@orpc/server 0.0.0-next.8f101b9 → 0.0.0-next.8f622a0
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 +122 -0
- package/dist/adapters/fetch/index.d.mts +28 -0
- package/dist/adapters/fetch/index.d.ts +28 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +21 -0
- package/dist/adapters/hono/index.d.ts +21 -0
- package/dist/adapters/hono/index.mjs +32 -0
- package/dist/adapters/next/index.d.mts +28 -0
- package/dist/adapters/next/index.d.ts +28 -0
- package/dist/{next.js → adapters/next/index.mjs} +11 -18
- package/dist/adapters/node/index.d.mts +36 -0
- package/dist/adapters/node/index.d.ts +36 -0
- package/dist/adapters/node/index.mjs +32 -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 +6 -0
- package/dist/index.d.mts +278 -0
- package/dist/index.d.ts +278 -0
- package/dist/{index.js → index.mjs} +92 -140
- 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.B52eKaNe.d.mts +8 -0
- package/dist/shared/server.BA-onDGB.d.ts +8 -0
- package/dist/shared/server.BY9sDlwl.mjs +158 -0
- package/dist/shared/server.BYTulgUc.d.mts +144 -0
- package/dist/shared/server.BYTulgUc.d.ts +144 -0
- package/dist/shared/server.BtxZnWJ9.mjs +374 -0
- package/dist/shared/server.CDzXh8DM.d.mts +75 -0
- package/dist/shared/server.CkGvC2T0.d.ts +75 -0
- package/dist/shared/server.Dba3Iiyp.mjs +12 -0
- package/dist/shared/server.Del5OmaY.mjs +29 -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 -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
@@ -1,31 +1,15 @@
|
|
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.BtxZnWJ9.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, q as call, w as createAccessibleLazyRouter, b as createContractedProcedure, j as createORPCErrorConstructorMap, r as getHiddenRouterContract, k as getLazyMeta, o as isStartWithMiddlewares, m as mergeCurrentContext, p as mergeMiddlewares, n as middlewareOutputFn, x as resolveContractProcedures, a as toHttpPath, t as traverseContractProcedures, u as unlazy, y as unlazyRouter, v as validateORPCError } from './shared/server.BtxZnWJ9.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
|
-
initialOutputValidationIndex: 0
|
11
|
+
initialOutputValidationIndex: 0,
|
12
|
+
dedupeLeadingMiddlewares: true
|
29
13
|
};
|
30
14
|
function fallbackConfig(key, value) {
|
31
15
|
if (value === void 0) {
|
@@ -34,9 +18,8 @@ function fallbackConfig(key, value) {
|
|
34
18
|
return value;
|
35
19
|
}
|
36
20
|
|
37
|
-
// src/middleware-decorated.ts
|
38
21
|
function decorateMiddleware(middleware) {
|
39
|
-
const decorated = middleware;
|
22
|
+
const decorated = (...args) => middleware(...args);
|
40
23
|
decorated.mapInput = (mapInput) => {
|
41
24
|
const mapped = decorateMiddleware(
|
42
25
|
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
@@ -46,10 +29,14 @@ function decorateMiddleware(middleware) {
|
|
46
29
|
decorated.concat = (concatMiddleware, mapInput) => {
|
47
30
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
48
31
|
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
49
|
-
const
|
50
|
-
|
51
|
-
|
52
|
-
|
32
|
+
const merged = middleware({
|
33
|
+
...options,
|
34
|
+
next: (...[nextOptions1]) => mapped({
|
35
|
+
...options,
|
36
|
+
context: { ...options.context, ...nextOptions1?.context },
|
37
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
38
|
+
}, input, output, ...rest)
|
39
|
+
}, input, output, ...rest);
|
53
40
|
return merged;
|
54
41
|
});
|
55
42
|
return concatted;
|
@@ -57,30 +44,28 @@ function decorateMiddleware(middleware) {
|
|
57
44
|
return decorated;
|
58
45
|
}
|
59
46
|
|
60
|
-
|
61
|
-
import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
|
62
|
-
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
47
|
+
class DecoratedProcedure extends Procedure {
|
63
48
|
errors(errors) {
|
64
|
-
return new
|
49
|
+
return new DecoratedProcedure({
|
65
50
|
...this["~orpc"],
|
66
51
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
67
52
|
});
|
68
53
|
}
|
69
54
|
meta(meta) {
|
70
|
-
return new
|
55
|
+
return new DecoratedProcedure({
|
71
56
|
...this["~orpc"],
|
72
57
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
73
58
|
});
|
74
59
|
}
|
75
60
|
route(route) {
|
76
|
-
return new
|
61
|
+
return new DecoratedProcedure({
|
77
62
|
...this["~orpc"],
|
78
63
|
route: mergeRoute(this["~orpc"].route, route)
|
79
64
|
});
|
80
65
|
}
|
81
66
|
use(middleware, mapInput) {
|
82
67
|
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
83
|
-
return new
|
68
|
+
return new DecoratedProcedure({
|
84
69
|
...this["~orpc"],
|
85
70
|
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
86
71
|
});
|
@@ -89,9 +74,13 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
|
89
74
|
* Make this procedure callable (works like a function while still being a procedure).
|
90
75
|
*/
|
91
76
|
callable(...rest) {
|
92
|
-
return
|
93
|
-
|
94
|
-
|
77
|
+
return new Proxy(createProcedureClient(this, ...rest), {
|
78
|
+
get: (target, key) => {
|
79
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
80
|
+
},
|
81
|
+
has: (target, key) => {
|
82
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
83
|
+
}
|
95
84
|
});
|
96
85
|
}
|
97
86
|
/**
|
@@ -100,10 +89,9 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
|
100
89
|
actionable(...rest) {
|
101
90
|
return this.callable(...rest);
|
102
91
|
}
|
103
|
-
}
|
92
|
+
}
|
104
93
|
|
105
|
-
|
106
|
-
var Builder = class _Builder {
|
94
|
+
class Builder {
|
107
95
|
"~orpc";
|
108
96
|
constructor(def) {
|
109
97
|
this["~orpc"] = def;
|
@@ -114,9 +102,10 @@ var Builder = class _Builder {
|
|
114
102
|
$config(config) {
|
115
103
|
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
116
104
|
const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
|
117
|
-
return new
|
105
|
+
return new Builder({
|
118
106
|
...this["~orpc"],
|
119
107
|
config,
|
108
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
|
120
109
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
121
110
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
122
111
|
});
|
@@ -125,7 +114,7 @@ var Builder = class _Builder {
|
|
125
114
|
* Reset initial context
|
126
115
|
*/
|
127
116
|
$context() {
|
128
|
-
return new
|
117
|
+
return new Builder({
|
129
118
|
...this["~orpc"],
|
130
119
|
middlewares: [],
|
131
120
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
@@ -136,7 +125,7 @@ var Builder = class _Builder {
|
|
136
125
|
* Reset initial meta
|
137
126
|
*/
|
138
127
|
$meta(initialMeta) {
|
139
|
-
return new
|
128
|
+
return new Builder({
|
140
129
|
...this["~orpc"],
|
141
130
|
meta: initialMeta
|
142
131
|
});
|
@@ -145,48 +134,54 @@ var Builder = class _Builder {
|
|
145
134
|
* Reset initial route
|
146
135
|
*/
|
147
136
|
$route(initialRoute) {
|
148
|
-
return new
|
137
|
+
return new Builder({
|
149
138
|
...this["~orpc"],
|
150
139
|
route: initialRoute
|
151
140
|
});
|
152
141
|
}
|
142
|
+
$input(initialInputSchema) {
|
143
|
+
return new Builder({
|
144
|
+
...this["~orpc"],
|
145
|
+
inputSchema: initialInputSchema
|
146
|
+
});
|
147
|
+
}
|
153
148
|
middleware(middleware) {
|
154
149
|
return decorateMiddleware(middleware);
|
155
150
|
}
|
156
151
|
errors(errors) {
|
157
|
-
return new
|
152
|
+
return new Builder({
|
158
153
|
...this["~orpc"],
|
159
|
-
errorMap:
|
154
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
160
155
|
});
|
161
156
|
}
|
162
157
|
use(middleware, mapInput) {
|
163
158
|
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
164
|
-
return new
|
159
|
+
return new Builder({
|
165
160
|
...this["~orpc"],
|
166
161
|
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
167
162
|
});
|
168
163
|
}
|
169
164
|
meta(meta) {
|
170
|
-
return new
|
165
|
+
return new Builder({
|
171
166
|
...this["~orpc"],
|
172
|
-
meta:
|
167
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
173
168
|
});
|
174
169
|
}
|
175
170
|
route(route) {
|
176
|
-
return new
|
171
|
+
return new Builder({
|
177
172
|
...this["~orpc"],
|
178
|
-
route:
|
173
|
+
route: mergeRoute(this["~orpc"].route, route)
|
179
174
|
});
|
180
175
|
}
|
181
176
|
input(schema) {
|
182
|
-
return new
|
177
|
+
return new Builder({
|
183
178
|
...this["~orpc"],
|
184
179
|
inputSchema: schema,
|
185
180
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
186
181
|
});
|
187
182
|
}
|
188
183
|
output(schema) {
|
189
|
-
return new
|
184
|
+
return new Builder({
|
190
185
|
...this["~orpc"],
|
191
186
|
outputSchema: schema,
|
192
187
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
@@ -199,43 +194,35 @@ var Builder = class _Builder {
|
|
199
194
|
});
|
200
195
|
}
|
201
196
|
prefix(prefix) {
|
202
|
-
return new
|
197
|
+
return new Builder({
|
203
198
|
...this["~orpc"],
|
204
199
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
205
200
|
});
|
206
201
|
}
|
207
202
|
tag(...tags) {
|
208
|
-
return new
|
203
|
+
return new Builder({
|
209
204
|
...this["~orpc"],
|
210
205
|
tags: mergeTags(this["~orpc"].tags, tags)
|
211
206
|
});
|
212
207
|
}
|
213
208
|
router(router) {
|
214
|
-
return
|
209
|
+
return enhanceRouter(router, this["~orpc"]);
|
215
210
|
}
|
216
211
|
lazy(loader) {
|
217
|
-
return
|
212
|
+
return enhanceRouter(lazy(loader), this["~orpc"]);
|
218
213
|
}
|
219
|
-
}
|
220
|
-
|
214
|
+
}
|
215
|
+
const os = new Builder({
|
221
216
|
config: {},
|
222
217
|
route: {},
|
223
218
|
meta: {},
|
224
219
|
errorMap: {},
|
225
|
-
inputSchema: void 0,
|
226
|
-
outputSchema: void 0,
|
227
220
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
228
221
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
229
|
-
middlewares: []
|
222
|
+
middlewares: [],
|
223
|
+
dedupeLeadingMiddlewares: true
|
230
224
|
});
|
231
225
|
|
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
226
|
function implementerInternal(contract, config, middlewares) {
|
240
227
|
if (isContractProcedure(contract)) {
|
241
228
|
const impl2 = new Builder({
|
@@ -243,12 +230,16 @@ function implementerInternal(contract, config, middlewares) {
|
|
243
230
|
config,
|
244
231
|
middlewares,
|
245
232
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
246
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
233
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
|
234
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
247
235
|
});
|
248
236
|
return impl2;
|
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,29 @@ 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,
|
261
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
268
262
|
});
|
269
|
-
return
|
263
|
+
return setHiddenRouterContract(adapted, contract);
|
270
264
|
};
|
271
265
|
} else if (key === "lazy") {
|
272
266
|
method = (loader) => {
|
273
|
-
const adapted =
|
267
|
+
const adapted = enhanceRouter(lazy(loader), {
|
274
268
|
middlewares,
|
275
|
-
errorMap: {}
|
269
|
+
errorMap: {},
|
270
|
+
prefix: void 0,
|
271
|
+
tags: void 0,
|
272
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
276
273
|
});
|
277
|
-
return
|
274
|
+
return setHiddenRouterContract(adapted, contract);
|
278
275
|
};
|
279
276
|
}
|
280
|
-
const next =
|
281
|
-
if (!next
|
277
|
+
const next = getContractRouter(target, [key]);
|
278
|
+
if (!next) {
|
282
279
|
return method ?? next;
|
283
280
|
}
|
284
281
|
const nextImpl = implementerInternal(next, config, middlewares);
|
@@ -305,44 +302,34 @@ function implement(contract, config = {}) {
|
|
305
302
|
method = (config2) => implement(contract, config2);
|
306
303
|
}
|
307
304
|
const next = Reflect.get(target, key);
|
308
|
-
if (!next || typeof next !== "function" && typeof next !== "object") {
|
309
|
-
return method
|
305
|
+
if (!method || !next || typeof next !== "function" && typeof next !== "object") {
|
306
|
+
return method || next;
|
310
307
|
}
|
311
|
-
|
312
|
-
|
313
|
-
get(
|
314
|
-
|
315
|
-
|
316
|
-
});
|
317
|
-
}
|
318
|
-
return next;
|
308
|
+
return new Proxy(method, {
|
309
|
+
get(_, key2) {
|
310
|
+
return Reflect.get(next, key2);
|
311
|
+
}
|
312
|
+
});
|
319
313
|
}
|
320
314
|
});
|
321
315
|
return impl;
|
322
316
|
}
|
323
317
|
|
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) {
|
318
|
+
function createRouterClient(router, ...[options]) {
|
331
319
|
if (isProcedure(router)) {
|
332
|
-
const caller = createProcedureClient(router,
|
320
|
+
const caller = createProcedureClient(router, options);
|
333
321
|
return caller;
|
334
322
|
}
|
335
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(
|
323
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
|
336
324
|
const recursive = new Proxy(procedureCaller, {
|
337
325
|
get(target, key) {
|
338
326
|
if (typeof key !== "string") {
|
339
327
|
return Reflect.get(target, key);
|
340
328
|
}
|
341
|
-
const next =
|
329
|
+
const next = getRouter(router, [key]);
|
342
330
|
if (!next) {
|
343
331
|
return Reflect.get(target, key);
|
344
332
|
}
|
345
|
-
const [options] = rest;
|
346
333
|
return createRouterClient(next, {
|
347
334
|
...options,
|
348
335
|
path: [...options?.path ?? [], key]
|
@@ -352,39 +339,4 @@ function createRouterClient(router, ...rest) {
|
|
352
339
|
return recursive;
|
353
340
|
}
|
354
341
|
|
355
|
-
|
356
|
-
import { isDefinedError, ORPCError, safe, type } from "@orpc/contract";
|
357
|
-
export {
|
358
|
-
Builder,
|
359
|
-
DecoratedProcedure,
|
360
|
-
LAZY_LOADER_SYMBOL,
|
361
|
-
ORPCError,
|
362
|
-
Procedure,
|
363
|
-
adaptRouter,
|
364
|
-
call,
|
365
|
-
createAccessibleLazyRouter,
|
366
|
-
createLazyProcedureFormAnyLazy,
|
367
|
-
createProcedureClient,
|
368
|
-
createRouterClient,
|
369
|
-
decorateMiddleware,
|
370
|
-
deepSetLazyRouterPrefix,
|
371
|
-
fallbackConfig,
|
372
|
-
flatLazy,
|
373
|
-
getLazyRouterPrefix,
|
374
|
-
getRouterChild,
|
375
|
-
getRouterContract,
|
376
|
-
implement,
|
377
|
-
implementerInternal,
|
378
|
-
isDefinedError,
|
379
|
-
isLazy,
|
380
|
-
isProcedure,
|
381
|
-
lazy,
|
382
|
-
mergeContext,
|
383
|
-
middlewareOutputFn,
|
384
|
-
os,
|
385
|
-
safe,
|
386
|
-
setRouterContract,
|
387
|
-
type,
|
388
|
-
unlazy
|
389
|
-
};
|
390
|
-
//# sourceMappingURL=index.js.map
|
342
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.CDzXh8DM.mjs';
|
2
|
+
export { C as CompositeHandlerPlugin } from '../shared/server.CDzXh8DM.mjs';
|
3
|
+
import { Value } from '@orpc/shared';
|
4
|
+
import { C as Context } from '../shared/server.BYTulgUc.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 { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.CkGvC2T0.js';
|
2
|
+
export { C as CompositeHandlerPlugin } from '../shared/server.CkGvC2T0.js';
|
3
|
+
import { Value } from '@orpc/shared';
|
4
|
+
import { C as Context } from '../shared/server.BYTulgUc.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 CompositeHandlerPlugin } from '../shared/server.Dba3Iiyp.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,8 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context } from './server.BYTulgUc.mjs';
|
3
|
+
import { a as StandardHandlerOptions } from './server.CDzXh8DM.mjs';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardRPCHandlerOptions as S };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context } from './server.BYTulgUc.js';
|
3
|
+
import { a as StandardHandlerOptions } from './server.CkGvC2T0.js';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardRPCHandlerOptions as S };
|