json-rest-api 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/connectors_ideas/fastify.js +66 -68
- package/connectors_ideas/koa-plugin.js +50 -51
- package/eslint.config.js +11 -2
- package/examples/url-override-example.js +63 -63
- package/index.js +13 -13
- package/lib/enhanced-logger.js +51 -51
- package/lib/error-formatter.js +61 -61
- package/lib/rest-api-errors.js +28 -28
- package/package.json +1 -1
- package/plugins/core/bulk-operations-plugin.js +142 -145
- package/plugins/core/connectors/express-plugin.js +210 -217
- package/plugins/core/connectors/lib/busboy-detector.js +84 -84
- package/plugins/core/connectors/lib/formidable-detector.js +50 -50
- package/plugins/core/connectors/lib/request-helpers.js +74 -74
- package/plugins/core/file-handling-plugin.js +125 -125
- package/plugins/core/lib/anyapi/anyapi-registry.js +254 -254
- package/plugins/core/lib/anyapi/query/anyapi-query-adapter.js +287 -287
- package/plugins/core/lib/anyapi/schema-utils.js +101 -101
- package/plugins/core/lib/anyapi/utils/descriptor-helpers.js +41 -41
- package/plugins/core/lib/dbTablesOperations.js +134 -135
- package/plugins/core/lib/fractional-positioning.js +74 -76
- package/plugins/core/lib/querying/knex-cross-table-search.js +320 -320
- package/plugins/core/lib/querying/knex-json-api-transformers-querying.js +144 -144
- package/plugins/core/lib/querying/knex-pagination-helpers.js +164 -164
- package/plugins/core/lib/querying/knex-process-includes.js +50 -50
- package/plugins/core/lib/querying/knex-query-helpers-base.js +31 -31
- package/plugins/core/lib/querying/knex-query-helpers.js +451 -452
- package/plugins/core/lib/querying/knex-relationship-includes.js +1160 -1170
- package/plugins/core/lib/querying/knex-window-queries.js +89 -89
- package/plugins/core/lib/querying/url-helpers.js +35 -35
- package/plugins/core/lib/querying-writing/compile-schemas.js +99 -99
- package/plugins/core/lib/querying-writing/connectors-query-parser.js +31 -31
- package/plugins/core/lib/querying-writing/database-capabilities.js +94 -94
- package/plugins/core/lib/querying-writing/database-value-normalizers.js +76 -76
- package/plugins/core/lib/querying-writing/default-data-helpers.js +27 -27
- package/plugins/core/lib/querying-writing/field-utils.js +44 -42
- package/plugins/core/lib/querying-writing/knex-constants.js +15 -16
- package/plugins/core/lib/querying-writing/knex-field-helpers.js +117 -115
- package/plugins/core/lib/querying-writing/knex-json-api-transformers.js +41 -41
- package/plugins/core/lib/querying-writing/payload-validators.js +275 -275
- package/plugins/core/lib/querying-writing/schema-helpers.js +129 -129
- package/plugins/core/lib/querying-writing/scope-validations.js +143 -146
- package/plugins/core/lib/querying-writing/simplified-helpers.js +133 -129
- package/plugins/core/lib/storage/storage-adapter.js +68 -68
- package/plugins/core/lib/writing/knex-json-api-transformers-writing.js +31 -31
- package/plugins/core/lib/writing/many-to-many-manipulations.js +81 -81
- package/plugins/core/lib/writing/relationship-processor.js +58 -58
- package/plugins/core/rest-api-access.js +11 -15
- package/plugins/core/rest-api-anyapi-knex-plugin.js +920 -920
- package/plugins/core/rest-api-cors-plugin.js +170 -171
- package/plugins/core/rest-api-knex-plugin.js +482 -493
- package/plugins/core/rest-api-multihome-plugin.js +247 -251
- package/plugins/core/rest-api-plugin-hooks/compile-resource-schemas.js +5 -5
- package/plugins/core/rest-api-plugin-hooks/register-relationship-routes.js +20 -21
- package/plugins/core/rest-api-plugin-hooks/register-scope-routes.js +44 -44
- package/plugins/core/rest-api-plugin-hooks/turn-scope-init-into-vars.js +23 -23
- package/plugins/core/rest-api-plugin-hooks/validate-include-configurations.js +15 -15
- package/plugins/core/rest-api-plugin-methods/add-route.js +9 -9
- package/plugins/core/rest-api-plugin-methods/check-permissions.js +5 -6
- package/plugins/core/rest-api-plugin-methods/common.js +295 -297
- package/plugins/core/rest-api-plugin-methods/delete-relationship.js +35 -37
- package/plugins/core/rest-api-plugin-methods/delete.js +57 -59
- package/plugins/core/rest-api-plugin-methods/enrich-attributes.js +172 -171
- package/plugins/core/rest-api-plugin-methods/get-related.js +96 -96
- package/plugins/core/rest-api-plugin-methods/get-relationship.js +16 -18
- package/plugins/core/rest-api-plugin-methods/get.js +86 -86
- package/plugins/core/rest-api-plugin-methods/patch-relationship.js +16 -17
- package/plugins/core/rest-api-plugin-methods/patch.js +63 -64
- package/plugins/core/rest-api-plugin-methods/post-relationship.js +54 -55
- package/plugins/core/rest-api-plugin-methods/post.js +61 -62
- package/plugins/core/rest-api-plugin-methods/put.js +86 -87
- package/plugins/core/rest-api-plugin-methods/query.js +88 -88
- package/plugins/core/rest-api-plugin-methods/release.js +5 -6
- package/plugins/core/rest-api-plugin.js +76 -78
- package/plugins/core/rest-api-positioning-plugin.js +251 -252
- package/plugins/core/socketio-plugin.js +240 -236
- package/plugins/storage/local-storage.js +103 -103
- package/plugins/storage/s3-storage.js +41 -42
- package/quickTest.js +37 -37
- package/scripts/debug-anyapi-review-filter.mjs +18 -18
- package/scripts/inspect-anyapi-descriptor-country.mjs +10 -10
- package/scripts/inspect-anyapi-descriptor.mjs +10 -10
- package/scripts/run-docs.js +112 -113
- package/test-debug.js +28 -28
- package/tests/TEST_TEMPLATE.test.js +51 -51
- package/tests/anyapi-basic.test.js +42 -42
- package/tests/anyapi-cursor-pagination.test.js +48 -48
- package/tests/bulk-operations.test.js +208 -208
- package/tests/computed-fields.test.js +204 -204
- package/tests/cors.test.js +412 -413
- package/tests/curl.test.js +275 -276
- package/tests/custom-idproperty-relationships.test.js +266 -266
- package/tests/field-getters.test.js +132 -132
- package/tests/field-setters.test.js +110 -110
- package/tests/fixtures/api-configs.js +699 -699
- package/tests/helpers/storage-mode.js +32 -32
- package/tests/helpers/test-utils.js +76 -76
- package/tests/include-depth-validation.test.js +76 -76
- package/tests/includes.test.js +145 -145
- package/tests/multihome.test.js +175 -175
- package/tests/nested-includes.test.js +255 -255
- package/tests/pagination-cursor-multifield.test.js +164 -164
- package/tests/pagination-enhanced.test.js +225 -225
- package/tests/polymorphic-relationships.test.js +96 -96
- package/tests/polymorphic-simple.test.js +44 -44
- package/tests/positioning-advanced.test.js +226 -226
- package/tests/positioning-extended.test.js +399 -399
- package/tests/positioning-multifilter.test.js +204 -204
- package/tests/positioning.test.js +266 -266
- package/tests/queries.test.js +184 -184
- package/tests/query-limits.test.js +154 -155
- package/tests/relationship-endpoints.test.js +127 -127
- package/tests/relationships.test.js +178 -179
- package/tests/rest-api-access.test.js +86 -86
- package/tests/rest-api.test.js +103 -103
- package/tests/searchschema-merge.test.js +93 -93
- package/tests/socketio.test.js +326 -326
- package/tests/virtual-fields.test.js +164 -164
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { toJsonApiRecord } from '../querying/knex-json-api-transformers-querying.js'
|
|
2
|
-
import { getSchemaStructure } from './knex-constants.js'
|
|
1
|
+
import { toJsonApiRecord } from '../querying/knex-json-api-transformers-querying.js'
|
|
2
|
+
import { getSchemaStructure } from './knex-constants.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Converts database record to JSON:API format with belongsTo relationships
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* @param {Object} scope - Resource scope with schema and relationship info
|
|
8
8
|
* @param {Object} record - Raw database record
|
|
9
9
|
* @param {string} scopeName - Resource type name
|
|
10
10
|
* @returns {Object} JSON:API resource with belongsTo relationships
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
12
|
* @example
|
|
13
13
|
* // Input: Database record with foreign keys
|
|
14
14
|
* const dbRecord = {
|
|
@@ -19,7 +19,7 @@ import { getSchemaStructure } from './knex-constants.js';
|
|
|
19
19
|
* category_id: null
|
|
20
20
|
* };
|
|
21
21
|
* const result = toJsonApiRecordWithBelongsTo(scope, dbRecord, 'articles');
|
|
22
|
-
*
|
|
22
|
+
*
|
|
23
23
|
* // Output: JSON:API with relationship objects
|
|
24
24
|
* // {
|
|
25
25
|
* // type: 'articles',
|
|
@@ -40,7 +40,7 @@ import { getSchemaStructure } from './knex-constants.js';
|
|
|
40
40
|
* // }
|
|
41
41
|
* // }
|
|
42
42
|
* // }
|
|
43
|
-
*
|
|
43
|
+
*
|
|
44
44
|
* @example
|
|
45
45
|
* // Input: Polymorphic relationships
|
|
46
46
|
* const dbRecord = {
|
|
@@ -57,7 +57,7 @@ import { getSchemaStructure } from './knex-constants.js';
|
|
|
57
57
|
* // idField: 'commentable_id'
|
|
58
58
|
* // }
|
|
59
59
|
* // }
|
|
60
|
-
*
|
|
60
|
+
*
|
|
61
61
|
* // Output: Polymorphic relationship in JSON:API
|
|
62
62
|
* // {
|
|
63
63
|
* // type: 'comments',
|
|
@@ -69,19 +69,19 @@ import { getSchemaStructure } from './knex-constants.js';
|
|
|
69
69
|
* // }
|
|
70
70
|
* // }
|
|
71
71
|
* // }
|
|
72
|
-
*
|
|
72
|
+
*
|
|
73
73
|
* @description
|
|
74
74
|
* Used by:
|
|
75
75
|
* - dataGetMinimal for lightweight single record fetches
|
|
76
76
|
* - dataDelete to return deleted record structure
|
|
77
77
|
* - Internal operations needing quick JSON:API conversion
|
|
78
|
-
*
|
|
78
|
+
*
|
|
79
79
|
* Purpose:
|
|
80
80
|
* - Provides JSON:API structure without loading related data
|
|
81
81
|
* - Transforms foreign keys into relationship objects
|
|
82
82
|
* - Handles both regular and polymorphic belongsTo
|
|
83
83
|
* - Maintains explicit nulls for empty relationships
|
|
84
|
-
*
|
|
84
|
+
*
|
|
85
85
|
* Data flow:
|
|
86
86
|
* 1. Calls toJsonApiRecord for basic transformation
|
|
87
87
|
* 2. Scans schema for belongsTo field definitions
|
|
@@ -90,73 +90,73 @@ import { getSchemaStructure } from './knex-constants.js';
|
|
|
90
90
|
* 5. Returns complete JSON:API resource object
|
|
91
91
|
*/
|
|
92
92
|
export const toJsonApiRecordWithBelongsTo = (scope, record, scopeName) => {
|
|
93
|
-
if (!record) return null
|
|
94
|
-
|
|
93
|
+
if (!record) return null
|
|
94
|
+
|
|
95
95
|
// Get the basic JSON:API structure (without relationships)
|
|
96
|
-
const jsonApiRecord = toJsonApiRecord(scope, record, scopeName)
|
|
97
|
-
|
|
96
|
+
const jsonApiRecord = toJsonApiRecord(scope, record, scopeName)
|
|
97
|
+
|
|
98
98
|
// Extract schema info from scope
|
|
99
|
-
const {
|
|
100
|
-
vars: {
|
|
101
|
-
schemaInfo: { schemaInstance
|
|
99
|
+
const {
|
|
100
|
+
vars: {
|
|
101
|
+
schemaInfo: { schemaInstance, schemaRelationships: relationships, idProperty }
|
|
102
102
|
}
|
|
103
|
-
} = scope
|
|
104
|
-
|
|
105
|
-
const idField = idProperty || 'id'
|
|
106
|
-
|
|
103
|
+
} = scope
|
|
104
|
+
|
|
105
|
+
const idField = idProperty || 'id'
|
|
106
|
+
|
|
107
107
|
// Get schema structure
|
|
108
|
-
const schemaStructure = getSchemaStructure(schemaInstance)
|
|
109
|
-
|
|
108
|
+
const schemaStructure = getSchemaStructure(schemaInstance)
|
|
109
|
+
|
|
110
110
|
// Initialize relationships object
|
|
111
|
-
jsonApiRecord.relationships = {}
|
|
112
|
-
|
|
111
|
+
jsonApiRecord.relationships = {}
|
|
112
|
+
|
|
113
113
|
// Process regular belongsTo relationships from schema
|
|
114
114
|
for (const [fieldName, fieldDef] of Object.entries(schemaStructure)) {
|
|
115
115
|
if (fieldDef.belongsTo && fieldDef.as) {
|
|
116
|
-
const foreignKeyValue = record[fieldName]
|
|
117
|
-
|
|
116
|
+
const foreignKeyValue = record[fieldName]
|
|
117
|
+
|
|
118
118
|
if (foreignKeyValue !== null && foreignKeyValue !== undefined) {
|
|
119
119
|
jsonApiRecord.relationships[fieldDef.as] = {
|
|
120
120
|
data: {
|
|
121
121
|
type: fieldDef.belongsTo,
|
|
122
122
|
id: String(foreignKeyValue)
|
|
123
123
|
}
|
|
124
|
-
}
|
|
124
|
+
}
|
|
125
125
|
} else {
|
|
126
126
|
// Explicitly null relationship
|
|
127
127
|
jsonApiRecord.relationships[fieldDef.as] = {
|
|
128
128
|
data: null
|
|
129
|
-
}
|
|
129
|
+
}
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
|
|
134
134
|
// Process polymorphic belongsTo relationships
|
|
135
135
|
Object.entries(relationships || {}).forEach(([relName, relDef]) => {
|
|
136
136
|
if (relDef.belongsToPolymorphic) {
|
|
137
|
-
const typeValue = record[relDef.typeField]
|
|
138
|
-
const idValue = record[relDef.idField]
|
|
139
|
-
|
|
137
|
+
const typeValue = record[relDef.typeField]
|
|
138
|
+
const idValue = record[relDef.idField]
|
|
139
|
+
|
|
140
140
|
if (typeValue && idValue) {
|
|
141
141
|
jsonApiRecord.relationships[relName] = {
|
|
142
142
|
data: {
|
|
143
143
|
type: typeValue,
|
|
144
144
|
id: String(idValue)
|
|
145
145
|
}
|
|
146
|
-
}
|
|
146
|
+
}
|
|
147
147
|
} else {
|
|
148
148
|
// Explicitly null relationship
|
|
149
149
|
jsonApiRecord.relationships[relName] = {
|
|
150
150
|
data: null
|
|
151
|
-
}
|
|
151
|
+
}
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
})
|
|
155
|
-
|
|
154
|
+
})
|
|
155
|
+
|
|
156
156
|
// Remove relationships object if empty
|
|
157
157
|
if (Object.keys(jsonApiRecord.relationships).length === 0) {
|
|
158
|
-
delete jsonApiRecord.relationships
|
|
158
|
+
delete jsonApiRecord.relationships
|
|
159
159
|
}
|
|
160
|
-
|
|
161
|
-
return jsonApiRecord
|
|
162
|
-
}
|
|
160
|
+
|
|
161
|
+
return jsonApiRecord
|
|
162
|
+
}
|