@orpc/nest 0.0.1 → 0.0.2

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 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, call, ORPCError } from '@orpc/server';
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 call(procedure, input);
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": "0.0.1",
4
+ "version": "0.0.2",
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": {
@@ -42,9 +41,10 @@
42
41
  "dependencies": {
43
42
  "@orpc/client": "1.2.0",
44
43
  "@orpc/openapi": "1.2.0",
45
- "@orpc/server": "1.2.0",
46
- "@orpc/openapi-client": "1.2.0",
47
44
  "@orpc/shared": "1.2.0",
45
+ "@orpc/contract": "1.2.0",
46
+ "@orpc/openapi-client": "1.2.0",
47
+ "@orpc/server": "1.2.0",
48
48
  "@orpc/standard-server": "1.2.0",
49
49
  "@orpc/standard-server-node": "1.2.0"
50
50
  },