@jbouduin/hal-rest-client
Advanced tools
Comparing version 0.8.0 to 0.8.1
import { IHalResource } from "./hal-resource.interface"; | ||
import { IHalRestClient } from "./hal-rest-client.interface"; | ||
export declare type HalCacheType = 'Client' | 'Resource'; | ||
export type HalCacheType = 'Client' | 'Resource'; | ||
/** | ||
* a function that accepts the calculated cachekey and returns true if the resource or client may be cached | ||
*/ | ||
export declare type KeyValidatorFn = (key: string) => boolean; | ||
export type KeyValidatorFn = (key: string) => boolean; | ||
export interface IHalCache { | ||
@@ -9,0 +9,0 @@ readonly isEnabled: boolean; |
@@ -7,2 +7,7 @@ "use strict"; | ||
//#endregion | ||
//#region IHalCache properties ---------------------------------------------- | ||
get isEnabled() { | ||
return this._isEnabled; | ||
} | ||
//#endregion | ||
//#region Constructor & C° -------------------------------------------------- | ||
@@ -15,7 +20,2 @@ constructor() { | ||
//#endregion | ||
//#region IHalCache properties ---------------------------------------------- | ||
get isEnabled() { | ||
return this._isEnabled; | ||
} | ||
//#endregion | ||
//#region IHalCach interface methods ---------------------------------------- | ||
@@ -22,0 +22,0 @@ enable() { |
@@ -6,3 +6,3 @@ import 'reflect-metadata'; | ||
*/ | ||
export declare type IHalPropertyOptions<T extends IHalResource> = { | ||
export type IHalPropertyOptions<T extends IHalResource> = { | ||
/** | ||
@@ -9,0 +9,0 @@ * @type {string} - the property name as found in the hal+json |
@@ -113,3 +113,3 @@ import { IJSONSerializer } from "./hal-json-serializer.interface"; | ||
*/ | ||
export declare type IResourceFetchOptions = { | ||
export type IResourceFetchOptions = { | ||
/** | ||
@@ -116,0 +116,0 @@ * @type {boolean=} - Force fetching, even if the resource has been fetched before |
@@ -8,14 +8,2 @@ "use strict"; | ||
//#endregion | ||
//#region Constructor & C° -------------------------------------------------- | ||
constructor(restClient, uri) { | ||
this._restClient = restClient; | ||
this._uri = uri; | ||
this._isLoaded = false; | ||
this.initEnded = false; | ||
this.links = {}; | ||
this.props = {}; | ||
this.settedLinks = new Array(); | ||
this.settedProps = new Array(); | ||
} | ||
//#endregion | ||
//#region IHalResource interface members ------------------------------------ | ||
@@ -41,2 +29,14 @@ get hasChanges() { | ||
//#endregion | ||
//#region Constructor & C° -------------------------------------------------- | ||
constructor(restClient, uri) { | ||
this._restClient = restClient; | ||
this._uri = uri; | ||
this._isLoaded = false; | ||
this.initEnded = false; | ||
this.links = {}; | ||
this.props = {}; | ||
this.settedLinks = new Array(); | ||
this.settedProps = new Array(); | ||
} | ||
//#endregion | ||
//#region IHalResource methods ---------------------------------------------- | ||
@@ -43,0 +43,0 @@ fetch(options) { |
@@ -15,10 +15,2 @@ "use strict"; | ||
//#endregion | ||
//#region Constructor & C° -------------------------------------------------- | ||
constructor(baseURL, options = {}) { | ||
const config = options; | ||
config.baseURL = baseURL; | ||
this.axios = axios_1.default.create(config); | ||
this.setJsonParser(new hal_json_parser_1.JSONParser()); | ||
} | ||
//#endregion | ||
//#region IHalRest client readonly properties ------------------------------- | ||
@@ -35,2 +27,10 @@ get config() { | ||
//#endregion | ||
//#region Constructor & C° -------------------------------------------------- | ||
constructor(baseURL, options = {}) { | ||
const config = options; | ||
config.baseURL = baseURL; | ||
this.axios = axios_1.default.create(config); | ||
this.setJsonParser(new hal_json_parser_1.JSONParser()); | ||
} | ||
//#endregion | ||
//#region IHalRest interface methods ---------------------------------------- | ||
@@ -37,0 +37,0 @@ // TODO 1660 Remove non compliant feature of retrieving an array of HAL-resources |
@@ -8,2 +8,7 @@ "use strict"; | ||
//#endregion | ||
//#region public getter ----------------------------------------------------- | ||
get resourceUri() { | ||
return this.templated ? this.fetchedURI : this.href; | ||
} | ||
//#endregion | ||
//#region Constructor & C° -------------------------------------------------- | ||
@@ -29,7 +34,2 @@ /** | ||
//#endregion | ||
//#region public getter ----------------------------------------------------- | ||
get resourceUri() { | ||
return this.templated ? this.fetchedURI : this.href; | ||
} | ||
//#endregion | ||
//#region public methods ---------------------------------------------------- | ||
@@ -36,0 +36,0 @@ setFetchedUri(fetchedUri) { |
@@ -1,2 +0,2 @@ | ||
export declare type TemplateFillParameters = Record<string, string | number | Array<string | number>>; | ||
export type TemplateFillParameters = Record<string, string | number | Array<string | number>>; | ||
export declare class UriTemplate { | ||
@@ -3,0 +3,0 @@ private readonly template; |
@@ -51,2 +51,5 @@ "use strict"; | ||
class TemplateSegment { | ||
get inErrorState() { | ||
return this.contents.findIndex((part) => part.inErrorState) >= 0; | ||
} | ||
constructor(type, content) { | ||
@@ -60,7 +63,7 @@ this.type = type; | ||
} | ||
} | ||
class UriTemplate { | ||
get inErrorState() { | ||
return this.contents.findIndex((part) => part.inErrorState) >= 0; | ||
return this._inErrorState || this.templateSegments.findIndex((part) => part.inErrorState) >= 0; | ||
} | ||
} | ||
class UriTemplate { | ||
constructor(template) { | ||
@@ -81,5 +84,2 @@ this._inErrorState = false; | ||
} | ||
get inErrorState() { | ||
return this._inErrorState || this.templateSegments.findIndex((part) => part.inErrorState) >= 0; | ||
} | ||
fill(values) { | ||
@@ -137,2 +137,3 @@ let result; | ||
// if (value[key] !== '') => not covered by official tests | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion | ||
return `${this.calculateValue(key, 0, segment.encodeFn)}=${this.calculateValue(value[key], segmentContent.sub, segment.encodeFn)}`; | ||
@@ -139,0 +140,0 @@ }) |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "Hal rest client for typescript", | ||
@@ -38,4 +38,4 @@ "tags": [ | ||
"devDependencies": { | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^17.0.23", | ||
"@types/jest": "^29.2.5", | ||
"@types/node": "^18.11.18", | ||
"@typescript-eslint/eslint-plugin": "^5.10.0", | ||
@@ -47,5 +47,5 @@ "@typescript-eslint/parser": "^5.10.0", | ||
"eslint-plugin-jsdoc": "^39.0.0", | ||
"jest": "^27.4.7", | ||
"jest": "^29.3.1", | ||
"nock": "^13.2.2", | ||
"ts-jest": "^27.1.3", | ||
"ts-jest": "^29.0.3", | ||
"typescript": "^4.5.5" | ||
@@ -52,0 +52,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
144271
1842