/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ import { ResourcerContext } from '@nocobase/resourcer'; import { HttpRequestContext } from '../template/contexts'; import { type PathSegment, type VariablePathRef } from '../template/variable-expression'; import { type AuthorizedRecordBinding, type RecordBindingPlan } from './record-bindings'; export type JSONValue = string | { [key: string]: JSONValue; } | JSONValue[]; export type VarScope = 'global' | 'request'; export interface RequiredParamSpec { name: string; required?: boolean; defaultValue?: unknown; } export type ValidateContextParamsOptions = { contextParams: Record; flowModelUid?: string; koaCtx: ResourcerContext; usage: readonly VariablePathRef[]; varName: string; }; export type ValidateContextParamsResult = { allowed?: boolean; contextParams?: Record; requireFlowModel?: boolean; }; export interface VariableDef { name: string; scope: VarScope; requiredParams?: RequiredParamSpec[]; attach: (ctx: HttpRequestContext, koaCtx: ResourcerContext, params?: unknown, usage?: VarUsage) => Promise | void; validateContextParams?: (options: ValidateContextParamsOptions) => Promise | ValidateContextParamsResult | void; } export type VarUsage = Readonly>; type LegacyVarUsage = Record; declare class VariableRegistry { private vars; register(def: VariableDef): void; get(name: string): VariableDef; list(): VariableDef[]; extractUsage(template: JSONValue): LegacyVarUsage; validate(template: JSONValue, contextParams: unknown): { ok: boolean; missing?: string[]; }; attachUsedVariables(ctx: HttpRequestContext, koaCtx: ResourcerContext, template: JSONValue, contextParams: Record): Promise; attachUsedVariablesFromUsage(ctx: HttpRequestContext, koaCtx: ResourcerContext, usage: VarUsage, contextParams: Record): Promise; attachUsedVariablesFromPlan(ctx: HttpRequestContext, koaCtx: ResourcerContext, usage: VarUsage, plan: RecordBindingPlan): Promise; } export declare const variables: VariableRegistry; /** 仅测试使用:重置变量注册表为内置默认集 */ export declare function omitVariableContextParams(contextParams: Record, varName: string): Record; export declare function sanitizeRegisteredVariableContextParams(contextParams: Record, registry?: { get?: (name: string) => VariableDef | undefined; list?: () => VariableDef[]; }): Record; /** * 从使用路径推断查询所需的 fields 与 appends。 * @param paths 使用到的子路径数组 * @param params 显式参数(仅用于兼容签名) */ export declare function inferSelectsFromUsage(paths?: readonly (string | readonly PathSegment[])[], _params?: unknown): { generatedAppends?: string[]; generatedFields?: string[]; }; export declare function isSafeRecordBinding(binding: AuthorizedRecordBinding): boolean; export declare function registerBuiltInVariables(reg: VariableRegistry): void; export {};