@temporary-name/server 1.9.3-alpha.26612c2cf6a7177d2b500d984d282309d8320ca3 → 1.9.3-alpha.2957dbc009ec31fa21575f028b83c96651cba827

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.
Files changed (39) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +3 -5
  2. package/dist/adapters/aws-lambda/index.d.ts +3 -5
  3. package/dist/adapters/aws-lambda/index.mjs +3 -3
  4. package/dist/adapters/fetch/index.d.mts +7 -85
  5. package/dist/adapters/fetch/index.d.ts +7 -85
  6. package/dist/adapters/fetch/index.mjs +15 -154
  7. package/dist/adapters/node/index.d.mts +7 -62
  8. package/dist/adapters/node/index.d.ts +7 -62
  9. package/dist/adapters/node/index.mjs +13 -119
  10. package/dist/adapters/standard/index.d.mts +9 -6
  11. package/dist/adapters/standard/index.d.ts +9 -6
  12. package/dist/adapters/standard/index.mjs +4 -4
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +72 -195
  15. package/dist/index.d.ts +72 -195
  16. package/dist/index.mjs +131 -114
  17. package/dist/openapi/index.d.mts +10 -27
  18. package/dist/openapi/index.d.ts +10 -27
  19. package/dist/openapi/index.mjs +57 -108
  20. package/dist/shared/{server.CjkiSCui.mjs → server.B7tjiDal.mjs} +73 -115
  21. package/dist/shared/server.C1RJffw4.mjs +30 -0
  22. package/dist/shared/server.CQIFwyhc.mjs +40 -0
  23. package/dist/shared/server.CpS0m3at.mjs +403 -0
  24. package/dist/shared/server.DPD7R7h_.d.mts +226 -0
  25. package/dist/shared/server.DPD7R7h_.d.ts +226 -0
  26. package/dist/shared/server.DfUs5c4R.d.ts +41 -0
  27. package/dist/shared/server.L8lRAYBR.d.mts +41 -0
  28. package/package.json +10 -27
  29. package/dist/plugins/index.d.mts +0 -160
  30. package/dist/plugins/index.d.ts +0 -160
  31. package/dist/plugins/index.mjs +0 -288
  32. package/dist/shared/server.BYnDyuDL.d.mts +0 -23
  33. package/dist/shared/server.BlJrjUA9.d.mts +0 -56
  34. package/dist/shared/server.C-tNYmY_.d.ts +0 -56
  35. package/dist/shared/server.DdHBdcen.mjs +0 -262
  36. package/dist/shared/server.JI4dqTgD.d.ts +0 -23
  37. package/dist/shared/server.Kxw442A9.mjs +0 -247
  38. package/dist/shared/server.WsFQIubj.d.mts +0 -235
  39. package/dist/shared/server.WsFQIubj.d.ts +0 -235
package/dist/index.mjs CHANGED
@@ -1,11 +1,64 @@
1
- import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
2
- export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
3
- import { mergePrefix, mergeTags, ContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, prefixRoute, isContractProcedure, getContractRouter } from '@temporary-name/contract';
4
- export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
5
- import { SchemaClass, gatingContext } from '@temporary-name/zod';
6
- 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.CjkiSCui.mjs';
7
- export { L as LAZY_SYMBOL, p as createAccessibleLazyRouter, f as createORPCErrorConstructorMap, o as getHiddenRouterContract, k as isStartWithMiddlewares, h as lazy, m as mergeCurrentContext, n as mergeMiddlewares, j as middlewareOutputFn, r as resolveContractProcedures, t as traverseContractProcedures, q as unlazyRouter } from './shared/server.CjkiSCui.mjs';
1
+ import { mergePrefix, mergeTags, mergeMeta, parseEndpointDefinition, mergeRoute, prefixRoute, initialSchemas } 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, C as Contract, a as addMiddleware, l as lazyInternal, g as getLazyMeta, u as unlazy, i as isProcedure, b as isLazy, d as getRouter } from './shared/server.B7tjiDal.mjs';
8
+ export { L as LAZY_SYMBOL, n as createAccessibleLazyRouter, j as isStartWithMiddlewares, f as lazy, m as mergeCurrentContext, k as mergeMiddlewares, h as middlewareOutputFn, r as resolveContractProcedures, t as traverseContractProcedures, o as unlazyRouter } from './shared/server.B7tjiDal.mjs';
8
9
  export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
10
+ import 'cookie';
11
+
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}"` });
15
+ }
16
+ }
17
+ function validateTokenAuth(config, token, options) {
18
+ const { tokenPrefix, validate } = config;
19
+ validateTokenPrefix(tokenPrefix, token);
20
+ return validate(token, options);
21
+ }
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);
29
+ }
30
+ function authByHeader(config, options) {
31
+ const authHeader = options.request.headers.get(config.name);
32
+ return authHeader ? validateTokenAuth(config, authHeader, options) : void 0;
33
+ }
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);
61
+ }
9
62
 
10
63
  class DecoratedProcedure extends Procedure {
11
64
  /**
@@ -26,24 +79,12 @@ class DecoratedProcedure extends Procedure {
26
79
  }
27
80
  }
28
81
 
29
- class ProcedureBuilder extends ContractProcedure {
82
+ class ProcedureBuilder extends Contract {
30
83
  z;
31
84
  constructor(def) {
32
85
  super(def);
33
86
  this.z = new SchemaClass();
34
87
  }
35
- /**
36
- * Adds type-safe custom errors to the contract.
37
- * The provided errors are spared-merged with any existing errors in the contract.
38
- *
39
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
40
- */
41
- errors(errors) {
42
- return new ProcedureBuilder({
43
- ...this["~orpc"],
44
- errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
45
- });
46
- }
47
88
  /**
48
89
  * Sets or updates the metadata for the contract.
49
90
  * The provided metadata is spared-merged with any existing metadata in the contract.
@@ -56,6 +97,19 @@ class ProcedureBuilder extends ContractProcedure {
56
97
  meta: mergeMeta(this["~orpc"].meta, meta)
57
98
  });
58
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
+ }
59
113
  /**
60
114
  * Sets or updates the route definition for the contract.
61
115
  * The provided route is spared-merged with any existing route in the contract.
@@ -64,22 +118,30 @@ class ProcedureBuilder extends ContractProcedure {
64
118
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
65
119
  * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
66
120
  */
67
- route(route) {
121
+ endpointOpts(route) {
68
122
  const { prefix } = this["~orpc"];
69
123
  return new ProcedureBuilder({
70
124
  ...this["~orpc"],
71
125
  route: mergeRoute(this["~orpc"].route, prefix ? prefixRoute(route, prefix) : route)
72
126
  });
73
127
  }
74
- /**
75
- * Defines the input validation schema.
76
- *
77
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
78
- */
79
- input(schema) {
128
+ query(schema) {
80
129
  return new ProcedureBuilder({
81
130
  ...this["~orpc"],
82
- inputSchema: schema,
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) {
139
+ return new ProcedureBuilder({
140
+ ...this["~orpc"],
141
+ schemas: {
142
+ ...this["~orpc"].schemas,
143
+ bodySchema: schema instanceof core.$ZodType ? schema : object(schema)
144
+ },
83
145
  inputValidationIndex: this["~orpc"].middlewares.length
84
146
  });
85
147
  }
@@ -91,7 +153,10 @@ class ProcedureBuilder extends ContractProcedure {
91
153
  output(schema) {
92
154
  return new ProcedureBuilder({
93
155
  ...this["~orpc"],
94
- outputSchema: schema,
156
+ schemas: {
157
+ ...this["~orpc"].schemas,
158
+ outputSchema: schema instanceof core.$ZodType ? schema : object(schema)
159
+ },
95
160
  outputValidationIndex: this["~orpc"].middlewares.length
96
161
  });
97
162
  }
@@ -108,6 +173,36 @@ class ProcedureBuilder extends ContractProcedure {
108
173
  middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
109
174
  });
110
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
+ }
111
206
  useGating(gates, isGateEnabled) {
112
207
  return this.use(({ next, context }) => {
113
208
  return gatingContext.run(
@@ -122,6 +217,9 @@ class ProcedureBuilder extends ContractProcedure {
122
217
  * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
123
218
  */
124
219
  handler(handler) {
220
+ if (this["~orpc"].schemas.outputSchema === initialSchemas.outputSchema) {
221
+ throw new Error("You must call .output() before calling .handler()");
222
+ }
125
223
  return new DecoratedProcedure({
126
224
  ...this["~orpc"],
127
225
  handler
@@ -223,7 +321,6 @@ function createApiBuilder(opts = {}) {
223
321
  return new Builder({
224
322
  route: {},
225
323
  meta: opts.meta ?? {},
226
- errorMap: {},
227
324
  inputValidationIndex: 0,
228
325
  outputValidationIndex: 0,
229
326
  middlewares: [
@@ -231,87 +328,15 @@ function createApiBuilder(opts = {}) {
231
328
  console.dir(error, { depth: null });
232
329
  })
233
330
  ],
331
+ schemas: initialSchemas,
234
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
235
333
  // the best solution). For now I've removed the interface to configure it externally.
236
- dedupeLeadingMiddlewares: true
334
+ dedupeLeadingMiddlewares: true,
335
+ authConfigs: []
237
336
  });
238
337
  }
239
338
  const os = createApiBuilder();
240
339
 
241
- function implementerInternal(contract, middlewares) {
242
- if (isContractProcedure(contract)) {
243
- const impl2 = new Builder({
244
- ...contract["~orpc"],
245
- middlewares,
246
- inputValidationIndex: middlewares.length,
247
- outputValidationIndex: middlewares.length,
248
- dedupeLeadingMiddlewares: true
249
- });
250
- return impl2;
251
- }
252
- const impl = new Proxy(contract, {
253
- get: (target, key) => {
254
- if (typeof key !== "string") {
255
- return Reflect.get(target, key);
256
- }
257
- let method;
258
- if (key === "middleware") {
259
- method = (mid) => decorateMiddleware(mid);
260
- } else if (key === "use") {
261
- method = (mid) => {
262
- return implementerInternal(contract, addMiddleware(middlewares, mid));
263
- };
264
- } else if (key === "router") {
265
- method = (router) => {
266
- const adapted = enhanceRouter(router, {
267
- middlewares,
268
- errorMap: {},
269
- prefix: void 0,
270
- tags: void 0,
271
- dedupeLeadingMiddlewares: true
272
- });
273
- return setHiddenRouterContract(adapted, contract);
274
- };
275
- }
276
- const next = getContractRouter(target, [key]);
277
- if (!next) {
278
- return method ?? next;
279
- }
280
- const nextImpl = implementerInternal(next, middlewares);
281
- if (method) {
282
- return new Proxy(method, {
283
- get(_, key2) {
284
- return Reflect.get(nextImpl, key2);
285
- }
286
- });
287
- }
288
- return nextImpl;
289
- }
290
- });
291
- return impl;
292
- }
293
- function implement(contract) {
294
- const implInternal = implementerInternal(contract, []);
295
- const impl = new Proxy(implInternal, {
296
- get: (target, key) => {
297
- let method;
298
- if (key === "$context") {
299
- method = () => impl;
300
- }
301
- const next = Reflect.get(target, key);
302
- if (!method || !next || typeof next !== "function" && typeof next !== "object") {
303
- return method || next;
304
- }
305
- return new Proxy(method, {
306
- get(_, key2) {
307
- return Reflect.get(next, key2);
308
- }
309
- });
310
- }
311
- });
312
- return impl;
313
- }
314
-
315
340
  function createAssertedLazyProcedure(lazied) {
316
341
  const lazyProcedure = lazyInternal(async () => {
317
342
  const { default: maybeProcedure } = await unlazy(lazied);
@@ -326,14 +351,6 @@ function createAssertedLazyProcedure(lazied) {
326
351
  }, getLazyMeta(lazied));
327
352
  return lazyProcedure;
328
353
  }
329
- function createContractedProcedure(procedure, contract) {
330
- return new Procedure({
331
- ...procedure["~orpc"],
332
- errorMap: contract["~orpc"].errorMap,
333
- route: contract["~orpc"].route,
334
- meta: contract["~orpc"].meta
335
- });
336
- }
337
354
  function call(procedure, input, ...rest) {
338
355
  const options = resolveMaybeOptionalOptions(rest);
339
356
  return createProcedureClient(procedure, options)(input, options);
@@ -364,4 +381,4 @@ function createRouterClient(router, ...rest) {
364
381
  return recursive;
365
382
  }
366
383
 
367
- 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 };
384
+ export { Builder, BuilderWithMiddlewares, Contract, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, isLazy, isProcedure, lazyInternal, os, unlazy };
@@ -1,11 +1,11 @@
1
- import { OpenAPI, AnyContractProcedure, AnySchema, AnyContractRouter } from '@temporary-name/contract';
1
+ import { OpenAPI, AnySchema } from '@temporary-name/contract';
2
2
  export { OpenAPI } from '@temporary-name/contract';
3
- import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter, ORPCError, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@temporary-name/server';
4
- import { Promisable, Value, HTTPPath, HTTPMethod, NestedClient, Client, MaybeOptionalOptions } from '@temporary-name/shared';
3
+ import { Contract, TraverseContractProcedureCallbackOptions, ContractRouter, AnyRouter } from '@temporary-name/server';
4
+ import { Promisable, Value, HTTPPath, HTTPMethod } 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';
7
7
 
8
- type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
8
+ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
9
9
  /**
10
10
  * Customize The Operation Object by proxy an error map item or a middleware.
11
11
  *
@@ -13,7 +13,7 @@ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: Open
13
13
  */
14
14
  declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
15
15
  declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
16
- declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
16
+ declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: Contract): OpenAPI.OperationObject;
17
17
 
18
18
  /**
19
19
  * @internal
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
55
55
  minStructureDepthForRef?: number;
56
56
  }
57
57
  interface SchemaConverter {
58
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
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>;
@@ -76,7 +76,7 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
76
76
  * @deprecated Use `filter` option instead.
77
77
  * @default () => false
78
78
  */
79
- exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
79
+ exclude?: (procedure: Contract, path: readonly string[]) => boolean;
80
80
  /**
81
81
  * Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
82
82
  *
@@ -129,7 +129,7 @@ declare class OpenAPIGenerator {
129
129
  *
130
130
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
131
131
  */
132
- generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
132
+ generate(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
133
133
  }
134
134
 
135
135
  /**
@@ -162,23 +162,6 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
162
162
  declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
163
163
  declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
164
164
 
165
- type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends null ? T : T extends undefined ? T : T extends Array<unknown> ? JsonifiedArray<T> : T extends Record<string, unknown> ? {
166
- [K in keyof T]: JsonifiedValue<T[K]>;
167
- } : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
168
- type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [
169
- U extends undefined ? null : JsonifiedValue<U>,
170
- ...JsonifiedArray<V>
171
- ] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
172
- /**
173
- * Convert types that JSON not support to corresponding json types
174
- *
175
- * @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
176
- */
177
- type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, UError extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : UError> : {
178
- [K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
179
- };
180
- declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
181
-
182
165
  /**
183
166
  *@internal
184
167
  */
@@ -216,5 +199,5 @@ declare const oo: {
216
199
  spec: typeof customOpenAPIOperation;
217
200
  };
218
201
 
219
- export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
220
- export type { ConditionalSchemaConverter, FileSchema, JsonifiedArray, JsonifiedClient, JsonifiedValue, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
202
+ export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
203
+ export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
@@ -1,11 +1,11 @@
1
- import { OpenAPI, AnyContractProcedure, AnySchema, AnyContractRouter } from '@temporary-name/contract';
1
+ import { OpenAPI, AnySchema } from '@temporary-name/contract';
2
2
  export { OpenAPI } from '@temporary-name/contract';
3
- import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter, ORPCError, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@temporary-name/server';
4
- import { Promisable, Value, HTTPPath, HTTPMethod, NestedClient, Client, MaybeOptionalOptions } from '@temporary-name/shared';
3
+ import { Contract, TraverseContractProcedureCallbackOptions, ContractRouter, AnyRouter } from '@temporary-name/server';
4
+ import { Promisable, Value, HTTPPath, HTTPMethod } 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';
7
7
 
8
- type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
8
+ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
9
9
  /**
10
10
  * Customize The Operation Object by proxy an error map item or a middleware.
11
11
  *
@@ -13,7 +13,7 @@ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: Open
13
13
  */
14
14
  declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
15
15
  declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
16
- declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
16
+ declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: Contract): OpenAPI.OperationObject;
17
17
 
18
18
  /**
19
19
  * @internal
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
55
55
  minStructureDepthForRef?: number;
56
56
  }
57
57
  interface SchemaConverter {
58
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
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>;
@@ -76,7 +76,7 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
76
76
  * @deprecated Use `filter` option instead.
77
77
  * @default () => false
78
78
  */
79
- exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
79
+ exclude?: (procedure: Contract, path: readonly string[]) => boolean;
80
80
  /**
81
81
  * Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
82
82
  *
@@ -129,7 +129,7 @@ declare class OpenAPIGenerator {
129
129
  *
130
130
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
131
131
  */
132
- generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
132
+ generate(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
133
133
  }
134
134
 
135
135
  /**
@@ -162,23 +162,6 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
162
162
  declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
163
163
  declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
164
164
 
165
- type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends null ? T : T extends undefined ? T : T extends Array<unknown> ? JsonifiedArray<T> : T extends Record<string, unknown> ? {
166
- [K in keyof T]: JsonifiedValue<T[K]>;
167
- } : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
168
- type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [
169
- U extends undefined ? null : JsonifiedValue<U>,
170
- ...JsonifiedArray<V>
171
- ] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
172
- /**
173
- * Convert types that JSON not support to corresponding json types
174
- *
175
- * @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
176
- */
177
- type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, UError extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : UError> : {
178
- [K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
179
- };
180
- declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
181
-
182
165
  /**
183
166
  *@internal
184
167
  */
@@ -216,5 +199,5 @@ declare const oo: {
216
199
  spec: typeof customOpenAPIOperation;
217
200
  };
218
201
 
219
- export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
220
- export type { ConditionalSchemaConverter, FileSchema, JsonifiedArray, JsonifiedClient, JsonifiedValue, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
202
+ export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
203
+ export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };