@vue-skuilder/db 0.1.3 → 0.1.5

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 (80) hide show
  1. package/dist/SyncStrategy-DnJRj-Xp.d.mts +74 -0
  2. package/dist/SyncStrategy-DnJRj-Xp.d.ts +74 -0
  3. package/dist/core/index.d.mts +90 -2
  4. package/dist/core/index.d.ts +90 -2
  5. package/dist/core/index.js +798 -650
  6. package/dist/core/index.js.map +1 -1
  7. package/dist/core/index.mjs +769 -621
  8. package/dist/core/index.mjs.map +1 -1
  9. package/dist/dataLayerProvider-B8wquRiB.d.mts +37 -0
  10. package/dist/dataLayerProvider-DRjMZMaf.d.ts +37 -0
  11. package/dist/impl/couch/index.d.mts +292 -0
  12. package/dist/impl/couch/index.d.ts +292 -0
  13. package/dist/impl/couch/index.js +8522 -0
  14. package/dist/impl/couch/index.js.map +1 -0
  15. package/dist/impl/couch/index.mjs +8474 -0
  16. package/dist/impl/couch/index.mjs.map +1 -0
  17. package/dist/impl/static/index.d.mts +204 -0
  18. package/dist/impl/static/index.d.ts +204 -0
  19. package/dist/impl/static/index.js +8499 -0
  20. package/dist/impl/static/index.js.map +1 -0
  21. package/dist/impl/static/index.mjs +8488 -0
  22. package/dist/impl/static/index.mjs.map +1 -0
  23. package/dist/index.d.mts +13 -4
  24. package/dist/index.d.ts +13 -4
  25. package/dist/index.js +3280 -2108
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +3290 -2118
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/types-B0GJsjOr.d.ts +47 -0
  30. package/dist/types-DIgj8pP7.d.mts +47 -0
  31. package/dist/types-legacy-CTsJvvxI.d.mts +137 -0
  32. package/dist/types-legacy-CTsJvvxI.d.ts +137 -0
  33. package/dist/{index-QMtzQI65.d.mts → userDB-C5dcuRZs.d.ts} +3 -251
  34. package/dist/{index-QMtzQI65.d.ts → userDB-ZSwOXiYN.d.mts} +3 -251
  35. package/dist/util/packer/index.d.mts +25 -0
  36. package/dist/util/packer/index.d.ts +25 -0
  37. package/dist/util/packer/index.js +307 -0
  38. package/dist/util/packer/index.js.map +1 -0
  39. package/dist/util/packer/index.mjs +280 -0
  40. package/dist/util/packer/index.mjs.map +1 -0
  41. package/package.json +12 -2
  42. package/src/core/interfaces/contentSource.ts +8 -6
  43. package/src/core/interfaces/userDB.ts +2 -2
  44. package/src/factory.ts +10 -7
  45. package/src/impl/{pouch/userDB.ts → common/BaseUserDB.ts} +225 -260
  46. package/src/impl/common/SyncStrategy.ts +90 -0
  47. package/src/impl/common/index.ts +23 -0
  48. package/src/impl/common/types.ts +50 -0
  49. package/src/impl/common/userDBHelpers.ts +144 -0
  50. package/src/impl/couch/CouchDBSyncStrategy.ts +209 -0
  51. package/src/impl/{pouch → couch}/PouchDataLayerProvider.ts +12 -7
  52. package/src/impl/{pouch → couch}/adminDB.ts +3 -3
  53. package/src/impl/{pouch → couch}/auth.ts +2 -2
  54. package/src/impl/{pouch → couch}/classroomDB.ts +6 -6
  55. package/src/impl/{pouch → couch}/courseAPI.ts +28 -5
  56. package/src/impl/{pouch → couch}/courseDB.ts +24 -10
  57. package/src/impl/{pouch → couch}/courseLookupDB.ts +1 -1
  58. package/src/impl/{pouch → couch}/index.ts +27 -20
  59. package/src/impl/{pouch → couch}/updateQueue.ts +5 -1
  60. package/src/impl/{pouch → couch}/user-course-relDB.ts +6 -1
  61. package/src/impl/static/NoOpSyncStrategy.ts +70 -0
  62. package/src/impl/static/StaticDataLayerProvider.ts +89 -0
  63. package/src/impl/static/StaticDataUnpacker.ts +376 -0
  64. package/src/impl/static/courseDB.ts +257 -0
  65. package/src/impl/static/coursesDB.ts +37 -0
  66. package/src/impl/static/index.ts +8 -0
  67. package/src/impl/static/userDB.ts +179 -0
  68. package/src/index.ts +1 -1
  69. package/src/study/SessionController.ts +4 -4
  70. package/src/study/SpacedRepetition.ts +3 -3
  71. package/src/study/getCardDataShape.ts +2 -2
  72. package/src/util/index.ts +1 -0
  73. package/src/util/packer/CouchDBToStaticPacker.ts +349 -0
  74. package/src/util/packer/index.ts +4 -0
  75. package/src/util/packer/types.ts +52 -0
  76. package/tsconfig.json +7 -10
  77. package/tsup.config.ts +5 -3
  78. /package/src/impl/{pouch → couch}/clientCache.ts +0 -0
  79. /package/src/impl/{pouch → couch}/pouchdb-setup.ts +0 -0
  80. /package/src/impl/{pouch → couch}/types.ts +0 -0
@@ -0,0 +1,74 @@
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
+
22
+ /**
23
+ * Strategy interface for handling user data synchronization
24
+ * Different implementations handle remote sync vs local-only storage
25
+ */
26
+ interface SyncStrategy {
27
+ /**
28
+ * Set up the remote database for a user
29
+ * @param username The username to set up remote DB for
30
+ * @returns PouchDB database instance (may be same as local for no-op)
31
+ */
32
+ setupRemoteDB(username: string): PouchDB.Database;
33
+ /**
34
+ * Start synchronization between local and remote databases
35
+ * @param localDB The local PouchDB instance
36
+ * @param remoteDB The remote PouchDB instance
37
+ */
38
+ startSync(localDB: PouchDB.Database, remoteDB: PouchDB.Database): void;
39
+ /**
40
+ * Stop synchronization (optional - for cleanup)
41
+ */
42
+ stopSync?(): void;
43
+ /**
44
+ * Whether this strategy supports account creation
45
+ */
46
+ canCreateAccount(): boolean;
47
+ /**
48
+ * Whether this strategy supports authentication
49
+ */
50
+ canAuthenticate(): boolean;
51
+ /**
52
+ * Create a new user account (if supported)
53
+ * @param username The username for the new account
54
+ * @param password The password for the new account
55
+ */
56
+ createAccount?(username: string, password: string): Promise<AccountCreationResult>;
57
+ /**
58
+ * Authenticate a user (if supported)
59
+ * @param username The username to authenticate
60
+ * @param password The password to authenticate with
61
+ */
62
+ authenticate?(username: string, password: string): Promise<AuthenticationResult>;
63
+ /**
64
+ * Log out the current user (if supported)
65
+ */
66
+ logout?(): Promise<AuthenticationResult>;
67
+ /**
68
+ * Get the current logged-in username
69
+ * Returns the username if logged in, or a default guest username
70
+ */
71
+ getCurrentUsername(): Promise<string>;
72
+ }
73
+
74
+ export type { AccountCreationResult as A, SyncStrategy as S, AuthenticationResult as a };
@@ -0,0 +1,74 @@
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
+
22
+ /**
23
+ * Strategy interface for handling user data synchronization
24
+ * Different implementations handle remote sync vs local-only storage
25
+ */
26
+ interface SyncStrategy {
27
+ /**
28
+ * Set up the remote database for a user
29
+ * @param username The username to set up remote DB for
30
+ * @returns PouchDB database instance (may be same as local for no-op)
31
+ */
32
+ setupRemoteDB(username: string): PouchDB.Database;
33
+ /**
34
+ * Start synchronization between local and remote databases
35
+ * @param localDB The local PouchDB instance
36
+ * @param remoteDB The remote PouchDB instance
37
+ */
38
+ startSync(localDB: PouchDB.Database, remoteDB: PouchDB.Database): void;
39
+ /**
40
+ * Stop synchronization (optional - for cleanup)
41
+ */
42
+ stopSync?(): void;
43
+ /**
44
+ * Whether this strategy supports account creation
45
+ */
46
+ canCreateAccount(): boolean;
47
+ /**
48
+ * Whether this strategy supports authentication
49
+ */
50
+ canAuthenticate(): boolean;
51
+ /**
52
+ * Create a new user account (if supported)
53
+ * @param username The username for the new account
54
+ * @param password The password for the new account
55
+ */
56
+ createAccount?(username: string, password: string): Promise<AccountCreationResult>;
57
+ /**
58
+ * Authenticate a user (if supported)
59
+ * @param username The username to authenticate
60
+ * @param password The password to authenticate with
61
+ */
62
+ authenticate?(username: string, password: string): Promise<AuthenticationResult>;
63
+ /**
64
+ * Log out the current user (if supported)
65
+ */
66
+ logout?(): Promise<AuthenticationResult>;
67
+ /**
68
+ * Get the current logged-in username
69
+ * Returns the username if logged in, or a default guest username
70
+ */
71
+ getCurrentUsername(): Promise<string>;
72
+ }
73
+
74
+ export type { AccountCreationResult as A, SyncStrategy as S, AuthenticationResult as a };
@@ -1,3 +1,91 @@
1
- export { V as ActivityRecord, A as AdminDBInterface, g as AssignedCard, d as AssignedContent, f as AssignedCourse, e as AssignedTag, a7 as BulkCardProcessorConfig, H as CardData, O as CardHistory, C as CardRecord, b as ClassroomDBInterface, w as ClassroomRegistration, v as ClassroomRegistrationDesignation, x as ClassroomRegistrationDoc, a3 as ContentNavigator, n as ContentSourceID, r as CourseDBInterface, q as CourseInfo, I as CourseListData, W as CourseRegistration, X as CourseRegistrationDoc, p as CoursesDBInterface, D as DataLayerProvider, M as DataShapeData, J as DisplayableData, z as DocType, K as Field, G as GuestUsername, a6 as ImportResult, L as Loggable, a2 as Navigators, Q as QuestionData, P as QuestionRecord, Y as ScheduledCard, B as SkuilderCourseData, c as StudentClassroomDBInterface, a as StudyContentSource, h as StudySessionFailedItem, i as StudySessionFailedNewItem, j as StudySessionFailedReviewItem, S as StudySessionItem, k as StudySessionNewItem, l as StudySessionReviewItem, E as Tag, F as TagStub, T as TeacherClassroomDBInterface, R as UserConfig, t as UserCourseSetting, s as UserCourseSettings, U as UserDBInterface, u as UsrCrsDataInterface, Z as areQuestionRecords, N as cardHistoryPrefix, a1 as docIsDeleted, $ as getCardHistoryID, o as getStudySource, a4 as importParsedCards, _ as isQuestionRecord, m as isReview, y as log, a0 as parseCardHistoryID, a5 as validateProcessorConfig } from '../index-QMtzQI65.mjs';
2
- import '@vue-skuilder/common';
1
+ import { c as StudyContentSource, U as UserDBInterface, C as CourseDBInterface, H as ContentNavigationStrategyData, m as StudySessionReviewItem, D as ScheduledCard, l as StudySessionNewItem } from '../userDB-ZSwOXiYN.mjs';
2
+ export { y as ActivityRecord, A as AdminDBInterface, h as AssignedCard, e as AssignedContent, g as AssignedCourse, f as AssignedTag, b as ClassroomDBInterface, v as ClassroomRegistration, u as ClassroomRegistrationDesignation, w as ClassroomRegistrationDoc, o as ContentSourceID, q as CourseInfo, z as CourseRegistration, B as CourseRegistrationDoc, a as CoursesDBInterface, d as StudentClassroomDBInterface, i as StudySessionFailedItem, j as StudySessionFailedNewItem, k as StudySessionFailedReviewItem, S as StudySessionItem, T as TeacherClassroomDBInterface, x as UserConfig, s as UserCourseSetting, r as UserCourseSettings, t as UsrCrsDataInterface, p as getStudySource, n as isReview } from '../userDB-ZSwOXiYN.mjs';
3
+ export { D as DataLayerProvider } from '../dataLayerProvider-B8wquRiB.mjs';
4
+ import { g as CardHistory, C as CardRecord, h as QuestionRecord } from '../types-legacy-CTsJvvxI.mjs';
5
+ export { b as CardData, c as CourseListData, e as DataShapeData, d as DisplayableData, D as DocType, F as Field, G as GuestUsername, Q as QuestionData, S as SkuilderCourseData, T as Tag, a as TagStub, f as cardHistoryPrefix, l as log } from '../types-legacy-CTsJvvxI.mjs';
6
+ import { DataShape, ParsedCard } from '@vue-skuilder/common';
3
7
  import 'moment';
8
+
9
+ declare abstract class Loggable {
10
+ protected abstract readonly _className: string;
11
+ protected log(...args: unknown[]): void;
12
+ protected error(...args: unknown[]): void;
13
+ }
14
+
15
+ declare function areQuestionRecords(h: CardHistory<CardRecord>): h is CardHistory<QuestionRecord>;
16
+ declare function isQuestionRecord(c: CardRecord): c is QuestionRecord;
17
+ declare function getCardHistoryID(courseID: string, cardID: string): PouchDB.Core.DocumentId;
18
+ declare function parseCardHistoryID(id: string): {
19
+ courseID: string;
20
+ cardID: string;
21
+ };
22
+ interface PouchDBError extends Error {
23
+ error?: string;
24
+ reason?: string;
25
+ }
26
+ declare function docIsDeleted(e: PouchDBError): boolean;
27
+
28
+ declare enum Navigators {
29
+ ELO = "elo"
30
+ }
31
+ /**
32
+ * A content-navigator provides runtime steering of study sessions.
33
+ */
34
+ declare abstract class ContentNavigator implements StudyContentSource {
35
+ /**
36
+ *
37
+ * @param user
38
+ * @param strategyData
39
+ * @returns the runtime object used to steer a study session.
40
+ */
41
+ static create(user: UserDBInterface, course: CourseDBInterface, strategyData: ContentNavigationStrategyData): Promise<ContentNavigator>;
42
+ abstract getPendingReviews(): Promise<(StudySessionReviewItem & ScheduledCard)[]>;
43
+ abstract getNewCards(n?: number): Promise<StudySessionNewItem[]>;
44
+ }
45
+
46
+ /**
47
+ * Interface representing the result of a bulk import operation for a single card
48
+ */
49
+ interface ImportResult {
50
+ /** The original text input for the card */
51
+ originalText: string;
52
+ /** Status of the import operation */
53
+ status: 'success' | 'error';
54
+ /** Message describing the result or error */
55
+ message: string;
56
+ /** ID of the newly created card (only for success) */
57
+ cardId?: string;
58
+ }
59
+ /**
60
+ * Configuration for the bulk card processor
61
+ */
62
+ interface BulkCardProcessorConfig {
63
+ /** The data shape to use for the cards */
64
+ dataShape: DataShape;
65
+ /** The course code used for adding notes */
66
+ courseCode: string;
67
+ /** The username of the current user */
68
+ userName: string;
69
+ }
70
+
71
+ /**
72
+ * Processes multiple cards from bulk text input
73
+ *
74
+ * @param parsedCards - Array of parsed cards to import
75
+ * @param courseDB - Course database interface
76
+ * @param config - Configuration for the card processor
77
+ * @returns Array of import results
78
+ */
79
+ declare function importParsedCards(parsedCards: ParsedCard[], courseDB: CourseDBInterface, config: BulkCardProcessorConfig): Promise<ImportResult[]>;
80
+ /**
81
+ * Validates the configuration for bulk card processing
82
+ *
83
+ * @param config - Configuration to validate
84
+ * @returns Object with validation result and error message if any
85
+ */
86
+ declare function validateProcessorConfig(config: Partial<BulkCardProcessorConfig>): {
87
+ isValid: boolean;
88
+ errorMessage?: string;
89
+ };
90
+
91
+ export { type BulkCardProcessorConfig, CardHistory, CardRecord, ContentNavigator, CourseDBInterface, type ImportResult, Loggable, Navigators, QuestionRecord, ScheduledCard, StudyContentSource, StudySessionNewItem, StudySessionReviewItem, UserDBInterface, areQuestionRecords, docIsDeleted, getCardHistoryID, importParsedCards, isQuestionRecord, parseCardHistoryID, validateProcessorConfig };
@@ -1,3 +1,91 @@
1
- export { V as ActivityRecord, A as AdminDBInterface, g as AssignedCard, d as AssignedContent, f as AssignedCourse, e as AssignedTag, a7 as BulkCardProcessorConfig, H as CardData, O as CardHistory, C as CardRecord, b as ClassroomDBInterface, w as ClassroomRegistration, v as ClassroomRegistrationDesignation, x as ClassroomRegistrationDoc, a3 as ContentNavigator, n as ContentSourceID, r as CourseDBInterface, q as CourseInfo, I as CourseListData, W as CourseRegistration, X as CourseRegistrationDoc, p as CoursesDBInterface, D as DataLayerProvider, M as DataShapeData, J as DisplayableData, z as DocType, K as Field, G as GuestUsername, a6 as ImportResult, L as Loggable, a2 as Navigators, Q as QuestionData, P as QuestionRecord, Y as ScheduledCard, B as SkuilderCourseData, c as StudentClassroomDBInterface, a as StudyContentSource, h as StudySessionFailedItem, i as StudySessionFailedNewItem, j as StudySessionFailedReviewItem, S as StudySessionItem, k as StudySessionNewItem, l as StudySessionReviewItem, E as Tag, F as TagStub, T as TeacherClassroomDBInterface, R as UserConfig, t as UserCourseSetting, s as UserCourseSettings, U as UserDBInterface, u as UsrCrsDataInterface, Z as areQuestionRecords, N as cardHistoryPrefix, a1 as docIsDeleted, $ as getCardHistoryID, o as getStudySource, a4 as importParsedCards, _ as isQuestionRecord, m as isReview, y as log, a0 as parseCardHistoryID, a5 as validateProcessorConfig } from '../index-QMtzQI65.js';
2
- import '@vue-skuilder/common';
1
+ import { c as StudyContentSource, U as UserDBInterface, C as CourseDBInterface, H as ContentNavigationStrategyData, m as StudySessionReviewItem, D as ScheduledCard, l as StudySessionNewItem } from '../userDB-C5dcuRZs.js';
2
+ export { y as ActivityRecord, A as AdminDBInterface, h as AssignedCard, e as AssignedContent, g as AssignedCourse, f as AssignedTag, b as ClassroomDBInterface, v as ClassroomRegistration, u as ClassroomRegistrationDesignation, w as ClassroomRegistrationDoc, o as ContentSourceID, q as CourseInfo, z as CourseRegistration, B as CourseRegistrationDoc, a as CoursesDBInterface, d as StudentClassroomDBInterface, i as StudySessionFailedItem, j as StudySessionFailedNewItem, k as StudySessionFailedReviewItem, S as StudySessionItem, T as TeacherClassroomDBInterface, x as UserConfig, s as UserCourseSetting, r as UserCourseSettings, t as UsrCrsDataInterface, p as getStudySource, n as isReview } from '../userDB-C5dcuRZs.js';
3
+ export { D as DataLayerProvider } from '../dataLayerProvider-DRjMZMaf.js';
4
+ import { g as CardHistory, C as CardRecord, h as QuestionRecord } from '../types-legacy-CTsJvvxI.js';
5
+ export { b as CardData, c as CourseListData, e as DataShapeData, d as DisplayableData, D as DocType, F as Field, G as GuestUsername, Q as QuestionData, S as SkuilderCourseData, T as Tag, a as TagStub, f as cardHistoryPrefix, l as log } from '../types-legacy-CTsJvvxI.js';
6
+ import { DataShape, ParsedCard } from '@vue-skuilder/common';
3
7
  import 'moment';
8
+
9
+ declare abstract class Loggable {
10
+ protected abstract readonly _className: string;
11
+ protected log(...args: unknown[]): void;
12
+ protected error(...args: unknown[]): void;
13
+ }
14
+
15
+ declare function areQuestionRecords(h: CardHistory<CardRecord>): h is CardHistory<QuestionRecord>;
16
+ declare function isQuestionRecord(c: CardRecord): c is QuestionRecord;
17
+ declare function getCardHistoryID(courseID: string, cardID: string): PouchDB.Core.DocumentId;
18
+ declare function parseCardHistoryID(id: string): {
19
+ courseID: string;
20
+ cardID: string;
21
+ };
22
+ interface PouchDBError extends Error {
23
+ error?: string;
24
+ reason?: string;
25
+ }
26
+ declare function docIsDeleted(e: PouchDBError): boolean;
27
+
28
+ declare enum Navigators {
29
+ ELO = "elo"
30
+ }
31
+ /**
32
+ * A content-navigator provides runtime steering of study sessions.
33
+ */
34
+ declare abstract class ContentNavigator implements StudyContentSource {
35
+ /**
36
+ *
37
+ * @param user
38
+ * @param strategyData
39
+ * @returns the runtime object used to steer a study session.
40
+ */
41
+ static create(user: UserDBInterface, course: CourseDBInterface, strategyData: ContentNavigationStrategyData): Promise<ContentNavigator>;
42
+ abstract getPendingReviews(): Promise<(StudySessionReviewItem & ScheduledCard)[]>;
43
+ abstract getNewCards(n?: number): Promise<StudySessionNewItem[]>;
44
+ }
45
+
46
+ /**
47
+ * Interface representing the result of a bulk import operation for a single card
48
+ */
49
+ interface ImportResult {
50
+ /** The original text input for the card */
51
+ originalText: string;
52
+ /** Status of the import operation */
53
+ status: 'success' | 'error';
54
+ /** Message describing the result or error */
55
+ message: string;
56
+ /** ID of the newly created card (only for success) */
57
+ cardId?: string;
58
+ }
59
+ /**
60
+ * Configuration for the bulk card processor
61
+ */
62
+ interface BulkCardProcessorConfig {
63
+ /** The data shape to use for the cards */
64
+ dataShape: DataShape;
65
+ /** The course code used for adding notes */
66
+ courseCode: string;
67
+ /** The username of the current user */
68
+ userName: string;
69
+ }
70
+
71
+ /**
72
+ * Processes multiple cards from bulk text input
73
+ *
74
+ * @param parsedCards - Array of parsed cards to import
75
+ * @param courseDB - Course database interface
76
+ * @param config - Configuration for the card processor
77
+ * @returns Array of import results
78
+ */
79
+ declare function importParsedCards(parsedCards: ParsedCard[], courseDB: CourseDBInterface, config: BulkCardProcessorConfig): Promise<ImportResult[]>;
80
+ /**
81
+ * Validates the configuration for bulk card processing
82
+ *
83
+ * @param config - Configuration to validate
84
+ * @returns Object with validation result and error message if any
85
+ */
86
+ declare function validateProcessorConfig(config: Partial<BulkCardProcessorConfig>): {
87
+ isValid: boolean;
88
+ errorMessage?: string;
89
+ };
90
+
91
+ export { type BulkCardProcessorConfig, CardHistory, CardRecord, ContentNavigator, CourseDBInterface, type ImportResult, Loggable, Navigators, QuestionRecord, ScheduledCard, StudyContentSource, StudySessionNewItem, StudySessionReviewItem, UserDBInterface, areQuestionRecords, docIsDeleted, getCardHistoryID, importParsedCards, isQuestionRecord, parseCardHistoryID, validateProcessorConfig };