-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change the file contruction
- Loading branch information
1 parent
6f29933
commit c035d41
Showing
8 changed files
with
143 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { BaseRecord } from "../../storage/storage.types"; | ||
import { IpexMessages } from "../agent.types"; | ||
|
||
interface IpexMessageProps { | ||
id: string; | ||
content: IpexMessages; | ||
connectionId: string; | ||
} | ||
|
||
class IpexMessageRecord extends BaseRecord { | ||
content!: IpexMessages; | ||
connectionId!: string; | ||
|
||
static readonly type = "IpexMessagMetadataRecord"; | ||
readonly type = IpexMessageRecord.type; | ||
|
||
constructor(props: { | ||
id: string; | ||
content: IpexMessages; | ||
connectionId: string; | ||
}) { | ||
super(); | ||
|
||
if (props) { | ||
this.id = props.id; | ||
this.content = props.content; | ||
this.connectionId = props.connectionId; | ||
} | ||
} | ||
|
||
getTags() { | ||
return { | ||
...this._tags, | ||
connectionId: this.connectionId, | ||
id: this.id, | ||
}; | ||
} | ||
} | ||
|
||
export { IpexMessageRecord }; | ||
export type { IpexMessageProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { StorageService } from "../../storage/storage.types"; | ||
import { IpexMessageProps, IpexMessageRecord } from "./ipexMessageRecord"; | ||
|
||
class IpexMessageStorage { | ||
static readonly IPEX_MESSAGE_METADATA_RECORD_MISSING = | ||
"Ipex message metadata record does not exist"; | ||
private storageService: StorageService<IpexMessageRecord>; | ||
|
||
constructor(storageService: StorageService<IpexMessageRecord>) { | ||
this.storageService = storageService; | ||
} | ||
|
||
async getIpexMessageMetadata(id: string): Promise<IpexMessageRecord> { | ||
const metadata = await this.storageService.findById(id, IpexMessageRecord); | ||
if (!metadata) { | ||
throw new Error(IpexMessageStorage.IPEX_MESSAGE_METADATA_RECORD_MISSING); | ||
} | ||
return metadata; | ||
} | ||
|
||
async createIpexMessageRecord(data: IpexMessageProps): Promise<void> { | ||
const record = new IpexMessageRecord(data); | ||
await this.storageService.save(record); | ||
} | ||
|
||
async getIpexMessageMetadataByConnectionId( | ||
connectionId: string | ||
): Promise<IpexMessageRecord[]> { | ||
const records = await this.storageService.findAllByQuery( | ||
{ | ||
connectionId, | ||
}, | ||
IpexMessageRecord | ||
); | ||
return records; | ||
} | ||
} | ||
|
||
export { IpexMessageStorage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters