Merge branch 'master' into chore/fix-exporting-rows
This commit is contained in:
commit
cf92da15c6
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||
"version": "2.32.12",
|
||||
"version": "2.32.13",
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
"packages/*",
|
||||
|
|
|
@ -213,17 +213,21 @@ export class DatabaseImpl implements Database {
|
|||
|
||||
async getMultiple<T extends Document>(
|
||||
ids: string[],
|
||||
opts?: { allowMissing?: boolean }
|
||||
opts?: { allowMissing?: boolean; excludeDocs?: boolean }
|
||||
): Promise<T[]> {
|
||||
// get unique
|
||||
ids = [...new Set(ids)]
|
||||
const includeDocs = !opts?.excludeDocs
|
||||
const response = await this.allDocs<T>({
|
||||
keys: ids,
|
||||
include_docs: true,
|
||||
include_docs: includeDocs,
|
||||
})
|
||||
const rowUnavailable = (row: RowResponse<T>) => {
|
||||
// row is deleted - key lookup can return this
|
||||
if (row.doc == null || ("deleted" in row.value && row.value.deleted)) {
|
||||
if (
|
||||
(includeDocs && row.doc == null) ||
|
||||
(row.value && "deleted" in row.value && row.value.deleted)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return row.error === "not_found"
|
||||
|
@ -237,7 +241,7 @@ export class DatabaseImpl implements Database {
|
|||
const missingIds = missing.map(row => row.key).join(", ")
|
||||
throw new Error(`Unable to get documents: ${missingIds}`)
|
||||
}
|
||||
return rows.map(row => row.doc!)
|
||||
return rows.map(row => (includeDocs ? row.doc! : row.value))
|
||||
}
|
||||
|
||||
async remove(idOrDoc: string | Document, rev?: string) {
|
||||
|
|
|
@ -221,9 +221,15 @@ class LinkController {
|
|||
link.id !== row._id && link.fieldName === linkedSchema.name
|
||||
)
|
||||
|
||||
// check all the related rows exist
|
||||
const foundRecords = await this._db.getMultiple(
|
||||
links.map(l => l.id),
|
||||
{ allowMissing: true, excludeDocs: true }
|
||||
)
|
||||
|
||||
// The 1 side of 1:N is already related to something else
|
||||
// You must remove the existing relationship
|
||||
if (links.length > 0) {
|
||||
if (foundRecords.length > 0) {
|
||||
throw new Error(
|
||||
`1:N Relationship Error: Record already linked to another.`
|
||||
)
|
||||
|
|
|
@ -133,7 +133,7 @@ export interface Database {
|
|||
exists(docId: string): Promise<boolean>
|
||||
getMultiple<T extends Document>(
|
||||
ids: string[],
|
||||
opts?: { allowMissing?: boolean }
|
||||
opts?: { allowMissing?: boolean; excludeDocs?: boolean }
|
||||
): Promise<T[]>
|
||||
remove(idOrDoc: Document): Promise<Nano.DocumentDestroyResponse>
|
||||
remove(idOrDoc: string, rev?: string): Promise<Nano.DocumentDestroyResponse>
|
||||
|
|
Loading…
Reference in New Issue