Skip to content

Commit 98e8249

Browse files
authored
feat!: v1.0.0 (#317)
1 parent ec69782 commit 98e8249

File tree

186 files changed

+9643
-21584
lines changed

Some content is hidden

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

186 files changed

+9643
-21584
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
github: mswjs
2-
open_collective: mswjs
2+
open_collective: mswjs

.github/workflows/ci.yml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,38 @@ on:
44
push:
55
branches: [main]
66
pull_request:
7-
branches: [main]
8-
97
workflow_dispatch:
108

119
jobs:
12-
build:
10+
test:
1311
runs-on: ubuntu-latest
1412
steps:
1513
- name: Checkout
16-
uses: actions/checkout@v2
14+
uses: actions/checkout@v4
15+
16+
- name: Set up pnpm
17+
uses: pnpm/action-setup@v4
18+
with:
19+
version: 9.14.0
20+
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 22
25+
cache: 'pnpm'
1726

1827
- name: Install dependencies
19-
run: yarn install --frozen-lockfile
28+
run: pnpm install
2029

2130
- name: Install browsers
22-
run: yarn playwright install
23-
24-
- name: Environment (versions)
25-
run: |
26-
echo "node: $(node -v)"
27-
echo "npm: $(npm -v)"
28-
echo "typescript: $(npm ls typescript)"
29-
echo "tsc: $(tsc -v)"
31+
run: pnpm exec playwright install chromium --with-deps
3032

3133
- name: Build
32-
run: yarn build
34+
run: pnpm build
35+
36+
- name: Tests (Node.js)
37+
run: pnpm test:node
3338

34-
- name: Tests
35-
run: yarn test
39+
- name: Tests (browser)
40+
run: pnpm test:browser
3641

37-
- name: Tests (typings)
38-
run: yarn test:ts

.github/workflows/release.yml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,46 @@ name: release
33
on:
44
schedule:
55
- cron: '0 23 * * *'
6-
76
workflow_dispatch:
87

98
jobs:
10-
release:
9+
publish:
1110
runs-on: ubuntu-latest
1211
steps:
1312
- name: Checkout
14-
uses: actions/checkout@v2
13+
uses: actions/checkout@v4
1514
with:
1615
fetch-depth: 0
1716
token: ${{ secrets.GH_ADMIN_TOKEN }}
1817

19-
- name: Setup Git
20-
run: |
21-
git config --local user.name "kettanaito"
22-
git config --local user.email "[email protected]"
18+
- name: Set up pnpm
19+
uses: pnpm/action-setup@v4
20+
with:
21+
version: 9.14.0
22+
23+
- name: Set up Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: 22
27+
cache: 'pnpm'
2328

2429
- name: Install dependencies
25-
run: yarn install --frozen-lockfile
30+
run: pnpm install
2631

2732
- name: Install browsers
28-
run: yarn playwright install
33+
run: pnpm exec playwright install chromium --with-deps
34+
35+
- name: Build
36+
run: pnpm build
37+
38+
- name: Tests (Node.js)
39+
run: pnpm test:node
40+
41+
- name: Tests (browser)
42+
run: pnpm test:browser
2943

30-
- name: Release
31-
run: yarn release
44+
- name: Publish
45+
run: pnpm publish
3246
env:
3347
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
3448
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
*.DS_Store
12
node_modules
3+
build
24
lib
3-
*.log
5+
dist
6+
test-results
7+
./tests/.tmp/**
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"semi": false,
3-
"singleQuote": true,
43
"arrowParens": "always",
5-
"trailingComma": "all"
4+
"trailingComma": "all",
5+
"singleQuote": true
66
}

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

LICENSE

Lines changed: 0 additions & 9 deletions
This file was deleted.

MIGRATING.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Migrating
2+
3+
## v0 → v1
4+
5+
Version 1.0 is a huge overhaul of the library to address some of the long-standing design issues and missing features. Please take your time to read through the [updated README](./README.md) to get familiar with the new concepts and APIs.
6+
7+
When migrating from v0.x.x, please consult the guide below regarding the breaking changes to the library.
8+
9+
### Terminology
10+
11+
A few changes in the terminology to consider to make this migration guide easier to parse:
12+
13+
- Model → Collection;
14+
- Entry → Record;
15+
- Relationship → Relation.
16+
17+
### Package name
18+
19+
The library has been migrated to a new package name—`@msw/data`.
20+
21+
```diff
22+
-npm i @mswjs/data
23+
+npm i @msw/data
24+
```
25+
26+
### Deprecated: `factory`
27+
28+
The model factory has been deprecated in favor of granular collections of data.
29+
30+
```diff
31+
-const db = factory({ user: {} })
32+
+const users = new Collection({ schema })
33+
```
34+
35+
### Describing data
36+
37+
The proprietary syntax of describing data has been deprecated in favor of the [Standard Schema](https://standardschema.dev/) for describing your data.
38+
39+
```diff
40+
-factory({
41+
- firstName: () => 'John',
42+
- lastName: () => 'Maverick'
43+
-})
44+
+new Collection({
45+
+ schema: z.object({
46+
+ firstName: z.string(),
47+
+ lastName: z.string()
48+
+ })
49+
+})
50+
```
51+
52+
> Although the example above is using [Zod](https://zod.dev/), you can use any Standard Schema-compatible schema library.
53+
54+
### Deprecated: `primaryKey`
55+
56+
The concept of a primary key has been deprecated entirely. You do not have to provide primary keys when describing your collections. You can query records by any properties.
57+
58+
### Default values
59+
60+
You can provide default values to the properies of your collection using the respective syntax of your schema library of choice. For example, here's how you list default values in Zod:
61+
62+
```ts
63+
const users = new Collection({
64+
schema: z.object({
65+
subscribed: z.boolean().default(false)
66+
})
67+
})
68+
69+
await users.create() // { subscribed: false }
70+
```
71+
72+
### Deprecated: `nullable`
73+
74+
The `nullable` utility has been deprecated. Use your schema library of choice to describe nullable properties.
75+
76+
### Deprecated: operators
77+
78+
Operators like `equals`, `in`, `lgt`, etc. have been deprecated in favor of _queries_. You can express conditions for your records via literal values as well as function predicates.
79+
80+
```ts
81+
// Find the first user with "id" equal to 1.
82+
users.findFirst(q => q.where({ id: 1 }))
83+
84+
// Find all users whose last name is longer than 5 letters.
85+
users.findMany(
86+
q => q.where({ lastName: lastName => lastName.length > 5 })
87+
)
88+
```
89+
90+
> Learn more about [Querying](./README.md#querying).
91+
92+
### Relations
93+
94+
The `oneOf` and `manyOf` utilities has been deprecated. Use the `.defineRelations()` method on your collections to define relations between collections.
95+
96+
```ts
97+
const userSchema = z.object({
98+
id: z.number(),
99+
get posts() {
100+
return z.array(postSchema)
101+
}
102+
})
103+
const postSchema = z.object({
104+
title: z.string(),
105+
get author() {
106+
return userSchema
107+
}
108+
})
109+
110+
const users = new Collection({ schema: userSchema })
111+
const posts = new Collection({ schema: postSchema })
112+
113+
users.defineRelations(({ many }) => ({
114+
posts: many(posts)
115+
}))
116+
117+
posts.defineRelations(({ one }) => ({
118+
author: one(users)
119+
}))
120+
```
121+
122+
> Learn more about [Relations](./README.md#relations).
123+
124+
### Collocated updates
125+
126+
You can now collocate updates of owner and foreign records in a relation by simply changing the foreign record's values as a part of the owner update.
127+
128+
```ts
129+
const posts = new Collection({ schema: postSchema })
130+
const revisions = new Collection({ schema: revisionSchema })
131+
132+
posts.defineRelations(({ one }) => ({
133+
revision: one(revisions)
134+
}))
135+
136+
await posts.update(q => q.where({ id: 'post-1' }), {
137+
data(post) {
138+
post.title = 'Renamed post'
139+
post.revision.updatedAt = Date.now()
140+
}
141+
})
142+
```
143+
144+
> The library will automatically translte the `updateAt` change of the reference revision into an implicit update.
145+
146+
### Deprecated: `.toHandlers()`
147+
148+
The `.toHandlers()` method has been deprecated. Generating request handlers is no longer a responsibility of this library. Instead, it should be possible via [Source](https://github.com/mswjs/source) (follow [this issue](https://github.com/mswjs/source/issues/80) for progress).

0 commit comments

Comments
 (0)