json-rest-api 1.0.21 → 1.0.22

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.
Files changed (173) hide show
  1. package/audit/00-charter.md +103 -0
  2. package/audit/01-scope-map.md +84 -0
  3. package/audit/02-coverage-matrix.csv +174 -0
  4. package/audit/03-invariants.md +123 -0
  5. package/audit/04-standards-rubric.md +56 -0
  6. package/audit/05-competitor-rubric.md +77 -0
  7. package/audit/06-findings.md +160 -0
  8. package/audit/07-risk-register.csv +10 -0
  9. package/audit/08-remediation-roadmap.md +177 -0
  10. package/audit/09-signoff-check.md +23 -0
  11. package/audit/10-final-synthesis.md +29 -0
  12. package/audit/evidence/code/all-files-json-rest-api.txt +168 -0
  13. package/audit/evidence/code/all-files-json-rest-schema.txt +12 -0
  14. package/audit/evidence/code/boundary-leak-checks.txt +72 -0
  15. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__bulk-operations-plugin.js.txt +480 -0
  16. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__express-plugin.js.txt +532 -0
  17. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__lib__busboy-detector.js.txt +175 -0
  18. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__lib__formidable-detector.js.txt +138 -0
  19. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__lib__request-helpers.js.txt +222 -0
  20. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__file-handling-plugin.js.txt +342 -0
  21. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__dbTablesOperations.js.txt +304 -0
  22. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__fractional-positioning.js.txt +188 -0
  23. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__compile-schemas.js.txt +336 -0
  24. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__connectors-query-parser.js.txt +165 -0
  25. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__database-capabilities.js.txt +265 -0
  26. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__database-value-normalizers.js.txt +369 -0
  27. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__default-data-helpers.js.txt +72 -0
  28. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__field-utils.js.txt +139 -0
  29. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__knex-constants.js.txt +45 -0
  30. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__knex-field-helpers.js.txt +396 -0
  31. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__knex-json-api-transformers.js.txt +162 -0
  32. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__payload-validators.js.txt +1314 -0
  33. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__schema-helpers.js.txt +488 -0
  34. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__scope-validations.js.txt +484 -0
  35. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__simplified-helpers.js.txt +857 -0
  36. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-cross-table-search.js.txt +565 -0
  37. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-json-api-transformers-querying.js.txt +485 -0
  38. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-pagination-helpers.js.txt +560 -0
  39. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-process-includes.js.txt +167 -0
  40. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-query-helpers-base.js.txt +109 -0
  41. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-query-helpers.js.txt +1064 -0
  42. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-relationship-includes.js.txt +1983 -0
  43. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-window-queries.js.txt +328 -0
  44. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__url-helpers.js.txt +119 -0
  45. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__storage__storage-adapter.js.txt +160 -0
  46. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__writing__many-to-many-manipulations.js.txt +300 -0
  47. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__writing__relationship-processor.js.txt +245 -0
  48. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-access.js.txt +459 -0
  49. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-cors-plugin.js.txt +237 -0
  50. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-knex-plugin.js.txt +1135 -0
  51. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-multihome-plugin.js.txt +314 -0
  52. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__compile-resource-schemas.js.txt +7 -0
  53. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__register-relationship-routes.js.txt +71 -0
  54. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__register-scope-routes.js.txt +102 -0
  55. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__turn-scope-init-into-vars.js.txt +49 -0
  56. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__validate-include-configurations.js.txt +39 -0
  57. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__add-route.js.txt +23 -0
  58. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__check-permissions.js.txt +13 -0
  59. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__common.js.txt +639 -0
  60. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__delete-relationship.js.txt +117 -0
  61. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__delete.js.txt +104 -0
  62. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__enrich-attributes.js.txt +199 -0
  63. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__get-related.js.txt +353 -0
  64. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__get-relationship.js.txt +61 -0
  65. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__get.js.txt +184 -0
  66. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__patch-relationship.js.txt +55 -0
  67. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__patch.js.txt +191 -0
  68. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__post-relationship.js.txt +110 -0
  69. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__post.js.txt +168 -0
  70. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__put.js.txt +253 -0
  71. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__query.js.txt +207 -0
  72. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__release.js.txt +12 -0
  73. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin.js.txt +165 -0
  74. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-positioning-plugin.js.txt +668 -0
  75. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__socketio-plugin.js.txt +621 -0
  76. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__storage__local-storage.js.txt +218 -0
  77. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__storage__s3-storage.js.txt +124 -0
  78. package/audit/evidence/code/critical-pass1/json-rest-schema__src__CorePlugin.js.txt +269 -0
  79. package/audit/evidence/code/critical-pass1/json-rest-schema__src__Schema.js.txt +242 -0
  80. package/audit/evidence/code/critical-pass1/json-rest-schema__src__index.js.txt +77 -0
  81. package/audit/evidence/code/critical-pass1-risk-keywords.txt +238 -0
  82. package/audit/evidence/code/critical-pass1-summary.csv +67 -0
  83. package/audit/evidence/code/critical-pass2-summary.csv +67 -0
  84. package/audit/evidence/code/early-silent-zones-no-test-token.txt +57 -0
  85. package/audit/evidence/code/error-model-signals.txt +98 -0
  86. package/audit/evidence/code/git-files-json-rest-api.txt +171 -0
  87. package/audit/evidence/code/git-files-json-rest-schema.txt +27 -0
  88. package/audit/evidence/code/hook-flow-signals.txt +282 -0
  89. package/audit/evidence/code/idproperty-signals.txt +157 -0
  90. package/audit/evidence/code/import-cycles-non-anyapi.txt +3 -0
  91. package/audit/evidence/code/import-hotspots-non-anyapi.txt +96 -0
  92. package/audit/evidence/code/imports-json-rest-api.txt +354 -0
  93. package/audit/evidence/code/imports-json-rest-schema.txt +15 -0
  94. package/audit/evidence/code/in-scope-files-json-rest-api.txt +160 -0
  95. package/audit/evidence/code/in-scope-files-json-rest-schema.txt +13 -0
  96. package/audit/evidence/code/non-anyapi-core-files.txt +101 -0
  97. package/audit/evidence/code/permission-signals.txt +193 -0
  98. package/audit/evidence/code/query-include-signals.txt +687 -0
  99. package/audit/evidence/code/transaction-signals.txt +28 -0
  100. package/audit/evidence/code/validation-signals.txt +650 -0
  101. package/audit/evidence/code/write-path-signals.txt +61 -0
  102. package/audit/evidence/docs/docs-claims-signals.txt +1075 -0
  103. package/audit/evidence/docs/schema-docs-claims-signals.txt +179 -0
  104. package/audit/evidence/external/corpus-freeze.md +21 -0
  105. package/audit/evidence/external/npm-competitor-metadata.txt +70 -0
  106. package/audit/evidence/external/npm-download-signals.txt +23 -0
  107. package/audit/evidence/external/npm-jsonapi-server.txt +8 -0
  108. package/audit/evidence/external/npm-modern-jsonapi-metadata.txt +38 -0
  109. package/audit/evidence/external/readme-fortune-signals.txt +26 -0
  110. package/audit/evidence/external/readme-fortune.md +165 -0
  111. package/audit/evidence/external/readme-json-api-serializer-signals.txt +80 -0
  112. package/audit/evidence/external/readme-json-api-serializer.md +690 -0
  113. package/audit/evidence/external/readme-jsonapi-serde-server-signals.txt +0 -0
  114. package/audit/evidence/external/readme-jsonapi-serde-server.md +22 -0
  115. package/audit/evidence/external/readme-jsonapi-serializer-signals.txt +63 -0
  116. package/audit/evidence/external/readme-jsonapi-serializer.md +315 -0
  117. package/audit/evidence/external/readme-jsonapi-server-signals.txt +19 -0
  118. package/audit/evidence/external/readme-jsonapi-server.md +104 -0
  119. package/audit/evidence/external/readme-nestjs-json-api-signals.txt +4 -0
  120. package/audit/evidence/external/readme-nestjs-json-api.md +94 -0
  121. package/audit/evidence/external/readme-yaser-json-api-nestjs-signals.txt +47 -0
  122. package/audit/evidence/external/readme-yaser-json-api-nestjs.md +447 -0
  123. package/audit/evidence/external/standard-jsonapi-snippets.txt +84 -0
  124. package/audit/evidence/external/standard-rfc-snippets.txt +168 -0
  125. package/audit/evidence/external/standards-sources.txt +6 -0
  126. package/audit/evidence/runtime/baseline-commits.txt +2 -0
  127. package/audit/evidence/runtime/db-adapter-assumptions.txt +3 -0
  128. package/audit/evidence/runtime/environment.txt +4 -0
  129. package/audit/evidence/runtime/invariant-runtime-mapping.md +38 -0
  130. package/audit/evidence/runtime/probe-patch-relationship-error.exitcode +1 -0
  131. package/audit/evidence/runtime/probe-patch-relationship-error.log +76 -0
  132. package/audit/evidence/runtime/probe-patch-relationship-error.mjs +67 -0
  133. package/audit/evidence/runtime/probe-patch-relationship-referenceerror.exitcode +1 -0
  134. package/audit/evidence/runtime/probe-patch-relationship-referenceerror.log +62 -0
  135. package/audit/evidence/runtime/probe-patch-relationship-referenceerror.mjs +47 -0
  136. package/audit/evidence/runtime/test-exitcodes.txt +4 -0
  137. package/audit/evidence/runtime/test-summary.md +107 -0
  138. package/audit/evidence/runtime/trace-anchors.txt +61 -0
  139. package/audit/evidence/tests/access-multitenancy-test-signals.txt +125 -0
  140. package/audit/evidence/tests/failing-tests-summary.txt +25 -0
  141. package/audit/evidence/tests/npm-test-json-rest-api.exitcode +1 -0
  142. package/audit/evidence/tests/npm-test-json-rest-api.log +5885 -0
  143. package/audit/evidence/tests/npm-test-json-rest-schema.exitcode +1 -0
  144. package/audit/evidence/tests/npm-test-json-rest-schema.log +356 -0
  145. package/audit/evidence/tests/query-include-test-signals.txt +948 -0
  146. package/audit/evidence/tests/relationship-test-signals.txt +223 -0
  147. package/audit/evidence/tests/skipped-tests.txt +10 -0
  148. package/audit/evidence/tests/test-suite-list-non-anyapi.txt +30 -0
  149. package/audit/evidence/tests/test-suite-list.txt +32 -0
  150. package/audit/subsystems/docs-drift.md +49 -0
  151. package/audit/subsystems/pass2-cross-review.md +131 -0
  152. package/audit/subsystems/plugins-access.md +51 -0
  153. package/audit/subsystems/plugins-bulk.md +50 -0
  154. package/audit/subsystems/plugins-cors.md +48 -0
  155. package/audit/subsystems/plugins-file.md +53 -0
  156. package/audit/subsystems/plugins-multihome.md +50 -0
  157. package/audit/subsystems/plugins-positioning.md +54 -0
  158. package/audit/subsystems/plugins-socketio.md +50 -0
  159. package/audit/subsystems/query-engine.md +61 -0
  160. package/audit/subsystems/relationships.md +55 -0
  161. package/audit/subsystems/rest-orchestration.md +66 -0
  162. package/audit/subsystems/schema-core.md +64 -0
  163. package/audit/subsystems/storage-knex.md +57 -0
  164. package/audit/subsystems/tests.md +48 -0
  165. package/audit/subsystems/transport-express.md +55 -0
  166. package/audit/traces/trace-read-get.md +22 -0
  167. package/audit/traces/trace-read-query.md +25 -0
  168. package/audit/traces/trace-relationship-endpoints.md +31 -0
  169. package/audit/traces/trace-write-delete.md +17 -0
  170. package/audit/traces/trace-write-patch.md +26 -0
  171. package/audit/traces/trace-write-post.md +22 -0
  172. package/audit/traces/trace-write-put.md +23 -0
  173. package/package.json +3 -3
@@ -0,0 +1,447 @@
1
+ <p align='center'>
2
+ <a href="https://www.npmjs.com/package/json-api-nestjs" target="_blank"><img src="https://img.shields.io/npm/v/json-api-nestjs.svg" alt="NPM Version" /></a>
3
+ <a href="https://www.npmjs.com/package/json-api-nestjs" target="_blank"><img src="https://img.shields.io/npm/l/json-api-nestjs.svg" alt="Package License" /></a>
4
+ <a href="https://www.npmjs.com/package/json-api-nestjs" target="_blank"><img src="https://img.shields.io/npm/dm/json-api-nestjs.svg" alt="NPM Downloads" /></a>
5
+ <a href="http://commitizen.github.io/cz-cli/" target="_blank"><img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen friendly" /></a>
6
+ <img src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/klerick/02a4c98cf7008fea2af70dc2d50f4cb7/raw/json-api-nestjs.json" alt="Coverage Badge" />
7
+ </p>
8
+
9
+ # json-api-nestjs
10
+
11
+ This plugin works upon **TypeOrm** or **MicroOrm** library, which is used as the main database abstraction layer tool. The module
12
+ automatically generates an API according to JSON API specification from the database structure (**TypeOrm** or **MicroOrm** entities). It
13
+ supports features such as requests validation based on database fields types, request filtering, endpoints extending,
14
+ data relations control and much more. Our module significantly reduces the development time of REST services by removing
15
+ the need to negotiate the mechanism of client-server interaction and implementing automatic API generation without the
16
+ need to write any code.
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ $ npm install @yaser2us/json-api-nestjs
22
+ ```
23
+
24
+ ## Example
25
+
26
+ Once the installation process is complete, we can import the **JsonApiModule** into the root **AppModule**.
27
+ ### TypeOrm
28
+ ```typescript
29
+ import {Module} from '@nestjs/common';
30
+ import {JsonApiModule} from '@yaser2us/json-api-nestjs';
31
+ import {TypeOrmJsonApiModule} from '@yaser2us/json-api-nestjs-typeorm';
32
+ import {Users} from 'type-orm/database';
33
+
34
+ @Module({
35
+ imports: [
36
+ JsonApiModule.forRoot(TypeOrmJsonApiModule, {
37
+ entities: [Users]
38
+ }),
39
+ ],
40
+ })
41
+ export class AppModule {
42
+ }
43
+ ```
44
+
45
+ ### MicroOrm
46
+ ```typescript
47
+ import {Module} from '@nestjs/common';
48
+ import {JsonApiModule} from '@yaser2us/json-api-nestjs';
49
+ import {MicroOrmJsonApiModule} from '@yaser2us/json-api-nestjs-microorm';
50
+ import {Users} from 'micro-orm/database';
51
+
52
+ @Module({
53
+ imports: [
54
+ JsonApiModule.forRoot(MicroOrmJsonApiModule, {
55
+ entities: [Users]
56
+ }),
57
+ ],
58
+ })
59
+ export class AppModule {
60
+ }
61
+ ```
62
+
63
+ After this, you have to prepare CRUDs with ready-to-use endpoints:
64
+
65
+ - GET /users
66
+ - POST /users
67
+ - GET /users/:id
68
+ - PATCH /users/:id
69
+ - DELETE /users/:id
70
+ - GET /users/{id}/relationships/{relName}
71
+ - POST /users/{id}/relationships/{relName}
72
+ - PATCH /users/{id}/relationships/{relName}
73
+ - DELETE /users/{id}/relationships/{relName}
74
+
75
+ ## Configuration params
76
+
77
+ The following interface is using for the configuration:
78
+
79
+ ```typescript
80
+ export interface ModuleOptions {
81
+ entities: Entity[]; // List of typeOrm Entity
82
+ controllers?: NestController[]; // List of controller, if you need extend default present
83
+ connectionName?: string; // Type orm connection name: "default" is default name
84
+ providers?: NestProvider[]; // List of addition provider for useing in custom controller
85
+ imports?: NestImport[]; // List of addition module for useing in custom controller
86
+ options?: {
87
+ requiredSelectField?: boolean; // Need list of select field in get endpoint, try is default
88
+ debug?: boolean; // Debug info in result object, like error message
89
+ pipeForId?: Type<PipeTransform> // Nestjs pipe for validate id params, by default ParseIntPipe
90
+ operationUrl?: string // Url for atomic operation https://jsonapi.org/ext/atomic/
91
+ // You can add params for MicroOrm or TypeOrm adapter
92
+ } ;
93
+ }
94
+ ```
95
+
96
+ You can extend the default controller:
97
+
98
+ ```typescript
99
+ import {Get, Param, Inject, BadRequestException} from '@nestjs/common';
100
+
101
+ import {Users} from 'database';
102
+ import {
103
+ JsonApi,
104
+ excludeMethod,
105
+ JsonBaseController,
106
+ InjectService,
107
+ JsonApiService,
108
+ Query,
109
+ } from '@yaser2us/json-api-nestjs';
110
+ import {
111
+ ResourceObjectRelationships,
112
+ } from '@yaser2us/json-api-nestjs-shared';
113
+ import {ExampleService} from '../../service/example/example.service';
114
+
115
+ @JsonApi(Users, {
116
+ allowMethod: excludeMethod(['deleteRelationship']),
117
+ requiredSelectField: true,
118
+ overrideRoute: 'user',
119
+ })
120
+ export class ExtendUserController extends JsonBaseController<Users, 'id'> {
121
+ @InjectService() public service: JsonApiService<Users>;
122
+ @Inject(ExampleService) protected exampleService: ExampleService;
123
+
124
+ public override getAll(query: Query<Users, 'id'>): Promise<ResourceObject<Users, 'array'>> {
125
+ if (!this.exampleService.someCheck(query)) {
126
+ throw new BadRequestException({});
127
+ }
128
+ return this.service.getAll(query);// OR call parent method: super.getAll(query);
129
+ }
130
+
131
+ public override patchRelationship<Rel extends EntityRelation<Users>>(
132
+ id: string | number,
133
+ relName: Rel,
134
+ input: PatchRelationshipData
135
+ ): Promise<ResourceObjectRelationships<Users, 'id', Rel>> {
136
+ return super.patchRelationship(id, relName, input);
137
+ }
138
+
139
+ @Get(':id/example')
140
+ testOne(@Param('id') id: string): string {
141
+ return this.exampleService.testMethode(id);
142
+ }
143
+ }
144
+ ```
145
+
146
+ You can overwrite the default config for the current controller using options in the decorator **JsonAPi**.
147
+ Also you can specify an API method necessary for you, using **allowMethod**
148
+ Defulat validation check only simple type and database structure.
149
+ If you need custom pipe validation you can your owner pipe like this:
150
+
151
+ ```typescript
152
+
153
+ import { Query } from '@nestjs/common';
154
+ import {
155
+ JsonApi,
156
+ excludeMethod,
157
+ JsonBaseController,
158
+ InjectService,
159
+ JsonApiService,
160
+ Query as QueryType,
161
+ } from 'json-api-nestjs';
162
+
163
+ @JsonApi(Users, {
164
+ allowMethod: excludeMethod(['deleteRelationship']),
165
+ requiredSelectField: true,
166
+ overrideRoute: 'user',
167
+ })
168
+ export class ExtendUserController extends JsonBaseController<Users, 'id'> {
169
+ @InjectService() public service: JsonApiService<Users>;
170
+ @Inject(ExampleService) protected exampleService: ExampleService;
171
+
172
+ public override getAll(
173
+ @Query(ExamplePipe) query: QueryType<Users, 'id'>
174
+ ): Promise<ResourceObject<Users, 'array'>> {
175
+ return super.getAll(query);
176
+ }
177
+ }
178
+ ```
179
+
180
+ ```typescript
181
+ import { ArgumentMetadata, PipeTransform } from '@nestjs/common';
182
+
183
+ import { Query } from 'json-api-nestjs';
184
+ import { Users } from 'database';
185
+
186
+ export class ExamplePipe implements PipeTransform<Query<Users, 'id'>, Query<Users, 'id'>> {
187
+ transform(value: Query<Users, 'id'>, metadata: ArgumentMetadata): Query<Users, 'id'> {
188
+ return value;
189
+ }
190
+ }
191
+ ```
192
+
193
+ ## Swagger UI
194
+
195
+ For using swagger, you should only add [@nestjs/swagger](https://docs.nestjs.com/openapi/introduction) and configure it
196
+ ```typescript
197
+ const app = await NestFactory.create(AppModule);
198
+
199
+ const config = new DocumentBuilder()
200
+ .setOpenAPIVersion('3.1.0')
201
+ .setTitle('JSON API swagger example')
202
+ .setDescription('The JSON API list example')
203
+ .setVersion('1.0')
204
+ .build();
205
+
206
+ SwaggerModule.setup(
207
+ 'swagger',
208
+ app,
209
+ () => SwaggerModule.createDocument(app, config), // !!!Important: document as factory
210
+ {}
211
+ );
212
+
213
+ ```
214
+
215
+ ## Available endpoint method
216
+
217
+ Using **Users** entity and relation **Roles** entity as example
218
+
219
+ ### List item of Users
220
+
221
+ ```
222
+ GET /users
223
+ ```
224
+
225
+ Available query params:
226
+
227
+ - **include** - you can extend result with relations (aka join)
228
+ ```
229
+ GET /users?include=roles
230
+ ```
231
+ result of request will have role relation for each **Users** item
232
+
233
+ - **fields** - you can specify required fields of result query
234
+
235
+ ```
236
+ GET /users?fields[target]=login,lastName&fileds[roles]=name,key
237
+ ```
238
+ The "target" is **Users** entity
239
+ The "roles" is **Roles** entity
240
+ So, result of request will be have only fields *login* and *lastName* for **Users** entity and fields *name* and *
241
+ key* for **Roles** entity
242
+ - **sort** - you can sort result of the request
243
+
244
+ ```
245
+ GET /users?sort=target.name,-roles.key
246
+ ```
247
+ The "target" is **Users** entity
248
+ The "roles" is **Roles** entity
249
+ So, result of the request will be sorted by field *name* of **Users** by *ASC* and field *key* of **Roles** entity
250
+ by **DESC**.
251
+ - **page** - pagination for you request
252
+
253
+ ```
254
+ GET /users?page[number]=1page[size]=20
255
+ ```
256
+ - **filter** - filter for query
257
+
258
+ ```
259
+ GET /users?filter[name][eq]=1&filter[roles.name][ne]=test&filter[roles.status][eq]=true
260
+ ```
261
+ The "name" is a field of **Users** entity
262
+ The "roles.name" is *name* field of **Roles** entity
263
+ The "eq", "ne" is *[Filter operand](#filter-operand)*
264
+
265
+ So, this query will be transformed like sql:
266
+ ```sql
267
+ WHERE users.name = 1 AND roles.name <> 'test' AND roles.status = true
268
+ ```
269
+
270
+ ## Filter operand
271
+
272
+ ```typescript
273
+ type FilterOperand
274
+ {
275
+ in:string[] // is equal to the conditional of query "WHERE 'attribute_name' IN ('value1', 'value2')"
276
+ nin: string[] // is equal to the conditional of query "WHERE 'attribute_name' NOT IN ('value1', 'value1')"
277
+ eq: string // is equal to the conditional of query "WHERE 'attribute_name' = 'value1'
278
+ ne: string // is equal to the conditional of query "WHERE 'attribute_name' <> 'value1'
279
+ gte: string // is equal to the conditional of query "WHERE 'attribute_name' >= 'value1'
280
+ gt: string // is equal to the conditional of query "WHERE 'attribute_name' > 'value1'
281
+ lt: string // is equal to the conditional of query "WHERE 'attribute_name' < 'value1'
282
+ lte:string // is equal to the conditional of query "WHERE 'attribute_name' <= 'value1'
283
+ regexp: string // is equal to the conditional of query "WHERE 'attribute_name' ~* value1
284
+ some: string // is equal to the conditional of query "WHERE 'attribute_name' && [value1]
285
+ }
286
+ ```
287
+
288
+ ### Get item of Users
289
+
290
+ ```
291
+ GET /users/:id
292
+ ```
293
+ - **include** - you can extend result with relations (aka join)
294
+ ```
295
+ GET /users?include=roles
296
+ ```
297
+ result of request will have role relation for each **Users** item
298
+
299
+ - **fields** - you can specify required fields of result query
300
+
301
+ ```
302
+ GET /users?fields[target]=login,lastName&fileds[roles]=name,key
303
+ ```
304
+ The "target" is **Users** entity
305
+ The "roles" is **Roles** entity
306
+ So, result of request will be have only fields *login* and *lastName* for **Users** entity and fields *name* and *
307
+ key* for **Roles** entity
308
+
309
+ ### Create item of Users
310
+ ```
311
+ POST /users
312
+ ```
313
+
314
+ - **body** - Create new User and add link to address
315
+
316
+ ```json
317
+ {
318
+ "data": {
319
+ "type": "users",
320
+ "attributes": {
321
+ "id": 0,
322
+ "login": "string",
323
+ "firstName": "string",
324
+ "lastName": "string",
325
+ "isActive": true,
326
+ "createdAt": "2023-12-08T10:32:27.352Z",
327
+ "updatedAt": "2023-12-08T10:32:27.352Z"
328
+ },
329
+ "relationships": {
330
+ "addresses": {
331
+ "id": "1",
332
+ "type": "addresses"
333
+ }
334
+ }
335
+ }
336
+ }
337
+ ```
338
+ ### Update item of Users
339
+ ```
340
+ PATCH /users/:id
341
+ ```
342
+
343
+ - **body** - Update User with id 1 and update link to address and manager
344
+
345
+ ```json
346
+ {
347
+ "data": {
348
+ "id": "1",
349
+ "type": "users",
350
+ "attributes": {
351
+ "id": 0,
352
+ "login": "string",
353
+ "firstName": "string",
354
+ "lastName": "string",
355
+ "isActive": true,
356
+ "createdAt": "2023-12-08T10:34:57.752Z",
357
+ "updatedAt": "2023-12-08T10:34:57.752Z"
358
+ },
359
+ "relationships": {
360
+ "addresses": {
361
+ "id": "2",
362
+ "type": "addresses"
363
+ },
364
+ "manager": {
365
+ "id": "2",
366
+ "type": "users"
367
+ }
368
+ }
369
+ }
370
+ }
371
+
372
+ ```
373
+
374
+ ### Atomic operation
375
+ You can more information find [here](https://jsonapi.org/ext/atomic/)
376
+ But you have additinal feature.
377
+ For example: you will need create new **Roles**, then - create new **Users** and assign new **Roles** to new **Users**.
378
+ If use native json api you need send 3 http request:
379
+ - POST /roles
380
+ - POST /users
381
+
382
+ but [Atomic operation](https://jsonapi.org/ext/atomic/) allow for one request.
383
+ ```json
384
+
385
+ {
386
+ "atomic:operations":[
387
+ {
388
+ "op":"add",
389
+ "ref":{
390
+ "type":"roles",
391
+ "tmpId":10000
392
+ },
393
+ "data":{
394
+ "type":"roles",
395
+ "attributes":{
396
+ "name":"testRolesAgain",
397
+ "key":"testRolesAgain"
398
+ }
399
+ }
400
+ },
401
+ {
402
+ "op":"add",
403
+ "ref":{
404
+ "type":"users"
405
+ },
406
+ "data":{
407
+ "type":"users",
408
+ "attributes":{
409
+ "login":"newLogin"
410
+ },
411
+ "relationships":{
412
+ "addresses":{
413
+ "type":"addresses",
414
+ "id":"1"
415
+ },
416
+ "roles":[
417
+ {
418
+ "type":"roles",
419
+ "id":"10000"
420
+ }
421
+ ]
422
+ }
423
+ }
424
+ }
425
+ ]
426
+ }
427
+
428
+ ```
429
+ **tmpId** - is params for operation **add**, should be unique for all operations.
430
+
431
+ If you have Interceptor you can check call it from **AtomicOperation**
432
+
433
+
434
+
435
+ ```ts
436
+ @Injectable()
437
+ export class AtomicInterceptor<T> implements NestInterceptor {
438
+ intercept(context: ExecutionContext, next: CallHandler<T>): Observable<T> {
439
+ const isAtomic = context.getArgByIndex(3)
440
+ if (isAtomic) {
441
+ console.log('call from atomic operation')
442
+ }
443
+ return next.handle();
444
+ }
445
+ }
446
+ ```
447
+ **isAtomic** - is array of params of method
@@ -0,0 +1,84 @@
1
+ # JSON:API spec key clauses (captured)
2
+ captured_at=2026-03-01T16:01:55Z
3
+ source=https://jsonapi.org/format/
4
+
5
+ 177:( application/vnd.api+json )
6
+ 193: The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”,
7
+ 194:“SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this
8
+ 204: application/vnd.api+json .
9
+ 236: The JSON:API media type MUST NOT be specified with any media type parameters
10
+ 242:profile’s URI SHOULD return documentation that describes its usage. The
11
+ 243:values of the ext and profile parameters MUST equal a space-separated
12
+ 257: An extension MUST NOT lessen or remove any processing rules, restrictions or
13
+ 268:extension MUST define a namespace to guarantee that extensions will never
14
+ 270: MUST meet all of the following conditions:
15
+ 273: A namespace MUST contain at least one character.
16
+ 274: A namespace MUST contain only these characters:
17
+ 283: An extension MUST NOT define more than one namespace. The namespace used for
18
+ 284:all query parameters and document members MUST be the same for any given
19
+ 292: Content-Type: application/vnd.api+json;ext= "https://jsonapi.org/ext/version"
20
+ 314: A profile MUST NOT define any query parameters except implementation-specific query parameters .
21
+ 316: A profile MUST NOT alter or remove processing rules that have been defined
22
+ 322:parameter , but it could not specify that relationship
23
+ 323:names in the include query parameter are
24
+ 340: Content-Type: application/vnd.api+json;profile= "https://example.com/resource-timestamps"
25
+ 361: Clients and servers MUST send all JSON:API payloads using the JSON:API media
26
+ 364: Clients and servers MUST specify the ext media type parameter in the
27
+ 368: Clients and servers MUST specify the profile media type parameters in the
28
+ 374: When processing a JSON:API response document, clients MUST ignore any
29
+ 399:servers MUST respond with a 415 Unsupported Media Type status code if
30
+ 405:parameter contains an unsupported extension URI, the server MUST respond
31
+ 415:servers MUST ignore instances of that media type which are modified by a
32
+ 418:servers MUST respond with a 406 Not Acceptable status code. If every
33
+ 420:at least one unsupported extension URI, the server MUST also respond with a
34
+ 423: If the profile parameter is received, a server SHOULD attempt to apply any
35
+ 424:requested profile(s) to its response. A server MUST ignore any profiles
36
+ 433: Servers that support the ext or profile media type parameters SHOULD
37
+ 453:members MUST comply with the naming requirements specified
38
+ 457:extensions MUST NOT contain any additional members. Client and server
39
+ 458:implementations MUST ignore non-compliant members.
40
+ 467: A JSON object MUST be at the root of every JSON:API request and response
41
+ 470: A document MUST contain at least one of the following top-level members:
42
+ 474: errors : an array of error objects .
43
+ 480: The members data and errors MUST NOT coexist in the same document.
44
+ 487: included : an array of resource objects that are related to the primary
45
+ 488:data and/or each other (“included resources”).
46
+ 491: If a document does not contain a top-level data key, the included member
47
+ 492: MUST NOT be present either.
48
+ 498:document has extensions or profiles applied to it, this link SHOULD be
49
+ 502:resource relationship.
50
+ 513:by the client to generate the response document. This includes but is not
51
+ 515: sparse fieldsets , sorting ,
52
+ 522: Primary data MUST be either:
53
+ 541: "relationships" : {
54
+ 542: // ... this article's relationships
55
+ 559: A logical collection of resources MUST be represented as an array, even if
56
+ 566: A resource object MUST contain at least the following top-level members:
57
+ 575:case, a client MAY include a lid member to uniquely identify the resource
58
+ 582: relationships : a relationships object describing relationships between
59
+ 586:resource that can not be represented as an attribute or relationship.
60
+ 598: "relationships" : {
61
+ 601: "self" : "/articles/1/relationships/author" ,
62
+ 613: As noted above, every resource object MUST contain a
63
+ 614: type member. Every resource object MUST also contain an id member,
64
+ 617:a lid member MAY be included to uniquely identify the resource by type
65
+ 618: locally within the document. The value of the lid member MUST be
66
+ 622: The values of the id , type , and lid members MUST be strings.
67
+ 624: Within a given API, each resource object’s type and id pair MUST
68
+ 629:attributes and relationships.
69
+ 631: The values of type members MUST adhere to the same constraints as
70
+ 642: A resource object’s attributes and its relationships are collectively called
71
+ 645: Fields for a resource object MUST share a common namespace with each
72
+ 647:attribute and relationship with the same name, nor can it have an attribute
73
+ 648:or relationship named type or id .
74
+ 652: The value of the attributes key MUST be an object (an “attributes
75
+ 659: Keys that reference related resources (e.g. author_id ) SHOULD NOT appear
76
+ 660:as attributes. Instead, relationships SHOULD be used.
77
+ 668: The value of the relationships key MUST be an object (a “relationships
78
+ 669:object”). Each member of a relationships object represents
79
+ 670:a “relationship” from the resource object
80
+ 675: A relationship’s name is given by its key. The value at that key MUST be an
81
+ 676:object (“relationship object”).
82
+ 679:A “relationship object” MUST contain at least one of the following:
83
+ 684: self : a link for the relationship itself (a “relationship link”). This
84
+ 685:link allows the client to directly manipulate the relationship. For example,