s3db.js 7.2.0 → 7.3.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 +200 -10
- package/dist/s3db.cjs.js +149 -1458
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.d.ts +14 -15
- package/dist/s3db.es.js +150 -1459
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +149 -1458
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +19 -8
- package/src/behaviors/body-only.js +2 -2
- package/src/behaviors/truncate-data.js +2 -2
- package/src/client.class.js +1 -1
- package/src/database.class.js +1 -1
- package/src/errors.js +1 -1
- package/src/plugins/audit.plugin.js +5 -5
- package/src/plugins/cache/filesystem-cache.class.js +661 -0
- package/src/plugins/cache/index.js +4 -0
- package/src/plugins/cache/partition-aware-filesystem-cache.class.js +480 -0
- package/src/plugins/cache.plugin.js +159 -9
- package/src/plugins/consumers/index.js +3 -3
- package/src/plugins/consumers/sqs-consumer.js +2 -2
- package/src/plugins/fulltext.plugin.js +5 -5
- package/src/plugins/metrics.plugin.js +2 -2
- package/src/plugins/queue-consumer.plugin.js +3 -3
- package/src/plugins/replicator.plugin.js +259 -362
- package/src/plugins/replicators/bigquery-replicator.class.js +102 -68
- package/src/plugins/replicators/postgres-replicator.class.js +19 -109
- package/src/plugins/replicators/s3db-replicator.class.js +56 -68
- package/src/plugins/replicators/sqs-replicator.class.js +34 -121
- package/src/resource.class.js +14 -14
- package/src/s3db.d.ts +14 -15
- package/src/schema.class.js +3 -3
package/PLUGINS.md
CHANGED
|
@@ -1608,18 +1608,147 @@ await users.insert({ name: 'John', email: 'john@example.com' });
|
|
|
1608
1608
|
|
|
1609
1609
|
#### S3DB Replicator
|
|
1610
1610
|
|
|
1611
|
-
Replicate to another S3DB instance:
|
|
1611
|
+
Replicate to another S3DB instance with flexible resource mapping and transformation capabilities:
|
|
1612
1612
|
|
|
1613
1613
|
```javascript
|
|
1614
1614
|
{
|
|
1615
1615
|
driver: 's3db',
|
|
1616
|
-
resources: ['users', 'products'],
|
|
1617
1616
|
config: {
|
|
1618
1617
|
connectionString: "s3://BACKUP_KEY:BACKUP_SECRET@BACKUP_BUCKET/backup"
|
|
1618
|
+
},
|
|
1619
|
+
resources: {
|
|
1620
|
+
// Simple resource mapping (replicate to same name)
|
|
1621
|
+
users: 'users',
|
|
1622
|
+
|
|
1623
|
+
// Map source → destination resource name
|
|
1624
|
+
products: 'backup_products',
|
|
1625
|
+
|
|
1626
|
+
// Advanced mapping with transformer
|
|
1627
|
+
orders: {
|
|
1628
|
+
resource: 'order_backup',
|
|
1629
|
+
transformer: (data) => ({
|
|
1630
|
+
...data,
|
|
1631
|
+
backup_timestamp: new Date().toISOString(),
|
|
1632
|
+
original_source: 'production'
|
|
1633
|
+
})
|
|
1634
|
+
},
|
|
1635
|
+
|
|
1636
|
+
// Multi-destination replication
|
|
1637
|
+
analytics: [
|
|
1638
|
+
'analytics_backup',
|
|
1639
|
+
{
|
|
1640
|
+
resource: 'analytics_processed',
|
|
1641
|
+
transformer: (data) => ({
|
|
1642
|
+
...data,
|
|
1643
|
+
processed_date: data.createdAt?.split('T')[0],
|
|
1644
|
+
data_source: 'analytics'
|
|
1645
|
+
})
|
|
1646
|
+
}
|
|
1647
|
+
]
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
```
|
|
1651
|
+
|
|
1652
|
+
**Resource Configuration Syntaxes:**
|
|
1653
|
+
|
|
1654
|
+
The S3DB replicator supports highly flexible resource mapping configurations:
|
|
1655
|
+
|
|
1656
|
+
**1. Array of resource names** (replicate to same name):
|
|
1657
|
+
```javascript
|
|
1658
|
+
resources: ['users', 'products', 'orders']
|
|
1659
|
+
// Replicates each resource to itself in the destination database
|
|
1660
|
+
```
|
|
1661
|
+
|
|
1662
|
+
**2. Object mapping** (source → destination):
|
|
1663
|
+
```javascript
|
|
1664
|
+
resources: {
|
|
1665
|
+
users: 'people', // users → people
|
|
1666
|
+
products: 'items', // products → items
|
|
1667
|
+
orders: 'order_history' // orders → order_history
|
|
1668
|
+
}
|
|
1669
|
+
```
|
|
1670
|
+
|
|
1671
|
+
**3. Array with transformer** (resource + transformation):
|
|
1672
|
+
```javascript
|
|
1673
|
+
resources: {
|
|
1674
|
+
users: ['people', (data) => ({ ...data, fullName: `${data.firstName} ${data.lastName}` })]
|
|
1675
|
+
// Replicates 'users' to 'people' with transformation
|
|
1676
|
+
}
|
|
1677
|
+
```
|
|
1678
|
+
|
|
1679
|
+
**4. Object with resource and transformer**:
|
|
1680
|
+
```javascript
|
|
1681
|
+
resources: {
|
|
1682
|
+
users: {
|
|
1683
|
+
resource: 'people',
|
|
1684
|
+
transformer: (data) => ({
|
|
1685
|
+
...data,
|
|
1686
|
+
fullName: `${data.firstName} ${data.lastName}`,
|
|
1687
|
+
migrated_at: new Date().toISOString()
|
|
1688
|
+
})
|
|
1619
1689
|
}
|
|
1620
1690
|
}
|
|
1621
1691
|
```
|
|
1622
1692
|
|
|
1693
|
+
**5. Multi-destination arrays**:
|
|
1694
|
+
```javascript
|
|
1695
|
+
resources: {
|
|
1696
|
+
users: [
|
|
1697
|
+
'people', // Simple copy
|
|
1698
|
+
{
|
|
1699
|
+
resource: 'user_analytics',
|
|
1700
|
+
transformer: (data) => ({
|
|
1701
|
+
id: data.id,
|
|
1702
|
+
signup_date: data.createdAt,
|
|
1703
|
+
user_type: data.role || 'standard'
|
|
1704
|
+
})
|
|
1705
|
+
}
|
|
1706
|
+
]
|
|
1707
|
+
}
|
|
1708
|
+
```
|
|
1709
|
+
|
|
1710
|
+
**6. Function-only transformation** (transform to same resource):
|
|
1711
|
+
```javascript
|
|
1712
|
+
resources: {
|
|
1713
|
+
users: (data) => ({
|
|
1714
|
+
...data,
|
|
1715
|
+
processed: true,
|
|
1716
|
+
backup_date: new Date().toISOString()
|
|
1717
|
+
})
|
|
1718
|
+
}
|
|
1719
|
+
```
|
|
1720
|
+
|
|
1721
|
+
**Mixed Configuration Example:**
|
|
1722
|
+
```javascript
|
|
1723
|
+
resources: {
|
|
1724
|
+
users: [
|
|
1725
|
+
'people', // Simple copy
|
|
1726
|
+
{
|
|
1727
|
+
resource: 'user_profiles',
|
|
1728
|
+
transformer: (data) => ({
|
|
1729
|
+
...data,
|
|
1730
|
+
profile_complete: !!(data.name && data.email)
|
|
1731
|
+
})
|
|
1732
|
+
}
|
|
1733
|
+
],
|
|
1734
|
+
orders: 'order_backup', // Rename only
|
|
1735
|
+
products: { resource: 'product_catalog' }, // Object form
|
|
1736
|
+
analytics: (data) => ({ ...data, processed: true }) // Transform only
|
|
1737
|
+
}
|
|
1738
|
+
```
|
|
1739
|
+
|
|
1740
|
+
**Configuration Options:**
|
|
1741
|
+
- `connectionString`: S3DB connection string for destination database (required)
|
|
1742
|
+
- `client`: Pre-configured S3DB client instance (alternative to connectionString)
|
|
1743
|
+
- `resources`: Resource mapping configuration (see syntaxes above)
|
|
1744
|
+
|
|
1745
|
+
**Transformer Features:**
|
|
1746
|
+
- **Data Transformation**: Apply custom logic before replication
|
|
1747
|
+
- **Field Mapping**: Rename, combine, or derive new fields
|
|
1748
|
+
- **Data Enrichment**: Add metadata, timestamps, or computed values
|
|
1749
|
+
- **Conditional Logic**: Apply transformations based on data content
|
|
1750
|
+
- **Multi-destination**: Send different transformed versions to multiple targets
|
|
1751
|
+
|
|
1623
1752
|
#### SQS Replicator
|
|
1624
1753
|
|
|
1625
1754
|
Send changes to AWS SQS queues:
|
|
@@ -1639,23 +1768,84 @@ Send changes to AWS SQS queues:
|
|
|
1639
1768
|
|
|
1640
1769
|
#### BigQuery Replicator
|
|
1641
1770
|
|
|
1642
|
-
Replicate to Google BigQuery:
|
|
1771
|
+
Replicate to Google BigQuery with advanced data transformation capabilities:
|
|
1643
1772
|
|
|
1644
1773
|
```javascript
|
|
1645
1774
|
{
|
|
1646
1775
|
driver: 'bigquery',
|
|
1647
|
-
resources: {
|
|
1648
|
-
users: [{ actions: ['insert', 'update'], table: 'users_table' }],
|
|
1649
|
-
orders: 'orders_table'
|
|
1650
|
-
},
|
|
1651
1776
|
config: {
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1777
|
+
location: 'US',
|
|
1778
|
+
projectId: 'my-gcp-project',
|
|
1779
|
+
datasetId: 'analytics',
|
|
1780
|
+
credentials: JSON.parse(Buffer.from(GOOGLE_CREDENTIALS, 'base64').toString()),
|
|
1781
|
+
logTable: 'replication_log' // Optional: table for operation logging
|
|
1782
|
+
},
|
|
1783
|
+
resources: {
|
|
1784
|
+
// Simple table mapping
|
|
1785
|
+
clicks: 'mrt-shortner__clicks',
|
|
1786
|
+
fingerprints: 'mrt-shortner__fingerprints',
|
|
1787
|
+
scans: 'mrt-shortner__scans',
|
|
1788
|
+
sessions: 'mrt-shortner__sessions',
|
|
1789
|
+
shares: 'mrt-shortner__shares',
|
|
1790
|
+
urls: 'mrt-shortner__urls',
|
|
1791
|
+
views: 'mrt-shortner__views',
|
|
1792
|
+
|
|
1793
|
+
// Advanced configuration with transform functions
|
|
1794
|
+
users: {
|
|
1795
|
+
table: 'mrt-shortner__users',
|
|
1796
|
+
actions: ['insert', 'update'],
|
|
1797
|
+
transform: (data) => {
|
|
1798
|
+
return {
|
|
1799
|
+
...data,
|
|
1800
|
+
ip: data.ip || 'unknown',
|
|
1801
|
+
userIp: data.userIp || 'unknown',
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
},
|
|
1805
|
+
|
|
1806
|
+
// Multiple destinations for a single resource
|
|
1807
|
+
orders: [
|
|
1808
|
+
{ actions: ['insert'], table: 'fact_orders' },
|
|
1809
|
+
{
|
|
1810
|
+
actions: ['insert'],
|
|
1811
|
+
table: 'daily_revenue',
|
|
1812
|
+
transform: (data) => ({
|
|
1813
|
+
date: data.createdAt?.split('T')[0],
|
|
1814
|
+
revenue: data.amount,
|
|
1815
|
+
customer_id: data.userId,
|
|
1816
|
+
order_count: 1
|
|
1817
|
+
})
|
|
1818
|
+
}
|
|
1819
|
+
]
|
|
1655
1820
|
}
|
|
1656
1821
|
}
|
|
1657
1822
|
```
|
|
1658
1823
|
|
|
1824
|
+
**Transform Function Features:**
|
|
1825
|
+
- **Data Transformation**: Apply custom logic before sending to BigQuery
|
|
1826
|
+
- **Field Mapping**: Rename, combine, or derive new fields
|
|
1827
|
+
- **Data Enrichment**: Add computed fields, defaults, or metadata
|
|
1828
|
+
- **Format Conversion**: Convert data types or formats for BigQuery compatibility
|
|
1829
|
+
- **Multiple Destinations**: Send transformed data to different tables
|
|
1830
|
+
|
|
1831
|
+
**Configuration Options:**
|
|
1832
|
+
- `projectId`: Google Cloud project ID (required)
|
|
1833
|
+
- `datasetId`: BigQuery dataset ID (required)
|
|
1834
|
+
- `credentials`: Service account credentials object (optional, uses default if omitted)
|
|
1835
|
+
- `location`: BigQuery dataset location/region (default: 'US')
|
|
1836
|
+
- `logTable`: Table name for operation logging (optional)
|
|
1837
|
+
|
|
1838
|
+
**Resource Configuration:**
|
|
1839
|
+
- **String**: Simple table mapping (e.g., `'table_name'`)
|
|
1840
|
+
- **Object**: Advanced configuration with actions and transforms
|
|
1841
|
+
- **Array**: Multiple destination tables with different configurations
|
|
1842
|
+
|
|
1843
|
+
**Automatic Features:**
|
|
1844
|
+
- **Retry Logic**: Handles BigQuery streaming buffer limitations with 30-second retry delays
|
|
1845
|
+
- **Error Handling**: Graceful handling of schema mismatches and quota limits
|
|
1846
|
+
- **Operation Logging**: Optional audit trail of all replication operations
|
|
1847
|
+
- **Schema Compatibility**: Automatic handling of missing fields
|
|
1848
|
+
|
|
1659
1849
|
#### PostgreSQL Replicator
|
|
1660
1850
|
|
|
1661
1851
|
Replicate to PostgreSQL database:
|