@orpc/nest 0.0.1 → 1.3.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/README.md +55 -1
- package/dist/index.mjs +7 -2
- package/package.json +13 -13
package/README.md
CHANGED
@@ -63,7 +63,61 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
63
63
|
|
64
64
|
## `@orpc/nest`
|
65
65
|
|
66
|
-
Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
66
|
+
Deeply integrate oRPC with [NestJS](https://nestjs.com/). Read the [documentation](https://orpc.unnoq.com/docs/openapi/nest/implement-contract) for more information.
|
67
|
+
|
68
|
+
### Implement Contract
|
69
|
+
|
70
|
+
An overview of how to implement an [oRPC contract](https://orpc.unnoq.com/docs/contract-first/define-contract) in NestJS.
|
71
|
+
|
72
|
+
```ts
|
73
|
+
import { Implement, implement, ORPCError } from '@orpc/nest'
|
74
|
+
|
75
|
+
@Controller()
|
76
|
+
export class PlanetController {
|
77
|
+
/**
|
78
|
+
* Implement a standalone procedure
|
79
|
+
*/
|
80
|
+
@Implement(contract.planet.list)
|
81
|
+
list() {
|
82
|
+
return implement(contract.planet.list).handler(({ input }) => {
|
83
|
+
// Implement logic here
|
84
|
+
|
85
|
+
return []
|
86
|
+
})
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Implement entire a contract
|
91
|
+
*/
|
92
|
+
@Implement(contract.planet)
|
93
|
+
planet() {
|
94
|
+
return {
|
95
|
+
list: implement(contract.planet.list).handler(({ input }) => {
|
96
|
+
// Implement logic here
|
97
|
+
return []
|
98
|
+
}),
|
99
|
+
find: implement(contract.planet.find).handler(({ input }) => {
|
100
|
+
// Implement logic here
|
101
|
+
return {
|
102
|
+
id: 1,
|
103
|
+
name: 'Earth',
|
104
|
+
description: 'The planet Earth',
|
105
|
+
}
|
106
|
+
}),
|
107
|
+
create: implement(contract.planet.create).handler(({ input }) => {
|
108
|
+
// Implement logic here
|
109
|
+
return {
|
110
|
+
id: 1,
|
111
|
+
name: 'Earth',
|
112
|
+
description: 'The planet Earth',
|
113
|
+
}
|
114
|
+
}),
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
// other handlers...
|
119
|
+
}
|
120
|
+
```
|
67
121
|
|
68
122
|
## Sponsors
|
69
123
|
|
package/dist/index.mjs
CHANGED
@@ -3,9 +3,10 @@ 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
|
-
import { getRouter, unlazy, isProcedure,
|
6
|
+
import { getRouter, unlazy, isProcedure, createProcedureClient, ORPCError } from '@orpc/server';
|
7
7
|
export { ORPCError, implement } from '@orpc/server';
|
8
8
|
import { toArray, get } from '@orpc/shared';
|
9
|
+
import { flattenHeader } from '@orpc/standard-server';
|
9
10
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
10
11
|
import { mergeMap } from 'rxjs';
|
11
12
|
import { toHttpPath } from '@orpc/client/standard';
|
@@ -107,10 +108,14 @@ class ImplementInterceptor {
|
|
107
108
|
const standardResponse = await (async () => {
|
108
109
|
let isDecoding = false;
|
109
110
|
try {
|
111
|
+
const client = createProcedureClient(procedure);
|
110
112
|
isDecoding = true;
|
111
113
|
const input = await codec.decode(standardRequest, flattenParams(req.params), procedure);
|
112
114
|
isDecoding = false;
|
113
|
-
const output = await
|
115
|
+
const output = await client(input, {
|
116
|
+
signal: standardRequest.signal,
|
117
|
+
lastEventId: flattenHeader(standardRequest.headers["last-event-id"])
|
118
|
+
});
|
114
119
|
return codec.encode(output, procedure);
|
115
120
|
} catch (e) {
|
116
121
|
const error = isDecoding && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/nest",
|
3
3
|
"type": "module",
|
4
|
-
"version": "
|
4
|
+
"version": "1.3.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -28,8 +28,7 @@
|
|
28
28
|
"@nestjs/core": ">=11.0.0",
|
29
29
|
"express": ">=5.0.0",
|
30
30
|
"fastify": ">=5.0.0",
|
31
|
-
"rxjs": ">=7.0.0"
|
32
|
-
"@orpc/contract": "1.2.0"
|
31
|
+
"rxjs": ">=7.0.0"
|
33
32
|
},
|
34
33
|
"peerDependenciesMeta": {
|
35
34
|
"express": {
|
@@ -40,17 +39,18 @@
|
|
40
39
|
}
|
41
40
|
},
|
42
41
|
"dependencies": {
|
43
|
-
"@orpc/client": "1.
|
44
|
-
"@orpc/
|
45
|
-
"@orpc/
|
46
|
-
"@orpc/
|
47
|
-
"@orpc/
|
48
|
-
"@orpc/
|
49
|
-
"@orpc/
|
42
|
+
"@orpc/client": "1.3.0",
|
43
|
+
"@orpc/contract": "1.3.0",
|
44
|
+
"@orpc/openapi": "1.3.0",
|
45
|
+
"@orpc/server": "1.3.0",
|
46
|
+
"@orpc/standard-server": "1.3.0",
|
47
|
+
"@orpc/openapi-client": "1.3.0",
|
48
|
+
"@orpc/shared": "1.3.0",
|
49
|
+
"@orpc/standard-server-node": "1.3.0"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
52
52
|
"@nestjs/common": "^11.1.0",
|
53
|
-
"@nestjs/core": "^11.0.
|
53
|
+
"@nestjs/core": "^11.0.1",
|
54
54
|
"@nestjs/platform-express": "^11.1.0",
|
55
55
|
"@nestjs/platform-fastify": "^11.1.0",
|
56
56
|
"@nestjs/testing": "^11.1.0",
|
@@ -58,9 +58,9 @@
|
|
58
58
|
"@types/express": "^5.0.1",
|
59
59
|
"express": "^5.0.0",
|
60
60
|
"fastify": "^5.0.0",
|
61
|
-
"rxjs": "^7.
|
61
|
+
"rxjs": "^7.8.1",
|
62
62
|
"supertest": "^7.1.0",
|
63
|
-
"zod": "^3.
|
63
|
+
"zod": "^3.25.11"
|
64
64
|
},
|
65
65
|
"scripts": {
|
66
66
|
"build": "unbuild",
|