hide-a-bed 5.0.2 → 5.0.4
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/cjs/impl/bulk.cjs +267 -0
- package/cjs/impl/changes.cjs +67 -0
- package/cjs/impl/crud.cjs +121 -0
- package/cjs/impl/errors.cjs +75 -0
- package/cjs/impl/logger.cjs +70 -0
- package/cjs/impl/patch.cjs +95 -0
- package/cjs/impl/query.cjs +116 -0
- package/cjs/impl/queryBuilder.cjs +99 -0
- package/cjs/impl/retry.cjs +54 -0
- package/cjs/impl/stream.cjs +121 -0
- package/cjs/impl/sugar/lock.cjs +81 -0
- package/cjs/impl/sugar/watch.cjs +159 -0
- package/cjs/impl/trackedEmitter.cjs +54 -0
- package/cjs/impl/transactionErrors.cjs +70 -0
- package/cjs/index.cjs +115 -0
- package/cjs/integration/changes.cjs +76 -0
- package/cjs/integration/disconnect-watch.cjs +52 -0
- package/cjs/integration/watch.cjs +59 -0
- package/cjs/schema/bind.cjs +51 -0
- package/cjs/schema/bulk.cjs +88 -0
- package/cjs/schema/changes.cjs +68 -0
- package/cjs/schema/config.cjs +48 -0
- package/cjs/schema/crud.cjs +77 -0
- package/cjs/schema/patch.cjs +53 -0
- package/cjs/schema/query.cjs +62 -0
- package/cjs/schema/stream.cjs +42 -0
- package/cjs/schema/sugar/lock.cjs +59 -0
- package/cjs/schema/sugar/watch.cjs +42 -0
- package/impl/bulk.d.mts +11 -0
- package/impl/bulk.d.mts.map +1 -0
- package/impl/bulk.mjs +1 -1
- package/impl/changes.d.mts +12 -0
- package/impl/changes.d.mts.map +1 -0
- package/impl/crud.d.mts +7 -0
- package/impl/crud.d.mts.map +1 -0
- package/impl/errors.d.mts +43 -0
- package/impl/errors.d.mts.map +1 -0
- package/impl/logger.d.mts +32 -0
- package/impl/logger.d.mts.map +1 -0
- package/impl/patch.d.mts +6 -0
- package/impl/patch.d.mts.map +1 -0
- package/impl/query.d.mts +195 -0
- package/impl/query.d.mts.map +1 -0
- package/impl/query.mjs +1 -1
- package/impl/queryBuilder.d.mts +94 -0
- package/impl/queryBuilder.d.mts.map +1 -0
- package/impl/retry.d.mts +2 -0
- package/impl/retry.d.mts.map +1 -0
- package/impl/stream.d.mts +3 -0
- package/impl/stream.d.mts.map +1 -0
- package/impl/sugar/lock.d.mts +5 -0
- package/impl/sugar/lock.d.mts.map +1 -0
- package/impl/sugar/watch.d.mts +34 -0
- package/impl/sugar/watch.d.mts.map +1 -0
- package/impl/trackedEmitter.d.mts +8 -0
- package/impl/trackedEmitter.d.mts.map +1 -0
- package/impl/transactionErrors.d.mts +57 -0
- package/impl/transactionErrors.d.mts.map +1 -0
- package/index.d.mts +74 -0
- package/index.d.mts.map +1 -0
- package/package.json +2 -2
- package/schema/bind.d.mts +922 -0
- package/schema/bind.d.mts.map +1 -0
- package/schema/bulk.d.mts +910 -0
- package/schema/bulk.d.mts.map +1 -0
- package/schema/changes.d.mts +191 -0
- package/schema/changes.d.mts.map +1 -0
- package/schema/config.d.mts +79 -0
- package/schema/config.d.mts.map +1 -0
- package/schema/crud.d.mts +491 -0
- package/schema/crud.d.mts.map +1 -0
- package/schema/patch.d.mts +255 -0
- package/schema/patch.d.mts.map +1 -0
- package/schema/query.d.mts +406 -0
- package/schema/query.d.mts.map +1 -0
- package/schema/stream.d.mts +211 -0
- package/schema/stream.d.mts.map +1 -0
- package/schema/sugar/lock.d.mts +238 -0
- package/schema/sugar/lock.d.mts.map +1 -0
- package/schema/sugar/watch.d.mts +127 -0
- package/schema/sugar/watch.d.mts.map +1 -0
- package/log.txt +0 -84
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var watch_exports = {};
|
|
30
|
+
__export(watch_exports, {
|
|
31
|
+
watchDocs: () => watchDocs
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(watch_exports);
|
|
34
|
+
var import_needle = __toESM(require("needle"), 1);
|
|
35
|
+
var import_events = require("events");
|
|
36
|
+
var import_errors = require("../errors.cjs");
|
|
37
|
+
var import_logger = require("../logger.cjs");
|
|
38
|
+
var import_patch = require("../patch.cjs");
|
|
39
|
+
var import_watch = require("../../schema/sugar/watch.cjs");
|
|
40
|
+
const watchDocs = import_watch.WatchDocs.implement((config, docIds, onChange, options = {}) => {
|
|
41
|
+
const logger = (0, import_logger.createLogger)(config);
|
|
42
|
+
const emitter = new import_events.EventEmitter();
|
|
43
|
+
let lastSeq = "now";
|
|
44
|
+
let stopping = false;
|
|
45
|
+
let retryCount = 0;
|
|
46
|
+
let currentRequest = null;
|
|
47
|
+
const maxRetries = options.maxRetries || 10;
|
|
48
|
+
const initialDelay = options.initialDelay || 1e3;
|
|
49
|
+
const maxDelay = options.maxDelay || 3e4;
|
|
50
|
+
const _docIds = Array.isArray(docIds) ? docIds : [docIds];
|
|
51
|
+
if (_docIds.length === 0) throw new Error("docIds must be a non-empty array");
|
|
52
|
+
if (_docIds.length > 100) throw new Error("docIds must be an array of 100 or fewer elements");
|
|
53
|
+
const connect = async () => {
|
|
54
|
+
if (stopping) return;
|
|
55
|
+
const feed = "continuous";
|
|
56
|
+
const includeDocs = options.include_docs ?? false;
|
|
57
|
+
const ids = _docIds.join('","');
|
|
58
|
+
const url = `${config.couch}/_changes?feed=${feed}&since=${lastSeq}&include_docs=${includeDocs}&filter=_doc_ids&doc_ids=["${ids}"]`;
|
|
59
|
+
const opts = {
|
|
60
|
+
headers: { "Content-Type": "application/json" },
|
|
61
|
+
parse_response: false
|
|
62
|
+
};
|
|
63
|
+
let buffer = "";
|
|
64
|
+
currentRequest = import_needle.default.get(url, opts);
|
|
65
|
+
currentRequest.on("data", (chunk) => {
|
|
66
|
+
buffer += chunk.toString();
|
|
67
|
+
const lines = buffer.split("\n");
|
|
68
|
+
buffer = lines.pop() || "";
|
|
69
|
+
for (const line of lines) {
|
|
70
|
+
if (line.trim()) {
|
|
71
|
+
try {
|
|
72
|
+
const change = JSON.parse(line);
|
|
73
|
+
if (!change.id) return null;
|
|
74
|
+
logger.debug(`Change detected, watching [${_docIds}]`, change);
|
|
75
|
+
lastSeq = change.seq || change.last_seq;
|
|
76
|
+
emitter.emit("change", change);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
logger.error("Error parsing change:", err, "Line:", line);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
currentRequest.on("response", (response) => {
|
|
84
|
+
logger.debug(`Received response with status code, watching [${_docIds}]: ${response.statusCode}`);
|
|
85
|
+
if (import_errors.RetryableError.isRetryableStatusCode(response.statusCode)) {
|
|
86
|
+
logger.warn(`Retryable status code received: ${response.statusCode}`);
|
|
87
|
+
currentRequest.abort();
|
|
88
|
+
handleReconnect();
|
|
89
|
+
} else {
|
|
90
|
+
retryCount = 0;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
currentRequest.on("error", async (err) => {
|
|
94
|
+
if (stopping) {
|
|
95
|
+
logger.info("stopping in progress, ignore stream error");
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
logger.error(`Network error during stream, watching [${_docIds}]:`, err.toString());
|
|
99
|
+
try {
|
|
100
|
+
import_errors.RetryableError.handleNetworkError(err);
|
|
101
|
+
} catch (filteredError) {
|
|
102
|
+
if (filteredError instanceof import_errors.RetryableError) {
|
|
103
|
+
logger.info(`Retryable error, watching [${_docIds}]:`, filteredError.toString());
|
|
104
|
+
handleReconnect();
|
|
105
|
+
} else {
|
|
106
|
+
logger.error(`Non-retryable error, watching [${_docIds}]`, filteredError.toString());
|
|
107
|
+
emitter.emit("error", filteredError);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
currentRequest.on("end", () => {
|
|
112
|
+
if (buffer.trim()) {
|
|
113
|
+
try {
|
|
114
|
+
const change = JSON.parse(buffer);
|
|
115
|
+
logger.debug("Final change detected:", change);
|
|
116
|
+
emitter.emit("change", change);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
logger.error("Error parsing final change:", err);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
logger.info("Stream completed. Last seen seq: ", lastSeq);
|
|
122
|
+
emitter.emit("end", { lastSeq });
|
|
123
|
+
if (!stopping) {
|
|
124
|
+
handleReconnect();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
const handleReconnect = async () => {
|
|
129
|
+
if (stopping || retryCount >= maxRetries) {
|
|
130
|
+
if (retryCount >= maxRetries) {
|
|
131
|
+
logger.error(`Max retries (${maxRetries}) reached, giving up`);
|
|
132
|
+
emitter.emit("error", new Error("Max retries reached"));
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const delay = Math.min(initialDelay * Math.pow(2, retryCount), maxDelay);
|
|
137
|
+
retryCount++;
|
|
138
|
+
logger.info(`Attempting to reconnect in ${delay}ms (attempt ${retryCount} of ${maxRetries})`);
|
|
139
|
+
await (0, import_patch.sleep)(delay);
|
|
140
|
+
try {
|
|
141
|
+
connect();
|
|
142
|
+
} catch (err) {
|
|
143
|
+
logger.error("Error during reconnection:", err);
|
|
144
|
+
handleReconnect();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
connect();
|
|
148
|
+
emitter.on("change", onChange);
|
|
149
|
+
return {
|
|
150
|
+
on: (event, listener) => emitter.on(event, listener),
|
|
151
|
+
removeListener: (event, listener) => emitter.removeListener(event, listener),
|
|
152
|
+
stop: () => {
|
|
153
|
+
stopping = true;
|
|
154
|
+
if (currentRequest) currentRequest.abort();
|
|
155
|
+
emitter.emit("end", { lastSeq });
|
|
156
|
+
emitter.removeAllListeners();
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
});
|
|
@@ -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
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
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 index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
bindConfig: () => bindConfig,
|
|
22
|
+
bulkGet: () => import_bulk.bulkGet,
|
|
23
|
+
bulkGetDictionary: () => import_bulk.bulkGetDictionary,
|
|
24
|
+
bulkRemove: () => import_bulk.bulkRemove,
|
|
25
|
+
bulkSave: () => import_bulk.bulkSave,
|
|
26
|
+
bulkSaveTransaction: () => import_bulk.bulkSaveTransaction,
|
|
27
|
+
createLock: () => import_lock.createLock,
|
|
28
|
+
createQuery: () => import_queryBuilder.createQuery,
|
|
29
|
+
get: () => import_crud.get,
|
|
30
|
+
getAtRev: () => import_crud.getAtRev,
|
|
31
|
+
patch: () => import_patch.patch,
|
|
32
|
+
patchDangerously: () => import_patch.patchDangerously,
|
|
33
|
+
put: () => import_crud.put,
|
|
34
|
+
query: () => import_query.query,
|
|
35
|
+
queryStream: () => import_stream.queryStream,
|
|
36
|
+
removeLock: () => import_lock.removeLock,
|
|
37
|
+
schema: () => schema,
|
|
38
|
+
withRetry: () => import_retry.withRetry
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
var import_bulk = require("./impl/bulk.cjs");
|
|
42
|
+
var import_crud = require("./impl/crud.cjs");
|
|
43
|
+
var import_changes = require("./impl/changes.cjs");
|
|
44
|
+
var import_patch = require("./impl/patch.cjs");
|
|
45
|
+
var import_lock = require("./impl/sugar/lock.cjs");
|
|
46
|
+
var import_watch = require("./impl/sugar/watch.cjs");
|
|
47
|
+
var import_query = require("./impl/query.cjs");
|
|
48
|
+
var import_stream = require("./impl/stream.cjs");
|
|
49
|
+
var import_queryBuilder = require("./impl/queryBuilder.cjs");
|
|
50
|
+
var import_retry = require("./impl/retry.cjs");
|
|
51
|
+
var import_bulk2 = require("./schema/bulk.cjs");
|
|
52
|
+
var import_config = require("./schema/config.cjs");
|
|
53
|
+
var import_query2 = require("./schema/query.cjs");
|
|
54
|
+
var import_changes2 = require("./schema/changes.cjs");
|
|
55
|
+
var import_stream2 = require("./schema/stream.cjs");
|
|
56
|
+
var import_patch2 = require("./schema/patch.cjs");
|
|
57
|
+
var import_lock2 = require("./schema/sugar/lock.cjs");
|
|
58
|
+
var import_watch2 = require("./schema/sugar/watch.cjs");
|
|
59
|
+
var import_crud2 = require("./schema/crud.cjs");
|
|
60
|
+
var import_bind = require("./schema/bind.cjs");
|
|
61
|
+
const schema = {
|
|
62
|
+
CouchConfig: import_config.CouchConfig,
|
|
63
|
+
SimpleViewQuery: import_query2.SimpleViewQuery,
|
|
64
|
+
SimpleViewQueryResponse: import_query2.SimpleViewQueryResponse,
|
|
65
|
+
SimpleViewQueryStream: import_stream2.SimpleViewQueryStream,
|
|
66
|
+
OnRow: import_stream2.OnRow,
|
|
67
|
+
BulkSave: import_bulk2.BulkSave,
|
|
68
|
+
BulkGet: import_bulk2.BulkGet,
|
|
69
|
+
BulkRemove: import_bulk2.BulkRemove,
|
|
70
|
+
BulkGetDictionary: import_bulk2.BulkGetDictionary,
|
|
71
|
+
BulkSaveTransaction: import_bulk2.BulkSaveTransaction,
|
|
72
|
+
CouchGet: import_crud2.CouchGet,
|
|
73
|
+
CouchPut: import_crud2.CouchPut,
|
|
74
|
+
CouchDoc: import_crud2.CouchDoc,
|
|
75
|
+
CouchDocResponse: import_crud2.CouchDocResponse,
|
|
76
|
+
Patch: import_patch2.Patch,
|
|
77
|
+
PatchDangerously: import_patch2.PatchDangerously,
|
|
78
|
+
CouchGetAtRev: import_crud2.CouchGetAtRev,
|
|
79
|
+
Bind: import_bind.Bind,
|
|
80
|
+
Lock: import_lock2.Lock,
|
|
81
|
+
WatchDocs: import_watch2.WatchDocs,
|
|
82
|
+
LockOptions: import_lock2.LockOptions,
|
|
83
|
+
CreateLock: import_lock2.CreateLock,
|
|
84
|
+
RemoveLock: import_lock2.RemoveLock,
|
|
85
|
+
Changes: import_changes2.Changes,
|
|
86
|
+
ChangesOptions: import_changes2.ChangesOptions,
|
|
87
|
+
ChangesResponse: import_changes2.ChangesResponse
|
|
88
|
+
};
|
|
89
|
+
const bindConfig = import_bind.Bind.implement((config) => {
|
|
90
|
+
const retryOptions = {
|
|
91
|
+
maxRetries: config.maxRetries ?? 10,
|
|
92
|
+
initialDelay: config.initialDelay ?? 1e3,
|
|
93
|
+
backoffFactor: config.backoffFactor ?? 2
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
get: config.bindWithRetry ? (0, import_retry.withRetry)(import_crud.get.bind(null, config), retryOptions) : import_crud.get.bind(null, config),
|
|
97
|
+
getAtRev: config.bindWithRetry ? (0, import_retry.withRetry)(import_crud.getAtRev.bind(null, config), retryOptions) : import_crud.getAtRev.bind(null, config),
|
|
98
|
+
put: config.bindWithRetry ? (0, import_retry.withRetry)(import_crud.put.bind(null, config), retryOptions) : import_crud.put.bind(null, config),
|
|
99
|
+
bulkGet: config.bindWithRetry ? (0, import_retry.withRetry)(import_bulk.bulkGet.bind(null, config), retryOptions) : import_bulk.bulkGet.bind(null, config),
|
|
100
|
+
bulkSave: config.bindWithRetry ? (0, import_retry.withRetry)(import_bulk.bulkSave.bind(null, config), retryOptions) : import_bulk.bulkSave.bind(null, config),
|
|
101
|
+
query: config.bindWithRetry ? (0, import_retry.withRetry)(import_query.query.bind(null, config), retryOptions) : import_query.query.bind(null, config),
|
|
102
|
+
queryStream: config.bindWithRetry ? (0, import_retry.withRetry)(import_stream.queryStream.bind(null, config), retryOptions) : import_stream.queryStream.bind(null, config),
|
|
103
|
+
// Sugar Methods
|
|
104
|
+
patch: config.bindWithRetry ? (0, import_retry.withRetry)(import_patch.patch.bind(null, config), retryOptions) : import_patch.patch.bind(null, config),
|
|
105
|
+
patchDangerously: import_patch.patchDangerously.bind(null, config),
|
|
106
|
+
// patchDangerously not included in retry
|
|
107
|
+
bulkRemove: config.bindWithRetry ? (0, import_retry.withRetry)(import_bulk.bulkRemove.bind(null, config), retryOptions) : import_bulk.bulkRemove.bind(null, config),
|
|
108
|
+
bulkGetDictionary: config.bindWithRetry ? (0, import_retry.withRetry)(import_bulk.bulkGetDictionary.bind(null, config), retryOptions) : import_bulk.bulkGetDictionary.bind(null, config),
|
|
109
|
+
bulkSaveTransaction: import_bulk.bulkSaveTransaction.bind(null, config),
|
|
110
|
+
createLock: import_lock.createLock.bind(null, config),
|
|
111
|
+
removeLock: import_lock.removeLock.bind(null, config),
|
|
112
|
+
watchDocs: import_watch.watchDocs.bind(null, config),
|
|
113
|
+
changes: import_changes.changes.bind(null, config)
|
|
114
|
+
};
|
|
115
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_trackedEmitter = require("../impl/trackedEmitter.cjs");
|
|
25
|
+
var import_tap = __toESM(require("tap"), 1);
|
|
26
|
+
var import_child_process = require("child_process");
|
|
27
|
+
var import__ = require("../index.cjs");
|
|
28
|
+
var import_needle = __toESM(require("needle"), 1);
|
|
29
|
+
let DB_URL = `https://admin:iEZCEQhVR9PVCmYuZ5Bv@redman-couchdb.staging.brivity.io/testdb`;
|
|
30
|
+
const config = {
|
|
31
|
+
couch: DB_URL,
|
|
32
|
+
bindWithRetry: true,
|
|
33
|
+
logger: (level, ...args) => {
|
|
34
|
+
console.log(`[${level.toUpperCase()}]`, ...args);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import_tap.default.test("changes tests", async (t) => {
|
|
38
|
+
await (0, import_needle.default)("put", DB_URL);
|
|
39
|
+
t.teardown(async () => {
|
|
40
|
+
await (0, import_needle.default)("delete", DB_URL);
|
|
41
|
+
});
|
|
42
|
+
const db = (0, import__.bindConfig)(config);
|
|
43
|
+
t.test("basic changes feed", (t2) => new Promise(async (resolve) => {
|
|
44
|
+
const onChange = (change) => {
|
|
45
|
+
t2.equal(change.id, "test-changes-doc", "change notification received");
|
|
46
|
+
changesEmitter.stop();
|
|
47
|
+
t2.end();
|
|
48
|
+
resolve();
|
|
49
|
+
};
|
|
50
|
+
const changesEmitter = await db.changes(onChange, { since: "now", feed: "continuous" });
|
|
51
|
+
t2.ok(changesEmitter.on, "changes emitter has on method");
|
|
52
|
+
t2.ok(changesEmitter.removeListener, "changes emitter has removeListener method");
|
|
53
|
+
t2.ok(changesEmitter.stop, "changes emitter has stop method");
|
|
54
|
+
await new Promise((resolve2) => setTimeout(resolve2, 1e3));
|
|
55
|
+
await db.put({ _id: "test-changes-doc", data: "test" });
|
|
56
|
+
}));
|
|
57
|
+
t.test("document id", (t2) => new Promise(async (resolve) => {
|
|
58
|
+
const opts = {
|
|
59
|
+
since: "now",
|
|
60
|
+
include_docs: true,
|
|
61
|
+
feed: "continuous"
|
|
62
|
+
};
|
|
63
|
+
const onChange = (change) => {
|
|
64
|
+
console.log("got a change", change);
|
|
65
|
+
if (change.id === "test-a") {
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
resolve();
|
|
68
|
+
}, 1e3);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const changesEmitter = await db.changes(onChange, opts);
|
|
72
|
+
await new Promise((resolve2) => setTimeout(resolve2, 4e3));
|
|
73
|
+
await db.put({ _id: "test-changes-doc-2", data: "test" });
|
|
74
|
+
await db.put({ _id: "test-a", data: "test" });
|
|
75
|
+
}));
|
|
76
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_watch = require("../impl/sugar/watch.cjs");
|
|
25
|
+
var import__ = require("../index.cjs");
|
|
26
|
+
var import_needle = __toESM(require("needle"), 1);
|
|
27
|
+
let DB_URL = `https://admin:iEZCEQhVR9PVCmYuZ5Bv@redman-couchdb.staging.brivity.io/testdb`;
|
|
28
|
+
const config = {
|
|
29
|
+
couch: DB_URL,
|
|
30
|
+
bindWithRetry: true,
|
|
31
|
+
logger: (level, ...args) => {
|
|
32
|
+
console.log(`[${level.toUpperCase()}]`, ...args);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const run = async () => {
|
|
36
|
+
await (0, import_needle.default)("put", DB_URL);
|
|
37
|
+
const db = (0, import__.bindConfig)(config);
|
|
38
|
+
const onChange = (change) => {
|
|
39
|
+
console.log(change);
|
|
40
|
+
};
|
|
41
|
+
const feed = (0, import_watch.watchDocs)(config, "doc-a-1", onChange, { include_docs: true });
|
|
42
|
+
feed.on("end", ({ lastSeq }) => {
|
|
43
|
+
console.log("ending");
|
|
44
|
+
console.log("lastSeq", lastSeq);
|
|
45
|
+
});
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
console.log("stopping...");
|
|
48
|
+
feed.stop();
|
|
49
|
+
console.log("stopped");
|
|
50
|
+
}, 19e4);
|
|
51
|
+
};
|
|
52
|
+
run();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_watch = require("../impl/sugar/watch.cjs");
|
|
25
|
+
var import_tap = __toESM(require("tap"), 1);
|
|
26
|
+
var import__ = require("../index.cjs");
|
|
27
|
+
var import_needle = __toESM(require("needle"), 1);
|
|
28
|
+
let DB_URL = `https://admin:iEZCEQhVR9PVCmYuZ5Bv@redman-couchdb.staging.brivity.io/testdb`;
|
|
29
|
+
const config = {
|
|
30
|
+
couch: DB_URL,
|
|
31
|
+
bindWithRetry: true,
|
|
32
|
+
logger: (level, ...args) => {
|
|
33
|
+
console.log(`[${level.toUpperCase()}]`, ...args);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
import_tap.default.test("changes tests", async (t) => {
|
|
37
|
+
await (0, import_needle.default)("put", DB_URL);
|
|
38
|
+
t.teardown(async () => {
|
|
39
|
+
await (0, import_needle.default)("delete", DB_URL);
|
|
40
|
+
});
|
|
41
|
+
const db = (0, import__.bindConfig)(config);
|
|
42
|
+
t.test("watch a doc", (t2) => new Promise(async (resolve) => {
|
|
43
|
+
let feed = null;
|
|
44
|
+
const onChange = (change) => {
|
|
45
|
+
t2.equal(change.id, "doc-a-1");
|
|
46
|
+
t2.equal(change.doc._id, "doc-a-1");
|
|
47
|
+
t2.equal(change.doc.data, "test");
|
|
48
|
+
feed.stop();
|
|
49
|
+
resolve();
|
|
50
|
+
};
|
|
51
|
+
feed = db.watchDocs("doc-a-1", onChange, { include_docs: true });
|
|
52
|
+
feed.on("end", ({ lastSeq }) => {
|
|
53
|
+
console.log("ending");
|
|
54
|
+
console.log("lastSeq", lastSeq);
|
|
55
|
+
});
|
|
56
|
+
await db.put({ _id: "doc-a-fake-out", data: "test" });
|
|
57
|
+
await db.put({ _id: "doc-a-1", data: "test" });
|
|
58
|
+
}));
|
|
59
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
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 bind_exports = {};
|
|
20
|
+
__export(bind_exports, {
|
|
21
|
+
Bind: () => Bind
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(bind_exports);
|
|
24
|
+
var import_zod = require("zod");
|
|
25
|
+
var import_config = require("./config.cjs");
|
|
26
|
+
var import_bulk = require("./bulk.cjs");
|
|
27
|
+
var import_crud = require("./crud.cjs");
|
|
28
|
+
var import_patch = require("./patch.cjs");
|
|
29
|
+
var import_query = require("./query.cjs");
|
|
30
|
+
var import_stream = require("./stream.cjs");
|
|
31
|
+
var import_lock = require("./sugar/lock.cjs");
|
|
32
|
+
var import_changes = require("./changes.cjs");
|
|
33
|
+
var import_watch = require("./sugar/watch.cjs");
|
|
34
|
+
const BindReturns = import_zod.z.object({
|
|
35
|
+
bulkGet: import_bulk.BulkGetBound,
|
|
36
|
+
bulkSave: import_bulk.BulkSaveBound,
|
|
37
|
+
bulkRemove: import_bulk.BulkRemoveBound,
|
|
38
|
+
bulkGetDictionary: import_bulk.BulkGetDictionaryBound,
|
|
39
|
+
bulkSaveTransaction: import_bulk.BulkSaveTransactionBound,
|
|
40
|
+
get: import_crud.CouchGetBound,
|
|
41
|
+
getAtRev: import_crud.CouchGetAtRevBound,
|
|
42
|
+
put: import_crud.CouchPutBound,
|
|
43
|
+
patch: import_patch.PatchBound,
|
|
44
|
+
query: import_query.SimpleViewQueryBound,
|
|
45
|
+
queryStream: import_stream.SimpleViewQueryStreamBound,
|
|
46
|
+
createLock: import_lock.CreateLockBound,
|
|
47
|
+
removeLock: import_lock.RemoveLockBound,
|
|
48
|
+
changes: import_changes.ChangesBound,
|
|
49
|
+
watchDocs: import_watch.WatchDocsBound
|
|
50
|
+
});
|
|
51
|
+
const Bind = import_zod.z.function().args(import_config.CouchConfig).returns(BindReturns);
|