GitHubivarvong
ply
main
1// The package entry (#100): a consumer imports values and types from index, with no casts.
2import {
3 fetchPack, push, spliceDelta, zlibDeflate, Tracer, arrayExporter, createTransport, discover, lsRefs,
4 fetchObject, packStream, spInit, spStep, spFinish, inflate, commitView, entryType, lsMode, refCandidates,
5 isFilterRejection, isPlyCode, DEFAULT_LIMITS, parseRefname,
6 type Transport, type ExportLine, type Exporter, type Limits, type FetchOpts, type SpState, type PackObject, type OperationOpts,
7 type TransferRun, type LastPush, type LastStep,
8} from '../../src/index.js';
10// A paused transfer's two facts (LastPush and LastStep, public beside TransferRun). The unions and the paused shape are
11// written out here from README's transfer section, not read from src/transfer.ts: a member added, dropped or renamed
12// there, a field renamed, or either export removed from the entry fails this file (tsconfig.check.json compiles it).
13type Same<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
14const lastPushIs: Same<LastPush, 'none' | 'acknowledged' | 'refused' | 'unanswered'> = true;
15const lastStepIs: Same<LastStep, 'none' | 'landed' | 'not_shown'> = true;
16const pausedIs: Same<Extract<TransferRun, { readonly tag: 'paused' }>, {
17 readonly tag: 'paused'; readonly step: number; readonly pushes: number; readonly reason: 'max_steps' | 'settling';
18 readonly lastPush: 'none' | 'acknowledged' | 'refused' | 'unanswered'; readonly lastStep: 'none' | 'landed' | 'not_shown';
19}> = true;
20void lastPushIs; void lastStepIs; void pausedIs;
21// a consumer reads both fields off a pause with no cast, and a done run has neither
22const pauseFacts = (run: TransferRun): readonly [LastPush, LastStep] | null => (run.tag === 'paused' ? [run.lastPush, run.lastStep] : null);
23void pauseFacts;
24// @ts-expect-error a done run states no last push
25const doneFacts = (run: Extract<TransferRun, { readonly tag: 'done' }>): LastPush => run.lastPush;
26void doneFacts;
28declare const transport: Transport;
29declare const anyBytes: Uint8Array;
30declare const shared: Uint8Array<SharedArrayBuffer>;
32// @ts-expect-error kind is the literal 'http'
33const kind: Transport['kind'] = 1;
34void kind;
36const exporter: Exporter = line => {
37 const spans: number = line.resourceSpans.length;
38 void spans;
39};
40const tracer = new Tracer({ exporter, maxEvents: 8, resource: { 'service.name': 'ply' } });
41const collected = arrayExporter();
42const sample: ExportLine = { resourceSpans: [] };
43collected(sample);
44const stored: number = collected.lines.length;
45void stored;
47const limits: Limits = DEFAULT_LIMITS;
48const made = createTransport('https://example.test/repo.git', {
49 tracer, userAgent: 'ply-web', limits, signal: new AbortController().signal, fetchImpl: globalThis.fetch, quirks: {},
50});
51if (made.ok) { const madeT: Transport = made.value; void madeT; }
53const opts: OperationOpts = { tracer };
54void opts;
56const fetchOpts: FetchOpts = { wants: ['a'.repeat(40)], filter: 'blob:none' };
58// fetchPack → push, and spliceDelta → zlibDeflate, through the entry. SharedArrayBuffer views are inputs.
59const consumer = async (): Promise<void> => {
60 const fetchedR = await fetchPack(transport, fetchOpts);
61 if (!fetchedR.ok) return;
62 const fetched = fetchedR.value;
63 const objects: PackObject[] = [...(fetched.objects?.values() ?? [])].map(o => ({ type: o.type, data: o.data }));
64 // helper: unwrap a Result Ok (type-level)
65 const expectOk = <T, E>(r: { ok: true; value: T } | { ok: false; error: E }): T => (r.ok ? r.value : (null as unknown as T));
66 const ref = expectOk(parseRefname('refs/heads/x'));
67 await push(transport, { ref, oldOid: '0'.repeat(40), newOid: 'b'.repeat(40), objects });
68 const { delta } = spliceDelta({ baseLen: 8, off: 0, oldLen: 1, insert: anyBytes });
69 const deflated: Uint8Array<ArrayBuffer> = await zlibDeflate(delta);
70 await zlibDeflate(shared);
71 void deflated;
73 const infoR = await discover(transport);
74 if (!infoR.ok) return;
75 const info = infoR.value;
76 const caps: ReadonlyMap<string, string> | Map<string, string> = info.caps;
77 void caps;
78 const listedR = await lsRefs(transport, ['refs/heads/']);
79 if (!listedR.ok) return;
80 const head: string | null = listedR.value.head;
81 void head;
82 const objectR = await fetchObject(transport, { oid: 'c'.repeat(40), filter: 'blob:none' });
83 if (!objectR.ok) return;
84 const object = objectR.value;
85 const view = commitView(object.data, limits);
86 const tree: string | null = view.ok ? view.value.tree : null;
87 void tree;
88 const entry: string = entryType('100644');
89 const mode: string = lsMode('100644');
90 const names: readonly string[] = expectOk(refCandidates('main'));
91 void entry; void mode; void names;
92 const span = tracer.start('git.fetch');
93 for await (const chunk of packStream(transport, fetchOpts, span)) {
94 const bytes: Uint8Array = chunk;
95 void bytes;
96 }
97 let cursor: SpState = spInit();
98 const steppedR = spStep(cursor, anyBytes);
99 if (!steppedR.ok) return;
100 const stepped = steppedR.value;
101 const finished = spFinish(stepped.state);
102 if (!finished.ok) return;
103 cursor = finished.value;
104 const pieces: readonly Uint8Array[] = stepped.zlib;
105 void cursor; void pieces;
106 const inflated = inflate(anyBytes, 0, { expectedSize: 1, maxOutput: 8 });
107 if (!inflated.ok) return;
108 // `out` is a subarray of the growable buffer, so the published type is `Uint8Array` (any backing).
109 const out: Uint8Array = inflated.value.out;
110 void out;
111 const rejected: boolean = isFilterRejection(new Error('no'));
112 const known: boolean = isPlyCode('pack_corrupt');
113 void rejected; void known;
114};
115void consumer;
Diagnostics7 git calls · 96 ms
CallStatusSizeTime096 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 KiB3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=11990 git.response.cache=UPDATING git.response.duration_ms=3 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 · 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=919 git.response.cache=HIT git.response.duration_ms=2 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 · 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=5724 git.response.cache=HIT git.response.duration_ms=3 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 · 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=746 git.response.cache=HIT git.response.duration_ms=2 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
fetch2002.3 KiB83 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=83 git.response.bytes=2381 git.response.cache=MISS git.response.duration_ms=83 git.fetch.wants=9cc0f56af5b2ba8daf91b6e40eb0f3a5c369ed08 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=2381 git.pkt.payload.max=2354 git.sideband.band1.bytes=2354 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
- a5e195172af8ddf0
- Request
- 994a5587…
- 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