spoonx / aurelia-orm Goto Github PK
View Code? Open in Web Editor NEWMakes working with entities and calling your Rest API simple.
Home Page: http://aurelia-orm.spoonx.org
License: MIT License
Makes working with entities and calling your Rest API simple.
Home Page: http://aurelia-orm.spoonx.org
License: MIT License
I might be missing something, but how do I achieve the same functionality as with the pure aurelia-validation? I want to show the user real-time input validation messages, not only validate during submiting the form. I'm looking for a solution that doesn't require to duplicate code (such as one set of validation rules in the entity and another one strictly for showing messages inside the form) Let's say I have a customer entity:
@validatedResource('customers')
export class Customer extends Entity {
@ensure(it => it.isNotEmpty().hasLengthBetween(1, 20))
name = null;
}
And somewhere in the app I'm using it in a form:
newcustomer.html
<button click.delegate="save()" >
Save </button>
<form validate.bind="validation" role="form">
<div class="form-group">
<label>Name</label>
<input type="text" placeholder="Name and Surname" class="form-control"
value.bind="customer.name" />
</div>
</form>
newcustomer.js
....
@inject(EntityManager)
export class newcustomer {
constructor(entityManager) {
this.customersRepository = entityManager.getRepository('customers');
this.customer = entityManager.getEntity('customer')
}
save() {
this.customer.getValidation().validate().then( () => {
console.log("I updated"+ this.customer.name);
return this.customer.save()
} )
};
By default aurelia-validation would attach messages to the such as is required or length has to be between x and y.
Thanks for any help!
I usually design my PUT api like so:
[HttpPut]
public async Task<JsonResult> Put([FromBody] T item) {
// ...
}
but after seeing the HTTP traffic from this plugin I had to change it to:
[HttpPut("{id}")]
public async Task<JsonResult> Put([FromRoute] Guid id, [FromBody] T item) {
item.Id = id;
// ...
}
See this thread if more context is needed: SpoonX/aurelia-api#151
Currently, there's a bug with collection associations that causes the isClean() to give false positives when the entity in question has new, not persisted children. The problem lies in the way we check the entity's state. We create a flat representation of the collections (by id) obviously not including new children.
We could change this, and just include null
values for new entities, but then the saveCollections method has to be altered, too (which will remove all the flexibility currently implemented).
I already have a pretty good idea how I want to solve this, and will come with a PR somewhere this week.
Unless there already is a way I'm not seeing, but would be nice to see the ability to add custom actions.
For example, if I wanted to add an authenticate()
action to an entity.
i'm using spoonx libs aurelia-authentication, aurelia-api, aurelia-orm. upgraded to the latest versions today.
regardless of the order the 3 plugins are loaded in aurelia configuration, the fetch request is not including the "authorization" header that aurelia-authentication injects. this results in all ORM calls returning only 401 Unauthorized due to this.
regular calls with aurelia fetch client are working fine as expected with aurelia-authentication "authorization" header.
causes dirty checking of the property as it makes it non-configurable
add dependency entries as there are for jspm
might be my current messed up TS version, but that version only works if i make my derived entitiy @transient as it's (in my messed up TS version at least) not inherited
has @Association({collection:'name'}
that might end up as having an es6Modules: true and getters in there ( aurelia-cli).-> crash on adding metadata
so, either:
for convinience markClean===true calls markClean
there shouldn't be the need to store originals oneself
Using aurelia-orm installing today we are getting this error. Changing the dependency for aurelia-templating to 1.2.1 it worked fine. So there is some incompatibility with 1.2.2.
DEBUG [templating] importing resources for http://localhost:9000/jspm_packages/npm/[email protected]/component/association-select.html []
aurelia-templating.js:692 Uncaught (in promise) Error: A BindingLanguage must implement parseText(...)
at BindingLanguage.parseText (http://localhost:9000/jspm_packages/npm/[email protected]/aurelia-templating.js:692:13)
at ViewCompiler._compileNode (http://localhost:9000/jspm_packages/npm/[email protected]/aurelia-templating.js:2008:79)
at ViewCompiler._compileNode (http://localhost:9000/jspm_packages/npm/[email protected]/aurelia-templating.js:2028:33)
at ViewCompiler.compile (http://localhost:9000/jspm_packages/npm/[email protected]/aurelia-templating.js:1985:12)
at eval (http://localhost:9000/jspm_packages/npm/[email protected]/aurelia-templating.js:2615:49)
Currently we have getProp as a dep, which I don't feel is needed.
Scenario
I have several APIs I want to call in an uniform manner, and I want to use aurelia-orm
as the only data access layer in my app.
For my APIs I could use a combination of well-known server libraries (like loopback), third-party ones, and custom written (maybe legacy) used among my company.
Proposal
aurelia-orm
will provide a way to configure a specific adapter for a repository, that will come from external plugins that I load beforehand.
For example there could be an aurelia-orm-loopback
plugin that provides an adapter for loopback based APIs. A developer should be able to write a custom adapter directly inside its app to deal with a custom API.
There are several features that aurelia-orm currently does not provide that should be added for completeness, like the ability to shape results on GET operations (for example a common approach is to support a query parameter like expand=prop1,prop2.subprop1
).
I plan to write my next API with loopback, but currently I can't say if I'll be able to implement the client-side part as an adapter for aurelia-orm
(I just started to read the docs, so I don't have the necessary background yet).
Waiting for votes on this..
aurelia-validatejs https://github.com/aurelia/validatejs wraps https://validatejs.org/ for use in aurelia. this might be a saver way for validation oving forward
load(..) better be call using compositionTransaction so that it's promise is respected
http://blog.williamhayes.org/2016/03/aurelia-custom-element-async-life-cycle.html
@RWOverdijk
i'd expect those to do the same. EntityManager.getEntity however doesn't have repository meta set
Scenario:
Entitiy company has association Entity brand
the server however returns brandId with a company request. since those don.t match, it doesn.t work.
so either it may be made clearer in the docs or we log a warning if the association brand doesn.t apear on company servet requests
Installing the latest aurelia-orm 2.2.3, it is loading github:spoonx/aurelia-api as a dependency.
This may be due to aurelia-authentication doing the same?
SpoonX/aurelia-authentication#109
I also see this reference to spoonx/aurelia-api in a /dist source:
aurelia-orm/dist/system/repository.js
Line 3 in 1b0798e
Currently, when saving an entity, the collection assocs all get added over again. No biggy, as the server side doesn't add twice, but a bit of a waste of resources.
This should be tackled, perhaps with the dirty check?
Add decorator to allow for entity label.
This label can be used as a key for i18n, too. This way, form generators and modals can automatically get the key (or label).
can't use properties in the view like customer.firstName
add my simple component test to prevent issues like #57
I just discovered that the private getFlat
method, used by the markClean
public method, does not call the asObject
public method, that I currently override, but the private/internal _asObject
method.
This violates the inheritance contract, as someone (like me for example ;) ) can override the base asObject
method to remove some harmful properties, that in my case cause circular ref errors on JSON.stringify
.
if ready, or else run code 'manually'
When updating a collection (with association-select
for example) it adds the selected items but doesn't remove the old existing ones.
It fires an OPTIONS
request but not the DELETE
request.
this.entity = this.repository.getPopulatedEntity(); // tags = [1,2,3,4]
this.entity.tags = [5, 6];
this.entity.save();
this.repository.getPopulatedEntity(); // tags = [1,2,3,4,5,6] (also in the DB)
Add a manyAssociation decorator. This gives us more info on the entity supplied.
Refactor find to accept path and criteria (relative to resource).
We are seeing this error on the latest aurelia-orm, aurelia-api and aurelia-authentication packages.
system.js:4 Uncaught (in promise) Error: TypeError: (0 , _aureliaTemplating.customElement) is not a function
at Object.eval (http://localhost:9000/jspm_packages/npm/[email protected]/component/association-select.js:75:100)
Error loading http://localhost:9000/jspm_packages/npm/[email protected]/component/association-select.js
This is a pretty interesting development, though have you seen redux and GraphQL? The GraphQL technology is pretty cool and redux as a store is super simple.
Scott
can't be used in views like that.
would be much easier if they'd be getters to enable disabled.bind="product.isClean"
in views
I would like to be able to override the default text value for the <option selected value="0">- Select a value -</option>
. This will allow the developer to set custom text, e.g. "- Assign to user -", as opposed to the default "- Select a value -".
Add read only properties, omitting any changes made to the entity on save, unless forced.
yeah, found the issue. will PR shortly
Make configurable
setData(data) {
Object.assign(this, data);
return this;
}
when data = {} , nothing happens. while i guess that is intended, wasn't clear enough in the docs. also a method to reset en entitiy is then needed (one can use EntityManager.getEntity('xy') though for this
Hi
having read the source code, I see that the HasAssociationValidationRule
class setup a validation rule that checks for an id
property, and that must be a number
..
That means this plugin can't deal with string foreign keys?
I have a backend that uses GUID as primary/foreign keys (I'm not happy with this, but it uses RethinkDB, and it is a lot happier with guids than with integers).
Thanks!
P.
To enable using the typings tool to get your .d.ts files...
for aurelia.api etc
Hi guys,
I have a question regarding nested resources. I have an article with multiple comments. I get the article via GET /articles/{id}
and the corresponding comments via GET /articles/{id}/comments
(the id is retrieved via a URL param).
The first GET is no problem (entityManager.getRepository('article')
and `find(params.id)). How would I handle the second GET? Right now, I am doing a
find(params.id + '/comments')`` on the articles repo. This does not look correct so far, am I missing something here from the docs?
Now, the same for adding a comment. My resource is POST /articles/{id}/comments
. How would I handle the dynamic param id in the comment entity?
Thank you for your help. Btw you are doing nice work here.
@RWOverdijk
dump name. by name i'd expect it to be the same as getPopulatedEntity(data) = make new entity and populates with data
@endpoint('api')
export class Customers extends Entity {
will still use default endpoint. users should be notified that the format is wrong and @resource() is needed for it to work
Make it possible to reference the parent. Take care of this in toObject(), too.
Hi
maybe it's only me, but when I program against a Repository instance, I'd expect every operation bounded to the resource
path. If I don't want that, I can simply program against the Rest endpoint..
I need the findPath
method, because my endpoint follows a (very common) REST structure where ids are in the path: /categories/id
If there's another clean way to GET a resource by altering the path, then discard the following.
The findPath
method on Repository feels wrong to me. It simply forwards the path to the underlying Rest endpoint, without prefixing resource
path:
var findQuery = this.getTransport().find(path, criteria);
but it can be changed to
var findQuery = this.getTransport().find(this.resource + path, criteria);
and change the find
method accordingly:
Repository.prototype.find = function find(criteria, raw) {
return this.findPath('', criteria, raw);
};
Then I can use the findPath
method like repo.findPath('/id')
When updating an entity (calling .save() or .update()) many relations don't get pushed as expected.
One fix for this, is to analyze the entity and set up actions to perform. Associations can be added through a series of /add calls.
I would like to be able to hide the default <option selected value="0">- Select a value -</option>
. In certain cases it would be desirable NOT to display this option, e.g. for mandatory fields where the user should ALWAYS select a value.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.