@deephaven/pouch-storage 0.42.1-beta.4 → 0.43.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/package.json +7 -7
- package/dist/PouchCommandHistoryCache.js +0 -56
- package/dist/PouchCommandHistoryCache.js.map +0 -1
- package/dist/PouchCommandHistoryStorage.js +0 -58
- package/dist/PouchCommandHistoryStorage.js.map +0 -1
- package/dist/PouchCommandHistoryTable.js +0 -206
- package/dist/PouchCommandHistoryTable.js.map +0 -1
- package/dist/PouchStorageTable.js +0 -391
- package/dist/PouchStorageTable.js.map +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/pouchCommandHistoryUtils.js +0 -22
- package/dist/pouchCommandHistoryUtils.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deephaven/pouch-storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "Deephaven Storage based on PouchDB",
|
|
5
5
|
"author": "Deephaven Data Labs LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"build:babel": "babel ./src --out-dir ./dist --extensions \".ts,.tsx,.js,.jsx\" --source-maps --root-mode upward"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@deephaven/console": "^0.
|
|
25
|
-
"@deephaven/filters": "^0.
|
|
26
|
-
"@deephaven/log": "^0.
|
|
27
|
-
"@deephaven/storage": "^0.
|
|
28
|
-
"@deephaven/utils": "^0.
|
|
24
|
+
"@deephaven/console": "^0.43.0",
|
|
25
|
+
"@deephaven/filters": "^0.43.0",
|
|
26
|
+
"@deephaven/log": "^0.43.0",
|
|
27
|
+
"@deephaven/storage": "^0.43.0",
|
|
28
|
+
"@deephaven/utils": "^0.43.0",
|
|
29
29
|
"lodash.throttle": "^4.1.1",
|
|
30
30
|
"pouchdb-browser": "^7.3.0",
|
|
31
31
|
"pouchdb-find": "^7.3.0"
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "b16776b5bdc15a02cd2897cd79d562ea38c60ed8"
|
|
44
44
|
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
3
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
4
|
-
import Log from '@deephaven/log';
|
|
5
|
-
var log = Log.module('PouchCommandHistoryCache');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Cache for tracking things shared across multiple
|
|
9
|
-
* `PouchCommandHistoryTable` instances.
|
|
10
|
-
*/
|
|
11
|
-
class PouchCommandHistoryCache {
|
|
12
|
-
constructor() {
|
|
13
|
-
_defineProperty(this, "isPruning", void 0);
|
|
14
|
-
_defineProperty(this, "response", void 0);
|
|
15
|
-
_defineProperty(this, "tableRegistry", void 0);
|
|
16
|
-
this.isPruning = new Map();
|
|
17
|
-
this.response = new Map();
|
|
18
|
-
this.tableRegistry = new Map();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Keep track of pruning status for a database. This helps ensure only 1
|
|
23
|
-
* pruning operation gets executed if multiple instances of a PouchCommandHistory
|
|
24
|
-
* table load data at the same time.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Pauses PouchDB change listeners for any `PouchCommandHistoryTable` with
|
|
29
|
-
* the given database name. This will cancel existing subscriptions and
|
|
30
|
-
* return a callback that can be used to re-subscribe them.
|
|
31
|
-
* @param dbName
|
|
32
|
-
*/
|
|
33
|
-
pauseChangeListeners(dbName) {
|
|
34
|
-
var _this$tableRegistry$g;
|
|
35
|
-
var pausedTables = [];
|
|
36
|
-
(_this$tableRegistry$g = this.tableRegistry.get(dbName)) === null || _this$tableRegistry$g === void 0 ? void 0 : _this$tableRegistry$g.forEach(table => {
|
|
37
|
-
if (table.changes) {
|
|
38
|
-
log.debug("Pausing event listeners on '".concat(dbName, "' table"), table);
|
|
39
|
-
table.changes.cancel();
|
|
40
|
-
pausedTables.push(table);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return () => {
|
|
44
|
-
pausedTables.forEach(table => {
|
|
45
|
-
var _this$tableRegistry$g2, _this$tableRegistry$g3;
|
|
46
|
-
// Resume listening for changes if the table is still in the registry
|
|
47
|
-
if ((_this$tableRegistry$g2 = (_this$tableRegistry$g3 = this.tableRegistry.get(dbName)) === null || _this$tableRegistry$g3 === void 0 ? void 0 : _this$tableRegistry$g3.has(table)) !== null && _this$tableRegistry$g2 !== void 0 ? _this$tableRegistry$g2 : false) {
|
|
48
|
-
log.debug("Resuming event listeners on '".concat(dbName, "' table"), table);
|
|
49
|
-
table.listenForChanges();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export default PouchCommandHistoryCache;
|
|
56
|
-
//# sourceMappingURL=PouchCommandHistoryCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PouchCommandHistoryCache.js","names":["Log","log","module","PouchCommandHistoryCache","constructor","isPruning","Map","response","tableRegistry","pauseChangeListeners","dbName","pausedTables","get","forEach","table","changes","debug","cancel","push","has","listenForChanges"],"sources":["../src/PouchCommandHistoryCache.ts"],"sourcesContent":["import { CommandHistoryStorageItem } from '@deephaven/console';\nimport Log from '@deephaven/log';\nimport PouchCommandHistoryTable from './PouchCommandHistoryTable';\nimport { PouchStorageItem } from './PouchStorageTable';\n\ntype CommandHistoryStorageItemFindResponse = PouchDB.Find.FindResponse<\n CommandHistoryStorageItem & PouchStorageItem\n>;\n\ntype DatabaseName = string;\n\nconst log = Log.module('PouchCommandHistoryCache');\n\n/**\n * Cache for tracking things shared across multiple\n * `PouchCommandHistoryTable` instances.\n */\nclass PouchCommandHistoryCache {\n constructor() {\n this.isPruning = new Map();\n this.response = new Map();\n this.tableRegistry = new Map();\n }\n\n /**\n * Keep track of pruning status for a database. This helps ensure only 1\n * pruning operation gets executed if multiple instances of a PouchCommandHistory\n * table load data at the same time.\n */\n isPruning: Map<DatabaseName, boolean>;\n\n /**\n * Cache for command history query results keyed by db name. The cached data\n * will be shared across all `PouchCommandHistoryTable` instances that have\n * the same db name.\n */\n response: Map<\n DatabaseName,\n Promise<CommandHistoryStorageItemFindResponse> | null\n >;\n\n /**\n * Keeps track of all `PouchCommandHistoryTable` instances.\n */\n tableRegistry: Map<DatabaseName, Set<PouchCommandHistoryTable>>;\n\n /**\n * Pauses PouchDB change listeners for any `PouchCommandHistoryTable` with\n * the given database name. This will cancel existing subscriptions and\n * return a callback that can be used to re-subscribe them.\n * @param dbName\n */\n pauseChangeListeners(dbName: DatabaseName): () => void {\n const pausedTables: PouchCommandHistoryTable[] = [];\n\n this.tableRegistry.get(dbName)?.forEach(table => {\n if (table.changes) {\n log.debug(`Pausing event listeners on '${dbName}' table`, table);\n table.changes.cancel();\n\n pausedTables.push(table);\n }\n });\n\n return () => {\n pausedTables.forEach(table => {\n // Resume listening for changes if the table is still in the registry\n if (this.tableRegistry.get(dbName)?.has(table) ?? false) {\n log.debug(`Resuming event listeners on '${dbName}' table`, table);\n table.listenForChanges();\n }\n });\n };\n }\n}\n\nexport default PouchCommandHistoryCache;\n"],"mappings":";;;AACA,OAAOA,GAAG,MAAM,gBAAgB;AAUhC,IAAMC,GAAG,GAAGD,GAAG,CAACE,MAAM,CAAC,0BAA0B,CAAC;;AAElD;AACA;AACA;AACA;AACA,MAAMC,wBAAwB,CAAC;EAC7BC,WAAW,GAAG;IAAA;IAAA;IAAA;IACZ,IAAI,CAACC,SAAS,GAAG,IAAIC,GAAG,EAAE;IAC1B,IAAI,CAACC,QAAQ,GAAG,IAAID,GAAG,EAAE;IACzB,IAAI,CAACE,aAAa,GAAG,IAAIF,GAAG,EAAE;EAChC;;EAEA;AACF;AACA;AACA;AACA;;EAkBE;AACF;AACA;AACA;AACA;AACA;EACEG,oBAAoB,CAACC,MAAoB,EAAc;IAAA;IACrD,IAAMC,YAAwC,GAAG,EAAE;IAEnD,6BAAI,CAACH,aAAa,CAACI,GAAG,CAACF,MAAM,CAAC,0DAA9B,sBAAgCG,OAAO,CAACC,KAAK,IAAI;MAC/C,IAAIA,KAAK,CAACC,OAAO,EAAE;QACjBd,GAAG,CAACe,KAAK,uCAAgCN,MAAM,cAAWI,KAAK,CAAC;QAChEA,KAAK,CAACC,OAAO,CAACE,MAAM,EAAE;QAEtBN,YAAY,CAACO,IAAI,CAACJ,KAAK,CAAC;MAC1B;IACF,CAAC,CAAC;IAEF,OAAO,MAAM;MACXH,YAAY,CAACE,OAAO,CAACC,KAAK,IAAI;QAAA;QAC5B;QACA,wDAAI,IAAI,CAACN,aAAa,CAACI,GAAG,CAACF,MAAM,CAAC,2DAA9B,uBAAgCS,GAAG,CAACL,KAAK,CAAC,2EAAI,KAAK,EAAE;UACvDb,GAAG,CAACe,KAAK,wCAAiCN,MAAM,cAAWI,KAAK,CAAC;UACjEA,KAAK,CAACM,gBAAgB,EAAE;QAC1B;MACF,CAAC,CAAC;IACJ,CAAC;EACH;AACF;AAEA,eAAejB,wBAAwB"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
-
/* eslint-disable class-methods-use-this */
|
|
9
|
-
import Log from '@deephaven/log';
|
|
10
|
-
import PouchCommandHistoryTable from "./PouchCommandHistoryTable.js";
|
|
11
|
-
import PouchCommandHistoryCache from "./PouchCommandHistoryCache.js";
|
|
12
|
-
var log = Log.module('PouchCommandHistoryStorage');
|
|
13
|
-
export class PouchCommandHistoryStorage {
|
|
14
|
-
constructor() {
|
|
15
|
-
_defineProperty(this, "cache", new PouchCommandHistoryCache());
|
|
16
|
-
_defineProperty(this, "updateTableMap", new Map());
|
|
17
|
-
}
|
|
18
|
-
getUpdateTable(language) {
|
|
19
|
-
if (!this.updateTableMap.has(language)) {
|
|
20
|
-
this.updateTableMap.set(language, new PouchCommandHistoryTable(language, this.cache));
|
|
21
|
-
}
|
|
22
|
-
return this.updateTableMap.get(language);
|
|
23
|
-
}
|
|
24
|
-
getTable(language) {
|
|
25
|
-
var _this = this;
|
|
26
|
-
return _asyncToGenerator(function* () {
|
|
27
|
-
return new PouchCommandHistoryTable(language, _this.cache);
|
|
28
|
-
})();
|
|
29
|
-
}
|
|
30
|
-
addItem(language, scope, command, data) {
|
|
31
|
-
var _this2 = this;
|
|
32
|
-
return _asyncToGenerator(function* () {
|
|
33
|
-
return _this2.updateItem(language, {
|
|
34
|
-
id: "".concat(new Date().getTime()),
|
|
35
|
-
name: command,
|
|
36
|
-
data
|
|
37
|
-
});
|
|
38
|
-
})();
|
|
39
|
-
}
|
|
40
|
-
updateItem(language, item) {
|
|
41
|
-
var _this3 = this;
|
|
42
|
-
return _asyncToGenerator(function* () {
|
|
43
|
-
var updateTable = _this3.getUpdateTable(language);
|
|
44
|
-
var dbItem = yield updateTable.refreshItem(item.id);
|
|
45
|
-
var updatedItem = _objectSpread(_objectSpread({}, dbItem !== null && dbItem !== void 0 ? dbItem : {}), item);
|
|
46
|
-
log.debug('Updating item', updatedItem);
|
|
47
|
-
yield updateTable.put(updatedItem);
|
|
48
|
-
log.debug('Update saved');
|
|
49
|
-
return item;
|
|
50
|
-
})();
|
|
51
|
-
}
|
|
52
|
-
listenItem(language, id, listener) {
|
|
53
|
-
var updateTable = this.getUpdateTable(language);
|
|
54
|
-
return updateTable.onItemUpdate(id, listener);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export default PouchCommandHistoryStorage;
|
|
58
|
-
//# sourceMappingURL=PouchCommandHistoryStorage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PouchCommandHistoryStorage.js","names":["Log","PouchCommandHistoryTable","PouchCommandHistoryCache","log","module","PouchCommandHistoryStorage","Map","getUpdateTable","language","updateTableMap","has","set","cache","get","getTable","addItem","scope","command","data","updateItem","id","Date","getTime","name","item","updateTable","dbItem","refreshItem","updatedItem","debug","put","listenItem","listener","onItemUpdate"],"sources":["../src/PouchCommandHistoryStorage.ts"],"sourcesContent":["/* eslint-disable class-methods-use-this */\nimport Log from '@deephaven/log';\nimport {\n CommandHistoryStorage,\n CommandHistoryStorageData,\n CommandHistoryStorageItem,\n} from '@deephaven/console';\nimport {\n StorageItemListener,\n StorageListenerRemover,\n} from '@deephaven/storage';\nimport PouchCommandHistoryTable from './PouchCommandHistoryTable';\nimport PouchCommandHistoryCache from './PouchCommandHistoryCache';\n\nconst log = Log.module('PouchCommandHistoryStorage');\n\nexport class PouchCommandHistoryStorage implements CommandHistoryStorage {\n private cache = new PouchCommandHistoryCache();\n\n private updateTableMap = new Map<string, PouchCommandHistoryTable>();\n\n private getUpdateTable(language: string): PouchCommandHistoryTable {\n if (!this.updateTableMap.has(language)) {\n this.updateTableMap.set(\n language,\n new PouchCommandHistoryTable(language, this.cache)\n );\n }\n\n return this.updateTableMap.get(language) as PouchCommandHistoryTable;\n }\n\n async getTable(language: string): Promise<PouchCommandHistoryTable> {\n return new PouchCommandHistoryTable(language, this.cache);\n }\n\n async addItem(\n language: string,\n scope: string,\n command: string,\n data: CommandHistoryStorageData\n ): Promise<CommandHistoryStorageItem> {\n return this.updateItem(language, {\n id: `${new Date().getTime()}`,\n name: command,\n data,\n } as CommandHistoryStorageItem);\n }\n\n async updateItem(\n language: string,\n item: CommandHistoryStorageItem\n ): Promise<CommandHistoryStorageItem> {\n const updateTable = this.getUpdateTable(language);\n\n const dbItem = await updateTable.refreshItem(item.id);\n\n const updatedItem = { ...(dbItem ?? {}), ...item };\n\n log.debug('Updating item', updatedItem);\n\n await updateTable.put(updatedItem);\n\n log.debug('Update saved');\n\n return item;\n }\n\n listenItem(\n language: string,\n id: string,\n listener: StorageItemListener<CommandHistoryStorageItem>\n ): StorageListenerRemover {\n const updateTable = this.getUpdateTable(language);\n\n return updateTable.onItemUpdate(id, listener);\n }\n}\n\nexport default PouchCommandHistoryStorage;\n"],"mappings":";;;;;;;AAAA;AACA,OAAOA,GAAG,MAAM,gBAAgB;AAAC,OAU1BC,wBAAwB;AAAA,OACxBC,wBAAwB;AAE/B,IAAMC,GAAG,GAAGH,GAAG,CAACI,MAAM,CAAC,4BAA4B,CAAC;AAEpD,OAAO,MAAMC,0BAA0B,CAAkC;EAAA;IAAA,+BACvD,IAAIH,wBAAwB,EAAE;IAAA,wCAErB,IAAII,GAAG,EAAoC;EAAA;EAE5DC,cAAc,CAACC,QAAgB,EAA4B;IACjE,IAAI,CAAC,IAAI,CAACC,cAAc,CAACC,GAAG,CAACF,QAAQ,CAAC,EAAE;MACtC,IAAI,CAACC,cAAc,CAACE,GAAG,CACrBH,QAAQ,EACR,IAAIP,wBAAwB,CAACO,QAAQ,EAAE,IAAI,CAACI,KAAK,CAAC,CACnD;IACH;IAEA,OAAO,IAAI,CAACH,cAAc,CAACI,GAAG,CAACL,QAAQ,CAAC;EAC1C;EAEMM,QAAQ,CAACN,QAAgB,EAAqC;IAAA;IAAA;MAClE,OAAO,IAAIP,wBAAwB,CAACO,QAAQ,EAAE,KAAI,CAACI,KAAK,CAAC;IAAC;EAC5D;EAEMG,OAAO,CACXP,QAAgB,EAChBQ,KAAa,EACbC,OAAe,EACfC,IAA+B,EACK;IAAA;IAAA;MACpC,OAAO,MAAI,CAACC,UAAU,CAACX,QAAQ,EAAE;QAC/BY,EAAE,YAAK,IAAIC,IAAI,EAAE,CAACC,OAAO,EAAE,CAAE;QAC7BC,IAAI,EAAEN,OAAO;QACbC;MACF,CAAC,CAA8B;IAAC;EAClC;EAEMC,UAAU,CACdX,QAAgB,EAChBgB,IAA+B,EACK;IAAA;IAAA;MACpC,IAAMC,WAAW,GAAG,MAAI,CAAClB,cAAc,CAACC,QAAQ,CAAC;MAEjD,IAAMkB,MAAM,SAASD,WAAW,CAACE,WAAW,CAACH,IAAI,CAACJ,EAAE,CAAC;MAErD,IAAMQ,WAAW,mCAASF,MAAM,aAANA,MAAM,cAANA,MAAM,GAAI,CAAC,CAAC,GAAMF,IAAI,CAAE;MAElDrB,GAAG,CAAC0B,KAAK,CAAC,eAAe,EAAED,WAAW,CAAC;MAEvC,MAAMH,WAAW,CAACK,GAAG,CAACF,WAAW,CAAC;MAElCzB,GAAG,CAAC0B,KAAK,CAAC,cAAc,CAAC;MAEzB,OAAOL,IAAI;IAAC;EACd;EAEAO,UAAU,CACRvB,QAAgB,EAChBY,EAAU,EACVY,QAAwD,EAChC;IACxB,IAAMP,WAAW,GAAG,IAAI,CAAClB,cAAc,CAACC,QAAQ,CAAC;IAEjD,OAAOiB,WAAW,CAACQ,YAAY,CAACb,EAAE,EAAEY,QAAQ,CAAC;EAC/C;AACF;AAEA,eAAe3B,0BAA0B"}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
-
import { Type as FilterType } from '@deephaven/filters';
|
|
9
|
-
import Log from '@deephaven/log';
|
|
10
|
-
import { StorageUtils } from '@deephaven/storage';
|
|
11
|
-
import { PromiseUtils } from '@deephaven/utils';
|
|
12
|
-
import { siftPrunableItems } from "./pouchCommandHistoryUtils.js";
|
|
13
|
-
import PouchStorageTable from "./PouchStorageTable.js";
|
|
14
|
-
var COMMAND_HISTORY_ITEMS_MAX = 2500;
|
|
15
|
-
var COMMAND_HISTORY_ITEMS_PRUNE = 2000;
|
|
16
|
-
var log = Log.module('PouchCommandHistoryTable');
|
|
17
|
-
export class PouchCommandHistoryTable extends PouchStorageTable {
|
|
18
|
-
constructor(language, cache) {
|
|
19
|
-
var _this$cache$tableRegi;
|
|
20
|
-
super("CommandHistoryStorage.".concat(language), {
|
|
21
|
-
// Optimizations to cut down on growing table size. These should be safe
|
|
22
|
-
// since we don't care about revision history for command history
|
|
23
|
-
// documents.
|
|
24
|
-
auto_compaction: true,
|
|
25
|
-
revs_limit: 1
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// Add this table instance to the table registry
|
|
29
|
-
_defineProperty(this, "searchText", void 0);
|
|
30
|
-
this.cache = cache;
|
|
31
|
-
if (!this.cache.tableRegistry.has(this.cacheKey)) {
|
|
32
|
-
this.cache.tableRegistry.set(this.cacheKey, new Set());
|
|
33
|
-
}
|
|
34
|
-
log.debug('Adding table to registry', this.cacheKey);
|
|
35
|
-
(_this$cache$tableRegi = this.cache.tableRegistry.get(this.cacheKey)) === null || _this$cache$tableRegi === void 0 ? void 0 : _this$cache$tableRegi.add(this);
|
|
36
|
-
}
|
|
37
|
-
get cacheKey() {
|
|
38
|
-
return this.db.name;
|
|
39
|
-
}
|
|
40
|
-
setSearch(searchText) {
|
|
41
|
-
log.debug('Setting search filters', searchText);
|
|
42
|
-
this.searchText = searchText.trim().toLowerCase();
|
|
43
|
-
this.setFilters(searchText ? [StorageUtils.makeFilterConfig([StorageUtils.makeFilterItem('name', FilterType.contains, searchText)])] : []);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Our current version of eslint + prettier doesn't always like the `override`
|
|
47
|
-
// keyword. Whenever we upgrade, we should annotate this function with `override`.
|
|
48
|
-
dbUpdate(event) {
|
|
49
|
-
log.debug('Clearing cache and refreshing data', event);
|
|
50
|
-
this.cache.response.delete(this.cacheKey);
|
|
51
|
-
super.dbUpdate(event);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Fetch command history data from `this.cache.response` or from
|
|
56
|
-
* PouchDB if data is not found in the cache. If the number of total items in
|
|
57
|
-
* the db exceeds COMMAND_HISTORY_ITEMS_MAX, the database will be pruned down
|
|
58
|
-
* to COMMAND_HISTORY_ITEMS_PRUNE total items. Note that PouchDB doesn't
|
|
59
|
-
* actually remove them from the underlying IndexDB, they are just marked
|
|
60
|
-
* as deleted and won't be present in our query results.
|
|
61
|
-
* @param selector
|
|
62
|
-
*/
|
|
63
|
-
fetchData(_selector) {
|
|
64
|
-
var _this = this;
|
|
65
|
-
return _asyncToGenerator(function* () {
|
|
66
|
-
// Wrapping this in a setTimeout so that it executes on next call stack.
|
|
67
|
-
// This is necessary to ensure `this.cache` has been initialized due to some
|
|
68
|
-
// nuances with property initilization with inherited classes.
|
|
69
|
-
return PromiseUtils.withTimeout(0, /*#__PURE__*/_asyncToGenerator(function* () {
|
|
70
|
-
if (_this.cache.response.has(_this.cacheKey)) {
|
|
71
|
-
log.debug('Fetching from cache', _this.searchText, _this.viewport);
|
|
72
|
-
} else {
|
|
73
|
-
log.debug('Fetching from PouchDB', _this.searchText, _this.viewport);
|
|
74
|
-
_this.cache.response.set(_this.cacheKey, _this.db.allDocs({
|
|
75
|
-
include_docs: true
|
|
76
|
-
}).then(result => {
|
|
77
|
-
var allItems = result.rows
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
79
|
-
.map(row => row.doc).filter(_ref2 => {
|
|
80
|
-
var {
|
|
81
|
-
name
|
|
82
|
-
} = _ref2;
|
|
83
|
-
return name;
|
|
84
|
-
});
|
|
85
|
-
log.debug("Fetched ".concat(allItems.length, " command history items"));
|
|
86
|
-
var {
|
|
87
|
-
toKeep,
|
|
88
|
-
toPrune
|
|
89
|
-
} = siftPrunableItems(allItems, COMMAND_HISTORY_ITEMS_MAX, COMMAND_HISTORY_ITEMS_PRUNE);
|
|
90
|
-
|
|
91
|
-
// If number of items in PouchDB has exceeded COMMAND_HISTORY_ITEMS_MAX
|
|
92
|
-
// prune them down so we have COMMAND_HISTORY_ITEMS_PRUNE left
|
|
93
|
-
if (toPrune.length) {
|
|
94
|
-
_this.pruneItems(toPrune);
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
docs: toKeep
|
|
98
|
-
};
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
103
|
-
var result = _this.cache.response.get(_this.cacheKey);
|
|
104
|
-
if (_this.searchText == null || _this.searchText === '') {
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
return _objectSpread(_objectSpread({}, result), {}, {
|
|
108
|
-
docs: (yield result).docs.filter(_ref3 => {
|
|
109
|
-
var {
|
|
110
|
-
name
|
|
111
|
-
} = _ref3;
|
|
112
|
-
return (
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
114
|
-
name.toLowerCase().includes(_this.searchText)
|
|
115
|
-
);
|
|
116
|
-
})
|
|
117
|
-
});
|
|
118
|
-
}));
|
|
119
|
-
})();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Override `PouchStorageTable.fetchInfo` so we can make use of
|
|
124
|
-
* `PouchCommandHistoryCache`
|
|
125
|
-
* @param selector
|
|
126
|
-
*/
|
|
127
|
-
// Our current version of eslint + prettier doesn't always like the `override`
|
|
128
|
-
// keyword. Whenever we upgrade, we should annotate this function with `override`.
|
|
129
|
-
fetchInfo(selector) {
|
|
130
|
-
var _this2 = this;
|
|
131
|
-
return _asyncToGenerator(function* () {
|
|
132
|
-
return _this2.fetchData(selector);
|
|
133
|
-
})();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Override `PouchStorageTable.fetchViewportData` to fetch command history
|
|
138
|
-
* storage items. This override provides caching + optimizations specific to
|
|
139
|
-
* command history. We cache the results to avoid excessive PouchDB queries
|
|
140
|
-
* during scrolling. The cache should only need to be invalidated when search
|
|
141
|
-
* filter changes or commands are added to the storage history.
|
|
142
|
-
*
|
|
143
|
-
* @param viewport
|
|
144
|
-
* @param selector
|
|
145
|
-
* @param sort
|
|
146
|
-
* @returns Promise to array of command history storage items
|
|
147
|
-
*/
|
|
148
|
-
// Our current version of eslint + prettier doesn't always like the `override`
|
|
149
|
-
// keyword. Whenever we upgrade, we should annotate this function with `override`.
|
|
150
|
-
fetchViewportData(viewport, selector, sort) {
|
|
151
|
-
var _this3 = this;
|
|
152
|
-
return _asyncToGenerator(function* () {
|
|
153
|
-
var data = yield _this3.fetchData(selector);
|
|
154
|
-
log.debug('Fetching viewport data', viewport.top, viewport.bottom + 1, sort, data);
|
|
155
|
-
var isReversed = typeof sort[0] === 'object' && sort[0].id === 'desc';
|
|
156
|
-
var docs = isReversed ? data.docs.slice(0).reverse() : data.docs;
|
|
157
|
-
var items = docs.slice(viewport.top, viewport.bottom + 1);
|
|
158
|
-
return {
|
|
159
|
-
items,
|
|
160
|
-
offset: viewport.top
|
|
161
|
-
};
|
|
162
|
-
})();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Mark given items as `_deleted` in the database.
|
|
167
|
-
* @param items
|
|
168
|
-
*/
|
|
169
|
-
pruneItems(items) {
|
|
170
|
-
var _this4 = this;
|
|
171
|
-
return _asyncToGenerator(function* () {
|
|
172
|
-
if (_this4.cache.isPruning.get(_this4.cacheKey) === true) {
|
|
173
|
-
log.debug('Pruning already in progress. Skipping.');
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
try {
|
|
177
|
-
log.debug("Pruning ".concat(items.length, " command history items"));
|
|
178
|
-
|
|
179
|
-
// Disable change notifications while we bulk delete to avoid locking up
|
|
180
|
-
// the app
|
|
181
|
-
var resumeListeners = _this4.cache.pauseChangeListeners(_this4.cacheKey);
|
|
182
|
-
_this4.cache.isPruning.set(_this4.cacheKey, true);
|
|
183
|
-
yield _this4.db.bulkDocs(items.map(item => _objectSpread(_objectSpread({}, item), {}, {
|
|
184
|
-
_deleted: true
|
|
185
|
-
})));
|
|
186
|
-
_this4.cache.isPruning.set(_this4.cacheKey, false);
|
|
187
|
-
resumeListeners();
|
|
188
|
-
log.debug('Finished pruning command history items');
|
|
189
|
-
} catch (err) {
|
|
190
|
-
log.error('An error occurred while pruning db', err);
|
|
191
|
-
}
|
|
192
|
-
})();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Our current version of eslint + prettier doesn't always like the `override`
|
|
196
|
-
// keyword. Whenever we upgrade, we should annotate this function with `override`.
|
|
197
|
-
close() {
|
|
198
|
-
var _this$cache$tableRegi2, _this$cache$tableRegi3, _this$changes;
|
|
199
|
-
log.debug('Closing table', this, (_this$cache$tableRegi2 = this.cache.tableRegistry.get(this.cacheKey)) === null || _this$cache$tableRegi2 === void 0 ? void 0 : _this$cache$tableRegi2.size);
|
|
200
|
-
(_this$cache$tableRegi3 = this.cache.tableRegistry.get(this.cacheKey)) === null || _this$cache$tableRegi3 === void 0 ? void 0 : _this$cache$tableRegi3.delete(this);
|
|
201
|
-
(_this$changes = this.changes) === null || _this$changes === void 0 ? void 0 : _this$changes.cancel();
|
|
202
|
-
super.close();
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
export default PouchCommandHistoryTable;
|
|
206
|
-
//# sourceMappingURL=PouchCommandHistoryTable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PouchCommandHistoryTable.js","names":["Type","FilterType","Log","StorageUtils","PromiseUtils","siftPrunableItems","PouchStorageTable","COMMAND_HISTORY_ITEMS_MAX","COMMAND_HISTORY_ITEMS_PRUNE","log","module","PouchCommandHistoryTable","constructor","language","cache","auto_compaction","revs_limit","tableRegistry","has","cacheKey","set","Set","debug","get","add","db","name","setSearch","searchText","trim","toLowerCase","setFilters","makeFilterConfig","makeFilterItem","contains","dbUpdate","event","response","delete","fetchData","_selector","withTimeout","viewport","allDocs","include_docs","then","result","allItems","rows","map","row","doc","filter","length","toKeep","toPrune","pruneItems","docs","includes","fetchInfo","selector","fetchViewportData","sort","data","top","bottom","isReversed","id","slice","reverse","items","offset","isPruning","resumeListeners","pauseChangeListeners","bulkDocs","item","_deleted","err","error","close","size","changes","cancel"],"sources":["../src/PouchCommandHistoryTable.ts"],"sourcesContent":["import {\n CommandHistoryStorageItem,\n CommandHistoryTable,\n} from '@deephaven/console';\nimport { Type as FilterType } from '@deephaven/filters';\nimport Log from '@deephaven/log';\nimport {\n StorageTableViewport,\n StorageUtils,\n ViewportData,\n} from '@deephaven/storage';\nimport { PromiseUtils } from '@deephaven/utils';\nimport PouchCommandHistoryCache from './PouchCommandHistoryCache';\nimport { siftPrunableItems } from './pouchCommandHistoryUtils';\nimport PouchStorageTable, {\n PouchDBSort,\n PouchStorageItem,\n} from './PouchStorageTable';\n\nconst COMMAND_HISTORY_ITEMS_MAX = 2500;\nconst COMMAND_HISTORY_ITEMS_PRUNE = 2000;\n\nconst log = Log.module('PouchCommandHistoryTable');\n\ntype CommandHistoryDoc = PouchDB.Core.ExistingDocument<\n CommandHistoryStorageItem & PouchStorageItem & PouchDB.Core.AllDocsMeta\n>;\n\nexport class PouchCommandHistoryTable\n extends PouchStorageTable<CommandHistoryStorageItem>\n implements CommandHistoryTable {\n constructor(language: string, private cache: PouchCommandHistoryCache) {\n super(`CommandHistoryStorage.${language}`, {\n // Optimizations to cut down on growing table size. These should be safe\n // since we don't care about revision history for command history\n // documents.\n auto_compaction: true,\n revs_limit: 1,\n });\n\n // Add this table instance to the table registry\n if (!this.cache.tableRegistry.has(this.cacheKey)) {\n this.cache.tableRegistry.set(this.cacheKey, new Set());\n }\n\n log.debug('Adding table to registry', this.cacheKey);\n this.cache.tableRegistry.get(this.cacheKey)?.add(this);\n }\n\n private searchText?: string;\n\n private get cacheKey(): string {\n return this.db.name;\n }\n\n setSearch(searchText: string): void {\n log.debug('Setting search filters', searchText);\n\n this.searchText = searchText.trim().toLowerCase();\n\n this.setFilters(\n searchText\n ? [\n StorageUtils.makeFilterConfig([\n StorageUtils.makeFilterItem(\n 'name',\n FilterType.contains,\n searchText\n ),\n ]),\n ]\n : []\n );\n }\n\n // Our current version of eslint + prettier doesn't always like the `override`\n // keyword. Whenever we upgrade, we should annotate this function with `override`.\n dbUpdate(\n event: PouchDB.Core.ChangesResponseChange<CommandHistoryStorageItem>\n ): void {\n log.debug('Clearing cache and refreshing data', event);\n\n this.cache.response.delete(this.cacheKey);\n\n super.dbUpdate(event);\n }\n\n /**\n * Fetch command history data from `this.cache.response` or from\n * PouchDB if data is not found in the cache. If the number of total items in\n * the db exceeds COMMAND_HISTORY_ITEMS_MAX, the database will be pruned down\n * to COMMAND_HISTORY_ITEMS_PRUNE total items. Note that PouchDB doesn't\n * actually remove them from the underlying IndexDB, they are just marked\n * as deleted and won't be present in our query results.\n * @param selector\n */\n private async fetchData(\n _selector: PouchDB.Find.Selector\n ): Promise<\n PouchDB.Find.FindResponse<CommandHistoryStorageItem & PouchStorageItem>\n > {\n // Wrapping this in a setTimeout so that it executes on next call stack.\n // This is necessary to ensure `this.cache` has been initialized due to some\n // nuances with property initilization with inherited classes.\n return PromiseUtils.withTimeout(0, async () => {\n if (this.cache.response.has(this.cacheKey)) {\n log.debug('Fetching from cache', this.searchText, this.viewport);\n } else {\n log.debug('Fetching from PouchDB', this.searchText, this.viewport);\n\n this.cache.response.set(\n this.cacheKey,\n this.db\n .allDocs({\n include_docs: true,\n })\n .then(result => {\n const allItems = result.rows\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n .map(row => row.doc!)\n .filter(({ name }) => name);\n\n log.debug(`Fetched ${allItems.length} command history items`);\n\n const { toKeep, toPrune } = siftPrunableItems(\n allItems,\n COMMAND_HISTORY_ITEMS_MAX,\n COMMAND_HISTORY_ITEMS_PRUNE\n );\n\n // If number of items in PouchDB has exceeded COMMAND_HISTORY_ITEMS_MAX\n // prune them down so we have COMMAND_HISTORY_ITEMS_PRUNE left\n if (toPrune.length) {\n this.pruneItems(toPrune);\n }\n\n return {\n docs: toKeep,\n };\n })\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const result = this.cache.response.get(this.cacheKey)!;\n\n if (this.searchText == null || this.searchText === '') {\n return result;\n }\n\n return {\n ...result,\n docs: (await result).docs.filter(({ name }) =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n name.toLowerCase().includes(this.searchText!)\n ),\n };\n });\n }\n\n /**\n * Override `PouchStorageTable.fetchInfo` so we can make use of\n * `PouchCommandHistoryCache`\n * @param selector\n */\n // Our current version of eslint + prettier doesn't always like the `override`\n // keyword. Whenever we upgrade, we should annotate this function with `override`.\n async fetchInfo(\n selector: PouchDB.Find.Selector\n ): Promise<\n PouchDB.Find.FindResponse<CommandHistoryStorageItem & PouchStorageItem>\n > {\n return this.fetchData(selector);\n }\n\n /**\n * Override `PouchStorageTable.fetchViewportData` to fetch command history\n * storage items. This override provides caching + optimizations specific to\n * command history. We cache the results to avoid excessive PouchDB queries\n * during scrolling. The cache should only need to be invalidated when search\n * filter changes or commands are added to the storage history.\n *\n * @param viewport\n * @param selector\n * @param sort\n * @returns Promise to array of command history storage items\n */\n // Our current version of eslint + prettier doesn't always like the `override`\n // keyword. Whenever we upgrade, we should annotate this function with `override`.\n async fetchViewportData(\n viewport: StorageTableViewport,\n selector: PouchDB.Find.Selector,\n sort: PouchDBSort\n ): Promise<ViewportData<CommandHistoryStorageItem>> {\n const data = await this.fetchData(selector);\n\n log.debug(\n 'Fetching viewport data',\n viewport.top,\n viewport.bottom + 1,\n sort,\n data\n );\n\n const isReversed = typeof sort[0] === 'object' && sort[0].id === 'desc';\n const docs = isReversed ? data.docs.slice(0).reverse() : data.docs;\n const items = docs.slice(viewport.top, viewport.bottom + 1);\n\n return {\n items,\n offset: viewport.top,\n };\n }\n\n /**\n * Mark given items as `_deleted` in the database.\n * @param items\n */\n async pruneItems(items: CommandHistoryDoc[]) {\n if (this.cache.isPruning.get(this.cacheKey) === true) {\n log.debug('Pruning already in progress. Skipping.');\n return;\n }\n\n try {\n log.debug(`Pruning ${items.length} command history items`);\n\n // Disable change notifications while we bulk delete to avoid locking up\n // the app\n const resumeListeners = this.cache.pauseChangeListeners(this.cacheKey);\n\n this.cache.isPruning.set(this.cacheKey, true);\n await this.db.bulkDocs(items.map(item => ({ ...item, _deleted: true })));\n this.cache.isPruning.set(this.cacheKey, false);\n\n resumeListeners();\n\n log.debug('Finished pruning command history items');\n } catch (err) {\n log.error('An error occurred while pruning db', err);\n }\n }\n\n // Our current version of eslint + prettier doesn't always like the `override`\n // keyword. Whenever we upgrade, we should annotate this function with `override`.\n close(): void {\n log.debug(\n 'Closing table',\n this,\n this.cache.tableRegistry.get(this.cacheKey)?.size\n );\n this.cache.tableRegistry.get(this.cacheKey)?.delete(this);\n this.changes?.cancel();\n super.close();\n }\n}\n\nexport default PouchCommandHistoryTable;\n"],"mappings":";;;;;;;AAIA,SAASA,IAAI,IAAIC,UAAU,QAAQ,oBAAoB;AACvD,OAAOC,GAAG,MAAM,gBAAgB;AAChC,SAEEC,YAAY,QAEP,oBAAoB;AAC3B,SAASC,YAAY,QAAQ,kBAAkB;AAAC,SAEvCC,iBAAiB;AAAA,OACnBC,iBAAiB;AAKxB,IAAMC,yBAAyB,GAAG,IAAI;AACtC,IAAMC,2BAA2B,GAAG,IAAI;AAExC,IAAMC,GAAG,GAAGP,GAAG,CAACQ,MAAM,CAAC,0BAA0B,CAAC;AAMlD,OAAO,MAAMC,wBAAwB,SAC3BL,iBAAiB,CACM;EAC/BM,WAAW,CAACC,QAAgB,EAAUC,KAA+B,EAAE;IAAA;IACrE,KAAK,iCAA0BD,QAAQ,GAAI;MACzC;MACA;MACA;MACAE,eAAe,EAAE,IAAI;MACrBC,UAAU,EAAE;IACd,CAAC,CAAC;;IAEF;IAAA;IAAA,KAToCF,KAA+B,GAA/BA,KAA+B;IAUnE,IAAI,CAAC,IAAI,CAACA,KAAK,CAACG,aAAa,CAACC,GAAG,CAAC,IAAI,CAACC,QAAQ,CAAC,EAAE;MAChD,IAAI,CAACL,KAAK,CAACG,aAAa,CAACG,GAAG,CAAC,IAAI,CAACD,QAAQ,EAAE,IAAIE,GAAG,EAAE,CAAC;IACx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1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
-
import PouchDB from 'pouchdb-browser';
|
|
9
|
-
import PouchDBFind from 'pouchdb-find';
|
|
10
|
-
import { Operator as FilterOperator, Type as FilterType } from '@deephaven/filters';
|
|
11
|
-
import Log from '@deephaven/log';
|
|
12
|
-
import { PromiseUtils } from '@deephaven/utils';
|
|
13
|
-
var log = Log.module('PouchStorageTable');
|
|
14
|
-
var DB_PREFIX = 'Deephaven.';
|
|
15
|
-
PouchDB.plugin(PouchDBFind);
|
|
16
|
-
function makePouchFilter(type, value) {
|
|
17
|
-
switch (type) {
|
|
18
|
-
case FilterType.in:
|
|
19
|
-
case FilterType.contains:
|
|
20
|
-
return {
|
|
21
|
-
$regex: new RegExp("".concat(value))
|
|
22
|
-
};
|
|
23
|
-
case FilterType.inIgnoreCase:
|
|
24
|
-
return {
|
|
25
|
-
$regex: new RegExp("".concat(value), 'i')
|
|
26
|
-
};
|
|
27
|
-
case FilterType.eq:
|
|
28
|
-
return {
|
|
29
|
-
$eq: value
|
|
30
|
-
};
|
|
31
|
-
case FilterType.notEq:
|
|
32
|
-
return {
|
|
33
|
-
$neq: value
|
|
34
|
-
};
|
|
35
|
-
case FilterType.greaterThan:
|
|
36
|
-
return {
|
|
37
|
-
$gt: value
|
|
38
|
-
};
|
|
39
|
-
case FilterType.greaterThanOrEqualTo:
|
|
40
|
-
return {
|
|
41
|
-
$gte: value
|
|
42
|
-
};
|
|
43
|
-
case FilterType.lessThan:
|
|
44
|
-
return {
|
|
45
|
-
$lt: value
|
|
46
|
-
};
|
|
47
|
-
case FilterType.lessThanOrEqualTo:
|
|
48
|
-
return {
|
|
49
|
-
$lte: value
|
|
50
|
-
};
|
|
51
|
-
case FilterType.startsWith:
|
|
52
|
-
return {
|
|
53
|
-
$regex: new RegExp("^(?".concat(value, ").*"))
|
|
54
|
-
};
|
|
55
|
-
default:
|
|
56
|
-
throw new Error("Unsupported type: ".concat(type));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function makePouchSelectorFromConfig(config) {
|
|
60
|
-
var {
|
|
61
|
-
filterItems,
|
|
62
|
-
filterOperators
|
|
63
|
-
} = config;
|
|
64
|
-
var filter = null;
|
|
65
|
-
for (var i = 0; i < filterItems.length; i += 1) {
|
|
66
|
-
var filterItem = filterItems[i];
|
|
67
|
-
var {
|
|
68
|
-
columnName,
|
|
69
|
-
type,
|
|
70
|
-
value
|
|
71
|
-
} = filterItem;
|
|
72
|
-
var newFilter = {
|
|
73
|
-
[columnName]: makePouchFilter(type, value)
|
|
74
|
-
};
|
|
75
|
-
if (i === 0) {
|
|
76
|
-
filter = newFilter;
|
|
77
|
-
} else if (filter !== null && i - 1 < filterOperators.length) {
|
|
78
|
-
var filterOperator = filterOperators[i - 1];
|
|
79
|
-
if (filterOperator === FilterOperator.and) {
|
|
80
|
-
filter = {
|
|
81
|
-
$and: [filter, newFilter]
|
|
82
|
-
};
|
|
83
|
-
} else if (filterOperator === FilterOperator.or) {
|
|
84
|
-
filter = {
|
|
85
|
-
$or: [filter, newFilter]
|
|
86
|
-
};
|
|
87
|
-
} else {
|
|
88
|
-
throw new Error("Unexpected filter operator ".concat(filterOperator, ", ").concat(newFilter));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (filter == null) {
|
|
93
|
-
throw new Error("Invalid filter config ".concat(config));
|
|
94
|
-
}
|
|
95
|
-
return filter;
|
|
96
|
-
}
|
|
97
|
-
function selectorWithFilters() {
|
|
98
|
-
var filters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
99
|
-
return {
|
|
100
|
-
$and: [...filters.map(filter => makePouchSelectorFromConfig(filter)), {
|
|
101
|
-
name: {
|
|
102
|
-
$gt: null
|
|
103
|
-
}
|
|
104
|
-
}, {
|
|
105
|
-
id: {
|
|
106
|
-
$gt: null
|
|
107
|
-
}
|
|
108
|
-
}]
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function sortWithConfigs(sorts) {
|
|
112
|
-
var _sorts$map;
|
|
113
|
-
var reverse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
114
|
-
return [{
|
|
115
|
-
id: reverse ? 'desc' : 'asc'
|
|
116
|
-
}, ...((_sorts$map = sorts === null || sorts === void 0 ? void 0 : sorts.map(sort => ({
|
|
117
|
-
[sort.column]: sort.direction
|
|
118
|
-
}))) !== null && _sorts$map !== void 0 ? _sorts$map : [])];
|
|
119
|
-
}
|
|
120
|
-
export class PouchStorageTable {
|
|
121
|
-
constructor(databaseName, dbOptions) {
|
|
122
|
-
_defineProperty(this, "db", void 0);
|
|
123
|
-
_defineProperty(this, "changes", void 0);
|
|
124
|
-
_defineProperty(this, "listeners", []);
|
|
125
|
-
_defineProperty(this, "itemListeners", new Map());
|
|
126
|
-
_defineProperty(this, "currentSize", 0);
|
|
127
|
-
_defineProperty(this, "currentViewport", void 0);
|
|
128
|
-
_defineProperty(this, "currentReverse", false);
|
|
129
|
-
_defineProperty(this, "currentFilter", null);
|
|
130
|
-
_defineProperty(this, "currentSort", null);
|
|
131
|
-
_defineProperty(this, "infoUpdatePromise", void 0);
|
|
132
|
-
_defineProperty(this, "viewportUpdatePromise", void 0);
|
|
133
|
-
_defineProperty(this, "currentViewportData", void 0);
|
|
134
|
-
this.db = new PouchDB("".concat(DB_PREFIX).concat(databaseName), dbOptions);
|
|
135
|
-
|
|
136
|
-
// Need to set `_remote` to false to remove deprecation warnings: https://github.com/pouchdb/pouchdb/issues/6106
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-underscore-dangle
|
|
138
|
-
this.db._remote = false;
|
|
139
|
-
this.listenForChanges();
|
|
140
|
-
this.db.createIndex({
|
|
141
|
-
index: {
|
|
142
|
-
fields: ['id', 'name']
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
this.refreshInfo();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Listen for db changes. This can be cancelled by calling
|
|
150
|
-
* `this.changes?.cancel()`
|
|
151
|
-
*/
|
|
152
|
-
listenForChanges() {
|
|
153
|
-
this.changes = this.db.changes({
|
|
154
|
-
live: true,
|
|
155
|
-
since: 'now',
|
|
156
|
-
include_docs: true
|
|
157
|
-
}).on('change', this.dbUpdate.bind(this));
|
|
158
|
-
}
|
|
159
|
-
onUpdate(callback) {
|
|
160
|
-
this.listeners = [...this.listeners, callback];
|
|
161
|
-
return () => {
|
|
162
|
-
this.listeners = this.listeners.filter(other => other !== callback);
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
onItemUpdate(id, listener) {
|
|
166
|
-
if (!this.itemListeners.has(id)) {
|
|
167
|
-
this.itemListeners.set(id, []);
|
|
168
|
-
}
|
|
169
|
-
this.itemListeners.set(id, [...this.itemListeners.get(id), listener]);
|
|
170
|
-
this.refreshItem(id);
|
|
171
|
-
return () => {
|
|
172
|
-
this.itemListeners.set(id, this.itemListeners.get(id).filter(other => other !== listener));
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
close() {
|
|
176
|
-
this.listeners = [];
|
|
177
|
-
}
|
|
178
|
-
get size() {
|
|
179
|
-
return this.currentSize;
|
|
180
|
-
}
|
|
181
|
-
get viewport() {
|
|
182
|
-
return this.currentViewport;
|
|
183
|
-
}
|
|
184
|
-
setReversed(reversed) {
|
|
185
|
-
this.currentReverse = reversed;
|
|
186
|
-
this.currentViewportData = undefined;
|
|
187
|
-
this.refreshData();
|
|
188
|
-
}
|
|
189
|
-
setViewport(viewport) {
|
|
190
|
-
this.currentViewport = viewport;
|
|
191
|
-
this.refreshInfo();
|
|
192
|
-
this.refreshData();
|
|
193
|
-
}
|
|
194
|
-
setSorts(config) {
|
|
195
|
-
this.currentSort = config;
|
|
196
|
-
this.currentViewportData = undefined;
|
|
197
|
-
this.refreshData();
|
|
198
|
-
}
|
|
199
|
-
setFilters(config) {
|
|
200
|
-
this.currentFilter = config;
|
|
201
|
-
this.currentViewportData = undefined;
|
|
202
|
-
this.refreshInfo();
|
|
203
|
-
this.refreshData();
|
|
204
|
-
}
|
|
205
|
-
get data() {
|
|
206
|
-
return this.currentViewportData;
|
|
207
|
-
}
|
|
208
|
-
getViewportData() {
|
|
209
|
-
var _this = this;
|
|
210
|
-
return _asyncToGenerator(function* () {
|
|
211
|
-
var _this$viewportUpdateP;
|
|
212
|
-
if (!_this.viewportUpdatePromise) {
|
|
213
|
-
_this.refreshData();
|
|
214
|
-
}
|
|
215
|
-
return (_this$viewportUpdateP = _this.viewportUpdatePromise) !== null && _this$viewportUpdateP !== void 0 ? _this$viewportUpdateP : Promise.resolve({
|
|
216
|
-
items: [],
|
|
217
|
-
offset: 0
|
|
218
|
-
});
|
|
219
|
-
})();
|
|
220
|
-
}
|
|
221
|
-
put(item) {
|
|
222
|
-
var _this2 = this;
|
|
223
|
-
return _asyncToGenerator(function* () {
|
|
224
|
-
// Put the item ID in both the _id and the id slot
|
|
225
|
-
// PouchDB uses _id everywhere, StorageTable just uses `id` though
|
|
226
|
-
var newItem = _objectSpread(_objectSpread({}, item), {}, {
|
|
227
|
-
_id: item.id
|
|
228
|
-
});
|
|
229
|
-
yield _this2.db.put(newItem);
|
|
230
|
-
return newItem;
|
|
231
|
-
})();
|
|
232
|
-
}
|
|
233
|
-
sendUpdate() {
|
|
234
|
-
var _this$currentViewport;
|
|
235
|
-
// Retain a reference to it in case a listener gets removed while sending an update
|
|
236
|
-
var {
|
|
237
|
-
listeners
|
|
238
|
-
} = this;
|
|
239
|
-
var data = (_this$currentViewport = this.currentViewportData) !== null && _this$currentViewport !== void 0 ? _this$currentViewport : {
|
|
240
|
-
items: [],
|
|
241
|
-
offset: 0
|
|
242
|
-
};
|
|
243
|
-
for (var i = 0; i < listeners.length; i += 1) {
|
|
244
|
-
listeners[i](data);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
sendItemUpdate(item) {
|
|
248
|
-
var listeners = this.itemListeners.get(item.id);
|
|
249
|
-
if (listeners !== undefined) {
|
|
250
|
-
for (var i = 0; i < listeners.length; i += 1) {
|
|
251
|
-
listeners[i](item);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
dbUpdate(event) {
|
|
256
|
-
log.debug('Update received', event);
|
|
257
|
-
this.refreshInfo();
|
|
258
|
-
if (event.doc !== undefined) {
|
|
259
|
-
this.sendItemUpdate(event.doc);
|
|
260
|
-
}
|
|
261
|
-
this.refreshData();
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Fetch infor for a given selector.
|
|
266
|
-
* @param selector
|
|
267
|
-
*/
|
|
268
|
-
fetchInfo(selector) {
|
|
269
|
-
var _this3 = this;
|
|
270
|
-
return _asyncToGenerator(function* () {
|
|
271
|
-
return _this3.db.find({
|
|
272
|
-
selector,
|
|
273
|
-
fields: []
|
|
274
|
-
});
|
|
275
|
-
})();
|
|
276
|
-
}
|
|
277
|
-
refreshInfo() {
|
|
278
|
-
var _this4 = this;
|
|
279
|
-
return _asyncToGenerator(function* () {
|
|
280
|
-
try {
|
|
281
|
-
var _this4$infoUpdateProm, _this4$currentFilter;
|
|
282
|
-
(_this4$infoUpdateProm = _this4.infoUpdatePromise) === null || _this4$infoUpdateProm === void 0 ? void 0 : _this4$infoUpdateProm.cancel();
|
|
283
|
-
_this4.infoUpdatePromise = PromiseUtils.makeCancelable(_this4.fetchInfo(selectorWithFilters((_this4$currentFilter = _this4.currentFilter) !== null && _this4$currentFilter !== void 0 ? _this4$currentFilter : [])));
|
|
284
|
-
var findResult = yield _this4.infoUpdatePromise;
|
|
285
|
-
_this4.currentSize = findResult.docs.length;
|
|
286
|
-
_this4.sendUpdate();
|
|
287
|
-
} catch (e) {
|
|
288
|
-
if (!PromiseUtils.isCanceled(e)) {
|
|
289
|
-
log.error('Unable to refreshInfo', e);
|
|
290
|
-
throw e;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
})();
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Fetch data for the given viewport, selector, and sort.
|
|
298
|
-
* @param viewport
|
|
299
|
-
* @param selector
|
|
300
|
-
* @param sort
|
|
301
|
-
*/
|
|
302
|
-
fetchViewportData(viewport, selector, sort) {
|
|
303
|
-
var _this5 = this;
|
|
304
|
-
return _asyncToGenerator(function* () {
|
|
305
|
-
return _this5.db.find({
|
|
306
|
-
selector,
|
|
307
|
-
skip: viewport.top,
|
|
308
|
-
limit: viewport.bottom - viewport.top + 1,
|
|
309
|
-
sort,
|
|
310
|
-
fields: ['id', 'name']
|
|
311
|
-
}).then(findResult => ({
|
|
312
|
-
items: findResult.docs,
|
|
313
|
-
offset: viewport.top
|
|
314
|
-
}));
|
|
315
|
-
})();
|
|
316
|
-
}
|
|
317
|
-
refreshData() {
|
|
318
|
-
var _this6 = this;
|
|
319
|
-
return _asyncToGenerator(function* () {
|
|
320
|
-
if (!_this6.currentViewport) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
try {
|
|
324
|
-
var _this6$currentFilter, _this6$viewportUpdate;
|
|
325
|
-
var selector = selectorWithFilters((_this6$currentFilter = _this6.currentFilter) !== null && _this6$currentFilter !== void 0 ? _this6$currentFilter : []);
|
|
326
|
-
var sort = sortWithConfigs(_this6.currentSort, _this6.currentReverse);
|
|
327
|
-
(_this6$viewportUpdate = _this6.viewportUpdatePromise) === null || _this6$viewportUpdate === void 0 ? void 0 : _this6$viewportUpdate.cancel();
|
|
328
|
-
_this6.viewportUpdatePromise = PromiseUtils.makeCancelable(_this6.fetchViewportData(_this6.currentViewport, selector, sort));
|
|
329
|
-
var viewportData = yield _this6.viewportUpdatePromise;
|
|
330
|
-
_this6.currentViewportData = viewportData;
|
|
331
|
-
_this6.sendUpdate();
|
|
332
|
-
return viewportData;
|
|
333
|
-
} catch (e) {
|
|
334
|
-
if (!PromiseUtils.isCanceled(e)) {
|
|
335
|
-
log.error('Unable to refreshData', e);
|
|
336
|
-
throw e;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
})();
|
|
340
|
-
}
|
|
341
|
-
refreshItem(id) {
|
|
342
|
-
var _this7 = this;
|
|
343
|
-
return _asyncToGenerator(function* () {
|
|
344
|
-
var findResult = yield _this7.db.find({
|
|
345
|
-
selector: {
|
|
346
|
-
id
|
|
347
|
-
},
|
|
348
|
-
limit: 1
|
|
349
|
-
});
|
|
350
|
-
var item = findResult.docs[0];
|
|
351
|
-
if (item !== undefined) {
|
|
352
|
-
_this7.sendItemUpdate(item);
|
|
353
|
-
}
|
|
354
|
-
return item;
|
|
355
|
-
})();
|
|
356
|
-
}
|
|
357
|
-
getSnapshot(sortedRanges) {
|
|
358
|
-
var _this8 = this;
|
|
359
|
-
return _asyncToGenerator(function* () {
|
|
360
|
-
var itemMap = new Map();
|
|
361
|
-
var sort = [{
|
|
362
|
-
id: _this8.currentReverse ? 'desc' : 'asc'
|
|
363
|
-
}];
|
|
364
|
-
yield Promise.all(sortedRanges.map( /*#__PURE__*/function () {
|
|
365
|
-
var _ref2 = _asyncToGenerator(function* (_ref) {
|
|
366
|
-
var _this8$currentFilter;
|
|
367
|
-
var [from, to] = _ref;
|
|
368
|
-
var limit = to - from + 1;
|
|
369
|
-
return _this8.db.find({
|
|
370
|
-
selector: selectorWithFilters((_this8$currentFilter = _this8.currentFilter) !== null && _this8$currentFilter !== void 0 ? _this8$currentFilter : []),
|
|
371
|
-
skip: from,
|
|
372
|
-
limit,
|
|
373
|
-
sort,
|
|
374
|
-
fields: ['id', 'name']
|
|
375
|
-
}).then(findSnapshotResult => {
|
|
376
|
-
for (var i = 0; i < limit; i += 1) {
|
|
377
|
-
var index = from + i;
|
|
378
|
-
itemMap.set(index, findSnapshotResult.docs[i]);
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
return function (_x) {
|
|
383
|
-
return _ref2.apply(this, arguments);
|
|
384
|
-
};
|
|
385
|
-
}()));
|
|
386
|
-
return itemMap;
|
|
387
|
-
})();
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
export default PouchStorageTable;
|
|
391
|
-
//# sourceMappingURL=PouchStorageTable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PouchStorageTable.js","names":["PouchDB","PouchDBFind","Operator","FilterOperator","Type","FilterType","Log","PromiseUtils","log","module","DB_PREFIX","plugin","makePouchFilter","type","value","in","contains","$regex","RegExp","inIgnoreCase","eq","$eq","notEq","$neq","greaterThan","$gt","greaterThanOrEqualTo","$gte","lessThan","$lt","lessThanOrEqualTo","$lte","startsWith","Error","makePouchSelectorFromConfig","config","filterItems","filterOperators","filter","i","length","filterItem","columnName","newFilter","filterOperator","and","$and","or","$or","selectorWithFilters","filters","map","name","id","sortWithConfigs","sorts","reverse","sort","column","direction","PouchStorageTable","constructor","databaseName","dbOptions","Map","db","_remote","listenForChanges","createIndex","index","fields","refreshInfo","changes","live","since","include_docs","on","dbUpdate","bind","onUpdate","callback","listeners","other","onItemUpdate","listener","itemListeners","has","set","get","refreshItem","close","size","currentSize","viewport","currentViewport","setReversed","reversed","currentReverse","currentViewportData","undefined","refreshData","setViewport","setSorts","currentSort","setFilters","currentFilter","data","getViewportData","viewportUpdatePromise","Promise","resolve","items","offset","put","item","newItem","_id","sendUpdate","sendItemUpdate","event","debug","doc","fetchInfo","selector","find","infoUpdatePromise","cancel","makeCancelable","findResult","docs","e","isCanceled","error","fetchViewportData","skip","top","limit","bottom","then","viewportData","getSnapshot","sortedRanges","itemMap","all","from","to","findSnapshotResult"],"sources":["../src/PouchStorageTable.ts"],"sourcesContent":["import PouchDB from 'pouchdb-browser';\nimport PouchDBFind from 'pouchdb-find';\nimport {\n Operator as FilterOperator,\n Type as FilterType,\n} from '@deephaven/filters';\nimport Log from '@deephaven/log';\nimport {\n FilterConfig,\n FilterValue,\n SortConfig,\n StorageItem,\n StorageTable,\n StorageListenerRemover,\n StorageTableViewport,\n StorageItemListener,\n StorageSnapshot,\n ViewportData,\n ViewportUpdateCallback,\n} from '@deephaven/storage';\nimport { CancelablePromise, PromiseUtils } from '@deephaven/utils';\n\nconst log = Log.module('PouchStorageTable');\n\nconst DB_PREFIX = 'Deephaven.';\n\nPouchDB.plugin(PouchDBFind);\n\nexport interface PouchStorageItem {\n _id?: string;\n}\n\nexport type PouchDBSort = Array<\n string | { [propName: string]: 'asc' | 'desc' }\n>;\n\nfunction makePouchFilter(type: string, value: FilterValue | FilterValue[]) {\n switch (type) {\n case FilterType.in:\n case FilterType.contains:\n return { $regex: new RegExp(`${value}`) };\n case FilterType.inIgnoreCase:\n return { $regex: new RegExp(`${value}`, 'i') };\n case FilterType.eq:\n return { $eq: value };\n case FilterType.notEq:\n return { $neq: value };\n case FilterType.greaterThan:\n return { $gt: value };\n case FilterType.greaterThanOrEqualTo:\n return { $gte: value };\n case FilterType.lessThan:\n return { $lt: value };\n case FilterType.lessThanOrEqualTo:\n return { $lte: value };\n case FilterType.startsWith:\n return { $regex: new RegExp(`^(?${value}).*`) };\n default:\n throw new Error(`Unsupported type: ${type}`);\n }\n}\n\nfunction makePouchSelectorFromConfig(\n config: FilterConfig\n): PouchDB.Find.Selector {\n const { filterItems, filterOperators } = config;\n let filter = null;\n for (let i = 0; i < filterItems.length; i += 1) {\n const filterItem = filterItems[i];\n const { columnName, type, value } = filterItem;\n const newFilter = { [columnName]: makePouchFilter(type, value) };\n if (i === 0) {\n filter = newFilter;\n } else if (filter !== null && i - 1 < filterOperators.length) {\n const filterOperator = filterOperators[i - 1];\n if (filterOperator === FilterOperator.and) {\n filter = { $and: [filter, newFilter] };\n } else if (filterOperator === FilterOperator.or) {\n filter = { $or: [filter, newFilter] };\n } else {\n throw new Error(\n `Unexpected filter operator ${filterOperator}, ${newFilter}`\n );\n }\n }\n }\n if (filter == null) {\n throw new Error(`Invalid filter config ${config}`);\n }\n return filter;\n}\n\nfunction selectorWithFilters(\n filters: FilterConfig[] = []\n): PouchDB.Find.Selector {\n return {\n $and: [\n ...filters.map(filter => makePouchSelectorFromConfig(filter)),\n { name: { $gt: null } },\n { id: { $gt: null } },\n ],\n };\n}\n\nfunction sortWithConfigs(\n sorts: SortConfig[] | null,\n reverse = false\n): PouchDBSort {\n return [\n { id: reverse ? 'desc' : 'asc' },\n ...(sorts?.map(sort => ({ [sort.column]: sort.direction })) ?? []),\n ];\n}\n\nexport class PouchStorageTable<T extends StorageItem = StorageItem>\n implements StorageTable<T> {\n protected db: PouchDB.Database<T & PouchStorageItem>;\n\n changes?: PouchDB.Core.Changes<T & PouchStorageItem>;\n\n private listeners: ViewportUpdateCallback<T>[] = [];\n\n private itemListeners: Map<string, StorageItemListener<T>[]> = new Map();\n\n private currentSize = 0;\n\n private currentViewport?: StorageTableViewport;\n\n private currentReverse = false;\n\n private currentFilter: FilterConfig[] | null = null;\n\n private currentSort: SortConfig[] | null = null;\n\n private infoUpdatePromise?: CancelablePromise<\n PouchDB.Find.FindResponse<T & PouchStorageItem>\n >;\n\n private viewportUpdatePromise?: CancelablePromise<ViewportData<T>>;\n\n private currentViewportData?: ViewportData<T>;\n\n constructor(\n databaseName: string,\n dbOptions?: PouchDB.Configuration.DatabaseConfiguration\n ) {\n this.db = new PouchDB<T & PouchStorageItem>(\n `${DB_PREFIX}${databaseName}`,\n dbOptions\n );\n\n // Need to set `_remote` to false to remove deprecation warnings: https://github.com/pouchdb/pouchdb/issues/6106\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, no-underscore-dangle\n (this.db as any)._remote = false;\n\n this.listenForChanges();\n\n this.db.createIndex({ index: { fields: ['id', 'name'] } });\n\n this.refreshInfo();\n }\n\n /**\n * Listen for db changes. This can be cancelled by calling\n * `this.changes?.cancel()`\n */\n listenForChanges(): void {\n this.changes = this.db\n .changes({ live: true, since: 'now', include_docs: true })\n .on('change', this.dbUpdate.bind(this));\n }\n\n onUpdate(callback: ViewportUpdateCallback<T>): StorageListenerRemover {\n this.listeners = [...this.listeners, callback];\n return () => {\n this.listeners = this.listeners.filter(other => other !== callback);\n };\n }\n\n onItemUpdate(\n id: string,\n listener: StorageItemListener<T>\n ): StorageListenerRemover {\n if (!this.itemListeners.has(id)) {\n this.itemListeners.set(id, []);\n }\n\n this.itemListeners.set(id, [\n ...(this.itemListeners.get(id) as StorageItemListener<T>[]),\n listener,\n ]);\n\n this.refreshItem(id);\n\n return () => {\n this.itemListeners.set(\n id,\n (this.itemListeners.get(id) as StorageItemListener<T>[]).filter(\n other => other !== listener\n )\n );\n };\n }\n\n close(): void {\n this.listeners = [];\n }\n\n get size(): number {\n return this.currentSize;\n }\n\n get viewport(): StorageTableViewport | undefined {\n return this.currentViewport;\n }\n\n setReversed(reversed: boolean): void {\n this.currentReverse = reversed;\n\n this.currentViewportData = undefined;\n\n this.refreshData();\n }\n\n setViewport(viewport: StorageTableViewport | undefined): void {\n this.currentViewport = viewport;\n\n this.refreshInfo();\n\n this.refreshData();\n }\n\n setSorts(config: SortConfig[] | null): void {\n this.currentSort = config;\n\n this.currentViewportData = undefined;\n\n this.refreshData();\n }\n\n setFilters(config: FilterConfig[] | null): void {\n this.currentFilter = config;\n\n this.currentViewportData = undefined;\n\n this.refreshInfo();\n\n this.refreshData();\n }\n\n get data(): ViewportData<T> | undefined {\n return this.currentViewportData;\n }\n\n async getViewportData(): Promise<ViewportData<T>> {\n if (!this.viewportUpdatePromise) {\n this.refreshData();\n }\n return (\n this.viewportUpdatePromise ?? Promise.resolve({ items: [], offset: 0 })\n );\n }\n\n async put(item: T): Promise<T> {\n // Put the item ID in both the _id and the id slot\n // PouchDB uses _id everywhere, StorageTable just uses `id` though\n const newItem = {\n ...item,\n _id: item.id,\n } as T;\n\n await this.db.put(newItem);\n\n return newItem;\n }\n\n private sendUpdate() {\n // Retain a reference to it in case a listener gets removed while sending an update\n const { listeners } = this;\n const data = this.currentViewportData ?? { items: [], offset: 0 };\n for (let i = 0; i < listeners.length; i += 1) {\n listeners[i](data);\n }\n }\n\n private sendItemUpdate(item: T) {\n const listeners = this.itemListeners.get(item.id);\n if (listeners !== undefined) {\n for (let i = 0; i < listeners.length; i += 1) {\n listeners[i](item);\n }\n }\n }\n\n protected dbUpdate(event: PouchDB.Core.ChangesResponseChange<T>): void {\n log.debug('Update received', event);\n\n this.refreshInfo();\n\n if (event.doc !== undefined) {\n this.sendItemUpdate(event.doc);\n }\n\n this.refreshData();\n }\n\n /**\n * Fetch infor for a given selector.\n * @param selector\n */\n protected async fetchInfo(\n selector: PouchDB.Find.Selector\n ): Promise<PouchDB.Find.FindResponse<T & PouchStorageItem>> {\n return this.db.find({\n selector,\n fields: [],\n });\n }\n\n private async refreshInfo() {\n try {\n this.infoUpdatePromise?.cancel();\n\n this.infoUpdatePromise = PromiseUtils.makeCancelable(\n this.fetchInfo(selectorWithFilters(this.currentFilter ?? []))\n );\n\n const findResult = await this.infoUpdatePromise;\n\n this.currentSize = findResult.docs.length;\n\n this.sendUpdate();\n } catch (e) {\n if (!PromiseUtils.isCanceled(e)) {\n log.error('Unable to refreshInfo', e);\n throw e;\n }\n }\n }\n\n /**\n * Fetch data for the given viewport, selector, and sort.\n * @param viewport\n * @param selector\n * @param sort\n */\n protected async fetchViewportData(\n viewport: StorageTableViewport,\n selector: PouchDB.Find.Selector,\n sort: PouchDBSort\n ): Promise<ViewportData<T>> {\n return this.db\n .find({\n selector,\n skip: viewport.top,\n limit: viewport.bottom - viewport.top + 1,\n sort,\n fields: ['id', 'name'],\n })\n .then(findResult => ({\n items: findResult.docs,\n offset: viewport.top,\n }));\n }\n\n private async refreshData(): Promise<ViewportData<T> | undefined> {\n if (!this.currentViewport) {\n return;\n }\n\n try {\n const selector = selectorWithFilters(this.currentFilter ?? []);\n const sort = sortWithConfigs(this.currentSort, this.currentReverse);\n\n this.viewportUpdatePromise?.cancel();\n\n this.viewportUpdatePromise = PromiseUtils.makeCancelable(\n this.fetchViewportData(this.currentViewport, selector, sort)\n );\n\n const viewportData = await this.viewportUpdatePromise;\n\n this.currentViewportData = viewportData;\n\n this.sendUpdate();\n\n return viewportData;\n } catch (e) {\n if (!PromiseUtils.isCanceled(e)) {\n log.error('Unable to refreshData', e);\n throw e;\n }\n }\n }\n\n async refreshItem(id: string): Promise<T | undefined> {\n const findResult = await this.db.find({\n selector: { id },\n limit: 1,\n });\n\n const item = findResult.docs[0];\n\n if (item !== undefined) {\n this.sendItemUpdate(item);\n }\n\n return item;\n }\n\n async getSnapshot(\n sortedRanges: [number, number][]\n ): Promise<StorageSnapshot<T>> {\n const itemMap = new Map();\n\n const sort: PouchDBSort = [{ id: this.currentReverse ? 'desc' : 'asc' }];\n\n await Promise.all(\n sortedRanges.map(async ([from, to]) => {\n const limit = to - from + 1;\n return this.db\n .find({\n selector: selectorWithFilters(this.currentFilter ?? []),\n skip: from,\n limit,\n sort,\n fields: ['id', 'name'],\n })\n .then(findSnapshotResult => {\n for (let i = 0; i < limit; i += 1) {\n const index = from + i;\n itemMap.set(index, findSnapshotResult.docs[i]);\n }\n });\n })\n );\n\n return itemMap;\n }\n}\n\nexport default PouchStorageTable;\n"],"mappings":";;;;;;;AAAA,OAAOA,OAAO,MAAM,iBAAiB;AACrC,OAAOC,WAAW,MAAM,cAAc;AACtC,SACEC,QAAQ,IAAIC,cAAc,EAC1BC,IAAI,IAAIC,UAAU,QACb,oBAAoB;AAC3B,OAAOC,GAAG,MAAM,gBAAgB;AAchC,SAA4BC,YAAY,QAAQ,kBAAkB;AAElE,IAAMC,GAAG,GAAGF,GAAG,CAACG,MAAM,CAAC,mBAAmB,CAAC;AAE3C,IAAMC,SAAS,GAAG,YAAY;AAE9BV,OAAO,CAACW,MAAM,CAACV,WAAW,CAAC;AAU3B,SAASW,eAAe,CAACC,IAAY,EAAEC,KAAkC,EAAE;EACzE,QAAQD,IAAI;IACV,KAAKR,UAAU,CAACU,EAAE;IAClB,KAAKV,UAAU,CAACW,QAAQ;MACtB,OAAO;QAAEC,MAAM,EAAE,IAAIC,MAAM,WAAIJ,KAAK;MAAI,CAAC;IAC3C,KAAKT,UAAU,CAACc,YAAY;MAC1B,OAAO;QAAEF,MAAM,EAAE,IAAIC,MAAM,WAAIJ,KAAK,GAAI,GAAG;MAAE,CAAC;IAChD,KAAKT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EjG,CAAC,IAAI,CAAC,EAAE;cACjC,IAAM8B,KAAK,GAAG2E,IAAI,GAAGzG,CAAC;cACtBuG,OAAO,CAACvD,GAAG,CAAClB,KAAK,EAAE6E,kBAAkB,CAACjB,IAAI,CAAC1F,CAAC,CAAC,CAAC;YAChD;UACF,CAAC,CAAC;QACN,CAAC;QAAA;UAAA;QAAA;MAAA,IAAC,CACH;MAED,OAAOuG,OAAO;IAAC;EACjB;AACF;AAEA,eAAelF,iBAAiB"}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './PouchCommandHistoryStorage';\n"],"mappings":""}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Takes an array of items and determines which ones to keep and which ones to
|
|
3
|
-
* prune based on the given thresholds.
|
|
4
|
-
* @param items items to keep or prune
|
|
5
|
-
* @param maxItems maximum number of items to allow before pruning
|
|
6
|
-
* @param pruneItemsCount if the maxItems count is exceeded, the number we want to keep
|
|
7
|
-
*/
|
|
8
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
9
|
-
export function siftPrunableItems(items, maxItems, pruneItemsCount) {
|
|
10
|
-
if (items.length > maxItems) {
|
|
11
|
-
var pruneCount = items.length - pruneItemsCount;
|
|
12
|
-
return {
|
|
13
|
-
toKeep: items.slice(pruneCount),
|
|
14
|
-
toPrune: items.slice(0, pruneCount)
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
toKeep: items,
|
|
19
|
-
toPrune: []
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=pouchCommandHistoryUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pouchCommandHistoryUtils.js","names":["siftPrunableItems","items","maxItems","pruneItemsCount","length","pruneCount","toKeep","slice","toPrune"],"sources":["../src/pouchCommandHistoryUtils.ts"],"sourcesContent":["/**\n * Takes an array of items and determines which ones to keep and which ones to\n * prune based on the given thresholds.\n * @param items items to keep or prune\n * @param maxItems maximum number of items to allow before pruning\n * @param pruneItemsCount if the maxItems count is exceeded, the number we want to keep\n */\n// eslint-disable-next-line import/prefer-default-export\nexport function siftPrunableItems<T>(\n items: T[],\n maxItems: number,\n pruneItemsCount: number\n): {\n toKeep: T[];\n toPrune: T[];\n} {\n if (items.length > maxItems) {\n const pruneCount = items.length - pruneItemsCount;\n return {\n toKeep: items.slice(pruneCount),\n toPrune: items.slice(0, pruneCount),\n };\n }\n\n return {\n toKeep: items,\n toPrune: [],\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,iBAAiB,CAC/BC,KAAU,EACVC,QAAgB,EAChBC,eAAuB,EAIvB;EACA,IAAIF,KAAK,CAACG,MAAM,GAAGF,QAAQ,EAAE;IAC3B,IAAMG,UAAU,GAAGJ,KAAK,CAACG,MAAM,GAAGD,eAAe;IACjD,OAAO;MACLG,MAAM,EAAEL,KAAK,CAACM,KAAK,CAACF,UAAU,CAAC;MAC/BG,OAAO,EAAEP,KAAK,CAACM,KAAK,CAAC,CAAC,EAAEF,UAAU;IACpC,CAAC;EACH;EAEA,OAAO;IACLC,MAAM,EAAEL,KAAK;IACbO,OAAO,EAAE;EACX,CAAC;AACH"}
|