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/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { RowDataPacket } from 'mysql2';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* RowDataPacket types - Database query results
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @interface ILexemeRecord
|
|
8
|
+
* @description represents the database record for a single lexeme of any language. Once parsed will be used to create
|
|
9
|
+
* a Lexeme object implementing ILexeme
|
|
10
|
+
*/
|
|
11
|
+
interface ILexemeRecord extends RowDataPacket {
|
|
12
|
+
id: number | undefined;
|
|
13
|
+
dateAdded: string;
|
|
14
|
+
text: string;
|
|
15
|
+
userId: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @interface ILexemePairRecord
|
|
19
|
+
* @description represents the database record for a lexeme pair along with texts and ids for the lexemes
|
|
20
|
+
* Once parsed will be used to create a LexemePair object implementing ILexemePair
|
|
21
|
+
*/
|
|
22
|
+
interface ILexemePairRecord extends RowDataPacket {
|
|
23
|
+
czId: number;
|
|
24
|
+
czText: string;
|
|
25
|
+
dateAdded: MySQLDate;
|
|
26
|
+
enId: number;
|
|
27
|
+
enText: string;
|
|
28
|
+
familiarity: Familiarity;
|
|
29
|
+
firstKnownSessionDigit: number | null;
|
|
30
|
+
lastFlashcardReview: MySQLDate;
|
|
31
|
+
lastModified: MySQLDate;
|
|
32
|
+
lastTested: MySQLDate;
|
|
33
|
+
learningStage: LearningStage;
|
|
34
|
+
notes: string;
|
|
35
|
+
userId: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Plain types - structured objects that are used throughout the application
|
|
39
|
+
*/
|
|
40
|
+
interface ILexeme {
|
|
41
|
+
id: number | undefined;
|
|
42
|
+
dateAdded: string;
|
|
43
|
+
text: string;
|
|
44
|
+
userId: string;
|
|
45
|
+
}
|
|
46
|
+
interface ILexemePair {
|
|
47
|
+
czechLexeme: ILexeme;
|
|
48
|
+
dateAdded: MySQLDate;
|
|
49
|
+
englishLexeme: ILexeme;
|
|
50
|
+
familiarity: Familiarity;
|
|
51
|
+
firstKnownSessionDigit: number | null;
|
|
52
|
+
lastFlashcardReview: MySQLDate;
|
|
53
|
+
lastModified: MySQLDate;
|
|
54
|
+
lastTested: MySQLDate;
|
|
55
|
+
learningStage: LearningStage;
|
|
56
|
+
notes: string;
|
|
57
|
+
userId: string;
|
|
58
|
+
}
|
|
59
|
+
type LexemePairPayload = {
|
|
60
|
+
czLexeme: ILexeme;
|
|
61
|
+
enLexeme: ILexeme;
|
|
62
|
+
pairingNotes: string;
|
|
63
|
+
};
|
|
64
|
+
type LexemePairWithLang = {
|
|
65
|
+
czechLexeme: ILexeme;
|
|
66
|
+
englishLexeme: ILexeme;
|
|
67
|
+
langToFocus: Language;
|
|
68
|
+
};
|
|
69
|
+
declare class LexemePair implements ILexemePair {
|
|
70
|
+
czechLexeme: ILexeme;
|
|
71
|
+
dateAdded: MySQLDate;
|
|
72
|
+
englishLexeme: ILexeme;
|
|
73
|
+
familiarity: Familiarity;
|
|
74
|
+
firstKnownSessionDigit: number | null;
|
|
75
|
+
lastFlashcardReview: MySQLDate;
|
|
76
|
+
lastModified: MySQLDate;
|
|
77
|
+
lastTested: MySQLDate;
|
|
78
|
+
learningStage: LearningStage;
|
|
79
|
+
notes: string;
|
|
80
|
+
userId: string;
|
|
81
|
+
constructor(englishLexeme: ILexeme, czechLexeme: ILexeme);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare enum Language {
|
|
85
|
+
CZECH = "cz",
|
|
86
|
+
ENGLISH = "en",
|
|
87
|
+
UNKNOWN = "UNKNOWN"
|
|
88
|
+
}
|
|
89
|
+
type Result<T> = [T, undefined] | [undefined, Error];
|
|
90
|
+
declare enum Familiarity {
|
|
91
|
+
KNOWN = "KNOWN",
|
|
92
|
+
ALMOST = "ALMOST",
|
|
93
|
+
UNKNOWN = "UNKNOWN"
|
|
94
|
+
}
|
|
95
|
+
declare enum VocabCheckType {
|
|
96
|
+
FLASHCARD = "flashcard",
|
|
97
|
+
TEST = "test"
|
|
98
|
+
}
|
|
99
|
+
declare enum LearningStage {
|
|
100
|
+
NEW = "NEW",
|
|
101
|
+
LEARNING = "LEARNING",
|
|
102
|
+
RETIRED = "RETIRED"
|
|
103
|
+
}
|
|
104
|
+
type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
|
|
105
|
+
declare enum ReminderFrequency {
|
|
106
|
+
ALWAYS = "always",
|
|
107
|
+
DAILY = "daily",
|
|
108
|
+
NEVER = "never"
|
|
109
|
+
}
|
|
110
|
+
interface TestInitResponse {
|
|
111
|
+
lexemePairs: ILexemePairRecord[];
|
|
112
|
+
vocabCheckType: VocabCheckType;
|
|
113
|
+
}
|
|
114
|
+
interface InsertOrUpdateResponse {
|
|
115
|
+
scenario: Scenario;
|
|
116
|
+
lexemePair: ILexemePairRecord;
|
|
117
|
+
newMappingInserted?: boolean;
|
|
118
|
+
}
|
|
119
|
+
declare enum ApiPath {
|
|
120
|
+
AUTOLOGIN = "/autologin",
|
|
121
|
+
HEALTH = "/health",
|
|
122
|
+
LEXEMES = "/lexemes",
|
|
123
|
+
LEXEMES_ALL = "/lexemes/all",
|
|
124
|
+
LEXEMES_COUNT = "/lexemes/count/:language",
|
|
125
|
+
LEXEMES_DELETE_ALL = "/lexemes/deleteAll",
|
|
126
|
+
LEXEMES_PAGE = "/lexemes/:length/:page",
|
|
127
|
+
LEXEME_PAIR = "/lexemePair/:czId/:enId",
|
|
128
|
+
LEXEME_PAIRS_BY_TEXT = "/lexemePairsByText/:inputText/:inputLang",
|
|
129
|
+
LEXEME_PAIR_FAMILIARITY = "/lexemePair/:czId/:enId/:familiarity",
|
|
130
|
+
SIGN_IN = "/signIn",
|
|
131
|
+
SIGN_OUT = "/signOut",
|
|
132
|
+
TEST_COMPLETE = "/test/complete",
|
|
133
|
+
TEST_INIT = "/test/init",
|
|
134
|
+
TRANSLATE = "/translate",
|
|
135
|
+
TRANSLATIONS_ALL = "/lexemes/allTranslations/:sourceText/:sourceLang",
|
|
136
|
+
USER = "/user",
|
|
137
|
+
USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked"
|
|
138
|
+
}
|
|
139
|
+
declare enum ApiMethod {
|
|
140
|
+
GET = "GET",
|
|
141
|
+
POST = "POST",
|
|
142
|
+
PUT = "PUT",
|
|
143
|
+
DELETE = "DELETE"
|
|
144
|
+
}
|
|
145
|
+
declare enum AppError {
|
|
146
|
+
NONE = "No error",
|
|
147
|
+
REQUEST_AUTOLOGIN_FAILED = "Failed to auto-login",
|
|
148
|
+
REQUEST_DELETE_ALL_USER_DATA_FAILED = "Failed to delete all user data",
|
|
149
|
+
REQUEST_DELETE_LEXEME_PAIR_FAILED = "Failed to delete lexeme pair",
|
|
150
|
+
REQUEST_SIGN_IN_FAILED = "Failed to sign in",
|
|
151
|
+
REQUEST_SIGN_OUT_FAILED = "Failed to sign out",
|
|
152
|
+
REQUEST_GET_LEXEMES_FAILED = "Failed to get lexemes",
|
|
153
|
+
REQUEST_GET_LEXEMES_FOR_TEST_FAILED = "Failed to get lexemes for test",
|
|
154
|
+
REQUEST_UPDATE_FAMILIARITY_FAILED = "Failed to update familiarity",
|
|
155
|
+
REQUEST_UPDATE_USER_SETTINGS_FAILED = "Failed to update user settings",
|
|
156
|
+
REQUEST_INSERT_OR_UPDATE_LEXEME_PAIR_FAILED = "Failed to insert or update lexeme pair",
|
|
157
|
+
REQUEST_TRANSLATION_FAILED = "Failed to get translation",
|
|
158
|
+
REQUEST_TEST_COMPLETE_FAILED = "Failed to complete test"
|
|
159
|
+
}
|
|
160
|
+
declare enum HttpStatusCode {
|
|
161
|
+
OK = 200,
|
|
162
|
+
BAD_REQUEST = 400,
|
|
163
|
+
UNAUTHORIZED = 401,
|
|
164
|
+
NOT_FOUND = 404,
|
|
165
|
+
TIMEOUT = 408,
|
|
166
|
+
ABORTED = 409,
|
|
167
|
+
INTERNAL_SERVER_ERROR = 500
|
|
168
|
+
}
|
|
169
|
+
interface ControllerResponse<T> {
|
|
170
|
+
message: string;
|
|
171
|
+
status: HttpStatusCode;
|
|
172
|
+
data: T;
|
|
173
|
+
}
|
|
174
|
+
interface ControllerResponse<T> {
|
|
175
|
+
message: string;
|
|
176
|
+
status: HttpStatusCode;
|
|
177
|
+
data: T;
|
|
178
|
+
}
|
|
179
|
+
type DeeplTranslation = {
|
|
180
|
+
detectedSourceLanguage: string;
|
|
181
|
+
translations: Array<{
|
|
182
|
+
translatedText: string;
|
|
183
|
+
}>;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* RowDataPacket types - Database query results
|
|
187
|
+
*/
|
|
188
|
+
interface MappedCzIds extends RowDataPacket {
|
|
189
|
+
czId: number;
|
|
190
|
+
}
|
|
191
|
+
interface MappedEnIds extends RowDataPacket {
|
|
192
|
+
enId: number;
|
|
193
|
+
}
|
|
194
|
+
interface DuplicateId extends RowDataPacket {
|
|
195
|
+
id: number;
|
|
196
|
+
}
|
|
197
|
+
interface InsertIdDataRecord extends RowDataPacket {
|
|
198
|
+
insertId: number;
|
|
199
|
+
}
|
|
200
|
+
interface UpdateDataRecord extends RowDataPacket {
|
|
201
|
+
}
|
|
202
|
+
interface UserRecord extends RowDataPacket {
|
|
203
|
+
id: number | undefined;
|
|
204
|
+
googleSub: string;
|
|
205
|
+
name: string;
|
|
206
|
+
email: string;
|
|
207
|
+
phone: string;
|
|
208
|
+
signUpDate: Date;
|
|
209
|
+
lastModified: Date;
|
|
210
|
+
learningLanguage: string;
|
|
211
|
+
flashcardReviewCompletedCount: number;
|
|
212
|
+
currentStreakLength: number;
|
|
213
|
+
currentStreakEnd: MySQLDate | undefined;
|
|
214
|
+
highStreakLength: number;
|
|
215
|
+
highStreakEnd: MySQLDate | undefined;
|
|
216
|
+
testsUnlocked: boolean;
|
|
217
|
+
rewardPoints: number;
|
|
218
|
+
}
|
|
219
|
+
interface CountRecord extends RowDataPacket {
|
|
220
|
+
count: number;
|
|
221
|
+
}
|
|
222
|
+
interface LastWordsAddedRecord extends RowDataPacket {
|
|
223
|
+
czText: string;
|
|
224
|
+
enText: string;
|
|
225
|
+
}
|
|
226
|
+
declare enum Scenario {
|
|
227
|
+
S1_INSERT_HAPPY_PATH = "Insert, happy path",
|
|
228
|
+
S2_INSERT_ENGLISH_LEXEME_AND_MAPPING_DUPLICATE_CZECH_LEXEME_FOUND_AND_USED = "Insert English lexeme and mapping, duplicate Czech lexeme found and used",
|
|
229
|
+
S3_INSERT_CZECH_LEXEME_AND_MAPPING_DUPLICATE_ENGLISH_LEXEME_FOUND_AND_USED = "Insert Czech lexeme and mapping, duplicate English lexeme found and used",
|
|
230
|
+
S4_INSERT_MAPPING_ONLY_DUPLICATE_CZECH_AND_ENGLISH_LEXEMES_FOUND_AND_USED = "Insert mapping only, duplicate Czech and English lexemes found and used",
|
|
231
|
+
S5_NO_INSERT_REQUIRED_DUPLICATE_LEXEMES_AND_PAIRING_FOUND = "No insert required, duplicate lexemes and pairing found",
|
|
232
|
+
S6_NO_UPDATE_REQUIRED_NO_CHANGES_DETECTED = "No update required, no changes detected",
|
|
233
|
+
S7_CZECH_LEXEME_UPDATED = "Scenario 7: Czech lexeme updated",
|
|
234
|
+
S8_CZECH_LEXEME_DELETED_DUPLICATE_CZECH_LEXEME_CAN_BE_USED = "Scenario 8: Czech lexeme deleted, duplicate Czech lexeme can be used can be used",
|
|
235
|
+
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",
|
|
236
|
+
S10_MAPPING_UPDATED_TO_USE_NEW_CZECH_LEXEME = "Scenario 10: Mapping updated to use new Czech lexeme",
|
|
237
|
+
S11_MAPPING_UPDATED_TO_USE_DUPLICATE_CZECH_LEXEME = "Scenario 11: Mapping updated to use duplicate Czech lexeme",
|
|
238
|
+
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",
|
|
239
|
+
S13_ENGLISH_LEXEME_UPDATED = "Scenario 13: English lexeme updated",
|
|
240
|
+
S14_ENGLISH_LEXEME_DELETED_DUPLICATE_ENGLISH_LEXEME_CAN_BE_USED = "Scenario 14: English lexeme deleted, duplicate English lexeme can be used",
|
|
241
|
+
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",
|
|
242
|
+
S16_MAPPING_UPDATED_TO_USE_NEW_ENGLISH_LEXEME = "Scenario 16: Mapping updated to use new English lexeme",
|
|
243
|
+
S17_MAPPING_UPDATED_TO_USE_DUPLICATE_ENGLISH_LEXEME = "Scenario 17: Mapping updated to use duplicate English lexeme",
|
|
244
|
+
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",
|
|
245
|
+
ERROR = "Error"
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @name convertJSDateObjectToMySQLDateString
|
|
250
|
+
* @description Converts a JavaScript Date object to a MySQL date string
|
|
251
|
+
* @param date
|
|
252
|
+
* @type Date
|
|
253
|
+
* @returns MySQLDate in the format "2021-01-01 07:41:23"
|
|
254
|
+
*/
|
|
255
|
+
declare const convertJSDateObjectToMySQLDateString: (date: Date) => MySQLDate | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* @name convertJSDateStringToMySQLDate
|
|
258
|
+
* @description Converts a JavaScript Date object to a MySQL date string
|
|
259
|
+
* @param date in the format "2021-01-01T07:41:23.000Z"
|
|
260
|
+
* @type string
|
|
261
|
+
* @returns date in the format "2021-01-01 07:41:23"
|
|
262
|
+
* @returns undefined if the input date is invalid
|
|
263
|
+
*/
|
|
264
|
+
declare const convertJSDateStringToMySQLDate: (date: string) => MySQLDate | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* @name isValidMysqlDateString
|
|
267
|
+
* @description Checks if a string representation of date/time is in the format "2021-01-01 07:41:23"
|
|
268
|
+
* @param dateStr
|
|
269
|
+
* @returns boolean
|
|
270
|
+
*/
|
|
271
|
+
declare const isValidMysqlDateString: (dateStr: string) => boolean;
|
|
272
|
+
/**
|
|
273
|
+
* @name isValidJsDateString
|
|
274
|
+
* @description Checks if a string representation of date/time is in the format "2021-01-01T07:41:23.000Z"
|
|
275
|
+
* @param dateStr
|
|
276
|
+
* @returns boolean
|
|
277
|
+
*/
|
|
278
|
+
declare const isValidJsDateString: (dateStr: string) => boolean;
|
|
279
|
+
/**
|
|
280
|
+
* @name isClientDateTooFarFromServerDate
|
|
281
|
+
* @description Checks if the client date is more than one day away from the server date
|
|
282
|
+
* @param clientDateMySQLFormat date in MySQL format
|
|
283
|
+
* @param serverDate date object representation of the current time on the server
|
|
284
|
+
* @returns boolean
|
|
285
|
+
*/
|
|
286
|
+
declare const isClientDateTooFarFromServerDate: (clientDateMySQLFormat: MySQLDate, serverDate: Date) => boolean;
|
|
287
|
+
/**
|
|
288
|
+
* @name dateDifferenceInDays
|
|
289
|
+
* @description Calculates the difference in days between two dates and returns a positive integer
|
|
290
|
+
* if the first date is before the second date, and a negative integer if the first date is after the second date
|
|
291
|
+
* @param date1 date in MySQL format
|
|
292
|
+
* @param date2 date in MySQL format
|
|
293
|
+
* @returns number
|
|
294
|
+
*/
|
|
295
|
+
declare const dateDifferenceInDays: (date1: MySQLDate, date2: MySQLDate) => number;
|
|
296
|
+
declare const getClientDate: (date: Date) => string;
|
|
297
|
+
declare const isThePreviousDay: (date: MySQLDate, referenceDate: MySQLDate) => boolean;
|
|
298
|
+
declare const isTheSameDay: (date1: MySQLDate, date2: MySQLDate) => boolean;
|
|
299
|
+
declare const getFormattedDate: (date: Date) => string;
|
|
300
|
+
|
|
301
|
+
type UserData = {
|
|
302
|
+
googleSub: string;
|
|
303
|
+
name: string;
|
|
304
|
+
email: string;
|
|
305
|
+
phone: string;
|
|
306
|
+
signUpDate: MySQLDate;
|
|
307
|
+
lastModified: MySQLDate;
|
|
308
|
+
learningLanguage: Language;
|
|
309
|
+
uiLanguage: Language;
|
|
310
|
+
testsCompletedCount: number;
|
|
311
|
+
currentStreakLength: number;
|
|
312
|
+
currentStreakEnd: MySQLDate;
|
|
313
|
+
highStreakLength: number;
|
|
314
|
+
highStreakEnd: MySQLDate;
|
|
315
|
+
testsUnlocked: boolean;
|
|
316
|
+
rewardPoints: number;
|
|
317
|
+
lastWordAdded: string;
|
|
318
|
+
lexemePairCount: number;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export { ApiMethod, ApiPath, AppError, type ControllerResponse, type CountRecord, type DeeplTranslation, type DuplicateId, Familiarity, HttpStatusCode, type ILexeme, type ILexemePair, type ILexemePairRecord, type ILexemeRecord, type InsertIdDataRecord, type InsertOrUpdateResponse, Language, type LastWordsAddedRecord, LearningStage, LexemePair, type LexemePairPayload, type LexemePairWithLang, type MappedCzIds, type MappedEnIds, type MySQLDate, ReminderFrequency, type Result, Scenario, type TestInitResponse, type UpdateDataRecord, type UserData, type UserRecord, VocabCheckType, convertJSDateObjectToMySQLDateString, convertJSDateStringToMySQLDate, dateDifferenceInDays, getClientDate, getFormattedDate, isClientDateTooFarFromServerDate, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { RowDataPacket } from 'mysql2';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* RowDataPacket types - Database query results
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @interface ILexemeRecord
|
|
8
|
+
* @description represents the database record for a single lexeme of any language. Once parsed will be used to create
|
|
9
|
+
* a Lexeme object implementing ILexeme
|
|
10
|
+
*/
|
|
11
|
+
interface ILexemeRecord extends RowDataPacket {
|
|
12
|
+
id: number | undefined;
|
|
13
|
+
dateAdded: string;
|
|
14
|
+
text: string;
|
|
15
|
+
userId: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @interface ILexemePairRecord
|
|
19
|
+
* @description represents the database record for a lexeme pair along with texts and ids for the lexemes
|
|
20
|
+
* Once parsed will be used to create a LexemePair object implementing ILexemePair
|
|
21
|
+
*/
|
|
22
|
+
interface ILexemePairRecord extends RowDataPacket {
|
|
23
|
+
czId: number;
|
|
24
|
+
czText: string;
|
|
25
|
+
dateAdded: MySQLDate;
|
|
26
|
+
enId: number;
|
|
27
|
+
enText: string;
|
|
28
|
+
familiarity: Familiarity;
|
|
29
|
+
firstKnownSessionDigit: number | null;
|
|
30
|
+
lastFlashcardReview: MySQLDate;
|
|
31
|
+
lastModified: MySQLDate;
|
|
32
|
+
lastTested: MySQLDate;
|
|
33
|
+
learningStage: LearningStage;
|
|
34
|
+
notes: string;
|
|
35
|
+
userId: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Plain types - structured objects that are used throughout the application
|
|
39
|
+
*/
|
|
40
|
+
interface ILexeme {
|
|
41
|
+
id: number | undefined;
|
|
42
|
+
dateAdded: string;
|
|
43
|
+
text: string;
|
|
44
|
+
userId: string;
|
|
45
|
+
}
|
|
46
|
+
interface ILexemePair {
|
|
47
|
+
czechLexeme: ILexeme;
|
|
48
|
+
dateAdded: MySQLDate;
|
|
49
|
+
englishLexeme: ILexeme;
|
|
50
|
+
familiarity: Familiarity;
|
|
51
|
+
firstKnownSessionDigit: number | null;
|
|
52
|
+
lastFlashcardReview: MySQLDate;
|
|
53
|
+
lastModified: MySQLDate;
|
|
54
|
+
lastTested: MySQLDate;
|
|
55
|
+
learningStage: LearningStage;
|
|
56
|
+
notes: string;
|
|
57
|
+
userId: string;
|
|
58
|
+
}
|
|
59
|
+
type LexemePairPayload = {
|
|
60
|
+
czLexeme: ILexeme;
|
|
61
|
+
enLexeme: ILexeme;
|
|
62
|
+
pairingNotes: string;
|
|
63
|
+
};
|
|
64
|
+
type LexemePairWithLang = {
|
|
65
|
+
czechLexeme: ILexeme;
|
|
66
|
+
englishLexeme: ILexeme;
|
|
67
|
+
langToFocus: Language;
|
|
68
|
+
};
|
|
69
|
+
declare class LexemePair implements ILexemePair {
|
|
70
|
+
czechLexeme: ILexeme;
|
|
71
|
+
dateAdded: MySQLDate;
|
|
72
|
+
englishLexeme: ILexeme;
|
|
73
|
+
familiarity: Familiarity;
|
|
74
|
+
firstKnownSessionDigit: number | null;
|
|
75
|
+
lastFlashcardReview: MySQLDate;
|
|
76
|
+
lastModified: MySQLDate;
|
|
77
|
+
lastTested: MySQLDate;
|
|
78
|
+
learningStage: LearningStage;
|
|
79
|
+
notes: string;
|
|
80
|
+
userId: string;
|
|
81
|
+
constructor(englishLexeme: ILexeme, czechLexeme: ILexeme);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare enum Language {
|
|
85
|
+
CZECH = "cz",
|
|
86
|
+
ENGLISH = "en",
|
|
87
|
+
UNKNOWN = "UNKNOWN"
|
|
88
|
+
}
|
|
89
|
+
type Result<T> = [T, undefined] | [undefined, Error];
|
|
90
|
+
declare enum Familiarity {
|
|
91
|
+
KNOWN = "KNOWN",
|
|
92
|
+
ALMOST = "ALMOST",
|
|
93
|
+
UNKNOWN = "UNKNOWN"
|
|
94
|
+
}
|
|
95
|
+
declare enum VocabCheckType {
|
|
96
|
+
FLASHCARD = "flashcard",
|
|
97
|
+
TEST = "test"
|
|
98
|
+
}
|
|
99
|
+
declare enum LearningStage {
|
|
100
|
+
NEW = "NEW",
|
|
101
|
+
LEARNING = "LEARNING",
|
|
102
|
+
RETIRED = "RETIRED"
|
|
103
|
+
}
|
|
104
|
+
type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
|
|
105
|
+
declare enum ReminderFrequency {
|
|
106
|
+
ALWAYS = "always",
|
|
107
|
+
DAILY = "daily",
|
|
108
|
+
NEVER = "never"
|
|
109
|
+
}
|
|
110
|
+
interface TestInitResponse {
|
|
111
|
+
lexemePairs: ILexemePairRecord[];
|
|
112
|
+
vocabCheckType: VocabCheckType;
|
|
113
|
+
}
|
|
114
|
+
interface InsertOrUpdateResponse {
|
|
115
|
+
scenario: Scenario;
|
|
116
|
+
lexemePair: ILexemePairRecord;
|
|
117
|
+
newMappingInserted?: boolean;
|
|
118
|
+
}
|
|
119
|
+
declare enum ApiPath {
|
|
120
|
+
AUTOLOGIN = "/autologin",
|
|
121
|
+
HEALTH = "/health",
|
|
122
|
+
LEXEMES = "/lexemes",
|
|
123
|
+
LEXEMES_ALL = "/lexemes/all",
|
|
124
|
+
LEXEMES_COUNT = "/lexemes/count/:language",
|
|
125
|
+
LEXEMES_DELETE_ALL = "/lexemes/deleteAll",
|
|
126
|
+
LEXEMES_PAGE = "/lexemes/:length/:page",
|
|
127
|
+
LEXEME_PAIR = "/lexemePair/:czId/:enId",
|
|
128
|
+
LEXEME_PAIRS_BY_TEXT = "/lexemePairsByText/:inputText/:inputLang",
|
|
129
|
+
LEXEME_PAIR_FAMILIARITY = "/lexemePair/:czId/:enId/:familiarity",
|
|
130
|
+
SIGN_IN = "/signIn",
|
|
131
|
+
SIGN_OUT = "/signOut",
|
|
132
|
+
TEST_COMPLETE = "/test/complete",
|
|
133
|
+
TEST_INIT = "/test/init",
|
|
134
|
+
TRANSLATE = "/translate",
|
|
135
|
+
TRANSLATIONS_ALL = "/lexemes/allTranslations/:sourceText/:sourceLang",
|
|
136
|
+
USER = "/user",
|
|
137
|
+
USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked"
|
|
138
|
+
}
|
|
139
|
+
declare enum ApiMethod {
|
|
140
|
+
GET = "GET",
|
|
141
|
+
POST = "POST",
|
|
142
|
+
PUT = "PUT",
|
|
143
|
+
DELETE = "DELETE"
|
|
144
|
+
}
|
|
145
|
+
declare enum AppError {
|
|
146
|
+
NONE = "No error",
|
|
147
|
+
REQUEST_AUTOLOGIN_FAILED = "Failed to auto-login",
|
|
148
|
+
REQUEST_DELETE_ALL_USER_DATA_FAILED = "Failed to delete all user data",
|
|
149
|
+
REQUEST_DELETE_LEXEME_PAIR_FAILED = "Failed to delete lexeme pair",
|
|
150
|
+
REQUEST_SIGN_IN_FAILED = "Failed to sign in",
|
|
151
|
+
REQUEST_SIGN_OUT_FAILED = "Failed to sign out",
|
|
152
|
+
REQUEST_GET_LEXEMES_FAILED = "Failed to get lexemes",
|
|
153
|
+
REQUEST_GET_LEXEMES_FOR_TEST_FAILED = "Failed to get lexemes for test",
|
|
154
|
+
REQUEST_UPDATE_FAMILIARITY_FAILED = "Failed to update familiarity",
|
|
155
|
+
REQUEST_UPDATE_USER_SETTINGS_FAILED = "Failed to update user settings",
|
|
156
|
+
REQUEST_INSERT_OR_UPDATE_LEXEME_PAIR_FAILED = "Failed to insert or update lexeme pair",
|
|
157
|
+
REQUEST_TRANSLATION_FAILED = "Failed to get translation",
|
|
158
|
+
REQUEST_TEST_COMPLETE_FAILED = "Failed to complete test"
|
|
159
|
+
}
|
|
160
|
+
declare enum HttpStatusCode {
|
|
161
|
+
OK = 200,
|
|
162
|
+
BAD_REQUEST = 400,
|
|
163
|
+
UNAUTHORIZED = 401,
|
|
164
|
+
NOT_FOUND = 404,
|
|
165
|
+
TIMEOUT = 408,
|
|
166
|
+
ABORTED = 409,
|
|
167
|
+
INTERNAL_SERVER_ERROR = 500
|
|
168
|
+
}
|
|
169
|
+
interface ControllerResponse<T> {
|
|
170
|
+
message: string;
|
|
171
|
+
status: HttpStatusCode;
|
|
172
|
+
data: T;
|
|
173
|
+
}
|
|
174
|
+
interface ControllerResponse<T> {
|
|
175
|
+
message: string;
|
|
176
|
+
status: HttpStatusCode;
|
|
177
|
+
data: T;
|
|
178
|
+
}
|
|
179
|
+
type DeeplTranslation = {
|
|
180
|
+
detectedSourceLanguage: string;
|
|
181
|
+
translations: Array<{
|
|
182
|
+
translatedText: string;
|
|
183
|
+
}>;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* RowDataPacket types - Database query results
|
|
187
|
+
*/
|
|
188
|
+
interface MappedCzIds extends RowDataPacket {
|
|
189
|
+
czId: number;
|
|
190
|
+
}
|
|
191
|
+
interface MappedEnIds extends RowDataPacket {
|
|
192
|
+
enId: number;
|
|
193
|
+
}
|
|
194
|
+
interface DuplicateId extends RowDataPacket {
|
|
195
|
+
id: number;
|
|
196
|
+
}
|
|
197
|
+
interface InsertIdDataRecord extends RowDataPacket {
|
|
198
|
+
insertId: number;
|
|
199
|
+
}
|
|
200
|
+
interface UpdateDataRecord extends RowDataPacket {
|
|
201
|
+
}
|
|
202
|
+
interface UserRecord extends RowDataPacket {
|
|
203
|
+
id: number | undefined;
|
|
204
|
+
googleSub: string;
|
|
205
|
+
name: string;
|
|
206
|
+
email: string;
|
|
207
|
+
phone: string;
|
|
208
|
+
signUpDate: Date;
|
|
209
|
+
lastModified: Date;
|
|
210
|
+
learningLanguage: string;
|
|
211
|
+
flashcardReviewCompletedCount: number;
|
|
212
|
+
currentStreakLength: number;
|
|
213
|
+
currentStreakEnd: MySQLDate | undefined;
|
|
214
|
+
highStreakLength: number;
|
|
215
|
+
highStreakEnd: MySQLDate | undefined;
|
|
216
|
+
testsUnlocked: boolean;
|
|
217
|
+
rewardPoints: number;
|
|
218
|
+
}
|
|
219
|
+
interface CountRecord extends RowDataPacket {
|
|
220
|
+
count: number;
|
|
221
|
+
}
|
|
222
|
+
interface LastWordsAddedRecord extends RowDataPacket {
|
|
223
|
+
czText: string;
|
|
224
|
+
enText: string;
|
|
225
|
+
}
|
|
226
|
+
declare enum Scenario {
|
|
227
|
+
S1_INSERT_HAPPY_PATH = "Insert, happy path",
|
|
228
|
+
S2_INSERT_ENGLISH_LEXEME_AND_MAPPING_DUPLICATE_CZECH_LEXEME_FOUND_AND_USED = "Insert English lexeme and mapping, duplicate Czech lexeme found and used",
|
|
229
|
+
S3_INSERT_CZECH_LEXEME_AND_MAPPING_DUPLICATE_ENGLISH_LEXEME_FOUND_AND_USED = "Insert Czech lexeme and mapping, duplicate English lexeme found and used",
|
|
230
|
+
S4_INSERT_MAPPING_ONLY_DUPLICATE_CZECH_AND_ENGLISH_LEXEMES_FOUND_AND_USED = "Insert mapping only, duplicate Czech and English lexemes found and used",
|
|
231
|
+
S5_NO_INSERT_REQUIRED_DUPLICATE_LEXEMES_AND_PAIRING_FOUND = "No insert required, duplicate lexemes and pairing found",
|
|
232
|
+
S6_NO_UPDATE_REQUIRED_NO_CHANGES_DETECTED = "No update required, no changes detected",
|
|
233
|
+
S7_CZECH_LEXEME_UPDATED = "Scenario 7: Czech lexeme updated",
|
|
234
|
+
S8_CZECH_LEXEME_DELETED_DUPLICATE_CZECH_LEXEME_CAN_BE_USED = "Scenario 8: Czech lexeme deleted, duplicate Czech lexeme can be used can be used",
|
|
235
|
+
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",
|
|
236
|
+
S10_MAPPING_UPDATED_TO_USE_NEW_CZECH_LEXEME = "Scenario 10: Mapping updated to use new Czech lexeme",
|
|
237
|
+
S11_MAPPING_UPDATED_TO_USE_DUPLICATE_CZECH_LEXEME = "Scenario 11: Mapping updated to use duplicate Czech lexeme",
|
|
238
|
+
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",
|
|
239
|
+
S13_ENGLISH_LEXEME_UPDATED = "Scenario 13: English lexeme updated",
|
|
240
|
+
S14_ENGLISH_LEXEME_DELETED_DUPLICATE_ENGLISH_LEXEME_CAN_BE_USED = "Scenario 14: English lexeme deleted, duplicate English lexeme can be used",
|
|
241
|
+
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",
|
|
242
|
+
S16_MAPPING_UPDATED_TO_USE_NEW_ENGLISH_LEXEME = "Scenario 16: Mapping updated to use new English lexeme",
|
|
243
|
+
S17_MAPPING_UPDATED_TO_USE_DUPLICATE_ENGLISH_LEXEME = "Scenario 17: Mapping updated to use duplicate English lexeme",
|
|
244
|
+
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",
|
|
245
|
+
ERROR = "Error"
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @name convertJSDateObjectToMySQLDateString
|
|
250
|
+
* @description Converts a JavaScript Date object to a MySQL date string
|
|
251
|
+
* @param date
|
|
252
|
+
* @type Date
|
|
253
|
+
* @returns MySQLDate in the format "2021-01-01 07:41:23"
|
|
254
|
+
*/
|
|
255
|
+
declare const convertJSDateObjectToMySQLDateString: (date: Date) => MySQLDate | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* @name convertJSDateStringToMySQLDate
|
|
258
|
+
* @description Converts a JavaScript Date object to a MySQL date string
|
|
259
|
+
* @param date in the format "2021-01-01T07:41:23.000Z"
|
|
260
|
+
* @type string
|
|
261
|
+
* @returns date in the format "2021-01-01 07:41:23"
|
|
262
|
+
* @returns undefined if the input date is invalid
|
|
263
|
+
*/
|
|
264
|
+
declare const convertJSDateStringToMySQLDate: (date: string) => MySQLDate | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* @name isValidMysqlDateString
|
|
267
|
+
* @description Checks if a string representation of date/time is in the format "2021-01-01 07:41:23"
|
|
268
|
+
* @param dateStr
|
|
269
|
+
* @returns boolean
|
|
270
|
+
*/
|
|
271
|
+
declare const isValidMysqlDateString: (dateStr: string) => boolean;
|
|
272
|
+
/**
|
|
273
|
+
* @name isValidJsDateString
|
|
274
|
+
* @description Checks if a string representation of date/time is in the format "2021-01-01T07:41:23.000Z"
|
|
275
|
+
* @param dateStr
|
|
276
|
+
* @returns boolean
|
|
277
|
+
*/
|
|
278
|
+
declare const isValidJsDateString: (dateStr: string) => boolean;
|
|
279
|
+
/**
|
|
280
|
+
* @name isClientDateTooFarFromServerDate
|
|
281
|
+
* @description Checks if the client date is more than one day away from the server date
|
|
282
|
+
* @param clientDateMySQLFormat date in MySQL format
|
|
283
|
+
* @param serverDate date object representation of the current time on the server
|
|
284
|
+
* @returns boolean
|
|
285
|
+
*/
|
|
286
|
+
declare const isClientDateTooFarFromServerDate: (clientDateMySQLFormat: MySQLDate, serverDate: Date) => boolean;
|
|
287
|
+
/**
|
|
288
|
+
* @name dateDifferenceInDays
|
|
289
|
+
* @description Calculates the difference in days between two dates and returns a positive integer
|
|
290
|
+
* if the first date is before the second date, and a negative integer if the first date is after the second date
|
|
291
|
+
* @param date1 date in MySQL format
|
|
292
|
+
* @param date2 date in MySQL format
|
|
293
|
+
* @returns number
|
|
294
|
+
*/
|
|
295
|
+
declare const dateDifferenceInDays: (date1: MySQLDate, date2: MySQLDate) => number;
|
|
296
|
+
declare const getClientDate: (date: Date) => string;
|
|
297
|
+
declare const isThePreviousDay: (date: MySQLDate, referenceDate: MySQLDate) => boolean;
|
|
298
|
+
declare const isTheSameDay: (date1: MySQLDate, date2: MySQLDate) => boolean;
|
|
299
|
+
declare const getFormattedDate: (date: Date) => string;
|
|
300
|
+
|
|
301
|
+
type UserData = {
|
|
302
|
+
googleSub: string;
|
|
303
|
+
name: string;
|
|
304
|
+
email: string;
|
|
305
|
+
phone: string;
|
|
306
|
+
signUpDate: MySQLDate;
|
|
307
|
+
lastModified: MySQLDate;
|
|
308
|
+
learningLanguage: Language;
|
|
309
|
+
uiLanguage: Language;
|
|
310
|
+
testsCompletedCount: number;
|
|
311
|
+
currentStreakLength: number;
|
|
312
|
+
currentStreakEnd: MySQLDate;
|
|
313
|
+
highStreakLength: number;
|
|
314
|
+
highStreakEnd: MySQLDate;
|
|
315
|
+
testsUnlocked: boolean;
|
|
316
|
+
rewardPoints: number;
|
|
317
|
+
lastWordAdded: string;
|
|
318
|
+
lexemePairCount: number;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export { ApiMethod, ApiPath, AppError, type ControllerResponse, type CountRecord, type DeeplTranslation, type DuplicateId, Familiarity, HttpStatusCode, type ILexeme, type ILexemePair, type ILexemePairRecord, type ILexemeRecord, type InsertIdDataRecord, type InsertOrUpdateResponse, Language, type LastWordsAddedRecord, LearningStage, LexemePair, type LexemePairPayload, type LexemePairWithLang, type MappedCzIds, type MappedEnIds, type MySQLDate, ReminderFrequency, type Result, Scenario, type TestInitResponse, type UpdateDataRecord, type UserData, type UserRecord, VocabCheckType, convertJSDateObjectToMySQLDateString, convertJSDateStringToMySQLDate, dateDifferenceInDays, getClientDate, getFormattedDate, isClientDateTooFarFromServerDate, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString };
|