-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(refactor indices): Refactor main index and organize our transfor…
…m pattern (#337) * remove rai data from main index, remove obe railist component * is this more readable? not sure * remove transforms that don't do anything * move action trasnforms * bind the transforms to their index * rename, move, etc * and now the changelog index.... * break apart sink handlers for clarity * refactor onemac * add missing error logging * rename transforms * naming * fix tests * Fix error * Fix logic for legacy * Unscrew attachments * Rename schema and type * Fix some codeclimate issues * feat(refactor indices): refactor the refactor * feat(refactor indices): refactor the refactor * feat(refactor indices): refactor the refactor * fix broken callouts to getLatestRai * Remove obe code * Correct rai logic --------- Co-authored-by: Paul Kim <[email protected]>
- Loading branch information
1 parent
b984055
commit ab536a3
Showing
39 changed files
with
599 additions
and
1,033 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,14 @@ | ||
import { z } from "zod"; | ||
import { onemacAttachmentSchema, handleAttachment } from "../attachments"; | ||
import { attachmentSchema } from "../attachments"; | ||
|
||
export const raiIssueSchema = z.object({ | ||
id: z.string(), | ||
authority: z.string(), | ||
origin: z.string(), | ||
requestedDate: z.number(), | ||
attachments: z.array(onemacAttachmentSchema).nullish(), | ||
attachments: z.array(attachmentSchema).nullish(), | ||
additionalInformation: z.string().nullable().default(null), | ||
submitterName: z.string(), | ||
submitterEmail: z.string(), | ||
}); | ||
export type RaiIssue = z.infer<typeof raiIssueSchema>; | ||
|
||
export const transformRaiIssue = (id: string) => { | ||
return raiIssueSchema.transform((data) => ({ | ||
id, | ||
rais: { | ||
[data.requestedDate]: { | ||
request: { | ||
attachments: | ||
data.attachments?.map((attachment) => { | ||
return handleAttachment(attachment); | ||
}) ?? null, | ||
additionalInformation: data.additionalInformation, | ||
submitterName: data.submitterName, | ||
submitterEmail: data.submitterEmail, | ||
}, | ||
}, | ||
}, | ||
})); | ||
}; | ||
export type RaiIssueTransform = z.infer<ReturnType<typeof transformRaiIssue>>; |
12 changes: 12 additions & 0 deletions
12
src/packages/shared-types/action-types/legacy-submission.ts
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,12 @@ | ||
import { z } from "zod"; | ||
import { legacyAttachmentSchema } from "../attachments"; | ||
|
||
// Event schema for legacy records | ||
export const onemacLegacySchema = z.object({ | ||
additionalInformation: z.string().nullable().default(null), | ||
submitterName: z.string(), | ||
submitterEmail: z.string(), | ||
attachments: z.array(legacyAttachmentSchema).nullish(), | ||
raiWithdrawEnabled: z.boolean().default(false), | ||
}); | ||
export type OnemacLegacy = z.infer<typeof onemacLegacySchema>; |
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,15 @@ | ||
import { z } from "zod"; | ||
import { attachmentSchema } from "../attachments"; | ||
|
||
// This is the event schema for ne submissions from our system | ||
export const onemacSchema = z.object({ | ||
authority: z.string(), | ||
origin: z.string(), | ||
additionalInformation: z.string().nullable().default(null), | ||
submitterName: z.string(), | ||
submitterEmail: z.string(), | ||
attachments: z.array(attachmentSchema).nullish(), | ||
raiWithdrawEnabled: z.boolean().default(false), | ||
}); | ||
|
||
export type OneMac = z.infer<typeof onemacSchema>; |
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 |
---|---|---|
@@ -1,37 +1,15 @@ | ||
import { z } from "zod"; | ||
import { onemacAttachmentSchema, handleAttachment } from "../attachments"; | ||
import { attachmentSchema } from "../attachments"; | ||
|
||
export const raiResponseSchema = z.object({ | ||
id: z.string(), | ||
authority: z.string(), | ||
origin: z.string(), | ||
requestedDate: z.number(), | ||
responseDate: z.number(), | ||
attachments: z.array(onemacAttachmentSchema).nullish(), | ||
attachments: z.array(attachmentSchema).nullish(), | ||
additionalInformation: z.string().nullable().default(null), | ||
submitterName: z.string(), | ||
submitterEmail: z.string(), | ||
}); | ||
export type RaiResponse = z.infer<typeof raiResponseSchema>; | ||
|
||
export const transformRaiResponse = (id: string) => { | ||
return raiResponseSchema.transform((data) => ({ | ||
id, | ||
rais: { | ||
[data.requestedDate]: { | ||
response: { | ||
attachments: | ||
data.attachments?.map((attachment) => { | ||
return handleAttachment(attachment); | ||
}) ?? null, | ||
additionalInformation: data.additionalInformation, | ||
submitterName: data.submitterName, | ||
submitterEmail: data.submitterEmail, | ||
}, | ||
}, | ||
}, | ||
})); | ||
}; | ||
export type RaiResponseTransform = z.infer< | ||
ReturnType<typeof transformRaiResponse> | ||
>; |
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,62 @@ | ||
import { z } from "zod"; | ||
|
||
// Reusable schema for officer data. | ||
export const seatoolOfficerSchema = z.object({ | ||
OFFICER_ID: z.number(), | ||
FIRST_NAME: z.string(), | ||
LAST_NAME: z.string(), | ||
}); | ||
export type SeatoolOfficer = z.infer<typeof seatoolOfficerSchema>; | ||
|
||
export const seatoolSchema = z.object({ | ||
ACTION_OFFICERS: z.array(seatoolOfficerSchema).nullish(), | ||
LEAD_ANALYST: z.array(seatoolOfficerSchema).nullable(), | ||
PLAN_TYPES: z | ||
.array( | ||
z.object({ | ||
PLAN_TYPE_NAME: z.string(), | ||
}) | ||
) | ||
.nonempty() | ||
.nullable(), | ||
STATE_PLAN: z.object({ | ||
SUBMISSION_DATE: z.number().nullable(), | ||
PLAN_TYPE: z.number().nullable(), | ||
LEAD_ANALYST_ID: z.number().nullable(), | ||
CHANGED_DATE: z.number().nullable(), | ||
APPROVED_EFFECTIVE_DATE: z.number().nullable(), | ||
PROPOSED_DATE: z.number().nullable(), | ||
SPW_STATUS_ID: z.number().nullable(), | ||
STATE_CODE: z.string().nullish(), | ||
STATUS_DATE: z.number().nullish(), | ||
SUMMARY_MEMO: z.string().nullish(), | ||
TITLE_NAME: z.string().nullish(), | ||
}), | ||
SPW_STATUS: z | ||
.array( | ||
z.object({ | ||
SPW_STATUS_DESC: z.string().nullable(), | ||
SPW_STATUS_ID: z.number().nullable(), | ||
}) | ||
) | ||
.nullable(), | ||
RAI: z | ||
.array( | ||
z.object({ | ||
RAI_RECEIVED_DATE: z.number().nullable(), | ||
RAI_REQUESTED_DATE: z.number().nullable(), | ||
RAI_WITHDRAWN_DATE: z.number().nullable(), | ||
}) | ||
) | ||
.nullable(), | ||
ACTIONTYPES: z | ||
.array( | ||
z.object({ | ||
ACTION_ID: z.number(), | ||
ACTION_NAME: z.string(), | ||
PLAN_TYPE_ID: z.number(), | ||
}) | ||
) | ||
.nullable(), | ||
}); | ||
export type SeaTool = z.infer<typeof seatoolSchema>; |
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 |
---|---|---|
@@ -1,38 +1,15 @@ | ||
import { z } from "zod"; | ||
import { onemacAttachmentSchema, handleAttachment } from "../attachments"; | ||
import { attachmentSchema } from "../attachments"; | ||
|
||
export const raiWithdrawSchema = z.object({ | ||
id: z.string(), | ||
authority: z.string(), | ||
origin: z.string(), | ||
requestedDate: z.number(), | ||
withdrawnDate: z.number(), | ||
attachments: z.array(onemacAttachmentSchema).nullish(), | ||
attachments: z.array(attachmentSchema).nullish(), | ||
additionalInformation: z.string().nullable().default(null), | ||
submitterName: z.string(), | ||
submitterEmail: z.string(), | ||
}); | ||
export type RaiWithdraw = z.infer<typeof raiWithdrawSchema>; | ||
|
||
export const transformRaiWithdraw = (id: string) => { | ||
return raiWithdrawSchema.transform((data) => ({ | ||
id, | ||
raiWithdrawEnabled: false, | ||
rais: { | ||
[data.requestedDate]: { | ||
withdraw: { | ||
attachments: | ||
data.attachments?.map((attachment) => { | ||
return handleAttachment(attachment); | ||
}) ?? null, | ||
additionalInformation: data.additionalInformation, | ||
submitterName: data.submitterName, | ||
submitterEmail: data.submitterEmail, | ||
}, | ||
}, | ||
}, | ||
})); | ||
}; | ||
export type RaiWithdrawTransform = z.infer< | ||
ReturnType<typeof transformRaiWithdraw> | ||
>; |
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,22 @@ | ||
export type KafkaEvent = { | ||
/** | ||
* @example "SelfManagedKafka" | ||
*/ | ||
eventSource: string; | ||
/** | ||
* @example: "b-1.master-msk.zf7e0q.c7.kafka.us-east-1.amazonaws.com:9094,b-2.master-msk.zf7e0q.c7.kafka.us-east-1.amazonaws.com:9094,b-3.master-msk.zf7e0q.c7.kafka.us-east-1.amazonaws.com:9094" | ||
*/ | ||
bootstrapServers: string; // comma separated string | ||
records: Record<string, KafkaRecord[]>; | ||
}; | ||
|
||
export type KafkaRecord = { | ||
topic: string; | ||
partition: number; | ||
offset: number; | ||
timestamp: number; | ||
timestampType: string; | ||
key: string; | ||
headers: Record<string, string>; | ||
value: string; // Kafka records typically have values as base64-encoded strings | ||
}; |
Oops, something went wrong.