@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/README.md +23 -0
- package/dist/index.cjs +42 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +42 -9
- package/dist/index.js.map +1 -1
- package/package.json +38 -39
- package/src/index.ts +41 -9
- package/src/types.ts +9 -1
package/package.json
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
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(
|
|
1204
|
-
}
|
|
1205
|
-
|
|
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
|
-
|
|
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 ||
|
|
1238
|
+
baseRepoOptions || resolvedDefaultBranch
|
|
1212
1239
|
? {
|
|
1213
1240
|
path: 'repos',
|
|
1214
1241
|
body: {
|
|
1215
1242
|
...(baseRepoOptions && { base_repo: baseRepoOptions }),
|
|
1216
|
-
default_branch:
|
|
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(
|
|
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
|
|
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;
|