Git Product home page Git Product logo

json-reviver's Introduction

Hi there ๐Ÿ‘‹

  • ๐Ÿ”ญ Iโ€™m currently working at Sogexia
  • ๐ŸŒฑ Iโ€™m currently improving my skills on Angular and RxJS
  • I try to improve my Lead Developer skills

Bio

Keen on web development, i practice a lot of PHP over different frameworks like symfony or copix. Even if i also did some #dotNet, #java or #coldfusion, i liked workgin with #meteorjs (a so cool #nodejs platform for server-side Javascript). Front-end is also a new part of my job with #VueJS (v2... not started on v3) and #Angular (v2...16).

In 2014 i did a talk about meteor at #LyonJs organization (in french https://youtu.be/ncLUaIDmCDk?t=1045) , and since the #worldwidemeteorday i leaded a #meteorjs #meetup group in #Lyon for 3 years.

In 2015 i did a talk at the great #BlendWebMixconference in #Lyon with the following subject : Going faster with MeteorJS (in french https://www.youtube.com/watch?v=6f7d_6VgiEM).

And in 2016 i did a talk on #VueJS at #BlendWebMixconference in #Lyon (in french https://www.youtube.com/watch?v=3-pt-7U2pNg).

I'm not a core contributor to open-source, but i try to help them when i can. You can find some of my contributions in symfony (code and docs), but also apiPlatform (mostly issues), clarity from VMWare ...:

If you have a project, contact me, i'm sure i may help you.

Except my work, i'm keen on bicycle (road for speed and mountain bike for nature) and i started small ultra races with the Gravelman Series (350km, ~4000 - 7500D+, in full autonomy). And finally i really love my family and my 3 beautiful daughters that support me all day long.

json-reviver's People

Contributors

fossabot avatar rebolon avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

fossabot

json-reviver's Issues

Should we manage entity with only ID (in an object or a number) ?

When we call an Api, sometimes, it won't return full sub-entity but just the IRIs (this is what does ApiPlatform because it prevents huge data download, or paginations problem in sub-entities).
So when we restore entity, should we allow the developper to ask for an automatic Api call ?

With this mode, we shall return a Promise (or an Observable) that will do all required Api call to retreive entities and transform them into real Entity.

AbstractReviver should be able to auto-select the root node

For instance here is what we have to do:

const oneBook = {
    "book": {
        "title": "Zombies in western culture",
        "serie": {
            "name": "Open Reports Series"
        }
    }
}

const serieReviver = new SerieReviver()
const bookReviver = new BookReviver(serieReviver)

const book = bookReviver.main(oneBook.book)

to get a Book we have to send oneBook.book instead of oneBook.
Maybe we should change the AbstractReviver::main to allow to get automatically the root node:

  • IF the propertyPath is on the root AND this.getNodeName is found in the content HEN take it and send to initFromJon

Need a method to Stringify and prevent Circula reference error

With complex object we can have parent embeded in children like this:

  • book > has authors > that write books so they owned each others (look at the tests you will understand)

But when we alter those object and send them to HTTP API, then we need to JSON.stringify them. At this moment we will have an error coz JSON.stringify is unable to stringify with circular reference

Maybe cycle.js (seen in mozilla dev site) or circular-json might be a quick solution. Circular-json replace duplicated noe by ~ , personllay i would prefer it to remove fully the node

Impossible to use it inside typescript project (but ok in js)

When i try to use the package in a typescript project, it fails:
error TS2307: Cannot find module '@rebolon/json-reviver'

i added a declaration module to fix it but it's not better.
Here is the d.ts file

declare module "@rebolon/json-reviver" {
    export interface EntityInterface {
    }

    export interface ReviverInterface {
        /**
         *
         * @returns {string}
         */
        getNodeName(): string;
        /**
         *
         * @returns EntityInterface
         */
        getNewEntity(): EntityInterface;
        /**
         * @return string
         */
        getIdProperty(): string;
        /**
         * List of accessible properties (int/string/date string converted into date from it's setter per exemple/date/boolean/...)
         *
         * @return array
         */
        getEzPropsName(): Array<string>;
        /**
         * List of properties that contain sub-entities in a Many-To-Many ways
         *
         * @return array
         */
        getManyRelPropsName(): Object;
        /**
         * List of properties that contain sub-entities in a Many-To-One way
         *
         * @return array
         */
        getOneRelPropsName(): Object;
        /**
         * @param jsonOrArray
         * @param propertyPath
         * @return mixed array|EntityInterface
         */
        initFromJson(jsonOrArray: any, propertyPath: any): any;
    }

    export function Accessor(prop: any, entity: EntityInterface, values: Array<any>): EntityInterface;

    export abstract class AbstractReviver implements ReviverInterface {
        /**
         * Default name of the id property
         * @var string
         */
        protected idProperty: string;
        /**
         * main entry point
         * {@inheritdoc}
         */
        main(content: any): any;
        /**
         * @inheritdoc
         */
        getIdProperty(): string;
        /**
         * @param json
         * @return mixed
         * @throws RuntimeException
         * @throws \TypeError
         */
        protected buildEntity(json: any): EntityInterface;
        /**
         * Used for simple property that is not linked to other entities with relation like ManyTo OneTo...
         *
         * @param array json
         * @param EntityInterface entity
         * @return EntityInterface
         */
        private buildWithEzProps(json, entity);
        /**
         * @param array json
         * @param EntityInterface entity
         * @return EntityInterface
         * @throws RuntimeException
         */
        private buildWithManyRelProps(json, entity);
        /**
         * @todo: if json is an object : creation, if it's a string : retreive the entity with doctrine and add it to entity
         *
         * @param array json
         * @param EntityInterface entity
         * @return EntityInterface
         *
         * @throws RuntimeException
         */
        private buildWithOneRelProps(json, entity);
        /**
         * @param jsonOrArray
         * @return mixed
         * @throws ValidationException
         */
        protected checkJsonOrArray(jsonOrArray: any): any;
        /**
         * @param operationsInfo
         * @param methodName
         * @throws RuntimeException
         */
        protected checkOperationsInfo(operationsInfo: any, methodName: any): void;
        /**
         * @param relation
         * @param operationsInfo
         * @return mixed
         */
        protected useRegistry(relation: any, operationsInfo: any): any;
        /**
         * @return string
         */
        protected getPropertyPath(): string;
        /**
         * for ManyToMany reviver, they need to access it
         * @returns {Array<any>}
         */
        protected getPropertyPathContent(): Array<any>;
        /**
         * this is for the tsc compiler because it considers it should implements ReviverInterface methods
         * @returns {Array<string>}
         */
        abstract getEzPropsName(): Array<string>;
        /**
         * this is for the tsc compiler because it considers it should implements ReviverInterface methods
         * @returns {Array<string>}
         */
        abstract getManyRelPropsName(): Object;
        /**
         * this is for the tsc compiler because it considers it should implements ReviverInterface methods
         * @returns {Array<string>}
         */
        abstract getOneRelPropsName(): Object;
        /**
         * this is for the tsc compiler because it considers it should implements ReviverInterface methods
         * @returns {string}
         */
        abstract getNodeName(): string;
        /**
         * this is for the tsc compiler because it considers it should implements ReviverInterface methods
         * @returns {Object}
         */
        abstract getNewEntity(): EntityInterface;
        /**
         * this is for the tsc compiler because it considers it should implements ReviverInterface methods
         * @returns {Object}
         */
        abstract initFromJson(jsonOrArray: any, propertyPath: any): any;
    }

    export abstract class ItemAbstractReviver extends AbstractReviver {
        /**
         * @inheritdoc
         */
        initFromJson(jsonOrArray: any, propertyPathToAdd: any): EntityInterface;
    }

    export abstract class ListAbstractReviver extends AbstractReviver {
        /**
         * @inheritdoc
         */
        initFromJson(jsonOrArray: any, propertyPathToAdd: any): any[];
    }

}

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.