Skip to content

Commit

Permalink
docs: Add changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jul 8, 2024
1 parent d8527a2 commit c1bf17d
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 39 deletions.
32 changes: 32 additions & 0 deletions .changeset/purple-cougars-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
'@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 + Schema.denormalize interface

```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;
denormalize(
input: {},
args: readonly any[],
unvisit: (schema: any, input: any) => any,
): T;
}
```

This results in a 10% normalize performance boost.
26 changes: 26 additions & 0 deletions .changeset/rich-frogs-move.md
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,
);
```

15 changes: 15 additions & 0 deletions .changeset/sharp-birds-tie.md
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);
```
7 changes: 7 additions & 0 deletions .changeset/silly-eagles-knock.md
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
13 changes: 13 additions & 0 deletions .changeset/smooth-houses-tickle.md
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;
}
```
12 changes: 4 additions & 8 deletions docs/rest/api/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Article extends Entity {
import { normalize } from '@data-client/normalizr';

const args = [{ id: '123' }];
const normalizedData = normalize(originalData, Article, args);
const normalizedData = normalize(Article, originalData, args);
```

Now, `normalizedData` will create a single serializable source of truth for all entities:
Expand Down Expand Up @@ -175,8 +175,8 @@ Now, `normalizedData` will create a single serializable source of truth for all
import { denormalize } from '@data-client/normalizr';

const denormalizedData = denormalize(
normalizedData.result,
Article,
normalizedData.result,
normalizedData.entities,
args,
);
Expand Down Expand Up @@ -218,14 +218,14 @@ import { MemoCache } from '@data-client/normalizr';
const memo = new MemoCache();

const { data, paths } = memo.denormalize(
normalizedData.result,
Article,
normalizedData.result,
normalizedData.entities,
args,
);
const { data: data2 } = memo.denormalize(
normalizedData.result,
Article,
normalizedData.result,
normalizedData.entities,
args,
);
Expand All @@ -242,11 +242,7 @@ is an Array of paths of all entities included in the result.
`memo.query()` allows denormalizing [Queryable](#queryable) based on args alone, rather than a normalized input.

```ts
// key is just any serialization of args
const key = JSON.stringify(args);

const data = memo.query(
key,
Article,
args,
normalizedData.entities,
Expand Down
2 changes: 1 addition & 1 deletion packages/img/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@data-client/endpoint": "^0.13.4"
},
"peerDependencies": {
"@data-client/react": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0",
"@data-client/react": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^0.14.0",
"@types/react": "^16.14.0 || ^17.0.0 || ^18.0.0-0 || ^19.0.0",
"react": "^16.14.0 || ^17.0.0 || ^18.0.0-0 || ^19.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/normalizr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Article extends Entity {
import { normalize } from '@data-client/normalizr';

const args = [{ id: '123' }];
const normalizedData = normalize(originalData, Article, args);
const normalizedData = normalize(Article, originalData, args);
```

Now, `normalizedData` will create a single serializable source of truth for all entities:
Expand Down
44 changes: 22 additions & 22 deletions packages/normalizr/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
- [Union](#uniondefinition-schemaattribute)
- [Values](#valuesdefinition-schemaattribute)

## `normalize(data, schema)`
## `normalize(schema, data)`

Normalizes input data per the schema definition provided.

- `data`: **required** Input JSON (or plain JS object) data that needs normalization.
- `schema`: **required** A schema definition
- `data`: **required** Input JSON (or plain JS object) data that needs normalization.

### Usage

Expand All @@ -23,9 +23,10 @@ import { schema } from '@data-client/endpoint';
import { normalize } from '@data-client/normalizr';

const myData = { users: [{ id: 1 }, { id: 2 }] };
const user = new schema.Entity('users');
const mySchema = { users: [user] };
const normalizedData = normalize(myData, mySchema);
class User { id = 0 }
const userSchema = new schema.Entity(User);
const mySchema = { users: [userSchema] };
const normalizedData = normalize(mySchema, myData);
```

### Output
Expand All @@ -34,20 +35,18 @@ const normalizedData = normalize(myData, mySchema);
{
result: { users: [ 1, 2 ] },
entities: {
users: {
User: {
'1': { id: 1 },
'2': { id: 2 }
}
}
}
```

## `denormalize(schema, input, entities): [denormalized, foundAllEntities]`
## `denormalize(schema, input, entities)`

Denormalizes an input based on schema and provided entities from a plain object or Immutable data. The reverse of `normalize`.

_Special Note:_ Be careful with denormalization. Prematurely reverting your data to large, nested objects could cause performance impacts in React (and other) applications.

If your schema and data have recursive references, only the first instance of an entity will be given. Subsequent references will be returned as the `id` provided.

- `schema`: **required** A schema definition that was used to get the value for `input`.
Expand All @@ -60,17 +59,18 @@ If your schema and data have recursive references, only the first instance of an
import { schema } from '@data-client/endpoint';
import { denormalize } from '@data-client/normalizr';

const user = new schema.Entity('users');
const mySchema = { users: [user] };
const entities = { users: { '1': { id: 1 }, '2': { id: 2 } } };
const denormalizedData = denormalize({ users: [1, 2] }, mySchema, entities);
class User { id = 0 }
const userSchema = new schema.Entity(User);
const mySchema = { users: [userSchema] };
const entities = { User: { '1': { id: 1 }, '2': { id: 2 } } };
const denormalizedData = denormalize(mySchema, { users: [1, 2] }, entities);
```

### Output

```js
{
users: [{ id: 1 }, { id: 2 }];
users: [User { id: 1 }, User { id: 2 }];
}
```

Expand Down Expand Up @@ -100,21 +100,21 @@ To describe a simple array of a singular entity type:
import { schema } from '@data-client/endpoint';

const data = [{ id: '123', name: 'Jim' }, { id: '456', name: 'Jane' }];
const userSchema = new schema.Entity('users');
const userSchema = new schema.Entity(class User {id='';name='';});

const userListSchema = new schema.Array(userSchema);
// or use shorthand syntax:
const userListSchema = [userSchema];

const normalizedData = normalize(data, userListSchema);
const normalizedData = normalize(userListSchema, data);
```

#### Output

```js
{
entities: {
users: {
User: {
'123': { id: '123', name: 'Jim' },
'456': { id: '456', name: 'Jane' }
}
Expand All @@ -134,8 +134,8 @@ import { schema } from '@data-client/endpoint';

const data = [{ id: 1, type: 'admin' }, { id: 2, type: 'user' }];

const userSchema = new schema.Entity('users');
const adminSchema = new schema.Entity('admins');
const userSchema = new schema.Entity(class User {id='';type='user';});
const adminSchema = new schema.Entity(class Admin {id='';type='admin';});
const myArray = new schema.Array(
{
admins: adminSchema,
Expand All @@ -144,16 +144,16 @@ const myArray = new schema.Array(
(input, parent, key) => `${input.type}s`
);

const normalizedData = normalize(data, myArray);
const normalizedData = normalize(myArray, data);
```

#### Output

```js
{
entities: {
admins: { '1': { id: 1, type: 'admin' } },
users: { '2': { id: 2, type: 'user' } }
Admin: { '1': { id: 1, type: 'admin' } },
User: { '2': { id: 2, type: 'user' } }
},
result: [
{ id: 1, schema: 'admins' },
Expand Down
4 changes: 2 additions & 2 deletions packages/ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
"@babel/runtime": "^7.17.0"
},
"peerDependencies": {
"@data-client/react": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0",
"@data-client/redux": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0",
"@data-client/react": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^0.14.0",
"@data-client/redux": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^0.14.0",
"@types/react": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"next": ">=12.0.0",
"react": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"@testing-library/react-native": "^12.0.1"
},
"peerDependencies": {
"@data-client/react": "^0.12.15 || ^0.13.0",
"@data-client/react": "^0.12.15 || ^0.13.0 || ^0.14.0",
"@testing-library/react-hooks": "^8.0.0",
"@types/react": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-0 || ^19.0.0",
"@types/react-dom": "*",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3201,7 +3201,7 @@ __metadata:
"@types/node": "npm:^20.0.0"
"@types/react": "npm:^18.0.30"
peerDependencies:
"@data-client/react": ^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0
"@data-client/react": ^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^0.14.0
"@types/react": ^16.14.0 || ^17.0.0 || ^18.0.0-0 || ^19.0.0
react: ^16.14.0 || ^17.0.0 || ^18.0.0-0 || ^19.0.0
peerDependenciesMeta:
Expand Down Expand Up @@ -3290,8 +3290,8 @@ __metadata:
react-dom: "npm:^18.2.0"
redux: "npm:^5.0.0"
peerDependencies:
"@data-client/react": ^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0
"@data-client/redux": ^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0
"@data-client/react": ^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^0.14.0
"@data-client/redux": ^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^0.14.0
"@types/react": ^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
next: ">=12.0.0"
react: ^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
Expand Down Expand Up @@ -3321,7 +3321,7 @@ __metadata:
"@types/react-test-renderer": "npm:^18"
jest: "npm:^29.5.0"
peerDependencies:
"@data-client/react": ^0.12.15 || ^0.13.0
"@data-client/react": ^0.12.15 || ^0.13.0 || ^0.14.0
"@testing-library/react-hooks": ^8.0.0
"@types/react": ^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-0 || ^19.0.0
"@types/react-dom": "*"
Expand Down

0 comments on commit c1bf17d

Please sign in to comment.