TypeScript API / @laikacms/gitlab / GitlabDataSource
Class: GitlabDataSource
Talks the GitLab REST v4 API over fetch. Stateless — no token caching is needed since PAT/OAuth tokens are long-lived (unlike GitHub App installation tokens). All errors are mapped onto Laika error types.
Project paths are accepted in either form (12345 or group/project); the implementation URL-encodes whatever you pass.
Constructors
Constructor
new GitlabDataSource(opts): GitlabDataSource;Parameters
| Parameter | Type |
|---|---|
opts | GitlabDataSourceOptions |
Returns
GitlabDataSource
Methods
createOrUpdate()
createOrUpdate(
relativePath,
content,
options?
): Promise<LaikaResult<{
path: string;
}>>;Create or update a file. Uses POST for new files and falls back to PUT when the server reports the file already exists. expectedLastCommitId enables optimistic concurrency on updates.
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
content | string |
options | { author?: { email: string; name: string; }; commitMessage?: string; expectedLastCommitId?: string; } |
options.author? | { email: string; name: string; } |
options.author.email | string |
options.author.name | string |
options.commitMessage? | string |
options.expectedLastCommitId? | string |
Returns
Promise<LaikaResult<{ path: string; }>>
deleteFile()
deleteFile(relativePath, options?): Promise<LaikaResult<{
path: string;
}>>;Delete a file.
Parameters
| Parameter | Type |
|---|---|
relativePath | 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(relativePath): Promise<LaikaResult<{
content: string;
lastCommitId: string;
path: string;
sha: string;
}>>;Fetch a file's content + blob id.
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
Returns
Promise<LaikaResult<{ content: string; lastCommitId: string; path: string; sha: string; }>>
getFileMeta()
getFileMeta(relativePath): Promise<LaikaResult<{
createdAt: Date;
lastCommitId: string;
sha: string;
updatedAt: Date;
}>>;Metadata for a file: blob id + first/last commit dates.
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
Returns
Promise<LaikaResult<{ createdAt: Date; lastCommitId: string; sha: string; updatedAt: Date; }>>
listDirectory()
listDirectory(relativePath): Promise<LaikaResult<GitlabDirEntry[]>>;List the immediate children of a directory. Returns [] for an empty directory; returns a NotFoundError only when the parent cannot be resolved at all. Pages through X-Next-Page until exhausted.
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
Returns
Promise<LaikaResult<GitlabDirEntry[]>>
pathType()
pathType(relativePath): Promise<"dir" | "file">;Distinguish file vs dir vs missing. Looks up the parent listing and inspects the entry — one request rather than two, and works for empty directories (which still appear in their parent's tree).
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
Returns
Promise<"dir" | "file">