@temporary-name/server 1.9.3-alpha.f9f5ce625d5edee78250b87b3a64f1d9760c2244 → 1.9.3-alpha.fb7b7d19964e1b2def7056f4345b63d6fcacce10

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 (42) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +4 -5
  2. package/dist/adapters/aws-lambda/index.d.ts +4 -5
  3. package/dist/adapters/aws-lambda/index.mjs +4 -4
  4. package/dist/adapters/fetch/index.d.mts +8 -85
  5. package/dist/adapters/fetch/index.d.ts +8 -85
  6. package/dist/adapters/fetch/index.mjs +16 -155
  7. package/dist/adapters/node/index.d.mts +8 -62
  8. package/dist/adapters/node/index.d.ts +8 -62
  9. package/dist/adapters/node/index.mjs +14 -120
  10. package/dist/adapters/standard/index.d.mts +5 -6
  11. package/dist/adapters/standard/index.d.ts +5 -6
  12. package/dist/adapters/standard/index.mjs +4 -4
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +110 -199
  15. package/dist/index.d.ts +110 -199
  16. package/dist/index.mjs +144 -153
  17. package/dist/openapi/index.d.mts +17 -53
  18. package/dist/openapi/index.d.ts +17 -53
  19. package/dist/openapi/index.mjs +339 -367
  20. package/dist/shared/server.B0LJ_wu-.d.ts +41 -0
  21. package/dist/shared/server.BQZMQrPe.d.mts +41 -0
  22. package/dist/shared/server.C1RJffw4.mjs +30 -0
  23. package/dist/shared/server.CQIFwyhc.mjs +40 -0
  24. package/dist/shared/server.CYa9puL2.mjs +403 -0
  25. package/dist/shared/server.ChOv1yG3.mjs +319 -0
  26. package/dist/shared/server.Cza0RB3u.mjs +160 -0
  27. package/dist/shared/server.DXPMDozZ.d.mts +388 -0
  28. package/dist/shared/server.DXPMDozZ.d.ts +388 -0
  29. package/dist/shared/server.YUvuxHty.mjs +48 -0
  30. package/package.json +11 -28
  31. package/dist/plugins/index.d.mts +0 -84
  32. package/dist/plugins/index.d.ts +0 -84
  33. package/dist/plugins/index.mjs +0 -122
  34. package/dist/shared/server.7aL9gcoU.d.mts +0 -23
  35. package/dist/shared/server.BL2R5jcp.d.mts +0 -228
  36. package/dist/shared/server.BL2R5jcp.d.ts +0 -228
  37. package/dist/shared/server.CVBLzkro.mjs +0 -255
  38. package/dist/shared/server.ClhVCxfg.mjs +0 -413
  39. package/dist/shared/server.D6Qs_UcF.d.mts +0 -55
  40. package/dist/shared/server.DFptr1Nz.d.ts +0 -23
  41. package/dist/shared/server.DpoO_ER_.d.ts +0 -55
  42. package/dist/shared/server.JtIZ8YG7.mjs +0 -237
package/dist/index.mjs CHANGED
@@ -1,11 +1,76 @@
1
- import { mergePrefix, mergeTags, ContractProcedure, mergeErrorMap, mergeMeta, parseEndpointDefinition, mergeRoute, prefixRoute, initialSchemas, isContractProcedure, getContractRouter } from '@temporary-name/contract';
2
- export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
3
- import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
4
- export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
1
+ import { assertNever, splitFirst, ORPCError, onError, resolveMaybeOptionalOptions, isTypescriptObject, isPropertyKey } from '@temporary-name/shared';
2
+ export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
3
+ import * as z from '@temporary-name/zod';
5
4
  import { SchemaClass, object, core, 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.ClhVCxfg.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.ClhVCxfg.mjs';
5
+ import { g as getCookie } from './shared/server.C1RJffw4.mjs';
6
+ import { P as Procedure, m as mergePrefix, a as mergeTags, e as enhanceRouter, C as Contract, p as parseEndpointDefinition, b as mergeRoute, c as prefixRoute, d as addMiddleware, l as lazyInternal, f as getLazyMeta, u as unlazy, i as isProcedure, h as isLazy, j as getRouter } from './shared/server.ChOv1yG3.mjs';
7
+ export { L as LAZY_SYMBOL, V as ValidationError, q as createAccessibleLazyRouter, w as endpointRegex, g as getDynamicParams, n as isStartWithMiddlewares, k as lazy, o as mergeMiddlewares, r as resolveContractProcedures, s as standardizeHTTPPath, t as traverseContractProcedures, v as unlazyRouter } from './shared/server.ChOv1yG3.mjs';
8
+ import { c as createProcedureClient } from './shared/server.Cza0RB3u.mjs';
9
+ export { m as mergeCurrentContext, a as middlewareOutputFn } from './shared/server.Cza0RB3u.mjs';
10
+ export { e as eventIterator, g as getEventIteratorSchemaDetails } from './shared/server.YUvuxHty.mjs';
8
11
  export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
12
+ import 'cookie';
13
+
14
+ function validateTokenPrefix(prefix, token) {
15
+ if (prefix && !token.startsWith(prefix)) {
16
+ throw new ORPCError("UNAUTHORIZED", { message: `Invalid auth token. It must start with "${prefix}"` });
17
+ }
18
+ }
19
+ function validateTokenAuth(config, token, options) {
20
+ const { tokenPrefix, validate } = config;
21
+ validateTokenPrefix(tokenPrefix, token);
22
+ return validate(token, options);
23
+ }
24
+ function runAuth(config, options) {
25
+ switch (config.type) {
26
+ case "header": {
27
+ const authHeader = options.request.headers.get(config.name);
28
+ return authHeader ? validateTokenAuth(config, authHeader, options) : void 0;
29
+ }
30
+ case "query": {
31
+ const { name, tokenPrefix, validate } = config;
32
+ const query = options.request.url.searchParams;
33
+ const token = query.get(name);
34
+ if (!token) return void 0;
35
+ validateTokenPrefix(tokenPrefix, token);
36
+ return validate(token, options);
37
+ }
38
+ case "cookie": {
39
+ const cookie = getCookie(options.request.headers, config.name);
40
+ return cookie ? validateTokenAuth(config, cookie, options) : void 0;
41
+ }
42
+ case "bearer": {
43
+ const authHeader = options.request.headers.get("Authorization");
44
+ if (!authHeader) return void 0;
45
+ const [authType, bearer] = splitFirst(authHeader, " ");
46
+ return authType === "Bearer" ? validateTokenAuth(config, bearer, options) : void 0;
47
+ }
48
+ case "basic": {
49
+ const authHeader = options.request.headers.get("Authorization");
50
+ if (!authHeader) return void 0;
51
+ const [authType, encoded] = splitFirst(authHeader, " ");
52
+ if (authType !== "Basic") return void 0;
53
+ const decoded = Buffer.from(encoded, "base64").toString("utf-8");
54
+ const [username, password] = splitFirst(decoded, ":");
55
+ validateTokenPrefix(config.tokenPrefix, password);
56
+ return config.validate(username, password, options);
57
+ }
58
+ case "none": {
59
+ return false;
60
+ }
61
+ default: {
62
+ assertNever(config);
63
+ }
64
+ }
65
+ }
66
+ function authDescription(config) {
67
+ const { type } = config;
68
+ 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);
69
+ }
70
+
71
+ function mergeMeta(meta1, meta2) {
72
+ return { ...meta1, ...meta2 };
73
+ }
9
74
 
10
75
  class DecoratedProcedure extends Procedure {
11
76
  /**
@@ -26,24 +91,19 @@ class DecoratedProcedure extends Procedure {
26
91
  }
27
92
  }
28
93
 
29
- class ProcedureBuilder extends ContractProcedure {
94
+ const initialSchemas = {
95
+ pathSchema: z.strictObject({}),
96
+ querySchema: z.strictObject({}),
97
+ bodySchema: z.strictObject({}),
98
+ outputSchema: z.unknown()
99
+ };
100
+
101
+ class ProcedureBuilder extends Contract {
30
102
  z;
31
103
  constructor(def) {
32
104
  super(def);
33
105
  this.z = new SchemaClass();
34
106
  }
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
107
  /**
48
108
  * Sets or updates the metadata for the contract.
49
109
  * The provided metadata is spared-merged with any existing metadata in the contract.
@@ -119,19 +179,40 @@ class ProcedureBuilder extends ContractProcedure {
119
179
  outputValidationIndex: this["~orpc"].middlewares.length
120
180
  });
121
181
  }
122
- /**
123
- * Uses a middleware to modify the context or improve the pipeline.
124
- *
125
- * @info Supports both normal middleware and inline middleware implementations.
126
- * @note The current context must be satisfy middleware dependent-context
127
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
128
- */
129
182
  use(middleware) {
130
183
  return new this.constructor({
131
184
  ...this["~orpc"],
132
185
  middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
133
186
  });
134
187
  }
188
+ // The default of false for ValidatedAuthContext is used when you pass in the type 'none'. We use false
189
+ // because we can't use null or undefined (see ValidatedAuthContext) but we still want it to be falsy.
190
+ useAuth(config) {
191
+ const middleware = baseApi.$context().middleware(async (options) => {
192
+ const { next, context } = options;
193
+ if (context.auth) return next();
194
+ const auth = await runAuth(config, options);
195
+ if (auth === void 0) {
196
+ const { authConfigs } = options.procedure["~orpc"];
197
+ if (context.auth !== false && config === authConfigs.at(-1)) {
198
+ let authDescriptions = authConfigs.map(authDescription).join(", ");
199
+ if (authConfigs.length > 1) {
200
+ authDescriptions = `one of: ${authDescriptions}`;
201
+ }
202
+ throw new ORPCError("UNAUTHORIZED", {
203
+ message: `Authentication required. You must provide ${authDescriptions}`
204
+ });
205
+ }
206
+ return next();
207
+ }
208
+ return next({ context: { auth } });
209
+ });
210
+ return new this.constructor({
211
+ ...this["~orpc"],
212
+ authConfigs: [...this["~orpc"].authConfigs, config],
213
+ middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
214
+ });
215
+ }
135
216
  useGating(gates, isGateEnabled) {
136
217
  return this.use(({ next, context }) => {
137
218
  return gatingContext.run(
@@ -146,6 +227,9 @@ class ProcedureBuilder extends ContractProcedure {
146
227
  * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
147
228
  */
148
229
  handler(handler) {
230
+ if (this["~orpc"].schemas.outputSchema === initialSchemas.outputSchema) {
231
+ throw new Error("You must call .output() before calling .handler()");
232
+ }
149
233
  return new DecoratedProcedure({
150
234
  ...this["~orpc"],
151
235
  handler
@@ -197,31 +281,6 @@ function decorateMiddleware(middleware) {
197
281
  );
198
282
  return mapped;
199
283
  };
200
- decorated.concat = (concatMiddleware, mapInput) => {
201
- const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
202
- const concatted = decorateMiddleware((options, input, output, ...rest) => {
203
- const merged = middleware(
204
- {
205
- ...options,
206
- next: (...[nextOptions1]) => mapped(
207
- {
208
- ...options,
209
- context: { ...options.context, ...nextOptions1?.context },
210
- next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
211
- },
212
- input,
213
- output,
214
- ...rest
215
- )
216
- },
217
- input,
218
- output,
219
- ...rest
220
- );
221
- return merged;
222
- });
223
- return concatted;
224
- };
225
284
  return decorated;
226
285
  }
227
286
 
@@ -243,99 +302,22 @@ class Builder extends BuilderWithMiddlewares {
243
302
  return decorateMiddleware(middleware);
244
303
  }
245
304
  }
246
- function createApiBuilder(opts = {}) {
247
- return new Builder({
248
- route: {},
249
- meta: opts.meta ?? {},
250
- errorMap: {},
251
- inputValidationIndex: 0,
252
- outputValidationIndex: 0,
253
- middlewares: [
254
- onError((error, _options) => {
255
- console.dir(error, { depth: null });
256
- })
257
- ],
258
- schemas: initialSchemas,
259
- // NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
260
- // the best solution). For now I've removed the interface to configure it externally.
261
- dedupeLeadingMiddlewares: true
262
- });
263
- }
264
- const os = createApiBuilder();
265
-
266
- function implementerInternal(contract, middlewares) {
267
- if (isContractProcedure(contract)) {
268
- const impl2 = new Builder({
269
- ...contract["~orpc"],
270
- middlewares,
271
- inputValidationIndex: middlewares.length,
272
- outputValidationIndex: middlewares.length,
273
- dedupeLeadingMiddlewares: true
274
- });
275
- return impl2;
276
- }
277
- const impl = new Proxy(contract, {
278
- get: (target, key) => {
279
- if (typeof key !== "string") {
280
- return Reflect.get(target, key);
281
- }
282
- let method;
283
- if (key === "middleware") {
284
- method = (mid) => decorateMiddleware(mid);
285
- } else if (key === "use") {
286
- method = (mid) => {
287
- return implementerInternal(contract, addMiddleware(middlewares, mid));
288
- };
289
- } else if (key === "router") {
290
- method = (router) => {
291
- const adapted = enhanceRouter(router, {
292
- middlewares,
293
- errorMap: {},
294
- prefix: void 0,
295
- tags: void 0,
296
- dedupeLeadingMiddlewares: true
297
- });
298
- return setHiddenRouterContract(adapted, contract);
299
- };
300
- }
301
- const next = getContractRouter(target, [key]);
302
- if (!next) {
303
- return method ?? next;
304
- }
305
- const nextImpl = implementerInternal(next, middlewares);
306
- if (method) {
307
- return new Proxy(method, {
308
- get(_, key2) {
309
- return Reflect.get(nextImpl, key2);
310
- }
311
- });
312
- }
313
- return nextImpl;
314
- }
315
- });
316
- return impl;
317
- }
318
- function implement(contract) {
319
- const implInternal = implementerInternal(contract, []);
320
- const impl = new Proxy(implInternal, {
321
- get: (target, key) => {
322
- let method;
323
- if (key === "$context") {
324
- method = () => impl;
325
- }
326
- const next = Reflect.get(target, key);
327
- if (!method || !next || typeof next !== "function" && typeof next !== "object") {
328
- return method || next;
329
- }
330
- return new Proxy(method, {
331
- get(_, key2) {
332
- return Reflect.get(next, key2);
333
- }
334
- });
335
- }
336
- });
337
- return impl;
338
- }
305
+ const baseApi = new Builder({
306
+ route: {},
307
+ meta: {},
308
+ inputValidationIndex: 0,
309
+ outputValidationIndex: 0,
310
+ middlewares: [
311
+ onError((error, _options) => {
312
+ console.dir(error, { depth: null });
313
+ })
314
+ ],
315
+ schemas: initialSchemas,
316
+ // NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
317
+ // the best solution). For now I've removed the interface to configure it externally.
318
+ dedupeLeadingMiddlewares: true,
319
+ authConfigs: []
320
+ });
339
321
 
340
322
  function createAssertedLazyProcedure(lazied) {
341
323
  const lazyProcedure = lazyInternal(async () => {
@@ -351,14 +333,6 @@ function createAssertedLazyProcedure(lazied) {
351
333
  }, getLazyMeta(lazied));
352
334
  return lazyProcedure;
353
335
  }
354
- function createContractedProcedure(procedure, contract) {
355
- return new Procedure({
356
- ...procedure["~orpc"],
357
- errorMap: contract["~orpc"].errorMap,
358
- route: contract["~orpc"].route,
359
- meta: contract["~orpc"].meta
360
- });
361
- }
362
336
  function call(procedure, input, ...rest) {
363
337
  const options = resolveMaybeOptionalOptions(rest);
364
338
  return createProcedureClient(procedure, options)(input, options);
@@ -389,4 +363,21 @@ function createRouterClient(router, ...rest) {
389
363
  return recursive;
390
364
  }
391
365
 
392
- 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 };
366
+ function isSchemaIssue(issue) {
367
+ if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
368
+ return false;
369
+ }
370
+ if (issue.path !== void 0) {
371
+ if (!Array.isArray(issue.path)) {
372
+ return false;
373
+ }
374
+ if (!issue.path.every(
375
+ (segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key)
376
+ )) {
377
+ return false;
378
+ }
379
+ }
380
+ return true;
381
+ }
382
+
383
+ export { Builder, BuilderWithMiddlewares, Contract, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, baseApi, call, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, initialSchemas, isLazy, isProcedure, isSchemaIssue, lazyInternal, mergeMeta, parseEndpointDefinition, unlazy };
@@ -1,11 +1,13 @@
1
- import { OpenAPI, AnyContractProcedure, AnySchema, AnyContractRouter } from '@temporary-name/contract';
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';
1
+ import { Contract } from '@temporary-name/server';
2
+ import { OpenAPI, Promisable, Value, HTTPPath, HTTPMethod } from '@temporary-name/shared';
3
+ export { OpenAPI } from '@temporary-name/shared';
4
+ import { ZodToJsonSchemaConverterOptions } from '@temporary-name/json-schema';
5
+ import { d as AnySchema, b as Contract$1, a9 as TraverseContractProcedureCallbackOptions, $ as ContractRouter, u as AnyRouter } from '../shared/server.DXPMDozZ.mjs';
5
6
  import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
6
7
  export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
8
+ import '@temporary-name/zod';
7
9
 
8
- type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
10
+ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
9
11
  /**
10
12
  * Customize The Operation Object by proxy an error map item or a middleware.
11
13
  *
@@ -13,7 +15,7 @@ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: Open
13
15
  */
14
16
  declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
15
17
  declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
16
- declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
18
+ declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: Contract): OpenAPI.OperationObject;
17
19
 
18
20
  /**
19
21
  * @internal
@@ -54,29 +56,18 @@ interface SchemaConvertOptions {
54
56
  */
55
57
  minStructureDepthForRef?: number;
56
58
  }
57
- interface SchemaConverter {
58
- convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
59
- }
60
- interface ConditionalSchemaConverter extends SchemaConverter {
61
- condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
62
- }
63
- declare class CompositeSchemaConverter implements SchemaConverter {
64
- private readonly converters;
65
- constructor(converters: readonly ConditionalSchemaConverter[]);
66
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
67
- }
59
+ type SchemaConverter = (schemas: AnySchema | undefined, options: SchemaConvertOptions) => Promisable<[required: boolean, jsonSchema: JSONSchema]>;
68
60
 
69
- interface OpenAPIGeneratorOptions {
70
- schemaConverters?: ConditionalSchemaConverter[];
71
- }
72
- interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
61
+ interface OpenAPIGeneratorGenerateOptions {
62
+ spec?: Partial<Omit<OpenAPI.Document, 'openapi'>>;
63
+ schemaConverter?: ZodToJsonSchemaConverterOptions | SchemaConverter;
73
64
  /**
74
65
  * Exclude procedures from the OpenAPI specification.
75
66
  *
76
67
  * @deprecated Use `filter` option instead.
77
68
  * @default () => false
78
69
  */
79
- exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
70
+ exclude?: (procedure: Contract$1, path: readonly string[]) => boolean;
80
71
  /**
81
72
  * Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
82
73
  *
@@ -116,21 +107,11 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
116
107
  }>;
117
108
  }
118
109
  /**
119
- * The generator that converts oRPC routers/contracts to OpenAPI specifications.
110
+ * Generates OpenAPI specifications from oRPC routers/contracts.
120
111
  *
121
112
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
122
113
  */
123
- declare class OpenAPIGenerator {
124
- #private;
125
- private readonly converter;
126
- constructor(options?: OpenAPIGeneratorOptions);
127
- /**
128
- * Generates OpenAPI specifications from oRPC routers/contracts.
129
- *
130
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
131
- */
132
- generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
133
- }
114
+ declare function generateOpenApiSpec(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
134
115
 
135
116
  /**
136
117
  * @internal
@@ -162,23 +143,6 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
162
143
  declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
163
144
  declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
164
145
 
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
146
  /**
183
147
  *@internal
184
148
  */
@@ -216,5 +180,5 @@ declare const oo: {
216
180
  spec: typeof customOpenAPIOperation;
217
181
  };
218
182
 
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 };
183
+ export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, generateOpenApiSpec, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
184
+ export type { FileSchema, ObjectSchema, OpenAPIGeneratorGenerateOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
@@ -1,11 +1,13 @@
1
- import { OpenAPI, AnyContractProcedure, AnySchema, AnyContractRouter } from '@temporary-name/contract';
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';
1
+ import { Contract } from '@temporary-name/server';
2
+ import { OpenAPI, Promisable, Value, HTTPPath, HTTPMethod } from '@temporary-name/shared';
3
+ export { OpenAPI } from '@temporary-name/shared';
4
+ import { ZodToJsonSchemaConverterOptions } from '@temporary-name/json-schema';
5
+ import { d as AnySchema, b as Contract$1, a9 as TraverseContractProcedureCallbackOptions, $ as ContractRouter, u as AnyRouter } from '../shared/server.DXPMDozZ.js';
5
6
  import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
6
7
  export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
8
+ import '@temporary-name/zod';
7
9
 
8
- type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
10
+ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
9
11
  /**
10
12
  * Customize The Operation Object by proxy an error map item or a middleware.
11
13
  *
@@ -13,7 +15,7 @@ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: Open
13
15
  */
14
16
  declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
15
17
  declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
16
- declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
18
+ declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: Contract): OpenAPI.OperationObject;
17
19
 
18
20
  /**
19
21
  * @internal
@@ -54,29 +56,18 @@ interface SchemaConvertOptions {
54
56
  */
55
57
  minStructureDepthForRef?: number;
56
58
  }
57
- interface SchemaConverter {
58
- convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
59
- }
60
- interface ConditionalSchemaConverter extends SchemaConverter {
61
- condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
62
- }
63
- declare class CompositeSchemaConverter implements SchemaConverter {
64
- private readonly converters;
65
- constructor(converters: readonly ConditionalSchemaConverter[]);
66
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
67
- }
59
+ type SchemaConverter = (schemas: AnySchema | undefined, options: SchemaConvertOptions) => Promisable<[required: boolean, jsonSchema: JSONSchema]>;
68
60
 
69
- interface OpenAPIGeneratorOptions {
70
- schemaConverters?: ConditionalSchemaConverter[];
71
- }
72
- interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
61
+ interface OpenAPIGeneratorGenerateOptions {
62
+ spec?: Partial<Omit<OpenAPI.Document, 'openapi'>>;
63
+ schemaConverter?: ZodToJsonSchemaConverterOptions | SchemaConverter;
73
64
  /**
74
65
  * Exclude procedures from the OpenAPI specification.
75
66
  *
76
67
  * @deprecated Use `filter` option instead.
77
68
  * @default () => false
78
69
  */
79
- exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
70
+ exclude?: (procedure: Contract$1, path: readonly string[]) => boolean;
80
71
  /**
81
72
  * Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
82
73
  *
@@ -116,21 +107,11 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
116
107
  }>;
117
108
  }
118
109
  /**
119
- * The generator that converts oRPC routers/contracts to OpenAPI specifications.
110
+ * Generates OpenAPI specifications from oRPC routers/contracts.
120
111
  *
121
112
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
122
113
  */
123
- declare class OpenAPIGenerator {
124
- #private;
125
- private readonly converter;
126
- constructor(options?: OpenAPIGeneratorOptions);
127
- /**
128
- * Generates OpenAPI specifications from oRPC routers/contracts.
129
- *
130
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
131
- */
132
- generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
133
- }
114
+ declare function generateOpenApiSpec(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
134
115
 
135
116
  /**
136
117
  * @internal
@@ -162,23 +143,6 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
162
143
  declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
163
144
  declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
164
145
 
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
146
  /**
183
147
  *@internal
184
148
  */
@@ -216,5 +180,5 @@ declare const oo: {
216
180
  spec: typeof customOpenAPIOperation;
217
181
  };
218
182
 
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 };
183
+ export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, generateOpenApiSpec, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
184
+ export type { FileSchema, ObjectSchema, OpenAPIGeneratorGenerateOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };