/** * 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 _ from 'lodash'; import { FlowEngine } from '../flowEngine'; import { jioToJoiSchema } from './jioToJoiSchema'; export interface DataSourceOptions extends Record { key: string; displayName?: string; description?: string; [key: string]: any; } export type DataSourceRequester = (options: Record) => Promise; export interface DataSourceLoadResult { collections?: CollectionOptions[]; dataSources?: Array; } export type DataSourceLoader = (context: { key: string; manager: DataSourceManager; }) => Promise; export declare class DataSourceManager { dataSources: Map; flowEngine: FlowEngine; requester?: DataSourceRequester; collectionFieldInterfaceManager?: { addFieldInterfaces?: (fieldInterfaceClasses?: any[]) => void; addFieldInterfaceGroups?: (groups: Record) => void; addFieldInterfaceComponentOption?: (name: string, option: any) => void; addFieldInterfaceOperator?: (name: string, operator: any) => void; registerFieldFilterOperator?: (operator: any) => void; registerFieldFilterOperatorGroup?: (name: string, operators?: any[]) => void; addFieldFilterOperatorsToGroup?: (name: string, operators?: any[]) => void; getFieldInterface?: (name: string) => any; registerFieldInterfaceConfigure?: (options: unknown) => void; getFieldInterfaceConfigure?: (name: string, collectionInfo?: unknown) => unknown; getFieldInterfaceConfigureProperties?: (name: string, collectionInfo?: any) => Record; }; loaders: Map; loadedKeys: Set; loadingKeys: Set; loadErrors: Map; loadingPromise: Promise | null; constructor(); setFlowEngine(flowEngine: FlowEngine): void; setRequester(requester?: DataSourceRequester): void; setCollectionFieldInterfaceManager(manager: DataSourceManager['collectionFieldInterfaceManager']): void; addFieldInterfaces(fieldInterfaceClasses?: any[]): void; addFieldInterfaceGroups(groups: Record): void; addFieldInterfaceComponentOption(name: string, option: any): void; addFieldInterfaceOperator(name: string, operator: any): void; registerFieldFilterOperator(operator: any): void; registerFieldFilterOperatorGroup(name: string, operators?: any[]): void; addFieldFilterOperatorsToGroup(name: string, operators?: any[]): void; registerLoader(key: string, loader: DataSourceLoader): void; removeLoader(key: string): void; addDataSource(ds: DataSource | DataSourceOptions): void; upsertDataSource(ds: DataSource | DataSourceOptions): void; removeDataSource(key: string): void; clearDataSources(): void; getDataSources(): DataSource[]; getDataSource(key: string): DataSource | undefined; getCollection(dataSourceKey: string, collectionName: string): Collection | undefined; getCollectionField(fieldPathWithDataSource: string): CollectionField; ensureLoaded(options?: { force?: boolean; keys?: string[]; }): Promise; reload(options?: { keys?: string[]; }): Promise; reloadDataSource(key: string): Promise; protected resolveLoadKeys(requestedKeys?: string[]): string[]; protected getApp(): { eventBus?: EventTarget; }; protected dispatchDataSourceEvent(type: 'dataSource:loaded' | 'dataSource:loadFailed', detail: { dataSourceKey: string; initial: boolean; error?: Error; }): void; protected setDataSourceState(key: string, options: Partial> & Record): void; protected applyDataSourceLoadResult(key: string, result: DataSourceLoadResult): void; protected loadKey(key: string, options: { initial: boolean; force: boolean; }): Promise; } export type CollectionFieldInterfaceDataSourceManager = Pick; export declare function getCollectionFieldInterface(interfaceName: string | undefined, ...dataSourceManagers: Array): any; export declare class DataSource { dataSourceManager: DataSourceManager; collectionManager: CollectionManager; options: Record; constructor(options?: Record); get flowEngine(): FlowEngine; get displayName(): any; get key(): any; get name(): any; get status(): any; get errorMessage(): any; setDataSourceManager(dataSourceManager: DataSourceManager): void; getCollections(): Collection[]; getCollection(name: string): Collection | undefined; /** * @deprecated use getAssociation instead */ getAssocation(associationName: string): CollectionField | undefined; getAssociation(associationName: string): CollectionField | undefined; addCollection(collection: Collection | CollectionOptions): void; updateCollection(newOptions: CollectionOptions): void; upsertCollection(options: CollectionOptions): Collection; upsertCollections(collections: CollectionOptions[], options?: { clearFields?: boolean; }): void; setCollections(collections: CollectionOptions[], options?: { clearFields?: boolean; }): void; removeCollection(name: string): void; clearCollections(): void; setOptions(newOptions?: any): void; patchOptions(newOptions?: any): void; reload(): Promise; getCollectionField(fieldPath: string): CollectionField; } export interface CollectionOptions { name: string; title?: string; inherits?: string[]; [key: string]: any; } export declare class CollectionManager { dataSource: DataSource; collections: Map; allCollectionsInheritChain: string[]; protected childrenCollectionsName: { supportView?: string[]; notSupportView?: string[]; }; constructor(dataSource: DataSource); protected resetCaches(): void; get flowEngine(): FlowEngine; addCollection(collection: Collection | CollectionOptions): void; removeCollection(name: string): void; updateCollection(newOptions: CollectionOptions, options?: { clearFields?: boolean; }): void; upsertCollection(options: CollectionOptions): Collection; upsertCollections(collections: CollectionOptions[], options?: { clearFields?: boolean; }): void; setCollections(collections: CollectionOptions[], options?: { clearFields?: boolean; }): void; sortCollectionsByInherits(collections: CollectionOptions[]): CollectionOptions[]; getCollection(name: string): Collection | undefined; getCollections(): Collection[]; clearCollections(): void; getAssociation(associationName: string): CollectionField | undefined; getChildrenCollections(name: any): any[]; getChildrenCollectionsName(name: any, isSupportView?: boolean): string[]; getAllCollectionsInheritChain(name: any): string[]; } export declare class Collection { fields: Map; options: Record; inherits: Map; dataSource: DataSource; constructor(options?: Record); clone(): Collection; getFilterByTK(record: any): any; get titleableFields(): CollectionField[]; get hidden(): any; get flowEngine(): FlowEngine; get collectionManager(): CollectionManager; get sort(): any; get filterTargetKey(): any; get dataSourceKey(): any; get name(): any; get template(): any; get storage(): any; get title(): any; get titleCollectionField(): CollectionField; initInherits(): void; setDataSource(dataSource: DataSource): void; setOptions(newOptions?: any, options?: { clearFields?: boolean; }): void; setOption(key: string, value: any): void; getFields(): CollectionField[]; getToOneAssociationFields(): CollectionField[]; getAssociationFields(types?: any[]): CollectionField[]; mapFields(callback: (field: CollectionField) => any): any[]; setFields(fields: CollectionField[] | Record[]): void; upsertFields(fields?: Record[]): void; getFieldByPath(fieldPath: string): CollectionField | undefined; getField(fieldName: string): CollectionField | undefined; getFullFieldPath(name: string): string; addField(field: CollectionField | Record): void; removeField(fieldName: string): boolean; clearFields(): void; refresh(): void; /** * 获取所有关联字段 * @returns 关联字段数组 */ getRelationshipFields(): CollectionField[]; /** * 获取所有关联的集合 * @returns 关联集合数组 */ getRelatedCollections(): Collection[]; /** * 检查是否有关联字段 * @returns 是否有关联字段 */ hasRelationshipFields(): boolean; } export declare class CollectionField { options: Record; collection: Collection; constructor(options: Record); setOptions(newOptions?: any): void; setCollection(collection: Collection): void; get targetCollectionTitleFieldName(): any; get targetCollectionTitleField(): CollectionField; get flowEngine(): FlowEngine; get dataSourceKey(): any; get resourceName(): string; get collectionName(): any; get readonly(): any; get titleable(): boolean; get fullpath(): string; get name(): any; get type(): any; get dataType(): any; get foreignKey(): any; get targetKey(): any; get sourceKey(): any; get target(): any; get title(): string; set title(value: string); get enum(): any[]; get defaultValue(): any; get interface(): any; get filterable(): any; get inputable(): any; get uiSchema(): any; get targetCollection(): Collection; get validation(): any; getComponentProps(): _.Dictionary; getFields(): CollectionField[]; getInterfaceOptions(): any; getFilterOperators(): any; getSubclassesOf(baseClass: string): Map; getFirstSubclassNameOf(baseClass: string): string; isAssociationField(): boolean; /** * 检查字段是否为关联字段 * @returns 是否为关联字段 */ isRelationshipField(): boolean; } /** * 判断 fieldInterfaces 是否匹配 targetInterface * @param fieldInterfaces string | string[] | null * @param targetInterface string */ export declare function isFieldInterfaceMatch(fieldInterfaces: string | string[] | null | undefined, targetInterface: string): boolean; export { jioToJoiSchema };