@budibase/backend-core 3.2.4 → 3.2.6
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.map +1 -1
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +11 -4
- package/dist/plugins.js.meta.json +1 -1
- package/package.json +11 -4
- package/src/accounts/accounts.ts +0 -82
- package/src/accounts/api.ts +0 -59
- package/src/accounts/index.ts +0 -1
- package/src/auth/auth.ts +0 -210
- package/src/auth/index.ts +0 -1
- package/src/auth/tests/auth.spec.ts +0 -14
- package/src/blacklist/blacklist.ts +0 -54
- package/src/blacklist/index.ts +0 -1
- package/src/blacklist/tests/blacklist.spec.ts +0 -46
- package/src/cache/appMetadata.ts +0 -88
- package/src/cache/base/index.ts +0 -150
- package/src/cache/docWritethrough.ts +0 -105
- package/src/cache/generic.ts +0 -33
- package/src/cache/index.ts +0 -8
- package/src/cache/invite.ts +0 -86
- package/src/cache/passwordReset.ts +0 -49
- package/src/cache/tests/docWritethrough.spec.ts +0 -296
- package/src/cache/tests/user.spec.ts +0 -145
- package/src/cache/tests/writethrough.spec.ts +0 -139
- package/src/cache/user.ts +0 -154
- package/src/cache/writethrough.ts +0 -133
- package/src/configs/configs.ts +0 -263
- package/src/configs/index.ts +0 -1
- package/src/configs/tests/configs.spec.ts +0 -184
- package/src/constants/db.ts +0 -75
- package/src/constants/index.ts +0 -2
- package/src/constants/misc.ts +0 -36
- package/src/context/Context.ts +0 -14
- package/src/context/identity.ts +0 -58
- package/src/context/index.ts +0 -3
- package/src/context/mainContext.ts +0 -422
- package/src/context/tests/index.spec.ts +0 -255
- package/src/context/types.ts +0 -26
- package/src/db/Replication.ts +0 -94
- package/src/db/couch/DatabaseImpl.ts +0 -511
- package/src/db/couch/connections.ts +0 -89
- package/src/db/couch/index.ts +0 -4
- package/src/db/couch/pouchDB.ts +0 -97
- package/src/db/couch/pouchDump.ts +0 -0
- package/src/db/couch/tests/DatabaseImpl.spec.ts +0 -118
- package/src/db/couch/utils.ts +0 -55
- package/src/db/db.ts +0 -34
- package/src/db/errors.ts +0 -14
- package/src/db/index.ts +0 -12
- package/src/db/instrumentation.ts +0 -199
- package/src/db/lucene.ts +0 -721
- package/src/db/searchIndexes/index.ts +0 -1
- package/src/db/searchIndexes/searchIndexes.ts +0 -62
- package/src/db/tests/DatabaseImpl.spec.ts +0 -55
- package/src/db/tests/connections.spec.ts +0 -22
- package/src/db/tests/index.spec.ts +0 -32
- package/src/db/tests/lucene.spec.ts +0 -400
- package/src/db/tests/pouch.spec.js +0 -62
- package/src/db/tests/utils.spec.ts +0 -63
- package/src/db/utils.ts +0 -208
- package/src/db/views.ts +0 -245
- package/src/docIds/conversions.ts +0 -60
- package/src/docIds/ids.ts +0 -126
- package/src/docIds/index.ts +0 -2
- package/src/docIds/newid.ts +0 -5
- package/src/docIds/params.ts +0 -189
- package/src/docUpdates/index.ts +0 -24
- package/src/environment.ts +0 -293
- package/src/errors/errors.ts +0 -119
- package/src/errors/index.ts +0 -1
- package/src/events/analytics.ts +0 -6
- package/src/events/asyncEvents/index.ts +0 -2
- package/src/events/asyncEvents/publisher.ts +0 -12
- package/src/events/asyncEvents/queue.ts +0 -22
- package/src/events/backfill.ts +0 -183
- package/src/events/documentId.ts +0 -56
- package/src/events/events.ts +0 -47
- package/src/events/identification.ts +0 -311
- package/src/events/index.ts +0 -15
- package/src/events/processors/AnalyticsProcessor.ts +0 -64
- package/src/events/processors/AuditLogsProcessor.ts +0 -92
- package/src/events/processors/LoggingProcessor.ts +0 -36
- package/src/events/processors/Processors.ts +0 -52
- package/src/events/processors/async/DocumentUpdateProcessor.ts +0 -38
- package/src/events/processors/index.ts +0 -19
- package/src/events/processors/posthog/PosthogProcessor.ts +0 -118
- package/src/events/processors/posthog/index.ts +0 -3
- package/src/events/processors/posthog/rateLimiting.ts +0 -106
- package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +0 -164
- package/src/events/processors/types.ts +0 -1
- package/src/events/publishers/account.ts +0 -41
- package/src/events/publishers/ai.ts +0 -21
- package/src/events/publishers/app.ts +0 -168
- package/src/events/publishers/auditLog.ts +0 -26
- package/src/events/publishers/auth.ts +0 -73
- package/src/events/publishers/automation.ts +0 -110
- package/src/events/publishers/backfill.ts +0 -74
- package/src/events/publishers/backup.ts +0 -42
- package/src/events/publishers/datasource.ts +0 -48
- package/src/events/publishers/email.ts +0 -17
- package/src/events/publishers/environmentVariable.ts +0 -38
- package/src/events/publishers/group.ts +0 -99
- package/src/events/publishers/index.ts +0 -25
- package/src/events/publishers/installation.ts +0 -38
- package/src/events/publishers/layout.ts +0 -26
- package/src/events/publishers/license.ts +0 -84
- package/src/events/publishers/org.ts +0 -37
- package/src/events/publishers/plugin.ts +0 -47
- package/src/events/publishers/query.ts +0 -89
- package/src/events/publishers/role.ts +0 -62
- package/src/events/publishers/rows.ts +0 -29
- package/src/events/publishers/screen.ts +0 -36
- package/src/events/publishers/serve.ts +0 -43
- package/src/events/publishers/table.ts +0 -70
- package/src/events/publishers/user.ts +0 -202
- package/src/events/publishers/view.ts +0 -107
- package/src/features/features.ts +0 -277
- package/src/features/index.ts +0 -2
- package/src/features/tests/features.spec.ts +0 -267
- package/src/features/tests/utils.ts +0 -64
- package/src/helpers.ts +0 -9
- package/src/index.ts +0 -59
- package/src/installation.ts +0 -115
- package/src/logging/alerts.ts +0 -26
- package/src/logging/correlation/correlation.ts +0 -15
- package/src/logging/correlation/index.ts +0 -1
- package/src/logging/correlation/middleware.ts +0 -18
- package/src/logging/index.ts +0 -4
- package/src/logging/pino/logger.ts +0 -239
- package/src/logging/pino/middleware.ts +0 -48
- package/src/logging/system.ts +0 -81
- package/src/logging/tests/system.spec.ts +0 -61
- package/src/middleware/adminOnly.ts +0 -9
- package/src/middleware/auditLog.ts +0 -6
- package/src/middleware/authenticated.ts +0 -247
- package/src/middleware/builderOnly.ts +0 -21
- package/src/middleware/builderOrAdmin.ts +0 -21
- package/src/middleware/contentSecurityPolicy.ts +0 -113
- package/src/middleware/csrf.ts +0 -81
- package/src/middleware/errorHandling.ts +0 -43
- package/src/middleware/index.ts +0 -24
- package/src/middleware/internalApi.ts +0 -23
- package/src/middleware/ip.ts +0 -12
- package/src/middleware/joi-validator.ts +0 -58
- package/src/middleware/matchers.ts +0 -39
- package/src/middleware/passport/datasource/google.ts +0 -102
- package/src/middleware/passport/local.ts +0 -54
- package/src/middleware/passport/sso/google.ts +0 -77
- package/src/middleware/passport/sso/oidc.ts +0 -152
- package/src/middleware/passport/sso/sso.ts +0 -138
- package/src/middleware/passport/sso/tests/google.spec.ts +0 -68
- package/src/middleware/passport/sso/tests/oidc.spec.ts +0 -144
- package/src/middleware/passport/sso/tests/sso.spec.ts +0 -197
- package/src/middleware/passport/utils.ts +0 -38
- package/src/middleware/querystringToBody.ts +0 -28
- package/src/middleware/tenancy.ts +0 -36
- package/src/middleware/tests/builder.spec.ts +0 -181
- package/src/middleware/tests/contentSecurityPolicy.spec.ts +0 -75
- package/src/middleware/tests/matchers.spec.ts +0 -100
- package/src/migrations/definitions.ts +0 -40
- package/src/migrations/index.ts +0 -2
- package/src/migrations/migrations.ts +0 -186
- package/src/migrations/tests/__snapshots__/migrations.spec.ts.snap +0 -11
- package/src/migrations/tests/migrations.spec.ts +0 -64
- package/src/objectStore/buckets/app.ts +0 -53
- package/src/objectStore/buckets/global.ts +0 -29
- package/src/objectStore/buckets/index.ts +0 -3
- package/src/objectStore/buckets/plugins.ts +0 -71
- package/src/objectStore/buckets/tests/app.spec.ts +0 -161
- package/src/objectStore/buckets/tests/global.spec.ts +0 -74
- package/src/objectStore/buckets/tests/plugins.spec.ts +0 -111
- package/src/objectStore/cloudfront.ts +0 -41
- package/src/objectStore/index.ts +0 -3
- package/src/objectStore/objectStore.ts +0 -585
- package/src/objectStore/utils.ts +0 -113
- package/src/platform/index.ts +0 -3
- package/src/platform/platformDb.ts +0 -6
- package/src/platform/tenants.ts +0 -101
- package/src/platform/tests/tenants.spec.ts +0 -26
- package/src/platform/users.ts +0 -129
- package/src/plugin/index.ts +0 -1
- package/src/plugin/tests/validation.spec.ts +0 -209
- package/src/plugin/utils.ts +0 -175
- package/src/queue/constants.ts +0 -8
- package/src/queue/inMemoryQueue.ts +0 -189
- package/src/queue/index.ts +0 -2
- package/src/queue/listeners.ts +0 -199
- package/src/queue/queue.ts +0 -84
- package/src/redis/index.ts +0 -6
- package/src/redis/init.ts +0 -118
- package/src/redis/redis.ts +0 -358
- package/src/redis/redlockImpl.ts +0 -155
- package/src/redis/tests/redis.spec.ts +0 -207
- package/src/redis/tests/redlockImpl.spec.ts +0 -105
- package/src/redis/utils.ts +0 -128
- package/src/security/auth.ts +0 -24
- package/src/security/encryption.ts +0 -185
- package/src/security/index.ts +0 -1
- package/src/security/permissions.ts +0 -166
- package/src/security/roles.ts +0 -655
- package/src/security/secrets.ts +0 -20
- package/src/security/sessions.ts +0 -123
- package/src/security/tests/auth.spec.ts +0 -45
- package/src/security/tests/encryption.spec.ts +0 -31
- package/src/security/tests/permissions.spec.ts +0 -146
- package/src/security/tests/secrets.spec.ts +0 -35
- package/src/security/tests/sessions.spec.ts +0 -12
- package/src/sql/designDoc.ts +0 -17
- package/src/sql/index.ts +0 -5
- package/src/sql/sql.ts +0 -1854
- package/src/sql/sqlTable.ts +0 -319
- package/src/sql/utils.ts +0 -193
- package/src/tenancy/db.ts +0 -6
- package/src/tenancy/index.ts +0 -2
- package/src/tenancy/tenancy.ts +0 -148
- package/src/tenancy/tests/tenancy.spec.ts +0 -184
- package/src/timers/index.ts +0 -1
- package/src/timers/timers.ts +0 -22
- package/src/users/db.ts +0 -582
- package/src/users/events.ts +0 -176
- package/src/users/index.ts +0 -4
- package/src/users/lookup.ts +0 -99
- package/src/users/test/db.spec.ts +0 -188
- package/src/users/test/utils.spec.ts +0 -67
- package/src/users/users.ts +0 -353
- package/src/users/utils.ts +0 -81
- package/src/utils/Duration.ts +0 -56
- package/src/utils/hashing.ts +0 -15
- package/src/utils/index.ts +0 -4
- package/src/utils/stringUtils.ts +0 -8
- package/src/utils/tests/Duration.spec.ts +0 -19
- package/src/utils/tests/utils.spec.ts +0 -204
- package/src/utils/utils.ts +0 -249
- package/tests/core/logging.ts +0 -34
- package/tests/core/users/users.spec.js +0 -53
- package/tests/core/utilities/index.ts +0 -7
- package/tests/core/utilities/jestUtils.ts +0 -33
- package/tests/core/utilities/mocks/alerts.ts +0 -4
- package/tests/core/utilities/mocks/date.ts +0 -3
- package/tests/core/utilities/mocks/events.ts +0 -132
- package/tests/core/utilities/mocks/index.ts +0 -9
- package/tests/core/utilities/mocks/licenses.ts +0 -119
- package/tests/core/utilities/queue.ts +0 -9
- package/tests/core/utilities/structures/Chance.ts +0 -20
- package/tests/core/utilities/structures/accounts.ts +0 -80
- package/tests/core/utilities/structures/apps.ts +0 -21
- package/tests/core/utilities/structures/common.ts +0 -7
- package/tests/core/utilities/structures/db.ts +0 -12
- package/tests/core/utilities/structures/documents/index.ts +0 -1
- package/tests/core/utilities/structures/documents/platform/index.ts +0 -1
- package/tests/core/utilities/structures/documents/platform/installation.ts +0 -12
- package/tests/core/utilities/structures/generator.ts +0 -3
- package/tests/core/utilities/structures/index.ts +0 -15
- package/tests/core/utilities/structures/koa.ts +0 -16
- package/tests/core/utilities/structures/licenses.ts +0 -190
- package/tests/core/utilities/structures/plugins.ts +0 -19
- package/tests/core/utilities/structures/quotas.ts +0 -72
- package/tests/core/utilities/structures/scim.ts +0 -80
- package/tests/core/utilities/structures/sso.ts +0 -118
- package/tests/core/utilities/structures/tenants.ts +0 -5
- package/tests/core/utilities/structures/userGroups.ts +0 -10
- package/tests/core/utilities/structures/users.ts +0 -89
- package/tests/core/utilities/testContainerUtils.ts +0 -165
- package/tests/core/utilities/utils/index.ts +0 -2
- package/tests/core/utilities/utils/queue.ts +0 -27
- package/tests/core/utilities/utils/time.ts +0 -3
- package/tests/extra/DBTestConfiguration.ts +0 -36
- package/tests/extra/index.ts +0 -2
- package/tests/extra/testEnv.ts +0 -95
- package/tests/index.ts +0 -2
- package/tests/jestEnv.ts +0 -10
- package/tests/jestSetup.ts +0 -36
package/src/db/couch/pouchDB.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import PouchDB from "pouchdb"
|
|
2
|
-
import env from "../../environment"
|
|
3
|
-
import { PouchOptions } from "@budibase/types"
|
|
4
|
-
import { getCouchInfo } from "./connections"
|
|
5
|
-
|
|
6
|
-
let Pouch: any
|
|
7
|
-
let initialised = false
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Return a constructor for PouchDB.
|
|
11
|
-
* This should be rarely used outside of the main application config.
|
|
12
|
-
* Exposed for exceptional cases such as in-memory views.
|
|
13
|
-
*/
|
|
14
|
-
export const getPouch = (opts: PouchOptions = {}) => {
|
|
15
|
-
let { url, cookie } = getCouchInfo()
|
|
16
|
-
let POUCH_DB_DEFAULTS = {
|
|
17
|
-
prefix: url,
|
|
18
|
-
fetch: (url: string, opts: any) => {
|
|
19
|
-
// use a specific authorization cookie - be very explicit about how we authenticate
|
|
20
|
-
opts.headers.set("Authorization", cookie)
|
|
21
|
-
return PouchDB.fetch(url, opts)
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (opts.inMemory) {
|
|
26
|
-
const inMemory = require("pouchdb-adapter-memory")
|
|
27
|
-
PouchDB.plugin(inMemory)
|
|
28
|
-
POUCH_DB_DEFAULTS = {
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
adapter: "memory",
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (opts.onDisk) {
|
|
35
|
-
POUCH_DB_DEFAULTS = {
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
adapter: "leveldb",
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (opts.replication) {
|
|
42
|
-
const replicationStream = require("@budibase/pouchdb-replication-stream")
|
|
43
|
-
PouchDB.plugin(replicationStream.plugin)
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
PouchDB.adapter("writableStream", replicationStream.adapters.writableStream)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (opts.find) {
|
|
49
|
-
const find = require("pouchdb-find")
|
|
50
|
-
PouchDB.plugin(find)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return PouchDB.defaults(POUCH_DB_DEFAULTS)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function init(opts?: PouchOptions) {
|
|
57
|
-
Pouch = getPouch(opts)
|
|
58
|
-
initialised = true
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const checkInitialised = () => {
|
|
62
|
-
if (!initialised) {
|
|
63
|
-
throw new Error("init has not been called")
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function getPouchDB(dbName: string, opts?: any): PouchDB.Database {
|
|
68
|
-
checkInitialised()
|
|
69
|
-
const db = new Pouch(dbName, opts)
|
|
70
|
-
const dbPut = db.put
|
|
71
|
-
db.put = async (doc: any, options = {}) => {
|
|
72
|
-
if (!doc.createdAt) {
|
|
73
|
-
doc.createdAt = new Date().toISOString()
|
|
74
|
-
}
|
|
75
|
-
doc.updatedAt = new Date().toISOString()
|
|
76
|
-
return dbPut(doc, options)
|
|
77
|
-
}
|
|
78
|
-
db.exists = async () => {
|
|
79
|
-
const info = await db.info()
|
|
80
|
-
return !info.error
|
|
81
|
-
}
|
|
82
|
-
return db
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// use this function if you have called getPouchDB - close
|
|
86
|
-
// the databases you've opened once finished
|
|
87
|
-
export async function closePouchDB(db: PouchDB.Database) {
|
|
88
|
-
if (!db || env.isTest()) {
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
// specifically await so that if there is an error, it can be ignored
|
|
93
|
-
return await db.close()
|
|
94
|
-
} catch (err) {
|
|
95
|
-
// ignore error, already closed
|
|
96
|
-
}
|
|
97
|
-
}
|
|
File without changes
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import tk from "timekeeper"
|
|
2
|
-
|
|
3
|
-
import { DatabaseImpl } from ".."
|
|
4
|
-
|
|
5
|
-
import { generator, structures } from "../../../../tests"
|
|
6
|
-
|
|
7
|
-
const initialTime = new Date()
|
|
8
|
-
tk.freeze(initialTime)
|
|
9
|
-
|
|
10
|
-
describe("DatabaseImpl", () => {
|
|
11
|
-
const db = new DatabaseImpl(structures.db.id())
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
tk.freeze(initialTime)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
describe("put", () => {
|
|
18
|
-
it("persists createdAt and updatedAt fields", async () => {
|
|
19
|
-
const id = generator.guid()
|
|
20
|
-
await db.put({ _id: id })
|
|
21
|
-
|
|
22
|
-
expect(await db.get(id)).toEqual({
|
|
23
|
-
_id: id,
|
|
24
|
-
_rev: expect.any(String),
|
|
25
|
-
createdAt: initialTime.toISOString(),
|
|
26
|
-
updatedAt: initialTime.toISOString(),
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it("updates updated at fields", async () => {
|
|
31
|
-
const id = generator.guid()
|
|
32
|
-
|
|
33
|
-
await db.put({ _id: id })
|
|
34
|
-
tk.travel(100)
|
|
35
|
-
|
|
36
|
-
await db.put({ ...(await db.get(id)), newValue: 123 })
|
|
37
|
-
|
|
38
|
-
expect(await db.get(id)).toEqual({
|
|
39
|
-
_id: id,
|
|
40
|
-
_rev: expect.any(String),
|
|
41
|
-
newValue: 123,
|
|
42
|
-
createdAt: initialTime.toISOString(),
|
|
43
|
-
updatedAt: new Date().toISOString(),
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
describe("bulkDocs", () => {
|
|
49
|
-
it("persists createdAt and updatedAt fields", async () => {
|
|
50
|
-
const ids = generator.unique(() => generator.guid(), 5)
|
|
51
|
-
await db.bulkDocs(ids.map(id => ({ _id: id })))
|
|
52
|
-
|
|
53
|
-
for (const id of ids) {
|
|
54
|
-
expect(await db.get(id)).toEqual({
|
|
55
|
-
_id: id,
|
|
56
|
-
_rev: expect.any(String),
|
|
57
|
-
createdAt: initialTime.toISOString(),
|
|
58
|
-
updatedAt: initialTime.toISOString(),
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it("updates updated at fields", async () => {
|
|
64
|
-
const ids = generator.unique(() => generator.guid(), 5)
|
|
65
|
-
|
|
66
|
-
await db.bulkDocs(ids.map(id => ({ _id: id })))
|
|
67
|
-
tk.travel(100)
|
|
68
|
-
|
|
69
|
-
const docsToUpdate = await Promise.all(
|
|
70
|
-
ids.map(async id => ({ ...(await db.get(id)), newValue: 123 }))
|
|
71
|
-
)
|
|
72
|
-
await db.bulkDocs(docsToUpdate)
|
|
73
|
-
|
|
74
|
-
for (const id of ids) {
|
|
75
|
-
expect(await db.get(id)).toEqual({
|
|
76
|
-
_id: id,
|
|
77
|
-
_rev: expect.any(String),
|
|
78
|
-
newValue: 123,
|
|
79
|
-
createdAt: initialTime.toISOString(),
|
|
80
|
-
updatedAt: new Date().toISOString(),
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it("keeps existing createdAt", async () => {
|
|
86
|
-
const ids = generator.unique(() => generator.guid(), 2)
|
|
87
|
-
|
|
88
|
-
await db.bulkDocs(ids.map(id => ({ _id: id })))
|
|
89
|
-
tk.travel(100)
|
|
90
|
-
|
|
91
|
-
const newDocs = generator
|
|
92
|
-
.unique(() => generator.guid(), 3)
|
|
93
|
-
.map(id => ({ _id: id }))
|
|
94
|
-
const docsToUpdate = await Promise.all(
|
|
95
|
-
ids.map(async id => ({ ...(await db.get(id)), newValue: 123 }))
|
|
96
|
-
)
|
|
97
|
-
await db.bulkDocs([...newDocs, ...docsToUpdate])
|
|
98
|
-
|
|
99
|
-
for (const { _id } of docsToUpdate) {
|
|
100
|
-
expect(await db.get(_id)).toEqual({
|
|
101
|
-
_id,
|
|
102
|
-
_rev: expect.any(String),
|
|
103
|
-
newValue: 123,
|
|
104
|
-
createdAt: initialTime.toISOString(),
|
|
105
|
-
updatedAt: new Date().toISOString(),
|
|
106
|
-
})
|
|
107
|
-
}
|
|
108
|
-
for (const { _id } of newDocs) {
|
|
109
|
-
expect(await db.get(_id)).toEqual({
|
|
110
|
-
_id,
|
|
111
|
-
_rev: expect.any(String),
|
|
112
|
-
createdAt: new Date().toISOString(),
|
|
113
|
-
updatedAt: new Date().toISOString(),
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
})
|
|
118
|
-
})
|
package/src/db/couch/utils.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { getCouchInfo } from "./connections"
|
|
2
|
-
import fetch from "node-fetch"
|
|
3
|
-
import { checkSlashesInUrl } from "../../helpers"
|
|
4
|
-
|
|
5
|
-
export async function directCouchCall(
|
|
6
|
-
path: string,
|
|
7
|
-
method: string = "GET",
|
|
8
|
-
body?: any
|
|
9
|
-
) {
|
|
10
|
-
let { url, cookie } = getCouchInfo()
|
|
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?: Record<string, any>
|
|
25
|
-
}) {
|
|
26
|
-
const params: any = {
|
|
27
|
-
method: method,
|
|
28
|
-
headers: {
|
|
29
|
-
Authorization: cookie,
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
if (body && method !== "GET") {
|
|
33
|
-
if (typeof body === "string") {
|
|
34
|
-
params.body = body
|
|
35
|
-
params.headers["Content-Type"] = "text/plain"
|
|
36
|
-
} else {
|
|
37
|
-
params.body = JSON.stringify(body)
|
|
38
|
-
params.headers["Content-Type"] = "application/json"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return await fetch(checkSlashesInUrl(encodeURI(url)), params)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function directCouchQuery(
|
|
45
|
-
path: string,
|
|
46
|
-
method: string = "GET",
|
|
47
|
-
body?: any
|
|
48
|
-
) {
|
|
49
|
-
const response = await directCouchCall(path, method, body)
|
|
50
|
-
if (response.status < 300) {
|
|
51
|
-
return await response.json()
|
|
52
|
-
} else {
|
|
53
|
-
throw "Cannot connect to CouchDB instance"
|
|
54
|
-
}
|
|
55
|
-
}
|
package/src/db/db.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { directCouchQuery, DatabaseImpl } from "./couch"
|
|
2
|
-
import { CouchFindOptions, Database, DatabaseOpts } from "@budibase/types"
|
|
3
|
-
import { DDInstrumentedDatabase } from "./instrumentation"
|
|
4
|
-
|
|
5
|
-
export function getDB(dbName: string, opts?: DatabaseOpts): Database {
|
|
6
|
-
return new DDInstrumentedDatabase(new DatabaseImpl(dbName, opts))
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// we have to use a callback for this so that we can close
|
|
10
|
-
// the DB when we're done, without this manual requests would
|
|
11
|
-
// need to close the database when done with it to avoid memory leaks
|
|
12
|
-
export async function doWithDB<T>(
|
|
13
|
-
dbName: string,
|
|
14
|
-
cb: (db: Database) => Promise<T>,
|
|
15
|
-
opts?: DatabaseOpts
|
|
16
|
-
) {
|
|
17
|
-
const db = getDB(dbName, opts)
|
|
18
|
-
// need this to be async so that we can correctly close DB after all
|
|
19
|
-
// async operations have been completed
|
|
20
|
-
return await cb(db)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function directCouchAllDbs(queryString?: string) {
|
|
24
|
-
let couchPath = "/_all_dbs"
|
|
25
|
-
if (queryString) {
|
|
26
|
-
couchPath += `?${queryString}`
|
|
27
|
-
}
|
|
28
|
-
return await directCouchQuery(couchPath)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function directCouchFind(dbName: string, opts: CouchFindOptions) {
|
|
32
|
-
const json = await directCouchQuery(`${dbName}/_find`, "POST", opts)
|
|
33
|
-
return { rows: json.docs, bookmark: json.bookmark }
|
|
34
|
-
}
|
package/src/db/errors.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function checkErrorCode(error: any, code: number) {
|
|
2
|
-
const stringCode = code.toString()
|
|
3
|
-
if (typeof error === "object") {
|
|
4
|
-
return error.status === code || error.message?.includes(stringCode)
|
|
5
|
-
} else if (typeof error === "number") {
|
|
6
|
-
return error === code
|
|
7
|
-
} else if (typeof error === "string") {
|
|
8
|
-
return error.includes(stringCode)
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function isDocumentConflictError(error: any) {
|
|
13
|
-
return checkErrorCode(error, 409)
|
|
14
|
-
}
|
package/src/db/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from "./couch"
|
|
2
|
-
export * from "./db"
|
|
3
|
-
export * from "./utils"
|
|
4
|
-
export * from "./views"
|
|
5
|
-
export * from "../docIds/conversions"
|
|
6
|
-
export { default as Replication } from "./Replication"
|
|
7
|
-
// exports to support old export structure
|
|
8
|
-
export * from "../constants/db"
|
|
9
|
-
export { getGlobalDBName, baseGlobalDBName } from "../context"
|
|
10
|
-
export * from "./lucene"
|
|
11
|
-
export * as searchIndexes from "./searchIndexes"
|
|
12
|
-
export * from "./errors"
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DocumentDestroyResponse,
|
|
3
|
-
DocumentInsertResponse,
|
|
4
|
-
DocumentBulkResponse,
|
|
5
|
-
OkResponse,
|
|
6
|
-
} from "@budibase/nano"
|
|
7
|
-
import {
|
|
8
|
-
AllDocsResponse,
|
|
9
|
-
AnyDocument,
|
|
10
|
-
Database,
|
|
11
|
-
DatabaseDumpOpts,
|
|
12
|
-
DatabasePutOpts,
|
|
13
|
-
DatabaseQueryOpts,
|
|
14
|
-
Document,
|
|
15
|
-
RowValue,
|
|
16
|
-
SqlQueryBinding,
|
|
17
|
-
} from "@budibase/types"
|
|
18
|
-
import tracer from "dd-trace"
|
|
19
|
-
import { Writable } from "stream"
|
|
20
|
-
|
|
21
|
-
export class DDInstrumentedDatabase implements Database {
|
|
22
|
-
constructor(private readonly db: Database) {}
|
|
23
|
-
|
|
24
|
-
get name(): string {
|
|
25
|
-
return this.db.name
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
exists(docId?: string): Promise<boolean> {
|
|
29
|
-
return tracer.trace("db.exists", span => {
|
|
30
|
-
span?.addTags({ db_name: this.name, doc_id: docId })
|
|
31
|
-
if (docId) {
|
|
32
|
-
return this.db.exists(docId)
|
|
33
|
-
}
|
|
34
|
-
return this.db.exists()
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get<T extends Document>(id?: string | undefined): Promise<T> {
|
|
39
|
-
return tracer.trace("db.get", span => {
|
|
40
|
-
span?.addTags({ db_name: this.name, doc_id: id })
|
|
41
|
-
return this.db.get(id)
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
tryGet<T extends Document>(id?: string | undefined): Promise<T | undefined> {
|
|
46
|
-
return tracer.trace("db.tryGet", span => {
|
|
47
|
-
span?.addTags({ db_name: this.name, doc_id: id })
|
|
48
|
-
return this.db.tryGet(id)
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getMultiple<T extends Document>(
|
|
53
|
-
ids: string[],
|
|
54
|
-
opts?: { allowMissing?: boolean | undefined } | undefined
|
|
55
|
-
): Promise<T[]> {
|
|
56
|
-
return tracer.trace("db.getMultiple", span => {
|
|
57
|
-
span?.addTags({
|
|
58
|
-
db_name: this.name,
|
|
59
|
-
num_docs: ids.length,
|
|
60
|
-
allow_missing: opts?.allowMissing,
|
|
61
|
-
})
|
|
62
|
-
return this.db.getMultiple(ids, opts)
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
remove(idOrDoc: Document): Promise<DocumentDestroyResponse>
|
|
67
|
-
remove(idOrDoc: string, rev?: string): Promise<DocumentDestroyResponse>
|
|
68
|
-
remove(
|
|
69
|
-
idOrDoc: string | Document,
|
|
70
|
-
rev?: string
|
|
71
|
-
): Promise<DocumentDestroyResponse> {
|
|
72
|
-
return tracer.trace("db.remove", span => {
|
|
73
|
-
span?.addTags({ db_name: this.name, doc_id: idOrDoc })
|
|
74
|
-
const isDocument = typeof idOrDoc === "object"
|
|
75
|
-
const id = isDocument ? idOrDoc._id! : idOrDoc
|
|
76
|
-
rev = isDocument ? idOrDoc._rev : rev
|
|
77
|
-
return this.db.remove(id, rev)
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
bulkRemove(
|
|
82
|
-
documents: Document[],
|
|
83
|
-
opts?: { silenceErrors?: boolean }
|
|
84
|
-
): Promise<void> {
|
|
85
|
-
return tracer.trace("db.bulkRemove", span => {
|
|
86
|
-
span?.addTags({ db_name: this.name, num_docs: documents.length })
|
|
87
|
-
return this.db.bulkRemove(documents, opts)
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
put(
|
|
92
|
-
document: AnyDocument,
|
|
93
|
-
opts?: DatabasePutOpts | undefined
|
|
94
|
-
): Promise<DocumentInsertResponse> {
|
|
95
|
-
return tracer.trace("db.put", span => {
|
|
96
|
-
span?.addTags({ db_name: this.name, doc_id: document._id })
|
|
97
|
-
return this.db.put(document, opts)
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
bulkDocs(documents: AnyDocument[]): Promise<DocumentBulkResponse[]> {
|
|
102
|
-
return tracer.trace("db.bulkDocs", span => {
|
|
103
|
-
span?.addTags({ db_name: this.name, num_docs: documents.length })
|
|
104
|
-
return this.db.bulkDocs(documents)
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
allDocs<T extends Document | RowValue>(
|
|
109
|
-
params: DatabaseQueryOpts
|
|
110
|
-
): Promise<AllDocsResponse<T>> {
|
|
111
|
-
return tracer.trace("db.allDocs", span => {
|
|
112
|
-
span?.addTags({ db_name: this.name })
|
|
113
|
-
return this.db.allDocs(params)
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
query<T extends Document>(
|
|
118
|
-
viewName: string,
|
|
119
|
-
params: DatabaseQueryOpts
|
|
120
|
-
): Promise<AllDocsResponse<T>> {
|
|
121
|
-
return tracer.trace("db.query", span => {
|
|
122
|
-
span?.addTags({ db_name: this.name, view_name: viewName })
|
|
123
|
-
return this.db.query(viewName, params)
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
destroy(): Promise<void | OkResponse> {
|
|
128
|
-
return tracer.trace("db.destroy", span => {
|
|
129
|
-
span?.addTags({ db_name: this.name })
|
|
130
|
-
return this.db.destroy()
|
|
131
|
-
})
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
compact(): Promise<void | OkResponse> {
|
|
135
|
-
return tracer.trace("db.compact", span => {
|
|
136
|
-
span?.addTags({ db_name: this.name })
|
|
137
|
-
return this.db.compact()
|
|
138
|
-
})
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
dump(stream: Writable, opts?: DatabaseDumpOpts | undefined): Promise<any> {
|
|
142
|
-
return tracer.trace("db.dump", span => {
|
|
143
|
-
span?.addTags({ db_name: this.name })
|
|
144
|
-
return this.db.dump(stream, opts)
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
load(...args: any[]): Promise<any> {
|
|
149
|
-
return tracer.trace("db.load", span => {
|
|
150
|
-
span?.addTags({ db_name: this.name })
|
|
151
|
-
return this.db.load(...args)
|
|
152
|
-
})
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
createIndex(...args: any[]): Promise<any> {
|
|
156
|
-
return tracer.trace("db.createIndex", span => {
|
|
157
|
-
span?.addTags({ db_name: this.name })
|
|
158
|
-
return this.db.createIndex(...args)
|
|
159
|
-
})
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
deleteIndex(...args: any[]): Promise<any> {
|
|
163
|
-
return tracer.trace("db.deleteIndex", span => {
|
|
164
|
-
span?.addTags({ db_name: this.name })
|
|
165
|
-
return this.db.deleteIndex(...args)
|
|
166
|
-
})
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
getIndexes(...args: any[]): Promise<any> {
|
|
170
|
-
return tracer.trace("db.getIndexes", span => {
|
|
171
|
-
span?.addTags({ db_name: this.name })
|
|
172
|
-
return this.db.getIndexes(...args)
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
sql<T extends Document>(
|
|
177
|
-
sql: string,
|
|
178
|
-
parameters?: SqlQueryBinding
|
|
179
|
-
): Promise<T[]> {
|
|
180
|
-
return tracer.trace("db.sql", span => {
|
|
181
|
-
span?.addTags({ db_name: this.name })
|
|
182
|
-
return this.db.sql(sql, parameters)
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
sqlPurgeDocument(docIds: string[] | string): Promise<void> {
|
|
187
|
-
return tracer.trace("db.sqlPurgeDocument", span => {
|
|
188
|
-
span?.addTags({ db_name: this.name })
|
|
189
|
-
return this.db.sqlPurgeDocument(docIds)
|
|
190
|
-
})
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
sqlDiskCleanup(): Promise<void> {
|
|
194
|
-
return tracer.trace("db.sqlDiskCleanup", span => {
|
|
195
|
-
span?.addTags({ db_name: this.name })
|
|
196
|
-
return this.db.sqlDiskCleanup()
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
}
|