czapp-shared 1.0.6 → 1.0.8
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 +18 -0
- package/dist/index.d.mts +268 -229
- package/dist/index.d.ts +268 -229
- package/dist/index.js +149 -114
- package/dist/index.mjs +144 -113
- package/package.json +3 -3
- package/src/{util.ts → concrete/date.ts} +1 -1
- package/src/concrete/lexeme.ts +32 -0
- package/src/concrete/string.ts +9 -0
- package/src/design/api.ts +172 -0
- package/src/design/lexemes.ts +40 -0
- package/src/{types.ts → design/types.ts} +13 -122
- package/src/{user.ts → design/user.ts} +13 -12
- package/src/index.ts +8 -4
- package/test/String.ts +31 -0
- package/src/lexemes.ts +0 -114
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ILexeme, ILexemePair } from '../design/lexemes';
|
|
2
|
+
import { Familiarity, LearningStage, MySQLDate } from '../design/types';
|
|
3
|
+
import { convertJSDateObjectToMySQLDateString } from './date';
|
|
4
|
+
|
|
5
|
+
export class Lexeme implements ILexeme {
|
|
6
|
+
text: string = '';
|
|
7
|
+
id: number | undefined = undefined;
|
|
8
|
+
dateAdded: MySQLDate;
|
|
9
|
+
userId: string = "";
|
|
10
|
+
constructor() {
|
|
11
|
+
this.dateAdded = convertJSDateObjectToMySQLDateString(new Date());
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class LexemePair implements ILexemePair {
|
|
16
|
+
czechLexeme: ILexeme;
|
|
17
|
+
dateAdded: MySQLDate;
|
|
18
|
+
englishLexeme: ILexeme;
|
|
19
|
+
familiarity: Familiarity = Familiarity.UNKNOWN;
|
|
20
|
+
firstKnownSessionDigit: number | null;
|
|
21
|
+
lastFlashcardReview: MySQLDate;
|
|
22
|
+
lastModified: MySQLDate;
|
|
23
|
+
lastTested: MySQLDate;
|
|
24
|
+
learningStage: LearningStage = LearningStage.NEW;
|
|
25
|
+
notes: string = "";
|
|
26
|
+
userId: string = "";
|
|
27
|
+
|
|
28
|
+
constructor (englishLexeme: Lexeme, czechLexeme: Lexeme) {
|
|
29
|
+
this.czechLexeme = czechLexeme;
|
|
30
|
+
this.englishLexeme = englishLexeme;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const isStringContainingInteger = (str: any): boolean => {
|
|
2
|
+
if (typeof str !== 'string') return false;
|
|
3
|
+
const regex = /^\d+$/;
|
|
4
|
+
return regex.test(str);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const parameterReplace = (path: string, params: string[] = []): string => {
|
|
8
|
+
return path.replace(/\:([a-zA-Z0-9]+)/g, (match, p1) => params.shift() || '');
|
|
9
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Language } from '../../dist/index';
|
|
2
|
+
import { ILexeme, ILexemeIdPair, ILexemePair } from './lexemes';
|
|
3
|
+
import { ITestResult, MySQLDate, Scenario, VocabCheckType } from './types';
|
|
4
|
+
import { IUserData } from './user';
|
|
5
|
+
|
|
6
|
+
export enum HttpStatusCode {
|
|
7
|
+
OK = 200,
|
|
8
|
+
BAD_REQUEST = 400,
|
|
9
|
+
UNAUTHORIZED = 401,
|
|
10
|
+
NOT_FOUND = 404,
|
|
11
|
+
TIMEOUT = 408,
|
|
12
|
+
ABORTED = 409,
|
|
13
|
+
INTERNAL_SERVER_ERROR = 500
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export enum ApiMethod {
|
|
17
|
+
GET = 'GET',
|
|
18
|
+
POST = 'POST',
|
|
19
|
+
PUT = 'PUT',
|
|
20
|
+
DELETE = 'DELETE',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export enum ApiPath {
|
|
24
|
+
AUTOLOGIN = '/autologin',
|
|
25
|
+
HEALTH = '/health',
|
|
26
|
+
LEXEMES = '/lexemes',
|
|
27
|
+
LEXEMES_ALL = '/lexemes/all',
|
|
28
|
+
LEXEMES_COUNT = '/lexemes/count/:language',
|
|
29
|
+
LEXEMES_DELETE_ALL = '/lexemes/deleteAll',
|
|
30
|
+
LEXEMES_PAGE = '/lexemes/:length/:page',
|
|
31
|
+
LEXEME_PAIR = '/lexemePair/:czId/:enId',
|
|
32
|
+
LEXEME_PAIRS_BY_TEXT = '/lexemePairsByText/:inputText/:inputLang',
|
|
33
|
+
LEXEME_PAIR_FAMILIARITY = '/lexemePair/:czId/:enId/:familiarity',
|
|
34
|
+
SIGN_IN = '/signIn',
|
|
35
|
+
SIGN_OUT = '/signOut',
|
|
36
|
+
TEST_COMPLETE = '/test/complete',
|
|
37
|
+
TEST_INIT = '/test/init',
|
|
38
|
+
TRANSLATE = '/translate',
|
|
39
|
+
TRANSLATIONS_ALL = '/lexemes/allTranslations/:sourceText/:sourceLang',
|
|
40
|
+
USER = '/user',
|
|
41
|
+
USER_RESET_TEST = '/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Request payloads
|
|
47
|
+
*/
|
|
48
|
+
export interface TestInitRequestBody {
|
|
49
|
+
vocabCheckType: VocabCheckType
|
|
50
|
+
}
|
|
51
|
+
export interface TestCompleteRequestBody {
|
|
52
|
+
clientDate: MySQLDate
|
|
53
|
+
results: ITestResult[]
|
|
54
|
+
vocabCheckType: string
|
|
55
|
+
}
|
|
56
|
+
export interface TranslationRequestBody {
|
|
57
|
+
q: string;
|
|
58
|
+
source: Language;
|
|
59
|
+
target: Language;
|
|
60
|
+
}
|
|
61
|
+
export type LexemePairRequestBody = {
|
|
62
|
+
czLexeme: ILexeme
|
|
63
|
+
enLexeme: ILexeme;
|
|
64
|
+
pairingNotes: string;
|
|
65
|
+
}
|
|
66
|
+
export interface UpdateUserRequestBody {
|
|
67
|
+
learningLanguage: Language;
|
|
68
|
+
uiLanguage: Language;
|
|
69
|
+
}
|
|
70
|
+
export interface AutologinRequestBody {
|
|
71
|
+
clientDate: MySQLDate;
|
|
72
|
+
}
|
|
73
|
+
export interface InsertOrUpdateRequestBody {
|
|
74
|
+
czLexeme: ILexeme;
|
|
75
|
+
enLexeme: ILexeme;
|
|
76
|
+
pairingNotes: string;
|
|
77
|
+
}
|
|
78
|
+
export interface SignInRequestBody {
|
|
79
|
+
rememberMe: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Request Params
|
|
84
|
+
*/
|
|
85
|
+
export interface SelectAllTranslationsParams {
|
|
86
|
+
sourceText: string;
|
|
87
|
+
sourceLang: string;
|
|
88
|
+
}
|
|
89
|
+
export interface SelectLexemeCountParams {
|
|
90
|
+
language: Language;
|
|
91
|
+
}
|
|
92
|
+
export interface SelectLexemePairParams {
|
|
93
|
+
czId: string;
|
|
94
|
+
enId: string;
|
|
95
|
+
}
|
|
96
|
+
export interface SelectLexemePairsByTextParams {
|
|
97
|
+
inputText: string;
|
|
98
|
+
inputLang: string;
|
|
99
|
+
}
|
|
100
|
+
export interface SelectLexemesParams {
|
|
101
|
+
page: string;
|
|
102
|
+
length: string;
|
|
103
|
+
}
|
|
104
|
+
export interface SelectTestLexemesParams {
|
|
105
|
+
testType: string;
|
|
106
|
+
testLength: string;
|
|
107
|
+
}
|
|
108
|
+
export interface UpdateLexemePairFamiliarityParams {
|
|
109
|
+
czId: string;
|
|
110
|
+
enId: string;
|
|
111
|
+
familiarity: string;
|
|
112
|
+
}
|
|
113
|
+
export interface DeleteLexemePairRequestParams {
|
|
114
|
+
czId: string;
|
|
115
|
+
enId: string;
|
|
116
|
+
}
|
|
117
|
+
export interface ResetTestUserParams {
|
|
118
|
+
flashcardReviewCompletedCount: number;
|
|
119
|
+
testsUnlocked: boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Response payloads
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
// Main Response
|
|
129
|
+
|
|
130
|
+
export interface ControllerResponse<T> {
|
|
131
|
+
message: string;
|
|
132
|
+
status: HttpStatusCode;
|
|
133
|
+
data: T;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Response Data
|
|
137
|
+
export type TranslationResponseData = {
|
|
138
|
+
detectedSourceLanguage: string,
|
|
139
|
+
translations: Array<{
|
|
140
|
+
translatedText: string
|
|
141
|
+
}>
|
|
142
|
+
}
|
|
143
|
+
export interface InsertOrUpdateResponseData {
|
|
144
|
+
scenario: Scenario,
|
|
145
|
+
lexemeIdPair: ILexemeIdPair,
|
|
146
|
+
newMappingInserted?: boolean
|
|
147
|
+
}
|
|
148
|
+
export interface SignInResponseData {
|
|
149
|
+
expiryDate: number;
|
|
150
|
+
user: IUserData;
|
|
151
|
+
}
|
|
152
|
+
export interface TestInitResponseData {
|
|
153
|
+
lexemePairs: ILexemePair[];
|
|
154
|
+
vocabCheckType: VocabCheckType;
|
|
155
|
+
}
|
|
156
|
+
export interface TestCompleteResponseData {
|
|
157
|
+
user: IUserData;
|
|
158
|
+
testResultIds: number[];
|
|
159
|
+
rewardPointsDelta: number;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// other
|
|
163
|
+
export type DeeplTranslation = {
|
|
164
|
+
detectedSourceLanguage: string,
|
|
165
|
+
translations: Array<{
|
|
166
|
+
translatedText: string
|
|
167
|
+
}>
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Familiarity, Language, LearningStage, MySQLDate } from './types';
|
|
2
|
+
|
|
3
|
+
export interface ILexeme {
|
|
4
|
+
id: number | undefined;
|
|
5
|
+
dateAdded: MySQLDate;
|
|
6
|
+
text: string;
|
|
7
|
+
userId: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ILexemePair {
|
|
11
|
+
czechLexeme: ILexeme;
|
|
12
|
+
dateAdded: MySQLDate;
|
|
13
|
+
englishLexeme: ILexeme;
|
|
14
|
+
familiarity: Familiarity;
|
|
15
|
+
firstKnownSessionDigit: number | null,
|
|
16
|
+
lastFlashcardReview: MySQLDate,
|
|
17
|
+
lastModified: MySQLDate;
|
|
18
|
+
lastTested: MySQLDate;
|
|
19
|
+
learningStage: LearningStage,
|
|
20
|
+
notes: string;
|
|
21
|
+
userId: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ILexemeIdPair {
|
|
25
|
+
czId: number;
|
|
26
|
+
enId: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type LexemePairWithLang = {
|
|
30
|
+
czechLexeme: ILexeme,
|
|
31
|
+
englishLexeme: ILexeme,
|
|
32
|
+
langToFocus: Language
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ICount {
|
|
36
|
+
count: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ILexemePairRecord } from './lexemes';
|
|
1
|
+
import { ILexemePair } from './lexemes';
|
|
3
2
|
|
|
4
3
|
export enum Language {
|
|
5
4
|
CZECH = 'cz',
|
|
@@ -24,6 +23,18 @@ export enum LearningStage {
|
|
|
24
23
|
RETIRED = 'RETIRED',
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
export enum Progress {
|
|
27
|
+
WORSE,
|
|
28
|
+
NONE,
|
|
29
|
+
IMPROVED
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ITestResult {
|
|
33
|
+
lexemePair: ILexemePair;
|
|
34
|
+
progress: Progress;
|
|
35
|
+
thinkingTimeSecs: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
27
38
|
export type MySQLDate = `${number}-${number}-${number} ${number}:${number}:${number}`;
|
|
28
39
|
|
|
29
40
|
export enum ReminderFrequency {
|
|
@@ -32,51 +43,6 @@ export enum ReminderFrequency {
|
|
|
32
43
|
NEVER = "never",
|
|
33
44
|
}
|
|
34
45
|
|
|
35
|
-
export interface ControllerResponse<T> {
|
|
36
|
-
message: string;
|
|
37
|
-
status: HttpStatusCode;
|
|
38
|
-
data: T;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface TestInitResponse {
|
|
42
|
-
lexemePairs: ILexemePairRecord[];
|
|
43
|
-
vocabCheckType: VocabCheckType;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface InsertOrUpdateResponse {
|
|
47
|
-
scenario: Scenario,
|
|
48
|
-
lexemePair: ILexemePairRecord,
|
|
49
|
-
newMappingInserted?: boolean
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export enum ApiPath {
|
|
53
|
-
AUTOLOGIN = '/autologin',
|
|
54
|
-
HEALTH = '/health',
|
|
55
|
-
LEXEMES = '/lexemes',
|
|
56
|
-
LEXEMES_ALL = '/lexemes/all',
|
|
57
|
-
LEXEMES_COUNT = '/lexemes/count/:language',
|
|
58
|
-
LEXEMES_DELETE_ALL = '/lexemes/deleteAll',
|
|
59
|
-
LEXEMES_PAGE = '/lexemes/:length/:page',
|
|
60
|
-
LEXEME_PAIR = '/lexemePair/:czId/:enId',
|
|
61
|
-
LEXEME_PAIRS_BY_TEXT = '/lexemePairsByText/:inputText/:inputLang',
|
|
62
|
-
LEXEME_PAIR_FAMILIARITY = '/lexemePair/:czId/:enId/:familiarity',
|
|
63
|
-
SIGN_IN = '/signIn',
|
|
64
|
-
SIGN_OUT = '/signOut',
|
|
65
|
-
TEST_COMPLETE = '/test/complete',
|
|
66
|
-
TEST_INIT = '/test/init',
|
|
67
|
-
TRANSLATE = '/translate',
|
|
68
|
-
TRANSLATIONS_ALL = '/lexemes/allTranslations/:sourceText/:sourceLang',
|
|
69
|
-
USER = '/user',
|
|
70
|
-
USER_RESET_TEST = '/user/test/reset/:flashcardReviewCompletedCount/:testsUnlocked',
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export enum ApiMethod {
|
|
74
|
-
GET = 'GET',
|
|
75
|
-
POST = 'POST',
|
|
76
|
-
PUT = 'PUT',
|
|
77
|
-
DELETE = 'DELETE',
|
|
78
|
-
}
|
|
79
|
-
|
|
80
46
|
export enum AppError {
|
|
81
47
|
NONE = 'No error',
|
|
82
48
|
REQUEST_AUTOLOGIN_FAILED = 'Failed to auto-login',
|
|
@@ -93,81 +59,6 @@ export enum AppError {
|
|
|
93
59
|
REQUEST_TEST_COMPLETE_FAILED = 'Failed to complete test',
|
|
94
60
|
}
|
|
95
61
|
|
|
96
|
-
export enum HttpStatusCode {
|
|
97
|
-
OK = 200,
|
|
98
|
-
BAD_REQUEST = 400,
|
|
99
|
-
UNAUTHORIZED = 401,
|
|
100
|
-
NOT_FOUND = 404,
|
|
101
|
-
TIMEOUT = 408,
|
|
102
|
-
ABORTED = 409,
|
|
103
|
-
INTERNAL_SERVER_ERROR = 500
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export interface ControllerResponse<T> {
|
|
107
|
-
message: string;
|
|
108
|
-
status: HttpStatusCode;
|
|
109
|
-
data: T;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
export type DeeplTranslation = {
|
|
114
|
-
detectedSourceLanguage: string,
|
|
115
|
-
translations: Array<{
|
|
116
|
-
translatedText: string
|
|
117
|
-
}>
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* RowDataPacket types - Database query results
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
|
-
export interface MappedCzIds extends RowDataPacket {
|
|
126
|
-
czId: number,
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export interface MappedEnIds extends RowDataPacket {
|
|
130
|
-
enId: number,
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export interface DuplicateId extends RowDataPacket {
|
|
134
|
-
id: number,
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface InsertIdDataRecord extends RowDataPacket {
|
|
138
|
-
insertId: number;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export interface UpdateDataRecord extends RowDataPacket {}
|
|
142
|
-
|
|
143
|
-
export interface UserRecord extends RowDataPacket {
|
|
144
|
-
id: number | undefined,
|
|
145
|
-
googleSub: string,
|
|
146
|
-
name: string,
|
|
147
|
-
email: string,
|
|
148
|
-
phone: string,
|
|
149
|
-
signUpDate: Date,
|
|
150
|
-
lastModified: Date,
|
|
151
|
-
learningLanguage: string,
|
|
152
|
-
flashcardReviewCompletedCount: number,
|
|
153
|
-
currentStreakLength: number,
|
|
154
|
-
currentStreakEnd: MySQLDate | undefined,
|
|
155
|
-
highStreakLength: number,
|
|
156
|
-
highStreakEnd: MySQLDate | undefined,
|
|
157
|
-
testsUnlocked: boolean,
|
|
158
|
-
rewardPoints: number,
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export interface CountRecord extends RowDataPacket {
|
|
162
|
-
count: number;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export interface LastWordsAddedRecord extends RowDataPacket {
|
|
166
|
-
czText: string;
|
|
167
|
-
enText: string;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
62
|
export enum Scenario {
|
|
172
63
|
S1_INSERT_HAPPY_PATH = "Insert, happy path",
|
|
173
64
|
S2_INSERT_ENGLISH_LEXEME_AND_MAPPING_DUPLICATE_CZECH_LEXEME_FOUND_AND_USED = "Insert English lexeme and mapping, duplicate Czech lexeme found and used",
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { Language, MySQLDate } from './types';
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export interface IUserData {
|
|
4
|
+
currentStreakEnd: MySQLDate | undefined,
|
|
5
|
+
currentStreakLength: number,
|
|
6
|
+
email: string,
|
|
7
|
+
flashcardReviewCompletedCount: number,
|
|
4
8
|
googleSub: string,
|
|
9
|
+
highStreakEnd: MySQLDate | undefined,
|
|
10
|
+
highStreakLength: number,
|
|
11
|
+
lastModified: MySQLDate,
|
|
12
|
+
lastWordAdded: string,
|
|
13
|
+
learningLanguage: Language,
|
|
14
|
+
lexemePairCount: number,
|
|
5
15
|
name: string,
|
|
6
|
-
email: string,
|
|
7
16
|
phone: string,
|
|
17
|
+
rewardPoints: number,
|
|
8
18
|
signUpDate: MySQLDate,
|
|
9
|
-
lastModified: MySQLDate,
|
|
10
|
-
learningLanguage: Language,
|
|
11
|
-
uiLanguage: Language,
|
|
12
19
|
testsCompletedCount: number,
|
|
13
|
-
currentStreakLength: number,
|
|
14
|
-
currentStreakEnd: MySQLDate,
|
|
15
|
-
highStreakLength: number,
|
|
16
|
-
highStreakEnd: MySQLDate,
|
|
17
20
|
testsUnlocked: boolean,
|
|
18
|
-
|
|
19
|
-
lastWordAdded: string,
|
|
20
|
-
lexemePairCount: number,
|
|
21
|
+
uiLanguage: Language,
|
|
21
22
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
|
|
1
|
+
export * from './concrete/date';
|
|
2
|
+
export * from './concrete/lexeme';
|
|
3
|
+
export * from './concrete/string';
|
|
4
|
+
|
|
5
|
+
export * from './design/api';
|
|
6
|
+
export * from './design/lexemes';
|
|
7
|
+
export * from './design/types';
|
|
8
|
+
export * from './design/user';
|
package/test/String.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { isStringContainingInteger, parameterReplace } from '../src/concrete/string';
|
|
3
|
+
|
|
4
|
+
describe('String Util', () => {
|
|
5
|
+
describe('isStringContainingInteger', () => {
|
|
6
|
+
it('should return true if the input is a string that contains an integer', () => {
|
|
7
|
+
expect(isStringContainingInteger('1')).to.be.true;
|
|
8
|
+
});
|
|
9
|
+
it('should return false if the input is a string is not a valid integer', () => {
|
|
10
|
+
expect(isStringContainingInteger('one')).to.be.false;
|
|
11
|
+
});
|
|
12
|
+
it('should return false if the input is not a string', () => {
|
|
13
|
+
expect(isStringContainingInteger(1)).to.be.false;
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('parameterReplace', () => {
|
|
18
|
+
it('should return the path if there are no parameters', () => {
|
|
19
|
+
expect(parameterReplace('/path')).to.equal('/path');
|
|
20
|
+
});
|
|
21
|
+
it('should replace the first parameter in the path with the first element in the params array', () => {
|
|
22
|
+
expect(parameterReplace('/path/:id', ['1'])).to.equal('/path/1');
|
|
23
|
+
});
|
|
24
|
+
it('should replace the second parameter in the path with the second element in the params array', () => {
|
|
25
|
+
expect(parameterReplace('/path/:id/:name', ['1', 'name'])).to.equal('/path/1/name');
|
|
26
|
+
});
|
|
27
|
+
it('should return the path if there are parameters but no placeholders', () => {
|
|
28
|
+
expect(parameterReplace('/path', ['1'])).to.equal('/path');
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
});
|
package/src/lexemes.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { RowDataPacket } from 'mysql2';
|
|
2
|
-
import { Familiarity, Language, LearningStage, MySQLDate } from './types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* RowDataPacket types - Database query results
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @interface ILexemeRecord
|
|
10
|
-
* @description represents the database record for a single lexeme of any language. Once parsed will be used to create
|
|
11
|
-
* a Lexeme object implementing ILexeme
|
|
12
|
-
*/
|
|
13
|
-
export interface ILexemeRecord extends RowDataPacket {
|
|
14
|
-
id: number | undefined,
|
|
15
|
-
dateAdded: string,
|
|
16
|
-
text: string,
|
|
17
|
-
userId: string,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @interface ILexemePairRecord
|
|
22
|
-
* @description represents the database record for a lexeme pair along with texts and ids for the lexemes
|
|
23
|
-
* Once parsed will be used to create a LexemePair object implementing ILexemePair
|
|
24
|
-
*/
|
|
25
|
-
export interface ILexemePairRecord extends RowDataPacket {
|
|
26
|
-
czId: number,
|
|
27
|
-
czText: string,
|
|
28
|
-
dateAdded: MySQLDate,
|
|
29
|
-
enId: number,
|
|
30
|
-
enText: string,
|
|
31
|
-
familiarity: Familiarity,
|
|
32
|
-
firstKnownSessionDigit: number | null,
|
|
33
|
-
lastFlashcardReview: MySQLDate,
|
|
34
|
-
lastModified: MySQLDate,
|
|
35
|
-
lastTested: MySQLDate,
|
|
36
|
-
learningStage: LearningStage,
|
|
37
|
-
notes: string,
|
|
38
|
-
userId: string,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Plain types - structured objects that are used throughout the application
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
export interface ILexeme {
|
|
47
|
-
id: number | undefined;
|
|
48
|
-
dateAdded: string;
|
|
49
|
-
text: string;
|
|
50
|
-
userId: string;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface ILexemePair {
|
|
54
|
-
czechLexeme: ILexeme;
|
|
55
|
-
dateAdded: MySQLDate;
|
|
56
|
-
englishLexeme: ILexeme;
|
|
57
|
-
familiarity: Familiarity;
|
|
58
|
-
firstKnownSessionDigit: number | null,
|
|
59
|
-
lastFlashcardReview: MySQLDate,
|
|
60
|
-
lastModified: MySQLDate;
|
|
61
|
-
lastTested: MySQLDate;
|
|
62
|
-
learningStage: LearningStage,
|
|
63
|
-
notes: string;
|
|
64
|
-
userId: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type LexemePairPayload = {
|
|
68
|
-
czLexeme: ILexeme
|
|
69
|
-
enLexeme: ILexeme;
|
|
70
|
-
pairingNotes: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type LexemePairWithLang = {
|
|
74
|
-
czechLexeme: ILexeme,
|
|
75
|
-
englishLexeme: ILexeme,
|
|
76
|
-
langToFocus: Language
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Classes
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
export default class Lexeme implements ILexeme {
|
|
85
|
-
text: string = '';
|
|
86
|
-
id: number | null = null;
|
|
87
|
-
dateAdded: string = "";
|
|
88
|
-
userId: string = "";
|
|
89
|
-
constructor(text: string, id: number | null = null) {
|
|
90
|
-
this.text = text;
|
|
91
|
-
this.id = id;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export class LexemePair implements ILexemePair {
|
|
96
|
-
czechLexeme: ILexeme;
|
|
97
|
-
dateAdded: MySQLDate;
|
|
98
|
-
englishLexeme: ILexeme;
|
|
99
|
-
familiarity: Familiarity;
|
|
100
|
-
firstKnownSessionDigit: number | null;
|
|
101
|
-
lastFlashcardReview: MySQLDate;
|
|
102
|
-
lastModified: MySQLDate;
|
|
103
|
-
lastTested: MySQLDate;
|
|
104
|
-
learningStage: LearningStage;
|
|
105
|
-
notes: string = "";
|
|
106
|
-
userId: string = "";
|
|
107
|
-
|
|
108
|
-
constructor (englishLexeme: ILexeme, czechLexeme: ILexeme) {
|
|
109
|
-
this.czechLexeme = czechLexeme;
|
|
110
|
-
this.englishLexeme = englishLexeme;
|
|
111
|
-
this.familiarity = Familiarity.UNKNOWN;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|