hide-a-bed 5.2.7 → 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 (363) 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 +45 -31
  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/log.txt +0 -580
  330. package/schema/bind.d.mts +0 -5461
  331. package/schema/bind.d.mts.map +0 -1
  332. package/schema/bind.mjs +0 -43
  333. package/schema/bulk.d.mts +0 -923
  334. package/schema/bulk.d.mts.map +0 -1
  335. package/schema/bulk.mjs +0 -83
  336. package/schema/changes.d.mts +0 -191
  337. package/schema/changes.d.mts.map +0 -1
  338. package/schema/changes.mjs +0 -59
  339. package/schema/config.d.mts +0 -79
  340. package/schema/config.d.mts.map +0 -1
  341. package/schema/config.mjs +0 -26
  342. package/schema/crud.d.mts +0 -491
  343. package/schema/crud.d.mts.map +0 -1
  344. package/schema/crud.mjs +0 -64
  345. package/schema/patch.d.mts +0 -255
  346. package/schema/patch.d.mts.map +0 -1
  347. package/schema/patch.mjs +0 -42
  348. package/schema/query.d.mts +0 -406
  349. package/schema/query.d.mts.map +0 -1
  350. package/schema/query.mjs +0 -45
  351. package/schema/stream.d.mts +0 -211
  352. package/schema/stream.d.mts.map +0 -1
  353. package/schema/stream.mjs +0 -23
  354. package/schema/sugar/lock.d.mts +0 -238
  355. package/schema/sugar/lock.d.mts.map +0 -1
  356. package/schema/sugar/lock.mjs +0 -50
  357. package/schema/sugar/watch.d.mts +0 -127
  358. package/schema/sugar/watch.d.mts.map +0 -1
  359. package/schema/sugar/watch.mjs +0 -29
  360. package/schema/util.d.mts +0 -160
  361. package/schema/util.d.mts.map +0 -1
  362. package/schema/util.mjs +0 -35
  363. package/types/changes-stream.d.ts +0 -11
package/index.mts ADDED
@@ -0,0 +1,82 @@
1
+ import { createQuery } from './impl/utils/queryBuilder.mts'
2
+ import { QueryBuilder } from './impl/utils/queryBuilder.mts'
3
+ import { bindConfig } from './impl/bindConfig.mts'
4
+ import { withRetry } from './impl/retry.mts'
5
+ import { bulkGet, bulkGetDictionary } from './impl/bulkGet.mts'
6
+ import { getAtRev, get } from './impl/get.mts'
7
+ import { queryStream } from './impl/stream.mts'
8
+ import { patch, patchDangerously } from './impl/patch.mts'
9
+ import { put } from './impl/put.mts'
10
+ import { remove } from './impl/remove.mts'
11
+ import { bulkSave, bulkSaveTransaction } from './impl/bulkSave.mts'
12
+ import { query } from './impl/query.mts'
13
+ import { getDBInfo } from './impl/getDBInfo.mts'
14
+ import { bulkRemove, bulkRemoveMap } from './impl/bulkRemove.mts'
15
+ import { createLock, removeLock } from './impl/sugar/lock.mts'
16
+ import { watchDocs } from './impl/sugar/watch.mts'
17
+
18
+ export {
19
+ get,
20
+ getAtRev,
21
+ put,
22
+ remove,
23
+ bulkGet,
24
+ bulkSave,
25
+ query,
26
+ queryStream,
27
+ getDBInfo,
28
+
29
+ // sugar methods
30
+ patch,
31
+ patchDangerously,
32
+ bulkRemove,
33
+ bulkRemoveMap,
34
+ bulkGetDictionary,
35
+ bulkSaveTransaction,
36
+ watchDocs,
37
+
38
+ // binding
39
+ bindConfig,
40
+ withRetry,
41
+
42
+ // utils
43
+ QueryBuilder,
44
+ createQuery,
45
+ createLock,
46
+ removeLock
47
+ }
48
+
49
+ export type {
50
+ BulkGetBound,
51
+ BulkGetDictionaryBound,
52
+ BulkGetDictionaryOptions,
53
+ BulkGetDictionaryResult,
54
+ BulkGetOptions,
55
+ BulkGetResponse
56
+ } from './impl/bulkGet.mts'
57
+ export type { OnInvalidDocAction } from './impl/utils/parseRows.mts'
58
+ export type { GetOptions, GetBound, GetAtRevBound } from './impl/get.mts'
59
+ export type { QueryBound } from './impl/query.mts'
60
+ export type {
61
+ ViewString,
62
+ ViewOptions as SimpleViewOptions
63
+ } from './schema/couch/couch.input.schema.ts'
64
+ export type {
65
+ ViewRow,
66
+ CouchDoc,
67
+ CouchDocInput,
68
+ ViewQueryResponse,
69
+ ViewQueryResponseValidated,
70
+ ViewRowValidated
71
+ } from './schema/couch/couch.output.schema.ts'
72
+ export type { RetryOptions } from './impl/retry.mts'
73
+ export type { NetworkError, RetryableError, NotFoundError } from './impl/utils/errors.mts'
74
+ export type { OnRow } from './impl/stream.mts'
75
+ export type { CouchConfig, CouchConfigInput } from './schema/config.mts'
76
+ export type { LockOptions, LockOptionsInput, LockDoc } from './schema/sugar/lock.mts'
77
+ export type {
78
+ WatchOptions as WatchOptionsSchema,
79
+ WatchOptionsInput
80
+ } from './schema/sugar/watch.mts'
81
+ export type { BoundInstance } from './impl/bindConfig.mts'
82
+ export type { StandardSchemaV1 } from './types/standard-schema.ts'
package/index.test.mts ADDED
@@ -0,0 +1,415 @@
1
+ import assert from 'node:assert/strict'
2
+ import test, { suite } from 'node:test'
3
+ import { TrackedEmitter } from './impl/utils/trackedEmitter.mts'
4
+ import { bulkSaveTransaction, get } from './index.mts'
5
+ import { bindConfig } from './impl/bindConfig.mts'
6
+ import z from 'zod'
7
+ import { TEST_DB_URL } from './test/setup-db.mts'
8
+ import {
9
+ TransactionRollbackError,
10
+ TransactionVersionConflictError
11
+ } from './impl/utils/transactionErrors.mts'
12
+
13
+ const config: Parameters<typeof get>[0] = {
14
+ couch: TEST_DB_URL,
15
+ bindWithRetry: true,
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ logger: (level: string, ...args: any[]) => {
18
+ console.log(`[${level.toUpperCase()}]`, ...args)
19
+ }
20
+ }
21
+
22
+ suite('Database Tests', () => {
23
+ test('full db tests', async t => {
24
+ const db = bindConfig(config)
25
+ const test_doc_id = `test-doc-${Date.now()}`
26
+
27
+ await t.test('simple get/put', async () => {
28
+ const doc = await db.put({ _id: test_doc_id, data: 'hello world' })
29
+ assert.ok(doc.ok, 'Document created')
30
+ const fetched = await db.get(test_doc_id)
31
+ assert.strictEqual(fetched?.data, 'hello world', 'Fetched document matches')
32
+ })
33
+ await t.test('get with no document', async () => {
34
+ const notThereDoc = await get(config, 'test-doc-not-there')
35
+ assert.strictEqual(notThereDoc, null)
36
+ })
37
+ await t.test('override config with different options', async () => {
38
+ try {
39
+ await db.options({ throwOnGetNotFound: true }).get('test-doc-not-there-override')
40
+ assert.fail('should have thrown')
41
+ } catch (e: unknown) {
42
+ if (!(e instanceof Error)) throw e
43
+ console.error(e)
44
+ assert.strictEqual(e.name, 'NotFoundError')
45
+ }
46
+ })
47
+ await t.test('get with no document and throwOnGetNotFound', async () => {
48
+ const _config = { couch: TEST_DB_URL, throwOnGetNotFound: true }
49
+ try {
50
+ await get(_config, 'test-doc-not-there')
51
+ assert.fail('should have thrown')
52
+ } catch (e: unknown) {
53
+ if (!(e instanceof Error)) throw e
54
+ console.log(e.message)
55
+ assert.strictEqual(e.name, 'NotFoundError')
56
+ }
57
+ })
58
+ await t.test('put with bad rev', async () => {
59
+ const doc = { _id: 'notThereDoc', _rev: '32-does-not-compute' }
60
+ const notThereDoc = await db.put(doc)
61
+ assert.ok(!notThereDoc.ok)
62
+ assert.strictEqual(notThereDoc.error, 'conflict')
63
+ console.log(notThereDoc)
64
+ })
65
+ await t.test('bulk get, including one doc that does not exist', async () => {
66
+ const results = await db.bulkGet([test_doc_id, 'notThereDoc'])
67
+ assert.strictEqual(results.rows?.length, 2, 'two rows returned')
68
+ assert.strictEqual(results.rows[0].id, test_doc_id)
69
+ assert.strictEqual(results.rows[1].error, 'not_found')
70
+ console.log(results)
71
+ })
72
+ await t.test('bulk get validates docs with schema', async () => {
73
+ const schema_doc_id = `schema-doc-${Date.now()}`
74
+ await db.put({ _id: schema_doc_id, kind: 'example', data: 'hello' })
75
+
76
+ const schema = z.looseObject({
77
+ _id: z.string(),
78
+ kind: z.literal('example'),
79
+ data: z.string()
80
+ })
81
+
82
+ const validated = await db.bulkGet([schema_doc_id], {
83
+ validate: {
84
+ docSchema: schema
85
+ }
86
+ })
87
+ assert.strictEqual(validated.rows[0].doc?.kind, 'example', 'doc schema applied')
88
+
89
+ await assert.rejects(
90
+ async () =>
91
+ db.bulkGet([schema_doc_id], {
92
+ validate: {
93
+ docSchema: z.object({
94
+ _id: z.string(),
95
+ data: z.number()
96
+ })
97
+ }
98
+ }),
99
+ (err: unknown) => Array.isArray(err)
100
+ )
101
+ })
102
+ await t.test('get validates docs with schema', async () => {
103
+ const docId = `get-schema-doc-${Date.now()}`
104
+ const { rev } = await db.put({
105
+ _id: docId,
106
+ kind: 'example',
107
+ data: 'hello'
108
+ })
109
+
110
+ const schema = z.looseObject({
111
+ _id: z.string(),
112
+ kind: z.literal('example'),
113
+ data: z.string()
114
+ })
115
+
116
+ const validated = await db.get(docId, {
117
+ validate: {
118
+ docSchema: schema
119
+ }
120
+ })
121
+ assert.strictEqual(validated?.kind, 'example', 'doc schema applied to get')
122
+
123
+ const atRev = await db.getAtRev(docId, rev!, {
124
+ validate: {
125
+ docSchema: schema
126
+ }
127
+ })
128
+ assert.strictEqual(atRev?.data, 'hello', 'getAtRev also validates doc schema')
129
+
130
+ await assert.rejects(
131
+ async () =>
132
+ get(config, docId, {
133
+ validate: {
134
+ docSchema: z.object({
135
+ _id: z.string(),
136
+ data: z.number()
137
+ })
138
+ }
139
+ }),
140
+ (err: unknown) => Array.isArray(err) && err[0].message.includes('Invalid input:')
141
+ )
142
+ })
143
+ let _rev: string | null | undefined = null
144
+ const [doc_a, doc_b, doc_rollback] = ['a', 'b', 'rollback'].map(
145
+ x => `rev-test-doc-${x}-${Date.now()}`
146
+ )
147
+ await t.test('a transaction', async () => {
148
+ const docs = [{ _id: doc_a, data: 'something' }]
149
+ const resp = await bulkSaveTransaction(config, `transaction-${Date.now()}`, docs)
150
+ assert.strictEqual(resp.length, 1, 'one response')
151
+ assert.strictEqual(resp[0].ok, true, 'response ok')
152
+ _rev = resp[0].rev
153
+ assert.ok(resp)
154
+ })
155
+ await t.test('a transaction with a bad initial rev', async () => {
156
+ try {
157
+ const docs = [
158
+ { _id: doc_a, data: 'something' },
159
+ { _id: doc_b, data: 'new doc' }
160
+ ]
161
+ await bulkSaveTransaction(config, 'random-1', docs)
162
+ assert.fail('should have thrown')
163
+ } catch (e) {
164
+ assert.ok(e)
165
+ }
166
+ })
167
+ let b_rev: string | null | undefined = null
168
+ await t.test('a new and an existing doc', async () => {
169
+ const docs = [
170
+ { _id: doc_a, data: 'something', _rev },
171
+ { _id: doc_b, data: 'new doc' }
172
+ ]
173
+ const resp = await bulkSaveTransaction(config, `transaction-${Date.now()}`, docs)
174
+ assert.ok(resp)
175
+ assert.strictEqual(resp.length, 2, 'one response')
176
+ assert.strictEqual(resp[0].ok, true, 'response ok')
177
+ _rev = resp[0].rev
178
+ b_rev = resp[1].rev
179
+ assert.strictEqual(resp[1].ok, true, 'response ok')
180
+ assert.ok(resp[0].rev?.startsWith('2-'), 'second rev saved')
181
+ })
182
+
183
+ await t.test(
184
+ 'testing a rollback where one doc was interfered with in the transaction',
185
+ async () => {
186
+ const _config = config
187
+ const emitter = new TrackedEmitter({ delay: 300 })
188
+ config['~emitter'] = emitter
189
+ const docs = [
190
+ { _id: doc_a, data: 'before-rollback', _rev }, // this doc gets interfered with in-between commit - so will be 'interfered'
191
+ { _id: doc_rollback, data: 'new doc' }, // this doc will get removed
192
+ { _id: doc_b, _rev: b_rev, data: 'should-not-be' } // this will not be committed. result will be from b doc above 'new doc'
193
+ ]
194
+ const transactionId = `transaction-${Date.now()}`
195
+ emitter.on('transaction-started', async txnDoc => {
196
+ assert.strictEqual(txnDoc._id, `txn:${transactionId}`, 'transaction id matches')
197
+ // lets change something!
198
+ docs[0].data = 'interfered'
199
+ const interfereResp = await db.put(docs[0])
200
+ assert.ok(interfereResp.ok, 'interfered with the transaction')
201
+ })
202
+ try {
203
+ await bulkSaveTransaction(_config, transactionId, docs)
204
+ assert.fail('should have thrown')
205
+ } catch (e: unknown) {
206
+ if (!(e instanceof TransactionRollbackError)) throw e
207
+ assert.ok(e)
208
+ console.log(e)
209
+ assert.strictEqual(e.name, 'TransactionRollbackError', 'correct error type thrown')
210
+
211
+ // lets make sure doc a has data from before, and
212
+ const finalDocs = await db.bulkGet([doc_a, doc_rollback, doc_b])
213
+ assert.strictEqual(finalDocs.rows?.length, 3, 'two rows returned')
214
+ assert.strictEqual(
215
+ finalDocs.rows[0].doc?.data,
216
+ 'interfered',
217
+ 'doc has the interfered data'
218
+ )
219
+ assert.ok(!finalDocs.rows[1].doc, 'doc b was deleted, and not saved')
220
+ assert.strictEqual(finalDocs.rows[2].doc?.data, 'new doc', 'doc b was rolled back')
221
+ }
222
+ }
223
+ )
224
+ await t.test('TransactionVersionConflictError test', async () => {
225
+ const conflict_doc_id = `conflict-doc-${Date.now()}`
226
+ const transactionId = `txn:conflict-error-${Date.now()}`
227
+ // First create a doc
228
+ await db.put({ _id: conflict_doc_id, data: 'original' })
229
+ // Then try to update it with wrong rev
230
+ try {
231
+ await bulkSaveTransaction(config, transactionId, [
232
+ { _id: conflict_doc_id, _rev: 'wrong-rev', data: 'new' }
233
+ ])
234
+ assert.fail('should have thrown TransactionVersionConflictError')
235
+ } catch (e: unknown) {
236
+ if (!(e instanceof TransactionVersionConflictError)) throw e
237
+ assert.strictEqual(e.name, 'TransactionVersionConflictError', 'correct error type thrown')
238
+ assert.deepStrictEqual(e.conflictingIds, [conflict_doc_id], 'includes conflicting doc ids')
239
+ }
240
+ })
241
+ await t.test('TransactionVersionConflictError test 2, new doc with _rev', async () => {
242
+ try {
243
+ const transactionId = `txn:conflict-error-2-${Date.now()}`
244
+ // Try to update a doc that doesn't exist with a rev
245
+ await bulkSaveTransaction(config, transactionId, [
246
+ { _id: 'nonexistent', _rev: '1-abc', data: 'test' }
247
+ ])
248
+ assert.fail('should have thrown TransactionVersionConflictError')
249
+ } catch (e: unknown) {
250
+ if (!(e instanceof TransactionVersionConflictError)) throw e
251
+ assert.strictEqual(e.name, 'TransactionVersionConflictError', 'correct error type thrown')
252
+ }
253
+ })
254
+
255
+ await t.test('locking tests', async t => {
256
+ const lockOptions = {
257
+ enableLocking: true,
258
+ username: 'testUser'
259
+ }
260
+
261
+ // Test successful lock creation
262
+ const lockDocId = `doc-to-lock-${Date.now()}`
263
+ await t.test('create lock', async () => {
264
+ const locked = await db.createLock(lockDocId, lockOptions)
265
+ assert.ok(locked, 'Lock was created successfully')
266
+
267
+ // Verify lock document exists
268
+ const lockDoc = await db.get(`lock-${lockDocId}`)
269
+ assert.ok(lockDoc, 'Lock document exists')
270
+ assert.strictEqual(lockDoc.type, 'lock', 'Document is a lock')
271
+ assert.strictEqual(lockDoc.locks, lockDocId, 'Correct document is locked')
272
+ assert.strictEqual(lockDoc.lockedBy, 'testUser', 'Lock owned by correct user')
273
+ })
274
+
275
+ // Test lock conflict
276
+ await t.test('lock conflict', async () => {
277
+ const locked = await db.createLock(lockDocId, lockOptions)
278
+ assert.ok(!locked, 'Second lock attempt failed')
279
+ })
280
+
281
+ // Test unlock
282
+ await t.test('unlock document', async () => {
283
+ await db.removeLock(lockDocId, lockOptions)
284
+ const lockDoc = await db.get(`lock-${lockDocId}`)
285
+ assert.ok(!lockDoc, 'Lock document was removed')
286
+ })
287
+
288
+ // Test unlock by different user
289
+ await t.test('unlock by different user', async () => {
290
+ // Create lock as testUser
291
+ await db.createLock(lockDocId, lockOptions)
292
+
293
+ // Try to unlock as different user
294
+ const differentUserOptions = {
295
+ ...lockOptions,
296
+ username: 'differentUser'
297
+ }
298
+ await db.removeLock(lockDocId, differentUserOptions)
299
+
300
+ // Verify lock still exists
301
+ const lockDoc = await db.get(`lock-${lockDocId}`)
302
+ assert.ok(lockDoc, 'Lock still exists')
303
+ assert.strictEqual(lockDoc.lockedBy, 'testUser', 'Lock still owned by original user')
304
+ })
305
+
306
+ // Test with locking disabled
307
+ await t.test('disabled locking', async () => {
308
+ const disabledOptions = {
309
+ ...lockOptions,
310
+ enableLocking: false
311
+ }
312
+ const locked = await db.createLock('doc-to-lock-2', disabledOptions)
313
+ assert.ok(locked, 'Lock creation returns true when disabled')
314
+
315
+ const lockDoc = await db.get('lock-doc-to-lock-2')
316
+ assert.ok(!lockDoc, 'No lock document created when disabled')
317
+ })
318
+
319
+ await t.test('empty keys on bulkGet', async () => {
320
+ const results = await db.bulkGet([])
321
+ console.log(results)
322
+ assert.deepStrictEqual(results.rows, [], 'empty array returns empty object')
323
+ })
324
+
325
+ await t.test('get db info', async () => {
326
+ const results = await db.getDBInfo()
327
+ assert.ok(results)
328
+ assert.strictEqual(results.db_name, 'hide-a-bed-test-db')
329
+ })
330
+ })
331
+ await t.test('bulkRemove', async () => {
332
+ const results = await db.bulkRemove(['test-doc-never51'])
333
+ assert.ok(results)
334
+ assert.strictEqual(results.length, 0) // not an actual doc
335
+
336
+ const remove_doc_id = `test-doc-remove-51-${Date.now()}`
337
+ const doc = await db.put({ _id: remove_doc_id, data: 'hello world' })
338
+ assert.ok(doc.ok, 'Document created')
339
+ const results2 = await db.bulkRemove([remove_doc_id])
340
+ assert.ok(results2)
341
+ assert.strictEqual(results2.length, 1)
342
+ })
343
+ await t.test('bulkRemoveMap', async () => {
344
+ const results = await db.bulkRemoveMap(['test-doc-never52'])
345
+ assert.ok(results)
346
+ assert.strictEqual(results.length, 0) // not an actual doc
347
+
348
+ const remove_doc_id = `test-doc-remove-52-${Date.now()}`
349
+ const doc = await db.put({ _id: remove_doc_id, data: 'hello world' })
350
+ assert.ok(doc.ok, 'Document created')
351
+ const results2 = await db.bulkRemoveMap([remove_doc_id])
352
+ assert.ok(results2)
353
+ assert.strictEqual(results2.length, 1)
354
+ })
355
+ await t.test('bulk save', async () => {
356
+ const doc_a_id = `bulk-save-doc-a-${Date.now()}`
357
+ // make sure docs with no id are accepted
358
+ const docs = [{ first: true }, { _id: doc_a_id, second: true }]
359
+ const results = await db.bulkSave(docs)
360
+ assert.strictEqual(results.length, 2, 'two rows returned')
361
+ assert.ok(results[0].id)
362
+ assert.strictEqual(results[1].id, doc_a_id, 'id matches')
363
+ })
364
+ await t.test('a view query with only keys', async () => {
365
+ const docs = [
366
+ { _id: `query-1-${Date.now()}` },
367
+ { _id: `query-2-${Date.now()}`, included: true },
368
+ { _id: `query-3-${Date.now()}` }
369
+ ]
370
+ // create a view
371
+ await db.put({
372
+ _id: '_design/test',
373
+ views: {
374
+ test: {
375
+ map: 'function(doc) { if (!doc.included) return; emit(doc._id, null); }'
376
+ }
377
+ }
378
+ })
379
+ await db.bulkSave(docs)
380
+ const queryResults = await db.query('_design/test/_view/test', {
381
+ keys: [docs[1]._id]
382
+ })
383
+ assert.strictEqual(queryResults.rows?.length, 1, 'one row returned')
384
+ assert.strictEqual(queryResults.rows[0].key, docs[1]._id, 'key matches')
385
+ })
386
+ await t.test('all docs query', async () => {
387
+ const query_results = await db.query('_all_docs', {})
388
+ assert.ok(query_results.rows)
389
+ })
390
+ await t.test('not found doc', async () => {
391
+ // should not throw
392
+ const notFound = await db.get('never-51st')
393
+ console.log('found status', notFound)
394
+ })
395
+
396
+ await t.test('remove test', async () => {
397
+ // First create a document to delete
398
+ const remove_doc_id = `delete-test-doc-${Date.now()}`
399
+ const doc = await db.put({ _id: remove_doc_id, data: 'to be deleted' })
400
+ assert.ok(doc.ok, 'Document created successfully')
401
+
402
+ // Verify the document exists
403
+ const fetchedDoc = await db.get(remove_doc_id)
404
+ assert.strictEqual(fetchedDoc?.data, 'to be deleted', 'Document exists and has correct data')
405
+
406
+ // Delete the document
407
+ const deleteResult = await db.remove(remove_doc_id, fetchedDoc._rev as string)
408
+ assert.ok(deleteResult.ok, 'Document deleted successfully')
409
+
410
+ // Verify the document no longer exists
411
+ const deletedDoc = await db.get(remove_doc_id)
412
+ assert.strictEqual(deletedDoc, null, 'Document was successfully deleted')
413
+ })
414
+ })
415
+ })
package/package.json CHANGED
@@ -1,23 +1,37 @@
1
1
  {
2
2
  "name": "hide-a-bed",
3
- "version": "5.2.7",
3
+ "version": "6.0.0-beta.0",
4
4
  "description": "An abstraction over couchdb calls that includes easy mock/stubs with pouchdb",
5
- "module": "index.mjs",
6
- "main": "cjs/index.cjs",
7
5
  "type": "module",
8
- "types": "index.d.mts",
6
+ "main": "./dist/cjs/index.cjs",
7
+ "module": "./dist/esm/index.mjs",
8
+ "types": "./types/output/index.d.mts",
9
9
  "exports": {
10
- "require": "./cjs/index.cjs",
11
- "import": "./index.mjs",
12
- "default": "./cjs/index.cjs"
10
+ "default": "./dist/cjs/index.cjs",
11
+ "types": "./types/output/index.d.mts",
12
+ "require": {
13
+ "types": "./types/output/index.d.mts",
14
+ "default": "./dist/cjs/index.cjs"
15
+ },
16
+ "import": {
17
+ "types": "./types/output/index.d.mts",
18
+ "default": "./dist/esm/index.mjs"
19
+ }
13
20
  },
14
21
  "scripts": {
15
- "clean": "rm -rf cjs && (find . -name \"*.mts\" -type f -delete || true) && (find . -name \"*.map\" -type f -delete || true) && (find . -name \"log.txt\" -type f -delete || true)",
16
- "build": "npm run clean && tsc && npx -p dualmode@latest build",
17
- "build:cjs": "rm -rf cjs && node build/build.mjs",
18
- "test": "node tests/*.mjs",
19
- "lint:fix": "standard --fix",
20
- "prepublish": "npm run build",
22
+ "clean": "rm -rf types/output && rm -rf dist && (find . -name \"log.txt\" -type f -delete || true)",
23
+ "build": "npm run clean && tsc && tsdown",
24
+ "build:docs": "typedoc ./index.mts",
25
+ "dev": "typedoc --watch ./index.mts & npx -y serve ./docs",
26
+ "test": "node --test --test-global-setup ./test/setup.mts",
27
+ "test:watch": "node --test --watch --test-global-setup ./test/setup.mts",
28
+ "lint": "eslint .",
29
+ "lint:fix": "eslint . --fix",
30
+ "format": "prettier --write .",
31
+ "format:check": "prettier --check .",
32
+ "typecheck": "tsc --noEmit",
33
+ "typecheck:watch": "tsc --noEmit --watch",
34
+ "prepublishOnly": "npm run build",
21
35
  "full": "npm run lint:fix && npm run build && npm run clean"
22
36
  },
23
37
  "repository": {
@@ -35,27 +49,27 @@
35
49
  },
36
50
  "homepage": "https://github.com/ryanramage/hide-a-bed#readme",
37
51
  "dependencies": {
38
- "changes-stream": "^2.2.0",
39
- "JSONStream": "^1.3.5",
40
- "lodash": "^4.17.21",
41
- "needle": "^3.2.0",
42
- "zod": "^3.22.4"
52
+ "needle": "3.3.1",
53
+ "stream-chain": "3.4.0",
54
+ "stream-json": "1.9.1",
55
+ "zod": "4.2.1"
43
56
  },
44
57
  "devDependencies": {
45
- "@types/lodash": "^4.17.15",
46
- "@types/needle": "^3.3.0",
47
- "esbuild": "^0.24.2",
48
- "glob": "^11.0.0",
49
- "install": "^0.13.0",
50
- "npm": "^11.1.0",
51
- "pouchdb-server": "^4.2.0",
52
- "standard": "17.1.0",
53
- "tap": "^21.0.2",
54
- "tape": "5.8.1",
55
- "typescript": "5.6.2"
58
+ "@eslint/js": "9.39.2",
59
+ "@types/needle": "3.3.0",
60
+ "@types/node": "22.19.3",
61
+ "@types/stream-json": "1.7.8",
62
+ "eslint": "9.39.2",
63
+ "globals": "16.5.0",
64
+ "pouchdb-server": "4.2.0",
65
+ "prettier": "3.7.4",
66
+ "tsdown": "0.18.1",
67
+ "typedoc": "0.28.15",
68
+ "typescript": "5.9.3",
69
+ "typescript-eslint": "8.50.1"
56
70
  },
57
71
  "volta": {
58
- "node": "20.17.0",
59
- "npm": "10.8.2"
72
+ "node": "24.12.0",
73
+ "npm": "11.6.2"
60
74
  }
61
75
  }
@@ -0,0 +1,81 @@
1
+ import { z } from 'zod'
2
+ import type { StandardSchemaV1 } from '../types/standard-schema.ts'
3
+
4
+ const anyArgs = z.array(z.any())
5
+
6
+ const LoggerSchema = z
7
+ .object({
8
+ error: z.function({ input: anyArgs, output: z.void() }).optional(),
9
+ warn: z.function({ input: anyArgs, output: z.void() }).optional(),
10
+ info: z.function({ input: anyArgs, output: z.void() }).optional(),
11
+ debug: z.function({ input: anyArgs, output: z.void() }).optional()
12
+ })
13
+ .or(z.function({ input: anyArgs, output: z.void() }))
14
+
15
+ export const NeedleBaseOptions = z.object({
16
+ json: z.boolean(),
17
+ headers: z.record(z.string(), z.string()),
18
+ parse_response: z.boolean().optional()
19
+ })
20
+ export type NeedleBaseOptionsSchema = z.infer<typeof NeedleBaseOptions>
21
+
22
+ export const NeedleOptions = z.object({
23
+ json: z.boolean().optional(),
24
+ compressed: z.boolean().optional(),
25
+ follow_max: z.number().optional(),
26
+ follow_set_cookie: z.boolean().optional(),
27
+ follow_set_referer: z.boolean().optional(),
28
+ follow: z.number().optional(),
29
+ timeout: z.number().optional(),
30
+ read_timeout: z.number().optional(),
31
+ parse_response: z.boolean().optional(),
32
+ decode: z.boolean().optional(),
33
+ parse_cookies: z.boolean().optional(),
34
+ cookies: z.record(z.string(), z.string()).optional(),
35
+ headers: z.record(z.string(), z.string()).optional(),
36
+ auth: z.enum(['auto', 'digest', 'basic']).optional(),
37
+ username: z.string().optional(),
38
+ password: z.string().optional(),
39
+ proxy: z.string().optional(),
40
+ agent: z.any().optional(),
41
+ rejectUnauthorized: z.boolean().optional(),
42
+ output: z.string().optional(),
43
+ parse: z.boolean().optional(),
44
+ multipart: z.boolean().optional(),
45
+ open_timeout: z.number().optional(),
46
+ response_timeout: z.number().optional(),
47
+ keepAlive: z.boolean().optional()
48
+ })
49
+
50
+ export const CouchConfig = z
51
+ .strictObject({
52
+ backoffFactor: z.number().optional().default(2).describe('multiplier for exponential backoff'),
53
+ bindWithRetry: z.boolean().optional().default(true).describe('should we bind with retry'),
54
+ couch: z.string().describe('the url of the couch db'),
55
+ initialDelay: z
56
+ .number()
57
+ .optional()
58
+ .default(1000)
59
+ .describe('initial retry delay in milliseconds'),
60
+ logger: LoggerSchema.optional().describe(
61
+ 'logging interface supporting winston-like or simple function interface'
62
+ ),
63
+ maxRetries: z.number().optional().default(3).describe('maximum number of retry attempts'),
64
+ needleOpts: NeedleOptions.optional(),
65
+ throwOnGetNotFound: z
66
+ .boolean()
67
+ .optional()
68
+ .default(false)
69
+ .describe('if a get is 404 should we throw or return undefined'),
70
+ useConsoleLogger: z
71
+ .boolean()
72
+ .optional()
73
+ .default(false)
74
+ .describe('turn on console as a fallback logger'),
75
+ '~emitter': z.any().optional().describe('emitter for events'),
76
+ '~normalizedLogger': z.any().optional() // Internal property for caching normalized logger
77
+ })
78
+ .describe('The std config object')
79
+
80
+ export type CouchConfig = StandardSchemaV1.InferOutput<typeof CouchConfig>
81
+ export type CouchConfigInput = StandardSchemaV1.InferInput<typeof CouchConfig>