@vue-skuilder/db 0.1.39 → 0.1.40

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.
@@ -351,11 +351,35 @@ interface CourseSyncStatus {
351
351
  *
352
352
  * The service is a singleton — course sync state is shared across the app.
353
353
  */
354
+ /**
355
+ * Tuning knobs for one-shot remote→local replication.
356
+ * Defaults are chosen for one-shot snapshot replication of bounded course
357
+ * corpora (text/JSON docs, no large attachments). PouchDB's built-in
358
+ * defaults (100/10) target live continuous sync — too conservative for
359
+ * cold-load UX on a course of a few thousand docs.
360
+ *
361
+ * Apps with smaller/larger corpora can override via
362
+ * `initializeDataLayer({ options: { courseSync: { replication: {...} } } })`.
363
+ */
364
+ interface ReplicationOptions {
365
+ /** Docs per `_bulk_get` HTTP request. Higher = fewer roundtrips. */
366
+ batchSize?: number;
367
+ /** Concurrent batches in flight. */
368
+ batchesLimit?: number;
369
+ }
354
370
  declare class CourseSyncService {
355
371
  private static instance;
356
372
  private entries;
373
+ private replicationOptions;
357
374
  private constructor();
358
375
  static getInstance(): CourseSyncService;
376
+ /**
377
+ * Apply replication tuning. Typically called once from `initializeDataLayer`.
378
+ * Partial overrides merge with defaults.
379
+ */
380
+ configure(opts: {
381
+ replication?: ReplicationOptions;
382
+ }): void;
359
383
  /**
360
384
  * Reset the singleton (for testing).
361
385
  */
@@ -506,4 +530,4 @@ declare function getStartAndEndKeys(key: string): {
506
530
  endkey: string;
507
531
  };
508
532
 
509
- export { AdminDB, CLASSROOM_CONFIG, ClassroomLookupDB, type ClassroomMessage, CouchDBSyncStrategy, CourseDB, CourseSyncService, type CourseSyncState, type CourseSyncStatus, CoursesDB, REVIEW_TIME_FORMAT, StudentClassroomDB, StudyContentSource, StudySessionItem, TeacherClassroomDB, addNote55, addTagToCard, createPouchDBConfig, createTag, deleteTag, filterAllDocsByPrefix, getAncestorTagIDs, getAppliedTags, getChildTagStubs, getClassroomConfig, getClassroomDB, getCouchUserDB, getCourseDB, getCourseDataShapes, getCourseDoc, getCourseDocs, getCourseQuestionTypes, getCourseTagStubs, getCredentialledCourseConfig, getCredentialledDataShapes, getLatestVersion, getRandomCards, getStartAndEndKeys, getTag, getTagID, hexEncode, localUserDB, removeTagFromCard, scheduleCardReview, updateCardElo, updateCredentialledCourseConfig, updateGuestAccountExpirationDate, updateTag, usernameIsAvailable };
533
+ export { AdminDB, CLASSROOM_CONFIG, ClassroomLookupDB, type ClassroomMessage, CouchDBSyncStrategy, CourseDB, CourseSyncService, type CourseSyncState, type CourseSyncStatus, CoursesDB, REVIEW_TIME_FORMAT, type ReplicationOptions, StudentClassroomDB, StudyContentSource, StudySessionItem, TeacherClassroomDB, addNote55, addTagToCard, createPouchDBConfig, createTag, deleteTag, filterAllDocsByPrefix, getAncestorTagIDs, getAppliedTags, getChildTagStubs, getClassroomConfig, getClassroomDB, getCouchUserDB, getCourseDB, getCourseDataShapes, getCourseDoc, getCourseDocs, getCourseQuestionTypes, getCourseTagStubs, getCredentialledCourseConfig, getCredentialledDataShapes, getLatestVersion, getRandomCards, getStartAndEndKeys, getTag, getTagID, hexEncode, localUserDB, removeTagFromCard, scheduleCardReview, updateCardElo, updateCredentialledCourseConfig, updateGuestAccountExpirationDate, updateTag, usernameIsAvailable };
@@ -351,11 +351,35 @@ interface CourseSyncStatus {
351
351
  *
352
352
  * The service is a singleton — course sync state is shared across the app.
353
353
  */
354
+ /**
355
+ * Tuning knobs for one-shot remote→local replication.
356
+ * Defaults are chosen for one-shot snapshot replication of bounded course
357
+ * corpora (text/JSON docs, no large attachments). PouchDB's built-in
358
+ * defaults (100/10) target live continuous sync — too conservative for
359
+ * cold-load UX on a course of a few thousand docs.
360
+ *
361
+ * Apps with smaller/larger corpora can override via
362
+ * `initializeDataLayer({ options: { courseSync: { replication: {...} } } })`.
363
+ */
364
+ interface ReplicationOptions {
365
+ /** Docs per `_bulk_get` HTTP request. Higher = fewer roundtrips. */
366
+ batchSize?: number;
367
+ /** Concurrent batches in flight. */
368
+ batchesLimit?: number;
369
+ }
354
370
  declare class CourseSyncService {
355
371
  private static instance;
356
372
  private entries;
373
+ private replicationOptions;
357
374
  private constructor();
358
375
  static getInstance(): CourseSyncService;
376
+ /**
377
+ * Apply replication tuning. Typically called once from `initializeDataLayer`.
378
+ * Partial overrides merge with defaults.
379
+ */
380
+ configure(opts: {
381
+ replication?: ReplicationOptions;
382
+ }): void;
359
383
  /**
360
384
  * Reset the singleton (for testing).
361
385
  */
@@ -506,4 +530,4 @@ declare function getStartAndEndKeys(key: string): {
506
530
  endkey: string;
507
531
  };
508
532
 
509
- export { AdminDB, CLASSROOM_CONFIG, ClassroomLookupDB, type ClassroomMessage, CouchDBSyncStrategy, CourseDB, CourseSyncService, type CourseSyncState, type CourseSyncStatus, CoursesDB, REVIEW_TIME_FORMAT, StudentClassroomDB, StudyContentSource, StudySessionItem, TeacherClassroomDB, addNote55, addTagToCard, createPouchDBConfig, createTag, deleteTag, filterAllDocsByPrefix, getAncestorTagIDs, getAppliedTags, getChildTagStubs, getClassroomConfig, getClassroomDB, getCouchUserDB, getCourseDB, getCourseDataShapes, getCourseDoc, getCourseDocs, getCourseQuestionTypes, getCourseTagStubs, getCredentialledCourseConfig, getCredentialledDataShapes, getLatestVersion, getRandomCards, getStartAndEndKeys, getTag, getTagID, hexEncode, localUserDB, removeTagFromCard, scheduleCardReview, updateCardElo, updateCredentialledCourseConfig, updateGuestAccountExpirationDate, updateTag, usernameIsAvailable };
533
+ export { AdminDB, CLASSROOM_CONFIG, ClassroomLookupDB, type ClassroomMessage, CouchDBSyncStrategy, CourseDB, CourseSyncService, type CourseSyncState, type CourseSyncStatus, CoursesDB, REVIEW_TIME_FORMAT, type ReplicationOptions, StudentClassroomDB, StudyContentSource, StudySessionItem, TeacherClassroomDB, addNote55, addTagToCard, createPouchDBConfig, createTag, deleteTag, filterAllDocsByPrefix, getAncestorTagIDs, getAppliedTags, getChildTagStubs, getClassroomConfig, getClassroomDB, getCouchUserDB, getCourseDB, getCourseDataShapes, getCourseDoc, getCourseDocs, getCourseQuestionTypes, getCourseTagStubs, getCredentialledCourseConfig, getCredentialledDataShapes, getLatestVersion, getRandomCards, getStartAndEndKeys, getTag, getTagID, hexEncode, localUserDB, removeTagFromCard, scheduleCardReview, updateCardElo, updateCredentialledCourseConfig, updateGuestAccountExpirationDate, updateTag, usernameIsAvailable };
@@ -7954,16 +7954,21 @@ var init_adminDB2 = __esm({
7954
7954
  });
7955
7955
 
7956
7956
  // src/impl/couch/CourseSyncService.ts
7957
- var CourseSyncService;
7957
+ var DEFAULT_REPLICATION, CourseSyncService;
7958
7958
  var init_CourseSyncService = __esm({
7959
7959
  "src/impl/couch/CourseSyncService.ts"() {
7960
7960
  "use strict";
7961
7961
  init_pouchdb_setup();
7962
7962
  init_couch();
7963
7963
  init_logger();
7964
+ DEFAULT_REPLICATION = {
7965
+ batchSize: 1e3,
7966
+ batchesLimit: 5
7967
+ };
7964
7968
  CourseSyncService = class _CourseSyncService {
7965
7969
  static instance = null;
7966
7970
  entries = /* @__PURE__ */ new Map();
7971
+ replicationOptions = DEFAULT_REPLICATION;
7967
7972
  constructor() {
7968
7973
  }
7969
7974
  static getInstance() {
@@ -7972,6 +7977,21 @@ var init_CourseSyncService = __esm({
7972
7977
  }
7973
7978
  return _CourseSyncService.instance;
7974
7979
  }
7980
+ /**
7981
+ * Apply replication tuning. Typically called once from `initializeDataLayer`.
7982
+ * Partial overrides merge with defaults.
7983
+ */
7984
+ configure(opts) {
7985
+ if (opts.replication) {
7986
+ this.replicationOptions = {
7987
+ ...DEFAULT_REPLICATION,
7988
+ ...opts.replication
7989
+ };
7990
+ logger.info(
7991
+ `[CourseSyncService] Replication configured: batch_size=${this.replicationOptions.batchSize}, batches_limit=${this.replicationOptions.batchesLimit}`
7992
+ );
7993
+ }
7994
+ }
7975
7995
  /**
7976
7996
  * Reset the singleton (for testing).
7977
7997
  */
@@ -8100,7 +8120,7 @@ var init_CourseSyncService = __esm({
8100
8120
  const remoteDB = this.getRemoteDB(courseId);
8101
8121
  const syncStart = Date.now();
8102
8122
  logger.info(
8103
- `[CourseSyncService] Starting one-shot replication for course ${courseId}`
8123
+ `[CourseSyncService] Starting one-shot replication for course ${courseId} (batch_size=${this.replicationOptions.batchSize}, batches_limit=${this.replicationOptions.batchesLimit})`
8104
8124
  );
8105
8125
  const result = await this.replicate(remoteDB, localDB);
8106
8126
  const syncTimeMs = Date.now() - syncStart;
@@ -8158,6 +8178,8 @@ var init_CourseSyncService = __esm({
8158
8178
  return new Promise((resolve, reject) => {
8159
8179
  void pouchdb_setup_default.replicate(source, target, {
8160
8180
  // One-shot, not live. Local is a read-only snapshot.
8181
+ batch_size: this.replicationOptions.batchSize,
8182
+ batches_limit: this.replicationOptions.batchesLimit
8161
8183
  }).on("complete", (info) => {
8162
8184
  resolve(info);
8163
8185
  }).on("error", (err) => {