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.
- package/CLAUDE.md +1 -2
- package/JSKIT_BACKEND_MIGRATION_TRACKER.txt +180 -0
- package/README.md +22 -1
- package/SINGLE_VALIDATION_CONTRACT_TODO.txt +172 -0
- package/docs/API.md +196 -38
- package/docs/COMPARISON.md +2 -2
- package/docs/GUIDE/GUIDE_1_Initial_Setup.md +111 -5
- package/docs/GUIDE/GUIDE_2_2_Manipulating_And_Searching_Tables.md +5 -1
- package/docs/GUIDE/GUIDE_2_7_Pagination_And_Ordering.md +3 -1
- package/docs/GUIDE/GUIDE_2_8_Effects_of_PUT_and_PATCH.md +12 -60
- package/docs/GUIDE/GUIDE_2_Data_And_Relations.md +2 -2
- package/docs/GUIDE/GUIDE_3_Field_Transformations.md +5 -1
- package/docs/GUIDE/GUIDE_7_Hooks_Data_Management_And_Plugins.md +2 -0
- package/docs/GUIDE/GUIDE_X_Autofiltering.md +355 -0
- package/docs/GUIDE/GUIDE_X_Fastify.md +78 -0
- package/docs/GUIDE/GUIDE_X_Knex_Schema_And_Migrations.md +370 -0
- package/docs/GUIDE/GUIDE_X_Query_Projections.md +159 -0
- package/docs/GUIDE/GUIDE_X_Writing_Plugins.md +199 -0
- package/docs/GUIDE/index.md +18 -9
- package/docs/QUICKSTART.md +5 -1
- package/docs/index.md +1 -1
- package/index.js +3 -2
- package/lib/enhanced-logger.js +1 -1
- package/package.json +6 -2
- package/plugins/core/bulk-operations-plugin.js +26 -34
- package/plugins/core/connectors/express-plugin.js +97 -190
- package/plugins/core/connectors/fastify-plugin.js +206 -0
- package/plugins/core/connectors/lib/busboy-detector.js +4 -4
- package/plugins/core/connectors/lib/connector-core.js +195 -0
- package/plugins/core/connectors/lib/transport-http-helpers.js +122 -0
- package/plugins/core/connectors/lib/transport-route-schemas.js +92 -0
- package/plugins/core/lib/anyapi/schema-utils.js +43 -4
- package/plugins/core/lib/anyapi/utils/descriptor-helpers.js +4 -1
- package/plugins/core/lib/dbIntrospection.js +1078 -0
- package/plugins/core/lib/dbTablesOperations.js +1111 -160
- package/plugins/core/lib/querying/knex-cross-table-search.js +0 -7
- package/plugins/core/lib/querying/knex-json-api-transformers-querying.js +5 -3
- package/plugins/core/lib/querying/knex-process-includes.js +3 -4
- package/plugins/core/lib/querying/knex-query-helpers.js +21 -76
- package/plugins/core/lib/querying/knex-relationship-includes.js +468 -215
- package/plugins/core/lib/querying/query-builder-utils.js +19 -0
- package/plugins/core/lib/querying/query-field-sort-helpers.js +135 -0
- package/plugins/core/lib/querying/sort-helpers.js +33 -0
- package/plugins/core/lib/querying/storage-adapter-utils.js +51 -0
- package/plugins/core/lib/querying/url-helpers.js +8 -2
- package/plugins/core/lib/querying-writing/compile-schemas.js +20 -5
- package/plugins/core/lib/querying-writing/knex-field-helpers.js +83 -14
- package/plugins/core/lib/querying-writing/knex-json-api-transformers.js +13 -12
- package/plugins/core/lib/querying-writing/query-field-helpers.js +88 -0
- package/plugins/core/lib/querying-writing/request-contracts.js +590 -0
- package/plugins/core/lib/querying-writing/resource-id-normalization.js +131 -0
- package/plugins/core/lib/querying-writing/schema-helpers.js +0 -2
- package/plugins/core/lib/querying-writing/simplified-helpers.js +4 -11
- package/plugins/core/lib/storage/canonical-storage-mapping.js +133 -0
- package/plugins/core/lib/storage/storage-adapter.js +82 -4
- package/plugins/core/lib/storage/storage-mapping.js +274 -0
- package/plugins/core/lib/writing/many-to-many-manipulations.js +4 -2
- package/plugins/core/rest-api-anyapi-knex-plugin.js +531 -312
- package/plugins/core/rest-api-autofilter-plugin.js +414 -0
- package/plugins/core/rest-api-knex-plugin.js +271 -226
- package/plugins/core/rest-api-plugin-hooks/register-relationship-routes.js +10 -5
- package/plugins/core/rest-api-plugin-hooks/register-scope-routes.js +12 -6
- package/plugins/core/rest-api-plugin-hooks/turn-scope-init-into-vars.js +1 -0
- package/plugins/core/rest-api-plugin-methods/apply-query-filters.js +41 -0
- package/plugins/core/rest-api-plugin-methods/common.js +148 -92
- package/plugins/core/rest-api-plugin-methods/delete-relationship.js +11 -2
- package/plugins/core/rest-api-plugin-methods/delete.js +6 -1
- package/plugins/core/rest-api-plugin-methods/enrich-attributes.js +6 -1
- package/plugins/core/rest-api-plugin-methods/get-related.js +7 -2
- package/plugins/core/rest-api-plugin-methods/get-relationship.js +7 -2
- package/plugins/core/rest-api-plugin-methods/get.js +29 -14
- package/plugins/core/rest-api-plugin-methods/patch-relationship.js +10 -3
- package/plugins/core/rest-api-plugin-methods/patch.js +56 -12
- package/plugins/core/rest-api-plugin-methods/post-relationship.js +11 -2
- package/plugins/core/rest-api-plugin-methods/post.js +21 -8
- package/plugins/core/rest-api-plugin-methods/put.js +73 -21
- package/plugins/core/rest-api-plugin-methods/query.js +15 -53
- package/plugins/core/rest-api-plugin-methods/release.js +0 -2
- package/plugins/core/rest-api-plugin.js +6 -0
- package/plugins/core/rest-api-positioning-plugin.js +2 -5
- package/plugins/core/rest-api-query-projections-plugin.js +130 -0
- package/plugins/core/socketio-plugin.js +1 -4
- package/plugins/storage/local-storage.js +1 -1
- package/plugins/storage/s3-storage.js +5 -2
- package/quickTest.js +1 -0
- package/scripts/run-docs.js +80 -84
- package/test-debug.js +1 -1
- package/tests/README.md +7 -0
- package/tests/anyapi-basic.test.js +3 -0
- package/tests/autofilter.test.js +463 -0
- package/tests/custom-id-mysql-returning-fallback.test.js +128 -0
- package/tests/custom-id-simplified-post.test.js +75 -0
- package/tests/custom-idproperty-relationships.test.js +33 -0
- package/tests/db-introspection.test.js +521 -0
- package/tests/db-table-operations.test.js +786 -0
- package/tests/fastify-plugin.test.js +156 -0
- package/tests/field-getters.test.js +1 -2
- package/tests/field-setters.test.js +0 -4
- package/tests/fixtures/api-configs.js +278 -176
- package/tests/helpers/fake-fastify.js +99 -0
- package/tests/http-connectors-parity.test.js +235 -0
- package/tests/id-normalization.test.js +444 -0
- package/tests/logical-id-write-validation.test.js +151 -0
- package/tests/pagination-cursor-multifield.test.js +11 -11
- package/tests/projected-fields.test.js +319 -0
- package/tests/relationships.test.js +3 -3
- package/tests/searchschema-knex-behavior.test.js +187 -0
- package/tests/searchschema-merge.test.js +21 -69
- package/tests/storage-mapping.test.js +259 -0
- package/audit/00-charter.md +0 -103
- package/audit/01-scope-map.md +0 -84
- package/audit/02-coverage-matrix.csv +0 -174
- package/audit/03-invariants.md +0 -123
- package/audit/04-standards-rubric.md +0 -56
- package/audit/05-competitor-rubric.md +0 -77
- package/audit/06-findings.md +0 -160
- package/audit/07-risk-register.csv +0 -10
- package/audit/08-remediation-roadmap.md +0 -177
- package/audit/09-signoff-check.md +0 -23
- package/audit/10-final-synthesis.md +0 -29
- package/audit/evidence/code/all-files-json-rest-api.txt +0 -168
- package/audit/evidence/code/all-files-json-rest-schema.txt +0 -12
- package/audit/evidence/code/boundary-leak-checks.txt +0 -72
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__bulk-operations-plugin.js.txt +0 -480
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__express-plugin.js.txt +0 -532
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__lib__busboy-detector.js.txt +0 -175
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__lib__formidable-detector.js.txt +0 -138
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__connectors__lib__request-helpers.js.txt +0 -222
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__file-handling-plugin.js.txt +0 -342
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__dbTablesOperations.js.txt +0 -304
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__fractional-positioning.js.txt +0 -188
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__compile-schemas.js.txt +0 -336
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__connectors-query-parser.js.txt +0 -165
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__database-capabilities.js.txt +0 -265
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__database-value-normalizers.js.txt +0 -369
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__default-data-helpers.js.txt +0 -72
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__field-utils.js.txt +0 -139
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__knex-constants.js.txt +0 -45
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__knex-field-helpers.js.txt +0 -396
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__knex-json-api-transformers.js.txt +0 -162
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__payload-validators.js.txt +0 -1314
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__schema-helpers.js.txt +0 -488
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__scope-validations.js.txt +0 -484
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying-writing__simplified-helpers.js.txt +0 -857
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-cross-table-search.js.txt +0 -565
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-json-api-transformers-querying.js.txt +0 -485
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-pagination-helpers.js.txt +0 -560
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-process-includes.js.txt +0 -167
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-query-helpers-base.js.txt +0 -109
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-query-helpers.js.txt +0 -1064
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-relationship-includes.js.txt +0 -1983
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__knex-window-queries.js.txt +0 -328
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__querying__url-helpers.js.txt +0 -119
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__storage__storage-adapter.js.txt +0 -160
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__writing__many-to-many-manipulations.js.txt +0 -300
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__lib__writing__relationship-processor.js.txt +0 -245
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-access.js.txt +0 -459
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-cors-plugin.js.txt +0 -237
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-knex-plugin.js.txt +0 -1135
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-multihome-plugin.js.txt +0 -314
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__compile-resource-schemas.js.txt +0 -7
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__register-relationship-routes.js.txt +0 -71
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__register-scope-routes.js.txt +0 -102
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__turn-scope-init-into-vars.js.txt +0 -49
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-hooks__validate-include-configurations.js.txt +0 -39
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__add-route.js.txt +0 -23
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__check-permissions.js.txt +0 -13
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__common.js.txt +0 -639
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__delete-relationship.js.txt +0 -117
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__delete.js.txt +0 -104
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__enrich-attributes.js.txt +0 -199
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__get-related.js.txt +0 -353
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__get-relationship.js.txt +0 -61
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__get.js.txt +0 -184
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__patch-relationship.js.txt +0 -55
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__patch.js.txt +0 -191
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__post-relationship.js.txt +0 -110
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__post.js.txt +0 -168
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__put.js.txt +0 -253
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__query.js.txt +0 -207
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin-methods__release.js.txt +0 -12
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-plugin.js.txt +0 -165
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__rest-api-positioning-plugin.js.txt +0 -668
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__core__socketio-plugin.js.txt +0 -621
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__storage__local-storage.js.txt +0 -218
- package/audit/evidence/code/critical-pass1/json-rest-api__plugins__storage__s3-storage.js.txt +0 -124
- package/audit/evidence/code/critical-pass1/json-rest-schema__src__CorePlugin.js.txt +0 -269
- package/audit/evidence/code/critical-pass1/json-rest-schema__src__Schema.js.txt +0 -242
- package/audit/evidence/code/critical-pass1/json-rest-schema__src__index.js.txt +0 -77
- package/audit/evidence/code/critical-pass1-risk-keywords.txt +0 -238
- package/audit/evidence/code/critical-pass1-summary.csv +0 -67
- package/audit/evidence/code/critical-pass2-summary.csv +0 -67
- package/audit/evidence/code/early-silent-zones-no-test-token.txt +0 -57
- package/audit/evidence/code/error-model-signals.txt +0 -98
- package/audit/evidence/code/git-files-json-rest-api.txt +0 -171
- package/audit/evidence/code/git-files-json-rest-schema.txt +0 -27
- package/audit/evidence/code/hook-flow-signals.txt +0 -282
- package/audit/evidence/code/idproperty-signals.txt +0 -157
- package/audit/evidence/code/import-cycles-non-anyapi.txt +0 -3
- package/audit/evidence/code/import-hotspots-non-anyapi.txt +0 -96
- package/audit/evidence/code/imports-json-rest-api.txt +0 -354
- package/audit/evidence/code/imports-json-rest-schema.txt +0 -15
- package/audit/evidence/code/in-scope-files-json-rest-api.txt +0 -160
- package/audit/evidence/code/in-scope-files-json-rest-schema.txt +0 -13
- package/audit/evidence/code/non-anyapi-core-files.txt +0 -101
- package/audit/evidence/code/permission-signals.txt +0 -193
- package/audit/evidence/code/query-include-signals.txt +0 -687
- package/audit/evidence/code/transaction-signals.txt +0 -28
- package/audit/evidence/code/validation-signals.txt +0 -650
- package/audit/evidence/code/write-path-signals.txt +0 -61
- package/audit/evidence/docs/docs-claims-signals.txt +0 -1075
- package/audit/evidence/docs/schema-docs-claims-signals.txt +0 -179
- package/audit/evidence/external/corpus-freeze.md +0 -21
- package/audit/evidence/external/npm-competitor-metadata.txt +0 -70
- package/audit/evidence/external/npm-download-signals.txt +0 -23
- package/audit/evidence/external/npm-jsonapi-server.txt +0 -8
- package/audit/evidence/external/npm-modern-jsonapi-metadata.txt +0 -38
- package/audit/evidence/external/readme-fortune-signals.txt +0 -26
- package/audit/evidence/external/readme-fortune.md +0 -165
- package/audit/evidence/external/readme-json-api-serializer-signals.txt +0 -80
- package/audit/evidence/external/readme-json-api-serializer.md +0 -690
- package/audit/evidence/external/readme-jsonapi-serde-server-signals.txt +0 -0
- package/audit/evidence/external/readme-jsonapi-serde-server.md +0 -22
- package/audit/evidence/external/readme-jsonapi-serializer-signals.txt +0 -63
- package/audit/evidence/external/readme-jsonapi-serializer.md +0 -315
- package/audit/evidence/external/readme-jsonapi-server-signals.txt +0 -19
- package/audit/evidence/external/readme-jsonapi-server.md +0 -104
- package/audit/evidence/external/readme-nestjs-json-api-signals.txt +0 -4
- package/audit/evidence/external/readme-nestjs-json-api.md +0 -94
- package/audit/evidence/external/readme-yaser-json-api-nestjs-signals.txt +0 -47
- package/audit/evidence/external/readme-yaser-json-api-nestjs.md +0 -447
- package/audit/evidence/external/standard-jsonapi-snippets.txt +0 -84
- package/audit/evidence/external/standard-rfc-snippets.txt +0 -168
- package/audit/evidence/external/standards-sources.txt +0 -6
- package/audit/evidence/runtime/baseline-commits.txt +0 -2
- package/audit/evidence/runtime/db-adapter-assumptions.txt +0 -3
- package/audit/evidence/runtime/environment.txt +0 -4
- package/audit/evidence/runtime/invariant-runtime-mapping.md +0 -38
- package/audit/evidence/runtime/probe-patch-relationship-error.exitcode +0 -1
- package/audit/evidence/runtime/probe-patch-relationship-error.log +0 -76
- package/audit/evidence/runtime/probe-patch-relationship-error.mjs +0 -67
- package/audit/evidence/runtime/probe-patch-relationship-referenceerror.exitcode +0 -1
- package/audit/evidence/runtime/probe-patch-relationship-referenceerror.log +0 -62
- package/audit/evidence/runtime/probe-patch-relationship-referenceerror.mjs +0 -47
- package/audit/evidence/runtime/test-exitcodes.txt +0 -4
- package/audit/evidence/runtime/test-summary.md +0 -107
- package/audit/evidence/runtime/trace-anchors.txt +0 -61
- package/audit/evidence/tests/access-multitenancy-test-signals.txt +0 -125
- package/audit/evidence/tests/failing-tests-summary.txt +0 -25
- package/audit/evidence/tests/npm-test-json-rest-api.exitcode +0 -1
- package/audit/evidence/tests/npm-test-json-rest-api.log +0 -5885
- package/audit/evidence/tests/npm-test-json-rest-schema.exitcode +0 -1
- package/audit/evidence/tests/npm-test-json-rest-schema.log +0 -356
- package/audit/evidence/tests/query-include-test-signals.txt +0 -948
- package/audit/evidence/tests/relationship-test-signals.txt +0 -223
- package/audit/evidence/tests/skipped-tests.txt +0 -10
- package/audit/evidence/tests/test-suite-list-non-anyapi.txt +0 -30
- package/audit/evidence/tests/test-suite-list.txt +0 -32
- package/audit/subsystems/docs-drift.md +0 -49
- package/audit/subsystems/pass2-cross-review.md +0 -131
- package/audit/subsystems/plugins-access.md +0 -51
- package/audit/subsystems/plugins-bulk.md +0 -50
- package/audit/subsystems/plugins-cors.md +0 -48
- package/audit/subsystems/plugins-file.md +0 -53
- package/audit/subsystems/plugins-multihome.md +0 -50
- package/audit/subsystems/plugins-positioning.md +0 -54
- package/audit/subsystems/plugins-socketio.md +0 -50
- package/audit/subsystems/query-engine.md +0 -61
- package/audit/subsystems/relationships.md +0 -55
- package/audit/subsystems/rest-orchestration.md +0 -66
- package/audit/subsystems/schema-core.md +0 -64
- package/audit/subsystems/storage-knex.md +0 -57
- package/audit/subsystems/tests.md +0 -48
- package/audit/subsystems/transport-express.md +0 -55
- package/audit/traces/trace-read-get.md +0 -22
- package/audit/traces/trace-read-query.md +0 -25
- package/audit/traces/trace-relationship-endpoints.md +0 -31
- package/audit/traces/trace-write-delete.md +0 -17
- package/audit/traces/trace-write-patch.md +0 -26
- package/audit/traces/trace-write-post.md +0 -22
- package/audit/traces/trace-write-put.md +0 -23
- package/docs/GUIDE/GUIDE_4_Authentication_And_Permissions.md +0 -707
- package/docs/GUIDE/GUIDE_X_Multihome.md +0 -666
- package/plugins/core/lib/querying-writing/payload-validators.js +0 -1314
- package/plugins/core/rest-api-access.js +0 -459
- package/plugins/core/rest-api-multihome-plugin.js +0 -314
- package/tests/multihome.test.js +0 -553
- package/tests/multihome.test.js.bak +0 -550
- package/tests/ownership-optout.test.js +0 -76
- package/tests/rest-api-access.test.js +0 -206
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:12:* **Clear Separation of Concerns:** The responsibility for *defining* types/validators is separate from the responsibility for *applying* them during validation.
|
|
2
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:13:* **Plugin-Based Extensibility:** New types and validators can be seamlessly added through a straightforward plugin system.
|
|
3
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:24:This file is the true heart and soul of the library. It acts as the central coordinator, managing the global collection of type and validator handlers, and providing the primary interface for users.
|
|
4
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:30: * **Crucially, these objects are *not* directly exported.** This design choice makes them effectively "private" to the `index.js` module's scope. They serve as the single, authoritative source for all registered type casting functions and validation logic across the entire application's lifetime when this library is imported.
|
|
5
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:31: * Think of them as the library's internal knowledge base for how to process different data types and apply various rules.
|
|
6
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:34: * To allow external code (including plugins) to add to our `globalTypes` and `globalValidators` registries, `index.js` exports two dedicated functions: `export function addType(...)` and `export function addValidator(...)`.
|
|
7
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:35: * These functions are straightforward: they take a `name` (e.g., `'string'`, `'min'`) and a `handler` function, perform a basic type check on the handler, and then assign it to the respective `globalTypes` or `globalValidators` object using the given `name` as the key.
|
|
8
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:39: * The `export function use(plugin)` function is our gateway for extensibility. It expects a `plugin` object that *must* have an `install` method.
|
|
9
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:40: * When `use(plugin)` is called, it executes `plugin.install()`.
|
|
10
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:41: * The `use` function passes a simple API object to the plugin's `install` method: `{ addType, addValidator }`. This means the plugin only receives the specific functions it needs to register its handlers, without having to know or interact with any other internal structures. It's clean, minimal, and promotes loose coupling.
|
|
11
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:43:* **The Schema Factory (`createSchema`):**
|
|
12
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:44: * The `const createSchema = (structure) => new Schema(structure, globalTypes, globalValidators);` function is the primary way users will interact with the library to define a new schema.
|
|
13
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:45: * When you call `createSchema({ /* your schema definition */ })`, it doesn't return some intermediary manager. Instead, it directly instantiates a new `Schema` object (from `./src/Schema.js`).
|
|
14
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:46: * **Crucially, it passes the *current references* to our `globalTypes` and `globalValidators` objects to the new `Schema` instance's constructor.** This means every `Schema` object created will automatically be "aware" of all the types and validators that have been registered globally up to that point.
|
|
15
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:48:* **The Public API (`createSchema.addType`, `createSchema.addValidator`, `createSchema.use`):**
|
|
16
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:49: * For user convenience and to maintain a familiar API shape (if you've seen similar libraries), we attach the globally exported `addType`, `addValidator`, and `use` functions as properties directly onto the `createSchema` function itself:
|
|
17
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:51: createSchema.addType = addType;
|
|
18
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:52: createSchema.addValidator = addValidator;
|
|
19
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:53: createSchema.use = use;
|
|
20
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:55: * This allows consumers of the library to import just one thing (`import createSchema from 'jsonrestapi-schema';`) and then access all core functionalities through it: `createSchema(...)`, `createSchema.addType(...)`, `createSchema.use(...)`.
|
|
21
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:58: * Right before the final export, `index.js` explicitly calls `createSchema.use(CorePlugin);`.
|
|
22
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:59: * This ensures that as soon as your application imports `jsonrestapi-schema`, all the built-in types (like `string`, `number`, `boolean`) and validators (like `min`, `max`, `required`) are automatically registered and ready for use. No extra setup step is required for basic functionality.
|
|
23
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:61:### 2.2. `./src/Schema.js` - The Validation Workhorse
|
|
24
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:63:While `index.js` manages the global registries, the `Schema` class is where the actual validation magic happens for a *specific* schema definition.
|
|
25
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:65:**Key Features of `Schema.js`:**
|
|
26
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:67:* **Self-Contained Validation Logic:** Each instance of `Schema` represents a single, defined data structure. It contains the logic to traverse an input object, apply type casting, and run validation rules against its own `structure`.
|
|
27
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:68:* **Dependency Injection in Constructor:** Unlike the previous design, the `Schema` constructor (`constructor(structure, types, validators)`) now explicitly receives the `types` and `validators` registries it needs from the `createSchema` factory function. This makes its dependencies clear and improves its testability.
|
|
28
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:70: 1. **Pre-checks:** Handling `required` rules, skipping fields, and dealing with `null` or empty values based on options.
|
|
29
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:71: 2. **Type Casting:** It looks up the appropriate type handler from its received `this.types` registry and attempts to transform the field's value.
|
|
30
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:72: 3. **Parameter Validation:** It then iterates through any validation parameters defined for the field (e.g., `min`, `max`, `validator`), looks up their respective handlers in `this.validators`, and applies them.
|
|
31
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:77:This file simply defines all the standard, built-in type and validator handlers that come with the library.
|
|
32
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:81:* **The `install` Method:** This is the critical part. As discussed, its `install` method is designed to receive the `addType` and `addValidator` functions. It then calls these functions multiple times, registering all the core functionalities like `string`, `number`, `boolean` types, and `min`, `max`, `notEmpty` validators.
|
|
33
|
-
/home/merc/Development/current/json-rest-schema/ONBOARDING.md:82:* **Clear Definition of Default Handlers:** It provides well-defined functions for common data transformations and validation checks, serving as excellent examples for how to write your own custom types and validators.
|
|
34
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:1:# Future Migration Module: json-rest-schema-migrations
|
|
35
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:5:This document outlines the design and implementation plan for `json-rest-schema-migrations`, a companion package that would provide automatic differential migration generation for `json-rest-schema` schemas using Knex's database abstraction.
|
|
36
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:9:Earlier versions of `json-rest-schema` included helpers such as `generateKnexMigration()` to scaffold an initial table, but that functionality has since been removed from the core package. The need that sparked those helpers remains: as applications grow, schemas change — fields are added, types are modified, constraints are updated. Manually writing migration files for these changes is error-prone and time-consuming.
|
|
37
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:20:### 1. Schema State Management
|
|
38
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:32: "email": { "type": "string", "required": true, "maxLength": 255 },
|
|
39
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:33: "name": { "type": "string", "nullable": true }
|
|
40
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:43:import createSchema from 'json-rest-schema';
|
|
41
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:44:import { MigrationManager } from 'json-rest-schema-migrations';
|
|
42
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:55:const userSchema = createSchema({
|
|
43
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:56: email: { type: 'string', required: true, maxLength: 255 },
|
|
44
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:57: name: { type: 'string', nullable: false }, // Changed: was nullable
|
|
45
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:58: age: { type: 'number', min: 0 }, // Added
|
|
46
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:63:const result = await manager.generateMigration('users', userSchema, {
|
|
47
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:87: async getTableSchema(tableName) {
|
|
48
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:91: // Normalize to json-rest-schema format
|
|
49
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:100: type: this.mapKnexType(info.type),
|
|
50
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:101: nullable: info.nullable,
|
|
51
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:103: defaultTo: info.defaultValue,
|
|
52
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:112: const typeMap = {
|
|
53
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:125: return typeMap[dbType.toLowerCase()] || 'string';
|
|
54
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:130:### Phase 2: Schema Diff Engine
|
|
55
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:133:class SchemaDiffer {
|
|
56
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:134: diff(currentSchema, targetSchema) {
|
|
57
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:143: for (const [field, def] of Object.entries(targetSchema)) {
|
|
58
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:144: if (!currentSchema[field]) {
|
|
59
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:154: for (const [field, current] of Object.entries(currentSchema)) {
|
|
60
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:155: const target = targetSchema[field];
|
|
61
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:168: for (const field of Object.keys(currentSchema)) {
|
|
62
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:169: if (!targetSchema[field]) {
|
|
63
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:172: definition: currentSchema[field],
|
|
64
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:183: const props = ['type', 'nullable', 'maxLength', 'unique', 'defaultTo'];
|
|
65
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:191: if (from.type !== to.type) {
|
|
66
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:192: if (from.type === 'string' && to.type === 'number') {
|
|
67
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:195: if (from.type === 'number' && to.type === 'string' && to.maxLength) {
|
|
68
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:200: // Nullable to required
|
|
69
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:201: if (from.nullable && !to.nullable) {
|
|
70
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:202: warnings.push('Making field required will fail if NULL values exist');
|
|
71
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:266: // Map type
|
|
72
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:267: switch (definition.type) {
|
|
73
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:298: if (!definition.nullable) code += '.notNullable()';
|
|
74
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:300: if (definition.defaultTo !== undefined) {
|
|
75
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:301: const value = typeof definition.defaultTo === 'string'
|
|
76
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:302: ? `'${definition.defaultTo}'`
|
|
77
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:303: : definition.defaultTo;
|
|
78
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:304: code += `.defaultTo(${value})`;
|
|
79
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:321: if (change.from.nullable && !change.to.nullable) {
|
|
80
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:329: type: 'error',
|
|
81
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:331: message: `Cannot make field required: ${nullCount[0].count} NULL values exist`
|
|
82
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:336: if (change.from.type !== change.to.type) {
|
|
83
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:346: change.from.type,
|
|
84
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:347: change.to.type
|
|
85
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:352: type: 'error',
|
|
86
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:372:const userSchema = createSchema({
|
|
87
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:373: email: { type: 'string', required: true, unique: true },
|
|
88
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:374: name: { type: 'string' }
|
|
89
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:378:await manager.createInitialMigration('users', userSchema);
|
|
90
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:380:// 2. Later: Add age field, make name required
|
|
91
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:381:const updatedSchema = createSchema({
|
|
92
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:382: email: { type: 'string', required: true, unique: true },
|
|
93
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:383: name: { type: 'string', required: true }, // Changed
|
|
94
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:384: age: { type: 'number', min: 0 } // Added
|
|
95
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:388:await manager.generateMigration('users', updatedSchema);
|
|
96
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:395:const plan = await manager.generateMigration('users', updatedSchema, {
|
|
97
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:401: console.log(`- ${change.type}: ${change.field}`);
|
|
98
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:415:const result = await manager.generateMigration('products', productSchema, {
|
|
99
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:434: // Schema state tracking
|
|
100
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:440: // Custom type mappings
|
|
101
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:441: typeMappings: {
|
|
102
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:476:1. Add new nullable column
|
|
103
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:478:3. Make it required
|
|
104
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:518:### 3. Schema Snapshots
|
|
105
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:524:const diff = await manager.compareWithSnapshot('users', userSchema);
|
|
106
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:558: const oldSchema = createSchema({ email: { type: 'string' } });
|
|
107
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:559: const newSchema = createSchema({
|
|
108
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:560: email: { type: 'string' },
|
|
109
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:561: age: { type: 'number' }
|
|
110
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:564: const changes = await manager.detectChanges('users', newSchema);
|
|
111
|
-
/home/merc/Development/current/json-rest-schema/FUTURE_MIGRATION_MODULE.md:587:This migration module would significantly enhance the json-rest-schema ecosystem by providing:
|
|
112
|
-
/home/merc/Development/current/json-rest-schema/README.md:1:# How to Use the Schema Validation Library: A Tutorial
|
|
113
|
-
/home/merc/Development/current/json-rest-schema/README.md:5:## 1. Getting Started: Your First Schema
|
|
114
|
-
/home/merc/Development/current/json-rest-schema/README.md:12:import createSchema from './src/index.js';
|
|
115
|
-
/home/merc/Development/current/json-rest-schema/README.md:15:const userSchema = createSchema({
|
|
116
|
-
/home/merc/Development/current/json-rest-schema/README.md:16: username: { type: 'string', required: true, minLength: 3 },
|
|
117
|
-
/home/merc/Development/current/json-rest-schema/README.md:17: email: { type: 'string', required: true },
|
|
118
|
-
/home/merc/Development/current/json-rest-schema/README.md:18: age: { type: 'number', min: 18, defaultTo: 18 }
|
|
119
|
-
/home/merc/Development/current/json-rest-schema/README.md:34: const { validatedObject, errors } = await userSchema.validate(userInput);
|
|
120
|
-
/home/merc/Development/current/json-rest-schema/README.md:51:1. The `age` string `'25'` is **cast** to the number `25` by the `number` type handler.
|
|
121
|
-
/home/merc/Development/current/json-rest-schema/README.md:52:2. The `username` string `' alex '` is **transformed** by the `string` type handler to `'alex'` (it gets trimmed).
|
|
122
|
-
/home/merc/Development/current/json-rest-schema/README.md:78: // email is missing, fails 'required: true'
|
|
123
|
-
/home/merc/Development/current/json-rest-schema/README.md:82:const { validatedObject, errors } = await userSchema.validate(invalidInput);
|
|
124
|
-
/home/merc/Development/current/json-rest-schema/README.md:100: "message": "Field is required",
|
|
125
|
-
/home/merc/Development/current/json-rest-schema/README.md:114:* **`params`**: Extra context about the failure. This is incredibly useful for creating dynamic error messages (e.g., "You entered 2 characters, but a minimum of 3 is required.").
|
|
126
|
-
/home/merc/Development/current/json-rest-schema/README.md:120:Here is a complete list of all types and validators available out of the box.
|
|
127
|
-
/home/merc/Development/current/json-rest-schema/README.md:124:A field's `type` defines how the input value will be converted before any other validation rules are run.
|
|
128
|
-
/home/merc/Development/current/json-rest-schema/README.md:139:| `none` | The "identity" type. Passes the value through completely unchanged without any casting. |
|
|
129
|
-
/home/merc/Development/current/json-rest-schema/README.md:143:Validators are rules that run after a value has been cast to its proper type.
|
|
130
|
-
/home/merc/Development/current/json-rest-schema/README.md:147:| `required: true` | The field must be present in the input object. Fails if the key is `undefined`. |
|
|
131
|
-
/home/merc/Development/current/json-rest-schema/README.md:148:| `minLength: <number>` | For `string` types, validates the minimum character length. |
|
|
132
|
-
/home/merc/Development/current/json-rest-schema/README.md:149:| `maxLength: <number>` | For `string` types, validates the maximum character length. |
|
|
133
|
-
/home/merc/Development/current/json-rest-schema/README.md:150:| `min: <number>` | For `number` types, validates the minimum value. |
|
|
134
|
-
/home/merc/Development/current/json-rest-schema/README.md:151:| `max: <number>` | For `number` types, validates the maximum value. |
|
|
135
|
-
/home/merc/Development/current/json-rest-schema/README.md:152:| `notEmpty: true` | The field cannot be an empty string (`''`). This is different from `required`, as an empty string is still a defined value. |
|
|
136
|
-
/home/merc/Development/current/json-rest-schema/README.md:153:| `length: <number>`| For `string` types, it **truncates** the string to the specified length. For `number` types, it throws an error if the number of digits in the original input exceeds the specified length. |
|
|
137
|
-
/home/merc/Development/current/json-rest-schema/README.md:154:| `nullable: true`| Allows the value for this field to be `null`. By default, `null` is not allowed. |
|
|
138
|
-
/home/merc/Development/current/json-rest-schema/README.md:155:| `nullOnEmpty: true`| If the input value is an empty string (`''`), it will be cast to `null` before other validators run. |
|
|
139
|
-
/home/merc/Development/current/json-rest-schema/README.md:158:| `validator: <function>`| Allows you to provide your own custom validation function for complex, one-off logic. |
|
|
140
|
-
/home/merc/Development/current/json-rest-schema/README.md:159:| `defaultTo: <value>` | If the field is not present in the input object and the entire object is valid, this value will be used. Can be a value or a function that returns a value. |
|
|
141
|
-
/home/merc/Development/current/json-rest-schema/README.md:160:| `unsigned: true` | For `number` and `id` types, indicates the value should be non-negative (database hint). |
|
|
142
|
-
/home/merc/Development/current/json-rest-schema/README.md:161:| `precision: <number>` | For `number` types, total number of digits (database hint for decimal types). |
|
|
143
|
-
/home/merc/Development/current/json-rest-schema/README.md:162:| `scale: <number>` | For `number` types, number of decimal places (database hint for decimal types). |
|
|
144
|
-
/home/merc/Development/current/json-rest-schema/README.md:171:The real power of the library comes from its extensibility. You can easily add your own reusable types and validators. When you do this, you'll be passed a powerful `context` object.
|
|
145
|
-
/home/merc/Development/current/json-rest-schema/README.md:175:Every custom type and validator handler receives a `context` object as its only argument. This object is your toolbox, giving you all the information you need to perform complex logic. Here are its properties:
|
|
146
|
-
/home/merc/Development/current/json-rest-schema/README.md:177:* **`value`**: The current value of the field being processed. Be aware that this value may have already been changed by the type handler or a previous validator.
|
|
147
|
-
/home/merc/Development/current/json-rest-schema/README.md:180:* **`valueBeforeCast`**: The original, raw value for the field, exactly as it was in the input object before any type casting occurred.
|
|
148
|
-
/home/merc/Development/current/json-rest-schema/README.md:182:* **`definition`**: The schema definition object for the current field. For a field defined as `{ type: 'string', min: 5 }`, this would be that exact object.
|
|
149
|
-
/home/merc/Development/current/json-rest-schema/README.md:183:* **`parameterName`**: *(For validators only)* The name of the validation rule currently being executed (e.g., `'min'`).
|
|
150
|
-
/home/merc/Development/current/json-rest-schema/README.md:184:* **`parameterValue`**: *(For validators only)* The value of the validation rule currently being executed (e.g., the `5` in `min: 5`).
|
|
151
|
-
/home/merc/Development/current/json-rest-schema/README.md:185:* **`throwTypeError()`**: A function you can call to throw a standardized `TYPE_CAST_FAILED` error. This is the preferred way to report an error from within a type handler.
|
|
152
|
-
/home/merc/Development/current/json-rest-schema/README.md:186:* **`throwParamError(code, message, params)`**: A function you can call to throw a standardized validation error from within a validator. It accepts a custom error `code`, a `message`, and an optional `params` object.
|
|
153
|
-
/home/merc/Development/current/json-rest-schema/README.md:192:You can define a new validator once and use it anywhere.
|
|
154
|
-
/home/merc/Development/current/json-rest-schema/README.md:196:createSchema.addValidator('slug', (context) => {
|
|
155
|
-
/home/merc/Development/current/json-rest-schema/README.md:199: if (typeof context.value !== 'string' || !slugRegex.test(context.value)) {
|
|
156
|
-
/home/merc/Development/current/json-rest-schema/README.md:209:const articleSchema = createSchema({
|
|
157
|
-
/home/merc/Development/current/json-rest-schema/README.md:210: title: { type: 'string', required: true },
|
|
158
|
-
/home/merc/Development/current/json-rest-schema/README.md:211: slug: { type: 'string', required: true, slug: true } // Use it here
|
|
159
|
-
/home/merc/Development/current/json-rest-schema/README.md:217:A `Type` is used for casting. Imagine you want a `csv` type that takes a string like `"apple,banana,cherry"` and turns it into an array `['apple', 'banana', 'cherry']`.
|
|
160
|
-
/home/merc/Development/current/json-rest-schema/README.md:221:createSchema.addType('csv', (context) => {
|
|
161
|
-
/home/merc/Development/current/json-rest-schema/README.md:225: if (typeof context.value !== 'string') {
|
|
162
|
-
/home/merc/Development/current/json-rest-schema/README.md:226: // Use the public context method to throw a standardized type error
|
|
163
|
-
/home/merc/Development/current/json-rest-schema/README.md:233:// Now use your new 'csv' type
|
|
164
|
-
/home/merc/Development/current/json-rest-schema/README.md:234:const productSchema = createSchema({
|
|
165
|
-
/home/merc/Development/current/json-rest-schema/README.md:235: name: { type: 'string', required: true },
|
|
166
|
-
/home/merc/Development/current/json-rest-schema/README.md:236: tags: { type: 'csv' }
|
|
167
|
-
/home/merc/Development/current/json-rest-schema/README.md:240:const { validatedObject } = await productSchema.validate(product);
|
|
168
|
-
/home/merc/Development/current/json-rest-schema/README.md:250:If you create a lot of custom types and validators for your project, you can bundle them into a single, reusable **Plugin**. A plugin is just an object with an `install` method.
|
|
169
|
-
/home/merc/Development/current/json-rest-schema/README.md:253:// my-custom-plugin.js
|
|
170
|
-
/home/merc/Development/current/json-rest-schema/README.md:258: if (typeof context.value !== 'string') context.throwTypeError();
|
|
171
|
-
/home/merc/Development/current/json-rest-schema/README.md:264: if (typeof context.value !== 'string' || !slugRegex.test(context.value)) {
|
|
172
|
-
/home/merc/Development/current/json-rest-schema/README.md:274:import createSchema from './src/index.js';
|
|
173
|
-
/home/merc/Development/current/json-rest-schema/README.md:275:import MyCustomPlugin from './my-custom-plugin.js';
|
|
174
|
-
/home/merc/Development/current/json-rest-schema/README.md:278:createSchema.use(MyCustomPlugin);
|
|
175
|
-
/home/merc/Development/current/json-rest-schema/README.md:281:const mySchema = createSchema({
|
|
176
|
-
/home/merc/Development/current/json-rest-schema/README.md:282: tags: { type: 'csv' },
|
|
177
|
-
/home/merc/Development/current/json-rest-schema/README.md:283: pageUrl: { type: 'string', slug: true }
|
|
178
|
-
/home/merc/Development/current/json-rest-schema/README.md:293:`json-rest-schema` is deliberately scoped to runtime validation and transformation. It no longer ships helpers for creating database tables or migrations, and it does not prescribe a specific persistence layer. Treat the schemas you build with this library as the canonical description of your data when you design storage models, migrations, API responses, or documentation.
|
|
179
|
-
/home/merc/Development/current/json-rest-schema/README.md:295:If you pair the library with a database toolkit (such as Knex), keep the tooling concerns separate: write migrations and models in the tool that best fits your project, then reuse the same field definitions inside `createSchema` so validation, casting, and persistence stay aligned.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# External Corpus Freeze
|
|
2
|
-
|
|
3
|
-
Frozen on: 2026-03-01T15:38:04Z
|
|
4
|
-
|
|
5
|
-
## Standards Corpus (for M6 scoring)
|
|
6
|
-
- JSON:API specification (latest stable): https://jsonapi.org/format/
|
|
7
|
-
- HTTP Semantics (RFC 9110): https://www.rfc-editor.org/rfc/rfc9110
|
|
8
|
-
- HTTP PATCH method (RFC 5789): https://www.rfc-editor.org/rfc/rfc5789
|
|
9
|
-
- CORS protocol reference (Fetch / MDN references used as operational interpretation)
|
|
10
|
-
|
|
11
|
-
## Competitor Corpus (for M6 benchmarking)
|
|
12
|
-
- json-api-serializer (npm + repository docs)
|
|
13
|
-
- @jsonapi/server (repository/docs)
|
|
14
|
-
- fortune.js (docs/repo)
|
|
15
|
-
- NestJS ecosystem patterns for JSON:API integration
|
|
16
|
-
- Modern API framework comparison points (Express/Nest/Fastify patterns where relevant)
|
|
17
|
-
|
|
18
|
-
## Freeze Rules
|
|
19
|
-
- Scoring criteria and comparator set are fixed before scoring.
|
|
20
|
-
- Additional sources may be appended only for evidence depth, not to change scoring dimensions.
|
|
21
|
-
- All scored external claims must cite source links in audit/evidence/external/.
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# Comparator package metadata (npm view)
|
|
2
|
-
captured_at=2026-03-01T16:01:15Z
|
|
3
|
-
|
|
4
|
-
## jsonapi-serializer
|
|
5
|
-
{
|
|
6
|
-
"name": "jsonapi-serializer",
|
|
7
|
-
"version": "3.6.9",
|
|
8
|
-
"description": "A Node.js framework agnostic library for serializing your data to JSON API",
|
|
9
|
-
"license": "MIT",
|
|
10
|
-
"repository.url": "git+https://github.com/SeyZ/jsonapi-serializer.git",
|
|
11
|
-
"homepage": "https://github.com/SeyZ/jsonapi-serializer#readme",
|
|
12
|
-
"dist-tags.latest": "3.6.9",
|
|
13
|
-
"time.modified": "2026-01-16T16:48:39.205Z"
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
## json-api-serializer
|
|
17
|
-
{
|
|
18
|
-
"name": "json-api-serializer",
|
|
19
|
-
"version": "2.6.6",
|
|
20
|
-
"description": "Framework agnostic JSON API serializer.",
|
|
21
|
-
"license": "MIT",
|
|
22
|
-
"repository.url": "git+https://github.com/danivek/json-api-serializer.git",
|
|
23
|
-
"homepage": "https://github.com/danivek/json-api-serializer#readme",
|
|
24
|
-
"dist-tags.latest": "2.6.6",
|
|
25
|
-
"time.modified": "2022-06-19T06:11:18.322Z"
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
## @jsonapi/server
|
|
29
|
-
{
|
|
30
|
-
"error": {
|
|
31
|
-
"code": "E404",
|
|
32
|
-
"summary": "Not Found - GET https://registry.npmjs.org/@jsonapi%2fserver - Not found",
|
|
33
|
-
"detail": "The requested resource '@jsonapi/server@*' could not be found or you do not have permission to access it.\n\nNote that you can also install from a\ntarball, folder, http url, or git url."
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
not_found
|
|
37
|
-
|
|
38
|
-
## fortune
|
|
39
|
-
{
|
|
40
|
-
"name": "fortune",
|
|
41
|
-
"version": "5.5.19",
|
|
42
|
-
"description": "Non-native graph database abstraction layer for Node.js and web browsers.",
|
|
43
|
-
"license": "MIT",
|
|
44
|
-
"repository.url": "git+ssh://git@github.com/fortunejs/fortune.git",
|
|
45
|
-
"homepage": "http://fortune.js.org",
|
|
46
|
-
"dist-tags.latest": "5.5.19",
|
|
47
|
-
"time.modified": "2024-02-20T22:41:33.598Z"
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
## @tqman/nestjs-json-api
|
|
51
|
-
{
|
|
52
|
-
"error": {
|
|
53
|
-
"code": "E404",
|
|
54
|
-
"summary": "Not Found - GET https://registry.npmjs.org/@tqman%2fnestjs-json-api - Not found",
|
|
55
|
-
"detail": "The requested resource '@tqman/nestjs-json-api@*' could not be found or you do not have permission to access it.\n\nNote that you can also install from a\ntarball, folder, http url, or git url."
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
not_found
|
|
59
|
-
|
|
60
|
-
## nestjs-json-api
|
|
61
|
-
{
|
|
62
|
-
"name": "nestjs-json-api",
|
|
63
|
-
"version": "1.1.5",
|
|
64
|
-
"description": "A library to implement a JSON API in NestJs",
|
|
65
|
-
"license": "MIT",
|
|
66
|
-
"homepage": "https://github.com/makmonty/nestjs-json-api",
|
|
67
|
-
"dist-tags.latest": "1.1.5",
|
|
68
|
-
"time.modified": "2022-05-10T12:47:31.673Z"
|
|
69
|
-
}
|
|
70
|
-
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# npm download signals (last-month)
|
|
2
|
-
captured_at=2026-03-01T16:03:15Z
|
|
3
|
-
|
|
4
|
-
## jsonapi-serializer
|
|
5
|
-
{"downloads":326010,"start":"2026-01-30","end":"2026-02-28","package":"jsonapi-serializer"}
|
|
6
|
-
|
|
7
|
-
## json-api-serializer
|
|
8
|
-
{"downloads":243752,"start":"2026-01-30","end":"2026-02-28","package":"json-api-serializer"}
|
|
9
|
-
|
|
10
|
-
## jsonapi-server
|
|
11
|
-
{"downloads":1526,"start":"2026-01-30","end":"2026-02-28","package":"jsonapi-server"}
|
|
12
|
-
|
|
13
|
-
## fortune
|
|
14
|
-
{"downloads":10453,"start":"2026-01-30","end":"2026-02-28","package":"fortune"}
|
|
15
|
-
|
|
16
|
-
## nestjs-json-api
|
|
17
|
-
{"downloads":15,"start":"2026-01-30","end":"2026-02-28","package":"nestjs-json-api"}
|
|
18
|
-
|
|
19
|
-
## @jsonapi-serde/server
|
|
20
|
-
{"downloads":221,"start":"2026-01-30","end":"2026-02-28","package":"@jsonapi-serde/server"}
|
|
21
|
-
|
|
22
|
-
## @yaser2us/json-api-nestjs
|
|
23
|
-
{"downloads":20,"start":"2026-01-30","end":"2026-02-28","package":"@yaser2us/json-api-nestjs"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "jsonapi-server",
|
|
3
|
-
"version": "4.2.0",
|
|
4
|
-
"description": "A config driven NodeJS framework implementing json:api",
|
|
5
|
-
"repository.url": "git+https://github.com/holidayextras/jsonapi-server.git",
|
|
6
|
-
"homepage": "https://github.com/holidayextras/jsonapi-server#readme",
|
|
7
|
-
"time.modified": "2022-06-19T06:35:25.049Z"
|
|
8
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# Additional modern JSON:API toolkit metadata
|
|
2
|
-
captured_at=2026-03-01T16:02:41Z
|
|
3
|
-
|
|
4
|
-
## @jsonapi-serde/server
|
|
5
|
-
{
|
|
6
|
-
"name": "@jsonapi-serde/server",
|
|
7
|
-
"version": "1.5.1",
|
|
8
|
-
"description": "Framework agnostic JSON:API serialization and deserialization",
|
|
9
|
-
"license": "BSD-3-Clause",
|
|
10
|
-
"repository.url": "git+https://github.com/DASPRiD/jsonapi-serde-js.git",
|
|
11
|
-
"homepage": "https://github.com/DASPRiD/jsonapi-serde-js#readme",
|
|
12
|
-
"dist-tags.latest": "1.5.1",
|
|
13
|
-
"time.modified": "2026-02-14T18:21:28.135Z"
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
## @jsonapi-serde/openapi
|
|
17
|
-
{
|
|
18
|
-
"name": "@jsonapi-serde/openapi",
|
|
19
|
-
"version": "1.4.1",
|
|
20
|
-
"description": "OpenAPI schema generation for JSON:API serde",
|
|
21
|
-
"license": "BSD-3-Clause",
|
|
22
|
-
"repository.url": "git+https://github.com/DASPRiD/jsonapi-serde-js.git",
|
|
23
|
-
"homepage": "https://github.com/DASPRiD/jsonapi-serde-js#readme",
|
|
24
|
-
"dist-tags.latest": "1.4.1",
|
|
25
|
-
"time.modified": "2026-02-14T18:21:37.816Z"
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
## @yaser2us/json-api-nestjs
|
|
29
|
-
{
|
|
30
|
-
"name": "@yaser2us/json-api-nestjs",
|
|
31
|
-
"version": "10.0.0-beta.10",
|
|
32
|
-
"description": "JsonApi Plugin for NestJs",
|
|
33
|
-
"license": "MIT",
|
|
34
|
-
"repository.url": "git+https://github.com/yaser2us/nestjs-json-api.git",
|
|
35
|
-
"homepage": "https://github.com/yaser2us/nestjs-json-api#readme",
|
|
36
|
-
"dist-tags.latest": "10.0.0-beta.10",
|
|
37
|
-
"time.modified": "2025-06-18T09:28:14.604Z"
|
|
38
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
7:Fortune.js is a non-native graph [database abstraction layer](https://en.wikipedia.org/wiki/Database_abstraction_layer) that implements graph-like features on the application-level for Node.js and web browsers. It provides a common interface for databases, as well as relationships, inverse updates, referential integrity, which are built upon assumptions in the data model.
|
|
2
|
-
11:- Bi-directional relationships in any database.
|
|
3
|
-
13:- Sharing the same data models on the server and client.
|
|
4
|
-
21:*This is the core module. Additional features such as networking (HTTP, WebSocket), database adapters, serialization formats are listed in the [plugins page](http://fortune.js.org/plugins).*
|
|
5
|
-
26:Only record type definitions need to be provided. These definitions describe what data types may belong on a record and what relationships they may have, for which Fortune.js does inverse updates and maintains referential integrity. Here's an example of a basic micro-blogging service:
|
|
6
|
-
39: // Many-to-one relationship of user posts to post author.
|
|
7
|
-
45: // One-to-many relationship of post author to user posts.
|
|
8
|
-
51:Note that the primary key `id` is reserved, so there is no need to specify this. Links are `id`s that are maintained internally at the application-level by Fortune.js, and are always denormalized so that every link has a back-link. What this also means is that changes in a record will affect the links in related records.
|
|
9
|
-
53:By default, the data is persisted in memory (and IndexedDB for the browser). There are adapters for databases such as [MongoDB](https://github.com/fortunejs/fortune-mongodb), [Postgres](https://github.com/fortunejs/fortune-postgres), and [NeDB](https://github.com/fortunejs/fortune-nedb). See the [plugins page](http://fortune.js.org/plugins/) for more details.
|
|
10
|
-
59:// argument is used for finding related records in the same request and is
|
|
11
|
-
61:// the adapter. All methods return promises.
|
|
12
|
-
63:store.create(type, records, include, meta) // Records required.
|
|
13
|
-
104:Based on whether or not the resolved record is different from what was passed in, serializers may decide not to show the resolved record of the output hook for update and delete requests.
|
|
14
|
-
122:There is a [HTTP listener implementation](https://github.com/fortunejs/fortune-http), which returns a Node.js request listener that may be composed within larger applications. It maps Fortune requests and responses to the HTTP protocol automatically:
|
|
15
|
-
125:// Bring your own HTTP! This makes it easier to add SSL and allows the user to
|
|
16
|
-
126:// choose between different HTTP implementations, such as HTTP/2.
|
|
17
|
-
129:const fortuneHTTP = require('fortune-http')
|
|
18
|
-
133:// The `fortuneHTTP` function returns a listener function which does
|
|
19
|
-
134:// content negotiation, and maps the internal response to a HTTP response.
|
|
20
|
-
135:const listener = fortuneHTTP(store)
|
|
21
|
-
136:const server = http.createServer((request, response) =>
|
|
22
|
-
140:store.connect().then(() => server.listen(1337))
|
|
23
|
-
143:This yields an *ad hoc* JSON over HTTP API, as well as a HTML interface for humans. There are also serializers for [Micro API](https://github.com/fortunejs/fortune-micro-api) (JSON-LD) and [JSON API](https://github.com/fortunejs/fortune-json-api).
|
|
24
|
-
150:- Inverse relationship updates, automatically maintain both sides of relationships between records.
|
|
25
|
-
151:- Referential integrity, ensure that links must be valid at the application level.
|
|
26
|
-
153:- Adapter interface, use any database that can implement an adapter.
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
# [](http://fortune.js.org)
|
|
2
|
-
|
|
3
|
-
[](https://travis-ci.org/fortunejs/fortune)
|
|
4
|
-
[](https://www.npmjs.com/package/fortune)
|
|
5
|
-
[](https://raw.githubusercontent.com/fortunejs/fortune/master/LICENSE)
|
|
6
|
-
|
|
7
|
-
Fortune.js is a non-native graph [database abstraction layer](https://en.wikipedia.org/wiki/Database_abstraction_layer) that implements graph-like features on the application-level for Node.js and web browsers. It provides a common interface for databases, as well as relationships, inverse updates, referential integrity, which are built upon assumptions in the data model.
|
|
8
|
-
|
|
9
|
-
It's particularly useful for:
|
|
10
|
-
|
|
11
|
-
- Bi-directional relationships in any database.
|
|
12
|
-
- Applications that need storage options to be portable.
|
|
13
|
-
- Sharing the same data models on the server and client.
|
|
14
|
-
|
|
15
|
-
[View the website](http://fortune.js.org) for documentation. Get it from `npm`:
|
|
16
|
-
|
|
17
|
-
```sh
|
|
18
|
-
$ npm install fortune --save
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
*This is the core module. Additional features such as networking (HTTP, WebSocket), database adapters, serialization formats are listed in the [plugins page](http://fortune.js.org/plugins).*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
## Usage
|
|
25
|
-
|
|
26
|
-
Only record type definitions need to be provided. These definitions describe what data types may belong on a record and what relationships they may have, for which Fortune.js does inverse updates and maintains referential integrity. Here's an example of a basic micro-blogging service:
|
|
27
|
-
|
|
28
|
-
```js
|
|
29
|
-
const fortune = require('fortune') // Works in web browsers, too.
|
|
30
|
-
|
|
31
|
-
const store = fortune({
|
|
32
|
-
user: {
|
|
33
|
-
name: String,
|
|
34
|
-
|
|
35
|
-
// Following and followers are inversely related (many-to-many).
|
|
36
|
-
following: [ Array('user'), 'followers' ],
|
|
37
|
-
followers: [ Array('user'), 'following' ],
|
|
38
|
-
|
|
39
|
-
// Many-to-one relationship of user posts to post author.
|
|
40
|
-
posts: [ Array('post'), 'author' ]
|
|
41
|
-
},
|
|
42
|
-
post: {
|
|
43
|
-
message: String,
|
|
44
|
-
|
|
45
|
-
// One-to-many relationship of post author to user posts.
|
|
46
|
-
author: [ 'user', 'posts' ]
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Note that the primary key `id` is reserved, so there is no need to specify this. Links are `id`s that are maintained internally at the application-level by Fortune.js, and are always denormalized so that every link has a back-link. What this also means is that changes in a record will affect the links in related records.
|
|
52
|
-
|
|
53
|
-
By default, the data is persisted in memory (and IndexedDB for the browser). There are adapters for databases such as [MongoDB](https://github.com/fortunejs/fortune-mongodb), [Postgres](https://github.com/fortunejs/fortune-postgres), and [NeDB](https://github.com/fortunejs/fortune-nedb). See the [plugins page](http://fortune.js.org/plugins/) for more details.
|
|
54
|
-
|
|
55
|
-
Fortune has 4 main methods: `find`, `create`, `update`, & `delete`, which correspond to [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete). The method signatures are as follows:
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
// The first argument `type` is always required. The optional `include`
|
|
59
|
-
// argument is used for finding related records in the same request and is
|
|
60
|
-
// documented in the `request` method, and the optional `meta` is specific to
|
|
61
|
-
// the adapter. All methods return promises.
|
|
62
|
-
store.find(type, ids, options, include, meta)
|
|
63
|
-
store.create(type, records, include, meta) // Records required.
|
|
64
|
-
store.update(type, updates, include, meta) // Updates required.
|
|
65
|
-
store.delete(type, ids, include, meta)
|
|
66
|
-
|
|
67
|
-
// For example...
|
|
68
|
-
store.find('user', 123).then(results => { ... })
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
The first method call to interact with the database will trigger a connection to the data store, and it returns the result as a Promise. The specific methods wrap around the more general `request` method, see the [API documentation for `request`](http://fortune.js.org/api/#fortune-request).
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
## Input and Output Hooks
|
|
75
|
-
|
|
76
|
-
I/O hooks isolate business logic, and are part of what makes the interface reusable across different protocols. An input and output hook function may be defined per record type. Hook functions accept at least two arguments, the `context` object, the `record`, and optionally the `update` object for an `update` request. The method of an input hook may be any method except `find`, and an output hook may be applied on all methods.
|
|
77
|
-
|
|
78
|
-
An input hook function may optionally return or resolve a value to determine what gets persisted, and it is safe to mutate any of its arguments. The returned or resolved value must be the record if it's a create request, the update if it's an update request, or anything (or simply `null`) if it's a delete request. For example, an input hook function for a record may look like this:
|
|
79
|
-
|
|
80
|
-
```js
|
|
81
|
-
function input (context, record, update) {
|
|
82
|
-
switch (context.request.method) {
|
|
83
|
-
// If it's a create request, return the record.
|
|
84
|
-
case 'create': return record
|
|
85
|
-
|
|
86
|
-
// If it's an update request, return the update.
|
|
87
|
-
case 'update': return update
|
|
88
|
-
|
|
89
|
-
// If it's a delete request, the return value doesn't matter.
|
|
90
|
-
case 'delete': return null
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
An output hook function may optionally return or resolve a record, and it is safe to mutate any of its arguments.
|
|
96
|
-
|
|
97
|
-
```js
|
|
98
|
-
function output (context, record) {
|
|
99
|
-
record.accessedAt = new Date()
|
|
100
|
-
return record
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Based on whether or not the resolved record is different from what was passed in, serializers may decide not to show the resolved record of the output hook for update and delete requests.
|
|
105
|
-
|
|
106
|
-
Hooks for a record type may be defined as follows:
|
|
107
|
-
|
|
108
|
-
```js
|
|
109
|
-
const store = fortune({
|
|
110
|
-
user: { ... }
|
|
111
|
-
}, {
|
|
112
|
-
hooks: {
|
|
113
|
-
// Hook functions must be defined in order: input first, output last.
|
|
114
|
-
user: [ input, output ]
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
## Networking
|
|
121
|
-
|
|
122
|
-
There is a [HTTP listener implementation](https://github.com/fortunejs/fortune-http), which returns a Node.js request listener that may be composed within larger applications. It maps Fortune requests and responses to the HTTP protocol automatically:
|
|
123
|
-
|
|
124
|
-
```js
|
|
125
|
-
// Bring your own HTTP! This makes it easier to add SSL and allows the user to
|
|
126
|
-
// choose between different HTTP implementations, such as HTTP/2.
|
|
127
|
-
const http = require('http')
|
|
128
|
-
const fortune = require('fortune')
|
|
129
|
-
const fortuneHTTP = require('fortune-http')
|
|
130
|
-
|
|
131
|
-
const store = fortune(...)
|
|
132
|
-
|
|
133
|
-
// The `fortuneHTTP` function returns a listener function which does
|
|
134
|
-
// content negotiation, and maps the internal response to a HTTP response.
|
|
135
|
-
const listener = fortuneHTTP(store)
|
|
136
|
-
const server = http.createServer((request, response) =>
|
|
137
|
-
listener(request, response)
|
|
138
|
-
.catch(error => { /* error logging */ }))
|
|
139
|
-
|
|
140
|
-
store.connect().then(() => server.listen(1337))
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
This yields an *ad hoc* JSON over HTTP API, as well as a HTML interface for humans. There are also serializers for [Micro API](https://github.com/fortunejs/fortune-micro-api) (JSON-LD) and [JSON API](https://github.com/fortunejs/fortune-json-api).
|
|
144
|
-
|
|
145
|
-
Fortune.js implements its own [wire protocol](https://github.com/fortunejs/fortune-ws) based on [WebSocket](https://developer.mozilla.org/docs/Web/API/WebSockets_API) and [MessagePack](http://msgpack.org), which is useful for soft real-time applications.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
## Features and Non-Features
|
|
149
|
-
|
|
150
|
-
- Inverse relationship updates, automatically maintain both sides of relationships between records.
|
|
151
|
-
- Referential integrity, ensure that links must be valid at the application level.
|
|
152
|
-
- Type validations, fields are guaranteed to belong to a single type.
|
|
153
|
-
- Adapter interface, use any database that can implement an adapter.
|
|
154
|
-
- **No** object-relational mapping (ORM) or active record pattern, just plain data objects.
|
|
155
|
-
- **No** coupling with network protocol, handle requests from anywhere.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
## Requirements
|
|
159
|
-
|
|
160
|
-
Fortune.js is written in ECMAScript 5.1, with one ECMAScript 6 addition: **Promise**. Most of its public API returns Promises to be compatible with future editions of the language.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
## License
|
|
164
|
-
|
|
165
|
-
This software is licensed under the [MIT license](https://raw.githubusercontent.com/fortunejs/fortune/master/LICENSE).
|