1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00

Fixes for find functionality after testing.

This commit is contained in:
mike12345567 2022-10-12 17:57:31 +01:00
parent 8deabb56dd
commit 92484fa240
3 changed files with 25 additions and 11 deletions

View file

@ -107,7 +107,8 @@ export async function directCouchQuery(
}, },
} }
if (body && method !== "GET") { if (body && method !== "GET") {
params.body = body params.body = JSON.stringify(body)
params.headers["Content-Type"] = "application/json"
} }
const response = await fetch(checkSlashesInUrl(encodeURI(couchUrl)), params) const response = await fetch(checkSlashesInUrl(encodeURI(couchUrl)), params)
if (response.status < 300) { if (response.status < 300) {
@ -117,6 +118,14 @@ export async function directCouchQuery(
} }
} }
export async function directCouchAllDbs(queryString?: string) {
let couchPath = "/_all_dbs"
if (queryString) {
couchPath += `?${queryString}`
}
return await directCouchQuery(couchPath)
}
export async function directCouchFind(dbName: string, opts: CouchFindOptions) { export async function directCouchFind(dbName: string, opts: CouchFindOptions) {
const json = await directCouchQuery(`${dbName}/_find`, "POST", opts) const json = await directCouchQuery(`${dbName}/_find`, "POST", opts)
return { rows: json.docs, bookmark: json.bookmark } return { rows: json.docs, bookmark: json.bookmark }

View file

@ -4,7 +4,7 @@ import env from "../environment"
import { SEPARATOR, DocumentType, UNICODE_MAX, ViewName } from "./constants" import { SEPARATOR, DocumentType, UNICODE_MAX, ViewName } from "./constants"
import { getTenantId, getGlobalDB } from "../context" import { getTenantId, getGlobalDB } from "../context"
import { getGlobalDBName } from "./tenancy" import { getGlobalDBName } from "./tenancy"
import { doWithDB, allDbs, directCouchQuery } from "./index" import { doWithDB, allDbs, directCouchQuery, directCouchAllDbs } from "./index"
import { getAppMetadata } from "../cache/appMetadata" import { getAppMetadata } from "../cache/appMetadata"
import { isDevApp, isDevAppID, getProdAppID } from "./conversions" import { isDevApp, isDevAppID, getProdAppID } from "./conversions"
import { APP_PREFIX } from "./constants" import { APP_PREFIX } from "./constants"
@ -188,9 +188,9 @@ export function getRoleParams(roleId = null, otherProps = {}) {
return getDocParams(DocumentType.ROLE, roleId, otherProps) return getDocParams(DocumentType.ROLE, roleId, otherProps)
} }
export function getStartEndKeyURL(base: any, baseKey: any, tenantId = null) { export function getStartEndKeyURL(baseKey: any, tenantId = null) {
const tenancy = tenantId ? `${SEPARATOR}${tenantId}` : "" const tenancy = tenantId ? `${SEPARATOR}${tenantId}` : ""
return `${base}?startkey="${baseKey}${tenancy}"&endkey="${baseKey}${tenancy}${UNICODE_MAX}"` return `startkey="${baseKey}${tenancy}"&endkey="${baseKey}${tenancy}${UNICODE_MAX}"`
} }
/** /**
@ -206,11 +206,10 @@ export async function getAllDbs(opts = { efficient: false }) {
return allDbs() return allDbs()
} }
let dbs: any[] = [] let dbs: any[] = []
async function addDbs(couchPath: string) { async function addDbs(queryString?: string) {
const json = await directCouchQuery(couchPath) const json = await directCouchAllDbs(queryString)
dbs = dbs.concat(json) dbs = dbs.concat(json)
} }
let couchPath = "/_all_dbs"
let tenantId = getTenantId() let tenantId = getTenantId()
if (!env.MULTI_TENANCY || (!efficient && tenantId === DEFAULT_TENANT_ID)) { if (!env.MULTI_TENANCY || (!efficient && tenantId === DEFAULT_TENANT_ID)) {
// just get all DBs when: // just get all DBs when:
@ -218,12 +217,12 @@ export async function getAllDbs(opts = { efficient: false }) {
// - default tenant // - default tenant
// - apps dbs don't contain tenant id // - apps dbs don't contain tenant id
// - non-default tenant dbs are filtered out application side in getAllApps // - non-default tenant dbs are filtered out application side in getAllApps
await addDbs(couchPath) await addDbs()
} else { } else {
// get prod apps // get prod apps
await addDbs(getStartEndKeyURL(couchPath, DocumentType.APP, tenantId)) await addDbs(getStartEndKeyURL(DocumentType.APP, tenantId))
// get dev apps // get dev apps
await addDbs(getStartEndKeyURL(couchPath, DocumentType.APP_DEV, tenantId)) await addDbs(getStartEndKeyURL(DocumentType.APP_DEV, tenantId))
// add global db name // add global db name
dbs.push(getGlobalDBName(tenantId)) dbs.push(getGlobalDBName(tenantId))
} }

View file

@ -1,7 +1,13 @@
import { default as backups } from "./app/backups" import { default as backups } from "./app/backups"
import { default as tables } from "./app/tables" import { default as tables } from "./app/tables"
export default { const toExport = {
backups, backups,
tables, tables,
} }
// default export for TS
export default toExport
// default export for JS
module.exports = toExport