dataply 0.0.7 → 0.0.9

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.
@@ -1,15 +1,12 @@
1
1
  import type { DataplyOptions, DataplyMetadata } from '../types';
2
- import { type IHookall, type IHookallSync } from 'hookall';
2
+ import { type IHookall } from 'hookall';
3
3
  import { PageFileSystem } from './PageFileSystem';
4
4
  import { RowTableEngine } from './RowTableEngine';
5
5
  import { TextCodec } from '../utils/TextCodec';
6
6
  import { LockManager } from './transaction/LockManager';
7
7
  import { Transaction } from './transaction/Transaction';
8
- interface DataplyAPISyncHook {
9
- create: (_: void, file: string, fileHandle: number, options: Required<DataplyOptions>) => void;
10
- }
11
8
  interface DataplyAPIAsyncHook {
12
- init: () => Promise<void>;
9
+ init: (tx: Transaction, isNewlyCreated: boolean) => Promise<Transaction>;
13
10
  close: () => Promise<void>;
14
11
  }
15
12
  /**
@@ -17,17 +14,28 @@ interface DataplyAPIAsyncHook {
17
14
  */
18
15
  export declare class DataplyAPI {
19
16
  protected readonly file: string;
17
+ /**
18
+ * These are not the same options that were used when the database was created.
19
+ * They are simply the options received when the instance was created.
20
+ * If you want to retrieve the options used during database creation, use `getMetadata()` instead.
21
+ */
20
22
  readonly options: Required<DataplyOptions>;
23
+ /** File handle. Database file descriptor */
21
24
  protected readonly fileHandle: number;
25
+ /** Page file system. Used for managing pages. If you know what it is, you can skip this. */
22
26
  protected readonly pfs: PageFileSystem;
27
+ /** Row table engine. Used for managing rows. If you know what it is, you can skip this. */
23
28
  protected readonly rowTableEngine: RowTableEngine;
29
+ /** Lock manager. Used for managing transactions */
24
30
  protected readonly lockManager: LockManager;
31
+ /** Text codec. Used for encoding and decoding text data */
25
32
  protected readonly textCodec: TextCodec;
26
- protected readonly hook: {
27
- sync: IHookallSync<DataplyAPISyncHook>;
28
- async: IHookall<DataplyAPIAsyncHook>;
29
- };
33
+ /** Hook */
34
+ protected readonly hook: IHookall<DataplyAPIAsyncHook>;
35
+ /** Whether the database was initialized via `init()` */
30
36
  protected initialized: boolean;
37
+ /** Whether the database was created this time. */
38
+ private readonly isNewlyCreated;
31
39
  private txIdCounter;
32
40
  constructor(file: string, options: DataplyOptions);
33
41
  /**
@@ -94,6 +102,14 @@ export declare class DataplyAPI {
94
102
  * @returns PK of the added data
95
103
  */
96
104
  insert(data: string | Uint8Array, incrementRowCount?: boolean, tx?: Transaction): Promise<number>;
105
+ /**
106
+ * Inserts overflow data forcly. Returns the PK of the added row.
107
+ * @param data Data to add
108
+ * @param incrementRowCount Whether to increment the row count to metadata
109
+ * @param tx Transaction
110
+ * @returns PK of the added data
111
+ */
112
+ insertAsOverflow(data: string | Uint8Array, incrementRowCount?: boolean, tx?: Transaction): Promise<number>;
97
113
  /**
98
114
  * Inserts multiple data in batch.
99
115
  * If a transaction is not provided, it internally creates a single transaction to process.
@@ -64,7 +64,7 @@ export declare class RowTableEngine {
64
64
  * @param tx Transaction
65
65
  * @returns PK of the inserted data
66
66
  */
67
- insert(data: Uint8Array, incrementRowCount: boolean, tx: Transaction): Promise<number>;
67
+ insert(data: Uint8Array, incrementRowCount: boolean, overflowForcly: boolean, tx: Transaction): Promise<number>;
68
68
  /**
69
69
  * Looks up the RID by PK.
70
70
  * Checks Pending Updates first if a transaction exists.
@@ -2,7 +2,7 @@ export * from 'serializable-bptree';
2
2
  export * from 'ryoiki';
3
3
  export * from 'cache-entanglement';
4
4
  export type { DataplyOptions } from './types';
5
- export type * from './core/Page';
5
+ export * from './core/Page';
6
6
  export { Dataply } from './core/Dataply';
7
7
  export { DataplyAPI } from './core/DataplyAPI';
8
8
  export { Transaction } from './core/transaction/Transaction';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataply",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "A lightweight storage engine for Node.js with support for MVCC, WAL.",
5
5
  "license": "MIT",
6
6
  "author": "izure <admin@izure.org>",
package/readme.md CHANGED
@@ -178,6 +178,8 @@ Rolls back all added transactions.
178
178
 
179
179
  If you want to extend Dataply's functionality, use the `DataplyAPI` class. Unlike the standard `Dataply` class, `DataplyAPI` provides direct access to internal components like `PageFileSystem` or `RowTableEngine`, offering much more flexibility for custom implementations.
180
180
 
181
+ For a detailed guide and examples on how to extend Dataply using Hooks, see [Extending Dataply Guide](docs/extension.md).
182
+
181
183
  ### Using DataplyAPI
182
184
 
183
185
  ```typescript
@@ -222,7 +224,7 @@ graph TD
222
224
  - **Fixed-size Pages**: All data is managed in fixed-size units (default 8KB) called pages.
223
225
  - **VFS Cache**: Minimizes disk I/O by caching frequently accessed pages in memory.
224
226
  - **Dirty Page Tracking**: Tracks modified pages (Dirty) to synchronize them with disk efficiently only at the time of commit.
225
- - **Detailed Structure**: For technical details on the physical layout, see [structure.md](structure.md).
227
+ - **Detailed Structure**: For technical details on the physical layout, see [structure.md](docs/structure.md).
226
228
 
227
229
  #### Page & Row Layout
228
230
  Dataply uses a **Slotted Page** architecture to manage records efficiently:
@@ -1,6 +0,0 @@
1
- import { BPTreeAsync } from 'serializable-bptree';
2
- export declare class RowIndexBPTree<K, V, C> extends BPTreeAsync<K, V> {
3
- private _bindContext?;
4
- bindContext(context?: C): void;
5
- getContext(): C | undefined;
6
- }