Coder Social home page Coder Social logo

halfred's Issues

Extend `Resource` prototype

I'd really love to be able to extend Resource by adding my own methods to the prototype.

(Related request, though not one I need: Might be nice to be able to provide your own Resource class to the parser.)

Halfred can't parse Resources with null embeds

Describe the bug
When trying to parse a Resource returned from a remote API with null embedded resources, halfred reports an error: TypeError: "embeddedElement is null"

It looks like the problem could be solved by adding an if statement in line 73 of parser.js. I can send the PR if needed.

I understand that having a null value for an embedded resource could not be the best option for a HAL API, but I couldn't find any good argument against having null values. (for example, some uninitialized embed that will be populated later).

To Reproduce
Just parsing a Resource with null values will raise the Error:

{
    "_embedded": {
        "embed": null
    }
}

Expected behavior
The parsing process should accomplish without errors.
When querying for the value of "embed", it should return null.

Node.js (please complete the following information):

  • OS: Ubuntu 18
  • Node.js version: 10.14.1
  • Halfred Version: 1.1.0

Remove console log

Hi,

I'm using traverson with traverson-hal which uses halfred under the hood. My problem is that halfred sends a lot of debugging log the console and there is no way to turn it off. I created an issue for this request in the traverson-hal repo as well: (traverson/traverson-hal#30).

Cheers,

LEo

Is halfred supposed to be used along with traverson?

I am wondering if Resource should be used on top of traverson responses.
Let's say root URL returns something like this:

{
    myItems: {
        href: "http://localhost:8080/api/data/myItems"
    },
}

We want to display myItems (which is an array of object) on front-end.
So we could write a helper method which would:

  1. fetch "root" API object
  2. look for requested resource ("myItems")
  3. return array of objects under that resource

Example implementation:

export const api = traverson
  .from('http://localhost:8080/api/data') // root URL
  .jsonHal();

export function fetchRelation(...args) {
  return api.newRequest()
    .follow(args)
    .getResource().result;
}

export function fetchRelationWithEmbeddedResources(...args) {
  return fetchRelation(...args)
    .then(halfred.parse)
    .then(x => x.allEmbeddedResources());
}

Example usage:
fetchRelationWithEmbeddedResources('myItems')

(notice I am using traverson-promise plugin)

Am I missing something here?

An in-range update of grunt-cli is breaking the build 🚨

The devDependency grunt-cli was updated from 1.3.1 to 1.3.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

grunt-cli is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

An in-range update of husky is breaking the build 🚨

The devDependency husky was updated from 1.2.0 to 1.2.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

husky is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 7 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

How to play Resource with data class in Typescript

May I ask question in Github issues? Because I find the tag traverson doesn't exist in stackoverflow. And no much resource can be googled with keyword "traverson hal typescript".

This is the response body in hal json returned from Spring Data REST backend. There is a root level property page besides _embedded and _links.

{
  "_embedded" : {
    "users" : [ {
      "username" : "apple",
      "lastLoginTime" : "2021-09-22T13:32:55.76",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/users/60857057c116924b2a7affc8"
        },
        "user" : {
          "href" : "http://localhost:8080/users/60857057c116924b2a7affc8"
        }
      }
    }, {
      "username" : "banana",
      "lastLoginTime" : "2021-09-22T13:43:51.145",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/users/6085726fc116924b2a7affc9"
        },
        "user" : {
          "href" : "http://localhost:8080/users/6085726fc116924b2a7affc9"
        }
      }
    } ]
  },
  "_links" : {
    "first" : {
      "href" : "http://localhost:8080/users?page=0&size=2"
    },
    "self" : {
      "href" : "http://localhost:8080/users?page=0&size=2"
    },
    "next" : {
      "href" : "http://localhost:8080/users?page=1&size=2"
    },
    "last" : {
      "href" : "http://localhost:8080/users?page=86&size=2"
    },
    "profile" : {
      "href" : "http://localhost:8080/profile/users"
    },
    "search" : {
      "href" : "http://localhost:8080/users/search"
    }
  },
  "page" : {
    "size" : 2,
    "totalElements" : 173,
    "totalPages" : 87,
    "number" : 0
  }
}

Traverson code.

traverson
  .from('http://localhost:8080/users')
  .jsonHal()
  .getResource((error, doc) => {
    if (error) {
      console.error(error);
    } else {
      let resource = halfred.parse(doc);  // type of halfred.Resource
      console.info('resource=', resource);
      console.info('page=', resource.page);  // error Property 'page' does not exist on type 'Resource'
      let users = resource.embeddedArray('users');  // type of Resource[]
      let user0 = users[0];  // type of halfred.Resource
      console.info('user0.username=', user0.username);  // error Property 'username' does not exist on type 'Resource'
    }
  });

data class

// User.ts
export default class User {
  constructor(readonly username: string, readonly lastLoginTime: date);
}

Question 1
resource.embeddedArray('users') returns an array of Resource. Should I convert to a data class User or keep using the type Resource? How to convert Resource to class User in Typescript?

Question 2
If I keep using the type Resource and access some data such as username, even though the username value is logged to console, I get IDE error "Property 'username' does not exist on type 'Resource'". Can anyone give me some advice?

It would be great if some traverson hal typescript example can be provided.

An in-range update of grunt is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye πŸ‘‹ and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The devDependency grunt was updated from 1.0.4 to 1.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

grunt is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for v1.1.0
  • Update to mkdirp ~1.0.3
  • Only support versions of Node >= 8
Commits

The new version differs by 8 commits.

  • d5cdac0 Merge pull request #1706 from gruntjs/tag-neew
  • 4674c59 v1.1.0
  • 6124409 Merge pull request #1705 from gruntjs/mkdirp-update
  • 0a66968 Fix up Buffer usage
  • 4bfa98e Support versions of node >= 8
  • f1898eb Update to mkdirp ~1.0.3
  • 75da17b HTTPS link to gruntjs.com (#1683)
  • 6795d31 Update js-yaml dependecy to ~3.13.1 (#1680)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

major release

once we iron out any remaining kinks in the release process, we should release a major version that officially drops support for bower and any versions of node that are no longer officially supported. is there anything else that we think is worth dropping/changing at the same time?

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.