Search Docs
Loading...
Skip to content

Class: AssetAPI

AssetAPI provides methods for asset source management API matches Web bindings: engine.asset.*

Implements#

  • IAssetAPI

Constructors#

Constructor#


| Parameter | Type | | —— | —— | | engine | NativeEngine |

Returns#

AssetAPI

Methods#

addSource()#


Add a custom asset source with callbacks.

This allows you to provide custom implementations for finding, fetching, and applying assets from any data source.

Parameters#

Parameter Type Description
source AssetSource The asset source configuration with callbacks.

Returns#

void

Implementation of#

IAssetAPI.addSource

Signature#

addSource(source: AssetSource): void

addLocalSource()#


Add a local asset source.

Mirrors @cesdk/engine’s 4-argument shape (bindings/wasm/js_web/src/AssetAPI.ts): when applyAsset or applyAssetToBlock is supplied, we wrap the local source as a synthetic AssetSource via addSource so the callbacks are honored. Without callbacks we go through the cheap addLocalSource fast path.

Parameters#

Parameter Type Description
id string Unique identifier for the asset source.
supportedMimeTypes? string[] The mime types of assets that are allowed to be added.
applyAsset? (asset) => Promise<number> Optional callback invoked when the asset is applied to a new block.
applyAssetToBlock? (asset, block) => Promise<void> Optional callback invoked when the asset is applied to an existing block.

Returns#

void

Implementation of#

IAssetAPI.addLocalSource

Signature#

addLocalSource(id: string, supportedMimeTypes?: string[], applyAsset?: (asset: CompleteAssetResult) => Promise<number>, applyAssetToBlock?: (asset: CompleteAssetResult, block: number) => Promise<void>): void

addLocalAssetSourceFromJSONString()#


Creates a new local asset source from a JSON string.

Parameters#

Parameter Type Description
contentJSON string The JSON string containing the asset definitions.
basePath? string Optional base path for resolving relative URLs.
options? { matcher?: string[]; } Optional configuration with matcher patterns.
options.matcher? string[] -

Returns#

Promise<string>

The ID of the created asset source.

Implementation of#

IAssetAPI.addLocalAssetSourceFromJSONString

Signature#

addLocalAssetSourceFromJSONString(contentJSON: string, basePath?: string, options?: object): Promise<string>

addLocalAssetSourceFromJSONURI()#


Creates a new local asset source from a JSON URI.

Parameters#

Parameter Type Description
contentURI string The URI for the JSON file to load.
options? { matcher?: string[]; abortSignal?: AbortSignal; } Optional configuration with matcher patterns, and an abortSignal that stops the download of the JSON file. No asset source is added then.
options.matcher? string[] -
options.abortSignal? AbortSignal -

Returns#

Promise<string>

The ID of the created asset source.

Implementation of#

IAssetAPI.addLocalAssetSourceFromJSONURI

Signature#

addLocalAssetSourceFromJSONURI(contentURI: string, options?: object): Promise<string>

removeSource()#


Remove a registered asset source.

Parameters#

Parameter Type Description
id string The ID of the asset source to remove.

Returns#

void

Implementation of#

IAssetAPI.removeSource

Signature#

removeSource(id: string): void

findAllSources()#


Get all registered asset source IDs.

Returns#

string[]

A list with the IDs of all registered asset sources.

Implementation of#

IAssetAPI.findAllSources

Signature#

findAllSources(): string[]

findAssets()#


Search for assets in a specific source.

Parameters#

Parameter Type Description
sourceId string The ID of the asset source.
query AssetsQuery Query options to filter and sort the search results.

Returns#

Promise<AssetsQueryResult<CompleteAssetResult>>

Promise resolving to paginated search results.

Implementation of#

IAssetAPI.findAssets

Signature#

findAssets(sourceId: string, query: AssetsQuery): Promise<AssetsQueryResult<CompleteAssetResult>>

fetchAsset()#


Fetch a specific asset by id from an asset source. Returns null when the asset is not found.

Parameters#

Parameter Type
sourceId string
assetId string
params? Pick<AssetQueryData, "locale">

Returns#

Promise<CompleteAssetResult>

Signature#

fetchAsset(sourceId: string, assetId: string, params?: Pick<AssetQueryData, "locale">): Promise<CompleteAssetResult>

getGroups()#


Get available asset groups from a source.

Parameters#

Parameter Type Description
id string The ID of the asset source.

Returns#

Promise<string[]>

Promise resolving to list of available group names.

Implementation of#

IAssetAPI.getGroups

Signature#

getGroups(id: string): Promise<string[]>

getLicense()#


Get license information for an asset source.

Parameters#

Parameter Type Description
sourceId string The ID of the asset source.

Returns#

object

The asset source’s license info.

Name Type
name string
url string

Implementation of#

IAssetAPI.getLicense

Signature#

getLicense(sourceId: string): object

getCredits()#


Get attribution credits for an asset source.

Parameters#

Parameter Type Description
sourceId string The ID of the asset source.

Returns#

object

The asset source’s credits info.

Name Type
name string
url string

Implementation of#

IAssetAPI.getCredits

Signature#

getCredits(sourceId: string): object

getSupportedMimeTypes()#


Get supported MIME types for an asset source.

Parameters#

Parameter Type Description
sourceId string The ID of the asset source.

Returns#

string[]

Array of supported MIME type strings.

Implementation of#

IAssetAPI.getSupportedMimeTypes

Signature#

getSupportedMimeTypes(sourceId: string): string[]

addAssetToSource()#


Add an asset to a local asset source.

Parameters#

Parameter Type Description
sourceId string The local asset source ID.
asset AssetDefinition The asset definition to add.

Returns#

void

Implementation of#

IAssetAPI.addAssetToSource

Signature#

addAssetToSource(sourceId: string, asset: AssetDefinition): void

removeAssetFromSource()#


Remove an asset from a local asset source.

Parameters#

Parameter Type Description
sourceId string The ID of the local asset source.
assetId string The ID of the asset to remove.

Returns#

void

Implementation of#

IAssetAPI.removeAssetFromSource

Signature#

removeAssetFromSource(sourceId: string, assetId: string): void

assetSourceContentsChanged()#


Notify the engine that an asset source’s contents have changed.

Parameters#

Parameter Type Description
sourceID string The asset source whose contents changed.

Returns#

void

Implementation of#

IAssetAPI.assetSourceContentsChanged

Signature#

assetSourceContentsChanged(sourceID: string): void

apply()#


Apply an asset to the current scene. Honors any middleware registered via registerApplyMiddleware and falls back to defaultApplyAsset.

Parameters#

Parameter Type
sourceId string
assetResult AssetResult
options? ApplyAssetOptions

Returns#

Promise<number>

Signature#

apply(sourceId: string, assetResult: AssetResult, options?: ApplyAssetOptions): Promise<number>

applyToBlock()#


Apply an asset to a specific block. Honors any middleware registered via registerApplyToBlockMiddleware and falls back to defaultApplyAssetToBlock.

Parameters#

Parameter Type
sourceId string
assetResult AssetResult
block number

Returns#

Promise<void>

Signature#

applyToBlock(sourceId: string, assetResult: AssetResult, block: number): Promise<void>

applyProperty()#


Apply a property change from an asset payload.

Parameters#

Parameter Type
sourceId string
asset AssetResult
property AssetProperty

Returns#

Promise<void>

Signature#

applyProperty(sourceId: string, asset: AssetResult, property: AssetProperty): Promise<void>

defaultApplyAsset()#


Default apply-asset implementation (no middleware). Calls the engine’s built-in apply logic; used as the tail of the middleware chain in apply.

Parameters#

Parameter Type
asset AssetResult
options? DefaultApplyAssetOptions

Returns#

Promise<number>

Signature#

defaultApplyAsset(asset: AssetResult, options?: DefaultApplyAssetOptions): Promise<number>

defaultApplyAssetToBlock()#


Default apply-to-block implementation (no middleware). Used as the tail of the middleware chain in applyToBlock.

An aspect ratio or fixed size preset reads the block’s layout, so the call performs an internal update to lay out pending changes. With the setting features/implicitUpdatesEnabled off, the preset can read the layout of the last update instead of pending changes. A block with no layout on a page that single page mode hides returns an error.

Parameters#

Parameter Type
asset AssetResult
block number

Returns#

Promise<void>

Signature#

defaultApplyAssetToBlock(asset: AssetResult, block: number): Promise<void>

registerApplyMiddleware()#


Register a middleware in the global apply-asset chain, matching @cesdk/engine’s registerApplyMiddleware. Returns a function that unregisters it.

The middleware receives a context that holds every option passed to apply, custom keys included. A context object that it passes to apply is merged over the received one into a new object: its top-level keys reach the next middleware and the default apply, and the keys it leaves out keep their values. A passed placement replaces the whole placement. Set a key to undefined to clear its value. Without a new context object, the next middleware gets the same object that the middleware received, so writes to it reach the outer middlewares. Only the abortSignal of the call to engine.asset.apply stops the apply.

Parameters#

Parameter Type
middleware (sourceId, assetResult, apply, context) => Promise<number>

Returns#

() => void

Signature#

registerApplyMiddleware(middleware: (sourceId: string, assetResult: AssetResult, apply: (sourceId: string, assetResult: AssetResult, options: ApplyAssetOptions) => Promise<number>, context: ApplyAssetOptions) => Promise<number>): () => void

registerApplyToBlockMiddleware()#


Register a middleware in the global apply-asset-to-block chain. Mirrors @cesdk/engine’s registerApplyToBlockMiddleware. Returns a function that unregisters it.

Parameters#

Parameter Type
middleware (sourceId, assetResult, block, applyToBlock) => Promise<void>

Returns#

() => void

Signature#

registerApplyToBlockMiddleware(middleware: (sourceId: string, assetResult: AssetResult, block: number, applyToBlock: (sourceId: string, assetResult: AssetResult, block: number) => Promise<void>) => Promise<void>): () => void

canManageAssets()#


Whether the named source declared the deprecated canManageAssets flag when it was registered.

The name suggests a capability question, but the answer is a record of what the host passed to addSource: a source registered without the flag reports false, and so does a source registered through addLocalSource, which never carries one. An unknown id is false rather than an error.

@cesdk/engine defines this method and is the reference for it, so this reads the recorded flag exactly as the web binding does. It used to probe the engine with a dry-run remove instead, which answered a different question — “can assets be added to and removed from this source?” — and returned true for every local source where the web binding returns false.

Parameters#

Parameter Type Description
sourceId string The source to ask about.

Returns#

boolean

Whether that source declared the flag.

Deprecated#

The underlying flag is deprecated. To control whether an upload button is rendered, use the canAdd option on an asset library entry instead.

Properties#

Property Type Description
onAssetSourceAdded (callback) => () => void Subscribe to “asset source added” events.
onAssetSourceRemoved (callback) => () => void Subscribe to “asset source removed” events.
onAssetSourceUpdated (callback) => () => void Subscribe to “asset source updated” events.