@temporary-name/server 1.9.3-alpha.03f5d40e5b399f85012c2fb4e98167e26d551d36 → 1.9.3-alpha.0f2e1f4d66464608b85c66977bff51174cbb238f
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/dist/adapters/aws-lambda/index.d.mts +3 -4
- package/dist/adapters/aws-lambda/index.d.ts +3 -4
- package/dist/adapters/aws-lambda/index.mjs +3 -3
- package/dist/adapters/fetch/index.d.mts +3 -4
- package/dist/adapters/fetch/index.d.ts +3 -4
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +3 -4
- package/dist/adapters/node/index.d.ts +3 -4
- package/dist/adapters/node/index.mjs +3 -3
- package/dist/adapters/standard/index.d.mts +10 -6
- package/dist/adapters/standard/index.d.ts +10 -6
- package/dist/adapters/standard/index.mjs +4 -4
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +73 -126
- package/dist/index.d.ts +73 -126
- package/dist/index.mjs +125 -234
- package/dist/openapi/index.d.mts +4 -4
- package/dist/openapi/index.d.ts +4 -4
- package/dist/openapi/index.mjs +61 -128
- package/dist/plugins/index.d.mts +5 -83
- package/dist/plugins/index.d.ts +5 -83
- package/dist/plugins/index.mjs +17 -189
- package/dist/shared/{server.Bk5r0-2R.d.ts → server.25yUS-xw.d.mts} +3 -4
- package/dist/shared/{server.Bs6ka_UE.d.mts → server.BKwU5-Ea.d.mts} +2 -2
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/{server.CbLTWfgn.d.mts → server.Co-zpS8Y.d.ts} +3 -4
- package/dist/shared/{server.BVxcyR6X.mjs → server.DRYRuXpK.mjs} +17 -50
- package/dist/shared/{server.D2UFMrxf.d.ts → server.DV_PWBS2.d.ts} +2 -2
- package/dist/shared/server.DWEp52Gx.mjs +379 -0
- package/dist/shared/{server.BEHw7Eyx.mjs → server.JtIZ8YG7.mjs} +1 -11
- package/dist/shared/server.VtI8pLxV.d.mts +242 -0
- package/dist/shared/server.VtI8pLxV.d.ts +242 -0
- package/package.json +10 -22
- package/dist/shared/server.CZNLCQBm.d.mts +0 -192
- package/dist/shared/server.CZNLCQBm.d.ts +0 -192
- package/dist/shared/server.DcfsPloY.mjs +0 -202
package/dist/index.mjs
CHANGED
|
@@ -1,50 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
import { SchemaClass, gatingContext } from '@temporary-name/zod';
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { mergePrefix, mergeTags, ContractProcedure, mergeMeta, parseEndpointDefinition, mergeRoute, prefixRoute, initialSchemas, isContractProcedure, getContractRouter } from '@temporary-name/contract';
|
|
2
|
+
export { ValidationError, eventIterator } from '@temporary-name/contract';
|
|
3
|
+
import { assertNever, splitFirst, ORPCError, onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
4
|
+
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
5
|
+
import { SchemaClass, object, core, gatingContext } from '@temporary-name/zod';
|
|
6
|
+
import { g as getCookie } from './shared/server.C1RJffw4.mjs';
|
|
7
|
+
import { P as Procedure, c as createProcedureClient, e as enhanceRouter, a as addMiddleware, s as setHiddenRouterContract, l as lazyInternal, g as getLazyMeta, u as unlazy, i as isProcedure, b as isLazy, d as getRouter } from './shared/server.DWEp52Gx.mjs';
|
|
8
|
+
export { L as LAZY_SYMBOL, o as createAccessibleLazyRouter, n as getHiddenRouterContract, j as isStartWithMiddlewares, f as lazy, m as mergeCurrentContext, k as mergeMiddlewares, h as middlewareOutputFn, r as resolveContractProcedures, t as traverseContractProcedures, p as unlazyRouter } from './shared/server.DWEp52Gx.mjs';
|
|
8
9
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
10
|
+
import 'cookie';
|
|
9
11
|
|
|
10
|
-
function
|
|
11
|
-
if (
|
|
12
|
-
|
|
12
|
+
function validateTokenPrefix(prefix, token) {
|
|
13
|
+
if (prefix && !token.startsWith(prefix)) {
|
|
14
|
+
throw new ORPCError("UNAUTHORIZED", { message: `Invalid auth token. It must start with "${prefix}"` });
|
|
13
15
|
}
|
|
14
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
15
|
-
if (compare[i] === void 0) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
if (middlewares[i] !== compare[i]) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
16
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return [...first, ...second];
|
|
17
|
+
function validateTokenAuth(config, token, options) {
|
|
18
|
+
const { tokenPrefix, validate } = config;
|
|
19
|
+
validateTokenPrefix(tokenPrefix, token);
|
|
20
|
+
return validate(token, options);
|
|
29
21
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
22
|
+
function authByQuery(config, options) {
|
|
23
|
+
const { name, tokenPrefix, validate } = config;
|
|
24
|
+
const query = options.request.url.searchParams;
|
|
25
|
+
const token = query.get(name);
|
|
26
|
+
if (!token) return void 0;
|
|
27
|
+
validateTokenPrefix(tokenPrefix, token);
|
|
28
|
+
return validate(token, options);
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* This property holds the defined options.
|
|
37
|
-
*/
|
|
38
|
-
"~orpc";
|
|
39
|
-
constructor(def) {
|
|
40
|
-
this["~orpc"] = def;
|
|
41
|
-
}
|
|
30
|
+
function authByHeader(config, options) {
|
|
31
|
+
const authHeader = options.request.headers.get(config.name);
|
|
32
|
+
return authHeader ? validateTokenAuth(config, authHeader, options) : void 0;
|
|
42
33
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
function authByCookie(config, options) {
|
|
35
|
+
const cookie = getCookie(options.request.headers, config.name);
|
|
36
|
+
return cookie ? validateTokenAuth(config, cookie, options) : void 0;
|
|
37
|
+
}
|
|
38
|
+
function authByBearer(config, options) {
|
|
39
|
+
const authHeader = options.request.headers.get("Authorization");
|
|
40
|
+
if (!authHeader) return void 0;
|
|
41
|
+
const [authType, bearer] = splitFirst(authHeader, " ");
|
|
42
|
+
return authType === "Bearer" ? validateTokenAuth(config, bearer, options) : void 0;
|
|
43
|
+
}
|
|
44
|
+
function authByBasic(config, options) {
|
|
45
|
+
const authHeader = options.request.headers.get("Authorization");
|
|
46
|
+
if (!authHeader) return void 0;
|
|
47
|
+
const [authType, encoded] = splitFirst(authHeader, " ");
|
|
48
|
+
if (authType !== "Basic") return void 0;
|
|
49
|
+
const decoded = Buffer.from(encoded, "base64").toString("utf-8");
|
|
50
|
+
const [username, password] = splitFirst(decoded, ":");
|
|
51
|
+
validateTokenPrefix(config.tokenPrefix, password);
|
|
52
|
+
return config.validate(username, password, options);
|
|
53
|
+
}
|
|
54
|
+
function authByType(config, options) {
|
|
55
|
+
const { type } = config;
|
|
56
|
+
return type === "header" ? authByHeader(config, options) : type === "query" ? authByQuery(config, options) : type === "cookie" ? authByCookie(config, options) : type === "bearer" ? authByBearer(config, options) : type === "basic" ? authByBasic(config, options) : type === "none" ? false : assertNever(type);
|
|
57
|
+
}
|
|
58
|
+
function authDescription(config) {
|
|
59
|
+
const { type } = config;
|
|
60
|
+
return type === "basic" ? "a Basic Authentication header" : type === "bearer" ? "a Bearer Authentication header" : type === "header" ? `a header named "${config.name}"` : type === "query" ? `a query parameter named "${config.name}"` : type === "cookie" ? `a cookie named "${config.name}"` : type === "none" ? "no authentication" : assertNever(type);
|
|
48
61
|
}
|
|
49
62
|
|
|
50
63
|
class DecoratedProcedure extends Procedure {
|
|
@@ -66,170 +79,12 @@ class DecoratedProcedure extends Procedure {
|
|
|
66
79
|
}
|
|
67
80
|
}
|
|
68
81
|
|
|
69
|
-
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
|
70
|
-
function setHiddenRouterContract(router, contract) {
|
|
71
|
-
return new Proxy(router, {
|
|
72
|
-
get(target, key) {
|
|
73
|
-
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
|
74
|
-
return contract;
|
|
75
|
-
}
|
|
76
|
-
return Reflect.get(target, key);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function getHiddenRouterContract(router) {
|
|
81
|
-
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function getRouter(router, path) {
|
|
85
|
-
let current = router;
|
|
86
|
-
for (let i = 0; i < path.length; i++) {
|
|
87
|
-
const segment = path[i];
|
|
88
|
-
if (!current) {
|
|
89
|
-
return void 0;
|
|
90
|
-
}
|
|
91
|
-
if (isProcedure(current)) {
|
|
92
|
-
return void 0;
|
|
93
|
-
}
|
|
94
|
-
if (!isLazy(current)) {
|
|
95
|
-
current = current[segment];
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const lazied = current;
|
|
99
|
-
const rest = path.slice(i);
|
|
100
|
-
return lazy(async () => {
|
|
101
|
-
const unwrapped = await unlazy(lazied);
|
|
102
|
-
const next = getRouter(unwrapped.default, rest);
|
|
103
|
-
return unlazy(next);
|
|
104
|
-
}, getLazyMeta(lazied));
|
|
105
|
-
}
|
|
106
|
-
return current;
|
|
107
|
-
}
|
|
108
|
-
function createAccessibleLazyRouter(lazied) {
|
|
109
|
-
const recursive = new Proxy(lazied, {
|
|
110
|
-
get(target, key) {
|
|
111
|
-
if (typeof key !== "string") {
|
|
112
|
-
return Reflect.get(target, key);
|
|
113
|
-
}
|
|
114
|
-
const next = getRouter(lazied, [key]);
|
|
115
|
-
return createAccessibleLazyRouter(next);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
return recursive;
|
|
119
|
-
}
|
|
120
|
-
function enhanceRouter(router, options) {
|
|
121
|
-
if (isLazy(router)) {
|
|
122
|
-
const laziedMeta = getLazyMeta(router);
|
|
123
|
-
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
|
124
|
-
const enhanced2 = lazy(
|
|
125
|
-
async () => {
|
|
126
|
-
const { default: unlaziedRouter } = await unlazy(router);
|
|
127
|
-
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
|
128
|
-
return unlazy(enhanced3);
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
...laziedMeta,
|
|
132
|
-
prefix: enhancedPrefix
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
const accessible = createAccessibleLazyRouter(enhanced2);
|
|
136
|
-
return accessible;
|
|
137
|
-
}
|
|
138
|
-
if (isProcedure(router)) {
|
|
139
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, {
|
|
140
|
-
dedupeLeading: options.dedupeLeadingMiddlewares
|
|
141
|
-
});
|
|
142
|
-
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
|
143
|
-
const enhanced2 = new Procedure({
|
|
144
|
-
...router["~orpc"],
|
|
145
|
-
route: enhanceRoute(router["~orpc"].route, options),
|
|
146
|
-
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
147
|
-
middlewares: newMiddlewares,
|
|
148
|
-
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
149
|
-
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
|
150
|
-
});
|
|
151
|
-
return enhanced2;
|
|
152
|
-
}
|
|
153
|
-
const enhanced = {};
|
|
154
|
-
for (const key in router) {
|
|
155
|
-
enhanced[key] = enhanceRouter(router[key], options);
|
|
156
|
-
}
|
|
157
|
-
return enhanced;
|
|
158
|
-
}
|
|
159
|
-
function traverseContractProcedures(options, callback, lazyOptions = []) {
|
|
160
|
-
let currentRouter = options.router;
|
|
161
|
-
const hiddenContract = getHiddenRouterContract(options.router);
|
|
162
|
-
if (hiddenContract !== void 0) {
|
|
163
|
-
currentRouter = hiddenContract;
|
|
164
|
-
}
|
|
165
|
-
if (isLazy(currentRouter)) {
|
|
166
|
-
lazyOptions.push({
|
|
167
|
-
router: currentRouter,
|
|
168
|
-
path: options.path
|
|
169
|
-
});
|
|
170
|
-
} else if (isContractProcedure(currentRouter)) {
|
|
171
|
-
callback({
|
|
172
|
-
contract: currentRouter,
|
|
173
|
-
path: options.path
|
|
174
|
-
});
|
|
175
|
-
} else {
|
|
176
|
-
for (const key in currentRouter) {
|
|
177
|
-
traverseContractProcedures(
|
|
178
|
-
{
|
|
179
|
-
router: currentRouter[key],
|
|
180
|
-
path: [...options.path, key]
|
|
181
|
-
},
|
|
182
|
-
callback,
|
|
183
|
-
lazyOptions
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return lazyOptions;
|
|
188
|
-
}
|
|
189
|
-
async function resolveContractProcedures(options, callback) {
|
|
190
|
-
const pending = [options];
|
|
191
|
-
for (const options2 of pending) {
|
|
192
|
-
const lazyOptions = traverseContractProcedures(options2, callback);
|
|
193
|
-
for (const options3 of lazyOptions) {
|
|
194
|
-
const { default: router } = await unlazy(options3.router);
|
|
195
|
-
pending.push({
|
|
196
|
-
router,
|
|
197
|
-
path: options3.path
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async function unlazyRouter(router) {
|
|
203
|
-
if (isProcedure(router)) {
|
|
204
|
-
return router;
|
|
205
|
-
}
|
|
206
|
-
const unlazied = {};
|
|
207
|
-
for (const key in router) {
|
|
208
|
-
const item = router[key];
|
|
209
|
-
const { default: unlaziedRouter } = await unlazy(item);
|
|
210
|
-
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
|
211
|
-
}
|
|
212
|
-
return unlazied;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
82
|
class ProcedureBuilder extends ContractProcedure {
|
|
216
83
|
z;
|
|
217
84
|
constructor(def) {
|
|
218
85
|
super(def);
|
|
219
86
|
this.z = new SchemaClass();
|
|
220
87
|
}
|
|
221
|
-
/**
|
|
222
|
-
* Adds type-safe custom errors to the contract.
|
|
223
|
-
* The provided errors are spared-merged with any existing errors in the contract.
|
|
224
|
-
*
|
|
225
|
-
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
226
|
-
*/
|
|
227
|
-
errors(errors) {
|
|
228
|
-
return new ProcedureBuilder({
|
|
229
|
-
...this["~orpc"],
|
|
230
|
-
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
88
|
/**
|
|
234
89
|
* Sets or updates the metadata for the contract.
|
|
235
90
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
@@ -242,6 +97,19 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
242
97
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
243
98
|
});
|
|
244
99
|
}
|
|
100
|
+
endpoint(stringsOrEndpoint, ...values) {
|
|
101
|
+
const { method, path, pathSchema } = parseEndpointDefinition(stringsOrEndpoint, values);
|
|
102
|
+
const { prefix } = this["~orpc"];
|
|
103
|
+
const route = { method, path };
|
|
104
|
+
return new ProcedureBuilder({
|
|
105
|
+
...this["~orpc"],
|
|
106
|
+
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route),
|
|
107
|
+
schemas: {
|
|
108
|
+
...this["~orpc"].schemas,
|
|
109
|
+
pathSchema
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
245
113
|
/**
|
|
246
114
|
* Sets or updates the route definition for the contract.
|
|
247
115
|
* The provided route is spared-merged with any existing route in the contract.
|
|
@@ -250,22 +118,30 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
250
118
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
251
119
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
252
120
|
*/
|
|
253
|
-
|
|
121
|
+
endpointOpts(route) {
|
|
254
122
|
const { prefix } = this["~orpc"];
|
|
255
123
|
return new ProcedureBuilder({
|
|
256
124
|
...this["~orpc"],
|
|
257
125
|
route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
|
|
258
126
|
});
|
|
259
127
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
128
|
+
query(schema) {
|
|
129
|
+
return new ProcedureBuilder({
|
|
130
|
+
...this["~orpc"],
|
|
131
|
+
schemas: {
|
|
132
|
+
...this["~orpc"].schemas,
|
|
133
|
+
querySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
134
|
+
},
|
|
135
|
+
inputValidationIndex: this["~orpc"].middlewares.length
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
body(schema) {
|
|
266
139
|
return new ProcedureBuilder({
|
|
267
140
|
...this["~orpc"],
|
|
268
|
-
|
|
141
|
+
schemas: {
|
|
142
|
+
...this["~orpc"].schemas,
|
|
143
|
+
bodySchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
144
|
+
},
|
|
269
145
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
270
146
|
});
|
|
271
147
|
}
|
|
@@ -277,7 +153,10 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
277
153
|
output(schema) {
|
|
278
154
|
return new ProcedureBuilder({
|
|
279
155
|
...this["~orpc"],
|
|
280
|
-
|
|
156
|
+
schemas: {
|
|
157
|
+
...this["~orpc"].schemas,
|
|
158
|
+
outputSchema: schema instanceof core.$ZodType ? schema : object(schema)
|
|
159
|
+
},
|
|
281
160
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
282
161
|
});
|
|
283
162
|
}
|
|
@@ -294,6 +173,36 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
294
173
|
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
295
174
|
});
|
|
296
175
|
}
|
|
176
|
+
// `& {}` is so AuthType will be expanded in parameter info tooltips.
|
|
177
|
+
// The default of false for ValidatedAuthContext is used when you pass in the type 'none'. We use false
|
|
178
|
+
// because we can't use null or undefined (see ValidatedAuthContext) but we still want it to be falsy.
|
|
179
|
+
useAuth(type, ...rest) {
|
|
180
|
+
const config = { type, ...rest[0] };
|
|
181
|
+
const middleware = os.$context().middleware(async (options) => {
|
|
182
|
+
const { next, context } = options;
|
|
183
|
+
if (context.auth) return next();
|
|
184
|
+
const auth = await authByType(config, options);
|
|
185
|
+
if (auth === void 0) {
|
|
186
|
+
const { authConfigs } = options.procedure["~orpc"];
|
|
187
|
+
if (context.auth !== false && config === authConfigs.at(-1)) {
|
|
188
|
+
let authDescriptions = authConfigs.map(authDescription).join(", ");
|
|
189
|
+
if (authConfigs.length > 1) {
|
|
190
|
+
authDescriptions = `one of: ${authDescriptions}`;
|
|
191
|
+
}
|
|
192
|
+
throw new ORPCError("UNAUTHORIZED", {
|
|
193
|
+
message: `Authentication required. You must provide ${authDescriptions}`
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return next();
|
|
197
|
+
}
|
|
198
|
+
return next({ context: { auth } });
|
|
199
|
+
});
|
|
200
|
+
return new this.constructor({
|
|
201
|
+
...this["~orpc"],
|
|
202
|
+
authConfigs: [...this["~orpc"].authConfigs, config],
|
|
203
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
204
|
+
});
|
|
205
|
+
}
|
|
297
206
|
useGating(gates, isGateEnabled) {
|
|
298
207
|
return this.use(({ next, context }) => {
|
|
299
208
|
return gatingContext.run(
|
|
@@ -308,6 +217,9 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
308
217
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
309
218
|
*/
|
|
310
219
|
handler(handler) {
|
|
220
|
+
if (this["~orpc"].schemas.outputSchema === initialSchemas.outputSchema) {
|
|
221
|
+
throw new Error("You must call .output() before calling .handler()");
|
|
222
|
+
}
|
|
311
223
|
return new DecoratedProcedure({
|
|
312
224
|
...this["~orpc"],
|
|
313
225
|
handler
|
|
@@ -349,16 +261,6 @@ class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
|
349
261
|
router(router) {
|
|
350
262
|
return enhanceRouter(router, this["~orpc"]);
|
|
351
263
|
}
|
|
352
|
-
/**
|
|
353
|
-
* Create a lazy router
|
|
354
|
-
* And applies all of the previously defined options to the specified router.
|
|
355
|
-
*
|
|
356
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
357
|
-
*/
|
|
358
|
-
lazyRoute(loader) {
|
|
359
|
-
const lazied = lazy(loader);
|
|
360
|
-
return enhanceRouter(lazied, this["~orpc"]);
|
|
361
|
-
}
|
|
362
264
|
}
|
|
363
265
|
|
|
364
266
|
function decorateMiddleware(middleware) {
|
|
@@ -419,7 +321,6 @@ function createApiBuilder(opts = {}) {
|
|
|
419
321
|
return new Builder({
|
|
420
322
|
route: {},
|
|
421
323
|
meta: opts.meta ?? {},
|
|
422
|
-
errorMap: {},
|
|
423
324
|
inputValidationIndex: 0,
|
|
424
325
|
outputValidationIndex: 0,
|
|
425
326
|
middlewares: [
|
|
@@ -427,9 +328,11 @@ function createApiBuilder(opts = {}) {
|
|
|
427
328
|
console.dir(error, { depth: null });
|
|
428
329
|
})
|
|
429
330
|
],
|
|
331
|
+
schemas: initialSchemas,
|
|
430
332
|
// NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
|
|
431
333
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
432
|
-
dedupeLeadingMiddlewares: true
|
|
334
|
+
dedupeLeadingMiddlewares: true,
|
|
335
|
+
authConfigs: []
|
|
433
336
|
});
|
|
434
337
|
}
|
|
435
338
|
const os = createApiBuilder();
|
|
@@ -439,6 +342,7 @@ function implementerInternal(contract, middlewares) {
|
|
|
439
342
|
const impl2 = new Builder({
|
|
440
343
|
...contract["~orpc"],
|
|
441
344
|
middlewares,
|
|
345
|
+
authConfigs: [],
|
|
442
346
|
inputValidationIndex: middlewares.length,
|
|
443
347
|
outputValidationIndex: middlewares.length,
|
|
444
348
|
dedupeLeadingMiddlewares: true
|
|
@@ -461,18 +365,6 @@ function implementerInternal(contract, middlewares) {
|
|
|
461
365
|
method = (router) => {
|
|
462
366
|
const adapted = enhanceRouter(router, {
|
|
463
367
|
middlewares,
|
|
464
|
-
errorMap: {},
|
|
465
|
-
prefix: void 0,
|
|
466
|
-
tags: void 0,
|
|
467
|
-
dedupeLeadingMiddlewares: true
|
|
468
|
-
});
|
|
469
|
-
return setHiddenRouterContract(adapted, contract);
|
|
470
|
-
};
|
|
471
|
-
} else if (key === "lazyRoute") {
|
|
472
|
-
method = (loader) => {
|
|
473
|
-
const adapted = enhanceRouter(lazy(loader), {
|
|
474
|
-
middlewares,
|
|
475
|
-
errorMap: {},
|
|
476
368
|
prefix: void 0,
|
|
477
369
|
tags: void 0,
|
|
478
370
|
dedupeLeadingMiddlewares: true
|
|
@@ -520,7 +412,7 @@ function implement(contract) {
|
|
|
520
412
|
}
|
|
521
413
|
|
|
522
414
|
function createAssertedLazyProcedure(lazied) {
|
|
523
|
-
const lazyProcedure =
|
|
415
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
524
416
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
525
417
|
if (!isProcedure(maybeProcedure)) {
|
|
526
418
|
throw new Error(`
|
|
@@ -536,7 +428,6 @@ function createAssertedLazyProcedure(lazied) {
|
|
|
536
428
|
function createContractedProcedure(procedure, contract) {
|
|
537
429
|
return new Procedure({
|
|
538
430
|
...procedure["~orpc"],
|
|
539
|
-
errorMap: contract["~orpc"].errorMap,
|
|
540
431
|
route: contract["~orpc"].route,
|
|
541
432
|
meta: contract["~orpc"].meta
|
|
542
433
|
});
|
|
@@ -571,4 +462,4 @@ function createRouterClient(router, ...rest) {
|
|
|
571
462
|
return recursive;
|
|
572
463
|
}
|
|
573
464
|
|
|
574
|
-
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call,
|
|
465
|
+
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, lazyInternal, os, setHiddenRouterContract, unlazy };
|
package/dist/openapi/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenAPI, AnyContractProcedure, AnySchema, AnyContractRouter } from '@temporary-name/contract';
|
|
2
2
|
export { OpenAPI } from '@temporary-name/contract';
|
|
3
|
-
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter,
|
|
3
|
+
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, Meta, RouterClient } from '@temporary-name/server';
|
|
4
4
|
import { Promisable, Value, HTTPPath, HTTPMethod, NestedClient, Client, MaybeOptionalOptions } from '@temporary-name/shared';
|
|
5
5
|
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
6
|
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
|
|
|
55
55
|
minStructureDepthForRef?: number;
|
|
56
56
|
}
|
|
57
57
|
interface SchemaConverter {
|
|
58
|
-
convert(
|
|
58
|
+
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
59
|
}
|
|
60
60
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
61
|
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
@@ -174,10 +174,10 @@ type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T e
|
|
|
174
174
|
*
|
|
175
175
|
* @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
|
|
176
176
|
*/
|
|
177
|
-
type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput
|
|
177
|
+
type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>> : {
|
|
178
178
|
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
179
179
|
};
|
|
180
|
-
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>,
|
|
180
|
+
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
183
|
*@internal
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenAPI, AnyContractProcedure, AnySchema, AnyContractRouter } from '@temporary-name/contract';
|
|
2
2
|
export { OpenAPI } from '@temporary-name/contract';
|
|
3
|
-
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter,
|
|
3
|
+
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, Meta, RouterClient } from '@temporary-name/server';
|
|
4
4
|
import { Promisable, Value, HTTPPath, HTTPMethod, NestedClient, Client, MaybeOptionalOptions } from '@temporary-name/shared';
|
|
5
5
|
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
6
|
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
|
|
|
55
55
|
minStructureDepthForRef?: number;
|
|
56
56
|
}
|
|
57
57
|
interface SchemaConverter {
|
|
58
|
-
convert(
|
|
58
|
+
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
59
|
}
|
|
60
60
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
61
|
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
@@ -174,10 +174,10 @@ type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T e
|
|
|
174
174
|
*
|
|
175
175
|
* @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
|
|
176
176
|
*/
|
|
177
|
-
type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput
|
|
177
|
+
type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>> : {
|
|
178
178
|
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
179
179
|
};
|
|
180
|
-
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>,
|
|
180
|
+
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
183
|
*@internal
|