mvcc-api 1.0.2 → 1.0.3

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.
@@ -2,13 +2,13 @@ import type { AsyncMVCCStrategy } from './Strategy';
2
2
  import { Ryoiki } from 'ryoiki';
3
3
  import { MVCCManager } from '../base';
4
4
  import { AsyncMVCCTransaction } from './Transaction';
5
- export declare class AsyncMVCCManager<T, S extends AsyncMVCCStrategy<T>> extends MVCCManager<T, S> {
5
+ export declare class AsyncMVCCManager<S extends AsyncMVCCStrategy<K, T>, K, T> extends MVCCManager<S, K, T> {
6
6
  readonly lock: Ryoiki;
7
7
  constructor(strategy: S);
8
- createTransaction(): AsyncMVCCTransaction<T, S, this>;
8
+ createTransaction(): AsyncMVCCTransaction<S, K, T, this>;
9
9
  writeLock<R>(fn: () => Promise<R>): Promise<R>;
10
- _diskWrite(key: string, value: T, version: number): Promise<void>;
11
- _diskRead(key: string, snapshotVersion: number): Promise<T | null>;
12
- _diskDelete(key: string, snapshotVersion: number): Promise<void>;
13
- _commit(tx: AsyncMVCCTransaction<T, S, this>): Promise<void>;
10
+ _diskWrite(key: K, value: T, version: number): Promise<void>;
11
+ _diskRead(key: K, snapshotVersion: number): Promise<T | null>;
12
+ _diskDelete(key: K, snapshotVersion: number): Promise<void>;
13
+ _commit(tx: AsyncMVCCTransaction<S, K, T, this>): Promise<void>;
14
14
  }
@@ -1,7 +1,7 @@
1
1
  import { MVCCStrategy } from '../base';
2
- export declare abstract class AsyncMVCCStrategy<T> extends MVCCStrategy<T> {
3
- abstract read(key: string): Promise<T>;
4
- abstract write(key: string, value: T): Promise<void>;
5
- abstract delete(key: string): Promise<void>;
6
- abstract exists(key: string): Promise<boolean>;
2
+ export declare abstract class AsyncMVCCStrategy<K, T> extends MVCCStrategy<K, T> {
3
+ abstract read(key: K): Promise<T>;
4
+ abstract write(key: K, value: T): Promise<void>;
5
+ abstract delete(key: K): Promise<void>;
6
+ abstract exists(key: K): Promise<boolean>;
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import type { AsyncMVCCStrategy } from './Strategy';
2
2
  import type { AsyncMVCCManager } from './Manager';
3
3
  import { MVCCTransaction } from '../base';
4
- export declare class AsyncMVCCTransaction<T, S extends AsyncMVCCStrategy<T>, M extends AsyncMVCCManager<T, S>> extends MVCCTransaction<T, S, M> {
5
- read(key: string): Promise<T | null>;
4
+ export declare class AsyncMVCCTransaction<S extends AsyncMVCCStrategy<K, T>, K, T, M extends AsyncMVCCManager<S, K, T>> extends MVCCTransaction<S, K, T, M> {
5
+ read(key: K): Promise<T | null>;
6
6
  commit(): Promise<this>;
7
7
  }
@@ -5,24 +5,25 @@ import type { MVCCTransaction } from './Transaction';
5
5
  * MVCC Manager abstract class.
6
6
  * Orchestrates transactions, manages the version index, and handles garbage collection.
7
7
  * It is responsible for maintaining the consistency of the data and version history.
8
- * @template T The type of data stored.
9
8
  * @template S The strategy type used for persistence.
9
+ * @template K The type of key used for data storage (e.g., string).
10
+ * @template T The type of data stored (e.g., string, Buffer, object).
10
11
  */
11
- export declare abstract class MVCCManager<T, S extends MVCCStrategy<T>> {
12
+ export declare abstract class MVCCManager<S extends MVCCStrategy<K, T>, K, T> {
12
13
  version: number;
13
14
  readonly strategy: S;
14
- protected readonly versionIndex: Map<string, {
15
+ protected readonly versionIndex: Map<K, {
15
16
  version: number;
16
17
  exists: boolean;
17
18
  }[]>;
18
- protected readonly activeTransactions: Set<MVCCTransaction<T, S, this>>;
19
- protected readonly deletedCache: Map<string, DeleteEntry<T>[]>;
19
+ protected readonly activeTransactions: Set<MVCCTransaction<S, K, T, this>>;
20
+ protected readonly deletedCache: Map<K, DeleteEntry<T>[]>;
20
21
  constructor(strategy: S);
21
22
  /**
22
23
  * Creates a new transaction with the current version.
23
24
  * @returns A new accessible transaction instance.
24
25
  */
25
- abstract createTransaction(): MVCCTransaction<T, S, this>;
26
+ abstract createTransaction(): MVCCTransaction<S, K, T, this>;
26
27
  /**
27
28
  * Writes data to the persistent storage and indexes the new version.
28
29
  * @internal This method is for internal use only and should not be called directly.
@@ -30,7 +31,7 @@ export declare abstract class MVCCManager<T, S extends MVCCStrategy<T>> {
30
31
  * @param value The value to write.
31
32
  * @param version The version number for this write.
32
33
  */
33
- abstract _diskWrite(key: string, value: T, version: number): Deferred<void>;
34
+ abstract _diskWrite(key: K, value: T, version: number): Deferred<void>;
34
35
  /**
35
36
  * Reads data from the persistent storage for a specific snapshot version.
36
37
  * @internal This method is for internal use only and should not be called directly.
@@ -38,21 +39,21 @@ export declare abstract class MVCCManager<T, S extends MVCCStrategy<T>> {
38
39
  * @param shapshotVersion The transaction's snapshot version.
39
40
  * @returns The data visible to the snapshot version, or null.
40
41
  */
41
- abstract _diskRead(key: string, shapshotVersion: number): Deferred<T | null>;
42
+ abstract _diskRead(key: K, shapshotVersion: number): Deferred<T | null>;
42
43
  /**
43
44
  * Deletes data from the persistent storage (records a deletion version).
44
45
  * @internal This method is for internal use only and should not be called directly.
45
46
  * @param key The key to delete.
46
47
  * @param snapshotVersion The version at which the deletion occurs.
47
48
  */
48
- abstract _diskDelete(key: string, snapshotVersion: number): Deferred<void>;
49
+ abstract _diskDelete(key: K, snapshotVersion: number): Deferred<void>;
49
50
  /**
50
51
  * Commits a transaction.
51
52
  * Validates conflicts and applies the transaction's changes.
52
53
  * @internal This method is for internal use only and should not be called directly.
53
54
  * @param tx The transaction to commit.
54
55
  */
55
- abstract _commit(tx: MVCCTransaction<T, S, this>): Deferred<void>;
56
- _removeTransaction(tx: MVCCTransaction<T, S, this>): void;
56
+ abstract _commit(tx: MVCCTransaction<S, K, T, this>): Deferred<void>;
57
+ _removeTransaction(tx: MVCCTransaction<S, K, T, this>): void;
57
58
  protected _cleanupDeletedCache(): void;
58
59
  }
@@ -3,30 +3,31 @@ import type { Deferred } from '../../types';
3
3
  * MVCC Strategy abstract class.
4
4
  * Defines the interface for data storage strategies (e.g., File System, In-Memory).
5
5
  * To implement a new storage backend, extend this class and implement the abstract methods.
6
+ * @template K The type of key used for data storage (e.g., string).
6
7
  * @template T The type of data stored (e.g., string, Buffer, object).
7
8
  */
8
- export declare abstract class MVCCStrategy<T> {
9
+ export declare abstract class MVCCStrategy<K, T> {
9
10
  /**
10
11
  * Reads a value from the storage.
11
12
  * @param key The key to read.
12
13
  * @returns The value corresponding to the key.
13
14
  */
14
- abstract read(key: string): Deferred<T>;
15
+ abstract read(key: K): Deferred<T>;
15
16
  /**
16
17
  * Writes a value to the storage.
17
18
  * @param key The key to write.
18
19
  * @param value The value to write.
19
20
  */
20
- abstract write(key: string, value: T): Deferred<void>;
21
+ abstract write(key: K, value: T): Deferred<void>;
21
22
  /**
22
23
  * Deletes a value from the storage.
23
24
  * @param key The key to delete.
24
25
  */
25
- abstract delete(key: string): Deferred<void>;
26
+ abstract delete(key: K): Deferred<void>;
26
27
  /**
27
28
  * Checks if a key exists in the storage.
28
29
  * @param key The key to check.
29
30
  * @returns True if the key exists, false otherwise.
30
31
  */
31
- abstract exists(key: string): Deferred<boolean>;
32
+ abstract exists(key: K): Deferred<boolean>;
32
33
  }
@@ -5,16 +5,17 @@ import type { MVCCStrategy } from './Strategy';
5
5
  * MVCC Transaction abstract class.
6
6
  * Represents a logical unit of work that isolates changes until commit.
7
7
  * It manages its own write/delete buffers and enforces Snapshot Isolation.
8
- * @template T The type of data stored.
9
8
  * @template S The strategy type used by the manager.
9
+ * @template K The type of key used for data storage (e.g., string).
10
+ * @template T The type of data stored (e.g., string, Buffer, object).
10
11
  * @template M The manager type that created this transaction.
11
12
  */
12
- export declare abstract class MVCCTransaction<T, S extends MVCCStrategy<T>, M extends MVCCManager<T, S>> {
13
+ export declare abstract class MVCCTransaction<S extends MVCCStrategy<K, T>, K, T, M extends MVCCManager<S, K, T>> {
13
14
  protected readonly manager: M;
14
15
  protected committed: boolean;
15
16
  readonly snapshotVersion: number;
16
- readonly writeBuffer: Map<string, T>;
17
- readonly deleteBuffer: Set<string>;
17
+ readonly writeBuffer: Map<K, T>;
18
+ readonly deleteBuffer: Set<K>;
18
19
  constructor(manager: M, snapshotVersion: number);
19
20
  /**
20
21
  * Schedules a creation (insert) of a key-value pair.
@@ -23,7 +24,7 @@ export declare abstract class MVCCTransaction<T, S extends MVCCStrategy<T>, M ex
23
24
  * @param value The value to store.
24
25
  * @returns The transaction instance for chaining.
25
26
  */
26
- create(key: string, value: T): this;
27
+ create(key: K, value: T): this;
27
28
  /**
28
29
  * Schedules a write (update) of a key-value pair.
29
30
  * Overwrites any existing value in the buffer.
@@ -31,13 +32,13 @@ export declare abstract class MVCCTransaction<T, S extends MVCCStrategy<T>, M ex
31
32
  * @param value The value to store.
32
33
  * @returns The transaction instance for chaining.
33
34
  */
34
- write(key: string, value: T): this;
35
+ write(key: K, value: T): this;
35
36
  /**
36
37
  * Schedules a deletion of a key.
37
38
  * @param key The key to delete.
38
39
  * @returns The transaction instance for chaining.
39
40
  */
40
- delete(key: string): this;
41
+ delete(key: K): this;
41
42
  /**
42
43
  * Rolls back the transaction.
43
44
  * Clears all buffers and marks the transaction as finished.
@@ -49,7 +50,7 @@ export declare abstract class MVCCTransaction<T, S extends MVCCStrategy<T>, M ex
49
50
  * @param key The key to read.
50
51
  * @returns The value, or null if not found.
51
52
  */
52
- abstract read(key: string): Deferred<T | null>;
53
+ abstract read(key: K): Deferred<T | null>;
53
54
  /**
54
55
  * Commits the transaction.
55
56
  * Applies buffered changes to the permanent storage via the manager.
@@ -1,11 +1,11 @@
1
1
  import type { SyncMVCCStrategy } from './Strategy';
2
2
  import { MVCCManager } from '../base';
3
3
  import { SyncMVCCTransaction } from './Transaction';
4
- export declare class SyncMVCCManager<T, S extends SyncMVCCStrategy<T>> extends MVCCManager<T, S> {
4
+ export declare class SyncMVCCManager<S extends SyncMVCCStrategy<K, T>, K, T> extends MVCCManager<S, K, T> {
5
5
  constructor(strategy: S);
6
- createTransaction(): SyncMVCCTransaction<T, S, this>;
7
- _diskWrite(key: string, value: T, version: number): void;
8
- _diskRead(key: string, snapshotVersion: number): T | null;
9
- _diskDelete(key: string, snapshotVersion: number): void;
10
- _commit(tx: SyncMVCCTransaction<T, S, this>): void;
6
+ createTransaction(): SyncMVCCTransaction<S, K, T, this>;
7
+ _diskWrite(key: K, value: T, version: number): void;
8
+ _diskRead(key: K, snapshotVersion: number): T | null;
9
+ _diskDelete(key: K, snapshotVersion: number): void;
10
+ _commit(tx: SyncMVCCTransaction<S, K, T, this>): void;
11
11
  }
@@ -1,7 +1,7 @@
1
1
  import { MVCCStrategy } from '../base';
2
- export declare abstract class SyncMVCCStrategy<T> extends MVCCStrategy<T> {
3
- abstract read(key: string): T;
4
- abstract write(key: string, value: T): void;
5
- abstract delete(key: string): void;
6
- abstract exists(key: string): boolean;
2
+ export declare abstract class SyncMVCCStrategy<K, T> extends MVCCStrategy<K, T> {
3
+ abstract read(key: K): T;
4
+ abstract write(key: K, value: T): void;
5
+ abstract delete(key: K): void;
6
+ abstract exists(key: K): boolean;
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import type { SyncMVCCStrategy } from './Strategy';
2
2
  import type { SyncMVCCManager } from './Manager';
3
3
  import { MVCCTransaction } from '../base';
4
- export declare class SyncMVCCTransaction<T, S extends SyncMVCCStrategy<T>, M extends SyncMVCCManager<T, S>> extends MVCCTransaction<T, S, M> {
5
- read(key: string): T | null;
4
+ export declare class SyncMVCCTransaction<S extends SyncMVCCStrategy<K, T>, K, T, M extends SyncMVCCManager<S, K, T>> extends MVCCTransaction<S, K, T, M> {
5
+ read(key: K): T | null;
6
6
  commit(): this;
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mvcc-api",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Multiversion Concurrency Control (MVCC) API for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "izure <admin@izure.org>",