updated configs, wipeDatabase function, changes sharing

This commit is contained in:
Mason Houtz
2020-12-30 12:09:44 -08:00
parent c2b1b87c51
commit eff56d1219
17 changed files with 38 additions and 27 deletions
@@ -17,7 +17,7 @@ export * from "./db/promises";
export { loadDscContent } from "./loadDscContent";
export { loadHistoryContents, clearHistoryDateStore } from "./loadHistoryContents";
export { monitorHistoryContent } from "./monitorHistoryContent";
export { wipeDatabase } from "./db/pouch";
export { wipeDatabase } from "./db/wipeDatabase";
// generic content query monitor
export const monitorContentQuery = (cfg = {}) => {
@@ -1,8 +1,8 @@
import { pipe, Observable } from "rxjs";
import { switchMap, filter, share } from "rxjs/operators";
import { switchMap, filter, share, shareReplay } from "rxjs/operators";
// feed observables, keyed by underlying database instance
const feeds = new Map();
export const feeds = new Map();
/**
* Returns an observable with all the change events from the indicated database
@@ -12,6 +12,7 @@ const feeds = new Map();
export const changes = (cfg = {}) => {
return pipe(
switchMap((db) => {
// console.log("subscribing to changes", db.name);
if (!feeds.has(db)) {
feeds.set(db, buildFeed(db, cfg));
}
@@ -19,7 +20,6 @@ export const changes = (cfg = {}) => {
}),
// filter out index creation which can appear as a change
filter(({ id }) => !id.includes("_design")),
share()
);
};
@@ -31,11 +31,17 @@ export const changes = (cfg = {}) => {
const buildFeed = (db, cfg = {}) => {
const { live = true, returnDocs = true, include_docs = true, since = "now", timeout = false } = cfg;
return new Observable((obs) => {
const feed$ = new Observable((obs) => {
// console.log("creating feed", db.name);
const changeOpts = { live, include_docs, returnDocs, since, timeout };
const feed = db.changes(changeOpts);
feed.on("change", (update) => obs.next(update));
feed.on("error", (err) => obs.error(err));
return () => feed.cancel();
return () => {
// console.log("cancelling feed", db.name);
feed.cancel();
}
});
return feed$.pipe(share());
};
@@ -1,6 +1,6 @@
import { takeWhile, share } from "rxjs/operators";
import { content$, dscContent$ } from "./observables";
import { wipeDatabase } from "./pouch";
import { wipeDatabase } from "./wipeDatabase";
import {
bulkCacheContent,
cacheContent,
@@ -1,6 +1,6 @@
import isPromise from "is-promise";
import { isObservable } from "rxjs";
import { wipeDatabase } from "./pouch";
import { wipeDatabase } from "./wipeDatabase";
import { content$, dscContent$, buildContentId, buildCollectionId, prepContent, prepDscContent } from "./observables";
import { firstValueFrom } from "utils/observable/firstValueFrom";
@@ -2,7 +2,7 @@ import { Subject } from "rxjs";
import { take } from "rxjs/operators";
import { ObserverSpy } from "@hirez_io/observer-spy";
import { wipeDatabase } from "./pouch";
import { wipeDatabase } from "./wipeDatabase";
import { bulkCacheContent, bulkCacheDscContent } from "./promises";
import { content$, dscContent$, buildContentId } from "./observables";
import { find } from "./find";
@@ -13,4 +13,4 @@ export { changes } from "./changes";
export { monitorQuery } from "./monitorQuery";
// utility function
export { wipeDatabase } from "./pouch";
export { wipeDatabase } from "./wipeDatabase";
@@ -2,7 +2,7 @@ import { of, timer } from "rxjs";
import { take, takeUntil } from "rxjs/operators";
import { ObserverSpy } from "@hirez_io/observer-spy";
import { wait } from "jest/helpers";
import { wipeDatabase } from "./pouch";
import { wipeDatabase } from "./wipeDatabase";
import { monitorQuery, ACTIONS } from "./monitorQuery";
import { content$, dscContent$ } from "./observables";
@@ -8,6 +8,7 @@ import deepEqual from "deep-equal";
import { defer, pipe, from } from "rxjs";
import { tap, filter, mergeMap, reduce, shareReplay } from "rxjs/operators";
import { needs } from "../operators/needs";
import { dasherize } from "underscore.string";
import PouchDB from "pouchdb";
import PouchAdapterMemory from "pouchdb-adapter-memory";
@@ -27,7 +28,7 @@ PouchDB.plugin(PouchErase);
// const show = (obj) => console.log(JSON.stringify(obj, null, 4));
// Instance storage map, keyed by database name
const dbs = new Map();
export const dbs = new Map();
/**
* Generate an observable that initializes and shares a pouchdb instance.
@@ -71,7 +72,7 @@ async function buildCollection(opts, appConfig) {
function collectionName(opts, appConfig) {
const { name: dbName } = opts;
const { name: envName } = appConfig;
return `${dbName}-${envName}`;
return dasherize(`${dbName} ${envName}`);
}
async function installCollectionIndexes(db, indexes = []) {
@@ -231,11 +232,3 @@ export async function deleteIndexes(db) {
return await Promise.all(promises);
}
/**
* Erases all stored database instances
*/
export async function wipeDatabase() {
for (const db of dbs.values()) {
await db.erase();
}
}
@@ -0,0 +1,10 @@
import { dbs } from "./pouch";
/**
* Erases all stored database instances
*/
export async function wipeDatabase() {
for (const db of dbs.values()) {
await db.erase();
}
}
@@ -1,7 +1,7 @@
import { timer, of } from "rxjs";
import { take, pluck, takeUntil } from "rxjs/operators";
import { firstValueFrom } from "utils/observable/firstValueFrom";
import { wipeDatabase } from "../caching/db/pouch";
import { wipeDatabase } from "./db/wipeDatabase";
import { wait } from "jest/helpers";
import { ObserverSpy } from "@hirez_io/observer-spy";
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
import { createLocalVue } from "@vue/test-utils";
import { wait, mountRenderless } from "jest/helpers";
import { wipeDatabase } from "../../caching/db/pouch";
import { wipeDatabase } from "../../caching";
import { cacheContent, getCachedContent, cacheCollectionContent, getCachedCollectionContent } from "../../caching";
import { DatasetCollection } from "../../model/DatasetCollection";
import DscProvider from "./DscProvider";
@@ -8,6 +8,7 @@ import { loadWebhookMenuItems } from "./_webhooks";
jest.mock("app");
jest.mock("layout/menu");
jest.mock("./_webhooks");
jest.mock("../History/caching");
describe("Masthead.vue", () => {
let wrapper;
@@ -6,6 +6,7 @@ import { shallowMount, createLocalVue } from "@vue/test-utils";
import BootstrapVue from "bootstrap-vue";
jest.mock("app");
jest.mock("../History/caching");
const propsData = {
chunkUploadSize: 1024,
+1 -1
View File
@@ -1,5 +1,5 @@
export default {
name: "development configs",
name: "development",
debug: true,
rxjsDebug: true,
caching: {
+1 -1
View File
@@ -1,5 +1,5 @@
export default {
name: "production configs",
name: "production",
debug: false,
rxjsDebug: false,
caching: {
+1 -1
View File
@@ -1,5 +1,5 @@
export default {
name: "unit testing configs",
name: "testing",
testBuild: true,
debug: false,
rxjsDebug: false,
+1 -1
View File
@@ -1,5 +1,5 @@
export default {
name: "unit testing configs",
name: "testing",
testBuild: true,
debug: false,
caching: {