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
@@ -1,53 +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
- PatchBound: () => PatchBound,
23
- PatchDangerously: () => PatchDangerously,
24
- PatchDangerouslyBound: () => PatchDangerouslyBound,
25
- PatchProperties: () => PatchProperties,
26
- StrictPatchProperties: () => StrictPatchProperties
27
- });
28
- module.exports = __toCommonJS(patch_exports);
29
- var import_zod = require("zod");
30
- var import_config = require("./config.cjs");
31
- var import_crud = require("./crud.cjs");
32
- const PatchProperties = import_zod.z.record(import_zod.z.string(), import_zod.z.any());
33
- const StrictPatchProperties = import_zod.z.object({
34
- _rev: import_zod.z.string()
35
- }).and(PatchProperties);
36
- const Patch = import_zod.z.function().args(
37
- import_config.CouchConfig,
38
- import_zod.z.string().describe("the couch doc id"),
39
- StrictPatchProperties
40
- ).returns(import_zod.z.promise(import_crud.CouchDocResponse));
41
- const PatchBound = import_zod.z.function().args(
42
- import_zod.z.string().describe("the couch doc id"),
43
- StrictPatchProperties
44
- ).returns(import_zod.z.promise(import_crud.CouchDocResponse));
45
- const PatchDangerously = import_zod.z.function().args(
46
- import_config.CouchConfig,
47
- import_zod.z.string().describe("the couch doc id"),
48
- PatchProperties
49
- ).returns(import_zod.z.promise(import_crud.CouchDocResponse));
50
- const PatchDangerouslyBound = import_zod.z.function().args(
51
- import_zod.z.string().describe("the couch doc id"),
52
- PatchProperties
53
- ).returns(import_zod.z.promise(import_crud.CouchDocResponse));
@@ -1,62 +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 query_exports = {};
20
- __export(query_exports, {
21
- SimpleViewOptions: () => SimpleViewOptions,
22
- SimpleViewQuery: () => SimpleViewQuery,
23
- SimpleViewQueryBound: () => SimpleViewQueryBound,
24
- SimpleViewQueryResponse: () => SimpleViewQueryResponse,
25
- ViewRow: () => ViewRow
26
- });
27
- module.exports = __toCommonJS(query_exports);
28
- var import_zod = require("zod");
29
- var import_config = require("./config.cjs");
30
- const ViewRow = import_zod.z.object({
31
- id: import_zod.z.string().optional(),
32
- key: import_zod.z.any().nullable(),
33
- value: import_zod.z.any().nullable(),
34
- doc: import_zod.z.object({}).passthrough().optional().nullish(),
35
- error: import_zod.z.string().optional().describe("usually not_found, if something is wrong with this doc")
36
- });
37
- const SimpleViewQueryResponse = import_zod.z.object({
38
- error: import_zod.z.string().optional().describe("if something is wrong"),
39
- rows: import_zod.z.array(ViewRow)
40
- }).passthrough();
41
- const SimpleViewOptions = import_zod.z.object({
42
- startkey: import_zod.z.any().optional(),
43
- endkey: import_zod.z.any().optional(),
44
- descending: import_zod.z.boolean().optional().describe("sort results descending"),
45
- skip: import_zod.z.number().nonnegative().optional().describe("skip this many rows"),
46
- limit: import_zod.z.number().nonnegative().optional().describe("limit the results to this many rows"),
47
- key: import_zod.z.any().optional(),
48
- keys: import_zod.z.array(import_zod.z.any()).optional(),
49
- include_docs: import_zod.z.boolean().optional().describe("join the id to the doc and return it"),
50
- reduce: import_zod.z.boolean().optional().describe("reduce the results"),
51
- group: import_zod.z.boolean().optional().describe("group the results"),
52
- group_level: import_zod.z.number().positive().optional().describe("group the results at this level")
53
- }).optional().describe("query options");
54
- const SimpleViewQuery = import_zod.z.function().args(
55
- import_config.CouchConfig,
56
- import_zod.z.string().describe("the view name"),
57
- SimpleViewOptions
58
- ).returns(import_zod.z.promise(SimpleViewQueryResponse));
59
- const SimpleViewQueryBound = import_zod.z.function().args(
60
- import_zod.z.string().describe("the view name"),
61
- SimpleViewOptions
62
- ).returns(import_zod.z.promise(SimpleViewQueryResponse));
@@ -1,42 +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 stream_exports = {};
20
- __export(stream_exports, {
21
- OnRow: () => OnRow,
22
- SimpleViewQueryStream: () => SimpleViewQueryStream,
23
- SimpleViewQueryStreamBound: () => SimpleViewQueryStreamBound
24
- });
25
- module.exports = __toCommonJS(stream_exports);
26
- var import_zod = require("zod");
27
- var import_config = require("./config.cjs");
28
- var import_query = require("./query.cjs");
29
- const OnRow = import_zod.z.function().args(
30
- import_query.ViewRow
31
- );
32
- const SimpleViewQueryStream = import_zod.z.function().args(
33
- import_config.CouchConfig,
34
- import_zod.z.string().describe("the view name"),
35
- import_query.SimpleViewOptions,
36
- OnRow
37
- ).returns(import_zod.z.promise(import_zod.z.undefined()));
38
- const SimpleViewQueryStreamBound = import_zod.z.function().args(
39
- import_zod.z.string().describe("the view name"),
40
- import_query.SimpleViewOptions,
41
- OnRow
42
- ).returns(import_zod.z.promise(import_zod.z.undefined()));
@@ -1,59 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var lock_exports = {};
20
- __export(lock_exports, {
21
- CreateLock: () => CreateLock,
22
- CreateLockBound: () => CreateLockBound,
23
- Lock: () => Lock,
24
- LockOptions: () => LockOptions,
25
- RemoveLock: () => RemoveLock,
26
- RemoveLockBound: () => RemoveLockBound
27
- });
28
- module.exports = __toCommonJS(lock_exports);
29
- var import_zod = require("zod");
30
- var import_config = require("../config.cjs");
31
- var import_crud = require("../crud.cjs");
32
- const Lock = import_crud.CouchDoc.extend({
33
- type: import_zod.z.literal("lock"),
34
- locks: import_zod.z.string().describe("the document ID being locked"),
35
- lockedAt: import_zod.z.string().describe("ISO timestamp when lock was created"),
36
- lockedBy: import_zod.z.string().describe("username of who created the lock")
37
- });
38
- const LockOptions = import_zod.z.object({
39
- enableLocking: import_zod.z.boolean().default(true).describe("whether locking is enabled"),
40
- username: import_zod.z.string().describe("username to attribute locks to")
41
- });
42
- const CreateLock = import_zod.z.function().args(
43
- import_config.CouchConfig,
44
- import_zod.z.string().describe("document ID to lock"),
45
- LockOptions
46
- ).returns(import_zod.z.promise(import_zod.z.boolean()));
47
- const CreateLockBound = import_zod.z.function().args(
48
- import_zod.z.string().describe("document ID to lock"),
49
- LockOptions
50
- ).returns(import_zod.z.promise(import_zod.z.boolean()));
51
- const RemoveLock = import_zod.z.function().args(
52
- import_config.CouchConfig,
53
- import_zod.z.string().describe("document ID to unlock"),
54
- LockOptions
55
- ).returns(import_zod.z.promise(import_zod.z.void()));
56
- const RemoveLockBound = import_zod.z.function().args(
57
- import_zod.z.string().describe("document ID to unlock"),
58
- LockOptions
59
- ).returns(import_zod.z.promise(import_zod.z.void()));
@@ -1,42 +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 watch_exports = {};
20
- __export(watch_exports, {
21
- WatchDocs: () => WatchDocs,
22
- WatchDocsBound: () => WatchDocsBound,
23
- WatchOptions: () => WatchOptions
24
- });
25
- module.exports = __toCommonJS(watch_exports);
26
- var import_zod = require("zod");
27
- var import_config = require("../config.cjs");
28
- var import_changes = require("../changes.cjs");
29
- const WatchOptions = import_zod.z.object({
30
- include_docs: import_zod.z.boolean().default(false)
31
- }).partial();
32
- const WatchDocs = import_zod.z.function().args(
33
- import_config.CouchConfig,
34
- import_zod.z.union([import_zod.z.string(), import_zod.z.array(import_zod.z.string())]),
35
- import_zod.z.function().args(import_zod.z.any()).returns(import_zod.z.void()),
36
- WatchOptions
37
- ).returns(import_changes.ChangesEmitter);
38
- const WatchDocsBound = import_zod.z.function().args(
39
- import_zod.z.union([import_zod.z.string(), import_zod.z.array(import_zod.z.string())]),
40
- import_zod.z.function().args(import_zod.z.any()).returns(import_zod.z.void()),
41
- WatchOptions
42
- ).returns(import_changes.ChangesEmitter);
@@ -1,39 +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 util_exports = {};
20
- __export(util_exports, {
21
- DBInfo: () => DBInfo,
22
- GetDBInfo: () => GetDBInfo,
23
- GetDBInfoBound: () => GetDBInfoBound
24
- });
25
- module.exports = __toCommonJS(util_exports);
26
- var import_zod = require("zod");
27
- var import_config = require("./config.cjs");
28
- const DBInfo = import_zod.z.object({
29
- db_name: import_zod.z.string(),
30
- doc_count: import_zod.z.number(),
31
- update_seq: import_zod.z.number(),
32
- compact_running: import_zod.z.boolean().nullish(),
33
- disk_size: import_zod.z.number().nullish(),
34
- committed_update_seq: import_zod.z.number().nullish()
35
- }).passthrough();
36
- const GetDBInfo = import_zod.z.function().args(
37
- import_config.CouchConfig
38
- ).returns(import_zod.z.promise(DBInfo));
39
- const GetDBInfoBound = import_zod.z.function().args().returns(import_zod.z.promise(DBInfo));
package/config.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "couchdb": {
3
- "uuid": "92fcdcf8-7d8a-4a1a-896c-fba3fa7eb623"
4
- }
5
- }
package/docs/compiler.png DELETED
Binary file
@@ -1,11 +0,0 @@
1
- {
2
- "esbuild": {
3
- "entryPoints": {
4
- "ignore": [
5
- "./node_modules/**/*",
6
- "./tests/**",
7
- "./temp/**"
8
- ]
9
- }
10
- }
11
- }
package/impl/bulk.d.mts DELETED
@@ -1,11 +0,0 @@
1
- /** @type { import('../schema/bulk.mjs').BulkSaveSchema } */
2
- export const bulkSave: import("../schema/bulk.mjs").BulkSaveSchema;
3
- /** @type { import('../schema/bulk.mjs').BulkGetSchema } */
4
- export const bulkGet: import("../schema/bulk.mjs").BulkGetSchema;
5
- /** @type { import('../schema/bulk.mjs').BulkRemoveSchema } */
6
- export const bulkRemove: import("../schema/bulk.mjs").BulkRemoveSchema;
7
- /** @type { import('../schema/bulk.mjs').BulkGetDictionarySchema } */
8
- export const bulkGetDictionary: import("../schema/bulk.mjs").BulkGetDictionarySchema;
9
- /** @type { import('../schema/bulk.mjs').BulkSaveTransactionSchema } bulkSaveTransaction */
10
- export const bulkSaveTransaction: import("../schema/bulk.mjs").BulkSaveTransactionSchema;
11
- //# sourceMappingURL=bulk.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bulk.d.mts","sourceRoot":"","sources":["bulk.mjs"],"names":[],"mappings":"AAWA,4DAA4D;AAC5D,uBADY,OAAO,oBAAoB,EAAE,cAAc,CA4CrD;AAEF,2DAA2D;AAC3D,sBADY,OAAO,oBAAoB,EAAE,aAAa,CAoCpD;AAIF,8DAA8D;AAC9D,yBADY,OAAO,oBAAoB,EAAE,gBAAgB,CAoBvD;AAEF,qEAAqE;AACrE,gCADY,OAAO,oBAAoB,EAAE,uBAAuB,CAwB9D;AAEF,2FAA2F;AAC3F,kCADY,OAAO,oBAAoB,EAAE,yBAAyB,CAiJhE"}
package/impl/bulk.mjs DELETED
@@ -1,291 +0,0 @@
1
- // @ts-check
2
- import needle from 'needle'
3
- import { BulkSave, BulkGet, BulkRemove, BulkGetDictionary, BulkSaveTransaction } from '../schema/bulk.mjs'
4
- import { withRetry } from './retry.mjs'
5
- import { put } from './crud.mjs'
6
- import { RetryableError } from './errors.mjs'
7
- import { TransactionSetupError, TransactionVersionConflictError, TransactionBulkOperationError, TransactionRollbackError } from './transactionErrors.mjs'
8
- import { createLogger } from './logger.mjs'
9
- import { CouchDoc } from '../schema/crud.mjs'
10
- import { setupEmitter } from './trackedEmitter.mjs'
11
-
12
- /** @type { import('../schema/bulk.mjs').BulkSaveSchema } */
13
- export const bulkSave = BulkSave.implement(async (config, docs) => {
14
- /** @type {import('./logger.mjs').Logger } */
15
- const logger = createLogger(config)
16
-
17
- if (!docs) {
18
- logger.warn('bulkSave called with no docs')
19
- return { ok: false, error: 'noDocs', reason: 'no docs provided' }
20
- }
21
- if (!docs.length) {
22
- logger.warn('bulkSave called with empty docs array')
23
- return { ok: false, error: 'noDocs', reason: 'no docs provided' }
24
- }
25
-
26
- logger.info(`Starting bulk save of ${docs.length} documents`)
27
- const url = `${config.couch}/_bulk_docs`
28
- const body = { docs }
29
- const opts = {
30
- json: true,
31
- headers: {
32
- 'Content-Type': 'application/json'
33
- }
34
- }
35
- let resp
36
- try {
37
- resp = await needle('post', url, body, opts)
38
- } catch (err) {
39
- logger.error('Network error during bulk save:', err)
40
- RetryableError.handleNetworkError(err)
41
- }
42
- if (!resp) {
43
- logger.error('No response received from bulk save request')
44
- throw new RetryableError('no response', 503)
45
- }
46
- if (RetryableError.isRetryableStatusCode(resp.statusCode)) {
47
- logger.warn(`Retryable status code received: ${resp.statusCode}`)
48
- throw new RetryableError('retryable error during bulk save', resp.statusCode)
49
- }
50
- if (resp.statusCode !== 201) {
51
- logger.error(`Unexpected status code: ${resp.statusCode}`)
52
- throw new Error('could not save')
53
- }
54
- const results = resp?.body || []
55
- return results
56
- })
57
-
58
- /** @type { import('../schema/bulk.mjs').BulkGetSchema } */
59
- export const bulkGet = BulkGet.implement(async (config, ids) => {
60
- const logger = createLogger(config)
61
- const keys = ids
62
-
63
- logger.info(`Starting bulk get for ${keys.length} documents`)
64
- const url = `${config.couch}/_all_docs?include_docs=true`
65
- const payload = { keys }
66
- const opts = {
67
- json: true,
68
- headers: {
69
- 'Content-Type': 'application/json'
70
- }
71
- }
72
- let resp
73
- try {
74
- resp = await needle('post', url, payload, opts)
75
- } catch (err) {
76
- logger.error('Network error during bulk get:', err)
77
- RetryableError.handleNetworkError(err)
78
- }
79
- if (!resp) {
80
- logger.error('No response received from bulk get request')
81
- throw new RetryableError('no response', 503)
82
- }
83
- if (RetryableError.isRetryableStatusCode(resp.statusCode)) {
84
- logger.warn(`Retryable status code received: ${resp.statusCode}`)
85
- throw new RetryableError('retryable error during bulk get', resp.statusCode)
86
- }
87
- if (resp.statusCode !== 200) {
88
- logger.error(`Unexpected status code: ${resp.statusCode}`)
89
- throw new Error('could not fetch')
90
- }
91
- /** @type { import('../schema/query.mjs').SimpleViewQueryResponseSchema } body */
92
- const body = resp.body
93
- return body
94
- })
95
-
96
- // sugar methods
97
-
98
- /** @type { import('../schema/bulk.mjs').BulkRemoveSchema } */
99
- export const bulkRemove = BulkRemove.implement(async (config, ids) => {
100
- const logger = createLogger(config)
101
- logger.info(`Starting bulk remove for ${ids.length} documents`)
102
- const resp = await bulkGet(config, ids)
103
- /** @type { Array<import('../schema/crud.mjs').CouchDocSchema> } toRemove */
104
- const toRemove = []
105
- resp.rows.forEach(row => {
106
- if (!row.doc) return
107
- try {
108
- const d = CouchDoc.parse(row.doc)
109
- d._deleted = true
110
- toRemove.push(d)
111
- } catch (e) {
112
- logger.warn(`Invalid document structure in bulk remove: ${row.id}`, e)
113
- }
114
- })
115
- if (!toRemove.length) return []
116
- const result = await bulkSave(config, toRemove)
117
- return result
118
- })
119
-
120
- /** @type { import('../schema/bulk.mjs').BulkGetDictionarySchema } */
121
- export const bulkGetDictionary = BulkGetDictionary.implement(async (config, ids) => {
122
- const resp = await bulkGet(config, ids)
123
-
124
- /** @type { import('../schema/bulk.mjs').BulkGetDictionaryResponseSchema } results */
125
- const results = { found: {}, notFound: {} }
126
-
127
- resp.rows.forEach(
128
- /** @param { import('../schema/query.mjs').ViewRowSchema } row */
129
- row => {
130
- if (!row.key) return
131
- if (row.error) {
132
- results.notFound[row.key] = row
133
- return
134
- }
135
- try {
136
- /** @type { import('../schema/crud.mjs').CouchDocSchema } doc */
137
- const doc = CouchDoc.parse(row.doc)
138
- results.found[doc._id] = doc
139
- } catch (e) {
140
- results.notFound[row.key] = row
141
- }
142
- })
143
- return results
144
- })
145
-
146
- /** @type { import('../schema/bulk.mjs').BulkSaveTransactionSchema } bulkSaveTransaction */
147
- export const bulkSaveTransaction = BulkSaveTransaction.implement(async (config, transactionId, docs) => {
148
- const emitter = setupEmitter(config)
149
- const logger = createLogger(config)
150
- const retryOptions = {
151
- maxRetries: config.maxRetries ?? 10,
152
- initialDelay: config.initialDelay ?? 1000,
153
- backoffFactor: config.backoffFactor ?? 2
154
- }
155
- const _put = config.bindWithRetry ? withRetry(put.bind(null, config), retryOptions) : put.bind(null, config)
156
- logger.info(`Starting bulk save transaction ${transactionId} for ${docs.length} documents`)
157
-
158
- // Create transaction document
159
- const txnDoc = {
160
- _id: `txn:${transactionId}`,
161
- _rev: null,
162
- type: 'transaction',
163
- status: 'pending',
164
- changes: docs,
165
- timestamp: new Date().toISOString()
166
- }
167
-
168
- // Save transaction document
169
- let txnresp = await _put(txnDoc)
170
- logger.debug('Transaction document created:', txnDoc, txnresp)
171
- await emitter.emit('transaction-created', { txnresp, txnDoc })
172
- if (txnresp.error) {
173
- throw new TransactionSetupError('Failed to create transaction document', {
174
- error: txnresp.error,
175
- response: txnresp.body
176
- })
177
- }
178
-
179
- // Get current revisions of all documents
180
- const existingDocs = await bulkGetDictionary(config, docs.map(d => d._id))
181
- logger.debug('Fetched current revisions of documents:', existingDocs)
182
- await emitter.emit('transaction-revs-fetched', existingDocs)
183
-
184
- /** @type {string[]} */
185
- const revErrors = []
186
- // if any of the existingDocs, and the docs provided dont match on rev, then throw an error
187
- docs.forEach(d => {
188
- if (existingDocs.found[d._id] && existingDocs.found[d._id]._rev !== d._rev) revErrors.push(d._id)
189
- if (existingDocs.notFound[d._id] && d._rev) revErrors.push(d._id)
190
- })
191
-
192
- if (revErrors.length > 0) {
193
- throw new TransactionVersionConflictError(revErrors)
194
- }
195
- logger.debug('Checked document revisions:', existingDocs)
196
- await emitter.emit('transaction-revs-checked', existingDocs)
197
-
198
- /** @type {Record<string, import('../schema/crud.mjs').CouchDocSchema>} providedDocsById */
199
- const providedDocsById = {}
200
- docs.forEach((
201
- /** @type {import('../schema/crud.mjs').CouchDocSchema} */ d
202
- ) => {
203
- if (!d._id) return
204
- providedDocsById[d._id] = d
205
- })
206
-
207
- /** @type {import('../schema/bulk.mjs').Response} */
208
- const newDocsToRollback = []
209
- /** @type {import('../schema/bulk.mjs').Response} */
210
- const potentialExistingDocsToRollack = []
211
- /** @type {import('../schema/bulk.mjs').Response} */
212
- const failedDocs = []
213
-
214
- try {
215
- logger.info('Transaction started:', txnDoc)
216
- await emitter.emit('transaction-started', txnDoc)
217
- // Apply updates
218
- const results = await bulkSave(config, docs)
219
- logger.info('Transaction updates applied:', results)
220
- await emitter.emit('transaction-updates-applied', results)
221
-
222
- // Check for failures
223
- results.forEach(r => {
224
- if (!r.id) return // not enough info
225
- if (!r.error) {
226
- if (existingDocs.notFound[r.id]) newDocsToRollback.push(r)
227
- if (existingDocs.found[r.id]) potentialExistingDocsToRollack.push(r)
228
- } else {
229
- failedDocs.push(r)
230
- }
231
- })
232
- if (failedDocs.length > 0) {
233
- throw new TransactionBulkOperationError(failedDocs)
234
- }
235
-
236
- // Update transaction status to completed
237
- txnDoc.status = 'completed'
238
- txnDoc._rev = txnresp.rev
239
- txnresp = await _put(txnDoc)
240
- logger.info('Transaction completed:', txnDoc)
241
- await emitter.emit('transaction-completed', { txnresp, txnDoc })
242
- if (txnresp.statusCode !== 201) {
243
- logger.error('Failed to update transaction status to completed')
244
- }
245
-
246
- return results
247
- } catch (error) {
248
- logger.error('Transaction failed, attempting rollback:', error)
249
-
250
- // Rollback changes
251
- /** @type {Array<import('../schema/crud.mjs').CouchDocSchema>} */
252
- const toRollback = []
253
- potentialExistingDocsToRollack.forEach(row => {
254
- if (!row.id || !row.rev) return
255
- const doc = existingDocs.found[row.id]
256
- doc._rev = row.rev
257
- toRollback.push(doc)
258
- })
259
- newDocsToRollback.forEach(d => {
260
- if (!d.id || !d.rev) return
261
- const before = JSON.parse(JSON.stringify(providedDocsById[d.id]))
262
- before._rev = d.rev
263
- before._deleted = true
264
- toRollback.push(before)
265
- })
266
-
267
- // rollback all the changes
268
- const bulkRollbackResult = await bulkSave(config, toRollback)
269
- let status = 'rolled_back'
270
- bulkRollbackResult.forEach(r => {
271
- if (r.error) status = 'rollback_failed'
272
- })
273
- logger.warn('Transaction rolled back:', { bulkRollbackResult, status })
274
- await emitter.emit('transaction-rolled-back', { bulkRollbackResult, status })
275
-
276
- // Update transaction status to rolled back
277
- txnDoc.status = status
278
- txnDoc._rev = txnresp.rev
279
- txnresp = await _put(txnDoc)
280
- logger.warn('Transaction rollback status updated:', txnDoc)
281
- await emitter.emit('transaction-rolled-back-status', { txnresp, txnDoc })
282
- if (txnresp.statusCode !== 201) {
283
- logger.error('Failed to update transaction status to rolled_back')
284
- }
285
- throw new TransactionRollbackError(
286
- 'Transaction failed and rollback was unsuccessful',
287
- /** @type {Error} */ (error),
288
- bulkRollbackResult
289
- )
290
- }
291
- })
@@ -1,12 +0,0 @@
1
- /** @type { import('../schema/changes.mjs').ChangesSchema } */
2
- export const changes: import("../schema/changes.mjs").ChangesSchema;
3
- export type ChangeInfo = {
4
- seq: string | number;
5
- id: string;
6
- changes: Array<{
7
- rev: string;
8
- }>;
9
- deleted?: boolean;
10
- doc?: any;
11
- };
12
- //# sourceMappingURL=changes.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"changes.d.mts","sourceRoot":"","sources":["changes.mjs"],"names":[],"mappings":"AAeA,8DAA8D;AAC9D,sBADY,OAAO,uBAAuB,EAAE,aAAa,CAqCvD;yBA/CY;IACT,GAAG,EAAE,MAAM,GAAC,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,GAAG,CAAC,EAAE,GAAG,CAAA;CACV"}