@khala/js-client-module-federation-out
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -23,2 +23,7 @@ import type { Configuration } from './configuration'; | ||
} | ||
export interface ApiConfig { | ||
axios: AxiosInstance; | ||
configuration?: Configuration; | ||
} | ||
export type ActionType = <T>(config: T, axiosRequest: AxiosRequestConfig) => Promise<RequestArgs>; | ||
/** | ||
@@ -31,11 +36,12 @@ * Base API to store config, basepath and axios instance. | ||
protected basePath: string; | ||
actions: Record<string, ActionType>; | ||
protected configuration: Configuration | undefined; | ||
protected axios: AxiosInstance; | ||
protected configuration: Configuration | undefined; | ||
/** | ||
* Constructor to create baseAPI. | ||
* @param { Configuration } configuration optional configuration for each request made with this API. | ||
* @param { string } basePath basePath of api requests. | ||
* @param { AxiosInstance } axios axios instance, global one is used as fallback | ||
* @param { { axios: AxiosInstance, configuration: Configuration } } config to be passed down to axios. | ||
* @param { Record<string, ActionType> } object with actions to send with axios. | ||
*/ | ||
constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance); | ||
constructor(basePath: string, config: ApiConfig, actions: Record<string, ActionType>); | ||
/** | ||
@@ -48,2 +54,7 @@ * Send axios request | ||
sendRequest<T>(request: Promise<RequestArgs>, axios?: AxiosInstance, basePath?: string): Promise<AxiosResponse<T>>; | ||
/** | ||
* Method to register new action. | ||
* @param { ActionType } toRegister object with new actions to register | ||
*/ | ||
register(toRegister: Record<string, ActionType>): void; | ||
} | ||
@@ -50,0 +61,0 @@ /** |
@@ -88,14 +88,15 @@ "use strict"; | ||
* Constructor to create baseAPI. | ||
* @param { Configuration } configuration optional configuration for each request made with this API. | ||
* @param { string } basePath basePath of api requests. | ||
* @param { AxiosInstance } axios axios instance, global one is used as fallback | ||
* @param { { axios: AxiosInstance, configuration: Configuration } } config to be passed down to axios. | ||
* @param { Record<string, ActionType> } object with actions to send with axios. | ||
*/ | ||
function BaseAPI(configuration, basePath, axios) { | ||
function BaseAPI(basePath, config, actions) { | ||
if (basePath === void 0) { basePath = exports.BASE_PATH; } | ||
if (axios === void 0) { axios = axios_1.default; } | ||
if (config === void 0) { config = { axios: axios_1.default }; } | ||
this.basePath = basePath; | ||
this.axios = axios; | ||
if (configuration) { | ||
this.configuration = configuration; | ||
this.basePath = configuration.basePath || this.basePath; | ||
this.actions = actions; | ||
this.axios = config.axios; | ||
if (config.configuration) { | ||
this.configuration = config.configuration; | ||
this.basePath = config.configuration.basePath || this.basePath; | ||
} | ||
@@ -130,2 +131,12 @@ } | ||
}; | ||
/** | ||
* Method to register new action. | ||
* @param { ActionType } toRegister object with new actions to register | ||
*/ | ||
BaseAPI.prototype.register = function (toRegister) { | ||
var _this = this; | ||
Object.entries(toRegister).forEach(function (entry) { | ||
_this.actions[entry[0]] = entry[1]; | ||
}); | ||
}; | ||
return BaseAPI; | ||
@@ -132,0 +143,0 @@ }()); |
@@ -33,2 +33,9 @@ /* tslint:disable */ | ||
export interface ApiConfig { | ||
axios: AxiosInstance; | ||
configuration?: Configuration; | ||
} | ||
export type ActionType = <T>(config: T, axiosRequest: AxiosRequestConfig) => Promise<RequestArgs>; | ||
/** | ||
@@ -41,13 +48,14 @@ * Base API to store config, basepath and axios instance. | ||
protected configuration: Configuration | undefined; | ||
protected axios: AxiosInstance; | ||
/** | ||
* Constructor to create baseAPI. | ||
* @param { Configuration } configuration optional configuration for each request made with this API. | ||
* @param { string } basePath basePath of api requests. | ||
* @param { AxiosInstance } axios axios instance, global one is used as fallback | ||
* @param { { axios: AxiosInstance, configuration: Configuration } } config to be passed down to axios. | ||
* @param { Record<string, ActionType> } object with actions to send with axios. | ||
*/ | ||
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) { | ||
if (configuration) { | ||
this.configuration = configuration; | ||
this.basePath = configuration.basePath || this.basePath; | ||
constructor(protected basePath: string = BASE_PATH, config: ApiConfig = { axios: globalAxios }, public actions: Record<string, ActionType>) { | ||
this.axios = config.axios; | ||
if (config.configuration) { | ||
this.configuration = config.configuration; | ||
this.basePath = config.configuration.basePath || this.basePath; | ||
} | ||
@@ -66,2 +74,12 @@ } | ||
} | ||
/** | ||
* Method to register new action. | ||
* @param { ActionType } toRegister object with new actions to register | ||
*/ | ||
public register(toRegister: Record<string, ActionType>): void { | ||
Object.entries(toRegister).forEach((entry: [string, ActionType]) => { | ||
this.actions[entry[0]] = entry[1]; | ||
}) | ||
} | ||
}; | ||
@@ -68,0 +86,0 @@ |
@@ -59,2 +59,2 @@ import type { AxiosRequestConfig } from 'axios'; | ||
*/ | ||
export declare const fooBarGetParamCreator: ({ name, perPage, page, orderBy, orderHow }: FooBarGetParams, options?: AxiosRequestConfig) => Promise<RequestArgs>; | ||
export declare const fooBarGetParamCreator: ({ name, perPage, page, orderBy, orderHow }?: FooBarGetParams, options?: AxiosRequestConfig) => Promise<RequestArgs>; |
@@ -78,7 +78,7 @@ "use strict"; | ||
var fooBarGetParamCreator = function (_a, options) { | ||
var name = _a.name, perPage = _a.perPage, page = _a.page, orderBy = _a.orderBy, orderHow = _a.orderHow; | ||
var _b = _a === void 0 ? {} : _a, name = _b.name, perPage = _b.perPage, page = _b.page, orderBy = _b.orderBy, orderHow = _b.orderHow; | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
var localVarPath, localVarUrlObj, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter; | ||
return __generator(this, function (_b) { | ||
return __generator(this, function (_c) { | ||
localVarPath = "/fooBar"; | ||
@@ -85,0 +85,0 @@ localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL); |
@@ -67,3 +67,3 @@ // @ts-ignore | ||
*/ | ||
export const fooBarGetParamCreator = async ({ name, perPage, page, orderBy, orderHow }: FooBarGetParams, options: AxiosRequestConfig = {}): Promise<RequestArgs> => { | ||
export const fooBarGetParamCreator = async ({ name, perPage, page, orderBy, orderHow }: FooBarGetParams = {}, options: AxiosRequestConfig = {}): Promise<RequestArgs> => { | ||
const localVarPath = `/fooBar`; | ||
@@ -70,0 +70,0 @@ // use dummy base URL string because the URL constructor only accepts absolute URLs. |
{ | ||
"name": "@khala/js-client-module-federation-out", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "FooBar", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ { | ||
"lib": [ | ||
"es6", | ||
"es2017", | ||
"dom" | ||
@@ -13,0 +13,0 @@ ] |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
63912
1650
0