appwrite-utils-cli 0.9.66 → 0.9.70

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
@@ -124,6 +124,8 @@ This updated CLI ensures that developers have robust tools at their fingertips t
124
124
 
125
125
  ## Changelog
126
126
 
127
+ - 0.9.70: I think I stopped it from deleting attributes, my bad on that
128
+ - 0.9.68: Temporarily disabled updating Attributes until `updateStringAttribute` is fixed -- it just deletes them now
127
129
  - 0.9.65: Temporary fix for Appwrite's `updateStringAttribute` bug
128
130
  - 0.9.64: Fixed string attribute requiring xdefault
129
131
  - 0.9.61: Remove fileURLToPath -- should hopefully fix windows
@@ -4,12 +4,58 @@ import { nameToIdMapping, enqueueOperation } from "./queue.js";
4
4
  import _ from "lodash";
5
5
  import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
6
6
  const attributesSame = (databaseAttribute, configAttribute) => {
7
- return databaseAttribute.key === configAttribute.key;
7
+ const attributesToCheck = [
8
+ 'key',
9
+ 'type',
10
+ 'array',
11
+ 'encrypted',
12
+ 'required',
13
+ 'size',
14
+ 'min',
15
+ 'max',
16
+ 'xdefault',
17
+ 'elements',
18
+ 'relationType',
19
+ 'twoWay',
20
+ 'twoWayKey',
21
+ 'onDelete',
22
+ 'relatedCollection'
23
+ ];
24
+ return attributesToCheck.every(attr => {
25
+ // Check if both objects have the attribute
26
+ const dbHasAttr = attr in databaseAttribute;
27
+ const configHasAttr = attr in configAttribute;
28
+ // If both have the attribute, compare values
29
+ if (dbHasAttr && configHasAttr) {
30
+ const dbValue = databaseAttribute[attr];
31
+ const configValue = configAttribute[attr];
32
+ // Consider undefined and null as equivalent
33
+ if ((dbValue === undefined || dbValue === null) && (configValue === undefined || configValue === null)) {
34
+ return true;
35
+ }
36
+ return dbValue === configValue;
37
+ }
38
+ // If neither has the attribute, consider it the same
39
+ if (!dbHasAttr && !configHasAttr) {
40
+ return true;
41
+ }
42
+ // If one has the attribute and the other doesn't, check if it's undefined or null
43
+ if (dbHasAttr && !configHasAttr) {
44
+ const dbValue = databaseAttribute[attr];
45
+ return dbValue === undefined || dbValue === null;
46
+ }
47
+ if (!dbHasAttr && configHasAttr) {
48
+ const configValue = configAttribute[attr];
49
+ return configValue === undefined || configValue === null;
50
+ }
51
+ // If we reach here, the attributes are different
52
+ return false;
53
+ });
8
54
  };
9
55
  export const createOrUpdateAttribute = async (db, dbId, collection, attribute) => {
10
56
  let action = "create";
11
57
  let foundAttribute;
12
- const updateEnabled = true;
58
+ const updateEnabled = false;
13
59
  let finalAttribute = attribute;
14
60
  try {
15
61
  const collectionAttr = collection.attributes.find(
@@ -20,38 +66,24 @@ export const createOrUpdateAttribute = async (db, dbId, collection, attribute) =
20
66
  catch (error) {
21
67
  foundAttribute = undefined;
22
68
  }
23
- if (foundAttribute && updateEnabled) {
24
- const changedProperties = Object.keys(attribute).filter(key => {
25
- // Only consider properties that are defined and not null in the new attribute
26
- if (attribute[key] !== undefined && attribute[key] !== null && attribute[key] !== '') {
27
- // Check if the property exists in the found attribute and is different
28
- return foundAttribute[key] !== attribute[key];
29
- }
30
- return false;
31
- });
32
- if (changedProperties.length > 0) {
33
- console.log(`Changed properties: ${changedProperties.join(', ')}`);
34
- // Merge the attributes, prioritizing the new attribute's values
35
- finalAttribute = {
36
- ...foundAttribute,
37
- ...attribute,
38
- };
39
- action = "update";
40
- }
41
- else {
42
- // If no properties that can be updated have changed, return early
43
- return;
44
- }
69
+ if (foundAttribute && attributesSame(foundAttribute, attribute) && updateEnabled) {
70
+ finalAttribute = {
71
+ ...attribute,
72
+ ...foundAttribute,
73
+ };
74
+ action = "update";
45
75
  }
46
- else if (!foundAttribute) {
47
- // If the attribute doesn't exist, we'll create it
76
+ else if (foundAttribute && !attributesSame(foundAttribute, attribute) && updateEnabled) {
77
+ console.log(`Updating attribute with same key ${attribute.key} but different values`);
48
78
  finalAttribute = attribute;
49
- action = "create";
79
+ action = "update";
50
80
  }
51
- else if (!updateEnabled) {
52
- // If updates are not enabled and the attribute exists, we do nothing
81
+ else if (!updateEnabled && foundAttribute && !attributesSame(foundAttribute, attribute)) {
82
+ await db.deleteAttribute(dbId, collection.$id, attribute.key);
83
+ console.log(`Deleted attribute: ${attribute.key} to recreate it because they diff (update disabled temporarily)`);
53
84
  return;
54
85
  }
86
+ // console.log(`${action}-ing attribute: ${finalAttribute.key}`);
55
87
  // Relationship attribute logic with adjustments
56
88
  let collectionFoundViaRelatedCollection;
57
89
  let relatedCollectionId;
@@ -92,10 +124,10 @@ export const createOrUpdateAttribute = async (db, dbId, collection, attribute) =
92
124
  switch (finalAttribute.type) {
93
125
  case "string":
94
126
  if (action === "create") {
95
- await tryAwaitWithRetry(async () => await db.createStringAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.size, finalAttribute.required, finalAttribute.xdefault, finalAttribute.array, finalAttribute.encrypted));
127
+ await tryAwaitWithRetry(async () => await db.createStringAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.size, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null), finalAttribute.array || false, finalAttribute.encrypted));
96
128
  }
97
129
  else {
98
- await tryAwaitWithRetry(async () => await db.updateStringAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault, finalAttribute.size));
130
+ await tryAwaitWithRetry(async () => await db.updateStringAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : ""), finalAttribute.size));
99
131
  }
100
132
  break;
101
133
  case "integer":
@@ -108,7 +140,7 @@ export const createOrUpdateAttribute = async (db, dbId, collection, attribute) =
108
140
  BigInt(finalAttribute.max) === BigInt(9223372036854776000)) {
109
141
  delete finalAttribute.max;
110
142
  }
111
- await tryAwaitWithRetry(async () => await db.createIntegerAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.min, finalAttribute.max, finalAttribute.xdefault, finalAttribute.array));
143
+ await tryAwaitWithRetry(async () => await db.createIntegerAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.min || -2147483647, finalAttribute.max || 2147483647, finalAttribute.xdefault || (finalAttribute.required ? undefined : ""), finalAttribute.array || false));
112
144
  }
113
145
  else {
114
146
  if (finalAttribute.min &&
@@ -119,63 +151,63 @@ export const createOrUpdateAttribute = async (db, dbId, collection, attribute) =
119
151
  BigInt(finalAttribute.max) === BigInt(9223372036854776000)) {
120
152
  delete finalAttribute.max;
121
153
  }
122
- await tryAwaitWithRetry(async () => await db.updateIntegerAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.min, finalAttribute.max, finalAttribute.xdefault));
154
+ await tryAwaitWithRetry(async () => await db.updateIntegerAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.min || -2147483647, finalAttribute.max || 2147483647, finalAttribute.xdefault || (finalAttribute.required ? undefined : null)));
123
155
  }
124
156
  break;
125
157
  case "float":
126
158
  if (action === "create") {
127
- await tryAwaitWithRetry(async () => await db.createFloatAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.min, finalAttribute.max, finalAttribute.xdefault, finalAttribute.array));
159
+ await tryAwaitWithRetry(async () => await db.createFloatAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.min || -2147483647, finalAttribute.max || 2147483647, finalAttribute.xdefault || (finalAttribute.required ? undefined : null), finalAttribute.array || false));
128
160
  }
129
161
  else {
130
- await tryAwaitWithRetry(async () => await db.updateFloatAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.min, finalAttribute.max, finalAttribute.xdefault));
162
+ await tryAwaitWithRetry(async () => await db.updateFloatAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.min || -2147483647, finalAttribute.max || 2147483647, finalAttribute.xdefault || (finalAttribute.required ? undefined : null)));
131
163
  }
132
164
  break;
133
165
  case "boolean":
134
166
  if (action === "create") {
135
- await tryAwaitWithRetry(async () => await db.createBooleanAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault, finalAttribute.array));
167
+ await tryAwaitWithRetry(async () => await db.createBooleanAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null), finalAttribute.array || false));
136
168
  }
137
169
  else {
138
- await tryAwaitWithRetry(async () => await db.updateBooleanAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault));
170
+ await tryAwaitWithRetry(async () => await db.updateBooleanAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null)));
139
171
  }
140
172
  break;
141
173
  case "datetime":
142
174
  if (action === "create") {
143
- await tryAwaitWithRetry(async () => await db.createDatetimeAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault, finalAttribute.array));
175
+ await tryAwaitWithRetry(async () => await db.createDatetimeAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null), finalAttribute.array || false));
144
176
  }
145
177
  else {
146
- await tryAwaitWithRetry(async () => await db.updateDatetimeAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault));
178
+ await tryAwaitWithRetry(async () => await db.updateDatetimeAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null)));
147
179
  }
148
180
  break;
149
181
  case "email":
150
182
  if (action === "create") {
151
- await tryAwaitWithRetry(async () => await db.createEmailAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault, finalAttribute.array));
183
+ await tryAwaitWithRetry(async () => await db.createEmailAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null), finalAttribute.array || false));
152
184
  }
153
185
  else {
154
- await tryAwaitWithRetry(async () => await db.updateEmailAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault));
186
+ await tryAwaitWithRetry(async () => await db.updateEmailAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null)));
155
187
  }
156
188
  break;
157
189
  case "ip":
158
190
  if (action === "create") {
159
- await tryAwaitWithRetry(async () => await db.createIpAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault, finalAttribute.array));
191
+ await tryAwaitWithRetry(async () => await db.createIpAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null), finalAttribute.array || false));
160
192
  }
161
193
  else {
162
- await tryAwaitWithRetry(async () => await db.updateIpAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault));
194
+ await tryAwaitWithRetry(async () => await db.updateIpAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null)));
163
195
  }
164
196
  break;
165
197
  case "url":
166
198
  if (action === "create") {
167
- await tryAwaitWithRetry(async () => await db.createUrlAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault, finalAttribute.array));
199
+ await tryAwaitWithRetry(async () => await db.createUrlAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null), finalAttribute.array || false));
168
200
  }
169
201
  else {
170
- await tryAwaitWithRetry(async () => await db.updateUrlAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required, finalAttribute.xdefault));
202
+ await tryAwaitWithRetry(async () => await db.updateUrlAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null)));
171
203
  }
172
204
  break;
173
205
  case "enum":
174
206
  if (action === "create") {
175
- await tryAwaitWithRetry(async () => await db.createEnumAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.elements, finalAttribute.required, finalAttribute.xdefault, finalAttribute.array));
207
+ await tryAwaitWithRetry(async () => await db.createEnumAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.elements, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null), finalAttribute.array || false));
176
208
  }
177
209
  else {
178
- await tryAwaitWithRetry(async () => await db.updateEnumAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.elements, finalAttribute.required, finalAttribute.xdefault));
210
+ await tryAwaitWithRetry(async () => await db.updateEnumAttribute(dbId, collection.$id, finalAttribute.key, finalAttribute.elements, finalAttribute.required || false, finalAttribute.xdefault || (finalAttribute.required ? undefined : null)));
179
211
  }
180
212
  break;
181
213
  case "relationship":
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.66",
4
+ "version": "0.9.70",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -12,7 +12,61 @@ const attributesSame = (
12
12
  databaseAttribute: Attribute,
13
13
  configAttribute: Attribute
14
14
  ): boolean => {
15
- return databaseAttribute.key === configAttribute.key;
15
+ const attributesToCheck = [
16
+ 'key',
17
+ 'type',
18
+ 'array',
19
+ 'encrypted',
20
+ 'required',
21
+ 'size',
22
+ 'min',
23
+ 'max',
24
+ 'xdefault',
25
+ 'elements',
26
+ 'relationType',
27
+ 'twoWay',
28
+ 'twoWayKey',
29
+ 'onDelete',
30
+ 'relatedCollection'
31
+ ];
32
+
33
+ return attributesToCheck.every(attr => {
34
+ // Check if both objects have the attribute
35
+ const dbHasAttr = attr in databaseAttribute;
36
+ const configHasAttr = attr in configAttribute;
37
+
38
+ // If both have the attribute, compare values
39
+ if (dbHasAttr && configHasAttr) {
40
+ const dbValue = databaseAttribute[attr as keyof typeof databaseAttribute];
41
+ const configValue = configAttribute[attr as keyof typeof configAttribute];
42
+
43
+ // Consider undefined and null as equivalent
44
+ if ((dbValue === undefined || dbValue === null) && (configValue === undefined || configValue === null)) {
45
+ return true;
46
+ }
47
+
48
+ return dbValue === configValue;
49
+ }
50
+
51
+ // If neither has the attribute, consider it the same
52
+ if (!dbHasAttr && !configHasAttr) {
53
+ return true;
54
+ }
55
+
56
+ // If one has the attribute and the other doesn't, check if it's undefined or null
57
+ if (dbHasAttr && !configHasAttr) {
58
+ const dbValue = databaseAttribute[attr as keyof typeof databaseAttribute];
59
+ return dbValue === undefined || dbValue === null;
60
+ }
61
+
62
+ if (!dbHasAttr && configHasAttr) {
63
+ const configValue = configAttribute[attr as keyof typeof configAttribute];
64
+ return configValue === undefined || configValue === null;
65
+ }
66
+
67
+ // If we reach here, the attributes are different
68
+ return false;
69
+ });
16
70
  };
17
71
 
18
72
  export const createOrUpdateAttribute = async (
@@ -23,7 +77,7 @@ export const createOrUpdateAttribute = async (
23
77
  ): Promise<void> => {
24
78
  let action = "create";
25
79
  let foundAttribute: Attribute | undefined;
26
- const updateEnabled = true;
80
+ const updateEnabled = false;
27
81
  let finalAttribute: any = attribute;
28
82
  try {
29
83
  const collectionAttr = collection.attributes.find(
@@ -35,38 +89,26 @@ export const createOrUpdateAttribute = async (
35
89
  foundAttribute = undefined;
36
90
  }
37
91
 
38
- if (foundAttribute && updateEnabled) {
39
- const changedProperties = Object.keys(attribute).filter(key => {
40
- // Only consider properties that are defined and not null in the new attribute
41
- if (attribute[key as keyof typeof attribute] !== undefined && attribute[key as keyof typeof attribute] !== null && attribute[key as keyof typeof attribute] !== '') {
42
- // Check if the property exists in the found attribute and is different
43
- return foundAttribute[key as keyof typeof foundAttribute] !== attribute[key as keyof typeof attribute];
44
- }
45
- return false;
46
- });
47
-
48
- if (changedProperties.length > 0) {
49
- console.log(`Changed properties: ${changedProperties.join(', ')}`);
50
-
51
- // Merge the attributes, prioritizing the new attribute's values
52
- finalAttribute = {
53
- ...foundAttribute,
54
- ...attribute,
55
- };
56
- action = "update";
57
- } else {
58
- // If no properties that can be updated have changed, return early
59
- return;
60
- }
61
- } else if (!foundAttribute) {
62
- // If the attribute doesn't exist, we'll create it
92
+ if (foundAttribute && attributesSame(foundAttribute, attribute) && updateEnabled) {
93
+ finalAttribute = {
94
+ ...attribute,
95
+ ...foundAttribute,
96
+ };
97
+ action = "update";
98
+ } else if (foundAttribute && !attributesSame(foundAttribute, attribute) && updateEnabled) {
99
+ console.log(
100
+ `Updating attribute with same key ${attribute.key} but different values`
101
+ );
63
102
  finalAttribute = attribute;
64
- action = "create";
65
- } else if (!updateEnabled) {
66
- // If updates are not enabled and the attribute exists, we do nothing
103
+ action = "update";
104
+ } else if (!updateEnabled && foundAttribute && !attributesSame(foundAttribute, attribute)) {
105
+ await db.deleteAttribute(dbId, collection.$id, attribute.key);
106
+ console.log(`Deleted attribute: ${attribute.key} to recreate it because they diff (update disabled temporarily)`);
67
107
  return;
68
108
  }
69
109
 
110
+ // console.log(`${action}-ing attribute: ${finalAttribute.key}`);
111
+
70
112
  // Relationship attribute logic with adjustments
71
113
  let collectionFoundViaRelatedCollection: Models.Collection | undefined;
72
114
  let relatedCollectionId: string | undefined;
@@ -122,9 +164,9 @@ export const createOrUpdateAttribute = async (
122
164
  collection.$id,
123
165
  finalAttribute.key,
124
166
  finalAttribute.size,
125
- finalAttribute.required,
126
- finalAttribute.xdefault,
127
- finalAttribute.array,
167
+ finalAttribute.required || false,
168
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null),
169
+ finalAttribute.array || false,
128
170
  finalAttribute.encrypted
129
171
  )
130
172
  );
@@ -135,8 +177,8 @@ export const createOrUpdateAttribute = async (
135
177
  dbId,
136
178
  collection.$id,
137
179
  finalAttribute.key,
138
- finalAttribute.required,
139
- finalAttribute.xdefault,
180
+ finalAttribute.required || false,
181
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : ""),
140
182
  finalAttribute.size
141
183
  )
142
184
  );
@@ -162,11 +204,11 @@ export const createOrUpdateAttribute = async (
162
204
  dbId,
163
205
  collection.$id,
164
206
  finalAttribute.key,
165
- finalAttribute.required,
166
- finalAttribute.min,
167
- finalAttribute.max,
168
- finalAttribute.xdefault,
169
- finalAttribute.array
207
+ finalAttribute.required || false,
208
+ finalAttribute.min || -2147483647,
209
+ finalAttribute.max || 2147483647,
210
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : ""),
211
+ finalAttribute.array || false
170
212
  )
171
213
  );
172
214
  } else {
@@ -188,10 +230,10 @@ export const createOrUpdateAttribute = async (
188
230
  dbId,
189
231
  collection.$id,
190
232
  finalAttribute.key,
191
- finalAttribute.required,
192
- finalAttribute.min,
193
- finalAttribute.max,
194
- finalAttribute.xdefault
233
+ finalAttribute.required || false,
234
+ finalAttribute.min || -2147483647,
235
+ finalAttribute.max || 2147483647,
236
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null)
195
237
  )
196
238
  );
197
239
  }
@@ -204,11 +246,11 @@ export const createOrUpdateAttribute = async (
204
246
  dbId,
205
247
  collection.$id,
206
248
  finalAttribute.key,
207
- finalAttribute.required,
208
- finalAttribute.min,
209
- finalAttribute.max,
210
- finalAttribute.xdefault,
211
- finalAttribute.array
249
+ finalAttribute.required || false,
250
+ finalAttribute.min || -2147483647,
251
+ finalAttribute.max || 2147483647,
252
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null),
253
+ finalAttribute.array || false
212
254
  )
213
255
  );
214
256
  } else {
@@ -218,10 +260,10 @@ export const createOrUpdateAttribute = async (
218
260
  dbId,
219
261
  collection.$id,
220
262
  finalAttribute.key,
221
- finalAttribute.required,
222
- finalAttribute.min,
223
- finalAttribute.max,
224
- finalAttribute.xdefault
263
+ finalAttribute.required || false,
264
+ finalAttribute.min || -2147483647,
265
+ finalAttribute.max || 2147483647,
266
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null)
225
267
  )
226
268
  );
227
269
  }
@@ -234,9 +276,9 @@ export const createOrUpdateAttribute = async (
234
276
  dbId,
235
277
  collection.$id,
236
278
  finalAttribute.key,
237
- finalAttribute.required,
238
- finalAttribute.xdefault,
239
- finalAttribute.array
279
+ finalAttribute.required || false,
280
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null),
281
+ finalAttribute.array || false
240
282
  )
241
283
  );
242
284
  } else {
@@ -246,8 +288,8 @@ export const createOrUpdateAttribute = async (
246
288
  dbId,
247
289
  collection.$id,
248
290
  finalAttribute.key,
249
- finalAttribute.required,
250
- finalAttribute.xdefault
291
+ finalAttribute.required || false,
292
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null)
251
293
  )
252
294
  );
253
295
  }
@@ -260,9 +302,9 @@ export const createOrUpdateAttribute = async (
260
302
  dbId,
261
303
  collection.$id,
262
304
  finalAttribute.key,
263
- finalAttribute.required,
264
- finalAttribute.xdefault,
265
- finalAttribute.array
305
+ finalAttribute.required || false,
306
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null),
307
+ finalAttribute.array || false
266
308
  )
267
309
  );
268
310
  } else {
@@ -272,8 +314,8 @@ export const createOrUpdateAttribute = async (
272
314
  dbId,
273
315
  collection.$id,
274
316
  finalAttribute.key,
275
- finalAttribute.required,
276
- finalAttribute.xdefault
317
+ finalAttribute.required || false,
318
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null)
277
319
  )
278
320
  );
279
321
  }
@@ -286,9 +328,9 @@ export const createOrUpdateAttribute = async (
286
328
  dbId,
287
329
  collection.$id,
288
330
  finalAttribute.key,
289
- finalAttribute.required,
290
- finalAttribute.xdefault,
291
- finalAttribute.array
331
+ finalAttribute.required || false,
332
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null),
333
+ finalAttribute.array || false
292
334
  )
293
335
  );
294
336
  } else {
@@ -298,8 +340,8 @@ export const createOrUpdateAttribute = async (
298
340
  dbId,
299
341
  collection.$id,
300
342
  finalAttribute.key,
301
- finalAttribute.required,
302
- finalAttribute.xdefault
343
+ finalAttribute.required || false,
344
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null)
303
345
  )
304
346
  );
305
347
  }
@@ -312,9 +354,9 @@ export const createOrUpdateAttribute = async (
312
354
  dbId,
313
355
  collection.$id,
314
356
  finalAttribute.key,
315
- finalAttribute.required,
316
- finalAttribute.xdefault,
317
- finalAttribute.array
357
+ finalAttribute.required || false,
358
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null),
359
+ finalAttribute.array || false
318
360
  )
319
361
  );
320
362
  } else {
@@ -324,8 +366,8 @@ export const createOrUpdateAttribute = async (
324
366
  dbId,
325
367
  collection.$id,
326
368
  finalAttribute.key,
327
- finalAttribute.required,
328
- finalAttribute.xdefault
369
+ finalAttribute.required || false,
370
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null)
329
371
  )
330
372
  );
331
373
  }
@@ -338,9 +380,9 @@ export const createOrUpdateAttribute = async (
338
380
  dbId,
339
381
  collection.$id,
340
382
  finalAttribute.key,
341
- finalAttribute.required,
342
- finalAttribute.xdefault,
343
- finalAttribute.array
383
+ finalAttribute.required || false,
384
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null),
385
+ finalAttribute.array || false
344
386
  )
345
387
  );
346
388
  } else {
@@ -350,8 +392,8 @@ export const createOrUpdateAttribute = async (
350
392
  dbId,
351
393
  collection.$id,
352
394
  finalAttribute.key,
353
- finalAttribute.required,
354
- finalAttribute.xdefault
395
+ finalAttribute.required || false,
396
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null)
355
397
  )
356
398
  );
357
399
  }
@@ -365,9 +407,9 @@ export const createOrUpdateAttribute = async (
365
407
  collection.$id,
366
408
  finalAttribute.key,
367
409
  finalAttribute.elements,
368
- finalAttribute.required,
369
- finalAttribute.xdefault,
370
- finalAttribute.array
410
+ finalAttribute.required || false,
411
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null),
412
+ finalAttribute.array || false
371
413
  )
372
414
  );
373
415
  } else {
@@ -378,8 +420,8 @@ export const createOrUpdateAttribute = async (
378
420
  collection.$id,
379
421
  finalAttribute.key,
380
422
  finalAttribute.elements,
381
- finalAttribute.required,
382
- finalAttribute.xdefault
423
+ finalAttribute.required || false,
424
+ finalAttribute.xdefault || (finalAttribute.required ? undefined : null)
383
425
  )
384
426
  );
385
427
  }