TypeScript API / laikacms/storage/r2 / R2StorageRepository
Class: R2StorageRepository
R2StorageRepository implements the StorageRepository interface using Cloudflare R2. R2 is a flat object store, so this implementation simulates a hierarchical file system:
- Folders are represented by key prefixes
- Empty folders are represented by .keep files
- File extensions are handled transparently
Extends
Constructors
Constructor
new R2StorageRepository(
bucket,
serializerRegistry,
defaultFileExtension,
ignoreList?,
determineExtension?
): R2StorageRepository;Parameters
| Parameter | Type | Default value |
|---|---|---|
bucket | R2Bucket | undefined |
serializerRegistry | StorageSerializerRegistry | undefined |
defaultFileExtension | string | undefined |
ignoreList | string[] | ... |
determineExtension | DetermineExtension | defaultDetermineExtension |
Returns
R2StorageRepository
Overrides
Methods
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
StorageRepository.createFolder
createObject()
createObject(create): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
metadata?: {
extension?: string;
revisionId?: string;
};
type: "object";
updatedAt?: string;
}>;Parameters
| Parameter | Type | Description |
|---|---|---|
create | { content: { [key: string]: any; }; key: string; metadata?: { extension?: string; revisionId?: string; }; type?: "object"; } | - |
create.content | { [key: string]: any; } | - |
create.key | string | - |
create.metadata? | { extension?: string; revisionId?: string; } | Optional capability-driven metadata hints. Read by the storage's determineExtension callback to decide the on-disk format. |
create.metadata.extension? | string | File extension to use when (de)serializing this object. Active on backends whose Capabilities.fileExtensions.supported is true. Must match a key in Capabilities.fileExtensions.supportedExtensions. On writes: hint to the backend to use this extension's serializer. On reads: the extension the backend used to (de)serialize the object. |
create.metadata.revisionId? | string | Backend-specific revision identifier (e.g., GitHub commit SHA, R2 ETag, version ID). Active on backends that track per-object revisions. |
create.type? | "object" | - |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; metadata?: { extension?: string; revisionId?: string; }; type: "object"; updatedAt?: string; }>
Overrides
StorageRepository.createObject
createOrUpdateObject()
createOrUpdateObject(create): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
metadata?: {
extension?: string;
revisionId?: string;
};
type: "object";
updatedAt?: string;
}>;Parameters
| Parameter | Type | Description |
|---|---|---|
create | { content: { [key: string]: any; }; key: string; metadata?: { extension?: string; revisionId?: string; }; type?: "object"; } | - |
create.content | { [key: string]: any; } | - |
create.key | string | - |
create.metadata? | { extension?: string; revisionId?: string; } | Optional capability-driven metadata hints. Read by the storage's determineExtension callback to decide the on-disk format. |
create.metadata.extension? | string | File extension to use when (de)serializing this object. Active on backends whose Capabilities.fileExtensions.supported is true. Must match a key in Capabilities.fileExtensions.supportedExtensions. On writes: hint to the backend to use this extension's serializer. On reads: the extension the backend used to (de)serialize the object. |
create.metadata.revisionId? | string | Backend-specific revision identifier (e.g., GitHub commit SHA, R2 ETag, version ID). Active on backends that track per-object revisions. |
create.type? | "object" | - |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; metadata?: { extension?: string; revisionId?: string; }; type: "object"; updatedAt?: string; }>
Overrides
StorageRepository.createOrUpdateObject
getAtom()
getAtom(key): LaikaTask<
| {
createdAt?: string;
key: string;
type: "folder";
updatedAt?: string;
}
| {
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
metadata?: {
extension?: string;
revisionId?: string;
};
type: "object";
updatedAt?: string;
}>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
LaikaTask< | { createdAt?: string; key: string; type: "folder"; updatedAt?: string; } | { content: { [key: string]: any; }; createdAt?: string; key: string; metadata?: { extension?: string; revisionId?: string; }; type: "object"; updatedAt?: string; }>
Overrides
getCapabilities()
getCapabilities(): LaikaTask<{
changes: | {
description: string;
supported: false;
}
| {
changeFeed: boolean;
description: string;
subscription: boolean;
supported: true;
syncToken: boolean;
};
compatibilityDate: string & Brand<"StorageRepositoryCompatibilityDate">;
fileExtensions: | {
description: string;
supported: false;
}
| {
description: string;
supported: true;
supportedExtensions: {
[key: string]: object;
};
};
pagination: | {
description: string;
supported: false;
}
| {
description: string;
styles: {
cursor: boolean;
offset: boolean;
page: boolean;
};
supported: true;
};
}>;Returns
LaikaTask<{ changes: | { description: string; supported: false; } | { changeFeed: boolean; description: string; subscription: boolean; supported: true; syncToken: boolean; }; compatibilityDate: string & Brand<"StorageRepositoryCompatibilityDate">; fileExtensions: | { description: string; supported: false; } | { description: string; supported: true; supportedExtensions: { [key: string]: object; }; }; pagination: | { description: string; supported: false; } | { description: string; styles: { cursor: boolean; offset: boolean; page: boolean; }; supported: true; }; }>
Overrides
StorageRepository.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
getObject()
getObject(key): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
metadata?: {
extension?: string;
revisionId?: string;
};
type: "object";
updatedAt?: string;
}>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; metadata?: { extension?: string; revisionId?: string; }; type: "object"; updatedAt?: string; }>
Overrides
listAtoms()
listAtoms(folderKey, options): LaikaStream<
| {
createdAt?: string;
key: string;
type: "folder";
updatedAt?: string;
}
| {
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
metadata?: {
extension?: string;
revisionId?: string;
};
type: "object";
updatedAt?: string;
}, LaikaDone>;Parameters
| Parameter | Type |
|---|---|
folderKey | string |
options | ListAtomsOptions |
Returns
LaikaStream< | { createdAt?: string; key: string; type: "folder"; updatedAt?: string; } | { content: { [key: string]: any; }; createdAt?: string; key: string; metadata?: { extension?: string; revisionId?: string; }; type: "object"; updatedAt?: string; }, LaikaDone>
Overrides
listAtomSummaries()
listAtomSummaries(folderKey, options): LaikaStream<
| {
createdAt?: string;
key: string;
type: "object-summary";
updatedAt?: string;
}
| {
createdAt?: string;
key: string;
type: "folder-summary";
updatedAt?: string;
}, LaikaDone>;Parameters
| Parameter | Type |
|---|---|
folderKey | string |
options | ListAtomsOptions |
Returns
LaikaStream< | { createdAt?: string; key: string; type: "object-summary"; updatedAt?: string; } | { createdAt?: string; key: string; type: "folder-summary"; updatedAt?: string; }, LaikaDone>
Overrides
StorageRepository.listAtomSummaries
removeAtoms()
removeAtoms(keys): LaikaStream<string, RemoveAtomsDone>;Parameters
| Parameter | Type |
|---|---|
keys | readonly string[] |
Returns
LaikaStream<string, RemoveAtomsDone>
Overrides
subscribeChanges()
subscribeChanges(options, listener): Unsubscribe;Subscribe to live change notifications for a scope (a folder, or the whole store when omitted). listener is invoked with a coalesced, non-empty batch of ChangeSummary entries each time the scope changes. Returns an Unsubscribe that stops delivery; when the last listener leaves, the repository releases any underlying watch resource.
This is the PUSH counterpart to the pull getSyncToken / listChanges feed. Non-abstract on purpose: existing subclasses stay source-compatible. The base implementation throws NotImplementedError; check getCapabilities().changes (the enabled variant's subscription flag) before calling.
Parameters
| Parameter | Type |
|---|---|
options | SubscribeChangesOptions |
listener | ChangeListener |
Returns
Inherited from
StorageRepository.subscribeChanges
updateObject()
updateObject(update): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
metadata?: {
extension?: string;
revisionId?: string;
};
type: "object";
updatedAt?: string;
}>;Parameters
| Parameter | Type | Description |
|---|---|---|
update | { content?: { [key: string]: any; }; key: string; metadata?: { extension?: string; revisionId?: string; }; type?: "object"; } | - |
update.content? | { [key: string]: any; } | - |
update.key | string | - |
update.metadata? | { extension?: string; revisionId?: string; } | Optional capability-driven metadata hints. May carry a revisionId from a prior read for optimistic concurrency on backends that support it. |
update.metadata.extension? | string | File extension to use when (de)serializing this object. Active on backends whose Capabilities.fileExtensions.supported is true. Must match a key in Capabilities.fileExtensions.supportedExtensions. On writes: hint to the backend to use this extension's serializer. On reads: the extension the backend used to (de)serialize the object. |
update.metadata.revisionId? | string | Backend-specific revision identifier (e.g., GitHub commit SHA, R2 ETag, version ID). Active on backends that track per-object revisions. |
update.type? | "object" | - |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; metadata?: { extension?: string; revisionId?: string; }; type: "object"; updatedAt?: string; }>