@naturalcycles/datastore-lib 4.1.0 → 4.3.0

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.
@@ -14,7 +14,9 @@ const RETRY_ON = [
14
14
  'UNAVAILABLE',
15
15
  'UNKNOWN',
16
16
  'DEADLINE_EXCEEDED',
17
+ 'ABORTED',
17
18
  'much contention',
19
+ 'try again',
18
20
  'timeout',
19
21
  ].map(s => s.toLowerCase());
20
22
  // Examples of errors:
@@ -249,7 +251,14 @@ export class DatastoreDB extends BaseCommonDB {
249
251
  async deleteByIds(table, ids, opt = {}) {
250
252
  const ds = await this.ds();
251
253
  const keys = ids.map(id => this.key(ds, table, id));
252
- await pMap(_chunk(keys, MAX_ITEMS), async (batch) => await (opt.tx?.tx || ds).delete(batch), {
254
+ const retryOptions = this.getPRetryOptions(`DatastoreLib.deleteByIds(${table})`);
255
+ await pMap(_chunk(keys, MAX_ITEMS),
256
+ // async batch => await doDelete(batch),
257
+ async (batchOfKeys) => {
258
+ await pRetry(async () => {
259
+ await (opt.tx?.tx || ds).delete(batchOfKeys);
260
+ }, retryOptions);
261
+ }, {
253
262
  concurrency: DATASTORE_RECOMMENDED_CONCURRENCY,
254
263
  });
255
264
  return ids.length;
package/package.json CHANGED
@@ -1,28 +1,25 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
3
  "type": "module",
4
- "version": "4.1.0",
4
+ "version": "4.3.0",
5
5
  "description": "Opinionated library to work with Google Datastore",
6
6
  "scripts": {
7
- "prepare": "husky",
8
7
  "build": "dev-lib build",
9
8
  "test": "dev-lib test",
10
9
  "lint": "dev-lib lint",
11
10
  "bt": "dev-lib bt",
12
- "lbt": "dev-lib lbt"
11
+ "lbt": "dev-lib lbt",
12
+ "check": "dev-lib lbt"
13
13
  },
14
14
  "dependencies": {
15
15
  "@google-cloud/datastore": "^10",
16
- "@naturalcycles/db-lib": "^10",
17
- "@naturalcycles/js-lib": "^15",
18
- "@naturalcycles/nodejs-lib": "^14"
16
+ "@naturalcycles/db-lib": "workspace:^10",
17
+ "@naturalcycles/js-lib": "workspace:^15",
18
+ "@naturalcycles/nodejs-lib": "workspace:^14"
19
19
  },
20
20
  "devDependencies": {
21
- "@naturalcycles/dev-lib": "^18",
22
- "@types/node": "^22",
23
- "@vitest/coverage-v8": "^3",
24
- "tsx": "^4",
25
- "vitest": "^3"
21
+ "@naturalcycles/dev-lib": "*",
22
+ "@types/node": "^22"
26
23
  },
27
24
  "files": [
28
25
  "dist",
@@ -37,13 +34,13 @@
37
34
  "engines": {
38
35
  "node": ">=22.12.0"
39
36
  },
40
- "packageManager": "yarn@1.22.22",
41
37
  "publishConfig": {
42
38
  "access": "public"
43
39
  },
44
40
  "repository": {
45
41
  "type": "git",
46
- "url": "https://github.com/NaturalCycles/datastore-lib"
42
+ "url": "git@github.com:NaturalCycles/js-libs.git",
43
+ "directory": "packages/datastore-lib"
47
44
  },
48
45
  "keywords": [
49
46
  "datastore",
@@ -65,7 +65,9 @@ const RETRY_ON = [
65
65
  'UNAVAILABLE',
66
66
  'UNKNOWN',
67
67
  'DEADLINE_EXCEEDED',
68
+ 'ABORTED',
68
69
  'much contention',
70
+ 'try again',
69
71
  'timeout',
70
72
  ].map(s => s.toLowerCase())
71
73
  // Examples of errors:
@@ -416,10 +418,16 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
416
418
  const ds = await this.ds()
417
419
  const keys = ids.map(id => this.key(ds, table, id))
418
420
 
421
+ const retryOptions = this.getPRetryOptions(`DatastoreLib.deleteByIds(${table})`)
422
+
419
423
  await pMap(
420
424
  _chunk(keys, MAX_ITEMS),
421
-
422
- async batch => await ((opt.tx as DatastoreDBTransaction)?.tx || ds).delete(batch),
425
+ // async batch => await doDelete(batch),
426
+ async batchOfKeys => {
427
+ await pRetry(async () => {
428
+ await ((opt.tx as DatastoreDBTransaction)?.tx || ds).delete(batchOfKeys)
429
+ }, retryOptions)
430
+ },
423
431
  {
424
432
  concurrency: DATASTORE_RECOMMENDED_CONCURRENCY,
425
433
  },