UNPKG

@gpa-gemstone/common-pages

Version:
116 lines (115 loc) 5.14 kB
"use strict"; //****************************************************************************************************** // Gemstone.tsx - Gbtc // // Copyright (c) 2025, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA may license this file to you under the MIT License (MIT), the "License"; you may not use this // file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 09/12/2025 - Preston Crawford // Generated original version of source code. // //****************************************************************************************************** Object.defineProperty(exports, "__esModule", { value: true }); exports.Gemstone = void 0; var Gemstone; (function (Gemstone) { var HelperFunctions; (function (HelperFunctions) { /** * Builds an array of Types.ISearchFilter<T> from an array of Search.IFilter<T> * @param searchFilter Array of Search.IFilter<T> * @returns Array of Gemstone.Types.ISearchFilter<T> */ HelperFunctions.getSearchFilter = function (searchFilter) { return searchFilter.map(function (s) { var castValue = function (val) { switch (s.Type) { case 'number': case 'integer': return Number(val); case 'boolean': return val === '1'; default: return val; } }; var searchText = s.SearchText; if (s.Operator === 'IN' || s.Operator === 'NOT IN') { if (searchText.startsWith('(') && searchText.endsWith(')')) searchText = searchText .slice(1, -1) .split(',') .map(function (v) { return v.trim(); }); } var searchParameter; if (Array.isArray(searchText)) { searchParameter = searchText.map(function (v) { return castValue(v); }); } else { searchParameter = castValue(searchText); } return { FieldName: s.FieldName, SearchParameter: searchParameter, Operator: s.Operator }; }); }; /** * Builds an array of Search.IFilter<T> from an array of Gemstone.Types.ISearchFilter<T> * @param filters Array of Gemstone.Types.ISearchFilter<T> * @returns Array of Search.IFilter<T> */ HelperFunctions.buildSearchFilter = function (filters) { return filters.map(function (f) { var toStringValue = function (val) { if (typeof val === 'boolean') { return val ? '1' : '0'; } return String(val); }; var searchText; if (Array.isArray(f.SearchParameter)) { // Cover IN / NOT IN case var values = f.SearchParameter.map(function (v) { return toStringValue(v); }); searchText = "(".concat(values.join(','), ")"); } else { searchText = toStringValue(f.SearchParameter); } var type; switch (typeof f.SearchParameter) { case 'number': type = Number.isInteger(f.SearchParameter) ? 'integer' : 'number'; break; case 'boolean': type = 'boolean'; break; default: type = 'string'; } return { FieldName: f.FieldName, SearchText: searchText, Operator: f.Operator, Type: type, IsPivotColumn: false // Defaulting to false as this info is not available here }; }); }; })(HelperFunctions = Gemstone.HelperFunctions || (Gemstone.HelperFunctions = {})); })(Gemstone || (exports.Gemstone = Gemstone = {}));