appwrite-utils-cli 0.0.285 → 0.9.0
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.
- package/README.md +122 -96
- package/dist/collections/attributes.d.ts +4 -0
- package/dist/collections/attributes.js +224 -0
- package/dist/collections/indexes.d.ts +4 -0
- package/dist/collections/indexes.js +27 -0
- package/dist/collections/methods.d.ts +16 -0
- package/dist/collections/methods.js +216 -0
- package/dist/databases/methods.d.ts +6 -0
- package/dist/databases/methods.js +33 -0
- package/dist/interactiveCLI.d.ts +19 -0
- package/dist/interactiveCLI.js +555 -0
- package/dist/main.js +227 -62
- package/dist/migrations/afterImportActions.js +37 -40
- package/dist/migrations/appwriteToX.d.ts +26 -25
- package/dist/migrations/appwriteToX.js +42 -6
- package/dist/migrations/attributes.js +21 -20
- package/dist/migrations/backup.d.ts +93 -87
- package/dist/migrations/collections.d.ts +6 -0
- package/dist/migrations/collections.js +149 -20
- package/dist/migrations/converters.d.ts +2 -18
- package/dist/migrations/converters.js +13 -2
- package/dist/migrations/dataLoader.d.ts +276 -161
- package/dist/migrations/dataLoader.js +535 -292
- package/dist/migrations/databases.js +8 -2
- package/dist/migrations/helper.d.ts +3 -0
- package/dist/migrations/helper.js +21 -0
- package/dist/migrations/importController.d.ts +5 -2
- package/dist/migrations/importController.js +125 -88
- package/dist/migrations/importDataActions.d.ts +9 -1
- package/dist/migrations/importDataActions.js +15 -3
- package/dist/migrations/indexes.js +3 -2
- package/dist/migrations/logging.js +20 -8
- package/dist/migrations/migrationHelper.d.ts +9 -4
- package/dist/migrations/migrationHelper.js +6 -5
- package/dist/migrations/openapi.d.ts +1 -1
- package/dist/migrations/openapi.js +33 -18
- package/dist/migrations/queue.js +3 -2
- package/dist/migrations/relationships.d.ts +2 -2
- package/dist/migrations/schemaStrings.js +53 -41
- package/dist/migrations/setupDatabase.d.ts +2 -4
- package/dist/migrations/setupDatabase.js +24 -105
- package/dist/migrations/storage.d.ts +3 -1
- package/dist/migrations/storage.js +110 -16
- package/dist/migrations/transfer.d.ts +30 -0
- package/dist/migrations/transfer.js +337 -0
- package/dist/migrations/users.d.ts +2 -1
- package/dist/migrations/users.js +78 -43
- package/dist/schemas/authUser.d.ts +2 -2
- package/dist/storage/methods.d.ts +15 -0
- package/dist/storage/methods.js +207 -0
- package/dist/storage/schemas.d.ts +687 -0
- package/dist/storage/schemas.js +175 -0
- package/dist/utils/getClientFromConfig.d.ts +4 -0
- package/dist/utils/getClientFromConfig.js +16 -0
- package/dist/utils/helperFunctions.d.ts +11 -1
- package/dist/utils/helperFunctions.js +38 -0
- package/dist/utils/retryFailedPromises.d.ts +2 -0
- package/dist/utils/retryFailedPromises.js +21 -0
- package/dist/utils/schemaStrings.d.ts +13 -0
- package/dist/utils/schemaStrings.js +403 -0
- package/dist/utils/setupFiles.js +110 -61
- package/dist/utilsController.d.ts +40 -22
- package/dist/utilsController.js +164 -84
- package/package.json +13 -15
- package/src/collections/attributes.ts +483 -0
- package/src/collections/indexes.ts +53 -0
- package/src/collections/methods.ts +331 -0
- package/src/databases/methods.ts +47 -0
- package/src/init.ts +64 -64
- package/src/interactiveCLI.ts +767 -0
- package/src/main.ts +292 -83
- package/src/migrations/afterImportActions.ts +553 -490
- package/src/migrations/appwriteToX.ts +237 -174
- package/src/migrations/attributes.ts +483 -422
- package/src/migrations/backup.ts +205 -205
- package/src/migrations/collections.ts +545 -300
- package/src/migrations/converters.ts +161 -150
- package/src/migrations/dataLoader.ts +1615 -1304
- package/src/migrations/databases.ts +44 -25
- package/src/migrations/dbHelpers.ts +92 -92
- package/src/migrations/helper.ts +40 -0
- package/src/migrations/importController.ts +448 -384
- package/src/migrations/importDataActions.ts +315 -307
- package/src/migrations/indexes.ts +40 -37
- package/src/migrations/logging.ts +29 -16
- package/src/migrations/migrationHelper.ts +207 -201
- package/src/migrations/openapi.ts +83 -70
- package/src/migrations/queue.ts +118 -119
- package/src/migrations/relationships.ts +324 -324
- package/src/migrations/schemaStrings.ts +472 -460
- package/src/migrations/setupDatabase.ts +118 -219
- package/src/migrations/storage.ts +538 -358
- package/src/migrations/transfer.ts +608 -0
- package/src/migrations/users.ts +362 -285
- package/src/migrations/validationRules.ts +63 -63
- package/src/schemas/authUser.ts +23 -23
- package/src/setup.ts +8 -8
- package/src/storage/methods.ts +371 -0
- package/src/storage/schemas.ts +205 -0
- package/src/types.ts +9 -9
- package/src/utils/getClientFromConfig.ts +17 -0
- package/src/utils/helperFunctions.ts +181 -127
- package/src/utils/index.ts +2 -2
- package/src/utils/loadConfigs.ts +59 -59
- package/src/utils/retryFailedPromises.ts +27 -0
- package/src/utils/schemaStrings.ts +473 -0
- package/src/utils/setupFiles.ts +228 -182
- package/src/utilsController.ts +325 -194
- package/tsconfig.json +37 -37
@@ -1,150 +1,161 @@
|
|
1
|
-
import _ from "lodash";
|
2
|
-
import { converterFunctions, type AttributeMappings } from "appwrite-utils";
|
3
|
-
|
4
|
-
const { cloneDeep, isObject } = _;
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Deeply converts all properties of an object (or array) to strings.
|
8
|
-
* @param data The input data to convert.
|
9
|
-
* @returns The data with all its properties converted to strings.
|
10
|
-
*/
|
11
|
-
export const deepAnyToString = (data: any): any => {
|
12
|
-
if (Array.isArray(data)) {
|
13
|
-
return data.map((item) => deepAnyToString(item));
|
14
|
-
} else if (isObject(data)) {
|
15
|
-
return Object.keys(data).reduce((acc, key) => {
|
16
|
-
acc[key] = deepAnyToString(data[key as keyof typeof data]);
|
17
|
-
return acc;
|
18
|
-
}, {} as Record<string, any>);
|
19
|
-
} else {
|
20
|
-
return converterFunctions.anyToString(data);
|
21
|
-
}
|
22
|
-
};
|
23
|
-
|
24
|
-
/**
|
25
|
-
* Performs a deep conversion of all values in a nested structure to the specified type.
|
26
|
-
* Uses a conversion function like anyToString, anyToNumber, etc.
|
27
|
-
* @param data The data to convert.
|
28
|
-
* @param convertFn The conversion function to apply.
|
29
|
-
* @returns The converted data.
|
30
|
-
*/
|
31
|
-
export const deepConvert = <T>(
|
32
|
-
data: any,
|
33
|
-
convertFn: (value: any) => T
|
34
|
-
): any => {
|
35
|
-
if (Array.isArray(data)) {
|
36
|
-
return data.map((item) => deepConvert(item, convertFn));
|
37
|
-
} else if (isObject(data)) {
|
38
|
-
return Object.keys(data).reduce((acc: Record<string, T>, key: string) => {
|
39
|
-
acc[key] = deepConvert(data[key as keyof typeof data], convertFn);
|
40
|
-
return acc;
|
41
|
-
}, {});
|
42
|
-
} else {
|
43
|
-
return convertFn(data);
|
44
|
-
}
|
45
|
-
};
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Converts an entire object's properties to different types based on a provided schema.
|
49
|
-
* @param obj The object to convert.
|
50
|
-
* @param schema A mapping of object keys to conversion functions.
|
51
|
-
* @returns The converted object.
|
52
|
-
*/
|
53
|
-
export const convertObjectBySchema = (
|
54
|
-
obj: Record<string, any>,
|
55
|
-
schema: Record<string, (value: any) => any>
|
56
|
-
): Record<string, any> => {
|
57
|
-
return Object.keys(obj).reduce((acc: Record<string, any>, key: string) => {
|
58
|
-
const convertFn = schema[key];
|
59
|
-
acc[key] = convertFn ? convertFn(obj[key]) : obj[key];
|
60
|
-
return acc;
|
61
|
-
}, {});
|
62
|
-
};
|
63
|
-
|
64
|
-
/**
|
65
|
-
* Converts the keys of an object based on a provided attributeMappings.
|
66
|
-
* Each key in the object is checked against attributeMappings; if a matching entry is found,
|
67
|
-
* the key is renamed to the targetKey specified in attributeMappings.
|
68
|
-
*
|
69
|
-
* @param obj The object to convert.
|
70
|
-
* @param attributeMappings The attributeMappings defining how keys in the object should be converted.
|
71
|
-
* @returns The converted object with keys renamed according to attributeMappings.
|
72
|
-
*/
|
73
|
-
export const convertObjectByAttributeMappings = (
|
74
|
-
obj: Record<string, any>,
|
75
|
-
attributeMappings: AttributeMappings
|
76
|
-
): Record<string, any> => {
|
77
|
-
const result: Record<string, any> = {};
|
78
|
-
|
79
|
-
// Correctly handle [any] notation by mapping or aggregating over all elements or keys
|
80
|
-
const resolveValue = (obj: Record<string, any>, path: string): any => {
|
81
|
-
const parts = path.split(".");
|
82
|
-
let current = obj;
|
83
|
-
|
84
|
-
for (let i = 0; i < parts.length; i++) {
|
85
|
-
if (parts[i] === "[any]") {
|
86
|
-
if (Array.isArray(current)) {
|
87
|
-
// If current is an array, apply resolution to each item
|
88
|
-
return current.map((item) =>
|
89
|
-
resolveValue(item, parts.slice(i + 1).join("."))
|
90
|
-
);
|
91
|
-
} else if (typeof current === "object" && current !== null) {
|
92
|
-
// If current is an object, aggregate values from all keys
|
93
|
-
return Object.values(current).map((value) =>
|
94
|
-
resolveValue(value, parts.slice(i + 1).join("."))
|
95
|
-
);
|
96
|
-
}
|
97
|
-
} else {
|
98
|
-
current = current[parts[i]];
|
99
|
-
if (current === undefined) return undefined;
|
100
|
-
}
|
101
|
-
}
|
102
|
-
return current;
|
103
|
-
};
|
104
|
-
|
105
|
-
for (const mapping of attributeMappings) {
|
106
|
-
if (
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
}
|
120
|
-
}
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
*
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
1
|
+
import _ from "lodash";
|
2
|
+
import { converterFunctions, type AttributeMappings } from "appwrite-utils";
|
3
|
+
|
4
|
+
const { cloneDeep, isObject } = _;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Deeply converts all properties of an object (or array) to strings.
|
8
|
+
* @param data The input data to convert.
|
9
|
+
* @returns The data with all its properties converted to strings.
|
10
|
+
*/
|
11
|
+
export const deepAnyToString = (data: any): any => {
|
12
|
+
if (Array.isArray(data)) {
|
13
|
+
return data.map((item) => deepAnyToString(item));
|
14
|
+
} else if (isObject(data)) {
|
15
|
+
return Object.keys(data).reduce((acc, key) => {
|
16
|
+
acc[key] = deepAnyToString(data[key as keyof typeof data]);
|
17
|
+
return acc;
|
18
|
+
}, {} as Record<string, any>);
|
19
|
+
} else {
|
20
|
+
return converterFunctions.anyToString(data);
|
21
|
+
}
|
22
|
+
};
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Performs a deep conversion of all values in a nested structure to the specified type.
|
26
|
+
* Uses a conversion function like anyToString, anyToNumber, etc.
|
27
|
+
* @param data The data to convert.
|
28
|
+
* @param convertFn The conversion function to apply.
|
29
|
+
* @returns The converted data.
|
30
|
+
*/
|
31
|
+
export const deepConvert = <T>(
|
32
|
+
data: any,
|
33
|
+
convertFn: (value: any) => T
|
34
|
+
): any => {
|
35
|
+
if (Array.isArray(data)) {
|
36
|
+
return data.map((item) => deepConvert(item, convertFn));
|
37
|
+
} else if (isObject(data)) {
|
38
|
+
return Object.keys(data).reduce((acc: Record<string, T>, key: string) => {
|
39
|
+
acc[key] = deepConvert(data[key as keyof typeof data], convertFn);
|
40
|
+
return acc;
|
41
|
+
}, {});
|
42
|
+
} else {
|
43
|
+
return convertFn(data);
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Converts an entire object's properties to different types based on a provided schema.
|
49
|
+
* @param obj The object to convert.
|
50
|
+
* @param schema A mapping of object keys to conversion functions.
|
51
|
+
* @returns The converted object.
|
52
|
+
*/
|
53
|
+
export const convertObjectBySchema = (
|
54
|
+
obj: Record<string, any>,
|
55
|
+
schema: Record<string, (value: any) => any>
|
56
|
+
): Record<string, any> => {
|
57
|
+
return Object.keys(obj).reduce((acc: Record<string, any>, key: string) => {
|
58
|
+
const convertFn = schema[key];
|
59
|
+
acc[key] = convertFn ? convertFn(obj[key]) : obj[key];
|
60
|
+
return acc;
|
61
|
+
}, {});
|
62
|
+
};
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Converts the keys of an object based on a provided attributeMappings.
|
66
|
+
* Each key in the object is checked against attributeMappings; if a matching entry is found,
|
67
|
+
* the key is renamed to the targetKey specified in attributeMappings.
|
68
|
+
*
|
69
|
+
* @param obj The object to convert.
|
70
|
+
* @param attributeMappings The attributeMappings defining how keys in the object should be converted.
|
71
|
+
* @returns The converted object with keys renamed according to attributeMappings.
|
72
|
+
*/
|
73
|
+
export const convertObjectByAttributeMappings = (
|
74
|
+
obj: Record<string, any>,
|
75
|
+
attributeMappings: AttributeMappings
|
76
|
+
): Record<string, any> => {
|
77
|
+
const result: Record<string, any> = {};
|
78
|
+
|
79
|
+
// Correctly handle [any] notation by mapping or aggregating over all elements or keys
|
80
|
+
const resolveValue = (obj: Record<string, any>, path: string): any => {
|
81
|
+
const parts = path.split(".");
|
82
|
+
let current = obj;
|
83
|
+
|
84
|
+
for (let i = 0; i < parts.length; i++) {
|
85
|
+
if (parts[i] === "[any]") {
|
86
|
+
if (Array.isArray(current)) {
|
87
|
+
// If current is an array, apply resolution to each item
|
88
|
+
return current.map((item) =>
|
89
|
+
resolveValue(item, parts.slice(i + 1).join("."))
|
90
|
+
);
|
91
|
+
} else if (typeof current === "object" && current !== null) {
|
92
|
+
// If current is an object, aggregate values from all keys
|
93
|
+
return Object.values(current).map((value) =>
|
94
|
+
resolveValue(value, parts.slice(i + 1).join("."))
|
95
|
+
);
|
96
|
+
}
|
97
|
+
} else {
|
98
|
+
current = current[parts[i]];
|
99
|
+
if (current === undefined) return undefined;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
return current;
|
103
|
+
};
|
104
|
+
|
105
|
+
for (const mapping of attributeMappings) {
|
106
|
+
if (mapping.valueToSet !== undefined) {
|
107
|
+
result[mapping.targetKey] = mapping.valueToSet;
|
108
|
+
} else if (Array.isArray(mapping.oldKeys)) {
|
109
|
+
// Collect and flatten values from multiple oldKeys
|
110
|
+
const values = mapping.oldKeys
|
111
|
+
.map((oldKey) => resolveValue(obj, oldKey))
|
112
|
+
.flat(Infinity);
|
113
|
+
if (values.length > 0) {
|
114
|
+
result[mapping.targetKey] = values.filter(
|
115
|
+
(value) => value !== undefined
|
116
|
+
);
|
117
|
+
} else {
|
118
|
+
result[mapping.targetKey] = null;
|
119
|
+
}
|
120
|
+
} else if (mapping.oldKey) {
|
121
|
+
// Resolve single oldKey
|
122
|
+
const value = resolveValue(obj, mapping.oldKey);
|
123
|
+
if (value !== undefined) {
|
124
|
+
result[mapping.targetKey] = Array.isArray(value)
|
125
|
+
? value.flat(Infinity)
|
126
|
+
: value;
|
127
|
+
} else {
|
128
|
+
result[mapping.targetKey] = value ? value : null;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
return result;
|
134
|
+
};
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Ensures data conversion without mutating the original input.
|
138
|
+
* @param data The data to convert.
|
139
|
+
* @param convertFn The conversion function to apply.
|
140
|
+
* @returns The converted data.
|
141
|
+
*/
|
142
|
+
export const immutableConvert = <T>(
|
143
|
+
data: any,
|
144
|
+
convertFn: (value: any) => T
|
145
|
+
): T => {
|
146
|
+
const clonedData = cloneDeep(data);
|
147
|
+
return convertFn(clonedData);
|
148
|
+
};
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Validates a string against a regular expression and returns the string if valid, or null.
|
152
|
+
* @param value The string to validate.
|
153
|
+
* @param pattern The regex pattern to validate against.
|
154
|
+
* @returns The original string if valid, otherwise null.
|
155
|
+
*/
|
156
|
+
export const validateString = (
|
157
|
+
value: string,
|
158
|
+
pattern: RegExp
|
159
|
+
): string | null => {
|
160
|
+
return pattern.test(value) ? value : null;
|
161
|
+
};
|