s3db.js 19.5.1 → 19.5.2

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.
@@ -322,19 +322,22 @@ export class ResourcePartitions {
322
322
  });
323
323
  await Promise.allSettled(updatePromises);
324
324
  const id = newData.id || oldData.id;
325
- const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
326
- const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
327
- const [okKeys, , keys] = await tryFn(() => this.resource.client.getAllKeys({ prefix }));
328
- if (!okKeys || !keys) {
329
- return;
330
- }
331
- const validKey = this.getKey({ partitionName, id, data: newData });
332
- const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
333
- if (staleKeys.length > 0) {
334
- await tryFn(() => this.resource.client.deleteObjects(staleKeys));
335
- }
336
- });
337
- await Promise.allSettled(cleanupPromises);
325
+ const isNewInsert = !oldData || Object.keys(oldData).length === 0;
326
+ if (!isNewInsert) {
327
+ const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
328
+ const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
329
+ const [okKeys, , keys] = await tryFn(() => this.resource.client.getAllKeys({ prefix }));
330
+ if (!okKeys || !keys) {
331
+ return;
332
+ }
333
+ const validKey = this.getKey({ partitionName, id, data: newData });
334
+ const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
335
+ if (staleKeys.length > 0) {
336
+ await tryFn(() => this.resource.client.deleteObjects(staleKeys));
337
+ }
338
+ });
339
+ await Promise.allSettled(cleanupPromises);
340
+ }
338
341
  }
339
342
  async handleReferenceUpdate(partitionName, partition, oldData, newData) {
340
343
  const id = newData.id || oldData.id;
@@ -67003,19 +67003,22 @@ class ResourcePartitions {
67003
67003
  });
67004
67004
  await Promise.allSettled(updatePromises);
67005
67005
  const id = newData.id || oldData.id;
67006
- const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
67007
- const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
67008
- const [okKeys, , keys] = await tryFn$1(() => this.resource.client.getAllKeys({ prefix }));
67009
- if (!okKeys || !keys) {
67010
- return;
67011
- }
67012
- const validKey = this.getKey({ partitionName, id, data: newData });
67013
- const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
67014
- if (staleKeys.length > 0) {
67015
- await tryFn$1(() => this.resource.client.deleteObjects(staleKeys));
67016
- }
67017
- });
67018
- await Promise.allSettled(cleanupPromises);
67006
+ const isNewInsert = !oldData || Object.keys(oldData).length === 0;
67007
+ if (!isNewInsert) {
67008
+ const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
67009
+ const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
67010
+ const [okKeys, , keys] = await tryFn$1(() => this.resource.client.getAllKeys({ prefix }));
67011
+ if (!okKeys || !keys) {
67012
+ return;
67013
+ }
67014
+ const validKey = this.getKey({ partitionName, id, data: newData });
67015
+ const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
67016
+ if (staleKeys.length > 0) {
67017
+ await tryFn$1(() => this.resource.client.deleteObjects(staleKeys));
67018
+ }
67019
+ });
67020
+ await Promise.allSettled(cleanupPromises);
67021
+ }
67019
67022
  }
67020
67023
  async handleReferenceUpdate(partitionName, partition, oldData, newData) {
67021
67024
  const id = newData.id || oldData.id;
@@ -70670,8 +70673,8 @@ class Database extends SafeEventEmitter {
70670
70673
  })();
70671
70674
  this.version = '1';
70672
70675
  this.s3dbVersion = (() => {
70673
- const [ok, , version] = tryFnSync(() => (typeof globalThis['19.5.1'] !== 'undefined' && globalThis['19.5.1'] !== '19.5.1'
70674
- ? globalThis['19.5.1']
70676
+ const [ok, , version] = tryFnSync(() => (typeof globalThis['19.5.2'] !== 'undefined' && globalThis['19.5.2'] !== '19.5.2'
70677
+ ? globalThis['19.5.2']
70675
70678
  : 'latest'));
70676
70679
  return ok ? version : 'latest';
70677
70680
  })();
@@ -66980,19 +66980,22 @@ class ResourcePartitions {
66980
66980
  });
66981
66981
  await Promise.allSettled(updatePromises);
66982
66982
  const id = newData.id || oldData.id;
66983
- const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
66984
- const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
66985
- const [okKeys, , keys] = await tryFn$1(() => this.resource.client.getAllKeys({ prefix }));
66986
- if (!okKeys || !keys) {
66987
- return;
66988
- }
66989
- const validKey = this.getKey({ partitionName, id, data: newData });
66990
- const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
66991
- if (staleKeys.length > 0) {
66992
- await tryFn$1(() => this.resource.client.deleteObjects(staleKeys));
66993
- }
66994
- });
66995
- await Promise.allSettled(cleanupPromises);
66983
+ const isNewInsert = !oldData || Object.keys(oldData).length === 0;
66984
+ if (!isNewInsert) {
66985
+ const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
66986
+ const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
66987
+ const [okKeys, , keys] = await tryFn$1(() => this.resource.client.getAllKeys({ prefix }));
66988
+ if (!okKeys || !keys) {
66989
+ return;
66990
+ }
66991
+ const validKey = this.getKey({ partitionName, id, data: newData });
66992
+ const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
66993
+ if (staleKeys.length > 0) {
66994
+ await tryFn$1(() => this.resource.client.deleteObjects(staleKeys));
66995
+ }
66996
+ });
66997
+ await Promise.allSettled(cleanupPromises);
66998
+ }
66996
66999
  }
66997
67000
  async handleReferenceUpdate(partitionName, partition, oldData, newData) {
66998
67001
  const id = newData.id || oldData.id;
@@ -70647,8 +70650,8 @@ class Database extends SafeEventEmitter {
70647
70650
  })();
70648
70651
  this.version = '1';
70649
70652
  this.s3dbVersion = (() => {
70650
- const [ok, , version] = tryFnSync(() => (typeof globalThis['19.5.1'] !== 'undefined' && globalThis['19.5.1'] !== '19.5.1'
70651
- ? globalThis['19.5.1']
70653
+ const [ok, , version] = tryFnSync(() => (typeof globalThis['19.5.2'] !== 'undefined' && globalThis['19.5.2'] !== '19.5.2'
70654
+ ? globalThis['19.5.2']
70652
70655
  : 'latest'));
70653
70656
  return ok ? version : 'latest';
70654
70657
  })();
package/dist/s3db.cjs CHANGED
@@ -16492,19 +16492,22 @@ class ResourcePartitions {
16492
16492
  });
16493
16493
  await Promise.allSettled(updatePromises);
16494
16494
  const id = newData.id || oldData.id;
16495
- const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
16496
- const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
16497
- const [okKeys, , keys] = await tryFn(() => this.resource.client.getAllKeys({ prefix }));
16498
- if (!okKeys || !keys) {
16499
- return;
16500
- }
16501
- const validKey = this.getKey({ partitionName, id, data: newData });
16502
- const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
16503
- if (staleKeys.length > 0) {
16504
- await tryFn(() => this.resource.client.deleteObjects(staleKeys));
16505
- }
16506
- });
16507
- await Promise.allSettled(cleanupPromises);
16495
+ const isNewInsert = !oldData || Object.keys(oldData).length === 0;
16496
+ if (!isNewInsert) {
16497
+ const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
16498
+ const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
16499
+ const [okKeys, , keys] = await tryFn(() => this.resource.client.getAllKeys({ prefix }));
16500
+ if (!okKeys || !keys) {
16501
+ return;
16502
+ }
16503
+ const validKey = this.getKey({ partitionName, id, data: newData });
16504
+ const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
16505
+ if (staleKeys.length > 0) {
16506
+ await tryFn(() => this.resource.client.deleteObjects(staleKeys));
16507
+ }
16508
+ });
16509
+ await Promise.allSettled(cleanupPromises);
16510
+ }
16508
16511
  }
16509
16512
  async handleReferenceUpdate(partitionName, partition, oldData, newData) {
16510
16513
  const id = newData.id || oldData.id;
@@ -20159,8 +20162,8 @@ class Database extends SafeEventEmitter {
20159
20162
  })();
20160
20163
  this.version = '1';
20161
20164
  this.s3dbVersion = (() => {
20162
- const [ok, , version] = tryFnSync(() => (typeof globalThis['19.5.1'] !== 'undefined' && globalThis['19.5.1'] !== '19.5.1'
20163
- ? globalThis['19.5.1']
20165
+ const [ok, , version] = tryFnSync(() => (typeof globalThis['19.5.2'] !== 'undefined' && globalThis['19.5.2'] !== '19.5.2'
20166
+ ? globalThis['19.5.2']
20164
20167
  : 'latest'));
20165
20168
  return ok ? version : 'latest';
20166
20169
  })();
package/dist/s3db.es.js CHANGED
@@ -16467,19 +16467,22 @@ class ResourcePartitions {
16467
16467
  });
16468
16468
  await Promise.allSettled(updatePromises);
16469
16469
  const id = newData.id || oldData.id;
16470
- const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
16471
- const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
16472
- const [okKeys, , keys] = await tryFn(() => this.resource.client.getAllKeys({ prefix }));
16473
- if (!okKeys || !keys) {
16474
- return;
16475
- }
16476
- const validKey = this.getKey({ partitionName, id, data: newData });
16477
- const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
16478
- if (staleKeys.length > 0) {
16479
- await tryFn(() => this.resource.client.deleteObjects(staleKeys));
16480
- }
16481
- });
16482
- await Promise.allSettled(cleanupPromises);
16470
+ const isNewInsert = !oldData || Object.keys(oldData).length === 0;
16471
+ if (!isNewInsert) {
16472
+ const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
16473
+ const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
16474
+ const [okKeys, , keys] = await tryFn(() => this.resource.client.getAllKeys({ prefix }));
16475
+ if (!okKeys || !keys) {
16476
+ return;
16477
+ }
16478
+ const validKey = this.getKey({ partitionName, id, data: newData });
16479
+ const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
16480
+ if (staleKeys.length > 0) {
16481
+ await tryFn(() => this.resource.client.deleteObjects(staleKeys));
16482
+ }
16483
+ });
16484
+ await Promise.allSettled(cleanupPromises);
16485
+ }
16483
16486
  }
16484
16487
  async handleReferenceUpdate(partitionName, partition, oldData, newData) {
16485
16488
  const id = newData.id || oldData.id;
@@ -20134,8 +20137,8 @@ class Database extends SafeEventEmitter {
20134
20137
  })();
20135
20138
  this.version = '1';
20136
20139
  this.s3dbVersion = (() => {
20137
- const [ok, , version] = tryFnSync(() => (typeof globalThis['19.5.1'] !== 'undefined' && globalThis['19.5.1'] !== '19.5.1'
20138
- ? globalThis['19.5.1']
20140
+ const [ok, , version] = tryFnSync(() => (typeof globalThis['19.5.2'] !== 'undefined' && globalThis['19.5.2'] !== '19.5.2'
20141
+ ? globalThis['19.5.2']
20139
20142
  : 'latest'));
20140
20143
  return ok ? version : 'latest';
20141
20144
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s3db.js",
3
- "version": "19.5.1",
3
+ "version": "19.5.2",
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",
6
6
  "module": "dist/s3db.es.js",
@@ -487,22 +487,26 @@ export class ResourcePartitions {
487
487
  await Promise.allSettled(updatePromises);
488
488
 
489
489
  const id = newData.id || oldData.id;
490
- const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
491
- const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
492
- const [okKeys, , keys] = await tryFn<string[]>(() => this.resource.client.getAllKeys({ prefix }));
493
- if (!okKeys || !keys) {
494
- return;
495
- }
490
+ const isNewInsert = !oldData || Object.keys(oldData).length === 0;
491
+
492
+ if (!isNewInsert) {
493
+ const cleanupPromises = Object.entries(partitions).map(async ([partitionName]) => {
494
+ const prefix = `resource=${this.resource.name}/partition=${partitionName}`;
495
+ const [okKeys, , keys] = await tryFn<string[]>(() => this.resource.client.getAllKeys({ prefix }));
496
+ if (!okKeys || !keys) {
497
+ return;
498
+ }
496
499
 
497
- const validKey = this.getKey({ partitionName, id, data: newData });
498
- const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
500
+ const validKey = this.getKey({ partitionName, id, data: newData });
501
+ const staleKeys = keys.filter(key => key.endsWith(`/id=${id}`) && key !== validKey);
499
502
 
500
- if (staleKeys.length > 0) {
501
- await tryFn(() => this.resource.client.deleteObjects(staleKeys));
502
- }
503
- });
503
+ if (staleKeys.length > 0) {
504
+ await tryFn(() => this.resource.client.deleteObjects(staleKeys));
505
+ }
506
+ });
504
507
 
505
- await Promise.allSettled(cleanupPromises);
508
+ await Promise.allSettled(cleanupPromises);
509
+ }
506
510
  }
507
511
 
508
512
  async handleReferenceUpdate(