diff options
Diffstat (limited to 'src/api/schema.zig')
-rw-r--r-- | src/api/schema.zig | 326 |
1 files changed, 0 insertions, 326 deletions
diff --git a/src/api/schema.zig b/src/api/schema.zig index 3c27a7fad..45589a431 100644 --- a/src/api/schema.zig +++ b/src/api/schema.zig @@ -2693,330 +2693,4 @@ pub const Api = struct { try writer.writeValue(@TypeOf(this.log), this.log); } }; - - pub const SemverQualifier = struct { - /// pre - pre: ?[]const u8 = null, - - /// build - build: ?[]const u8 = null, - - pub fn decode(reader: anytype) anyerror!SemverQualifier { - var this = std.mem.zeroes(SemverQualifier); - - while (true) { - switch (try reader.readByte()) { - 0 => { - return this; - }, - - 1 => { - this.pre = try reader.readValue([]const u8); - }, - 2 => { - this.build = try reader.readValue([]const u8); - }, - else => { - return error.InvalidMessage; - }, - } - } - unreachable; - } - - pub fn encode(this: *const @This(), writer: anytype) anyerror!void { - if (this.pre) |pre| { - try writer.writeFieldID(1); - try writer.writeValue(@TypeOf(pre), pre); - } - if (this.build) |build| { - try writer.writeFieldID(2); - try writer.writeValue(@TypeOf(build), build); - } - try writer.endMessage(); - } - }; - - pub const Semver = struct { - /// major - major: u32 = 0, - - /// minor - minor: u32 = 0, - - /// patch - patch: u32 = 0, - - /// raw - raw: StringPointer, - - /// qualifiers - qualifiers: []const SemverQualifier, - - pub fn decode(reader: anytype) anyerror!Semver { - var this = std.mem.zeroes(Semver); - - this.major = try reader.readValue(u32); - this.minor = try reader.readValue(u32); - this.patch = try reader.readValue(u32); - this.raw = try reader.readValue(StringPointer); - this.qualifiers = try reader.readArray(SemverQualifier); - return this; - } - - pub fn encode(this: *const @This(), writer: anytype) anyerror!void { - try writer.writeInt(this.major); - try writer.writeInt(this.minor); - try writer.writeInt(this.patch); - try writer.writeValue(@TypeOf(this.raw), this.raw); - try writer.writeArray(SemverQualifier, this.qualifiers); - } - }; - - pub const NpmPackageDataKind = enum(u32) { - _none, - /// tarball - tarball, - - /// http - http, - - /// symlink - symlink, - - /// workspace - workspace, - - _, - - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); - } - }; - - pub const NpmPackageData = struct { - /// kind - kind: NpmPackageDataKind, - - /// value - value: StringPointer, - - /// integrity - integrity: StringPointer, - - /// destination - destination: StringPointer, - - pub fn decode(reader: anytype) anyerror!NpmPackageData { - var this = std.mem.zeroes(NpmPackageData); - - this.kind = try reader.readValue(NpmPackageDataKind); - this.value = try reader.readValue(StringPointer); - this.integrity = try reader.readValue(StringPointer); - this.destination = try reader.readValue(StringPointer); - return this; - } - - pub fn encode(this: *const @This(), writer: anytype) anyerror!void { - try writer.writeEnum(this.kind); - try writer.writeValue(@TypeOf(this.value), this.value); - try writer.writeValue(@TypeOf(this.integrity), this.integrity); - try writer.writeValue(@TypeOf(this.destination), this.destination); - } - }; - - pub const NpmPackage = struct { - /// id - id: u32 = 0, - - /// name - name: StringPointer, - - /// version - version: StringPointer, - - /// resolution - resolution: Semver, - - /// data - data: NpmPackageData, - - /// dependencies_hash - dependencies_hash: u32 = 0, - - /// dev_dependencies_hash - dev_dependencies_hash: u32 = 0, - - /// peer_dependencies_hash - peer_dependencies_hash: u32 = 0, - - /// optional_dependencies_hash - optional_dependencies_hash: u32 = 0, - - /// dependencies - dependencies: []const DependencyResolution, - - pub fn decode(reader: anytype) anyerror!NpmPackage { - var this = std.mem.zeroes(NpmPackage); - - this.id = try reader.readValue(u32); - this.name = try reader.readValue(StringPointer); - this.version = try reader.readValue(StringPointer); - this.resolution = try reader.readValue(Semver); - this.data = try reader.readValue(NpmPackageData); - this.dependencies_hash = try reader.readValue(u32); - this.dev_dependencies_hash = try reader.readValue(u32); - this.peer_dependencies_hash = try reader.readValue(u32); - this.optional_dependencies_hash = try reader.readValue(u32); - this.dependencies = try reader.readArray(DependencyResolution); - return this; - } - - pub fn encode(this: *const @This(), writer: anytype) anyerror!void { - try writer.writeInt(this.id); - try writer.writeValue(@TypeOf(this.name), this.name); - try writer.writeValue(@TypeOf(this.version), this.version); - try writer.writeValue(@TypeOf(this.resolution), this.resolution); - try writer.writeValue(@TypeOf(this.data), this.data); - try writer.writeInt(this.dependencies_hash); - try writer.writeInt(this.dev_dependencies_hash); - try writer.writeInt(this.peer_dependencies_hash); - try writer.writeInt(this.optional_dependencies_hash); - try writer.writeArray(DependencyResolution, this.dependencies); - } - }; - - pub const DependencyResolution = struct { - /// version - version: Semver, - - /// package - package: u32 = 0, - - /// required - required: bool = false, - - /// optional - optional: bool = false, - - /// peer - peer: bool = false, - - /// dev - dev: bool = false, - - pub fn decode(reader: anytype) anyerror!DependencyResolution { - var this = std.mem.zeroes(DependencyResolution); - - this.version = try reader.readValue(Semver); - this.package = try reader.readValue(u32); - this.required = try reader.readValue(bool); - this.optional = try reader.readValue(bool); - this.peer = try reader.readValue(bool); - this.dev = try reader.readValue(bool); - return this; - } - - pub fn encode(this: *const @This(), writer: anytype) anyerror!void { - try writer.writeValue(@TypeOf(this.version), this.version); - try writer.writeInt(this.package); - try writer.writeInt(@as(u8, @boolToInt(this.required))); - try writer.writeInt(@as(u8, @boolToInt(this.optional))); - try writer.writeInt(@as(u8, @boolToInt(this.peer))); - try writer.writeInt(@as(u8, @boolToInt(this.dev))); - } - }; - - pub const Lockfile = struct { - /// version - version: ?[]const u8 = null, - - /// registry - registry: ?[]const u8 = null, - - /// root - root: ?u32 = null, - - /// hashes - hashes: []const u32, - - /// name_hashes - name_hashes: []const u32, - - /// packages - packages: []const NpmPackage, - - /// blob - blob: []const u8, - - pub fn decode(reader: anytype) anyerror!Lockfile { - var this = std.mem.zeroes(Lockfile); - - while (true) { - switch (try reader.readByte()) { - 0 => { - return this; - }, - - 1 => { - this.version = try reader.readValue([]const u8); - }, - 2 => { - this.registry = try reader.readValue([]const u8); - }, - 3 => { - this.root = try reader.readValue(u32); - }, - 4 => { - this.hashes = try reader.readArray(u32); - }, - 5 => { - this.name_hashes = try reader.readArray(u32); - }, - 6 => { - this.packages = try reader.readArray(NpmPackage); - }, - 7 => { - this.blob = try reader.readArray(u8); - }, - else => { - return error.InvalidMessage; - }, - } - } - unreachable; - } - - pub fn encode(this: *const @This(), writer: anytype) anyerror!void { - if (this.version) |version| { - try writer.writeFieldID(1); - try writer.writeValue(@TypeOf(version), version); - } - if (this.registry) |registry| { - try writer.writeFieldID(2); - try writer.writeValue(@TypeOf(registry), registry); - } - if (this.root) |root| { - try writer.writeFieldID(3); - try writer.writeInt(root); - } - if (this.hashes) |hashes| { - try writer.writeFieldID(4); - try writer.writeArray(u32, hashes); - } - if (this.name_hashes) |name_hashes| { - try writer.writeFieldID(5); - try writer.writeArray(u32, name_hashes); - } - if (this.packages) |packages| { - try writer.writeFieldID(6); - try writer.writeArray(NpmPackage, packages); - } - if (this.blob) |blob| { - try writer.writeFieldID(7); - try writer.writeArray(u8, blob); - } - try writer.endMessage(); - } - }; }; |