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
package/cjs/impl/crud.cjs DELETED
@@ -1,127 +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 crud_exports = {};
30
- __export(crud_exports, {
31
- get: () => get,
32
- getAtRev: () => getAtRev,
33
- put: () => put
34
- });
35
- module.exports = __toCommonJS(crud_exports);
36
- var import_needle = __toESM(require("needle"), 1);
37
- var import_crud = require("../schema/crud.cjs");
38
- var import_errors = require("./errors.cjs");
39
- var import_logger = require("./logger.cjs");
40
- const _getWithOptions = import_crud.CouchGetWithOptions.implement(async (config, id, getOpts) => {
41
- const logger = (0, import_logger.createLogger)(config);
42
- const rev = getOpts?.rev;
43
- const path = rev ? `${id}?rev=${rev}` : id;
44
- const url = `${config.couch}/${path}`;
45
- const opts = {
46
- json: true,
47
- headers: {
48
- "Content-Type": "application/json"
49
- }
50
- };
51
- logger.info(`Getting document with id: ${id}, rev ${rev || "latest"}`);
52
- try {
53
- const resp = await (0, import_needle.default)("get", url, opts);
54
- if (!resp) {
55
- logger.error("No response received from get request");
56
- throw new import_errors.RetryableError("no response", 503);
57
- }
58
- const result = resp?.body || {};
59
- if (resp.statusCode === 404) {
60
- if (config.throwOnGetNotFound) {
61
- logger.warn(`Document not found (throwing error): ${id}, rev ${rev || "latest"}`);
62
- throw new import_errors.NotFoundError(id, result.reason || "not_found");
63
- } else {
64
- logger.debug(`Document not found (returning undefined): ${id}, rev ${rev || "latest"}`);
65
- return null;
66
- }
67
- }
68
- if (import_errors.RetryableError.isRetryableStatusCode(resp.statusCode)) {
69
- logger.warn(`Retryable status code received: ${resp.statusCode}`);
70
- throw new import_errors.RetryableError(result.reason || "retryable error", resp.statusCode);
71
- }
72
- if (resp.statusCode !== 200) {
73
- logger.error(`Unexpected status code: ${resp.statusCode}`);
74
- throw new Error(result.reason || "failed");
75
- }
76
- logger.info(`Successfully retrieved document: ${id}, rev ${rev || "latest"}`);
77
- return result;
78
- } catch (err) {
79
- logger.error("Error during get operation:", err);
80
- import_errors.RetryableError.handleNetworkError(err);
81
- }
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
- });
91
- const put = import_crud.CouchPut.implement(async (config, doc) => {
92
- const logger = (0, import_logger.createLogger)(config);
93
- const url = `${config.couch}/${doc._id}`;
94
- const body = doc;
95
- const opts = {
96
- json: true,
97
- headers: {
98
- "Content-Type": "application/json"
99
- }
100
- };
101
- logger.info(`Putting document with id: ${doc._id}`);
102
- let resp;
103
- try {
104
- resp = await (0, import_needle.default)("put", url, body, opts);
105
- } catch (err) {
106
- logger.error("Error during put operation:", err);
107
- import_errors.RetryableError.handleNetworkError(err);
108
- }
109
- if (!resp) {
110
- logger.error("No response received from put request");
111
- throw new import_errors.RetryableError("no response", 503);
112
- }
113
- const result = resp?.body || {};
114
- result.statusCode = resp.statusCode;
115
- if (resp.statusCode === 409) {
116
- logger.warn(`Conflict detected for document: ${doc._id}`);
117
- result.ok = false;
118
- result.error = "conflict";
119
- return result;
120
- }
121
- if (import_errors.RetryableError.isRetryableStatusCode(resp.statusCode)) {
122
- logger.warn(`Retryable status code received: ${resp.statusCode}`);
123
- throw new import_errors.RetryableError(result.reason || "retryable error", resp.statusCode);
124
- }
125
- logger.info(`Successfully saved document: ${doc._id}`);
126
- return result;
127
- });
@@ -1,75 +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 errors_exports = {};
20
- __export(errors_exports, {
21
- NotFoundError: () => NotFoundError,
22
- RetryableError: () => RetryableError
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
- }
36
- class RetryableError extends Error {
37
- /**
38
- * @param {string} message - The error message
39
- * @param {number|undefined} statusCode - The HTTP status code
40
- */
41
- constructor(message, statusCode) {
42
- super(message);
43
- this.name = "RetryableError";
44
- this.statusCode = statusCode;
45
- }
46
- /**
47
- * @param {number|undefined} statusCode - The HTTP status code to check
48
- * @returns {boolean} Whether the status code is retryable
49
- */
50
- static isRetryableStatusCode(statusCode) {
51
- if (statusCode === void 0) return false;
52
- return [408, 429, 500, 502, 503, 504].includes(statusCode);
53
- }
54
- /**
55
- * @param {NetworkError | unknown} err - The network error to handle
56
- * @throws {RetryableError} If the error is retryable
57
- * @throws {Error} If the error is not retryable
58
- */
59
- static handleNetworkError(err) {
60
- const networkErrors = {
61
- ECONNREFUSED: 503,
62
- ECONNRESET: 503,
63
- ETIMEDOUT: 503,
64
- ENETUNREACH: 503,
65
- ENOTFOUND: 503,
66
- EPIPE: 503,
67
- EHOSTUNREACH: 503,
68
- ESOCKETTIMEDOUT: 503
69
- };
70
- if (typeof err === "object" && err !== null && "code" in err && typeof err.code === "string" && networkErrors[err.code]) {
71
- throw new RetryableError(`Network error: ${err.code}`, networkErrors[err.code]);
72
- }
73
- throw err;
74
- }
75
- }
@@ -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 logger_exports = {};
20
- __export(logger_exports, {
21
- createLogger: () => createLogger
22
- });
23
- module.exports = __toCommonJS(logger_exports);
24
- function createLogger(config) {
25
- if (config._normalizedLogger) {
26
- return config._normalizedLogger;
27
- }
28
- if (!config.logger) {
29
- if (config.useConsoleLogger) {
30
- config._normalizedLogger = {
31
- error: (...args) => console.error(...args),
32
- warn: (...args) => console.warn(...args),
33
- info: (...args) => console.info(...args),
34
- debug: (...args) => console.debug(...args)
35
- };
36
- } else {
37
- config._normalizedLogger = {
38
- error: () => {
39
- },
40
- warn: () => {
41
- },
42
- info: () => {
43
- },
44
- debug: () => {
45
- }
46
- };
47
- }
48
- return config._normalizedLogger;
49
- }
50
- if (typeof config.logger === "function") {
51
- config._normalizedLogger = {
52
- error: (...args) => config.logger("error", ...args),
53
- warn: (...args) => config.logger("warn", ...args),
54
- info: (...args) => config.logger("info", ...args),
55
- debug: (...args) => config.logger("debug", ...args)
56
- };
57
- return config._normalizedLogger;
58
- }
59
- config._normalizedLogger = {
60
- error: config.logger.error || (() => {
61
- }),
62
- warn: config.logger.warn || (() => {
63
- }),
64
- info: config.logger.info || (() => {
65
- }),
66
- debug: config.logger.debug || (() => {
67
- })
68
- };
69
- return config._normalizedLogger;
70
- }
@@ -1,95 +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 patch_exports = {};
20
- __export(patch_exports, {
21
- patch: () => patch,
22
- patchDangerously: () => patchDangerously,
23
- sleep: () => sleep
24
- });
25
- module.exports = __toCommonJS(patch_exports);
26
- var import_crud = require("./crud.cjs");
27
- var import_patch = require("../schema/patch.cjs");
28
- var import_logger = require("./logger.cjs");
29
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
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) => {
49
- const logger = (0, import_logger.createLogger)(config);
50
- const maxRetries = config.maxRetries || 5;
51
- let delay = config.initialDelay || 1e3;
52
- let attempts = 0;
53
- logger.info(`Starting patch operation for document ${id}`);
54
- logger.debug("Patch properties:", properties);
55
- while (attempts <= maxRetries) {
56
- logger.debug(`Attempt ${attempts + 1} of ${maxRetries + 1}`);
57
- try {
58
- const doc = await (0, import_crud.get)(config, id);
59
- if (!doc) {
60
- logger.warn(`Document ${id} not found`);
61
- return { ok: false, statusCode: 404, error: "not_found" };
62
- }
63
- const updatedDoc = { ...doc, ...properties };
64
- logger.debug("Merged document:", updatedDoc);
65
- const result = await (0, import_crud.put)(config, updatedDoc);
66
- if (result.ok) {
67
- logger.info(`Successfully patched document ${id}, rev: ${result.rev}`);
68
- return result;
69
- }
70
- attempts++;
71
- if (attempts > maxRetries) {
72
- logger.error(`Failed to patch ${id} after ${maxRetries} attempts`);
73
- throw new Error(`Failed to patch after ${maxRetries} attempts`);
74
- }
75
- logger.warn(`Conflict detected for ${id}, retrying (attempt ${attempts})`);
76
- await sleep(delay);
77
- delay *= config.backoffFactor;
78
- logger.debug(`Next retry delay: ${delay}ms`);
79
- } catch (err) {
80
- if (err.message === "not_found") {
81
- logger.warn(`Document ${id} not found during patch operation`);
82
- return { ok: false, statusCode: 404, error: "not_found" };
83
- }
84
- attempts++;
85
- if (attempts > maxRetries) {
86
- const error = `Failed to patch after ${maxRetries} attempts: ${err.message}`;
87
- logger.error(error);
88
- return { ok: false, statusCode: 500, error };
89
- }
90
- logger.warn(`Error during patch attempt ${attempts}: ${err.message}`);
91
- await sleep(delay);
92
- logger.debug(`Retrying after ${delay}ms`);
93
- }
94
- }
95
- });
@@ -1,116 +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 query_exports = {};
30
- __export(query_exports, {
31
- query: () => query,
32
- queryString: () => queryString
33
- });
34
- module.exports = __toCommonJS(query_exports);
35
- var import_zod = require("zod");
36
- var import_needle = __toESM(require("needle"), 1);
37
- var import_query = require("../schema/query.cjs");
38
- var import_errors = require("./errors.cjs");
39
- var import_logger = require("./logger.cjs");
40
- var import_lodash = __toESM(require("lodash"), 1);
41
- const { includes } = import_lodash.default;
42
- const query = import_query.SimpleViewQuery.implement(async (config, view, options = {}) => {
43
- const logger = (0, import_logger.createLogger)(config);
44
- logger.info(`Starting view query: ${view}`);
45
- logger.debug("Query options:", options);
46
- let qs = queryString(options, ["key", "startkey", "endkey", "reduce", "group", "group_level", "stale", "limit"]);
47
- let method = "GET";
48
- let payload = null;
49
- const opts = {
50
- json: true,
51
- headers: {
52
- "Content-Type": "application/json"
53
- }
54
- };
55
- if (typeof options.keys !== "undefined") {
56
- const MAX_URL_LENGTH = 2e3;
57
- const _options = JSON.parse(JSON.stringify(options));
58
- delete _options.keys;
59
- qs = queryString(_options, ["key", "startkey", "endkey", "reduce", "group", "group_level", "stale", "limit"]);
60
- const keysAsString = `keys=${JSON.stringify(options.keys)}`;
61
- if (keysAsString.length + qs.length + 1 <= MAX_URL_LENGTH) {
62
- method = "GET";
63
- if (qs.length > 0) qs += "&";
64
- else qs = "";
65
- qs += keysAsString;
66
- } else {
67
- method = "POST";
68
- payload = { keys: options.keys };
69
- }
70
- }
71
- logger.debug("Generated query string:", qs);
72
- const url = `${config.couch}/${view}?${qs.toString()}`;
73
- let results;
74
- try {
75
- logger.debug(`Sending ${method} request to: ${url}`);
76
- results = method === "GET" ? await (0, import_needle.default)("get", url, opts) : await (0, import_needle.default)("post", url, payload, opts);
77
- } catch (err) {
78
- logger.error("Network error during query:", err);
79
- import_errors.RetryableError.handleNetworkError(err);
80
- }
81
- if (!results) {
82
- logger.error("No response received from query request");
83
- throw new import_errors.RetryableError("no response", 503);
84
- }
85
- const body = results.body;
86
- if (import_errors.RetryableError.isRetryableStatusCode(results.statusCode)) {
87
- logger.warn(`Retryable status code received: ${results.statusCode}`);
88
- throw new import_errors.RetryableError(body.error || "retryable error during query", results.statusCode);
89
- }
90
- if (body.error) {
91
- logger.error(`Query error: ${body.error}`);
92
- throw new Error(body.error);
93
- }
94
- logger.info(`Successfully executed view query: ${view}`);
95
- logger.debug("Query response:", body);
96
- return body;
97
- });
98
- function queryString(options = {}, params) {
99
- const parts = Object.keys(options).map((key) => {
100
- let value = options[key];
101
- if (includes(params, key)) {
102
- if (typeof value === "string" && key !== "stale") value = `"${value}"`;
103
- if (Array.isArray(value)) {
104
- value = "[" + value.map((i) => {
105
- if (i === null) return "null";
106
- if (typeof i === "string") return `"${i}"`;
107
- if (typeof i === "object" && Object.keys(i).length === 0) return "{}";
108
- if (typeof i === "object") return JSON.stringify(i);
109
- return i;
110
- }).join(",") + "]";
111
- }
112
- }
113
- return `${key}=${value}`;
114
- });
115
- return parts.join("&");
116
- }
@@ -1,163 +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 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} startkey
46
- * @returns {QueryBuilder}
47
- */
48
- startkey(startkey) {
49
- this.#options.startkey = startkey;
50
- return this;
51
- }
52
- /**
53
- * @param {any} endkey
54
- * @returns {QueryBuilder}
55
- */
56
- endKey(endkey) {
57
- this.#options.endkey = endkey;
58
- return this;
59
- }
60
- /**
61
- * @param {any} endkey
62
- * @returns {QueryBuilder}
63
- */
64
- endkey(endkey) {
65
- this.#options.endkey = endkey;
66
- return this;
67
- }
68
- /**
69
- * @param {boolean} reduce
70
- * @returns {QueryBuilder}
71
- */
72
- reduce(reduce = true) {
73
- this.#options.reduce = reduce;
74
- return this;
75
- }
76
- /**
77
- * @param {boolean} group
78
- * @returns {QueryBuilder}
79
- */
80
- group(group = true) {
81
- this.#options.group = group;
82
- return this;
83
- }
84
- /**
85
- * @param {number} level
86
- * @returns {QueryBuilder}
87
- */
88
- groupLevel(level) {
89
- this.#options.group_level = level;
90
- return this;
91
- }
92
- /**
93
- * @param {number} level
94
- * @returns {QueryBuilder}
95
- */
96
- group_level(level) {
97
- this.#options.group_level = level;
98
- return this;
99
- }
100
- /**
101
- * @param {boolean} includeDocs
102
- * @returns {QueryBuilder}
103
- */
104
- includeDocs(includeDocs = true) {
105
- this.#options.include_docs = includeDocs;
106
- return this;
107
- }
108
- /**
109
- * @param {boolean} includeDocs
110
- * @returns {QueryBuilder}
111
- */
112
- include_docs(includeDocs = true) {
113
- this.#options.include_docs = includeDocs;
114
- return this;
115
- }
116
- /**
117
- * @param {string} stale
118
- * @returns {QueryBuilder}
119
- */
120
- stale(stale) {
121
- this.#options.stale = stale;
122
- return this;
123
- }
124
- /**
125
- * @param {number} limit
126
- * @returns {QueryBuilder}
127
- */
128
- limit(limit) {
129
- this.#options.limit = limit;
130
- return this;
131
- }
132
- /**
133
- * @param {boolean} descending
134
- * @returns {QueryBuilder}
135
- */
136
- descending(descending = true) {
137
- this.#options.descending = descending;
138
- return this;
139
- }
140
- /**
141
- * @param {number} skip
142
- * @returns {QueryBuilder}
143
- */
144
- skip(skip) {
145
- this.#options.skip = skip;
146
- return this;
147
- }
148
- /**
149
- * @param {any[]} keys
150
- * @returns {QueryBuilder}
151
- */
152
- keys(keys) {
153
- this.#options.keys = keys;
154
- return this;
155
- }
156
- /**
157
- * @returns {QueryOptions}
158
- */
159
- build() {
160
- return { ...this.#options };
161
- }
162
- }
163
- const createQuery = () => new QueryBuilder();