Skip to content

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 ​

ts
new GithubDataSource(opts): GithubDataSource;

Parameters ​

ParameterType
optsGithubDataSourceOptions

Returns ​

GithubDataSource

Methods ​

createOrUpdate() ​

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

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

Returns ​

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


deleteFile() ​

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

Delete a file by sha. Empty-folder semantics are handled at the repository layer.

Parameters ​

ParameterType
relativePathstring
shastring
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;
  path: string;
  sha: string;
}>>;

Fetch a file's content + sha. Returns NotFound when the path is a directory or missing.

Parameters ​

ParameterType
relativePathstring

Returns ​

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


getFileMeta() ​

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

Get just the metadata (sha, lastModified) without downloading content.

Parameters ​

ParameterType
relativePathstring

Returns ​

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


listDirectory() ​

ts
listDirectory(relativePath): Promise<LaikaResult<GithubDirEntry[]>>;

List immediate children of a directory. Empty array when missing (mirrors storage-fs).

Parameters ​

ParameterType
relativePathstring

Returns ​

Promise<LaikaResult<GithubDirEntry[]>>


pathType() ​

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

ParameterType
relativePathstring

Returns ​

Promise<"dir" | "file">

Released under the MIT License.