@gisatcz/ptr-be-core 0.0.6 → 0.0.8

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.
package/Readme.md CHANGED
@@ -1,5 +1,29 @@
1
- # Shared Library for Panther Backend
2
- This repository contains source of shared functionalities across Panther backend services.
1
+ # NPM Library for Panther Backends
2
+ NPM package with shared functionalities across Panther projects (FE and BE).
3
+
4
+ ## Build and Outputs
5
+ The NPM contains two standalone builds made from Typescript by Rollup.
6
+
7
+ - Globals NPM (FE + BE):
8
+ - From `index.browser.ts` containing exports from `src/globals/**/*`.
9
+ - This is shared functionality between FE and BE services like models, code helpers etc..
10
+
11
+ - Node NPM:
12
+ - Containes all from globals
13
+ - By `index.node.ts` containing exports from `src/node/**/*`. This is Node JS only funtionality. Everything with peer dependency to Node.js packages should be here.
14
+
15
+ Production build and publishing is realised by Github Workflow.
16
+
17
+ ## Configuration Files
18
+ As mentioned, Rollup set up in `rollup.config.js` make two standalone builds named by purpose.
19
+
20
+ Important is setup in `package.json`
21
+ - `type` with value `module`
22
+ - `exports`, each for one NPM target
23
+ - Empty `dependencies`.
24
+ - All required dependencies defined in `peerDependencies` field.
25
+
26
+ Each build platform has defined standalone `tsconfig` in the repository root. Final `tsconfig.json` is merged together by platform or purpose.
3
27
 
4
28
  ## Installation (DEV)
5
29
  - Install Node and NPM
@@ -12,11 +36,14 @@ This repository contains source of shared functionalities across Panther backend
12
36
  - Run `npm run dev` for development mode with Rollup build watcher and auto yalc publishing.
13
37
 
14
38
  ## Usage in Applications
15
- - FE based apps should use imports from `@gisatcz/ptr-be-core/browser`
16
- - NodeJS based apps should use imports from `@gisatcz/ptr-be-core/node`
39
+ - FE apps (in browser) should use imports from `@gisatcz/ptr-be-core/browser`
40
+ - Node.js apps and NextJS backend routes should use imports from `@gisatcz/ptr-be-core/node`
17
41
 
18
42
  ## Resources
19
43
  - YALC (local NPM): https://github.com/wclr/yalc
20
44
  - Vitest (testing): https://vitest.dev
21
45
  - Barrelsby (TS Imports into one `index.ts`): https://github.com/bencoveney/barrelsby
22
46
  - Rollup (NPM package build): https://rollupjs.org
47
+
48
+ ## AI Agents (Important)
49
+ Please folow instructions in `.github/` for better code results.
@@ -115,11 +115,6 @@ const flattenObject = (obj, prefix = '') => {
115
115
  }, {});
116
116
  };
117
117
 
118
- /**
119
- * Extract message from exception error (try-catch)
120
- * @param error error from catch block as any
121
- * @returns
122
- */
123
118
  /**
124
119
  * We miss a API parameter needed to process action
125
120
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.js","sources":["../src/globals/coding/code.formating.ts","../src/node/api/errors.api.ts","../src/globals/coding/code.dates.ts","../src/globals/coding/formats.csv.ts","../src/globals/panther/utils.panther.ts","../src/globals/panther/enums.panther.ts"],"sourcesContent":["/**\n * Check, if the string is url\n * @param candidate Candidate input, to be checked\n * @returns Is this string url?\n */\nexport const isUrl = (candidate: string) => {\n try {\n new URL(candidate)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Check, if the string array contain urls\n * @param candidates Candidate input array, to be checked\n * @returns Is this string array only from url?\n */\nexport const isArrayOfUrls = (candidates: string[]) => candidates.every(candidate => isUrl(candidate))\n\n/**\n * Check if the value in included in enum posibilities.\n * @param value Value we need to check\n * @param enumEntity Enum type we check againts the value\n * @returns Is the value in this enum?\n */\nexport const isInEnum = (value: any, enumEntity: any) => {\n const allEnumValues = Object.values(enumEntity) as string[]\n return allEnumValues.includes(value)\n }\n\n/**\n * Sort array of string elements\n * @param rawArray Raw unsorted array of elements\n * @returns Sorted string array\n */\nexport const sortStringArray = (rawArray: string[]) => rawArray.sort()\n\n/**\n * Remove all duplicity string items from an array\n * @param arr Original array with duplicities\n * @returns Array of original values\n */\nexport const removeDuplicitiesFromArray = (arr: any[]) => [...new Set(arr)]\n\n\n/**\n * Check if the string value is not ` \"\" `\n * @param value Value to check\n * @returns Boolean result about the truth\n */\nexport const notEmptyString = (value: string) => value !== \"\"\n\n\n/**\n * Return enum values as array of string\n * @param enumType Type of the enum from code\n * @param separator Optional - separator character\n * @returns Array of enum possible values\n */\nexport const enumValuesToString = (enumType: any, separator = \", \") => Object.values(enumType).join(separator)\n\n/**\n * Return enum values as array of string\n * @param enumTypes Combination of enum types\n * @param separator Optional - separator character\n * @returns Array of enum possible values\n */\nexport const enumCombineValuesToString = (enumTypes: any[], separator = \", \") => enumTypes.map(enumType => enumValuesToString(enumType, separator)).join(separator)\n\n/**\n * Return all enum values as array\n * @param enumType What array we want to work with\n * @returns Array of enum values\n */\nexport const enumValuesToArray = (enumType: any) => Object.values(enumType) as string[]\n\n/**\n * Return random number (integer) between two values\n * @param min \n * @param max \n * @returns \n */\nexport const randomNumberBetween = (min: number, max: number) => {\n const minAr = Math.ceil(min)\n const maxAr = Math.floor(max)\n return Math.floor(Math.random()*(maxAr - minAr + 1) + min)\n}\n\n/**\n * Recursively flattens a nested object. The keys of the resulting object\n * will be the paths to the original values in the nested object, joined by dots.\n *\n * @param obj - The object to flatten.\n * @param prefix - The prefix to use for the keys in the flattened object. Defaults to an empty string.\n * @returns A new object with flattened keys.\n *\n * @example\n * ```typescript\n * const nestedObj = {\n * a: {\n * b: {\n * c: 1\n * }\n * },\n * d: 2\n * };\n * const flatObj = flattenObject(nestedObj);\n * console.log(flatObj);\n * // Output: { 'a.b.c': 1, 'a.b.d': 2 }\n * ```\n */\nexport const flattenObject = (obj: any, prefix = ''): Record<string, any> => {\n return Object.keys(obj).reduce((acc: Record<string, any>, key: string) => {\n const propName = prefix ? `${prefix}.${key}` : key\n if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {\n Object.assign(acc, flattenObject(obj[key], propName))\n } else {\n acc[propName] = obj[key]\n }\n return acc\n }, {})\n}","/**\n * Extract message from exception error (try-catch)\n * @param error error from catch block as any\n * @returns \n */\n export const messageFromError = (error: any) => error[\"message\"] as string\n\n/**\n * We miss a API parameter needed to process action\n */\nexport class InvalidRequestError extends Error{\n constructor(message: string){\n super(`Invalid Request: ${message}`)\n }\n}\n\n/**\n * Where client has general authorization issue\n */\nexport class AuthorizationError extends Error{\n constructor(){\n super(`Authorization has failed.`)\n }\n}","import { DateTime } from \"luxon\"\nimport { InvalidRequestError } from \"../../node/api/errors.api\"\n\n/**\n * Return epoch timestamp\n * @param regime Set if you want milisecond format or second format\n * @returns \n */\nexport const nowTimestamp = (regime: \"milisecond\" | \"second\" = \"milisecond\"): number => {\n const timestamp = DateTime.now().toMillis()\n return regime === \"second\" ? Math.round((timestamp / 1000)) : timestamp\n}\n\n/**\n * Return now local timestamp plus number of seconds to add\n * @param secondsToAdd Seconds to add from now (1 = now + 1 sec.)\n * @returns Timestamp of the future (past) on seconds\n */\nexport const nowPlusTime = (secondsToAdd: number) => {\n return Math.round(DateTime.now().plus({seconds: secondsToAdd}).toSeconds())\n}\n\n/**\n * Convert epoch time value into ISO format\n * @param epochValue Epoch value of the timestamp\n * @returns ISO format of the date\n */\nexport const epochToIsoFormat = (epochValue: number) => DateTime.fromMillis(epochValue).toISO() as string\n\n/**\n * Return epoch timestamp\n * @param regime Set if you want milisecond format or second format\n * @returns \n */\nexport const nowTimestampIso = () => {\n const timestamp = DateTime.now().toISO()\n return timestamp as string\n}\n\n/**\n * Check if input date is valid for ISO format\n * @param dateToCheck \n * @returns \n */\n export const hasIsoFormat = (dateToCheck: string) => {\n try{\n const toDate = new Date(Date.parse(dateToCheck))\n const isoCheck = toDate.toISOString().includes(dateToCheck) \n return isoCheck\n }\n catch{\n return false\n }\n}\n\n/**\n * Convert date in ISO formtat to milisecond timestamp\n * @param isoDate Date in ISO 8601 format\n * @returns Timestamp representing the date in miliseconds\n */\nexport const isoDateToTimestamp = (isoDate: string) => DateTime.fromISO(isoDate).toMillis()\n\n/**\n * Format ISO 8601 interval to from-to values\n * @param interval Defined inteval in ISO format (from/to) of the UTC\n * @returns Tuple - from timestamp and to timestamp\n */\nexport const isoIntervalToTimestamps = (interval: string): [number, number] => {\n\n // Split the interval into two parts\n const intervals = interval.split(\"/\")\n\n // interval as a single year has just one part\n if (intervals.length == 1) {\n const newIso = `${interval}-01-01/${interval}-12-31`\n return isoIntervalToTimestamps(newIso)\n }\n\n // interval with two parts or less than one\n else if (intervals.length > 2 || intervals.length < 1)\n throw new InvalidRequestError(\"Interval can have only two parameters\")\n\n // valid interval with two parts\n else {\n if (!intervals.every(interval => hasIsoFormat(interval)))\n throw new InvalidRequestError(\"Parameter utcIntervalIso is not ISO 8601 time interval (date01/date02) or year\");\n\n const [int1, int2] = intervals.map(intervalIso => {\n const cleared = intervalIso.replace(\" \", \"\")\n return isoDateToTimestamp(cleared)\n })\n\n return [int1, int2]\n }\n}\n","// TODO: Cover by tests\n// TODO: mode to ptr-be-core as general CSV methods\n\n\n/**\n * Parses a single line of CSV-formatted strings into an array of trimmed string values.\n *\n * @param csvStingsLine - A string representing a single line of comma-separated values.\n * @returns An array of strings, each representing a trimmed value from the CSV line.\n */\nexport const csvParseStrings = (csvStingsLine: string): string[] => {\n return csvStingsLine.split(\",\").map((value: string) => value.trim());\n}\n\n/**\n * Parses a comma-separated string of numbers into an array of numbers.\n *\n * @param csvNumbersLine - A string containing numbers separated by commas (e.g., \"1, 2, 3.5\").\n * @returns An array of numbers parsed from the input string.\n */\nexport const csvParseNumbers = (csvNumbersLine: string): number[] => {\n return csvNumbersLine.split(\",\").map((value: string) => parseFloat(value.trim()));\n}","import { UsedDatasourceLabels, UsedEdgeLabels, UsedNodeLabels } from \"./enums.panther\"\nimport { GraphEdge } from \"./models.edges\"\nimport { FullPantherEntity } from \"./models.nodes\"\n\n/**\n * Finds the first node in the provided list that contains the specified label.\n *\n * Searches the given array of FullPantherEntity objects and returns the first entity\n * whose `labels` array includes the provided label.\n *\n * @param nodes - Array of FullPantherEntity objects to search through.\n * @param label - Label to match; may be a UsedDatasourceLabels or UsedNodeLabels.\n * @returns The first FullPantherEntity whose `labels` includes `label`, or `undefined`\n * if no such entity is found.\n *\n * @remarks\n * - The search stops at the first match (uses `Array.prototype.find`).\n * - Label comparison is exact (uses `Array.prototype.includes`), so it is case-sensitive\n * and requires the same string instance/value.\n *\n * @example\n * const result = findNodeByLabel(nodes, 'datasource-main');\n * if (result) {\n * // found a node that has the 'datasource-main' label\n * }\n */\nexport const findNodeByLabel = (\n nodes: FullPantherEntity[],\n label: UsedDatasourceLabels | UsedNodeLabels): FullPantherEntity | undefined => {\n return nodes.find(n => n.labels.includes(label))\n}\n\n/**\n * Filters an array of FullPantherEntity objects, returning only those that contain the specified label.\n *\n * The function performs a shallow, non-mutating filter: it returns a new array and does not modify the input.\n * Matching is done using Array.prototype.includes on each entity's `labels` array (strict equality).\n *\n * @param nodes - The array of entities to filter.\n * @param label - The label to match; can be a UsedDatasourceLabels or UsedNodeLabels value.\n * @returns A new array containing only the entities whose `labels` array includes the provided label.\n *\n * @remarks\n * Time complexity is O(n * m) where n is the number of entities and m is the average number of labels per entity.\n *\n * @example\n * ```ts\n * const matched = filterNodeByLabel(entities, 'MY_LABEL');\n * ```\n */\nexport const filterNodeByLabel = (\n nodes: FullPantherEntity[],\n label: UsedDatasourceLabels | UsedNodeLabels): FullPantherEntity[] => {\n return nodes.filter(n => n.labels.includes(label))\n}\n\n/**\n * Finds the first edge in the provided array whose label strictly equals the given label.\n *\n * @param edges - Array of GraphEdge objects to search.\n * @param label - The UsedEdgeLabels value to match against each edge's `label` property.\n * @returns The first matching GraphEdge if found; otherwise `undefined`.\n *\n * @example\n * const edge = findEdgeByLabel(edges, 'dependency');\n * if (edge) {\n * // handle found edge\n * }\n */\nexport const findEdgeByLabel = (\n edges: GraphEdge[],\n label: UsedEdgeLabels): GraphEdge | undefined => {\n return edges.find(e => e.label === label)\n}\n\n/**\n * Filters a list of GraphEdge objects by a specific edge label.\n *\n * Returns a new array containing only those edges whose `label` property\n * strictly equals the provided `label` argument. The original `edges`\n * array is not mutated.\n *\n * @param edges - Array of GraphEdge objects to filter.\n * @param label - The label to match; comparison is performed using strict (`===`) equality.\n * @returns A new array of GraphEdge objects whose `label` matches the provided label. Returns an empty array if no edges match.\n *\n * @remarks\n * Time complexity: O(n), where n is the number of edges.\n *\n * @example\n * // const result = filterEdgeByLabel(edges, 'CONNECTS');\n */\nexport const filterEdgeByLabel = (\n edges: GraphEdge[],\n label: UsedEdgeLabels): GraphEdge[] => {\n return edges.filter(e => e.label === label)\n}","/**\n * What types of graph nodes we use in metadata model\n */\nexport enum UsedNodeLabels {\n Application = \"application\", // Application node (the root of the FE app)\n Datasource = \"datasource\", // Datasource node for data including GIS information\n Place = \"place\", // Place node for geographical information\n Period = \"period\", // Period node for time information\n AreaTree = \"areaTree\", // Area tree node for administrative division\n AreaTreeLevel = \"areaTreeLevel\", // Area tree level node for administrative division\n Layer = \"layer\", // Layer node for map layer (layer have a style and a datasource)\n Style = \"style\", // Style node for map layer or a feature\n Feature = \"feature\", // Feature node for map layer,\n Attribute = \"attribute\" // Attribute node for properties of entities, like \"temperature\", \"population\", etc.\n}\n\n/**\n * What datasources we use in the system\n */\nexport enum UsedDatasourceLabels {\n Attribute = \"attributeSource\", // Column(s) with attribute values\n Geojson = \"geojson\", // Geojson for web map\n WMS = \"wms\", // WMS online source\n COG = \"cloudOptimizedGeotiff\", // COG online source\n MVT = \"mvt\", // MVT (Mapbox Vector Tiles) source\n XYZ = \"xyz\", // XYZ tile source\n CSV = \"csv\", // CSV data source\n GeoTIFF = \"geotiff\", // GeoTIFF raster data\n Shapefile = \"shapefile\", // ESRI Shapefile format\n PostGIS = \"postgis\", // PostGIS database source\n WMTS = \"wmts\", // Web Map Tile Service\n WFS = \"wfs\", // Web Feature Service\n GeoPackage = \"geopackage\", // OGC GeoPackage format\n MapStyle = \"mapStyle\", // Map style datasource\n Timeseries = \"timeseries\" // Timeseries datasource (with from-to and step)\n}\n\n/**\n * What types of edges we use in metadata model\n */\nexport enum UsedEdgeLabels {\n RelatedTo = \"RELATED\", // Generic edge for any relation\n Has = \"HAS\", // Edge for ownership relation\n InPostgisLocation = \"IN_POSTGIS_LOCATION\" // Edge to connect datasource with PostGIS location (schema, table, geometry column)\n}\n\n/**\n * What time steps are used in timeseries data\n */\nexport enum UsedTimeseriesSteps{\n Year = \"year\",\n Quarter = \"quarter\",\n Month = \"month\",\n Week = \"week\",\n Day = \"day\"\n}"],"names":[],"mappings":";;AAAA;;;;AAIG;AACI,MAAM,KAAK,GAAG,CAAC,SAAiB,KAAI;AACzC,IAAA,IAAI;AACF,QAAA,IAAI,GAAG,CAAC,SAAS,CAAC;AAClB,QAAA,OAAO,IAAI;IACb;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,KAAK;IACd;AACF;AAEA;;;;AAIG;MACU,aAAa,GAAG,CAAC,UAAoB,KAAK,UAAU,CAAC,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC;AAErG;;;;;AAKG;MACU,QAAQ,GAAG,CAAC,KAAU,EAAE,UAAe,KAAI;IACpD,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAa;AAC3D,IAAA,OAAO,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC;AACtC;AAEF;;;;AAIG;AACI,MAAM,eAAe,GAAG,CAAC,QAAkB,KAAK,QAAQ,CAAC,IAAI;AAEpE;;;;AAIG;AACI,MAAM,0BAA0B,GAAG,CAAC,GAAU,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC;AAG1E;;;;AAIG;AACI,MAAM,cAAc,GAAG,CAAC,KAAa,KAAK,KAAK,KAAK;AAG3D;;;;;AAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,QAAa,EAAE,SAAS,GAAG,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS;AAE7G;;;;;AAKG;AACI,MAAM,yBAAyB,GAAG,CAAC,SAAgB,EAAE,SAAS,GAAG,IAAI,KAAK,SAAS,CAAC,GAAG,CAAC,QAAQ,IAAI,kBAAkB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,IAA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AW;IACX,cAAA,CAAA,mBAAA,CAAA,GAAA,qBAAyC,CAAA;AAC7C,CAAC,EAJW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;AAM1B;;AAEG;IACS;AAAZ,CAAA,UAAY,mBAAmB,EAAA;AAC3B,IAAA,mBAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,mBAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,mBAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACf,IAAA,mBAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,mBAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACf,CAAC,EANW,mBAAmB,KAAnB,mBAAmB,GAAA,EAAA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"index.browser.js","sources":["../src/globals/coding/code.formating.ts","../src/node/api/models.errors.ts","../src/globals/coding/code.dates.ts","../src/globals/coding/formats.csv.ts","../src/globals/panther/utils.panther.ts","../src/globals/panther/enums.panther.ts"],"sourcesContent":["/**\n * Check, if the string is url\n * @param candidate Candidate input, to be checked\n * @returns Is this string url?\n */\nexport const isUrl = (candidate: string) => {\n try {\n new URL(candidate)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Check, if the string array contain urls\n * @param candidates Candidate input array, to be checked\n * @returns Is this string array only from url?\n */\nexport const isArrayOfUrls = (candidates: string[]) => candidates.every(candidate => isUrl(candidate))\n\n/**\n * Check if the value in included in enum posibilities.\n * @param value Value we need to check\n * @param enumEntity Enum type we check againts the value\n * @returns Is the value in this enum?\n */\nexport const isInEnum = (value: any, enumEntity: any) => {\n const allEnumValues = Object.values(enumEntity) as string[]\n return allEnumValues.includes(value)\n }\n\n/**\n * Sort array of string elements\n * @param rawArray Raw unsorted array of elements\n * @returns Sorted string array\n */\nexport const sortStringArray = (rawArray: string[]) => rawArray.sort()\n\n/**\n * Remove all duplicity string items from an array\n * @param arr Original array with duplicities\n * @returns Array of original values\n */\nexport const removeDuplicitiesFromArray = (arr: any[]) => [...new Set(arr)]\n\n\n/**\n * Check if the string value is not ` \"\" `\n * @param value Value to check\n * @returns Boolean result about the truth\n */\nexport const notEmptyString = (value: string) => value !== \"\"\n\n\n/**\n * Return enum values as array of string\n * @param enumType Type of the enum from code\n * @param separator Optional - separator character\n * @returns Array of enum possible values\n */\nexport const enumValuesToString = (enumType: any, separator = \", \") => Object.values(enumType).join(separator)\n\n/**\n * Return enum values as array of string\n * @param enumTypes Combination of enum types\n * @param separator Optional - separator character\n * @returns Array of enum possible values\n */\nexport const enumCombineValuesToString = (enumTypes: any[], separator = \", \") => enumTypes.map(enumType => enumValuesToString(enumType, separator)).join(separator)\n\n/**\n * Return all enum values as array\n * @param enumType What array we want to work with\n * @returns Array of enum values\n */\nexport const enumValuesToArray = (enumType: any) => Object.values(enumType) as string[]\n\n/**\n * Return random number (integer) between two values\n * @param min \n * @param max \n * @returns \n */\nexport const randomNumberBetween = (min: number, max: number) => {\n const minAr = Math.ceil(min)\n const maxAr = Math.floor(max)\n return Math.floor(Math.random()*(maxAr - minAr + 1) + min)\n}\n\n/**\n * Recursively flattens a nested object. The keys of the resulting object\n * will be the paths to the original values in the nested object, joined by dots.\n *\n * @param obj - The object to flatten.\n * @param prefix - The prefix to use for the keys in the flattened object. Defaults to an empty string.\n * @returns A new object with flattened keys.\n *\n * @example\n * ```typescript\n * const nestedObj = {\n * a: {\n * b: {\n * c: 1\n * }\n * },\n * d: 2\n * };\n * const flatObj = flattenObject(nestedObj);\n * console.log(flatObj);\n * // Output: { 'a.b.c': 1, 'a.b.d': 2 }\n * ```\n */\nexport const flattenObject = (obj: any, prefix = ''): Record<string, any> => {\n return Object.keys(obj).reduce((acc: Record<string, any>, key: string) => {\n const propName = prefix ? `${prefix}.${key}` : key\n if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {\n Object.assign(acc, flattenObject(obj[key], propName))\n } else {\n acc[propName] = obj[key]\n }\n return acc\n }, {})\n}","/**\n * We miss a API parameter needed to process action\n */\nclass InvalidRequestError extends Error{\n constructor(message: string){\n super(`Invalid Request: ${message}`)\n }\n}\n\n/**\n * Where client has general authorization issue\n */\nclass AuthorizationError extends Error{\n constructor(){\n super(`Authorization has failed.`)\n }\n}\n\n/**\n * General backend server side error\n */\nclass ServerError extends Error{\n constructor(message: string){\n super(`Server Error: ${message}`)\n }\n}\n\n/**\n * Error to indicate that some functionality is SSR only\n */\nclass SSROnlyError extends Error{\n constructor(message: string){\n super(`SSR Only Error: ${message}`)\n }\n}\n\nexport {\n InvalidRequestError,\n AuthorizationError,\n ServerError,\n SSROnlyError\n} ","import { DateTime } from \"luxon\"\nimport { InvalidRequestError } from \"../../node/api/models.errors\"\n\n/**\n * Return epoch timestamp\n * @param regime Set if you want milisecond format or second format\n * @returns \n */\nexport const nowTimestamp = (regime: \"milisecond\" | \"second\" = \"milisecond\"): number => {\n const timestamp = DateTime.now().toMillis()\n return regime === \"second\" ? Math.round((timestamp / 1000)) : timestamp\n}\n\n/**\n * Return now local timestamp plus number of seconds to add\n * @param secondsToAdd Seconds to add from now (1 = now + 1 sec.)\n * @returns Timestamp of the future (past) on seconds\n */\nexport const nowPlusTime = (secondsToAdd: number) => {\n return Math.round(DateTime.now().plus({seconds: secondsToAdd}).toSeconds())\n}\n\n/**\n * Convert epoch time value into ISO format\n * @param epochValue Epoch value of the timestamp\n * @returns ISO format of the date\n */\nexport const epochToIsoFormat = (epochValue: number) => DateTime.fromMillis(epochValue).toISO() as string\n\n/**\n * Return epoch timestamp\n * @param regime Set if you want milisecond format or second format\n * @returns \n */\nexport const nowTimestampIso = () => {\n const timestamp = DateTime.now().toISO()\n return timestamp as string\n}\n\n/**\n * Check if input date is valid for ISO format\n * @param dateToCheck \n * @returns \n */\n export const hasIsoFormat = (dateToCheck: string) => {\n try{\n const toDate = new Date(Date.parse(dateToCheck))\n const isoCheck = toDate.toISOString().includes(dateToCheck) \n return isoCheck\n }\n catch{\n return false\n }\n}\n\n/**\n * Convert date in ISO formtat to milisecond timestamp\n * @param isoDate Date in ISO 8601 format\n * @returns Timestamp representing the date in miliseconds\n */\nexport const isoDateToTimestamp = (isoDate: string) => DateTime.fromISO(isoDate).toMillis()\n\n/**\n * Format ISO 8601 interval to from-to values\n * @param interval Defined inteval in ISO format (from/to) of the UTC\n * @returns Tuple - from timestamp and to timestamp\n */\nexport const isoIntervalToTimestamps = (interval: string): [number, number] => {\n\n // Split the interval into two parts\n const intervals = interval.split(\"/\")\n\n // interval as a single year has just one part\n if (intervals.length == 1) {\n const newIso = `${interval}-01-01/${interval}-12-31`\n return isoIntervalToTimestamps(newIso)\n }\n\n // interval with two parts or less than one\n else if (intervals.length > 2 || intervals.length < 1)\n throw new InvalidRequestError(\"Interval can have only two parameters\")\n\n // valid interval with two parts\n else {\n if (!intervals.every(interval => hasIsoFormat(interval)))\n throw new InvalidRequestError(\"Parameter utcIntervalIso is not ISO 8601 time interval (date01/date02) or year\");\n\n const [int1, int2] = intervals.map(intervalIso => {\n const cleared = intervalIso.replace(\" \", \"\")\n return isoDateToTimestamp(cleared)\n })\n\n return [int1, int2]\n }\n}\n","// TODO: Cover by tests\n// TODO: mode to ptr-be-core as general CSV methods\n\n\n/**\n * Parses a single line of CSV-formatted strings into an array of trimmed string values.\n *\n * @param csvStingsLine - A string representing a single line of comma-separated values.\n * @returns An array of strings, each representing a trimmed value from the CSV line.\n */\nexport const csvParseStrings = (csvStingsLine: string): string[] => {\n return csvStingsLine.split(\",\").map((value: string) => value.trim());\n}\n\n/**\n * Parses a comma-separated string of numbers into an array of numbers.\n *\n * @param csvNumbersLine - A string containing numbers separated by commas (e.g., \"1, 2, 3.5\").\n * @returns An array of numbers parsed from the input string.\n */\nexport const csvParseNumbers = (csvNumbersLine: string): number[] => {\n return csvNumbersLine.split(\",\").map((value: string) => parseFloat(value.trim()));\n}","import { UsedDatasourceLabels, UsedEdgeLabels, UsedNodeLabels } from \"./enums.panther\"\nimport { GraphEdge } from \"./models.edges\"\nimport { FullPantherEntity } from \"./models.nodes\"\n\n/**\n * Finds the first node in the provided list that contains the specified label.\n *\n * Searches the given array of FullPantherEntity objects and returns the first entity\n * whose `labels` array includes the provided label.\n *\n * @param nodes - Array of FullPantherEntity objects to search through.\n * @param label - Label to match; may be a UsedDatasourceLabels or UsedNodeLabels.\n * @returns The first FullPantherEntity whose `labels` includes `label`, or `undefined`\n * if no such entity is found.\n *\n * @remarks\n * - The search stops at the first match (uses `Array.prototype.find`).\n * - Label comparison is exact (uses `Array.prototype.includes`), so it is case-sensitive\n * and requires the same string instance/value.\n *\n * @example\n * const result = findNodeByLabel(nodes, 'datasource-main');\n * if (result) {\n * // found a node that has the 'datasource-main' label\n * }\n */\nexport const findNodeByLabel = (\n nodes: FullPantherEntity[],\n label: UsedDatasourceLabels | UsedNodeLabels): FullPantherEntity | undefined => {\n return nodes.find(n => n.labels.includes(label))\n}\n\n/**\n * Filters an array of FullPantherEntity objects, returning only those that contain the specified label.\n *\n * The function performs a shallow, non-mutating filter: it returns a new array and does not modify the input.\n * Matching is done using Array.prototype.includes on each entity's `labels` array (strict equality).\n *\n * @param nodes - The array of entities to filter.\n * @param label - The label to match; can be a UsedDatasourceLabels or UsedNodeLabels value.\n * @returns A new array containing only the entities whose `labels` array includes the provided label.\n *\n * @remarks\n * Time complexity is O(n * m) where n is the number of entities and m is the average number of labels per entity.\n *\n * @example\n * ```ts\n * const matched = filterNodeByLabel(entities, 'MY_LABEL');\n * ```\n */\nexport const filterNodeByLabel = (\n nodes: FullPantherEntity[],\n label: UsedDatasourceLabels | UsedNodeLabels): FullPantherEntity[] => {\n return nodes.filter(n => n.labels.includes(label))\n}\n\n/**\n * Finds the first edge in the provided array whose label strictly equals the given label.\n *\n * @param edges - Array of GraphEdge objects to search.\n * @param label - The UsedEdgeLabels value to match against each edge's `label` property.\n * @returns The first matching GraphEdge if found; otherwise `undefined`.\n *\n * @example\n * const edge = findEdgeByLabel(edges, 'dependency');\n * if (edge) {\n * // handle found edge\n * }\n */\nexport const findEdgeByLabel = (\n edges: GraphEdge[],\n label: UsedEdgeLabels): GraphEdge | undefined => {\n return edges.find(e => e.label === label)\n}\n\n/**\n * Filters a list of GraphEdge objects by a specific edge label.\n *\n * Returns a new array containing only those edges whose `label` property\n * strictly equals the provided `label` argument. The original `edges`\n * array is not mutated.\n *\n * @param edges - Array of GraphEdge objects to filter.\n * @param label - The label to match; comparison is performed using strict (`===`) equality.\n * @returns A new array of GraphEdge objects whose `label` matches the provided label. Returns an empty array if no edges match.\n *\n * @remarks\n * Time complexity: O(n), where n is the number of edges.\n *\n * @example\n * // const result = filterEdgeByLabel(edges, 'CONNECTS');\n */\nexport const filterEdgeByLabel = (\n edges: GraphEdge[],\n label: UsedEdgeLabels): GraphEdge[] => {\n return edges.filter(e => e.label === label)\n}","/**\n * What types of graph nodes we use in metadata model\n */\nexport enum UsedNodeLabels {\n Application = \"application\", // Application node (the root of the FE app)\n Datasource = \"datasource\", // Datasource node for data including GIS information\n Place = \"place\", // Place node for geographical information\n Period = \"period\", // Period node for time information\n AreaTree = \"areaTree\", // Area tree node for administrative division\n AreaTreeLevel = \"areaTreeLevel\", // Area tree level node for administrative division\n Layer = \"layer\", // Layer node for map layer (layer have a style and a datasource)\n Style = \"style\", // Style node for map layer or a feature\n Feature = \"feature\", // Feature node for map layer,\n Attribute = \"attribute\" // Attribute node for properties of entities, like \"temperature\", \"population\", etc.\n}\n\n/**\n * What datasources we use in the system\n */\nexport enum UsedDatasourceLabels {\n Attribute = \"attributeSource\", // Column(s) with attribute values\n Geojson = \"geojson\", // Geojson for web map\n WMS = \"wms\", // WMS online source\n COG = \"cloudOptimizedGeotiff\", // COG online source\n MVT = \"mvt\", // MVT (Mapbox Vector Tiles) source\n XYZ = \"xyz\", // XYZ tile source\n CSV = \"csv\", // CSV data source\n GeoTIFF = \"geotiff\", // GeoTIFF raster data\n Shapefile = \"shapefile\", // ESRI Shapefile format\n PostGIS = \"postgis\", // PostGIS database source\n WMTS = \"wmts\", // Web Map Tile Service\n WFS = \"wfs\", // Web Feature Service\n GeoPackage = \"geopackage\", // OGC GeoPackage format\n MapStyle = \"mapStyle\", // Map style datasource\n Timeseries = \"timeseries\" // Timeseries datasource (with from-to and step)\n}\n\n/**\n * What types of edges we use in metadata model\n */\nexport enum UsedEdgeLabels {\n RelatedTo = \"RELATED\", // Generic edge for any relation\n Has = \"HAS\", // Edge for ownership relation\n InPostgisLocation = \"IN_POSTGIS_LOCATION\" // Edge to connect datasource with PostGIS location (schema, table, geometry column)\n}\n\n/**\n * What time steps are used in timeseries data\n */\nexport enum UsedTimeseriesSteps{\n Year = \"year\",\n Quarter = \"quarter\",\n Month = \"month\",\n Week = \"week\",\n Day = \"day\"\n}"],"names":[],"mappings":";;AAAA;;;;AAIG;AACI,MAAM,KAAK,GAAG,CAAC,SAAiB,KAAI;AACzC,IAAA,IAAI;AACF,QAAA,IAAI,GAAG,CAAC,SAAS,CAAC;AAClB,QAAA,OAAO,IAAI;IACb;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,KAAK;IACd;AACF;AAEA;;;;AAIG;MACU,aAAa,GAAG,CAAC,UAAoB,KAAK,UAAU,CAAC,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC;AAErG;;;;;AAKG;MACU,QAAQ,GAAG,CAAC,KAAU,EAAE,UAAe,KAAI;IACpD,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAa;AAC3D,IAAA,OAAO,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC;AACtC;AAEF;;;;AAIG;AACI,MAAM,eAAe,GAAG,CAAC,QAAkB,KAAK,QAAQ,CAAC,IAAI;AAEpE;;;;AAIG;AACI,MAAM,0BAA0B,GAAG,CAAC,GAAU,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC;AAG1E;;;;AAIG;AACI,MAAM,cAAc,GAAG,CAAC,KAAa,KAAK,KAAK,KAAK;AAG3D;;;;;AAKG;AACI,MAAM,kBA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GAAA,UAAqB;IACrB,oBAAA,CAAA,YAAA,CAAA,GAAA,YAAyB,CAAA;AAC7B,CAAC,EAhBW,oBAAoB,KAApB,oBAAoB,GAAA,EAAA,CAAA,CAAA;AAkBhC;;AAEG;IACS;AAAZ,CAAA,UAAY,cAAc,EAAA;AACtB,IAAA,cAAA,CAAA,WAAA,CAAA,GAAA,SAAqB;AACrB,IAAA,cAAA,CAAA,KAAA,CAAA,GAAA,KAAW;IACX,cAAA,CAAA,mBAAA,CAAA,GAAA,qBAAyC,CAAA;AAC7C,CAAC,EAJW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;AAM1B;;AAEG;IACS;AAAZ,CAAA,UAAY,mBAAmB,EAAA;AAC3B,IAAA,mBAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,mBAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,mBAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACf,IAAA,mBAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,mBAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACf,CAAC,EANW,mBAAmB,KAAnB,mBAAmB,GAAA,EAAA,CAAA,CAAA;;;;"}
@@ -6,6 +6,8 @@ var crypto = require('crypto');
6
6
  var _ = require('lodash');
7
7
  var path = require('path');
8
8
  var fs = require('fs');
9
+ var sqlite3 = require('sqlite3');
10
+ var sqlite = require('sqlite');
9
11
 
10
12
  /**
11
13
  * Check, if the string is url
@@ -122,12 +124,6 @@ const flattenObject = (obj, prefix = '') => {
122
124
  }, {});
123
125
  };
124
126
 
125
- /**
126
- * Extract message from exception error (try-catch)
127
- * @param error error from catch block as any
128
- * @returns
129
- */
130
- const messageFromError = (error) => error["message"];
131
127
  /**
132
128
  * We miss a API parameter needed to process action
133
129
  */
@@ -144,6 +140,22 @@ class AuthorizationError extends Error {
144
140
  super(`Authorization has failed.`);
145
141
  }
146
142
  }
143
+ /**
144
+ * General backend server side error
145
+ */
146
+ class ServerError extends Error {
147
+ constructor(message) {
148
+ super(`Server Error: ${message}`);
149
+ }
150
+ }
151
+ /**
152
+ * Error to indicate that some functionality is SSR only
153
+ */
154
+ class SSROnlyError extends Error {
155
+ constructor(message) {
156
+ super(`SSR Only Error: ${message}`);
157
+ }
158
+ }
147
159
 
148
160
  /**
149
161
  * Return epoch timestamp
@@ -388,6 +400,13 @@ exports.UsedTimeseriesSteps = void 0;
388
400
  UsedTimeseriesSteps["Day"] = "day";
389
401
  })(exports.UsedTimeseriesSteps || (exports.UsedTimeseriesSteps = {}));
390
402
 
403
+ /**
404
+ * Extract message from exception error (try-catch)
405
+ * @param error error from catch block as any
406
+ * @returns
407
+ */
408
+ const messageFromError = (error) => error["message"];
409
+
391
410
  /**
392
411
  * Shared pino logger instance used by all logging functions.
393
412
  *
@@ -1067,10 +1086,117 @@ exports.SwaggerTypes = void 0;
1067
1086
  SwaggerTypes["Boolean"] = "boolean";
1068
1087
  })(exports.SwaggerTypes || (exports.SwaggerTypes = {}));
1069
1088
 
1089
+ /**
1090
+ * Enumeration of the SQL table names used throughout the application.
1091
+ *
1092
+ * This enum provides a centralized registry of table names to ensure consistent
1093
+ * references across the application's database operations.
1094
+ *
1095
+ * @enum {string}
1096
+ */
1097
+ exports.UsedSqlTables = void 0;
1098
+ (function (UsedSqlTables) {
1099
+ UsedSqlTables["APP_STATES"] = "states";
1100
+ })(exports.UsedSqlTables || (exports.UsedSqlTables = {}));
1101
+
1102
+ /**
1103
+ * The default name for the SQLite database file in backend and SSR apps.
1104
+ * Default value is "db.sqlite".
1105
+ */
1106
+ const DEFAULT_DB_NAME = "db.sqlite";
1107
+ /**
1108
+ * The default expiration time for database states, in seconds. For backend and SSR apps.
1109
+ * Default value is set to 1 day (86400 seconds).
1110
+ */
1111
+ const DEFAULT_DB_STATE_EXPIRATION_SEC = 60 * 60 * 24; // default to 1 day
1112
+
1113
+ /**
1114
+ * Opens a connection to a SQLite database.
1115
+ *
1116
+ * @param filename - The path to the SQLite database file. If the file does not exist, it will be created.
1117
+ * @returns A Promise that resolves to an AppDb instance representing the opened database connection.
1118
+ *
1119
+ * @example
1120
+ * ```typescript
1121
+ * const db = await openDb('./myDatabase.sqlite');
1122
+ * ```
1123
+ */
1124
+ async function openDb(filename) {
1125
+ const db = await sqlite.open({
1126
+ filename, //database file will be created if it does not exist
1127
+ driver: sqlite3.Database,
1128
+ });
1129
+ // create the database structure
1130
+ await db.run(`
1131
+ CREATE TABLE IF NOT EXISTS ${exports.UsedSqlTables.APP_STATES} (
1132
+ key VARCHAR(50) PRIMARY KEY,
1133
+ state BLOB,
1134
+ expires_at DATETIME
1135
+ )`);
1136
+ // return the database connection
1137
+ // Note: The database connection is automatically closed when the process exits
1138
+ return db;
1139
+ }
1140
+
1141
+ /**
1142
+ * Saves a state to the database with the specified key.
1143
+ *
1144
+ * @param db - The application database instance.
1145
+ * @param key - The unique identifier for the state.
1146
+ * @param state - The state data to be saved as a string.
1147
+ * @returns A promise that resolves when the state has been saved.
1148
+ */
1149
+ const dbSaveState = async (db, key, state, expirationSec) => {
1150
+ // Clean up expired state rows
1151
+ await db.run(`DELETE FROM ${exports.UsedSqlTables.APP_STATES}
1152
+ WHERE expires_at < ?`, [Math.floor(Date.now() / 1000)]);
1153
+ // Calculate expiration date by adding seconds to current time
1154
+ const currentTimestamp = Math.floor(Date.now() / 1000); // Current time in seconds
1155
+ const expiresAt = currentTimestamp + expirationSec;
1156
+ // Convert JSON to string
1157
+ const jsonString = JSON.stringify(state);
1158
+ // Convert string to binary (UTF-8)
1159
+ const encoder = new TextEncoder(); // Available in most modern environments
1160
+ const binaryData = encoder.encode(jsonString); // Uint8Array
1161
+ await db.run(`INSERT INTO ${exports.UsedSqlTables.APP_STATES} (key, state, expires_at)
1162
+ VALUES (?, ?, ?)`, [key, binaryData, expiresAt]);
1163
+ };
1164
+
1165
+ /**
1166
+ * Retrieves the application state associated with the specified key from the database.
1167
+ *
1168
+ * @param db - The application database instance.
1169
+ * @param key - The key identifying the state to retrieve.
1170
+ * @returns A promise that resolves to the requested state data or undefined if not found.
1171
+ */
1172
+ const dbNeedAppState = async (db, key) => {
1173
+ // read the state from the database
1174
+ const wantedState = await db.get(`SELECT * FROM ${exports.UsedSqlTables.APP_STATES} WHERE key= ?`, key);
1175
+ // if the state is not found, return null
1176
+ if (!wantedState)
1177
+ return null;
1178
+ // convert binary state back to JSON format
1179
+ const decoder = new TextDecoder("utf-8");
1180
+ const decodedString = decoder.decode(wantedState.state);
1181
+ const jsonState = JSON.parse(decodedString);
1182
+ // return the state and metadata
1183
+ return {
1184
+ key: wantedState.key,
1185
+ state: jsonState,
1186
+ expiresAt: wantedState.expires_at
1187
+ };
1188
+ };
1189
+
1070
1190
  exports.AuthorizationError = AuthorizationError;
1191
+ exports.DEFAULT_DB_NAME = DEFAULT_DB_NAME;
1192
+ exports.DEFAULT_DB_STATE_EXPIRATION_SEC = DEFAULT_DB_STATE_EXPIRATION_SEC;
1071
1193
  exports.InvalidRequestError = InvalidRequestError;
1194
+ exports.SSROnlyError = SSROnlyError;
1195
+ exports.ServerError = ServerError;
1072
1196
  exports.csvParseNumbers = csvParseNumbers;
1073
1197
  exports.csvParseStrings = csvParseStrings;
1198
+ exports.dbNeedAppState = dbNeedAppState;
1199
+ exports.dbSaveState = dbSaveState;
1074
1200
  exports.enumCombineValuesToString = enumCombineValuesToString;
1075
1201
  exports.enumValuesToArray = enumValuesToArray;
1076
1202
  exports.enumValuesToString = enumValuesToString;
@@ -1100,6 +1226,7 @@ exports.notEmptyString = notEmptyString;
1100
1226
  exports.nowPlusTime = nowPlusTime;
1101
1227
  exports.nowTimestamp = nowTimestamp;
1102
1228
  exports.nowTimestampIso = nowTimestampIso;
1229
+ exports.openDb = openDb;
1103
1230
  exports.parseArrowsJson = parseArrowsJson;
1104
1231
  exports.parseEqualEdges = parseEqualEdges;
1105
1232
  exports.parsePackageJsonEnvironments = parsePackageJsonEnvironments;