Skip to content

Commit 4939456

Browse files
authored
enhance: state.entityMeta -> state.entitiesMeta (#3451)
1 parent 49a5fd3 commit 4939456

Some content is hidden

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

52 files changed

+184
-175
lines changed

.changeset/sixty-monkeys-open.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@data-client/normalizr': minor
3+
'@data-client/react': minor
4+
'@data-client/core': minor
5+
---
6+
7+
state.entityMeta -> state.entitiesMeta

__tests__/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ export function mockEventHandlers() {
2525
export function createEntityMeta(
2626
entities: Record<string, Record<string, any>>,
2727
) {
28-
const entityMeta: any = {};
28+
const entitiesMeta: any = {};
2929
for (const k in entities) {
30-
entityMeta[k] = {};
30+
entitiesMeta[k] = {};
3131
for (const pk in entities[k]) {
32-
entityMeta[k][pk] = { date: 0, expiresAt: 0 };
32+
entitiesMeta[k][pk] = { date: 0, expiresAt: 0 };
3333
}
3434
}
35-
return entityMeta;
35+
return entitiesMeta;
3636
}

docs/core/api/DataProvider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface State<T> {
5454
readonly errorPolicy?: 'hard' | 'soft' | undefined;
5555
};
5656
};
57-
readonly entityMeta: {
57+
readonly entitiesMeta: {
5858
readonly [entityKey: string]: {
5959
readonly [pk: string]: {
6060
readonly date: number;

docs/core/api/types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ interface State<T> {
5757
readonly errorPolicy?: 'hard' | 'soft' | undefined;
5858
};
5959
};
60-
readonly entityMeta: {
60+
readonly entitiesMeta: {
6161
readonly [entityKey: string]: {
6262
readonly [pk: string]: {
6363
readonly date: number;

docs/rest/api/schema.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Now, `normalizedData` will create a single serializable source of truth for all
142142
},
143143
// contents excluded for brevity
144144
indexes,
145-
entityMeta,
145+
entitiesMeta,
146146
}
147147
```
148148

examples/normalizr-relationships/output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"1",
8282
"2"
8383
],
84-
"entityMeta": {
84+
"entitiesMeta": {
8585
"User": {
8686
"123": {
8787
"expiresAt": null,

packages/core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function useSuspense(endpoint, ...args)
4848
cacheResults,
4949
state.indexes,
5050
state.entities,
51-
state.entityMeta,
51+
state.entitiesMeta,
5252
meta,
5353
key,
5454
]);

packages/core/src/controller/Controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ export default class Controller<
563563
// note: isInvalid can only be true if shouldQuery is true
564564
if (isInvalid) expiresAt = 1;
565565
// fallback to entity expiry time
566-
else expiresAt = entityExpiresAt(paths, state.entityMeta);
566+
else expiresAt = entityExpiresAt(paths, state.entitiesMeta);
567567
}
568568

569569
return {
@@ -664,7 +664,7 @@ export default class Controller<
664664
// earliest expiry dictates age
665665
function entityExpiresAt(
666666
paths: EntityPath[],
667-
entityMeta: {
667+
entitiesMeta: {
668668
readonly [entityKey: string]: {
669669
readonly [pk: string]: {
670670
readonly date: number;
@@ -676,7 +676,7 @@ function entityExpiresAt(
676676
) {
677677
let expiresAt = Infinity;
678678
for (const { pk, key } of paths) {
679-
const entityExpiry = entityMeta[key]?.[pk]?.expiresAt;
679+
const entityExpiry = entitiesMeta[key]?.[pk]?.expiresAt;
680680
// expiresAt will always resolve to false with any comparison
681681
if (entityExpiry < expiresAt) expiresAt = entityExpiry;
682682
}

packages/core/src/controller/__tests__/Controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('Controller', () => {
4646
endpoints: {
4747
[fetchKey]: result,
4848
},
49-
entityMeta: createEntityMeta(entities),
49+
entitiesMeta: createEntityMeta(entities),
5050
meta: {
5151
[fetchKey]: {
5252
date: Date.now(),
@@ -85,7 +85,7 @@ describe('Controller', () => {
8585
endpoints: {
8686
[fetchKey]: result,
8787
},
88-
entityMeta: createEntityMeta(entities),
88+
entitiesMeta: createEntityMeta(entities),
8989
meta: {
9090
[fetchKey]: {
9191
date: 0,

packages/core/src/controller/__tests__/getResponse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('Controller.getResponse()', () => {
152152
const state = {
153153
...initialState,
154154
entities,
155-
entityMeta: {
155+
entitiesMeta: {
156156
Tacos: {
157157
1: { date: 1000000, expiresAt: 1100000, fetchedAt: 1000000 },
158158
2: { date: 2000000, expiresAt: 2100000, fetchedAt: 2000000 },

0 commit comments

Comments
 (0)