@vue-skuilder/db 0.1.6 → 0.1.8-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.
Files changed (70) hide show
  1. package/dist/{SyncStrategy-DnJRj-Xp.d.mts → SyncStrategy-CyATpyLQ.d.mts} +6 -0
  2. package/dist/{SyncStrategy-DnJRj-Xp.d.ts → SyncStrategy-CyATpyLQ.d.ts} +6 -0
  3. package/dist/core/index.d.mts +5 -5
  4. package/dist/core/index.d.ts +5 -5
  5. package/dist/core/index.js +825 -762
  6. package/dist/core/index.js.map +1 -1
  7. package/dist/core/index.mjs +812 -750
  8. package/dist/core/index.mjs.map +1 -1
  9. package/dist/{dataLayerProvider-BZmLyBVw.d.mts → dataLayerProvider-BInqI_RF.d.mts} +1 -1
  10. package/dist/{dataLayerProvider-BuntXkCs.d.ts → dataLayerProvider-DqtNroSh.d.ts} +1 -1
  11. package/dist/impl/couch/index.d.mts +6 -6
  12. package/dist/impl/couch/index.d.ts +6 -6
  13. package/dist/impl/couch/index.js +2261 -2081
  14. package/dist/impl/couch/index.js.map +1 -1
  15. package/dist/impl/couch/index.mjs +2274 -2095
  16. package/dist/impl/couch/index.mjs.map +1 -1
  17. package/dist/impl/static/index.d.mts +8 -6
  18. package/dist/impl/static/index.d.ts +8 -6
  19. package/dist/impl/static/index.js +524 -1064
  20. package/dist/impl/static/index.js.map +1 -1
  21. package/dist/impl/static/index.mjs +515 -1058
  22. package/dist/impl/static/index.mjs.map +1 -1
  23. package/dist/index-CLL31bEy.d.ts +137 -0
  24. package/dist/index-CUNnL38E.d.mts +137 -0
  25. package/dist/index.d.mts +200 -9
  26. package/dist/index.d.ts +200 -9
  27. package/dist/index.js +4123 -2820
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +4119 -2830
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/{types-D6SnlHPm.d.ts → types-BefDGkKa.d.ts} +1 -1
  32. package/dist/{types-DPRvCrIk.d.mts → types-DC-ckZug.d.mts} +1 -1
  33. package/dist/{types-legacy-WPe8CtO-.d.mts → types-legacy-Birv-Jx6.d.mts} +2 -2
  34. package/dist/{types-legacy-WPe8CtO-.d.ts → types-legacy-Birv-Jx6.d.ts} +2 -2
  35. package/dist/{userDB-D9EuWTp1.d.ts → userDB-C33Hzjgn.d.mts} +11 -4
  36. package/dist/{userDB-31gsvxyd.d.mts → userDB-DusL7OXe.d.ts} +11 -4
  37. package/dist/util/packer/index.d.mts +3 -63
  38. package/dist/util/packer/index.d.ts +3 -63
  39. package/dist/util/packer/index.js +53 -1
  40. package/dist/util/packer/index.js.map +1 -1
  41. package/dist/util/packer/index.mjs +53 -1
  42. package/dist/util/packer/index.mjs.map +1 -1
  43. package/package.json +7 -4
  44. package/src/core/types/types-legacy.ts +13 -1
  45. package/src/core/types/user.ts +9 -2
  46. package/src/core/util/index.ts +5 -4
  47. package/src/factory.ts +25 -0
  48. package/src/impl/common/BaseUserDB.ts +62 -28
  49. package/src/impl/common/SyncStrategy.ts +7 -0
  50. package/src/impl/common/index.ts +0 -1
  51. package/src/impl/common/userDBHelpers.ts +15 -5
  52. package/src/impl/couch/CouchDBSyncStrategy.ts +10 -0
  53. package/src/impl/couch/courseAPI.ts +7 -6
  54. package/src/impl/couch/courseLookupDB.ts +24 -0
  55. package/src/impl/couch/index.ts +10 -5
  56. package/src/impl/couch/updateQueue.ts +12 -8
  57. package/src/impl/couch/user-course-relDB.ts +17 -27
  58. package/src/impl/static/NoOpSyncStrategy.ts +5 -0
  59. package/src/impl/static/StaticDataUnpacker.ts +18 -36
  60. package/src/impl/static/courseDB.ts +135 -17
  61. package/src/util/dataDirectory.test.ts +53 -0
  62. package/src/util/dataDirectory.ts +52 -0
  63. package/src/util/index.ts +3 -0
  64. package/src/util/migrator/FileSystemAdapter.ts +79 -0
  65. package/src/util/migrator/StaticToCouchDBMigrator.ts +713 -0
  66. package/src/util/migrator/index.ts +18 -0
  67. package/src/util/migrator/types.ts +84 -0
  68. package/src/util/migrator/validation.ts +517 -0
  69. package/src/util/packer/CouchDBToStaticPacker.ts +92 -2
  70. package/src/util/tuiLogger.ts +139 -0
package/dist/index.d.ts CHANGED
@@ -1,16 +1,199 @@
1
- import { S as StudySessionItem, c as StudyContentSource } from './userDB-D9EuWTp1.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, C as CourseDBInterface, q as CourseInfo, z as CourseRegistration, B as CourseRegistrationDoc, a as CoursesDBInterface, E as DocumentUpdater, D as ScheduledCard, d as StudentClassroomDBInterface, i as StudySessionFailedItem, j as StudySessionFailedNewItem, k as StudySessionFailedReviewItem, l as StudySessionNewItem, m as StudySessionReviewItem, T as TeacherClassroomDBInterface, x as UserConfig, s as UserCourseSetting, r as UserCourseSettings, U as UserDBInterface, t as UsrCrsDataInterface, p as getStudySource, n as isReview, F as newInterval } from './userDB-D9EuWTp1.js';
3
- import { D as DataLayerProvider } from './dataLayerProvider-BuntXkCs.js';
4
- import { C as CardRecord } from './types-legacy-WPe8CtO-.js';
5
- export { b as CardData, g as CardHistory, c as CourseListData, e as DataShapeData, d as DisplayableData, D as DocType, F as Field, G as GuestUsername, Q as QuestionData, h as QuestionRecord, S as SkuilderCourseData, T as Tag, a as TagStub, f as cardHistoryPrefix, l as log } from './types-legacy-WPe8CtO-.js';
1
+ import { j as StudySessionItem, h as StudyContentSource } from './userDB-DusL7OXe.js';
2
+ export { B as ActivityRecord, A as AdminDBInterface, s as AssignedCard, g as AssignedContent, r as AssignedCourse, q as AssignedTag, b as ClassroomDBInterface, x as ClassroomRegistration, w as ClassroomRegistrationDesignation, y as ClassroomRegistrationDoc, o as ContentSourceID, C as CourseDBInterface, c as CourseInfo, E as CourseRegistration, F as CourseRegistrationDoc, a as CoursesDBInterface, G as DocumentUpdater, f as ScheduledCard, i as StudentClassroomDBInterface, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, S as StudySessionNewItem, e as StudySessionReviewItem, T as TeacherClassroomDBInterface, z as UserConfig, u as UserCourseSetting, t as UserCourseSettings, U as UserDBInterface, v as UsrCrsDataInterface, p as getStudySource, n as isReview, H as newInterval } from './userDB-DusL7OXe.js';
3
+ import { D as DataLayerProvider } from './dataLayerProvider-DqtNroSh.js';
4
+ import { C as CardRecord } from './types-legacy-Birv-Jx6.js';
5
+ export { b as CardData, g as CardHistory, c as CourseListData, e as DataShapeData, d as DisplayableData, D as DocType, f as DocTypePrefixes, F as Field, G as GuestUsername, Q as QuestionData, h as QuestionRecord, S as SkuilderCourseData, a as Tag, T as TagStub, l as log } from './types-legacy-Birv-Jx6.js';
6
6
  import { Loggable } from './core/index.js';
7
7
  export { BulkCardProcessorConfig, ContentNavigator, ImportResult, Navigators, areQuestionRecords, docIsDeleted, getCardHistoryID, importParsedCards, isQuestionRecord, parseCardHistoryID, validateProcessorConfig } from './core/index.js';
8
- import { S as StaticCourseManifest } from './types-D6SnlHPm.js';
9
- export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, a as PackedCourseData, P as PackerConfig } from './types-D6SnlHPm.js';
10
- export { CouchDBToStaticPacker } from './util/packer/index.js';
8
+ import { S as StaticCourseManifest } from './types-BefDGkKa.js';
9
+ export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, a as PackedCourseData, P as PackerConfig } from './types-BefDGkKa.js';
10
+ import { F as FileSystemAdapter } from './index-CLL31bEy.js';
11
+ export { C as CouchDBToStaticPacker, a as FileStats, b as FileSystemError } from './index-CLL31bEy.js';
11
12
  import '@vue-skuilder/common';
12
13
  import 'moment';
13
14
 
15
+ interface MigrationOptions {
16
+ chunkBatchSize: number;
17
+ validateRoundTrip: boolean;
18
+ cleanupOnFailure: boolean;
19
+ timeout: number;
20
+ }
21
+ interface MigrationResult {
22
+ success: boolean;
23
+ documentsRestored: number;
24
+ attachmentsRestored: number;
25
+ designDocsRestored: number;
26
+ courseConfigRestored: number;
27
+ errors: string[];
28
+ warnings: string[];
29
+ migrationTime: number;
30
+ tempDatabaseName?: string;
31
+ }
32
+ interface ValidationResult {
33
+ valid: boolean;
34
+ documentCountMatch: boolean;
35
+ attachmentIntegrity: boolean;
36
+ viewFunctionality: boolean;
37
+ issues: ValidationIssue[];
38
+ }
39
+ interface ValidationIssue {
40
+ type: 'error' | 'warning';
41
+ category: 'documents' | 'attachments' | 'views' | 'metadata' | 'course_config';
42
+ message: string;
43
+ details?: any;
44
+ }
45
+ interface DocumentCounts {
46
+ [docType: string]: number;
47
+ }
48
+ interface RestoreProgress {
49
+ phase: 'manifest' | 'design_docs' | 'course_config' | 'documents' | 'attachments' | 'validation';
50
+ current: number;
51
+ total: number;
52
+ message: string;
53
+ }
54
+ interface StaticCourseValidation {
55
+ valid: boolean;
56
+ manifestExists: boolean;
57
+ chunksExist: boolean;
58
+ attachmentsExist: boolean;
59
+ errors: string[];
60
+ warnings: string[];
61
+ courseId?: string;
62
+ courseName?: string;
63
+ }
64
+ interface AggregatedDocument {
65
+ _id: string;
66
+ _attachments?: Record<string, any>;
67
+ docType: string;
68
+ [key: string]: any;
69
+ }
70
+ interface AttachmentUploadResult {
71
+ success: boolean;
72
+ attachmentName: string;
73
+ docId: string;
74
+ error?: string;
75
+ }
76
+ declare const DEFAULT_MIGRATION_OPTIONS: MigrationOptions;
77
+
78
+ declare class StaticToCouchDBMigrator {
79
+ private options;
80
+ private progressCallback?;
81
+ private fs?;
82
+ constructor(options?: Partial<MigrationOptions>, fileSystemAdapter?: FileSystemAdapter);
83
+ /**
84
+ * Set a progress callback to receive updates during migration
85
+ */
86
+ setProgressCallback(callback: (progress: RestoreProgress) => void): void;
87
+ /**
88
+ * Migrate a static course to CouchDB
89
+ */
90
+ migrateCourse(staticPath: string, targetDB: PouchDB.Database): Promise<MigrationResult>;
91
+ /**
92
+ * Load and parse the manifest file
93
+ */
94
+ private loadManifest;
95
+ /**
96
+ * Restore design documents to CouchDB
97
+ */
98
+ private restoreDesignDocuments;
99
+ /**
100
+ * Aggregate documents from all chunks
101
+ */
102
+ private aggregateDocuments;
103
+ /**
104
+ * Load documents from a single chunk file
105
+ */
106
+ private loadChunk;
107
+ /**
108
+ * Upload documents to CouchDB in batches
109
+ */
110
+ private uploadDocuments;
111
+ /**
112
+ * Upload attachments from filesystem to CouchDB
113
+ */
114
+ private uploadAttachments;
115
+ /**
116
+ * Upload a single attachment file
117
+ */
118
+ private uploadSingleAttachment;
119
+ /**
120
+ * Restore CourseConfig document from manifest
121
+ */
122
+ private restoreCourseConfig;
123
+ /**
124
+ * Calculate expected document counts from manifest
125
+ */
126
+ private calculateExpectedCounts;
127
+ /**
128
+ * Clean up database after failed migration
129
+ */
130
+ private cleanupFailedMigration;
131
+ /**
132
+ * Report progress to callback if available
133
+ */
134
+ private reportProgress;
135
+ /**
136
+ * Check if a path is a local file path (vs URL)
137
+ */
138
+ private isLocalPath;
139
+ }
140
+
141
+ /**
142
+ * Validate that a static course directory contains all required files
143
+ */
144
+ declare function validateStaticCourse(staticPath: string, fs?: FileSystemAdapter): Promise<StaticCourseValidation>;
145
+ /**
146
+ * Validate the result of a migration by checking document counts and integrity
147
+ */
148
+ declare function validateMigration(targetDB: PouchDB.Database, expectedCounts: DocumentCounts, manifest: StaticCourseManifest): Promise<ValidationResult>;
149
+
150
+ /**
151
+ * Get the application data directory for the current platform
152
+ * Uses ~/.tuilder as requested by user for simplicity
153
+ */
154
+ declare function getAppDataDirectory(): string;
155
+ /**
156
+ * Ensure the application data directory exists
157
+ * Creates directory recursively if it doesn't exist
158
+ */
159
+ declare function ensureAppDataDirectory(): Promise<string>;
160
+ /**
161
+ * Get the full path for a PouchDB database file
162
+ * @param dbName - The database name (e.g., 'userdb-Colin')
163
+ */
164
+ declare function getDbPath(dbName: string): string;
165
+ /**
166
+ * Initialize data directory for PouchDB usage
167
+ * Should be called once at application startup
168
+ */
169
+ declare function initializeDataDirectory(): Promise<void>;
170
+
171
+ /**
172
+ * Initialize TUI logging - redirect console logs to file in Node.js
173
+ */
174
+ declare function initializeTuiLogging(): void;
175
+ /**
176
+ * Get the current log file path (for debugging)
177
+ */
178
+ declare function getLogFilePath(): string | null;
179
+ /**
180
+ * Show user-facing message (always visible in TUI)
181
+ */
182
+ declare function showUserMessage(message: string): void;
183
+ /**
184
+ * Show user-facing error (always visible in TUI)
185
+ */
186
+ declare function showUserError(message: string): void;
187
+ /**
188
+ * Logger object with standard log levels
189
+ */
190
+ declare const logger: {
191
+ debug: (message: string, ...args: any[]) => void;
192
+ info: (message: string, ...args: any[]) => void;
193
+ warn: (message: string, ...args: any[]) => void;
194
+ error: (message: string, ...args: any[]) => void;
195
+ };
196
+
14
197
  interface StudySessionRecord {
15
198
  card: {
16
199
  course_id: string;
@@ -95,6 +278,14 @@ declare class CourseLookup {
95
278
  * @returns
96
279
  */
97
280
  static add(courseName: string): Promise<string>;
281
+ /**
282
+ * Adds a new course to the lookup database with a specific courseID
283
+ * @param courseId The specific course ID to use
284
+ * @param courseName The course name
285
+ * @param disambiguator Optional disambiguator
286
+ * @returns Promise<void>
287
+ */
288
+ static addWithId(courseId: string, courseName: string, disambiguator?: string): Promise<void>;
98
289
  /**
99
290
  * Removes a course from the index
100
291
  * @param courseID
@@ -139,4 +330,4 @@ declare function getDataLayer(): DataLayerProvider;
139
330
  */
140
331
  declare function _resetDataLayer(): Promise<void>;
141
332
 
142
- export { CardRecord, CourseLookup, type DataLayerConfig, DataLayerProvider, ENV, Loggable, SessionController, StaticCourseManifest, StudyContentSource, StudySessionItem, type StudySessionRecord, _resetDataLayer, getDataLayer, initializeDataLayer };
333
+ export { type AggregatedDocument, type AttachmentUploadResult, CardRecord, CourseLookup, DEFAULT_MIGRATION_OPTIONS, type DataLayerConfig, DataLayerProvider, type DocumentCounts, ENV, FileSystemAdapter, Loggable, type MigrationOptions, type MigrationResult, type RestoreProgress, SessionController, StaticCourseManifest, type StaticCourseValidation, StaticToCouchDBMigrator, StudyContentSource, StudySessionItem, type StudySessionRecord, type ValidationIssue, type ValidationResult, _resetDataLayer, ensureAppDataDirectory, getAppDataDirectory, getDataLayer, getDbPath, getLogFilePath, initializeDataDirectory, initializeDataLayer, initializeTuiLogging, logger, showUserError, showUserMessage, validateMigration, validateStaticCourse };