@orpc/server 0.0.0-next.c3068b4 → 0.0.0-next.c40d0c9
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 +131 -0
- package/dist/adapters/fetch/index.d.mts +54 -0
- package/dist/adapters/fetch/index.d.ts +54 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +22 -0
- package/dist/adapters/hono/index.d.ts +22 -0
- package/dist/{hono.js → adapters/hono/index.mjs} +12 -21
- package/dist/adapters/next/index.d.mts +29 -0
- package/dist/adapters/next/index.d.ts +29 -0
- package/dist/adapters/next/index.mjs +29 -0
- package/dist/adapters/node/index.d.mts +53 -0
- package/dist/adapters/node/index.d.ts +53 -0
- package/dist/adapters/node/index.mjs +85 -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 +291 -0
- package/dist/index.d.ts +291 -0
- package/dist/{index.js → index.mjs} +115 -156
- package/dist/plugins/index.d.mts +30 -0
- package/dist/plugins/index.d.ts +30 -0
- package/dist/plugins/index.mjs +107 -0
- package/dist/shared/server.B77ImKAP.d.mts +8 -0
- package/dist/shared/server.BHlRCrf_.d.ts +66 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.Cud5qk0c.d.ts +10 -0
- package/dist/shared/server.CzxlqYZL.d.mts +66 -0
- package/dist/shared/server.DCCkTG29.mjs +162 -0
- package/dist/shared/server.DGnN7q3R.d.mts +10 -0
- package/dist/shared/server.DLt5njUb.d.mts +143 -0
- package/dist/shared/server.DLt5njUb.d.ts +143 -0
- package/dist/shared/server.DUF89eb-.d.ts +8 -0
- package/dist/shared/server.Prfzu_zf.mjs +98 -0
- package/dist/shared/server.e3W6AG3-.mjs +370 -0
- package/package.json +32 -29
- package/dist/chunk-6RSW63UJ.js +0 -136
- package/dist/chunk-JHLUGXCM.js +0 -294
- package/dist/chunk-NOA3GBJQ.js +0 -380
- package/dist/fetch.js +0 -17
- package/dist/next.js +0 -38
- package/dist/node.js +0 -173
- package/dist/src/adapters/fetch/index.d.ts +0 -4
- package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -10
- package/dist/src/adapters/fetch/types.d.ts +0 -13
- package/dist/src/adapters/fetch/utils.d.ts +0 -6
- package/dist/src/adapters/hono/index.d.ts +0 -3
- package/dist/src/adapters/hono/middleware.d.ts +0 -13
- package/dist/src/adapters/next/index.d.ts +0 -3
- package/dist/src/adapters/next/serve.d.ts +0 -20
- package/dist/src/adapters/node/index.d.ts +0 -4
- package/dist/src/adapters/node/rpc-handler.d.ts +0 -10
- package/dist/src/adapters/node/types.d.ts +0 -21
- package/dist/src/adapters/node/utils.d.ts +0 -5
- package/dist/src/adapters/standard/handler.d.ts +0 -33
- package/dist/src/adapters/standard/index.d.ts +0 -7
- package/dist/src/adapters/standard/rpc-codec.d.ts +0 -15
- 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 -16
- package/dist/src/adapters/standard/types.d.ts +0 -44
- 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 -23
- 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/src/utils.d.ts +0 -24
- package/dist/standard.js +0 -16
@@ -1,35 +1,16 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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-NOA3GBJQ.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, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure, g as getRouter } from './shared/server.e3W6AG3-.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures, u as unlazy, x as unlazyRouter, v as validateORPCError } from './shared/server.e3W6AG3-.mjs';
|
5
|
+
import { toORPCError } from '@orpc/client';
|
6
|
+
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
7
|
+
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
8
|
+
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
25
9
|
|
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 = {
|
10
|
+
const DEFAULT_CONFIG = {
|
31
11
|
initialInputValidationIndex: 0,
|
32
|
-
initialOutputValidationIndex: 0
|
12
|
+
initialOutputValidationIndex: 0,
|
13
|
+
dedupeLeadingMiddlewares: true
|
33
14
|
};
|
34
15
|
function fallbackConfig(key, value) {
|
35
16
|
if (value === void 0) {
|
@@ -38,9 +19,8 @@ function fallbackConfig(key, value) {
|
|
38
19
|
return value;
|
39
20
|
}
|
40
21
|
|
41
|
-
// src/middleware-decorated.ts
|
42
22
|
function decorateMiddleware(middleware) {
|
43
|
-
const decorated = middleware;
|
23
|
+
const decorated = (...args) => middleware(...args);
|
44
24
|
decorated.mapInput = (mapInput) => {
|
45
25
|
const mapped = decorateMiddleware(
|
46
26
|
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
@@ -50,10 +30,14 @@ function decorateMiddleware(middleware) {
|
|
50
30
|
decorated.concat = (concatMiddleware, mapInput) => {
|
51
31
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
52
32
|
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
53
|
-
const
|
54
|
-
|
55
|
-
|
56
|
-
|
33
|
+
const merged = middleware({
|
34
|
+
...options,
|
35
|
+
next: (...[nextOptions1]) => mapped({
|
36
|
+
...options,
|
37
|
+
context: { ...options.context, ...nextOptions1?.context },
|
38
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
39
|
+
}, input, output, ...rest)
|
40
|
+
}, input, output, ...rest);
|
57
41
|
return merged;
|
58
42
|
});
|
59
43
|
return concatted;
|
@@ -61,30 +45,39 @@ function decorateMiddleware(middleware) {
|
|
61
45
|
return decorated;
|
62
46
|
}
|
63
47
|
|
64
|
-
|
65
|
-
|
66
|
-
|
48
|
+
function createActionableClient(client) {
|
49
|
+
const action = async (input) => {
|
50
|
+
try {
|
51
|
+
return [null, await client(input)];
|
52
|
+
} catch (error) {
|
53
|
+
return [toORPCError(error).toJSON(), void 0];
|
54
|
+
}
|
55
|
+
};
|
56
|
+
return action;
|
57
|
+
}
|
58
|
+
|
59
|
+
class DecoratedProcedure extends Procedure {
|
67
60
|
errors(errors) {
|
68
|
-
return new
|
61
|
+
return new DecoratedProcedure({
|
69
62
|
...this["~orpc"],
|
70
63
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
71
64
|
});
|
72
65
|
}
|
73
66
|
meta(meta) {
|
74
|
-
return new
|
67
|
+
return new DecoratedProcedure({
|
75
68
|
...this["~orpc"],
|
76
69
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
77
70
|
});
|
78
71
|
}
|
79
72
|
route(route) {
|
80
|
-
return new
|
73
|
+
return new DecoratedProcedure({
|
81
74
|
...this["~orpc"],
|
82
75
|
route: mergeRoute(this["~orpc"].route, route)
|
83
76
|
});
|
84
77
|
}
|
85
78
|
use(middleware, mapInput) {
|
86
79
|
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
87
|
-
return new
|
80
|
+
return new DecoratedProcedure({
|
88
81
|
...this["~orpc"],
|
89
82
|
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
90
83
|
});
|
@@ -93,21 +86,33 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
|
93
86
|
* Make this procedure callable (works like a function while still being a procedure).
|
94
87
|
*/
|
95
88
|
callable(...rest) {
|
96
|
-
|
97
|
-
|
98
|
-
|
89
|
+
const client = createProcedureClient(this, ...rest);
|
90
|
+
return new Proxy(client, {
|
91
|
+
get: (target, key) => {
|
92
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
93
|
+
},
|
94
|
+
has: (target, key) => {
|
95
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
96
|
+
}
|
99
97
|
});
|
100
98
|
}
|
101
99
|
/**
|
102
|
-
* Make this procedure compatible with server action
|
100
|
+
* Make this procedure compatible with server action.
|
103
101
|
*/
|
104
102
|
actionable(...rest) {
|
105
|
-
|
103
|
+
const action = createActionableClient(createProcedureClient(this, ...rest));
|
104
|
+
return new Proxy(action, {
|
105
|
+
get: (target, key) => {
|
106
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
107
|
+
},
|
108
|
+
has: (target, key) => {
|
109
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
110
|
+
}
|
111
|
+
});
|
106
112
|
}
|
107
|
-
}
|
113
|
+
}
|
108
114
|
|
109
|
-
|
110
|
-
var Builder = class _Builder {
|
115
|
+
class Builder {
|
111
116
|
"~orpc";
|
112
117
|
constructor(def) {
|
113
118
|
this["~orpc"] = def;
|
@@ -118,9 +123,10 @@ var Builder = class _Builder {
|
|
118
123
|
$config(config) {
|
119
124
|
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
120
125
|
const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
|
121
|
-
return new
|
126
|
+
return new Builder({
|
122
127
|
...this["~orpc"],
|
123
128
|
config,
|
129
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
|
124
130
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
125
131
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
126
132
|
});
|
@@ -129,7 +135,7 @@ var Builder = class _Builder {
|
|
129
135
|
* Reset initial context
|
130
136
|
*/
|
131
137
|
$context() {
|
132
|
-
return new
|
138
|
+
return new Builder({
|
133
139
|
...this["~orpc"],
|
134
140
|
middlewares: [],
|
135
141
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
@@ -140,7 +146,7 @@ var Builder = class _Builder {
|
|
140
146
|
* Reset initial meta
|
141
147
|
*/
|
142
148
|
$meta(initialMeta) {
|
143
|
-
return new
|
149
|
+
return new Builder({
|
144
150
|
...this["~orpc"],
|
145
151
|
meta: initialMeta
|
146
152
|
});
|
@@ -149,48 +155,54 @@ var Builder = class _Builder {
|
|
149
155
|
* Reset initial route
|
150
156
|
*/
|
151
157
|
$route(initialRoute) {
|
152
|
-
return new
|
158
|
+
return new Builder({
|
153
159
|
...this["~orpc"],
|
154
160
|
route: initialRoute
|
155
161
|
});
|
156
162
|
}
|
163
|
+
$input(initialInputSchema) {
|
164
|
+
return new Builder({
|
165
|
+
...this["~orpc"],
|
166
|
+
inputSchema: initialInputSchema
|
167
|
+
});
|
168
|
+
}
|
157
169
|
middleware(middleware) {
|
158
170
|
return decorateMiddleware(middleware);
|
159
171
|
}
|
160
172
|
errors(errors) {
|
161
|
-
return new
|
173
|
+
return new Builder({
|
162
174
|
...this["~orpc"],
|
163
|
-
errorMap:
|
175
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
164
176
|
});
|
165
177
|
}
|
166
178
|
use(middleware, mapInput) {
|
167
179
|
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
168
|
-
return new
|
180
|
+
return new Builder({
|
169
181
|
...this["~orpc"],
|
170
182
|
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
171
183
|
});
|
172
184
|
}
|
173
185
|
meta(meta) {
|
174
|
-
return new
|
186
|
+
return new Builder({
|
175
187
|
...this["~orpc"],
|
176
|
-
meta:
|
188
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
177
189
|
});
|
178
190
|
}
|
179
191
|
route(route) {
|
180
|
-
return new
|
192
|
+
return new Builder({
|
181
193
|
...this["~orpc"],
|
182
|
-
route:
|
194
|
+
route: mergeRoute(this["~orpc"].route, route)
|
183
195
|
});
|
184
196
|
}
|
185
197
|
input(schema) {
|
186
|
-
return new
|
198
|
+
return new Builder({
|
187
199
|
...this["~orpc"],
|
188
200
|
inputSchema: schema,
|
189
201
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
190
202
|
});
|
191
203
|
}
|
192
204
|
output(schema) {
|
193
|
-
return new
|
205
|
+
return new Builder({
|
194
206
|
...this["~orpc"],
|
195
207
|
outputSchema: schema,
|
196
208
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
@@ -203,43 +215,35 @@ var Builder = class _Builder {
|
|
203
215
|
});
|
204
216
|
}
|
205
217
|
prefix(prefix) {
|
206
|
-
return new
|
218
|
+
return new Builder({
|
207
219
|
...this["~orpc"],
|
208
220
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
209
221
|
});
|
210
222
|
}
|
211
223
|
tag(...tags) {
|
212
|
-
return new
|
224
|
+
return new Builder({
|
213
225
|
...this["~orpc"],
|
214
226
|
tags: mergeTags(this["~orpc"].tags, tags)
|
215
227
|
});
|
216
228
|
}
|
217
229
|
router(router) {
|
218
|
-
return
|
230
|
+
return enhanceRouter(router, this["~orpc"]);
|
219
231
|
}
|
220
232
|
lazy(loader) {
|
221
|
-
return
|
233
|
+
return enhanceRouter(lazy(loader), this["~orpc"]);
|
222
234
|
}
|
223
|
-
}
|
224
|
-
|
235
|
+
}
|
236
|
+
const os = new Builder({
|
225
237
|
config: {},
|
226
238
|
route: {},
|
227
239
|
meta: {},
|
228
240
|
errorMap: {},
|
229
|
-
inputSchema: void 0,
|
230
|
-
outputSchema: void 0,
|
231
241
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
232
242
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
233
|
-
middlewares: []
|
243
|
+
middlewares: [],
|
244
|
+
dedupeLeadingMiddlewares: true
|
234
245
|
});
|
235
246
|
|
236
|
-
// src/context.ts
|
237
|
-
function mergeContext(context, other) {
|
238
|
-
return { ...context, ...other };
|
239
|
-
}
|
240
|
-
|
241
|
-
// src/implementer.ts
|
242
|
-
import { isContractProcedure } from "@orpc/contract";
|
243
247
|
function implementerInternal(contract, config, middlewares) {
|
244
248
|
if (isContractProcedure(contract)) {
|
245
249
|
const impl2 = new Builder({
|
@@ -247,12 +251,16 @@ function implementerInternal(contract, config, middlewares) {
|
|
247
251
|
config,
|
248
252
|
middlewares,
|
249
253
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
250
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
254
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
|
255
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
251
256
|
});
|
252
257
|
return impl2;
|
253
258
|
}
|
254
259
|
const impl = new Proxy(contract, {
|
255
260
|
get: (target, key) => {
|
261
|
+
if (typeof key !== "string") {
|
262
|
+
return Reflect.get(target, key);
|
263
|
+
}
|
256
264
|
let method;
|
257
265
|
if (key === "middleware") {
|
258
266
|
method = (mid) => decorateMiddleware(mid);
|
@@ -266,23 +274,29 @@ function implementerInternal(contract, config, middlewares) {
|
|
266
274
|
};
|
267
275
|
} else if (key === "router") {
|
268
276
|
method = (router) => {
|
269
|
-
const adapted =
|
277
|
+
const adapted = enhanceRouter(router, {
|
270
278
|
middlewares,
|
271
|
-
errorMap: {}
|
279
|
+
errorMap: {},
|
280
|
+
prefix: void 0,
|
281
|
+
tags: void 0,
|
282
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
272
283
|
});
|
273
|
-
return
|
284
|
+
return setHiddenRouterContract(adapted, contract);
|
274
285
|
};
|
275
286
|
} else if (key === "lazy") {
|
276
287
|
method = (loader) => {
|
277
|
-
const adapted =
|
288
|
+
const adapted = enhanceRouter(lazy(loader), {
|
278
289
|
middlewares,
|
279
|
-
errorMap: {}
|
290
|
+
errorMap: {},
|
291
|
+
prefix: void 0,
|
292
|
+
tags: void 0,
|
293
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
280
294
|
});
|
281
|
-
return
|
295
|
+
return setHiddenRouterContract(adapted, contract);
|
282
296
|
};
|
283
297
|
}
|
284
|
-
const next =
|
285
|
-
if (!next
|
298
|
+
const next = getContractRouter(target, [key]);
|
299
|
+
if (!next) {
|
286
300
|
return method ?? next;
|
287
301
|
}
|
288
302
|
const nextImpl = implementerInternal(next, config, middlewares);
|
@@ -309,44 +323,34 @@ function implement(contract, config = {}) {
|
|
309
323
|
method = (config2) => implement(contract, config2);
|
310
324
|
}
|
311
325
|
const next = Reflect.get(target, key);
|
312
|
-
if (!next || typeof next !== "function" && typeof next !== "object") {
|
313
|
-
return method
|
326
|
+
if (!method || !next || typeof next !== "function" && typeof next !== "object") {
|
327
|
+
return method || next;
|
314
328
|
}
|
315
|
-
|
316
|
-
|
317
|
-
get(
|
318
|
-
|
319
|
-
|
320
|
-
});
|
321
|
-
}
|
322
|
-
return next;
|
329
|
+
return new Proxy(method, {
|
330
|
+
get(_, key2) {
|
331
|
+
return Reflect.get(next, key2);
|
332
|
+
}
|
333
|
+
});
|
323
334
|
}
|
324
335
|
});
|
325
336
|
return impl;
|
326
337
|
}
|
327
338
|
|
328
|
-
|
329
|
-
function call(procedure, input, ...rest) {
|
330
|
-
return createProcedureClient(procedure, ...rest)(input);
|
331
|
-
}
|
332
|
-
|
333
|
-
// src/router-client.ts
|
334
|
-
function createRouterClient(router, ...rest) {
|
339
|
+
function createRouterClient(router, ...[options]) {
|
335
340
|
if (isProcedure(router)) {
|
336
|
-
const caller = createProcedureClient(router,
|
341
|
+
const caller = createProcedureClient(router, options);
|
337
342
|
return caller;
|
338
343
|
}
|
339
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(
|
344
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
|
340
345
|
const recursive = new Proxy(procedureCaller, {
|
341
346
|
get(target, key) {
|
342
347
|
if (typeof key !== "string") {
|
343
348
|
return Reflect.get(target, key);
|
344
349
|
}
|
345
|
-
const next =
|
350
|
+
const next = getRouter(router, [key]);
|
346
351
|
if (!next) {
|
347
352
|
return Reflect.get(target, key);
|
348
353
|
}
|
349
|
-
const [options] = rest;
|
350
354
|
return createRouterClient(next, {
|
351
355
|
...options,
|
352
356
|
path: [...options?.path ?? [], key]
|
@@ -356,49 +360,4 @@ function createRouterClient(router, ...rest) {
|
|
356
360
|
return recursive;
|
357
361
|
}
|
358
362
|
|
359
|
-
|
360
|
-
import { isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
|
361
|
-
import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
|
362
|
-
export {
|
363
|
-
Builder,
|
364
|
-
DecoratedProcedure,
|
365
|
-
LAZY_LOADER_SYMBOL,
|
366
|
-
ORPCError,
|
367
|
-
Procedure,
|
368
|
-
ValidationError,
|
369
|
-
adaptRouter,
|
370
|
-
call,
|
371
|
-
convertPathToHttpPath,
|
372
|
-
createAccessibleLazyRouter,
|
373
|
-
createContractedProcedure,
|
374
|
-
createLazyProcedureFormAnyLazy,
|
375
|
-
createProcedureClient,
|
376
|
-
createRouterClient,
|
377
|
-
decorateMiddleware,
|
378
|
-
deepSetLazyRouterPrefix,
|
379
|
-
eachAllContractProcedure,
|
380
|
-
eachContractProcedure,
|
381
|
-
fallbackConfig,
|
382
|
-
flatLazy,
|
383
|
-
getLazyRouterPrefix,
|
384
|
-
getRouterChild,
|
385
|
-
getRouterContract,
|
386
|
-
implement,
|
387
|
-
implementerInternal,
|
388
|
-
isDefinedError,
|
389
|
-
isLazy,
|
390
|
-
isProcedure,
|
391
|
-
lazy,
|
392
|
-
mergeContext,
|
393
|
-
middlewareOutputFn,
|
394
|
-
onError,
|
395
|
-
onFinish,
|
396
|
-
onStart,
|
397
|
-
onSuccess,
|
398
|
-
os,
|
399
|
-
safe,
|
400
|
-
setRouterContract,
|
401
|
-
type,
|
402
|
-
unlazy
|
403
|
-
};
|
404
|
-
//# sourceMappingURL=index.js.map
|
363
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { b as StandardHandlerInterceptorOptions, c as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.CzxlqYZL.mjs';
|
2
|
+
import { Value } from '@orpc/shared';
|
3
|
+
import { C as Context } from '../shared/server.DLt5njUb.mjs';
|
4
|
+
import '@orpc/client';
|
5
|
+
import '@orpc/contract';
|
6
|
+
import '@orpc/standard-server';
|
7
|
+
|
8
|
+
interface CORSOptions<T extends Context> {
|
9
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
10
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
11
|
+
allowMethods?: readonly string[];
|
12
|
+
allowHeaders?: readonly string[];
|
13
|
+
maxAge?: number;
|
14
|
+
credentials?: boolean;
|
15
|
+
exposeHeaders?: readonly string[];
|
16
|
+
}
|
17
|
+
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
18
|
+
private readonly options;
|
19
|
+
constructor(options?: CORSOptions<T>);
|
20
|
+
init(options: StandardHandlerOptions<T>): void;
|
21
|
+
}
|
22
|
+
|
23
|
+
interface ResponseHeadersPluginContext {
|
24
|
+
resHeaders?: Headers;
|
25
|
+
}
|
26
|
+
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
27
|
+
init(options: StandardHandlerOptions<T>): void;
|
28
|
+
}
|
29
|
+
|
30
|
+
export { type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { b as StandardHandlerInterceptorOptions, c as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.BHlRCrf_.js';
|
2
|
+
import { Value } from '@orpc/shared';
|
3
|
+
import { C as Context } from '../shared/server.DLt5njUb.js';
|
4
|
+
import '@orpc/client';
|
5
|
+
import '@orpc/contract';
|
6
|
+
import '@orpc/standard-server';
|
7
|
+
|
8
|
+
interface CORSOptions<T extends Context> {
|
9
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
10
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
11
|
+
allowMethods?: readonly string[];
|
12
|
+
allowHeaders?: readonly string[];
|
13
|
+
maxAge?: number;
|
14
|
+
credentials?: boolean;
|
15
|
+
exposeHeaders?: readonly string[];
|
16
|
+
}
|
17
|
+
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
18
|
+
private readonly options;
|
19
|
+
constructor(options?: CORSOptions<T>);
|
20
|
+
init(options: StandardHandlerOptions<T>): void;
|
21
|
+
}
|
22
|
+
|
23
|
+
interface ResponseHeadersPluginContext {
|
24
|
+
resHeaders?: Headers;
|
25
|
+
}
|
26
|
+
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
27
|
+
init(options: StandardHandlerOptions<T>): void;
|
28
|
+
}
|
29
|
+
|
30
|
+
export { type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
@@ -0,0 +1,107 @@
|
|
1
|
+
import { value } from '@orpc/shared';
|
2
|
+
|
3
|
+
class CORSPlugin {
|
4
|
+
options;
|
5
|
+
constructor(options = {}) {
|
6
|
+
const defaults = {
|
7
|
+
origin: (origin) => origin,
|
8
|
+
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
9
|
+
};
|
10
|
+
this.options = {
|
11
|
+
...defaults,
|
12
|
+
...options
|
13
|
+
};
|
14
|
+
}
|
15
|
+
init(options) {
|
16
|
+
options.rootInterceptors ??= [];
|
17
|
+
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
18
|
+
if (interceptorOptions.request.method === "OPTIONS") {
|
19
|
+
const resHeaders = {};
|
20
|
+
if (this.options.maxAge !== void 0) {
|
21
|
+
resHeaders["access-control-max-age"] = this.options.maxAge.toString();
|
22
|
+
}
|
23
|
+
if (this.options.allowMethods?.length) {
|
24
|
+
resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
|
25
|
+
}
|
26
|
+
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
|
27
|
+
if (Array.isArray(allowHeaders) && allowHeaders.length) {
|
28
|
+
resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
|
29
|
+
} else if (typeof allowHeaders === "string") {
|
30
|
+
resHeaders["access-control-allow-headers"] = allowHeaders;
|
31
|
+
}
|
32
|
+
return {
|
33
|
+
matched: true,
|
34
|
+
response: {
|
35
|
+
status: 204,
|
36
|
+
headers: resHeaders,
|
37
|
+
body: void 0
|
38
|
+
}
|
39
|
+
};
|
40
|
+
}
|
41
|
+
return interceptorOptions.next();
|
42
|
+
});
|
43
|
+
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
44
|
+
const result = await interceptorOptions.next();
|
45
|
+
if (!result.matched) {
|
46
|
+
return result;
|
47
|
+
}
|
48
|
+
const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
|
49
|
+
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
50
|
+
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
51
|
+
if (allowedOriginArr.includes("*")) {
|
52
|
+
result.response.headers["access-control-allow-origin"] = "*";
|
53
|
+
} else {
|
54
|
+
if (allowedOriginArr.includes(origin)) {
|
55
|
+
result.response.headers["access-control-allow-origin"] = origin;
|
56
|
+
}
|
57
|
+
result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
|
58
|
+
}
|
59
|
+
const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
|
60
|
+
const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
|
61
|
+
if (allowedTimingOriginArr.includes("*")) {
|
62
|
+
result.response.headers["timing-allow-origin"] = "*";
|
63
|
+
} else if (allowedTimingOriginArr.includes(origin)) {
|
64
|
+
result.response.headers["timing-allow-origin"] = origin;
|
65
|
+
}
|
66
|
+
if (this.options.credentials) {
|
67
|
+
result.response.headers["access-control-allow-credentials"] = "true";
|
68
|
+
}
|
69
|
+
if (this.options.exposeHeaders?.length) {
|
70
|
+
result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
|
71
|
+
}
|
72
|
+
return result;
|
73
|
+
});
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
class ResponseHeadersPlugin {
|
78
|
+
init(options) {
|
79
|
+
options.rootInterceptors ??= [];
|
80
|
+
options.rootInterceptors.push(async (interceptorOptions) => {
|
81
|
+
const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
|
82
|
+
const result = await interceptorOptions.next({
|
83
|
+
...interceptorOptions,
|
84
|
+
context: {
|
85
|
+
...interceptorOptions.context,
|
86
|
+
resHeaders
|
87
|
+
}
|
88
|
+
});
|
89
|
+
if (!result.matched) {
|
90
|
+
return result;
|
91
|
+
}
|
92
|
+
const responseHeaders = result.response.headers;
|
93
|
+
for (const [key, value] of resHeaders) {
|
94
|
+
if (Array.isArray(responseHeaders[key])) {
|
95
|
+
responseHeaders[key].push(value);
|
96
|
+
} else if (responseHeaders[key] !== void 0) {
|
97
|
+
responseHeaders[key] = [responseHeaders[key], value];
|
98
|
+
} else {
|
99
|
+
responseHeaders[key] = value;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
return result;
|
103
|
+
});
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
export { CORSPlugin, ResponseHeadersPlugin };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context } from './server.DLt5njUb.mjs';
|
3
|
+
import { a as StandardHandlerOptions } from './server.CzxlqYZL.mjs';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardRPCHandlerOptions as S };
|