@orpc/contract 0.0.0-next.db1f26d → 0.0.0-next.dbce934

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 DELETED
@@ -1,179 +0,0 @@
1
- // src/procedure.ts
2
- var ContractProcedure = class {
3
- constructor(zz$cp) {
4
- this.zz$cp = zz$cp;
5
- }
6
- };
7
- var DecoratedContractProcedure = class _DecoratedContractProcedure extends ContractProcedure {
8
- static decorate(cp) {
9
- if (cp instanceof _DecoratedContractProcedure)
10
- return cp;
11
- return new _DecoratedContractProcedure(cp.zz$cp);
12
- }
13
- route(opts) {
14
- return new _DecoratedContractProcedure({
15
- ...this.zz$cp,
16
- ...opts,
17
- method: opts.method,
18
- path: opts.path
19
- });
20
- }
21
- prefix(prefix) {
22
- if (!this.zz$cp.path)
23
- return this;
24
- return new _DecoratedContractProcedure({
25
- ...this.zz$cp,
26
- path: `${prefix}${this.zz$cp.path}`
27
- });
28
- }
29
- addTags(...tags) {
30
- if (!tags.length)
31
- return this;
32
- return new _DecoratedContractProcedure({
33
- ...this.zz$cp,
34
- tags: [...this.zz$cp.tags ?? [], ...tags]
35
- });
36
- }
37
- input(schema, example) {
38
- return new _DecoratedContractProcedure({
39
- ...this.zz$cp,
40
- InputSchema: schema,
41
- inputExample: example
42
- });
43
- }
44
- output(schema, example) {
45
- return new _DecoratedContractProcedure({
46
- ...this.zz$cp,
47
- OutputSchema: schema,
48
- outputExample: example
49
- });
50
- }
51
- };
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
-
58
- // src/router-builder.ts
59
- var ContractRouterBuilder = class _ContractRouterBuilder {
60
- constructor(zz$crb) {
61
- this.zz$crb = zz$crb;
62
- if (zz$crb.prefix && zz$crb.prefix.includes("{")) {
63
- throw new Error('Prefix cannot contain "{" for dynamic routing');
64
- }
65
- }
66
- prefix(prefix) {
67
- return new _ContractRouterBuilder({
68
- ...this.zz$crb,
69
- prefix: `${this.zz$crb.prefix ?? ""}${prefix}`
70
- });
71
- }
72
- tags(...tags) {
73
- if (!tags.length)
74
- return this;
75
- return new _ContractRouterBuilder({
76
- ...this.zz$crb,
77
- tags: [...this.zz$crb.tags ?? [], ...tags]
78
- });
79
- }
80
- router(router) {
81
- const handled = {};
82
- for (const key in router) {
83
- const item = router[key];
84
- if (isContractProcedure(item)) {
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);
91
- }
92
- }
93
- return handled;
94
- }
95
- };
96
-
97
- // src/builder.ts
98
- var ContractBuilder = class {
99
- prefix(prefix) {
100
- return new ContractRouterBuilder({
101
- prefix
102
- });
103
- }
104
- tags(...tags) {
105
- return new ContractRouterBuilder({
106
- tags
107
- });
108
- }
109
- route(opts) {
110
- return new DecoratedContractProcedure({
111
- InputSchema: void 0,
112
- OutputSchema: void 0,
113
- ...opts
114
- });
115
- }
116
- input(schema, example) {
117
- return new DecoratedContractProcedure({
118
- InputSchema: schema,
119
- inputExample: example,
120
- OutputSchema: void 0
121
- });
122
- }
123
- output(schema, example) {
124
- return new DecoratedContractProcedure({
125
- InputSchema: void 0,
126
- OutputSchema: schema,
127
- outputExample: example
128
- });
129
- }
130
- router(router) {
131
- return router;
132
- }
133
- };
134
-
135
- // src/constants.ts
136
- var ORPC_HEADER = "x-orpc-transformer";
137
- var ORPC_HEADER_VALUE = "t";
138
-
139
- // src/router.ts
140
- function eachContractRouterLeaf(router, callback, prefix = []) {
141
- for (const key in router) {
142
- const item = router[key];
143
- if (isContractProcedure(item)) {
144
- callback(item, [...prefix, key]);
145
- } else {
146
- eachContractRouterLeaf(item, callback, [...prefix, key]);
147
- }
148
- }
149
- }
150
-
151
- // src/utils.ts
152
- function standardizeHTTPPath(path) {
153
- return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
154
- }
155
- function prefixHTTPPath(prefix, path) {
156
- const prefix_ = standardizeHTTPPath(prefix);
157
- const path_ = standardizeHTTPPath(path);
158
- if (prefix_ === "/")
159
- return path_;
160
- if (path_ === "/")
161
- return prefix_;
162
- return `${prefix_}${path_}`;
163
- }
164
-
165
- // src/index.ts
166
- var oc = new ContractBuilder();
167
- export {
168
- ContractBuilder,
169
- ContractProcedure,
170
- DecoratedContractProcedure,
171
- ORPC_HEADER,
172
- ORPC_HEADER_VALUE,
173
- eachContractRouterLeaf,
174
- isContractProcedure,
175
- oc,
176
- prefixHTTPPath,
177
- standardizeHTTPPath
178
- };
179
- //# sourceMappingURL=index.js.map
@@ -1,13 +0,0 @@
1
- import type { ContractRouter } from './router';
2
- import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
3
- import { DecoratedContractProcedure, type RouteOptions } from './procedure';
4
- import { ContractRouterBuilder } from './router-builder';
5
- export declare class ContractBuilder {
6
- prefix(prefix: HTTPPath): ContractRouterBuilder;
7
- tags(...tags: string[]): ContractRouterBuilder;
8
- route(opts: RouteOptions): DecoratedContractProcedure<undefined, undefined>;
9
- input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): DecoratedContractProcedure<USchema, undefined>;
10
- output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): DecoratedContractProcedure<undefined, USchema>;
11
- router<T extends ContractRouter>(router: T): T;
12
- }
13
- //# sourceMappingURL=builder.d.ts.map
@@ -1,3 +0,0 @@
1
- export declare const ORPC_HEADER = "x-orpc-transformer";
2
- export declare const ORPC_HEADER_VALUE = "t";
3
- //# sourceMappingURL=constants.d.ts.map
@@ -1,10 +0,0 @@
1
- /** unnoq */
2
- import { ContractBuilder } from './builder';
3
- export * from './builder';
4
- export * from './constants';
5
- export * from './procedure';
6
- export * from './router';
7
- export * from './types';
8
- export * from './utils';
9
- export declare const oc: ContractBuilder;
10
- //# sourceMappingURL=index.d.ts.map
@@ -1,47 +0,0 @@
1
- import type { HTTPMethod, HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
2
- export interface RouteOptions {
3
- method?: HTTPMethod;
4
- path?: HTTPPath;
5
- summary?: string;
6
- description?: string;
7
- deprecated?: boolean;
8
- tags?: string[];
9
- }
10
- export declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> {
11
- zz$cp: {
12
- path?: HTTPPath;
13
- method?: HTTPMethod;
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
- });
35
- }
36
- export type WELL_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema>;
37
- export declare class DecoratedContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema> extends ContractProcedure<TInputSchema, TOutputSchema> {
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;
47
- //# sourceMappingURL=procedure.d.ts.map
@@ -1,16 +0,0 @@
1
- import type { ContractRouter, HandledContractRouter } from './router';
2
- import type { HTTPPath } from './types';
3
- export declare class ContractRouterBuilder {
4
- zz$crb: {
5
- prefix?: HTTPPath;
6
- tags?: string[];
7
- };
8
- constructor(zz$crb: {
9
- prefix?: HTTPPath;
10
- tags?: string[];
11
- });
12
- prefix(prefix: HTTPPath): ContractRouterBuilder;
13
- tags(...tags: string[]): ContractRouterBuilder;
14
- router<T extends ContractRouter>(router: T): HandledContractRouter<T>;
15
- }
16
- //# sourceMappingURL=router-builder.d.ts.map
@@ -1,16 +0,0 @@
1
- import type { SchemaInput, SchemaOutput } from './types';
2
- import { type ContractProcedure, type DecoratedContractProcedure, type WELL_DEFINED_CONTRACT_PROCEDURE } from './procedure';
3
- export interface ContractRouter {
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;
8
- };
9
- export declare function eachContractRouterLeaf(router: ContractRouter, callback: (item: WELL_DEFINED_CONTRACT_PROCEDURE, path: string[]) => void, prefix?: string[]): void;
10
- export type InferContractRouterInputs<T extends ContractRouter> = {
11
- [K in keyof T]: T[K] extends ContractProcedure<infer UInputSchema, any> ? SchemaInput<UInputSchema> : T[K] extends ContractRouter ? InferContractRouterInputs<T[K]> : never;
12
- };
13
- export type InferContractRouterOutputs<T extends ContractRouter> = {
14
- [K in keyof T]: T[K] extends ContractProcedure<any, infer UOutputSchema> ? SchemaOutput<UOutputSchema> : T[K] extends ContractRouter ? InferContractRouterOutputs<T[K]> : never;
15
- };
16
- //# sourceMappingURL=router.d.ts.map
@@ -1,8 +0,0 @@
1
- import type { input, output, ZodType } from 'zod';
2
- export type HTTPPath = `/${string}`;
3
- export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
4
- export type HTTPStatus = number;
5
- export type Schema = ZodType<any, any, any> | undefined;
6
- export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends ZodType<any, any, any> ? input<TSchema> : TFallback;
7
- export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends ZodType<any, any, any> ? output<TSchema> : TFallback;
8
- //# sourceMappingURL=types.d.ts.map
@@ -1,4 +0,0 @@
1
- import type { HTTPPath } from './types';
2
- export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
3
- export declare function prefixHTTPPath(prefix: HTTPPath, path: HTTPPath): HTTPPath;
4
- //# sourceMappingURL=utils.d.ts.map