@pierre/storage 0.3.0 → 0.4.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/dist/index.d.cts CHANGED
@@ -455,6 +455,7 @@ interface Repo {
455
455
  listCommits(options?: ListCommitsOptions): Promise<ListCommitsResult>;
456
456
  getBranchDiff(options: GetBranchDiffOptions): Promise<GetBranchDiffResult>;
457
457
  getCommitDiff(options: GetCommitDiffOptions): Promise<GetCommitDiffResult>;
458
+ grep(options: GrepOptions): Promise<GrepResult>;
458
459
  pullUpstream(options?: PullUpstreamOptions): Promise<void>;
459
460
  restoreCommit(options: RestoreCommitOptions): Promise<RestoreCommitResult>;
460
461
  createBranch(options: CreateBranchOptions): Promise<CreateBranchResult>;
@@ -490,6 +491,13 @@ interface CreateRepoOptions extends GitStorageInvocationOptions {
490
491
  baseRepo?: BaseRepo;
491
492
  defaultBranch?: string;
492
493
  }
494
+ interface DeleteRepoOptions extends GitStorageInvocationOptions {
495
+ id: string;
496
+ }
497
+ interface DeleteRepoResult {
498
+ repoId: string;
499
+ message: string;
500
+ }
493
501
  interface GetFileOptions extends GitStorageInvocationOptions {
494
502
  path: string;
495
503
  ref?: string;
@@ -585,6 +593,57 @@ interface GetCommitDiffResult {
585
593
  files: FileDiff[];
586
594
  filteredFiles: FilteredFile[];
587
595
  }
596
+ interface GrepOptions extends GitStorageInvocationOptions {
597
+ ref?: string;
598
+ paths?: string[];
599
+ query: {
600
+ pattern: string;
601
+ /**
602
+ * Default is case-sensitive.
603
+ * When omitted, the server default is used.
604
+ */
605
+ caseSensitive?: boolean;
606
+ };
607
+ fileFilters?: {
608
+ includeGlobs?: string[];
609
+ excludeGlobs?: string[];
610
+ extensionFilters?: string[];
611
+ };
612
+ context?: {
613
+ before?: number;
614
+ after?: number;
615
+ };
616
+ limits?: {
617
+ maxLines?: number;
618
+ maxMatchesPerFile?: number;
619
+ };
620
+ pagination?: {
621
+ cursor?: string;
622
+ limit?: number;
623
+ };
624
+ }
625
+ interface GrepLine {
626
+ lineNumber: number;
627
+ text: string;
628
+ type: string;
629
+ }
630
+ interface GrepFileMatch {
631
+ path: string;
632
+ lines: GrepLine[];
633
+ }
634
+ interface GrepResult {
635
+ query: {
636
+ pattern: string;
637
+ caseSensitive: boolean;
638
+ };
639
+ repo: {
640
+ ref: string;
641
+ commit: string;
642
+ };
643
+ matches: GrepFileMatch[];
644
+ nextCursor?: string;
645
+ hasMore: boolean;
646
+ }
588
647
  interface DiffStats {
589
648
  files: number;
590
649
  additions: number;
@@ -882,6 +941,12 @@ declare class GitStorage {
882
941
  * @returns The found repository
883
942
  */
884
943
  findOne(options: FindOneOptions): Promise<Repo | null>;
944
+ /**
945
+ * Delete a repository by ID
946
+ * @param options The delete options containing the repo ID
947
+ * @returns The deletion result
948
+ */
949
+ deleteRepo(options: DeleteRepoOptions): Promise<DeleteRepoResult>;
885
950
  /**
886
951
  * Get the current configuration
887
952
  * @returns The client configuration
@@ -897,4 +962,4 @@ declare function createClient(options: GitStorageOptions): GitStorage;
897
962
 
898
963
  type StorageOptions = GitStorageOptions;
899
964
 
900
- export { ApiError, type BaseRepo, type BlobLike, type BranchInfo, GitStorage as CodeStorage, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateRepoOptions, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetRemoteURLOptions, type GitFileMode, GitStorage, type GitStorageOptions, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
965
+ export { ApiError, type BaseRepo, type BlobLike, type BranchInfo, GitStorage as CodeStorage, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateRepoOptions, type DeleteRepoOptions, type DeleteRepoResult, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetRemoteURLOptions, type GitFileMode, GitStorage, type GitStorageOptions, type GrepFileMatch, type GrepLine, type GrepOptions, type GrepResult, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -455,6 +455,7 @@ interface Repo {
455
455
  listCommits(options?: ListCommitsOptions): Promise<ListCommitsResult>;
456
456
  getBranchDiff(options: GetBranchDiffOptions): Promise<GetBranchDiffResult>;
457
457
  getCommitDiff(options: GetCommitDiffOptions): Promise<GetCommitDiffResult>;
458
+ grep(options: GrepOptions): Promise<GrepResult>;
458
459
  pullUpstream(options?: PullUpstreamOptions): Promise<void>;
459
460
  restoreCommit(options: RestoreCommitOptions): Promise<RestoreCommitResult>;
460
461
  createBranch(options: CreateBranchOptions): Promise<CreateBranchResult>;
@@ -490,6 +491,13 @@ interface CreateRepoOptions extends GitStorageInvocationOptions {
490
491
  baseRepo?: BaseRepo;
491
492
  defaultBranch?: string;
492
493
  }
494
+ interface DeleteRepoOptions extends GitStorageInvocationOptions {
495
+ id: string;
496
+ }
497
+ interface DeleteRepoResult {
498
+ repoId: string;
499
+ message: string;
500
+ }
493
501
  interface GetFileOptions extends GitStorageInvocationOptions {
494
502
  path: string;
495
503
  ref?: string;
@@ -585,6 +593,57 @@ interface GetCommitDiffResult {
585
593
  files: FileDiff[];
586
594
  filteredFiles: FilteredFile[];
587
595
  }
596
+ interface GrepOptions extends GitStorageInvocationOptions {
597
+ ref?: string;
598
+ paths?: string[];
599
+ query: {
600
+ pattern: string;
601
+ /**
602
+ * Default is case-sensitive.
603
+ * When omitted, the server default is used.
604
+ */
605
+ caseSensitive?: boolean;
606
+ };
607
+ fileFilters?: {
608
+ includeGlobs?: string[];
609
+ excludeGlobs?: string[];
610
+ extensionFilters?: string[];
611
+ };
612
+ context?: {
613
+ before?: number;
614
+ after?: number;
615
+ };
616
+ limits?: {
617
+ maxLines?: number;
618
+ maxMatchesPerFile?: number;
619
+ };
620
+ pagination?: {
621
+ cursor?: string;
622
+ limit?: number;
623
+ };
624
+ }
625
+ interface GrepLine {
626
+ lineNumber: number;
627
+ text: string;
628
+ type: string;
629
+ }
630
+ interface GrepFileMatch {
631
+ path: string;
632
+ lines: GrepLine[];
633
+ }
634
+ interface GrepResult {
635
+ query: {
636
+ pattern: string;
637
+ caseSensitive: boolean;
638
+ };
639
+ repo: {
640
+ ref: string;
641
+ commit: string;
642
+ };
643
+ matches: GrepFileMatch[];
644
+ nextCursor?: string;
645
+ hasMore: boolean;
646
+ }
588
647
  interface DiffStats {
589
648
  files: number;
590
649
  additions: number;
@@ -882,6 +941,12 @@ declare class GitStorage {
882
941
  * @returns The found repository
883
942
  */
884
943
  findOne(options: FindOneOptions): Promise<Repo | null>;
944
+ /**
945
+ * Delete a repository by ID
946
+ * @param options The delete options containing the repo ID
947
+ * @returns The deletion result
948
+ */
949
+ deleteRepo(options: DeleteRepoOptions): Promise<DeleteRepoResult>;
885
950
  /**
886
951
  * Get the current configuration
887
952
  * @returns The client configuration
@@ -897,4 +962,4 @@ declare function createClient(options: GitStorageOptions): GitStorage;
897
962
 
898
963
  type StorageOptions = GitStorageOptions;
899
964
 
900
- export { ApiError, type BaseRepo, type BlobLike, type BranchInfo, GitStorage as CodeStorage, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateRepoOptions, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetRemoteURLOptions, type GitFileMode, GitStorage, type GitStorageOptions, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
965
+ export { ApiError, type BaseRepo, type BlobLike, type BranchInfo, GitStorage as CodeStorage, type CommitBuilder, type CommitFileOptions, type CommitFileSource, type CommitInfo, type CommitResult, type CommitSignature, type CommitTextFileOptions, type CreateBranchOptions, type CreateBranchResponse, type CreateBranchResult, type CreateCommitBranchOptions, type CreateCommitFromDiffOptions, type CreateCommitOptions, type CreateRepoOptions, type DeleteRepoOptions, type DeleteRepoResult, type DiffFileBase, type DiffFileState, type DiffSource, type DiffStats, type FileDiff, type FileLike, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetBranchDiffResult, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitDiffResult, type GetFileOptions, type GetRemoteURLOptions, type GitFileMode, GitStorage, type GitStorageOptions, type GrepFileMatch, type GrepLine, type GrepOptions, type GrepResult, type LegacyCreateCommitOptions, type ListBranchesOptions, type ListBranchesResponse, type ListBranchesResult, type ListCommitsOptions, type ListCommitsResponse, type ListCommitsResult, type ListFilesOptions, type ListFilesResponse, type ListFilesResult, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type PullUpstreamOptions, type RawBranchInfo, type RawCommitInfo, type RawFileDiff, type RawFilteredFile, type RawWebhookPushEvent, type ReadableStreamLike, type ReadableStreamReaderLike, type RefUpdate, RefUpdateError, type RefUpdateReason, type Repo, type RestoreCommitOptions, type RestoreCommitResult, type StorageOptions, type SupportedRepoProvider, type TextEncoding, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookUnknownEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };
package/dist/index.js CHANGED
@@ -150,6 +150,28 @@ var restoreCommitResponseSchema = z.object({
150
150
  commit: restoreCommitCommitSchema.partial().optional().nullable(),
151
151
  result: refUpdateResultWithOptionalsSchema
152
152
  });
153
+ var grepLineSchema = z.object({
154
+ line_number: z.number(),
155
+ text: z.string(),
156
+ type: z.string()
157
+ });
158
+ var grepFileMatchSchema = z.object({
159
+ path: z.string(),
160
+ lines: z.array(grepLineSchema)
161
+ });
162
+ var grepResponseSchema = z.object({
163
+ query: z.object({
164
+ pattern: z.string(),
165
+ case_sensitive: z.boolean()
166
+ }),
167
+ repo: z.object({
168
+ ref: z.string(),
169
+ commit: z.string()
170
+ }),
171
+ matches: z.array(grepFileMatchSchema),
172
+ next_cursor: z.string().nullable().optional(),
173
+ has_more: z.boolean()
174
+ });
153
175
  var errorEnvelopeSchema = z.object({
154
176
  error: z.string()
155
177
  });
@@ -444,7 +466,7 @@ function concatChunks(a, b) {
444
466
 
445
467
  // package.json
446
468
  var package_default = {
447
- version: "0.3.0"};
469
+ version: "0.4.1"};
448
470
 
449
471
  // src/version.ts
450
472
  var PACKAGE_NAME = "code-storage-sdk";
@@ -1513,6 +1535,19 @@ function transformCreateBranchResult(raw) {
1513
1535
  commitSha: raw.commit_sha ?? void 0
1514
1536
  };
1515
1537
  }
1538
+ function transformGrepLine(raw) {
1539
+ return {
1540
+ lineNumber: raw.line_number,
1541
+ text: raw.text,
1542
+ type: raw.type
1543
+ };
1544
+ }
1545
+ function transformGrepFileMatch(raw) {
1546
+ return {
1547
+ path: raw.path,
1548
+ lines: raw.lines.map(transformGrepLine)
1549
+ };
1550
+ }
1516
1551
  var RepoImpl = class {
1517
1552
  constructor(id, options, generateJWT) {
1518
1553
  this.id = id;
@@ -1665,6 +1700,69 @@ var RepoImpl = class {
1665
1700
  const raw = commitDiffResponseSchema.parse(await response.json());
1666
1701
  return transformCommitDiffResult(raw);
1667
1702
  }
1703
+ async grep(options) {
1704
+ const pattern = options?.query?.pattern?.trim();
1705
+ if (!pattern) {
1706
+ throw new Error("grep query.pattern is required");
1707
+ }
1708
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1709
+ const jwt = await this.generateJWT(this.id, {
1710
+ permissions: ["git:read"],
1711
+ ttl
1712
+ });
1713
+ const body = {
1714
+ query: {
1715
+ pattern,
1716
+ ...typeof options.query.caseSensitive === "boolean" ? { case_sensitive: options.query.caseSensitive } : {}
1717
+ }
1718
+ };
1719
+ if (options.ref) {
1720
+ body.rev = options.ref;
1721
+ }
1722
+ if (Array.isArray(options.paths) && options.paths.length > 0) {
1723
+ body.paths = options.paths;
1724
+ }
1725
+ if (options.fileFilters) {
1726
+ body.file_filters = {
1727
+ ...options.fileFilters.includeGlobs ? { include_globs: options.fileFilters.includeGlobs } : {},
1728
+ ...options.fileFilters.excludeGlobs ? { exclude_globs: options.fileFilters.excludeGlobs } : {},
1729
+ ...options.fileFilters.extensionFilters ? { extension_filters: options.fileFilters.extensionFilters } : {}
1730
+ };
1731
+ }
1732
+ if (options.context) {
1733
+ body.context = {
1734
+ ...typeof options.context.before === "number" ? { before: options.context.before } : {},
1735
+ ...typeof options.context.after === "number" ? { after: options.context.after } : {}
1736
+ };
1737
+ }
1738
+ if (options.limits) {
1739
+ body.limits = {
1740
+ ...typeof options.limits.maxLines === "number" ? { max_lines: options.limits.maxLines } : {},
1741
+ ...typeof options.limits.maxMatchesPerFile === "number" ? { max_matches_per_file: options.limits.maxMatchesPerFile } : {}
1742
+ };
1743
+ }
1744
+ if (options.pagination) {
1745
+ body.pagination = {
1746
+ ...typeof options.pagination.cursor === "string" && options.pagination.cursor.trim() !== "" ? { cursor: options.pagination.cursor } : {},
1747
+ ...typeof options.pagination.limit === "number" ? { limit: options.pagination.limit } : {}
1748
+ };
1749
+ }
1750
+ const response = await this.api.post({ path: "repos/grep", body }, jwt);
1751
+ const raw = grepResponseSchema.parse(await response.json());
1752
+ return {
1753
+ query: {
1754
+ pattern: raw.query.pattern,
1755
+ caseSensitive: raw.query.case_sensitive
1756
+ },
1757
+ repo: {
1758
+ ref: raw.repo.ref,
1759
+ commit: raw.repo.commit
1760
+ },
1761
+ matches: raw.matches.map(transformGrepFileMatch),
1762
+ nextCursor: raw.next_cursor ?? void 0,
1763
+ hasMore: raw.has_more
1764
+ };
1765
+ }
1668
1766
  async pullUpstream(options = {}) {
1669
1767
  const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
1670
1768
  const jwt = await this.generateJWT(this.id, {
@@ -1897,6 +1995,30 @@ var GitStorage = class _GitStorage {
1897
1995
  }
1898
1996
  return new RepoImpl(options.id, this.options, this.generateJWT.bind(this));
1899
1997
  }
1998
+ /**
1999
+ * Delete a repository by ID
2000
+ * @param options The delete options containing the repo ID
2001
+ * @returns The deletion result
2002
+ */
2003
+ async deleteRepo(options) {
2004
+ const ttl = resolveInvocationTtlSeconds(options, DEFAULT_TOKEN_TTL_SECONDS);
2005
+ const jwt = await this.generateJWT(options.id, {
2006
+ permissions: ["repo:write"],
2007
+ ttl
2008
+ });
2009
+ const resp = await this.api.delete("repos/delete", jwt, { allowedStatus: [404, 409] });
2010
+ if (resp.status === 404) {
2011
+ throw new Error("Repository not found");
2012
+ }
2013
+ if (resp.status === 409) {
2014
+ throw new Error("Repository already deleted");
2015
+ }
2016
+ const body = await resp.json();
2017
+ return {
2018
+ repoId: body.repo_id,
2019
+ message: body.message
2020
+ };
2021
+ }
1900
2022
  /**
1901
2023
  * Get the current configuration
1902
2024
  * @returns The client configuration