@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/dist/package.json +3 -3
- package/dist/src/db/couch/DatabaseImpl.d.ts +1 -0
- package/dist/src/db/couch/DatabaseImpl.js +8 -3
- package/dist/src/db/couch/DatabaseImpl.js.map +1 -1
- package/dist/src/db/couch/connections.js +11 -10
- package/dist/src/db/couch/connections.js.map +1 -1
- package/dist/src/db/couch/utils.d.ts +6 -0
- package/dist/src/db/couch/utils.js +9 -3
- package/dist/src/db/couch/utils.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/couch/DatabaseImpl.ts +10 -4
- package/src/db/couch/connections.ts +8 -8
- package/src/db/couch/utils.ts +15 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/backend-core",
|
|
3
|
-
"version": "2.6.16-alpha.
|
|
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.
|
|
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": "
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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 (
|
|
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
|
}
|
package/src/db/couch/utils.ts
CHANGED
|
@@ -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(
|
|
36
|
+
return await fetch(checkSlashesInUrl(encodeURI(url)), params)
|
|
23
37
|
}
|
|
24
38
|
|
|
25
39
|
export async function directCouchQuery(
|