-
Notifications
You must be signed in to change notification settings - Fork 0
feat(data-pathways)!: id-keyed pump-state commands + sources metrics shape #217
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { Command } from "../../common/command.ts" | ||
| import { type DataPathwayPumpStateBySource, DataPathwayPumpStateBySourceSchema } from "../../contracts/data-pathways.ts" | ||
| import type { ClientError } from "../../exceptions/client-error.ts" | ||
| import { NotFoundException } from "../../exceptions/not-found.ts" | ||
| import { parseResponseHelper } from "../../utils/parse-response-helper.ts" | ||
|
|
||
| export interface DataPathwayPumpStateFetchBySourceInput { | ||
| pathwayId: string | ||
| sourceId: string | ||
| } | ||
|
|
||
| export class DataPathwayPumpStateFetchBySourceCommand | ||
| extends Command<DataPathwayPumpStateFetchBySourceInput, DataPathwayPumpStateBySource> { | ||
| protected override allowedModes: ("apiKey" | "bearer")[] = ["apiKey"] | ||
|
|
||
| protected override getMethod(): string { | ||
| return "GET" | ||
| } | ||
|
|
||
| protected override getBaseUrl(): string { | ||
| return "https://data-pathways.api.flowcore.io" | ||
| } | ||
|
|
||
| protected override getPath(): string { | ||
| return `/api/v1/pump-states/${this.input.pathwayId}/sources/${this.input.sourceId}` | ||
| } | ||
|
|
||
| protected override parseResponse(rawResponse: unknown): DataPathwayPumpStateBySource { | ||
| return parseResponseHelper(DataPathwayPumpStateBySourceSchema, rawResponse) | ||
| } | ||
|
|
||
| protected override handleClientError(error: ClientError): void { | ||
| if (error.status === 404) { | ||
| throw new NotFoundException("DataPathwayPumpState", { | ||
| pathwayId: this.input.pathwayId, | ||
| sourceId: this.input.sourceId, | ||
| }) | ||
| } | ||
| throw error | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||||||||||||||||
| import { Command } from "../../common/command.ts" | ||||||||||||||||||
| import { | ||||||||||||||||||
| type DataPathwayPumpStateSaveResponse, | ||||||||||||||||||
| DataPathwayPumpStateSaveResponseSchema, | ||||||||||||||||||
| } from "../../contracts/data-pathways.ts" | ||||||||||||||||||
| import { parseResponseHelper } from "../../utils/parse-response-helper.ts" | ||||||||||||||||||
|
|
||||||||||||||||||
| export interface DataPathwayPumpStateSaveBySourceInput { | ||||||||||||||||||
| pathwayId: string | ||||||||||||||||||
| sourceId: string | ||||||||||||||||||
| state: { | ||||||||||||||||||
| timeBucket: string | ||||||||||||||||||
| eventId?: string | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| export class DataPathwayPumpStateSaveBySourceCommand | ||||||||||||||||||
| extends Command<DataPathwayPumpStateSaveBySourceInput, DataPathwayPumpStateSaveResponse> { | ||||||||||||||||||
| protected override retryOnFailure: boolean = false | ||||||||||||||||||
| protected override allowedModes: ("apiKey" | "bearer")[] = ["apiKey"] | ||||||||||||||||||
|
|
||||||||||||||||||
| protected override getMethod(): string { | ||||||||||||||||||
| return "PUT" | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| protected override getBaseUrl(): string { | ||||||||||||||||||
| return "https://data-pathways.api.flowcore.io" | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| protected override getPath(): string { | ||||||||||||||||||
| return `/api/v1/pump-states/${this.input.pathwayId}/sources/${this.input.sourceId}` | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+30
to
+32
Contributor
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. Encode path parameters before building the source route.
🐛 Proposed fix protected override getPath(): string {
- return `/api/v1/pump-states/${this.input.pathwayId}/sources/${this.input.sourceId}`
+ const pathwayId = encodeURIComponent(this.input.pathwayId)
+ const sourceId = encodeURIComponent(this.input.sourceId)
+ return `/api/v1/pump-states/${pathwayId}/sources/${sourceId}`
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| protected override getBody(): Record<string, unknown> { | ||||||||||||||||||
| return { state: this.input.state } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| protected override parseResponse(rawResponse: unknown): DataPathwayPumpStateSaveResponse { | ||||||||||||||||||
| return parseResponseHelper(DataPathwayPumpStateSaveResponseSchema, rawResponse) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
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.
Encode path parameters before building the source route.
Raw
sourceIdinterpolation will misroute IDs containing path or query delimiters.🐛 Proposed fix
protected override getPath(): string { - return `/api/v1/pump-states/${this.input.pathwayId}/sources/${this.input.sourceId}` + const pathwayId = encodeURIComponent(this.input.pathwayId) + const sourceId = encodeURIComponent(this.input.sourceId) + return `/api/v1/pump-states/${pathwayId}/sources/${sourceId}` }🤖 Prompt for AI Agents