json-rest-api 1.0.7 → 1.0.8

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 (146) hide show
  1. package/.claude/agents/library-guide-expert.md +29 -0
  2. package/.claude/agents/rest-api-internals-expert.md +53 -0
  3. package/CLAUDE.md +139 -1
  4. package/README.md +2 -5
  5. package/docTest.js +238 -0
  6. package/docs/GUIDE/GUIDE_1_Initial_Setup.md +955 -0
  7. package/docs/GUIDE/GUIDE_2_1_The_Starting_Point.md +54 -0
  8. package/docs/GUIDE/GUIDE_2_2_Manipulating_And_Searching_Tables.md +750 -0
  9. package/docs/GUIDE/GUIDE_2_3_BelongsTo_Relationships.md +494 -0
  10. package/docs/GUIDE/GUIDE_2_4_HasMany_Records.md +398 -0
  11. package/docs/GUIDE/GUIDE_2_5_HasMany_Polymorphic.md +882 -0
  12. package/docs/GUIDE/GUIDE_2_6_Many_To_Many.md +709 -0
  13. package/docs/GUIDE/GUIDE_2_7_Pagination_And_Ordering.md +1233 -0
  14. package/docs/GUIDE/GUIDE_2_8_Effects_of_PUT_and_PATCH.md +796 -0
  15. package/{README_X_Relationship_Plugin.md → docs/GUIDE/GUIDE_2_9_Relationships_Urls.md} +1 -4
  16. package/docs/GUIDE/GUIDE_2_Data_And_Relations.md +66 -0
  17. package/docs/GUIDE/GUIDE_3_Field_Transformations.md +1246 -0
  18. package/docs/GUIDE/GUIDE_5_Non-Db_Stores.md +0 -0
  19. package/docs/GUIDE/GUIDE_7_Hooks_Data_Management_And_Plugins.md +1490 -0
  20. package/{README_X_SocketIO.md → docs/GUIDE/GUIDE_X_SocketIO.md} +17 -17
  21. package/docs/GUIDE/index.md +58 -0
  22. package/docs/GUIDE.md +61 -2238
  23. package/docs/ONBOARDING/Computed_Properties_And_Sparse_Fields.md +398 -0
  24. package/docs/README.md +57 -2239
  25. package/{README_2_Computed_and_hidden_fields.md → docs/README_VARIOUS/GUIDE_2_Computed_and_hidden_fields.md} +22 -17
  26. package/docs/README_VARIOUS/GUIDE_IN_DOCS.md +2277 -0
  27. package/{README.ORIG.md → docs/README_VARIOUS/README.ORIG.md} +8 -8
  28. package/{README_8_Polymorphic_Relationships.md → docs/README_VARIOUS/README_8_Polymorphic_Relationships.md} +1 -1
  29. package/docs/README_VARIOUS/README_IN_DOCS.ms +2277 -0
  30. package/{RELATIONSHIPS_ADVANCED.md → docs/README_VARIOUS/RELATIONSHIPS_ADVANCED.md} +3 -3
  31. package/{correct-schema-format.md → docs/README_VARIOUS/correct-schema-format.md} +13 -13
  32. package/{pagination.md → docs/README_VARIOUS/pagination.md} +11 -8
  33. package/docs/assets/css/style.scss +78 -5
  34. package/docs/index.md +2 -12
  35. package/helper-reorganization-plan.md +85 -0
  36. package/helper-usage-analysis.md +94 -0
  37. package/package.json +5 -4
  38. package/plugins/core/bulk-operations-plugin.js +2 -2
  39. package/plugins/core/connectors/express-plugin.js +90 -32
  40. package/plugins/core/lib/querying/knex-cross-table-search.js +609 -0
  41. package/plugins/core/lib/querying/knex-json-api-transformers-querying.js +491 -0
  42. package/plugins/core/lib/querying/knex-pagination-helpers.js +544 -0
  43. package/plugins/core/lib/{knex-process-includes.js → querying/knex-process-includes.js} +65 -50
  44. package/plugins/core/lib/querying/knex-query-helpers-base.js +74 -0
  45. package/plugins/core/lib/{knex-query-helpers.js → querying/knex-query-helpers.js} +416 -180
  46. package/plugins/core/lib/{knex-relationship-includes.js → querying/knex-relationship-includes.js} +430 -114
  47. package/plugins/core/lib/querying/knex-window-queries.js +328 -0
  48. package/plugins/core/lib/querying-writing/compile-schemas.js +328 -0
  49. package/plugins/core/{utils → lib/querying-writing}/connectors-query-parser.js +62 -57
  50. package/plugins/core/lib/{database-capabilities.js → querying-writing/database-capabilities.js} +113 -7
  51. package/plugins/core/lib/querying-writing/database-value-normalizers.js +369 -0
  52. package/plugins/core/lib/querying-writing/default-data-helpers.js +72 -0
  53. package/plugins/core/{utils → lib/querying-writing}/field-utils.js +41 -31
  54. package/plugins/core/{utils → lib/querying-writing}/knex-constants.js +1 -0
  55. package/plugins/core/lib/{knex-field-helpers.js → querying-writing/knex-field-helpers.js} +190 -57
  56. package/plugins/core/lib/querying-writing/knex-json-api-transformers.js +162 -0
  57. package/plugins/core/lib/{payload-validators.js → querying-writing/payload-validators.js} +297 -217
  58. package/plugins/core/lib/querying-writing/schema-helpers.js +497 -0
  59. package/plugins/core/lib/querying-writing/scope-validations.js +431 -0
  60. package/plugins/core/lib/{simplified-helpers.js → querying-writing/simplified-helpers.js} +216 -176
  61. package/plugins/core/lib/writing/knex-json-api-transformers-writing.js +110 -0
  62. package/plugins/core/lib/writing/many-to-many-manipulations.js +300 -0
  63. package/plugins/core/lib/writing/relationship-processor.js +252 -0
  64. package/plugins/core/rest-api-knex-plugin.js +183 -62
  65. package/plugins/core/rest-api-plugin-hooks/compile-resource-schemas.js +7 -0
  66. package/plugins/core/rest-api-plugin-hooks/register-relationship-routes.js +72 -0
  67. package/plugins/core/rest-api-plugin-hooks/register-scope-routes.js +102 -0
  68. package/plugins/core/rest-api-plugin-hooks/turn-scope-init-into-vars.js +50 -0
  69. package/plugins/core/rest-api-plugin-hooks/validate-include-configurations.js +39 -0
  70. package/plugins/core/rest-api-plugin-methods/add-route.js +23 -0
  71. package/plugins/core/rest-api-plugin-methods/check-permissions.js +18 -0
  72. package/plugins/core/rest-api-plugin-methods/common.js +605 -0
  73. package/plugins/core/rest-api-plugin-methods/delete-relationship.js +115 -0
  74. package/plugins/core/rest-api-plugin-methods/delete.js +109 -0
  75. package/plugins/core/rest-api-plugin-methods/enrich-attributes.js +186 -0
  76. package/plugins/core/rest-api-plugin-methods/get-related.js +295 -0
  77. package/plugins/core/rest-api-plugin-methods/get-relationship.js +62 -0
  78. package/plugins/core/rest-api-plugin-methods/get.js +187 -0
  79. package/plugins/core/rest-api-plugin-methods/patch-relationship.js +56 -0
  80. package/plugins/core/rest-api-plugin-methods/patch.js +193 -0
  81. package/plugins/core/rest-api-plugin-methods/post-relationship.js +104 -0
  82. package/plugins/core/rest-api-plugin-methods/post.js +157 -0
  83. package/plugins/core/rest-api-plugin-methods/put.js +257 -0
  84. package/plugins/core/rest-api-plugin-methods/query.js +208 -0
  85. package/plugins/core/rest-api-plugin.js +108 -2498
  86. package/plugins/core/socketio-plugin.js +28 -5
  87. package/plugins/storage/local-storage.js +2 -2
  88. package/tests/computed-fields.test.js +483 -0
  89. package/tests/cors.test.js +4 -4
  90. package/tests/curl.test.js +5 -4
  91. package/tests/custom-idproperty-relationships.test.js +891 -0
  92. package/tests/field-getters.test.js +353 -0
  93. package/tests/field-setters.test.js +310 -0
  94. package/tests/fixtures/api-configs.js +800 -28
  95. package/tests/jwt-auth.test.js +0 -2
  96. package/tests/nested-includes.test.js +1 -1
  97. package/tests/pagination-cursor-multifield.test.js +514 -0
  98. package/tests/pagination-enhanced.test.js +12 -9
  99. package/tests/polymorphic-relationships.test.js +10 -8
  100. package/tests/polymorphic-simple.test.js +6 -4
  101. package/tests/positioning-advanced.test.js +12 -12
  102. package/tests/positioning-extended.test.js +25 -25
  103. package/tests/positioning-multifilter.test.js +24 -24
  104. package/tests/positioning.test.js +3 -3
  105. package/tests/query-limits.test.js +24 -8
  106. package/tests/relationship-endpoints.test.js +4 -5
  107. package/tests/relationships.test.js +0 -1
  108. package/tests/socketio.test.js +12 -1
  109. package/tests/virtual-fields.test.js +13 -13
  110. package/PLAN_FOR_WEBSOCKETS.md +0 -398
  111. package/README_1_Initial_Setup.md +0 -393
  112. package/README_X_Hooks.md +0 -647
  113. package/TODO_rest-api-plugin-extras.todo +0 -23
  114. package/connectors_ideas/express-plugin.js +0 -120
  115. package/connectors_ideas/http-plugin.js +0 -138
  116. package/docs/examples/express-plugin.js +0 -366
  117. package/example.js +0 -301
  118. package/plugins/core/HELPER_MODULES.md +0 -285
  119. package/plugins/core/lib/compile-schemas.js +0 -245
  120. package/plugins/core/lib/database-value-normalizers.js +0 -192
  121. package/plugins/core/lib/default-data-helpers.js +0 -100
  122. package/plugins/core/lib/knex-cross-table-search.js +0 -442
  123. package/plugins/core/lib/knex-json-api-helpers.js +0 -84
  124. package/plugins/core/lib/knex-json-api-transformers.js +0 -449
  125. package/plugins/core/lib/knex-pagination-helpers.js +0 -193
  126. package/plugins/core/lib/knex-window-queries.js +0 -142
  127. package/plugins/core/lib/many-to-many-manipulations.js +0 -343
  128. package/plugins/core/lib/relationship-processor.js +0 -278
  129. package/plugins/core/lib/schema-helpers.js +0 -343
  130. package/plugins/core/lib/scope-validations.js +0 -252
  131. package/plugins/core/rest-api-relationships-plugin.js +0 -700
  132. package/plugins/core/utils/knex-query-helpers-base.js +0 -56
  133. /package/{README_X_Permissions.md → docs/GUIDE/GUIDE_4_Authentication_And_Permissions.md} +0 -0
  134. /package/{README_X_Positioning.md → docs/GUIDE/GUIDE_6_Positioning.md} +0 -0
  135. /package/{README_X_Bulk_Operations.md → docs/GUIDE/GUIDE_X_Bulk_Operations.md} +0 -0
  136. /package/{README_X_Cors.md → docs/GUIDE/GUIDE_X_Cors.md} +0 -0
  137. /package/{README_X_Multihome.md → docs/GUIDE/GUIDE_X_Multihome.md} +0 -0
  138. /package/{README_X_Appendices.md → docs/GUIDE/GUIDE_Y_Appendices.md} +0 -0
  139. /package/{QUERY_DEPTH_PROTECTION.md → docs/README_VARIOUS/QUERY_DEPTH_PROTECTION.md} +0 -0
  140. /package/{RELATIONSHIPS.md → docs/README_VARIOUS/RELATIONSHIPS.md} +0 -0
  141. /package/{WEBSOCKET_IMPLEMENTATION_STATUS.md → docs/README_VARIOUS/WEBSOCKET_IMPLEMENTATION_STATUS.md} +0 -0
  142. /package/{helper-functions-chart.md → docs/README_VARIOUS/helper-functions-chart.md} +0 -0
  143. /package/docs/{implementation-hidden-computed-fields.md → README_VARIOUS/implementation-hidden-computed-fields.md} +0 -0
  144. /package/docs/{include-limits-migration-guide.md → README_VARIOUS/include-limits-migration-guide.md} +0 -0
  145. /package/{readmeSnippets → docs/README_VARIOUS}/test_put_behavior.js +0 -0
  146. /package/{readmeSnippets → docs/README_VARIOUS}/test_put_fields_without_defaults.js +0 -0
@@ -150,10 +150,10 @@ await api.addResource('posts', {
150
150
 
151
151
  searchSchema: {
152
152
  // These filters work for both REST and WebSocket
153
- status: { type: 'string', filterUsing: '=' },
154
- author_id: { type: 'id', filterUsing: '=' },
155
- published_at: { type: 'dateTime', filterUsing: '>=' },
156
- view_count: { type: 'number', filterUsing: '>' }
153
+ status: { type: 'string', filterOperator: '=' },
154
+ author_id: { type: 'id', filterOperator: '=' },
155
+ published_at: { type: 'dateTime', filterOperator: '>=' },
156
+ view_count: { type: 'number', filterOperator: '>' }
157
157
  }
158
158
  });
159
159
 
@@ -203,20 +203,20 @@ Filters using simple operators (`=`, `>`, `>=`, `<`, `<=`, `!=`, `like`, `in`, `
203
203
  ```javascript
204
204
  searchSchema: {
205
205
  // Equality
206
- status: { type: 'string', filterUsing: '=' },
206
+ status: { type: 'string', filterOperator: '=' },
207
207
 
208
208
  // Comparison
209
- price: { type: 'number', filterUsing: '>=' },
210
- stock: { type: 'number', filterUsing: '>' },
209
+ price: { type: 'number', filterOperator: '>=' },
210
+ stock: { type: 'number', filterOperator: '>' },
211
211
 
212
212
  // Pattern matching
213
- title: { type: 'string', filterUsing: 'like' },
213
+ title: { type: 'string', filterOperator: 'like' },
214
214
 
215
215
  // Multiple values
216
- category_id: { type: 'array', filterUsing: 'in' },
216
+ category_id: { type: 'array', filterOperator: 'in' },
217
217
 
218
218
  // Range
219
- created_at: { type: 'date', filterUsing: 'between' }
219
+ created_at: { type: 'date', filterOperator: 'between' }
220
220
  }
221
221
 
222
222
  // These work for both REST and WebSocket
@@ -234,7 +234,7 @@ socket.emit('subscribe', {
234
234
 
235
235
  ### Complex Filters with filterRecord
236
236
 
237
- When `filterUsing` is a function (for complex SQL queries), you must provide `filterRecord` for WebSocket support:
237
+ When `filterOperator` is a function (for complex SQL queries), you must provide `filterRecord` for WebSocket support:
238
238
 
239
239
  ```javascript
240
240
  searchSchema: {
@@ -243,7 +243,7 @@ searchSchema: {
243
243
  type: 'string',
244
244
 
245
245
  // For REST API - builds SQL query
246
- filterUsing: function(query, value, { tableName }) {
246
+ filterOperator: function(query, value, { tableName }) {
247
247
  query.where(function() {
248
248
  this.where(`${tableName}.title`, 'like', `%${value}%`)
249
249
  .orWhere(`${tableName}.description`, 'like', `%${value}%`)
@@ -269,7 +269,7 @@ searchSchema: {
269
269
  type: 'object',
270
270
 
271
271
  // REST: Haversine formula in SQL
272
- filterUsing: function(query, value, { tableName }) {
272
+ filterOperator: function(query, value, { tableName }) {
273
273
  const { lat, lng, radius = 10 } = value;
274
274
  query.whereRaw(`
275
275
  (6371 * acos(
@@ -296,7 +296,7 @@ searchSchema: {
296
296
  type: 'object',
297
297
 
298
298
  // REST: Complex JOIN with user permissions
299
- filterUsing: function(query, value, { tableName }) {
299
+ filterOperator: function(query, value, { tableName }) {
300
300
  const { user_id, include_private } = value;
301
301
  query.where(`${tableName}.owner_id`, user_id);
302
302
  if (!include_private) {
@@ -937,14 +937,14 @@ Check:
937
937
 
938
938
  **2. "UNSUPPORTED_FILTER" errors**
939
939
 
940
- If using custom filterUsing functions, you must provide filterRecord:
940
+ If using custom filterOperator functions, you must provide filterRecord:
941
941
 
942
942
  ```javascript
943
943
  // ❌ This will error for WebSocket
944
944
  searchSchema: {
945
945
  complex_search: {
946
946
  type: 'string',
947
- filterUsing: function(query, value) { /* SQL */ }
947
+ filterOperator: function(query, value) { /* SQL */ }
948
948
  }
949
949
  }
950
950
 
@@ -952,7 +952,7 @@ searchSchema: {
952
952
  searchSchema: {
953
953
  complex_search: {
954
954
  type: 'string',
955
- filterUsing: function(query, value) { /* SQL */ },
955
+ filterOperator: function(query, value) { /* SQL */ },
956
956
  filterRecord: function(record, value) { /* JavaScript */ }
957
957
  }
958
958
  }
@@ -0,0 +1,58 @@
1
+ # JSON REST API Complete Guide
2
+
3
+ Welcome to the comprehensive guide for JSON REST API. This guide will walk you through everything from initial setup to advanced features.
4
+
5
+ ## Table of Contents
6
+
7
+ ### Core Chapters
8
+
9
+ 1. **[Initial Setup](GUIDE_1_Initial_Setup.md)**
10
+ Get started with JSON REST API, create your first API instance, and understand the basic concepts.
11
+
12
+ 2. **[Data and Relations](GUIDE_2_Data_And_Relations.md)**
13
+ Learn how to define resources, set up relationships, and work with your data model.
14
+
15
+ 3. **[Field Transformations](GUIDE_3_Field_Transformations.md)**
16
+ Transform data with virtual fields, getters, setters, computed fields, and visibility control.
17
+
18
+ 4. **[Authentication and Permissions](GUIDE_4_Authentication_And_Permissions.md)**
19
+ Implement security with authentication strategies and fine-grained permissions.
20
+
21
+ 5. **[Non-Database Stores](GUIDE_5_Non-Db_Stores.md)**
22
+ Connect your API to alternative data sources beyond traditional databases.
23
+
24
+ 6. **[Positioning](GUIDE_6_Positioning.md)**
25
+ Implement drag-and-drop functionality with automatic position management.
26
+
27
+ 7. **[Hooks, Data Management, and Plugins](GUIDE_7_Hooks_Data_Management_And_Plugins.md)**
28
+ Master the hook system for data validation, transformation, and business logic.
29
+
30
+
31
+ ### Additional Topics
32
+
33
+ - **[Bulk Operations](GUIDE_X_Bulk_Operations.md)**
34
+ Handle multiple records efficiently with bulk create, update, and delete operations.
35
+
36
+ - **[CORS Configuration](GUIDE_X_Cors.md)**
37
+ Set up Cross-Origin Resource Sharing for browser-based applications.
38
+
39
+ - **[Multihome Support](GUIDE_X_Multihome.md)**
40
+ Run multiple API instances or serve different domains from a single server.
41
+
42
+ - **[Socket.IO Integration](GUIDE_X_SocketIO.md)**
43
+ Add real-time capabilities to your API with WebSocket support.
44
+
45
+ - **[Appendices](GUIDE_Y_Appendices.md)**
46
+ Reference material, troubleshooting, and additional resources.
47
+
48
+ ## Prerequisites
49
+
50
+ Before starting this guide, you should have:
51
+
52
+ - Node.js 20+ installed
53
+ - Basic knowledge of JavaScript and REST APIs
54
+ - Familiarity with npm/yarn package management
55
+
56
+ ---
57
+
58
+ Ready to get started? Head to [Chapter 1: Initial Setup](GUIDE_1_Initial_Setup.md) →