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