@pierre/storage 0.2.1 → 0.2.3
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 +30 -0
- package/dist/index.cjs +50 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -2
- package/dist/index.d.ts +34 -2
- package/dist/index.js +50 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +55 -1
- package/src/schemas.ts +8 -0
- package/src/types.ts +21 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { RestoreCommitAckRaw } from './schemas';
|
|
|
14
14
|
import {
|
|
15
15
|
branchDiffResponseSchema,
|
|
16
16
|
commitDiffResponseSchema,
|
|
17
|
+
createBranchResponseSchema,
|
|
17
18
|
listBranchesResponseSchema,
|
|
18
19
|
listCommitsResponseSchema,
|
|
19
20
|
listFilesResponseSchema,
|
|
@@ -25,6 +26,9 @@ import type {
|
|
|
25
26
|
CommitBuilder,
|
|
26
27
|
CommitInfo,
|
|
27
28
|
CommitResult,
|
|
29
|
+
CreateBranchOptions,
|
|
30
|
+
CreateBranchResponse,
|
|
31
|
+
CreateBranchResult,
|
|
28
32
|
CreateCommitFromDiffOptions,
|
|
29
33
|
CreateCommitOptions,
|
|
30
34
|
CreateRepoOptions,
|
|
@@ -318,6 +322,15 @@ function transformCommitDiffResult(raw: GetCommitDiffResponse): GetCommitDiffRes
|
|
|
318
322
|
};
|
|
319
323
|
}
|
|
320
324
|
|
|
325
|
+
function transformCreateBranchResult(raw: CreateBranchResponse): CreateBranchResult {
|
|
326
|
+
return {
|
|
327
|
+
message: raw.message,
|
|
328
|
+
targetBranch: raw.target_branch,
|
|
329
|
+
targetIsEphemeral: raw.target_is_ephemeral,
|
|
330
|
+
commitSha: raw.commit_sha ?? undefined,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
321
334
|
/**
|
|
322
335
|
* Implementation of the Repo interface
|
|
323
336
|
*/
|
|
@@ -346,6 +359,14 @@ class RepoImpl implements Repo {
|
|
|
346
359
|
return url.toString();
|
|
347
360
|
}
|
|
348
361
|
|
|
362
|
+
async getEphemeralRemoteURL(urlOptions?: GetRemoteURLOptions): Promise<string> {
|
|
363
|
+
const storageBaseUrl = this.options.storageBaseUrl ?? STORAGE_BASE_URL;
|
|
364
|
+
const url = new URL(`https://${this.options.name}.${storageBaseUrl}/${this.id}+ephemeral.git`);
|
|
365
|
+
url.username = `t`;
|
|
366
|
+
url.password = await this.generateJWT(this.id, urlOptions);
|
|
367
|
+
return url.toString();
|
|
368
|
+
}
|
|
369
|
+
|
|
349
370
|
async getFileStream(options: GetFileOptions): Promise<Response> {
|
|
350
371
|
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
351
372
|
const jwt = await this.generateJWT(this.id, {
|
|
@@ -491,7 +512,7 @@ class RepoImpl implements Repo {
|
|
|
491
512
|
return transformCommitDiffResult(raw);
|
|
492
513
|
}
|
|
493
514
|
|
|
494
|
-
async pullUpstream(options: PullUpstreamOptions): Promise<void> {
|
|
515
|
+
async pullUpstream(options: PullUpstreamOptions = {}): Promise<void> {
|
|
495
516
|
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
496
517
|
const jwt = await this.generateJWT(this.id, {
|
|
497
518
|
permissions: ['git:write'],
|
|
@@ -513,6 +534,39 @@ class RepoImpl implements Repo {
|
|
|
513
534
|
return;
|
|
514
535
|
}
|
|
515
536
|
|
|
537
|
+
async createBranch(options: CreateBranchOptions): Promise<CreateBranchResult> {
|
|
538
|
+
const baseBranch = options?.baseBranch?.trim();
|
|
539
|
+
if (!baseBranch) {
|
|
540
|
+
throw new Error('createBranch baseBranch is required');
|
|
541
|
+
}
|
|
542
|
+
const targetBranch = options?.targetBranch?.trim();
|
|
543
|
+
if (!targetBranch) {
|
|
544
|
+
throw new Error('createBranch targetBranch is required');
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
|
|
548
|
+
const jwt = await this.generateJWT(this.id, {
|
|
549
|
+
permissions: ['git:write'],
|
|
550
|
+
ttl,
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
const body: Record<string, unknown> = {
|
|
554
|
+
base_branch: baseBranch,
|
|
555
|
+
target_branch: targetBranch,
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
if (options.baseIsEphemeral === true) {
|
|
559
|
+
body.base_is_ephemeral = true;
|
|
560
|
+
}
|
|
561
|
+
if (options.targetIsEphemeral === true) {
|
|
562
|
+
body.target_is_ephemeral = true;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const response = await this.api.post({ path: 'repos/branches/create', body }, jwt);
|
|
566
|
+
const raw = createBranchResponseSchema.parse(await response.json());
|
|
567
|
+
return transformCreateBranchResult(raw);
|
|
568
|
+
}
|
|
569
|
+
|
|
516
570
|
async restoreCommit(options: RestoreCommitOptions): Promise<RestoreCommitResult> {
|
|
517
571
|
const targetBranch = options?.targetBranch?.trim();
|
|
518
572
|
if (!targetBranch) {
|
package/src/schemas.ts
CHANGED
|
@@ -73,6 +73,13 @@ export const commitDiffResponseSchema = z.object({
|
|
|
73
73
|
filtered_files: z.array(filteredFileRawSchema),
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
+
export const createBranchResponseSchema = z.object({
|
|
77
|
+
message: z.string(),
|
|
78
|
+
target_branch: z.string(),
|
|
79
|
+
target_is_ephemeral: z.boolean(),
|
|
80
|
+
commit_sha: z.string().nullable().optional(),
|
|
81
|
+
});
|
|
82
|
+
|
|
76
83
|
export const refUpdateResultSchema = z.object({
|
|
77
84
|
branch: z.string(),
|
|
78
85
|
old_sha: z.string(),
|
|
@@ -134,5 +141,6 @@ export type RawFileDiff = z.infer<typeof diffFileRawSchema>;
|
|
|
134
141
|
export type RawFilteredFile = z.infer<typeof filteredFileRawSchema>;
|
|
135
142
|
export type GetBranchDiffResponseRaw = z.infer<typeof branchDiffResponseSchema>;
|
|
136
143
|
export type GetCommitDiffResponseRaw = z.infer<typeof commitDiffResponseSchema>;
|
|
144
|
+
export type CreateBranchResponseRaw = z.infer<typeof createBranchResponseSchema>;
|
|
137
145
|
export type CommitPackAckRaw = z.infer<typeof commitPackAckSchema>;
|
|
138
146
|
export type RestoreCommitAckRaw = z.infer<typeof restoreCommitAckSchema>;
|
package/src/types.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
|
+
CreateBranchResponseRaw,
|
|
6
7
|
GetBranchDiffResponseRaw,
|
|
7
8
|
GetCommitDiffResponseRaw,
|
|
8
9
|
ListBranchesResponseRaw,
|
|
@@ -37,6 +38,7 @@ export interface GetRemoteURLOptions {
|
|
|
37
38
|
export interface Repo {
|
|
38
39
|
id: string;
|
|
39
40
|
getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
|
|
41
|
+
getEphemeralRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
|
|
40
42
|
|
|
41
43
|
getFileStream(options: GetFileOptions): Promise<Response>;
|
|
42
44
|
listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
|
|
@@ -44,8 +46,9 @@ export interface Repo {
|
|
|
44
46
|
listCommits(options?: ListCommitsOptions): Promise<ListCommitsResult>;
|
|
45
47
|
getBranchDiff(options: GetBranchDiffOptions): Promise<GetBranchDiffResult>;
|
|
46
48
|
getCommitDiff(options: GetCommitDiffOptions): Promise<GetCommitDiffResult>;
|
|
47
|
-
pullUpstream(options
|
|
49
|
+
pullUpstream(options?: PullUpstreamOptions): Promise<void>;
|
|
48
50
|
restoreCommit(options: RestoreCommitOptions): Promise<RestoreCommitResult>;
|
|
51
|
+
createBranch(options: CreateBranchOptions): Promise<CreateBranchResult>;
|
|
49
52
|
createCommit(options: CreateCommitOptions): CommitBuilder;
|
|
50
53
|
createCommitFromDiff(options: CreateCommitFromDiffOptions): Promise<CommitResult>;
|
|
51
54
|
}
|
|
@@ -132,6 +135,23 @@ export interface ListBranchesResult {
|
|
|
132
135
|
hasMore: boolean;
|
|
133
136
|
}
|
|
134
137
|
|
|
138
|
+
// Create Branch API types
|
|
139
|
+
export interface CreateBranchOptions extends GitStorageInvocationOptions {
|
|
140
|
+
baseBranch: string;
|
|
141
|
+
targetBranch: string;
|
|
142
|
+
baseIsEphemeral?: boolean;
|
|
143
|
+
targetIsEphemeral?: boolean;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type CreateBranchResponse = CreateBranchResponseRaw;
|
|
147
|
+
|
|
148
|
+
export interface CreateBranchResult {
|
|
149
|
+
message: string;
|
|
150
|
+
targetBranch: string;
|
|
151
|
+
targetIsEphemeral: boolean;
|
|
152
|
+
commitSha?: string;
|
|
153
|
+
}
|
|
154
|
+
|
|
135
155
|
// List Commits API types
|
|
136
156
|
export interface ListCommitsOptions extends GitStorageInvocationOptions {
|
|
137
157
|
branch?: string;
|