@orpc/contract 1.12.3 → 1.13.1
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/index.d.mts +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.mjs +35 -3
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -24,6 +24,21 @@ declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap ex
|
|
|
24
24
|
* @see {@link https://orpc.dev/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
25
25
|
*/
|
|
26
26
|
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
27
|
+
type PopulatedContractRouterPaths<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, UErrors, UMeta> : {
|
|
28
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? PopulatedContractRouterPaths<T[K]> : never;
|
|
29
|
+
};
|
|
30
|
+
interface PopulateContractRouterPathsOptions {
|
|
31
|
+
path?: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Automatically populates missing route paths using the router's nested keys.
|
|
35
|
+
*
|
|
36
|
+
* Constructs paths by joining router keys with `/`.
|
|
37
|
+
* Useful for NestJS integration that require explicit route paths.
|
|
38
|
+
*
|
|
39
|
+
* @see {@link https://orpc.dev/docs/openapi/integrations/implement-contract-in-nest#define-your-contract NestJS Implement Contract Docs}
|
|
40
|
+
*/
|
|
41
|
+
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
|
27
42
|
|
|
28
43
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
29
44
|
/**
|
|
@@ -207,6 +222,12 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
207
222
|
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
208
223
|
*/
|
|
209
224
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
225
|
+
/**
|
|
226
|
+
* Sets or overrides the initial input schema.
|
|
227
|
+
*
|
|
228
|
+
* @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
|
229
|
+
*/
|
|
230
|
+
$input<U extends AnySchema>(initialInputSchema?: U): ContractBuilder<U, TOutputSchema, TErrorMap, TMeta>;
|
|
210
231
|
/**
|
|
211
232
|
* Adds type-safe custom errors to the contract.
|
|
212
233
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
@@ -303,5 +324,5 @@ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext exte
|
|
|
303
324
|
|
|
304
325
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
305
326
|
|
|
306
|
-
export { AnyContractRouter, AnySchema, ContractBuilder, ContractProcedure, ContractProcedureDef, ContractRouter, EnhanceRouteOptions, ErrorFromErrorMap, ErrorMap, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, SchemaIssue, enhanceContractRouter, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isSchemaIssue, minifyContractRouter, oc };
|
|
307
|
-
export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails };
|
|
327
|
+
export { AnyContractRouter, AnySchema, ContractBuilder, ContractProcedure, ContractProcedureDef, ContractRouter, EnhanceRouteOptions, ErrorFromErrorMap, ErrorMap, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, SchemaIssue, enhanceContractRouter, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isSchemaIssue, minifyContractRouter, oc, populateContractRouterPaths };
|
|
328
|
+
export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,21 @@ declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap ex
|
|
|
24
24
|
* @see {@link https://orpc.dev/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
25
25
|
*/
|
|
26
26
|
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
27
|
+
type PopulatedContractRouterPaths<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, UErrors, UMeta> : {
|
|
28
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? PopulatedContractRouterPaths<T[K]> : never;
|
|
29
|
+
};
|
|
30
|
+
interface PopulateContractRouterPathsOptions {
|
|
31
|
+
path?: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Automatically populates missing route paths using the router's nested keys.
|
|
35
|
+
*
|
|
36
|
+
* Constructs paths by joining router keys with `/`.
|
|
37
|
+
* Useful for NestJS integration that require explicit route paths.
|
|
38
|
+
*
|
|
39
|
+
* @see {@link https://orpc.dev/docs/openapi/integrations/implement-contract-in-nest#define-your-contract NestJS Implement Contract Docs}
|
|
40
|
+
*/
|
|
41
|
+
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
|
27
42
|
|
|
28
43
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
29
44
|
/**
|
|
@@ -207,6 +222,12 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
207
222
|
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
208
223
|
*/
|
|
209
224
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
225
|
+
/**
|
|
226
|
+
* Sets or overrides the initial input schema.
|
|
227
|
+
*
|
|
228
|
+
* @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
|
229
|
+
*/
|
|
230
|
+
$input<U extends AnySchema>(initialInputSchema?: U): ContractBuilder<U, TOutputSchema, TErrorMap, TMeta>;
|
|
210
231
|
/**
|
|
211
232
|
* Adds type-safe custom errors to the contract.
|
|
212
233
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
@@ -303,5 +324,5 @@ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext exte
|
|
|
303
324
|
|
|
304
325
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
305
326
|
|
|
306
|
-
export { AnyContractRouter, AnySchema, ContractBuilder, ContractProcedure, ContractProcedureDef, ContractRouter, EnhanceRouteOptions, ErrorFromErrorMap, ErrorMap, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, SchemaIssue, enhanceContractRouter, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isSchemaIssue, minifyContractRouter, oc };
|
|
307
|
-
export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails };
|
|
327
|
+
export { AnyContractRouter, AnySchema, ContractBuilder, ContractProcedure, ContractProcedureDef, ContractRouter, EnhanceRouteOptions, ErrorFromErrorMap, ErrorMap, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, SchemaIssue, enhanceContractRouter, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isSchemaIssue, minifyContractRouter, oc, populateContractRouterPaths };
|
|
328
|
+
export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { i as isContractProcedure, C as ContractProcedure, m as mergeErrorMap, V as ValidationError } from './shared/contract.D_dZrO__.mjs';
|
|
2
2
|
export { v as validateORPCError } from './shared/contract.D_dZrO__.mjs';
|
|
3
|
+
import { toHttpPath } from '@orpc/client/standard';
|
|
4
|
+
import { toArray, isAsyncIteratorObject, get, isTypescriptObject, isPropertyKey } from '@orpc/shared';
|
|
5
|
+
export { AsyncIteratorClass } from '@orpc/shared';
|
|
3
6
|
import { mapEventIterator, ORPCError } from '@orpc/client';
|
|
4
7
|
export { ORPCError } from '@orpc/client';
|
|
5
|
-
import { isAsyncIteratorObject, get, isTypescriptObject, isPropertyKey } from '@orpc/shared';
|
|
6
|
-
export { AsyncIteratorClass } from '@orpc/shared';
|
|
7
8
|
|
|
8
9
|
function mergeMeta(meta1, meta2) {
|
|
9
10
|
return { ...meta1, ...meta2 };
|
|
@@ -90,6 +91,26 @@ function minifyContractRouter(router) {
|
|
|
90
91
|
}
|
|
91
92
|
return json;
|
|
92
93
|
}
|
|
94
|
+
function populateContractRouterPaths(router, options = {}) {
|
|
95
|
+
const path = toArray(options.path);
|
|
96
|
+
if (isContractProcedure(router)) {
|
|
97
|
+
if (router["~orpc"].route.path === void 0) {
|
|
98
|
+
return new ContractProcedure({
|
|
99
|
+
...router["~orpc"],
|
|
100
|
+
route: {
|
|
101
|
+
...router["~orpc"].route,
|
|
102
|
+
path: toHttpPath(path)
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return router;
|
|
107
|
+
}
|
|
108
|
+
const populated = {};
|
|
109
|
+
for (const key in router) {
|
|
110
|
+
populated[key] = populateContractRouterPaths(router[key], { ...options, path: [...path, key] });
|
|
111
|
+
}
|
|
112
|
+
return populated;
|
|
113
|
+
}
|
|
93
114
|
|
|
94
115
|
class ContractBuilder extends ContractProcedure {
|
|
95
116
|
constructor(def) {
|
|
@@ -121,6 +142,17 @@ class ContractBuilder extends ContractProcedure {
|
|
|
121
142
|
route: initialRoute
|
|
122
143
|
});
|
|
123
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Sets or overrides the initial input schema.
|
|
147
|
+
*
|
|
148
|
+
* @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
|
149
|
+
*/
|
|
150
|
+
$input(initialInputSchema) {
|
|
151
|
+
return new ContractBuilder({
|
|
152
|
+
...this["~orpc"],
|
|
153
|
+
inputSchema: initialInputSchema
|
|
154
|
+
});
|
|
155
|
+
}
|
|
124
156
|
/**
|
|
125
157
|
* Adds type-safe custom errors to the contract.
|
|
126
158
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
@@ -323,4 +355,4 @@ function isSchemaIssue(issue) {
|
|
|
323
355
|
return true;
|
|
324
356
|
}
|
|
325
357
|
|
|
326
|
-
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
|
|
358
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, populateContractRouterPaths, prefixRoute, type, unshiftTagRoute };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/contract",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.13.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@standard-schema/spec": "^1.0.0",
|
|
33
33
|
"openapi-types": "^12.1.3",
|
|
34
|
-
"@orpc/
|
|
35
|
-
"@orpc/
|
|
34
|
+
"@orpc/shared": "1.13.1",
|
|
35
|
+
"@orpc/client": "1.13.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"arktype": "2.1.27",
|