czapp-shared 1.0.8 → 1.0.10

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/dist/index.d.mts CHANGED
@@ -1,11 +1,16 @@
1
1
  /**
2
- * @name convertJSDateObjectToMySQLDateString
3
- * @description Converts a JavaScript Date object to a MySQL date string
2
+ * @name getMysqlDateIgnoreTZ
3
+ * @description Converts a JavaScript Date object to a MySQL date string by ignoring the timezone
4
4
  * @param date
5
5
  * @type Date
6
- * @returns MySQLDate in the format "2021-01-01 07:41:23"
6
+ * @returns MySQLDate in the format "2021-01-01 07:41:23" or undefined if the input date is invalid
7
7
  */
8
- declare const convertJSDateObjectToMySQLDateString: (date: Date) => MySQLDate | undefined;
8
+ declare const getMysqlDateIgnoreTZ: (date: Date) => MySQLDate | undefined;
9
+ /**
10
+ * @name getMysqlDateAllowingForTZ
11
+ * @param date
12
+ */
13
+ declare const getMysqlDateAllowingForTZ: (date: Date) => MySQLDate;
9
14
  /**
10
15
  * @name convertJSDateStringToMySQLDate
11
16
  * @description Converts a JavaScript Date object to a MySQL date string
@@ -46,14 +51,13 @@ declare const isClientDateTooFarFromServerDate: (clientDateMySQLFormat: MySQLDat
46
51
  * @returns number
47
52
  */
48
53
  declare const dateDifferenceInDays: (date1: MySQLDate, date2: MySQLDate) => number;
49
- declare const getClientDate: (date: Date) => string;
50
54
  declare const isThePreviousDay: (date: MySQLDate, referenceDate: MySQLDate) => boolean;
51
55
  declare const isTheSameDay: (date1: MySQLDate, date2: MySQLDate) => boolean;
52
56
  declare const getFormattedDate: (date: Date) => string;
53
57
 
54
58
  declare enum Language {
55
- CZECH = "cz",
56
- ENGLISH = "en",
59
+ CZECH = "CZECH",
60
+ ENGLISH = "ENGLISH",
57
61
  UNKNOWN = "UNKNOWN"
58
62
  }
59
63
  type Result<T> = [T, undefined] | [undefined, Error];
@@ -63,8 +67,8 @@ declare enum Familiarity {
63
67
  UNKNOWN = "UNKNOWN"
64
68
  }
65
69
  declare enum VocabCheckType {
66
- FLASHCARD = "flashcard",
67
- TEST = "test"
70
+ FLASHCARD = "FLASHCARD",
71
+ TEST = "TEST"
68
72
  }
69
73
  declare enum LearningStage {
70
74
  NEW = "NEW",
@@ -72,9 +76,9 @@ declare enum LearningStage {
72
76
  RETIRED = "RETIRED"
73
77
  }
74
78
  declare enum Progress {
75
- WORSE = 0,
76
- NONE = 1,
77
- IMPROVED = 2
79
+ WORSE = "WORSE",
80
+ NONE = "NONE",
81
+ IMPROVED = "IMPROVED"
78
82
  }
79
83
  interface ITestResult {
80
84
  lexemePair: ILexemePair;
@@ -83,9 +87,9 @@ interface ITestResult {
83
87
  }
84
88
  type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
85
89
  declare enum ReminderFrequency {
86
- ALWAYS = "always",
87
- DAILY = "daily",
88
- NEVER = "never"
90
+ ALWAYS = "ALWAYS",
91
+ DAILY = "DAILY",
92
+ NEVER = "NEVER"
89
93
  }
90
94
  declare enum AppError {
91
95
  NONE = "No error",
@@ -100,7 +104,8 @@ declare enum AppError {
100
104
  REQUEST_UPDATE_USER_SETTINGS_FAILED = "Failed to update user settings",
101
105
  REQUEST_INSERT_OR_UPDATE_LEXEME_PAIR_FAILED = "Failed to insert or update lexeme pair",
102
106
  REQUEST_TRANSLATION_FAILED = "Failed to get translation",
103
- REQUEST_TEST_COMPLETE_FAILED = "Failed to complete test"
107
+ REQUEST_TEST_COMPLETE_FAILED = "Failed to complete test",
108
+ REQUEST_TEST_SKIP_FAILED = "Failed to skip to the next deck"
104
109
  }
105
110
  declare enum Scenario {
106
111
  S1_INSERT_HAPPY_PATH = "Insert, happy path",
@@ -125,7 +130,7 @@ declare enum Scenario {
125
130
  }
126
131
 
127
132
  interface ILexeme {
128
- id: number | undefined;
133
+ id: number | null;
129
134
  dateAdded: MySQLDate;
130
135
  text: string;
131
136
  userId: string;
@@ -136,9 +141,9 @@ interface ILexemePair {
136
141
  englishLexeme: ILexeme;
137
142
  familiarity: Familiarity;
138
143
  firstKnownSessionDigit: number | null;
139
- lastFlashcardReview: MySQLDate;
144
+ lastFlashcardReview: MySQLDate | null;
140
145
  lastModified: MySQLDate;
141
- lastTested: MySQLDate;
146
+ lastTested: MySQLDate | null;
142
147
  learningStage: LearningStage;
143
148
  notes: string;
144
149
  userId: string;
@@ -155,13 +160,18 @@ type LexemePairWithLang = {
155
160
  interface ICount {
156
161
  count: number;
157
162
  }
163
+ interface ILexemeLearningInfo {
164
+ newCount: number;
165
+ learningCount: number;
166
+ retiredCount: number;
167
+ }
158
168
 
159
169
  declare class Lexeme implements ILexeme {
160
170
  text: string;
161
- id: number | undefined;
171
+ id: number | null;
162
172
  dateAdded: MySQLDate;
163
173
  userId: string;
164
- constructor();
174
+ constructor(userId: string);
165
175
  }
166
176
  declare class LexemePair implements ILexemePair {
167
177
  czechLexeme: ILexeme;
@@ -175,18 +185,12 @@ declare class LexemePair implements ILexemePair {
175
185
  learningStage: LearningStage;
176
186
  notes: string;
177
187
  userId: string;
178
- constructor(englishLexeme: Lexeme, czechLexeme: Lexeme);
188
+ constructor(userId: string, englishLexeme: Lexeme, czechLexeme: Lexeme);
179
189
  }
180
190
 
181
191
  declare const isStringContainingInteger: (str: any) => boolean;
182
192
  declare const parameterReplace: (path: string, params?: string[]) => string;
183
193
 
184
- declare enum Language$1 {
185
- CZECH = "cz",
186
- ENGLISH = "en",
187
- UNKNOWN = "UNKNOWN"
188
- }
189
-
190
194
  interface IUserData {
191
195
  currentStreakEnd: MySQLDate | undefined;
192
196
  currentStreakLength: number;
@@ -204,7 +208,6 @@ interface IUserData {
204
208
  rewardPoints: number;
205
209
  signUpDate: MySQLDate;
206
210
  testsCompletedCount: number;
207
- testsUnlocked: boolean;
208
211
  uiLanguage: Language;
209
212
  }
210
213
 
@@ -238,10 +241,11 @@ declare enum ApiPath {
238
241
  SIGN_OUT = "/signOut",
239
242
  TEST_COMPLETE = "/test/complete",
240
243
  TEST_INIT = "/test/init",
244
+ TEST_SKIP_DECK = "/test/skipDeck",
241
245
  TRANSLATE = "/translate",
242
246
  TRANSLATIONS_ALL = "/lexemes/allTranslations/:sourceText/:sourceLang",
243
247
  USER = "/user",
244
- USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked"
248
+ USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd"
245
249
  }
246
250
  /**
247
251
  * Request payloads
@@ -252,12 +256,12 @@ interface TestInitRequestBody {
252
256
  interface TestCompleteRequestBody {
253
257
  clientDate: MySQLDate;
254
258
  results: ITestResult[];
255
- vocabCheckType: string;
259
+ vocabCheckType: VocabCheckType;
256
260
  }
257
261
  interface TranslationRequestBody {
258
262
  q: string;
259
- source: Language$1;
260
- target: Language$1;
263
+ source: Language;
264
+ target: Language;
261
265
  }
262
266
  type LexemePairRequestBody = {
263
267
  czLexeme: ILexeme;
@@ -265,8 +269,8 @@ type LexemePairRequestBody = {
265
269
  pairingNotes: string;
266
270
  };
267
271
  interface UpdateUserRequestBody {
268
- learningLanguage: Language$1;
269
- uiLanguage: Language$1;
272
+ learningLanguage: Language;
273
+ uiLanguage: Language;
270
274
  }
271
275
  interface AutologinRequestBody {
272
276
  clientDate: MySQLDate;
@@ -284,39 +288,39 @@ interface SignInRequestBody {
284
288
  */
285
289
  interface SelectAllTranslationsParams {
286
290
  sourceText: string;
287
- sourceLang: string;
291
+ sourceLang: Language;
288
292
  }
289
293
  interface SelectLexemeCountParams {
290
- language: Language$1;
294
+ language: Language;
291
295
  }
292
296
  interface SelectLexemePairParams {
293
- czId: string;
294
- enId: string;
297
+ czId: number;
298
+ enId: number;
295
299
  }
296
300
  interface SelectLexemePairsByTextParams {
297
301
  inputText: string;
298
- inputLang: string;
302
+ inputLang: Language;
299
303
  }
300
304
  interface SelectLexemesParams {
301
- page: string;
302
- length: string;
305
+ page: number;
306
+ length: number;
303
307
  }
304
308
  interface SelectTestLexemesParams {
305
- testType: string;
306
- testLength: string;
309
+ testType: VocabCheckType;
310
+ testLength: number;
307
311
  }
308
312
  interface UpdateLexemePairFamiliarityParams {
309
- czId: string;
310
- enId: string;
311
- familiarity: string;
313
+ czId: number;
314
+ enId: number;
315
+ familiarity: Familiarity;
312
316
  }
313
317
  interface DeleteLexemePairRequestParams {
314
- czId: string;
315
- enId: string;
318
+ czId: number;
319
+ enId: number;
316
320
  }
317
321
  interface ResetTestUserParams {
318
322
  flashcardReviewCompletedCount: number;
319
- testsUnlocked: boolean;
323
+ currentStreakEnd: MySQLDate;
320
324
  }
321
325
  /**
322
326
  * Response payloads
@@ -327,7 +331,7 @@ interface ControllerResponse<T> {
327
331
  data: T;
328
332
  }
329
333
  type TranslationResponseData = {
330
- detectedSourceLanguage: string;
334
+ detectedSourceLanguage: Language;
331
335
  translations: Array<{
332
336
  translatedText: string;
333
337
  }>;
@@ -343,6 +347,7 @@ interface SignInResponseData {
343
347
  }
344
348
  interface TestInitResponseData {
345
349
  lexemePairs: ILexemePair[];
350
+ lexemeLearningInfo: ILexemeLearningInfo;
346
351
  vocabCheckType: VocabCheckType;
347
352
  }
348
353
  interface TestCompleteResponseData {
@@ -351,10 +356,10 @@ interface TestCompleteResponseData {
351
356
  rewardPointsDelta: number;
352
357
  }
353
358
  type DeeplTranslation = {
354
- detectedSourceLanguage: string;
359
+ detectedSourceLanguage: Language;
355
360
  translations: Array<{
356
361
  translatedText: string;
357
362
  }>;
358
363
  };
359
364
 
360
- export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, type ControllerResponse, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, HttpStatusCode, type ICount, type ILexeme, type ILexemeIdPair, type ILexemePair, type ITestResult, type IUserData, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, ReminderFrequency, type ResetTestUserParams, type Result, Scenario, type SelectAllTranslationsParams, type SelectLexemeCountParams, type SelectLexemePairParams, type SelectLexemePairsByTextParams, type SelectLexemesParams, type SelectTestLexemesParams, type SignInRequestBody, type SignInResponseData, type TestCompleteRequestBody, type TestCompleteResponseData, type TestInitRequestBody, type TestInitResponseData, type TranslationRequestBody, type TranslationResponseData, type UpdateLexemePairFamiliarityParams, type UpdateUserRequestBody, VocabCheckType, convertJSDateObjectToMySQLDateString, convertJSDateStringToMySQLDate, dateDifferenceInDays, getClientDate, getFormattedDate, isClientDateTooFarFromServerDate, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
365
+ export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, type ControllerResponse, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, HttpStatusCode, type ICount, type ILexeme, type ILexemeIdPair, type ILexemeLearningInfo, type ILexemePair, type ITestResult, type IUserData, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, ReminderFrequency, type ResetTestUserParams, type Result, Scenario, type SelectAllTranslationsParams, type SelectLexemeCountParams, type SelectLexemePairParams, type SelectLexemePairsByTextParams, type SelectLexemesParams, type SelectTestLexemesParams, type SignInRequestBody, type SignInResponseData, type TestCompleteRequestBody, type TestCompleteResponseData, type TestInitRequestBody, type TestInitResponseData, type TranslationRequestBody, type TranslationResponseData, type UpdateLexemePairFamiliarityParams, type UpdateUserRequestBody, VocabCheckType, convertJSDateStringToMySQLDate, dateDifferenceInDays, getFormattedDate, getMysqlDateAllowingForTZ, getMysqlDateIgnoreTZ, isClientDateTooFarFromServerDate, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,16 @@
1
1
  /**
2
- * @name convertJSDateObjectToMySQLDateString
3
- * @description Converts a JavaScript Date object to a MySQL date string
2
+ * @name getMysqlDateIgnoreTZ
3
+ * @description Converts a JavaScript Date object to a MySQL date string by ignoring the timezone
4
4
  * @param date
5
5
  * @type Date
6
- * @returns MySQLDate in the format "2021-01-01 07:41:23"
6
+ * @returns MySQLDate in the format "2021-01-01 07:41:23" or undefined if the input date is invalid
7
7
  */
8
- declare const convertJSDateObjectToMySQLDateString: (date: Date) => MySQLDate | undefined;
8
+ declare const getMysqlDateIgnoreTZ: (date: Date) => MySQLDate | undefined;
9
+ /**
10
+ * @name getMysqlDateAllowingForTZ
11
+ * @param date
12
+ */
13
+ declare const getMysqlDateAllowingForTZ: (date: Date) => MySQLDate;
9
14
  /**
10
15
  * @name convertJSDateStringToMySQLDate
11
16
  * @description Converts a JavaScript Date object to a MySQL date string
@@ -46,14 +51,13 @@ declare const isClientDateTooFarFromServerDate: (clientDateMySQLFormat: MySQLDat
46
51
  * @returns number
47
52
  */
48
53
  declare const dateDifferenceInDays: (date1: MySQLDate, date2: MySQLDate) => number;
49
- declare const getClientDate: (date: Date) => string;
50
54
  declare const isThePreviousDay: (date: MySQLDate, referenceDate: MySQLDate) => boolean;
51
55
  declare const isTheSameDay: (date1: MySQLDate, date2: MySQLDate) => boolean;
52
56
  declare const getFormattedDate: (date: Date) => string;
53
57
 
54
58
  declare enum Language {
55
- CZECH = "cz",
56
- ENGLISH = "en",
59
+ CZECH = "CZECH",
60
+ ENGLISH = "ENGLISH",
57
61
  UNKNOWN = "UNKNOWN"
58
62
  }
59
63
  type Result<T> = [T, undefined] | [undefined, Error];
@@ -63,8 +67,8 @@ declare enum Familiarity {
63
67
  UNKNOWN = "UNKNOWN"
64
68
  }
65
69
  declare enum VocabCheckType {
66
- FLASHCARD = "flashcard",
67
- TEST = "test"
70
+ FLASHCARD = "FLASHCARD",
71
+ TEST = "TEST"
68
72
  }
69
73
  declare enum LearningStage {
70
74
  NEW = "NEW",
@@ -72,9 +76,9 @@ declare enum LearningStage {
72
76
  RETIRED = "RETIRED"
73
77
  }
74
78
  declare enum Progress {
75
- WORSE = 0,
76
- NONE = 1,
77
- IMPROVED = 2
79
+ WORSE = "WORSE",
80
+ NONE = "NONE",
81
+ IMPROVED = "IMPROVED"
78
82
  }
79
83
  interface ITestResult {
80
84
  lexemePair: ILexemePair;
@@ -83,9 +87,9 @@ interface ITestResult {
83
87
  }
84
88
  type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
85
89
  declare enum ReminderFrequency {
86
- ALWAYS = "always",
87
- DAILY = "daily",
88
- NEVER = "never"
90
+ ALWAYS = "ALWAYS",
91
+ DAILY = "DAILY",
92
+ NEVER = "NEVER"
89
93
  }
90
94
  declare enum AppError {
91
95
  NONE = "No error",
@@ -100,7 +104,8 @@ declare enum AppError {
100
104
  REQUEST_UPDATE_USER_SETTINGS_FAILED = "Failed to update user settings",
101
105
  REQUEST_INSERT_OR_UPDATE_LEXEME_PAIR_FAILED = "Failed to insert or update lexeme pair",
102
106
  REQUEST_TRANSLATION_FAILED = "Failed to get translation",
103
- REQUEST_TEST_COMPLETE_FAILED = "Failed to complete test"
107
+ REQUEST_TEST_COMPLETE_FAILED = "Failed to complete test",
108
+ REQUEST_TEST_SKIP_FAILED = "Failed to skip to the next deck"
104
109
  }
105
110
  declare enum Scenario {
106
111
  S1_INSERT_HAPPY_PATH = "Insert, happy path",
@@ -125,7 +130,7 @@ declare enum Scenario {
125
130
  }
126
131
 
127
132
  interface ILexeme {
128
- id: number | undefined;
133
+ id: number | null;
129
134
  dateAdded: MySQLDate;
130
135
  text: string;
131
136
  userId: string;
@@ -136,9 +141,9 @@ interface ILexemePair {
136
141
  englishLexeme: ILexeme;
137
142
  familiarity: Familiarity;
138
143
  firstKnownSessionDigit: number | null;
139
- lastFlashcardReview: MySQLDate;
144
+ lastFlashcardReview: MySQLDate | null;
140
145
  lastModified: MySQLDate;
141
- lastTested: MySQLDate;
146
+ lastTested: MySQLDate | null;
142
147
  learningStage: LearningStage;
143
148
  notes: string;
144
149
  userId: string;
@@ -155,13 +160,18 @@ type LexemePairWithLang = {
155
160
  interface ICount {
156
161
  count: number;
157
162
  }
163
+ interface ILexemeLearningInfo {
164
+ newCount: number;
165
+ learningCount: number;
166
+ retiredCount: number;
167
+ }
158
168
 
159
169
  declare class Lexeme implements ILexeme {
160
170
  text: string;
161
- id: number | undefined;
171
+ id: number | null;
162
172
  dateAdded: MySQLDate;
163
173
  userId: string;
164
- constructor();
174
+ constructor(userId: string);
165
175
  }
166
176
  declare class LexemePair implements ILexemePair {
167
177
  czechLexeme: ILexeme;
@@ -175,18 +185,12 @@ declare class LexemePair implements ILexemePair {
175
185
  learningStage: LearningStage;
176
186
  notes: string;
177
187
  userId: string;
178
- constructor(englishLexeme: Lexeme, czechLexeme: Lexeme);
188
+ constructor(userId: string, englishLexeme: Lexeme, czechLexeme: Lexeme);
179
189
  }
180
190
 
181
191
  declare const isStringContainingInteger: (str: any) => boolean;
182
192
  declare const parameterReplace: (path: string, params?: string[]) => string;
183
193
 
184
- declare enum Language$1 {
185
- CZECH = "cz",
186
- ENGLISH = "en",
187
- UNKNOWN = "UNKNOWN"
188
- }
189
-
190
194
  interface IUserData {
191
195
  currentStreakEnd: MySQLDate | undefined;
192
196
  currentStreakLength: number;
@@ -204,7 +208,6 @@ interface IUserData {
204
208
  rewardPoints: number;
205
209
  signUpDate: MySQLDate;
206
210
  testsCompletedCount: number;
207
- testsUnlocked: boolean;
208
211
  uiLanguage: Language;
209
212
  }
210
213
 
@@ -238,10 +241,11 @@ declare enum ApiPath {
238
241
  SIGN_OUT = "/signOut",
239
242
  TEST_COMPLETE = "/test/complete",
240
243
  TEST_INIT = "/test/init",
244
+ TEST_SKIP_DECK = "/test/skipDeck",
241
245
  TRANSLATE = "/translate",
242
246
  TRANSLATIONS_ALL = "/lexemes/allTranslations/:sourceText/:sourceLang",
243
247
  USER = "/user",
244
- USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked"
248
+ USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd"
245
249
  }
246
250
  /**
247
251
  * Request payloads
@@ -252,12 +256,12 @@ interface TestInitRequestBody {
252
256
  interface TestCompleteRequestBody {
253
257
  clientDate: MySQLDate;
254
258
  results: ITestResult[];
255
- vocabCheckType: string;
259
+ vocabCheckType: VocabCheckType;
256
260
  }
257
261
  interface TranslationRequestBody {
258
262
  q: string;
259
- source: Language$1;
260
- target: Language$1;
263
+ source: Language;
264
+ target: Language;
261
265
  }
262
266
  type LexemePairRequestBody = {
263
267
  czLexeme: ILexeme;
@@ -265,8 +269,8 @@ type LexemePairRequestBody = {
265
269
  pairingNotes: string;
266
270
  };
267
271
  interface UpdateUserRequestBody {
268
- learningLanguage: Language$1;
269
- uiLanguage: Language$1;
272
+ learningLanguage: Language;
273
+ uiLanguage: Language;
270
274
  }
271
275
  interface AutologinRequestBody {
272
276
  clientDate: MySQLDate;
@@ -284,39 +288,39 @@ interface SignInRequestBody {
284
288
  */
285
289
  interface SelectAllTranslationsParams {
286
290
  sourceText: string;
287
- sourceLang: string;
291
+ sourceLang: Language;
288
292
  }
289
293
  interface SelectLexemeCountParams {
290
- language: Language$1;
294
+ language: Language;
291
295
  }
292
296
  interface SelectLexemePairParams {
293
- czId: string;
294
- enId: string;
297
+ czId: number;
298
+ enId: number;
295
299
  }
296
300
  interface SelectLexemePairsByTextParams {
297
301
  inputText: string;
298
- inputLang: string;
302
+ inputLang: Language;
299
303
  }
300
304
  interface SelectLexemesParams {
301
- page: string;
302
- length: string;
305
+ page: number;
306
+ length: number;
303
307
  }
304
308
  interface SelectTestLexemesParams {
305
- testType: string;
306
- testLength: string;
309
+ testType: VocabCheckType;
310
+ testLength: number;
307
311
  }
308
312
  interface UpdateLexemePairFamiliarityParams {
309
- czId: string;
310
- enId: string;
311
- familiarity: string;
313
+ czId: number;
314
+ enId: number;
315
+ familiarity: Familiarity;
312
316
  }
313
317
  interface DeleteLexemePairRequestParams {
314
- czId: string;
315
- enId: string;
318
+ czId: number;
319
+ enId: number;
316
320
  }
317
321
  interface ResetTestUserParams {
318
322
  flashcardReviewCompletedCount: number;
319
- testsUnlocked: boolean;
323
+ currentStreakEnd: MySQLDate;
320
324
  }
321
325
  /**
322
326
  * Response payloads
@@ -327,7 +331,7 @@ interface ControllerResponse<T> {
327
331
  data: T;
328
332
  }
329
333
  type TranslationResponseData = {
330
- detectedSourceLanguage: string;
334
+ detectedSourceLanguage: Language;
331
335
  translations: Array<{
332
336
  translatedText: string;
333
337
  }>;
@@ -343,6 +347,7 @@ interface SignInResponseData {
343
347
  }
344
348
  interface TestInitResponseData {
345
349
  lexemePairs: ILexemePair[];
350
+ lexemeLearningInfo: ILexemeLearningInfo;
346
351
  vocabCheckType: VocabCheckType;
347
352
  }
348
353
  interface TestCompleteResponseData {
@@ -351,10 +356,10 @@ interface TestCompleteResponseData {
351
356
  rewardPointsDelta: number;
352
357
  }
353
358
  type DeeplTranslation = {
354
- detectedSourceLanguage: string;
359
+ detectedSourceLanguage: Language;
355
360
  translations: Array<{
356
361
  translatedText: string;
357
362
  }>;
358
363
  };
359
364
 
360
- export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, type ControllerResponse, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, HttpStatusCode, type ICount, type ILexeme, type ILexemeIdPair, type ILexemePair, type ITestResult, type IUserData, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, ReminderFrequency, type ResetTestUserParams, type Result, Scenario, type SelectAllTranslationsParams, type SelectLexemeCountParams, type SelectLexemePairParams, type SelectLexemePairsByTextParams, type SelectLexemesParams, type SelectTestLexemesParams, type SignInRequestBody, type SignInResponseData, type TestCompleteRequestBody, type TestCompleteResponseData, type TestInitRequestBody, type TestInitResponseData, type TranslationRequestBody, type TranslationResponseData, type UpdateLexemePairFamiliarityParams, type UpdateUserRequestBody, VocabCheckType, convertJSDateObjectToMySQLDateString, convertJSDateStringToMySQLDate, dateDifferenceInDays, getClientDate, getFormattedDate, isClientDateTooFarFromServerDate, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
365
+ export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, type ControllerResponse, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, HttpStatusCode, type ICount, type ILexeme, type ILexemeIdPair, type ILexemeLearningInfo, type ILexemePair, type ITestResult, type IUserData, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, ReminderFrequency, type ResetTestUserParams, type Result, Scenario, type SelectAllTranslationsParams, type SelectLexemeCountParams, type SelectLexemePairParams, type SelectLexemePairsByTextParams, type SelectLexemesParams, type SelectTestLexemesParams, type SignInRequestBody, type SignInResponseData, type TestCompleteRequestBody, type TestCompleteResponseData, type TestInitRequestBody, type TestInitResponseData, type TranslationRequestBody, type TranslationResponseData, type UpdateLexemePairFamiliarityParams, type UpdateUserRequestBody, VocabCheckType, convertJSDateStringToMySQLDate, dateDifferenceInDays, getFormattedDate, getMysqlDateAllowingForTZ, getMysqlDateIgnoreTZ, isClientDateTooFarFromServerDate, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
package/dist/index.js CHANGED
@@ -32,11 +32,11 @@ __export(src_exports, {
32
32
  ReminderFrequency: () => ReminderFrequency,
33
33
  Scenario: () => Scenario,
34
34
  VocabCheckType: () => VocabCheckType,
35
- convertJSDateObjectToMySQLDateString: () => convertJSDateObjectToMySQLDateString,
36
35
  convertJSDateStringToMySQLDate: () => convertJSDateStringToMySQLDate,
37
36
  dateDifferenceInDays: () => dateDifferenceInDays,
38
- getClientDate: () => getClientDate,
39
37
  getFormattedDate: () => getFormattedDate,
38
+ getMysqlDateAllowingForTZ: () => getMysqlDateAllowingForTZ,
39
+ getMysqlDateIgnoreTZ: () => getMysqlDateIgnoreTZ,
40
40
  isClientDateTooFarFromServerDate: () => isClientDateTooFarFromServerDate,
41
41
  isStringContainingInteger: () => isStringContainingInteger,
42
42
  isThePreviousDay: () => isThePreviousDay,
@@ -48,7 +48,7 @@ __export(src_exports, {
48
48
  module.exports = __toCommonJS(src_exports);
49
49
 
50
50
  // src/concrete/date.ts
51
- var convertJSDateObjectToMySQLDateString = (date) => {
51
+ var getMysqlDateIgnoreTZ = (date) => {
52
52
  let dateStr;
53
53
  try {
54
54
  dateStr = date.toISOString().slice(0, 19).replace("T", " ");
@@ -61,6 +61,12 @@ var convertJSDateObjectToMySQLDateString = (date) => {
61
61
  return dateStr;
62
62
  }
63
63
  };
64
+ var getMysqlDateAllowingForTZ = (date) => {
65
+ const zeroPad = (num) => {
66
+ return num < 10 ? `0${num}` : num.toString();
67
+ };
68
+ return `${date.getFullYear()}-${zeroPad(date.getMonth() + 1)}-${zeroPad(date.getDate())} ${zeroPad(date.getHours())}:${zeroPad(date.getMinutes())}:${zeroPad(date.getSeconds())}`;
69
+ };
64
70
  var convertJSDateStringToMySQLDate = (date) => {
65
71
  let dateStr;
66
72
  try {
@@ -78,7 +84,7 @@ var isValidJsDateString = (dateStr) => {
78
84
  return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(dateStr);
79
85
  };
80
86
  var isClientDateTooFarFromServerDate = (clientDateMySQLFormat, serverDate) => {
81
- const serverDateMysqlFormat = convertJSDateObjectToMySQLDateString(serverDate);
87
+ const serverDateMysqlFormat = getMysqlDateIgnoreTZ(serverDate);
82
88
  if (!serverDateMysqlFormat) return true;
83
89
  return Math.abs(dateDifferenceInDays(clientDateMySQLFormat, serverDateMysqlFormat)) > 1;
84
90
  };
@@ -90,12 +96,6 @@ var dateDifferenceInDays = (date1, date2) => {
90
96
  const difference = dateObj_2.getTime() - dateObj_1.getTime();
91
97
  return difference / (1e3 * 3600 * 24);
92
98
  };
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
99
  var isThePreviousDay = (date, referenceDate) => {
100
100
  const previousDay = new Date(referenceDate);
101
101
  previousDay.setDate(new Date(referenceDate).getDate() - 1);
@@ -113,8 +113,8 @@ var getFormattedDate = (date) => {
113
113
 
114
114
  // src/design/types.ts
115
115
  var Language = /* @__PURE__ */ ((Language2) => {
116
- Language2["CZECH"] = "cz";
117
- Language2["ENGLISH"] = "en";
116
+ Language2["CZECH"] = "CZECH";
117
+ Language2["ENGLISH"] = "ENGLISH";
118
118
  Language2["UNKNOWN"] = "UNKNOWN";
119
119
  return Language2;
120
120
  })(Language || {});
@@ -125,8 +125,8 @@ var Familiarity = /* @__PURE__ */ ((Familiarity2) => {
125
125
  return Familiarity2;
126
126
  })(Familiarity || {});
127
127
  var VocabCheckType = /* @__PURE__ */ ((VocabCheckType2) => {
128
- VocabCheckType2["FLASHCARD"] = "flashcard";
129
- VocabCheckType2["TEST"] = "test";
128
+ VocabCheckType2["FLASHCARD"] = "FLASHCARD";
129
+ VocabCheckType2["TEST"] = "TEST";
130
130
  return VocabCheckType2;
131
131
  })(VocabCheckType || {});
132
132
  var LearningStage = /* @__PURE__ */ ((LearningStage2) => {
@@ -136,15 +136,15 @@ var LearningStage = /* @__PURE__ */ ((LearningStage2) => {
136
136
  return LearningStage2;
137
137
  })(LearningStage || {});
138
138
  var Progress = /* @__PURE__ */ ((Progress2) => {
139
- Progress2[Progress2["WORSE"] = 0] = "WORSE";
140
- Progress2[Progress2["NONE"] = 1] = "NONE";
141
- Progress2[Progress2["IMPROVED"] = 2] = "IMPROVED";
139
+ Progress2["WORSE"] = "WORSE";
140
+ Progress2["NONE"] = "NONE";
141
+ Progress2["IMPROVED"] = "IMPROVED";
142
142
  return Progress2;
143
143
  })(Progress || {});
144
144
  var ReminderFrequency = /* @__PURE__ */ ((ReminderFrequency2) => {
145
- ReminderFrequency2["ALWAYS"] = "always";
146
- ReminderFrequency2["DAILY"] = "daily";
147
- ReminderFrequency2["NEVER"] = "never";
145
+ ReminderFrequency2["ALWAYS"] = "ALWAYS";
146
+ ReminderFrequency2["DAILY"] = "DAILY";
147
+ ReminderFrequency2["NEVER"] = "NEVER";
148
148
  return ReminderFrequency2;
149
149
  })(ReminderFrequency || {});
150
150
  var AppError = /* @__PURE__ */ ((AppError2) => {
@@ -161,6 +161,7 @@ var AppError = /* @__PURE__ */ ((AppError2) => {
161
161
  AppError2["REQUEST_INSERT_OR_UPDATE_LEXEME_PAIR_FAILED"] = "Failed to insert or update lexeme pair";
162
162
  AppError2["REQUEST_TRANSLATION_FAILED"] = "Failed to get translation";
163
163
  AppError2["REQUEST_TEST_COMPLETE_FAILED"] = "Failed to complete test";
164
+ AppError2["REQUEST_TEST_SKIP_FAILED"] = "Failed to skip to the next deck";
164
165
  return AppError2;
165
166
  })(AppError || {});
166
167
  var Scenario = /* @__PURE__ */ ((Scenario2) => {
@@ -188,19 +189,21 @@ var Scenario = /* @__PURE__ */ ((Scenario2) => {
188
189
 
189
190
  // src/concrete/lexeme.ts
190
191
  var Lexeme = class {
191
- constructor() {
192
+ constructor(userId) {
192
193
  this.text = "";
193
- this.id = void 0;
194
+ this.id = null;
194
195
  this.userId = "";
195
- this.dateAdded = convertJSDateObjectToMySQLDateString(/* @__PURE__ */ new Date());
196
+ this.userId = userId;
197
+ this.dateAdded = getMysqlDateIgnoreTZ(/* @__PURE__ */ new Date());
196
198
  }
197
199
  };
198
200
  var LexemePair = class {
199
- constructor(englishLexeme, czechLexeme) {
201
+ constructor(userId, englishLexeme, czechLexeme) {
200
202
  this.familiarity = "UNKNOWN" /* UNKNOWN */;
201
203
  this.learningStage = "NEW" /* NEW */;
202
204
  this.notes = "";
203
205
  this.userId = "";
206
+ this.userId = userId;
204
207
  this.czechLexeme = czechLexeme;
205
208
  this.englishLexeme = englishLexeme;
206
209
  }
@@ -249,10 +252,11 @@ var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
249
252
  ApiPath2["SIGN_OUT"] = "/signOut";
250
253
  ApiPath2["TEST_COMPLETE"] = "/test/complete";
251
254
  ApiPath2["TEST_INIT"] = "/test/init";
255
+ ApiPath2["TEST_SKIP_DECK"] = "/test/skipDeck";
252
256
  ApiPath2["TRANSLATE"] = "/translate";
253
257
  ApiPath2["TRANSLATIONS_ALL"] = "/lexemes/allTranslations/:sourceText/:sourceLang";
254
258
  ApiPath2["USER"] = "/user";
255
- ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked";
259
+ ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd";
256
260
  return ApiPath2;
257
261
  })(ApiPath || {});
258
262
  // Annotate the CommonJS export names for ESM import in node:
@@ -270,11 +274,11 @@ var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
270
274
  ReminderFrequency,
271
275
  Scenario,
272
276
  VocabCheckType,
273
- convertJSDateObjectToMySQLDateString,
274
277
  convertJSDateStringToMySQLDate,
275
278
  dateDifferenceInDays,
276
- getClientDate,
277
279
  getFormattedDate,
280
+ getMysqlDateAllowingForTZ,
281
+ getMysqlDateIgnoreTZ,
278
282
  isClientDateTooFarFromServerDate,
279
283
  isStringContainingInteger,
280
284
  isThePreviousDay,
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/concrete/date.ts
2
- var convertJSDateObjectToMySQLDateString = (date) => {
2
+ var getMysqlDateIgnoreTZ = (date) => {
3
3
  let dateStr;
4
4
  try {
5
5
  dateStr = date.toISOString().slice(0, 19).replace("T", " ");
@@ -12,6 +12,12 @@ var convertJSDateObjectToMySQLDateString = (date) => {
12
12
  return dateStr;
13
13
  }
14
14
  };
15
+ var getMysqlDateAllowingForTZ = (date) => {
16
+ const zeroPad = (num) => {
17
+ return num < 10 ? `0${num}` : num.toString();
18
+ };
19
+ return `${date.getFullYear()}-${zeroPad(date.getMonth() + 1)}-${zeroPad(date.getDate())} ${zeroPad(date.getHours())}:${zeroPad(date.getMinutes())}:${zeroPad(date.getSeconds())}`;
20
+ };
15
21
  var convertJSDateStringToMySQLDate = (date) => {
16
22
  let dateStr;
17
23
  try {
@@ -29,7 +35,7 @@ var isValidJsDateString = (dateStr) => {
29
35
  return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(dateStr);
30
36
  };
31
37
  var isClientDateTooFarFromServerDate = (clientDateMySQLFormat, serverDate) => {
32
- const serverDateMysqlFormat = convertJSDateObjectToMySQLDateString(serverDate);
38
+ const serverDateMysqlFormat = getMysqlDateIgnoreTZ(serverDate);
33
39
  if (!serverDateMysqlFormat) return true;
34
40
  return Math.abs(dateDifferenceInDays(clientDateMySQLFormat, serverDateMysqlFormat)) > 1;
35
41
  };
@@ -41,12 +47,6 @@ var dateDifferenceInDays = (date1, date2) => {
41
47
  const difference = dateObj_2.getTime() - dateObj_1.getTime();
42
48
  return difference / (1e3 * 3600 * 24);
43
49
  };
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
50
  var isThePreviousDay = (date, referenceDate) => {
51
51
  const previousDay = new Date(referenceDate);
52
52
  previousDay.setDate(new Date(referenceDate).getDate() - 1);
@@ -64,8 +64,8 @@ var getFormattedDate = (date) => {
64
64
 
65
65
  // src/design/types.ts
66
66
  var Language = /* @__PURE__ */ ((Language2) => {
67
- Language2["CZECH"] = "cz";
68
- Language2["ENGLISH"] = "en";
67
+ Language2["CZECH"] = "CZECH";
68
+ Language2["ENGLISH"] = "ENGLISH";
69
69
  Language2["UNKNOWN"] = "UNKNOWN";
70
70
  return Language2;
71
71
  })(Language || {});
@@ -76,8 +76,8 @@ var Familiarity = /* @__PURE__ */ ((Familiarity2) => {
76
76
  return Familiarity2;
77
77
  })(Familiarity || {});
78
78
  var VocabCheckType = /* @__PURE__ */ ((VocabCheckType2) => {
79
- VocabCheckType2["FLASHCARD"] = "flashcard";
80
- VocabCheckType2["TEST"] = "test";
79
+ VocabCheckType2["FLASHCARD"] = "FLASHCARD";
80
+ VocabCheckType2["TEST"] = "TEST";
81
81
  return VocabCheckType2;
82
82
  })(VocabCheckType || {});
83
83
  var LearningStage = /* @__PURE__ */ ((LearningStage2) => {
@@ -87,15 +87,15 @@ var LearningStage = /* @__PURE__ */ ((LearningStage2) => {
87
87
  return LearningStage2;
88
88
  })(LearningStage || {});
89
89
  var Progress = /* @__PURE__ */ ((Progress2) => {
90
- Progress2[Progress2["WORSE"] = 0] = "WORSE";
91
- Progress2[Progress2["NONE"] = 1] = "NONE";
92
- Progress2[Progress2["IMPROVED"] = 2] = "IMPROVED";
90
+ Progress2["WORSE"] = "WORSE";
91
+ Progress2["NONE"] = "NONE";
92
+ Progress2["IMPROVED"] = "IMPROVED";
93
93
  return Progress2;
94
94
  })(Progress || {});
95
95
  var ReminderFrequency = /* @__PURE__ */ ((ReminderFrequency2) => {
96
- ReminderFrequency2["ALWAYS"] = "always";
97
- ReminderFrequency2["DAILY"] = "daily";
98
- ReminderFrequency2["NEVER"] = "never";
96
+ ReminderFrequency2["ALWAYS"] = "ALWAYS";
97
+ ReminderFrequency2["DAILY"] = "DAILY";
98
+ ReminderFrequency2["NEVER"] = "NEVER";
99
99
  return ReminderFrequency2;
100
100
  })(ReminderFrequency || {});
101
101
  var AppError = /* @__PURE__ */ ((AppError2) => {
@@ -112,6 +112,7 @@ var AppError = /* @__PURE__ */ ((AppError2) => {
112
112
  AppError2["REQUEST_INSERT_OR_UPDATE_LEXEME_PAIR_FAILED"] = "Failed to insert or update lexeme pair";
113
113
  AppError2["REQUEST_TRANSLATION_FAILED"] = "Failed to get translation";
114
114
  AppError2["REQUEST_TEST_COMPLETE_FAILED"] = "Failed to complete test";
115
+ AppError2["REQUEST_TEST_SKIP_FAILED"] = "Failed to skip to the next deck";
115
116
  return AppError2;
116
117
  })(AppError || {});
117
118
  var Scenario = /* @__PURE__ */ ((Scenario2) => {
@@ -139,19 +140,21 @@ var Scenario = /* @__PURE__ */ ((Scenario2) => {
139
140
 
140
141
  // src/concrete/lexeme.ts
141
142
  var Lexeme = class {
142
- constructor() {
143
+ constructor(userId) {
143
144
  this.text = "";
144
- this.id = void 0;
145
+ this.id = null;
145
146
  this.userId = "";
146
- this.dateAdded = convertJSDateObjectToMySQLDateString(/* @__PURE__ */ new Date());
147
+ this.userId = userId;
148
+ this.dateAdded = getMysqlDateIgnoreTZ(/* @__PURE__ */ new Date());
147
149
  }
148
150
  };
149
151
  var LexemePair = class {
150
- constructor(englishLexeme, czechLexeme) {
152
+ constructor(userId, englishLexeme, czechLexeme) {
151
153
  this.familiarity = "UNKNOWN" /* UNKNOWN */;
152
154
  this.learningStage = "NEW" /* NEW */;
153
155
  this.notes = "";
154
156
  this.userId = "";
157
+ this.userId = userId;
155
158
  this.czechLexeme = czechLexeme;
156
159
  this.englishLexeme = englishLexeme;
157
160
  }
@@ -200,10 +203,11 @@ var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
200
203
  ApiPath2["SIGN_OUT"] = "/signOut";
201
204
  ApiPath2["TEST_COMPLETE"] = "/test/complete";
202
205
  ApiPath2["TEST_INIT"] = "/test/init";
206
+ ApiPath2["TEST_SKIP_DECK"] = "/test/skipDeck";
203
207
  ApiPath2["TRANSLATE"] = "/translate";
204
208
  ApiPath2["TRANSLATIONS_ALL"] = "/lexemes/allTranslations/:sourceText/:sourceLang";
205
209
  ApiPath2["USER"] = "/user";
206
- ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked";
210
+ ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd";
207
211
  return ApiPath2;
208
212
  })(ApiPath || {});
209
213
  export {
@@ -220,11 +224,11 @@ export {
220
224
  ReminderFrequency,
221
225
  Scenario,
222
226
  VocabCheckType,
223
- convertJSDateObjectToMySQLDateString,
224
227
  convertJSDateStringToMySQLDate,
225
228
  dateDifferenceInDays,
226
- getClientDate,
227
229
  getFormattedDate,
230
+ getMysqlDateAllowingForTZ,
231
+ getMysqlDateIgnoreTZ,
228
232
  isClientDateTooFarFromServerDate,
229
233
  isStringContainingInteger,
230
234
  isThePreviousDay,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "czapp-shared",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
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",
@@ -1,14 +1,14 @@
1
1
  import { MySQLDate } from '../index';
2
2
 
3
3
  /**
4
- * @name convertJSDateObjectToMySQLDateString
5
- * @description Converts a JavaScript Date object to a MySQL date string
4
+ * @name getMysqlDateIgnoreTZ
5
+ * @description Converts a JavaScript Date object to a MySQL date string by ignoring the timezone
6
6
  * @param date
7
7
  * @type Date
8
- * @returns MySQLDate in the format "2021-01-01 07:41:23"
8
+ * @returns MySQLDate in the format "2021-01-01 07:41:23" or undefined if the input date is invalid
9
9
  */
10
10
 
11
- export const convertJSDateObjectToMySQLDateString = (date: Date): MySQLDate | undefined => {
11
+ export const getMysqlDateIgnoreTZ = (date: Date): MySQLDate | undefined => {
12
12
  let dateStr: string;
13
13
  try {
14
14
  dateStr = date.toISOString().slice(0, 19).replace('T', ' ');
@@ -22,6 +22,20 @@ export const convertJSDateObjectToMySQLDateString = (date: Date): MySQLDate | un
22
22
  }
23
23
  }
24
24
 
25
+ /**
26
+ * @name getMysqlDateAllowingForTZ
27
+ * @param date
28
+ */
29
+ export const getMysqlDateAllowingForTZ = (date: Date): MySQLDate => {
30
+ const zeroPad = (num: number): string => {
31
+ return num < 10 ? `0${num}` : num.toString();
32
+ }
33
+ return `${date.getFullYear()}-${zeroPad(date.getMonth() + 1)}-${zeroPad(date.getDate())} ${zeroPad(date.getHours())}:${zeroPad(date.getMinutes())}:${zeroPad(date.getSeconds())}` as MySQLDate;
34
+ }
35
+
36
+
37
+
38
+
25
39
  /**
26
40
  * @name convertJSDateStringToMySQLDate
27
41
  * @description Converts a JavaScript Date object to a MySQL date string
@@ -69,7 +83,7 @@ export const isValidJsDateString = (dateStr: string): boolean => {
69
83
  * @returns boolean
70
84
  */
71
85
  export const isClientDateTooFarFromServerDate = (clientDateMySQLFormat: MySQLDate, serverDate: Date): boolean => {
72
- const serverDateMysqlFormat = convertJSDateObjectToMySQLDateString(serverDate);
86
+ const serverDateMysqlFormat = getMysqlDateIgnoreTZ(serverDate);
73
87
  if (!serverDateMysqlFormat) return true;
74
88
  return Math.abs(dateDifferenceInDays(clientDateMySQLFormat, serverDateMysqlFormat)) > 1;
75
89
  }
@@ -91,14 +105,6 @@ export const dateDifferenceInDays = (date1: MySQLDate, date2: MySQLDate): number
91
105
  return difference / (1000 * 3600 * 24);
92
106
  }
93
107
 
94
- export const getClientDate = (date: Date): string => {
95
- return `${date.getFullYear()}-${zeroPad(date.getMonth() + 1)}-${zeroPad(date.getDate())} ${zeroPad(date.getHours())}:${zeroPad(date.getMinutes())}:${zeroPad(date.getSeconds())}`;
96
- }
97
-
98
- const zeroPad = (num: number): string => {
99
- return num < 10 ? `0${num}` : num.toString();
100
- }
101
-
102
108
  export const isThePreviousDay = (date: MySQLDate, referenceDate: MySQLDate): boolean => {
103
109
  const previousDay = new Date(referenceDate);
104
110
  previousDay.setDate(new Date(referenceDate).getDate() - 1);
@@ -1,14 +1,15 @@
1
1
  import { ILexeme, ILexemePair } from '../design/lexemes';
2
2
  import { Familiarity, LearningStage, MySQLDate } from '../design/types';
3
- import { convertJSDateObjectToMySQLDateString } from './date';
3
+ import { getMysqlDateIgnoreTZ } from './date';
4
4
 
5
5
  export class Lexeme implements ILexeme {
6
6
  text: string = '';
7
- id: number | undefined = undefined;
7
+ id: number | null = null;
8
8
  dateAdded: MySQLDate;
9
9
  userId: string = "";
10
- constructor() {
11
- this.dateAdded = convertJSDateObjectToMySQLDateString(new Date());
10
+ constructor(userId: string) {
11
+ this.userId = userId;
12
+ this.dateAdded = getMysqlDateIgnoreTZ(new Date());
12
13
  }
13
14
  }
14
15
 
@@ -25,7 +26,8 @@ export class LexemePair implements ILexemePair {
25
26
  notes: string = "";
26
27
  userId: string = "";
27
28
 
28
- constructor (englishLexeme: Lexeme, czechLexeme: Lexeme) {
29
+ constructor (userId:string, englishLexeme: Lexeme, czechLexeme: Lexeme) {
30
+ this.userId = userId;
29
31
  this.czechLexeme = czechLexeme;
30
32
  this.englishLexeme = englishLexeme;
31
33
  }
package/src/design/api.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { Language } from '../../dist/index';
2
- import { ILexeme, ILexemeIdPair, ILexemePair } from './lexemes';
3
- import { ITestResult, MySQLDate, Scenario, VocabCheckType } from './types';
1
+ import { ILexeme, ILexemeIdPair, ILexemeLearningInfo, ILexemePair } from './lexemes';
2
+ import { Familiarity, ITestResult, Language, MySQLDate, Scenario, VocabCheckType } from './types';
4
3
  import { IUserData } from './user';
5
4
 
6
5
  export enum HttpStatusCode {
@@ -35,10 +34,11 @@ export enum ApiPath {
35
34
  SIGN_OUT = '/signOut',
36
35
  TEST_COMPLETE = '/test/complete',
37
36
  TEST_INIT = '/test/init',
37
+ TEST_SKIP_DECK = '/test/skipDeck',
38
38
  TRANSLATE = '/translate',
39
39
  TRANSLATIONS_ALL = '/lexemes/allTranslations/:sourceText/:sourceLang',
40
40
  USER = '/user',
41
- USER_RESET_TEST = '/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked',
41
+ USER_RESET_TEST = '/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd',
42
42
  }
43
43
 
44
44
 
@@ -51,7 +51,7 @@ export interface TestInitRequestBody {
51
51
  export interface TestCompleteRequestBody {
52
52
  clientDate: MySQLDate
53
53
  results: ITestResult[]
54
- vocabCheckType: string
54
+ vocabCheckType: VocabCheckType
55
55
  }
56
56
  export interface TranslationRequestBody {
57
57
  q: string;
@@ -84,39 +84,39 @@ export interface SignInRequestBody {
84
84
  */
85
85
  export interface SelectAllTranslationsParams {
86
86
  sourceText: string;
87
- sourceLang: string;
87
+ sourceLang: Language;
88
88
  }
89
89
  export interface SelectLexemeCountParams {
90
90
  language: Language;
91
91
  }
92
92
  export interface SelectLexemePairParams {
93
- czId: string;
94
- enId: string;
93
+ czId: number;
94
+ enId: number;
95
95
  }
96
96
  export interface SelectLexemePairsByTextParams {
97
97
  inputText: string;
98
- inputLang: string;
98
+ inputLang: Language;
99
99
  }
100
100
  export interface SelectLexemesParams {
101
- page: string;
102
- length: string;
101
+ page: number;
102
+ length: number;
103
103
  }
104
104
  export interface SelectTestLexemesParams {
105
- testType: string;
106
- testLength: string;
105
+ testType: VocabCheckType;
106
+ testLength: number;
107
107
  }
108
108
  export interface UpdateLexemePairFamiliarityParams {
109
- czId: string;
110
- enId: string;
111
- familiarity: string;
109
+ czId: number;
110
+ enId: number;
111
+ familiarity: Familiarity;
112
112
  }
113
113
  export interface DeleteLexemePairRequestParams {
114
- czId: string;
115
- enId: string;
114
+ czId: number;
115
+ enId: number;
116
116
  }
117
117
  export interface ResetTestUserParams {
118
118
  flashcardReviewCompletedCount: number;
119
- testsUnlocked: boolean;
119
+ currentStreakEnd: MySQLDate;
120
120
  }
121
121
 
122
122
 
@@ -135,7 +135,7 @@ export interface ControllerResponse<T> {
135
135
 
136
136
  // Response Data
137
137
  export type TranslationResponseData = {
138
- detectedSourceLanguage: string,
138
+ detectedSourceLanguage: Language,
139
139
  translations: Array<{
140
140
  translatedText: string
141
141
  }>
@@ -151,6 +151,7 @@ export interface SignInResponseData {
151
151
  }
152
152
  export interface TestInitResponseData {
153
153
  lexemePairs: ILexemePair[];
154
+ lexemeLearningInfo: ILexemeLearningInfo;
154
155
  vocabCheckType: VocabCheckType;
155
156
  }
156
157
  export interface TestCompleteResponseData {
@@ -161,7 +162,7 @@ export interface TestCompleteResponseData {
161
162
 
162
163
  // other
163
164
  export type DeeplTranslation = {
164
- detectedSourceLanguage: string,
165
+ detectedSourceLanguage: Language,
165
166
  translations: Array<{
166
167
  translatedText: string
167
168
  }>
@@ -1,7 +1,7 @@
1
1
  import { Familiarity, Language, LearningStage, MySQLDate } from './types';
2
2
 
3
3
  export interface ILexeme {
4
- id: number | undefined;
4
+ id: number | null;
5
5
  dateAdded: MySQLDate;
6
6
  text: string;
7
7
  userId: string;
@@ -13,9 +13,9 @@ export interface ILexemePair {
13
13
  englishLexeme: ILexeme;
14
14
  familiarity: Familiarity;
15
15
  firstKnownSessionDigit: number | null,
16
- lastFlashcardReview: MySQLDate,
16
+ lastFlashcardReview: MySQLDate | null,
17
17
  lastModified: MySQLDate;
18
- lastTested: MySQLDate;
18
+ lastTested: MySQLDate | null;
19
19
  learningStage: LearningStage,
20
20
  notes: string;
21
21
  userId: string;
@@ -36,5 +36,11 @@ export interface ICount {
36
36
  count: number;
37
37
  }
38
38
 
39
+ export interface ILexemeLearningInfo {
40
+ newCount: number;
41
+ learningCount: number;
42
+ retiredCount: number;
43
+ }
44
+
39
45
 
40
46
 
@@ -1,8 +1,8 @@
1
1
  import { ILexemePair } from './lexemes';
2
2
 
3
3
  export enum Language {
4
- CZECH = 'cz',
5
- ENGLISH = 'en',
4
+ CZECH = "CZECH",
5
+ ENGLISH = "ENGLISH",
6
6
  UNKNOWN = 'UNKNOWN'
7
7
  }
8
8
  export type Result<T> = [T, undefined] | [undefined, Error];
@@ -13,8 +13,8 @@ export enum Familiarity {
13
13
  UNKNOWN = "UNKNOWN",
14
14
  }
15
15
  export enum VocabCheckType {
16
- FLASHCARD = 'flashcard',
17
- TEST = 'test',
16
+ FLASHCARD = "FLASHCARD",
17
+ TEST = "TEST",
18
18
  }
19
19
 
20
20
  export enum LearningStage {
@@ -24,9 +24,9 @@ export enum LearningStage {
24
24
  }
25
25
 
26
26
  export enum Progress {
27
- WORSE,
28
- NONE,
29
- IMPROVED
27
+ WORSE = "WORSE",
28
+ NONE = "NONE",
29
+ IMPROVED = "IMPROVED",
30
30
  }
31
31
 
32
32
  export interface ITestResult {
@@ -38,9 +38,9 @@ export interface ITestResult {
38
38
  export type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
39
39
 
40
40
  export enum ReminderFrequency {
41
- ALWAYS = "always",
42
- DAILY = "daily",
43
- NEVER = "never",
41
+ ALWAYS = "ALWAYS",
42
+ DAILY = "DAILY",
43
+ NEVER = "NEVER",
44
44
  }
45
45
 
46
46
  export enum AppError {
@@ -57,6 +57,7 @@ export enum AppError {
57
57
  REQUEST_INSERT_OR_UPDATE_LEXEME_PAIR_FAILED = 'Failed to insert or update lexeme pair',
58
58
  REQUEST_TRANSLATION_FAILED = 'Failed to get translation',
59
59
  REQUEST_TEST_COMPLETE_FAILED = 'Failed to complete test',
60
+ REQUEST_TEST_SKIP_FAILED = "Failed to skip to the next deck"
60
61
  }
61
62
 
62
63
  export enum Scenario {
@@ -17,6 +17,5 @@ export interface IUserData {
17
17
  rewardPoints: number,
18
18
  signUpDate: MySQLDate,
19
19
  testsCompletedCount: number,
20
- testsUnlocked: boolean,
21
20
  uiLanguage: Language,
22
21
  }
@@ -1,11 +1,11 @@
1
1
  import { expect } from 'chai';
2
2
  import {
3
- convertJSDateObjectToMySQLDateString,
4
- convertJSDateStringToMySQLDate, dateDifferenceInDays, isClientDateTooFarFromServerDate,
3
+ getMysqlDateIgnoreTZ,
4
+ convertJSDateStringToMySQLDate, dateDifferenceInDays, getMysqlDateAllowingForTZ, isClientDateTooFarFromServerDate,
5
5
  isThePreviousDay,
6
6
  isTheSameDay, isValidJsDateString, isValidMysqlDateString,
7
7
  MySQLDate
8
- } from '../../src';
8
+ } from '../src';
9
9
  describe('Date', () => {
10
10
  describe('isTheSameDay', () => {
11
11
  it('should return true if both dates are the same calendar day', () => {
@@ -48,14 +48,25 @@ describe('Date', () => {
48
48
  });
49
49
  });
50
50
 
51
- describe('convertJSDateObjectToMySQLDateString', () =>{
51
+ describe('getMysqlDateIgnoreTZ', () =>{
52
52
  it('should convert a JavaScript date object to a MySQL date string', () => {
53
53
  const date = new Date("2021-01-01T07:41:23.000Z");
54
- expect(convertJSDateObjectToMySQLDateString(date)).to.equal("2021-01-01 07:41:23");
54
+ expect(getMysqlDateIgnoreTZ(date)).to.equal("2021-01-01 07:41:23");
55
55
  });
56
56
  it('should return undefined if the input date is invalid', () => {
57
57
  const date = new Date("not a date");
58
- expect(convertJSDateObjectToMySQLDateString(date)).to.be.undefined;
58
+ expect(getMysqlDateIgnoreTZ(date)).to.be.undefined;
59
+ });
60
+ });
61
+
62
+ describe('getMysqlDateAllowingForTZ', () => {
63
+ it('should convert a JavaScript date object to a MySQL date string', () => {
64
+ const date = new Date("2021-01-01T07:41:23.000Z");
65
+ expect(getMysqlDateAllowingForTZ(date)).to.equal("2021-01-01 07:41:23");
66
+ });
67
+ it('should return undefined if the input date is invalid', () => {
68
+ const date = new Date("not a date");
69
+ expect(getMysqlDateAllowingForTZ(date)).to.be.undefined;
59
70
  });
60
71
  });
61
72
 
File without changes