@vue-skuilder/db 0.1.39 → 0.2.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.
package/dist/index.d.cts CHANGED
@@ -1117,6 +1117,17 @@ interface DataLayerConfig {
1117
1117
  COUCHDB_USERNAME?: string;
1118
1118
  COUCHDB_PASSWORD?: string;
1119
1119
  COURSE_IDS?: string[];
1120
+ /**
1121
+ * Per-app tuning for the CouchDB→PouchDB course sync. Only applies when
1122
+ * `type === 'couch'` and the course has `localSync.enabled === true`.
1123
+ * See CourseSyncService.ReplicationOptions for defaults.
1124
+ */
1125
+ courseSync?: {
1126
+ replication?: {
1127
+ batchSize?: number;
1128
+ batchesLimit?: number;
1129
+ };
1130
+ };
1120
1131
  };
1121
1132
  }
1122
1133
  /**
package/dist/index.d.ts CHANGED
@@ -1117,6 +1117,17 @@ interface DataLayerConfig {
1117
1117
  COUCHDB_USERNAME?: string;
1118
1118
  COUCHDB_PASSWORD?: string;
1119
1119
  COURSE_IDS?: string[];
1120
+ /**
1121
+ * Per-app tuning for the CouchDB→PouchDB course sync. Only applies when
1122
+ * `type === 'couch'` and the course has `localSync.enabled === true`.
1123
+ * See CourseSyncService.ReplicationOptions for defaults.
1124
+ */
1125
+ courseSync?: {
1126
+ replication?: {
1127
+ batchSize?: number;
1128
+ batchesLimit?: number;
1129
+ };
1130
+ };
1120
1131
  };
1121
1132
  }
1122
1133
  /**
package/dist/index.js CHANGED
@@ -6469,16 +6469,25 @@ var init_adminDB2 = __esm({
6469
6469
  });
6470
6470
 
6471
6471
  // src/impl/couch/CourseSyncService.ts
6472
- var CourseSyncService;
6472
+ var CourseSyncService_exports = {};
6473
+ __export(CourseSyncService_exports, {
6474
+ CourseSyncService: () => CourseSyncService
6475
+ });
6476
+ var DEFAULT_REPLICATION, CourseSyncService;
6473
6477
  var init_CourseSyncService = __esm({
6474
6478
  "src/impl/couch/CourseSyncService.ts"() {
6475
6479
  "use strict";
6476
6480
  init_pouchdb_setup();
6477
6481
  init_couch();
6478
6482
  init_logger();
6483
+ DEFAULT_REPLICATION = {
6484
+ batchSize: 1e3,
6485
+ batchesLimit: 5
6486
+ };
6479
6487
  CourseSyncService = class _CourseSyncService {
6480
6488
  static instance = null;
6481
6489
  entries = /* @__PURE__ */ new Map();
6490
+ replicationOptions = DEFAULT_REPLICATION;
6482
6491
  constructor() {
6483
6492
  }
6484
6493
  static getInstance() {
@@ -6487,6 +6496,21 @@ var init_CourseSyncService = __esm({
6487
6496
  }
6488
6497
  return _CourseSyncService.instance;
6489
6498
  }
6499
+ /**
6500
+ * Apply replication tuning. Typically called once from `initializeDataLayer`.
6501
+ * Partial overrides merge with defaults.
6502
+ */
6503
+ configure(opts) {
6504
+ if (opts.replication) {
6505
+ this.replicationOptions = {
6506
+ ...DEFAULT_REPLICATION,
6507
+ ...opts.replication
6508
+ };
6509
+ logger.info(
6510
+ `[CourseSyncService] Replication configured: batch_size=${this.replicationOptions.batchSize}, batches_limit=${this.replicationOptions.batchesLimit}`
6511
+ );
6512
+ }
6513
+ }
6490
6514
  /**
6491
6515
  * Reset the singleton (for testing).
6492
6516
  */
@@ -6615,7 +6639,7 @@ var init_CourseSyncService = __esm({
6615
6639
  const remoteDB = this.getRemoteDB(courseId);
6616
6640
  const syncStart = Date.now();
6617
6641
  logger.info(
6618
- `[CourseSyncService] Starting one-shot replication for course ${courseId}`
6642
+ `[CourseSyncService] Starting one-shot replication for course ${courseId} (batch_size=${this.replicationOptions.batchSize}, batches_limit=${this.replicationOptions.batchesLimit})`
6619
6643
  );
6620
6644
  const result = await this.replicate(remoteDB, localDB);
6621
6645
  const syncTimeMs = Date.now() - syncStart;
@@ -6673,6 +6697,8 @@ var init_CourseSyncService = __esm({
6673
6697
  return new Promise((resolve, reject) => {
6674
6698
  void pouchdb_setup_default.replicate(source, target, {
6675
6699
  // One-shot, not live. Local is a read-only snapshot.
6700
+ batch_size: this.replicationOptions.batchSize,
6701
+ batches_limit: this.replicationOptions.batchesLimit
6676
6702
  }).on("complete", (info) => {
6677
6703
  resolve(info);
6678
6704
  }).on("error", (err) => {
@@ -9298,6 +9324,10 @@ async function initializeDataLayer(config) {
9298
9324
  ENV.COUCHDB_SERVER_URL = config.options.COUCHDB_SERVER_URL;
9299
9325
  ENV.COUCHDB_USERNAME = config.options.COUCHDB_USERNAME;
9300
9326
  ENV.COUCHDB_PASSWORD = config.options.COUCHDB_PASSWORD;
9327
+ if (config.options.courseSync) {
9328
+ const { CourseSyncService: CourseSyncService2 } = await Promise.resolve().then(() => (init_CourseSyncService(), CourseSyncService_exports));
9329
+ CourseSyncService2.getInstance().configure(config.options.courseSync);
9330
+ }
9301
9331
  if (config.options.COUCHDB_PASSWORD && config.options.COUCHDB_USERNAME && typeof window !== "undefined") {
9302
9332
  const { CouchDBSyncStrategy: CouchDBSyncStrategy2 } = await Promise.resolve().then(() => (init_CouchDBSyncStrategy(), CouchDBSyncStrategy_exports));
9303
9333
  const syncStrategy = new CouchDBSyncStrategy2();
@@ -13968,8 +13998,8 @@ var SessionController = class _SessionController extends Loggable {
13968
13998
  this._minCardsGuarantee--;
13969
13999
  this.log(`[CardGuarantee] ${this._minCardsGuarantee} guaranteed cards remaining`);
13970
14000
  }
13971
- if (this._replanPromise) {
13972
- this.log("nextCard: awaiting in-flight replan before drawing");
14001
+ if (this._replanPromise && this.newQ.length === 0 && this.reviewQ.length === 0 && this.failedQ.length === 0) {
14002
+ this.log("nextCard: queues empty, awaiting in-flight replan before drawing");
13973
14003
  await this._replanPromise;
13974
14004
  }
13975
14005
  if (this.newQ.length <= 1 && this._secondsRemaining > 0 && !this._replanPromise) {