Skip to content

Commit 75f0e80

Browse files
authored
Enables strict null checks in SDK (#2360)
1 parent 26688e0 commit 75f0e80

File tree

300 files changed

+1864
-1111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+1864
-1111
lines changed

waspc/ChangeLog.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## Next
4+
5+
### ⚠️ Breaking Changes
6+
7+
- Renamed and split `deserializeAndSanitizeProviderData` to `getProviderData` and `getProviderDataWithPassword` so it's more explicit if the resulting data will contain the hashed password or not.
8+
9+
### 🔧 Small improvements
10+
11+
- Enabled strict null checks for the Wasp SDK which means that some of the return types are more precise now e.g. you'll need to check if some value is `null` before using it.
12+
313
## 0.15.2
414

515
### 🐞 Bug fixes
@@ -79,7 +89,6 @@ To learn more about this feature and how to activate it, check out the [Wasp TS
7989
There are some breaking changes with React Router 6 which will require you to update your code.
8090
Also, the new version of Prisma may cause breaking changes depending on how you're using it.
8191

82-
8392
Read more about breaking changes in the migration guide: https://wasp-lang.dev/docs/migration-guides/migrate-from-0-14-to-0-15 .
8493

8594
### 🐞 Bug fixes

waspc/data/Generator/templates/sdk/wasp/api/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ window.addEventListener('storage', (event) => {
7777
* standard format to be further used by the client. It is also assumed that given API
7878
* error has been formatted as implemented by HttpError on the server.
7979
*/
80-
export function handleApiError(error: AxiosError<{ message?: string, data?: unknown }>): void {
80+
export function handleApiError<T extends AxiosError<{ message?: string, data?: unknown }>>(error: T): T | WaspHttpError {
8181
if (error?.response) {
8282
// If error came from HTTP response, we capture most informative message
8383
// and also add .statusCode information to it.
@@ -88,10 +88,10 @@ export function handleApiError(error: AxiosError<{ message?: string, data?: unkn
8888
// That would require copying HttpError code to web-app also and using it here.
8989
const responseJson = error.response?.data
9090
const responseStatusCode = error.response.status
91-
throw new WaspHttpError(responseStatusCode, responseJson?.message ?? error.message, responseJson)
91+
return new WaspHttpError(responseStatusCode, responseJson?.message ?? error.message, responseJson)
9292
} else {
9393
// If any other error, we just propagate it.
94-
throw error
94+
return error
9595
}
9696
}
9797

waspc/data/Generator/templates/sdk/wasp/auth/email/actions/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export async function login(data: { email: string; password: string }): Promise<
88
const response = await api.post('{= loginPath =}', data);
99
await initSession(response.data.sessionId);
1010
} catch (e) {
11-
handleApiError(e);
11+
throw handleApiError(e);
1212
}
1313
}

waspc/data/Generator/templates/sdk/wasp/auth/email/actions/passwordReset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function requestPasswordReset(data: { email: string; }): Promise<{
77
const response = await api.post('{= requestPasswordResetPath =}', data);
88
return response.data;
99
} catch (e) {
10-
handleApiError(e);
10+
throw handleApiError(e);
1111
}
1212
}
1313

@@ -17,6 +17,6 @@ export async function resetPassword(data: { token: string; password: string; }):
1717
const response = await api.post('{= resetPasswordPath =}', data);
1818
return response.data;
1919
} catch (e) {
20-
handleApiError(e);
20+
throw handleApiError(e);
2121
}
2222
}

waspc/data/Generator/templates/sdk/wasp/auth/email/actions/signup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export async function signup(data: { email: string; password: string }): Promise
77
const response = await api.post('{= signupPath =}', data);
88
return response.data;
99
} catch (e) {
10-
handleApiError(e);
10+
throw handleApiError(e);
1111
}
1212
}

waspc/data/Generator/templates/sdk/wasp/auth/email/actions/verifyEmail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export async function verifyEmail(data: {
99
const response = await api.post('{= verifyEmailPath =}', data)
1010
return response.data
1111
} catch (e) {
12-
handleApiError(e)
12+
throw handleApiError(e)
1313
}
1414
}

waspc/data/Generator/templates/sdk/wasp/auth/forms/internal/common/LoginSignupForm.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ function AdditionalFormFields({
280280
}: {
281281
hookForm: UseFormReturn<LoginSignupFormFields>;
282282
formState: FormState;
283-
additionalSignupFields: AdditionalSignupFields;
283+
additionalSignupFields?: AdditionalSignupFields;
284284
}) {
285285
const {
286286
register,
@@ -293,6 +293,7 @@ function AdditionalFormFields({
293293
Component: any,
294294
props?: React.ComponentProps<ComponentType>
295295
) {
296+
const errorMessage = errors[field.name]?.message;
296297
return (
297298
<FormItemGroup key={field.name}>
298299
<FormLabel>{field.label}</FormLabel>
@@ -301,8 +302,8 @@ function AdditionalFormFields({
301302
{...props}
302303
disabled={isLoading}
303304
/>
304-
{errors[field.name] && (
305-
<FormError>{errors[field.name].message}</FormError>
305+
{errorMessage && (
306+
<FormError>{errorMessage}</FormError>
306307
)}
307308
</FormItemGroup>
308309
);
@@ -341,7 +342,7 @@ function isFieldRenderFn(
341342
}
342343

343344
function areAdditionalFieldsRenderFn(
344-
additionalSignupFields: AdditionalSignupFields
345+
additionalSignupFields?: AdditionalSignupFields
345346
): additionalSignupFields is AdditionalSignupFieldRenderFn {
346347
return typeof additionalSignupFields === 'function'
347348
}

waspc/data/Generator/templates/sdk/wasp/auth/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export default async function login(username: string, password: string): Promise
99

1010
await initSession(response.data.sessionId)
1111
} catch (error) {
12-
handleApiError(error)
12+
throw handleApiError(error)
1313
}
1414
}

waspc/data/Generator/templates/sdk/wasp/auth/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { type AuthUserData } from '../server/auth/user.js';
66

77
import { auth } from "./lucia.js";
88
import type { Session } from "lucia";
9-
import { throwInvalidCredentialsError } from "./utils.js";
9+
import { createInvalidCredentialsError } from "./utils.js";
1010

1111
import { prisma } from 'wasp/server';
1212
import { createAuthUserData } from "../server/auth/user.js";
@@ -66,7 +66,7 @@ async function getAuthUserData(userId: {= userEntityUpper =}['id']): Promise<Aut
6666
})
6767

6868
if (!user) {
69-
throwInvalidCredentialsError()
69+
throw createInvalidCredentialsError()
7070
}
7171

7272
return createAuthUserData(user);

waspc/data/Generator/templates/sdk/wasp/auth/signup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export default async function signup(userFields: { username: string; password: s
55
try {
66
await api.post('{= signupPath =}', userFields)
77
} catch (error) {
8-
handleApiError(error)
8+
throw handleApiError(error)
99
}
1010
}

0 commit comments

Comments
 (0)