TypeScript API / @laikacms/github / GithubDataSource
Class: GithubDataSource
I/O against a single GitHub repository. Stateless aside from a cached installation token. All errors are mapped onto laikacms error types.
Constructors
Constructor
new GithubDataSource(opts): GithubDataSource;Parameters
| Parameter | Type |
|---|---|
opts | GithubDataSourceOptions |
Returns
GithubDataSource
Methods
createOrUpdate()
createOrUpdate(
relativePath,
content,
options?
): Promise<LaikaResult<{
path: string;
sha: string;
}>>;Create or update a file. If expectedSha is supplied, the API enforces optimistic concurrency: a 409 response maps to VersionMismatchError.
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
content | string |
options | { author?: { email: string; name: string; }; commitMessage?: string; expectedSha?: string; } |
options.author? | { email: string; name: string; } |
options.author.email | string |
options.author.name | string |
options.commitMessage? | string |
options.expectedSha? | string |
Returns
Promise<LaikaResult<{ path: string; sha: string; }>>
deleteFile()
deleteFile(
relativePath,
sha,
options?
): Promise<LaikaResult<{
path: string;
}>>;Delete a file by sha. Empty-folder semantics are handled at the repository layer.
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
sha | 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;
path: string;
sha: string;
}>>;Fetch a file's content + sha. Returns NotFound when the path is a directory or missing.
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
Returns
Promise<LaikaResult<{ content: string; path: string; sha: string; }>>
getFileMeta()
getFileMeta(relativePath): Promise<LaikaResult<{
createdAt: Date;
sha: string;
updatedAt: Date;
}>>;Get just the metadata (sha, lastModified) without downloading content.
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
Returns
Promise<LaikaResult<{ createdAt: Date; sha: string; updatedAt: Date; }>>
listDirectory()
listDirectory(relativePath): Promise<LaikaResult<GithubDirEntry[]>>;List immediate children of a directory. Empty array when missing (mirrors storage-fs).
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
Returns
Promise<LaikaResult<GithubDirEntry[]>>
pathType()
pathType(relativePath): Promise<"dir" | "file">;Distinguish file vs dir vs missing. Throws NotFoundError for missing paths so the caller can decide whether that's terminal — matches storage-fs.isDir behavior.
Parameters
| Parameter | Type |
|---|---|
relativePath | string |
Returns
Promise<"dir" | "file">