Skip to content

Commit

Permalink
broken
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocmaster committed May 6, 2024
1 parent 11ebafd commit 09df6b0
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 4 deletions.
1 change: 1 addition & 0 deletions documentation/user-preference.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# User preference encodings

### One-for-all

16 changes: 16 additions & 0 deletions src/interfaces/data/ICursor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// import {
// PersistenceError,
// VersionedObject,
// VolatileStorageMetadata,
// } from "@snickerdoodlelabs/objects";
import { DataObject, PersistenceError } from "crunchDB/objects";
import { ResultAsync } from "neverthrow";

export interface IVolatileCursor<T extends DataObject> {
nextValue(): ResultAsync<T | null, PersistenceError>;
allValues(): ResultAsync<T[] | null, PersistenceError>;

_next(): ResultAsync<VolatileStorageMetadata<T> | null, PersistenceError>;
_all(): ResultAsync<VolatileStorageMetadata<T>[], PersistenceError>;
}

52 changes: 52 additions & 0 deletions src/interfaces/data/IPersistence.ts
Original file line number Diff line number Diff line change
@@ -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<T extends DataObject>(
recordKey: ECollectionName,
key: CollectionKeys,
): ResultAsync<T | null, PersistenceError>;
getCursor<T extends DataObject>(
recordKey: ECollectionName,
indexName?: string,
query?: IDBValidKey | IDBKeyRange,
direction?: IDBCursorDirection | undefined,
mode?: IDBTransactionMode,
): ResultAsync<IVolatileCursor<T>, PersistenceError>;
getAll<T extends DataObject>(
recordKey: ECollectionName,
indexName?: string,
): ResultAsync<T[], PersistenceError>;
getAllByIndex<T extends DataObject>(
recordKey: ECollectionName,
indexName: string,
query: IDBValidKey | IDBKeyRange,
): ResultAsync<T[], PersistenceError>;
getAllByMultiIndex<T extends DataObject>(
recordKey: ECollectionName,
indices: string[],
values: IDBValidKey | IDBKeyRange,
): ResultAsync<T[], PersistenceError>;
getAllKeys<T extends DataObject>(
recordKey: ECollectionName,
indexName?: string,
query?: IDBValidKey | IDBKeyRange,
count?: number | undefined,
): ResultAsync<T[], PersistenceError>;
updateRecord<T extends DataObject>(
recordKey: ECollectionName,
value: T,
): ResultAsync<void, PersistenceError>;
deleteRecord(
recordKey: ECollectionName,
key: CollectionKeys,
): ResultAsync<void, PersistenceError>;
// #endregion

}

export const IPersistenceType = Symbol.for("IPersistence");

Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 2 additions & 1 deletion src/objects/business/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './nlp';
export * from './ranking';
export * from './vectorDB';
export * from './vectorDB';
export * from './DataObject';
4 changes: 4 additions & 0 deletions src/objects/enum/ECollectionName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum ECollectionName {
Vector = "Vector",
VectorMeta = "VectorMeta",
}
1 change: 1 addition & 0 deletions src/objects/enum/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./ELanguageCode";
export * from "./ECollectionName";
12 changes: 12 additions & 0 deletions src/objects/error/PersistenceError.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/objects/error/errorCodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ const errorCodes: {[Key: string]: string} = {
NLPError: "ERR_NLPError",
DuplicateWordError: "ERR_DuplicateWordError",
EigenJSNotReadyError: "ERR_EigenJSNotReadyError",
PersistenceError: "ERR_PersistenceError",
}
export default errorCodes;
1 change: 1 addition & 0 deletions src/objects/error/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './NLPError';
export * from './MatrixErrors';
export * from './MatrixOperatorsError';
export * from './EigenJSNotReadyError';
export * from './PersistenceError';
2 changes: 2 additions & 0 deletions src/objects/primitive/CollectionKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type CollectionKey = string | number;
export type CollectionKeys = CollectionKey[];

0 comments on commit 09df6b0

Please sign in to comment.