diff --git a/packages/gallery/src/data/album.js b/packages/gallery/src/data/album.js index bdc5c0f..aa1d5d9 100644 --- a/packages/gallery/src/data/album.js +++ b/packages/gallery/src/data/album.js @@ -14,15 +14,15 @@ class AlbumSpec extends TypeSpec { async findImages(live = false) { return await ImageType.find( - Object.assign({ [`$links.${this._id}`]: { $exists: true } }, ImageType.selector), + Object.assign({ [`$$links.${this._id}`]: { $exists: true } }, ImageType.selector), live ); } async addImage(image) { - if (!image.$links[this._id]) { + if (!image.$$links[this._id]) { await image.update({ - $links: { + $$links: { [this._id]: { sequence: this.count } @@ -35,8 +35,8 @@ class AlbumSpec extends TypeSpec { } async removeImage(image) { - if (image.$links[this._id]) { - delete image.$links[this._id]; + if (image.$$links[this._id]) { + delete image.$$links[this._id]; this.count -= 1; await image.save(); await this.save(); @@ -75,7 +75,7 @@ ImageType.subscribe((id, deleted, doc) => { return; } - Object.keys(doc.$links) + Object.keys(doc.$$links) .filter(k => k.startsWith(AlbumType.prefix)) .forEach(async albumId => { const album = await AlbumType.find(albumId); diff --git a/packages/pouchorm/src/type.js b/packages/pouchorm/src/type.js index 377ca26..4ae5923 100644 --- a/packages/pouchorm/src/type.js +++ b/packages/pouchorm/src/type.js @@ -3,13 +3,17 @@ import { pouchDocHash, deepAssign } from './utils.js'; export class TypeSpec { constructor(props) { this._populateId(props); - Object.assign(this, { $links: {} }, props, { type: this._prefix }); + Object.assign(this, { $$links: {} }, props, { $$type: this._prefix }); } static getUniqueID(doc) { throw 'NotImplemented'; } + static isType(doc) { + return doc && doc.$$type === TypeSpec.prefix; + } + static validate(doc) {} instantiate(doc) {