@utaba/deep-memory-storage-cosmosdb 0.9.2 → 0.10.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.
- package/dist/index.cjs +33 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -129,11 +129,24 @@ function isTransientError(err) {
|
|
|
129
129
|
return false;
|
|
130
130
|
}
|
|
131
131
|
function getRetryAfterMs(err, attempt) {
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
const exponentialMs = Math.min(500 * Math.pow(2, attempt), 1e4);
|
|
133
|
+
const topLevel = err?.["retryAfterMs"];
|
|
134
|
+
if (typeof topLevel === "number" && topLevel > 0) {
|
|
135
|
+
return Math.max(topLevel, exponentialMs);
|
|
136
|
+
}
|
|
137
|
+
const attrs = err?.statusAttributes;
|
|
138
|
+
let hintVal;
|
|
139
|
+
if (attrs instanceof Map) {
|
|
140
|
+
hintVal = attrs.get("x-ms-retry-after-ms") ?? attrs.get("x-ms-retry-after");
|
|
141
|
+
} else if (typeof attrs === "object" && attrs !== null) {
|
|
142
|
+
const record = attrs;
|
|
143
|
+
hintVal = record["x-ms-retry-after-ms"] ?? record["x-ms-retry-after"];
|
|
144
|
+
}
|
|
145
|
+
const hintMs = Number(hintVal);
|
|
146
|
+
if (Number.isFinite(hintMs) && hintMs > 0) {
|
|
147
|
+
return Math.max(hintMs, exponentialMs);
|
|
148
|
+
}
|
|
149
|
+
return exponentialMs;
|
|
137
150
|
}
|
|
138
151
|
function extractRequestCharge(resultSet) {
|
|
139
152
|
const attrs = resultSet.attributes;
|
|
@@ -417,7 +430,11 @@ async function updateRepository(conn, repositoryId, updates) {
|
|
|
417
430
|
return await getRepository(conn, repositoryId);
|
|
418
431
|
}
|
|
419
432
|
var DELETE_BATCH_SIZE = 500;
|
|
420
|
-
|
|
433
|
+
function sleep2(ms) {
|
|
434
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
435
|
+
}
|
|
436
|
+
async function deleteRepository(conn, repositoryId, onProgress, options) {
|
|
437
|
+
const batchDelayMs = options?.batchDelayMs ?? 0;
|
|
421
438
|
const entityCountResult = await conn.submit(
|
|
422
439
|
"g.V().has('repositoryId', rid).has('entityType').count()",
|
|
423
440
|
{ rid: repositoryId }
|
|
@@ -443,6 +460,7 @@ async function deleteRepository(conn, repositoryId, onProgress) {
|
|
|
443
460
|
relationshipsDeleted = totalRelationships - remainingCount;
|
|
444
461
|
await onProgress?.({ entitiesDeleted, relationshipsDeleted, totalEntities, totalRelationships });
|
|
445
462
|
if (remainingCount === 0) break;
|
|
463
|
+
if (batchDelayMs > 0) await sleep2(batchDelayMs);
|
|
446
464
|
}
|
|
447
465
|
while (true) {
|
|
448
466
|
await conn.submit(
|
|
@@ -457,9 +475,11 @@ async function deleteRepository(conn, repositoryId, onProgress) {
|
|
|
457
475
|
entitiesDeleted = totalEntities - remainingCount;
|
|
458
476
|
await onProgress?.({ entitiesDeleted, relationshipsDeleted, totalEntities, totalRelationships });
|
|
459
477
|
if (remainingCount === 0) break;
|
|
478
|
+
if (batchDelayMs > 0) await sleep2(batchDelayMs);
|
|
460
479
|
}
|
|
461
480
|
}
|
|
462
|
-
async function deleteAllContents(conn, repositoryId, onProgress) {
|
|
481
|
+
async function deleteAllContents(conn, repositoryId, onProgress, options) {
|
|
482
|
+
const batchDelayMs = options?.batchDelayMs ?? 0;
|
|
463
483
|
const entityCountResult = await conn.submit(
|
|
464
484
|
"g.V().has('repositoryId', rid).has('entityType').count()",
|
|
465
485
|
{ rid: repositoryId }
|
|
@@ -485,6 +505,7 @@ async function deleteAllContents(conn, repositoryId, onProgress) {
|
|
|
485
505
|
relationshipsDeleted = totalRelationships - remainingCount;
|
|
486
506
|
await onProgress?.({ entitiesDeleted, relationshipsDeleted, totalEntities, totalRelationships });
|
|
487
507
|
if (remainingCount === 0) break;
|
|
508
|
+
if (batchDelayMs > 0) await sleep2(batchDelayMs);
|
|
488
509
|
}
|
|
489
510
|
while (true) {
|
|
490
511
|
await conn.submit(
|
|
@@ -499,6 +520,7 @@ async function deleteAllContents(conn, repositoryId, onProgress) {
|
|
|
499
520
|
entitiesDeleted = totalEntities - remainingCount;
|
|
500
521
|
await onProgress?.({ entitiesDeleted, relationshipsDeleted, totalEntities, totalRelationships });
|
|
501
522
|
if (remainingCount === 0) break;
|
|
523
|
+
if (batchDelayMs > 0) await sleep2(batchDelayMs);
|
|
502
524
|
}
|
|
503
525
|
return { deletedEntities: totalEntities, deletedRelationships: totalRelationships };
|
|
504
526
|
}
|
|
@@ -1532,18 +1554,20 @@ var CosmosDbProvider = class {
|
|
|
1532
1554
|
}
|
|
1533
1555
|
async deleteRepository(repositoryId, onProgress) {
|
|
1534
1556
|
this.assertValidRepositoryId(repositoryId);
|
|
1557
|
+
const batchDelayMs = this.config.deleteBatchDelayMs ?? 0;
|
|
1535
1558
|
return this.track(
|
|
1536
1559
|
"deleteRepository",
|
|
1537
1560
|
repositoryId,
|
|
1538
|
-
() => deleteRepository(this.conn, repositoryId, onProgress)
|
|
1561
|
+
() => deleteRepository(this.conn, repositoryId, onProgress, { batchDelayMs })
|
|
1539
1562
|
);
|
|
1540
1563
|
}
|
|
1541
1564
|
async deleteAllContents(repositoryId, onProgress) {
|
|
1542
1565
|
this.assertValidRepositoryId(repositoryId);
|
|
1566
|
+
const batchDelayMs = this.config.deleteBatchDelayMs ?? 0;
|
|
1543
1567
|
return this.track(
|
|
1544
1568
|
"deleteAllContents",
|
|
1545
1569
|
repositoryId,
|
|
1546
|
-
() => deleteAllContents(this.conn, repositoryId, onProgress)
|
|
1570
|
+
() => deleteAllContents(this.conn, repositoryId, onProgress, { batchDelayMs })
|
|
1547
1571
|
);
|
|
1548
1572
|
}
|
|
1549
1573
|
async getRepositoryStats(repositoryId) {
|