Aller au contenu

virtuals/sdk/effect/pluginUtils

Ce contenu n’est pas encore disponible dans votre langue.

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.

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: "existsShouldFail";

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:20^

The plugin data exists and should cause a failure.

NotExistsShouldFail: "notExistsShouldFail";

Defined in: studiocms/packages/studiocms/src/virtuals/sdk/effect/pluginUtils.ts:21^

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^

A

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.

The expected type of the validated data.

The validator options, which must include one of: jsonFn, effectSchema, or zodSchema.

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.

Error if none of the expected validator options are provided.


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.

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.

An Effect yielding the parsed and validated data of type T, or an error if parsing or validation fails.

If the input is neither a string nor an object, or if parsing/validation fails.

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.

T extends object

The expected type of the validated object.

unknown

The value to be validated and potentially returned as type T.

Function

A function that takes a boolean indicating validation success.

boolean

T

If the boolean argument is false, throws an error with the serialized value.

const validateUser = isJsonValid<User>(userData);
const user = validateUser(isUserValid); // Returns userData as User if valid, otherwise throws.

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.

T

The type of the array elements.

(undefined | T)[]

An array containing elements of type T or undefined.

T[]

A new array containing only the defined (non-undefined, non-null) entries of type T.


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.

T extends object

The type of the data to be wrapped.

string

The unique identifier for the plugin data entry.

T

The data to be associated with the given id.

Effect<PluginDataEntry<T>, never, never>

An Effect that, when executed, yields a PluginDataEntry<T> containing the provided id and data.