upfrontjs / framework Goto Github PK
View Code? Open in Web Editor NEWData handling framework complementary to backend active record systems.
Home Page: https://upfrontjs.com/
License: MIT License
Data handling framework complementary to backend active record systems.
Home Page: https://upfrontjs.com/
License: MIT License
Search terms
Is your feature request related to a problem? Please describe.
Complicated overloads might not return what's originally intended.
Describe the solution you'd like
Testing the expected types.
Describe how this would benefit the project/others
Gives confidence in the in the expected types.
Additional context
https://github.com/SamVerschueren/tsd - configuarbility improved tsdjs/tsd#132
https://github.com/dsherret/conditional-type-checks
https://github.com/microsoft/DefinitelyTyped-tools/tree/master/packages/dtslint
and/or write my own like vue-test-utils
and/or write a bunch of // @ts-expect-error
statements
Search terms
Describe how this would benefit the project/others
This might prove useful in larger projects where some event driven patterns maybe present.
Describe alternatives you've considered
None
Currently a shell script creates a symbolic link, update to husky for a more streamlined solution.
https://typicode.github.io/husky/#/
https://github.com/typicode/pinst
Add the following badges to make some info more accessible:
If accessors going to be a thing and has their property set up on the model as if they existed their typings should be hinted
I have started the work but the below means all hints are camel cased and that on an empty model (export default class User extends Model implements Getters<User>
) it gives the following error:
TS2559: Type 'User' has no properties in common with type 'Partial "", unknown>>'.
// only keep getters that are functions
type FilterGetters<T> = {
[K in keyof T as Extract<K, `get${string}Attribute`>]: T[K] extends (...args: any) => any ? T[K] : never
};
type TransformGetters<T extends Record<`get${string}Attribute`, (...args: any) => any>> = {
[K in keyof T]: Record<K extends `get${infer P}Attribute` ? Uncapitalize<P> : never, ReturnType<T[K]>>
};
export type Getters<T> = Partial<UnionToIntersection<TransformGetters<FilterGetters<T>>[keyof TransformGetters<FilterGetters<T>>]>>;
This depends on #155
Search terms
attributes
default value
Is your feature request related to a problem? Please describe.
It isn't
Describe the solution you'd like
When defining a new model, the developer should have the option to define default values on the model. These defaults are sent to the server when saving the model so they should not be included in the original
object when checking for changes
Describe how this would benefit the project/others
It would save the developer from having to pass in default values on constructing
Describe alternatives you've considered
none
Is there a currently a way to achieve this?
Additional context
Perhaps setting the attributes on the class definitely like public myAttribute = 1
would be the most intuitive given the current typing uses these attributes when set. This might be achieved by getting all the custom properties on the model which doesn't have getter and setter defined but a value.
Investigate and implement better typings throughout
GlobalConfig.prototype.unset
- Omit<T, K>
doesn't seems to work.Collection.prototype.pluck
- K extends keyof T
?Consider making attributes hidden or visible with methods.
This would be an options to temporarily "disable" access to attributes and relations. Meaning when one has hidden an attribute it will not return the value when using getAttribute
.
This could also hide the attribute when looping over the model woth for...of
(can be achieved by setting enumerable: false
.
The proposed api would look like:
user.makeHidden(key).makeVisible(key);
Questions:
setAttributes
Search terms
package exports
esm
cjs
Is your feature request related to a problem? Please describe.
The user currently have to import their helpers like import '@upfrontjs/framework/string.es.min.js';
What would be ideal if import '@upfrontjs/framework/string
was enough to specify and the rest can be figured out by the bundlers.
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe how this would benefit the project/others
better discoverability for IDEs, less things to type
Describe alternatives you've considered
not applicable
Additional context
microsoft/TypeScript#33079
This would allow for better scanning of the licenses in the package and making a decision whether the user's product should use upfront or not.
Devise a way to update the readme with a summary of the dependency licenses.
This could be an action that updates the readme when the package-lock.json file changes. It would create a commit?
Or perhaps a third party service?
https://github.com/davglass/license-checker
https://github.com/RSeidelsohn/license-checker-rseidelsohn
Update ci to automatically update version of the package, create release notes and release the package
This will be only applicable when the package has entered v1
https://github.com/conventional-changelog/conventional-changelog
https://github.com/semantic-release/semantic-release
This depends on #2
Investigate how graphql support can be added.
Ideally this should be a driver.
Things to consider:
relations
type
typings
attributes
When calling .getRawAttributes()
the result will include the relation typehints too
The purely attribute management methods returnin the attributes or subset of them, should not include relation type hints.
- OS: darwin
- Node: v17.4.0
- npm: v8.3.1
Proposed solution is to introduce two new types which are same as Attributes
and AttributeKeys
except Model | undefined
is also excluded.
Consider the following:
import { Model } from '@upfrontjs/framework';
import RelatedModel from './RelatedModel';
export default MyModel extends Model {
public myKey?: string;
public relatedModel?: RelatedModel;
}
Search terms
events
emit
lifecycle
Describe the solution you'd like
Lifecycle events can be added such as saving
, saved
, replicating
, deleting
etc to the package.
Describe how this would benefit the project/others
This would add an additional way to interact with the flow of the model logic.
Note: this will cause the event emitter to not to be tree shakeable as it's always included
Ideas:
delete()
method bot executedDescribe alternatives you've considered
None
This feature depends on #23
casting, datetime
If you have a field like deleted_at
which will be a nullable datetime
casting it will create a js Date with the epoch datetime
when casting a null datetime it should remain null
No response
No response
No response
Search terms
Describe the bug
When 0
or negative value is given to the times
method, it will always return a model. If float is given it's stuck in a loop.
To Reproduce
Steps to reproduce the behavior:
times
methodExpected behavior
The method should throw an error to notify the user of possible bug on their side.
Floats should be rounded.
Workaround
By normally using with valid values.
Once #1 has been done, the commitlint package can be added to enforce commit messages
https://commitlint.js.org/#/
commit messages should be compatible with https://github.com/semantic-release/semantic-release
Look into validating commit messages in gh actions
Search terms
Is your feature request related to a problem? Please describe.
On the model the static factory
method does not take an amount argunet like the helper method
Describe the solution you'd like
Being able to pass the amount
to the factory
method
Describe how this would benefit the project/others
Add consistency with the helper factory
method
Describe alternatives you've considered
Currently you can set the amount by the times()
method on the FactoryBuilder
Set up the properties on the model for the accessors.
If mutator also exists set up the set
method as well.
make sure this isn't a writable property
Search terms
mobile app
react native
native script
web worker
electron
node
deno
Is your feature request related to a problem? Please describe.
The package will not work in the above environments
Describe the solution you'd like
Get the package ready for other environments and tested in other environments.
Describe how this would benefit the project/others
They would be able to use the package in the above mentioned environments
Describe alternatives you've considered
not applicable
Additional context
document
, fetch
are not availbale in the above environments
https://nodejs.org/api/packages.html
Search terms
relations
parent
child
sub class
belongsToMany
hasOne
hasMany
morphMany
morphOne
Is your feature request related to a problem? Please describe.
When using belongsToMany
, hasOne
, hasMany
, morphMany
, morphOne
relation methods on a new instance. That instance might not have the primary key which is accessed druing the above methods.
Describe the solution you'd like
There should be a way to warn the user if the above happens so they become aware when testing their code and have done this mistake.
Describe how this would benefit the project/others
It would make the developer's projects less error prone.
Describe alternatives you've considered
Workaround is not use the relations without the foreign key missing
Additional context
Considered adding the following
/**
* Throw an error if the current model doesn't have the primary key set.
*
* @param {Model} relation
*
* @private
*/
private throwIfAncestorDoesntExists(relation: Model & { _relationType: Relation }): void {
if ((this as unknown as Model).getKey() === undefined) {
throw new LogicException(
'Attempted to use ' + relation._relationType + ' relation method to access the \''
+ relation.getName() + '\' model when \''
+ (this as unknown as Model).getName() + '\' does not have the primary key set.'
);
}
}
and calling it in the above methods after configureRelationType
has been called, but this isn't compatible with the relationDefined
because that calls the relation to ensure correct value has been returned.
Update type to specify value type so getAttributes().myKey
will correctly typehint and not be unknown
Already started the work but is is still causing issues because of the model index signature:
export type Attributes<
M extends HasAttributes = HasAttributes
// string index falls back to the model index signature
> = { [P in keyof M extends AttributeKeys<M> ? keyof M : never]: M[P] };
export type KeysNotMatching<T, V> = KeysNotMatching2<keyof T, T, V>;
// Using this intermediate type to force distribution.
type KeysNotMatching2<Keys extends keyof T, T, V> = Keys extends unknown ? KeyIsAttribute<Keys, T, V> : never;
type KeyIsAttribute<Key extends keyof T, T, V> = T[Key] extends V ? never : Key;
field
property
attribute
default value
constructing
new model
magic access
descriptors
accessor
mutator
constructing
If a model has default values like so:
export default class User extends Model {
public myAttribute: number = 1;
}
when constructing a class with myAttribute
value passed in as 2 new User({ myAttribute: 2 })
key will still be 1
.
Furthermore, casting and mutators will not work either.
Even if there are default values, the attribute should still be set to the passed value when constructing the class.
- OS: darwin
- Node: 17.4.0
- npm: 8.3.1
This is due to js first constructing the parent class and properties defined in the subclass will only be actually set when it comes to constructing the subclass. By this time the property descriptors have already been set up and now being overwritten.
Avoid constructing classes by using the create
method or construct the class and call the fill
with the intended attributes on the instance
No response
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.