s3db.js 9.1.0 → 9.2.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.
- package/PLUGINS.md +871 -13
- package/README.md +31 -2
- package/dist/s3db.cjs.js +3867 -1615
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.es.js +3870 -1621
- package/dist/s3db.es.js.map +1 -1
- package/package.json +5 -5
- package/src/concerns/async-event-emitter.js +46 -0
- package/src/database.class.js +23 -0
- package/src/plugins/backup/base-backup-driver.class.js +119 -0
- package/src/plugins/backup/filesystem-backup-driver.class.js +254 -0
- package/src/plugins/backup/index.js +85 -0
- package/src/plugins/backup/multi-backup-driver.class.js +304 -0
- package/src/plugins/backup/s3-backup-driver.class.js +313 -0
- package/src/plugins/backup.plugin.js +664 -0
- package/src/plugins/backup.plugin.js.backup +1026 -0
- package/src/plugins/cache/memory-cache.class.js +112 -3
- package/src/plugins/index.js +3 -0
- package/src/plugins/scheduler.plugin.js +833 -0
- package/src/plugins/state-machine.plugin.js +543 -0
- package/src/resource.class.js +9 -6
package/README.md
CHANGED
|
@@ -1615,7 +1615,35 @@ await users.insert({ name: 'john', email: 'john@example.com' });
|
|
|
1615
1615
|
|
|
1616
1616
|
### 🎧 Event Listeners Configuration
|
|
1617
1617
|
|
|
1618
|
-
s3db.js resources extend Node.js EventEmitter, providing a powerful event system for real-time monitoring and notifications.
|
|
1618
|
+
s3db.js resources extend Node.js EventEmitter, providing a powerful event system for real-time monitoring and notifications. **By default, events are emitted asynchronously** for better performance, but you can configure synchronous events when needed.
|
|
1619
|
+
|
|
1620
|
+
#### **Async vs Sync Events**
|
|
1621
|
+
|
|
1622
|
+
```javascript
|
|
1623
|
+
// Async events (default) - Non-blocking, better performance
|
|
1624
|
+
const asyncResource = await s3db.createResource({
|
|
1625
|
+
name: "users",
|
|
1626
|
+
attributes: { name: "string", email: "string" },
|
|
1627
|
+
asyncEvents: true // Optional, this is the default
|
|
1628
|
+
});
|
|
1629
|
+
|
|
1630
|
+
// Sync events - Blocking, useful for testing or critical operations
|
|
1631
|
+
const syncResource = await s3db.createResource({
|
|
1632
|
+
name: "critical_ops",
|
|
1633
|
+
attributes: { name: "string", value: "number" },
|
|
1634
|
+
asyncEvents: false // Events will block until listeners complete
|
|
1635
|
+
});
|
|
1636
|
+
|
|
1637
|
+
// Runtime mode change
|
|
1638
|
+
asyncResource.setAsyncMode(false); // Switch to sync mode
|
|
1639
|
+
syncResource.setAsyncMode(true); // Switch to async mode
|
|
1640
|
+
```
|
|
1641
|
+
|
|
1642
|
+
**When to use each mode:**
|
|
1643
|
+
- **Async (default)**: Best for production, logging, analytics, non-critical operations
|
|
1644
|
+
- **Sync**: Testing, critical validations, operations that must complete before continuing
|
|
1645
|
+
|
|
1646
|
+
You can configure event listeners in **two ways**: programmatically using `.on()` or declaratively in the resource configuration.
|
|
1619
1647
|
|
|
1620
1648
|
#### **Programmatic Event Listeners**
|
|
1621
1649
|
Traditional EventEmitter pattern using `.on()`, `.once()`, or `.off()`:
|
|
@@ -1771,7 +1799,8 @@ await users.insert({ name: 'John' });
|
|
|
1771
1799
|
- **Declarative for core functionality**: Use the `events` config for essential listeners
|
|
1772
1800
|
- **Programmatic for conditional/dynamic**: Use `.on()` for listeners that might change at runtime
|
|
1773
1801
|
- **Error handling**: Listeners should handle their own errors to avoid breaking operations
|
|
1774
|
-
- **Performance**: Keep listeners lightweight;
|
|
1802
|
+
- **Performance**: Keep listeners lightweight; async events (default) ensure non-blocking operations
|
|
1803
|
+
- **Testing**: Use `asyncEvents: false` in tests when you need predictable synchronous behavior
|
|
1775
1804
|
- **Debugging**: Event listeners are excellent for debugging and monitoring
|
|
1776
1805
|
- Middlewares are powerful and ideal for controlling or transforming operations.
|
|
1777
1806
|
- You can safely combine both for maximum flexibility.
|