@pierre/storage 0.4.2 → 0.6.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/dist/index.cjs +25 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +25 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/fetch.ts +11 -1
- package/src/index.ts +15 -8
- package/src/types.ts +6 -1
package/package.json
CHANGED
package/src/fetch.ts
CHANGED
|
@@ -45,7 +45,17 @@ export class ApiFetcher {
|
|
|
45
45
|
if (typeof path === 'string') {
|
|
46
46
|
return `${this.getBaseUrl()}/${path}`;
|
|
47
47
|
} else if (path.params) {
|
|
48
|
-
const
|
|
48
|
+
const searchParams = new URLSearchParams();
|
|
49
|
+
for (const [key, value] of Object.entries(path.params)) {
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
for (const v of value) {
|
|
52
|
+
searchParams.append(key, v);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
searchParams.append(key, value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const paramStr = searchParams.toString();
|
|
49
59
|
return `${this.getBaseUrl()}/${path.path}${paramStr ? `?${paramStr}` : ''}`;
|
|
50
60
|
} else {
|
|
51
61
|
return `${this.getBaseUrl()}/${path.path}`;
|
package/src/index.ts
CHANGED
|
@@ -363,6 +363,7 @@ class RepoImpl implements Repo {
|
|
|
363
363
|
|
|
364
364
|
constructor(
|
|
365
365
|
public readonly id: string,
|
|
366
|
+
public readonly defaultBranch: string,
|
|
366
367
|
private readonly options: GitStorageOptions,
|
|
367
368
|
private readonly generateJWT: (
|
|
368
369
|
repoId: string,
|
|
@@ -506,7 +507,7 @@ class RepoImpl implements Repo {
|
|
|
506
507
|
ttl,
|
|
507
508
|
});
|
|
508
509
|
|
|
509
|
-
const params: Record<string, string> = {
|
|
510
|
+
const params: Record<string, string | string[]> = {
|
|
510
511
|
branch: options.branch,
|
|
511
512
|
};
|
|
512
513
|
|
|
@@ -519,6 +520,9 @@ class RepoImpl implements Repo {
|
|
|
519
520
|
if (typeof options.ephemeralBase === 'boolean') {
|
|
520
521
|
params.ephemeral_base = String(options.ephemeralBase);
|
|
521
522
|
}
|
|
523
|
+
if (options.paths && options.paths.length > 0) {
|
|
524
|
+
params.path = options.paths;
|
|
525
|
+
}
|
|
522
526
|
|
|
523
527
|
const response = await this.api.get({ path: 'repos/branches/diff', params }, jwt);
|
|
524
528
|
|
|
@@ -533,13 +537,16 @@ class RepoImpl implements Repo {
|
|
|
533
537
|
ttl,
|
|
534
538
|
});
|
|
535
539
|
|
|
536
|
-
const params: Record<string, string> = {
|
|
540
|
+
const params: Record<string, string | string[]> = {
|
|
537
541
|
sha: options.sha,
|
|
538
542
|
};
|
|
539
543
|
|
|
540
544
|
if (options.baseSha) {
|
|
541
545
|
params.baseSha = options.baseSha;
|
|
542
546
|
}
|
|
547
|
+
if (options.paths && options.paths.length > 0) {
|
|
548
|
+
params.path = options.paths;
|
|
549
|
+
}
|
|
543
550
|
|
|
544
551
|
const response = await this.api.get({ path: 'repos/diff', params }, jwt);
|
|
545
552
|
|
|
@@ -886,8 +893,8 @@ export class GitStorage {
|
|
|
886
893
|
}
|
|
887
894
|
: null;
|
|
888
895
|
|
|
889
|
-
//
|
|
890
|
-
const defaultBranch = options?.defaultBranch ?? 'main';
|
|
896
|
+
// Match backend priority: baseRepo.defaultBranch > options.defaultBranch > 'main'
|
|
897
|
+
const defaultBranch = options?.baseRepo?.defaultBranch ?? options?.defaultBranch ?? 'main';
|
|
891
898
|
|
|
892
899
|
const createRepoPath =
|
|
893
900
|
baseRepoOptions || defaultBranch
|
|
@@ -906,7 +913,7 @@ export class GitStorage {
|
|
|
906
913
|
throw new Error('Repository already exists');
|
|
907
914
|
}
|
|
908
915
|
|
|
909
|
-
return new RepoImpl(repoId, this.options, this.generateJWT.bind(this));
|
|
916
|
+
return new RepoImpl(repoId, defaultBranch, this.options, this.generateJWT.bind(this));
|
|
910
917
|
}
|
|
911
918
|
|
|
912
919
|
/**
|
|
@@ -925,9 +932,9 @@ export class GitStorage {
|
|
|
925
932
|
if (resp.status === 404) {
|
|
926
933
|
return null;
|
|
927
934
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
return new RepoImpl(options.id, this.options, this.generateJWT.bind(this));
|
|
935
|
+
const body = (await resp.json()) as { default_branch?: string };
|
|
936
|
+
const defaultBranch = body.default_branch ?? 'main';
|
|
937
|
+
return new RepoImpl(options.id, defaultBranch, this.options, this.generateJWT.bind(this));
|
|
931
938
|
}
|
|
932
939
|
|
|
933
940
|
/**
|
package/src/types.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface GetRemoteURLOptions {
|
|
|
37
37
|
|
|
38
38
|
export interface Repo {
|
|
39
39
|
id: string;
|
|
40
|
+
defaultBranch: string;
|
|
40
41
|
getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
|
|
41
42
|
getEphemeralRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
|
|
42
43
|
|
|
@@ -58,7 +59,7 @@ export type ValidMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
|
58
59
|
type SimplePath = string;
|
|
59
60
|
type ComplexPath = {
|
|
60
61
|
path: string;
|
|
61
|
-
params?: Record<string, string>;
|
|
62
|
+
params?: Record<string, string | string[]>;
|
|
62
63
|
body?: Record<string, any>;
|
|
63
64
|
};
|
|
64
65
|
export type ValidPath = SimplePath | ComplexPath;
|
|
@@ -197,6 +198,8 @@ export interface GetBranchDiffOptions extends GitStorageInvocationOptions {
|
|
|
197
198
|
base?: string;
|
|
198
199
|
ephemeral?: boolean;
|
|
199
200
|
ephemeralBase?: boolean;
|
|
201
|
+
/** Optional paths to filter the diff to specific files */
|
|
202
|
+
paths?: string[];
|
|
200
203
|
}
|
|
201
204
|
|
|
202
205
|
export type GetBranchDiffResponse = GetBranchDiffResponseRaw;
|
|
@@ -213,6 +216,8 @@ export interface GetBranchDiffResult {
|
|
|
213
216
|
export interface GetCommitDiffOptions extends GitStorageInvocationOptions {
|
|
214
217
|
sha: string;
|
|
215
218
|
baseSha?: string;
|
|
219
|
+
/** Optional paths to filter the diff to specific files */
|
|
220
|
+
paths?: string[];
|
|
216
221
|
}
|
|
217
222
|
|
|
218
223
|
export type GetCommitDiffResponse = GetCommitDiffResponseRaw;
|