coding-agent-benchmarks 0.5.0 → 0.5.2
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 +7 -3
- package/dist/evaluator.d.ts +1 -0
- package/dist/evaluator.d.ts.map +1 -1
- package/dist/evaluator.js +1 -1
- package/dist/evaluator.js.map +1 -1
- package/dist/lcs.d.ts +33 -0
- package/dist/lcs.d.ts.map +1 -0
- package/dist/lcs.js +147 -0
- package/dist/lcs.js.map +1 -0
- package/dist/longest-common-subsequence.d.ts +45 -0
- package/dist/longest-common-subsequence.d.ts.map +1 -0
- package/dist/longest-common-subsequence.js +162 -0
- package/dist/longest-common-subsequence.js.map +1 -0
- package/dist/longestCommonSubsequence.d.ts +39 -0
- package/dist/longestCommonSubsequence.d.ts.map +1 -0
- package/dist/longestCommonSubsequence.js +166 -0
- package/dist/longestCommonSubsequence.js.map +1 -0
- package/dist/runner.js +8 -4
- package/dist/runner.js.map +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/user-registration/example.d.ts +2 -0
- package/dist/user-registration/example.d.ts.map +1 -0
- package/dist/user-registration/example.js +41 -0
- package/dist/user-registration/example.js.map +1 -0
- package/dist/user-registration/index.d.ts +9 -0
- package/dist/user-registration/index.d.ts.map +1 -0
- package/dist/user-registration/index.js +22 -0
- package/dist/user-registration/index.js.map +1 -0
- package/dist/user-registration/services/email-service.d.ts +13 -0
- package/dist/user-registration/services/email-service.d.ts.map +1 -0
- package/dist/user-registration/services/email-service.js +34 -0
- package/dist/user-registration/services/email-service.js.map +1 -0
- package/dist/user-registration/services/password-service.d.ts +5 -0
- package/dist/user-registration/services/password-service.d.ts.map +1 -0
- package/dist/user-registration/services/password-service.js +23 -0
- package/dist/user-registration/services/password-service.js.map +1 -0
- package/dist/user-registration/services/registration-service.d.ts +19 -0
- package/dist/user-registration/services/registration-service.d.ts.map +1 -0
- package/dist/user-registration/services/registration-service.js +60 -0
- package/dist/user-registration/services/registration-service.js.map +1 -0
- package/dist/user-registration/services/user-repository.d.ts +12 -0
- package/dist/user-registration/services/user-repository.d.ts.map +1 -0
- package/dist/user-registration/services/user-repository.js +24 -0
- package/dist/user-registration/services/user-repository.js.map +1 -0
- package/dist/user-registration/types.d.ts +26 -0
- package/dist/user-registration/types.d.ts.map +1 -0
- package/dist/user-registration/types.js +18 -0
- package/dist/user-registration/types.js.map +1 -0
- package/dist/user-registration/validators/email-validator.d.ts +3 -0
- package/dist/user-registration/validators/email-validator.d.ts.map +1 -0
- package/dist/user-registration/validators/email-validator.js +22 -0
- package/dist/user-registration/validators/email-validator.js.map +1 -0
- package/dist/user-registration/validators/password-validator.d.ts +3 -0
- package/dist/user-registration/validators/password-validator.d.ts.map +1 -0
- package/dist/user-registration/validators/password-validator.js +36 -0
- package/dist/user-registration/validators/password-validator.js.map +1 -0
- package/dist/user-registration/validators/required-fields-validator.d.ts +3 -0
- package/dist/user-registration/validators/required-fields-validator.d.ts.map +1 -0
- package/dist/user-registration/validators/required-fields-validator.js +17 -0
- package/dist/user-registration/validators/required-fields-validator.js.map +1 -0
- package/dist/utils/dataFetcher.d.ts +21 -0
- package/dist/utils/dataFetcher.d.ts.map +1 -0
- package/dist/utils/dataFetcher.js +71 -0
- package/dist/utils/dataFetcher.js.map +1 -0
- package/dist/utils/imageProcessor.d.ts +16 -0
- package/dist/utils/imageProcessor.d.ts.map +1 -0
- package/dist/utils/imageProcessor.js +121 -0
- package/dist/utils/imageProcessor.js.map +1 -0
- package/dist/utils/lcs.d.ts +42 -0
- package/dist/utils/lcs.d.ts.map +1 -0
- package/dist/utils/lcs.js +135 -0
- package/dist/utils/lcs.js.map +1 -0
- package/dist/utils/notifications.d.ts +2 -0
- package/dist/utils/notifications.d.ts.map +1 -0
- package/dist/utils/notifications.js +8 -0
- package/dist/utils/notifications.js.map +1 -0
- package/dist/utils/timeUtils.d.ts +16 -1
- package/dist/utils/timeUtils.d.ts.map +1 -1
- package/dist/utils/timeUtils.js +54 -17
- package/dist/utils/timeUtils.js.map +1 -1
- package/dist/utils/userReport.d.ts +10 -0
- package/dist/utils/userReport.d.ts.map +1 -0
- package/dist/utils/userReport.js +19 -0
- package/dist/utils/userReport.js.map +1 -0
- package/dist/validators/llmJudge.d.ts.map +1 -1
- package/dist/validators/llmJudge.js +10 -6
- package/dist/validators/llmJudge.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface User {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly email: string;
|
|
4
|
+
readonly passwordHash: string;
|
|
5
|
+
readonly createdAt: Date;
|
|
6
|
+
}
|
|
7
|
+
export interface UserRegistrationInput {
|
|
8
|
+
readonly email: string;
|
|
9
|
+
readonly password: string;
|
|
10
|
+
readonly name?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ValidationResult {
|
|
13
|
+
readonly isValid: boolean;
|
|
14
|
+
readonly errors: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
export declare class RegistrationError extends Error {
|
|
17
|
+
readonly code: string;
|
|
18
|
+
constructor(message: string, code: string);
|
|
19
|
+
}
|
|
20
|
+
export declare const ERROR_CODES: {
|
|
21
|
+
readonly VALIDATION_FAILED: "VALIDATION_FAILED";
|
|
22
|
+
readonly DUPLICATE_EMAIL: "DUPLICATE_EMAIL";
|
|
23
|
+
readonly DATABASE_ERROR: "DATABASE_ERROR";
|
|
24
|
+
readonly EMAIL_SEND_FAILED: "EMAIL_SEND_FAILED";
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/user-registration/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,qBAAa,iBAAkB,SAAQ,KAAK;aACG,IAAI,EAAE,MAAM;gBAA7C,OAAO,EAAE,MAAM,EAAkB,IAAI,EAAE,MAAM;CAI1D;AAED,eAAO,MAAM,WAAW;;;;;CAKd,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERROR_CODES = exports.RegistrationError = void 0;
|
|
4
|
+
class RegistrationError extends Error {
|
|
5
|
+
constructor(message, code) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.name = 'RegistrationError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.RegistrationError = RegistrationError;
|
|
12
|
+
exports.ERROR_CODES = {
|
|
13
|
+
VALIDATION_FAILED: 'VALIDATION_FAILED',
|
|
14
|
+
DUPLICATE_EMAIL: 'DUPLICATE_EMAIL',
|
|
15
|
+
DATABASE_ERROR: 'DATABASE_ERROR',
|
|
16
|
+
EMAIL_SEND_FAILED: 'EMAIL_SEND_FAILED',
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/user-registration/types.ts"],"names":[],"mappings":";;;AAkBA,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe,EAAkB,IAAY;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,SAAI,GAAJ,IAAI,CAAQ;QAEvD,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AALD,8CAKC;AAEY,QAAA,WAAW,GAAG;IACzB,iBAAiB,EAAE,mBAAmB;IACtC,eAAe,EAAE,iBAAiB;IAClC,cAAc,EAAE,gBAAgB;IAChC,iBAAiB,EAAE,mBAAmB;CAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-validator.d.ts","sourceRoot":"","sources":["../../../src/user-registration/validators/email-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAI5C,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,gBAe7C,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateEmail = void 0;
|
|
4
|
+
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
5
|
+
const validateEmail = (email) => {
|
|
6
|
+
const errors = [];
|
|
7
|
+
if (!email || email.trim() === '') {
|
|
8
|
+
errors.push('Email is required');
|
|
9
|
+
}
|
|
10
|
+
else if (!EMAIL_REGEX.test(email)) {
|
|
11
|
+
errors.push('Invalid email format');
|
|
12
|
+
}
|
|
13
|
+
else if (email.length > 255) {
|
|
14
|
+
errors.push('Email must be less than 255 characters');
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
isValid: errors.length === 0,
|
|
18
|
+
errors,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
exports.validateEmail = validateEmail;
|
|
22
|
+
//# sourceMappingURL=email-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-validator.js","sourceRoot":"","sources":["../../../src/user-registration/validators/email-validator.ts"],"names":[],"mappings":";;;AAEA,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAE1C,MAAM,aAAa,GAAG,CAAC,KAAa,EAAoB,EAAE;IAC/D,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACnC,CAAC;SAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;IACxD,CAAC;IAED,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,aAAa,iBAexB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-validator.d.ts","sourceRoot":"","sources":["../../../src/user-registration/validators/password-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAK5C,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,KAAG,gBAoCnD,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePassword = void 0;
|
|
4
|
+
const MIN_PASSWORD_LENGTH = 8;
|
|
5
|
+
const MAX_PASSWORD_LENGTH = 128;
|
|
6
|
+
const validatePassword = (password) => {
|
|
7
|
+
const errors = [];
|
|
8
|
+
if (!password) {
|
|
9
|
+
errors.push('Password is required');
|
|
10
|
+
return { isValid: false, errors };
|
|
11
|
+
}
|
|
12
|
+
if (password.length < MIN_PASSWORD_LENGTH) {
|
|
13
|
+
errors.push(`Password must be at least ${MIN_PASSWORD_LENGTH} characters long`);
|
|
14
|
+
}
|
|
15
|
+
if (password.length > MAX_PASSWORD_LENGTH) {
|
|
16
|
+
errors.push(`Password must be less than ${MAX_PASSWORD_LENGTH} characters`);
|
|
17
|
+
}
|
|
18
|
+
if (!/[a-z]/.test(password)) {
|
|
19
|
+
errors.push('Password must contain at least one lowercase letter');
|
|
20
|
+
}
|
|
21
|
+
if (!/[A-Z]/.test(password)) {
|
|
22
|
+
errors.push('Password must contain at least one uppercase letter');
|
|
23
|
+
}
|
|
24
|
+
if (!/[0-9]/.test(password)) {
|
|
25
|
+
errors.push('Password must contain at least one number');
|
|
26
|
+
}
|
|
27
|
+
if (!/[^a-zA-Z0-9]/.test(password)) {
|
|
28
|
+
errors.push('Password must contain at least one special character');
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
isValid: errors.length === 0,
|
|
32
|
+
errors,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.validatePassword = validatePassword;
|
|
36
|
+
//# sourceMappingURL=password-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-validator.js","sourceRoot":"","sources":["../../../src/user-registration/validators/password-validator.ts"],"names":[],"mappings":";;;AAEA,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEzB,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAoB,EAAE;IACrE,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACpC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACpC,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,GAAG,mBAAmB,EAAE,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,6BAA6B,mBAAmB,kBAAkB,CAAC,CAAC;IAClF,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,GAAG,mBAAmB,EAAE,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,8BAA8B,mBAAmB,aAAa,CAAC,CAAC;IAC9E,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnC,MAAM,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;IACtE,CAAC;IAED,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AApCW,QAAA,gBAAgB,oBAoC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"required-fields-validator.d.ts","sourceRoot":"","sources":["../../../src/user-registration/validators/required-fields-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAInE,eAAO,MAAM,sBAAsB,GAAI,OAAO,qBAAqB,KAAG,gBAYrE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRequiredFields = void 0;
|
|
4
|
+
const email_validator_1 = require("./email-validator");
|
|
5
|
+
const password_validator_1 = require("./password-validator");
|
|
6
|
+
const validateRequiredFields = (input) => {
|
|
7
|
+
const errors = [];
|
|
8
|
+
const emailValidation = (0, email_validator_1.validateEmail)(input.email);
|
|
9
|
+
const passwordValidation = (0, password_validator_1.validatePassword)(input.password);
|
|
10
|
+
errors.push(...emailValidation.errors, ...passwordValidation.errors);
|
|
11
|
+
return {
|
|
12
|
+
isValid: errors.length === 0,
|
|
13
|
+
errors,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.validateRequiredFields = validateRequiredFields;
|
|
17
|
+
//# sourceMappingURL=required-fields-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"required-fields-validator.js","sourceRoot":"","sources":["../../../src/user-registration/validators/required-fields-validator.ts"],"names":[],"mappings":";;;AACA,uDAAkD;AAClD,6DAAwD;AAEjD,MAAM,sBAAsB,GAAG,CAAC,KAA4B,EAAoB,EAAE;IACvF,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,MAAM,eAAe,GAAG,IAAA,+BAAa,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,kBAAkB,GAAG,IAAA,qCAAgB,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAE5D,MAAM,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAErE,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,sBAAsB,0BAYjC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface User {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
email: string;
|
|
5
|
+
username: string;
|
|
6
|
+
}
|
|
7
|
+
interface Post {
|
|
8
|
+
id: number;
|
|
9
|
+
userId: number;
|
|
10
|
+
title: string;
|
|
11
|
+
body: string;
|
|
12
|
+
}
|
|
13
|
+
interface EnrichedPost extends Post {
|
|
14
|
+
commentCount: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const fetchUserWithPosts: (userId: number, baseUrl?: string) => Promise<{
|
|
17
|
+
user: User;
|
|
18
|
+
posts: readonly EnrichedPost[];
|
|
19
|
+
}>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=dataFetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataFetcher.d.ts","sourceRoot":"","sources":["../../src/utils/dataFetcher.ts"],"names":[],"mappings":"AAAA,UAAU,IAAI;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,IAAI;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,YAAa,SAAQ,IAAI;IACjC,YAAY,EAAE,MAAM,CAAC;CACtB;AA0CD,eAAO,MAAM,kBAAkB,GAAU,QAAQ,MAAM,EAAE,UAAS,MAA+C,KAAG,OAAO,CAAC;IAC1H,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;CAChC,CA8CA,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchUserWithPosts = void 0;
|
|
4
|
+
const fetchWithErrorHandling = async (url) => {
|
|
5
|
+
try {
|
|
6
|
+
const response = await fetch(url);
|
|
7
|
+
if (!response.ok) {
|
|
8
|
+
const error = {
|
|
9
|
+
message: `HTTP error ${response.status}: ${response.statusText}`,
|
|
10
|
+
endpoint: url,
|
|
11
|
+
statusCode: response.status,
|
|
12
|
+
};
|
|
13
|
+
throw new Error(JSON.stringify(error));
|
|
14
|
+
}
|
|
15
|
+
const data = await response.json();
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error instanceof Error && error.message.startsWith('{')) {
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
throw new Error(JSON.stringify({
|
|
23
|
+
message: `Network error: ${error}`,
|
|
24
|
+
endpoint: url,
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const fetchUserWithPosts = async (userId, baseUrl = 'https://jsonplaceholder.typicode.com') => {
|
|
29
|
+
try {
|
|
30
|
+
// Step 1: Fetch user information
|
|
31
|
+
const user = await fetchWithErrorHandling(`${baseUrl}/users/${userId}`);
|
|
32
|
+
// Step 2: Fetch user's posts
|
|
33
|
+
const posts = await fetchWithErrorHandling(`${baseUrl}/posts?userId=${userId}`);
|
|
34
|
+
// Step 3: Enrich each post with comment counts
|
|
35
|
+
const enrichedPosts = await Promise.all(posts.map(async (post) => {
|
|
36
|
+
try {
|
|
37
|
+
const comments = await fetchWithErrorHandling(`${baseUrl}/comments?postId=${post.id}`);
|
|
38
|
+
return {
|
|
39
|
+
...post,
|
|
40
|
+
commentCount: comments.length,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
// If comment fetching fails, return post with zero comments
|
|
45
|
+
console.warn(`Failed to fetch comments for post ${post.id}:`, error);
|
|
46
|
+
return {
|
|
47
|
+
...post,
|
|
48
|
+
commentCount: 0,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
return {
|
|
53
|
+
user,
|
|
54
|
+
posts: enrichedPosts,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error instanceof Error) {
|
|
59
|
+
try {
|
|
60
|
+
const fetchError = JSON.parse(error.message);
|
|
61
|
+
throw new Error(`Failed to fetch user data: ${fetchError.message} (endpoint: ${fetchError.endpoint})`);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
throw new Error(`Failed to fetch user data: ${error.message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`Failed to fetch user data: ${error}`);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.fetchUserWithPosts = fetchUserWithPosts;
|
|
71
|
+
//# sourceMappingURL=dataFetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataFetcher.js","sourceRoot":"","sources":["../../src/utils/dataFetcher.ts"],"names":[],"mappings":";;;AAgCA,MAAM,sBAAsB,GAAG,KAAK,EAAK,GAAW,EAAc,EAAE;IAClE,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,KAAK,GAAe;gBACxB,OAAO,EAAE,cAAc,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE;gBAChE,QAAQ,EAAE,GAAG;gBACb,UAAU,EAAE,QAAQ,CAAC,MAAM;aAC5B,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QACzC,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,OAAO,IAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5D,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,IAAI,CA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K,CAAC,OAAO,CAAe,CAAC;gBAC3D,MAAM,IAAI,KAAK,CAAC,8BAA8B,UAAU,CAAC,OAAO,eAAe,UAAU,CAAC,QAAQ,GAAG,CAAC,CAAC;YACzG,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC;AACH,CAAC,CAAC;AAjDW,QAAA,kBAAkB,sBAiD7B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface ImageProcessingOptions {
|
|
2
|
+
readonly width?: number;
|
|
3
|
+
readonly height?: number;
|
|
4
|
+
readonly fit?: 'cover' | 'contain' | 'fill' | 'inside' | 'outside';
|
|
5
|
+
readonly format?: 'jpeg' | 'png' | 'webp';
|
|
6
|
+
readonly quality?: number;
|
|
7
|
+
}
|
|
8
|
+
interface ProcessingResult {
|
|
9
|
+
readonly filePath: string;
|
|
10
|
+
readonly success: boolean;
|
|
11
|
+
readonly outputPath?: string;
|
|
12
|
+
readonly error?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const processBatchImages: (inputPaths: readonly string[], outputDir: string, options?: ImageProcessingOptions) => Promise<readonly ProcessingResult[]>;
|
|
15
|
+
export type { ImageProcessingOptions, ProcessingResult };
|
|
16
|
+
//# sourceMappingURL=imageProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageProcessor.d.ts","sourceRoot":"","sources":["../../src/utils/imageProcessor.ts"],"names":[],"mappings":"AAIA,UAAU,sBAAsB;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IACnE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,UAAU,gBAAgB;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAwFD,eAAO,MAAM,kBAAkB,GAC7B,YAAY,SAAS,MAAM,EAAE,EAC7B,WAAW,MAAM,EACjB,UAAS,sBAA2B,KACnC,OAAO,CAAC,SAAS,gBAAgB,EAAE,CASrC,CAAC;AAEF,YAAY,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.processBatchImages = void 0;
|
|
40
|
+
const fs = __importStar(require("fs/promises"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const sharp_1 = __importDefault(require("sharp"));
|
|
43
|
+
const SUPPORTED_FORMATS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'tiff', 'svg'];
|
|
44
|
+
const getFileExtension = (filePath) => {
|
|
45
|
+
return path.extname(filePath).toLowerCase().slice(1);
|
|
46
|
+
};
|
|
47
|
+
const isValidImageFormat = (filePath) => {
|
|
48
|
+
const ext = getFileExtension(filePath);
|
|
49
|
+
return SUPPORTED_FORMATS.includes(ext);
|
|
50
|
+
};
|
|
51
|
+
const ensureDirectoryExists = async (dirPath) => {
|
|
52
|
+
try {
|
|
53
|
+
await fs.access(dirPath);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const processImage = async (inputPath, outputDir, options) => {
|
|
60
|
+
try {
|
|
61
|
+
if (!isValidImageFormat(inputPath)) {
|
|
62
|
+
return {
|
|
63
|
+
filePath: inputPath,
|
|
64
|
+
success: false,
|
|
65
|
+
error: `Unsupported image format. Supported: ${SUPPORTED_FORMATS.join(', ')}`
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const fileExists = await fs.access(inputPath)
|
|
69
|
+
.then(() => true)
|
|
70
|
+
.catch(() => false);
|
|
71
|
+
if (!fileExists) {
|
|
72
|
+
return {
|
|
73
|
+
filePath: inputPath,
|
|
74
|
+
success: false,
|
|
75
|
+
error: 'File does not exist'
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
await ensureDirectoryExists(outputDir);
|
|
79
|
+
const fileName = path.basename(inputPath);
|
|
80
|
+
const fileNameWithoutExt = path.parse(fileName).name;
|
|
81
|
+
const outputFormat = options.format || getFileExtension(inputPath);
|
|
82
|
+
const outputFileName = `${fileNameWithoutExt}.${outputFormat}`;
|
|
83
|
+
const outputPath = path.join(outputDir, outputFileName);
|
|
84
|
+
let transform = (0, sharp_1.default)(inputPath);
|
|
85
|
+
if (options.width || options.height) {
|
|
86
|
+
transform = transform.resize({
|
|
87
|
+
width: options.width,
|
|
88
|
+
height: options.height,
|
|
89
|
+
fit: options.fit || 'cover'
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (options.format) {
|
|
93
|
+
transform = transform.toFormat(options.format, {
|
|
94
|
+
quality: options.quality || 80
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
await transform.toFile(outputPath);
|
|
98
|
+
return {
|
|
99
|
+
filePath: inputPath,
|
|
100
|
+
success: true,
|
|
101
|
+
outputPath
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
return {
|
|
106
|
+
filePath: inputPath,
|
|
107
|
+
success: false,
|
|
108
|
+
error: error instanceof Error ? error.message : String(error)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const processBatchImages = async (inputPaths, outputDir, options = {}) => {
|
|
113
|
+
const results = [];
|
|
114
|
+
for (const inputPath of inputPaths) {
|
|
115
|
+
const result = await processImage(inputPath, outputDir, options);
|
|
116
|
+
results.push(result);
|
|
117
|
+
}
|
|
118
|
+
return results;
|
|
119
|
+
};
|
|
120
|
+
exports.processBatchImages = processBatchImages;
|
|
121
|
+
//# sourceMappingURL=imageProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageProcessor.js","sourceRoot":"","sources":["../../src/utils/imageProcessor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,2CAA6B;AAC7B,kDAA0B;AAiB1B,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAU,CAAC;AAExF,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAU,EAAE;IACpD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAW,EAAE;IACvD,MAAM,GAAG,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACvC,OAAO,iBAAiB,CAAC,QAAQ,CAAC,GAAuC,CAAC,CAAC;AAC7E,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,KAAK,EAAE,OAAe,EAAiB,EAAE;IACrE,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC,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face LCSResult {
|
|
5
|
+
readonly subsequence: string;
|
|
6
|
+
readonly length: number;
|
|
7
|
+
readonly indices1: readonly number[];
|
|
8
|
+
readonly indices2: readonly number[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Finds the longest common subsequence (LCS) between two strings using dynamic programming.
|
|
12
|
+
*
|
|
13
|
+
* Time Complexity: O(m * n) where m and n are string lengths
|
|
14
|
+
* Space Complexity: O(m * n) for the DP table
|
|
15
|
+
*
|
|
16
|
+
* @param str1 First string
|
|
17
|
+
* @param str2 Second string
|
|
18
|
+
* @returns LCS result with subsequence, length, and character indices
|
|
19
|
+
*/
|
|
20
|
+
export declare const findLongestCommonSubsequence: (str1: string, str2: string) => LCSResult;
|
|
21
|
+
/**
|
|
22
|
+
* Computes similarity ratio between two strings based on their LCS.
|
|
23
|
+
* Returns value between 0 (no similarity) and 1 (identical).
|
|
24
|
+
*
|
|
25
|
+
* @param str1 First string
|
|
26
|
+
* @param str2 Second string
|
|
27
|
+
* @returns Similarity ratio (0-1)
|
|
28
|
+
*/
|
|
29
|
+
export declare const computeLCSSimilarity: (str1: string, str2: string) => number;
|
|
30
|
+
/**
|
|
31
|
+
* Finds all longest common subsequences between two strings.
|
|
32
|
+
* Note: There can be multiple LCS of the same length.
|
|
33
|
+
*
|
|
34
|
+
* This is more computationally expensive than findLongestCommonSubsequence
|
|
35
|
+
* as it explores all possible paths.
|
|
36
|
+
*
|
|
37
|
+
* @param str1 First string
|
|
38
|
+
* @param str2 Second string
|
|
39
|
+
* @returns Array of all LCS strings
|
|
40
|
+
*/
|
|
41
|
+
export declare const findAllLongestCommonSubsequences: (str1: string, str2: string) => readonly string[];
|
|
42
|
+
//# sourceMappingURL=lcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lcs.d.ts","sourceRoot":"","sources":["../../src/utils/lcs.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,GACvC,MAAM,MAAM,EACZ,MAAM,MAAM,KACX,SAuDF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,EAAE,MAAM,MAAM,KAAG,MAajE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gCAAgC,GAC3C,MAAM,MAAM,EACZ,MAAM,MAAM,KACX,SAAS,MAAM,EA2CjB,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findAllLongestCommonSubsequences = exports.computeLCSSimilarity = exports.findLongestCommonSubsequence = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Finds the longest common subsequence (LCS) between two strings using dynamic programming.
|
|
6
|
+
*
|
|
7
|
+
* Time Complexity: O(m * n) where m and n are string lengths
|
|
8
|
+
* Space Complexity: O(m * n) for the DP table
|
|
9
|
+
*
|
|
10
|
+
* @param str1 First string
|
|
11
|
+
* @param str2 Second string
|
|
12
|
+
* @returns LCS result with subsequence, length, and character indices
|
|
13
|
+
*/
|
|
14
|
+
const findLongestCommonSubsequence = (str1, str2) => {
|
|
15
|
+
const m = str1.length;
|
|
16
|
+
const n = str2.length;
|
|
17
|
+
// DP table: dp[i][j] stores length of LCS of str1[0..i-1] and str2[0..j-1]
|
|
18
|
+
const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
19
|
+
// Build DP table bottom-up
|
|
20
|
+
for (let i = 1; i <= m; i++) {
|
|
21
|
+
for (let j = 1; j <= n; j++) {
|
|
22
|
+
if (str1[i - 1] === str2[j - 1]) {
|
|
23
|
+
// Characters match: extend previous LCS by 1
|
|
24
|
+
dp[i][j] = dp[i - 1][j - 1] + 1;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// Characters don't match: take max from excluding either character
|
|
28
|
+
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Backtrack to reconstruct the actual subsequence and indices
|
|
33
|
+
const lcsLength = dp[m][n];
|
|
34
|
+
const subsequenceChars = [];
|
|
35
|
+
const indices1 = [];
|
|
36
|
+
const indices2 = [];
|
|
37
|
+
let i = m;
|
|
38
|
+
let j = n;
|
|
39
|
+
// Trace back from dp[m][n] to dp[0][0] to build the LCS
|
|
40
|
+
while (i > 0 && j > 0) {
|
|
41
|
+
if (str1[i - 1] === str2[j - 1]) {
|
|
42
|
+
// This character is part of LCS
|
|
43
|
+
subsequenceChars.unshift(str1[i - 1]);
|
|
44
|
+
indices1.unshift(i - 1);
|
|
45
|
+
indices2.unshift(j - 1);
|
|
46
|
+
i--;
|
|
47
|
+
j--;
|
|
48
|
+
}
|
|
49
|
+
else if (dp[i - 1][j] > dp[i][j - 1]) {
|
|
50
|
+
// LCS came from excluding current char in str1
|
|
51
|
+
i--;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// LCS came from excluding current char in str2
|
|
55
|
+
j--;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
subsequence: subsequenceChars.join(''),
|
|
60
|
+
length: lcsLength,
|
|
61
|
+
indices1,
|
|
62
|
+
indices2,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
exports.findLongestCommonSubsequence = findLongestCommonSubsequence;
|
|
66
|
+
/**
|
|
67
|
+
* Computes similarity ratio between two strings based on their LCS.
|
|
68
|
+
* Returns value between 0 (no similarity) and 1 (identical).
|
|
69
|
+
*
|
|
70
|
+
* @param str1 First string
|
|
71
|
+
* @param str2 Second string
|
|
72
|
+
* @returns Similarity ratio (0-1)
|
|
73
|
+
*/
|
|
74
|
+
const computeLCSSimilarity = (str1, str2) => {
|
|
75
|
+
if (str1.length === 0 && str2.length === 0) {
|
|
76
|
+
return 1.0;
|
|
77
|
+
}
|
|
78
|
+
if (str1.length === 0 || str2.length === 0) {
|
|
79
|
+
return 0.0;
|
|
80
|
+
}
|
|
81
|
+
const lcsLength = (0, exports.findLongestCommonSubsequence)(str1, str2).length;
|
|
82
|
+
const maxLength = Math.max(str1.length, str2.length);
|
|
83
|
+
return lcsLength / maxLength;
|
|
84
|
+
};
|
|
85
|
+
exports.computeLCSSimilarity = computeLCSSimilarity;
|
|
86
|
+
/**
|
|
87
|
+
* Finds all longest common subsequences between two strings.
|
|
88
|
+
* Note: There can be multiple LCS of the same length.
|
|
89
|
+
*
|
|
90
|
+
* This is more computationally expensive than findLongestCommonSubsequence
|
|
91
|
+
* as it explores all possible paths.
|
|
92
|
+
*
|
|
93
|
+
* @param str1 First string
|
|
94
|
+
* @param str2 Second string
|
|
95
|
+
* @returns Array of all LCS strings
|
|
96
|
+
*/
|
|
97
|
+
const findAllLongestCommonSubsequences = (str1, str2) => {
|
|
98
|
+
const m = str1.length;
|
|
99
|
+
const n = str2.length;
|
|
100
|
+
// Build DP table same as before
|
|
101
|
+
const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
102
|
+
for (let i = 1; i <= m; i++) {
|
|
103
|
+
for (let j = 1; j <= n; j++) {
|
|
104
|
+
if (str1[i - 1] === str2[j - 1]) {
|
|
105
|
+
dp[i][j] = dp[i - 1][j - 1] + 1;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const allLCS = new Set();
|
|
113
|
+
// Recursive backtracking to find all possible LCS paths
|
|
114
|
+
const backtrack = (i, j, current) => {
|
|
115
|
+
if (i === 0 || j === 0) {
|
|
116
|
+
allLCS.add(current.split('').reverse().join(''));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (str1[i - 1] === str2[j - 1]) {
|
|
120
|
+
backtrack(i - 1, j - 1, current + str1[i - 1]);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
if (dp[i - 1][j] >= dp[i][j - 1]) {
|
|
124
|
+
backtrack(i - 1, j, current);
|
|
125
|
+
}
|
|
126
|
+
if (dp[i][j - 1] >= dp[i - 1][j]) {
|
|
127
|
+
backtrack(i, j - 1, current);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
backtrack(m, n, '');
|
|
132
|
+
return Array.from(allLCS);
|
|
133
|
+
};
|
|
134
|
+
exports.findAllLongestCommonSubsequences = findAllLongestCommonSubsequences;
|
|
135
|
+
//# sourceMappingURL=lcs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lcs.js","sourceRoot":"","sources":["../../src/utils/lcs.ts"],"names":[],"mappings":";;;AAUA;;;;;;;;;GASG;AACI,MAAM,4BAA4B,GAAG,CAC1C,IAAY,EACZ,IAAY,EACD,EAAE;IACb,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IACtB,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IAEtB,2EAA2E;IAC3E,MAAM,EAAE,GAAe,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,CACxD,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACrB,CAAC;IAEF,2BAA2B;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,KAAK,IAAI,CAAC,GAA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AC,KAClD,OAAO,CAAC,IAAI,CAEd,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendNotificationToUsers = void 0;
|
|
4
|
+
const sendNotificationToUsers = async (userIds, sendNotification) => {
|
|
5
|
+
await Promise.all(userIds.map((userId) => sendNotification(userId)));
|
|
6
|
+
};
|
|
7
|
+
exports.sendNotificationToUsers = sendNotificationToUsers;
|
|
8
|
+
//# sourceMappingURL=notifications.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifications.js","sourceRoot":"","sources":["../../src/utils/notifications.ts"],"names":[],"mappings":";;;AAAO,MAAM,uBAAuB,GAAG,KAAK,EAC1C,OAA0B,EAC1B,gBAAmD,EACpC,EAAE;IACjB,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC,CAAC;AALW,QAAA,uBAAuB,2BAKlC"}
|