json-rest-api 1.0.13 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/connectors_ideas/fastify.js +66 -68
  2. package/connectors_ideas/koa-plugin.js +50 -51
  3. package/eslint.config.js +13 -0
  4. package/examples/url-override-example.js +63 -63
  5. package/index.js +13 -13
  6. package/lib/enhanced-logger.js +51 -51
  7. package/lib/error-formatter.js +61 -61
  8. package/lib/rest-api-errors.js +28 -28
  9. package/package.json +9 -5
  10. package/plugins/core/bulk-operations-plugin.js +142 -145
  11. package/plugins/core/connectors/express-plugin.js +210 -217
  12. package/plugins/core/connectors/lib/busboy-detector.js +84 -84
  13. package/plugins/core/connectors/lib/formidable-detector.js +50 -50
  14. package/plugins/core/connectors/lib/request-helpers.js +74 -74
  15. package/plugins/core/file-handling-plugin.js +125 -125
  16. package/plugins/core/lib/anyapi/anyapi-registry.js +254 -254
  17. package/plugins/core/lib/anyapi/query/anyapi-query-adapter.js +287 -287
  18. package/plugins/core/lib/anyapi/schema-utils.js +101 -101
  19. package/plugins/core/lib/anyapi/utils/descriptor-helpers.js +41 -41
  20. package/plugins/core/lib/dbTablesOperations.js +134 -135
  21. package/plugins/core/lib/fractional-positioning.js +74 -76
  22. package/plugins/core/lib/querying/knex-cross-table-search.js +320 -320
  23. package/plugins/core/lib/querying/knex-json-api-transformers-querying.js +144 -144
  24. package/plugins/core/lib/querying/knex-pagination-helpers.js +164 -164
  25. package/plugins/core/lib/querying/knex-process-includes.js +50 -50
  26. package/plugins/core/lib/querying/knex-query-helpers-base.js +31 -31
  27. package/plugins/core/lib/querying/knex-query-helpers.js +451 -452
  28. package/plugins/core/lib/querying/knex-relationship-includes.js +1160 -1170
  29. package/plugins/core/lib/querying/knex-window-queries.js +89 -89
  30. package/plugins/core/lib/querying/url-helpers.js +35 -35
  31. package/plugins/core/lib/querying-writing/compile-schemas.js +97 -98
  32. package/plugins/core/lib/querying-writing/connectors-query-parser.js +31 -31
  33. package/plugins/core/lib/querying-writing/database-capabilities.js +94 -94
  34. package/plugins/core/lib/querying-writing/database-value-normalizers.js +76 -76
  35. package/plugins/core/lib/querying-writing/default-data-helpers.js +27 -27
  36. package/plugins/core/lib/querying-writing/field-utils.js +44 -42
  37. package/plugins/core/lib/querying-writing/knex-constants.js +15 -16
  38. package/plugins/core/lib/querying-writing/knex-field-helpers.js +117 -115
  39. package/plugins/core/lib/querying-writing/knex-json-api-transformers.js +41 -41
  40. package/plugins/core/lib/querying-writing/payload-validators.js +275 -275
  41. package/plugins/core/lib/querying-writing/schema-helpers.js +129 -129
  42. package/plugins/core/lib/querying-writing/scope-validations.js +143 -146
  43. package/plugins/core/lib/querying-writing/simplified-helpers.js +133 -129
  44. package/plugins/core/lib/storage/storage-adapter.js +68 -68
  45. package/plugins/core/lib/writing/knex-json-api-transformers-writing.js +31 -31
  46. package/plugins/core/lib/writing/many-to-many-manipulations.js +81 -81
  47. package/plugins/core/lib/writing/relationship-processor.js +58 -58
  48. package/plugins/core/rest-api-access.js +8 -8
  49. package/plugins/core/rest-api-anyapi-knex-plugin.js +920 -920
  50. package/plugins/core/rest-api-cors-plugin.js +170 -171
  51. package/plugins/core/rest-api-knex-plugin.js +482 -493
  52. package/plugins/core/rest-api-multihome-plugin.js +247 -251
  53. package/plugins/core/rest-api-plugin-hooks/compile-resource-schemas.js +5 -5
  54. package/plugins/core/rest-api-plugin-hooks/register-relationship-routes.js +20 -21
  55. package/plugins/core/rest-api-plugin-hooks/register-scope-routes.js +44 -44
  56. package/plugins/core/rest-api-plugin-hooks/turn-scope-init-into-vars.js +23 -23
  57. package/plugins/core/rest-api-plugin-hooks/validate-include-configurations.js +15 -15
  58. package/plugins/core/rest-api-plugin-methods/add-route.js +9 -9
  59. package/plugins/core/rest-api-plugin-methods/check-permissions.js +5 -6
  60. package/plugins/core/rest-api-plugin-methods/common.js +295 -297
  61. package/plugins/core/rest-api-plugin-methods/delete-relationship.js +35 -37
  62. package/plugins/core/rest-api-plugin-methods/delete.js +57 -59
  63. package/plugins/core/rest-api-plugin-methods/enrich-attributes.js +172 -171
  64. package/plugins/core/rest-api-plugin-methods/get-related.js +96 -96
  65. package/plugins/core/rest-api-plugin-methods/get-relationship.js +16 -18
  66. package/plugins/core/rest-api-plugin-methods/get.js +86 -86
  67. package/plugins/core/rest-api-plugin-methods/patch-relationship.js +16 -17
  68. package/plugins/core/rest-api-plugin-methods/patch.js +63 -64
  69. package/plugins/core/rest-api-plugin-methods/post-relationship.js +54 -55
  70. package/plugins/core/rest-api-plugin-methods/post.js +61 -62
  71. package/plugins/core/rest-api-plugin-methods/put.js +86 -87
  72. package/plugins/core/rest-api-plugin-methods/query.js +88 -88
  73. package/plugins/core/rest-api-plugin-methods/release.js +5 -6
  74. package/plugins/core/rest-api-plugin.js +76 -78
  75. package/plugins/core/rest-api-positioning-plugin.js +251 -252
  76. package/plugins/core/socketio-plugin.js +240 -236
  77. package/plugins/storage/local-storage.js +103 -103
  78. package/plugins/storage/s3-storage.js +41 -42
  79. package/quickTest.js +37 -37
  80. package/scripts/debug-anyapi-review-filter.mjs +18 -18
  81. package/scripts/inspect-anyapi-descriptor-country.mjs +10 -10
  82. package/scripts/inspect-anyapi-descriptor.mjs +10 -10
  83. package/scripts/run-docs.js +112 -113
  84. package/test-debug.js +28 -28
  85. package/tests/TEST_TEMPLATE.test.js +51 -51
  86. package/tests/anyapi-basic.test.js +42 -42
  87. package/tests/anyapi-cursor-pagination.test.js +48 -48
  88. package/tests/bulk-operations.test.js +208 -208
  89. package/tests/computed-fields.test.js +204 -204
  90. package/tests/cors.test.js +412 -413
  91. package/tests/curl.test.js +275 -276
  92. package/tests/custom-idproperty-relationships.test.js +266 -266
  93. package/tests/field-getters.test.js +132 -132
  94. package/tests/field-setters.test.js +110 -110
  95. package/tests/fixtures/api-configs.js +699 -699
  96. package/tests/helpers/storage-mode.js +32 -32
  97. package/tests/helpers/test-utils.js +76 -76
  98. package/tests/include-depth-validation.test.js +76 -76
  99. package/tests/includes.test.js +145 -145
  100. package/tests/multihome.test.js +175 -175
  101. package/tests/nested-includes.test.js +255 -255
  102. package/tests/pagination-cursor-multifield.test.js +164 -164
  103. package/tests/pagination-enhanced.test.js +225 -225
  104. package/tests/polymorphic-relationships.test.js +96 -96
  105. package/tests/polymorphic-simple.test.js +44 -44
  106. package/tests/positioning-advanced.test.js +226 -226
  107. package/tests/positioning-extended.test.js +399 -399
  108. package/tests/positioning-multifilter.test.js +204 -204
  109. package/tests/positioning.test.js +266 -266
  110. package/tests/queries.test.js +184 -184
  111. package/tests/query-limits.test.js +154 -155
  112. package/tests/relationship-endpoints.test.js +127 -127
  113. package/tests/relationships.test.js +178 -179
  114. package/tests/rest-api-access.test.js +86 -86
  115. package/tests/rest-api.test.js +103 -103
  116. package/tests/searchschema-merge.test.js +93 -93
  117. package/tests/socketio.test.js +326 -326
  118. 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: schemaInstance, schemaRelationships: relationships, idProperty }
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
+ }