document-dataply 0.0.3 → 0.0.4-alpha.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/cjs/index.js CHANGED
@@ -285,6 +285,45 @@ var require_cjs = __commonJS({
285
285
  }
286
286
  return { success: true, created, updated, deleted };
287
287
  }
288
+ /**
289
+ * Cleans up both deletedCache and versionIndex based on minActiveVersion.
290
+ * Root transactions call this after commit to reclaim memory.
291
+ */
292
+ _cleanupDeletedCache() {
293
+ if (this.deletedCache.size === 0 && this.versionIndex.size === 0) return;
294
+ let minActiveVersion = this.version;
295
+ if (this.activeTransactions.size > 0) {
296
+ for (const tx of this.activeTransactions) {
297
+ if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
298
+ minActiveVersion = tx.snapshotVersion;
299
+ }
300
+ }
301
+ }
302
+ if (this.deletedCache.size > 0) {
303
+ for (const [key, cachedList] of this.deletedCache) {
304
+ const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
305
+ if (remaining.length === 0) {
306
+ this.deletedCache.delete(key);
307
+ } else {
308
+ this.deletedCache.set(key, remaining);
309
+ }
310
+ }
311
+ }
312
+ if (this.versionIndex.size > 0) {
313
+ for (const [key, versions] of this.versionIndex) {
314
+ let latestInSnapshotIdx = -1;
315
+ for (let i = versions.length - 1; i >= 0; i--) {
316
+ if (versions[i].version <= minActiveVersion) {
317
+ latestInSnapshotIdx = i;
318
+ break;
319
+ }
320
+ }
321
+ if (latestInSnapshotIdx > 0) {
322
+ versions.splice(0, latestInSnapshotIdx);
323
+ }
324
+ }
325
+ }
326
+ }
288
327
  };
289
328
  var SyncMVCCStrategy = class extends MVCCStrategy {
290
329
  };
@@ -624,25 +663,6 @@ var require_cjs = __commonJS({
624
663
  if (!this.versionIndex.has(key)) this.versionIndex.set(key, []);
625
664
  this.versionIndex.get(key).push({ version: snapshotVersion, exists: false });
626
665
  }
627
- _cleanupDeletedCache() {
628
- if (this.deletedCache.size === 0) return;
629
- let minActiveVersion = this.version;
630
- if (this.activeTransactions.size > 0) {
631
- for (const tx of this.activeTransactions) {
632
- if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
633
- minActiveVersion = tx.snapshotVersion;
634
- }
635
- }
636
- }
637
- for (const [key, cachedList] of this.deletedCache) {
638
- const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
639
- if (remaining.length === 0) {
640
- this.deletedCache.delete(key);
641
- } else {
642
- this.deletedCache.set(key, remaining);
643
- }
644
- }
645
- }
646
666
  };
647
667
  var AsyncMVCCStrategy = class extends MVCCStrategy {
648
668
  };
@@ -1251,25 +1271,6 @@ var require_cjs = __commonJS({
1251
1271
  if (!this.versionIndex.has(key)) this.versionIndex.set(key, []);
1252
1272
  this.versionIndex.get(key).push({ version: snapshotVersion, exists: false });
1253
1273
  }
1254
- _cleanupDeletedCache() {
1255
- if (this.deletedCache.size === 0) return;
1256
- let minActiveVersion = this.version;
1257
- if (this.activeTransactions.size > 0) {
1258
- for (const tx of this.activeTransactions) {
1259
- if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
1260
- minActiveVersion = tx.snapshotVersion;
1261
- }
1262
- }
1263
- }
1264
- for (const [key, cachedList] of this.deletedCache) {
1265
- const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
1266
- if (remaining.length === 0) {
1267
- this.deletedCache.delete(key);
1268
- } else {
1269
- this.deletedCache.set(key, remaining);
1270
- }
1271
- }
1272
- }
1273
1274
  };
1274
1275
  var LRUMap = class {
1275
1276
  capacity;
@@ -4729,6 +4730,45 @@ var require_cjs = __commonJS({
4729
4730
  }
4730
4731
  return { success: true, created, updated, deleted };
4731
4732
  }
4733
+ /**
4734
+ * Cleans up both deletedCache and versionIndex based on minActiveVersion.
4735
+ * Root transactions call this after commit to reclaim memory.
4736
+ */
4737
+ _cleanupDeletedCache() {
4738
+ if (this.deletedCache.size === 0 && this.versionIndex.size === 0) return;
4739
+ let minActiveVersion = this.version;
4740
+ if (this.activeTransactions.size > 0) {
4741
+ for (const tx of this.activeTransactions) {
4742
+ if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
4743
+ minActiveVersion = tx.snapshotVersion;
4744
+ }
4745
+ }
4746
+ }
4747
+ if (this.deletedCache.size > 0) {
4748
+ for (const [key, cachedList] of this.deletedCache) {
4749
+ const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
4750
+ if (remaining.length === 0) {
4751
+ this.deletedCache.delete(key);
4752
+ } else {
4753
+ this.deletedCache.set(key, remaining);
4754
+ }
4755
+ }
4756
+ }
4757
+ if (this.versionIndex.size > 0) {
4758
+ for (const [key, versions] of this.versionIndex) {
4759
+ let latestInSnapshotIdx = -1;
4760
+ for (let i = versions.length - 1; i >= 0; i--) {
4761
+ if (versions[i].version <= minActiveVersion) {
4762
+ latestInSnapshotIdx = i;
4763
+ break;
4764
+ }
4765
+ }
4766
+ if (latestInSnapshotIdx > 0) {
4767
+ versions.splice(0, latestInSnapshotIdx);
4768
+ }
4769
+ }
4770
+ }
4771
+ }
4732
4772
  };
4733
4773
  var SyncMVCCStrategy2 = class extends MVCCStrategy2 {
4734
4774
  };
@@ -5068,25 +5108,6 @@ var require_cjs = __commonJS({
5068
5108
  if (!this.versionIndex.has(key)) this.versionIndex.set(key, []);
5069
5109
  this.versionIndex.get(key).push({ version: snapshotVersion, exists: false });
5070
5110
  }
5071
- _cleanupDeletedCache() {
5072
- if (this.deletedCache.size === 0) return;
5073
- let minActiveVersion = this.version;
5074
- if (this.activeTransactions.size > 0) {
5075
- for (const tx of this.activeTransactions) {
5076
- if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
5077
- minActiveVersion = tx.snapshotVersion;
5078
- }
5079
- }
5080
- }
5081
- for (const [key, cachedList] of this.deletedCache) {
5082
- const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
5083
- if (remaining.length === 0) {
5084
- this.deletedCache.delete(key);
5085
- } else {
5086
- this.deletedCache.set(key, remaining);
5087
- }
5088
- }
5089
- }
5090
5111
  };
5091
5112
  var AsyncMVCCStrategy2 = class extends MVCCStrategy2 {
5092
5113
  };
@@ -5695,25 +5716,6 @@ var require_cjs = __commonJS({
5695
5716
  if (!this.versionIndex.has(key)) this.versionIndex.set(key, []);
5696
5717
  this.versionIndex.get(key).push({ version: snapshotVersion, exists: false });
5697
5718
  }
5698
- _cleanupDeletedCache() {
5699
- if (this.deletedCache.size === 0) return;
5700
- let minActiveVersion = this.version;
5701
- if (this.activeTransactions.size > 0) {
5702
- for (const tx of this.activeTransactions) {
5703
- if (!tx.committed && tx.snapshotVersion < minActiveVersion) {
5704
- minActiveVersion = tx.snapshotVersion;
5705
- }
5706
- }
5707
- }
5708
- for (const [key, cachedList] of this.deletedCache) {
5709
- const remaining = cachedList.filter((item) => item.deletedAtVersion > minActiveVersion);
5710
- if (remaining.length === 0) {
5711
- this.deletedCache.delete(key);
5712
- } else {
5713
- this.deletedCache.set(key, remaining);
5714
- }
5715
- }
5716
- }
5717
5719
  };
5718
5720
  function numberToBytes(value, buffer, offset = 0, length = buffer.length) {
5719
5721
  if (length === 4) {
@@ -9105,9 +9107,10 @@ var require_cjs = __commonJS({
9105
9107
  await tx.rollback();
9106
9108
  }
9107
9109
  throw error;
9108
- }
9109
- if (!hasError && isInternalTx) {
9110
- await tx.commit();
9110
+ } finally {
9111
+ if (!hasError && isInternalTx) {
9112
+ await tx.commit();
9113
+ }
9111
9114
  }
9112
9115
  }
9113
9116
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-dataply",
3
- "version": "0.0.3",
3
+ "version": "0.0.4-alpha.0",
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.19"
45
+ "dataply": "^0.0.20-alpha.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/jest": "^30.0.0",
@@ -51,4 +51,4 @@
51
51
  "ts-jest": "^29.4.6",
52
52
  "typescript": "^5.9.3"
53
53
  }
54
- }
54
+ }
package/readme.md CHANGED
@@ -8,7 +8,7 @@
8
8
  > **This project is currently in the Alpha stage.**
9
9
  > APIs and internal structures may change significantly between versions. Use with caution in production environments.
10
10
 
11
- `document-dataply` is a high-performance document-oriented database library built on top of the [`dataply`](https://github.com/izure1/dataply) record storage engine. It provides a structured way to store, index, and query JSON-style documents, supporting transactions and complex field indexing.
11
+ `document-dataply` is a **pure JavaScript** high-performance document-oriented database library built on top of the [`dataply`](https://github.com/izure1/dataply) record storage engine. It is designed to handle **millions of rows** with high stability, providing a structured way to store, index, and query JSON-style documents.
12
12
 
13
13
  ## Key Features
14
14
 
@@ -16,9 +16,22 @@
16
16
  - **B+Tree Indexing**: Supports high-performance lookups using a B+Tree indexing engine.
17
17
  - **Deep Indexing**: Index nested object fields and specific array elements (e.g., `user.profile.name` or `tags.0`).
18
18
  - **Flexible Indexing Policies**: Supports full re-indexing for existing data or incremental indexing for future data.
19
- - **Transactions**: ACID-compliant transactions for atomic operations.
19
+ - **ACID Transactions**: Reliable atomic operations with **WAL (Write-Ahead Logging)** and **MVCC (Multi-Version Concurrency Control)** support.
20
+ - **Modern Architecture**: Fully supports **Async/Await** and **Streaming**, making it ideal for modern high-concurrency server environments.
20
21
  - **Rich Querying**: Supports comparison operators (`lt`, `gt`, `equal`, etc.) and pattern matching (`like`).
21
22
 
23
+ ## Platform Compatibility
24
+
25
+ Built with pure JavaScript, `document-dataply` can be used in various environments:
26
+ - **Official Support**: Node.js, Electron, NW.js
27
+ - **Experimental Support**: Deno, Bun
28
+
29
+ ## Data Types
30
+
31
+ Supports standard JSON data types:
32
+ - `string`, `number`, `boolean`, `null`
33
+ - Nested `object` and `array`
34
+
22
35
  ## Installation
23
36
 
24
37
  ```bash
@@ -58,7 +71,7 @@ async function main() {
58
71
 
59
72
  // Query document
60
73
  const query = db.select({
61
- name: 'John Doe',
74
+ name: 'John Doe', // Shortcut for { name: { equal: 'John Doe' } }
62
75
  age: { gte: 25 }
63
76
  })
64
77