typeshi 1.0.1 → 1.2.0
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/dist/config/env.d.ts +3 -6
- package/dist/config/env.js +2 -12
- package/dist/config/index.d.ts +0 -1
- package/dist/config/index.js +0 -1
- package/dist/config/setupLog.d.ts +2 -11
- package/dist/config/setupLog.js +13 -22
- package/dist/utils/io/logging.d.ts +7 -0
- package/dist/utils/io/logging.js +23 -2
- package/dist/utils/io/reading.js +1 -1
- package/dist/utils/io/writing.d.ts +1 -1
- package/dist/utils/io/writing.js +2 -3
- package/dist/utils/regex/configureParameters.d.ts +0 -3
- package/dist/utils/regex/configureParameters.js +0 -11
- package/dist/utils/regex/entity.js +11 -5
- package/package.json +1 -1
- package/dist/config/dataLoader.d.ts +0 -37
- package/dist/config/dataLoader.js +0 -171
package/dist/config/env.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare const SRC_DIR: string;
|
|
5
|
-
/** = `typeshi/src/data` */
|
|
6
|
-
export declare const DATA_DIR: string;
|
|
1
|
+
/**
|
|
2
|
+
* @file src/config/env.ts
|
|
3
|
+
*/
|
|
7
4
|
/**
|
|
8
5
|
* @description Exit the program/script for debugging purposes
|
|
9
6
|
* @param exitCode `number` - The exit code to use when exiting the program. Default is `0`. Use `1` for error.
|
package/dist/config/env.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
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.DELAY = exports.STOP_RUNNING = exports.DATA_DIR = exports.SRC_DIR = exports.NODE_HOME_DIR = void 0;
|
|
7
2
|
/**
|
|
8
3
|
* @file src/config/env.ts
|
|
9
4
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.NODE_HOME_DIR = process.cwd();
|
|
13
|
-
/** = {@link NODE_HOME_DIR}`/src` = `process.cwd()/src`*/
|
|
14
|
-
exports.SRC_DIR = node_path_1.default.join(exports.NODE_HOME_DIR, 'node_modules', 'typeshi', 'dist');
|
|
15
|
-
/** = `typeshi/src/data` */
|
|
16
|
-
exports.DATA_DIR = node_path_1.default.join(exports.SRC_DIR, 'data');
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DELAY = exports.STOP_RUNNING = void 0;
|
|
17
7
|
/**
|
|
18
8
|
* @description Exit the program/script for debugging purposes
|
|
19
9
|
* @param exitCode `number` - The exit code to use when exiting the program. Default is `0`. Use `1` for error.
|
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
|
@@ -19,4 +19,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
__exportStar(require("./setupLog"), exports);
|
|
21
21
|
__exportStar(require("./env"), exports);
|
|
22
|
-
__exportStar(require("./dataLoader"), exports);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @file src/config/setupLog.ts
|
|
3
3
|
* @reference https://tslog.js.org/#/?id=pretty-templates-and-styles-color-settings
|
|
4
4
|
*/
|
|
5
|
-
import { Logger, ILogObj
|
|
5
|
+
import { Logger, ILogObj } from 'tslog';
|
|
6
6
|
/**
|
|
7
7
|
* `TAB = INDENT_LOG_LINE = '\n\t• '` = newLine + tab + bullet + space
|
|
8
8
|
* - log.debug(s1, INDENT_LOG_LINE + s2, INDENT_LOG_LINE + s3,...)
|
|
@@ -27,13 +27,4 @@ export declare const NEW_LINE: string;
|
|
|
27
27
|
* */
|
|
28
28
|
export declare const typeshiLogger: Logger<ILogObj>;
|
|
29
29
|
export declare const typeshiSimpleLogger: Logger<ILogObj>;
|
|
30
|
-
|
|
31
|
-
* compress metadata into `logObj['-1']` then return stringified `logObj`
|
|
32
|
-
* @param logObj {@link ILogObj}
|
|
33
|
-
* @returns `string`
|
|
34
|
-
*/
|
|
35
|
-
export declare function formatLogObj(logObj: ILogObj | (ILogObj & ILogObjMeta)): string;
|
|
36
|
-
/**suppress logs by putting them here (do not print to console) */
|
|
37
|
-
export declare const SUPPRESSED_LOGS: any[];
|
|
38
|
-
export declare const INFO_LOGS: any[];
|
|
39
|
-
export declare const DEBUG_LOGS: any[];
|
|
30
|
+
export declare const typeshiHiddenLogger: Logger<ILogObj>;
|
package/dist/config/setupLog.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.formatLogObj = formatLogObj;
|
|
3
|
+
exports.typeshiHiddenLogger = exports.typeshiSimpleLogger = exports.typeshiLogger = exports.NEW_LINE = exports.INDENT_LOG_LINE = void 0;
|
|
5
4
|
/**
|
|
6
5
|
* @file src/config/setupLog.ts
|
|
7
6
|
* @reference https://tslog.js.org/#/?id=pretty-templates-and-styles-color-settings
|
|
@@ -122,23 +121,15 @@ const SIMPLE_LOGGER_SETTINGS = {
|
|
|
122
121
|
prettyLogStyles: PRETTY_LOG_STYLES,
|
|
123
122
|
};
|
|
124
123
|
exports.typeshiSimpleLogger = new tslog_1.Logger(SIMPLE_LOGGER_SETTINGS);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
logObj['meta0'] = `[${logLevelName}] (${timestamp})`;
|
|
138
|
-
logObj['meta1'] = `${fileInfo} @ ${methodInfo}`;
|
|
139
|
-
return JSON.stringify(logObj, null, 4) + "\n";
|
|
140
|
-
}
|
|
141
|
-
/**suppress logs by putting them here (do not print to console) */
|
|
142
|
-
exports.SUPPRESSED_LOGS = [];
|
|
143
|
-
exports.INFO_LOGS = [];
|
|
144
|
-
exports.DEBUG_LOGS = [];
|
|
124
|
+
const HIDDEN_LOGGER_SETTINGS = {
|
|
125
|
+
type: "hidden",
|
|
126
|
+
name: "typeshi_hidden",
|
|
127
|
+
minLevel: 0,
|
|
128
|
+
prettyLogTemplate: SIMPLE_LOG_TEMPLATE,
|
|
129
|
+
prettyErrorTemplate: ERROR_TEMPLATE,
|
|
130
|
+
prettyErrorStackTemplate: ERROR_STACK_TEMPLATE,
|
|
131
|
+
stylePrettyLogs: true,
|
|
132
|
+
prettyLogTimeZone: "local",
|
|
133
|
+
prettyLogStyles: PRETTY_LOG_STYLES,
|
|
134
|
+
};
|
|
135
|
+
exports.typeshiHiddenLogger = new tslog_1.Logger(HIDDEN_LOGGER_SETTINGS);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ILogObj, ILogObjMeta } from "tslog";
|
|
1
2
|
/**
|
|
2
3
|
* @param fileName `string` passed into `extractFileName()`
|
|
3
4
|
* @param func `Function` - to get Function.name
|
|
@@ -32,3 +33,9 @@ export declare function formatDebugLogFile(inputFilePath: string, outputFilePath
|
|
|
32
33
|
* @returns `void`
|
|
33
34
|
*/
|
|
34
35
|
export declare function formatAllDebugLogs(logDirectory: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* reduce metadata to two entries, then return stringified `logObj`
|
|
38
|
+
* @param logObj {@link ILogObj}
|
|
39
|
+
* @returns `string`
|
|
40
|
+
*/
|
|
41
|
+
export declare function formatLogObj(logObj: ILogObj | (ILogObj & ILogObjMeta)): string;
|
package/dist/utils/io/logging.js
CHANGED
|
@@ -40,6 +40,7 @@ exports.getSourceString = getSourceString;
|
|
|
40
40
|
exports.autoFormatLogsOnExit = autoFormatLogsOnExit;
|
|
41
41
|
exports.formatDebugLogFile = formatDebugLogFile;
|
|
42
42
|
exports.formatAllDebugLogs = formatAllDebugLogs;
|
|
43
|
+
exports.formatLogObj = formatLogObj;
|
|
43
44
|
/**
|
|
44
45
|
* @file src/utils/io/logging.ts
|
|
45
46
|
*/
|
|
@@ -49,7 +50,6 @@ const typeValidation_1 = require("../typeValidation");
|
|
|
49
50
|
const regex_1 = require("../regex");
|
|
50
51
|
const validate = __importStar(require("../argumentValidation"));
|
|
51
52
|
const node_path_1 = __importDefault(require("node:path"));
|
|
52
|
-
const F = (0, regex_1.extractFileName)(__filename);
|
|
53
53
|
/**
|
|
54
54
|
* @param fileName `string` passed into `extractFileName()`
|
|
55
55
|
* @param func `Function` - to get Function.name
|
|
@@ -78,7 +78,7 @@ function getSourceString(fileName, func, funcInfo, startLine, endLine) {
|
|
|
78
78
|
* @returns `void`
|
|
79
79
|
*/
|
|
80
80
|
function autoFormatLogsOnExit(filePaths) {
|
|
81
|
-
const source = `
|
|
81
|
+
const source = getSourceString(__filename, autoFormatLogsOnExit.name, `Array<string>(${(filePaths ?? []).length})`);
|
|
82
82
|
if (!(0, typeValidation_1.isStringArray)(filePaths)) {
|
|
83
83
|
setupLog_1.typeshiLogger.warn([`${source} Invalid param 'filePaths'`,
|
|
84
84
|
`Expected: string[] (array of filePaths)`,
|
|
@@ -258,3 +258,24 @@ function formatAllDebugLogs(logDirectory) {
|
|
|
258
258
|
throw error;
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* reduce metadata to two entries, then return stringified `logObj`
|
|
263
|
+
* @param logObj {@link ILogObj}
|
|
264
|
+
* @returns `string`
|
|
265
|
+
*/
|
|
266
|
+
function formatLogObj(logObj) {
|
|
267
|
+
const meta = logObj['_meta'];
|
|
268
|
+
const { logLevelName, date, path: stackFrame } = meta;
|
|
269
|
+
const timestamp = date ? date.toLocaleString() : '';
|
|
270
|
+
if (stackFrame) {
|
|
271
|
+
const fileInfo = [
|
|
272
|
+
stackFrame.filePathWithLine ? `${stackFrame.filePathWithLine}` : '',
|
|
273
|
+
stackFrame.fileColumn && stackFrame.filePathWithLine ? `:${stackFrame.fileColumn}` : '',
|
|
274
|
+
].join('');
|
|
275
|
+
const methodInfo = stackFrame.method ? `${stackFrame.method}()` : '';
|
|
276
|
+
logObj['meta0'] = `[${logLevelName}] (${timestamp})`;
|
|
277
|
+
logObj['meta1'] = `${fileInfo || 'unknown_file'} @ ${methodInfo || 'unknown_method'}`;
|
|
278
|
+
delete logObj['_meta'];
|
|
279
|
+
}
|
|
280
|
+
return JSON.stringify(logObj, null, 4) + "\n";
|
|
281
|
+
}
|
package/dist/utils/io/reading.js
CHANGED
|
@@ -365,7 +365,7 @@ async function getCsvRows(arg1) {
|
|
|
365
365
|
.pipe((0, csv_parser_1.default)({ separator: delimiter }))
|
|
366
366
|
.on('data', (row) => rows.push(row))
|
|
367
367
|
.on('end', () => {
|
|
368
|
-
config_1.
|
|
368
|
+
config_1.typeshiHiddenLogger.debug([`${source} Successfully read CSV file.`,
|
|
369
369
|
`filePath: '${filePath}'`,
|
|
370
370
|
`Number of rows read: ${rows.length}`
|
|
371
371
|
].join(config_1.INDENT_LOG_LINE));
|
|
@@ -29,7 +29,7 @@ export declare const writeJsonSync: typeof writeObjectToJsonSync;
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function indentedStringify(data: Record<string, any> | string, indent?: number, spaces?: number): string;
|
|
31
31
|
/**
|
|
32
|
-
* @returns **`timestamp`** `string` = `(${MM}-${DD})
|
|
32
|
+
* @returns **`timestamp`** `string` = `(${MM}-${DD})_(${HH}-${mm}.${ss}.${ms})`
|
|
33
33
|
*/
|
|
34
34
|
export declare function getFileNameTimestamp(): string;
|
|
35
35
|
/**
|
package/dist/utils/io/writing.js
CHANGED
|
@@ -135,7 +135,7 @@ function indentedStringify(data, indent = 0, spaces = 4) {
|
|
|
135
135
|
return jsonString;
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
|
-
* @returns **`timestamp`** `string` = `(${MM}-${DD})
|
|
138
|
+
* @returns **`timestamp`** `string` = `(${MM}-${DD})_(${HH}-${mm}.${ss}.${ms})`
|
|
139
139
|
*/
|
|
140
140
|
function getFileNameTimestamp() {
|
|
141
141
|
const now = new Date();
|
|
@@ -145,7 +145,7 @@ function getFileNameTimestamp() {
|
|
|
145
145
|
const mm = String(now.getMinutes()).padStart(2, '0');
|
|
146
146
|
const ss = String(now.getSeconds()).padStart(2, '0');
|
|
147
147
|
const ms = String(now.getMilliseconds()).padStart(3, '0');
|
|
148
|
-
return `(${MM}-${DD})
|
|
148
|
+
return `(${MM}-${DD})_(${HH}-${mm}.${ss}.${ms})`;
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
151
|
* @param listData `Record<string, Array<string>>` map col names to col values
|
|
@@ -156,7 +156,6 @@ function getFileNameTimestamp() {
|
|
|
156
156
|
function writeListsToCsvSync(listData, outputPath, delimiter = types_1.DelimiterCharacterEnum.TAB, columnDelimiter = '') {
|
|
157
157
|
const listNames = Object.keys(listData);
|
|
158
158
|
const listValues = Object.values(listData);
|
|
159
|
-
// Get the maximum length of the lists
|
|
160
159
|
const maxLength = Math.max(...listValues.map(list => list.length));
|
|
161
160
|
let csvContent = listNames.join(delimiter) + '\n';
|
|
162
161
|
if ((0, typeValidation_1.isNonEmptyString)(columnDelimiter)) {
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
* @file src/utils/regex/configureParameters.ts
|
|
3
3
|
*/
|
|
4
4
|
import { StringStripOptions, StringReplaceParams } from ".";
|
|
5
|
-
export declare function getCompanyKeywordList(): string[];
|
|
6
|
-
export declare function getJobTitleSuffixList(): string[];
|
|
7
|
-
/** strip leading `.` and (trailing `.` if satisfy stripRightCondition: {@link doesNotEndWithKnownAbbreviation}) */
|
|
8
5
|
/**
|
|
9
6
|
* @param {string} s - `string` - the string to check
|
|
10
7
|
* @returns `!s.endsWith('Ph.D.') && !`{@link stringEndsWithAnyOf}`(s`, {@link COMPANY_ABBREVIATION_PATTERN} as RegExp, `[`{@link RegExpFlagsEnum.IGNORE_CASE}`]) && !stringEndsWithAnyOf(s, /\b[A-Z]\.?\b/, [RegExpFlagsEnum.IGNORE_CASE]);` */
|
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.REPLACE_EM_HYPHEN = exports.ENSURE_SPACE_AROUND_HYPHEN = exports.UNCONDITIONAL_STRIP_DOT_OPTIONS = exports.STRIP_DOT_IF_NOT_END_WITH_ABBREVIATION = void 0;
|
|
4
|
-
exports.getCompanyKeywordList = getCompanyKeywordList;
|
|
5
|
-
exports.getJobTitleSuffixList = getJobTitleSuffixList;
|
|
6
4
|
exports.doesNotEndWithKnownAbbreviation = doesNotEndWithKnownAbbreviation;
|
|
7
5
|
/**
|
|
8
6
|
* @file src/utils/regex/configureParameters.ts
|
|
9
7
|
*/
|
|
10
8
|
const _1 = require(".");
|
|
11
|
-
const dataLoader_1 = require("../../config/dataLoader");
|
|
12
|
-
// These are now loaded via the dataLoader system
|
|
13
|
-
function getCompanyKeywordList() {
|
|
14
|
-
return (0, dataLoader_1.getRegexConstants)().COMPANY_KEYWORD_LIST;
|
|
15
|
-
}
|
|
16
|
-
function getJobTitleSuffixList() {
|
|
17
|
-
return (0, dataLoader_1.getRegexConstants)().JOB_TITLE_SUFFIX_LIST;
|
|
18
|
-
}
|
|
19
|
-
/** strip leading `.` and (trailing `.` if satisfy stripRightCondition: {@link doesNotEndWithKnownAbbreviation}) */
|
|
20
9
|
/**
|
|
21
10
|
* @param {string} s - `string` - the string to check
|
|
22
11
|
* @returns `!s.endsWith('Ph.D.') && !`{@link stringEndsWithAnyOf}`(s`, {@link COMPANY_ABBREVIATION_PATTERN} as RegExp, `[`{@link RegExpFlagsEnum.IGNORE_CASE}`]) && !stringEndsWithAnyOf(s, /\b[A-Z]\.?\b/, [RegExpFlagsEnum.IGNORE_CASE]);` */
|
|
@@ -68,7 +68,11 @@ function extractName(name, includeJobTitleSuffix = true) {
|
|
|
68
68
|
|| _1.KOREA_ADDRESS_LATIN_TEXT_PATTERN.test(name)) {
|
|
69
69
|
return { first: '', middle: '', last: '' };
|
|
70
70
|
}
|
|
71
|
-
config_1.
|
|
71
|
+
config_1.typeshiHiddenLogger.debug([`extractName()`,
|
|
72
|
+
` originalName = "${originalName}"`,
|
|
73
|
+
` cleaned name = "${name}"`,
|
|
74
|
+
`jobTitleSuffix = "${jobTitleSuffix}"`
|
|
75
|
+
].join(config_1.INDENT_LOG_LINE));
|
|
72
76
|
let nameSplit = name.split(/(?<!,)\s+/);
|
|
73
77
|
if (nameSplit.length === 0) {
|
|
74
78
|
return { first: '', middle: '', last: '' };
|
|
@@ -81,7 +85,9 @@ function extractName(name, includeJobTitleSuffix = true) {
|
|
|
81
85
|
strip: _1.STRIP_DOT_IF_NOT_END_WITH_ABBREVIATION,
|
|
82
86
|
replace: [{ searchValue: /(^[-+])*/g, replaceValue: '' }]
|
|
83
87
|
}));
|
|
84
|
-
config_1.
|
|
88
|
+
config_1.typeshiHiddenLogger.debug([`nameSplit.length === ${nameSplit.length},`,
|
|
89
|
+
`nameSplit: ${JSON.stringify(nameSplit)}`
|
|
90
|
+
].join(config_1.INDENT_LOG_LINE));
|
|
85
91
|
if (nameSplit.length == 1) {
|
|
86
92
|
return {
|
|
87
93
|
first: nameSplit[0].replace(/(,|\.)$/g, ''),
|
|
@@ -125,7 +131,7 @@ function extractName(name, includeJobTitleSuffix = true) {
|
|
|
125
131
|
// .replace(/(,|\.)$/g, '')
|
|
126
132
|
};
|
|
127
133
|
}
|
|
128
|
-
config_1.
|
|
134
|
+
config_1.typeshiHiddenLogger.debug(config_1.NEW_LINE + `extractName() - no valid name parts found, returning empty strings`);
|
|
129
135
|
return { first: '', middle: '', last: '' };
|
|
130
136
|
}
|
|
131
137
|
/**
|
|
@@ -148,11 +154,11 @@ function extractJobTitleSuffix(s) {
|
|
|
148
154
|
{ searchValue: /,$/g, replaceValue: '' }
|
|
149
155
|
] });
|
|
150
156
|
if (exports.JOB_TITLE_SUFFIX_PATTERN.test(s)) {
|
|
151
|
-
config_1.
|
|
157
|
+
config_1.typeshiHiddenLogger.debug(config_1.NEW_LINE + `[regex/entity.extractJobTitleSuffix()]`, `s = "${s}"`);
|
|
152
158
|
const jobTitleMatch = s.match(exports.JOB_TITLE_SUFFIX_PATTERN);
|
|
153
159
|
if (jobTitleMatch && jobTitleMatch.length > 0) {
|
|
154
160
|
let jobTitle = jobTitleMatch[0].replace(/^\s*,\s*/g, '').trim();
|
|
155
|
-
config_1.
|
|
161
|
+
config_1.typeshiHiddenLogger.debug(`jobTitleMatch[0] = "${jobTitleMatch[0]}" -> trim and return "${jobTitle}"`);
|
|
156
162
|
return jobTitle;
|
|
157
163
|
}
|
|
158
164
|
}
|
package/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @enum {string} **`DataDomainEnum`** `string`
|
|
3
|
-
* @property **`REGEX`** = `'regex'`
|
|
4
|
-
*/
|
|
5
|
-
export declare enum DataDomainEnum {
|
|
6
|
-
REGEX = "regex"
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Initialize all data required by the application.
|
|
10
|
-
* This should be called once at the start of the application.
|
|
11
|
-
*/
|
|
12
|
-
export declare function initializeData(...domains: DataDomainEnum[]): Promise<void>;
|
|
13
|
-
export declare function getRegexConstants(): RegexConstants;
|
|
14
|
-
/**
|
|
15
|
-
* `Sync` Get company keyword list
|
|
16
|
-
* @returns **`COMPANY_KEYWORD_LIST`** `string[]`
|
|
17
|
-
*/
|
|
18
|
-
export declare function getCompanyKeywordList(): string[];
|
|
19
|
-
/**
|
|
20
|
-
* Get job title suffix list
|
|
21
|
-
* @returns **`JOB_TITLE_SUFFIX_LIST`** `string[]`
|
|
22
|
-
*/
|
|
23
|
-
export declare function getJobTitleSuffixList(): string[];
|
|
24
|
-
export declare function isDataInitialized(): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* @interface **`RegexConstants`**
|
|
27
|
-
* @property **`COMPANY_KEYWORD_LIST`** `string[]`
|
|
28
|
-
* @property **`JOB_TITLE_SUFFIX_LIST`** `string[]`
|
|
29
|
-
*/
|
|
30
|
-
export interface RegexConstants {
|
|
31
|
-
COMPANY_KEYWORD_LIST: string[];
|
|
32
|
-
JOB_TITLE_SUFFIX_LIST: string[];
|
|
33
|
-
}
|
|
34
|
-
export type DataLoaderConfig = {
|
|
35
|
-
regexFile: string;
|
|
36
|
-
[key: string]: string;
|
|
37
|
-
};
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.DataDomainEnum = void 0;
|
|
40
|
-
exports.initializeData = initializeData;
|
|
41
|
-
exports.getRegexConstants = getRegexConstants;
|
|
42
|
-
exports.getCompanyKeywordList = getCompanyKeywordList;
|
|
43
|
-
exports.getJobTitleSuffixList = getJobTitleSuffixList;
|
|
44
|
-
exports.isDataInitialized = isDataInitialized;
|
|
45
|
-
/**
|
|
46
|
-
* @file src/config/dataLoader.ts
|
|
47
|
-
* @TODO change this file and env.ts to use initializeEnvironment() pattern
|
|
48
|
-
*/
|
|
49
|
-
const env_1 = require("./env");
|
|
50
|
-
const setupLog_1 = require("./setupLog");
|
|
51
|
-
const reading_1 = require("../utils/io/reading");
|
|
52
|
-
const typeValidation_1 = require("../utils/typeValidation");
|
|
53
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
54
|
-
const validate = __importStar(require("../utils/argumentValidation"));
|
|
55
|
-
let dataInitialized = false;
|
|
56
|
-
let config = null;
|
|
57
|
-
/**
|
|
58
|
-
* @enum {string} **`DataDomainEnum`** `string`
|
|
59
|
-
* @property **`REGEX`** = `'regex'`
|
|
60
|
-
*/
|
|
61
|
-
var DataDomainEnum;
|
|
62
|
-
(function (DataDomainEnum) {
|
|
63
|
-
DataDomainEnum["REGEX"] = "regex";
|
|
64
|
-
})(DataDomainEnum || (exports.DataDomainEnum = DataDomainEnum = {}));
|
|
65
|
-
/* ---------------------- LOAD REGEX CONFIG -------------------------- */
|
|
66
|
-
let regexConstants = null;
|
|
67
|
-
/* ------------------------- MAIN FUNCTION ----------------------------- */
|
|
68
|
-
const DEFAULT_DOMAINS_TO_LOAD = [
|
|
69
|
-
DataDomainEnum.REGEX,
|
|
70
|
-
];
|
|
71
|
-
/**
|
|
72
|
-
* Initialize all data required by the application.
|
|
73
|
-
* This should be called once at the start of the application.
|
|
74
|
-
*/
|
|
75
|
-
async function initializeData(...domains) {
|
|
76
|
-
const source = getSourceString(__filename, initializeData.name);
|
|
77
|
-
if (dataInitialized) {
|
|
78
|
-
setupLog_1.typeshiLogger.info(`${source} Data already initialized, skipping...`);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (!domains || domains.length === 0) {
|
|
82
|
-
domains.push(...DEFAULT_DOMAINS_TO_LOAD);
|
|
83
|
-
}
|
|
84
|
-
setupLog_1.typeshiSimpleLogger.info(`${source} Starting data initialization...`);
|
|
85
|
-
try {
|
|
86
|
-
const configPath = node_path_1.default.join(env_1.DATA_DIR, `typeshi.data.config.json`);
|
|
87
|
-
config = await loadConfig(configPath);
|
|
88
|
-
for (const d of domains) {
|
|
89
|
-
switch (d) {
|
|
90
|
-
case DataDomainEnum.REGEX:
|
|
91
|
-
regexConstants = await loadRegexConstants(node_path_1.default.join(env_1.DATA_DIR, DataDomainEnum.REGEX, config.regexFile));
|
|
92
|
-
break;
|
|
93
|
-
default:
|
|
94
|
-
setupLog_1.typeshiLogger.warn(`${source} Unrecognized data domain: '${d}'. Skipping...`);
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
dataInitialized = true;
|
|
99
|
-
setupLog_1.typeshiSimpleLogger.info(`${source} ✓ All data initialized successfully`);
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
setupLog_1.typeshiLogger.error(`${source} ✗ Failed to initialize data:`, error);
|
|
103
|
-
(0, env_1.STOP_RUNNING)(1, `Data initialization failed`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
function getRegexConstants() {
|
|
107
|
-
if (!dataInitialized || !regexConstants) {
|
|
108
|
-
throw new Error('[dataLoader.getRegexConstants()] Regex constants not initialized. Call initializeData() first.');
|
|
109
|
-
}
|
|
110
|
-
return regexConstants;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* `Sync` Get company keyword list
|
|
114
|
-
* @returns **`COMPANY_KEYWORD_LIST`** `string[]`
|
|
115
|
-
*/
|
|
116
|
-
function getCompanyKeywordList() {
|
|
117
|
-
const constants = getRegexConstants();
|
|
118
|
-
return constants.COMPANY_KEYWORD_LIST;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Get job title suffix list
|
|
122
|
-
* @returns **`JOB_TITLE_SUFFIX_LIST`** `string[]`
|
|
123
|
-
*/
|
|
124
|
-
function getJobTitleSuffixList() {
|
|
125
|
-
const constants = getRegexConstants();
|
|
126
|
-
return constants.JOB_TITLE_SUFFIX_LIST;
|
|
127
|
-
}
|
|
128
|
-
function isDataInitialized() {
|
|
129
|
-
return dataInitialized;
|
|
130
|
-
}
|
|
131
|
-
async function loadConfig(jsonPath) {
|
|
132
|
-
const source = getSourceString(__filename, loadConfig.name);
|
|
133
|
-
validate.existingFileArgument(source, '.json', { jsonPath });
|
|
134
|
-
let configData = (0, reading_1.readJsonFileAsObject)(jsonPath);
|
|
135
|
-
validate.objectArgument(source, { configData, isDataLoaderConfig });
|
|
136
|
-
return configData;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Load regex constants
|
|
140
|
-
*/
|
|
141
|
-
async function loadRegexConstants(filePath) {
|
|
142
|
-
const source = getSourceString(__filename, loadRegexConstants.name);
|
|
143
|
-
setupLog_1.typeshiSimpleLogger.info(`${source} Loading regex constants...`);
|
|
144
|
-
validate.existingFileArgument(source, '.json', { filePath });
|
|
145
|
-
const REGEX_CONSTANTS = (0, reading_1.readJsonFileAsObject)(filePath);
|
|
146
|
-
if (!REGEX_CONSTANTS || !(0, typeValidation_1.hasKeys)(REGEX_CONSTANTS, ['COMPANY_KEYWORD_LIST', 'JOB_TITLE_SUFFIX_LIST'])) {
|
|
147
|
-
throw new Error(`${source} Invalid REGEX_CONSTANTS file at '${filePath}'. Expected json object to have 'COMPANY_KEYWORD_LIST' and 'JOB_TITLE_SUFFIX_LIST' keys.`);
|
|
148
|
-
}
|
|
149
|
-
const COMPANY_KEYWORD_LIST = REGEX_CONSTANTS.COMPANY_KEYWORD_LIST || [];
|
|
150
|
-
if (!(0, typeValidation_1.isNonEmptyArray)(COMPANY_KEYWORD_LIST)) {
|
|
151
|
-
throw new Error(`${source} Invalid COMPANY_KEYWORD_LIST in REGEX_CONSTANTS file at '${filePath}'`);
|
|
152
|
-
}
|
|
153
|
-
const JOB_TITLE_SUFFIX_LIST = REGEX_CONSTANTS.JOB_TITLE_SUFFIX_LIST || [];
|
|
154
|
-
if (!(0, typeValidation_1.isNonEmptyArray)(JOB_TITLE_SUFFIX_LIST)) {
|
|
155
|
-
throw new Error(`${source} Invalid JOB_TITLE_SUFFIX_LIST in REGEX_CONSTANTS file at '${filePath}'`);
|
|
156
|
-
}
|
|
157
|
-
setupLog_1.typeshiSimpleLogger.info(`${source} ✓ Regex constants loaded successfully`);
|
|
158
|
-
return {
|
|
159
|
-
COMPANY_KEYWORD_LIST,
|
|
160
|
-
JOB_TITLE_SUFFIX_LIST,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
function isDataLoaderConfig(value) {
|
|
164
|
-
return ((0, typeValidation_1.isObject)(value)
|
|
165
|
-
&& Object.values(value).every(v => (0, typeValidation_1.isNonEmptyString)(v)));
|
|
166
|
-
}
|
|
167
|
-
function getSourceString(fileName, func, funcInfo) {
|
|
168
|
-
fileName = node_path_1.default.basename(fileName).replace(/(?<=.+)\.[a-z0-9]{1,}$/i, '');
|
|
169
|
-
let funcName = typeof func === 'string' ? func : func.name;
|
|
170
|
-
return `[typeshi.${fileName}.${funcName}(${(0, typeValidation_1.isNonEmptyString)(funcInfo) ? ` ${funcInfo} ` : ''})]`;
|
|
171
|
-
}
|