@lion/ajax
Advanced tools
Comparing version 1.2.2 to 1.2.3
export { Ajax } from "./Ajax.js"; | ||
export { AjaxFetchError } from "./AjaxFetchError.js"; | ||
export const ajax: Ajax; | ||
export type LionRequestInit = import('../types/types.js').LionRequestInit; | ||
export type AjaxConfig = import('../types/types.js').AjaxConfig; | ||
export type RequestInterceptor = import('../types/types.js').RequestInterceptor; | ||
export type ResponseInterceptor = import('../types/types.js').ResponseInterceptor; | ||
export type CacheConfig = import('../types/types.js').CacheConfig; | ||
export type RequestIdFunction = import('../types/types.js').RequestIdFunction; | ||
export type CacheOptions = import('../types/types.js').CacheOptions; | ||
export type CacheOptionsWithIdentifier = import('../types/types.js').CacheOptionsWithIdentifier; | ||
export type ValidatedCacheOptions = import('../types/types.js').ValidatedCacheOptions; | ||
export type CacheRequestExtension = import('../types/types.js').CacheRequestExtension; | ||
export type CacheResponseRequest = import('../types/types.js').CacheResponseRequest; | ||
export type CacheResponseExtension = import('../types/types.js').CacheResponseExtension; | ||
export type CacheRequest = import('../types/types.js').CacheRequest; | ||
export type CacheResponse = import('../types/types.js').CacheResponse; | ||
export type CachedRequests = import('../types/types.js').CachedRequests; | ||
export type CachedRequestInterceptor = import('../types/types.js').CachedRequestInterceptor; | ||
export type CachedResponseInterceptor = import('../types/types.js').CachedResponseInterceptor; | ||
import { Ajax } from "./Ajax.js"; | ||
export { acceptLanguageRequestInterceptor, createXsrfRequestInterceptor, createCacheInterceptors } from "./interceptors/index.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -13,8 +13,8 @@ /** | ||
export interface AjaxConfig { | ||
addAcceptLanguage: boolean; | ||
addCaching: boolean; | ||
xsrfCookieName: string | null; | ||
xsrfHeaderName: string | null; | ||
cacheOptions: CacheOptionsWithIdentifier; | ||
jsonPrefix: string; | ||
addAcceptLanguage?: boolean; | ||
addCaching?: boolean; | ||
xsrfCookieName?: string | null; | ||
xsrfHeaderName?: string | null; | ||
cacheOptions?: CacheOptionsWithIdentifier; | ||
jsonPrefix?: string; | ||
} | ||
@@ -42,3 +42,3 @@ export declare type RequestInterceptor = (request: Request) => Promise<Request | Response>; | ||
export interface CacheOptionsWithIdentifier extends CacheOptions { | ||
getCacheIdentifier: () => string; | ||
getCacheIdentifier?: () => string; | ||
} | ||
@@ -45,0 +45,0 @@ export interface ValidatedCacheOptions extends CacheOptions { |
{ | ||
"name": "@lion/ajax", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Thin wrapper around fetch with support for interceptors.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -75,10 +75,15 @@ /* eslint-disable consistent-return */ | ||
const { cacheOptions } = this.__config; | ||
if (cacheOptions.useCache || this.__config.addCaching) { | ||
const { cacheRequestInterceptor, cacheResponseInterceptor } = createCacheInterceptors( | ||
cacheOptions.getCacheIdentifier, | ||
cacheOptions, | ||
); | ||
this.addRequestInterceptor(cacheRequestInterceptor); | ||
this.addResponseInterceptor(cacheResponseInterceptor); | ||
// eslint-disable-next-line prefer-destructuring | ||
const cacheOptions = /** @type {import('@lion/ajax').CacheOptionsWithIdentifier} */ ( | ||
this.__config.cacheOptions | ||
); | ||
if ((cacheOptions && cacheOptions.useCache) || this.__config.addCaching) { | ||
if (cacheOptions.getCacheIdentifier) { | ||
const { cacheRequestInterceptor, cacheResponseInterceptor } = createCacheInterceptors( | ||
cacheOptions.getCacheIdentifier, | ||
cacheOptions, | ||
); | ||
this.addRequestInterceptor(cacheRequestInterceptor); | ||
this.addResponseInterceptor(cacheResponseInterceptor); | ||
} | ||
} | ||
@@ -85,0 +90,0 @@ } |
@@ -13,1 +13,21 @@ import { Ajax } from './Ajax.js'; | ||
export const ajax = new Ajax(); | ||
/** | ||
* @typedef {import('../types/types.js').LionRequestInit} LionRequestInit | ||
* @typedef {import('../types/types.js').AjaxConfig} AjaxConfig | ||
* @typedef {import('../types/types.js').RequestInterceptor} RequestInterceptor | ||
* @typedef {import('../types/types.js').ResponseInterceptor} ResponseInterceptor | ||
* @typedef {import('../types/types.js').CacheConfig} CacheConfig | ||
* @typedef {import('../types/types.js').RequestIdFunction} RequestIdFunction | ||
* @typedef {import('../types/types.js').CacheOptions} CacheOptions | ||
* @typedef {import('../types/types.js').CacheOptionsWithIdentifier} CacheOptionsWithIdentifier | ||
* @typedef {import('../types/types.js').ValidatedCacheOptions} ValidatedCacheOptions | ||
* @typedef {import('../types/types.js').CacheRequestExtension} CacheRequestExtension | ||
* @typedef {import('../types/types.js').CacheResponseRequest} CacheResponseRequest | ||
* @typedef {import('../types/types.js').CacheResponseExtension} CacheResponseExtension | ||
* @typedef {import('../types/types.js').CacheRequest} CacheRequest | ||
* @typedef {import('../types/types.js').CacheResponse} CacheResponse | ||
* @typedef {import('../types/types.js').CachedRequests} CachedRequests | ||
* @typedef {import('../types/types.js').CachedRequestInterceptor} CachedRequestInterceptor | ||
* @typedef {import('../types/types.js').CachedResponseInterceptor} CachedResponseInterceptor | ||
*/ |
@@ -75,3 +75,6 @@ import { expect } from '@open-wc/testing'; | ||
const ajax1 = new Ajax(config); | ||
const defaultCacheIdentifierFunction = ajax1.options?.cacheOptions?.getCacheIdentifier; | ||
const defaultCacheIdentifierFunction = /** @type {() => void} */ ( | ||
ajax1.options?.cacheOptions?.getCacheIdentifier | ||
); | ||
// Then | ||
@@ -78,0 +81,0 @@ expect(defaultCacheIdentifierFunction).not.to.be.undefined; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
186829
3156