s3db.js 4.1.5 → 4.1.6

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 (2) hide show
  1. package/README.md +76 -57
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -263,74 +263,93 @@ const users = await s3db.createResource({
263
263
  });
264
264
  ```
265
265
 
266
- #### Nested Attributes
266
+ #### List, ListIds, Count, Page, Query (Novo Formato)
267
267
 
268
- `s3db.js` fully supports nested object attributes, allowing you to create complex document structures:
268
+ Todos os métodos de listagem, paginação e contagem agora recebem um único objeto de parâmetros:
269
269
 
270
- ```javascript
270
+ ```js
271
+ // Listar todos os usuários
272
+ const allUsers = await users.list();
273
+
274
+ // Listar usuários de uma partição
275
+ const googleUsers = await users.list({
276
+ partition: 'byUtmSource',
277
+ partitionValues: { 'utm.source': 'google' }
278
+ });
279
+
280
+ // Listar IDs de uma partição
281
+ const googleUserIds = await users.listIds({
282
+ partition: 'byUtmSource',
283
+ partitionValues: { 'utm.source': 'google' }
284
+ });
285
+
286
+ // Paginar resultados
287
+ const page = await users.page({
288
+ partition: 'byUtmSource',
289
+ partitionValues: { 'utm.source': 'google' },
290
+ offset: 0,
291
+ size: 10
292
+ });
293
+ console.log(page.items); // Array de usuários
294
+ console.log(page.totalItems, page.totalPages);
295
+
296
+ // Contar documentos em uma partição
297
+ const count = await users.count({
298
+ partition: 'byUtmSource',
299
+ partitionValues: { 'utm.source': 'google' }
300
+ });
301
+
302
+ // Query com filtro e paginação
303
+ const filtered = await users.query(
304
+ { isActive: true },
305
+ { partition: 'byUtmSource', partitionValues: { 'utm.source': 'google' }, limit: 5, offset: 0 }
306
+ );
307
+ ```
308
+
309
+ #### Partições com Campos Aninhados
310
+
311
+ Você pode usar dot notation para acessar campos aninhados em partições:
312
+
313
+ ```js
271
314
  const users = await s3db.createResource({
272
- name: "users",
315
+ name: 'users',
273
316
  attributes: {
274
- name: "string|required",
275
- email: "email|required",
276
- utm: {
277
- source: "string|required",
278
- medium: "string|required",
279
- campaign: "string|required",
280
- term: "string|optional",
281
- content: "string|optional"
282
- },
283
- address: {
284
- street: "string|required",
285
- city: "string|required",
286
- state: "string|required",
287
- country: "string|required",
288
- zipCode: "string|optional"
289
- },
290
- metadata: {
291
- category: "string|required",
292
- priority: "string|required",
293
- settings: "object|optional"
317
+ name: 'string|required',
318
+ utm: { source: 'string|required', medium: 'string|required' },
319
+ address: { country: 'string|required', city: 'string|required' }
320
+ },
321
+ options: {
322
+ partitions: {
323
+ byUtmSource: { fields: { 'utm.source': 'string' } },
324
+ byCountry: { fields: { 'address.country': 'string' } }
294
325
  }
295
326
  }
296
327
  });
297
328
 
298
- // Insert data with nested objects
299
- const user = await users.insert({
300
- name: "John Doe",
301
- email: "john@example.com",
302
- utm: {
303
- source: "google",
304
- medium: "cpc",
305
- campaign: "brand_awareness",
306
- term: "search term"
307
- },
308
- address: {
309
- street: "123 Main St",
310
- city: "San Francisco",
311
- state: "California",
312
- country: "US",
313
- zipCode: "94105"
314
- },
315
- metadata: {
316
- category: "premium",
317
- priority: "high",
318
- settings: { theme: "dark", notifications: true }
319
- }
329
+ // Listar por campo aninhado
330
+ const usUsers = await users.list({
331
+ partition: 'byCountry',
332
+ partitionValues: { 'address.country': 'US' }
320
333
  });
321
-
322
- // Access nested data
323
- console.log(user.utm.source); // "google"
324
- console.log(user.address.city); // "San Francisco"
325
- console.log(user.metadata.category); // "premium"
326
334
  ```
327
335
 
328
- **Key features of nested attributes:**
329
- - **Deep nesting**: Support for multiple levels of nested objects
330
- - **Validation**: Each nested field can have its own validation rules
331
- - **Optional fields**: Nested objects can contain optional fields
332
- - **Mixed types**: Combine simple types, arrays, and nested objects
333
- - **Partition support**: Use dot notation for partitions on nested fields (e.g., `"utm.source"`, `"address.country"`)
336
+ #### getPartitionKey e getFromPartition
337
+
338
+ ```js
339
+ // Gerar chave de partição
340
+ const key = users.getPartitionKey({
341
+ partitionName: 'byUtmSource',
342
+ id: 'user-123',
343
+ data: { utm: { source: 'google' } }
344
+ });
345
+
346
+ // Buscar diretamente de uma partição
347
+ const user = await users.getFromPartition({
348
+ id: 'user-123',
349
+ partitionName: 'byUtmSource',
350
+ partitionValues: { 'utm.source': 'google' }
351
+ });
352
+ ```
334
353
 
335
354
  #### Automatic Timestamps
336
355
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s3db.js",
3
- "version": "4.1.5",
3
+ "version": "4.1.6",
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",