@wisemen/one-of 0.0.15 → 0.0.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wisemen/one-of",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -8,21 +8,24 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "type": "module",
10
10
  "files": [
11
- "dist/"
11
+ "dist/",
12
+ "skills/"
12
13
  ],
13
14
  "peerDependencies": {
14
- "@nestjs/common": ">=11.1.17",
15
- "@nestjs/swagger": ">=11.2.6",
16
- "class-transformer": ">=0.5.1",
17
- "class-validator": ">=0.15.1",
18
- "reflect-metadata": ">=0.2.2",
19
- "typeorm": ">=1.0.0"
15
+ "@nestjs/common": "^11.1.19",
16
+ "@nestjs/swagger": "^11.4.2",
17
+ "class-transformer": "^0.5.1",
18
+ "class-validator": "^0.15.1",
19
+ "reflect-metadata": "^0.2.2",
20
+ "typeorm": "^1.0.0"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@types/node": "25.3.0",
23
24
  "eslint": "10.2.1",
25
+ "oxlint": "1.59.0",
24
26
  "expect": "30.2.0",
25
- "typescript": ">=4.8.4 <=5.9.3",
27
+ "typescript": "^5.9.3",
28
+ "oxlint-tsgolint": "0.20.0",
26
29
  "@wisemen/eslint-config-nestjs": "1.1.1"
27
30
  },
28
31
  "author": "Kobe Kwanten",
@@ -0,0 +1,88 @@
1
+ ---
2
+ name: getting-started
3
+ description: Use when documenting discriminated NestJS API responses with Swagger.
4
+ ---
5
+
6
+ # @wisemen/one-of - Getting Started
7
+
8
+ Use `@wisemen/one-of` when an API response has a shared shape with a `type`
9
+ discriminator and variant-specific `meta`.
10
+
11
+ ## Define The Response Shape
12
+
13
+ ```ts
14
+ import { ApiProperty } from '@nestjs/swagger'
15
+ import { OneOfMeta, OneOfMetaApiProperty, OneOfResponse, OneOfTypeApiProperty } from '@wisemen/one-of'
16
+
17
+ enum NotificationType {
18
+ DRIVER_CREATED = 'driver.created',
19
+ DRIVER_UPDATED = 'driver.updated',
20
+ }
21
+
22
+ class Notification {} // example class that anchors the type and meta
23
+
24
+ @OneOfResponse(Notification)
25
+ class NotificationResponse {
26
+ @ApiProperty({ type: String, format: 'uuid' })
27
+ uuid: string
28
+
29
+ @OneOfTypeApiProperty()
30
+ type: NotificationType
31
+
32
+ @OneOfMetaApiProperty()
33
+ meta: unknown
34
+ }
35
+
36
+ @OneOfMeta(Notification, NotificationType.DRIVER_CREATED)
37
+ class DriverCreatedNotificationMeta {
38
+ @ApiProperty({ type: String, format: 'uuid' })
39
+ driverUuid: string
40
+
41
+ @ApiProperty({type: String, format: 'date-time'})
42
+ createdAt: Date
43
+ }
44
+
45
+ @OneOfMeta(Notification, NotificationType.DRIVER_UPDATED)
46
+ class DriverUpdatedNotificationMeta {
47
+ @ApiProperty({ type: String, format: 'uuid' })
48
+ driverUuid: string
49
+
50
+ @ApiProperty({type: String, format: 'date-time'})
51
+ updatedAt: Date
52
+ }
53
+ ```
54
+
55
+ Always pair `@OneOfResponse(...)` with both `@OneOfTypeApiProperty()` and
56
+ `@OneOfMetaApiProperty()`. Each `@OneOfMeta(...)` registers one allowed
57
+ discriminator value.
58
+
59
+ ## Expose It In Swagger
60
+
61
+ Use `@OneOfApiResponse(...)` for direct controller responses:
62
+
63
+ ```ts
64
+ import { Controller, Get } from '@nestjs/common'
65
+ import { OneOfApiResponse } from '@wisemen/one-of'
66
+
67
+ @Controller('/notifications')
68
+ class NotificationController {
69
+ @Get()
70
+ @OneOfApiResponse(Notification)
71
+ async getNotification(): Promise<NotificationResponse> {
72
+ throw new Error('not implemented')
73
+ }
74
+ }
75
+ ```
76
+
77
+ Use `@OneOfApiExtraModels(...)` and `@OneOfApiProperty(...)` when the one-of
78
+ response is nested inside another DTO:
79
+
80
+ ```ts
81
+ import { OneOfApiExtraModels, OneOfApiProperty } from '@wisemen/one-of'
82
+
83
+ @OneOfApiExtraModels(Notification)
84
+ class GetNotificationsResponse {
85
+ @OneOfApiProperty(Notification, { isArray: true })
86
+ items: NotificationResponse[]
87
+ }
88
+ ```