diff --git a/documentation/user-preference.md b/documentation/user-preference.md index f8d5952..db2c3be 100644 --- a/documentation/user-preference.md +++ b/documentation/user-preference.md @@ -1,3 +1,4 @@ # User preference encodings ### One-for-all + diff --git a/src/interfaces/data/ICursor.ts b/src/interfaces/data/ICursor.ts new file mode 100644 index 0000000..5a11c1c --- /dev/null +++ b/src/interfaces/data/ICursor.ts @@ -0,0 +1,16 @@ +// import { +// PersistenceError, +// VersionedObject, +// VolatileStorageMetadata, +// } from "@snickerdoodlelabs/objects"; + import { DataObject, PersistenceError } from "crunchDB/objects"; +import { ResultAsync } from "neverthrow"; + + export interface IVolatileCursor { + nextValue(): ResultAsync; + allValues(): ResultAsync; + + _next(): ResultAsync | null, PersistenceError>; + _all(): ResultAsync[], PersistenceError>; + } + \ No newline at end of file diff --git a/src/interfaces/data/IPersistence.ts b/src/interfaces/data/IPersistence.ts new file mode 100644 index 0000000..a71dc48 --- /dev/null +++ b/src/interfaces/data/IPersistence.ts @@ -0,0 +1,52 @@ + import { ResultAsync } from "neverthrow"; + import { ECollectionName, DataObject, PersistenceError } from "crunchDB/objects"; + + import { IVolatileCursor } from "@persistence/volatile/IVolatileCursor.js"; +import { CollectionKeys } from "crunchDB/objects/primitive/CollectionKey"; + + export interface IPersistence { + getObject( + recordKey: ECollectionName, + key: CollectionKeys, + ): ResultAsync; + getCursor( + recordKey: ECollectionName, + indexName?: string, + query?: IDBValidKey | IDBKeyRange, + direction?: IDBCursorDirection | undefined, + mode?: IDBTransactionMode, + ): ResultAsync, PersistenceError>; + getAll( + recordKey: ECollectionName, + indexName?: string, + ): ResultAsync; + getAllByIndex( + recordKey: ECollectionName, + indexName: string, + query: IDBValidKey | IDBKeyRange, + ): ResultAsync; + getAllByMultiIndex( + recordKey: ECollectionName, + indices: string[], + values: IDBValidKey | IDBKeyRange, + ): ResultAsync; + getAllKeys( + recordKey: ECollectionName, + indexName?: string, + query?: IDBValidKey | IDBKeyRange, + count?: number | undefined, + ): ResultAsync; + updateRecord( + recordKey: ECollectionName, + value: T, + ): ResultAsync; + deleteRecord( + recordKey: ECollectionName, + key: CollectionKeys, + ): ResultAsync; + // #endregion + + } + + export const IPersistenceType = Symbol.for("IPersistence"); + \ No newline at end of file diff --git a/src/objects/business/SimpleObject.ts b/src/objects/business/DataObject.ts similarity index 55% rename from src/objects/business/SimpleObject.ts rename to src/objects/business/DataObject.ts index c2b73e0..e137a2c 100644 --- a/src/objects/business/SimpleObject.ts +++ b/src/objects/business/DataObject.ts @@ -1,6 +1,4 @@ //@TODO add properties and rename the file to VolatileObject.ts -export interface SimpleObject { +export interface DataObject { id: number; - name: string; - value: string; } diff --git a/src/objects/business/index.ts b/src/objects/business/index.ts index 76bd9fc..77818d0 100644 --- a/src/objects/business/index.ts +++ b/src/objects/business/index.ts @@ -1,3 +1,4 @@ export * from './nlp'; export * from './ranking'; -export * from './vectorDB'; \ No newline at end of file +export * from './vectorDB'; +export * from './DataObject'; \ No newline at end of file diff --git a/src/objects/enum/ECollectionName.ts b/src/objects/enum/ECollectionName.ts new file mode 100644 index 0000000..559b55b --- /dev/null +++ b/src/objects/enum/ECollectionName.ts @@ -0,0 +1,4 @@ +export enum ECollectionName { + Vector = "Vector", + VectorMeta = "VectorMeta", +} \ No newline at end of file diff --git a/src/objects/enum/index.ts b/src/objects/enum/index.ts index 5e1fd90..698769b 100644 --- a/src/objects/enum/index.ts +++ b/src/objects/enum/index.ts @@ -1 +1,2 @@ export * from "./ELanguageCode"; +export * from "./ECollectionName"; diff --git a/src/objects/error/PersistenceError.ts b/src/objects/error/PersistenceError.ts new file mode 100644 index 0000000..e947932 --- /dev/null +++ b/src/objects/error/PersistenceError.ts @@ -0,0 +1,12 @@ +import { BaseError } from "./BaseError"; +import errorCodes from "./errorCodes"; + +export class PersistenceError extends BaseError { + protected errorCode: string = errorCodes[PersistenceError.name]; + constructor( + message: string, + public src?: unknown, + ) { + super(message, errorCodes[PersistenceError.name], src); + } +} \ No newline at end of file diff --git a/src/objects/error/errorCodes.ts b/src/objects/error/errorCodes.ts index 6fa2cc9..7ed7c0e 100644 --- a/src/objects/error/errorCodes.ts +++ b/src/objects/error/errorCodes.ts @@ -4,5 +4,6 @@ const errorCodes: {[Key: string]: string} = { NLPError: "ERR_NLPError", DuplicateWordError: "ERR_DuplicateWordError", EigenJSNotReadyError: "ERR_EigenJSNotReadyError", + PersistenceError: "ERR_PersistenceError", } export default errorCodes; \ No newline at end of file diff --git a/src/objects/error/index.ts b/src/objects/error/index.ts index 69a63f8..81f40c4 100644 --- a/src/objects/error/index.ts +++ b/src/objects/error/index.ts @@ -5,3 +5,4 @@ export * from './NLPError'; export * from './MatrixErrors'; export * from './MatrixOperatorsError'; export * from './EigenJSNotReadyError'; +export * from './PersistenceError'; diff --git a/src/objects/primitive/CollectionKey.ts b/src/objects/primitive/CollectionKey.ts new file mode 100644 index 0000000..a2b4aee --- /dev/null +++ b/src/objects/primitive/CollectionKey.ts @@ -0,0 +1,2 @@ +export type CollectionKey = string | number; +export type CollectionKeys = CollectionKey[]; \ No newline at end of file