@budibase/backend-core 2.6.16-alpha.4 → 2.6.16-alpha.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/backend-core",
3
- "version": "2.6.16-alpha.4",
3
+ "version": "2.6.16-alpha.5",
4
4
  "description": "Budibase backend core libraries used in server and worker",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@budibase/nano": "10.1.2",
24
24
  "@budibase/pouchdb-replication-stream": "1.2.10",
25
- "@budibase/types": "2.6.16-alpha.4",
25
+ "@budibase/types": "2.6.16-alpha.5",
26
26
  "@shopify/jest-koa-mocks": "5.0.1",
27
27
  "@techpass/passport-openidconnect": "0.3.2",
28
28
  "aws-cloudfront-sign": "2.2.0",
@@ -88,5 +88,5 @@
88
88
  "tsconfig-paths": "4.0.0",
89
89
  "typescript": "4.7.3"
90
90
  },
91
- "gitHead": "7ef56bb0effd46a525ca978773976e71b9a90465"
91
+ "gitHead": "bbb516f26ae966668b5fa65418d81fbccf3dce37"
92
92
  }
@@ -12,7 +12,7 @@ import {
12
12
  isDocument,
13
13
  } from "@budibase/types"
14
14
  import { getCouchInfo } from "./connections"
15
- import { directCouchCall } from "./utils"
15
+ import { directCouchUrlCall } from "./utils"
16
16
  import { getPouchDB } from "./pouchDB"
17
17
  import { WriteStream, ReadStream } from "fs"
18
18
  import { newid } from "../../docIds/newid"
@@ -46,6 +46,8 @@ export class DatabaseImpl implements Database {
46
46
  private readonly instanceNano?: Nano.ServerScope
47
47
  private readonly pouchOpts: DatabaseOpts
48
48
 
49
+ private readonly couchInfo = getCouchInfo()
50
+
49
51
  constructor(dbName?: string, opts?: DatabaseOpts, connection?: string) {
50
52
  if (dbName == null) {
51
53
  throw new Error("Database name cannot be undefined.")
@@ -53,8 +55,8 @@ export class DatabaseImpl implements Database {
53
55
  this.name = dbName
54
56
  this.pouchOpts = opts || {}
55
57
  if (connection) {
56
- const couchInfo = getCouchInfo(connection)
57
- this.instanceNano = buildNano(couchInfo)
58
+ this.couchInfo = getCouchInfo(connection)
59
+ this.instanceNano = buildNano(this.couchInfo)
58
60
  }
59
61
  if (!DatabaseImpl.nano) {
60
62
  DatabaseImpl.init()
@@ -67,7 +69,11 @@ export class DatabaseImpl implements Database {
67
69
  }
68
70
 
69
71
  async exists() {
70
- let response = await directCouchCall(`/${this.name}`, "HEAD")
72
+ const response = await directCouchUrlCall({
73
+ url: `${this.couchInfo.url}/${this.name}`,
74
+ method: "HEAD",
75
+ cookie: this.couchInfo.cookie,
76
+ })
71
77
  return response.status === 200
72
78
  }
73
79
 
@@ -4,21 +4,21 @@ export const getCouchInfo = (connection?: string) => {
4
4
  const urlInfo = getUrlInfo(connection)
5
5
  let username
6
6
  let password
7
- if (env.COUCH_DB_USERNAME) {
8
- // set from env
9
- username = env.COUCH_DB_USERNAME
10
- } else if (urlInfo.auth.username) {
7
+ if (urlInfo.auth?.username) {
11
8
  // set from url
12
9
  username = urlInfo.auth.username
10
+ } else if (env.COUCH_DB_USERNAME) {
11
+ // set from env
12
+ username = env.COUCH_DB_USERNAME
13
13
  } else if (!env.isTest()) {
14
14
  throw new Error("CouchDB username not set")
15
15
  }
16
- if (env.COUCH_DB_PASSWORD) {
17
- // set from env
18
- password = env.COUCH_DB_PASSWORD
19
- } else if (urlInfo.auth.password) {
16
+ if (urlInfo.auth?.password) {
20
17
  // set from url
21
18
  password = urlInfo.auth.password
19
+ } else if (env.COUCH_DB_PASSWORD) {
20
+ // set from env
21
+ password = env.COUCH_DB_PASSWORD
22
22
  } else if (!env.isTest()) {
23
23
  throw new Error("CouchDB password not set")
24
24
  }
@@ -9,6 +9,20 @@ export async function directCouchCall(
9
9
  ) {
10
10
  let { url, cookie } = getCouchInfo()
11
11
  const couchUrl = `${url}/${path}`
12
+ return await directCouchUrlCall({ url: couchUrl, cookie, method, body })
13
+ }
14
+
15
+ export async function directCouchUrlCall({
16
+ url,
17
+ cookie,
18
+ method,
19
+ body,
20
+ }: {
21
+ url: string
22
+ cookie: string
23
+ method: string
24
+ body?: any
25
+ }) {
12
26
  const params: any = {
13
27
  method: method,
14
28
  headers: {
@@ -19,7 +33,7 @@ export async function directCouchCall(
19
33
  params.body = JSON.stringify(body)
20
34
  params.headers["Content-Type"] = "application/json"
21
35
  }
22
- return await fetch(checkSlashesInUrl(encodeURI(couchUrl)), params)
36
+ return await fetch(checkSlashesInUrl(encodeURI(url)), params)
23
37
  }
24
38
 
25
39
  export async function directCouchQuery(