studiocms
Version:
Astro Native CMS for AstroDB. Built from the ground up by the Astro community.
359 lines (358 loc) • 20.1 kB
TypeScript
import { Effect } from '../../../effect.js';
import { AstroDB, GetVersionFromNPM, SDKCore_Collectors, SDKCore_FolderTree, SDKCore_Users } from '../effect/index.js';
import { SDKCoreError } from '../errors.js';
import type { CombinedPageData, CombinedUserData, FolderNode, MetaOnlyPageData, MetaOnlyPageDataCacheObject, PageDataCacheObject, PaginateInput } from '../types/index.js';
import { CacheContext } from '../utils.js';
import { SDKCore_CONFIG } from './config.js';
declare const SDKCore_GET_base: Effect.Service.Class<SDKCore_GET, "studiocms/sdk/SDKCore/modules/get", {
readonly dependencies: readonly [import("effect/Layer").Layer<AstroDB, never, never>, import("effect/Layer").Layer<SDKCore_FolderTree, never, never>, import("effect/Layer").Layer<GetVersionFromNPM, never, never>, import("effect/Layer").Layer<SDKCore_Users, never, never>, import("effect/Layer").Layer<SDKCore_Collectors, never, never>, import("effect/Layer").Layer<SDKCore_CONFIG, never, never>];
readonly effect: Effect.Effect<{
databaseTable: {
users: () => Effect.Effect<{
name: string;
password: string | null;
email: string | null;
url: string | null;
id: string;
username: string;
avatar: string | null;
updatedAt: Date | null;
createdAt: Date | null;
emailVerified: boolean;
notifications: string | null;
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
oAuthAccounts: () => Effect.Effect<{
provider: string;
userId: string;
providerUserId: string;
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
sessionTable: () => Effect.Effect<{
id: string;
userId: string;
expiresAt: Date;
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
permissions: () => Effect.Effect<{
user: string;
rank: "unknown" | "owner" | "admin" | "editor" | "visitor";
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
pageData: () => Effect.Effect<{
title: string;
description: string;
slug: string;
id: string;
augments: unknown;
categories: unknown;
updatedAt: Date | null;
package: string;
showOnNav: boolean;
publishedAt: Date;
contentLang: string;
heroImage: string;
tags: unknown;
authorId: string | null;
contributorIds: unknown;
showAuthor: boolean | null;
showContributors: boolean | null;
parentFolder: string | null;
draft: boolean | null;
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
pageDataTags: () => Effect.Effect<{
name: string;
description: string;
slug: string;
id: number;
meta: unknown;
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
pageDataCategories: () => Effect.Effect<{
name: string;
description: string;
slug: string;
id: number;
parent: number | null;
meta: unknown;
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
pageContent: () => Effect.Effect<{
id: string;
contentLang: string;
contentId: string;
content: string | null;
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
diffTracking: () => Effect.Effect<{
id: string;
userId: string;
pageId: string;
timestamp: Date | null;
pageMetaData: unknown;
pageContentStart: string;
diff: string | null;
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
pageFolderStructure: () => Effect.Effect<{
name: string;
id: string;
parent: string | null;
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
notificationSettings: () => Effect.Effect<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
} | undefined, import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
emailVerificationTokens: () => Effect.Effect<{
id: string;
userId: string;
token: string;
expiresAt: Date;
}[], import("@withstudiocms/effect/drizzle").LibSQLClientError, never>;
};
permissionsLists: {
/**
* Retrieves all permissions for users in the database.
*
* @returns A promise that resolves to an array of combined rank data.
* @throws {StudioCMS_SDK_Error} If an error occurs while getting the permissions.
*/
all: () => Effect.Effect<import("../types/tableDefs.js").CombinedRank[], SDKCoreError, never>;
/**
* Retrieves all owners in the database.
*
* @returns A promise that resolves to an array of combined rank data.
* @throws {StudioCMS_SDK_Error} If an error occurs while getting the owners.
*/
owners: () => Effect.Effect<import("../types/tableDefs.js").SingleRank[], SDKCoreError, never>;
/**
* Retrieves all admins in the database.
*
* @returns A promise that resolves to an array of combined rank data.
* @throws {StudioCMS_SDK_Error} If an error occurs while getting the admins.
*/
admins: () => Effect.Effect<import("../types/tableDefs.js").SingleRank[], SDKCoreError, never>;
/**
* Retrieves all editors in the database.
*
* @returns A promise that resolves to an array of combined rank data.
* @throws {StudioCMS_SDK_Error} If an error occurs while getting the editors.
*/
editors: () => Effect.Effect<import("../types/tableDefs.js").SingleRank[], SDKCoreError, never>;
/**
* Retrieves all visitors in the database.
*
* @returns A promise that resolves to an array of combined rank data.
* @throws {StudioCMS_SDK_Error} If an error occurs while getting the visitors.
*/
visitors: () => Effect.Effect<import("../types/tableDefs.js").SingleRank[], SDKCoreError, never>;
};
users: {
/**
* Retrieves all users from the database.
*
* @returns A promise that resolves to an array of combined user data.
* @throws {StudioCMS_SDK_Error} If an error occurs while getting the users.
*/
all: () => Effect.Effect<CombinedUserData[], SDKCoreError, never>;
/**
* Retrieves a user by ID.
*
* @param id - The ID of the user to retrieve.
* @returns A promise that resolves to the user data.
* @throws {StudioCMS_SDK_Error} If an error occurs while getting the user.
*/
byId: (id: string) => Effect.Effect<CombinedUserData | undefined, SDKCoreError, never>;
/**
* Retrieves a user by username.
*
* @param username - The username of the user to retrieve.
* @returns A promise that resolves to the user data.
* @throws {StudioCMS_SDK_Error} If an error occurs while getting the user.
*/
byUsername: (username: string) => Effect.Effect<CombinedUserData | undefined, SDKCoreError, never>;
/**
* Retrieves a user by email.
*
* @param email - The email of the user to retrieve.
* @returns A promise that resolves to the user data.
* @throws {StudioCMS_SDK_Error} If an error occurs while getting the user.
*/
byEmail: (email: string) => Effect.Effect<CombinedUserData | undefined, SDKCoreError, never>;
};
/**
* Retrieves a folder by ID.
*
* @param id - The ID of the folder to retrieve.
* @returns A promise that resolves to the folder data.
* @throws {StudioCMS_SDK_Error} If an error occurs while getting the folder.
*/
folder: (input: string) => Effect.Effect<{
name: string;
id: string;
parent: string | null;
} | undefined, SDKCoreError, never>;
/**
* Retrieves the site configuration, with caching support.
* If caching is enabled, it checks the cache for an existing site config.
* If the cache is expired or not available, it fetches the site config from the database
* and updates the cache.
* @returns An `Effect` that yields the site config.
* @throws UnknownException - If an unknown error occurs during retrieval.
* @throws LibSQLDatabaseError - If a database error occurs during retrieval.
*/
siteConfig: () => Effect.Effect<import("../types/index.js").SiteConfigCacheObject | undefined, SDKCoreError, never>;
/**
* Retrieves the folder tree structure, with caching support.
* If caching is enabled, it checks the cache for an existing folder tree.
* If the cache is expired or not available, it fetches the folder tree from the database
* and updates the cache.
* @returns An `Effect` that yields the folder tree.
* @throws UnknownException - If an unknown error occurs during retrieval.
* @throws LibSQLDatabaseError - If a database error occurs during retrieval.
*/
folderTree: () => Effect.Effect<import("../types/index.js").FolderTreeCacheObject, SDKCoreError, never>;
/**
* Retrieves the folder tree structure, with caching support.
* If caching is enabled, it checks the cache for an existing folder tree.
* If the cache is expired or not available, it fetches the folder tree from the database
* and updates the cache.
* @returns An `Effect` that yields the folder tree.
* @throws UnknownException - If an unknown error occurs during retrieval.
* @throws LibSQLDatabaseError - If a database error occurs during retrieval.
*/
pageFolderTree: (hideDefaultIndex?: boolean) => Effect.Effect<import("../types/index.js").FolderTreeCacheObject, SDKCoreError, never>;
/**
* Retrieves a list of available folders, with caching support.
* If caching is enabled, it checks the cache for an existing folder list.
* If the cache is expired or not available, it fetches the folder list from the database
* and updates the cache.
* @returns An `Effect` that yields the folder list.
* @throws UnknownException - If an unknown error occurs during retrieval.
* @throws LibSQLDatabaseError - If a database error occurs during retrieval.
*/
folderList: () => Effect.Effect<import("../types/index.js").FolderListCacheObject, SDKCoreError, never>;
/**
* Retrieves the latest version of StudioCMS from NPM, with caching support.
* @returns An `Effect` that yields the latest version of StudioCMS.
* @throws UnknownException - If an unknown error occurs during retrieval.
*/
latestVersion: () => Effect.Effect<import("../types/index.js").VersionCacheObject, SDKCoreError | import("@effect/platform/HttpClientError").HttpClientError | import("effect/ParseResult").ParseError, never>;
page: {
/**
* Retrieves a page by its ID, with an option to return only metadata.
*
* @param id - The ID of the page to retrieve.
* @param metaOnly - If `true`, returns only metadata for the page. Defaults to `false`.
* @returns An `Effect` that yields the page data or metadata, depending on `metaOnly`.
*
* @throws UnknownException - If an unknown error occurs during retrieval.
* @throws LibSQLDatabaseError - If a database error occurs during retrieval.
*/
byId: {
(id: string): Effect.Effect<PageDataCacheObject | undefined, SDKCoreError, never>;
(id: string, metaOnly?: boolean): Effect.Effect<MetaOnlyPageDataCacheObject | undefined, SDKCoreError, never>;
};
/**
* Retrieves a page by its slug, with an option to return only metadata.
*
* @param slug - The slug of the page to retrieve.
* @param metaOnly - If `true`, returns only metadata for the page. Defaults to `false`.
* @returns An `Effect` that yields the page data or metadata, depending on `metaOnly`.
*
* @throws UnknownException - If an unknown error occurs during retrieval.
* @throws LibSQLDatabaseError - If a database error occurs during retrieval.
*/
bySlug: {
(slug: string): Effect.Effect<PageDataCacheObject | undefined, SDKCoreError, never>;
(slug: string, metaOnly?: boolean): Effect.Effect<MetaOnlyPageDataCacheObject | undefined, SDKCoreError, never>;
};
};
/**
* Retrieves pages within a specified folder by its ID or name, supporting various filtering and pagination options.
*
* This function handles both cached and non-cached scenarios, fetching pages from the database or cache as appropriate.
* It supports filtering drafts, hiding default index pages, returning only metadata, and paginating results.
*
* @param idOrName - The ID or name of the folder to retrieve pages from.
* @param includeDrafts - Whether to include draft pages in the results. Defaults to `false`.
* @param hideDefaultIndex - Whether to exclude default index pages from the results. Defaults to `false`.
* @param metaOnly - If `true`, returns only metadata for each page. Defaults to `false`.
* @param paginate - Optional pagination input specifying `limit` and `offset`.
* @returns An `Effect` that yields an array of page data or metadata, depending on `metaOnly`.
*
* @throws UnknownException - If an unknown error occurs during retrieval.
* @throws LibSQLDatabaseError - If a database error occurs during retrieval.
*/
folderPages: {
(idOrName: string, includeDrafts?: boolean, hideDefaultIndex?: boolean, metaOnly?: false, paginate?: PaginateInput): Effect.Effect<PageDataCacheObject[], SDKCoreError, never>;
(idOrName: string, includeDrafts?: boolean, hideDefaultIndex?: boolean, metaOnly?: true, paginate?: PaginateInput): Effect.Effect<MetaOnlyPageDataCacheObject[], SDKCoreError, never>;
};
/**
* Retrieves all pages associated with a given package name, optionally using a provided folder tree and returning only metadata if specified.
*
* @param packageName - The name of the package to fetch pages for.
* @param tree - Optional. A pre-built folder tree to use for organizing pages. If not provided, the folder tree will be built automatically.
* @param metaOnly - Optional. If true, returns only metadata for each page; otherwise, returns combined page data. Defaults to false.
* @returns An Effect that resolves to an array of page data, either as `MetaOnlyPageData[]` or `CombinedPageData[]` depending on `metaOnly`.
*/
packagePages: {
(packageName: string, tree?: FolderNode[]): Effect.Effect<CombinedPageData[], SDKCoreError, never>;
(packageName: string, tree?: FolderNode[], metaOnly?: boolean): Effect.Effect<MetaOnlyPageData[], SDKCoreError, never>;
};
/**
* Retrieves all pages from the database or cache, with options for including drafts,
* hiding the default index page, returning only metadata, and paginating results.
*
* - If caching is enabled, attempts to return cached pages and updates expired cache entries.
* - If caching is disabled, fetches pages directly from the database.
* - Supports filtering by draft status and default index visibility.
* - Can return either full page data or metadata only.
* - Supports pagination via the `paginate` parameter.
*
* @param includeDrafts - Whether to include draft pages in the results. Defaults to `false`.
* @param hideDefaultIndex - Whether to exclude the default index page from the results. Defaults to `false`.
* @param metaOnly - Whether to return only metadata for each page. Defaults to `false`.
* @param paginate - Optional pagination input specifying `limit` and `offset`.
* @returns An `Effect` that yields an array of page data or metadata, depending on `metaOnly`.
*/
pages: {
(includeDrafts?: boolean, hideDefaultIndex?: boolean, metaOnly?: false, paginate?: PaginateInput): Effect.Effect<PageDataCacheObject[], SDKCoreError, never>;
(includeDrafts?: boolean, hideDefaultIndex?: boolean, metaOnly?: true, paginate?: PaginateInput): Effect.Effect<MetaOnlyPageDataCacheObject[], SDKCoreError, never>;
};
}, never, AstroDB | SDKCore_CONFIG | SDKCore_FolderTree | SDKCore_Users | SDKCore_Collectors | CacheContext | GetVersionFromNPM>;
}>;
/**
* The `SDKCore_GET` service provides a comprehensive set of data retrieval methods for the StudioCMS SDK.
* It encapsulates database queries, caching logic, and transformation utilities for core CMS entities such as pages, users, folders, permissions, and site configuration.
*
* @remarks
* - All methods are wrapped in `Effect` for composable error handling and dependency injection.
* - Caching is used for performance optimization, with cache invalidation and fallback to database queries.
* - Pagination, filtering, and meta-only retrieval are supported for page queries.
*
* @example
* ```typescript
* const pages = yield* GET.pages();
* const user = yield* GET.users.byId("user-id");
* const folderTree = yield* GET.folderTree();
* ```
*
* @service studiocms/sdk/SDKCore/modules/get
* @dependencies
* - AstroDB.Default
* - SDKCore_FolderTree.Default
* - GetVersionFromNPM.Default
* - SDKCore_Users.Default
* - SDKCore_Collectors.Default
*
* @effect
* Provides the following main query groups:
* - `databaseTable`: Direct access to raw database tables.
* - `permissionsLists`: Retrieve users by permission rank.
* - `users`: Retrieve user data by various identifiers.
* - `folder`, `folderTree`, `folderList`, `pageFolderTree`: Folder and tree structure queries.
* - `siteConfig`, `latestVersion`: Site configuration and version info.
* - `page`: Retrieve page data by ID or slug.
* - `folderPages`, `packagePages`, `pages`: Retrieve pages by folder, package, or all pages.
*
* @throws {SDKCoreError} If a database or unknown error occurs during retrieval.
*/
export declare class SDKCore_GET extends SDKCore_GET_base {
}
export {};