@temporary-name/server 1.9.3-alpha.a252b3ff8cb6bf7deaa6d41dc9ac8a8d50edd80e → 1.9.3-alpha.a253b67a3639148c12f13a47295e1922182adecd
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 +4 -5
- package/dist/adapters/aws-lambda/index.d.ts +4 -5
- package/dist/adapters/aws-lambda/index.mjs +4 -3
- package/dist/adapters/fetch/index.d.mts +4 -5
- package/dist/adapters/fetch/index.d.ts +4 -5
- package/dist/adapters/fetch/index.mjs +4 -3
- package/dist/adapters/node/index.d.mts +4 -5
- package/dist/adapters/node/index.d.ts +4 -5
- package/dist/adapters/node/index.mjs +4 -3
- package/dist/adapters/standard/index.d.mts +20 -32
- package/dist/adapters/standard/index.d.ts +20 -32
- package/dist/adapters/standard/index.mjs +5 -4
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +54 -1194
- package/dist/index.d.ts +54 -1194
- package/dist/index.mjs +168 -1983
- package/dist/openapi/index.d.mts +9 -9
- package/dist/openapi/index.d.ts +9 -9
- package/dist/openapi/index.mjs +64 -133
- 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.SLLuK6_v.d.ts → server.BR0GBxlv.d.ts} +2 -2
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/{server.BeuTpcmO.d.mts → server.C7HccVwN.d.mts} +2 -2
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.CPThlZ_E.d.ts} +6 -8
- package/dist/shared/server.D-DR5Z00.mjs +362 -0
- package/dist/shared/{server.BEHw7Eyx.mjs → server.JtIZ8YG7.mjs} +1 -11
- package/dist/shared/server.oy0285uM.d.mts +252 -0
- package/dist/shared/server.oy0285uM.d.ts +252 -0
- package/dist/shared/{server.CMTfy2UB.mjs → server.rZDPWnA8.mjs} +65 -124
- package/dist/shared/{server.C1fnTLq0.d.mts → server.y97Td78c.d.mts} +6 -8
- package/package.json +10 -21
- package/dist/shared/server.BKSOrA6h.d.mts +0 -192
- package/dist/shared/server.BKSOrA6h.d.ts +0 -192
- package/dist/shared/server.BZtKt8i8.mjs +0 -201
package/dist/openapi/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { OpenAPI,
|
|
1
|
+
import { OpenAPI, AnySchema } from '@temporary-name/contract';
|
|
2
2
|
export { OpenAPI } from '@temporary-name/contract';
|
|
3
|
-
import {
|
|
3
|
+
import { Contract, TraverseContractProcedureCallbackOptions, ContractRouter, 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';
|
|
7
7
|
|
|
8
|
-
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure:
|
|
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:
|
|
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(
|
|
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:
|
|
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:
|
|
132
|
+
generate(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/**
|
|
@@ -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,11 +1,11 @@
|
|
|
1
|
-
import { OpenAPI,
|
|
1
|
+
import { OpenAPI, AnySchema } from '@temporary-name/contract';
|
|
2
2
|
export { OpenAPI } from '@temporary-name/contract';
|
|
3
|
-
import {
|
|
3
|
+
import { Contract, TraverseContractProcedureCallbackOptions, ContractRouter, 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';
|
|
7
7
|
|
|
8
|
-
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure:
|
|
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:
|
|
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(
|
|
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:
|
|
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:
|
|
132
|
+
generate(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/**
|
|
@@ -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.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus,
|
|
4
|
-
import {
|
|
1
|
+
import { standardizeHTTPPath, fallbackContractConfig, getDynamicParams, getEventIteratorSchemaDetails } from '@temporary-name/contract';
|
|
2
|
+
import { resolveContractProcedures, ORPCError, createRouterClient } from '@temporary-name/server';
|
|
3
|
+
import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus, resolveMaybeOptionalOptions, createORPCErrorFromJson } from '@temporary-name/shared';
|
|
4
|
+
import { j as jsonSerialize, d as deserialize, s as serialize } from '../shared/server.JtIZ8YG7.mjs';
|
|
5
5
|
import '@temporary-name/standard-server';
|
|
6
6
|
import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
7
|
export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
@@ -22,20 +22,12 @@ function getCustomOpenAPIOperation(o) {
|
|
|
22
22
|
}
|
|
23
23
|
function applyCustomOpenAPIOperation(operation, contract) {
|
|
24
24
|
const operationCustoms = [];
|
|
25
|
-
for (const
|
|
26
|
-
const maybeExtender =
|
|
25
|
+
for (const middleware of contract["~orpc"].middlewares) {
|
|
26
|
+
const maybeExtender = getCustomOpenAPIOperation(middleware);
|
|
27
27
|
if (maybeExtender) {
|
|
28
28
|
operationCustoms.push(maybeExtender);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
if (isProcedure(contract)) {
|
|
32
|
-
for (const middleware of contract["~orpc"].middlewares) {
|
|
33
|
-
const maybeExtender = getCustomOpenAPIOperation(middleware);
|
|
34
|
-
if (maybeExtender) {
|
|
35
|
-
operationCustoms.push(maybeExtender);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
31
|
let currentOperation = operation;
|
|
40
32
|
for (const custom of operationCustoms) {
|
|
41
33
|
if (typeof custom === "function") {
|
|
@@ -432,12 +424,6 @@ class OpenAPIGenerator {
|
|
|
432
424
|
};
|
|
433
425
|
await this.#request(doc, operationObjectRef, def, baseSchemaConvertOptions);
|
|
434
426
|
await this.#successResponse(doc, operationObjectRef, def, baseSchemaConvertOptions);
|
|
435
|
-
await this.#errorResponse(
|
|
436
|
-
operationObjectRef,
|
|
437
|
-
def,
|
|
438
|
-
baseSchemaConvertOptions,
|
|
439
|
-
undefinedErrorJsonSchema
|
|
440
|
-
);
|
|
441
427
|
}
|
|
442
428
|
if (typeof def.route.spec === "function") {
|
|
443
429
|
operationObjectRef = def.route.spec(operationObjectRef);
|
|
@@ -530,94 +516,77 @@ ${errors.join("\n\n")}`
|
|
|
530
516
|
}
|
|
531
517
|
async #request(doc, ref, def, baseSchemaConvertOptions) {
|
|
532
518
|
const method = fallbackContractConfig("defaultMethod", def.route.method);
|
|
533
|
-
const details = getEventIteratorSchemaDetails(def.inputSchema);
|
|
534
|
-
if (details) {
|
|
535
|
-
ref.requestBody = {
|
|
536
|
-
required: true,
|
|
537
|
-
content: toOpenAPIEventIteratorContent(
|
|
538
|
-
await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
|
|
539
|
-
await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
|
|
540
|
-
)
|
|
541
|
-
};
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
519
|
const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
|
|
545
|
-
const
|
|
546
|
-
let [required, schema] = await this.converter.convert(def.inputSchema, {
|
|
520
|
+
const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
|
|
547
521
|
...baseSchemaConvertOptions,
|
|
548
522
|
strategy: "input",
|
|
549
|
-
minStructureDepthForRef:
|
|
523
|
+
minStructureDepthForRef: 1
|
|
550
524
|
});
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
);
|
|
559
|
-
if (!isObjectSchema(schema)) {
|
|
560
|
-
throw error2;
|
|
561
|
-
}
|
|
562
|
-
const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
|
|
563
|
-
schema = rest;
|
|
564
|
-
required = rest.required ? rest.required.length !== 0 : false;
|
|
565
|
-
if (!checkParamsSchema(paramsSchema, dynamicParams)) {
|
|
566
|
-
throw error2;
|
|
567
|
-
}
|
|
568
|
-
ref.parameters ??= [];
|
|
569
|
-
ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
|
|
525
|
+
if (dynamicParams?.length) {
|
|
526
|
+
const error = new OpenAPIGeneratorError(
|
|
527
|
+
// TODO: fix this error
|
|
528
|
+
'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
|
|
529
|
+
);
|
|
530
|
+
if (!isObjectSchema(pathSchema)) {
|
|
531
|
+
throw error;
|
|
570
532
|
}
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
533
|
+
if (!checkParamsSchema(pathSchema, dynamicParams)) {
|
|
534
|
+
throw error;
|
|
535
|
+
}
|
|
536
|
+
ref.parameters ??= [];
|
|
537
|
+
ref.parameters.push(...toOpenAPIParameters(pathSchema, "path"));
|
|
538
|
+
} else {
|
|
539
|
+
const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
|
|
540
|
+
if (!isObjectSchema(pathSchema)) {
|
|
541
|
+
console.log("FOO", pathSchema);
|
|
542
|
+
throw error;
|
|
543
|
+
}
|
|
544
|
+
if (!checkParamsSchema(pathSchema, [])) {
|
|
545
|
+
console.log("BAR", pathSchema);
|
|
546
|
+
throw error;
|
|
585
547
|
}
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
const error = new OpenAPIGeneratorError(
|
|
589
|
-
'When input structure is "detailed", input schema must satisfy: { params?: Record<string, unknown>, query?: Record<string, unknown>, headers?: Record<string, unknown>, body?: unknown }'
|
|
590
|
-
);
|
|
591
|
-
if (!isObjectSchema(schema)) {
|
|
592
|
-
throw error;
|
|
593
548
|
}
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
549
|
+
const [_queryRequired, querySchema] = await this.converter.convert(def.schemas.querySchema, {
|
|
550
|
+
...baseSchemaConvertOptions,
|
|
551
|
+
strategy: "input",
|
|
552
|
+
minStructureDepthForRef: 0
|
|
553
|
+
});
|
|
554
|
+
if (!isAnySchema(querySchema)) {
|
|
555
|
+
const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, querySchema);
|
|
556
|
+
if (!isObjectSchema(resolvedSchema)) {
|
|
557
|
+
throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
|
|
558
|
+
}
|
|
559
|
+
ref.parameters ??= [];
|
|
560
|
+
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
|
|
599
561
|
}
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
if (
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
562
|
+
if (method !== "GET") {
|
|
563
|
+
const details = getEventIteratorSchemaDetails(def.schemas.bodySchema);
|
|
564
|
+
if (details) {
|
|
565
|
+
ref.requestBody = {
|
|
566
|
+
required: true,
|
|
567
|
+
content: toOpenAPIEventIteratorContent(
|
|
568
|
+
await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
|
|
569
|
+
await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
|
|
570
|
+
)
|
|
571
|
+
};
|
|
572
|
+
} else {
|
|
573
|
+
const [bodyRequired, bodySchema] = await this.converter.convert(def.schemas.bodySchema, {
|
|
574
|
+
...baseSchemaConvertOptions,
|
|
575
|
+
strategy: "input",
|
|
576
|
+
minStructureDepthForRef: 0
|
|
577
|
+
});
|
|
578
|
+
if (isAnySchema(bodySchema)) {
|
|
579
|
+
return;
|
|
606
580
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
581
|
+
ref.requestBody = {
|
|
582
|
+
required: bodyRequired,
|
|
583
|
+
content: toOpenAPIContent(bodySchema)
|
|
584
|
+
};
|
|
610
585
|
}
|
|
611
586
|
}
|
|
612
|
-
if (schema.properties?.body !== void 0) {
|
|
613
|
-
ref.requestBody = {
|
|
614
|
-
required: schema.required?.includes("body"),
|
|
615
|
-
content: toOpenAPIContent(schema.properties.body)
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
587
|
}
|
|
619
588
|
async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
|
|
620
|
-
const outputSchema = def.outputSchema;
|
|
589
|
+
const outputSchema = def.schemas.outputSchema;
|
|
621
590
|
const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
|
|
622
591
|
const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
|
|
623
592
|
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
|
|
@@ -713,44 +682,6 @@ ${errors.join("\n\n")}`
|
|
|
713
682
|
}
|
|
714
683
|
}
|
|
715
684
|
}
|
|
716
|
-
async #errorResponse(ref, def, baseSchemaConvertOptions, undefinedErrorSchema) {
|
|
717
|
-
const errorMap = def.errorMap;
|
|
718
|
-
const errors = {};
|
|
719
|
-
for (const code in errorMap) {
|
|
720
|
-
const config = errorMap[code];
|
|
721
|
-
if (!config) {
|
|
722
|
-
continue;
|
|
723
|
-
}
|
|
724
|
-
const status = fallbackORPCErrorStatus(code, config.status);
|
|
725
|
-
const message = fallbackORPCErrorMessage(code, config.message);
|
|
726
|
-
const [dataRequired, dataSchema] = await this.converter.convert(config.data, {
|
|
727
|
-
...baseSchemaConvertOptions,
|
|
728
|
-
strategy: "output"
|
|
729
|
-
});
|
|
730
|
-
errors[status] ??= [];
|
|
731
|
-
errors[status].push({
|
|
732
|
-
type: "object",
|
|
733
|
-
properties: {
|
|
734
|
-
defined: { const: true },
|
|
735
|
-
code: { const: code },
|
|
736
|
-
status: { const: status },
|
|
737
|
-
message: { type: "string", default: message },
|
|
738
|
-
data: dataSchema
|
|
739
|
-
},
|
|
740
|
-
required: dataRequired ? ["defined", "code", "status", "message", "data"] : ["defined", "code", "status", "message"]
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
ref.responses ??= {};
|
|
744
|
-
for (const status in errors) {
|
|
745
|
-
const schemas = errors[status];
|
|
746
|
-
ref.responses[status] = {
|
|
747
|
-
description: status,
|
|
748
|
-
content: toOpenAPIContent({
|
|
749
|
-
oneOf: [...schemas, undefinedErrorSchema]
|
|
750
|
-
})
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
685
|
}
|
|
755
686
|
|
|
756
687
|
function createJsonifiedRouterClient(router, ...rest) {
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.C1fnTLq0.mjs';
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.BKSOrA6h.mjs';
|
|
2
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.y97Td78c.mjs';
|
|
3
|
+
import { C as Context, N as ProcedureClientInterceptorOptions } from '../shared/server.oy0285uM.mjs';
|
|
6
4
|
import { Meta } from '@temporary-name/contract';
|
|
7
5
|
|
|
8
|
-
interface BatchHandlerOptions<T extends Context> {
|
|
9
|
-
/**
|
|
10
|
-
* The max size of the batch allowed.
|
|
11
|
-
*
|
|
12
|
-
* @default 10
|
|
13
|
-
*/
|
|
14
|
-
maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
|
|
15
|
-
/**
|
|
16
|
-
* Map the request before processing it.
|
|
17
|
-
*
|
|
18
|
-
* @default merged back batch request headers into the request
|
|
19
|
-
*/
|
|
20
|
-
mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
|
|
21
|
-
/**
|
|
22
|
-
* Success batch response status code.
|
|
23
|
-
*
|
|
24
|
-
* @default 207
|
|
25
|
-
*/
|
|
26
|
-
successStatus?: Value<Promisable<number>, [
|
|
27
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
28
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
29
|
-
]>;
|
|
30
|
-
/**
|
|
31
|
-
* success batch response headers.
|
|
32
|
-
*
|
|
33
|
-
* @default {}
|
|
34
|
-
*/
|
|
35
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
36
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
37
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
38
|
-
]>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
42
|
-
* reducing the overhead of sending each one separately.
|
|
43
|
-
*
|
|
44
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
45
|
-
*/
|
|
46
|
-
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
47
|
-
private readonly maxSize;
|
|
48
|
-
private readonly mapRequestItem;
|
|
49
|
-
private readonly successStatus;
|
|
50
|
-
private readonly headers;
|
|
51
|
-
order: number;
|
|
52
|
-
constructor(options?: BatchHandlerOptions<T>);
|
|
53
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
6
|
interface CORSOptions<T extends Context> {
|
|
57
7
|
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [
|
|
58
8
|
origin: string,
|
|
@@ -80,32 +30,6 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
|
|
|
80
30
|
init(options: StandardHandlerOptions<T>): void;
|
|
81
31
|
}
|
|
82
32
|
|
|
83
|
-
interface RequestHeadersPluginContext {
|
|
84
|
-
reqHeaders?: Headers;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
88
|
-
* allowing access to request headers in oRPC.
|
|
89
|
-
*
|
|
90
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
91
|
-
*/
|
|
92
|
-
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
93
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
interface ResponseHeadersPluginContext {
|
|
97
|
-
resHeaders?: Headers;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
101
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
104
|
-
*/
|
|
105
|
-
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
106
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
33
|
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
110
34
|
/**
|
|
111
35
|
* The name of the header to check.
|
|
@@ -126,9 +50,7 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
|
126
50
|
* @default false
|
|
127
51
|
*
|
|
128
52
|
*/
|
|
129
|
-
exclude?: Value<Promisable<boolean>, [
|
|
130
|
-
options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>
|
|
131
|
-
]>;
|
|
53
|
+
exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Meta>]>;
|
|
132
54
|
/**
|
|
133
55
|
* The error thrown when the CSRF token is invalid.
|
|
134
56
|
*
|
|
@@ -156,5 +78,5 @@ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements St
|
|
|
156
78
|
init(options: StandardHandlerOptions<T>): void;
|
|
157
79
|
}
|
|
158
80
|
|
|
159
|
-
export {
|
|
160
|
-
export type {
|
|
81
|
+
export { CORSPlugin, SimpleCsrfProtectionHandlerPlugin };
|
|
82
|
+
export type { CORSOptions, SimpleCsrfProtectionHandlerPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CQyYNJ1H.js';
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.BKSOrA6h.js';
|
|
2
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CPThlZ_E.js';
|
|
3
|
+
import { C as Context, N as ProcedureClientInterceptorOptions } from '../shared/server.oy0285uM.js';
|
|
6
4
|
import { Meta } from '@temporary-name/contract';
|
|
7
5
|
|
|
8
|
-
interface BatchHandlerOptions<T extends Context> {
|
|
9
|
-
/**
|
|
10
|
-
* The max size of the batch allowed.
|
|
11
|
-
*
|
|
12
|
-
* @default 10
|
|
13
|
-
*/
|
|
14
|
-
maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
|
|
15
|
-
/**
|
|
16
|
-
* Map the request before processing it.
|
|
17
|
-
*
|
|
18
|
-
* @default merged back batch request headers into the request
|
|
19
|
-
*/
|
|
20
|
-
mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
|
|
21
|
-
/**
|
|
22
|
-
* Success batch response status code.
|
|
23
|
-
*
|
|
24
|
-
* @default 207
|
|
25
|
-
*/
|
|
26
|
-
successStatus?: Value<Promisable<number>, [
|
|
27
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
28
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
29
|
-
]>;
|
|
30
|
-
/**
|
|
31
|
-
* success batch response headers.
|
|
32
|
-
*
|
|
33
|
-
* @default {}
|
|
34
|
-
*/
|
|
35
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
36
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
37
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
38
|
-
]>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
42
|
-
* reducing the overhead of sending each one separately.
|
|
43
|
-
*
|
|
44
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
45
|
-
*/
|
|
46
|
-
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
47
|
-
private readonly maxSize;
|
|
48
|
-
private readonly mapRequestItem;
|
|
49
|
-
private readonly successStatus;
|
|
50
|
-
private readonly headers;
|
|
51
|
-
order: number;
|
|
52
|
-
constructor(options?: BatchHandlerOptions<T>);
|
|
53
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
6
|
interface CORSOptions<T extends Context> {
|
|
57
7
|
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [
|
|
58
8
|
origin: string,
|
|
@@ -80,32 +30,6 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
|
|
|
80
30
|
init(options: StandardHandlerOptions<T>): void;
|
|
81
31
|
}
|
|
82
32
|
|
|
83
|
-
interface RequestHeadersPluginContext {
|
|
84
|
-
reqHeaders?: Headers;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
88
|
-
* allowing access to request headers in oRPC.
|
|
89
|
-
*
|
|
90
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
91
|
-
*/
|
|
92
|
-
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
93
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
interface ResponseHeadersPluginContext {
|
|
97
|
-
resHeaders?: Headers;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
101
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
104
|
-
*/
|
|
105
|
-
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
106
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
33
|
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
110
34
|
/**
|
|
111
35
|
* The name of the header to check.
|
|
@@ -126,9 +50,7 @@ interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
|
126
50
|
* @default false
|
|
127
51
|
*
|
|
128
52
|
*/
|
|
129
|
-
exclude?: Value<Promisable<boolean>, [
|
|
130
|
-
options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>
|
|
131
|
-
]>;
|
|
53
|
+
exclude?: Value<Promisable<boolean>, [options: ProcedureClientInterceptorOptions<T, Meta>]>;
|
|
132
54
|
/**
|
|
133
55
|
* The error thrown when the CSRF token is invalid.
|
|
134
56
|
*
|
|
@@ -156,5 +78,5 @@ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements St
|
|
|
156
78
|
init(options: StandardHandlerOptions<T>): void;
|
|
157
79
|
}
|
|
158
80
|
|
|
159
|
-
export {
|
|
160
|
-
export type {
|
|
81
|
+
export { CORSPlugin, SimpleCsrfProtectionHandlerPlugin };
|
|
82
|
+
export type { CORSOptions, SimpleCsrfProtectionHandlerPluginOptions };
|