@lenne.tech/nest-server 10.8.9 → 10.8.11

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.
Files changed (212) hide show
  1. package/dist/core/common/args/filter.args.js +2 -2
  2. package/dist/core/common/args/filter.args.js.map +1 -1
  3. package/dist/core/common/args/pagination.args.js +5 -5
  4. package/dist/core/common/args/pagination.args.js.map +1 -1
  5. package/dist/core/common/helpers/config.helper.d.ts +1 -1
  6. package/dist/core/common/helpers/config.helper.js +8 -8
  7. package/dist/core/common/helpers/config.helper.js.map +1 -1
  8. package/dist/core/common/helpers/db.helper.d.ts +11 -11
  9. package/dist/core/common/helpers/db.helper.js +100 -100
  10. package/dist/core/common/helpers/db.helper.js.map +1 -1
  11. package/dist/core/common/helpers/file.helper.d.ts +1 -1
  12. package/dist/core/common/helpers/file.helper.js +10 -10
  13. package/dist/core/common/helpers/file.helper.js.map +1 -1
  14. package/dist/core/common/helpers/filter.helper.d.ts +12 -12
  15. package/dist/core/common/helpers/filter.helper.js +19 -19
  16. package/dist/core/common/helpers/filter.helper.js.map +1 -1
  17. package/dist/core/common/helpers/graphql.helper.d.ts +8 -8
  18. package/dist/core/common/helpers/graphql.helper.js +75 -75
  19. package/dist/core/common/helpers/graphql.helper.js.map +1 -1
  20. package/dist/core/common/helpers/input.helper.d.ts +7 -7
  21. package/dist/core/common/helpers/input.helper.js +60 -60
  22. package/dist/core/common/helpers/input.helper.js.map +1 -1
  23. package/dist/core/common/helpers/model.helper.d.ts +8 -8
  24. package/dist/core/common/helpers/model.helper.js +38 -38
  25. package/dist/core/common/helpers/model.helper.js.map +1 -1
  26. package/dist/core/common/helpers/service.helper.d.ts +2 -2
  27. package/dist/core/common/helpers/table.helper.d.ts +1 -1
  28. package/dist/core/common/inputs/combined-filter.input.js +6 -6
  29. package/dist/core/common/inputs/combined-filter.input.js.map +1 -1
  30. package/dist/core/common/inputs/filter.input.js +6 -6
  31. package/dist/core/common/inputs/filter.input.js.map +1 -1
  32. package/dist/core/common/inputs/single-filter.input.js +10 -10
  33. package/dist/core/common/inputs/single-filter.input.js.map +1 -1
  34. package/dist/core/common/inputs/sort.input.js +4 -4
  35. package/dist/core/common/inputs/sort.input.js.map +1 -1
  36. package/dist/core/common/interfaces/server-options.interface.d.ts +8 -8
  37. package/dist/core/common/models/core-persistence.model.js +8 -8
  38. package/dist/core/common/models/core-persistence.model.js.map +1 -1
  39. package/dist/core/common/plugins/mongoose-id.plugin.d.ts +1 -1
  40. package/dist/core/common/plugins/mongoose-id.plugin.js +2 -2
  41. package/dist/core/common/plugins/mongoose-id.plugin.js.map +1 -1
  42. package/dist/core/common/scalars/any.scalar.js +8 -8
  43. package/dist/core/common/scalars/any.scalar.js.map +1 -1
  44. package/dist/core/common/scalars/date-timestamp.scalar.js +1 -1
  45. package/dist/core/common/scalars/date-timestamp.scalar.js.map +1 -1
  46. package/dist/core/common/scalars/date.scalar.js +1 -1
  47. package/dist/core/common/scalars/date.scalar.js.map +1 -1
  48. package/dist/core/common/scalars/json.scalar.js +8 -8
  49. package/dist/core/common/scalars/json.scalar.js.map +1 -1
  50. package/dist/core/common/services/config.service.d.ts +26 -26
  51. package/dist/core/common/services/crud.service.d.ts +32 -32
  52. package/dist/core/common/services/mailjet.service.js +1 -1
  53. package/dist/core/common/services/mailjet.service.js.map +1 -1
  54. package/dist/core/common/services/module.service.d.ts +1 -1
  55. package/dist/core/common/services/module.service.js.map +1 -1
  56. package/dist/core/common/types/falsy.type.d.ts +1 -1
  57. package/dist/core/common/types/id.type.d.ts +4 -4
  58. package/dist/core/common/types/require-only-one.type.d.ts +2 -2
  59. package/dist/core/common/types/required-at-least-one.type.d.ts +2 -2
  60. package/dist/core/common/types/string-or-object-id.type.d.ts +1 -1
  61. package/dist/core/modules/auth/core-auth.controller.js +6 -6
  62. package/dist/core/modules/auth/core-auth.controller.js.map +1 -1
  63. package/dist/core/modules/auth/core-auth.model.js +2 -2
  64. package/dist/core/modules/auth/core-auth.model.js.map +1 -1
  65. package/dist/core/modules/auth/core-auth.module.d.ts +4 -4
  66. package/dist/core/modules/auth/core-auth.module.js +2 -2
  67. package/dist/core/modules/auth/core-auth.module.js.map +1 -1
  68. package/dist/core/modules/auth/core-auth.resolver.js +6 -6
  69. package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
  70. package/dist/core/modules/auth/guards/auth.guard.d.ts +2 -2
  71. package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js +2 -2
  72. package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js.map +1 -1
  73. package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js +2 -2
  74. package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js.map +1 -1
  75. package/dist/core/modules/auth/services/core-auth.service.d.ts +2 -2
  76. package/dist/core/modules/file/core-file-info.model.js +8 -8
  77. package/dist/core/modules/file/core-file-info.model.js.map +1 -1
  78. package/dist/core/modules/file/core-file.controller.js +2 -2
  79. package/dist/core/modules/file/core-file.controller.js.map +1 -1
  80. package/dist/core/modules/file/core-file.resolver.js +6 -6
  81. package/dist/core/modules/file/core-file.resolver.js.map +1 -1
  82. package/dist/core/modules/file/core-file.service.d.ts +6 -6
  83. package/dist/core/modules/health-check/core-health-check-result.model.js +9 -9
  84. package/dist/core/modules/health-check/core-health-check-result.model.js.map +1 -1
  85. package/dist/core/modules/health-check/core-health-check.controller.js +2 -2
  86. package/dist/core/modules/health-check/core-health-check.controller.js.map +1 -1
  87. package/dist/core/modules/health-check/core-health-check.resolver.js +2 -2
  88. package/dist/core/modules/health-check/core-health-check.resolver.js.map +1 -1
  89. package/dist/core/modules/user/core-user.model.js +11 -11
  90. package/dist/core/modules/user/core-user.model.js.map +1 -1
  91. package/dist/core/modules/user/core-user.service.d.ts +2 -2
  92. package/dist/core/modules/user/inputs/core-user-create.input.js +3 -3
  93. package/dist/core/modules/user/inputs/core-user-create.input.js.map +1 -1
  94. package/dist/core/modules/user/inputs/core-user.input.js +10 -10
  95. package/dist/core/modules/user/inputs/core-user.input.js.map +1 -1
  96. package/dist/index.d.ts +8 -8
  97. package/dist/index.js +8 -8
  98. package/dist/index.js.map +1 -1
  99. package/dist/server/common/models/persistence.model.d.ts +2 -2
  100. package/dist/server/common/models/persistence.model.js +6 -6
  101. package/dist/server/common/models/persistence.model.js.map +1 -1
  102. package/dist/server/modules/auth/auth.controller.js +1 -1
  103. package/dist/server/modules/auth/auth.controller.js.map +1 -1
  104. package/dist/server/modules/auth/auth.model.js +3 -3
  105. package/dist/server/modules/auth/auth.model.js.map +1 -1
  106. package/dist/server/modules/auth/auth.resolver.js +3 -3
  107. package/dist/server/modules/auth/auth.resolver.js.map +1 -1
  108. package/dist/server/modules/auth/inputs/auth-sign-in.input.js +2 -2
  109. package/dist/server/modules/auth/inputs/auth-sign-in.input.js.map +1 -1
  110. package/dist/server/modules/auth/inputs/auth-sign-up.input.js +4 -4
  111. package/dist/server/modules/auth/inputs/auth-sign-up.input.js.map +1 -1
  112. package/dist/server/modules/file/file-info.model.js +2 -2
  113. package/dist/server/modules/file/file-info.model.js.map +1 -1
  114. package/dist/server/modules/file/file.controller.js +5 -5
  115. package/dist/server/modules/file/file.controller.js.map +1 -1
  116. package/dist/server/modules/file/file.resolver.js +5 -5
  117. package/dist/server/modules/file/file.resolver.js.map +1 -1
  118. package/dist/server/modules/user/avatar.controller.js +2 -2
  119. package/dist/server/modules/user/avatar.controller.js.map +1 -1
  120. package/dist/server/modules/user/inputs/user-create.input.js +2 -2
  121. package/dist/server/modules/user/inputs/user-create.input.js.map +1 -1
  122. package/dist/server/modules/user/inputs/user.input.js +2 -2
  123. package/dist/server/modules/user/inputs/user.input.js.map +1 -1
  124. package/dist/server/modules/user/outputs/find-and-count-users-result.output.js +4 -4
  125. package/dist/server/modules/user/outputs/find-and-count-users-result.output.js.map +1 -1
  126. package/dist/server/modules/user/user.model.js +8 -8
  127. package/dist/server/modules/user/user.model.js.map +1 -1
  128. package/dist/server/modules/user/user.resolver.d.ts +1 -1
  129. package/dist/server/modules/user/user.resolver.js +11 -11
  130. package/dist/server/modules/user/user.resolver.js.map +1 -1
  131. package/dist/server/modules/user/user.service.d.ts +1 -1
  132. package/dist/server/server.controller.js +2 -2
  133. package/dist/server/server.controller.js.map +1 -1
  134. package/dist/test/test.helper.d.ts +14 -14
  135. package/dist/test/test.helper.js +13 -3
  136. package/dist/test/test.helper.js.map +1 -1
  137. package/dist/tsconfig.build.tsbuildinfo +1 -1
  138. package/package.json +22 -19
  139. package/src/core/common/args/filter.args.ts +2 -2
  140. package/src/core/common/args/pagination.args.ts +5 -5
  141. package/src/core/common/decorators/graphql-service-options.decorator.ts +1 -1
  142. package/src/core/common/decorators/graphql-user.decorator.ts +1 -1
  143. package/src/core/common/decorators/rest-user.decorator.ts +1 -1
  144. package/src/core/common/helpers/config.helper.ts +22 -21
  145. package/src/core/common/helpers/db.helper.ts +164 -164
  146. package/src/core/common/helpers/file.helper.ts +18 -18
  147. package/src/core/common/helpers/filter.helper.ts +35 -35
  148. package/src/core/common/helpers/graphql.helper.ts +100 -100
  149. package/src/core/common/helpers/input.helper.ts +89 -89
  150. package/src/core/common/helpers/model.helper.ts +70 -70
  151. package/src/core/common/helpers/service.helper.ts +3 -3
  152. package/src/core/common/helpers/table.helper.ts +1 -1
  153. package/src/core/common/inputs/combined-filter.input.ts +5 -5
  154. package/src/core/common/inputs/filter.input.ts +5 -5
  155. package/src/core/common/inputs/single-filter.input.ts +9 -9
  156. package/src/core/common/inputs/sort.input.ts +3 -3
  157. package/src/core/common/interfaces/server-options.interface.ts +9 -9
  158. package/src/core/common/models/core-persistence.model.ts +8 -8
  159. package/src/core/common/plugins/mongoose-id.plugin.js +2 -2
  160. package/src/core/common/scalars/any.scalar.ts +8 -8
  161. package/src/core/common/scalars/date-timestamp.scalar.ts +1 -1
  162. package/src/core/common/scalars/date.scalar.ts +1 -1
  163. package/src/core/common/scalars/json.scalar.ts +8 -8
  164. package/src/core/common/services/config.service.ts +7 -7
  165. package/src/core/common/services/crud.service.ts +19 -19
  166. package/src/core/common/services/mailjet.service.ts +1 -1
  167. package/src/core/common/services/module.service.ts +4 -4
  168. package/src/core/common/types/falsy.type.ts +1 -1
  169. package/src/core/common/types/id.type.ts +1 -1
  170. package/src/core/common/types/require-only-one.type.ts +3 -3
  171. package/src/core/common/types/required-at-least-one.type.ts +3 -3
  172. package/src/core/common/types/string-or-object-id.type.ts +1 -1
  173. package/src/core/modules/auth/core-auth.controller.ts +6 -6
  174. package/src/core/modules/auth/core-auth.model.ts +1 -1
  175. package/src/core/modules/auth/core-auth.module.ts +4 -4
  176. package/src/core/modules/auth/core-auth.resolver.ts +6 -6
  177. package/src/core/modules/auth/guards/auth.guard.ts +3 -3
  178. package/src/core/modules/auth/inputs/core-auth-sign-in.input.ts +1 -1
  179. package/src/core/modules/auth/inputs/core-auth-sign-up.input.ts +1 -1
  180. package/src/core/modules/auth/services/core-auth.service.ts +1 -1
  181. package/src/core/modules/auth/tokens.decorator.ts +2 -2
  182. package/src/core/modules/file/core-file-info.model.ts +7 -7
  183. package/src/core/modules/file/core-file.controller.ts +2 -2
  184. package/src/core/modules/file/core-file.resolver.ts +6 -6
  185. package/src/core/modules/file/core-file.service.ts +6 -6
  186. package/src/core/modules/health-check/core-health-check-result.model.ts +8 -8
  187. package/src/core/modules/health-check/core-health-check.controller.ts +2 -2
  188. package/src/core/modules/health-check/core-health-check.resolver.ts +2 -2
  189. package/src/core/modules/user/core-user.model.ts +11 -11
  190. package/src/core/modules/user/core-user.service.ts +2 -2
  191. package/src/core/modules/user/inputs/core-user-create.input.ts +2 -2
  192. package/src/core/modules/user/inputs/core-user.input.ts +9 -9
  193. package/src/index.ts +9 -9
  194. package/src/server/common/models/persistence.model.ts +8 -8
  195. package/src/server/modules/auth/auth.controller.ts +1 -1
  196. package/src/server/modules/auth/auth.model.ts +2 -2
  197. package/src/server/modules/auth/auth.resolver.ts +3 -3
  198. package/src/server/modules/auth/inputs/auth-sign-in.input.ts +1 -1
  199. package/src/server/modules/auth/inputs/auth-sign-up.input.ts +3 -3
  200. package/src/server/modules/file/file-info.model.ts +2 -2
  201. package/src/server/modules/file/file.controller.ts +5 -5
  202. package/src/server/modules/file/file.module.ts +1 -1
  203. package/src/server/modules/file/file.resolver.ts +5 -5
  204. package/src/server/modules/user/avatar.controller.ts +2 -2
  205. package/src/server/modules/user/inputs/user-create.input.ts +1 -1
  206. package/src/server/modules/user/inputs/user.input.ts +1 -1
  207. package/src/server/modules/user/outputs/find-and-count-users-result.output.ts +3 -3
  208. package/src/server/modules/user/user.model.ts +8 -8
  209. package/src/server/modules/user/user.resolver.ts +11 -11
  210. package/src/server/modules/user/user.service.ts +1 -1
  211. package/src/server/server.controller.ts +2 -2
  212. package/src/test/test.helper.ts +31 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "10.8.9",
3
+ "version": "10.8.11",
4
4
  "description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
5
5
  "keywords": [
6
6
  "node",
@@ -22,7 +22,8 @@
22
22
  "docs:ci": "ts-node ./scripts/init-server.ts && npm run docs:bootstrap && compodoc -p tsconfig.json",
23
23
  "format": "prettier --write 'src/**/*.ts'",
24
24
  "format:staged": "pretty-quick --staged",
25
- "lint": "eslint \"{src,tests}/**/*.ts\" --fix",
25
+ "lint": "eslint './src/**/*.{ts,js,vue}'",
26
+ "lint:fix": "eslint './src/**/*.{ts,js,vue}' --fix",
26
27
  "prestart:prod": "npm run build",
27
28
  "reinit": "rimraf package-lock.json && rimraf node_modules && npm i && npm run lint && npm run test:e2e && npm run test:ci && npm run build",
28
29
  "reinit:clean": "rimraf package-lock.json && rimraf node_modules && npm cache clean --force && npm i && npm run test:e2e && npm run build",
@@ -49,7 +50,9 @@
49
50
  "prepack": "npm run prestart:prod",
50
51
  "prepublishOnly": "npm run lint && npm run test:ci",
51
52
  "preversion": "npm run lint",
52
- "watch": "npm-watch"
53
+ "watch": "npm-watch",
54
+ "link:eslint": "yalc add @lenne.tech/eslint-config-ts && yalc link @lenne.tech/eslint-config-ts && npm install",
55
+ "unlink:eslint": "yalc remove @lenne.tech/eslint-config-ts && npm install"
53
56
  },
54
57
  "repository": {
55
58
  "type": "git",
@@ -94,10 +97,10 @@
94
97
  "json-to-graphql-query": "2.3.0",
95
98
  "light-my-request": "6.6.0",
96
99
  "lodash": "4.17.21",
97
- "mongodb": "6.13.1",
100
+ "mongodb": "6.15.0",
98
101
  "mongoose": "7.8.6",
99
- "multer": "1.4.5-lts.1",
100
- "node-mailjet": "6.0.6",
102
+ "multer": "1.4.5-lts.2",
103
+ "node-mailjet": "6.0.8",
101
104
  "nodemailer": "6.10.0",
102
105
  "nodemon": "3.1.9",
103
106
  "passport": "0.7.0",
@@ -111,28 +114,28 @@
111
114
  "devDependencies": {
112
115
  "@babel/plugin-proposal-private-methods": "7.18.6",
113
116
  "@compodoc/compodoc": "1.1.26",
114
- "@lenne.tech/eslint-config-ts": "0.0.16",
117
+ "@lenne.tech/eslint-config-ts": "1.0.8",
115
118
  "@nestjs/cli": "10.4.9",
116
119
  "@nestjs/schematics": "10.2.3",
117
120
  "@nestjs/testing": "10.4.15",
118
121
  "@swc/cli": "0.5.2",
119
- "@swc/core": "1.10.18",
122
+ "@swc/core": "1.11.13",
120
123
  "@swc/jest": "0.2.37",
121
124
  "@types/compression": "1.7.5",
122
125
  "@types/cookie-parser": "1.4.8",
123
126
  "@types/ejs": "3.1.5",
124
127
  "@types/express": "4.17.21",
125
128
  "@types/jest": "29.5.14",
126
- "@types/lodash": "4.17.15",
129
+ "@types/lodash": "4.17.16",
127
130
  "@types/multer": "1.4.12",
128
- "@types/node": "22.13.5",
131
+ "@types/node": "22.13.14",
129
132
  "@types/nodemailer": "6.4.17",
130
133
  "@types/passport": "1.0.17",
131
- "@types/supertest": "6.0.2",
132
- "@typescript-eslint/eslint-plugin": "6.21.0",
133
- "@typescript-eslint/parser": "6.21.0",
134
+ "@types/supertest": "6.0.3",
135
+ "@typescript-eslint/eslint-plugin": "8.28.0",
136
+ "@typescript-eslint/parser": "8.28.0",
134
137
  "coffeescript": "2.7.0",
135
- "eslint": "8.57.1",
138
+ "eslint": "9.23.0",
136
139
  "eslint-config-prettier": "9.1.0",
137
140
  "eslint-plugin-unused-imports": "4.1.4",
138
141
  "find-file-up": "2.0.1",
@@ -145,15 +148,15 @@
145
148
  "jest": "29.7.0",
146
149
  "npm-watch": "0.13.0",
147
150
  "pm2": "5.4.3",
148
- "prettier": "3.5.2",
149
- "pretty-quick": "4.0.0",
150
- "supertest": "7.0.0",
151
- "ts-jest": "29.2.6",
151
+ "prettier": "3.5.3",
152
+ "pretty-quick": "4.1.1",
153
+ "supertest": "7.1.0",
154
+ "ts-jest": "29.3.0",
152
155
  "ts-loader": "9.5.2",
153
156
  "ts-morph": "24.0.0",
154
157
  "ts-node": "10.9.2",
155
158
  "tsconfig-paths": "4.2.0",
156
- "typescript": "5.7.3",
159
+ "typescript": "5.8.2",
157
160
  "yalc": "1.0.0-pre.53"
158
161
  },
159
162
  "overrides": {
@@ -9,7 +9,7 @@ export class FilterArgs extends PaginationArgs {
9
9
  /**
10
10
  * Filtering
11
11
  */
12
- @Field(type => FilterInput, {
12
+ @Field(() => FilterInput, {
13
13
  description: 'Input for filtering',
14
14
  nullable: true,
15
15
  })
@@ -19,7 +19,7 @@ export class FilterArgs extends PaginationArgs {
19
19
  /**
20
20
  * Get a specific number of random samples from filter results
21
21
  */
22
- @Field(type => Number, {
22
+ @Field(() => Number, {
23
23
  description:
24
24
  'Request only a specified number of samples from the filter results; if not specified, all results are returned.',
25
25
  nullable: true,
@@ -10,7 +10,7 @@ export class PaginationArgs extends CoreInput {
10
10
  /**
11
11
  * Limit for pagination
12
12
  */
13
- @Field(type => Int, {
13
+ @Field(() => Int, {
14
14
  description: 'Limit specifies the maximum number of elements found that are to be returned',
15
15
  nullable: true,
16
16
  })
@@ -20,7 +20,7 @@ export class PaginationArgs extends CoreInput {
20
20
  /**
21
21
  * Alias for skip
22
22
  */
23
- @Field(type => Int, {
23
+ @Field(() => Int, {
24
24
  description: 'Alias for skip',
25
25
  nullable: true,
26
26
  })
@@ -30,7 +30,7 @@ export class PaginationArgs extends CoreInput {
30
30
  /**
31
31
  * Skip for pagination
32
32
  */
33
- @Field(type => Int, {
33
+ @Field(() => Int, {
34
34
  description: 'Skip specifies how many found elements should be skipped on return',
35
35
  nullable: true,
36
36
  })
@@ -40,7 +40,7 @@ export class PaginationArgs extends CoreInput {
40
40
  /**
41
41
  * Sorting for pagination
42
42
  */
43
- @Field(type => [SortInput], {
43
+ @Field(() => [SortInput], {
44
44
  description: 'Sorting the returned elements',
45
45
  nullable: true,
46
46
  })
@@ -50,7 +50,7 @@ export class PaginationArgs extends CoreInput {
50
50
  /**
51
51
  * Alias for limit
52
52
  */
53
- @Field(type => Int, {
53
+ @Field(() => Int, {
54
54
  description: 'Alias for limit',
55
55
  nullable: true,
56
56
  })
@@ -1,4 +1,4 @@
1
- import { ExecutionContext, createParamDecorator } from '@nestjs/common';
1
+ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
2
2
 
3
3
  import { currentUserDec, graphqlPopulateDec } from '../helpers/decorator.helper';
4
4
  import { ServiceOptions } from '../interfaces/service-options.interface';
@@ -1,4 +1,4 @@
1
- import { ExecutionContext, createParamDecorator } from '@nestjs/common';
1
+ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
2
2
  import { GqlExecutionContext } from '@nestjs/graphql';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { ExecutionContext, createParamDecorator } from '@nestjs/common';
1
+ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
2
2
 
3
3
  /**
4
4
  * User decorator for REST request
@@ -28,28 +28,7 @@ export default class Config {
28
28
  }
29
29
  }
30
30
 
31
- /**
32
- * Special merge function (e.g. for configurations)
33
- *
34
- * It acts like the merge function of lodash:
35
- * - Source objects are merged into the destination object
36
- * - Source objects are applied from left to right
37
- * - Subsequent sources overwrite property assignments of previous sources
38
- *
39
- * except that arrays are not merged but overwrite arrays of previous sources.
40
- *
41
- * @param {any} obj destination object
42
- * @param {any[]} sources source objects
43
- * @returns {any}
44
- */
45
31
 
46
- export function merge(obj: Record<string, any>, ...sources: any[]): any {
47
- return _.mergeWith(obj, ...sources, (objValue: any, srcValue: any) => {
48
- if (Array.isArray(srcValue)) {
49
- return srcValue;
50
- }
51
- });
52
- }
53
32
 
54
33
  /**
55
34
  * Get environment configuration (deeply merged into config object set via options)
@@ -193,3 +172,25 @@ export function getEnvironmentObject(options?: {
193
172
 
194
173
  return output;
195
174
  }
175
+
176
+ /**
177
+ * Special merge function (e.g. for configurations)
178
+ *
179
+ * It acts like the merge function of lodash:
180
+ * - Source objects are merged into the destination object
181
+ * - Source objects are applied from left to right
182
+ * - Subsequent sources overwrite property assignments of previous sources
183
+ *
184
+ * except that arrays are not merged but overwrite arrays of previous sources.
185
+ *
186
+ * @param {any} obj destination object
187
+ * @param {any[]} sources source objects
188
+ * @returns {any}
189
+ */
190
+ export function merge(obj: Record<string, any>, ...sources: any[]): any {
191
+ return _.mergeWith(obj, ...sources, (objValue: any, srcValue: any) => {
192
+ if (Array.isArray(srcValue)) {
193
+ return srcValue;
194
+ }
195
+ });
196
+ }
@@ -112,6 +112,55 @@ export function equalIds(...ids: IdsType[]): boolean {
112
112
  return ids.every(id => getStringIds(id) === compare);
113
113
  }
114
114
 
115
+ /**
116
+ * Get (and remove) elements with specific IDs from array
117
+ */
118
+ export function getElementsViaIds<T = any>(
119
+ ids: any | any[],
120
+ array: T[],
121
+ options: {
122
+ splice?: boolean;
123
+ unique?: boolean;
124
+ } = {},
125
+ ): T[] {
126
+ // Config
127
+ const config = {
128
+ // Remove found elements from array
129
+ splice: false,
130
+
131
+ // Return unique elements
132
+ unique: false,
133
+
134
+ // Overwrite with options from parameters
135
+ ...options,
136
+ };
137
+
138
+ // Get and check indexes
139
+ const indexes = getIndexesViaIds(ids, array);
140
+ if (!indexes?.length) {
141
+ return [];
142
+ }
143
+
144
+ // Get elements
145
+ const elements = [];
146
+ indexes.forEach((index) => {
147
+ if (config.splice) {
148
+ elements.push(array.splice(index, 1)[0]);
149
+ } else {
150
+ elements.push(array[index]);
151
+ }
152
+ });
153
+
154
+ // Unique elements
155
+ if (config.unique) {
156
+ return elements.filter((value, index, self) => {
157
+ return self.findIndex(e => getStringIds(e)) === index;
158
+ });
159
+ }
160
+
161
+ // Return elements
162
+ return elements;
163
+ }
115
164
  /**
116
165
  * Get included ids
117
166
  * @param includes IdsType, which should be checked if it contains the ID
@@ -121,11 +170,12 @@ export function equalIds(...ids: IdsType[]): boolean {
121
170
  */
122
171
  export function getIncludedIds(includes: IdsType, ids: IdsType, convert?: 'string'): string[];
123
172
  export function getIncludedIds(includes: IdsType, ids: IdsType, convert?: 'object'): Types.ObjectId[];
173
+
124
174
  export function getIncludedIds<T = IdsType>(
125
175
  includes: IdsType,
126
176
  ids: IdsType | T,
127
177
  convert?: 'object' | 'string',
128
- ): T[] | null | undefined {
178
+ ): null | T[] | undefined {
129
179
  if (!includes || !ids) {
130
180
  return undefined;
131
181
  }
@@ -181,52 +231,26 @@ export function getIndexesViaIds(ids: IdsType, array: IdsType): number[] {
181
231
  // Return indexes
182
232
  return indexes;
183
233
  }
184
-
185
234
  /**
186
- * Get IDs from string of ObjectId array in a flat string array
235
+ * Get simple clone of object via JSON.stringify and JSON.parse
236
+ * @param obj
187
237
  */
188
- export function getStringIds(elements: any[], options?: { deep?: boolean; unique?: boolean }): string[];
189
- export function getStringIds(elements: any, options?: { deep?: boolean; unique?: boolean }): string;
190
- export function getStringIds<T extends any | any[]>(
191
- elements: T,
192
- options?: { deep?: boolean; unique?: boolean },
193
- ): string | string[] {
194
- // Process options
195
- const { deep, unique } = {
196
- deep: false,
197
- unique: false,
198
- ...options,
199
- };
200
-
201
- // Check elements
202
- if (!elements) {
203
- return elements as any;
204
- }
205
-
206
- // Init ids
207
- let ids = [];
208
-
209
- // Process non array
210
- if (!Array.isArray(elements)) {
211
- return getStringId(elements);
212
- }
213
-
214
- // Process array
215
- for (const element of elements) {
216
- if (Array.isArray(element)) {
217
- if (deep) {
218
- ids = ids.concat(getStringIds(element, { deep }));
219
- }
220
- } else {
221
- const id = getStringId(element);
222
- if (id) {
223
- ids.push(id);
224
- }
238
+ export function getJSONClone<T = any>(obj: T): Partial<T> {
239
+ return JSON.parse(JSON.stringify(obj));
240
+ }
241
+ /**
242
+ * Get next field nodes
243
+ */
244
+ export function getNextFieldNodes(nodes: readonly SelectionNode[]): FieldNode[] {
245
+ const result = [];
246
+ for (const node of nodes as FieldNode[]) {
247
+ if (node.name?.value) {
248
+ result.push(node);
249
+ } else if (node.selectionSet?.selections) {
250
+ result.push(...getNextFieldNodes(node.selectionSet.selections));
225
251
  }
226
252
  }
227
-
228
- // Return (unique) ID array
229
- return unique ? _.uniq(ids) : ids;
253
+ return result;
230
254
  }
231
255
 
232
256
  /**
@@ -241,56 +265,6 @@ export function getObjectIds<T extends any | any[]>(ids: T): Types.ObjectId | Ty
241
265
  return new Types.ObjectId(getStringId(ids));
242
266
  }
243
267
 
244
- /**
245
- * Get (and remove) elements with specific IDs from array
246
- */
247
- export function getElementsViaIds<T = any>(
248
- ids: any | any[],
249
- array: T[],
250
- options: {
251
- splice?: boolean;
252
- unique?: boolean;
253
- } = {},
254
- ): T[] {
255
- // Config
256
- const config = {
257
- // Remove found elements from array
258
- splice: false,
259
-
260
- // Return unique elements
261
- unique: false,
262
-
263
- // Overwrite with options from parameters
264
- ...options,
265
- };
266
-
267
- // Get and check indexes
268
- const indexes = getIndexesViaIds(ids, array);
269
- if (!indexes?.length) {
270
- return [];
271
- }
272
-
273
- // Get elements
274
- const elements = [];
275
- indexes.forEach((index) => {
276
- if (config.splice) {
277
- elements.push(array.splice(index, 1)[0]);
278
- } else {
279
- elements.push(array[index]);
280
- }
281
- });
282
-
283
- // Unique elements
284
- if (config.unique) {
285
- return elements.filter((value, index, self) => {
286
- return self.findIndex(e => getStringIds(e)) === index;
287
- });
288
- }
289
-
290
- // Return elements
291
- return elements;
292
- }
293
-
294
268
  /**
295
269
  * Get populate options from GraphQL resolve info
296
270
  */
@@ -332,21 +306,6 @@ export function getPopulateOptions(info: GraphQLResolveInfo, dotSeparatedSelect?
332
306
  return result;
333
307
  }
334
308
 
335
- /**
336
- * Get next field nodes
337
- */
338
- export function getNextFieldNodes(nodes: readonly SelectionNode[]): FieldNode[] {
339
- const result = [];
340
- for (const node of nodes as FieldNode[]) {
341
- if (node.name?.value) {
342
- result.push(node);
343
- } else if (node.selectionSet?.selections) {
344
- result.push(...getNextFieldNodes(node.selectionSet.selections));
345
- }
346
- }
347
- return result;
348
- }
349
-
350
309
  /**
351
310
  * Get populate options from selections
352
311
  */
@@ -399,11 +358,52 @@ export function getPopulatOptionsFromSelections(selectionNodes: readonly Selecti
399
358
  }
400
359
 
401
360
  /**
402
- * Get simple clone of object via JSON.stringify and JSON.parse
403
- * @param obj
361
+ * Get IDs from string of ObjectId array in a flat string array
404
362
  */
405
- export function getJSONClone<T = any>(obj: T): Partial<T> {
406
- return JSON.parse(JSON.stringify(obj));
363
+ export function getStringIds(elements: any[], options?: { deep?: boolean; unique?: boolean }): string[];
364
+
365
+ export function getStringIds(elements: any, options?: { deep?: boolean; unique?: boolean }): string;
366
+
367
+ export function getStringIds<T extends any | any[]>(
368
+ elements: T,
369
+ options?: { deep?: boolean; unique?: boolean },
370
+ ): string | string[] {
371
+ // Process options
372
+ const { deep, unique } = {
373
+ deep: false,
374
+ unique: false,
375
+ ...options,
376
+ };
377
+
378
+ // Check elements
379
+ if (!elements) {
380
+ return elements as any;
381
+ }
382
+
383
+ // Init ids
384
+ let ids = [];
385
+
386
+ // Process non array
387
+ if (!Array.isArray(elements)) {
388
+ return getStringId(elements);
389
+ }
390
+
391
+ // Process array
392
+ for (const element of elements) {
393
+ if (Array.isArray(element)) {
394
+ if (deep) {
395
+ ids = ids.concat(getStringIds(element, { deep }));
396
+ }
397
+ } else {
398
+ const id = getStringId(element);
399
+ if (id) {
400
+ ids.push(id);
401
+ }
402
+ }
403
+ }
404
+
405
+ // Return (unique) ID array
406
+ return unique ? _.uniq(ids) : ids;
407
407
  }
408
408
 
409
409
  /**
@@ -442,58 +442,6 @@ export function objectIdsToStrings(element: any, prepared: WeakMap<any, any> = n
442
442
  return element;
443
443
  }
444
444
 
445
- /**
446
- * Remove unresolved references: ObjectId => null
447
- */
448
- export function removeUnresolvedReferences<T = any>(
449
- populated: T,
450
- populatedOptions: (PopulateOptions | string)[] | PopulateOptions | PopulateOptions[] | string,
451
- ignoreFirst = true,
452
- ): T {
453
- // Check parameter
454
- if (!populated || !populatedOptions) {
455
- return populated;
456
- }
457
-
458
- // Process array
459
- if (Array.isArray(populated)) {
460
- populated.forEach(p => removeUnresolvedReferences(p, populatedOptions, false));
461
- return populated;
462
- }
463
-
464
- // Process object
465
- if (typeof populated === 'object') {
466
- // populatedOptions is an array
467
- if (Array.isArray(populatedOptions)) {
468
- populatedOptions.forEach(po =>
469
- removeUnresolvedReferences(populated, ignoreFirst && typeof po === 'object' ? po.populate : po, false),
470
- );
471
- return populated;
472
- }
473
-
474
- // populatedOptions is a string
475
- if (typeof populatedOptions === 'string') {
476
- if (!['_id', 'id'].includes(populatedOptions) && populated[populatedOptions] instanceof Types.ObjectId) {
477
- populated[populatedOptions] = null;
478
- }
479
- return populated;
480
- }
481
-
482
- // populatedOptions is an PopulateOptions object
483
- if (populatedOptions.path) {
484
- const key = populatedOptions.path;
485
- if (!['_id', 'id'].includes(key) && populated[key] instanceof Types.ObjectId) {
486
- populated[key] = null;
487
- } else if (populatedOptions.populate) {
488
- removeUnresolvedReferences(populated[key], populatedOptions.populate, false);
489
- }
490
- }
491
- }
492
-
493
- // Process others
494
- return populated;
495
- }
496
-
497
445
  /**
498
446
  * Set populates, execute and map result
499
447
  */
@@ -596,6 +544,58 @@ export function removeIds(source: any[], ids: StringOrObjectId | StringOrObjectI
596
544
  return source;
597
545
  }
598
546
 
547
+ /**
548
+ * Remove unresolved references: ObjectId => null
549
+ */
550
+ export function removeUnresolvedReferences<T = any>(
551
+ populated: T,
552
+ populatedOptions: (PopulateOptions | string)[] | PopulateOptions | PopulateOptions[] | string,
553
+ ignoreFirst = true,
554
+ ): T {
555
+ // Check parameter
556
+ if (!populated || !populatedOptions) {
557
+ return populated;
558
+ }
559
+
560
+ // Process array
561
+ if (Array.isArray(populated)) {
562
+ populated.forEach(p => removeUnresolvedReferences(p, populatedOptions, false));
563
+ return populated;
564
+ }
565
+
566
+ // Process object
567
+ if (typeof populated === 'object') {
568
+ // populatedOptions is an array
569
+ if (Array.isArray(populatedOptions)) {
570
+ populatedOptions.forEach(po =>
571
+ removeUnresolvedReferences(populated, ignoreFirst && typeof po === 'object' ? po.populate : po, false),
572
+ );
573
+ return populated;
574
+ }
575
+
576
+ // populatedOptions is a string
577
+ if (typeof populatedOptions === 'string') {
578
+ if (!['_id', 'id'].includes(populatedOptions) && populated[populatedOptions] instanceof Types.ObjectId) {
579
+ populated[populatedOptions] = null;
580
+ }
581
+ return populated;
582
+ }
583
+
584
+ // populatedOptions is an PopulateOptions object
585
+ if (populatedOptions.path) {
586
+ const key = populatedOptions.path;
587
+ if (!['_id', 'id'].includes(key) && populated[key] instanceof Types.ObjectId) {
588
+ populated[key] = null;
589
+ } else if (populatedOptions.populate) {
590
+ removeUnresolvedReferences(populated[key], populatedOptions.populate, false);
591
+ }
592
+ }
593
+ }
594
+
595
+ // Process others
596
+ return populated;
597
+ }
598
+
599
599
  /**
600
600
  * Set populates via populates options array
601
601
  */
@@ -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
+ }