json-rest-api 1.0.22 → 1.0.24

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 (290) hide show
  1. package/CLAUDE.md +1 -2
  2. package/JSKIT_BACKEND_MIGRATION_TRACKER.txt +180 -0
  3. package/README.md +22 -1
  4. package/SINGLE_VALIDATION_CONTRACT_TODO.txt +172 -0
  5. package/docs/API.md +196 -38
  6. package/docs/COMPARISON.md +2 -2
  7. package/docs/GUIDE/GUIDE_1_Initial_Setup.md +111 -5
  8. package/docs/GUIDE/GUIDE_2_2_Manipulating_And_Searching_Tables.md +5 -1
  9. package/docs/GUIDE/GUIDE_2_7_Pagination_And_Ordering.md +3 -1
  10. package/docs/GUIDE/GUIDE_2_8_Effects_of_PUT_and_PATCH.md +12 -60
  11. package/docs/GUIDE/GUIDE_2_Data_And_Relations.md +2 -2
  12. package/docs/GUIDE/GUIDE_3_Field_Transformations.md +5 -1
  13. package/docs/GUIDE/GUIDE_7_Hooks_Data_Management_And_Plugins.md +2 -0
  14. package/docs/GUIDE/GUIDE_X_Autofiltering.md +355 -0
  15. package/docs/GUIDE/GUIDE_X_Fastify.md +78 -0
  16. package/docs/GUIDE/GUIDE_X_Knex_Schema_And_Migrations.md +370 -0
  17. package/docs/GUIDE/GUIDE_X_Query_Projections.md +159 -0
  18. package/docs/GUIDE/GUIDE_X_Writing_Plugins.md +199 -0
  19. package/docs/GUIDE/index.md +18 -9
  20. package/docs/QUICKSTART.md +5 -1
  21. package/docs/index.md +1 -1
  22. package/index.js +3 -2
  23. package/lib/enhanced-logger.js +1 -1
  24. package/package.json +6 -2
  25. package/plugins/core/bulk-operations-plugin.js +26 -34
  26. package/plugins/core/connectors/express-plugin.js +97 -190
  27. package/plugins/core/connectors/fastify-plugin.js +206 -0
  28. package/plugins/core/connectors/lib/busboy-detector.js +4 -4
  29. package/plugins/core/connectors/lib/connector-core.js +195 -0
  30. package/plugins/core/connectors/lib/transport-http-helpers.js +122 -0
  31. package/plugins/core/connectors/lib/transport-route-schemas.js +92 -0
  32. package/plugins/core/lib/anyapi/schema-utils.js +43 -4
  33. package/plugins/core/lib/anyapi/utils/descriptor-helpers.js +4 -1
  34. package/plugins/core/lib/dbIntrospection.js +1078 -0
  35. package/plugins/core/lib/dbTablesOperations.js +1111 -160
  36. package/plugins/core/lib/querying/knex-cross-table-search.js +0 -7
  37. package/plugins/core/lib/querying/knex-json-api-transformers-querying.js +5 -3
  38. package/plugins/core/lib/querying/knex-process-includes.js +3 -4
  39. package/plugins/core/lib/querying/knex-query-helpers.js +21 -76
  40. package/plugins/core/lib/querying/knex-relationship-includes.js +468 -215
  41. package/plugins/core/lib/querying/query-builder-utils.js +19 -0
  42. package/plugins/core/lib/querying/query-field-sort-helpers.js +135 -0
  43. package/plugins/core/lib/querying/sort-helpers.js +33 -0
  44. package/plugins/core/lib/querying/storage-adapter-utils.js +51 -0
  45. package/plugins/core/lib/querying/url-helpers.js +8 -2
  46. package/plugins/core/lib/querying-writing/compile-schemas.js +20 -5
  47. package/plugins/core/lib/querying-writing/knex-field-helpers.js +83 -14
  48. package/plugins/core/lib/querying-writing/knex-json-api-transformers.js +13 -12
  49. package/plugins/core/lib/querying-writing/query-field-helpers.js +88 -0
  50. package/plugins/core/lib/querying-writing/request-contracts.js +590 -0
  51. package/plugins/core/lib/querying-writing/resource-id-normalization.js +131 -0
  52. package/plugins/core/lib/querying-writing/schema-helpers.js +0 -2
  53. package/plugins/core/lib/querying-writing/simplified-helpers.js +4 -11
  54. package/plugins/core/lib/storage/canonical-storage-mapping.js +133 -0
  55. package/plugins/core/lib/storage/storage-adapter.js +82 -4
  56. package/plugins/core/lib/storage/storage-mapping.js +274 -0
  57. package/plugins/core/lib/writing/many-to-many-manipulations.js +4 -2
  58. package/plugins/core/rest-api-anyapi-knex-plugin.js +531 -312
  59. package/plugins/core/rest-api-autofilter-plugin.js +414 -0
  60. package/plugins/core/rest-api-knex-plugin.js +271 -226
  61. package/plugins/core/rest-api-plugin-hooks/register-relationship-routes.js +10 -5
  62. package/plugins/core/rest-api-plugin-hooks/register-scope-routes.js +12 -6
  63. package/plugins/core/rest-api-plugin-hooks/turn-scope-init-into-vars.js +1 -0
  64. package/plugins/core/rest-api-plugin-methods/apply-query-filters.js +41 -0
  65. package/plugins/core/rest-api-plugin-methods/common.js +148 -92
  66. package/plugins/core/rest-api-plugin-methods/delete-relationship.js +11 -2
  67. package/plugins/core/rest-api-plugin-methods/delete.js +6 -1
  68. package/plugins/core/rest-api-plugin-methods/enrich-attributes.js +6 -1
  69. package/plugins/core/rest-api-plugin-methods/get-related.js +7 -2
  70. package/plugins/core/rest-api-plugin-methods/get-relationship.js +7 -2
  71. package/plugins/core/rest-api-plugin-methods/get.js +29 -14
  72. package/plugins/core/rest-api-plugin-methods/patch-relationship.js +10 -3
  73. package/plugins/core/rest-api-plugin-methods/patch.js +56 -12
  74. package/plugins/core/rest-api-plugin-methods/post-relationship.js +11 -2
  75. package/plugins/core/rest-api-plugin-methods/post.js +21 -8
  76. package/plugins/core/rest-api-plugin-methods/put.js +73 -21
  77. package/plugins/core/rest-api-plugin-methods/query.js +15 -53
  78. package/plugins/core/rest-api-plugin-methods/release.js +0 -2
  79. package/plugins/core/rest-api-plugin.js +6 -0
  80. package/plugins/core/rest-api-positioning-plugin.js +2 -5
  81. package/plugins/core/rest-api-query-projections-plugin.js +130 -0
  82. package/plugins/core/socketio-plugin.js +1 -4
  83. package/plugins/storage/local-storage.js +1 -1
  84. package/plugins/storage/s3-storage.js +5 -2
  85. package/quickTest.js +1 -0
  86. package/scripts/run-docs.js +80 -84
  87. package/test-debug.js +1 -1
  88. package/tests/README.md +7 -0
  89. package/tests/anyapi-basic.test.js +3 -0
  90. package/tests/autofilter.test.js +463 -0
  91. package/tests/custom-id-mysql-returning-fallback.test.js +128 -0
  92. package/tests/custom-id-simplified-post.test.js +75 -0
  93. package/tests/custom-idproperty-relationships.test.js +33 -0
  94. package/tests/db-introspection.test.js +521 -0
  95. package/tests/db-table-operations.test.js +786 -0
  96. package/tests/fastify-plugin.test.js +156 -0
  97. package/tests/field-getters.test.js +1 -2
  98. package/tests/field-setters.test.js +0 -4
  99. package/tests/fixtures/api-configs.js +278 -176
  100. package/tests/helpers/fake-fastify.js +99 -0
  101. package/tests/http-connectors-parity.test.js +235 -0
  102. package/tests/id-normalization.test.js +444 -0
  103. package/tests/logical-id-write-validation.test.js +151 -0
  104. package/tests/pagination-cursor-multifield.test.js +11 -11
  105. package/tests/projected-fields.test.js +319 -0
  106. package/tests/relationships.test.js +3 -3
  107. package/tests/searchschema-knex-behavior.test.js +187 -0
  108. package/tests/searchschema-merge.test.js +21 -69
  109. package/tests/storage-mapping.test.js +259 -0
  110. package/audit/00-charter.md +0 -103
  111. package/audit/01-scope-map.md +0 -84
  112. package/audit/02-coverage-matrix.csv +0 -174
  113. package/audit/03-invariants.md +0 -123
  114. package/audit/04-standards-rubric.md +0 -56
  115. package/audit/05-competitor-rubric.md +0 -77
  116. package/audit/06-findings.md +0 -160
  117. package/audit/07-risk-register.csv +0 -10
  118. package/audit/08-remediation-roadmap.md +0 -177
  119. package/audit/09-signoff-check.md +0 -23
  120. package/audit/10-final-synthesis.md +0 -29
  121. package/audit/evidence/code/all-files-json-rest-api.txt +0 -168
  122. package/audit/evidence/code/all-files-json-rest-schema.txt +0 -12
  123. package/audit/evidence/code/boundary-leak-checks.txt +0 -72
  124. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__bulk-operations-plugin.js.txt +0 -480
  125. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__express-plugin.js.txt +0 -532
  126. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__lib__busboy-detector.js.txt +0 -175
  127. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__lib__formidable-detector.js.txt +0 -138
  128. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__lib__request-helpers.js.txt +0 -222
  129. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__file-handling-plugin.js.txt +0 -342
  130. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__dbTablesOperations.js.txt +0 -304
  131. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__fractional-positioning.js.txt +0 -188
  132. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__compile-schemas.js.txt +0 -336
  133. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__connectors-query-parser.js.txt +0 -165
  134. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__database-capabilities.js.txt +0 -265
  135. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__database-value-normalizers.js.txt +0 -369
  136. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__default-data-helpers.js.txt +0 -72
  137. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__field-utils.js.txt +0 -139
  138. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__knex-constants.js.txt +0 -45
  139. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__knex-field-helpers.js.txt +0 -396
  140. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__knex-json-api-transformers.js.txt +0 -162
  141. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__payload-validators.js.txt +0 -1314
  142. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__schema-helpers.js.txt +0 -488
  143. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__scope-validations.js.txt +0 -484
  144. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__simplified-helpers.js.txt +0 -857
  145. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-cross-table-search.js.txt +0 -565
  146. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-json-api-transformers-querying.js.txt +0 -485
  147. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-pagination-helpers.js.txt +0 -560
  148. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-process-includes.js.txt +0 -167
  149. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-query-helpers-base.js.txt +0 -109
  150. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-query-helpers.js.txt +0 -1064
  151. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-relationship-includes.js.txt +0 -1983
  152. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-window-queries.js.txt +0 -328
  153. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__url-helpers.js.txt +0 -119
  154. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__storage__storage-adapter.js.txt +0 -160
  155. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__writing__many-to-many-manipulations.js.txt +0 -300
  156. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__writing__relationship-processor.js.txt +0 -245
  157. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-access.js.txt +0 -459
  158. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-cors-plugin.js.txt +0 -237
  159. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-knex-plugin.js.txt +0 -1135
  160. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-multihome-plugin.js.txt +0 -314
  161. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__compile-resource-schemas.js.txt +0 -7
  162. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__register-relationship-routes.js.txt +0 -71
  163. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__register-scope-routes.js.txt +0 -102
  164. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__turn-scope-init-into-vars.js.txt +0 -49
  165. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__validate-include-configurations.js.txt +0 -39
  166. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__add-route.js.txt +0 -23
  167. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__check-permissions.js.txt +0 -13
  168. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__common.js.txt +0 -639
  169. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__delete-relationship.js.txt +0 -117
  170. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__delete.js.txt +0 -104
  171. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__enrich-attributes.js.txt +0 -199
  172. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__get-related.js.txt +0 -353
  173. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__get-relationship.js.txt +0 -61
  174. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__get.js.txt +0 -184
  175. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__patch-relationship.js.txt +0 -55
  176. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__patch.js.txt +0 -191
  177. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__post-relationship.js.txt +0 -110
  178. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__post.js.txt +0 -168
  179. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__put.js.txt +0 -253
  180. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__query.js.txt +0 -207
  181. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__release.js.txt +0 -12
  182. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin.js.txt +0 -165
  183. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-positioning-plugin.js.txt +0 -668
  184. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__socketio-plugin.js.txt +0 -621
  185. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__storage__local-storage.js.txt +0 -218
  186. package/audit/evidence/code/critical-pass1/json-rest-api__plugins__storage__s3-storage.js.txt +0 -124
  187. package/audit/evidence/code/critical-pass1/json-rest-schema__src__CorePlugin.js.txt +0 -269
  188. package/audit/evidence/code/critical-pass1/json-rest-schema__src__Schema.js.txt +0 -242
  189. package/audit/evidence/code/critical-pass1/json-rest-schema__src__index.js.txt +0 -77
  190. package/audit/evidence/code/critical-pass1-risk-keywords.txt +0 -238
  191. package/audit/evidence/code/critical-pass1-summary.csv +0 -67
  192. package/audit/evidence/code/critical-pass2-summary.csv +0 -67
  193. package/audit/evidence/code/early-silent-zones-no-test-token.txt +0 -57
  194. package/audit/evidence/code/error-model-signals.txt +0 -98
  195. package/audit/evidence/code/git-files-json-rest-api.txt +0 -171
  196. package/audit/evidence/code/git-files-json-rest-schema.txt +0 -27
  197. package/audit/evidence/code/hook-flow-signals.txt +0 -282
  198. package/audit/evidence/code/idproperty-signals.txt +0 -157
  199. package/audit/evidence/code/import-cycles-non-anyapi.txt +0 -3
  200. package/audit/evidence/code/import-hotspots-non-anyapi.txt +0 -96
  201. package/audit/evidence/code/imports-json-rest-api.txt +0 -354
  202. package/audit/evidence/code/imports-json-rest-schema.txt +0 -15
  203. package/audit/evidence/code/in-scope-files-json-rest-api.txt +0 -160
  204. package/audit/evidence/code/in-scope-files-json-rest-schema.txt +0 -13
  205. package/audit/evidence/code/non-anyapi-core-files.txt +0 -101
  206. package/audit/evidence/code/permission-signals.txt +0 -193
  207. package/audit/evidence/code/query-include-signals.txt +0 -687
  208. package/audit/evidence/code/transaction-signals.txt +0 -28
  209. package/audit/evidence/code/validation-signals.txt +0 -650
  210. package/audit/evidence/code/write-path-signals.txt +0 -61
  211. package/audit/evidence/docs/docs-claims-signals.txt +0 -1075
  212. package/audit/evidence/docs/schema-docs-claims-signals.txt +0 -179
  213. package/audit/evidence/external/corpus-freeze.md +0 -21
  214. package/audit/evidence/external/npm-competitor-metadata.txt +0 -70
  215. package/audit/evidence/external/npm-download-signals.txt +0 -23
  216. package/audit/evidence/external/npm-jsonapi-server.txt +0 -8
  217. package/audit/evidence/external/npm-modern-jsonapi-metadata.txt +0 -38
  218. package/audit/evidence/external/readme-fortune-signals.txt +0 -26
  219. package/audit/evidence/external/readme-fortune.md +0 -165
  220. package/audit/evidence/external/readme-json-api-serializer-signals.txt +0 -80
  221. package/audit/evidence/external/readme-json-api-serializer.md +0 -690
  222. package/audit/evidence/external/readme-jsonapi-serde-server-signals.txt +0 -0
  223. package/audit/evidence/external/readme-jsonapi-serde-server.md +0 -22
  224. package/audit/evidence/external/readme-jsonapi-serializer-signals.txt +0 -63
  225. package/audit/evidence/external/readme-jsonapi-serializer.md +0 -315
  226. package/audit/evidence/external/readme-jsonapi-server-signals.txt +0 -19
  227. package/audit/evidence/external/readme-jsonapi-server.md +0 -104
  228. package/audit/evidence/external/readme-nestjs-json-api-signals.txt +0 -4
  229. package/audit/evidence/external/readme-nestjs-json-api.md +0 -94
  230. package/audit/evidence/external/readme-yaser-json-api-nestjs-signals.txt +0 -47
  231. package/audit/evidence/external/readme-yaser-json-api-nestjs.md +0 -447
  232. package/audit/evidence/external/standard-jsonapi-snippets.txt +0 -84
  233. package/audit/evidence/external/standard-rfc-snippets.txt +0 -168
  234. package/audit/evidence/external/standards-sources.txt +0 -6
  235. package/audit/evidence/runtime/baseline-commits.txt +0 -2
  236. package/audit/evidence/runtime/db-adapter-assumptions.txt +0 -3
  237. package/audit/evidence/runtime/environment.txt +0 -4
  238. package/audit/evidence/runtime/invariant-runtime-mapping.md +0 -38
  239. package/audit/evidence/runtime/probe-patch-relationship-error.exitcode +0 -1
  240. package/audit/evidence/runtime/probe-patch-relationship-error.log +0 -76
  241. package/audit/evidence/runtime/probe-patch-relationship-error.mjs +0 -67
  242. package/audit/evidence/runtime/probe-patch-relationship-referenceerror.exitcode +0 -1
  243. package/audit/evidence/runtime/probe-patch-relationship-referenceerror.log +0 -62
  244. package/audit/evidence/runtime/probe-patch-relationship-referenceerror.mjs +0 -47
  245. package/audit/evidence/runtime/test-exitcodes.txt +0 -4
  246. package/audit/evidence/runtime/test-summary.md +0 -107
  247. package/audit/evidence/runtime/trace-anchors.txt +0 -61
  248. package/audit/evidence/tests/access-multitenancy-test-signals.txt +0 -125
  249. package/audit/evidence/tests/failing-tests-summary.txt +0 -25
  250. package/audit/evidence/tests/npm-test-json-rest-api.exitcode +0 -1
  251. package/audit/evidence/tests/npm-test-json-rest-api.log +0 -5885
  252. package/audit/evidence/tests/npm-test-json-rest-schema.exitcode +0 -1
  253. package/audit/evidence/tests/npm-test-json-rest-schema.log +0 -356
  254. package/audit/evidence/tests/query-include-test-signals.txt +0 -948
  255. package/audit/evidence/tests/relationship-test-signals.txt +0 -223
  256. package/audit/evidence/tests/skipped-tests.txt +0 -10
  257. package/audit/evidence/tests/test-suite-list-non-anyapi.txt +0 -30
  258. package/audit/evidence/tests/test-suite-list.txt +0 -32
  259. package/audit/subsystems/docs-drift.md +0 -49
  260. package/audit/subsystems/pass2-cross-review.md +0 -131
  261. package/audit/subsystems/plugins-access.md +0 -51
  262. package/audit/subsystems/plugins-bulk.md +0 -50
  263. package/audit/subsystems/plugins-cors.md +0 -48
  264. package/audit/subsystems/plugins-file.md +0 -53
  265. package/audit/subsystems/plugins-multihome.md +0 -50
  266. package/audit/subsystems/plugins-positioning.md +0 -54
  267. package/audit/subsystems/plugins-socketio.md +0 -50
  268. package/audit/subsystems/query-engine.md +0 -61
  269. package/audit/subsystems/relationships.md +0 -55
  270. package/audit/subsystems/rest-orchestration.md +0 -66
  271. package/audit/subsystems/schema-core.md +0 -64
  272. package/audit/subsystems/storage-knex.md +0 -57
  273. package/audit/subsystems/tests.md +0 -48
  274. package/audit/subsystems/transport-express.md +0 -55
  275. package/audit/traces/trace-read-get.md +0 -22
  276. package/audit/traces/trace-read-query.md +0 -25
  277. package/audit/traces/trace-relationship-endpoints.md +0 -31
  278. package/audit/traces/trace-write-delete.md +0 -17
  279. package/audit/traces/trace-write-patch.md +0 -26
  280. package/audit/traces/trace-write-post.md +0 -22
  281. package/audit/traces/trace-write-put.md +0 -23
  282. package/docs/GUIDE/GUIDE_4_Authentication_And_Permissions.md +0 -707
  283. package/docs/GUIDE/GUIDE_X_Multihome.md +0 -666
  284. package/plugins/core/lib/querying-writing/payload-validators.js +0 -1314
  285. package/plugins/core/rest-api-access.js +0 -459
  286. package/plugins/core/rest-api-multihome-plugin.js +0 -314
  287. package/tests/multihome.test.js +0 -553
  288. package/tests/multihome.test.js.bak +0 -550
  289. package/tests/ownership-optout.test.js +0 -76
  290. package/tests/rest-api-access.test.js +0 -206
package/CLAUDE.md CHANGED
@@ -71,7 +71,7 @@ This separation ensures backend developers have full control and visibility into
71
71
  - `url-helpers.js` - Centralized URL generation functions
72
72
  - `knex-json-api-transformers-querying.js` - JSON:API transformations
73
73
  - `relationship-processor.js` - Handles relationship updates
74
- - `payload-validators.js` - Request validation
74
+ - `request-contracts.js` - Compiled request validation contracts
75
75
  - `knex-query-helpers.js` - Database query building
76
76
  - `simplified-helpers.js` - Simplified API mode transformations
77
77
 
@@ -158,4 +158,3 @@ const book = await api.resources.books.post({
158
158
  3. **ID Type Confusion**: SQLite returns numeric IDs, but JSON:API expects strings
159
159
  4. **Context Placement**: Context is a separate parameter, not inside the first parameter
160
160
  5. **Cleanup**: Always destroy knex connection in `after()` hook
161
-
@@ -0,0 +1,180 @@
1
+ JSKIT Backend Migration Tracker
2
+
3
+ Scope
4
+ - Move DB, schema, casting, and normalization ownership out of jskit-ai.
5
+ - Enrich json-rest-schema and json-rest-api so they can natively cover the required capability set.
6
+ - Do not add compatibility runtimes.
7
+ - Do not bend json-rest-api or json-rest-schema around jskit-ai shapes unless the capability is a clean native addition.
8
+
9
+ Status Legend
10
+ - done
11
+ - in_progress
12
+ - pending
13
+ - blocked
14
+
15
+ Execution Rule
16
+ - Complete one numbered point at a time.
17
+ - After each point, write a full report:
18
+ - what changed
19
+ - how it worked before
20
+ - how it works now
21
+ - relevant code snippets
22
+ - Stop and wait for the next user prompt before starting the next numbered point.
23
+
24
+ Work List
25
+
26
+ 0. [done] Create and maintain this tracker as the canonical work ledger.
27
+ Notes:
28
+ - This file is the progress source of truth for the migration work.
29
+ - Status changes must be recorded here before moving to the next point.
30
+
31
+ 1. [done] Tighten json-rest-schema scalar semantics.
32
+ Deliverables:
33
+ - make `id` represent the real external/resource ID contract
34
+ - tighten boolean parsing
35
+ - tighten number/integer parsing where schema should reject invalid inputs instead of silently coercing
36
+
37
+ 2. [done] Define a native json-rest-schema create/replace/patch validation contract.
38
+ Deliverables:
39
+ - explicit operation mode semantics
40
+ - presence-aware field handling
41
+ - patch behavior that preserves omission and only normalizes touched fields
42
+ - switch json-rest-api call sites to the explicit schema contract
43
+ Notes:
44
+ - verification blocker removed by deleting stale DB-helper tests from `json-rest-schema`
45
+ - DB-helper coverage now lives in `json-rest-api`, which owns `createKnexTable()` and `generateKnexMigration()`
46
+ - verified end-to-end against a local symlinked `json-rest-schema@1.0.13`; `json-rest-api` test suite passes with the new schema contract
47
+
48
+ 3. [done] Add transport-schema export from json-rest-schema.
49
+ Deliverables:
50
+ - export usable by JSON Schema / Ajv style consumers
51
+ - enough structure for pre-handler validation in connectors such as Fastify
52
+ Notes:
53
+ - added `schema.toJsonSchema({ mode, additionalProperties })` in `json-rest-schema`
54
+ - export is draft-07, mode-aware, and transport-facing rather than a clone of every in-process coercion path
55
+ - custom transport export hooks are supported through `handler.toJsonSchema`
56
+ - unknown external metadata keys are ignored; custom registered validators without a transport hook fail loudly
57
+
58
+ 4. [done] Extend json-rest-schema field metadata only where it remains schema-level meaning.
59
+ Deliverables:
60
+ - preserve useful passive metadata such as nullability, defaults, precision, scale, unsigned, enum values, and temporal precision
61
+ Notes:
62
+ - made `enum` a first-class built-in rule in `json-rest-schema`
63
+ - added canonical passive metadata support for `temporalPrecision`
64
+ - transport export now preserves passive schema metadata under `x-json-rest-schema.metadata`
65
+ - passive metadata remains schema-owned metadata; no DB-specific runtime logic was added to `json-rest-schema`
66
+
67
+ 5. [done] Add repository/storage mapping in json-rest-api.
68
+ Deliverables:
69
+ - API field to DB column mapping
70
+ - virtual/non-column fields
71
+ - write serializers where persistence formatting is required
72
+ Notes:
73
+ - added `field.storage = { column, serialize }` as the native repository/storage surface in `json-rest-api`
74
+ - storage metadata is compiled once into `schemaInfo.storageInfo`
75
+ - Knex writes now translate logical attributes to storage columns through the compiled mapping
76
+ - table creation and migration generation now respect storage column overrides
77
+ - JSON:API transformers translate storage rows back to logical field names before response shaping
78
+ - storage adapters now own row/id/select translation used by Knex callers, reducing repeated mapping helpers
79
+ - runtime row access now uses the same logical field path for `id` as for other fields: `getFieldValue(record, 'id')`
80
+ - include handling and relationship links now use logical record IDs consistently, including custom-id resources
81
+ - direct DB helper surfaces now support logical `id` fields mapped to custom storage columns without duplicate-column drift
82
+ - verified with dedicated storage-mapping tests and the full `json-rest-api` suite
83
+
84
+ 6. [done] Add DB introspection snapshot support in json-rest-api.
85
+ Deliverables:
86
+ - column type and shape introspection
87
+ - enum/set values
88
+ - indexes
89
+ - foreign keys
90
+ - check constraints
91
+ - precision/scale/temporal precision
92
+ Notes:
93
+ - added `introspectKnexTableSnapshot(knex, { tableName, idColumn })` as the native normalized snapshot helper
94
+ - snapshot support is dialect-aware for `better-sqlite3`/SQLite and `mysql2`
95
+ - SQLite captures named check constraints and foreign keys from table SQL, while indexes/columns/foreign-key actions come from PRAGMA metadata
96
+ - `RestApiKnexPlugin` now exposes `api.resources.{resource}.introspectKnexTableSnapshot()` for table-backed resources
97
+ - verified with real SQLite snapshot tests, MySQL raw-double snapshot tests, and a public scope-method test
98
+
99
+ 7. [done] Add deterministic migration generation and diffing in json-rest-api.
100
+ Deliverables:
101
+ - create and alter support
102
+ - named/composite indexes
103
+ - FK rules
104
+ - enum/set handling
105
+ - defaults and safety warnings for destructive changes
106
+ Notes:
107
+ - `dbTablesOperations` now normalizes table-level metadata (`indexes`, `foreignKeys`, `checkConstraints`) and uses one contract for live table creation, create-migration generation, and snapshot diffing
108
+ - field-level `unique` / `index` / `references` are compiled into deterministic named indexes and foreign keys instead of relying on ad hoc column builder side effects
109
+ - added `generateKnexMigrationDiff(tableName, currentSnapshot, schema, options)` returning `{ migration, warnings, plan }`
110
+ - additive diff generation supports columns, indexes, and foreign keys; destructive or unsupported changes stay explicit as warnings
111
+ - `RestApiKnexPlugin` now exposes `generateKnexMigration()` and `generateKnexMigrationDiff()` on table-backed scopes and threads table-level metadata through `schemaInfo`
112
+
113
+ 8. [done] Preserve and clarify the pass-through searchSchema contract in json-rest-api.
114
+ Deliverables:
115
+ - searchSchema validates allowed filter keys and normalizes values only
116
+ - filter meaning remains backend-owned and server-defined
117
+ - arbitrary public filter keys are supported when the backend maps them intentionally
118
+ - regression coverage for shared merge/validation behavior and invalid filter keys
119
+ Notes:
120
+ - did not introduce a generic filter DSL
121
+ - documented that searchSchema keys are public filter names, not a portable operator language
122
+ - verified that alias filters (`oneOf`) and custom backend filters (`applyFilter`) work as intended in the Knex path, where their execution semantics are owned by the backend
123
+
124
+ 9. [done] Add declarative autofiltering/scoping in json-rest-api.
125
+ Deliverables:
126
+ - public
127
+ - workspace
128
+ - user
129
+ - workspace_user
130
+ Notes:
131
+ - replaced the purpose-specific multihome surface with a generic `AutoFilterPlugin`
132
+ - resources now declare `autofilter` presets or inline filters, while the plugin resolves scope values from configured resolver functions
133
+ - `workspace`, `user`, `workspace_user`, and `public` are example presets, not built-in auth meanings
134
+ - the plugin scopes collection queries and single-record lookups, stamps scoped fields on `POST`/`PUT`, and rejects inconsistent scoped updates
135
+ - scoped `belongsTo` relationships are supported by injecting or validating JSON:API relationship identifiers before write validation
136
+ - auth/admission semantics remain out of scope for `json-rest-api`; core keeps `checkPermissions` hooks as a neutral extension point only
137
+ - shipped `AccessPlugin` was removed before this point so scoping does not inherit built-in auth assumptions
138
+
139
+ 10. [done] Add SQL-backed query projections and stable list behavior in json-rest-api.
140
+ Deliverables:
141
+ - SQL-backed output-only query fields via an optional plugin
142
+ - sparse-field and include support for declared query fields
143
+ - deterministic ordered-list / cursor behavior with stable tie-breakers
144
+ Notes:
145
+ - added an optional `QueryProjectionsPlugin` that compiles resource-level `queryFields`, separate from normal schema fields and response-layer computed fields
146
+ - query fields are selected by default, can be requested in sparse fieldsets, and are stripped from write input
147
+ - query fields can drive sorting and cursor pagination; `id` is appended as a deterministic tie-breaker
148
+ - query-field selection is supported on the Knex path and the AnyAPI Knex path, including included resources
149
+ - documented as a separate advanced guide so it does not blur with response-layer computed fields
150
+
151
+ 11. [done] Add a Fastify-oriented connector layer in json-rest-api.
152
+ Deliverables:
153
+ - consume exported schema before request handling
154
+ - no jskit-ai compatibility shim
155
+ Notes:
156
+ - added `FastifyPlugin` as a transport connector that registers REST routes on a supplied Fastify instance
157
+ - resource `POST`/`PUT`/`PATCH` routes now attach transport-facing JSON Schemas built from `schema.toJsonSchema({ mode })`, wrapped in the JSON:API document envelope
158
+ - connector-level transport schemas strip output-only/computed fields and direct `belongsTo` foreign keys from `data.attributes`, matching the existing transport write contract
159
+ - connector registers an `application/vnd.api+json` parser and rejects unsupported write content types before route handlers run
160
+ - no jskit-ai compatibility shim or duplicate hand-written field validation layer was added
161
+
162
+ 12. [pending] Remove the corresponding DB/schema/normalization ownership from jskit-ai and verify parity.
163
+ Deliverables:
164
+ - no jskit-ai-owned DB/schema normalization path remains for the migrated surface
165
+ - verification notes for anything still intentionally left outside scope
166
+
167
+ ADDENDUM ITEMS TO POINT 12:
168
+
169
+ * This is the reason we did points 1 to 11 (!).
170
+ * Needs to be done with a lot of care, since it's harder than it looks
171
+ * You MUST read AGENTS.md in jskit-ai VERY carefully, follow it VERY carefully. One of the previous attempts (4 failed in total) was unsuccessful because this step was missed. That file has important instructions on how to avoid repeated helpers and a pointer to important function maps
172
+ * There must be NOTHING left of the in house DB stuff. jskit is only a user of what json-rest-api offers.
173
+ * NO SHIMS. NO COMPATIBILITY LAYERS. NO LAYERS AT ALL. NO RUNTIMES.
174
+ * In an earlier attempt, you made a runtime that mimiked the repository's functions. NO. Repository functions will use json-rest-api's functions to do what they need to do
175
+ * A repository should be simple. It can have helper functions, but if it has a LOT of helper functions, there is a problem -- interrupt and let's talk. This happened in the workspace repository
176
+ * Multi homing is to be done with the generic filtering option of json-rest-api
177
+ * Take a LOT of care with the definiton of the resource file. Do NOT keep the old Type + Normalisation flow. That is GONE. We now have json-rest-schema, and that's what you need to use. One of the 4 failed attempts failed because you were stubborn about reusing that paradigm
178
+ * The resource file (which is what is used by the server, AND by the client) needs to be clean, and contain the right information (schemas, relationships, etc). It's a DATA ONLY file.
179
+ * The goal is to devoid jskit of any db logic/layering/
180
+
package/README.md CHANGED
@@ -72,4 +72,25 @@ app.listen(3000, () => {
72
72
  - [Quick Start](QUICKSTART.md) - Quick start
73
73
  - [Complete guide](GUIDE/) - Comprehensive guide
74
74
  - [API Reference](API.md) - API reference
75
- - [Why json-rest-api?](docs/COMPARISON.md) - Step-by-step tutorial
75
+ - [Why json-rest-api?](docs/COMPARISON.md) - Step-by-step tutorial
76
+
77
+ ## Development
78
+
79
+ ```bash
80
+ # Run the normalizeId contract suites under the default backend and AnyAPI,
81
+ # then rebuild the checked-in docs site
82
+ npm run verify
83
+
84
+ # Run lint separately
85
+ npm run lint
86
+
87
+ # Run the focused normalizeId suites directly
88
+ npm run test:id-contracts
89
+ npm run test:id-contracts:anyapi
90
+
91
+ # Rebuild the checked-in docs site
92
+ npm run docs
93
+
94
+ # Serve the docs locally with live rebuild
95
+ npm run docs:dev
96
+ ```
@@ -0,0 +1,172 @@
1
+ Single Validation Contract TODO
2
+
3
+ Goal
4
+ - Make `json-rest-schema` the single authored validation contract in `json-rest-api`.
5
+ - Keep plain JSON Schema only as a derived transport artifact for connectors.
6
+ - Remove the split between:
7
+ - resource/search validation via `json-rest-schema`
8
+ - hand-written JSON:API/query validators in `plugins/core/lib/querying-writing/payload-validators.js`
9
+
10
+ Current audit status
11
+ - [done] Audit the live validation paths and identify the actual indirection.
12
+
13
+ Root cause
14
+ - Validation is split across three places:
15
+ 1. `plugins/core/lib/querying-writing/compile-schemas.js`
16
+ - compiles resource and search schemas with `createSchema(...)`
17
+ 2. `plugins/core/lib/querying-writing/payload-validators.js`
18
+ - manually validates JSON:API request envelopes and query parameter objects
19
+ 3. `plugins/core/connectors/lib/transport-route-schemas.js`
20
+ - separately builds connector-facing JSON Schemas from `schemaInfo`
21
+ - This duplicates contract meaning across runtime and transport.
22
+ - Route methods still call imperative payload validators before calling
23
+ `schemaInstance.create()`, `schemaInstance.replace()`, or `schemaInstance.patch()`.
24
+ - `setupCommonRequest()` in `plugins/core/rest-api-plugin-methods/common.js`
25
+ also repeats some checks that are already transport-contract concerns.
26
+
27
+ What the neat end state looks like
28
+ - Authored contract:
29
+ - `json-rest-schema` only
30
+ - Derived transport schema:
31
+ - plain JSON Schema, generated from the same compiled contract
32
+ - Runtime write validation:
33
+ - uses the same compiled contract as Fastify pre-validation
34
+ - Remaining imperative checks:
35
+ - only stateful/business checks that are not schema concerns
36
+ - examples: permission checks, record existence, relationship access, complete-replace semantics
37
+
38
+ What should stay imperative
39
+ - `validateRelationshipAccess()` in `plugins/core/rest-api-plugin-methods/common.js`
40
+ - `validateCompleteReplacePayload()` in `plugins/core/rest-api-plugin-methods/common.js`
41
+ - path/body cross-source checks such as URL id vs body id consistency
42
+ - permission and data existence checks
43
+
44
+ What should stop existing
45
+ - `validateGetPayload()`
46
+ - `validateQueryPayload()`
47
+ - `validatePostPayload()`
48
+ - `validatePutPayload()`
49
+ - `validatePatchPayload()`
50
+ - duplicate route/body/query syntax checks spread across route methods and `setupCommonRequest()`
51
+
52
+ Work list
53
+
54
+ 1. [done] Define one compiled request-contract surface for resource `get/query/post/put/patch`.
55
+ Target files:
56
+ - `plugins/core/lib/querying-writing/compile-schemas.js`
57
+ - `plugins/core/connectors/lib/transport-route-schemas.js`
58
+ Deliverables:
59
+ - compile request contracts once per scope
60
+ - store them on `scope.vars.schemaInfo` or an adjacent compiled-contract object
61
+ - separate:
62
+ - write document contracts (`post`, `put`, `patch`)
63
+ - query/get contracts (`get`, `query`)
64
+ - relationship route contracts
65
+ Status:
66
+ - resource route contracts now compile once in `request-contracts.js`
67
+ - relationship route contracts are still separate and remain pending work
68
+
69
+ 2. [done] Replace manual write-document validation with compiled schema contracts.
70
+ Target files:
71
+ - `plugins/core/lib/querying-writing/payload-validators.js`
72
+ - `plugins/core/rest-api-plugin-methods/post.js`
73
+ - `plugins/core/rest-api-plugin-methods/put.js`
74
+ - `plugins/core/rest-api-plugin-methods/patch.js`
75
+ Deliverables:
76
+ - one compiled JSON:API document contract per write mode
77
+ - `data.type` constrained to the scope name inside the contract
78
+ - `data.id` required/optional according to mode
79
+ - `attributes` contract derived from `schemaInstance.toJsonSchema({ mode })`
80
+ - relationship identifier contracts derived from `schemaRelationships` and `belongsTo` metadata
81
+ - `included` rules expressed once in the contract rather than repeated manually
82
+
83
+ 3. [done] Replace manual GET/query parameter validation with compiled schema contracts.
84
+ Target files:
85
+ - `plugins/core/lib/querying-writing/payload-validators.js`
86
+ - `plugins/core/rest-api-plugin-methods/get.js`
87
+ - `plugins/core/rest-api-plugin-methods/query.js`
88
+ Deliverables:
89
+ - a compiled `get` contract for:
90
+ - `id`
91
+ - `queryParams.include`
92
+ - `queryParams.fields`
93
+ - a compiled `query` contract for:
94
+ - `include`
95
+ - `fields`
96
+ - `filters`
97
+ - `sort`
98
+ - `page`
99
+ - include-depth validation and sortable-field restrictions represented in the compiled contract, not duplicated in ad hoc code
100
+ Notes:
101
+ - `searchSchemaInstance` should remain the value contract for `filters`
102
+ - the query contract should validate the envelope/shape, not duplicate filter semantics
103
+
104
+ 4. [done] Collapse Fastify pre-validation and in-process validation onto the same source for resource write routes.
105
+ Target files:
106
+ - `plugins/core/connectors/lib/transport-route-schemas.js`
107
+ - `plugins/core/connectors/fastify-plugin.js`
108
+ - route methods in `plugins/core/rest-api-plugin-methods/`
109
+ Deliverables:
110
+ - Fastify consumes transport JSON Schema exported from the compiled request contract
111
+ - route methods consume the same compiled contract directly for runtime validation
112
+ - no second hand-written envelope contract path
113
+
114
+ 5. [done] Shrink `setupCommonRequest()` to non-schema responsibilities.
115
+ Target file:
116
+ - `plugins/core/rest-api-plugin-methods/common.js`
117
+ Deliverables:
118
+ - keep simplified-mode conversion, transaction setup, context wiring
119
+ - keep stateful/business checks only
120
+ - remove syntax/envelope checks that belong in the compiled contract
121
+ - keep only cross-input checks that a single schema cannot express cleanly
122
+
123
+ 6. [done] Delete `payload-validators.js`.
124
+ Target file:
125
+ - `plugins/core/lib/querying-writing/payload-validators.js`
126
+ Deliverables:
127
+ - no route method imports it anymore
128
+ - helper logic worth keeping is either:
129
+ - absorbed into compiled contracts
130
+ - or moved into narrowly named stateful helpers
131
+
132
+ 7. [done] Tighten tests around the single-contract flow.
133
+ Target areas:
134
+ - `tests/fastify-plugin.test.js`
135
+ - route method coverage exercised by the existing REST suites
136
+ - add one focused contract test suite if needed
137
+ Deliverables:
138
+ - prove Fastify pre-validation and runtime validation reject the same bad inputs
139
+ - cover:
140
+ - wrong `data.type`
141
+ - missing/invalid `data.id`
142
+ - invalid relationships
143
+ - invalid query/include/page/sort shapes
144
+ - verify there is no drift between transport schema and runtime schema behavior
145
+
146
+ 8. [done] Proof cleanup.
147
+ Deliverables:
148
+ - `rg` proof that route methods no longer import `payload-validators.js`
149
+ - `rg` proof that `validateGetPayload`, `validateQueryPayload`, `validatePostPayload`,
150
+ `validatePutPayload`, and `validatePatchPayload` are gone
151
+ - `npm test`
152
+
153
+ Current state
154
+ - Resource `get/query/post/put/patch` now use one compiled contract source.
155
+ - Fastify transport schemas for those resource routes are derived from the same compiled contract.
156
+ - `payload-validators.js` is deleted.
157
+ - `npm test` passes.
158
+ - The main remaining simplification is the separate relationship-route contract path.
159
+
160
+ File map for the next implementation pass
161
+ - Remaining relationship-route cleanup:
162
+ - `plugins/core/rest-api-plugin-methods/post-relationship.js`
163
+ - `plugins/core/rest-api-plugin-methods/patch-relationship.js`
164
+ - `plugins/core/rest-api-plugin-methods/delete-relationship.js`
165
+ - Transport schema generator to reuse, not duplicate:
166
+ - `plugins/core/connectors/lib/transport-route-schemas.js`
167
+
168
+ Explicit non-goals
169
+ - Do not move permission checks into schemas.
170
+ - Do not move DB existence checks into schemas.
171
+ - Do not turn `searchSchema` into a generic filter DSL.
172
+ - Do not add a compatibility layer that preserves both manual validators and compiled contracts.