@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/README.md +23 -0
- package/dist/index.cjs +43 -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 +43 -9
- package/dist/index.js.map +1 -1
- package/package.json +38 -39
- package/src/index.ts +42 -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.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
|
|
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(
|
|
1204
|
-
}
|
|
1205
|
-
|
|
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
|
-
|
|
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 ||
|
|
1239
|
+
baseRepoOptions || resolvedDefaultBranch
|
|
1212
1240
|
? {
|
|
1213
1241
|
path: 'repos',
|
|
1214
1242
|
body: {
|
|
1215
1243
|
...(baseRepoOptions && { base_repo: baseRepoOptions }),
|
|
1216
|
-
default_branch:
|
|
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(
|
|
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
|
|
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;
|