hide-a-bed 4.0.3 → 4.1.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.
Files changed (65) hide show
  1. package/README.md +304 -73
  2. package/cjs/impl/bulk.cjs +158 -10
  3. package/cjs/impl/crud.cjs +19 -12
  4. package/cjs/impl/errors.cjs +12 -0
  5. package/cjs/impl/patch.cjs +19 -0
  6. package/cjs/impl/queryBuilder.cjs +99 -0
  7. package/cjs/impl/stream.cjs +12 -1
  8. package/cjs/impl/trackedEmitter.cjs +54 -0
  9. package/cjs/impl/transactionErrors.cjs +70 -0
  10. package/cjs/index.cjs +21 -5
  11. package/cjs/schema/bind.cjs +4 -0
  12. package/cjs/schema/bulk.cjs +35 -11
  13. package/cjs/schema/config.cjs +1 -0
  14. package/cjs/schema/crud.cjs +23 -1
  15. package/cjs/schema/patch.cjs +17 -2
  16. package/cjs/schema/query.cjs +2 -1
  17. package/config.json +5 -0
  18. package/impl/bulk.d.mts +4 -0
  19. package/impl/bulk.d.mts.map +1 -1
  20. package/impl/bulk.mjs +200 -13
  21. package/impl/crud.d.mts +2 -0
  22. package/impl/crud.d.mts.map +1 -1
  23. package/impl/crud.mjs +25 -15
  24. package/impl/errors.d.mts +8 -0
  25. package/impl/errors.d.mts.map +1 -1
  26. package/impl/errors.mjs +12 -0
  27. package/impl/patch.d.mts +2 -0
  28. package/impl/patch.d.mts.map +1 -1
  29. package/impl/patch.mjs +22 -1
  30. package/impl/query.d.mts +18 -9
  31. package/impl/query.d.mts.map +1 -1
  32. package/impl/queryBuilder.d.mts +94 -0
  33. package/impl/queryBuilder.d.mts.map +1 -0
  34. package/impl/queryBuilder.mjs +99 -0
  35. package/impl/stream.d.mts.map +1 -1
  36. package/impl/stream.mjs +12 -1
  37. package/impl/trackedEmitter.d.mts +8 -0
  38. package/impl/trackedEmitter.d.mts.map +1 -0
  39. package/impl/trackedEmitter.mjs +33 -0
  40. package/impl/transactionErrors.d.mts +57 -0
  41. package/impl/transactionErrors.d.mts.map +1 -0
  42. package/impl/transactionErrors.mjs +47 -0
  43. package/index.d.mts +18 -3
  44. package/index.d.mts.map +1 -1
  45. package/index.mjs +42 -11
  46. package/package.json +9 -4
  47. package/schema/bind.d.mts +382 -45
  48. package/schema/bind.d.mts.map +1 -1
  49. package/schema/bind.mjs +6 -2
  50. package/schema/bulk.d.mts +559 -16
  51. package/schema/bulk.d.mts.map +1 -1
  52. package/schema/bulk.mjs +40 -10
  53. package/schema/config.d.mts.map +1 -1
  54. package/schema/config.mjs +1 -0
  55. package/schema/crud.d.mts +240 -15
  56. package/schema/crud.d.mts.map +1 -1
  57. package/schema/crud.mjs +27 -1
  58. package/schema/patch.d.mts +138 -2
  59. package/schema/patch.d.mts.map +1 -1
  60. package/schema/patch.mjs +22 -2
  61. package/schema/query.d.mts +62 -30
  62. package/schema/query.d.mts.map +1 -1
  63. package/schema/query.mjs +4 -1
  64. package/schema/stream.d.mts +18 -9
  65. package/schema/stream.d.mts.map +1 -1
package/cjs/impl/crud.cjs CHANGED
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var crud_exports = {};
30
30
  __export(crud_exports, {
31
31
  get: () => get,
32
+ getAtRev: () => getAtRev,
32
33
  put: () => put
33
34
  });
34
35
  module.exports = __toCommonJS(crud_exports);
@@ -42,28 +43,26 @@ const opts = {
42
43
  "Content-Type": "application/json"
43
44
  }
44
45
  };
45
- const get = import_crud.CouchGet.implement(async (config, id) => {
46
+ const _getWithOptions = import_crud.CouchGetWithOptions.implement(async (config, id, getOpts) => {
46
47
  const logger = (0, import_logger.createLogger)(config);
47
- const url = `${config.couch}/${id}`;
48
- logger.info(`Getting document with id: ${id}`);
48
+ const rev = getOpts?.rev;
49
+ const path = rev ? `${id}?rev=${rev}` : id;
50
+ const url = `${config.couch}/${path}`;
51
+ logger.info(`Getting document with id: ${id}, rev ${rev || "latest"}`);
49
52
  try {
50
53
  const resp = await (0, import_needle.default)("get", url, opts);
51
54
  if (!resp) {
52
55
  logger.error("No response received from get request");
53
56
  throw new import_errors.RetryableError("no response", 503);
54
57
  }
55
- if (resp.statusCode === 404) {
56
- logger.debug(`Document not found: ${id}`);
57
- return null;
58
- }
59
58
  const result = resp?.body || {};
60
59
  if (resp.statusCode === 404) {
61
60
  if (config.throwOnGetNotFound) {
62
- logger.warn(`Document not found (throwing error): ${id}`);
63
- throw new Error(result.reason || "not_found");
61
+ logger.warn(`Document not found (throwing error): ${id}, rev ${rev || "latest"}`);
62
+ throw new import_errors.NotFoundError(id, result.reason || "not_found");
64
63
  } else {
65
- logger.debug(`Document not found (returning undefined): ${id}`);
66
- return void 0;
64
+ logger.debug(`Document not found (returning undefined): ${id}, rev ${rev || "latest"}`);
65
+ return null;
67
66
  }
68
67
  }
69
68
  if (import_errors.RetryableError.isRetryableStatusCode(resp.statusCode)) {
@@ -74,13 +73,21 @@ const get = import_crud.CouchGet.implement(async (config, id) => {
74
73
  logger.error(`Unexpected status code: ${resp.statusCode}`);
75
74
  throw new Error(result.reason || "failed");
76
75
  }
77
- logger.info(`Successfully retrieved document: ${id}`);
76
+ logger.info(`Successfully retrieved document: ${id}, rev ${rev || "latest"}`);
78
77
  return result;
79
78
  } catch (err) {
80
79
  logger.error("Error during get operation:", err);
81
80
  import_errors.RetryableError.handleNetworkError(err);
82
81
  }
83
82
  });
83
+ const get = import_crud.CouchGet.implement(async (config, id) => {
84
+ const getOptions = {};
85
+ return _getWithOptions(config, id, getOptions);
86
+ });
87
+ const getAtRev = import_crud.CouchGetAtRev.implement(async (config, id, rev) => {
88
+ const getOptions = { rev };
89
+ return _getWithOptions(config, id, getOptions);
90
+ });
84
91
  const put = import_crud.CouchPut.implement(async (config, doc) => {
85
92
  const logger = (0, import_logger.createLogger)(config);
86
93
  const url = `${config.couch}/${doc._id}`;
@@ -18,9 +18,21 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var errors_exports = {};
20
20
  __export(errors_exports, {
21
+ NotFoundError: () => NotFoundError,
21
22
  RetryableError: () => RetryableError
22
23
  });
23
24
  module.exports = __toCommonJS(errors_exports);
25
+ class NotFoundError extends Error {
26
+ /**
27
+ * @param {string} docId - The ID of the document that wasn't found
28
+ * @param {string} [message] - Optional error message
29
+ */
30
+ constructor(docId, message = "Document not found") {
31
+ super(message);
32
+ this.name = "NotFoundError";
33
+ this.docId = docId;
34
+ }
35
+ }
24
36
  class RetryableError extends Error {
25
37
  /**
26
38
  * @param {string} message - The error message
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var patch_exports = {};
20
20
  __export(patch_exports, {
21
21
  patch: () => patch,
22
+ patchDangerously: () => patchDangerously,
22
23
  sleep: () => sleep
23
24
  });
24
25
  module.exports = __toCommonJS(patch_exports);
@@ -27,6 +28,24 @@ var import_patch = require("../schema/patch.cjs");
27
28
  var import_logger = require("./logger.cjs");
28
29
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
29
30
  const patch = import_patch.Patch.implement(async (config, id, properties) => {
31
+ const logger = (0, import_logger.createLogger)(config);
32
+ logger.info(`Starting patch operation for document ${id}`);
33
+ logger.debug("Patch properties:", properties);
34
+ const doc = await (0, import_crud.get)(config, id);
35
+ if (doc._rev !== properties._rev) {
36
+ const result2 = {};
37
+ result2.ok = false;
38
+ result2.error = "conflict";
39
+ result2.statusCode = 409;
40
+ return result2;
41
+ }
42
+ const updatedDoc = { ...doc, ...properties };
43
+ logger.debug("Merged document:", updatedDoc);
44
+ const result = await (0, import_crud.put)(config, updatedDoc);
45
+ logger.info(`Successfully patched document ${id}, rev: ${result.rev}`);
46
+ return result;
47
+ });
48
+ const patchDangerously = import_patch.PatchDangerously.implement(async (config, id, properties) => {
30
49
  const logger = (0, import_logger.createLogger)(config);
31
50
  const maxRetries = config.maxRetries || 5;
32
51
  let delay = config.initialDelay || 1e3;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var queryBuilder_exports = {};
20
+ __export(queryBuilder_exports, {
21
+ QueryBuilder: () => QueryBuilder,
22
+ createQuery: () => createQuery
23
+ });
24
+ module.exports = __toCommonJS(queryBuilder_exports);
25
+ class QueryBuilder {
26
+ /** @type {QueryOptions} */
27
+ #options = {};
28
+ /**
29
+ * @param {any} key
30
+ * @returns {QueryBuilder}
31
+ */
32
+ key(key) {
33
+ this.#options.key = key;
34
+ return this;
35
+ }
36
+ /**
37
+ * @param {any} startkey
38
+ * @returns {QueryBuilder}
39
+ */
40
+ startKey(startkey) {
41
+ this.#options.startkey = startkey;
42
+ return this;
43
+ }
44
+ /**
45
+ * @param {any} endkey
46
+ * @returns {QueryBuilder}
47
+ */
48
+ endKey(endkey) {
49
+ this.#options.endkey = endkey;
50
+ return this;
51
+ }
52
+ /**
53
+ * @param {boolean} reduce
54
+ * @returns {QueryBuilder}
55
+ */
56
+ reduce(reduce = true) {
57
+ this.#options.reduce = reduce;
58
+ return this;
59
+ }
60
+ /**
61
+ * @param {boolean} group
62
+ * @returns {QueryBuilder}
63
+ */
64
+ group(group = true) {
65
+ this.#options.group = group;
66
+ return this;
67
+ }
68
+ /**
69
+ * @param {number} level
70
+ * @returns {QueryBuilder}
71
+ */
72
+ groupLevel(level) {
73
+ this.#options.group_level = level;
74
+ return this;
75
+ }
76
+ /**
77
+ * @param {string} stale
78
+ * @returns {QueryBuilder}
79
+ */
80
+ stale(stale) {
81
+ this.#options.stale = stale;
82
+ return this;
83
+ }
84
+ /**
85
+ * @param {number} limit
86
+ * @returns {QueryBuilder}
87
+ */
88
+ limit(limit) {
89
+ this.#options.limit = limit;
90
+ return this;
91
+ }
92
+ /**
93
+ * @returns {QueryOptions}
94
+ */
95
+ build() {
96
+ return { ...this.#options };
97
+ }
98
+ }
99
+ const createQuery = () => new QueryBuilder();
@@ -32,13 +32,19 @@ __export(stream_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(stream_exports);
34
34
  var import_needle = __toESM(require("needle"), 1);
35
+ var import_config = require("../schema/config.cjs");
35
36
  var import_query = require("./query.cjs");
36
37
  var import_errors = require("./errors.cjs");
37
38
  var import_logger = require("./logger.cjs");
38
39
  var import_JSONStream = __toESM(require("JSONStream"), 1);
39
- const queryStream = (config, view, options, onRow) => new Promise((resolve, reject) => {
40
+ const queryStream = (rawConfig, view, options, onRow) => new Promise((resolve, reject) => {
41
+ const config = import_config.CouchConfig.parse(rawConfig);
42
+ const logger = (0, import_logger.createLogger)(config);
43
+ logger.info(`Starting view query stream: ${view}`);
44
+ logger.debug("Query options:", options);
40
45
  if (!options) options = {};
41
46
  const qs = (0, import_query.queryString)(options, ["key", "startkey", "endkey", "reduce", "group", "group_level", "stale", "limit"]);
47
+ logger.debug("Generated query string:", qs);
42
48
  const url = `${config.couch}/${view}?${qs.toString()}`;
43
49
  const opts = {
44
50
  json: true,
@@ -62,6 +68,7 @@ const queryStream = (config, view, options, onRow) => new Promise((resolve, reje
62
68
  "error",
63
69
  /** @param {Error} err */
64
70
  (err) => {
71
+ logger.error("Stream parsing error:", err);
65
72
  reject(new Error(`Stream parsing error: ${err.message}`));
66
73
  }
67
74
  );
@@ -77,15 +84,19 @@ const queryStream = (config, view, options, onRow) => new Promise((resolve, reje
77
84
  }
78
85
  );
79
86
  streamer.on("end", () => {
87
+ logger.info(`Stream completed, processed ${rowCount} rows`);
80
88
  resolve(void 0);
81
89
  });
82
90
  const req = import_needle.default.get(url, opts);
83
91
  req.on("response", (response) => {
92
+ logger.debug(`Received response with status code: ${response.statusCode}`);
84
93
  if (import_errors.RetryableError.isRetryableStatusCode(response.statusCode)) {
94
+ logger.warn(`Retryable status code received: ${response.statusCode}`);
85
95
  reject(new import_errors.RetryableError("retryable error during stream query", response.statusCode));
86
96
  }
87
97
  });
88
98
  req.on("error", (err) => {
99
+ logger.error("Network error during stream query:", err);
89
100
  try {
90
101
  import_errors.RetryableError.handleNetworkError(err);
91
102
  } catch (retryErr) {
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var trackedEmitter_exports = {};
20
+ __export(trackedEmitter_exports, {
21
+ TrackedEmitter: () => TrackedEmitter,
22
+ setupEmitter: () => setupEmitter
23
+ });
24
+ module.exports = __toCommonJS(trackedEmitter_exports);
25
+ var import_events = require("events");
26
+ class TrackedEmitter extends import_events.EventEmitter {
27
+ // create a constructor with some options
28
+ constructor(options) {
29
+ super(options);
30
+ if (options.delay) this.delay = options.delay;
31
+ }
32
+ emit(event, ...args) {
33
+ const listeners = this.listeners(event);
34
+ let completed = 0;
35
+ return new Promise((resolve) => {
36
+ if (!listeners || listeners.length === 0) {
37
+ return resolve();
38
+ }
39
+ listeners.forEach((listener) => {
40
+ listener(...args);
41
+ completed++;
42
+ if (completed === listeners.length) {
43
+ if (!this.delay) resolve();
44
+ setTimeout(resolve, this.delay);
45
+ }
46
+ });
47
+ });
48
+ }
49
+ }
50
+ const setupEmitter = (config) => {
51
+ if (!config._emitter) return { emit: async () => {
52
+ } };
53
+ return config._emitter;
54
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var transactionErrors_exports = {};
20
+ __export(transactionErrors_exports, {
21
+ TransactionBulkOperationError: () => TransactionBulkOperationError,
22
+ TransactionRollbackError: () => TransactionRollbackError,
23
+ TransactionSetupError: () => TransactionSetupError,
24
+ TransactionVersionConflictError: () => TransactionVersionConflictError
25
+ });
26
+ module.exports = __toCommonJS(transactionErrors_exports);
27
+ class TransactionSetupError extends Error {
28
+ /**
29
+ * @param {string} message
30
+ * @param {Record<string, any>} details
31
+ */
32
+ constructor(message, details = {}) {
33
+ super(message);
34
+ this.name = "TransactionSetupError";
35
+ this.details = details;
36
+ }
37
+ }
38
+ class TransactionVersionConflictError extends Error {
39
+ /**
40
+ * @param {string[]} conflictingIds
41
+ */
42
+ constructor(conflictingIds) {
43
+ super(`Revision mismatch for documents: ${conflictingIds.join(", ")}`);
44
+ this.name = "TransactionVersionConflictError";
45
+ this.conflictingIds = conflictingIds;
46
+ }
47
+ }
48
+ class TransactionBulkOperationError extends Error {
49
+ /**
50
+ * @param {Array<{ok?: boolean|null, id?: string|null, rev?: string|null, error?: string|null, reason?: string|null}>} failedDocs
51
+ */
52
+ constructor(failedDocs) {
53
+ super(`Failed to save documents: ${failedDocs.map((d) => d.id).join(", ")}`);
54
+ this.name = "TransactionBulkOperationError";
55
+ this.failedDocs = failedDocs;
56
+ }
57
+ }
58
+ class TransactionRollbackError extends Error {
59
+ /**
60
+ * @param {string} message
61
+ * @param {Error} originalError
62
+ * @param {Array<{ok?: boolean|null, id?: string|null, rev?: string|null, error?: string|null, reason?: string|null}>} rollbackResults
63
+ */
64
+ constructor(message, originalError, rollbackResults) {
65
+ super(message);
66
+ this.name = "TransactionRollbackError";
67
+ this.originalError = originalError;
68
+ this.rollbackResults = rollbackResults;
69
+ }
70
+ }
package/cjs/index.cjs CHANGED
@@ -20,10 +20,15 @@ var index_exports = {};
20
20
  __export(index_exports, {
21
21
  bindConfig: () => bindConfig,
22
22
  bulkGet: () => import_bulk.bulkGet,
23
+ bulkGetDictionary: () => import_bulk.bulkGetDictionary,
23
24
  bulkRemove: () => import_bulk.bulkRemove,
24
25
  bulkSave: () => import_bulk.bulkSave,
26
+ bulkSaveTransaction: () => import_bulk.bulkSaveTransaction,
27
+ createQuery: () => import_queryBuilder.createQuery,
25
28
  get: () => import_crud.get,
29
+ getAtRev: () => import_crud.getAtRev,
26
30
  patch: () => import_patch.patch,
31
+ patchDangerously: () => import_patch.patchDangerously,
27
32
  put: () => import_crud.put,
28
33
  query: () => import_query.query,
29
34
  queryStream: () => import_stream.queryStream,
@@ -36,6 +41,7 @@ var import_crud = require("./impl/crud.cjs");
36
41
  var import_patch = require("./impl/patch.cjs");
37
42
  var import_query = require("./impl/query.cjs");
38
43
  var import_stream = require("./impl/stream.cjs");
44
+ var import_queryBuilder = require("./impl/queryBuilder.cjs");
39
45
  var import_retry = require("./impl/retry.cjs");
40
46
  var import_bulk2 = require("./schema/bulk.cjs");
41
47
  var import_config = require("./schema/config.cjs");
@@ -53,11 +59,16 @@ const schema = {
53
59
  BulkSave: import_bulk2.BulkSave,
54
60
  BulkGet: import_bulk2.BulkGet,
55
61
  BulkRemove: import_bulk2.BulkRemove,
62
+ BulkGetDictionary: import_bulk2.BulkGetDictionary,
63
+ BulkSaveTransaction: import_bulk2.BulkSaveTransaction,
56
64
  CouchGet: import_crud2.CouchGet,
57
65
  CouchPut: import_crud2.CouchPut,
58
66
  CouchDoc: import_crud2.CouchDoc,
59
67
  CouchDocResponse: import_crud2.CouchDocResponse,
60
- Patch: import_patch2.Patch
68
+ Patch: import_patch2.Patch,
69
+ PatchDangerously: import_patch2.PatchDangerously,
70
+ CouchGetAtRev: import_crud2.CouchGetAtRev,
71
+ Bind: import_bind.Bind
61
72
  };
62
73
  const bindConfig = import_bind.Bind.implement((config) => {
63
74
  const retryOptions = {
@@ -67,13 +78,18 @@ const bindConfig = import_bind.Bind.implement((config) => {
67
78
  };
68
79
  return {
69
80
  get: config.bindWithRetry ? (0, import_retry.withRetry)(import_crud.get.bind(null, config), retryOptions) : import_crud.get.bind(null, config),
81
+ getAtRev: config.bindWithRetry ? (0, import_retry.withRetry)(import_crud.getAtRev.bind(null, config), retryOptions) : import_crud.getAtRev.bind(null, config),
70
82
  put: config.bindWithRetry ? (0, import_retry.withRetry)(import_crud.put.bind(null, config), retryOptions) : import_crud.put.bind(null, config),
71
- patch: import_patch.patch.bind(null, config),
72
- // patch not included in retry
73
83
  bulkGet: config.bindWithRetry ? (0, import_retry.withRetry)(import_bulk.bulkGet.bind(null, config), retryOptions) : import_bulk.bulkGet.bind(null, config),
74
84
  bulkSave: config.bindWithRetry ? (0, import_retry.withRetry)(import_bulk.bulkSave.bind(null, config), retryOptions) : import_bulk.bulkSave.bind(null, config),
75
- bulkRemove: config.bindWithRetry ? (0, import_retry.withRetry)(import_bulk.bulkRemove.bind(null, config), retryOptions) : import_bulk.bulkRemove.bind(null, config),
76
85
  query: config.bindWithRetry ? (0, import_retry.withRetry)(import_query.query.bind(null, config), retryOptions) : import_query.query.bind(null, config),
77
- queryStream: config.bindWithRetry ? (0, import_retry.withRetry)(import_stream.queryStream.bind(null, config), retryOptions) : import_stream.queryStream.bind(null, config)
86
+ queryStream: config.bindWithRetry ? (0, import_retry.withRetry)(import_stream.queryStream.bind(null, config), retryOptions) : import_stream.queryStream.bind(null, config),
87
+ // Sugar Methods
88
+ patch: config.bindWithRetry ? (0, import_retry.withRetry)(import_patch.patch.bind(null, config), retryOptions) : import_patch.patch.bind(null, config),
89
+ patchDangerously: import_patch.patchDangerously.bind(null, config),
90
+ // patchDangerously not included in retry
91
+ bulkRemove: config.bindWithRetry ? (0, import_retry.withRetry)(import_bulk.bulkRemove.bind(null, config), retryOptions) : import_bulk.bulkRemove.bind(null, config),
92
+ bulkGetDictionary: config.bindWithRetry ? (0, import_retry.withRetry)(import_bulk.bulkGetDictionary.bind(null, config), retryOptions) : import_bulk.bulkGetDictionary.bind(null, config),
93
+ bulkSaveTransaction: import_bulk.bulkSaveTransaction.bind(null, config)
78
94
  };
79
95
  });
@@ -31,7 +31,11 @@ var import_stream = require("./stream.cjs");
31
31
  const BindReturns = import_zod.z.object({
32
32
  bulkGet: import_bulk.BulkGetBound,
33
33
  bulkSave: import_bulk.BulkSaveBound,
34
+ bulkRemove: import_bulk.BulkRemoveBound,
35
+ bulkGetDictionary: import_bulk.BulkGetDictionaryBound,
36
+ bulkSaveTransaction: import_bulk.BulkSaveTransactionBound,
34
37
  get: import_crud.CouchGetBound,
38
+ getAtRev: import_crud.CouchGetAtRevBound,
35
39
  put: import_crud.CouchPutBound,
36
40
  patch: import_patch.PatchBound,
37
41
  query: import_query.SimpleViewQueryBound,
@@ -20,41 +20,45 @@ var bulk_exports = {};
20
20
  __export(bulk_exports, {
21
21
  BulkGet: () => BulkGet,
22
22
  BulkGetBound: () => BulkGetBound,
23
+ BulkGetDictionary: () => BulkGetDictionary,
24
+ BulkGetDictionaryBound: () => BulkGetDictionaryBound,
25
+ BulkGetDictionaryResponse: () => BulkGetDictionaryResponse,
23
26
  BulkRemove: () => BulkRemove,
24
27
  BulkRemoveBound: () => BulkRemoveBound,
25
28
  BulkSave: () => BulkSave,
26
29
  BulkSaveBound: () => BulkSaveBound,
27
- BulkSaveResponseSchema: () => BulkSaveResponseSchema
30
+ BulkSaveResponseSchema: () => BulkSaveResponseSchema,
31
+ BulkSaveRow: () => BulkSaveRow,
32
+ BulkSaveTransaction: () => BulkSaveTransaction,
33
+ BulkSaveTransactionBound: () => BulkSaveTransactionBound
28
34
  });
29
35
  module.exports = __toCommonJS(bulk_exports);
30
36
  var import_zod = require("zod");
31
37
  var import_config = require("./config.cjs");
38
+ var import_query = require("./query.cjs");
32
39
  var import_crud = require("./crud.cjs");
33
- const BulkSaveResponseSchema = import_zod.z.array(import_zod.z.object({
40
+ const BulkSaveRow = import_zod.z.object({
34
41
  ok: import_zod.z.boolean().nullish(),
35
42
  id: import_zod.z.string().nullish(),
36
43
  rev: import_zod.z.string().nullish(),
37
44
  error: import_zod.z.string().nullish().describe("if an error occured, one word reason, eg conflict"),
38
45
  reason: import_zod.z.string().nullish().describe("a full error message")
39
- }));
46
+ });
47
+ const BulkSaveResponseSchema = import_zod.z.array(BulkSaveRow);
40
48
  const BulkSave = import_zod.z.function().args(
41
49
  import_config.CouchConfig,
42
- import_zod.z.array(import_zod.z.object({
43
- _id: import_zod.z.string()
44
- }).passthrough())
50
+ import_zod.z.array(import_crud.CouchDoc)
45
51
  ).returns(import_zod.z.promise(BulkSaveResponseSchema));
46
52
  const BulkSaveBound = import_zod.z.function().args(
47
- import_zod.z.array(import_zod.z.object({
48
- _id: import_zod.z.string()
49
- }).passthrough())
53
+ import_zod.z.array(import_crud.CouchDoc)
50
54
  ).returns(import_zod.z.promise(BulkSaveResponseSchema));
51
55
  const BulkGet = import_zod.z.function().args(
52
56
  import_config.CouchConfig,
53
57
  import_zod.z.array(import_zod.z.string().describe("the ids to get"))
54
- ).returns(import_zod.z.promise(import_zod.z.array(import_crud.CouchDoc)));
58
+ ).returns(import_zod.z.promise(import_query.SimpleViewQueryResponse));
55
59
  const BulkGetBound = import_zod.z.function().args(
56
60
  import_zod.z.array(import_zod.z.string().describe("the ids to get"))
57
- ).returns(import_zod.z.promise(import_zod.z.array(import_crud.CouchDoc)));
61
+ ).returns(import_zod.z.promise(import_query.SimpleViewQueryResponse));
58
62
  const BulkRemove = import_zod.z.function().args(
59
63
  import_config.CouchConfig,
60
64
  import_zod.z.array(import_zod.z.string().describe("the ids to delete"))
@@ -62,3 +66,23 @@ const BulkRemove = import_zod.z.function().args(
62
66
  const BulkRemoveBound = import_zod.z.function().args(
63
67
  import_zod.z.array(import_zod.z.string().describe("the ids to delete"))
64
68
  ).returns(import_zod.z.promise(BulkSaveResponseSchema));
69
+ const BulkGetDictionaryResponse = import_zod.z.object({
70
+ found: import_zod.z.record(import_zod.z.string(), import_crud.CouchDoc),
71
+ notFound: import_zod.z.record(import_zod.z.string(), import_query.ViewRow)
72
+ });
73
+ const BulkGetDictionary = import_zod.z.function().args(
74
+ import_config.CouchConfig,
75
+ import_zod.z.array(import_zod.z.string().describe("the ids to get"))
76
+ ).returns(import_zod.z.promise(BulkGetDictionaryResponse));
77
+ const BulkGetDictionaryBound = import_zod.z.function().args(
78
+ import_zod.z.array(import_zod.z.string().describe("the ids to get"))
79
+ ).returns(import_zod.z.promise(BulkGetDictionaryResponse));
80
+ const BulkSaveTransaction = import_zod.z.function().args(
81
+ import_config.CouchConfig,
82
+ import_zod.z.string().describe("transaction id"),
83
+ import_zod.z.array(import_crud.CouchDoc)
84
+ ).returns(import_zod.z.promise(BulkSaveResponseSchema));
85
+ const BulkSaveTransactionBound = import_zod.z.function().args(
86
+ import_zod.z.string().describe("transaction id"),
87
+ import_zod.z.array(import_crud.CouchDoc)
88
+ ).returns(import_zod.z.promise(BulkSaveResponseSchema));
@@ -42,6 +42,7 @@ const CouchConfig = import_zod.z.object({
42
42
  backoffFactor: import_zod.z.number().optional().default(2).describe("multiplier for exponential backoff"),
43
43
  useConsoleLogger: import_zod.z.boolean().optional().default(false).describe("turn on console as a fallback logger"),
44
44
  logger: LoggerSchema.optional().describe("logging interface supporting winston-like or simple function interface"),
45
+ // _emitter: z.any().optional().describe('emitter for events'),
45
46
  _normalizedLogger: import_zod.z.any().optional()
46
47
  // Internal property for caching normalized logger
47
48
  }).passthrough().describe("The std config object");
@@ -21,7 +21,11 @@ __export(crud_exports, {
21
21
  CouchDoc: () => CouchDoc,
22
22
  CouchDocResponse: () => CouchDocResponse,
23
23
  CouchGet: () => CouchGet,
24
+ CouchGetAtRev: () => CouchGetAtRev,
25
+ CouchGetAtRevBound: () => CouchGetAtRevBound,
24
26
  CouchGetBound: () => CouchGetBound,
27
+ CouchGetOptions: () => CouchGetOptions,
28
+ CouchGetWithOptions: () => CouchGetWithOptions,
25
29
  CouchPut: () => CouchPut,
26
30
  CouchPutBound: () => CouchPutBound
27
31
  });
@@ -30,7 +34,8 @@ var import_zod = require("zod");
30
34
  var import_config = require("./config.cjs");
31
35
  const CouchDoc = import_zod.z.object({
32
36
  _id: import_zod.z.string().describe("the couch doc id"),
33
- _rev: import_zod.z.string().optional().describe("the doc revision")
37
+ _rev: import_zod.z.string().optional().nullish().describe("the doc revision"),
38
+ _deleted: import_zod.z.boolean().optional().describe("is the doc deleted")
34
39
  }).passthrough();
35
40
  const CouchDocResponse = import_zod.z.object({
36
41
  ok: import_zod.z.boolean().optional().describe("did the request succeed"),
@@ -53,3 +58,20 @@ const CouchGet = import_zod.z.function().args(
53
58
  const CouchGetBound = import_zod.z.function().args(
54
59
  import_zod.z.string().describe("the couch doc id")
55
60
  ).returns(import_zod.z.promise(CouchDoc.nullable()));
61
+ const CouchGetAtRev = import_zod.z.function().args(
62
+ import_config.CouchConfig,
63
+ import_zod.z.string().describe("the couch doc id"),
64
+ import_zod.z.string().describe("the rev")
65
+ ).returns(import_zod.z.promise(CouchDoc.nullable()));
66
+ const CouchGetAtRevBound = import_zod.z.function().args(
67
+ import_zod.z.string().describe("the couch doc id"),
68
+ import_zod.z.string().describe("the rev")
69
+ ).returns(import_zod.z.promise(CouchDoc.nullable()));
70
+ const CouchGetOptions = import_zod.z.object({
71
+ rev: import_zod.z.string().optional().describe("the couch doc revision")
72
+ });
73
+ const CouchGetWithOptions = import_zod.z.function().args(
74
+ import_config.CouchConfig,
75
+ import_zod.z.string().describe("the couch doc id"),
76
+ CouchGetOptions
77
+ ).returns(import_zod.z.promise(CouchDoc.nullable()));
@@ -20,19 +20,34 @@ var patch_exports = {};
20
20
  __export(patch_exports, {
21
21
  Patch: () => Patch,
22
22
  PatchBound: () => PatchBound,
23
- PatchProperties: () => PatchProperties
23
+ PatchDangerously: () => PatchDangerously,
24
+ PatchDangerouslyBound: () => PatchDangerouslyBound,
25
+ PatchProperties: () => PatchProperties,
26
+ StrictPatchProperties: () => StrictPatchProperties
24
27
  });
25
28
  module.exports = __toCommonJS(patch_exports);
26
29
  var import_zod = require("zod");
27
30
  var import_config = require("./config.cjs");
28
31
  var import_crud = require("./crud.cjs");
29
32
  const PatchProperties = import_zod.z.record(import_zod.z.string(), import_zod.z.any());
33
+ const StrictPatchProperties = import_zod.z.object({
34
+ _rev: import_zod.z.string()
35
+ }).and(PatchProperties);
30
36
  const Patch = import_zod.z.function().args(
31
37
  import_config.CouchConfig,
32
38
  import_zod.z.string().describe("the couch doc id"),
33
- PatchProperties
39
+ StrictPatchProperties
34
40
  ).returns(import_zod.z.promise(import_crud.CouchDocResponse));
35
41
  const PatchBound = import_zod.z.function().args(
42
+ import_zod.z.string().describe("the couch doc id"),
43
+ StrictPatchProperties
44
+ ).returns(import_zod.z.promise(import_crud.CouchDocResponse));
45
+ const PatchDangerously = import_zod.z.function().args(
46
+ import_config.CouchConfig,
47
+ import_zod.z.string().describe("the couch doc id"),
48
+ PatchProperties
49
+ ).returns(import_zod.z.promise(import_crud.CouchDocResponse));
50
+ const PatchDangerouslyBound = import_zod.z.function().args(
36
51
  import_zod.z.string().describe("the couch doc id"),
37
52
  PatchProperties
38
53
  ).returns(import_zod.z.promise(import_crud.CouchDocResponse));
@@ -31,7 +31,8 @@ const ViewRow = import_zod.z.object({
31
31
  id: import_zod.z.string().optional(),
32
32
  key: import_zod.z.any().nullable(),
33
33
  value: import_zod.z.any().nullable(),
34
- doc: import_zod.z.object({}).passthrough().optional()
34
+ doc: import_zod.z.object({}).passthrough().optional().nullish(),
35
+ error: import_zod.z.string().optional().describe("usually not_found, if something is wrong with this doc")
35
36
  });
36
37
  const SimpleViewQueryResponse = import_zod.z.object({
37
38
  error: import_zod.z.string().optional().describe("if something is wrong"),
package/config.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "couchdb": {
3
+ "uuid": "92fcdcf8-7d8a-4a1a-896c-fba3fa7eb623"
4
+ }
5
+ }