s3db.js 4.1.6 → 4.1.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.
- package/README.md +83 -16
- package/dist/s3db.cjs.js +513 -146
- package/dist/s3db.cjs.min.js +9 -9
- package/dist/s3db.es.js +513 -146
- package/dist/s3db.es.min.js +9 -9
- package/dist/s3db.iife.js +513 -146
- package/dist/s3db.iife.min.js +10 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -283,7 +283,7 @@ const googleUserIds = await users.listIds({
|
|
|
283
283
|
partitionValues: { 'utm.source': 'google' }
|
|
284
284
|
});
|
|
285
285
|
|
|
286
|
-
// Paginar resultados
|
|
286
|
+
// Paginar resultados com contagem total
|
|
287
287
|
const page = await users.page({
|
|
288
288
|
partition: 'byUtmSource',
|
|
289
289
|
partitionValues: { 'utm.source': 'google' },
|
|
@@ -291,7 +291,20 @@ const page = await users.page({
|
|
|
291
291
|
size: 10
|
|
292
292
|
});
|
|
293
293
|
console.log(page.items); // Array de usuários
|
|
294
|
-
console.log(page.totalItems, page.totalPages);
|
|
294
|
+
console.log(page.totalItems, page.totalPages); // Contagem total e páginas
|
|
295
|
+
console.log(page.page, page.pageSize); // Página atual e tamanho
|
|
296
|
+
|
|
297
|
+
// Paginar resultados sem contagem total (mais rápido para grandes coleções)
|
|
298
|
+
const fastPage = await users.page({
|
|
299
|
+
partition: 'byUtmSource',
|
|
300
|
+
partitionValues: { 'utm.source': 'google' },
|
|
301
|
+
offset: 0,
|
|
302
|
+
size: 10,
|
|
303
|
+
skipCount: true // Pula a contagem total para melhor performance
|
|
304
|
+
});
|
|
305
|
+
console.log(fastPage.items); // Array de usuários
|
|
306
|
+
console.log(fastPage.totalItems); // null (não contado)
|
|
307
|
+
console.log(fastPage._debug); // Informações de debug
|
|
295
308
|
|
|
296
309
|
// Contar documentos em uma partição
|
|
297
310
|
const count = await users.count({
|
|
@@ -960,6 +973,73 @@ const count = await users.count();
|
|
|
960
973
|
console.log(`Total users: ${count}`);
|
|
961
974
|
```
|
|
962
975
|
|
|
976
|
+
#### Page Documents
|
|
977
|
+
|
|
978
|
+
The `page()` method provides efficient pagination with optional total count for performance optimization.
|
|
979
|
+
|
|
980
|
+
```javascript
|
|
981
|
+
// Basic pagination with total count
|
|
982
|
+
const page = await users.page({
|
|
983
|
+
offset: 0,
|
|
984
|
+
size: 10
|
|
985
|
+
});
|
|
986
|
+
|
|
987
|
+
console.log(page.items); // Array of user objects
|
|
988
|
+
console.log(page.totalItems); // Total number of items
|
|
989
|
+
console.log(page.totalPages); // Total number of pages
|
|
990
|
+
console.log(page.page); // Current page number (0-based)
|
|
991
|
+
console.log(page.pageSize); // Items per page
|
|
992
|
+
console.log(page._debug); // Debug information
|
|
993
|
+
|
|
994
|
+
// Pagination with partition filtering
|
|
995
|
+
const googleUsersPage = await users.page({
|
|
996
|
+
partition: 'byUtmSource',
|
|
997
|
+
partitionValues: { 'utm.source': 'google' },
|
|
998
|
+
offset: 0,
|
|
999
|
+
size: 5
|
|
1000
|
+
});
|
|
1001
|
+
|
|
1002
|
+
// Skip total count for better performance on large collections
|
|
1003
|
+
const fastPage = await users.page({
|
|
1004
|
+
offset: 0,
|
|
1005
|
+
size: 100,
|
|
1006
|
+
skipCount: true // Skips counting total items
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
console.log(fastPage.totalItems); // null (not counted)
|
|
1010
|
+
console.log(fastPage.totalPages); // null (not calculated)
|
|
1011
|
+
console.log(fastPage._debug.skipCount); // true
|
|
1012
|
+
```
|
|
1013
|
+
|
|
1014
|
+
**Page Response Structure:**
|
|
1015
|
+
|
|
1016
|
+
```javascript
|
|
1017
|
+
{
|
|
1018
|
+
items: Array, // Array of document objects
|
|
1019
|
+
totalItems: number, // Total count (null if skipCount: true)
|
|
1020
|
+
page: number, // Current page number (0-based)
|
|
1021
|
+
pageSize: number, // Number of items per page
|
|
1022
|
+
totalPages: number, // Total pages (null if skipCount: true)
|
|
1023
|
+
_debug: { // Debug information
|
|
1024
|
+
requestedSize: number,
|
|
1025
|
+
requestedOffset: number,
|
|
1026
|
+
actualItemsReturned: number,
|
|
1027
|
+
skipCount: boolean,
|
|
1028
|
+
hasTotalItems: boolean
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
```
|
|
1032
|
+
|
|
1033
|
+
**Parameters:**
|
|
1034
|
+
|
|
1035
|
+
| Parameter | Type | Default | Description |
|
|
1036
|
+
|-----------|------|---------|-------------|
|
|
1037
|
+
| `offset` | `number` | `0` | Number of items to skip |
|
|
1038
|
+
| `size` | `number` | `100` | Number of items per page |
|
|
1039
|
+
| `partition` | `string` | `null` | Partition name to filter by |
|
|
1040
|
+
| `partitionValues` | `object` | `{}` | Partition field values |
|
|
1041
|
+
| `skipCount` | `boolean` | `false` | Skip total count for performance |
|
|
1042
|
+
|
|
963
1043
|
### Bulk Operations
|
|
964
1044
|
|
|
965
1045
|
#### Insert Many
|
|
@@ -1680,7 +1760,7 @@ await products.insert({
|
|
|
1680
1760
|
| `listIds()` | Get array of document IDs | ✅ `{ partition, partitionValues }` |
|
|
1681
1761
|
| `count()` | Count documents | ✅ `{ partition, partitionValues }` |
|
|
1682
1762
|
| `listByPartition()` | List documents by partition | ✅ `{ partition, partitionValues }` |
|
|
1683
|
-
| `page()` | Paginate documents | ✅ `{ partition, partitionValues }` |
|
|
1763
|
+
| `page()` | Paginate documents | ✅ `{ partition, partitionValues, skipCount }` |
|
|
1684
1764
|
| `getFromPartition()` | Get single document from partition | ✅ Direct partition access |
|
|
1685
1765
|
| `query()` | Filter documents in memory | ❌ No partition support |
|
|
1686
1766
|
|
|
@@ -1767,19 +1847,6 @@ const s3db = new S3db({
|
|
|
1767
1847
|
- **`enforce-limits`**: Strict validation to prevent oversized documents
|
|
1768
1848
|
- **`user-management`**: Default behavior with warnings and monitoring
|
|
1769
1849
|
|
|
1770
|
-
### ✅ Recent Improvements
|
|
1771
|
-
|
|
1772
|
-
**🔧 Enhanced Data Serialization (v3.3.2+)**
|
|
1773
|
-
|
|
1774
|
-
s3db.js now handles complex data structures robustly:
|
|
1775
|
-
|
|
1776
|
-
- **Empty Arrays**: `[]` correctly serialized and preserved
|
|
1777
|
-
- **Null Arrays**: `null` values maintained without corruption
|
|
1778
|
-
- **Special Characters**: Arrays with pipe `|` characters properly escaped
|
|
1779
|
-
- **Empty Objects**: `{}` correctly mapped and stored
|
|
1780
|
-
- **Null Objects**: `null` object values preserved during serialization
|
|
1781
|
-
- **Nested Structures**: Complex nested objects with mixed empty/null values supported
|
|
1782
|
-
|
|
1783
1850
|
### Best Practices
|
|
1784
1851
|
|
|
1785
1852
|
#### 1. Design for Document Storage
|