appwrite-utils-cli 0.9.86 → 0.9.89
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/dist/interactiveCLI.js
CHANGED
@@ -104,11 +104,18 @@ export class InteractiveCLI {
|
|
104
104
|
}
|
105
105
|
}
|
106
106
|
async selectDatabases(databases, message, multiSelect = true) {
|
107
|
+
await this.initControllerIfNeeded();
|
107
108
|
const configDatabases = this.getLocalDatabases();
|
108
|
-
const
|
109
|
-
|
110
|
-
|
111
|
-
|
109
|
+
const allDatabases = [...databases, ...configDatabases].reduce((acc, db) => {
|
110
|
+
if (!acc.find(d => d.name === db.name)) {
|
111
|
+
acc.push(db);
|
112
|
+
}
|
113
|
+
return acc;
|
114
|
+
}, []);
|
115
|
+
const choices = allDatabases
|
116
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
117
|
+
.map((db) => ({ name: db.name, value: db }))
|
118
|
+
.filter((db) => db.name.toLowerCase() !== "migrations");
|
112
119
|
const { selectedDatabases } = await inquirer.prompt([
|
113
120
|
{
|
114
121
|
type: multiSelect ? "checkbox" : "list",
|
@@ -122,6 +129,7 @@ export class InteractiveCLI {
|
|
122
129
|
return selectedDatabases;
|
123
130
|
}
|
124
131
|
async selectCollections(database, databasesClient, message, multiSelect = true) {
|
132
|
+
await this.initControllerIfNeeded();
|
125
133
|
const collections = await fetchAllCollections(database.$id, databasesClient);
|
126
134
|
const configCollections = this.getLocalCollections();
|
127
135
|
const collectionNames = collections.map((c) => c.name).concat(configCollections.map((c) => c.name));
|
@@ -43,7 +43,6 @@ export const loadConfig = async (configDir) => {
|
|
43
43
|
for (const file of collectionFiles) {
|
44
44
|
const filePath = path.join(collectionsDir, file);
|
45
45
|
const fileUrl = pathToFileURL(filePath).href;
|
46
|
-
console.log(`Loading collection from: ${fileUrl}`);
|
47
46
|
const collectionModule = (await import(fileUrl)).default;
|
48
47
|
config.collections.push(collectionModule);
|
49
48
|
}
|
@@ -111,6 +111,9 @@ export class SchemaGenerator {
|
|
111
111
|
return;
|
112
112
|
}
|
113
113
|
this.config.collections.forEach((collection) => {
|
114
|
+
if (!collection.attributes) {
|
115
|
+
return;
|
116
|
+
}
|
114
117
|
collection.attributes.forEach((attr) => {
|
115
118
|
if (attr.type === "relationship" && attr.twoWay && attr.twoWayKey) {
|
116
119
|
const relationshipAttr = attr;
|
@@ -169,6 +172,7 @@ export class SchemaGenerator {
|
|
169
172
|
return;
|
170
173
|
}
|
171
174
|
this.config.collections.forEach((collection) => {
|
175
|
+
console.log(`Generating schema for ${JSON.stringify(collection, null, 4)}`);
|
172
176
|
const schemaString = this.createSchemaString(collection.name, collection.attributes);
|
173
177
|
const camelCaseName = toCamelCase(collection.name);
|
174
178
|
const schemaPath = path.join(this.appwriteFolderPath, "schemas", `${camelCaseName}.ts`);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "appwrite-utils-cli",
|
3
3
|
"description": "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.",
|
4
|
-
"version": "0.9.
|
4
|
+
"version": "0.9.89",
|
5
5
|
"main": "src/main.ts",
|
6
6
|
"type": "module",
|
7
7
|
"repository": {
|
package/src/interactiveCLI.ts
CHANGED
@@ -121,12 +121,20 @@ export class InteractiveCLI {
|
|
121
121
|
message: string,
|
122
122
|
multiSelect = true
|
123
123
|
): Promise<Models.Database[]> {
|
124
|
+
await this.initControllerIfNeeded();
|
124
125
|
const configDatabases = this.getLocalDatabases();
|
125
|
-
const
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
126
|
+
const allDatabases = [...databases, ...configDatabases].reduce((acc, db) => {
|
127
|
+
if (!acc.find(d => d.name === db.name)) {
|
128
|
+
acc.push(db);
|
129
|
+
}
|
130
|
+
return acc;
|
131
|
+
}, [] as Models.Database[]);
|
132
|
+
|
133
|
+
const choices = allDatabases
|
134
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
135
|
+
.map((db) => ({ name: db.name, value: db }))
|
136
|
+
.filter((db) => db.name.toLowerCase() !== "migrations");
|
137
|
+
|
130
138
|
const { selectedDatabases } = await inquirer.prompt([
|
131
139
|
{
|
132
140
|
type: multiSelect ? "checkbox" : "list",
|
@@ -137,7 +145,7 @@ export class InteractiveCLI {
|
|
137
145
|
pageSize: 10,
|
138
146
|
},
|
139
147
|
]);
|
140
|
-
|
148
|
+
|
141
149
|
return selectedDatabases;
|
142
150
|
}
|
143
151
|
|
@@ -145,8 +153,9 @@ export class InteractiveCLI {
|
|
145
153
|
database: Models.Database,
|
146
154
|
databasesClient: Databases,
|
147
155
|
message: string,
|
148
|
-
multiSelect = true
|
156
|
+
multiSelect = true
|
149
157
|
): Promise<Models.Collection[]> {
|
158
|
+
await this.initControllerIfNeeded();
|
150
159
|
const collections = await fetchAllCollections(
|
151
160
|
database.$id,
|
152
161
|
databasesClient
|
package/src/utils/loadConfigs.ts
CHANGED
@@ -51,7 +51,6 @@ export const loadConfig = async (
|
|
51
51
|
for (const file of collectionFiles) {
|
52
52
|
const filePath = path.join(collectionsDir, file);
|
53
53
|
const fileUrl = pathToFileURL(filePath).href;
|
54
|
-
console.log(`Loading collection from: ${fileUrl}`);
|
55
54
|
const collectionModule = (await import(fileUrl)).default as Collection;
|
56
55
|
config.collections.push(collectionModule);
|
57
56
|
}
|
@@ -146,6 +146,9 @@ export class SchemaGenerator {
|
|
146
146
|
return;
|
147
147
|
}
|
148
148
|
this.config.collections.forEach((collection) => {
|
149
|
+
if (!collection.attributes) {
|
150
|
+
return;
|
151
|
+
}
|
149
152
|
collection.attributes.forEach((attr) => {
|
150
153
|
if (attr.type === "relationship" && attr.twoWay && attr.twoWayKey) {
|
151
154
|
const relationshipAttr = attr as RelationshipAttribute;
|
@@ -223,6 +226,7 @@ export class SchemaGenerator {
|
|
223
226
|
return;
|
224
227
|
}
|
225
228
|
this.config.collections.forEach((collection) => {
|
229
|
+
console.log(`Generating schema for ${JSON.stringify(collection, null, 4)}`);
|
226
230
|
const schemaString = this.createSchemaString(
|
227
231
|
collection.name,
|
228
232
|
collection.attributes
|