@budibase/backend-core 2.14.6 → 2.14.7
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/index.js +66 -55
- package/dist/index.js.map +2 -2
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/db/couch/DatabaseImpl.d.ts +3 -2
- package/dist/src/db/couch/DatabaseImpl.js +67 -49
- package/dist/src/db/couch/DatabaseImpl.js.map +1 -1
- package/dist/src/db/instrumentation.d.ts +1 -2
- package/dist/src/db/instrumentation.js +0 -6
- package/dist/src/db/instrumentation.js.map +1 -1
- package/package.json +4 -4
- package/src/db/couch/DatabaseImpl.ts +71 -48
- package/src/db/instrumentation.ts +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../src/db/instrumentation.ts"],"names":[],"mappings":";;;;;;AAgBA,wDAA6B;AAG7B,MAAa,sBAAsB;IACjC,YAA6B,EAAY;QAAZ,OAAE,GAAF,EAAE,CAAU;IAAG,CAAC;IAE7C,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAA;IACrB,CAAC;IAED,MAAM;QACJ,OAAO,kBAAM,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE;YACtC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;YACrC,OAAO,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAA;QACzB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../src/db/instrumentation.ts"],"names":[],"mappings":";;;;;;AAgBA,wDAA6B;AAG7B,MAAa,sBAAsB;IACjC,YAA6B,EAAY;QAAZ,OAAE,GAAF,EAA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E,CAAC,CAAA;YACrC,OAAO,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAA;QACpC,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAjID,wDAiIC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/backend-core",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.7",
|
|
4
4
|
"description": "Budibase backend core libraries used in server and worker",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@budibase/nano": "10.1.4",
|
|
25
25
|
"@budibase/pouchdb-replication-stream": "1.2.10",
|
|
26
|
-
"@budibase/shared-core": "2.14.
|
|
27
|
-
"@budibase/types": "2.14.
|
|
26
|
+
"@budibase/shared-core": "2.14.7",
|
|
27
|
+
"@budibase/types": "2.14.7",
|
|
28
28
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
29
29
|
"aws-cloudfront-sign": "3.0.2",
|
|
30
30
|
"aws-sdk": "2.1030.0",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "7b5a19d3146b137e974c22f99e04f3541c9e5215"
|
|
100
100
|
}
|
|
@@ -19,6 +19,8 @@ import { WriteStream, ReadStream } from "fs"
|
|
|
19
19
|
import { newid } from "../../docIds/newid"
|
|
20
20
|
import { DDInstrumentedDatabase } from "../instrumentation"
|
|
21
21
|
|
|
22
|
+
const DATABASE_NOT_FOUND = "Database does not exist."
|
|
23
|
+
|
|
22
24
|
function buildNano(couchInfo: { url: string; cookie: string }) {
|
|
23
25
|
return Nano({
|
|
24
26
|
url: couchInfo.url,
|
|
@@ -31,6 +33,8 @@ function buildNano(couchInfo: { url: string; cookie: string }) {
|
|
|
31
33
|
})
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
type DBCall<T> = () => Promise<T>
|
|
37
|
+
|
|
34
38
|
export function DatabaseWithConnection(
|
|
35
39
|
dbName: string,
|
|
36
40
|
connection: string,
|
|
@@ -78,7 +82,11 @@ export class DatabaseImpl implements Database {
|
|
|
78
82
|
return this.instanceNano || DatabaseImpl.nano
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
|
|
85
|
+
private getDb() {
|
|
86
|
+
return this.nano().db.use(this.name)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private async checkAndCreateDb() {
|
|
82
90
|
let shouldCreate = !this.pouchOpts?.skip_setup
|
|
83
91
|
// check exists in a lightweight fashion
|
|
84
92
|
let exists = await this.exists()
|
|
@@ -95,14 +103,22 @@ export class DatabaseImpl implements Database {
|
|
|
95
103
|
}
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
|
-
return this.
|
|
106
|
+
return this.getDb()
|
|
99
107
|
}
|
|
100
108
|
|
|
101
|
-
|
|
109
|
+
// this function fetches the DB and handles if DB creation is needed
|
|
110
|
+
private async performCall<T>(
|
|
111
|
+
call: (db: Nano.DocumentScope<any>) => Promise<DBCall<T>> | DBCall<T>
|
|
112
|
+
): Promise<any> {
|
|
113
|
+
const db = this.getDb()
|
|
114
|
+
const fnc = await call(db)
|
|
102
115
|
try {
|
|
103
116
|
return await fnc()
|
|
104
117
|
} catch (err: any) {
|
|
105
|
-
if (err.statusCode) {
|
|
118
|
+
if (err.statusCode === 404 && err.reason === DATABASE_NOT_FOUND) {
|
|
119
|
+
await this.checkAndCreateDb()
|
|
120
|
+
return await this.performCall(call)
|
|
121
|
+
} else if (err.statusCode) {
|
|
106
122
|
err.status = err.statusCode
|
|
107
123
|
}
|
|
108
124
|
throw err
|
|
@@ -110,11 +126,12 @@ export class DatabaseImpl implements Database {
|
|
|
110
126
|
}
|
|
111
127
|
|
|
112
128
|
async get<T extends Document>(id?: string): Promise<T> {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
129
|
+
return this.performCall(db => {
|
|
130
|
+
if (!id) {
|
|
131
|
+
throw new Error("Unable to get doc without a valid _id.")
|
|
132
|
+
}
|
|
133
|
+
return () => db.get(id)
|
|
134
|
+
})
|
|
118
135
|
}
|
|
119
136
|
|
|
120
137
|
async getMultiple<T extends Document>(
|
|
@@ -147,22 +164,23 @@ export class DatabaseImpl implements Database {
|
|
|
147
164
|
}
|
|
148
165
|
|
|
149
166
|
async remove(idOrDoc: string | Document, rev?: string) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
167
|
+
return this.performCall(db => {
|
|
168
|
+
let _id: string
|
|
169
|
+
let _rev: string
|
|
153
170
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
171
|
+
if (isDocument(idOrDoc)) {
|
|
172
|
+
_id = idOrDoc._id!
|
|
173
|
+
_rev = idOrDoc._rev!
|
|
174
|
+
} else {
|
|
175
|
+
_id = idOrDoc
|
|
176
|
+
_rev = rev!
|
|
177
|
+
}
|
|
161
178
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
179
|
+
if (!_id || !_rev) {
|
|
180
|
+
throw new Error("Unable to remove doc without a valid _id and _rev.")
|
|
181
|
+
}
|
|
182
|
+
return () => db.destroy(_id, _rev)
|
|
183
|
+
})
|
|
166
184
|
}
|
|
167
185
|
|
|
168
186
|
async post(document: AnyDocument, opts?: DatabasePutOpts) {
|
|
@@ -176,45 +194,49 @@ export class DatabaseImpl implements Database {
|
|
|
176
194
|
if (!document._id) {
|
|
177
195
|
throw new Error("Cannot store document without _id field.")
|
|
178
196
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
197
|
+
return this.performCall(async db => {
|
|
198
|
+
if (!document.createdAt) {
|
|
199
|
+
document.createdAt = new Date().toISOString()
|
|
200
|
+
}
|
|
201
|
+
document.updatedAt = new Date().toISOString()
|
|
202
|
+
if (opts?.force && document._id) {
|
|
203
|
+
try {
|
|
204
|
+
const existing = await this.get(document._id)
|
|
205
|
+
if (existing) {
|
|
206
|
+
document._rev = existing._rev
|
|
207
|
+
}
|
|
208
|
+
} catch (err: any) {
|
|
209
|
+
if (err.status !== 404) {
|
|
210
|
+
throw err
|
|
211
|
+
}
|
|
193
212
|
}
|
|
194
213
|
}
|
|
195
|
-
|
|
196
|
-
|
|
214
|
+
return () => db.insert(document)
|
|
215
|
+
})
|
|
197
216
|
}
|
|
198
217
|
|
|
199
218
|
async bulkDocs(documents: AnyDocument[]) {
|
|
200
|
-
|
|
201
|
-
|
|
219
|
+
return this.performCall(db => {
|
|
220
|
+
return () => db.bulk({ docs: documents })
|
|
221
|
+
})
|
|
202
222
|
}
|
|
203
223
|
|
|
204
224
|
async allDocs<T extends Document>(
|
|
205
225
|
params: DatabaseQueryOpts
|
|
206
226
|
): Promise<AllDocsResponse<T>> {
|
|
207
|
-
|
|
208
|
-
|
|
227
|
+
return this.performCall(db => {
|
|
228
|
+
return () => db.list(params)
|
|
229
|
+
})
|
|
209
230
|
}
|
|
210
231
|
|
|
211
232
|
async query<T extends Document>(
|
|
212
233
|
viewName: string,
|
|
213
234
|
params: DatabaseQueryOpts
|
|
214
235
|
): Promise<AllDocsResponse<T>> {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
236
|
+
return this.performCall(db => {
|
|
237
|
+
const [database, view] = viewName.split("/")
|
|
238
|
+
return () => db.view(database, view, params)
|
|
239
|
+
})
|
|
218
240
|
}
|
|
219
241
|
|
|
220
242
|
async destroy() {
|
|
@@ -231,8 +253,9 @@ export class DatabaseImpl implements Database {
|
|
|
231
253
|
}
|
|
232
254
|
|
|
233
255
|
async compact() {
|
|
234
|
-
|
|
235
|
-
|
|
256
|
+
return this.performCall(db => {
|
|
257
|
+
return () => db.compact()
|
|
258
|
+
})
|
|
236
259
|
}
|
|
237
260
|
|
|
238
261
|
// All below functions are in-frequently called, just utilise PouchDB
|
|
@@ -31,13 +31,6 @@ export class DDInstrumentedDatabase implements Database {
|
|
|
31
31
|
})
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
checkSetup(): Promise<DocumentScope<any>> {
|
|
35
|
-
return tracer.trace("db.checkSetup", span => {
|
|
36
|
-
span?.addTags({ db_name: this.name })
|
|
37
|
-
return this.db.checkSetup()
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
34
|
get<T extends Document>(id?: string | undefined): Promise<T> {
|
|
42
35
|
return tracer.trace("db.get", span => {
|
|
43
36
|
span?.addTags({ db_name: this.name, doc_id: id })
|