appwrite-utils-cli 0.10.81 → 0.10.82

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
@@ -150,6 +150,7 @@ This updated CLI ensures that developers have robust tools at their fingertips t
150
150
 
151
151
  ## Changelog
152
152
 
153
+ - 0.10.82: Fixed the `lodash` import, replaced with `es-toolkit`
153
154
  - 0.10.81: Fixed `wipeCollection` -- it wasn't properly deleting all files in a loop
154
155
  - 0.10.80: Updated `appwrite-utils` req
155
156
  - 0.10.78: Fixed `attributesSame` so it will properly update attributes that have changed
@@ -2,46 +2,46 @@ import { Client, Databases, ID, Permission, Query, } from "node-appwrite";
2
2
  import { nameToIdMapping, processQueue } from "../migrations/queue.js";
3
3
  import { createUpdateCollectionAttributes } from "./attributes.js";
4
4
  import { createOrUpdateIndexes } from "./indexes.js";
5
- import _, { initial } from "lodash";
6
5
  import { SchemaGenerator } from "../migrations/schemaStrings.js";
6
+ import { isNull, isUndefined, isNil, isPlainObject, isString, isJSONValue, } from "es-toolkit";
7
7
  import { delay, tryAwaitWithRetry } from "../utils/helperFunctions.js";
8
8
  export const documentExists = async (db, dbId, targetCollectionId, toCreateObject) => {
9
- // Had to do this because kept running into issues with type checking arrays so, sorry 40ms
10
9
  const collection = await db.getCollection(dbId, targetCollectionId);
11
10
  const attributes = collection.attributes;
12
11
  let arrayTypeAttributes = attributes
13
12
  .filter((attribute) => attribute.array === true)
14
13
  .map((attribute) => attribute.key);
15
- // Function to check if a string is JSON
16
14
  const isJsonString = (str) => {
17
15
  try {
18
16
  const json = JSON.parse(str);
19
- return typeof json === "object" && json !== null; // Check if parsed JSON is an object or array
17
+ return typeof json === "object" && json !== null;
20
18
  }
21
19
  catch (e) {
22
20
  return false;
23
21
  }
24
22
  };
25
- // Validate and prepare query parameters
26
- const validQueryParams = _.chain(toCreateObject)
27
- .pickBy((value, key) => !arrayTypeAttributes.includes(key) &&
23
+ // Convert object to entries and filter
24
+ const validEntries = Object.entries(toCreateObject).filter(([key, value]) => !arrayTypeAttributes.includes(key) &&
28
25
  !key.startsWith("$") &&
29
- !_.isNull(value) &&
30
- !_.isUndefined(value) &&
31
- !_.isEmpty(value) &&
32
- !_.isObject(value) && // Keeps excluding objects
33
- !_.isArray(value) && // Explicitly exclude arrays
34
- !(_.isString(value) && isJsonString(value)) && // Exclude JSON strings
35
- (_.isString(value) ? value.length < 4096 && value.length > 0 : true) // String length check
36
- )
37
- .mapValues((value, key) => _.isString(value) || _.isNumber(value) || _.isBoolean(value)
38
- ? value
39
- : null)
40
- .omitBy(_.isNull) // Remove any null values that might have been added in mapValues
41
- .toPairs()
42
- .slice(0, 25) // Limit to 25 to adhere to query limit
43
- .map(([key, value]) => Query.equal(key, value))
44
- .value();
26
+ !isNull(value) &&
27
+ !isUndefined(value) &&
28
+ !isNil(value) &&
29
+ !isPlainObject(value) &&
30
+ !Array.isArray(value) &&
31
+ !(isString(value) && isJsonString(value)) &&
32
+ (isString(value) ? value.length < 4096 && value.length > 0 : true));
33
+ // Map and filter valid entries
34
+ const validMappedEntries = validEntries
35
+ .map(([key, value]) => [
36
+ key,
37
+ isString(value) || typeof value === "number" || typeof value === "boolean"
38
+ ? value
39
+ : null,
40
+ ])
41
+ .filter(([key, value]) => !isNull(value) && isString(key))
42
+ .slice(0, 25);
43
+ // Convert to Query parameters
44
+ const validQueryParams = validMappedEntries.map(([key, value]) => Query.equal(key, value));
45
45
  // Execute the query with the validated and prepared parameters
46
46
  const result = await db.listDocuments(dbId, targetCollectionId, validQueryParams);
47
47
  return result.documents[0] || null;
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.10.81",
4
+ "version": "0.10.82",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -35,10 +35,10 @@
35
35
  "chalk": "^5.3.0",
36
36
  "cli-progress": "^3.12.0",
37
37
  "commander": "^12.1.0",
38
+ "es-toolkit": "^1.32.0",
38
39
  "ignore": "^6.0.2",
39
40
  "inquirer": "^9.3.6",
40
41
  "js-yaml": "^4.1.0",
41
- "lodash": "^4.17.21",
42
42
  "luxon": "^3.5.0",
43
43
  "nanostores": "^0.10.3",
44
44
  "node-appwrite": "^14.1.0",
@@ -10,8 +10,15 @@ import type { AppwriteConfig, CollectionCreate, Indexes } from "appwrite-utils";
10
10
  import { nameToIdMapping, processQueue } from "../migrations/queue.js";
11
11
  import { createUpdateCollectionAttributes } from "./attributes.js";
12
12
  import { createOrUpdateIndexes } from "./indexes.js";
13
- import _, { initial } from "lodash";
14
13
  import { SchemaGenerator } from "../migrations/schemaStrings.js";
14
+ import {
15
+ isNull,
16
+ isUndefined,
17
+ isNil,
18
+ isPlainObject,
19
+ isString,
20
+ isJSONValue,
21
+ } from "es-toolkit";
15
22
  import { delay, tryAwaitWithRetry } from "../utils/helperFunctions.js";
16
23
 
17
24
  export const documentExists = async (
@@ -20,46 +27,50 @@ export const documentExists = async (
20
27
  targetCollectionId: string,
21
28
  toCreateObject: any
22
29
  ): Promise<Models.Document | null> => {
23
- // Had to do this because kept running into issues with type checking arrays so, sorry 40ms
24
30
  const collection = await db.getCollection(dbId, targetCollectionId);
25
31
  const attributes = collection.attributes as any[];
26
32
  let arrayTypeAttributes = attributes
27
33
  .filter((attribute: any) => attribute.array === true)
28
34
  .map((attribute: any) => attribute.key);
29
- // Function to check if a string is JSON
35
+
30
36
  const isJsonString = (str: string) => {
31
37
  try {
32
38
  const json = JSON.parse(str);
33
- return typeof json === "object" && json !== null; // Check if parsed JSON is an object or array
39
+ return typeof json === "object" && json !== null;
34
40
  } catch (e) {
35
41
  return false;
36
42
  }
37
43
  };
38
44
 
39
- // Validate and prepare query parameters
40
- const validQueryParams = _.chain(toCreateObject)
41
- .pickBy(
42
- (value, key) =>
43
- !arrayTypeAttributes.includes(key) &&
44
- !key.startsWith("$") &&
45
- !_.isNull(value) &&
46
- !_.isUndefined(value) &&
47
- !_.isEmpty(value) &&
48
- !_.isObject(value) && // Keeps excluding objects
49
- !_.isArray(value) && // Explicitly exclude arrays
50
- !(_.isString(value) && isJsonString(value)) && // Exclude JSON strings
51
- (_.isString(value) ? value.length < 4096 && value.length > 0 : true) // String length check
52
- )
53
- .mapValues((value, key) =>
54
- _.isString(value) || _.isNumber(value) || _.isBoolean(value)
45
+ // Convert object to entries and filter
46
+ const validEntries = Object.entries(toCreateObject).filter(
47
+ ([key, value]) =>
48
+ !arrayTypeAttributes.includes(key) &&
49
+ !key.startsWith("$") &&
50
+ !isNull(value) &&
51
+ !isUndefined(value) &&
52
+ !isNil(value) &&
53
+ !isPlainObject(value) &&
54
+ !Array.isArray(value) &&
55
+ !(isString(value) && isJsonString(value)) &&
56
+ (isString(value) ? value.length < 4096 && value.length > 0 : true)
57
+ );
58
+
59
+ // Map and filter valid entries
60
+ const validMappedEntries = validEntries
61
+ .map(([key, value]) => [
62
+ key,
63
+ isString(value) || typeof value === "number" || typeof value === "boolean"
55
64
  ? value
56
- : null
57
- )
58
- .omitBy(_.isNull) // Remove any null values that might have been added in mapValues
59
- .toPairs()
60
- .slice(0, 25) // Limit to 25 to adhere to query limit
61
- .map(([key, value]) => Query.equal(key, value as any))
62
- .value();
65
+ : null,
66
+ ])
67
+ .filter(([key, value]) => !isNull(value) && isString(key))
68
+ .slice(0, 25);
69
+
70
+ // Convert to Query parameters
71
+ const validQueryParams = validMappedEntries.map(([key, value]) =>
72
+ Query.equal(key as string, value as any)
73
+ );
63
74
 
64
75
  // Execute the query with the validated and prepared parameters
65
76
  const result = await db.listDocuments(