@orpc/server 0.0.0-next.b45a533 → 0.0.0-next.b47b94e

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 (51) hide show
  1. package/README.md +25 -17
  2. package/dist/adapters/bun-ws/index.d.mts +35 -0
  3. package/dist/adapters/bun-ws/index.d.ts +35 -0
  4. package/dist/adapters/bun-ws/index.mjs +50 -0
  5. package/dist/adapters/crossws/index.d.mts +30 -0
  6. package/dist/adapters/crossws/index.d.ts +30 -0
  7. package/dist/adapters/crossws/index.mjs +50 -0
  8. package/dist/adapters/fetch/index.d.mts +62 -10
  9. package/dist/adapters/fetch/index.d.ts +62 -10
  10. package/dist/adapters/fetch/index.mjs +109 -8
  11. package/dist/adapters/node/index.d.mts +64 -21
  12. package/dist/adapters/node/index.d.ts +64 -21
  13. package/dist/adapters/node/index.mjs +87 -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 +3 -3
  17. package/dist/adapters/websocket/index.d.mts +27 -0
  18. package/dist/adapters/websocket/index.d.ts +27 -0
  19. package/dist/adapters/websocket/index.mjs +37 -0
  20. package/dist/adapters/ws/index.d.mts +28 -0
  21. package/dist/adapters/ws/index.d.ts +28 -0
  22. package/dist/adapters/ws/index.mjs +37 -0
  23. package/dist/index.d.mts +602 -51
  24. package/dist/index.d.ts +602 -51
  25. package/dist/index.mjs +147 -19
  26. package/dist/plugins/index.d.mts +140 -15
  27. package/dist/plugins/index.d.ts +140 -15
  28. package/dist/plugins/index.mjs +162 -14
  29. package/dist/shared/server.BRoxSiSC.d.mts +12 -0
  30. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  31. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  32. package/dist/shared/server.BjiJH9Vo.d.ts +10 -0
  33. package/dist/shared/server.Cy1vfSiG.d.ts +12 -0
  34. package/dist/shared/{server.B_5ZADvP.mjs → server.DG7Tamti.mjs} +26 -22
  35. package/dist/shared/{server.DnmJuN02.d.mts → server.DPWk5pjW.d.mts} +61 -13
  36. package/dist/shared/{server.DnmJuN02.d.ts → server.DPWk5pjW.d.ts} +61 -13
  37. package/dist/shared/server.QUe9N8P4.d.mts +10 -0
  38. package/dist/shared/{server.3mOimouH.mjs → server.SxlTJfG2.mjs} +55 -30
  39. package/dist/shared/server.YZzrREz9.d.ts +74 -0
  40. package/dist/shared/server.eWLxY3lq.d.mts +74 -0
  41. package/package.json +43 -20
  42. package/dist/adapters/hono/index.d.mts +0 -19
  43. package/dist/adapters/hono/index.d.ts +0 -19
  44. package/dist/adapters/hono/index.mjs +0 -32
  45. package/dist/adapters/next/index.d.mts +0 -26
  46. package/dist/adapters/next/index.d.ts +0 -26
  47. package/dist/adapters/next/index.mjs +0 -29
  48. package/dist/shared/server.BgDZnmUZ.mjs +0 -28
  49. package/dist/shared/server.CL84X8p4.d.mts +0 -75
  50. package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
  51. package/dist/shared/server.hqPWnakL.d.ts +0 -75
@@ -1,26 +0,0 @@
1
- import { FetchHandler } from '../fetch/index.js';
2
- export { FetchHandleResult, RPCHandler } from '../fetch/index.js';
3
- import { Value, MaybeOptionalOptions } from '@orpc/shared';
4
- import { NextRequest } from 'next/server';
5
- import { C as Context } from '../../shared/server.DnmJuN02.js';
6
- import { S as StandardHandleOptions } from '../../shared/server.hqPWnakL.js';
7
- import '@orpc/standard-server-fetch';
8
- import '@orpc/client';
9
- import '@orpc/contract';
10
- import '@orpc/standard-server';
11
-
12
- type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
13
- context?: Value<T, [NextRequest]>;
14
- } : {
15
- context: Value<T, [NextRequest]>;
16
- });
17
- interface ServeResult {
18
- GET(req: NextRequest): Promise<Response>;
19
- POST(req: NextRequest): Promise<Response>;
20
- PUT(req: NextRequest): Promise<Response>;
21
- PATCH(req: NextRequest): Promise<Response>;
22
- DELETE(req: NextRequest): Promise<Response>;
23
- }
24
- declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
25
-
26
- export { FetchHandler, type ServeOptions, type ServeResult, serve };
@@ -1,29 +0,0 @@
1
- export { R as RPCHandler } from '../../shared/server.BgDZnmUZ.mjs';
2
- import { value } from '@orpc/shared';
3
- import '@orpc/client/standard';
4
- import '@orpc/standard-server-fetch';
5
- import '../../shared/server.3mOimouH.mjs';
6
- import '@orpc/client';
7
- import '../../shared/server.Q6ZmnTgO.mjs';
8
- import '../../shared/server.B_5ZADvP.mjs';
9
- import '@orpc/contract';
10
-
11
- function serve(handler, ...[options]) {
12
- const main = async (req) => {
13
- const context = await value(options?.context ?? {}, req);
14
- const { matched, response } = await handler.handle(req, { ...options, context });
15
- if (matched) {
16
- return response;
17
- }
18
- return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
19
- };
20
- return {
21
- GET: main,
22
- POST: main,
23
- PUT: main,
24
- PATCH: main,
25
- DELETE: main
26
- };
27
- }
28
-
29
- export { serve };
@@ -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.3mOimouH.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,75 +0,0 @@
1
- import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
3
- 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.DnmJuN02.mjs';
5
- import { ORPCError } from '@orpc/client';
6
-
7
- type StandardParams = Record<string, string>;
8
- type StandardMatchResult = {
9
- path: readonly string[];
10
- procedure: AnyProcedure;
11
- params?: StandardParams;
12
- } | undefined;
13
- interface StandardMatcher {
14
- init(router: AnyRouter): void;
15
- match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
16
- }
17
- interface StandardCodec {
18
- encode(output: unknown, procedure: AnyProcedure): StandardResponse;
19
- encodeError(error: ORPCError<any, any>): StandardResponse;
20
- decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
- }
22
-
23
- type StandardHandleOptions<T extends Context> = {
24
- prefix?: HTTPPath;
25
- } & (Record<never, never> extends T ? {
26
- context?: T;
27
- } : {
28
- context: T;
29
- });
30
- type StandardHandleResult = {
31
- matched: true;
32
- response: StandardResponse;
33
- } | {
34
- matched: false;
35
- response: undefined;
36
- };
37
- type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
38
- context: T;
39
- request: StandardLazyRequest;
40
- };
41
- interface StandardHandlerOptions<TContext extends Context> {
42
- plugins?: HandlerPlugin<TContext>[];
43
- /**
44
- * Interceptors at the request level, helpful when you want catch errors
45
- */
46
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
47
- /**
48
- * Interceptors at the root level, helpful when you want override the request/response
49
- */
50
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
51
- /**
52
- *
53
- * Interceptors for procedure client.
54
- */
55
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
56
- }
57
- declare class StandardHandler<T extends Context> {
58
- private readonly matcher;
59
- private readonly codec;
60
- private readonly options;
61
- private readonly plugin;
62
- 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;
73
- }
74
-
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 };
@@ -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 };
@@ -1,75 +0,0 @@
1
- import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
3
- 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.DnmJuN02.js';
5
- import { ORPCError } from '@orpc/client';
6
-
7
- type StandardParams = Record<string, string>;
8
- type StandardMatchResult = {
9
- path: readonly string[];
10
- procedure: AnyProcedure;
11
- params?: StandardParams;
12
- } | undefined;
13
- interface StandardMatcher {
14
- init(router: AnyRouter): void;
15
- match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
16
- }
17
- interface StandardCodec {
18
- encode(output: unknown, procedure: AnyProcedure): StandardResponse;
19
- encodeError(error: ORPCError<any, any>): StandardResponse;
20
- decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
- }
22
-
23
- type StandardHandleOptions<T extends Context> = {
24
- prefix?: HTTPPath;
25
- } & (Record<never, never> extends T ? {
26
- context?: T;
27
- } : {
28
- context: T;
29
- });
30
- type StandardHandleResult = {
31
- matched: true;
32
- response: StandardResponse;
33
- } | {
34
- matched: false;
35
- response: undefined;
36
- };
37
- type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
38
- context: T;
39
- request: StandardLazyRequest;
40
- };
41
- interface StandardHandlerOptions<TContext extends Context> {
42
- plugins?: HandlerPlugin<TContext>[];
43
- /**
44
- * Interceptors at the request level, helpful when you want catch errors
45
- */
46
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
47
- /**
48
- * Interceptors at the root level, helpful when you want override the request/response
49
- */
50
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
51
- /**
52
- *
53
- * Interceptors for procedure client.
54
- */
55
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
56
- }
57
- declare class StandardHandler<T extends Context> {
58
- private readonly matcher;
59
- private readonly codec;
60
- private readonly options;
61
- private readonly plugin;
62
- 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;
73
- }
74
-
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 };