@yamato-daiwa/es-extensions-nodejs 0.0.2 → 0.10.0-alpha.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/Distributable/ConsoleApplicationLogger.d.ts +68 -0
- package/Distributable/ConsoleApplicationLogger.js +435 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParser.d.ts +289 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParser.js +702 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParserLocalization.english.d.ts +4 -0
- package/Distributable/ConsoleCommandsParser/ConsoleCommandsParserLocalization.english.js +118 -0
- package/Distributable/DateTime/NodeJS_Timer.d.ts +21 -7
- package/Distributable/DateTime/NodeJS_Timer.js +61 -13
- package/Distributable/DotEnvFilesGenerator.d.ts +13 -0
- package/Distributable/DotEnvFilesGenerator.js +21 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundError.d.ts +25 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundError.js +21 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundErrorLocalization.english.d.ts +3 -0
- package/Distributable/Errors/FileNotFoundError/FileNotFoundErrorLocalization.english.js +7 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandError.d.ts +25 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandError.js +21 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandErrorLocalization.english.d.ts +3 -0
- package/Distributable/Errors/InvalidConsoleCommand/InvalidConsoleCommandErrorLocalization.english.js +7 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileError.d.ts +25 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileError.js +21 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileErrorLocalization.english.d.ts +3 -0
- package/Distributable/Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileErrorLocalization.english.js +7 -0
- package/Distributable/ImprovedFileSystem.d.ts +43 -0
- package/Distributable/ImprovedFileSystem.js +142 -0
- package/Distributable/ImprovedGlob.d.ts +57 -0
- package/Distributable/ImprovedGlob.js +275 -0
- package/Distributable/ImprovedPath/ImprovedPath.d.ts +59 -0
- package/Distributable/ImprovedPath/ImprovedPath.js +224 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessor.d.ts +55 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessor.js +228 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessorLocalization.english.d.ts +4 -0
- package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessorLocalization.english.js +11 -0
- package/Distributable/Temporary/appendCharacterIfItDoesNotPresentInLastPosition.d.ts +4 -0
- package/Distributable/Temporary/appendCharacterIfItDoesNotPresentInLastPosition.js +7 -0
- package/Distributable/Temporary/extractLastExtensionOfFileName.d.ts +9 -0
- package/Distributable/Temporary/extractLastExtensionOfFileName.js +21 -0
- package/Distributable/index.d.ts +22 -7
- package/Distributable/index.js +45 -7
- package/Distributable/isErrnoException.d.ts +2 -0
- package/Distributable/isErrnoException.js +12 -0
- package/LICENSE +1 -1
- package/README.md +51 -3
- package/package.json +45 -15
- package/tsconfig.test.json +0 -4
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RawObjectDataProcessor } from "@yamato-daiwa/es-extensions";
|
|
2
|
+
import type { PossiblyReadonlyParsedJSON } from "@yamato-daiwa/es-extensions";
|
|
3
|
+
declare abstract class ObjectDataFilesProcessor {
|
|
4
|
+
static localization: ObjectDataFilesProcessor.Localization;
|
|
5
|
+
static processFile<ValidData extends PossiblyReadonlyParsedJSON>(compoundParameter: Readonly<{
|
|
6
|
+
filePath: string;
|
|
7
|
+
validDataSpecification: RawObjectDataProcessor.ObjectDataSpecification;
|
|
8
|
+
schema?: ObjectDataFilesProcessor.SupportedSchemas;
|
|
9
|
+
synchronously: false;
|
|
10
|
+
}>): Promise<ValidData>;
|
|
11
|
+
static processFile<ValidData extends PossiblyReadonlyParsedJSON>(compoundParameter: Readonly<{
|
|
12
|
+
filePath: string;
|
|
13
|
+
validDataSpecification: RawObjectDataProcessor.ObjectDataSpecification;
|
|
14
|
+
schema?: ObjectDataFilesProcessor.SupportedSchemas;
|
|
15
|
+
synchronously: true;
|
|
16
|
+
}>): ValidData;
|
|
17
|
+
static processFile(compoundParameter: Readonly<{
|
|
18
|
+
filePath: string;
|
|
19
|
+
schema?: ObjectDataFilesProcessor.SupportedSchemas;
|
|
20
|
+
synchronously: false;
|
|
21
|
+
}>): Promise<unknown>;
|
|
22
|
+
static processFile(compoundParameter: Readonly<{
|
|
23
|
+
filePath: string;
|
|
24
|
+
schema?: ObjectDataFilesProcessor.SupportedSchemas;
|
|
25
|
+
synchronously: true;
|
|
26
|
+
}>): unknown;
|
|
27
|
+
private static extractRawRawDataSynchronously;
|
|
28
|
+
private static extractRawRawDataAsynchronously;
|
|
29
|
+
private static parseRawData;
|
|
30
|
+
}
|
|
31
|
+
declare namespace ObjectDataFilesProcessor {
|
|
32
|
+
enum SupportedSchemas {
|
|
33
|
+
JSON = "JSON",
|
|
34
|
+
YAML = "YAML",
|
|
35
|
+
DOTENV = "DOTENV"
|
|
36
|
+
}
|
|
37
|
+
type Localization = Readonly<{
|
|
38
|
+
generateUnableToDecideDataParsingAlgorithmErrorMessage: (templateVariables: Localization.UnableToDecideDataParsingAlgorithmErrorMessage.TemplateVariables) => string;
|
|
39
|
+
generateUnsupportedFileNameExtension: (templateVariables: Localization.UnsupportedFileNameExtensionErrorMessage.TemplateVariables) => string;
|
|
40
|
+
}>;
|
|
41
|
+
namespace Localization {
|
|
42
|
+
namespace UnableToDecideDataParsingAlgorithmErrorMessage {
|
|
43
|
+
type TemplateVariables = Readonly<{
|
|
44
|
+
filePath: string;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
namespace UnsupportedFileNameExtensionErrorMessage {
|
|
48
|
+
type TemplateVariables = Readonly<{
|
|
49
|
+
filePath: string;
|
|
50
|
+
fileNameLastExtensionWithoutLeadingDot: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export default ObjectDataFilesProcessor;
|
|
@@ -0,0 +1,228 @@
|
|
|
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
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
|
+
const yamljs_1 = __importDefault(require("yamljs"));
|
|
9
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
10
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
11
|
+
const extractLastExtensionOfFileName_1 = __importDefault(require("../Temporary/extractLastExtensionOfFileName"));
|
|
12
|
+
const isErrnoException_1 = __importDefault(require("../isErrnoException"));
|
|
13
|
+
const FileNotFoundError_1 = __importDefault(require("../Errors/FileNotFoundError/FileNotFoundError"));
|
|
14
|
+
const PathRefersToDirectoryNotFileError_1 = __importDefault(require("../Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileError"));
|
|
15
|
+
const ObjectDataFilesProcessorLocalization_english_1 = __importDefault(require("./ObjectDataFilesProcessorLocalization.english"));
|
|
16
|
+
class ObjectDataFilesProcessor {
|
|
17
|
+
static localization = ObjectDataFilesProcessorLocalization_english_1.default;
|
|
18
|
+
static processFile(compoundParameter) {
|
|
19
|
+
const filePath = compoundParameter.filePath;
|
|
20
|
+
let dataSchema;
|
|
21
|
+
if ((0, es_extensions_1.isNotUndefined)(compoundParameter.schema)) {
|
|
22
|
+
dataSchema = compoundParameter.schema;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const fileNameLastExtensionWithoutLeadingDot = (0, extractLastExtensionOfFileName_1.default)({
|
|
26
|
+
targetPath: filePath, withLeadingDot: false
|
|
27
|
+
});
|
|
28
|
+
if ((0, es_extensions_1.isNull)(fileNameLastExtensionWithoutLeadingDot)) {
|
|
29
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
30
|
+
errorInstance: new es_extensions_1.InvalidParameterValueError({
|
|
31
|
+
parameterName: "compoundParameter",
|
|
32
|
+
parameterNumber: 1,
|
|
33
|
+
messageSpecificPart: ObjectDataFilesProcessor.localization.
|
|
34
|
+
generateUnableToDecideDataParsingAlgorithmErrorMessage({ filePath })
|
|
35
|
+
}),
|
|
36
|
+
title: es_extensions_1.InvalidParameterValueError.localization.defaultTitle,
|
|
37
|
+
occurrenceLocation: "ObjectDataFilesProcessor.processFile(compoundParameter)"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
switch (fileNameLastExtensionWithoutLeadingDot) {
|
|
41
|
+
case "json": {
|
|
42
|
+
dataSchema = ObjectDataFilesProcessor.SupportedSchemas.JSON;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case "yaml":
|
|
46
|
+
case "yml": {
|
|
47
|
+
dataSchema = ObjectDataFilesProcessor.SupportedSchemas.YAML;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case "env": {
|
|
51
|
+
dataSchema = ObjectDataFilesProcessor.SupportedSchemas.DOTENV;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
default: {
|
|
55
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
56
|
+
errorInstance: new es_extensions_1.InvalidParameterValueError({
|
|
57
|
+
parameterName: "compoundParameter.filePath",
|
|
58
|
+
parameterNumber: 1,
|
|
59
|
+
messageSpecificPart: ObjectDataFilesProcessor.localization.generateUnsupportedFileNameExtension({
|
|
60
|
+
filePath, fileNameLastExtensionWithoutLeadingDot
|
|
61
|
+
})
|
|
62
|
+
}),
|
|
63
|
+
title: es_extensions_1.InvalidParameterValueError.localization.defaultTitle,
|
|
64
|
+
occurrenceLocation: "ObjectDataFilesProcessor.processFile(compoundParameter)"
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (compoundParameter.synchronously) {
|
|
70
|
+
return (0, es_extensions_1.isNotUndefined)(compoundParameter.validDataSpecification) ?
|
|
71
|
+
ObjectDataFilesProcessor.parseRawData({
|
|
72
|
+
rawData: ObjectDataFilesProcessor.extractRawRawDataSynchronously(filePath),
|
|
73
|
+
validDataSpecification: compoundParameter.validDataSpecification,
|
|
74
|
+
dataSchema,
|
|
75
|
+
filePathForLogging: filePath
|
|
76
|
+
}) :
|
|
77
|
+
ObjectDataFilesProcessor.parseRawData({
|
|
78
|
+
rawData: ObjectDataFilesProcessor.extractRawRawDataSynchronously(filePath),
|
|
79
|
+
dataSchema,
|
|
80
|
+
filePathForLogging: filePath
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return ObjectDataFilesProcessor.
|
|
84
|
+
extractRawRawDataAsynchronously(filePath).
|
|
85
|
+
then(async (rawData) => ((0, es_extensions_1.isNotUndefined)(compoundParameter.validDataSpecification) ?
|
|
86
|
+
ObjectDataFilesProcessor.parseRawData({
|
|
87
|
+
rawData,
|
|
88
|
+
validDataSpecification: compoundParameter.validDataSpecification,
|
|
89
|
+
dataSchema,
|
|
90
|
+
filePathForLogging: filePath
|
|
91
|
+
}) :
|
|
92
|
+
ObjectDataFilesProcessor.parseRawData({
|
|
93
|
+
rawData,
|
|
94
|
+
dataSchema,
|
|
95
|
+
filePathForLogging: filePath
|
|
96
|
+
})));
|
|
97
|
+
}
|
|
98
|
+
static extractRawRawDataSynchronously(filePath) {
|
|
99
|
+
const POTENTIAL_ERROR_OCCURRENCE_LOCATION = "ObjectDataFilesProcessor.processFile(compoundParameter)->" +
|
|
100
|
+
"ObjectDataFilesProcessor.extractRawRawDataSynchronously(filePath)";
|
|
101
|
+
let targetFileStatistics;
|
|
102
|
+
try {
|
|
103
|
+
targetFileStatistics = fs_1.default.statSync(filePath);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if ((0, isErrnoException_1.default)(error) && error.code === "ENOENT") {
|
|
107
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
108
|
+
errorInstance: new FileNotFoundError_1.default({ filePath }),
|
|
109
|
+
title: FileNotFoundError_1.default.localization.defaultTitle,
|
|
110
|
+
occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION,
|
|
111
|
+
innerError: error
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
if (!targetFileStatistics.isFile()) {
|
|
117
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
118
|
+
errorInstance: new PathRefersToDirectoryNotFileError_1.default({ targetPath: filePath }),
|
|
119
|
+
title: PathRefersToDirectoryNotFileError_1.default.localization.defaultTitle,
|
|
120
|
+
occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
let rawData;
|
|
124
|
+
try {
|
|
125
|
+
rawData = fs_1.default.readFileSync(filePath, "utf-8");
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
129
|
+
errorInstance: new es_extensions_1.FileReadingFailedError({ filePath }),
|
|
130
|
+
title: es_extensions_1.FileReadingFailedError.localization.defaultTitle,
|
|
131
|
+
occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION,
|
|
132
|
+
innerError: error
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return rawData;
|
|
136
|
+
}
|
|
137
|
+
static async extractRawRawDataAsynchronously(filePath) {
|
|
138
|
+
const POTENTIAL_ERROR_OCCURRENCE_LOCATION = "ObjectDataFilesProcessor.processFile(compoundParameter)->" +
|
|
139
|
+
"ObjectDataFilesProcessor.extractRawRawDataAsynchronously(filePath)";
|
|
140
|
+
let targetFileStatistics;
|
|
141
|
+
try {
|
|
142
|
+
targetFileStatistics = await promises_1.default.stat(filePath);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
if ((0, isErrnoException_1.default)(error) && error.code === "ENOENT") {
|
|
146
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
147
|
+
errorInstance: new FileNotFoundError_1.default({ filePath }),
|
|
148
|
+
title: FileNotFoundError_1.default.localization.defaultTitle,
|
|
149
|
+
occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION,
|
|
150
|
+
innerError: error
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
if (!targetFileStatistics.isFile()) {
|
|
156
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
157
|
+
errorInstance: new PathRefersToDirectoryNotFileError_1.default({ targetPath: filePath }),
|
|
158
|
+
title: PathRefersToDirectoryNotFileError_1.default.localization.defaultTitle,
|
|
159
|
+
occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
let rawData;
|
|
163
|
+
try {
|
|
164
|
+
rawData = await promises_1.default.readFile(filePath, "utf-8");
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
168
|
+
errorInstance: new es_extensions_1.FileReadingFailedError({ filePath }),
|
|
169
|
+
title: es_extensions_1.FileReadingFailedError.localization.defaultTitle,
|
|
170
|
+
occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION,
|
|
171
|
+
innerError: error
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return rawData;
|
|
175
|
+
}
|
|
176
|
+
static parseRawData({ rawData, validDataSpecification, dataSchema, filePathForLogging }) {
|
|
177
|
+
const POTENTIAL_ERROR_OCCURRENCE_LOCATION = "ObjectDataFilesProcessor.processFile(compoundParameter)->" +
|
|
178
|
+
"ObjectDataFilesProcessor.parseRawData(compoundParameter)";
|
|
179
|
+
let parsedData;
|
|
180
|
+
try {
|
|
181
|
+
switch (dataSchema) {
|
|
182
|
+
case ObjectDataFilesProcessor.SupportedSchemas.JSON: {
|
|
183
|
+
parsedData = JSON.parse(rawData);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
case ObjectDataFilesProcessor.SupportedSchemas.YAML: {
|
|
187
|
+
parsedData = yamljs_1.default.parse(rawData);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case ObjectDataFilesProcessor.SupportedSchemas.DOTENV: {
|
|
191
|
+
parsedData = dotenv_1.default.parse(rawData);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
197
|
+
errorInstance: new es_extensions_1.InvalidExternalDataError({ mentionToExpectedData: filePathForLogging }),
|
|
198
|
+
title: es_extensions_1.InvalidExternalDataError.localization.defaultTitle,
|
|
199
|
+
occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION,
|
|
200
|
+
innerError: error
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if ((0, es_extensions_1.isUndefined)(validDataSpecification)) {
|
|
204
|
+
return parsedData;
|
|
205
|
+
}
|
|
206
|
+
const processingResult = es_extensions_1.RawObjectDataProcessor.process(parsedData, validDataSpecification);
|
|
207
|
+
if (processingResult.isRawDataInvalid) {
|
|
208
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
209
|
+
errorInstance: new es_extensions_1.InvalidExternalDataError({
|
|
210
|
+
customMessage: `The contents of file '${filePathForLogging}' does not matching with valid data specification:\n` +
|
|
211
|
+
es_extensions_1.RawObjectDataProcessor.formatValidationErrorsList(processingResult.validationErrorsMessages)
|
|
212
|
+
}),
|
|
213
|
+
title: es_extensions_1.InvalidExternalDataError.localization.defaultTitle,
|
|
214
|
+
occurrenceLocation: POTENTIAL_ERROR_OCCURRENCE_LOCATION
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
return processingResult.processedData;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
(function (ObjectDataFilesProcessor) {
|
|
221
|
+
let SupportedSchemas;
|
|
222
|
+
(function (SupportedSchemas) {
|
|
223
|
+
SupportedSchemas["JSON"] = "JSON";
|
|
224
|
+
SupportedSchemas["YAML"] = "YAML";
|
|
225
|
+
SupportedSchemas["DOTENV"] = "DOTENV";
|
|
226
|
+
})(SupportedSchemas = ObjectDataFilesProcessor.SupportedSchemas || (ObjectDataFilesProcessor.SupportedSchemas = {}));
|
|
227
|
+
})(ObjectDataFilesProcessor || (ObjectDataFilesProcessor = {}));
|
|
228
|
+
exports.default = ObjectDataFilesProcessor;
|
package/Distributable/ObjectDataFilesProcessor/ObjectDataFilesProcessorLocalization.english.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const objectDataFilesProcessorLocalization__english = {
|
|
4
|
+
generateUnableToDecideDataParsingAlgorithmErrorMessage: ({ filePath }) => `Unable to decide the data parsing algorithm because target file path "${filePath}" has no the file name extension. ` +
|
|
5
|
+
"If it is intentional, specify \"dataSchema\" property with desired element of " +
|
|
6
|
+
"\"ObjectDataFilesProcessor.SupportedSchemas\" enumeration.",
|
|
7
|
+
generateUnsupportedFileNameExtension: ({ filePath, fileNameLastExtensionWithoutLeadingDot }) => `Target file "${filePath}" has unsupported file name extension "${fileNameLastExtensionWithoutLeadingDot}". ` +
|
|
8
|
+
"If it is intentional and this file including the data of known for \"ObjectDataFilesProcessor\" schema, please specify " +
|
|
9
|
+
"\"compoundParameter.dataSchema\" with desired element of \"ObjectDataFilesProcessor.SupportedSchemas\" enumeration."
|
|
10
|
+
};
|
|
11
|
+
exports.default = objectDataFilesProcessorLocalization__english;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = appendCharacterIfItDoesNotPresentInLastPosition;
|
|
4
|
+
function appendCharacterIfItDoesNotPresentInLastPosition(compoundParameter) {
|
|
5
|
+
const { targetString, trailingCharacter } = compoundParameter;
|
|
6
|
+
return targetString.endsWith(trailingCharacter) ? targetString : `${targetString}${trailingCharacter}`;
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default function extractLastExtensionOfFileName(compoundParameter: Readonly<{
|
|
2
|
+
targetPath: string;
|
|
3
|
+
withLeadingDot: boolean;
|
|
4
|
+
}>): string | null;
|
|
5
|
+
export default function extractLastExtensionOfFileName(compoundParameter: Readonly<{
|
|
6
|
+
targetPath: string;
|
|
7
|
+
withLeadingDot: boolean;
|
|
8
|
+
mustThrowErrorIfLastPathSegmentHasNotDots: true;
|
|
9
|
+
}>): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = extractLastExtensionOfFileName;
|
|
4
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
5
|
+
function extractLastExtensionOfFileName(compoundParameter) {
|
|
6
|
+
const lastFileNameExtensionWithoutLeadingDot = (/.(?<lastFileNameExtensionWithoutLeadingDot>\w+)$/u).
|
|
7
|
+
exec(compoundParameter.targetPath)?.
|
|
8
|
+
groups?.
|
|
9
|
+
lastFileNameExtensionWithoutLeadingDot;
|
|
10
|
+
if ((0, es_extensions_1.isUndefined)(lastFileNameExtensionWithoutLeadingDot)) {
|
|
11
|
+
if (compoundParameter.mustThrowErrorIfLastPathSegmentHasNotDots === true) {
|
|
12
|
+
es_extensions_1.Logger.throwErrorWithFormattedMessage({
|
|
13
|
+
errorInstance: new es_extensions_1.UnexpectedEventError(`Contrary to expectations, the path ${compoundParameter.targetPath} has not the file name extension.`),
|
|
14
|
+
title: es_extensions_1.UnexpectedEventError.localization.defaultTitle,
|
|
15
|
+
occurrenceLocation: "extractLastExtensionOfFileName(compoundParameter)"
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return lastFileNameExtensionWithoutLeadingDot;
|
|
21
|
+
}
|
package/Distributable/index.d.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* @yamato-daiwa/es-extensions-nodejs
|
|
3
|
-
* (c)
|
|
4
|
-
* Released under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export {
|
|
1
|
+
/*!
|
|
2
|
+
* @yamato-daiwa/es-extensions-nodejs v1.9
|
|
3
|
+
* (c) 2023 Yamato Daiwa Co., Ltd.
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
export { default as NodeJS_Timer } from "./DateTime/NodeJS_Timer";
|
|
7
|
+
export { default as ConsoleApplicationLogger } from "./ConsoleApplicationLogger";
|
|
8
|
+
export { default as DotEnvFilesGenerator } from "./DotEnvFilesGenerator";
|
|
9
|
+
export { default as ConsoleCommandsParser } from "./ConsoleCommandsParser/ConsoleCommandsParser";
|
|
10
|
+
export { default as consoleCommandsParserLocalization__english } from "./ConsoleCommandsParser/ConsoleCommandsParserLocalization.english";
|
|
11
|
+
export { default as PathRefersToDirectoryNotFileError } from "./Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileError";
|
|
12
|
+
export { default as pathRefersToDirectoryNotFileErrorLocalization__english } from "./Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileErrorLocalization.english";
|
|
13
|
+
export { default as FileNotFoundError } from "./Errors/FileNotFoundError/FileNotFoundError";
|
|
14
|
+
export { default as FileNotFoundErrorLocalization__English } from "./Errors/FileNotFoundError/FileNotFoundErrorLocalization.english";
|
|
15
|
+
export { default as InvalidConsoleCommandError } from "./Errors/InvalidConsoleCommand/InvalidConsoleCommandError";
|
|
16
|
+
export { default as InvalidConsoleCommandErrorLocalization__English } from "./Errors/InvalidConsoleCommand/InvalidConsoleCommandErrorLocalization.english";
|
|
17
|
+
export { default as ImprovedPath } from "./ImprovedPath/ImprovedPath";
|
|
18
|
+
export { default as ImprovedGlob } from "./ImprovedGlob";
|
|
19
|
+
export { default as ImprovedFileSystem } from "./ImprovedFileSystem";
|
|
20
|
+
export { default as ObjectDataFilesProcessor } from "./ObjectDataFilesProcessor/ObjectDataFilesProcessor";
|
|
21
|
+
export { default as objectDataFilesProcessorLocalization__english } from "./ObjectDataFilesProcessor/ObjectDataFilesProcessorLocalization.english";
|
|
22
|
+
export { default as isErrnoException } from "./isErrnoException";
|
package/Distributable/index.js
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* @yamato-daiwa/es-extensions-nodejs v1.9
|
|
4
|
+
* (c) 2023 Yamato Daiwa Co., Ltd.
|
|
5
|
+
* Released under the MIT License.
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.isErrnoException = exports.objectDataFilesProcessorLocalization__english = exports.ObjectDataFilesProcessor = exports.ImprovedFileSystem = exports.ImprovedGlob = exports.ImprovedPath = exports.InvalidConsoleCommandErrorLocalization__English = exports.InvalidConsoleCommandError = exports.FileNotFoundErrorLocalization__English = exports.FileNotFoundError = exports.pathRefersToDirectoryNotFileErrorLocalization__english = exports.PathRefersToDirectoryNotFileError = exports.consoleCommandsParserLocalization__english = exports.ConsoleCommandsParser = exports.DotEnvFilesGenerator = exports.ConsoleApplicationLogger = exports.NodeJS_Timer = void 0;
|
|
12
|
+
var NodeJS_Timer_1 = require("./DateTime/NodeJS_Timer");
|
|
13
|
+
Object.defineProperty(exports, "NodeJS_Timer", { enumerable: true, get: function () { return __importDefault(NodeJS_Timer_1).default; } });
|
|
14
|
+
var ConsoleApplicationLogger_1 = require("./ConsoleApplicationLogger");
|
|
15
|
+
Object.defineProperty(exports, "ConsoleApplicationLogger", { enumerable: true, get: function () { return __importDefault(ConsoleApplicationLogger_1).default; } });
|
|
16
|
+
var DotEnvFilesGenerator_1 = require("./DotEnvFilesGenerator");
|
|
17
|
+
Object.defineProperty(exports, "DotEnvFilesGenerator", { enumerable: true, get: function () { return __importDefault(DotEnvFilesGenerator_1).default; } });
|
|
18
|
+
var ConsoleCommandsParser_1 = require("./ConsoleCommandsParser/ConsoleCommandsParser");
|
|
19
|
+
Object.defineProperty(exports, "ConsoleCommandsParser", { enumerable: true, get: function () { return __importDefault(ConsoleCommandsParser_1).default; } });
|
|
20
|
+
var ConsoleCommandsParserLocalization_english_1 = require("./ConsoleCommandsParser/ConsoleCommandsParserLocalization.english");
|
|
21
|
+
Object.defineProperty(exports, "consoleCommandsParserLocalization__english", { enumerable: true, get: function () { return __importDefault(ConsoleCommandsParserLocalization_english_1).default; } });
|
|
22
|
+
var PathRefersToDirectoryNotFileError_1 = require("./Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileError");
|
|
23
|
+
Object.defineProperty(exports, "PathRefersToDirectoryNotFileError", { enumerable: true, get: function () { return __importDefault(PathRefersToDirectoryNotFileError_1).default; } });
|
|
24
|
+
var PathRefersToDirectoryNotFileErrorLocalization_english_1 = require("./Errors/PathRefersToDirectoryNotFileError/PathRefersToDirectoryNotFileErrorLocalization.english");
|
|
25
|
+
Object.defineProperty(exports, "pathRefersToDirectoryNotFileErrorLocalization__english", { enumerable: true, get: function () { return __importDefault(PathRefersToDirectoryNotFileErrorLocalization_english_1).default; } });
|
|
26
|
+
var FileNotFoundError_1 = require("./Errors/FileNotFoundError/FileNotFoundError");
|
|
27
|
+
Object.defineProperty(exports, "FileNotFoundError", { enumerable: true, get: function () { return __importDefault(FileNotFoundError_1).default; } });
|
|
28
|
+
var FileNotFoundErrorLocalization_english_1 = require("./Errors/FileNotFoundError/FileNotFoundErrorLocalization.english");
|
|
29
|
+
Object.defineProperty(exports, "FileNotFoundErrorLocalization__English", { enumerable: true, get: function () { return __importDefault(FileNotFoundErrorLocalization_english_1).default; } });
|
|
30
|
+
var InvalidConsoleCommandError_1 = require("./Errors/InvalidConsoleCommand/InvalidConsoleCommandError");
|
|
31
|
+
Object.defineProperty(exports, "InvalidConsoleCommandError", { enumerable: true, get: function () { return __importDefault(InvalidConsoleCommandError_1).default; } });
|
|
32
|
+
var InvalidConsoleCommandErrorLocalization_english_1 = require("./Errors/InvalidConsoleCommand/InvalidConsoleCommandErrorLocalization.english");
|
|
33
|
+
Object.defineProperty(exports, "InvalidConsoleCommandErrorLocalization__English", { enumerable: true, get: function () { return __importDefault(InvalidConsoleCommandErrorLocalization_english_1).default; } });
|
|
34
|
+
var ImprovedPath_1 = require("./ImprovedPath/ImprovedPath");
|
|
35
|
+
Object.defineProperty(exports, "ImprovedPath", { enumerable: true, get: function () { return __importDefault(ImprovedPath_1).default; } });
|
|
36
|
+
var ImprovedGlob_1 = require("./ImprovedGlob");
|
|
37
|
+
Object.defineProperty(exports, "ImprovedGlob", { enumerable: true, get: function () { return __importDefault(ImprovedGlob_1).default; } });
|
|
38
|
+
var ImprovedFileSystem_1 = require("./ImprovedFileSystem");
|
|
39
|
+
Object.defineProperty(exports, "ImprovedFileSystem", { enumerable: true, get: function () { return __importDefault(ImprovedFileSystem_1).default; } });
|
|
40
|
+
var ObjectDataFilesProcessor_1 = require("./ObjectDataFilesProcessor/ObjectDataFilesProcessor");
|
|
41
|
+
Object.defineProperty(exports, "ObjectDataFilesProcessor", { enumerable: true, get: function () { return __importDefault(ObjectDataFilesProcessor_1).default; } });
|
|
42
|
+
var ObjectDataFilesProcessorLocalization_english_1 = require("./ObjectDataFilesProcessor/ObjectDataFilesProcessorLocalization.english");
|
|
43
|
+
Object.defineProperty(exports, "objectDataFilesProcessorLocalization__english", { enumerable: true, get: function () { return __importDefault(ObjectDataFilesProcessorLocalization_english_1).default; } });
|
|
44
|
+
var isErrnoException_1 = require("./isErrnoException");
|
|
45
|
+
Object.defineProperty(exports, "isErrnoException", { enumerable: true, get: function () { return __importDefault(isErrnoException_1).default; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = isErrnoException;
|
|
4
|
+
const es_extensions_1 = require("@yamato-daiwa/es-extensions");
|
|
5
|
+
function isErrnoException(error) {
|
|
6
|
+
return (0, es_extensions_1.isArbitraryObject)(error) &&
|
|
7
|
+
error instanceof Error &&
|
|
8
|
+
((0, es_extensions_1.isNumber)(error.errno, { mustConsiderNaN_AsNumber: false }) || (0, es_extensions_1.isUndefined)(error.errno)) &&
|
|
9
|
+
((0, es_extensions_1.isString)(error.code) || (0, es_extensions_1.isUndefined)(error.code)) &&
|
|
10
|
+
((0, es_extensions_1.isString)(error.path) || (0, es_extensions_1.isUndefined)(error.path)) &&
|
|
11
|
+
((0, es_extensions_1.isString)(error.syscall) || (0, es_extensions_1.isUndefined)(error.syscall));
|
|
12
|
+
}
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2023-present, Yamato Daiwa Co., Ltd.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,12 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Yamato Daiwa ES Extensions [YDEE] - NodeJS
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@yamato-daiwa/es-extensions)
|
|
4
|
+
[](https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions/blob/master/CoreLibrary/Package)
|
|
5
|
+
[](https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions/blob/master/CoreLibrary/Package/LICENSE)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://plugins.jetbrains.com/plugin/17638-yamato-daiwa-es-extensions)
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/@yamato-daiwa/es-extensions-nodejs)
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
[](https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions?sponsor=1)
|
|
13
|
+
[](https://www.paypal.com/paypalme/tokugawatakeshi)
|
|
14
|
+
[](https://liberapay.com/TokugawaT-YD)
|
|
2
15
|
|
|
3
16
|
Additional to [@yamato-daiwa/es-extensions](https://www.npmjs.com/package/@yamato-daiwa/es-extensions) functionality
|
|
4
|
-
for Node.js environment.
|
|
17
|
+
for Node.js environment.
|
|
18
|
+
|
|
19
|
+
Helper functions and classes aimed to reduce the routine code.
|
|
5
20
|
Build-in TypeScript type safety without `any` type.
|
|
21
|
+
Oriented to TypeScript users investing the time to quality including type-safety.
|
|
6
22
|
|
|
7
23
|
|
|
8
24
|
## Installation
|
|
9
25
|
|
|
26
|
+
The minor versions of **@yamato-daiwa/es-extensions-nodejs** and **@yamato-daiwa/es-extensions** must match.
|
|
27
|
+
|
|
10
28
|
```
|
|
11
|
-
npm i @yamato-daiwa/es-extensions-nodejs -E
|
|
29
|
+
npm i @yamato-daiwa/es-extensions-nodejs @yamato-daiwa/es-extensions -E
|
|
12
30
|
```
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Functionality
|
|
34
|
+
### Utils
|
|
35
|
+
|
|
36
|
+
<dl>
|
|
37
|
+
|
|
38
|
+
<dt><a href="https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions/blob/master/NodeJS/Package/Documentation/Logging/ConsoleApplicationLogger/ConsoleApplicationLogger.md">ConsoleApplicationLogger</a></dt>
|
|
39
|
+
<dd>The implementation of <b>ILogger</b> interface for <a href="https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions/blob/master/CoreLibrary/Package/Documentation/Logging/Logger/Logger.md">Logger</a> facade and Node.js environment.</dd>
|
|
40
|
+
|
|
41
|
+
<dt><a href="https://ee.yamato-daiwa.com/NodeJS/ConsoleCommandsParser/ConsoleCommandsParser.english.html">ConsoleCommandsParser</a></dt>
|
|
42
|
+
<dd>Parsing and validating of CLI commands</dd>
|
|
43
|
+
|
|
44
|
+
<dt>isErrnoException</dt>
|
|
45
|
+
<dd>Type guard which checks is value compatible with <b>NodeJS.ErrnoException</b> interface.</dd>
|
|
46
|
+
|
|
47
|
+
</dl>
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Pre-made errors
|
|
51
|
+
|
|
52
|
+
<dl>
|
|
53
|
+
|
|
54
|
+
<dt>FileNotFoundError</dt>
|
|
55
|
+
<dd>Intended to be thrown when the file which expected to exist was not found.</dd>
|
|
56
|
+
|
|
57
|
+
<dt>InvalidConsoleCommandError</dt>
|
|
58
|
+
<dd>Intended to be thrown when the inputted console commands does not match with the manual.</dd>
|
|
59
|
+
|
|
60
|
+
</dl>
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamato-daiwa/es-extensions-nodejs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.10.0-alpha.0",
|
|
4
4
|
"description": "Additional to @yamato-daiwa/es-extensions functionality for Node.js environment. Helper functions and classes aimed to reduce the routine code. Build-in TypeScript type safety.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nodejs",
|
|
7
|
+
"typescript",
|
|
7
8
|
"utils",
|
|
8
9
|
"logger"
|
|
9
10
|
],
|
|
@@ -12,31 +13,60 @@
|
|
|
12
13
|
"email": "tokugawa.takesi@gmail.com"
|
|
13
14
|
},
|
|
14
15
|
"license": "MIT",
|
|
16
|
+
"homepage": "https://ee.yamato-daiwa.com",
|
|
15
17
|
"repository": {
|
|
16
18
|
"type": "git",
|
|
17
|
-
"url": "https://github.com/TokugawaTakeshi/
|
|
19
|
+
"url": "git+https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions.git"
|
|
18
20
|
},
|
|
19
21
|
"bugs": {
|
|
20
|
-
"url": "https://github.com/TokugawaTakeshi/
|
|
22
|
+
"url": "https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions.git/issues",
|
|
21
23
|
"email": "tokugawa.takesi@gmail.com"
|
|
22
24
|
},
|
|
23
25
|
"main": "./Distributable/index.js",
|
|
26
|
+
"sideEffects": false,
|
|
24
27
|
"types": "./Distributable/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"Distributable"
|
|
30
|
+
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=22.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@yamato-daiwa/es-extensions": "0.10.0-alpha.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"dotenv": "17.4.2",
|
|
39
|
+
"glob": "13.0.6",
|
|
40
|
+
"json5": "2.2.3",
|
|
41
|
+
"minimatch": "10.2.6",
|
|
42
|
+
"yamljs": "0.3.0"
|
|
43
|
+
},
|
|
25
44
|
"devDependencies": {
|
|
26
|
-
"@types/
|
|
27
|
-
"@types/node": "
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
45
|
+
"@types/json5": "0.0.30",
|
|
46
|
+
"@types/node": "22.15.31",
|
|
47
|
+
"@types/yamljs": "0.2.34",
|
|
48
|
+
"@yamato-daiwa/es-extensions": "0.10.0-alpha.0",
|
|
49
|
+
"@yamato-daiwa/style_guides": "0.15.0",
|
|
50
|
+
"rimraf": "6.1.3",
|
|
51
|
+
"tsx": "4.23.15",
|
|
52
|
+
"typescript": "6.0.3"
|
|
32
53
|
},
|
|
33
|
-
"
|
|
34
|
-
"
|
|
54
|
+
"overrides": {
|
|
55
|
+
"yamljs": {
|
|
56
|
+
"argparse": "3.0.3"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"allowScripts": {
|
|
60
|
+
"esbuild": true
|
|
35
61
|
},
|
|
36
62
|
"scripts": {
|
|
37
|
-
"
|
|
63
|
+
"Check Types": "tsc --noEmit",
|
|
64
|
+
"Lint": "eslint",
|
|
65
|
+
"Run Tests": "node --require tsx/cjs --test \"Tests/Automated/**/*.test.ts\"",
|
|
66
|
+
"Rebuild Distributable Without Preliminary Cleaning": "tsc -p tsconfig.build.json",
|
|
67
|
+
"Rebuild Distributable": "rimraf --glob Distributable/* && tsc -p tsconfig.build.json",
|
|
68
|
+
"Rebuild Distributable and Realize Alpha": "npm run \"Rebuild Distributable\" && npm publish --tag alpha",
|
|
69
|
+
"Rebuild Distributable and Realize RC": "npm run \"Rebuild Distributable\" && npm publish --tag rc"
|
|
38
70
|
},
|
|
39
|
-
"
|
|
40
|
-
"@yamato-daiwa/es-extensions": "1.0.1"
|
|
41
|
-
}
|
|
71
|
+
"funding": "https://github.com/TokugawaTakeshi/Yamato-Daiwa-ES-Extensions?sponsor=1"
|
|
42
72
|
}
|
package/tsconfig.test.json
DELETED