appwrite-utils-cli 0.0.279 → 0.0.280

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.
@@ -2,7 +2,7 @@ import { SchemaGenerator } from "./schemaStrings.js";
2
2
  import { Databases, Query } from "node-appwrite";
3
3
  import { fetchAllCollections } from "./collections.js";
4
4
  import { fetchAllDatabases } from "./databases.js";
5
- import { collectionSchema, attributeSchema, AppwriteConfigSchema, permissionsSchema, attributesSchema, indexesSchema, } from "appwrite-utils";
5
+ import { CollectionSchema, attributeSchema, AppwriteConfigSchema, permissionsSchema, attributesSchema, indexesSchema, } from "appwrite-utils";
6
6
  import { getDatabaseFromConfig } from "./afterImportActions.js";
7
7
  export class AppwriteToX {
8
8
  config;
@@ -88,7 +88,7 @@ export class AppwriteToX {
88
88
  this.collToAttributeMap.set(collection.name, collAttributes);
89
89
  const collIndexes = indexesSchema.parse(collection.indexes);
90
90
  // Prepare the collection object to be added or updated
91
- const collToPush = collectionSchema.parse({
91
+ const collToPush = CollectionSchema.parse({
92
92
  $id: collection.$id,
93
93
  name: collection.name,
94
94
  enabled: collection.enabled,
@@ -16,21 +16,21 @@ export declare const BackupSchema: z.ZodObject<{
16
16
  data: string;
17
17
  }>, "many">>;
18
18
  }, "strip", z.ZodTypeAny, {
19
- $id: string;
20
- $createdAt: string;
21
- $updatedAt: string;
22
- database: string;
23
19
  collections: string[];
24
20
  documents: {
25
21
  collectionId: string;
26
22
  data: string;
27
23
  }[];
28
- }, {
29
24
  $id: string;
30
25
  $createdAt: string;
31
26
  $updatedAt: string;
32
27
  database: string;
28
+ }, {
33
29
  collections: string[];
30
+ $id: string;
31
+ $createdAt: string;
32
+ $updatedAt: string;
33
+ database: string;
34
34
  documents?: {
35
35
  collectionId: string;
36
36
  data: string;
@@ -54,15 +54,15 @@ export declare const BackupCreateSchema: z.ZodObject<Omit<{
54
54
  data: string;
55
55
  }>, "many">>;
56
56
  }, "$id" | "$createdAt" | "$updatedAt">, "strip", z.ZodTypeAny, {
57
- database: string;
58
57
  collections: string[];
59
58
  documents: {
60
59
  collectionId: string;
61
60
  data: string;
62
61
  }[];
63
- }, {
64
62
  database: string;
63
+ }, {
65
64
  collections: string[];
65
+ database: string;
66
66
  documents?: {
67
67
  collectionId: string;
68
68
  data: string;
@@ -1,5 +1,5 @@
1
1
  import type { ImportDataActions } from "./importDataActions.js";
2
- import { type AppwriteConfig, type AttributeMappings, type ConfigCollection, type ConfigDatabase, type IdMapping, type ImportDef } from "appwrite-utils";
2
+ import { type AppwriteConfig, type AttributeMappings, type CollectionCreate, type ConfigDatabase, type IdMapping, type ImportDef } from "appwrite-utils";
3
3
  import { z } from "zod";
4
4
  import { type Databases } from "node-appwrite";
5
5
  export declare const CollectionImportDataSchema: z.ZodObject<{
@@ -1670,7 +1670,7 @@ export declare class DataLoader {
1670
1670
  loadData(importDef: ImportDef): any[];
1671
1671
  checkMapValuesForId(newId: string, collectionName: string): string | false;
1672
1672
  getTrueUniqueId(collectionName: string): string;
1673
- createContext(db: ConfigDatabase, collection: ConfigCollection, item: any, docId: string): any;
1673
+ createContext(db: ConfigDatabase, collection: CollectionCreate, item: any, docId: string): any;
1674
1674
  /**
1675
1675
  * Transforms the given item based on the provided attribute mappings.
1676
1676
  * This method applies conversion rules to the item's attributes as defined in the attribute mappings.
@@ -1706,7 +1706,7 @@ export declare class DataLoader {
1706
1706
  * @param collection - The collection configuration.
1707
1707
  * @param importDef - The import definition containing the attribute mappings and other relevant info.
1708
1708
  */
1709
- prepareUserCollectionCreateData(db: ConfigDatabase, collection: ConfigCollection, importDef: ImportDef): Promise<void>;
1709
+ prepareUserCollectionCreateData(db: ConfigDatabase, collection: CollectionCreate, importDef: ImportDef): Promise<void>;
1710
1710
  /**
1711
1711
  * Prepares the data for creating documents in a collection.
1712
1712
  * This involves loading the data, transforming it, and handling ID mappings.
@@ -1715,7 +1715,7 @@ export declare class DataLoader {
1715
1715
  * @param collection - The collection configuration.
1716
1716
  * @param importDef - The import definition containing the attribute mappings and other relevant info.
1717
1717
  */
1718
- prepareCreateData(db: ConfigDatabase, collection: ConfigCollection, importDef: ImportDef): Promise<void>;
1718
+ prepareCreateData(db: ConfigDatabase, collection: CollectionCreate, importDef: ImportDef): Promise<void>;
1719
1719
  /**
1720
1720
  * Prepares the data for updating documents within a collection.
1721
1721
  * This method loads the raw data based on the import definition, transforms it according to the attribute mappings,
@@ -1726,7 +1726,7 @@ export declare class DataLoader {
1726
1726
  * @param collection - The collection configuration.
1727
1727
  * @param importDef - The import definition containing the attribute mappings and other relevant info.
1728
1728
  */
1729
- prepareUpdateData(db: ConfigDatabase, collection: ConfigCollection, importDef: ImportDef): Promise<void>;
1729
+ prepareUpdateData(db: ConfigDatabase, collection: CollectionCreate, importDef: ImportDef): Promise<void>;
1730
1730
  private updateReferencesBasedOnAttributeMappings;
1731
1731
  private getMergedId;
1732
1732
  /**
@@ -1,5 +1,5 @@
1
1
  import { OpenAPIRegistry, OpenApiGeneratorV3, OpenApiGeneratorV31, } from "@asteasolutions/zod-to-openapi";
2
- import { attributeSchema, collectionSchema, } from "appwrite-utils";
2
+ import { attributeSchema, CollectionSchema, } from "appwrite-utils";
3
3
  import { z } from "zod";
4
4
  import { writeFileSync } from "fs";
5
5
  const registry = new OpenAPIRegistry();
@@ -13,12 +13,10 @@ export const generateOpenApi = async (config) => {
13
13
  return transformTypeToOpenApi(attributeSchema);
14
14
  });
15
15
  // Create and register the collection schema with descriptions
16
- const updatedCollectionSchema = collectionSchema
17
- .extend({
16
+ const updatedCollectionSchema = CollectionSchema.extend({
18
17
  // @ts-ignore
19
18
  attributes: z.array(z.union(attributeSchemas)),
20
- })
21
- .openapi(collection.description ?? "No description");
19
+ }).openapi(collection.description ?? "No description");
22
20
  // Register the updated collection schema under the collection name
23
21
  registry.register(collection.name, updatedCollectionSchema);
24
22
  }
@@ -12,17 +12,17 @@ export declare const AuthUserSchema: z.ZodObject<{
12
12
  $id: string;
13
13
  prefs: Record<string, string>;
14
14
  labels: string[];
15
+ email?: string | null | undefined;
16
+ name?: string | null | undefined;
15
17
  $createdAt?: string | undefined;
16
18
  $updatedAt?: string | undefined;
17
- name?: string | null | undefined;
18
- email?: string | null | undefined;
19
19
  phone?: string | null | undefined;
20
20
  }, {
21
21
  $id: string;
22
+ email?: string | null | undefined;
23
+ name?: string | null | undefined;
22
24
  $createdAt?: string | undefined;
23
25
  $updatedAt?: string | undefined;
24
- name?: string | null | undefined;
25
- email?: string | null | undefined;
26
26
  phone?: string | null | undefined;
27
27
  prefs?: Record<string, string> | undefined;
28
28
  labels?: string[] | undefined;
@@ -43,19 +43,19 @@ export declare const AuthUserCreateSchema: z.ZodObject<z.objectUtil.extendShape<
43
43
  }>, "strip", z.ZodTypeAny, {
44
44
  prefs: Record<string, string>;
45
45
  labels: string[];
46
+ email?: string | null | undefined;
47
+ password?: string | undefined;
48
+ name?: string | null | undefined;
46
49
  $createdAt?: string | undefined;
47
50
  $updatedAt?: string | undefined;
48
- name?: string | null | undefined;
49
- password?: string | undefined;
50
- email?: string | null | undefined;
51
51
  phone?: string | null | undefined;
52
52
  userId?: string | undefined;
53
53
  }, {
54
+ email?: string | null | undefined;
55
+ password?: string | undefined;
56
+ name?: string | null | undefined;
54
57
  $createdAt?: string | undefined;
55
58
  $updatedAt?: string | undefined;
56
- name?: string | null | undefined;
57
- password?: string | undefined;
58
- email?: string | null | undefined;
59
59
  phone?: string | null | undefined;
60
60
  prefs?: Record<string, string> | undefined;
61
61
  labels?: string[] | undefined;
package/dist/setup.js CHANGED
File without changes
@@ -1,5 +1,6 @@
1
1
  import type { Models } from "node-appwrite";
2
2
  import type { CollectionImportData } from "../migrations/dataLoader.js";
3
+ import type { ConfigCollection } from "appwrite-utils";
3
4
  export declare const toPascalCase: (str: string) => string;
4
5
  export declare const toCamelCase: (str: string) => string;
5
6
  export declare const ensureDirectoryExistence: (filePath: string) => true | undefined;
@@ -33,4 +34,4 @@ export declare const getFileViewUrl: (endpoint: string, projectId: string, bucke
33
34
  * @return {string} The complete download URL for the file.
34
35
  */
35
36
  export declare const getFileDownloadUrl: (endpoint: string, projectId: string, bucketId: string, fileId: string, jwt?: Models.Jwt) => string;
36
- export declare const finalizeByAttributeMap: (appwriteFolderPath: string, collection: Collections, item: CollectionImportData["data"][number]) => Promise<any>;
37
+ export declare const finalizeByAttributeMap: (appwriteFolderPath: string, collection: ConfigCollection, item: CollectionImportData["data"][number]) => Promise<any>;
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.0.279",
4
+ "version": "0.0.280",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@asteasolutions/zod-to-openapi": "^7.0.0",
36
36
  "@types/inquirer": "^9.0.7",
37
- "appwrite-utils": "latest",
37
+ "appwrite-utils": "^0.1.225",
38
38
  "commander": "^12.0.0",
39
39
  "inquirer": "^9.2.20",
40
40
  "js-yaml": "^4.1.0",
@@ -3,7 +3,7 @@ import { Databases, Query, type Models, type Permission } from "node-appwrite";
3
3
  import { fetchAllCollections } from "./collections.js";
4
4
  import { fetchAllDatabases } from "./databases.js";
5
5
  import {
6
- collectionSchema,
6
+ CollectionSchema,
7
7
  attributeSchema,
8
8
  type AppwriteConfig,
9
9
  AppwriteConfigSchema,
@@ -130,7 +130,7 @@ export class AppwriteToX {
130
130
  const collIndexes = indexesSchema.parse(collection.indexes);
131
131
 
132
132
  // Prepare the collection object to be added or updated
133
- const collToPush = collectionSchema.parse({
133
+ const collToPush = CollectionSchema.parse({
134
134
  $id: collection.$id,
135
135
  name: collection.name,
136
136
  enabled: collection.enabled,
@@ -32,7 +32,7 @@ export const createOrUpdateAttribute = async (
32
32
  const collectionAttr = collection.attributes.find(
33
33
  // @ts-expect-error
34
34
  (attr) => attr.key === attribute.key
35
- ) as unknown;
35
+ ) as unknown as any;
36
36
  foundAttribute = parseAttribute(collectionAttr);
37
37
  } catch (error) {
38
38
  foundAttribute = undefined;
@@ -5,7 +5,7 @@ import {
5
5
  importDefSchema,
6
6
  type AppwriteConfig,
7
7
  type AttributeMappings,
8
- type ConfigCollection,
8
+ type CollectionCreate,
9
9
  type ConfigDatabase,
10
10
  type IdMapping,
11
11
  type ImportDef,
@@ -171,7 +171,7 @@ export class DataLoader {
171
171
  // Method to create a context object for data transformation
172
172
  createContext(
173
173
  db: ConfigDatabase,
174
- collection: ConfigCollection,
174
+ collection: CollectionCreate,
175
175
  item: any,
176
176
  docId: string
177
177
  ) {
@@ -739,7 +739,7 @@ export class DataLoader {
739
739
  */
740
740
  async prepareUserCollectionCreateData(
741
741
  db: ConfigDatabase,
742
- collection: ConfigCollection,
742
+ collection: CollectionCreate,
743
743
  importDef: ImportDef
744
744
  ): Promise<void> {
745
745
  // Load the raw data based on the import definition
@@ -924,7 +924,7 @@ export class DataLoader {
924
924
  */
925
925
  async prepareCreateData(
926
926
  db: ConfigDatabase,
927
- collection: ConfigCollection,
927
+ collection: CollectionCreate,
928
928
  importDef: ImportDef
929
929
  ): Promise<void> {
930
930
  // Load the raw data based on the import definition
@@ -1037,7 +1037,7 @@ export class DataLoader {
1037
1037
  */
1038
1038
  async prepareUpdateData(
1039
1039
  db: ConfigDatabase,
1040
- collection: ConfigCollection,
1040
+ collection: CollectionCreate,
1041
1041
  importDef: ImportDef
1042
1042
  ) {
1043
1043
  // Retrieve the current collection data and old-to-new ID map from the import map
@@ -5,7 +5,7 @@ import {
5
5
  } from "@asteasolutions/zod-to-openapi";
6
6
  import {
7
7
  attributeSchema,
8
- collectionSchema,
8
+ CollectionSchema,
9
9
  type AppwriteConfig,
10
10
  type Attribute,
11
11
  type Collection,
@@ -27,12 +27,10 @@ export const generateOpenApi = async (config: AppwriteConfig) => {
27
27
  });
28
28
 
29
29
  // Create and register the collection schema with descriptions
30
- const updatedCollectionSchema = collectionSchema
31
- .extend({
32
- // @ts-ignore
33
- attributes: z.array(z.union(attributeSchemas)),
34
- })
35
- .openapi(collection.description ?? "No description");
30
+ const updatedCollectionSchema = CollectionSchema.extend({
31
+ // @ts-ignore
32
+ attributes: z.array(z.union(attributeSchemas)),
33
+ }).openapi(collection.description ?? "No description");
36
34
 
37
35
  // Register the updated collection schema under the collection name
38
36
  registry.register(collection.name, updatedCollectionSchema);
package/tsconfig.json CHANGED
@@ -32,6 +32,6 @@
32
32
  "rootDir": "./src",
33
33
  "declaration": true
34
34
  },
35
- "include": ["src/main.ts", "src/**/*"],
35
+ "include": ["src/**/*"],
36
36
  "exclude": ["node_modules", "dist", "src/appwrite", "example/*"]
37
37
  }