@orpc/nest 1.5.2 → 1.6.1
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/README.md +1 -1
- package/dist/index.d.mts +16 -6
- package/dist/index.d.ts +16 -6
- package/dist/index.mjs +53 -7
- package/package.json +10 -10
package/README.md
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
31
31
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
32
32
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
33
|
-
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
33
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
34
34
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
35
35
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
36
36
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
package/dist/index.d.mts
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
-
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
2
|
-
import { ContractRouter, HTTPPath, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
3
|
-
import { Router } from '@orpc/server';
|
4
|
-
export { ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ORPCError, ProcedureImplementer, RouterImplementer, RouterImplementerWithMiddlewares, implement } from '@orpc/server';
|
1
|
+
import { DynamicModule, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
2
|
+
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, implement, onError, onFinish, onStart, onSuccess } from '@orpc/server';
|
5
5
|
import { Promisable } from '@orpc/shared';
|
6
6
|
import { Observable } from 'rxjs';
|
7
|
+
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
8
|
+
|
9
|
+
declare const ORPC_MODULE_CONFIG_SYMBOL: unique symbol;
|
10
|
+
interface ORPCModuleConfig extends CreateProcedureClientOptions<object, AnySchema, object, object, object>, SendStandardResponseOptions {
|
11
|
+
}
|
12
|
+
declare class ORPCModule {
|
13
|
+
static forRoot(config: ORPCModuleConfig): DynamicModule;
|
14
|
+
}
|
7
15
|
|
8
16
|
/**
|
9
17
|
* Decorator in controller handler to implement a oRPC contract.
|
@@ -12,6 +20,8 @@ import { Observable } from 'rxjs';
|
|
12
20
|
*/
|
13
21
|
declare function Implement<T extends ContractRouter<any>>(contract: T): <U extends Promisable<Router<T, Record<never, never>>>>(target: Record<PropertyKey, any>, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => U>) => void;
|
14
22
|
declare class ImplementInterceptor implements NestInterceptor {
|
23
|
+
private readonly config;
|
24
|
+
constructor(config: ORPCModuleConfig | undefined);
|
15
25
|
intercept(ctx: ExecutionContext, next: CallHandler<any>): Observable<any>;
|
16
26
|
}
|
17
27
|
|
@@ -32,5 +42,5 @@ interface PopulateContractRouterPathsOptions {
|
|
32
42
|
*/
|
33
43
|
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
34
44
|
|
35
|
-
export { Implement as Impl, Implement, ImplementInterceptor, populateContractRouterPaths, toNestPattern };
|
36
|
-
export type { PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
45
|
+
export { Implement as Impl, Implement, ImplementInterceptor, ORPCModule, ORPC_MODULE_CONFIG_SYMBOL, populateContractRouterPaths, toNestPattern };
|
46
|
+
export type { ORPCModuleConfig, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
package/dist/index.d.ts
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
-
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
2
|
-
import { ContractRouter, HTTPPath, AnyContractRouter, ContractProcedure } from '@orpc/contract';
|
3
|
-
import { Router } from '@orpc/server';
|
4
|
-
export { ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ORPCError, ProcedureImplementer, RouterImplementer, RouterImplementerWithMiddlewares, implement } from '@orpc/server';
|
1
|
+
import { DynamicModule, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
2
|
+
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, implement, onError, onFinish, onStart, onSuccess } from '@orpc/server';
|
5
5
|
import { Promisable } from '@orpc/shared';
|
6
6
|
import { Observable } from 'rxjs';
|
7
|
+
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
8
|
+
|
9
|
+
declare const ORPC_MODULE_CONFIG_SYMBOL: unique symbol;
|
10
|
+
interface ORPCModuleConfig extends CreateProcedureClientOptions<object, AnySchema, object, object, object>, SendStandardResponseOptions {
|
11
|
+
}
|
12
|
+
declare class ORPCModule {
|
13
|
+
static forRoot(config: ORPCModuleConfig): DynamicModule;
|
14
|
+
}
|
7
15
|
|
8
16
|
/**
|
9
17
|
* Decorator in controller handler to implement a oRPC contract.
|
@@ -12,6 +20,8 @@ import { Observable } from 'rxjs';
|
|
12
20
|
*/
|
13
21
|
declare function Implement<T extends ContractRouter<any>>(contract: T): <U extends Promisable<Router<T, Record<never, never>>>>(target: Record<PropertyKey, any>, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => U>) => void;
|
14
22
|
declare class ImplementInterceptor implements NestInterceptor {
|
23
|
+
private readonly config;
|
24
|
+
constructor(config: ORPCModuleConfig | undefined);
|
15
25
|
intercept(ctx: ExecutionContext, next: CallHandler<any>): Observable<any>;
|
16
26
|
}
|
17
27
|
|
@@ -32,5 +42,5 @@ interface PopulateContractRouterPathsOptions {
|
|
32
42
|
*/
|
33
43
|
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
34
44
|
|
35
|
-
export { Implement as Impl, Implement, ImplementInterceptor, populateContractRouterPaths, toNestPattern };
|
36
|
-
export type { PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
45
|
+
export { Implement as Impl, Implement, ImplementInterceptor, ORPCModule, ORPC_MODULE_CONFIG_SYMBOL, populateContractRouterPaths, toNestPattern };
|
46
|
+
export type { ORPCModuleConfig, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
package/dist/index.mjs
CHANGED
@@ -1,16 +1,45 @@
|
|
1
|
-
import { applyDecorators, Delete, Patch, Put, Post, Get, Head, UseInterceptors } from '@nestjs/common';
|
1
|
+
import { Module, Injectable, Inject, Optional, applyDecorators, Delete, Patch, Put, Post, Get, Head, UseInterceptors } from '@nestjs/common';
|
2
2
|
import { toORPCError } from '@orpc/client';
|
3
3
|
import { isContractProcedure, ContractProcedure, fallbackContractConfig } from '@orpc/contract';
|
4
4
|
import { standardizeHTTPPath, StandardOpenAPISerializer, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer } from '@orpc/openapi-client/standard';
|
5
5
|
import { StandardOpenAPICodec } from '@orpc/openapi/standard';
|
6
6
|
import { getRouter, unlazy, isProcedure, createProcedureClient, ORPCError } from '@orpc/server';
|
7
|
-
export { ORPCError, implement } from '@orpc/server';
|
7
|
+
export { ORPCError, implement, onError, onFinish, onStart, onSuccess } from '@orpc/server';
|
8
8
|
import { toArray, get } from '@orpc/shared';
|
9
9
|
import { flattenHeader } from '@orpc/standard-server';
|
10
10
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
11
11
|
import { mergeMap } from 'rxjs';
|
12
12
|
import { toHttpPath } from '@orpc/client/standard';
|
13
13
|
|
14
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
15
|
+
var __decorateClass$1 = (decorators, target, key, kind) => {
|
16
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
|
17
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
18
|
+
if (decorator = decorators[i])
|
19
|
+
result = (decorator(result)) || result;
|
20
|
+
return result;
|
21
|
+
};
|
22
|
+
const ORPC_MODULE_CONFIG_SYMBOL = Symbol("ORPC_MODULE_CONFIG");
|
23
|
+
let ORPCModule = class {
|
24
|
+
static forRoot(config) {
|
25
|
+
return {
|
26
|
+
module: ORPCModule,
|
27
|
+
providers: [
|
28
|
+
{
|
29
|
+
provide: ORPC_MODULE_CONFIG_SYMBOL,
|
30
|
+
useValue: config
|
31
|
+
},
|
32
|
+
ImplementInterceptor
|
33
|
+
],
|
34
|
+
exports: [ORPC_MODULE_CONFIG_SYMBOL, ImplementInterceptor],
|
35
|
+
global: true
|
36
|
+
};
|
37
|
+
}
|
38
|
+
};
|
39
|
+
ORPCModule = __decorateClass$1([
|
40
|
+
Module({})
|
41
|
+
], ORPCModule);
|
42
|
+
|
14
43
|
function toNestPattern(path) {
|
15
44
|
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/*$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
16
45
|
}
|
@@ -35,6 +64,15 @@ function populateContractRouterPaths(router, options = {}) {
|
|
35
64
|
return populated;
|
36
65
|
}
|
37
66
|
|
67
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
68
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
69
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
70
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
71
|
+
if (decorator = decorators[i])
|
72
|
+
result = (decorator(result)) || result;
|
73
|
+
return result;
|
74
|
+
};
|
75
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
38
76
|
const MethodDecoratorMap = {
|
39
77
|
HEAD: Head,
|
40
78
|
GET: Get,
|
@@ -88,7 +126,10 @@ const codec = new StandardOpenAPICodec(
|
|
88
126
|
new StandardBracketNotationSerializer()
|
89
127
|
)
|
90
128
|
);
|
91
|
-
|
129
|
+
let ImplementInterceptor = class {
|
130
|
+
constructor(config) {
|
131
|
+
this.config = config;
|
132
|
+
}
|
92
133
|
intercept(ctx, next) {
|
93
134
|
return next.handle().pipe(
|
94
135
|
mergeMap(async (impl) => {
|
@@ -108,7 +149,7 @@ class ImplementInterceptor {
|
|
108
149
|
const standardResponse = await (async () => {
|
109
150
|
let isDecoding = false;
|
110
151
|
try {
|
111
|
-
const client = createProcedureClient(procedure);
|
152
|
+
const client = createProcedureClient(procedure, this.config);
|
112
153
|
isDecoding = true;
|
113
154
|
const input = await codec.decode(standardRequest, flattenParams(req.params), procedure);
|
114
155
|
isDecoding = false;
|
@@ -125,11 +166,16 @@ class ImplementInterceptor {
|
|
125
166
|
return codec.encodeError(error);
|
126
167
|
}
|
127
168
|
})();
|
128
|
-
await sendStandardResponse(nodeRes, standardResponse);
|
169
|
+
await sendStandardResponse(nodeRes, standardResponse, this.config);
|
129
170
|
})
|
130
171
|
);
|
131
172
|
}
|
132
|
-
}
|
173
|
+
};
|
174
|
+
ImplementInterceptor = __decorateClass([
|
175
|
+
Injectable(),
|
176
|
+
__decorateParam(0, Inject(ORPC_MODULE_CONFIG_SYMBOL)),
|
177
|
+
__decorateParam(0, Optional())
|
178
|
+
], ImplementInterceptor);
|
133
179
|
function flattenParams(params) {
|
134
180
|
const flatten = {};
|
135
181
|
for (const [key, value] of Object.entries(params)) {
|
@@ -142,4 +188,4 @@ function flattenParams(params) {
|
|
142
188
|
return flatten;
|
143
189
|
}
|
144
190
|
|
145
|
-
export { Implement as Impl, Implement, ImplementInterceptor, populateContractRouterPaths, toNestPattern };
|
191
|
+
export { Implement as Impl, Implement, ImplementInterceptor, ORPCModule, ORPC_MODULE_CONFIG_SYMBOL, 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.6.1",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -39,14 +39,14 @@
|
|
39
39
|
}
|
40
40
|
},
|
41
41
|
"dependencies": {
|
42
|
-
"@orpc/client": "1.
|
43
|
-
"@orpc/
|
44
|
-
"@orpc/openapi": "1.
|
45
|
-
"@orpc/
|
46
|
-
"@orpc/
|
47
|
-
"@orpc/
|
48
|
-
"@orpc/standard-server": "1.
|
49
|
-
"@orpc/
|
42
|
+
"@orpc/client": "1.6.1",
|
43
|
+
"@orpc/openapi": "1.6.1",
|
44
|
+
"@orpc/openapi-client": "1.6.1",
|
45
|
+
"@orpc/contract": "1.6.1",
|
46
|
+
"@orpc/server": "1.6.1",
|
47
|
+
"@orpc/shared": "1.6.1",
|
48
|
+
"@orpc/standard-server": "1.6.1",
|
49
|
+
"@orpc/standard-server-node": "1.6.1"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
52
52
|
"@nestjs/common": "^11.1.0",
|
@@ -60,7 +60,7 @@
|
|
60
60
|
"fastify": "^5.4.0",
|
61
61
|
"rxjs": "^7.8.1",
|
62
62
|
"supertest": "^7.1.0",
|
63
|
-
"zod": "^3.25.
|
63
|
+
"zod": "^3.25.67"
|
64
64
|
},
|
65
65
|
"scripts": {
|
66
66
|
"build": "unbuild",
|