-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 datasource config from JSON to TS files #5000
Conversation
Other than through the changelogs, we could...
As there isn't a clear scope on which parts of the CLI are expected to be consistent, it should be considered a breaking change. Examples of scopes:
|
Thank you @achrinza for chiming in!
That's what I am leaning towards too. I am thinking about adding a sub-section to https://loopback.io/doc/en/lb4/DataSource-generator.html, where I can explain the difference in the output of
IIUC, you are saying that if we are not sure, then we should treat the change as breaking? Such strategy seems a bit too conservative to me. My changes are not going to break any existing projects or applications. After the CLI is upgraded, The question is whether Do you still think that a semver-major release is needed when the only change is in the newly scaffolded files? |
Does discovery of datasources continue to work for related |
I think the proposal at a high level is good, but +1 to @raymondfeng's comment. It's important to make sure that discovery related CLI commands are compatible.
👍 This is what I would've proposed as well.
We can see how the other CLI commands are affected, then decide this. |
ff8db3a
to
eb5774b
Compare
Hello 👋 I updated the pull request with the following improvements:
I'd like to get your feedback on this increment, @raymondfeng @nabdelgadir @achrinza What's remaining: fix the tests of the following CLI commands:
|
I think it's time to break down |
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.
This increment looks good to me, with one question
packages/cli/test/integration/generators/repository.integration.js
Outdated
Show resolved
Hide resolved
Sure, but that's out of scope of this pull request. Personally, I think we should start with extracting code for working with project artifacts into a new package, something similar to https://github.com/strongloop/loopback-workspace. See also #844 [CLI] Get rid of Yeoman. |
eb5774b
to
e5ae08a
Compare
Since we can now effectively do variable substitution, this may be a good opportunity to port over Specifying database credentials with environment variables into the LoopBack 4 docs. |
Thank you @achrinza for raising this point! It was indeed one of my goals to make it easier to provide datasource configuration from environment variables. However, we haven't decided yet what should be the recommended way for handling environment-specific configuration in LB4. There was some discussion in #1464 plus we already have some LB4 documentation in our deployment guides:
We don't have any Kubernetes-specific advice, I am not sure if it's because Kubernetes deployments don't need to change datasource configuration or because we didn't consider that aspect when writing the guide. Either way, I feel that documenting how to use environment variables in datasource config is out of scope of this pull request, the PR is already too large to my taste. Would you mind creating a follow-up issue for the docs you have in mind? |
c6f9c1c
to
b9b3d15
Compare
I pushed few new commits today, I consider the patch ready for final review. I'll clean up the commit history after the changes are approved. List of recent changes:
The code in tests is not as clean & consistent as I it would like to be, but I have only so much time available for refactoring existing cruft 🤷 @achrinza @nabdelgadir @raymondfeng Do you have any more comments? Does the pull request LGTY now? |
(Investigating test failures now. It looks like the test is not picking |
64867c2
to
ad7732c
Compare
ad7732c should fix the build 🤞 |
Oh well, looks like snapshots are not the best tool when testing file paths :( const config = {
name: 'petStore',
connector: 'openapi',
- spec: 'C:\projects\loopback-next\packages\cli\test\fixtures\openapi\3.0\petstore-expanded.yaml',
+ spec: '../../../fixtures/openapi/3.0/petstore-expanded.yaml',
validate: false,
positional: true
}; |
ca9f4f4
to
892d733
Compare
892d733 is fixing the failing snapshot tests on Windows in a way that (I hope) will improve lives of all LB users on Windows |
@achrinza @nabdelgadir @raymondfeng PTAL, does the pull request LGTY now? |
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.
👍
892d733
to
fe208cb
Compare
Rework the template for new datasources to store the datasource configuration inside the TypeScript source code file (e.g. `src/datasources/db.datasource.ts`) and stop emitting JSON files. Update affected CLI commands like `lb4 repository` to support both styles: - legacy JSON-based configuration - modern TS-based configuration Update existing examples to use the new style. Update relevant places in our documentation to use the new style too. Signed-off-by: Miroslav Bajtoš <[email protected]>
When creating a new OpenAPI-backed datasource and the spec URL is a relative path, normalize the value on Windows to use forward-slash characters (e.g. `../foo/bar.yaml`) instead of backslash-characters (e.g. `..\foo\bar.yaml`). Signed-off-by: Miroslav Bajtoš <[email protected]>
fe208cb
to
1d1e791
Compare
I have rebased the patch on top of the latest master and squashed the commits. Unless there are any more comments and/or objections, my plan is to go ahead and merge this change as a backwards-compatible feature on Friday April 24th. |
For quite some time I was thinking about our current project layout for datasources and the issues it brings:
IIRC, we introduced DataSource JSON files because it was the design already used by LB3 and loopback-workspace. We were anticipating that in early future (from the point of view of 2017), we will write tooling to edit DataSource configuration programmatically - somethings that's easier to implement for JSON files rather than TS files.
Clearly, programmatic editing of datasource config didn't become a priority in the last several years and most likely won't become important anytime soon.
Additionally, we already have pretty good tooling for editing TypeScript source code programmatically, we use it to edit model and repository files when scaffolding new relations.
In that light, I feel there is no need to use DataSource JSON files any more and it's better to move the definition of the (default) configuration object to the "main" TypeScript file.
And that's exactly what this pull request is about. I split the changes into three parts to make them easier to review.
Open questionsWhat's the best way for communicating these change to our users? Should we treat the CLI change as a breaking change? The new version is not going to break existing projects, but it will start emitting different source code for new datasources. Should we provide a migration guide?UPDATE 2020-04-06
Based on the discussion, I added a migration guide to Datasource-generator.md page and implemented backwards compatibility layer to support both JSON-based and TypeScript-based configuration of datasources.
My intention is to label this change as a backwards-compatible feature triggering a semver-minor release.
Out of scope
While reviewing all things related to DataSources, I found few more opportunities for cleanup. I prefer to leave them out of this PR, but would like to implement them soon after this patch is landed.
name
read-only, set it fromconfig.name
to avoid duplication.@config
, so that they can be configured viaapp.configure()
. Update the docs (especially Cloudant & Bluemix guides), make sure to preserve content for the old configuration style (think of existing projects created before the change).examples
to use the same style as scaffolded bylb4 datasource
. Most notably, change them to participate in app life-cycle and disconnect when the application has stopped. Update the docs accordingly.(UPDATE 2020-04-24: created a follow-up issue #5220.)
I'd like to get feedback especially from @raymondfeng as our architect and @nabdelgadir as the FA owner of LB4 project conventions.
/cc @strongloop/loopback-next because this change is going to affect most of our users.
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈
TODO
Fix the tests (and possibly the implementation) of the following CLI commands to support & test both the new style but also the legacy one.
lb4 relation
lb4 repository
lb4 rest-crud
lb4 service
lb4 openapi