@pierre/storage 0.8.0 → 0.9.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/package.json CHANGED
@@ -1,40 +1,39 @@
1
1
  {
2
- "name": "@pierre/storage",
3
- "version": "0.8.0",
4
- "description": "Pierre Git Storage SDK",
5
- "license": "MIT",
6
- "type": "module",
7
- "main": "./dist/index.cjs",
8
- "module": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
10
- "exports": {
11
- ".": {
12
- "types": "./dist/index.d.ts",
13
- "import": "./dist/index.js",
14
- "require": "./dist/index.cjs",
15
- "default": "./dist/index.js"
16
- }
17
- },
18
- "files": [
19
- "dist",
20
- "src"
21
- ],
22
- "scripts": {
23
- "build": "tsup",
24
- "dev": "tsup --watch",
25
- "prepublishOnly": "pnpm build"
26
- },
27
- "dependencies": {
28
- "jose": "^5.10.0",
29
- "snakecase-keys": "^9.0.2",
30
- "zod": "^3.23.8"
31
- },
32
- "devDependencies": {
33
- "tsup": "8.5.0",
34
- "typescript": "5.8.3",
35
- "vitest": "3.2.4"
36
- },
37
- "publishConfig": {
38
- "access": "public"
39
- }
40
- }
2
+ "name": "@pierre/storage",
3
+ "version": "0.9.0",
4
+ "description": "Pierre Git Storage SDK",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "src"
21
+ ],
22
+ "dependencies": {
23
+ "jose": "^5.10.0",
24
+ "snakecase-keys": "^9.0.2",
25
+ "zod": "^3.23.8"
26
+ },
27
+ "devDependencies": {
28
+ "tsup": "8.5.0",
29
+ "typescript": "5.8.3",
30
+ "vitest": "3.2.4"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "build": "tsup",
37
+ "dev": "tsup --watch"
38
+ }
39
+ }
package/src/index.ts CHANGED
@@ -1197,23 +1197,50 @@ export class GitStorage {
1197
1197
  ttl,
1198
1198
  });
1199
1199
 
1200
- const baseRepoOptions = options?.baseRepo
1201
- ? {
1200
+ const baseRepo = options?.baseRepo;
1201
+ const isFork = baseRepo ? 'id' in baseRepo : false;
1202
+ let baseRepoOptions: Record<string, unknown> | null = null;
1203
+ let resolvedDefaultBranch: string | undefined;
1204
+
1205
+ if (baseRepo) {
1206
+ if ('id' in baseRepo) {
1207
+ const baseRepoToken = await this.generateJWT(baseRepo.id, {
1208
+ permissions: ['git:read'],
1209
+ ttl,
1210
+ });
1211
+ baseRepoOptions = {
1212
+ provider: 'code',
1213
+ name: baseRepo.id,
1214
+ operation: 'fork',
1215
+ auth: { token: baseRepoToken },
1216
+ ...(baseRepo.ref ? { ref: baseRepo.ref } : {}),
1217
+ ...(baseRepo.sha ? { sha: baseRepo.sha } : {}),
1218
+ };
1219
+ } else {
1220
+ baseRepoOptions = {
1202
1221
  provider: 'github',
1203
- ...snakecaseKeys(options.baseRepo as unknown as Record<string, unknown>),
1204
- }
1205
- : null;
1222
+ ...snakecaseKeys(baseRepo as unknown as Record<string, unknown>),
1223
+ };
1224
+ resolvedDefaultBranch = baseRepo.defaultBranch;
1225
+ }
1226
+ }
1206
1227
 
1207
1228
  // Match backend priority: baseRepo.defaultBranch > options.defaultBranch > 'main'
1208
- const defaultBranch = options?.baseRepo?.defaultBranch ?? options?.defaultBranch ?? 'main';
1229
+ if (!resolvedDefaultBranch) {
1230
+ if (options?.defaultBranch) {
1231
+ resolvedDefaultBranch = options.defaultBranch;
1232
+ } else if (!isFork) {
1233
+ resolvedDefaultBranch = 'main';
1234
+ }
1235
+ }
1209
1236
 
1210
1237
  const createRepoPath =
1211
- baseRepoOptions || defaultBranch
1238
+ baseRepoOptions || resolvedDefaultBranch
1212
1239
  ? {
1213
1240
  path: 'repos',
1214
1241
  body: {
1215
1242
  ...(baseRepoOptions && { base_repo: baseRepoOptions }),
1216
- default_branch: defaultBranch,
1243
+ ...(resolvedDefaultBranch && { default_branch: resolvedDefaultBranch }),
1217
1244
  },
1218
1245
  }
1219
1246
  : 'repos';
@@ -1224,7 +1251,12 @@ export class GitStorage {
1224
1251
  throw new Error('Repository already exists');
1225
1252
  }
1226
1253
 
1227
- return new RepoImpl(repoId, defaultBranch, this.options, this.generateJWT.bind(this));
1254
+ return new RepoImpl(
1255
+ repoId,
1256
+ resolvedDefaultBranch ?? 'main',
1257
+ this.options,
1258
+ this.generateJWT.bind(this),
1259
+ );
1228
1260
  }
1229
1261
 
1230
1262
  /**
package/src/types.ts CHANGED
@@ -83,7 +83,7 @@ export interface FindOneOptions {
83
83
 
84
84
  export type SupportedRepoProvider = 'github';
85
85
 
86
- export interface BaseRepo {
86
+ export interface GitHubBaseRepo {
87
87
  /**
88
88
  * @default github
89
89
  */
@@ -93,6 +93,14 @@ export interface BaseRepo {
93
93
  defaultBranch?: string;
94
94
  }
95
95
 
96
+ export interface ForkBaseRepo {
97
+ id: string;
98
+ ref?: string;
99
+ sha?: string;
100
+ }
101
+
102
+ export type BaseRepo = GitHubBaseRepo | ForkBaseRepo;
103
+
96
104
  export interface ListReposOptions extends GitStorageInvocationOptions {
97
105
  cursor?: string;
98
106
  limit?: number;