@lenne.tech/nest-server 10.8.10 → 11.0.0
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/dist/core/common/args/filter.args.js +2 -2
- package/dist/core/common/args/filter.args.js.map +1 -1
- package/dist/core/common/args/pagination.args.js +5 -5
- package/dist/core/common/args/pagination.args.js.map +1 -1
- package/dist/core/common/helpers/config.helper.d.ts +1 -1
- package/dist/core/common/helpers/config.helper.js +8 -8
- package/dist/core/common/helpers/config.helper.js.map +1 -1
- package/dist/core/common/helpers/db.helper.d.ts +11 -11
- package/dist/core/common/helpers/db.helper.js +100 -100
- package/dist/core/common/helpers/db.helper.js.map +1 -1
- package/dist/core/common/helpers/file.helper.d.ts +1 -1
- package/dist/core/common/helpers/file.helper.js +10 -10
- package/dist/core/common/helpers/file.helper.js.map +1 -1
- package/dist/core/common/helpers/filter.helper.d.ts +12 -12
- package/dist/core/common/helpers/filter.helper.js +19 -19
- package/dist/core/common/helpers/filter.helper.js.map +1 -1
- package/dist/core/common/helpers/graphql.helper.d.ts +8 -8
- package/dist/core/common/helpers/graphql.helper.js +75 -75
- package/dist/core/common/helpers/graphql.helper.js.map +1 -1
- package/dist/core/common/helpers/input.helper.d.ts +7 -7
- package/dist/core/common/helpers/input.helper.js +60 -60
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/common/helpers/model.helper.d.ts +8 -8
- package/dist/core/common/helpers/model.helper.js +38 -38
- package/dist/core/common/helpers/model.helper.js.map +1 -1
- package/dist/core/common/helpers/service.helper.d.ts +2 -2
- package/dist/core/common/helpers/table.helper.d.ts +1 -1
- package/dist/core/common/inputs/combined-filter.input.js +6 -6
- package/dist/core/common/inputs/combined-filter.input.js.map +1 -1
- package/dist/core/common/inputs/filter.input.js +6 -6
- package/dist/core/common/inputs/filter.input.js.map +1 -1
- package/dist/core/common/inputs/single-filter.input.js +10 -10
- package/dist/core/common/inputs/single-filter.input.js.map +1 -1
- package/dist/core/common/inputs/sort.input.js +4 -4
- package/dist/core/common/inputs/sort.input.js.map +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +8 -8
- package/dist/core/common/models/core-persistence.model.js +8 -8
- package/dist/core/common/models/core-persistence.model.js.map +1 -1
- package/dist/core/common/plugins/mongoose-id.plugin.d.ts +1 -1
- package/dist/core/common/plugins/mongoose-id.plugin.js +2 -2
- package/dist/core/common/plugins/mongoose-id.plugin.js.map +1 -1
- package/dist/core/common/scalars/any.scalar.js +8 -8
- package/dist/core/common/scalars/any.scalar.js.map +1 -1
- package/dist/core/common/scalars/date-timestamp.scalar.js +1 -1
- package/dist/core/common/scalars/date-timestamp.scalar.js.map +1 -1
- package/dist/core/common/scalars/date.scalar.js +1 -1
- package/dist/core/common/scalars/date.scalar.js.map +1 -1
- package/dist/core/common/scalars/json.scalar.js +8 -8
- package/dist/core/common/scalars/json.scalar.js.map +1 -1
- package/dist/core/common/services/config.service.d.ts +26 -26
- package/dist/core/common/services/crud.service.d.ts +32 -32
- package/dist/core/common/services/mailjet.service.js +1 -1
- package/dist/core/common/services/mailjet.service.js.map +1 -1
- package/dist/core/common/services/module.service.d.ts +1 -1
- package/dist/core/common/services/module.service.js.map +1 -1
- package/dist/core/common/types/falsy.type.d.ts +1 -1
- package/dist/core/common/types/id.type.d.ts +4 -4
- package/dist/core/common/types/require-only-one.type.d.ts +2 -2
- package/dist/core/common/types/required-at-least-one.type.d.ts +2 -2
- package/dist/core/common/types/string-or-object-id.type.d.ts +1 -1
- package/dist/core/modules/auth/core-auth.controller.js +6 -6
- package/dist/core/modules/auth/core-auth.controller.js.map +1 -1
- package/dist/core/modules/auth/core-auth.model.js +2 -2
- package/dist/core/modules/auth/core-auth.model.js.map +1 -1
- package/dist/core/modules/auth/core-auth.module.d.ts +4 -4
- package/dist/core/modules/auth/core-auth.module.js +2 -2
- package/dist/core/modules/auth/core-auth.module.js.map +1 -1
- package/dist/core/modules/auth/core-auth.resolver.js +6 -6
- package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
- package/dist/core/modules/auth/guards/auth.guard.d.ts +2 -2
- package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
- package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js +2 -2
- package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js.map +1 -1
- package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js +2 -2
- package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js.map +1 -1
- package/dist/core/modules/auth/services/core-auth.service.d.ts +2 -2
- package/dist/core/modules/auth/services/core-auth.service.js +3 -0
- package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
- package/dist/core/modules/auth/strategies/jwt-refresh.strategy.d.ts +1 -1
- package/dist/core/modules/auth/strategies/jwt.strategy.d.ts +1 -1
- package/dist/core/modules/file/core-file-info.model.js +8 -8
- package/dist/core/modules/file/core-file-info.model.js.map +1 -1
- package/dist/core/modules/file/core-file.controller.js +2 -2
- package/dist/core/modules/file/core-file.controller.js.map +1 -1
- package/dist/core/modules/file/core-file.resolver.js +6 -6
- package/dist/core/modules/file/core-file.resolver.js.map +1 -1
- package/dist/core/modules/file/core-file.service.d.ts +6 -6
- package/dist/core/modules/health-check/core-health-check-result.model.js +9 -9
- package/dist/core/modules/health-check/core-health-check-result.model.js.map +1 -1
- package/dist/core/modules/health-check/core-health-check.controller.js +2 -2
- package/dist/core/modules/health-check/core-health-check.controller.js.map +1 -1
- package/dist/core/modules/health-check/core-health-check.resolver.js +2 -2
- package/dist/core/modules/health-check/core-health-check.resolver.js.map +1 -1
- package/dist/core/modules/user/core-user.model.js +11 -11
- package/dist/core/modules/user/core-user.model.js.map +1 -1
- package/dist/core/modules/user/core-user.service.d.ts +2 -2
- package/dist/core/modules/user/inputs/core-user-create.input.js +3 -3
- package/dist/core/modules/user/inputs/core-user-create.input.js.map +1 -1
- package/dist/core/modules/user/inputs/core-user.input.js +10 -10
- package/dist/core/modules/user/inputs/core-user.input.js.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/server/common/models/persistence.model.d.ts +2 -2
- package/dist/server/common/models/persistence.model.js +6 -6
- package/dist/server/common/models/persistence.model.js.map +1 -1
- package/dist/server/modules/auth/auth.controller.js +1 -1
- package/dist/server/modules/auth/auth.controller.js.map +1 -1
- package/dist/server/modules/auth/auth.model.js +3 -3
- package/dist/server/modules/auth/auth.model.js.map +1 -1
- package/dist/server/modules/auth/auth.resolver.js +3 -3
- package/dist/server/modules/auth/auth.resolver.js.map +1 -1
- package/dist/server/modules/auth/inputs/auth-sign-in.input.js +2 -2
- package/dist/server/modules/auth/inputs/auth-sign-in.input.js.map +1 -1
- package/dist/server/modules/auth/inputs/auth-sign-up.input.js +4 -4
- package/dist/server/modules/auth/inputs/auth-sign-up.input.js.map +1 -1
- package/dist/server/modules/file/file-info.model.js +2 -2
- package/dist/server/modules/file/file-info.model.js.map +1 -1
- package/dist/server/modules/file/file.controller.js +5 -5
- package/dist/server/modules/file/file.controller.js.map +1 -1
- package/dist/server/modules/file/file.resolver.js +5 -5
- package/dist/server/modules/file/file.resolver.js.map +1 -1
- package/dist/server/modules/user/avatar.controller.js +2 -2
- package/dist/server/modules/user/avatar.controller.js.map +1 -1
- package/dist/server/modules/user/inputs/user-create.input.js +2 -2
- package/dist/server/modules/user/inputs/user-create.input.js.map +1 -1
- package/dist/server/modules/user/inputs/user.input.js +2 -2
- package/dist/server/modules/user/inputs/user.input.js.map +1 -1
- package/dist/server/modules/user/outputs/find-and-count-users-result.output.js +4 -4
- package/dist/server/modules/user/outputs/find-and-count-users-result.output.js.map +1 -1
- package/dist/server/modules/user/user.model.js +8 -8
- package/dist/server/modules/user/user.model.js.map +1 -1
- package/dist/server/modules/user/user.resolver.d.ts +1 -1
- package/dist/server/modules/user/user.resolver.js +11 -11
- package/dist/server/modules/user/user.resolver.js.map +1 -1
- package/dist/server/modules/user/user.service.d.ts +1 -1
- package/dist/server/server.controller.js +2 -2
- package/dist/server/server.controller.js.map +1 -1
- package/dist/test/test.helper.d.ts +14 -14
- package/dist/test/test.helper.js +0 -1
- package/dist/test/test.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +44 -41
- package/src/core/common/args/filter.args.ts +2 -2
- package/src/core/common/args/pagination.args.ts +5 -5
- package/src/core/common/decorators/graphql-service-options.decorator.ts +1 -1
- package/src/core/common/decorators/graphql-user.decorator.ts +1 -1
- package/src/core/common/decorators/rest-user.decorator.ts +1 -1
- package/src/core/common/helpers/config.helper.ts +22 -21
- package/src/core/common/helpers/db.helper.ts +164 -164
- package/src/core/common/helpers/file.helper.ts +18 -18
- package/src/core/common/helpers/filter.helper.ts +35 -35
- package/src/core/common/helpers/graphql.helper.ts +100 -100
- package/src/core/common/helpers/input.helper.ts +89 -89
- package/src/core/common/helpers/model.helper.ts +70 -70
- package/src/core/common/helpers/service.helper.ts +3 -3
- package/src/core/common/helpers/table.helper.ts +1 -1
- package/src/core/common/inputs/combined-filter.input.ts +5 -5
- package/src/core/common/inputs/filter.input.ts +5 -5
- package/src/core/common/inputs/single-filter.input.ts +9 -9
- package/src/core/common/inputs/sort.input.ts +3 -3
- package/src/core/common/interfaces/server-options.interface.ts +9 -9
- package/src/core/common/models/core-persistence.model.ts +8 -8
- package/src/core/common/plugins/mongoose-id.plugin.js +2 -2
- package/src/core/common/scalars/any.scalar.ts +8 -8
- package/src/core/common/scalars/date-timestamp.scalar.ts +1 -1
- package/src/core/common/scalars/date.scalar.ts +1 -1
- package/src/core/common/scalars/json.scalar.ts +8 -8
- package/src/core/common/services/config.service.ts +7 -7
- package/src/core/common/services/crud.service.ts +19 -19
- package/src/core/common/services/mailjet.service.ts +1 -1
- package/src/core/common/services/module.service.ts +4 -4
- package/src/core/common/types/falsy.type.ts +1 -1
- package/src/core/common/types/id.type.ts +1 -1
- package/src/core/common/types/require-only-one.type.ts +3 -3
- package/src/core/common/types/required-at-least-one.type.ts +3 -3
- package/src/core/common/types/string-or-object-id.type.ts +1 -1
- package/src/core/modules/auth/core-auth.controller.ts +6 -6
- package/src/core/modules/auth/core-auth.model.ts +1 -1
- package/src/core/modules/auth/core-auth.module.ts +4 -4
- package/src/core/modules/auth/core-auth.resolver.ts +6 -6
- package/src/core/modules/auth/guards/auth.guard.ts +5 -5
- package/src/core/modules/auth/inputs/core-auth-sign-in.input.ts +1 -1
- package/src/core/modules/auth/inputs/core-auth-sign-up.input.ts +1 -1
- package/src/core/modules/auth/services/core-auth.service.ts +6 -1
- package/src/core/modules/auth/tokens.decorator.ts +2 -2
- package/src/core/modules/file/core-file-info.model.ts +7 -7
- package/src/core/modules/file/core-file.controller.ts +2 -2
- package/src/core/modules/file/core-file.resolver.ts +6 -6
- package/src/core/modules/file/core-file.service.ts +6 -6
- package/src/core/modules/health-check/core-health-check-result.model.ts +8 -8
- package/src/core/modules/health-check/core-health-check.controller.ts +2 -2
- package/src/core/modules/health-check/core-health-check.resolver.ts +2 -2
- package/src/core/modules/user/core-user.model.ts +11 -11
- package/src/core/modules/user/core-user.service.ts +2 -2
- package/src/core/modules/user/inputs/core-user-create.input.ts +2 -2
- package/src/core/modules/user/inputs/core-user.input.ts +9 -9
- package/src/index.ts +9 -9
- package/src/server/common/models/persistence.model.ts +8 -8
- package/src/server/modules/auth/auth.controller.ts +1 -1
- package/src/server/modules/auth/auth.model.ts +2 -2
- package/src/server/modules/auth/auth.resolver.ts +3 -3
- package/src/server/modules/auth/inputs/auth-sign-in.input.ts +1 -1
- package/src/server/modules/auth/inputs/auth-sign-up.input.ts +3 -3
- package/src/server/modules/file/file-info.model.ts +2 -2
- package/src/server/modules/file/file.controller.ts +5 -5
- package/src/server/modules/file/file.module.ts +1 -1
- package/src/server/modules/file/file.resolver.ts +5 -5
- package/src/server/modules/user/avatar.controller.ts +2 -2
- package/src/server/modules/user/inputs/user-create.input.ts +1 -1
- package/src/server/modules/user/inputs/user.input.ts +1 -1
- package/src/server/modules/user/outputs/find-and-count-users-result.output.ts +3 -3
- package/src/server/modules/user/user.model.ts +8 -8
- package/src/server/modules/user/user.resolver.ts +11 -11
- package/src/server/modules/user/user.service.ts +1 -1
- package/src/server/server.controller.ts +2 -2
- package/src/test/test.helper.ts +14 -15
|
@@ -34,24 +34,6 @@ export default class FileHelper {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
* Get function to generate a random file name for multer with a certain
|
|
39
|
-
* number of digits
|
|
40
|
-
*/
|
|
41
|
-
export function multerRandomFileName(numberOfDigits = 32) {
|
|
42
|
-
return (req, file, cb) => {
|
|
43
|
-
// Generating a random string
|
|
44
|
-
const randomName = Array(numberOfDigits)
|
|
45
|
-
.fill(null)
|
|
46
|
-
.map(() => Math.round(Math.random() * 16).toString(16))
|
|
47
|
-
.join('');
|
|
48
|
-
|
|
49
|
-
// Calling the callback passing the random name generated with the
|
|
50
|
-
// original extension name
|
|
51
|
-
cb(null, `${randomName}${extname(file.originalname)}`);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
37
|
/**
|
|
56
38
|
* Get function to filter files for multer with a certain mimetype & extname
|
|
57
39
|
*/
|
|
@@ -105,3 +87,21 @@ export function multerOptionsForImageUpload(options: {
|
|
|
105
87
|
}),
|
|
106
88
|
};
|
|
107
89
|
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get function to generate a random file name for multer with a certain
|
|
93
|
+
* number of digits
|
|
94
|
+
*/
|
|
95
|
+
export function multerRandomFileName(numberOfDigits = 32) {
|
|
96
|
+
return (req, file, cb) => {
|
|
97
|
+
// Generating a random string
|
|
98
|
+
const randomName = Array(numberOfDigits)
|
|
99
|
+
.fill(null)
|
|
100
|
+
.map(() => Math.round(Math.random() * 16).toString(16))
|
|
101
|
+
.join('');
|
|
102
|
+
|
|
103
|
+
// Calling the callback passing the random name generated with the
|
|
104
|
+
// original extension name
|
|
105
|
+
cb(null, `${randomName}${extname(file.originalname)}`);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -26,7 +26,7 @@ export class Filter {
|
|
|
26
26
|
/**
|
|
27
27
|
* Generate filter query
|
|
28
28
|
*/
|
|
29
|
-
public static generateFilterQuery<T = any>(filter?: Partial<FilterInput>): FilterQuery<T>
|
|
29
|
+
public static generateFilterQuery<T = any>(filter?: Partial<FilterInput>): any | FilterQuery<T> {
|
|
30
30
|
return generateFilterQuery(filter);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -38,6 +38,39 @@ export class Filter {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Convert filter arguments to a query array
|
|
43
|
+
*/
|
|
44
|
+
export function convertFilterArgsToQuery<T = any>(filterArgs: Partial<FilterArgs>): [FilterQuery<T>, QueryOptions] {
|
|
45
|
+
return [generateFilterQuery(filterArgs?.filter), generateFindOptions(filterArgs)];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Merge FilterArgs and FilterQueries
|
|
50
|
+
*/
|
|
51
|
+
export function filterMerge<T = unknown>(
|
|
52
|
+
filterArgs: Partial<FilterArgs>,
|
|
53
|
+
filterQuery: Partial<FilterQuery<T>>,
|
|
54
|
+
options?: {
|
|
55
|
+
operator?: '$and' | '$nor' | '$or';
|
|
56
|
+
queryOptions?: Partial<QueryOptions>;
|
|
57
|
+
samples?: number;
|
|
58
|
+
},
|
|
59
|
+
): { filterQuery: FilterQuery<T>; queryOptions?: QueryOptions; samples?: number } {
|
|
60
|
+
const config = {
|
|
61
|
+
operator: '$and',
|
|
62
|
+
...options,
|
|
63
|
+
};
|
|
64
|
+
const converted = convertFilterArgsToQuery(filterArgs);
|
|
65
|
+
return {
|
|
66
|
+
filterQuery: (converted[0]
|
|
67
|
+
? { [config.operator]: [converted[0], filterQuery || {}] }
|
|
68
|
+
: filterQuery) as FilterQuery<T>,
|
|
69
|
+
queryOptions: converted[1] || config.queryOptions ? { ...converted[1], ...config.queryOptions } : undefined,
|
|
70
|
+
samples: config.samples,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
41
74
|
/**
|
|
42
75
|
* Helper function to create $and, $or or $nor filter
|
|
43
76
|
*/
|
|
@@ -104,20 +137,13 @@ export function findFilter(options?: {
|
|
|
104
137
|
return filterOptions;
|
|
105
138
|
}
|
|
106
139
|
|
|
107
|
-
/**
|
|
108
|
-
* Convert filter arguments to a query array
|
|
109
|
-
*/
|
|
110
|
-
export function convertFilterArgsToQuery<T = any>(filterArgs: Partial<FilterArgs>): [FilterQuery<T>, QueryOptions] {
|
|
111
|
-
return [generateFilterQuery(filterArgs?.filter), generateFindOptions(filterArgs)];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
140
|
/**
|
|
115
141
|
* Generate filter query
|
|
116
142
|
*/
|
|
117
143
|
export function generateFilterQuery<T = any>(
|
|
118
144
|
filter?: Partial<FilterInput>,
|
|
119
145
|
options?: { automaticObjectIdFiltering?: boolean },
|
|
120
|
-
): FilterQuery<T>
|
|
146
|
+
): any | FilterQuery<T> {
|
|
121
147
|
// Check filter
|
|
122
148
|
if (!filter) {
|
|
123
149
|
return undefined;
|
|
@@ -263,29 +289,3 @@ export function generateFindOptions(filterArgs: Partial<FilterArgs>, options?: {
|
|
|
263
289
|
|
|
264
290
|
return queryOptions;
|
|
265
291
|
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Merge FilterArgs and FilterQueries
|
|
269
|
-
*/
|
|
270
|
-
export function filterMerge<T = unknown>(
|
|
271
|
-
filterArgs: Partial<FilterArgs>,
|
|
272
|
-
filterQuery: Partial<FilterQuery<T>>,
|
|
273
|
-
options?: {
|
|
274
|
-
operator?: '$and' | '$nor' | '$or';
|
|
275
|
-
queryOptions?: Partial<QueryOptions>;
|
|
276
|
-
samples?: number;
|
|
277
|
-
},
|
|
278
|
-
): { filterQuery: FilterQuery<T>; queryOptions?: QueryOptions; samples?: number } {
|
|
279
|
-
const config = {
|
|
280
|
-
operator: '$and',
|
|
281
|
-
...options,
|
|
282
|
-
};
|
|
283
|
-
const converted = convertFilterArgsToQuery(filterArgs);
|
|
284
|
-
return {
|
|
285
|
-
filterQuery: (converted[0]
|
|
286
|
-
? { [config.operator]: [converted[0], filterQuery || {}] }
|
|
287
|
-
: filterQuery) as FilterQuery<T>,
|
|
288
|
-
queryOptions: converted[1] || config.queryOptions ? { ...converted[1], ...config.queryOptions } : undefined,
|
|
289
|
-
samples: config.samples,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
@@ -139,48 +139,59 @@ export default class GraphQLHelper {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
|
-
*
|
|
143
|
-
* @param ast
|
|
142
|
+
* Create flatten AST from FieldNode for GraphQLResolveInfo
|
|
144
143
|
*/
|
|
145
|
-
export function
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
export function flattenAST(
|
|
145
|
+
ast: FieldNode,
|
|
146
|
+
info: GraphQLResolveInfo,
|
|
147
|
+
obj: any = {},
|
|
148
|
+
config: Partial<GraphQLFieldsConfig> = {},
|
|
149
|
+
) {
|
|
150
|
+
// Process configuration
|
|
151
|
+
config = Object.assign(
|
|
152
|
+
{
|
|
153
|
+
excludedFields: [],
|
|
154
|
+
processArguments: false,
|
|
155
|
+
},
|
|
156
|
+
config,
|
|
157
|
+
);
|
|
148
158
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
return getASTSelections(ast).reduce((flattened, a) => {
|
|
160
|
+
if (a.directives && a.directives.length) {
|
|
161
|
+
const { shouldInclude, shouldSkip } = getDirectiveResults(a, info);
|
|
162
|
+
// Field/fragment is not included if either the @skip condition is true or the @include condition is false
|
|
163
|
+
// https://facebook.github.io/graphql/draft/#sec--include
|
|
164
|
+
if (shouldSkip || !shouldInclude) {
|
|
165
|
+
return flattened;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
155
168
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return value.kind === 'ListValue';
|
|
162
|
-
}
|
|
169
|
+
if (isFieldNode(a)) {
|
|
170
|
+
const name = a.name.value;
|
|
171
|
+
if (config.excludedFields.indexOf(name) !== -1) {
|
|
172
|
+
return flattened;
|
|
173
|
+
}
|
|
163
174
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return ast.selectionSet.selections;
|
|
170
|
-
}
|
|
175
|
+
if (flattened[name] && flattened[name] !== '__arguments') {
|
|
176
|
+
Object.assign(flattened[name], flattenAST(a, info, flattened[name]));
|
|
177
|
+
} else {
|
|
178
|
+
flattened[name] = flattenAST(a, info);
|
|
179
|
+
}
|
|
171
180
|
|
|
172
|
-
|
|
173
|
-
|
|
181
|
+
if (config.processArguments) {
|
|
182
|
+
// check if the current field has arguments
|
|
183
|
+
if (a.arguments && a.arguments.length) {
|
|
184
|
+
Object.assign(flattened[name], {
|
|
185
|
+
__arguments: getArguments(a),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
flattened = flattenAST(getAST(a, info), info, flattened);
|
|
191
|
+
}
|
|
174
192
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
*/
|
|
178
|
-
export function getAST(ast, info) {
|
|
179
|
-
if (ast.kind === 'FragmentSpread') {
|
|
180
|
-
const fragmentName = ast.name.value;
|
|
181
|
-
return info.fragments[fragmentName];
|
|
182
|
-
}
|
|
183
|
-
return ast;
|
|
193
|
+
return flattened;
|
|
194
|
+
}, obj);
|
|
184
195
|
}
|
|
185
196
|
|
|
186
197
|
/**
|
|
@@ -203,18 +214,25 @@ export function getArguments(ast: FieldNode) {
|
|
|
203
214
|
}
|
|
204
215
|
|
|
205
216
|
/**
|
|
206
|
-
* Get
|
|
217
|
+
* Get AST
|
|
207
218
|
*/
|
|
208
|
-
export function
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return;
|
|
219
|
+
export function getAST(ast, info) {
|
|
220
|
+
if (ast.kind === 'FragmentSpread') {
|
|
221
|
+
const fragmentName = ast.name.value;
|
|
222
|
+
return info.fragments[fragmentName];
|
|
212
223
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
224
|
+
return ast;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Get selections of AST
|
|
229
|
+
*/
|
|
230
|
+
export function getASTSelections(ast: FieldNode) {
|
|
231
|
+
if (ast && ast.selectionSet && ast.selectionSet.selections && ast.selectionSet.selections.length) {
|
|
232
|
+
return ast.selectionSet.selections;
|
|
216
233
|
}
|
|
217
|
-
|
|
234
|
+
|
|
235
|
+
return [];
|
|
218
236
|
}
|
|
219
237
|
|
|
220
238
|
/**
|
|
@@ -246,59 +264,18 @@ export function getDirectiveResults(ast: SelectionNode, info: GraphQLResolveInfo
|
|
|
246
264
|
}
|
|
247
265
|
|
|
248
266
|
/**
|
|
249
|
-
*
|
|
267
|
+
* Get directive value from DirectiveNode for GraphQLResolveInfo
|
|
250
268
|
*/
|
|
251
|
-
export function
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
processArguments: false,
|
|
262
|
-
},
|
|
263
|
-
config,
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
return getASTSelections(ast).reduce((flattened, a) => {
|
|
267
|
-
if (a.directives && a.directives.length) {
|
|
268
|
-
const { shouldInclude, shouldSkip } = getDirectiveResults(a, info);
|
|
269
|
-
// Field/fragment is not included if either the @skip condition is true or the @include condition is false
|
|
270
|
-
// https://facebook.github.io/graphql/draft/#sec--include
|
|
271
|
-
if (shouldSkip || !shouldInclude) {
|
|
272
|
-
return flattened;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (isFieldNode(a)) {
|
|
277
|
-
const name = a.name.value;
|
|
278
|
-
if (config.excludedFields.indexOf(name) !== -1) {
|
|
279
|
-
return flattened;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (flattened[name] && flattened[name] !== '__arguments') {
|
|
283
|
-
Object.assign(flattened[name], flattenAST(a, info, flattened[name]));
|
|
284
|
-
} else {
|
|
285
|
-
flattened[name] = flattenAST(a, info);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (config.processArguments) {
|
|
289
|
-
// check if the current field has arguments
|
|
290
|
-
if (a.arguments && a.arguments.length) {
|
|
291
|
-
Object.assign(flattened[name], {
|
|
292
|
-
__arguments: getArguments(a),
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
} else {
|
|
297
|
-
flattened = flattenAST(getAST(a, info), info, flattened);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return flattened;
|
|
301
|
-
}, obj);
|
|
269
|
+
export function getDirectiveValue(directive: DirectiveNode, info: GraphQLResolveInfo) {
|
|
270
|
+
const arg = directive.arguments?.[0]; // only arg on an include or skip directive is "if"
|
|
271
|
+
if (!arg) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (arg.value.kind !== 'Variable') {
|
|
275
|
+
const valueNode = arg.value;
|
|
276
|
+
return isValueNodeWithValueField(valueNode) ? !!valueNode.value : false;
|
|
277
|
+
}
|
|
278
|
+
return info.variableValues[arg.value.name.value];
|
|
302
279
|
}
|
|
303
280
|
|
|
304
281
|
/**
|
|
@@ -326,10 +303,11 @@ export function getFields(
|
|
|
326
303
|
}
|
|
327
304
|
|
|
328
305
|
/**
|
|
329
|
-
* Check if
|
|
306
|
+
* Check if AST is a Field
|
|
307
|
+
* @param ast
|
|
330
308
|
*/
|
|
331
|
-
export function
|
|
332
|
-
return
|
|
309
|
+
export function isFieldNode(ast: SelectionNode): ast is FieldNode {
|
|
310
|
+
return ast.kind === 'Field';
|
|
333
311
|
}
|
|
334
312
|
|
|
335
313
|
/**
|
|
@@ -338,3 +316,25 @@ export function isInGraphQLResolveInfo(path: any, info: GraphQLResolveInfo, conf
|
|
|
338
316
|
export function isInFields(path: any, fields: any) {
|
|
339
317
|
return _.has(fields, path);
|
|
340
318
|
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Check if field is in GraphQLResolveInfo
|
|
322
|
+
*/
|
|
323
|
+
export function isInGraphQLResolveInfo(path: any, info: GraphQLResolveInfo, config: Partial<GraphQLFieldsConfig> = {}) {
|
|
324
|
+
return _.has(getFields(info, config), path);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Check ValueNode is a ListValue
|
|
329
|
+
* @param value
|
|
330
|
+
*/
|
|
331
|
+
export function isListValueNode(value: ValueNode): value is ListValueNode {
|
|
332
|
+
return value.kind === 'ListValue';
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Check if ValueNode has a value field
|
|
337
|
+
*/
|
|
338
|
+
export function isValueNodeWithValueField(value: ValueNode): value is ValueNodeWithValueField {
|
|
339
|
+
return value.kind !== 'NullValue' && value.kind !== 'ListValue' && value.kind !== 'ObjectValue';
|
|
340
|
+
}
|
|
@@ -466,6 +466,29 @@ export function getPlain(object: any) {
|
|
|
466
466
|
return JSON.parse(JSON.stringify(object));
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
+
/**
|
|
470
|
+
* Get instance of array items (via first item)
|
|
471
|
+
*/
|
|
472
|
+
export function instanceofArray(arr: any[], strict = false): string {
|
|
473
|
+
let constructor: string = undefined;
|
|
474
|
+
if (!arr?.length) {
|
|
475
|
+
return constructor;
|
|
476
|
+
}
|
|
477
|
+
try {
|
|
478
|
+
constructor = arr[0].constructor;
|
|
479
|
+
if (strict) {
|
|
480
|
+
for (const item of arr) {
|
|
481
|
+
if (item.constructor !== constructor) {
|
|
482
|
+
return undefined;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
} catch (e) {
|
|
487
|
+
return undefined;
|
|
488
|
+
}
|
|
489
|
+
return constructor;
|
|
490
|
+
}
|
|
491
|
+
|
|
469
492
|
/**
|
|
470
493
|
* Check if parameter is an array
|
|
471
494
|
*/
|
|
@@ -605,13 +628,6 @@ export function isObject(parameter: any, falseFunction: (...params) => any = err
|
|
|
605
628
|
: falseFunction(isObject);
|
|
606
629
|
}
|
|
607
630
|
|
|
608
|
-
/**
|
|
609
|
-
* Check whether the parameter can be converted to true
|
|
610
|
-
*/
|
|
611
|
-
export function isTrue(parameter: any, falseFunction: (...params) => any = errorFunction): boolean {
|
|
612
|
-
return !!parameter ? true : falseFunction(isTrue);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
631
|
/**
|
|
616
632
|
* Check if parameter is a string
|
|
617
633
|
*/
|
|
@@ -620,41 +636,10 @@ export function isString(parameter: string, falseFunction: (...params) => any =
|
|
|
620
636
|
}
|
|
621
637
|
|
|
622
638
|
/**
|
|
623
|
-
*
|
|
624
|
-
*/
|
|
625
|
-
export function mergePlain(target: Record<any, any>, ...args: Record<any, any>[]): any {
|
|
626
|
-
return merge(
|
|
627
|
-
target,
|
|
628
|
-
...args.map(
|
|
629
|
-
// Prepare records
|
|
630
|
-
item =>
|
|
631
|
-
// Return item if not an object or cloned record with undefined properties removed
|
|
632
|
-
!item ? item : filterProperties(clone(item, { circles: false }), prop => prop !== undefined),
|
|
633
|
-
),
|
|
634
|
-
);
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
* Alternative for errorFunction
|
|
639
|
-
*/
|
|
640
|
-
export function returnFalse(): boolean {
|
|
641
|
-
return false;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* Match function to use instead of switch case
|
|
646
|
-
* Inspired by https://yusfuu.medium.com/dont-use-switch-or-if-else-in-javascript-instead-try-this-82f32616c269
|
|
647
|
-
*
|
|
648
|
-
* Example:
|
|
649
|
-
* const matched = match(expr, {
|
|
650
|
-
* Oranges: 'Oranges are $0.59 a pound.',
|
|
651
|
-
* Mangoes: 'Mangoes and papayas are $2.79 a pound.',
|
|
652
|
-
* Papayas: 'Mangoes and papayas are $2.79 a pound.',
|
|
653
|
-
* default: `Sorry, we are out of ${expr}.`,
|
|
654
|
-
* });
|
|
639
|
+
* Check whether the parameter can be converted to true
|
|
655
640
|
*/
|
|
656
|
-
export function
|
|
657
|
-
return
|
|
641
|
+
export function isTrue(parameter: any, falseFunction: (...params) => any = errorFunction): boolean {
|
|
642
|
+
return !!parameter ? true : falseFunction(isTrue);
|
|
658
643
|
}
|
|
659
644
|
|
|
660
645
|
/**
|
|
@@ -684,45 +669,50 @@ export function mapClass<T>(
|
|
|
684
669
|
}
|
|
685
670
|
|
|
686
671
|
/**
|
|
687
|
-
*
|
|
672
|
+
* Match function to use instead of switch case
|
|
673
|
+
* Inspired by https://yusfuu.medium.com/dont-use-switch-or-if-else-in-javascript-instead-try-this-82f32616c269
|
|
674
|
+
*
|
|
675
|
+
* Example:
|
|
676
|
+
* const matched = match(expr, {
|
|
677
|
+
* Oranges: 'Oranges are $0.59 a pound.',
|
|
678
|
+
* Mangoes: 'Mangoes and papayas are $2.79 a pound.',
|
|
679
|
+
* Papayas: 'Mangoes and papayas are $2.79 a pound.',
|
|
680
|
+
* default: `Sorry, we are out of ${expr}.`,
|
|
681
|
+
* });
|
|
688
682
|
*/
|
|
689
|
-
export function
|
|
690
|
-
|
|
691
|
-
if (!arr?.length) {
|
|
692
|
-
return type;
|
|
693
|
-
}
|
|
694
|
-
type = typeof arr[0];
|
|
695
|
-
if (strict) {
|
|
696
|
-
for (const item of arr) {
|
|
697
|
-
if (typeof item !== type) {
|
|
698
|
-
return undefined;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
return type;
|
|
683
|
+
export function match(expression: any, cases: Record<any, any>): any {
|
|
684
|
+
return cases[expression] || cases?.default;
|
|
703
685
|
}
|
|
704
686
|
|
|
705
687
|
/**
|
|
706
|
-
*
|
|
688
|
+
* Merge plain objects deep into target object and ignores undefined
|
|
707
689
|
*/
|
|
708
|
-
export function
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
690
|
+
export function mergePlain(target: Record<any, any>, ...args: Record<any, any>[]): any {
|
|
691
|
+
return merge(
|
|
692
|
+
target,
|
|
693
|
+
...args.map(
|
|
694
|
+
// Prepare records
|
|
695
|
+
item =>
|
|
696
|
+
// Return item if not an object or cloned record with undefined properties removed
|
|
697
|
+
!item ? item : filterProperties(clone(item, { circles: false }), prop => prop !== undefined),
|
|
698
|
+
),
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Helper to avoid very slow merge of serviceOptions
|
|
704
|
+
*/
|
|
705
|
+
export function prepareServiceOptionsForCreate(serviceOptions: any) {
|
|
706
|
+
if (!serviceOptions) {
|
|
707
|
+
serviceOptions = {};
|
|
712
708
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
if (strict) {
|
|
716
|
-
for (const item of arr) {
|
|
717
|
-
if (item.constructor !== constructor) {
|
|
718
|
-
return undefined;
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
} catch (e) {
|
|
723
|
-
return undefined;
|
|
709
|
+
if (!serviceOptions.prepareInput) {
|
|
710
|
+
serviceOptions.prepareInput = {};
|
|
724
711
|
}
|
|
725
|
-
|
|
712
|
+
if (serviceOptions.prepareInput.create === undefined) {
|
|
713
|
+
serviceOptions.prepareInput.create = true;
|
|
714
|
+
}
|
|
715
|
+
return serviceOptions;
|
|
726
716
|
}
|
|
727
717
|
|
|
728
718
|
/**
|
|
@@ -794,22 +784,6 @@ export function processDeep(
|
|
|
794
784
|
return func(data);
|
|
795
785
|
}
|
|
796
786
|
|
|
797
|
-
/**
|
|
798
|
-
* Helper to avoid very slow merge of serviceOptions
|
|
799
|
-
*/
|
|
800
|
-
export function prepareServiceOptionsForCreate(serviceOptions: any) {
|
|
801
|
-
if (!serviceOptions) {
|
|
802
|
-
serviceOptions = {};
|
|
803
|
-
}
|
|
804
|
-
if (!serviceOptions.prepareInput) {
|
|
805
|
-
serviceOptions.prepareInput = {};
|
|
806
|
-
}
|
|
807
|
-
if (serviceOptions.prepareInput.create === undefined) {
|
|
808
|
-
serviceOptions.prepareInput.create = true;
|
|
809
|
-
}
|
|
810
|
-
return serviceOptions;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
787
|
/**
|
|
814
788
|
* Remove properties deep
|
|
815
789
|
*/
|
|
@@ -857,3 +831,29 @@ export function removePropertiesDeep(
|
|
|
857
831
|
// Process others
|
|
858
832
|
return data;
|
|
859
833
|
}
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Alternative for errorFunction
|
|
837
|
+
*/
|
|
838
|
+
export function returnFalse(): boolean {
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Get type of array (via first item)
|
|
844
|
+
*/
|
|
845
|
+
export function typeofArray(arr: any[], strict = false): string {
|
|
846
|
+
let type: string = undefined;
|
|
847
|
+
if (!arr?.length) {
|
|
848
|
+
return type;
|
|
849
|
+
}
|
|
850
|
+
type = typeof arr[0];
|
|
851
|
+
if (strict) {
|
|
852
|
+
for (const item of arr) {
|
|
853
|
+
if (typeof item !== type) {
|
|
854
|
+
return undefined;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
return type;
|
|
859
|
+
}
|