File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
packages/crates-io-msw/models Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ import { mswSession } from './msw-session' ;
12import { user } from './user' ;
23
34export const models = {
5+ mswSession,
46 user,
57} ;
Original file line number Diff line number Diff line change 1+ import { oneOf , primaryKey } from '@mswjs/data' ;
2+
3+ import { applyDefault } from './-utils' ;
4+
5+ /**
6+ * This is a mirage-only model, that is used to keep track of the current
7+ * session and the associated `user` model, because in route handlers we don't
8+ * have access to the cookie data that the actual API is using for these things.
9+ *
10+ * This mock implementation means that there can only ever exist one
11+ * session at a time.
12+ */
13+ export const mswSession = {
14+ id : primaryKey ( Number ) ,
15+ user : oneOf ( 'user' ) ,
16+
17+ preCreate ( attrs , counter ) {
18+ applyDefault ( attrs , 'id' , ( ) => counter ) ;
19+
20+ if ( ! attrs . user ) {
21+ throw new Error ( 'Missing `user` relationship' ) ;
22+ }
23+ } ,
24+ } ;
You can’t perform that action at this time.
0 commit comments