pangea-lib 4.0.511 → 4.0.512

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 (25) hide show
  1. package/dist/main.cjs.js +1 -1
  2. package/dist/main.es.js +5 -37
  3. package/dist/types/api/create-api.d.ts +38 -0
  4. package/dist/types/api/index.d.ts +1 -0
  5. package/dist/types/api/methods/call-axios.d.ts +4 -0
  6. package/dist/types/api/methods/connect-to-api.d.ts +7 -0
  7. package/dist/types/api/methods/convert-json-to-model.d.ts +3 -0
  8. package/dist/types/api/methods/get-finals.d.ts +6 -0
  9. package/dist/types/main.d.ts +1 -1
  10. package/dist/types/types/api.types.d.ts +39 -0
  11. package/dist/types/types/index.d.ts +1 -1
  12. package/package.json +1 -1
  13. package/dist/types/api-connections/create-api-connections.d.ts +0 -38
  14. package/dist/types/api-connections/index.d.ts +0 -1
  15. package/dist/types/api-connections/methods/call-axios.d.ts +0 -4
  16. package/dist/types/api-connections/methods/connect-to-api.d.ts +0 -7
  17. package/dist/types/api-connections/methods/convert-json-to-model.d.ts +0 -3
  18. package/dist/types/api-connections/methods/get-finals.d.ts +0 -6
  19. package/dist/types/types/api-connections.types.d.ts +0 -39
  20. /package/dist/types/{api-connections → api}/i18n/api-connections-error.i18n.d.ts +0 -0
  21. /package/dist/types/{api-connections → api}/i18n/api-connections-success.i18n.d.ts +0 -0
  22. /package/dist/types/{api-connections → api}/methods/convert-params-into-form-data.d.ts +0 -0
  23. /package/dist/types/{api-connections → api}/methods/display-error.d.ts +0 -0
  24. /package/dist/types/{api-connections → api}/methods/display-success.d.ts +0 -0
  25. /package/dist/types/{api-connections → api}/methods/get-request-config.d.ts +0 -0
package/dist/main.es.js CHANGED
@@ -159577,39 +159577,15 @@ function by4(e, t, a) {
159577
159577
  },
159578
159578
  getMany(c, n, r) {
159579
159579
  const i = e[c].getMany, o = us(i.params, n);
159580
- return O5(
159581
- "get",
159582
- c,
159583
- i,
159584
- o,
159585
- t,
159586
- a,
159587
- r
159588
- );
159580
+ return O5("get", c, i, o, t, a, r);
159589
159581
  },
159590
159582
  postOne(c, n, r) {
159591
159583
  const i = e[c].postOne, o = us(i.params, n);
159592
- return O5(
159593
- "post",
159594
- c,
159595
- i,
159596
- o,
159597
- t,
159598
- a,
159599
- r
159600
- );
159584
+ return O5("post", c, i, o, t, a, r);
159601
159585
  },
159602
159586
  postMany(c, n, r) {
159603
159587
  const i = e[c].postMany, o = us(i.params, n);
159604
- return O5(
159605
- "post",
159606
- c,
159607
- i,
159608
- o,
159609
- t,
159610
- a,
159611
- r
159612
- );
159588
+ return O5("post", c, i, o, t, a, r);
159613
159589
  },
159614
159590
  putOne(c, n, r, i) {
159615
159591
  const o = IG(c, n), s = e[c].putOne, l = us(s.params, r);
@@ -159617,15 +159593,7 @@ function by4(e, t, a) {
159617
159593
  },
159618
159594
  putMany(c, n, r) {
159619
159595
  const i = e[c].putMany, o = us(i.params, n);
159620
- return O5(
159621
- "put",
159622
- c,
159623
- i,
159624
- o,
159625
- t,
159626
- a,
159627
- r
159628
- );
159596
+ return O5("put", c, i, o, t, a, r);
159629
159597
  },
159630
159598
  deleteOne(c, n, r) {
159631
159599
  const i = IG(c, n), o = e[c].deleteOne;
@@ -159813,7 +159781,7 @@ export {
159813
159781
  Xv4 as animateElement,
159814
159782
  An1 as colorSelectorColors,
159815
159783
  jK as copyModelFields,
159816
- by4 as createApiConnections,
159784
+ by4 as createApi,
159817
159785
  FT1 as createI18n,
159818
159786
  Ty4 as createRouter,
159819
159787
  Ey4 as default,
@@ -0,0 +1,38 @@
1
+ import { Arrayify } from 'pangea-helpers';
2
+ import { Id } from '../types';
3
+ import { CallConfig, Endpoints, EndpointName, ParamsOf, ResponseOf, ApiConfig } from '../types/api.types';
4
+
5
+ export declare function createApi<AE extends Endpoints>(endpoints: AE, appVersion: string, apiConfig?: ApiConfig): {
6
+ getOne<T extends EndpointName<AE, "getOne">>(url: T, id?: Id, params?: ParamsOf<AE, T, "getOne">, callConfig?: CallConfig<ResponseOf<AE, T, "getOne">>): Promise<{
7
+ data: ResponseOf<AE, T, "getOne">;
8
+ totalCount: undefined;
9
+ }>;
10
+ getMany<T_1 extends EndpointName<AE, "getMany">>(url: T_1, params?: ParamsOf<AE, T_1, "getMany">, callConfig?: CallConfig<Arrayify<ResponseOf<AE, T_1, "getMany">>, number>): Promise<{
11
+ data: Arrayify<ResponseOf<AE, T_1, "getMany">>;
12
+ totalCount: number;
13
+ }>;
14
+ postOne<T_2 extends EndpointName<AE, "postOne">>(url: T_2, params?: ParamsOf<AE, T_2, "postOne">, callConfig?: CallConfig<ResponseOf<AE, T_2, "postOne">>): Promise<{
15
+ data: ResponseOf<AE, T_2, "postOne">;
16
+ totalCount: undefined;
17
+ }>;
18
+ postMany<T_3 extends EndpointName<AE, "postMany">>(url: T_3, params: ParamsOf<AE, T_3, "postMany">[], callConfig?: CallConfig<ResponseOf<AE, T_3, "postMany">>): Promise<{
19
+ data: ResponseOf<AE, T_3, "postMany">;
20
+ totalCount: undefined;
21
+ }>;
22
+ putOne<T_4 extends EndpointName<AE, "putOne">>(url: T_4, id?: Id, params?: ParamsOf<AE, T_4, "putOne">, callConfig?: CallConfig<ResponseOf<AE, T_4, "putOne">>): Promise<{
23
+ data: ResponseOf<AE, T_4, "putOne">;
24
+ totalCount: undefined;
25
+ }>;
26
+ putMany<T_5 extends EndpointName<AE, "putMany">>(url: T_5, params: ParamsOf<AE, T_5, "putMany">[], callConfig?: CallConfig<ResponseOf<AE, T_5, "putMany">>): Promise<{
27
+ data: ResponseOf<AE, T_5, "putMany">;
28
+ totalCount: undefined;
29
+ }>;
30
+ deleteOne<T_6 extends EndpointName<AE, "deleteOne">>(url: T_6, id?: Id, callConfig?: CallConfig<ResponseOf<AE, T_6, "deleteOne">>): Promise<{
31
+ data: ResponseOf<AE, T_6, "deleteOne">;
32
+ totalCount: undefined;
33
+ }>;
34
+ deleteMany<T_7 extends EndpointName<AE, "deleteMany">>(url: T_7, ids: Id[], callConfig?: CallConfig<ResponseOf<AE, T_7, "deleteMany">>): Promise<{
35
+ data: ResponseOf<AE, T_7, "deleteMany">;
36
+ totalCount: undefined;
37
+ }>;
38
+ };
@@ -0,0 +1 @@
1
+ export { createApi } from './create-api';
@@ -0,0 +1,4 @@
1
+ import { default as axios, AxiosRequestConfig } from 'axios';
2
+ import { HttpMethod } from '../../types/api.types';
3
+
4
+ export declare function callAxios(method: HttpMethod, url: string, params?: object, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
@@ -0,0 +1,7 @@
1
+ import { PlainObject } from 'pangea-helpers';
2
+ import { HttpMethod, CallConfig, Endpoint, ApiConfig } from '../../types/api.types';
3
+
4
+ export declare function connectToApi<T extends HttpMethod, SuccessRes, TCount>(method: T, url: string, endpoint: Endpoint, params: PlainObject | Array<any>, appVersion: string, apiConfig: ApiConfig | undefined, callConfig?: CallConfig<SuccessRes, TCount>): Promise<{
5
+ data: SuccessRes;
6
+ totalCount: TCount;
7
+ }>;
@@ -0,0 +1,3 @@
1
+ import { EndpointResponse } from '../../types/api.types';
2
+
3
+ export declare function convertJsonToModel(Model: EndpointResponse, jsonData: any): any;
@@ -0,0 +1,6 @@
1
+ import { PlainObject } from 'pangea-helpers';
2
+ import { Id } from '../../types';
3
+ import { EndpointParams } from '../../types/api.types';
4
+
5
+ export declare function getFinalUrl(url: string, id?: Id): string;
6
+ export declare function getFinalParams(Model: EndpointParams, params: PlainObject | PlainObject[]): import('../../models').BaseParams;
@@ -13,7 +13,7 @@ export default install;
13
13
  export { App };
14
14
  export * from './alert-danger';
15
15
  export * from './alert-info';
16
- export * from './api-connections';
16
+ export * from './api';
17
17
  export * from './composables';
18
18
  export * from './helpers';
19
19
  export * from './i18n';
@@ -0,0 +1,39 @@
1
+ import { Ref } from 'vue';
2
+ import { AxiosError, AxiosBasicCredentials } from 'axios';
3
+ import { BaseModel } from '../models/base-model.model';
4
+ import { BaseParams } from '../models/base-params.models';
5
+ import { BaseResponse } from '../models/base-response.models';
6
+ import { ExtractConstructor } from 'pangea-helpers';
7
+ import { ClassWithConstructor } from '.';
8
+
9
+ export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
10
+ export type ApiMethod = 'getOne' | 'getMany' | 'postOne' | 'postMany' | 'putOne' | 'putMany' | 'deleteOne' | 'deleteMany';
11
+ export type CallConfig<SuccessRes, TCount = undefined> = {
12
+ success?: (data: SuccessRes, totalCount?: TCount) => void;
13
+ error?: (err: AxiosError) => void;
14
+ noDisplayError?: boolean;
15
+ noThrowError?: boolean;
16
+ isLoading?: Ref<boolean>;
17
+ basicAuth?: AxiosBasicCredentials;
18
+ };
19
+ export type Headers = Record<string, string>;
20
+ export type GetCustomHeaders = () => Headers;
21
+ export type ApiConfig = {
22
+ getCustomHeaders?: GetCustomHeaders;
23
+ };
24
+ export type EndpointParams = typeof BaseParams;
25
+ export type EndpointResponse = typeof BaseModel | typeof BaseResponse | ClassWithConstructor | undefined;
26
+ export type EndpointMeta = {
27
+ sendAsFormData?: boolean;
28
+ };
29
+ export type Endpoint = {
30
+ params?: EndpointParams;
31
+ response: EndpointResponse;
32
+ meta?: EndpointMeta;
33
+ };
34
+ export type Endpoints = Record<string, Partial<Record<ApiMethod, Endpoint>>>;
35
+ export type EndpointName<AE extends Endpoints, CM extends ApiMethod> = {
36
+ [K in keyof AE]: CM extends keyof AE[K] ? K : never;
37
+ }[keyof AE];
38
+ export type ParamsOf<AE extends Endpoints, EN extends EndpointName<AE, CM>, CM extends ApiMethod> = EN extends keyof AE ? CM extends keyof AE[EN] ? 'params' extends keyof AE[EN][CM] ? InstanceType<ExtractConstructor<AE[EN][CM]['params']>> : never : never : any;
39
+ export type ResponseOf<AE extends Endpoints, EN extends EndpointName<AE, CM>, CM extends ApiMethod> = EN extends keyof AE ? CM extends keyof AE[EN] ? 'response' extends keyof AE[EN][CM] ? InstanceType<ExtractConstructor<AE[EN][CM]['response']>> : never : never : any;
@@ -1,4 +1,4 @@
1
- export * from './api-connections.types';
1
+ export * from './api.types';
2
2
  export * from './app-config.types';
3
3
  export * from './app-options.types';
4
4
  export * from './auth-store.types';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-lib",
3
3
  "description": "",
4
- "version": "4.0.511",
4
+ "version": "4.0.512",
5
5
  "author": "Gianfranco Raselli",
6
6
  "license": "ISC",
7
7
  "homepage": "https://github.com/GianfrancoRaselli/pangea-lib#readme",
@@ -1,38 +0,0 @@
1
- import { Arrayify } from 'pangea-helpers';
2
- import { Id } from '../types';
3
- import { ApiConfig, ApiEndpoints, ApiEndpointName, ApiEndpointParams, ApiEndpointResponse, ApiConnectionsConfig } from '../types/api-connections.types';
4
-
5
- export declare function createApiConnections<AE extends ApiEndpoints>(endpoints: AE, appVersion: string, apiConnectionsConfig?: ApiConnectionsConfig): {
6
- getOne<T extends ApiEndpointName<AE, "getOne">>(url: T, id?: Id, params?: ApiEndpointParams<AE, T, "getOne">, apiConfig?: ApiConfig<ApiEndpointResponse<AE, T, "getOne">>): Promise<{
7
- data: ApiEndpointResponse<AE, T, "getOne">;
8
- totalCount: undefined;
9
- }>;
10
- getMany<T_1 extends ApiEndpointName<AE, "getMany">>(url: T_1, params?: ApiEndpointParams<AE, T_1, "getMany">, apiConfig?: ApiConfig<Arrayify<ApiEndpointResponse<AE, T_1, "getMany">>, number>): Promise<{
11
- data: Arrayify<ApiEndpointResponse<AE, T_1, "getMany">>;
12
- totalCount: number;
13
- }>;
14
- postOne<T_2 extends ApiEndpointName<AE, "postOne">>(url: T_2, params?: ApiEndpointParams<AE, T_2, "postOne">, apiConfig?: ApiConfig<ApiEndpointResponse<AE, T_2, "postOne">>): Promise<{
15
- data: ApiEndpointResponse<AE, T_2, "postOne">;
16
- totalCount: undefined;
17
- }>;
18
- postMany<T_3 extends ApiEndpointName<AE, "postMany">>(url: T_3, params: ApiEndpointParams<AE, T_3, "postMany">[], apiConfig?: ApiConfig<ApiEndpointResponse<AE, T_3, "postMany">>): Promise<{
19
- data: ApiEndpointResponse<AE, T_3, "postMany">;
20
- totalCount: undefined;
21
- }>;
22
- putOne<T_4 extends ApiEndpointName<AE, "putOne">>(url: T_4, id?: Id, params?: ApiEndpointParams<AE, T_4, "putOne">, apiConfig?: ApiConfig<ApiEndpointResponse<AE, T_4, "putOne">>): Promise<{
23
- data: ApiEndpointResponse<AE, T_4, "putOne">;
24
- totalCount: undefined;
25
- }>;
26
- putMany<T_5 extends ApiEndpointName<AE, "putMany">>(url: T_5, params: ApiEndpointParams<AE, T_5, "putMany">[], apiConfig?: ApiConfig<ApiEndpointResponse<AE, T_5, "putMany">>): Promise<{
27
- data: ApiEndpointResponse<AE, T_5, "putMany">;
28
- totalCount: undefined;
29
- }>;
30
- deleteOne<T_6 extends ApiEndpointName<AE, "deleteOne">>(url: T_6, id?: Id, apiConfig?: ApiConfig<ApiEndpointResponse<AE, T_6, "deleteOne">>): Promise<{
31
- data: ApiEndpointResponse<AE, T_6, "deleteOne">;
32
- totalCount: undefined;
33
- }>;
34
- deleteMany<T_7 extends ApiEndpointName<AE, "deleteMany">>(url: T_7, ids: Id[], apiConfig?: ApiConfig<ApiEndpointResponse<AE, T_7, "deleteMany">>): Promise<{
35
- data: ApiEndpointResponse<AE, T_7, "deleteMany">;
36
- totalCount: undefined;
37
- }>;
38
- };
@@ -1 +0,0 @@
1
- export { createApiConnections } from './create-api-connections';
@@ -1,4 +0,0 @@
1
- import { default as axios, AxiosRequestConfig } from 'axios';
2
- import { ApiMethod } from '../../types/api-connections.types';
3
-
4
- export declare function callAxios(method: ApiMethod, url: string, params?: object, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
@@ -1,7 +0,0 @@
1
- import { PlainObject } from 'pangea-helpers';
2
- import { ApiMethod, ApiConfig, EndpointSettings, ApiConnectionsConfig } from '../../types/api-connections.types';
3
-
4
- export declare function connectToApi<T extends ApiMethod, SuccessRes, TCount>(method: T, url: string, endpointSettings: EndpointSettings, params: PlainObject | Array<any>, appVersion: string, apiConnectionsConfig: ApiConnectionsConfig | undefined, apiConfig?: ApiConfig<SuccessRes, TCount>): Promise<{
5
- data: SuccessRes;
6
- totalCount: TCount;
7
- }>;
@@ -1,3 +0,0 @@
1
- import { EndpointSettingsResponse } from '../../types/api-connections.types';
2
-
3
- export declare function convertJsonToModel(Model: EndpointSettingsResponse, jsonData: any): any;
@@ -1,6 +0,0 @@
1
- import { PlainObject } from 'pangea-helpers';
2
- import { Id } from '../../types';
3
- import { EndpointSettingsParams } from '../../types/api-connections.types';
4
-
5
- export declare function getFinalUrl(url: string, id?: Id): string;
6
- export declare function getFinalParams(Model: EndpointSettingsParams, params: PlainObject | PlainObject[]): import('../../models').BaseParams;
@@ -1,39 +0,0 @@
1
- import { Ref } from 'vue';
2
- import { AxiosError, AxiosBasicCredentials } from 'axios';
3
- import { BaseModel } from '../models/base-model.model';
4
- import { BaseParams } from '../models/base-params.models';
5
- import { BaseResponse } from '../models/base-response.models';
6
- import { ExtractConstructor } from 'pangea-helpers';
7
- import { ClassWithConstructor } from '.';
8
-
9
- export type ApiMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
10
- export type ApiConnectionMethod = 'getOne' | 'getMany' | 'postOne' | 'postMany' | 'putOne' | 'putMany' | 'deleteOne' | 'deleteMany';
11
- export type ApiConfig<SuccessRes, TCount = undefined> = {
12
- success?: (data: SuccessRes, totalCount?: TCount) => void;
13
- error?: (err: AxiosError) => void;
14
- noDisplayError?: boolean;
15
- noThrowError?: boolean;
16
- isLoading?: Ref<boolean>;
17
- basicAuth?: AxiosBasicCredentials;
18
- };
19
- export type Headers = Record<string, string>;
20
- export type GetCustomHeaders = () => Headers;
21
- export type ApiConnectionsConfig = {
22
- getCustomHeaders?: GetCustomHeaders;
23
- };
24
- export type EndpointSettingsParams = typeof BaseParams;
25
- export type EndpointSettingsResponse = typeof BaseModel | typeof BaseResponse | ClassWithConstructor | undefined;
26
- export type EndpointSettingsMeta = {
27
- sendAsFormData?: boolean;
28
- };
29
- export type EndpointSettings = {
30
- params?: EndpointSettingsParams;
31
- response: EndpointSettingsResponse;
32
- meta?: EndpointSettingsMeta;
33
- };
34
- export type ApiEndpoints = Record<string, Partial<Record<ApiConnectionMethod, EndpointSettings>>>;
35
- export type ApiEndpointName<AE extends ApiEndpoints, CM extends ApiConnectionMethod> = {
36
- [K in keyof AE]: CM extends keyof AE[K] ? K : never;
37
- }[keyof AE];
38
- export type ApiEndpointParams<AE extends ApiEndpoints, EN extends ApiEndpointName<AE, CM>, CM extends ApiConnectionMethod> = EN extends keyof AE ? CM extends keyof AE[EN] ? 'params' extends keyof AE[EN][CM] ? InstanceType<ExtractConstructor<AE[EN][CM]['params']>> : never : never : any;
39
- export type ApiEndpointResponse<AE extends ApiEndpoints, EN extends ApiEndpointName<AE, CM>, CM extends ApiConnectionMethod> = EN extends keyof AE ? CM extends keyof AE[EN] ? 'response' extends keyof AE[EN][CM] ? InstanceType<ExtractConstructor<AE[EN][CM]['response']>> : never : never : any;