czapp-shared 1.0.28 → 1.0.30

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
@@ -48,7 +48,7 @@ declare const isClientDateTooFarFromServerDate: (clientDateMySQLFormat: MySQLDat
48
48
  declare const dateDifferenceInDays: (date1: MySQLDate, date2: MySQLDate) => number;
49
49
  declare const isThePreviousDay: (date: MySQLDate, referenceDate: MySQLDate) => boolean;
50
50
  declare const isTheSameDay: (date1: MySQLDate, date2: MySQLDate) => boolean;
51
- declare const getFormattedDate: (date: Date) => string;
51
+ declare const getFormattedDate: (date: Date) => DateString;
52
52
  declare const isExpired: (date: MySQLDate) => boolean;
53
53
 
54
54
  interface ISession {
@@ -90,12 +90,12 @@ interface ITestResult {
90
90
  thinkingTimeSecs: number;
91
91
  }
92
92
  interface IVocabCheckActivity {
93
- testDate: MySQLDate;
93
+ testDate: DateString;
94
94
  flashcardCount: number;
95
95
  testQuestionCount: number;
96
96
  }
97
97
  type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
98
- type DateString = `${number}-${number}-${number}`;
98
+ type DateString = `${number}-${string}-${string}`;
99
99
  declare enum ReminderFrequency {
100
100
  ALWAYS = "ALWAYS",
101
101
  DAILY = "DAILY",
@@ -151,10 +151,10 @@ interface ILexemePair {
151
151
  dateAdded: MySQLDate;
152
152
  englishLexeme: ILexeme;
153
153
  familiarity: Familiarity;
154
- firstKnownSessionDigit: number | null;
155
- lastFlashcardReview: MySQLDate | null;
156
- lastModified: MySQLDate;
157
- lastTested: MySQLDate | null;
154
+ firstKnownSessionDigit?: number;
155
+ lastFlashcardReview?: MySQLDate;
156
+ lastModified?: MySQLDate;
157
+ lastTested?: MySQLDate;
158
158
  learningStage: LearningStage;
159
159
  notes: string;
160
160
  userId: string;
@@ -193,10 +193,10 @@ declare class LexemePair implements ILexemePair {
193
193
  dateAdded: MySQLDate;
194
194
  englishLexeme: ILexeme;
195
195
  familiarity: Familiarity;
196
- firstKnownSessionDigit: number | null;
197
- lastFlashcardReview: MySQLDate;
198
- lastModified: MySQLDate;
199
- lastTested: MySQLDate;
196
+ firstKnownSessionDigit?: number;
197
+ lastFlashcardReview?: MySQLDate;
198
+ lastModified?: MySQLDate;
199
+ lastTested?: MySQLDate;
200
200
  learningStage: LearningStage;
201
201
  notes: string;
202
202
  userId: string;
@@ -206,6 +206,12 @@ declare class LexemePair implements ILexemePair {
206
206
  declare const isStringContainingInteger: (str: any) => boolean;
207
207
  declare const parameterReplace: (path: string, params?: string[]) => string;
208
208
 
209
+ type Streaks = {
210
+ flashcardStreak: number;
211
+ testStreak: number;
212
+ };
213
+ declare const deriveStreakFromVocabCheckActivity: (activity: IVocabCheckActivity[], today: DateString) => Streaks;
214
+
209
215
  interface IActivityCount {
210
216
  date: DateString;
211
217
  count: number;
@@ -269,7 +275,8 @@ declare enum ApiPath {
269
275
  TRANSLATIONS_ALL = "/lexemes/allTranslations/:sourceText/:sourceLang",
270
276
  USER = "/user",
271
277
  USER_ONBOARDING = "/user/onboarding",
272
- USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd"
278
+ USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd",
279
+ VOCAB_CHECK_ACTIVITY = "/vocabCheckActivity/:endDate/:noOfDays"
273
280
  }
274
281
  declare enum ClientPlatform {
275
282
  IOS = "ios",
@@ -363,6 +370,10 @@ interface HeatMapParams {
363
370
  weekCount: number;
364
371
  endDate: DateString;
365
372
  }
373
+ interface SelectVocabCheckActivityParams {
374
+ endDate: DateString;
375
+ noOfDays: number;
376
+ }
366
377
  /**
367
378
  * Response payloads
368
379
  */
@@ -412,4 +423,4 @@ type DeeplTranslation = {
412
423
  }>;
413
424
  };
414
425
 
415
- export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, ClientPlatform, type ControllerResponse, type DateString, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, type HeatMapParams, type HeatMapResponseData, HttpStatusCode, type IActivityCount, type ICount, type ILexeme, type ILexemeIdPair, type ILexemeLearningInfo, type ILexemePair, type ILexemePairTexts, type ISession, type ITestResult, type IUserData, type IVocabCheckActivity, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, type RecycleLexemePairParams, 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 UpdateOnboardingStatusRequestBody, type UpdateUserRequestBody, VocabCheckType, convertJSDateStringToMySQLDate, dateDifferenceInDays, getFormattedDate, getMysqlDateIgnoreTZ, isClientDateTooFarFromServerDate, isExpired, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
426
+ export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, ClientPlatform, type ControllerResponse, type DateString, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, type HeatMapParams, type HeatMapResponseData, HttpStatusCode, type IActivityCount, type ICount, type ILexeme, type ILexemeIdPair, type ILexemeLearningInfo, type ILexemePair, type ILexemePairTexts, type ISession, type ITestResult, type IUserData, type IVocabCheckActivity, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, type RecycleLexemePairParams, ReminderFrequency, type ResetTestUserParams, type Result, Scenario, type SelectAllTranslationsParams, type SelectLexemeCountParams, type SelectLexemePairParams, type SelectLexemePairsByTextParams, type SelectLexemesParams, type SelectTestLexemesParams, type SelectVocabCheckActivityParams, type SignInRequestBody, type SignInResponseData, type Streaks, type TestCompleteRequestBody, type TestCompleteResponseData, type TestInitRequestBody, type TestInitResponseData, type TranslationRequestBody, type TranslationResponseData, type UpdateLexemePairFamiliarityParams, type UpdateOnboardingStatusRequestBody, type UpdateUserRequestBody, VocabCheckType, convertJSDateStringToMySQLDate, dateDifferenceInDays, deriveStreakFromVocabCheckActivity, getFormattedDate, getMysqlDateIgnoreTZ, isClientDateTooFarFromServerDate, isExpired, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
package/dist/index.d.ts CHANGED
@@ -48,7 +48,7 @@ declare const isClientDateTooFarFromServerDate: (clientDateMySQLFormat: MySQLDat
48
48
  declare const dateDifferenceInDays: (date1: MySQLDate, date2: MySQLDate) => number;
49
49
  declare const isThePreviousDay: (date: MySQLDate, referenceDate: MySQLDate) => boolean;
50
50
  declare const isTheSameDay: (date1: MySQLDate, date2: MySQLDate) => boolean;
51
- declare const getFormattedDate: (date: Date) => string;
51
+ declare const getFormattedDate: (date: Date) => DateString;
52
52
  declare const isExpired: (date: MySQLDate) => boolean;
53
53
 
54
54
  interface ISession {
@@ -90,12 +90,12 @@ interface ITestResult {
90
90
  thinkingTimeSecs: number;
91
91
  }
92
92
  interface IVocabCheckActivity {
93
- testDate: MySQLDate;
93
+ testDate: DateString;
94
94
  flashcardCount: number;
95
95
  testQuestionCount: number;
96
96
  }
97
97
  type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
98
- type DateString = `${number}-${number}-${number}`;
98
+ type DateString = `${number}-${string}-${string}`;
99
99
  declare enum ReminderFrequency {
100
100
  ALWAYS = "ALWAYS",
101
101
  DAILY = "DAILY",
@@ -151,10 +151,10 @@ interface ILexemePair {
151
151
  dateAdded: MySQLDate;
152
152
  englishLexeme: ILexeme;
153
153
  familiarity: Familiarity;
154
- firstKnownSessionDigit: number | null;
155
- lastFlashcardReview: MySQLDate | null;
156
- lastModified: MySQLDate;
157
- lastTested: MySQLDate | null;
154
+ firstKnownSessionDigit?: number;
155
+ lastFlashcardReview?: MySQLDate;
156
+ lastModified?: MySQLDate;
157
+ lastTested?: MySQLDate;
158
158
  learningStage: LearningStage;
159
159
  notes: string;
160
160
  userId: string;
@@ -193,10 +193,10 @@ declare class LexemePair implements ILexemePair {
193
193
  dateAdded: MySQLDate;
194
194
  englishLexeme: ILexeme;
195
195
  familiarity: Familiarity;
196
- firstKnownSessionDigit: number | null;
197
- lastFlashcardReview: MySQLDate;
198
- lastModified: MySQLDate;
199
- lastTested: MySQLDate;
196
+ firstKnownSessionDigit?: number;
197
+ lastFlashcardReview?: MySQLDate;
198
+ lastModified?: MySQLDate;
199
+ lastTested?: MySQLDate;
200
200
  learningStage: LearningStage;
201
201
  notes: string;
202
202
  userId: string;
@@ -206,6 +206,12 @@ declare class LexemePair implements ILexemePair {
206
206
  declare const isStringContainingInteger: (str: any) => boolean;
207
207
  declare const parameterReplace: (path: string, params?: string[]) => string;
208
208
 
209
+ type Streaks = {
210
+ flashcardStreak: number;
211
+ testStreak: number;
212
+ };
213
+ declare const deriveStreakFromVocabCheckActivity: (activity: IVocabCheckActivity[], today: DateString) => Streaks;
214
+
209
215
  interface IActivityCount {
210
216
  date: DateString;
211
217
  count: number;
@@ -269,7 +275,8 @@ declare enum ApiPath {
269
275
  TRANSLATIONS_ALL = "/lexemes/allTranslations/:sourceText/:sourceLang",
270
276
  USER = "/user",
271
277
  USER_ONBOARDING = "/user/onboarding",
272
- USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd"
278
+ USER_RESET_TEST = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd",
279
+ VOCAB_CHECK_ACTIVITY = "/vocabCheckActivity/:endDate/:noOfDays"
273
280
  }
274
281
  declare enum ClientPlatform {
275
282
  IOS = "ios",
@@ -363,6 +370,10 @@ interface HeatMapParams {
363
370
  weekCount: number;
364
371
  endDate: DateString;
365
372
  }
373
+ interface SelectVocabCheckActivityParams {
374
+ endDate: DateString;
375
+ noOfDays: number;
376
+ }
366
377
  /**
367
378
  * Response payloads
368
379
  */
@@ -412,4 +423,4 @@ type DeeplTranslation = {
412
423
  }>;
413
424
  };
414
425
 
415
- export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, ClientPlatform, type ControllerResponse, type DateString, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, type HeatMapParams, type HeatMapResponseData, HttpStatusCode, type IActivityCount, type ICount, type ILexeme, type ILexemeIdPair, type ILexemeLearningInfo, type ILexemePair, type ILexemePairTexts, type ISession, type ITestResult, type IUserData, type IVocabCheckActivity, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, type RecycleLexemePairParams, 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 UpdateOnboardingStatusRequestBody, type UpdateUserRequestBody, VocabCheckType, convertJSDateStringToMySQLDate, dateDifferenceInDays, getFormattedDate, getMysqlDateIgnoreTZ, isClientDateTooFarFromServerDate, isExpired, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
426
+ export { ApiMethod, ApiPath, AppError, type AutologinRequestBody, ClientPlatform, type ControllerResponse, type DateString, type DeeplTranslation, type DeleteLexemePairRequestParams, Familiarity, type HeatMapParams, type HeatMapResponseData, HttpStatusCode, type IActivityCount, type ICount, type ILexeme, type ILexemeIdPair, type ILexemeLearningInfo, type ILexemePair, type ILexemePairTexts, type ISession, type ITestResult, type IUserData, type IVocabCheckActivity, type InsertOrUpdateRequestBody, type InsertOrUpdateResponseData, Language, LearningStage, Lexeme, LexemePair, type LexemePairRequestBody, type LexemePairWithLang, type MySQLDate, Progress, type RecycleLexemePairParams, ReminderFrequency, type ResetTestUserParams, type Result, Scenario, type SelectAllTranslationsParams, type SelectLexemeCountParams, type SelectLexemePairParams, type SelectLexemePairsByTextParams, type SelectLexemesParams, type SelectTestLexemesParams, type SelectVocabCheckActivityParams, type SignInRequestBody, type SignInResponseData, type Streaks, type TestCompleteRequestBody, type TestCompleteResponseData, type TestInitRequestBody, type TestInitResponseData, type TranslationRequestBody, type TranslationResponseData, type UpdateLexemePairFamiliarityParams, type UpdateOnboardingStatusRequestBody, type UpdateUserRequestBody, VocabCheckType, convertJSDateStringToMySQLDate, dateDifferenceInDays, deriveStreakFromVocabCheckActivity, getFormattedDate, getMysqlDateIgnoreTZ, isClientDateTooFarFromServerDate, isExpired, isStringContainingInteger, isThePreviousDay, isTheSameDay, isValidJsDateString, isValidMysqlDateString, parameterReplace };
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  VocabCheckType: () => VocabCheckType,
36
36
  convertJSDateStringToMySQLDate: () => convertJSDateStringToMySQLDate,
37
37
  dateDifferenceInDays: () => dateDifferenceInDays,
38
+ deriveStreakFromVocabCheckActivity: () => deriveStreakFromVocabCheckActivity,
38
39
  getFormattedDate: () => getFormattedDate,
39
40
  getMysqlDateIgnoreTZ: () => getMysqlDateIgnoreTZ,
40
41
  isClientDateTooFarFromServerDate: () => isClientDateTooFarFromServerDate,
@@ -207,6 +208,7 @@ var LexemePair = class {
207
208
  this.userId = userId;
208
209
  this.czechLexeme = czechLexeme;
209
210
  this.englishLexeme = englishLexeme;
211
+ this.dateAdded = getMysqlDateIgnoreTZ(/* @__PURE__ */ new Date());
210
212
  }
211
213
  };
212
214
 
@@ -220,6 +222,50 @@ var parameterReplace = (path, params = []) => {
220
222
  return path.replace(/\:([a-zA-Z0-9]+)/g, (match, p1) => params.shift() || "");
221
223
  };
222
224
 
225
+ // src/concrete/vocabCheck.ts
226
+ var deriveStreakFromVocabCheckActivity = (activity, today) => {
227
+ if (activity.length === 0) return { flashcardStreak: 0, testStreak: 0 };
228
+ let flashcardStreak = 0;
229
+ let testStreak = 0;
230
+ const sortedActivity = activity.sort((a, b) => a.testDate < b.testDate ? 1 : -1);
231
+ const todayRecord = sortedActivity.find((record) => record.testDate === today);
232
+ const yesterdaysDateObj = new Date(today);
233
+ yesterdaysDateObj.setDate(yesterdaysDateObj.getDate() - 1);
234
+ let currentDate = yesterdaysDateObj.toISOString().split("T")[0];
235
+ for (const record of sortedActivity) {
236
+ if (record.flashcardCount > 0) {
237
+ if (record.testDate === currentDate) {
238
+ flashcardStreak++;
239
+ const dateObj = new Date(currentDate);
240
+ dateObj.setDate(dateObj.getDate() - 1);
241
+ currentDate = dateObj.toISOString().split("T")[0];
242
+ } else if (record.testDate < currentDate) {
243
+ break;
244
+ }
245
+ }
246
+ }
247
+ if (todayRecord && todayRecord.flashcardCount > 0) {
248
+ flashcardStreak++;
249
+ }
250
+ currentDate = yesterdaysDateObj.toISOString().split("T")[0];
251
+ for (const record of sortedActivity) {
252
+ if (record.testQuestionCount > 0) {
253
+ if (record.testDate === currentDate) {
254
+ testStreak++;
255
+ const dateObj = new Date(currentDate);
256
+ dateObj.setDate(dateObj.getDate() - 1);
257
+ currentDate = dateObj.toISOString().split("T")[0];
258
+ } else if (record.testDate < currentDate) {
259
+ break;
260
+ }
261
+ }
262
+ }
263
+ if (todayRecord && todayRecord.testQuestionCount > 0) {
264
+ testStreak++;
265
+ }
266
+ return { flashcardStreak, testStreak };
267
+ };
268
+
223
269
  // src/design/api.ts
224
270
  var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
225
271
  HttpStatusCode2[HttpStatusCode2["OK"] = 200] = "OK";
@@ -263,6 +309,7 @@ var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
263
309
  ApiPath2["USER"] = "/user";
264
310
  ApiPath2["USER_ONBOARDING"] = "/user/onboarding";
265
311
  ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd";
312
+ ApiPath2["VOCAB_CHECK_ACTIVITY"] = "/vocabCheckActivity/:endDate/:noOfDays";
266
313
  return ApiPath2;
267
314
  })(ApiPath || {});
268
315
  var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
@@ -289,6 +336,7 @@ var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
289
336
  VocabCheckType,
290
337
  convertJSDateStringToMySQLDate,
291
338
  dateDifferenceInDays,
339
+ deriveStreakFromVocabCheckActivity,
292
340
  getFormattedDate,
293
341
  getMysqlDateIgnoreTZ,
294
342
  isClientDateTooFarFromServerDate,
package/dist/index.mjs CHANGED
@@ -157,6 +157,7 @@ var LexemePair = class {
157
157
  this.userId = userId;
158
158
  this.czechLexeme = czechLexeme;
159
159
  this.englishLexeme = englishLexeme;
160
+ this.dateAdded = getMysqlDateIgnoreTZ(/* @__PURE__ */ new Date());
160
161
  }
161
162
  };
162
163
 
@@ -170,6 +171,50 @@ var parameterReplace = (path, params = []) => {
170
171
  return path.replace(/\:([a-zA-Z0-9]+)/g, (match, p1) => params.shift() || "");
171
172
  };
172
173
 
174
+ // src/concrete/vocabCheck.ts
175
+ var deriveStreakFromVocabCheckActivity = (activity, today) => {
176
+ if (activity.length === 0) return { flashcardStreak: 0, testStreak: 0 };
177
+ let flashcardStreak = 0;
178
+ let testStreak = 0;
179
+ const sortedActivity = activity.sort((a, b) => a.testDate < b.testDate ? 1 : -1);
180
+ const todayRecord = sortedActivity.find((record) => record.testDate === today);
181
+ const yesterdaysDateObj = new Date(today);
182
+ yesterdaysDateObj.setDate(yesterdaysDateObj.getDate() - 1);
183
+ let currentDate = yesterdaysDateObj.toISOString().split("T")[0];
184
+ for (const record of sortedActivity) {
185
+ if (record.flashcardCount > 0) {
186
+ if (record.testDate === currentDate) {
187
+ flashcardStreak++;
188
+ const dateObj = new Date(currentDate);
189
+ dateObj.setDate(dateObj.getDate() - 1);
190
+ currentDate = dateObj.toISOString().split("T")[0];
191
+ } else if (record.testDate < currentDate) {
192
+ break;
193
+ }
194
+ }
195
+ }
196
+ if (todayRecord && todayRecord.flashcardCount > 0) {
197
+ flashcardStreak++;
198
+ }
199
+ currentDate = yesterdaysDateObj.toISOString().split("T")[0];
200
+ for (const record of sortedActivity) {
201
+ if (record.testQuestionCount > 0) {
202
+ if (record.testDate === currentDate) {
203
+ testStreak++;
204
+ const dateObj = new Date(currentDate);
205
+ dateObj.setDate(dateObj.getDate() - 1);
206
+ currentDate = dateObj.toISOString().split("T")[0];
207
+ } else if (record.testDate < currentDate) {
208
+ break;
209
+ }
210
+ }
211
+ }
212
+ if (todayRecord && todayRecord.testQuestionCount > 0) {
213
+ testStreak++;
214
+ }
215
+ return { flashcardStreak, testStreak };
216
+ };
217
+
173
218
  // src/design/api.ts
174
219
  var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
175
220
  HttpStatusCode2[HttpStatusCode2["OK"] = 200] = "OK";
@@ -213,6 +258,7 @@ var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
213
258
  ApiPath2["USER"] = "/user";
214
259
  ApiPath2["USER_ONBOARDING"] = "/user/onboarding";
215
260
  ApiPath2["USER_RESET_TEST"] = "/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd";
261
+ ApiPath2["VOCAB_CHECK_ACTIVITY"] = "/vocabCheckActivity/:endDate/:noOfDays";
216
262
  return ApiPath2;
217
263
  })(ApiPath || {});
218
264
  var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
@@ -238,6 +284,7 @@ export {
238
284
  VocabCheckType,
239
285
  convertJSDateStringToMySQLDate,
240
286
  dateDifferenceInDays,
287
+ deriveStreakFromVocabCheckActivity,
241
288
  getFormattedDate,
242
289
  getMysqlDateIgnoreTZ,
243
290
  isClientDateTooFarFromServerDate,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "czapp-shared",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
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,4 +1,4 @@
1
- import { MySQLDate } from '../index';
1
+ import { DateString, MySQLDate } from '../index';
2
2
 
3
3
  /**
4
4
  * @name getMysqlDateIgnoreTZ
@@ -100,7 +100,7 @@ export const isTheSameDay = (date1: MySQLDate, date2: MySQLDate): boolean => {
100
100
  return new Date(date1).toDateString() === new Date(date2).toDateString();
101
101
  }
102
102
 
103
- export const getFormattedDate = (date: Date) => {
103
+ export const getFormattedDate = (date: Date): DateString => {
104
104
  const year = date.getFullYear();
105
105
  const month = (1 + date.getMonth()).toString().padStart(2, '0');
106
106
  const day = date.getDate().toString().padStart(2, '0');
@@ -18,10 +18,10 @@ export class LexemePair implements ILexemePair {
18
18
  dateAdded: MySQLDate;
19
19
  englishLexeme: ILexeme;
20
20
  familiarity: Familiarity = Familiarity.UNKNOWN;
21
- firstKnownSessionDigit: number | null;
22
- lastFlashcardReview: MySQLDate;
23
- lastModified: MySQLDate;
24
- lastTested: MySQLDate;
21
+ firstKnownSessionDigit?: number;
22
+ lastFlashcardReview?: MySQLDate;
23
+ lastModified?: MySQLDate;
24
+ lastTested?: MySQLDate;
25
25
  learningStage: LearningStage = LearningStage.NEW;
26
26
  notes: string = "";
27
27
  userId: string = "";
@@ -30,5 +30,6 @@ export class LexemePair implements ILexemePair {
30
30
  this.userId = userId;
31
31
  this.czechLexeme = czechLexeme;
32
32
  this.englishLexeme = englishLexeme;
33
+ this.dateAdded = getMysqlDateIgnoreTZ(new Date())!;
33
34
  }
34
35
  }
@@ -0,0 +1,66 @@
1
+ import { DateString, IVocabCheckActivity } from '../design/types';
2
+
3
+ export type Streaks = {
4
+ flashcardStreak: number;
5
+ testStreak: number;
6
+ }
7
+
8
+ export const deriveStreakFromVocabCheckActivity = (activity: IVocabCheckActivity[], today: DateString): Streaks => {
9
+ if (activity.length === 0) return { flashcardStreak: 0, testStreak: 0 };
10
+ let flashcardStreak = 0;
11
+ let testStreak = 0;
12
+
13
+ // Sort activity by date descending
14
+ const sortedActivity = activity.sort((a, b) => (a.testDate < b.testDate ? 1 : -1));
15
+ const todayRecord = sortedActivity.find(record => record.testDate === today);
16
+
17
+ // Derive flashcard streak
18
+ // starting from yesterday, check each day if there was activity
19
+ const yesterdaysDateObj = new Date(today);
20
+ yesterdaysDateObj.setDate(yesterdaysDateObj.getDate() - 1);
21
+ let currentDate = yesterdaysDateObj.toISOString().split('T')[0] as DateString;
22
+ for (const record of sortedActivity) {
23
+ if (record.flashcardCount > 0) {
24
+ if (record.testDate === currentDate) {
25
+ flashcardStreak++;
26
+ // Move to previous day
27
+ const dateObj = new Date(currentDate);
28
+ dateObj.setDate(dateObj.getDate() - 1);
29
+ currentDate = dateObj.toISOString().split('T')[0] as DateString;
30
+ } else if (record.testDate < currentDate) {
31
+ // Break the streak if there's a gap
32
+ break;
33
+ }
34
+ }
35
+ }
36
+ // finally, if there were flashcards done today, add one to the streak
37
+ if (todayRecord && todayRecord.flashcardCount > 0) {
38
+ flashcardStreak++;
39
+ }
40
+
41
+ // Derive test streak
42
+
43
+ // Reset currentDate for test streak calculation to yesterday
44
+ currentDate = yesterdaysDateObj.toISOString().split('T')[0] as DateString;
45
+ for (const record of sortedActivity) {
46
+ if (record.testQuestionCount > 0) {
47
+ if (record.testDate === currentDate) {
48
+ testStreak++;
49
+ // Move to previous day
50
+ const dateObj = new Date(currentDate);
51
+ dateObj.setDate(dateObj.getDate() - 1);
52
+ currentDate = dateObj.toISOString().split('T')[0] as DateString;
53
+ } else if (record.testDate < currentDate) {
54
+ // Break the streak if there's a gap
55
+ break;
56
+ }
57
+ }
58
+ }
59
+ // finally, if there were flashcards done today, add one to the streak
60
+ if (todayRecord && todayRecord.testQuestionCount > 0) {
61
+ testStreak++;
62
+ }
63
+
64
+ return { flashcardStreak, testStreak };
65
+
66
+ }
package/src/design/api.ts CHANGED
@@ -54,6 +54,7 @@ export enum ApiPath {
54
54
  USER = '/user',
55
55
  USER_ONBOARDING = '/user/onboarding',
56
56
  USER_RESET_TEST = '/user/test/reset/:flashcardReviewCompletedCount/:currentStreakEnd',
57
+ VOCAB_CHECK_ACTIVITY = '/vocabCheckActivity/:endDate/:noOfDays',
57
58
  }
58
59
 
59
60
  export enum ClientPlatform {
@@ -151,6 +152,10 @@ export interface HeatMapParams {
151
152
  weekCount: number;
152
153
  endDate: DateString;
153
154
  }
155
+ export interface SelectVocabCheckActivityParams {
156
+ endDate: DateString;
157
+ noOfDays: number;
158
+ }
154
159
 
155
160
 
156
161
  /**
@@ -12,10 +12,10 @@ export interface ILexemePair {
12
12
  dateAdded: MySQLDate;
13
13
  englishLexeme: ILexeme;
14
14
  familiarity: Familiarity;
15
- firstKnownSessionDigit: number | null,
16
- lastFlashcardReview: MySQLDate | null,
17
- lastModified: MySQLDate;
18
- lastTested: MySQLDate | null;
15
+ firstKnownSessionDigit?: number,
16
+ lastFlashcardReview?: MySQLDate,
17
+ lastModified?: MySQLDate;
18
+ lastTested?: MySQLDate;
19
19
  learningStage: LearningStage,
20
20
  notes: string;
21
21
  userId: string;
@@ -45,14 +45,14 @@ export interface ITestResult {
45
45
  }
46
46
 
47
47
  export interface IVocabCheckActivity {
48
- testDate: MySQLDate;
48
+ testDate: DateString;
49
49
  flashcardCount: number;
50
50
  testQuestionCount: number
51
51
  }
52
52
 
53
53
  export type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
54
54
 
55
- export type DateString = `${number}-${number}-${number}`;
55
+ export type DateString = `${number}-${string}-${string}`;
56
56
 
57
57
  export enum ReminderFrequency {
58
58
  ALWAYS = "ALWAYS",
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './concrete/date';
2
2
  export * from './concrete/lexeme';
3
3
  export * from './concrete/string';
4
+ export * from './concrete/vocabCheck';
4
5
 
5
6
  export * from './design/api';
6
7
  export * from './design/lexemes';
@@ -0,0 +1,49 @@
1
+ import { expect } from 'chai';
2
+ import { IVocabCheckActivity } from '../src';
3
+ import { deriveStreakFromVocabCheckActivity } from '../src/concrete/vocabCheck';
4
+
5
+
6
+
7
+ describe('deriveStreakFromVocabCheckActivity', () => {
8
+ it('should return 0 for empty activity', () => {
9
+ const mockToday = '2025-09-03';
10
+ expect(deriveStreakFromVocabCheckActivity([], mockToday)).to.deep.equal({flashcardStreak: 0, testStreak: 0});
11
+ });
12
+ it('should return correct streak for consecutive days', () => {
13
+ const mockToday = '2025-09-03';
14
+ const activity = [
15
+ { testDate: '2025-09-01', flashcardCount: 10, testQuestionCount: 0 },
16
+ { testDate: '2025-09-02', flashcardCount: 1, testQuestionCount: 0 },
17
+ { testDate: '2025-09-03', flashcardCount: 20, testQuestionCount: 1 }
18
+ ] as IVocabCheckActivity[];
19
+ expect(deriveStreakFromVocabCheckActivity(activity, mockToday)).to.deep.equal({flashcardStreak: 3, testStreak: 1});
20
+ });
21
+ it('should return correct streak with gaps in activity', () => {
22
+ const mockToday = '2025-09-04';
23
+ const activity = [
24
+ { testDate: '2025-09-01', flashcardCount: 10, testQuestionCount: 10 },
25
+ { testDate: '2025-09-03', flashcardCount: 15, testQuestionCount: 10 },
26
+ { testDate: '2025-09-04', flashcardCount: 20, testQuestionCount: 10 },
27
+ ] as IVocabCheckActivity[];
28
+ expect(deriveStreakFromVocabCheckActivity(activity, mockToday)).to.deep.equal({flashcardStreak: 2, testStreak: 2});
29
+ });
30
+ it('should return 0 if no activity today', () => {
31
+ const mockToday = '2025-09-04';
32
+ const activity = [
33
+ { testDate: '2025-08-30', flashcardCount: 10, testQuestionCount: 10 },
34
+ { testDate: '2025-08-31', flashcardCount: 15, testQuestionCount: 10 },
35
+ ] as IVocabCheckActivity[];
36
+ expect(deriveStreakFromVocabCheckActivity(activity, mockToday)).to.deep.equal({flashcardStreak: 0, testStreak: 0});
37
+ });
38
+ it('should handle non-consecutive activity correctly', () => {
39
+ const mockToday = '2025-09-05';
40
+ const activity = [
41
+ { testDate: '2025-09-01', flashcardCount: 10, testQuestionCount: 10 },
42
+ { testDate: '2025-09-02', flashcardCount: 15, testQuestionCount: 10 },
43
+ { testDate: '2025-09-04', flashcardCount: 20, testQuestionCount: 10 },
44
+ { testDate: '2025-09-05', flashcardCount: 25, testQuestionCount: 10 },
45
+ ] as IVocabCheckActivity[];
46
+ expect(deriveStreakFromVocabCheckActivity(activity, mockToday)).to.deep.equal({flashcardStreak: 2, testStreak: 2});
47
+ });
48
+
49
+ });