Skip to content

Commit

Permalink
fix(storage-engine): work with new types
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Dec 17, 2022
1 parent ef7ca74 commit e86c9cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
12 changes: 6 additions & 6 deletions core/storage-engine/src/storage-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import exitHook from 'exit-hook';

import {readJsonFile, writeJsonFile} from './util.js';

import type {DataStorage, AlwatrStorageEngineConfig, AlwatrDocumentObject} from './type.js';
import type {AlwatrDocumentStorage, AlwatrStorageEngineConfig, AlwatrDocumentObject} from './type.js';
import type {AlwatrLogger} from '@alwatr/logger';

export {DataStorage, AlwatrStorageEngineConfig, AlwatrDocumentObject};
export {AlwatrDocumentStorage as DataStorage, AlwatrStorageEngineConfig, AlwatrDocumentObject};

alwatrRegisteredList.push({
name: '@alwatr/storage-engine',
Expand Down Expand Up @@ -97,7 +97,7 @@ export class AlwatrStorageEngine<DocumentType extends AlwatrDocumentObject = Alw
*/
hasUnsavedChanges = false;

_storage: DataStorage<DocumentType>;
_storage: AlwatrDocumentStorage<DocumentType>;

protected _logger: AlwatrLogger;
protected _keys: Array<string> | null = null;
Expand Down Expand Up @@ -130,7 +130,7 @@ export class AlwatrStorageEngine<DocumentType extends AlwatrDocumentObject = Alw
return this._storage.meta.lastAutoId.toString();
}

protected get _newStorage(): DataStorage<DocumentType> {
protected get _newStorage(): AlwatrDocumentStorage<DocumentType> {
return {
ok: true,
meta: {
Expand Down Expand Up @@ -160,10 +160,10 @@ export class AlwatrStorageEngine<DocumentType extends AlwatrDocumentObject = Alw
/**
* load storage file.
*/
protected load(): DataStorage<DocumentType> {
protected load(): AlwatrDocumentStorage<DocumentType> {
this._logger.logMethodArgs('load', {name: this.name, path: this.storagePath});

const storage = readJsonFile<DataStorage<DocumentType>>(this.storagePath);
const storage = readJsonFile<AlwatrDocumentStorage<DocumentType>>(this.storagePath);

if (storage === null) {
this._logger.incident('load', 'file_not_found', 'Storage path not found, empty storage loaded', {
Expand Down
14 changes: 2 additions & 12 deletions core/storage-engine/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import type {AlwatrDocumentObject, AlwatrServiceResponseSuccessWithMeta} from '@alwatr/fetch/type.js';
import type {AlwatrDocumentObject, AlwatrDocumentMeta, AlwatrDocumentStorage} from '@alwatr/fetch/type.js';

export {AlwatrDocumentObject};
export {AlwatrDocumentObject, AlwatrDocumentMeta, AlwatrDocumentStorage};

export type StorageMeta = {
formatVersion: number;
reversion: number;
lastUpdated: number;
lastAutoId: number;
};

export type DataStorage<T extends AlwatrDocumentObject> = Readonly<
Omit<AlwatrServiceResponseSuccessWithMeta<Record<string, T | undefined>, StorageMeta>, 'statusCode' | 'errorCode'>
>;

export type AlwatrStorageEngineConfig = {
/**
Expand Down

0 comments on commit e86c9cd

Please sign in to comment.