appwrite-utils-cli 0.0.272 → 0.0.273

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
@@ -118,6 +118,7 @@ This setup ensures that developers have robust tools at their fingertips to mana
118
118
 
119
119
  ### Changelog
120
120
 
121
+ - 0.0.273: Small fix for relationship attribute comparisons
121
122
  - 0.0.272: That's what I get for not testing lmao, also updated logic for checking for existing attributes to take the `format` into consideration from the database (URL's are not of `type: "url"`, they are of `format: "url"`)
122
123
  - 0.0.271: Small change to update attributes that are different from each other by deleting the attribute and recreating, as we cannot update most things
123
124
  - 0.0.270: Fixed enums in `--sync`, added optional OpenAPI generation (in progress, almost done, but wanted to push other changes), added `--endpoint`, `--project`, `--key` as optional parameters to change the target destination (shoutout to [pingu24k](https://github.com/pingu2k4) for pointing out these bugs and suggesting those changes for endpoint customization)
@@ -4,8 +4,17 @@ import { nameToIdMapping, enqueueOperation } from "./queue.js";
4
4
  import _ from "lodash";
5
5
  const attributesSame = (a, b) => {
6
6
  // Direct type comparison for non-string types
7
+ // Also check if the type IS string and has a format for either
8
+ // That means the format is the type of the attribute
7
9
  if (a.type === b.type &&
8
10
  !((a.type === "string" && a.format) || (b.type === "string" && b.format))) {
11
+ if (a.type === "relationship" && b.type === "relationship") {
12
+ return (a.key === b.key &&
13
+ a.relationType === b.relationType &&
14
+ a.twoWay === b.twoWay &&
15
+ a.twoWayKey === b.twoWayKey &&
16
+ a.required === b.required);
17
+ }
9
18
  return a.key === b.key && a.array === b.array && a.required === b.required;
10
19
  }
11
20
  if (a.type === "string" && a.format) {
@@ -42,7 +51,7 @@ export const createOrUpdateAttribute = async (db, dbId, collection, attribute) =
42
51
  return;
43
52
  }
44
53
  else if (foundAttribute && !attributesSame(foundAttribute, attribute)) {
45
- console.log(`Deleting attribute with same key ${attribute.key} -- ${foundAttribute.key} but different values, assuming update...`);
54
+ console.log(`Deleting attribute with same key ${attribute.key} -- ${foundAttribute.key} but different values -- ${JSON.stringify(attribute, null, 2)} -- ${JSON.stringify(foundAttribute, null, 2)}`);
46
55
  await db.deleteAttribute(dbId, collection.$id, attribute.key);
47
56
  }
48
57
  // Relationship attribute logic with adjustments
@@ -335,8 +335,9 @@ export const parseAttribute = (attribute) => {
335
335
  if (attribute.type === "string" &&
336
336
  attribute.format &&
337
337
  attribute.format.length > 0) {
338
+ console.log(`Parsing attribute ${attribute.key} with format ${attribute.format}, setting type to ${attribute.format.toLowerCase()}`);
338
339
  // @ts-expect-error
339
- attribute.type = attribute.format;
340
+ attribute.type = attribute.format.toLowerCase();
340
341
  delete attribute.format;
341
342
  }
342
343
  if (attribute.type === "string") {
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.272",
4
+ "version": "0.0.273",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -5,10 +5,21 @@ import _ from "lodash";
5
5
 
6
6
  const attributesSame = (a: Attribute, b: Attribute) => {
7
7
  // Direct type comparison for non-string types
8
+ // Also check if the type IS string and has a format for either
9
+ // That means the format is the type of the attribute
8
10
  if (
9
11
  a.type === b.type &&
10
12
  !((a.type === "string" && a.format) || (b.type === "string" && b.format))
11
13
  ) {
14
+ if (a.type === "relationship" && b.type === "relationship") {
15
+ return (
16
+ a.key === b.key &&
17
+ a.relationType === b.relationType &&
18
+ a.twoWay === b.twoWay &&
19
+ a.twoWayKey === b.twoWayKey &&
20
+ a.required === b.required
21
+ );
22
+ }
12
23
  return a.key === b.key && a.array === b.array && a.required === b.required;
13
24
  }
14
25
 
@@ -55,7 +66,13 @@ export const createOrUpdateAttribute = async (
55
66
  return;
56
67
  } else if (foundAttribute && !attributesSame(foundAttribute, attribute)) {
57
68
  console.log(
58
- `Deleting attribute with same key ${attribute.key} -- ${foundAttribute.key} but different values, assuming update...`
69
+ `Deleting attribute with same key ${attribute.key} -- ${
70
+ foundAttribute.key
71
+ } but different values -- ${JSON.stringify(
72
+ attribute,
73
+ null,
74
+ 2
75
+ )} -- ${JSON.stringify(foundAttribute, null, 2)}`
59
76
  );
60
77
  await db.deleteAttribute(dbId, collection.$id, attribute.key);
61
78
  }
@@ -415,8 +415,13 @@ export const parseAttribute = (
415
415
  attribute.format &&
416
416
  attribute.format.length > 0
417
417
  ) {
418
+ console.log(
419
+ `Parsing attribute ${attribute.key} with format ${
420
+ attribute.format
421
+ }, setting type to ${attribute.format.toLowerCase()}`
422
+ );
418
423
  // @ts-expect-error
419
- attribute.type = attribute.format;
424
+ attribute.type = attribute.format.toLowerCase();
420
425
  delete attribute.format;
421
426
  }
422
427
  if (attribute.type === "string") {