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
@@ -0,0 +1,85 @@
1
+ import { z } from 'zod';
2
+ export declare const MergeNeedleOpts: z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
3
+ backoffFactor: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
4
+ bindWithRetry: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
5
+ couch: z.ZodString;
6
+ initialDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
7
+ logger: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
8
+ error: z.ZodOptional<z.ZodFunction<z.ZodArray<z.ZodAny>, z.ZodVoid>>;
9
+ warn: z.ZodOptional<z.ZodFunction<z.ZodArray<z.ZodAny>, z.ZodVoid>>;
10
+ info: z.ZodOptional<z.ZodFunction<z.ZodArray<z.ZodAny>, z.ZodVoid>>;
11
+ debug: z.ZodOptional<z.ZodFunction<z.ZodArray<z.ZodAny>, z.ZodVoid>>;
12
+ }, z.core.$strip>, z.ZodFunction<z.ZodArray<z.ZodAny>, z.ZodVoid>]>>;
13
+ maxRetries: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
14
+ needleOpts: z.ZodOptional<z.ZodObject<{
15
+ json: z.ZodOptional<z.ZodBoolean>;
16
+ compressed: z.ZodOptional<z.ZodBoolean>;
17
+ follow_max: z.ZodOptional<z.ZodNumber>;
18
+ follow_set_cookie: z.ZodOptional<z.ZodBoolean>;
19
+ follow_set_referer: z.ZodOptional<z.ZodBoolean>;
20
+ follow: z.ZodOptional<z.ZodNumber>;
21
+ timeout: z.ZodOptional<z.ZodNumber>;
22
+ read_timeout: z.ZodOptional<z.ZodNumber>;
23
+ parse_response: z.ZodOptional<z.ZodBoolean>;
24
+ decode: z.ZodOptional<z.ZodBoolean>;
25
+ parse_cookies: z.ZodOptional<z.ZodBoolean>;
26
+ cookies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
27
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
28
+ auth: z.ZodOptional<z.ZodEnum<{
29
+ auto: "auto";
30
+ digest: "digest";
31
+ basic: "basic";
32
+ }>>;
33
+ username: z.ZodOptional<z.ZodString>;
34
+ password: z.ZodOptional<z.ZodString>;
35
+ proxy: z.ZodOptional<z.ZodString>;
36
+ agent: z.ZodOptional<z.ZodAny>;
37
+ rejectUnauthorized: z.ZodOptional<z.ZodBoolean>;
38
+ output: z.ZodOptional<z.ZodString>;
39
+ parse: z.ZodOptional<z.ZodBoolean>;
40
+ multipart: z.ZodOptional<z.ZodBoolean>;
41
+ open_timeout: z.ZodOptional<z.ZodNumber>;
42
+ response_timeout: z.ZodOptional<z.ZodNumber>;
43
+ keepAlive: z.ZodOptional<z.ZodBoolean>;
44
+ }, z.core.$strip>>;
45
+ throwOnGetNotFound: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
46
+ useConsoleLogger: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
47
+ '~emitter': z.ZodOptional<z.ZodAny>;
48
+ '~normalizedLogger': z.ZodOptional<z.ZodAny>;
49
+ }, z.core.$strict>, z.ZodObject<{
50
+ json: z.ZodBoolean;
51
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
52
+ parse_response: z.ZodOptional<z.ZodBoolean>;
53
+ }, z.core.$strip>], null>, z.ZodObject<{
54
+ json: z.ZodOptional<z.ZodBoolean>;
55
+ compressed: z.ZodOptional<z.ZodBoolean>;
56
+ follow_max: z.ZodOptional<z.ZodNumber>;
57
+ follow_set_cookie: z.ZodOptional<z.ZodBoolean>;
58
+ follow_set_referer: z.ZodOptional<z.ZodBoolean>;
59
+ follow: z.ZodOptional<z.ZodNumber>;
60
+ timeout: z.ZodOptional<z.ZodNumber>;
61
+ read_timeout: z.ZodOptional<z.ZodNumber>;
62
+ parse_response: z.ZodOptional<z.ZodBoolean>;
63
+ decode: z.ZodOptional<z.ZodBoolean>;
64
+ parse_cookies: z.ZodOptional<z.ZodBoolean>;
65
+ cookies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
66
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
67
+ auth: z.ZodOptional<z.ZodEnum<{
68
+ auto: "auto";
69
+ digest: "digest";
70
+ basic: "basic";
71
+ }>>;
72
+ username: z.ZodOptional<z.ZodString>;
73
+ password: z.ZodOptional<z.ZodString>;
74
+ proxy: z.ZodOptional<z.ZodString>;
75
+ agent: z.ZodOptional<z.ZodAny>;
76
+ rejectUnauthorized: z.ZodOptional<z.ZodBoolean>;
77
+ output: z.ZodOptional<z.ZodString>;
78
+ parse: z.ZodOptional<z.ZodBoolean>;
79
+ multipart: z.ZodOptional<z.ZodBoolean>;
80
+ open_timeout: z.ZodOptional<z.ZodNumber>;
81
+ response_timeout: z.ZodOptional<z.ZodNumber>;
82
+ keepAlive: z.ZodOptional<z.ZodBoolean>;
83
+ }, z.core.$strip>>;
84
+ export type MergeNeedleOptsSchema = z.infer<typeof MergeNeedleOpts>;
85
+ //# sourceMappingURL=util.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.mts","sourceRoot":"","sources":["../../../schema/util.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAG1B,CAAA;AACF,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("tsdown").UserConfig[];
2
+ export default _default;
3
+ //# sourceMappingURL=tsdown.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tsdown.config.d.ts","sourceRoot":"","sources":["../../tsdown.config.ts"],"names":[],"mappings":";AAEA,wBAaE"}
@@ -0,0 +1,60 @@
1
+ /** The Standard Schema interface. */
2
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
3
+ /** The Standard Schema properties. */
4
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
5
+ }
6
+ export declare namespace StandardSchemaV1 {
7
+ /** The Standard Schema properties interface. */
8
+ interface Props<Input = unknown, Output = Input> {
9
+ /** The version number of the standard. */
10
+ readonly version: 1;
11
+ /** The vendor name of the schema library. */
12
+ readonly vendor: string;
13
+ /** Validates unknown input values. */
14
+ readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
15
+ /** Inferred types associated with the schema. */
16
+ readonly types?: Types<Input, Output> | undefined;
17
+ }
18
+ /** The result interface of the validate function. */
19
+ type Result<Output> = SuccessResult<Output> | FailureResult;
20
+ /** The result interface if validation succeeds. */
21
+ interface SuccessResult<Output> {
22
+ /** The typed output value. */
23
+ readonly value: Output;
24
+ /** A falsy value for `issues` indicates success. */
25
+ readonly issues?: undefined;
26
+ }
27
+ interface Options {
28
+ /** Explicit support for additional vendor-specific parameters, if needed. */
29
+ readonly libraryOptions?: Record<string, unknown> | undefined;
30
+ }
31
+ /** The result interface if validation fails. */
32
+ interface FailureResult {
33
+ /** The issues of failed validation. */
34
+ readonly issues: ReadonlyArray<Issue>;
35
+ }
36
+ /** The issue interface of the failure output. */
37
+ interface Issue {
38
+ /** The error message of the issue. */
39
+ readonly message: string;
40
+ /** The path of the issue, if any. */
41
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
42
+ }
43
+ /** The path segment interface of the issue. */
44
+ interface PathSegment {
45
+ /** The key representing a path segment. */
46
+ readonly key: PropertyKey;
47
+ }
48
+ /** The Standard Schema types interface. */
49
+ interface Types<Input = unknown, Output = Input> {
50
+ /** The input type of the schema. */
51
+ readonly input: Input;
52
+ /** The output type of the schema. */
53
+ readonly output: Output;
54
+ }
55
+ /** Infers the input type of a Standard Schema. */
56
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
57
+ /** Infers the output type of a Standard Schema. */
58
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
59
+ }
60
+ //# sourceMappingURL=standard-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-schema.d.ts","sourceRoot":"","sources":["../../standard-schema.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAC/D,sCAAsC;IACtC,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;CAC5D;AAED,MAAM,CAAC,OAAO,WAAW,gBAAgB,CAAC;IACxC,gDAAgD;IAChD,UAAiB,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;QACpD,0CAA0C;QAC1C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;QACnB,6CAA6C;QAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;QACvB,sCAAsC;QACtC,QAAQ,CAAC,QAAQ,EAAE,CACjB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,GAAG,SAAS,KAC3C,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;QAC7C,iDAAiD;QACjD,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;KAClD;IAED,qDAAqD;IACrD,KAAY,MAAM,CAAC,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAA;IAElE,mDAAmD;IACnD,UAAiB,aAAa,CAAC,MAAM;QACnC,8BAA8B;QAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;QACtB,oDAAoD;QACpD,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAA;KAC5B;IAED,UAAiB,OAAO;QACtB,6EAA6E;QAC7E,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;KAC9D;IAED,gDAAgD;IAChD,UAAiB,aAAa;QAC5B,uCAAuC;QACvC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;KACtC;IAED,iDAAiD;IACjD,UAAiB,KAAK;QACpB,sCAAsC;QACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;QACxB,qCAAqC;QACrC,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,SAAS,CAAA;KACrE;IAED,+CAA+C;IAC/C,UAAiB,WAAW;QAC1B,2CAA2C;QAC3C,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAA;KAC1B;IAED,2CAA2C;IAC3C,UAAiB,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;QACpD,oCAAoC;QACpC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;QACrB,qCAAqC;QACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KACxB;IAED,kDAAkD;IAClD,KAAY,UAAU,CAAC,MAAM,SAAS,gBAAgB,IAAI,WAAW,CACnE,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAC7B,CAAC,OAAO,CAAC,CAAA;IAEV,mDAAmD;IACnD,KAAY,WAAW,CAAC,MAAM,SAAS,gBAAgB,IAAI,WAAW,CACpE,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAC7B,CAAC,QAAQ,CAAC,CAAA;CACZ"}
@@ -0,0 +1,76 @@
1
+ /** The Standard Schema interface. */
2
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
3
+ /** The Standard Schema properties. */
4
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>
5
+ }
6
+
7
+ export declare namespace StandardSchemaV1 {
8
+ /** The Standard Schema properties interface. */
9
+ export interface Props<Input = unknown, Output = Input> {
10
+ /** The version number of the standard. */
11
+ readonly version: 1
12
+ /** The vendor name of the schema library. */
13
+ readonly vendor: string
14
+ /** Validates unknown input values. */
15
+ readonly validate: (
16
+ value: unknown,
17
+ options?: StandardSchemaV1.Options | undefined
18
+ ) => Result<Output> | Promise<Result<Output>>
19
+ /** Inferred types associated with the schema. */
20
+ readonly types?: Types<Input, Output> | undefined
21
+ }
22
+
23
+ /** The result interface of the validate function. */
24
+ export type Result<Output> = SuccessResult<Output> | FailureResult
25
+
26
+ /** The result interface if validation succeeds. */
27
+ export interface SuccessResult<Output> {
28
+ /** The typed output value. */
29
+ readonly value: Output
30
+ /** A falsy value for `issues` indicates success. */
31
+ readonly issues?: undefined
32
+ }
33
+
34
+ export interface Options {
35
+ /** Explicit support for additional vendor-specific parameters, if needed. */
36
+ readonly libraryOptions?: Record<string, unknown> | undefined
37
+ }
38
+
39
+ /** The result interface if validation fails. */
40
+ export interface FailureResult {
41
+ /** The issues of failed validation. */
42
+ readonly issues: ReadonlyArray<Issue>
43
+ }
44
+
45
+ /** The issue interface of the failure output. */
46
+ export interface Issue {
47
+ /** The error message of the issue. */
48
+ readonly message: string
49
+ /** The path of the issue, if any. */
50
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined
51
+ }
52
+
53
+ /** The path segment interface of the issue. */
54
+ export interface PathSegment {
55
+ /** The key representing a path segment. */
56
+ readonly key: PropertyKey
57
+ }
58
+
59
+ /** The Standard Schema types interface. */
60
+ export interface Types<Input = unknown, Output = Input> {
61
+ /** The input type of the schema. */
62
+ readonly input: Input
63
+ /** The output type of the schema. */
64
+ readonly output: Output
65
+ }
66
+
67
+ /** Infers the input type of a Standard Schema. */
68
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<
69
+ Schema['~standard']['types']
70
+ >['input']
71
+
72
+ /** Infers the output type of a Standard Schema. */
73
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<
74
+ Schema['~standard']['types']
75
+ >['output']
76
+ }
@@ -0,0 +1 @@
1
+ type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never
package/cjs/impl/bulk.cjs DELETED
@@ -1,275 +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 bulk_exports = {};
30
- __export(bulk_exports, {
31
- bulkGet: () => bulkGet,
32
- bulkGetDictionary: () => bulkGetDictionary,
33
- bulkRemove: () => bulkRemove,
34
- bulkSave: () => bulkSave,
35
- bulkSaveTransaction: () => bulkSaveTransaction
36
- });
37
- module.exports = __toCommonJS(bulk_exports);
38
- var import_needle = __toESM(require("needle"), 1);
39
- var import_bulk = require("../schema/bulk.cjs");
40
- var import_retry = require("./retry.cjs");
41
- var import_crud = require("./crud.cjs");
42
- var import_errors = require("./errors.cjs");
43
- var import_transactionErrors = require("./transactionErrors.cjs");
44
- var import_logger = require("./logger.cjs");
45
- var import_crud2 = require("../schema/crud.cjs");
46
- var import_trackedEmitter = require("./trackedEmitter.cjs");
47
- const bulkSave = import_bulk.BulkSave.implement(async (config, docs) => {
48
- const logger = (0, import_logger.createLogger)(config);
49
- if (!docs) {
50
- logger.warn("bulkSave called with no docs");
51
- return { ok: false, error: "noDocs", reason: "no docs provided" };
52
- }
53
- if (!docs.length) {
54
- logger.warn("bulkSave called with empty docs array");
55
- return { ok: false, error: "noDocs", reason: "no docs provided" };
56
- }
57
- logger.info(`Starting bulk save of ${docs.length} documents`);
58
- const url = `${config.couch}/_bulk_docs`;
59
- const body = { docs };
60
- const opts = {
61
- json: true,
62
- headers: {
63
- "Content-Type": "application/json"
64
- }
65
- };
66
- let resp;
67
- try {
68
- resp = await (0, import_needle.default)("post", url, body, opts);
69
- } catch (err) {
70
- logger.error("Network error during bulk save:", err);
71
- import_errors.RetryableError.handleNetworkError(err);
72
- }
73
- if (!resp) {
74
- logger.error("No response received from bulk save request");
75
- throw new import_errors.RetryableError("no response", 503);
76
- }
77
- if (import_errors.RetryableError.isRetryableStatusCode(resp.statusCode)) {
78
- logger.warn(`Retryable status code received: ${resp.statusCode}`);
79
- throw new import_errors.RetryableError("retryable error during bulk save", resp.statusCode);
80
- }
81
- if (resp.statusCode !== 201) {
82
- logger.error(`Unexpected status code: ${resp.statusCode}`);
83
- throw new Error("could not save");
84
- }
85
- const results = resp?.body || [];
86
- return results;
87
- });
88
- const bulkGet = import_bulk.BulkGet.implement(async (config, ids) => {
89
- const logger = (0, import_logger.createLogger)(config);
90
- const keys = ids;
91
- logger.info(`Starting bulk get for ${keys.length} documents`);
92
- const url = `${config.couch}/_all_docs?include_docs=true`;
93
- const payload = { keys };
94
- const opts = {
95
- json: true,
96
- headers: {
97
- "Content-Type": "application/json"
98
- }
99
- };
100
- let resp;
101
- try {
102
- resp = await (0, import_needle.default)("post", url, payload, opts);
103
- } catch (err) {
104
- logger.error("Network error during bulk get:", err);
105
- import_errors.RetryableError.handleNetworkError(err);
106
- }
107
- if (!resp) {
108
- logger.error("No response received from bulk get request");
109
- throw new import_errors.RetryableError("no response", 503);
110
- }
111
- if (import_errors.RetryableError.isRetryableStatusCode(resp.statusCode)) {
112
- logger.warn(`Retryable status code received: ${resp.statusCode}`);
113
- throw new import_errors.RetryableError("retryable error during bulk get", resp.statusCode);
114
- }
115
- if (resp.statusCode !== 200) {
116
- logger.error(`Unexpected status code: ${resp.statusCode}`);
117
- throw new Error("could not fetch");
118
- }
119
- const body = resp.body;
120
- return body;
121
- });
122
- const bulkRemove = import_bulk.BulkRemove.implement(async (config, ids) => {
123
- const logger = (0, import_logger.createLogger)(config);
124
- logger.info(`Starting bulk remove for ${ids.length} documents`);
125
- const resp = await bulkGet(config, ids);
126
- const toRemove = [];
127
- resp.rows.forEach((row) => {
128
- if (!row.doc) return;
129
- try {
130
- const d = import_crud2.CouchDoc.parse(row.doc);
131
- d._deleted = true;
132
- toRemove.push(d);
133
- } catch (e) {
134
- logger.warn(`Invalid document structure in bulk remove: ${row.id}`, e);
135
- }
136
- });
137
- if (!toRemove.length) return [];
138
- const result = await bulkSave(config, toRemove);
139
- return result;
140
- });
141
- const bulkGetDictionary = import_bulk.BulkGetDictionary.implement(async (config, ids) => {
142
- const resp = await bulkGet(config, ids);
143
- const results = { found: {}, notFound: {} };
144
- resp.rows.forEach(
145
- /** @param { import('../schema/query.mjs').ViewRowSchema } row */
146
- (row) => {
147
- if (!row.key) return;
148
- if (row.error) {
149
- results.notFound[row.key] = row;
150
- return;
151
- }
152
- try {
153
- const doc = import_crud2.CouchDoc.parse(row.doc);
154
- results.found[doc._id] = doc;
155
- } catch (e) {
156
- results.notFound[row.key] = row;
157
- }
158
- }
159
- );
160
- return results;
161
- });
162
- const bulkSaveTransaction = import_bulk.BulkSaveTransaction.implement(async (config, transactionId, docs) => {
163
- const emitter = (0, import_trackedEmitter.setupEmitter)(config);
164
- const logger = (0, import_logger.createLogger)(config);
165
- const retryOptions = {
166
- maxRetries: config.maxRetries ?? 10,
167
- initialDelay: config.initialDelay ?? 1e3,
168
- backoffFactor: config.backoffFactor ?? 2
169
- };
170
- const _put = config.bindWithRetry ? (0, import_retry.withRetry)(import_crud.put.bind(null, config), retryOptions) : import_crud.put.bind(null, config);
171
- logger.info(`Starting bulk save transaction ${transactionId} for ${docs.length} documents`);
172
- const txnDoc = {
173
- _id: `txn:${transactionId}`,
174
- _rev: null,
175
- type: "transaction",
176
- status: "pending",
177
- changes: docs,
178
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
179
- };
180
- let txnresp = await _put(txnDoc);
181
- logger.debug("Transaction document created:", txnDoc, txnresp);
182
- await emitter.emit("transaction-created", { txnresp, txnDoc });
183
- if (txnresp.error) {
184
- throw new import_transactionErrors.TransactionSetupError("Failed to create transaction document", {
185
- error: txnresp.error,
186
- response: txnresp.body
187
- });
188
- }
189
- const existingDocs = await bulkGetDictionary(config, docs.map((d) => d._id));
190
- logger.debug("Fetched current revisions of documents:", existingDocs);
191
- await emitter.emit("transaction-revs-fetched", existingDocs);
192
- const revErrors = [];
193
- docs.forEach((d) => {
194
- if (existingDocs.found[d._id] && existingDocs.found[d._id]._rev !== d._rev) revErrors.push(d._id);
195
- if (existingDocs.notFound[d._id] && d._rev) revErrors.push(d._id);
196
- });
197
- if (revErrors.length > 0) {
198
- throw new import_transactionErrors.TransactionVersionConflictError(revErrors);
199
- }
200
- logger.debug("Checked document revisions:", existingDocs);
201
- await emitter.emit("transaction-revs-checked", existingDocs);
202
- const providedDocsById = {};
203
- docs.forEach((d) => {
204
- if (!d._id) return;
205
- providedDocsById[d._id] = d;
206
- });
207
- const newDocsToRollback = [];
208
- const potentialExistingDocsToRollack = [];
209
- const failedDocs = [];
210
- try {
211
- logger.info("Transaction started:", txnDoc);
212
- await emitter.emit("transaction-started", txnDoc);
213
- const results = await bulkSave(config, docs);
214
- logger.info("Transaction updates applied:", results);
215
- await emitter.emit("transaction-updates-applied", results);
216
- results.forEach((r) => {
217
- if (!r.id) return;
218
- if (!r.error) {
219
- if (existingDocs.notFound[r.id]) newDocsToRollback.push(r);
220
- if (existingDocs.found[r.id]) potentialExistingDocsToRollack.push(r);
221
- } else {
222
- failedDocs.push(r);
223
- }
224
- });
225
- if (failedDocs.length > 0) {
226
- throw new import_transactionErrors.TransactionBulkOperationError(failedDocs);
227
- }
228
- txnDoc.status = "completed";
229
- txnDoc._rev = txnresp.rev;
230
- txnresp = await _put(txnDoc);
231
- logger.info("Transaction completed:", txnDoc);
232
- await emitter.emit("transaction-completed", { txnresp, txnDoc });
233
- if (txnresp.statusCode !== 201) {
234
- logger.error("Failed to update transaction status to completed");
235
- }
236
- return results;
237
- } catch (error) {
238
- logger.error("Transaction failed, attempting rollback:", error);
239
- const toRollback = [];
240
- potentialExistingDocsToRollack.forEach((row) => {
241
- if (!row.id || !row.rev) return;
242
- const doc = existingDocs.found[row.id];
243
- doc._rev = row.rev;
244
- toRollback.push(doc);
245
- });
246
- newDocsToRollback.forEach((d) => {
247
- if (!d.id || !d.rev) return;
248
- const before = JSON.parse(JSON.stringify(providedDocsById[d.id]));
249
- before._rev = d.rev;
250
- before._deleted = true;
251
- toRollback.push(before);
252
- });
253
- const bulkRollbackResult = await bulkSave(config, toRollback);
254
- let status = "rolled_back";
255
- bulkRollbackResult.forEach((r) => {
256
- if (r.error) status = "rollback_failed";
257
- });
258
- logger.warn("Transaction rolled back:", { bulkRollbackResult, status });
259
- await emitter.emit("transaction-rolled-back", { bulkRollbackResult, status });
260
- txnDoc.status = status;
261
- txnDoc._rev = txnresp.rev;
262
- txnresp = await _put(txnDoc);
263
- logger.warn("Transaction rollback status updated:", txnDoc);
264
- await emitter.emit("transaction-rolled-back-status", { txnresp, txnDoc });
265
- if (txnresp.statusCode !== 201) {
266
- logger.error("Failed to update transaction status to rolled_back");
267
- }
268
- throw new import_transactionErrors.TransactionRollbackError(
269
- "Transaction failed and rollback was unsuccessful",
270
- /** @type {Error} */
271
- error,
272
- bulkRollbackResult
273
- );
274
- }
275
- });
@@ -1,67 +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 changes_exports = {};
30
- __export(changes_exports, {
31
- changes: () => changes
32
- });
33
- module.exports = __toCommonJS(changes_exports);
34
- var import_needle = __toESM(require("needle"), 1);
35
- var import_events = require("events");
36
- var import_changes = require("../schema/changes.cjs");
37
- var import_changes_stream = __toESM(require("changes-stream"), 1);
38
- const changes = import_changes.Changes.implement(async (config, onChange, options = {}) => {
39
- const emitter = new import_events.EventEmitter();
40
- options.db = config.couch;
41
- if (options.since && options.since === "now") {
42
- const opts = {
43
- json: true,
44
- headers: {
45
- "Content-Type": "application/json"
46
- }
47
- };
48
- const resp = await (0, import_needle.default)("get", config.couch, opts);
49
- options.since = resp.body.update_seq;
50
- }
51
- const changes2 = (0, import_changes_stream.default)(options);
52
- changes2.on("readable", () => {
53
- const change = changes2.read();
54
- if (change.results && Array.isArray(change.results)) {
55
- change.results.forEach((c) => emitter.emit("change", c));
56
- } else emitter.emit("change", change);
57
- });
58
- emitter.on("change", onChange);
59
- return {
60
- on: (event, listener) => emitter.on(event, listener),
61
- removeListener: (event, listener) => emitter.removeListener(event, listener),
62
- stop: () => {
63
- changes2.destroy();
64
- emitter.removeAllListeners();
65
- }
66
- };
67
- });