@orpc/nest 0.0.0-next.fd13879 → 0.0.0-next.fd1ee2a
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 +6 -8
- package/dist/index.d.mts +18 -8
- package/dist/index.d.ts +18 -8
- package/dist/index.mjs +53 -7
- package/package.json +18 -18
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.
|
@@ -49,21 +49,19 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
49
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
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
|
-
- [@orpc/
|
52
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
53
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
53
54
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
54
|
-
- [@orpc/
|
55
|
-
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
56
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
57
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
55
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
58
56
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
59
|
-
- [@orpc/
|
57
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
60
58
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
61
59
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
62
60
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
63
61
|
|
64
62
|
## `@orpc/nest`
|
65
63
|
|
66
|
-
Deeply integrate oRPC with [NestJS](https://nestjs.com/). Read the [documentation](https://orpc.unnoq.com/docs/openapi/
|
64
|
+
Deeply integrate oRPC with [NestJS](https://nestjs.com/). Read the [documentation](https://orpc.unnoq.com/docs/openapi/integrations/implement-contract-in-nest) for more information.
|
67
65
|
|
68
66
|
### Implement Contract
|
69
67
|
|
package/dist/index.d.mts
CHANGED
@@ -1,17 +1,27 @@
|
|
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.
|
10
18
|
*
|
11
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/
|
19
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/integrations/implement-contract-in-nest#implement-your-contract NestJS Implement Contract Docs}
|
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
|
|
@@ -28,9 +38,9 @@ interface PopulateContractRouterPathsOptions {
|
|
28
38
|
* This utility automatically populates any missing paths
|
29
39
|
* Using the router's keys + `/`.
|
30
40
|
*
|
31
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/
|
41
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/integrations/implement-contract-in-nest#define-your-contract NestJS Implement Contract Docs}
|
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,17 +1,27 @@
|
|
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.
|
10
18
|
*
|
11
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/
|
19
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/integrations/implement-contract-in-nest#implement-your-contract NestJS Implement Contract Docs}
|
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
|
|
@@ -28,9 +38,9 @@ interface PopulateContractRouterPathsOptions {
|
|
28
38
|
* This utility automatically populates any missing paths
|
29
39
|
* Using the router's keys + `/`.
|
30
40
|
*
|
31
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/
|
41
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/integrations/implement-contract-in-nest#define-your-contract NestJS Implement Contract Docs}
|
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": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.fd1ee2a",
|
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/
|
43
|
-
"@orpc/
|
44
|
-
"@orpc/openapi
|
45
|
-
"@orpc/
|
46
|
-
"@orpc/
|
47
|
-
"@orpc/standard-server": "0.0.0-next.
|
48
|
-
"@orpc/
|
49
|
-
"@orpc/
|
42
|
+
"@orpc/client": "0.0.0-next.fd1ee2a",
|
43
|
+
"@orpc/contract": "0.0.0-next.fd1ee2a",
|
44
|
+
"@orpc/openapi": "0.0.0-next.fd1ee2a",
|
45
|
+
"@orpc/openapi-client": "0.0.0-next.fd1ee2a",
|
46
|
+
"@orpc/server": "0.0.0-next.fd1ee2a",
|
47
|
+
"@orpc/standard-server": "0.0.0-next.fd1ee2a",
|
48
|
+
"@orpc/standard-server-node": "0.0.0-next.fd1ee2a",
|
49
|
+
"@orpc/shared": "0.0.0-next.fd1ee2a"
|
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.4",
|
53
|
+
"@nestjs/core": "^11.1.4",
|
54
|
+
"@nestjs/platform-express": "^11.1.4",
|
55
|
+
"@nestjs/platform-fastify": "^11.1.4",
|
56
|
+
"@nestjs/testing": "^11.1.4",
|
57
57
|
"@ts-rest/core": "^3.52.1",
|
58
|
-
"@types/express": "^5.0.
|
58
|
+
"@types/express": "^5.0.3",
|
59
59
|
"express": "^5.0.0",
|
60
|
-
"fastify": "^5.
|
60
|
+
"fastify": "^5.4.0",
|
61
61
|
"rxjs": "^7.8.1",
|
62
|
-
"supertest": "^7.1.
|
63
|
-
"zod": "
|
62
|
+
"supertest": "^7.1.3",
|
63
|
+
"zod": "^4.0.5"
|
64
64
|
},
|
65
65
|
"scripts": {
|
66
66
|
"build": "unbuild",
|