@pierre/storage 0.2.1 → 0.2.2

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@pierre/storage",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Pierre Git Storage SDK",
5
5
  "license": "MIT",
6
6
  "type": "module",
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
  */
@@ -491,7 +504,7 @@ class RepoImpl implements Repo {
491
504
  return transformCommitDiffResult(raw);
492
505
  }
493
506
 
494
- async pullUpstream(options: PullUpstreamOptions): Promise<void> {
507
+ async pullUpstream(options: PullUpstreamOptions = {}): Promise<void> {
495
508
  const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
496
509
  const jwt = await this.generateJWT(this.id, {
497
510
  permissions: ['git:write'],
@@ -513,6 +526,39 @@ class RepoImpl implements Repo {
513
526
  return;
514
527
  }
515
528
 
529
+ async createBranch(options: CreateBranchOptions): Promise<CreateBranchResult> {
530
+ const baseBranch = options?.baseBranch?.trim();
531
+ if (!baseBranch) {
532
+ throw new Error('createBranch baseBranch is required');
533
+ }
534
+ const targetBranch = options?.targetBranch?.trim();
535
+ if (!targetBranch) {
536
+ throw new Error('createBranch targetBranch is required');
537
+ }
538
+
539
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
540
+ const jwt = await this.generateJWT(this.id, {
541
+ permissions: ['git:write'],
542
+ ttl,
543
+ });
544
+
545
+ const body: Record<string, unknown> = {
546
+ base_branch: baseBranch,
547
+ target_branch: targetBranch,
548
+ };
549
+
550
+ if (options.baseIsEphemeral === true) {
551
+ body.base_is_ephemeral = true;
552
+ }
553
+ if (options.targetIsEphemeral === true) {
554
+ body.target_is_ephemeral = true;
555
+ }
556
+
557
+ const response = await this.api.post({ path: 'repos/branches/create', body }, jwt);
558
+ const raw = createBranchResponseSchema.parse(await response.json());
559
+ return transformCreateBranchResult(raw);
560
+ }
561
+
516
562
  async restoreCommit(options: RestoreCommitOptions): Promise<RestoreCommitResult> {
517
563
  const targetBranch = options?.targetBranch?.trim();
518
564
  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,
@@ -44,8 +45,9 @@ export interface Repo {
44
45
  listCommits(options?: ListCommitsOptions): Promise<ListCommitsResult>;
45
46
  getBranchDiff(options: GetBranchDiffOptions): Promise<GetBranchDiffResult>;
46
47
  getCommitDiff(options: GetCommitDiffOptions): Promise<GetCommitDiffResult>;
47
- pullUpstream(options: PullUpstreamOptions): Promise<void>;
48
+ pullUpstream(options?: PullUpstreamOptions): Promise<void>;
48
49
  restoreCommit(options: RestoreCommitOptions): Promise<RestoreCommitResult>;
50
+ createBranch(options: CreateBranchOptions): Promise<CreateBranchResult>;
49
51
  createCommit(options: CreateCommitOptions): CommitBuilder;
50
52
  createCommitFromDiff(options: CreateCommitFromDiffOptions): Promise<CommitResult>;
51
53
  }
@@ -132,6 +134,23 @@ export interface ListBranchesResult {
132
134
  hasMore: boolean;
133
135
  }
134
136
 
137
+ // Create Branch API types
138
+ export interface CreateBranchOptions extends GitStorageInvocationOptions {
139
+ baseBranch: string;
140
+ targetBranch: string;
141
+ baseIsEphemeral?: boolean;
142
+ targetIsEphemeral?: boolean;
143
+ }
144
+
145
+ export type CreateBranchResponse = CreateBranchResponseRaw;
146
+
147
+ export interface CreateBranchResult {
148
+ message: string;
149
+ targetBranch: string;
150
+ targetIsEphemeral: boolean;
151
+ commitSha?: string;
152
+ }
153
+
135
154
  // List Commits API types
136
155
  export interface ListCommitsOptions extends GitStorageInvocationOptions {
137
156
  branch?: string;