czapp-shared 1.0.5 → 1.0.7
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 +20 -2
- package/dist/index.d.mts +185 -232
- package/dist/index.d.ts +185 -232
- package/dist/index.js +149 -114
- package/dist/index.mjs +144 -113
- package/package.json +4 -4
- package/src/{util.ts → concrete/date.ts} +1 -1
- package/src/concrete/lexeme.ts +32 -0
- package/src/concrete/string.ts +9 -0
- package/src/design/api.ts +94 -0
- package/src/design/lexemes.ts +37 -0
- package/src/{types.ts → design/types.ts} +13 -122
- package/src/{user.ts → design/user.ts} +13 -12
- package/src/index.ts +8 -4
- package/test/String.ts +31 -0
- package/src/lexemes.ts +0 -114
package/dist/index.js
CHANGED
|
@@ -26,7 +26,9 @@ __export(src_exports, {
|
|
|
26
26
|
HttpStatusCode: () => HttpStatusCode,
|
|
27
27
|
Language: () => Language,
|
|
28
28
|
LearningStage: () => LearningStage,
|
|
29
|
+
Lexeme: () => Lexeme,
|
|
29
30
|
LexemePair: () => LexemePair,
|
|
31
|
+
Progress: () => Progress,
|
|
30
32
|
ReminderFrequency: () => ReminderFrequency,
|
|
31
33
|
Scenario: () => Scenario,
|
|
32
34
|
VocabCheckType: () => VocabCheckType,
|
|
@@ -36,19 +38,85 @@ __export(src_exports, {
|
|
|
36
38
|
getClientDate: () => getClientDate,
|
|
37
39
|
getFormattedDate: () => getFormattedDate,
|
|
38
40
|
isClientDateTooFarFromServerDate: () => isClientDateTooFarFromServerDate,
|
|
41
|
+
isStringContainingInteger: () => isStringContainingInteger,
|
|
39
42
|
isThePreviousDay: () => isThePreviousDay,
|
|
40
43
|
isTheSameDay: () => isTheSameDay,
|
|
41
44
|
isValidJsDateString: () => isValidJsDateString,
|
|
42
|
-
isValidMysqlDateString: () => isValidMysqlDateString
|
|
45
|
+
isValidMysqlDateString: () => isValidMysqlDateString,
|
|
46
|
+
parameterReplace: () => parameterReplace
|
|
43
47
|
});
|
|
44
48
|
module.exports = __toCommonJS(src_exports);
|
|
45
49
|
|
|
46
|
-
// src/
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
// src/concrete/date.ts
|
|
51
|
+
var convertJSDateObjectToMySQLDateString = (date) => {
|
|
52
|
+
let dateStr;
|
|
53
|
+
try {
|
|
54
|
+
dateStr = date.toISOString().slice(0, 19).replace("T", " ");
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
if (!isValidMysqlDateString(dateStr)) {
|
|
59
|
+
return void 0;
|
|
60
|
+
} else {
|
|
61
|
+
return dateStr;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var convertJSDateStringToMySQLDate = (date) => {
|
|
65
|
+
let dateStr;
|
|
66
|
+
try {
|
|
67
|
+
dateStr = date.slice(0, 19).replace("T", " ");
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
if (!isValidMysqlDateString(dateStr)) return void 0;
|
|
72
|
+
return dateStr;
|
|
73
|
+
};
|
|
74
|
+
var isValidMysqlDateString = (dateStr) => {
|
|
75
|
+
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(dateStr);
|
|
76
|
+
};
|
|
77
|
+
var isValidJsDateString = (dateStr) => {
|
|
78
|
+
return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(dateStr);
|
|
79
|
+
};
|
|
80
|
+
var isClientDateTooFarFromServerDate = (clientDateMySQLFormat, serverDate) => {
|
|
81
|
+
const serverDateMysqlFormat = convertJSDateObjectToMySQLDateString(serverDate);
|
|
82
|
+
if (!serverDateMysqlFormat) return true;
|
|
83
|
+
return Math.abs(dateDifferenceInDays(clientDateMySQLFormat, serverDateMysqlFormat)) > 1;
|
|
84
|
+
};
|
|
85
|
+
var dateDifferenceInDays = (date1, date2) => {
|
|
86
|
+
const dateObj_1 = new Date(date1);
|
|
87
|
+
const dateObj_2 = new Date(date2);
|
|
88
|
+
dateObj_1.setHours(0, 0, 0, 0);
|
|
89
|
+
dateObj_2.setHours(0, 0, 0, 0);
|
|
90
|
+
const difference = dateObj_2.getTime() - dateObj_1.getTime();
|
|
91
|
+
return difference / (1e3 * 3600 * 24);
|
|
92
|
+
};
|
|
93
|
+
var getClientDate = (date) => {
|
|
94
|
+
return `${date.getFullYear()}-${zeroPad(date.getMonth() + 1)}-${zeroPad(date.getDate())} ${zeroPad(date.getHours())}:${zeroPad(date.getMinutes())}:${zeroPad(date.getSeconds())}`;
|
|
95
|
+
};
|
|
96
|
+
var zeroPad = (num) => {
|
|
97
|
+
return num < 10 ? `0${num}` : num.toString();
|
|
98
|
+
};
|
|
99
|
+
var isThePreviousDay = (date, referenceDate) => {
|
|
100
|
+
const previousDay = new Date(referenceDate);
|
|
101
|
+
previousDay.setDate(new Date(referenceDate).getDate() - 1);
|
|
102
|
+
return new Date(date).toDateString() === previousDay.toDateString();
|
|
103
|
+
};
|
|
104
|
+
var isTheSameDay = (date1, date2) => {
|
|
105
|
+
return new Date(date1).toDateString() === new Date(date2).toDateString();
|
|
106
|
+
};
|
|
107
|
+
var getFormattedDate = (date) => {
|
|
108
|
+
const year = date.getFullYear();
|
|
109
|
+
const month = (1 + date.getMonth()).toString().padStart(2, "0");
|
|
110
|
+
const day = date.getDate().toString().padStart(2, "0");
|
|
111
|
+
return `${year}-${month}-${day}`;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/design/types.ts
|
|
115
|
+
var Language = /* @__PURE__ */ ((Language2) => {
|
|
116
|
+
Language2["CZECH"] = "cz";
|
|
117
|
+
Language2["ENGLISH"] = "en";
|
|
118
|
+
Language2["UNKNOWN"] = "UNKNOWN";
|
|
119
|
+
return Language2;
|
|
52
120
|
})(Language || {});
|
|
53
121
|
var Familiarity = /* @__PURE__ */ ((Familiarity2) => {
|
|
54
122
|
Familiarity2["KNOWN"] = "KNOWN";
|
|
@@ -61,46 +129,24 @@ var VocabCheckType = /* @__PURE__ */ ((VocabCheckType2) => {
|
|
|
61
129
|
VocabCheckType2["TEST"] = "test";
|
|
62
130
|
return VocabCheckType2;
|
|
63
131
|
})(VocabCheckType || {});
|
|
64
|
-
var LearningStage = /* @__PURE__ */ ((
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return
|
|
132
|
+
var LearningStage = /* @__PURE__ */ ((LearningStage2) => {
|
|
133
|
+
LearningStage2["NEW"] = "NEW";
|
|
134
|
+
LearningStage2["LEARNING"] = "LEARNING";
|
|
135
|
+
LearningStage2["RETIRED"] = "RETIRED";
|
|
136
|
+
return LearningStage2;
|
|
69
137
|
})(LearningStage || {});
|
|
138
|
+
var Progress = /* @__PURE__ */ ((Progress2) => {
|
|
139
|
+
Progress2[Progress2["WORSE"] = 0] = "WORSE";
|
|
140
|
+
Progress2[Progress2["NONE"] = 1] = "NONE";
|
|
141
|
+
Progress2[Progress2["IMPROVED"] = 2] = "IMPROVED";
|
|
142
|
+
return Progress2;
|
|
143
|
+
})(Progress || {});
|
|
70
144
|
var ReminderFrequency = /* @__PURE__ */ ((ReminderFrequency2) => {
|
|
71
145
|
ReminderFrequency2["ALWAYS"] = "always";
|
|
72
146
|
ReminderFrequency2["DAILY"] = "daily";
|
|
73
147
|
ReminderFrequency2["NEVER"] = "never";
|
|
74
148
|
return ReminderFrequency2;
|
|
75
149
|
})(ReminderFrequency || {});
|
|
76
|
-
var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
|
|
77
|
-
ApiPath2["AUTOLOGIN"] = "/autologin";
|
|
78
|
-
ApiPath2["HEALTH"] = "/health";
|
|
79
|
-
ApiPath2["LEXEMES"] = "/lexemes";
|
|
80
|
-
ApiPath2["LEXEMES_ALL"] = "/lexemes/all";
|
|
81
|
-
ApiPath2["LEXEMES_COUNT"] = "/lexemes/count/:language";
|
|
82
|
-
ApiPath2["LEXEMES_DELETE_ALL"] = "/lexemes/deleteAll";
|
|
83
|
-
ApiPath2["LEXEMES_PAGE"] = "/lexemes/:length/:page";
|
|
84
|
-
ApiPath2["LEXEME_PAIR"] = "/lexemePair/:czId/:enId";
|
|
85
|
-
ApiPath2["LEXEME_PAIRS_BY_TEXT"] = "/lexemePairsByText/:inputText/:inputLang";
|
|
86
|
-
ApiPath2["LEXEME_PAIR_FAMILIARITY"] = "/lexemePair/:czId/:enId/:familiarity";
|
|
87
|
-
ApiPath2["SIGN_IN"] = "/signIn";
|
|
88
|
-
ApiPath2["SIGN_OUT"] = "/signOut";
|
|
89
|
-
ApiPath2["TEST_COMPLETE"] = "/test/complete";
|
|
90
|
-
ApiPath2["TEST_INIT"] = "/test/init";
|
|
91
|
-
ApiPath2["TRANSLATE"] = "/translate";
|
|
92
|
-
ApiPath2["TRANSLATIONS_ALL"] = "/lexemes/allTranslations/:sourceText/:sourceLang";
|
|
93
|
-
ApiPath2["USER"] = "/user";
|
|
94
|
-
ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked";
|
|
95
|
-
return ApiPath2;
|
|
96
|
-
})(ApiPath || {});
|
|
97
|
-
var ApiMethod = /* @__PURE__ */ ((ApiMethod2) => {
|
|
98
|
-
ApiMethod2["GET"] = "GET";
|
|
99
|
-
ApiMethod2["POST"] = "POST";
|
|
100
|
-
ApiMethod2["PUT"] = "PUT";
|
|
101
|
-
ApiMethod2["DELETE"] = "DELETE";
|
|
102
|
-
return ApiMethod2;
|
|
103
|
-
})(ApiMethod || {});
|
|
104
150
|
var AppError = /* @__PURE__ */ ((AppError2) => {
|
|
105
151
|
AppError2["NONE"] = "No error";
|
|
106
152
|
AppError2["REQUEST_AUTOLOGIN_FAILED"] = "Failed to auto-login";
|
|
@@ -117,16 +163,6 @@ var AppError = /* @__PURE__ */ ((AppError2) => {
|
|
|
117
163
|
AppError2["REQUEST_TEST_COMPLETE_FAILED"] = "Failed to complete test";
|
|
118
164
|
return AppError2;
|
|
119
165
|
})(AppError || {});
|
|
120
|
-
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
121
|
-
HttpStatusCode2[HttpStatusCode2["OK"] = 200] = "OK";
|
|
122
|
-
HttpStatusCode2[HttpStatusCode2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
123
|
-
HttpStatusCode2[HttpStatusCode2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
124
|
-
HttpStatusCode2[HttpStatusCode2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
125
|
-
HttpStatusCode2[HttpStatusCode2["TIMEOUT"] = 408] = "TIMEOUT";
|
|
126
|
-
HttpStatusCode2[HttpStatusCode2["ABORTED"] = 409] = "ABORTED";
|
|
127
|
-
HttpStatusCode2[HttpStatusCode2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
128
|
-
return HttpStatusCode2;
|
|
129
|
-
})(HttpStatusCode || {});
|
|
130
166
|
var Scenario = /* @__PURE__ */ ((Scenario2) => {
|
|
131
167
|
Scenario2["S1_INSERT_HAPPY_PATH"] = "Insert, happy path";
|
|
132
168
|
Scenario2["S2_INSERT_ENGLISH_LEXEME_AND_MAPPING_DUPLICATE_CZECH_LEXEME_FOUND_AND_USED"] = "Insert English lexeme and mapping, duplicate Czech lexeme found and used";
|
|
@@ -150,80 +186,75 @@ var Scenario = /* @__PURE__ */ ((Scenario2) => {
|
|
|
150
186
|
return Scenario2;
|
|
151
187
|
})(Scenario || {});
|
|
152
188
|
|
|
153
|
-
// src/
|
|
189
|
+
// src/concrete/lexeme.ts
|
|
190
|
+
var Lexeme = class {
|
|
191
|
+
constructor() {
|
|
192
|
+
this.text = "";
|
|
193
|
+
this.id = void 0;
|
|
194
|
+
this.userId = "";
|
|
195
|
+
this.dateAdded = convertJSDateObjectToMySQLDateString(/* @__PURE__ */ new Date());
|
|
196
|
+
}
|
|
197
|
+
};
|
|
154
198
|
var LexemePair = class {
|
|
155
199
|
constructor(englishLexeme, czechLexeme) {
|
|
200
|
+
this.familiarity = "UNKNOWN" /* UNKNOWN */;
|
|
201
|
+
this.learningStage = "NEW" /* NEW */;
|
|
156
202
|
this.notes = "";
|
|
157
203
|
this.userId = "";
|
|
158
204
|
this.czechLexeme = czechLexeme;
|
|
159
205
|
this.englishLexeme = englishLexeme;
|
|
160
|
-
this.familiarity = "UNKNOWN" /* UNKNOWN */;
|
|
161
206
|
}
|
|
162
207
|
};
|
|
163
208
|
|
|
164
|
-
// src/
|
|
165
|
-
var
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
} catch (error) {
|
|
170
|
-
return void 0;
|
|
171
|
-
}
|
|
172
|
-
if (!isValidMysqlDateString(dateStr)) {
|
|
173
|
-
return void 0;
|
|
174
|
-
} else {
|
|
175
|
-
return dateStr;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
var convertJSDateStringToMySQLDate = (date) => {
|
|
179
|
-
let dateStr;
|
|
180
|
-
try {
|
|
181
|
-
dateStr = date.slice(0, 19).replace("T", " ");
|
|
182
|
-
} catch (error) {
|
|
183
|
-
return void 0;
|
|
184
|
-
}
|
|
185
|
-
if (!isValidMysqlDateString(dateStr)) return void 0;
|
|
186
|
-
return dateStr;
|
|
187
|
-
};
|
|
188
|
-
var isValidMysqlDateString = (dateStr) => {
|
|
189
|
-
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(dateStr);
|
|
190
|
-
};
|
|
191
|
-
var isValidJsDateString = (dateStr) => {
|
|
192
|
-
return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(dateStr);
|
|
193
|
-
};
|
|
194
|
-
var isClientDateTooFarFromServerDate = (clientDateMySQLFormat, serverDate) => {
|
|
195
|
-
const serverDateMysqlFormat = convertJSDateObjectToMySQLDateString(serverDate);
|
|
196
|
-
if (!serverDateMysqlFormat) return true;
|
|
197
|
-
return Math.abs(dateDifferenceInDays(clientDateMySQLFormat, serverDateMysqlFormat)) > 1;
|
|
198
|
-
};
|
|
199
|
-
var dateDifferenceInDays = (date1, date2) => {
|
|
200
|
-
const dateObj_1 = new Date(date1);
|
|
201
|
-
const dateObj_2 = new Date(date2);
|
|
202
|
-
dateObj_1.setHours(0, 0, 0, 0);
|
|
203
|
-
dateObj_2.setHours(0, 0, 0, 0);
|
|
204
|
-
const difference = dateObj_2.getTime() - dateObj_1.getTime();
|
|
205
|
-
return difference / (1e3 * 3600 * 24);
|
|
206
|
-
};
|
|
207
|
-
var getClientDate = (date) => {
|
|
208
|
-
return `${date.getFullYear()}-${zeroPad(date.getMonth() + 1)}-${zeroPad(date.getDate())} ${zeroPad(date.getHours())}:${zeroPad(date.getMinutes())}:${zeroPad(date.getSeconds())}`;
|
|
209
|
-
};
|
|
210
|
-
var zeroPad = (num) => {
|
|
211
|
-
return num < 10 ? `0${num}` : num.toString();
|
|
212
|
-
};
|
|
213
|
-
var isThePreviousDay = (date, referenceDate) => {
|
|
214
|
-
const previousDay = new Date(referenceDate);
|
|
215
|
-
previousDay.setDate(new Date(referenceDate).getDate() - 1);
|
|
216
|
-
return new Date(date).toDateString() === previousDay.toDateString();
|
|
209
|
+
// src/concrete/string.ts
|
|
210
|
+
var isStringContainingInteger = (str) => {
|
|
211
|
+
if (typeof str !== "string") return false;
|
|
212
|
+
const regex = /^\d+$/;
|
|
213
|
+
return regex.test(str);
|
|
217
214
|
};
|
|
218
|
-
var
|
|
219
|
-
return
|
|
220
|
-
};
|
|
221
|
-
var getFormattedDate = (date) => {
|
|
222
|
-
const year = date.getFullYear();
|
|
223
|
-
const month = (1 + date.getMonth()).toString().padStart(2, "0");
|
|
224
|
-
const day = date.getDate().toString().padStart(2, "0");
|
|
225
|
-
return `${year}-${month}-${day}`;
|
|
215
|
+
var parameterReplace = (path, params = []) => {
|
|
216
|
+
return path.replace(/\:([a-zA-Z0-9]+)/g, (match, p1) => params.shift() || "");
|
|
226
217
|
};
|
|
218
|
+
|
|
219
|
+
// src/design/api.ts
|
|
220
|
+
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
221
|
+
HttpStatusCode2[HttpStatusCode2["OK"] = 200] = "OK";
|
|
222
|
+
HttpStatusCode2[HttpStatusCode2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
223
|
+
HttpStatusCode2[HttpStatusCode2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
224
|
+
HttpStatusCode2[HttpStatusCode2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
225
|
+
HttpStatusCode2[HttpStatusCode2["TIMEOUT"] = 408] = "TIMEOUT";
|
|
226
|
+
HttpStatusCode2[HttpStatusCode2["ABORTED"] = 409] = "ABORTED";
|
|
227
|
+
HttpStatusCode2[HttpStatusCode2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
228
|
+
return HttpStatusCode2;
|
|
229
|
+
})(HttpStatusCode || {});
|
|
230
|
+
var ApiMethod = /* @__PURE__ */ ((ApiMethod2) => {
|
|
231
|
+
ApiMethod2["GET"] = "GET";
|
|
232
|
+
ApiMethod2["POST"] = "POST";
|
|
233
|
+
ApiMethod2["PUT"] = "PUT";
|
|
234
|
+
ApiMethod2["DELETE"] = "DELETE";
|
|
235
|
+
return ApiMethod2;
|
|
236
|
+
})(ApiMethod || {});
|
|
237
|
+
var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
|
|
238
|
+
ApiPath2["AUTOLOGIN"] = "/autologin";
|
|
239
|
+
ApiPath2["HEALTH"] = "/health";
|
|
240
|
+
ApiPath2["LEXEMES"] = "/lexemes";
|
|
241
|
+
ApiPath2["LEXEMES_ALL"] = "/lexemes/all";
|
|
242
|
+
ApiPath2["LEXEMES_COUNT"] = "/lexemes/count/:language";
|
|
243
|
+
ApiPath2["LEXEMES_DELETE_ALL"] = "/lexemes/deleteAll";
|
|
244
|
+
ApiPath2["LEXEMES_PAGE"] = "/lexemes/:length/:page";
|
|
245
|
+
ApiPath2["LEXEME_PAIR"] = "/lexemePair/:czId/:enId";
|
|
246
|
+
ApiPath2["LEXEME_PAIRS_BY_TEXT"] = "/lexemePairsByText/:inputText/:inputLang";
|
|
247
|
+
ApiPath2["LEXEME_PAIR_FAMILIARITY"] = "/lexemePair/:czId/:enId/:familiarity";
|
|
248
|
+
ApiPath2["SIGN_IN"] = "/signIn";
|
|
249
|
+
ApiPath2["SIGN_OUT"] = "/signOut";
|
|
250
|
+
ApiPath2["TEST_COMPLETE"] = "/test/complete";
|
|
251
|
+
ApiPath2["TEST_INIT"] = "/test/init";
|
|
252
|
+
ApiPath2["TRANSLATE"] = "/translate";
|
|
253
|
+
ApiPath2["TRANSLATIONS_ALL"] = "/lexemes/allTranslations/:sourceText/:sourceLang";
|
|
254
|
+
ApiPath2["USER"] = "/user";
|
|
255
|
+
ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked";
|
|
256
|
+
return ApiPath2;
|
|
257
|
+
})(ApiPath || {});
|
|
227
258
|
// Annotate the CommonJS export names for ESM import in node:
|
|
228
259
|
0 && (module.exports = {
|
|
229
260
|
ApiMethod,
|
|
@@ -233,7 +264,9 @@ var getFormattedDate = (date) => {
|
|
|
233
264
|
HttpStatusCode,
|
|
234
265
|
Language,
|
|
235
266
|
LearningStage,
|
|
267
|
+
Lexeme,
|
|
236
268
|
LexemePair,
|
|
269
|
+
Progress,
|
|
237
270
|
ReminderFrequency,
|
|
238
271
|
Scenario,
|
|
239
272
|
VocabCheckType,
|
|
@@ -243,8 +276,10 @@ var getFormattedDate = (date) => {
|
|
|
243
276
|
getClientDate,
|
|
244
277
|
getFormattedDate,
|
|
245
278
|
isClientDateTooFarFromServerDate,
|
|
279
|
+
isStringContainingInteger,
|
|
246
280
|
isThePreviousDay,
|
|
247
281
|
isTheSameDay,
|
|
248
282
|
isValidJsDateString,
|
|
249
|
-
isValidMysqlDateString
|
|
283
|
+
isValidMysqlDateString,
|
|
284
|
+
parameterReplace
|
|
250
285
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,73 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
// src/concrete/date.ts
|
|
2
|
+
var convertJSDateObjectToMySQLDateString = (date) => {
|
|
3
|
+
let dateStr;
|
|
4
|
+
try {
|
|
5
|
+
dateStr = date.toISOString().slice(0, 19).replace("T", " ");
|
|
6
|
+
} catch (error) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
if (!isValidMysqlDateString(dateStr)) {
|
|
10
|
+
return void 0;
|
|
11
|
+
} else {
|
|
12
|
+
return dateStr;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var convertJSDateStringToMySQLDate = (date) => {
|
|
16
|
+
let dateStr;
|
|
17
|
+
try {
|
|
18
|
+
dateStr = date.slice(0, 19).replace("T", " ");
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
if (!isValidMysqlDateString(dateStr)) return void 0;
|
|
23
|
+
return dateStr;
|
|
24
|
+
};
|
|
25
|
+
var isValidMysqlDateString = (dateStr) => {
|
|
26
|
+
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(dateStr);
|
|
27
|
+
};
|
|
28
|
+
var isValidJsDateString = (dateStr) => {
|
|
29
|
+
return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(dateStr);
|
|
30
|
+
};
|
|
31
|
+
var isClientDateTooFarFromServerDate = (clientDateMySQLFormat, serverDate) => {
|
|
32
|
+
const serverDateMysqlFormat = convertJSDateObjectToMySQLDateString(serverDate);
|
|
33
|
+
if (!serverDateMysqlFormat) return true;
|
|
34
|
+
return Math.abs(dateDifferenceInDays(clientDateMySQLFormat, serverDateMysqlFormat)) > 1;
|
|
35
|
+
};
|
|
36
|
+
var dateDifferenceInDays = (date1, date2) => {
|
|
37
|
+
const dateObj_1 = new Date(date1);
|
|
38
|
+
const dateObj_2 = new Date(date2);
|
|
39
|
+
dateObj_1.setHours(0, 0, 0, 0);
|
|
40
|
+
dateObj_2.setHours(0, 0, 0, 0);
|
|
41
|
+
const difference = dateObj_2.getTime() - dateObj_1.getTime();
|
|
42
|
+
return difference / (1e3 * 3600 * 24);
|
|
43
|
+
};
|
|
44
|
+
var getClientDate = (date) => {
|
|
45
|
+
return `${date.getFullYear()}-${zeroPad(date.getMonth() + 1)}-${zeroPad(date.getDate())} ${zeroPad(date.getHours())}:${zeroPad(date.getMinutes())}:${zeroPad(date.getSeconds())}`;
|
|
46
|
+
};
|
|
47
|
+
var zeroPad = (num) => {
|
|
48
|
+
return num < 10 ? `0${num}` : num.toString();
|
|
49
|
+
};
|
|
50
|
+
var isThePreviousDay = (date, referenceDate) => {
|
|
51
|
+
const previousDay = new Date(referenceDate);
|
|
52
|
+
previousDay.setDate(new Date(referenceDate).getDate() - 1);
|
|
53
|
+
return new Date(date).toDateString() === previousDay.toDateString();
|
|
54
|
+
};
|
|
55
|
+
var isTheSameDay = (date1, date2) => {
|
|
56
|
+
return new Date(date1).toDateString() === new Date(date2).toDateString();
|
|
57
|
+
};
|
|
58
|
+
var getFormattedDate = (date) => {
|
|
59
|
+
const year = date.getFullYear();
|
|
60
|
+
const month = (1 + date.getMonth()).toString().padStart(2, "0");
|
|
61
|
+
const day = date.getDate().toString().padStart(2, "0");
|
|
62
|
+
return `${year}-${month}-${day}`;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/design/types.ts
|
|
66
|
+
var Language = /* @__PURE__ */ ((Language2) => {
|
|
67
|
+
Language2["CZECH"] = "cz";
|
|
68
|
+
Language2["ENGLISH"] = "en";
|
|
69
|
+
Language2["UNKNOWN"] = "UNKNOWN";
|
|
70
|
+
return Language2;
|
|
7
71
|
})(Language || {});
|
|
8
72
|
var Familiarity = /* @__PURE__ */ ((Familiarity2) => {
|
|
9
73
|
Familiarity2["KNOWN"] = "KNOWN";
|
|
@@ -16,46 +80,24 @@ var VocabCheckType = /* @__PURE__ */ ((VocabCheckType2) => {
|
|
|
16
80
|
VocabCheckType2["TEST"] = "test";
|
|
17
81
|
return VocabCheckType2;
|
|
18
82
|
})(VocabCheckType || {});
|
|
19
|
-
var LearningStage = /* @__PURE__ */ ((
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
83
|
+
var LearningStage = /* @__PURE__ */ ((LearningStage2) => {
|
|
84
|
+
LearningStage2["NEW"] = "NEW";
|
|
85
|
+
LearningStage2["LEARNING"] = "LEARNING";
|
|
86
|
+
LearningStage2["RETIRED"] = "RETIRED";
|
|
87
|
+
return LearningStage2;
|
|
24
88
|
})(LearningStage || {});
|
|
89
|
+
var Progress = /* @__PURE__ */ ((Progress2) => {
|
|
90
|
+
Progress2[Progress2["WORSE"] = 0] = "WORSE";
|
|
91
|
+
Progress2[Progress2["NONE"] = 1] = "NONE";
|
|
92
|
+
Progress2[Progress2["IMPROVED"] = 2] = "IMPROVED";
|
|
93
|
+
return Progress2;
|
|
94
|
+
})(Progress || {});
|
|
25
95
|
var ReminderFrequency = /* @__PURE__ */ ((ReminderFrequency2) => {
|
|
26
96
|
ReminderFrequency2["ALWAYS"] = "always";
|
|
27
97
|
ReminderFrequency2["DAILY"] = "daily";
|
|
28
98
|
ReminderFrequency2["NEVER"] = "never";
|
|
29
99
|
return ReminderFrequency2;
|
|
30
100
|
})(ReminderFrequency || {});
|
|
31
|
-
var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
|
|
32
|
-
ApiPath2["AUTOLOGIN"] = "/autologin";
|
|
33
|
-
ApiPath2["HEALTH"] = "/health";
|
|
34
|
-
ApiPath2["LEXEMES"] = "/lexemes";
|
|
35
|
-
ApiPath2["LEXEMES_ALL"] = "/lexemes/all";
|
|
36
|
-
ApiPath2["LEXEMES_COUNT"] = "/lexemes/count/:language";
|
|
37
|
-
ApiPath2["LEXEMES_DELETE_ALL"] = "/lexemes/deleteAll";
|
|
38
|
-
ApiPath2["LEXEMES_PAGE"] = "/lexemes/:length/:page";
|
|
39
|
-
ApiPath2["LEXEME_PAIR"] = "/lexemePair/:czId/:enId";
|
|
40
|
-
ApiPath2["LEXEME_PAIRS_BY_TEXT"] = "/lexemePairsByText/:inputText/:inputLang";
|
|
41
|
-
ApiPath2["LEXEME_PAIR_FAMILIARITY"] = "/lexemePair/:czId/:enId/:familiarity";
|
|
42
|
-
ApiPath2["SIGN_IN"] = "/signIn";
|
|
43
|
-
ApiPath2["SIGN_OUT"] = "/signOut";
|
|
44
|
-
ApiPath2["TEST_COMPLETE"] = "/test/complete";
|
|
45
|
-
ApiPath2["TEST_INIT"] = "/test/init";
|
|
46
|
-
ApiPath2["TRANSLATE"] = "/translate";
|
|
47
|
-
ApiPath2["TRANSLATIONS_ALL"] = "/lexemes/allTranslations/:sourceText/:sourceLang";
|
|
48
|
-
ApiPath2["USER"] = "/user";
|
|
49
|
-
ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked";
|
|
50
|
-
return ApiPath2;
|
|
51
|
-
})(ApiPath || {});
|
|
52
|
-
var ApiMethod = /* @__PURE__ */ ((ApiMethod2) => {
|
|
53
|
-
ApiMethod2["GET"] = "GET";
|
|
54
|
-
ApiMethod2["POST"] = "POST";
|
|
55
|
-
ApiMethod2["PUT"] = "PUT";
|
|
56
|
-
ApiMethod2["DELETE"] = "DELETE";
|
|
57
|
-
return ApiMethod2;
|
|
58
|
-
})(ApiMethod || {});
|
|
59
101
|
var AppError = /* @__PURE__ */ ((AppError2) => {
|
|
60
102
|
AppError2["NONE"] = "No error";
|
|
61
103
|
AppError2["REQUEST_AUTOLOGIN_FAILED"] = "Failed to auto-login";
|
|
@@ -72,16 +114,6 @@ var AppError = /* @__PURE__ */ ((AppError2) => {
|
|
|
72
114
|
AppError2["REQUEST_TEST_COMPLETE_FAILED"] = "Failed to complete test";
|
|
73
115
|
return AppError2;
|
|
74
116
|
})(AppError || {});
|
|
75
|
-
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
76
|
-
HttpStatusCode2[HttpStatusCode2["OK"] = 200] = "OK";
|
|
77
|
-
HttpStatusCode2[HttpStatusCode2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
78
|
-
HttpStatusCode2[HttpStatusCode2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
79
|
-
HttpStatusCode2[HttpStatusCode2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
80
|
-
HttpStatusCode2[HttpStatusCode2["TIMEOUT"] = 408] = "TIMEOUT";
|
|
81
|
-
HttpStatusCode2[HttpStatusCode2["ABORTED"] = 409] = "ABORTED";
|
|
82
|
-
HttpStatusCode2[HttpStatusCode2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
83
|
-
return HttpStatusCode2;
|
|
84
|
-
})(HttpStatusCode || {});
|
|
85
117
|
var Scenario = /* @__PURE__ */ ((Scenario2) => {
|
|
86
118
|
Scenario2["S1_INSERT_HAPPY_PATH"] = "Insert, happy path";
|
|
87
119
|
Scenario2["S2_INSERT_ENGLISH_LEXEME_AND_MAPPING_DUPLICATE_CZECH_LEXEME_FOUND_AND_USED"] = "Insert English lexeme and mapping, duplicate Czech lexeme found and used";
|
|
@@ -105,80 +137,75 @@ var Scenario = /* @__PURE__ */ ((Scenario2) => {
|
|
|
105
137
|
return Scenario2;
|
|
106
138
|
})(Scenario || {});
|
|
107
139
|
|
|
108
|
-
// src/
|
|
140
|
+
// src/concrete/lexeme.ts
|
|
141
|
+
var Lexeme = class {
|
|
142
|
+
constructor() {
|
|
143
|
+
this.text = "";
|
|
144
|
+
this.id = void 0;
|
|
145
|
+
this.userId = "";
|
|
146
|
+
this.dateAdded = convertJSDateObjectToMySQLDateString(/* @__PURE__ */ new Date());
|
|
147
|
+
}
|
|
148
|
+
};
|
|
109
149
|
var LexemePair = class {
|
|
110
150
|
constructor(englishLexeme, czechLexeme) {
|
|
151
|
+
this.familiarity = "UNKNOWN" /* UNKNOWN */;
|
|
152
|
+
this.learningStage = "NEW" /* NEW */;
|
|
111
153
|
this.notes = "";
|
|
112
154
|
this.userId = "";
|
|
113
155
|
this.czechLexeme = czechLexeme;
|
|
114
156
|
this.englishLexeme = englishLexeme;
|
|
115
|
-
this.familiarity = "UNKNOWN" /* UNKNOWN */;
|
|
116
157
|
}
|
|
117
158
|
};
|
|
118
159
|
|
|
119
|
-
// src/
|
|
120
|
-
var
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
} catch (error) {
|
|
125
|
-
return void 0;
|
|
126
|
-
}
|
|
127
|
-
if (!isValidMysqlDateString(dateStr)) {
|
|
128
|
-
return void 0;
|
|
129
|
-
} else {
|
|
130
|
-
return dateStr;
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var convertJSDateStringToMySQLDate = (date) => {
|
|
134
|
-
let dateStr;
|
|
135
|
-
try {
|
|
136
|
-
dateStr = date.slice(0, 19).replace("T", " ");
|
|
137
|
-
} catch (error) {
|
|
138
|
-
return void 0;
|
|
139
|
-
}
|
|
140
|
-
if (!isValidMysqlDateString(dateStr)) return void 0;
|
|
141
|
-
return dateStr;
|
|
142
|
-
};
|
|
143
|
-
var isValidMysqlDateString = (dateStr) => {
|
|
144
|
-
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(dateStr);
|
|
145
|
-
};
|
|
146
|
-
var isValidJsDateString = (dateStr) => {
|
|
147
|
-
return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(dateStr);
|
|
148
|
-
};
|
|
149
|
-
var isClientDateTooFarFromServerDate = (clientDateMySQLFormat, serverDate) => {
|
|
150
|
-
const serverDateMysqlFormat = convertJSDateObjectToMySQLDateString(serverDate);
|
|
151
|
-
if (!serverDateMysqlFormat) return true;
|
|
152
|
-
return Math.abs(dateDifferenceInDays(clientDateMySQLFormat, serverDateMysqlFormat)) > 1;
|
|
153
|
-
};
|
|
154
|
-
var dateDifferenceInDays = (date1, date2) => {
|
|
155
|
-
const dateObj_1 = new Date(date1);
|
|
156
|
-
const dateObj_2 = new Date(date2);
|
|
157
|
-
dateObj_1.setHours(0, 0, 0, 0);
|
|
158
|
-
dateObj_2.setHours(0, 0, 0, 0);
|
|
159
|
-
const difference = dateObj_2.getTime() - dateObj_1.getTime();
|
|
160
|
-
return difference / (1e3 * 3600 * 24);
|
|
161
|
-
};
|
|
162
|
-
var getClientDate = (date) => {
|
|
163
|
-
return `${date.getFullYear()}-${zeroPad(date.getMonth() + 1)}-${zeroPad(date.getDate())} ${zeroPad(date.getHours())}:${zeroPad(date.getMinutes())}:${zeroPad(date.getSeconds())}`;
|
|
164
|
-
};
|
|
165
|
-
var zeroPad = (num) => {
|
|
166
|
-
return num < 10 ? `0${num}` : num.toString();
|
|
167
|
-
};
|
|
168
|
-
var isThePreviousDay = (date, referenceDate) => {
|
|
169
|
-
const previousDay = new Date(referenceDate);
|
|
170
|
-
previousDay.setDate(new Date(referenceDate).getDate() - 1);
|
|
171
|
-
return new Date(date).toDateString() === previousDay.toDateString();
|
|
160
|
+
// src/concrete/string.ts
|
|
161
|
+
var isStringContainingInteger = (str) => {
|
|
162
|
+
if (typeof str !== "string") return false;
|
|
163
|
+
const regex = /^\d+$/;
|
|
164
|
+
return regex.test(str);
|
|
172
165
|
};
|
|
173
|
-
var
|
|
174
|
-
return
|
|
175
|
-
};
|
|
176
|
-
var getFormattedDate = (date) => {
|
|
177
|
-
const year = date.getFullYear();
|
|
178
|
-
const month = (1 + date.getMonth()).toString().padStart(2, "0");
|
|
179
|
-
const day = date.getDate().toString().padStart(2, "0");
|
|
180
|
-
return `${year}-${month}-${day}`;
|
|
166
|
+
var parameterReplace = (path, params = []) => {
|
|
167
|
+
return path.replace(/\:([a-zA-Z0-9]+)/g, (match, p1) => params.shift() || "");
|
|
181
168
|
};
|
|
169
|
+
|
|
170
|
+
// src/design/api.ts
|
|
171
|
+
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
172
|
+
HttpStatusCode2[HttpStatusCode2["OK"] = 200] = "OK";
|
|
173
|
+
HttpStatusCode2[HttpStatusCode2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
174
|
+
HttpStatusCode2[HttpStatusCode2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
175
|
+
HttpStatusCode2[HttpStatusCode2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
176
|
+
HttpStatusCode2[HttpStatusCode2["TIMEOUT"] = 408] = "TIMEOUT";
|
|
177
|
+
HttpStatusCode2[HttpStatusCode2["ABORTED"] = 409] = "ABORTED";
|
|
178
|
+
HttpStatusCode2[HttpStatusCode2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
179
|
+
return HttpStatusCode2;
|
|
180
|
+
})(HttpStatusCode || {});
|
|
181
|
+
var ApiMethod = /* @__PURE__ */ ((ApiMethod2) => {
|
|
182
|
+
ApiMethod2["GET"] = "GET";
|
|
183
|
+
ApiMethod2["POST"] = "POST";
|
|
184
|
+
ApiMethod2["PUT"] = "PUT";
|
|
185
|
+
ApiMethod2["DELETE"] = "DELETE";
|
|
186
|
+
return ApiMethod2;
|
|
187
|
+
})(ApiMethod || {});
|
|
188
|
+
var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
|
|
189
|
+
ApiPath2["AUTOLOGIN"] = "/autologin";
|
|
190
|
+
ApiPath2["HEALTH"] = "/health";
|
|
191
|
+
ApiPath2["LEXEMES"] = "/lexemes";
|
|
192
|
+
ApiPath2["LEXEMES_ALL"] = "/lexemes/all";
|
|
193
|
+
ApiPath2["LEXEMES_COUNT"] = "/lexemes/count/:language";
|
|
194
|
+
ApiPath2["LEXEMES_DELETE_ALL"] = "/lexemes/deleteAll";
|
|
195
|
+
ApiPath2["LEXEMES_PAGE"] = "/lexemes/:length/:page";
|
|
196
|
+
ApiPath2["LEXEME_PAIR"] = "/lexemePair/:czId/:enId";
|
|
197
|
+
ApiPath2["LEXEME_PAIRS_BY_TEXT"] = "/lexemePairsByText/:inputText/:inputLang";
|
|
198
|
+
ApiPath2["LEXEME_PAIR_FAMILIARITY"] = "/lexemePair/:czId/:enId/:familiarity";
|
|
199
|
+
ApiPath2["SIGN_IN"] = "/signIn";
|
|
200
|
+
ApiPath2["SIGN_OUT"] = "/signOut";
|
|
201
|
+
ApiPath2["TEST_COMPLETE"] = "/test/complete";
|
|
202
|
+
ApiPath2["TEST_INIT"] = "/test/init";
|
|
203
|
+
ApiPath2["TRANSLATE"] = "/translate";
|
|
204
|
+
ApiPath2["TRANSLATIONS_ALL"] = "/lexemes/allTranslations/:sourceText/:sourceLang";
|
|
205
|
+
ApiPath2["USER"] = "/user";
|
|
206
|
+
ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked";
|
|
207
|
+
return ApiPath2;
|
|
208
|
+
})(ApiPath || {});
|
|
182
209
|
export {
|
|
183
210
|
ApiMethod,
|
|
184
211
|
ApiPath,
|
|
@@ -187,7 +214,9 @@ export {
|
|
|
187
214
|
HttpStatusCode,
|
|
188
215
|
Language,
|
|
189
216
|
LearningStage,
|
|
217
|
+
Lexeme,
|
|
190
218
|
LexemePair,
|
|
219
|
+
Progress,
|
|
191
220
|
ReminderFrequency,
|
|
192
221
|
Scenario,
|
|
193
222
|
VocabCheckType,
|
|
@@ -197,8 +226,10 @@ export {
|
|
|
197
226
|
getClientDate,
|
|
198
227
|
getFormattedDate,
|
|
199
228
|
isClientDateTooFarFromServerDate,
|
|
229
|
+
isStringContainingInteger,
|
|
200
230
|
isThePreviousDay,
|
|
201
231
|
isTheSameDay,
|
|
202
232
|
isValidJsDateString,
|
|
203
|
-
isValidMysqlDateString
|
|
233
|
+
isValidMysqlDateString,
|
|
234
|
+
parameterReplace
|
|
204
235
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "czapp-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "This is a shared library for Czapp projects. It contains common code that is used across multiple projects.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"typings": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "mocha --require ts-node/register/transpile-only test/**/*.ts",
|
|
9
|
+
"test:unit": "mocha --require ts-node/register/transpile-only test/**/*.ts",
|
|
10
10
|
"build": "tsup src/index.ts --clean --format=cjs,esm --dts",
|
|
11
|
-
"release:bump": "bumpp"
|
|
11
|
+
"release:bump": "bumpp",
|
|
12
|
+
"watch": "tsup src/index.ts --format=cjs,esm --dts --watch"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|
|
@@ -25,7 +26,6 @@
|
|
|
25
26
|
"bumpp": "^9.5.2",
|
|
26
27
|
"chai": "^3.0.0",
|
|
27
28
|
"mocha": "^10.5.2",
|
|
28
|
-
"mysql2": "^3.11.3",
|
|
29
29
|
"sinon": "^15.2.0",
|
|
30
30
|
"ts-node": "^7.0.1",
|
|
31
31
|
"tsup": "^8.3.0",
|