hide-a-bed 1.1.0 → 1.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/impl/crud.mjs CHANGED
@@ -13,6 +13,7 @@ export const get = CouchGet.implement(async (config, id) => {
13
13
  const url = `${config.couch}/${id}`
14
14
  const resp = await needle('get', url, opts)
15
15
  const result = resp?.body || {}
16
+ result.statusCode = resp.statusCode
16
17
  if (resp.statusCode !== 200) {
17
18
  throw new Error('not found')
18
19
  }
package/index.mjs CHANGED
@@ -2,6 +2,22 @@ import { bulkGet, bulkSave, bulkRemove } from './impl/bulk.mjs'
2
2
  import { get, put } from './impl/crud.mjs'
3
3
  import { query } from './impl/query.mjs'
4
4
  import { queryStream } from './impl/stream.mjs'
5
+ import { BulkSave, BulkGet } from './schema/bulk.mjs'
6
+ import { CouchConfig } from './schema/config.mjs'
7
+ import { SimpleViewQuery, SimpleViewQueryResponse } from './schema/query.mjs'
8
+ import { CouchDoc, CouchDocResponse, CouchPut, CouchGet } from './schema/crud.mjs'
5
9
 
6
- export { get, put, bulkGet, bulkSave, bulkRemove, query, queryStream }
10
+ const schema = {
11
+ CouchConfig,
12
+ SimpleViewQuery,
13
+ SimpleViewQueryResponse,
14
+ BulkSave,
15
+ BulkGet,
16
+ CouchGet,
17
+ CouchPut,
18
+ CouchDoc,
19
+ CouchDocResponse
20
+ }
21
+
22
+ export { get, put, bulkGet, bulkSave, bulkRemove, query, queryStream, schema }
7
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hide-a-bed",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "An abstraction over couchdb calls that includes easy mock/stubs with pouchdb",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
package/schema/bulk.mjs CHANGED
@@ -1,28 +1,24 @@
1
1
  import { z } from 'zod'
2
+ import { CouchConfig } from './config.mjs'
2
3
 
3
- // TODO - type this object
4
- export const SaveResponseSchema = z.array(z.object({
4
+ export const BulkSaveResponseSchema = z.array(z.object({
5
5
  ok: z.boolean().nullish(),
6
6
  id: z.string(),
7
7
  rev: z.string().nullish(),
8
8
  error: z.string().nullish().describe('if an error occured, one word reason, eg conflict'),
9
9
  reason: z.string().nullish().describe('a full error message')
10
10
  }))
11
- /** @typedef { z.infer<typeof SaveResponseSchema> } Response */
11
+ /** @typedef { z.infer<typeof BulkSaveResponseSchema> } Response */
12
12
 
13
13
  export const BulkSave = z.function().args(
14
- z.object({
15
- couch: z.string().describe('the url to the couch database')
16
- }).passthrough().describe('config object'),
14
+ CouchConfig,
17
15
  z.array(z.object({
18
16
  _id: z.string()
19
17
  }).passthrough())
20
- ).returns(z.promise(SaveResponseSchema))
18
+ ).returns(z.promise(BulkSaveResponseSchema))
21
19
  /** @typedef { z.infer<typeof SaveSchema> } Save */
22
20
 
23
21
  export const BulkGet = z.function().args(
24
- z.object({
25
- couch: z.string().describe('the url to the couch database')
26
- }).passthrough().describe('config object'),
22
+ CouchConfig,
27
23
  z.array(z.string().describe('the ids to get'))
28
24
  )
@@ -0,0 +1,4 @@
1
+ import { z } from 'zod'
2
+ export const CouchConfig = z.object({
3
+ couch: z.string().describe('the url of the couch db')
4
+ }).passthrough().describe('The std config object')
package/schema/crud.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod'
2
+ import { CouchConfig } from './config.mjs'
2
3
 
3
4
  export const CouchDoc = z.object({
4
5
  _id: z.string().describe('the couch doc id'),
@@ -13,10 +14,6 @@ export const CouchDocResponse = z.object({
13
14
  rev: z.string().optional().describe('the new rev of the doc')
14
15
  })
15
16
 
16
- export const CouchConfig = z.object({
17
- couch: z.string().describe('the url of the couch db')
18
- }).passthrough().describe('The std config object')
19
-
20
17
  export const CouchPut = z.function().args(
21
18
  CouchConfig,
22
19
  CouchDoc
package/schema/query.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod'
2
+ import { CouchConfig } from './config.mjs'
2
3
 
3
4
  export const SimpleViewQueryResponse = z.object({
4
5
  error: z.string().optional().describe('if something is wrong'),
@@ -10,12 +11,9 @@ export const SimpleViewQueryResponse = z.object({
10
11
  }))
11
12
  }).passthrough()
12
13
 
13
- export const SimpleViewQueryConfig = z.object({
14
- couch: z.string().describe('the url of the couch db')
15
- }).passthrough().describe('The std config object')
16
14
 
17
15
  export const SimpleViewQuery = z.function().args(
18
- SimpleViewQueryConfig,
16
+ CouchConfig,
19
17
  z.string().describe('the view name'),
20
18
  z.object({
21
19
  startkey: z.any().optional(),