hide-a-bed 5.2.8 → 6.0.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 (258) 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/eslint.config.js +15 -0
  6. package/impl/bindConfig.mts +140 -0
  7. package/impl/bulkGet.mts +256 -0
  8. package/impl/bulkRemove.mts +98 -0
  9. package/impl/bulkSave.mts +286 -0
  10. package/impl/get.mts +137 -0
  11. package/impl/getDBInfo.mts +67 -0
  12. package/impl/patch.mts +134 -0
  13. package/impl/put.mts +56 -0
  14. package/impl/query.mts +224 -0
  15. package/impl/remove.mts +65 -0
  16. package/impl/retry.mts +66 -0
  17. package/impl/stream.mts +143 -0
  18. package/impl/sugar/lock.mts +103 -0
  19. package/impl/sugar/{watch.mjs → watch.mts} +56 -22
  20. package/impl/utils/errors.mts +130 -0
  21. package/impl/utils/logger.mts +62 -0
  22. package/impl/utils/mergeNeedleOpts.mts +16 -0
  23. package/impl/utils/parseRows.mts +117 -0
  24. package/impl/utils/queryBuilder.mts +173 -0
  25. package/impl/utils/queryString.mts +44 -0
  26. package/impl/{trackedEmitter.mjs → utils/trackedEmitter.mts} +9 -7
  27. package/impl/utils/transactionErrors.mts +71 -0
  28. package/index.mts +82 -0
  29. package/migration_guides/v6.md +70 -0
  30. package/package.json +49 -32
  31. package/schema/config.mts +81 -0
  32. package/schema/couch/couch.input.schema.ts +43 -0
  33. package/schema/couch/couch.output.schema.ts +169 -0
  34. package/schema/sugar/lock.mts +18 -0
  35. package/schema/sugar/watch.mts +14 -0
  36. package/schema/util.mts +8 -0
  37. package/tsconfig.json +10 -4
  38. package/tsdown.config.ts +16 -0
  39. package/typedoc.json +4 -0
  40. package/types/output/eslint.config.d.ts +3 -0
  41. package/types/output/eslint.config.d.ts.map +1 -0
  42. package/types/output/impl/bindConfig.d.mts +174 -0
  43. package/types/output/impl/bindConfig.d.mts.map +1 -0
  44. package/types/output/impl/bulkGet.d.mts +75 -0
  45. package/types/output/impl/bulkGet.d.mts.map +1 -0
  46. package/types/output/impl/bulkGet.test.d.mts +2 -0
  47. package/types/output/impl/bulkGet.test.d.mts.map +1 -0
  48. package/types/output/impl/bulkRemove.d.mts +63 -0
  49. package/types/output/impl/bulkRemove.d.mts.map +1 -0
  50. package/types/output/impl/bulkRemove.test.d.mts +2 -0
  51. package/types/output/impl/bulkRemove.test.d.mts.map +1 -0
  52. package/types/output/impl/bulkSave.d.mts +64 -0
  53. package/types/output/impl/bulkSave.d.mts.map +1 -0
  54. package/types/output/impl/bulkSave.test.d.mts +2 -0
  55. package/types/output/impl/bulkSave.test.d.mts.map +1 -0
  56. package/types/output/impl/get.d.mts +20 -0
  57. package/types/output/impl/get.d.mts.map +1 -0
  58. package/types/output/impl/get.test.d.mts +2 -0
  59. package/types/output/impl/get.test.d.mts.map +1 -0
  60. package/types/output/impl/getDBInfo.d.mts +52 -0
  61. package/types/output/impl/getDBInfo.d.mts.map +1 -0
  62. package/types/output/impl/getDBInfo.test.d.mts +2 -0
  63. package/types/output/impl/getDBInfo.test.d.mts.map +1 -0
  64. package/types/output/impl/patch.d.mts +45 -0
  65. package/types/output/impl/patch.d.mts.map +1 -0
  66. package/types/output/impl/patch.test.d.mts +2 -0
  67. package/types/output/impl/patch.test.d.mts.map +1 -0
  68. package/types/output/impl/put.d.mts +5 -0
  69. package/types/output/impl/put.d.mts.map +1 -0
  70. package/types/output/impl/put.test.d.mts +2 -0
  71. package/types/output/impl/put.test.d.mts.map +1 -0
  72. package/types/output/impl/query.d.mts +47 -0
  73. package/types/output/impl/query.d.mts.map +1 -0
  74. package/types/output/impl/query.test.d.mts +2 -0
  75. package/types/output/impl/query.test.d.mts.map +1 -0
  76. package/types/output/impl/remove.d.mts +9 -0
  77. package/types/output/impl/remove.d.mts.map +1 -0
  78. package/types/output/impl/remove.test.d.mts +2 -0
  79. package/types/output/impl/remove.test.d.mts.map +1 -0
  80. package/types/output/impl/retry.d.mts +32 -0
  81. package/types/output/impl/retry.d.mts.map +1 -0
  82. package/types/output/impl/retry.test.d.mts +2 -0
  83. package/types/output/impl/retry.test.d.mts.map +1 -0
  84. package/types/output/impl/stream.d.mts +13 -0
  85. package/types/output/impl/stream.d.mts.map +1 -0
  86. package/types/output/impl/stream.test.d.mts +2 -0
  87. package/types/output/impl/stream.test.d.mts.map +1 -0
  88. package/types/output/impl/sugar/lock.d.mts +24 -0
  89. package/types/output/impl/sugar/lock.d.mts.map +1 -0
  90. package/types/output/impl/sugar/lock.test.d.mts +2 -0
  91. package/types/output/impl/sugar/lock.test.d.mts.map +1 -0
  92. package/types/output/impl/sugar/watch.d.mts +21 -0
  93. package/types/output/impl/sugar/watch.d.mts.map +1 -0
  94. package/types/output/impl/sugar/watch.test.d.mts +2 -0
  95. package/types/output/impl/sugar/watch.test.d.mts.map +1 -0
  96. package/types/output/impl/utils/errors.d.mts +78 -0
  97. package/types/output/impl/utils/errors.d.mts.map +1 -0
  98. package/types/output/impl/utils/errors.test.d.mts +2 -0
  99. package/types/output/impl/utils/errors.test.d.mts.map +1 -0
  100. package/types/output/impl/utils/logger.d.mts +11 -0
  101. package/types/output/impl/utils/logger.d.mts.map +1 -0
  102. package/types/output/impl/utils/logger.test.d.mts +2 -0
  103. package/types/output/impl/utils/logger.test.d.mts.map +1 -0
  104. package/types/output/impl/utils/mergeNeedleOpts.d.mts +53 -0
  105. package/types/output/impl/utils/mergeNeedleOpts.d.mts.map +1 -0
  106. package/types/output/impl/utils/parseRows.d.mts +15 -0
  107. package/types/output/impl/utils/parseRows.d.mts.map +1 -0
  108. package/types/output/impl/utils/parseRows.test.d.mts +2 -0
  109. package/types/output/impl/utils/parseRows.test.d.mts.map +1 -0
  110. package/types/output/impl/utils/queryBuilder.d.mts +68 -0
  111. package/types/output/impl/utils/queryBuilder.d.mts.map +1 -0
  112. package/types/output/impl/utils/queryBuilder.test.d.mts +2 -0
  113. package/types/output/impl/utils/queryBuilder.test.d.mts.map +1 -0
  114. package/types/output/impl/utils/queryString.d.mts +9 -0
  115. package/types/output/impl/utils/queryString.d.mts.map +1 -0
  116. package/types/output/impl/utils/queryString.test.d.mts +2 -0
  117. package/types/output/impl/utils/queryString.test.d.mts.map +1 -0
  118. package/types/output/impl/utils/trackedEmitter.d.mts +7 -0
  119. package/types/output/impl/utils/trackedEmitter.d.mts.map +1 -0
  120. package/{impl → types/output/impl/utils}/transactionErrors.d.mts +16 -31
  121. package/types/output/impl/utils/transactionErrors.d.mts.map +1 -0
  122. package/types/output/index.d.mts +32 -0
  123. package/types/output/index.d.mts.map +1 -0
  124. package/types/output/index.test.d.mts +2 -0
  125. package/types/output/index.test.d.mts.map +1 -0
  126. package/types/output/schema/config.d.mts +90 -0
  127. package/types/output/schema/config.d.mts.map +1 -0
  128. package/types/output/schema/couch/couch.input.schema.d.ts +29 -0
  129. package/types/output/schema/couch/couch.input.schema.d.ts.map +1 -0
  130. package/types/output/schema/couch/couch.output.schema.d.ts +113 -0
  131. package/types/output/schema/couch/couch.output.schema.d.ts.map +1 -0
  132. package/types/output/schema/sugar/lock.d.mts +19 -0
  133. package/types/output/schema/sugar/lock.d.mts.map +1 -0
  134. package/types/output/schema/sugar/watch.d.mts +11 -0
  135. package/types/output/schema/sugar/watch.d.mts.map +1 -0
  136. package/types/output/schema/util.d.mts +85 -0
  137. package/types/output/schema/util.d.mts.map +1 -0
  138. package/types/output/tsdown.config.d.ts +3 -0
  139. package/types/output/tsdown.config.d.ts.map +1 -0
  140. package/types/output/types/standard-schema.d.ts +60 -0
  141. package/types/output/types/standard-schema.d.ts.map +1 -0
  142. package/types/standard-schema.ts +76 -0
  143. package/types/utils.d.ts +1 -0
  144. package/cjs/impl/bulk.cjs +0 -275
  145. package/cjs/impl/changes.cjs +0 -67
  146. package/cjs/impl/crud.cjs +0 -127
  147. package/cjs/impl/errors.cjs +0 -75
  148. package/cjs/impl/logger.cjs +0 -70
  149. package/cjs/impl/patch.cjs +0 -95
  150. package/cjs/impl/query.cjs +0 -116
  151. package/cjs/impl/queryBuilder.cjs +0 -163
  152. package/cjs/impl/retry.cjs +0 -55
  153. package/cjs/impl/stream.cjs +0 -121
  154. package/cjs/impl/sugar/lock.cjs +0 -81
  155. package/cjs/impl/sugar/watch.cjs +0 -159
  156. package/cjs/impl/trackedEmitter.cjs +0 -54
  157. package/cjs/impl/transactionErrors.cjs +0 -70
  158. package/cjs/impl/util.cjs +0 -64
  159. package/cjs/index.cjs +0 -132
  160. package/cjs/integration/changes.cjs +0 -76
  161. package/cjs/integration/disconnect-watch.cjs +0 -52
  162. package/cjs/integration/watch.cjs +0 -59
  163. package/cjs/schema/bind.cjs +0 -59
  164. package/cjs/schema/bulk.cjs +0 -92
  165. package/cjs/schema/changes.cjs +0 -68
  166. package/cjs/schema/config.cjs +0 -48
  167. package/cjs/schema/crud.cjs +0 -77
  168. package/cjs/schema/patch.cjs +0 -53
  169. package/cjs/schema/query.cjs +0 -62
  170. package/cjs/schema/stream.cjs +0 -42
  171. package/cjs/schema/sugar/lock.cjs +0 -59
  172. package/cjs/schema/sugar/watch.cjs +0 -42
  173. package/cjs/schema/util.cjs +0 -39
  174. package/config.json +0 -5
  175. package/docs/compiler.png +0 -0
  176. package/dualmode.config.json +0 -11
  177. package/impl/bulk.d.mts +0 -11
  178. package/impl/bulk.d.mts.map +0 -1
  179. package/impl/bulk.mjs +0 -291
  180. package/impl/changes.d.mts +0 -12
  181. package/impl/changes.d.mts.map +0 -1
  182. package/impl/changes.mjs +0 -53
  183. package/impl/crud.d.mts +0 -7
  184. package/impl/crud.d.mts.map +0 -1
  185. package/impl/crud.mjs +0 -108
  186. package/impl/errors.d.mts +0 -43
  187. package/impl/errors.d.mts.map +0 -1
  188. package/impl/errors.mjs +0 -65
  189. package/impl/logger.d.mts +0 -32
  190. package/impl/logger.d.mts.map +0 -1
  191. package/impl/logger.mjs +0 -59
  192. package/impl/patch.d.mts +0 -6
  193. package/impl/patch.d.mts.map +0 -1
  194. package/impl/patch.mjs +0 -88
  195. package/impl/query.d.mts +0 -195
  196. package/impl/query.d.mts.map +0 -1
  197. package/impl/query.mjs +0 -122
  198. package/impl/queryBuilder.d.mts +0 -154
  199. package/impl/queryBuilder.d.mts.map +0 -1
  200. package/impl/queryBuilder.mjs +0 -175
  201. package/impl/retry.d.mts +0 -2
  202. package/impl/retry.d.mts.map +0 -1
  203. package/impl/retry.mjs +0 -39
  204. package/impl/stream.d.mts +0 -3
  205. package/impl/stream.d.mts.map +0 -1
  206. package/impl/stream.mjs +0 -98
  207. package/impl/sugar/lock.d.mts +0 -5
  208. package/impl/sugar/lock.d.mts.map +0 -1
  209. package/impl/sugar/lock.mjs +0 -70
  210. package/impl/sugar/watch.d.mts +0 -34
  211. package/impl/sugar/watch.d.mts.map +0 -1
  212. package/impl/trackedEmitter.d.mts +0 -8
  213. package/impl/trackedEmitter.d.mts.map +0 -1
  214. package/impl/transactionErrors.d.mts.map +0 -1
  215. package/impl/transactionErrors.mjs +0 -47
  216. package/impl/util.d.mts +0 -3
  217. package/impl/util.d.mts.map +0 -1
  218. package/impl/util.mjs +0 -35
  219. package/index.d.mts +0 -80
  220. package/index.d.mts.map +0 -1
  221. package/index.mjs +0 -141
  222. package/integration/changes.mjs +0 -60
  223. package/integration/disconnect-watch.mjs +0 -36
  224. package/integration/watch.mjs +0 -40
  225. package/schema/bind.d.mts +0 -5461
  226. package/schema/bind.d.mts.map +0 -1
  227. package/schema/bind.mjs +0 -43
  228. package/schema/bulk.d.mts +0 -923
  229. package/schema/bulk.d.mts.map +0 -1
  230. package/schema/bulk.mjs +0 -83
  231. package/schema/changes.d.mts +0 -191
  232. package/schema/changes.d.mts.map +0 -1
  233. package/schema/changes.mjs +0 -59
  234. package/schema/config.d.mts +0 -79
  235. package/schema/config.d.mts.map +0 -1
  236. package/schema/config.mjs +0 -26
  237. package/schema/crud.d.mts +0 -491
  238. package/schema/crud.d.mts.map +0 -1
  239. package/schema/crud.mjs +0 -64
  240. package/schema/patch.d.mts +0 -255
  241. package/schema/patch.d.mts.map +0 -1
  242. package/schema/patch.mjs +0 -42
  243. package/schema/query.d.mts +0 -406
  244. package/schema/query.d.mts.map +0 -1
  245. package/schema/query.mjs +0 -45
  246. package/schema/stream.d.mts +0 -211
  247. package/schema/stream.d.mts.map +0 -1
  248. package/schema/stream.mjs +0 -23
  249. package/schema/sugar/lock.d.mts +0 -238
  250. package/schema/sugar/lock.d.mts.map +0 -1
  251. package/schema/sugar/lock.mjs +0 -50
  252. package/schema/sugar/watch.d.mts +0 -127
  253. package/schema/sugar/watch.d.mts.map +0 -1
  254. package/schema/sugar/watch.mjs +0 -29
  255. package/schema/util.d.mts +0 -160
  256. package/schema/util.d.mts.map +0 -1
  257. package/schema/util.mjs +0 -35
  258. package/types/changes-stream.d.ts +0 -11
@@ -1,175 +0,0 @@
1
- // @ts-check
2
-
3
- /**
4
- * @typedef {Object} QueryOptions
5
- * @property {any} [key] - Exact key to match
6
- * @property {any} [startkey] - Start of key range
7
- * @property {any} [endkey] - End of key range
8
- * @property {boolean} [reduce] - Whether to use reduce function
9
- * @property {boolean} [group] - Whether to group results
10
- * @property {number} [group_level] - Level at which to group
11
- * @property {boolean} [include_docs] - Whether to include full couch docs
12
- * @property {string} [stale] - Stale parameter value
13
- * @property {number} [limit] - Max number of results
14
- * @property {boolean} [descending] - Whether to return results in descending order
15
- * @property {number} [skip] - Number of results to skip
16
- * @property {any[]} [keys] - Array of keys to match
17
- */
18
-
19
- export class QueryBuilder {
20
- /** @type {QueryOptions} */
21
- #options = {}
22
-
23
- /**
24
- * @param {any} key
25
- * @returns {QueryBuilder}
26
- */
27
- key (key) {
28
- this.#options.key = key
29
- return this
30
- }
31
-
32
- /**
33
- * @param {any} startkey
34
- * @returns {QueryBuilder}
35
- */
36
- startKey (startkey) {
37
- this.#options.startkey = startkey
38
- return this
39
- }
40
-
41
- /**
42
- * @param {any} startkey
43
- * @returns {QueryBuilder}
44
- */
45
- startkey (startkey) {
46
- this.#options.startkey = startkey
47
- return this
48
- }
49
-
50
- /**
51
- * @param {any} endkey
52
- * @returns {QueryBuilder}
53
- */
54
- endKey (endkey) {
55
- this.#options.endkey = endkey
56
- return this
57
- }
58
-
59
- /**
60
- * @param {any} endkey
61
- * @returns {QueryBuilder}
62
- */
63
- endkey (endkey) {
64
- this.#options.endkey = endkey
65
- return this
66
- }
67
-
68
- /**
69
- * @param {boolean} reduce
70
- * @returns {QueryBuilder}
71
- */
72
- reduce (reduce = true) {
73
- this.#options.reduce = reduce
74
- return this
75
- }
76
-
77
- /**
78
- * @param {boolean} group
79
- * @returns {QueryBuilder}
80
- */
81
- group (group = true) {
82
- this.#options.group = group
83
- return this
84
- }
85
-
86
- /**
87
- * @param {number} level
88
- * @returns {QueryBuilder}
89
- */
90
- groupLevel (level) {
91
- this.#options.group_level = level
92
- return this
93
- }
94
-
95
- /**
96
- * @param {number} level
97
- * @returns {QueryBuilder}
98
- */
99
- group_level (level) {
100
- this.#options.group_level = level
101
- return this
102
- }
103
-
104
- /**
105
- * @param {boolean} includeDocs
106
- * @returns {QueryBuilder}
107
- */
108
- includeDocs (includeDocs = true) {
109
- this.#options.include_docs = includeDocs
110
- return this
111
- }
112
-
113
- /**
114
- * @param {boolean} includeDocs
115
- * @returns {QueryBuilder}
116
- */
117
- include_docs (includeDocs = true) {
118
- this.#options.include_docs = includeDocs
119
- return this
120
- }
121
-
122
- /**
123
- * @param {string} stale
124
- * @returns {QueryBuilder}
125
- */
126
- stale (stale) {
127
- this.#options.stale = stale
128
- return this
129
- }
130
-
131
- /**
132
- * @param {number} limit
133
- * @returns {QueryBuilder}
134
- */
135
- limit (limit) {
136
- this.#options.limit = limit
137
- return this
138
- }
139
-
140
- /**
141
- * @param {boolean} descending
142
- * @returns {QueryBuilder}
143
- */
144
- descending (descending = true) {
145
- this.#options.descending = descending
146
- return this
147
- }
148
-
149
- /**
150
- * @param {number} skip
151
- * @returns {QueryBuilder}
152
- */
153
- skip (skip) {
154
- this.#options.skip = skip
155
- return this
156
- }
157
-
158
- /**
159
- * @param {any[]} keys
160
- * @returns {QueryBuilder}
161
- */
162
- keys (keys) {
163
- this.#options.keys = keys
164
- return this
165
- }
166
-
167
- /**
168
- * @returns {QueryOptions}
169
- */
170
- build () {
171
- return { ...this.#options }
172
- }
173
- }
174
-
175
- export const createQuery = () => new QueryBuilder()
package/impl/retry.d.mts DELETED
@@ -1,2 +0,0 @@
1
- export function withRetry(fn: any, options?: {}): (...args: any[]) => Promise<any>;
2
- //# sourceMappingURL=retry.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retry.d.mts","sourceRoot":"","sources":["retry.mjs"],"names":[],"mappings":"AAGA,mFAmCC"}
package/impl/retry.mjs DELETED
@@ -1,39 +0,0 @@
1
- import { RetryableError } from './errors.mjs'
2
- import { sleep } from './patch.mjs'
3
-
4
- export function withRetry (fn, options = {}) {
5
- const {
6
- maxRetries = 3,
7
- initialDelay = 1000, // 1 second
8
- backoffFactor = 2, // exponential backoff multiplier
9
- maxDelay = 30000 // 30 seconds max delay
10
- } = options
11
-
12
- return async (...args) => {
13
- let delay = initialDelay
14
-
15
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
16
- try {
17
- // Clear any references to previous attempts
18
- const result = await fn(...args)
19
- return result
20
- } catch (error) {
21
- // Only retry if it's a RetryableError
22
- if (!(error instanceof RetryableError)) {
23
- throw error
24
- }
25
-
26
- // If we've used all retries, throw the error
27
- if (attempt === maxRetries) {
28
- throw error
29
- }
30
-
31
- // Calculate next delay with a maximum cap
32
- const nextDelay = Math.min(delay, maxDelay)
33
- // Wait with exponential backoff
34
- await sleep(nextDelay)
35
- delay *= backoffFactor
36
- }
37
- }
38
- }
39
- }
package/impl/stream.d.mts DELETED
@@ -1,3 +0,0 @@
1
- /** @type { import('../schema/stream.mjs').SimpleViewQueryStreamSchema } queryStream */
2
- export const queryStream: import("../schema/stream.mjs").SimpleViewQueryStreamSchema;
3
- //# sourceMappingURL=stream.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.d.mts","sourceRoot":"","sources":["stream.mjs"],"names":[],"mappings":"AASA,uFAAuF;AACvF,0BADY,OAAO,sBAAsB,EAAE,2BAA2B,CAwFpE"}
package/impl/stream.mjs DELETED
@@ -1,98 +0,0 @@
1
- // @ts-check
2
- import needle from 'needle'
3
- import { CouchConfig } from '../schema/config.mjs'
4
- import { queryString } from './query.mjs'
5
- import { RetryableError } from './errors.mjs'
6
- import { createLogger } from './logger.mjs'
7
- // @ts-ignore
8
- import JSONStream from 'JSONStream'
9
-
10
- /** @type { import('../schema/stream.mjs').SimpleViewQueryStreamSchema } queryStream */
11
- export const queryStream = (rawConfig, view, options, onRow) => new Promise((resolve, reject) => {
12
- const config = CouchConfig.parse(rawConfig)
13
- const logger = createLogger(config)
14
- logger.info(`Starting view query stream: ${view}`)
15
- logger.debug('Query options:', options)
16
-
17
- if (!options) options = {}
18
-
19
- let method = 'GET'
20
- let payload = null
21
- let qs = queryString(options, ['key', 'startkey', 'endkey', 'reduce', 'group', 'group_level', 'stale', 'limit'])
22
- logger.debug('Generated query string:', qs)
23
-
24
- // If keys are supplied, issue a POST to circumvent GET query string limits
25
- if (typeof options.keys !== 'undefined') {
26
- const MAX_URL_LENGTH = 2000
27
- const keysAsString = `keys=${encodeURIComponent(JSON.stringify(options.keys))}`
28
-
29
- if (keysAsString.length + qs.length + 1 <= MAX_URL_LENGTH) {
30
- // If the keys are short enough, do a GET
31
- qs += (qs[0] === '?' ? '&' : '?') + keysAsString
32
- } else {
33
- method = 'POST'
34
- payload = { keys: options.keys }
35
- }
36
- }
37
-
38
- const url = `${config.couch}/${view}?${qs.toString()}`
39
- const opts = {
40
- json: true,
41
- headers: {
42
- 'Content-Type': 'application/json'
43
- },
44
- parse_response: false // Keep as stream
45
- }
46
-
47
- const streamer = JSONStream.parse('rows.*')
48
-
49
- let rowCount = 0
50
- streamer.on('data', /** @param {object} row */ row => {
51
- rowCount++
52
- onRow(row)
53
- })
54
-
55
- streamer.on('error', /** @param {Error} err */ err => {
56
- logger.error('Stream parsing error:', err)
57
- reject(new Error(`Stream parsing error: ${err.message}`))
58
- })
59
-
60
- streamer.on('done', /** @param {Error|null} err */ err => {
61
- try {
62
- RetryableError.handleNetworkError(err)
63
- } catch (e) {
64
- reject(e)
65
- }
66
- })
67
-
68
- streamer.on('end', () => {
69
- logger.info(`Stream completed, processed ${rowCount} rows`)
70
- resolve(undefined) // all work should be done in the stream
71
- })
72
-
73
- const req = method === 'GET'
74
- ? needle.get(url, opts)
75
- : needle.post(url, payload, opts)
76
-
77
- req.on('response', response => {
78
- logger.debug(`Received response with status code: ${response.statusCode}`)
79
- if (RetryableError.isRetryableStatusCode(response.statusCode)) {
80
- logger.warn(`Retryable status code received: ${response.statusCode}`)
81
- reject(new RetryableError('retryable error during stream query', response.statusCode))
82
- // req.abort()
83
- }
84
- })
85
-
86
- req.on('error', err => {
87
- logger.error('Network error during stream query:', err)
88
- try {
89
- RetryableError.handleNetworkError(err)
90
- } catch (retryErr) {
91
- reject(retryErr)
92
- return
93
- }
94
- reject(err)
95
- })
96
-
97
- req.pipe(streamer)
98
- })
@@ -1,5 +0,0 @@
1
- /** @type {import('../../schema/sugar/lock.mjs').CreateLockSchema} */
2
- export const createLock: import("../../schema/sugar/lock.mjs").CreateLockSchema;
3
- /** @type {import('../../schema/sugar/lock.mjs').RemoveLockSchema} */
4
- export const removeLock: import("../../schema/sugar/lock.mjs").RemoveLockSchema;
5
- //# sourceMappingURL=lock.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lock.d.mts","sourceRoot":"","sources":["lock.mjs"],"names":[],"mappings":"AAIA,qEAAqE;AACrE,yBADW,OAAO,6BAA6B,EAAE,gBAAgB,CA8B/D;AAEF,qEAAqE;AACrE,yBADW,OAAO,6BAA6B,EAAE,gBAAgB,CAiC/D"}
@@ -1,70 +0,0 @@
1
- import { CreateLock, RemoveLock } from '../../schema/sugar/lock.mjs'
2
- import { put, get } from '../crud.mjs'
3
- import { createLogger } from '../logger.mjs'
4
-
5
- /** @type {import('../../schema/sugar/lock.mjs').CreateLockSchema} */
6
- export const createLock = CreateLock.implement(async (config, docId, options) => {
7
- const logger = createLogger(config)
8
-
9
- if (!options.enableLocking) {
10
- logger.debug('Locking disabled, returning true')
11
- return true
12
- }
13
-
14
- const _id = `lock-${docId}`
15
- const lock = {
16
- _id,
17
- type: 'lock',
18
- locks: docId,
19
- lockedAt: new Date().toISOString(),
20
- lockedBy: options.username
21
- }
22
-
23
- try {
24
- const result = await put(config, lock)
25
- logger.info(`Lock created for ${docId} by ${options.username}`)
26
- return result.ok === true
27
- } catch (error) {
28
- if (error.status === 409) {
29
- logger.warn(`Lock conflict for ${docId} - already locked`)
30
- } else {
31
- logger.error(`Error creating lock for ${docId}:`, error)
32
- }
33
- return false
34
- }
35
- })
36
-
37
- /** @type {import('../../schema/sugar/lock.mjs').RemoveLockSchema} */
38
- export const removeLock = RemoveLock.implement(async (config, docId, options) => {
39
- const logger = createLogger(config)
40
-
41
- if (!options.enableLocking) {
42
- logger.debug('Locking disabled, skipping unlock')
43
- return
44
- }
45
-
46
- if (!docId) {
47
- logger.warn('No docId provided for unlock')
48
- return
49
- }
50
-
51
- const _id = `lock-${docId}`
52
- const existingLock = await get(config, _id)
53
-
54
- if (!existingLock) {
55
- logger.debug(`No lock found for ${docId}`)
56
- return
57
- }
58
-
59
- if (existingLock.lockedBy !== options.username) {
60
- logger.warn(`Cannot remove lock for ${docId} - owned by ${existingLock.lockedBy}`)
61
- return
62
- }
63
-
64
- try {
65
- await put(config, { ...existingLock, _deleted: true })
66
- logger.info(`Lock removed for ${docId}`)
67
- } catch (error) {
68
- logger.error(`Error removing lock for ${docId}:`, error)
69
- }
70
- })
@@ -1,34 +0,0 @@
1
- export const watchDocs: (args_0: import("zod").objectInputType<{
2
- throwOnGetNotFound: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
3
- couch: import("zod").ZodString;
4
- bindWithRetry: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
5
- maxRetries: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodNumber>>;
6
- initialDelay: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodNumber>>;
7
- backoffFactor: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodNumber>>;
8
- useConsoleLogger: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
9
- logger: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodObject<{
10
- error: import("zod").ZodOptional<import("zod").ZodFunction<import("zod").ZodTuple<[import("zod").ZodAny], import("zod").ZodUnknown>, import("zod").ZodVoid>>;
11
- warn: import("zod").ZodOptional<import("zod").ZodFunction<import("zod").ZodTuple<[import("zod").ZodAny], import("zod").ZodUnknown>, import("zod").ZodVoid>>;
12
- info: import("zod").ZodOptional<import("zod").ZodFunction<import("zod").ZodTuple<[import("zod").ZodAny], import("zod").ZodUnknown>, import("zod").ZodVoid>>;
13
- debug: import("zod").ZodOptional<import("zod").ZodFunction<import("zod").ZodTuple<[import("zod").ZodAny], import("zod").ZodUnknown>, import("zod").ZodVoid>>;
14
- }, "strip", import("zod").ZodTypeAny, {
15
- error?: ((args_0: any, ...args: unknown[]) => void) | undefined;
16
- warn?: ((args_0: any, ...args: unknown[]) => void) | undefined;
17
- info?: ((args_0: any, ...args: unknown[]) => void) | undefined;
18
- debug?: ((args_0: any, ...args: unknown[]) => void) | undefined;
19
- }, {
20
- error?: ((args_0: any, ...args: unknown[]) => void) | undefined;
21
- warn?: ((args_0: any, ...args: unknown[]) => void) | undefined;
22
- info?: ((args_0: any, ...args: unknown[]) => void) | undefined;
23
- debug?: ((args_0: any, ...args: unknown[]) => void) | undefined;
24
- }>, import("zod").ZodFunction<import("zod").ZodTuple<[import("zod").ZodString, import("zod").ZodAny], import("zod").ZodUnknown>, import("zod").ZodVoid>]>>;
25
- _normalizedLogger: import("zod").ZodOptional<import("zod").ZodAny>;
26
- }, import("zod").ZodTypeAny, "passthrough">, args_1: string | string[], args_2: (args_0: any, ...args: unknown[]) => void, args_3: {
27
- include_docs?: boolean | undefined;
28
- }, ...args: unknown[]) => {
29
- on: (event: string, listener: (args_0: any, ...args: unknown[]) => void) => EventEmitter<[never]>;
30
- removeListener: (event: string, listener: (args_0: any, ...args: unknown[]) => void) => EventEmitter<[never]>;
31
- stop: () => void;
32
- };
33
- import { EventEmitter } from 'events';
34
- //# sourceMappingURL=watch.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"watch.d.mts","sourceRoot":"","sources":["watch.mjs"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiJE;6BAxJ2B,QAAQ"}
@@ -1,8 +0,0 @@
1
- export class TrackedEmitter extends EventEmitter<[never]> {
2
- constructor(options: any);
3
- delay: any;
4
- emit(event: any, ...args: any[]): Promise<any>;
5
- }
6
- export function setupEmitter(config: any): any;
7
- import { EventEmitter } from 'events';
8
- //# sourceMappingURL=trackedEmitter.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trackedEmitter.d.mts","sourceRoot":"","sources":["trackedEmitter.mjs"],"names":[],"mappings":"AAEA;IAEE,0BAGC;IADoB,WAA0B;IAG/C,+CAiBC;CACF;AAEM,+CAGN;6BAhC4B,QAAQ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"transactionErrors.d.mts","sourceRoot":"","sources":["transactionErrors.mjs"],"names":[],"mappings":"AAAA;IACE;;;OAGG;IACH,qBAHW,MAAM,YACN,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAM7B;IADC,6BAAsB;CAEzB;AAED;IACE;;OAEG;IACH,4BAFW,MAAM,EAAE,EAMlB;IADC,yBAAoC;CAEvC;AAED;IACE;;OAEG;IACH,wBAFW,KAAK,CAAC;QAAC,EAAE,CAAC,EAAE,OAAO,GAAC,IAAI,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAC,IAAI,CAAA;KAAC,CAAC,EAMpH;IADC;aALqB,OAAO,GAAC,IAAI;aAAO,MAAM,GAAC,IAAI;cAAQ,MAAM,GAAC,IAAI;gBAAU,MAAM,GAAC,IAAI;iBAAW,MAAM,GAAC,IAAI;QAKrF;CAE/B;AAED;IACE;;;;OAIG;IACH,qBAJW,MAAM,iBACN,KAAK,mBACL,KAAK,CAAC;QAAC,EAAE,CAAC,EAAE,OAAO,GAAC,IAAI,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAC,IAAI,CAAA;KAAC,CAAC,EAOpH;IAFC,qBAAkC;IAClC;aANqB,OAAO,GAAC,IAAI;aAAO,MAAM,GAAC,IAAI;cAAQ,MAAM,GAAC,IAAI;gBAAU,MAAM,GAAC,IAAI;iBAAW,MAAM,GAAC,IAAI;QAM3E;CAEzC"}
@@ -1,47 +0,0 @@
1
- export class TransactionSetupError extends Error {
2
- /**
3
- * @param {string} message
4
- * @param {Record<string, any>} details
5
- */
6
- constructor (message, details = {}) {
7
- super(message)
8
- this.name = 'TransactionSetupError'
9
- this.details = details
10
- }
11
- }
12
-
13
- export class TransactionVersionConflictError extends Error {
14
- /**
15
- * @param {string[]} conflictingIds
16
- */
17
- constructor (conflictingIds) {
18
- super(`Revision mismatch for documents: ${conflictingIds.join(', ')}`)
19
- this.name = 'TransactionVersionConflictError'
20
- this.conflictingIds = conflictingIds
21
- }
22
- }
23
-
24
- export class TransactionBulkOperationError extends Error {
25
- /**
26
- * @param {Array<{ok?: boolean|null, id?: string|null, rev?: string|null, error?: string|null, reason?: string|null}>} failedDocs
27
- */
28
- constructor (failedDocs) {
29
- super(`Failed to save documents: ${failedDocs.map(d => d.id).join(', ')}`)
30
- this.name = 'TransactionBulkOperationError'
31
- this.failedDocs = failedDocs
32
- }
33
- }
34
-
35
- export class TransactionRollbackError extends Error {
36
- /**
37
- * @param {string} message
38
- * @param {Error} originalError
39
- * @param {Array<{ok?: boolean|null, id?: string|null, rev?: string|null, error?: string|null, reason?: string|null}>} rollbackResults
40
- */
41
- constructor (message, originalError, rollbackResults) {
42
- super(message)
43
- this.name = 'TransactionRollbackError'
44
- this.originalError = originalError
45
- this.rollbackResults = rollbackResults
46
- }
47
- }
package/impl/util.d.mts DELETED
@@ -1,3 +0,0 @@
1
- /** @type { import('../schema/util.mjs').GetDBInfoSchema} */
2
- export const getDBInfo: import("../schema/util.mjs").GetDBInfoSchema;
3
- //# sourceMappingURL=util.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.d.mts","sourceRoot":"","sources":["util.mjs"],"names":[],"mappings":"AAMA,4DAA4D;AAC5D,wBADY,OAAO,oBAAoB,EAAE,eAAe,CA4BtD"}
package/impl/util.mjs DELETED
@@ -1,35 +0,0 @@
1
- // @ts-check
2
- import needle from 'needle'
3
- import { RetryableError, NotFoundError } from './errors.mjs'
4
- import { createLogger } from './logger.mjs'
5
- import { GetDBInfo } from '../schema/util.mjs'
6
-
7
- /** @type { import('../schema/util.mjs').GetDBInfoSchema} */
8
- export const getDBInfo = GetDBInfo.implement(async (config) => {
9
- const logger = createLogger(config)
10
- const url = `${config.couch}`
11
- const opts = {
12
- json: true,
13
- headers: {
14
- 'Content-Type': 'application/json'
15
- }
16
- }
17
- let resp
18
- try {
19
- resp = await needle('get', url, opts)
20
- } catch (err) {
21
- logger.error('Error during put operation:', err)
22
- RetryableError.handleNetworkError(err)
23
- }
24
-
25
- if (!resp) {
26
- logger.error('No response received from put request')
27
- throw new RetryableError('no response', 503)
28
- }
29
- const result = resp.body
30
- if (RetryableError.isRetryableStatusCode(resp.statusCode)) {
31
- logger.warn(`Retryable status code received: ${resp.statusCode}`)
32
- throw new RetryableError(result.reason || 'retryable error', resp.statusCode)
33
- }
34
- return result
35
- })
package/index.d.mts DELETED
@@ -1,80 +0,0 @@
1
- export type DB = z.infer<typeof BindReturns>;
2
- import { get } from './impl/crud.mjs';
3
- import { getAtRev } from './impl/crud.mjs';
4
- import { put } from './impl/crud.mjs';
5
- import { bulkGet } from './impl/bulk.mjs';
6
- import { bulkSave } from './impl/bulk.mjs';
7
- import { query } from './impl/query.mjs';
8
- import { queryStream } from './impl/stream.mjs';
9
- export namespace schema {
10
- export { CouchConfig };
11
- export { SimpleViewQuery };
12
- export { SimpleViewQueryResponse };
13
- export { SimpleViewQueryStream };
14
- export { OnRow };
15
- export { BulkSave };
16
- export { BulkGet };
17
- export { BulkRemove };
18
- export { BulkGetDictionary };
19
- export { BulkSaveTransaction };
20
- export { CouchGet };
21
- export { CouchPut };
22
- export { CouchDoc };
23
- export { CouchDocResponse };
24
- export { Patch };
25
- export { PatchDangerously };
26
- export { CouchGetAtRev };
27
- export { Bind };
28
- export { Lock };
29
- export { WatchDocs };
30
- export { LockOptions };
31
- export { CreateLock };
32
- export { RemoveLock };
33
- export { Changes };
34
- export { ChangesOptions };
35
- export { ChangesResponse };
36
- export { GetDBInfo };
37
- }
38
- import { getDBInfo } from './impl/util.mjs';
39
- import { patch } from './impl/patch.mjs';
40
- import { patchDangerously } from './impl/patch.mjs';
41
- import { bulkRemove } from './impl/bulk.mjs';
42
- import { bulkGetDictionary } from './impl/bulk.mjs';
43
- import { bulkSaveTransaction } from './impl/bulk.mjs';
44
- /** @type { import('./schema/bind.mjs').BindSchema } */
45
- export const bindConfig: import("./schema/bind.mjs").BindSchema;
46
- import { withRetry } from './impl/retry.mjs';
47
- import { createQuery } from './impl/queryBuilder.mjs';
48
- import { createLock } from './impl/sugar/lock.mjs';
49
- import { removeLock } from './impl/sugar/lock.mjs';
50
- import { z } from 'zod';
51
- import { BindReturns } from './schema/bind.mjs';
52
- import { CouchConfig } from './schema/config.mjs';
53
- import { SimpleViewQuery } from './schema/query.mjs';
54
- import { SimpleViewQueryResponse } from './schema/query.mjs';
55
- import { SimpleViewQueryStream } from './schema/stream.mjs';
56
- import { OnRow } from './schema/stream.mjs';
57
- import { BulkSave } from './schema/bulk.mjs';
58
- import { BulkGet } from './schema/bulk.mjs';
59
- import { BulkRemove } from './schema/bulk.mjs';
60
- import { BulkGetDictionary } from './schema/bulk.mjs';
61
- import { BulkSaveTransaction } from './schema/bulk.mjs';
62
- import { CouchGet } from './schema/crud.mjs';
63
- import { CouchPut } from './schema/crud.mjs';
64
- import { CouchDoc } from './schema/crud.mjs';
65
- import { CouchDocResponse } from './schema/crud.mjs';
66
- import { Patch } from './schema/patch.mjs';
67
- import { PatchDangerously } from './schema/patch.mjs';
68
- import { CouchGetAtRev } from './schema/crud.mjs';
69
- import { Bind } from './schema/bind.mjs';
70
- import { Lock } from './schema/sugar/lock.mjs';
71
- import { WatchDocs } from './schema/sugar/watch.mjs';
72
- import { LockOptions } from './schema/sugar/lock.mjs';
73
- import { CreateLock } from './schema/sugar/lock.mjs';
74
- import { RemoveLock } from './schema/sugar/lock.mjs';
75
- import { Changes } from './schema/changes.mjs';
76
- import { ChangesOptions } from './schema/changes.mjs';
77
- import { ChangesResponse } from './schema/changes.mjs';
78
- import { GetDBInfo } from './schema/util.mjs';
79
- export { get, getAtRev, put, bulkGet, bulkSave, query, queryStream, getDBInfo, patch, patchDangerously, bulkRemove, bulkGetDictionary, bulkSaveTransaction, withRetry, createQuery, createLock, removeLock };
80
- //# sourceMappingURL=index.d.mts.map
package/index.d.mts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["index.mjs"],"names":[],"mappings":"iBAmHe,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC;oBAhHP,iBAAiB;yBAAjB,iBAAiB;oBAAjB,iBAAiB;wBADkC,iBAAiB;yBAAjB,iBAAiB;sBAMjF,kBAAkB;4BACZ,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAErB,iBAAiB;sBANH,kBAAkB;iCAAlB,kBAAkB;2BAH4B,iBAAiB;kCAAjB,iBAAiB;oCAAjB,iBAAiB;AAwFvG,uDAAuD;AACvD,yBADY,OAAO,mBAAmB,EAAE,UAAU,CAuBhD;0BArGwB,kBAAkB;4BAFhB,yBAAyB;2BAJd,uBAAuB;2BAAvB,uBAAuB;kBAL5C,KAAK;4BAqBW,mBAAmB;4BARzB,qBAAqB;gCACQ,oBAAoB;wCAApB,oBAAoB;sCAEhC,qBAAqB;sBAArB,qBAAqB;yBAJoB,mBAAmB;wBAAnB,mBAAmB;2BAAnB,mBAAmB;kCAAnB,mBAAmB;oCAAnB,mBAAmB;yBAQ3B,mBAAmB;yBAAnB,mBAAmB;yBAAnB,mBAAmB;iCAAnB,mBAAmB;sBAHzD,oBAAoB;iCAApB,oBAAoB;8BAGkB,mBAAmB;qBAC/D,mBAAmB;qBAHK,yBAAyB;0BACzD,0BAA0B;4BADM,yBAAyB;2BAAzB,yBAAyB;2BAAzB,yBAAyB;wBAH1B,sBAAsB;+BAAtB,sBAAsB;gCAAtB,sBAAsB;0BAOrD,mBAAmB"}