appwrite-utils-cli 0.10.82 → 0.10.83
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 +1 -0
- package/dist/collections/attributes.js +86 -41
- package/dist/collections/methods.d.ts +6 -0
- package/dist/collections/methods.js +136 -1
- package/dist/migrations/appwriteToX.js +1 -1
- package/dist/migrations/attributes.js +0 -1
- package/dist/migrations/converters.js +3 -4
- package/dist/migrations/dataLoader.js +3 -3
- package/dist/migrations/importController.js +0 -1
- package/dist/migrations/queue.js +1 -2
- package/dist/migrations/relationships.js +1 -1
- package/dist/migrations/users.js +5 -4
- package/dist/migrations/validationRules.js +30 -30
- package/package.json +1 -1
- package/src/collections/attributes.ts +126 -50
- package/src/collections/methods.ts +221 -1
- package/src/migrations/appwriteToX.ts +4 -4
- package/src/migrations/attributes.ts +0 -1
- package/src/migrations/converters.ts +3 -5
- package/src/migrations/dataLoader.ts +4 -4
- package/src/migrations/importController.ts +0 -1
- package/src/migrations/queue.ts +1 -2
- package/src/migrations/relationships.ts +1 -1
- package/src/migrations/users.ts +8 -7
- package/src/migrations/validationRules.ts +56 -31
- package/src/migrations/collections.ts +0 -545
@@ -16,14 +16,14 @@ import path from "path";
|
|
16
16
|
import fs from "fs";
|
17
17
|
import { convertObjectByAttributeMappings } from "./converters.js";
|
18
18
|
import { z } from "zod";
|
19
|
-
import { checkForCollection } from "
|
19
|
+
import { checkForCollection } from "../collections/methods.js";
|
20
20
|
import { ID, Users, type Databases } from "node-appwrite";
|
21
21
|
import { logger } from "./logging.js";
|
22
22
|
import { findOrCreateOperation, updateOperation } from "./migrationHelper.js";
|
23
23
|
import { AuthUserCreateSchema } from "../schemas/authUser.js";
|
24
|
-
import _ from "lodash";
|
25
24
|
import { UsersController } from "./users.js";
|
26
25
|
import { finalizeByAttributeMap } from "../utils/helperFunctions.js";
|
26
|
+
import { isEmpty } from "es-toolkit/compat";
|
27
27
|
|
28
28
|
// Define a schema for the structure of collection import data using Zod for validation
|
29
29
|
export const CollectionImportDataSchema = z.object({
|
@@ -315,7 +315,7 @@ export class DataLoader {
|
|
315
315
|
// Find or create an import operation for the collection
|
316
316
|
const collectionImportOperation = await findOrCreateOperation(
|
317
317
|
this.database,
|
318
|
-
collection.$id
|
318
|
+
collection.$id!,
|
319
319
|
"importData"
|
320
320
|
);
|
321
321
|
// Store the operation ID in the map
|
@@ -556,7 +556,7 @@ export class DataLoader {
|
|
556
556
|
// Skip if value to match is missing or empty
|
557
557
|
if (
|
558
558
|
!sourceValue ||
|
559
|
-
|
559
|
+
isEmpty(sourceValue) ||
|
560
560
|
sourceValue === null
|
561
561
|
)
|
562
562
|
continue;
|
@@ -13,7 +13,6 @@ import type {
|
|
13
13
|
AttributeMappings,
|
14
14
|
} from "appwrite-utils";
|
15
15
|
import type { ImportDataActions } from "./importDataActions.js";
|
16
|
-
import _ from "lodash";
|
17
16
|
import { areCollectionNamesSame, tryAwaitWithRetry } from "../utils/index.js";
|
18
17
|
import type { SetupOptions } from "../utilsController.js";
|
19
18
|
import { resolveAndUpdateRelationships } from "./relationships.js";
|
package/src/migrations/queue.ts
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
import { Query, type Databases, type Models } from "node-appwrite";
|
2
2
|
import type { Attribute } from "appwrite-utils";
|
3
3
|
import { createOrUpdateAttribute } from "./attributes.js";
|
4
|
-
import
|
5
|
-
import { fetchAndCacheCollectionByName } from "./collections.js";
|
4
|
+
import { fetchAndCacheCollectionByName } from "../collections/methods.js";
|
6
5
|
import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
7
6
|
|
8
7
|
export interface QueuedOperation {
|
package/src/migrations/users.ts
CHANGED
@@ -12,13 +12,14 @@ import {
|
|
12
12
|
type AuthUser,
|
13
13
|
type AuthUserCreate,
|
14
14
|
} from "../schemas/authUser.js";
|
15
|
-
import _ from "lodash";
|
16
15
|
import { logger } from "./logging.js";
|
17
16
|
import { splitIntoBatches } from "./migrationHelper.js";
|
18
17
|
import {
|
19
18
|
getAppwriteClient,
|
20
19
|
tryAwaitWithRetry,
|
21
20
|
} from "../utils/helperFunctions.js";
|
21
|
+
import { isUndefined } from "es-toolkit/compat";
|
22
|
+
import { isEmpty } from "es-toolkit/compat";
|
22
23
|
|
23
24
|
export class UsersController {
|
24
25
|
private config: AppwriteConfig;
|
@@ -123,17 +124,17 @@ export class UsersController {
|
|
123
124
|
`changeMe${item.email?.toLowerCase()}` || `changeMePlease`,
|
124
125
|
item.name || undefined
|
125
126
|
);
|
126
|
-
|
127
|
+
|
127
128
|
if (item.labels) {
|
128
129
|
await this.users.updateLabels(createdUser.$id, item.labels);
|
129
130
|
}
|
130
131
|
if (item.prefs) {
|
131
132
|
await this.users.updatePrefs(createdUser.$id, item.prefs);
|
132
133
|
}
|
133
|
-
|
134
|
+
|
134
135
|
return createdUser;
|
135
136
|
}); // Set throwError to true since we want to handle errors
|
136
|
-
|
137
|
+
|
137
138
|
return user;
|
138
139
|
} catch (e) {
|
139
140
|
if (e instanceof Error) {
|
@@ -181,8 +182,8 @@ export class UsersController {
|
|
181
182
|
if (
|
182
183
|
item.email &&
|
183
184
|
item.email !== userToReturn.email &&
|
184
|
-
!
|
185
|
-
!
|
185
|
+
!isEmpty(item.email) &&
|
186
|
+
!isUndefined(item.email)
|
186
187
|
) {
|
187
188
|
const emailExists = await this.users.list([
|
188
189
|
Query.equal("email", item.email),
|
@@ -213,7 +214,7 @@ export class UsersController {
|
|
213
214
|
item.phone !== userToReturn.phone &&
|
214
215
|
item.phone.length < 15 &&
|
215
216
|
item.phone.startsWith("+") &&
|
216
|
-
(
|
217
|
+
(isUndefined(userToReturn.phone) || isEmpty(userToReturn.phone))
|
217
218
|
) {
|
218
219
|
const userFoundWithPhone = await this.users.list([
|
219
220
|
Query.equal("phone", item.phone),
|
@@ -1,17 +1,42 @@
|
|
1
|
-
import
|
2
|
-
|
1
|
+
import {
|
2
|
+
isNumber,
|
3
|
+
isString,
|
4
|
+
isBoolean,
|
5
|
+
isArray,
|
6
|
+
isPlainObject,
|
7
|
+
isNull,
|
8
|
+
isUndefined,
|
9
|
+
isDate,
|
10
|
+
isEmpty,
|
11
|
+
isInteger,
|
12
|
+
isArrayLike,
|
13
|
+
isArrayLikeObject,
|
14
|
+
isFunction,
|
15
|
+
isLength,
|
16
|
+
isMap,
|
17
|
+
isSet,
|
18
|
+
isRegExp,
|
19
|
+
isSymbol,
|
20
|
+
isObjectLike,
|
21
|
+
isSafeInteger,
|
22
|
+
isTypedArray,
|
23
|
+
isEqual,
|
24
|
+
isMatch,
|
25
|
+
has,
|
26
|
+
get,
|
27
|
+
} from "es-toolkit/compat";
|
3
28
|
export interface ValidationRules {
|
4
29
|
[key: string]: (value: any, ...args: any[]) => boolean;
|
5
30
|
}
|
6
31
|
|
7
32
|
export const validationRules = {
|
8
|
-
isNumber: (value: any): boolean =>
|
9
|
-
isString: (value: any): boolean =>
|
10
|
-
isBoolean: (value: any): boolean =>
|
11
|
-
isArray: (value: any): boolean =>
|
33
|
+
isNumber: (value: any): boolean => isNumber(value),
|
34
|
+
isString: (value: any): boolean => isString(value),
|
35
|
+
isBoolean: (value: any): boolean => isBoolean(value),
|
36
|
+
isArray: (value: any): boolean => isArray(value),
|
12
37
|
isObject: (value: any): boolean =>
|
13
|
-
|
14
|
-
isNull: (value: any): boolean =>
|
38
|
+
isPlainObject(value) && !isArray(value) && !isFunction(value),
|
39
|
+
isNull: (value: any): boolean => isNull(value),
|
15
40
|
isValidEmail: (value: string): boolean =>
|
16
41
|
value.match(/^[\w\-\.]+@([\w-]+\.)+[\w-]{2,}$/) !== null,
|
17
42
|
isValidPhone: (value: string): boolean =>
|
@@ -35,29 +60,29 @@ export const validationRules = {
|
|
35
60
|
value.match(/^\d{4}-\d{2}-\d{2}$/) !== null,
|
36
61
|
isValidTime: (value: string): boolean =>
|
37
62
|
value.match(/^\d{2}:\d{2}(:\d{2})?$/) !== null,
|
38
|
-
isNullish: (value: any): boolean =>
|
39
|
-
isUndefined: (value: any): boolean =>
|
63
|
+
isNullish: (value: any): boolean => isNull(value) || isUndefined(value),
|
64
|
+
isUndefined: (value: any): boolean => isUndefined(value),
|
40
65
|
isDefined: (value: any): boolean =>
|
41
|
-
!
|
42
|
-
isDate: (value: any): boolean =>
|
43
|
-
isEmpty: (value: any): boolean =>
|
44
|
-
isInteger: (value: any): boolean =>
|
45
|
-
isFloat: (value: any): boolean =>
|
46
|
-
isArrayLike: (value: any): boolean =>
|
47
|
-
isArrayLikeObject: (value: any): boolean =>
|
48
|
-
isFunction: (value: any): boolean =>
|
49
|
-
isLength: (value: any): boolean =>
|
50
|
-
isMap: (value: any): boolean =>
|
51
|
-
isSet: (value: any): boolean =>
|
52
|
-
isRegExp: (value: any): boolean =>
|
53
|
-
isSymbol: (value: any): boolean =>
|
54
|
-
isObjectLike: (value: any): boolean =>
|
55
|
-
isPlainObject: (value: any): boolean =>
|
56
|
-
isSafeInteger: (value: any): boolean =>
|
57
|
-
isTypedArray: (value: any): boolean =>
|
58
|
-
isEqual: (value: any, other: any): boolean =>
|
59
|
-
isMatch: (object: any, source: any): boolean =>
|
60
|
-
has: (object: any, path: string): boolean =>
|
66
|
+
!isUndefined(value) && !isNull(value) && !isEmpty(value),
|
67
|
+
isDate: (value: any): boolean => isDate(value),
|
68
|
+
isEmpty: (value: any): boolean => isEmpty(value),
|
69
|
+
isInteger: (value: any): boolean => isInteger(value),
|
70
|
+
isFloat: (value: any): boolean => isNumber(value) && !isInteger(value),
|
71
|
+
isArrayLike: (value: any): boolean => isArrayLike(value),
|
72
|
+
isArrayLikeObject: (value: any): boolean => isArrayLikeObject(value),
|
73
|
+
isFunction: (value: any): boolean => isFunction(value),
|
74
|
+
isLength: (value: any): boolean => isLength(value),
|
75
|
+
isMap: (value: any): boolean => isMap(value),
|
76
|
+
isSet: (value: any): boolean => isSet(value),
|
77
|
+
isRegExp: (value: any): boolean => isRegExp(value),
|
78
|
+
isSymbol: (value: any): boolean => isSymbol(value),
|
79
|
+
isObjectLike: (value: any): boolean => isObjectLike(value),
|
80
|
+
isPlainObject: (value: any): boolean => isPlainObject(value),
|
81
|
+
isSafeInteger: (value: any): boolean => isSafeInteger(value),
|
82
|
+
isTypedArray: (value: any): boolean => isTypedArray(value),
|
83
|
+
isEqual: (value: any, other: any): boolean => isEqual(value, other),
|
84
|
+
isMatch: (object: any, source: any): boolean => isMatch(object, source),
|
85
|
+
has: (object: any, path: string): boolean => has(object, path),
|
61
86
|
get: (object: any, path: string, defaultValue: any): any =>
|
62
|
-
|
87
|
+
get(object, path, defaultValue),
|
63
88
|
};
|