@orpc/server 0.0.0-next.c59d67c → 0.0.0-next.ca29a36
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/chunk-MBMXGUNI.js +32 -0
- package/dist/chunk-MHVECKBC.js +421 -0
- package/dist/chunk-NTHCS5CK.js +182 -0
- package/dist/chunk-TXHKQO7N.js +120 -0
- package/dist/fetch.js +6 -102
- package/dist/hono.js +34 -0
- package/dist/index.js +341 -322
- package/dist/next.js +31 -0
- package/dist/node.js +31 -0
- package/dist/plugins.js +11 -0
- package/dist/src/adapters/fetch/index.d.ts +3 -0
- package/dist/src/adapters/fetch/rpc-handler.d.ts +11 -0
- package/dist/src/adapters/fetch/types.d.ts +14 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +12 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +19 -0
- package/dist/src/adapters/node/index.d.ts +3 -0
- package/dist/src/adapters/node/rpc-handler.d.ts +11 -0
- package/dist/src/adapters/node/types.d.ts +22 -0
- package/dist/src/adapters/standard/handler.d.ts +53 -0
- package/dist/src/adapters/standard/index.d.ts +6 -0
- package/dist/src/adapters/standard/rpc-codec.d.ts +16 -0
- package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
- package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
- package/dist/src/adapters/standard/types.d.ts +21 -0
- package/dist/src/builder-variants.d.ts +75 -0
- package/dist/src/builder.d.ts +48 -39
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +8 -0
- package/dist/src/error.d.ts +12 -0
- package/dist/src/hidden.d.ts +8 -0
- package/dist/src/implementer-procedure.d.ts +33 -0
- package/dist/src/implementer-variants.d.ts +18 -0
- package/dist/src/implementer.d.ts +29 -0
- package/dist/src/index.d.ts +19 -9
- package/dist/src/lazy-utils.d.ts +6 -0
- package/dist/src/lazy.d.ts +22 -0
- package/dist/src/middleware-decorated.d.ts +11 -0
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +30 -18
- package/dist/src/plugins/base.d.ts +11 -0
- package/dist/src/plugins/cors.d.ts +19 -0
- package/dist/src/plugins/index.d.ts +4 -0
- package/dist/src/plugins/response-headers.d.ts +10 -0
- package/dist/src/procedure-client.d.ts +33 -0
- package/dist/src/procedure-decorated.d.ts +24 -0
- package/dist/src/procedure-utils.d.ts +19 -0
- package/dist/src/procedure.d.ts +27 -25
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +12 -0
- package/dist/src/router.d.ts +26 -16
- package/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +13 -0
- package/package.json +37 -9
- package/dist/chunk-TDFYNRZV.js +0 -190
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -35
- package/dist/src/procedure-builder.d.ts +0 -31
- package/dist/src/procedure-caller.d.ts +0 -19
- package/dist/src/procedure-implementer.d.ts +0 -18
- package/dist/src/router-builder.d.ts +0 -22
- package/dist/src/router-caller.d.ts +0 -22
- package/dist/src/router-implementer.d.ts +0 -20
- package/dist/src/types.d.ts +0 -8
package/dist/index.js
CHANGED
@@ -1,394 +1,413 @@
|
|
1
1
|
import {
|
2
|
+
LAZY_LOADER_SYMBOL,
|
2
3
|
Procedure,
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
adaptRouter,
|
5
|
+
addMiddleware,
|
6
|
+
convertPathToHttpPath,
|
7
|
+
createAccessibleLazyRouter,
|
8
|
+
createContractedProcedure,
|
9
|
+
createLazyProcedureFormAnyLazy,
|
10
|
+
createProcedureClient,
|
11
|
+
deepSetLazyRouterPrefix,
|
12
|
+
eachAllContractProcedure,
|
13
|
+
eachContractProcedure,
|
14
|
+
flatLazy,
|
15
|
+
getLazyRouterPrefix,
|
16
|
+
getRouterChild,
|
17
|
+
getRouterContract,
|
18
|
+
isLazy,
|
6
19
|
isProcedure,
|
7
|
-
|
8
|
-
|
20
|
+
lazy,
|
21
|
+
middlewareOutputFn,
|
22
|
+
setRouterContract,
|
23
|
+
unlazy
|
24
|
+
} from "./chunk-MHVECKBC.js";
|
9
25
|
|
10
26
|
// src/builder.ts
|
11
|
-
import {
|
12
|
-
ContractProcedure,
|
13
|
-
isContractProcedure as isContractProcedure2
|
14
|
-
} from "@orpc/contract";
|
15
|
-
|
16
|
-
// src/procedure-builder.ts
|
17
|
-
import {
|
18
|
-
DecoratedContractProcedure
|
19
|
-
} from "@orpc/contract";
|
27
|
+
import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
|
20
28
|
|
21
|
-
// src/
|
22
|
-
var
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
return
|
29
|
-
...this.zz$pi,
|
30
|
-
middlewares: [...this.zz$pi.middlewares ?? [], middleware_]
|
31
|
-
});
|
29
|
+
// src/config.ts
|
30
|
+
var DEFAULT_CONFIG = {
|
31
|
+
initialInputValidationIndex: 0,
|
32
|
+
initialOutputValidationIndex: 0
|
33
|
+
};
|
34
|
+
function fallbackConfig(key, value) {
|
35
|
+
if (value === void 0) {
|
36
|
+
return DEFAULT_CONFIG[key];
|
32
37
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
return value;
|
39
|
+
}
|
40
|
+
|
41
|
+
// src/middleware-decorated.ts
|
42
|
+
function decorateMiddleware(middleware) {
|
43
|
+
const decorated = middleware;
|
44
|
+
decorated.mapInput = (mapInput) => {
|
45
|
+
const mapped = decorateMiddleware(
|
46
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
47
|
+
);
|
48
|
+
return mapped;
|
49
|
+
};
|
50
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
51
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
52
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
53
|
+
const merged = middleware({
|
54
|
+
...options,
|
55
|
+
next: (...[nextOptions1]) => mapped({
|
56
|
+
...options,
|
57
|
+
context: { ...options.context, ...nextOptions1?.context },
|
58
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
59
|
+
}, input, output, ...rest)
|
60
|
+
}, input, output, ...rest);
|
61
|
+
return merged;
|
40
62
|
});
|
41
|
-
|
42
|
-
};
|
63
|
+
return concatted;
|
64
|
+
};
|
65
|
+
return decorated;
|
66
|
+
}
|
43
67
|
|
44
|
-
// src/procedure-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
*/
|
52
|
-
route(opts) {
|
53
|
-
return new _ProcedureBuilder({
|
54
|
-
...this.zz$pb,
|
55
|
-
contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).route(
|
56
|
-
opts
|
57
|
-
)
|
68
|
+
// src/procedure-decorated.ts
|
69
|
+
import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
|
70
|
+
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
71
|
+
errors(errors) {
|
72
|
+
return new _DecoratedProcedure({
|
73
|
+
...this["~orpc"],
|
74
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
58
75
|
});
|
59
76
|
}
|
60
|
-
|
61
|
-
return new
|
62
|
-
...this
|
63
|
-
|
64
|
-
schema,
|
65
|
-
example
|
66
|
-
)
|
77
|
+
meta(meta) {
|
78
|
+
return new _DecoratedProcedure({
|
79
|
+
...this["~orpc"],
|
80
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
67
81
|
});
|
68
82
|
}
|
69
|
-
|
70
|
-
return new
|
71
|
-
...this
|
72
|
-
|
73
|
-
schema,
|
74
|
-
example
|
75
|
-
)
|
83
|
+
route(route) {
|
84
|
+
return new _DecoratedProcedure({
|
85
|
+
...this["~orpc"],
|
86
|
+
route: mergeRoute(this["~orpc"].route, route)
|
76
87
|
});
|
77
88
|
}
|
78
89
|
use(middleware, mapInput) {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
}
|
85
|
-
return new ProcedureImplementer({
|
86
|
-
contract: this.zz$pb.contract,
|
87
|
-
middlewares: this.zz$pb.middlewares
|
88
|
-
}).use(middleware, mapInput);
|
90
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
91
|
+
return new _DecoratedProcedure({
|
92
|
+
...this["~orpc"],
|
93
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
94
|
+
});
|
89
95
|
}
|
90
96
|
/**
|
91
|
-
*
|
97
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
92
98
|
*/
|
93
|
-
|
94
|
-
return
|
95
|
-
|
96
|
-
|
97
|
-
contract: this.zz$pb.contract,
|
98
|
-
func
|
99
|
-
}
|
99
|
+
callable(...rest) {
|
100
|
+
return Object.assign(createProcedureClient(this, ...rest), {
|
101
|
+
"~type": "Procedure",
|
102
|
+
"~orpc": this["~orpc"]
|
100
103
|
});
|
101
104
|
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
constructor(zz$rb) {
|
108
|
-
this.zz$rb = zz$rb;
|
109
|
-
}
|
110
|
-
prefix(prefix) {
|
111
|
-
return new _RouterBuilder({
|
112
|
-
...this.zz$rb,
|
113
|
-
prefix: `${this.zz$rb.prefix ?? ""}${prefix}`
|
114
|
-
});
|
115
|
-
}
|
116
|
-
tags(...tags) {
|
117
|
-
if (!tags.length)
|
118
|
-
return this;
|
119
|
-
return new _RouterBuilder({
|
120
|
-
...this.zz$rb,
|
121
|
-
tags: [...this.zz$rb.tags ?? [], ...tags]
|
122
|
-
});
|
123
|
-
}
|
124
|
-
use(middleware, mapInput) {
|
125
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
126
|
-
return new _RouterBuilder({
|
127
|
-
...this.zz$rb,
|
128
|
-
middlewares: [...this.zz$rb.middlewares || [], middleware_]
|
129
|
-
});
|
130
|
-
}
|
131
|
-
router(router) {
|
132
|
-
const handled = {};
|
133
|
-
for (const key in router) {
|
134
|
-
const item = router[key];
|
135
|
-
if (isProcedure(item)) {
|
136
|
-
const builderMiddlewares = this.zz$rb.middlewares ?? [];
|
137
|
-
const itemMiddlewares = item.zz$p.middlewares ?? [];
|
138
|
-
const middlewares = [
|
139
|
-
...builderMiddlewares,
|
140
|
-
...itemMiddlewares.filter(
|
141
|
-
(item2) => !builderMiddlewares.includes(item2)
|
142
|
-
)
|
143
|
-
];
|
144
|
-
const contract = DecoratedContractProcedure2.decorate(
|
145
|
-
item.zz$p.contract
|
146
|
-
).addTags(...this.zz$rb.tags ?? []);
|
147
|
-
handled[key] = decorateProcedure({
|
148
|
-
zz$p: {
|
149
|
-
...item.zz$p,
|
150
|
-
contract: this.zz$rb.prefix ? contract.prefix(this.zz$rb.prefix) : contract,
|
151
|
-
middlewares
|
152
|
-
}
|
153
|
-
});
|
154
|
-
} else {
|
155
|
-
handled[key] = this.router(item);
|
156
|
-
}
|
157
|
-
}
|
158
|
-
return handled;
|
159
|
-
}
|
160
|
-
};
|
161
|
-
|
162
|
-
// src/router-implementer.ts
|
163
|
-
import {
|
164
|
-
isContractProcedure
|
165
|
-
} from "@orpc/contract";
|
166
|
-
var RouterImplementer = class {
|
167
|
-
constructor(zz$ri) {
|
168
|
-
this.zz$ri = zz$ri;
|
169
|
-
}
|
170
|
-
router(router) {
|
171
|
-
assertRouterImplementation(this.zz$ri.contract, router);
|
172
|
-
return router;
|
105
|
+
/**
|
106
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
107
|
+
*/
|
108
|
+
actionable(...rest) {
|
109
|
+
return this.callable(...rest);
|
173
110
|
}
|
174
111
|
};
|
175
|
-
function chainRouterImplementer(contract, middlewares) {
|
176
|
-
const result = {};
|
177
|
-
for (const key in contract) {
|
178
|
-
const item = contract[key];
|
179
|
-
if (isContractProcedure(item)) {
|
180
|
-
result[key] = new ProcedureImplementer({
|
181
|
-
contract: item,
|
182
|
-
middlewares
|
183
|
-
});
|
184
|
-
} else {
|
185
|
-
result[key] = chainRouterImplementer(item, middlewares);
|
186
|
-
}
|
187
|
-
}
|
188
|
-
const implementer = new RouterImplementer({ contract });
|
189
|
-
return Object.assign(implementer, result);
|
190
|
-
}
|
191
|
-
function assertRouterImplementation(contract, router, path = []) {
|
192
|
-
for (const key in contract) {
|
193
|
-
const currentPath = [...path, key];
|
194
|
-
const contractItem = contract[key];
|
195
|
-
const routerItem = router[key];
|
196
|
-
if (!routerItem) {
|
197
|
-
throw new Error(
|
198
|
-
`Missing implementation for procedure at [${currentPath.join(".")}]`
|
199
|
-
);
|
200
|
-
}
|
201
|
-
if (isContractProcedure(contractItem)) {
|
202
|
-
if (isProcedure(routerItem)) {
|
203
|
-
if (routerItem.zz$p.contract !== contractItem) {
|
204
|
-
throw new Error(
|
205
|
-
`Mismatch implementation for procedure at [${currentPath.join(".")}]`
|
206
|
-
);
|
207
|
-
}
|
208
|
-
} else {
|
209
|
-
throw new Error(
|
210
|
-
`Mismatch implementation for procedure at [${currentPath.join(".")}]`
|
211
|
-
);
|
212
|
-
}
|
213
|
-
} else {
|
214
|
-
assertRouterImplementation(
|
215
|
-
contractItem,
|
216
|
-
routerItem,
|
217
|
-
currentPath
|
218
|
-
);
|
219
|
-
}
|
220
|
-
}
|
221
|
-
}
|
222
112
|
|
223
113
|
// src/builder.ts
|
224
114
|
var Builder = class _Builder {
|
225
|
-
|
226
|
-
|
115
|
+
"~orpc";
|
116
|
+
constructor(def) {
|
117
|
+
this["~orpc"] = def;
|
227
118
|
}
|
228
119
|
/**
|
229
|
-
*
|
120
|
+
* Reset config
|
230
121
|
*/
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
use(middleware, mapInput) {
|
235
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
122
|
+
$config(config) {
|
123
|
+
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
124
|
+
const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
|
236
125
|
return new _Builder({
|
237
|
-
...this
|
238
|
-
|
126
|
+
...this["~orpc"],
|
127
|
+
config,
|
128
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
129
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
239
130
|
});
|
240
131
|
}
|
241
132
|
/**
|
242
|
-
*
|
133
|
+
* Reset initial context
|
243
134
|
*/
|
244
|
-
|
245
|
-
return new
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
OutputSchema: void 0
|
251
|
-
})
|
252
|
-
});
|
253
|
-
}
|
254
|
-
input(schema, example) {
|
255
|
-
return new ProcedureBuilder({
|
256
|
-
middlewares: this.zz$b.middlewares,
|
257
|
-
contract: new ContractProcedure({
|
258
|
-
OutputSchema: void 0,
|
259
|
-
InputSchema: schema,
|
260
|
-
inputExample: example
|
261
|
-
})
|
262
|
-
});
|
263
|
-
}
|
264
|
-
output(schema, example) {
|
265
|
-
return new ProcedureBuilder({
|
266
|
-
middlewares: this.zz$b.middlewares,
|
267
|
-
contract: new ContractProcedure({
|
268
|
-
InputSchema: void 0,
|
269
|
-
OutputSchema: schema,
|
270
|
-
outputExample: example
|
271
|
-
})
|
135
|
+
$context() {
|
136
|
+
return new _Builder({
|
137
|
+
...this["~orpc"],
|
138
|
+
middlewares: [],
|
139
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
140
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
|
272
141
|
});
|
273
142
|
}
|
274
143
|
/**
|
275
|
-
*
|
144
|
+
* Reset initial meta
|
276
145
|
*/
|
277
|
-
|
278
|
-
return
|
279
|
-
|
280
|
-
|
281
|
-
contract: new ContractProcedure({
|
282
|
-
InputSchema: void 0,
|
283
|
-
OutputSchema: void 0
|
284
|
-
}),
|
285
|
-
func
|
286
|
-
}
|
146
|
+
$meta(initialMeta) {
|
147
|
+
return new _Builder({
|
148
|
+
...this["~orpc"],
|
149
|
+
meta: initialMeta
|
287
150
|
});
|
288
151
|
}
|
289
152
|
/**
|
290
|
-
*
|
153
|
+
* Reset initial route
|
291
154
|
*/
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
});
|
298
|
-
}
|
299
|
-
return chainRouterImplementer(
|
300
|
-
contract,
|
301
|
-
this.zz$b.middlewares
|
302
|
-
);
|
155
|
+
$route(initialRoute) {
|
156
|
+
return new _Builder({
|
157
|
+
...this["~orpc"],
|
158
|
+
route: initialRoute
|
159
|
+
});
|
303
160
|
}
|
304
|
-
/**
|
305
|
-
* Create ExtendedMiddleware
|
306
|
-
*/
|
307
|
-
// TODO: TOutput always any, infer not work at all, because TOutput used inside middleware params,
|
308
|
-
// solution (maybe): create new generic for .output() method
|
309
161
|
middleware(middleware) {
|
310
162
|
return decorateMiddleware(middleware);
|
311
163
|
}
|
164
|
+
errors(errors) {
|
165
|
+
return new _Builder({
|
166
|
+
...this["~orpc"],
|
167
|
+
errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
|
168
|
+
});
|
169
|
+
}
|
170
|
+
use(middleware, mapInput) {
|
171
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
172
|
+
return new _Builder({
|
173
|
+
...this["~orpc"],
|
174
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
175
|
+
});
|
176
|
+
}
|
177
|
+
meta(meta) {
|
178
|
+
return new _Builder({
|
179
|
+
...this["~orpc"],
|
180
|
+
meta: mergeMeta2(this["~orpc"].meta, meta)
|
181
|
+
});
|
182
|
+
}
|
183
|
+
route(route) {
|
184
|
+
return new _Builder({
|
185
|
+
...this["~orpc"],
|
186
|
+
route: mergeRoute2(this["~orpc"].route, route)
|
187
|
+
});
|
188
|
+
}
|
189
|
+
input(schema) {
|
190
|
+
return new _Builder({
|
191
|
+
...this["~orpc"],
|
192
|
+
inputSchema: schema,
|
193
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
194
|
+
});
|
195
|
+
}
|
196
|
+
output(schema) {
|
197
|
+
return new _Builder({
|
198
|
+
...this["~orpc"],
|
199
|
+
outputSchema: schema,
|
200
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
201
|
+
});
|
202
|
+
}
|
203
|
+
handler(handler) {
|
204
|
+
return new DecoratedProcedure({
|
205
|
+
...this["~orpc"],
|
206
|
+
handler
|
207
|
+
});
|
208
|
+
}
|
312
209
|
prefix(prefix) {
|
313
|
-
return new
|
314
|
-
...this
|
315
|
-
prefix
|
210
|
+
return new _Builder({
|
211
|
+
...this["~orpc"],
|
212
|
+
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
316
213
|
});
|
317
214
|
}
|
318
|
-
|
319
|
-
return new
|
320
|
-
...this
|
321
|
-
tags
|
215
|
+
tag(...tags) {
|
216
|
+
return new _Builder({
|
217
|
+
...this["~orpc"],
|
218
|
+
tags: mergeTags(this["~orpc"].tags, tags)
|
322
219
|
});
|
323
220
|
}
|
324
|
-
/**
|
325
|
-
* Create DecoratedRouter
|
326
|
-
*/
|
327
221
|
router(router) {
|
328
|
-
return
|
222
|
+
return adaptRouter(router, this["~orpc"]);
|
223
|
+
}
|
224
|
+
lazy(loader) {
|
225
|
+
return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
|
329
226
|
}
|
330
227
|
};
|
228
|
+
var os = new Builder({
|
229
|
+
config: {},
|
230
|
+
route: {},
|
231
|
+
meta: {},
|
232
|
+
errorMap: {},
|
233
|
+
inputSchema: void 0,
|
234
|
+
outputSchema: void 0,
|
235
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
236
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
237
|
+
middlewares: []
|
238
|
+
});
|
331
239
|
|
332
|
-
// src/
|
333
|
-
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
240
|
+
// src/context.ts
|
241
|
+
function mergeContext(context, other) {
|
242
|
+
return { ...context, ...other };
|
243
|
+
}
|
244
|
+
|
245
|
+
// src/implementer.ts
|
246
|
+
import { isContractProcedure } from "@orpc/contract";
|
247
|
+
function implementerInternal(contract, config, middlewares) {
|
248
|
+
if (isContractProcedure(contract)) {
|
249
|
+
const impl2 = new Builder({
|
250
|
+
...contract["~orpc"],
|
251
|
+
config,
|
252
|
+
middlewares,
|
253
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
254
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
255
|
+
});
|
256
|
+
return impl2;
|
257
|
+
}
|
258
|
+
const impl = new Proxy(contract, {
|
259
|
+
get: (target, key) => {
|
260
|
+
let method;
|
261
|
+
if (key === "middleware") {
|
262
|
+
method = (mid) => decorateMiddleware(mid);
|
263
|
+
} else if (key === "use") {
|
264
|
+
method = (mid) => {
|
265
|
+
return implementerInternal(
|
266
|
+
contract,
|
267
|
+
config,
|
268
|
+
addMiddleware(middlewares, mid)
|
269
|
+
);
|
270
|
+
};
|
271
|
+
} else if (key === "router") {
|
272
|
+
method = (router) => {
|
273
|
+
const adapted = adaptRouter(router, {
|
274
|
+
middlewares,
|
275
|
+
errorMap: {}
|
276
|
+
});
|
277
|
+
return setRouterContract(adapted, contract);
|
278
|
+
};
|
279
|
+
} else if (key === "lazy") {
|
280
|
+
method = (loader) => {
|
281
|
+
const adapted = adaptRouter(flatLazy(lazy(loader)), {
|
282
|
+
middlewares,
|
283
|
+
errorMap: {}
|
284
|
+
});
|
285
|
+
return setRouterContract(adapted, contract);
|
286
|
+
};
|
287
|
+
}
|
288
|
+
const next = Reflect.get(target, key);
|
289
|
+
if (!next || typeof next !== "function" && typeof next !== "object") {
|
290
|
+
return method ?? next;
|
291
|
+
}
|
292
|
+
const nextImpl = implementerInternal(next, config, middlewares);
|
293
|
+
if (method) {
|
294
|
+
return new Proxy(method, {
|
295
|
+
get(_, key2) {
|
296
|
+
return Reflect.get(nextImpl, key2);
|
297
|
+
}
|
298
|
+
});
|
299
|
+
}
|
300
|
+
return nextImpl;
|
346
301
|
}
|
347
|
-
}
|
348
|
-
return
|
302
|
+
});
|
303
|
+
return impl;
|
304
|
+
}
|
305
|
+
function implement(contract, config = {}) {
|
306
|
+
const implInternal = implementerInternal(contract, config, []);
|
307
|
+
const impl = new Proxy(implInternal, {
|
308
|
+
get: (target, key) => {
|
309
|
+
let method;
|
310
|
+
if (key === "$context") {
|
311
|
+
method = () => impl;
|
312
|
+
} else if (key === "$config") {
|
313
|
+
method = (config2) => implement(contract, config2);
|
314
|
+
}
|
315
|
+
const next = Reflect.get(target, key);
|
316
|
+
if (!next || typeof next !== "function" && typeof next !== "object") {
|
317
|
+
return method ?? next;
|
318
|
+
}
|
319
|
+
if (method) {
|
320
|
+
return new Proxy(method, {
|
321
|
+
get(_, key2) {
|
322
|
+
return Reflect.get(next, key2);
|
323
|
+
}
|
324
|
+
});
|
325
|
+
}
|
326
|
+
return next;
|
327
|
+
}
|
328
|
+
});
|
329
|
+
return impl;
|
349
330
|
}
|
350
331
|
|
351
|
-
// src/
|
352
|
-
function
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
332
|
+
// src/procedure-utils.ts
|
333
|
+
function call(procedure, input, ...rest) {
|
334
|
+
return createProcedureClient(procedure, ...rest)(input);
|
335
|
+
}
|
336
|
+
|
337
|
+
// src/router-client.ts
|
338
|
+
function createRouterClient(router, ...rest) {
|
339
|
+
if (isProcedure(router)) {
|
340
|
+
const caller = createProcedureClient(router, ...rest);
|
341
|
+
return caller;
|
342
|
+
}
|
343
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
344
|
+
const recursive = new Proxy(procedureCaller, {
|
345
|
+
get(target, key) {
|
346
|
+
if (typeof key !== "string") {
|
347
|
+
return Reflect.get(target, key);
|
348
|
+
}
|
349
|
+
const next = getRouterChild(router, key);
|
350
|
+
if (!next) {
|
351
|
+
return Reflect.get(target, key);
|
352
|
+
}
|
353
|
+
const [options] = rest;
|
354
|
+
return createRouterClient(next, {
|
355
|
+
...options,
|
356
|
+
path: [...options?.path ?? [], key]
|
368
357
|
});
|
369
358
|
}
|
370
|
-
}
|
371
|
-
return
|
359
|
+
});
|
360
|
+
return recursive;
|
372
361
|
}
|
373
362
|
|
374
363
|
// src/index.ts
|
375
|
-
|
376
|
-
|
364
|
+
import { isDefinedError, ORPCError, safe } from "@orpc/client";
|
365
|
+
import { eventIterator, type, ValidationError } from "@orpc/contract";
|
366
|
+
import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
|
367
|
+
import { getEventMeta, withEventMeta } from "@orpc/standard-server";
|
377
368
|
export {
|
378
369
|
Builder,
|
370
|
+
DecoratedProcedure,
|
371
|
+
LAZY_LOADER_SYMBOL,
|
372
|
+
ORPCError,
|
379
373
|
Procedure,
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
374
|
+
ValidationError,
|
375
|
+
adaptRouter,
|
376
|
+
call,
|
377
|
+
convertPathToHttpPath,
|
378
|
+
createAccessibleLazyRouter,
|
379
|
+
createContractedProcedure,
|
380
|
+
createLazyProcedureFormAnyLazy,
|
381
|
+
createProcedureClient,
|
382
|
+
createRouterClient,
|
387
383
|
decorateMiddleware,
|
388
|
-
|
384
|
+
deepSetLazyRouterPrefix,
|
385
|
+
eachAllContractProcedure,
|
386
|
+
eachContractProcedure,
|
387
|
+
eventIterator,
|
388
|
+
fallbackConfig,
|
389
|
+
flatLazy,
|
390
|
+
getEventMeta,
|
391
|
+
getLazyRouterPrefix,
|
392
|
+
getRouterChild,
|
393
|
+
getRouterContract,
|
394
|
+
implement,
|
395
|
+
implementerInternal,
|
396
|
+
isDefinedError,
|
397
|
+
isLazy,
|
389
398
|
isProcedure,
|
399
|
+
lazy,
|
390
400
|
mergeContext,
|
401
|
+
middlewareOutputFn,
|
402
|
+
onError,
|
403
|
+
onFinish,
|
404
|
+
onStart,
|
405
|
+
onSuccess,
|
391
406
|
os,
|
392
|
-
|
407
|
+
safe,
|
408
|
+
setRouterContract,
|
409
|
+
type,
|
410
|
+
unlazy,
|
411
|
+
withEventMeta
|
393
412
|
};
|
394
413
|
//# sourceMappingURL=index.js.map
|