s3db.js 8.0.1 → 8.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s3db.js",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "description": "Use AWS S3, the world's most reliable document storage, as a database with this ORM.",
5
5
  "main": "dist/s3db.cjs.js",
6
6
  "module": "dist/s3db.es.js",
@@ -91,8 +91,8 @@ export class MemoryCache extends Cache {
91
91
  super(config);
92
92
  this.cache = {};
93
93
  this.meta = {};
94
- this.maxSize = config.maxSize || 0;
95
- this.ttl = config.ttl || 0;
94
+ this.maxSize = config.maxSize !== undefined ? config.maxSize : 1000;
95
+ this.ttl = config.ttl !== undefined ? config.ttl : 300000;
96
96
  }
97
97
 
98
98
  async _set(key, data) {
@@ -11,14 +11,26 @@ import tryFn from "../concerns/try-fn.js";
11
11
  export class CachePlugin extends Plugin {
12
12
  constructor(options = {}) {
13
13
  super(options);
14
- this.driver = options.driver;
15
- this.config = {
16
- includePartitions: options.includePartitions !== false,
17
- partitionStrategy: options.partitionStrategy || 'hierarchical',
18
- partitionAware: options.partitionAware !== false,
19
- trackUsage: options.trackUsage !== false,
20
- preloadRelated: options.preloadRelated !== false,
21
- ...options
14
+
15
+ // Extract primary configuration
16
+ this.driverName = options.driver || 's3';
17
+ this.ttl = options.ttl;
18
+ this.maxSize = options.maxSize;
19
+ this.config = options.config || {};
20
+
21
+ // Plugin-level settings
22
+ this.includePartitions = options.includePartitions !== false;
23
+ this.partitionStrategy = options.partitionStrategy || 'hierarchical';
24
+ this.partitionAware = options.partitionAware !== false;
25
+ this.trackUsage = options.trackUsage !== false;
26
+ this.preloadRelated = options.preloadRelated !== false;
27
+
28
+ // Legacy support - keep the old options for backward compatibility
29
+ this.legacyConfig = {
30
+ memoryOptions: options.memoryOptions,
31
+ filesystemOptions: options.filesystemOptions,
32
+ s3Options: options.s3Options,
33
+ driver: options.driver
22
34
  };
23
35
  }
24
36
 
@@ -28,26 +40,68 @@ export class CachePlugin extends Plugin {
28
40
 
29
41
  async onSetup() {
30
42
  // Initialize cache driver
31
- if (this.config.driver && typeof this.config.driver === 'object') {
43
+ if (this.driverName && typeof this.driverName === 'object') {
32
44
  // Use custom driver instance if provided
33
- this.driver = this.config.driver;
34
- } else if (this.config.driver === 'memory') {
35
- this.driver = new MemoryCache(this.config.memoryOptions || {});
36
- } else if (this.config.driver === 'filesystem') {
45
+ this.driver = this.driverName;
46
+ } else if (this.driverName === 'memory') {
47
+ // Build driver configuration with proper precedence
48
+ const driverConfig = {
49
+ ...this.legacyConfig.memoryOptions, // Legacy support (lowest priority)
50
+ ...this.config, // New config format (medium priority)
51
+ };
52
+
53
+ // Add global settings if defined (highest priority)
54
+ if (this.ttl !== undefined) {
55
+ driverConfig.ttl = this.ttl;
56
+ }
57
+ if (this.maxSize !== undefined) {
58
+ driverConfig.maxSize = this.maxSize;
59
+ }
60
+
61
+ this.driver = new MemoryCache(driverConfig);
62
+ } else if (this.driverName === 'filesystem') {
63
+ // Build driver configuration with proper precedence
64
+ const driverConfig = {
65
+ ...this.legacyConfig.filesystemOptions, // Legacy support (lowest priority)
66
+ ...this.config, // New config format (medium priority)
67
+ };
68
+
69
+ // Add global settings if defined (highest priority)
70
+ if (this.ttl !== undefined) {
71
+ driverConfig.ttl = this.ttl;
72
+ }
73
+ if (this.maxSize !== undefined) {
74
+ driverConfig.maxSize = this.maxSize;
75
+ }
76
+
37
77
  // Use partition-aware filesystem cache if enabled
38
- if (this.config.partitionAware) {
78
+ if (this.partitionAware) {
39
79
  this.driver = new PartitionAwareFilesystemCache({
40
- partitionStrategy: this.config.partitionStrategy,
41
- trackUsage: this.config.trackUsage,
42
- preloadRelated: this.config.preloadRelated,
43
- ...this.config.filesystemOptions
80
+ partitionStrategy: this.partitionStrategy,
81
+ trackUsage: this.trackUsage,
82
+ preloadRelated: this.preloadRelated,
83
+ ...driverConfig
44
84
  });
45
85
  } else {
46
- this.driver = new FilesystemCache(this.config.filesystemOptions || {});
86
+ this.driver = new FilesystemCache(driverConfig);
47
87
  }
48
88
  } else {
49
- // Default to S3Cache, sempre passa o client do database
50
- this.driver = new S3Cache({ client: this.database.client, ...(this.config.s3Options || {}) });
89
+ // Default to S3Cache - build driver configuration with proper precedence
90
+ const driverConfig = {
91
+ client: this.database.client, // Required for S3Cache
92
+ ...this.legacyConfig.s3Options, // Legacy support (lowest priority)
93
+ ...this.config, // New config format (medium priority)
94
+ };
95
+
96
+ // Add global settings if defined (highest priority)
97
+ if (this.ttl !== undefined) {
98
+ driverConfig.ttl = this.ttl;
99
+ }
100
+ if (this.maxSize !== undefined) {
101
+ driverConfig.maxSize = this.maxSize;
102
+ }
103
+
104
+ this.driver = new S3Cache(driverConfig);
51
105
  }
52
106
 
53
107
  // Use database hooks instead of method overwriting