From e58d0fd905722352238e11ed4e308907485f8ff5 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Mon, 2 Sep 2024 14:07:52 +0330 Subject: [PATCH] refactor: Replace id_ with documentId and collectionId in AlwatrStore This refactor updates the parameter names in the AlwatrStore class from id_ to documentId and collectionId in the openDocument and openCollection methods. The new parameter names provide clearer and more descriptive identifiers for the document and collection IDs. This change aligns with the recent refactoring of method names in the repository and improves code readability. --- packages/engine/src/alwatr-store.ts | 74 ++++++++++++++--------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/packages/engine/src/alwatr-store.ts b/packages/engine/src/alwatr-store.ts index e83b1094..62c63dc8 100644 --- a/packages/engine/src/alwatr-store.ts +++ b/packages/engine/src/alwatr-store.ts @@ -231,7 +231,7 @@ export class AlwatrStore { * If the document not exists or its not a document, an error is thrown. * * @template TDoc document data type - * @param id_ document id + * @param documentId document id {@link StoreFileId} * @returns document reference {@link DocumentReference} * @example * ```typescript @@ -243,34 +243,34 @@ export class AlwatrStore { * userProfile.update({name: 'ali'}); * ``` */ - async openDocument(id: StoreFileId): Promise> { - const id_ = getStoreId(id); - logger.logMethodArgs?.('openDocument', id_); + async openDocument(documentId: StoreFileId): Promise> { + const id = getStoreId(documentId); + logger.logMethodArgs?.('openDocument', id); - if (Object.hasOwn(this.cacheReferences__, id_)) { - const ref = this.cacheReferences__[id_]; + if (Object.hasOwn(this.cacheReferences__, id)) { + const ref = this.cacheReferences__[id]; if (!(ref instanceof DocumentReference)) { - logger.accident('openDocument', 'document_wrong_type', id_); - throw new Error('document_wrong_type', {cause: id_}); + logger.accident('openDocument', 'document_wrong_type', id); + throw new Error('document_wrong_type', {cause: id}); } - return this.cacheReferences__[id_] as unknown as DocumentReference; + return this.cacheReferences__[id] as unknown as DocumentReference; } - if (!this.rootDb__.itemExists(id_)) { - logger.accident('openDocument', 'document_not_found', id_); - throw new Error('document_not_found', {cause: id_}); + if (!this.rootDb__.itemExists(id)) { + logger.accident('openDocument', 'document_not_found', id); + throw new Error('document_not_found', {cause: id}); } - const storeStat = this.rootDb__.getItemData(id_); + const storeStat = this.rootDb__.getItemData(id); if (storeStat.type != StoreFileType.Document) { - logger.accident('openDocument', 'document_wrong_type', id_); - throw new Error('document_wrong_type', {cause: id_}); + logger.accident('openDocument', 'document_wrong_type', id); + throw new Error('document_wrong_type', {cause: id}); } const context = await this.readContext__>(storeStat); const docRef = DocumentReference.newRefFromContext(context, this.storeChanged_.bind(this)); - this.cacheReferences__[id_] = docRef as unknown as DocumentReference; + this.cacheReferences__[id] = docRef as unknown as DocumentReference; return docRef; } @@ -279,7 +279,7 @@ export class AlwatrStore { * If the collection not exists or its not a collection, an error is thrown. * * @template TItem collection item data type - * @param id_ collection id + * @param collectionId collection id {@link StoreFileId} * @returns collection reference {@link CollectionReference} * @example * ```typescript @@ -291,43 +291,43 @@ export class AlwatrStore { * orders.append({name: 'order 1'}); * ``` */ - async openCollection(id: StoreFileId): Promise> { - const id_ = getStoreId(id); - logger.logMethodArgs?.('openCollection', id_); + async openCollection(collectionId: StoreFileId): Promise> { + const id = getStoreId(collectionId); + logger.logMethodArgs?.('openCollection', id); // try to get from cache - if (Object.hasOwn(this.cacheReferences__, id_)) { - const ref = this.cacheReferences__[id_]; + if (Object.hasOwn(this.cacheReferences__, id)) { + const ref = this.cacheReferences__[id]; if (!(ref instanceof CollectionReference)) { - logger.accident('openCollection', 'collection_wrong_type', id_); - throw new Error('collection_wrong_type', {cause: id_}); + logger.accident('openCollection', 'collection_wrong_type', id); + throw new Error('collection_wrong_type', {cause: id}); } - return this.cacheReferences__[id_] as unknown as CollectionReference; + return this.cacheReferences__[id] as unknown as CollectionReference; } // load and create new collection reference - if (!this.rootDb__.itemExists(id_)) { - logger.accident('openCollection', 'collection_not_found', id_); - throw new Error('collection_not_found', {cause: id_}); + if (!this.rootDb__.itemExists(id)) { + logger.accident('openCollection', 'collection_not_found', id); + throw new Error('collection_not_found', {cause: id}); } - const storeStat = this.rootDb__.getItemData(id_); + const storeStat = this.rootDb__.getItemData(id); if (storeStat.type != StoreFileType.Collection) { - logger.accident('openCollection', 'collection_wrong_type', id_); - throw new Error('collection_not_found', {cause: id_}); + logger.accident('openCollection', 'collection_wrong_type', id); + throw new Error('collection_not_found', {cause: id}); } const context = await this.readContext__>(storeStat); const colRef = CollectionReference.newRefFromContext(context, this.storeChanged_.bind(this)); - this.cacheReferences__[id_] = colRef as unknown as CollectionReference; + this.cacheReferences__[id] = colRef as unknown as CollectionReference; return colRef; } /** * Unloads the store file with the given id from memory. * - * @param id_ The unique identifier of the store file. + * @param storeId The unique identifier of the store file. {@link StoreFileId} * @example * ```typescript * alwatrStore.unloadStore({name: 'user-list', region: Region.Secret}); @@ -352,7 +352,7 @@ export class AlwatrStore { * If the file is not unloaded, it will be unloaded first. * You don't need to await this method to complete unless you want to make sure the file is deleted on disk. * - * @param storeId The ID of the file to delete. + * @param storeId The ID of the file to delete. {@link StoreFileId} * @returns A Promise that resolves when the file is deleted. * @example * ```typescript @@ -388,6 +388,7 @@ export class AlwatrStore { /** * Saves all changes in the store. + * * @returns A Promise that resolves when all changes are saved. * @example * ```typescript @@ -437,9 +438,8 @@ export class AlwatrStore { /** * Write store file context. * - * @param id The unique identifier of the store file. - * @param context The store file context. If not provided, it will be loaded from memory. - * @param sync If true, the file will be written synchronously. + * @param from store file reference + * @returns A promise that resolves when the write operation is complete. */ protected async storeChanged_(from: DocumentReference | CollectionReference): Promise { logger.logMethodArgs?.('storeChanged__', from.id);