hide-a-bed 7.0.0-beta.0 → 7.0.0-beta.1
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/cjs/index.cjs +57 -25
- package/dist/esm/index.mjs +57 -25
- package/impl/bulkSave.mts +22 -10
- package/impl/utils/errors.mts +29 -4
- package/impl/utils/transactionErrors.mts +22 -38
- package/package.json +1 -1
- package/schema/couch/couch.output.schema.ts +17 -15
- package/types/output/impl/bulkRemove.d.mts +6 -5
- package/types/output/impl/bulkRemove.d.mts.map +1 -1
- package/types/output/impl/bulkSave.d.mts +5 -3
- package/types/output/impl/bulkSave.d.mts.map +1 -1
- package/types/output/impl/patch.d.mts +2 -4
- package/types/output/impl/patch.d.mts.map +1 -1
- package/types/output/impl/remove.d.mts +1 -2
- package/types/output/impl/remove.d.mts.map +1 -1
- package/types/output/impl/utils/errors.d.mts +2 -0
- package/types/output/impl/utils/errors.d.mts.map +1 -1
- package/types/output/impl/utils/transactionErrors.d.mts +8 -28
- package/types/output/impl/utils/transactionErrors.d.mts.map +1 -1
- package/types/output/schema/couch/couch.output.schema.d.ts +19 -9
- package/types/output/schema/couch/couch.output.schema.d.ts.map +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -267,6 +267,10 @@ const SUCCESS_STATUS_CODES = {
|
|
|
267
267
|
viewQuery: [200],
|
|
268
268
|
viewStream: [200]
|
|
269
269
|
};
|
|
270
|
+
const getReason = (value, fallback) => {
|
|
271
|
+
if (!isRecord(value) || typeof value.reason !== "string") return fallback;
|
|
272
|
+
return value.reason;
|
|
273
|
+
};
|
|
270
274
|
const getCouchError = (value) => {
|
|
271
275
|
if (!isRecord(value) || typeof value.error !== "string") return;
|
|
272
276
|
return value.error;
|
|
@@ -314,6 +318,7 @@ const getNestedNetworkError = (value) => {
|
|
|
314
318
|
var HideABedError = class extends Error {
|
|
315
319
|
category;
|
|
316
320
|
couchError;
|
|
321
|
+
couchReason;
|
|
317
322
|
docId;
|
|
318
323
|
operation;
|
|
319
324
|
retryable;
|
|
@@ -323,6 +328,7 @@ var HideABedError = class extends Error {
|
|
|
323
328
|
this.name = "HideABedError";
|
|
324
329
|
this.category = options.category;
|
|
325
330
|
this.couchError = options.couchError;
|
|
331
|
+
this.couchReason = options.couchReason;
|
|
326
332
|
this.docId = options.docId;
|
|
327
333
|
this.operation = options.operation;
|
|
328
334
|
this.retryable = options.retryable;
|
|
@@ -343,6 +349,7 @@ var NotFoundError = class extends HideABedError {
|
|
|
343
349
|
super(options.message ?? "Document not found", {
|
|
344
350
|
category: "not_found",
|
|
345
351
|
couchError: options.couchError ?? "not_found",
|
|
352
|
+
couchReason: options.couchReason,
|
|
346
353
|
cause: options.cause,
|
|
347
354
|
docId,
|
|
348
355
|
operation: options.operation,
|
|
@@ -362,6 +369,7 @@ var ConflictError = class extends HideABedError {
|
|
|
362
369
|
super(options.message ?? "Document update conflict", {
|
|
363
370
|
category: "conflict",
|
|
364
371
|
couchError: options.couchError ?? "conflict",
|
|
372
|
+
couchReason: options.couchReason,
|
|
365
373
|
cause: options.cause,
|
|
366
374
|
docId,
|
|
367
375
|
operation: options.operation,
|
|
@@ -382,6 +390,7 @@ var OperationError = class extends HideABedError {
|
|
|
382
390
|
category: options.category ?? "operation",
|
|
383
391
|
cause: options.cause,
|
|
384
392
|
couchError: options.couchError,
|
|
393
|
+
couchReason: options.couchReason,
|
|
385
394
|
docId: options.docId,
|
|
386
395
|
operation: options.operation,
|
|
387
396
|
retryable: false,
|
|
@@ -402,6 +411,7 @@ var ValidationError = class extends HideABedError {
|
|
|
402
411
|
category: "validation",
|
|
403
412
|
cause: options.cause,
|
|
404
413
|
couchError: options.couchError,
|
|
414
|
+
couchReason: options.couchReason,
|
|
405
415
|
docId: options.docId,
|
|
406
416
|
operation: options.operation,
|
|
407
417
|
retryable: false,
|
|
@@ -426,6 +436,7 @@ var RetryableError = class RetryableError extends HideABedError {
|
|
|
426
436
|
category: options.category ?? "retryable",
|
|
427
437
|
cause: options.cause,
|
|
428
438
|
couchError: options.couchError,
|
|
439
|
+
couchReason: options.couchReason,
|
|
429
440
|
docId: options.docId,
|
|
430
441
|
operation: options.operation,
|
|
431
442
|
retryable: true,
|
|
@@ -465,25 +476,37 @@ var RetryableError = class RetryableError extends HideABedError {
|
|
|
465
476
|
throw err;
|
|
466
477
|
}
|
|
467
478
|
};
|
|
479
|
+
const getResponseErrorMessage = (body, defaultMessage) => {
|
|
480
|
+
const reason = getReason(body, "").trim();
|
|
481
|
+
if (!reason || reason === defaultMessage) return defaultMessage;
|
|
482
|
+
return `${defaultMessage}: ${reason}`;
|
|
483
|
+
};
|
|
468
484
|
function createResponseError({ body, defaultMessage, docId, notFoundMessage, operation, statusCode }) {
|
|
469
485
|
const couchError = getCouchError(body);
|
|
486
|
+
const couchReason = getReason(body, "").trim() || void 0;
|
|
487
|
+
const message = getResponseErrorMessage(body, defaultMessage);
|
|
470
488
|
if (statusCode === 404 && docId) return new NotFoundError(docId, {
|
|
471
489
|
couchError,
|
|
472
|
-
|
|
490
|
+
couchReason,
|
|
491
|
+
message: notFoundMessage ? getResponseErrorMessage(body, notFoundMessage) : void 0,
|
|
473
492
|
operation,
|
|
474
493
|
statusCode
|
|
475
494
|
});
|
|
476
495
|
if (statusCode === 409 && docId) return new ConflictError(docId, {
|
|
477
496
|
couchError,
|
|
497
|
+
couchReason,
|
|
498
|
+
message,
|
|
478
499
|
operation,
|
|
479
500
|
statusCode
|
|
480
501
|
});
|
|
481
|
-
if (RetryableError.isRetryableStatusCode(statusCode)) return new RetryableError(
|
|
502
|
+
if (RetryableError.isRetryableStatusCode(statusCode)) return new RetryableError(message, statusCode, {
|
|
482
503
|
couchError,
|
|
504
|
+
couchReason,
|
|
483
505
|
operation
|
|
484
506
|
});
|
|
485
|
-
return new OperationError(
|
|
507
|
+
return new OperationError(message, {
|
|
486
508
|
couchError,
|
|
509
|
+
couchReason,
|
|
487
510
|
docId,
|
|
488
511
|
operation,
|
|
489
512
|
statusCode
|
|
@@ -584,32 +607,34 @@ const ViewRow = zod.z.object({
|
|
|
584
607
|
doc: CouchDoc.nullish(),
|
|
585
608
|
error: zod.z.string().optional().describe("usually not_found, if something is wrong with this doc")
|
|
586
609
|
});
|
|
610
|
+
const BulkSaveSuccessRow = zod.z.object({
|
|
611
|
+
ok: zod.z.literal(true).describe("successful bulk mutation rows always return ok=true"),
|
|
612
|
+
id: zod.z.string().nullish(),
|
|
613
|
+
rev: zod.z.string().nullish()
|
|
614
|
+
});
|
|
615
|
+
const BulkSaveFailureRow = zod.z.object({
|
|
616
|
+
id: zod.z.string().nullish(),
|
|
617
|
+
error: zod.z.string().nullish().describe("if an error occurred, one word reason, eg conflict"),
|
|
618
|
+
reason: zod.z.string().nullish().describe("a full error message")
|
|
619
|
+
});
|
|
587
620
|
/**
|
|
588
621
|
* Response type for a CouchDB view query if no validation schemas are provided.
|
|
589
622
|
*/
|
|
590
623
|
const ViewQueryResponse = zod.z.object({
|
|
591
624
|
total_rows: zod.z.number().nonnegative().optional().describe("total rows in the view"),
|
|
592
625
|
offset: zod.z.number().nonnegative().optional().describe("the offset of the first row in this result set"),
|
|
593
|
-
|
|
594
|
-
rows: zod.z.array(ViewRow).optional().describe("the rows returned by the view"),
|
|
626
|
+
rows: zod.z.array(ViewRow).describe("the rows returned by the view"),
|
|
595
627
|
update_seq: zod.z.number().optional().describe("the update sequence of the database at the time of the query")
|
|
596
628
|
});
|
|
597
629
|
/**
|
|
598
630
|
* CouchDB _bulk_docs response schema
|
|
599
631
|
*/
|
|
600
|
-
const BulkSaveResponse = zod.z.array(zod.z.
|
|
601
|
-
ok: zod.z.boolean().nullish(),
|
|
602
|
-
id: zod.z.string().nullish(),
|
|
603
|
-
rev: zod.z.string().nullish(),
|
|
604
|
-
error: zod.z.string().nullish().describe("if an error occurred, one word reason, eg conflict"),
|
|
605
|
-
reason: zod.z.string().nullish().describe("a full error message")
|
|
606
|
-
}));
|
|
632
|
+
const BulkSaveResponse = zod.z.array(zod.z.union([BulkSaveSuccessRow, BulkSaveFailureRow]));
|
|
607
633
|
const CouchPutResponse = zod.z.object({
|
|
608
|
-
ok: zod.z.
|
|
609
|
-
error: zod.z.string().optional().describe("the error message, if did not succeed"),
|
|
610
|
-
statusCode: zod.z.number(),
|
|
634
|
+
ok: zod.z.literal(true).describe("successful mutation responses always return ok=true"),
|
|
611
635
|
id: zod.z.string().optional().describe("the couch doc id"),
|
|
612
|
-
rev: zod.z.string().optional().describe("the new rev of the doc")
|
|
636
|
+
rev: zod.z.string().optional().describe("the new rev of the doc"),
|
|
637
|
+
statusCode: zod.z.number()
|
|
613
638
|
});
|
|
614
639
|
const CouchDBInfo = zod.z.looseObject({
|
|
615
640
|
cluster: zod.z.object({
|
|
@@ -1573,6 +1598,9 @@ const setupEmitter = (config) => {
|
|
|
1573
1598
|
|
|
1574
1599
|
//#endregion
|
|
1575
1600
|
//#region impl/utils/transactionErrors.mts
|
|
1601
|
+
const getFailedDocLabel = (doc) => {
|
|
1602
|
+
return `${doc.id ?? "<unknown id>"} (${doc.reason ?? doc.error ?? "unknown error"})`;
|
|
1603
|
+
};
|
|
1576
1604
|
var TransactionSetupError = class extends OperationError {
|
|
1577
1605
|
details;
|
|
1578
1606
|
constructor(message, details = {}) {
|
|
@@ -1592,7 +1620,7 @@ var TransactionVersionConflictError = class extends OperationError {
|
|
|
1592
1620
|
var TransactionBulkOperationError = class extends OperationError {
|
|
1593
1621
|
failedDocs;
|
|
1594
1622
|
constructor(failedDocs) {
|
|
1595
|
-
super(`Failed to save
|
|
1623
|
+
super(`Failed to save ${failedDocs.length} document${failedDocs.length === 1 ? "" : "s"}: ${failedDocs.map(getFailedDocLabel).join(", ")}`, { category: "transaction" });
|
|
1596
1624
|
this.name = "TransactionBulkOperationError";
|
|
1597
1625
|
this.failedDocs = failedDocs;
|
|
1598
1626
|
}
|
|
@@ -1610,6 +1638,12 @@ var TransactionRollbackError = class extends OperationError {
|
|
|
1610
1638
|
|
|
1611
1639
|
//#endregion
|
|
1612
1640
|
//#region impl/bulkSave.mts
|
|
1641
|
+
const isBulkSaveSuccess = (row) => {
|
|
1642
|
+
return "ok" in row && row.ok === true;
|
|
1643
|
+
};
|
|
1644
|
+
const isBulkSaveFailure = (row) => {
|
|
1645
|
+
return !isBulkSaveSuccess(row);
|
|
1646
|
+
};
|
|
1613
1647
|
/**
|
|
1614
1648
|
* Bulk saves documents to CouchDB using the _bulk_docs endpoint.
|
|
1615
1649
|
*
|
|
@@ -1649,17 +1683,13 @@ const bulkSave = async (config, docs) => {
|
|
|
1649
1683
|
}
|
|
1650
1684
|
if (!resp) {
|
|
1651
1685
|
logger.error("No response received from bulk save request");
|
|
1652
|
-
throw new RetryableError(
|
|
1653
|
-
}
|
|
1654
|
-
if (RetryableError.isRetryableStatusCode(resp.statusCode)) {
|
|
1655
|
-
logger.warn(`Retryable status code received: ${resp.statusCode}`);
|
|
1656
|
-
throw new RetryableError("Bulk save failed", resp.statusCode, { operation: "request" });
|
|
1686
|
+
throw new RetryableError(`Bulk save failed for ${docs.length} document${docs.length === 1 ? "" : "s"}`, 503, { operation: "request" });
|
|
1657
1687
|
}
|
|
1658
1688
|
if (!isSuccessStatusCode("bulkSave", resp.statusCode)) {
|
|
1659
1689
|
logger.error(`Unexpected status code: ${resp.statusCode}`);
|
|
1660
1690
|
throw createResponseError({
|
|
1661
1691
|
body: resp.body,
|
|
1662
|
-
defaultMessage:
|
|
1692
|
+
defaultMessage: `Bulk save failed for ${docs.length} document${docs.length === 1 ? "" : "s"}`,
|
|
1663
1693
|
operation: "request",
|
|
1664
1694
|
statusCode: resp.statusCode
|
|
1665
1695
|
});
|
|
@@ -1769,7 +1799,7 @@ const bulkSaveTransaction = async (config, transactionId, docs) => {
|
|
|
1769
1799
|
await emitter.emit("transaction-updates-applied", results);
|
|
1770
1800
|
results.forEach((r) => {
|
|
1771
1801
|
if (!r.id) return;
|
|
1772
|
-
if (
|
|
1802
|
+
if (isBulkSaveSuccess(r)) {
|
|
1773
1803
|
if (existingDocs.notFound[r.id]) newDocsToRollback.push(r);
|
|
1774
1804
|
if (existingDocs.found[r.id]) potentialExistingDocsToRollback.push(r);
|
|
1775
1805
|
} else failedDocs.push(r);
|
|
@@ -1789,12 +1819,14 @@ const bulkSaveTransaction = async (config, transactionId, docs) => {
|
|
|
1789
1819
|
logger.error("Transaction failed, attempting rollback:", error);
|
|
1790
1820
|
const toRollback = [];
|
|
1791
1821
|
potentialExistingDocsToRollback.forEach((row) => {
|
|
1822
|
+
if (!isBulkSaveSuccess(row)) return;
|
|
1792
1823
|
if (!row.id || !row.rev) return;
|
|
1793
1824
|
const doc = existingDocs.found[row.id];
|
|
1794
1825
|
doc._rev = row.rev;
|
|
1795
1826
|
toRollback.push(doc);
|
|
1796
1827
|
});
|
|
1797
1828
|
newDocsToRollback.forEach((d) => {
|
|
1829
|
+
if (!isBulkSaveSuccess(d)) return;
|
|
1798
1830
|
if (!d.id || !d.rev) return;
|
|
1799
1831
|
const before = JSON.parse(JSON.stringify(providedDocsById[d.id]));
|
|
1800
1832
|
before._rev = d.rev;
|
|
@@ -1804,7 +1836,7 @@ const bulkSaveTransaction = async (config, transactionId, docs) => {
|
|
|
1804
1836
|
const bulkRollbackResult = await bulkSave(config, toRollback);
|
|
1805
1837
|
let status = "rolled_back";
|
|
1806
1838
|
bulkRollbackResult.forEach((r) => {
|
|
1807
|
-
if (r
|
|
1839
|
+
if (isBulkSaveFailure(r)) status = "rollback_failed";
|
|
1808
1840
|
});
|
|
1809
1841
|
logger.warn("Transaction rolled back:", {
|
|
1810
1842
|
bulkRollbackResult,
|
package/dist/esm/index.mjs
CHANGED
|
@@ -235,6 +235,10 @@ const SUCCESS_STATUS_CODES = {
|
|
|
235
235
|
viewQuery: [200],
|
|
236
236
|
viewStream: [200]
|
|
237
237
|
};
|
|
238
|
+
const getReason = (value, fallback) => {
|
|
239
|
+
if (!isRecord(value) || typeof value.reason !== "string") return fallback;
|
|
240
|
+
return value.reason;
|
|
241
|
+
};
|
|
238
242
|
const getCouchError = (value) => {
|
|
239
243
|
if (!isRecord(value) || typeof value.error !== "string") return;
|
|
240
244
|
return value.error;
|
|
@@ -282,6 +286,7 @@ const getNestedNetworkError = (value) => {
|
|
|
282
286
|
var HideABedError = class extends Error {
|
|
283
287
|
category;
|
|
284
288
|
couchError;
|
|
289
|
+
couchReason;
|
|
285
290
|
docId;
|
|
286
291
|
operation;
|
|
287
292
|
retryable;
|
|
@@ -291,6 +296,7 @@ var HideABedError = class extends Error {
|
|
|
291
296
|
this.name = "HideABedError";
|
|
292
297
|
this.category = options.category;
|
|
293
298
|
this.couchError = options.couchError;
|
|
299
|
+
this.couchReason = options.couchReason;
|
|
294
300
|
this.docId = options.docId;
|
|
295
301
|
this.operation = options.operation;
|
|
296
302
|
this.retryable = options.retryable;
|
|
@@ -311,6 +317,7 @@ var NotFoundError = class extends HideABedError {
|
|
|
311
317
|
super(options.message ?? "Document not found", {
|
|
312
318
|
category: "not_found",
|
|
313
319
|
couchError: options.couchError ?? "not_found",
|
|
320
|
+
couchReason: options.couchReason,
|
|
314
321
|
cause: options.cause,
|
|
315
322
|
docId,
|
|
316
323
|
operation: options.operation,
|
|
@@ -330,6 +337,7 @@ var ConflictError = class extends HideABedError {
|
|
|
330
337
|
super(options.message ?? "Document update conflict", {
|
|
331
338
|
category: "conflict",
|
|
332
339
|
couchError: options.couchError ?? "conflict",
|
|
340
|
+
couchReason: options.couchReason,
|
|
333
341
|
cause: options.cause,
|
|
334
342
|
docId,
|
|
335
343
|
operation: options.operation,
|
|
@@ -350,6 +358,7 @@ var OperationError = class extends HideABedError {
|
|
|
350
358
|
category: options.category ?? "operation",
|
|
351
359
|
cause: options.cause,
|
|
352
360
|
couchError: options.couchError,
|
|
361
|
+
couchReason: options.couchReason,
|
|
353
362
|
docId: options.docId,
|
|
354
363
|
operation: options.operation,
|
|
355
364
|
retryable: false,
|
|
@@ -370,6 +379,7 @@ var ValidationError = class extends HideABedError {
|
|
|
370
379
|
category: "validation",
|
|
371
380
|
cause: options.cause,
|
|
372
381
|
couchError: options.couchError,
|
|
382
|
+
couchReason: options.couchReason,
|
|
373
383
|
docId: options.docId,
|
|
374
384
|
operation: options.operation,
|
|
375
385
|
retryable: false,
|
|
@@ -394,6 +404,7 @@ var RetryableError = class RetryableError extends HideABedError {
|
|
|
394
404
|
category: options.category ?? "retryable",
|
|
395
405
|
cause: options.cause,
|
|
396
406
|
couchError: options.couchError,
|
|
407
|
+
couchReason: options.couchReason,
|
|
397
408
|
docId: options.docId,
|
|
398
409
|
operation: options.operation,
|
|
399
410
|
retryable: true,
|
|
@@ -433,25 +444,37 @@ var RetryableError = class RetryableError extends HideABedError {
|
|
|
433
444
|
throw err;
|
|
434
445
|
}
|
|
435
446
|
};
|
|
447
|
+
const getResponseErrorMessage = (body, defaultMessage) => {
|
|
448
|
+
const reason = getReason(body, "").trim();
|
|
449
|
+
if (!reason || reason === defaultMessage) return defaultMessage;
|
|
450
|
+
return `${defaultMessage}: ${reason}`;
|
|
451
|
+
};
|
|
436
452
|
function createResponseError({ body, defaultMessage, docId, notFoundMessage, operation, statusCode }) {
|
|
437
453
|
const couchError = getCouchError(body);
|
|
454
|
+
const couchReason = getReason(body, "").trim() || void 0;
|
|
455
|
+
const message = getResponseErrorMessage(body, defaultMessage);
|
|
438
456
|
if (statusCode === 404 && docId) return new NotFoundError(docId, {
|
|
439
457
|
couchError,
|
|
440
|
-
|
|
458
|
+
couchReason,
|
|
459
|
+
message: notFoundMessage ? getResponseErrorMessage(body, notFoundMessage) : void 0,
|
|
441
460
|
operation,
|
|
442
461
|
statusCode
|
|
443
462
|
});
|
|
444
463
|
if (statusCode === 409 && docId) return new ConflictError(docId, {
|
|
445
464
|
couchError,
|
|
465
|
+
couchReason,
|
|
466
|
+
message,
|
|
446
467
|
operation,
|
|
447
468
|
statusCode
|
|
448
469
|
});
|
|
449
|
-
if (RetryableError.isRetryableStatusCode(statusCode)) return new RetryableError(
|
|
470
|
+
if (RetryableError.isRetryableStatusCode(statusCode)) return new RetryableError(message, statusCode, {
|
|
450
471
|
couchError,
|
|
472
|
+
couchReason,
|
|
451
473
|
operation
|
|
452
474
|
});
|
|
453
|
-
return new OperationError(
|
|
475
|
+
return new OperationError(message, {
|
|
454
476
|
couchError,
|
|
477
|
+
couchReason,
|
|
455
478
|
docId,
|
|
456
479
|
operation,
|
|
457
480
|
statusCode
|
|
@@ -552,32 +575,34 @@ const ViewRow = z$1.object({
|
|
|
552
575
|
doc: CouchDoc.nullish(),
|
|
553
576
|
error: z$1.string().optional().describe("usually not_found, if something is wrong with this doc")
|
|
554
577
|
});
|
|
578
|
+
const BulkSaveSuccessRow = z$1.object({
|
|
579
|
+
ok: z$1.literal(true).describe("successful bulk mutation rows always return ok=true"),
|
|
580
|
+
id: z$1.string().nullish(),
|
|
581
|
+
rev: z$1.string().nullish()
|
|
582
|
+
});
|
|
583
|
+
const BulkSaveFailureRow = z$1.object({
|
|
584
|
+
id: z$1.string().nullish(),
|
|
585
|
+
error: z$1.string().nullish().describe("if an error occurred, one word reason, eg conflict"),
|
|
586
|
+
reason: z$1.string().nullish().describe("a full error message")
|
|
587
|
+
});
|
|
555
588
|
/**
|
|
556
589
|
* Response type for a CouchDB view query if no validation schemas are provided.
|
|
557
590
|
*/
|
|
558
591
|
const ViewQueryResponse = z$1.object({
|
|
559
592
|
total_rows: z$1.number().nonnegative().optional().describe("total rows in the view"),
|
|
560
593
|
offset: z$1.number().nonnegative().optional().describe("the offset of the first row in this result set"),
|
|
561
|
-
|
|
562
|
-
rows: z$1.array(ViewRow).optional().describe("the rows returned by the view"),
|
|
594
|
+
rows: z$1.array(ViewRow).describe("the rows returned by the view"),
|
|
563
595
|
update_seq: z$1.number().optional().describe("the update sequence of the database at the time of the query")
|
|
564
596
|
});
|
|
565
597
|
/**
|
|
566
598
|
* CouchDB _bulk_docs response schema
|
|
567
599
|
*/
|
|
568
|
-
const BulkSaveResponse = z$1.array(z$1.
|
|
569
|
-
ok: z$1.boolean().nullish(),
|
|
570
|
-
id: z$1.string().nullish(),
|
|
571
|
-
rev: z$1.string().nullish(),
|
|
572
|
-
error: z$1.string().nullish().describe("if an error occurred, one word reason, eg conflict"),
|
|
573
|
-
reason: z$1.string().nullish().describe("a full error message")
|
|
574
|
-
}));
|
|
600
|
+
const BulkSaveResponse = z$1.array(z$1.union([BulkSaveSuccessRow, BulkSaveFailureRow]));
|
|
575
601
|
const CouchPutResponse = z$1.object({
|
|
576
|
-
ok: z$1.
|
|
577
|
-
error: z$1.string().optional().describe("the error message, if did not succeed"),
|
|
578
|
-
statusCode: z$1.number(),
|
|
602
|
+
ok: z$1.literal(true).describe("successful mutation responses always return ok=true"),
|
|
579
603
|
id: z$1.string().optional().describe("the couch doc id"),
|
|
580
|
-
rev: z$1.string().optional().describe("the new rev of the doc")
|
|
604
|
+
rev: z$1.string().optional().describe("the new rev of the doc"),
|
|
605
|
+
statusCode: z$1.number()
|
|
581
606
|
});
|
|
582
607
|
const CouchDBInfo = z$1.looseObject({
|
|
583
608
|
cluster: z$1.object({
|
|
@@ -1541,6 +1566,9 @@ const setupEmitter = (config) => {
|
|
|
1541
1566
|
|
|
1542
1567
|
//#endregion
|
|
1543
1568
|
//#region impl/utils/transactionErrors.mts
|
|
1569
|
+
const getFailedDocLabel = (doc) => {
|
|
1570
|
+
return `${doc.id ?? "<unknown id>"} (${doc.reason ?? doc.error ?? "unknown error"})`;
|
|
1571
|
+
};
|
|
1544
1572
|
var TransactionSetupError = class extends OperationError {
|
|
1545
1573
|
details;
|
|
1546
1574
|
constructor(message, details = {}) {
|
|
@@ -1560,7 +1588,7 @@ var TransactionVersionConflictError = class extends OperationError {
|
|
|
1560
1588
|
var TransactionBulkOperationError = class extends OperationError {
|
|
1561
1589
|
failedDocs;
|
|
1562
1590
|
constructor(failedDocs) {
|
|
1563
|
-
super(`Failed to save
|
|
1591
|
+
super(`Failed to save ${failedDocs.length} document${failedDocs.length === 1 ? "" : "s"}: ${failedDocs.map(getFailedDocLabel).join(", ")}`, { category: "transaction" });
|
|
1564
1592
|
this.name = "TransactionBulkOperationError";
|
|
1565
1593
|
this.failedDocs = failedDocs;
|
|
1566
1594
|
}
|
|
@@ -1578,6 +1606,12 @@ var TransactionRollbackError = class extends OperationError {
|
|
|
1578
1606
|
|
|
1579
1607
|
//#endregion
|
|
1580
1608
|
//#region impl/bulkSave.mts
|
|
1609
|
+
const isBulkSaveSuccess = (row) => {
|
|
1610
|
+
return "ok" in row && row.ok === true;
|
|
1611
|
+
};
|
|
1612
|
+
const isBulkSaveFailure = (row) => {
|
|
1613
|
+
return !isBulkSaveSuccess(row);
|
|
1614
|
+
};
|
|
1581
1615
|
/**
|
|
1582
1616
|
* Bulk saves documents to CouchDB using the _bulk_docs endpoint.
|
|
1583
1617
|
*
|
|
@@ -1617,17 +1651,13 @@ const bulkSave = async (config, docs) => {
|
|
|
1617
1651
|
}
|
|
1618
1652
|
if (!resp) {
|
|
1619
1653
|
logger.error("No response received from bulk save request");
|
|
1620
|
-
throw new RetryableError(
|
|
1621
|
-
}
|
|
1622
|
-
if (RetryableError.isRetryableStatusCode(resp.statusCode)) {
|
|
1623
|
-
logger.warn(`Retryable status code received: ${resp.statusCode}`);
|
|
1624
|
-
throw new RetryableError("Bulk save failed", resp.statusCode, { operation: "request" });
|
|
1654
|
+
throw new RetryableError(`Bulk save failed for ${docs.length} document${docs.length === 1 ? "" : "s"}`, 503, { operation: "request" });
|
|
1625
1655
|
}
|
|
1626
1656
|
if (!isSuccessStatusCode("bulkSave", resp.statusCode)) {
|
|
1627
1657
|
logger.error(`Unexpected status code: ${resp.statusCode}`);
|
|
1628
1658
|
throw createResponseError({
|
|
1629
1659
|
body: resp.body,
|
|
1630
|
-
defaultMessage:
|
|
1660
|
+
defaultMessage: `Bulk save failed for ${docs.length} document${docs.length === 1 ? "" : "s"}`,
|
|
1631
1661
|
operation: "request",
|
|
1632
1662
|
statusCode: resp.statusCode
|
|
1633
1663
|
});
|
|
@@ -1737,7 +1767,7 @@ const bulkSaveTransaction = async (config, transactionId, docs) => {
|
|
|
1737
1767
|
await emitter.emit("transaction-updates-applied", results);
|
|
1738
1768
|
results.forEach((r) => {
|
|
1739
1769
|
if (!r.id) return;
|
|
1740
|
-
if (
|
|
1770
|
+
if (isBulkSaveSuccess(r)) {
|
|
1741
1771
|
if (existingDocs.notFound[r.id]) newDocsToRollback.push(r);
|
|
1742
1772
|
if (existingDocs.found[r.id]) potentialExistingDocsToRollback.push(r);
|
|
1743
1773
|
} else failedDocs.push(r);
|
|
@@ -1757,12 +1787,14 @@ const bulkSaveTransaction = async (config, transactionId, docs) => {
|
|
|
1757
1787
|
logger.error("Transaction failed, attempting rollback:", error);
|
|
1758
1788
|
const toRollback = [];
|
|
1759
1789
|
potentialExistingDocsToRollback.forEach((row) => {
|
|
1790
|
+
if (!isBulkSaveSuccess(row)) return;
|
|
1760
1791
|
if (!row.id || !row.rev) return;
|
|
1761
1792
|
const doc = existingDocs.found[row.id];
|
|
1762
1793
|
doc._rev = row.rev;
|
|
1763
1794
|
toRollback.push(doc);
|
|
1764
1795
|
});
|
|
1765
1796
|
newDocsToRollback.forEach((d) => {
|
|
1797
|
+
if (!isBulkSaveSuccess(d)) return;
|
|
1766
1798
|
if (!d.id || !d.rev) return;
|
|
1767
1799
|
const before = JSON.parse(JSON.stringify(providedDocsById[d.id]));
|
|
1768
1800
|
before._rev = d.rev;
|
|
@@ -1772,7 +1804,7 @@ const bulkSaveTransaction = async (config, transactionId, docs) => {
|
|
|
1772
1804
|
const bulkRollbackResult = await bulkSave(config, toRollback);
|
|
1773
1805
|
let status = "rolled_back";
|
|
1774
1806
|
bulkRollbackResult.forEach((r) => {
|
|
1775
|
-
if (r
|
|
1807
|
+
if (isBulkSaveFailure(r)) status = "rollback_failed";
|
|
1776
1808
|
});
|
|
1777
1809
|
logger.warn("Transaction rolled back:", {
|
|
1778
1810
|
bulkRollbackResult,
|
package/impl/bulkSave.mts
CHANGED
|
@@ -25,6 +25,18 @@ import { fetchCouchJson } from './utils/fetch.mts'
|
|
|
25
25
|
import { isSuccessStatusCode } from './utils/response.mts'
|
|
26
26
|
import { createCouchPathUrl } from './utils/url.mts'
|
|
27
27
|
|
|
28
|
+
type BulkSaveRow = BulkSaveResponse[number]
|
|
29
|
+
type BulkSaveSuccessRow = Extract<BulkSaveRow, { ok: true }>
|
|
30
|
+
type BulkSaveFailureRow = Exclude<BulkSaveRow, BulkSaveSuccessRow>
|
|
31
|
+
|
|
32
|
+
const isBulkSaveSuccess = (row: BulkSaveRow): row is BulkSaveSuccessRow => {
|
|
33
|
+
return 'ok' in row && row.ok === true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const isBulkSaveFailure = (row: BulkSaveRow): row is BulkSaveFailureRow => {
|
|
37
|
+
return !isBulkSaveSuccess(row)
|
|
38
|
+
}
|
|
39
|
+
|
|
28
40
|
/**
|
|
29
41
|
* Bulk saves documents to CouchDB using the _bulk_docs endpoint.
|
|
30
42
|
*
|
|
@@ -68,19 +80,17 @@ export const bulkSave = async (config: CouchConfigInput, docs: CouchDocInput[])
|
|
|
68
80
|
}
|
|
69
81
|
if (!resp) {
|
|
70
82
|
logger.error('No response received from bulk save request')
|
|
71
|
-
throw new RetryableError(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
operation: 'request'
|
|
77
|
-
})
|
|
83
|
+
throw new RetryableError(
|
|
84
|
+
`Bulk save failed for ${docs.length} document${docs.length === 1 ? '' : 's'}`,
|
|
85
|
+
503,
|
|
86
|
+
{ operation: 'request' }
|
|
87
|
+
)
|
|
78
88
|
}
|
|
79
89
|
if (!isSuccessStatusCode('bulkSave', resp.statusCode)) {
|
|
80
90
|
logger.error(`Unexpected status code: ${resp.statusCode}`)
|
|
81
91
|
throw createResponseError({
|
|
82
92
|
body: resp.body,
|
|
83
|
-
defaultMessage:
|
|
93
|
+
defaultMessage: `Bulk save failed for ${docs.length} document${docs.length === 1 ? '' : 's'}`,
|
|
84
94
|
operation: 'request',
|
|
85
95
|
statusCode: resp.statusCode
|
|
86
96
|
})
|
|
@@ -231,7 +241,7 @@ export const bulkSaveTransaction = async (
|
|
|
231
241
|
// Check for failures
|
|
232
242
|
results.forEach(r => {
|
|
233
243
|
if (!r.id) return // not enough info
|
|
234
|
-
if (
|
|
244
|
+
if (isBulkSaveSuccess(r)) {
|
|
235
245
|
if (existingDocs.notFound[r.id]) newDocsToRollback.push(r)
|
|
236
246
|
if (existingDocs.found[r.id]) potentialExistingDocsToRollback.push(r)
|
|
237
247
|
} else {
|
|
@@ -262,12 +272,14 @@ export const bulkSaveTransaction = async (
|
|
|
262
272
|
// Rollback changes
|
|
263
273
|
const toRollback: CouchDoc[] = []
|
|
264
274
|
potentialExistingDocsToRollback.forEach(row => {
|
|
275
|
+
if (!isBulkSaveSuccess(row)) return
|
|
265
276
|
if (!row.id || !row.rev) return
|
|
266
277
|
const doc = existingDocs.found[row.id]
|
|
267
278
|
doc._rev = row.rev
|
|
268
279
|
toRollback.push(doc)
|
|
269
280
|
})
|
|
270
281
|
newDocsToRollback.forEach(d => {
|
|
282
|
+
if (!isBulkSaveSuccess(d)) return
|
|
271
283
|
if (!d.id || !d.rev) return
|
|
272
284
|
const before = JSON.parse(JSON.stringify(providedDocsById[d.id]))
|
|
273
285
|
before._rev = d.rev
|
|
@@ -279,7 +291,7 @@ export const bulkSaveTransaction = async (
|
|
|
279
291
|
const bulkRollbackResult = await bulkSave(config, toRollback)
|
|
280
292
|
let status: TransactionStatus = 'rolled_back'
|
|
281
293
|
bulkRollbackResult.forEach(r => {
|
|
282
|
-
if (r
|
|
294
|
+
if (isBulkSaveFailure(r)) status = 'rollback_failed'
|
|
283
295
|
})
|
|
284
296
|
logger.warn('Transaction rolled back:', { bulkRollbackResult, status })
|
|
285
297
|
await emitter.emit('transaction-rolled-back', {
|
package/impl/utils/errors.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCouchError } from './response.mts'
|
|
1
|
+
import { getCouchError, getReason } from './response.mts'
|
|
2
2
|
import type { StandardSchemaV1 } from '../../types/standard-schema.ts'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -89,6 +89,7 @@ export type HideABedErrorOptions = {
|
|
|
89
89
|
category: ErrorCategory
|
|
90
90
|
cause?: unknown
|
|
91
91
|
couchError?: string
|
|
92
|
+
couchReason?: string
|
|
92
93
|
docId?: string
|
|
93
94
|
operation?: ErrorOperation
|
|
94
95
|
retryable: boolean
|
|
@@ -103,6 +104,7 @@ export type HideABedErrorOptions = {
|
|
|
103
104
|
export class HideABedError extends Error {
|
|
104
105
|
readonly category: ErrorCategory
|
|
105
106
|
readonly couchError?: string
|
|
107
|
+
readonly couchReason?: string
|
|
106
108
|
readonly docId?: string
|
|
107
109
|
readonly operation?: ErrorOperation
|
|
108
110
|
readonly retryable: boolean
|
|
@@ -113,6 +115,7 @@ export class HideABedError extends Error {
|
|
|
113
115
|
this.name = 'HideABedError'
|
|
114
116
|
this.category = options.category
|
|
115
117
|
this.couchError = options.couchError
|
|
118
|
+
this.couchReason = options.couchReason
|
|
116
119
|
this.docId = options.docId
|
|
117
120
|
this.operation = options.operation
|
|
118
121
|
this.retryable = options.retryable
|
|
@@ -147,6 +150,7 @@ export class NotFoundError extends HideABedError {
|
|
|
147
150
|
super(options.message ?? 'Document not found', {
|
|
148
151
|
category: 'not_found',
|
|
149
152
|
couchError: options.couchError ?? 'not_found',
|
|
153
|
+
couchReason: options.couchReason,
|
|
150
154
|
cause: options.cause,
|
|
151
155
|
docId,
|
|
152
156
|
operation: options.operation,
|
|
@@ -172,6 +176,7 @@ export class ConflictError extends HideABedError {
|
|
|
172
176
|
super(options.message ?? 'Document update conflict', {
|
|
173
177
|
category: 'conflict',
|
|
174
178
|
couchError: options.couchError ?? 'conflict',
|
|
179
|
+
couchReason: options.couchReason,
|
|
175
180
|
cause: options.cause,
|
|
176
181
|
docId,
|
|
177
182
|
operation: options.operation,
|
|
@@ -198,6 +203,7 @@ export class OperationError extends HideABedError {
|
|
|
198
203
|
category: options.category ?? 'operation',
|
|
199
204
|
cause: options.cause,
|
|
200
205
|
couchError: options.couchError,
|
|
206
|
+
couchReason: options.couchReason,
|
|
201
207
|
docId: options.docId,
|
|
202
208
|
operation: options.operation,
|
|
203
209
|
retryable: false,
|
|
@@ -220,6 +226,7 @@ export class ValidationError extends HideABedError {
|
|
|
220
226
|
category: 'validation',
|
|
221
227
|
cause: options.cause,
|
|
222
228
|
couchError: options.couchError,
|
|
229
|
+
couchReason: options.couchReason,
|
|
223
230
|
docId: options.docId,
|
|
224
231
|
operation: options.operation,
|
|
225
232
|
retryable: false,
|
|
@@ -251,6 +258,7 @@ export class RetryableError extends HideABedError {
|
|
|
251
258
|
category: options.category ?? 'retryable',
|
|
252
259
|
cause: options.cause,
|
|
253
260
|
couchError: options.couchError,
|
|
261
|
+
couchReason: options.couchReason,
|
|
254
262
|
docId: options.docId,
|
|
255
263
|
operation: options.operation,
|
|
256
264
|
retryable: true,
|
|
@@ -306,6 +314,16 @@ type ResponseErrorOptions = {
|
|
|
306
314
|
statusCode?: number
|
|
307
315
|
}
|
|
308
316
|
|
|
317
|
+
const getResponseErrorMessage = (body: unknown, defaultMessage: string) => {
|
|
318
|
+
const reason = getReason(body, '').trim()
|
|
319
|
+
|
|
320
|
+
if (!reason || reason === defaultMessage) {
|
|
321
|
+
return defaultMessage
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return `${defaultMessage}: ${reason}`
|
|
325
|
+
}
|
|
326
|
+
|
|
309
327
|
export function createResponseError({
|
|
310
328
|
body,
|
|
311
329
|
defaultMessage,
|
|
@@ -315,11 +333,14 @@ export function createResponseError({
|
|
|
315
333
|
statusCode
|
|
316
334
|
}: ResponseErrorOptions): HideABedError {
|
|
317
335
|
const couchError = getCouchError(body)
|
|
336
|
+
const couchReason = getReason(body, '').trim() || undefined
|
|
337
|
+
const message = getResponseErrorMessage(body, defaultMessage)
|
|
318
338
|
|
|
319
339
|
if (statusCode === 404 && docId) {
|
|
320
340
|
return new NotFoundError(docId, {
|
|
321
341
|
couchError,
|
|
322
|
-
|
|
342
|
+
couchReason,
|
|
343
|
+
message: notFoundMessage ? getResponseErrorMessage(body, notFoundMessage) : undefined,
|
|
323
344
|
operation,
|
|
324
345
|
statusCode
|
|
325
346
|
})
|
|
@@ -328,20 +349,24 @@ export function createResponseError({
|
|
|
328
349
|
if (statusCode === 409 && docId) {
|
|
329
350
|
return new ConflictError(docId, {
|
|
330
351
|
couchError,
|
|
352
|
+
couchReason,
|
|
353
|
+
message,
|
|
331
354
|
operation,
|
|
332
355
|
statusCode
|
|
333
356
|
})
|
|
334
357
|
}
|
|
335
358
|
|
|
336
359
|
if (RetryableError.isRetryableStatusCode(statusCode)) {
|
|
337
|
-
return new RetryableError(
|
|
360
|
+
return new RetryableError(message, statusCode, {
|
|
338
361
|
couchError,
|
|
362
|
+
couchReason,
|
|
339
363
|
operation
|
|
340
364
|
})
|
|
341
365
|
}
|
|
342
366
|
|
|
343
|
-
return new OperationError(
|
|
367
|
+
return new OperationError(message, {
|
|
344
368
|
couchError,
|
|
369
|
+
couchReason,
|
|
345
370
|
docId,
|
|
346
371
|
operation,
|
|
347
372
|
statusCode
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
+
import type z from 'zod'
|
|
2
|
+
import type { BulkSaveFailureRow } from '../../schema/couch/couch.output.schema.ts'
|
|
1
3
|
import { OperationError } from './errors.mts'
|
|
2
4
|
|
|
5
|
+
type FailedDoc = z.infer<typeof BulkSaveFailureRow>
|
|
6
|
+
|
|
7
|
+
const getFailedDocLabel = (doc: FailedDoc) => {
|
|
8
|
+
const id = doc.id ?? '<unknown id>'
|
|
9
|
+
const detail = doc.reason ?? doc.error ?? 'unknown error'
|
|
10
|
+
|
|
11
|
+
return `${id} (${detail})`
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
export class TransactionSetupError extends OperationError {
|
|
4
15
|
details: Record<string, unknown>
|
|
5
16
|
|
|
@@ -23,26 +34,15 @@ export class TransactionVersionConflictError extends OperationError {
|
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
export class TransactionBulkOperationError extends OperationError {
|
|
26
|
-
failedDocs:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
failedDocs: Array<{
|
|
36
|
-
ok?: boolean | null
|
|
37
|
-
id?: string | null
|
|
38
|
-
rev?: string | null
|
|
39
|
-
error?: string | null
|
|
40
|
-
reason?: string | null
|
|
41
|
-
}>
|
|
42
|
-
) {
|
|
43
|
-
super(`Failed to save documents: ${failedDocs.map(d => d.id).join(', ')}`, {
|
|
44
|
-
category: 'transaction'
|
|
45
|
-
})
|
|
37
|
+
failedDocs: FailedDoc[]
|
|
38
|
+
|
|
39
|
+
constructor(failedDocs: FailedDoc[]) {
|
|
40
|
+
super(
|
|
41
|
+
`Failed to save ${failedDocs.length} document${failedDocs.length === 1 ? '' : 's'}: ${failedDocs.map(getFailedDocLabel).join(', ')}`,
|
|
42
|
+
{
|
|
43
|
+
category: 'transaction'
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
46
|
this.name = 'TransactionBulkOperationError'
|
|
47
47
|
this.failedDocs = failedDocs
|
|
48
48
|
}
|
|
@@ -50,25 +50,9 @@ export class TransactionBulkOperationError extends OperationError {
|
|
|
50
50
|
|
|
51
51
|
export class TransactionRollbackError extends OperationError {
|
|
52
52
|
originalError: Error
|
|
53
|
-
rollbackResults:
|
|
54
|
-
ok?: boolean | null
|
|
55
|
-
id?: string | null
|
|
56
|
-
rev?: string | null
|
|
57
|
-
error?: string | null
|
|
58
|
-
reason?: string | null
|
|
59
|
-
}[]
|
|
53
|
+
rollbackResults: FailedDoc[]
|
|
60
54
|
|
|
61
|
-
constructor(
|
|
62
|
-
message: string,
|
|
63
|
-
originalError: Error,
|
|
64
|
-
rollbackResults: Array<{
|
|
65
|
-
ok?: boolean | null
|
|
66
|
-
id?: string | null
|
|
67
|
-
rev?: string | null
|
|
68
|
-
error?: string | null
|
|
69
|
-
reason?: string | null
|
|
70
|
-
}>
|
|
71
|
-
) {
|
|
55
|
+
constructor(message: string, originalError: Error, rollbackResults: FailedDoc[]) {
|
|
72
56
|
super(message, { category: 'transaction' })
|
|
73
57
|
this.name = 'TransactionRollbackError'
|
|
74
58
|
this.originalError = originalError
|
package/package.json
CHANGED
|
@@ -28,6 +28,18 @@ export const ViewRow = z.object({
|
|
|
28
28
|
})
|
|
29
29
|
export type ViewRow = StandardSchemaV1.InferOutput<typeof ViewRow>
|
|
30
30
|
|
|
31
|
+
export const BulkSaveSuccessRow = z.object({
|
|
32
|
+
ok: z.literal(true).describe('successful bulk mutation rows always return ok=true'),
|
|
33
|
+
id: z.string().nullish(),
|
|
34
|
+
rev: z.string().nullish()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
export const BulkSaveFailureRow = z.object({
|
|
38
|
+
id: z.string().nullish(),
|
|
39
|
+
error: z.string().nullish().describe('if an error occurred, one word reason, eg conflict'),
|
|
40
|
+
reason: z.string().nullish().describe('a full error message')
|
|
41
|
+
})
|
|
42
|
+
|
|
31
43
|
/**
|
|
32
44
|
* A CouchDB view row with validated key, value, and document schemas.
|
|
33
45
|
*/
|
|
@@ -53,8 +65,7 @@ export const ViewQueryResponse = z.object({
|
|
|
53
65
|
.nonnegative()
|
|
54
66
|
.optional()
|
|
55
67
|
.describe('the offset of the first row in this result set'),
|
|
56
|
-
|
|
57
|
-
rows: z.array(ViewRow).optional().describe('the rows returned by the view'),
|
|
68
|
+
rows: z.array(ViewRow).describe('the rows returned by the view'),
|
|
58
69
|
update_seq: z
|
|
59
70
|
.number()
|
|
60
71
|
.optional()
|
|
@@ -76,23 +87,14 @@ export type ViewQueryResponseValidated<
|
|
|
76
87
|
/**
|
|
77
88
|
* CouchDB _bulk_docs response schema
|
|
78
89
|
*/
|
|
79
|
-
export const BulkSaveResponse = z.array(
|
|
80
|
-
z.object({
|
|
81
|
-
ok: z.boolean().nullish(),
|
|
82
|
-
id: z.string().nullish(),
|
|
83
|
-
rev: z.string().nullish(),
|
|
84
|
-
error: z.string().nullish().describe('if an error occurred, one word reason, eg conflict'),
|
|
85
|
-
reason: z.string().nullish().describe('a full error message')
|
|
86
|
-
})
|
|
87
|
-
)
|
|
90
|
+
export const BulkSaveResponse = z.array(z.union([BulkSaveSuccessRow, BulkSaveFailureRow]))
|
|
88
91
|
export type BulkSaveResponse = z.infer<typeof BulkSaveResponse>
|
|
89
92
|
|
|
90
93
|
export const CouchPutResponse = z.object({
|
|
91
|
-
ok: z.
|
|
92
|
-
error: z.string().optional().describe('the error message, if did not succeed'),
|
|
93
|
-
statusCode: z.number(),
|
|
94
|
+
ok: z.literal(true).describe('successful mutation responses always return ok=true'),
|
|
94
95
|
id: z.string().optional().describe('the couch doc id'),
|
|
95
|
-
rev: z.string().optional().describe('the new rev of the doc')
|
|
96
|
+
rev: z.string().optional().describe('the new rev of the doc'),
|
|
97
|
+
statusCode: z.number()
|
|
96
98
|
})
|
|
97
99
|
|
|
98
100
|
export const CouchDBInfo = z.looseObject({
|
|
@@ -24,13 +24,15 @@ import { type CouchConfigInput } from '../schema/config.mts';
|
|
|
24
24
|
* @throws {RetryableError} When the bulk request fails with a retryable transport or HTTP error.
|
|
25
25
|
* @throws {OperationError} When CouchDB returns a non-retryable request-level failure.
|
|
26
26
|
*/
|
|
27
|
-
export declare const bulkRemove: (configInput: CouchConfigInput, ids: string[]) => Promise<{
|
|
28
|
-
ok
|
|
27
|
+
export declare const bulkRemove: (configInput: CouchConfigInput, ids: string[]) => Promise<({
|
|
28
|
+
ok: true;
|
|
29
29
|
id?: string | null | undefined;
|
|
30
30
|
rev?: string | null | undefined;
|
|
31
|
+
} | {
|
|
32
|
+
id?: string | null | undefined;
|
|
31
33
|
error?: string | null | undefined;
|
|
32
34
|
reason?: string | null | undefined;
|
|
33
|
-
}[]>;
|
|
35
|
+
})[]>;
|
|
34
36
|
/**
|
|
35
37
|
* Removes multiple documents from a CouchDB database by their IDs using individual delete operations.
|
|
36
38
|
* It first retrieves the documents to get their revision IDs, then deletes each document one by one.
|
|
@@ -56,9 +58,8 @@ export declare const bulkRemove: (configInput: CouchConfigInput, ids: string[])
|
|
|
56
58
|
* @throws {OperationError} When a request fails in a non-retryable way.
|
|
57
59
|
*/
|
|
58
60
|
export declare const bulkRemoveMap: (configInput: CouchConfigInput, ids: string[]) => Promise<{
|
|
61
|
+
ok: true;
|
|
59
62
|
statusCode: number;
|
|
60
|
-
ok?: boolean | undefined;
|
|
61
|
-
error?: string | undefined;
|
|
62
63
|
id?: string | undefined;
|
|
63
64
|
rev?: string | undefined;
|
|
64
65
|
}[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulkRemove.d.mts","sourceRoot":"","sources":["../../../impl/bulkRemove.mts"],"names":[],"mappings":"AAKA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,GAAU,aAAa,gBAAgB,EAAE,KAAK,MAAM,EAAE
|
|
1
|
+
{"version":3,"file":"bulkRemove.d.mts","sourceRoot":"","sources":["../../../impl/bulkRemove.mts"],"names":[],"mappings":"AAKA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,GAAU,aAAa,gBAAgB,EAAE,KAAK,MAAM,EAAE;;;;;;;;KAmB5E,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,aAAa,GAAU,aAAa,gBAAgB,EAAE,KAAK,MAAM,EAAE;;;;;IAsB/E,CAAA"}
|
|
@@ -13,13 +13,15 @@ import { type CouchConfigInput } from '../schema/config.mts';
|
|
|
13
13
|
* @throws {RetryableError} When a retryable HTTP status code is encountered or no response is received.
|
|
14
14
|
* @throws {OperationError} When bulk save input is invalid or CouchDB returns a non-retryable request-level failure.
|
|
15
15
|
*/
|
|
16
|
-
export declare const bulkSave: (config: CouchConfigInput, docs: CouchDocInput[]) => Promise<{
|
|
17
|
-
ok
|
|
16
|
+
export declare const bulkSave: (config: CouchConfigInput, docs: CouchDocInput[]) => Promise<({
|
|
17
|
+
ok: true;
|
|
18
18
|
id?: string | null | undefined;
|
|
19
19
|
rev?: string | null | undefined;
|
|
20
|
+
} | {
|
|
21
|
+
id?: string | null | undefined;
|
|
20
22
|
error?: string | null | undefined;
|
|
21
23
|
reason?: string | null | undefined;
|
|
22
|
-
}[]>;
|
|
24
|
+
})[]>;
|
|
23
25
|
/**
|
|
24
26
|
* Performs a bulk save of documents within a transaction context.
|
|
25
27
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulkSave.d.mts","sourceRoot":"","sources":["../../../impl/bulkSave.mts"],"names":[],"mappings":"AASA,OAAO,EACL,gBAAgB,EAEhB,KAAK,aAAa,EACnB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"bulkSave.d.mts","sourceRoot":"","sources":["../../../impl/bulkSave.mts"],"names":[],"mappings":"AASA,OAAO,EACL,gBAAgB,EAEhB,KAAK,aAAa,EACnB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAyBzE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,GAAU,QAAQ,gBAAgB,EAAE,MAAM,aAAa,EAAE;;;;;;;;KA+C7E,CAAA;AAYD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,gBAAgB,EACxB,eAAe,MAAM,EACrB,MAAM,aAAa,EAAE,KACpB,OAAO,CAAC,gBAAgB,CAoK1B,CAAA"}
|
|
@@ -18,9 +18,8 @@ declare const PatchProperties: z.ZodObject<{
|
|
|
18
18
|
* @throws {OperationError} When a non-retryable operational failure occurs.
|
|
19
19
|
*/
|
|
20
20
|
export declare const patch: (configInput: CouchConfigInput, id: string, _properties: z.infer<typeof PatchProperties>) => Promise<{
|
|
21
|
+
ok: true;
|
|
21
22
|
statusCode: number;
|
|
22
|
-
ok?: boolean | undefined;
|
|
23
|
-
error?: string | undefined;
|
|
24
23
|
id?: string | undefined;
|
|
25
24
|
rev?: string | undefined;
|
|
26
25
|
}>;
|
|
@@ -40,9 +39,8 @@ export declare const patch: (configInput: CouchConfigInput, id: string, _propert
|
|
|
40
39
|
* @throws {OperationError} When retries are exhausted or a non-retryable operational failure occurs.
|
|
41
40
|
*/
|
|
42
41
|
export declare const patchDangerously: (configInput: CouchConfigInput, id: string, properties: Record<string, unknown>) => Promise<{
|
|
42
|
+
ok: true;
|
|
43
43
|
statusCode: number;
|
|
44
|
-
ok?: boolean | undefined;
|
|
45
|
-
error?: string | undefined;
|
|
46
44
|
id?: string | undefined;
|
|
47
45
|
rev?: string | undefined;
|
|
48
46
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.d.mts","sourceRoot":"","sources":["../../../impl/patch.mts"],"names":[],"mappings":"AAIA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,QAAA,MAAM,eAAe;;iBAIiB,CAAA;AAEtC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,GAChB,aAAa,gBAAgB,EAC7B,IAAI,MAAM,EACV,aAAa,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC
|
|
1
|
+
{"version":3,"file":"patch.d.mts","sourceRoot":"","sources":["../../../impl/patch.mts"],"names":[],"mappings":"AAIA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,QAAA,MAAM,eAAe;;iBAIiB,CAAA;AAEtC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,GAChB,aAAa,gBAAgB,EAC7B,IAAI,MAAM,EACV,aAAa,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC;;;;;EAwB7C,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GAC3B,aAAa,gBAAgB,EAC7B,IAAI,MAAM,EACV,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;EA8DpC,CAAA"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type CouchConfigInput } from '../schema/config.mts';
|
|
2
2
|
export declare const remove: (configInput: CouchConfigInput, id: string, rev: string) => Promise<{
|
|
3
|
+
ok: true;
|
|
3
4
|
statusCode: number;
|
|
4
|
-
ok?: boolean | undefined;
|
|
5
|
-
error?: string | undefined;
|
|
6
5
|
id?: string | undefined;
|
|
7
6
|
rev?: string | undefined;
|
|
8
7
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove.d.mts","sourceRoot":"","sources":["../../../impl/remove.mts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAYzE,eAAO,MAAM,MAAM,GAAU,aAAa,gBAAgB,EAAE,IAAI,MAAM,EAAE,KAAK,MAAM
|
|
1
|
+
{"version":3,"file":"remove.d.mts","sourceRoot":"","sources":["../../../impl/remove.mts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAYzE,eAAO,MAAM,MAAM,GAAU,aAAa,gBAAgB,EAAE,IAAI,MAAM,EAAE,KAAK,MAAM;;;;;EAiDlF,CAAA"}
|
|
@@ -25,6 +25,7 @@ export type HideABedErrorOptions = {
|
|
|
25
25
|
category: ErrorCategory;
|
|
26
26
|
cause?: unknown;
|
|
27
27
|
couchError?: string;
|
|
28
|
+
couchReason?: string;
|
|
28
29
|
docId?: string;
|
|
29
30
|
operation?: ErrorOperation;
|
|
30
31
|
retryable: boolean;
|
|
@@ -38,6 +39,7 @@ export type HideABedErrorOptions = {
|
|
|
38
39
|
export declare class HideABedError extends Error {
|
|
39
40
|
readonly category: ErrorCategory;
|
|
40
41
|
readonly couchError?: string;
|
|
42
|
+
readonly couchReason?: string;
|
|
41
43
|
readonly docId?: string;
|
|
42
44
|
readonly operation?: ErrorOperation;
|
|
43
45
|
readonly retryable: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","sourceRoot":"","sources":["../../../../impl/utils/errors.mts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAEtE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAMD,MAAM,MAAM,aAAa,GACrB,UAAU,GACV,SAAS,GACT,WAAW,GACX,WAAW,GACX,WAAW,GACX,YAAY,GACZ,aAAa,CAAA;AAEjB,MAAM,MAAM,cAAc,GACtB,KAAK,GACL,UAAU,GACV,WAAW,GACX,OAAO,GACP,kBAAkB,GAClB,KAAK,GACL,OAAO,GACP,aAAa,GACb,QAAQ,GACR,SAAS,GACT,WAAW,CAAA;AAsCf;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,aAAa,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,cAAc,CAAA;IAC1B,SAAS,EAAE,OAAO,CAAA;IAClB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oB,GAAG,aAAa,CAwCtC;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAKrD"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type z from 'zod';
|
|
2
|
+
import type { BulkSaveFailureRow } from '../../schema/couch/couch.output.schema.ts';
|
|
1
3
|
import { OperationError } from './errors.mts';
|
|
4
|
+
type FailedDoc = z.infer<typeof BulkSaveFailureRow>;
|
|
2
5
|
export declare class TransactionSetupError extends OperationError {
|
|
3
6
|
details: Record<string, unknown>;
|
|
4
7
|
constructor(message: string, details?: Record<string, unknown>);
|
|
@@ -8,36 +11,13 @@ export declare class TransactionVersionConflictError extends OperationError {
|
|
|
8
11
|
constructor(conflictingIds: string[]);
|
|
9
12
|
}
|
|
10
13
|
export declare class TransactionBulkOperationError extends OperationError {
|
|
11
|
-
failedDocs:
|
|
12
|
-
|
|
13
|
-
id?: string | null;
|
|
14
|
-
rev?: string | null;
|
|
15
|
-
error?: string | null;
|
|
16
|
-
reason?: string | null;
|
|
17
|
-
}[];
|
|
18
|
-
constructor(failedDocs: Array<{
|
|
19
|
-
ok?: boolean | null;
|
|
20
|
-
id?: string | null;
|
|
21
|
-
rev?: string | null;
|
|
22
|
-
error?: string | null;
|
|
23
|
-
reason?: string | null;
|
|
24
|
-
}>);
|
|
14
|
+
failedDocs: FailedDoc[];
|
|
15
|
+
constructor(failedDocs: FailedDoc[]);
|
|
25
16
|
}
|
|
26
17
|
export declare class TransactionRollbackError extends OperationError {
|
|
27
18
|
originalError: Error;
|
|
28
|
-
rollbackResults:
|
|
29
|
-
|
|
30
|
-
id?: string | null;
|
|
31
|
-
rev?: string | null;
|
|
32
|
-
error?: string | null;
|
|
33
|
-
reason?: string | null;
|
|
34
|
-
}[];
|
|
35
|
-
constructor(message: string, originalError: Error, rollbackResults: Array<{
|
|
36
|
-
ok?: boolean | null;
|
|
37
|
-
id?: string | null;
|
|
38
|
-
rev?: string | null;
|
|
39
|
-
error?: string | null;
|
|
40
|
-
reason?: string | null;
|
|
41
|
-
}>);
|
|
19
|
+
rollbackResults: FailedDoc[];
|
|
20
|
+
constructor(message: string, originalError: Error, rollbackResults: FailedDoc[]);
|
|
42
21
|
}
|
|
22
|
+
export {};
|
|
43
23
|
//# sourceMappingURL=transactionErrors.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactionErrors.d.mts","sourceRoot":"","sources":["../../../../impl/utils/transactionErrors.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,qBAAa,qBAAsB,SAAQ,cAAc;IACvD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;gBAEpB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAKnE;AAED,qBAAa,+BAAgC,SAAQ,cAAc;IACjE,cAAc,EAAE,MAAM,EAAE,CAAA;gBAEZ,cAAc,EAAE,MAAM,EAAE;CAOrC;AAED,qBAAa,6BAA8B,SAAQ,cAAc;IAC/D,UAAU,EAAE
|
|
1
|
+
{"version":3,"file":"transactionErrors.d.mts","sourceRoot":"","sources":["../../../../impl/utils/transactionErrors.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,KAAK,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AASnD,qBAAa,qBAAsB,SAAQ,cAAc;IACvD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;gBAEpB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAKnE;AAED,qBAAa,+BAAgC,SAAQ,cAAc;IACjE,cAAc,EAAE,MAAM,EAAE,CAAA;gBAEZ,cAAc,EAAE,MAAM,EAAE;CAOrC;AAED,qBAAa,6BAA8B,SAAQ,cAAc;IAC/D,UAAU,EAAE,SAAS,EAAE,CAAA;gBAEX,UAAU,EAAE,SAAS,EAAE;CAUpC;AAED,qBAAa,wBAAyB,SAAQ,cAAc;IAC1D,aAAa,EAAE,KAAK,CAAA;IACpB,eAAe,EAAE,SAAS,EAAE,CAAA;gBAEhB,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE;CAMhF"}
|
|
@@ -30,6 +30,16 @@ export declare const ViewRow: z.ZodObject<{
|
|
|
30
30
|
error: z.ZodOptional<z.ZodString>;
|
|
31
31
|
}, z.core.$strip>;
|
|
32
32
|
export type ViewRow = StandardSchemaV1.InferOutput<typeof ViewRow>;
|
|
33
|
+
export declare const BulkSaveSuccessRow: z.ZodObject<{
|
|
34
|
+
ok: z.ZodLiteral<true>;
|
|
35
|
+
id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
36
|
+
rev: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
export declare const BulkSaveFailureRow: z.ZodObject<{
|
|
39
|
+
id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
|
+
error: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
|
+
reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
|
+
}, z.core.$strip>;
|
|
33
43
|
/**
|
|
34
44
|
* A CouchDB view row with validated key, value, and document schemas.
|
|
35
45
|
*/
|
|
@@ -46,8 +56,7 @@ export type ViewRowValidated<DocSchema extends StandardSchemaV1, KeySchema exten
|
|
|
46
56
|
export declare const ViewQueryResponse: z.ZodObject<{
|
|
47
57
|
total_rows: z.ZodOptional<z.ZodNumber>;
|
|
48
58
|
offset: z.ZodOptional<z.ZodNumber>;
|
|
49
|
-
|
|
50
|
-
rows: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
59
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
51
60
|
id: z.ZodOptional<z.ZodString>;
|
|
52
61
|
key: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
|
|
53
62
|
value: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
|
|
@@ -57,7 +66,7 @@ export declare const ViewQueryResponse: z.ZodObject<{
|
|
|
57
66
|
_deleted: z.ZodOptional<z.ZodBoolean>;
|
|
58
67
|
}, z.core.$loose>>>;
|
|
59
68
|
error: z.ZodOptional<z.ZodString>;
|
|
60
|
-
}, z.core.$strip
|
|
69
|
+
}, z.core.$strip>>;
|
|
61
70
|
update_seq: z.ZodOptional<z.ZodNumber>;
|
|
62
71
|
}, z.core.$strip>;
|
|
63
72
|
export type ViewQueryResponse = StandardSchemaV1.InferOutput<typeof ViewQueryResponse>;
|
|
@@ -70,20 +79,21 @@ export type ViewQueryResponseValidated<DocSchema extends StandardSchemaV1, KeySc
|
|
|
70
79
|
/**
|
|
71
80
|
* CouchDB _bulk_docs response schema
|
|
72
81
|
*/
|
|
73
|
-
export declare const BulkSaveResponse: z.ZodArray<z.ZodObject<{
|
|
74
|
-
ok: z.
|
|
82
|
+
export declare const BulkSaveResponse: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
83
|
+
ok: z.ZodLiteral<true>;
|
|
75
84
|
id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
76
85
|
rev: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
86
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
87
|
+
id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
77
88
|
error: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
78
89
|
reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
79
|
-
}, z.core.$strip>>;
|
|
90
|
+
}, z.core.$strip>]>>;
|
|
80
91
|
export type BulkSaveResponse = z.infer<typeof BulkSaveResponse>;
|
|
81
92
|
export declare const CouchPutResponse: z.ZodObject<{
|
|
82
|
-
ok: z.
|
|
83
|
-
error: z.ZodOptional<z.ZodString>;
|
|
84
|
-
statusCode: z.ZodNumber;
|
|
93
|
+
ok: z.ZodLiteral<true>;
|
|
85
94
|
id: z.ZodOptional<z.ZodString>;
|
|
86
95
|
rev: z.ZodOptional<z.ZodString>;
|
|
96
|
+
statusCode: z.ZodNumber;
|
|
87
97
|
}, z.core.$strip>;
|
|
88
98
|
export declare const CouchDBInfo: z.ZodObject<{
|
|
89
99
|
cluster: z.ZodOptional<z.ZodObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"couch.output.schema.d.ts","sourceRoot":"","sources":["../../../../schema/couch/couch.output.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAEtE;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;iBAInB,CAAA;AACF,MAAM,MAAM,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAA;AAEpE;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEpE;;GAEG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;iBAMlB,CAAA;AACF,MAAM,MAAM,OAAO,GAAG,gBAAgB,CAAC,WAAW,CAAC,OAAO,OAAO,CAAC,CAAA;AAElE;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAC1B,SAAS,SAAS,gBAAgB,EAClC,SAAS,SAAS,gBAAgB,EAClC,WAAW,SAAS,gBAAgB,IAClC;IACF,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,GAAG,CAAC,EAAE,gBAAgB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