Skip to content

TypeScript API / laikacms/assets/jsonapi-proxy / AssetsJsonApiProxyRepository

Class: AssetsJsonApiProxyRepository ​

Proxies all assets operations through a remote JSON:API endpoint.

Extends ​

Constructors ​

Constructor ​

ts
new AssetsJsonApiProxyRepository(options): AssetsJsonApiProxyRepository;

Parameters ​

ParameterType
optionsAssetsJsonApiProxyRepositoryOptions

Returns ​

AssetsJsonApiProxyRepository

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>;

Batch-remove several assets in a single POST /operations call instead of one DELETE per key. Follows the upstream assets-api server's fail-fast contract (ADR-004): ops apply in order and processing stops at the first repository failure, so results may be shorter than keys when a mid-batch failure occurred. Unlike the fail-fast server contract itself, this method's own contract (mirrors storage-jsonapi-proxy's removeAtoms) is best-effort per key — every key is resolved to either a data (removed) or recoverableError (skipped) outcome, including keys left unprocessed by a fail-fast stop.

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


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">>

Overrides ​

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>;

Compute variation URLs for the given assets, one entry per asset. Per-asset failures (e.g. unsupported format) surface as recoverable errors.

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>

Overrides ​

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;
}>;

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.