@orpc/contract 0.0.0-next.a895960 → 0.0.0-next.aa72097
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.js +98 -88
- package/dist/src/builder.d.ts +6 -5
- package/dist/src/config.d.ts +36 -0
- package/dist/src/index.d.ts +3 -2
- package/dist/src/procedure-decorated.d.ts +12 -0
- package/dist/src/procedure.d.ts +70 -36
- package/dist/src/router-builder.d.ts +15 -11
- package/dist/src/router.d.ts +7 -11
- package/dist/src/types.d.ts +6 -5
- package/package.json +8 -5
- package/dist/src/constants.d.ts +0 -3
- package/dist/src/utils.d.ts +0 -4
package/dist/index.js
CHANGED
|
@@ -1,96 +1,112 @@
|
|
|
1
1
|
// src/procedure.ts
|
|
2
2
|
var ContractProcedure = class {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
"~type" = "ContractProcedure";
|
|
4
|
+
"~orpc";
|
|
5
|
+
constructor(def) {
|
|
6
|
+
if (def.route?.successStatus && (def.route.successStatus < 200 || def.route?.successStatus > 299)) {
|
|
7
|
+
throw new Error("[ContractProcedure] The successStatus must be between 200 and 299");
|
|
8
|
+
}
|
|
9
|
+
this["~orpc"] = def;
|
|
5
10
|
}
|
|
6
11
|
};
|
|
12
|
+
function isContractProcedure(item) {
|
|
13
|
+
if (item instanceof ContractProcedure) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "ContractProcedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "InputSchema" in item["~orpc"] && "OutputSchema" in item["~orpc"];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/procedure-decorated.ts
|
|
7
20
|
var DecoratedContractProcedure = class _DecoratedContractProcedure extends ContractProcedure {
|
|
8
|
-
static decorate(
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
11
|
-
|
|
21
|
+
static decorate(procedure) {
|
|
22
|
+
if (procedure instanceof _DecoratedContractProcedure) {
|
|
23
|
+
return procedure;
|
|
24
|
+
}
|
|
25
|
+
return new _DecoratedContractProcedure(procedure["~orpc"]);
|
|
12
26
|
}
|
|
13
|
-
route(
|
|
27
|
+
route(route) {
|
|
14
28
|
return new _DecoratedContractProcedure({
|
|
15
|
-
...this
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
...this["~orpc"],
|
|
30
|
+
route: {
|
|
31
|
+
...this["~orpc"].route,
|
|
32
|
+
...route
|
|
33
|
+
}
|
|
19
34
|
});
|
|
20
35
|
}
|
|
21
36
|
prefix(prefix) {
|
|
22
|
-
if (!this.zz$cp.path)
|
|
23
|
-
return this;
|
|
24
37
|
return new _DecoratedContractProcedure({
|
|
25
|
-
...this
|
|
26
|
-
path
|
|
38
|
+
...this["~orpc"],
|
|
39
|
+
...this["~orpc"].route?.path ? {
|
|
40
|
+
route: {
|
|
41
|
+
...this["~orpc"].route,
|
|
42
|
+
path: `${prefix}${this["~orpc"].route.path}`
|
|
43
|
+
}
|
|
44
|
+
} : void 0
|
|
27
45
|
});
|
|
28
46
|
}
|
|
29
|
-
|
|
30
|
-
if (!tags.length)
|
|
31
|
-
return this;
|
|
47
|
+
unshiftTag(...tags) {
|
|
32
48
|
return new _DecoratedContractProcedure({
|
|
33
|
-
...this
|
|
34
|
-
|
|
49
|
+
...this["~orpc"],
|
|
50
|
+
route: {
|
|
51
|
+
...this["~orpc"].route,
|
|
52
|
+
tags: [
|
|
53
|
+
...tags,
|
|
54
|
+
...this["~orpc"].route?.tags?.filter((tag) => !tags.includes(tag)) ?? []
|
|
55
|
+
]
|
|
56
|
+
}
|
|
35
57
|
});
|
|
36
58
|
}
|
|
37
59
|
input(schema, example) {
|
|
38
60
|
return new _DecoratedContractProcedure({
|
|
39
|
-
...this
|
|
61
|
+
...this["~orpc"],
|
|
40
62
|
InputSchema: schema,
|
|
41
63
|
inputExample: example
|
|
42
64
|
});
|
|
43
65
|
}
|
|
44
66
|
output(schema, example) {
|
|
45
67
|
return new _DecoratedContractProcedure({
|
|
46
|
-
...this
|
|
68
|
+
...this["~orpc"],
|
|
47
69
|
OutputSchema: schema,
|
|
48
70
|
outputExample: example
|
|
49
71
|
});
|
|
50
72
|
}
|
|
51
73
|
};
|
|
52
|
-
function isContractProcedure(item) {
|
|
53
|
-
if (item instanceof ContractProcedure)
|
|
54
|
-
return true;
|
|
55
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "zz$cp" in item && typeof item.zz$cp === "object" && item.zz$cp !== null && "InputSchema" in item.zz$cp && "OutputSchema" in item.zz$cp;
|
|
56
|
-
}
|
|
57
74
|
|
|
58
75
|
// src/router-builder.ts
|
|
59
76
|
var ContractRouterBuilder = class _ContractRouterBuilder {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
77
|
+
"~type" = "ContractProcedure";
|
|
78
|
+
"~orpc";
|
|
79
|
+
constructor(def) {
|
|
80
|
+
this["~orpc"] = def;
|
|
65
81
|
}
|
|
66
82
|
prefix(prefix) {
|
|
67
83
|
return new _ContractRouterBuilder({
|
|
68
|
-
...this
|
|
69
|
-
prefix: `${this.
|
|
84
|
+
...this["~orpc"],
|
|
85
|
+
prefix: `${this["~orpc"].prefix ?? ""}${prefix}`
|
|
70
86
|
});
|
|
71
87
|
}
|
|
72
|
-
|
|
73
|
-
if (!tags.length)
|
|
74
|
-
return this;
|
|
88
|
+
tag(...tags) {
|
|
75
89
|
return new _ContractRouterBuilder({
|
|
76
|
-
...this
|
|
77
|
-
tags: [...this.
|
|
90
|
+
...this["~orpc"],
|
|
91
|
+
tags: [...this["~orpc"].tags ?? [], ...tags]
|
|
78
92
|
});
|
|
79
93
|
}
|
|
80
94
|
router(router) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const decorated = DecoratedContractProcedure.decorate(item).addTags(
|
|
86
|
-
...this.zz$crb.tags ?? []
|
|
87
|
-
);
|
|
88
|
-
handled[key] = this.zz$crb.prefix ? decorated.prefix(this.zz$crb.prefix) : decorated;
|
|
89
|
-
} else {
|
|
90
|
-
handled[key] = this.router(item);
|
|
95
|
+
if (isContractProcedure(router)) {
|
|
96
|
+
let decorated = DecoratedContractProcedure.decorate(router);
|
|
97
|
+
if (this["~orpc"].tags) {
|
|
98
|
+
decorated = decorated.unshiftTag(...this["~orpc"].tags);
|
|
91
99
|
}
|
|
100
|
+
if (this["~orpc"].prefix) {
|
|
101
|
+
decorated = decorated.prefix(this["~orpc"].prefix);
|
|
102
|
+
}
|
|
103
|
+
return decorated;
|
|
104
|
+
}
|
|
105
|
+
const adapted = {};
|
|
106
|
+
for (const key in router) {
|
|
107
|
+
adapted[key] = this.router(router[key]);
|
|
92
108
|
}
|
|
93
|
-
return
|
|
109
|
+
return adapted;
|
|
94
110
|
}
|
|
95
111
|
};
|
|
96
112
|
|
|
@@ -101,16 +117,16 @@ var ContractBuilder = class {
|
|
|
101
117
|
prefix
|
|
102
118
|
});
|
|
103
119
|
}
|
|
104
|
-
|
|
120
|
+
tag(...tags) {
|
|
105
121
|
return new ContractRouterBuilder({
|
|
106
122
|
tags
|
|
107
123
|
});
|
|
108
124
|
}
|
|
109
|
-
route(
|
|
125
|
+
route(route) {
|
|
110
126
|
return new DecoratedContractProcedure({
|
|
127
|
+
route,
|
|
111
128
|
InputSchema: void 0,
|
|
112
|
-
OutputSchema: void 0
|
|
113
|
-
...opts
|
|
129
|
+
OutputSchema: void 0
|
|
114
130
|
});
|
|
115
131
|
}
|
|
116
132
|
input(schema, example) {
|
|
@@ -122,9 +138,9 @@ var ContractBuilder = class {
|
|
|
122
138
|
}
|
|
123
139
|
output(schema, example) {
|
|
124
140
|
return new DecoratedContractProcedure({
|
|
125
|
-
InputSchema: void 0,
|
|
126
141
|
OutputSchema: schema,
|
|
127
|
-
outputExample: example
|
|
142
|
+
outputExample: example,
|
|
143
|
+
InputSchema: void 0
|
|
128
144
|
});
|
|
129
145
|
}
|
|
130
146
|
router(router) {
|
|
@@ -132,34 +148,30 @@ var ContractBuilder = class {
|
|
|
132
148
|
}
|
|
133
149
|
};
|
|
134
150
|
|
|
135
|
-
// src/
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
151
|
+
// src/config.ts
|
|
152
|
+
var DEFAULT_CONFIG = {
|
|
153
|
+
defaultMethod: "POST",
|
|
154
|
+
defaultSuccessStatus: 200,
|
|
155
|
+
defaultSuccessDescription: "OK",
|
|
156
|
+
defaultInputStructure: "compact",
|
|
157
|
+
defaultOutputStructure: "compact"
|
|
158
|
+
};
|
|
159
|
+
var GLOBAL_CONFIG_REF = { value: DEFAULT_CONFIG };
|
|
160
|
+
function configGlobal(config) {
|
|
161
|
+
if (config.defaultSuccessStatus !== void 0 && (config.defaultSuccessStatus < 200 || config.defaultSuccessStatus > 299)) {
|
|
162
|
+
throw new Error("[configGlobal] The defaultSuccessStatus must be between 200 and 299");
|
|
148
163
|
}
|
|
164
|
+
GLOBAL_CONFIG_REF.value = config;
|
|
149
165
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return path_;
|
|
160
|
-
if (path_ === "/")
|
|
161
|
-
return prefix_;
|
|
162
|
-
return `${prefix_}${path_}`;
|
|
166
|
+
function fallbackToGlobalConfig(key, value) {
|
|
167
|
+
if (value === void 0) {
|
|
168
|
+
const fallback = GLOBAL_CONFIG_REF.value[key];
|
|
169
|
+
if (fallback === void 0) {
|
|
170
|
+
return DEFAULT_CONFIG[key];
|
|
171
|
+
}
|
|
172
|
+
return fallback;
|
|
173
|
+
}
|
|
174
|
+
return value;
|
|
163
175
|
}
|
|
164
176
|
|
|
165
177
|
// src/index.ts
|
|
@@ -167,13 +179,11 @@ var oc = new ContractBuilder();
|
|
|
167
179
|
export {
|
|
168
180
|
ContractBuilder,
|
|
169
181
|
ContractProcedure,
|
|
182
|
+
ContractRouterBuilder,
|
|
170
183
|
DecoratedContractProcedure,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
eachContractRouterLeaf,
|
|
184
|
+
configGlobal,
|
|
185
|
+
fallbackToGlobalConfig,
|
|
174
186
|
isContractProcedure,
|
|
175
|
-
oc
|
|
176
|
-
prefixHTTPPath,
|
|
177
|
-
standardizeHTTPPath
|
|
187
|
+
oc
|
|
178
188
|
};
|
|
179
189
|
//# sourceMappingURL=index.js.map
|
package/dist/src/builder.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import type { RouteOptions } from './procedure';
|
|
1
2
|
import type { ContractRouter } from './router';
|
|
2
3
|
import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
|
|
3
|
-
import { DecoratedContractProcedure
|
|
4
|
+
import { DecoratedContractProcedure } from './procedure-decorated';
|
|
4
5
|
import { ContractRouterBuilder } from './router-builder';
|
|
5
6
|
export declare class ContractBuilder {
|
|
6
7
|
prefix(prefix: HTTPPath): ContractRouterBuilder;
|
|
7
|
-
|
|
8
|
-
route(
|
|
9
|
-
input<
|
|
10
|
-
output<
|
|
8
|
+
tag(...tags: string[]): ContractRouterBuilder;
|
|
9
|
+
route(route: RouteOptions): DecoratedContractProcedure<undefined, undefined>;
|
|
10
|
+
input<U extends Schema = undefined>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, undefined>;
|
|
11
|
+
output<U extends Schema = undefined>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<undefined, U>;
|
|
11
12
|
router<T extends ContractRouter>(router: T): T;
|
|
12
13
|
}
|
|
13
14
|
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { HTTPMethod, InputStructure } from './types';
|
|
2
|
+
export interface ORPCConfig {
|
|
3
|
+
/**
|
|
4
|
+
* @default 'POST'
|
|
5
|
+
*/
|
|
6
|
+
defaultMethod?: HTTPMethod;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @default 200
|
|
10
|
+
*/
|
|
11
|
+
defaultSuccessStatus?: number;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @default 'OK'
|
|
15
|
+
*/
|
|
16
|
+
defaultSuccessDescription?: string;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @default 'compact'
|
|
20
|
+
*/
|
|
21
|
+
defaultInputStructure?: InputStructure;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @default 'compact'
|
|
25
|
+
*/
|
|
26
|
+
defaultOutputStructure?: InputStructure;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Set the global configuration, this configuration can effect entire project
|
|
30
|
+
*/
|
|
31
|
+
export declare function configGlobal(config: ORPCConfig): void;
|
|
32
|
+
/**
|
|
33
|
+
* Fallback the value to the global config if it is undefined
|
|
34
|
+
*/
|
|
35
|
+
export declare function fallbackToGlobalConfig<T extends keyof ORPCConfig>(key: T, value: ORPCConfig[T]): Exclude<ORPCConfig[T], undefined>;
|
|
36
|
+
//# sourceMappingURL=config.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** unnoq */
|
|
2
2
|
import { ContractBuilder } from './builder';
|
|
3
3
|
export * from './builder';
|
|
4
|
-
export * from './
|
|
4
|
+
export * from './config';
|
|
5
5
|
export * from './procedure';
|
|
6
|
+
export * from './procedure-decorated';
|
|
6
7
|
export * from './router';
|
|
8
|
+
export * from './router-builder';
|
|
7
9
|
export * from './types';
|
|
8
|
-
export * from './utils';
|
|
9
10
|
export declare const oc: ContractBuilder;
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RouteOptions } from './procedure';
|
|
2
|
+
import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
|
|
3
|
+
import { ContractProcedure } from './procedure';
|
|
4
|
+
export declare class DecoratedContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> extends ContractProcedure<TInputSchema, TOutputSchema> {
|
|
5
|
+
static decorate<UInputSchema extends Schema = undefined, UOutputSchema extends Schema = undefined>(procedure: ContractProcedure<UInputSchema, UOutputSchema>): DecoratedContractProcedure<UInputSchema, UOutputSchema>;
|
|
6
|
+
route(route: RouteOptions): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
|
|
7
|
+
prefix(prefix: HTTPPath): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
|
|
8
|
+
unshiftTag(...tags: string[]): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
|
|
9
|
+
input<U extends Schema = undefined>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, TOutputSchema>;
|
|
10
|
+
output<U extends Schema = undefined>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<TInputSchema, U>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=procedure-decorated.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
|
@@ -1,47 +1,81 @@
|
|
|
1
|
-
import type { HTTPMethod, HTTPPath,
|
|
1
|
+
import type { HTTPMethod, HTTPPath, InputStructure, OutputStructure, Schema, SchemaOutput } from './types';
|
|
2
2
|
export interface RouteOptions {
|
|
3
3
|
method?: HTTPMethod;
|
|
4
4
|
path?: HTTPPath;
|
|
5
5
|
summary?: string;
|
|
6
6
|
description?: string;
|
|
7
7
|
deprecated?: boolean;
|
|
8
|
-
tags?: string[];
|
|
8
|
+
tags?: readonly string[];
|
|
9
|
+
/**
|
|
10
|
+
* The status code of the response when the procedure is successful.
|
|
11
|
+
*
|
|
12
|
+
* @default 200
|
|
13
|
+
*/
|
|
14
|
+
successStatus?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The description of the response when the procedure is successful.
|
|
17
|
+
*
|
|
18
|
+
* @default 'OK'
|
|
19
|
+
*/
|
|
20
|
+
successDescription?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
|
|
23
|
+
*
|
|
24
|
+
* @option 'compact'
|
|
25
|
+
* Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
|
|
26
|
+
*
|
|
27
|
+
* @option 'detailed'
|
|
28
|
+
* Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
|
|
29
|
+
*
|
|
30
|
+
* Example:
|
|
31
|
+
* ```ts
|
|
32
|
+
* const input = {
|
|
33
|
+
* params: { id: 1 },
|
|
34
|
+
* query: { search: 'hello' },
|
|
35
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
36
|
+
* body: { name: 'John' },
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @default 'compact'
|
|
41
|
+
*/
|
|
42
|
+
inputStructure?: InputStructure;
|
|
43
|
+
/**
|
|
44
|
+
* Determines how the response should be structured based on the output.
|
|
45
|
+
*
|
|
46
|
+
* @option 'compact'
|
|
47
|
+
* Includes only the body data, encoded directly in the response.
|
|
48
|
+
*
|
|
49
|
+
* @option 'detailed'
|
|
50
|
+
* Separates the output into `headers` and `body` fields.
|
|
51
|
+
* - `headers`: Custom headers to merge with the response headers.
|
|
52
|
+
* - `body`: The response data.
|
|
53
|
+
*
|
|
54
|
+
* Example:
|
|
55
|
+
* ```ts
|
|
56
|
+
* const output = {
|
|
57
|
+
* headers: { 'x-custom-header': 'value' },
|
|
58
|
+
* body: { message: 'Hello, world!' },
|
|
59
|
+
* };
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @default 'compact'
|
|
63
|
+
*/
|
|
64
|
+
outputStructure?: OutputStructure;
|
|
65
|
+
}
|
|
66
|
+
export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema> {
|
|
67
|
+
route?: RouteOptions;
|
|
68
|
+
InputSchema: TInputSchema;
|
|
69
|
+
inputExample?: SchemaOutput<TInputSchema>;
|
|
70
|
+
OutputSchema: TOutputSchema;
|
|
71
|
+
outputExample?: SchemaOutput<TOutputSchema>;
|
|
9
72
|
}
|
|
10
73
|
export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
summary?: string;
|
|
15
|
-
description?: string;
|
|
16
|
-
deprecated?: boolean;
|
|
17
|
-
tags?: string[];
|
|
18
|
-
InputSchema: TInputSchema;
|
|
19
|
-
inputExample?: SchemaOutput<TInputSchema>;
|
|
20
|
-
OutputSchema: TOutputSchema;
|
|
21
|
-
outputExample?: SchemaOutput<TOutputSchema>;
|
|
22
|
-
};
|
|
23
|
-
constructor(zz$cp: {
|
|
24
|
-
path?: HTTPPath;
|
|
25
|
-
method?: HTTPMethod;
|
|
26
|
-
summary?: string;
|
|
27
|
-
description?: string;
|
|
28
|
-
deprecated?: boolean;
|
|
29
|
-
tags?: string[];
|
|
30
|
-
InputSchema: TInputSchema;
|
|
31
|
-
inputExample?: SchemaOutput<TInputSchema>;
|
|
32
|
-
OutputSchema: TOutputSchema;
|
|
33
|
-
outputExample?: SchemaOutput<TOutputSchema>;
|
|
34
|
-
});
|
|
74
|
+
'~type': "ContractProcedure";
|
|
75
|
+
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema>;
|
|
76
|
+
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema>);
|
|
35
77
|
}
|
|
78
|
+
export type ANY_CONTRACT_PROCEDURE = ContractProcedure<any, any>;
|
|
36
79
|
export type WELL_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema>;
|
|
37
|
-
export declare
|
|
38
|
-
static decorate<TInputSchema extends Schema, TOutputSchema extends Schema>(cp: ContractProcedure<TInputSchema, TOutputSchema>): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
|
|
39
|
-
route(opts: RouteOptions): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
|
|
40
|
-
prefix(prefix: HTTPPath): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
|
|
41
|
-
addTags(...tags: string[]): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
|
|
42
|
-
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): DecoratedContractProcedure<USchema, TOutputSchema>;
|
|
43
|
-
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): DecoratedContractProcedure<TInputSchema, USchema>;
|
|
44
|
-
}
|
|
45
|
-
export type WELL_DEFINED_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema>;
|
|
46
|
-
export declare function isContractProcedure(item: unknown): item is WELL_DEFINED_CONTRACT_PROCEDURE;
|
|
80
|
+
export declare function isContractProcedure(item: unknown): item is ANY_CONTRACT_PROCEDURE;
|
|
47
81
|
//# sourceMappingURL=procedure.d.ts.map
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ContractProcedure } from './procedure';
|
|
2
|
+
import type { ContractRouter } from './router';
|
|
2
3
|
import type { HTTPPath } from './types';
|
|
4
|
+
import { DecoratedContractProcedure } from './procedure-decorated';
|
|
5
|
+
export type AdaptedContractRouter<TContract extends ContractRouter> = {
|
|
6
|
+
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? DecoratedContractProcedure<UInputSchema, UOutputSchema> : TContract[K] extends ContractRouter ? AdaptedContractRouter<TContract[K]> : never;
|
|
7
|
+
};
|
|
8
|
+
export interface ContractRouterBuilderDef {
|
|
9
|
+
prefix?: HTTPPath;
|
|
10
|
+
tags?: string[];
|
|
11
|
+
}
|
|
3
12
|
export declare class ContractRouterBuilder {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
constructor(zz$crb: {
|
|
9
|
-
prefix?: HTTPPath;
|
|
10
|
-
tags?: string[];
|
|
11
|
-
});
|
|
13
|
+
'~type': "ContractProcedure";
|
|
14
|
+
'~orpc': ContractRouterBuilderDef;
|
|
15
|
+
constructor(def: ContractRouterBuilderDef);
|
|
12
16
|
prefix(prefix: HTTPPath): ContractRouterBuilder;
|
|
13
|
-
|
|
14
|
-
router<T extends ContractRouter>(router: T):
|
|
17
|
+
tag(...tags: string[]): ContractRouterBuilder;
|
|
18
|
+
router<T extends ContractRouter>(router: T): AdaptedContractRouter<T>;
|
|
15
19
|
}
|
|
16
20
|
//# sourceMappingURL=router-builder.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE, ContractProcedure } from './procedure';
|
|
1
2
|
import type { SchemaInput, SchemaOutput } from './types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
[k: string]: ContractProcedure<any, any> | ContractRouter;
|
|
5
|
-
}
|
|
6
|
-
export type HandledContractRouter<TContract extends ContractRouter> = {
|
|
7
|
-
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? DecoratedContractProcedure<UInputSchema, UOutputSchema> : TContract[K] extends ContractRouter ? HandledContractRouter<TContract[K]> : never;
|
|
3
|
+
export type ContractRouter = ANY_CONTRACT_PROCEDURE | {
|
|
4
|
+
[k: string]: ContractRouter;
|
|
8
5
|
};
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
[K in keyof T]: T[K] extends ContractProcedure<infer UInputSchema, any> ? SchemaInput<UInputSchema> : T[K] extends ContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
6
|
+
export type InferContractRouterInputs<T extends ContractRouter> = T extends ContractProcedure<infer UInputSchema, any> ? SchemaInput<UInputSchema> : {
|
|
7
|
+
[K in keyof T]: T[K] extends ContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
12
8
|
};
|
|
13
|
-
export type InferContractRouterOutputs<T extends ContractRouter> = {
|
|
14
|
-
[K in keyof T]: T[K] extends
|
|
9
|
+
export type InferContractRouterOutputs<T extends ContractRouter> = T extends ContractProcedure<any, infer UOutputSchema> ? SchemaOutput<UOutputSchema> : {
|
|
10
|
+
[K in keyof T]: T[K] extends ContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
15
11
|
};
|
|
16
12
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
export type HTTPPath = `/${string}`;
|
|
3
3
|
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
7
|
-
export type
|
|
4
|
+
export type InputStructure = 'compact' | 'detailed';
|
|
5
|
+
export type OutputStructure = 'compact' | 'detailed';
|
|
6
|
+
export type Schema = StandardSchemaV1 | undefined;
|
|
7
|
+
export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
|
|
8
|
+
export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
8
9
|
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/contract",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.aa72097",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -28,11 +28,14 @@
|
|
|
28
28
|
"!**/*.tsbuildinfo",
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"zod": ">=3.23.0"
|
|
33
|
-
},
|
|
34
31
|
"dependencies": {
|
|
35
|
-
"@
|
|
32
|
+
"@standard-schema/spec": "1.0.0-beta.4",
|
|
33
|
+
"@orpc/shared": "0.0.0-next.aa72097"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"arktype": "2.0.0-rc.26",
|
|
37
|
+
"valibot": "1.0.0-beta.9",
|
|
38
|
+
"zod": "3.24.1"
|
|
36
39
|
},
|
|
37
40
|
"scripts": {
|
|
38
41
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
package/dist/src/constants.d.ts
DELETED
package/dist/src/utils.d.ts
DELETED