appwrite-utils-cli 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +80 -0
  2. package/dist/main.d.ts +2 -0
  3. package/dist/main.js +74 -0
  4. package/dist/migrations/afterImportActions.d.ts +12 -0
  5. package/dist/migrations/afterImportActions.js +196 -0
  6. package/dist/migrations/attributes.d.ts +4 -0
  7. package/dist/migrations/attributes.js +158 -0
  8. package/dist/migrations/backup.d.ts +621 -0
  9. package/dist/migrations/backup.js +159 -0
  10. package/dist/migrations/collections.d.ts +16 -0
  11. package/dist/migrations/collections.js +207 -0
  12. package/dist/migrations/converters.d.ts +179 -0
  13. package/dist/migrations/converters.js +575 -0
  14. package/dist/migrations/dbHelpers.d.ts +5 -0
  15. package/dist/migrations/dbHelpers.js +54 -0
  16. package/dist/migrations/importController.d.ts +44 -0
  17. package/dist/migrations/importController.js +312 -0
  18. package/dist/migrations/importDataActions.d.ts +44 -0
  19. package/dist/migrations/importDataActions.js +219 -0
  20. package/dist/migrations/indexes.d.ts +4 -0
  21. package/dist/migrations/indexes.js +18 -0
  22. package/dist/migrations/logging.d.ts +2 -0
  23. package/dist/migrations/logging.js +14 -0
  24. package/dist/migrations/migrationHelper.d.ts +18 -0
  25. package/dist/migrations/migrationHelper.js +66 -0
  26. package/dist/migrations/queue.d.ts +13 -0
  27. package/dist/migrations/queue.js +79 -0
  28. package/dist/migrations/relationships.d.ts +90 -0
  29. package/dist/migrations/relationships.js +209 -0
  30. package/dist/migrations/schema.d.ts +3142 -0
  31. package/dist/migrations/schema.js +485 -0
  32. package/dist/migrations/schemaStrings.d.ts +12 -0
  33. package/dist/migrations/schemaStrings.js +261 -0
  34. package/dist/migrations/setupDatabase.d.ts +7 -0
  35. package/dist/migrations/setupDatabase.js +151 -0
  36. package/dist/migrations/storage.d.ts +8 -0
  37. package/dist/migrations/storage.js +241 -0
  38. package/dist/migrations/users.d.ts +11 -0
  39. package/dist/migrations/users.js +114 -0
  40. package/dist/migrations/validationRules.d.ts +43 -0
  41. package/dist/migrations/validationRules.js +42 -0
  42. package/dist/schemas/authUser.d.ts +62 -0
  43. package/dist/schemas/authUser.js +17 -0
  44. package/dist/setup.d.ts +2 -0
  45. package/dist/setup.js +5 -0
  46. package/dist/types.d.ts +9 -0
  47. package/dist/types.js +5 -0
  48. package/dist/utils/configSchema.json +742 -0
  49. package/dist/utils/helperFunctions.d.ts +34 -0
  50. package/dist/utils/helperFunctions.js +72 -0
  51. package/dist/utils/index.d.ts +2 -0
  52. package/dist/utils/index.js +2 -0
  53. package/dist/utils/setupFiles.d.ts +2 -0
  54. package/dist/utils/setupFiles.js +276 -0
  55. package/dist/utilsController.d.ts +30 -0
  56. package/dist/utilsController.js +106 -0
  57. package/package.json +34 -0
  58. package/src/main.ts +77 -0
  59. package/src/migrations/afterImportActions.ts +300 -0
  60. package/src/migrations/attributes.ts +315 -0
  61. package/src/migrations/backup.ts +189 -0
  62. package/src/migrations/collections.ts +303 -0
  63. package/src/migrations/converters.ts +628 -0
  64. package/src/migrations/dbHelpers.ts +89 -0
  65. package/src/migrations/importController.ts +509 -0
  66. package/src/migrations/importDataActions.ts +313 -0
  67. package/src/migrations/indexes.ts +37 -0
  68. package/src/migrations/logging.ts +15 -0
  69. package/src/migrations/migrationHelper.ts +100 -0
  70. package/src/migrations/queue.ts +119 -0
  71. package/src/migrations/relationships.ts +336 -0
  72. package/src/migrations/schema.ts +590 -0
  73. package/src/migrations/schemaStrings.ts +310 -0
  74. package/src/migrations/setupDatabase.ts +219 -0
  75. package/src/migrations/storage.ts +351 -0
  76. package/src/migrations/users.ts +148 -0
  77. package/src/migrations/validationRules.ts +63 -0
  78. package/src/schemas/authUser.ts +23 -0
  79. package/src/setup.ts +8 -0
  80. package/src/types.ts +14 -0
  81. package/src/utils/configSchema.json +742 -0
  82. package/src/utils/helperFunctions.ts +111 -0
  83. package/src/utils/index.ts +2 -0
  84. package/src/utils/setupFiles.ts +295 -0
  85. package/src/utilsController.ts +173 -0
  86. package/tsconfig.json +37 -0
@@ -0,0 +1,159 @@
1
+ import { z } from "zod";
2
+ import { attributeSchema, parseAttribute, CollectionCreateSchema, } from "./schema.js";
3
+ export const BackupSchema = z.object({
4
+ $id: z.string(),
5
+ $createdAt: z.string(),
6
+ $updatedAt: z.string(),
7
+ database: z.string(),
8
+ collections: z.array(z.string()),
9
+ documents: z
10
+ .array(z.object({
11
+ collectionId: z.string(),
12
+ data: z.string(),
13
+ }))
14
+ .default([]),
15
+ });
16
+ export const BackupCreateSchema = BackupSchema.omit({
17
+ $id: true,
18
+ $createdAt: true,
19
+ $updatedAt: true,
20
+ });
21
+ export const BatchSchema = z.object({
22
+ $id: z.string(),
23
+ $createdAt: z.string(),
24
+ $updatedAt: z.string(),
25
+ data: z.string().describe("The serialized data for this batch"),
26
+ processed: z
27
+ .boolean()
28
+ .default(false)
29
+ .describe("Whether the batch has been processed"),
30
+ });
31
+ export const BatchCreateSchema = BatchSchema.omit({
32
+ $id: true,
33
+ $createdAt: true,
34
+ $updatedAt: true,
35
+ });
36
+ export const OperationSchema = z.object({
37
+ $id: z.string(),
38
+ $createdAt: z.string(),
39
+ $updatedAt: z.string(),
40
+ operationType: z.string(),
41
+ collectionId: z.string(),
42
+ data: z.any(),
43
+ batches: z.array(z.string()).default([]).optional(),
44
+ progress: z.number(),
45
+ total: z.number(),
46
+ error: z.string(),
47
+ status: z.enum(["pending", "in_progress", "completed", "error"]),
48
+ });
49
+ export const OperationCreateSchema = OperationSchema.omit({
50
+ $id: true,
51
+ $createdAt: true,
52
+ $updatedAt: true,
53
+ });
54
+ export const getMigrationCollectionSchemas = () => {
55
+ const currentOperationsAttributes = [
56
+ parseAttribute({
57
+ key: "operationType",
58
+ type: "string",
59
+ error: "Invalid Operation Type",
60
+ size: 50,
61
+ required: true,
62
+ array: false,
63
+ xdefault: null,
64
+ }),
65
+ attributeSchema.parse({
66
+ key: "collectionId",
67
+ type: "string",
68
+ error: "Invalid Collection Id",
69
+ size: 50,
70
+ array: false,
71
+ xdefault: null,
72
+ }),
73
+ attributeSchema.parse({
74
+ key: "batches",
75
+ type: "string",
76
+ error: "Invalid Batches",
77
+ size: 1073741824,
78
+ array: true,
79
+ }),
80
+ attributeSchema.parse({
81
+ key: "data",
82
+ type: "string",
83
+ error: "Invalid Data",
84
+ size: 1073741824,
85
+ }),
86
+ attributeSchema.parse({
87
+ key: "progress",
88
+ type: "integer",
89
+ error: "Invalid Progress",
90
+ required: true,
91
+ array: false,
92
+ }),
93
+ attributeSchema.parse({
94
+ key: "total",
95
+ type: "integer",
96
+ error: "Invalid Total",
97
+ required: true,
98
+ array: false,
99
+ }),
100
+ attributeSchema.parse({
101
+ key: "error",
102
+ type: "string",
103
+ error: "Operation Error",
104
+ required: false,
105
+ array: false,
106
+ }),
107
+ attributeSchema.parse({
108
+ key: "status",
109
+ type: "enum",
110
+ elements: ["pending", "in_progress", "completed", "error"],
111
+ error: "Invalid Status",
112
+ array: false,
113
+ xdefault: "pending",
114
+ }),
115
+ ];
116
+ const currentOperationsConfig = CollectionCreateSchema.parse({
117
+ name: "CurrentOperations",
118
+ enabled: true,
119
+ documentSecurity: false,
120
+ attributes: [],
121
+ indexes: [],
122
+ });
123
+ const batchesAttributes = [
124
+ attributeSchema.parse({
125
+ key: "data",
126
+ type: "string",
127
+ size: 1073741824,
128
+ error: "Invalid Data",
129
+ required: true,
130
+ array: false,
131
+ }),
132
+ attributeSchema.parse({
133
+ key: "processed",
134
+ type: "boolean",
135
+ error: "Invalid Processed",
136
+ required: true,
137
+ array: false,
138
+ xdefault: false,
139
+ }),
140
+ ];
141
+ const batchesConfig = CollectionCreateSchema.parse({
142
+ name: "Batches",
143
+ enabled: true,
144
+ documentSecurity: false,
145
+ attributes: [],
146
+ indexes: [],
147
+ });
148
+ const toReturn = {
149
+ CurrentOperations: {
150
+ collection: currentOperationsConfig,
151
+ attributes: currentOperationsAttributes,
152
+ },
153
+ Batches: {
154
+ collection: batchesConfig,
155
+ attributes: batchesAttributes,
156
+ },
157
+ };
158
+ return toReturn;
159
+ };
@@ -0,0 +1,16 @@
1
+ import { Databases, type Models } from "node-appwrite";
2
+ import type { AppwriteConfig, CollectionCreate } from "./schema.js";
3
+ export declare const documentExists: (db: Databases, dbId: string, targetCollectionId: string, toCreateObject: any) => Promise<Models.Document | null>;
4
+ export declare const checkForCollection: (db: Databases, dbId: string, collection: Partial<CollectionCreate>) => Promise<Models.Collection | null>;
5
+ export declare const fetchAndCacheCollectionByName: (db: Databases, dbId: string, collectionName: string) => Promise<Models.Collection | undefined>;
6
+ export declare const wipeDatabase: (database: Databases, databaseId: string) => Promise<{
7
+ collectionId: string;
8
+ collectionName: string;
9
+ }[]>;
10
+ export declare const generateSchemas: (config: AppwriteConfig, appwriteFolderPath: string) => Promise<void>;
11
+ export declare const createOrUpdateCollections: (database: Databases, databaseId: string, config: AppwriteConfig, deletedCollections?: {
12
+ collectionId: string;
13
+ collectionName: string;
14
+ }[]) => Promise<void>;
15
+ export declare const generateMockData: (database: Databases, databaseId: string, configCollections: any[]) => Promise<void>;
16
+ export declare const fetchAllCollections: (dbId: string, database: Databases) => Promise<Models.Collection[]>;
@@ -0,0 +1,207 @@
1
+ import { Databases, ID, Permission, Query } from "node-appwrite";
2
+ import { nameToIdMapping, processQueue } from "./queue.js";
3
+ import { createUpdateCollectionAttributes } from "./attributes.js";
4
+ import { createOrUpdateIndexes } from "./indexes.js";
5
+ import { ensureDirectoryExistence, toCamelCase, toPascalCase, writeFileSync, } from "../utils/index.js";
6
+ import _ from "lodash";
7
+ import { SchemaGenerator } from "./schemaStrings.js";
8
+ import path from "path";
9
+ const { join } = _;
10
+ export const documentExists = async (db, dbId, targetCollectionId, toCreateObject) => {
11
+ // Had to do this because kept running into issues with type checking arrays so, sorry 40ms
12
+ const collection = await db.getCollection(dbId, targetCollectionId);
13
+ const attributes = collection.attributes;
14
+ let arrayTypeAttributes = attributes
15
+ .filter((attribute) => attribute.array === true)
16
+ .map((attribute) => attribute.key);
17
+ // Function to check if a string is JSON
18
+ const isJsonString = (str) => {
19
+ try {
20
+ const json = JSON.parse(str);
21
+ return typeof json === "object" && json !== null; // Check if parsed JSON is an object or array
22
+ }
23
+ catch (e) {
24
+ return false;
25
+ }
26
+ };
27
+ // Validate and prepare query parameters
28
+ const validQueryParams = _.chain(toCreateObject)
29
+ .pickBy((value, key) => !arrayTypeAttributes.includes(key) &&
30
+ !key.startsWith("$") &&
31
+ !_.isNull(value) &&
32
+ !_.isUndefined(value) &&
33
+ !_.isEmpty(value) &&
34
+ !_.isObject(value) && // Keeps excluding objects
35
+ !_.isArray(value) && // Explicitly exclude arrays
36
+ !(_.isString(value) && isJsonString(value)) && // Exclude JSON strings
37
+ (_.isString(value) ? value.length < 4096 && value.length > 0 : true) // String length check
38
+ )
39
+ .mapValues((value, key) => _.isString(value) || _.isNumber(value) || _.isBoolean(value)
40
+ ? value
41
+ : null)
42
+ .omitBy(_.isNull) // Remove any null values that might have been added in mapValues
43
+ .toPairs()
44
+ .slice(0, 25) // Limit to 25 to adhere to query limit
45
+ .map(([key, value]) => Query.equal(key, value))
46
+ .value();
47
+ // Execute the query with the validated and prepared parameters
48
+ const result = await db.listDocuments(dbId, targetCollectionId, validQueryParams);
49
+ return result.documents[0] || null;
50
+ };
51
+ export const checkForCollection = async (db, dbId, collection) => {
52
+ try {
53
+ console.log(`Checking for collection with name: ${collection.name}`);
54
+ const response = await db.listCollections(dbId, [
55
+ Query.equal("name", collection.name),
56
+ ]);
57
+ if (response.collections.length > 0) {
58
+ console.log(`Collection found: ${response.collections[0].$id}`);
59
+ return { ...collection, ...response.collections[0] };
60
+ }
61
+ else {
62
+ console.log(`No collection found with name: ${collection.name}`);
63
+ return null;
64
+ }
65
+ }
66
+ catch (error) {
67
+ console.error(`Error checking for collection: ${error}`);
68
+ return null;
69
+ }
70
+ };
71
+ // Helper function to fetch and cache collection by name
72
+ export const fetchAndCacheCollectionByName = async (db, dbId, collectionName) => {
73
+ if (nameToIdMapping.has(collectionName)) {
74
+ const collectionId = nameToIdMapping.get(collectionName);
75
+ console.log(`\tCollection found in cache: ${collectionId}`);
76
+ return await db.getCollection(dbId, collectionId);
77
+ }
78
+ else {
79
+ console.log(`\tFetching collection by name: ${collectionName}`);
80
+ const collectionsPulled = await db.listCollections(dbId, [
81
+ Query.equal("name", collectionName),
82
+ ]);
83
+ if (collectionsPulled.total > 0) {
84
+ const collection = collectionsPulled.collections[0];
85
+ console.log(`\tCollection found: ${collection.$id}`);
86
+ nameToIdMapping.set(collectionName, collection.$id);
87
+ return collection;
88
+ }
89
+ else {
90
+ console.log(`\tCollection not found by name: ${collectionName}`);
91
+ return undefined;
92
+ }
93
+ }
94
+ };
95
+ export const wipeDatabase = async (database, databaseId) => {
96
+ console.log(`Wiping database: ${databaseId}`);
97
+ const { collections: existingCollections } = await database.listCollections(databaseId);
98
+ let collectionsDeleted = [];
99
+ for (const { $id: collectionId, name: name } of existingCollections) {
100
+ console.log(`Deleting collection: ${collectionId}`);
101
+ collectionsDeleted.push({
102
+ collectionId: collectionId,
103
+ collectionName: name,
104
+ });
105
+ await database.deleteCollection(databaseId, collectionId);
106
+ }
107
+ return collectionsDeleted;
108
+ };
109
+ export const generateSchemas = async (config, appwriteFolderPath) => {
110
+ const schemaGenerator = new SchemaGenerator(config, appwriteFolderPath);
111
+ schemaGenerator.generateSchemas();
112
+ };
113
+ export const createOrUpdateCollections = async (database, databaseId, config, deletedCollections) => {
114
+ const configCollections = config.collections;
115
+ for (const { attributes, indexes, ...collection } of configCollections) {
116
+ let collectionsFound = await database.listCollections(databaseId, [
117
+ Query.equal("name", collection.name),
118
+ ]);
119
+ const permissions = [];
120
+ if (collection.$permissions.length > 0) {
121
+ for (const permission of collection.$permissions) {
122
+ switch (permission.permission) {
123
+ case "read":
124
+ permissions.push(Permission.read(permission.target));
125
+ break;
126
+ case "create":
127
+ permissions.push(Permission.create(permission.target));
128
+ break;
129
+ case "update":
130
+ permissions.push(Permission.update(permission.target));
131
+ break;
132
+ case "delete":
133
+ permissions.push(Permission.delete(permission.target));
134
+ break;
135
+ case "write":
136
+ permissions.push(Permission.write(permission.target));
137
+ break;
138
+ default:
139
+ console.log(`Unknown permission: ${permission.permission}`);
140
+ break;
141
+ }
142
+ }
143
+ }
144
+ let collectionToUse = collectionsFound.total > 0 ? collectionsFound.collections[0] : null;
145
+ if (!collectionToUse) {
146
+ console.log(`Creating collection: ${collection.name}`);
147
+ if (deletedCollections && deletedCollections.length > 0) {
148
+ const foundColl = deletedCollections.find((coll) => coll.collectionName.toLowerCase().trim().replace(" ", "") ===
149
+ collection.name.toLowerCase().trim().replace(" ", ""));
150
+ if (foundColl) {
151
+ const collectionId = foundColl.collectionId || ID.unique();
152
+ console.log(`Processing collection: ${collection.name} with ID: ${collectionId}`);
153
+ collectionToUse = await database.createCollection(databaseId, collectionId, collection.name, permissions, collection.documentSecurity, collection.enabled);
154
+ nameToIdMapping.set(collection.name, collectionToUse.$id);
155
+ }
156
+ else {
157
+ collectionToUse = await database.createCollection(databaseId, ID.unique(), collection.name, permissions, collection.documentSecurity, collection.enabled);
158
+ nameToIdMapping.set(collection.name, collectionToUse.$id);
159
+ }
160
+ }
161
+ else {
162
+ collectionToUse = await database.createCollection(databaseId, ID.unique(), collection.name, permissions, collection.documentSecurity, collection.enabled);
163
+ nameToIdMapping.set(collection.name, collectionToUse.$id);
164
+ }
165
+ }
166
+ else {
167
+ console.log(`Collection ${collection.name} already exists.`);
168
+ }
169
+ console.log("Creating Attributes");
170
+ await createUpdateCollectionAttributes(database, databaseId, collectionToUse, attributes);
171
+ console.log("Creating Indexes");
172
+ await createOrUpdateIndexes(databaseId, database, collectionToUse.$id, indexes);
173
+ }
174
+ await processQueue(database, databaseId);
175
+ };
176
+ export const generateMockData = async (database, databaseId, configCollections) => {
177
+ for (const { collection, mockFunction } of configCollections) {
178
+ if (mockFunction) {
179
+ console.log(`Generating mock data for collection: ${collection.name}`);
180
+ const mockData = mockFunction();
181
+ for (const data of mockData) {
182
+ await database.createDocument(databaseId, collection.$id, ID.unique(), data);
183
+ }
184
+ }
185
+ }
186
+ };
187
+ export const fetchAllCollections = async (dbId, database) => {
188
+ console.log(`Fetching all collections for database ID: ${dbId}`);
189
+ let collections = [];
190
+ let moreCollections = true;
191
+ let lastCollectionId;
192
+ while (moreCollections) {
193
+ const queries = [Query.limit(500)];
194
+ if (lastCollectionId) {
195
+ queries.push(Query.cursorAfter(lastCollectionId));
196
+ }
197
+ const response = await database.listCollections(dbId, queries);
198
+ collections = collections.concat(response.collections);
199
+ moreCollections = response.collections.length === 500;
200
+ if (moreCollections) {
201
+ lastCollectionId =
202
+ response.collections[response.collections.length - 1].$id;
203
+ }
204
+ }
205
+ console.log(`Fetched a total of ${collections.length} collections.`);
206
+ return collections;
207
+ };
@@ -0,0 +1,179 @@
1
+ export interface ConverterFunctions {
2
+ [key: string]: (value: any) => any;
3
+ }
4
+ export declare const converterFunctions: {
5
+ /**
6
+ * Converts any value to a string. Handles null and undefined explicitly.
7
+ * @param {any} value The value to convert.
8
+ * @return {string | null} The converted string or null if the value is null or undefined.
9
+ */
10
+ anyToString(value: any): string | null;
11
+ /**
12
+ * Converts any value to a number. Returns null for non-numeric values, null, or undefined.
13
+ * @param {any} value The value to convert.
14
+ * @return {number | null} The converted number or null.
15
+ */
16
+ anyToNumber(value: any): number | null;
17
+ /**
18
+ * Converts any value to a boolean. Specifically handles string representations.
19
+ * @param {any} value The value to convert.
20
+ * @return {boolean | null} The converted boolean or null if conversion is not possible.
21
+ */
22
+ anyToBoolean(value: any): boolean | null;
23
+ /**
24
+ * Converts any value to an array, attempting to split strings by a specified separator.
25
+ * @param {any} value The value to convert.
26
+ * @param {string | undefined} separator The separator to use when splitting strings.
27
+ * @return {any[]} The resulting array after conversion.
28
+ */
29
+ anyToAnyArray(value: any): any[];
30
+ /**
31
+ * Converts any value to an array of strings. If the input is already an array, returns it as is.
32
+ * Otherwise, if the input is a string, returns an array with the string as the only element.
33
+ * Otherwise, returns an empty array.
34
+ * @param {any} value The value to convert.
35
+ * @return {string[]} The resulting array after conversion.
36
+ */
37
+ anyToStringArray(value: any): string[];
38
+ /**
39
+ * A function that converts any type of value to an array of numbers.
40
+ *
41
+ * @param {any} value - the value to be converted
42
+ * @return {number[]} an array of numbers
43
+ */
44
+ anyToNumberArray(value: any): number[];
45
+ trim(value: string): string;
46
+ /**
47
+ * Removes the start and end quotes from a string.
48
+ * @param value The string to remove quotes from.
49
+ * @return The string with quotes removed.
50
+ **/
51
+ removeStartEndQuotes(value: string): string;
52
+ /**
53
+ * Tries to split a string by different separators and returns the split that has the most uniform segment lengths.
54
+ * This can be particularly useful for structured data like phone numbers.
55
+ * @param value The string to split.
56
+ * @return The split string array that has the most uniform segment lengths.
57
+ */
58
+ trySplitByDifferentSeparators(value: string): string[];
59
+ joinValues(values: any[]): any;
60
+ joinBySpace(values: any[]): any;
61
+ joinByComma(values: any[]): any;
62
+ joinByPipe(values: any[]): any;
63
+ joinBySemicolon(values: any[]): any;
64
+ joinByColon(values: any[]): any;
65
+ joinBySlash(values: any[]): any;
66
+ joinByHyphen(values: any[]): any;
67
+ splitByComma(value: string): any;
68
+ splitByPipe(value: string): any;
69
+ splitBySemicolon(value: string): any;
70
+ splitByColon(value: string): any;
71
+ splitBySlash(value: string): any;
72
+ splitByBackslash(value: string): any;
73
+ splitBySpace(value: string): any;
74
+ splitByDot(value: string): any;
75
+ splitByUnderscore(value: string): any;
76
+ splitByHyphen(value: string): any;
77
+ /**
78
+ * Takes the first element of an array and returns it.
79
+ * @param {any[]} value The array to take the first element from.
80
+ * @return {any} The first element of the array.
81
+ */
82
+ pickFirstElement(value: any[]): any;
83
+ /**
84
+ * Takes the last element of an array and returns it.
85
+ * @param {any[]} value The array to take the last element from.
86
+ * @return {any} The last element of the array.
87
+ */
88
+ pickLastElement(value: any[]): any;
89
+ /**
90
+ * Converts an object to a JSON string.
91
+ * @param {any} object The object to convert.
92
+ * @return {string} The JSON string representation of the object.
93
+ */
94
+ stringifyObject(object: any): string;
95
+ /**
96
+ * Converts a JSON string to an object.
97
+ * @param {string} jsonString The JSON string to convert.
98
+ * @return {any} The object representation of the JSON string.
99
+ */
100
+ parseObject(jsonString: string): any;
101
+ convertPhoneStringToUSInternational(value: string): string;
102
+ convertEmptyToNull(value: any): any;
103
+ /**
104
+ * A function that removes invalid elements from an array
105
+ *
106
+ * @param {any[]} array - the input array
107
+ * @return {any[]} the filtered array without invalid elements
108
+ */
109
+ removeInvalidElements(array: any[]): any[];
110
+ validateOrNullEmail(email: string): string | null;
111
+ /**
112
+ * Tries to parse a date from various formats using Luxon with enhanced error reporting.
113
+ * @param {string | number} input The input date as a string or timestamp.
114
+ * @return {string | null} The parsed date in ISO 8601 format or null if parsing failed.
115
+ */
116
+ safeParseDate(input: string | number): string | null;
117
+ };
118
+ /**
119
+ * Deeply converts all properties of an object (or array) to strings.
120
+ * @param data The input data to convert.
121
+ * @returns The data with all its properties converted to strings.
122
+ */
123
+ export declare const deepAnyToString: (data: any) => any;
124
+ /**
125
+ * Performs a deep conversion of all values in a nested structure to the specified type.
126
+ * Uses a conversion function like anyToString, anyToNumber, etc.
127
+ * @param data The data to convert.
128
+ * @param convertFn The conversion function to apply.
129
+ * @returns The converted data.
130
+ */
131
+ export declare const deepConvert: <T>(data: any, convertFn: (value: any) => T) => any;
132
+ /**
133
+ * Converts an entire object's properties to different types based on a provided schema.
134
+ * @param obj The object to convert.
135
+ * @param schema A mapping of object keys to conversion functions.
136
+ * @returns The converted object.
137
+ */
138
+ export declare const convertObjectBySchema: (obj: Record<string, any>, schema: Record<string, (value: any) => any>) => Record<string, any>;
139
+ /**
140
+ * Converts the keys of an object based on a provided attributeMappings.
141
+ * Each key in the object is checked against attributeMappings; if a matching entry is found,
142
+ * the key is renamed to the targetKey specified in attributeMappings.
143
+ *
144
+ * @param obj The object to convert.
145
+ * @param attributeMappings The attributeMappings defining how keys in the object should be converted.
146
+ * @returns The converted object with keys renamed according to attributeMappings.
147
+ */
148
+ export declare const convertObjectByAttributeMappings: (obj: Record<string, any>, attributeMappings: {
149
+ targetKey: string;
150
+ converters: string[];
151
+ validationActions: {
152
+ params: string[];
153
+ action: string;
154
+ }[];
155
+ postImportActions: {
156
+ params: (string | Record<string, any>)[];
157
+ action: string;
158
+ }[];
159
+ oldKey?: string | undefined;
160
+ oldKeys?: string[] | undefined;
161
+ fileData?: {
162
+ path: string;
163
+ name: string;
164
+ } | undefined;
165
+ }[]) => Record<string, any>;
166
+ /**
167
+ * Ensures data conversion without mutating the original input.
168
+ * @param data The data to convert.
169
+ * @param convertFn The conversion function to apply.
170
+ * @returns The converted data.
171
+ */
172
+ export declare const immutableConvert: <T>(data: any, convertFn: (value: any) => T) => T;
173
+ /**
174
+ * Validates a string against a regular expression and returns the string if valid, or null.
175
+ * @param value The string to validate.
176
+ * @param pattern The regex pattern to validate against.
177
+ * @returns The original string if valid, otherwise null.
178
+ */
179
+ export declare const validateString: (value: string, pattern: RegExp) => string | null;