document-dataply 0.0.4-alpha.0 → 0.0.4-alpha.2

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/cjs/index.js CHANGED
@@ -7382,6 +7382,7 @@ var require_cjs = __commonJS({
7382
7382
  entrySize;
7383
7383
  buffer;
7384
7384
  view;
7385
+ commitCount = 0;
7385
7386
  /**
7386
7387
  * Constructor
7387
7388
  * @param walFilePath WAL file path
@@ -7541,6 +7542,20 @@ var require_cjs = __commonJS({
7541
7542
  }
7542
7543
  return restoredPages;
7543
7544
  }
7545
+ /**
7546
+ * Increments the commit count.
7547
+ */
7548
+ incrementCommitCount() {
7549
+ this.commitCount++;
7550
+ }
7551
+ /**
7552
+ * Returns whether a checkpoint should be performed.
7553
+ * @param threshold Threshold
7554
+ * @returns Whether a checkpoint should be performed
7555
+ */
7556
+ shouldCheckpoint(threshold) {
7557
+ return this.commitCount >= threshold;
7558
+ }
7544
7559
  /**
7545
7560
  * Initializes (clears) the log file.
7546
7561
  * Should be called after a checkpoint.
@@ -7553,6 +7568,7 @@ var require_cjs = __commonJS({
7553
7568
  return new Promise((resolve, reject) => {
7554
7569
  import_node_fs.default.truncate(this.walFilePath, 0, (err) => {
7555
7570
  if (err) return reject(err);
7571
+ this.commitCount = 0;
7556
7572
  resolve();
7557
7573
  });
7558
7574
  });
@@ -7674,16 +7690,15 @@ var require_cjs = __commonJS({
7674
7690
  };
7675
7691
  var PageFileSystem = class {
7676
7692
  /**
7677
- * @param fileHandle 파일 핸들 (fs.open으로 얻은 핸들)
7678
- * @param pageSize 페이지 크기
7679
7693
  * @param pageCacheCapacity 페이지 캐시 크기
7680
- * @param walPath WAL 파일 경로 (기본값: null)
7694
+ * @param options 데이터플라이 옵션
7681
7695
  */
7682
- constructor(fileHandle, pageSize, pageCacheCapacity, walPath) {
7696
+ constructor(fileHandle, pageSize, pageCacheCapacity, options) {
7683
7697
  this.fileHandle = fileHandle;
7684
7698
  this.pageSize = pageSize;
7685
7699
  this.pageCacheCapacity = pageCacheCapacity;
7686
- this.walPath = walPath;
7700
+ this.options = options;
7701
+ const walPath = options.wal;
7687
7702
  this.walManager = walPath ? new WALManager(walPath, pageSize) : null;
7688
7703
  this.pageManagerFactory = new PageManagerFactory();
7689
7704
  this.pageStrategy = new PageMVCCStrategy(fileHandle, pageSize, pageCacheCapacity);
@@ -8008,6 +8023,7 @@ var require_cjs = __commonJS({
8008
8023
  */
8009
8024
  async close() {
8010
8025
  if (this.walManager) {
8026
+ await this.walManager.clear();
8011
8027
  this.walManager.close();
8012
8028
  }
8013
8029
  }
@@ -8705,12 +8721,15 @@ var require_cjs = __commonJS({
8705
8721
  var Transaction3 = class {
8706
8722
  /**
8707
8723
  * @param id Transaction ID
8724
+ * @param context Transaction context
8708
8725
  * @param pageStrategy Page MVCC Strategy for disk I/O
8709
8726
  * @param lockManager LockManager instance
8727
+ * @param pfs Page File System
8710
8728
  */
8711
- constructor(id, context, pageStrategy, lockManager) {
8729
+ constructor(id, context, pageStrategy, lockManager, pfs) {
8712
8730
  this.context = context;
8713
8731
  this.lockManager = lockManager;
8732
+ this.pfs = pfs;
8714
8733
  this.id = id;
8715
8734
  this.pageStrategy = pageStrategy;
8716
8735
  }
@@ -8816,9 +8835,19 @@ var require_cjs = __commonJS({
8816
8835
  await hook();
8817
8836
  }
8818
8837
  });
8838
+ if (this.pfs.wal && this.dirtyPages.size > 0) {
8839
+ await this.pfs.wal.prepareCommit(this.dirtyPages);
8840
+ await this.pfs.wal.writeCommitMarker();
8841
+ }
8819
8842
  for (const [pageId, data] of this.dirtyPages) {
8820
8843
  await this.pageStrategy.write(pageId, data);
8821
8844
  }
8845
+ if (this.pfs.wal) {
8846
+ this.pfs.wal.incrementCommitCount();
8847
+ if (this.pfs.wal.shouldCheckpoint(this.pfs.options.walCheckpointThreshold)) {
8848
+ await this.pfs.wal.clear();
8849
+ }
8850
+ }
8822
8851
  this.dirtyPages.clear();
8823
8852
  this.undoPages.clear();
8824
8853
  this.releaseAllLocks();
@@ -8875,7 +8904,7 @@ var require_cjs = __commonJS({
8875
8904
  this.fileHandle,
8876
8905
  this.options.pageSize,
8877
8906
  this.options.pageCacheCapacity,
8878
- this.options.wal
8907
+ this.options
8879
8908
  );
8880
8909
  this.textCodec = new TextCodec();
8881
8910
  this.txContext = new TransactionContext();
@@ -8933,7 +8962,8 @@ var require_cjs = __commonJS({
8933
8962
  return Object.assign({
8934
8963
  pageSize: 8192,
8935
8964
  pageCacheCapacity: 1e4,
8936
- wal: null
8965
+ wal: null,
8966
+ walCheckpointThreshold: 1e3
8937
8967
  }, options);
8938
8968
  }
8939
8969
  /**
@@ -9051,7 +9081,8 @@ var require_cjs = __commonJS({
9051
9081
  ++this.txIdCounter,
9052
9082
  this.txContext,
9053
9083
  this.pfs.getPageStrategy(),
9054
- this.lockManager
9084
+ this.lockManager,
9085
+ this.pfs
9055
9086
  );
9056
9087
  }
9057
9088
  /**
@@ -57,7 +57,9 @@ export type DocumentDataplyQuery<T> = {
57
57
  */
58
58
  export type DocumentDataplyIndexedQuery<T extends DocumentJSON, IC extends IndexConfig<T>> = {
59
59
  [key in keyof IC]: key extends keyof FinalFlatten<DataplyDocument<T>> ? FinalFlatten<DataplyDocument<T>>[key] | DocumentDataplyCondition<FinalFlatten<DataplyDocument<T>>[key]> : never;
60
- };
60
+ } & DocumentDataplyQuery<{
61
+ _id: number;
62
+ }>;
61
63
  export interface DataplyTreeValue<T> {
62
64
  k: number;
63
65
  v: T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-dataply",
3
- "version": "0.0.4-alpha.0",
3
+ "version": "0.0.4-alpha.2",
4
4
  "description": "Simple and powerful JSON document database supporting complex queries and flexible indexing policies.",
5
5
  "license": "MIT",
6
6
  "author": "izure <admin@izure.org>",
@@ -42,7 +42,7 @@
42
42
  "dataply"
43
43
  ],
44
44
  "dependencies": {
45
- "dataply": "^0.0.20-alpha.0"
45
+ "dataply": "^0.0.20-alpha.1"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/jest": "^30.0.0",