Skip to content

Commit

Permalink
chore: remove operations from storage engine interface
Browse files Browse the repository at this point in the history
  • Loading branch information
litcodeur committed Feb 21, 2024
1 parent db951ee commit 3ee9cbc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 96 deletions.
85 changes: 0 additions & 85 deletions src/IDBStorageEngine/IDBStorageEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@ import {
Collection,
IndexOptions,
} from "../Collection";
import { Condition } from "../Condition";
import { EnhancedStorageEngineTransaction } from "../EnhancedStorageEngineTransaction";
import { AnyDatabaseSchema } from "../types/Database";
import {
InsertOptionWithKey,
InsertOptionWithoutKey,
StorageEngine,
StorageEngineCDCEvent,
StorageEngineCDCEventSubscriber,
StorageEngineQueryResult,
StorageEngineStoredValue,
StorageEngineValidKey,
} from "../types/StorageEngine";
import { StorableJSONObject } from "../types/types";
import { resolver } from "../utils";
import { IDBStorageEngineTransaction } from "./IDBStorageEngineTransaction";

Expand Down Expand Up @@ -233,84 +226,6 @@ export class IDBStorageEngine<
get schema(): TSchema {
return this.#schema;
}

async queryByKey<TValue extends StorableJSONObject = StorableJSONObject>(
collectionName: string,
key: StorageEngineValidKey
): Promise<StorageEngineQueryResult<TValue>> {
await this.initialize();
const tx = this.startTransaction();
return await tx.queryByKey<TValue>(collectionName, key);
}

async queryByCondition<
TValue extends StorableJSONObject = StorableJSONObject
>(
collectionName: string,
condition: Condition
): Promise<StorageEngineQueryResult<TValue>> {
await this.initialize();
const tx = this.startTransaction();
return await tx.queryByCondition<TValue>(collectionName, condition);
}

async queryAll<TValue extends StorableJSONObject = StorableJSONObject>(
collectionName: string
): Promise<StorageEngineQueryResult<TValue>> {
await this.initialize();
const tx = this.startTransaction();
return await tx.queryAll<TValue>(collectionName);
}

async insert<TValue extends StorableJSONObject = StorableJSONObject>(
option: InsertOptionWithKey<TValue> | InsertOptionWithoutKey<TValue>
): Promise<StorageEngineStoredValue<TValue>> {
await this.initialize();
const tx = this.startTransaction();
return await tx.insert<TValue>(option);
}

async update<TValue extends StorableJSONObject = StorableJSONObject>(option: {
collectionName: string;
key: StorageEngineValidKey;
value: Partial<TValue>;
emitCDCEvent?: boolean | undefined;
}): Promise<StorageEngineStoredValue<TValue> | null> {
await this.initialize();
const tx = this.startTransaction();
return await tx.update<TValue>(option);
}

async delete<TValue extends StorableJSONObject = StorableJSONObject>(option: {
collectionName: string;
key: StorageEngineValidKey;
emitCDCEvent?: boolean | undefined;
}): Promise<StorageEngineStoredValue<TValue> | null> {
await this.initialize();
const tx = this.startTransaction();
return await tx.delete<TValue>(option);
}

async upsert<TValue extends StorableJSONObject = StorableJSONObject>(option: {
collectionName: string;
key: StorageEngineValidKey;
value: TValue;
emitCDCEvent?: boolean | undefined;
}): Promise<StorageEngineStoredValue<TValue>> {
await this.initialize();
const tx = this.startTransaction();
return await tx.upsert<TValue>(option);
}

async clear(option: {
collectionName: string;
emitCDCEvent?: boolean | undefined;
}): Promise<void> {
await this.initialize();
const tx = this.startTransaction();
return await tx.clear(option);
}

get name() {
return this.#name;
}
Expand Down
12 changes: 1 addition & 11 deletions src/types/StorageEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,7 @@ export type StorageEngineCDCEventSubscriber = (

export interface StorageEngine<
TSchema extends AnyDatabaseSchema = AnyDatabaseSchema
> extends Pick<
StorageEngineTransaction,
| "queryAll"
| "queryByCondition"
| "queryByKey"
| "insert"
| "update"
| "upsert"
| "delete"
| "clear"
> {
> {
initialize(): Promise<void>;

get schema(): TSchema;
Expand Down

0 comments on commit 3ee9cbc

Please sign in to comment.