hide-a-bed 5.2.8 → 6.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/.prettierrc +7 -0
  2. package/README.md +270 -218
  3. package/dist/cjs/index.cjs +1952 -0
  4. package/dist/esm/index.mjs +1898 -0
  5. package/docs/.nojekyll +1 -0
  6. package/docs/assets/hierarchy.js +1 -0
  7. package/docs/assets/highlight.css +113 -0
  8. package/docs/assets/icons.js +18 -0
  9. package/docs/assets/icons.svg +1 -0
  10. package/docs/assets/main.js +60 -0
  11. package/docs/assets/navigation.js +1 -0
  12. package/docs/assets/search.js +1 -0
  13. package/docs/assets/style.css +1633 -0
  14. package/docs/classes/QueryBuilder.html +42 -0
  15. package/docs/functions/bindConfig.html +4 -0
  16. package/docs/functions/bulkGet.html +14 -0
  17. package/docs/functions/bulkGetDictionary.html +10 -0
  18. package/docs/functions/bulkRemove.html +12 -0
  19. package/docs/functions/bulkRemoveMap.html +11 -0
  20. package/docs/functions/bulkSave.html +10 -0
  21. package/docs/functions/bulkSaveTransaction.html +23 -0
  22. package/docs/functions/createLock.html +7 -0
  23. package/docs/functions/createQuery.html +1 -0
  24. package/docs/functions/get.html +1 -0
  25. package/docs/functions/getAtRev.html +1 -0
  26. package/docs/functions/getDBInfo.html +10 -0
  27. package/docs/functions/patch.html +8 -0
  28. package/docs/functions/patchDangerously.html +9 -0
  29. package/docs/functions/put.html +1 -0
  30. package/docs/functions/query.html +15 -0
  31. package/docs/functions/queryStream.html +6 -0
  32. package/docs/functions/remove.html +1 -0
  33. package/docs/functions/removeLock.html +6 -0
  34. package/docs/functions/watchDocs.html +9 -0
  35. package/docs/functions/withRetry.html +6 -0
  36. package/docs/hierarchy.html +1 -0
  37. package/docs/index.html +483 -0
  38. package/docs/interfaces/NetworkError.html +6 -0
  39. package/docs/interfaces/NotFoundError.html +10 -0
  40. package/docs/interfaces/RetryOptions.html +10 -0
  41. package/docs/interfaces/RetryableError.html +10 -0
  42. package/docs/interfaces/StandardSchemaV1.FailureResult.html +4 -0
  43. package/docs/interfaces/StandardSchemaV1.Issue.html +6 -0
  44. package/docs/interfaces/StandardSchemaV1.Options.html +3 -0
  45. package/docs/interfaces/StandardSchemaV1.PathSegment.html +4 -0
  46. package/docs/interfaces/StandardSchemaV1.Props.html +10 -0
  47. package/docs/interfaces/StandardSchemaV1.SuccessResult.html +6 -0
  48. package/docs/interfaces/StandardSchemaV1.Types.html +6 -0
  49. package/docs/interfaces/StandardSchemaV1.html +4 -0
  50. package/docs/modules/StandardSchemaV1.html +1 -0
  51. package/docs/modules.html +1 -0
  52. package/docs/types/BoundInstance.html +1 -0
  53. package/docs/types/BulkGetBound.html +2 -0
  54. package/docs/types/BulkGetDictionaryBound.html +1 -0
  55. package/docs/types/BulkGetDictionaryOptions.html +2 -0
  56. package/docs/types/BulkGetDictionaryResult.html +3 -0
  57. package/docs/types/BulkGetOptions.html +3 -0
  58. package/docs/types/BulkGetResponse.html +1 -0
  59. package/docs/types/CouchConfig-1.html +1 -0
  60. package/docs/types/CouchConfig.html +1 -0
  61. package/docs/types/CouchConfigInput.html +1 -0
  62. package/docs/types/CouchDoc-1.html +1 -0
  63. package/docs/types/CouchDoc.html +2 -0
  64. package/docs/types/CouchDocInput.html +2 -0
  65. package/docs/types/GetAtRevBound.html +1 -0
  66. package/docs/types/GetBound.html +1 -0
  67. package/docs/types/GetOptions.html +2 -0
  68. package/docs/types/LockDoc-1.html +1 -0
  69. package/docs/types/LockDoc.html +1 -0
  70. package/docs/types/LockOptions-1.html +1 -0
  71. package/docs/types/LockOptions.html +1 -0
  72. package/docs/types/LockOptionsInput.html +1 -0
  73. package/docs/types/OnInvalidDocAction.html +1 -0
  74. package/docs/types/OnRow.html +1 -0
  75. package/docs/types/QueryBound.html +1 -0
  76. package/docs/types/SimpleViewOptions-1.html +1 -0
  77. package/docs/types/SimpleViewOptions.html +1 -0
  78. package/docs/types/StandardSchemaV1.InferInput.html +2 -0
  79. package/docs/types/StandardSchemaV1.InferOutput.html +2 -0
  80. package/docs/types/StandardSchemaV1.Result.html +2 -0
  81. package/docs/types/ViewQueryResponse-1.html +1 -0
  82. package/docs/types/ViewQueryResponse.html +2 -0
  83. package/docs/types/ViewQueryResponseValidated.html +2 -0
  84. package/docs/types/ViewRow-1.html +1 -0
  85. package/docs/types/ViewRow.html +2 -0
  86. package/docs/types/ViewRowValidated.html +7 -0
  87. package/docs/types/ViewString.html +1 -0
  88. package/docs/types/WatchOptionsInput.html +1 -0
  89. package/docs/types/WatchOptionsSchema-1.html +1 -0
  90. package/docs/types/WatchOptionsSchema.html +1 -0
  91. package/eslint.config.js +15 -0
  92. package/impl/bindConfig.mts +140 -0
  93. package/impl/bulkGet.mts +256 -0
  94. package/impl/bulkGet.test.mts +159 -0
  95. package/impl/bulkRemove.mts +98 -0
  96. package/impl/bulkRemove.test.mts +102 -0
  97. package/impl/bulkSave.mts +286 -0
  98. package/impl/bulkSave.test.mts +319 -0
  99. package/impl/get.mts +137 -0
  100. package/impl/get.test.mts +114 -0
  101. package/impl/getDBInfo.mts +67 -0
  102. package/impl/getDBInfo.test.mts +62 -0
  103. package/impl/patch.mts +134 -0
  104. package/impl/patch.test.mts +142 -0
  105. package/impl/put.mts +56 -0
  106. package/impl/put.test.mts +114 -0
  107. package/impl/query.mts +224 -0
  108. package/impl/query.test.mts +280 -0
  109. package/impl/remove.mts +65 -0
  110. package/impl/remove.test.mts +82 -0
  111. package/impl/retry.mts +66 -0
  112. package/impl/retry.test.mts +77 -0
  113. package/impl/stream.mts +143 -0
  114. package/impl/stream.test.mts +205 -0
  115. package/impl/sugar/lock.mts +103 -0
  116. package/impl/sugar/lock.test.mts +113 -0
  117. package/impl/sugar/{watch.mjs → watch.mts} +56 -22
  118. package/impl/sugar/watch.test.mts +155 -0
  119. package/impl/utils/errors.mts +130 -0
  120. package/impl/utils/errors.test.mts +58 -0
  121. package/impl/utils/logger.mts +62 -0
  122. package/impl/utils/logger.test.mts +129 -0
  123. package/impl/utils/mergeNeedleOpts.mts +16 -0
  124. package/impl/utils/parseRows.mts +117 -0
  125. package/impl/utils/parseRows.test.mts +183 -0
  126. package/impl/utils/queryBuilder.mts +173 -0
  127. package/impl/utils/queryBuilder.test.mts +83 -0
  128. package/impl/utils/queryString.mts +44 -0
  129. package/impl/utils/queryString.test.mts +53 -0
  130. package/impl/{trackedEmitter.mjs → utils/trackedEmitter.mts} +9 -7
  131. package/impl/utils/transactionErrors.mts +71 -0
  132. package/index.mts +82 -0
  133. package/index.test.mts +415 -0
  134. package/package.json +46 -32
  135. package/schema/config.mts +81 -0
  136. package/schema/couch/couch.input.schema.ts +43 -0
  137. package/schema/couch/couch.output.schema.ts +169 -0
  138. package/schema/sugar/lock.mts +18 -0
  139. package/schema/sugar/watch.mts +14 -0
  140. package/schema/util.mts +8 -0
  141. package/tsconfig.json +10 -4
  142. package/tsdown.config.ts +16 -0
  143. package/typedoc.json +4 -0
  144. package/types/output/eslint.config.d.ts +3 -0
  145. package/types/output/eslint.config.d.ts.map +1 -0
  146. package/types/output/impl/bindConfig.d.mts +174 -0
  147. package/types/output/impl/bindConfig.d.mts.map +1 -0
  148. package/types/output/impl/bulkGet.d.mts +75 -0
  149. package/types/output/impl/bulkGet.d.mts.map +1 -0
  150. package/types/output/impl/bulkGet.test.d.mts +2 -0
  151. package/types/output/impl/bulkGet.test.d.mts.map +1 -0
  152. package/types/output/impl/bulkRemove.d.mts +63 -0
  153. package/types/output/impl/bulkRemove.d.mts.map +1 -0
  154. package/types/output/impl/bulkRemove.test.d.mts +2 -0
  155. package/types/output/impl/bulkRemove.test.d.mts.map +1 -0
  156. package/types/output/impl/bulkSave.d.mts +64 -0
  157. package/types/output/impl/bulkSave.d.mts.map +1 -0
  158. package/types/output/impl/bulkSave.test.d.mts +2 -0
  159. package/types/output/impl/bulkSave.test.d.mts.map +1 -0
  160. package/types/output/impl/get.d.mts +20 -0
  161. package/types/output/impl/get.d.mts.map +1 -0
  162. package/types/output/impl/get.test.d.mts +2 -0
  163. package/types/output/impl/get.test.d.mts.map +1 -0
  164. package/types/output/impl/getDBInfo.d.mts +52 -0
  165. package/types/output/impl/getDBInfo.d.mts.map +1 -0
  166. package/types/output/impl/getDBInfo.test.d.mts +2 -0
  167. package/types/output/impl/getDBInfo.test.d.mts.map +1 -0
  168. package/types/output/impl/patch.d.mts +45 -0
  169. package/types/output/impl/patch.d.mts.map +1 -0
  170. package/types/output/impl/patch.test.d.mts +2 -0
  171. package/types/output/impl/patch.test.d.mts.map +1 -0
  172. package/types/output/impl/put.d.mts +5 -0
  173. package/types/output/impl/put.d.mts.map +1 -0
  174. package/types/output/impl/put.test.d.mts +2 -0
  175. package/types/output/impl/put.test.d.mts.map +1 -0
  176. package/types/output/impl/query.d.mts +47 -0
  177. package/types/output/impl/query.d.mts.map +1 -0
  178. package/types/output/impl/query.test.d.mts +2 -0
  179. package/types/output/impl/query.test.d.mts.map +1 -0
  180. package/types/output/impl/remove.d.mts +9 -0
  181. package/types/output/impl/remove.d.mts.map +1 -0
  182. package/types/output/impl/remove.test.d.mts +2 -0
  183. package/types/output/impl/remove.test.d.mts.map +1 -0
  184. package/types/output/impl/retry.d.mts +32 -0
  185. package/types/output/impl/retry.d.mts.map +1 -0
  186. package/types/output/impl/retry.test.d.mts +2 -0
  187. package/types/output/impl/retry.test.d.mts.map +1 -0
  188. package/types/output/impl/stream.d.mts +13 -0
  189. package/types/output/impl/stream.d.mts.map +1 -0
  190. package/types/output/impl/stream.test.d.mts +2 -0
  191. package/types/output/impl/stream.test.d.mts.map +1 -0
  192. package/types/output/impl/sugar/lock.d.mts +24 -0
  193. package/types/output/impl/sugar/lock.d.mts.map +1 -0
  194. package/types/output/impl/sugar/lock.test.d.mts +2 -0
  195. package/types/output/impl/sugar/lock.test.d.mts.map +1 -0
  196. package/types/output/impl/sugar/watch.d.mts +21 -0
  197. package/types/output/impl/sugar/watch.d.mts.map +1 -0
  198. package/types/output/impl/sugar/watch.test.d.mts +2 -0
  199. package/types/output/impl/sugar/watch.test.d.mts.map +1 -0
  200. package/types/output/impl/utils/errors.d.mts +78 -0
  201. package/types/output/impl/utils/errors.d.mts.map +1 -0
  202. package/types/output/impl/utils/errors.test.d.mts +2 -0
  203. package/types/output/impl/utils/errors.test.d.mts.map +1 -0
  204. package/types/output/impl/utils/logger.d.mts +11 -0
  205. package/types/output/impl/utils/logger.d.mts.map +1 -0
  206. package/types/output/impl/utils/logger.test.d.mts +2 -0
  207. package/types/output/impl/utils/logger.test.d.mts.map +1 -0
  208. package/types/output/impl/utils/mergeNeedleOpts.d.mts +53 -0
  209. package/types/output/impl/utils/mergeNeedleOpts.d.mts.map +1 -0
  210. package/types/output/impl/utils/parseRows.d.mts +15 -0
  211. package/types/output/impl/utils/parseRows.d.mts.map +1 -0
  212. package/types/output/impl/utils/parseRows.test.d.mts +2 -0
  213. package/types/output/impl/utils/parseRows.test.d.mts.map +1 -0
  214. package/types/output/impl/utils/queryBuilder.d.mts +68 -0
  215. package/types/output/impl/utils/queryBuilder.d.mts.map +1 -0
  216. package/types/output/impl/utils/queryBuilder.test.d.mts +2 -0
  217. package/types/output/impl/utils/queryBuilder.test.d.mts.map +1 -0
  218. package/types/output/impl/utils/queryString.d.mts +9 -0
  219. package/types/output/impl/utils/queryString.d.mts.map +1 -0
  220. package/types/output/impl/utils/queryString.test.d.mts +2 -0
  221. package/types/output/impl/utils/queryString.test.d.mts.map +1 -0
  222. package/types/output/impl/utils/trackedEmitter.d.mts +7 -0
  223. package/types/output/impl/utils/trackedEmitter.d.mts.map +1 -0
  224. package/{impl → types/output/impl/utils}/transactionErrors.d.mts +16 -31
  225. package/types/output/impl/utils/transactionErrors.d.mts.map +1 -0
  226. package/types/output/index.d.mts +32 -0
  227. package/types/output/index.d.mts.map +1 -0
  228. package/types/output/index.test.d.mts +2 -0
  229. package/types/output/index.test.d.mts.map +1 -0
  230. package/types/output/schema/config.d.mts +90 -0
  231. package/types/output/schema/config.d.mts.map +1 -0
  232. package/types/output/schema/couch/couch.input.schema.d.ts +29 -0
  233. package/types/output/schema/couch/couch.input.schema.d.ts.map +1 -0
  234. package/types/output/schema/couch/couch.output.schema.d.ts +113 -0
  235. package/types/output/schema/couch/couch.output.schema.d.ts.map +1 -0
  236. package/types/output/schema/sugar/lock.d.mts +19 -0
  237. package/types/output/schema/sugar/lock.d.mts.map +1 -0
  238. package/types/output/schema/sugar/watch.d.mts +11 -0
  239. package/types/output/schema/sugar/watch.d.mts.map +1 -0
  240. package/types/output/schema/util.d.mts +85 -0
  241. package/types/output/schema/util.d.mts.map +1 -0
  242. package/types/output/tsdown.config.d.ts +3 -0
  243. package/types/output/tsdown.config.d.ts.map +1 -0
  244. package/types/output/types/standard-schema.d.ts +60 -0
  245. package/types/output/types/standard-schema.d.ts.map +1 -0
  246. package/types/standard-schema.ts +76 -0
  247. package/types/utils.d.ts +1 -0
  248. package/cjs/impl/bulk.cjs +0 -275
  249. package/cjs/impl/changes.cjs +0 -67
  250. package/cjs/impl/crud.cjs +0 -127
  251. package/cjs/impl/errors.cjs +0 -75
  252. package/cjs/impl/logger.cjs +0 -70
  253. package/cjs/impl/patch.cjs +0 -95
  254. package/cjs/impl/query.cjs +0 -116
  255. package/cjs/impl/queryBuilder.cjs +0 -163
  256. package/cjs/impl/retry.cjs +0 -55
  257. package/cjs/impl/stream.cjs +0 -121
  258. package/cjs/impl/sugar/lock.cjs +0 -81
  259. package/cjs/impl/sugar/watch.cjs +0 -159
  260. package/cjs/impl/trackedEmitter.cjs +0 -54
  261. package/cjs/impl/transactionErrors.cjs +0 -70
  262. package/cjs/impl/util.cjs +0 -64
  263. package/cjs/index.cjs +0 -132
  264. package/cjs/integration/changes.cjs +0 -76
  265. package/cjs/integration/disconnect-watch.cjs +0 -52
  266. package/cjs/integration/watch.cjs +0 -59
  267. package/cjs/schema/bind.cjs +0 -59
  268. package/cjs/schema/bulk.cjs +0 -92
  269. package/cjs/schema/changes.cjs +0 -68
  270. package/cjs/schema/config.cjs +0 -48
  271. package/cjs/schema/crud.cjs +0 -77
  272. package/cjs/schema/patch.cjs +0 -53
  273. package/cjs/schema/query.cjs +0 -62
  274. package/cjs/schema/stream.cjs +0 -42
  275. package/cjs/schema/sugar/lock.cjs +0 -59
  276. package/cjs/schema/sugar/watch.cjs +0 -42
  277. package/cjs/schema/util.cjs +0 -39
  278. package/config.json +0 -5
  279. package/docs/compiler.png +0 -0
  280. package/dualmode.config.json +0 -11
  281. package/impl/bulk.d.mts +0 -11
  282. package/impl/bulk.d.mts.map +0 -1
  283. package/impl/bulk.mjs +0 -291
  284. package/impl/changes.d.mts +0 -12
  285. package/impl/changes.d.mts.map +0 -1
  286. package/impl/changes.mjs +0 -53
  287. package/impl/crud.d.mts +0 -7
  288. package/impl/crud.d.mts.map +0 -1
  289. package/impl/crud.mjs +0 -108
  290. package/impl/errors.d.mts +0 -43
  291. package/impl/errors.d.mts.map +0 -1
  292. package/impl/errors.mjs +0 -65
  293. package/impl/logger.d.mts +0 -32
  294. package/impl/logger.d.mts.map +0 -1
  295. package/impl/logger.mjs +0 -59
  296. package/impl/patch.d.mts +0 -6
  297. package/impl/patch.d.mts.map +0 -1
  298. package/impl/patch.mjs +0 -88
  299. package/impl/query.d.mts +0 -195
  300. package/impl/query.d.mts.map +0 -1
  301. package/impl/query.mjs +0 -122
  302. package/impl/queryBuilder.d.mts +0 -154
  303. package/impl/queryBuilder.d.mts.map +0 -1
  304. package/impl/queryBuilder.mjs +0 -175
  305. package/impl/retry.d.mts +0 -2
  306. package/impl/retry.d.mts.map +0 -1
  307. package/impl/retry.mjs +0 -39
  308. package/impl/stream.d.mts +0 -3
  309. package/impl/stream.d.mts.map +0 -1
  310. package/impl/stream.mjs +0 -98
  311. package/impl/sugar/lock.d.mts +0 -5
  312. package/impl/sugar/lock.d.mts.map +0 -1
  313. package/impl/sugar/lock.mjs +0 -70
  314. package/impl/sugar/watch.d.mts +0 -34
  315. package/impl/sugar/watch.d.mts.map +0 -1
  316. package/impl/trackedEmitter.d.mts +0 -8
  317. package/impl/trackedEmitter.d.mts.map +0 -1
  318. package/impl/transactionErrors.d.mts.map +0 -1
  319. package/impl/transactionErrors.mjs +0 -47
  320. package/impl/util.d.mts +0 -3
  321. package/impl/util.d.mts.map +0 -1
  322. package/impl/util.mjs +0 -35
  323. package/index.d.mts +0 -80
  324. package/index.d.mts.map +0 -1
  325. package/index.mjs +0 -141
  326. package/integration/changes.mjs +0 -60
  327. package/integration/disconnect-watch.mjs +0 -36
  328. package/integration/watch.mjs +0 -40
  329. package/schema/bind.d.mts +0 -5461
  330. package/schema/bind.d.mts.map +0 -1
  331. package/schema/bind.mjs +0 -43
  332. package/schema/bulk.d.mts +0 -923
  333. package/schema/bulk.d.mts.map +0 -1
  334. package/schema/bulk.mjs +0 -83
  335. package/schema/changes.d.mts +0 -191
  336. package/schema/changes.d.mts.map +0 -1
  337. package/schema/changes.mjs +0 -59
  338. package/schema/config.d.mts +0 -79
  339. package/schema/config.d.mts.map +0 -1
  340. package/schema/config.mjs +0 -26
  341. package/schema/crud.d.mts +0 -491
  342. package/schema/crud.d.mts.map +0 -1
  343. package/schema/crud.mjs +0 -64
  344. package/schema/patch.d.mts +0 -255
  345. package/schema/patch.d.mts.map +0 -1
  346. package/schema/patch.mjs +0 -42
  347. package/schema/query.d.mts +0 -406
  348. package/schema/query.d.mts.map +0 -1
  349. package/schema/query.mjs +0 -45
  350. package/schema/stream.d.mts +0 -211
  351. package/schema/stream.d.mts.map +0 -1
  352. package/schema/stream.mjs +0 -23
  353. package/schema/sugar/lock.d.mts +0 -238
  354. package/schema/sugar/lock.d.mts.map +0 -1
  355. package/schema/sugar/lock.mjs +0 -50
  356. package/schema/sugar/watch.d.mts +0 -127
  357. package/schema/sugar/watch.d.mts.map +0 -1
  358. package/schema/sugar/watch.mjs +0 -29
  359. package/schema/util.d.mts +0 -160
  360. package/schema/util.d.mts.map +0 -1
  361. package/schema/util.mjs +0 -35
  362. package/types/changes-stream.d.ts +0 -11
@@ -1,55 +0,0 @@
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 retry_exports = {};
20
- __export(retry_exports, {
21
- withRetry: () => withRetry
22
- });
23
- module.exports = __toCommonJS(retry_exports);
24
- var import_errors = require("./errors.cjs");
25
- var import_patch = require("./patch.cjs");
26
- function withRetry(fn, options = {}) {
27
- const {
28
- maxRetries = 3,
29
- initialDelay = 1e3,
30
- // 1 second
31
- backoffFactor = 2,
32
- // exponential backoff multiplier
33
- maxDelay = 3e4
34
- // 30 seconds max delay
35
- } = options;
36
- return async (...args) => {
37
- let delay = initialDelay;
38
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
39
- try {
40
- const result = await fn(...args);
41
- return result;
42
- } catch (error) {
43
- if (!(error instanceof import_errors.RetryableError)) {
44
- throw error;
45
- }
46
- if (attempt === maxRetries) {
47
- throw error;
48
- }
49
- const nextDelay = Math.min(delay, maxDelay);
50
- await (0, import_patch.sleep)(nextDelay);
51
- delay *= backoffFactor;
52
- }
53
- }
54
- };
55
- }
@@ -1,121 +0,0 @@
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 stream_exports = {};
30
- __export(stream_exports, {
31
- queryStream: () => queryStream
32
- });
33
- module.exports = __toCommonJS(stream_exports);
34
- var import_needle = __toESM(require("needle"), 1);
35
- var import_config = require("../schema/config.cjs");
36
- var import_query = require("./query.cjs");
37
- var import_errors = require("./errors.cjs");
38
- var import_logger = require("./logger.cjs");
39
- var import_JSONStream = __toESM(require("JSONStream"), 1);
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);
45
- if (!options) options = {};
46
- let method = "GET";
47
- let payload = null;
48
- let qs = (0, import_query.queryString)(options, ["key", "startkey", "endkey", "reduce", "group", "group_level", "stale", "limit"]);
49
- logger.debug("Generated query string:", qs);
50
- if (typeof options.keys !== "undefined") {
51
- const MAX_URL_LENGTH = 2e3;
52
- const keysAsString = `keys=${encodeURIComponent(JSON.stringify(options.keys))}`;
53
- if (keysAsString.length + qs.length + 1 <= MAX_URL_LENGTH) {
54
- qs += (qs[0] === "?" ? "&" : "?") + keysAsString;
55
- } else {
56
- method = "POST";
57
- payload = { keys: options.keys };
58
- }
59
- }
60
- const url = `${config.couch}/${view}?${qs.toString()}`;
61
- const opts = {
62
- json: true,
63
- headers: {
64
- "Content-Type": "application/json"
65
- },
66
- parse_response: false
67
- // Keep as stream
68
- };
69
- const streamer = import_JSONStream.default.parse("rows.*");
70
- let rowCount = 0;
71
- streamer.on(
72
- "data",
73
- /** @param {object} row */
74
- (row) => {
75
- rowCount++;
76
- onRow(row);
77
- }
78
- );
79
- streamer.on(
80
- "error",
81
- /** @param {Error} err */
82
- (err) => {
83
- logger.error("Stream parsing error:", err);
84
- reject(new Error(`Stream parsing error: ${err.message}`));
85
- }
86
- );
87
- streamer.on(
88
- "done",
89
- /** @param {Error|null} err */
90
- (err) => {
91
- try {
92
- import_errors.RetryableError.handleNetworkError(err);
93
- } catch (e) {
94
- reject(e);
95
- }
96
- }
97
- );
98
- streamer.on("end", () => {
99
- logger.info(`Stream completed, processed ${rowCount} rows`);
100
- resolve(void 0);
101
- });
102
- const req = method === "GET" ? import_needle.default.get(url, opts) : import_needle.default.post(url, payload, opts);
103
- req.on("response", (response) => {
104
- logger.debug(`Received response with status code: ${response.statusCode}`);
105
- if (import_errors.RetryableError.isRetryableStatusCode(response.statusCode)) {
106
- logger.warn(`Retryable status code received: ${response.statusCode}`);
107
- reject(new import_errors.RetryableError("retryable error during stream query", response.statusCode));
108
- }
109
- });
110
- req.on("error", (err) => {
111
- logger.error("Network error during stream query:", err);
112
- try {
113
- import_errors.RetryableError.handleNetworkError(err);
114
- } catch (retryErr) {
115
- reject(retryErr);
116
- return;
117
- }
118
- reject(err);
119
- });
120
- req.pipe(streamer);
121
- });
@@ -1,81 +0,0 @@
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 lock_exports = {};
20
- __export(lock_exports, {
21
- createLock: () => createLock,
22
- removeLock: () => removeLock
23
- });
24
- module.exports = __toCommonJS(lock_exports);
25
- var import_lock = require("../../schema/sugar/lock.cjs");
26
- var import_crud = require("../crud.cjs");
27
- var import_logger = require("../logger.cjs");
28
- const createLock = import_lock.CreateLock.implement(async (config, docId, options) => {
29
- const logger = (0, import_logger.createLogger)(config);
30
- if (!options.enableLocking) {
31
- logger.debug("Locking disabled, returning true");
32
- return true;
33
- }
34
- const _id = `lock-${docId}`;
35
- const lock = {
36
- _id,
37
- type: "lock",
38
- locks: docId,
39
- lockedAt: (/* @__PURE__ */ new Date()).toISOString(),
40
- lockedBy: options.username
41
- };
42
- try {
43
- const result = await (0, import_crud.put)(config, lock);
44
- logger.info(`Lock created for ${docId} by ${options.username}`);
45
- return result.ok === true;
46
- } catch (error) {
47
- if (error.status === 409) {
48
- logger.warn(`Lock conflict for ${docId} - already locked`);
49
- } else {
50
- logger.error(`Error creating lock for ${docId}:`, error);
51
- }
52
- return false;
53
- }
54
- });
55
- const removeLock = import_lock.RemoveLock.implement(async (config, docId, options) => {
56
- const logger = (0, import_logger.createLogger)(config);
57
- if (!options.enableLocking) {
58
- logger.debug("Locking disabled, skipping unlock");
59
- return;
60
- }
61
- if (!docId) {
62
- logger.warn("No docId provided for unlock");
63
- return;
64
- }
65
- const _id = `lock-${docId}`;
66
- const existingLock = await (0, import_crud.get)(config, _id);
67
- if (!existingLock) {
68
- logger.debug(`No lock found for ${docId}`);
69
- return;
70
- }
71
- if (existingLock.lockedBy !== options.username) {
72
- logger.warn(`Cannot remove lock for ${docId} - owned by ${existingLock.lockedBy}`);
73
- return;
74
- }
75
- try {
76
- await (0, import_crud.put)(config, { ...existingLock, _deleted: true });
77
- logger.info(`Lock removed for ${docId}`);
78
- } catch (error) {
79
- logger.error(`Error removing lock for ${docId}:`, error);
80
- }
81
- });
@@ -1,159 +0,0 @@
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
- });
@@ -1,54 +0,0 @@
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
- };
@@ -1,70 +0,0 @@
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/impl/util.cjs DELETED
@@ -1,64 +0,0 @@
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 util_exports = {};
30
- __export(util_exports, {
31
- getDBInfo: () => getDBInfo
32
- });
33
- module.exports = __toCommonJS(util_exports);
34
- var import_needle = __toESM(require("needle"), 1);
35
- var import_errors = require("./errors.cjs");
36
- var import_logger = require("./logger.cjs");
37
- var import_util = require("../schema/util.cjs");
38
- const getDBInfo = import_util.GetDBInfo.implement(async (config) => {
39
- const logger = (0, import_logger.createLogger)(config);
40
- const url = `${config.couch}`;
41
- const opts = {
42
- json: true,
43
- headers: {
44
- "Content-Type": "application/json"
45
- }
46
- };
47
- let resp;
48
- try {
49
- resp = await (0, import_needle.default)("get", url, opts);
50
- } catch (err) {
51
- logger.error("Error during put operation:", err);
52
- import_errors.RetryableError.handleNetworkError(err);
53
- }
54
- if (!resp) {
55
- logger.error("No response received from put request");
56
- throw new import_errors.RetryableError("no response", 503);
57
- }
58
- const result = resp.body;
59
- if (import_errors.RetryableError.isRetryableStatusCode(resp.statusCode)) {
60
- logger.warn(`Retryable status code received: ${resp.statusCode}`);
61
- throw new import_errors.RetryableError(result.reason || "retryable error", resp.statusCode);
62
- }
63
- return result;
64
- });