UNPKG

@statezero/core

Version:

The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate

133 lines (132 loc) 3.36 kB
/** * Main exported function to generate schema. * @param {GenerateArgs} args * @returns {Promise<void>} */ export function generateSchema(args: GenerateArgs): Promise<void>; /** * // Additional arguments for generation if needed. */ export type GenerateArgs = Object; export type SchemaProperty = { type: string; format?: string | undefined; items?: SchemaProperty | undefined; properties?: { [x: string]: SchemaProperty; } | undefined; required?: string[] | undefined; enum?: string[] | undefined; description?: string | undefined; nullable?: boolean | undefined; default?: any; ref?: string | undefined; }; export type RelationshipField = { /** * - Name of the relationship field */ field: string; /** * - The class name of the related model */ ModelClass: string; /** * - Type of relationship (e.g., "many-to-many", "foreign-key") */ relationshipType: string; }; export type RelationshipData = { type: string; /** * - e.g. "django_app.deepmodellevel1" */ model: string; /** * - e.g. "DeepModelLevel1" */ class_name: string; primary_key_field: string; }; export type SchemaDefinition = { type: string; properties: { [x: string]: SchemaProperty; }; required?: string[] | undefined; description?: string | undefined; definitions?: { [x: string]: SchemaDefinition; } | undefined; model_name: string; class_name: string; primary_key_field?: string | undefined; relationships?: { [x: string]: RelationshipData; } | undefined; }; export type PropertyDefinition = { name: string; type: string; required: boolean; defaultValue: string; isRelationship?: boolean | undefined; relationshipClassName?: string | undefined; isArrayRelationship?: boolean | undefined; relationshipPrimaryKeyField?: string | undefined; isString?: boolean | undefined; isNumber?: boolean | undefined; isBoolean?: boolean | undefined; isDate?: boolean | undefined; isPrimaryKey?: boolean | undefined; }; export type TemplateData = { /** * - Dynamic module path for imports. */ modulePath: string; /** * - Exported full model class name (from schema.class_name). */ className: string; /** * - Full model fields interface name (e.g. DeepModelLevel1Fields). */ interfaceName: string; /** * - Raw schema.model_name (including app label path). */ modelName: string; properties: PropertyDefinition[]; /** * - List of relationship fields for the model */ relationshipFields: RelationshipField[]; description?: string | undefined; definitions?: string[] | undefined; /** * - For JS generation: full class imports. */ jsImports?: string[] | undefined; /** * - For TS generation: type imports (Fields). */ tsImports?: string[] | undefined; /** * - The backend config key. */ configKey: string; /** * - Primary key field from schema. */ primaryKeyField: string; }; export type BackendConfig = { NAME: string; API_URL: string; GENERATED_TYPES_DIR: string; }; export type SelectedModel = { backend: BackendConfig; model: string; };