@vue-skuilder/db 0.1.4 → 0.1.6

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.
Files changed (83) hide show
  1. package/CLAUDE.md +43 -0
  2. package/dist/SyncStrategy-DnJRj-Xp.d.mts +74 -0
  3. package/dist/SyncStrategy-DnJRj-Xp.d.ts +74 -0
  4. package/dist/core/index.d.mts +90 -2
  5. package/dist/core/index.d.ts +90 -2
  6. package/dist/core/index.js +856 -6155
  7. package/dist/core/index.js.map +1 -1
  8. package/dist/core/index.mjs +778 -6097
  9. package/dist/core/index.mjs.map +1 -1
  10. package/dist/dataLayerProvider-BZmLyBVw.d.mts +41 -0
  11. package/dist/dataLayerProvider-BuntXkCs.d.ts +41 -0
  12. package/dist/impl/couch/index.d.mts +292 -0
  13. package/dist/impl/couch/index.d.ts +292 -0
  14. package/dist/impl/couch/index.js +3075 -0
  15. package/dist/impl/couch/index.js.map +1 -0
  16. package/dist/impl/couch/index.mjs +3007 -0
  17. package/dist/impl/couch/index.mjs.map +1 -0
  18. package/dist/impl/static/index.d.mts +188 -0
  19. package/dist/impl/static/index.d.ts +188 -0
  20. package/dist/impl/static/index.js +3055 -0
  21. package/dist/impl/static/index.js.map +1 -0
  22. package/dist/impl/static/index.mjs +3025 -0
  23. package/dist/impl/static/index.mjs.map +1 -0
  24. package/dist/index.d.mts +13 -4
  25. package/dist/index.d.ts +13 -4
  26. package/dist/index.js +2920 -6846
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +3567 -7513
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/types-D6SnlHPm.d.ts +58 -0
  31. package/dist/types-DPRvCrIk.d.mts +58 -0
  32. package/dist/types-legacy-WPe8CtO-.d.mts +139 -0
  33. package/dist/types-legacy-WPe8CtO-.d.ts +139 -0
  34. package/dist/{index-QMtzQI65.d.mts → userDB-31gsvxyd.d.mts} +11 -252
  35. package/dist/{index-QMtzQI65.d.ts → userDB-D9EuWTp1.d.ts} +11 -252
  36. package/dist/util/packer/index.d.mts +65 -0
  37. package/dist/util/packer/index.d.ts +65 -0
  38. package/dist/util/packer/index.js +512 -0
  39. package/dist/util/packer/index.js.map +1 -0
  40. package/dist/util/packer/index.mjs +485 -0
  41. package/dist/util/packer/index.mjs.map +1 -0
  42. package/package.json +12 -2
  43. package/src/core/interfaces/contentSource.ts +8 -6
  44. package/src/core/interfaces/courseDB.ts +1 -1
  45. package/src/core/interfaces/dataLayerProvider.ts +5 -0
  46. package/src/core/interfaces/userDB.ts +7 -2
  47. package/src/core/types/types-legacy.ts +2 -0
  48. package/src/factory.ts +10 -7
  49. package/src/impl/{pouch/userDB.ts → common/BaseUserDB.ts} +283 -260
  50. package/src/impl/common/SyncStrategy.ts +90 -0
  51. package/src/impl/common/index.ts +23 -0
  52. package/src/impl/common/types.ts +50 -0
  53. package/src/impl/common/userDBHelpers.ts +144 -0
  54. package/src/impl/couch/CouchDBSyncStrategy.ts +209 -0
  55. package/src/impl/{pouch → couch}/PouchDataLayerProvider.ts +16 -7
  56. package/src/impl/{pouch → couch}/adminDB.ts +3 -3
  57. package/src/impl/{pouch → couch}/auth.ts +2 -2
  58. package/src/impl/{pouch → couch}/classroomDB.ts +6 -6
  59. package/src/impl/{pouch → couch}/courseAPI.ts +59 -21
  60. package/src/impl/{pouch → couch}/courseDB.ts +32 -17
  61. package/src/impl/{pouch → couch}/courseLookupDB.ts +1 -1
  62. package/src/impl/{pouch → couch}/index.ts +27 -20
  63. package/src/impl/{pouch → couch}/updateQueue.ts +5 -1
  64. package/src/impl/{pouch → couch}/user-course-relDB.ts +6 -1
  65. package/src/impl/static/NoOpSyncStrategy.ts +70 -0
  66. package/src/impl/static/StaticDataLayerProvider.ts +93 -0
  67. package/src/impl/static/StaticDataUnpacker.ts +549 -0
  68. package/src/impl/static/courseDB.ts +275 -0
  69. package/src/impl/static/coursesDB.ts +37 -0
  70. package/src/impl/static/index.ts +7 -0
  71. package/src/index.ts +1 -1
  72. package/src/study/SessionController.ts +4 -4
  73. package/src/study/SpacedRepetition.ts +3 -3
  74. package/src/study/getCardDataShape.ts +2 -2
  75. package/src/util/index.ts +1 -0
  76. package/src/util/packer/CouchDBToStaticPacker.ts +620 -0
  77. package/src/util/packer/index.ts +4 -0
  78. package/src/util/packer/types.ts +64 -0
  79. package/tsconfig.json +7 -10
  80. package/tsup.config.ts +5 -3
  81. /package/src/impl/{pouch → couch}/clientCache.ts +0 -0
  82. /package/src/impl/{pouch → couch}/pouchdb-setup.ts +0 -0
  83. /package/src/impl/{pouch → couch}/types.ts +0 -0
@@ -1,5 +1,6 @@
1
- import { CourseConfig, ClassroomConfig, CourseElo, Evaluation, Answer, Status, SkuilderCourseData as SkuilderCourseData$1, DataShape, ParsedCard } from '@vue-skuilder/common';
1
+ import { CourseConfig, ClassroomConfig, CourseElo, Status, SkuilderCourseData as SkuilderCourseData$1, DataShape } from '@vue-skuilder/common';
2
2
  import { Moment } from 'moment';
3
+ import { S as SkuilderCourseData, D as DocType, a as TagStub, T as Tag, g as CardHistory, C as CardRecord } from './types-legacy-WPe8CtO-.js';
3
4
 
4
5
  /**
5
6
  * Admin functionality
@@ -181,139 +182,6 @@ interface ContentBase {
181
182
  courseID: string;
182
183
  }
183
184
 
184
- declare const GuestUsername: string;
185
- declare const log: (message: string) => void;
186
- declare enum DocType {
187
- DISPLAYABLE_DATA = "DISPLAYABLE_DATA",
188
- CARD = "CARD",
189
- DATASHAPE = "DATASHAPE",
190
- QUESTIONTYPE = "QUESTION",
191
- VIEW = "VIEW",
192
- PEDAGOGY = "PEDAGOGY",
193
- CARDRECORD = "CARDRECORD",
194
- SCHEDULED_CARD = "SCHEDULED_CARD",
195
- TAG = "TAG",
196
- NAVIGATION_STRATEGY = "NAVIGATION_STRATEGY"
197
- }
198
- /**
199
- * Interface for all data on course content and pedagogy stored
200
- * in the c/pouch database.
201
- */
202
- interface SkuilderCourseData {
203
- course: string;
204
- docType: DocType;
205
- }
206
- interface Tag extends SkuilderCourseData {
207
- docType: DocType.TAG;
208
- name: string;
209
- snippet: string;
210
- wiki: string;
211
- taggedCards: PouchDB.Core.DocumentId[];
212
- }
213
- interface TagStub {
214
- name: string;
215
- snippet: string;
216
- count: number;
217
- }
218
- interface CardData extends SkuilderCourseData {
219
- docType: DocType.CARD;
220
- id_displayable_data: PouchDB.Core.DocumentId[];
221
- id_view: PouchDB.Core.DocumentId;
222
- elo: CourseElo;
223
- }
224
- /** A list of populated courses in the DB */
225
- interface CourseListData extends PouchDB.Core.Response {
226
- courses: string[];
227
- }
228
- /**
229
- * The data used to hydrate viewable components (questions, info, etc)
230
- */
231
- interface DisplayableData extends SkuilderCourseData {
232
- docType: DocType.DISPLAYABLE_DATA;
233
- author?: string;
234
- id_datashape: PouchDB.Core.DocumentId;
235
- data: Field[];
236
- _attachments?: {
237
- [index: string]: PouchDB.Core.FullAttachment;
238
- };
239
- }
240
- interface Field {
241
- data: unknown;
242
- name: string;
243
- }
244
- interface DataShapeData extends SkuilderCourseData {
245
- docType: DocType.DATASHAPE;
246
- _id: PouchDB.Core.DocumentId;
247
- questionTypes: PouchDB.Core.DocumentId[];
248
- }
249
- interface QuestionData extends SkuilderCourseData {
250
- docType: DocType.QUESTIONTYPE;
251
- _id: PouchDB.Core.DocumentId;
252
- viewList: string[];
253
- dataShapeList: PouchDB.Core.DocumentId[];
254
- }
255
- declare const cardHistoryPrefix = "cardH";
256
- interface CardHistory<T extends CardRecord> {
257
- _id: PouchDB.Core.DocumentId;
258
- /**
259
- * The CouchDB id of the card
260
- */
261
- cardID: PouchDB.Core.DocumentId;
262
- /**
263
- * The ID of the course
264
- */
265
- courseID: string;
266
- /**
267
- * The to-date largest interval between successful
268
- * card reviews. `0` indicates no successful reviews.
269
- */
270
- bestInterval: number;
271
- /**
272
- * The number of times that a card has been
273
- * failed in review
274
- */
275
- lapses: number;
276
- /**
277
- * The number of consecutive successful impressions
278
- * on this card
279
- */
280
- streak: number;
281
- records: T[];
282
- }
283
- interface CardRecord {
284
- /**
285
- * The CouchDB id of the card
286
- */
287
- cardID: string;
288
- /**
289
- * The ID of the course
290
- */
291
- courseID: string;
292
- /**
293
- * Number of milliseconds that the user spent before dismissing
294
- * the card (ie, "I've read this" or "here is my answer")
295
- *
296
- * //TODO: this (sometimes?) wants to be replaced with a rich
297
- * recording of user activity in working the question
298
- */
299
- timeSpent: number;
300
- /**
301
- * The date-time that the card was rendered. timeStamp + timeSpent will give the
302
- * time of user submission.
303
- */
304
- timeStamp: Moment;
305
- }
306
- interface QuestionRecord extends CardRecord, Evaluation {
307
- userAnswer: Answer;
308
- /**
309
- * The number of incorrect user submissions prededing this submisstion.
310
- *
311
- * eg, if a user is asked 7*6=__, submitting 46, 48, 42 will result in three
312
- * records being created having 0, 1, and 2 as their recorded 'priorAttempts' values
313
- */
314
- priorAttemps: number;
315
- }
316
-
317
185
  interface DataLayerResult {
318
186
  status: Status;
319
187
  message: string;
@@ -443,7 +311,7 @@ interface CourseDBInterface extends NavigationStrategyManager {
443
311
  /**
444
312
  * Create a new tag
445
313
  */
446
- createTag(tagName: string): Promise<PouchDB.Core.Response>;
314
+ createTag(tagName: string, author: string): Promise<PouchDB.Core.Response>;
447
315
  /**
448
316
  * Get a tag by name
449
317
  */
@@ -471,12 +339,6 @@ interface CourseDBInterface extends NavigationStrategyManager {
471
339
  }[]>;
472
340
  }
473
341
 
474
- declare abstract class Loggable {
475
- protected abstract readonly _className: string;
476
- protected log(...args: unknown[]): void;
477
- protected error(...args: unknown[]): void;
478
- }
479
-
480
342
  type Update<T> = Partial<T> | ((x: T) => T);
481
343
 
482
344
  interface DocumentUpdater {
@@ -598,6 +460,13 @@ interface UserDBInterface extends DocumentUpdater {
598
460
  * Update user's ELO rating for a course
599
461
  */
600
462
  updateUserElo(courseId: string, elo: CourseElo): Promise<PouchDB.Core.Response>;
463
+ /**
464
+ * Reset all user data (progress, registrations, etc.) while preserving authentication
465
+ */
466
+ resetUserData(): Promise<{
467
+ status: Status;
468
+ error?: string;
469
+ }>;
601
470
  getCourseInterface(courseId: string): Promise<UsrCrsDataInterface>;
602
471
  }
603
472
  interface UserCourseSettings {
@@ -621,114 +490,4 @@ interface ClassroomRegistrationDoc {
621
490
  registrations: ClassroomRegistration[];
622
491
  }
623
492
 
624
- /**
625
- * Main factory interface for data access
626
- */
627
- interface DataLayerProvider {
628
- /**
629
- * Get the user database interface
630
- */
631
- getUserDB(): UserDBInterface;
632
- /**
633
- * Get a course database interface
634
- */
635
- getCourseDB(courseId: string): CourseDBInterface;
636
- /**
637
- * Get the courses-lookup interface
638
- */
639
- getCoursesDB(): CoursesDBInterface;
640
- /**
641
- * Get a classroom database interface
642
- */
643
- getClassroomDB(classId: string, type: 'student' | 'teacher'): Promise<ClassroomDBInterface>;
644
- /**
645
- * Get the admin database interface
646
- */
647
- getAdminDB(): AdminDBInterface;
648
- /**
649
- * Initialize the data layer
650
- */
651
- initialize(): Promise<void>;
652
- /**
653
- * Teardown the data layer
654
- */
655
- teardown(): Promise<void>;
656
- }
657
-
658
- declare function areQuestionRecords(h: CardHistory<CardRecord>): h is CardHistory<QuestionRecord>;
659
- declare function isQuestionRecord(c: CardRecord): c is QuestionRecord;
660
- declare function getCardHistoryID(courseID: string, cardID: string): PouchDB.Core.DocumentId;
661
- declare function parseCardHistoryID(id: string): {
662
- courseID: string;
663
- cardID: string;
664
- };
665
- interface PouchDBError extends Error {
666
- error?: string;
667
- reason?: string;
668
- }
669
- declare function docIsDeleted(e: PouchDBError): boolean;
670
-
671
- declare enum Navigators {
672
- ELO = "elo"
673
- }
674
- /**
675
- * A content-navigator provides runtime steering of study sessions.
676
- */
677
- declare abstract class ContentNavigator implements StudyContentSource {
678
- /**
679
- *
680
- * @param user
681
- * @param strategyData
682
- * @returns the runtime object used to steer a study session.
683
- */
684
- static create(user: UserDBInterface, course: CourseDBInterface, strategyData: ContentNavigationStrategyData): Promise<ContentNavigator>;
685
- abstract getPendingReviews(): Promise<(StudySessionReviewItem & ScheduledCard)[]>;
686
- abstract getNewCards(n?: number): Promise<StudySessionNewItem[]>;
687
- }
688
-
689
- /**
690
- * Interface representing the result of a bulk import operation for a single card
691
- */
692
- interface ImportResult {
693
- /** The original text input for the card */
694
- originalText: string;
695
- /** Status of the import operation */
696
- status: 'success' | 'error';
697
- /** Message describing the result or error */
698
- message: string;
699
- /** ID of the newly created card (only for success) */
700
- cardId?: string;
701
- }
702
- /**
703
- * Configuration for the bulk card processor
704
- */
705
- interface BulkCardProcessorConfig {
706
- /** The data shape to use for the cards */
707
- dataShape: DataShape;
708
- /** The course code used for adding notes */
709
- courseCode: string;
710
- /** The username of the current user */
711
- userName: string;
712
- }
713
-
714
- /**
715
- * Processes multiple cards from bulk text input
716
- *
717
- * @param parsedCards - Array of parsed cards to import
718
- * @param courseDB - Course database interface
719
- * @param config - Configuration for the card processor
720
- * @returns Array of import results
721
- */
722
- declare function importParsedCards(parsedCards: ParsedCard[], courseDB: CourseDBInterface, config: BulkCardProcessorConfig): Promise<ImportResult[]>;
723
- /**
724
- * Validates the configuration for bulk card processing
725
- *
726
- * @param config - Configuration to validate
727
- * @returns Object with validation result and error message if any
728
- */
729
- declare function validateProcessorConfig(config: Partial<BulkCardProcessorConfig>): {
730
- isValid: boolean;
731
- errorMessage?: string;
732
- };
733
-
734
- export { getCardHistoryID as $, type AdminDBInterface as A, type SkuilderCourseData as B, type CardRecord as C, type DataLayerProvider as D, type Tag as E, type TagStub as F, GuestUsername as G, type CardData as H, type CourseListData as I, type DisplayableData as J, type Field as K, Loggable as L, type DataShapeData as M, cardHistoryPrefix as N, type CardHistory as O, type QuestionRecord as P, type QuestionData as Q, type UserConfig as R, type StudySessionItem as S, type TeacherClassroomDBInterface as T, type UserDBInterface as U, type ActivityRecord as V, type CourseRegistration as W, type CourseRegistrationDoc as X, type ScheduledCard as Y, areQuestionRecords as Z, isQuestionRecord as _, type StudyContentSource as a, parseCardHistoryID as a0, docIsDeleted as a1, Navigators as a2, ContentNavigator as a3, importParsedCards as a4, validateProcessorConfig as a5, type ImportResult as a6, type BulkCardProcessorConfig as a7, type DocumentUpdater as a8, newInterval as a9, type ClassroomDBInterface as b, type StudentClassroomDBInterface as c, type AssignedContent as d, type AssignedTag as e, type AssignedCourse as f, type AssignedCard as g, type StudySessionFailedItem as h, type StudySessionFailedNewItem as i, type StudySessionFailedReviewItem as j, type StudySessionNewItem as k, type StudySessionReviewItem as l, isReview as m, type ContentSourceID as n, getStudySource as o, type CoursesDBInterface as p, type CourseInfo as q, type CourseDBInterface as r, type UserCourseSettings as s, type UserCourseSetting as t, type UsrCrsDataInterface as u, type ClassroomRegistrationDesignation as v, type ClassroomRegistration as w, type ClassroomRegistrationDoc as x, log as y, DocType as z };
493
+ export { type AdminDBInterface as A, type CourseRegistrationDoc as B, type CourseDBInterface as C, type ScheduledCard as D, type DocumentUpdater as E, newInterval as F, type DataLayerResult as G, type ContentNavigationStrategyData as H, type StudySessionItem as S, type TeacherClassroomDBInterface as T, type UserDBInterface as U, type CoursesDBInterface as a, type ClassroomDBInterface as b, type StudyContentSource as c, type StudentClassroomDBInterface as d, type AssignedContent as e, type AssignedTag as f, type AssignedCourse as g, type AssignedCard as h, type StudySessionFailedItem as i, type StudySessionFailedNewItem as j, type StudySessionFailedReviewItem as k, type StudySessionNewItem as l, type StudySessionReviewItem as m, isReview as n, type ContentSourceID as o, getStudySource as p, type CourseInfo as q, type UserCourseSettings as r, type UserCourseSetting as s, type UsrCrsDataInterface as t, type ClassroomRegistrationDesignation as u, type ClassroomRegistration as v, type ClassroomRegistrationDoc as w, type UserConfig as x, type ActivityRecord as y, type CourseRegistration as z };
@@ -0,0 +1,65 @@
1
+ import { P as PackerConfig, a as PackedCourseData } from '../../types-DPRvCrIk.mjs';
2
+ export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, S as StaticCourseManifest } from '../../types-DPRvCrIk.mjs';
3
+ import '@vue-skuilder/common';
4
+ import '../../types-legacy-WPe8CtO-.mjs';
5
+ import 'moment';
6
+
7
+ declare class CouchDBToStaticPacker {
8
+ private config;
9
+ private sourceDB;
10
+ constructor(config?: Partial<PackerConfig>);
11
+ /**
12
+ * Pack a CouchDB course database into static data structures
13
+ */
14
+ packCourse(sourceDB: PouchDB.Database, courseId: string): Promise<PackedCourseData>;
15
+ private extractCourseConfig;
16
+ private extractDesignDocs;
17
+ private extractDocumentsByType;
18
+ private createChunks;
19
+ private prepareChunkData;
20
+ private buildIndices;
21
+ private buildEloIndex;
22
+ private buildTagIndex;
23
+ /**
24
+ * Build view index by querying CouchDB views directly instead of parsing map functions
25
+ */
26
+ private buildViewIndex;
27
+ /**
28
+ * Format CouchDB view results for static consumption
29
+ */
30
+ private formatViewResults;
31
+ /**
32
+ * Format ELO view results - convert to sorted array format
33
+ */
34
+ private formatEloViewIndex;
35
+ /**
36
+ * Format tags view results - convert to tag mapping format
37
+ */
38
+ private formatTagsViewIndex;
39
+ /**
40
+ * Format inexperience view results - convert to experience-based format
41
+ */
42
+ private formatInexperienceViewIndex;
43
+ /**
44
+ * Format generic view results - fallback for unknown views
45
+ */
46
+ private formatGenericViewIndex;
47
+ /**
48
+ * Extract all attachments from documents and download binary data
49
+ */
50
+ private extractAllAttachments;
51
+ /**
52
+ * Extract attachments for a single document
53
+ */
54
+ private extractDocumentAttachments;
55
+ /**
56
+ * Transform attachment stubs to include file paths
57
+ */
58
+ private transformAttachmentStubs;
59
+ /**
60
+ * Get file extension from content type
61
+ */
62
+ private getFileExtension;
63
+ }
64
+
65
+ export { CouchDBToStaticPacker, PackedCourseData, PackerConfig };
@@ -0,0 +1,65 @@
1
+ import { P as PackerConfig, a as PackedCourseData } from '../../types-D6SnlHPm.js';
2
+ export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, S as StaticCourseManifest } from '../../types-D6SnlHPm.js';
3
+ import '@vue-skuilder/common';
4
+ import '../../types-legacy-WPe8CtO-.js';
5
+ import 'moment';
6
+
7
+ declare class CouchDBToStaticPacker {
8
+ private config;
9
+ private sourceDB;
10
+ constructor(config?: Partial<PackerConfig>);
11
+ /**
12
+ * Pack a CouchDB course database into static data structures
13
+ */
14
+ packCourse(sourceDB: PouchDB.Database, courseId: string): Promise<PackedCourseData>;
15
+ private extractCourseConfig;
16
+ private extractDesignDocs;
17
+ private extractDocumentsByType;
18
+ private createChunks;
19
+ private prepareChunkData;
20
+ private buildIndices;
21
+ private buildEloIndex;
22
+ private buildTagIndex;
23
+ /**
24
+ * Build view index by querying CouchDB views directly instead of parsing map functions
25
+ */
26
+ private buildViewIndex;
27
+ /**
28
+ * Format CouchDB view results for static consumption
29
+ */
30
+ private formatViewResults;
31
+ /**
32
+ * Format ELO view results - convert to sorted array format
33
+ */
34
+ private formatEloViewIndex;
35
+ /**
36
+ * Format tags view results - convert to tag mapping format
37
+ */
38
+ private formatTagsViewIndex;
39
+ /**
40
+ * Format inexperience view results - convert to experience-based format
41
+ */
42
+ private formatInexperienceViewIndex;
43
+ /**
44
+ * Format generic view results - fallback for unknown views
45
+ */
46
+ private formatGenericViewIndex;
47
+ /**
48
+ * Extract all attachments from documents and download binary data
49
+ */
50
+ private extractAllAttachments;
51
+ /**
52
+ * Extract attachments for a single document
53
+ */
54
+ private extractDocumentAttachments;
55
+ /**
56
+ * Transform attachment stubs to include file paths
57
+ */
58
+ private transformAttachmentStubs;
59
+ /**
60
+ * Get file extension from content type
61
+ */
62
+ private getFileExtension;
63
+ }
64
+
65
+ export { CouchDBToStaticPacker, PackedCourseData, PackerConfig };