GitHubivarvong
ply
main
1// Compile-time checks: `tsc --noEmit` must pass; every @ts-expect-error must still be an error.
2import { assertNever, match, matchKind, matchOption, ok, some, none, optionToResult, resultToOption, transposeOptionResult, transposeResultOption, andThen, type Option, type Result } from '../../src/result.js';
3import { fail, type PlyError, type Code, type Miss } from '../../src/errors.js';
5const r: Result<number, PlyError> = Math.random() > 0.5 ? ok(1) : fail('timeout', 't');
6if (r.ok) { const n: number = r.value; void n; } else { const c: Code = r.error.code; void c; }
7// @ts-expect-error value is not accessible without narrowing
8void r.value;
10// exhaustive switch
11const describe = (e: PlyError): string => {
12 switch (e.code) {
13 case 'http': return `status ${e.status}`; // narrowed: status exists
14 case 'limit_exceeded': return `${e.what} ${e.got} > ${e.max}`;
15 case 'ambiguous': return String(e.original ?? 'unknown');
16 case 'cas_conflict': return `${e.expected} != ${e.actual}`;
17 case 'match_count': return String(e.matches);
18 case 'merge_conflict': return e.conflicts.join(',');
19 case 'bad_request': case 'unsupported': case 'network': case 'timeout': case 'aborted': case 'auth':
20 case 'not_found': case 'rate_limited': case 'upstream_5xx': case 'not_git':
21 case 'protocol': case 'pack_corrupt': case 'remote_error': case 'lfs_pointer':
22 case 'push_rejected': case 'push_partial': case 'not_fast_forward':
23 case 'not_linear': case 'unrelated_histories': case 'internal':
24 return e.message;
25 }
26 return assertNever(e);
27};
28void describe;
29const missingCase = (e: PlyError): string => {
30 switch (e.code) {
31 case 'http': return 'x';
32 }
33 // @ts-expect-error not exhaustive: e is not never here
34 return assertNever(e);
35};
36void missingCase;
38// payload required by code
39fail('http', 'x', { status: 500 });
40// @ts-expect-error http requires status
41fail('http', 'x');
42// @ts-expect-error timeout takes no payload
43fail('timeout', 'x', { status: 1 });
44// @ts-expect-error unknown code
45fail('nope', 'x');
47// match: every tag, and only tags
48type Step = { code: 'more'; n: number } | { code: 'done' };
49const s = { code: 'more', n: 1 } as Step;
50match(s, { more: x => x.n, done: () => 0 });
51// @ts-expect-error missing handler
52match(s, { more: x => x.n });
53// @ts-expect-error extra handler
54match(s, { more: x => x.n, done: () => 0, other: () => 1 });
56// matchKind: the #131 miss union, and any operation error discriminated by kind
57declare const miss: Miss;
58const missLabel = matchKind(miss, {
59 ref: x => x.ref,
60 head_unborn: x => x.target,
61 head_absent: () => 'absent',
62 path: x => x.missing,
63 not_directory: x => x.mode,
64 is_directory: x => x.tree,
65 submodule: x => x.commit,
66 commit: x => x.miss.kind,
67 repository: () => 'repository',
68});
69void missLabel;
70// @ts-expect-error missing kind handler
71matchKind(miss, { ref: x => x.ref });
73type OpErr = { readonly kind: 'not_string'; readonly which: 'left' } | { readonly kind: 'not_bytes'; readonly which: 'right' };
74declare const opErr: OpErr;
75matchKind(opErr, { not_string: x => x.which, not_bytes: x => x.which });
76// @ts-expect-error missing not_bytes
77matchKind(opErr, { not_string: x => x.which });
79// Option: both tags, and it composes with Result.
80const present: Option<number> = some(1);
81const absent: Option<number> = none;
82matchOption(present, { some: n => n, none: () => 0 });
83// @ts-expect-error missing none
84matchOption(present, { some: n => n });
85const back: Result<number, 'missing'> = optionToResult(absent, 'missing');
86const dropped: Option<number> = resultToOption(back);
87const nested: Option<Result<number, 'missing'>> = transposeResultOption(ok(absent));
88const flat: Result<Option<number>, 'missing'> = transposeOptionResult(some(ok(1)));
89void dropped; void nested; void flat;
91// andThen unions error types
92const a = andThen(ok(1) as Result<number, 'e1'>, n => (n > 0 ? ok(String(n)) : { ok: false as const, error: 'e2' as const }));
93const e: Result<string, 'e1' | 'e2'> = a; void e;
Diagnostics7 git calls · 121 ms
CallStatusSizeTime0121 ms
discover200191 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=191 git.server.agent=git/github-9922ec520325-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=191 git.pkt.payload.max=36
ls-refs20012 KiB93 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=93 git.response.bytes=11990 git.response.cache=EXPIRED git.response.duration_ms=93 git.protocol.version=2 git.pkt.frames=152 git.pkt.data=151 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=11990 git.pkt.payload.max=122 git.ls_refs.count=151 git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=4347 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4347 git.pkt.payload.max=4247 git.sideband.band1.bytes=4247 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=10 git.pack.bytes=4247 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400 git.pack.full=10Open pack map
fetchtree:0200919 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=919 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=919 git.pkt.payload.max=892 git.sideband.band1.bytes=892 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=892 git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76eOpen pack map
fetchtree:02005.6 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=5724 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=58fabb6768b3f737ee9cd8bac647bdc27405fb4d git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=5724 git.pkt.payload.max=5697 git.sideband.band1.bytes=5697 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=5697 git.pack.trailer=be7e0453974a5fe832f9065a33bb7e3434c10e9bOpen pack map
fetchtree:0200746 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=746 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=1a4f84aea08d080a229290d401e77da8415108a0 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=746 git.pkt.payload.max=719 git.sideband.band1.bytes=719 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=719 git.pack.trailer=fd3904a205b94cd1bbf03c591c9acea7ca5dd5a7Open pack map
fetch2001.5 KiB · hit17 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=17 git.response.bytes=1575 git.response.cache=HIT git.response.duration_ms=17 git.fetch.wants=ccc70a8b0d3cbc3a24c563a2052b6c9733c8c6ad git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1575 git.pkt.payload.max=1548 git.sideband.band1.bytes=1548 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://github.com/ivarvong/ply
- Ref
- refs/heads/main
- Commit
- 19912563f540228593df0c489082e5e2508e21e4
- cf-ray
- a5e1e4af2a3fd96e
- Request
- 0fbbe92d…
- Protocol
- v2 · sha1
- Agent
- git/github-9922ec520325-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format