studiocms
Version:
Astro Native CMS for AstroDB. Built from the ground up by the Astro community.
95 lines (94 loc) • 5.19 kB
TypeScript
import { Effect, Schema } from '../../../effect.js';
import { AstroDB, type LibSQLClientError } from '../effect/db.js';
import { type RecursiveSimplifyMutable } from '../effect/pluginUtils.js';
import type { PluginDataEntry, UsePluginDataOpts, UsePluginDataOptsBase } from '../types/index.js';
import { CacheContext } from '../utils.js';
declare const SDKCore_PLUGINS_base: Effect.Service.Class<SDKCore_PLUGINS, "studiocms/sdk/SDKCore/modules/plugins", {
readonly dependencies: readonly [import("effect/Layer").Layer<AstroDB, never, never>];
readonly effect: Effect.Effect<{
/**
* Provides a set of effectful operations for managing plugin data entries by plugin ID and optional entry ID.
*
* When an `entryId` is provided, returns an object with methods to:
* - Generate a unique plugin data entry ID.
* - Insert new plugin data after validation and duplicate checks.
* - Select and validate existing plugin data by ID.
* - Update existing plugin data after validation.
*
* When no `entryId` is provided, returns an object with a method to retrieve all entries for the given plugin.
*
* @param pluginId - The unique identifier for the plugin.
* @param entryId - (Optional) The unique identifier for the plugin data entry.
* @returns An object with effectful methods for plugin data management, varying by presence of `entryId`.
*/
usePluginData: {
<T extends Schema.Struct<Schema.Struct.Fields> | object, R extends object = T extends Schema.Struct<any> ? RecursiveSimplifyMutable<T["Type"]> : T>(pluginId: string, opts?: UsePluginDataOptsBase<T>): {
getEntries: (filter?: (data: PluginDataEntry<R>[]) => PluginDataEntry<R>[]) => Effect.Effect<PluginDataEntry<R>[], LibSQLClientError | Error, never>;
getEntry: (id: string) => {
generatedId: () => Effect.Effect<string, never, never>;
select: () => Effect.Effect<PluginDataEntry<R> | undefined, LibSQLClientError | Error, never>;
insert: (data: R) => Effect.Effect<PluginDataEntry<R>, LibSQLClientError | Error, never>;
update: (data: R) => Effect.Effect<PluginDataEntry<R>, LibSQLClientError | Error, never>;
};
};
<T extends Schema.Struct<Schema.Struct.Fields> | object, R extends object = T extends Schema.Struct<any> ? RecursiveSimplifyMutable<T["Type"]> : T>(pluginId: string, opts?: UsePluginDataOpts<T>): {
generatedId: () => Effect.Effect<string, never, never>;
select: () => Effect.Effect<PluginDataEntry<R> | undefined, LibSQLClientError | Error, never>;
insert: (data: R) => Effect.Effect<PluginDataEntry<R>, LibSQLClientError | Error, never>;
update: (data: R) => Effect.Effect<PluginDataEntry<R>, LibSQLClientError | Error, never>;
};
};
/**
* Initializes the plugin data cache by fetching all existing entries from the database
* and populating the in-memory cache with these entries.
*/
initPluginDataCache: (BATCH_SIZE?: number | undefined) => Effect.Effect<void, LibSQLClientError, never>;
/**
* Clears the plugin data cache, removing all cached entries.
*
* @returns An Effect that resolves to `void` on success or an `Error` on failure.
*/
clearPluginDataCache: () => Effect.Effect<void, Error, never>;
/**
* Utility class to infer types from a given Schema.
*
* @typeParam S - The schema type extending `Schema.Struct<any>`.
*
* @property _Schema - The schema instance used for type inference.
* @property usePluginData - The inferred type from the schema, used for plugin data.
* @property Insert - A recursively simplified, mutable version of the schema's type.
*
*/
InferType: {
new <S extends Schema.Struct<any>, R = RecursiveSimplifyMutable<S["Type"]>>(schema: S): {
readonly _Schema: S;
readonly $UsePluginData: S;
readonly $Insert: R;
};
};
}, never, AstroDB | CacheContext>;
}>;
/**
* Provides effectful operations for managing plugin-specific data entries in the database.
*
* The `SDKCore_PLUGINS` service exposes utilities for plugins to store, retrieve, and update
* their own data entries, scoped by a unique `pluginId` and `entryId`. All operations are
* effectful and designed to be used within an Effect context.
*
* @remarks
* - Depends on the `AstroDB` service for database access.
* - All methods are effectful and yield results or errors as Effects.
*
* @example
* ```typescript
* const plugins = yield* SDKCore_PLUGINS;
* const pluginDataOps = yield* plugins.usePluginData('myPlugin', 'entry1');
* const data = yield* pluginDataOps.select<MyDataType>();
* ```
*
* @service
* @module studiocms/sdk/SDKCore/modules/plugins
*/
export declare class SDKCore_PLUGINS extends SDKCore_PLUGINS_base {
}
export {};