diff --git a/src/repository/couch/TypeRepository.ts b/src/repository/couch/TypeRepository.ts index 95e256e..aba02b1 100644 --- a/src/repository/couch/TypeRepository.ts +++ b/src/repository/couch/TypeRepository.ts @@ -135,26 +135,20 @@ export class TypeRepository implements TypeInterface { public async _get(mode: any, type_id: string, attachment_key: string): Promise { const repo = new Repository() const TypeRepository = repo.getTypeRepository() - const self_type = (type_id ===null) ? undefined : await TypeRepository._self_type(type_id) - const parents = (type_id ===null) ? new Array : Object.values(await TypeRepository._parent(type_id)).reverse() - - + const self_type = (type_id === null) ? undefined : await TypeRepository._self_type(type_id) + const parents = (type_id === null) ? new Array : [null,...Object.values(await TypeRepository._parent(type_id)).reverse()] + // All possible conditions to retreive Tags, ordered greatest-to-least priority. const conditions = [ // Explicit parent-ownership. (Ordered greatest-to-least ancestor.) ...parents.map((pid) => ({ "#parent": pid, type: type_id, key: attachment_key })), // Implicit parent-ownership. (Ordered greatest-to-least ancestor.) ...parents.map((pid) => ({ "#parent": pid, type: self_type, key: attachment_key })), + ...parents.map((pid) => ({ "#parent": pid, type: "*", key: attachment_key })), // Explicit self-ownership. { "#parent": type_id, type: type_id, key: attachment_key }, // Implicit self-ownership. - { "#parent": type_id, type: "me", key: attachment_key }, - { "#parent": null, type: '*', key: attachment_key }, - { "#parent": type_id, type: '*', key: attachment_key }, - { "#parent": null, type: self_type, key: attachment_key }, - { "#parent": null, type: type_id, key: attachment_key }, - { "#parent": type_id, type: "null", key: attachment_key }, - { "#parent": null, type: "null", key: attachment_key }, + { "#parent": type_id, type: "me", key: attachment_key }, ] // Following greatest-to-least priority, see if the Tag exists. We do this because: @@ -178,9 +172,8 @@ export class TypeRepository implements TypeInterface { public async _list(mode: any, type_id: string): Promise { const repo = new Repository() const TypeRepository = repo.getTypeRepository() - const self_type = (type_id ===null) ? undefined : await TypeRepository._self_type(type_id) - const parents = (type_id ===null) ? new Array : Object.values(await TypeRepository._parent(type_id)).reverse() - + const self_type = (type_id === null) ? undefined : await TypeRepository._self_type(type_id) + const parents = (type_id === null) ? new Array : [null,...Object.values(await TypeRepository._parent(type_id)).reverse()] // All possible conditions to retreive Tags, ordered greatest-to-least priority. // Note: We MUST add a "key" selector to force CouchDB to use the right Mango index. const conditions = [ @@ -188,16 +181,12 @@ export class TypeRepository implements TypeInterface { ...parents.map((pid) => ({ "#parent": pid, type: type_id, key: { $gt: null } })), // Implicit parent-ownership. (Ordered greatest-to-least ancestor.) ...parents.map((pid) => ({ "#parent": pid, type: self_type, key: { $gt: null } })), + ...parents.map((pid) => ({ "#parent": pid, type: "*", key: { $gt: null } })), // Explicit self-ownership. { "#parent": type_id, type: type_id, key: { $gt: null } }, // Implicit self-ownership. { "#parent": type_id, type: "me", key: { $gt: null } }, - { "#parent": null, type: '*', key: { $gt: null }}, - { "#parent": type_id, type: '*', key: { $gt: null }}, - { "#parent": null, type:self_type, key: { $gt: null }}, - { "#parent": null, type:type_id, key: { $gt: null }}, - { "#parent": type_id, type:"null", key: { $gt: null }}, - { "#parent": null, type:"null", key: { $gt: null }}, + ] // Following greatest-to-least priority, see if the Tag exists. We do this because: diff --git a/src/repository/mongo/TypeRepository.ts b/src/repository/mongo/TypeRepository.ts index e497723..3a8155a 100644 --- a/src/repository/mongo/TypeRepository.ts +++ b/src/repository/mongo/TypeRepository.ts @@ -112,26 +112,21 @@ export class TypeRepository implements TypeInterface { public async _get(mode: any, type_id: string, attachment_key: string): Promise { const repo = new Repository() const TypeRepository = repo.getTypeRepository() - const self_type = (type_id ===null) ? undefined : await TypeRepository._self_type(type_id) - const parents = (type_id ===null) ? new Array : Object.values(await TypeRepository._parent(type_id)).reverse() + const self_type = (type_id === null) ? undefined : await TypeRepository._self_type(type_id) + const parents = (type_id === null) ? new Array : [null,...Object.values(await TypeRepository._parent(type_id)).reverse()] + // All possible conditions to retreive Tags, ordered greatest-to-least priority. const conditions = [ // Explicit parent-ownership. (Ordered greatest-to-least ancestor.) ...parents.map((pid) => ({ _deleted: false, _parent: pid, type: type_id, key: attachment_key })), // Implicit parent-ownership. (Ordered greatest-to-least ancestor.) ...parents.map((pid) => ({ _deleted: false, _parent: pid, type: self_type, key: attachment_key })), + ...parents.map((pid) => ({ _deleted: false, _parent: pid, type: "*", key: attachment_key })), // Explicit self-ownership. { _deleted: false, _parent: type_id, type: type_id, key: attachment_key }, // Implicit self-ownership. { _deleted: false, _parent: type_id, type: "me", key: attachment_key }, - { _deleted: false, _parent: null, type: '*', key: attachment_key }, - { _deleted: false, _parent: type_id, type: '*', key: attachment_key }, - { _deleted: false, _parent:null , type: self_type, key: attachment_key }, - { _deleted: false, _parent:null , type: type_id, key: attachment_key }, - { _deleted: false, _parent:type_id , type: "null", key: attachment_key }, - { _deleted: false, _parent:null , type: "null", key: attachment_key }, - ] - + ] // Following greatest-to-least priority, see if the Tag exists. We do this because: // (1) Following priority order allows us to avoid searching the database after we find the // Tag we're looking for that applies with the greatest priority. @@ -153,27 +148,21 @@ export class TypeRepository implements TypeInterface { public async _list(mode: any, type_id: string): Promise { const repo = new Repository() const TypeRepository = repo.getTypeRepository() - const self_type = (type_id ===null) ? undefined : await TypeRepository._self_type(type_id) - const parents = (type_id ===null) ? new Array : Object.values(await TypeRepository._parent(type_id)).reverse() + const self_type = (type_id === null) ? undefined : await TypeRepository._self_type(type_id) + const parents = (type_id === null) ? new Array : [null,...Object.values(await TypeRepository._parent(type_id)).reverse()] let conditions: any[] = [] conditions = [ // Explicit parent-ownership. (Ordered greatest-to-least ancestor.) - ...parents.map((pid) => ({ _deleted: false, _parent: pid, type: type_id, key: { $ne: null } })), // Implicit parent-ownership. (Ordered greatest-to-least ancestor.) ...parents.map((pid) => ({ _deleted: false, _parent: pid, type: self_type, key: { $ne: null } })), + ...parents.map((pid) => ({ _deleted: false, _parent: pid, type: "*", key: { $ne: null } })), // Explicit self-ownership. { _deleted: false, _parent: type_id, type: type_id, key: { $ne: null } }, // Implicit self-ownership. { _deleted: false, _parent: type_id, type: "me", key: { $ne: null } }, - { _deleted: false, _parent: null, type: '*', key: { $ne: null }}, - { _deleted: false, _parent: type_id, type: '*', key: { $ne: null }}, - { _deleted: false, _parent: null, type: self_type, key: { $ne: null }}, - { _deleted: false, _parent: null, type: type_id, key: { $ne: null }}, - { _deleted: false, _parent: type_id, type: "null", key: { $ne: null }}, - { _deleted: false, _parent: null, type: "null", key: { $ne: null }}, ] - + // Following greatest-to-least priority, see if the Tag exists. We do this because: // (1) Following priority order allows us to avoid searching the database after we find the // Tag we're looking for that applies with the greatest priority.