Merge pull request #2079 from ing-bank/fix/export-ajax-types
fix: export ajax types
This commit is contained in:
commit
0ea8b75349
5 changed files with 49 additions and 16 deletions
5
.changeset/long-actors-trade.md
Normal file
5
.changeset/long-actors-trade.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@lion/ajax": patch
|
||||
---
|
||||
|
||||
fix: export ajax types
|
||||
|
|
@ -72,8 +72,12 @@ export class Ajax {
|
|||
this.addRequestInterceptor(createXsrfRequestInterceptor(xsrfCookieName, xsrfHeaderName));
|
||||
}
|
||||
|
||||
const { cacheOptions } = this.__config;
|
||||
if (cacheOptions.useCache || this.__config.addCaching) {
|
||||
// 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,
|
||||
|
|
@ -82,6 +86,7 @@ export class Ajax {
|
|||
this.addResponseInterceptor(cacheResponseInterceptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the Ajax instance
|
||||
|
|
|
|||
|
|
@ -10,3 +10,23 @@ export {
|
|||
|
||||
// globally available instance
|
||||
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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -72,7 +72,10 @@ describe('Ajax', () => {
|
|||
// TODO: fix AjaxConfig types => e.g. create FullAjaxConfig with everything "mandatory" and then AjaxConfig (= Partial of it) for user
|
||||
// @ts-ignore
|
||||
const ajax1 = new Ajax(config);
|
||||
const defaultCacheIdentifierFunction = ajax1.options?.cacheOptions?.getCacheIdentifier;
|
||||
|
||||
const defaultCacheIdentifierFunction = /** @type {() => void} */ (
|
||||
ajax1.options?.cacheOptions?.getCacheIdentifier
|
||||
);
|
||||
// Then
|
||||
expect(defaultCacheIdentifierFunction).not.to.be.undefined;
|
||||
expect(defaultCacheIdentifierFunction).to.be.a('function');
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ export interface LionRequestInit extends Omit<RequestInit, 'body'> {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
export type RequestInterceptor = (request: Request) => Promise<Request | Response>;
|
||||
|
|
@ -46,7 +46,7 @@ export interface CacheOptions {
|
|||
}
|
||||
|
||||
export interface CacheOptionsWithIdentifier extends CacheOptions {
|
||||
getCacheIdentifier: () => string;
|
||||
getCacheIdentifier?: () => string;
|
||||
}
|
||||
|
||||
export interface ValidatedCacheOptions extends CacheOptions {
|
||||
|
|
|
|||
Loading…
Reference in a new issue