11import { DataConnectError } from '../api' ;
22
3- import { BackingDataObject , BackingDataObjectJson , FDCScalarValue } from './BackingDataObject' ;
43import { CacheProvider } from './CacheProvider' ;
4+ import { EntityDataObject , BackingDataObjectJson , FDCScalarValue } from './EntityDataObject' ;
55import { ImpactedQueryRefsAccumulator } from './ImpactedQueryRefsAccumulator' ;
66
77export const GLOBAL_ID_KEY = 'cacheId' ;
8- export class StubDataObject {
9- backingData ?: BackingDataObject ;
8+ export class EntityNode {
9+ entityData ?: EntityDataObject ;
1010 scalars : { [ key : string ] : FDCScalarValue } = { } ;
11- references : { [ key : string ] : StubDataObject } = { } ;
11+ references : { [ key : string ] : EntityNode } = { } ;
1212 objectLists : {
13- [ key : string ] : StubDataObject [ ] ;
13+ [ key : string ] : EntityNode [ ] ;
1414 } = { } ;
1515 globalId ?: string ;
1616 impactedQueryRefs = new Set < string > ( ) ;
@@ -24,7 +24,7 @@ export class StubDataObject {
2424 if ( typeof values !== 'object' || Array . isArray ( values ) ) {
2525 throw new DataConnectError (
2626 'invalid-argument' ,
27- 'StubDataObject initialized with non-object value'
27+ 'EntityNode initialized with non-object value'
2828 ) ;
2929 }
3030 if ( values === null ) {
@@ -36,7 +36,7 @@ export class StubDataObject {
3636 typeof values [ GLOBAL_ID_KEY ] === 'string'
3737 ) {
3838 this . globalId = values [ GLOBAL_ID_KEY ] ;
39- this . backingData = cacheProvider . getBdo ( this . globalId ) ;
39+ this . entityData = cacheProvider . getBdo ( this . globalId ) ;
4040 }
4141 for ( const key in values ) {
4242 if ( values . hasOwnProperty ( key ) ) {
@@ -45,14 +45,14 @@ export class StubDataObject {
4545 }
4646 if ( typeof values [ key ] === 'object' ) {
4747 if ( Array . isArray ( values [ key ] ) ) {
48- const objArray : StubDataObject [ ] = [ ] ;
48+ const objArray : EntityNode [ ] = [ ] ;
4949 const scalarArray : Array < NonNullable < FDCScalarValue > > = [ ] ;
5050 for ( const value of values [ key ] ) {
5151 if ( typeof value === 'object' ) {
5252 if ( Array . isArray ( value ) ) {
5353 // TODO: What if it's an array of arrays?
5454 } else {
55- objArray . push ( new StubDataObject ( value , cacheProvider , this . acc ) ) ;
55+ objArray . push ( new EntityNode ( value , cacheProvider , this . acc ) ) ;
5656 }
5757 } else {
5858 scalarArray . push ( value ) ;
@@ -65,8 +65,8 @@ export class StubDataObject {
6565 ) ;
6666 }
6767 if ( scalarArray . length > 0 ) {
68- if ( this . backingData ) {
69- const impactedRefs = this . backingData . updateServerValue ( key , scalarArray ) ;
68+ if ( this . entityData ) {
69+ const impactedRefs = this . entityData . updateServerValue ( key , scalarArray ) ;
7070 this . acc . add ( impactedRefs ) ;
7171 } else {
7272 this . scalars [ key ] = scalarArray ;
@@ -81,17 +81,17 @@ export class StubDataObject {
8181 this . scalars [ key ] = null ;
8282 continue ;
8383 }
84- const stubDataObject = new StubDataObject (
84+ const stubDataObject = new EntityNode (
8585 values [ key ] ,
8686 cacheProvider ,
8787 this . acc
8888 ) ;
8989 this . references [ key ] = stubDataObject ;
9090 }
9191 } else {
92- if ( this . backingData ) {
92+ if ( this . entityData ) {
9393 // TODO: Track only the fields we need for the BDO
94- const impactedRefs = this . backingData . updateServerValue (
94+ const impactedRefs = this . entityData . updateServerValue (
9595 key ,
9696 values [ key ]
9797 ) ;
@@ -102,15 +102,15 @@ export class StubDataObject {
102102 }
103103 }
104104 }
105- if ( this . backingData ) {
106- cacheProvider . updateBackingData ( this . backingData ) ;
105+ if ( this . entityData ) {
106+ cacheProvider . updateBackingData ( this . entityData ) ;
107107 }
108108 }
109109 toJson ( ) : object {
110110 const resultObject : object = { } ;
111- for ( const key in this . backingData ) {
112- if ( this . backingData . hasOwnProperty ( key ) ) {
113- resultObject [ key ] = this . backingData [ key ] ;
111+ for ( const key in this . entityData ) {
112+ if ( this . entityData . hasOwnProperty ( key ) ) {
113+ resultObject [ key ] = this . entityData [ key ] ;
114114 }
115115 }
116116 // Scalars should never have stubdataobjects
@@ -133,23 +133,23 @@ export class StubDataObject {
133133 }
134134 return resultObject ;
135135 }
136- static parseMap ( map : { [ key : string ] : StubDataObject | StubDataObject [ ] | FDCScalarValue } , isSdo = false ) : typeof map {
136+ static parseMap ( map : { [ key : string ] : EntityNode | EntityNode [ ] | FDCScalarValue } , isSdo = false ) : typeof map {
137137 const newMap : typeof map = { } ;
138138 for ( const key in map ) {
139139 if ( map . hasOwnProperty ( key ) ) {
140140 if ( Array . isArray ( map [ key ] ) ) {
141- newMap [ key ] = map [ key ] . map ( value => isSdo ? StubDataObject . fromStorableJson ( value ) : value ) ;
141+ newMap [ key ] = map [ key ] . map ( value => isSdo ? EntityNode . fromStorableJson ( value ) : value ) ;
142142 } else {
143- newMap [ key ] = isSdo ? StubDataObject . fromStorableJson ( map [ key ] as StubDataObjectJson ) : map [ key ] ;
143+ newMap [ key ] = isSdo ? EntityNode . fromStorableJson ( map [ key ] as StubDataObjectJson ) : map [ key ] ;
144144 }
145145 }
146146 }
147147 return newMap ;
148148 }
149- static fromStorableJson ( obj : StubDataObjectJson ) : StubDataObject {
150- const sdo = new StubDataObject ( ) ;
149+ static fromStorableJson ( obj : StubDataObjectJson ) : EntityNode {
150+ const sdo = new EntityNode ( ) ;
151151 if ( obj . backingData ) {
152- sdo . backingData = BackingDataObject . fromStorableJson ( obj . backingData ) ;
152+ sdo . entityData = EntityDataObject . fromStorableJson ( obj . backingData ) ;
153153 }
154154 sdo . acc = new ImpactedQueryRefsAccumulator ( ) ;
155155 sdo . globalId = obj . globalID ;
@@ -159,7 +159,7 @@ export class StubDataObject {
159159 sdo . objectLists = this . parseMap ( obj . objectLists , true ) as typeof sdo . objectLists ;
160160 return sdo ;
161161 }
162- getStorableMap ( map : { [ key : string ] : StubDataObject | StubDataObject [ ] } ) : { [ key : string ] : StubDataObjectJson | StubDataObjectJson [ ] } {
162+ getStorableMap ( map : { [ key : string ] : EntityNode | EntityNode [ ] } ) : { [ key : string ] : StubDataObjectJson | StubDataObjectJson [ ] } {
163163 const newMap : { [ key : string ] : StubDataObjectJson | StubDataObjectJson [ ] } = { } ;
164164 for ( const key in map ) {
165165 if ( map . hasOwnProperty ( key ) ) {
@@ -179,8 +179,8 @@ export class StubDataObject {
179179 references : this . getStorableMap ( this . references ) as StubDataObjectJson [ 'references' ] ,
180180 objectLists : this . getStorableMap ( this . objectLists ) as StubDataObjectJson [ 'objectLists' ]
181181 } ;
182- if ( this . backingData ) {
183- obj . backingData = this . backingData . toStorableJson ( ) ;
182+ if ( this . entityData ) {
183+ obj . backingData = this . entityData . toStorableJson ( ) ;
184184 }
185185 return obj ;
186186 }
0 commit comments