cozy-pouch-link 57.5.0 → 57.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CozyPouchLink.js +234 -470
- package/dist/CozyPouchLink.spec.js +6 -147
- package/dist/PouchManager.js +43 -8
- package/dist/PouchManager.spec.js +21 -12
- package/dist/__mocks__/@op-engineering/op-sqlite.js +11 -0
- package/dist/db/dbInterface.js +190 -0
- package/dist/db/helpers.js +128 -0
- package/dist/db/pouchdb/getDocs.js +157 -0
- package/dist/db/pouchdb/getDocs.spec.js +63 -0
- package/dist/db/pouchdb/pouchdb.js +264 -0
- package/dist/db/pouchdb/pouchdb.spec.js +151 -0
- package/dist/db/sqlite/sql.js +422 -0
- package/dist/db/sqlite/sql.spec.js +419 -0
- package/dist/db/sqlite/sqliteDb.js +41 -0
- package/dist/db/sqlite/sqliteDb.native.js +317 -0
- package/dist/errors.js +17 -2
- package/dist/helpers.js +21 -147
- package/dist/helpers.spec.js +1 -98
- package/dist/index.js +9 -1
- package/dist/jsonapi.js +57 -21
- package/dist/jsonapi.spec.js +105 -32
- package/dist/mango.js +146 -3
- package/dist/migrations/pouchdb.js +32 -0
- package/dist/replicateOnce.js +25 -23
- package/dist/types.js +5 -0
- package/dist/utils.js +33 -3
- package/package.json +5 -3
- package/types/CozyPouchLink.d.ts +6 -63
- package/types/PouchManager.d.ts +6 -1
- package/types/__mocks__/@op-engineering/op-sqlite.d.ts +1 -0
- package/types/db/dbInterface.d.ts +117 -0
- package/types/db/helpers.d.ts +4 -0
- package/types/db/pouchdb/getDocs.d.ts +18 -0
- package/types/db/pouchdb/pouchdb.d.ts +8 -0
- package/types/db/sqlite/sql.d.ts +45 -0
- package/types/db/sqlite/sqliteDb.d.ts +4 -0
- package/types/db/sqlite/sqliteDb.native.d.ts +7 -0
- package/types/errors.d.ts +2 -0
- package/types/helpers.d.ts +1 -4
- package/types/index.d.ts +1 -0
- package/types/jsonapi.d.ts +4 -2
- package/types/mango.d.ts +19 -1
- package/types/migrations/pouchdb.d.ts +1 -0
- package/types/types.d.ts +2 -0
- package/types/utils.d.ts +3 -0
|
@@ -6,7 +6,8 @@ jest.mock('./helpers', () => ({
|
|
|
6
6
|
allDocs: jest.fn(),
|
|
7
7
|
normalizeFindSelector: jest.requireActual('./helpers').default
|
|
8
8
|
.normalizeFindSelector,
|
|
9
|
-
withoutDesignDocuments: jest.fn()
|
|
9
|
+
withoutDesignDocuments: jest.fn(),
|
|
10
|
+
isAdapterBugged: jest.fn()
|
|
10
11
|
}))
|
|
11
12
|
|
|
12
13
|
import CozyPouchLink from '.'
|
|
@@ -309,12 +310,9 @@ describe('CozyPouchLink', () => {
|
|
|
309
310
|
.indexFields(['done', 'label'])
|
|
310
311
|
.sortBy([{ done: 'asc' }, { label: 'asc' }])
|
|
311
312
|
.select(['label', 'done'])
|
|
312
|
-
await link.request(query)
|
|
313
|
-
expect(
|
|
314
|
-
expect.
|
|
315
|
-
expect.objectContaining({
|
|
316
|
-
fields: ['label', 'done', '_id', '_rev']
|
|
317
|
-
})
|
|
313
|
+
const res = await link.request(query)
|
|
314
|
+
expect(Object.keys(res.data[0])).toEqual(
|
|
315
|
+
expect.arrayContaining(['label', 'done', '_id', '_rev'])
|
|
318
316
|
)
|
|
319
317
|
})
|
|
320
318
|
})
|
|
@@ -455,10 +453,7 @@ describe('CozyPouchLink', () => {
|
|
|
455
453
|
_type: 'io.cozy.todos',
|
|
456
454
|
done: false,
|
|
457
455
|
id: '1',
|
|
458
|
-
label: 'Buy bread'
|
|
459
|
-
relationships: {
|
|
460
|
-
referenced_by: undefined
|
|
461
|
-
}
|
|
456
|
+
label: 'Buy bread'
|
|
462
457
|
}
|
|
463
458
|
]
|
|
464
459
|
})
|
|
@@ -552,142 +547,6 @@ describe('CozyPouchLink', () => {
|
|
|
552
547
|
})
|
|
553
548
|
})
|
|
554
549
|
|
|
555
|
-
describe('index creation', () => {
|
|
556
|
-
let spy
|
|
557
|
-
beforeEach(() => {
|
|
558
|
-
allDocs.mockReturnValue({ docs: [] })
|
|
559
|
-
withoutDesignDocuments.mockReturnValue({ docs: [] })
|
|
560
|
-
find.mockReturnValue({ docs: [] })
|
|
561
|
-
})
|
|
562
|
-
afterEach(() => {
|
|
563
|
-
spy.mockRestore()
|
|
564
|
-
})
|
|
565
|
-
|
|
566
|
-
it('uses the default index, the one from the sort', async () => {
|
|
567
|
-
spy = jest.spyOn(PouchDB.prototype, 'createIndex')
|
|
568
|
-
await setup()
|
|
569
|
-
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
570
|
-
const query = Q(TODO_DOCTYPE)
|
|
571
|
-
.where({})
|
|
572
|
-
.sortBy([{ name: 'asc' }])
|
|
573
|
-
await link.request(query)
|
|
574
|
-
expect(spy).toHaveBeenCalledWith({
|
|
575
|
-
index: {
|
|
576
|
-
ddoc: 'by_name',
|
|
577
|
-
fields: ['name'],
|
|
578
|
-
indexName: 'by_name',
|
|
579
|
-
partial_filter_selector: undefined
|
|
580
|
-
}
|
|
581
|
-
})
|
|
582
|
-
})
|
|
583
|
-
|
|
584
|
-
it('uses indexFields if provided', async () => {
|
|
585
|
-
spy = jest.spyOn(PouchDB.prototype, 'createIndex').mockReturnValue({})
|
|
586
|
-
await setup()
|
|
587
|
-
await link.ensureIndex(TODO_DOCTYPE, {
|
|
588
|
-
indexedFields: ['myIndex']
|
|
589
|
-
})
|
|
590
|
-
expect(spy).toHaveBeenCalled()
|
|
591
|
-
expect(spy).toHaveBeenCalledWith({
|
|
592
|
-
index: {
|
|
593
|
-
ddoc: 'by_myIndex',
|
|
594
|
-
fields: ['myIndex'],
|
|
595
|
-
indexName: 'by_myIndex',
|
|
596
|
-
partial_filter_selector: undefined
|
|
597
|
-
}
|
|
598
|
-
})
|
|
599
|
-
})
|
|
600
|
-
|
|
601
|
-
it('should handle partial filters', async () => {
|
|
602
|
-
spy = jest.spyOn(PouchDB.prototype, 'createIndex').mockReturnValue({})
|
|
603
|
-
await setup()
|
|
604
|
-
await link.ensureIndex(TODO_DOCTYPE, {
|
|
605
|
-
indexedFields: ['myIndex'],
|
|
606
|
-
partialFilter: { SOME_FIELD: { $exists: true } }
|
|
607
|
-
})
|
|
608
|
-
expect(spy).toHaveBeenCalled()
|
|
609
|
-
expect(spy).toHaveBeenCalledWith({
|
|
610
|
-
index: {
|
|
611
|
-
ddoc: 'by_myIndex_and_SOME_FIELD_filter_(SOME_FIELD_$exists_true)',
|
|
612
|
-
fields: ['myIndex', 'SOME_FIELD'],
|
|
613
|
-
indexName:
|
|
614
|
-
'by_myIndex_and_SOME_FIELD_filter_(SOME_FIELD_$exists_true)',
|
|
615
|
-
partial_filter_selector: {
|
|
616
|
-
SOME_FIELD: {
|
|
617
|
-
$exists: true
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
})
|
|
622
|
-
})
|
|
623
|
-
|
|
624
|
-
it('should exclude $and and $or operators from fields with partialIndex', async () => {
|
|
625
|
-
spy = jest.spyOn(PouchDB.prototype, 'createIndex').mockReturnValue({})
|
|
626
|
-
await setup()
|
|
627
|
-
await link.ensureIndex(TODO_DOCTYPE, {
|
|
628
|
-
indexedFields: ['myIndex'],
|
|
629
|
-
partialFilter: {
|
|
630
|
-
$and: [
|
|
631
|
-
{ SOME_FIELD: { $exists: true } },
|
|
632
|
-
{ SOME_FIELD: { $gt: null } }
|
|
633
|
-
],
|
|
634
|
-
$or: [{ SOME_FIELD: { $eq: '1' } }, { SOME_FIELD: { $eq: '2' } }]
|
|
635
|
-
}
|
|
636
|
-
})
|
|
637
|
-
expect(spy).toHaveBeenCalled()
|
|
638
|
-
expect(spy).toHaveBeenCalledWith({
|
|
639
|
-
index: {
|
|
640
|
-
ddoc:
|
|
641
|
-
'by_myIndex_filter_((SOME_FIELD_$exists_true)_$and_(SOME_FIELD_$gt_null))_and_((SOME_FIELD_$eq_1)_$or_(SOME_FIELD_$eq_2))',
|
|
642
|
-
fields: ['myIndex'],
|
|
643
|
-
indexName:
|
|
644
|
-
'by_myIndex_filter_((SOME_FIELD_$exists_true)_$and_(SOME_FIELD_$gt_null))_and_((SOME_FIELD_$eq_1)_$or_(SOME_FIELD_$eq_2))',
|
|
645
|
-
partial_filter_selector: {
|
|
646
|
-
$and: [
|
|
647
|
-
{ SOME_FIELD: { $exists: true } },
|
|
648
|
-
{ SOME_FIELD: { $gt: null } }
|
|
649
|
-
],
|
|
650
|
-
$or: [{ SOME_FIELD: { $eq: '1' } }, { SOME_FIELD: { $eq: '2' } }]
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
})
|
|
654
|
-
})
|
|
655
|
-
|
|
656
|
-
it('uses the specified index', async () => {
|
|
657
|
-
let spyIndex = jest
|
|
658
|
-
.spyOn(CozyPouchLink.prototype, 'ensureIndex')
|
|
659
|
-
.mockReturnValue({ id: 'design/myIndex2' })
|
|
660
|
-
|
|
661
|
-
await setup()
|
|
662
|
-
const db = link.getPouch(TODO_DOCTYPE)
|
|
663
|
-
await link.executeQuery({
|
|
664
|
-
doctype: TODO_DOCTYPE,
|
|
665
|
-
indexedFields: ['myIndex2'],
|
|
666
|
-
selector: {}
|
|
667
|
-
})
|
|
668
|
-
const params = {
|
|
669
|
-
sort: undefined,
|
|
670
|
-
selector: {
|
|
671
|
-
myIndex2: {
|
|
672
|
-
$gt: null
|
|
673
|
-
}
|
|
674
|
-
},
|
|
675
|
-
fields: undefined,
|
|
676
|
-
limit: undefined,
|
|
677
|
-
partialFilter: undefined,
|
|
678
|
-
skip: undefined
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
expect(spyIndex).toHaveBeenCalledWith('io.cozy.todos', {
|
|
682
|
-
...params,
|
|
683
|
-
indexedFields: ['myIndex2']
|
|
684
|
-
})
|
|
685
|
-
params.use_index = 'design/myIndex2'
|
|
686
|
-
expect(find).toHaveBeenCalledWith(db, params)
|
|
687
|
-
spyIndex.mockRestore()
|
|
688
|
-
})
|
|
689
|
-
})
|
|
690
|
-
|
|
691
550
|
describe('deleteDocument', () => {
|
|
692
551
|
it('should add _rev and _deleted prop to a deleted document', async () => {
|
|
693
552
|
await setup()
|
package/dist/PouchManager.js
CHANGED
|
@@ -35,6 +35,10 @@ var _replicateOnce3 = require("./replicateOnce");
|
|
|
35
35
|
|
|
36
36
|
var _utils = require("./utils");
|
|
37
37
|
|
|
38
|
+
var _pouchdb = require("./migrations/pouchdb");
|
|
39
|
+
|
|
40
|
+
var _pouchdb2 = _interopRequireDefault(require("./db/pouchdb/pouchdb"));
|
|
41
|
+
|
|
38
42
|
var DEFAULT_DELAY = 30 * 1000; // See view_update_changes_batch_size in https://pouchdb.com/api.html#create_database
|
|
39
43
|
// PouchDB default is 50, which badly hurt performances for large databases
|
|
40
44
|
|
|
@@ -64,9 +68,12 @@ var PouchManager = /*#__PURE__*/function () {
|
|
|
64
68
|
this.options = options;
|
|
65
69
|
this.doctypes = doctypes;
|
|
66
70
|
this.storage = new _localStorage.PouchLocalStorage(((_options$platform = options.platform) === null || _options$platform === void 0 ? void 0 : _options$platform.storage) || _platformWeb.platformWeb.storage);
|
|
71
|
+
this.queryEngine = options.queryEngine || _pouchdb2.default;
|
|
72
|
+
this.client = options.client;
|
|
67
73
|
this.PouchDB = ((_options$platform2 = options.platform) === null || _options$platform2 === void 0 ? void 0 : _options$platform2.pouchAdapter) || _platformWeb.platformWeb.pouchAdapter;
|
|
68
74
|
this.isOnline = ((_options$platform3 = options.platform) === null || _options$platform3 === void 0 ? void 0 : _options$platform3.isOnline) || _platformWeb.platformWeb.isOnline;
|
|
69
75
|
this.events = ((_options$platform4 = options.platform) === null || _options$platform4 === void 0 ? void 0 : _options$platform4.events) || _platformWeb.platformWeb.events;
|
|
76
|
+
this.dbQueryEngines = new Map();
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
(0, _createClass2.default)(PouchManager, [{
|
|
@@ -91,19 +98,27 @@ var PouchManager = /*#__PURE__*/function () {
|
|
|
91
98
|
return _this.PouchDB.plugin(plugin);
|
|
92
99
|
});
|
|
93
100
|
this.pouches = (0, _fromPairs.default)(this.doctypes.map(function (doctype) {
|
|
94
|
-
|
|
101
|
+
var dbName = (0, _utils.getDatabaseName)(_this.options.prefix, doctype);
|
|
102
|
+
var pouch = new _this.PouchDB((0, _utils.getDatabaseName)(_this.options.prefix, doctype), pouchOptions);
|
|
103
|
+
return [dbName, pouch];
|
|
95
104
|
}));
|
|
105
|
+
Object.keys(this.pouches).forEach(function (dbName) {
|
|
106
|
+
// Set query engine for all databases
|
|
107
|
+
var doctype = (0, _utils.getDoctypeFromDatabaseName)(dbName);
|
|
108
|
+
|
|
109
|
+
_this.setQueryEngine(dbName, doctype);
|
|
110
|
+
});
|
|
96
111
|
/** @type {Record<string, import('./types').SyncInfo>} - Stores synchronization info per doctype */
|
|
97
112
|
|
|
98
|
-
_context.next =
|
|
113
|
+
_context.next = 8;
|
|
99
114
|
return this.storage.getPersistedSyncedDoctypes();
|
|
100
115
|
|
|
101
|
-
case
|
|
116
|
+
case 8:
|
|
102
117
|
this.syncedDoctypes = _context.sent;
|
|
103
|
-
_context.next =
|
|
118
|
+
_context.next = 11;
|
|
104
119
|
return this.storage.getPersistedWarmedUpQueries();
|
|
105
120
|
|
|
106
|
-
case
|
|
121
|
+
case 11:
|
|
107
122
|
this.warmedUpQueries = _context.sent;
|
|
108
123
|
this.getReplicationURL = this.options.getReplicationURL;
|
|
109
124
|
this.doctypesReplicationOptions = this.options.doctypesReplicationOptions || {};
|
|
@@ -118,8 +133,9 @@ var PouchManager = /*#__PURE__*/function () {
|
|
|
118
133
|
/** @type {import('./types').CancelablePromise[]} - Stores replication promises */
|
|
119
134
|
|
|
120
135
|
this.replications = undefined;
|
|
136
|
+
(0, _pouchdb.destroyOldDatabases)();
|
|
121
137
|
|
|
122
|
-
case
|
|
138
|
+
case 22:
|
|
123
139
|
case "end":
|
|
124
140
|
return _context.stop();
|
|
125
141
|
}
|
|
@@ -421,8 +437,27 @@ var PouchManager = /*#__PURE__*/function () {
|
|
|
421
437
|
}
|
|
422
438
|
}, {
|
|
423
439
|
key: "getPouch",
|
|
424
|
-
value: function getPouch(
|
|
425
|
-
return this.pouches[
|
|
440
|
+
value: function getPouch(dbName) {
|
|
441
|
+
return this.pouches[dbName];
|
|
442
|
+
}
|
|
443
|
+
}, {
|
|
444
|
+
key: "setQueryEngine",
|
|
445
|
+
value: function setQueryEngine(name, doctype) {
|
|
446
|
+
var engine = new this.queryEngine(this, doctype);
|
|
447
|
+
engine.openDB(name);
|
|
448
|
+
this.dbQueryEngines.set(name, engine);
|
|
449
|
+
return engine;
|
|
450
|
+
}
|
|
451
|
+
}, {
|
|
452
|
+
key: "getQueryEngine",
|
|
453
|
+
value: function getQueryEngine(name, doctype) {
|
|
454
|
+
var engine = this.dbQueryEngines.get(name);
|
|
455
|
+
|
|
456
|
+
if (!engine) {
|
|
457
|
+
engine = this.setQueryEngine(name, doctype);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return engine;
|
|
426
461
|
}
|
|
427
462
|
/**
|
|
428
463
|
* Update the Sync info for the specifed doctype
|
|
@@ -60,6 +60,9 @@ const query2 = () => ({
|
|
|
60
60
|
as: 'query2'
|
|
61
61
|
}
|
|
62
62
|
})
|
|
63
|
+
|
|
64
|
+
const dbName = 'cozy.tools__doctype__io.cozy.todos'
|
|
65
|
+
|
|
63
66
|
describe('PouchManager', () => {
|
|
64
67
|
let manager,
|
|
65
68
|
managerOptions,
|
|
@@ -76,7 +79,7 @@ describe('PouchManager', () => {
|
|
|
76
79
|
}
|
|
77
80
|
manager = new PouchManager(['io.cozy.todos'], managerOptions)
|
|
78
81
|
await manager.init()
|
|
79
|
-
const pouch = manager.getPouch(
|
|
82
|
+
const pouch = manager.getPouch(dbName)
|
|
80
83
|
const replication = mocks.pouchReplication({
|
|
81
84
|
direction: 'pull',
|
|
82
85
|
change: {
|
|
@@ -106,7 +109,7 @@ describe('PouchManager', () => {
|
|
|
106
109
|
manager.startReplicationLoop()
|
|
107
110
|
await sleep(1000)
|
|
108
111
|
expect(fetchRemoteInstance).toHaveBeenCalledTimes(1)
|
|
109
|
-
const pouch = manager.getPouch(
|
|
112
|
+
const pouch = manager.getPouch(dbName)
|
|
110
113
|
expect(pouch.info).toHaveBeenCalledTimes(1)
|
|
111
114
|
expect(pouch.sync).toHaveBeenCalled()
|
|
112
115
|
})
|
|
@@ -114,19 +117,19 @@ describe('PouchManager', () => {
|
|
|
114
117
|
it('should call info() on all pouches before starting replication', async () => {
|
|
115
118
|
manager.startReplicationLoop()
|
|
116
119
|
await sleep(1)
|
|
117
|
-
expect(manager.getPouch(
|
|
120
|
+
expect(manager.getPouch(dbName).info).toHaveBeenCalled()
|
|
118
121
|
manager.stopReplicationLoop()
|
|
119
122
|
manager.startReplicationLoop()
|
|
120
123
|
await sleep(1)
|
|
121
124
|
|
|
122
125
|
// Database existence check should only occur once
|
|
123
|
-
expect(manager.getPouch(
|
|
126
|
+
expect(manager.getPouch(dbName).info).toHaveBeenCalledTimes(1)
|
|
124
127
|
})
|
|
125
128
|
|
|
126
129
|
it('should periodically call sync', async () => {
|
|
127
130
|
manager.startReplicationLoop()
|
|
128
131
|
await sleep(1000)
|
|
129
|
-
const pouch = manager.getPouch(
|
|
132
|
+
const pouch = manager.getPouch(dbName)
|
|
130
133
|
expect(pouch.sync.mock.calls.length).toBeGreaterThan(5)
|
|
131
134
|
})
|
|
132
135
|
|
|
@@ -138,8 +141,10 @@ describe('PouchManager', () => {
|
|
|
138
141
|
}
|
|
139
142
|
})
|
|
140
143
|
await manager.init()
|
|
141
|
-
const normalPouch = manager.getPouch(
|
|
142
|
-
const readOnlyPouch = manager.getPouch(
|
|
144
|
+
const normalPouch = manager.getPouch(dbName)
|
|
145
|
+
const readOnlyPouch = manager.getPouch(
|
|
146
|
+
'cozy.tools__doctype__io.cozy.readonly'
|
|
147
|
+
)
|
|
143
148
|
readOnlyPouch.replicate = {}
|
|
144
149
|
readOnlyPouch.replicate.from = jest.fn()
|
|
145
150
|
manager.startReplicationLoop()
|
|
@@ -161,11 +166,15 @@ describe('PouchManager', () => {
|
|
|
161
166
|
}
|
|
162
167
|
)
|
|
163
168
|
await manager.init()
|
|
164
|
-
const normalPouch = manager.getPouch(
|
|
165
|
-
const readOnlyPouch = manager.getPouch(
|
|
169
|
+
const normalPouch = manager.getPouch(dbName)
|
|
170
|
+
const readOnlyPouch = manager.getPouch(
|
|
171
|
+
'cozy.tools__doctype__io.cozy.readonly'
|
|
172
|
+
)
|
|
166
173
|
readOnlyPouch.replicate = {}
|
|
167
174
|
readOnlyPouch.replicate.from = jest.fn()
|
|
168
|
-
const writeOnlyPouch = manager.getPouch(
|
|
175
|
+
const writeOnlyPouch = manager.getPouch(
|
|
176
|
+
'cozy.tools__doctype__io.cozy.writeonly'
|
|
177
|
+
)
|
|
169
178
|
writeOnlyPouch.replicate = {}
|
|
170
179
|
writeOnlyPouch.replicate.to = jest.fn()
|
|
171
180
|
manager.updateSyncInfo('io.cozy.todos')
|
|
@@ -226,7 +235,7 @@ describe('PouchManager', () => {
|
|
|
226
235
|
manager.updateSyncInfo('io.cozy.todos')
|
|
227
236
|
await manager.replicateOnce()
|
|
228
237
|
expect(onSync).toHaveBeenCalledWith({
|
|
229
|
-
'
|
|
238
|
+
'cozy.tools__doctype__io.cozy.todos': [
|
|
230
239
|
{
|
|
231
240
|
_id: '1',
|
|
232
241
|
name: 'Make replication work'
|
|
@@ -252,7 +261,7 @@ describe('PouchManager', () => {
|
|
|
252
261
|
const manager = new PouchManager(['io.cozy.todos'], options)
|
|
253
262
|
await manager.init()
|
|
254
263
|
expect(PouchDB).toHaveBeenCalledWith(
|
|
255
|
-
'cozy.
|
|
264
|
+
'cozy.tools__doctype__io.cozy.todos',
|
|
256
265
|
pouchOptions
|
|
257
266
|
)
|
|
258
267
|
})
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
|
|
14
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
+
|
|
16
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {object} FindParams
|
|
20
|
+
* @property {object} selector - The mango selector
|
|
21
|
+
* @property {object} partialFilter - Following the mango selector syntax, used to filter out documents at indexing time
|
|
22
|
+
* @property {Array} sort - The mango sort
|
|
23
|
+
* @property {string} doctype - The doctype
|
|
24
|
+
* @property {Array<string>} indexedFields - Array of indexed field name
|
|
25
|
+
* @property {number} limit - Maximum number of documents to return
|
|
26
|
+
* @property {number} skip - Number of documents to skip
|
|
27
|
+
* @property {boolean} recreateIndex - Whether or not an existing index should be recreated
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {object} AllDocsParams
|
|
32
|
+
* @property {number} limit - Maximum number of documents to return
|
|
33
|
+
* @property {number} skip - Number of documents to skip
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {object} QueryResponse
|
|
38
|
+
* @property {Array<object>} data - The documents retrieved by the query
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {object} QueryResponseSingleDoc
|
|
43
|
+
* @property {object} data - The document retrieved by the query
|
|
44
|
+
*/
|
|
45
|
+
var DatabaseQueryEngine = /*#__PURE__*/function () {
|
|
46
|
+
function DatabaseQueryEngine() {
|
|
47
|
+
(0, _classCallCheck2.default)(this, DatabaseQueryEngine);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
(0, _createClass2.default)(DatabaseQueryEngine, [{
|
|
51
|
+
key: "openDB",
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Open the database
|
|
55
|
+
*
|
|
56
|
+
* @param {string} dbName - The database name
|
|
57
|
+
*/
|
|
58
|
+
value: function openDB(dbName) {
|
|
59
|
+
throw new Error('method non implemented');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Find docs with filtered query
|
|
63
|
+
*
|
|
64
|
+
* @param {FindParams} options - The find options
|
|
65
|
+
* @returns {Promise<QueryResponse>} The found docs
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
}, {
|
|
69
|
+
key: "find",
|
|
70
|
+
value: function () {
|
|
71
|
+
var _find = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(options) {
|
|
72
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
73
|
+
while (1) {
|
|
74
|
+
switch (_context.prev = _context.next) {
|
|
75
|
+
case 0:
|
|
76
|
+
throw new Error('method not implemented');
|
|
77
|
+
|
|
78
|
+
case 1:
|
|
79
|
+
case "end":
|
|
80
|
+
return _context.stop();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}, _callee);
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
function find(_x) {
|
|
87
|
+
return _find.apply(this, arguments);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return find;
|
|
91
|
+
}()
|
|
92
|
+
/**
|
|
93
|
+
* Get all docs
|
|
94
|
+
*
|
|
95
|
+
* @param {AllDocsParams} options - The all docs options
|
|
96
|
+
* @returns {Promise<QueryResponse>} The found docs
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
}, {
|
|
100
|
+
key: "allDocs",
|
|
101
|
+
value: function () {
|
|
102
|
+
var _allDocs = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(options) {
|
|
103
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
104
|
+
while (1) {
|
|
105
|
+
switch (_context2.prev = _context2.next) {
|
|
106
|
+
case 0:
|
|
107
|
+
throw new Error('method not implemented');
|
|
108
|
+
|
|
109
|
+
case 1:
|
|
110
|
+
case "end":
|
|
111
|
+
return _context2.stop();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}, _callee2);
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
function allDocs(_x2) {
|
|
118
|
+
return _allDocs.apply(this, arguments);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return allDocs;
|
|
122
|
+
}()
|
|
123
|
+
/**
|
|
124
|
+
* Get a single doc by its id
|
|
125
|
+
*
|
|
126
|
+
* @param {string} id - id of the document to get
|
|
127
|
+
* @returns {Promise<QueryResponseSingleDoc>} The found docs
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
}, {
|
|
131
|
+
key: "getById",
|
|
132
|
+
value: function () {
|
|
133
|
+
var _getById = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(id) {
|
|
134
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
135
|
+
while (1) {
|
|
136
|
+
switch (_context3.prev = _context3.next) {
|
|
137
|
+
case 0:
|
|
138
|
+
throw new Error('method not implemented');
|
|
139
|
+
|
|
140
|
+
case 1:
|
|
141
|
+
case "end":
|
|
142
|
+
return _context3.stop();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}, _callee3);
|
|
146
|
+
}));
|
|
147
|
+
|
|
148
|
+
function getById(_x3) {
|
|
149
|
+
return _getById.apply(this, arguments);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return getById;
|
|
153
|
+
}()
|
|
154
|
+
/**
|
|
155
|
+
* Get several docs by their ids
|
|
156
|
+
*
|
|
157
|
+
* @param {Array<string>} ids - ids of the documents to get
|
|
158
|
+
* @returns {Promise<QueryResponse>} The found docs
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
}, {
|
|
162
|
+
key: "getByIds",
|
|
163
|
+
value: function () {
|
|
164
|
+
var _getByIds = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(ids) {
|
|
165
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
166
|
+
while (1) {
|
|
167
|
+
switch (_context4.prev = _context4.next) {
|
|
168
|
+
case 0:
|
|
169
|
+
throw new Error('method not implemented');
|
|
170
|
+
|
|
171
|
+
case 1:
|
|
172
|
+
case "end":
|
|
173
|
+
return _context4.stop();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}, _callee4);
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
function getByIds(_x4) {
|
|
180
|
+
return _getByIds.apply(this, arguments);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return getByIds;
|
|
184
|
+
}()
|
|
185
|
+
}]);
|
|
186
|
+
return DatabaseQueryEngine;
|
|
187
|
+
}();
|
|
188
|
+
|
|
189
|
+
var _default = DatabaseQueryEngine;
|
|
190
|
+
exports.default = _default;
|