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.
- package/.prettierrc +7 -0
- package/README.md +270 -218
- package/dist/cjs/index.cjs +1952 -0
- package/dist/esm/index.mjs +1898 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +113 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1633 -0
- package/docs/classes/QueryBuilder.html +42 -0
- package/docs/functions/bindConfig.html +4 -0
- package/docs/functions/bulkGet.html +14 -0
- package/docs/functions/bulkGetDictionary.html +10 -0
- package/docs/functions/bulkRemove.html +12 -0
- package/docs/functions/bulkRemoveMap.html +11 -0
- package/docs/functions/bulkSave.html +10 -0
- package/docs/functions/bulkSaveTransaction.html +23 -0
- package/docs/functions/createLock.html +7 -0
- package/docs/functions/createQuery.html +1 -0
- package/docs/functions/get.html +1 -0
- package/docs/functions/getAtRev.html +1 -0
- package/docs/functions/getDBInfo.html +10 -0
- package/docs/functions/patch.html +8 -0
- package/docs/functions/patchDangerously.html +9 -0
- package/docs/functions/put.html +1 -0
- package/docs/functions/query.html +15 -0
- package/docs/functions/queryStream.html +6 -0
- package/docs/functions/remove.html +1 -0
- package/docs/functions/removeLock.html +6 -0
- package/docs/functions/watchDocs.html +9 -0
- package/docs/functions/withRetry.html +6 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +483 -0
- package/docs/interfaces/NetworkError.html +6 -0
- package/docs/interfaces/NotFoundError.html +10 -0
- package/docs/interfaces/RetryOptions.html +10 -0
- package/docs/interfaces/RetryableError.html +10 -0
- package/docs/interfaces/StandardSchemaV1.FailureResult.html +4 -0
- package/docs/interfaces/StandardSchemaV1.Issue.html +6 -0
- package/docs/interfaces/StandardSchemaV1.Options.html +3 -0
- package/docs/interfaces/StandardSchemaV1.PathSegment.html +4 -0
- package/docs/interfaces/StandardSchemaV1.Props.html +10 -0
- package/docs/interfaces/StandardSchemaV1.SuccessResult.html +6 -0
- package/docs/interfaces/StandardSchemaV1.Types.html +6 -0
- package/docs/interfaces/StandardSchemaV1.html +4 -0
- package/docs/modules/StandardSchemaV1.html +1 -0
- package/docs/modules.html +1 -0
- package/docs/types/BoundInstance.html +1 -0
- package/docs/types/BulkGetBound.html +2 -0
- package/docs/types/BulkGetDictionaryBound.html +1 -0
- package/docs/types/BulkGetDictionaryOptions.html +2 -0
- package/docs/types/BulkGetDictionaryResult.html +3 -0
- package/docs/types/BulkGetOptions.html +3 -0
- package/docs/types/BulkGetResponse.html +1 -0
- package/docs/types/CouchConfig-1.html +1 -0
- package/docs/types/CouchConfig.html +1 -0
- package/docs/types/CouchConfigInput.html +1 -0
- package/docs/types/CouchDoc-1.html +1 -0
- package/docs/types/CouchDoc.html +2 -0
- package/docs/types/CouchDocInput.html +2 -0
- package/docs/types/GetAtRevBound.html +1 -0
- package/docs/types/GetBound.html +1 -0
- package/docs/types/GetOptions.html +2 -0
- package/docs/types/LockDoc-1.html +1 -0
- package/docs/types/LockDoc.html +1 -0
- package/docs/types/LockOptions-1.html +1 -0
- package/docs/types/LockOptions.html +1 -0
- package/docs/types/LockOptionsInput.html +1 -0
- package/docs/types/OnInvalidDocAction.html +1 -0
- package/docs/types/OnRow.html +1 -0
- package/docs/types/QueryBound.html +1 -0
- package/docs/types/SimpleViewOptions-1.html +1 -0
- package/docs/types/SimpleViewOptions.html +1 -0
- package/docs/types/StandardSchemaV1.InferInput.html +2 -0
- package/docs/types/StandardSchemaV1.InferOutput.html +2 -0
- package/docs/types/StandardSchemaV1.Result.html +2 -0
- package/docs/types/ViewQueryResponse-1.html +1 -0
- package/docs/types/ViewQueryResponse.html +2 -0
- package/docs/types/ViewQueryResponseValidated.html +2 -0
- package/docs/types/ViewRow-1.html +1 -0
- package/docs/types/ViewRow.html +2 -0
- package/docs/types/ViewRowValidated.html +7 -0
- package/docs/types/ViewString.html +1 -0
- package/docs/types/WatchOptionsInput.html +1 -0
- package/docs/types/WatchOptionsSchema-1.html +1 -0
- package/docs/types/WatchOptionsSchema.html +1 -0
- package/eslint.config.js +15 -0
- package/impl/bindConfig.mts +140 -0
- package/impl/bulkGet.mts +256 -0
- package/impl/bulkGet.test.mts +159 -0
- package/impl/bulkRemove.mts +98 -0
- package/impl/bulkRemove.test.mts +102 -0
- package/impl/bulkSave.mts +286 -0
- package/impl/bulkSave.test.mts +319 -0
- package/impl/get.mts +137 -0
- package/impl/get.test.mts +114 -0
- package/impl/getDBInfo.mts +67 -0
- package/impl/getDBInfo.test.mts +62 -0
- package/impl/patch.mts +134 -0
- package/impl/patch.test.mts +142 -0
- package/impl/put.mts +56 -0
- package/impl/put.test.mts +114 -0
- package/impl/query.mts +224 -0
- package/impl/query.test.mts +280 -0
- package/impl/remove.mts +65 -0
- package/impl/remove.test.mts +82 -0
- package/impl/retry.mts +66 -0
- package/impl/retry.test.mts +77 -0
- package/impl/stream.mts +143 -0
- package/impl/stream.test.mts +205 -0
- package/impl/sugar/lock.mts +103 -0
- package/impl/sugar/lock.test.mts +113 -0
- package/impl/sugar/{watch.mjs → watch.mts} +56 -22
- package/impl/sugar/watch.test.mts +155 -0
- package/impl/utils/errors.mts +130 -0
- package/impl/utils/errors.test.mts +58 -0
- package/impl/utils/logger.mts +62 -0
- package/impl/utils/logger.test.mts +129 -0
- package/impl/utils/mergeNeedleOpts.mts +16 -0
- package/impl/utils/parseRows.mts +117 -0
- package/impl/utils/parseRows.test.mts +183 -0
- package/impl/utils/queryBuilder.mts +173 -0
- package/impl/utils/queryBuilder.test.mts +83 -0
- package/impl/utils/queryString.mts +44 -0
- package/impl/utils/queryString.test.mts +53 -0
- package/impl/{trackedEmitter.mjs → utils/trackedEmitter.mts} +9 -7
- package/impl/utils/transactionErrors.mts +71 -0
- package/index.mts +82 -0
- package/index.test.mts +415 -0
- package/package.json +45 -31
- package/schema/config.mts +81 -0
- package/schema/couch/couch.input.schema.ts +43 -0
- package/schema/couch/couch.output.schema.ts +169 -0
- package/schema/sugar/lock.mts +18 -0
- package/schema/sugar/watch.mts +14 -0
- package/schema/util.mts +8 -0
- package/tsconfig.json +10 -4
- package/tsdown.config.ts +16 -0
- package/typedoc.json +4 -0
- package/types/output/eslint.config.d.ts +3 -0
- package/types/output/eslint.config.d.ts.map +1 -0
- package/types/output/impl/bindConfig.d.mts +174 -0
- package/types/output/impl/bindConfig.d.mts.map +1 -0
- package/types/output/impl/bulkGet.d.mts +75 -0
- package/types/output/impl/bulkGet.d.mts.map +1 -0
- package/types/output/impl/bulkGet.test.d.mts +2 -0
- package/types/output/impl/bulkGet.test.d.mts.map +1 -0
- package/types/output/impl/bulkRemove.d.mts +63 -0
- package/types/output/impl/bulkRemove.d.mts.map +1 -0
- package/types/output/impl/bulkRemove.test.d.mts +2 -0
- package/types/output/impl/bulkRemove.test.d.mts.map +1 -0
- package/types/output/impl/bulkSave.d.mts +64 -0
- package/types/output/impl/bulkSave.d.mts.map +1 -0
- package/types/output/impl/bulkSave.test.d.mts +2 -0
- package/types/output/impl/bulkSave.test.d.mts.map +1 -0
- package/types/output/impl/get.d.mts +20 -0
- package/types/output/impl/get.d.mts.map +1 -0
- package/types/output/impl/get.test.d.mts +2 -0
- package/types/output/impl/get.test.d.mts.map +1 -0
- package/types/output/impl/getDBInfo.d.mts +52 -0
- package/types/output/impl/getDBInfo.d.mts.map +1 -0
- package/types/output/impl/getDBInfo.test.d.mts +2 -0
- package/types/output/impl/getDBInfo.test.d.mts.map +1 -0
- package/types/output/impl/patch.d.mts +45 -0
- package/types/output/impl/patch.d.mts.map +1 -0
- package/types/output/impl/patch.test.d.mts +2 -0
- package/types/output/impl/patch.test.d.mts.map +1 -0
- package/types/output/impl/put.d.mts +5 -0
- package/types/output/impl/put.d.mts.map +1 -0
- package/types/output/impl/put.test.d.mts +2 -0
- package/types/output/impl/put.test.d.mts.map +1 -0
- package/types/output/impl/query.d.mts +47 -0
- package/types/output/impl/query.d.mts.map +1 -0
- package/types/output/impl/query.test.d.mts +2 -0
- package/types/output/impl/query.test.d.mts.map +1 -0
- package/types/output/impl/remove.d.mts +9 -0
- package/types/output/impl/remove.d.mts.map +1 -0
- package/types/output/impl/remove.test.d.mts +2 -0
- package/types/output/impl/remove.test.d.mts.map +1 -0
- package/types/output/impl/retry.d.mts +32 -0
- package/types/output/impl/retry.d.mts.map +1 -0
- package/types/output/impl/retry.test.d.mts +2 -0
- package/types/output/impl/retry.test.d.mts.map +1 -0
- package/types/output/impl/stream.d.mts +13 -0
- package/types/output/impl/stream.d.mts.map +1 -0
- package/types/output/impl/stream.test.d.mts +2 -0
- package/types/output/impl/stream.test.d.mts.map +1 -0
- package/types/output/impl/sugar/lock.d.mts +24 -0
- package/types/output/impl/sugar/lock.d.mts.map +1 -0
- package/types/output/impl/sugar/lock.test.d.mts +2 -0
- package/types/output/impl/sugar/lock.test.d.mts.map +1 -0
- package/types/output/impl/sugar/watch.d.mts +21 -0
- package/types/output/impl/sugar/watch.d.mts.map +1 -0
- package/types/output/impl/sugar/watch.test.d.mts +2 -0
- package/types/output/impl/sugar/watch.test.d.mts.map +1 -0
- package/types/output/impl/utils/errors.d.mts +78 -0
- package/types/output/impl/utils/errors.d.mts.map +1 -0
- package/types/output/impl/utils/errors.test.d.mts +2 -0
- package/types/output/impl/utils/errors.test.d.mts.map +1 -0
- package/types/output/impl/utils/logger.d.mts +11 -0
- package/types/output/impl/utils/logger.d.mts.map +1 -0
- package/types/output/impl/utils/logger.test.d.mts +2 -0
- package/types/output/impl/utils/logger.test.d.mts.map +1 -0
- package/types/output/impl/utils/mergeNeedleOpts.d.mts +53 -0
- package/types/output/impl/utils/mergeNeedleOpts.d.mts.map +1 -0
- package/types/output/impl/utils/parseRows.d.mts +15 -0
- package/types/output/impl/utils/parseRows.d.mts.map +1 -0
- package/types/output/impl/utils/parseRows.test.d.mts +2 -0
- package/types/output/impl/utils/parseRows.test.d.mts.map +1 -0
- package/types/output/impl/utils/queryBuilder.d.mts +68 -0
- package/types/output/impl/utils/queryBuilder.d.mts.map +1 -0
- package/types/output/impl/utils/queryBuilder.test.d.mts +2 -0
- package/types/output/impl/utils/queryBuilder.test.d.mts.map +1 -0
- package/types/output/impl/utils/queryString.d.mts +9 -0
- package/types/output/impl/utils/queryString.d.mts.map +1 -0
- package/types/output/impl/utils/queryString.test.d.mts +2 -0
- package/types/output/impl/utils/queryString.test.d.mts.map +1 -0
- package/types/output/impl/utils/trackedEmitter.d.mts +7 -0
- package/types/output/impl/utils/trackedEmitter.d.mts.map +1 -0
- package/{impl → types/output/impl/utils}/transactionErrors.d.mts +16 -31
- package/types/output/impl/utils/transactionErrors.d.mts.map +1 -0
- package/types/output/index.d.mts +32 -0
- package/types/output/index.d.mts.map +1 -0
- package/types/output/index.test.d.mts +2 -0
- package/types/output/index.test.d.mts.map +1 -0
- package/types/output/schema/config.d.mts +90 -0
- package/types/output/schema/config.d.mts.map +1 -0
- package/types/output/schema/couch/couch.input.schema.d.ts +29 -0
- package/types/output/schema/couch/couch.input.schema.d.ts.map +1 -0
- package/types/output/schema/couch/couch.output.schema.d.ts +113 -0
- package/types/output/schema/couch/couch.output.schema.d.ts.map +1 -0
- package/types/output/schema/sugar/lock.d.mts +19 -0
- package/types/output/schema/sugar/lock.d.mts.map +1 -0
- package/types/output/schema/sugar/watch.d.mts +11 -0
- package/types/output/schema/sugar/watch.d.mts.map +1 -0
- package/types/output/schema/util.d.mts +85 -0
- package/types/output/schema/util.d.mts.map +1 -0
- package/types/output/tsdown.config.d.ts +3 -0
- package/types/output/tsdown.config.d.ts.map +1 -0
- package/types/output/types/standard-schema.d.ts +60 -0
- package/types/output/types/standard-schema.d.ts.map +1 -0
- package/types/standard-schema.ts +76 -0
- package/types/utils.d.ts +1 -0
- package/cjs/impl/bulk.cjs +0 -275
- package/cjs/impl/changes.cjs +0 -67
- package/cjs/impl/crud.cjs +0 -127
- package/cjs/impl/errors.cjs +0 -75
- package/cjs/impl/logger.cjs +0 -70
- package/cjs/impl/patch.cjs +0 -95
- package/cjs/impl/query.cjs +0 -116
- package/cjs/impl/queryBuilder.cjs +0 -163
- package/cjs/impl/retry.cjs +0 -55
- package/cjs/impl/stream.cjs +0 -121
- package/cjs/impl/sugar/lock.cjs +0 -81
- package/cjs/impl/sugar/watch.cjs +0 -159
- package/cjs/impl/trackedEmitter.cjs +0 -54
- package/cjs/impl/transactionErrors.cjs +0 -70
- package/cjs/impl/util.cjs +0 -64
- package/cjs/index.cjs +0 -132
- package/cjs/integration/changes.cjs +0 -76
- package/cjs/integration/disconnect-watch.cjs +0 -52
- package/cjs/integration/watch.cjs +0 -59
- package/cjs/schema/bind.cjs +0 -59
- package/cjs/schema/bulk.cjs +0 -92
- package/cjs/schema/changes.cjs +0 -68
- package/cjs/schema/config.cjs +0 -48
- package/cjs/schema/crud.cjs +0 -77
- package/cjs/schema/patch.cjs +0 -53
- package/cjs/schema/query.cjs +0 -62
- package/cjs/schema/stream.cjs +0 -42
- package/cjs/schema/sugar/lock.cjs +0 -59
- package/cjs/schema/sugar/watch.cjs +0 -42
- package/cjs/schema/util.cjs +0 -39
- package/config.json +0 -5
- package/docs/compiler.png +0 -0
- package/dualmode.config.json +0 -11
- package/impl/bulk.d.mts +0 -11
- package/impl/bulk.d.mts.map +0 -1
- package/impl/bulk.mjs +0 -291
- package/impl/changes.d.mts +0 -12
- package/impl/changes.d.mts.map +0 -1
- package/impl/changes.mjs +0 -53
- package/impl/crud.d.mts +0 -7
- package/impl/crud.d.mts.map +0 -1
- package/impl/crud.mjs +0 -108
- package/impl/errors.d.mts +0 -43
- package/impl/errors.d.mts.map +0 -1
- package/impl/errors.mjs +0 -65
- package/impl/logger.d.mts +0 -32
- package/impl/logger.d.mts.map +0 -1
- package/impl/logger.mjs +0 -59
- package/impl/patch.d.mts +0 -6
- package/impl/patch.d.mts.map +0 -1
- package/impl/patch.mjs +0 -88
- package/impl/query.d.mts +0 -195
- package/impl/query.d.mts.map +0 -1
- package/impl/query.mjs +0 -122
- package/impl/queryBuilder.d.mts +0 -154
- package/impl/queryBuilder.d.mts.map +0 -1
- package/impl/queryBuilder.mjs +0 -175
- package/impl/retry.d.mts +0 -2
- package/impl/retry.d.mts.map +0 -1
- package/impl/retry.mjs +0 -39
- package/impl/stream.d.mts +0 -3
- package/impl/stream.d.mts.map +0 -1
- package/impl/stream.mjs +0 -98
- package/impl/sugar/lock.d.mts +0 -5
- package/impl/sugar/lock.d.mts.map +0 -1
- package/impl/sugar/lock.mjs +0 -70
- package/impl/sugar/watch.d.mts +0 -34
- package/impl/sugar/watch.d.mts.map +0 -1
- package/impl/trackedEmitter.d.mts +0 -8
- package/impl/trackedEmitter.d.mts.map +0 -1
- package/impl/transactionErrors.d.mts.map +0 -1
- package/impl/transactionErrors.mjs +0 -47
- package/impl/util.d.mts +0 -3
- package/impl/util.d.mts.map +0 -1
- package/impl/util.mjs +0 -35
- package/index.d.mts +0 -80
- package/index.d.mts.map +0 -1
- package/index.mjs +0 -141
- package/integration/changes.mjs +0 -60
- package/integration/disconnect-watch.mjs +0 -36
- package/integration/watch.mjs +0 -40
- package/log.txt +0 -580
- package/schema/bind.d.mts +0 -5461
- package/schema/bind.d.mts.map +0 -1
- package/schema/bind.mjs +0 -43
- package/schema/bulk.d.mts +0 -923
- package/schema/bulk.d.mts.map +0 -1
- package/schema/bulk.mjs +0 -83
- package/schema/changes.d.mts +0 -191
- package/schema/changes.d.mts.map +0 -1
- package/schema/changes.mjs +0 -59
- package/schema/config.d.mts +0 -79
- package/schema/config.d.mts.map +0 -1
- package/schema/config.mjs +0 -26
- package/schema/crud.d.mts +0 -491
- package/schema/crud.d.mts.map +0 -1
- package/schema/crud.mjs +0 -64
- package/schema/patch.d.mts +0 -255
- package/schema/patch.d.mts.map +0 -1
- package/schema/patch.mjs +0 -42
- package/schema/query.d.mts +0 -406
- package/schema/query.d.mts.map +0 -1
- package/schema/query.mjs +0 -45
- package/schema/stream.d.mts +0 -211
- package/schema/stream.d.mts.map +0 -1
- package/schema/stream.mjs +0 -23
- package/schema/sugar/lock.d.mts +0 -238
- package/schema/sugar/lock.d.mts.map +0 -1
- package/schema/sugar/lock.mjs +0 -50
- package/schema/sugar/watch.d.mts +0 -127
- package/schema/sugar/watch.d.mts.map +0 -1
- package/schema/sugar/watch.mjs +0 -29
- package/schema/util.d.mts +0 -160
- package/schema/util.d.mts.map +0 -1
- package/schema/util.mjs +0 -35
- package/types/changes-stream.d.ts +0 -11
package/impl/query.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.mts","sourceRoot":"","sources":["query.mjs"],"names":[],"mappings":"AA8FA;;;GAGG;AACH;;;;GAIG;AACH,qCAJW;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,sBACtB,MAAM,EAAE,GACN,MAAM,CAoBlB;AA9GD;;;;;GAKG;AACH,oBALW,CAAC,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAAiB,CAgFjC;kBA1FgB,KAAK"}
|
package/impl/query.mjs
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { z } from 'zod' // eslint-disable-line
|
|
4
|
-
import needle from 'needle'
|
|
5
|
-
import { SimpleViewQuery, SimpleViewQueryResponse } from '../schema/query.mjs' // eslint-disable-line
|
|
6
|
-
import { RetryableError } from './errors.mjs'
|
|
7
|
-
import { createLogger } from './logger.mjs'
|
|
8
|
-
|
|
9
|
-
import pkg from 'lodash'
|
|
10
|
-
const { includes } = pkg
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @type { z.infer<SimpleViewQuery> }
|
|
14
|
-
* @param {import('../schema/config.mjs').CouchConfigSchema} config
|
|
15
|
-
* @param {string} view
|
|
16
|
-
* @param {import('../schema/query.mjs').SimpleViewOptionsSchema} [options]
|
|
17
|
-
*/
|
|
18
|
-
export const query = SimpleViewQuery.implement(async (config, view, options = {}) => {
|
|
19
|
-
const logger = createLogger(config)
|
|
20
|
-
logger.info(`Starting view query: ${view}`)
|
|
21
|
-
logger.debug('Query options:', options)
|
|
22
|
-
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
let qs = queryString(options, ['key', 'startkey', 'endkey', 'reduce', 'group', 'group_level', 'stale', 'limit'])
|
|
25
|
-
let method = 'GET'
|
|
26
|
-
let payload = null
|
|
27
|
-
const opts = {
|
|
28
|
-
json: true,
|
|
29
|
-
headers: {
|
|
30
|
-
'Content-Type': 'application/json'
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// If keys are supplied, issue a POST to circumvent GET query string limits
|
|
35
|
-
// see http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
|
|
36
|
-
if (typeof options.keys !== 'undefined') {
|
|
37
|
-
const MAX_URL_LENGTH = 2000
|
|
38
|
-
// according to http://stackoverflow.com/a/417184/680742,
|
|
39
|
-
// the de facto URL length limit is 2000 characters
|
|
40
|
-
|
|
41
|
-
const _options = JSON.parse(JSON.stringify(options))
|
|
42
|
-
delete _options.keys
|
|
43
|
-
qs = queryString(_options, ['key', 'startkey', 'endkey', 'reduce', 'group', 'group_level', 'stale', 'limit']) // dont need descening or skip, those will work
|
|
44
|
-
|
|
45
|
-
const keysAsString = `keys=${JSON.stringify(options.keys)}`
|
|
46
|
-
|
|
47
|
-
if (keysAsString.length + qs.length + 1 <= MAX_URL_LENGTH) {
|
|
48
|
-
// If the keys are short enough, do a GET. we do this to work around
|
|
49
|
-
// Safari not understanding 304s on POSTs (see pouchdb/pouchdb#1239)
|
|
50
|
-
method = 'GET'
|
|
51
|
-
if (qs.length > 0) qs += '&'
|
|
52
|
-
else qs = ''
|
|
53
|
-
qs += keysAsString
|
|
54
|
-
} else {
|
|
55
|
-
method = 'POST'
|
|
56
|
-
payload = { keys: options.keys }
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
logger.debug('Generated query string:', qs)
|
|
61
|
-
const url = `${config.couch}/${view}?${qs.toString()}`
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
let results
|
|
64
|
-
try {
|
|
65
|
-
logger.debug(`Sending ${method} request to: ${url}`)
|
|
66
|
-
results = (method === 'GET') ? await needle('get', url, opts) : await needle('post', url, payload, opts)
|
|
67
|
-
} catch (err) {
|
|
68
|
-
logger.error('Network error during query:', err)
|
|
69
|
-
RetryableError.handleNetworkError(err)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (!results) {
|
|
73
|
-
logger.error('No response received from query request')
|
|
74
|
-
throw new RetryableError('no response', 503)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** @type { z.infer<SimpleViewQueryResponse> } body */
|
|
78
|
-
const body = results.body
|
|
79
|
-
|
|
80
|
-
if (RetryableError.isRetryableStatusCode(results.statusCode)) {
|
|
81
|
-
logger.warn(`Retryable status code received: ${results.statusCode}`)
|
|
82
|
-
throw new RetryableError(body.error || 'retryable error during query', results.statusCode)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (body.error) {
|
|
86
|
-
logger.error(`Query error: ${body.error}`)
|
|
87
|
-
throw new Error(body.error)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
logger.info(`Successfully executed view query: ${view}`)
|
|
91
|
-
logger.debug('Query response:', body)
|
|
92
|
-
return body
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @param {{ [key: string]: any }} options - The options object containing query parameters.
|
|
97
|
-
* @param {string[]} params - The list of parameter names to include in the query string.
|
|
98
|
-
*/
|
|
99
|
-
/**
|
|
100
|
-
* @param {{ [key: string]: any }} options
|
|
101
|
-
* @param {string[]} params
|
|
102
|
-
* @returns {string}
|
|
103
|
-
*/
|
|
104
|
-
export function queryString (options = {}, params) {
|
|
105
|
-
const parts = Object.keys(options).map(key => {
|
|
106
|
-
let value = options[key]
|
|
107
|
-
if (includes(params, key)) {
|
|
108
|
-
if (typeof value === 'string' && key !== 'stale') value = `"${value}"`
|
|
109
|
-
if (Array.isArray(value)) {
|
|
110
|
-
value = '[' + value.map(i => {
|
|
111
|
-
if (i === null) return 'null'
|
|
112
|
-
if (typeof i === 'string') return `"${i}"`
|
|
113
|
-
if (typeof i === 'object' && Object.keys(i).length === 0) return '{}'
|
|
114
|
-
if (typeof i === 'object') return JSON.stringify(i)
|
|
115
|
-
return i
|
|
116
|
-
}).join(',') + ']'
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return `${key}=${value}`
|
|
120
|
-
})
|
|
121
|
-
return parts.join('&')
|
|
122
|
-
}
|
package/impl/queryBuilder.d.mts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Object} QueryOptions
|
|
3
|
-
* @property {any} [key] - Exact key to match
|
|
4
|
-
* @property {any} [startkey] - Start of key range
|
|
5
|
-
* @property {any} [endkey] - End of key range
|
|
6
|
-
* @property {boolean} [reduce] - Whether to use reduce function
|
|
7
|
-
* @property {boolean} [group] - Whether to group results
|
|
8
|
-
* @property {number} [group_level] - Level at which to group
|
|
9
|
-
* @property {boolean} [include_docs] - Whether to include full couch docs
|
|
10
|
-
* @property {string} [stale] - Stale parameter value
|
|
11
|
-
* @property {number} [limit] - Max number of results
|
|
12
|
-
* @property {boolean} [descending] - Whether to return results in descending order
|
|
13
|
-
* @property {number} [skip] - Number of results to skip
|
|
14
|
-
* @property {any[]} [keys] - Array of keys to match
|
|
15
|
-
*/
|
|
16
|
-
export class QueryBuilder {
|
|
17
|
-
/**
|
|
18
|
-
* @param {any} key
|
|
19
|
-
* @returns {QueryBuilder}
|
|
20
|
-
*/
|
|
21
|
-
key(key: any): QueryBuilder;
|
|
22
|
-
/**
|
|
23
|
-
* @param {any} startkey
|
|
24
|
-
* @returns {QueryBuilder}
|
|
25
|
-
*/
|
|
26
|
-
startKey(startkey: any): QueryBuilder;
|
|
27
|
-
/**
|
|
28
|
-
* @param {any} startkey
|
|
29
|
-
* @returns {QueryBuilder}
|
|
30
|
-
*/
|
|
31
|
-
startkey(startkey: any): QueryBuilder;
|
|
32
|
-
/**
|
|
33
|
-
* @param {any} endkey
|
|
34
|
-
* @returns {QueryBuilder}
|
|
35
|
-
*/
|
|
36
|
-
endKey(endkey: any): QueryBuilder;
|
|
37
|
-
/**
|
|
38
|
-
* @param {any} endkey
|
|
39
|
-
* @returns {QueryBuilder}
|
|
40
|
-
*/
|
|
41
|
-
endkey(endkey: any): QueryBuilder;
|
|
42
|
-
/**
|
|
43
|
-
* @param {boolean} reduce
|
|
44
|
-
* @returns {QueryBuilder}
|
|
45
|
-
*/
|
|
46
|
-
reduce(reduce?: boolean): QueryBuilder;
|
|
47
|
-
/**
|
|
48
|
-
* @param {boolean} group
|
|
49
|
-
* @returns {QueryBuilder}
|
|
50
|
-
*/
|
|
51
|
-
group(group?: boolean): QueryBuilder;
|
|
52
|
-
/**
|
|
53
|
-
* @param {number} level
|
|
54
|
-
* @returns {QueryBuilder}
|
|
55
|
-
*/
|
|
56
|
-
groupLevel(level: number): QueryBuilder;
|
|
57
|
-
/**
|
|
58
|
-
* @param {number} level
|
|
59
|
-
* @returns {QueryBuilder}
|
|
60
|
-
*/
|
|
61
|
-
group_level(level: number): QueryBuilder;
|
|
62
|
-
/**
|
|
63
|
-
* @param {boolean} includeDocs
|
|
64
|
-
* @returns {QueryBuilder}
|
|
65
|
-
*/
|
|
66
|
-
includeDocs(includeDocs?: boolean): QueryBuilder;
|
|
67
|
-
/**
|
|
68
|
-
* @param {boolean} includeDocs
|
|
69
|
-
* @returns {QueryBuilder}
|
|
70
|
-
*/
|
|
71
|
-
include_docs(includeDocs?: boolean): QueryBuilder;
|
|
72
|
-
/**
|
|
73
|
-
* @param {string} stale
|
|
74
|
-
* @returns {QueryBuilder}
|
|
75
|
-
*/
|
|
76
|
-
stale(stale: string): QueryBuilder;
|
|
77
|
-
/**
|
|
78
|
-
* @param {number} limit
|
|
79
|
-
* @returns {QueryBuilder}
|
|
80
|
-
*/
|
|
81
|
-
limit(limit: number): QueryBuilder;
|
|
82
|
-
/**
|
|
83
|
-
* @param {boolean} descending
|
|
84
|
-
* @returns {QueryBuilder}
|
|
85
|
-
*/
|
|
86
|
-
descending(descending?: boolean): QueryBuilder;
|
|
87
|
-
/**
|
|
88
|
-
* @param {number} skip
|
|
89
|
-
* @returns {QueryBuilder}
|
|
90
|
-
*/
|
|
91
|
-
skip(skip: number): QueryBuilder;
|
|
92
|
-
/**
|
|
93
|
-
* @param {any[]} keys
|
|
94
|
-
* @returns {QueryBuilder}
|
|
95
|
-
*/
|
|
96
|
-
keys(keys: any[]): QueryBuilder;
|
|
97
|
-
/**
|
|
98
|
-
* @returns {QueryOptions}
|
|
99
|
-
*/
|
|
100
|
-
build(): QueryOptions;
|
|
101
|
-
#private;
|
|
102
|
-
}
|
|
103
|
-
export function createQuery(): QueryBuilder;
|
|
104
|
-
export type QueryOptions = {
|
|
105
|
-
/**
|
|
106
|
-
* - Exact key to match
|
|
107
|
-
*/
|
|
108
|
-
key?: any;
|
|
109
|
-
/**
|
|
110
|
-
* - Start of key range
|
|
111
|
-
*/
|
|
112
|
-
startkey?: any;
|
|
113
|
-
/**
|
|
114
|
-
* - End of key range
|
|
115
|
-
*/
|
|
116
|
-
endkey?: any;
|
|
117
|
-
/**
|
|
118
|
-
* - Whether to use reduce function
|
|
119
|
-
*/
|
|
120
|
-
reduce?: boolean | undefined;
|
|
121
|
-
/**
|
|
122
|
-
* - Whether to group results
|
|
123
|
-
*/
|
|
124
|
-
group?: boolean | undefined;
|
|
125
|
-
/**
|
|
126
|
-
* - Level at which to group
|
|
127
|
-
*/
|
|
128
|
-
group_level?: number | undefined;
|
|
129
|
-
/**
|
|
130
|
-
* - Whether to include full couch docs
|
|
131
|
-
*/
|
|
132
|
-
include_docs?: boolean | undefined;
|
|
133
|
-
/**
|
|
134
|
-
* - Stale parameter value
|
|
135
|
-
*/
|
|
136
|
-
stale?: string | undefined;
|
|
137
|
-
/**
|
|
138
|
-
* - Max number of results
|
|
139
|
-
*/
|
|
140
|
-
limit?: number | undefined;
|
|
141
|
-
/**
|
|
142
|
-
* - Whether to return results in descending order
|
|
143
|
-
*/
|
|
144
|
-
descending?: boolean | undefined;
|
|
145
|
-
/**
|
|
146
|
-
* - Number of results to skip
|
|
147
|
-
*/
|
|
148
|
-
skip?: number | undefined;
|
|
149
|
-
/**
|
|
150
|
-
* - Array of keys to match
|
|
151
|
-
*/
|
|
152
|
-
keys?: any[] | undefined;
|
|
153
|
-
};
|
|
154
|
-
//# sourceMappingURL=queryBuilder.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryBuilder.d.mts","sourceRoot":"","sources":["queryBuilder.mjs"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH;IAIE;;;OAGG;IACH,SAHW,GAAG,GACD,YAAY,CAKxB;IAED;;;OAGG;IACH,mBAHW,GAAG,GACD,YAAY,CAKxB;IAED;;;OAGG;IACH,mBAHW,GAAG,GACD,YAAY,CAKxB;IAED;;;OAGG;IACH,eAHW,GAAG,GACD,YAAY,CAKxB;IAED;;;OAGG;IACH,eAHW,GAAG,GACD,YAAY,CAKxB;IAED;;;OAGG;IACH,gBAHW,OAAO,GACL,YAAY,CAKxB;IAED;;;OAGG;IACH,cAHW,OAAO,GACL,YAAY,CAKxB;IAED;;;OAGG;IACH,kBAHW,MAAM,GACJ,YAAY,CAKxB;IAED;;;OAGG;IACH,mBAHW,MAAM,GACJ,YAAY,CAKxB;IAED;;;OAGG;IACH,0BAHW,OAAO,GACL,YAAY,CAKxB;IAED;;;OAGG;IACH,2BAHW,OAAO,GACL,YAAY,CAKxB;IAED;;;OAGG;IACH,aAHW,MAAM,GACJ,YAAY,CAKxB;IAED;;;OAGG;IACH,aAHW,MAAM,GACJ,YAAY,CAKxB;IAED;;;OAGG;IACH,wBAHW,OAAO,GACL,YAAY,CAKxB;IAED;;;OAGG;IACH,WAHW,MAAM,GACJ,YAAY,CAKxB;IAED;;;OAGG;IACH,WAHW,GAAG,EAAE,GACH,YAAY,CAKxB;IAED;;OAEG;IACH,SAFa,YAAY,CAIxB;;CACF;AAEM,4CAA4C;;;;;UA1KrC,GAAG;;;;eACH,GAAG;;;;aACH,GAAG"}
|
package/impl/queryBuilder.mjs
DELETED
|
@@ -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
package/impl/retry.d.mts.map
DELETED
|
@@ -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
package/impl/stream.d.mts.map
DELETED
|
@@ -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
|
-
})
|
package/impl/sugar/lock.d.mts
DELETED
|
@@ -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"}
|
package/impl/sugar/lock.mjs
DELETED
|
@@ -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
|
-
})
|