wabe 0.6.9 → 0.6.10

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 (158) hide show
  1. package/README.md +138 -32
  2. package/bucket/b.txt +1 -0
  3. package/dev/index.ts +215 -0
  4. package/dist/authentication/Session.d.ts +4 -1
  5. package/dist/authentication/interface.d.ts +16 -0
  6. package/dist/email/interface.d.ts +1 -1
  7. package/dist/graphql/resolvers.d.ts +4 -2
  8. package/dist/hooks/index.d.ts +1 -0
  9. package/dist/index.d.ts +0 -1
  10. package/dist/index.js +8713 -8867
  11. package/dist/server/index.d.ts +4 -2
  12. package/dist/utils/crypto.d.ts +7 -0
  13. package/dist/utils/helper.d.ts +4 -1
  14. package/generated/schema.graphql +16 -14
  15. package/generated/wabe.ts +4 -4
  16. package/package.json +15 -15
  17. package/src/authentication/OTP.test.ts +69 -0
  18. package/src/authentication/OTP.ts +66 -0
  19. package/src/authentication/Session.test.ts +665 -0
  20. package/src/authentication/Session.ts +529 -0
  21. package/src/authentication/defaultAuthentication.ts +214 -0
  22. package/src/authentication/index.ts +3 -0
  23. package/src/authentication/interface.ts +157 -0
  24. package/src/authentication/oauth/GitHub.test.ts +105 -0
  25. package/src/authentication/oauth/GitHub.ts +133 -0
  26. package/src/authentication/oauth/Google.test.ts +105 -0
  27. package/src/authentication/oauth/Google.ts +110 -0
  28. package/src/authentication/oauth/Oauth2Client.test.ts +225 -0
  29. package/src/authentication/oauth/Oauth2Client.ts +140 -0
  30. package/src/authentication/oauth/index.ts +2 -0
  31. package/src/authentication/oauth/utils.test.ts +35 -0
  32. package/src/authentication/oauth/utils.ts +28 -0
  33. package/src/authentication/providers/EmailOTP.test.ts +138 -0
  34. package/src/authentication/providers/EmailOTP.ts +93 -0
  35. package/src/authentication/providers/EmailPassword.test.ts +187 -0
  36. package/src/authentication/providers/EmailPassword.ts +130 -0
  37. package/src/authentication/providers/EmailPasswordSRP.test.ts +206 -0
  38. package/src/authentication/providers/EmailPasswordSRP.ts +184 -0
  39. package/src/authentication/providers/GitHub.ts +30 -0
  40. package/src/authentication/providers/Google.ts +30 -0
  41. package/src/authentication/providers/OAuth.test.ts +185 -0
  42. package/src/authentication/providers/OAuth.ts +112 -0
  43. package/src/authentication/providers/PhonePassword.test.ts +187 -0
  44. package/src/authentication/providers/PhonePassword.ts +129 -0
  45. package/src/authentication/providers/QRCodeOTP.test.ts +79 -0
  46. package/src/authentication/providers/QRCodeOTP.ts +65 -0
  47. package/src/authentication/providers/index.ts +6 -0
  48. package/src/authentication/resolvers/refreshResolver.test.ts +37 -0
  49. package/src/authentication/resolvers/refreshResolver.ts +20 -0
  50. package/src/authentication/resolvers/signInWithResolver.inte.test.ts +59 -0
  51. package/src/authentication/resolvers/signInWithResolver.test.ts +307 -0
  52. package/src/authentication/resolvers/signInWithResolver.ts +102 -0
  53. package/src/authentication/resolvers/signOutResolver.test.ts +41 -0
  54. package/src/authentication/resolvers/signOutResolver.ts +22 -0
  55. package/src/authentication/resolvers/signUpWithResolver.test.ts +186 -0
  56. package/src/authentication/resolvers/signUpWithResolver.ts +69 -0
  57. package/src/authentication/resolvers/verifyChallenge.test.ts +136 -0
  58. package/src/authentication/resolvers/verifyChallenge.ts +69 -0
  59. package/src/authentication/roles.test.ts +59 -0
  60. package/src/authentication/roles.ts +40 -0
  61. package/src/authentication/utils.test.ts +99 -0
  62. package/src/authentication/utils.ts +43 -0
  63. package/src/cache/InMemoryCache.test.ts +62 -0
  64. package/src/cache/InMemoryCache.ts +45 -0
  65. package/src/cron/index.test.ts +17 -0
  66. package/src/cron/index.ts +46 -0
  67. package/src/database/DatabaseController.test.ts +625 -0
  68. package/src/database/DatabaseController.ts +983 -0
  69. package/src/database/index.test.ts +1230 -0
  70. package/src/database/index.ts +9 -0
  71. package/src/database/interface.ts +312 -0
  72. package/src/email/DevAdapter.ts +8 -0
  73. package/src/email/EmailController.test.ts +29 -0
  74. package/src/email/EmailController.ts +13 -0
  75. package/src/email/index.ts +2 -0
  76. package/src/email/interface.ts +36 -0
  77. package/src/email/templates/sendOtpCode.ts +120 -0
  78. package/src/file/FileController.ts +28 -0
  79. package/src/file/FileDevAdapter.ts +54 -0
  80. package/src/file/hookDeleteFile.ts +27 -0
  81. package/src/file/hookReadFile.ts +70 -0
  82. package/src/file/hookUploadFile.ts +53 -0
  83. package/src/file/index.test.ts +979 -0
  84. package/src/file/index.ts +2 -0
  85. package/src/file/interface.ts +42 -0
  86. package/src/graphql/GraphQLSchema.test.ts +4399 -0
  87. package/src/graphql/GraphQLSchema.ts +928 -0
  88. package/src/graphql/index.ts +2 -0
  89. package/src/graphql/parseGraphqlSchema.ts +94 -0
  90. package/src/graphql/parser.test.ts +217 -0
  91. package/src/graphql/parser.ts +566 -0
  92. package/src/graphql/pointerAndRelationFunction.ts +200 -0
  93. package/src/graphql/resolvers.ts +467 -0
  94. package/src/graphql/tests/aggregation.test.ts +1123 -0
  95. package/src/graphql/tests/e2e.test.ts +596 -0
  96. package/src/graphql/tests/scalars.test.ts +250 -0
  97. package/src/graphql/types.ts +219 -0
  98. package/src/hooks/HookObject.test.ts +122 -0
  99. package/src/hooks/HookObject.ts +168 -0
  100. package/src/hooks/authentication.ts +76 -0
  101. package/src/hooks/createUser.test.ts +77 -0
  102. package/src/hooks/createUser.ts +10 -0
  103. package/src/hooks/defaultFields.test.ts +187 -0
  104. package/src/hooks/defaultFields.ts +40 -0
  105. package/src/hooks/deleteSession.test.ts +181 -0
  106. package/src/hooks/deleteSession.ts +20 -0
  107. package/src/hooks/hashFieldHook.test.ts +163 -0
  108. package/src/hooks/hashFieldHook.ts +97 -0
  109. package/src/hooks/index.test.ts +207 -0
  110. package/src/hooks/index.ts +430 -0
  111. package/src/hooks/permissions.test.ts +424 -0
  112. package/src/hooks/permissions.ts +113 -0
  113. package/src/hooks/protected.test.ts +551 -0
  114. package/src/hooks/protected.ts +72 -0
  115. package/src/hooks/searchableFields.test.ts +166 -0
  116. package/src/hooks/searchableFields.ts +98 -0
  117. package/src/hooks/session.test.ts +138 -0
  118. package/src/hooks/session.ts +78 -0
  119. package/src/hooks/setEmail.test.ts +216 -0
  120. package/src/hooks/setEmail.ts +35 -0
  121. package/src/hooks/setupAcl.test.ts +589 -0
  122. package/src/hooks/setupAcl.ts +29 -0
  123. package/src/index.ts +9 -0
  124. package/src/schema/Schema.test.ts +484 -0
  125. package/src/schema/Schema.ts +795 -0
  126. package/src/schema/defaultResolvers.ts +94 -0
  127. package/src/schema/index.ts +1 -0
  128. package/src/schema/resolvers/meResolver.test.ts +62 -0
  129. package/src/schema/resolvers/meResolver.ts +14 -0
  130. package/src/schema/resolvers/newFile.ts +0 -0
  131. package/src/schema/resolvers/resetPassword.test.ts +345 -0
  132. package/src/schema/resolvers/resetPassword.ts +64 -0
  133. package/src/schema/resolvers/sendEmail.test.ts +118 -0
  134. package/src/schema/resolvers/sendEmail.ts +21 -0
  135. package/src/schema/resolvers/sendOtpCode.test.ts +153 -0
  136. package/src/schema/resolvers/sendOtpCode.ts +52 -0
  137. package/src/security.test.ts +3461 -0
  138. package/src/server/defaultSessionHandler.test.ts +66 -0
  139. package/src/server/defaultSessionHandler.ts +115 -0
  140. package/src/server/generateCodegen.ts +476 -0
  141. package/src/server/index.test.ts +552 -0
  142. package/src/server/index.ts +354 -0
  143. package/src/server/interface.ts +11 -0
  144. package/src/server/routes/authHandler.ts +187 -0
  145. package/src/server/routes/index.ts +40 -0
  146. package/src/utils/crypto.test.ts +41 -0
  147. package/src/utils/crypto.ts +121 -0
  148. package/src/utils/export.ts +13 -0
  149. package/src/utils/helper.ts +195 -0
  150. package/src/utils/index.test.ts +11 -0
  151. package/src/utils/index.ts +201 -0
  152. package/src/utils/preload.ts +8 -0
  153. package/src/utils/testHelper.ts +117 -0
  154. package/tsconfig.json +32 -0
  155. package/bunfig.toml +0 -4
  156. package/dist/ai/index.d.ts +0 -1
  157. package/dist/ai/interface.d.ts +0 -9
  158. /package/dist/server/{defaultHandlers.d.ts → defaultSessionHandler.d.ts} +0 -0
@@ -0,0 +1,2 @@
1
+ export * from './types'
2
+ export * from './GraphQLSchema'
@@ -0,0 +1,94 @@
1
+ import type { GraphQLSchema } from 'graphql'
2
+
3
+ export interface GraphqlSchemaOutput {
4
+ input: Record<string, string>
5
+ output?: string
6
+ }
7
+
8
+ const _getQueryFields = (
9
+ name: string,
10
+ schema: GraphQLSchema,
11
+ ): GraphqlSchemaOutput => {
12
+ const query = schema.getQueryType()?.getFields()[name]
13
+
14
+ if (!query) throw new Error('Type not found in schema')
15
+
16
+ const inputFields = query.args.reduce(
17
+ (acc, arg) => ({ ...acc, [arg.name]: arg.type.toString() }),
18
+ {},
19
+ )
20
+
21
+ const outputFields = query.type.toString()
22
+
23
+ return {
24
+ input: inputFields,
25
+ output: outputFields,
26
+ }
27
+ }
28
+
29
+ const _getMutationFields = (
30
+ name: string,
31
+ schema: GraphQLSchema,
32
+ ): GraphqlSchemaOutput => {
33
+ const mutation = schema.getMutationType()?.getFields()[name]
34
+
35
+ if (!mutation) throw new Error('Type not found in schema')
36
+
37
+ const inputFields = mutation.args.reduce(
38
+ (acc, arg) => ({ ...acc, [arg.name]: arg.type.toString() }),
39
+ {},
40
+ )
41
+
42
+ const outputFields = mutation.type.toString()
43
+
44
+ return {
45
+ input: inputFields,
46
+ output: outputFields,
47
+ }
48
+ }
49
+
50
+ const _getTypeFields = (
51
+ name: string,
52
+ schema: GraphQLSchema,
53
+ ): GraphqlSchemaOutput => {
54
+ const type = schema.getType(name)
55
+
56
+ if (!type) throw new Error('Type not found in schema')
57
+
58
+ // @ts-expect-error
59
+ const fields = (type?.getFields?.() || {}) as Record<string, any>
60
+
61
+ const formattedFields = Object.entries(fields).reduce(
62
+ (acc, [fieldName, fieldType]) => ({
63
+ ...acc,
64
+ [fieldName]: fieldType.type.toString(),
65
+ }),
66
+ {},
67
+ )
68
+
69
+ return {
70
+ input: formattedFields,
71
+ }
72
+ }
73
+
74
+ export const getTypeFromGraphQLSchema = ({
75
+ type,
76
+ name,
77
+ schema,
78
+ }: {
79
+ type: 'Type' | 'Query' | 'Mutation'
80
+ name: string
81
+ filter?: Array<string>
82
+ schema: GraphQLSchema
83
+ }): GraphqlSchemaOutput => {
84
+ switch (type) {
85
+ case 'Query':
86
+ return _getQueryFields(name, schema)
87
+ case 'Mutation':
88
+ return _getMutationFields(name, schema)
89
+ case 'Type':
90
+ return _getTypeFields(name, schema)
91
+ default:
92
+ throw new Error('Not implemented')
93
+ }
94
+ }
@@ -0,0 +1,217 @@
1
+ import { describe, expect, it } from 'bun:test'
2
+ import { GraphqlParser } from './parser'
3
+ import {
4
+ GraphQLNonNull,
5
+ type GraphQLNullableType,
6
+ GraphQLObjectType,
7
+ GraphQLString,
8
+ } from 'graphql'
9
+
10
+ const deepCompareGraphQLObjects = (
11
+ obj1: GraphQLNullableType,
12
+ obj2: GraphQLNullableType,
13
+ ): boolean => {
14
+ // Check if both objects are instances of GraphQLObjectType or GraphQLNonNull
15
+ if (
16
+ (!(obj1 instanceof GraphQLObjectType) &&
17
+ !(obj1 instanceof GraphQLNonNull)) ||
18
+ (!(obj2 instanceof GraphQLObjectType) && !(obj2 instanceof GraphQLNonNull))
19
+ )
20
+ return false
21
+
22
+ // Unwrap GraphQLNonNull if present
23
+ const unwrappedObj1 = obj1 instanceof GraphQLNonNull ? obj1.ofType : obj1
24
+ const unwrappedObj2 = obj2 instanceof GraphQLNonNull ? obj2.ofType : obj2
25
+
26
+ // Compare type name
27
+ if (unwrappedObj1.name !== unwrappedObj2.name) return false
28
+
29
+ // Compare description
30
+ if (unwrappedObj1.description !== unwrappedObj2.description) return false
31
+
32
+ // If both objects are GraphQLNonNull, recursively compare the wrapped types
33
+ if (obj1 instanceof GraphQLNonNull && obj2 instanceof GraphQLNonNull)
34
+ return deepCompareGraphQLObjects(unwrappedObj1, unwrappedObj2)
35
+
36
+ // If one object is GraphQLNonNull and the other is not, they are not equal
37
+ if (obj1 instanceof GraphQLNonNull || obj2 instanceof GraphQLNonNull)
38
+ return false
39
+
40
+ // Compare fields if both objects are GraphQLObjectType
41
+ const fields1 = (obj1 as GraphQLObjectType).getFields()
42
+ const fields2 = (obj2 as GraphQLObjectType).getFields()
43
+
44
+ if (Object.keys(fields1).length !== Object.keys(fields2).length) return false
45
+
46
+ for (const fieldName in fields1) {
47
+ if (!fields2[fieldName]) return false
48
+
49
+ const field1 = fields1[fieldName]
50
+ const field2 = fields2[fieldName]
51
+
52
+ // Check field name
53
+ if (field1?.name !== field2?.name) return false
54
+
55
+ // Check field description
56
+ if (field1?.description !== field2?.description) return false
57
+
58
+ // Check field type
59
+ if (field1?.type.toString() !== field2?.type.toString()) return false
60
+ }
61
+
62
+ return true
63
+ }
64
+
65
+ describe('WabeGraphqlParser', () => {
66
+ it('should parse a wabe object', () => {
67
+ const graphqlParser = GraphqlParser({
68
+ enums: [],
69
+ scalars: [],
70
+ })
71
+ const simpleObject = graphqlParser({
72
+ graphqlObjectType: {} as any,
73
+ schemaFields: {} as any,
74
+ allObjects: {} as any,
75
+ })._parseWabeObject({
76
+ description: 'A simple object',
77
+ required: true,
78
+ objectToParse: {
79
+ name: 'SimpleObject',
80
+ fields: {
81
+ name: { type: 'String', required: true },
82
+ },
83
+ },
84
+ nameOfTheObject: 'SimpleObject',
85
+ })
86
+
87
+ const expectedObject = new GraphQLNonNull(
88
+ new GraphQLObjectType({
89
+ name: 'SimpleObject',
90
+ description: 'A simple object',
91
+ fields: {
92
+ name: {
93
+ type: new GraphQLNonNull(GraphQLString),
94
+ },
95
+ },
96
+ }),
97
+ )
98
+
99
+ expect(deepCompareGraphQLObjects(simpleObject, expectedObject)).toEqual(
100
+ true,
101
+ )
102
+ })
103
+
104
+ it('should parse a recursive wabe object', () => {
105
+ const graphqlParser = GraphqlParser({
106
+ enums: [],
107
+ scalars: [],
108
+ })
109
+
110
+ const recursiveObject = graphqlParser({
111
+ graphqlObjectType: {} as any,
112
+ schemaFields: {} as any,
113
+ allObjects: {} as any,
114
+ })._parseWabeObject({
115
+ description: 'A recursive object',
116
+ required: true,
117
+ objectToParse: {
118
+ name: 'RecursiveObject',
119
+ fields: {
120
+ subObject: {
121
+ type: 'Object',
122
+ object: {
123
+ name: 'SubObject',
124
+ fields: {
125
+ name: { type: 'String', required: true },
126
+ },
127
+ },
128
+ },
129
+ },
130
+ },
131
+ nameOfTheObject: 'RecursiveObject',
132
+ })
133
+
134
+ const expectedObject = new GraphQLNonNull(
135
+ new GraphQLObjectType({
136
+ name: 'RecursiveObject',
137
+ description: 'A recursive object',
138
+ fields: {
139
+ subObject: {
140
+ type: new GraphQLObjectType({
141
+ name: 'RecursiveObjectSubObject',
142
+ fields: {
143
+ name: {
144
+ type: new GraphQLNonNull(GraphQLString),
145
+ },
146
+ },
147
+ }),
148
+ },
149
+ },
150
+ }),
151
+ )
152
+
153
+ expect(deepCompareGraphQLObjects(recursiveObject, expectedObject)).toEqual(
154
+ true,
155
+ )
156
+ })
157
+
158
+ it('should create an graphql object from simple object', () => {
159
+ const graphqlParser = GraphqlParser({
160
+ scalars: [],
161
+ enums: [],
162
+ })
163
+
164
+ const simpleObject = graphqlParser({
165
+ schemaFields: {
166
+ name: { type: 'String', required: true },
167
+ },
168
+ graphqlObjectType: 'Object',
169
+ allObjects: {},
170
+ }).getGraphqlFields('SimpleObject')
171
+
172
+ expect(simpleObject).toEqual({
173
+ name: {
174
+ type: new GraphQLNonNull(GraphQLString),
175
+ },
176
+ } as any)
177
+ })
178
+
179
+ it('should create an graphql object from recursive object', () => {
180
+ const graphqlParser = GraphqlParser({
181
+ scalars: [],
182
+ enums: [],
183
+ })
184
+
185
+ const recursiveObject = graphqlParser({
186
+ schemaFields: {
187
+ subObject: {
188
+ type: 'Object',
189
+ object: {
190
+ name: 'SubObject',
191
+ fields: {
192
+ name: { type: 'String', required: true },
193
+ },
194
+ },
195
+ },
196
+ },
197
+ graphqlObjectType: 'Object',
198
+ allObjects: {},
199
+ }).getGraphqlFields('SimpleObject')
200
+
201
+ const expectedGraphqlObject = new GraphQLObjectType({
202
+ name: 'SimpleObjectSubObject',
203
+ fields: {
204
+ name: {
205
+ type: new GraphQLNonNull(GraphQLString),
206
+ },
207
+ },
208
+ })
209
+
210
+ expect(
211
+ deepCompareGraphQLObjects(
212
+ recursiveObject.subObject.type,
213
+ expectedGraphqlObject,
214
+ ),
215
+ ).toEqual(true)
216
+ })
217
+ })