authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-09-03 02:22:53 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-09-03 02:22:53 -07:00
log26b16273bda24a08741ddc60a9be0a62473dd653
tree66539182e81dc36722a831cf6a8a86b427aca1b1
parent25a046c27248b925e38c8ef4e2dd62c9d96f0ded

switch to nektro/zig-json for json


11 files changed, 80 insertions(+), 58 deletions(-)

deps.zig+15-1
......@@ -63,6 +63,8 @@ pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step {
6363 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "74f0ddb0a4dfa7921739b88cc381951a6b6e73ce").step);
6464 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-git", "103f4e419c35b88f802bb8234ece1c0a9aa40c03").step);
6565 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "cf43dd6c9f328073f7468b5341c69ed0bb185db3").step);
66 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-intrusive-parser", "2336d8b767eb7378762e1ba63635ca44accbd2ca").step);
67 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-json", "29587071de6dd3338e8eb76d4e0307af69a2d61a").step);
6668 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "e5481b297b6023d446d835156591ba5ce88c17be").step);
6769 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "f46d9f774df929885eef66c733a1e2a46bf16aec").step);
6870 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "b01e5a2dffcc564bddd8f514fe64bab9b5c52572").step);
......@@ -202,6 +204,12 @@ pub const package_data = struct {
202204 .entry = "/git/github.com/nektro/zig-inquirer/cf43dd6c9f328073f7468b5341c69ed0bb185db3/src/lib.zig",
203205 .deps = &[_]*Package{ &_s84v9o48ucb0 },
204206 };
207 pub var _7l3oxw6nqqws = Package{
208 .store = "/git/github.com/nektro/zig-intrusive-parser/2336d8b767eb7378762e1ba63635ca44accbd2ca",
209 .name = "intrusive-parser",
210 .entry = "/git/github.com/nektro/zig-intrusive-parser/2336d8b767eb7378762e1ba63635ca44accbd2ca/intrusive_parser.zig",
211 .deps = &[_]*Package{ &_f7dubzb7cyqe },
212 };
205213 pub var _96h80ezrvj7i = Package{
206214 .store = "/git/github.com/nektro/zig-leven/e5481b297b6023d446d835156591ba5ce88c17be",
207215 .name = "leven",
......@@ -241,6 +249,12 @@ pub const package_data = struct {
241249 .entry = "/git/github.com/nektro/zig-git/103f4e419c35b88f802bb8234ece1c0a9aa40c03/git.zig",
242250 .deps = &[_]*Package{ &_iecwp4b3bsfm, &_f7dubzb7cyqe, &_ede2wygpe1iy },
243251 };
252 pub var _ocmr9rtohgcc = Package{
253 .store = "/git/github.com/nektro/zig-json/29587071de6dd3338e8eb76d4e0307af69a2d61a",
254 .name = "json",
255 .entry = "/git/github.com/nektro/zig-json/29587071de6dd3338e8eb76d4e0307af69a2d61a/json.zig",
256 .deps = &[_]*Package{ &_f7dubzb7cyqe, &_ede2wygpe1iy, &_7l3oxw6nqqws },
257 };
244258 pub var _g982zq6e8wsv = Package{
245259 .store = "/git/github.com/nektro/zig-yaml/0d17fb99cba338aedc1abac12d78d5e5f04f0b6b",
246260 .name = "yaml",
......@@ -266,7 +280,7 @@ pub const package_data = struct {
266280 pub var _89ujp8gq842x = Package{
267281 .name = "zigmod",
268282 .entry = "/../..//src/lib.zig",
269 .deps = &[_]*Package{ &_g982zq6e8wsv, &_s84v9o48ucb0, &_2ta738wrqbaq, &_0npcrzfdlrvk, &_ejw82j2ipa0e, &_2ovav391ivak, &_c1xirp1ota5p, &_u7sysdckdymi, &_iecwp4b3bsfm, &_f7dubzb7cyqe, &_0k64oe2nuzvj },
283 .deps = &[_]*Package{ &_g982zq6e8wsv, &_s84v9o48ucb0, &_2ta738wrqbaq, &_0npcrzfdlrvk, &_ejw82j2ipa0e, &_2ovav391ivak, &_c1xirp1ota5p, &_u7sysdckdymi, &_iecwp4b3bsfm, &_f7dubzb7cyqe, &_0k64oe2nuzvj, &_ocmr9rtohgcc },
270284 };
271285 pub var _root = Package{
272286 };
licenses.txt+5
......@@ -10,6 +10,7 @@ MIT:
1010- git https://github.com/nektro/zig-extras
1111- git https://github.com/nektro/zig-git
1212- git https://github.com/nektro/zig-inquirer
13- git https://github.com/nektro/zig-json
1314- git https://github.com/nektro/zig-leven
1415- git https://github.com/nektro/zig-licenses
1516- git https://github.com/nektro/zig-licenses-text
......@@ -19,3 +20,7 @@ MIT:
1920- git https://github.com/truemedian/hzzp
2021- git https://github.com/ziglibs/known-folders
2122- git https://github.com/yaml/libyaml
23
24MPL-2.0:
25= https://spdx.org/licenses/MPL-2.0
26- git https://github.com/nektro/zig-intrusive-parser
src/cmd/aq.zig+8-7
......@@ -3,6 +3,7 @@ const string = []const u8;
33const gpa = std.heap.c_allocator;
44const zfetch = @import("zfetch");
55const extras = @import("extras");
6const json = @import("json");
67
78const u = @import("./../util/index.zig");
89
......@@ -43,7 +44,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
4344 u.fail("unknown command \"{s}\" for \"zigmod aq\"", .{args[0]});
4445}
4546
46pub fn server_fetch(url: string) !std.json.Parsed(std.json.Value) {
47pub fn server_fetch(url: string) !json.Document {
4748 const req = try zfetch.Request.init(gpa, url, null);
4849 defer req.deinit();
4950
......@@ -53,13 +54,13 @@ pub fn server_fetch(url: string) !std.json.Parsed(std.json.Value) {
5354
5455 try req.do(.GET, headers, null);
5556
56 const r = req.reader();
57 const body_content = try r.readAllAlloc(gpa, std.math.maxInt(usize));
58 const val = try extras.parse_json(gpa, body_content);
57 const doc = try json.parse(gpa, "", req.reader(), .{ .support_trailing_commas = true, .maximum_depth = 100 });
58 doc.acquire();
59 defer doc.release();
5960
60 if (val.value.object.get("message")) |msg| {
61 std.log.err("server: {s}", .{msg.string});
61 if (doc.root.object().getS("message")) |msg| {
62 std.log.err("server: {s}", .{msg});
6263 return error.AquilaBadResponse;
6364 }
64 return val;
65 return doc;
6566}
src/cmd/aquila/add.zig+5-3
......@@ -18,11 +18,13 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
1818
1919pub fn do(dir: std.fs.Dir, pkg_id: string) !string {
2020 const url = try std.mem.join(gpa, "/", &.{ aq.server_root, pkg_id });
21 const val = try aq.server_fetch(url);
21 const doc = try aq.server_fetch(url);
22 doc.acquire();
23 defer doc.release();
2224
2325 const pkg_url = try std.fmt.allocPrint(gpa, "https://{s}/{s}", .{
24 val.value.object.get("repo").?.object.get("domain").?.string,
25 val.value.object.get("package").?.object.get("remote_name").?.string,
26 doc.root.object().getO("repo").?.getS("domain").?,
27 doc.root.object().getO("package").?.getS("remote_name").?,
2628 });
2729
2830 const m = try zigmod.ModFile.from_dir(gpa, dir);
src/cmd/aquila/showjson.zig+4-2
......@@ -12,7 +12,9 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
1212 const out = std.io.getStdOut().writer();
1313
1414 const url = try std.mem.join(gpa, "/", &.{ aq.server_root, args[0] });
15 const val = try aq.server_fetch(url);
15 const doc = try aq.server_fetch(url);
16 doc.acquire();
17 defer doc.release();
1618
17 try out.print("{}\n", .{val});
19 try out.print("{}\n", .{doc});
1820}
src/cmd/zpm.zig+26-31
......@@ -3,6 +3,7 @@ const string = []const u8;
33const gpa = std.heap.c_allocator;
44const zfetch = @import("zfetch");
55const extras = @import("extras");
6const json = @import("json");
67
78const u = @import("./../util/index.zig");
89
......@@ -26,7 +27,7 @@ pub const Package = struct {
2627 root_file: string,
2728 description: string,
2829 source: u32,
29 links: []const ?string,
30 links: []const string,
3031};
3132
3233pub fn execute(self_name: []const u8, args: [][]u8) !void {
......@@ -55,60 +56,54 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
5556 u.fail("unknown command \"{s}\" for \"zigmod zpm\"", .{args[0]});
5657}
5758
58pub fn server_fetch(url: string) !std.json.Parsed(std.json.Value) {
59pub fn server_fetch(url: string) !json.Document {
5960 const req = try zfetch.Request.init(gpa, url, null);
6061 defer req.deinit();
6162 try req.do(.GET, null, null);
62 const r = req.reader();
63 const body_content = try r.readAllAlloc(gpa, std.math.maxInt(usize));
64 return extras.parse_json(gpa, body_content);
63 return json.parse(gpa, "", req.reader(), .{ .support_trailing_commas = true, .maximum_depth = 100 });
6564}
6665
6766pub fn server_fetchArray(url: string) ![]const Package {
68 const val = try server_fetch(url);
67 const doc = try server_fetch(url);
68 doc.acquire();
69 defer doc.release();
6970 var list = std.ArrayList(Package).init(gpa);
7071 errdefer list.deinit();
7172
72 for (val.value.array.items) |item| {
73 if (get(item, "root_file") == null) continue;
73 for (doc.root.array()) |item| {
74 const obj = item.object();
75 if (obj.getS("root_file") == null) continue;
7476 try list.append(Package{
75 .name = item.object.get("name").?.string,
76 .author = item.object.get("author").?.string,
77 .description = item.object.get("description").?.string,
78 .tags = try valueStrArray(item.object.get("tags").?.array.items),
79 .git = item.object.get("git").?.string,
80 .root_file = item.object.get("root_file").?.string,
81 .source = @intCast(item.object.get("source").?.integer),
82 .links = try valueLinks(item.object.get("links").?),
77 .name = obj.getS("name").?,
78 .author = obj.getS("author").?,
79 .description = obj.getS("description").?,
80 .tags = try valueStrArray(obj.getA("tags").?),
81 .git = obj.getS("git").?,
82 .root_file = obj.getS("root_file").?,
83 .source = obj.getN("source").?.get(u32),
84 .links = try valueLinks(obj.getO("links").?),
8385 });
8486 }
8587 return list.toOwnedSlice();
8688}
8789
88fn valueStrArray(vals: []std.json.Value) ![]string {
90fn valueStrArray(vals: json.Array) ![]string {
8991 var list = std.ArrayList(string).init(gpa);
9092 errdefer list.deinit();
9193
9294 for (vals) |item| {
93 if (item != .string) continue;
94 try list.append(item.string);
95 if (item.v() != .string) continue;
96 try list.append(item.string());
9597 }
9698 return list.toOwnedSlice();
9799}
98100
99fn valueLinks(vals: std.json.Value) ![]?string {
100 var list = std.ArrayList(?string).init(gpa);
101fn valueLinks(vals: json.ObjectIndex) ![]string {
102 var list = std.ArrayList(string).init(gpa);
101103 errdefer list.deinit();
102104
103 if (get(vals, "github")) |x| try list.append(x.string);
104 if (get(vals, "aquila")) |x| try list.append(x.string);
105 if (get(vals, "astrolabe")) |x| try list.append(x.string);
105 if (vals.getS("github")) |x| try list.append(x);
106 if (vals.getS("aquila")) |x| try list.append(x);
107 if (vals.getS("astrolabe")) |x| try list.append(x);
106108 return list.toOwnedSlice();
107109}
108
109fn get(obj: std.json.Value, key: string) ?std.json.Value {
110 const v = obj.object.get(key);
111 if (v == null) return null;
112 if (v.? == .null) return null;
113 return v.?;
114}
src/cmd/zpm/showjson.zig+4-2
......@@ -12,7 +12,9 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
1212 const out = std.io.getStdOut().writer();
1313
1414 const url = try std.mem.join(gpa, "/", &.{ zpm.server_root, args[0] });
15 const val = try zpm.server_fetch(url);
15 const doc = try zpm.server_fetch(url);
16 doc.acquire();
17 defer doc.release();
1618
17 try out.print("{}\n", .{val});
19 try out.print("{}\n", .{doc});
1820}
src/cmd/zpm/tags.zig+8-6
......@@ -14,12 +14,14 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
1414 const out = std.io.getStdOut().writer();
1515
1616 const url = try std.mem.join(gpa, "/", &.{ zpm.server_root, "tags" });
17 const val = try zpm.server_fetch(url);
17 const doc = try zpm.server_fetch(url);
18 doc.acquire();
19 defer doc.release();
1820
1921 const name_col_width = blk: {
2022 var w: usize = 4;
21 for (val.value.array.items) |tag| {
22 const len = tag.object.get("name").?.string.len;
23 for (doc.root.array()) |tag| {
24 const len = tag.object().getS("name").?.len;
2325 if (len > w) {
2426 w = len;
2527 }
......@@ -31,11 +33,11 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
3133 try print_c_n(out, ' ', name_col_width - 4);
3234 try out.writeAll("DESCRIPTION\n");
3335
34 for (val.value.array.items) |tag| {
35 const name = tag.object.get("name").?.string;
36 for (doc.root.array()) |tag| {
37 const name = tag.object().getS("name").?;
3638 try out.writeAll(name);
3739 try print_c_n(out, ' ', name_col_width - name.len);
38 try out.writeAll(tag.object.get("description").?.string);
40 try out.writeAll(tag.object().getS("description").?);
3941 try out.writeAll("\n");
4042 }
4143}
src/util/modfile.zig+2-6
......@@ -90,7 +90,6 @@ pub const ModFile = struct {
9090 var dtype: string = undefined;
9191 var path: string = undefined;
9292 var version: ?string = null;
93 var name = item.mapping.get_string("name") orelse "";
9493 var main = item.mapping.get_string("main") orelse "";
9594
9695 if (item.mapping.get("src")) |val| {
......@@ -112,10 +111,6 @@ pub const ModFile = struct {
112111 }
113112 const dep_type = std.meta.stringToEnum(zigmod.Dep.Type, dtype).?;
114113 if (dep_type == .local) {
115 if (path.len > 0) {
116 name = path;
117 path = "";
118 }
119114 if (version.?.len > 0) {
120115 main = version.?;
121116 version = "";
......@@ -129,7 +124,7 @@ pub const ModFile = struct {
129124 .type = dep_type,
130125 .path = path,
131126 .id = id,
132 .name = name,
127 .name = item.mapping.get_string("name") orelse "",
133128 .main = main,
134129 .version = version.?,
135130 .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"),
......@@ -142,6 +137,7 @@ pub const ModFile = struct {
142137 .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep") orelse ""),
143138 .for_build = for_build,
144139 });
140 // const d = &dep_list.getLast();
145141 }
146142 }
147143 }
zig.mod+1
......@@ -16,6 +16,7 @@ dependencies:
1616 - src: git https://github.com/nektro/zig-time
1717 - src: git https://github.com/nektro/zig-extras
1818 - src: git https://github.com/nektro/zig-git
19 - src: git https://github.com/nektro/zig-json
1920
2021root_dependencies:
2122 - src: git https://github.com/marlersoft/zigwin32
zigmod.lock+2
......@@ -8,6 +8,8 @@ git https://github.com/nektro/zig-detect-license commit-3ff57d0681b7bd7f8ca9bd09
88git https://github.com/nektro/zig-extras commit-74f0ddb0a4dfa7921739b88cc381951a6b6e73ce
99git https://github.com/nektro/zig-git commit-103f4e419c35b88f802bb8234ece1c0a9aa40c03
1010git https://github.com/nektro/zig-inquirer commit-cf43dd6c9f328073f7468b5341c69ed0bb185db3
11git https://github.com/nektro/zig-intrusive-parser commit-2336d8b767eb7378762e1ba63635ca44accbd2ca
12git https://github.com/nektro/zig-json commit-29587071de6dd3338e8eb76d4e0307af69a2d61a
1113git https://github.com/nektro/zig-leven commit-e5481b297b6023d446d835156591ba5ce88c17be
1214git https://github.com/nektro/zig-licenses commit-f46d9f774df929885eef66c733a1e2a46bf16aec
1315git https://github.com/nektro/zig-licenses-text commit-b01e5a2dffcc564bddd8f514fe64bab9b5c52572