virtuals/sdk/effect/pluginUtils
이 콘텐츠는 아직 번역되지 않았습니다.
Enumerations
Section titled “Enumerations”SelectPluginDataRespondOrFail
Section titled “SelectPluginDataRespondOrFail”Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:18^
Enum representing the possible responses when selecting plugin data, indicating whether the existence of the data should cause a failure or not.
Enumeration Members
Section titled “Enumeration Members”ExistsNoFail
Section titled “ExistsNoFail”ExistsNoFail: "existsNoFail";
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:19^
The plugin data exists and should not cause a failure.
ExistsShouldFail
Section titled “ExistsShouldFail”ExistsShouldFail: "existsShouldFail";
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:20^
The plugin data exists and should cause a failure.
NotExistsShouldFail
Section titled “NotExistsShouldFail”NotExistsShouldFail: "notExistsShouldFail";
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:21^
Type Aliases
Section titled “Type Aliases”RecursiveSimplifyMutable<A>
Section titled “RecursiveSimplifyMutable<A>”type RecursiveSimplifyMutable<A> = { -readonly [K in keyof A]: A[K] extends object ? RecursiveSimplifyMutable<A[K]> : A[K] } extends infer B ? B : never;
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:4^
Type Parameters
Section titled “Type Parameters”A
Variables
Section titled “Variables”getValidatorFn
Section titled “getValidatorFn”const getValidatorFn: any;
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:91^
Returns a validator function based on the provided validator options.
This function supports three types of validators:
jsonFn
: A custom JSON validation function.effectSchema
: An Effect schema for validation.zodSchema
: A Zod schema for validation.
The returned validator function takes unknown data and attempts to validate it
according to the specified validator. If validation succeeds, the data is returned
as type T
. If validation fails, an error is thrown or returned as an Effect error.
Type Param
Section titled “Type Param”The expected type of the validated data.
The validator options, which must include one of: jsonFn
, effectSchema
, or zodSchema
.
Returns
Section titled “Returns”A function that takes unknown data and returns an Effect that resolves to type T
if validation succeeds, or fails with an error if validation fails.
Throws
Section titled “Throws”Error if none of the expected validator options are provided.
parseData
Section titled “parseData”const parseData: any;
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:159^
Parses and validates plugin data from a raw input, supporting multiple validation strategies.
This function attempts to parse the provided rawData
, which can be either a JSON string or an object.
If a validator is provided, it validates the parsed data using one of the supported validation methods:
- JSON function (
jsonFn
) - Effect schema (
effectSchema
) - Zod schema (
zodSchema
)
If no validator is provided, the parsed data is returned as is. If validation fails or the input format is invalid, an error is yielded.
Type Param
Section titled “Type Param”The expected type of the parsed and validated data.
The raw input data, which can be a JSON string or an object.
Optional. An object specifying the validation strategy to use.
Returns
Section titled “Returns”An Effect
yielding the parsed and validated data of type T
, or an error if parsing or validation fails.
Throws
Section titled “Throws”If the input is neither a string nor an object, or if parsing/validation fails.
Functions
Section titled “Functions”isJsonValid()
Section titled “isJsonValid()”function isJsonValid<T>(data: unknown): (isValid: boolean) => T
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:68^
Returns a function that validates a boolean condition and either returns the provided value
cast to type T
if the condition is true, or throws an error if the condition is false.
Type Parameters
Section titled “Type Parameters”T
extends object
The expected type of the validated object.
Parameters
Section titled “Parameters”unknown
The value to be validated and potentially returned as type T
.
Returns
Section titled “Returns”Function
A function that takes a boolean indicating validation success.
Parameters
Section titled “Parameters”isValid
Section titled “isValid”boolean
Returns
Section titled “Returns”T
Throws
Section titled “Throws”If the boolean argument is false, throws an error with the serialized value.
Example
Section titled “Example”const validateUser = isJsonValid<User>(userData);const user = validateUser(isUserValid); // Returns userData as User if valid, otherwise throws.
noUndefinedEntries()
Section titled “noUndefinedEntries()”function noUndefinedEntries<T>(entries: (undefined | T)[]): T[]
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:48^
Filters out undefined
and null
values from an array of entries.
Type Parameters
Section titled “Type Parameters”T
The type of the array elements.
Parameters
Section titled “Parameters”entries
Section titled “entries”(undefined
| T
)[]
An array containing elements of type T
or undefined
.
Returns
Section titled “Returns”T
[]
A new array containing only the defined (non-undefined
, non-null
) entries of type T
.
parsedDataResponse()
Section titled “parsedDataResponse()”function parsedDataResponse<T>(id: string, data: T): Effect<PluginDataEntry<T>, never, never>
Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:32^
Wraps the provided id
and data
into a PluginDataEntry<T>
object and returns it as an Effect.
Type Parameters
Section titled “Type Parameters”T
extends object
The type of the data to be wrapped.
Parameters
Section titled “Parameters”string
The unique identifier for the plugin data entry.
T
The data to be associated with the given id.
Returns
Section titled “Returns”Effect
<PluginDataEntry
<T
>, never
, never
>
An Effect that, when executed, yields a PluginDataEntry<T>
containing the provided id and data.