Git Product home page Git Product logo

framework's People

Contributors

dependabot[bot] avatar jackgamesftw avatar nandi95 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

framework's Issues

Add testing for types

Search terms

  • TypeDefinition
  • types
  • definition
  • overrides
  • testing

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

Consider adding an event emitter

Search terms

  • events
  • emitter
  • listener
  • on
  • off
  • emit

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

Add Badges

Add the following badges to make some info more accessible:

  • current version
  • testing coverage
  • #5
  • github stars
  • license
  • actual size (if nothing is treeshaken and gzip/brotli compressed)

Typehint accessors on the model

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

Consider adding default values to attributes

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?

  • factories
  • custom user built method
  • an accessor
  • a custom caster

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.

Questions

  • Should these default values be passed to the accessors and should they be cast?
  • How should these default values be defined?

Improve typings

Investigate and implement better typings throughout

  • GlobalConfig.prototype.unset - Omit<T, K> doesn't seems to work. - I believe this is not possible as that would be widening the type not narrow it by changing to a supertype
  • Collection.prototype.pluck - K extends keyof T?
  • Type arguments to the async methods?
  • Overrides to methods with one or more optional arguments if the return is dependent on the argument
  • Figure out a way to get typehints on the instantiated model and method argument where the argument is the attribute name
  • #153
  • #154

Add hidding attributes feature

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:

  • What should happen when one tries to use setAttributes
  • What should happen when sending data to the api (I imagine it should still be there)

Consider adding package exports

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

Add dependency license summary

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

Add GraphQL support

Investigate how graphql support can be added.
Ideally this should be a driver.
Things to consider:

  • endpoints -> single endpoint
  • transforming query builder output into graphql schemas

`Attributes` type unexpectedly includes relation typehints on attribute only methods

Is there an existing issue for this?

  • I have searched the existing issues

Search terms

relations
type
typings
attributes

Current Behavior

When calling .getRawAttributes() the result will include the relation typehints too

Expected Behavior

The purely attribute management methods returnin the attributes or subset of them, should not include relation type hints.

Environment

- OS: darwin
- Node: v17.4.0
- npm: v8.3.1

Anything else?

Proposed solution is to introduce two new types which are same as Attributes and AttributeKeys except Model | undefined is also excluded.

Reproduction

Consider the following:

import { Model } from '@upfrontjs/framework';
import RelatedModel from './RelatedModel';

export default MyModel extends Model {
  public myKey?: string;
  public relatedModel?: RelatedModel;
}

Consider adding lifecycle events

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:

  • The listeners could return a boolean and if false the original logic stops e.g.: deleting hook returns false, no request will be made and and any further logic in the delete() method bot executed
  • The hooks are free to change the passed in argument as it's passed by reference.

Describe alternatives you've considered
None

This feature depends on #23

Nullable datetime casting

Is there an existing issue for this?

  • I have searched the existing issues

Search terms

casting, datetime

Current Behavior

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

Screenshot_2022-10-04_at_18 26 33

Expected Behavior

when casting a null datetime it should remain null

Environment

No response

Anything else?

No response

Reproduction

No response

FactoryBuilder times method with unexpected argument

Search terms

  • FactoryBuilder
  • times
  • negative value
  • float

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:

  1. Pass 0, negative integer or float to the times method
  2. Call any of the compile methods.

Expected 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.

Add `amount` argument to the Model.factory method

Search terms

  • factory
  • times

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 properties based on accessors

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

Cross environment support

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

Parent class's primary key might be missing in relation methods

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.

Improve typehint on `Attributes`

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;

Default values are not overridden when constructing a model

Is there an existing issue for this?

  • I have searched the existing issues

Search terms

field
property
attribute
default value
constructing
new model
magic access
descriptors
accessor
mutator
constructing

Current Behavior

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.

Expected Behavior

Even if there are default values, the attribute should still be set to the passed value when constructing the class.

Environment

- OS: darwin
- Node: 17.4.0
- npm: 8.3.1

Anything else?

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.

Workaround

Avoid constructing classes by using the create method or construct the class and call the fill with the intended attributes on the instance

Reproduction

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.