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.
Files changed (109) hide show
  1. package/README.md +122 -96
  2. package/dist/collections/attributes.d.ts +4 -0
  3. package/dist/collections/attributes.js +224 -0
  4. package/dist/collections/indexes.d.ts +4 -0
  5. package/dist/collections/indexes.js +27 -0
  6. package/dist/collections/methods.d.ts +16 -0
  7. package/dist/collections/methods.js +216 -0
  8. package/dist/databases/methods.d.ts +6 -0
  9. package/dist/databases/methods.js +33 -0
  10. package/dist/interactiveCLI.d.ts +19 -0
  11. package/dist/interactiveCLI.js +555 -0
  12. package/dist/main.js +227 -62
  13. package/dist/migrations/afterImportActions.js +37 -40
  14. package/dist/migrations/appwriteToX.d.ts +26 -25
  15. package/dist/migrations/appwriteToX.js +42 -6
  16. package/dist/migrations/attributes.js +21 -20
  17. package/dist/migrations/backup.d.ts +93 -87
  18. package/dist/migrations/collections.d.ts +6 -0
  19. package/dist/migrations/collections.js +149 -20
  20. package/dist/migrations/converters.d.ts +2 -18
  21. package/dist/migrations/converters.js +13 -2
  22. package/dist/migrations/dataLoader.d.ts +276 -161
  23. package/dist/migrations/dataLoader.js +535 -292
  24. package/dist/migrations/databases.js +8 -2
  25. package/dist/migrations/helper.d.ts +3 -0
  26. package/dist/migrations/helper.js +21 -0
  27. package/dist/migrations/importController.d.ts +5 -2
  28. package/dist/migrations/importController.js +125 -88
  29. package/dist/migrations/importDataActions.d.ts +9 -1
  30. package/dist/migrations/importDataActions.js +15 -3
  31. package/dist/migrations/indexes.js +3 -2
  32. package/dist/migrations/logging.js +20 -8
  33. package/dist/migrations/migrationHelper.d.ts +9 -4
  34. package/dist/migrations/migrationHelper.js +6 -5
  35. package/dist/migrations/openapi.d.ts +1 -1
  36. package/dist/migrations/openapi.js +33 -18
  37. package/dist/migrations/queue.js +3 -2
  38. package/dist/migrations/relationships.d.ts +2 -2
  39. package/dist/migrations/schemaStrings.js +53 -41
  40. package/dist/migrations/setupDatabase.d.ts +2 -4
  41. package/dist/migrations/setupDatabase.js +24 -105
  42. package/dist/migrations/storage.d.ts +3 -1
  43. package/dist/migrations/storage.js +110 -16
  44. package/dist/migrations/transfer.d.ts +30 -0
  45. package/dist/migrations/transfer.js +337 -0
  46. package/dist/migrations/users.d.ts +2 -1
  47. package/dist/migrations/users.js +78 -43
  48. package/dist/schemas/authUser.d.ts +2 -2
  49. package/dist/storage/methods.d.ts +15 -0
  50. package/dist/storage/methods.js +207 -0
  51. package/dist/storage/schemas.d.ts +687 -0
  52. package/dist/storage/schemas.js +175 -0
  53. package/dist/utils/getClientFromConfig.d.ts +4 -0
  54. package/dist/utils/getClientFromConfig.js +16 -0
  55. package/dist/utils/helperFunctions.d.ts +11 -1
  56. package/dist/utils/helperFunctions.js +38 -0
  57. package/dist/utils/retryFailedPromises.d.ts +2 -0
  58. package/dist/utils/retryFailedPromises.js +21 -0
  59. package/dist/utils/schemaStrings.d.ts +13 -0
  60. package/dist/utils/schemaStrings.js +403 -0
  61. package/dist/utils/setupFiles.js +110 -61
  62. package/dist/utilsController.d.ts +40 -22
  63. package/dist/utilsController.js +164 -84
  64. package/package.json +13 -15
  65. package/src/collections/attributes.ts +483 -0
  66. package/src/collections/indexes.ts +53 -0
  67. package/src/collections/methods.ts +331 -0
  68. package/src/databases/methods.ts +47 -0
  69. package/src/init.ts +64 -64
  70. package/src/interactiveCLI.ts +767 -0
  71. package/src/main.ts +292 -83
  72. package/src/migrations/afterImportActions.ts +553 -490
  73. package/src/migrations/appwriteToX.ts +237 -174
  74. package/src/migrations/attributes.ts +483 -422
  75. package/src/migrations/backup.ts +205 -205
  76. package/src/migrations/collections.ts +545 -300
  77. package/src/migrations/converters.ts +161 -150
  78. package/src/migrations/dataLoader.ts +1615 -1304
  79. package/src/migrations/databases.ts +44 -25
  80. package/src/migrations/dbHelpers.ts +92 -92
  81. package/src/migrations/helper.ts +40 -0
  82. package/src/migrations/importController.ts +448 -384
  83. package/src/migrations/importDataActions.ts +315 -307
  84. package/src/migrations/indexes.ts +40 -37
  85. package/src/migrations/logging.ts +29 -16
  86. package/src/migrations/migrationHelper.ts +207 -201
  87. package/src/migrations/openapi.ts +83 -70
  88. package/src/migrations/queue.ts +118 -119
  89. package/src/migrations/relationships.ts +324 -324
  90. package/src/migrations/schemaStrings.ts +472 -460
  91. package/src/migrations/setupDatabase.ts +118 -219
  92. package/src/migrations/storage.ts +538 -358
  93. package/src/migrations/transfer.ts +608 -0
  94. package/src/migrations/users.ts +362 -285
  95. package/src/migrations/validationRules.ts +63 -63
  96. package/src/schemas/authUser.ts +23 -23
  97. package/src/setup.ts +8 -8
  98. package/src/storage/methods.ts +371 -0
  99. package/src/storage/schemas.ts +205 -0
  100. package/src/types.ts +9 -9
  101. package/src/utils/getClientFromConfig.ts +17 -0
  102. package/src/utils/helperFunctions.ts +181 -127
  103. package/src/utils/index.ts +2 -2
  104. package/src/utils/loadConfigs.ts +59 -59
  105. package/src/utils/retryFailedPromises.ts +27 -0
  106. package/src/utils/schemaStrings.ts +473 -0
  107. package/src/utils/setupFiles.ts +228 -182
  108. package/src/utilsController.ts +325 -194
  109. 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 (Array.isArray(mapping.oldKeys)) {
107
- // Collect and flatten values from multiple oldKeys
108
- const values = mapping.oldKeys
109
- .map((oldKey) => resolveValue(obj, oldKey))
110
- .flat(Infinity);
111
- result[mapping.targetKey] = values.filter((value) => value !== undefined);
112
- } else if (mapping.oldKey) {
113
- // Resolve single oldKey
114
- const value = resolveValue(obj, mapping.oldKey);
115
- if (value !== undefined) {
116
- result[mapping.targetKey] = Array.isArray(value)
117
- ? value.flat(Infinity)
118
- : value;
119
- }
120
- }
121
- }
122
- return result;
123
- };
124
-
125
- /**
126
- * Ensures data conversion without mutating the original input.
127
- * @param data The data to convert.
128
- * @param convertFn The conversion function to apply.
129
- * @returns The converted data.
130
- */
131
- export const immutableConvert = <T>(
132
- data: any,
133
- convertFn: (value: any) => T
134
- ): T => {
135
- const clonedData = cloneDeep(data);
136
- return convertFn(clonedData);
137
- };
138
-
139
- /**
140
- * Validates a string against a regular expression and returns the string if valid, or null.
141
- * @param value The string to validate.
142
- * @param pattern The regex pattern to validate against.
143
- * @returns The original string if valid, otherwise null.
144
- */
145
- export const validateString = (
146
- value: string,
147
- pattern: RegExp
148
- ): string | null => {
149
- return pattern.test(value) ? value : null;
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
+ };