s3db.js 11.3.2 → 12.0.1

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 (83) hide show
  1. package/README.md +102 -8
  2. package/dist/s3db.cjs.js +36945 -15510
  3. package/dist/s3db.cjs.js.map +1 -1
  4. package/dist/s3db.d.ts +66 -1
  5. package/dist/s3db.es.js +36914 -15534
  6. package/dist/s3db.es.js.map +1 -1
  7. package/mcp/entrypoint.js +58 -0
  8. package/mcp/tools/documentation.js +434 -0
  9. package/mcp/tools/index.js +4 -0
  10. package/package.json +35 -15
  11. package/src/behaviors/user-managed.js +13 -6
  12. package/src/client.class.js +79 -49
  13. package/src/concerns/base62.js +85 -0
  14. package/src/concerns/dictionary-encoding.js +294 -0
  15. package/src/concerns/geo-encoding.js +256 -0
  16. package/src/concerns/high-performance-inserter.js +34 -30
  17. package/src/concerns/ip.js +325 -0
  18. package/src/concerns/metadata-encoding.js +345 -66
  19. package/src/concerns/money.js +193 -0
  20. package/src/concerns/partition-queue.js +7 -4
  21. package/src/concerns/plugin-storage.js +97 -47
  22. package/src/database.class.js +76 -74
  23. package/src/errors.js +0 -4
  24. package/src/plugins/api/auth/api-key-auth.js +88 -0
  25. package/src/plugins/api/auth/basic-auth.js +154 -0
  26. package/src/plugins/api/auth/index.js +112 -0
  27. package/src/plugins/api/auth/jwt-auth.js +169 -0
  28. package/src/plugins/api/index.js +544 -0
  29. package/src/plugins/api/middlewares/index.js +15 -0
  30. package/src/plugins/api/middlewares/validator.js +185 -0
  31. package/src/plugins/api/routes/auth-routes.js +241 -0
  32. package/src/plugins/api/routes/resource-routes.js +304 -0
  33. package/src/plugins/api/server.js +354 -0
  34. package/src/plugins/api/utils/error-handler.js +147 -0
  35. package/src/plugins/api/utils/openapi-generator.js +1240 -0
  36. package/src/plugins/api/utils/response-formatter.js +218 -0
  37. package/src/plugins/backup/streaming-exporter.js +132 -0
  38. package/src/plugins/backup.plugin.js +103 -50
  39. package/src/plugins/cache/s3-cache.class.js +95 -47
  40. package/src/plugins/cache.plugin.js +107 -9
  41. package/src/plugins/concerns/plugin-dependencies.js +313 -0
  42. package/src/plugins/concerns/prometheus-formatter.js +255 -0
  43. package/src/plugins/consumers/rabbitmq-consumer.js +4 -0
  44. package/src/plugins/consumers/sqs-consumer.js +4 -0
  45. package/src/plugins/costs.plugin.js +255 -39
  46. package/src/plugins/eventual-consistency/helpers.js +15 -1
  47. package/src/plugins/geo.plugin.js +873 -0
  48. package/src/plugins/importer/index.js +1020 -0
  49. package/src/plugins/index.js +11 -0
  50. package/src/plugins/metrics.plugin.js +163 -4
  51. package/src/plugins/queue-consumer.plugin.js +6 -27
  52. package/src/plugins/relation.errors.js +139 -0
  53. package/src/plugins/relation.plugin.js +1242 -0
  54. package/src/plugins/replicator.plugin.js +2 -1
  55. package/src/plugins/replicators/bigquery-replicator.class.js +180 -8
  56. package/src/plugins/replicators/dynamodb-replicator.class.js +383 -0
  57. package/src/plugins/replicators/index.js +28 -3
  58. package/src/plugins/replicators/mongodb-replicator.class.js +391 -0
  59. package/src/plugins/replicators/mysql-replicator.class.js +558 -0
  60. package/src/plugins/replicators/planetscale-replicator.class.js +409 -0
  61. package/src/plugins/replicators/postgres-replicator.class.js +182 -7
  62. package/src/plugins/replicators/s3db-replicator.class.js +1 -12
  63. package/src/plugins/replicators/schema-sync.helper.js +601 -0
  64. package/src/plugins/replicators/sqs-replicator.class.js +11 -9
  65. package/src/plugins/replicators/turso-replicator.class.js +416 -0
  66. package/src/plugins/replicators/webhook-replicator.class.js +612 -0
  67. package/src/plugins/state-machine.plugin.js +122 -68
  68. package/src/plugins/tfstate/README.md +745 -0
  69. package/src/plugins/tfstate/base-driver.js +80 -0
  70. package/src/plugins/tfstate/errors.js +112 -0
  71. package/src/plugins/tfstate/filesystem-driver.js +129 -0
  72. package/src/plugins/tfstate/index.js +2660 -0
  73. package/src/plugins/tfstate/s3-driver.js +192 -0
  74. package/src/plugins/ttl.plugin.js +536 -0
  75. package/src/resource.class.js +315 -36
  76. package/src/s3db.d.ts +66 -1
  77. package/src/schema.class.js +366 -32
  78. package/SECURITY.md +0 -76
  79. package/src/partition-drivers/base-partition-driver.js +0 -106
  80. package/src/partition-drivers/index.js +0 -66
  81. package/src/partition-drivers/memory-partition-driver.js +0 -289
  82. package/src/partition-drivers/sqs-partition-driver.js +0 -337
  83. package/src/partition-drivers/sync-partition-driver.js +0 -38
package/dist/s3db.d.ts CHANGED
@@ -319,6 +319,20 @@ declare module 's3db.js' {
319
319
  maxResults?: number;
320
320
  }
321
321
 
322
+ /** Geo Plugin resource config */
323
+ export interface GeoResourceConfig {
324
+ latField: string;
325
+ lonField: string;
326
+ precision?: number;
327
+ addGeohash?: boolean;
328
+ }
329
+
330
+ /** Geo Plugin config */
331
+ export interface GeoPluginConfig extends PluginConfig {
332
+ resources?: Record<string, GeoResourceConfig>;
333
+ verbose?: boolean;
334
+ }
335
+
322
336
  /** Metrics Plugin config */
323
337
  export interface MetricsPluginConfig extends PluginConfig {
324
338
  trackLatency?: boolean;
@@ -709,6 +723,8 @@ declare module 's3db.js' {
709
723
  get(id: string): Promise<any>;
710
724
  exists(id: string): Promise<boolean>;
711
725
  update(id: string, attributes: any): Promise<any>;
726
+ patch(id: string, fields: any, options?: { partition?: string; partitionValues?: Record<string, any> }): Promise<any>;
727
+ replace(id: string, fullData: any, options?: { partition?: string; partitionValues?: Record<string, any> }): Promise<any>;
712
728
  upsert(data: any): Promise<any>;
713
729
  delete(id: string): Promise<void>;
714
730
  deleteMany(ids: string[]): Promise<void>;
@@ -827,7 +843,13 @@ declare module 's3db.js' {
827
843
  }): Promise<any>;
828
844
  getObject(key: string): Promise<any>;
829
845
  headObject(key: string): Promise<any>;
830
- copyObject(options: { from: string; to: string }): Promise<any>;
846
+ copyObject(options: {
847
+ from: string;
848
+ to: string;
849
+ metadata?: Record<string, any>;
850
+ metadataDirective?: 'COPY' | 'REPLACE';
851
+ contentType?: string;
852
+ }): Promise<any>;
831
853
  exists(key: string): Promise<boolean>;
832
854
  deleteObject(key: string): Promise<any>;
833
855
  deleteObjects(keys: string[]): Promise<{ deleted: any[]; notFound: any[] }>;
@@ -1016,6 +1038,16 @@ declare module 's3db.js' {
1016
1038
  getIndexStats(): any;
1017
1039
  }
1018
1040
 
1041
+ /** Geo Plugin */
1042
+ export class GeoPlugin extends Plugin {
1043
+ constructor(config?: GeoPluginConfig);
1044
+ encodeGeohash(latitude: number, longitude: number, precision?: number): string;
1045
+ decodeGeohash(geohash: string): { latitude: number; longitude: number; error: { latitude: number; longitude: number } };
1046
+ calculateDistance(lat1: number, lon1: number, lat2: number, lon2: number): number;
1047
+ getNeighbors(geohash: string): string[];
1048
+ getStats(): any;
1049
+ }
1050
+
1019
1051
  /** Metrics Plugin */
1020
1052
  export class MetricsPlugin extends Plugin {
1021
1053
  constructor(config?: MetricsPluginConfig);
@@ -1254,6 +1286,33 @@ declare module 's3db.js' {
1254
1286
  }
1255
1287
 
1256
1288
  /** Resource extensions added by EventualConsistencyPlugin */
1289
+ export interface GeoResourceExtensions {
1290
+ /** Find locations within radius of a point */
1291
+ findNearby(options: {
1292
+ lat: number;
1293
+ lon: number;
1294
+ radius?: number;
1295
+ limit?: number;
1296
+ }): Promise<Array<any & { _distance: number }>>;
1297
+
1298
+ /** Find locations within bounding box */
1299
+ findInBounds(options: {
1300
+ north: number;
1301
+ south: number;
1302
+ east: number;
1303
+ west: number;
1304
+ limit?: number;
1305
+ }): Promise<any[]>;
1306
+
1307
+ /** Get distance between two records */
1308
+ getDistance(id1: string, id2: string): Promise<{
1309
+ distance: number;
1310
+ unit: string;
1311
+ from: string;
1312
+ to: string;
1313
+ }>;
1314
+ }
1315
+
1257
1316
  export interface EventualConsistencyResourceExtensions {
1258
1317
  /** Set field value (replaces current value) */
1259
1318
  set(id: string, field: string, value: number): Promise<number>;
@@ -1264,6 +1323,12 @@ declare module 's3db.js' {
1264
1323
  /** Decrement field value */
1265
1324
  sub(id: string, field: string, amount: number): Promise<number>;
1266
1325
 
1326
+ /** Increment field value by 1 (shorthand for add(id, field, 1)) */
1327
+ increment(id: string, field: string): Promise<number>;
1328
+
1329
+ /** Decrement field value by 1 (shorthand for sub(id, field, 1)) */
1330
+ decrement(id: string, field: string): Promise<number>;
1331
+
1267
1332
  /** Manually trigger consolidation */
1268
1333
  consolidate(id: string, field: string): Promise<number>;
1269
1334