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.
174 lines (173 loc) • 6.11 kB
TypeScript
import { type Databases } from "node-appwrite";
import { z } from "zod";
/**
* Object that contains the context for an action that needs to be executed after import
* Used in the afterImportActionsDefinitions
* @type {ContextObject}
* @typedef {Object} ContextObject
* @property {string} collectionId - The ID of the collection
* @property {any} finalItem - The final item that was imported
* @property {string} action - The name of the action
* @property {string[]} params - The parameters for the action
* @property {Object} context - The context object for the action (all the data of this specific item)
*/
export declare const ContextObject: z.ZodObject<{
dbId: z.ZodString;
collectionId: z.ZodString;
finalItem: z.ZodAny;
attributeMappings: 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<{
name: z.ZodString;
path: z.ZodString;
}, "strip", z.ZodTypeAny, {
path: string;
name: string;
}, {
path: string;
name: string;
}>>;
converters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
validationActions: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
action: z.ZodString;
params: z.ZodArray<z.ZodString, "many">;
}, "strip", z.ZodTypeAny, {
params: string[];
action: string;
}, {
params: string[];
action: string;
}>, "many">>>;
postImportActions: z.ZodOptional<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, {
targetKey: string;
oldKey?: string | undefined;
oldKeys?: string[] | undefined;
valueToSet?: any;
fileData?: {
path: string;
name: string;
} | undefined;
converters?: string[] | undefined;
validationActions?: {
params: string[];
action: string;
}[] | undefined;
postImportActions?: {
params: (string | Record<string, any>)[];
action: string;
}[] | undefined;
}, {
targetKey: string;
oldKey?: string | undefined;
oldKeys?: string[] | undefined;
valueToSet?: any;
fileData?: {
path: string;
name: string;
} | undefined;
converters?: string[] | undefined;
validationActions?: {
params: string[];
action: string;
}[] | undefined;
postImportActions?: {
params: (string | Record<string, any>)[];
action: string;
}[] | undefined;
}>, "many">;
context: z.ZodAny;
}, "strip", z.ZodTypeAny, {
collectionId: string;
attributeMappings: {
targetKey: string;
oldKey?: string | undefined;
oldKeys?: string[] | undefined;
valueToSet?: any;
fileData?: {
path: string;
name: string;
} | undefined;
converters?: string[] | undefined;
validationActions?: {
params: string[];
action: string;
}[] | undefined;
postImportActions?: {
params: (string | Record<string, any>)[];
action: string;
}[] | undefined;
}[];
dbId: string;
context?: any;
finalItem?: any;
}, {
collectionId: string;
attributeMappings: {
targetKey: string;
oldKey?: string | undefined;
oldKeys?: string[] | undefined;
valueToSet?: any;
fileData?: {
path: string;
name: string;
} | undefined;
converters?: string[] | undefined;
validationActions?: {
params: string[];
action: string;
}[] | undefined;
postImportActions?: {
params: (string | Record<string, any>)[];
action: string;
}[] | undefined;
}[];
dbId: string;
context?: any;
finalItem?: any;
}>;
export type ContextObject = z.infer<typeof ContextObject>;
export declare const createOrFindAfterImportOperation: (database: Databases, collectionId: string, context: ContextObject, useMigrations?: boolean) => Promise<void>;
export declare const addBatch: (database: Databases, data: string) => Promise<string>;
export declare const getAfterImportOperations: (database: Databases, collectionId: string, useMigrations?: boolean) => Promise<{
status: "error" | "pending" | "ready" | "in_progress" | "completed" | "cancelled";
error: string;
$id: string;
$createdAt: string;
$updatedAt: string;
collectionId: string;
operationType: string;
progress: number;
total: number;
data?: any;
batches?: string[] | undefined;
}[]>;
export declare const findOrCreateOperation: (database: Databases, collectionId: string, operationType: string, additionalQueries?: string[]) => Promise<{
status: "error" | "pending" | "ready" | "in_progress" | "completed" | "cancelled";
error: string;
$id: string;
$createdAt: string;
$updatedAt: string;
collectionId: string;
operationType: string;
progress: number;
total: number;
data?: any;
batches?: string[] | undefined;
}>;
export declare const updateOperation: (database: Databases, operationId: string, updateFields: any, useMigrations?: boolean) => Promise<void>;
export declare const maxDataLength = 1073741820;
export declare const maxBatchItems = 25;
export declare const splitIntoBatches: (data: any[]) => any[][];