-
Notifications
You must be signed in to change notification settings - Fork 0
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
453 ega api funcs #458
Merged
Merged
453 ega api funcs #458
Conversation
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
joneubank
approved these changes
Sep 27, 2024
src/jobs/ega/types/results.ts
Outdated
Comment on lines
79
to
110
export type ZodResultAccumulator<T> = { success: T[]; failure: ZodError[] }; | ||
/** | ||
* Parses an array of Zod SafeParseReturnType results into success (successful parse) and failure (parsing error) | ||
* @param acc ZodResultAccumulator<T> | ||
* @param item z.SafeParseReturnType<T, T> | ||
* @returns ZodResultAccumulator<T> | ||
*/ | ||
const resultReducer = <T>(acc: ZodResultAccumulator<T>, item: z.SafeParseReturnType<T, T>) => { | ||
if (item.success) { | ||
acc.success.push(item.data); | ||
} else { | ||
acc.failure.push(item.error); | ||
} | ||
return acc; | ||
}; | ||
|
||
/** | ||
* Run Zod safeParse for Schema T on an array of items, and split results by SafeParseReturnType 'success' or 'error'. | ||
* @params schema<T> | ||
* @params data unknown[] | ||
* @returns { success: [], failure: [] } | ||
*/ | ||
export const safeParseArray = <T extends ZodTypeAny>( | ||
schema: T, | ||
data: Array<unknown>, | ||
): ZodResultAccumulator<z.infer<T>> => | ||
data | ||
.map((i) => schema.safeParse(i)) | ||
.reduce<ZodResultAccumulator<z.infer<T>>>((acc, item) => resultReducer(acc, item), { | ||
success: [], | ||
failure: [], | ||
}); |
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.
Feel like this file is getting overloaded, kind of a dumping ground. This new stuff belongs in a dedicated file for zodSafeParseArray.ts
or similar
src/jobs/ega/utils.ts
Outdated
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.
👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds necessary API calls for permissions flow.
EGA Job
dacId
as a config value, for referencing the ICGC DAC idAxiosError
classes for404
and429
errorsexpiresAtUtc
to approved apps db query to be used asexpires_at
value in ApprovePermissionRequestTypes
safeParseArray
utility func to validate items in list responses (thanks @joneubank !)Result
type forDocumentation
DAC_ID
to.env.example
+README
Dependencies
zod
, bumpstypescript
versionDev testing
userJwt
expiry value