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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
import type { StandardSchemaV1 } from '../../types/standard-schema.ts'
|
|
3
|
+
|
|
4
|
+
export type ViewString = '_all_docs' | `_design/${string}/_view/${string}`
|
|
5
|
+
|
|
6
|
+
export const ViewOptions = z
|
|
7
|
+
.object({
|
|
8
|
+
descending: z.boolean().optional().describe('sort results descending'),
|
|
9
|
+
endkey_docid: z
|
|
10
|
+
.string()
|
|
11
|
+
.optional()
|
|
12
|
+
.describe('stop returning records when this document ID is reached'),
|
|
13
|
+
endkey: z.any().optional(),
|
|
14
|
+
group_level: z.number().positive().optional().describe('group the results at this level'),
|
|
15
|
+
group: z.boolean().optional().describe('group the results'),
|
|
16
|
+
include_docs: z.boolean().optional().describe('join the id to the doc and return it'),
|
|
17
|
+
inclusive_end: z
|
|
18
|
+
.boolean()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('whether the endkey is included in the result, default true'),
|
|
21
|
+
key: z.any().optional(),
|
|
22
|
+
keys: z.array(z.any()).optional(),
|
|
23
|
+
limit: z.number().nonnegative().optional().describe('limit the results to this many rows'),
|
|
24
|
+
reduce: z.boolean().optional().describe('reduce the results'),
|
|
25
|
+
skip: z.number().nonnegative().optional().describe('skip this many rows'),
|
|
26
|
+
sorted: z.boolean().optional().describe('sort returned rows, default true'),
|
|
27
|
+
stable: z
|
|
28
|
+
.boolean()
|
|
29
|
+
.optional()
|
|
30
|
+
.describe('ensure the view index is not updated during the query, default false'),
|
|
31
|
+
startkey: z.any().optional(),
|
|
32
|
+
startkey_docid: z
|
|
33
|
+
.string()
|
|
34
|
+
.optional()
|
|
35
|
+
.describe('start returning records when this document ID is reached'),
|
|
36
|
+
update: z
|
|
37
|
+
.enum(['true', 'false', 'lazy'])
|
|
38
|
+
.optional()
|
|
39
|
+
.describe('whether to update the view index before returning results, default true'),
|
|
40
|
+
update_seq: z.boolean().optional().describe('include the update sequence in the result')
|
|
41
|
+
})
|
|
42
|
+
.describe('base options for a CouchDB view query')
|
|
43
|
+
export type ViewOptions = StandardSchemaV1.InferOutput<typeof ViewOptions>
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { StandardSchemaV1 } from '../../types/standard-schema.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Default schema for a returned CouchDB document if no validation schema is provided.
|
|
6
|
+
*/
|
|
7
|
+
export const CouchDoc = z.looseObject({
|
|
8
|
+
_id: z.string().describe('the couch doc id'),
|
|
9
|
+
_rev: z.string().optional().nullish().describe('the doc revision'),
|
|
10
|
+
_deleted: z.boolean().optional().describe('is the doc deleted')
|
|
11
|
+
})
|
|
12
|
+
export type CouchDoc = StandardSchemaV1.InferOutput<typeof CouchDoc>
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A type for input CouchDB documents (without required _id).
|
|
16
|
+
*/
|
|
17
|
+
export type CouchDocInput = Omit<CouchDoc, '_id'> & { _id?: string }
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Default schema for a CouchDB view row if no validation schema is provided.
|
|
21
|
+
*/
|
|
22
|
+
export const ViewRow = z.object({
|
|
23
|
+
id: z.string().optional(),
|
|
24
|
+
key: z.any().nullish(),
|
|
25
|
+
value: z.any().nullish(),
|
|
26
|
+
doc: CouchDoc.nullish(),
|
|
27
|
+
error: z.string().optional().describe('usually not_found, if something is wrong with this doc')
|
|
28
|
+
})
|
|
29
|
+
export type ViewRow = StandardSchemaV1.InferOutput<typeof ViewRow>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A CouchDB view row with validated key, value, and document schemas.
|
|
33
|
+
*/
|
|
34
|
+
export type ViewRowValidated<
|
|
35
|
+
DocSchema extends StandardSchemaV1,
|
|
36
|
+
KeySchema extends StandardSchemaV1,
|
|
37
|
+
ValueSchema extends StandardSchemaV1
|
|
38
|
+
> = {
|
|
39
|
+
id?: string
|
|
40
|
+
key?: StandardSchemaV1.InferOutput<KeySchema>
|
|
41
|
+
value?: StandardSchemaV1.InferOutput<ValueSchema>
|
|
42
|
+
doc?: StandardSchemaV1.InferOutput<DocSchema>
|
|
43
|
+
error?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Response type for a CouchDB view query if no validation schemas are provided.
|
|
48
|
+
*/
|
|
49
|
+
export const ViewQueryResponse = z.object({
|
|
50
|
+
total_rows: z.number().nonnegative().optional().describe('total rows in the view'),
|
|
51
|
+
offset: z
|
|
52
|
+
.number()
|
|
53
|
+
.nonnegative()
|
|
54
|
+
.optional()
|
|
55
|
+
.describe('the offset of the first row in this result set'),
|
|
56
|
+
error: z.string().optional().describe('if something is wrong'),
|
|
57
|
+
rows: z.array(ViewRow).optional().describe('the rows returned by the view'),
|
|
58
|
+
update_seq: z
|
|
59
|
+
.number()
|
|
60
|
+
.optional()
|
|
61
|
+
.describe('the update sequence of the database at the time of the query')
|
|
62
|
+
})
|
|
63
|
+
export type ViewQueryResponse = StandardSchemaV1.InferOutput<typeof ViewQueryResponse>
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Response type for a CouchDB view query with validated key, value, and document schemas.
|
|
67
|
+
*/
|
|
68
|
+
export type ViewQueryResponseValidated<
|
|
69
|
+
DocSchema extends StandardSchemaV1,
|
|
70
|
+
KeySchema extends StandardSchemaV1 = StandardSchemaV1<unknown>,
|
|
71
|
+
ValueSchema extends StandardSchemaV1 = StandardSchemaV1<unknown>
|
|
72
|
+
> = Omit<ViewQueryResponse, 'rows'> & {
|
|
73
|
+
rows: Array<ViewRowValidated<DocSchema, KeySchema, ValueSchema>>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* CouchDB _bulk_docs response schema
|
|
78
|
+
*/
|
|
79
|
+
export const BulkSaveResponse = z.array(
|
|
80
|
+
z.object({
|
|
81
|
+
ok: z.boolean().nullish(),
|
|
82
|
+
id: z.string().nullish(),
|
|
83
|
+
rev: z.string().nullish(),
|
|
84
|
+
error: z.string().nullish().describe('if an error occurred, one word reason, eg conflict'),
|
|
85
|
+
reason: z.string().nullish().describe('a full error message')
|
|
86
|
+
})
|
|
87
|
+
)
|
|
88
|
+
export type BulkSaveResponse = z.infer<typeof BulkSaveResponse>
|
|
89
|
+
|
|
90
|
+
export const CouchPutResponse = z.object({
|
|
91
|
+
ok: z.boolean().optional().describe('did the request succeed'),
|
|
92
|
+
error: z.string().optional().describe('the error message, if did not succeed'),
|
|
93
|
+
statusCode: z.number(),
|
|
94
|
+
id: z.string().optional().describe('the couch doc id'),
|
|
95
|
+
rev: z.string().optional().describe('the new rev of the doc')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
export const CouchDBInfo = z.looseObject({
|
|
99
|
+
cluster: z
|
|
100
|
+
.object({
|
|
101
|
+
n: z.number().describe('Replicas. The number of copies of every document.').optional(),
|
|
102
|
+
q: z.number().describe('Shards. The number of range partitions.').optional(),
|
|
103
|
+
r: z
|
|
104
|
+
.number()
|
|
105
|
+
.describe(
|
|
106
|
+
'Read quorum. The number of consistent copies of a document that need to be read before a successful reply.'
|
|
107
|
+
)
|
|
108
|
+
.optional(),
|
|
109
|
+
w: z
|
|
110
|
+
.number()
|
|
111
|
+
.describe(
|
|
112
|
+
'Write quorum. The number of copies of a document that need to be written before a successful reply.'
|
|
113
|
+
)
|
|
114
|
+
.optional()
|
|
115
|
+
})
|
|
116
|
+
.optional(),
|
|
117
|
+
compact_running: z
|
|
118
|
+
.boolean()
|
|
119
|
+
.describe('Set to true if the database compaction routine is operating on this database.')
|
|
120
|
+
.optional(),
|
|
121
|
+
db_name: z.string().describe('The name of the database.'),
|
|
122
|
+
disk_format_version: z
|
|
123
|
+
.number()
|
|
124
|
+
.describe('The version of the physical format used for the data when it is stored on disk.')
|
|
125
|
+
.optional(),
|
|
126
|
+
doc_count: z.number().describe('A count of the documents in the specified database.').optional(),
|
|
127
|
+
doc_del_count: z.number().describe('Number of deleted documents').optional(),
|
|
128
|
+
instance_start_time: z.string().optional(),
|
|
129
|
+
purge_seq: z
|
|
130
|
+
.string()
|
|
131
|
+
.describe(
|
|
132
|
+
'An opaque string that describes the purge state of the database. Do not rely on this string for counting the number of purge operations.'
|
|
133
|
+
)
|
|
134
|
+
.optional(),
|
|
135
|
+
sizes: z
|
|
136
|
+
.object({
|
|
137
|
+
active: z
|
|
138
|
+
.number()
|
|
139
|
+
.describe('The size of live data inside the database, in bytes.')
|
|
140
|
+
.optional(),
|
|
141
|
+
external: z
|
|
142
|
+
.number()
|
|
143
|
+
.describe('The uncompressed size of database contents in bytes.')
|
|
144
|
+
.optional(),
|
|
145
|
+
file: z
|
|
146
|
+
.number()
|
|
147
|
+
.describe(
|
|
148
|
+
'The size of the database file on disk in bytes. Views indexes are not included in the calculation.'
|
|
149
|
+
)
|
|
150
|
+
.optional()
|
|
151
|
+
})
|
|
152
|
+
.optional(),
|
|
153
|
+
update_seq: z
|
|
154
|
+
.string()
|
|
155
|
+
.or(z.number())
|
|
156
|
+
.describe(
|
|
157
|
+
'An opaque string that describes the state of the database. Do not rely on this string for counting the number of updates.'
|
|
158
|
+
)
|
|
159
|
+
.optional(),
|
|
160
|
+
props: z
|
|
161
|
+
.object({
|
|
162
|
+
partitioned: z
|
|
163
|
+
.boolean()
|
|
164
|
+
.describe('If present and true, this indicates that the database is partitioned.')
|
|
165
|
+
.optional()
|
|
166
|
+
})
|
|
167
|
+
.optional()
|
|
168
|
+
})
|
|
169
|
+
export type CouchDBInfo = z.infer<typeof CouchDBInfo>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { CouchDoc } from '../couch/couch.output.schema.ts'
|
|
3
|
+
import type { StandardSchemaV1 } from '../../types/standard-schema.ts'
|
|
4
|
+
|
|
5
|
+
export const LockDoc = CouchDoc.extend({
|
|
6
|
+
type: z.literal('lock'),
|
|
7
|
+
locks: z.string().describe('the document ID being locked'),
|
|
8
|
+
lockedAt: z.string().describe('ISO timestamp when lock was created'),
|
|
9
|
+
lockedBy: z.string().describe('username of who created the lock')
|
|
10
|
+
})
|
|
11
|
+
export type LockDoc = StandardSchemaV1.InferOutput<typeof LockDoc>
|
|
12
|
+
|
|
13
|
+
export const LockOptions = z.object({
|
|
14
|
+
enableLocking: z.boolean().prefault(true).describe('whether locking is enabled'),
|
|
15
|
+
username: z.string().describe('username to attribute locks to')
|
|
16
|
+
})
|
|
17
|
+
export type LockOptions = StandardSchemaV1.InferOutput<typeof LockOptions>
|
|
18
|
+
export type LockOptionsInput = StandardSchemaV1.InferInput<typeof LockOptions>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { StandardSchemaV1 } from '../../types/standard-schema.ts'
|
|
3
|
+
|
|
4
|
+
export const WatchOptions = z
|
|
5
|
+
.object({
|
|
6
|
+
include_docs: z.boolean().default(false),
|
|
7
|
+
maxRetries: z.number().describe('maximum number of retries before giving up'),
|
|
8
|
+
initialDelay: z.number().describe('initial delay between retries in milliseconds'),
|
|
9
|
+
maxDelay: z.number().describe('maximum delay between retries in milliseconds')
|
|
10
|
+
})
|
|
11
|
+
.partial()
|
|
12
|
+
|
|
13
|
+
export type WatchOptions = StandardSchemaV1.InferOutput<typeof WatchOptions>
|
|
14
|
+
export type WatchOptionsInput = StandardSchemaV1.InferInput<typeof WatchOptions>
|
package/schema/util.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { CouchConfig, NeedleBaseOptions, NeedleOptions } from './config.mts'
|
|
3
|
+
|
|
4
|
+
export const MergeNeedleOpts = z.function({
|
|
5
|
+
input: [CouchConfig, NeedleBaseOptions],
|
|
6
|
+
output: NeedleOptions
|
|
7
|
+
})
|
|
8
|
+
export type MergeNeedleOptsSchema = z.infer<typeof MergeNeedleOpts>
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"exclude": ["node_modules", "dist", "types/output", "docs"],
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"module": "
|
|
5
|
-
"target": "
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"target": "esnext",
|
|
6
|
+
"erasableSyntaxOnly": true,
|
|
7
|
+
"rewriteRelativeImportExtensions": true,
|
|
8
|
+
"allowImportingTsExtensions": true,
|
|
6
9
|
"verbatimModuleSyntax": true,
|
|
7
10
|
"strict": true,
|
|
8
11
|
"allowJs": true,
|
|
12
|
+
"checkJs": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
9
14
|
"declaration": true,
|
|
10
15
|
"emitDeclarationOnly": true,
|
|
11
|
-
"declarationMap": true
|
|
16
|
+
"declarationMap": true,
|
|
17
|
+
"outDir": "types/output"
|
|
12
18
|
}
|
|
13
19
|
}
|
package/tsdown.config.ts
ADDED
package/typedoc.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eslint.config.d.ts","sourceRoot":"","sources":["../../eslint.config.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type z from 'zod';
|
|
2
|
+
import { CouchConfig, type CouchConfigInput } from '../schema/config.mts';
|
|
3
|
+
import { type BulkGetBound, type BulkGetDictionaryBound } from './bulkGet.mts';
|
|
4
|
+
import { type GetBound, type GetAtRevBound } from './get.mts';
|
|
5
|
+
import type { QueryBound } from './query.mts';
|
|
6
|
+
export type BoundInstance = ReturnType<typeof doBind> & {
|
|
7
|
+
options(overrides: Partial<z.input<typeof CouchConfig>>): BoundInstance;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Build a validated binding that exposes CouchDB helpers plus an options() helper for overrides.
|
|
11
|
+
* @param config The CouchDB configuration
|
|
12
|
+
* @returns A bound instance with CouchDB operations and an options() method for overrides
|
|
13
|
+
*/
|
|
14
|
+
export declare const bindConfig: (config: CouchConfigInput) => BoundInstance;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*
|
|
18
|
+
* Helper to bind a function to a config, optionally wrapping it with retry logic.
|
|
19
|
+
* Casts to the appropriate bound function type.
|
|
20
|
+
* @param func The function to bind
|
|
21
|
+
* @param config The CouchDB configuration
|
|
22
|
+
* @returns The bound function, possibly wrapped with retry logic
|
|
23
|
+
*/
|
|
24
|
+
export declare function getBoundWithRetry<TBound extends (...args: any[]) => Promise<any>>(func: (config: CouchConfig, ...args: any[]) => Promise<any>, config: CouchConfig): TBound;
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*
|
|
28
|
+
* Bind core CouchDB operations to a specific configuration, optionally applying retry wrappers.
|
|
29
|
+
* @param config The CouchDB configuration
|
|
30
|
+
* @returns An object with CouchDB operations bound to the provided configuration
|
|
31
|
+
*/
|
|
32
|
+
declare function doBind(config: CouchConfig): {
|
|
33
|
+
/**
|
|
34
|
+
* These functions use overloaded signatures when bound.
|
|
35
|
+
* To preserve the overloads we need dedicated Bound types
|
|
36
|
+
*/
|
|
37
|
+
bulkGet: BulkGetBound;
|
|
38
|
+
bulkGetDictionary: BulkGetDictionaryBound;
|
|
39
|
+
get: GetBound;
|
|
40
|
+
getAtRev: GetAtRevBound;
|
|
41
|
+
query: QueryBound;
|
|
42
|
+
/**
|
|
43
|
+
* These functions have single signatures and can be bound directly
|
|
44
|
+
*/
|
|
45
|
+
bulkRemove: (ids: string[]) => Promise<{
|
|
46
|
+
ok?: boolean | null | undefined;
|
|
47
|
+
id?: string | null | undefined;
|
|
48
|
+
rev?: string | null | undefined;
|
|
49
|
+
error?: string | null | undefined;
|
|
50
|
+
reason?: string | null | undefined;
|
|
51
|
+
}[]>;
|
|
52
|
+
bulkRemoveMap: (ids: string[]) => Promise<{
|
|
53
|
+
statusCode: number;
|
|
54
|
+
ok?: boolean | undefined;
|
|
55
|
+
error?: string | undefined;
|
|
56
|
+
id?: string | undefined;
|
|
57
|
+
rev?: string | undefined;
|
|
58
|
+
}[]>;
|
|
59
|
+
bulkSave: (docs: import("../index.mts").CouchDocInput[]) => Promise<{
|
|
60
|
+
ok?: boolean | null | undefined;
|
|
61
|
+
id?: string | null | undefined;
|
|
62
|
+
rev?: string | null | undefined;
|
|
63
|
+
error?: string | null | undefined;
|
|
64
|
+
reason?: string | null | undefined;
|
|
65
|
+
}[]>;
|
|
66
|
+
bulkSaveTransaction: (transactionId: string, docs: import("../index.mts").CouchDocInput[]) => Promise<{
|
|
67
|
+
ok?: boolean | null | undefined;
|
|
68
|
+
id?: string | null | undefined;
|
|
69
|
+
rev?: string | null | undefined;
|
|
70
|
+
error?: string | null | undefined;
|
|
71
|
+
reason?: string | null | undefined;
|
|
72
|
+
}[]>;
|
|
73
|
+
getDBInfo: () => Promise<{
|
|
74
|
+
[x: string]: unknown;
|
|
75
|
+
db_name: string;
|
|
76
|
+
cluster?: {
|
|
77
|
+
n?: number | undefined;
|
|
78
|
+
q?: number | undefined;
|
|
79
|
+
r?: number | undefined;
|
|
80
|
+
w?: number | undefined;
|
|
81
|
+
} | undefined;
|
|
82
|
+
compact_running?: boolean | undefined;
|
|
83
|
+
disk_format_version?: number | undefined;
|
|
84
|
+
doc_count?: number | undefined;
|
|
85
|
+
doc_del_count?: number | undefined;
|
|
86
|
+
instance_start_time?: string | undefined;
|
|
87
|
+
purge_seq?: string | undefined;
|
|
88
|
+
sizes?: {
|
|
89
|
+
active?: number | undefined;
|
|
90
|
+
external?: number | undefined;
|
|
91
|
+
file?: number | undefined;
|
|
92
|
+
} | undefined;
|
|
93
|
+
update_seq?: string | number | undefined;
|
|
94
|
+
props?: {
|
|
95
|
+
partitioned?: boolean | undefined;
|
|
96
|
+
} | undefined;
|
|
97
|
+
}>;
|
|
98
|
+
patch: (id: string, _properties: {
|
|
99
|
+
[x: string]: unknown;
|
|
100
|
+
_rev: string;
|
|
101
|
+
}) => Promise<{
|
|
102
|
+
statusCode: number;
|
|
103
|
+
ok?: boolean | undefined;
|
|
104
|
+
error?: string | undefined;
|
|
105
|
+
id?: string | undefined;
|
|
106
|
+
rev?: string | undefined;
|
|
107
|
+
}>;
|
|
108
|
+
patchDangerously: (id: string, properties: Record<string, unknown>) => Promise<{
|
|
109
|
+
statusCode: number;
|
|
110
|
+
ok?: boolean | undefined;
|
|
111
|
+
error?: string | undefined;
|
|
112
|
+
id?: string | undefined;
|
|
113
|
+
rev?: string | undefined;
|
|
114
|
+
} | undefined>;
|
|
115
|
+
put: (doc: {
|
|
116
|
+
[x: string]: unknown;
|
|
117
|
+
_id: string;
|
|
118
|
+
_rev?: string | null | undefined;
|
|
119
|
+
_deleted?: boolean | undefined;
|
|
120
|
+
}) => Promise<{
|
|
121
|
+
statusCode: number;
|
|
122
|
+
ok?: boolean | undefined;
|
|
123
|
+
error?: string | undefined;
|
|
124
|
+
id?: string | undefined;
|
|
125
|
+
rev?: string | undefined;
|
|
126
|
+
}>;
|
|
127
|
+
queryStream: (view: string, options: {
|
|
128
|
+
descending?: boolean | undefined;
|
|
129
|
+
endkey_docid?: string | undefined;
|
|
130
|
+
endkey?: any;
|
|
131
|
+
group_level?: number | undefined;
|
|
132
|
+
group?: boolean | undefined;
|
|
133
|
+
include_docs?: boolean | undefined;
|
|
134
|
+
inclusive_end?: boolean | undefined;
|
|
135
|
+
key?: any;
|
|
136
|
+
keys?: any[] | undefined;
|
|
137
|
+
limit?: number | undefined;
|
|
138
|
+
reduce?: boolean | undefined;
|
|
139
|
+
skip?: number | undefined;
|
|
140
|
+
sorted?: boolean | undefined;
|
|
141
|
+
stable?: boolean | undefined;
|
|
142
|
+
startkey?: any;
|
|
143
|
+
startkey_docid?: string | undefined;
|
|
144
|
+
update?: "lazy" | "true" | "false" | undefined;
|
|
145
|
+
update_seq?: boolean | undefined;
|
|
146
|
+
} | undefined, onRow: import("./stream.mts").OnRow) => Promise<void>;
|
|
147
|
+
remove: (id: string, rev: string) => Promise<{
|
|
148
|
+
statusCode: number;
|
|
149
|
+
ok?: boolean | undefined;
|
|
150
|
+
error?: string | undefined;
|
|
151
|
+
id?: string | undefined;
|
|
152
|
+
rev?: string | undefined;
|
|
153
|
+
}>;
|
|
154
|
+
createLock: (docId: string, lockOptions: {
|
|
155
|
+
enableLocking: boolean;
|
|
156
|
+
username: string;
|
|
157
|
+
}) => Promise<boolean>;
|
|
158
|
+
removeLock: (docId: string, lockOptions: {
|
|
159
|
+
enableLocking: boolean;
|
|
160
|
+
username: string;
|
|
161
|
+
}) => Promise<void>;
|
|
162
|
+
watchDocs: (docIds: string | string[], onChange: (change: any) => void, optionsInput?: {
|
|
163
|
+
include_docs?: boolean | undefined;
|
|
164
|
+
maxRetries?: number | undefined;
|
|
165
|
+
initialDelay?: number | undefined;
|
|
166
|
+
maxDelay?: number | undefined;
|
|
167
|
+
} | undefined) => {
|
|
168
|
+
on: (event: string, listener: EventListener) => import("events")<[never]>;
|
|
169
|
+
removeListener: (event: string, listener: EventListener) => import("events")<[never]>;
|
|
170
|
+
stop: () => void;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
export {};
|
|
174
|
+
//# sourceMappingURL=bindConfig.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindConfig.d.mts","sourceRoot":"","sources":["../../../impl/bindConfig.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEzE,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,sBAAsB,EAE5B,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAiB,MAAM,WAAW,CAAA;AAI5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAS7C,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,GAAG;IACtD,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC,GAAG,aAAa,CAAA;CACxE,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,gBAAgB,KAAG,aAcrD,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAE/B,MAAM,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAG/C,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAC3D,MAAM,EAAE,WAAW,UAYpB;AAED;;;;;;GAMG;AACH,iBAAS,MAAM,CAAC,MAAM,EAAE,WAAW;IAU/B;;;OAGG;;;;;;IAOH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCN"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type CouchConfigInput } from '../schema/config.mts';
|
|
2
|
+
import { ViewQueryResponse, type ViewQueryResponseValidated, CouchDoc, type ViewRowValidated } from '../schema/couch/couch.output.schema.ts';
|
|
3
|
+
import type { StandardSchemaV1 } from '../types/standard-schema.ts';
|
|
4
|
+
import { type OnInvalidDocAction } from './utils/parseRows.mts';
|
|
5
|
+
export type BulkGetResponse<DocSchema extends StandardSchemaV1 = StandardSchemaV1<CouchDoc>> = ViewQueryResponseValidated<DocSchema, StandardSchemaV1, StandardSchemaV1<{
|
|
6
|
+
rev: string;
|
|
7
|
+
}>>;
|
|
8
|
+
export type BulkGetOptions<DocSchema extends StandardSchemaV1> = {
|
|
9
|
+
includeDocs?: boolean;
|
|
10
|
+
validate?: {
|
|
11
|
+
docSchema: DocSchema;
|
|
12
|
+
onInvalidDoc?: OnInvalidDocAction;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Bulk get documents by IDs.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* By default, documents are included in the response. To exclude documents, set `includeDocs` to `false`.
|
|
20
|
+
* When `includeDocs` is `true`, you can provide a schema (StandardSchemaV1) to validate the documents.
|
|
21
|
+
* When a schema is provided, you can specify how to handle invalid documents using `onInvalidDoc` option.
|
|
22
|
+
* `onInvalidDoc` can be set to `'throw'` (default) to throw an error on invalid documents, or `'skip'` to omit them from the results.
|
|
23
|
+
*
|
|
24
|
+
* @template DocSchema - schema (StandardSchemaV1) used to validate each returned document, if provided.
|
|
25
|
+
*
|
|
26
|
+
* @param config - CouchDB configuration data that is validated before use.
|
|
27
|
+
* @param ids - Array of document IDs to retrieve.
|
|
28
|
+
* @param options - Options for bulk get operation, including whether to include documents and validation schema.
|
|
29
|
+
*
|
|
30
|
+
* @returns The bulk get response with rows optionally validated against the supplied document schema.
|
|
31
|
+
*
|
|
32
|
+
* @throws {RetryableError} When a retryable HTTP status code is encountered or no response is received.
|
|
33
|
+
* @throws {Error<StandardSchemaV1.FailureResult["issues"]>} When the configuration or validation schemas fail to parse.
|
|
34
|
+
* @throws {Error} When CouchDB returns a non-retryable error payload.
|
|
35
|
+
*/
|
|
36
|
+
export declare function bulkGet<DocSchema extends StandardSchemaV1 = typeof CouchDoc>(config: CouchConfigInput, ids: Array<string | undefined>, options?: BulkGetOptions<DocSchema>): Promise<BulkGetResponse<DocSchema>>;
|
|
37
|
+
/**
|
|
38
|
+
* Bound version of bulkGet with config pre-applied.
|
|
39
|
+
*/
|
|
40
|
+
export type BulkGetBound = {
|
|
41
|
+
(ids: string[], options?: {
|
|
42
|
+
includeDocs?: boolean;
|
|
43
|
+
}): Promise<ViewQueryResponse>;
|
|
44
|
+
<DocSchema extends StandardSchemaV1>(ids: string[], options?: BulkGetOptions<DocSchema>): Promise<ViewQueryResponseValidated<DocSchema>>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Bulk get documents by IDs and return a dictionary of found and not found documents.
|
|
48
|
+
*/
|
|
49
|
+
export type BulkGetDictionaryOptions<DocSchema extends StandardSchemaV1 = typeof CouchDoc> = Omit<BulkGetOptions<DocSchema>, 'includeDocs'>;
|
|
50
|
+
export type BulkGetDictionaryResult<DocSchema extends StandardSchemaV1 = StandardSchemaV1<CouchDoc>> = {
|
|
51
|
+
found: Record<string, StandardSchemaV1.InferOutput<DocSchema>>;
|
|
52
|
+
notFound: Record<string, ViewRowValidated<DocSchema, StandardSchemaV1, StandardSchemaV1<{
|
|
53
|
+
rev: string;
|
|
54
|
+
}>>>;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Bulk get documents by IDs and return a dictionary of found and not found documents.
|
|
58
|
+
*
|
|
59
|
+
* @template DocSchema - Schema used to validate each returned document, if provided. Note: if a document is found and it fails validation this will throw a Error<StandardSchemaV1.FailureResult["issues"]>.
|
|
60
|
+
*
|
|
61
|
+
* @param config - CouchDB configuration data that is validated before use.
|
|
62
|
+
* @param ids - Array of document IDs to retrieve.
|
|
63
|
+
* @param options - Options for bulk get operation, including validation schema.
|
|
64
|
+
*
|
|
65
|
+
* @returns An object containing found documents and not found rows.
|
|
66
|
+
*
|
|
67
|
+
* @throws {RetryableError} When a retryable HTTP status code is encountered or no response is received.
|
|
68
|
+
* @throws {Error<StandardSchemaV1.FailureResult["issues"]>} When the configuration or validation schemas fail to parse.
|
|
69
|
+
* @throws {Error} When CouchDB returns a non-retryable error payload.
|
|
70
|
+
*/
|
|
71
|
+
export declare function bulkGetDictionary<DocSchema extends StandardSchemaV1 = typeof CouchDoc>(config: CouchConfigInput, ids: Array<string | undefined>, options?: Omit<BulkGetDictionaryOptions<DocSchema>, 'includeDocs'>): Promise<BulkGetDictionaryResult<DocSchema>>;
|
|
72
|
+
export type BulkGetDictionaryBound = {
|
|
73
|
+
<DocSchema extends StandardSchemaV1 = typeof CouchDoc>(ids: string[], options: BulkGetDictionaryOptions<DocSchema>): Promise<BulkGetDictionaryResult<DocSchema>>;
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=bulkGet.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulkGet.d.mts","sourceRoot":"","sources":["../../../impl/bulkGet.mts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAIzE,OAAO,EACL,iBAAiB,EACjB,KAAK,0BAA0B,EAC/B,QAAQ,EACR,KAAK,gBAAgB,EACtB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,EAAa,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE1E,MAAM,MAAM,eAAe,CAAC,SAAS,SAAS,gBAAgB,GAAG,gBAAgB,CAAC,QAAQ,CAAC,IACzF,0BAA0B,CACxB,SAAS,EACT,gBAAgB,EAChB,gBAAgB,CAAC;IACf,GAAG,EAAE,MAAM,CAAA;CACZ,CAAC,CACH,CAAA;AAEH,MAAM,MAAM,cAAc,CAAC,SAAS,SAAS,gBAAgB,IAAI;IAC/D,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE;QACT,SAAS,EAAE,SAAS,CAAA;QACpB,YAAY,CAAC,EAAE,kBAAkB,CAAA;KAClC,CAAA;CACF,CAAA;AAmGD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,OAAO,CAAC,SAAS,SAAS,gBAAgB,GAAG,OAAO,QAAQ,EAChF,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,EAC9B,OAAO,GAAE,cAAc,CAAC,SAAS,CAAM,uCAMxC;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,CACE,GAAG,EAAE,MAAM,EAAE,EACb,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,OAAO,CAAA;KACtB,GACA,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAC7B,CAAC,SAAS,SAAS,gBAAgB,EACjC,GAAG,EAAE,MAAM,EAAE,EACb,OAAO,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,GAClC,OAAO,CAAC,0BAA0B,CAAC,SAAS,CAAC,CAAC,CAAA;CAClD,CAAA;AAED;;GAEG;AAEH,MAAM,MAAM,wBAAwB,CAAC,SAAS,SAAS,gBAAgB,GAAG,OAAO,QAAQ,IAAI,IAAI,CAC/F,cAAc,CAAC,SAAS,CAAC,EACzB,aAAa,CACd,CAAA;AAED,MAAM,MAAM,uBAAuB,CACjC,SAAS,SAAS,gBAAgB,GAAG,gBAAgB,CAAC,QAAQ,CAAC,IAC7D;IACF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAA;IAC9D,QAAQ,EAAE,MAAM,CACd,MAAM,EACN,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CACjF,CAAA;CACF,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,SAAS,gBAAgB,GAAG,OAAO,QAAQ,EAC1F,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,EAC9B,OAAO,CAAC,EAAE,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,GACjE,OAAO,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC,CAkC7C;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,CAAC,SAAS,SAAS,gBAAgB,GAAG,OAAO,QAAQ,EACnD,GAAG,EAAE,MAAM,EAAE,EACb,OAAO,EAAE,wBAAwB,CAAC,SAAS,CAAC,GAC3C,OAAO,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC,CAAA;CAC/C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulkGet.test.d.mts","sourceRoot":"","sources":["../../../impl/bulkGet.test.mts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type CouchConfigInput } from '../schema/config.mts';
|
|
2
|
+
/**
|
|
3
|
+
* Removes multiple documents from a CouchDB database using the _bulk_docs endpoint.
|
|
4
|
+
* It first retrieves the documents by their IDs, marks them as deleted, and then
|
|
5
|
+
* sends them back to the database for deletion.
|
|
6
|
+
*
|
|
7
|
+
* See https://docs.couchdb.org/en/stable/api/database/bulk-api.html#post--db-_bulk_docs
|
|
8
|
+
*
|
|
9
|
+
* @param configInput - The CouchDB configuration input.
|
|
10
|
+
* @param ids - An array of document IDs to be removed.
|
|
11
|
+
* @returns A promise that resolves to an array of results from the bulk delete operation.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const config: CouchConfigInput = {
|
|
16
|
+
* couch: 'http://localhost:5984/mydb',
|
|
17
|
+
* useConsoleLogger: true
|
|
18
|
+
* };
|
|
19
|
+
* const idsToRemove = ['doc1', 'doc2', 'doc3'];
|
|
20
|
+
* const results = await bulkRemove(config, idsToRemove);
|
|
21
|
+
* console.log(results);
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @throws Will throw an error if the provided configuration is invalid or if the bulk delete operation fails.
|
|
25
|
+
*/
|
|
26
|
+
export declare const bulkRemove: (configInput: CouchConfigInput, ids: string[]) => Promise<{
|
|
27
|
+
ok?: boolean | null | undefined;
|
|
28
|
+
id?: string | null | undefined;
|
|
29
|
+
rev?: string | null | undefined;
|
|
30
|
+
error?: string | null | undefined;
|
|
31
|
+
reason?: string | null | undefined;
|
|
32
|
+
}[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Removes multiple documents from a CouchDB database by their IDs using individual delete operations.
|
|
35
|
+
* It first retrieves the documents to get their revision IDs, then deletes each document one by one.
|
|
36
|
+
*
|
|
37
|
+
* See https://docs.couchdb.org/en/stable/api/document/common.html#delete--db-docid
|
|
38
|
+
*
|
|
39
|
+
* @param configInput - The CouchDB configuration input.
|
|
40
|
+
* @param ids - An array of document IDs to be removed.
|
|
41
|
+
* @returns A promise that resolves to an array of results from the individual delete operations.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const config: CouchConfigInput = {
|
|
46
|
+
* couch: 'http://localhost:5984/mydb',
|
|
47
|
+
* useConsoleLogger: true
|
|
48
|
+
* };
|
|
49
|
+
* const idsToRemove = ['doc1', 'doc2', 'doc3'];
|
|
50
|
+
* const results = await bulkRemoveMap(config, idsToRemove);
|
|
51
|
+
* console.log(results);
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @throws Will throw an error if the provided configuration is invalid or if any delete operation fails.
|
|
55
|
+
*/
|
|
56
|
+
export declare const bulkRemoveMap: (configInput: CouchConfigInput, ids: string[]) => Promise<{
|
|
57
|
+
statusCode: number;
|
|
58
|
+
ok?: boolean | undefined;
|
|
59
|
+
error?: string | undefined;
|
|
60
|
+
id?: string | undefined;
|
|
61
|
+
rev?: string | undefined;
|
|
62
|
+
}[]>;
|
|
63
|
+
//# sourceMappingURL=bulkRemove.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulkRemove.d.mts","sourceRoot":"","sources":["../../../impl/bulkRemove.mts"],"names":[],"mappings":"AAKA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEzE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,UAAU,GAAU,aAAa,gBAAgB,EAAE,KAAK,MAAM,EAAE;;;;;;IAmB5E,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,aAAa,GAAU,aAAa,gBAAgB,EAAE,KAAK,MAAM,EAAE;;;;;;IAsB/E,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulkRemove.test.d.mts","sourceRoot":"","sources":["../../../impl/bulkRemove.test.mts"],"names":[],"mappings":""}
|