api-def 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/cjs/Api.d.ts +35 -35
  2. package/cjs/Api.js +140 -144
  3. package/cjs/ApiConstants.d.ts +58 -58
  4. package/cjs/ApiConstants.js +55 -55
  5. package/cjs/ApiTypes.d.ts +103 -103
  6. package/cjs/ApiTypes.js +4 -4
  7. package/cjs/ApiUtils.d.ts +6 -6
  8. package/cjs/ApiUtils.js +51 -53
  9. package/cjs/Endpoint.d.ts +52 -52
  10. package/cjs/Endpoint.js +104 -108
  11. package/cjs/EndpointBuilder.d.ts +14 -14
  12. package/cjs/EndpointBuilder.js +46 -46
  13. package/cjs/MockingTypes.d.ts +30 -30
  14. package/cjs/MockingTypes.js +2 -2
  15. package/cjs/QueryHandling.d.ts +3 -3
  16. package/cjs/QueryHandling.js +24 -24
  17. package/cjs/RequestConfig.d.ts +2 -2
  18. package/cjs/RequestConfig.js +74 -74
  19. package/cjs/RequestContext.d.ts +48 -48
  20. package/cjs/RequestContext.js +235 -238
  21. package/cjs/RequestError.d.ts +30 -30
  22. package/cjs/RequestError.js +47 -47
  23. package/cjs/Requester.d.ts +3 -3
  24. package/cjs/Requester.js +335 -336
  25. package/cjs/TextDecoding.d.ts +1 -1
  26. package/cjs/TextDecoding.js +152 -139
  27. package/cjs/UtilTypes.d.ts +5 -5
  28. package/cjs/UtilTypes.js +2 -2
  29. package/cjs/Utils.d.ts +15 -15
  30. package/cjs/Utils.js +79 -77
  31. package/cjs/Validation.d.ts +8 -8
  32. package/cjs/Validation.js +2 -2
  33. package/cjs/backend/AxiosRequestBackend.d.ts +13 -13
  34. package/cjs/backend/AxiosRequestBackend.js +99 -99
  35. package/cjs/backend/FetchRequestBackend.d.ts +15 -15
  36. package/cjs/backend/FetchRequestBackend.js +202 -202
  37. package/cjs/backend/MockRequestBackend.d.ts +11 -11
  38. package/cjs/backend/MockRequestBackend.js +164 -164
  39. package/cjs/backend/RequestBackend.d.ts +19 -19
  40. package/cjs/backend/RequestBackend.js +2 -2
  41. package/cjs/cache/CacheBackend.d.ts +6 -6
  42. package/cjs/cache/CacheBackend.js +2 -2
  43. package/cjs/cache/Caching.d.ts +10 -10
  44. package/cjs/cache/Caching.js +88 -88
  45. package/cjs/cache/LocalForageCacheBackend.d.ts +9 -9
  46. package/cjs/cache/LocalForageCacheBackend.js +24 -24
  47. package/cjs/cache/LocalStorageCacheBackend.d.ts +7 -7
  48. package/cjs/cache/LocalStorageCacheBackend.js +77 -77
  49. package/cjs/index.d.ts +13 -13
  50. package/cjs/index.js +41 -41
  51. package/cjs/middleware/CacheMiddleware.d.ts +7 -7
  52. package/cjs/middleware/CacheMiddleware.js +107 -107
  53. package/cjs/middleware/LoggingMiddleware.d.ts +6 -6
  54. package/cjs/middleware/LoggingMiddleware.js +82 -88
  55. package/cjs/util/retry/index.d.ts +3 -3
  56. package/cjs/util/retry/index.js +52 -52
  57. package/cjs/util/retry/lib/retry.d.ts +3 -3
  58. package/cjs/util/retry/lib/retry.js +50 -54
  59. package/cjs/util/retry/lib/retryOperation.d.ts +27 -27
  60. package/cjs/util/retry/lib/retryOperation.js +130 -134
  61. package/esm/Api.d.ts +35 -35
  62. package/esm/Api.js +92 -98
  63. package/esm/ApiConstants.d.ts +58 -58
  64. package/esm/ApiConstants.js +52 -52
  65. package/esm/ApiTypes.d.ts +103 -103
  66. package/esm/ApiTypes.js +1 -1
  67. package/esm/ApiUtils.d.ts +6 -6
  68. package/esm/ApiUtils.js +43 -45
  69. package/esm/Endpoint.d.ts +52 -52
  70. package/esm/Endpoint.js +66 -70
  71. package/esm/EndpointBuilder.d.ts +14 -14
  72. package/esm/EndpointBuilder.js +31 -31
  73. package/esm/MockingTypes.d.ts +30 -30
  74. package/esm/MockingTypes.js +1 -1
  75. package/esm/QueryHandling.d.ts +3 -3
  76. package/esm/QueryHandling.js +19 -19
  77. package/esm/RequestConfig.d.ts +2 -2
  78. package/esm/RequestConfig.js +56 -56
  79. package/esm/RequestContext.d.ts +48 -48
  80. package/esm/RequestContext.js +167 -170
  81. package/esm/RequestError.d.ts +30 -30
  82. package/esm/RequestError.js +42 -42
  83. package/esm/Requester.d.ts +3 -3
  84. package/esm/Requester.js +252 -253
  85. package/esm/TextDecoding.d.ts +1 -1
  86. package/esm/TextDecoding.js +148 -135
  87. package/esm/UtilTypes.d.ts +5 -5
  88. package/esm/UtilTypes.js +1 -1
  89. package/esm/Utils.d.ts +15 -15
  90. package/esm/Utils.js +66 -68
  91. package/esm/Validation.d.ts +8 -8
  92. package/esm/Validation.js +1 -1
  93. package/esm/backend/AxiosRequestBackend.d.ts +13 -13
  94. package/esm/backend/AxiosRequestBackend.js +62 -62
  95. package/esm/backend/FetchRequestBackend.d.ts +15 -15
  96. package/esm/backend/FetchRequestBackend.js +136 -136
  97. package/esm/backend/MockRequestBackend.d.ts +11 -11
  98. package/esm/backend/MockRequestBackend.js +116 -116
  99. package/esm/backend/RequestBackend.d.ts +19 -19
  100. package/esm/backend/RequestBackend.js +1 -1
  101. package/esm/cache/CacheBackend.d.ts +6 -6
  102. package/esm/cache/CacheBackend.js +1 -1
  103. package/esm/cache/Caching.d.ts +10 -10
  104. package/esm/cache/Caching.js +39 -39
  105. package/esm/cache/LocalForageCacheBackend.d.ts +9 -9
  106. package/esm/cache/LocalForageCacheBackend.js +20 -20
  107. package/esm/cache/LocalStorageCacheBackend.d.ts +7 -7
  108. package/esm/cache/LocalStorageCacheBackend.js +32 -32
  109. package/esm/index.d.ts +13 -13
  110. package/esm/index.js +14 -15
  111. package/esm/middleware/CacheMiddleware.d.ts +7 -7
  112. package/esm/middleware/CacheMiddleware.js +58 -58
  113. package/esm/middleware/LoggingMiddleware.d.ts +6 -6
  114. package/esm/middleware/LoggingMiddleware.js +77 -83
  115. package/esm/util/retry/index.d.ts +3 -3
  116. package/esm/util/retry/index.js +50 -50
  117. package/esm/util/retry/lib/retry.d.ts +3 -3
  118. package/esm/util/retry/lib/retry.js +35 -39
  119. package/esm/util/retry/lib/retryOperation.d.ts +27 -27
  120. package/esm/util/retry/lib/retryOperation.js +126 -132
  121. package/package.json +12 -32
@@ -1,116 +1,116 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import * as Utils from "../Utils";
11
- import { delayThenReturn, randInt } from "../Utils";
12
- import { convertToRequestError, RequestErrorCode } from "../RequestError";
13
- export default class MockRequestBackend {
14
- constructor() {
15
- this.id = "mock";
16
- }
17
- convertResponse(context, response, error) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- return response;
20
- });
21
- }
22
- extractResponseFromError(error) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- if ("response" in error) {
25
- const fetchError = error;
26
- return fetchError.response ? fetchError.response : null;
27
- }
28
- return undefined;
29
- });
30
- }
31
- runRequest(context) {
32
- var _a, _b, _c, _d;
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const mockingFunc = (_a = context.mocking) === null || _a === void 0 ? void 0 : _a.handler;
35
- if (!mockingFunc) {
36
- throw convertToRequestError({
37
- error: new Error("[api-def] Attempted to run mocked request without mocking function"),
38
- code: RequestErrorCode.REQUEST_INVALID_CONFIG,
39
- context,
40
- });
41
- }
42
- const req = {
43
- body: context.getParsedBody(),
44
- params: (_b = context.computedConfig.params) !== null && _b !== void 0 ? _b : {},
45
- query: context.computedConfig.queryObject,
46
- headers: (_c = context.computedConfig.headers) !== null && _c !== void 0 ? _c : {},
47
- url: context.requestUrl.toString(),
48
- };
49
- const res = {
50
- statusCode: -1,
51
- headers: {},
52
- response: undefined,
53
- status(statusCode) {
54
- res.statusCode = statusCode;
55
- return res;
56
- },
57
- send(response) {
58
- res.response = response;
59
- if (response && typeof response === "object") {
60
- res.headers["Content-Type"] = "application/json";
61
- }
62
- return res;
63
- },
64
- };
65
- if ((_d = context.mocking) === null || _d === void 0 ? void 0 : _d.delay) {
66
- const delay = context.mocking.delay;
67
- let delayMs;
68
- if (typeof delay === "number") {
69
- delayMs = delay;
70
- }
71
- else {
72
- const [min, max] = delay;
73
- if (min > max) {
74
- throw convertToRequestError({
75
- error: new Error("[api-def] Min delay cannot be greater than max delay"),
76
- code: RequestErrorCode.REQUEST_INVALID_CONFIG,
77
- context,
78
- });
79
- }
80
- delayMs = randInt(min, max);
81
- }
82
- yield delayThenReturn(yield mockingFunc(req, res), delayMs);
83
- }
84
- else {
85
- yield mockingFunc(req, res);
86
- }
87
- if (res.response === undefined) {
88
- throw convertToRequestError({
89
- error: new Error("[api-def] Mocked API did not respond"),
90
- code: RequestErrorCode.REQUEST_INVALID_CONFIG,
91
- context,
92
- });
93
- }
94
- const parsedHeaders = Object.keys(res.headers).reduce((parsedHeaders, key) => {
95
- parsedHeaders[key] = res.headers[key].toString();
96
- return parsedHeaders;
97
- }, {});
98
- return {
99
- url: context.requestUrl.href,
100
- method: context.method,
101
- headers: parsedHeaders,
102
- data: res.response,
103
- status: res.statusCode,
104
- };
105
- });
106
- }
107
- makeRequest(context) {
108
- return {
109
- canceler: Utils.noop,
110
- promise: this.runRequest(context),
111
- };
112
- }
113
- getErrorInfo(error, response) {
114
- return undefined;
115
- }
116
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { RequestErrorCode, convertToRequestError } from "../RequestError";
11
+ import * as Utils from "../Utils";
12
+ import { delayThenReturn, randInt } from "../Utils";
13
+ export default class MockRequestBackend {
14
+ constructor() {
15
+ this.id = "mock";
16
+ }
17
+ convertResponse(context, response, error) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ return response;
20
+ });
21
+ }
22
+ extractResponseFromError(error) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ if ("response" in error) {
25
+ const fetchError = error;
26
+ return fetchError.response ? fetchError.response : null;
27
+ }
28
+ return undefined;
29
+ });
30
+ }
31
+ runRequest(context) {
32
+ var _a, _b, _c, _d;
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const mockingFunc = (_a = context.mocking) === null || _a === void 0 ? void 0 : _a.handler;
35
+ if (!mockingFunc) {
36
+ throw convertToRequestError({
37
+ error: new Error("[api-def] Attempted to run mocked request without mocking function"),
38
+ code: RequestErrorCode.REQUEST_INVALID_CONFIG,
39
+ context,
40
+ });
41
+ }
42
+ const req = {
43
+ body: context.getParsedBody(),
44
+ params: (_b = context.computedConfig.params) !== null && _b !== void 0 ? _b : {},
45
+ query: context.computedConfig.queryObject,
46
+ headers: (_c = context.computedConfig.headers) !== null && _c !== void 0 ? _c : {},
47
+ url: context.requestUrl.toString(),
48
+ };
49
+ const res = {
50
+ statusCode: -1,
51
+ headers: {},
52
+ response: undefined,
53
+ status(statusCode) {
54
+ res.statusCode = statusCode;
55
+ return res;
56
+ },
57
+ send(response) {
58
+ res.response = response;
59
+ if (response && typeof response === "object") {
60
+ res.headers["Content-Type"] = "application/json";
61
+ }
62
+ return res;
63
+ },
64
+ };
65
+ if ((_d = context.mocking) === null || _d === void 0 ? void 0 : _d.delay) {
66
+ const delay = context.mocking.delay;
67
+ let delayMs;
68
+ if (typeof delay === "number") {
69
+ delayMs = delay;
70
+ }
71
+ else {
72
+ const [min, max] = delay;
73
+ if (min > max) {
74
+ throw convertToRequestError({
75
+ error: new Error("[api-def] Min delay cannot be greater than max delay"),
76
+ code: RequestErrorCode.REQUEST_INVALID_CONFIG,
77
+ context,
78
+ });
79
+ }
80
+ delayMs = randInt(min, max);
81
+ }
82
+ yield delayThenReturn(yield mockingFunc(req, res), delayMs);
83
+ }
84
+ else {
85
+ yield mockingFunc(req, res);
86
+ }
87
+ if (res.response === undefined) {
88
+ throw convertToRequestError({
89
+ error: new Error("[api-def] Mocked API did not respond"),
90
+ code: RequestErrorCode.REQUEST_INVALID_CONFIG,
91
+ context,
92
+ });
93
+ }
94
+ const parsedHeaders = Object.keys(res.headers).reduce((parsedHeaders, key) => {
95
+ parsedHeaders[key] = res.headers[key].toString();
96
+ return parsedHeaders;
97
+ }, {});
98
+ return {
99
+ url: context.requestUrl.href,
100
+ method: context.method,
101
+ headers: parsedHeaders,
102
+ data: res.response,
103
+ status: res.statusCode,
104
+ };
105
+ });
106
+ }
107
+ makeRequest(context) {
108
+ return {
109
+ canceler: Utils.noop,
110
+ promise: this.runRequest(context),
111
+ };
112
+ }
113
+ getErrorInfo(error, response) {
114
+ return undefined;
115
+ }
116
+ }
@@ -1,19 +1,19 @@
1
- import RequestContext from "../RequestContext";
2
- import { ApiResponse } from "../ApiTypes";
3
- export interface RequestOperation<R> {
4
- promise: Promise<R>;
5
- canceler: () => void;
6
- }
7
- export interface RequestBackendErrorInfo {
8
- code: string;
9
- }
10
- export declare type ConvertedApiResponse<T> = ApiResponse<T> & {
11
- __lowercaseHeaders?: any;
12
- };
13
- export default interface RequestBackend<R = any> {
14
- readonly id: string;
15
- makeRequest(context: RequestContext): RequestOperation<R>;
16
- convertResponse<T>(context: RequestContext, response: R): Promise<ConvertedApiResponse<T>>;
17
- extractResponseFromError(error: Error): Promise<R | null | undefined>;
18
- getErrorInfo(error: Error, response: ApiResponse | undefined | null): RequestBackendErrorInfo | undefined;
19
- }
1
+ import { ApiResponse } from "../ApiTypes";
2
+ import RequestContext from "../RequestContext";
3
+ export interface RequestOperation<R> {
4
+ promise: Promise<R>;
5
+ canceler: () => void;
6
+ }
7
+ export interface RequestBackendErrorInfo {
8
+ code: string;
9
+ }
10
+ export type ConvertedApiResponse<T> = ApiResponse<T> & {
11
+ __lowercaseHeaders?: any;
12
+ };
13
+ export default interface RequestBackend<R = any> {
14
+ readonly id: string;
15
+ makeRequest(context: RequestContext): RequestOperation<R>;
16
+ convertResponse<T>(context: RequestContext, response: R): Promise<ConvertedApiResponse<T>>;
17
+ extractResponseFromError(error: Error): Promise<R | null | undefined>;
18
+ getErrorInfo(error: Error, response: ApiResponse | undefined | null): RequestBackendErrorInfo | undefined;
19
+ }
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,6 +1,6 @@
1
- export interface CacheBackend {
2
- removeItem(key: string): Promise<void>;
3
- setItem<T>(key: string, value: T): Promise<void>;
4
- getItem<T>(key: string): Promise<T | null>;
5
- clear(): Promise<void>;
6
- }
1
+ export interface CacheBackend {
2
+ removeItem(key: string): Promise<void>;
3
+ setItem<T>(key: string, value: T): Promise<void>;
4
+ getItem<T>(key: string): Promise<T | null>;
5
+ clear(): Promise<void>;
6
+ }
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,10 +1,10 @@
1
- import { CacheBackend } from "./CacheBackend";
2
- export declare const setCacheBackend: (backend: CacheBackend) => void;
3
- export declare const DEFAULT_CACHE_EXPIRY: number;
4
- export declare const clearCache: () => Promise<void>;
5
- export interface CacheEntry {
6
- data: any;
7
- expiry: number | null;
8
- }
9
- export declare const setCachedItem: <T>(key: string, value: T, expiry?: number) => Promise<T>;
10
- export declare const getCachedItem: <T = any>(key: string) => Promise<T | undefined>;
1
+ import { CacheBackend } from "./CacheBackend";
2
+ export declare const setCacheBackend: (backend: CacheBackend) => void;
3
+ export declare const DEFAULT_CACHE_EXPIRY: number;
4
+ export declare const clearCache: () => Promise<void>;
5
+ export interface CacheEntry {
6
+ data: any;
7
+ expiry: number | null;
8
+ }
9
+ export declare const setCachedItem: <T>(key: string, value: T, expiry?: number) => Promise<T>;
10
+ export declare const getCachedItem: <T = any>(key: string) => Promise<T | undefined>;
@@ -1,39 +1,39 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import LocalStorageCacheBackend from "./LocalStorageCacheBackend";
11
- let cacheBackend = new LocalStorageCacheBackend();
12
- export const setCacheBackend = (backend) => {
13
- cacheBackend = backend;
14
- };
15
- export const DEFAULT_CACHE_EXPIRY = /* 15 mins */ 60 * 1000 * 15;
16
- export const clearCache = () => {
17
- return cacheBackend.clear();
18
- };
19
- export const setCachedItem = (key, value, expiry) => __awaiter(void 0, void 0, void 0, function* () {
20
- const entry = {
21
- data: value,
22
- expiry: expiry === undefined || isNaN(expiry) ? null : expiry,
23
- };
24
- yield cacheBackend.setItem(key, entry);
25
- return value;
26
- });
27
- export const getCachedItem = (key) => __awaiter(void 0, void 0, void 0, function* () {
28
- const entry = yield cacheBackend.getItem(key);
29
- if (!entry) {
30
- return undefined;
31
- }
32
- if (typeof entry.expiry === "number") {
33
- if (Date.now() >= entry.expiry) {
34
- yield cacheBackend.removeItem(key);
35
- return undefined;
36
- }
37
- }
38
- return entry.data;
39
- });
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import LocalStorageCacheBackend from "./LocalStorageCacheBackend";
11
+ let cacheBackend = new LocalStorageCacheBackend();
12
+ export const setCacheBackend = (backend) => {
13
+ cacheBackend = backend;
14
+ };
15
+ export const DEFAULT_CACHE_EXPIRY = /* 15 mins */ 60 * 1000 * 15;
16
+ export const clearCache = () => {
17
+ return cacheBackend.clear();
18
+ };
19
+ export const setCachedItem = (key, value, expiry) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const entry = {
21
+ data: value,
22
+ expiry: expiry === undefined || Number.isNaN(expiry) ? null : expiry,
23
+ };
24
+ yield cacheBackend.setItem(key, entry);
25
+ return value;
26
+ });
27
+ export const getCachedItem = (key) => __awaiter(void 0, void 0, void 0, function* () {
28
+ const entry = yield cacheBackend.getItem(key);
29
+ if (!entry) {
30
+ return undefined;
31
+ }
32
+ if (typeof entry.expiry === "number") {
33
+ if (Date.now() >= entry.expiry) {
34
+ yield cacheBackend.removeItem(key);
35
+ return undefined;
36
+ }
37
+ }
38
+ return entry.data;
39
+ });
@@ -1,9 +1,9 @@
1
- import { CacheBackend } from "./CacheBackend";
2
- export default class LocalForageCacheBackend implements CacheBackend {
3
- private readonly store;
4
- constructor(localforage: any);
5
- clear(): Promise<void>;
6
- getItem<T>(key: string): Promise<T | null>;
7
- removeItem(key: string): Promise<void>;
8
- setItem<T>(key: string, value: T): Promise<void>;
9
- }
1
+ import { CacheBackend } from "./CacheBackend";
2
+ export default class LocalForageCacheBackend implements CacheBackend {
3
+ private readonly store;
4
+ constructor(localforage: any);
5
+ clear(): Promise<void>;
6
+ getItem<T>(key: string): Promise<T | null>;
7
+ removeItem(key: string): Promise<void>;
8
+ setItem<T>(key: string, value: T): Promise<void>;
9
+ }
@@ -1,20 +1,20 @@
1
- export default class LocalForageCacheBackend {
2
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
3
- constructor(localforage) {
4
- this.store = localforage.createInstance({
5
- name: "requestCache",
6
- });
7
- }
8
- clear() {
9
- return this.store.clear();
10
- }
11
- getItem(key) {
12
- return this.store.getItem(key);
13
- }
14
- removeItem(key) {
15
- return this.store.removeItem(key);
16
- }
17
- setItem(key, value) {
18
- return this.store.setItem(key, value);
19
- }
20
- }
1
+ export default class LocalForageCacheBackend {
2
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
3
+ constructor(localforage) {
4
+ this.store = localforage.createInstance({
5
+ name: "requestCache",
6
+ });
7
+ }
8
+ clear() {
9
+ return this.store.clear();
10
+ }
11
+ getItem(key) {
12
+ return this.store.getItem(key);
13
+ }
14
+ removeItem(key) {
15
+ return this.store.removeItem(key);
16
+ }
17
+ setItem(key, value) {
18
+ return this.store.setItem(key, value);
19
+ }
20
+ }
@@ -1,7 +1,7 @@
1
- import { CacheBackend } from "./CacheBackend";
2
- export default class LocalStorageCacheBackend implements CacheBackend {
3
- clear(): Promise<void>;
4
- getItem<T>(key: string): Promise<T | null>;
5
- removeItem(key: string): Promise<void>;
6
- setItem<T>(key: string, value: T): Promise<void>;
7
- }
1
+ import { CacheBackend } from "./CacheBackend";
2
+ export default class LocalStorageCacheBackend implements CacheBackend {
3
+ clear(): Promise<void>;
4
+ getItem<T>(key: string): Promise<T | null>;
5
+ removeItem(key: string): Promise<void>;
6
+ setItem<T>(key: string, value: T): Promise<void>;
7
+ }
@@ -1,32 +1,32 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- export default class LocalStorageCacheBackend {
11
- clear() {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- localStorage.clear();
14
- });
15
- }
16
- getItem(key) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const value = localStorage.getItem(key);
19
- return value ? JSON.parse(value) : null;
20
- });
21
- }
22
- removeItem(key) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- localStorage.removeItem(key);
25
- });
26
- }
27
- setItem(key, value) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- localStorage.setItem(key, JSON.stringify(value));
30
- });
31
- }
32
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export default class LocalStorageCacheBackend {
11
+ clear() {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ localStorage.clear();
14
+ });
15
+ }
16
+ getItem(key) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ const value = localStorage.getItem(key);
19
+ return value ? JSON.parse(value) : null;
20
+ });
21
+ }
22
+ removeItem(key) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ localStorage.removeItem(key);
25
+ });
26
+ }
27
+ setItem(key, value) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ localStorage.setItem(key, JSON.stringify(value));
30
+ });
31
+ }
32
+ }
package/esm/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- export * from "./Api";
2
- export * from "./ApiTypes";
3
- export * from "./UtilTypes";
4
- export * from "./ApiConstants";
5
- export { isRequestError } from "./RequestError";
6
- export { default as Endpoint, EndpointConfig } from "./Endpoint";
7
- export { clearCache, setCacheBackend } from "./cache/Caching";
8
- export { default as LocalStorageCacheBackend } from "./cache/LocalStorageCacheBackend";
9
- export { default as LocaleForageCacheBackend } from "./cache/LocalForageCacheBackend";
10
- export { default as AxiosRequestBackend } from "./backend/AxiosRequestBackend";
11
- export { default as FetchRequestBackend } from "./backend/FetchRequestBackend";
12
- export { default as CacheMiddleware } from "./middleware/CacheMiddleware";
13
- export { default as LoggingMiddleware } from "./middleware/LoggingMiddleware";
1
+ export * from "./Api";
2
+ export * from "./ApiTypes";
3
+ export * from "./UtilTypes";
4
+ export * from "./ApiConstants";
5
+ export { isRequestError } from "./RequestError";
6
+ export { default as Endpoint, EndpointConfig } from "./Endpoint";
7
+ export { clearCache, setCacheBackend } from "./cache/Caching";
8
+ export { default as LocalStorageCacheBackend } from "./cache/LocalStorageCacheBackend";
9
+ export { default as LocaleForageCacheBackend } from "./cache/LocalForageCacheBackend";
10
+ export { default as AxiosRequestBackend } from "./backend/AxiosRequestBackend";
11
+ export { default as FetchRequestBackend } from "./backend/FetchRequestBackend";
12
+ export { default as CacheMiddleware } from "./middleware/CacheMiddleware";
13
+ export { default as LoggingMiddleware } from "./middleware/LoggingMiddleware";
package/esm/index.js CHANGED
@@ -1,15 +1,14 @@
1
- /// <reference types="typescript" />
2
- "use strict";
3
- export * from "./Api";
4
- export * from "./ApiTypes";
5
- export * from "./UtilTypes";
6
- export * from "./ApiConstants";
7
- export { isRequestError } from "./RequestError";
8
- export { default as Endpoint } from "./Endpoint";
9
- export { clearCache, setCacheBackend } from "./cache/Caching";
10
- export { default as LocalStorageCacheBackend } from "./cache/LocalStorageCacheBackend";
11
- export { default as LocaleForageCacheBackend } from "./cache/LocalForageCacheBackend";
12
- export { default as AxiosRequestBackend } from "./backend/AxiosRequestBackend";
13
- export { default as FetchRequestBackend } from "./backend/FetchRequestBackend";
14
- export { default as CacheMiddleware } from "./middleware/CacheMiddleware";
15
- export { default as LoggingMiddleware } from "./middleware/LoggingMiddleware";
1
+ /// <reference types="typescript" />
2
+ export * from "./Api";
3
+ export * from "./ApiTypes";
4
+ export * from "./UtilTypes";
5
+ export * from "./ApiConstants";
6
+ export { isRequestError } from "./RequestError";
7
+ export { default as Endpoint } from "./Endpoint";
8
+ export { clearCache, setCacheBackend } from "./cache/Caching";
9
+ export { default as LocalStorageCacheBackend } from "./cache/LocalStorageCacheBackend";
10
+ export { default as LocaleForageCacheBackend } from "./cache/LocalForageCacheBackend";
11
+ export { default as AxiosRequestBackend } from "./backend/AxiosRequestBackend";
12
+ export { default as FetchRequestBackend } from "./backend/FetchRequestBackend";
13
+ export { default as CacheMiddleware } from "./middleware/CacheMiddleware";
14
+ export { default as LoggingMiddleware } from "./middleware/LoggingMiddleware";
@@ -1,7 +1,7 @@
1
- import { RequestMiddleware } from "../ApiTypes";
2
- export interface CacheMiddlewareOptions {
3
- defaultExpiry?: number;
4
- predicate?: () => boolean;
5
- }
6
- declare const CacheMiddleware: (options?: CacheMiddlewareOptions) => RequestMiddleware;
7
- export default CacheMiddleware;
1
+ import { RequestMiddleware } from "../ApiTypes";
2
+ export interface CacheMiddlewareOptions {
3
+ defaultExpiry?: number;
4
+ predicate?: () => boolean;
5
+ }
6
+ declare const CacheMiddleware: (options?: CacheMiddlewareOptions) => RequestMiddleware;
7
+ export default CacheMiddleware;