Skip to content

Commit b1f5e1a

Browse files
authored
feat(vscode): defined dev_server domain (#931)
1 parent 85f0f81 commit b1f5e1a

File tree

3 files changed

+470
-0
lines changed

3 files changed

+470
-0
lines changed
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
/**
2+
* Defines the protocol used by the Dart Frog daemon "dev-server" domain and
3+
* custom type guards to check if an object is a valid message.
4+
*
5+
* @see {@link https://dartfrog.vgv.dev/docs/advanced/daemon#dev_server-domain Dart Frog dev server domain}
6+
*/
7+
8+
import {
9+
DaemonEvent,
10+
DaemonRequest,
11+
isDaemonEvent,
12+
isDaemonRequest,
13+
} from "../protocol";
14+
15+
const domainName = "dev_server";
16+
17+
const startMethodName = `${domainName}.start`;
18+
19+
export class StartDaemonRequest extends DaemonRequest {
20+
constructor(
21+
id: string,
22+
workingDirectory: string,
23+
port: number,
24+
dartVmServicePort: number
25+
) {
26+
super();
27+
this.id = id;
28+
this.params = {
29+
workingDirectory: workingDirectory,
30+
port: port,
31+
dartVmServicePort: dartVmServicePort,
32+
};
33+
}
34+
35+
public readonly method: string = startMethodName;
36+
public readonly id: string;
37+
public readonly params: {
38+
workingDirectory: string;
39+
port: number;
40+
dartVmServicePort: number;
41+
};
42+
}
43+
44+
export function isStartDaemonRequest(
45+
object: any
46+
): object is StartDaemonRequest {
47+
return (
48+
isDaemonRequest(object) &&
49+
object.method === startMethodName &&
50+
typeof object.params.workingDirectory === "string" &&
51+
typeof object.params.port === "number" &&
52+
typeof object.params.dartVmServicePort === "number"
53+
);
54+
}
55+
56+
const reloadMethodName = `${domainName}.reload`;
57+
58+
export class ReloadDaemonRequest extends DaemonRequest {
59+
constructor(id: string, applicationId: string) {
60+
super();
61+
this.id = id;
62+
this.params = {
63+
applicationId: applicationId,
64+
};
65+
}
66+
67+
public readonly method: string = reloadMethodName;
68+
public readonly id: string;
69+
public readonly params: { applicationId: string };
70+
}
71+
72+
export function isReloadDaemonRequest(
73+
object: any
74+
): object is ReloadDaemonRequest {
75+
return (
76+
isDaemonRequest(object) &&
77+
object.method === reloadMethodName &&
78+
typeof object.params.applicationId === "string"
79+
);
80+
}
81+
82+
const stopMethodName = `${domainName}.stop`;
83+
84+
export class StopDaemonRequest extends DaemonRequest {
85+
constructor(id: string, applicationId: string) {
86+
super();
87+
this.id = id;
88+
this.params = {
89+
applicationId: applicationId,
90+
};
91+
}
92+
93+
public readonly method: string = stopMethodName;
94+
public readonly id: string;
95+
public readonly params: { applicationId: string };
96+
}
97+
98+
export function isStopDaemonRequest(object: any): object is StopDaemonRequest {
99+
return (
100+
isDaemonRequest(object) &&
101+
object.method === stopMethodName &&
102+
typeof object.params.applicationId === "string"
103+
);
104+
}
105+
106+
const applicationStartingEventName = `${domainName}.applicationStarting`;
107+
108+
export interface ApplicationStartingDaemonEvent extends DaemonEvent {
109+
params: {
110+
applicationId: string;
111+
requestId: string;
112+
};
113+
}
114+
115+
export function isApplicationStartingDaemonEvent(
116+
object: any
117+
): object is ApplicationStartingDaemonEvent {
118+
return (
119+
isDaemonEvent(object) &&
120+
object.event === applicationStartingEventName &&
121+
typeof object.params.applicationId === "string" &&
122+
typeof object.params.requestId === "string"
123+
);
124+
}
125+
126+
const applicationExitEventName = `${domainName}.applicationExit`;
127+
128+
export interface ApplicationExitDaemonEvent extends DaemonEvent {
129+
params: { applicationId: string; requestId: string; exitCode: number };
130+
}
131+
132+
export function isApplicationExitDaemonEvent(
133+
object: any
134+
): object is ApplicationExitDaemonEvent {
135+
return (
136+
isDaemonEvent(object) &&
137+
object.event === applicationExitEventName &&
138+
typeof object.params.applicationId === "string" &&
139+
typeof object.params.requestId === "string" &&
140+
typeof object.params.exitCode === "number"
141+
);
142+
}
143+
144+
const loggerInfoEventName = `${domainName}.loggerInfo`;
145+
146+
export interface LoggerInfoDaemonEvent extends DaemonEvent {
147+
params: {
148+
applicationId: string;
149+
requestId: string;
150+
workingDirectory: string;
151+
message: string;
152+
};
153+
}
154+
155+
export function isLoggerInfoDaemonEvent(
156+
object: any
157+
): object is LoggerInfoDaemonEvent {
158+
return (
159+
isDaemonEvent(object) &&
160+
object.event === loggerInfoEventName &&
161+
typeof object.params.applicationId === "string" &&
162+
typeof object.params.requestId === "string" &&
163+
typeof object.params.workingDirectory === "string" &&
164+
typeof object.params.message === "string"
165+
);
166+
}
167+
168+
const loggerDetailEventName = `${domainName}.loggerDetail`;
169+
170+
export interface LoggerDetailDaemonEvent extends DaemonEvent {
171+
params: {
172+
applicationId: string;
173+
requestId: string;
174+
workingDirectory: string;
175+
message: string;
176+
};
177+
}
178+
179+
export function isLoggerDetailDaemonEvent(
180+
object: any
181+
): object is LoggerDetailDaemonEvent {
182+
return (
183+
isDaemonEvent(object) &&
184+
object.event === loggerDetailEventName &&
185+
typeof object.params.applicationId === "string" &&
186+
typeof object.params.requestId === "string" &&
187+
typeof object.params.workingDirectory === "string" &&
188+
typeof object.params.message === "string"
189+
);
190+
}
191+
192+
const progessStartEventName = `${domainName}.progressStart`;
193+
194+
export interface ProgressStartDaemonEvent extends DaemonEvent {
195+
params: {
196+
applicationId: string;
197+
requestId: string;
198+
workingDirectory: string;
199+
progressMessage: string;
200+
progressId: string;
201+
};
202+
}
203+
204+
export function isProgressStartDaemonEvent(
205+
object: any
206+
): object is ProgressStartDaemonEvent {
207+
return (
208+
isDaemonEvent(object) &&
209+
object.event === progessStartEventName &&
210+
typeof object.params.applicationId === "string" &&
211+
typeof object.params.requestId === "string" &&
212+
typeof object.params.workingDirectory === "string" &&
213+
typeof object.params.progressMessage === "string" &&
214+
typeof object.params.progressId === "string"
215+
);
216+
}
217+
218+
const progressCompleteEventName = `${domainName}.progressComplete`;
219+
220+
export interface ProgressCompleteDaemonEvent extends DaemonEvent {
221+
params: {
222+
applicationId: string;
223+
requestId: string;
224+
workingDirectory: string;
225+
progressMessage: string;
226+
progressId: string;
227+
};
228+
}
229+
230+
export function isProgressCompleteDaemonEvent(
231+
object: any
232+
): object is ProgressCompleteDaemonEvent {
233+
return (
234+
isDaemonEvent(object) &&
235+
object.event === progressCompleteEventName &&
236+
typeof object.params.applicationId === "string" &&
237+
typeof object.params.requestId === "string" &&
238+
typeof object.params.workingDirectory === "string" &&
239+
typeof object.params.progressMessage === "string" &&
240+
typeof object.params.progressId === "string"
241+
);
242+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./daemon";
2+
export * from "./dev-server";

0 commit comments

Comments
 (0)