studiocms
Version:
Astro Native CMS for AstroDB. Built from the ground up by the Astro community.
128 lines (127 loc) • 8.08 kB
TypeScript
import { Deepmerge, Effect } from '../../../effect.js';
import { AstroDB, type LibSQLClientError } from '../effect/db.js';
import { tsMailerConfig, tsNotificationSettings, tsSiteConfig } from '../tables.js';
import type { ConfigFinal, DynamicConfigEntry, RawDynamicConfigEntry, StudioCMSMailerConfig, StudioCMSNotificationSettings, StudioCMSSiteConfig, StudioCMSTemplateConfig } from './config-types.js';
export type { ConfigFinal, DynamicConfigEntry, LegacyMailerConfig, LegacyNotificationSettings, LegacySiteConfig, LegacyTables, RawDynamicConfigEntry, RawDynamicConfigInsert, StudioCMSDynamicConfigBase, StudioCMSMailerConfig, StudioCMSNotificationSettings, StudioCMSSiteConfig, StudioCMSTemplateConfig, } from './config-types.js';
/**
* Casts the `data` property of a `RawDynamicConfigEntry` to the specified generic type `T`
* and returns a new `DynamicConfigEntry<T>` object.
*
* @typeParam T - The type to cast the `data` property to.
* @param param0 - An object containing the `data` to cast and its associated `id`.
* @param param0.data - The raw data to be cast to type `T`.
* @param param0.id - The identifier for the config entry.
* @returns A `DynamicConfigEntry<T>` object with the `data` property cast to type `T`.
*/
export declare const castType: <T>({ data, id }: RawDynamicConfigEntry) => DynamicConfigEntry<T>;
/**
* Migrates a legacy site configuration object to the latest `StudioCMSSiteConfig` format.
*
* @param params - The legacy site configuration object, destructured to extract `id`, `gridItems`, and the rest of the config.
* @param params.id - The unique identifier of the site (legacy, not used in the new config).
* @param params.gridItems - The grid items from the legacy config, which will be cast to a string array.
* @param params.legacyConfig - The remaining properties of the legacy config.
* @returns The migrated site configuration object with the latest config version and normalized `gridItems`.
*/
export declare const migrateLegacySiteConfig: ({ id, gridItems, ...legacyConfig }: typeof tsSiteConfig.$inferSelect) => StudioCMSSiteConfig;
/**
* Migrates a legacy mailer configuration object to the current configuration version.
*
* @param param0 - The legacy mailer configuration object, destructured to extract the `id` and the rest of the configuration.
* @returns The updated mailer configuration object with the current configuration version applied.
*/
export declare const migrateLegacyMailerConfig: ({ id, ...legacyConfig }: typeof tsMailerConfig.$inferSelect) => StudioCMSMailerConfig;
/**
* Migrates legacy notification settings to the current configuration version.
*
* @param param0 - An object containing the legacy notification settings, including an `id` and other configuration properties.
* @returns The migrated notification settings object with the updated `_config_version`.
*/
export declare const migrateLegacyNotificationSettings: ({ id, ...legacyConfig }: typeof tsNotificationSettings.$inferSelect) => StudioCMSNotificationSettings;
declare const SDKCore_CONFIG_base: Effect.Service.Class<SDKCore_CONFIG, "studiocms/sdk/modules/SDKCore_CONFIG", {
readonly dependencies: readonly [import("effect/Layer").Layer<AstroDB, never, never>, import("effect/Layer").Layer<Deepmerge, never, never>];
readonly effect: Effect.Effect<{
readonly siteConfig: {
/**
* Retrieves the current site configuration.
*/
get: () => Effect.Effect<DynamicConfigEntry<StudioCMSSiteConfig> | undefined, LibSQLClientError, never>;
/**
* Updates the site configuration with the provided data.
* @param data The new configuration data, excluding the internal version field.
* @returns The updated site configuration.
*/
update: (data: ConfigFinal<StudioCMSSiteConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSSiteConfig> | undefined, Error, never>;
/**
* Initializes the site configuration with the provided data.
* @param data The initial configuration data, excluding the internal version field.
* @returns The created site configuration.
*/
init: (data: ConfigFinal<StudioCMSSiteConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSSiteConfig>, LibSQLClientError, never>;
};
readonly mailerConfig: {
/**
* Retrieves the current mailer configuration.
*/
get: () => Effect.Effect<DynamicConfigEntry<StudioCMSMailerConfig> | undefined, LibSQLClientError, never>;
/**
* Updates the mailer configuration with the provided data.
* @param data The new configuration data, excluding the internal version field.
* @returns The updated mailer configuration.
*/
update: (data: ConfigFinal<StudioCMSMailerConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSMailerConfig> | undefined, Error, never>;
/**
* Initializes the mailer configuration with the provided data.
* @param data The initial configuration data, excluding the internal version field.
* @returns The created mailer configuration.
*/
init: (data: ConfigFinal<StudioCMSMailerConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSMailerConfig>, LibSQLClientError, never>;
};
readonly notificationConfig: {
/**
* Retrieves the current notification settings.
*/
get: () => Effect.Effect<DynamicConfigEntry<StudioCMSNotificationSettings> | undefined, LibSQLClientError, never>;
/**
* Updates the notification settings with the provided data.
* @param data The new notification settings, excluding the `_config_version` property.
* @returns A promise resolving to the updated `StudioCMSNotificationSettings`.
*/
update: (data: ConfigFinal<StudioCMSNotificationSettings>) => Effect.Effect<DynamicConfigEntry<StudioCMSNotificationSettings> | undefined, Error, never>;
/**
* Initializes the notification settings with the provided data.
* @param data The initial configuration data, excluding the internal version field.
* @returns The created notification settings.
*/
init: (data: ConfigFinal<StudioCMSNotificationSettings>) => Effect.Effect<DynamicConfigEntry<StudioCMSNotificationSettings>, LibSQLClientError, never>;
};
readonly templateConfig: {
get: () => Effect.Effect<DynamicConfigEntry<StudioCMSTemplateConfig> | undefined, LibSQLClientError, never>;
update: (data: ConfigFinal<StudioCMSTemplateConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSTemplateConfig>, Error, never>;
init: (data: ConfigFinal<StudioCMSTemplateConfig>) => Effect.Effect<DynamicConfigEntry<StudioCMSTemplateConfig>, LibSQLClientError, never>;
};
}, never, AstroDB | Deepmerge>;
}>;
/**
* Provides configuration management services for StudioCMS using an effect-based service pattern.
*
* This service handles CRUD operations for dynamic configuration entries, supports migration from legacy tables,
* and exposes specialized interfaces for site, mailer, and notification configuration management.
*
* @remarks
* - Uses dependency injection for database and deep merge utilities.
* - Supports versioned dynamic configs and automatic migration from legacy schemas.
* - Exposes effect-based methods for creating, retrieving, updating, and migrating configuration entries.
*
* @example
* ```typescript
* const configService = Effect.service(SDKCore_CONFIG);
* const siteConfig = yield* configService.siteConfig.get();
* yield* configService.siteConfig.update({ ...siteConfig, someField: 'newValue' });
* ```
*
* @service
* @module studiocms/sdk/modules/SDKCore_CONFIG
*/
export declare class SDKCore_CONFIG extends SDKCore_CONFIG_base {
}