npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-data-link-traversal

v0.3.0

Published

An ember-data adapter and utility for link relation APIs. This adapter has no initial knowledge on resource URLs and gathers it by following from an api entrypoint.

Downloads

9

Readme

Ember-data-link-traversal

An ember-data adapter and utility for link relation APIs. This adapter has no initial knowledge on resource URLs and gathers it by following from an api entrypoint.

The adapter is serializer independent and requires JSON API Links links (see "Compatibility" for more information).

Build
Status Code Climate

Compatibility

ember-data-link-traversal supports ember data and ember data 1.13.4+. Currently it requires ember-data-hal-9000 because of the way it stores document links. By overwriting the ember-data-link-traversal/traversal extractRecordLinks method and let it return the record links, it should work with any other serializer but that isn't currently tested.

Usage

Install ember-data-link-traversal:

  • npm install --save-dev ember-data-link-traversal
  • Extend your application adapter from the Traversal adapter, e.g.:
// app/adapters/application.js

import TraversalAdapter from "ember-data-traversal-adapter/adapter";
export default TraversalAdapter.extend();
  • Extend your application serializer from the HAL-9000 serializer, e.g.:
// app/serializers/application.js

import HalSerializer from "ember-data-traversal-adapter/serializer";
export default HalSerializer.extend();

Tested with Ember release, beta and canary channels.

Entrypoint

You need an ember model that represents your api entrypoint with all corresponding links. In the test app the entrypoint model is called root.

Link following

  • import {follow} from 'ember-data-link-traversal/traversal'
  • follow resolves a promise with a found record (like findRecord or findAll)
  • start at your api entrypoint by using a links key string as the second method parameter
follow(store, 'user', 'family').then(familyRecord => {

});
  • start from an already loaded record by using the record as the second parameter
follow(store, userRecord, 'family').then(familyRecord => {

});
  • provide an object that is expanded in possible templated link uris
  • the object will be expanded in each template uri link
// user._links = {pets: {href: '/foo{?onlyCats}', templated: true}}
follow(store, 'user', 'pets', {onlyCats: true}).then(petCatsCollection => {

});

Creating new records

  • import {save} from 'ember-data-link-traversal/traversal'
  • follows a given path to get a link to POST the locally created record
let newThread = store.createRecord('thread', {
  title: 'Big Brother'
});

// follow entrypoint, user, threads links and POST the new user json
save(store, 'user', 'threads', newThread).then(createdThread => {

});

Saving and deleting existing records

  • uses ember data existing api

Pagination

  • pagination in hal should done by following links on a collection response
{
  "_links": {
    "next": { "href": "api.tld/threads?page=2" },
    "self": { "href": "api.tld/threads{?page}" }
  },
  _embedded: […]
}
  • the followUrl(store, modelClass, url, templateParams = {}) method allows you to load a given url
follow(store, user, 'threads').then(threads => 
  followUrl(store, threads.type, threads.get('meta.links.next')).then(nextPageThreads => {
      …
  })
})

Running Tests

  • npm test # test all scenarios in config/ember-try.js
  • ember try <scenario-name> test --server # test a specific scenario