Skip to content

TypeScript API / @laikacms/bitbucket/storage-bb / BitbucketDataSource

Class: BitbucketDataSource ​

Talks the Bitbucket Cloud REST API v2 over fetch. Bitbucket's commit model is unusual compared to GitHub/GitLab:

  • All writes — creates, updates, and deletes — go through one endpoint: POST /repositories/{ws}/{repo}/src with multipart form data. File uploads are form fields whose names are the paths and values are the content; file deletions are repeated files=<path> form fields. A single POST can contain any mix of writes and deletes, all committed atomically.
  • Listing requires a trailing slash. /src/<commit>/<path>/ returns a paginated directory listing; without the trailing slash the same URL returns the file's body (when it's a file).

The datasource normalizes both quirks behind a clean method surface.

Constructors ​

Constructor ​

ts
new BitbucketDataSource(options): BitbucketDataSource;

Parameters ​

ParameterType
optionsBitbucketDataSourceOptions

Returns ​

BitbucketDataSource

Methods ​

commit() ​

ts
commit(options): Promise<LaikaResult<void>>;

Commit one or more file additions/updates and/or deletions in a single Bitbucket commit. commitMessage is the commit subject; author is the optional Name <email> byline.

Parameters ​

ParameterType
options{ author?: { email: string; name: string; }; commitMessage: string; deletes?: readonly string[]; puts?: readonly object[]; }
options.author?{ email: string; name: string; }
options.author.emailstring
options.author.namestring
options.commitMessagestring
options.deletes?readonly string[]
options.puts?readonly object[]

Returns ​

Promise<LaikaResult<void>>


createOrUpdate() ​

ts
createOrUpdate(
   path, 
   content, 
   options?
): Promise<LaikaResult<{
  path: string;
}>>;

Convenience wrapper around commit for the common case of writing one file. Matches the GitHub / GitLab datasources' shape so the repository layer reads almost identically across the three platforms.

Parameters ​

ParameterType
pathstring
contentstring
options{ author?: { email: string; name: string; }; commitMessage?: string; }
options.author?{ email: string; name: string; }
options.author.emailstring
options.author.namestring
options.commitMessage?string

Returns ​

Promise<LaikaResult<{ path: string; }>>


deleteFile() ​

ts
deleteFile(path, options?): Promise<LaikaResult<{
  path: string;
}>>;

Convenience wrapper around commit for the common case of one delete.

Parameters ​

ParameterType
pathstring
options{ author?: { email: string; name: string; }; commitMessage?: string; }
options.author?{ email: string; name: string; }
options.author.emailstring
options.author.namestring
options.commitMessage?string

Returns ​

Promise<LaikaResult<{ path: string; }>>


getFileContents() ​

ts
getFileContents(path): Promise<LaikaResult<string>>;

Fetch a file's raw content.

Parameters ​

ParameterType
pathstring

Returns ​

Promise<LaikaResult<string>>


getFileMeta() ​

ts
getFileMeta(path): Promise<LaikaResult<
  | {
  commit?: string;
  createdAt?: Date;
  size: number;
  updatedAt?: Date;
}
| null>>;

Metadata for a file (size + last commit). null on 404.

Parameters ​

ParameterType
pathstring

Returns ​

Promise<LaikaResult< | { commit?: string; createdAt?: Date; size: number; updatedAt?: Date; } | null>>


listDirectory() ​

ts
listDirectory(path): Promise<LaikaResult<BitbucketDirEntry[]>>;

List a directory's direct children. Pages through next until exhausted.

Parameters ​

ParameterType
pathstring

Returns ​

Promise<LaikaResult<BitbucketDirEntry[]>>

Released under the MIT License.