Skip to content

Commit 3ef1b25

Browse files
authored
msw: Migrate from zod to valibot (#12531)
1 parent 9d2b1d8 commit 3ef1b25

File tree

16 files changed

+156
-149
lines changed

16 files changed

+156
-149
lines changed

packages/crates-io-msw/models/api-token.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { Collection } from '@msw/data';
2-
import { z } from 'zod';
2+
import * as v from 'valibot';
33

44
import { applyDefault } from '../utils/defaults.js';
55
import { preCreateExtension } from '../utils/pre-create-extension.js';
66
import { seededRandom } from '../utils/random.js';
77

8-
const schema = z.object({
9-
id: z.number(),
8+
const schema = v.object({
9+
id: v.number(),
1010

11-
crateScopes: z.array(z.any()).nullable(),
12-
createdAt: z.string(),
13-
endpointScopes: z.array(z.any()).nullable(),
14-
expiredAt: z.string().nullable(),
15-
lastUsedAt: z.string().nullable(),
16-
name: z.string(),
17-
token: z.string(),
18-
revoked: z.boolean(),
11+
crateScopes: v.nullable(v.array(v.any())),
12+
createdAt: v.string(),
13+
endpointScopes: v.nullable(v.array(v.any())),
14+
expiredAt: v.nullable(v.string()),
15+
lastUsedAt: v.nullable(v.string()),
16+
name: v.string(),
17+
token: v.string(),
18+
revoked: v.boolean(),
1919

20-
user: z.any(),
20+
user: v.any(),
2121
});
2222

2323
function preCreate(attrs, counter) {

packages/crates-io-msw/models/category.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { Collection } from '@msw/data';
2-
import { z } from 'zod';
2+
import * as v from 'valibot';
33

44
import { applyDefault } from '../utils/defaults.js';
55
import { preCreateExtension } from '../utils/pre-create-extension.js';
66
import { dasherize } from '../utils/strings.js';
77

8-
const schema = z.object({
9-
id: z.string(),
8+
const schema = v.object({
9+
id: v.string(),
1010

11-
category: z.string(),
12-
slug: z.string(),
13-
description: z.string(),
14-
created_at: z.string(),
15-
crates_cnt: z.number().nullable(),
11+
category: v.string(),
12+
slug: v.string(),
13+
description: v.string(),
14+
created_at: v.string(),
15+
crates_cnt: v.nullable(v.number()),
1616
});
1717

1818
function preCreate(attrs, counter) {

packages/crates-io-msw/models/crate-owner-invitation.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { Collection } from '@msw/data';
2-
import { z } from 'zod';
2+
import * as v from 'valibot';
33

44
import { applyDefault } from '../utils/defaults.js';
55
import { preCreateExtension } from '../utils/pre-create-extension.js';
66

7-
const schema = z.object({
8-
id: z.number(),
7+
const schema = v.object({
8+
id: v.number(),
99

10-
createdAt: z.string(),
11-
expiresAt: z.string(),
12-
token: z.string(),
10+
createdAt: v.string(),
11+
expiresAt: v.string(),
12+
token: v.string(),
1313

14-
crate: z.any(),
15-
invitee: z.any(),
16-
inviter: z.any(),
14+
crate: v.any(),
15+
invitee: v.any(),
16+
inviter: v.any(),
1717
});
1818

1919
function preCreate(attrs, counter) {

packages/crates-io-msw/models/crate-ownership.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { Collection } from '@msw/data';
2-
import { z } from 'zod';
2+
import * as v from 'valibot';
33

44
import { applyDefault } from '../utils/defaults.js';
55
import { preCreateExtension } from '../utils/pre-create-extension.js';
66

7-
const schema = z.object({
8-
id: z.number(),
7+
const schema = v.object({
8+
id: v.number(),
99

10-
emailNotifications: z.boolean(),
10+
emailNotifications: v.boolean(),
1111

12-
crate: z.any(),
13-
team: z.any().nullable(),
14-
user: z.any().nullable(),
12+
crate: v.any(),
13+
team: v.any(),
14+
user: v.any(),
1515
});
1616

1717
function preCreate(attrs, counter) {

packages/crates-io-msw/models/crate.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import { Collection } from '@msw/data';
2-
import { z } from 'zod';
2+
import * as v from 'valibot';
33

44
import { applyDefault } from '../utils/defaults.js';
55
import { preCreateExtension } from '../utils/pre-create-extension.js';
66

7-
const schema = z.object({
8-
// `z.string()` is used to support some of our old fixture that use strings here for some reason
9-
id: z.number().or(z.string()),
7+
const schema = v.object({
8+
// `v.string()` is used to support some of our old fixtures that use strings here for some reason
9+
id: v.union([v.number(), v.string()]),
1010

11-
name: z.string(),
12-
description: z.string(),
13-
downloads: z.number(),
14-
recent_downloads: z.number(),
15-
documentation: z.string().nullable(),
16-
homepage: z.string().nullable(),
17-
repository: z.string().nullable(),
18-
created_at: z.string(),
19-
updated_at: z.string(),
20-
badges: z.array(z.any()),
21-
_extra_downloads: z.array(z.any()),
22-
trustpubOnly: z.boolean(),
11+
name: v.string(),
12+
description: v.string(),
13+
downloads: v.number(),
14+
recent_downloads: v.number(),
15+
documentation: v.nullable(v.string()),
16+
homepage: v.nullable(v.string()),
17+
repository: v.nullable(v.string()),
18+
created_at: v.string(),
19+
updated_at: v.string(),
20+
badges: v.array(v.any()),
21+
_extra_downloads: v.array(v.any()),
22+
trustpubOnly: v.boolean(),
2323

24-
categories: z.array(z.any()).default(() => []),
25-
keywords: z.array(z.any()).default(() => []),
24+
categories: v.optional(v.array(v.any()), () => []),
25+
keywords: v.optional(v.array(v.any()), () => []),
2626
});
2727

2828
function preCreate(attrs, counter) {

packages/crates-io-msw/models/dependency.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { Collection } from '@msw/data';
2-
import { z } from 'zod';
2+
import * as v from 'valibot';
33

44
import { applyDefault } from '../utils/defaults.js';
55
import { preCreateExtension } from '../utils/pre-create-extension.js';
66

77
const REQS = ['^0.1.0', '^2.1.3', '0.3.7', '~5.2.12'];
88

9-
const schema = z.object({
10-
id: z.number(),
9+
const schema = v.object({
10+
id: v.number(),
1111

12-
default_features: z.boolean(),
13-
features: z.array(z.any()),
14-
kind: z.string(),
15-
optional: z.boolean(),
16-
req: z.string(),
17-
target: z.string().nullable(),
12+
default_features: v.boolean(),
13+
features: v.array(v.any()),
14+
kind: v.string(),
15+
optional: v.boolean(),
16+
req: v.string(),
17+
target: v.nullable(v.string()),
1818

19-
crate: z.any(),
20-
version: z.any(),
19+
crate: v.any(),
20+
version: v.any(),
2121
});
2222

2323
function preCreate(attrs, counter) {

packages/crates-io-msw/models/keyword.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Collection } from '@msw/data';
2-
import { z } from 'zod';
2+
import * as v from 'valibot';
33

44
import { applyDefault } from '../utils/defaults.js';
55
import { preCreateExtension } from '../utils/pre-create-extension.js';
66

7-
const schema = z.object({
8-
id: z.string(),
9-
keyword: z.string(),
7+
const schema = v.object({
8+
id: v.string(),
9+
keyword: v.string(),
1010
});
1111

1212
function preCreate(attrs, counter) {

packages/crates-io-msw/models/msw-session.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Collection } from '@msw/data';
2-
import { z } from 'zod';
2+
import * as v from 'valibot';
33

44
import { applyDefault } from '../utils/defaults.js';
55
import { preCreateExtension } from '../utils/pre-create-extension.js';
@@ -12,10 +12,10 @@ import { preCreateExtension } from '../utils/pre-create-extension.js';
1212
* This mock implementation means that there can only ever exist one
1313
* session at a time.
1414
*/
15-
const schema = z.object({
16-
id: z.number(),
15+
const schema = v.object({
16+
id: v.number(),
1717

18-
user: z.any(),
18+
user: v.any(),
1919
});
2020

2121
function preCreate(attrs, counter) {

packages/crates-io-msw/models/team.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { Collection } from '@msw/data';
2-
import { z } from 'zod';
2+
import * as v from 'valibot';
33

44
import { applyDefault } from '../utils/defaults.js';
55
import { preCreateExtension } from '../utils/pre-create-extension.js';
66

77
const ORGS = ['rust-lang', 'emberjs', 'rust-random', 'georust', 'actix'];
88

9-
const schema = z.object({
10-
id: z.number(),
9+
const schema = v.object({
10+
id: v.number(),
1111

12-
name: z.string(),
13-
org: z.string(),
14-
login: z.string(),
15-
url: z.string(),
16-
avatar: z.string(),
12+
name: v.string(),
13+
org: v.string(),
14+
login: v.string(),
15+
url: v.string(),
16+
avatar: v.string(),
1717
});
1818

1919
function preCreate(attrs, counter) {

packages/crates-io-msw/models/trustpub/github-config.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { Collection } from '@msw/data';
2-
import { z } from 'zod';
2+
import * as v from 'valibot';
33

44
import { applyDefault } from '../../utils/defaults.js';
55
import { preCreateExtension } from '../../utils/pre-create-extension.js';
66

7-
const schema = z.object({
8-
id: z.number(),
7+
const schema = v.object({
8+
id: v.number(),
99

10-
crate: z.any().nullable(),
11-
repository_owner: z.string(),
12-
repository_owner_id: z.number(),
13-
repository_name: z.string(),
14-
workflow_filename: z.string(),
15-
environment: z.string().nullable(),
16-
created_at: z.string(),
10+
crate: v.any(),
11+
repository_owner: v.string(),
12+
repository_owner_id: v.number(),
13+
repository_name: v.string(),
14+
workflow_filename: v.string(),
15+
environment: v.nullable(v.string()),
16+
created_at: v.string(),
1717
});
1818

1919
function preCreate(attrs, counter) {

0 commit comments

Comments
 (0)