s3db.js 1.0.6 → 1.0.7

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 CHANGED
@@ -206,7 +206,7 @@ await s3db.createResource({
206
206
  });
207
207
  ```
208
208
 
209
- Resources' names **cannot** prefix each other, like: `leads` and `leads-copy`! S3's api will consider both one single resource.
209
+ Resources' names **cannot** prefix each other, like: `leads` and `leads-copy`! S3's api lists keys using prefix notation, so every time you list `leads`, all keys of `leads-copy` will appear as well.
210
210
 
211
211
  ##### Attributes
212
212
 
@@ -389,6 +389,7 @@ await resource.bulkDelete(["id1", "id2", "id3 "]);
389
389
 
390
390
  ```javascript
391
391
  const ids = await resource.getAllIds();
392
+
392
393
  // [
393
394
  // 'id1',
394
395
  // 'id2',
@@ -406,6 +407,12 @@ await resource.deleteAll();
406
407
 
407
408
  ```javascript
408
409
  const data = await resource.getAll();
410
+
411
+ // [
412
+ // obj1,
413
+ // obj2,
414
+ // ...
415
+ // ]
409
416
  ```
410
417
 
411
418
  ### Resource streams
@@ -436,16 +443,18 @@ writableStream.write({
436
443
 
437
444
  ### Events
438
445
 
439
- 1. s3db
446
+ The 3 main classes `S3db`, `Resource` and `S3Client` are extensions of Javascript's `EventEmitter`.
447
+
448
+ 1. S3db
440
449
  - connected
441
450
  - resource.created
442
451
  - resource.inserted
443
452
  - resource.deleted
444
453
  - error
445
- 1. client
454
+ 1. S3Client
446
455
  - action
447
456
  - error
448
- 1. resource
457
+ 1. Resource
449
458
  - id
450
459
  - inserted
451
460
  - deleted
@@ -219,7 +219,7 @@ class Resource extends events_1.default {
219
219
  safe: true,
220
220
  }), { id } = _b, attrs = __rest(_b, ["id"]);
221
221
  // validate
222
- const { isValid, errors, data: validated } = this.check(attrs);
222
+ let { isValid, errors, data: validated } = this.check(attrs);
223
223
  if (!isValid) {
224
224
  return Promise.reject(new errors_1.S3dbInvalidResource({
225
225
  bucket: this.s3Client.bucket,
@@ -230,13 +230,14 @@ class Resource extends events_1.default {
230
230
  }
231
231
  if (!id && id !== 0)
232
232
  id = (0, nanoid_1.nanoid)();
233
+ validated = this.map(validated);
233
234
  // save
234
235
  yield this.s3Client.putObject({
235
236
  key: path.join(`resource=${this.name}`, `id=${id}`),
236
237
  body: "",
237
- metadata: this.map(validated),
238
+ metadata: validated,
238
239
  });
239
- const final = Object.assign({ id }, (0, flat_1.unflatten)(validated));
240
+ const final = Object.assign({ id }, (0, flat_1.unflatten)(this.unmap(validated)));
240
241
  this.emit("inserted", final);
241
242
  this.s3db.emit("inserted", this.name, final);
242
243
  if (this.s3Cache) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s3db.js",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Use AWS S3 as a cheap document database.",
5
5
  "main": "build/index.js",
6
6
  "author": "forattini-dev",