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}/srcwith multipart form data. File uploads are form fields whose names are the paths and values are the content; file deletions are repeatedfiles=<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
new BitbucketDataSource(options): BitbucketDataSource;Parameters
| Parameter | Type |
|---|---|
options | BitbucketDataSourceOptions |
Returns
BitbucketDataSource
Methods
commit()
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
| Parameter | Type |
|---|---|
options | { author?: { email: string; name: string; }; commitMessage: string; deletes?: readonly string[]; puts?: readonly object[]; } |
options.author? | { email: string; name: string; } |
options.author.email | string |
options.author.name | string |
options.commitMessage | string |
options.deletes? | readonly string[] |
options.puts? | readonly object[] |
Returns
Promise<LaikaResult<void>>
createOrUpdate()
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
| Parameter | Type |
|---|---|
path | string |
content | string |
options | { author?: { email: string; name: string; }; commitMessage?: string; } |
options.author? | { email: string; name: string; } |
options.author.email | string |
options.author.name | string |
options.commitMessage? | string |
Returns
Promise<LaikaResult<{ path: string; }>>
deleteFile()
deleteFile(path, options?): Promise<LaikaResult<{
path: string;
}>>;Convenience wrapper around commit for the common case of one delete.
Parameters
| Parameter | Type |
|---|---|
path | string |
options | { author?: { email: string; name: string; }; commitMessage?: string; } |
options.author? | { email: string; name: string; } |
options.author.email | string |
options.author.name | string |
options.commitMessage? | string |
Returns
Promise<LaikaResult<{ path: string; }>>
getFileContents()
getFileContents(path): Promise<LaikaResult<string>>;Fetch a file's raw content.
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
Promise<LaikaResult<string>>
getFileMeta()
getFileMeta(path): Promise<LaikaResult<
| {
commit?: string;
createdAt?: Date;
size: number;
updatedAt?: Date;
}
| null>>;Metadata for a file (size + last commit). null on 404.
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
Promise<LaikaResult< | { commit?: string; createdAt?: Date; size: number; updatedAt?: Date; } | null>>
listDirectory()
listDirectory(path): Promise<LaikaResult<BitbucketDirEntry[]>>;List a directory's direct children. Pages through next until exhausted.
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
Promise<LaikaResult<BitbucketDirEntry[]>>