Skip to content

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 ​

ts
new GitlabDataSource(opts): GitlabDataSource;

Parameters ​

ParameterType
optsGitlabDataSourceOptions

Returns ​

GitlabDataSource

Methods ​

createOrUpdate() ​

ts
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 ​

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

Returns ​

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


deleteFile() ​

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

Delete a file.

Parameters ​

ParameterType
relativePathstring
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(relativePath): Promise<LaikaResult<{
  content: string;
  lastCommitId: string;
  path: string;
  sha: string;
}>>;

Fetch a file's content + blob id.

Parameters ​

ParameterType
relativePathstring

Returns ​

Promise<LaikaResult<{ content: string; lastCommitId: string; path: string; sha: string; }>>


getFileMeta() ​

ts
getFileMeta(relativePath): Promise<LaikaResult<{
  createdAt: Date;
  lastCommitId: string;
  sha: string;
  updatedAt: Date;
}>>;

Metadata for a file: blob id + first/last commit dates.

Parameters ​

ParameterType
relativePathstring

Returns ​

Promise<LaikaResult<{ createdAt: Date; lastCommitId: string; sha: string; updatedAt: Date; }>>


listDirectory() ​

ts
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 ​

ParameterType
relativePathstring

Returns ​

Promise<LaikaResult<GitlabDirEntry[]>>


pathType() ​

ts
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 ​

ParameterType
relativePathstring

Returns ​

Promise<"dir" | "file">

Released under the MIT License.