json-rest-api 1.0.14 → 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 +11 -2
  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 +1 -1
  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,54 +1,52 @@
1
- import { validateRelationships } from './lib/querying-writing/scope-validations.js';
1
+ import { validateRelationships } from './lib/querying-writing/scope-validations.js'
2
2
 
3
3
  // Import hook functions
4
- import compileResourceSchemas from './rest-api-plugin-hooks/compile-resource-schemas.js';
5
- import validateIncludeConfigurations from './rest-api-plugin-hooks/validate-include-configurations.js';
6
- import turnScopeInitIntoVars from './rest-api-plugin-hooks/turn-scope-init-into-vars.js';
7
- import registerScopeRoutes from './rest-api-plugin-hooks/register-scope-routes.js';
8
- import registerRelationshipRoutes from './rest-api-plugin-hooks/register-relationship-routes.js';
4
+ import compileResourceSchemas from './rest-api-plugin-hooks/compile-resource-schemas.js'
5
+ import validateIncludeConfigurations from './rest-api-plugin-hooks/validate-include-configurations.js'
6
+ import turnScopeInitIntoVars from './rest-api-plugin-hooks/turn-scope-init-into-vars.js'
7
+ import registerScopeRoutes from './rest-api-plugin-hooks/register-scope-routes.js'
8
+ import registerRelationshipRoutes from './rest-api-plugin-hooks/register-relationship-routes.js'
9
9
 
10
10
  // Import method functions
11
- import queryMethod from './rest-api-plugin-methods/query.js';
12
- import getMethod from './rest-api-plugin-methods/get.js';
13
- import postMethod from './rest-api-plugin-methods/post.js';
14
- import putMethod from './rest-api-plugin-methods/put.js';
15
- import patchMethod from './rest-api-plugin-methods/patch.js';
16
- import deleteMethod from './rest-api-plugin-methods/delete.js';
17
- import enrichAttributesMethod from './rest-api-plugin-methods/enrich-attributes.js';
18
- import checkPermissionsMethod from './rest-api-plugin-methods/check-permissions.js';
19
- import addRouteMethod from './rest-api-plugin-methods/add-route.js';
20
- import releaseMethod from './rest-api-plugin-methods/release.js';
21
- import { defaultDataHelpers } from './lib/querying-writing/default-data-helpers.js';
22
- import { DEFAULT_QUERY_LIMIT, DEFAULT_MAX_QUERY_LIMIT, DEFAULT_INCLUDE_DEPTH_LIMIT } from './lib/querying-writing/knex-constants.js';
23
-
24
- import getRelatedMethod from './rest-api-plugin-methods/get-related.js';
25
- import postRelationshipMethod from './rest-api-plugin-methods/post-relationship.js';
26
- import getRelationshipMethod from './rest-api-plugin-methods/get-relationship.js';
27
- import patchRelationshipMethod from './rest-api-plugin-methods/patch-relationship.js';
28
- import deleteRelationshipMethod from './rest-api-plugin-methods/delete-relationship.js';
29
-
11
+ import queryMethod from './rest-api-plugin-methods/query.js'
12
+ import getMethod from './rest-api-plugin-methods/get.js'
13
+ import postMethod from './rest-api-plugin-methods/post.js'
14
+ import putMethod from './rest-api-plugin-methods/put.js'
15
+ import patchMethod from './rest-api-plugin-methods/patch.js'
16
+ import deleteMethod from './rest-api-plugin-methods/delete.js'
17
+ import enrichAttributesMethod from './rest-api-plugin-methods/enrich-attributes.js'
18
+ import checkPermissionsMethod from './rest-api-plugin-methods/check-permissions.js'
19
+ import addRouteMethod from './rest-api-plugin-methods/add-route.js'
20
+ import releaseMethod from './rest-api-plugin-methods/release.js'
21
+ import { defaultDataHelpers } from './lib/querying-writing/default-data-helpers.js'
22
+ import { DEFAULT_QUERY_LIMIT, DEFAULT_MAX_QUERY_LIMIT, DEFAULT_INCLUDE_DEPTH_LIMIT } from './lib/querying-writing/knex-constants.js'
23
+
24
+ import getRelatedMethod from './rest-api-plugin-methods/get-related.js'
25
+ import postRelationshipMethod from './rest-api-plugin-methods/post-relationship.js'
26
+ import getRelationshipMethod from './rest-api-plugin-methods/get-relationship.js'
27
+ import patchRelationshipMethod from './rest-api-plugin-methods/patch-relationship.js'
28
+ import deleteRelationshipMethod from './rest-api-plugin-methods/delete-relationship.js'
30
29
 
31
30
  export const RestApiPlugin = {
32
31
  name: 'rest-api',
33
32
 
34
- install({ helpers, addScopeMethod, addApiMethod, vars, addHook, runHooks, apiOptions, pluginOptions, api, setScopeAlias, scopes, log, on }) {
35
-
33
+ install ({ helpers, addScopeMethod, addApiMethod, vars, addHook, runHooks, apiOptions, pluginOptions, api, setScopeAlias, scopes, log, on }) {
36
34
  // **************
37
35
  // Initial setup
38
36
  // **************
39
37
 
40
38
  // Initialize the rest namespace for REST API functionality
41
- api.rest = {};
39
+ api.rest = {}
42
40
 
43
41
  // Set up REST-friendly aliases
44
- setScopeAlias('resources', 'addResource');
42
+ setScopeAlias('resources', 'addResource')
45
43
 
46
44
  // **********
47
45
  // Variables
48
46
  // **********
49
47
 
50
48
  // Initialize default vars for the plugin from pluginOptions
51
- const restApiOptions = pluginOptions || {};
49
+ const restApiOptions = pluginOptions || {}
52
50
 
53
51
  // These will be used as default fallbacks by the vars proxy if
54
52
  // they are not set in the scope options
@@ -58,22 +56,22 @@ export const RestApiPlugin = {
58
56
  vars.enablePaginationCounts = restApiOptions.enablePaginationCounts || true
59
57
 
60
58
  // New simplified settings
61
- vars.simplifiedTransport = restApiOptions.simplifiedTransport !== undefined
62
- ? restApiOptions.simplifiedTransport
63
- : false; // Default false for JSON:API compliance over the wire
64
-
65
- vars.simplifiedApi = restApiOptions.simplifiedApi !== undefined
66
- ? restApiOptions.simplifiedApi
67
- : true; // Default true for better DX in programmatic API
68
-
59
+ vars.simplifiedTransport = restApiOptions.simplifiedTransport !== undefined
60
+ ? restApiOptions.simplifiedTransport
61
+ : false // Default false for JSON:API compliance over the wire
62
+
63
+ vars.simplifiedApi = restApiOptions.simplifiedApi !== undefined
64
+ ? restApiOptions.simplifiedApi
65
+ : true // Default true for better DX in programmatic API
66
+
69
67
  vars.idProperty = restApiOptions.idProperty || 'id'
70
68
 
71
69
  // Return full record configuration for API and Transport
72
70
  // Support values: 'no', 'minimal', 'full'
73
71
  const normalizeReturnValue = (value, defaultValue) => {
74
- if (['no', 'minimal', 'full'].includes(value)) return value;
75
- return defaultValue;
76
- };
72
+ if (['no', 'minimal', 'full'].includes(value)) return value
73
+ return defaultValue
74
+ }
77
75
 
78
76
  const optionConfigs = [
79
77
  {
@@ -84,73 +82,73 @@ export const RestApiPlugin = {
84
82
  propName: 'returnRecordTransport',
85
83
  defaultValue: 'no',
86
84
  },
87
- ];
85
+ ]
88
86
 
89
87
  for (const config of optionConfigs) {
90
- const optionValue = restApiOptions[config.propName];
91
- let processedValue;
88
+ const optionValue = restApiOptions[config.propName]
89
+ let processedValue
92
90
 
93
91
  if (typeof optionValue === 'object' && optionValue !== null) {
94
92
  processedValue = {
95
93
  post: normalizeReturnValue(optionValue.post, config.defaultValue),
96
94
  put: normalizeReturnValue(optionValue.put, config.defaultValue),
97
95
  patch: normalizeReturnValue(optionValue.patch, config.defaultValue),
98
- };
96
+ }
99
97
  } else if (optionValue !== undefined) {
100
- const normalized = normalizeReturnValue(optionValue, config.defaultValue);
101
- processedValue = { post: normalized, put: normalized, patch: normalized };
98
+ const normalized = normalizeReturnValue(optionValue, config.defaultValue)
99
+ processedValue = { post: normalized, put: normalized, patch: normalized }
102
100
  } else {
103
- processedValue = { post: config.defaultValue, put: config.defaultValue, patch: config.defaultValue };
101
+ processedValue = { post: config.defaultValue, put: config.defaultValue, patch: config.defaultValue }
104
102
  }
105
- vars[config.propName] = processedValue;
103
+ vars[config.propName] = processedValue
106
104
  }
107
105
 
108
- log.debug('returnRecordApi configuration:', vars.returnRecordApi);
109
- log.debug('returnRecordTransport configuration:', vars.returnRecordTransport);
106
+ log.debug('returnRecordApi configuration:', vars.returnRecordApi)
107
+ log.debug('returnRecordTransport configuration:', vars.returnRecordTransport)
110
108
 
111
109
  // Schema cache vars
112
- vars.schemaProcessed = false;
113
- vars.schema = null;
110
+ vars.schemaProcessed = false
111
+ vars.schema = null
114
112
 
115
113
  // ******************************
116
114
  // Scope (resources) added hooks
117
115
  // ******************************
118
116
 
119
- addHook('scope:added', 'validateRelationships', {}, validateRelationships);
120
- addHook('scope:added', 'compileResourceSchemas', {}, compileResourceSchemas);
121
- addHook('scope:added', 'validateIncludeConfigurations', {}, validateIncludeConfigurations);
117
+ addHook('scope:added', 'validateRelationships', {}, validateRelationships)
118
+ addHook('scope:added', 'compileResourceSchemas', {}, compileResourceSchemas)
119
+ addHook('scope:added', 'validateIncludeConfigurations', {}, validateIncludeConfigurations)
122
120
  addHook('scope:added', 'turnScopeInitIntoVars', {}, turnScopeInitIntoVars)
123
-
121
+
124
122
  // *********
125
123
  // Methods
126
124
  // *********
127
125
 
128
- addApiMethod('addRoute', addRouteMethod);
126
+ addApiMethod('addRoute', addRouteMethod)
129
127
 
130
- addApiMethod('release', releaseMethod);
128
+ addApiMethod('release', releaseMethod)
131
129
 
132
130
  // Main REST methods
133
- addScopeMethod('query', queryMethod);
134
- addScopeMethod('get', getMethod);
135
- addScopeMethod('post', postMethod);
136
- addScopeMethod('put', putMethod);
137
- addScopeMethod('patch', patchMethod);
138
- addScopeMethod('delete', deleteMethod);
139
-
131
+ addScopeMethod('query', queryMethod)
132
+ addScopeMethod('get', getMethod)
133
+ addScopeMethod('post', postMethod)
134
+ addScopeMethod('put', putMethod)
135
+ addScopeMethod('patch', patchMethod)
136
+ addScopeMethod('delete', deleteMethod)
137
+
140
138
  // Relationship methods
141
- addScopeMethod('getRelationship', getRelationshipMethod);
142
- addScopeMethod('getRelated', getRelatedMethod);
139
+ addScopeMethod('getRelationship', getRelationshipMethod)
140
+ addScopeMethod('getRelated', getRelatedMethod)
143
141
  addScopeMethod('postRelationship', postRelationshipMethod)
144
- addScopeMethod('patchRelationship', patchRelationshipMethod);
145
- addScopeMethod('deleteRelationship', deleteRelationshipMethod );
142
+ addScopeMethod('patchRelationship', patchRelationshipMethod)
143
+ addScopeMethod('deleteRelationship', deleteRelationshipMethod)
144
+
145
+ addHook('scope:added', 'registerRelationshipRoutes', {}, registerRelationshipRoutes)
146
+ addHook('scope:added', 'registerScopeRoutes', {}, registerScopeRoutes)
146
147
 
147
- addHook('scope:added', 'registerRelationshipRoutes', {}, registerRelationshipRoutes);
148
- addHook('scope:added', 'registerScopeRoutes', {}, registerScopeRoutes);
149
-
150
148
  // Non-URL methods
151
- addScopeMethod('enrichAttributes', enrichAttributesMethod);
152
- addScopeMethod('checkPermissions', checkPermissionsMethod);
153
-
149
+ addScopeMethod('enrichAttributes', enrichAttributesMethod)
150
+ addScopeMethod('checkPermissions', checkPermissionsMethod)
151
+
154
152
  // *********
155
153
  // Helpers
156
154
  // *********
@@ -158,10 +156,10 @@ export const RestApiPlugin = {
158
156
  // Initialize default data helpers that throw errors until a storage plugin is installed
159
157
  // These placeholders show storage plugin developers what methods to implement
160
158
  // Example: helpers.dataGet, helpers.dataPost, etc. will throw "No storage implementation" errors
161
- Object.assign(helpers, defaultDataHelpers);
159
+ Object.assign(helpers, defaultDataHelpers)
162
160
 
163
161
  // Add default getLocation helper for generating resource URLs
164
162
  // This can be overridden by storage plugins if needed
165
163
  helpers.getLocation = ({ scopeName, id }) => `/${scopeName}/${id}`
166
164
  }
167
- };
165
+ }