/
protocol.ts
193 lines (159 loc) · 4.99 KB
/
protocol.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/**
* @fileoverview Lists all possible messages that can be passed back and forth
* between two environments (VScode and Webview)
*/
import { FirebaseConfig } from "../../../src/firebaseConfig";
import { User } from "../../../src/types/auth";
import { ServiceAccountUser } from "../types";
import { RCData } from "../../../src/rc";
import { EmulatorUiSelections, RunningEmulatorInfo } from "./types";
import { ExecutionResult } from "graphql";
import { SerializedError } from "../error";
export const DEFAULT_EMULATOR_UI_SELECTIONS: EmulatorUiSelections = {
projectId: "demo-something",
importStateFolderPath: "",
exportStateOnExit: false,
mode: "dataconnect",
debugLogging: false,
};
export enum UserMockKind {
ADMIN = "admin",
UNAUTHENTICATED = "unauthenticated",
AUTHENTICATED = "authenticated",
}
export type UserMock =
| { kind: UserMockKind.ADMIN | UserMockKind.UNAUTHENTICATED }
| {
kind: UserMockKind.AUTHENTICATED;
claims: string;
};
export interface WebviewToExtensionParamsMap {
/**
* Ask extension for initial data
*/
getInitialData: {};
addUser: {};
logout: { email: string };
/* Emulator panel requests */
getEmulatorUiSelections: void;
getEmulatorInfos: void;
updateEmulatorUiSelections: Partial<EmulatorUiSelections>;
/* Equivalent to the `firebase emulators:start` command.*/
launchEmulators: void;
/** Notify extension that current user has been changed in UI. */
requestChangeUser: { user: User | ServiceAccountUser };
/** Trigger project selection */
selectProject: {};
/**
* Runs `firebase init hosting` command.
* TODO(hsubox76): Generalize to work for all `firebase init` products.
*/
selectAndInitHostingFolder: {
projectId: string;
singleAppSupport: boolean;
};
/**
* Runs `firebase deploy` for hosting.
* TODO(hsubox76): Generalize to work for all `firebase deploy` targets.
*/
hostingDeploy: {
target: string;
};
/**
* Prompt user for text input
*/
promptUserForInput: { title: string; prompt: string };
/** Calls the `firebase init` CLI */
runFirebaseInit: void;
/**
* Show a UI message using the vscode interface
*/
showMessage: { msg: string; options?: {} };
/**
* Write a log to the extension logger.
*/
writeLog: { level: string; args: string[] };
/**
* Call extension runtime to open a link (a href does not work in Monospace)
*/
openLink: {
href: string;
};
/** Stops the emulators gracefully allowing for data export if required. */
stopEmulators: void;
selectEmulatorImportFolder: {};
definedDataConnectArgs: string;
/** Prompts the user to select a directory in which to place the quickstart */
chooseQuickstartDir: {};
notifyAuthUserMockChange: UserMock;
/** Deploy connectors/services to production */
"fdc.deploy": void;
/** Deploy all connectors/services to production */
"fdc.deploy-all": void;
}
export interface DataConnectResults {
query: string;
displayName: string;
results?: ExecutionResult | SerializedError;
args?: string;
}
export type ValueOrError<T> =
| { value: T; error: undefined }
| { error: string; value: undefined };
export interface ExtensionToWebviewParamsMap {
/** Triggered when the emulator UI/state changes */
notifyEmulatorUiSelectionsChanged: EmulatorUiSelections;
notifyEmulatorStateChanged: {
status: "running" | "stopped" | "starting" | "stopping";
infos: RunningEmulatorInfo | undefined;
};
notifyEmulatorImportFolder: { folder: string };
/** Triggered when new environment variables values are found. */
notifyEnv: { env: { isMonospace: boolean } };
/** Triggered when users have been updated. */
notifyUsers: { users: User[] };
/** Triggered when hosting channels have been fetched. */
notifyChannels: { channels: any[] };
/** Triggered when a new project is selected */
notifyProjectChanged: { projectId: string };
/**
* This can potentially call multiple webviews to notify of user selection.
*/
notifyUserChanged: { user: User | ServiceAccountUser };
/**
* Notifies webview when user has successfully selected a hosting folder
* and it has been written to firebase.json.
*/
notifyHostingInitDone: {
success: boolean;
projectId: string;
folderPath?: string;
framework?: string;
};
/**
* Notify webview of status of deployment attempt.
*/
notifyHostingDeploy: {
success: boolean;
consoleUrl?: string;
hostingUrl?: string;
};
/**
* Notify webview of initial discovery or change in firebase.json or
* .firebaserc
*/
notifyFirebaseConfig: {
firebaseJson: ValueOrError<FirebaseConfig> | undefined;
firebaseRC: ValueOrError<RCData> | undefined;
};
/**
* Return user-selected preview channel name
*/
notifyPreviewChannelResponse: { id: string };
// data connect specific
notifyDataConnectResults: DataConnectResults;
notifyDataConnectRequiredArgs: { args: string[] };
}
export type MessageParamsMap =
| WebviewToExtensionParamsMap
| ExtensionToWebviewParamsMap;