drapcode-utility 2.0.0 → 2.0.2
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/build/encryption/KMS.js +54 -102
- package/build/encryption/crypt.d.ts +4 -2
- package/build/encryption/crypt.js +76 -91
- package/build/encryption/file.d.ts +0 -2
- package/build/encryption/file.js +14 -130
- package/build/encryption/index.js +162 -334
- package/build/encryption/utility.js +7 -10
- package/build/errors/app-error.js +9 -27
- package/build/errors/axios-error.js +3 -3
- package/build/errors/bad-request-error.js +10 -28
- package/build/errors/custom-error.js +5 -23
- package/build/errors/not-found.js +9 -27
- package/build/format-fields/index.d.ts +0 -1
- package/build/format-fields/index.js +32 -65
- package/build/index.d.ts +1 -4
- package/build/index.js +1 -4
- package/build/middlewares/error-logger.d.ts +1 -1
- package/build/middlewares/error-logger.js +29 -29
- package/build/middlewares/redis/request-log.js +24 -74
- package/build/query/queryBuilder.d.ts +9 -0
- package/build/query/queryBuilder.js +567 -0
- package/build/utils/check-error.d.ts +15 -8
- package/build/utils/check-error.js +71 -160
- package/build/utils/common-util.d.ts +40 -39
- package/build/utils/common-util.js +60 -59
- package/build/utils/date-util.d.ts +28 -7
- package/build/utils/date-util.js +180 -127
- package/build/utils/file-util.d.ts +51 -6
- package/build/utils/file-util.js +36 -40
- package/build/utils/prepare-query.js +70 -43
- package/build/utils/project-util.d.ts +43 -5
- package/build/utils/project-util.js +176 -121
- package/build/utils/query-parser.d.ts +1 -1
- package/build/utils/query-parser.js +289 -342
- package/build/utils/query-utils.d.ts +2 -2
- package/build/utils/query-utils.js +103 -116
- package/build/utils/rest-client.js +236 -328
- package/build/utils/s3-util.js +238 -469
- package/build/utils/token.js +34 -81
- package/build/utils/util.d.ts +58 -13
- package/build/utils/util.js +424 -494
- package/build/utils/uuid-generator.d.ts +20 -1
- package/build/utils/uuid-generator.js +111 -47
- package/package.json +7 -5
- package/build/middlewares/interceptor-logger-new.d.ts +0 -2
- package/build/middlewares/interceptor-logger-new.js +0 -53
- package/build/middlewares/interceptor-logger.d.ts +0 -2
- package/build/middlewares/interceptor-logger.js +0 -52
- package/build/utils/query-parser-new.d.ts +0 -1
- package/build/utils/query-parser-new.js +0 -541
package/build/utils/date-util.js
CHANGED
|
@@ -1,98 +1,136 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatProjectDates = exports.timezoneDateParse = exports.nextDayDate = exports.getDateRangeValue = exports.getDateValue = exports.createLogsDateFormat = exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
exports.formatProjectDates = exports.timezoneDateParse = exports.nextDayDate = exports.getDateRangeValue = exports.getDateValue = exports.createLogsDateFormat = exports.createLoggerPreviousDateFormat = exports.createLoggerDateFormat = exports.DATE_REGEX = void 0;
|
|
7
|
+
const drapcode_constant_1 = require("drapcode-constant");
|
|
8
|
+
const moment_1 = __importDefault(require("moment"));
|
|
9
|
+
const dateFormat = "YYYY-MM-DDTHH:mm:ss.SSS";
|
|
6
10
|
exports.DATE_REGEX = /^[12]\d{3}(-(0[1-9]|1[0-2])(-(0[1-9]|[12][0-9]|3[01]))?)(T| )?(([01][0-9]|2[0-3]):[0-5]\d(:[0-5]\d(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const createLoggerDateFormat = (timezone) => {
|
|
12
|
+
try {
|
|
13
|
+
let result = (0, moment_1.default)();
|
|
14
|
+
if (timezone) {
|
|
15
|
+
if (!/^[+-]\d{2}:\d{2}$/.test(timezone)) {
|
|
16
|
+
throw new Error("Invalid timezone format. Expected format: +/-HH:mm");
|
|
17
|
+
}
|
|
18
|
+
result = result.utcOffset(timezone);
|
|
19
|
+
}
|
|
20
|
+
return result.format("YYYY-MM-DD");
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.error("Error in createLoggerDateFormat:", error);
|
|
24
|
+
return (0, moment_1.default)().format("YYYY-MM-DD");
|
|
25
|
+
}
|
|
12
26
|
};
|
|
13
27
|
exports.createLoggerDateFormat = createLoggerDateFormat;
|
|
14
|
-
|
|
15
|
-
return
|
|
28
|
+
const createLoggerPreviousDateFormat = () => {
|
|
29
|
+
return (0, moment_1.default)().subtract(10, "days").format("YYYY-MM-DD");
|
|
16
30
|
};
|
|
17
|
-
exports.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
exports.createLoggerPreviousDateFormat = createLoggerPreviousDateFormat;
|
|
32
|
+
const createLogsDateFormat = (timezone) => {
|
|
33
|
+
try {
|
|
34
|
+
let result = (0, moment_1.default)();
|
|
35
|
+
if (timezone) {
|
|
36
|
+
if (!/^[+-]\d{2}:\d{2}$/.test(timezone)) {
|
|
37
|
+
throw new Error("Invalid timezone format. Expected format: +/-HH:mm");
|
|
38
|
+
}
|
|
39
|
+
result = result.utcOffset(timezone);
|
|
40
|
+
}
|
|
41
|
+
return result.format("YYYY-MM-DDTHH:mm:ss.SSS");
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error("Error in createLogsDateFormat:", error);
|
|
45
|
+
return (0, moment_1.default)().format("YYYY-MM-DDTHH:mm:ss.SSS");
|
|
46
|
+
}
|
|
23
47
|
};
|
|
24
48
|
exports.createLogsDateFormat = createLogsDateFormat;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
const getDateValue = (value, timezone) => {
|
|
50
|
+
try {
|
|
51
|
+
if (!value)
|
|
52
|
+
return (0, exports.createLogsDateFormat)(timezone);
|
|
53
|
+
const dateFormat = "YYYY-MM-DDTHH:mm:ss.SSS";
|
|
54
|
+
const [type, number, unit] = value.split(":");
|
|
55
|
+
if (!["ADD", "SUB"].includes(type)) {
|
|
56
|
+
return (0, exports.createLogsDateFormat)(timezone);
|
|
57
|
+
}
|
|
58
|
+
const dateUnit = getDateUnit(unit);
|
|
59
|
+
if (!dateUnit) {
|
|
60
|
+
throw new Error(`Invalid date unit: ${unit}`);
|
|
61
|
+
}
|
|
62
|
+
let result = (0, moment_1.default)();
|
|
63
|
+
if (type === "ADD") {
|
|
64
|
+
result = result.add(Number(number), dateUnit);
|
|
65
|
+
}
|
|
66
|
+
else if (type === "SUB") {
|
|
67
|
+
result = result.subtract(Number(number), dateUnit);
|
|
68
|
+
}
|
|
69
|
+
if (timezone) {
|
|
70
|
+
if (!/^[+-]\d{2}:\d{2}$/.test(timezone)) {
|
|
71
|
+
throw new Error("Invalid timezone format. Expected format: +/-HH:mm");
|
|
72
|
+
}
|
|
73
|
+
result = result.utcOffset(timezone);
|
|
74
|
+
}
|
|
75
|
+
return result.format(dateFormat);
|
|
37
76
|
}
|
|
38
|
-
|
|
39
|
-
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error("Error in getDateValue:", error);
|
|
79
|
+
return (0, exports.createLogsDateFormat)(timezone);
|
|
40
80
|
}
|
|
41
|
-
result = timezone ? result.utcOffset(timezone) : result;
|
|
42
|
-
return result.format(dateFormat);
|
|
43
81
|
};
|
|
44
82
|
exports.getDateValue = getDateValue;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
else if (key === drapcode_constant_1.NOT_EQUAL) {
|
|
72
|
-
finalValue = {
|
|
73
|
-
$or: [
|
|
74
|
-
(_b = {}, _b[field] = { $gte: endValue.format(dateFormat) }, _b),
|
|
75
|
-
(_c = {}, _c[field] = { $lte: startValue.format(dateFormat) }, _c),
|
|
76
|
-
],
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
else if (key === drapcode_constant_1.EQUALS_OR_IGNORE) {
|
|
80
|
-
if (startValue && endValue) {
|
|
81
|
-
finalValue = (_d = {},
|
|
82
|
-
_d[field] = {
|
|
83
|
-
$gte: startValue.format(dateFormat),
|
|
84
|
-
$lte: endValue.format(dateFormat),
|
|
83
|
+
const getDateRangeValue = (key, field, value) => {
|
|
84
|
+
try {
|
|
85
|
+
let startValue = null;
|
|
86
|
+
let endValue = null;
|
|
87
|
+
switch (value) {
|
|
88
|
+
case drapcode_constant_1.CURRENT_MONTH:
|
|
89
|
+
startValue = (0, moment_1.default)().startOf("month");
|
|
90
|
+
endValue = (0, moment_1.default)().endOf("month");
|
|
91
|
+
break;
|
|
92
|
+
case drapcode_constant_1.CURRENT_YEAR:
|
|
93
|
+
startValue = (0, moment_1.default)().startOf("year");
|
|
94
|
+
endValue = (0, moment_1.default)().endOf("year");
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
return {};
|
|
98
|
+
}
|
|
99
|
+
if (!startValue || !endValue) {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
102
|
+
startValue = formatDate(startValue);
|
|
103
|
+
endValue = formatDate(endValue);
|
|
104
|
+
if ([drapcode_constant_1.EQUALS, drapcode_constant_1.EQUALS_OR_IGNORE].includes(key)) {
|
|
105
|
+
return {
|
|
106
|
+
[field]: {
|
|
107
|
+
$gte: startValue,
|
|
108
|
+
$lte: endValue,
|
|
85
109
|
},
|
|
86
|
-
|
|
110
|
+
};
|
|
87
111
|
}
|
|
88
|
-
else {
|
|
89
|
-
|
|
112
|
+
else if (key === drapcode_constant_1.NOT_EQUAL) {
|
|
113
|
+
return {
|
|
114
|
+
$or: [
|
|
115
|
+
{ [field]: { $gte: endValue } },
|
|
116
|
+
{ [field]: { $lte: startValue } },
|
|
117
|
+
],
|
|
118
|
+
};
|
|
90
119
|
}
|
|
120
|
+
return {};
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error("Error in getDateRangeValue:", error);
|
|
124
|
+
return {};
|
|
91
125
|
}
|
|
92
|
-
return finalValue;
|
|
93
126
|
};
|
|
94
127
|
exports.getDateRangeValue = getDateRangeValue;
|
|
95
|
-
|
|
128
|
+
const formatDate = (date) => {
|
|
129
|
+
if (!date)
|
|
130
|
+
return `${date}`;
|
|
131
|
+
return date.format(dateFormat);
|
|
132
|
+
};
|
|
133
|
+
const getDateUnit = (unit) => {
|
|
96
134
|
switch (unit) {
|
|
97
135
|
case drapcode_constant_1.HOUR:
|
|
98
136
|
return "hour";
|
|
@@ -105,64 +143,79 @@ var getDateUnit = function (unit) {
|
|
|
105
143
|
case drapcode_constant_1.YEAR:
|
|
106
144
|
return "years";
|
|
107
145
|
default:
|
|
108
|
-
return
|
|
146
|
+
return null;
|
|
109
147
|
}
|
|
110
148
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
149
|
+
const nextDayDate = (date) => {
|
|
150
|
+
try {
|
|
151
|
+
const parsedDate = (0, moment_1.default)(date);
|
|
152
|
+
if (!parsedDate.isValid()) {
|
|
153
|
+
throw new Error("Invalid date input");
|
|
154
|
+
}
|
|
155
|
+
return parsedDate.add(1, "days").format("YYYY-MM-DD");
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
console.error("Error in nextDayDate:", error);
|
|
159
|
+
return (0, moment_1.default)().add(1, "days").format("YYYY-MM-DD");
|
|
160
|
+
}
|
|
114
161
|
};
|
|
115
162
|
exports.nextDayDate = nextDayDate;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
163
|
+
const timezoneDateParse = (value, nextDay = false, prevDay = false) => {
|
|
164
|
+
try {
|
|
165
|
+
let timeZoneDate = (0, moment_1.default)(value);
|
|
166
|
+
if (!timeZoneDate.isValid()) {
|
|
167
|
+
throw new Error("Invalid date input");
|
|
168
|
+
}
|
|
169
|
+
if (nextDay && value.length <= 10) {
|
|
170
|
+
timeZoneDate = timeZoneDate.add(1, "days");
|
|
171
|
+
}
|
|
172
|
+
if (prevDay && value.length <= 10) {
|
|
173
|
+
timeZoneDate = timeZoneDate.subtract(1, "days");
|
|
174
|
+
}
|
|
175
|
+
const formatted = timeZoneDate.format("YYYY-MM-DDTHH:mm:ss");
|
|
176
|
+
return new Date(formatted);
|
|
177
|
+
// return timeZoneDate.toDate();
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error("Error in timezoneDateParse:", error);
|
|
181
|
+
return new Date();
|
|
182
|
+
}
|
|
128
183
|
};
|
|
129
184
|
exports.timezoneDateParse = timezoneDateParse;
|
|
130
|
-
|
|
131
|
-
if (item
|
|
132
|
-
|
|
133
|
-
var dateFormat1_1 = reverse ? dateFormat : "YYYY-MM-DD";
|
|
134
|
-
var dateFormat2_1 = reverse ? "YYYY-MM-DD" : dateFormat;
|
|
135
|
-
Object.keys(item).forEach(function (fieldName) {
|
|
136
|
-
var _a;
|
|
137
|
-
var field = fields.find(function (field) { return field.fieldName === fieldName; });
|
|
138
|
-
if (field && (field === null || field === void 0 ? void 0 : field.type) === "date") {
|
|
139
|
-
if (((_a = field === null || field === void 0 ? void 0 : field.extraFieldSetting) === null || _a === void 0 ? void 0 : _a.dateDisplayType) === "datetime-local") {
|
|
140
|
-
if (moment(item[fieldName], dateTimeFormat_1).isValid()) {
|
|
141
|
-
item[fieldName] = item[fieldName];
|
|
142
|
-
}
|
|
143
|
-
else
|
|
144
|
-
item[fieldName] = "";
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
if (moment(item[fieldName], dateFormat1_1).isValid()) {
|
|
148
|
-
item[fieldName] = moment(item[fieldName], dateFormat1_1).format(dateFormat2_1);
|
|
149
|
-
}
|
|
150
|
-
else
|
|
151
|
-
item[fieldName] = "";
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
});
|
|
185
|
+
const formatItemDates = (item, fields, dateFormat, reverse) => {
|
|
186
|
+
if (!item || typeof item !== "object") {
|
|
187
|
+
return item;
|
|
155
188
|
}
|
|
189
|
+
const dateTimeFormat = "YYYY-MM-DD";
|
|
190
|
+
const dateFormat1 = reverse ? dateFormat : "YYYY-MM-DD";
|
|
191
|
+
const dateFormat2 = reverse ? "YYYY-MM-DD" : dateFormat;
|
|
192
|
+
Object.keys(item).forEach((fieldName) => {
|
|
193
|
+
const field = fields.find((field) => field.fieldName === fieldName);
|
|
194
|
+
if (field?.type === "date") {
|
|
195
|
+
if (field?.extraFieldSetting?.dateDisplayType === "datetime-local") {
|
|
196
|
+
item[fieldName] = (0, moment_1.default)(item[fieldName], dateTimeFormat).isValid()
|
|
197
|
+
? item[fieldName]
|
|
198
|
+
: "";
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
item[fieldName] = (0, moment_1.default)(item[fieldName], dateFormat1).isValid()
|
|
202
|
+
? (0, moment_1.default)(item[fieldName], dateFormat1).format(dateFormat2)
|
|
203
|
+
: "";
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
156
207
|
return item;
|
|
157
208
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return formatItemDates(item, fields, dateFormat, reverse);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
209
|
+
const formatProjectDates = (item, dateFormat, fields, reverse) => {
|
|
210
|
+
try {
|
|
211
|
+
if (Array.isArray(item)) {
|
|
212
|
+
return item.map((item) => formatItemDates(item, fields, dateFormat, reverse));
|
|
213
|
+
}
|
|
214
|
+
return formatItemDates(item, fields, dateFormat, reverse);
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
console.error("Error in formatProjectDates:", error);
|
|
218
|
+
return item;
|
|
219
|
+
}
|
|
167
220
|
};
|
|
168
221
|
exports.formatProjectDates = formatProjectDates;
|
|
@@ -1,7 +1,52 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface FileContent {
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
}
|
|
4
|
+
export interface PageContent extends FileContent {
|
|
5
|
+
slug: string;
|
|
6
|
+
isDefaultPage?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface WebhookContent extends FileContent {
|
|
9
|
+
uuid: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ExternalApiContent extends FileContent {
|
|
12
|
+
uuid: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CustomComponentContent extends FileContent {
|
|
15
|
+
uuid: string;
|
|
16
|
+
}
|
|
17
|
+
export interface CustomMappingContent extends FileContent {
|
|
18
|
+
uuid: string;
|
|
19
|
+
}
|
|
20
|
+
export interface TaskContent extends FileContent {
|
|
21
|
+
uuid: string;
|
|
22
|
+
}
|
|
23
|
+
export interface EventContent extends FileContent {
|
|
24
|
+
uuid: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SnippetContent extends FileContent {
|
|
27
|
+
uuid: string;
|
|
28
|
+
}
|
|
29
|
+
export interface LocalizationContent extends FileContent {
|
|
30
|
+
language: string;
|
|
31
|
+
isDefault?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface PluginContent extends FileContent {
|
|
34
|
+
code: string;
|
|
35
|
+
}
|
|
36
|
+
export interface DevApiContent extends FileContent {
|
|
37
|
+
uuid: string;
|
|
38
|
+
}
|
|
39
|
+
export interface TemplateContent extends FileContent {
|
|
40
|
+
uuid: string;
|
|
41
|
+
}
|
|
42
|
+
export interface CollectionContent extends FileContent {
|
|
43
|
+
uuid: string;
|
|
44
|
+
collectionName: string;
|
|
45
|
+
}
|
|
46
|
+
export declare const checkFolder: (folderPath: string) => void;
|
|
2
47
|
export declare const verifyProjectSettingFolder: (projectId: string) => boolean;
|
|
3
|
-
export declare const readFile: (filePath: string
|
|
4
|
-
export declare const createFile: (filePath: string
|
|
5
|
-
export declare const loadJsonFilesFromSubfolder: (projectId: string, subfolder: string, excludeFiles?: string[]) =>
|
|
6
|
-
export declare const loadSingleJsonFromSubfolder: (projectId: string, subfolder: string, fileName: string) =>
|
|
7
|
-
export declare const saveEntities: (projectId: string, folderName: string, entities:
|
|
48
|
+
export declare const readFile: (filePath: string) => FileContent | null;
|
|
49
|
+
export declare const createFile: (filePath: string, content: FileContent) => void;
|
|
50
|
+
export declare const loadJsonFilesFromSubfolder: (projectId: string, subfolder: string, excludeFiles?: string[]) => FileContent[];
|
|
51
|
+
export declare const loadSingleJsonFromSubfolder: (projectId: string, subfolder: string, fileName: string) => FileContent | null;
|
|
52
|
+
export declare const saveEntities: <T extends FileContent>(projectId: string, folderName: string, entities: T[], getFileName: (entity: T) => string, handleExtraSave?: (folderPath: string, entity: T) => void) => void;
|
package/build/utils/file-util.js
CHANGED
|
@@ -4,70 +4,68 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.saveEntities = exports.loadSingleJsonFromSubfolder = exports.loadJsonFilesFromSubfolder = exports.createFile = exports.readFile = exports.verifyProjectSettingFolder = exports.checkFolder = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (!
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const filePath = process.env.BUILD_FOLDER || "";
|
|
10
|
+
const checkFolder = (folderPath) => {
|
|
11
|
+
if (!folderPath) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
if (!(0, fs_1.existsSync)(
|
|
14
|
+
if (!(0, fs_1.existsSync)(folderPath)) {
|
|
15
15
|
try {
|
|
16
|
-
(0, fs_1.mkdirSync)(
|
|
16
|
+
(0, fs_1.mkdirSync)(folderPath);
|
|
17
17
|
}
|
|
18
18
|
catch (error) {
|
|
19
|
-
console.error(error);
|
|
19
|
+
console.error("Failed to create folder:", error);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
exports.checkFolder = checkFolder;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const verifyProjectSettingFolder = (projectId) => {
|
|
25
|
+
const projectPath = path_1.default.join(filePath, `project_${projectId}`);
|
|
26
26
|
return (0, fs_1.existsSync)(filePath) && (0, fs_1.existsSync)(projectPath);
|
|
27
27
|
};
|
|
28
28
|
exports.verifyProjectSettingFolder = verifyProjectSettingFolder;
|
|
29
|
-
|
|
29
|
+
const readFile = (filePath) => {
|
|
30
30
|
try {
|
|
31
31
|
if (!(0, fs_1.existsSync)(filePath)) {
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
const content = (0, fs_1.readFileSync)(filePath, "utf8");
|
|
35
35
|
if (!content)
|
|
36
36
|
return null;
|
|
37
37
|
return JSON.parse(content);
|
|
38
38
|
}
|
|
39
39
|
catch (error) {
|
|
40
|
-
console.
|
|
40
|
+
console.error("Failed to read file:", error);
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
exports.readFile = readFile;
|
|
45
|
-
|
|
45
|
+
const createFile = (filePath, content) => {
|
|
46
46
|
try {
|
|
47
|
-
(0, fs_1.writeFileSync)(filePath, JSON.stringify(content));
|
|
47
|
+
(0, fs_1.writeFileSync)(filePath, JSON.stringify(content, null, 2));
|
|
48
48
|
}
|
|
49
49
|
catch (error) {
|
|
50
|
-
console.
|
|
50
|
+
console.error("Failed to create file:", error);
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
exports.createFile = createFile;
|
|
54
|
-
|
|
55
|
-
if (excludeFiles === void 0) { excludeFiles = []; }
|
|
54
|
+
const loadJsonFilesFromSubfolder = (projectId, subfolder, excludeFiles = []) => {
|
|
56
55
|
if (!projectId)
|
|
57
56
|
return [];
|
|
58
|
-
|
|
57
|
+
const isMainExists = (0, exports.verifyProjectSettingFolder)(projectId);
|
|
59
58
|
if (!isMainExists)
|
|
60
59
|
return [];
|
|
61
|
-
|
|
60
|
+
const folderPath = path_1.default.join(filePath, `project_${projectId}`, subfolder);
|
|
62
61
|
if (!(0, fs_1.existsSync)(folderPath))
|
|
63
62
|
return [];
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
for (
|
|
67
|
-
var file = files_1[_i];
|
|
63
|
+
const files = (0, fs_1.readdirSync)(folderPath);
|
|
64
|
+
const result = [];
|
|
65
|
+
for (const file of files) {
|
|
68
66
|
if (!file.endsWith(".json") || excludeFiles.includes(file))
|
|
69
67
|
continue;
|
|
70
|
-
|
|
68
|
+
const json = (0, exports.readFile)(path_1.default.join(folderPath, file));
|
|
71
69
|
if (json) {
|
|
72
70
|
result.push(json);
|
|
73
71
|
}
|
|
@@ -75,43 +73,41 @@ var loadJsonFilesFromSubfolder = function (projectId, subfolder, excludeFiles) {
|
|
|
75
73
|
return result;
|
|
76
74
|
};
|
|
77
75
|
exports.loadJsonFilesFromSubfolder = loadJsonFilesFromSubfolder;
|
|
78
|
-
|
|
76
|
+
const loadSingleJsonFromSubfolder = (projectId, subfolder, fileName) => {
|
|
79
77
|
if (!projectId || !fileName)
|
|
80
78
|
return null;
|
|
81
|
-
|
|
79
|
+
const isMainExists = (0, exports.verifyProjectSettingFolder)(projectId);
|
|
82
80
|
if (!isMainExists)
|
|
83
81
|
return null;
|
|
84
|
-
|
|
82
|
+
const folderPath = path_1.default.join(filePath, `project_${projectId}`, subfolder);
|
|
85
83
|
if (!(0, fs_1.existsSync)(folderPath))
|
|
86
84
|
return null;
|
|
87
|
-
|
|
88
|
-
return (0, exports.readFile)(
|
|
85
|
+
const fullFilePath = path_1.default.join(folderPath, `${fileName}.json`);
|
|
86
|
+
return (0, exports.readFile)(fullFilePath);
|
|
89
87
|
};
|
|
90
88
|
exports.loadSingleJsonFromSubfolder = loadSingleJsonFromSubfolder;
|
|
91
|
-
|
|
89
|
+
const saveEntities = (projectId, folderName, entities, getFileName, handleExtraSave) => {
|
|
92
90
|
if (!projectId || !Array.isArray(entities) || entities.length === 0) {
|
|
93
91
|
return;
|
|
94
92
|
}
|
|
95
93
|
(0, exports.checkFolder)(filePath);
|
|
96
|
-
|
|
94
|
+
const projectFolder = path_1.default.join(filePath, `project_${projectId}`);
|
|
97
95
|
(0, exports.checkFolder)(projectFolder);
|
|
98
|
-
|
|
96
|
+
const targetFolder = path_1.default.join(projectFolder, folderName);
|
|
99
97
|
(0, exports.checkFolder)(targetFolder);
|
|
100
|
-
for (
|
|
101
|
-
|
|
102
|
-
var fileName = getFileName(entity);
|
|
98
|
+
for (const entity of entities) {
|
|
99
|
+
const fileName = getFileName(entity);
|
|
103
100
|
if (!fileName || typeof fileName !== "string")
|
|
104
101
|
continue;
|
|
105
102
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
(0, exports.createFile)(filePath_1, entity);
|
|
103
|
+
const filePath = path_1.default.join(targetFolder, `${fileName}.json`);
|
|
104
|
+
(0, exports.createFile)(filePath, entity);
|
|
109
105
|
if (handleExtraSave) {
|
|
110
106
|
handleExtraSave(targetFolder, entity);
|
|
111
107
|
}
|
|
112
108
|
}
|
|
113
109
|
catch (error) {
|
|
114
|
-
console.error(
|
|
110
|
+
console.error(`Failed to save ${folderName} "${fileName}":`, error);
|
|
115
111
|
}
|
|
116
112
|
}
|
|
117
113
|
};
|