hide-a-bed 5.2.1 → 5.2.3

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 CHANGED
@@ -60,15 +60,16 @@ Here is an example of compiler warnings:
60
60
 
61
61
  ##### Config Overrides
62
62
 
63
- You also can quickly change one (or more) config settings for a particular call with the db.config(options)
63
+ You also can quickly change one (or more) config settings for a particular call with the db.options(optionOverrides)
64
64
 
65
65
  eg
66
66
 
67
67
  ```
68
- const doc = await db.config({ throwOnGetNotFound: true }).get('doc-id')
68
+ const db = bindConfig({ couch: 'http://localhost:5984/db', throwOnGetNotFound: false })
69
+ const doc = await db.options({ throwOnGetNotFound: true }).get('doc-id')
69
70
  ```
70
71
 
71
- You can pass any of [Config Options](#advanced-config-options) to db.config to override the original bindings.
72
+ You can pass any of [Config Options](#advanced-config-options) to db.options to override the original config bindings.
72
73
 
73
74
 
74
75
  ### Document Operations
package/cjs/impl/bulk.cjs CHANGED
@@ -44,12 +44,6 @@ var import_transactionErrors = require("./transactionErrors.cjs");
44
44
  var import_logger = require("./logger.cjs");
45
45
  var import_crud2 = require("../schema/crud.cjs");
46
46
  var import_trackedEmitter = require("./trackedEmitter.cjs");
47
- const opts = {
48
- json: true,
49
- headers: {
50
- "Content-Type": "application/json"
51
- }
52
- };
53
47
  const bulkSave = import_bulk.BulkSave.implement(async (config, docs) => {
54
48
  const logger = (0, import_logger.createLogger)(config);
55
49
  if (!docs) {
@@ -63,6 +57,12 @@ const bulkSave = import_bulk.BulkSave.implement(async (config, docs) => {
63
57
  logger.info(`Starting bulk save of ${docs.length} documents`);
64
58
  const url = `${config.couch}/_bulk_docs`;
65
59
  const body = { docs };
60
+ const opts = {
61
+ json: true,
62
+ headers: {
63
+ "Content-Type": "application/json"
64
+ }
65
+ };
66
66
  let resp;
67
67
  try {
68
68
  resp = await (0, import_needle.default)("post", url, body, opts);
@@ -91,6 +91,12 @@ const bulkGet = import_bulk.BulkGet.implement(async (config, ids) => {
91
91
  logger.info(`Starting bulk get for ${keys.length} documents`);
92
92
  const url = `${config.couch}/_all_docs?include_docs=true`;
93
93
  const payload = { keys };
94
+ const opts = {
95
+ json: true,
96
+ headers: {
97
+ "Content-Type": "application/json"
98
+ }
99
+ };
94
100
  let resp;
95
101
  try {
96
102
  resp = await (0, import_needle.default)("post", url, payload, opts);
package/cjs/impl/crud.cjs CHANGED
@@ -37,17 +37,17 @@ var import_needle = __toESM(require("needle"), 1);
37
37
  var import_crud = require("../schema/crud.cjs");
38
38
  var import_errors = require("./errors.cjs");
39
39
  var import_logger = require("./logger.cjs");
40
- const opts = {
41
- json: true,
42
- headers: {
43
- "Content-Type": "application/json"
44
- }
45
- };
46
40
  const _getWithOptions = import_crud.CouchGetWithOptions.implement(async (config, id, getOpts) => {
47
41
  const logger = (0, import_logger.createLogger)(config);
48
42
  const rev = getOpts?.rev;
49
43
  const path = rev ? `${id}?rev=${rev}` : id;
50
44
  const url = `${config.couch}/${path}`;
45
+ const opts = {
46
+ json: true,
47
+ headers: {
48
+ "Content-Type": "application/json"
49
+ }
50
+ };
51
51
  logger.info(`Getting document with id: ${id}, rev ${rev || "latest"}`);
52
52
  try {
53
53
  const resp = await (0, import_needle.default)("get", url, opts);
@@ -92,6 +92,12 @@ const put = import_crud.CouchPut.implement(async (config, doc) => {
92
92
  const logger = (0, import_logger.createLogger)(config);
93
93
  const url = `${config.couch}/${doc._id}`;
94
94
  const body = doc;
95
+ const opts = {
96
+ json: true,
97
+ headers: {
98
+ "Content-Type": "application/json"
99
+ }
100
+ };
95
101
  logger.info(`Putting document with id: ${doc._id}`);
96
102
  let resp;
97
103
  try {
@@ -129,6 +129,30 @@ class QueryBuilder {
129
129
  this.#options.limit = limit;
130
130
  return this;
131
131
  }
132
+ /**
133
+ * @param {boolean} descending
134
+ * @returns {QueryBuilder}
135
+ */
136
+ descending(descending = true) {
137
+ this.#options.descending = descending;
138
+ return this;
139
+ }
140
+ /**
141
+ * @param {number} skip
142
+ * @returns {QueryBuilder}
143
+ */
144
+ skip(skip) {
145
+ this.#options.skip = skip;
146
+ return this;
147
+ }
148
+ /**
149
+ * @param {any[]} keys
150
+ * @returns {QueryBuilder}
151
+ */
152
+ keys(keys) {
153
+ this.#options.keys = keys;
154
+ return this;
155
+ }
132
156
  /**
133
157
  * @returns {QueryOptions}
134
158
  */
package/cjs/impl/util.cjs CHANGED
@@ -35,15 +35,15 @@ var import_needle = __toESM(require("needle"), 1);
35
35
  var import_errors = require("./errors.cjs");
36
36
  var import_logger = require("./logger.cjs");
37
37
  var import_util = require("../schema/util.cjs");
38
- const opts = {
39
- json: true,
40
- headers: {
41
- "Content-Type": "application/json"
42
- }
43
- };
44
38
  const getDBInfo = import_util.GetDBInfo.implement(async (config) => {
45
39
  const logger = (0, import_logger.createLogger)(config);
46
40
  const url = `${config.couch}`;
41
+ const opts = {
42
+ json: true,
43
+ headers: {
44
+ "Content-Type": "application/json"
45
+ }
46
+ };
47
47
  let resp;
48
48
  try {
49
49
  resp = await (0, import_needle.default)("get", url, opts);
@@ -1 +1 @@
1
- {"version":3,"file":"bulk.d.mts","sourceRoot":"","sources":["bulk.mjs"],"names":[],"mappings":"AAkBA,4DAA4D;AAC5D,uBADY,OAAO,oBAAoB,EAAE,cAAc,CAsCrD;AAEF,2DAA2D;AAC3D,sBADY,OAAO,oBAAoB,EAAE,aAAa,CA8BpD;AAIF,8DAA8D;AAC9D,yBADY,OAAO,oBAAoB,EAAE,gBAAgB,CAkBvD;AAEF,qEAAqE;AACrE,gCADY,OAAO,oBAAoB,EAAE,uBAAuB,CAwB9D;AAEF,2FAA2F;AAC3F,kCADY,OAAO,oBAAoB,EAAE,yBAAyB,CAiJhE"}
1
+ {"version":3,"file":"bulk.d.mts","sourceRoot":"","sources":["bulk.mjs"],"names":[],"mappings":"AAWA,4DAA4D;AAC5D,uBADY,OAAO,oBAAoB,EAAE,cAAc,CA4CrD;AAEF,2DAA2D;AAC3D,sBADY,OAAO,oBAAoB,EAAE,aAAa,CAoCpD;AAIF,8DAA8D;AAC9D,yBADY,OAAO,oBAAoB,EAAE,gBAAgB,CAkBvD;AAEF,qEAAqE;AACrE,gCADY,OAAO,oBAAoB,EAAE,uBAAuB,CAwB9D;AAEF,2FAA2F;AAC3F,kCADY,OAAO,oBAAoB,EAAE,yBAAyB,CAiJhE"}
package/impl/bulk.mjs CHANGED
@@ -9,13 +9,6 @@ import { createLogger } from './logger.mjs'
9
9
  import { CouchDoc } from '../schema/crud.mjs'
10
10
  import { setupEmitter } from './trackedEmitter.mjs'
11
11
 
12
- const opts = {
13
- json: true,
14
- headers: {
15
- 'Content-Type': 'application/json'
16
- }
17
- }
18
-
19
12
  /** @type { import('../schema/bulk.mjs').BulkSaveSchema } */
20
13
  export const bulkSave = BulkSave.implement(async (config, docs) => {
21
14
  /** @type {import('./logger.mjs').Logger } */
@@ -33,6 +26,12 @@ export const bulkSave = BulkSave.implement(async (config, docs) => {
33
26
  logger.info(`Starting bulk save of ${docs.length} documents`)
34
27
  const url = `${config.couch}/_bulk_docs`
35
28
  const body = { docs }
29
+ const opts = {
30
+ json: true,
31
+ headers: {
32
+ 'Content-Type': 'application/json'
33
+ }
34
+ }
36
35
  let resp
37
36
  try {
38
37
  resp = await needle('post', url, body, opts)
@@ -64,6 +63,12 @@ export const bulkGet = BulkGet.implement(async (config, ids) => {
64
63
  logger.info(`Starting bulk get for ${keys.length} documents`)
65
64
  const url = `${config.couch}/_all_docs?include_docs=true`
66
65
  const payload = { keys }
66
+ const opts = {
67
+ json: true,
68
+ headers: {
69
+ 'Content-Type': 'application/json'
70
+ }
71
+ }
67
72
  let resp
68
73
  try {
69
74
  resp = await needle('post', url, payload, opts)
@@ -1 +1 @@
1
- {"version":3,"file":"crud.d.mts","sourceRoot":"","sources":["crud.mjs"],"names":[],"mappings":"AAqDA,4DAA4D;AAC5D,kBADY,OAAO,oBAAoB,EAAE,cAAc,CAIrD;AAEF,iEAAiE;AACjE,uBADY,OAAO,oBAAoB,EAAE,mBAAmB,CAI1D;AAEF,4DAA4D;AAC5D,kBADY,OAAO,oBAAoB,EAAE,cAAc,CAqCrD"}
1
+ {"version":3,"file":"crud.d.mts","sourceRoot":"","sources":["crud.mjs"],"names":[],"mappings":"AAoDA,4DAA4D;AAC5D,kBADY,OAAO,oBAAoB,EAAE,cAAc,CAIrD;AAEF,iEAAiE;AACjE,uBADY,OAAO,oBAAoB,EAAE,mBAAmB,CAI1D;AAEF,4DAA4D;AAC5D,kBADY,OAAO,oBAAoB,EAAE,cAAc,CA2CrD"}
package/impl/crud.mjs CHANGED
@@ -4,19 +4,18 @@ import { CouchGet, CouchPut, CouchGetWithOptions, CouchGetAtRev } from '../schem
4
4
  import { RetryableError, NotFoundError } from './errors.mjs'
5
5
  import { createLogger } from './logger.mjs'
6
6
 
7
- const opts = {
8
- json: true,
9
- headers: {
10
- 'Content-Type': 'application/json'
11
- }
12
- }
13
-
14
7
  /** @type { import('../schema/crud.mjs').CouchGetWithOptionsSchema } */
15
8
  const _getWithOptions = CouchGetWithOptions.implement(async (config, id, getOpts) => {
16
9
  const logger = createLogger(config)
17
10
  const rev = getOpts?.rev
18
11
  const path = rev ? `${id}?rev=${rev}` : id
19
12
  const url = `${config.couch}/${path}`
13
+ const opts = {
14
+ json: true,
15
+ headers: {
16
+ 'Content-Type': 'application/json'
17
+ }
18
+ }
20
19
  logger.info(`Getting document with id: ${id}, rev ${rev || 'latest'}`)
21
20
 
22
21
  try {
@@ -68,6 +67,12 @@ export const put = CouchPut.implement(async (config, doc) => {
68
67
  const logger = createLogger(config)
69
68
  const url = `${config.couch}/${doc._id}`
70
69
  const body = doc
70
+ const opts = {
71
+ json: true,
72
+ headers: {
73
+ 'Content-Type': 'application/json'
74
+ }
75
+ }
71
76
 
72
77
  logger.info(`Putting document with id: ${doc._id}`)
73
78
  let resp
package/impl/query.mjs CHANGED
@@ -40,7 +40,7 @@ export const query = SimpleViewQuery.implement(async (config, view, options = {}
40
40
 
41
41
  const _options = JSON.parse(JSON.stringify(options))
42
42
  delete _options.keys
43
- qs = queryString(_options, ['key', 'startkey', 'endkey', 'reduce', 'group', 'group_level', 'stale', 'limit'])
43
+ qs = queryString(_options, ['key', 'startkey', 'endkey', 'reduce', 'group', 'group_level', 'stale', 'limit']) // dont need descening or skip, those will work
44
44
 
45
45
  const keysAsString = `keys=${JSON.stringify(options.keys)}`
46
46
 
@@ -6,9 +6,12 @@
6
6
  * @property {boolean} [reduce] - Whether to use reduce function
7
7
  * @property {boolean} [group] - Whether to group results
8
8
  * @property {number} [group_level] - Level at which to group
9
- * @property {boolean} [include_docs] - Whether to include full couch docs
9
+ * @property {boolean} [include_docs] - Whether to include full couch docs
10
10
  * @property {string} [stale] - Stale parameter value
11
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
12
15
  */
13
16
  export class QueryBuilder {
14
17
  /**
@@ -76,6 +79,21 @@ export class QueryBuilder {
76
79
  * @returns {QueryBuilder}
77
80
  */
78
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;
79
97
  /**
80
98
  * @returns {QueryOptions}
81
99
  */
@@ -120,5 +138,17 @@ export type QueryOptions = {
120
138
  * - Max number of results
121
139
  */
122
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;
123
153
  };
124
154
  //# sourceMappingURL=queryBuilder.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queryBuilder.d.mts","sourceRoot":"","sources":["queryBuilder.mjs"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;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;;OAEG;IACH,SAFa,YAAY,CAIxB;;CACF;AAEM,4CAA4C;;;;;UA5IrC,GAAG;;;;eACH,GAAG;;;;aACH,GAAG"}
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"}
@@ -8,9 +8,12 @@
8
8
  * @property {boolean} [reduce] - Whether to use reduce function
9
9
  * @property {boolean} [group] - Whether to group results
10
10
  * @property {number} [group_level] - Level at which to group
11
- * @property {boolean} [include_docs] - Whether to include full couch docs
11
+ * @property {boolean} [include_docs] - Whether to include full couch docs
12
12
  * @property {string} [stale] - Stale parameter value
13
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
14
17
  */
15
18
 
16
19
  export class QueryBuilder {
@@ -134,6 +137,33 @@ export class QueryBuilder {
134
137
  return this
135
138
  }
136
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
+
137
167
  /**
138
168
  * @returns {QueryOptions}
139
169
  */
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.mts","sourceRoot":"","sources":["util.mjs"],"names":[],"mappings":"AAaA,4DAA4D;AAC5D,wBADY,OAAO,oBAAoB,EAAE,eAAe,CAsBtD"}
1
+ {"version":3,"file":"util.d.mts","sourceRoot":"","sources":["util.mjs"],"names":[],"mappings":"AAMA,4DAA4D;AAC5D,wBADY,OAAO,oBAAoB,EAAE,eAAe,CA4BtD"}
package/impl/util.mjs CHANGED
@@ -4,17 +4,16 @@ import { RetryableError, NotFoundError } from './errors.mjs'
4
4
  import { createLogger } from './logger.mjs'
5
5
  import { GetDBInfo } from '../schema/util.mjs'
6
6
 
7
- const opts = {
8
- json: true,
9
- headers: {
10
- 'Content-Type': 'application/json'
11
- }
12
- }
13
-
14
7
  /** @type { import('../schema/util.mjs').GetDBInfoSchema} */
15
8
  export const getDBInfo = GetDBInfo.implement(async (config) => {
16
9
  const logger = createLogger(config)
17
10
  const url = `${config.couch}`
11
+ const opts = {
12
+ json: true,
13
+ headers: {
14
+ 'Content-Type': 'application/json'
15
+ }
16
+ }
18
17
  let resp
19
18
  try {
20
19
  resp = await needle('get', url, opts)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hide-a-bed",
3
- "version": "5.2.1",
3
+ "version": "5.2.3",
4
4
  "description": "An abstraction over couchdb calls that includes easy mock/stubs with pouchdb",
5
5
  "module": "index.mjs",
6
6
  "main": "cjs/index.cjs",
@@ -58,4 +58,4 @@
58
58
  "node": "20.17.0",
59
59
  "npm": "10.8.2"
60
60
  }
61
- }
61
+ }
package/schema/util.mjs CHANGED
@@ -26,7 +26,7 @@ export const DBInfo = z.object({
26
26
  }).passthrough()
27
27
 
28
28
  export const GetDBInfo = z.function().args(
29
- CouchConfig,
29
+ CouchConfig
30
30
  ).returns(z.promise(DBInfo))
31
31
  /** @typedef { z.infer<typeof GetDBInfo> } GetDBInfoSchema */
32
32