@orpc/server 0.0.0-next.a5c2886 → 0.0.0-next.a6dec3e

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.
Files changed (38) hide show
  1. package/README.md +11 -0
  2. package/dist/adapters/fetch/index.d.mts +42 -10
  3. package/dist/adapters/fetch/index.d.ts +42 -10
  4. package/dist/adapters/fetch/index.mjs +8 -6
  5. package/dist/adapters/hono/index.d.mts +7 -4
  6. package/dist/adapters/hono/index.d.ts +7 -4
  7. package/dist/adapters/hono/index.mjs +12 -9
  8. package/dist/adapters/next/index.d.mts +7 -4
  9. package/dist/adapters/next/index.d.ts +7 -4
  10. package/dist/adapters/next/index.mjs +12 -9
  11. package/dist/adapters/node/index.d.mts +44 -21
  12. package/dist/adapters/node/index.d.ts +44 -21
  13. package/dist/adapters/node/index.mjs +82 -23
  14. package/dist/adapters/standard/index.d.mts +11 -10
  15. package/dist/adapters/standard/index.d.ts +11 -10
  16. package/dist/adapters/standard/index.mjs +6 -4
  17. package/dist/index.d.mts +83 -61
  18. package/dist/index.d.ts +83 -61
  19. package/dist/index.mjs +50 -30
  20. package/dist/plugins/index.d.mts +108 -15
  21. package/dist/plugins/index.d.ts +108 -15
  22. package/dist/plugins/index.mjs +147 -6
  23. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  24. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  25. package/dist/shared/server.Bm0UqHzd.mjs +103 -0
  26. package/dist/shared/{server.CMrS28Go.mjs → server.C37gDhSZ.mjs} +42 -24
  27. package/dist/shared/server.C8NkqxHo.d.ts +17 -0
  28. package/dist/shared/server.CGCwEAt_.d.mts +10 -0
  29. package/dist/shared/server.DCQgF_JR.d.mts +17 -0
  30. package/dist/shared/{server.CM3tWr3C.d.mts → server.DFFT_EZo.d.ts} +27 -29
  31. package/dist/shared/{server.CSZRzcSW.mjs → server.DFuJLDuo.mjs} +62 -30
  32. package/dist/shared/{server.CPteJIPP.d.mts → server.DLt5njUb.d.mts} +19 -19
  33. package/dist/shared/{server.CPteJIPP.d.ts → server.DLt5njUb.d.ts} +19 -19
  34. package/dist/shared/{server.DmW25ynm.d.ts → server.DOYDVeMX.d.mts} +27 -29
  35. package/dist/shared/server._2UufoXA.d.ts +10 -0
  36. package/package.json +8 -8
  37. package/dist/shared/server.Cq3B6PoL.mjs +0 -28
  38. package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
@@ -1,8 +1,8 @@
1
- import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
1
+ import { HTTPPath, ORPCError } from '@orpc/client';
2
+ import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
+ import { Interceptor, ThrowableError } from '@orpc/shared';
3
4
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
4
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.CPteJIPP.js';
5
- import { ORPCError } from '@orpc/client';
5
+ import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.mjs';
6
6
 
7
7
  type StandardParams = Record<string, string>;
8
8
  type StandardMatchResult = {
@@ -20,13 +20,20 @@ interface StandardCodec {
20
20
  decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
21
  }
22
22
 
23
- type StandardHandleOptions<T extends Context> = {
23
+ interface StandardHandlerPlugin<TContext extends Context> {
24
+ order?: number;
25
+ init?(options: StandardHandlerOptions<TContext>): void;
26
+ }
27
+ declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
28
+ protected readonly plugins: TPlugin[];
29
+ constructor(plugins?: readonly TPlugin[]);
30
+ init(options: StandardHandlerOptions<T>): void;
31
+ }
32
+
33
+ interface StandardHandleOptions<T extends Context> {
24
34
  prefix?: HTTPPath;
25
- } & (Record<never, never> extends T ? {
26
- context?: T;
27
- } : {
28
35
  context: T;
29
- });
36
+ }
30
37
  type StandardHandleResult = {
31
38
  matched: true;
32
39
  response: StandardResponse;
@@ -34,42 +41,33 @@ type StandardHandleResult = {
34
41
  matched: false;
35
42
  response: undefined;
36
43
  };
37
- type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
38
- context: T;
44
+ interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
39
45
  request: StandardLazyRequest;
40
- };
46
+ }
41
47
  interface StandardHandlerOptions<TContext extends Context> {
42
- plugins?: HandlerPlugin<TContext>[];
48
+ plugins?: StandardHandlerPlugin<TContext>[];
43
49
  /**
44
50
  * Interceptors at the request level, helpful when you want catch errors
45
51
  */
46
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
52
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
47
53
  /**
48
54
  * Interceptors at the root level, helpful when you want override the request/response
49
55
  */
50
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
56
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
51
57
  /**
52
58
  *
53
59
  * Interceptors for procedure client.
54
60
  */
55
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
61
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
56
62
  }
57
63
  declare class StandardHandler<T extends Context> {
58
64
  private readonly matcher;
59
65
  private readonly codec;
60
- private readonly options;
61
- private readonly plugin;
66
+ private readonly interceptors;
67
+ private readonly clientInterceptors;
68
+ private readonly rootInterceptors;
62
69
  constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
63
- handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
64
- }
65
-
66
- interface HandlerPlugin<TContext extends Context> {
67
- init?(options: StandardHandlerOptions<TContext>): void;
68
- }
69
- declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
70
- private readonly plugins;
71
- constructor(plugins?: HandlerPlugin<TContext>[]);
72
- init(options: StandardHandlerOptions<TContext>): void;
70
+ handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
73
71
  }
74
72
 
75
- export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerInterceptorOptions as a, type StandardHandlerOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
73
+ export { CompositeStandardHandlerPlugin as C, type StandardHandleOptions as S, type StandardHandlerOptions as a, StandardHandler as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, type StandardHandlerInterceptorOptions as h, type StandardHandlerPlugin as i };
@@ -0,0 +1,10 @@
1
+ import { C as Context } from './server.DLt5njUb.js';
2
+ import { S as StandardHandleOptions } from './server.DFFT_EZo.js';
3
+
4
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
+ context?: T;
6
+ } : {
7
+ context: T;
8
+ });
9
+
10
+ export type { FriendlyStandardHandleOptions as F };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.a5c2886",
4
+ "version": "0.0.0-next.a6dec3e",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -58,15 +58,15 @@
58
58
  "next": ">=14.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@orpc/client": "0.0.0-next.a5c2886",
62
- "@orpc/contract": "0.0.0-next.a5c2886",
63
- "@orpc/shared": "0.0.0-next.a5c2886",
64
- "@orpc/standard-server-fetch": "0.0.0-next.a5c2886",
65
- "@orpc/standard-server-node": "0.0.0-next.a5c2886",
66
- "@orpc/standard-server": "0.0.0-next.a5c2886"
61
+ "@orpc/client": "0.0.0-next.a6dec3e",
62
+ "@orpc/shared": "0.0.0-next.a6dec3e",
63
+ "@orpc/standard-server": "0.0.0-next.a6dec3e",
64
+ "@orpc/standard-server-fetch": "0.0.0-next.a6dec3e",
65
+ "@orpc/contract": "0.0.0-next.a6dec3e",
66
+ "@orpc/standard-server-node": "0.0.0-next.a6dec3e"
67
67
  },
68
68
  "devDependencies": {
69
- "light-my-request": "^6.5.1"
69
+ "supertest": "^7.0.0"
70
70
  },
71
71
  "scripts": {
72
72
  "build": "unbuild",
@@ -1,28 +0,0 @@
1
- import { RPCSerializer } from '@orpc/client/standard';
2
- import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
3
- import { S as StandardHandler, a as RPCMatcher, R as RPCCodec } from './server.CSZRzcSW.mjs';
4
-
5
- class RPCHandler {
6
- standardHandler;
7
- constructor(router, options = {}) {
8
- const serializer = new RPCSerializer();
9
- const matcher = new RPCMatcher();
10
- const codec = new RPCCodec(serializer);
11
- this.standardHandler = new StandardHandler(router, matcher, codec, options);
12
- }
13
- async handle(request, ...[
14
- options = {}
15
- ]) {
16
- const standardRequest = toStandardLazyRequest(request);
17
- const result = await this.standardHandler.handle(standardRequest, options);
18
- if (!result.matched) {
19
- return result;
20
- }
21
- return {
22
- matched: true,
23
- response: toFetchResponse(result.response, options)
24
- };
25
- }
26
- }
27
-
28
- export { RPCHandler as R };
@@ -1,12 +0,0 @@
1
- class CompositePlugin {
2
- constructor(plugins = []) {
3
- this.plugins = plugins;
4
- }
5
- init(options) {
6
- for (const plugin of this.plugins) {
7
- plugin.init?.(options);
8
- }
9
- }
10
- }
11
-
12
- export { CompositePlugin as C };