@orpc/nest 0.0.0-next.ec7d801 → 0.0.0-next.ed87680
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 +4 -2
- package/dist/index.d.mts +21 -6
- package/dist/index.d.ts +21 -6
- package/dist/index.mjs +69 -7
- package/package.json +17 -17
package/README.md
CHANGED
@@ -30,7 +30,8 @@
|
|
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
|
-
-
|
33
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
34
35
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
35
36
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
36
37
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
@@ -38,7 +39,6 @@
|
|
38
39
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
39
40
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
40
41
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
42
42
|
|
43
43
|
## Documentation
|
44
44
|
|
@@ -50,9 +50,11 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
50
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
51
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
52
52
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
53
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
53
54
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
54
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
55
56
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
57
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
56
58
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
57
59
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
58
60
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
package/dist/index.d.mts
CHANGED
@@ -1,9 +1,22 @@
|
|
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
|
+
static forRootAsync(options: {
|
15
|
+
imports?: any[];
|
16
|
+
useFactory: (...args: any[]) => Promise<ORPCModuleConfig> | ORPCModuleConfig;
|
17
|
+
inject?: any[];
|
18
|
+
}): DynamicModule;
|
19
|
+
}
|
7
20
|
|
8
21
|
/**
|
9
22
|
* Decorator in controller handler to implement a oRPC contract.
|
@@ -12,6 +25,8 @@ import { Observable } from 'rxjs';
|
|
12
25
|
*/
|
13
26
|
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
27
|
declare class ImplementInterceptor implements NestInterceptor {
|
28
|
+
private readonly config;
|
29
|
+
constructor(config: ORPCModuleConfig | undefined);
|
15
30
|
intercept(ctx: ExecutionContext, next: CallHandler<any>): Observable<any>;
|
16
31
|
}
|
17
32
|
|
@@ -32,5 +47,5 @@ interface PopulateContractRouterPathsOptions {
|
|
32
47
|
*/
|
33
48
|
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
34
49
|
|
35
|
-
export { Implement as Impl, Implement, ImplementInterceptor, populateContractRouterPaths, toNestPattern };
|
36
|
-
export type { PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
50
|
+
export { Implement as Impl, Implement, ImplementInterceptor, ORPCModule, ORPC_MODULE_CONFIG_SYMBOL, populateContractRouterPaths, toNestPattern };
|
51
|
+
export type { ORPCModuleConfig, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
package/dist/index.d.ts
CHANGED
@@ -1,9 +1,22 @@
|
|
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
|
+
static forRootAsync(options: {
|
15
|
+
imports?: any[];
|
16
|
+
useFactory: (...args: any[]) => Promise<ORPCModuleConfig> | ORPCModuleConfig;
|
17
|
+
inject?: any[];
|
18
|
+
}): DynamicModule;
|
19
|
+
}
|
7
20
|
|
8
21
|
/**
|
9
22
|
* Decorator in controller handler to implement a oRPC contract.
|
@@ -12,6 +25,8 @@ import { Observable } from 'rxjs';
|
|
12
25
|
*/
|
13
26
|
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
27
|
declare class ImplementInterceptor implements NestInterceptor {
|
28
|
+
private readonly config;
|
29
|
+
constructor(config: ORPCModuleConfig | undefined);
|
15
30
|
intercept(ctx: ExecutionContext, next: CallHandler<any>): Observable<any>;
|
16
31
|
}
|
17
32
|
|
@@ -32,5 +47,5 @@ interface PopulateContractRouterPathsOptions {
|
|
32
47
|
*/
|
33
48
|
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
34
49
|
|
35
|
-
export { Implement as Impl, Implement, ImplementInterceptor, populateContractRouterPaths, toNestPattern };
|
36
|
-
export type { PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
50
|
+
export { Implement as Impl, Implement, ImplementInterceptor, ORPCModule, ORPC_MODULE_CONFIG_SYMBOL, populateContractRouterPaths, toNestPattern };
|
51
|
+
export type { ORPCModuleConfig, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|
package/dist/index.mjs
CHANGED
@@ -1,16 +1,61 @@
|
|
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
|
+
static forRootAsync(options) {
|
39
|
+
return {
|
40
|
+
module: ORPCModule,
|
41
|
+
imports: options.imports,
|
42
|
+
providers: [
|
43
|
+
{
|
44
|
+
provide: ORPC_MODULE_CONFIG_SYMBOL,
|
45
|
+
useFactory: options.useFactory,
|
46
|
+
inject: options.inject
|
47
|
+
},
|
48
|
+
ImplementInterceptor
|
49
|
+
],
|
50
|
+
exports: [ORPC_MODULE_CONFIG_SYMBOL, ImplementInterceptor],
|
51
|
+
global: true
|
52
|
+
};
|
53
|
+
}
|
54
|
+
};
|
55
|
+
ORPCModule = __decorateClass$1([
|
56
|
+
Module({})
|
57
|
+
], ORPCModule);
|
58
|
+
|
14
59
|
function toNestPattern(path) {
|
15
60
|
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/*$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
16
61
|
}
|
@@ -35,6 +80,15 @@ function populateContractRouterPaths(router, options = {}) {
|
|
35
80
|
return populated;
|
36
81
|
}
|
37
82
|
|
83
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
84
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
85
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
86
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
87
|
+
if (decorator = decorators[i])
|
88
|
+
result = (decorator(result)) || result;
|
89
|
+
return result;
|
90
|
+
};
|
91
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
38
92
|
const MethodDecoratorMap = {
|
39
93
|
HEAD: Head,
|
40
94
|
GET: Get,
|
@@ -88,7 +142,10 @@ const codec = new StandardOpenAPICodec(
|
|
88
142
|
new StandardBracketNotationSerializer()
|
89
143
|
)
|
90
144
|
);
|
91
|
-
|
145
|
+
let ImplementInterceptor = class {
|
146
|
+
constructor(config) {
|
147
|
+
this.config = config;
|
148
|
+
}
|
92
149
|
intercept(ctx, next) {
|
93
150
|
return next.handle().pipe(
|
94
151
|
mergeMap(async (impl) => {
|
@@ -108,7 +165,7 @@ class ImplementInterceptor {
|
|
108
165
|
const standardResponse = await (async () => {
|
109
166
|
let isDecoding = false;
|
110
167
|
try {
|
111
|
-
const client = createProcedureClient(procedure);
|
168
|
+
const client = createProcedureClient(procedure, this.config);
|
112
169
|
isDecoding = true;
|
113
170
|
const input = await codec.decode(standardRequest, flattenParams(req.params), procedure);
|
114
171
|
isDecoding = false;
|
@@ -125,11 +182,16 @@ class ImplementInterceptor {
|
|
125
182
|
return codec.encodeError(error);
|
126
183
|
}
|
127
184
|
})();
|
128
|
-
await sendStandardResponse(nodeRes, standardResponse);
|
185
|
+
await sendStandardResponse(nodeRes, standardResponse, this.config);
|
129
186
|
})
|
130
187
|
);
|
131
188
|
}
|
132
|
-
}
|
189
|
+
};
|
190
|
+
ImplementInterceptor = __decorateClass([
|
191
|
+
Injectable(),
|
192
|
+
__decorateParam(0, Inject(ORPC_MODULE_CONFIG_SYMBOL)),
|
193
|
+
__decorateParam(0, Optional())
|
194
|
+
], ImplementInterceptor);
|
133
195
|
function flattenParams(params) {
|
134
196
|
const flatten = {};
|
135
197
|
for (const [key, value] of Object.entries(params)) {
|
@@ -142,4 +204,4 @@ function flattenParams(params) {
|
|
142
204
|
return flatten;
|
143
205
|
}
|
144
206
|
|
145
|
-
export { Implement as Impl, Implement, ImplementInterceptor, populateContractRouterPaths, toNestPattern };
|
207
|
+
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": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.ed87680",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -39,28 +39,28 @@
|
|
39
39
|
}
|
40
40
|
},
|
41
41
|
"dependencies": {
|
42
|
-
"@orpc/client": "0.0.0-next.
|
43
|
-
"@orpc/
|
44
|
-
"@orpc/
|
45
|
-
"@orpc/
|
46
|
-
"@orpc/
|
47
|
-
"@orpc/server": "0.0.0-next.
|
48
|
-
"@orpc/standard-server-node": "0.0.0-next.
|
49
|
-
"@orpc/
|
42
|
+
"@orpc/client": "0.0.0-next.ed87680",
|
43
|
+
"@orpc/contract": "0.0.0-next.ed87680",
|
44
|
+
"@orpc/openapi-client": "0.0.0-next.ed87680",
|
45
|
+
"@orpc/server": "0.0.0-next.ed87680",
|
46
|
+
"@orpc/shared": "0.0.0-next.ed87680",
|
47
|
+
"@orpc/standard-server": "0.0.0-next.ed87680",
|
48
|
+
"@orpc/standard-server-node": "0.0.0-next.ed87680",
|
49
|
+
"@orpc/openapi": "0.0.0-next.ed87680"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
52
|
-
"@nestjs/common": "^11.1.
|
53
|
-
"@nestjs/core": "^11.
|
54
|
-
"@nestjs/platform-express": "^11.1.
|
55
|
-
"@nestjs/platform-fastify": "^11.1.
|
56
|
-
"@nestjs/testing": "^11.1.
|
52
|
+
"@nestjs/common": "^11.1.6",
|
53
|
+
"@nestjs/core": "^11.1.6",
|
54
|
+
"@nestjs/platform-express": "^11.1.6",
|
55
|
+
"@nestjs/platform-fastify": "^11.1.6",
|
56
|
+
"@nestjs/testing": "^11.1.6",
|
57
57
|
"@ts-rest/core": "^3.52.1",
|
58
58
|
"@types/express": "^5.0.3",
|
59
59
|
"express": "^5.0.0",
|
60
|
-
"fastify": "^5.
|
60
|
+
"fastify": "^5.5.0",
|
61
61
|
"rxjs": "^7.8.1",
|
62
|
-
"supertest": "^7.1.
|
63
|
-
"zod": "^
|
62
|
+
"supertest": "^7.1.4",
|
63
|
+
"zod": "^4.1.5"
|
64
64
|
},
|
65
65
|
"scripts": {
|
66
66
|
"build": "unbuild",
|