diff options
Diffstat (limited to 'src/api/schema.zig')
-rw-r--r-- | src/api/schema.zig | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/api/schema.zig b/src/api/schema.zig index 61d6b82d1..5f4532522 100644 --- a/src/api/schema.zig +++ b/src/api/schema.zig @@ -2047,6 +2047,134 @@ pub const Api = struct { } }; + pub const Scan = struct { + /// path + path: ?[]const u8 = null, + + /// contents + contents: []const u8, + + /// loader + loader: ?Loader = null, + + pub fn decode(reader: anytype) anyerror!Scan { + var this = std.mem.zeroes(Scan); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.path = try reader.readValue([]const u8); + }, + 2 => { + this.contents = try reader.readArray(u8); + }, + 3 => { + this.loader = try reader.readValue(Loader); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.path) |path| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(path), path); + } + if (this.contents) |contents| { + try writer.writeFieldID(2); + try writer.writeArray(u8, contents); + } + if (this.loader) |loader| { + try writer.writeFieldID(3); + try writer.writeEnum(loader); + } + try writer.endMessage(); + } + }; + + pub const ScanResult = struct { + /// exports + exports: []const []const u8, + + /// imports + imports: []const ScannedImport, + + pub fn decode(reader: anytype) anyerror!ScanResult { + var this = std.mem.zeroes(ScanResult); + + this.exports = try reader.readArray([]const u8); + this.imports = try reader.readArray(ScannedImport); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeArray([]const u8, this.exports); + try writer.writeArray(ScannedImport, this.imports); + } + }; + + pub const ScannedImport = struct { + /// path + path: []const u8, + + /// kind + kind: ImportKind, + + pub fn decode(reader: anytype) anyerror!ScannedImport { + var this = std.mem.zeroes(ScannedImport); + + this.path = try reader.readValue([]const u8); + this.kind = try reader.readValue(ImportKind); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.path), this.path); + try writer.writeEnum(this.kind); + } + }; + + pub const ImportKind = enum(u8) { + _none, + /// entry_point + entry_point, + + /// stmt + stmt, + + /// require + require, + + /// dynamic + dynamic, + + /// require_resolve + require_resolve, + + /// at + at, + + /// url + url, + + /// internal + internal, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + pub const TransformResponseStatus = enum(u32) { _none, /// success |