hide-a-bed 7.1.3 → 7.2.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/README.md +64 -0
- package/dist/cjs/index.cjs +414 -339
- package/dist/esm/index.mjs +409 -340
- package/impl/bindConfig.mts +3 -0
- package/impl/find.mts +59 -0
- package/impl/utils/errors.mts +1 -0
- package/impl/utils/fetch.mts +1 -0
- package/index.mts +19 -0
- package/package.json +1 -1
- package/schema/couch/mango.schema.ts +61 -0
- package/types/output/impl/bindConfig.d.mts +2 -0
- package/types/output/impl/bindConfig.d.mts.map +1 -1
- package/types/output/impl/find.d.mts +8 -0
- package/types/output/impl/find.d.mts.map +1 -0
- package/types/output/impl/find.test.d.mts +2 -0
- package/types/output/impl/find.test.d.mts.map +1 -0
- package/types/output/impl/utils/errors.d.mts +1 -1
- package/types/output/impl/utils/errors.d.mts.map +1 -1
- package/types/output/impl/utils/fetch.d.mts +1 -1
- package/types/output/impl/utils/fetch.d.mts.map +1 -1
- package/types/output/index.d.mts +5 -1
- package/types/output/index.d.mts.map +1 -1
- package/types/output/schema/couch/mango.schema.d.ts +58 -0
- package/types/output/schema/couch/mango.schema.d.ts.map +1 -0
- package/types/output/schema/couch/mango.schema.test.d.mts +2 -0
- package/types/output/schema/couch/mango.schema.test.d.mts.map +1 -0
package/README.md
CHANGED
|
@@ -859,3 +859,67 @@ Each operation logs appropriate information at these levels:
|
|
|
859
859
|
- warn: Retryable errors, conflicts.
|
|
860
860
|
- info: Operation start/completion.
|
|
861
861
|
- debug: Detailed operation information.
|
|
862
|
+
|
|
863
|
+
### find
|
|
864
|
+
|
|
865
|
+
`find(config, options)` and `bindConfig(config).find(options)` POST a native CouchDB
|
|
866
|
+
Mango query to `_find`. `options` contains `selector`, with optional `use_index`,
|
|
867
|
+
`limit`, `skip`, `bookmark`, `fields`, `sort`, `conflicts`, read quorum `r`,
|
|
868
|
+
`update`, `stable`, deprecated `stale`, `execution_stats`, and `allow_fallback`.
|
|
869
|
+
Returns `{docs, bookmark?, warning?, execution_stats?}` without discarding metadata.
|
|
870
|
+
Use config auth/request controls and bound retries as with `query`. Check your
|
|
871
|
+
CouchDB version before using `allow_fallback`. Mango was introduced in
|
|
872
|
+
[CouchDB 2.0](https://docs.couchdb.org/en/stable/whatsnew/2.0.html); it does not
|
|
873
|
+
require MongoDB. Individual options and statistics depend on the server version.
|
|
874
|
+
|
|
875
|
+
Index creation and planner verification belong to deployment. Before using
|
|
876
|
+
`use_index`, create the named index in the target database; `find` does not create
|
|
877
|
+
indexes. CouchDB's documentation covers the setup:
|
|
878
|
+
|
|
879
|
+
- [Mango index design](https://docs.couchdb.org/en/stable/ddocs/mango.html#indexes)
|
|
880
|
+
explains index definitions, JSON indexes, and partial indexes.
|
|
881
|
+
- [`POST /{db}/_index`](https://docs.couchdb.org/en/stable/api/database/find.html#api-db-find-index-post)
|
|
882
|
+
documents index creation, with request examples and the `fields`, `ddoc`, and
|
|
883
|
+
`name` settings used to define and identify an index.
|
|
884
|
+
- [`POST /{db}/_explain`](https://docs.couchdb.org/en/stable/api/database/find.html#api-db-find-explain)
|
|
885
|
+
shows which index a query will use. Check the selector and sort against the
|
|
886
|
+
intended index before deploying; queries without a suitable index may fall back
|
|
887
|
+
to a full database scan.
|
|
888
|
+
|
|
889
|
+
```javascript
|
|
890
|
+
const result = await db.find({
|
|
891
|
+
selector: { type: 'job' },
|
|
892
|
+
use_index: ['_design/jobs-geo-mango', 'published_lat_lng_expiry'],
|
|
893
|
+
limit: 100
|
|
894
|
+
})
|
|
895
|
+
```
|
|
896
|
+
|
|
897
|
+
`MangoQuery`, `MangoSelector`, `MangoSort`, `MangoExecutionStats`, and
|
|
898
|
+
`MangoResponse<Doc>` are inferred from/reuse the exported Zod schemas. The older
|
|
899
|
+
`FindOptions` / `FindResponse<Doc>` names remain aliases. Both standalone and
|
|
900
|
+
bound methods support `find<Job>(...)`; omitting the generic keeps
|
|
901
|
+
`Record<string, unknown>` documents. A generic is a compile-time assertion, not
|
|
902
|
+
runtime validation of your domain fields. Projections can omit `_id` and `_rev`.
|
|
903
|
+
|
|
904
|
+
`find` validates response envelopes and the five named execution-stat fields.
|
|
905
|
+
Use `createMangoResponseSchema(jobSchema).parse(result)` for domain/document
|
|
906
|
+
validation. Envelope and execution-stat schemas preserve additional response
|
|
907
|
+
metadata. `MangoQuerySchema` rejects unknown request options.
|
|
908
|
+
|
|
909
|
+
```typescript
|
|
910
|
+
import { createMangoResponseSchema, type MangoQuery } from 'hide-a-bed'
|
|
911
|
+
import { z } from 'zod'
|
|
912
|
+
|
|
913
|
+
const query: MangoQuery = { selector: { type: 'job' }, fields: ['title'] }
|
|
914
|
+
const result = await db.find<{ title: string }>(query)
|
|
915
|
+
const validated = createMangoResponseSchema(z.object({ title: z.string() })).parse(result)
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
View query serialization preserves the existing behavior from before Mango
|
|
919
|
+
support, including quoting `startkey_docid` and `endkey_docid`. Mango options are
|
|
920
|
+
validated separately by `MangoQuerySchema` and sent as a JSON POST body to `_find`;
|
|
921
|
+
they do not change the supported options or serialization of existing view queries.
|
|
922
|
+
|
|
923
|
+
Mango options/statistics are documented in the [CouchDB Mango API reference](https://docs.couchdb.org/en/stable/api/database/find.html)
|
|
924
|
+
and [Apache Nano's Mango definitions](https://github.com/apache/couchdb-nano/blob/main/lib/nano.d.ts).
|
|
925
|
+
No Nano dependency is required.
|