Skip to content
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

FHIR Package Loader Rewrite #42

Merged
merged 10 commits into from
Dec 6, 2024
Merged

FHIR Package Loader Rewrite #42

merged 10 commits into from
Dec 6, 2024

Conversation

cmoesel
Copy link
Member

@cmoesel cmoesel commented Dec 2, 2024

Description: And now for something completely different...

This PR represents a total rewrite of the FHIR Package Loader -- with completely new interfaces, implementations, and APIs. This rewrite was necessary to address limitations in the package loader as well as support future use cases (such as transitive dependencies, multiple versions of the the same package, etc).

The new FHIR Package Loader now utilizes an in-memory database (currently sql.js) to store and query metadata about packages and their resources. This reduces memory usage per-resource since now only the metadata is kept in memory (vs the entire JSON object). With more efficient memory usage, we can now load all resources from the package (instead of just conformance resources) and we will also be able to load transitive packages in the future.

Separate concerns of the package loader have been separated out into their own interfaces and implementations, including:

  • PackageDB interface w/ SQLJSPackageDB implementation. Note that sql.js was chosen due to its support for synchronous queries -- which causes the least disruption to SUSHI (which has many synchronous functions).
  • RegistryClient interface w/ FHIRRegistryClient, NPMRegistryClient, RedundantRegistryClient, and DefaultRegistryClient implementations
  • CurrentBuildClient interface w/ BuildDotFhirDotOrgClient implementation
  • PackageCache interface w/ DiskBasedPackageCache implementation
  • VirtualPackage interface w/ DiskBasedVirtualPackage and InMemoryVirtualPackage implementations
  • PackageLoader interface w/ BasePackageLoader implementation that accepts implementations of the previous interfaces and ties them together for a complete package loading solution.

This approach allows for additional capabilities in the future, such as implementations that work well in web browsers.

Testing Instructions:

  • Ensure that all unit tests pass
  • Try the command-line client as described in the README
  • Try SUSHI's new-fpl branch that integrates this PR's package loader

NOTE: Much of this PR contains code that was previously reviewed before merging into the new-fpl feature branch. Those reviews, however, typically only involved one reviewer -- and some of the initial code never went through a PR. So... review and test accordingly.

Related Issue: Implements #30.

cmoesel and others added 8 commits December 2, 2024 10:14
- Refactored package loader w/ interfaces for db, registry, current, cache, and loader
- SQL Lite JS database implementation for package and resource metadata
- FHIR, NPM, and build.fhir.org registry client implementations
- Diskbased cache for accessing the local .fhir cache
- BasePackageLoader implementation that ties them all together
* Add tests for SQLJSPackageDB

Test the save, find, stats, and clear class methods. No tests are added
for the logging methods.

Minor styling changes in some other files, as applied by prettier.

* Make test for SQLJSPackageDB.findResourceInfo stricter

Check properties of the returned resource to make sure it matches one of
the expected results.

Remove unneeded comment from saveResourceInfo test.

* Expect last added resource from findResourceInfo
- Remove FHIRDefinitions
- Remove load function
- Remove old API (fpl function)
- Remove other unused errors, classes, and functions
- Update app.ts to use new classes
- Update README
* Update dependencies

Add eslint config file based on requirements for updated eslint
dependencies.

Remove @types/tar dependency because types are now included in the tar
dependency.

Minor usage updates for tar and commander based on changes to package
export.

Minor fixes for linting rules.

* Update node types to latest 20.x version

Other packages with recent minor updates are also updated. No change to
the packages in dependency notes.
- BasePackageLoader tests
- DefaultPackageLoader tests
- Additional json files used taken from fpl and sushi
- Fix spy usage in BasePackageLoader tests
- Add BasePackageLoader tests for more coverage
- Add DefaultPackageLoader tests
- Change log message on successful package load to use the actual
  loaded version, which may be different than the requested version.
Various changes to better support the needs of SUSHI while remaining neutral for other environments and applications. Including:
* VirtualPackage interface for pseudo packages not in the registry or local FHIR cache
* DiskBased and InMemory implementations of Virtual Package
* Support for loading VirtualPackages in the BasePackageLoader
* Support for '|version' when searching by key
* New exportDB function in SQLJSPackageDB and BasePackageLoader for debugging purposes
* New --export flag in CLI app to export a SQLite DB file from the loaded packages
* Added sort to find functions' options, with initial ByLoadOrder and ByType implementations (the original type argument is now just a filter, no longer affecting sort)
* Added resolveVersion function to RegistryClient interface and corresponding implementations
* Moved LRU cache from DiskBasedPackageCache to BasePackageLoader
* getPackageInfos returns all loaded package infos when search key is '*'
* BasePackageLoader returns helpful tips about SSL certificates and proxies when error is due to self-signed certificates
* SafeMode option with values OFF, CLONE, and FREEZE
* Optimize queries and indices
* Expose database optimization function
Copy link
Collaborator

@jafeltra jafeltra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really great! This was my first time really digging into this rewrite, and this really breaks out all the separations of concerns and nicely brings them all together for the implementation for SUSHI. I left a few small comments, but none of them are big changes of anything.

package.json Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
test/current/BuildDotFhirDotOrgClient.test.ts Outdated Show resolved Hide resolved
src/current/BuildDotFhirDotOrgClient.ts Outdated Show resolved Hide resolved
test/current/BuildDotFhirDotOrgClient.test.ts Outdated Show resolved Hide resolved
test/registry/FHIRRegistryClient.test.ts Outdated Show resolved Hide resolved
src/package/index.ts Outdated Show resolved Hide resolved
@cmoesel
Copy link
Member Author

cmoesel commented Dec 4, 2024

Thank you for the very thorough review, @jafeltra. I believe I've addressed all of your findings in a538efd.

Copy link
Collaborator

@mint-thompson mint-thompson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's finally here! The big FPL refactor! @jafeltra already caught most everything I noticed, but there was one minor discrepancy in the readme that I want to point out.

README.md Outdated Show resolved Hide resolved
jafeltra
jafeltra previously approved these changes Dec 4, 2024
Copy link
Collaborator

@jafeltra jafeltra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for making all those changes! 💯

Copy link
Collaborator

@mint-thompson mint-thompson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooray for new FPL!

Copy link
Collaborator

@jafeltra jafeltra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reapproving for such nicely sorted imports! 💯 💯

@cmoesel cmoesel merged commit a59a015 into main Dec 6, 2024
14 checks passed
@cmoesel cmoesel deleted the new-fpl branch December 6, 2024 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants