@pierre/storage 0.8.0 → 0.9.1

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.1",
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,51 @@ 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
+ owner: this.options.name,
1214
+ name: baseRepo.id,
1215
+ operation: 'fork',
1216
+ auth: { token: baseRepoToken },
1217
+ ...(baseRepo.ref ? { ref: baseRepo.ref } : {}),
1218
+ ...(baseRepo.sha ? { sha: baseRepo.sha } : {}),
1219
+ };
1220
+ } else {
1221
+ baseRepoOptions = {
1202
1222
  provider: 'github',
1203
- ...snakecaseKeys(options.baseRepo as unknown as Record<string, unknown>),
1204
- }
1205
- : null;
1223
+ ...snakecaseKeys(baseRepo as unknown as Record<string, unknown>),
1224
+ };
1225
+ resolvedDefaultBranch = baseRepo.defaultBranch;
1226
+ }
1227
+ }
1206
1228
 
1207
1229
  // Match backend priority: baseRepo.defaultBranch > options.defaultBranch > 'main'
1208
- const defaultBranch = options?.baseRepo?.defaultBranch ?? options?.defaultBranch ?? 'main';
1230
+ if (!resolvedDefaultBranch) {
1231
+ if (options?.defaultBranch) {
1232
+ resolvedDefaultBranch = options.defaultBranch;
1233
+ } else if (!isFork) {
1234
+ resolvedDefaultBranch = 'main';
1235
+ }
1236
+ }
1209
1237
 
1210
1238
  const createRepoPath =
1211
- baseRepoOptions || defaultBranch
1239
+ baseRepoOptions || resolvedDefaultBranch
1212
1240
  ? {
1213
1241
  path: 'repos',
1214
1242
  body: {
1215
1243
  ...(baseRepoOptions && { base_repo: baseRepoOptions }),
1216
- default_branch: defaultBranch,
1244
+ ...(resolvedDefaultBranch && { default_branch: resolvedDefaultBranch }),
1217
1245
  },
1218
1246
  }
1219
1247
  : 'repos';
@@ -1224,7 +1252,12 @@ export class GitStorage {
1224
1252
  throw new Error('Repository already exists');
1225
1253
  }
1226
1254
 
1227
- return new RepoImpl(repoId, defaultBranch, this.options, this.generateJWT.bind(this));
1255
+ return new RepoImpl(
1256
+ repoId,
1257
+ resolvedDefaultBranch ?? 'main',
1258
+ this.options,
1259
+ this.generateJWT.bind(this),
1260
+ );
1228
1261
  }
1229
1262
 
1230
1263
  /**
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;