TypeScript API / laikacms/assets/obsidian / ObsidianAssetsRepository
Class: ObsidianAssetsRepository
An AssetsRepository backed by the files of an Obsidian vault.
Every non-markdown file in the vault (images, PDFs, audio, ...) is exposed as an Asset keyed by its path relative to the asset root. This is intended for retrieving attachments that already live alongside your notes; writing assets back into a vault bloats whatever syncs it (git, Obsidian Sync), so for write-heavy workloads prefer an object-storage backend such as assets-r2.
An Obsidian vault has no place to keep per-file custom metadata or cache headers, so updateAsset is unsupported — replace the file via createAsset instead.
Extends
Constructors
Constructor
new ObsidianAssetsRepository(vaultPath, options?): ObsidianAssetsRepository;Parameters
| Parameter | Type |
|---|---|
vaultPath | string |
options | ObsidianAssetsRepositoryOptions |
Returns
ObsidianAssetsRepository
Overrides
Methods
createAsset()
createAsset(create): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
type: "asset";
updatedAt?: string;
version?: string;
}>;Parameters
| Parameter | Type | Description |
|---|---|---|
create | { cacheControl?: string; content: BinaryContent; customMetadata?: { [key: string]: string; }; filename?: string; key: string; mimeType: string; } | - |
create.cacheControl? | string | Cache control header value |
create.content | BinaryContent | The binary content of the asset. Accepts Uint8Array, ArrayBuffer, or ReadableStream<Uint8Array>. |
create.customMetadata? | { [key: string]: string; } | Custom metadata to store with the asset |
create.filename? | string | Original filename (optional) |
create.key | string | Key/path for the asset (without extension) |
create.mimeType | string | MIME type of the asset |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; type: "asset"; updatedAt?: string; version?: string; }>
Overrides
createFolder()
createFolder(folderCreate): LaikaTask<{
createdAt?: string;
key: string;
type: "folder";
updatedAt?: string;
}>;Parameters
| Parameter | Type |
|---|---|
folderCreate | { key: string; type?: "folder"; } |
folderCreate.key | string |
folderCreate.type? | "folder" |
Returns
LaikaTask<{ createdAt?: string; key: string; type: "folder"; updatedAt?: string; }>
Overrides
deleteAsset()
deleteAsset(key): LaikaTask<void>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
LaikaTask<void>
Overrides
deleteAssets()
deleteAssets(keys): LaikaStream<string, DeleteAssetsDone>;Delete multiple assets. Emits each successfully-removed key as data; per-key failures surface as recoverable errors.
Parameters
| Parameter | Type |
|---|---|
keys | readonly string[] |
Returns
LaikaStream<string, DeleteAssetsDone>
Overrides
deleteFolder()
deleteFolder(key, recursive?): LaikaTask<void>;Parameters
| Parameter | Type |
|---|---|
key | string |
recursive? | boolean |
Returns
LaikaTask<void>
Overrides
getAsset()
getAsset(key, _options?): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
type: "asset";
updatedAt?: string;
version?: string;
}>;Parameters
| Parameter | Type |
|---|---|
key | string |
_options? | GetResourceOptions |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; type: "asset"; updatedAt?: string; version?: string; }>
Overrides
getAssetContent()
getAssetContent(key): Promise<LaikaResult<{
body: ReadableStream<Uint8Array<ArrayBufferLike>>;
contentType: string;
size: number;
}>>;Stream an asset's bytes — for HTTP handlers that serve the file directly. Returns a LaikaResult rather than a LaikaTask because the body is a live stream the caller must consume.
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Promise<LaikaResult<{ body: ReadableStream<Uint8Array<ArrayBufferLike>>; contentType: string; size: number; }>>
getCapabilities()
getCapabilities(): LaikaTask<{
changes: | {
description: string;
supported: false;
}
| {
changeFeed: boolean;
description: string;
supported: true;
syncToken: boolean;
};
compatibilityDate: string & Brand<"AssetsRepositoryCompatibilityDate">;
filtering?: | {
description: string;
supported: false;
}
| {
description: string;
filters: readonly object[];
supported: true;
};
pagination: | {
description: string;
supported: false;
}
| {
description: string;
styles: {
cursor: boolean;
offset: boolean;
page: boolean;
};
supported: true;
};
versionTracking: | {
description: string;
supported: false;
}
| {
description: string;
supported: true;
};
}>;Returns
LaikaTask<{ changes: | { description: string; supported: false; } | { changeFeed: boolean; description: string; supported: true; syncToken: boolean; }; compatibilityDate: string & Brand<"AssetsRepositoryCompatibilityDate">; filtering?: | { description: string; supported: false; } | { description: string; filters: readonly object[]; supported: true; }; pagination: | { description: string; supported: false; } | { description: string; styles: { cursor: boolean; offset: boolean; page: boolean; }; supported: true; }; versionTracking: | { description: string; supported: false; } | { description: string; supported: true; }; }>
Overrides
AssetsRepository.getCapabilities
getFolder()
getFolder(key): LaikaTask<{
createdAt?: string;
key: string;
type: "folder";
updatedAt?: string;
}>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
LaikaTask<{ createdAt?: string; key: string; type: "folder"; updatedAt?: string; }>
Overrides
getMetadata()
getMetadata(assets): LaikaStream<{
key: string;
metadata: | {
animated?: boolean;
bitDepth?: number;
colorSpace?: string;
createdAt?: Utc;
exif?: {
[key: string]: any;
};
extension?: string;
filename?: string;
hasAlpha?: boolean;
hash?: string;
hashAlgorithm?: string;
height: number;
kind: "image";
mimeType: string;
modifiedAt?: Utc;
size: number;
width: number;
}
| {
audioBitrate?: number;
audioChannels?: number;
audioCodec?: string;
audioSampleRate?: number;
createdAt?: Utc;
duration: number;
extension?: string;
filename?: string;
frameRate?: number;
hash?: string;
hashAlgorithm?: string;
height: number;
kind: "video";
mimeType: string;
modifiedAt?: Utc;
size: number;
videoBitrate?: number;
videoCodec?: string;
width: number;
}
| {
bitrate?: number;
channels?: number;
codec?: string;
createdAt?: Utc;
duration: number;
extension?: string;
filename?: string;
hash?: string;
hashAlgorithm?: string;
kind: "audio";
mimeType: string;
modifiedAt?: Utc;
sampleRate?: number;
size: number;
tags?: {
[key: string]: string;
};
}
| {
author?: string;
createdAt?: Utc;
documentCreatedAt?: Utc;
documentModifiedAt?: Utc;
extension?: string;
filename?: string;
hash?: string;
hashAlgorithm?: string;
keywords?: readonly string[];
kind: "document";
mimeType: string;
modifiedAt?: Utc;
pageCount?: number;
size: number;
subject?: string;
title?: string;
}
| {
createdAt?: Utc;
extension?: string;
filename?: string;
hash?: string;
hashAlgorithm?: string;
kind: "binary";
mimeType: string;
modifiedAt?: Utc;
size: number;
};
}, LaikaDone>;Parameters
| Parameter | Type |
|---|---|
assets | object[] |
Returns
LaikaStream<{ key: string; metadata: | { animated?: boolean; bitDepth?: number; colorSpace?: string; createdAt?: Utc; exif?: { [key: string]: any; }; extension?: string; filename?: string; hasAlpha?: boolean; hash?: string; hashAlgorithm?: string; height: number; kind: "image"; mimeType: string; modifiedAt?: Utc; size: number; width: number; } | { audioBitrate?: number; audioChannels?: number; audioCodec?: string; audioSampleRate?: number; createdAt?: Utc; duration: number; extension?: string; filename?: string; frameRate?: number; hash?: string; hashAlgorithm?: string; height: number; kind: "video"; mimeType: string; modifiedAt?: Utc; size: number; videoBitrate?: number; videoCodec?: string; width: number; } | { bitrate?: number; channels?: number; codec?: string; createdAt?: Utc; duration: number; extension?: string; filename?: string; hash?: string; hashAlgorithm?: string; kind: "audio"; mimeType: string; modifiedAt?: Utc; sampleRate?: number; size: number; tags?: { [key: string]: string; }; } | { author?: string; createdAt?: Utc; documentCreatedAt?: Utc; documentModifiedAt?: Utc; extension?: string; filename?: string; hash?: string; hashAlgorithm?: string; keywords?: readonly string[]; kind: "document"; mimeType: string; modifiedAt?: Utc; pageCount?: number; size: number; subject?: string; title?: string; } | { createdAt?: Utc; extension?: string; filename?: string; hash?: string; hashAlgorithm?: string; kind: "binary"; mimeType: string; modifiedAt?: Utc; size: number; }; }, LaikaDone>
Overrides
getResource()
getResource(key, _options?): LaikaTask<readonly (
| {
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
type: "asset";
updatedAt?: string;
version?: string;
}
| {
createdAt?: string;
key: string;
type: "folder";
updatedAt?: string;
})[]>;Get a resource (asset or folder) by key. Returns an array because a single key may resolve to multiple resources (e.g. variations included via hints).
Parameters
| Parameter | Type |
|---|---|
key | string |
_options? | GetResourceOptions |
Returns
LaikaTask<readonly ( | { content: { [key: string]: any; }; createdAt?: string; key: string; type: "asset"; updatedAt?: string; version?: string; } | { createdAt?: string; key: string; type: "folder"; updatedAt?: string; })[]>
Overrides
getSyncToken()
getSyncToken(options?): LaikaTask<string & Brand<"SyncToken">>;Return an opaque token for the given scope (a folder, or the whole store when omitted) that changes whenever anything inside the scope changes. Compare tokens only by equality.
Non-abstract on purpose: existing subclasses stay source-compatible. The base implementation fails with NotImplementedError; check getCapabilities().changes before calling.
Parameters
| Parameter | Type |
|---|---|
options? | GetSyncTokenOptions |
Returns
LaikaTask<string & Brand<"SyncToken">>
Inherited from
getUrls()
getUrls(assets): LaikaStream<{
expiresAt?: Utc;
key: string;
url?: string;
}, LaikaDone>;Parameters
| Parameter | Type |
|---|---|
assets | object[] |
Returns
LaikaStream<{ expiresAt?: Utc; key: string; url?: string; }, LaikaDone>
Overrides
getVariations()
getVariations(assets): LaikaStream<{
key: string;
variations: {
[key: string]: object;
};
}, LaikaDone>;No transformation pipeline — an Obsidian vault holds originals only.
Parameters
| Parameter | Type |
|---|---|
assets | object[] |
Returns
LaikaStream<{ key: string; variations: { [key: string]: object; }; }, LaikaDone>
Overrides
AssetsRepository.getVariations
listChanges()
listChanges(options): LaikaStream<{
deleted: boolean;
key: string;
version?: string;
}, ListChangesDone>;Enumerate what changed inside the scope since a previously obtained sync token. The done value carries the new sync token to resume from.
Non-abstract on purpose: existing subclasses stay source-compatible. The base implementation fails with NotImplementedError; check getCapabilities().changes before calling.
Parameters
| Parameter | Type |
|---|---|
options | ListChangesOptions |
Returns
LaikaStream<{ deleted: boolean; key: string; version?: string; }, ListChangesDone>
Inherited from
listResources()
listResources(folderKey, options): LaikaStream<
| {
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
type: "asset";
updatedAt?: string;
version?: string;
}
| {
createdAt?: string;
key: string;
type: "folder";
updatedAt?: string;
}, LaikaDone>;Parameters
| Parameter | Type |
|---|---|
folderKey | string |
options | ListResourcesOptions |
Returns
LaikaStream< | { content: { [key: string]: any; }; createdAt?: string; key: string; type: "asset"; updatedAt?: string; version?: string; } | { createdAt?: string; key: string; type: "folder"; updatedAt?: string; }, LaikaDone>
Overrides
AssetsRepository.listResources
updateAsset()
updateAsset(update): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
type: "asset";
updatedAt?: string;
version?: string;
}>;Unsupported: an Obsidian vault stores no per-file custom metadata or cache headers, so there is nothing for an update to change. Replace the file with createAsset instead.
Parameters
| Parameter | Type | Description |
|---|---|---|
update | { cacheControl?: string; customMetadata?: { [key: string]: string; }; key: string; mimeType?: string; } | - |
update.cacheControl? | string | Updated cache control header value |
update.customMetadata? | { [key: string]: string; } | Updated custom metadata (replaces existing) |
update.key | string | Key/path of the asset to update |
update.mimeType? | string | Updated MIME type (if content type needs correction) |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; type: "asset"; updatedAt?: string; version?: string; }>