From 4b588d1269e801d5bef27fa60708ec0d77afe727 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Thu, 16 Apr 2026 15:59:32 +0000 Subject: [PATCH] feat(types): add action api types to ApiInfo --- index.d.ts | 230 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 222 insertions(+), 8 deletions(-) diff --git a/index.d.ts b/index.d.ts index 85ea054..2597ca5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -13,24 +13,108 @@ declare global { export type BoolOrEval = boolean | { eval: string } /** Structured field validator as defined in Go CollectionField.Validator */ + export interface FieldImageValidator { + /** Minimum allowed image width in pixels */ + minWidth?: number + /** Maximum allowed image width in pixels */ + maxWidth?: number + /** Minimum allowed image height in pixels */ + minHeight?: number + /** Maximum allowed image height in pixels */ + maxHeight?: number + /** Allow non-image uploads to bypass image dimension checks entirely */ + allowNonImages?: boolean + /** Allow image/* uploads to pass when dimensions cannot be determined */ + allowUnknownDimensions?: boolean + } + export interface FieldValidator { - /** Array of allowed values */ + /** Array of allowed primitive values the field may equal */ in?: any[] + /** Built-in string format validator */ + format?: "email" | "url" | "uuid" | "slug" /** Whether the field is required */ required?: boolean /** Whether zero-values are allowed when required is true */ allowZero?: boolean /** JS eval expression for custom validation */ eval?: string + /** Minimum number of items for array fields */ + minItems?: number + /** Maximum number of items for array fields */ + maxItems?: number + /** Minimum number of characters for string values */ + minLength?: number + /** Maximum number of characters for string values */ + maxLength?: number + /** Regex pattern the string value must fully match */ + pattern?: string + /** Minimum numeric value */ + min?: number + /** Maximum numeric value */ + max?: number + /** Earliest allowed date/time value for date, time, and datetime fields */ + minDate?: string + /** Latest allowed date/time value for date, time, and datetime fields */ + maxDate?: string + /** Minimum decoded file size (e.g. 50KB) for file and file[] fields */ + minFileSize?: string + /** Maximum decoded file size (e.g. 5MB) */ + maxFileSize?: string + /** Allowed MIME types for file and file[] fields */ + accept?: string[] + /** Image dimension bounds for newly uploaded file and file[] images */ + image?: FieldImageValidator + } + + export interface ScoreConfig { + expr?: { [key: string]: any } + } + + export interface RegexConfig { + weights?: { [field: string]: number } + scoring?: "count" | "binary" | "log" + } + + export interface NormalizeConfig { + use?: string[] + eval?: string + } + + export interface NgramConfig { + sizes?: number[] + normalize?: NormalizeConfig + } + + export interface RrfConfig { + k?: number + topK?: number + weights?: { [source: string]: number } + } + + export interface VectorConfig { + provider: string + documentPrefix?: string + queryPrefix?: string + overflow?: "truncate" | "chunk" + chunkSize?: number + chunkOverlap?: number } /** Search configuration for a collection */ export interface SearchConfig { /** Search config name (used in query parameter qName) */ name: string - /** Search mode: text (MongoDB text index), regex, eval (JS), filter, ngram */ - mode: "text" | "regex" | "eval" | "filter" | "ngram" - /** Fields to search in (for text/regex mode) */ + /** Search mode: text, regex, eval, filter, ngram, vector or combined */ + mode: + | "text" + | "regex" + | "eval" + | "filter" + | "ngram" + | "vector" + | "combined" + /** Fields to search in (for regex and ngram mode) */ fields?: string[] /** Meta information */ meta?: { [key: string]: any } @@ -38,6 +122,18 @@ declare global { eval?: string /** MongoDB filter template (for filter mode) */ filter?: { [key: string]: any } + /** Ngram search configuration */ + ngram?: NgramConfig + /** Regex search configuration */ + regex?: RegexConfig + /** Custom scoring for eval/filter search */ + score?: ScoreConfig + /** Vector search configuration */ + vector?: VectorConfig + /** Reciprocal rank fusion configuration */ + rrf?: RrfConfig + /** Auto-regenerate enrichment data when the config changes */ + autoRegenerate?: boolean } /** Query limits configuration for a collection */ @@ -88,10 +184,76 @@ declare global { export interface AuditCollectionConfig { /** Whether audit logging is enabled for this collection */ enabled?: boolean - /** List of actions to audit: create, update, delete, bulkCreate, bulkUpdate, bulkDelete, get */ - actions?: string[] + /** List of actions to audit */ + actions?: Array< + | "create" + | "update" + | "delete" + | "bulkCreate" + | "bulkUpdate" + | "bulkDelete" + > } + export interface UploadConfig { + maxBodySize?: string + allowedMimeTypes?: string[] + } + + export type LocalizedText = string | Record + + export type ChoiceValue = string | number | boolean | null + + export interface ChoiceItem { + id?: ChoiceValue + value?: ChoiceValue + name?: LocalizedText + label?: LocalizedText + badgeVariant?: "success" | "error" | "warning" | "info" | "neutral" + chipVariant?: "success" | "error" | "warning" | "info" | "neutral" + badgeStyle?: Record + chipStyle?: Record + } + + export type EvalStringConfig = { + eval: string + select?: string[] + } + + export type EvalHtmlConfig = { + eval: string + raw?: boolean + select?: string[] + } + + export interface PreviewTableColumn { + source?: string + label?: LocalizedText + align?: "left" | "center" | "right" + eval?: string + raw?: boolean + select?: string[] + } + + export type PreviewSlotValue = string | EvalStringConfig + + export interface PreviewSlots { + label?: PreviewSlotValue + labelStyle?: PreviewSlotValue + secondary?: PreviewSlotValue + tertiary?: PreviewSlotValue + badge?: PreviewSlotValue + image?: PreviewSlotValue + imageFallback?: PreviewSlotValue + mediaFile?: string + eval?: string + raw?: boolean + table?: Array + select?: string[] + } + + export type PreviewConfig = string | EvalHtmlConfig | PreviewSlots + /** Image filter parameters — used in both CollectionConfig.imageFilter and ImagePackage.filter() */ export interface ImageFilterParams { width?: number @@ -143,6 +305,7 @@ declare global { export interface CollectionInfo { name: string defaultLanguage?: string + upload?: UploadConfig permissions?: { [role: string]: PermissionSet } projections?: { [name: string]: ProjectionConfig } meta?: { [key: string]: any } @@ -168,6 +331,53 @@ declare global { [key: string]: any } + /** Action endpoint descriptor as returned by context.api() for _actions resources */ + export interface ActionInfo { + name: string + meta?: ActionMeta + [key: string]: any + } + + export interface ActionMeta { + label?: LocalizedText + muiIcon?: string + description?: LocalizedText + group?: string + hide?: boolean + methods?: Record + [key: string]: any + } + + export interface ActionMethodMeta { + query?: { + title?: LocalizedText + description?: LocalizedText + fields?: CollectionFieldInfo[] + } + data?: { + title?: LocalizedText + description?: LocalizedText + fields?: CollectionFieldInfo[] + } + execution?: ActionExecutionMeta + output?: ActionOutputMeta + [key: string]: any + } + + export interface ActionExecutionMeta { + kind?: "sync" | "sse" | string + progress?: boolean + cancellable?: boolean + [key: string]: any + } + + export interface ActionOutputMeta { + display?: "summary" | "detail" | "raw" | "download" | "none" | string + title?: LocalizedText + fields?: CollectionFieldInfo[] + [key: string]: any + } + export type MethodPermission = boolean | { allow: boolean; bulk?: boolean } export type SimpleMethodPermission = boolean | { allow: boolean } @@ -220,6 +430,7 @@ declare global { meta?: { [key: string]: any } assets?: { name: string; path: string }[] collections?: CollectionInfo[] + actions?: ActionInfo[] jobs?: JobConfig[] errors?: { collection?: string; context?: string; error: any }[] [key: string]: any @@ -1314,7 +1525,10 @@ declare global { } export interface HookContext - extends GetHookData, GetHookGetOnlyData, PostHookData, JobData { + extends GetHookData, + GetHookGetOnlyData, + PostHookData, + JobData { request(): { method: string remoteAddr: string @@ -1329,7 +1543,7 @@ declare global { /** * bodyBytes return []byte go slice of post body for later use pe. in iso8859ToUtf8 */ - bodyBytes(): string + bodyBytes(): Int8Array } api(): ApiInfo