appwrite-utils-cli 0.9.78 → 0.9.80

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 CHANGED
@@ -61,6 +61,7 @@ Available options:
61
61
  - `--collectionIds`: Comma-separated list of collection IDs to operate on
62
62
  - `--bucketIds`: Comma-separated list of bucket IDs to operate on
63
63
  - `--wipe`: Wipe data (all: everything, docs: only documents, users: only user data)
64
+ - `--wipeCollections`: Wipe collections (wipes specified collections from collectionIds -- does this non-destructively, deletes all documents)
64
65
  - `--generate`: Generate TypeScript schemas from database schemas
65
66
  - `--import`: Import data into your databases
66
67
  - `--backup`: Perform a backup of your databases
@@ -124,6 +125,8 @@ This updated CLI ensures that developers have robust tools at their fingertips t
124
125
 
125
126
  ## Changelog
126
127
 
128
+ - 0.9.80: Fixed collections not being unique between local and remote
129
+ - 0.9.79: Fixed local collections not being considered for the synchronization unless all de-selected
127
130
  - 0.9.78: Added colored text! And also added a lot more customization options as to what to wipe, update, etc.
128
131
  - 0.9.75: Fixed attribute bug
129
132
  - 0.9.72: Fixed my own null bug
@@ -18,5 +18,7 @@ export declare class InteractiveCLI {
18
18
  private generateSchemas;
19
19
  private importData;
20
20
  private transferData;
21
+ private getLocalCollections;
22
+ private getLocalDatabases;
21
23
  private reloadConfig;
22
24
  }
@@ -6,8 +6,10 @@ import { fetchAllCollections } from "./collections/methods.js";
6
6
  import { listBuckets, createBucket } from "./storage/methods.js";
7
7
  import { Databases, Storage, Client, Compression, } from "node-appwrite";
8
8
  import { getClient } from "./utils/getClientFromConfig.js";
9
+ import { parseAttribute, PermissionToAppwritePermission } from "appwrite-utils";
9
10
  import { ulid } from "ulidx";
10
11
  import chalk from "chalk";
12
+ import { DateTime } from "luxon";
11
13
  var CHOICES;
12
14
  (function (CHOICES) {
13
15
  CHOICES["CREATE_COLLECTION_CONFIG"] = "Create collection config file";
@@ -103,6 +105,8 @@ export class InteractiveCLI {
103
105
  }
104
106
  async selectDatabases(databases, message, multiSelect = true) {
105
107
  const choices = databases.map((db) => ({ name: db.name, value: db })).filter((db) => db.name.toLowerCase() !== "migrations");
108
+ const configDatabases = this.getLocalDatabases();
109
+ const allDatabases = Array.from(new Set([...databases, ...configDatabases]));
106
110
  const { selectedDatabases } = await inquirer.prompt([
107
111
  {
108
112
  type: multiSelect ? "checkbox" : "list",
@@ -117,7 +121,11 @@ export class InteractiveCLI {
117
121
  }
118
122
  async selectCollections(database, databasesClient, message, multiSelect = true) {
119
123
  const collections = await fetchAllCollections(database.$id, databasesClient);
120
- const choices = collections.map((collection) => ({
124
+ const configCollections = this.getLocalCollections();
125
+ const collectionNames = collections.map((c) => c.name).concat(configCollections.map((c) => c.name));
126
+ const allCollectionNamesUnique = Array.from(new Set(collectionNames));
127
+ const allCollections = allCollectionNamesUnique.map((name) => configCollections.find((c) => c.name === name) ?? collections.find((c) => c.name === name)).filter((v) => v !== undefined);
128
+ const choices = allCollections.map((collection) => ({
121
129
  name: collection.name,
122
130
  value: collection,
123
131
  }));
@@ -581,6 +589,32 @@ export class InteractiveCLI {
581
589
  await this.controller.transferData(transferOptions);
582
590
  console.log(chalk.green("Data transfer completed."));
583
591
  }
592
+ getLocalCollections() {
593
+ const configCollections = this.controller.config.collections || [];
594
+ // @ts-expect-error - appwrite invalid types
595
+ return configCollections.map(c => ({
596
+ $id: c.$id || ulid(),
597
+ $createdAt: DateTime.now().toISO(),
598
+ $updatedAt: DateTime.now().toISO(),
599
+ name: c.name,
600
+ enabled: c.enabled || true,
601
+ documentSecurity: c.documentSecurity || false,
602
+ attributes: c.attributes || [],
603
+ indexes: c.indexes || [],
604
+ $permissions: PermissionToAppwritePermission(c.$permissions) || [],
605
+ databaseId: c.databaseId,
606
+ }));
607
+ }
608
+ getLocalDatabases() {
609
+ const configDatabases = this.controller.config.databases || [];
610
+ return configDatabases.map(db => ({
611
+ $id: db.$id || ulid(),
612
+ $createdAt: DateTime.now().toISO(),
613
+ $updatedAt: DateTime.now().toISO(),
614
+ name: db.name,
615
+ enabled: true,
616
+ }));
617
+ }
584
618
  async reloadConfig() {
585
619
  console.log(chalk.yellow("Reloading configuration files..."));
586
620
  try {
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.78",
4
+ "version": "0.9.80",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@types/inquirer": "^9.0.7",
34
- "appwrite-utils": "^0.3.9",
34
+ "appwrite-utils": "^0.3.94",
35
35
  "chalk": "^5.3.0",
36
36
  "commander": "^12.1.0",
37
37
  "inquirer": "^9.3.6",
@@ -13,9 +13,10 @@ import {
13
13
  } from "node-appwrite";
14
14
  import { getClient } from "./utils/getClientFromConfig.js";
15
15
  import type { TransferOptions } from "./migrations/transfer.js";
16
- import type { AppwriteConfig, ConfigDatabases } from "appwrite-utils";
16
+ import { parseAttribute, PermissionToAppwritePermission, type AppwriteConfig, type ConfigDatabases } from "appwrite-utils";
17
17
  import { ulid } from "ulidx";
18
18
  import chalk from "chalk";
19
+ import { DateTime } from "luxon";
19
20
 
20
21
  enum CHOICES {
21
22
  CREATE_COLLECTION_CONFIG = "Create collection config file",
@@ -122,6 +123,9 @@ export class InteractiveCLI {
122
123
  multiSelect = true
123
124
  ): Promise<Models.Database[]> {
124
125
  const choices = databases.map((db) => ({ name: db.name, value: db })).filter((db) => db.name.toLowerCase() !== "migrations");
126
+ const configDatabases = this.getLocalDatabases();
127
+ const allDatabases = Array.from(new Set([...databases, ...configDatabases]));
128
+
125
129
 
126
130
  const { selectedDatabases } = await inquirer.prompt([
127
131
  {
@@ -147,7 +151,11 @@ export class InteractiveCLI {
147
151
  database.$id,
148
152
  databasesClient
149
153
  );
150
- const choices = collections.map((collection) => ({
154
+ const configCollections = this.getLocalCollections();
155
+ const collectionNames = collections.map((c) => c.name).concat(configCollections.map((c) => c.name));
156
+ const allCollectionNamesUnique = Array.from(new Set(collectionNames));
157
+ const allCollections = allCollectionNamesUnique.map((name) => configCollections.find((c) => c.name === name) ?? collections.find((c) => c.name === name)).filter((v) => v !== undefined);
158
+ const choices = allCollections.map((collection) => ({
151
159
  name: collection.name,
152
160
  value: collection,
153
161
  }));
@@ -805,6 +813,35 @@ export class InteractiveCLI {
805
813
  console.log(chalk.green("Data transfer completed."));
806
814
  }
807
815
 
816
+
817
+ private getLocalCollections(): Models.Collection[] {
818
+ const configCollections = this.controller!.config!.collections || [];
819
+ // @ts-expect-error - appwrite invalid types
820
+ return configCollections.map(c => ({
821
+ $id: c.$id || ulid(),
822
+ $createdAt: DateTime.now().toISO(),
823
+ $updatedAt: DateTime.now().toISO(),
824
+ name: c.name,
825
+ enabled: c.enabled || true,
826
+ documentSecurity: c.documentSecurity || false,
827
+ attributes: c.attributes || [],
828
+ indexes: c.indexes || [],
829
+ $permissions: PermissionToAppwritePermission(c.$permissions) || [],
830
+ databaseId: c.databaseId!,
831
+ }));
832
+ }
833
+
834
+ private getLocalDatabases(): Models.Database[] {
835
+ const configDatabases = this.controller!.config!.databases || [];
836
+ return configDatabases.map(db => ({
837
+ $id: db.$id || ulid(),
838
+ $createdAt: DateTime.now().toISO(),
839
+ $updatedAt: DateTime.now().toISO(),
840
+ name: db.name,
841
+ enabled: true,
842
+ }));
843
+ }
844
+
808
845
  private async reloadConfig(): Promise<void> {
809
846
  console.log(chalk.yellow("Reloading configuration files..."));
810
847
  try {