Skip to content
Snippets Groups Projects
Commit d0961420 authored by Sourabh Desai's avatar Sourabh Desai
Browse files

small bug/syntax fixes

parent 30dfa807
Branches
Tags
No related merge requests found
...@@ -5,7 +5,7 @@ import { SimpleDocumentStore } from "./docStore/SimpleDocumentStore"; ...@@ -5,7 +5,7 @@ import { SimpleDocumentStore } from "./docStore/SimpleDocumentStore";
import { SimpleIndexStore } from "./indexStore/SimpleIndexStore"; import { SimpleIndexStore } from "./indexStore/SimpleIndexStore";
import { SimpleVectorStore } from "./vectorStore/SimpleVectorStore"; import { SimpleVectorStore } from "./vectorStore/SimpleVectorStore";
import { GenericFileSystem } from "./FileSystem"; import { GenericFileSystem } from "./FileSystem";
import { DEFAULT_PERSIST_DIR, DEFAULT_FS } from "./constants"; import { DEFAULT_PERSIST_DIR, DEFAULT_FS, DEFAULT_NAMESPACE } from "./constants";
export interface StorageContext { export interface StorageContext {
docStore?: BaseDocumentStore; docStore?: BaseDocumentStore;
...@@ -21,16 +21,16 @@ type BuilderParams = { ...@@ -21,16 +21,16 @@ type BuilderParams = {
fs?: GenericFileSystem, fs?: GenericFileSystem,
}; };
export function storageContextFromDefaults({ export async function storageContextFromDefaults({
docStore, indexStore, vectorStore, persistDir, fs docStore, indexStore, vectorStore, persistDir, fs
}: BuilderParams): StorageContext { }: BuilderParams): StorageContext {
persistDir = persistDir || DEFAULT_PERSIST_DIR; persistDir = persistDir || DEFAULT_PERSIST_DIR;
fs = fs || DEFAULT_FS; fs = fs || DEFAULT_FS;
docStore = docStore || SimpleDocumentStore.fromPersistDir(persistDir, fs=fs); docStore = docStore || await SimpleDocumentStore.fromPersistDir(persistDir, DEFAULT_NAMESPACE, fs);
indexStore = indexStore || SimpleIndexStore.fromPersistDir(persistDir, fs=fs); indexStore = indexStore || await SimpleIndexStore.fromPersistDir(persistDir, fs);
vectorStore = vectorStore || SimpleVectorStore.fromPersistDir(persistDir, fs=fs); vectorStore = vectorStore || await SimpleVectorStore.fromPersistDir(persistDir, fs);
return { return {
docStore, docStore,
......
...@@ -3,7 +3,7 @@ import { BaseDocument } from '../../Document'; ...@@ -3,7 +3,7 @@ import { BaseDocument } from '../../Document';
import { BaseDocumentStore, RefDocInfo } from './types'; import { BaseDocumentStore, RefDocInfo } from './types';
import { BaseKVStore } from '../kvStore/types'; import { BaseKVStore } from '../kvStore/types';
import _, * as lodash from 'lodash'; import _, * as lodash from 'lodash';
import { docToJson, jsonToDoc } from './docstore-utils'; import { docToJson, jsonToDoc } from './utils';
import { DEFAULT_NAMESPACE } from '../constants'; import { DEFAULT_NAMESPACE } from '../constants';
type DocMetaData = { docHash: string, refDocId?: string }; type DocMetaData = { docHash: string, refDocId?: string };
...@@ -22,11 +22,11 @@ export class KVDocumentStore extends BaseDocumentStore { ...@@ -22,11 +22,11 @@ export class KVDocumentStore extends BaseDocumentStore {
this.metadataCollection = `${namespace}/metadata`; this.metadataCollection = `${namespace}/metadata`;
} }
get docs(): Record<string, BaseDocument> { async docs(): Promise<Record<string, BaseDocument>> {
let jsonDict = this.kvstore.getAll(this.nodeCollection); let jsonDict = await this.kvstore.getAll(this.nodeCollection);
let docs: Record<string, BaseDocument> = {}; let docs: Record<string, BaseDocument> = {};
for (let key in jsonDict) { for (let key in jsonDict) {
docs[key] = jsonToDoc(jsonDict[key]); docs[key] = jsonToDoc(jsonDict[key] as Record<string, any>);
} }
return docs; return docs;
} }
......
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
DEFAULT_FS DEFAULT_FS
} from '../constants'; } from '../constants';
type SaveDict = {[key: string]: any}; // Replace `any` with the appropriate type if possible. type SaveDict = {[key: string]: any};
export class SimpleDocumentStore extends KVDocumentStore { export class SimpleDocumentStore extends KVDocumentStore {
private kvStore: SimpleKVStore; private kvStore: SimpleKVStore;
...@@ -23,13 +23,13 @@ export class SimpleDocumentStore extends KVDocumentStore { ...@@ -23,13 +23,13 @@ export class SimpleDocumentStore extends KVDocumentStore {
this.kvStore = kvStore; this.kvStore = kvStore;
} }
static fromPersistDir( static async fromPersistDir(
persistDir: string = DEFAULT_PERSIST_DIR, persistDir: string = DEFAULT_PERSIST_DIR,
namespace?: string, namespace?: string,
fsModule?: GenericFileSystem fsModule?: GenericFileSystem
): SimpleDocumentStore { ): Promise<SimpleDocumentStore> {
const persistPath = path.join(persistDir, DEFAULT_DOC_STORE_PERSIST_FILENAME); const persistPath = path.join(persistDir, DEFAULT_DOC_STORE_PERSIST_FILENAME);
return SimpleDocumentStore.fromPersistPath(persistPath, namespace, fsModule); return await SimpleDocumentStore.fromPersistPath(persistPath, namespace, fsModule);
} }
static async fromPersistPath( static async fromPersistPath(
......
...@@ -18,7 +18,7 @@ export abstract class BaseDocumentStore { ...@@ -18,7 +18,7 @@ export abstract class BaseDocumentStore {
} }
// Main interface // Main interface
abstract get docs(): {[key: string]: BaseDocument}; abstract docs(): Promise<Record<string, BaseDocument>>;
abstract addDocuments(docs: BaseDocument[], allowUpdate: boolean): void; abstract addDocuments(docs: BaseDocument[], allowUpdate: boolean): void;
......
...@@ -3,14 +3,14 @@ import { BaseDocument, NodeType } from '../../Document'; ...@@ -3,14 +3,14 @@ import { BaseDocument, NodeType } from '../../Document';
import { DATA_KEY, TYPE_KEY } from '../constants'; import { DATA_KEY, TYPE_KEY } from '../constants';
function docToJson(doc: BaseDocument): Record<string, any> { export function docToJson(doc: BaseDocument): Record<string, any> {
return { return {
[DATA_KEY]: JSON.stringify(doc), [DATA_KEY]: JSON.stringify(doc),
[TYPE_KEY]: doc.getType(), [TYPE_KEY]: doc.getType(),
}; };
} }
function jsonToDoc(docDict: Record<string, any>): BaseDocument { export function jsonToDoc(docDict: Record<string, any>): BaseDocument {
let docType = docDict[TYPE_KEY]; let docType = docDict[TYPE_KEY];
let dataDict = docDict[DATA_KEY]; let dataDict = docDict[DATA_KEY];
let doc: BaseDocument; let doc: BaseDocument;
......
import { BaseKVStore } from '../kvStore/types'; import { BaseKVStore } from '../kvStore/types';
import { IndexStruct, indexStructToJson, jsonToIndexStruct } from '../../dataStructs'; import { IndexStruct, indexStructToJson, jsonToIndexStruct } from '../../dataStructs';
import _ from 'lodash'; import _ from 'lodash';
import { DEFAULT_NAMESPACE } from './constants'; import { DEFAULT_NAMESPACE } from '../constants';
import { BaseIndexStore } from './types'; import { BaseIndexStore } from './types';
export class KVIndexStore extends BaseIndexStore { export class KVIndexStore extends BaseIndexStore {
......
...@@ -18,6 +18,7 @@ class SimpleVectorStoreData { ...@@ -18,6 +18,7 @@ class SimpleVectorStoreData {
} }
export class SimpleVectorStore implements VectorStore { export class SimpleVectorStore implements VectorStore {
storesText: boolean = false;
private data: SimpleVectorStoreData = new SimpleVectorStoreData(); private data: SimpleVectorStoreData = new SimpleVectorStoreData();
private fs: GenericFileSystem = DEFAULT_FS; private fs: GenericFileSystem = DEFAULT_FS;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment