wabe 0.6.7 → 0.6.9

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 (68) hide show
  1. package/README.md +10 -7
  2. package/dist/authentication/OTP.d.ts +8 -0
  3. package/dist/authentication/Session.d.ts +5 -5
  4. package/dist/authentication/index.d.ts +1 -0
  5. package/dist/authentication/interface.d.ts +43 -26
  6. package/dist/authentication/oauth/GitHub.d.ts +1 -1
  7. package/dist/authentication/oauth/Google.d.ts +1 -1
  8. package/dist/authentication/oauth/Oauth2Client.d.ts +11 -11
  9. package/dist/authentication/oauth/utils.d.ts +1 -0
  10. package/dist/authentication/providers/EmailOTP.d.ts +2 -2
  11. package/dist/authentication/providers/EmailPassword.d.ts +3 -3
  12. package/dist/authentication/providers/EmailPasswordSRP.d.ts +21 -0
  13. package/dist/authentication/providers/GitHub.d.ts +3 -2
  14. package/dist/authentication/providers/Google.d.ts +3 -2
  15. package/dist/authentication/providers/OAuth.d.ts +2 -2
  16. package/dist/authentication/providers/PhonePassword.d.ts +3 -3
  17. package/dist/authentication/providers/QRCodeOTP.d.ts +11 -0
  18. package/dist/authentication/providers/index.d.ts +1 -0
  19. package/dist/authentication/resolvers/signInWithResolver.d.ts +4 -0
  20. package/dist/authentication/resolvers/signUpWithResolver.d.ts +4 -0
  21. package/dist/authentication/utils.d.ts +0 -1
  22. package/dist/cron/index.d.ts +8 -8
  23. package/dist/database/{controllers/DatabaseController.d.ts → DatabaseController.d.ts} +38 -36
  24. package/dist/database/index.d.ts +6 -9
  25. package/dist/database/{adapters/adaptersInterface.d.ts → interface.d.ts} +37 -47
  26. package/dist/email/DevAdapter.d.ts +1 -0
  27. package/dist/email/interface.d.ts +4 -4
  28. package/dist/{files → file}/FileController.d.ts +1 -1
  29. package/dist/{files → file}/FileDevAdapter.d.ts +1 -1
  30. package/dist/{files → file}/interface.d.ts +9 -3
  31. package/dist/graphql/GraphQLSchema.d.ts +32 -32
  32. package/dist/graphql/parser.d.ts +13 -13
  33. package/dist/graphql/pointerAndRelationFunction.d.ts +6 -6
  34. package/dist/graphql/resolvers.d.ts +5 -5
  35. package/dist/hooks/HookObject.d.ts +13 -12
  36. package/dist/hooks/createUser.d.ts +1 -0
  37. package/dist/hooks/deleteSession.d.ts +2 -0
  38. package/dist/hooks/hashFieldHook.d.ts +6 -0
  39. package/dist/hooks/index.d.ts +17 -13
  40. package/dist/hooks/setEmail.d.ts +2 -0
  41. package/dist/index.d.ts +1 -2
  42. package/dist/index.js +51013 -486
  43. package/dist/schema/Schema.d.ts +59 -57
  44. package/dist/schema/defaultResolvers.d.ts +2 -2
  45. package/dist/server/index.d.ts +20 -24
  46. package/dist/server/interface.d.ts +1 -0
  47. package/dist/server/routes/authHandler.d.ts +11 -0
  48. package/dist/utils/crypto.d.ts +11 -0
  49. package/dist/utils/export.d.ts +2 -0
  50. package/dist/utils/helper.d.ts +3 -6
  51. package/dist/utils/index.d.ts +20 -2
  52. package/generated/schema.graphql +87 -76
  53. package/generated/wabe.ts +49 -52
  54. package/package.json +52 -54
  55. package/dist/authentication/srp/processSRPChallenge.d.ts +0 -1
  56. package/dist/authentication/srp/signInWithSRP.d.ts +0 -1
  57. package/dist/authentication/srp/signUpWithSRP.d.ts +0 -1
  58. package/dist/database/adapters/MongoAdapter.d.ts +0 -64
  59. package/dist/database/adapters/index.d.ts +0 -2
  60. package/dist/database/controllers/index.d.ts +0 -1
  61. package/dist/payment/DevAdapter.d.ts +0 -17
  62. package/dist/payment/PaymentController.d.ts +0 -19
  63. package/dist/payment/index.d.ts +0 -2
  64. package/dist/payment/interface.d.ts +0 -235
  65. /package/dist/{files → file}/hookDeleteFile.d.ts +0 -0
  66. /package/dist/{files → file}/hookReadFile.d.ts +0 -0
  67. /package/dist/{files → file}/hookUploadFile.d.ts +0 -0
  68. /package/dist/{files → file}/index.d.ts +0 -0
package/README.md CHANGED
@@ -8,7 +8,9 @@
8
8
 
9
9
  ## What is Wabe?
10
10
 
11
- Wabe is an open-source backend as a service that allows you to create your own fully customizable backend in just a few minutes. It handles database access, automatic GraphQL API generation, authentication with various methods (classic or OAuth), permissions, security, payment, emails, and more for you.
11
+ Wabe is an open-source backend as a service that allows you to create your own fully customizable backend in just a few minutes. It handles database access, automatic GraphQL API generation, authentication with various methods (classic or OAuth), permissions, security, emails, and more for you.
12
+
13
+ It requires Bun or Node > 24.7.
12
14
 
13
15
  ## Install
14
16
 
@@ -21,7 +23,8 @@ yarn add wabe # On yarn
21
23
  ## Basic example
22
24
 
23
25
  ```ts
24
- import { DatabaseEnum, Wabe } from "wabe";
26
+ import { Wabe } from "wabe";
27
+ import { MongoAdapter } from "wabe-mongodb";
25
28
 
26
29
  const run = async () => {
27
30
  // Ensure your database is running before run the file
@@ -32,11 +35,12 @@ const run = async () => {
32
35
  rootKey:
33
36
  "0uwFvUxM$ceFuF1aEtTtZMa7DUN2NZudqgY5ve5W*QCyb58cwMj9JeoaV@d#%29v&aJzswuudVU1%nAT+rxS0Bh&OkgBYc0PH18*",
34
37
  database: {
35
- type: DatabaseEnum.Mongo,
36
- url: "mongodb://127.0.0.1:27045",
37
- name: "WabeApp",
38
+ adapter: new MongoAdapter({
39
+ databaseName: "WabeApp",
40
+ databaseUrl: "mongodb://127.0.0.1:27045",
41
+ }),
38
42
  },
39
- port: 3000,
43
+ port: 3001,
40
44
  });
41
45
 
42
46
  await wabe.start();
@@ -53,7 +57,6 @@ await run();
53
57
  - **GraphQL API**: A flexible and powerful GraphQL API (following GraphQL Relay standard) to interact with your data.
54
58
  - **Hooks**: Powerful hooks system to execute custom actions before or after database requests.
55
59
  - **Email**: Send emails with your favorite provider with very simple integration.
56
- - **Payment**: Accept payments with Stripe or create your own payment provider adapter.
57
60
 
58
61
  ## Contributing
59
62
 
@@ -3,6 +3,14 @@ export declare class OTP {
3
3
  private secret;
4
4
  internalTotp: TOTP;
5
5
  constructor(rootKey: string);
6
+ deriveSecret(userId: string): string;
6
7
  generate(userId: string): string;
7
8
  verify(otp: string, userId: string): boolean;
9
+ authenticatorGenerate(userId: string): string;
10
+ authenticatorVerify(otp: string, userId: string): boolean;
11
+ generateKeyuri({ userId, emailOrUsername, applicationName }: {
12
+ userId: string;
13
+ emailOrUsername: string;
14
+ applicationName: string;
15
+ }): string;
8
16
  }
@@ -9,13 +9,13 @@ export declare class Session {
9
9
  _getRefreshTokenExpiresInMs(config: WabeConfig<DevWabeTypes>);
10
10
  getRefreshTokenExpireAt(config: WabeConfig<DevWabeTypes>);
11
11
  meFromAccessToken(accessToken: string, context: WabeContext<DevWabeTypes>): Promise<{
12
- sessionId: string | null
13
- user: User | null
14
- accessToken: string | null
15
- refreshToken?: string | null
12
+ sessionId: string | null;
13
+ user: User | null;
14
+ accessToken: string | null;
15
+ refreshToken?: string | null;
16
16
  }>;
17
17
  create(userId: string, context: WabeContext<DevWabeTypes>);
18
+ refresh(accessToken: string, refreshToken: string, context: WabeContext<DevWabeTypes>);
18
19
  delete(context: WabeContext<DevWabeTypes>);
19
20
  _isRefreshTokenExpired(userRefreshTokenExpiresAt: Date, refreshTokenAgeInMs: number);
20
- refresh(accessToken: string, refreshToken: string, context: WabeContext<DevWabeTypes>);
21
21
  }
@@ -1,2 +1,3 @@
1
1
  export * from "./interface";
2
2
  export * from "./oauth";
3
+ export * from "./OTP";
@@ -2,9 +2,10 @@ import type { User } from "../../generated/wabe";
2
2
  import type { WabeContext } from "../server/interface";
3
3
  import type { SchemaFields } from "../schema";
4
4
  import type { WabeTypes, WobeCustomContext } from "../server";
5
+ import type { SelectType } from "../database/interface";
5
6
  export declare enum ProviderEnum {
6
7
  google = "google",
7
- github = "github",
8
+ github = "github"
8
9
  }
9
10
  export interface ProviderConfig {
10
11
  clientId: string;
@@ -14,50 +15,60 @@ export type AuthenticationEventsOptions<
14
15
  T extends WabeTypes,
15
16
  K
16
17
  > = {
17
- context: WabeContext<T>
18
- input: K
18
+ context: WabeContext<T>;
19
+ input: K;
19
20
  };
20
21
  export type AuthenticationEventsOptionsWithUserId<
21
22
  T extends WabeTypes,
22
23
  K
23
24
  > = AuthenticationEventsOptions<T, K> & {
24
- userId: string
25
+ userId: string;
25
26
  };
26
27
  export type OnSendChallengeOptions<T extends WabeTypes> = {
27
- context: WabeContext<T>
28
- user: T["types"]["User"]
28
+ context: WabeContext<T>;
29
+ user: T["types"]["User"];
29
30
  };
30
31
  export type OnVerifyChallengeOptions<
31
32
  T extends WabeTypes,
32
33
  K
33
34
  > = {
34
- context: WabeContext<T>
35
- input: K
35
+ context: WabeContext<T>;
36
+ input: K;
36
37
  };
37
38
  export type ProviderInterface<
38
39
  T extends WabeTypes,
39
40
  K = any
40
41
  > = {
41
42
  onSignIn: (options: AuthenticationEventsOptions<T, K>) => Promise<{
42
- user: Partial<User>
43
- }>
43
+ user: Partial<User>;
44
+ srp?: {
45
+ salt: string;
46
+ serverPublic: string;
47
+ };
48
+ }>;
44
49
  onSignUp: (options: AuthenticationEventsOptions<T, K>) => Promise<{
45
- authenticationDataToSave: any
46
- }>
50
+ authenticationDataToSave: any;
51
+ }>;
47
52
  onUpdateAuthenticationData?: (options: AuthenticationEventsOptionsWithUserId<T, K>) => Promise<{
48
- authenticationDataToSave: any
49
- }>
53
+ authenticationDataToSave: any;
54
+ }>;
50
55
  };
51
56
  export type SecondaryProviderInterface<
52
57
  T extends WabeTypes,
53
58
  K = any
54
59
  > = {
55
- onSendChallenge: (options: OnSendChallengeOptions<T>) => Promise<void> | void
60
+ onSendChallenge?: (options: OnSendChallengeOptions<T>) => Promise<void> | void;
56
61
  onVerifyChallenge: (options: OnVerifyChallengeOptions<T, K>) => Promise<{
57
- userId: string
62
+ userId: string;
63
+ srp?: {
64
+ serverSessionProof: string;
65
+ };
58
66
  } | null> | ({
59
- userId: string
60
- } | null)
67
+ userId: string;
68
+ srp?: {
69
+ serverSessionProof: string;
70
+ };
71
+ } | null);
61
72
  };
62
73
  export type CustomAuthenticationMethods<
63
74
  T extends WabeTypes,
@@ -65,14 +76,14 @@ export type CustomAuthenticationMethods<
65
76
  K = SchemaFields<T>,
66
77
  W = SchemaFields<T>
67
78
  > = {
68
- name: string
69
- input: K
70
- dataToStore?: W
71
- provider: U
72
- isSecondaryFactor?: boolean
79
+ name: string;
80
+ input: K;
81
+ dataToStore?: W;
82
+ provider: U;
83
+ isSecondaryFactor?: boolean;
73
84
  };
74
85
  export type RoleConfig = Array<string>;
75
- export interface SessionConfig {
86
+ export interface SessionConfig<T extends WabeTypes> {
76
87
  /**
77
88
  * The time in milliseconds that the access token will expire
78
89
  */
@@ -89,9 +100,13 @@ export interface SessionConfig {
89
100
  * The JWT secret used to sign the session tokens
90
101
  */
91
102
  jwtSecret: string;
103
+ /**
104
+ * A selection of fields to include in the JWT token in the "user" fields
105
+ */
106
+ jwtTokenFields?: SelectType<T, "User", keyof T["types"]["User"]>;
92
107
  }
93
108
  export interface AuthenticationConfig<T extends WabeTypes> {
94
- session?: SessionConfig;
109
+ session?: SessionConfig<T>;
95
110
  roles?: RoleConfig;
96
111
  successRedirectPath?: string;
97
112
  failureRedirectPath?: string;
@@ -100,6 +115,7 @@ export interface AuthenticationConfig<T extends WabeTypes> {
100
115
  providers?: Partial<Record<ProviderEnum, ProviderConfig>>;
101
116
  customAuthenticationMethods?: CustomAuthenticationMethods<T>[];
102
117
  sessionHandler?: (context: WobeCustomContext<T>) => void | Promise<void>;
118
+ disableSignUp?: boolean;
103
119
  }
104
120
  export interface CreateTokenFromAuthorizationCodeOptions {
105
121
  code: string;
@@ -115,8 +131,9 @@ export declare enum AuthenticationProvider {
115
131
  GitHub = "github",
116
132
  Google = "google",
117
133
  EmailPassword = "emailPassword",
118
- PhonePassword = "phonePassword",
134
+ PhonePassword = "phonePassword"
119
135
  }
120
136
  export declare enum SecondaryFactor {
121
137
  EmailOTP = "emailOTP",
138
+ QRCodeOTP = "qrcodeOTP"
122
139
  }
@@ -5,7 +5,7 @@ export declare class GitHub implements OAuth2ProviderWithPKCE {
5
5
  private clientSecret;
6
6
  constructor(config: WabeConfig<any>);
7
7
  createAuthorizationURL(state: string, codeVerifier: string, options?: {
8
- scopes?: string[]
8
+ scopes?: string[];
9
9
  }): URL;
10
10
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<Tokens>;
11
11
  refreshAccessToken(refreshToken: string): Promise<Tokens>;
@@ -5,7 +5,7 @@ export declare class Google implements OAuth2ProviderWithPKCE {
5
5
  private clientSecret;
6
6
  constructor(config: WabeConfig<any>);
7
7
  createAuthorizationURL(state: string, codeVerifier: string, options?: {
8
- scopes?: string[]
8
+ scopes?: string[];
9
9
  }): URL;
10
10
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<Tokens>;
11
11
  refreshAccessToken(refreshToken: string): Promise<Tokens>;
@@ -12,22 +12,22 @@ export declare class OAuth2Client {
12
12
  private redirectURI;
13
13
  constructor(clientId: string, authorizeEndpoint: string, tokenEndpoint: string, redirectURI: string);
14
14
  createAuthorizationURL(options?: {
15
- state?: string
16
- codeVerifier?: string
17
- scopes?: string[]
15
+ state?: string;
16
+ codeVerifier?: string;
17
+ scopes?: string[];
18
18
  }): URL;
19
19
  validateAuthorizationCode<_TokenResponseBody extends TokenResponseBody>(authorizationCode: string, options?: {
20
- codeVerifier?: string
21
- credentials?: string
22
- authenticateWith?: "http_basic_auth" | "request_body"
20
+ codeVerifier?: string;
21
+ credentials?: string;
22
+ authenticateWith?: "http_basic_auth" | "request_body";
23
23
  }): Promise<_TokenResponseBody>;
24
24
  refreshAccessToken<_TokenResponseBody extends TokenResponseBody>(refreshToken: string, options?: {
25
- credentials?: string
26
- authenticateWith?: "http_basic_auth" | "request_body"
27
- scopes?: string[]
25
+ credentials?: string;
26
+ authenticateWith?: "http_basic_auth" | "request_body";
27
+ scopes?: string[];
28
28
  }): Promise<_TokenResponseBody>;
29
29
  _sendTokenRequest<_TokenResponseBody extends TokenResponseBody>(body: URLSearchParams, options?: {
30
- credentials?: string
31
- authenticateWith?: "http_basic_auth" | "request_body"
30
+ credentials?: string;
31
+ authenticateWith?: "http_basic_auth" | "request_body";
32
32
  }): Promise<_TokenResponseBody>;
33
33
  }
@@ -10,5 +10,6 @@ export interface OAuth2ProviderWithPKCE {
10
10
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<Tokens>;
11
11
  refreshAccessToken?(refreshToken: string): Promise<Tokens>;
12
12
  }
13
+ // https://datatracker.ietf.org/doc/html/rfc7636#appendix-A
13
14
  export declare const base64URLencode: unknown;
14
15
  export declare const generateRandomValues: unknown;
@@ -1,8 +1,8 @@
1
1
  import type { DevWabeTypes } from "../../utils/helper";
2
2
  import type { OnSendChallengeOptions, OnVerifyChallengeOptions, SecondaryProviderInterface } from "../interface";
3
3
  type EmailOTPInterface = {
4
- email: string
5
- otp: string
4
+ email: string;
5
+ otp: string;
6
6
  };
7
7
  export declare class EmailOTP implements SecondaryProviderInterface<DevWabeTypes, EmailOTPInterface> {
8
8
  onSendChallenge({ context, user }: OnSendChallengeOptions<DevWabeTypes>);
@@ -1,9 +1,9 @@
1
1
  import type { AuthenticationEventsOptions, AuthenticationEventsOptionsWithUserId, ProviderInterface } from "../interface";
2
2
  import type { DevWabeTypes } from "../../utils/helper";
3
3
  type EmailPasswordInterface = {
4
- password: string
5
- email: string
6
- otp?: string
4
+ password: string;
5
+ email: string;
6
+ otp?: string;
7
7
  };
8
8
  export declare class EmailPassword implements ProviderInterface<DevWabeTypes, EmailPasswordInterface> {
9
9
  onSignIn({ input, context }: AuthenticationEventsOptions<DevWabeTypes, EmailPasswordInterface>);
@@ -0,0 +1,21 @@
1
+ import type { AuthenticationEventsOptions, OnVerifyChallengeOptions, ProviderInterface, SecondaryProviderInterface } from "../interface";
2
+ import type { DevWabeTypes } from "../../utils/helper";
3
+ type EmailPasswordSRPInterface = {
4
+ clientPublic: string;
5
+ email: string;
6
+ salt?: string;
7
+ verifier?: string;
8
+ };
9
+ export declare class EmailPasswordSRP implements ProviderInterface<DevWabeTypes, EmailPasswordSRPInterface> {
10
+ onSignIn({ input, context }: AuthenticationEventsOptions<DevWabeTypes, EmailPasswordSRPInterface>);
11
+ onSignUp({ input, context }: AuthenticationEventsOptions<DevWabeTypes, EmailPasswordSRPInterface>);
12
+ }
13
+ export interface EmailPasswordSRPChallengeInterface {
14
+ email: string;
15
+ clientPublic: string;
16
+ clientSessionProof: string;
17
+ }
18
+ export declare class EmailPasswordSRPChallenge implements SecondaryProviderInterface<DevWabeTypes, EmailPasswordSRPChallengeInterface> {
19
+ onVerifyChallenge({ context, input }: OnVerifyChallengeOptions<DevWabeTypes, EmailPasswordSRPChallengeInterface>);
20
+ }
21
+ export {};
@@ -1,12 +1,13 @@
1
1
  import type { DevWabeTypes } from "../../utils/helper";
2
2
  import { type AuthenticationEventsOptions, type ProviderInterface } from "../interface";
3
3
  type GitHubInterface = {
4
- authorizationCode: string
5
- codeVerifier: string
4
+ authorizationCode: string;
5
+ codeVerifier: string;
6
6
  };
7
7
  export declare class GitHub implements ProviderInterface<DevWabeTypes, GitHubInterface> {
8
8
  name: string;
9
9
  onSignIn(options: AuthenticationEventsOptions<DevWabeTypes, GitHubInterface>);
10
+ // @ts-expect-error
10
11
  onSignUp();
11
12
  }
12
13
  export {};
@@ -1,12 +1,13 @@
1
1
  import type { DevWabeTypes } from "../../utils/helper";
2
2
  import { type AuthenticationEventsOptions, type ProviderInterface } from "../interface";
3
3
  type GoogleInterface = {
4
- authorizationCode: string
5
- codeVerifier: string
4
+ authorizationCode: string;
5
+ codeVerifier: string;
6
6
  };
7
7
  export declare class Google implements ProviderInterface<DevWabeTypes, GoogleInterface> {
8
8
  name: string;
9
9
  onSignIn(options: AuthenticationEventsOptions<DevWabeTypes, GoogleInterface>);
10
+ // @ts-expect-error
10
11
  onSignUp();
11
12
  }
12
13
  export {};
@@ -1,6 +1,6 @@
1
1
  export type OAuthAuthenticationInterface = {
2
- authorizationCode: string
3
- codeVerifier: string
2
+ authorizationCode: string;
3
+ codeVerifier: string;
4
4
  };
5
5
  export declare const getProvider: unknown;
6
6
  export declare const oAuthAuthentication: unknown;
@@ -1,9 +1,9 @@
1
1
  import type { AuthenticationEventsOptions, AuthenticationEventsOptionsWithUserId, ProviderInterface } from "../interface";
2
2
  import type { DevWabeTypes } from "../../utils/helper";
3
3
  type PhonePasswordInterface = {
4
- password: string
5
- phone: string
6
- otp?: string
4
+ password: string;
5
+ phone: string;
6
+ otp?: string;
7
7
  };
8
8
  export declare class PhonePassword implements ProviderInterface<DevWabeTypes, PhonePasswordInterface> {
9
9
  onSignIn({ input, context }: AuthenticationEventsOptions<DevWabeTypes, PhonePasswordInterface>);
@@ -0,0 +1,11 @@
1
+ import type { DevWabeTypes } from "../../utils/helper";
2
+ import type { OnVerifyChallengeOptions, SecondaryProviderInterface } from "../interface";
3
+ type QRCodeOTPInterface = {
4
+ email: string;
5
+ otp: string;
6
+ };
7
+ export declare class QRCodeOTP implements SecondaryProviderInterface<DevWabeTypes, QRCodeOTPInterface> {
8
+ onSendChallenge();
9
+ onVerifyChallenge({ context, input }: OnVerifyChallengeOptions<DevWabeTypes, QRCodeOTPInterface>);
10
+ }
11
+ export {};
@@ -3,3 +3,4 @@ export * from "./Google";
3
3
  export * from "./GitHub";
4
4
  export * from "./PhonePassword";
5
5
  export * from "./EmailOTP";
6
+ export * from "./QRCodeOTP";
@@ -1 +1,5 @@
1
+ // 0 - Get the authentication method
2
+ // 1 - We check if the signIn is possible (call onSign)
3
+ // 2 - If secondaryFactor is present, we call the onSendChallenge method of the provider
4
+ // 3 - We create session
1
5
  export declare const signInWithResolver: unknown;
@@ -1 +1,5 @@
1
+ // 0 - Get the authentication method
2
+ // 1 - We check if the signUp is possible (call onSign)
3
+ // 2 - We create the user
4
+ // 3 - We create session
1
5
  export declare const signUpWithResolver: unknown;
@@ -5,4 +5,3 @@ export declare const getAuthenticationMethod: <
5
5
  T extends WabeTypes,
6
6
  U = ProviderInterface<T> | SecondaryProviderInterface<T>
7
7
  >(listOfMethods: string[], context: WabeContext<any>) => CustomAuthenticationMethods<T, U>;
8
- export declare const hashPassword: unknown;
@@ -2,10 +2,10 @@ import { Cron } from "croner";
2
2
  import type { Wabe, WabeTypes } from "../server";
3
3
  export type OutputCron<T extends WabeTypes> = (wabe: Wabe<T>) => Cron;
4
4
  export declare const cron: <T extends WabeTypes>({ pattern, run, maxRuns, enabledProtectedRuns }: {
5
- pattern: string
6
- maxRuns?: number
7
- enabledProtectedRuns?: boolean
8
- run: (wabe: Wabe<T>) => any | Promise<any>
5
+ pattern: string;
6
+ maxRuns?: number;
7
+ enabledProtectedRuns?: boolean;
8
+ run: (wabe: Wabe<T>) => any | Promise<any>;
9
9
  }) => OutputCron<T>;
10
10
  export declare enum CronExpressions {
11
11
  EVERY_SECOND = "* * * * * *",
@@ -23,10 +23,10 @@ export declare enum CronExpressions {
23
23
  EVERY_30_MINUTES = "0 */30 * * * *",
24
24
  EVERY_2_HOURS = "0 0 */2 * * *",
25
25
  EVERY_6_HOURS = "0 0 */6 * * *",
26
- EVERY_12_HOURS = "0 0 */12 * * *",
26
+ EVERY_12_HOURS = "0 0 */12 * * *"
27
27
  }
28
28
  export type CronConfig<T extends WabeTypes> = Array<{
29
- name: string
30
- cron: OutputCron<T>
31
- job?: Cron
29
+ name: string;
30
+ cron: OutputCron<T>;
31
+ job?: Cron;
32
32
  }>;
@@ -1,90 +1,92 @@
1
1
  import type { WabeTypes } from "../..";
2
- import type { WabeContext } from "../../server/interface";
3
- import type { CountOptions, CreateObjectOptions, CreateObjectsOptions, DatabaseAdapter, DeleteObjectOptions, DeleteObjectsOptions, GetObjectOptions, GetObjectsOptions, OutputType, UpdateObjectOptions, UpdateObjectsOptions, WhereType } from "../adapters/adaptersInterface";
2
+ import type { SchemaInterface } from "../schema";
3
+ import type { WabeContext } from "../server/interface";
4
+ import type { CountOptions, CreateObjectOptions, CreateObjectsOptions, DatabaseAdapter, DeleteObjectOptions, DeleteObjectsOptions, GetObjectOptions, GetObjectsOptions, OutputType, UpdateObjectOptions, UpdateObjectsOptions, WhereType } from "./interface";
4
5
  export type Select = Record<string, boolean>;
5
6
  type SelectWithObject = Record<string, object | boolean>;
6
7
  export declare class DatabaseController<T extends WabeTypes> {
7
8
  adapter: DatabaseAdapter<T>;
8
9
  constructor(adapter: DatabaseAdapter<T>);
9
10
  _getSelectMinusPointersAndRelations({ className, context, select }: {
10
- className: keyof T["types"]
11
- context: WabeContext<T>
12
- select?: SelectWithObject
11
+ className: keyof T["types"];
12
+ context: WabeContext<T>;
13
+ select?: SelectWithObject;
13
14
  }): {
15
+ // We associated the fieldName with a className and a select object
14
16
  pointers: Record<string, {
15
- className: string
16
- select: Select
17
- }>
18
- selectWithoutPointers: Select
17
+ className: string;
18
+ select: Select;
19
+ }>;
20
+ selectWithoutPointers: Select;
19
21
  };
20
22
  _isRelationField({ pointerField, currentClassName, context, originClassName }: {
21
- pointerField: string
22
- originClassName: string
23
- context: WabeContext<T>
24
- currentClassName?: string
23
+ pointerField: string;
24
+ originClassName: string;
25
+ context: WabeContext<T>;
26
+ currentClassName?: string;
25
27
  });
26
28
  _isPointerField({ pointerField, currentClassName, context, originClassName }: {
27
- originClassName: string
28
- context: WabeContext<T>
29
- pointerField: string
30
- currentClassName?: string
29
+ originClassName: string;
30
+ context: WabeContext<T>;
31
+ pointerField: string;
32
+ currentClassName?: string;
31
33
  });
32
34
  _getWhereObjectWithPointerOrRelation<U extends keyof T["types"]>(className: U, where: WhereType<T, U>, context: WabeContext<T>);
33
35
  _buildWhereWithACL<K extends keyof T["types"]>(where: WhereType<T, K>, context: WabeContext<T>, operation: "write" | "read"): WhereType<T, K>;
34
- _getFinalObjectWithPointerAndRelation({ pointers, context, originClassName, object, isGraphQLCall }: {
35
- originClassName: string
36
+ _getFinalObjectWithPointerAndRelation({ pointers, context, originClassName, object, _skipHooks }: {
37
+ originClassName: string;
36
38
  pointers: Record<string, {
37
- className: string
38
- select: Select
39
- }>
40
- context: WabeContext<any>
41
- object: Record<string, any>
42
- isGraphQLCall?: boolean
39
+ className: string;
40
+ select: Select;
41
+ }>;
42
+ context: WabeContext<any>;
43
+ object: Record<string, any>;
44
+ _skipHooks?: boolean;
43
45
  });
44
- connect(): Promise<any>;
45
- close(): Promise<any>;
46
- createClassIfNotExist(className: string, context: WabeContext<T>): Promise<any>;
46
+ close();
47
+ createClassIfNotExist(className: string, schema: SchemaInterface<T>): Promise<any>;
48
+ initializeDatabase(schema: SchemaInterface<T>): Promise<void>;
47
49
  count<K extends keyof T["types"]>({ className, context, where }: CountOptions<T, K>): Promise<number>;
48
50
  clearDatabase(): Promise<void>;
49
51
  getObject<
50
52
  K extends keyof T["types"],
51
53
  U extends keyof T["types"][K]
52
- >({ select, className, context, skipHooks, id, where, isGraphQLCall }: GetObjectOptions<T, K, U>): Promise<OutputType<T, K, U>>;
54
+ >({ select, className, context, _skipHooks, id, where }: GetObjectOptions<T, K, U>): Promise<OutputType<T, K, U>>;
53
55
  getObjects<
54
56
  K extends keyof T["types"],
55
57
  U extends keyof T["types"][K],
56
58
  W extends keyof T["types"][K]
57
- >({ className, select, context, where, skipHooks, first, offset, order, isGraphQLCall }: GetObjectsOptions<T, K, U, W>): Promise<OutputType<T, K, W>[]>;
59
+ >({ className, select, context, where, _skipHooks, first, offset, order }: GetObjectsOptions<T, K, U, W>): Promise<OutputType<T, K, W>[]>;
58
60
  createObject<
59
61
  K extends keyof T["types"],
60
62
  U extends keyof T["types"][K],
61
63
  W extends keyof T["types"][K]
62
- >({ className, context, data, select, isGraphQLCall }: CreateObjectOptions<T, K, U, W>): Promise<OutputType<T, K, W>>;
64
+ >({ className, context, data, select }: CreateObjectOptions<T, K, U, W>): Promise<OutputType<T, K, W>>;
63
65
  createObjects<
64
66
  K extends keyof T["types"],
65
67
  U extends keyof T["types"][K],
66
68
  W extends keyof T["types"][K],
67
69
  X extends keyof T["types"][K]
68
- >({ data, select, className, context, first, offset, order, isGraphQLCall }: CreateObjectsOptions<T, K, U, W, X>): Promise<OutputType<T, K, W>[]>;
70
+ >({ data, select, className, context, first, offset, order }: CreateObjectsOptions<T, K, U, W, X>): Promise<OutputType<T, K, W>[]>;
69
71
  updateObject<
70
72
  K extends keyof T["types"],
71
73
  U extends keyof T["types"][K],
72
74
  W extends keyof T["types"][K]
73
- >({ id, className, context, data, select, skipHooks, isGraphQLCall }: UpdateObjectOptions<T, K, U, W>): Promise<OutputType<T, K, W>>;
75
+ >({ id, className, context, data, select, _skipHooks }: UpdateObjectOptions<T, K, U, W>): Promise<OutputType<T, K, W>>;
74
76
  updateObjects<
75
77
  K extends keyof T["types"],
76
78
  U extends keyof T["types"][K],
77
79
  W extends keyof T["types"][K],
78
80
  X extends keyof T["types"][K]
79
- >({ className, where, context, select, data, first, offset, order, skipHooks, isGraphQLCall }: UpdateObjectsOptions<T, K, U, W, X>): Promise<OutputType<T, K, W>[]>;
81
+ >({ className, where, context, select, data, first, offset, order, _skipHooks }: UpdateObjectsOptions<T, K, U, W, X>): Promise<OutputType<T, K, W>[]>;
80
82
  deleteObject<
81
83
  K extends keyof T["types"],
82
84
  U extends keyof T["types"][K]
83
- >({ context, className, id, select, isGraphQLCall }: DeleteObjectOptions<T, K, U>): Promise<OutputType<T, K, U>>;
85
+ >({ context, className, id, select }: DeleteObjectOptions<T, K, U>): Promise<OutputType<T, K, U>>;
84
86
  deleteObjects<
85
87
  K extends keyof T["types"],
86
88
  U extends keyof T["types"][K],
87
89
  W extends keyof T["types"][K]
88
- >({ className, context, select, where, first, offset, order, isGraphQLCall }: DeleteObjectsOptions<T, K, U, W>): Promise<OutputType<T, K, W>[]>;
90
+ >({ className, context, select, where, first, offset, order }: DeleteObjectsOptions<T, K, U, W>): Promise<OutputType<T, K, W>[]>;
89
91
  }
90
92
  export {};
@@ -1,10 +1,7 @@
1
- export declare enum DatabaseEnum {
2
- Mongo = "mongo",
1
+ import type { WabeTypes } from "../server";
2
+ import type { DatabaseAdapter } from "./interface";
3
+ export interface DatabaseConfig<T extends WabeTypes> {
4
+ adapter: DatabaseAdapter<T>;
3
5
  }
4
- export interface DatabaseConfig {
5
- type: DatabaseEnum;
6
- url: string;
7
- name: string;
8
- }
9
- export * from "./adapters";
10
- export * from "./controllers";
6
+ export * from "./DatabaseController";
7
+ export * from "./interface";