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.
132 lines (131 loc) • 5.23 kB
TypeScript
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: "json";
csv: "csv";
yaml: "yaml";
}>>;
}, z.core.$strip>;
target: z.ZodObject<{
collection: z.ZodString;
type: z.ZodDefault<z.ZodEnum<{
create: "create";
update: "update";
}>>;
primaryKey: z.ZodDefault<z.ZodString>;
createUsers: z.ZodDefault<z.ZodBoolean>;
}, z.core.$strip>;
mapping: z.ZodObject<{
attributes: z.ZodArray<z.ZodObject<{
oldKey: z.ZodOptional<z.ZodString>;
oldKeys: z.ZodOptional<z.ZodArray<z.ZodString>>;
targetKey: z.ZodString;
valueToSet: z.ZodOptional<z.ZodAny>;
fileData: z.ZodOptional<z.ZodObject<{
path: z.ZodString;
name: z.ZodString;
}, z.core.$strip>>;
converters: z.ZodDefault<z.ZodArray<z.ZodString>>;
validation: z.ZodDefault<z.ZodArray<z.ZodObject<{
rule: z.ZodString;
params: z.ZodArray<z.ZodString>;
}, z.core.$strip>>>;
afterImport: z.ZodDefault<z.ZodArray<z.ZodObject<{
action: z.ZodString;
params: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
}, z.core.$strip>>>;
}, z.core.$strip>>;
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>;
}, z.core.$strip>>>;
}, z.core.$strip>;
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;
}, z.core.$strip>>;
}, z.core.$strip>>;
}, z.core.$strip>;
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.
* Supports both collection and table terminology.
*
* @param collectionName - Name of the collection
* @param sourceFile - Source data file name
* @param useTableTerminology - Whether to use table terminology
* @returns YAML configuration template
*/
generateTemplate(collectionName: string, sourceFile: string, useTableTerminology?: boolean): 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;
};
};
}