1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.FILE_HOOKS_CONFIG = exports.DEPRECATED_WARM_MESSAGE = exports.CONFIG = exports.getHooksImports = exports.getHooksFunctions = exports.SERVICE_BEGINNING = exports.HTTP_REQUEST = exports.SERVICE_NEEDED_FUNCTIONS = exports.AUTOGENERATED_COMMENT = void 0;
|
7 | const fs_1 = require("fs");
|
8 | const path_1 = __importDefault(require("path"));
|
9 | const HTTP_REQUEST = fs_1.readFileSync(path_1.default.resolve(__dirname, "../files/httpRequest.tsf")).toString();
|
10 | exports.HTTP_REQUEST = HTTP_REQUEST;
|
11 | const CONFIG = fs_1.readFileSync(path_1.default.resolve(__dirname, "../files/config.tsf")).toString();
|
12 | exports.CONFIG = CONFIG;
|
13 | const FILE_HOOKS_CONFIG = fs_1.readFileSync(path_1.default.resolve(__dirname, "../files/hooksConfig.tsf")).toString();
|
14 | exports.FILE_HOOKS_CONFIG = FILE_HOOKS_CONFIG;
|
15 | const AUTOGENERATED_COMMENT = `
|
16 | /**
|
17 | * AUTO_GENERATED Do not change this file directly, use config.ts file instead
|
18 | *
|
19 | * @version 5
|
20 | */
|
21 | `;
|
22 | exports.AUTOGENERATED_COMMENT = AUTOGENERATED_COMMENT;
|
23 | const SERVICE_BEGINNING = `${AUTOGENERATED_COMMENT}
|
24 | import { AxiosRequestConfig } from "axios";
|
25 | import { SwaggerResponse } from "./config";
|
26 | import { Http } from "./httpRequest";
|
27 | `;
|
28 | exports.SERVICE_BEGINNING = SERVICE_BEGINNING;
|
29 | const SERVICE_NEEDED_FUNCTIONS = `
|
30 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
31 | const __DEV__ = process.env.NODE_ENV !== "production";
|
32 |
|
33 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
34 | function overrideConfig(
|
35 | config?: AxiosRequestConfig,
|
36 | configOverride?: AxiosRequestConfig,
|
37 | ): AxiosRequestConfig {
|
38 | return {
|
39 | ...config,
|
40 | ...configOverride,
|
41 | headers: {
|
42 | ...config?.headers,
|
43 | ...configOverride?.headers,
|
44 | },
|
45 | };
|
46 | }
|
47 |
|
48 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
49 | export function template(path: string, obj: { [x: string]: any } = {}) {
|
50 | Object.keys(obj).forEach((key) => {
|
51 | const re = new RegExp(\`{\${key}}\`, "i");
|
52 | path = path.replace(re, obj[key]);
|
53 | });
|
54 |
|
55 | return path;
|
56 | }
|
57 |
|
58 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
59 | function objToForm(requestBody: object) {
|
60 | const formData = new FormData();
|
61 |
|
62 | Object.entries(requestBody).forEach(([key, value]) => {
|
63 | value && formData.append(key, value);
|
64 | });
|
65 |
|
66 | return formData;
|
67 | }
|
68 | `;
|
69 | exports.SERVICE_NEEDED_FUNCTIONS = SERVICE_NEEDED_FUNCTIONS;
|
70 | const getHooksImports = ({ hasInfinity, }) => `${AUTOGENERATED_COMMENT}
|
71 | ${hasInfinity ? `import { useMemo } from "react";` : ""}
|
72 | import { AxiosRequestConfig } from "axios";
|
73 | import {
|
74 | UseQueryOptions,
|
75 | useQuery,
|
76 | useMutation,
|
77 | UseMutationOptions,
|
78 | ${hasInfinity
|
79 | ? ` useInfiniteQuery,
|
80 | UseInfiniteQueryOptions,`
|
81 | : ""}
|
82 | QueryClient,
|
83 | QueryKey,
|
84 | } from "react-query";
|
85 | import { RequestError, SwaggerResponse } from "./config";
|
86 | ${hasInfinity
|
87 | ? `import { paginationFlattenData, getPageSize, getTotal } from "./hooksConfig";`
|
88 | : ""}
|
89 | `;
|
90 | exports.getHooksImports = getHooksImports;
|
91 | const getHooksFunctions = ({ hasInfinity }) => hasInfinity
|
92 | ? `
|
93 | const useHasMore = (
|
94 | pages: Array<SwaggerResponse<any>> | undefined,
|
95 | list: any,
|
96 | queryParams: any,
|
97 | ) =>
|
98 | useMemo(() => {
|
99 | if (!pages || (pages && pages.length < 1)) {
|
100 | return false;
|
101 | }
|
102 |
|
103 | const total = getTotal(pages);
|
104 |
|
105 | if (total !== undefined) {
|
106 | if (list && list.length < total) {
|
107 | return true;
|
108 | }
|
109 | return false;
|
110 | }
|
111 | if (
|
112 | paginationFlattenData([pages[pages.length - 1]])?.length === getPageSize(queryParams as any)
|
113 | ) {
|
114 | return true;
|
115 | }
|
116 |
|
117 | return false;
|
118 | }, [pages, list, queryParams]);
|
119 |
|
120 | `
|
121 | : "";
|
122 | exports.getHooksFunctions = getHooksFunctions;
|
123 | const DEPRECATED_WARM_MESSAGE = "This endpoint deprecated and will be remove. Please use an alternative";
|
124 | exports.DEPRECATED_WARM_MESSAGE = DEPRECATED_WARM_MESSAGE;
|
125 |
|
\ | No newline at end of file |