json-rest-api 1.0.29 → 2.0.0
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/LICENSE +10 -670
- package/LICENSE-GPL-3.0 +674 -0
- package/LICENSE-MIT +21 -0
- package/README.md +39 -30
- package/docs/API.md +744 -1273
- package/docs/GUIDE/01-getting-started.md +338 -0
- package/docs/GUIDE/02-resources-and-relationships.md +33 -0
- package/docs/GUIDE/03-running-example.md +87 -0
- package/docs/GUIDE/04-creating-and-querying.md +181 -0
- package/docs/GUIDE/05-belongs-to.md +177 -0
- package/docs/GUIDE/06-has-many.md +184 -0
- package/docs/GUIDE/07-polymorphic-relationships.md +191 -0
- package/docs/GUIDE/08-many-to-many.md +184 -0
- package/docs/GUIDE/09-pagination-and-sorting.md +149 -0
- package/docs/GUIDE/10-put-and-patch.md +174 -0
- package/docs/GUIDE/11-relationship-endpoints.md +174 -0
- package/docs/GUIDE/12-field-transformations.md +287 -0
- package/docs/GUIDE/13-hooks-and-lifecycle.md +479 -0
- package/docs/GUIDE/14-custom-resource-methods.md +125 -0
- package/docs/GUIDE/15-query-projections.md +266 -0
- package/docs/GUIDE/{GUIDE_X_Autofiltering.md → 16-autofiltering.md} +77 -15
- package/docs/GUIDE/{GUIDE_X_Row_Policies.md → 17-row-policies.md} +137 -44
- package/docs/GUIDE/18-labels.md +86 -0
- package/docs/GUIDE/19-managed-transactions.md +179 -0
- package/docs/GUIDE/20-transaction-outcomes.md +207 -0
- package/docs/GUIDE/21-schema-and-migrations.md +634 -0
- package/docs/GUIDE/22-version-field-migrations.md +208 -0
- package/docs/GUIDE/23-fastify.md +179 -0
- package/docs/GUIDE/24-cors.md +172 -0
- package/docs/GUIDE/{GUIDE_X_URL_Management.md → 25-url-management.md} +7 -1
- package/docs/GUIDE/26-file-uploads.md +278 -0
- package/docs/GUIDE/27-bulk-operations.md +277 -0
- package/docs/GUIDE/28-socketio.md +325 -0
- package/docs/GUIDE/29-writing-plugins.md +278 -0
- package/docs/GUIDE/30-backend-capabilities.md +100 -0
- package/docs/GUIDE/31-positioning.md +181 -0
- package/docs/GUIDE/{GUIDE_Y_Appendices.md → 32-date-and-time.md} +74 -30
- package/docs/GUIDE/33-migrating-to-v2.md +3827 -0
- package/docs/GUIDE/index.md +51 -59
- package/docs/QUICKSTART.md +120 -287
- package/docs/architecture.md +75 -0
- package/docs/contributing.md +178 -0
- package/index.d.ts +36 -0
- package/index.js +1 -22
- package/lib/enhanced-logger.js +91 -85
- package/lib/error-context.js +445 -5
- package/lib/error-formatter.js +219 -59
- package/lib/knex-transaction.js +64 -0
- package/lib/logger-types.d.ts +22 -0
- package/lib/missing-package.js +4 -0
- package/lib/rest-api-errors.js +103 -8
- package/lib/runtime/json-rest-api.js +172 -0
- package/lib/transaction-types.d.ts +59 -0
- package/package.json +97 -27
- package/plugins/core/bulk-operations-plugin.js +191 -184
- package/plugins/core/connectors/express-plugin.js +148 -219
- package/plugins/core/connectors/fastify-plugin.js +125 -82
- package/plugins/core/connectors/lib/busboy-detector.js +74 -156
- package/plugins/core/connectors/lib/connector-core.js +144 -20
- package/plugins/core/connectors/lib/formidable-detector.js +63 -120
- package/plugins/core/connectors/lib/http-validators.js +77 -0
- package/plugins/core/connectors/lib/multipart-helpers.js +18 -0
- package/plugins/core/connectors/lib/request-helpers.js +10 -1
- package/plugins/core/connectors/lib/transport-http-helpers.js +89 -8
- package/plugins/core/connectors/lib/transport-route-schemas.js +7 -4
- package/plugins/core/file-handling-plugin.js +87 -177
- package/plugins/core/lib/anyapi/anyapi-registry.js +213 -164
- package/plugins/core/lib/anyapi/canonical-link-store.js +507 -0
- package/plugins/core/lib/anyapi/canonical-relationship-reader.js +598 -0
- package/plugins/core/lib/anyapi/schema-utils.js +25 -16
- package/plugins/core/lib/anyapi/utils/descriptor-helpers.js +0 -64
- package/plugins/core/lib/dbIntrospection.js +228 -21
- package/plugins/core/lib/dbTablesOperations.js +409 -92
- package/plugins/core/lib/fractional-positioning.js +12 -48
- package/plugins/core/lib/querying/identifier-query.js +19 -0
- package/plugins/core/lib/querying/include-query-helpers.js +364 -0
- package/plugins/core/lib/querying/include-to-many.js +428 -0
- package/plugins/core/lib/querying/include-to-one.js +579 -0
- package/plugins/core/lib/querying/knex-cross-table-search.js +31 -307
- package/plugins/core/lib/querying/knex-json-api-transformers-querying.js +99 -401
- package/plugins/core/lib/querying/knex-pagination-helpers.js +48 -317
- package/plugins/core/lib/querying/knex-process-includes.js +5 -110
- package/plugins/core/lib/querying/knex-query-helpers-base.js +21 -56
- package/plugins/core/lib/querying/knex-query-helpers.js +298 -448
- package/plugins/core/lib/querying/knex-relationship-includes.js +120 -2138
- package/plugins/core/lib/querying/knex-window-queries.js +62 -253
- package/plugins/core/lib/querying/query-builder-utils.js +44 -4
- package/plugins/core/lib/querying/query-constraint.d.ts +12 -0
- package/plugins/core/lib/querying/query-constraint.js +27 -0
- package/plugins/core/lib/querying/query-field-sort-helpers.js +134 -37
- package/plugins/core/lib/querying/relationship-identifiers.js +208 -0
- package/plugins/core/lib/querying/sort-helpers.js +13 -1
- package/plugins/core/lib/querying/storage-adapter-utils.js +13 -5
- package/plugins/core/lib/querying/url-helpers.js +11 -4
- package/plugins/core/lib/querying-writing/compile-schemas.js +148 -249
- package/plugins/core/lib/querying-writing/connectors-query-parser.js +33 -118
- package/plugins/core/lib/querying-writing/database-capabilities.js +149 -223
- package/plugins/core/lib/querying-writing/database-value-normalizers.js +179 -194
- package/plugins/core/lib/querying-writing/default-data-helpers.js +15 -45
- package/plugins/core/lib/querying-writing/field-selection-types.d.ts +43 -0
- package/plugins/core/lib/querying-writing/field-utils.js +113 -92
- package/plugins/core/lib/querying-writing/knex-constants.d.ts +18 -0
- package/plugins/core/lib/querying-writing/knex-constants.js +2 -26
- package/plugins/core/lib/querying-writing/knex-field-helpers.js +100 -290
- package/plugins/core/lib/querying-writing/knex-json-api-transformers.js +31 -120
- package/plugins/core/lib/querying-writing/query-field-helpers.js +108 -32
- package/plugins/core/lib/querying-writing/query-field-types.d.ts +60 -0
- package/plugins/core/lib/querying-writing/relationship-contracts.js +33 -13
- package/plugins/core/lib/querying-writing/request-contracts.js +93 -38
- package/plugins/core/lib/querying-writing/resource-id-normalization.js +23 -5
- package/plugins/core/lib/querying-writing/response-options.js +35 -0
- package/plugins/core/lib/querying-writing/schema-helpers.js +203 -324
- package/plugins/core/lib/querying-writing/scope-validations.js +92 -290
- package/plugins/core/lib/querying-writing/simplified-helpers.js +113 -712
- package/plugins/core/lib/storage/canonical-data-helpers.js +683 -0
- package/plugins/core/lib/storage/canonical-storage-mapping.js +51 -20
- package/plugins/core/lib/storage/ordinary-data-helpers.js +710 -0
- package/plugins/core/lib/storage/storage-adapter.js +128 -62
- package/plugins/core/lib/storage/storage-mapping.js +78 -28
- package/plugins/core/lib/storage/storage-types.d.ts +502 -0
- package/plugins/core/lib/writing/many-to-many-manipulations.js +114 -284
- package/plugins/core/lib/writing/relationship-processor.js +94 -158
- package/plugins/core/lib/writing/resource-version.js +172 -0
- package/plugins/core/lib/writing/reverse-relationship-manipulations.js +110 -0
- package/plugins/core/rest-api-anyapi-knex-plugin.js +116 -2485
- package/plugins/core/rest-api-autofilter-plugin.js +17 -19
- package/plugins/core/rest-api-cors-plugin.js +52 -205
- package/plugins/core/rest-api-knex-plugin.js +45 -1077
- package/plugins/core/rest-api-label-plugin.js +25 -38
- package/plugins/core/rest-api-plugin-hooks/register-relationship-routes.js +5 -5
- package/plugins/core/rest-api-plugin-hooks/register-scope-routes.js +9 -6
- package/plugins/core/rest-api-plugin-hooks/turn-scope-init-into-vars.js +7 -26
- package/plugins/core/rest-api-plugin-hooks/validate-include-configurations.js +20 -26
- package/plugins/core/rest-api-plugin-methods/add-route.js +4 -6
- package/plugins/core/rest-api-plugin-methods/apply-query-filters.js +42 -13
- package/plugins/core/rest-api-plugin-methods/check-permissions.js +11 -5
- package/plugins/core/rest-api-plugin-methods/common.js +291 -395
- package/plugins/core/rest-api-plugin-methods/delete-relationship.js +49 -47
- package/plugins/core/rest-api-plugin-methods/delete.js +31 -25
- package/plugins/core/rest-api-plugin-methods/enrich-attributes.js +108 -148
- package/plugins/core/rest-api-plugin-methods/get-related.js +113 -305
- package/plugins/core/rest-api-plugin-methods/get-relationship.js +25 -18
- package/plugins/core/rest-api-plugin-methods/get.js +36 -68
- package/plugins/core/rest-api-plugin-methods/lifecycle-types.d.ts +225 -0
- package/plugins/core/rest-api-plugin-methods/patch-relationship.js +28 -25
- package/plugins/core/rest-api-plugin-methods/patch.js +46 -99
- package/plugins/core/rest-api-plugin-methods/post-relationship.js +49 -53
- package/plugins/core/rest-api-plugin-methods/post.js +51 -51
- package/plugins/core/rest-api-plugin-methods/put.js +69 -148
- package/plugins/core/rest-api-plugin-methods/query.js +37 -81
- package/plugins/core/rest-api-plugin-methods/release.js +2 -1
- package/plugins/core/rest-api-plugin.js +32 -46
- package/plugins/core/rest-api-positioning-plugin.js +183 -628
- package/plugins/core/rest-api-query-projections-plugin.js +19 -102
- package/plugins/core/rest-api-row-policy-plugin.js +3 -3
- package/plugins/core/socketio-plugin.js +364 -344
- package/plugins/storage/local-storage.js +40 -36
- package/types/autofilter.d.ts +57 -0
- package/types/bulk-methods.d.ts +63 -0
- package/types/errors.d.ts +118 -0
- package/types/fastify-options.d.ts +19 -0
- package/types/file-detectors.d.ts +33 -0
- package/types/file-storage.d.ts +48 -0
- package/types/hook-context.d.ts +180 -0
- package/types/plugin-options.d.ts +53 -0
- package/types/relationship-methods.d.ts +74 -0
- package/types/representations.d.ts +50 -0
- package/types/resource-methods.d.ts +95 -0
- package/types/resource-schema.d.ts +157 -0
- package/types/row-policy.d.ts +31 -0
- package/types/runtime.d.ts +132 -0
- package/types/transactions.d.ts +21 -0
- package/.claude/agents/library-guide-expert.md +0 -30
- package/.claude/agents/rest-api-internals-expert.md +0 -54
- package/.claude/settings.local.json +0 -70
- package/AGENTS.md +0 -34
- package/CLAUDE.md +0 -160
- package/CRUSH.md +0 -55
- package/JSKIT_BACKEND_MIGRATION_TRACKER.txt +0 -180
- package/SINGLE_VALIDATION_CONTRACT_TODO.txt +0 -172
- package/TODO.todo +0 -13
- package/connectors_ideas/fastify.js +0 -217
- package/connectors_ideas/koa-plugin.js +0 -112
- package/docs/.bundle/config +0 -2
- package/docs/COMPARISON.md +0 -433
- package/docs/GUIDE/GUIDE_1_Initial_Setup.md +0 -1057
- package/docs/GUIDE/GUIDE_2_1_The_Starting_Point.md +0 -88
- package/docs/GUIDE/GUIDE_2_2_Manipulating_And_Searching_Tables.md +0 -808
- package/docs/GUIDE/GUIDE_2_3_BelongsTo_Relationships.md +0 -491
- package/docs/GUIDE/GUIDE_2_4_HasMany_Records.md +0 -398
- package/docs/GUIDE/GUIDE_2_5_HasMany_Polymorphic.md +0 -898
- package/docs/GUIDE/GUIDE_2_6_Many_To_Many.md +0 -712
- package/docs/GUIDE/GUIDE_2_7_Pagination_And_Ordering.md +0 -1247
- package/docs/GUIDE/GUIDE_2_8_Effects_of_PUT_and_PATCH.md +0 -748
- package/docs/GUIDE/GUIDE_2_9_Relationships_Urls.md +0 -517
- package/docs/GUIDE/GUIDE_2_Data_And_Relations.md +0 -66
- package/docs/GUIDE/GUIDE_3_Field_Transformations.md +0 -1252
- package/docs/GUIDE/GUIDE_5_Non-Db_Resources.md +0 -1107
- package/docs/GUIDE/GUIDE_6_Positioning.md +0 -692
- package/docs/GUIDE/GUIDE_7_Hooks_Data_Management_And_Plugins.md +0 -1491
- package/docs/GUIDE/GUIDE_X_Bulk_Operations.md +0 -732
- package/docs/GUIDE/GUIDE_X_Cors.md +0 -1957
- package/docs/GUIDE/GUIDE_X_Fastify.md +0 -78
- package/docs/GUIDE/GUIDE_X_File_Uploads.md +0 -729
- package/docs/GUIDE/GUIDE_X_Knex_Schema_And_Migrations.md +0 -370
- package/docs/GUIDE/GUIDE_X_Query_Projections.md +0 -159
- package/docs/GUIDE/GUIDE_X_SocketIO.md +0 -1040
- package/docs/GUIDE/GUIDE_X_Writing_Plugins.md +0 -201
- package/docs/Gemfile +0 -6
- package/docs/Gemfile.lock +0 -308
- package/docs/ONBOARDING.md +0 -315
- package/docs/_config.yml +0 -36
- package/docs/_layouts/default.html +0 -123
- package/docs/apple-touch-icon.svg +0 -4
- package/docs/assets/css/style.scss +0 -392
- package/docs/favicon.svg +0 -4
- package/docs/index.md +0 -164
- package/docs/mini-guides/file-uploads-complete.md +0 -161
- package/eslint.config.js +0 -13
- package/examples/url-override-example.js +0 -137
- package/fixing_plan.md +0 -112
- package/plugins/core/lib/anyapi/query/anyapi-query-adapter.js +0 -657
- package/plugins/core/lib/querying-writing/return-record-settings.js +0 -47
- package/plugins/core/lib/writing/knex-json-api-transformers-writing.js +0 -110
- package/plugins/storage/s3-storage.js +0 -93
- package/quickTest.js +0 -136
- package/scripts/debug-anyapi-review-filter.mjs +0 -63
- package/scripts/inspect-anyapi-descriptor-country.mjs +0 -19
- package/scripts/inspect-anyapi-descriptor.mjs +0 -19
- package/scripts/run-docs.js +0 -133
- package/test-debug.js +0 -59
- package/tests/README.md +0 -202
- package/tests/TEST_TEMPLATE.test.js +0 -178
- package/tests/anyapi-basic.test.js +0 -105
- package/tests/anyapi-cursor-pagination.test.js +0 -148
- package/tests/anyapi-custom-idproperty.test.js +0 -163
- package/tests/autofilter.test.js +0 -463
- package/tests/bulk-operations.test.js +0 -657
- package/tests/computed-fields.test.js +0 -586
- package/tests/cors.test.js +0 -834
- package/tests/curl.test.js +0 -467
- package/tests/custom-id-mysql-returning-fallback.test.js +0 -128
- package/tests/custom-id-simplified-post.test.js +0 -75
- package/tests/custom-idproperty-relationships.test.js +0 -932
- package/tests/db-introspection.test.js +0 -521
- package/tests/db-table-operations.test.js +0 -798
- package/tests/fastify-plugin.test.js +0 -184
- package/tests/field-getters.test.js +0 -370
- package/tests/field-setters.test.js +0 -306
- package/tests/file-handling.test.js +0 -155
- package/tests/fixtures/api-configs.js +0 -2566
- package/tests/full-jsonapi-belongsto-linkage.test.js +0 -150
- package/tests/helpers/fake-fastify.js +0 -99
- package/tests/helpers/storage-mode.js +0 -65
- package/tests/helpers/test-utils.js +0 -203
- package/tests/http-connectors-parity.test.js +0 -395
- package/tests/id-normalization.test.js +0 -444
- package/tests/include-depth-validation.test.js +0 -331
- package/tests/includes.test.js +0 -427
- package/tests/local-storage.test.js +0 -96
- package/tests/logical-id-write-validation.test.js +0 -151
- package/tests/nested-includes.test.js +0 -617
- package/tests/pagination-boundaries.test.js +0 -154
- package/tests/pagination-contract.test.js +0 -122
- package/tests/pagination-cursor-multifield.test.js +0 -641
- package/tests/pagination-enhanced.test.js +0 -563
- package/tests/polymorphic-relationships.test.js +0 -347
- package/tests/polymorphic-simple.test.js +0 -148
- package/tests/positioning-advanced.test.js +0 -692
- package/tests/positioning-extended.test.js +0 -915
- package/tests/positioning-multifilter.test.js +0 -699
- package/tests/positioning.test.js +0 -560
- package/tests/post-commit-hooks.test.js +0 -120
- package/tests/projected-fields.test.js +0 -319
- package/tests/public-exports.test.js +0 -15
- package/tests/put-create-parity.test.js +0 -216
- package/tests/queries.test.js +0 -521
- package/tests/query-limits.test.js +0 -584
- package/tests/relationship-endpoints.test.js +0 -620
- package/tests/relationship-include-storage-adapter.test.js +0 -56
- package/tests/relationships.test.js +0 -681
- package/tests/rest-api.test.js +0 -337
- package/tests/return-record-settings.test.js +0 -184
- package/tests/row-policy.test.js +0 -489
- package/tests/s3-storage.test.js +0 -38
- package/tests/searchschema-knex-behavior.test.js +0 -187
- package/tests/searchschema-merge.test.js +0 -151
- package/tests/socketio.test.js +0 -860
- package/tests/storage-mapping.test.js +0 -362
- package/tests/temporal-boundaries.test.js +0 -208
- package/tests/test-development-guide.md +0 -370
- package/tests/virtual-fields.test.js +0 -404
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
# Writing Plugins
|
|
2
|
-
|
|
3
|
-
`json-rest-api` is built as a set of plugins on top of `hooked-api`. This guide covers the public extension surface for plugin authors.
|
|
4
|
-
|
|
5
|
-
Use this guide when you want to:
|
|
6
|
-
|
|
7
|
-
- add resource-level behavior across many resources
|
|
8
|
-
- add new scope methods
|
|
9
|
-
- compile resource metadata into reusable runtime state
|
|
10
|
-
- hook into query or write processing
|
|
11
|
-
|
|
12
|
-
For internal architecture notes and maintainer-oriented details, see [docs/ONBOARDING.md](../ONBOARDING.md).
|
|
13
|
-
|
|
14
|
-
## Minimal plugin shape
|
|
15
|
-
|
|
16
|
-
```javascript
|
|
17
|
-
export const MyPlugin = {
|
|
18
|
-
name: 'my-plugin',
|
|
19
|
-
dependencies: ['rest-api'],
|
|
20
|
-
|
|
21
|
-
install ({ addHook, addScopeMethod, helpers, log, pluginOptions = {} }) {
|
|
22
|
-
addHook('scope:added', 'compile-my-plugin', {}, ({ context, scopes }) => {
|
|
23
|
-
const scope = scopes[context.scopeName]
|
|
24
|
-
scope.vars.myPlugin = { enabled: true }
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
addScopeMethod('doSomething', async ({ scopeName, scope, params, context }) => {
|
|
28
|
-
return { scopeName, enabled: scope.vars.myPlugin?.enabled === true }
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
The usual pattern is:
|
|
35
|
-
|
|
36
|
-
1. compile resource metadata during `scope:added`
|
|
37
|
-
2. store normalized state in `scope.vars`
|
|
38
|
-
3. use hooks or scope methods to apply behavior at runtime
|
|
39
|
-
|
|
40
|
-
## The stable extension points
|
|
41
|
-
|
|
42
|
-
### `scope:added`
|
|
43
|
-
|
|
44
|
-
Use this to inspect `scopeOptions`, validate configuration, and compile resource-specific runtime state into `scope.vars`.
|
|
45
|
-
|
|
46
|
-
Typical uses:
|
|
47
|
-
|
|
48
|
-
- compile autofilter presets
|
|
49
|
-
- compile query-field definitions
|
|
50
|
-
- validate resource-specific options
|
|
51
|
-
|
|
52
|
-
Example:
|
|
53
|
-
|
|
54
|
-
```javascript
|
|
55
|
-
addHook('scope:added', 'compile-example', {}, ({ context, scopes }) => {
|
|
56
|
-
const scope = scopes[context.scopeName]
|
|
57
|
-
const options = scope.scopeOptions || {}
|
|
58
|
-
|
|
59
|
-
scope.vars.example = {
|
|
60
|
-
flag: options.exampleFlag === true
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### `beforeSchemaValidate`
|
|
66
|
-
|
|
67
|
-
Use this to normalize or strip write input before schema validation runs.
|
|
68
|
-
|
|
69
|
-
Typical uses:
|
|
70
|
-
|
|
71
|
-
- inject derived input values
|
|
72
|
-
- remove output-only fields from `POST`/`PUT`/`PATCH`
|
|
73
|
-
- translate alternate request forms into canonical attributes/relationships
|
|
74
|
-
|
|
75
|
-
Example:
|
|
76
|
-
|
|
77
|
-
```javascript
|
|
78
|
-
addHook('beforeSchemaValidate', 'strip-output-only-input', {}, ({ context }) => {
|
|
79
|
-
const attributes = context.inputRecord?.data?.attributes
|
|
80
|
-
if (!attributes) return
|
|
81
|
-
|
|
82
|
-
delete attributes.output_only_field
|
|
83
|
-
})
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### `knexQueryFiltering`
|
|
87
|
-
|
|
88
|
-
Use this to add query constraints to the generated Knex query.
|
|
89
|
-
|
|
90
|
-
Typical uses:
|
|
91
|
-
|
|
92
|
-
- automatic scoping
|
|
93
|
-
- cross-table filters
|
|
94
|
-
- custom public filter semantics
|
|
95
|
-
|
|
96
|
-
Example:
|
|
97
|
-
|
|
98
|
-
```javascript
|
|
99
|
-
addHook('knexQueryFiltering', 'scope-by-workspace', {}, async ({ context }) => {
|
|
100
|
-
const query = context.knexQuery?.query
|
|
101
|
-
if (!query) return
|
|
102
|
-
|
|
103
|
-
query.where('workspace_id', context.session.workspaceId)
|
|
104
|
-
})
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
`knexQueryFiltering` is the right seam for filtering. It is **not** the right seam for turning ad hoc SQL aliases into first-class fields.
|
|
108
|
-
|
|
109
|
-
For mandatory resource visibility, prefer the supported [`RowPolicyPlugin`](GUIDE_X_Row_Policies.md) contract over registering a raw filtering hook. It validates resource configuration, requires an explicit allow/deny decision, provides logical field translation, exposes query-purpose metadata, and is exercised across pagination counts, single-record preflights, includes, and relationship loading.
|
|
110
|
-
|
|
111
|
-
### `addScopeMethod`
|
|
112
|
-
|
|
113
|
-
Use this when a plugin needs a reusable method on every resource or selected resources.
|
|
114
|
-
|
|
115
|
-
Example:
|
|
116
|
-
|
|
117
|
-
```javascript
|
|
118
|
-
addScopeMethod('introspect', async ({ vars }) => {
|
|
119
|
-
return {
|
|
120
|
-
tableName: vars.schemaInfo?.tableName,
|
|
121
|
-
fields: Object.keys(vars.schemaInfo?.schemaStructure || {})
|
|
122
|
-
}
|
|
123
|
-
})
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## The query-field seam
|
|
127
|
-
|
|
128
|
-
`json-rest-api` now supports a small, explicit seam for **query-only read fields**.
|
|
129
|
-
|
|
130
|
-
This is the seam used by `QueryProjectionsPlugin`, and it is the recommended pattern for plugins that need derived SQL-backed fields.
|
|
131
|
-
|
|
132
|
-
### What a plugin should provide
|
|
133
|
-
|
|
134
|
-
Compile resource-level definitions into:
|
|
135
|
-
|
|
136
|
-
```javascript
|
|
137
|
-
scope.vars.queryFields = {
|
|
138
|
-
full_name: {
|
|
139
|
-
type: 'string',
|
|
140
|
-
sortable: true,
|
|
141
|
-
hidden: false,
|
|
142
|
-
normallyHidden: false,
|
|
143
|
-
select: ({ knex, db, context, scopeName, tableName, fieldName, schemaInfo, adapter, column, ref }) => {
|
|
144
|
-
return knex.raw(
|
|
145
|
-
"trim(coalesce(??, '') || ' ' || coalesce(??, ''))",
|
|
146
|
-
[column('first_name'), column('last_name')]
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### What core will do with `scope.vars.queryFields`
|
|
154
|
-
|
|
155
|
-
Once a plugin sets `scope.vars.queryFields`, core will:
|
|
156
|
-
|
|
157
|
-
- include visible query fields by default in `get()` and `query()`
|
|
158
|
-
- allow them in sparse fieldsets
|
|
159
|
-
- allow them in sorting when the plugin marks them sortable
|
|
160
|
-
- use them in cursor pagination with a stable `id` tie-breaker
|
|
161
|
-
- carry them through included-resource selection
|
|
162
|
-
- only expose declared query-field aliases on the AnyAPI path
|
|
163
|
-
|
|
164
|
-
### What this seam is for
|
|
165
|
-
|
|
166
|
-
Use it for:
|
|
167
|
-
|
|
168
|
-
- SQL-backed projections
|
|
169
|
-
- aggregate list fields
|
|
170
|
-
- joined display labels
|
|
171
|
-
- derived fields that must participate in `ORDER BY`
|
|
172
|
-
|
|
173
|
-
Do **not** use it for:
|
|
174
|
-
|
|
175
|
-
- writable fields
|
|
176
|
-
- storage/schema ownership
|
|
177
|
-
- migrations or introspection
|
|
178
|
-
- normal response-only computed fields
|
|
179
|
-
|
|
180
|
-
For the concrete projection example, see [Query Projections](GUIDE_X_Query_Projections.md).
|
|
181
|
-
|
|
182
|
-
## Recommended plugin pattern
|
|
183
|
-
|
|
184
|
-
When you add a new plugin feature, prefer this flow:
|
|
185
|
-
|
|
186
|
-
1. read plugin options at install time
|
|
187
|
-
2. validate and compile per-resource config in `scope:added`
|
|
188
|
-
3. store only normalized runtime state in `scope.vars`
|
|
189
|
-
4. use hooks or scope methods to apply behavior
|
|
190
|
-
|
|
191
|
-
That keeps the plugin declarative and avoids re-parsing configuration during requests.
|
|
192
|
-
|
|
193
|
-
## Boundaries to keep clean
|
|
194
|
-
|
|
195
|
-
- Keep **query-layer** extensions out of `schema`.
|
|
196
|
-
- Keep **write/input** reshaping in `beforeSchemaValidate`.
|
|
197
|
-
- Keep **filtering** in `knexQueryFiltering`.
|
|
198
|
-
- Keep **response-only** enrichment in `enrichAttributes`.
|
|
199
|
-
- Do not rely on arbitrary internal helper filenames as public API.
|
|
200
|
-
|
|
201
|
-
If a feature requires deeper integration than the public seams provide, treat that as a core extension discussion rather than a plugin hack.
|
package/docs/Gemfile
DELETED
package/docs/Gemfile.lock
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
GEM
|
|
2
|
-
remote: https://rubygems.org/
|
|
3
|
-
specs:
|
|
4
|
-
activesupport (8.0.2)
|
|
5
|
-
base64
|
|
6
|
-
benchmark (>= 0.3)
|
|
7
|
-
bigdecimal
|
|
8
|
-
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
9
|
-
connection_pool (>= 2.2.5)
|
|
10
|
-
drb
|
|
11
|
-
i18n (>= 1.6, < 2)
|
|
12
|
-
logger (>= 1.4.2)
|
|
13
|
-
minitest (>= 5.1)
|
|
14
|
-
securerandom (>= 0.3)
|
|
15
|
-
tzinfo (~> 2.0, >= 2.0.5)
|
|
16
|
-
uri (>= 0.13.1)
|
|
17
|
-
addressable (2.8.7)
|
|
18
|
-
public_suffix (>= 2.0.2, < 7.0)
|
|
19
|
-
base64 (0.2.0)
|
|
20
|
-
benchmark (0.4.1)
|
|
21
|
-
bigdecimal (3.2.2)
|
|
22
|
-
coffee-script (2.4.1)
|
|
23
|
-
coffee-script-source
|
|
24
|
-
execjs
|
|
25
|
-
coffee-script-source (1.12.2)
|
|
26
|
-
colorator (1.1.0)
|
|
27
|
-
commonmarker (0.23.11)
|
|
28
|
-
concurrent-ruby (1.3.5)
|
|
29
|
-
connection_pool (2.5.3)
|
|
30
|
-
dnsruby (1.72.4)
|
|
31
|
-
base64 (~> 0.2.0)
|
|
32
|
-
logger (~> 1.6.5)
|
|
33
|
-
simpleidn (~> 0.2.1)
|
|
34
|
-
drb (2.2.3)
|
|
35
|
-
em-websocket (0.5.3)
|
|
36
|
-
eventmachine (>= 0.12.9)
|
|
37
|
-
http_parser.rb (~> 0)
|
|
38
|
-
ethon (0.16.0)
|
|
39
|
-
ffi (>= 1.15.0)
|
|
40
|
-
eventmachine (1.2.7)
|
|
41
|
-
execjs (2.10.0)
|
|
42
|
-
faraday (2.13.1)
|
|
43
|
-
faraday-net_http (>= 2.0, < 3.5)
|
|
44
|
-
json
|
|
45
|
-
logger
|
|
46
|
-
faraday-net_http (3.4.1)
|
|
47
|
-
net-http (>= 0.5.0)
|
|
48
|
-
ffi (1.17.2-aarch64-linux-gnu)
|
|
49
|
-
ffi (1.17.2-aarch64-linux-musl)
|
|
50
|
-
ffi (1.17.2-arm-linux-gnu)
|
|
51
|
-
ffi (1.17.2-arm-linux-musl)
|
|
52
|
-
ffi (1.17.2-arm64-darwin)
|
|
53
|
-
ffi (1.17.2-x86_64-darwin)
|
|
54
|
-
ffi (1.17.2-x86_64-linux-gnu)
|
|
55
|
-
ffi (1.17.2-x86_64-linux-musl)
|
|
56
|
-
forwardable-extended (2.6.0)
|
|
57
|
-
gemoji (4.1.0)
|
|
58
|
-
github-pages (230)
|
|
59
|
-
github-pages-health-check (= 1.18.2)
|
|
60
|
-
jekyll (= 3.9.5)
|
|
61
|
-
jekyll-avatar (= 0.8.0)
|
|
62
|
-
jekyll-coffeescript (= 1.2.2)
|
|
63
|
-
jekyll-commonmark-ghpages (= 0.4.0)
|
|
64
|
-
jekyll-default-layout (= 0.1.5)
|
|
65
|
-
jekyll-feed (= 0.17.0)
|
|
66
|
-
jekyll-gist (= 1.5.0)
|
|
67
|
-
jekyll-github-metadata (= 2.16.1)
|
|
68
|
-
jekyll-include-cache (= 0.2.1)
|
|
69
|
-
jekyll-mentions (= 1.6.0)
|
|
70
|
-
jekyll-optional-front-matter (= 0.3.2)
|
|
71
|
-
jekyll-paginate (= 1.1.0)
|
|
72
|
-
jekyll-readme-index (= 0.3.0)
|
|
73
|
-
jekyll-redirect-from (= 0.16.0)
|
|
74
|
-
jekyll-relative-links (= 0.7.0)
|
|
75
|
-
jekyll-remote-theme (= 0.4.3)
|
|
76
|
-
jekyll-sass-converter (= 1.5.2)
|
|
77
|
-
jekyll-seo-tag (= 2.8.0)
|
|
78
|
-
jekyll-sitemap (= 1.4.0)
|
|
79
|
-
jekyll-swiss (= 1.0.0)
|
|
80
|
-
jekyll-theme-architect (= 0.2.0)
|
|
81
|
-
jekyll-theme-cayman (= 0.2.0)
|
|
82
|
-
jekyll-theme-dinky (= 0.2.0)
|
|
83
|
-
jekyll-theme-hacker (= 0.2.0)
|
|
84
|
-
jekyll-theme-leap-day (= 0.2.0)
|
|
85
|
-
jekyll-theme-merlot (= 0.2.0)
|
|
86
|
-
jekyll-theme-midnight (= 0.2.0)
|
|
87
|
-
jekyll-theme-minimal (= 0.2.0)
|
|
88
|
-
jekyll-theme-modernist (= 0.2.0)
|
|
89
|
-
jekyll-theme-primer (= 0.6.0)
|
|
90
|
-
jekyll-theme-slate (= 0.2.0)
|
|
91
|
-
jekyll-theme-tactile (= 0.2.0)
|
|
92
|
-
jekyll-theme-time-machine (= 0.2.0)
|
|
93
|
-
jekyll-titles-from-headings (= 0.5.3)
|
|
94
|
-
jemoji (= 0.13.0)
|
|
95
|
-
kramdown (= 2.4.0)
|
|
96
|
-
kramdown-parser-gfm (= 1.1.0)
|
|
97
|
-
liquid (= 4.0.4)
|
|
98
|
-
mercenary (~> 0.3)
|
|
99
|
-
minima (= 2.5.1)
|
|
100
|
-
nokogiri (>= 1.13.6, < 2.0)
|
|
101
|
-
rouge (= 3.30.0)
|
|
102
|
-
terminal-table (~> 1.4)
|
|
103
|
-
github-pages-health-check (1.18.2)
|
|
104
|
-
addressable (~> 2.3)
|
|
105
|
-
dnsruby (~> 1.60)
|
|
106
|
-
octokit (>= 4, < 8)
|
|
107
|
-
public_suffix (>= 3.0, < 6.0)
|
|
108
|
-
typhoeus (~> 1.3)
|
|
109
|
-
html-pipeline (2.14.3)
|
|
110
|
-
activesupport (>= 2)
|
|
111
|
-
nokogiri (>= 1.4)
|
|
112
|
-
http_parser.rb (0.8.0)
|
|
113
|
-
i18n (1.14.7)
|
|
114
|
-
concurrent-ruby (~> 1.0)
|
|
115
|
-
jekyll (3.9.5)
|
|
116
|
-
addressable (~> 2.4)
|
|
117
|
-
colorator (~> 1.0)
|
|
118
|
-
em-websocket (~> 0.5)
|
|
119
|
-
i18n (>= 0.7, < 2)
|
|
120
|
-
jekyll-sass-converter (~> 1.0)
|
|
121
|
-
jekyll-watch (~> 2.0)
|
|
122
|
-
kramdown (>= 1.17, < 3)
|
|
123
|
-
liquid (~> 4.0)
|
|
124
|
-
mercenary (~> 0.3.3)
|
|
125
|
-
pathutil (~> 0.9)
|
|
126
|
-
rouge (>= 1.7, < 4)
|
|
127
|
-
safe_yaml (~> 1.0)
|
|
128
|
-
jekyll-avatar (0.8.0)
|
|
129
|
-
jekyll (>= 3.0, < 5.0)
|
|
130
|
-
jekyll-coffeescript (1.2.2)
|
|
131
|
-
coffee-script (~> 2.2)
|
|
132
|
-
coffee-script-source (~> 1.12)
|
|
133
|
-
jekyll-commonmark (1.4.0)
|
|
134
|
-
commonmarker (~> 0.22)
|
|
135
|
-
jekyll-commonmark-ghpages (0.4.0)
|
|
136
|
-
commonmarker (~> 0.23.7)
|
|
137
|
-
jekyll (~> 3.9.0)
|
|
138
|
-
jekyll-commonmark (~> 1.4.0)
|
|
139
|
-
rouge (>= 2.0, < 5.0)
|
|
140
|
-
jekyll-default-layout (0.1.5)
|
|
141
|
-
jekyll (>= 3.0, < 5.0)
|
|
142
|
-
jekyll-feed (0.17.0)
|
|
143
|
-
jekyll (>= 3.7, < 5.0)
|
|
144
|
-
jekyll-gist (1.5.0)
|
|
145
|
-
octokit (~> 4.2)
|
|
146
|
-
jekyll-github-metadata (2.16.1)
|
|
147
|
-
jekyll (>= 3.4, < 5.0)
|
|
148
|
-
octokit (>= 4, < 7, != 4.4.0)
|
|
149
|
-
jekyll-include-cache (0.2.1)
|
|
150
|
-
jekyll (>= 3.7, < 5.0)
|
|
151
|
-
jekyll-mentions (1.6.0)
|
|
152
|
-
html-pipeline (~> 2.3)
|
|
153
|
-
jekyll (>= 3.7, < 5.0)
|
|
154
|
-
jekyll-optional-front-matter (0.3.2)
|
|
155
|
-
jekyll (>= 3.0, < 5.0)
|
|
156
|
-
jekyll-paginate (1.1.0)
|
|
157
|
-
jekyll-readme-index (0.3.0)
|
|
158
|
-
jekyll (>= 3.0, < 5.0)
|
|
159
|
-
jekyll-redirect-from (0.16.0)
|
|
160
|
-
jekyll (>= 3.3, < 5.0)
|
|
161
|
-
jekyll-relative-links (0.7.0)
|
|
162
|
-
jekyll (>= 3.3, < 5.0)
|
|
163
|
-
jekyll-remote-theme (0.4.3)
|
|
164
|
-
addressable (~> 2.0)
|
|
165
|
-
jekyll (>= 3.5, < 5.0)
|
|
166
|
-
jekyll-sass-converter (>= 1.0, <= 3.0.0, != 2.0.0)
|
|
167
|
-
rubyzip (>= 1.3.0, < 3.0)
|
|
168
|
-
jekyll-sass-converter (1.5.2)
|
|
169
|
-
sass (~> 3.4)
|
|
170
|
-
jekyll-seo-tag (2.8.0)
|
|
171
|
-
jekyll (>= 3.8, < 5.0)
|
|
172
|
-
jekyll-sitemap (1.4.0)
|
|
173
|
-
jekyll (>= 3.7, < 5.0)
|
|
174
|
-
jekyll-swiss (1.0.0)
|
|
175
|
-
jekyll-theme-architect (0.2.0)
|
|
176
|
-
jekyll (> 3.5, < 5.0)
|
|
177
|
-
jekyll-seo-tag (~> 2.0)
|
|
178
|
-
jekyll-theme-cayman (0.2.0)
|
|
179
|
-
jekyll (> 3.5, < 5.0)
|
|
180
|
-
jekyll-seo-tag (~> 2.0)
|
|
181
|
-
jekyll-theme-dinky (0.2.0)
|
|
182
|
-
jekyll (> 3.5, < 5.0)
|
|
183
|
-
jekyll-seo-tag (~> 2.0)
|
|
184
|
-
jekyll-theme-hacker (0.2.0)
|
|
185
|
-
jekyll (> 3.5, < 5.0)
|
|
186
|
-
jekyll-seo-tag (~> 2.0)
|
|
187
|
-
jekyll-theme-leap-day (0.2.0)
|
|
188
|
-
jekyll (> 3.5, < 5.0)
|
|
189
|
-
jekyll-seo-tag (~> 2.0)
|
|
190
|
-
jekyll-theme-merlot (0.2.0)
|
|
191
|
-
jekyll (> 3.5, < 5.0)
|
|
192
|
-
jekyll-seo-tag (~> 2.0)
|
|
193
|
-
jekyll-theme-midnight (0.2.0)
|
|
194
|
-
jekyll (> 3.5, < 5.0)
|
|
195
|
-
jekyll-seo-tag (~> 2.0)
|
|
196
|
-
jekyll-theme-minimal (0.2.0)
|
|
197
|
-
jekyll (> 3.5, < 5.0)
|
|
198
|
-
jekyll-seo-tag (~> 2.0)
|
|
199
|
-
jekyll-theme-modernist (0.2.0)
|
|
200
|
-
jekyll (> 3.5, < 5.0)
|
|
201
|
-
jekyll-seo-tag (~> 2.0)
|
|
202
|
-
jekyll-theme-primer (0.6.0)
|
|
203
|
-
jekyll (> 3.5, < 5.0)
|
|
204
|
-
jekyll-github-metadata (~> 2.9)
|
|
205
|
-
jekyll-seo-tag (~> 2.0)
|
|
206
|
-
jekyll-theme-slate (0.2.0)
|
|
207
|
-
jekyll (> 3.5, < 5.0)
|
|
208
|
-
jekyll-seo-tag (~> 2.0)
|
|
209
|
-
jekyll-theme-tactile (0.2.0)
|
|
210
|
-
jekyll (> 3.5, < 5.0)
|
|
211
|
-
jekyll-seo-tag (~> 2.0)
|
|
212
|
-
jekyll-theme-time-machine (0.2.0)
|
|
213
|
-
jekyll (> 3.5, < 5.0)
|
|
214
|
-
jekyll-seo-tag (~> 2.0)
|
|
215
|
-
jekyll-titles-from-headings (0.5.3)
|
|
216
|
-
jekyll (>= 3.3, < 5.0)
|
|
217
|
-
jekyll-watch (2.2.1)
|
|
218
|
-
listen (~> 3.0)
|
|
219
|
-
jemoji (0.13.0)
|
|
220
|
-
gemoji (>= 3, < 5)
|
|
221
|
-
html-pipeline (~> 2.2)
|
|
222
|
-
jekyll (>= 3.0, < 5.0)
|
|
223
|
-
json (2.12.2)
|
|
224
|
-
kramdown (2.4.0)
|
|
225
|
-
rexml
|
|
226
|
-
kramdown-parser-gfm (1.1.0)
|
|
227
|
-
kramdown (~> 2.0)
|
|
228
|
-
liquid (4.0.4)
|
|
229
|
-
listen (3.9.0)
|
|
230
|
-
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
231
|
-
rb-inotify (~> 0.9, >= 0.9.10)
|
|
232
|
-
logger (1.6.6)
|
|
233
|
-
mercenary (0.3.6)
|
|
234
|
-
minima (2.5.1)
|
|
235
|
-
jekyll (>= 3.5, < 5.0)
|
|
236
|
-
jekyll-feed (~> 0.9)
|
|
237
|
-
jekyll-seo-tag (~> 2.1)
|
|
238
|
-
minitest (5.25.5)
|
|
239
|
-
net-http (0.6.0)
|
|
240
|
-
uri
|
|
241
|
-
nokogiri (1.18.8-aarch64-linux-gnu)
|
|
242
|
-
racc (~> 1.4)
|
|
243
|
-
nokogiri (1.18.8-aarch64-linux-musl)
|
|
244
|
-
racc (~> 1.4)
|
|
245
|
-
nokogiri (1.18.8-arm-linux-gnu)
|
|
246
|
-
racc (~> 1.4)
|
|
247
|
-
nokogiri (1.18.8-arm-linux-musl)
|
|
248
|
-
racc (~> 1.4)
|
|
249
|
-
nokogiri (1.18.8-arm64-darwin)
|
|
250
|
-
racc (~> 1.4)
|
|
251
|
-
nokogiri (1.18.8-x86_64-darwin)
|
|
252
|
-
racc (~> 1.4)
|
|
253
|
-
nokogiri (1.18.8-x86_64-linux-gnu)
|
|
254
|
-
racc (~> 1.4)
|
|
255
|
-
nokogiri (1.18.8-x86_64-linux-musl)
|
|
256
|
-
racc (~> 1.4)
|
|
257
|
-
octokit (4.25.1)
|
|
258
|
-
faraday (>= 1, < 3)
|
|
259
|
-
sawyer (~> 0.9)
|
|
260
|
-
pathutil (0.16.2)
|
|
261
|
-
forwardable-extended (~> 2.6)
|
|
262
|
-
public_suffix (5.1.1)
|
|
263
|
-
racc (1.8.1)
|
|
264
|
-
rb-fsevent (0.11.2)
|
|
265
|
-
rb-inotify (0.11.1)
|
|
266
|
-
ffi (~> 1.0)
|
|
267
|
-
rexml (3.4.1)
|
|
268
|
-
rouge (3.30.0)
|
|
269
|
-
rubyzip (2.4.1)
|
|
270
|
-
safe_yaml (1.0.5)
|
|
271
|
-
sass (3.7.4)
|
|
272
|
-
sass-listen (~> 4.0.0)
|
|
273
|
-
sass-listen (4.0.0)
|
|
274
|
-
rb-fsevent (~> 0.9, >= 0.9.4)
|
|
275
|
-
rb-inotify (~> 0.9, >= 0.9.7)
|
|
276
|
-
sawyer (0.9.2)
|
|
277
|
-
addressable (>= 2.3.5)
|
|
278
|
-
faraday (>= 0.17.3, < 3)
|
|
279
|
-
securerandom (0.4.1)
|
|
280
|
-
simpleidn (0.2.3)
|
|
281
|
-
terminal-table (1.8.0)
|
|
282
|
-
unicode-display_width (~> 1.1, >= 1.1.1)
|
|
283
|
-
typhoeus (1.4.1)
|
|
284
|
-
ethon (>= 0.9.0)
|
|
285
|
-
tzinfo (2.0.6)
|
|
286
|
-
concurrent-ruby (~> 1.0)
|
|
287
|
-
unicode-display_width (1.8.0)
|
|
288
|
-
uri (1.0.3)
|
|
289
|
-
webrick (1.9.1)
|
|
290
|
-
|
|
291
|
-
PLATFORMS
|
|
292
|
-
aarch64-linux-gnu
|
|
293
|
-
aarch64-linux-musl
|
|
294
|
-
arm-linux-gnu
|
|
295
|
-
arm-linux-musl
|
|
296
|
-
arm64-darwin
|
|
297
|
-
x86_64-darwin
|
|
298
|
-
x86_64-linux-gnu
|
|
299
|
-
x86_64-linux-musl
|
|
300
|
-
|
|
301
|
-
DEPENDENCIES
|
|
302
|
-
github-pages
|
|
303
|
-
jekyll-relative-links
|
|
304
|
-
jekyll-seo-tag
|
|
305
|
-
webrick (~> 1.9)
|
|
306
|
-
|
|
307
|
-
BUNDLED WITH
|
|
308
|
-
2.6.9
|