@citec-spbu/contracts 1.0.15 → 1.0.17
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/dist/gen/ts/auth.d.ts +1 -1
- package/package.json +3 -3
- package/proto/auth.proto +1 -1
- package/README.md +0 -329
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/index.js → index.js} +0 -0
- /package/dist/{src/proto → proto}/index.d.ts +0 -0
- /package/dist/{src/proto → proto}/index.js +0 -0
- /package/dist/{src/proto → proto}/paths.d.ts +0 -0
- /package/dist/{src/proto → proto}/paths.js +0 -0
package/dist/gen/ts/auth.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citec-spbu/contracts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "Protobuf definitions and generated TypeScript types",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
|
-
"generate": "mkdir -p gen/ts && protoc -I ./proto ./proto/*.proto --ts_proto_out=./gen/ts --ts_proto_opt=nestJs=true,package=omit
|
|
19
|
-
"build": "tsc -p tsconfig.build.json"
|
|
18
|
+
"generate": "mkdir -p gen/ts && protoc -I ./proto ./proto/*.proto --ts_proto_out=./gen/ts --ts_proto_opt=nestJs=true,package=omit",
|
|
19
|
+
"build": "tsc -p tsconfig.build.json && tsc -p tsconfig.gen.json"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|
package/proto/auth.proto
CHANGED
package/README.md
DELETED
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
# gRPC Contracts
|
|
2
|
-
|
|
3
|
-
This package contains Protocol Buffer definitions and generated TypeScript types for all microservices in the SCM Service ecosystem.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The contracts package provides:
|
|
8
|
-
- **Proto definitions** - `.proto` files defining gRPC service contracts
|
|
9
|
-
- **Generated TypeScript types** - Type-safe interfaces and decorators for NestJS
|
|
10
|
-
- **Shared enums and messages** - Common data types used across services
|
|
11
|
-
|
|
12
|
-
## Proto Files
|
|
13
|
-
|
|
14
|
-
### SCM Service Contracts
|
|
15
|
-
|
|
16
|
-
- **`organizations.proto`** - Organization management service
|
|
17
|
-
- **`repositories.proto`** - Repository management service
|
|
18
|
-
- **`scm-users.proto`** - SCM user management service
|
|
19
|
-
- **`issues.proto`** - Issue tracking service
|
|
20
|
-
- **`pull-requests.proto`** - Pull request management service
|
|
21
|
-
- **`commits.proto`** - Git commit tracking service
|
|
22
|
-
- **`repository-memberships.proto`** - Repository membership management
|
|
23
|
-
- **`issue-assignees.proto`** - Issue assignee management
|
|
24
|
-
|
|
25
|
-
### Other Services
|
|
26
|
-
|
|
27
|
-
- **`auth.proto`** - Authentication service
|
|
28
|
-
- **`users.proto`** - User management service
|
|
29
|
-
- **`account.proto`** - Account management service
|
|
30
|
-
- **`metrics.proto`** - Metrics aggregation service
|
|
31
|
-
- **`scm.proto`** - Legacy SCM service (repository collection management)
|
|
32
|
-
|
|
33
|
-
## Generating TypeScript Types
|
|
34
|
-
|
|
35
|
-
### Prerequisites
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
yarn install
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Generate Types
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
yarn generate
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
This command:
|
|
48
|
-
1. Creates the `gen/ts/` directory
|
|
49
|
-
2. Runs `protoc` with the `ts-proto` plugin
|
|
50
|
-
3. Generates TypeScript files with NestJS decorators
|
|
51
|
-
|
|
52
|
-
### Build Package
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
yarn build
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
This compiles both the generated types and any additional TypeScript files.
|
|
59
|
-
|
|
60
|
-
## Usage in NestJS Services
|
|
61
|
-
|
|
62
|
-
### 1. Install the Package
|
|
63
|
-
|
|
64
|
-
In your service's `package.json`:
|
|
65
|
-
|
|
66
|
-
```json
|
|
67
|
-
{
|
|
68
|
-
"dependencies": {
|
|
69
|
-
"@citec-spbu/contracts": "workspace:*"
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### 2. Import Generated Types
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
import {
|
|
78
|
-
OrganizationsServiceControllerMethods,
|
|
79
|
-
CreateOrganizationRequest,
|
|
80
|
-
CreateOrganizationResponse,
|
|
81
|
-
Organization
|
|
82
|
-
} from "@citec-spbu/contracts/gen/ts/organizations"
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### 3. Implement gRPC Controller
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
import { Controller } from "@nestjs/common"
|
|
89
|
-
import {
|
|
90
|
-
OrganizationsServiceControllerMethods,
|
|
91
|
-
CreateOrganizationRequest
|
|
92
|
-
} from "@citec-spbu/contracts/gen/ts/organizations"
|
|
93
|
-
|
|
94
|
-
@Controller()
|
|
95
|
-
@OrganizationsServiceControllerMethods()
|
|
96
|
-
export class OrganizationGrpcController {
|
|
97
|
-
public async createOrganization(data: CreateOrganizationRequest) {
|
|
98
|
-
// Implementation
|
|
99
|
-
return { organization: { ... } }
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### 4. Configure gRPC Client
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
import { ClientsModule, Transport } from "@nestjs/microservices"
|
|
108
|
-
import { join } from "path"
|
|
109
|
-
|
|
110
|
-
@Module({
|
|
111
|
-
imports: [
|
|
112
|
-
ClientsModule.register([
|
|
113
|
-
{
|
|
114
|
-
name: 'ORGANIZATIONS_PACKAGE',
|
|
115
|
-
transport: Transport.GRPC,
|
|
116
|
-
options: {
|
|
117
|
-
package: 'organizations.v1',
|
|
118
|
-
protoPath: join(__dirname, '../../../contracts/proto/organizations.proto'),
|
|
119
|
-
url: 'localhost:5000'
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
])
|
|
123
|
-
]
|
|
124
|
-
})
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
## Adding New Contracts
|
|
128
|
-
|
|
129
|
-
### 1. Create Proto File
|
|
130
|
-
|
|
131
|
-
Create a new `.proto` file in the `proto/` directory:
|
|
132
|
-
|
|
133
|
-
```protobuf
|
|
134
|
-
syntax = "proto3";
|
|
135
|
-
|
|
136
|
-
package myservice.v1;
|
|
137
|
-
|
|
138
|
-
import "google/protobuf/timestamp.proto";
|
|
139
|
-
|
|
140
|
-
service MyService {
|
|
141
|
-
rpc GetItem(GetItemRequest) returns (GetItemResponse);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
message GetItemRequest {
|
|
145
|
-
string id = 1;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
message GetItemResponse {
|
|
149
|
-
Item item = 1;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
message Item {
|
|
153
|
-
string id = 1;
|
|
154
|
-
string name = 2;
|
|
155
|
-
google.protobuf.Timestamp created_at = 3;
|
|
156
|
-
}
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### 2. Generate Types
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
yarn generate
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### 3. Build Package
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
yarn build
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### 4. Implement Service
|
|
172
|
-
|
|
173
|
-
Use the generated types in your NestJS service as shown above.
|
|
174
|
-
|
|
175
|
-
## Proto Best Practices
|
|
176
|
-
|
|
177
|
-
### Naming Conventions
|
|
178
|
-
|
|
179
|
-
- **Packages**: Use `service_name.v1` format (e.g., `organizations.v1`)
|
|
180
|
-
- **Services**: Use `PascalCase` with `Service` suffix (e.g., `OrganizationsService`)
|
|
181
|
-
- **Messages**: Use `PascalCase` (e.g., `Organization`)
|
|
182
|
-
- **Fields**: Use `snake_case` (e.g., `external_id`)
|
|
183
|
-
- **Enums**: Use `SCREAMING_SNAKE_CASE` with prefix (e.g., `ISSUE_STATE_OPEN`)
|
|
184
|
-
|
|
185
|
-
### Common Imports
|
|
186
|
-
|
|
187
|
-
```protobuf
|
|
188
|
-
import "google/protobuf/timestamp.proto"; // For dates
|
|
189
|
-
import "auth.proto"; // For Provider enum
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Optional Fields
|
|
193
|
-
|
|
194
|
-
Use `optional` keyword for nullable fields:
|
|
195
|
-
|
|
196
|
-
```protobuf
|
|
197
|
-
message Organization {
|
|
198
|
-
string id = 1;
|
|
199
|
-
optional string description = 2; // Can be null
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### Timestamps
|
|
204
|
-
|
|
205
|
-
Always use `google.protobuf.Timestamp`:
|
|
206
|
-
|
|
207
|
-
```protobuf
|
|
208
|
-
import "google/protobuf/timestamp.proto";
|
|
209
|
-
|
|
210
|
-
message Item {
|
|
211
|
-
google.protobuf.Timestamp created_at = 1;
|
|
212
|
-
optional google.protobuf.Timestamp closed_at = 2;
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
## TypeScript Integration
|
|
217
|
-
|
|
218
|
-
### Generated Files Structure
|
|
219
|
-
|
|
220
|
-
```
|
|
221
|
-
gen/ts/
|
|
222
|
-
├── organizations.ts
|
|
223
|
-
├── repositories.ts
|
|
224
|
-
├── issues.ts
|
|
225
|
-
├── pull-requests.ts
|
|
226
|
-
├── commits.ts
|
|
227
|
-
├── repository-memberships.ts
|
|
228
|
-
├── issue-assignees.ts
|
|
229
|
-
├── scm-users.ts
|
|
230
|
-
└── ...
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
### Type Safety
|
|
234
|
-
|
|
235
|
-
All generated types are fully type-safe:
|
|
236
|
-
|
|
237
|
-
```typescript
|
|
238
|
-
// Request/Response types
|
|
239
|
-
type CreateOrganizationRequest = {
|
|
240
|
-
name: string
|
|
241
|
-
provider: Provider
|
|
242
|
-
externalId: number
|
|
243
|
-
url: string
|
|
244
|
-
avatarUrl: string
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// Entity types
|
|
248
|
-
type Organization = {
|
|
249
|
-
id: string
|
|
250
|
-
name: string
|
|
251
|
-
provider: Provider
|
|
252
|
-
externalId: number
|
|
253
|
-
url: string
|
|
254
|
-
avatarUrl: string
|
|
255
|
-
}
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
### NestJS Decorators
|
|
259
|
-
|
|
260
|
-
The `ts-proto` plugin generates decorators for NestJS:
|
|
261
|
-
|
|
262
|
-
- `@{Service}ControllerMethods()` - Automatically maps methods to gRPC handlers
|
|
263
|
-
- Method names match proto service definitions exactly
|
|
264
|
-
|
|
265
|
-
## Versioning
|
|
266
|
-
|
|
267
|
-
The package follows semantic versioning:
|
|
268
|
-
|
|
269
|
-
- **Major**: Breaking changes to proto contracts
|
|
270
|
-
- **Minor**: New services or backward-compatible additions
|
|
271
|
-
- **Patch**: Bug fixes, documentation updates
|
|
272
|
-
|
|
273
|
-
Current version: `1.0.10`
|
|
274
|
-
|
|
275
|
-
## Publishing
|
|
276
|
-
|
|
277
|
-
To publish a new version:
|
|
278
|
-
|
|
279
|
-
1. Update version in `package.json`
|
|
280
|
-
2. Build the package: `yarn build`
|
|
281
|
-
3. Publish: `npm publish` or `yarn publish`
|
|
282
|
-
|
|
283
|
-
## Troubleshooting
|
|
284
|
-
|
|
285
|
-
### Types Not Found
|
|
286
|
-
|
|
287
|
-
Make sure you've run `yarn generate` and `yarn build` in the contracts package.
|
|
288
|
-
|
|
289
|
-
### Import Errors
|
|
290
|
-
|
|
291
|
-
Check that your import paths match the generated file structure:
|
|
292
|
-
|
|
293
|
-
```typescript
|
|
294
|
-
// Correct
|
|
295
|
-
import { ... } from "@citec-spbu/contracts/gen/ts/organizations"
|
|
296
|
-
|
|
297
|
-
// Wrong
|
|
298
|
-
import { ... } from "@citec-spbu/contracts/organizations"
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### Protoc Not Found
|
|
302
|
-
|
|
303
|
-
Install Protocol Buffer compiler:
|
|
304
|
-
|
|
305
|
-
```bash
|
|
306
|
-
# macOS
|
|
307
|
-
brew install protobuf
|
|
308
|
-
|
|
309
|
-
# Ubuntu/Debian
|
|
310
|
-
sudo apt install -y protobuf-compiler
|
|
311
|
-
|
|
312
|
-
# Windows
|
|
313
|
-
choco install protoc
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
## Development Workflow
|
|
317
|
-
|
|
318
|
-
1. **Modify proto files** in `proto/` directory
|
|
319
|
-
2. **Generate types**: `yarn generate`
|
|
320
|
-
3. **Build package**: `yarn build`
|
|
321
|
-
4. **Test in service**: Import and use generated types
|
|
322
|
-
5. **Commit changes**: Include both `.proto` and generated `.ts` files
|
|
323
|
-
|
|
324
|
-
## Resources
|
|
325
|
-
|
|
326
|
-
- [Protocol Buffers Documentation](https://protobuf.dev/)
|
|
327
|
-
- [ts-proto GitHub](https://github.com/stephenh/ts-proto)
|
|
328
|
-
- [NestJS Microservices](https://docs.nestjs.com/microservices/grpc)
|
|
329
|
-
- [gRPC Documentation](https://grpc.io/docs/)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|