just-git 1.3.6 → 1.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,13 @@
1
- import { _ as RawObject, $ as Ref, g as GitRepo, a3 as Rejection, N as NetworkPolicy } from '../hooks-DNBNCTgb.js';
1
+ import { i as ObjectId, W as RawObject, X as Ref, g as GitRepo, $ as Rejection, N as NetworkPolicy } from '../hooks-C7c_BLqp.js';
2
+ import { b as CommitOptions } from '../writing-CnM1ufDP.js';
3
+
4
+ /** Shallow boundary delta: what to add/remove from `.git/shallow`. */
5
+ interface ShallowUpdate {
6
+ /** Commits to add to the shallow boundary. */
7
+ shallow: ObjectId[];
8
+ /** Commits to remove from the shallow boundary (now have full parents). */
9
+ unshallow: ObjectId[];
10
+ }
2
11
 
3
12
  /**
4
13
  * A value that may be synchronous or asynchronous.
@@ -263,8 +272,10 @@ interface GitServerConfig<S = Session> {
263
272
  * The server calls `createStorageAdapter(storage)` internally to build the
264
273
  * git-aware adapter. Users provide the storage backend; they never see
265
274
  * the `StorageAdapter` interface.
275
+ *
276
+ * Defaults to {@link MemoryStorage} when omitted.
266
277
  */
267
- storage: Storage;
278
+ storage?: Storage;
268
279
  /**
269
280
  * Map a request path to a repo ID.
270
281
  *
@@ -337,8 +348,8 @@ interface GitServerConfig<S = Session> {
337
348
  /**
338
349
  * A ref update request for {@link GitServer.updateRefs}.
339
350
  *
340
- * In-process equivalent of a push command updates a ref with CAS
341
- * protection and hook enforcement, without transport overhead.
351
+ * In-process ref update with CAS protection. Objects must already
352
+ * exist in the repo's object store.
342
353
  */
343
354
  interface RefUpdateRequest {
344
355
  /** Full ref name (e.g. `"refs/heads/main"`, `"refs/tags/v1.0"`). */
@@ -356,7 +367,7 @@ interface RefUpdateRequest {
356
367
  */
357
368
  oldHash?: string | null;
358
369
  }
359
- interface GitServer<S = Session> {
370
+ interface GitServer {
360
371
  /** Standard fetch-API handler for HTTP: (Request) => Response */
361
372
  fetch(request: Request): Promise<Response>;
362
373
  /**
@@ -393,14 +404,15 @@ interface GitServer<S = Session> {
393
404
  */
394
405
  handleSession(command: string, channel: SshChannel, session?: SshSessionInfo): Promise<number>;
395
406
  /**
396
- * Update refs in-process with hook enforcement and CAS protection.
407
+ * Update refs in-process with CAS protection.
397
408
  *
398
- * Equivalent to a push, but without transport overhead — no pack
399
- * negotiation, no object transfer. Objects must already exist in
400
- * the repo's object store (e.g. via `createCommit` from `just-git/repo`).
409
+ * Applies compare-and-swap ref updates without transport overhead.
410
+ * Does NOT fire hooks (`preReceive`, `update`, `postReceive`)
411
+ * hooks are a transport boundary concern. For hook enforcement,
412
+ * push through {@link asNetwork} instead.
401
413
  *
402
- * Runs the full hook lifecycle: `preReceive` per-ref `update`
403
- * CAS application `postReceive`. Returns per-ref results.
414
+ * Objects must already exist in the repo's object store (e.g. via
415
+ * `createCommit` or `buildCommit` from `just-git/repo`).
404
416
  *
405
417
  * ```ts
406
418
  * import { createCommit, writeBlob, writeTree } from "just-git/repo";
@@ -417,7 +429,36 @@ interface GitServer<S = Session> {
417
429
  *
418
430
  * @throws If the repo does not exist or the server is shutting down.
419
431
  */
420
- updateRefs(repoId: string, refs: RefUpdateRequest[], session?: S): Promise<RefUpdateResult>;
432
+ updateRefs(repoId: string, refs: RefUpdateRequest[]): Promise<RefUpdateResult>;
433
+ /**
434
+ * Commit files to a branch with CAS protection.
435
+ *
436
+ * High-level convenience that combines object creation ({@link buildCommit}
437
+ * from `just-git/repo`) with CAS-protected ref advancement
438
+ * ({@link updateRefs}). This is the recommended API for trusted
439
+ * server-side writes (bots, scripts, platform features).
440
+ *
441
+ * Does NOT fire hooks — hooks are a transport boundary concern.
442
+ * For hook enforcement (auth, policy), push through
443
+ * {@link asNetwork} instead.
444
+ *
445
+ * ```ts
446
+ * const hash = await server.commit("my-repo", {
447
+ * files: { "README.md": "# Hello\n" },
448
+ * message: "auto-fix",
449
+ * author: { name: "Bot", email: "bot@example.com" },
450
+ * branch: "main",
451
+ * });
452
+ * ```
453
+ *
454
+ * For lower-level control (e.g. constructing trees manually, multi-ref
455
+ * updates), use `buildCommit()` + {@link updateRefs} directly.
456
+ *
457
+ * @returns The new commit's hash.
458
+ * @throws If the repo does not exist, the server is shutting down,
459
+ * or a concurrent write moved the branch.
460
+ */
461
+ commit(repoId: string, options: CommitOptions): Promise<string>;
421
462
  /**
422
463
  * Node.js `http.createServer` compatible handler.
423
464
  *
@@ -527,8 +568,8 @@ interface PreReceiveEvent<S = Session> {
527
568
  /** Resolved repo ID (the value returned by `resolve`, or the raw path when `resolve` is not set). */
528
569
  repoId: string;
529
570
  updates: readonly RefUpdate[];
530
- /** Session info. Present for HTTP and SSH; absent for in-process pushes. */
531
- session?: S;
571
+ /** Session built by the transport's session builder. Always present hooks only fire from HTTP/SSH transport. */
572
+ session: S;
532
573
  }
533
574
  /** Fired per-ref after preReceive passes. */
534
575
  interface UpdateEvent<S = Session> {
@@ -536,8 +577,8 @@ interface UpdateEvent<S = Session> {
536
577
  /** Resolved repo ID (the value returned by `resolve`, or the raw path when `resolve` is not set). */
537
578
  repoId: string;
538
579
  update: RefUpdate;
539
- /** Session info. Present for HTTP and SSH; absent for in-process pushes. */
540
- session?: S;
580
+ /** Session built by the transport's session builder. Always present hooks only fire from HTTP/SSH transport. */
581
+ session: S;
541
582
  }
542
583
  /** Fired after all ref updates succeed. */
543
584
  interface PostReceiveEvent<S = Session> {
@@ -545,8 +586,8 @@ interface PostReceiveEvent<S = Session> {
545
586
  /** Resolved repo ID (the value returned by `resolve`, or the raw path when `resolve` is not set). */
546
587
  repoId: string;
547
588
  updates: readonly RefUpdate[];
548
- /** Session info. Present for HTTP and SSH; absent for in-process pushes. */
549
- session?: S;
589
+ /** Session built by the transport's session builder. Always present hooks only fire from HTTP/SSH transport. */
590
+ session: S;
550
591
  }
551
592
  /** Fired during ref advertisement (info/refs). */
552
593
  interface AdvertiseRefsEvent<S = Session> {
@@ -555,15 +596,15 @@ interface AdvertiseRefsEvent<S = Session> {
555
596
  repoId: string;
556
597
  refs: RefAdvertisement[];
557
598
  service: "git-upload-pack" | "git-receive-pack";
558
- /** Session info. Present for HTTP and SSH; absent for in-process requests. */
559
- session?: S;
599
+ /** Session built by the transport's session builder. Always present hooks only fire from HTTP/SSH transport. */
600
+ session: S;
560
601
  }
561
602
  /** A ref name and hash advertised to clients during fetch/push discovery. */
562
603
  interface RefAdvertisement {
563
604
  name: string;
564
605
  hash: string;
565
606
  }
566
- /** Per-ref result from a push or {@link GitServer.updateRefs} call. */
607
+ /** Per-ref result from a push, {@link GitServer.updateRefs}, or {@link GitServer.commit} call. */
567
608
  interface RefResult {
568
609
  ref: string;
569
610
  ok: boolean;
@@ -584,10 +625,7 @@ interface RefUpdateResult {
584
625
  * works with any SSH library (ssh2, etc.) through a thin adapter.
585
626
  *
586
627
  * ```ts
587
- * const server = createServer({
588
- * storage: new MemoryStorage(),
589
- * autoCreate: true,
590
- * });
628
+ * const server = createServer({ autoCreate: true });
591
629
  * await server.createRepo("my-repo");
592
630
  *
593
631
  * // HTTP
@@ -600,7 +638,6 @@ interface RefUpdateResult {
600
638
  *
601
639
  * ```ts
602
640
  * const server = createServer({
603
- * storage: new MemoryStorage(),
604
641
  * autoCreate: true,
605
642
  * });
606
643
  * await server.createRepo("my-repo");
@@ -612,7 +649,7 @@ interface RefUpdateResult {
612
649
  * server.handleSession(command, channel, { username });
613
650
  * ```
614
651
  */
615
- declare function createServer<S = Session>(config: GitServerConfig<S>): GitServer<S>;
652
+ declare function createServer<S = Session>(config?: GitServerConfig<S>): GitServer;
616
653
  /**
617
654
  * Compose multiple hook sets into a single `ServerHooks` object.
618
655
  *
@@ -654,6 +691,86 @@ interface PushCommand {
654
691
  newHash: string;
655
692
  refName: string;
656
693
  }
694
+ /**
695
+ * Build the v2 capability advertisement response body.
696
+ *
697
+ * Format:
698
+ * PKT-LINE("version 2\n")
699
+ * PKT-LINE(capability LF)
700
+ * ...
701
+ * flush-pkt
702
+ */
703
+ declare function buildV2CapabilityAdvertisement(capabilities: string[]): Uint8Array;
704
+ interface V2CommandRequest {
705
+ command: string;
706
+ capabilities: string[];
707
+ args: string[];
708
+ }
709
+ /**
710
+ * Parse a v2 command request body.
711
+ *
712
+ * Format:
713
+ * PKT-LINE("command=" key LF)
714
+ * *(PKT-LINE(capability LF))
715
+ * delim-pkt
716
+ * *(PKT-LINE(command-arg LF))
717
+ * flush-pkt
718
+ */
719
+ declare function parseV2CommandRequest(body: Uint8Array): V2CommandRequest;
720
+ interface V2LsRefsRef {
721
+ hash: string;
722
+ name: string;
723
+ symrefTarget?: string;
724
+ peeledHash?: string;
725
+ }
726
+ /**
727
+ * Build the v2 ls-refs response.
728
+ *
729
+ * Format:
730
+ * PKT-LINE(obj-id SP refname *(SP ref-attribute) LF)
731
+ * ...
732
+ * flush-pkt
733
+ */
734
+ declare function buildV2LsRefsResponse(refs: V2LsRefsRef[]): Uint8Array;
735
+ interface V2FetchRequest {
736
+ wants: string[];
737
+ haves: string[];
738
+ done: boolean;
739
+ clientShallows: string[];
740
+ depth?: number;
741
+ includeTag: boolean;
742
+ ofsDeltas: boolean;
743
+ wantRefs: string[];
744
+ }
745
+ /**
746
+ * Parse v2 fetch command args into structured request.
747
+ */
748
+ declare function parseV2FetchArgs(args: string[]): V2FetchRequest;
749
+ interface V2FetchResponseOptions {
750
+ commonHashes?: string[];
751
+ shallowInfo?: ShallowUpdate;
752
+ wantedRefs?: Array<{
753
+ hash: string;
754
+ name: string;
755
+ }>;
756
+ }
757
+ /**
758
+ * Build a v2 fetch response with section-based format.
759
+ *
760
+ * Per the spec, when commonHashes are provided the acknowledgments
761
+ * section is included (with "ready") followed by the packfile.
762
+ * When omitted (e.g. fresh clone with no haves), acks are skipped.
763
+ *
764
+ * Sections (separated by delim-pkt):
765
+ * [acknowledgments section]
766
+ * [shallow-info section]
767
+ * [wanted-refs section]
768
+ * packfile section
769
+ *
770
+ * The packfile section always uses sideband-64k.
771
+ * Terminated by flush-pkt.
772
+ */
773
+ declare function buildV2FetchResponse(packData: Uint8Array, options?: V2FetchResponseOptions): Uint8Array;
657
774
 
658
775
  /**
659
776
  * High-level server operations.
@@ -728,7 +845,7 @@ interface AdvertiseResult {
728
845
  * Both HTTP and SSH code paths use this — the caller handles the
729
846
  * transport-specific response (HTTP 403 vs SSH exit 128).
730
847
  */
731
- declare function advertiseRefsWithHooks<S>(repo: GitRepo, repoId: string, service: "git-upload-pack" | "git-receive-pack", hooks?: ServerHooks<S>, session?: S): Promise<AdvertiseResult | Rejection>;
848
+ declare function advertiseRefsWithHooks<S>(repo: GitRepo, repoId: string, service: "git-upload-pack" | "git-receive-pack", hooks: ServerHooks<S> | undefined, session: S): Promise<AdvertiseResult | Rejection>;
732
849
  interface UploadPackOptions {
733
850
  /** Pack cache instance. When provided, full clones (no haves) are cached. */
734
851
  cache?: PackCache;
@@ -770,18 +887,26 @@ declare function ingestReceivePack(repo: GitRepo, requestBody: Uint8Array): Prom
770
887
  * pkt-line commands.
771
888
  */
772
889
  declare function ingestReceivePackFromStream(repo: GitRepo, commands: PushCommand[], capabilities: string[], packStream: AsyncIterable<Uint8Array>, sawFlush?: boolean): Promise<ReceivePackResult>;
890
+ /**
891
+ * Apply ref updates with CAS protection only — no hooks.
892
+ *
893
+ * Validates ref format, checks object existence, and performs
894
+ * `compareAndSwapRef` per ref. Used directly by in-process APIs
895
+ * (`server.updateRefs`, `server.commit`) and internally by
896
+ * {@link applyReceivePack} for the transport path.
897
+ */
898
+ declare function applyCasRefUpdates(repo: GitRepo, updates: readonly RefUpdate[]): Promise<RefUpdateResult>;
773
899
  interface ApplyReceivePackOptions<S = unknown> {
774
900
  repo: GitRepo;
775
901
  repoId: string;
776
902
  ingestResult: ReceivePackResult;
777
903
  hooks?: ServerHooks<S>;
778
- /** Session info threaded through to hooks. */
779
- session?: S;
904
+ session: S;
780
905
  }
781
906
  /**
782
907
  * Run the full receive-pack lifecycle: preReceive hook, per-ref update
783
908
  * hook with ref format validation, CAS ref application, and postReceive
784
- * hook. Transport-agnosticworks for HTTP, SSH, or in-process pushes.
909
+ * hook. Transport-onlyused by HTTP and SSH push handlers.
785
910
  *
786
911
  * Returns per-ref results and the list of successfully applied updates.
787
912
  * Does NOT handle unpack failures — the caller should check
@@ -795,6 +920,19 @@ declare function applyReceivePack<S = unknown>(options: ApplyReceivePackOptions<
795
920
  * `isFF`/`isCreate`/`isDelete` for each entry.
796
921
  */
797
922
  declare function resolveRefUpdates(repo: GitRepo, requests: RefUpdateRequest[]): Promise<RefUpdate[]>;
923
+ declare function buildV2CapabilityAdvertisementBytes(): Uint8Array;
924
+ /**
925
+ * Handle a v2 `ls-refs` command. Collects refs, applies hook filtering,
926
+ * then builds a v2 ls-refs response respecting the client's requested
927
+ * attributes (symrefs, peel, ref-prefix, unborn).
928
+ */
929
+ declare function handleLsRefs<S>(repo: GitRepo, repoId: string, args: string[], hooks: ServerHooks<S> | undefined, session: S): Promise<Uint8Array | Rejection>;
930
+ /**
931
+ * Handle a v2 `fetch` command. Parses fetch args, performs object
932
+ * enumeration and pack building via the shared pipeline, then
933
+ * builds a v2 section-based response.
934
+ */
935
+ declare function handleV2Fetch(repo: GitRepo, args: string[], options?: UploadPackOptions): Promise<Uint8Array | ReadableStream<Uint8Array>>;
798
936
 
799
937
  /**
800
938
  * In-memory storage backend with multi-repo support.
@@ -803,10 +941,9 @@ declare function resolveRefUpdates(repo: GitRepo, requests: RefUpdateRequest[]):
803
941
  * Data is lost when the process exits.
804
942
  *
805
943
  * ```ts
806
- * const server = createServer({
807
- * storage: new MemoryStorage(),
808
- * });
809
- * await server.createRepo("my-repo");
944
+ * // MemoryStorage is the default — these are equivalent:
945
+ * const server = createServer();
946
+ * const server2 = createServer({ storage: new MemoryStorage() });
810
947
  * ```
811
948
  */
812
949
  declare class MemoryStorage implements Storage {
@@ -832,6 +969,7 @@ declare class MemoryStorage implements Storage {
832
969
  removeRef(repoId: string, name: string): void;
833
970
  listRefs(repoId: string, prefix?: string): RawRefEntry[];
834
971
  atomicRefUpdate<T>(repoId: string, fn: (ops: RefOps) => T): T;
972
+ /** List all created repo IDs. Convenience for tests and debugging. */
835
973
  repoIds(): string[];
836
974
  private getObjMap;
837
975
  private getRefMap;
@@ -981,4 +1119,4 @@ declare class PgStorage implements Storage {
981
1119
  atomicRefUpdate<T>(repoId: string, fn: (ops: RefOps) => Promise<T> | T): Promise<T>;
982
1120
  }
983
1121
 
984
- export { type AdvertiseRefsEvent, type AdvertiseResult, type ApplyReceivePackOptions, type BetterSqlite3Database, BetterSqlite3Storage, type BunSqliteDatabase, BunSqliteStorage, type CreateRepoOptions, type GcOptions, type GcResult, GitRepo, type GitServer, type GitServerConfig, type MaybeAsync, MemoryStorage, type NodeHttpRequest, type NodeHttpResponse, type PgPool, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type PushCommand, RawObject, type RawRefEntry, type ReceivePackResult, Ref, type RefAdvertisement, type RefOps, type RefResult, type RefUpdate, type RefUpdateRequest, type RefUpdateResult, Rejection, type ServerHooks, type ServerPolicy, type Session, type SessionBuilder, type SshChannel, type SshSessionInfo, type Storage, type UpdateEvent, advertiseRefsWithHooks, applyReceivePack, buildRefAdvertisementBytes, buildRefListBytes, buildRefListPktLines, collectRefs, composeHooks, createServer, handleUploadPack, ingestReceivePack, ingestReceivePackFromStream, resolveRefUpdates };
1122
+ export { type AdvertiseRefsEvent, type AdvertiseResult, type ApplyReceivePackOptions, type BetterSqlite3Database, BetterSqlite3Storage, type BunSqliteDatabase, BunSqliteStorage, type CreateRepoOptions, type GcOptions, type GcResult, GitRepo, type GitServer, type GitServerConfig, type MaybeAsync, MemoryStorage, type NodeHttpRequest, type NodeHttpResponse, type PgPool, PgStorage, type PostReceiveEvent, type PreReceiveEvent, type PushCommand, RawObject, type RawRefEntry, type ReceivePackResult, Ref, type RefAdvertisement, type RefOps, type RefResult, type RefUpdate, type RefUpdateRequest, type RefUpdateResult, Rejection, type ServerHooks, type ServerPolicy, type Session, type SessionBuilder, type SshChannel, type SshSessionInfo, type Storage, type UpdateEvent, type V2CommandRequest, type V2FetchRequest, type V2FetchResponseOptions, type V2LsRefsRef, advertiseRefsWithHooks, applyCasRefUpdates, applyReceivePack, buildRefAdvertisementBytes, buildRefListBytes, buildRefListPktLines, buildV2CapabilityAdvertisement, buildV2CapabilityAdvertisementBytes, buildV2FetchResponse, buildV2LsRefsResponse, collectRefs, composeHooks, createServer, handleLsRefs, handleUploadPack, handleV2Fetch, ingestReceivePack, ingestReceivePackFromStream, parseV2CommandRequest, parseV2FetchArgs, resolveRefUpdates };