-
Notifications
You must be signed in to change notification settings - Fork 90
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
Move package API requests to one file, consolidate naming and internal API #2154
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2154 +/- ##
==========================================
+ Coverage 47.36% 47.38% +0.02%
==========================================
Files 439 440 +1
Lines 21068 21095 +27
Branches 2432 2432
==========================================
+ Hits 9978 9996 +18
- Misses 10180 10189 +9
Partials 910 910
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
the general direction is right, but i think we should
- adjust naming
- remove unnecessary level of abstraction by calling
req
directly
}): Promise<O> | ||
} | ||
|
||
const uploadManifest = ( |
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.
i dont think this function should exist
- its name doesnt reflect all its use cases, it looks like a leaked abstraction;
- it doesnt have enough logic, i think it's better to just call
req
directly (you can parameterize body and response types to add type checking there)
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.
It's a place where I can validate the request body with Schema
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.
you can validate it the same way by using type arg for req
I can't do this, because my goal was to consolidate requests in one function where I can validate the request body |
but requests are different, so are the bodies. you can type-check request body by simply using type arg when calling |
ok, i see that by "validate" you probably mean some runtime validation, not type-checking, but i still dont quite get it |
function uploadManifest(req, s3, endpoint, workflow, body) {
const schema = await s3.fetchFile(workflow.objectSchemaurl)
const error = validateBody(schema)
if (error.length) throw error
return req(endpoint, body)
}
function useCreatePackage(body) {
const req = useAPIConnector()
const s3 = useS3()
return uploadManifest(req, s3, "/packages", workflow, body)
}
function useCopyPackage(body) {
const req = useAPIConnector()
const s3 = useS3()
return uploadManifest(req, s3,"/packages/promote", workflow, body)
} |
I don't have working code for the next PR, but I wanted something like this ^ |
ok now i get it, but
|
Do you have in mind what name could be appropriate? |
dunno, smth like |
I can be confident about an object's shape with type-checking, but Schema gives more possibilities like, for example, checking number values ( |
true, but you must somehow guarantee that the schema is compatible with the type |
* master: (54 commits) Use stable nginx version for catalog image (#2182) Ability to add S3 folders / files to package (#2171) lambda for adding S3 data to existing package (#2180) use github tarball for faster installation (#2181) Bump py from 1.7.0 to 1.10.0 in /lambdas/es/indexer (#2176) Bump py from 1.8.0 to 1.10.0 in /lambdas/s3select (#2177) Bump py from 1.8.0 to 1.10.0 in /lambdas/thumbnail (#2178) Allow unicode characters for package routes by allowing any character (#2179) Additional NotFoundPage scoped to Bucket (#2175) Docs: fix catalog config path (#2168) rework pkgpush auth (#2170) Use AWS credentials for directory package and copy package submit (#2172) Document package push limitations in catalog [ci skip] (#2161) Preview warnings accordion (#2167) tweak warning text (#2169) Copy tweaks (#2164) Don't crash pkgselect for empty manifests (#2147) add codecov config (#2155) Simplify warning messages for package name (#2134) Move package API requests to one file, consolidate naming and internal API (#2154) ...
I need this refactoring because I want to be able to validate params for every package API request in one place