@codeclimbers/server 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +73 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/src/app.module.d.ts +4 -0
- package/dist/src/app.module.js +49 -0
- package/dist/src/app.module.js.map +1 -0
- package/dist/src/assets/startup.plist.d.ts +1 -0
- package/dist/src/assets/startup.plist.js +41 -0
- package/dist/src/assets/startup.plist.js.map +1 -0
- package/dist/src/common/infrastructure/http/controllers/health.controller.d.ts +5 -0
- package/dist/src/common/infrastructure/http/controllers/health.controller.js +29 -0
- package/dist/src/common/infrastructure/http/controllers/health.controller.js.map +1 -0
- package/dist/src/common/infrastructure/http/middleware/requestlogger.middleware.d.ts +5 -0
- package/dist/src/common/infrastructure/http/middleware/requestlogger.middleware.js +27 -0
- package/dist/src/common/infrastructure/http/middleware/requestlogger.middleware.js.map +1 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/main.js +44 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/sentry.d.ts +1 -0
- package/dist/src/sentry.js +13 -0
- package/dist/src/sentry.js.map +1 -0
- package/dist/src/v1/activities/activities.service.d.ts +21 -0
- package/dist/src/v1/activities/activities.service.js +174 -0
- package/dist/src/v1/activities/activities.service.js.map +1 -0
- package/dist/src/v1/activities/pulse.controller.d.ts +19 -0
- package/dist/src/v1/activities/pulse.controller.js +92 -0
- package/dist/src/v1/activities/pulse.controller.js.map +1 -0
- package/dist/src/v1/activities/wakatimeProxy.controller.d.ts +13 -0
- package/dist/src/v1/activities/wakatimeProxy.controller.js +64 -0
- package/dist/src/v1/activities/wakatimeProxy.controller.js.map +1 -0
- package/dist/src/v1/database/__tests__/knex.test.d.ts +1 -0
- package/dist/src/v1/database/__tests__/knex.test.js +18 -0
- package/dist/src/v1/database/__tests__/knex.test.js.map +1 -0
- package/dist/src/v1/database/__tests__/pulse.repo.test.d.ts +1 -0
- package/dist/src/v1/database/__tests__/pulse.repo.test.js +141 -0
- package/dist/src/v1/database/__tests__/pulse.repo.test.js.map +1 -0
- package/dist/src/v1/database/knex.d.ts +5 -0
- package/dist/src/v1/database/knex.js +87 -0
- package/dist/src/v1/database/knex.js.map +1 -0
- package/dist/src/v1/database/migrations.d.ts +1 -0
- package/dist/src/v1/database/migrations.js +16 -0
- package/dist/src/v1/database/migrations.js.map +1 -0
- package/dist/src/v1/database/pulse.repo.d.ts +17 -0
- package/dist/src/v1/database/pulse.repo.js +115 -0
- package/dist/src/v1/database/pulse.repo.js.map +1 -0
- package/dist/src/v1/database/queries/getCategoryTimeOverview.sql +6 -0
- package/dist/src/v1/database/queries/getLongestDayInRangeMinutes.sql +11 -0
- package/dist/src/v1/database/queries/getStatusBarDetails.sql +42 -0
- package/dist/src/v1/dtos/createWakatimePulse.dto.d.ts +19 -0
- package/dist/src/v1/dtos/createWakatimePulse.dto.js +97 -0
- package/dist/src/v1/dtos/createWakatimePulse.dto.js.map +1 -0
- package/dist/src/v1/dtos/getCategoryTimeOverview.dto.d.ts +4 -0
- package/dist/src/v1/dtos/getCategoryTimeOverview.dto.js +25 -0
- package/dist/src/v1/dtos/getCategoryTimeOverview.dto.js.map +1 -0
- package/dist/src/v1/dtos/getWeekOverview.dto.d.ts +3 -0
- package/dist/src/v1/dtos/getWeekOverview.dto.js +21 -0
- package/dist/src/v1/dtos/getWeekOverview.dto.js.map +1 -0
- package/dist/src/v1/startup/darwinStartup.service.d.ts +8 -0
- package/dist/src/v1/startup/darwinStartup.service.js +114 -0
- package/dist/src/v1/startup/darwinStartup.service.js.map +1 -0
- package/dist/src/v1/startup/linuxStartup.service.d.ts +8 -0
- package/dist/src/v1/startup/linuxStartup.service.js +104 -0
- package/dist/src/v1/startup/linuxStartup.service.js.map +1 -0
- package/dist/src/v1/startup/startup.controller.d.ts +8 -0
- package/dist/src/v1/startup/startup.controller.js +46 -0
- package/dist/src/v1/startup/startup.controller.js.map +1 -0
- package/dist/src/v1/startup/startup.util.d.ts +5 -0
- package/dist/src/v1/startup/startup.util.js +19 -0
- package/dist/src/v1/startup/startup.util.js.map +1 -0
- package/dist/src/v1/startup/startupService.factory.d.ts +9 -0
- package/dist/src/v1/startup/startupService.factory.js +41 -0
- package/dist/src/v1/startup/startupService.factory.js.map +1 -0
- package/dist/src/v1/startup/unsupportedStartup.service.d.ts +6 -0
- package/dist/src/v1/startup/unsupportedStartup.service.js +29 -0
- package/dist/src/v1/startup/unsupportedStartup.service.js.map +1 -0
- package/dist/src/v1/v1.module.d.ts +2 -0
- package/dist/src/v1/v1.module.js +41 -0
- package/dist/src/v1/v1.module.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/utils/__tests__/activites.util.test.d.ts +1 -0
- package/dist/utils/__tests__/activites.util.test.js +18 -0
- package/dist/utils/__tests__/activites.util.test.js.map +1 -0
- package/dist/utils/__tests__/helpers.util.test.d.ts +1 -0
- package/dist/utils/__tests__/helpers.util.test.js +120 -0
- package/dist/utils/__tests__/helpers.util.test.js.map +1 -0
- package/dist/utils/__tests__/wakatime.util.test.d.ts +1 -0
- package/dist/utils/__tests__/wakatime.util.test.js +210 -0
- package/dist/utils/__tests__/wakatime.util.test.js.map +1 -0
- package/dist/utils/activities.util.d.ts +15 -0
- package/dist/utils/activities.util.js +147 -0
- package/dist/utils/activities.util.js.map +1 -0
- package/dist/utils/allExceptions.filter.d.ts +7 -0
- package/dist/utils/allExceptions.filter.js +39 -0
- package/dist/utils/allExceptions.filter.js.map +1 -0
- package/dist/utils/codeClimberErrors.d.ts +16 -0
- package/dist/utils/codeClimberErrors.js +27 -0
- package/dist/utils/codeClimberErrors.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/environment.util.d.ts +1 -0
- package/dist/utils/environment.util.js +6 -0
- package/dist/utils/environment.util.js.map +1 -0
- package/dist/utils/helpers.util.d.ts +7 -0
- package/dist/utils/helpers.util.js +116 -0
- package/dist/utils/helpers.util.js.map +1 -0
- package/dist/utils/node.util.d.ts +7 -0
- package/dist/utils/node.util.js +26 -0
- package/dist/utils/node.util.js.map +1 -0
- package/dist/utils/sql.util.d.ts +1 -0
- package/dist/utils/sql.util.js +11 -0
- package/dist/utils/sql.util.js.map +1 -0
- package/dist/utils/sqlReader.util.d.ts +5 -0
- package/dist/utils/sqlReader.util.js +34 -0
- package/dist/utils/sqlReader.util.js.map +1 -0
- package/dist/utils/wakatime.util.d.ts +6 -0
- package/dist/utils/wakatime.util.js +63 -0
- package/dist/utils/wakatime.util.js.map +1 -0
- package/index.ts +5 -0
- package/jest.config.js +8 -0
- package/knexfile.js +14 -0
- package/nest-cli.json +15 -0
- package/package.json +77 -0
- package/src/app.module.ts +37 -0
- package/src/assets/startup.plist.ts +36 -0
- package/src/common/infrastructure/http/controllers/health.controller.ts +9 -0
- package/src/common/infrastructure/http/middleware/requestlogger.middleware.ts +22 -0
- package/src/main.ts +51 -0
- package/src/sentry.ts +14 -0
- package/src/types/activities.api.d.ts +18 -0
- package/src/types/time.api.d.ts +23 -0
- package/src/types/utils.d.ts +8 -0
- package/src/types/wakatimeProxy.api.d.ts +55 -0
- package/src/v1/activities/activities.service.ts +213 -0
- package/src/v1/activities/pulse.controller.ts +68 -0
- package/src/v1/activities/wakatimeProxy.controller.ts +33 -0
- package/src/v1/database/__tests__/knex.test.ts +18 -0
- package/src/v1/database/__tests__/pulse.repo.test.ts +209 -0
- package/src/v1/database/knex.ts +107 -0
- package/src/v1/database/migrations.ts +13 -0
- package/src/v1/database/models/pulse.d.ts +24 -0
- package/src/v1/database/pulse.repo.ts +132 -0
- package/src/v1/database/queries/getCategoryTimeOverview.sql +6 -0
- package/src/v1/database/queries/getLongestDayInRangeMinutes.sql +11 -0
- package/src/v1/database/queries/getStatusBarDetails.sql +42 -0
- package/src/v1/dtos/createWakatimePulse.dto.ts +66 -0
- package/src/v1/dtos/getCategoryTimeOverview.dto.ts +9 -0
- package/src/v1/dtos/getWeekOverview.dto.ts +6 -0
- package/src/v1/startup/darwinStartup.service.ts +114 -0
- package/src/v1/startup/linuxStartup.service.ts +101 -0
- package/src/v1/startup/startup.controller.ts +23 -0
- package/src/v1/startup/startup.util.ts +21 -0
- package/src/v1/startup/startupService.factory.ts +28 -0
- package/src/v1/startup/unsupportedStartup.service.ts +21 -0
- package/src/v1/v1.module.ts +28 -0
- package/test/app.e2e-spec.ts +24 -0
- package/test/jest-e2e.json +9 -0
- package/test/jest.globalSetup.js +15 -0
- package/test/jest.globalTeardown.js +8 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +22 -0
- package/utils/__tests__/activites.util.test.ts +18 -0
- package/utils/__tests__/helpers.util.test.ts +155 -0
- package/utils/__tests__/wakatime.util.test.ts +222 -0
- package/utils/activities.util.ts +193 -0
- package/utils/allExceptions.filter.ts +43 -0
- package/utils/codeClimberErrors.ts +32 -0
- package/utils/constants.ts +1 -0
- package/utils/environment.util.ts +1 -0
- package/utils/helpers.util.ts +131 -0
- package/utils/node.util.ts +29 -0
- package/utils/sql.util.ts +13 -0
- package/utils/sqlReader.util.ts +49 -0
- package/utils/wakatime.util.ts +78 -0
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const activities_util_1 = require("../activities.util");
|
4
|
+
describe('getSourceFromUserAgent', () => {
|
5
|
+
it(`should return 'vscode' as source of userAgents`, () => {
|
6
|
+
const userAgents = [
|
7
|
+
'wakatime/v1.98.1 (windows-10.0.22631.3880-unknown) go1.22.5 vscode/1.91.1 vscode-climbers/0.0.0',
|
8
|
+
'wakatime/v1.98.1 (windows-10.0.22631.3880-unknown) go1.22.5 vscode/1.91.1 vscode-wakatime/24.6.0',
|
9
|
+
'wakatime/v1.98.3 (windows-10.0.22631.3880-unknown) go1.22.5 vscode/1.91.1 vscode-climbers/0.0.0',
|
10
|
+
'wakatime/v1.98.3 (windows-10.0.22631.3880-unknown) go1.22.5 vscode/1.91.1 vscode-wakatime/24.6.0',
|
11
|
+
];
|
12
|
+
const result = userAgents.map((userAgent) => {
|
13
|
+
return activities_util_1.default.getSourceFromUserAgent(userAgent);
|
14
|
+
});
|
15
|
+
expect(result).toEqual(['vscode', 'vscode', 'vscode', 'vscode']);
|
16
|
+
});
|
17
|
+
});
|
18
|
+
//# sourceMappingURL=activites.util.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"activites.util.test.js","sourceRoot":"","sources":["../../../utils/__tests__/activites.util.test.ts"],"names":[],"mappings":";;AAAA,wDAA+C;AAE/C,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,UAAU,GAAG;YACjB,iGAAiG;YACjG,kGAAkG;YAClG,iGAAiG;YACjG,kGAAkG;SACnG,CAAA;QAED,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YAC1C,OAAO,yBAAc,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;IAClE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,120 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const helpers_util_1 = require("../helpers.util");
|
4
|
+
describe('forOwn', () => {
|
5
|
+
it('should iterate over own enumerable properties', () => {
|
6
|
+
const obj = { a: 1, b: 2, c: 3 };
|
7
|
+
const result = [];
|
8
|
+
(0, helpers_util_1.forOwn)(obj, (value, key) => {
|
9
|
+
result.push([key, value]);
|
10
|
+
});
|
11
|
+
expect(result).toEqual([
|
12
|
+
['a', 1],
|
13
|
+
['b', 2],
|
14
|
+
['c', 3],
|
15
|
+
]);
|
16
|
+
});
|
17
|
+
it('should handle empty objects', () => {
|
18
|
+
const obj = {};
|
19
|
+
let count = 0;
|
20
|
+
(0, helpers_util_1.forOwn)(obj, () => {
|
21
|
+
count++;
|
22
|
+
});
|
23
|
+
expect(count).toBe(0);
|
24
|
+
});
|
25
|
+
});
|
26
|
+
describe('isPlainObject', () => {
|
27
|
+
it('should return true for plain objects', () => {
|
28
|
+
expect((0, helpers_util_1.isPlainObject)({})).toBe(true);
|
29
|
+
expect((0, helpers_util_1.isPlainObject)({ a: 1 })).toBe(true);
|
30
|
+
expect((0, helpers_util_1.isPlainObject)(Object.create(null))).toBe(true);
|
31
|
+
});
|
32
|
+
it('should return false for non-plain objects', () => {
|
33
|
+
expect((0, helpers_util_1.isPlainObject)(null)).toBe(false);
|
34
|
+
expect((0, helpers_util_1.isPlainObject)(undefined)).toBe(false);
|
35
|
+
expect((0, helpers_util_1.isPlainObject)(123)).toBe(false);
|
36
|
+
expect((0, helpers_util_1.isPlainObject)('string')).toBe(false);
|
37
|
+
expect((0, helpers_util_1.isPlainObject)([])).toBe(false);
|
38
|
+
expect((0, helpers_util_1.isPlainObject)(new Date())).toBe(false);
|
39
|
+
});
|
40
|
+
});
|
41
|
+
describe('snakeCase', () => {
|
42
|
+
it('should convert strings to snake case', () => {
|
43
|
+
expect((0, helpers_util_1.snakeCase)('hello world')).toBe('hello_world');
|
44
|
+
expect((0, helpers_util_1.snakeCase)('helloWorld')).toBe('hello_world');
|
45
|
+
expect((0, helpers_util_1.snakeCase)('HelloWorld')).toBe('hello_world');
|
46
|
+
expect((0, helpers_util_1.snakeCase)('hello-world')).toBe('hello_world');
|
47
|
+
});
|
48
|
+
it('should handle non-string inputs', () => {
|
49
|
+
expect((0, helpers_util_1.snakeCase)(null)).toBe('');
|
50
|
+
expect((0, helpers_util_1.snakeCase)(123)).toBe('');
|
51
|
+
});
|
52
|
+
});
|
53
|
+
describe('camelCase', () => {
|
54
|
+
it('should convert strings to camel case', () => {
|
55
|
+
expect((0, helpers_util_1.camelCase)('hello world')).toBe('helloWorld');
|
56
|
+
expect((0, helpers_util_1.camelCase)('hello-world')).toBe('helloWorld');
|
57
|
+
expect((0, helpers_util_1.camelCase)('hello_world')).toBe('helloWorld');
|
58
|
+
expect((0, helpers_util_1.camelCase)('Hello World')).toBe('helloWorld');
|
59
|
+
expect((0, helpers_util_1.camelCase)('HELLO WORLD')).toBe('helloWorld');
|
60
|
+
});
|
61
|
+
it('should handle non-string inputs', () => {
|
62
|
+
expect((0, helpers_util_1.camelCase)(null)).toBe('');
|
63
|
+
expect((0, helpers_util_1.camelCase)(123)).toBe('');
|
64
|
+
});
|
65
|
+
});
|
66
|
+
describe('maxBy', () => {
|
67
|
+
it('should return the maximum value by the given key', () => {
|
68
|
+
const arr = [
|
69
|
+
{ a: 1, b: 3 },
|
70
|
+
{ a: 2, b: 1 },
|
71
|
+
{ a: 3, b: 2 },
|
72
|
+
];
|
73
|
+
expect((0, helpers_util_1.maxBy)(arr, (x) => x.a)).toEqual({ a: 3, b: 2 });
|
74
|
+
expect((0, helpers_util_1.maxBy)(arr, (x) => x.b)).toEqual({ a: 1, b: 3 });
|
75
|
+
});
|
76
|
+
it('should return undefined for empty arrays', () => {
|
77
|
+
expect((0, helpers_util_1.maxBy)([], () => {
|
78
|
+
return;
|
79
|
+
})).toBeUndefined();
|
80
|
+
});
|
81
|
+
});
|
82
|
+
describe('minBy', () => {
|
83
|
+
it('should return the minimum value by the given key', () => {
|
84
|
+
const arr = [
|
85
|
+
{ a: 1, b: 2 },
|
86
|
+
{ a: 2, b: 1 },
|
87
|
+
{ a: 3, b: 3 },
|
88
|
+
];
|
89
|
+
expect((0, helpers_util_1.minBy)(arr, (x) => x.a)).toEqual({ a: 1, b: 2 });
|
90
|
+
expect((0, helpers_util_1.minBy)(arr, (x) => x.b)).toEqual({ a: 2, b: 1 });
|
91
|
+
});
|
92
|
+
it('should return undefined for empty arrays', () => {
|
93
|
+
expect((0, helpers_util_1.minBy)([], () => {
|
94
|
+
return;
|
95
|
+
})).toBeUndefined();
|
96
|
+
});
|
97
|
+
});
|
98
|
+
describe('groupBy', () => {
|
99
|
+
it('should group items by the given key', () => {
|
100
|
+
const arr = [
|
101
|
+
{ a: 1, b: 2 },
|
102
|
+
{ a: 2, b: 1 },
|
103
|
+
{ a: 1, b: 3 },
|
104
|
+
];
|
105
|
+
const result = (0, helpers_util_1.groupBy)(arr, 'a');
|
106
|
+
expect(result).toEqual({
|
107
|
+
1: [
|
108
|
+
{ a: 1, b: 2 },
|
109
|
+
{ a: 1, b: 3 },
|
110
|
+
],
|
111
|
+
2: [{ a: 2, b: 1 }],
|
112
|
+
});
|
113
|
+
});
|
114
|
+
it('should handle empty arrays', () => {
|
115
|
+
const arr = [];
|
116
|
+
const result = (0, helpers_util_1.groupBy)(arr, 'a');
|
117
|
+
expect(result).toEqual({});
|
118
|
+
});
|
119
|
+
});
|
120
|
+
//# sourceMappingURL=helpers.util.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.util.test.js","sourceRoot":"","sources":["../../../utils/__tests__/helpers.util.test.ts"],"names":[],"mappings":";;AACA,kDAQwB;AAExB,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAA;QAChC,MAAM,MAAM,GAAuB,EAAE,CAAA;QAErC,IAAA,qBAAM,EAAC,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACzB,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;QAC3B,CAAC,CAAC,CAAA;QAE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1 = require("../wakatime.util");
|
4
|
+
describe('parseIni', () => {
|
5
|
+
it('should parse a valid INI string with one section', () => {
|
6
|
+
const input = `
|
7
|
+
[section1]
|
8
|
+
key1 = value1
|
9
|
+
key2 = value2
|
10
|
+
`;
|
11
|
+
const expected = {
|
12
|
+
section1: {
|
13
|
+
key1: 'value1',
|
14
|
+
key2: 'value2',
|
15
|
+
},
|
16
|
+
};
|
17
|
+
expect((0, wakatime_util_1.parseIni)(input)).toEqual(expected);
|
18
|
+
});
|
19
|
+
it('should parse a valid INI string with multiple sections', () => {
|
20
|
+
const input = `
|
21
|
+
[section1]
|
22
|
+
key1 = value1
|
23
|
+
key2 = value2
|
24
|
+
|
25
|
+
[section2]
|
26
|
+
key3 = value3
|
27
|
+
key4 = value4
|
28
|
+
`;
|
29
|
+
const expected = {
|
30
|
+
section1: {
|
31
|
+
key1: 'value1',
|
32
|
+
key2: 'value2',
|
33
|
+
},
|
34
|
+
section2: {
|
35
|
+
key3: 'value3',
|
36
|
+
key4: 'value4',
|
37
|
+
},
|
38
|
+
};
|
39
|
+
expect((0, wakatime_util_1.parseIni)(input)).toEqual(expected);
|
40
|
+
});
|
41
|
+
it('should handle empty input', () => {
|
42
|
+
const input = '';
|
43
|
+
const expected = {};
|
44
|
+
expect((0, wakatime_util_1.parseIni)(input)).toEqual(expected);
|
45
|
+
});
|
46
|
+
it('should handle input with only whitespace', () => {
|
47
|
+
const input = ' \n \t ';
|
48
|
+
const expected = {};
|
49
|
+
expect((0, wakatime_util_1.parseIni)(input)).toEqual(expected);
|
50
|
+
});
|
51
|
+
it('should ignore lines without a section', () => {
|
52
|
+
const input = `
|
53
|
+
key1 = value1
|
54
|
+
[section1]
|
55
|
+
key2 = value2
|
56
|
+
`;
|
57
|
+
const expected = {
|
58
|
+
section1: {
|
59
|
+
key2: 'value2',
|
60
|
+
},
|
61
|
+
};
|
62
|
+
expect((0, wakatime_util_1.parseIni)(input)).toEqual(expected);
|
63
|
+
});
|
64
|
+
it('should handle malformed lines within a section', () => {
|
65
|
+
const input = `
|
66
|
+
[section1]
|
67
|
+
key1 = value1
|
68
|
+
malformed line
|
69
|
+
key2 = value2
|
70
|
+
`;
|
71
|
+
const expected = {
|
72
|
+
section1: {
|
73
|
+
key1: 'value1',
|
74
|
+
key2: 'value2',
|
75
|
+
},
|
76
|
+
};
|
77
|
+
expect((0, wakatime_util_1.parseIni)(input)).toEqual(expected);
|
78
|
+
});
|
79
|
+
it('should handle keys without values', () => {
|
80
|
+
const input = `
|
81
|
+
[section1]
|
82
|
+
key1 = value1
|
83
|
+
key2 =
|
84
|
+
key3 = value3
|
85
|
+
`;
|
86
|
+
const expected = {
|
87
|
+
section1: {
|
88
|
+
key1: 'value1',
|
89
|
+
key3: 'value3',
|
90
|
+
},
|
91
|
+
};
|
92
|
+
expect((0, wakatime_util_1.parseIni)(input)).toEqual(expected);
|
93
|
+
});
|
94
|
+
it('should handle section names with spaces', () => {
|
95
|
+
const input = `
|
96
|
+
[Section One]
|
97
|
+
key1 = value1
|
98
|
+
[Section Two]
|
99
|
+
key2 = value2
|
100
|
+
`;
|
101
|
+
const expected = {
|
102
|
+
'Section One': {
|
103
|
+
key1: 'value1',
|
104
|
+
},
|
105
|
+
'Section Two': {
|
106
|
+
key2: 'value2',
|
107
|
+
},
|
108
|
+
};
|
109
|
+
expect((0, wakatime_util_1.parseIni)(input)).toEqual(expected);
|
110
|
+
});
|
111
|
+
});
|
112
|
+
describe('stringifyIni', () => {
|
113
|
+
it('should return an empty string for empty input', () => {
|
114
|
+
const input = {};
|
115
|
+
const expected = '\n';
|
116
|
+
expect((0, wakatime_util_1.stringifyIni)(input)).toBe(expected);
|
117
|
+
});
|
118
|
+
it('should correctly stringify a single section with multiple entries', () => {
|
119
|
+
const input = {
|
120
|
+
section1: {
|
121
|
+
key1: 'value1',
|
122
|
+
key2: 'value2',
|
123
|
+
key3: 'value3',
|
124
|
+
},
|
125
|
+
};
|
126
|
+
const expected = `[section1]
|
127
|
+
key1 = value1
|
128
|
+
key2 = value2
|
129
|
+
key3 = value3\n`;
|
130
|
+
expect((0, wakatime_util_1.stringifyIni)(input)).toBe(expected);
|
131
|
+
});
|
132
|
+
it('should correctly stringify multiple sections with multiple entries', () => {
|
133
|
+
const input = {
|
134
|
+
section1: {
|
135
|
+
key1: 'value1',
|
136
|
+
key2: 'value2',
|
137
|
+
},
|
138
|
+
section2: {
|
139
|
+
key3: 'value3',
|
140
|
+
key4: 'value4',
|
141
|
+
},
|
142
|
+
};
|
143
|
+
const expected = `[section1]
|
144
|
+
key1 = value1
|
145
|
+
key2 = value2
|
146
|
+
|
147
|
+
[section2]
|
148
|
+
key3 = value3
|
149
|
+
key4 = value4\n`;
|
150
|
+
expect((0, wakatime_util_1.stringifyIni)(input)).toBe(expected);
|
151
|
+
});
|
152
|
+
it('should handle sections with no entries', () => {
|
153
|
+
const input = {
|
154
|
+
section1: {},
|
155
|
+
section2: {
|
156
|
+
key1: 'value1',
|
157
|
+
},
|
158
|
+
section3: {},
|
159
|
+
};
|
160
|
+
const expected = `[section1]
|
161
|
+
|
162
|
+
|
163
|
+
[section2]
|
164
|
+
key1 = value1
|
165
|
+
|
166
|
+
[section3]
|
167
|
+
\n`;
|
168
|
+
expect((0, wakatime_util_1.stringifyIni)(input)).toBe(expected);
|
169
|
+
});
|
170
|
+
it('should handle a mix of sections with and without entries', () => {
|
171
|
+
const input = {
|
172
|
+
section1: {
|
173
|
+
key1: 'value1',
|
174
|
+
},
|
175
|
+
section2: {},
|
176
|
+
section3: {
|
177
|
+
key2: 'value2',
|
178
|
+
key3: 'value3',
|
179
|
+
},
|
180
|
+
section4: {},
|
181
|
+
};
|
182
|
+
const expected = `[section1]
|
183
|
+
key1 = value1
|
184
|
+
|
185
|
+
[section2]
|
186
|
+
|
187
|
+
|
188
|
+
[section3]
|
189
|
+
key2 = value2
|
190
|
+
key3 = value3
|
191
|
+
|
192
|
+
[section4]
|
193
|
+
\n`;
|
194
|
+
console.log((0, wakatime_util_1.stringifyIni)(input));
|
195
|
+
expect((0, wakatime_util_1.stringifyIni)(input)).toBe(expected);
|
196
|
+
});
|
197
|
+
it('should handle values containing spaces', () => {
|
198
|
+
const input = {
|
199
|
+
section1: {
|
200
|
+
key1: 'value with spaces',
|
201
|
+
key2: 'another value with spaces',
|
202
|
+
},
|
203
|
+
};
|
204
|
+
const expected = `[section1]
|
205
|
+
key1 = value with spaces
|
206
|
+
key2 = another value with spaces\n`;
|
207
|
+
expect((0, wakatime_util_1.stringifyIni)(input)).toBe(expected);
|
208
|
+
});
|
209
|
+
});
|
210
|
+
//# sourceMappingURL=wakatime.util.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"wakatime.util.test.js","sourceRoot":"","sources":["../../../utils/__tests__/wakatime.util.test.ts"],"names":[],"mappings":";;AAAA,oDAAoE;AAEpE,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,KAAK,GAAG;;;;KAIb,CAAA;QACD,MAAM,QAAQ,GAAc;YAC1B,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;aACf;SACF,CAAA;QACD,MAAM,CAAC,IAAA,wBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,MAAM,KAAK,GAAG;;;;;;;;KAQb,CAAA;QACD,MAAM,QAAQ,GAAc;YAC1B,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;aACf;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;aACf;SACF,CAAA;QACD,MAAM,CAAC,IAAA,wBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CA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QAAQ,EAAE;gBACR,IAAI,EAAE,mBAAmB;gBACzB,IAAI,EAAE,2BAA2B;aAClC;SACF,CAAA;QACD,MAAM,QAAQ,GAAG;;mCAEc,CAAA;QAC/B,MAAM,CAAC,IAAA,4BAAY,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
declare function filterUniqueByHash(arr: CodeClimbers.Pulse[]): CodeClimbers.Pulse[];
|
2
|
+
declare function pulseSuccessResponse(n: number): {
|
3
|
+
Responses: number[][];
|
4
|
+
};
|
5
|
+
declare function mapStatusBarRawToDto(statusBarRaw: CodeClimbers.WakatimePulseStatusDao[]): CodeClimbers.ActivitiesStatusBar;
|
6
|
+
declare function getSourceFromUserAgent(userAgent: string): string | undefined;
|
7
|
+
declare const _default: {
|
8
|
+
mapStatusBarRawToDto: typeof mapStatusBarRawToDto;
|
9
|
+
calculatePulseHash: (pulse: CodeClimbers.CreateWakatimePulseDto) => number;
|
10
|
+
filterUniqueByHash: typeof filterUniqueByHash;
|
11
|
+
pulseSuccessResponse: typeof pulseSuccessResponse;
|
12
|
+
cyrb53: (str: string, seed?: number) => number;
|
13
|
+
getSourceFromUserAgent: typeof getSourceFromUserAgent;
|
14
|
+
};
|
15
|
+
export default _default;
|
@@ -0,0 +1,147 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const dayjs = require("dayjs");
|
4
|
+
const helpers_util_1 = require("./helpers.util");
|
5
|
+
const cyrb53 = (str, seed = 0) => {
|
6
|
+
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
7
|
+
for (let i = 0, ch; i < str.length; i++) {
|
8
|
+
ch = str.charCodeAt(i);
|
9
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
10
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
11
|
+
}
|
12
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
|
13
|
+
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
14
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
|
15
|
+
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
16
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
17
|
+
};
|
18
|
+
const calculatePulseHash = (pulse) => {
|
19
|
+
const { editor, user_agent, origin, origin_id, operating_system, machine, ...pulseHash } = { ...pulse };
|
20
|
+
const hash = cyrb53(JSON.stringify(pulseHash));
|
21
|
+
return hash;
|
22
|
+
};
|
23
|
+
function filterUniqueByHash(arr) {
|
24
|
+
const uniqueMap = new Map();
|
25
|
+
return arr.filter((obj) => {
|
26
|
+
if (!uniqueMap.has(obj.hash)) {
|
27
|
+
uniqueMap.set(obj.hash, true);
|
28
|
+
return true;
|
29
|
+
}
|
30
|
+
return false;
|
31
|
+
});
|
32
|
+
}
|
33
|
+
function pulseSuccessResponse(n) {
|
34
|
+
const responses = [...Array(n).keys()].map((i) => [null, 201]);
|
35
|
+
return {
|
36
|
+
Responses: responses,
|
37
|
+
};
|
38
|
+
}
|
39
|
+
function defaultStatusBar() {
|
40
|
+
const now = dayjs();
|
41
|
+
return {
|
42
|
+
data: {
|
43
|
+
categories: [],
|
44
|
+
dependencies: [],
|
45
|
+
editors: [],
|
46
|
+
languages: [],
|
47
|
+
machines: [],
|
48
|
+
operating_systems: [],
|
49
|
+
projects: [],
|
50
|
+
branches: null,
|
51
|
+
entities: null,
|
52
|
+
grand_total: {
|
53
|
+
digital: '0:0',
|
54
|
+
hours: 0,
|
55
|
+
minutes: 0,
|
56
|
+
text: '0 hrs 0 mins',
|
57
|
+
total_seconds: 0,
|
58
|
+
},
|
59
|
+
range: {
|
60
|
+
date: now.toISOString(),
|
61
|
+
end: now.toISOString(),
|
62
|
+
start: now.startOf('day').toISOString(),
|
63
|
+
text: '',
|
64
|
+
timezone: 'UTC',
|
65
|
+
},
|
66
|
+
},
|
67
|
+
cached_at: now.toISOString(),
|
68
|
+
};
|
69
|
+
}
|
70
|
+
function getStatusByKey(data, dataKey) {
|
71
|
+
const keyWithoutS = dataKey.replace(/s$/, '');
|
72
|
+
const groupedData = (0, helpers_util_1.groupBy)(data, keyWithoutS);
|
73
|
+
return Object.keys(groupedData).map((key) => {
|
74
|
+
const group = groupedData[key];
|
75
|
+
const totalSeconds = group.reduce((acc, x) => acc + parseInt(x.seconds), 0);
|
76
|
+
const hours = Math.floor(totalSeconds / 3600);
|
77
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
78
|
+
const seconds = Math.floor(totalSeconds % 60);
|
79
|
+
return {
|
80
|
+
digital: `${hours}:${minutes}:${seconds}`,
|
81
|
+
hours,
|
82
|
+
minutes,
|
83
|
+
name: key || 'unknown',
|
84
|
+
percent: 100,
|
85
|
+
seconds,
|
86
|
+
text: `${hours} hrs ${seconds >= 30 ? minutes + 1 : minutes} mins`,
|
87
|
+
total_seconds: data.reduce((acc, x) => acc + parseInt(x.seconds), 0),
|
88
|
+
};
|
89
|
+
});
|
90
|
+
}
|
91
|
+
function mapStatusBarRawToDto(statusBarRaw) {
|
92
|
+
if (statusBarRaw.length <= 0)
|
93
|
+
return defaultStatusBar();
|
94
|
+
const now = new Date();
|
95
|
+
const statusbar = {
|
96
|
+
cached_at: '',
|
97
|
+
data: {
|
98
|
+
branches: null,
|
99
|
+
entities: null,
|
100
|
+
},
|
101
|
+
};
|
102
|
+
statusbar.data.editors = getStatusByKey(statusBarRaw, 'editors');
|
103
|
+
statusbar.data.languages = getStatusByKey(statusBarRaw, 'languages');
|
104
|
+
statusbar.data.machines = getStatusByKey(statusBarRaw, 'machines');
|
105
|
+
statusbar.data.operating_systems = getStatusByKey(statusBarRaw, 'operating_systems');
|
106
|
+
statusbar.data.projects = getStatusByKey(statusBarRaw, 'projects');
|
107
|
+
const grandTotalSeconds = statusBarRaw.reduce((acc, x) => acc + parseInt(x.seconds), 0);
|
108
|
+
const hours = Math.floor(grandTotalSeconds / 3600);
|
109
|
+
const minutes = Math.floor((grandTotalSeconds % 3600) / 60);
|
110
|
+
const seconds = Math.floor(grandTotalSeconds % 60);
|
111
|
+
statusbar.data.grand_total = {
|
112
|
+
digital: `${hours}:${minutes}`,
|
113
|
+
hours,
|
114
|
+
minutes,
|
115
|
+
text: `${hours} hrs ${seconds >= 30 ? minutes + 1 : minutes} mins`,
|
116
|
+
total_seconds: grandTotalSeconds,
|
117
|
+
};
|
118
|
+
const dates = statusBarRaw.map((x) => new Date(x.maxHeartbeatTime));
|
119
|
+
statusbar.data.range = {
|
120
|
+
date: new Date().toISOString(),
|
121
|
+
end: (0, helpers_util_1.maxBy)(statusBarRaw, (item) => new Date(item.maxHeartbeatTime))
|
122
|
+
?.maxHeartbeatTime || '',
|
123
|
+
start: (0, helpers_util_1.minBy)(statusBarRaw, (item) => new Date(item.minHeartbeatTime))
|
124
|
+
?.minHeartbeatTime || '',
|
125
|
+
text: '',
|
126
|
+
timezone: 'UTC',
|
127
|
+
};
|
128
|
+
statusbar.cached_at = new Date().toISOString();
|
129
|
+
return statusbar;
|
130
|
+
}
|
131
|
+
function getSourceFromUserAgent(userAgent) {
|
132
|
+
const sourceRegex = /.*?\/.*?\s([^0-9]*)\//;
|
133
|
+
const match = userAgent.match(sourceRegex);
|
134
|
+
if (match) {
|
135
|
+
return match[1];
|
136
|
+
}
|
137
|
+
return undefined;
|
138
|
+
}
|
139
|
+
exports.default = {
|
140
|
+
mapStatusBarRawToDto,
|
141
|
+
calculatePulseHash,
|
142
|
+
filterUniqueByHash,
|
143
|
+
pulseSuccessResponse,
|
144
|
+
cyrb53,
|
145
|
+
getSourceFromUserAgent,
|
146
|
+
};
|
147
|
+
//# sourceMappingURL=activities.util.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"activities.util.js","sourceRoot":"","sources":["../../utils/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AAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAE9C,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,SAAS,sBAAsB,CAAC,SAAiB;IAC/C,MAAM,WAAW,GAAG,uBAAuB,CAAA;IAC3C,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IAC1C,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,KAAK,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,kBAAe;IACb,oBAAoB;IACpB,kBAAkB;IAClB,kBAAkB;IAClB,oBAAoB;IACpB,MAAM;IACN,sBAAsB;CACvB,CAAA"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
|
2
|
+
export type BEErrorReport = {
|
3
|
+
customMessage?: string;
|
4
|
+
} & Error;
|
5
|
+
export declare class AllExceptionsFilter implements ExceptionFilter {
|
6
|
+
catch(exception: unknown, host: ArgumentsHost): Promise<void>;
|
7
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.AllExceptionsFilter = void 0;
|
10
|
+
const common_1 = require("@nestjs/common");
|
11
|
+
let AllExceptionsFilter = class AllExceptionsFilter {
|
12
|
+
async catch(exception, host) {
|
13
|
+
const ctx = host.switchToHttp();
|
14
|
+
const response = ctx.getResponse();
|
15
|
+
const status = exception instanceof common_1.HttpException
|
16
|
+
? exception.getStatus()
|
17
|
+
: common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
18
|
+
const message = exception instanceof common_1.HttpException
|
19
|
+
? exception.getResponse()
|
20
|
+
: 'Internal server error';
|
21
|
+
const errorReport = {
|
22
|
+
message: typeof message === 'object' ? JSON.stringify(message) : message,
|
23
|
+
name: exception instanceof Error ? exception.name : 'Error',
|
24
|
+
stack: exception instanceof Error ? exception.stack : undefined,
|
25
|
+
};
|
26
|
+
if (status >= 500) {
|
27
|
+
common_1.Logger.error(errorReport);
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
common_1.Logger.debug(errorReport);
|
31
|
+
}
|
32
|
+
response.status(status).json(message);
|
33
|
+
}
|
34
|
+
};
|
35
|
+
exports.AllExceptionsFilter = AllExceptionsFilter;
|
36
|
+
exports.AllExceptionsFilter = AllExceptionsFilter = __decorate([
|
37
|
+
(0, common_1.Catch)()
|
38
|
+
], AllExceptionsFilter);
|
39
|
+
//# sourceMappingURL=allExceptions.filter.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"allExceptions.filter.js","sourceRoot":"","sources":["../../utils/allExceptions.filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAOuB;AAOhB,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,KAAK,CAAC,KAAK,CAAC,SAAkB,EAAE,IAAmB;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;QAC/B,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;QAElC,MAAM,MAAM,GACV,SAAS,YAAY,sBAAa;YAChC,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE;YACvB,CAAC,CAAC,mBAAU,CAAC,qBAAqB,CAAA;QACtC,MAAM,OAAO,GACX,SAAS,YAAY,sBAAa;YAChC,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE;YACzB,CAAC,CAAC,uBAAuB,CAAA;QAE7B,MAAM,WAAW,GAAkB;YACjC,OAAO,EAAE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO;YACxE,IAAI,EAAE,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO;YAC3D,KAAK,EAAE,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SAChE,CAAA;QACD,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;YAClB,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QAE3B,CAAC;aAAM,CAAC;YACN,eAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QAC3B,CAAC;QAED,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;CACF,CAAA;AA5BY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,cAAK,GAAE;GACK,mBAAmB,CA4B/B"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
2
|
+
export declare class CodeClimberError extends Error {
|
3
|
+
message: string;
|
4
|
+
status: number;
|
5
|
+
constructor(message: string, status?: number);
|
6
|
+
}
|
7
|
+
export declare namespace CodeClimberError {
|
8
|
+
class ValidationErr extends CodeClimberError {
|
9
|
+
validationErrors?: ValidationError[];
|
10
|
+
constructor(message: string, validationErrors?: ValidationError[]);
|
11
|
+
}
|
12
|
+
export class InvalidBody extends ValidationErr {
|
13
|
+
constructor(validationErrors: ValidationError[], message?: string);
|
14
|
+
}
|
15
|
+
export {};
|
16
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.CodeClimberError = void 0;
|
4
|
+
class CodeClimberError extends Error {
|
5
|
+
constructor(message, status = 500) {
|
6
|
+
super(message);
|
7
|
+
this.name = this.constructor.name;
|
8
|
+
Error.captureStackTrace(this, this.constructor);
|
9
|
+
this.status = status;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
exports.CodeClimberError = CodeClimberError;
|
13
|
+
(function (CodeClimberError) {
|
14
|
+
class ValidationErr extends CodeClimberError {
|
15
|
+
constructor(message, validationErrors) {
|
16
|
+
super(message, 422);
|
17
|
+
this.validationErrors = validationErrors;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
class InvalidBody extends ValidationErr {
|
21
|
+
constructor(validationErrors, message) {
|
22
|
+
super(message || 'Expected request body was invalid', validationErrors);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
CodeClimberError.InvalidBody = InvalidBody;
|
26
|
+
})(CodeClimberError || (exports.CodeClimberError = CodeClimberError = {}));
|
27
|
+
//# sourceMappingURL=codeClimberErrors.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"codeClimberErrors.js","sourceRoot":"","sources":["../../utils/codeClimberErrors.ts"],"names":[],"mappings":";;;AAMA,MAAa,gBAAiB,SAAQ,KAAK;IAIzC,YAAmB,OAAe,EAAE,MAAM,GAAG,GAAG;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QACjC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAVD,4CAUC;AAED,WAAiB,gBAAgB;IAC/B,MAAM,aAAc,SAAQ,gBAAgB;QAE1C,YAAmB,OAAe,EAAE,gBAAoC;YACtE,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;YACnB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QAC1C,CAAC;KACF;IACD,MAAa,WAAY,SAAQ,aAAa;QAC5C,YAAY,gBAAmC,EAAE,OAAgB;YAC/D,KAAK,CAAC,OAAO,IAAI,mCAAmC,EAAE,gBAAgB,CAAC,CAAA;QACzE,CAAC;KACF;IAJY,4BAAW,cAIvB,CAAA;AACH,CAAC,EAbgB,gBAAgB,gCAAhB,gBAAgB,QAahC"}
|