-
Notifications
You must be signed in to change notification settings - Fork 12
dhis2: Implement http
namespace, a generic request function, and remove all callbacks
#1046
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
dhis2: Implement http
namespace, a generic request function, and remove all callbacks
#1046
Conversation
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
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 am having a hard time seperating "move http methods out into a clean namespace" from "fix all the problems with DHIS2 http APIs"
Docs are worrying me, base64 is worrying me, and I wonder if handleResponse needs to move into here.
I need to break here today but I'll think about this stuff more tomorrow.
It doesn't technically matter which PR fixes these problems - but it does matter what's in the next release. Dhis2 7 really needs to have a clean, well documented API. And do get to there we'll need more work.
I'll come back with a fresh brain.
packages/dhis2/src/Adaptor.js
Outdated
return update(resourceType, path, data, options)(state); | ||
} | ||
}); | ||
promise = http |
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.
ooh this is really annoying
Because we're using the http.get()
operation directly, we have to feed state back into the call here.
it's an antipattern really. We certainly don't want to encourage it, and this is a big, brand-defining adaptor.
We don't have to do this in this PR, but what's the cost in using like util.request
instead of http.request
? Of using a function rather than an operation?
Also: if asbase64
is true, I think this stuff might be broken? Because response.data is a string and all these tests will fail 😬
|
||
/** | ||
* Options object | ||
* @typedef {Object} RequestOptions |
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.
Worried about these docs but they're not technically part of this PR. Let me think about it. Referenced here: #975 (comment)
packages/dhis2/src/http.js
Outdated
* @example <caption>a dataElement</caption> | ||
* http.patch('dataElements', 'FTRrcoaog83', { name: 'New Name' }); | ||
*/ | ||
// TODO: @Elias, can this be deleted in favor of update? How does DHIS2 handle PATCH vs PUT? |
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.
@mtuchi can you help resolve this? Should we just remove patch?
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.
Hiya @josephjclark this is what i was able to gather regarding PATCH
method in DHIS2
The DHIS2 API supports the PATCH method for various metadata endpoints.
For example, you can use PATCH to:
- Update properties of metadata objects
- Add or remove items from collections
- Change domain types and value types
- Remove specific organization units from groups
When using the PATCH method with any of these endpoints, you must use the content type application/json-patch+json
in your request headers as per the JSON patch specification. See DHIS2 Documentation - Partial Updates DHIS2 Documentation - Bulk Sharing
Meanwhile, you can use PUT on:
- Metadata endpoints - For updating various metadata objects like data elements, organization units, etc. DHIS2 Documentation - Metadata CRUD
- Data Store endpoints - For updating key-value pairs DHIS2 Documentation - Data Store
- Maintenance endpoints - For performing system maintenance operations DHIS2 Documentation - Maintenance
- Visualization endpoints - For updating visualizations DHIS2 Documentation - Visualizations
That being said, I have never used the API endpoints in this discovery but i guess it doesn't hurt to maintain both patch
and put
or if we decide to remove them we should have a http.request
function which will still allow me to specify patch
or put
when there is a need for that
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.
Thank you for the thorough report @mtuchi!
So this must be a JSON patch. That's interesting.
If we wanted, we could sit down a workout a nice easy JSON patch API. But we should not do that for a function that no-one is using.
How about:
- We keep the patch function
- We default the content type to
application/json-patch+json
- We document that data must be in JSON Patch format and link to DHIS2 docs
That's a reasonable position to take right now. Maybe later we can make this a bit slicker.
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 am happy with that, and since the link to DHIS2 docs is subjected to either metadata apis or sharing apis maybe we add an example with JSON Patch format. For example we should convert this example 👇🏽 to openfn job code
PATCH /api/dataElements/{id}
[
{"op": "add", "path": "/name", "value": "New Name"},
{"op": "add", "path": "/valueType", "value": "INTEGER"}
]
Signed-off-by: Hunter Achieng <[email protected]>
http
namespacehttp
namespace, a generic request function, and remove all callbacks
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
fix odoo images
odoo: Add `downloadNewRecord` to create
* openmrs: feed the error map through to common request * common: don't throw any errors if the error map is false * common: docs * changesets * strict equality * versions * fix ignore * package lock
@hunterachieng after you've addressed my comments, you'll want to rebase this on top of #1059 (or maybe merge is easier). It might be a hard rebase so it might be easier to start again? You'll need to take a look and decide. |
* new branch for varo adaptor. * ContentIndicator validation should be on "name", not on "type". * update linting rules * gmail: default parameters to fix lint fail * Added changeset. * version: [email protected] * Added fridgetag parsing. * Fridgetag enhancements. * Added more metadata to fridgetag. * metadata * Refactored key functions into utility files. * Updated changelog * Updated icon assets. * Update VaroEmsUtils.js Removed test code. * Updated readme with enhanced information. Enhanced the function to accept a parameter instead of relying directly on state.data. * updated readme * Fix broken test runner. Updated package versions for testing framework. Updated README. Simplified name of core functions. * Added unit tests. * Updated jsdocs. * Fixed pnpm-lock file * Fixed jsdoc example formatting. * eslint should be 8.26 * tweak build stuff (#1069) * revert mocha version * remove dirname stuff * revert pacakge lock * revert package.json --------- Co-authored-by: Jason DeCarteret <[email protected]> Co-authored-by: Joe Clark <[email protected]>
* tools: add support for core fhir definitions Core fhir definitions seem use a different bundle structure to the regular IG definitions. Basically the folder structure is a bit different and the resources are all captured in a single bundle. This commit adds a solution which seems to work in fhir 4 at least * tools: experiment with unit tests in codegen * fhir4: add generated adaptor * tools: restructure generated output Put each profile in its own file, and just the entrypoints in builders.js * tools: override ts definition for simple signatures * tools: geneate basic jsdocs for builder functions We need these for the docsite anyway - but they're not a good solution for driving ts * tools: tweak to fix typescript in tests * fhir-4: update generated artefacts * fhir4: refactor tests * fhir4: add patient example test A good way to sketch out the value of the builder APIs. Not sure we're coming out ahead yet * fhir4: remove inactive and foundation profiles * fhir-4: restore missing files Accidentally used an overly restrictive mapping * fhir4: add typescript support * start porting over type defintions to the builder * tools: generate correct implementation signatures * tools: wire up type interfaces to the builders this includes referneces to @types/fhir with _ props removed works in unit tests now, hurrah! * fhir4: regen in ts * tools: mark lodash as external in fhir adaptors * tools: bundle fhir types into one big file. Difficulty: doesn't hanndle imported fhir types * fhir4: bundle types plus some tool tidyups * tools: generate tests as ts now we get instant type tracking in the builders * fhir-4: redo tests * fhir4: ts tweaks * fhir4: tmp refactor to figure out type structure * fhir: generate datatype definitions woohoo! * fhir4: tweak build order * fhir4: fix typings * fhir4: make mapping lookup more robust * fhir4: fix build * fhir4: update template * fhir4: attempt to simplify generated code But profiles are now failing to generated d.ts files. Maybe globals are broken? * fhir: restructure types to remove global namespaces, which cause problems I think this is all working now? * fhir4: regeerate all types * fhir4: fix export * ensure jsdocs can handle ts files * fhir4: fix build error * fhir4: fix typings don't bundle everything into one file, just bundle the fhir types * fhir-4: add initialiser function and remove text and meta * initialiser docs * start building out operations with fhir verbs * fhir-4: fill out more ops and tests * simplify docs by ignoring common props * fhir-4: added extra ops * partial commit for adding bundle support * add bundle helpers * move datatypes into builders * fix datatype exports * fhir4: save and re-use options * fhir4: tidyup data type helpers Warning! this will break the generated codegit status * fhir4: delete key in composite, add patient test * fhir4: better handling of array types * fhir4: better support for arbitrary props * version bump * test all files * refine resources * regenerate tests * remove lint command * ux improvements to datatypes * Add typings for shorthand properties * suport polymorphic types in resource definitions * fhir4: make setSystemMap a proper operations * make setSystemMap a proper operation * account tests * fhir4: fix some issues with typings and add Account test * fhir4: fixes to shorthand typing * tweak package.json * update tests * revert fhir-fr test
* fix docs * version: fhir-4:0.1.1
* `http` update examples (#1072) * update docs * update syntax * add changeset * Add `mSet` function in `redis` (#1080) * feat(#731): Add mSet() function to redis adaptor (#1064) * add mSet * add mSet unit test * add mSet on ast * correct the jsdoc * fix test * add changeset * fix feedback * update util import and code format * rename Utils to util * code format * add changeset --------- Co-authored-by: Alassane Ndoye <[email protected]> * build(deps): bump jsonpath-plus from 10.2.0 to 10.3.0 (#1019) Bumps [jsonpath-plus](https://github.com/s3u/JSONPath) from 10.2.0 to 10.3.0. - [Release notes](https://github.com/s3u/JSONPath/releases) - [Changelog](https://github.com/JSONPath-Plus/JSONPath/blob/main/CHANGES.md) - [Commits](JSONPath-Plus/JSONPath@v10.2.0...v10.3.0) --- updated-dependencies: - dependency-name: jsonpath-plus dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * releases * Add `bulkQuery` integration test (#1061) * wip bulk test * add id * add test for bulkQuery --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Emmanuel Evance <[email protected]> Co-authored-by: Alassane Ndoye <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Hunter Achieng <[email protected]>
* feat: add release dates to adaptor version bumps Signed-off-by: Hunter Achieng <[email protected]> * fix: add adaptor name to changeset script Signed-off-by: Hunter Achieng <[email protected]> * fix: format dates Signed-off-by: Hunter Achieng <[email protected]> * fix: implement ast for md conversion and date changes Signed-off-by: Hunter Achieng <[email protected]> * fix: add latest release date and configure version commands Signed-off-by: Hunter Achieng <[email protected]> * feat: update all changelogs with release dates Signed-off-by: Hunter Achieng <[email protected]> * Revert "feat: update all changelogs with release dates" This reverts commit 16a4cce. * fix: change date format Signed-off-by: Hunter Achieng <[email protected]> * Revert "fix: change date format" This reverts commit 2b0f256. * fix: change date format for version release dates Signed-off-by: Hunter Achieng <[email protected]> * fix: update commands, add read me Signed-off-by: Hunter Achieng <[email protected]> --------- Signed-off-by: Hunter Achieng <[email protected]>
Hi @hunterachieng , can we please restore the basically the http namespace should include Thanks! |
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
common: Add support for `parseAs:'base64'`
* New adaptor: Google Drive (#1098) * generate new adaptor for gdrive * add gdrive logic * update jsdoc * add unit test * AST * fix failing tests * delete utils * Enables resumable uploads * fix feedback * Feedback and refactoring Reafactoring: I changed the new Promise implementation to .then() because the Google Drive API client methods already return Promises. Instead of wrapping them in an unnecessary new Promise, we can directly return the existing Promise, which simplifies the code and avoids potential issues like missing error handling or double resolution. * fix text * update logo * refactoring * Update ast.json * Update examples and remove fileName param (#1146) * update examples and remove fileName param code format, update examples and remove fileName parameter on update function * build docs --------- Co-authored-by: Alassane Ndoye <[email protected]> Co-authored-by: Emmanuel Evance <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
@hunterachieng something really weird has happened on this diff? The history is all messed up. I think you need to revert that merge. |
Signed-off-by: Hunter Achieng <[email protected]>
@josephjclark I have implemented the changes |
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
@hunterachieng can you please take the http tests and split them out into a new file |
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
Signed-off-by: Hunter Achieng <[email protected]>
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.
Great, thank you @hunterachieng
I'm still confused about the main namespace get()
. It just doesn't sit well with http.get()
.
I'm going to have to work out what to do and raise an new issue for next sprint.
Summary
Move all the generic functions into a
http
namespace, remove callbacks and add a genericrequest
function.Fixes #978
Details
All the functions such as
post
,get
, andpatch
are moved to their ownhttp
name-spaced file to separate them from the other specific functions, and a genericrequest
function was added as well.All callbacks are being removed since the same behaviour can be achieved with promise chaining
AI Usage
Please disclose how you've used AI in this work (it's cool, we just want to
know!):
You can read more details in our
Responsible AI Policy
Review Checklist
Before merging, the reviewer should check the following items:
production? Is it safe to release?
dev only changes don't need a changeset.