@pierre/storage 1.0.3 → 1.1.0

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.
package/README.md CHANGED
@@ -72,6 +72,22 @@ if (foundRepo) {
72
72
  }
73
73
  ```
74
74
 
75
+ ### Hydrating a Repository Without a Request
76
+
77
+ If you already know the repo metadata, you can construct a `Repo` directly:
78
+
79
+ ```typescript
80
+ const repo = store.repo({
81
+ id: 'repo-id',
82
+ defaultBranch: 'main',
83
+ createdAt: '2024-06-15T12:00:00Z',
84
+ });
85
+
86
+ // No HTTP request is made by repo()
87
+ const url = await repo.getRemoteURL();
88
+ console.log(url);
89
+ ```
90
+
75
91
  ### Grep
76
92
 
77
93
  ```typescript
@@ -363,6 +379,7 @@ class GitStorage {
363
379
  constructor(options: GitStorageOptions);
364
380
  async createRepo(options?: CreateRepoOptions): Promise<Repo>;
365
381
  async findOne(options: FindOneOptions): Promise<Repo | null>;
382
+ repo(options: RepoOptions): Repo;
366
383
  getConfig(): GitStorageOptions;
367
384
  }
368
385
  ```
@@ -400,6 +417,12 @@ interface FindOneOptions {
400
417
  id: string; // Repository ID to find
401
418
  }
402
419
 
420
+ interface RepoOptions {
421
+ id: string; // Repository ID
422
+ defaultBranch?: string; // Defaults to "main"
423
+ createdAt?: string; // Defaults to ""
424
+ }
425
+
403
426
  interface Repo {
404
427
  id: string;
405
428
  getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
package/dist/index.cjs CHANGED
@@ -514,7 +514,7 @@ function concatChunks(a, b) {
514
514
 
515
515
  // package.json
516
516
  var package_default = {
517
- version: "1.0.3"};
517
+ version: "1.1.0"};
518
518
 
519
519
  // src/version.ts
520
520
  var PACKAGE_NAME = "code-storage-sdk";
@@ -2418,13 +2418,11 @@ var GitStorage = class _GitStorage {
2418
2418
  if (resp.status === 409) {
2419
2419
  throw new Error("Repository already exists");
2420
2420
  }
2421
- return new RepoImpl(
2422
- repoId,
2423
- resolvedDefaultBranch ?? "main",
2424
- (/* @__PURE__ */ new Date()).toISOString(),
2425
- this.options,
2426
- this.generateJWT.bind(this)
2427
- );
2421
+ return this.repo({
2422
+ id: repoId,
2423
+ defaultBranch: resolvedDefaultBranch ?? "main",
2424
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
2425
+ });
2428
2426
  }
2429
2427
  /**
2430
2428
  * List repositories for the authenticated organization
@@ -2470,10 +2468,23 @@ var GitStorage = class _GitStorage {
2470
2468
  const body = await resp.json();
2471
2469
  const defaultBranch = body.default_branch ?? "main";
2472
2470
  const createdAt = body.created_at ?? "";
2471
+ return this.repo({
2472
+ id: options.id,
2473
+ defaultBranch,
2474
+ createdAt
2475
+ });
2476
+ }
2477
+ /**
2478
+ * Create a Repo handle from known metadata without making an HTTP request.
2479
+ */
2480
+ repo(options) {
2481
+ if (!options || typeof options.id !== "string" || options.id.trim() === "") {
2482
+ throw new Error("repo requires a non-empty repository id.");
2483
+ }
2473
2484
  return new RepoImpl(
2474
2485
  options.id,
2475
- defaultBranch,
2476
- createdAt,
2486
+ options.defaultBranch ?? "main",
2487
+ options.createdAt ?? "",
2477
2488
  this.options,
2478
2489
  this.generateJWT.bind(this)
2479
2490
  );