virtuals/sdk/utils
Ce contenu n’est pas encore disponible dans votre langue.
Classes
Section titled “Classes”CacheContext
Section titled “CacheContext”Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:65^
Represents a context for caching within the application.
Remarks
Section titled “Remarks”This class extends a tagged context using Context.Tag
, allowing for type-safe context management.
Example
Section titled “Example”const cacheLayer = CacheContext.makeLayer(myCachedContext);const providedEffect = CacheContext.makeProvide(myCachedContext);
Method
Section titled “Method”makeLayer
Creates a Layer
that provides the given cached context.
The cached context to be provided.
Method
Section titled “Method”makeProvide
Creates an Effect
that provides the cached context using a layer.
The cached context to be provided.
Extends
Section titled “Extends”any
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CacheContext(): CacheContext
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Context.Tag('CacheContext')<CacheContext, CachedContext>().constructor
Methods
Section titled “Methods”makeLayer()
Section titled “makeLayer()”static makeLayer(context: CachedContext): any
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:66^
Parameters
Section titled “Parameters”context
Section titled “context”Returns
Section titled “Returns”any
makeProvide()
Section titled “makeProvide()”static makeProvide(context: CachedContext): any
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:67^
Parameters
Section titled “Parameters”context
Section titled “context”Returns
Section titled “Returns”any
Interfaces
Section titled “Interfaces”CachedContext
Section titled “CachedContext”Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:31^
Represents the cached context containing various cache maps for different data types.
Properties
Section titled “Properties”FolderList
Section titled “FolderList”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
Section titled “folderTree”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
Section titled “pageFolderTree”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
Section titled “pluginData”pluginData: CacheMap<string, PluginDataCacheObject>;
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:38^
siteConfig
Section titled “siteConfig”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
Section titled “version”version: CacheMap<string, VersionCacheObject>;
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/utils.ts:34^
Cache map storing version objects, keyed by string.
Variables
Section titled “Variables”cacheConfig
Section titled “cacheConfig”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.
Type declaration
Section titled “Type declaration”enabled
Section titled “enabled”enabled: boolean;
Cache Enabled
Default
Section titled “Default”true
lifetime
Section titled “lifetime”lifetime: number;
Cache Lifetime
{number}{unit}
- e.g. ‘5m’ for 5 minutes or ‘1h’ for 1 hour
Default
Section titled “Default”'5m'
sdkConfig.cacheConfig
isCacheEnabled
Section titled “isCacheEnabled”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.
Returns
Section titled “Returns”An Effect
that resolves to a boolean indicating whether caching is enabled.
Functions
Section titled “Functions”_clearLibSQLError()
Section titled “_clearLibSQLError()”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.
Parameters
Section titled “Parameters”string
Identifier or context for the error.
unknown
The underlying cause of the error.
Returns
Section titled “Returns”any
An Effect.fail
containing a SDKCoreError
with type ‘LibSQLDatabaseError’ and a wrapped StudioCMS_SDK_Error
.
_ClearUnknownError()
Section titled “_ClearUnknownError()”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
.
Parameters
Section titled “Parameters”string
A string identifier for the error context.
unknown
The unknown error cause to be included in the error message.
Returns
Section titled “Returns”any
An Effect.fail
containing the constructed SDKCoreError
.
convertCombinedPageDataToMetaOnly()
Section titled “convertCombinedPageDataToMetaOnly()”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.
Type Parameters
Section titled “Type Parameters”T
extends
| PageDataCacheObject
| PageDataCacheObject
[]
Either a single PageDataCacheObject
or an array of them.
Parameters
Section titled “Parameters”T
The input object(s) containing page data and cache information.
Returns
Section titled “Returns”The meta-only representation of the input, preserving lastCacheUpdate
and all properties of data
except defaultContent
and multiLangContent
.
filterPagesByDraftAndIndex()
Section titled “filterPagesByDraftAndIndex()”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.
Parameters
Section titled “Parameters”{
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.
includeDrafts
Section titled “includeDrafts”boolean
If true
, includes pages marked as drafts; otherwise, excludes them.
hideDefaultIndex
Section titled “hideDefaultIndex”boolean
If true
, excludes pages with the slug 'index'
; otherwise, includes them.
Returns
Section titled “Returns”{
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.
folderListReturn()
Section titled “folderListReturn()”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.
Parameters
Section titled “Parameters”An array of FolderListItem
representing the folder list.
Returns
Section titled “Returns”A FolderListCacheObject
containing the folder list and the timestamp of the cache update.
folderTreeReturn()
Section titled “folderTreeReturn()”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.
Parameters
Section titled “Parameters”An array of FolderNode
objects representing the folder tree structure.
Returns
Section titled “Returns”A FolderTreeCacheObject
containing the folder tree data and the time of cache update.
isCacheExpired()
Section titled “isCacheExpired()”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.
Parameters
Section titled “Parameters”The cache entry object containing the last cache update timestamp.
lifetime
Section titled “lifetime”number
= cacheConfig.lifetime
The maximum allowed lifetime (in milliseconds) for the cache entry before it is considered expired. Defaults to cacheConfig.lifetime
.
Returns
Section titled “Returns”boolean
true
if the cache entry has expired; otherwise, false
.
pageDataReturn()
Section titled “pageDataReturn()”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.
Parameters
Section titled “Parameters”The combined page data to be cached.
Returns
Section titled “Returns”An object with the cached data and the time of cache update.
siteConfigReturn()
Section titled “siteConfigReturn()”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.
Parameters
Section titled “Parameters”siteConfig
Section titled “siteConfig”The site configuration object to cache.
Returns
Section titled “Returns”An object containing the site configuration and the time of cache update.
versionReturn()
Section titled “versionReturn()”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.
Parameters
Section titled “Parameters”version
Section titled “version”string
The version string to include in the returned object.
Returns
Section titled “Returns”An object with the specified version and the current date as lastCacheUpdate
.