Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

be-hippo

Package Overview
Dependencies
Maintainers
48
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

be-hippo - npm Package Compare versions

Comparing version 12.0.0 to 12.1.0

.tern-project

2

index.d.ts

@@ -54,3 +54,3 @@ declare module 'be-hippo' {

export class Client {
constructor(apiRoot: string, options?: ClientOptions);
constructor(apiRoot: KeyValuePair | string, options?: ClientOptions);

@@ -57,0 +57,0 @@ walk(...shortNames: Connection[]): Promise<Resource>;

{
"name": "be-hippo",
"version": "12.0.0",
"version": "12.1.0",
"description": "A PropositionH hypermedia consumer",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -27,6 +27,12 @@ import xhr from './xhr';

this._apiRoot = apiRoot;
this._options = options;
this._traversals = {};
this._nodes = {};
if (typeof apiRoot === 'object') {
this._backfillTraversals(apiRoot);
}
else {
this._apiRoot = apiRoot;
this._traversals = {};
this._nodes = {};
}
}

@@ -64,2 +70,6 @@

_getRootDescriptor() {
if (this._nodes[this._apiRoot]) {
return Promise.resolve(this._nodes[this._apiRoot]);
}
return this._getDescriptor(this._apiRoot)

@@ -69,3 +79,3 @@ .catch(() => {

});
};
}

@@ -95,2 +105,30 @@ _getDescriptor(uri) {

}
_backfillTraversals(shortnameMap) {
this._apiRoot = shortnameMap.self;
this._traversals = {};
this._nodes = {};
Object.entries(shortnameMap)
.forEach(([shortname, uri]) => {
let traversalUri;
let descriptor;
if (typeof uri === 'string') {
traversalUri = uri;
descriptor = {
self: {
href: uri,
},
};
}
else {
traversalUri = uri.self.href;
descriptor = uri;
}
this._traversals[shortname] = traversalUri;
this._nodes[traversalUri] = new Resource({ _links: descriptor }, this._options.requestOptions);
});
}
}

@@ -7,3 +7,3 @@ import Uri from './uri';

const RESERVED = '(?:[' + ALL + ']|%[a-fA-F0-9][a-fA-F0-9])';
const UNRESERVED = '(?:[#{' + UNRESERVED + '}]|%[a-fA-F0-9][a-fA-F0-9])'; // eslint-disable-line no-use-before-define
const UNRESERVED = '(?:[#{' + Uri.CHAR_CLASSES.UNRESERVED + '}]|%[a-fA-F0-9][a-fA-F0-9])';
const VARIABLE = '(?:' + VAR_CHAR + '(?:\\.?' + VAR_CHAR + ')*)';

@@ -10,0 +10,0 @@ const VARSPEC = '(?:(' + VARIABLE + ')(\\*|:\\d+)?)';

@@ -339,3 +339,99 @@ import Client from 'src/client';

});
describe('when called on a client preloaded with traversals', function() {
beforeEach(function() {
this.client = new Client({
self: '/v1/api',
foo: '/v1/foo',
objResource: {
self: {
href: '/v1/obj{/id}',
accept: 'application/json',
},
},
objWithSubResource: {
self: {
href: '/v1/objwithsub{/id}',
subresource: '/v1/sub',
},
},
templated: '/v1/foo{?id,name}',
});
});
describe('when given a shortname', function() {
it('does not make a request to get the descriptor data', function() {
spyOn(this.client, '_getDescriptor');
return this.client.walk('foo')
.then(() => {
expect(this.client._getDescriptor).not.toHaveBeenCalled();
});
});
it('returns a resolved promise', function(done) {
this.client.walk('foo')
.then((resource) => {
expect(resource).toEqual(new Resource({
_links: {
self: {
href: '/v1/foo',
},
},
}));
})
.then(done, done.fail);
});
});
describe('when given a shortname that was initialized with an object', function() {
it('does not make a request to get the descriptor data', function() {
spyOn(this.client, '_getDescriptor');
return this.client.walk('objResource')
.then(() => {
expect(this.client._getDescriptor).not.toHaveBeenCalled();
});
});
it('returns a resolved promise', function() {
return this.client.walk('objResource')
.then((resource) => {
expect(resource).toEqual(new Resource({
_links: {
self: {
href: '/v1/obj{/id}',
accept: 'application/json',
},
},
}));
});
});
});
describe('when given a shortname object', function() {
it('resolves with the resource specified by the shortname', function() {
return this.client.walk({ name: 'templated', data: { var: 5 } })
.then((resource) => {
expect(resource).toEqual(new Resource({
_links: {
self: {
href: '/v1/foo{?id,name}',
},
},
}));
});
});
});
describe('when given a shortname that is not present in the initial traversals', function() {
it('returns a promise that rejects', function() {
return this.client.walk('fakepath')
.catch((e) => {
expect(e.message).toMatch(/Unknown connection/);
});
});
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc