cozy-pouch-link 57.4.0 → 57.6.0
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 +221 -469
- 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 +106 -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 +418 -0
- package/dist/db/sqlite/sql.spec.js +363 -0
- package/dist/db/sqlite/sqliteDb.js +319 -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 +49 -10
- 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 +4 -3
- package/types/CozyPouchLink.d.ts +4 -60
- 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 +3 -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 +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 +2 -0
- 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
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export default DatabaseQueryEngine;
|
|
2
|
+
export type FindParams = {
|
|
3
|
+
/**
|
|
4
|
+
* - The mango selector
|
|
5
|
+
*/
|
|
6
|
+
selector: object;
|
|
7
|
+
/**
|
|
8
|
+
* - Following the mango selector syntax, used to filter out documents at indexing time
|
|
9
|
+
*/
|
|
10
|
+
partialFilter: object;
|
|
11
|
+
/**
|
|
12
|
+
* - The mango sort
|
|
13
|
+
*/
|
|
14
|
+
sort: any[];
|
|
15
|
+
/**
|
|
16
|
+
* - The doctype
|
|
17
|
+
*/
|
|
18
|
+
doctype: string;
|
|
19
|
+
/**
|
|
20
|
+
* - Array of indexed field name
|
|
21
|
+
*/
|
|
22
|
+
indexedFields: Array<string>;
|
|
23
|
+
/**
|
|
24
|
+
* - Maximum number of documents to return
|
|
25
|
+
*/
|
|
26
|
+
limit: number;
|
|
27
|
+
/**
|
|
28
|
+
* - Number of documents to skip
|
|
29
|
+
*/
|
|
30
|
+
skip: number;
|
|
31
|
+
/**
|
|
32
|
+
* - Whether or not an existing index should be recreated
|
|
33
|
+
*/
|
|
34
|
+
recreateIndex: boolean;
|
|
35
|
+
};
|
|
36
|
+
export type AllDocsParams = {
|
|
37
|
+
/**
|
|
38
|
+
* - Maximum number of documents to return
|
|
39
|
+
*/
|
|
40
|
+
limit: number;
|
|
41
|
+
/**
|
|
42
|
+
* - Number of documents to skip
|
|
43
|
+
*/
|
|
44
|
+
skip: number;
|
|
45
|
+
};
|
|
46
|
+
export type QueryResponse = {
|
|
47
|
+
/**
|
|
48
|
+
* - The documents retrieved by the query
|
|
49
|
+
*/
|
|
50
|
+
data: Array<object>;
|
|
51
|
+
};
|
|
52
|
+
export type QueryResponseSingleDoc = {
|
|
53
|
+
/**
|
|
54
|
+
* - The document retrieved by the query
|
|
55
|
+
*/
|
|
56
|
+
data: object;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {object} FindParams
|
|
60
|
+
* @property {object} selector - The mango selector
|
|
61
|
+
* @property {object} partialFilter - Following the mango selector syntax, used to filter out documents at indexing time
|
|
62
|
+
* @property {Array} sort - The mango sort
|
|
63
|
+
* @property {string} doctype - The doctype
|
|
64
|
+
* @property {Array<string>} indexedFields - Array of indexed field name
|
|
65
|
+
* @property {number} limit - Maximum number of documents to return
|
|
66
|
+
* @property {number} skip - Number of documents to skip
|
|
67
|
+
* @property {boolean} recreateIndex - Whether or not an existing index should be recreated
|
|
68
|
+
*/
|
|
69
|
+
/**
|
|
70
|
+
* @typedef {object} AllDocsParams
|
|
71
|
+
* @property {number} limit - Maximum number of documents to return
|
|
72
|
+
* @property {number} skip - Number of documents to skip
|
|
73
|
+
*/
|
|
74
|
+
/**
|
|
75
|
+
* @typedef {object} QueryResponse
|
|
76
|
+
* @property {Array<object>} data - The documents retrieved by the query
|
|
77
|
+
*/
|
|
78
|
+
/**
|
|
79
|
+
* @typedef {object} QueryResponseSingleDoc
|
|
80
|
+
* @property {object} data - The document retrieved by the query
|
|
81
|
+
*/
|
|
82
|
+
declare class DatabaseQueryEngine {
|
|
83
|
+
/**
|
|
84
|
+
* Open the database
|
|
85
|
+
*
|
|
86
|
+
* @param {string} dbName - The database name
|
|
87
|
+
*/
|
|
88
|
+
openDB(dbName: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* Find docs with filtered query
|
|
91
|
+
*
|
|
92
|
+
* @param {FindParams} options - The find options
|
|
93
|
+
* @returns {Promise<QueryResponse>} The found docs
|
|
94
|
+
*/
|
|
95
|
+
find(options: FindParams): Promise<QueryResponse>;
|
|
96
|
+
/**
|
|
97
|
+
* Get all docs
|
|
98
|
+
*
|
|
99
|
+
* @param {AllDocsParams} options - The all docs options
|
|
100
|
+
* @returns {Promise<QueryResponse>} The found docs
|
|
101
|
+
*/
|
|
102
|
+
allDocs(options: AllDocsParams): Promise<QueryResponse>;
|
|
103
|
+
/**
|
|
104
|
+
* Get a single doc by its id
|
|
105
|
+
*
|
|
106
|
+
* @param {string} id - id of the document to get
|
|
107
|
+
* @returns {Promise<QueryResponseSingleDoc>} The found docs
|
|
108
|
+
*/
|
|
109
|
+
getById(id: string): Promise<QueryResponseSingleDoc>;
|
|
110
|
+
/**
|
|
111
|
+
* Get several docs by their ids
|
|
112
|
+
*
|
|
113
|
+
* @param {Array<string>} ids - ids of the documents to get
|
|
114
|
+
* @returns {Promise<QueryResponse>} The found docs
|
|
115
|
+
*/
|
|
116
|
+
getByIds(ids: Array<string>): Promise<QueryResponse>;
|
|
117
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export function getExistingDocument(queryEngine: DatabaseQueryEngine, id: string, throwIfNotFound?: boolean): Promise<import('./dbInterface').QueryResponseSingleDoc>;
|
|
2
|
+
export function areDocsEqual(oldDoc: any, newDoc: any): Promise<boolean>;
|
|
3
|
+
import DatabaseQueryEngine from "./dbInterface";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function getDocsAndNormalize({ client, doctype, db, queryFunc, queryParams, withRows }: {
|
|
2
|
+
client: any;
|
|
3
|
+
doctype: any;
|
|
4
|
+
db: any;
|
|
5
|
+
queryFunc: any;
|
|
6
|
+
queryParams?: {};
|
|
7
|
+
withRows?: boolean;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
data: any;
|
|
10
|
+
meta: {
|
|
11
|
+
count: any;
|
|
12
|
+
};
|
|
13
|
+
skip: any;
|
|
14
|
+
next: boolean;
|
|
15
|
+
} | {
|
|
16
|
+
data: any;
|
|
17
|
+
}>;
|
|
18
|
+
export function getDocs(db: any, fct: any, queryParams?: {}): any;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function keepDocWitHighestRev(docs: any): any;
|
|
2
|
+
export function parseResults(client: any, result: any, doctype: any, { isSingleDoc, skip, limit }?: {
|
|
3
|
+
isSingleDoc?: boolean;
|
|
4
|
+
skip?: number;
|
|
5
|
+
limit?: any;
|
|
6
|
+
}): {
|
|
7
|
+
data: any;
|
|
8
|
+
meta?: undefined;
|
|
9
|
+
skip?: undefined;
|
|
10
|
+
next?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
data: any[];
|
|
13
|
+
meta: {
|
|
14
|
+
count: number;
|
|
15
|
+
};
|
|
16
|
+
skip: number;
|
|
17
|
+
next: boolean;
|
|
18
|
+
};
|
|
19
|
+
export function mangoSelectorToSQL(selector: any): string;
|
|
20
|
+
export function makeWhereClause(selector: any): string;
|
|
21
|
+
export function makeSortClause(mangoSortBy: any): string;
|
|
22
|
+
export function makeSQLQueryFromMango({ selector, sort, indexName, limit, skip }: {
|
|
23
|
+
selector: any;
|
|
24
|
+
sort: any;
|
|
25
|
+
indexName: any;
|
|
26
|
+
limit: any;
|
|
27
|
+
skip?: number;
|
|
28
|
+
}): string;
|
|
29
|
+
export function makeSQLQueryForId(id: any): string;
|
|
30
|
+
export function makeSQLQueryForIds(ids: any): string;
|
|
31
|
+
export function makeSQLQueryAll({ limit, skip }?: {
|
|
32
|
+
limit?: number;
|
|
33
|
+
skip?: number;
|
|
34
|
+
}): string;
|
|
35
|
+
export function makeSQLDropIndex(indexName: any): string;
|
|
36
|
+
export function makeSQLCreateMangoIndex(indexName: any, fieldsToIndex: any, { partialFilter }: {
|
|
37
|
+
partialFilter: any;
|
|
38
|
+
}): string;
|
|
39
|
+
export function makeSQLCreateDocIDIndex(): string;
|
|
40
|
+
export function makeSQLCreateDeletedIndex(): string;
|
|
41
|
+
export function createMangoIndex(db: any, indexName: any, fieldsToIndex: any, { partialFilter }: {
|
|
42
|
+
partialFilter: any;
|
|
43
|
+
}): Promise<any>;
|
|
44
|
+
export function deleteIndex(db: any, indexName: any): Promise<void>;
|
|
45
|
+
export function executeSQL(db: any, sql: any): Promise<any>;
|
package/types/errors.d.ts
CHANGED
package/types/helpers.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
+
export const LIMIT_BUG: 999;
|
|
1
2
|
export default helpers;
|
|
2
3
|
declare namespace helpers {
|
|
3
4
|
function isAdapterBugged(adapterName: any): boolean;
|
|
4
|
-
function withoutDesignDocuments(res: any): any;
|
|
5
|
-
function getDocs(db: any, fct: any, options?: {}): any;
|
|
6
|
-
function allDocs(db: any, options?: {}): Promise<any>;
|
|
7
|
-
function find(db: any, options?: {}): Promise<any>;
|
|
8
5
|
function isDesignDocument(doc: any): boolean;
|
|
9
6
|
function isDeletedDocument(doc: any): any;
|
|
10
7
|
function insertBulkDocs(db: any, docs: any): Promise<any>;
|
package/types/index.d.ts
CHANGED
package/types/jsonapi.d.ts
CHANGED
|
@@ -15,4 +15,6 @@ export function fromPouchResult({ res, withRows, doctype, client }: {
|
|
|
15
15
|
} | {
|
|
16
16
|
data: any;
|
|
17
17
|
};
|
|
18
|
+
export function sanitized(doc: any): Pick<any, string | number | symbol>;
|
|
19
|
+
export function sanitizeJsonApi(doc: any): Pick<Pick<any, string | number | symbol>, string | number | symbol>;
|
|
18
20
|
import CozyClient from "cozy-client";
|
package/types/mango.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
1
|
export function makeKeyFromPartialFilter(condition: object): string;
|
|
2
2
|
export function getIndexNameFromFields(fields: Array<string>, partialFilter?: object): string;
|
|
3
|
-
export function
|
|
3
|
+
export function getIndexFieldsFromFind({ selector, sort, partialFilter }: import('./types').MangoQueryOptions): string[];
|
|
4
|
+
export function createIndex(db: object, fields: any[], { partialFilter, indexName, doctype }?: {
|
|
5
|
+
partialFilter: object;
|
|
6
|
+
indexName: string;
|
|
7
|
+
doctype: string;
|
|
8
|
+
}): Promise<import('./types').PouchDbIndex>;
|
|
9
|
+
export function findExistingIndex(doctype: string, options: import('./types').MangoQueryOptions, indexName: string): import('./types').PouchDbIndex | undefined;
|
|
10
|
+
export function getIndexFields({ selector, sort, partialFilter, indexedFields }: {
|
|
11
|
+
selector: any;
|
|
12
|
+
sort: any;
|
|
13
|
+
partialFilter: any;
|
|
14
|
+
indexedFields: any;
|
|
15
|
+
}): any;
|
|
16
|
+
export function getIndexName({ selector, sort, indexedFields, partialFilter }: {
|
|
17
|
+
selector: any;
|
|
18
|
+
sort: any;
|
|
19
|
+
indexedFields: any;
|
|
20
|
+
partialFilter: any;
|
|
21
|
+
}): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function destroyOldDatabases(PouchDB: any, doctypes: any, prefix: any): void;
|
package/types/types.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export type LinkPlatform = {
|
|
|
33
33
|
* PouchDB class (can be pouchdb-core or pouchdb-browser)
|
|
34
34
|
*/
|
|
35
35
|
pouchAdapter: any;
|
|
36
|
+
queryEngine: DatabaseQueryEngine;
|
|
36
37
|
/**
|
|
37
38
|
* Method that check if the app is connected to internet
|
|
38
39
|
*/
|
|
@@ -144,3 +145,4 @@ export type PouchDBChanges = {
|
|
|
144
145
|
*/
|
|
145
146
|
doc: object;
|
|
146
147
|
};
|
|
148
|
+
import DatabaseQueryEngine from "./db/dbInterface";
|
package/types/utils.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
export const DATABASE_NAME_SEPARATOR: "__doctype__";
|
|
1
2
|
export function getDatabaseName(prefix: string, doctype: string): string;
|
|
3
|
+
export function getOldDatabaseName(prefix: string, doctype: string): string;
|
|
4
|
+
export function getDoctypeFromDatabaseName(dbName: any): any;
|
|
2
5
|
export function getPrefix(uri: string): string;
|
|
3
6
|
export function formatAggregatedError(aggregatedError: any): any;
|
|
4
7
|
export function allSettled(promises: Promise<any>[]): Promise<(FulfilledPromise | RejectedPromise)[]>;
|