@orpc/server 1.0.0-beta.7 → 1.1.0

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.
@@ -28,6 +28,9 @@ interface Lazy<T> {
28
28
  };
29
29
  }
30
30
  type Lazyable<T> = T | Lazy<T>;
31
+ /**
32
+ * Create a lazy thing.
33
+ */
31
34
  declare function lazy<T>(loader: () => Promise<{
32
35
  default: T;
33
36
  }>, meta?: LazyMeta): Lazy<T>;
@@ -56,7 +59,15 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
56
59
  outputValidationIndex: number;
57
60
  handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
58
61
  }
62
+ /**
63
+ * This class represents a procedure.
64
+ *
65
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
66
+ */
59
67
  declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
68
+ /**
69
+ * This property holds the defined options.
70
+ */
60
71
  '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
61
72
  constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
62
73
  }
@@ -87,6 +98,11 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
87
98
  next: MiddlewareNextFn<TOutput>;
88
99
  errors: TErrorConstructorMap;
89
100
  }
101
+ /**
102
+ * A function that represents a middleware.
103
+ *
104
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
105
+ */
90
106
  interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
91
107
  (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
92
108
  }
@@ -106,9 +122,6 @@ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TEr
106
122
  signal?: AbortSignal;
107
123
  lastEventId: string | undefined;
108
124
  }
109
- /**
110
- * Options for creating a procedure caller with comprehensive type safety
111
- */
112
125
  type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
113
126
  /**
114
127
  * This is helpful for logging and analytics.
@@ -120,22 +133,57 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
120
133
  } : {
121
134
  context: Value<TInitialContext, [clientContext: TClientContext]>;
122
135
  });
136
+ /**
137
+ * Create Server-side client from a procedure.
138
+ *
139
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
140
+ */
123
141
  declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
124
142
 
143
+ /**
144
+ * Represents a router, which defines a hierarchical structure of procedures.
145
+ *
146
+ * @info A procedure is a router too.
147
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
148
+ */
125
149
  type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
126
150
  [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
127
151
  };
128
152
  type AnyRouter = Router<any, any>;
129
153
  type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
154
+ /**
155
+ * Infer all initial context of the router.
156
+ *
157
+ * @info A procedure is a router too.
158
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
159
+ */
130
160
  type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
131
161
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
132
162
  };
163
+ /**
164
+ * Infer all current context of the router.
165
+ *
166
+ * @info A procedure is a router too.
167
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
168
+ */
133
169
  type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
134
170
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
135
171
  };
172
+ /**
173
+ * Infer all router inputs
174
+ *
175
+ * @info A procedure is a router too.
176
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
177
+ */
136
178
  type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
137
179
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
138
180
  };
181
+ /**
182
+ * Infer all router outputs
183
+ *
184
+ * @info A procedure is a router too.
185
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
186
+ */
139
187
  type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
140
188
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
189
  };
@@ -1,5 +1,5 @@
1
- import { C as Context } from './server.BVHsfJ99.mjs';
2
- import { g as StandardHandleOptions } from './server.B1oIHH_j.mjs';
1
+ import { C as Context } from './server.DPWk5pjW.mjs';
2
+ import { g as StandardHandleOptions } from './server.eWLxY3lq.mjs';
3
3
 
4
4
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
5
  context?: T;
@@ -2,16 +2,16 @@ import { HTTPPath, ORPCError } from '@orpc/client';
2
2
  import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
3
  import { Interceptor, ThrowableError } from '@orpc/shared';
4
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
- import { C as Context, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions, R as Router } from './server.BVHsfJ99.mjs';
5
+ import { C as Context, R as Router, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions } from './server.DPWk5pjW.js';
6
6
 
7
- interface StandardHandlerPlugin<TContext extends Context> {
7
+ interface StandardHandlerPlugin<T extends Context> {
8
8
  order?: number;
9
- init?(options: StandardHandlerOptions<TContext>): void;
9
+ init?(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
10
10
  }
11
11
  declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
12
12
  protected readonly plugins: TPlugin[];
13
13
  constructor(plugins?: readonly TPlugin[]);
14
- init(options: StandardHandlerOptions<T>): void;
14
+ init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
15
15
  }
16
16
 
17
17
  type StandardParams = Record<string, string>;
@@ -2,16 +2,16 @@ import { HTTPPath, ORPCError } from '@orpc/client';
2
2
  import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
3
  import { Interceptor, ThrowableError } from '@orpc/shared';
4
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
- import { C as Context, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions, R as Router } from './server.BVHsfJ99.js';
5
+ import { C as Context, R as Router, f as AnyRouter, h as AnyProcedure, F as ProcedureClientInterceptorOptions } from './server.DPWk5pjW.mjs';
6
6
 
7
- interface StandardHandlerPlugin<TContext extends Context> {
7
+ interface StandardHandlerPlugin<T extends Context> {
8
8
  order?: number;
9
- init?(options: StandardHandlerOptions<TContext>): void;
9
+ init?(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
10
10
  }
11
11
  declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
12
12
  protected readonly plugins: TPlugin[];
13
13
  constructor(plugins?: readonly TPlugin[]);
14
- init(options: StandardHandlerOptions<T>): void;
14
+ init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
15
15
  }
16
16
 
17
17
  type StandardParams = Record<string, string>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.7",
4
+ "version": "1.1.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -44,12 +44,12 @@
44
44
  "dist"
45
45
  ],
46
46
  "dependencies": {
47
- "@orpc/client": "1.0.0-beta.7",
48
- "@orpc/contract": "1.0.0-beta.7",
49
- "@orpc/standard-server-node": "1.0.0-beta.7",
50
- "@orpc/standard-server-fetch": "1.0.0-beta.7",
51
- "@orpc/shared": "1.0.0-beta.7",
52
- "@orpc/standard-server": "1.0.0-beta.7"
47
+ "@orpc/client": "1.1.0",
48
+ "@orpc/standard-server-fetch": "1.1.0",
49
+ "@orpc/standard-server": "1.1.0",
50
+ "@orpc/standard-server-node": "1.1.0",
51
+ "@orpc/contract": "1.1.0",
52
+ "@orpc/shared": "1.1.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "supertest": "^7.1.0"