UNPKG

alinea

Version:
1,558 lines (1,293 loc) 362 kB
declare module 'alinea/adapter/core/cms' { import { CMS } from 'alinea/core/CMS'; import type { Config } from 'alinea/core/Config'; import type { UploadResponse } from 'alinea/core/Connection'; import type { AnyQueryResult, GraphQuery } from 'alinea/core/Graph'; import type { Mutation } from 'alinea/core/db/Mutation'; export class CoreCMS<Definition extends Config = Config> extends CMS<Definition> { sync(): Promise<string>; resolve<Query extends GraphQuery>(query: Query): Promise<AnyQueryResult<Query>>; mutate(mutations: Array<Mutation>): Promise<{ sha: string; }>; prepareUpload(file: string): Promise<UploadResponse>; } export function createCMS<Definition extends Config>(config: Definition): CoreCMS<Definition>; } declare module 'alinea/adapter/core/handler' { export { createHandler } from 'alinea/backend/Handler'; } declare module 'alinea/adapter/core/preview' { import type { CoreCMS } from 'alinea/adapter/core/cms'; export function preview<T>(cms: CoreCMS, request: Request, run: () => Promise<T>): Promise<T>; } declare module 'alinea/adapter/core/previewContext' { import type { AsyncLocalStorage } from 'node:async_hooks'; import type { ConnectionContext } from 'alinea/core/CMS'; import type { CoreCMS } from 'alinea/adapter/core/cms'; export const previewStore: WeakMap<CoreCMS<import("alinea/core/Config").Config>, AsyncLocalStorage<ConnectionContext>>; export function previewContext(cms: CoreCMS): ConnectionContext; } declare module 'alinea/adapter/next/cms' { import { CMS } from 'alinea/core/CMS'; import type { Config } from 'alinea/core/Config'; import type { UploadResponse } from 'alinea/core/Connection'; import type { Mutation } from 'alinea/core/db/Mutation'; import type { GraphQuery } from 'alinea/core/Graph'; import type { User } from 'alinea/core/User'; export interface PreviewProps { widget?: boolean; workspace?: string; root?: string; } export class NextCMS<Definition extends Config = Config> extends CMS<Definition> { #private; constructor(config: Definition); resolve<Query extends GraphQuery>(query: Query): Promise<any>; user(): Promise<User | undefined>; mutate(mutations: Array<Mutation>): Promise<{ sha: string; }>; prepareUpload(file: string): Promise<UploadResponse>; previews: ({ widget, workspace, root }: PreviewProps) => Promise<import("react/jsx-runtime").JSX.Element | null>; } export function createCMS<Definition extends Config>(config: Definition): NextCMS<Definition>; } declare module 'alinea/adapter/next/context' { import { Config } from 'alinea/core/Config'; import type { RequestContext } from 'alinea/core/Connection'; export function requestContext(config: Config): Promise<RequestContext>; } declare module 'alinea/adapter/next/handler' { import { type BackendOptions } from 'alinea/backend/api/CreateBackend'; import { type HandlerHooks } from 'alinea/backend/Handler'; import type { RemoteConnection, RequestContext } from 'alinea/core/Connection'; import { NextCMS } from 'alinea/adapter/next/cms'; type Handler = (request: Request) => Promise<Response>; export interface NextHandlerOptions extends HandlerHooks { cms: NextCMS; backend?: BackendOptions; remote?: (context: RequestContext) => RemoteConnection; } export function createHandler(input: NextCMS | NextHandlerOptions): Handler; export {}; } declare module 'alinea/adapter/next/previews' { export interface NextPreviewsProps { dashboardUrl: string; widget?: boolean; root?: string; workspace?: string; } export default function NextPreviews({ dashboardUrl, widget, root, workspace }: NextPreviewsProps): import("react/jsx-runtime").JSX.Element | null; /** * Wrapper around `router.refresh()` from `next/navigation` `useRouter()` to return Promise, and resolve after refresh completed * @returns Refresh function */ export function useRouterRefresh(): () => Promise<unknown>; } declare module 'alinea/adapter/next/with-alinea' { import type { NextConfig } from 'next/dist/types.js'; export function createCMS(): void; export function withAlinea(config: NextConfig): NextConfig; } declare module 'alinea/backend/api/BasicAuth' { import type { AuthApi, AuthedContext, RequestContext } from 'alinea/core/Connection'; export interface Verifier { (username: string, password: string): boolean | Promise<boolean>; } export class BasicAuth implements AuthApi { #private; constructor(context: RequestContext, verify: Verifier); authenticate(request: Request): Promise<Response>; verify(request: Request): Promise<AuthedContext>; } } declare module 'alinea/backend/api/CreateBackend' { import type { Config } from 'alinea/core/Config'; import type { RemoteConnection, RequestContext } from 'alinea/core/Connection'; import * as driver from 'rado/driver'; import { type GithubOptions } from 'alinea/backend/api/GithubApi'; import { type OAuth2Options } from 'alinea/backend/api/OAuth2'; export type AvailableDrivers = 'd1' | 'mysql2' | '@neondatabase/serverless' | '@vercel/postgres' | 'pg' | '@electric-sql/pglite' | 'sql.js' | '@libsql/client'; type DatabaseClient<Driver extends AvailableDrivers> = Parameters<(typeof driver)[Driver]>[0]; type DatabaseOption<Driver extends AvailableDrivers> = { driver: Driver; client: DatabaseClient<Driver>; }; export type DatabaseDeclaration = DatabaseOption<'d1'> | DatabaseOption<'mysql2'> | DatabaseOption<'@neondatabase/serverless'> | DatabaseOption<'@vercel/postgres'> | DatabaseOption<'pg'> | DatabaseOption<'@electric-sql/pglite'> | DatabaseOption<'sql.js'> | DatabaseOption<'@libsql/client'>; export interface BackendOptions { auth?(username: string, password: string): boolean | Promise<boolean>; oauth2?: OAuth2Options; database: DatabaseDeclaration; github: GithubOptions; } export function createBackend(config: Config, options: BackendOptions): (context: RequestContext) => RemoteConnection; export function createRemote(...impl: Array<Partial<RemoteConnection>>): RemoteConnection; export {}; } declare module 'alinea/backend/api/DatabaseApi' { import type { DraftsApi, RequestContext, UploadResponse, UploadsApi } from 'alinea/core/Connection'; import { type Draft, type DraftKey } from 'alinea/core/Draft'; import { type Database } from 'rado'; export interface DatabaseOptions { db: Database; } export class DatabaseApi implements DraftsApi, UploadsApi { #private; constructor(context: RequestContext, { db }: DatabaseOptions); getDraft(draftKey: DraftKey): Promise<Draft | undefined>; storeDraft(draft: Draft): Promise<void>; prepareUpload(file: string): Promise<UploadResponse>; handleUpload(entryId: string, file: Blob): Promise<void>; previewUpload(entryId: string): Promise<Response>; } } declare module 'alinea/backend/api/GithubApi' { import type { CommitApi, HistoryApi, Revision, SyncApi } from 'alinea/core/Connection'; import type { EntryRecord } from 'alinea/core/EntryRecord'; import type { CommitRequest } from 'alinea/core/db/CommitRequest'; import { GithubSource, type GithubSourceOptions } from 'alinea/core/source/GithubSource'; export interface GithubOptions extends GithubSourceOptions { author?: { name: string; email: string; }; } export class GithubApi extends GithubSource implements HistoryApi, CommitApi, SyncApi { #private; constructor(options: GithubOptions); write(request: CommitRequest): Promise<{ sha: string; }>; revisions(file: string): Promise<Array<Revision>>; revisionData(file: string, revisionId: string): Promise<EntryRecord | undefined>; } } declare module 'alinea/backend/api/OAuth2' { import { Request, Response } from '@alinea/iso'; import type { Config } from 'alinea/core/Config'; import type { AuthApi, AuthedContext, RequestContext } from 'alinea/core/Connection'; export interface OAuth2Options { /** * OAuth2 clientId */ clientId: string; /** * OAuth2 clientSecret * * This is required when using the 'client_secret_basic' authenticationMethod * for the client_credentials and password flows, but not authorization_code * or implicit. */ clientSecret?: string; /** * The JSON Web Key Set (JWKS) URI. */ jwksUri: string; /** * The /authorize endpoint. * * Required only for the browser-portion of the authorization_code flow. */ authorizationEndpoint: string; /** * The token endpoint. * * Required for most grant types and refreshing tokens. */ tokenEndpoint: string; /** * Revocation endpoint. * * Required for revoking tokens. Not supported by all servers. */ revocationEndpoint?: string; } export class OAuth2 implements AuthApi { #private; constructor(context: RequestContext, config: Config, options: OAuth2Options); authenticate(request: Request): Promise<Response>; verify(request: Request): Promise<AuthedContext>; } } declare module 'alinea/backend/Auth' { import { HttpError } from 'alinea/core/HttpError'; export enum AuthAction { Status = "status", Handshake = "handshake", Login = "login", Logout = "logout", Refresh = "refresh" } export class AuthError extends HttpError { name: string; constructor(message: string, options?: ErrorOptions); } export class MissingCredentialsError extends AuthError { name: string; } export class InvalidCredentialsError extends AuthError { name: string; } } declare module 'alinea/backend/HandleAction' { export enum HandleAction { Auth = "auth", User = "user", Resolve = "resolve", Pending = "pending", Sync = "sync", Draft = "draft", History = "history", PreviewToken = "previewToken", Mutate = "mutate", Upload = "upload", Tree = "tree", Commit = "commit", Blob = "blob" } } declare module 'alinea/backend/Handler' { import type { Entry } from 'alinea/core'; import type { CMS } from 'alinea/core/CMS'; import type { RemoteConnection, RequestContext } from 'alinea/core/Connection'; import type { LocalDB } from 'alinea/core/db/LocalDB'; export interface Handler { (request: Request, context: RequestContext): Promise<Response>; } export type HookResponse<T = void> = void | T | Promise<T> | Promise<void>; export interface HandlerHooks { beforeCreate?(entry: Entry): HookResponse<Entry>; afterCreate?(entry: Entry): HookResponse; beforeUpdate?(entry: Entry): HookResponse<Entry>; afterUpdate?(entry: Entry): HookResponse; beforeArchive?(entryId: string): HookResponse; afterArchive?(entryId: string): HookResponse; beforeRemove?(entryId: string): HookResponse; afterRemove?(entryId: string): HookResponse; } export interface HandlerOptions extends HandlerHooks { cms: CMS; db: LocalDB | Promise<LocalDB>; remote?: (context: RequestContext) => RemoteConnection; } export function createHandler({ cms, remote, db, ...hooks }: HandlerOptions): Handler; } declare module 'alinea/backend/Loader' { import type { EntryRecord } from 'alinea/core/EntryRecord'; import type { Schema } from 'alinea/core/Schema'; export interface Loader { extension: string; parse(schema: Schema, input: Uint8Array): EntryRecord; format(schema: Schema, entry: EntryRecord): Uint8Array; } } declare module 'alinea/backend/loader/JsonLoader' { import type { Loader } from 'alinea/backend/Loader'; export const JsonLoader: Loader; } declare module 'alinea/backend/Previews' { export interface PreviewInfo { url: string; } export interface Previews { sign(data: PreviewInfo): Promise<string>; verify(token: string): Promise<PreviewInfo>; } } declare module 'alinea/backend/resolver/ParsePreview' { import type { LocalDB } from 'alinea/core/db/LocalDB'; import type { PreviewRequest } from 'alinea/core/Preview'; export function createPreviewParser(local: LocalDB): { parse(preview: PreviewRequest, sync: () => Promise<unknown>): Promise<PreviewRequest | undefined>; }; } declare module 'alinea/backend/router/NodeHandler' { import { Request, type Response } from '@alinea/iso'; import type http from 'node:http'; export function respondTo(to: http.ServerResponse, response: Response): Promise<void>; export function fromNodeRequest(request: http.IncomingMessage): globalThis.Request; export function nodeHandler(handler: (request: Request) => Promise<Response | undefined> | Response | undefined): (req: http.IncomingMessage, res: http.ServerResponse, next?: () => void) => Promise<void>; } declare module 'alinea/backend/router/Router' { import { type Request, Response } from '@alinea/iso'; export interface HttpRouter { (input: Request): Promise<Response>; } export interface Handle<In, Out> { (input: In): Out | undefined | Promise<Out | undefined>; } type Next<In, Out> = Handle<In, Out> | Route<In, Out>; export class Route<In, Out> { handle: Handle<In, Out>; constructor(handle: Handle<In, Out>); map<T>(next: Handle<Out, T>): Route<In, T>; map<T>(next: Route<Out, T>): Route<In, T>; notFound(handler: (input: In) => Out | Promise<Out>): Route<In, Out>; recover(handler: (error: Error) => Out | Promise<Out>): Route<In, Out>; } export function router(...routes: Array<Next<Request, Response | undefined> | undefined>): Route<Request, Response | undefined>; export namespace router { function use<In, Out>(handle: Handle<In, Out>): Route<In, Out>; function matcher(getPathname?: (url: URL) => string): { get(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; post(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; put(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; delete(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; all(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; }; function base(url: string): { get(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; post(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; put(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; delete(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; all(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; }; const queryMatcher: { get(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; post(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; put(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; delete(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; all(path: string): Route<globalThis.Request, { request: globalThis.Request; url: URL; params: Record<string, unknown>; }>; }; function parseFormData<In extends { request: Request; }>(input: In): Promise<In & { body: FormData; }>; function parseBuffer<In extends { request: Request; }>(input: In): Promise<In & { body: ArrayBuffer; }>; function parseJson<In extends { request: Request; }>(input: In): Promise<In & { body: unknown; }>; function reportError(error: any): globalThis.Response; function redirect(url: URL | string, init?: ResponseInit): globalThis.Response; type Cookie = { name: string; value: string; expires?: Date; maxAge?: number; domain?: string; path?: string; secure?: boolean; httpOnly?: boolean; sameSite?: 'strict' | 'lax' | 'none'; }; function cookie(...cookies: Array<Cookie>): string; function compress(...routes: Array<Next<Request, Response | undefined>>): Route<Request, Response | undefined>; } export {}; } declare module 'alinea/backend/router/Router.test' { export {}; } declare module 'alinea/backend/store/GeneratedRelease' { export const generatedRelease: Promise<string>; } declare module 'alinea/backend/store/GeneratedSource' { import { MemorySource } from 'alinea/core/source/MemorySource'; export const generatedSource: Promise<MemorySource>; } declare module 'alinea/backend/util/ExecGit' { import PLazy from 'p-lazy'; export function execGit(cwd: string, args: string[]): Promise<string>; export function gitUser(cwd: string): PLazy<{ name: string; email: string; sub: string; }>; } declare module 'alinea/backend/util/JsonPatch' { export function applyJsonPatch(source: any, patch: object): any; } declare module 'alinea/backend/util/JWTPreviews' { import type { PreviewInfo, Previews } from 'alinea/backend/Previews'; export class JWTPreviews implements Previews { private secret; constructor(secret: string); sign(data: PreviewInfo): Promise<string>; verify(token: string): Promise<PreviewInfo>; } } declare module 'alinea/backend/util/ORM' { import { type Sql } from 'rado'; import { type Input } from 'rado/core/expr/Input'; export function is<T>(a: Input<T>, b: Input<T>): Sql<boolean>; export function values<const Values extends Array<Input>>(...rows: Array<Values>): Sql<Array<Values>>; } declare module 'alinea/cli' { import 'alinea/cli/bin'; } declare module 'alinea/cli/bin' { export {}; } declare module 'alinea/cli/build/BuildEmitter' { import { type BuildOptions, type BuildResult } from 'esbuild'; import { type Emitter } from 'alinea/cli/util/Emitter'; export type BuildInfo = { type: 'start'; result: undefined; } | { type: 'done'; result: BuildResult; }; export function buildEmitter(config: BuildOptions): Emitter<BuildInfo>; } declare module 'alinea/cli/build/BuildOptions' { import type { BuildOptions } from 'esbuild'; export const buildOptions: BuildOptions; } declare module 'alinea/cli/Generate' { import type { CMS } from 'alinea/core/CMS'; import { DevDB } from 'alinea/cli/generate/DevDB'; export interface GenerateOptions { cmd: 'dev' | 'build'; cwd?: string; staticDir?: string; configFile?: string; watch?: boolean; fix?: boolean; wasmCache?: boolean; quiet?: boolean; onAfterGenerate?: (buildMessage: string) => void; dashboardUrl?: Promise<string>; } export function generate(options: GenerateOptions): AsyncGenerator<{ cms: CMS; db: DevDB; }, void>; } declare module 'alinea/cli/generate/CompileConfig' { import type { GenerateContext } from 'alinea/cli/generate/GenerateContext'; export function compileConfig(ctx: GenerateContext): AsyncGenerator<import("alinea/core/CMS").CMS<import("alinea/core/Config").Config>, void, unknown>; } declare module 'alinea/cli/generate/CopyStaticFiles' { import type { GenerateContext } from 'alinea/cli/generate/GenerateContext'; export function copyStaticFiles({ outDir }: GenerateContext): Promise<void>; } declare module 'alinea/cli/generate/DevDB' { import { Config } from 'alinea/core/Config'; import type { UploadResponse } from 'alinea/core/Connection'; import { type CommitRequest } from 'alinea/core/db/CommitRequest'; import { LocalDB } from 'alinea/core/db/LocalDB'; import { CachedFSSource } from 'alinea/core/source/FSSource'; export interface DevDBOptions { config: Config; rootDir: string; dashboardUrl: string | undefined; } export interface WatchFiles { files: Array<string>; dirs: Array<string>; } export class DevDB extends LocalDB { #private; source: CachedFSSource; constructor(options: DevDBOptions); sync(): Promise<string>; fix(): Promise<void>; watchFiles(): Promise<WatchFiles>; isInMediaLocation(file: string): boolean; write(request: CommitRequest): Promise<{ sha: string; }>; prepareUpload(file: string): Promise<UploadResponse>; } } declare module 'alinea/cli/generate/FillCache' { import { type Emitter } from 'alinea/cli/util/Emitter'; import type { DevDB } from 'alinea/cli/generate/DevDB'; export function fillCache(db: DevDB, fix?: boolean): Emitter<DevDB>; } declare module 'alinea/cli/generate/GenerateContext' { export interface GenerateContext { cmd: 'dev' | 'build'; wasmCache: boolean; rootDir: string; configLocation: string; configDir: string; staticDir: string; quiet: boolean; outDir: string; fix: boolean; } } declare module 'alinea/cli/generate/GenerateDashboard' { import type { CMS } from 'alinea/core/CMS'; import type { GenerateContext } from 'alinea/cli/generate/GenerateContext'; export function generateDashboard({ configLocation, rootDir, configDir }: GenerateContext, cms: CMS, handlerUrl: string, staticFile: string): Promise<void>; } declare module 'alinea/cli/generate/LoadConfig' { import { CMS } from 'alinea/core/CMS'; export function loadCMS(outDir: string): Promise<CMS>; } declare module 'alinea/cli/Init' { export type InitOptions = { cwd?: string; quiet?: boolean; next?: boolean; }; export function init(options: InitOptions): Promise<void>; } declare module 'alinea/cli/Init.test' { export {}; } declare module 'alinea/cli/Serve' { import type { BuildOptions } from 'esbuild'; export type ServeOptions = { cmd: 'dev' | 'build'; cwd?: string; base?: string; staticDir?: string; configFile?: string; port?: number; buildOptions?: BuildOptions; alineaDev?: boolean; production?: boolean; onAfterGenerate?: (env?: Record<string, string>) => void; }; export function serve(options: ServeOptions): Promise<void>; } declare module 'alinea/cli/serve/CreateLocalServer' { import { type Request, Response } from '@alinea/iso'; import type { Handler } from 'alinea/backend/Handler'; import type { CMS } from 'alinea/core/CMS'; import type { User } from 'alinea/core/User'; import type { ServeContext } from 'alinea/cli/serve/ServeContext'; export function createLocalServer({ cmd, configLocation, rootDir, staticDir, alineaDev, buildOptions, production, liveReload, buildId }: ServeContext, cms: CMS, handleApi: Handler, user: User): { close(): void; handle(input: Request): Promise<Response>; }; } declare module 'alinea/cli/serve/GitHistory' { import type { Config } from 'alinea/core/Config'; import type { Revision } from 'alinea/core/Connection'; import type { HistoryApi } from 'alinea/core/Connection'; import type { EntryRecord } from 'alinea/core/EntryRecord'; export class GitHistory implements HistoryApi { config: Config; rootDir: string; constructor(config: Config, rootDir: string); revisions(file: string): Promise<Array<Revision>>; revisionData(file: string, ref: string): Promise<EntryRecord>; } } declare module 'alinea/cli/serve/LiveReload' { type Client = { write(value: string): void; close(): void; }; export class LiveReload { clients: Array<Client>; reload(type: 'refetch' | 'refresh' | 'reload'): void; register(client: Client): void; } export {}; } declare module 'alinea/cli/serve/LocalAuth' { import type { AuthApi, AuthedContext, RequestContext } from 'alinea/core/Connection'; import type { User } from 'alinea/core/User'; export class LocalAuth implements AuthApi { #private; constructor(context: RequestContext, user: Promise<User>); authenticate(): Promise<Response>; verify(request: Request): Promise<AuthedContext>; } } declare module 'alinea/cli/serve/MemoryDrafts' { import type { DraftsApi } from 'alinea/core/Connection'; import type { Draft } from 'alinea/core/Draft'; export class MemoryDrafts implements DraftsApi { drafts: Map<string, Draft>; getDraft(entryId: string): Promise<Draft | undefined>; storeDraft(draft: Draft): Promise<void>; } } declare module 'alinea/cli/serve/ServeContext' { import type { BuildOptions } from 'esbuild'; import type { LiveReload } from 'alinea/cli/serve/LiveReload'; export interface ServeContext { cmd: 'dev' | 'build'; configLocation: string; rootDir: string; base: string | undefined; staticDir: string; alineaDev: boolean; buildOptions: BuildOptions; production: boolean; liveReload: LiveReload; buildId: string; } } declare module 'alinea/cli/serve/StartServer' { import type { Request, Response } from '@alinea/iso'; interface RequestEvent { request: Request; respondWith(response: Response): Promise<void>; } export interface Server { port: number; serve(abortController?: AbortController): AsyncIterable<RequestEvent>; close(): void; } function startBunServer(port?: number, attempt?: number, silent?: boolean): Promise<Server>; export const startServer: typeof startBunServer; export {}; } declare module 'alinea/cli/Upgrade' { export function upgrade(): Promise<void>; } declare module 'alinea/cli/util/CommitMessage' { export function parseCoAuthoredBy(commitMessage: string): { email: string; name: string; } | undefined; } declare module 'alinea/cli/util/CommitMessage.test' { export {}; } declare module 'alinea/cli/util/CommitSha' { export function getCommitSha(): string | undefined; } declare module 'alinea/cli/util/Dirname' { export function dirname(url?: string): string; export function filename(url?: string): string; } declare module 'alinea/cli/util/Emitter' { export interface Emitter<T> extends AsyncIterable<T> { emit(value: T): void; throw(error: any): void; return(): void; } export interface EmitterOptions { onReturn?: () => void; onThrow?: (error: any) => void; } export function createEmitter<T>({ onReturn, onThrow }?: EmitterOptions): Emitter<T>; } declare module 'alinea/cli/util/EnsureEnv' { export function ensureEnv(cwd?: string): void; } declare module 'alinea/cli/util/EnsureLibs' { export function ensureLibs(libs: Record<string, string>): void; } declare module 'alinea/cli/util/EnsureNode' { export function ensureNode(): void; } declare module 'alinea/cli/util/ExternalPlugin' { import type { Plugin } from 'esbuild'; export function externalPlugin(cwd: string): Plugin; } declare module 'alinea/cli/util/FindConfigFile' { export function findConfigFile(cwd: string): string | undefined; } declare module 'alinea/cli/util/ForwardCommand' { export function forwardCommand(env?: Record<string, string>): boolean; } declare module 'alinea/cli/util/FS' { export function copyFileIfContentsDiffer(source: string, target: string): Promise<void>; export function writeFileIfContentsDiffer(destination: string, contents: string | Buffer): Promise<void>; } declare module 'alinea/cli/util/IgnorePlugin' { import type { Plugin } from 'esbuild'; export const ignorePlugin: Plugin; } declare module 'alinea/cli/util/PublicDefines' { export function publicDefines(environment: typeof process.env): { [k: string]: string; }; } declare module 'alinea/cli/util/Report' { export function reportWarning(...messages: Array<string>): void; export function reportFatal(...messages: Array<string>): void; export function reportError(error: Error): void; export const red: (input: string) => string; export const gray: (input: string) => string; export const cyan: (input: string) => string; export const yellow: (input: string) => string; export const bold: (input: string) => string; export const redBg: (input: string) => string; } declare module 'alinea/cli/util/ViewsPlugin' { import type { CMS } from 'alinea/core/CMS'; import type { Plugin } from 'esbuild'; export function viewsPlugin(rootDir: string, cms: CMS): Plugin; export namespace viewsPlugin { const entry = "#alinea/views"; } } declare module 'alinea/cli/util/WarnPublicEnv' { const mockProcess: { env: any; }; export { mockProcess as process }; } declare module 'alinea/cli/util/Watcher' { interface ToWatch { dirs: Array<string>; files: Array<string>; } export interface WatchOptions { watchFiles(): Promise<ToWatch>; onChange(): void; } export function createWatcher(options: WatchOptions): Promise<() => void>; export {}; } declare module 'alinea/cloud/AuthResult' { import type { User } from 'alinea/core/User'; export enum AuthResultType { Authenticated = 0, UnAuthenticated = 1, MissingApiKey = 2, NeedsRefresh = 3 } export type AuthResult = { type: AuthResultType.Authenticated; user: User; } | { type: AuthResultType.UnAuthenticated; redirect: string; } | { type: AuthResultType.MissingApiKey; setupUrl: string; } | { type: AuthResultType.NeedsRefresh; }; } declare module 'alinea/cloud/CloudConfig' { export const cloudUrl: string; export const cloudConfig: { url: string; jwks: string; setup: string; handshake: string; upload: string; logout: string; history: string; drafts: string; tree: string; blobs: string; write: string; auth: string; token: string; revocation: string; }; } declare module 'alinea/cloud/CloudRemote' { import { OAuth2 } from 'alinea/backend/api/OAuth2'; import { Config } from 'alinea/core/Config'; import type { RemoteConnection, RequestContext, Revision } from 'alinea/core/Connection'; import { type Draft, type DraftKey } from 'alinea/core/Draft'; import type { CommitRequest } from 'alinea/core/db/CommitRequest'; import type { EntryRecord } from 'alinea/core/EntryRecord'; import { ReadonlyTree } from 'alinea/core/source/Tree'; export class CloudRemote extends OAuth2 implements RemoteConnection { #private; constructor(context: RequestContext, config: Config); getTreeIfDifferent(sha: string): Promise<ReadonlyTree | undefined>; getBlobs(shas: Array<string>): AsyncGenerator<[sha: string, blob: Uint8Array]>; write(request: CommitRequest): Promise<{ sha: string; }>; authenticate(request: Request): Promise<globalThis.Response>; prepareUpload(file: string): Promise<{ method: string | undefined; url: string; entryId: string; location: string; previewUrl: string; provider: string; }>; getDraft(draftKey: DraftKey): Promise<Draft | undefined>; storeDraft(draft: Draft): Promise<void>; revisions(file: string): Promise<Array<Revision>>; revisionData(file: string, revisionId: string): Promise<EntryRecord | undefined>; } } declare module 'alinea/cloud/view/CloudAuth.browser' { import type { Auth } from 'alinea/core/Auth'; export function CloudAuthView({ setSession }: Auth.ViewProps): import("react/jsx-runtime").JSX.Element | null; } declare module 'alinea/cloud/view/CloudAuth' { export function CloudAuthView(): null; } declare module 'alinea/config' { export { createMediaRoot as media } from 'alinea/core/media/MediaRoot'; export { createConfig as create } from 'alinea/core/Config'; export { document } from 'alinea/core/Document'; export { page } from 'alinea/core/Page'; export { snippet } from 'alinea/core/pages/Snippet'; export { root } from 'alinea/core/Root'; export { schema } from 'alinea/core/Schema'; export { track } from 'alinea/core/Tracker'; export { type } from 'alinea/core/Type'; export { workspace } from 'alinea/core/Workspace'; } declare module 'alinea/core' { export { createCMS } from 'alinea/adapter/core/cms'; export * from 'alinea/core/Entry'; export * from 'alinea/core/Field'; export * from 'alinea/core/field/ListField'; export * from 'alinea/core/field/RecordField'; export * from 'alinea/core/field/RichTextField'; export * from 'alinea/core/field/ScalarField'; export * from 'alinea/core/field/UnionField'; } declare module 'alinea/core/Auth' { import type { ComponentType } from 'react'; import type { Session } from 'alinea/core/Session'; export namespace Auth { type ViewProps = { setSession: (session: Session | undefined) => void; }; type View = ComponentType<ViewProps>; } } declare module 'alinea/core/Client' { import type { PreviewInfo } from 'alinea/backend/Previews'; import { type AuthResult } from 'alinea/cloud/AuthResult'; import type { Config } from 'alinea/core/Config'; import type { LocalConnection, Revision, UploadResponse } from 'alinea/core/Connection'; import type { Draft, DraftKey } from 'alinea/core/Draft'; import type { CommitRequest } from 'alinea/core/db/CommitRequest'; import type { Mutation } from 'alinea/core/db/Mutation'; import type { EntryRecord } from 'alinea/core/EntryRecord'; import type { AnyQueryResult, GraphQuery } from 'alinea/core/Graph'; import { ReadonlyTree } from 'alinea/core/source/Tree'; import type { User } from 'alinea/core/User'; export type AuthenticateRequest = (request?: RequestInit) => RequestInit | undefined; export interface ClientOptions { config: Config; url: string; applyAuth?: AuthenticateRequest; unauthorized?: () => void; } export class Client implements LocalConnection { #private; constructor(options: ClientOptions); get url(): string; authStatus(): Promise<AuthResult>; logout: () => Promise<void>; previewToken(request: PreviewInfo): Promise<string>; prepareUpload(file: string): Promise<UploadResponse>; user(): Promise<User | undefined>; resolve<Query extends GraphQuery>(query: Query): Promise<AnyQueryResult<Query>>; mutate(mutations: Array<Mutation>): Promise<{ sha: string; }>; authenticate(applyAuth: AuthenticateRequest, unauthorized: () => void): Client; revisions(file: string): Promise<Array<Revision>>; revisionData(file: string, revisionId: string): Promise<EntryRecord | undefined>; getTreeIfDifferent(sha: string): Promise<ReadonlyTree | undefined>; getBlobs(shas: Array<string>): AsyncGenerator<[sha: string, blob: Uint8Array]>; write(request: CommitRequest): Promise<{ sha: string; }>; getDraft(key: DraftKey): Promise<Draft | undefined>; storeDraft(draft: Draft): Promise<void>; } } declare module 'alinea/core/CMS' { import { type Config } from 'alinea/core/Config'; import type { PreviewRequest } from 'alinea/core/Preview'; import { WriteableGraph } from 'alinea/core/db/WriteableGraph'; export interface ConnectionContext { apiKey?: string; accessToken?: string; preview?: PreviewRequest; } export abstract class CMS<Definition extends Config = Config> extends WriteableGraph { config: Definition; constructor(config: Definition); get schema(): Definition['schema']; get workspaces(): Definition['workspaces']; } } declare module 'alinea/core/Config' { import type { Preview } from 'alinea/core/Preview'; import type { Auth } from 'alinea/core/Auth'; import { Root } from 'alinea/core/Root'; import { Schema } from 'alinea/core/Schema'; import { Type } from 'alinea/core/Type'; import { Workspace, type WorkspaceInternal } from 'alinea/core/Workspace'; /** Configuration options */ export interface Config { /** A schema describing the types of entries */ schema: Schema; /** A record containing workspace configurations */ workspaces: Record<string, Workspace>; /** A url which will be embedded in the dashboard for live previews */ preview?: Preview; /** Every edit will pass through a draft status before being published */ enableDrafts?: boolean; /** The interval in seconds at which the frontend will poll for updates */ syncInterval?: number; /** The base url of the application */ baseUrl?: string | { development?: string; production?: string; }; /** The url of the handler endpoint */ handlerUrl?: string; /** The folder where public assets are stored, defaults to /public */ publicDir?: string; /** Filename of the generated dashboard */ dashboardFile?: string; auth?: Auth.View; } export namespace Config { function baseUrl(config: Config, env?: string): string | undefined; function mainWorkspace(config: Config): WorkspaceInternal; function type(config: Config, name: string): Type | undefined; function rootContains(config: Config, root: Root, childType: Type): boolean; function typeContains(config: Config, parentType: Type, childType: Type): boolean; function hasAuth(config: Config): boolean; function multipleWorkspaces(config: Config): boolean; function contentDir(config: Config): string; function filePath(config: Config, workspace: string, root: string, locale: string | null, ...rest: Array<string>): string; function validate(config: Config): void; function referencedViews(config: Config): Array<string>; } /** Create a new config instance */ export function createConfig<Definition extends Config>(definition: Definition): Definition; } declare module 'alinea/core/Config.test' { export {}; } declare module 'alinea/core/Connection' { import type { Request, Response } from '@alinea/iso'; import type { PreviewInfo } from 'alinea/backend/Previews'; import type { Draft, DraftKey } from 'alinea/core/Draft'; import type { CommitRequest } from 'alinea/core/db/CommitRequest'; import type { Mutation } from 'alinea/core/db/Mutation'; import type { EntryRecord } from 'alinea/core/EntryRecord'; import type { AnyQueryResult, GraphQuery } from 'alinea/core/Graph'; import type { ReadonlyTree } from 'alinea/core/source/Tree'; import type { User } from 'alinea/core/User'; export interface AuthApi { authenticate(request: Request): Promise<Response>; verify(request: Request): Promise<AuthedContext>; } export interface RemoteConnection extends Connection, AuthApi { } export interface BrowserConnection extends Connection { logout?(): Promise<void>; } export interface LocalConnection extends Connection { mutate(mutations: Array<Mutation>): Promise<{ sha: string; }>; previewToken(request: PreviewInfo): Promise<string>; resolve<Query extends GraphQuery>(query: Query): Promise<AnyQueryResult<Query>>; user(): Promise<User | undefined>; } export interface SyncApi { getTreeIfDifferent(sha: string): Promise<ReadonlyTree | undefined>; getBlobs(shas: Array<string>): AsyncGenerator<[sha: string, blob: Uint8Array]>; } export interface CommitApi { write(request: CommitRequest): Promise<{ sha: string; }>; } export interface HistoryApi { revisions(file: string): Promise<Array<Revision>>; revisionData(file: string, revisionId: string): Promise<EntryRecord | undefined>; } export interface DraftsApi { getDraft(draftKey: DraftKey): Promise<Draft | undefined>; storeDraft(draft: Draft): Promise<void>; } export interface UploadsApi { prepareUpload(file: string): Promise<UploadResponse>; handleUpload?(entryId: string, file: Blob): Promise<void>; previewUpload?(entryId: string): Promise<Response>; } export interface Connection extends CommitApi, SyncApi, HistoryApi, DraftsApi, UploadsApi { } export interface RequestContext { isDev: boolean; handlerUrl: URL; apiKey: string; user?: User; token?: string; } export interface AuthedContext extends RequestContext { user: User; token: string; } export interface Revision { ref: string; createdAt: number; file: string; user?: { name: string; email: string; }; description?: string; } export interface UploadDestination { entryId: string; location: string; previewUrl: string; } export interface UploadResponse extends UploadDestination { url: string; method?: string; } export interface DraftTransport { entryId: string; locale: string | null; commitHash: string; fileHash: string; draft: string; } } declare module 'alinea/core/db/CommitRequest' { import type { Change, ChangeFile, ChangesBatch } from 'alinea/core/source/Change'; import type { ReadonlyTree } from 'alinea/core/source/Tree'; import type { RemoveFileMutation, UploadFileMutation } from 'alinea/core/db/Mutation'; export interface AddContent extends ChangeFile { op: 'addContent'; contents: string; } export interface DeleteContent extends ChangeFile { op: 'deleteContent'; } export type CommitChange = AddContent | DeleteContent | UploadFileMutation | RemoveFileMutation; export function commitChanges(changes: Array<Change>): Array<CommitChange>; export function sourceChanges(request: CommitRequest): ChangesBatch; export interface CommitRequest { description: string; fromSha: string; intoSha: string; checks: Array<[path: string, sha: string]>; changes: Array<CommitChange>; } export function checkCommit(tree: ReadonlyTree, request: CommitRequest): void; } declare module 'alinea/core/db/EntryDB' { import type { Config } from 'alinea/core/Config'; import type { LocalConnection, UploadResponse } from 'alinea/core/Connection'; import type { Source } from 'alinea/core/source/Source'; import { type CommitRequest } from 'alinea/core/db/CommitRequest'; import { LocalDB } from 'alinea/core/db/LocalDB'; import type { Mutation } from 'alinea/core/db/Mutation'; export class EntryDB extends LocalDB { connect: () => Promise<LocalConnection>; constructor(config: Config, source: Source, connect: () => Promise<LocalConnection>); mutate(mutations: Array<Mutation>): Promise<{ sha: string; remote: Promise<string>; }>; write(request: CommitRequest): Promise<{ sha: string; }>; prepareUpload(file: string): Promise<UploadResponse>; syncWithRemote(): Promise<string>; } } declare module 'alinea/core/db/EntryIndex' { import { Config } from 'alinea/core/Config'; import type { Entry, EntryStatus } from 'alinea/core/Entry'; import type { ChangesBatch } from 'alinea/core/source/Change'; import { type Source } from 'alinea/core/source/Source'; import { ReadonlyTree } from 'alinea/core/source/Tree'; import { Type } from 'alinea/core/Type'; import { EntryTransaction } from 'alinea/core/db/EntryTransaction'; export interface EntryFilter { ids?: ReadonlyArray<string>; search?: string; condition?(entry: Entry): boolean; } export interface EntryCondition { search?: string; nodes?: Iterable<EntryNode>; node?(node: EntryNode): boolean; language?(language: EntryLanguageNode): boolean; entry?(entry: Entry): boolean; } export function combineConditions(a: EntryCondition, b: EntryCondition): EntryCondition; interface EntryVersionData { id: string; type: string; index: string; searchableText: string; title: string; data: Record<string, unknown>; seeded: string | null; rowHash: string; fileHash: string; } interface EntryVersion extends EntryVersionData { locale: string | null; workspace: string; root: string; path: string; status: EntryStatus; parentDir: string; childrenDir: string; filePath: string; level: number; } class EntryLanguage extends Map<EntryStatus, EntryVersion> { readonly locale: string | null; readonly parentDir: string; readonly selfDir: string; constructor(versions: Array<EntryVersion>); } class EntryCollection extends Map<string | null, EntryLanguage> { versions: Array<EntryVersion>; readonly type: string; constructor(versions: Array<EntryVersion>); } class EntryLanguageNode { #private; private node; private language; inheritedStatus: EntryStatus | undefined; main: EntryVersion; active: EntryVersion; url: string; locale: string | null; path: string; readonly seeded: string | null; constructor(node: EntryNode, language: EntryLanguage); [Symbol.iterator](): MapIterator<[EntryStatus, EntryVersion]>; has(status: EntryStatus): boolean; get parentPaths(): string[]; get entries(): Entry<Record<string, unknown>>[]; filter(filter: EntryCondition): Generator<Entry>; } export class EntryNode extends Map<string | null, EntryLanguageNode> { entryType: Type; parent: EntryNode | null; children: () => Iterable<EntryNode>; readonly id: string; readonly index: string; readonly parentId: string | null; readonly parents: Array<string>; readonly workspace: string; readonly root: string; readonly type: string; readonly level: number; constructor(entryType: Type, parent: EntryNode | null, children: () => Iterable<EntryNode>, collection: EntryCollection); filter(filter: EntryCondition): Generator<Entry>; } export class EntryGraph { #private; nodes: Array<EntryNode>; constructor(config: Config, versionData: Map<string, EntryVersionData>, seeds: Map<string, Seed>); byId(id: string): EntryNode | undefined; byDir(dir: string): EntryNode | undefined; withChanges(batch: ChangesBatch): EntryGraph; filter({ search, ...filter }: EntryCondition): Generator<Entry>; } export class EntryIndex extends EventTarget { #private; tree: ReadonlyTree; initialSync: ReadonlyTree | undefined; graph: EntryGraph; constructor(config: Config); get sha(): string; filter(filter: EntryCondition): Iterable<Entry>; findFirst<T extends Record<string, unknown>>(filter: (entry: Entry) => boolean): Entry<T> | undefined; findMany(filter: (entry: Entry) => boolean): Iterable<Entry>; syncWith(source: Source): Promise<string>; indexChanges(batch: ChangesBatch): Promise<string>; seed(source: Source): Promise<void>; byId(id: string): EntryNode | undefined; fix(source: Source): Promise<void>; transaction(source: Source): Promise<EntryTransaction>; } interface Seed { seedId: string; type: string; workspace: string; root: string; locale: string | null; data: Record<string, any>; } export {}; } declare module 'alinea/core/db/EntryIndex.test' { export {}; } declare module 'alinea/core/db/EntryResolver' { import type { Type } from 'alinea'; import type { Config } from 'alinea/core/Config'; import type { Entry } from 'alinea/core/Entry'; import type { Expr } from 'alinea/core/Expr'; import { Field } from 'alinea/core/Field'; import { type AnyQueryResult, type Edge, type EdgeQuery, type GraphQuery, type Projection, type Status } from 'alinea/core/Graph'; import { type HasExpr } from 'alinea/core/Internal'; import type { Resolver } from 'alinea/core/Resolver'; import { type EntryCondition, type EntryFilter, type EntryGraph, type EntryIndex } from 'alinea/core/db/EntryIndex'; import { LinkResolver } from 'alinea