czapp-shared 1.0.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/README.md +2 -0
- package/dist/index.d.mts +321 -0
- package/dist/index.d.ts +321 -0
- package/dist/index.js +250 -0
- package/dist/index.mjs +204 -0
- package/package.json +32 -0
- package/src/index.ts +4 -0
- package/src/lexemes.ts +114 -0
- package/src/types.ts +194 -0
- package/src/user.ts +21 -0
- package/src/util.ts +118 -0
- package/test/util/util.test.ts +149 -0
- package/tsconfig.json +17 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
ApiMethod: () => ApiMethod,
|
|
23
|
+
ApiPath: () => ApiPath,
|
|
24
|
+
AppError: () => AppError,
|
|
25
|
+
Familiarity: () => Familiarity,
|
|
26
|
+
HttpStatusCode: () => HttpStatusCode,
|
|
27
|
+
Language: () => Language,
|
|
28
|
+
LearningStage: () => LearningStage,
|
|
29
|
+
LexemePair: () => LexemePair,
|
|
30
|
+
ReminderFrequency: () => ReminderFrequency,
|
|
31
|
+
Scenario: () => Scenario,
|
|
32
|
+
VocabCheckType: () => VocabCheckType,
|
|
33
|
+
convertJSDateObjectToMySQLDateString: () => convertJSDateObjectToMySQLDateString,
|
|
34
|
+
convertJSDateStringToMySQLDate: () => convertJSDateStringToMySQLDate,
|
|
35
|
+
dateDifferenceInDays: () => dateDifferenceInDays,
|
|
36
|
+
getClientDate: () => getClientDate,
|
|
37
|
+
getFormattedDate: () => getFormattedDate,
|
|
38
|
+
isClientDateTooFarFromServerDate: () => isClientDateTooFarFromServerDate,
|
|
39
|
+
isThePreviousDay: () => isThePreviousDay,
|
|
40
|
+
isTheSameDay: () => isTheSameDay,
|
|
41
|
+
isValidJsDateString: () => isValidJsDateString,
|
|
42
|
+
isValidMysqlDateString: () => isValidMysqlDateString
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(src_exports);
|
|
45
|
+
|
|
46
|
+
// src/types.ts
|
|
47
|
+
var Language = /* @__PURE__ */ ((Language3) => {
|
|
48
|
+
Language3["CZECH"] = "cz";
|
|
49
|
+
Language3["ENGLISH"] = "en";
|
|
50
|
+
Language3["UNKNOWN"] = "UNKNOWN";
|
|
51
|
+
return Language3;
|
|
52
|
+
})(Language || {});
|
|
53
|
+
var Familiarity = /* @__PURE__ */ ((Familiarity2) => {
|
|
54
|
+
Familiarity2["KNOWN"] = "KNOWN";
|
|
55
|
+
Familiarity2["ALMOST"] = "ALMOST";
|
|
56
|
+
Familiarity2["UNKNOWN"] = "UNKNOWN";
|
|
57
|
+
return Familiarity2;
|
|
58
|
+
})(Familiarity || {});
|
|
59
|
+
var VocabCheckType = /* @__PURE__ */ ((VocabCheckType2) => {
|
|
60
|
+
VocabCheckType2["FLASHCARD"] = "flashcard";
|
|
61
|
+
VocabCheckType2["TEST"] = "test";
|
|
62
|
+
return VocabCheckType2;
|
|
63
|
+
})(VocabCheckType || {});
|
|
64
|
+
var LearningStage = /* @__PURE__ */ ((LearningStage3) => {
|
|
65
|
+
LearningStage3["NEW"] = "NEW";
|
|
66
|
+
LearningStage3["LEARNING"] = "LEARNING";
|
|
67
|
+
LearningStage3["RETIRED"] = "RETIRED";
|
|
68
|
+
return LearningStage3;
|
|
69
|
+
})(LearningStage || {});
|
|
70
|
+
var ReminderFrequency = /* @__PURE__ */ ((ReminderFrequency2) => {
|
|
71
|
+
ReminderFrequency2["ALWAYS"] = "always";
|
|
72
|
+
ReminderFrequency2["DAILY"] = "daily";
|
|
73
|
+
ReminderFrequency2["NEVER"] = "never";
|
|
74
|
+
return ReminderFrequency2;
|
|
75
|
+
})(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
|
+
var AppError = /* @__PURE__ */ ((AppError2) => {
|
|
105
|
+
AppError2["NONE"] = "No error";
|
|
106
|
+
AppError2["REQUEST_AUTOLOGIN_FAILED"] = "Failed to auto-login";
|
|
107
|
+
AppError2["REQUEST_DELETE_ALL_USER_DATA_FAILED"] = "Failed to delete all user data";
|
|
108
|
+
AppError2["REQUEST_DELETE_LEXEME_PAIR_FAILED"] = "Failed to delete lexeme pair";
|
|
109
|
+
AppError2["REQUEST_SIGN_IN_FAILED"] = "Failed to sign in";
|
|
110
|
+
AppError2["REQUEST_SIGN_OUT_FAILED"] = "Failed to sign out";
|
|
111
|
+
AppError2["REQUEST_GET_LEXEMES_FAILED"] = "Failed to get lexemes";
|
|
112
|
+
AppError2["REQUEST_GET_LEXEMES_FOR_TEST_FAILED"] = "Failed to get lexemes for test";
|
|
113
|
+
AppError2["REQUEST_UPDATE_FAMILIARITY_FAILED"] = "Failed to update familiarity";
|
|
114
|
+
AppError2["REQUEST_UPDATE_USER_SETTINGS_FAILED"] = "Failed to update user settings";
|
|
115
|
+
AppError2["REQUEST_INSERT_OR_UPDATE_LEXEME_PAIR_FAILED"] = "Failed to insert or update lexeme pair";
|
|
116
|
+
AppError2["REQUEST_TRANSLATION_FAILED"] = "Failed to get translation";
|
|
117
|
+
AppError2["REQUEST_TEST_COMPLETE_FAILED"] = "Failed to complete test";
|
|
118
|
+
return AppError2;
|
|
119
|
+
})(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
|
+
var Scenario = /* @__PURE__ */ ((Scenario2) => {
|
|
131
|
+
Scenario2["S1_INSERT_HAPPY_PATH"] = "Insert, happy path";
|
|
132
|
+
Scenario2["S2_INSERT_ENGLISH_LEXEME_AND_MAPPING_DUPLICATE_CZECH_LEXEME_FOUND_AND_USED"] = "Insert English lexeme and mapping, duplicate Czech lexeme found and used";
|
|
133
|
+
Scenario2["S3_INSERT_CZECH_LEXEME_AND_MAPPING_DUPLICATE_ENGLISH_LEXEME_FOUND_AND_USED"] = "Insert Czech lexeme and mapping, duplicate English lexeme found and used";
|
|
134
|
+
Scenario2["S4_INSERT_MAPPING_ONLY_DUPLICATE_CZECH_AND_ENGLISH_LEXEMES_FOUND_AND_USED"] = "Insert mapping only, duplicate Czech and English lexemes found and used";
|
|
135
|
+
Scenario2["S5_NO_INSERT_REQUIRED_DUPLICATE_LEXEMES_AND_PAIRING_FOUND"] = "No insert required, duplicate lexemes and pairing found";
|
|
136
|
+
Scenario2["S6_NO_UPDATE_REQUIRED_NO_CHANGES_DETECTED"] = "No update required, no changes detected";
|
|
137
|
+
Scenario2["S7_CZECH_LEXEME_UPDATED"] = "Scenario 7: Czech lexeme updated";
|
|
138
|
+
Scenario2["S8_CZECH_LEXEME_DELETED_DUPLICATE_CZECH_LEXEME_CAN_BE_USED"] = "Scenario 8: Czech lexeme deleted, duplicate Czech lexeme can be used can be used";
|
|
139
|
+
Scenario2["S9_CZECH_LEXEME_AND_MAPPING_DELETED_DISCOVERED_LEXEMES_AND_MAPPING_CAN_BE_USED"] = "Scenario 9: Czech lexeme and mapping deleted, discovered lexemes and mapping can be used";
|
|
140
|
+
Scenario2["S10_MAPPING_UPDATED_TO_USE_NEW_CZECH_LEXEME"] = "Scenario 10: Mapping updated to use new Czech lexeme";
|
|
141
|
+
Scenario2["S11_MAPPING_UPDATED_TO_USE_DUPLICATE_CZECH_LEXEME"] = "Scenario 11: Mapping updated to use duplicate Czech lexeme";
|
|
142
|
+
Scenario2["S12_MAPPING_DELETED_DUPLICATE_MAPPING_CAN_BE_USED_WHEN_CZECH_LEXEME_MODIFIED"] = "Scenario 12: Mapping deleted, duplicate mapping can be used when Czech lexeme modified";
|
|
143
|
+
Scenario2["S13_ENGLISH_LEXEME_UPDATED"] = "Scenario 13: English lexeme updated";
|
|
144
|
+
Scenario2["S14_ENGLISH_LEXEME_DELETED_DUPLICATE_ENGLISH_LEXEME_CAN_BE_USED"] = "Scenario 14: English lexeme deleted, duplicate English lexeme can be used";
|
|
145
|
+
Scenario2["S15_ENGLISH_LEXEME_AND_MAPPING_DELETED_DISCOVERED_LEXEMES_AND_MAPPING_CAN_BE_USED"] = "Scenario 15: English lexeme and mapping deleted, discovered lexemes and mapping can be used";
|
|
146
|
+
Scenario2["S16_MAPPING_UPDATED_TO_USE_NEW_ENGLISH_LEXEME"] = "Scenario 16: Mapping updated to use new English lexeme";
|
|
147
|
+
Scenario2["S17_MAPPING_UPDATED_TO_USE_DUPLICATE_ENGLISH_LEXEME"] = "Scenario 17: Mapping updated to use duplicate English lexeme";
|
|
148
|
+
Scenario2["S18_MAPPING_DELETED_DUPLICATE_MAPPING_CAN_BE_USED_WHEN_ENGLISH_LEXEME_MODIFIED"] = "Scenario 18: Mapping deleted, duplicate mapping can be used when English lexeme modified";
|
|
149
|
+
Scenario2["ERROR"] = "Error";
|
|
150
|
+
return Scenario2;
|
|
151
|
+
})(Scenario || {});
|
|
152
|
+
|
|
153
|
+
// src/lexemes.ts
|
|
154
|
+
var LexemePair = class {
|
|
155
|
+
constructor(englishLexeme, czechLexeme) {
|
|
156
|
+
this.notes = "";
|
|
157
|
+
this.userId = "";
|
|
158
|
+
this.czechLexeme = czechLexeme;
|
|
159
|
+
this.englishLexeme = englishLexeme;
|
|
160
|
+
this.familiarity = "UNKNOWN" /* UNKNOWN */;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/util.ts
|
|
165
|
+
var convertJSDateObjectToMySQLDateString = (date) => {
|
|
166
|
+
let dateStr;
|
|
167
|
+
try {
|
|
168
|
+
dateStr = date.toISOString().slice(0, 19).replace("T", " ");
|
|
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();
|
|
217
|
+
};
|
|
218
|
+
var isTheSameDay = (date1, date2) => {
|
|
219
|
+
return new Date(date1).toDateString() === new Date(date2).toDateString();
|
|
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}`;
|
|
226
|
+
};
|
|
227
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
228
|
+
0 && (module.exports = {
|
|
229
|
+
ApiMethod,
|
|
230
|
+
ApiPath,
|
|
231
|
+
AppError,
|
|
232
|
+
Familiarity,
|
|
233
|
+
HttpStatusCode,
|
|
234
|
+
Language,
|
|
235
|
+
LearningStage,
|
|
236
|
+
LexemePair,
|
|
237
|
+
ReminderFrequency,
|
|
238
|
+
Scenario,
|
|
239
|
+
VocabCheckType,
|
|
240
|
+
convertJSDateObjectToMySQLDateString,
|
|
241
|
+
convertJSDateStringToMySQLDate,
|
|
242
|
+
dateDifferenceInDays,
|
|
243
|
+
getClientDate,
|
|
244
|
+
getFormattedDate,
|
|
245
|
+
isClientDateTooFarFromServerDate,
|
|
246
|
+
isThePreviousDay,
|
|
247
|
+
isTheSameDay,
|
|
248
|
+
isValidJsDateString,
|
|
249
|
+
isValidMysqlDateString
|
|
250
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var Language = /* @__PURE__ */ ((Language3) => {
|
|
3
|
+
Language3["CZECH"] = "cz";
|
|
4
|
+
Language3["ENGLISH"] = "en";
|
|
5
|
+
Language3["UNKNOWN"] = "UNKNOWN";
|
|
6
|
+
return Language3;
|
|
7
|
+
})(Language || {});
|
|
8
|
+
var Familiarity = /* @__PURE__ */ ((Familiarity2) => {
|
|
9
|
+
Familiarity2["KNOWN"] = "KNOWN";
|
|
10
|
+
Familiarity2["ALMOST"] = "ALMOST";
|
|
11
|
+
Familiarity2["UNKNOWN"] = "UNKNOWN";
|
|
12
|
+
return Familiarity2;
|
|
13
|
+
})(Familiarity || {});
|
|
14
|
+
var VocabCheckType = /* @__PURE__ */ ((VocabCheckType2) => {
|
|
15
|
+
VocabCheckType2["FLASHCARD"] = "flashcard";
|
|
16
|
+
VocabCheckType2["TEST"] = "test";
|
|
17
|
+
return VocabCheckType2;
|
|
18
|
+
})(VocabCheckType || {});
|
|
19
|
+
var LearningStage = /* @__PURE__ */ ((LearningStage3) => {
|
|
20
|
+
LearningStage3["NEW"] = "NEW";
|
|
21
|
+
LearningStage3["LEARNING"] = "LEARNING";
|
|
22
|
+
LearningStage3["RETIRED"] = "RETIRED";
|
|
23
|
+
return LearningStage3;
|
|
24
|
+
})(LearningStage || {});
|
|
25
|
+
var ReminderFrequency = /* @__PURE__ */ ((ReminderFrequency2) => {
|
|
26
|
+
ReminderFrequency2["ALWAYS"] = "always";
|
|
27
|
+
ReminderFrequency2["DAILY"] = "daily";
|
|
28
|
+
ReminderFrequency2["NEVER"] = "never";
|
|
29
|
+
return ReminderFrequency2;
|
|
30
|
+
})(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
|
+
var AppError = /* @__PURE__ */ ((AppError2) => {
|
|
60
|
+
AppError2["NONE"] = "No error";
|
|
61
|
+
AppError2["REQUEST_AUTOLOGIN_FAILED"] = "Failed to auto-login";
|
|
62
|
+
AppError2["REQUEST_DELETE_ALL_USER_DATA_FAILED"] = "Failed to delete all user data";
|
|
63
|
+
AppError2["REQUEST_DELETE_LEXEME_PAIR_FAILED"] = "Failed to delete lexeme pair";
|
|
64
|
+
AppError2["REQUEST_SIGN_IN_FAILED"] = "Failed to sign in";
|
|
65
|
+
AppError2["REQUEST_SIGN_OUT_FAILED"] = "Failed to sign out";
|
|
66
|
+
AppError2["REQUEST_GET_LEXEMES_FAILED"] = "Failed to get lexemes";
|
|
67
|
+
AppError2["REQUEST_GET_LEXEMES_FOR_TEST_FAILED"] = "Failed to get lexemes for test";
|
|
68
|
+
AppError2["REQUEST_UPDATE_FAMILIARITY_FAILED"] = "Failed to update familiarity";
|
|
69
|
+
AppError2["REQUEST_UPDATE_USER_SETTINGS_FAILED"] = "Failed to update user settings";
|
|
70
|
+
AppError2["REQUEST_INSERT_OR_UPDATE_LEXEME_PAIR_FAILED"] = "Failed to insert or update lexeme pair";
|
|
71
|
+
AppError2["REQUEST_TRANSLATION_FAILED"] = "Failed to get translation";
|
|
72
|
+
AppError2["REQUEST_TEST_COMPLETE_FAILED"] = "Failed to complete test";
|
|
73
|
+
return AppError2;
|
|
74
|
+
})(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
|
+
var Scenario = /* @__PURE__ */ ((Scenario2) => {
|
|
86
|
+
Scenario2["S1_INSERT_HAPPY_PATH"] = "Insert, happy path";
|
|
87
|
+
Scenario2["S2_INSERT_ENGLISH_LEXEME_AND_MAPPING_DUPLICATE_CZECH_LEXEME_FOUND_AND_USED"] = "Insert English lexeme and mapping, duplicate Czech lexeme found and used";
|
|
88
|
+
Scenario2["S3_INSERT_CZECH_LEXEME_AND_MAPPING_DUPLICATE_ENGLISH_LEXEME_FOUND_AND_USED"] = "Insert Czech lexeme and mapping, duplicate English lexeme found and used";
|
|
89
|
+
Scenario2["S4_INSERT_MAPPING_ONLY_DUPLICATE_CZECH_AND_ENGLISH_LEXEMES_FOUND_AND_USED"] = "Insert mapping only, duplicate Czech and English lexemes found and used";
|
|
90
|
+
Scenario2["S5_NO_INSERT_REQUIRED_DUPLICATE_LEXEMES_AND_PAIRING_FOUND"] = "No insert required, duplicate lexemes and pairing found";
|
|
91
|
+
Scenario2["S6_NO_UPDATE_REQUIRED_NO_CHANGES_DETECTED"] = "No update required, no changes detected";
|
|
92
|
+
Scenario2["S7_CZECH_LEXEME_UPDATED"] = "Scenario 7: Czech lexeme updated";
|
|
93
|
+
Scenario2["S8_CZECH_LEXEME_DELETED_DUPLICATE_CZECH_LEXEME_CAN_BE_USED"] = "Scenario 8: Czech lexeme deleted, duplicate Czech lexeme can be used can be used";
|
|
94
|
+
Scenario2["S9_CZECH_LEXEME_AND_MAPPING_DELETED_DISCOVERED_LEXEMES_AND_MAPPING_CAN_BE_USED"] = "Scenario 9: Czech lexeme and mapping deleted, discovered lexemes and mapping can be used";
|
|
95
|
+
Scenario2["S10_MAPPING_UPDATED_TO_USE_NEW_CZECH_LEXEME"] = "Scenario 10: Mapping updated to use new Czech lexeme";
|
|
96
|
+
Scenario2["S11_MAPPING_UPDATED_TO_USE_DUPLICATE_CZECH_LEXEME"] = "Scenario 11: Mapping updated to use duplicate Czech lexeme";
|
|
97
|
+
Scenario2["S12_MAPPING_DELETED_DUPLICATE_MAPPING_CAN_BE_USED_WHEN_CZECH_LEXEME_MODIFIED"] = "Scenario 12: Mapping deleted, duplicate mapping can be used when Czech lexeme modified";
|
|
98
|
+
Scenario2["S13_ENGLISH_LEXEME_UPDATED"] = "Scenario 13: English lexeme updated";
|
|
99
|
+
Scenario2["S14_ENGLISH_LEXEME_DELETED_DUPLICATE_ENGLISH_LEXEME_CAN_BE_USED"] = "Scenario 14: English lexeme deleted, duplicate English lexeme can be used";
|
|
100
|
+
Scenario2["S15_ENGLISH_LEXEME_AND_MAPPING_DELETED_DISCOVERED_LEXEMES_AND_MAPPING_CAN_BE_USED"] = "Scenario 15: English lexeme and mapping deleted, discovered lexemes and mapping can be used";
|
|
101
|
+
Scenario2["S16_MAPPING_UPDATED_TO_USE_NEW_ENGLISH_LEXEME"] = "Scenario 16: Mapping updated to use new English lexeme";
|
|
102
|
+
Scenario2["S17_MAPPING_UPDATED_TO_USE_DUPLICATE_ENGLISH_LEXEME"] = "Scenario 17: Mapping updated to use duplicate English lexeme";
|
|
103
|
+
Scenario2["S18_MAPPING_DELETED_DUPLICATE_MAPPING_CAN_BE_USED_WHEN_ENGLISH_LEXEME_MODIFIED"] = "Scenario 18: Mapping deleted, duplicate mapping can be used when English lexeme modified";
|
|
104
|
+
Scenario2["ERROR"] = "Error";
|
|
105
|
+
return Scenario2;
|
|
106
|
+
})(Scenario || {});
|
|
107
|
+
|
|
108
|
+
// src/lexemes.ts
|
|
109
|
+
var LexemePair = class {
|
|
110
|
+
constructor(englishLexeme, czechLexeme) {
|
|
111
|
+
this.notes = "";
|
|
112
|
+
this.userId = "";
|
|
113
|
+
this.czechLexeme = czechLexeme;
|
|
114
|
+
this.englishLexeme = englishLexeme;
|
|
115
|
+
this.familiarity = "UNKNOWN" /* UNKNOWN */;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/util.ts
|
|
120
|
+
var convertJSDateObjectToMySQLDateString = (date) => {
|
|
121
|
+
let dateStr;
|
|
122
|
+
try {
|
|
123
|
+
dateStr = date.toISOString().slice(0, 19).replace("T", " ");
|
|
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();
|
|
172
|
+
};
|
|
173
|
+
var isTheSameDay = (date1, date2) => {
|
|
174
|
+
return new Date(date1).toDateString() === new Date(date2).toDateString();
|
|
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}`;
|
|
181
|
+
};
|
|
182
|
+
export {
|
|
183
|
+
ApiMethod,
|
|
184
|
+
ApiPath,
|
|
185
|
+
AppError,
|
|
186
|
+
Familiarity,
|
|
187
|
+
HttpStatusCode,
|
|
188
|
+
Language,
|
|
189
|
+
LearningStage,
|
|
190
|
+
LexemePair,
|
|
191
|
+
ReminderFrequency,
|
|
192
|
+
Scenario,
|
|
193
|
+
VocabCheckType,
|
|
194
|
+
convertJSDateObjectToMySQLDateString,
|
|
195
|
+
convertJSDateStringToMySQLDate,
|
|
196
|
+
dateDifferenceInDays,
|
|
197
|
+
getClientDate,
|
|
198
|
+
getFormattedDate,
|
|
199
|
+
isClientDateTooFarFromServerDate,
|
|
200
|
+
isThePreviousDay,
|
|
201
|
+
isTheSameDay,
|
|
202
|
+
isValidJsDateString,
|
|
203
|
+
isValidMysqlDateString
|
|
204
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "czapp-shared",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "This is a shared library for Czapp projects. It contains common code that is used across multiple projects.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"typings": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test:unit": "mocha --require ts-node/register/transpile-only test/**/*.ts",
|
|
10
|
+
"build": "tsup src/index.ts --clean --format=cjs,esm --dts"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://gitlab.com/xoundserver/czapp-shared.git"
|
|
15
|
+
},
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"homepage": "https://gitlab.com/xoundserver/czapp-shared#readme",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@types/chai": "^3.0.0",
|
|
21
|
+
"@types/mocha": "^10.0.6",
|
|
22
|
+
"@types/node": "^18.11.9",
|
|
23
|
+
"@types/sinon": "^10.0.13",
|
|
24
|
+
"chai": "^3.0.0",
|
|
25
|
+
"mocha": "^10.5.2",
|
|
26
|
+
"mysql2": "^3.11.3",
|
|
27
|
+
"sinon": "^15.2.0",
|
|
28
|
+
"ts-node": "^7.0.1",
|
|
29
|
+
"tsup": "^8.3.0",
|
|
30
|
+
"typescript": "^4.9.3"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/index.ts
ADDED
package/src/lexemes.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { RowDataPacket } from 'mysql2';
|
|
2
|
+
import { Familiarity, Language, LearningStage, MySQLDate } from './types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* RowDataPacket types - Database query results
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @interface ILexemeRecord
|
|
10
|
+
* @description represents the database record for a single lexeme of any language. Once parsed will be used to create
|
|
11
|
+
* a Lexeme object implementing ILexeme
|
|
12
|
+
*/
|
|
13
|
+
export interface ILexemeRecord extends RowDataPacket {
|
|
14
|
+
id: number | undefined,
|
|
15
|
+
dateAdded: string,
|
|
16
|
+
text: string,
|
|
17
|
+
userId: string,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @interface ILexemePairRecord
|
|
22
|
+
* @description represents the database record for a lexeme pair along with texts and ids for the lexemes
|
|
23
|
+
* Once parsed will be used to create a LexemePair object implementing ILexemePair
|
|
24
|
+
*/
|
|
25
|
+
export interface ILexemePairRecord extends RowDataPacket {
|
|
26
|
+
czId: number,
|
|
27
|
+
czText: string,
|
|
28
|
+
dateAdded: MySQLDate,
|
|
29
|
+
enId: number,
|
|
30
|
+
enText: string,
|
|
31
|
+
familiarity: Familiarity,
|
|
32
|
+
firstKnownSessionDigit: number | null,
|
|
33
|
+
lastFlashcardReview: MySQLDate,
|
|
34
|
+
lastModified: MySQLDate,
|
|
35
|
+
lastTested: MySQLDate,
|
|
36
|
+
learningStage: LearningStage,
|
|
37
|
+
notes: string,
|
|
38
|
+
userId: string,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Plain types - structured objects that are used throughout the application
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
export interface ILexeme {
|
|
47
|
+
id: number | undefined;
|
|
48
|
+
dateAdded: string;
|
|
49
|
+
text: string;
|
|
50
|
+
userId: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ILexemePair {
|
|
54
|
+
czechLexeme: ILexeme;
|
|
55
|
+
dateAdded: MySQLDate;
|
|
56
|
+
englishLexeme: ILexeme;
|
|
57
|
+
familiarity: Familiarity;
|
|
58
|
+
firstKnownSessionDigit: number | null,
|
|
59
|
+
lastFlashcardReview: MySQLDate,
|
|
60
|
+
lastModified: MySQLDate;
|
|
61
|
+
lastTested: MySQLDate;
|
|
62
|
+
learningStage: LearningStage,
|
|
63
|
+
notes: string;
|
|
64
|
+
userId: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type LexemePairPayload = {
|
|
68
|
+
czLexeme: ILexeme
|
|
69
|
+
enLexeme: ILexeme;
|
|
70
|
+
pairingNotes: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type LexemePairWithLang = {
|
|
74
|
+
czechLexeme: ILexeme,
|
|
75
|
+
englishLexeme: ILexeme,
|
|
76
|
+
langToFocus: Language
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Classes
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
export default class Lexeme implements ILexeme {
|
|
85
|
+
text: string = '';
|
|
86
|
+
id: number | null = null;
|
|
87
|
+
dateAdded: string = "";
|
|
88
|
+
userId: string = "";
|
|
89
|
+
constructor(text: string, id: number | null = null) {
|
|
90
|
+
this.text = text;
|
|
91
|
+
this.id = id;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class LexemePair implements ILexemePair {
|
|
96
|
+
czechLexeme: ILexeme;
|
|
97
|
+
dateAdded: MySQLDate;
|
|
98
|
+
englishLexeme: ILexeme;
|
|
99
|
+
familiarity: Familiarity;
|
|
100
|
+
firstKnownSessionDigit: number | null;
|
|
101
|
+
lastFlashcardReview: MySQLDate;
|
|
102
|
+
lastModified: MySQLDate;
|
|
103
|
+
lastTested: MySQLDate;
|
|
104
|
+
learningStage: LearningStage;
|
|
105
|
+
notes: string = "";
|
|
106
|
+
userId: string = "";
|
|
107
|
+
|
|
108
|
+
constructor (englishLexeme: ILexeme, czechLexeme: ILexeme) {
|
|
109
|
+
this.czechLexeme = czechLexeme;
|
|
110
|
+
this.englishLexeme = englishLexeme;
|
|
111
|
+
this.familiarity = Familiarity.UNKNOWN;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|