import { ActionVariable } from '../types/ActionVariable'; import { PrefabComponent, PrefabReference, PrefabWrapper, } from '../types/component'; import { Model } from '../types/model'; import { Prefab } from '../types/prefabs'; import { Property, PropertyKind, ModelPropertyInput } from '../types/property'; import { BettyPrefabs } from '../types/constants/BettyPrefabs'; import { PreparedAction, PreparedInput, LinkOptionProps, } from '../types/helpers'; import { PrefabComponentOption, ActionVariableKind, LinkedOptionProducer, MakePrepareActionArgs, } from '../types'; import { SchemaModel } from '../types/schemaModel'; import { WrapperAttrs } from './wrapper'; type Attributes = Omit; export type BeforeCreateArgs = { modelId: string; close: () => void; save: (prefab: Prefab) => void; prefab: Prefab; prefabs: Prefab[]; components: { [name: string]: any; }; helpers: { camelToSnakeCase: (str: string) => string; useCurrentPageId: () => string; useCurrentPartialId: () => string; useModelQuery: (options: Record) => { loading: boolean; data: Record | null; error: Record | null; }; usePropertyQuery: (propertyId: string) => { loading: boolean; data: Record | null; error: Record | null; }; useModelRelationQuery: (propertyModelId: string) => { loading: boolean; data: Record | null; error: Record | null; }; useModelIdSelector: () => string | null; useActionIdSelector: () => string | null; usePrefabSelector: () => { name: string; id: string } | null; cloneStructure: (prefabName: string) => PrefabReference; addActionVariable: ( actionId: string, name: string, kind: ActionVariableKind, options: object, ) => Promise; addSchemaModel: (name: string, jsonSchema: string) => Promise; addModelAndProperties: ( modelName: string, properties: ModelPropertyInput[], ) => Promise; prepareAction: (...args: MakePrepareActionArgs) => Promise; prepareInput: ( actionId: string | null, variableName: string | undefined, kind: PropertyKind, propertyKind: PropertyKind, permissions?: 'public' | 'private' | 'inherit', getPageAuthenticationProfileId?: string, ) => Promise; getPageAuthenticationProfileId: () => string; getPageName: () => string; makeBettyInput: ( prefabName: string, model: Model, property: Property, variable: ActionVariable, relatedIdProperties?: string[][], relatedModelIds?: Record, ) => PrefabReference; makeBettyUpdateInput: ( prefabName: string, model: Model, property: Property, variable: ActionVariable, relatedIdProperties?: string[][], relatedModelIds?: Record, ) => PrefabReference; BettyPrefabs: typeof BettyPrefabs; PropertyKind: typeof PropertyKind; createUuid: () => string; setOption: ( structure: PrefabComponent, key: string, transform: (option: PrefabComponentOption) => PrefabComponentOption, ) => void; createBlacklist: (whiteList: PropertyKind[]) => PropertyKind[]; createWrapper: ( attrs: WrapperAttrs, descendants: PrefabReference[], ) => PrefabWrapper; linkOption: (attrs: LinkOptionProps) => LinkedOptionProducer; }; }; type BeforeCreate = (args: BeforeCreateArgs) => any; export const prefab = ( name: string, attr: Attributes, beforeCreate: BeforeCreate | undefined, structure: PrefabReference[], ): Prefab => ({ name, ...attr, beforeCreate: beforeCreate?.toString(), structure, });