@orpc/contract 1.14.10 → 1.14.11
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 +52 -81
- package/dist/index.d.mts +161 -301
- package/dist/index.d.ts +161 -301
- package/dist/index.mjs +136 -283
- package/dist/plugins/index.d.mts +24 -29
- package/dist/plugins/index.d.ts +24 -29
- package/dist/plugins/index.mjs +72 -63
- package/dist/shared/contract.CW-2wl1i.mjs +180 -0
- package/dist/shared/contract.Do92aRJ4.d.mts +126 -0
- package/dist/shared/contract.Do92aRJ4.d.ts +126 -0
- package/package.json +7 -8
- package/dist/shared/contract.D_dZrO__.mjs +0 -53
- package/dist/shared/contract.TuRtB1Ca.d.mts +0 -254
- package/dist/shared/contract.TuRtB1Ca.d.ts +0 -254
package/dist/index.mjs
CHANGED
|
@@ -1,346 +1,200 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
export { AsyncIteratorClass } from '@orpc/shared';
|
|
6
|
-
import { mapEventIterator, ORPCError } from '@orpc/client';
|
|
7
|
-
export { ORPCError } from '@orpc/client';
|
|
1
|
+
import { isTypescriptObject, toArray, get, set, ORPC_NAME, isAsyncIteratorObject, isPropertyKey } from '@orpc/shared';
|
|
2
|
+
import { P as ProcedureContract, r as resolveMetaPlugins, m as mergeErrorMap, a as augmentContractRouter, V as ValidationError } from './shared/contract.CW-2wl1i.mjs';
|
|
3
|
+
export { d as defineMeta, g as getProcedureContractOrThrow, b as getRouterContract, c as minifyRouterContract, e as reconcileORPCError } from './shared/contract.CW-2wl1i.mjs';
|
|
4
|
+
import { createORPCClient, wrapAsyncIteratorPreservingEventMeta, ORPCError } from '@orpc/client';
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function mergeRoute(a, b) {
|
|
14
|
-
return { ...a, ...b };
|
|
15
|
-
}
|
|
16
|
-
function prefixRoute(route, prefix) {
|
|
17
|
-
if (!route.path) {
|
|
18
|
-
return route;
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
...route,
|
|
22
|
-
path: `${prefix}${route.path}`
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function unshiftTagRoute(route, tags) {
|
|
26
|
-
return {
|
|
27
|
-
...route,
|
|
28
|
-
tags: [...tags, ...route.tags ?? []]
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function mergePrefix(a, b) {
|
|
32
|
-
return a ? `${a}${b}` : b;
|
|
33
|
-
}
|
|
34
|
-
function mergeTags(a, b) {
|
|
35
|
-
return a ? [...a, ...b] : b;
|
|
36
|
-
}
|
|
37
|
-
function enhanceRoute(route, options) {
|
|
38
|
-
let router = route;
|
|
39
|
-
if (options.prefix) {
|
|
40
|
-
router = prefixRoute(router, options.prefix);
|
|
41
|
-
}
|
|
42
|
-
if (options.tags?.length) {
|
|
43
|
-
router = unshiftTagRoute(router, options.tags);
|
|
44
|
-
}
|
|
45
|
-
return router;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function getContractRouter(router, path) {
|
|
49
|
-
let current = router;
|
|
50
|
-
for (let i = 0; i < path.length; i++) {
|
|
51
|
-
const segment = path[i];
|
|
52
|
-
if (!current) {
|
|
53
|
-
return void 0;
|
|
54
|
-
}
|
|
55
|
-
if (isContractProcedure(current)) {
|
|
56
|
-
return void 0;
|
|
57
|
-
}
|
|
58
|
-
if (typeof current !== "object") {
|
|
59
|
-
return void 0;
|
|
60
|
-
}
|
|
61
|
-
current = current[segment];
|
|
62
|
-
}
|
|
63
|
-
return current;
|
|
64
|
-
}
|
|
65
|
-
function enhanceContractRouter(router, options) {
|
|
66
|
-
if (isContractProcedure(router)) {
|
|
67
|
-
const enhanced2 = new ContractProcedure({
|
|
68
|
-
...router["~orpc"],
|
|
69
|
-
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
70
|
-
route: enhanceRoute(router["~orpc"].route, options)
|
|
71
|
-
});
|
|
72
|
-
return enhanced2;
|
|
73
|
-
}
|
|
74
|
-
if (typeof router !== "object" || router === null) {
|
|
75
|
-
return router;
|
|
76
|
-
}
|
|
77
|
-
const enhanced = {};
|
|
78
|
-
for (const key in router) {
|
|
79
|
-
enhanced[key] = enhanceContractRouter(router[key], options);
|
|
80
|
-
}
|
|
81
|
-
return enhanced;
|
|
82
|
-
}
|
|
83
|
-
function minifyContractRouter(router) {
|
|
84
|
-
if (isContractProcedure(router)) {
|
|
85
|
-
const procedure = {
|
|
86
|
-
"~orpc": {
|
|
87
|
-
errorMap: {},
|
|
88
|
-
meta: router["~orpc"].meta,
|
|
89
|
-
route: router["~orpc"].route
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
return procedure;
|
|
93
|
-
}
|
|
94
|
-
if (typeof router !== "object" || router === null) {
|
|
95
|
-
return router;
|
|
96
|
-
}
|
|
97
|
-
const json = {};
|
|
98
|
-
for (const key in router) {
|
|
99
|
-
json[key] = minifyContractRouter(router[key]);
|
|
6
|
+
const HIDDEN_META_PLUGINS_SYMBOL = Symbol.for("ORPC_HIDDEN_META_PLUGINS");
|
|
7
|
+
function getHiddenMetaPlugins(container) {
|
|
8
|
+
if (!isTypescriptObject(container)) {
|
|
9
|
+
return void 0;
|
|
100
10
|
}
|
|
101
|
-
return
|
|
11
|
+
return container[HIDDEN_META_PLUGINS_SYMBOL];
|
|
102
12
|
}
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
if (isContractProcedure(router)) {
|
|
106
|
-
if (router["~orpc"].route.path === void 0) {
|
|
107
|
-
return new ContractProcedure({
|
|
108
|
-
...router["~orpc"],
|
|
109
|
-
route: {
|
|
110
|
-
...router["~orpc"].route,
|
|
111
|
-
path: toHttpPath(path)
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return router;
|
|
116
|
-
}
|
|
117
|
-
if (typeof router !== "object" || router === null) {
|
|
118
|
-
return router;
|
|
119
|
-
}
|
|
120
|
-
const populated = {};
|
|
121
|
-
for (const key in router) {
|
|
122
|
-
populated[key] = populateContractRouterPaths(router[key], { ...options, path: [...path, key] });
|
|
123
|
-
}
|
|
124
|
-
return populated;
|
|
13
|
+
function setHiddenMetaPlugins(container, metaPlugins) {
|
|
14
|
+
container[HIDDEN_META_PLUGINS_SYMBOL] = metaPlugins;
|
|
125
15
|
}
|
|
126
16
|
|
|
127
|
-
class ContractBuilder extends
|
|
128
|
-
constructor(def) {
|
|
129
|
-
super(def);
|
|
130
|
-
this["~orpc"].prefix = def.prefix;
|
|
131
|
-
this["~orpc"].tags = def.tags;
|
|
132
|
-
}
|
|
17
|
+
class ContractBuilder extends ProcedureContract {
|
|
133
18
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
19
|
+
* Private constructor to prevent direct instantiation.
|
|
20
|
+
* Use the static `create` method to initialize a new instance with a safe initial definition.
|
|
137
21
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
...this["~orpc"],
|
|
141
|
-
meta: initialMeta
|
|
142
|
-
});
|
|
22
|
+
constructor(definition) {
|
|
23
|
+
super(definition);
|
|
143
24
|
}
|
|
144
|
-
|
|
145
|
-
* Sets or overrides the initial route.
|
|
146
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
147
|
-
*
|
|
148
|
-
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
149
|
-
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
150
|
-
*/
|
|
151
|
-
$route(initialRoute) {
|
|
25
|
+
static create() {
|
|
152
26
|
return new ContractBuilder({
|
|
153
|
-
|
|
154
|
-
|
|
27
|
+
errorMap: {},
|
|
28
|
+
meta: {}
|
|
155
29
|
});
|
|
156
30
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
31
|
+
meta(...plugins) {
|
|
32
|
+
const [meta, metaPlugins] = resolveMetaPlugins(
|
|
33
|
+
this["~orpc"].meta,
|
|
34
|
+
this["~orpc"].metaPlugins,
|
|
35
|
+
plugins
|
|
36
|
+
);
|
|
163
37
|
return new ContractBuilder({
|
|
164
38
|
...this["~orpc"],
|
|
165
|
-
|
|
39
|
+
meta,
|
|
40
|
+
metaPlugins
|
|
166
41
|
});
|
|
167
42
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Adds type-safe custom errors to the contract.
|
|
170
|
-
* The provided errors are spared-merged with any existing errors in the contract.
|
|
171
|
-
*
|
|
172
|
-
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
173
|
-
*/
|
|
174
43
|
errors(errors) {
|
|
175
|
-
|
|
44
|
+
let result = new ContractBuilder({
|
|
176
45
|
...this["~orpc"],
|
|
177
46
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
178
47
|
});
|
|
48
|
+
const plugins = getHiddenMetaPlugins(errors);
|
|
49
|
+
if (plugins) {
|
|
50
|
+
result = result.meta(...plugins);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
179
53
|
}
|
|
180
|
-
/**
|
|
181
|
-
* Sets or updates the metadata for the contract.
|
|
182
|
-
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
183
|
-
*
|
|
184
|
-
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
185
|
-
*/
|
|
186
|
-
meta(meta) {
|
|
187
|
-
return new ContractBuilder({
|
|
188
|
-
...this["~orpc"],
|
|
189
|
-
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Sets or updates the route definition for the contract.
|
|
194
|
-
* The provided route is spared-merged with any existing route in the contract.
|
|
195
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
196
|
-
*
|
|
197
|
-
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
198
|
-
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
199
|
-
*/
|
|
200
|
-
route(route) {
|
|
201
|
-
return new ContractBuilder({
|
|
202
|
-
...this["~orpc"],
|
|
203
|
-
route: mergeRoute(this["~orpc"].route, route)
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Defines the input validation schema for the contract.
|
|
208
|
-
*
|
|
209
|
-
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
210
|
-
*/
|
|
211
54
|
input(schema) {
|
|
212
|
-
|
|
55
|
+
let result = new ContractBuilder({
|
|
213
56
|
...this["~orpc"],
|
|
214
|
-
|
|
57
|
+
inputSchemas: [...toArray(this["~orpc"].inputSchemas), schema]
|
|
215
58
|
});
|
|
59
|
+
const plugins = getHiddenMetaPlugins(schema);
|
|
60
|
+
if (plugins) {
|
|
61
|
+
result = result.meta(...plugins);
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
216
64
|
}
|
|
217
|
-
/**
|
|
218
|
-
* Defines the output validation schema for the contract.
|
|
219
|
-
*
|
|
220
|
-
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
221
|
-
*/
|
|
222
65
|
output(schema) {
|
|
223
|
-
|
|
224
|
-
...this["~orpc"],
|
|
225
|
-
outputSchema: schema
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Prefixes all procedures in the contract router.
|
|
230
|
-
* The provided prefix is post-appended to any existing router prefix.
|
|
231
|
-
*
|
|
232
|
-
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
233
|
-
*
|
|
234
|
-
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
235
|
-
*/
|
|
236
|
-
prefix(prefix) {
|
|
237
|
-
return new ContractBuilder({
|
|
66
|
+
let result = new ContractBuilder({
|
|
238
67
|
...this["~orpc"],
|
|
239
|
-
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Adds tags to all procedures in the contract router.
|
|
244
|
-
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
245
|
-
*
|
|
246
|
-
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
247
|
-
*/
|
|
248
|
-
tag(...tags) {
|
|
249
|
-
return new ContractBuilder({
|
|
250
|
-
...this["~orpc"],
|
|
251
|
-
tags: mergeTags(this["~orpc"].tags, tags)
|
|
68
|
+
outputSchemas: [...toArray(this["~orpc"].outputSchemas), schema]
|
|
252
69
|
});
|
|
70
|
+
const plugins = getHiddenMetaPlugins(schema);
|
|
71
|
+
if (plugins) {
|
|
72
|
+
result = result.meta(...plugins);
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
253
75
|
}
|
|
254
|
-
/**
|
|
255
|
-
* Applies all of the previously defined options to the specified contract router.
|
|
256
|
-
*
|
|
257
|
-
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
258
|
-
*/
|
|
259
76
|
router(router) {
|
|
260
|
-
return
|
|
77
|
+
return augmentContractRouter(router, this["~orpc"]);
|
|
261
78
|
}
|
|
262
79
|
}
|
|
263
|
-
const oc =
|
|
264
|
-
errorMap: {},
|
|
265
|
-
route: {},
|
|
266
|
-
meta: {}
|
|
267
|
-
});
|
|
80
|
+
const oc = ContractBuilder.create();
|
|
268
81
|
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
82
|
+
const meta = {
|
|
83
|
+
path(path) {
|
|
84
|
+
return {
|
|
85
|
+
name: "~path",
|
|
86
|
+
init(meta2) {
|
|
87
|
+
return {
|
|
88
|
+
...meta2,
|
|
89
|
+
"~path": path
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
275
94
|
};
|
|
276
|
-
function
|
|
277
|
-
|
|
278
|
-
|
|
95
|
+
function getPathMeta(procedureOrLazy) {
|
|
96
|
+
return procedureOrLazy["~orpc"].meta["~path"];
|
|
97
|
+
}
|
|
98
|
+
function resolveBasePathMeta(contract, currentPath = []) {
|
|
99
|
+
if (contract instanceof ProcedureContract) {
|
|
100
|
+
const path = getPathMeta(contract);
|
|
101
|
+
if (!path) {
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
const base = path.slice(0, Math.max(0, path.length - currentPath.length));
|
|
105
|
+
if (currentPath.some((key, i) => path[base.length + i] !== key)) {
|
|
106
|
+
throw new TypeError(
|
|
107
|
+
`Procedure contract at "${currentPath.join(".")}" defines meta.path "${path.join(".")}" that does not match its path inside the given router contract.`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return base;
|
|
279
111
|
}
|
|
280
|
-
|
|
112
|
+
if (isTypescriptObject(contract)) {
|
|
113
|
+
for (const key in contract) {
|
|
114
|
+
const base = resolveBasePathMeta(contract[key], [...currentPath, key]);
|
|
115
|
+
if (base !== void 0) {
|
|
116
|
+
return base;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return void 0;
|
|
281
121
|
}
|
|
282
122
|
|
|
283
|
-
|
|
284
|
-
|
|
123
|
+
function createContractClientFactory(link, options = {}) {
|
|
124
|
+
const factory = (contract) => {
|
|
125
|
+
const path = resolveBasePathMeta(contract);
|
|
126
|
+
if (path === void 0) {
|
|
127
|
+
throw new TypeError(
|
|
128
|
+
"ContractClientFactory: procedure contract must define `meta.path` that matches its path in the root router contract."
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const contractRef = options.contractRef;
|
|
132
|
+
if (contractRef) {
|
|
133
|
+
const register = (contract2, path2) => {
|
|
134
|
+
if (contract2 instanceof ProcedureContract) {
|
|
135
|
+
set(contractRef, [...path2, "~orpc"], contract2["~orpc"]);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (isTypescriptObject(contract2)) {
|
|
139
|
+
for (const [key, value] of Object.entries(contract2)) {
|
|
140
|
+
register(value, [...path2, key]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
register(contract, path);
|
|
145
|
+
}
|
|
146
|
+
return createORPCClient(link, { ...options, scoped: get(options.scoped, path), path });
|
|
147
|
+
};
|
|
148
|
+
return factory;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS_SYMBOL = Symbol.for("ORPC_ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS");
|
|
152
|
+
function asyncIteratorObject(yieldSchema, returnSchema) {
|
|
285
153
|
return {
|
|
286
154
|
"~standard": {
|
|
287
|
-
[
|
|
288
|
-
vendor:
|
|
155
|
+
[ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS_SYMBOL]: { yieldSchema, returnSchema },
|
|
156
|
+
vendor: ORPC_NAME,
|
|
289
157
|
version: 1,
|
|
290
158
|
validate(iterator) {
|
|
291
159
|
if (!isAsyncIteratorObject(iterator)) {
|
|
292
|
-
return { issues: [{ message: "Expect
|
|
160
|
+
return { issues: [{ message: "Expect AsyncIteratorObject", path: [] }] };
|
|
293
161
|
}
|
|
294
|
-
const mapped =
|
|
295
|
-
async
|
|
296
|
-
const schema = done ?
|
|
162
|
+
const mapped = wrapAsyncIteratorPreservingEventMeta(iterator, {
|
|
163
|
+
async mapResult(result) {
|
|
164
|
+
const schema = result.done ? returnSchema : yieldSchema;
|
|
297
165
|
if (!schema) {
|
|
298
|
-
return
|
|
166
|
+
return result;
|
|
299
167
|
}
|
|
300
|
-
const
|
|
301
|
-
if (
|
|
302
|
-
throw new ORPCError("
|
|
303
|
-
message: "
|
|
168
|
+
const validated = await schema["~standard"].validate(result.value);
|
|
169
|
+
if (validated.issues) {
|
|
170
|
+
throw new ORPCError("ASYNC_ITERATOR_OBJECT_VALIDATION_FAILED", {
|
|
171
|
+
message: "AsyncIteratorObject validation failed",
|
|
304
172
|
cause: new ValidationError({
|
|
305
|
-
issues:
|
|
306
|
-
message: "
|
|
307
|
-
|
|
173
|
+
issues: validated.issues,
|
|
174
|
+
message: "AsyncIteratorObject validation failed",
|
|
175
|
+
invalidData: result.value
|
|
308
176
|
})
|
|
309
177
|
});
|
|
310
178
|
}
|
|
311
|
-
return result.value;
|
|
312
|
-
}
|
|
313
|
-
error: async (error) => error
|
|
179
|
+
return { done: result.done, value: validated.value };
|
|
180
|
+
}
|
|
314
181
|
});
|
|
315
182
|
return { value: mapped };
|
|
316
183
|
}
|
|
317
184
|
}
|
|
318
185
|
};
|
|
319
186
|
}
|
|
320
|
-
function
|
|
187
|
+
function getAsyncIteratorObjectSchemaDetails(schema) {
|
|
321
188
|
if (schema === void 0) {
|
|
322
189
|
return void 0;
|
|
323
190
|
}
|
|
324
|
-
return schema["~standard"][
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function inferRPCMethodFromContractRouter(contract) {
|
|
328
|
-
return (_, path) => {
|
|
329
|
-
const procedure = get(contract, path);
|
|
330
|
-
if (!isContractProcedure(procedure)) {
|
|
331
|
-
throw new Error(
|
|
332
|
-
`[inferRPCMethodFromContractRouter] No valid procedure found at path "${path.join(".")}". This may happen when the contract router is not properly configured.`
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
|
336
|
-
return method === "HEAD" ? "GET" : method;
|
|
337
|
-
};
|
|
191
|
+
return schema["~standard"][ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS_SYMBOL];
|
|
338
192
|
}
|
|
339
193
|
|
|
340
194
|
function type(...[map]) {
|
|
341
195
|
return {
|
|
342
196
|
"~standard": {
|
|
343
|
-
vendor:
|
|
197
|
+
vendor: ORPC_NAME,
|
|
344
198
|
version: 1,
|
|
345
199
|
async validate(value) {
|
|
346
200
|
if (map) {
|
|
@@ -351,7 +205,6 @@ function type(...[map]) {
|
|
|
351
205
|
}
|
|
352
206
|
};
|
|
353
207
|
}
|
|
354
|
-
|
|
355
208
|
function isSchemaIssue(issue) {
|
|
356
209
|
if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
|
|
357
210
|
return false;
|
|
@@ -367,4 +220,4 @@ function isSchemaIssue(issue) {
|
|
|
367
220
|
return true;
|
|
368
221
|
}
|
|
369
222
|
|
|
370
|
-
export { ContractBuilder,
|
|
223
|
+
export { ContractBuilder, HIDDEN_META_PLUGINS_SYMBOL, ProcedureContract, ValidationError, asyncIteratorObject, augmentContractRouter, createContractClientFactory, asyncIteratorObject as eventIterator, getAsyncIteratorObjectSchemaDetails, getHiddenMetaPlugins, getPathMeta, isSchemaIssue, mergeErrorMap, meta, oc, resolveBasePathMeta, resolveMetaPlugins, setHiddenMetaPlugins, type };
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,43 +1,38 @@
|
|
|
1
1
|
import { ClientContext } from '@orpc/client';
|
|
2
2
|
import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
|
|
3
|
-
import {
|
|
3
|
+
import { R as RouterContract } from '../shared/contract.Do92aRJ4.mjs';
|
|
4
4
|
import '@orpc/shared';
|
|
5
5
|
import '@standard-schema/spec';
|
|
6
|
-
import 'openapi-types';
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
interface RequestValidationLinkPluginOptions<_T extends ClientContext> {
|
|
8
|
+
/**
|
|
9
|
+
* Forwards the locally validated/transformed input downstream.
|
|
10
|
+
*
|
|
11
|
+
* Disabled by default because some schema transforms produce a locally valid
|
|
12
|
+
* value that cannot be validated successfully again by the server.
|
|
13
|
+
* Keeping the original input as the flow input is the safer default.
|
|
14
|
+
*
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
forwardValidatedInput?: boolean | undefined;
|
|
9
18
|
}
|
|
10
19
|
/**
|
|
11
|
-
*
|
|
12
|
-
* ensuring that data sent to your server matches the expected types defined in your contract.
|
|
13
|
-
*
|
|
14
|
-
* @throws {ORPCError} with code `BAD_REQUEST` (same as server side) if input doesn't match the expected schema
|
|
15
|
-
* @see {@link https://orpc.dev/docs/plugins/request-validation Request Validation Plugin Docs}
|
|
20
|
+
* Validates client request input against contract schemas before the request is encoded.
|
|
16
21
|
*/
|
|
17
|
-
declare class
|
|
22
|
+
declare class RequestValidationLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
18
23
|
private readonly contract;
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
name: string;
|
|
25
|
+
private readonly forwardValidatedInput;
|
|
26
|
+
constructor(contract: RouterContract, options?: RequestValidationLinkPluginOptions<T>);
|
|
27
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
* A link plugin that validates server responses against your contract schema,
|
|
25
|
-
* ensuring that data returned from your server matches the expected types defined in your contract.
|
|
26
|
-
*
|
|
27
|
-
* - Throws `ValidationError` if output doesn't match the expected schema
|
|
28
|
-
* - Converts mismatched defined errors to normal `ORPCError` instances
|
|
29
|
-
*
|
|
30
|
-
* @see {@link https://orpc.dev/docs/plugins/response-validation Response Validation Plugin Docs}
|
|
31
|
-
*/
|
|
32
|
-
declare class ResponseValidationPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
30
|
+
declare class ResponseValidationLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
33
31
|
private readonly contract;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* run before (validate after) durable iterator plugin, because we expect durable iterator to validation (if user use it)
|
|
38
|
-
*/
|
|
39
|
-
order: number;
|
|
40
|
-
init(options: StandardLinkOptions<T>): void;
|
|
32
|
+
name: string;
|
|
33
|
+
constructor(contract: RouterContract);
|
|
34
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
41
35
|
}
|
|
42
36
|
|
|
43
|
-
export {
|
|
37
|
+
export { RequestValidationLinkPlugin, ResponseValidationLinkPlugin };
|
|
38
|
+
export type { RequestValidationLinkPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,43 +1,38 @@
|
|
|
1
1
|
import { ClientContext } from '@orpc/client';
|
|
2
2
|
import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
|
|
3
|
-
import {
|
|
3
|
+
import { R as RouterContract } from '../shared/contract.Do92aRJ4.js';
|
|
4
4
|
import '@orpc/shared';
|
|
5
5
|
import '@standard-schema/spec';
|
|
6
|
-
import 'openapi-types';
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
interface RequestValidationLinkPluginOptions<_T extends ClientContext> {
|
|
8
|
+
/**
|
|
9
|
+
* Forwards the locally validated/transformed input downstream.
|
|
10
|
+
*
|
|
11
|
+
* Disabled by default because some schema transforms produce a locally valid
|
|
12
|
+
* value that cannot be validated successfully again by the server.
|
|
13
|
+
* Keeping the original input as the flow input is the safer default.
|
|
14
|
+
*
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
forwardValidatedInput?: boolean | undefined;
|
|
9
18
|
}
|
|
10
19
|
/**
|
|
11
|
-
*
|
|
12
|
-
* ensuring that data sent to your server matches the expected types defined in your contract.
|
|
13
|
-
*
|
|
14
|
-
* @throws {ORPCError} with code `BAD_REQUEST` (same as server side) if input doesn't match the expected schema
|
|
15
|
-
* @see {@link https://orpc.dev/docs/plugins/request-validation Request Validation Plugin Docs}
|
|
20
|
+
* Validates client request input against contract schemas before the request is encoded.
|
|
16
21
|
*/
|
|
17
|
-
declare class
|
|
22
|
+
declare class RequestValidationLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
18
23
|
private readonly contract;
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
name: string;
|
|
25
|
+
private readonly forwardValidatedInput;
|
|
26
|
+
constructor(contract: RouterContract, options?: RequestValidationLinkPluginOptions<T>);
|
|
27
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
* A link plugin that validates server responses against your contract schema,
|
|
25
|
-
* ensuring that data returned from your server matches the expected types defined in your contract.
|
|
26
|
-
*
|
|
27
|
-
* - Throws `ValidationError` if output doesn't match the expected schema
|
|
28
|
-
* - Converts mismatched defined errors to normal `ORPCError` instances
|
|
29
|
-
*
|
|
30
|
-
* @see {@link https://orpc.dev/docs/plugins/response-validation Response Validation Plugin Docs}
|
|
31
|
-
*/
|
|
32
|
-
declare class ResponseValidationPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
30
|
+
declare class ResponseValidationLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
33
31
|
private readonly contract;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* run before (validate after) durable iterator plugin, because we expect durable iterator to validation (if user use it)
|
|
38
|
-
*/
|
|
39
|
-
order: number;
|
|
40
|
-
init(options: StandardLinkOptions<T>): void;
|
|
32
|
+
name: string;
|
|
33
|
+
constructor(contract: RouterContract);
|
|
34
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
41
35
|
}
|
|
42
36
|
|
|
43
|
-
export {
|
|
37
|
+
export { RequestValidationLinkPlugin, ResponseValidationLinkPlugin };
|
|
38
|
+
export type { RequestValidationLinkPluginOptions };
|