traverson / halfred Goto Github PK
View Code? Open in Web Editor NEWA parser for application/hal+json
License: MIT License
A parser for application/hal+json
License: MIT License
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.)
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):
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
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:
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?
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.
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
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.
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 π¦π
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.
The new version differs by 7 commits.
73c0ad7
1.2.1
cb5fd3b
Update CHANGELOG.md
c0e5f5e
Update package-lock.json
aabd390
Fix whitespace in project folder name issue (#423)
d43f813
Update README.md
f0fcc21
Update README.md
4897994
npm upgrade
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
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.
βοΈ 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
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.
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
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
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.
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 π¦π
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?
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.