aboutsummaryrefslogtreecommitdiff
path: root/src/api/schema.peechy
blob: 74050e90f2af8f24d25df500bbaaffbeba43d61b (plain) (blame)
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
package Api;

smol Loader {
    jsx = 1;
    js = 2;
    ts = 3;
    tsx = 4;
    css = 5;
    file = 6;
    json = 7;
}

smol ResolveMode {
  disable = 1;
  lazy = 2;
  dev = 3;
  bundle = 4;
}

smol Platform {
  browser = 1;
  node = 2;
}

smol JSXRuntime {
  automatic = 1;
  classic = 2;
}

struct JSX {
  string factory;
  JSXRuntime runtime;
  string fragment;
  bool development;

  // Probably react
  string import_source;

  bool react_fast_refresh;
}

struct StringPointer {
  uint32 offset;
  uint32 length;
}

struct JavascriptBundledModule {
  // package-relative path including file extension
  StringPointer path;

  // Source code
  StringPointer code;

  // index into JavascriptBundle.packages
  uint32 package_id;

  // The ESM export is this id ("$" + number.toString(16))
  uint32 id;

  // This lets us efficiently compare strings ignoring the extension
  byte path_extname_length;
}

struct JavascriptBundledPackage {
  StringPointer name;
  StringPointer version;
  uint32 hash;

  uint32 modules_offset;
  uint32 modules_length;
}

struct JavascriptBundle {
  // These are sorted alphabetically so you can do binary search
  JavascriptBundledModule[] modules;
  JavascriptBundledPackage[] packages;
  
  // This is ASCII-encoded so you can send it directly over HTTP
  byte[] etag;

  uint32 generated_at;
  
  // generated by hashing all ${name}@${version} in sorted order
  byte[] app_package_json_dependencies_hash;


  byte[] import_from_name;

  // This is what StringPointer refers to 
  byte[] manifest_string;
}

message JavascriptBundleContainer {
  uint32 bundle_format_version = 1;

  JavascriptBundle bundle = 2;

  // Don't technically need to store this, but it may be helpful as a sanity check
  uint32 code_length = 3;
}

smol ScanDependencyMode {
  app = 1;
  all = 2;
}

smol ModuleImportType {
  import = 1;
  require = 2;
}

struct ModuleImportRecord {
  ModuleImportType kind;
  string path;

  bool dynamic;
}

struct Module {
  string path;
  ModuleImportRecord[] imports;
}

struct StringMap {
  string[] keys;
  string[] values;
}

struct LoaderMap {
  string[] extensions;
  Loader[] loaders;
}

message TransformOptions {
  JSX jsx = 1;
  string tsconfig_override = 2;
  ResolveMode resolve = 3;

  string public_url = 4;
  string absolute_working_dir = 5;

  StringMap define = 6;

  bool preserve_symlinks = 7;

  string[] entry_points = 8;
  bool write = 9;

  string[] inject = 10;
  string output_dir = 11;

  string[] external = 12;

  LoaderMap loaders = 13;

  string[] main_fields = 14;
  Platform platform = 15;

  bool serve = 16;

  string[] extension_order = 17;

  string public_dir = 18;

  ScanDependencyMode only_scan_dependencies = 19;

  bool generate_node_module_bundle = 20;

  string node_modules_bundle_path = 21;
}

struct FileHandle {
  string path;
  uint size;
  uint fd; 
}

message Transform {
  FileHandle handle = 1;
  string path = 2;
  byte[] contents = 3;

  Loader loader = 4;
  TransformOptions options = 5;
}

enum TransformResponseStatus {
  success = 1;
  fail = 2;
}

struct OutputFile {
  byte[] data;
  string path;
}

struct TransformResponse {
  TransformResponseStatus status;
  OutputFile[] files;
  Message[] errors;
}

enum MessageKind {
  err = 1;
  warn  =2;
  note = 3;
  debug = 4;
}

struct Location {
  string file;
  string namespace;
  int32 line;
  int32 column;
  string line_text;
  string suggestion;
  uint offset;
}

message MessageData {
  string text = 1;
   Location location = 2;
}

struct Message {
  MessageKind kind;
  MessageData data;
  MessageData[] notes;
}

struct Log {
  uint32 warnings;
  uint32 errors;
  Message[] msgs;
}


smol Reloader {
  disable = 1;
  // equivalent of CMD + R 
  live = 2;
  // React Fast Refresh
  fast_refresh = 3;
}

// The WebSocket protocol
// Server: "hey, this file changed. Does anyone want it?"
// Browser: *checks array* "uhh yeah, ok. rebuild that for me"
// Server: "here u go"
// This makes the client responsible for tracking which files it needs to listen for.
// From a server perspective, this means the filesystem watching thread can send the same WebSocket message
// to every client, which is good for performance. It means if you have 5 tabs open it won't really be different than one tab
// The clients can just ignore files they don't care about
smol WebsocketMessageKind {
  welcome = 1;
  file_change_notification = 2;
  build_success = 3;
  build_fail = 4;
  manifest_success = 5;
  manifest_fail = 6;
}

smol WebsocketCommandKind {
  build = 1;
  manifest = 2;
}

// Each websocket message has two messages in it!
// This is the first.
struct WebsocketMessage {
  uint32 timestamp;
  WebsocketMessageKind kind;
}

// This is the first.
struct WebsocketMessageWelcome {
  uint32 epoch;
  Reloader javascriptReloader;
}

struct WebsocketMessageFileChangeNotification {
  uint32 id;
  Loader loader;
}

struct WebsocketCommand {
  WebsocketCommandKind kind;
  uint32 timestamp;
}

// The timestamp is used for client-side deduping
struct WebsocketCommandBuild {
  uint32 id;
}

struct WebsocketCommandManifest {
  uint32 id;
}

// We copy the module_path here incase they don't already have it
struct WebsocketMessageBuildSuccess {
  uint32 id;
  uint32 from_timestamp;

  Loader loader;
  string module_path;
  
  // This is the length of the blob that immediately follows this message.
  uint32 blob_length;
}


struct WebsocketMessageBuildFailure {
  uint32 id;
  uint32 from_timestamp;
  Loader loader;

  string module_path;
  Log log;
}

// CSS @import only for now!
struct DependencyManifest {
  uint32[] ids;
}

struct FileList {
  StringPointer[] ptrs;
  string files;
}

struct WebsocketMessageResolveIDs {
  uint32[] id;
  FileList list;
}

struct WebsocketCommandResolveIDs {
  StringPointer[] ptrs;
  string files;
}

struct WebsocketMessageManifestSuccess {
  uint32 id;
  string module_path;
  Loader loader;

  DependencyManifest manifest;
}

struct WebsocketMessageManifestFailure {
  uint32 id;
  uint32 from_timestamp;
  Loader loader;
  Log log;
}