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.
754 lines (753 loc) • 34.7 kB
TypeScript
import type { ImportDataActions } from "./importDataActions.js";
import { type AppwriteConfig, type AttributeMappings, type CollectionCreate, type ConfigDatabase, type ImportDef } from "appwrite-utils";
import { z } from "zod";
import { type Databases } from "node-appwrite";
import { AuthUserCreateSchema } from "../schemas/authUser.js";
export declare const CollectionImportDataSchema: z.ZodObject<{
collection: z.ZodOptional<z.ZodObject<{
name: z.ZodString;
attributes: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodObject<{
key: z.ZodString;
type: z.ZodString;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
error: z.ZodOptional<z.ZodString>;
required: z.ZodOptional<z.ZodBoolean>;
array: z.ZodOptional<z.ZodBoolean>;
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
xdefault: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
format: z.ZodOptional<z.ZodString>;
size: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
min: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
max: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
elements: z.ZodOptional<z.ZodArray<z.ZodString>>;
encrypt: z.ZodOptional<z.ZodBoolean>;
relatedCollection: z.ZodOptional<z.ZodString>;
relationType: z.ZodOptional<z.ZodString>;
twoWay: z.ZodOptional<z.ZodBoolean>;
twoWayKey: z.ZodOptional<z.ZodString>;
onDelete: z.ZodOptional<z.ZodString>;
side: z.ZodOptional<z.ZodString>;
importMapping: z.ZodOptional<z.ZodObject<{
originalIdField: z.ZodString;
targetField: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>;
}, z.core.$loose>, z.ZodDiscriminatedUnion<[z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"string">;
size: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
xdefault: z.ZodOptional<z.ZodNullable<z.ZodString>>;
encrypt: z.ZodOptional<z.ZodBoolean>;
}, z.core.$strip>, z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"integer">;
min: z.ZodOptional<z.ZodNumber>;
max: z.ZodOptional<z.ZodNumber>;
xdefault: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
}, z.core.$strip>, z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"double">;
min: z.ZodOptional<z.ZodNumber>;
max: z.ZodOptional<z.ZodNumber>;
xdefault: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
}, z.core.$strip>, z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"float">;
min: z.ZodOptional<z.ZodNumber>;
max: z.ZodOptional<z.ZodNumber>;
xdefault: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
}, z.core.$strip>, z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"boolean">;
xdefault: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
}, z.core.$strip>, z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"datetime">;
xdefault: z.ZodOptional<z.ZodNullable<z.ZodString>>;
}, z.core.$strip>, z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"email">;
xdefault: z.ZodOptional<z.ZodNullable<z.ZodString>>;
}, z.core.$strip>, z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"ip">;
xdefault: z.ZodOptional<z.ZodNullable<z.ZodString>>;
}, z.core.$strip>, z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"url">;
xdefault: z.ZodOptional<z.ZodNullable<z.ZodString>>;
}, z.core.$strip>, z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"enum">;
elements: z.ZodDefault<z.ZodArray<z.ZodString>>;
xdefault: z.ZodOptional<z.ZodNullable<z.ZodString>>;
}, z.core.$strip>, z.ZodObject<{
array: z.ZodOptional<z.ZodBoolean>;
format: z.ZodOptional<z.ZodString>;
key: z.ZodString;
status: z.ZodOptional<z.ZodString>;
attributes: z.ZodOptional<z.ZodArray<z.ZodString>>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
$createdAt: z.ZodOptional<z.ZodString>;
$updatedAt: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
type: z.ZodLiteral<"relationship">;
relatedCollection: z.ZodString;
relationType: z.ZodEnum<{
oneToMany: "oneToMany";
manyToOne: "manyToOne";
oneToOne: "oneToOne";
manyToMany: "manyToMany";
}>;
twoWay: z.ZodBoolean;
twoWayKey: z.ZodOptional<z.ZodString>;
onDelete: z.ZodDefault<z.ZodEnum<{
setNull: "setNull";
cascade: "cascade";
restrict: "restrict";
}>>;
side: z.ZodOptional<z.ZodEnum<{
parent: "parent";
child: "child";
}>>;
importMapping: z.ZodOptional<z.ZodObject<{
originalIdField: z.ZodString;
targetField: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>;
}, z.core.$strip>], "type">>>>;
$id: z.ZodOptional<z.ZodString>;
enabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
documentSecurity: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
$permissions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
permission: z.ZodString;
target: z.ZodString;
}, z.core.$strip>>>>;
indexes: z.ZodPipe<z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
key: z.ZodString;
type: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
key: "key";
unique: "unique";
fulltext: "fulltext";
}>>>;
status: z.ZodOptional<z.ZodString>;
error: z.ZodOptional<z.ZodString>;
attributes: z.ZodArray<z.ZodString>;
orders: z.ZodOptional<z.ZodArray<z.ZodString>>;
}, z.core.$strip>>>>, z.ZodTransform<{
key: string;
type: "key" | "unique" | "fulltext";
attributes: string[];
status?: string | undefined;
error?: string | undefined;
orders?: string[] | undefined;
}[], {
key: string;
type: "key" | "unique" | "fulltext";
attributes: string[];
status?: string | undefined;
error?: string | undefined;
orders?: string[] | undefined;
}[]>>;
importDefs: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
type: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
create: "create";
update: "update";
}>>>;
filePath: z.ZodString;
basePath: z.ZodOptional<z.ZodString>;
primaryKeyField: z.ZodDefault<z.ZodString>;
idMappings: z.ZodOptional<z.ZodArray<z.ZodObject<{
sourceField: z.ZodString;
fieldToSet: z.ZodOptional<z.ZodString>;
targetFieldToMatch: z.ZodOptional<z.ZodString>;
targetField: z.ZodString;
targetCollection: z.ZodString;
}, z.core.$strip>>>;
createUsers: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodBoolean>>>;
updateMapping: z.ZodOptional<z.ZodObject<{
originalIdField: z.ZodString;
targetField: z.ZodString;
}, z.core.$strip>>;
attributeMappings: 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<{
name: z.ZodString;
path: z.ZodString;
}, z.core.$strip>>;
converters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString>>>;
validationActions: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
action: z.ZodString;
params: z.ZodArray<z.ZodString>;
}, z.core.$strip>>>>;
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>]>>;
}, z.core.$strip>>>>;
}, z.core.$strip>>;
}, z.core.$strip>>>>;
databaseId: z.ZodOptional<z.ZodString>;
databaseIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
}, z.core.$strip>>;
data: z.ZodArray<z.ZodObject<{
rawData: z.ZodAny;
finalData: z.ZodAny;
context: z.ZodAny;
importDef: z.ZodOptional<z.ZodObject<{
type: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
create: "create";
update: "update";
}>>>;
filePath: z.ZodString;
basePath: z.ZodOptional<z.ZodString>;
primaryKeyField: z.ZodDefault<z.ZodString>;
idMappings: z.ZodOptional<z.ZodArray<z.ZodObject<{
sourceField: z.ZodString;
fieldToSet: z.ZodOptional<z.ZodString>;
targetFieldToMatch: z.ZodOptional<z.ZodString>;
targetField: z.ZodString;
targetCollection: z.ZodString;
}, z.core.$strip>>>;
createUsers: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodBoolean>>>;
updateMapping: z.ZodOptional<z.ZodObject<{
originalIdField: z.ZodString;
targetField: z.ZodString;
}, z.core.$strip>>;
attributeMappings: 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<{
name: z.ZodString;
path: z.ZodString;
}, z.core.$strip>>;
converters: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString>>>;
validationActions: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
action: z.ZodString;
params: z.ZodArray<z.ZodString>;
}, z.core.$strip>>>>;
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>]>>;
}, z.core.$strip>>>>;
}, z.core.$strip>>;
}, z.core.$strip>>;
}, z.core.$strip>>;
}, z.core.$strip>;
export type CollectionImportData = z.infer<typeof CollectionImportDataSchema>;
export declare class DataLoader {
private appwriteFolderPath;
private importDataActions;
private database;
private usersController;
private config;
importMap: Map<string, {
data: {
rawData: any;
finalData: any;
context: any;
importDef?: {
filePath: string;
primaryKeyField: string;
attributeMappings: {
targetKey: string;
oldKey?: string | undefined;
oldKeys?: string[] | undefined;
valueToSet?: any;
fileData?: {
name: string;
path: string;
} | undefined;
converters?: string[] | undefined;
validationActions?: {
action: string;
params: string[];
}[] | undefined;
postImportActions?: {
action: string;
params: (string | Record<string, any>)[];
}[] | undefined;
}[];
type?: "create" | "update" | undefined;
basePath?: string | undefined;
idMappings?: {
sourceField: string;
targetField: string;
targetCollection: string;
fieldToSet?: string | undefined;
targetFieldToMatch?: string | undefined;
}[] | undefined;
createUsers?: boolean | null | undefined;
updateMapping?: {
originalIdField: string;
targetField: string;
} | undefined;
} | undefined;
}[];
collection?: {
name: string;
attributes: ({
key: string;
required: boolean;
type: "string";
size: number;
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
xdefault?: string | null | undefined;
encrypt?: boolean | undefined;
} | {
key: string;
required: boolean;
type: "integer";
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
min?: number | undefined;
max?: number | undefined;
xdefault?: number | null | undefined;
} | {
key: string;
required: boolean;
type: "double";
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
min?: number | undefined;
max?: number | undefined;
xdefault?: number | null | undefined;
} | {
key: string;
required: boolean;
type: "float";
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
min?: number | undefined;
max?: number | undefined;
xdefault?: number | null | undefined;
} | {
key: string;
required: boolean;
type: "boolean";
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
xdefault?: boolean | null | undefined;
} | {
key: string;
required: boolean;
type: "datetime";
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
xdefault?: string | null | undefined;
} | {
key: string;
required: boolean;
type: "email";
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
xdefault?: string | null | undefined;
} | {
key: string;
required: boolean;
type: "ip";
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
xdefault?: string | null | undefined;
} | {
key: string;
required: boolean;
type: "url";
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
xdefault?: string | null | undefined;
} | {
key: string;
required: boolean;
type: "enum";
elements: string[];
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
xdefault?: string | null | undefined;
} | {
key: string;
required: boolean;
type: "relationship";
relatedCollection: string;
relationType: "oneToMany" | "manyToOne" | "oneToOne" | "manyToMany";
twoWay: boolean;
onDelete: "setNull" | "cascade" | "restrict";
array?: boolean | undefined;
format?: string | undefined;
status?: string | undefined;
attributes?: string[] | undefined;
orders?: string[] | undefined;
$createdAt?: string | undefined;
$updatedAt?: string | undefined;
error?: string | undefined;
twoWayKey?: string | undefined;
side?: "parent" | "child" | undefined;
importMapping?: {
originalIdField: string;
targetField?: string | undefined;
} | undefined;
})[];
$permissions: {
permission: string;
target: string;
}[];
indexes: {
key: string;
type: "key" | "unique" | "fulltext";
attributes: string[];
status?: string | undefined;
error?: string | undefined;
orders?: string[] | undefined;
}[];
importDefs: {
filePath: string;
primaryKeyField: string;
attributeMappings: {
targetKey: string;
oldKey?: string | undefined;
oldKeys?: string[] | undefined;
valueToSet?: any;
fileData?: {
name: string;
path: string;
} | undefined;
converters?: string[] | undefined;
validationActions?: {
action: string;
params: string[];
}[] | undefined;
postImportActions?: {
action: string;
params: (string | Record<string, any>)[];
}[] | undefined;
}[];
type?: "create" | "update" | undefined;
basePath?: string | undefined;
idMappings?: {
sourceField: string;
targetField: string;
targetCollection: string;
fieldToSet?: string | undefined;
targetFieldToMatch?: string | undefined;
}[] | undefined;
createUsers?: boolean | null | undefined;
updateMapping?: {
originalIdField: string;
targetField: string;
} | undefined;
}[];
$id?: string | undefined;
enabled?: boolean | undefined;
documentSecurity?: boolean | undefined;
databaseId?: string | undefined;
databaseIds?: string[] | undefined;
} | undefined;
}>;
private oldIdToNewIdPerCollectionMap;
collectionImportOperations: Map<string, string>;
private mergedUserMap;
private emailToUserIdMap;
private phoneToUserIdMap;
private userIdSet;
userExistsMap: Map<string, boolean>;
private shouldWriteFile;
constructor(appwriteFolderPath: string, importDataActions: ImportDataActions, database: Databases, config: AppwriteConfig, shouldWriteFile?: boolean);
getCollectionKey(name: string): string;
/**
* Merges two objects by updating the source object with the target object's values.
* It iterates through the target object's keys and updates the source object if:
* - The source object has the key.
* - The target object's value for that key is not null, undefined, or an empty string.
* - If the target object has an array value, it concatenates the values and removes duplicates.
*
* @param source - The source object to be updated.
* @param target - The target object with values to update the source object.
* @returns The updated source object.
*/
mergeObjects(source: any, update: any): any;
loadData(importDef: ImportDef): any[];
checkMapValuesForId(newId: string, collectionName: string): string | false;
getTrueUniqueId(collectionName: string): string;
createContext(db: ConfigDatabase, collection: CollectionCreate, item: any, docId: string): any;
/**
* Transforms the given item based on the provided attribute mappings.
* This method applies conversion rules to the item's attributes as defined in the attribute mappings.
*
* @param item - The item to be transformed.
* @param attributeMappings - The mappings that define how each attribute should be transformed.
* @returns The transformed item.
*/
transformData(item: any, attributeMappings: AttributeMappings): any;
setupMaps(dbId: string): Promise<void>;
getAllUsers(): Promise<import("node-appwrite").Models.User<import("node-appwrite").Models.Preferences>[]>;
start(dbId: string): Promise<void>;
/**
* Deals with merged users by iterating through all collections in the configuration.
* We have merged users if there are duplicate emails or phones in the import data.
* This function will iterate through all collections that are the same name as the
* users collection and pull out their primaryKeyField's. It will then loop through
* each collection and find any documents that have a
*
* @return {void} This function does not return anything.
*/
/**
* Gets the value to match for a given key in the final data or context.
* @param finalData - The final data object.
* @param context - The context object.
* @param key - The key to get the value for.
* @returns The value to match for from finalData or Context
*/
getValueFromData(finalData: any, context: any, key: string): any;
updateOldReferencesForNew(): void;
private writeMapsToJsonFile;
/**
* Prepares user data by checking for duplicates based on email or phone, adding to a duplicate map if found,
* and then returning the transformed item without user-specific keys.
*
* @param item - The raw item to be processed.
* @param attributeMappings - The attribute mappings for the item.
* @returns The transformed item with user-specific keys removed.
*/
prepareUserData(item: any, attributeMappings: AttributeMappings, primaryKeyField: string, newId: string): {
transformedItem: any;
existingId: string | undefined;
userData: {
rawData: any;
finalData: z.infer<typeof AuthUserCreateSchema>;
};
};
/**
* Prepares the data for creating user collection documents.
* This involves loading the data, transforming it according to the import definition,
* and handling the creation of new unique IDs for each item.
*
* @param db - The database configuration.
* @param collection - The collection configuration.
* @param importDef - The import definition containing the attribute mappings and other relevant info.
*/
prepareUserCollectionCreateData(db: ConfigDatabase, collection: CollectionCreate, importDef: ImportDef): Promise<void>;
/**
* Prepares the data for creating documents in a collection.
* This involves loading the data, transforming it, and handling ID mappings.
*
* @param db - The database configuration.
* @param collection - The collection configuration.
* @param importDef - The import definition containing the attribute mappings and other relevant info.
*/
prepareCreateData(db: ConfigDatabase, collection: CollectionCreate, importDef: ImportDef): Promise<void>;
/**
* Prepares the data for updating documents within a collection.
* This method loads the raw data based on the import definition, transforms it according to the attribute mappings,
* finds the new ID for each item based on the primary key or update mapping, and then validates the transformed data.
* If the data is valid, it updates the import definition with any post-import actions and adds the item to the current collection data.
*
* @param db - The database configuration.
* @param collection - The collection configuration.
* @param importDef - The import definition containing the attribute mappings and other relevant info.
*/
prepareUpdateData(db: ConfigDatabase, collection: CollectionCreate, importDef: ImportDef): Promise<void>;
private updateReferencesBasedOnAttributeMappings;
private getMergedId;
/**
* Generates attribute mappings with post-import actions based on the provided attribute mappings.
* This method checks each mapping for a fileData attribute and adds a post-import action to create a file
* and update the field with the file's ID if necessary.
*
* @param attributeMappings - The attribute mappings from the import definition.
* @param context - The context object containing information about the database, collection, and document.
* @param item - The item being imported, used for resolving template paths in fileData mappings.
* @returns The attribute mappings updated with any necessary post-import actions.
*/
getAttributeMappingsWithActions(attributeMappings: AttributeMappings, context: any, item: any): ({
targetKey: string;
oldKey?: string | undefined;
oldKeys?: string[] | undefined;
valueToSet?: any;
fileData?: {
name: string;
path: string;
} | undefined;
converters?: string[] | undefined;
validationActions?: {
action: string;
params: string[];
}[] | undefined;
postImportActions?: {
action: string;
params: (string | Record<string, any>)[];
}[] | undefined;
} | {
postImportActions: {
action: string;
params: any[];
}[];
targetKey: string;
oldKey?: string | undefined;
oldKeys?: string[] | undefined;
valueToSet?: any;
fileData?: {
name: string;
path: string;
} | undefined;
converters?: string[] | undefined;
validationActions?: {
action: string;
params: string[];
}[] | undefined;
})[];
}