@nxtedition/lib 23.8.1 → 23.9.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/couch.js CHANGED
@@ -102,7 +102,7 @@ export function makeCouch(opts) {
102
102
 
103
103
  /**
104
104
  * @param {Object} [options={}]
105
- * @param {AbortSignal} [options.signal=null]
105
+ * @param {AbortSignal} [options.signal]
106
106
  * @param {boolean} [options.descending=false]
107
107
  * @param {boolean} [options.include_docs=false]
108
108
  * @param {number} [options.seq_interval=null]
@@ -115,7 +115,7 @@ export function makeCouch(opts) {
115
115
  * @param {import('pino').Logger} [options.logger=null]
116
116
  * @return {AsyncGenerator<Array<{ id: string, seq?: string, doc?: Object, deleted?: boolean, changes: Array<{ rev: string }>}> & { lastSeq: string | null | 0 }}
117
117
  */
118
- async function* changes({ client = defaultClient, signal = null, logger, ...options } = {}) {
118
+ async function* changes({ client = defaultClient, signal, logger, ...options } = {}) {
119
119
  const params = {}
120
120
 
121
121
  let body
@@ -583,7 +583,7 @@ export function makeCouch(opts) {
583
583
  pathname,
584
584
  params,
585
585
  body,
586
- { client = defaultClient, signal = null, idempotent = true, headers = null } = {},
586
+ { client = defaultClient, signal, idempotent = true, headers = null } = {},
587
587
  ) {
588
588
  const req = {
589
589
  pathname,
@@ -629,7 +629,7 @@ export function makeCouch(opts) {
629
629
  pathname,
630
630
  params,
631
631
  body,
632
- { client = getClient('_all_docs'), signal = null, idempotent = true, headers = null } = {},
632
+ { client = getClient('_all_docs'), signal, idempotent = true, headers = null } = {},
633
633
  ) {
634
634
  const req = {
635
635
  pathname,
@@ -654,7 +654,7 @@ export function makeCouch(opts) {
654
654
  pathname,
655
655
  params,
656
656
  body,
657
- { client = defaultClient, signal = null, idempotent = true, headers = null } = {},
657
+ { client = defaultClient, signal, idempotent = true, headers = null } = {},
658
658
  ) {
659
659
  const req = {
660
660
  pathname,
@@ -678,7 +678,7 @@ export function makeCouch(opts) {
678
678
  async function info(
679
679
  params,
680
680
  body,
681
- { client = defaultClient, signal = null, idempotent = true, headers = null } = {},
681
+ { client = defaultClient, signal, idempotent = true, headers = null } = {},
682
682
  ) {
683
683
  const req = {
684
684
  pathname: null,
@@ -699,7 +699,7 @@ export function makeCouch(opts) {
699
699
  return res.data
700
700
  }
701
701
 
702
- async function up(params, body, { client = defaultClient, signal = null } = {}) {
702
+ async function up(params, body, { client = defaultClient, signal } = {}) {
703
703
  const res = await undiciRequest(new URL('/_up', dbOrigin), {
704
704
  signal,
705
705
  dispatcher: client,
@@ -707,7 +707,7 @@ export function makeCouch(opts) {
707
707
  return await res.body.json()
708
708
  }
709
709
 
710
- async function upsert(pathname, diffFun, { client = defaultClient, signal = null } = {}) {
710
+ async function upsert(pathname, diffFun, { client = defaultClient, signal } = {}) {
711
711
  while (true) {
712
712
  let doc
713
713
  try {
package/http.js CHANGED
@@ -745,7 +745,17 @@ export async function request(ctx, next) {
745
745
  }
746
746
  }
747
747
 
748
- export function createServer(options, ctx, middleware) {
748
+ export function createServer(...args) {
749
+ let options
750
+ let ctx
751
+ let middleware
752
+
753
+ if (typeof args[0] === 'function') {
754
+ ;[ctx, middleware] = args
755
+ } else {
756
+ ;[options, ctx, middleware] = args
757
+ }
758
+
749
759
  if (middleware) {
750
760
  middleware = [middleware].flat(16).filter(Boolean)
751
761
  middleware = middleware.includes(requestMiddleware)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.8.1",
3
+ "version": "23.9.0",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -45,9 +45,18 @@ class FetchEntry {
45
45
  this.status = null
46
46
  this.error = null
47
47
 
48
+ let { headers, body } = options
49
+
50
+ if (fp.isPlainObject(body) || fp.isArray(body)) {
51
+ headers = { 'content-type': 'application/json', ...headers }
52
+ body = JSON.stringify(body)
53
+ }
54
+
48
55
  try {
49
56
  request(resource, {
50
57
  ...options,
58
+ headers,
59
+ body,
51
60
  signal: this.ac.signal,
52
61
  dispatcher: fetchClient,
53
62
  })