-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: normalize/denormalize interface updates (#3134)
* enhance: Change Schema.normalize interface * enhance: Update denormalize() args order * enhance: Reorder normalize arguments * enhance: Make argsKey optional in memo.query and memo.buildQueryKey * enhance: Extract EntitySchema type helpers into own file * enhance: Destructure store in normalize()
- Loading branch information
Showing
95 changed files
with
1,830 additions
and
1,805 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
'@data-client/normalizr': minor | ||
'@data-client/endpoint': minor | ||
'@data-client/graphql': minor | ||
'@data-client/rest': minor | ||
'@data-client/react': patch | ||
'@data-client/core': patch | ||
--- | ||
|
||
Change Schema.normalize `visit()` interface; removing non-contextual arguments. | ||
|
||
```ts | ||
/** Visits next data + schema while recurisvely normalizing */ | ||
export interface Visit { | ||
(schema: any, value: any, parent: any, key: any, args: readonly any[]): any; | ||
creating?: boolean; | ||
} | ||
``` | ||
|
||
This results in a 10% normalize performance boost. | ||
|
||
```ts title="Before" | ||
processedEntity[key] = visit( | ||
processedEntity[key], | ||
processedEntity, | ||
key, | ||
this.schema[key], | ||
addEntity, | ||
visitedEntities, | ||
storeEntities, | ||
args, | ||
); | ||
``` | ||
|
||
```ts title="After" | ||
processedEntity[key] = visit( | ||
this.schema[key], | ||
processedEntity[key], | ||
processedEntity, | ||
key, | ||
args, | ||
); | ||
``` | ||
|
||
The information needed from these arguments are provided by [closing](https://en.wikipedia.org/wiki/Closure_(computer_programming)) `visit()` around them. |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
'@data-client/normalizr': minor | ||
'@data-client/endpoint': minor | ||
'@data-client/graphql': minor | ||
'@data-client/rest': minor | ||
'@data-client/react': patch | ||
'@data-client/core': patch | ||
--- | ||
|
||
Change Schema.normalize interface from direct data access, to using functions like `getEntity` | ||
|
||
```ts | ||
interface SchemaSimple { | ||
normalize( | ||
input: any, | ||
parent: any, | ||
key: any, | ||
args: any[], | ||
visit: (schema: any, value: any, parent: any, key: any, args: readonly any[]) => any, | ||
addEntity: (...args: any) => any, | ||
getEntity: (...args: any) => any, | ||
checkLoop: (...args: any) => any, | ||
): any; | ||
} | ||
``` | ||
|
||
We also add `checkLoop()`, which moves some logic in [Entity](https://dataclient.io/rest/api/Entity) | ||
to the core normalize algorithm. | ||
|
||
```ts | ||
/** Returns true if a circular reference is found */ | ||
export interface CheckLoop { | ||
(entityKey: string, pk: string, input: object): boolean; | ||
} | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
'@data-client/normalizr': minor | ||
'@data-client/endpoint': minor | ||
'@data-client/graphql': minor | ||
'@data-client/rest': minor | ||
'@data-client/react': patch | ||
'@data-client/core': patch | ||
--- | ||
|
||
Change Schema.denormalize `unvisit` to have [schema](https://dataclient.io/rest/api/schema) argument first. | ||
|
||
```ts | ||
interface SchemaSimple { | ||
denormalize( | ||
input: {}, | ||
args: readonly any[], | ||
unvisit: (schema: any, input: any) => any, | ||
): T; | ||
} | ||
``` | ||
|
||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
'@data-client/normalizr': minor | ||
--- | ||
|
||
Change normalize() interface | ||
|
||
```ts | ||
function normalize( | ||
schema, | ||
input, | ||
{ date, expiresAt, fetchedAt, args }, | ||
{ entities, indexes, entityMeta }, | ||
); | ||
``` | ||
|
||
#### Usage | ||
|
||
```ts | ||
const { result, entities, indexes, entityMeta } = normalize( | ||
action.endpoint.schema, | ||
payload, | ||
action.meta, | ||
state, | ||
); | ||
``` | ||
|
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
'@data-client/normalizr': minor | ||
--- | ||
|
||
Change denormalize() interface | ||
|
||
```ts | ||
function denormalize(schema, input, entities, args); | ||
``` | ||
|
||
#### Usage | ||
|
||
```ts | ||
const value = denormalize(endpoint.schema, input, state.entities, args); | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@data-client/test': patch | ||
'@data-client/img': patch | ||
'@data-client/ssr': patch | ||
--- | ||
|
||
Expand peerdep support range to include ^0.14.0 |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
'@data-client/normalizr': minor | ||
--- | ||
|
||
Change MemoCache methods interface | ||
|
||
```ts | ||
class MemoCache { | ||
denormalize(schema, input, entities, args): { data, paths }; | ||
query(schema, args, entities, indexes): data; | ||
buildQueryKey(schema, args, entities, indexes): normalized; | ||
} | ||
``` |
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 |
---|---|---|
|
@@ -73,4 +73,4 @@ typings/ | |
# build info | ||
**/tsconfig*.tsbuildinfo | ||
|
||
/codemods/ | ||
/codemods |
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
Oops, something went wrong.