Expose a frozen baseSelector for each type.
each document should have a type property
This commit is contained in:
parent
3206345999
commit
234a814112
@ -19,7 +19,7 @@ export const PouchDB = core
|
|||||||
export class TypeSpec {
|
export class TypeSpec {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
this._populateId(props);
|
this._populateId(props);
|
||||||
Object.assign(this, props);
|
Object.assign(this, props, { type: this._prefix });
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSequence(doc) {
|
static getSequence(doc) {
|
||||||
@ -88,6 +88,9 @@ export function PouchORM(PouchDB) {
|
|||||||
PouchDB.registerType = (name, cls, db) => {
|
PouchDB.registerType = (name, cls, db) => {
|
||||||
const prefix = name.toLowerCase();
|
const prefix = name.toLowerCase();
|
||||||
const _db = db || PouchDB(prefix);
|
const _db = db || PouchDB(prefix);
|
||||||
|
const _baseSelector = Object.freeze({
|
||||||
|
_id: { $gt: `${prefix}_0`, $lt: `${prefix}_\ufff0` }
|
||||||
|
});
|
||||||
|
|
||||||
if (!cls.hasOwnProperty('validate')) {
|
if (!cls.hasOwnProperty('validate')) {
|
||||||
warn(`${cls.name} has no validation.`);
|
warn(`${cls.name} has no validation.`);
|
||||||
@ -104,7 +107,7 @@ export function PouchORM(PouchDB) {
|
|||||||
|
|
||||||
const selector = Object.assign(
|
const selector = Object.assign(
|
||||||
isSelector && idOrSelector._deleted ? { _deleted: true } : { _deleted: { exists: false } },
|
isSelector && idOrSelector._deleted ? { _deleted: true } : { _deleted: { exists: false } },
|
||||||
isSelector ? idOrSelector : { _id: { $gt: `${prefix}_0`, $lt: `${prefix}_\ufff0` } }
|
isSelector ? idOrSelector : _baseSelector
|
||||||
);
|
);
|
||||||
if (live) {
|
if (live) {
|
||||||
return LiveArray(_db, idOrSelector, instantiate);
|
return LiveArray(_db, idOrSelector, instantiate);
|
||||||
@ -141,7 +144,8 @@ export function PouchORM(PouchDB) {
|
|||||||
_name: { value: name },
|
_name: { value: name },
|
||||||
_prefix: { value: prefix },
|
_prefix: { value: prefix },
|
||||||
_db: { value: _db },
|
_db: { value: _db },
|
||||||
_cls: { value: cls }
|
_cls: { value: cls },
|
||||||
|
_baseSelector: { value: _baseSelector }
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperties(cls, {
|
Object.defineProperties(cls, {
|
||||||
@ -149,7 +153,8 @@ export function PouchORM(PouchDB) {
|
|||||||
find: { value: find },
|
find: { value: find },
|
||||||
delete: { value: _delete },
|
delete: { value: _delete },
|
||||||
db: { value: _db },
|
db: { value: _db },
|
||||||
name: { value: name }
|
name: { value: name },
|
||||||
|
selector: { value: _baseSelector }
|
||||||
});
|
});
|
||||||
|
|
||||||
return cls;
|
return cls;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user