Skip to content

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 ​

ts
new ObsidianAssetsRepository(vaultPath, options?): ObsidianAssetsRepository;

Parameters ​

ParameterType
vaultPathstring
optionsObsidianAssetsRepositoryOptions

Returns ​

ObsidianAssetsRepository

Overrides ​

AssetsRepository.constructor

Methods ​

createAsset() ​

ts
createAsset(create): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt?: string;
  key: string;
  type: "asset";
  updatedAt?: string;
  version?: string;
}>;

Parameters ​

ParameterTypeDescription
create{ cacheControl?: string; content: BinaryContent; customMetadata?: { [key: string]: string; }; filename?: string; key: string; mimeType: string; }-
create.cacheControl?stringCache control header value
create.contentBinaryContentThe 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?stringOriginal filename (optional)
create.keystringKey/path for the asset (without extension)
create.mimeTypestringMIME type of the asset

Returns ​

LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; type: "asset"; updatedAt?: string; version?: string; }>

Overrides ​

AssetsRepository.createAsset


createFolder() ​

ts
createFolder(folderCreate): LaikaTask<{
  createdAt?: string;
  key: string;
  type: "folder";
  updatedAt?: string;
}>;

Parameters ​

ParameterType
folderCreate{ key: string; type?: "folder"; }
folderCreate.keystring
folderCreate.type?"folder"

Returns ​

LaikaTask<{ createdAt?: string; key: string; type: "folder"; updatedAt?: string; }>

Overrides ​

AssetsRepository.createFolder


deleteAsset() ​

ts
deleteAsset(key): LaikaTask<void>;

Parameters ​

ParameterType
keystring

Returns ​

LaikaTask<void>

Overrides ​

AssetsRepository.deleteAsset


deleteAssets() ​

ts
deleteAssets(keys): LaikaStream<string, DeleteAssetsDone>;

Delete multiple assets. Emits each successfully-removed key as data; per-key failures surface as recoverable errors.

Parameters ​

ParameterType
keysreadonly string[]

Returns ​

LaikaStream<string, DeleteAssetsDone>

Overrides ​

AssetsRepository.deleteAssets


deleteFolder() ​

ts
deleteFolder(key, recursive?): LaikaTask<void>;

Parameters ​

ParameterType
keystring
recursive?boolean

Returns ​

LaikaTask<void>

Overrides ​

AssetsRepository.deleteFolder


getAsset() ​

ts
getAsset(key, _options?): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt?: string;
  key: string;
  type: "asset";
  updatedAt?: string;
  version?: string;
}>;

Parameters ​

ParameterType
keystring
_options?GetResourceOptions

Returns ​

LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; type: "asset"; updatedAt?: string; version?: string; }>

Overrides ​

AssetsRepository.getAsset


getAssetContent() ​

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

ParameterType
keystring

Returns ​

Promise<LaikaResult<{ body: ReadableStream<Uint8Array<ArrayBufferLike>>; contentType: string; size: number; }>>


getCapabilities() ​

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

ts
getFolder(key): LaikaTask<{
  createdAt?: string;
  key: string;
  type: "folder";
  updatedAt?: string;
}>;

Parameters ​

ParameterType
keystring

Returns ​

LaikaTask<{ createdAt?: string; key: string; type: "folder"; updatedAt?: string; }>

Overrides ​

AssetsRepository.getFolder


getMetadata() ​

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

ParameterType
assetsobject[]

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 ​

AssetsRepository.getMetadata


getResource() ​

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

ParameterType
keystring
_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 ​

AssetsRepository.getResource


getSyncToken() ​

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

ParameterType
options?GetSyncTokenOptions

Returns ​

LaikaTask<string & Brand<"SyncToken">>

Inherited from ​

AssetsRepository.getSyncToken


getUrls() ​

ts
getUrls(assets): LaikaStream<{
  expiresAt?: Utc;
  key: string;
  url?: string;
}, LaikaDone>;

Parameters ​

ParameterType
assetsobject[]

Returns ​

LaikaStream<{ expiresAt?: Utc; key: string; url?: string; }, LaikaDone>

Overrides ​

AssetsRepository.getUrls


getVariations() ​

ts
getVariations(assets): LaikaStream<{
  key: string;
  variations: {
   [key: string]: object;
  };
}, LaikaDone>;

No transformation pipeline — an Obsidian vault holds originals only.

Parameters ​

ParameterType
assetsobject[]

Returns ​

LaikaStream<{ key: string; variations: { [key: string]: object; }; }, LaikaDone>

Overrides ​

AssetsRepository.getVariations


listChanges() ​

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

ParameterType
optionsListChangesOptions

Returns ​

LaikaStream<{ deleted: boolean; key: string; version?: string; }, ListChangesDone>

Inherited from ​

AssetsRepository.listChanges


listResources() ​

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

ParameterType
folderKeystring
optionsListResourcesOptions

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() ​

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

ParameterTypeDescription
update{ cacheControl?: string; customMetadata?: { [key: string]: string; }; key: string; mimeType?: string; }-
update.cacheControl?stringUpdated cache control header value
update.customMetadata?{ [key: string]: string; }Updated custom metadata (replaces existing)
update.keystringKey/path of the asset to update
update.mimeType?stringUpdated MIME type (if content type needs correction)

Returns ​

LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; type: "asset"; updatedAt?: string; version?: string; }>

Overrides ​

AssetsRepository.updateAsset

Released under the MIT License.