Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/lib/types/auth_forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export type AuthFormConstraints = {
password?: FieldConstraints;
};

type SchemaShape = Record<string, unknown>;
// Must match the recursive SchemaShape from sveltekit-superforms (dist/jsonSchema/schemaShape.d.ts)
// Record<string, SchemaShape> is semantically equivalent but triggers TS circular reference error.
type SchemaShape = { [K in string]: SchemaShape };

/**
* Represents the state and data structure for authentication forms.
Expand Down
6 changes: 4 additions & 2 deletions src/lib/utils/auth_forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ const createBaseAuthForm = () => ({
pattern: '(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\\d)[a-zA-Z\\d]{8,128}',
},
},
// Primitive fields get empty objects; only arrays/objects produce nested shape nodes.
// See: sveltekit-superforms/src/lib/jsonSchema/schemaShape.ts (_schemaShape)
shape: {
username: { type: 'string' },
password: { type: 'string' },
username: {},
password: {},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
},
});

Expand Down
12 changes: 6 additions & 6 deletions src/test/lib/utils/auth_forms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
authSchema: {
_type: 'ZodObject',
shape: {
username: { type: 'string' },
password: { type: 'string' },
username: {},
password: {},
},
},
}));
Expand Down Expand Up @@ -129,8 +129,8 @@
},
},
shape: {
username: { type: 'string' },
password: { type: 'string' },
username: {},
password: {},
} as unknown,
message: '',
} as unknown as SuperValidated<Record<string, string>, string>;
Expand Down Expand Up @@ -205,8 +205,8 @@

expect(result.form.shape).toBeDefined();
expect(result.form.shape).toEqual({
username: { type: 'string' },
password: { type: 'string' },
username: {},
password: {},
});
});

Expand All @@ -223,7 +223,7 @@
test('expect to use fallback ID generation when crypto.randomUUID is unavailable', async () => {
// Mock crypto.randomUUID to be undefined (preserve other properties)
const prevCrypto = globalThis.crypto;
vi.stubGlobal('crypto', { ...(prevCrypto ?? {}), randomUUID: undefined });

Check warning on line 226 in src/test/lib/utils/auth_forms.test.ts

View workflow job for this annotation

GitHub Actions / build (24)

unicorn(no-useless-fallback-in-spread)

Empty fallbacks in spreads are unnecessary

vi.mocked(superValidate).mockRejectedValueOnce(new Error('Primary strategy failed'));

Expand Down
Loading