just-git 1.3.7 → 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,5 @@
1
- import { i as ObjectId, _ 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';
2
3
 
3
4
  /** Shallow boundary delta: what to add/remove from `.git/shallow`. */
4
5
  interface ShallowUpdate {
@@ -271,8 +272,10 @@ interface GitServerConfig<S = Session> {
271
272
  * The server calls `createStorageAdapter(storage)` internally to build the
272
273
  * git-aware adapter. Users provide the storage backend; they never see
273
274
  * the `StorageAdapter` interface.
275
+ *
276
+ * Defaults to {@link MemoryStorage} when omitted.
274
277
  */
275
- storage: Storage;
278
+ storage?: Storage;
276
279
  /**
277
280
  * Map a request path to a repo ID.
278
281
  *
@@ -345,8 +348,8 @@ interface GitServerConfig<S = Session> {
345
348
  /**
346
349
  * A ref update request for {@link GitServer.updateRefs}.
347
350
  *
348
- * In-process equivalent of a push command updates a ref with CAS
349
- * 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.
350
353
  */
351
354
  interface RefUpdateRequest {
352
355
  /** Full ref name (e.g. `"refs/heads/main"`, `"refs/tags/v1.0"`). */
@@ -364,7 +367,7 @@ interface RefUpdateRequest {
364
367
  */
365
368
  oldHash?: string | null;
366
369
  }
367
- interface GitServer<S = Session> {
370
+ interface GitServer {
368
371
  /** Standard fetch-API handler for HTTP: (Request) => Response */
369
372
  fetch(request: Request): Promise<Response>;
370
373
  /**
@@ -401,14 +404,15 @@ interface GitServer<S = Session> {
401
404
  */
402
405
  handleSession(command: string, channel: SshChannel, session?: SshSessionInfo): Promise<number>;
403
406
  /**
404
- * Update refs in-process with hook enforcement and CAS protection.
407
+ * Update refs in-process with CAS protection.
405
408
  *
406
- * Equivalent to a push, but without transport overhead — no pack
407
- * negotiation, no object transfer. Objects must already exist in
408
- * 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.
409
413
  *
410
- * Runs the full hook lifecycle: `preReceive` per-ref `update`
411
- * 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`).
412
416
  *
413
417
  * ```ts
414
418
  * import { createCommit, writeBlob, writeTree } from "just-git/repo";
@@ -425,7 +429,36 @@ interface GitServer<S = Session> {
425
429
  *
426
430
  * @throws If the repo does not exist or the server is shutting down.
427
431
  */
428
- 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>;
429
462
  /**
430
463
  * Node.js `http.createServer` compatible handler.
431
464
  *
@@ -535,8 +568,8 @@ interface PreReceiveEvent<S = Session> {
535
568
  /** Resolved repo ID (the value returned by `resolve`, or the raw path when `resolve` is not set). */
536
569
  repoId: string;
537
570
  updates: readonly RefUpdate[];
538
- /** Session info. Present for HTTP and SSH; absent for in-process pushes. */
539
- session?: S;
571
+ /** Session built by the transport's session builder. Always present hooks only fire from HTTP/SSH transport. */
572
+ session: S;
540
573
  }
541
574
  /** Fired per-ref after preReceive passes. */
542
575
  interface UpdateEvent<S = Session> {
@@ -544,8 +577,8 @@ interface UpdateEvent<S = Session> {
544
577
  /** Resolved repo ID (the value returned by `resolve`, or the raw path when `resolve` is not set). */
545
578
  repoId: string;
546
579
  update: RefUpdate;
547
- /** Session info. Present for HTTP and SSH; absent for in-process pushes. */
548
- session?: S;
580
+ /** Session built by the transport's session builder. Always present hooks only fire from HTTP/SSH transport. */
581
+ session: S;
549
582
  }
550
583
  /** Fired after all ref updates succeed. */
551
584
  interface PostReceiveEvent<S = Session> {
@@ -553,8 +586,8 @@ interface PostReceiveEvent<S = Session> {
553
586
  /** Resolved repo ID (the value returned by `resolve`, or the raw path when `resolve` is not set). */
554
587
  repoId: string;
555
588
  updates: readonly RefUpdate[];
556
- /** Session info. Present for HTTP and SSH; absent for in-process pushes. */
557
- session?: S;
589
+ /** Session built by the transport's session builder. Always present hooks only fire from HTTP/SSH transport. */
590
+ session: S;
558
591
  }
559
592
  /** Fired during ref advertisement (info/refs). */
560
593
  interface AdvertiseRefsEvent<S = Session> {
@@ -563,15 +596,15 @@ interface AdvertiseRefsEvent<S = Session> {
563
596
  repoId: string;
564
597
  refs: RefAdvertisement[];
565
598
  service: "git-upload-pack" | "git-receive-pack";
566
- /** Session info. Present for HTTP and SSH; absent for in-process requests. */
567
- session?: S;
599
+ /** Session built by the transport's session builder. Always present hooks only fire from HTTP/SSH transport. */
600
+ session: S;
568
601
  }
569
602
  /** A ref name and hash advertised to clients during fetch/push discovery. */
570
603
  interface RefAdvertisement {
571
604
  name: string;
572
605
  hash: string;
573
606
  }
574
- /** 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. */
575
608
  interface RefResult {
576
609
  ref: string;
577
610
  ok: boolean;
@@ -592,10 +625,7 @@ interface RefUpdateResult {
592
625
  * works with any SSH library (ssh2, etc.) through a thin adapter.
593
626
  *
594
627
  * ```ts
595
- * const server = createServer({
596
- * storage: new MemoryStorage(),
597
- * autoCreate: true,
598
- * });
628
+ * const server = createServer({ autoCreate: true });
599
629
  * await server.createRepo("my-repo");
600
630
  *
601
631
  * // HTTP
@@ -608,7 +638,6 @@ interface RefUpdateResult {
608
638
  *
609
639
  * ```ts
610
640
  * const server = createServer({
611
- * storage: new MemoryStorage(),
612
641
  * autoCreate: true,
613
642
  * });
614
643
  * await server.createRepo("my-repo");
@@ -620,7 +649,7 @@ interface RefUpdateResult {
620
649
  * server.handleSession(command, channel, { username });
621
650
  * ```
622
651
  */
623
- declare function createServer<S = Session>(config: GitServerConfig<S>): GitServer<S>;
652
+ declare function createServer<S = Session>(config?: GitServerConfig<S>): GitServer;
624
653
  /**
625
654
  * Compose multiple hook sets into a single `ServerHooks` object.
626
655
  *
@@ -816,7 +845,7 @@ interface AdvertiseResult {
816
845
  * Both HTTP and SSH code paths use this — the caller handles the
817
846
  * transport-specific response (HTTP 403 vs SSH exit 128).
818
847
  */
819
- 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>;
820
849
  interface UploadPackOptions {
821
850
  /** Pack cache instance. When provided, full clones (no haves) are cached. */
822
851
  cache?: PackCache;
@@ -858,18 +887,26 @@ declare function ingestReceivePack(repo: GitRepo, requestBody: Uint8Array): Prom
858
887
  * pkt-line commands.
859
888
  */
860
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>;
861
899
  interface ApplyReceivePackOptions<S = unknown> {
862
900
  repo: GitRepo;
863
901
  repoId: string;
864
902
  ingestResult: ReceivePackResult;
865
903
  hooks?: ServerHooks<S>;
866
- /** Session info threaded through to hooks. */
867
- session?: S;
904
+ session: S;
868
905
  }
869
906
  /**
870
907
  * Run the full receive-pack lifecycle: preReceive hook, per-ref update
871
908
  * hook with ref format validation, CAS ref application, and postReceive
872
- * hook. Transport-agnosticworks for HTTP, SSH, or in-process pushes.
909
+ * hook. Transport-onlyused by HTTP and SSH push handlers.
873
910
  *
874
911
  * Returns per-ref results and the list of successfully applied updates.
875
912
  * Does NOT handle unpack failures — the caller should check
@@ -889,7 +926,7 @@ declare function buildV2CapabilityAdvertisementBytes(): Uint8Array;
889
926
  * then builds a v2 ls-refs response respecting the client's requested
890
927
  * attributes (symrefs, peel, ref-prefix, unborn).
891
928
  */
892
- declare function handleLsRefs<S>(repo: GitRepo, repoId: string, args: string[], hooks?: ServerHooks<S>, session?: S): Promise<Uint8Array | Rejection>;
929
+ declare function handleLsRefs<S>(repo: GitRepo, repoId: string, args: string[], hooks: ServerHooks<S> | undefined, session: S): Promise<Uint8Array | Rejection>;
893
930
  /**
894
931
  * Handle a v2 `fetch` command. Parses fetch args, performs object
895
932
  * enumeration and pack building via the shared pipeline, then
@@ -904,10 +941,9 @@ declare function handleV2Fetch(repo: GitRepo, args: string[], options?: UploadPa
904
941
  * Data is lost when the process exits.
905
942
  *
906
943
  * ```ts
907
- * const server = createServer({
908
- * storage: new MemoryStorage(),
909
- * });
910
- * await server.createRepo("my-repo");
944
+ * // MemoryStorage is the default — these are equivalent:
945
+ * const server = createServer();
946
+ * const server2 = createServer({ storage: new MemoryStorage() });
911
947
  * ```
912
948
  */
913
949
  declare class MemoryStorage implements Storage {
@@ -933,6 +969,7 @@ declare class MemoryStorage implements Storage {
933
969
  removeRef(repoId: string, name: string): void;
934
970
  listRefs(repoId: string, prefix?: string): RawRefEntry[];
935
971
  atomicRefUpdate<T>(repoId: string, fn: (ops: RefOps) => T): T;
972
+ /** List all created repo IDs. Convenience for tests and debugging. */
936
973
  repoIds(): string[];
937
974
  private getObjMap;
938
975
  private getRefMap;
@@ -1082,4 +1119,4 @@ declare class PgStorage implements Storage {
1082
1119
  atomicRefUpdate<T>(repoId: string, fn: (ops: RefOps) => Promise<T> | T): Promise<T>;
1083
1120
  }
1084
1121
 
1085
- 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, applyReceivePack, buildRefAdvertisementBytes, buildRefListBytes, buildRefListPktLines, buildV2CapabilityAdvertisement, buildV2CapabilityAdvertisementBytes, buildV2FetchResponse, buildV2LsRefsResponse, collectRefs, composeHooks, createServer, handleLsRefs, handleUploadPack, handleV2Fetch, ingestReceivePack, ingestReceivePackFromStream, parseV2CommandRequest, parseV2FetchArgs, 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 };