@hestia-earth/api 0.9.22 → 0.9.23

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.
@@ -11,3 +11,4 @@ export declare const allowedDataStates: (type: SchemaType | NodeType) => DataSta
11
11
  export declare const pathWithState: (type: SchemaType | NodeType, id: string, dataState?: DataState) => string;
12
12
  export declare const nodeTypeToParam: (type: NodeType) => string;
13
13
  export declare const paramToNodeType: (type: string) => NodeType;
14
+ export declare const parseLogMissingLookups: (data: string) => any[];
@@ -1,8 +1,21 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var _a;
3
14
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.paramToNodeType = exports.nodeTypeToParam = exports.pathWithState = exports.allowedDataStates = exports.dataStatesTypeMapping = exports.DataState = void 0;
15
+ exports.parseLogMissingLookups = exports.paramToNodeType = exports.nodeTypeToParam = exports.pathWithState = exports.allowedDataStates = exports.dataStatesTypeMapping = exports.DataState = void 0;
5
16
  var schema_1 = require("@hestia-earth/schema");
17
+ var utils_1 = require("@hestia-earth/utils");
18
+ var model_1 = require("../../files/model/model");
6
19
  var DataState;
7
20
  (function (DataState) {
8
21
  DataState["original"] = "original";
@@ -31,3 +44,28 @@ exports.pathWithState = function (type, id, dataState) {
31
44
  };
32
45
  exports.nodeTypeToParam = function (type) { return (type || '').toLowerCase() + "s"; };
33
46
  exports.paramToNodeType = function (type) { return Object.values(schema_1.NodeType).find(function (v) { return exports.nodeTypeToParam(v) === type; }); };
47
+ var csvValue = function (value) { return (value || '').replace('[', '').replace(']', ''); };
48
+ var parseMessage = function (_a) {
49
+ var message = _a.message;
50
+ return message.split(',').reduce(function (prev, parts) {
51
+ var _a;
52
+ var _b = parts.split('='), key = _b[0], value = _b[1];
53
+ var val = csvValue(value);
54
+ return __assign(__assign({}, prev), (key && val ? (_a = {}, _a[key.trim()] = val, _a) : {}));
55
+ }, {});
56
+ };
57
+ var termTypes = Object.values(schema_1.TermTermType);
58
+ var parseFilename = function (filepath) {
59
+ var filename = filepath.split('.')[0];
60
+ var ext = termTypes.includes(filename) ? model_1.SupportedExtensions.xlsx : model_1.SupportedExtensions.csv;
61
+ return model_1.fileToExt(filename, ext);
62
+ };
63
+ exports.parseLogMissingLookups = function (data) {
64
+ var lines = data.split('\n').filter(function (log) { return log.includes('Missing lookup'); });
65
+ var messages = lines.map(function (v) { return JSON.parse(v); }).map(parseMessage).filter(function (v) { return Object.keys(v).length > 1; });
66
+ var lookups = messages.map(function (_a) {
67
+ var path = _a["Missing lookup"], termId = _a.termid, column = _a.column;
68
+ return JSON.stringify({ filename: parseFilename(path), termId: termId, column: column });
69
+ });
70
+ return utils_1.unique(lookups).map(function (v) { return JSON.parse(v); });
71
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/api",
3
- "version": "0.9.22",
3
+ "version": "0.9.23",
4
4
  "description": "Hestia API definitions",
5
5
  "main": "dist/models.js",
6
6
  "typings": "dist/models.d.ts",