-
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
fix(repository): fix broken code in readme #1121
Conversation
9f3e91c
to
cb7a989
Compare
packages/repository/README.md
Outdated
id: string; | ||
@property() title: string; | ||
@property() content: string; | ||
} | ||
``` | ||
|
||
**NOTE**: There is no declarative support for data source and model yet in |
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 thought we have declarative support for data source.
In db.datasource.ts, we can do something like below:
const dsConfigPath = path.resolve('config', 'datasources.json');
const config = require(dsConfigPath);
export const db = new DataSourceConstructor(config);
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.
@dhmlau I personally thought that the meaning of having declarative support meant that no config is necessary outside of the declarative file itself (the declarative file being config.json). Please correct me if I am wrong.
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 was thinking that we can still define the datasource.json like what we did in LB3. It's not the ultimate goal for declarative support. So i'm not sure what we wanna say about this statement. Maybe @raymondfeng can help :)
@@ -21,213 +21,6 @@ $ npm install --save @loopback/repository | |||
|
|||
## Basic use |
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.
Can we change it to Basic Use
?
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.
@dhmlau In loopback.io, we did sentence-case for titles and I thought we'd be sticking to that in the READMEs as well. Is it different for readmes?
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 was looking at the READMEs for @loopback/core and @loopback/rest and they seem to use the title capitalization rules. But i also see that the READMEs are not all consistent. Let me check with @bschrammIBM
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.
won't be a blocker for this PR.
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.
@shimks , according to @bschrammIBM, you're right!
packages/repository/README.md
Outdated
``` | ||
|
||
**NOTE**: There is no declarative support for data source and model yet in | ||
LoopBack Next. These constructs need to be created programmatically as | ||
LoopBack 4. These constructs need to be created programmatically as | ||
illustrated above. | ||
|
||
### Define a repository |
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.
Make it capitalization for titles.
--> Define a Repository
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.
confirmed with @bschrammIBM , your original version was correct (for capitalization) but should be Defining a repository
.
Similarly for others.. e.g. Defining a controller
.
That's something she can edit later.
packages/repository/README.md
Outdated
public noteRepo: EntityCrudRepository<Entity, number>; | ||
} | ||
``` | ||
|
||
### Run the controller and repository together |
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.
Same for this one please ignore
--> Run the Controller and Repository Together
packages/repository/README.md
Outdated
} | ||
} | ||
``` | ||
|
||
## Related resources |
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.
Related Resources please ignore
43ee221
to
d065b0a
Compare
@shimks I'm fine to move the concepts into |
Since moving the concepts isn't part of the issue #988, I'll keep the key concepts in the readme for now, and then create an issue to implement this decision made here. I'll later reference the issue here once it's been created. |
52041e1
to
b45f64b
Compare
b45f64b
to
680c3d1
Compare
|
||
export const ds: juggler.DataSource = new DataSourceConstructor({ | ||
export const db: juggler.DataSource = new DataSourceConstructor({ |
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.
Not sure why switch to db
. Please note ds
stands for dataSource
.
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 switched the constant name to db
because when we import the datasource to be registered with app.datasource()
, we retrieve it back through dependency injection via the string: datasources.db
and NOT datasources.ds
, the name of the constant. I thought we should be consistent here as to not confuse the users.
Alternatively, I could change name: 'db'
to name: 'ds'
so that the name of the variable being named is consistent with the datasource's name. Should I switch back regardless?
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.
+1 for using db
, it's the name of the default we use in our project templates (LB 3.x and 4.x) too.
Not a big deal though, I can live with ds
too.
packages/repository/README.md
Outdated
@@ -139,12 +229,13 @@ There are two subtly different types of models for domain objects: | |||
} | |||
``` | |||
|
|||
### DataSource | |||
### Datasource |
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.
We use DataSource
in LB3.
680c3d1
to
35982af
Compare
packages/repository/README.md
Outdated
It contains the constructs for modeling and accessing data. Repositories can be | ||
used alone or as part of a `Controller` implementation. | ||
It contains the constructs for modeling and accessing data. We recommend using | ||
Repositories with implmentation of `Controllers`. |
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.
Typo: implmentation
|
||
export const ds: juggler.DataSource = new DataSourceConstructor({ | ||
export const db: juggler.DataSource = new DataSourceConstructor({ |
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.
+1 for using db
, it's the name of the default we use in our project templates (LB 3.x and 4.x) too.
Not a big deal though, I can live with ds
too.
|
||
// Create a new note | ||
@post('/note') | ||
create(@requestBody() data: Note) { |
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 think data
should be Partial<Note>
? E.g. when the database is creating the id
value for us, then id
needs to be omitted from the data payload.
Feel free to leave this change out of scope of this pull request though.
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 just tried out changing the type to Partial<Note>
to see what OpenAPI spec would get generated, and it just interpreted the parameter type to be an object
, so it seems like we can't do this here unless we specifically circumvent around this issue.
This isn't really a problem right now since type validation isn't being done, but it IS technically wrong for the route to accept an object that is only partially a Note
. What do you think?
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.
@bajtos ^^^
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.
@shimks I'm interested to hear why the route can't accept Partial<Note>
. I thought partial just meant that the type is preserved, but some(or all?) properties are optional.
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.
Yes, Partial<Note>
means Note
model with all properties made optional. We are already using it in our ORM layer, see e.g. here:
I just tried out changing the type to
Partial<Note>
to see what OpenAPI spec would get generated, and it just interpreted the parameter type to be an object
That looks like a rather unfortunate limitation of what can be inferred via TypeScript type system 😞
I personally think it's important to have correct type annotation (Partial<Note>
), even if it means that we have to explicitly provide the request body schema for OpenAPI Spec.
packages/repository/README.md
Outdated
|
||
// Find notes by title | ||
@get('/note/{title}') | ||
findByTitle(@param.query.string('title') title: string) { |
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.
Since your path contains {title}
in it, you should not use param.query
. I think param.path
is what you need.
cbfbf4d
to
a1c704f
Compare
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.
Minor nit-picks
packages/repository/README.md
Outdated
It contains the constructs for modeling and accessing data. Repositories can be | ||
used alone or as part of a `Controller` implementation. | ||
It contains the constructs for modeling and accessing data. We recommend using | ||
Repositories with implementation of `Controllers`. |
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.
implementation of Controllers
but then can be used alone.
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'm a bit confused. Are you saying that I should reword the sentence so that it doesn't imply controllers have to be used in conjunction with repositories?
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.
Yep. Adding a but can be used alone
so it's clear our recommendation isn't the only way forward.
packages/repository/README.md
Outdated
- https://martinfowler.com/eaaCatalog/repository.html | ||
- https://msdn.microsoft.com/en-us/library/ff649690.aspx | ||
- http://docs.spring.io/spring-data/data-commons/docs/2.0.0.M3/reference/html/#repositories | ||
|
||
## Contributions | ||
|
||
- [Guidelines](https://github.com/strongloop/loopback-next/wiki/Contributing##guidelines) | ||
- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/site/DEVELOPING.md) |
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.
Change this to point to https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md
a1c704f
to
f290964
Compare
packages/repository/README.md
Outdated
It contains the constructs for modeling and accessing data. Repositories can be | ||
used alone or as part of a `Controller` implementation. | ||
It contains the constructs for modeling and accessing data. We recommend using | ||
Repositories with implementation of `Controllers` but it can be used |
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'd be great if we have a sentence on what repositories are before we say We recommend using Repositories...
packages/repository/README.md
Outdated
|
||
const repo = new DefaultCrudRepository(Note, ds); | ||
We'll use `BootMixin` on top of `RepositoryMixin` so that Repository bindings | ||
can be taken care of at boot. |
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.
nitpick: taken care of by @loopback/boot at boot time before the application starts
or something along those lines. Feel free to ignore.
|
||
// Create a new note | ||
@post('/note') | ||
create(@requestBody() data: Note) { |
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.
@shimks I'm interested to hear why the route can't accept Partial<Note>
. I thought partial just meant that the type is preserved, but some(or all?) properties are optional.
@b-admike It has to do with how TypeScrpt preserves metadata of Constructors that are @bajtos Should I be making an issue to address this problem? |
@shimks Thanks for clarifying and +1 for opening an issue to track it. |
Looks like this issue is trickier than I originally thought. Let's keep you current version For example, I would like to write |
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 think the current proposal is definitely an improvement compared to the current status and should be landed even if it's not perfect.
As far as I am concerned, this patch LGTM.
cf667a1
to
8d250fe
Compare
8d250fe
to
a04fa2d
Compare
loopback.io
. But then again, they may have been covered already. @raymondfeng any thoughts?Checklist
npm test
passes on your machinepackages/cli
were updatedpackages/example-*
were updated