@orpc/contract 2.0.0-beta.49 → 2.0.0-beta.50
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/builder-variants.d.ts +79 -79
- package/dist/builder.d.ts +52 -52
- package/dist/builder.js +106 -110
- package/dist/client-factory.d.ts +12 -12
- package/dist/client-factory.js +36 -36
- package/dist/error-factory.d.ts +20 -23
- package/dist/error-factory.js +105 -117
- package/dist/error-utils.d.ts +3 -3
- package/dist/error-utils.js +35 -38
- package/dist/error.d.ts +23 -27
- package/dist/error.js +21 -19
- package/dist/index.d.ts +20 -62
- package/dist/index.js +12 -31
- package/dist/meta-built-in.d.ts +10 -10
- package/dist/meta-built-in.js +41 -50
- package/dist/meta-utils.d.ts +10 -13
- package/dist/meta-utils.js +67 -73
- package/dist/meta.d.ts +27 -27
- package/dist/meta.js +9 -11
- package/dist/plugins/index.d.ts +3 -12
- package/dist/plugins/index.js +2 -12
- package/dist/plugins/request-validation.d.ts +19 -19
- package/dist/plugins/request-validation.js +49 -54
- package/dist/plugins/response-validation.d.ts +8 -8
- package/dist/plugins/response-validation.js +66 -71
- package/dist/procedure-client.d.ts +5 -5
- package/dist/procedure.d.ts +24 -24
- package/dist/procedure.js +17 -28
- package/dist/router-client.d.ts +5 -7
- package/dist/router-utils.d.ts +10 -17
- package/dist/router-utils.js +53 -73
- package/dist/router.d.ts +10 -20
- package/dist/schema-built-in.d.ts +5 -10
- package/dist/schema-built-in.js +64 -71
- package/dist/schema-utils.d.ts +3 -3
- package/dist/schema-utils.js +32 -40
- package/dist/schema.d.ts +2 -2
- package/package.json +3 -3
- package/dist/builder-variants.js +0 -1
- package/dist/procedure-client.js +0 -1
- package/dist/router-client.js +0 -1
- package/dist/router.js +0 -1
- package/dist/schema.js +0 -1
package/dist/router.d.ts
CHANGED
|
@@ -1,52 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { ORPCErrorFromErrorMap } from "./error.js";
|
|
2
|
+
import { AnyProcedureContract, ProcedureContract } from "./procedure.js";
|
|
3
|
+
import { InferSchemaInput, InferSchemaOutput } from "./schema.js";
|
|
4
|
+
import { ThrowableError } from "@orpc/shared";
|
|
5
5
|
/**
|
|
6
6
|
* A router contract: a single procedure contract or a nested record of them.
|
|
7
7
|
*
|
|
8
8
|
* @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
|
|
9
9
|
*/
|
|
10
10
|
export type RouterContract = AnyProcedureContract | {
|
|
11
|
-
|
|
11
|
+
[k: string]: RouterContract;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* Infer the input types for each procedure-contract, preserving the router-contract shape.
|
|
15
15
|
*
|
|
16
16
|
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-inputs | Router Contract - Infer Router Contract Inputs}
|
|
17
17
|
*/
|
|
18
|
-
export type InferRouterContractInputs<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
19
|
-
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractInputs<T[K]> : never;
|
|
20
|
-
};
|
|
18
|
+
export type InferRouterContractInputs<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : { [K in keyof T]: T[K] extends RouterContract ? InferRouterContractInputs<T[K]> : never; };
|
|
21
19
|
/**
|
|
22
20
|
* Infer the output types for each procedure-contract, preserving the router-contract shape.
|
|
23
21
|
*
|
|
24
22
|
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-outputs | Router Contract - Infer Router Contract Outputs}
|
|
25
23
|
*/
|
|
26
|
-
export type InferRouterContractOutputs<T extends RouterContract> = T extends ProcedureContract<any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
27
|
-
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractOutputs<T[K]> : never;
|
|
28
|
-
};
|
|
24
|
+
export type InferRouterContractOutputs<T extends RouterContract> = T extends ProcedureContract<any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : { [K in keyof T]: T[K] extends RouterContract ? InferRouterContractOutputs<T[K]> : never; };
|
|
29
25
|
/**
|
|
30
26
|
* Infer the union of error maps defined across the entire router-contract.
|
|
31
27
|
*
|
|
32
28
|
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-error-map | Router Contract - Infer Router Contract Error Map}
|
|
33
29
|
*/
|
|
34
|
-
export type InferRouterContractErrorMap<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? UErrorMap : {
|
|
35
|
-
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrorMap<T[K]> : never;
|
|
36
|
-
}[keyof T];
|
|
30
|
+
export type InferRouterContractErrorMap<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? UErrorMap : { [K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrorMap<T[K]> : never; }[keyof T];
|
|
37
31
|
/**
|
|
38
32
|
* Infer the union of throwable errors for entire router-contract.
|
|
39
33
|
*
|
|
40
34
|
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-error | Router Contract - Infer Router Contract Error}
|
|
41
35
|
*/
|
|
42
|
-
export type InferRouterContractError<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
43
|
-
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractError<T[K]> : never;
|
|
44
|
-
}[keyof T];
|
|
36
|
+
export type InferRouterContractError<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : { [K in keyof T]: T[K] extends RouterContract ? InferRouterContractError<T[K]> : never; }[keyof T];
|
|
45
37
|
/**
|
|
46
38
|
* Infer throwable errors for each procedure-contract, preserving the router-contract shape.
|
|
47
39
|
*
|
|
48
40
|
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-errors | Router Contract - Infer Router Contract Errors}
|
|
49
41
|
*/
|
|
50
|
-
export type InferRouterContractErrors<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
51
|
-
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrors<T[K]> : never;
|
|
52
|
-
};
|
|
42
|
+
export type InferRouterContractErrors<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : { [K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrors<T[K]> : never; };
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
export interface AsyncIteratorObjectSchemaDetails {
|
|
4
|
-
yieldSchema: AnySchema;
|
|
5
|
-
returnSchema?: AnySchema | undefined;
|
|
6
|
-
}
|
|
1
|
+
import { AnySchema, Schema } from "./schema.js";
|
|
2
|
+
import { AsyncIteratorClass } from "@orpc/shared";
|
|
7
3
|
/**
|
|
8
4
|
* Defines a schema for an AsyncIteratorObject, validating each yielded value
|
|
9
5
|
* (and optionally the return value) with the given schemas.
|
|
@@ -11,13 +7,12 @@ export interface AsyncIteratorObjectSchemaDetails {
|
|
|
11
7
|
* @see {@link https://orpc.dev/docs/async-iterator-object | AsyncIteratorObject (SSE)}
|
|
12
8
|
*/
|
|
13
9
|
export declare function asyncIteratorObject<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yieldSchema: Schema<TYieldIn, TYieldOut>, returnSchema?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorClass<TYieldOut, TReturnOut, void>>;
|
|
14
|
-
export declare function getAsyncIteratorObjectSchemaDetails(schema: AnySchema | undefined): undefined | AsyncIteratorObjectSchemaDetails;
|
|
15
10
|
export interface AsyncIteratorObjectSchemasDetails {
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
yieldSchemas: AnySchema[];
|
|
12
|
+
returnSchemas: AnySchema[];
|
|
18
13
|
}
|
|
19
14
|
/**
|
|
20
15
|
* Collects the yield and return schemas of multiple schemas, such as the `.output` schemas of a procedure,
|
|
21
16
|
* or returns `undefined` when there are none or any of them does not describe an AsyncIteratorObject.
|
|
22
17
|
*/
|
|
23
|
-
export declare function getAsyncIteratorObjectSchemasDetails(schemas: readonly AnySchema[] | undefined): undefined | AsyncIteratorObjectSchemasDetails;
|
|
18
|
+
export declare function getAsyncIteratorObjectSchemasDetails(schemas: readonly AnySchema[] | undefined): undefined | AsyncIteratorObjectSchemasDetails;
|
package/dist/schema-built-in.js
CHANGED
|
@@ -1,76 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { ValidationError } from "./error.js";
|
|
2
|
+
import { ORPC_NAME, isAsyncIteratorObject, override } from "@orpc/shared";
|
|
3
|
+
import { ORPCError, wrapAsyncIteratorPreservingEventMeta } from "@orpc/client";
|
|
4
|
+
// src/schema-built-in.ts
|
|
5
|
+
const ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS");
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return { value: override(iterator, mapped) };
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
};
|
|
7
|
+
* Defines a schema for an AsyncIteratorObject, validating each yielded value
|
|
8
|
+
* (and optionally the return value) with the given schemas.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://orpc.dev/docs/async-iterator-object | AsyncIteratorObject (SSE)}
|
|
11
|
+
*/
|
|
12
|
+
function asyncIteratorObject(yieldSchema, returnSchema) {
|
|
13
|
+
return { "~standard": {
|
|
14
|
+
[ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS_SYMBOL]: {
|
|
15
|
+
yieldSchema,
|
|
16
|
+
returnSchema
|
|
17
|
+
},
|
|
18
|
+
vendor: ORPC_NAME,
|
|
19
|
+
version: 1,
|
|
20
|
+
validate(iterator) {
|
|
21
|
+
if (!isAsyncIteratorObject(iterator)) return { issues: [{
|
|
22
|
+
message: "Expect AsyncIteratorObject",
|
|
23
|
+
path: []
|
|
24
|
+
}] };
|
|
25
|
+
const mapped = wrapAsyncIteratorPreservingEventMeta(iterator, { async mapResult(result) {
|
|
26
|
+
const schema = result.done ? returnSchema : yieldSchema;
|
|
27
|
+
if (!schema) return result;
|
|
28
|
+
const validated = await schema["~standard"].validate(result.value);
|
|
29
|
+
if (validated.issues) throw new ORPCError("ASYNC_ITERATOR_OBJECT_VALIDATION_FAILED", {
|
|
30
|
+
message: "AsyncIteratorObject validation failed",
|
|
31
|
+
cause: new ValidationError({
|
|
32
|
+
issues: validated.issues,
|
|
33
|
+
message: "AsyncIteratorObject validation failed",
|
|
34
|
+
invalidData: result.value
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
done: result.done,
|
|
39
|
+
value: validated.value
|
|
40
|
+
};
|
|
41
|
+
} });
|
|
42
|
+
return { value: override(iterator, mapped) };
|
|
43
|
+
}
|
|
44
|
+
} };
|
|
48
45
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
return schema['~standard'][ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS_SYMBOL];
|
|
46
|
+
function getAsyncIteratorObjectSchemaDetails(schema) {
|
|
47
|
+
if (schema === void 0) return;
|
|
48
|
+
return schema["~standard"][ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS_SYMBOL];
|
|
54
49
|
}
|
|
55
50
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return { yieldSchemas, returnSchemas };
|
|
51
|
+
* Collects the yield and return schemas of multiple schemas, such as the `.output` schemas of a procedure,
|
|
52
|
+
* or returns `undefined` when there are none or any of them does not describe an AsyncIteratorObject.
|
|
53
|
+
*/
|
|
54
|
+
function getAsyncIteratorObjectSchemasDetails(schemas) {
|
|
55
|
+
if (!schemas || schemas.length === 0) return;
|
|
56
|
+
const yieldSchemas = [];
|
|
57
|
+
const returnSchemas = [];
|
|
58
|
+
for (const schema of schemas) {
|
|
59
|
+
const details = getAsyncIteratorObjectSchemaDetails(schema);
|
|
60
|
+
if (!details) return;
|
|
61
|
+
yieldSchemas.push(details.yieldSchema);
|
|
62
|
+
if (details.returnSchema) returnSchemas.push(details.returnSchema);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
yieldSchemas,
|
|
66
|
+
returnSchemas
|
|
67
|
+
};
|
|
76
68
|
}
|
|
69
|
+
export { asyncIteratorObject, getAsyncIteratorObjectSchemaDetails, getAsyncIteratorObjectSchemasDetails };
|
package/dist/schema-utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Schema, SchemaIssue } from "./schema.js";
|
|
2
|
+
import { IsEqual, Promisable } from "@orpc/shared";
|
|
3
3
|
export type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
4
4
|
/**
|
|
5
5
|
* Create a schema for things can be trust without validation.
|
|
@@ -17,4 +17,4 @@ export declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput
|
|
|
17
17
|
/**
|
|
18
18
|
* Check if the given issue is following the standard-schema issue format.
|
|
19
19
|
*/
|
|
20
|
-
export declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
20
|
+
export declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
package/dist/schema-utils.js
CHANGED
|
@@ -1,44 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ORPC_NAME, isNonPrimitive, isPropertyKey } from "@orpc/shared";
|
|
2
|
+
// src/schema-utils.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return { value: value };
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
4
|
+
* Create a schema for things can be trust without validation.
|
|
5
|
+
* You can optionally pass a map function for mapping
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const normal = type<number>()
|
|
10
|
+
* const withMap = type<number, string>(input => input.toString())
|
|
11
|
+
*```
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://orpc.dev/docs/procedure#type-utility | Procedure - type Utility}
|
|
14
|
+
*/
|
|
15
|
+
function type(...[map]) {
|
|
16
|
+
return { "~standard": {
|
|
17
|
+
vendor: ORPC_NAME,
|
|
18
|
+
version: 1,
|
|
19
|
+
async validate(value) {
|
|
20
|
+
if (map) return { value: await map(value) };
|
|
21
|
+
return { value };
|
|
22
|
+
}
|
|
23
|
+
} };
|
|
27
24
|
}
|
|
28
25
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
if (!issue.path.every((segment) => isPropertyKey(segment) || (isNonPrimitive(segment) && isPropertyKey(segment.key)))) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return true;
|
|
26
|
+
* Check if the given issue is following the standard-schema issue format.
|
|
27
|
+
*/
|
|
28
|
+
function isSchemaIssue(issue) {
|
|
29
|
+
if (!isNonPrimitive(issue) || typeof issue.message !== "string") return false;
|
|
30
|
+
if (issue.path !== void 0) {
|
|
31
|
+
if (!Array.isArray(issue.path)) return false;
|
|
32
|
+
if (!issue.path.every((segment) => isPropertyKey(segment) || isNonPrimitive(segment) && isPropertyKey(segment.key))) return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
44
35
|
}
|
|
36
|
+
export { isSchemaIssue, type };
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
2
|
/**
|
|
3
3
|
* TOutput default = TInput for better readability (shorter) in-case both TInput, TOutput is equal
|
|
4
4
|
*/
|
|
@@ -22,4 +22,4 @@ export type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<i
|
|
|
22
22
|
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
23
23
|
*/
|
|
24
24
|
export type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
25
|
-
export type MergedSchema<T extends AnySchema, U extends AnySchema> = T extends Schema<infer TInput, infer TOutput> ? U extends Schema<infer UInput, infer UOutput> ? Schema<TInput & UInput, TOutput & UOutput> : never : never;
|
|
25
|
+
export type MergedSchema<T extends AnySchema, U extends AnySchema> = T extends Schema<infer TInput, infer TOutput> ? U extends Schema<infer UInput, infer UOutput> ? Schema<TInput & UInput, TOutput & UOutput> : never : never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/contract",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.50",
|
|
4
4
|
"description": "Define typesafe API contracts as the single source of truth for oRPC, powered by Standard Schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@orpc/client": "2.0.0-beta.
|
|
47
|
-
"@orpc/shared": "2.0.0-beta.
|
|
46
|
+
"@orpc/client": "2.0.0-beta.50",
|
|
47
|
+
"@orpc/shared": "2.0.0-beta.50",
|
|
48
48
|
"@standard-schema/spec": "^1.1.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
package/dist/builder-variants.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/procedure-client.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/router-client.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/router.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/schema.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|