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,20 +0,0 @@
1
- import { contextWithRoot } from '../utils/export'
2
- import type { DevWabeTypes } from '../utils/helper'
3
- import type { HookObject } from './HookObject'
4
-
5
- // TODO: It should better to do this in after delete to avoid case when deleteUser failed
6
- // For the moment KISS
7
- export const defaultDeleteSessionOnDeleteUser = async (
8
- object: HookObject<DevWabeTypes, 'User'>,
9
- ) => {
10
- const userId = object.object?.id
11
-
12
- await object.context.wabe.controllers.database.deleteObjects({
13
- className: '_Session',
14
- context: contextWithRoot(object.context),
15
- where: {
16
- user: { id: { equalTo: userId } },
17
- },
18
- select: {},
19
- })
20
- }
@@ -1,152 +0,0 @@
1
- import { hashFieldHook } from './hashFieldHook'
2
- import { describe, expect, it } from 'bun:test'
3
- import { HookObject } from './HookObject'
4
- import type { SchemaFields } from '../schema'
5
- import { OperationType } from '.'
6
- import { hashArgon2, verifyArgon2 } from 'src/utils/crypto'
7
-
8
- const makeHookObject = ({ className, operationType, newData, fields }: any) => {
9
- const config = {
10
- port: 0,
11
- isProduction: false,
12
- database: {} as any,
13
- rootKey: '',
14
- schema: {
15
- classes: [{ name: className, fields }],
16
- },
17
- }
18
- return new HookObject({
19
- className,
20
- operationType,
21
- newData,
22
- context: {
23
- wabe: { config } as any,
24
- isRoot: false,
25
- },
26
- object: { id: 'dummy' },
27
- select: {},
28
- })
29
- }
30
-
31
- describe('hashFieldHook', () => {
32
- const fields: SchemaFields<any> = {
33
- password: { type: 'Hash' },
34
- email: { type: 'Email' },
35
- authentication: {
36
- type: 'Object',
37
- object: {
38
- name: 'Authentication',
39
- fields: {
40
- emailPassword: {
41
- type: 'Object',
42
- object: {
43
- name: 'EmailPassword',
44
- fields: {
45
- password: { type: 'Hash' },
46
- },
47
- },
48
- },
49
- },
50
- },
51
- },
52
- twoHashes: {
53
- type: 'Object',
54
- object: {
55
- name: 'TwoHashes',
56
- fields: {
57
- hash1: { type: 'Hash' },
58
- hash2: { type: 'Hash' },
59
- },
60
- },
61
- },
62
- }
63
-
64
- it('should hashed a plain value in a sub object in beforeCreate', async () => {
65
- const newData = {
66
- authentication: { emailPassword: { password: 'mysecret' } },
67
- }
68
-
69
- const hookObject = makeHookObject({
70
- className: 'User',
71
- operationType: OperationType.BeforeCreate,
72
- newData,
73
- fields,
74
- })
75
-
76
- await hashFieldHook(hookObject)
77
-
78
- expect(hookObject.getNewData().authentication.emailPassword.password).not.toBe('mysecret')
79
-
80
- const isValid = await verifyArgon2(
81
- 'mysecret',
82
- hookObject.getNewData().authentication.emailPassword.password,
83
- )
84
- expect(isValid).toBe(true)
85
- })
86
-
87
- it('should hashed a plain value in a sub object with 2 hash fields in beforeCreate', async () => {
88
- const newData = {
89
- twoHashes: { hash1: 'mysecret', hash2: 'mysecret' },
90
- }
91
-
92
- const hookObject = makeHookObject({
93
- className: 'User',
94
- operationType: OperationType.BeforeCreate,
95
- newData,
96
- fields,
97
- })
98
-
99
- await hashFieldHook(hookObject)
100
-
101
- expect(hookObject.getNewData().twoHashes.hash1).not.toBe('mysecret')
102
-
103
- const isValid = await verifyArgon2('mysecret', hookObject.getNewData().twoHashes.hash1)
104
- expect(isValid).toBe(true)
105
-
106
- expect(hookObject.getNewData().twoHashes.hash2).not.toBe('mysecret')
107
-
108
- const isValid2 = await verifyArgon2('mysecret', hookObject.getNewData().twoHashes.hash2)
109
- expect(isValid2).toBe(true)
110
- })
111
-
112
- it('hashes a plain value on beforeCreate', async () => {
113
- const newData = { password: 'mysecret', email: 'test@example.com' }
114
- const hookObject = makeHookObject({
115
- className: 'User',
116
- operationType: 'beforeCreate',
117
- newData,
118
- fields,
119
- })
120
- await hashFieldHook(hookObject)
121
- expect(hookObject.getNewData().password).not.toBe('mysecret')
122
- expect(hookObject.getNewData().email).toBe('test@example.com')
123
-
124
- const isValid = await verifyArgon2('mysecret', hookObject.getNewData().password)
125
- expect(isValid).toBe(true)
126
- })
127
-
128
- it('does not double-hash an already hashed value', async () => {
129
- const hashed = await hashArgon2('alreadyhashed')
130
- const newData = { password: hashed }
131
- const hookObject = makeHookObject({
132
- className: 'User',
133
- operationType: 'beforeUpdate',
134
- newData,
135
- fields,
136
- })
137
- await hashFieldHook(hookObject)
138
- expect(hookObject.getNewData().password).toBe(hashed)
139
- })
140
-
141
- it('does nothing if not beforeCreate or beforeUpdate', async () => {
142
- const newData = { password: 'shouldnotchange' }
143
- const hookObject = makeHookObject({
144
- className: 'User',
145
- operationType: 'afterRead',
146
- newData,
147
- fields,
148
- })
149
- await hashFieldHook(hookObject)
150
- expect(hookObject.getNewData().password).toBe('shouldnotchange')
151
- })
152
- })
@@ -1,89 +0,0 @@
1
- import type { HookObject } from './HookObject'
2
- import type { WabeTypes } from '../server'
3
- import { getNestedProperty, getNewObjectAfterUpdateNestedProperty } from '../utils'
4
- import { OperationType } from '.'
5
- import { hashArgon2, isArgon2Hash } from 'src/utils/crypto'
6
-
7
- const hashField = ({ value }: { value: ReturnType<typeof HookObject.prototype.getNewData> }) => {
8
- if (!value || typeof value !== 'string' || isArgon2Hash(value)) return value
9
-
10
- return hashArgon2(value)
11
- }
12
-
13
- export async function hashFieldHook<T extends WabeTypes, K extends keyof WabeTypes['types']>(
14
- hookObject: HookObject<T, K>,
15
- ) {
16
- if (
17
- hookObject.operationType !== OperationType.BeforeCreate &&
18
- hookObject.operationType !== OperationType.BeforeUpdate
19
- )
20
- return
21
-
22
- const fields = hookObject.context.wabe.config.schema?.classes?.find(
23
- (cls: any) => cls.name === hookObject.className,
24
- )?.fields
25
-
26
- if (!fields) return
27
-
28
- const computeHashForFields = ({
29
- fieldsToCompute,
30
- path = '',
31
- }: {
32
- fieldsToCompute: typeof fields
33
- path?: string
34
- }) =>
35
- Promise.all(
36
- Object.entries(fieldsToCompute).map(async ([fieldName, fieldDef]) => {
37
- if (fieldDef.type === 'Object') {
38
- await computeHashForFields({
39
- // @ts-expect-error
40
- fieldsToCompute: fieldDef.object.fields,
41
- path: `${path || ''}${path ? '.' : ''}${fieldName}`,
42
- })
43
-
44
- return
45
- }
46
-
47
- if (fieldDef.type !== 'Hash') return
48
-
49
- // If we don't have nested object
50
- if (!path) {
51
- const hashed = await hashField({
52
- // @ts-expect-error
53
- value: hookObject.getNewData()[fieldName],
54
- })
55
-
56
- // @ts-expect-error
57
- hookObject.upsertNewData(fieldName, hashed)
58
-
59
- return
60
- }
61
-
62
- const objectNameToUpdate = path.split('.')[0] || ''
63
- // @ts-expect-error
64
- const objectToUpdate = hookObject.getNewData()[objectNameToUpdate]
65
- const valueToUpdate = getNestedProperty(hookObject.getNewData(), path)
66
-
67
- if (!valueToUpdate?.[fieldName]) return
68
-
69
- const hashed = await hashField({
70
- value: valueToUpdate[fieldName],
71
- })
72
-
73
- const newObject = getNewObjectAfterUpdateNestedProperty(
74
- { [objectNameToUpdate]: objectToUpdate },
75
- `${path}.${fieldName}`,
76
- hashed,
77
- )
78
-
79
- if (hashed)
80
- hookObject.upsertNewData(
81
- // @ts-expect-error
82
- objectNameToUpdate,
83
- newObject[objectNameToUpdate],
84
- )
85
- }),
86
- )
87
-
88
- await computeHashForFields({ fieldsToCompute: fields })
89
- }
@@ -1,258 +0,0 @@
1
- import { afterEach, describe, expect, it, spyOn, mock } from 'bun:test'
2
- import * as index from './index'
3
- import { OperationType } from './index'
4
-
5
- describe('Hooks', () => {
6
- const mockGetObject = mock(async (..._args: any[]) => ({}) as any)
7
- const mockGetObjects = mock(() => {})
8
- const mockCallback1 = mock(() => {})
9
- const mockCallback2 = mock(() => {})
10
- const mockCallback3 = mock(() => {})
11
- const mockCallback4 = mock(() => {})
12
- const mockCallback5 = mock(() => {})
13
-
14
- const controllers = {
15
- database: {
16
- getObject: mockGetObject,
17
- getObjects: mockGetObjects,
18
- },
19
- } as any
20
-
21
- const config = {
22
- hooks: [
23
- {
24
- callback: mockCallback1,
25
- operationType: OperationType.BeforeRead,
26
- priority: 1,
27
- },
28
- {
29
- callback: mockCallback2,
30
- operationType: OperationType.BeforeRead,
31
- priority: 2,
32
- },
33
- {
34
- callback: mockCallback3,
35
- operationType: OperationType.BeforeCreate,
36
- priority: 1,
37
- },
38
- {
39
- callback: mockCallback4,
40
- operationType: OperationType.BeforeRead,
41
- priority: 1,
42
- className: 'ClassTest',
43
- },
44
- {
45
- callback: mockCallback5,
46
- operationType: OperationType.BeforeRead,
47
- priority: 1,
48
- className: 'AnotherClass',
49
- },
50
- ],
51
- } as any
52
-
53
- afterEach(() => {
54
- mockGetObjects.mockClear()
55
- mockGetObject.mockClear()
56
- mockCallback1.mockClear()
57
- mockCallback2.mockClear()
58
- mockCallback3.mockClear()
59
- mockCallback4.mockClear()
60
- mockCallback5.mockClear()
61
- })
62
-
63
- it('should only run hook on specified className', async () => {
64
- const hooks = index.initializeHook({
65
- className: 'ClassTest',
66
- context: {
67
- isRoot: true,
68
- wabe: { controllers, config } as any,
69
- },
70
- newData: { name: 'test' },
71
- select: {},
72
- objectLoader: (id) =>
73
- mockGetObject({
74
- className: 'ClassTest',
75
- context: {
76
- isRoot: true,
77
- wabe: { controllers, config },
78
- },
79
- id,
80
- _skipHooks: true,
81
- }),
82
- })
83
-
84
- await hooks.runOnSingleObject({
85
- operationType: OperationType.BeforeRead,
86
- id: 'id',
87
- })
88
-
89
- expect(mockCallback4).toHaveBeenCalledTimes(1)
90
- expect(mockCallback5).toHaveBeenCalledTimes(0)
91
- })
92
-
93
- it('should run hook on BeforeRead with one object impacted', async () => {
94
- mockGetObject.mockResolvedValueOnce({ id: 'id', name: 'name' } as never)
95
-
96
- const hooks = index.initializeHook({
97
- className: 'ClassName',
98
- context: {
99
- isRoot: true,
100
- wabe: { controllers, config } as any,
101
- },
102
- newData: { name: 'test' },
103
- select: {},
104
- objectLoader: (id) =>
105
- mockGetObject({
106
- className: 'ClassName',
107
- context: {
108
- isRoot: true,
109
- wabe: { controllers, config },
110
- isGraphQLCall: false,
111
- },
112
- id,
113
- _skipHooks: true,
114
- }),
115
- })
116
-
117
- await hooks.runOnSingleObject({
118
- operationType: OperationType.BeforeRead,
119
- id: 'id',
120
- })
121
-
122
- expect(mockGetObject).toHaveBeenCalledTimes(1)
123
- expect(mockGetObject).toHaveBeenCalledWith({
124
- className: 'ClassName',
125
- context: {
126
- isRoot: true,
127
- wabe: { controllers, config },
128
- isGraphQLCall: false,
129
- },
130
- id: 'id',
131
- _skipHooks: true,
132
- })
133
-
134
- expect(mockCallback1).toHaveBeenCalledTimes(1)
135
-
136
- // @ts-expect-error
137
- const hookObject = mockCallback1.mock.calls[0][0] as any
138
-
139
- expect(hookObject.object).toEqual({
140
- id: 'id',
141
- name: 'name',
142
- })
143
-
144
- expect(hookObject.context).toEqual({
145
- isRoot: true,
146
- wabe: {
147
- controllers: expect.any(Object),
148
- config,
149
- },
150
- isGraphQLCall: false,
151
- })
152
- })
153
-
154
- it('should run hook on BeforeCreate', async () => {
155
- const hooks = index.initializeHook({
156
- className: 'ClassName',
157
- context: {
158
- isRoot: true,
159
- wabe: { controllers, config } as any,
160
- },
161
- newData: { name: 'test' },
162
- select: {},
163
- objectLoader: (id) =>
164
- mockGetObject({
165
- className: 'ClassTest',
166
- context: {
167
- isRoot: true,
168
- wabe: { controllers, config },
169
- },
170
- id,
171
- _skipHooks: true,
172
- }),
173
- })
174
-
175
- await hooks.runOnSingleObject({
176
- operationType: OperationType.BeforeCreate,
177
- })
178
-
179
- expect(mockGetObjects).toHaveBeenCalledTimes(0)
180
-
181
- // @ts-expect-error
182
- const hookObject = mockCallback3.mock.calls[0][0] as any
183
-
184
- // Before create the object is empty
185
- expect(hookObject.object).toEqual({})
186
-
187
- expect(hookObject.context).toEqual({
188
- isRoot: true,
189
- wabe: { controllers: expect.any(Object), config },
190
- isGraphQLCall: false,
191
- })
192
- })
193
-
194
- it('should run callback in priorities order', async () => {
195
- const spy_findHooksByPriority = spyOn(index, '_findHooksByPriority')
196
-
197
- mockGetObjects.mockResolvedValueOnce([{ id: 'id', name: 'name' }] as never)
198
-
199
- const hooks = index.initializeHook({
200
- className: 'ClassName',
201
- context: {
202
- isRoot: true,
203
- wabe: { controllers, config } as any,
204
- },
205
- newData: { name: 'test' },
206
- select: {},
207
- objectLoader: (id) =>
208
- mockGetObject({
209
- className: 'ClassTest',
210
- context: {
211
- isRoot: true,
212
- wabe: { controllers, config },
213
- },
214
- id,
215
- _skipHooks: true,
216
- }),
217
- })
218
-
219
- await hooks.runOnSingleObject({
220
- operationType: OperationType.BeforeRead,
221
- id: 'id',
222
- })
223
-
224
- expect(spy_findHooksByPriority.mock.calls[0]?.[0].priority).toEqual(1)
225
- expect(spy_findHooksByPriority.mock.calls[1]?.[0].priority).toEqual(2)
226
- })
227
-
228
- it('should call hook that is trigger by operation type', async () => {
229
- mockGetObjects.mockResolvedValueOnce([{ id: 'id', name: 'name' }] as never)
230
-
231
- const hooks = index.initializeHook({
232
- className: 'ClassName',
233
- context: {
234
- isRoot: true,
235
- wabe: { controllers, config } as any,
236
- },
237
- newData: { name: 'test' },
238
- select: {},
239
- objectLoader: (id) =>
240
- mockGetObject({
241
- className: 'ClassTest',
242
- context: {
243
- isRoot: true,
244
- wabe: { controllers, config },
245
- },
246
- id,
247
- _skipHooks: true,
248
- }),
249
- })
250
-
251
- await hooks.runOnSingleObject({
252
- operationType: OperationType.BeforeRead,
253
- id: 'id',
254
- })
255
-
256
- expect(mockCallback3).toHaveBeenCalledTimes(0)
257
- })
258
- })