@vue-skuilder/db 0.2.35 → 0.2.37
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/CLAUDE.md +15 -4
- package/build.entries.mjs +12 -0
- package/dist/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/{contentSource-BteiDpxH.d.ts → contentSource-D_E7JaxR.d.ts} +1 -1
- package/dist/core/UserDBDebugger.mjs +285 -0
- package/dist/core/UserDBDebugger.mjs.map +1 -0
- package/dist/core/bulkImport/cardProcessor.mjs +106 -0
- package/dist/core/bulkImport/cardProcessor.mjs.map +1 -0
- package/dist/core/{index.js → index.cjs} +6413 -7738
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.mjs +20 -11368
- package/dist/core/interfaces/contentSource.mjs +20 -0
- package/dist/core/interfaces/contentSource.mjs.map +1 -0
- package/dist/core/navigators/Pipeline.mjs +723 -0
- package/dist/core/navigators/Pipeline.mjs.map +1 -0
- package/dist/core/navigators/PipelineAssembler.mjs +86 -0
- package/dist/core/navigators/PipelineAssembler.mjs.map +1 -0
- package/dist/core/navigators/PipelineDebugger.mjs +771 -0
- package/dist/core/navigators/PipelineDebugger.mjs.map +1 -0
- package/dist/core/navigators/SrsDebugger.mjs +34 -0
- package/dist/core/navigators/SrsDebugger.mjs.map +1 -0
- package/dist/core/navigators/StrategyPressureDebugger.mjs +19 -0
- package/dist/core/navigators/StrategyPressureDebugger.mjs.map +1 -0
- package/dist/core/navigators/defaults.mjs +96 -0
- package/dist/core/navigators/defaults.mjs.map +1 -0
- package/dist/core/navigators/diversityRerank.mjs +85 -0
- package/dist/core/navigators/diversityRerank.mjs.map +1 -0
- package/dist/core/navigators/filters/WeightedFilter.mjs +81 -0
- package/dist/core/navigators/filters/WeightedFilter.mjs.map +1 -0
- package/dist/core/navigators/filters/eloDistance.mjs +244 -0
- package/dist/core/navigators/filters/eloDistance.mjs.map +1 -0
- package/dist/core/navigators/filters/hierarchyDefinition.mjs +235 -0
- package/dist/core/navigators/filters/hierarchyDefinition.mjs.map +1 -0
- package/dist/core/navigators/filters/interferenceMitigator.mjs +201 -0
- package/dist/core/navigators/filters/interferenceMitigator.mjs.map +1 -0
- package/dist/core/navigators/filters/relativePriority.mjs +135 -0
- package/dist/core/navigators/filters/relativePriority.mjs.map +1 -0
- package/dist/core/navigators/filters/userTagPreference.mjs +101 -0
- package/dist/core/navigators/filters/userTagPreference.mjs.map +1 -0
- package/dist/core/navigators/generators/CompositeGenerator.mjs +203 -0
- package/dist/core/navigators/generators/CompositeGenerator.mjs.map +1 -0
- package/dist/core/navigators/generators/elo.mjs +77 -0
- package/dist/core/navigators/generators/elo.mjs.map +1 -0
- package/dist/core/navigators/generators/prescribed.mjs +694 -0
- package/dist/core/navigators/generators/prescribed.mjs.map +1 -0
- package/dist/core/navigators/generators/srs.mjs +158 -0
- package/dist/core/navigators/generators/srs.mjs.map +1 -0
- package/dist/core/navigators/index.mjs +345 -0
- package/dist/core/navigators/index.mjs.map +1 -0
- package/dist/core/navigators/pipelinePlan.mjs +109 -0
- package/dist/core/navigators/pipelinePlan.mjs.map +1 -0
- package/dist/core/navigators/regulators.mjs +128 -0
- package/dist/core/navigators/regulators.mjs.map +1 -0
- package/dist/core/orchestration/gradient.mjs +101 -0
- package/dist/core/orchestration/gradient.mjs.map +1 -0
- package/dist/core/orchestration/index.mjs +115 -0
- package/dist/core/orchestration/index.mjs.map +1 -0
- package/dist/core/orchestration/learning.mjs +140 -0
- package/dist/core/orchestration/learning.mjs.map +1 -0
- package/dist/core/orchestration/recording.mjs +64 -0
- package/dist/core/orchestration/recording.mjs.map +1 -0
- package/dist/core/orchestration/signal.mjs +40 -0
- package/dist/core/orchestration/signal.mjs.map +1 -0
- package/dist/core/types/contentNavigationStrategy.mjs +10 -0
- package/dist/core/types/contentNavigationStrategy.mjs.map +1 -0
- package/dist/core/types/hydration.mjs +13 -0
- package/dist/core/types/hydration.mjs.map +1 -0
- package/dist/core/types/strategyState.mjs +16 -0
- package/dist/core/types/strategyState.mjs.map +1 -0
- package/dist/core/types/studySession.mjs +14 -0
- package/dist/core/types/studySession.mjs.map +1 -0
- package/dist/core/types/types-legacy.mjs +44 -0
- package/dist/core/types/types-legacy.mjs.map +1 -0
- package/dist/core/util/index.mjs +31 -0
- package/dist/core/util/index.mjs.map +1 -0
- package/dist/core/versionStamps.mjs +46 -0
- package/dist/core/versionStamps.mjs.map +1 -0
- package/dist/courseConfigRegistration.mjs +306 -0
- package/dist/courseConfigRegistration.mjs.map +1 -0
- package/dist/{dataLayerProvider-C_QWzHf-.d.ts → dataLayerProvider-BDshhSp_.d.ts} +1 -1
- package/dist/diagnostics/dataset.mjs +118 -0
- package/dist/diagnostics/dataset.mjs.map +1 -0
- package/dist/diagnostics/derive.mjs +318 -0
- package/dist/diagnostics/derive.mjs.map +1 -0
- package/dist/diagnostics/{index.js → index.cjs} +1 -1
- package/dist/diagnostics/index.d.ts +3 -3
- package/dist/diagnostics/index.mjs +7 -1042
- package/dist/diagnostics/loader.mjs +151 -0
- package/dist/diagnostics/loader.mjs.map +1 -0
- package/dist/diagnostics/pipeline.mjs +161 -0
- package/dist/diagnostics/pipeline.mjs.map +1 -0
- package/dist/diagnostics/tagElo.mjs +177 -0
- package/dist/diagnostics/tagElo.mjs.map +1 -0
- package/dist/diagnostics/text.mjs +174 -0
- package/dist/diagnostics/text.mjs.map +1 -0
- package/dist/factory.mjs +70 -0
- package/dist/factory.mjs.map +1 -0
- package/dist/impl/common/BaseUserDB.mjs +1115 -0
- package/dist/impl/common/BaseUserDB.mjs.map +1 -0
- package/dist/impl/common/userDBHelpers.mjs +49 -0
- package/dist/impl/common/userDBHelpers.mjs.map +1 -0
- package/dist/impl/common/userDBKeys.mjs +45 -0
- package/dist/impl/common/userDBKeys.mjs.map +1 -0
- package/dist/impl/couch/CouchDBSyncStrategy.mjs +272 -0
- package/dist/impl/couch/CouchDBSyncStrategy.mjs.map +1 -0
- package/dist/impl/couch/CourseSyncService.mjs +320 -0
- package/dist/impl/couch/CourseSyncService.mjs.map +1 -0
- package/dist/impl/couch/PouchDataLayerProvider.mjs +89 -0
- package/dist/impl/couch/PouchDataLayerProvider.mjs.map +1 -0
- package/dist/impl/couch/adminDB.mjs +61 -0
- package/dist/impl/couch/adminDB.mjs.map +1 -0
- package/dist/impl/couch/auth.mjs +33 -0
- package/dist/impl/couch/auth.mjs.map +1 -0
- package/dist/impl/couch/classroomDB.mjs +227 -0
- package/dist/impl/couch/classroomDB.mjs.map +1 -0
- package/dist/impl/couch/clientCache.mjs +15 -0
- package/dist/impl/couch/clientCache.mjs.map +1 -0
- package/dist/impl/couch/courseAPI.mjs +197 -0
- package/dist/impl/couch/courseAPI.mjs.map +1 -0
- package/dist/impl/couch/courseDB.mjs +735 -0
- package/dist/impl/couch/courseDB.mjs.map +1 -0
- package/dist/impl/couch/courseLookupDB.mjs +94 -0
- package/dist/impl/couch/courseLookupDB.mjs.map +1 -0
- package/dist/impl/couch/{index.js → index.cjs} +7003 -10358
- package/dist/impl/couch/index.cjs.map +1 -0
- package/dist/impl/couch/index.d.ts +33 -5
- package/dist/impl/couch/index.mjs +152 -12147
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/couch/pouchdb-setup.mjs +15 -0
- package/dist/impl/couch/pouchdb-setup.mjs.map +1 -0
- package/dist/impl/couch/updateQueue.mjs +101 -0
- package/dist/impl/couch/updateQueue.mjs.map +1 -0
- package/dist/impl/couch/user-course-relDB.mjs +55 -0
- package/dist/impl/couch/user-course-relDB.mjs.map +1 -0
- package/dist/impl/static/NoOpSyncStrategy.mjs +49 -0
- package/dist/impl/static/NoOpSyncStrategy.mjs.map +1 -0
- package/dist/impl/static/StaticDataLayerProvider.mjs +94 -0
- package/dist/impl/static/StaticDataLayerProvider.mjs.map +1 -0
- package/dist/impl/static/StaticDataUnpacker.mjs +311 -0
- package/dist/impl/static/StaticDataUnpacker.mjs.map +1 -0
- package/dist/impl/static/courseDB.mjs +368 -0
- package/dist/impl/static/courseDB.mjs.map +1 -0
- package/dist/impl/static/coursesDB.mjs +38 -0
- package/dist/impl/static/coursesDB.mjs.map +1 -0
- package/dist/impl/static/{index.js → index.cjs} +2486 -5993
- package/dist/impl/static/index.cjs.map +1 -0
- package/dist/impl/static/index.d.ts +4 -4
- package/dist/impl/static/index.mjs +6 -10741
- package/dist/{index-C745YB_6.d.ts → index-BLDpFYG3.d.ts} +1 -1
- package/dist/{index.js → index.cjs} +14190 -14249
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +12 -23
- package/dist/index.mjs +38 -16937
- package/dist/pouch/{index.js → index.cjs} +5 -1
- package/dist/pouch/index.cjs.map +1 -0
- package/dist/pouch/index.mjs +2 -19
- package/dist/study/ItemQueue.mjs +95 -0
- package/dist/study/ItemQueue.mjs.map +1 -0
- package/dist/study/MixerDebugger.mjs +303 -0
- package/dist/study/MixerDebugger.mjs.map +1 -0
- package/dist/study/SessionController.mjs +1187 -0
- package/dist/study/SessionController.mjs.map +1 -0
- package/dist/study/SessionDebugger.mjs +271 -0
- package/dist/study/SessionDebugger.mjs.map +1 -0
- package/dist/study/SessionOverlay.mjs +407 -0
- package/dist/study/SessionOverlay.mjs.map +1 -0
- package/dist/study/SourceMixer.mjs +45 -0
- package/dist/study/SourceMixer.mjs.map +1 -0
- package/dist/study/SpacedRepetition.mjs +108 -0
- package/dist/study/SpacedRepetition.mjs.map +1 -0
- package/dist/study/TagFilteredContentSource.mjs +136 -0
- package/dist/study/TagFilteredContentSource.mjs.map +1 -0
- package/dist/study/services/CardHydrationService.mjs +172 -0
- package/dist/study/services/CardHydrationService.mjs.map +1 -0
- package/dist/study/services/EloService.mjs +217 -0
- package/dist/study/services/EloService.mjs.map +1 -0
- package/dist/study/services/ResponseProcessor.mjs +190 -0
- package/dist/study/services/ResponseProcessor.mjs.map +1 -0
- package/dist/study/services/SrsService.mjs +49 -0
- package/dist/study/services/SrsService.mjs.map +1 -0
- package/dist/study/services/tagRecent.mjs +65 -0
- package/dist/study/services/tagRecent.mjs.map +1 -0
- package/dist/{types-DF0JuPbs.d.ts → types-DChCz22D.d.ts} +1 -1
- package/dist/{types-legacy-DdVjg81H.d.cts → types-legacy-fT5Y1Wuy.d.ts} +1 -1
- package/dist/userDBKeys-ne1g4Xuq.d.ts +16 -0
- package/dist/util/Loggable.mjs +14 -0
- package/dist/util/Loggable.mjs.map +1 -0
- package/dist/util/dataDirectory.mjs +47 -0
- package/dist/util/dataDirectory.mjs.map +1 -0
- package/dist/util/logger.mjs +86 -0
- package/dist/util/logger.mjs.map +1 -0
- package/dist/util/migrator/FileSystemAdapter.mjs +18 -0
- package/dist/util/migrator/FileSystemAdapter.mjs.map +1 -0
- package/dist/util/migrator/StaticToCouchDBMigrator.mjs +428 -0
- package/dist/util/migrator/StaticToCouchDBMigrator.mjs.map +1 -0
- package/dist/util/migrator/types.mjs +11 -0
- package/dist/util/migrator/types.mjs.map +1 -0
- package/dist/util/migrator/validation.mjs +334 -0
- package/dist/util/migrator/validation.mjs.map +1 -0
- package/dist/util/packer/CouchDBToStaticPacker.mjs +438 -0
- package/dist/util/packer/CouchDBToStaticPacker.mjs.map +1 -0
- package/dist/util/packer/{index.js → index.cjs} +73 -9
- package/dist/util/packer/index.cjs.map +1 -0
- package/dist/util/packer/index.d.ts +3 -3
- package/dist/util/packer/index.mjs +2 -537
- package/eslint.config.mjs +9 -1
- package/package.json +25 -13
- package/rolldown.config.mjs +44 -0
- package/src/core/UserDBDebugger.ts +47 -46
- package/src/core/navigators/Pipeline.ts +10 -10
- package/src/core/navigators/PipelineDebugger.ts +55 -55
- package/src/core/navigators/filters/eloDistance.ts +1 -1
- package/src/core/navigators/generators/elo.ts +5 -1
- package/src/core/navigators/generators/prescribed.ts +42 -16
- package/src/core/navigators/index.ts +9 -3
- package/src/factory.ts +10 -1
- package/src/impl/common/BaseUserDB.ts +16 -5
- package/src/impl/common/index.ts +2 -0
- package/src/impl/common/userDBHelpers.ts +4 -58
- package/src/impl/common/userDBKeys.ts +64 -0
- package/src/impl/couch/CourseSyncService.ts +130 -20
- package/src/impl/couch/PouchDataLayerProvider.ts +14 -1
- package/src/impl/couch/courseAPI.ts +26 -12
- package/src/impl/couch/courseDB.ts +35 -15
- package/src/impl/couch/index.ts +18 -23
- package/src/impl/couch/pouchdb-setup.ts +8 -0
- package/src/index.ts +1 -1
- package/src/study/MixerDebugger.ts +46 -46
- package/src/study/SessionDebugger.ts +20 -20
- package/src/study/SessionOverlay.ts +4 -4
- package/src/util/logger.ts +112 -13
- package/tests/core/navigators/eloGenerator.test.ts +36 -0
- package/tests/impl/courseSync.test.ts +139 -0
- package/tsup.config.ts +24 -21
- package/dist/SyncStrategy-BXliog1m.d.cts +0 -116
- package/dist/classroomDB-DLTtLZct.d.cts +0 -86
- package/dist/contentSource-FQZcZopC.d.cts +0 -2007
- package/dist/core/index.d.cts +0 -521
- package/dist/core/index.js.map +0 -1
- package/dist/core/index.mjs.map +0 -1
- package/dist/dataLayerProvider-3y21KtF-.d.cts +0 -61
- package/dist/diagnostics/index.d.cts +0 -561
- package/dist/diagnostics/index.mjs.map +0 -1
- package/dist/impl/couch/index.d.cts +0 -620
- package/dist/impl/couch/index.js.map +0 -1
- package/dist/impl/static/index.d.cts +0 -232
- package/dist/impl/static/index.js.map +0 -1
- package/dist/impl/static/index.mjs.map +0 -1
- package/dist/index-BIum9Ue2.d.cts +0 -137
- package/dist/index.d.cts +0 -1663
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/pouch/index.d.cts +0 -1
- package/dist/pouch/index.js.map +0 -1
- package/dist/pouch/index.mjs.map +0 -1
- package/dist/types-BcWVH4ww.d.cts +0 -58
- package/dist/types-legacy-DdVjg81H.d.ts +0 -168
- package/dist/util/packer/index.d.cts +0 -5
- package/dist/util/packer/index.js.map +0 -1
- package/dist/util/packer/index.mjs.map +0 -1
- package/src/study/getCardDataShape.ts +0 -34
- /package/dist/diagnostics/{index.js.map → index.cjs.map} +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
+
import PouchDB from 'pouchdb';
|
|
3
|
+
import memoryAdapter from 'pouchdb-adapter-memory';
|
|
4
|
+
|
|
5
|
+
PouchDB.plugin(memoryAdapter);
|
|
6
|
+
|
|
7
|
+
// Local replicas: in-memory PouchDB. The memory adapter keys stores by name,
|
|
8
|
+
// so a new handle with the same name (a "page load") sees the same data, as an
|
|
9
|
+
// IndexedDB replica would.
|
|
10
|
+
vi.mock('@db/impl/couch/pouchdb-setup', async () => {
|
|
11
|
+
const Pouch = (await import('pouchdb')).default;
|
|
12
|
+
const memory = (await import('pouchdb-adapter-memory')).default;
|
|
13
|
+
Pouch.plugin(memory);
|
|
14
|
+
return { default: Pouch.defaults({ adapter: 'memory' }) };
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const { CourseSyncService } = await import('@db/impl/couch/CourseSyncService');
|
|
18
|
+
|
|
19
|
+
// A course ID per test, so each test has its own local replica (no teardown).
|
|
20
|
+
let COURSE = '';
|
|
21
|
+
const MARKER = '_local/sk-course-sync-complete';
|
|
22
|
+
|
|
23
|
+
let remote: PouchDB.Database;
|
|
24
|
+
let n = 0;
|
|
25
|
+
|
|
26
|
+
/** A fresh service instance, i.e. a new page load, with `remote` as the server. */
|
|
27
|
+
function pageLoad() {
|
|
28
|
+
// Abandon the previous instance, as a reload does. (resetInstance() would
|
|
29
|
+
// start closing its handles, and a new handle on the same store waits on that.)
|
|
30
|
+
(CourseSyncService as any).instance = null;
|
|
31
|
+
const service = CourseSyncService.getInstance();
|
|
32
|
+
vi.spyOn(service as any, 'getRemoteDB').mockImplementation(() => remote);
|
|
33
|
+
return service;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function local() {
|
|
37
|
+
return new PouchDB(`coursedb-local-${COURSE}`, { adapter: 'memory' });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function hasMarker(): Promise<boolean> {
|
|
41
|
+
try {
|
|
42
|
+
await local().get(MARKER);
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
beforeEach(async () => {
|
|
50
|
+
COURSE = `course-sync-test-${n}`;
|
|
51
|
+
remote = new PouchDB(`remote-${COURSE}-${n++}`, { adapter: 'memory' });
|
|
52
|
+
await remote.bulkDocs([
|
|
53
|
+
{ _id: 'db-epoch', epoch: 1 },
|
|
54
|
+
{ _id: 'c-1', docType: 'CARD' },
|
|
55
|
+
{ _id: 'c-2', docType: 'CARD' },
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
(CourseSyncService as any).instance = null;
|
|
61
|
+
vi.restoreAllMocks();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('CourseSyncService: replica ready from the marker', () => {
|
|
65
|
+
it('first sync replicates everything and writes the marker', async () => {
|
|
66
|
+
const service = pageLoad();
|
|
67
|
+
await service.ensureSynced(COURSE, true);
|
|
68
|
+
|
|
69
|
+
expect(service.isReady(COURSE)).toBe(true);
|
|
70
|
+
expect(await hasMarker()).toBe(true);
|
|
71
|
+
await expect(service.getLocalDB(COURSE)!.get('c-2')).resolves.toBeTruthy();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('next page load: ready immediately, refreshed in the background', async () => {
|
|
75
|
+
await pageLoad().ensureSynced(COURSE, true);
|
|
76
|
+
await remote.put({ _id: 'c-3', docType: 'CARD' });
|
|
77
|
+
|
|
78
|
+
const service = pageLoad();
|
|
79
|
+
const replicate = vi.spyOn(service as any, 'replicate');
|
|
80
|
+
await service.ensureSynced(COURSE, true);
|
|
81
|
+
|
|
82
|
+
// Ready before the refresh pulls the new doc (handed out from the marker).
|
|
83
|
+
expect(service.isReady(COURSE)).toBe(true);
|
|
84
|
+
const db = service.getLocalDB(COURSE)!;
|
|
85
|
+
|
|
86
|
+
await vi.waitFor(async () => {
|
|
87
|
+
expect(service.getStatus(COURSE)?.docsReplicated).toBe(1);
|
|
88
|
+
});
|
|
89
|
+
expect(replicate).toHaveBeenCalledTimes(1);
|
|
90
|
+
await expect(db.get('c-3')).resolves.toBeTruthy();
|
|
91
|
+
// Same DB throughout: readers keep their handle.
|
|
92
|
+
expect(service.getLocalDB(COURSE)).toBe(db);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('remote recreated: keeps the outdated replica this page, rebuilds on the next', async () => {
|
|
96
|
+
await pageLoad().ensureSynced(COURSE, true);
|
|
97
|
+
|
|
98
|
+
// "Recreate" the remote: new epoch, different content.
|
|
99
|
+
remote = new PouchDB(`remote-${COURSE}-${n++}`, { adapter: 'memory' });
|
|
100
|
+
await remote.bulkDocs([
|
|
101
|
+
{ _id: 'db-epoch', epoch: 2 },
|
|
102
|
+
{ _id: 'c-new', docType: 'CARD' },
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
const service = pageLoad();
|
|
106
|
+
await service.ensureSynced(COURSE, true);
|
|
107
|
+
const db = service.getLocalDB(COURSE)!;
|
|
108
|
+
|
|
109
|
+
await vi.waitFor(async () => {
|
|
110
|
+
expect(await hasMarker()).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
// Not destroyed under readers: still ready, still the old content.
|
|
113
|
+
expect(service.isReady(COURSE)).toBe(true);
|
|
114
|
+
await expect(db.get('c-1')).resolves.toBeTruthy();
|
|
115
|
+
|
|
116
|
+
// Next page load: no marker, so the full path rebuilds from the new remote.
|
|
117
|
+
const next = pageLoad();
|
|
118
|
+
await next.ensureSynced(COURSE, true);
|
|
119
|
+
const rebuilt = next.getLocalDB(COURSE)!;
|
|
120
|
+
await expect(rebuilt.get('c-new')).resolves.toBeTruthy();
|
|
121
|
+
await expect(rebuilt.get('c-1')).rejects.toBeTruthy();
|
|
122
|
+
expect(await hasMarker()).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('a failed background refresh leaves the replica ready', async () => {
|
|
126
|
+
await pageLoad().ensureSynced(COURSE, true);
|
|
127
|
+
|
|
128
|
+
const service = pageLoad();
|
|
129
|
+
vi.spyOn(service as any, 'isLocalEpochStale').mockResolvedValue(false);
|
|
130
|
+
const replicate = vi
|
|
131
|
+
.spyOn(service as any, 'replicate')
|
|
132
|
+
.mockRejectedValue(new Error('network down'));
|
|
133
|
+
await service.ensureSynced(COURSE, true);
|
|
134
|
+
|
|
135
|
+
await vi.waitFor(() => expect(replicate).toHaveBeenCalled());
|
|
136
|
+
expect(service.isReady(COURSE)).toBe(true);
|
|
137
|
+
await expect(service.getLocalDB(COURSE)!.get('c-1')).resolves.toBeTruthy();
|
|
138
|
+
});
|
|
139
|
+
});
|
package/tsup.config.ts
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
|
+
// The CommonJS bundle (Node and tests) and the types. The ESM build, one file
|
|
2
|
+
// per module, is rolldown.config.mjs.
|
|
3
|
+
//
|
|
4
|
+
// No `clean`: the two configs run in parallel, and rolldown writes into the
|
|
5
|
+
// same dist. The build script empties dist first.
|
|
1
6
|
import { readFileSync } from 'node:fs';
|
|
2
7
|
import { defineConfig } from 'tsup';
|
|
8
|
+
import { entries } from './build.entries.mjs';
|
|
3
9
|
|
|
4
10
|
const { version } = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'));
|
|
5
11
|
|
|
6
|
-
export default defineConfig(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
js: format === 'esm' ? '.mjs' : '.js',
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
12
|
+
export default defineConfig([
|
|
13
|
+
{
|
|
14
|
+
entry: entries,
|
|
15
|
+
format: ['cjs'],
|
|
16
|
+
dts: false,
|
|
17
|
+
splitting: false,
|
|
18
|
+
sourcemap: true,
|
|
19
|
+
// Session records stamp the framework version (core/versionStamps.ts).
|
|
20
|
+
define: { __SKUILDER_DB_VERSION__: JSON.stringify(version) },
|
|
21
|
+
outExtension: () => ({ js: '.cjs' }),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
// ESM-flavoured .d.ts, for both conditions (as before).
|
|
25
|
+
entry: entries,
|
|
26
|
+
format: ['esm'],
|
|
27
|
+
dts: { only: true },
|
|
28
|
+
},
|
|
29
|
+
]);
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Status } from '@vue-skuilder/common';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Common types used by UserDB implementations across different sync strategies
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Result type for account creation operations
|
|
9
|
-
*/
|
|
10
|
-
interface AccountCreationResult {
|
|
11
|
-
status: Status;
|
|
12
|
-
error?: string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Result type for authentication operations
|
|
16
|
-
*/
|
|
17
|
-
interface AuthenticationResult {
|
|
18
|
-
ok: boolean;
|
|
19
|
-
error?: string;
|
|
20
|
-
}
|
|
21
|
-
interface AdoptSessionResult extends AuthenticationResult {
|
|
22
|
-
/** The adopted session's user, when ok. */
|
|
23
|
-
username?: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Strategy interface for handling user data synchronization
|
|
28
|
-
* Different implementations handle remote sync vs local-only storage
|
|
29
|
-
*/
|
|
30
|
-
interface SyncStrategy {
|
|
31
|
-
/**
|
|
32
|
-
* Set up the remote database for a user
|
|
33
|
-
* @param username The username to set up remote DB for
|
|
34
|
-
* @returns PouchDB database instance (may be same as local for no-op)
|
|
35
|
-
*/
|
|
36
|
-
setupRemoteDB(username: string): PouchDB.Database;
|
|
37
|
-
/**
|
|
38
|
-
* Get the database to use for write operations (local-first approach)
|
|
39
|
-
* @param username The username to get write DB for
|
|
40
|
-
* @returns PouchDB database instance for write operations
|
|
41
|
-
*/
|
|
42
|
-
getWriteDB?(username: string): PouchDB.Database;
|
|
43
|
-
/**
|
|
44
|
-
* Pull the remote database into the local one and RESOLVE WHEN DONE.
|
|
45
|
-
*
|
|
46
|
-
* Distinct from startSync(): this is a one-shot, awaitable catch-up used to
|
|
47
|
-
* populate an empty local mirror before the user object is handed out. A
|
|
48
|
-
* strategy that omits it declares that it has no remote worth waiting for.
|
|
49
|
-
*
|
|
50
|
-
* Mechanism only — BaseUser owns the policy (whether to run it, timeout,
|
|
51
|
-
* marker bookkeeping, resulting hydration state).
|
|
52
|
-
*
|
|
53
|
-
* @param localDB The local PouchDB instance
|
|
54
|
-
* @param remoteDB The remote PouchDB instance
|
|
55
|
-
* @returns Count of documents written locally, and — only when the pull is
|
|
56
|
-
* known to have landed the remote's complete current state — the sequence
|
|
57
|
-
* it corresponds to, for startSync() to resume from. Omitted means "no
|
|
58
|
-
* safe shortcut, walk from the checkpoint".
|
|
59
|
-
*/
|
|
60
|
-
hydrate?(localDB: PouchDB.Database, remoteDB: PouchDB.Database): Promise<{
|
|
61
|
-
docsWritten: number;
|
|
62
|
-
lastSeq?: string | number;
|
|
63
|
-
}>;
|
|
64
|
-
/**
|
|
65
|
-
* Start synchronization between local and remote databases
|
|
66
|
-
* @param localDB The local PouchDB instance
|
|
67
|
-
* @param remoteDB The remote PouchDB instance
|
|
68
|
-
* @param since Sequence to start the pull from, as returned by a hydrate()
|
|
69
|
-
* in the same session. Omit to resume from the stored checkpoint.
|
|
70
|
-
*/
|
|
71
|
-
startSync(localDB: PouchDB.Database, remoteDB: PouchDB.Database, since?: string | number): void;
|
|
72
|
-
/**
|
|
73
|
-
* Stop synchronization (optional - for cleanup)
|
|
74
|
-
*/
|
|
75
|
-
stopSync?(): void;
|
|
76
|
-
/**
|
|
77
|
-
* Whether this strategy supports account creation
|
|
78
|
-
*/
|
|
79
|
-
canCreateAccount(): boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Whether this strategy supports authentication
|
|
82
|
-
*/
|
|
83
|
-
canAuthenticate(): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Create a new user account (if supported)
|
|
86
|
-
* @param username The username for the new account
|
|
87
|
-
* @param password The password for the new account
|
|
88
|
-
*/
|
|
89
|
-
createAccount?(username: string, password: string): Promise<AccountCreationResult>;
|
|
90
|
-
/**
|
|
91
|
-
* Authenticate a user (if supported)
|
|
92
|
-
* @param username The username to authenticate
|
|
93
|
-
* @param password The password to authenticate with
|
|
94
|
-
*/
|
|
95
|
-
authenticate?(username: string, password: string): Promise<AuthenticationResult>;
|
|
96
|
-
/**
|
|
97
|
-
* Log out the current user (if supported)
|
|
98
|
-
*/
|
|
99
|
-
logout?(): Promise<AuthenticationResult>;
|
|
100
|
-
/**
|
|
101
|
-
* Adopt a remote session established outside this client (e.g. a server that
|
|
102
|
-
* verified a third-party sign-in and set the session cookie), optionally
|
|
103
|
-
* migrating a guest account's local data into it (if supported).
|
|
104
|
-
* @param migrateFromGuest Guest username whose local data should be carried
|
|
105
|
-
* over. The caller must capture it BEFORE the session switched, since the
|
|
106
|
-
* remote now reports the adopted user.
|
|
107
|
-
*/
|
|
108
|
-
adoptSession?(migrateFromGuest?: string): Promise<AdoptSessionResult>;
|
|
109
|
-
/**
|
|
110
|
-
* Get the current logged-in username
|
|
111
|
-
* Returns the username if logged in, or a default guest username
|
|
112
|
-
*/
|
|
113
|
-
getCurrentUsername(): Promise<string>;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export type { AccountCreationResult as A, SyncStrategy as S, AuthenticationResult as a, AdoptSessionResult as b };
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { CourseConfig, ClassroomConfig } from '@vue-skuilder/common';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Admin functionality
|
|
5
|
-
*/
|
|
6
|
-
interface AdminDBInterface {
|
|
7
|
-
/**
|
|
8
|
-
* Get all users
|
|
9
|
-
*/
|
|
10
|
-
getUsers(): Promise<PouchDB.Core.Document<{}>[]>;
|
|
11
|
-
/**
|
|
12
|
-
* Get all courses
|
|
13
|
-
*/
|
|
14
|
-
getCourses(): Promise<CourseConfig[]>;
|
|
15
|
-
/**
|
|
16
|
-
* Remove a course
|
|
17
|
-
*/
|
|
18
|
-
removeCourse(id: string): Promise<PouchDB.Core.Response>;
|
|
19
|
-
/**
|
|
20
|
-
* Get all classrooms
|
|
21
|
-
*/
|
|
22
|
-
getClassrooms(): Promise<(ClassroomConfig & {
|
|
23
|
-
_id: string;
|
|
24
|
-
})[]>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Classroom management
|
|
29
|
-
*/
|
|
30
|
-
interface ClassroomDBInterface {
|
|
31
|
-
/**
|
|
32
|
-
* Get classroom config
|
|
33
|
-
*/
|
|
34
|
-
getConfig(): ClassroomConfig;
|
|
35
|
-
/**
|
|
36
|
-
* Get assigned content
|
|
37
|
-
*/
|
|
38
|
-
getAssignedContent(): Promise<AssignedContent[]>;
|
|
39
|
-
}
|
|
40
|
-
interface TeacherClassroomDBInterface extends ClassroomDBInterface {
|
|
41
|
-
/**
|
|
42
|
-
* For teacher interfaces: assign content
|
|
43
|
-
*/
|
|
44
|
-
assignContent?(content: AssignedContent): Promise<boolean>;
|
|
45
|
-
/**
|
|
46
|
-
* For teacher interfaces: remove content
|
|
47
|
-
*/
|
|
48
|
-
removeContent?(content: AssignedContent): Promise<void>;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Student-facing classroom interface.
|
|
52
|
-
* Content is accessed via StudyContentSource.getWeightedCards().
|
|
53
|
-
*/
|
|
54
|
-
type StudentClassroomDBInterface = ClassroomDBInterface;
|
|
55
|
-
type AssignedContent = AssignedCourse | AssignedTag | AssignedCard;
|
|
56
|
-
interface AssignedTag extends ContentBase {
|
|
57
|
-
type: 'tag';
|
|
58
|
-
tagID: string;
|
|
59
|
-
}
|
|
60
|
-
interface AssignedCourse extends ContentBase {
|
|
61
|
-
type: 'course';
|
|
62
|
-
}
|
|
63
|
-
interface AssignedCard extends ContentBase {
|
|
64
|
-
type: 'card';
|
|
65
|
-
cardID: string;
|
|
66
|
-
}
|
|
67
|
-
interface ContentBase {
|
|
68
|
-
type: 'course' | 'tag' | 'card';
|
|
69
|
-
/**
|
|
70
|
-
* Username of the assigning teacher.
|
|
71
|
-
*/
|
|
72
|
-
assignedBy: string;
|
|
73
|
-
/**
|
|
74
|
-
* Date the content was assigned.
|
|
75
|
-
*/
|
|
76
|
-
assignedOn: moment.Moment;
|
|
77
|
-
/**
|
|
78
|
-
* A 'due' date for this assigned content, for scheduling content
|
|
79
|
-
* in advance. Content will not be actively pushed to students until
|
|
80
|
-
* this date.
|
|
81
|
-
*/
|
|
82
|
-
activeOn: moment.Moment;
|
|
83
|
-
courseID: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export type { AdminDBInterface as A, ClassroomDBInterface as C, StudentClassroomDBInterface as S, TeacherClassroomDBInterface as T, AssignedContent as a, AssignedTag as b, AssignedCourse as c, AssignedCard as d };
|