appwrite-utils-cli 1.7.7 → 1.7.8
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/SELECTION_DIALOGS.md +146 -0
- package/dist/cli/commands/databaseCommands.js +90 -23
- package/dist/main.js +175 -4
- package/dist/migrations/appwriteToX.d.ts +27 -2
- package/dist/migrations/appwriteToX.js +293 -69
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +1 -1
- package/dist/migrations/yaml/generateImportSchemas.js +23 -8
- package/dist/shared/schemaGenerator.js +25 -12
- package/dist/shared/selectionDialogs.d.ts +214 -0
- package/dist/shared/selectionDialogs.js +516 -0
- package/dist/utils/configDiscovery.d.ts +4 -4
- package/dist/utils/configDiscovery.js +66 -30
- package/dist/utils/yamlConverter.d.ts +1 -0
- package/dist/utils/yamlConverter.js +26 -3
- package/dist/utilsController.d.ts +6 -1
- package/dist/utilsController.js +91 -2
- package/package.json +1 -1
- package/src/cli/commands/databaseCommands.ts +134 -34
- package/src/main.ts +276 -34
- package/src/migrations/appwriteToX.ts +385 -90
- package/src/migrations/yaml/generateImportSchemas.ts +26 -8
- package/src/shared/schemaGenerator.ts +29 -12
- package/src/shared/selectionDialogs.ts +716 -0
- package/src/utils/configDiscovery.ts +83 -39
- package/src/utils/yamlConverter.ts +29 -3
- package/src/utilsController.ts +116 -4
|
@@ -143,13 +143,18 @@ export class SchemaGenerator {
|
|
|
143
143
|
collectionsFolderPath,
|
|
144
144
|
`${collection.name}.ts`
|
|
145
145
|
);
|
|
146
|
+
|
|
147
|
+
// Determine if we're in tables mode for terminology
|
|
148
|
+
const isTablesMode = outputDir === "tables";
|
|
149
|
+
const securityField = isTablesMode ? "rowSecurity" : "documentSecurity";
|
|
150
|
+
|
|
146
151
|
const collectionContent = `import { type CollectionCreate } from "appwrite-utils";
|
|
147
|
-
|
|
152
|
+
|
|
148
153
|
const ${collection.name}Config: Partial<CollectionCreate> = {
|
|
149
154
|
name: "${collection.name}",
|
|
150
155
|
$id: "${collection.$id}",
|
|
151
156
|
enabled: ${collection.enabled},
|
|
152
|
-
|
|
157
|
+
${securityField}: ${collection.documentSecurity},
|
|
153
158
|
$permissions: [
|
|
154
159
|
${collection.$permissions
|
|
155
160
|
.map(
|
|
@@ -163,22 +168,33 @@ export class SchemaGenerator {
|
|
|
163
168
|
.map((attr) => {
|
|
164
169
|
return `{ ${Object.entries(attr)
|
|
165
170
|
.map(([key, value]) => {
|
|
171
|
+
// Handle table vs collection terminology for related fields
|
|
172
|
+
let outputKey = key;
|
|
173
|
+
let outputValue = value;
|
|
174
|
+
|
|
175
|
+
if (isTablesMode) {
|
|
176
|
+
// Convert collection terminology to table terminology
|
|
177
|
+
if (key === "relatedCollection") {
|
|
178
|
+
outputKey = "relatedTable";
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
166
182
|
// Check the type of the value and format it accordingly
|
|
167
|
-
if (typeof
|
|
183
|
+
if (typeof outputValue === "string") {
|
|
168
184
|
// If the value is a string, wrap it in quotes
|
|
169
|
-
return `${
|
|
170
|
-
} else if (Array.isArray(
|
|
185
|
+
return `${outputKey}: "${outputValue.replace(/"/g, '\\"')}"`; // Escape existing quotes in the string
|
|
186
|
+
} else if (Array.isArray(outputValue)) {
|
|
171
187
|
// If the value is an array, join it with commas
|
|
172
|
-
if (
|
|
173
|
-
return `${
|
|
188
|
+
if (outputValue.length > 0) {
|
|
189
|
+
return `${outputKey}: [${outputValue
|
|
174
190
|
.map((item) => `"${item}"`)
|
|
175
191
|
.join(", ")}]`;
|
|
176
192
|
} else {
|
|
177
|
-
return `${
|
|
193
|
+
return `${outputKey}: []`;
|
|
178
194
|
}
|
|
179
195
|
} else {
|
|
180
196
|
// If the value is not a string (e.g., boolean or number), output it directly
|
|
181
|
-
return `${
|
|
197
|
+
return `${outputKey}: ${outputValue}`;
|
|
182
198
|
}
|
|
183
199
|
})
|
|
184
200
|
.join(", ")} }`;
|
|
@@ -188,12 +204,13 @@ export class SchemaGenerator {
|
|
|
188
204
|
indexes: [
|
|
189
205
|
${(
|
|
190
206
|
collection.indexes?.map((index) => {
|
|
191
|
-
//
|
|
207
|
+
// Use appropriate terminology for index attributes/columns
|
|
208
|
+
const indexField = isTablesMode ? "columns" : "attributes";
|
|
192
209
|
const formattedAttributes =
|
|
193
210
|
index.attributes.map((attr) => `"${attr}"`).join(", ") ?? "";
|
|
194
211
|
return `{ key: "${index.key}", type: "${
|
|
195
212
|
index.type
|
|
196
|
-
}",
|
|
213
|
+
}", ${indexField}: [${formattedAttributes}], orders: [${
|
|
197
214
|
index.orders
|
|
198
215
|
?.filter((order) => order !== null)
|
|
199
216
|
.map((order) => `"${order}"`)
|
|
@@ -203,7 +220,7 @@ export class SchemaGenerator {
|
|
|
203
220
|
).join(",\n ")}
|
|
204
221
|
]
|
|
205
222
|
};
|
|
206
|
-
|
|
223
|
+
|
|
207
224
|
export default ${collection.name}Config;
|
|
208
225
|
`;
|
|
209
226
|
fs.writeFileSync(collectionFilePath, collectionContent, {
|