1
- import {
1
+ import type {
2
2
EntityTable ,
3
3
NormalizedIndex ,
4
4
INormalizeDelegate ,
@@ -7,12 +7,22 @@ import {
7
7
import { getCheckLoop } from './getCheckLoop.js' ;
8
8
import { POJODelegate } from '../delegate/Delegate.js' ;
9
9
import { INVALID } from '../denormalize/symbol.js' ;
10
+ import { NormalizedSchema } from '../types.js' ;
10
11
11
12
/** Full normalize() logic for POJO state */
12
13
export class NormalizeDelegate
13
14
extends POJODelegate
14
- implements INormalizeDelegate
15
+ implements INormalizeDelegate , NormalizedSchema < EntityTable , any >
15
16
{
17
+ // declare readonly normalized: NormalizedSchema<E, R>;
18
+ declare result : any ;
19
+ declare readonly entities : EntityTable ;
20
+ declare readonly indexes : {
21
+ [ entityKey : string ] : {
22
+ [ indexName : string ] : { [ lookup : string ] : string } ;
23
+ } ;
24
+ } ;
25
+
16
26
declare readonly entitiesMeta : {
17
27
[ entityKey : string ] : {
18
28
[ pk : string ] : {
@@ -26,8 +36,10 @@ export class NormalizeDelegate
26
36
declare readonly meta : { fetchedAt : number ; date : number ; expiresAt : number } ;
27
37
declare checkLoop : ( entityKey : string , pk : string , input : object ) => boolean ;
28
38
29
- protected newEntities = new Map < string , Map < string , any > > ( ) ;
30
- protected newIndexes = new Map < string , Map < string , any > > ( ) ;
39
+ protected new = {
40
+ entities : new Map < string , Map < string , any > > ( ) ,
41
+ indexes : new Map < string , Map < string , any > > ( ) ,
42
+ } ;
31
43
32
44
constructor (
33
45
state : {
@@ -46,7 +58,15 @@ export class NormalizeDelegate
46
58
actionMeta : { fetchedAt : number ; date : number ; expiresAt : number } ,
47
59
) {
48
60
super ( state ) ;
49
- this . entitiesMeta = state . entitiesMeta ;
61
+ // this.normalized = NormalizedSchema<E, R> = {
62
+ // result: '' as any,
63
+ // entities: { ...state.entities },
64
+ // indexes: { ...state.indexes },
65
+ // entitiesMeta: { ...state.entitiesMeta },
66
+ // };
67
+ this . entities = { ...state . entities } ;
68
+ this . indexes = { ...state . indexes } ;
69
+ this . entitiesMeta = { ...state . entitiesMeta } ;
50
70
this . meta = actionMeta ;
51
71
this . checkLoop = getCheckLoop ( ) ;
52
72
}
@@ -57,8 +77,8 @@ export class NormalizeDelegate
57
77
58
78
protected getNewEntities ( key : string ) : Map < string , any > {
59
79
// first time we come across this type of entity
60
- if ( ! this . newEntities . has ( key ) ) {
61
- this . newEntities . set ( key , new Map ( ) ) ;
80
+ if ( ! this . new . entities . has ( key ) ) {
81
+ this . new . entities . set ( key , new Map ( ) ) ;
62
82
// we will be editing these, so we need to clone them first
63
83
this . entities [ key ] = {
64
84
...this . entities [ key ] ,
@@ -68,15 +88,15 @@ export class NormalizeDelegate
68
88
} ;
69
89
}
70
90
71
- return this . newEntities . get ( key ) as Map < string , any > ;
91
+ return this . new . entities . get ( key ) as Map < string , any > ;
72
92
}
73
93
74
94
protected getNewIndexes ( key : string ) : Map < string , any > {
75
- if ( ! this . newIndexes . has ( key ) ) {
76
- this . newIndexes . set ( key , new Map ( ) ) ;
95
+ if ( ! this . new . indexes . has ( key ) ) {
96
+ this . new . indexes . set ( key , new Map ( ) ) ;
77
97
this . indexes [ key ] = { ...this . indexes [ key ] } ;
78
98
}
79
- return this . newIndexes . get ( key ) as Map < string , any > ;
99
+ return this . new . indexes . get ( key ) as Map < string , any > ;
80
100
}
81
101
82
102
/** Updates an entity using merge lifecycles when it has previously been set */
0 commit comments