From e1a12652447f80d55a7c561ebde3afb60b290a9b Mon Sep 17 00:00:00 2001 From: Sirbu Nicolae-Cezar Date: Thu, 13 Oct 2022 12:23:22 +0300 Subject: [PATCH 1/4] Extract AssetCatalog API logic Signed-off-by: Sirbu Nicolae-Cezar --- dist/esm/api/assets/index.js | 3 ++ dist/esm/api/assets/search/index.js | 26 +++++++++++++++++ dist/esm/api/assets/types/index.js | 24 ++++++++++++++++ dist/esm/api/egeria-fetch.js | 23 +++++++++++++-- dist/esm/api/index.js | 6 ++-- dist/esm/api/routes.js | 3 ++ dist/esm/commons/constants.js | 4 +++ dist/esm/commons/helpers.js | 26 +++++++++++++++++ dist/esm/commons/index.js | 4 +++ dist/esm/commons/paths.js | 2 ++ dist/esm/main.js | 5 ++-- dist/esm/types/formData.js | 1 + dist/types/api/assets/index.d.ts | 3 ++ dist/types/api/assets/search/index.d.ts | 3 ++ dist/types/api/assets/types/index.d.ts | 2 ++ dist/types/api/egeria-fetch.d.ts | 3 +- dist/types/api/index.d.ts | 6 ++-- dist/types/api/routes.d.ts | 3 ++ dist/types/commons/constants.d.ts | 4 +++ dist/types/commons/helpers.d.ts | 10 +++++++ dist/types/commons/index.d.ts | 4 +++ dist/types/commons/paths.d.ts | 2 ++ dist/types/main.d.ts | 7 +++-- dist/types/types/formData.d.ts | 8 ++++++ src/api/assets/index.ts | 7 +++++ src/api/assets/search/index.ts | 25 +++++++++++++++++ src/api/assets/types/index.ts | 22 +++++++++++++++ src/api/egeria-fetch.ts | 19 +++++++++++-- src/api/index.ts | 18 ++++++++++-- src/api/routes.ts | 7 +++++ src/commons/constants.ts | 9 ++++++ src/commons/helpers.ts | 37 +++++++++++++++++++++++++ src/commons/index.ts | 24 ++++++++++++++++ src/commons/paths.ts | 5 ++++ src/main.ts | 29 +++++++++++++++++-- src/types/formData.ts | 11 ++++++++ 36 files changed, 378 insertions(+), 17 deletions(-) create mode 100644 dist/esm/api/assets/index.js create mode 100644 dist/esm/api/assets/search/index.js create mode 100644 dist/esm/api/assets/types/index.js create mode 100644 dist/esm/api/routes.js create mode 100644 dist/esm/commons/constants.js create mode 100644 dist/esm/commons/helpers.js create mode 100644 dist/esm/commons/index.js create mode 100644 dist/esm/commons/paths.js create mode 100644 dist/esm/types/formData.js create mode 100644 dist/types/api/assets/index.d.ts create mode 100644 dist/types/api/assets/search/index.d.ts create mode 100644 dist/types/api/assets/types/index.d.ts create mode 100644 dist/types/api/routes.d.ts create mode 100644 dist/types/commons/constants.d.ts create mode 100644 dist/types/commons/helpers.d.ts create mode 100644 dist/types/commons/index.d.ts create mode 100644 dist/types/commons/paths.d.ts create mode 100644 dist/types/types/formData.d.ts create mode 100644 src/api/assets/index.ts create mode 100644 src/api/assets/search/index.ts create mode 100644 src/api/assets/types/index.ts create mode 100644 src/api/routes.ts create mode 100644 src/commons/constants.ts create mode 100644 src/commons/helpers.ts create mode 100644 src/commons/index.ts create mode 100644 src/commons/paths.ts create mode 100644 src/types/formData.ts diff --git a/dist/esm/api/assets/index.js b/dist/esm/api/assets/index.js new file mode 100644 index 0000000..19c5e91 --- /dev/null +++ b/dist/esm/api/assets/index.js @@ -0,0 +1,3 @@ +import { fetchRawData } from './search'; +import { fetchTypes } from './types'; +export { fetchRawData, fetchTypes }; diff --git a/dist/esm/api/assets/search/index.js b/dist/esm/api/assets/search/index.js new file mode 100644 index 0000000..369fb6c --- /dev/null +++ b/dist/esm/api/assets/search/index.js @@ -0,0 +1,26 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +import { API_ASSETS_SEARCH_PATH } from '../../routes'; +import { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED } from '../../../commons/constants'; +import { fetchData } from '../../egeria-fetch'; +import { getQueryParamsPath } from '../../../commons/helpers'; +const fetchRawData = (formData, apiUrl) => __awaiter(void 0, void 0, void 0, function* () { + const { q, types } = formData; + if (q.length >= QUERY_MIN_LENGTH && types.length >= TYPES_MIN_SELECTED) { + const _queryParams = getQueryParamsPath(formData); + const path = `${apiUrl || ''}${API_ASSETS_SEARCH_PATH}${_queryParams.length ? `?${_queryParams.join('&')}` : ``}`; + const rawData = yield fetchData(path, 'GET'); + return rawData; + } + else { + return []; + } +}); +export { fetchRawData }; diff --git a/dist/esm/api/assets/types/index.js b/dist/esm/api/assets/types/index.js new file mode 100644 index 0000000..701e4df --- /dev/null +++ b/dist/esm/api/assets/types/index.js @@ -0,0 +1,24 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +import { API_ASSETS_TYPES_PATH } from '../../routes'; +import { fetchData } from '../../egeria-fetch'; +const fetchTypes = (apiUrl) => __awaiter(void 0, void 0, void 0, function* () { + let typesData = yield fetchData(`${apiUrl || ''}${API_ASSETS_TYPES_PATH}`, 'GET'); + typesData = [ + ...typesData.map((d) => { + return { + value: d.name, + label: d.name + }; + }) + ]; + return typesData; +}); +export { fetchTypes }; diff --git a/dist/esm/api/egeria-fetch.js b/dist/esm/api/egeria-fetch.js index 04a7fba..e70cb54 100644 --- a/dist/esm/api/egeria-fetch.js +++ b/dist/esm/api/egeria-fetch.js @@ -1,7 +1,26 @@ -import { handleResponse } from '../auth'; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +import { handleResponse, authHeader } from '../auth'; const egeriaFetch = (endpoint, method, headers, options) => { const requestOptions = Object.assign({ method: method, headers: headers }, options); const apiUrl = process.env.REACT_APP_API_URL || ''; return fetch(`${apiUrl}${endpoint}`, requestOptions).then(handleResponse); }; -export { egeriaFetch }; +const fetchData = (uri, method, callback) => __awaiter(void 0, void 0, void 0, function* () { + const res = yield egeriaFetch(uri, method, Object.assign({}, authHeader()), {}); + const data = yield res.json(); + if (callback) { + callback(data); + } + else { + return data; + } +}); +export { egeriaFetch, fetchData }; diff --git a/dist/esm/api/index.js b/dist/esm/api/index.js index b912a55..9d2e8ba 100644 --- a/dist/esm/api/index.js +++ b/dist/esm/api/index.js @@ -1,7 +1,9 @@ import { glossaries } from './data/glossaries'; import { lineage } from './data/lineage'; import { types } from './data/types'; -import { egeriaFetch } from './egeria-fetch'; +import { egeriaFetch, fetchData } from './egeria-fetch'; +import { fetchRawData, fetchTypes } from './assets'; +import { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH } from './routes'; const apiUrl = () => { return `${process.env.REACT_APP_API_URL}`; }; @@ -10,4 +12,4 @@ function goHome() { window.location.href = '/'; } ; -export { apiUrl, egeriaFetch, glossaries, goHome, lineage, types }; +export { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH, apiUrl, egeriaFetch, fetchData, fetchRawData, fetchTypes, glossaries, goHome, lineage, types, }; diff --git a/dist/esm/api/routes.js b/dist/esm/api/routes.js new file mode 100644 index 0000000..8b225ce --- /dev/null +++ b/dist/esm/api/routes.js @@ -0,0 +1,3 @@ +const API_ASSETS_SEARCH_PATH = '/api/assets/search'; +const API_ASSETS_TYPES_PATH = '/api/assets/types'; +export { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH }; diff --git a/dist/esm/commons/constants.js b/dist/esm/commons/constants.js new file mode 100644 index 0000000..afac369 --- /dev/null +++ b/dist/esm/commons/constants.js @@ -0,0 +1,4 @@ +const QUERY_MIN_LENGTH = 3; +const TYPES_MIN_SELECTED = 1; +const PAGE_SIZE_INCREASE_VALUE = 25; +export { PAGE_SIZE_INCREASE_VALUE, QUERY_MIN_LENGTH, TYPES_MIN_SELECTED }; diff --git a/dist/esm/commons/helpers.js b/dist/esm/commons/helpers.js new file mode 100644 index 0000000..747dfe7 --- /dev/null +++ b/dist/esm/commons/helpers.js @@ -0,0 +1,26 @@ +import { PAGE_SIZE_INCREASE_VALUE } from './constants'; +const getQueryParamsPath = (formData) => { + const { q, exactMatch, caseSensitive, types, pageSize } = formData; + let queryParams = []; + if (q) { + queryParams.push(`q=${q}`); + } + if (types && types.length > 0) { + queryParams.push(`types=${types.join(',')}`); + } + queryParams.push(`exactMatch=${exactMatch}`); + queryParams.push(`caseSensitive=${caseSensitive}`); + queryParams.push(`pageSize=${pageSize}`); + return queryParams; +}; +const getQueryParams = (searchParams) => { + var _a; + return { + q: searchParams.get('q') || '', + types: ((_a = searchParams.get('types')) === null || _a === void 0 ? void 0 : _a.split(',')) || [], + exactMatch: searchParams.get('exactMatch') === "true" ? true : false, + caseSensitive: searchParams.get('caseSensitive') === "true" ? true : false, + pageSize: searchParams.get('pageSize') ? parseInt(searchParams.get('pageSize')) : PAGE_SIZE_INCREASE_VALUE + }; +}; +export { getQueryParams, getQueryParamsPath }; diff --git a/dist/esm/commons/index.js b/dist/esm/commons/index.js new file mode 100644 index 0000000..be203dc --- /dev/null +++ b/dist/esm/commons/index.js @@ -0,0 +1,4 @@ +import { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED, PAGE_SIZE_INCREASE_VALUE } from './constants'; +import { getQueryParams, getQueryParamsPath } from './helpers'; +import { ASSET_CATALOG_PATH } from './paths'; +export { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED, PAGE_SIZE_INCREASE_VALUE, getQueryParams, getQueryParamsPath, ASSET_CATALOG_PATH }; diff --git a/dist/esm/commons/paths.js b/dist/esm/commons/paths.js new file mode 100644 index 0000000..6b4e5a4 --- /dev/null +++ b/dist/esm/commons/paths.js @@ -0,0 +1,2 @@ +const ASSET_CATALOG_PATH = '/assets/catalog'; +export { ASSET_CATALOG_PATH }; diff --git a/dist/esm/main.js b/dist/esm/main.js index 8d2ab7c..23f9df0 100644 --- a/dist/esm/main.js +++ b/dist/esm/main.js @@ -2,6 +2,7 @@ import { iconsMap, itemGroupIconMap, getIconByGroup, linksTypeIconMap, menuIcons import { lineageViewsTypesMapping } from './navigation-types-mappings'; import { capitalize } from './capitalize'; import { getComponent } from './get-component'; -import { apiUrl, egeriaFetch, glossaries, goHome, lineage, types } from './api'; +import { apiUrl, egeriaFetch, fetchRawData, fetchTypes, glossaries, goHome, lineage, types, } from './api'; import { authHeader, authHeaderWithContentType, currentJwt, handleResponse, login, logout, parseJwt, setToken } from './auth'; -export { apiUrl, authHeader, authHeaderWithContentType, capitalize, currentJwt, egeriaFetch, getComponent, getIconByGroup, glossaries, goHome, handleResponse, iconsMap, itemGroupIconMap, lineage, lineageViewsTypesMapping, linksTypeIconMap, login, logout, menuIcons, parseJwt, setToken, types }; +import { PAGE_SIZE_INCREASE_VALUE, getQueryParams, getQueryParamsPath, ASSET_CATALOG_PATH } from './commons'; +export { apiUrl, authHeader, authHeaderWithContentType, capitalize, currentJwt, egeriaFetch, getComponent, getIconByGroup, glossaries, goHome, handleResponse, iconsMap, itemGroupIconMap, lineage, lineageViewsTypesMapping, linksTypeIconMap, login, logout, menuIcons, parseJwt, setToken, types, ASSET_CATALOG_PATH, PAGE_SIZE_INCREASE_VALUE, getQueryParams, getQueryParamsPath, fetchTypes, fetchRawData }; diff --git a/dist/esm/types/formData.js b/dist/esm/types/formData.js new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/esm/types/formData.js @@ -0,0 +1 @@ +export {}; diff --git a/dist/types/api/assets/index.d.ts b/dist/types/api/assets/index.d.ts new file mode 100644 index 0000000..19c5e91 --- /dev/null +++ b/dist/types/api/assets/index.d.ts @@ -0,0 +1,3 @@ +import { fetchRawData } from './search'; +import { fetchTypes } from './types'; +export { fetchRawData, fetchTypes }; diff --git a/dist/types/api/assets/search/index.d.ts b/dist/types/api/assets/search/index.d.ts new file mode 100644 index 0000000..14b7c01 --- /dev/null +++ b/dist/types/api/assets/search/index.d.ts @@ -0,0 +1,3 @@ +import { formData } from '../../../types/formData'; +declare const fetchRawData: (formData: formData, apiUrl?: string) => Promise; +export { fetchRawData }; diff --git a/dist/types/api/assets/types/index.d.ts b/dist/types/api/assets/types/index.d.ts new file mode 100644 index 0000000..553453d --- /dev/null +++ b/dist/types/api/assets/types/index.d.ts @@ -0,0 +1,2 @@ +declare const fetchTypes: (apiUrl?: string) => Promise; +export { fetchTypes }; diff --git a/dist/types/api/egeria-fetch.d.ts b/dist/types/api/egeria-fetch.d.ts index ab9b512..641e7d7 100644 --- a/dist/types/api/egeria-fetch.d.ts +++ b/dist/types/api/egeria-fetch.d.ts @@ -1,2 +1,3 @@ declare const egeriaFetch: (endpoint: string, method: string, headers: any, options: any) => Promise; -export { egeriaFetch }; +declare const fetchData: (uri: string, method: string, callback?: Function) => Promise; +export { egeriaFetch, fetchData }; diff --git a/dist/types/api/index.d.ts b/dist/types/api/index.d.ts index 159a689..b481098 100644 --- a/dist/types/api/index.d.ts +++ b/dist/types/api/index.d.ts @@ -1,7 +1,9 @@ import { glossaries } from './data/glossaries'; import { lineage } from './data/lineage'; import { types } from './data/types'; -import { egeriaFetch } from './egeria-fetch'; +import { egeriaFetch, fetchData } from './egeria-fetch'; +import { fetchRawData, fetchTypes } from './assets'; +import { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH } from './routes'; declare const apiUrl: () => string; declare function goHome(): void; -export { apiUrl, egeriaFetch, glossaries, goHome, lineage, types }; +export { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH, apiUrl, egeriaFetch, fetchData, fetchRawData, fetchTypes, glossaries, goHome, lineage, types, }; diff --git a/dist/types/api/routes.d.ts b/dist/types/api/routes.d.ts new file mode 100644 index 0000000..d59aec3 --- /dev/null +++ b/dist/types/api/routes.d.ts @@ -0,0 +1,3 @@ +declare const API_ASSETS_SEARCH_PATH = "/api/assets/search"; +declare const API_ASSETS_TYPES_PATH = "/api/assets/types"; +export { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH }; diff --git a/dist/types/commons/constants.d.ts b/dist/types/commons/constants.d.ts new file mode 100644 index 0000000..00d3827 --- /dev/null +++ b/dist/types/commons/constants.d.ts @@ -0,0 +1,4 @@ +declare const QUERY_MIN_LENGTH = 3; +declare const TYPES_MIN_SELECTED = 1; +declare const PAGE_SIZE_INCREASE_VALUE = 25; +export { PAGE_SIZE_INCREASE_VALUE, QUERY_MIN_LENGTH, TYPES_MIN_SELECTED }; diff --git a/dist/types/commons/helpers.d.ts b/dist/types/commons/helpers.d.ts new file mode 100644 index 0000000..15b72c1 --- /dev/null +++ b/dist/types/commons/helpers.d.ts @@ -0,0 +1,10 @@ +import { formData } from '../types/formData'; +declare const getQueryParamsPath: (formData: formData) => any; +declare const getQueryParams: (searchParams: any) => { + q: any; + types: any; + exactMatch: boolean; + caseSensitive: boolean; + pageSize: number; +}; +export { getQueryParams, getQueryParamsPath }; diff --git a/dist/types/commons/index.d.ts b/dist/types/commons/index.d.ts new file mode 100644 index 0000000..be203dc --- /dev/null +++ b/dist/types/commons/index.d.ts @@ -0,0 +1,4 @@ +import { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED, PAGE_SIZE_INCREASE_VALUE } from './constants'; +import { getQueryParams, getQueryParamsPath } from './helpers'; +import { ASSET_CATALOG_PATH } from './paths'; +export { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED, PAGE_SIZE_INCREASE_VALUE, getQueryParams, getQueryParamsPath, ASSET_CATALOG_PATH }; diff --git a/dist/types/commons/paths.d.ts b/dist/types/commons/paths.d.ts new file mode 100644 index 0000000..84881d9 --- /dev/null +++ b/dist/types/commons/paths.d.ts @@ -0,0 +1,2 @@ +declare const ASSET_CATALOG_PATH = "/assets/catalog"; +export { ASSET_CATALOG_PATH }; diff --git a/dist/types/main.d.ts b/dist/types/main.d.ts index 8d2ab7c..4f3c460 100644 --- a/dist/types/main.d.ts +++ b/dist/types/main.d.ts @@ -2,6 +2,9 @@ import { iconsMap, itemGroupIconMap, getIconByGroup, linksTypeIconMap, menuIcons import { lineageViewsTypesMapping } from './navigation-types-mappings'; import { capitalize } from './capitalize'; import { getComponent } from './get-component'; -import { apiUrl, egeriaFetch, glossaries, goHome, lineage, types } from './api'; +import { apiUrl, egeriaFetch, fetchRawData, fetchTypes, glossaries, goHome, lineage, types } from './api'; import { authHeader, authHeaderWithContentType, currentJwt, handleResponse, login, logout, parseJwt, setToken } from './auth'; -export { apiUrl, authHeader, authHeaderWithContentType, capitalize, currentJwt, egeriaFetch, getComponent, getIconByGroup, glossaries, goHome, handleResponse, iconsMap, itemGroupIconMap, lineage, lineageViewsTypesMapping, linksTypeIconMap, login, logout, menuIcons, parseJwt, setToken, types }; +import { PAGE_SIZE_INCREASE_VALUE, getQueryParams, getQueryParamsPath, ASSET_CATALOG_PATH } from './commons'; +import { formData } from './types/formData'; +export type { formData }; +export { apiUrl, authHeader, authHeaderWithContentType, capitalize, currentJwt, egeriaFetch, getComponent, getIconByGroup, glossaries, goHome, handleResponse, iconsMap, itemGroupIconMap, lineage, lineageViewsTypesMapping, linksTypeIconMap, login, logout, menuIcons, parseJwt, setToken, types, ASSET_CATALOG_PATH, PAGE_SIZE_INCREASE_VALUE, getQueryParams, getQueryParamsPath, fetchTypes, fetchRawData }; diff --git a/dist/types/types/formData.d.ts b/dist/types/types/formData.d.ts new file mode 100644 index 0000000..4a984f3 --- /dev/null +++ b/dist/types/types/formData.d.ts @@ -0,0 +1,8 @@ +interface formData { + caseSensitive: boolean; + exactMatch: boolean; + pageSize: number; + q: string; + types: Array; +} +export type { formData }; diff --git a/src/api/assets/index.ts b/src/api/assets/index.ts new file mode 100644 index 0000000..39fdbd0 --- /dev/null +++ b/src/api/assets/index.ts @@ -0,0 +1,7 @@ +import { fetchRawData } from './search'; +import { fetchTypes } from './types'; + +export { + fetchRawData, + fetchTypes +} diff --git a/src/api/assets/search/index.ts b/src/api/assets/search/index.ts new file mode 100644 index 0000000..15884fc --- /dev/null +++ b/src/api/assets/search/index.ts @@ -0,0 +1,25 @@ +import { API_ASSETS_SEARCH_PATH } from '../../routes'; +import { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED } from '../../../commons/constants'; +import { formData } from '../../../types/formData'; +import { fetchData } from '../../egeria-fetch'; +import { getQueryParamsPath } from '../../../commons/helpers'; + +const fetchRawData = async (formData: formData, apiUrl?: string) => { + const {q, types} = formData; + + if(q.length >= QUERY_MIN_LENGTH && types.length >= TYPES_MIN_SELECTED) { + const _queryParams = getQueryParamsPath(formData); + + const path = `${apiUrl || ''}${API_ASSETS_SEARCH_PATH}${_queryParams.length ? `?${_queryParams.join('&')}` : ``}`; + + const rawData = await fetchData(path, 'GET'); + + return rawData; + } else { + return []; + } +}; + +export { + fetchRawData +} diff --git a/src/api/assets/types/index.ts b/src/api/assets/types/index.ts new file mode 100644 index 0000000..6be8c1a --- /dev/null +++ b/src/api/assets/types/index.ts @@ -0,0 +1,22 @@ +import { API_ASSETS_TYPES_PATH } from '../../routes'; + +import { fetchData } from '../../egeria-fetch'; + +const fetchTypes = async (apiUrl?: string) => { + let typesData = await fetchData(`${apiUrl || ''}${API_ASSETS_TYPES_PATH}`, 'GET'); + + typesData = [ + ...typesData.map((d: any) => { + return { + value: d.name, + label: d.name + }; + }) + ]; + + return typesData; +}; + +export { + fetchTypes +} diff --git a/src/api/egeria-fetch.ts b/src/api/egeria-fetch.ts index f57dc8d..d1571ec 100644 --- a/src/api/egeria-fetch.ts +++ b/src/api/egeria-fetch.ts @@ -1,4 +1,7 @@ -import { handleResponse } from '../auth'; +import { + handleResponse, + authHeader +} from '../auth'; const egeriaFetch = (endpoint: string, method : string, headers : any, options: any) => { const requestOptions: any = { @@ -12,6 +15,18 @@ const egeriaFetch = (endpoint: string, method : string, headers : any, options: return fetch(`${apiUrl}${endpoint}`, requestOptions).then(handleResponse); } +const fetchData = async (uri: string, method: string, callback?: Function) => { + const res = await egeriaFetch(uri, method, {...authHeader()}, {}); + const data = await res.json(); + + if(callback) { + callback(data); + } else { + return data; + } +}; + export { - egeriaFetch + egeriaFetch, + fetchData }; \ No newline at end of file diff --git a/src/api/index.ts b/src/api/index.ts index 75e3570..3d69b42 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,7 +1,16 @@ import { glossaries } from './data/glossaries'; import { lineage } from './data/lineage'; import { types } from './data/types'; -import { egeriaFetch } from './egeria-fetch'; +import { egeriaFetch, fetchData } from './egeria-fetch'; +import { + fetchRawData, + fetchTypes +} from './assets'; + +import { + API_ASSETS_SEARCH_PATH, + API_ASSETS_TYPES_PATH +} from './routes'; const apiUrl = () => { return `${process.env.REACT_APP_API_URL}`; @@ -14,10 +23,15 @@ function goHome() { }; export { + API_ASSETS_SEARCH_PATH, + API_ASSETS_TYPES_PATH, apiUrl, egeriaFetch, + fetchData, + fetchRawData, + fetchTypes, glossaries, goHome, lineage, - types + types, } diff --git a/src/api/routes.ts b/src/api/routes.ts new file mode 100644 index 0000000..171cad8 --- /dev/null +++ b/src/api/routes.ts @@ -0,0 +1,7 @@ +const API_ASSETS_SEARCH_PATH = '/api/assets/search'; +const API_ASSETS_TYPES_PATH = '/api/assets/types'; + +export { + API_ASSETS_SEARCH_PATH, + API_ASSETS_TYPES_PATH +} \ No newline at end of file diff --git a/src/commons/constants.ts b/src/commons/constants.ts new file mode 100644 index 0000000..a299aee --- /dev/null +++ b/src/commons/constants.ts @@ -0,0 +1,9 @@ +const QUERY_MIN_LENGTH = 3; +const TYPES_MIN_SELECTED = 1; +const PAGE_SIZE_INCREASE_VALUE = 25; + +export { + PAGE_SIZE_INCREASE_VALUE, + QUERY_MIN_LENGTH, + TYPES_MIN_SELECTED +} \ No newline at end of file diff --git a/src/commons/helpers.ts b/src/commons/helpers.ts new file mode 100644 index 0000000..f8a0e49 --- /dev/null +++ b/src/commons/helpers.ts @@ -0,0 +1,37 @@ +import { formData } from '../types/formData'; +import { PAGE_SIZE_INCREASE_VALUE } from './constants'; + +const getQueryParamsPath = (formData: formData) => { + const {q, exactMatch, caseSensitive, types, pageSize } = formData; + + let queryParams = [] as any; + + if(q) { + queryParams.push(`q=${q}`); + } + + if(types && types.length > 0) { + queryParams.push(`types=${types.join(',')}`); + } + + queryParams.push(`exactMatch=${exactMatch}`); + queryParams.push(`caseSensitive=${caseSensitive}`); + queryParams.push(`pageSize=${pageSize}`); + + return queryParams; +}; + +const getQueryParams = (searchParams: any) => { + return { + q: searchParams.get('q') || '', + types: searchParams.get('types')?.split(',') || [], + exactMatch: searchParams.get('exactMatch') === "true" ? true : false, + caseSensitive: searchParams.get('caseSensitive') === "true" ? true : false, + pageSize: searchParams.get('pageSize') ? parseInt(searchParams.get('pageSize')) : PAGE_SIZE_INCREASE_VALUE + }; +}; + +export { + getQueryParams, + getQueryParamsPath +} \ No newline at end of file diff --git a/src/commons/index.ts b/src/commons/index.ts new file mode 100644 index 0000000..408c4e3 --- /dev/null +++ b/src/commons/index.ts @@ -0,0 +1,24 @@ +import { + QUERY_MIN_LENGTH, + TYPES_MIN_SELECTED, + PAGE_SIZE_INCREASE_VALUE +} from './constants'; + +import { + getQueryParams, + getQueryParamsPath +} from './helpers'; + +import { ASSET_CATALOG_PATH } from './paths'; + +export { + QUERY_MIN_LENGTH, + TYPES_MIN_SELECTED, + PAGE_SIZE_INCREASE_VALUE, + + getQueryParams, + getQueryParamsPath, + + ASSET_CATALOG_PATH +} + diff --git a/src/commons/paths.ts b/src/commons/paths.ts new file mode 100644 index 0000000..fd44d6a --- /dev/null +++ b/src/commons/paths.ts @@ -0,0 +1,5 @@ +const ASSET_CATALOG_PATH = '/assets/catalog'; + +export { + ASSET_CATALOG_PATH +} diff --git a/src/main.ts b/src/main.ts index e595e5c..a3129ef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,12 +19,17 @@ import { } from './get-component'; import { + API_ASSETS_SEARCH_PATH, + API_ASSETS_TYPES_PATH, apiUrl, egeriaFetch, + fetchData, + fetchRawData, + fetchTypes, glossaries, goHome, lineage, - types + types, } from './api'; import { @@ -38,6 +43,19 @@ import { setToken } from './auth'; +import { + QUERY_MIN_LENGTH, + TYPES_MIN_SELECTED, + PAGE_SIZE_INCREASE_VALUE, + getQueryParams, + getQueryParamsPath, + ASSET_CATALOG_PATH +} from './commons'; + +import { formData } from './types/formData'; + +export type { formData }; + export { apiUrl, authHeader, @@ -60,5 +78,12 @@ export { menuIcons, parseJwt, setToken, - types + types, + + ASSET_CATALOG_PATH, + PAGE_SIZE_INCREASE_VALUE, + getQueryParams, + getQueryParamsPath, + fetchTypes, + fetchRawData }; diff --git a/src/types/formData.ts b/src/types/formData.ts new file mode 100644 index 0000000..f5b99cb --- /dev/null +++ b/src/types/formData.ts @@ -0,0 +1,11 @@ +interface formData { + caseSensitive: boolean, + exactMatch: boolean, + pageSize: number, + q: string, + types: Array +} + +export type { + formData +} \ No newline at end of file From c30b146fe98dc633ee7cf371bdec072c7a8885f9 Mon Sep 17 00:00:00 2001 From: Sirbu Nicolae-Cezar Date: Thu, 13 Oct 2022 12:28:57 +0300 Subject: [PATCH 2/4] 4.0.1 Signed-off-by: Sirbu Nicolae-Cezar --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0814292..1a71ea1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "egeria-js-commons", - "version": "4.0.0", + "version": "4.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "egeria-js-commons", - "version": "4.0.0", + "version": "4.0.1", "license": "SEE LICENSE IN LICENSE", "devDependencies": { "@types/node": "^18.8.2", diff --git a/package.json b/package.json index e37679d..995be0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "egeria-js-commons", - "version": "4.0.0", + "version": "4.0.1", "description": "Egeria JS Commons repository, abstract JS library", "files": [ "dist" From 353010891ea493e67e0e51c1c21ee8c06d7880aa Mon Sep 17 00:00:00 2001 From: Sirbu Nicolae-Cezar Date: Thu, 13 Oct 2022 13:49:11 +0300 Subject: [PATCH 3/4] Add documentation for new functions Signed-off-by: Sirbu Nicolae-Cezar --- src/api/assets/search/index.ts | 11 +++++++++++ src/api/assets/types/index.ts | 7 +++++++ src/api/egeria-fetch.ts | 8 ++++++++ src/api/routes.ts | 3 +++ src/commons/constants.ts | 3 +++ src/commons/helpers.ts | 12 ++++++++++++ src/commons/paths.ts | 3 +++ src/types/formData.ts | 5 +++++ 8 files changed, 52 insertions(+) diff --git a/src/api/assets/search/index.ts b/src/api/assets/search/index.ts index 15884fc..4e4426a 100644 --- a/src/api/assets/search/index.ts +++ b/src/api/assets/search/index.ts @@ -4,6 +4,17 @@ import { formData } from '../../../types/formData'; import { fetchData } from '../../egeria-fetch'; import { getQueryParamsPath } from '../../../commons/helpers'; +/** + * + * @param formData should contain all the query params from the URL + * @param apiUrl is an optional parameter but it is used if API is deployed + * in a different location + * @returns empty array if conditions aren't met otherwise it will fetch data + * from the API + * + * This function is used to fetch data for Asset Catalog. + * + */ const fetchRawData = async (formData: formData, apiUrl?: string) => { const {q, types} = formData; diff --git a/src/api/assets/types/index.ts b/src/api/assets/types/index.ts index 6be8c1a..706cf86 100644 --- a/src/api/assets/types/index.ts +++ b/src/api/assets/types/index.ts @@ -2,6 +2,13 @@ import { API_ASSETS_TYPES_PATH } from '../../routes'; import { fetchData } from '../../egeria-fetch'; +/** + * @param apiUrl is an optional parameter but it is used if API is deployed + * in a different location + * + * This function is used to fetch Asset Types. + * +*/ const fetchTypes = async (apiUrl?: string) => { let typesData = await fetchData(`${apiUrl || ''}${API_ASSETS_TYPES_PATH}`, 'GET'); diff --git a/src/api/egeria-fetch.ts b/src/api/egeria-fetch.ts index d1571ec..c27cdf0 100644 --- a/src/api/egeria-fetch.ts +++ b/src/api/egeria-fetch.ts @@ -15,6 +15,14 @@ const egeriaFetch = (endpoint: string, method : string, headers : any, options: return fetch(`${apiUrl}${endpoint}`, requestOptions).then(handleResponse); } +/* + * @param uri is the full URL + * @param method usual fetch methods such as 'GET', 'POST', etc. + * @param callback this is an optional callback function that can be used + * in a different context to get the response and manage it + * in a custom manner + * @returns + */ const fetchData = async (uri: string, method: string, callback?: Function) => { const res = await egeriaFetch(uri, method, {...authHeader()}, {}); const data = await res.json(); diff --git a/src/api/routes.ts b/src/api/routes.ts index 171cad8..5117621 100644 --- a/src/api/routes.ts +++ b/src/api/routes.ts @@ -1,3 +1,6 @@ +/** + * CONSTANTS used for API URLs + */ const API_ASSETS_SEARCH_PATH = '/api/assets/search'; const API_ASSETS_TYPES_PATH = '/api/assets/types'; diff --git a/src/commons/constants.ts b/src/commons/constants.ts index a299aee..0dc6210 100644 --- a/src/commons/constants.ts +++ b/src/commons/constants.ts @@ -1,3 +1,6 @@ +/** + * CONSTANTS used through the entire application. + */ const QUERY_MIN_LENGTH = 3; const TYPES_MIN_SELECTED = 1; const PAGE_SIZE_INCREASE_VALUE = 25; diff --git a/src/commons/helpers.ts b/src/commons/helpers.ts index f8a0e49..fe8d30e 100644 --- a/src/commons/helpers.ts +++ b/src/commons/helpers.ts @@ -1,6 +1,12 @@ import { formData } from '../types/formData'; import { PAGE_SIZE_INCREASE_VALUE } from './constants'; +/** + * + * @param formData should contain all the query params from the URL + * @returns an array of query params prepared to be concatenated in order to + * form a valid URL path + */ const getQueryParamsPath = (formData: formData) => { const {q, exactMatch, caseSensitive, types, pageSize } = formData; @@ -21,6 +27,12 @@ const getQueryParamsPath = (formData: formData) => { return queryParams; }; +/** + * + * @param searchParams react-router-dom object that contains and object with all + * query params + * @returns a new object with validated query params input for Asset Catalog + */ const getQueryParams = (searchParams: any) => { return { q: searchParams.get('q') || '', diff --git a/src/commons/paths.ts b/src/commons/paths.ts index fd44d6a..48153bb 100644 --- a/src/commons/paths.ts +++ b/src/commons/paths.ts @@ -1,3 +1,6 @@ +/** + * CONSTANTS used for main application paths (deep linking). + */ const ASSET_CATALOG_PATH = '/assets/catalog'; export { diff --git a/src/types/formData.ts b/src/types/formData.ts index f5b99cb..8a06f80 100644 --- a/src/types/formData.ts +++ b/src/types/formData.ts @@ -1,3 +1,8 @@ + +/** + * Interface used for the Asset Catalog form. + * It's describing the attributes types used. + */ interface formData { caseSensitive: boolean, exactMatch: boolean, From 7db03cf58349f9cdd041f0e6c4aa2b7f96d7602d Mon Sep 17 00:00:00 2001 From: Sirbu Nicolae-Cezar Date: Thu, 13 Oct 2022 13:50:00 +0300 Subject: [PATCH 4/4] Regenerate dist Signed-off-by: Sirbu Nicolae-Cezar --- dist/esm/api/assets/search/index.js | 11 +++++++++++ dist/esm/api/assets/types/index.js | 7 +++++++ dist/esm/api/egeria-fetch.js | 8 ++++++++ dist/esm/api/routes.js | 3 +++ dist/esm/commons/constants.js | 3 +++ dist/esm/commons/helpers.js | 12 ++++++++++++ dist/esm/commons/paths.js | 3 +++ dist/types/api/assets/search/index.d.ts | 11 +++++++++++ dist/types/api/assets/types/index.d.ts | 7 +++++++ dist/types/api/routes.d.ts | 3 +++ dist/types/commons/constants.d.ts | 3 +++ dist/types/commons/helpers.d.ts | 12 ++++++++++++ dist/types/commons/paths.d.ts | 3 +++ dist/types/types/formData.d.ts | 4 ++++ 14 files changed, 90 insertions(+) diff --git a/dist/esm/api/assets/search/index.js b/dist/esm/api/assets/search/index.js index 369fb6c..80b2e9b 100644 --- a/dist/esm/api/assets/search/index.js +++ b/dist/esm/api/assets/search/index.js @@ -11,6 +11,17 @@ import { API_ASSETS_SEARCH_PATH } from '../../routes'; import { QUERY_MIN_LENGTH, TYPES_MIN_SELECTED } from '../../../commons/constants'; import { fetchData } from '../../egeria-fetch'; import { getQueryParamsPath } from '../../../commons/helpers'; +/** + * + * @param formData should contain all the query params from the URL + * @param apiUrl is an optional parameter but it is used if API is deployed + * in a different location + * @returns empty array if conditions aren't met otherwise it will fetch data + * from the API + * + * This function is used to fetch data for Asset Catalog. + * + */ const fetchRawData = (formData, apiUrl) => __awaiter(void 0, void 0, void 0, function* () { const { q, types } = formData; if (q.length >= QUERY_MIN_LENGTH && types.length >= TYPES_MIN_SELECTED) { diff --git a/dist/esm/api/assets/types/index.js b/dist/esm/api/assets/types/index.js index 701e4df..77fdf3d 100644 --- a/dist/esm/api/assets/types/index.js +++ b/dist/esm/api/assets/types/index.js @@ -9,6 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; import { API_ASSETS_TYPES_PATH } from '../../routes'; import { fetchData } from '../../egeria-fetch'; +/** + * @param apiUrl is an optional parameter but it is used if API is deployed + * in a different location + * + * This function is used to fetch Asset Types. + * +*/ const fetchTypes = (apiUrl) => __awaiter(void 0, void 0, void 0, function* () { let typesData = yield fetchData(`${apiUrl || ''}${API_ASSETS_TYPES_PATH}`, 'GET'); typesData = [ diff --git a/dist/esm/api/egeria-fetch.js b/dist/esm/api/egeria-fetch.js index e70cb54..0c747a1 100644 --- a/dist/esm/api/egeria-fetch.js +++ b/dist/esm/api/egeria-fetch.js @@ -13,6 +13,14 @@ const egeriaFetch = (endpoint, method, headers, options) => { const apiUrl = process.env.REACT_APP_API_URL || ''; return fetch(`${apiUrl}${endpoint}`, requestOptions).then(handleResponse); }; +/* + * @param uri is the full URL + * @param method usual fetch methods such as 'GET', 'POST', etc. + * @param callback this is an optional callback function that can be used + * in a different context to get the response and manage it + * in a custom manner + * @returns + */ const fetchData = (uri, method, callback) => __awaiter(void 0, void 0, void 0, function* () { const res = yield egeriaFetch(uri, method, Object.assign({}, authHeader()), {}); const data = yield res.json(); diff --git a/dist/esm/api/routes.js b/dist/esm/api/routes.js index 8b225ce..f0e0372 100644 --- a/dist/esm/api/routes.js +++ b/dist/esm/api/routes.js @@ -1,3 +1,6 @@ +/** + * CONSTANTS used for API URLs + */ const API_ASSETS_SEARCH_PATH = '/api/assets/search'; const API_ASSETS_TYPES_PATH = '/api/assets/types'; export { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH }; diff --git a/dist/esm/commons/constants.js b/dist/esm/commons/constants.js index afac369..c81626b 100644 --- a/dist/esm/commons/constants.js +++ b/dist/esm/commons/constants.js @@ -1,3 +1,6 @@ +/** + * CONSTANTS used through the entire application. + */ const QUERY_MIN_LENGTH = 3; const TYPES_MIN_SELECTED = 1; const PAGE_SIZE_INCREASE_VALUE = 25; diff --git a/dist/esm/commons/helpers.js b/dist/esm/commons/helpers.js index 747dfe7..4bb42fe 100644 --- a/dist/esm/commons/helpers.js +++ b/dist/esm/commons/helpers.js @@ -1,4 +1,10 @@ import { PAGE_SIZE_INCREASE_VALUE } from './constants'; +/** + * + * @param formData should contain all the query params from the URL + * @returns an array of query params prepared to be concatenated in order to + * form a valid URL path + */ const getQueryParamsPath = (formData) => { const { q, exactMatch, caseSensitive, types, pageSize } = formData; let queryParams = []; @@ -13,6 +19,12 @@ const getQueryParamsPath = (formData) => { queryParams.push(`pageSize=${pageSize}`); return queryParams; }; +/** + * + * @param searchParams react-router-dom object that contains and object with all + * query params + * @returns a new object with validated query params input for Asset Catalog + */ const getQueryParams = (searchParams) => { var _a; return { diff --git a/dist/esm/commons/paths.js b/dist/esm/commons/paths.js index 6b4e5a4..8432e9d 100644 --- a/dist/esm/commons/paths.js +++ b/dist/esm/commons/paths.js @@ -1,2 +1,5 @@ +/** + * CONSTANTS used for main application paths (deep linking). + */ const ASSET_CATALOG_PATH = '/assets/catalog'; export { ASSET_CATALOG_PATH }; diff --git a/dist/types/api/assets/search/index.d.ts b/dist/types/api/assets/search/index.d.ts index 14b7c01..67520b1 100644 --- a/dist/types/api/assets/search/index.d.ts +++ b/dist/types/api/assets/search/index.d.ts @@ -1,3 +1,14 @@ import { formData } from '../../../types/formData'; +/** + * + * @param formData should contain all the query params from the URL + * @param apiUrl is an optional parameter but it is used if API is deployed + * in a different location + * @returns empty array if conditions aren't met otherwise it will fetch data + * from the API + * + * This function is used to fetch data for Asset Catalog. + * + */ declare const fetchRawData: (formData: formData, apiUrl?: string) => Promise; export { fetchRawData }; diff --git a/dist/types/api/assets/types/index.d.ts b/dist/types/api/assets/types/index.d.ts index 553453d..890a935 100644 --- a/dist/types/api/assets/types/index.d.ts +++ b/dist/types/api/assets/types/index.d.ts @@ -1,2 +1,9 @@ +/** + * @param apiUrl is an optional parameter but it is used if API is deployed + * in a different location + * + * This function is used to fetch Asset Types. + * +*/ declare const fetchTypes: (apiUrl?: string) => Promise; export { fetchTypes }; diff --git a/dist/types/api/routes.d.ts b/dist/types/api/routes.d.ts index d59aec3..6faa610 100644 --- a/dist/types/api/routes.d.ts +++ b/dist/types/api/routes.d.ts @@ -1,3 +1,6 @@ +/** + * CONSTANTS used for API URLs + */ declare const API_ASSETS_SEARCH_PATH = "/api/assets/search"; declare const API_ASSETS_TYPES_PATH = "/api/assets/types"; export { API_ASSETS_SEARCH_PATH, API_ASSETS_TYPES_PATH }; diff --git a/dist/types/commons/constants.d.ts b/dist/types/commons/constants.d.ts index 00d3827..c4178dd 100644 --- a/dist/types/commons/constants.d.ts +++ b/dist/types/commons/constants.d.ts @@ -1,3 +1,6 @@ +/** + * CONSTANTS used through the entire application. + */ declare const QUERY_MIN_LENGTH = 3; declare const TYPES_MIN_SELECTED = 1; declare const PAGE_SIZE_INCREASE_VALUE = 25; diff --git a/dist/types/commons/helpers.d.ts b/dist/types/commons/helpers.d.ts index 15b72c1..03a1a3a 100644 --- a/dist/types/commons/helpers.d.ts +++ b/dist/types/commons/helpers.d.ts @@ -1,5 +1,17 @@ import { formData } from '../types/formData'; +/** + * + * @param formData should contain all the query params from the URL + * @returns an array of query params prepared to be concatenated in order to + * form a valid URL path + */ declare const getQueryParamsPath: (formData: formData) => any; +/** + * + * @param searchParams react-router-dom object that contains and object with all + * query params + * @returns a new object with validated query params input for Asset Catalog + */ declare const getQueryParams: (searchParams: any) => { q: any; types: any; diff --git a/dist/types/commons/paths.d.ts b/dist/types/commons/paths.d.ts index 84881d9..3302ad8 100644 --- a/dist/types/commons/paths.d.ts +++ b/dist/types/commons/paths.d.ts @@ -1,2 +1,5 @@ +/** + * CONSTANTS used for main application paths (deep linking). + */ declare const ASSET_CATALOG_PATH = "/assets/catalog"; export { ASSET_CATALOG_PATH }; diff --git a/dist/types/types/formData.d.ts b/dist/types/types/formData.d.ts index 4a984f3..43d3084 100644 --- a/dist/types/types/formData.d.ts +++ b/dist/types/types/formData.d.ts @@ -1,3 +1,7 @@ +/** + * Interface used for the Asset Catalog form. + * It's describing the attributes types used. + */ interface formData { caseSensitive: boolean; exactMatch: boolean;