GithubHelp home page GithubHelp logo

dinevillar / adonis-json-api-serializer Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 3.0 97 KB

An AdonisJS framework wrapper for https://github.com/danivek/json-api-serializer to have API response formatted according to the JSON API Specification (http://jsonapi.org/)

License: MIT License

JavaScript 100.00%
json-api adonisjs-json-api adonisjs json-api-serializer rest-api adonis-framework adonis-serializer

adonis-json-api-serializer's People

Contributors

dawidjaniga avatar dinevillar avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

adonis-json-api-serializer's Issues

Generated HATEOAS links broken

Hi. Thanks for this project because it helps a lot of devs out there including me.

However, I am getting broken pagination link. Not really sure what I am missing since I have followed the README. If anyone can help, much appreciated!

Here is the generated links:

...
    "links": {
        "self": "/my-resource?page%5Bnumber%5D=1&page%5Bsize%5D=100",
        "first": "/my-resource?page%5Bnumber%5D=1&page%5Bsize%5D=100",
        "prev": "/my-resource?page%5Bnumber%5D=1&page%5Bsize%5D=100",
        "next": "/my-resource?page%5Bnumber%5D=1&page%5Bsize%5D=100",
        "last": "/my-resource?page%5Bnumber%5D=1&page%5Bsize%5D=100"
    },
    "data": [
        {
....

JsonApi service singleton and parseError

Maybe I am not understanding something, so I apologize ahead.

But it appears that JsonApi aka JsonApi/Service/JsonApiService is registered as a singleton. Which means there is only one instance of this service for the whole app. But the service singleton keeps state via pushError/jsonApiErrors. This means that there is potential for race condition and errors of one client leaking to another.

'limit' field must be numeric

Contrary to my previous opened issue, where I said it was working fine, I just got some errors.
Did this package ever get tested combined with https://github.com/duyluonglc/lucid-mongo ?

My request:

/users?page[number]=1&page[size]=1000

config/jsonApi.js:

module.exports = {
  globalOptions: {
    convertCase: 'snake_case',
    unconvertCase: 'camelCase',
  },
  registry: {
    user: {
      model: 'App/Models/User',
      structure: {
        links: {
          self: data => `/users/${data._id}`,
        },
        topLevelLinks: {
          self: '/users',
        },
      },
    },
  },
};

UserController.js:

  async list({ request }) {
    const results = await JsonApiRecordBrowser
      .model(User)
      .request(request.get())
      .paginateOrFetch();
    return results;
  }

response:

{
    "error": {
        "message": "Failed to parse: { find: \"users\", filter: {}, limit: \"1000\", returnKey: false, showRecordId: false }. 'limit' field must be numeric.",
        "name": "MongoError",
        "status": 500,
        "frames": [
            {
                "file": "node_modules/mongodb-core/lib/cursor.js",
                "method": "queryCallback",
                "line": 244,
                "column": 25,
                "context": {
                    "start": 239,
                    "pre": "        result.documents[0]['errmsg'] ||\n        Array.isArray(result.documents[0].result))\n    ) {\n      // We have a an error document return the error\n      if (result.documents[0]['$err'] || result.documents[0]['errmsg']) {",
                    "line": "        return callback(new MongoError(result.documents[0]), null);",
                    "post": "      }\n\n      // We have a cursor document\n      if (result.documents[0].cursor != null && typeof result.documents[0].cursor !== 'string') {\n        var id = result.documents[0].cursor.id;"
                },
                "isModule": true,
                "isNative": false,
                "isApp": false
            },
            {
                "file": "node_modules/mongodb-core/lib/connection/pool.js",
                "method": null,
                "line": 544,
                "column": 18,
                "context": {
                    "start": 539,
                    "pre": "\n    function handleOperationCallback(self, cb, err, result) {\n      // No domain enabled\n      if (!self.options.domainsEnabled) {\n        return process.nextTick(function() {",
                    "line": "          return cb(err, result);",
                    "post": "        });\n      }\n\n      // Domain enabled just call the callback\n      cb(err, result);"
                },
                "isModule": true,
                "isNative": false,
                "isApp": false
            },
            {
                "file": "internal/process/next_tick.js",
                "filePath": "internal/process/next_tick.js",
                "method": "_combinedTickCallback",
                "line": 131,
                "column": 7,
                "context": {},
                "isModule": false,
                "isNative": true,
                "isApp": false
            },
            {
                "file": "internal/process/next_tick.js",
                "filePath": "internal/process/next_tick.js",
                "method": "process._tickCallback",
                "line": 180,
                "column": 9,
                "context": {},
                "isModule": false,
                "isNative": true,
                "isApp": false
            },
            {
                "file": "node_modules/mquery/lib/mquery.js",
                "method": "Query.then",
                "line": 2775,
                "column": 17,
                "context": {
                    "start": 2770,
                    "pre": " * @api public\n */\n\nQuery.prototype.then = function(resolve, reject) {\n  var self = this;",
                    "line": "  var promise = new Query.Promise(function(success, error) {",
                    "post": "    self.exec(function(err, val) {\n      if (err) error(err);\n      else success(val);\n      self = success = error = null;\n    });"
                },
                "isModule": true,
                "isNative": false,
                "isApp": false
            }
        ]
    }
}

Typo in docs

Hey great job with the package. I am currently using it with AdonisJS v4.1 with MongoDB and it's working fine.

I have noticed there is a typo on your README.md, or maybe it's something I had to change to work with the https://github.com/duyluonglc/lucid-mongo package...

In models, where it says...

static get Serializer() {
    return 'JsonApi/Serializer/LucidSerializer';
};

I changed to:

const LucidSerializer = use('JsonApi/Serializer/LucidSerializer');

...

static get Serializer() {
    return LucidSerializer;
};

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.