@strayl/coregit 0.1.1 → 0.2.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.
Files changed (79) hide show
  1. package/dist/branches.d.ts +6 -6
  2. package/dist/branches.d.ts.map +1 -1
  3. package/dist/branches.js +11 -10
  4. package/dist/branches.js.map +1 -1
  5. package/dist/cherry-pick.d.ts +2 -2
  6. package/dist/cherry-pick.d.ts.map +1 -1
  7. package/dist/cherry-pick.js +3 -2
  8. package/dist/cherry-pick.js.map +1 -1
  9. package/dist/commits.d.ts +4 -4
  10. package/dist/commits.d.ts.map +1 -1
  11. package/dist/commits.js +7 -6
  12. package/dist/commits.js.map +1 -1
  13. package/dist/compare.d.ts +2 -2
  14. package/dist/compare.d.ts.map +1 -1
  15. package/dist/compare.js +3 -2
  16. package/dist/compare.js.map +1 -1
  17. package/dist/diff.d.ts +2 -2
  18. package/dist/diff.d.ts.map +1 -1
  19. package/dist/diff.js +3 -2
  20. package/dist/diff.js.map +1 -1
  21. package/dist/files.d.ts +4 -4
  22. package/dist/files.d.ts.map +1 -1
  23. package/dist/files.js +7 -6
  24. package/dist/files.js.map +1 -1
  25. package/dist/index.d.ts +13 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +13 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/refs.d.ts +5 -5
  30. package/dist/refs.d.ts.map +1 -1
  31. package/dist/refs.js +9 -8
  32. package/dist/refs.js.map +1 -1
  33. package/dist/repo-ref.d.ts +3 -0
  34. package/dist/repo-ref.d.ts.map +1 -0
  35. package/dist/repo-ref.js +7 -0
  36. package/dist/repo-ref.js.map +1 -0
  37. package/dist/repos.d.ts +5 -5
  38. package/dist/repos.d.ts.map +1 -1
  39. package/dist/repos.js +9 -6
  40. package/dist/repos.js.map +1 -1
  41. package/dist/snapshots.d.ts +6 -6
  42. package/dist/snapshots.d.ts.map +1 -1
  43. package/dist/snapshots.js +11 -10
  44. package/dist/snapshots.js.map +1 -1
  45. package/dist/sync.d.ts +8 -0
  46. package/dist/sync.d.ts.map +1 -0
  47. package/dist/sync.js +10 -0
  48. package/dist/sync.js.map +1 -0
  49. package/dist/tokens.d.ts +13 -0
  50. package/dist/tokens.d.ts.map +1 -0
  51. package/dist/tokens.js +15 -0
  52. package/dist/tokens.js.map +1 -0
  53. package/dist/types.d.ts +81 -1
  54. package/dist/types.d.ts.map +1 -1
  55. package/dist/webhooks.d.ts +16 -0
  56. package/dist/webhooks.d.ts.map +1 -0
  57. package/dist/webhooks.js +21 -0
  58. package/dist/webhooks.js.map +1 -0
  59. package/dist/workspace.d.ts +8 -0
  60. package/dist/workspace.d.ts.map +1 -0
  61. package/dist/workspace.js +10 -0
  62. package/dist/workspace.js.map +1 -0
  63. package/package.json +1 -1
  64. package/src/branches.ts +12 -10
  65. package/src/cherry-pick.ts +4 -3
  66. package/src/commits.ts +8 -6
  67. package/src/compare.ts +4 -3
  68. package/src/diff.ts +4 -3
  69. package/src/files.ts +8 -6
  70. package/src/index.ts +18 -1
  71. package/src/refs.ts +10 -8
  72. package/src/repo-ref.ts +8 -0
  73. package/src/repos.ts +11 -8
  74. package/src/snapshots.ts +12 -10
  75. package/src/sync.ts +11 -0
  76. package/src/tokens.ts +18 -0
  77. package/src/types.ts +99 -1
  78. package/src/webhooks.ts +32 -0
  79. package/src/workspace.ts +11 -0
package/src/repos.ts CHANGED
@@ -2,11 +2,13 @@ import type { HttpClient } from "./http";
2
2
  import type {
3
3
  CoregitResult,
4
4
  CreateRepoInput,
5
- PaginationOptions,
6
5
  Repo,
6
+ RepoListOptions,
7
7
  RepoListResponse,
8
+ RepoRef,
8
9
  UpdateRepoInput,
9
10
  } from "./types";
11
+ import { buildRepoPath } from "./repo-ref";
10
12
 
11
13
  export class ReposClient {
12
14
  constructor(private http: HttpClient) {}
@@ -15,23 +17,24 @@ export class ReposClient {
15
17
  return this.http.request<Repo>("POST", "/v1/repos", input);
16
18
  }
17
19
 
18
- list(opts?: PaginationOptions): Promise<CoregitResult<RepoListResponse>> {
20
+ list(opts?: RepoListOptions): Promise<CoregitResult<RepoListResponse>> {
19
21
  const params = new URLSearchParams();
20
22
  if (opts?.limit !== undefined) params.set("limit", String(opts.limit));
21
23
  if (opts?.offset !== undefined) params.set("offset", String(opts.offset));
24
+ if (opts?.namespace) params.set("namespace", opts.namespace);
22
25
  const qs = params.toString();
23
26
  return this.http.request<RepoListResponse>("GET", `/v1/repos${qs ? `?${qs}` : ""}`);
24
27
  }
25
28
 
26
- get(slug: string): Promise<CoregitResult<Repo>> {
27
- return this.http.request<Repo>("GET", `/v1/repos/${encodeURIComponent(slug)}`);
29
+ get(repo: RepoRef): Promise<CoregitResult<Repo>> {
30
+ return this.http.request<Repo>("GET", buildRepoPath(repo));
28
31
  }
29
32
 
30
- update(slug: string, input: UpdateRepoInput): Promise<CoregitResult<Repo>> {
31
- return this.http.request<Repo>("PATCH", `/v1/repos/${encodeURIComponent(slug)}`, input);
33
+ update(repo: RepoRef, input: UpdateRepoInput): Promise<CoregitResult<Repo>> {
34
+ return this.http.request<Repo>("PATCH", buildRepoPath(repo), input);
32
35
  }
33
36
 
34
- delete(slug: string): Promise<CoregitResult<{ deleted: boolean }>> {
35
- return this.http.request<{ deleted: boolean }>("DELETE", `/v1/repos/${encodeURIComponent(slug)}`);
37
+ delete(repo: RepoRef): Promise<CoregitResult<{ deleted: boolean }>> {
38
+ return this.http.request<{ deleted: boolean }>("DELETE", buildRepoPath(repo));
36
39
  }
37
40
  }
package/src/snapshots.ts CHANGED
@@ -2,35 +2,37 @@ import type { HttpClient } from "./http";
2
2
  import type {
3
3
  CoregitResult,
4
4
  CreateSnapshotInput,
5
+ RepoRef,
5
6
  RestoreInput,
6
7
  RestoreResult,
7
8
  Snapshot,
8
9
  SnapshotListResponse,
9
10
  } from "./types";
11
+ import { buildRepoPath } from "./repo-ref";
10
12
 
11
13
  export class SnapshotsClient {
12
14
  constructor(private http: HttpClient) {}
13
15
 
14
- create(repoSlug: string, input: CreateSnapshotInput): Promise<CoregitResult<Snapshot>> {
15
- return this.http.request<Snapshot>("POST", `/v1/repos/${encodeURIComponent(repoSlug)}/snapshots`, input);
16
+ create(repo: RepoRef, input: CreateSnapshotInput): Promise<CoregitResult<Snapshot>> {
17
+ return this.http.request<Snapshot>("POST", `${buildRepoPath(repo)}/snapshots`, input);
16
18
  }
17
19
 
18
- list(repoSlug: string): Promise<CoregitResult<SnapshotListResponse>> {
19
- return this.http.request<SnapshotListResponse>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/snapshots`);
20
+ list(repo: RepoRef): Promise<CoregitResult<SnapshotListResponse>> {
21
+ return this.http.request<SnapshotListResponse>("GET", `${buildRepoPath(repo)}/snapshots`);
20
22
  }
21
23
 
22
- get(repoSlug: string, name: string): Promise<CoregitResult<Snapshot>> {
23
- return this.http.request<Snapshot>("GET", `/v1/repos/${encodeURIComponent(repoSlug)}/snapshots/${encodeURIComponent(name)}`);
24
+ get(repo: RepoRef, name: string): Promise<CoregitResult<Snapshot>> {
25
+ return this.http.request<Snapshot>("GET", `${buildRepoPath(repo)}/snapshots/${encodeURIComponent(name)}`);
24
26
  }
25
27
 
26
- delete(repoSlug: string, name: string): Promise<CoregitResult<{ deleted: boolean }>> {
27
- return this.http.request("DELETE", `/v1/repos/${encodeURIComponent(repoSlug)}/snapshots/${encodeURIComponent(name)}`);
28
+ delete(repo: RepoRef, name: string): Promise<CoregitResult<{ deleted: boolean }>> {
29
+ return this.http.request("DELETE", `${buildRepoPath(repo)}/snapshots/${encodeURIComponent(name)}`);
28
30
  }
29
31
 
30
- restore(repoSlug: string, name: string, opts?: RestoreInput): Promise<CoregitResult<RestoreResult>> {
32
+ restore(repo: RepoRef, name: string, opts?: RestoreInput): Promise<CoregitResult<RestoreResult>> {
31
33
  return this.http.request<RestoreResult>(
32
34
  "POST",
33
- `/v1/repos/${encodeURIComponent(repoSlug)}/snapshots/${encodeURIComponent(name)}/restore`,
35
+ `${buildRepoPath(repo)}/snapshots/${encodeURIComponent(name)}/restore`,
34
36
  opts,
35
37
  );
36
38
  }
package/src/sync.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { HttpClient } from "./http";
2
+ import type { CoregitResult, SyncInput, SyncResult, RepoRef } from "./types";
3
+ import { buildRepoPath } from "./repo-ref";
4
+
5
+ export class SyncClient {
6
+ constructor(private http: HttpClient) {}
7
+
8
+ trigger(repo: RepoRef, input: SyncInput): Promise<CoregitResult<SyncResult>> {
9
+ return this.http.request<SyncResult>("POST", `${buildRepoPath(repo)}/sync`, input);
10
+ }
11
+ }
package/src/tokens.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { HttpClient } from "./http";
2
+ import type { CoregitResult, CreateTokenInput, Token, TokenListResponse } from "./types";
3
+
4
+ export class TokensClient {
5
+ constructor(private http: HttpClient) {}
6
+
7
+ create(input: CreateTokenInput): Promise<CoregitResult<Token>> {
8
+ return this.http.request<Token>("POST", "/v1/tokens", input);
9
+ }
10
+
11
+ list(): Promise<CoregitResult<TokenListResponse>> {
12
+ return this.http.request<TokenListResponse>("GET", "/v1/tokens");
13
+ }
14
+
15
+ revoke(id: string): Promise<CoregitResult<{ id: string; revoked: boolean }>> {
16
+ return this.http.request("DELETE", `/v1/tokens/${encodeURIComponent(id)}`);
17
+ }
18
+ }
package/src/types.ts CHANGED
@@ -18,10 +18,15 @@ export interface CoregitError {
18
18
  status?: number;
19
19
  }
20
20
 
21
+ // --- Repo Ref ---
22
+
23
+ export type RepoRef = string | { namespace: string; slug: string };
24
+
21
25
  // --- Repos ---
22
26
 
23
27
  export interface CreateRepoInput {
24
28
  slug: string;
29
+ namespace?: string;
25
30
  description?: string;
26
31
  default_branch?: string;
27
32
  visibility?: "public" | "private";
@@ -36,6 +41,7 @@ export interface UpdateRepoInput {
36
41
 
37
42
  export interface Repo {
38
43
  id: string;
44
+ namespace: string | null;
39
45
  slug: string;
40
46
  description: string | null;
41
47
  default_branch: string;
@@ -161,7 +167,7 @@ export interface FileChange {
161
167
  path: string;
162
168
  content?: string;
163
169
  encoding?: "utf-8" | "base64";
164
- action?: "delete";
170
+ action?: "create" | "modify" | "delete";
165
171
  }
166
172
 
167
173
  export interface CreateCommitInput {
@@ -310,3 +316,95 @@ export interface PaginationOptions {
310
316
  limit?: number;
311
317
  offset?: number;
312
318
  }
319
+
320
+ export interface RepoListOptions extends PaginationOptions {
321
+ namespace?: string;
322
+ }
323
+
324
+ // --- Workspace ---
325
+
326
+ export interface ExecInput {
327
+ command: string;
328
+ branch?: string;
329
+ ref?: string;
330
+ cwd?: string;
331
+ env?: Record<string, string>;
332
+ commit?: boolean;
333
+ commit_message?: string;
334
+ author?: { name: string; email: string };
335
+ }
336
+
337
+ export interface ExecResult {
338
+ stdout: string;
339
+ stderr: string;
340
+ exit_code: number;
341
+ changed_files: string[];
342
+ commit_sha: string | null;
343
+ execution_time_ms: number;
344
+ }
345
+
346
+ // --- Sync ---
347
+
348
+ export interface SyncInput {
349
+ sync_id: string;
350
+ branch?: string;
351
+ }
352
+
353
+ export interface SyncResult {
354
+ synced: boolean;
355
+ remote_sha: string;
356
+ commit_sha: string | null;
357
+ files_changed: number;
358
+ deleted: number;
359
+ }
360
+
361
+ // --- Tokens ---
362
+
363
+ export interface CreateTokenInput {
364
+ name: string;
365
+ scopes: Record<string, string[]>;
366
+ expires_in: number;
367
+ }
368
+
369
+ export interface Token {
370
+ id: string;
371
+ token?: string;
372
+ name: string;
373
+ key_prefix: string;
374
+ scopes: Record<string, string[]>;
375
+ expires_at: string;
376
+ last_used?: string | null;
377
+ created_at: string;
378
+ }
379
+
380
+ export interface TokenListResponse {
381
+ tokens: Token[];
382
+ }
383
+
384
+ // --- Webhooks ---
385
+
386
+ export type WebhookEvent = "push" | "repo.created" | "repo.deleted" | "branch.created" | "branch.deleted" | "*";
387
+
388
+ export interface CreateWebhookInput {
389
+ url: string;
390
+ events: WebhookEvent[];
391
+ }
392
+
393
+ export interface UpdateWebhookInput {
394
+ url?: string;
395
+ events?: WebhookEvent[];
396
+ active?: boolean;
397
+ }
398
+
399
+ export interface Webhook {
400
+ id: string;
401
+ url: string;
402
+ events: WebhookEvent[];
403
+ secret?: string;
404
+ active: boolean;
405
+ created_at?: string;
406
+ }
407
+
408
+ export interface WebhookListResponse {
409
+ webhooks: Webhook[];
410
+ }
@@ -0,0 +1,32 @@
1
+ import type { HttpClient } from "./http";
2
+ import type {
3
+ CoregitResult,
4
+ CreateWebhookInput,
5
+ UpdateWebhookInput,
6
+ Webhook,
7
+ WebhookListResponse,
8
+ } from "./types";
9
+
10
+ export class WebhooksClient {
11
+ constructor(private http: HttpClient) {}
12
+
13
+ create(input: CreateWebhookInput): Promise<CoregitResult<Webhook>> {
14
+ return this.http.request<Webhook>("POST", "/v1/webhooks", input);
15
+ }
16
+
17
+ list(): Promise<CoregitResult<WebhookListResponse>> {
18
+ return this.http.request<WebhookListResponse>("GET", "/v1/webhooks");
19
+ }
20
+
21
+ get(id: string): Promise<CoregitResult<Webhook>> {
22
+ return this.http.request<Webhook>("GET", `/v1/webhooks/${encodeURIComponent(id)}`);
23
+ }
24
+
25
+ update(id: string, input: UpdateWebhookInput): Promise<CoregitResult<{ updated: boolean }>> {
26
+ return this.http.request("PATCH", `/v1/webhooks/${encodeURIComponent(id)}`, input);
27
+ }
28
+
29
+ delete(id: string): Promise<CoregitResult<{ deleted: boolean }>> {
30
+ return this.http.request("DELETE", `/v1/webhooks/${encodeURIComponent(id)}`);
31
+ }
32
+ }
@@ -0,0 +1,11 @@
1
+ import type { HttpClient } from "./http";
2
+ import type { CoregitResult, ExecInput, ExecResult, RepoRef } from "./types";
3
+ import { buildRepoPath } from "./repo-ref";
4
+
5
+ export class WorkspaceClient {
6
+ constructor(private http: HttpClient) {}
7
+
8
+ exec(repo: RepoRef, input: ExecInput): Promise<CoregitResult<ExecResult>> {
9
+ return this.http.request<ExecResult>("POST", `${buildRepoPath(repo)}/exec`, input);
10
+ }
11
+ }