@pierre/storage 1.0.2 → 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 +35 -0
- package/dist/index.cjs +21 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +21 -10
- package/dist/index.js.map +1 -1
- package/package.json +40 -39
- package/src/index.ts +29 -10
- package/src/types.ts +14 -0
package/README.md
CHANGED
|
@@ -51,6 +51,15 @@ const forkedRepo = await store.createRepo({
|
|
|
51
51
|
},
|
|
52
52
|
});
|
|
53
53
|
// If defaultBranch is omitted, the SDK returns "main".
|
|
54
|
+
|
|
55
|
+
// Create a repo synced to a public GitHub repository without app auth
|
|
56
|
+
const publicSyncRepo = await store.createRepo({
|
|
57
|
+
baseRepo: {
|
|
58
|
+
owner: 'octocat',
|
|
59
|
+
name: 'Hello-World',
|
|
60
|
+
auth: { authType: 'public' },
|
|
61
|
+
},
|
|
62
|
+
});
|
|
54
63
|
```
|
|
55
64
|
|
|
56
65
|
### Finding a Repository
|
|
@@ -63,6 +72,22 @@ if (foundRepo) {
|
|
|
63
72
|
}
|
|
64
73
|
```
|
|
65
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
|
+
|
|
66
91
|
### Grep
|
|
67
92
|
|
|
68
93
|
```typescript
|
|
@@ -354,6 +379,7 @@ class GitStorage {
|
|
|
354
379
|
constructor(options: GitStorageOptions);
|
|
355
380
|
async createRepo(options?: CreateRepoOptions): Promise<Repo>;
|
|
356
381
|
async findOne(options: FindOneOptions): Promise<Repo | null>;
|
|
382
|
+
repo(options: RepoOptions): Repo;
|
|
357
383
|
getConfig(): GitStorageOptions;
|
|
358
384
|
}
|
|
359
385
|
```
|
|
@@ -380,6 +406,9 @@ interface CreateRepoOptions {
|
|
|
380
406
|
name: string; // GitHub repository name
|
|
381
407
|
defaultBranch?: string;
|
|
382
408
|
provider?: 'github';
|
|
409
|
+
auth?: {
|
|
410
|
+
authType: 'public'; // Force public GitHub mode (no app install)
|
|
411
|
+
};
|
|
383
412
|
};
|
|
384
413
|
defaultBranch?: string; // Optional default branch name (defaults to "main")
|
|
385
414
|
}
|
|
@@ -388,6 +417,12 @@ interface FindOneOptions {
|
|
|
388
417
|
id: string; // Repository ID to find
|
|
389
418
|
}
|
|
390
419
|
|
|
420
|
+
interface RepoOptions {
|
|
421
|
+
id: string; // Repository ID
|
|
422
|
+
defaultBranch?: string; // Defaults to "main"
|
|
423
|
+
createdAt?: string; // Defaults to ""
|
|
424
|
+
}
|
|
425
|
+
|
|
391
426
|
interface Repo {
|
|
392
427
|
id: string;
|
|
393
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
|
|
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
|
|
2422
|
-
repoId,
|
|
2423
|
-
resolvedDefaultBranch ?? "main",
|
|
2424
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
2425
|
-
|
|
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
|
);
|