@orpc/nest 1.11.3 → 1.12.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.
- package/dist/index.d.mts +38 -9
- package/dist/index.d.ts +38 -9
- package/dist/index.mjs +46 -38
- package/package.json +15 -15
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
import { DynamicModule, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
1
|
import { AnySchema, ContractRouter, HTTPPath, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
|
3
|
-
import { CreateProcedureClientOptions, Router } from '@orpc/server';
|
|
4
|
-
export { ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ORPCError, ProcedureImplementer, RouterImplementer, RouterImplementerWithMiddlewares,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { CreateProcedureClientOptions, Router, Context, BuilderConfig, Implementer } from '@orpc/server';
|
|
3
|
+
export { ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ORPCError, ProcedureImplementer, RouterImplementer, RouterImplementerWithMiddlewares, onError, onFinish, onStart, onSuccess } from '@orpc/server';
|
|
4
|
+
import { DynamicModule, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
5
|
+
import { StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions } from '@orpc/openapi-client/standard';
|
|
6
|
+
import { StandardOpenAPICodecOptions } from '@orpc/openapi/standard';
|
|
7
|
+
import { StandardHandlerOptions } from '@orpc/server/standard';
|
|
8
|
+
import { Interceptor, Promisable } from '@orpc/shared';
|
|
9
|
+
import { StandardResponse } from '@orpc/standard-server';
|
|
7
10
|
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
|
11
|
+
import { Observable } from 'rxjs';
|
|
8
12
|
|
|
9
13
|
declare const ORPC_MODULE_CONFIG_SYMBOL: unique symbol;
|
|
10
|
-
|
|
14
|
+
/**
|
|
15
|
+
* You can extend this interface to add global context properties.
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* declare module '@orpc/nest' {
|
|
19
|
+
* interface ORPCGlobalContext {
|
|
20
|
+
* user: { id: string; name: string }
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
interface ORPCGlobalContext {
|
|
26
|
+
}
|
|
27
|
+
interface ORPCModuleConfig extends CreateProcedureClientOptions<ORPCGlobalContext, AnySchema, object, object, object>, SendStandardResponseOptions, StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions, StandardOpenAPICodecOptions {
|
|
28
|
+
plugins?: StandardHandlerOptions<ORPCGlobalContext>['plugins'];
|
|
29
|
+
sendResponseInterceptors?: Interceptor<{
|
|
30
|
+
request: any;
|
|
31
|
+
response: any;
|
|
32
|
+
standardResponse: StandardResponse;
|
|
33
|
+
}, unknown>[];
|
|
11
34
|
}
|
|
12
35
|
declare class ORPCModule {
|
|
13
36
|
static forRoot(config: ORPCModuleConfig): DynamicModule;
|
|
@@ -23,9 +46,10 @@ declare class ORPCModule {
|
|
|
23
46
|
*
|
|
24
47
|
* @see {@link https://orpc.unnoq.com/docs/openapi/integrations/implement-contract-in-nest#implement-your-contract NestJS Implement Contract Docs}
|
|
25
48
|
*/
|
|
26
|
-
declare function Implement<T extends ContractRouter<any>>(contract: T): <U extends Promisable<Router<T,
|
|
49
|
+
declare function Implement<T extends ContractRouter<any>>(contract: T): <U extends Promisable<Router<T, ORPCGlobalContext>>>(target: Record<PropertyKey, any>, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => U>) => void;
|
|
27
50
|
declare class ImplementInterceptor implements NestInterceptor {
|
|
28
51
|
private readonly config;
|
|
52
|
+
private readonly codec;
|
|
29
53
|
constructor(config: ORPCModuleConfig | undefined);
|
|
30
54
|
intercept(ctx: ExecutionContext, next: CallHandler<any>): Observable<any>;
|
|
31
55
|
}
|
|
@@ -47,5 +71,10 @@ interface PopulateContractRouterPathsOptions {
|
|
|
47
71
|
*/
|
|
48
72
|
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
|
49
73
|
|
|
50
|
-
|
|
51
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Alias for `implement` from `@orpc/server` with default context set to `ORPCGlobalContext`
|
|
76
|
+
*/
|
|
77
|
+
declare function implement<T extends AnyContractRouter, TContext extends Context = ORPCGlobalContext>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
|
|
78
|
+
|
|
79
|
+
export { Implement as Impl, Implement, ImplementInterceptor, ORPCModule, ORPC_MODULE_CONFIG_SYMBOL, implement, populateContractRouterPaths, toNestPattern };
|
|
80
|
+
export type { ORPCGlobalContext, ORPCModuleConfig, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
import { DynamicModule, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
1
|
import { AnySchema, ContractRouter, HTTPPath, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
|
3
|
-
import { CreateProcedureClientOptions, Router } from '@orpc/server';
|
|
4
|
-
export { ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ORPCError, ProcedureImplementer, RouterImplementer, RouterImplementerWithMiddlewares,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { CreateProcedureClientOptions, Router, Context, BuilderConfig, Implementer } from '@orpc/server';
|
|
3
|
+
export { ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ORPCError, ProcedureImplementer, RouterImplementer, RouterImplementerWithMiddlewares, onError, onFinish, onStart, onSuccess } from '@orpc/server';
|
|
4
|
+
import { DynamicModule, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
5
|
+
import { StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions } from '@orpc/openapi-client/standard';
|
|
6
|
+
import { StandardOpenAPICodecOptions } from '@orpc/openapi/standard';
|
|
7
|
+
import { StandardHandlerOptions } from '@orpc/server/standard';
|
|
8
|
+
import { Interceptor, Promisable } from '@orpc/shared';
|
|
9
|
+
import { StandardResponse } from '@orpc/standard-server';
|
|
7
10
|
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
|
11
|
+
import { Observable } from 'rxjs';
|
|
8
12
|
|
|
9
13
|
declare const ORPC_MODULE_CONFIG_SYMBOL: unique symbol;
|
|
10
|
-
|
|
14
|
+
/**
|
|
15
|
+
* You can extend this interface to add global context properties.
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* declare module '@orpc/nest' {
|
|
19
|
+
* interface ORPCGlobalContext {
|
|
20
|
+
* user: { id: string; name: string }
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
interface ORPCGlobalContext {
|
|
26
|
+
}
|
|
27
|
+
interface ORPCModuleConfig extends CreateProcedureClientOptions<ORPCGlobalContext, AnySchema, object, object, object>, SendStandardResponseOptions, StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions, StandardOpenAPICodecOptions {
|
|
28
|
+
plugins?: StandardHandlerOptions<ORPCGlobalContext>['plugins'];
|
|
29
|
+
sendResponseInterceptors?: Interceptor<{
|
|
30
|
+
request: any;
|
|
31
|
+
response: any;
|
|
32
|
+
standardResponse: StandardResponse;
|
|
33
|
+
}, unknown>[];
|
|
11
34
|
}
|
|
12
35
|
declare class ORPCModule {
|
|
13
36
|
static forRoot(config: ORPCModuleConfig): DynamicModule;
|
|
@@ -23,9 +46,10 @@ declare class ORPCModule {
|
|
|
23
46
|
*
|
|
24
47
|
* @see {@link https://orpc.unnoq.com/docs/openapi/integrations/implement-contract-in-nest#implement-your-contract NestJS Implement Contract Docs}
|
|
25
48
|
*/
|
|
26
|
-
declare function Implement<T extends ContractRouter<any>>(contract: T): <U extends Promisable<Router<T,
|
|
49
|
+
declare function Implement<T extends ContractRouter<any>>(contract: T): <U extends Promisable<Router<T, ORPCGlobalContext>>>(target: Record<PropertyKey, any>, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => U>) => void;
|
|
27
50
|
declare class ImplementInterceptor implements NestInterceptor {
|
|
28
51
|
private readonly config;
|
|
52
|
+
private readonly codec;
|
|
29
53
|
constructor(config: ORPCModuleConfig | undefined);
|
|
30
54
|
intercept(ctx: ExecutionContext, next: CallHandler<any>): Observable<any>;
|
|
31
55
|
}
|
|
@@ -47,5 +71,10 @@ interface PopulateContractRouterPathsOptions {
|
|
|
47
71
|
*/
|
|
48
72
|
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
|
49
73
|
|
|
50
|
-
|
|
51
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Alias for `implement` from `@orpc/server` with default context set to `ORPCGlobalContext`
|
|
76
|
+
*/
|
|
77
|
+
declare function implement<T extends AnyContractRouter, TContext extends Context = ORPCGlobalContext>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
|
|
78
|
+
|
|
79
|
+
export { Implement as Impl, Implement, ImplementInterceptor, ORPCModule, ORPC_MODULE_CONFIG_SYMBOL, implement, populateContractRouterPaths, toNestPattern };
|
|
80
|
+
export type { ORPCGlobalContext, ORPCModuleConfig, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { getRouter, unlazy, isProcedure, implement as implement$1 } from '@orpc/server';
|
|
2
|
+
export { ORPCError, onError, onFinish, onStart, onSuccess } from '@orpc/server';
|
|
3
|
+
import { Module, Injectable, Inject, Optional, applyDecorators, Delete, Patch, Put, Post, Get, Head, HttpCode, UseInterceptors } from '@nestjs/common';
|
|
3
4
|
import { isContractProcedure, ContractProcedure, fallbackContractConfig } from '@orpc/contract';
|
|
4
5
|
import { standardizeHTTPPath, StandardOpenAPISerializer, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer } from '@orpc/openapi-client/standard';
|
|
5
6
|
import { StandardOpenAPICodec } from '@orpc/openapi/standard';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { toArray, get } from '@orpc/shared';
|
|
9
|
-
import { flattenHeader } from '@orpc/standard-server';
|
|
7
|
+
import { StandardHandler } from '@orpc/server/standard';
|
|
8
|
+
import { toArray, get, intercept } from '@orpc/shared';
|
|
10
9
|
import * as StandardServerFastify from '@orpc/standard-server-fastify';
|
|
11
10
|
import * as StandardServerNode from '@orpc/standard-server-node';
|
|
12
11
|
import { mergeMap } from 'rxjs';
|
|
@@ -112,6 +111,7 @@ function Implement(contract) {
|
|
|
112
111
|
return (target, propertyKey, descriptor) => {
|
|
113
112
|
applyDecorators(
|
|
114
113
|
MethodDecoratorMap[method](toNestPattern(path)),
|
|
114
|
+
HttpCode(fallbackContractConfig("defaultSuccessStatus", contract["~orpc"].route.successStatus)),
|
|
115
115
|
UseInterceptors(ImplementInterceptor)
|
|
116
116
|
)(target, propertyKey, descriptor);
|
|
117
117
|
};
|
|
@@ -137,15 +137,18 @@ function Implement(contract) {
|
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
-
const codec = new StandardOpenAPICodec(
|
|
141
|
-
new StandardOpenAPISerializer(
|
|
142
|
-
new StandardOpenAPIJsonSerializer(),
|
|
143
|
-
new StandardBracketNotationSerializer()
|
|
144
|
-
)
|
|
145
|
-
);
|
|
146
140
|
let ImplementInterceptor = class {
|
|
141
|
+
config;
|
|
142
|
+
codec;
|
|
147
143
|
constructor(config) {
|
|
148
|
-
this.config = config;
|
|
144
|
+
this.config = config ?? {};
|
|
145
|
+
this.codec = new StandardOpenAPICodec(
|
|
146
|
+
new StandardOpenAPISerializer(
|
|
147
|
+
new StandardOpenAPIJsonSerializer(this.config),
|
|
148
|
+
new StandardBracketNotationSerializer(this.config)
|
|
149
|
+
),
|
|
150
|
+
this.config
|
|
151
|
+
);
|
|
149
152
|
}
|
|
150
153
|
intercept(ctx, next) {
|
|
151
154
|
return next.handle().pipe(
|
|
@@ -159,30 +162,31 @@ let ImplementInterceptor = class {
|
|
|
159
162
|
const req = ctx.switchToHttp().getRequest();
|
|
160
163
|
const res = ctx.switchToHttp().getResponse();
|
|
161
164
|
const standardRequest = "raw" in req ? StandardServerFastify.toStandardLazyRequest(req, res) : StandardServerNode.toStandardLazyRequest(req, res);
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
165
|
+
const handler = new StandardHandler(procedure, {
|
|
166
|
+
init: () => {
|
|
167
|
+
},
|
|
168
|
+
match: () => Promise.resolve({ path: toArray(this.config.path), procedure, params: flattenParams(req.params) })
|
|
169
|
+
}, this.codec, {
|
|
170
|
+
// Since plugins can modify options directly, so we need to clone to avoid affecting other handlers/requests
|
|
171
|
+
// TODO: improve plugins system to avoid this cloning
|
|
172
|
+
clientInterceptors: [...toArray(this.config.interceptors)],
|
|
173
|
+
plugins: [...toArray(this.config.plugins)]
|
|
174
|
+
});
|
|
175
|
+
const result = await handler.handle(standardRequest, {
|
|
176
|
+
context: this.config.context
|
|
177
|
+
});
|
|
178
|
+
if (result.matched) {
|
|
179
|
+
return intercept(
|
|
180
|
+
toArray(this.config.sendResponseInterceptors),
|
|
181
|
+
{ request: req, response: res, standardResponse: result.response },
|
|
182
|
+
async ({ response, standardResponse }) => {
|
|
183
|
+
if ("raw" in response) {
|
|
184
|
+
await StandardServerFastify.sendStandardResponse(response, standardResponse, this.config);
|
|
185
|
+
} else {
|
|
186
|
+
await StandardServerNode.sendStandardResponse(response, standardResponse, this.config);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
);
|
|
186
190
|
}
|
|
187
191
|
})
|
|
188
192
|
);
|
|
@@ -205,4 +209,8 @@ function flattenParams(params) {
|
|
|
205
209
|
return flatten;
|
|
206
210
|
}
|
|
207
211
|
|
|
208
|
-
|
|
212
|
+
function implement(contract, config = {}) {
|
|
213
|
+
return implement$1(contract, config);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export { Implement as Impl, Implement, ImplementInterceptor, ORPCModule, ORPC_MODULE_CONFIG_SYMBOL, implement, populateContractRouterPaths, toNestPattern };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/nest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.12.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -39,23 +39,23 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@orpc/
|
|
43
|
-
"@orpc/
|
|
44
|
-
"@orpc/openapi": "1.
|
|
45
|
-
"@orpc/
|
|
46
|
-
"@orpc/
|
|
47
|
-
"@orpc/
|
|
48
|
-
"@orpc/standard-server": "1.
|
|
49
|
-
"@orpc/standard-server-fastify": "1.
|
|
50
|
-
"@orpc/standard-server-node": "1.
|
|
42
|
+
"@orpc/contract": "1.12.0",
|
|
43
|
+
"@orpc/client": "1.12.0",
|
|
44
|
+
"@orpc/openapi": "1.12.0",
|
|
45
|
+
"@orpc/shared": "1.12.0",
|
|
46
|
+
"@orpc/openapi-client": "1.12.0",
|
|
47
|
+
"@orpc/server": "1.12.0",
|
|
48
|
+
"@orpc/standard-server": "1.12.0",
|
|
49
|
+
"@orpc/standard-server-fastify": "1.12.0",
|
|
50
|
+
"@orpc/standard-server-node": "1.12.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@fastify/cookie": "^11.0.2",
|
|
54
|
-
"@nestjs/common": "^11.1.
|
|
55
|
-
"@nestjs/core": "^11.1.
|
|
56
|
-
"@nestjs/platform-express": "^11.1.
|
|
57
|
-
"@nestjs/platform-fastify": "^11.1.
|
|
58
|
-
"@nestjs/testing": "^11.1.
|
|
54
|
+
"@nestjs/common": "^11.1.9",
|
|
55
|
+
"@nestjs/core": "^11.1.9",
|
|
56
|
+
"@nestjs/platform-express": "^11.1.9",
|
|
57
|
+
"@nestjs/platform-fastify": "^11.1.9",
|
|
58
|
+
"@nestjs/testing": "^11.1.9",
|
|
59
59
|
"@ts-rest/core": "^3.52.1",
|
|
60
60
|
"@types/express": "^5.0.5",
|
|
61
61
|
"express": "^5.0.0",
|