Skip to content

Commit 8aeb36e

Browse files
committed
Code cleanup and typings improvement
1 parent ffeb51f commit 8aeb36e

23 files changed

+300
-288
lines changed

src/CrystalQuartz.Application.Client2/dev/dev-server.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const mimeTypeResolver = (fileName: string) => {
1919
case '.js':
2020
return 'application/javascript';
2121
default:
22-
return null;
22+
return 'application/unknown';
2323
}
2424
};
2525

@@ -110,11 +110,13 @@ const schedulerServer = new FakeSchedulerServer({
110110
},
111111
});
112112

113-
const requestHandler = (request: any, response: any) => {
114-
const requestUrl = url.parse(request.url, true);
113+
const server = http.createServer();
114+
115+
server.on('request', (request, response) => {
116+
const requestUrl = url.parse(request.url ?? '', true);
115117

116118
if (request.method === 'GET') {
117-
console.log(request.url);
119+
console.log('GET', request.url);
118120

119121
const filePath = requestUrl.query.path ? 'dist/' + requestUrl.query.path : 'dist/index.html';
120122

@@ -129,29 +131,18 @@ const requestHandler = (request: any, response: any) => {
129131
response.write('Not found');
130132
response.end();
131133
} else {
132-
request.on('data', (data: any) => {
134+
request.on('data', (data) => {
133135
data = data.toString();
134136
const POST = querystring.parse(data);
135137

136-
console.log(POST);
138+
console.log('POST', POST);
137139

138140
const result = schedulerServer.handleRequest(POST);
139141
response.writeHead(200, { 'Content-Type': 'application/json' });
140142
response.write(JSON.stringify(result));
141143
response.end();
142144
});
143145
}
144-
};
145-
146-
const server = http.createServer(requestHandler);
147-
148-
server.listen(
149-
port /*,
150-
(err: any) => {
151-
if (err) {
152-
return console.log('something bad happened', err);
153-
}
146+
});
154147

155-
console.log(`server is listening on ${port}`);
156-
}*/
157-
);
148+
server.listen(port);

src/CrystalQuartz.Application.Client2/dev/fake-scheduler-server.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@ export interface IFakeSchedulerOptions {
1616
errorEmulation?: Record<string, IErrorEmulationOptions>;
1717
}
1818

19+
type CommandResponseValue = string | number | boolean | null | undefined;
20+
type CommandHandlerResponse = {
21+
[k: string]:
22+
| CommandResponseValue
23+
| CommandResponseValue[]
24+
| CommandHandlerResponse
25+
| CommandHandlerResponse[];
26+
};
27+
1928
export class FakeSchedulerServer {
2029
private readonly _scheduler: FakeScheduler;
21-
private readonly _commandHandlers: { [command: string]: (args: any) => any };
30+
private readonly _commandHandlers: {
31+
[command: string]: (args: Record<string, string>) => CommandHandlerResponse;
32+
};
2233
private readonly _getError: (code: string) => { _err: string } | undefined;
2334

2435
public constructor(options: IFakeSchedulerOptions) {
@@ -53,7 +64,7 @@ export class FakeSchedulerServer {
5364
dnv: options.dotNetVersion,
5465
ts: options.timelineSpan,
5566
}),
56-
get_input_types: (args) => ({
67+
get_input_types: (_) => ({
5768
_ok: 1,
5869
i: [
5970
{ _: 'string', l: 'string' },
@@ -65,14 +76,14 @@ export class FakeSchedulerServer {
6576
{ _: 'ErrorTest', l: 'Error test' },
6677
],
6778
}),
68-
get_input_type_variants: (args) => ({
79+
get_input_type_variants: (_) => ({
6980
_ok: 1,
7081
i: [
7182
{ _: 'true', l: 'True' },
7283
{ _: 'false', l: 'False' },
7384
],
7485
}),
75-
get_job_types: (args) => ({
86+
get_job_types: (_) => ({
7687
_ok: 1,
7788
i: [
7889
'HelloJob|CrystalQuartz.Samples|CrystalQuartz',
@@ -138,7 +149,7 @@ export class FakeSchedulerServer {
138149
this._scheduler.deleteGroup(args.group);
139150
return this.mapCommonData(args);
140151
},
141-
get_scheduler_details: (args) => ({
152+
get_scheduler_details: (_) => ({
142153
_ok: 1,
143154
ism: this._scheduler.status === SchedulerStatus.Ready,
144155
jsc: false,
@@ -155,7 +166,7 @@ export class FakeSchedulerServer {
155166
tpt: null,
156167
v: 'In-Browser Emulation',
157168
}),
158-
get_job_details: (args) => {
169+
get_job_details: (_) => {
159170
return {
160171
_ok: true,
161172
jd: {
@@ -215,7 +226,7 @@ export class FakeSchedulerServer {
215226
const triggerType = args.triggerType;
216227

217228
let i = 0;
218-
let errors: any = null;
229+
let errors: Record<string, string> | null = null;
219230

220231
while (args['jobDataMap[' + i + '].Key']) {
221232
if (args['jobDataMap[' + i + '].InputTypeCode'] === 'ErrorTest') {
@@ -261,7 +272,7 @@ export class FakeSchedulerServer {
261272
this._scheduler.start();
262273
}
263274

264-
public handleRequest(data: any) {
275+
public handleRequest(data: Record<string, string>) {
265276
const handler = this._commandHandlers[data.command];
266277

267278
if (handler) {
@@ -291,7 +302,7 @@ export class FakeSchedulerServer {
291302
};
292303
}
293304

294-
private mapCommonData(args: any) {
305+
private mapCommonData(args: Record<string, string>) {
295306
const scheduler = this._scheduler;
296307
const data = scheduler.getData();
297308

@@ -316,22 +327,19 @@ export class FakeSchedulerServer {
316327
tr: j.triggers.map((t) => this.mapTrigger(g, t)),
317328
})),
318329
})),
319-
ev: scheduler.findEvents(+args.minEventId).map(
320-
(ev) => {
321-
const result: any = {
322-
_: `${ev.id}|${ev.date}|${ev.eventType}|${ev.scope}`,
323-
k: ev.itemKey,
324-
fid: ev.fireInstanceId,
325-
};
326-
327-
if (ev.faulted) {
328-
result['_err'] = ev.errors ? ev.errors.map((er) => ({ _: er.text, l: er.level })) : 1;
329-
}
330+
ev: scheduler.findEvents(+args.minEventId).map((ev) => {
331+
const result: CommandHandlerResponse = {
332+
_: `${ev.id}|${ev.date}|${ev.eventType}|${ev.scope}`,
333+
k: ev.itemKey,
334+
fid: ev.fireInstanceId,
335+
};
330336

331-
return result;
337+
if (ev.faulted) {
338+
result['_err'] = ev.errors ? ev.errors.map((er) => ({ _: er.text, l: er.level })) : 1;
332339
}
333-
//`${ev.id}|${ev.date}|${ev.eventType}|${ev.scope}|${ev.fireInstanceId}|${ev.itemKey}`
334-
),
340+
341+
return result;
342+
}),
335343
};
336344
}
337345
}

src/CrystalQuartz.Application.Client2/eslint.config.mjs

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -27,50 +27,6 @@ export default [
2727
},
2828
},
2929

30-
// Import order rules
31-
// {
32-
// plugins: {
33-
// import: importPlugin
34-
// },
35-
// rules: {
36-
// 'import/order': [
37-
// 'error',
38-
// {
39-
// 'groups': [
40-
// 'builtin',
41-
// 'external',
42-
// 'internal',
43-
// 'parent',
44-
// 'sibling',
45-
// 'index',
46-
// 'object',
47-
// 'type'
48-
// ],
49-
// 'pathGroups': [
50-
// {
51-
// pattern: 'john-smith',
52-
// group: 'external',
53-
// position: 'before'
54-
// },
55-
// {
56-
// pattern: '@/**',
57-
// group: 'internal'
58-
// }
59-
// ],
60-
// 'pathGroupsExcludedImportTypes': ['john-smith'],
61-
// 'newlines-between': 'always',
62-
// 'alphabetize': {
63-
// order: 'asc',
64-
// caseInsensitive: true
65-
// }
66-
// }
67-
// ],
68-
// 'import/first': 'error',
69-
// 'import/newline-after-import': 'error',
70-
// 'import/no-duplicates': 'error'
71-
// }
72-
// },
73-
7430
// TypeScript rules
7531
{
7632
languageOptions: {
@@ -99,24 +55,6 @@ export default [
9955
},
10056
},
10157

102-
// React rules
103-
// {
104-
// files: ['**/*.jsx', '**/*.tsx'],
105-
// plugins: {
106-
// react: reactPlugin,
107-
// 'react-hooks': reactHooks,
108-
// 'jsx-a11y': jsxA11y
109-
// },
110-
// rules: {
111-
// ...reactPlugin.configs.recommended.rules,
112-
// ...reactHooks.configs.recommended.rules,
113-
// ...jsxA11y.configs.recommended.rules,
114-
// 'react/react-in-jsx-scope': 'off',
115-
// 'react/jsx-uses-react': 'off',
116-
// 'react/prop-types': 'off'
117-
// }
118-
// },
119-
12058
// Prettier with import sorting (must be last)
12159
{
12260
plugins: {
@@ -142,6 +80,6 @@ export default [
14280

14381
// Ignore patterns (replaces .eslintignore)
14482
{
145-
ignores: ['**/node_modules/', '**/dist/', '**/build/', '**/*.d.ts'],
83+
ignores: ['**/node_modules/', '**/dist/', '**/dist-dev-server/', '**/build/', '**/*.d.ts'],
14684
},
14785
];

src/CrystalQuartz.Application.Client2/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"build-dev-server": "webpack --config webpack.dev-server.config.js",
1313
"run-dev-server": "node dist-dev-server",
1414
"dev-server": "npm run build-dev-server && npm run run-dev-server",
15-
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
16-
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
15+
"lint": "eslint . --ext .ts,.tsx",
16+
"lint:fix": "eslint . --ext .ts,.tsx --fix",
1717
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css,md,json}\""
1818
},
1919
"author": "",

src/CrystalQuartz.Application.Client2/src/api/index.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ export interface Trigger extends Activity {
158158
UniqueTriggerKey: string;
159159
}
160160

161-
export interface TriggerData {
162-
Trigger: Trigger;
163-
}
164-
165161
export type ObjectPropertyValue = {
166162
typeCode: 'object';
167163
nestedProperties: Property[];
@@ -182,21 +178,6 @@ export type PropertyValue =
182178
| ObjectPropertyValue
183179
| EnumerablePropertyValue;
184180

185-
// export class PropertyValue {
186-
// public constructor(
187-
// public readonly typeCode: string,
188-
// public readonly rawValue: string | null,
189-
// public readonly errorMessage: string,
190-
// public readonly nestedProperties: Property[] | null,
191-
// public readonly isOverflow: boolean,
192-
// public readonly kind: number
193-
// ) {}
194-
//
195-
// public isSingle(): boolean {
196-
// return this.typeCode === 'single' || this.typeCode === 'error' || this.typeCode === '...';
197-
// }
198-
// }
199-
200181
export class Property {
201182
public constructor(
202183
public readonly title: string,
@@ -215,7 +196,7 @@ export interface JobProperties {
215196

216197
export interface JobDetails {
217198
JobDataMap: PropertyValue | null;
218-
JobDetails: JobProperties;
199+
JobDetails: JobProperties | null;
219200
}
220201

221202
export interface TriggerDetails {

src/CrystalQuartz.Application.Client2/src/application-model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ObservableValue } from 'john-smith/reactive';
22
import { Event } from 'john-smith/reactive/event';
3-
import { Job, JobGroup, SchedulerData } from './api';
3+
import { JobGroup, SchedulerData } from './api';
44
import { SchedulerExplorer } from './scheduler-explorer';
55

66
export class ApplicationModel implements SchedulerExplorer {
@@ -13,7 +13,7 @@ export class ApplicationModel implements SchedulerExplorer {
1313
public inProgressCount = new ObservableValue<number>(0);
1414

1515
public onDataChanged = new Event<SchedulerData>();
16-
public onDataInvalidate = new Event<any>();
16+
public onDataInvalidate = new Event<void>();
1717

1818
public offlineSince: number | null = null;
1919

@@ -39,7 +39,7 @@ export class ApplicationModel implements SchedulerExplorer {
3939
* Causes application to reload all job gorups, jobs and triggers.
4040
*/
4141
public invalidateData() {
42-
this.onDataInvalidate.trigger(null);
42+
this.onDataInvalidate.trigger();
4343
}
4444

4545
public goOffline() {

src/CrystalQuartz.Application.Client2/src/command-progress/command-progress-view-model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ICommand } from '../commands/contracts';
33
import { CommandService } from '../services';
44

55
export default class CommandProgressViewModel {
6-
private _commands: ICommand<any>[] = [];
6+
private _commands: ICommand<unknown>[] = [];
77

88
public readonly active = new ObservableValue<boolean>(false);
99
public readonly commandsCount = new ObservableValue<number>(0);
@@ -14,12 +14,12 @@ export default class CommandProgressViewModel {
1414
commandService.onCommandComplete.listen((command) => this.removeCommand(command));
1515
}
1616

17-
private addCommand(command: ICommand<any>) {
17+
private addCommand(command: ICommand<unknown>) {
1818
this._commands.push(command);
1919
this.updateState();
2020
}
2121

22-
private removeCommand(command: ICommand<any>) {
22+
private removeCommand(command: ICommand<unknown>) {
2323
this._commands = this._commands.filter((c) => c !== command);
2424
this.updateState();
2525
}
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
import { CommandData, ICommand } from './contracts';
22

3-
export abstract class AbstractCommand<T> implements ICommand<T> {
4-
public abstract code: string;
5-
public data: any;
6-
public abstract message: string;
7-
8-
protected constructor() {
9-
this.data = {};
10-
}
11-
}
12-
133
export abstract class AbstractTypedCommand<TResult, TDto> implements ICommand<TResult> {
14-
public abstract code: string;
15-
public abstract message: string;
4+
public abstract readonly code: string;
5+
public abstract readonly message: string;
166

177
protected constructor(public readonly data: CommandData) {}
188

19-
public abstract mapper(dto: TDto): TResult;
9+
public abstract typedMapper(dto: TDto): TResult;
10+
11+
public readonly mapper = (unknownDto: unknown) => this.typedMapper(unknownDto as TDto);
2012
}

0 commit comments

Comments
 (0)