@orpc/contract 0.0.0-next.57a6344 → 0.0.0-next.5d3da98

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 CHANGED
@@ -7,7 +7,10 @@ var ContractProcedure = class {
7
7
  }
8
8
  };
9
9
  function isContractProcedure(item) {
10
- return item instanceof ContractProcedure;
10
+ if (item instanceof ContractProcedure) {
11
+ return true;
12
+ }
13
+ 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"];
11
14
  }
12
15
 
13
16
  // src/procedure-decorated.ts
@@ -35,12 +38,15 @@ var DecoratedContractProcedure = class _DecoratedContractProcedure extends Contr
35
38
  } : void 0
36
39
  });
37
40
  }
38
- pushTag(...tags) {
41
+ unshiftTag(...tags) {
39
42
  return new _DecoratedContractProcedure({
40
43
  ...this["~orpc"],
41
44
  route: {
42
45
  ...this["~orpc"].route,
43
- tags: [...this["~orpc"].route?.tags ?? [], ...tags]
46
+ tags: [
47
+ ...tags,
48
+ ...this["~orpc"].route?.tags?.filter((tag) => !tags.includes(tag)) ?? []
49
+ ]
44
50
  }
45
51
  });
46
52
  }
@@ -80,21 +86,19 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
80
86
  });
81
87
  }
82
88
  router(router) {
89
+ if (isContractProcedure(router)) {
90
+ let decorated = DecoratedContractProcedure.decorate(router);
91
+ if (this["~orpc"].tags) {
92
+ decorated = decorated.unshiftTag(...this["~orpc"].tags);
93
+ }
94
+ if (this["~orpc"].prefix) {
95
+ decorated = decorated.prefix(this["~orpc"].prefix);
96
+ }
97
+ return decorated;
98
+ }
83
99
  const adapted = {};
84
100
  for (const key in router) {
85
- const item = router[key];
86
- if (isContractProcedure(item)) {
87
- let decorated = DecoratedContractProcedure.decorate(item);
88
- if (this["~orpc"].tags) {
89
- decorated = decorated.pushTag(...this["~orpc"].tags);
90
- }
91
- if (this["~orpc"].prefix) {
92
- decorated = decorated.prefix(this["~orpc"].prefix);
93
- }
94
- adapted[key] = decorated;
95
- } else {
96
- adapted[key] = this.router(item);
97
- }
101
+ adapted[key] = this.router(router[key]);
98
102
  }
99
103
  return adapted;
100
104
  }
@@ -7,8 +7,8 @@ export declare class ContractBuilder {
7
7
  prefix(prefix: HTTPPath): ContractRouterBuilder;
8
8
  tag(...tags: string[]): ContractRouterBuilder;
9
9
  route(route: RouteOptions): DecoratedContractProcedure<undefined, undefined>;
10
- input<U extends Schema>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, undefined>;
11
- output<U extends Schema>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<undefined, U>;
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>;
12
12
  router<T extends ContractRouter>(router: T): T;
13
13
  }
14
14
  //# sourceMappingURL=builder.d.ts.map
@@ -5,7 +5,7 @@ export declare class DecoratedContractProcedure<TInputSchema extends Schema, TOu
5
5
  static decorate<UInputSchema extends Schema = undefined, UOutputSchema extends Schema = undefined>(procedure: ContractProcedure<UInputSchema, UOutputSchema>): DecoratedContractProcedure<UInputSchema, UOutputSchema>;
6
6
  route(route: RouteOptions): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
7
7
  prefix(prefix: HTTPPath): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
8
- pushTag(...tags: string[]): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
8
+ unshiftTag(...tags: string[]): DecoratedContractProcedure<TInputSchema, TOutputSchema>;
9
9
  input<U extends Schema = undefined>(schema: U, example?: SchemaInput<U>): DecoratedContractProcedure<U, TOutputSchema>;
10
10
  output<U extends Schema = undefined>(schema: U, example?: SchemaOutput<U>): DecoratedContractProcedure<TInputSchema, U>;
11
11
  }
@@ -5,7 +5,7 @@ export interface RouteOptions {
5
5
  summary?: string;
6
6
  description?: string;
7
7
  deprecated?: boolean;
8
- tags?: string[];
8
+ tags?: readonly string[];
9
9
  }
10
10
  export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema> {
11
11
  route?: RouteOptions;
@@ -1,12 +1,12 @@
1
1
  import type { ANY_CONTRACT_PROCEDURE, ContractProcedure } from './procedure';
2
2
  import type { SchemaInput, SchemaOutput } from './types';
3
- export interface ContractRouter {
4
- [k: string]: ANY_CONTRACT_PROCEDURE | ContractRouter;
5
- }
6
- export type InferContractRouterInputs<T extends ContractRouter> = {
7
- [K in keyof T]: T[K] extends ContractProcedure<infer UInputSchema, any> ? SchemaInput<UInputSchema> : T[K] extends ContractRouter ? InferContractRouterInputs<T[K]> : never;
3
+ export type ContractRouter = ANY_CONTRACT_PROCEDURE | {
4
+ [k: string]: ContractRouter;
8
5
  };
9
- export type InferContractRouterOutputs<T extends ContractRouter> = {
10
- [K in keyof T]: T[K] extends ContractProcedure<any, infer UOutputSchema> ? SchemaOutput<UOutputSchema> : T[K] extends ContractRouter ? InferContractRouterOutputs<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;
8
+ };
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;
11
11
  };
12
12
  //# sourceMappingURL=router.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.57a6344",
4
+ "version": "0.0.0-next.5d3da98",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "@standard-schema/spec": "1.0.0-beta.4",
33
- "@orpc/shared": "0.0.0-next.57a6344"
33
+ "@orpc/shared": "0.0.0-next.5d3da98"
34
34
  },
35
35
  "devDependencies": {
36
36
  "arktype": "2.0.0-rc.26",