-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(webhooks): add postgres persistence to clients and requests (feature branch) #108
Changes from 1 commit
a06f222
7f636dc
d7b02f6
180a47e
969a6a9
22ddb90
b9cdea8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: david <david@umaproject.org>
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
import { DataSource } from "typeorm"; | ||
import { WebhookRequest } from "../types"; | ||
import { entities } from "@repo/indexer-database"; | ||
import { entities, DataSource } from "@repo/indexer-database"; | ||
|
||
export class WebhookRequestRepository { | ||
private repository; | ||
|
@@ -9,7 +7,7 @@ export class WebhookRequestRepository { | |
this.repository = this.dataSource.getRepository(entities.WebhookRequest); | ||
} | ||
|
||
public async register(webhook: WebhookRequest): Promise<void> { | ||
public async register(webhook: entities.WebhookRequest): Promise<void> { | ||
const existingWebhook = await this.repository.findOne({ | ||
where: { id: webhook.id }, | ||
}); | ||
|
@@ -31,17 +29,19 @@ export class WebhookRequestRepository { | |
|
||
public async getWebhook( | ||
webhookId: string, | ||
): Promise<WebhookRequest | undefined> { | ||
): Promise<entities.WebhookRequest | undefined> { | ||
return ( | ||
(await this.repository.findOne({ where: { id: webhookId } })) ?? undefined | ||
); | ||
} | ||
|
||
public async listWebhooks(): Promise<WebhookRequest[]> { | ||
public async listWebhooks(): Promise<entities.WebhookRequest[]> { | ||
return this.repository.find(); | ||
} | ||
|
||
public async filterWebhooks(filter: string): Promise<WebhookRequest[]> { | ||
public async filterWebhooks( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function name is a bit misleading because it suggests that you can filter webhooks by custom fields. It should sound more like |
||
filter: string, | ||
): Promise<entities.WebhookRequest[]> { | ||
return this.repository.find({ where: { filter } }); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ export class DepositStatusProcessor implements IEventProcessor { | |
private postgres: DataSource; | ||
// Type shoudl be uniqe across all event processors, this is to avoid colliding with multiple | ||
// processors writing to the same tables | ||
public type = "DepositStatus"; | ||
static type = "DepositStatus"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hardcoded strings should really be avoided. If this is common to all event processors, should we add the |
||
|
||
constructor(deps: Dependencies) { | ||
this.webhookRequests = new WebhookRequestRepository(deps.postgres); | ||
|
@@ -40,7 +40,7 @@ export class DepositStatusProcessor implements IEventProcessor { | |
} | ||
private async _write(event: DepositStatusEvent): Promise<void> { | ||
const filter = customId( | ||
this.type, | ||
DepositStatusProcessor.type, | ||
event.originChainId, | ||
event.depositTxHash, | ||
); | ||
|
@@ -65,13 +65,13 @@ export class DepositStatusProcessor implements IEventProcessor { | |
params: DepositStatusFilter, | ||
): Promise<string> { | ||
const id = customId( | ||
this.type, | ||
DepositStatusProcessor.type, | ||
url, | ||
params.originChainId, | ||
params.depositTxHash, | ||
); | ||
const filter = customId( | ||
this.type, | ||
DepositStatusProcessor.type, | ||
params.originChainId, | ||
params.depositTxHash, | ||
); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.