wabe 0.6.12 → 0.6.14

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 (156) hide show
  1. package/dist/database/DatabaseController.d.ts +2 -0
  2. package/dist/file/FileDevAdapter.d.ts +1 -0
  3. package/dist/graphql/pointerAndRelationFunction.d.ts +6 -0
  4. package/dist/index.js +3827 -3541
  5. package/dist/schema/Schema.d.ts +2 -2
  6. package/dist/server/generateCodegen.d.ts +10 -0
  7. package/dist/server/index.d.ts +2 -1
  8. package/dist/utils/objectKeys.d.ts +1 -0
  9. package/package.json +7 -4
  10. package/dev/index.ts +0 -215
  11. package/dist/schema/resolvers/sendEmail.d.ts +0 -1
  12. package/generated/schema.graphql +0 -1945
  13. package/generated/wabe.ts +0 -448
  14. package/src/authentication/OTP.test.ts +0 -69
  15. package/src/authentication/OTP.ts +0 -64
  16. package/src/authentication/Session.test.ts +0 -629
  17. package/src/authentication/Session.ts +0 -517
  18. package/src/authentication/cookies.ts +0 -10
  19. package/src/authentication/defaultAuthentication.ts +0 -209
  20. package/src/authentication/index.ts +0 -4
  21. package/src/authentication/interface.ts +0 -177
  22. package/src/authentication/oauth/GitHub.test.ts +0 -91
  23. package/src/authentication/oauth/GitHub.ts +0 -121
  24. package/src/authentication/oauth/Google.test.ts +0 -91
  25. package/src/authentication/oauth/Google.ts +0 -101
  26. package/src/authentication/oauth/Oauth2Client.test.ts +0 -219
  27. package/src/authentication/oauth/Oauth2Client.ts +0 -135
  28. package/src/authentication/oauth/index.ts +0 -2
  29. package/src/authentication/oauth/utils.test.ts +0 -33
  30. package/src/authentication/oauth/utils.ts +0 -27
  31. package/src/authentication/providers/EmailOTP.test.ts +0 -127
  32. package/src/authentication/providers/EmailOTP.ts +0 -95
  33. package/src/authentication/providers/EmailPassword.test.ts +0 -263
  34. package/src/authentication/providers/EmailPassword.ts +0 -138
  35. package/src/authentication/providers/EmailPasswordSRP.test.ts +0 -208
  36. package/src/authentication/providers/EmailPasswordSRP.ts +0 -191
  37. package/src/authentication/providers/GitHub.ts +0 -24
  38. package/src/authentication/providers/Google.ts +0 -24
  39. package/src/authentication/providers/OAuth.test.ts +0 -185
  40. package/src/authentication/providers/OAuth.ts +0 -106
  41. package/src/authentication/providers/PhonePassword.test.ts +0 -221
  42. package/src/authentication/providers/PhonePassword.ts +0 -136
  43. package/src/authentication/providers/QRCodeOTP.test.ts +0 -77
  44. package/src/authentication/providers/QRCodeOTP.ts +0 -69
  45. package/src/authentication/providers/index.ts +0 -6
  46. package/src/authentication/resolvers/refreshResolver.test.ts +0 -30
  47. package/src/authentication/resolvers/refreshResolver.ts +0 -19
  48. package/src/authentication/resolvers/signInWithResolver.inte.test.ts +0 -59
  49. package/src/authentication/resolvers/signInWithResolver.test.ts +0 -306
  50. package/src/authentication/resolvers/signInWithResolver.ts +0 -106
  51. package/src/authentication/resolvers/signOutResolver.test.ts +0 -38
  52. package/src/authentication/resolvers/signOutResolver.ts +0 -18
  53. package/src/authentication/resolvers/signUpWithResolver.test.ts +0 -180
  54. package/src/authentication/resolvers/signUpWithResolver.ts +0 -68
  55. package/src/authentication/resolvers/verifyChallenge.test.ts +0 -230
  56. package/src/authentication/resolvers/verifyChallenge.ts +0 -78
  57. package/src/authentication/roles.test.ts +0 -49
  58. package/src/authentication/roles.ts +0 -40
  59. package/src/authentication/security.ts +0 -278
  60. package/src/authentication/utils.test.ts +0 -97
  61. package/src/authentication/utils.ts +0 -39
  62. package/src/cache/InMemoryCache.test.ts +0 -62
  63. package/src/cache/InMemoryCache.ts +0 -45
  64. package/src/cron/index.test.ts +0 -17
  65. package/src/cron/index.ts +0 -43
  66. package/src/database/DatabaseController.test.ts +0 -613
  67. package/src/database/DatabaseController.ts +0 -1415
  68. package/src/database/index.test.ts +0 -1551
  69. package/src/database/index.ts +0 -9
  70. package/src/database/interface.ts +0 -308
  71. package/src/email/DevAdapter.ts +0 -7
  72. package/src/email/EmailController.test.ts +0 -29
  73. package/src/email/EmailController.ts +0 -13
  74. package/src/email/index.ts +0 -2
  75. package/src/email/interface.ts +0 -36
  76. package/src/email/templates/sendOtpCode.ts +0 -120
  77. package/src/file/FileController.ts +0 -28
  78. package/src/file/FileDevAdapter.ts +0 -51
  79. package/src/file/hookDeleteFile.ts +0 -25
  80. package/src/file/hookReadFile.ts +0 -66
  81. package/src/file/hookUploadFile.ts +0 -52
  82. package/src/file/index.test.ts +0 -1031
  83. package/src/file/index.ts +0 -2
  84. package/src/file/interface.ts +0 -63
  85. package/src/file/security.ts +0 -156
  86. package/src/graphql/GraphQLSchema.test.ts +0 -5099
  87. package/src/graphql/GraphQLSchema.ts +0 -886
  88. package/src/graphql/index.ts +0 -2
  89. package/src/graphql/parseGraphqlSchema.ts +0 -85
  90. package/src/graphql/parser.test.ts +0 -203
  91. package/src/graphql/parser.ts +0 -707
  92. package/src/graphql/pointerAndRelationFunction.ts +0 -191
  93. package/src/graphql/resolvers.ts +0 -464
  94. package/src/graphql/tests/aggregation.test.ts +0 -1115
  95. package/src/graphql/tests/e2e.test.ts +0 -590
  96. package/src/graphql/tests/scalars.test.ts +0 -250
  97. package/src/graphql/types.ts +0 -227
  98. package/src/hooks/HookObject.test.ts +0 -122
  99. package/src/hooks/HookObject.ts +0 -165
  100. package/src/hooks/authentication.ts +0 -67
  101. package/src/hooks/createUser.test.ts +0 -77
  102. package/src/hooks/createUser.ts +0 -10
  103. package/src/hooks/defaultFields.test.ts +0 -176
  104. package/src/hooks/defaultFields.ts +0 -32
  105. package/src/hooks/deleteSession.test.ts +0 -181
  106. package/src/hooks/deleteSession.ts +0 -20
  107. package/src/hooks/hashFieldHook.test.ts +0 -152
  108. package/src/hooks/hashFieldHook.ts +0 -89
  109. package/src/hooks/index.test.ts +0 -258
  110. package/src/hooks/index.ts +0 -420
  111. package/src/hooks/permissions.test.ts +0 -412
  112. package/src/hooks/permissions.ts +0 -93
  113. package/src/hooks/protected.test.ts +0 -551
  114. package/src/hooks/protected.ts +0 -74
  115. package/src/hooks/searchableFields.test.ts +0 -147
  116. package/src/hooks/searchableFields.ts +0 -86
  117. package/src/hooks/session.test.ts +0 -134
  118. package/src/hooks/session.ts +0 -76
  119. package/src/hooks/setEmail.test.ts +0 -216
  120. package/src/hooks/setEmail.ts +0 -33
  121. package/src/hooks/setupAcl.test.ts +0 -618
  122. package/src/hooks/setupAcl.ts +0 -25
  123. package/src/hooks/virtualFields.test.ts +0 -228
  124. package/src/hooks/virtualFields.ts +0 -48
  125. package/src/index.ts +0 -9
  126. package/src/schema/Schema.test.ts +0 -482
  127. package/src/schema/Schema.ts +0 -839
  128. package/src/schema/defaultResolvers.ts +0 -93
  129. package/src/schema/index.ts +0 -1
  130. package/src/schema/resolvers/meResolver.test.ts +0 -62
  131. package/src/schema/resolvers/meResolver.ts +0 -10
  132. package/src/schema/resolvers/resetPassword.test.ts +0 -341
  133. package/src/schema/resolvers/resetPassword.ts +0 -63
  134. package/src/schema/resolvers/sendEmail.test.ts +0 -118
  135. package/src/schema/resolvers/sendEmail.ts +0 -21
  136. package/src/schema/resolvers/sendOtpCode.test.ts +0 -141
  137. package/src/schema/resolvers/sendOtpCode.ts +0 -52
  138. package/src/security.test.ts +0 -4136
  139. package/src/server/defaultSessionHandler.test.ts +0 -62
  140. package/src/server/defaultSessionHandler.ts +0 -104
  141. package/src/server/generateCodegen.ts +0 -433
  142. package/src/server/index.test.ts +0 -843
  143. package/src/server/index.ts +0 -336
  144. package/src/server/interface.ts +0 -11
  145. package/src/server/routes/authHandler.ts +0 -171
  146. package/src/server/routes/index.ts +0 -48
  147. package/src/utils/crypto.test.ts +0 -41
  148. package/src/utils/crypto.ts +0 -105
  149. package/src/utils/database.ts +0 -8
  150. package/src/utils/export.ts +0 -12
  151. package/src/utils/helper.ts +0 -204
  152. package/src/utils/index.test.ts +0 -11
  153. package/src/utils/index.ts +0 -196
  154. package/src/utils/preload.ts +0 -8
  155. package/src/utils/testHelper.ts +0 -124
  156. package/tsconfig.json +0 -32
@@ -1,191 +0,0 @@
1
- import { getClassFromClassName } from '../utils'
2
- import type { WabeContext } from '../server/interface'
3
- import { notEmpty } from '../utils/export'
4
-
5
- type CreateAndLink = any
6
- type Link = string
7
- type Unlink = boolean
8
- type Add = Array<string>
9
- type Remove = Array<string>
10
- type CreateAndAdd = Array<any>
11
-
12
- export type TypeOfExecution = 'create' | 'update' | 'updateMany'
13
-
14
- export type InputFields = Record<
15
- string,
16
- | {
17
- createAndLink?: CreateAndLink
18
- link?: Link
19
- unlink?: Unlink
20
- add?: Add
21
- remove?: Remove
22
- createAndAdd?: CreateAndAdd
23
- }
24
- | string
25
- >
26
-
27
- export const createAndLink = async ({
28
- createAndLink,
29
- context,
30
- fieldName,
31
- className,
32
- }: {
33
- createAndLink: CreateAndLink
34
- fieldName: string
35
- context: WabeContext<any>
36
- className: string
37
- }) => {
38
- const classInSchema = getClassFromClassName(className, context.wabe.config)
39
-
40
- const res = await context.wabe.controllers.database.createObject({
41
- // @ts-expect-error
42
- className: classInSchema.fields[fieldName].class,
43
- data: createAndLink,
44
- select: { id: true },
45
- context,
46
- })
47
-
48
- return res?.id
49
- }
50
-
51
- export const createAndAdd = async ({
52
- createAndAdd,
53
- context,
54
- fieldName,
55
- className,
56
- }: {
57
- createAndAdd: CreateAndAdd
58
- fieldName: string
59
- context: WabeContext<any>
60
- className: string
61
- }) => {
62
- const classInSchema = getClassFromClassName(className, context.wabe.config)
63
-
64
- const result = await context.wabe.controllers.database.createObjects({
65
- // @ts-expect-error
66
- className: classInSchema.fields[fieldName].class,
67
- data: createAndAdd,
68
- select: { id: true },
69
- context,
70
- })
71
-
72
- return result.map((object: any) => object.id)
73
- }
74
-
75
- export const add = async ({
76
- add,
77
- context,
78
- fieldName,
79
- typeOfExecution,
80
- id,
81
- className,
82
- where,
83
- }: {
84
- add: Add
85
- fieldName: string
86
- context: WabeContext<any>
87
- typeOfExecution: TypeOfExecution
88
- id?: string
89
- className: string
90
- where: any
91
- }) => {
92
- if (typeOfExecution === 'create') return add
93
-
94
- if (typeOfExecution === 'update' && id) {
95
- const currentValue = await context.wabe.controllers.database.getObject({
96
- className,
97
- id,
98
- select: { [fieldName]: true },
99
- context,
100
- })
101
-
102
- const currentValueIds = currentValue?.[fieldName]?.map((object: any) => object.id) || []
103
-
104
- return [...currentValueIds, ...add].filter(notEmpty)
105
- }
106
-
107
- // For update many we need to get all objects that match the where and add the new value
108
- // So we doesn't update the field for updateMany
109
- if (typeOfExecution === 'updateMany' && where) {
110
- const allObjectsMatchedWithWhere = await context.wabe.controllers.database.getObjects({
111
- className,
112
- where,
113
- select: { [fieldName]: true },
114
- context,
115
- })
116
-
117
- return Promise.all(
118
- allObjectsMatchedWithWhere.flatMap((object: any) => {
119
- const currentValueIds = object[fieldName]?.map((object: any) => object.id) || []
120
-
121
- return [...currentValueIds, ...add]
122
- }),
123
- )
124
- }
125
- }
126
-
127
- export const remove = async ({
128
- remove,
129
- context,
130
- fieldName,
131
- typeOfExecution,
132
- id,
133
- className,
134
- where,
135
- }: {
136
- remove: Remove
137
- fieldName: string
138
- context: WabeContext<any>
139
- typeOfExecution: TypeOfExecution
140
- id?: string
141
- className: string
142
- where: any
143
- }) => {
144
- if (typeOfExecution === 'create') return []
145
-
146
- const classInSchema = getClassFromClassName(className, context.wabe.config)
147
-
148
- if (typeOfExecution === 'update' && id) {
149
- const currentValue = await context.wabe.controllers.database.getObject({
150
- className,
151
- id,
152
- select: { [fieldName]: true },
153
- context,
154
- })
155
-
156
- const olderValuesIds = currentValue?.[fieldName]?.map((object: any) => object.id) || []
157
-
158
- await context.wabe.controllers.database.deleteObjects({
159
- // @ts-expect-error
160
- className: classInSchema.fields[fieldName].class,
161
- where: { id: { in: remove } },
162
- context,
163
- select: {},
164
- })
165
-
166
- return olderValuesIds.filter((olderValue: any) => !remove.includes(olderValue))
167
- }
168
-
169
- if (typeOfExecution === 'updateMany' && where) {
170
- const allObjectsMatchedWithWhere = await context.wabe.controllers.database.getObjects({
171
- className,
172
- where,
173
- select: { [fieldName]: true },
174
- context,
175
- })
176
-
177
- const olderValuesIds = allObjectsMatchedWithWhere.flatMap(
178
- (object: any) => object[fieldName]?.map((object: any) => object.id) || [],
179
- )
180
-
181
- await context.wabe.controllers.database.deleteObjects({
182
- // @ts-expect-error
183
- className: classInSchema.fields[fieldName].class,
184
- where: { id: { in: remove } },
185
- context,
186
- select: {},
187
- })
188
-
189
- return olderValuesIds.filter((olderValue: any) => !remove.includes(olderValue))
190
- }
191
- }
@@ -1,464 +0,0 @@
1
- import type {
2
- GraphQLResolveInfo,
3
- SelectionSetNode,
4
- FragmentSpreadNode,
5
- FragmentDefinitionNode,
6
- } from 'graphql'
7
- import type { WabeTypes } from '..'
8
- import type { WabeContext } from '../server/interface'
9
- import { contextWithoutGraphQLCall, firstLetterInLowerCase } from '../utils'
10
- import {
11
- type InputFields,
12
- type TypeOfExecution,
13
- add,
14
- createAndAdd,
15
- createAndLink,
16
- remove,
17
- } from './pointerAndRelationFunction'
18
-
19
- import { valueFromASTUntyped } from 'graphql'
20
-
21
- const expandFragmentSpread = (
22
- fragmentSpread: FragmentSpreadNode,
23
- fragments: Record<string, FragmentDefinitionNode>,
24
- className: string,
25
- variables?: Record<string, any>,
26
- ): Record<string, any> => {
27
- const fragmentName = fragmentSpread.name.value
28
- const fragmentDef = fragments[fragmentName]
29
-
30
- if (!fragmentDef) {
31
- throw new Error(`Fragment "${fragmentName}" not found`)
32
- }
33
-
34
- return extractFieldsFromSetNode(fragmentDef.selectionSet, className, fragments, {
35
- variables,
36
- })
37
- }
38
-
39
- export const extractFieldsFromSetNode = (
40
- selectionSet: SelectionSetNode,
41
- className: string,
42
- fragments?: Record<string, FragmentDefinitionNode>,
43
- options?: { ignoreClassField?: boolean; variables?: Record<string, any> },
44
- ): Record<string, any> => {
45
- const ignoredFields = ['edges', 'node', 'clientMutationId', 'ok']
46
- const shouldIgnoreClassField = options?.ignoreClassField ?? true
47
-
48
- if (shouldIgnoreClassField && className) ignoredFields.push(firstLetterInLowerCase(className))
49
-
50
- return selectionSet.selections?.reduce(
51
- (acc, selection) => {
52
- // Handle fragment spreads
53
- if (selection.kind === 'FragmentSpread') {
54
- if (!fragments) {
55
- throw new Error('Fragment spreads require fragments to be provided')
56
- }
57
- const fragmentFields = expandFragmentSpread(
58
- selection as FragmentSpreadNode,
59
- fragments,
60
- className,
61
- options?.variables,
62
- )
63
- return { ...acc, ...fragmentFields }
64
- }
65
-
66
- //@ts-expect-error
67
- const currentValue = selection.name.value
68
-
69
- const _args =
70
- selection.kind === 'Field' && selection.arguments && selection.arguments.length > 0
71
- ? selection.arguments.reduce(
72
- (argAcc, arg) => ({
73
- ...argAcc,
74
- [arg.name.value]: valueFromASTUntyped(arg.value, options?.variables),
75
- }),
76
- {} as Record<string, any>,
77
- )
78
- : undefined
79
-
80
- if (selection.selectionSet?.selections && selection.selectionSet?.selections?.length > 0) {
81
- const res = extractFieldsFromSetNode(selection.selectionSet, className, fragments, {
82
- ignoreClassField: false,
83
- variables: options?.variables,
84
- })
85
-
86
- if (ignoredFields.indexOf(currentValue) === -1)
87
- return {
88
- ...acc,
89
- [currentValue]: _args ? { ...res, _args } : res,
90
- }
91
-
92
- return {
93
- ...acc,
94
- ...res,
95
- }
96
- }
97
-
98
- if (ignoredFields.indexOf(currentValue) === -1) {
99
- acc[currentValue] = _args ? { _args } : true
100
- }
101
-
102
- return acc
103
- },
104
- {} as Record<string, any>,
105
- )
106
- }
107
-
108
- const getFieldsFromInfo = (info: GraphQLResolveInfo, className: string) => {
109
- const selectionSet = info.fieldNodes[0]?.selectionSet
110
-
111
- if (!selectionSet) throw new Error('No output fields provided')
112
-
113
- const fields = extractFieldsFromSetNode(selectionSet, className, info.fragments, {
114
- variables: info.variableValues,
115
- })
116
-
117
- if (!fields) throw new Error('No fields provided')
118
-
119
- return fields
120
- }
121
-
122
- export const getFieldsOfClassName = ({
123
- fields,
124
- className,
125
- context,
126
- }: {
127
- fields: string[]
128
- className: string
129
- context: WabeContext<any>
130
- }): {
131
- classFields: string[]
132
- othersFields: string[]
133
- } => {
134
- const classFields = context.wabe.config.schema?.classes?.find(
135
- (schemaClass) => schemaClass.name === className,
136
- )?.fields
137
-
138
- if (!classFields) return { classFields: [], othersFields: fields }
139
-
140
- const sameFieldsAsClass = fields.filter((field) => {
141
- // If the field exist in the class
142
- // id is automatically include in a class but not provided in fields
143
- if (classFields[field] || field === 'id') return true
144
-
145
- // If the name of the field is include in the field provided
146
- // For example if a pointer field name "Role" is include in the field "role.name"
147
- if (Object.keys(classFields).find((classField) => field.includes(classField))) return true
148
-
149
- return false
150
- })
151
-
152
- const othersFields = fields.filter((field) => !sameFieldsAsClass.includes(field))
153
-
154
- return { classFields: sameFieldsAsClass, othersFields }
155
- }
156
-
157
- export const executeRelationOnFields = ({
158
- className,
159
- fields,
160
- context,
161
- id,
162
- typeOfExecution,
163
- where,
164
- }: {
165
- className: string
166
- fields: InputFields
167
- context: WabeContext<any>
168
- id?: string
169
- where?: any
170
- typeOfExecution?: TypeOfExecution
171
- }) => {
172
- const entries = Object.entries(fields)
173
-
174
- return entries.reduce(
175
- async (acc, [fieldName, value]) => {
176
- const newAcc = await acc
177
-
178
- if (value instanceof File) {
179
- newAcc[fieldName] = value
180
- } else if (typeof value === 'object' && value?.createAndLink) {
181
- newAcc[fieldName] = await createAndLink({
182
- createAndLink: value.createAndLink,
183
- fieldName,
184
- context: contextWithoutGraphQLCall(context),
185
- className,
186
- })
187
- } else if (typeof value === 'object' && value?.link) {
188
- newAcc[fieldName] = value.link
189
- } else if (typeof value === 'object' && value.unlink) {
190
- newAcc[fieldName] = null
191
- } else if (typeof value === 'object' && value?.createAndAdd) {
192
- newAcc[fieldName] = await createAndAdd({
193
- createAndAdd: value.createAndAdd,
194
- fieldName,
195
- context: contextWithoutGraphQLCall(context),
196
- className,
197
- })
198
- } else if (typeof value === 'object' && value?.add) {
199
- const addValue = await add({
200
- add: value.add,
201
- context: contextWithoutGraphQLCall(context),
202
- fieldName,
203
- typeOfExecution: typeOfExecution || 'create',
204
- id,
205
- className,
206
- where,
207
- })
208
-
209
- if (addValue) newAcc[fieldName] = addValue
210
- } else if (typeof value === 'object' && value?.remove) {
211
- const removeValue = await remove({
212
- remove: value.remove,
213
- context: contextWithoutGraphQLCall(context),
214
- fieldName,
215
- typeOfExecution: typeOfExecution || 'create',
216
- id,
217
- className,
218
- where,
219
- })
220
-
221
- if (removeValue) newAcc[fieldName] = removeValue
222
- } else {
223
- newAcc[fieldName] = value
224
- }
225
-
226
- return newAcc
227
- },
228
- Promise.resolve({}) as Promise<Record<string, any>>,
229
- )
230
- }
231
-
232
- const transformOrder = (order?: Array<string>): Record<string, 'ASC' | 'DESC'> =>
233
- order?.reduce(
234
- (acc, currentOrder) => {
235
- const result = Object.entries(currentOrder)[0]
236
-
237
- if (!result || !result[0] || !result[1]) return acc
238
-
239
- // @ts-expect-error
240
- acc[result[0]] = result[1]
241
-
242
- return acc
243
- },
244
- {} as Record<string, 'ASC' | 'DESC'>,
245
- ) || {}
246
-
247
- export const queryForOneObject = (
248
- _: any,
249
- { id }: any,
250
- context: WabeContext<any>,
251
- info: GraphQLResolveInfo,
252
- className: keyof WabeTypes['types'],
253
- ) => {
254
- const select = getFieldsFromInfo(info, className)
255
-
256
- return context.wabe.controllers.database.getObject({
257
- className,
258
- id,
259
- select,
260
- context,
261
- })
262
- }
263
-
264
- export const queryForMultipleObject = async (
265
- _: any,
266
- { where, offset, first, order }: any,
267
- context: WabeContext<any>,
268
- info: GraphQLResolveInfo,
269
- className: keyof WabeTypes['types'],
270
- ) => {
271
- const select = getFieldsFromInfo(info, className)
272
-
273
- const { totalCount, ...selectWithoutTotalCount } = select
274
-
275
- const objects = await context.wabe.controllers.database.getObjects({
276
- className,
277
- where,
278
- select: selectWithoutTotalCount,
279
- offset,
280
- first,
281
- context,
282
- order: transformOrder(order),
283
- })
284
-
285
- return {
286
- totalCount: totalCount
287
- ? await context.wabe.controllers.database.count({
288
- className,
289
- where,
290
- context,
291
- })
292
- : undefined,
293
- edges: objects.map((object: any) => ({
294
- node: object,
295
- })),
296
- }
297
- }
298
-
299
- export const mutationToCreateObject = async (
300
- _: any,
301
- args: any,
302
- context: WabeContext<any>,
303
- info: GraphQLResolveInfo,
304
- className: keyof WabeTypes['types'],
305
- ) => {
306
- const select = getFieldsFromInfo(info, className)
307
-
308
- const updatedFieldsToCreate = await executeRelationOnFields({
309
- className,
310
- fields: args.input?.fields,
311
- context,
312
- })
313
-
314
- return {
315
- [firstLetterInLowerCase(className)]: await context.wabe.controllers.database.createObject({
316
- className,
317
- data: updatedFieldsToCreate,
318
- select,
319
- context,
320
- }),
321
- ok: true,
322
- }
323
- }
324
-
325
- export const mutationToCreateMultipleObjects = async (
326
- _: any,
327
- { input: { fields, offset, first, order } }: any,
328
- context: WabeContext<any>,
329
- info: GraphQLResolveInfo,
330
- className: keyof WabeTypes['types'],
331
- ) => {
332
- const select = getFieldsFromInfo(info, className)
333
- const inputFields = fields as Array<any>
334
-
335
- const updatedFieldsToCreate = await Promise.all(
336
- inputFields.map((inputField) =>
337
- executeRelationOnFields({
338
- className,
339
- fields: inputField,
340
- context,
341
- }),
342
- ),
343
- )
344
-
345
- const objects = await context.wabe.controllers.database.createObjects({
346
- className,
347
- data: updatedFieldsToCreate,
348
- select,
349
- offset,
350
- first,
351
- context,
352
- order: transformOrder(order),
353
- })
354
-
355
- return {
356
- edges: objects.map((object: any) => ({ node: object })),
357
- }
358
- }
359
-
360
- export const mutationToUpdateObject = async (
361
- _: any,
362
- args: any,
363
- context: WabeContext<any>,
364
- info: GraphQLResolveInfo,
365
- className: keyof WabeTypes['types'],
366
- ) => {
367
- const select = getFieldsFromInfo(info, className)
368
-
369
- const updatedFields = await executeRelationOnFields({
370
- className,
371
- fields: args.input?.fields,
372
- context,
373
- id: args.input?.id,
374
- typeOfExecution: 'update',
375
- })
376
-
377
- return {
378
- [firstLetterInLowerCase(className)]: await context.wabe.controllers.database.updateObject({
379
- className,
380
- id: args.input?.id,
381
- data: updatedFields,
382
- select,
383
- context,
384
- }),
385
- ok: true,
386
- }
387
- }
388
-
389
- export const mutationToUpdateMultipleObjects = async (
390
- _: any,
391
- { input: { fields, where, offset, first, order } }: any,
392
- context: WabeContext<any>,
393
- info: GraphQLResolveInfo,
394
- className: keyof WabeTypes['types'],
395
- ) => {
396
- const select = getFieldsFromInfo(info, className)
397
-
398
- const updatedFields = await executeRelationOnFields({
399
- className,
400
- fields,
401
- context,
402
- typeOfExecution: 'updateMany',
403
- where,
404
- })
405
-
406
- const objects = await context.wabe.controllers.database.updateObjects({
407
- className,
408
- where,
409
- data: updatedFields,
410
- select,
411
- offset,
412
- first,
413
- context,
414
- order,
415
- })
416
-
417
- return {
418
- edges: objects.map((object: any) => ({ node: object })),
419
- }
420
- }
421
-
422
- export const mutationToDeleteObject = async (
423
- _: any,
424
- args: any,
425
- context: WabeContext<any>,
426
- info: GraphQLResolveInfo,
427
- className: keyof WabeTypes['types'],
428
- ) => {
429
- const select = getFieldsFromInfo(info, className)
430
-
431
- return {
432
- [firstLetterInLowerCase(className)]: await context.wabe.controllers.database.deleteObject({
433
- className,
434
- id: args.input?.id,
435
- select,
436
- context,
437
- }),
438
- ok: true,
439
- }
440
- }
441
-
442
- export const mutationToDeleteMultipleObjects = async (
443
- _: any,
444
- { input: { where, offset, first, order } }: any,
445
- context: WabeContext<any>,
446
- info: GraphQLResolveInfo,
447
- className: keyof WabeTypes['types'],
448
- ) => {
449
- const select = getFieldsFromInfo(info, className)
450
-
451
- const objects = await context.wabe.controllers.database.deleteObjects({
452
- className,
453
- where,
454
- select,
455
- offset,
456
- first,
457
- context,
458
- order,
459
- })
460
-
461
- return {
462
- edges: objects.map((object: any) => ({ node: object })),
463
- }
464
- }