UNPKG

appwrite-utils-cli

Version:

Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.

385 lines (384 loc) 13 kB
import { z } from "zod"; import type { ImportDef } from "appwrite-utils"; export declare const YamlImportConfigSchema: z.ZodObject<{ source: z.ZodObject<{ file: z.ZodString; basePath: z.ZodOptional<z.ZodString>; type: z.ZodDefault<z.ZodEnum<["json", "csv", "yaml"]>>; }, "strip", z.ZodTypeAny, { type: "json" | "csv" | "yaml"; file: string; basePath?: string | undefined; }, { file: string; type?: "json" | "csv" | "yaml" | undefined; basePath?: string | undefined; }>; target: z.ZodObject<{ collection: z.ZodString; type: z.ZodDefault<z.ZodEnum<["create", "update"]>>; primaryKey: z.ZodDefault<z.ZodString>; createUsers: z.ZodDefault<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { type: "create" | "update"; collection: string; primaryKey: string; createUsers: boolean; }, { collection: string; type?: "create" | "update" | undefined; primaryKey?: string | undefined; createUsers?: boolean | undefined; }>; mapping: z.ZodObject<{ attributes: z.ZodArray<z.ZodObject<{ oldKey: z.ZodOptional<z.ZodString>; oldKeys: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; targetKey: z.ZodString; valueToSet: z.ZodOptional<z.ZodAny>; fileData: z.ZodOptional<z.ZodObject<{ path: z.ZodString; name: z.ZodString; }, "strip", z.ZodTypeAny, { path: string; name: string; }, { path: string; name: string; }>>; converters: z.ZodDefault<z.ZodArray<z.ZodString, "many">>; validation: z.ZodDefault<z.ZodArray<z.ZodObject<{ rule: z.ZodString; params: z.ZodArray<z.ZodString, "many">; }, "strip", z.ZodTypeAny, { params: string[]; rule: string; }, { params: string[]; rule: string; }>, "many">>; afterImport: z.ZodDefault<z.ZodArray<z.ZodObject<{ action: z.ZodString; params: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>, "many">; }, "strip", z.ZodTypeAny, { params: (string | Record<string, any>)[]; action: string; }, { params: (string | Record<string, any>)[]; action: string; }>, "many">>; }, "strip", z.ZodTypeAny, { validation: { params: string[]; rule: string; }[]; targetKey: string; converters: string[]; afterImport: { params: (string | Record<string, any>)[]; action: string; }[]; oldKey?: string | undefined; oldKeys?: string[] | undefined; valueToSet?: any; fileData?: { path: string; name: string; } | undefined; }, { targetKey: string; validation?: { params: string[]; rule: string; }[] | undefined; oldKey?: string | undefined; oldKeys?: string[] | undefined; valueToSet?: any; fileData?: { path: string; name: string; } | undefined; converters?: string[] | undefined; afterImport?: { params: (string | Record<string, any>)[]; action: string; }[] | undefined; }>, "many">; relationships: z.ZodDefault<z.ZodArray<z.ZodObject<{ sourceField: z.ZodString; targetField: z.ZodString; targetCollection: z.ZodString; fieldToSet: z.ZodOptional<z.ZodString>; targetFieldToMatch: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { targetField: string; sourceField: string; targetCollection: string; fieldToSet?: string | undefined; targetFieldToMatch?: string | undefined; }, { targetField: string; sourceField: string; targetCollection: string; fieldToSet?: string | undefined; targetFieldToMatch?: string | undefined; }>, "many">>; }, "strip", z.ZodTypeAny, { attributes: { validation: { params: string[]; rule: string; }[]; targetKey: string; converters: string[]; afterImport: { params: (string | Record<string, any>)[]; action: string; }[]; oldKey?: string | undefined; oldKeys?: string[] | undefined; valueToSet?: any; fileData?: { path: string; name: string; } | undefined; }[]; relationships: { targetField: string; sourceField: string; targetCollection: string; fieldToSet?: string | undefined; targetFieldToMatch?: string | undefined; }[]; }, { attributes: { targetKey: string; validation?: { params: string[]; rule: string; }[] | undefined; oldKey?: string | undefined; oldKeys?: string[] | undefined; valueToSet?: any; fileData?: { path: string; name: string; } | undefined; converters?: string[] | undefined; afterImport?: { params: (string | Record<string, any>)[]; action: string; }[] | undefined; }[]; relationships?: { targetField: string; sourceField: string; targetCollection: string; fieldToSet?: string | undefined; targetFieldToMatch?: string | undefined; }[] | undefined; }>; options: z.ZodDefault<z.ZodObject<{ batchSize: z.ZodDefault<z.ZodNumber>; skipValidation: z.ZodDefault<z.ZodBoolean>; dryRun: z.ZodDefault<z.ZodBoolean>; continueOnError: z.ZodDefault<z.ZodBoolean>; updateMapping: z.ZodOptional<z.ZodObject<{ originalIdField: z.ZodString; targetField: z.ZodString; }, "strip", z.ZodTypeAny, { targetField: string; originalIdField: string; }, { targetField: string; originalIdField: string; }>>; }, "strip", z.ZodTypeAny, { batchSize: number; dryRun: boolean; skipValidation: boolean; continueOnError: boolean; updateMapping?: { targetField: string; originalIdField: string; } | undefined; }, { batchSize?: number | undefined; dryRun?: boolean | undefined; skipValidation?: boolean | undefined; continueOnError?: boolean | undefined; updateMapping?: { targetField: string; originalIdField: string; } | undefined; }>>; }, "strip", z.ZodTypeAny, { options: { batchSize: number; dryRun: boolean; skipValidation: boolean; continueOnError: boolean; updateMapping?: { targetField: string; originalIdField: string; } | undefined; }; target: { type: "create" | "update"; collection: string; primaryKey: string; createUsers: boolean; }; source: { type: "json" | "csv" | "yaml"; file: string; basePath?: string | undefined; }; mapping: { attributes: { validation: { params: string[]; rule: string; }[]; targetKey: string; converters: string[]; afterImport: { params: (string | Record<string, any>)[]; action: string; }[]; oldKey?: string | undefined; oldKeys?: string[] | undefined; valueToSet?: any; fileData?: { path: string; name: string; } | undefined; }[]; relationships: { targetField: string; sourceField: string; targetCollection: string; fieldToSet?: string | undefined; targetFieldToMatch?: string | undefined; }[]; }; }, { target: { collection: string; type?: "create" | "update" | undefined; primaryKey?: string | undefined; createUsers?: boolean | undefined; }; source: { file: string; type?: "json" | "csv" | "yaml" | undefined; basePath?: string | undefined; }; mapping: { attributes: { targetKey: string; validation?: { params: string[]; rule: string; }[] | undefined; oldKey?: string | undefined; oldKeys?: string[] | undefined; valueToSet?: any; fileData?: { path: string; name: string; } | undefined; converters?: string[] | undefined; afterImport?: { params: (string | Record<string, any>)[]; action: string; }[] | undefined; }[]; relationships?: { targetField: string; sourceField: string; targetCollection: string; fieldToSet?: string | undefined; targetFieldToMatch?: string | undefined; }[] | undefined; }; options?: { batchSize?: number | undefined; dryRun?: boolean | undefined; skipValidation?: boolean | undefined; continueOnError?: boolean | undefined; updateMapping?: { targetField: string; originalIdField: string; } | undefined; } | undefined; }>; export type YamlImportConfig = z.infer<typeof YamlImportConfigSchema>; /** * Service for loading and converting YAML import configurations. * Integrates with existing .appwrite YAML structure while providing * enhanced import configuration capabilities. */ export declare class YamlImportConfigLoader { private appwriteFolderPath; constructor(appwriteFolderPath: string); /** * Loads a YAML import configuration file. * * @param configPath - Path to the YAML config file relative to .appwrite/import/ * @returns Parsed and validated YAML import configuration */ loadImportConfig(configPath: string): Promise<YamlImportConfig>; /** * Loads all import configurations from the .appwrite/import directory. * * @returns Map of collection names to their import configurations */ loadAllImportConfigs(): Promise<Map<string, YamlImportConfig[]>>; /** * Converts YAML import configuration to legacy ImportDef format. * Maintains compatibility with existing import system. * * @param yamlConfig - YAML import configuration * @returns Legacy ImportDef object */ convertToImportDef(yamlConfig: YamlImportConfig): ImportDef; /** * Generates a template YAML import configuration. * Useful for getting started with YAML-based imports. * * @param collectionName - Name of the collection * @param sourceFile - Source data file name * @returns YAML configuration template */ generateTemplate(collectionName: string, sourceFile: string): string; /** * Creates the import directory structure if it doesn't exist. * Sets up the recommended directory layout for YAML import configurations. */ createImportStructure(): Promise<void>; /** * Validates import configuration against collection schema. * Ensures that all target keys exist as attributes in the collection. * * @param yamlConfig - YAML import configuration * @param collectionAttributes - Collection attribute definitions * @returns Validation errors (empty if valid) */ validateAgainstCollection(yamlConfig: YamlImportConfig, collectionAttributes: any[]): string[]; /** * Gets statistics about import configurations. * * @param configs - Map of collection configurations * @returns Statistics object */ getStatistics(configs: Map<string, YamlImportConfig[]>): { totalConfigurations: number; collectionsWithConfigs: number; totalAttributeMappings: number; totalRelationshipMappings: number; configsByType: { [type: string]: number; }; }; }