main
1// ply 0.2.0 returns every failure as a value (`Result<T, PlyError>`). The /v1 handlers and the write layer read those
2// Results where they are returned (`if (!r.ok)`); status.ts maps a code to an HTTP status exhaustively.
3// `unwrap` is what is left of the old convention, for the places where a throw still crosses a boundary on purpose:
4// a helper inside an `operation()` body (ply turns a thrown PlyError into its Err and records it on the root span),
5// a span-wrapped step (`tracer.span` records the throw), and the public viewer, whose error page is built from a catch.
6// An Err's error is thrown exactly as ply 0.1 threw it (the same Error instance, the same code and fields).
7import { CODES, DEFAULT_LIMITS, discover, parsePath, parseRefname, type Path, type Refname } from 'ply';
8import { chainGet } from './absent.ts';
9import type { Result } from './http/machine.ts';
11type PlyResult<T> = { readonly ok: true; readonly value: T } | { readonly ok: false; readonly error: unknown };
13/** ply's error union. ply's index does not export it by name; every public Result carries it. */
14export type PlyError = Extract<Awaited<ReturnType<typeof discover>>, { readonly ok: false }>['error'];
15/** ply's closed set of error codes. */
16export type PlyCode = (typeof CODES)[number];
17/** The success value of a ply call's Result (or a Promise of one). */
18export type OkOf<R> = Awaited<R> extends { readonly ok: true; readonly value: infer T } | { readonly ok: false } ? T : never;
20export function unwrap<T>(r: PlyResult<T>): T {
21 if (r.ok) return r.value;
22 throw r.error;
23}
25export async function unwrapAsync<T>(p: Promise<PlyResult<T>>): Promise<T> {
26 return unwrap(await p);
27}
29// ply 0.2.0 takes a ref name and a path as branded strings. The worker's request layer has validated both already
30// (request.ts); these re-check through ply's own parser, so the brand is earned, not cast. A bad value throws ply's
31// bad_request, as ply 0.1's push and editFile did when they validated the same string.
32export const refname = (ref: string): Refname => unwrap(parseRefname(ref));
33// `opts` is the call's options: its limits (ply's defaults when it names none, as operation() does) bound the path.
34export function pathIn(path: string, opts: object): Result<Path, PlyError> {
35 const given = chainGet(opts, 'limits');
36 const limits = given.tag === 'some' && typeof given.value === 'object' && given.value !== null ? given.value : DEFAULT_LIMITS;
37 const parsed = parsePath(path, limits);
38 return parsed.ok ? { ok: true, value: parsed.value.path } : parsed;
39}
Diagnostics4 git calls · 33 ms
CallStatusSizeTime033 ms
discover200152 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=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200145 B · hit4 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=4 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=4 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=145 git.pkt.payload.max=76 git.ls_refs.count=2 git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit3 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=41349 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921 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=6 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2001.3 KiB · hit26 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=26 git.response.bytes=1280 git.response.cache=HIT git.response.duration_ms=26 git.fetch.wants=1b3d4e5183ac974f2d6952f21e63151db5340e21 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=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1280 git.pkt.payload.max=1259 git.sideband.band1.bytes=1258 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://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e368af49bd724e
- Request
- e364e7e3…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format