Zum Inhalt springen

virtuals/sdk/utils

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:65^

Represents a context for caching within the application.

This class extends a tagged context using Context.Tag, allowing for type-safe context management.

const cacheLayer = CacheContext.makeLayer(myCachedContext);
const providedEffect = CacheContext.makeProvide(myCachedContext);

makeLayer Creates a Layer that provides the given cached context.

The cached context to be provided.

makeProvide Creates an Effect that provides the cached context using a layer.

The cached context to be provided.

  • any

new CacheContext(): CacheContext

CacheContext

Context.Tag('CacheContext')<CacheContext, CachedContext>().constructor

static makeLayer(context: CachedContext): any

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:66^

CachedContext

any

static makeProvide(context: CachedContext): any

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:67^

CachedContext

any

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:31^

Represents the cached context containing various cache maps for different data types.

FolderList: CacheMap<string, FolderListCacheObject>;

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:37^

Cache map storing folder list objects, keyed by string.

folderTree: CacheMap<string, FolderTreeCacheObject>;

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:35^

Cache map storing folder tree objects, keyed by string.

pageFolderTree: CacheMap<string, FolderTreeCacheObject>;

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:36^

Cache map storing page folder tree objects, keyed by string.

pages: CacheMap<string, PageDataCacheObject>;

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:32^

Cache map storing page data objects, keyed by string.

pluginData: CacheMap<string, PluginDataCacheObject>;

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:38^

siteConfig: CacheMap<string, SiteConfigCacheObject>;

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:33^

Cache map storing site configuration objects, keyed by string.

version: CacheMap<string, VersionCacheObject>;

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:34^

Cache map storing version objects, keyed by string.

const cacheConfig: {
enabled: boolean;
lifetime: number;
} = sdkConfig.cacheConfig;

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:76^

Exports the cache configuration object from the SDK configuration. This configuration is used to control caching behavior within the SDK.

enabled: boolean;

Cache Enabled

true

lifetime: number;

Cache Lifetime

{number}{unit} - e.g. ‘5m’ for 5 minutes or ‘1h’ for 1 hour

'5m'

sdkConfig.cacheConfig


const isCacheEnabled: any;

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:86^

Determines if caching is enabled based on the current cache configuration.

This function attempts to access the enabled property of cacheConfig within an Effect.try block, which safely handles any errors that may occur during the retrieval.

An Effect that resolves to a boolean indicating whether caching is enabled.

function _clearLibSQLError(id: string, cause: unknown): any

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:111^

Creates an Effect.fail with a custom SDKCoreError for LibSQL database errors.

string

Identifier or context for the error.

unknown

The underlying cause of the error.

any

An Effect.fail containing a SDKCoreError with type ‘LibSQLDatabaseError’ and a wrapped StudioCMS_SDK_Error.


function _ClearUnknownError(id: string, cause: unknown): any

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:96^

Creates an Effect.fail with a custom SDKCoreError of type ‘UNKNOWN’. The error message includes the provided id and the unknown cause.

string

A string identifier for the error context.

unknown

The unknown error cause to be included in the error message.

any

An Effect.fail containing the constructed SDKCoreError.


function convertCombinedPageDataToMetaOnly<T>(data: T): PageDataCacheReturnType<T>

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:192^

Converts a PageDataCacheObject or an array of such objects to a meta-only representation, removing defaultContent and multiLangContent from the data property.

T extends | PageDataCacheObject | PageDataCacheObject[]

Either a single PageDataCacheObject or an array of them.

T

The input object(s) containing page data and cache information.

PageDataCacheReturnType<T>

The meta-only representation of the input, preserving lastCacheUpdate and all properties of data except defaultContent and multiLangContent.


function filterPagesByDraftAndIndex(
pages: {
authorId: null | string;
categories: unknown;
contentLang: string;
contributorIds: unknown;
description: string;
draft: null | boolean;
heroImage: string;
id: string;
package: string;
parentFolder: null | string;
publishedAt: Date;
showAuthor: null | boolean;
showContributors: null | boolean;
showOnNav: boolean;
slug: string;
tags: unknown;
title: string;
updatedAt: null | Date;
}[],
includeDrafts: boolean,
hideDefaultIndex: boolean): {
authorId: null | string;
categories: unknown;
contentLang: string;
contributorIds: unknown;
description: string;
draft: null | boolean;
heroImage: string;
id: string;
package: string;
parentFolder: null | string;
publishedAt: Date;
showAuthor: null | boolean;
showContributors: null | boolean;
showOnNav: boolean;
slug: string;
tags: unknown;
title: string;
updatedAt: null | Date;
}[]

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:230^

Filters an array of page data objects based on draft status and index slug.

{ authorId: null | string; categories: unknown; contentLang: string; contributorIds: unknown; description: string; draft: null | boolean; heroImage: string; id: string; package: string; parentFolder: null | string; publishedAt: Date; showAuthor: null | boolean; showContributors: null | boolean; showOnNav: boolean; slug: string; tags: unknown; title: string; updatedAt: null | Date; }[]

The array of page data objects to filter.

boolean

If true, includes pages marked as drafts; otherwise, excludes them.

boolean

If true, excludes pages with the slug 'index'; otherwise, includes them.

{ authorId: null | string; categories: unknown; contentLang: string; contributorIds: unknown; description: string; draft: null | boolean; heroImage: string; id: string; package: string; parentFolder: null | string; publishedAt: Date; showAuthor: null | boolean; showContributors: null | boolean; showOnNav: boolean; slug: string; tags: unknown; title: string; updatedAt: null | Date; }[]

The filtered array of page data objects.


function folderListReturn(data: FolderListItem[]): FolderListCacheObject

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:138^

Creates a cache object for a list of folders.

FolderListItem[]

An array of FolderListItem representing the folder list.

FolderListCacheObject

A FolderListCacheObject containing the folder list and the timestamp of the cache update.


function folderTreeReturn(data: FolderNode[]): FolderTreeCacheObject

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:125^

Returns a cache object containing the provided folder tree data and the current timestamp.

FolderNode[]

An array of FolderNode objects representing the folder tree structure.

FolderTreeCacheObject

A FolderTreeCacheObject containing the folder tree data and the time of cache update.


function isCacheExpired(entry: BaseCacheObject, lifetime: number): boolean

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:218^

Determines whether a cache entry has expired based on its last update time and a specified lifetime.

BaseCacheObject

The cache entry object containing the last cache update timestamp.

number = cacheConfig.lifetime

The maximum allowed lifetime (in milliseconds) for the cache entry before it is considered expired. Defaults to cacheConfig.lifetime.

boolean

true if the cache entry has expired; otherwise, false.


function pageDataReturn(data: CombinedPageData): PageDataCacheObject

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:151^

Creates a PageDataCacheObject containing the provided page data and the current timestamp.

CombinedPageData

The combined page data to be cached.

PageDataCacheObject

An object with the cached data and the time of cache update.


function siteConfigReturn(siteConfig: SiteConfig): SiteConfigCacheObject

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:164^

Returns a cache object containing the provided site configuration and the current timestamp.

SiteConfig

The site configuration object to cache.

SiteConfigCacheObject

An object containing the site configuration and the time of cache update.


function versionReturn(version: string): VersionCacheObject

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:177^

Creates a VersionCacheObject containing the provided version string and the current timestamp.

string

The version string to include in the returned object.

VersionCacheObject

An object with the specified version and the current date as lastCacheUpdate.