This repository has been archived by the owner on Mar 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to dynamically set nested schema type (#415)
* Add ability to dynamically set nested schema type * Re-use type * Use blocks * Add response type * Update types, add tests Co-authored-by: Paul Armstrong <[email protected]>
- Loading branch information
1 parent
3246f91
commit a61b8cf
Showing
6 changed files
with
127 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
import { normalize, schema } from '../index' | ||
|
||
const data = { | ||
/* ...*/ | ||
}; | ||
type Response = { | ||
users: Array<{ id: string }> | ||
} | ||
const data: Response = { users: [ { id: 'foo' } ] }; | ||
const user = new schema.Entity('users'); | ||
|
||
const responseSchema = new schema.Object({ users: new schema.Array(user) }); | ||
const normalizedData = normalize(data, responseSchema); | ||
{ | ||
const responseSchema = new schema.Object({ users: new schema.Array(user) }); | ||
const normalizedData = normalize(data, responseSchema); | ||
} | ||
|
||
const responseSchemaAlt = { users: new schema.Array(user) }; | ||
const normalizedDataAlt = normalize(data, responseSchemaAlt); | ||
{ | ||
const responseSchema = new schema.Object<Response>({ users: (response: Response) => new schema.Array(user) }); | ||
const normalizedData = normalize(data, responseSchema); | ||
} | ||
|
||
{ | ||
const responseSchema = { users: new schema.Array(user) }; | ||
const normalizedData = normalize(data, responseSchema); | ||
} |