@@ -79,11 +79,12 @@ export class DocumentConventions {
7979 this . _identityPartsSeparator = "/" ;
8080
8181 this . _findIdentityPropertyNameFromCollectionName = ( ) => "id" ;
82+
8283 this . _findJsType = ( id : string , doc : object ) => {
8384 const metadata = doc [ CONSTANTS . Documents . Metadata . KEY ] ;
8485 if ( metadata ) {
8586 const jsType = metadata [ CONSTANTS . Documents . Metadata . RAVEN_JS_TYPE ] as string ;
86- return this . _knownEntityTypes . get ( jsType ) || null ;
87+ return this . getJsTypeByDocumentType ( jsType ) ;
8788 }
8889
8990 return null ;
@@ -94,11 +95,12 @@ export class DocumentConventions {
9495 return null ;
9596 }
9697
97- if ( TypeUtil . isFunction ( ctorOrTypeChecker [ "isType" ] ) ) {
98- return ( ctorOrTypeChecker as ObjectLiteralDescriptor ) . name ;
98+ const name = ( ctorOrTypeChecker as ClassConstructor ) . name ;
99+ if ( name === "Object" ) {
100+ return null ;
99101 }
100102
101- return ( ctorOrTypeChecker as ClassConstructor ) . name ;
103+ return name ;
102104 } ;
103105
104106 this . _transformClassCollectionNameToDocumentIdPrefix =
@@ -161,6 +163,15 @@ export class DocumentConventions {
161163 this . _remoteEntityFieldNameConvention = val ;
162164 }
163165
166+ public set useOptimisticConcurrency ( val ) {
167+ this . _assertNotFrozen ( ) ;
168+ this . _useOptimisticConcurrency = val ;
169+ }
170+
171+ public get useOptimisticConcurrency ( ) {
172+ return this . _useOptimisticConcurrency ;
173+ }
174+
164175 public deserializeEntityFromJson ( documentType : ObjectTypeDescriptor , document : object ) : object {
165176 try {
166177 const typeName = documentType ? documentType . name : null ;
@@ -411,6 +422,10 @@ export class DocumentConventions {
411422 this . _findCollectionNameForObjectLiteral = value ;
412423 }
413424
425+ public getTypeDescriptorByEntity < T extends object > ( entity : T ) : ObjectTypeDescriptor < T > {
426+ return this . getEntityTypeDescriptor ( entity ) ;
427+ }
428+
414429 public getEntityTypeDescriptor < T extends object > ( entity : T ) : ObjectTypeDescriptor < T > {
415430 if ( TypeUtil . isClass ( entity . constructor ) ) {
416431 return entity . constructor as ClassConstructor ;
@@ -483,7 +498,7 @@ export class DocumentConventions {
483498 * Gets the identity property.
484499 */
485500 public getIdentityProperty ( documentType : DocumentType ) : string {
486- const typeDescriptor = this . findEntityType ( documentType ) ;
501+ const typeDescriptor = this . getJsTypeByDocumentType ( documentType ) ;
487502 return this . _registeredIdPropertyNames . get ( typeDescriptor )
488503 || CONSTANTS . Documents . Metadata . ID_PROPERTY ;
489504 }
@@ -585,10 +600,6 @@ export class DocumentConventions {
585600 }
586601 }
587602
588- // TODO:
589- // public get registeredTypeDescriptors() {
590- // return this._registeredTypeDescriptors;
591- // }
592603 public get knownEntityTypesByName ( ) {
593604 return this . _knownEntityTypes ;
594605 }
@@ -597,6 +608,12 @@ export class DocumentConventions {
597608 return Array . from ( this . _knownEntityTypes . values ( ) ) ;
598609 }
599610
611+ public registerJsType ( entityType : ObjectTypeDescriptor ) : this;
612+ public registerJsType ( entityType : ObjectTypeDescriptor , name : string ) : this;
613+ public registerJsType ( entityType : ObjectTypeDescriptor , name ?: string ) : this {
614+ return this . registerEntityType ( entityType , name ) ;
615+ }
616+
600617 public registerEntityType ( entityType : ObjectTypeDescriptor ) : this;
601618 public registerEntityType ( entityType : ObjectTypeDescriptor , name : string ) : this;
602619 public registerEntityType ( entityType : ObjectTypeDescriptor , name ?: string ) : this {
@@ -613,26 +630,36 @@ export class DocumentConventions {
613630 return this ;
614631 }
615632
633+ public tryRegisterJsType ( docType : DocumentType ) : this {
634+ return this . tryRegisterEntityType ( docType ) ;
635+ }
636+
616637 public tryRegisterEntityType ( docType : DocumentType ) : this {
617638 if ( TypeUtil . isObjectTypeDescriptor ( docType ) ) {
618- this . registerEntityType ( docType as ObjectTypeDescriptor ) ;
639+ this . registerJsType ( docType as ObjectTypeDescriptor ) ;
619640 }
620641
621642 return this ;
622643 }
623644
624- public findEntityType < T extends object > ( documentType : DocumentType < T > ) : ObjectTypeDescriptor < T > ;
625- public findEntityType < T extends object > ( typeName : string ) : ObjectTypeDescriptor < T > ;
626- public findEntityType < T extends object > ( docTypeOrTypeName : string | DocumentType < T > ) : ObjectTypeDescriptor < T > {
645+ public getJsTypeByDocumentType < T extends object > ( documentType : DocumentType < T > ) : ObjectTypeDescriptor < T > ;
646+ public getJsTypeByDocumentType < T extends object > ( typeName : string ) : ObjectTypeDescriptor < T > ;
647+ public getJsTypeByDocumentType < T extends object > (
648+ docTypeOrTypeName : string | DocumentType < T > ) : ObjectTypeDescriptor < T > {
627649 if ( ! docTypeOrTypeName ) {
628650 return null ;
629651 }
630652
631- if ( typeof ( docTypeOrTypeName ) !== "string" ) {
632- return docTypeOrTypeName as ObjectTypeDescriptor < T > ;
653+ if ( typeof ( docTypeOrTypeName ) === "string" ) {
654+ return this . _knownEntityTypes . get (
655+ docTypeOrTypeName ) as ObjectLiteralDescriptor < T > || null ;
656+ }
657+
658+ if ( docTypeOrTypeName . name === "Object" ) {
659+ return null ;
633660 }
634661
635- return this . _knownEntityTypes . get ( docTypeOrTypeName ) as ObjectLiteralDescriptor < T > ;
662+ return docTypeOrTypeName as ObjectTypeDescriptor < T > ;
636663 }
637664
638665 public transformObjectKeysToRemoteFieldNameConvention ( obj : object , opts ?: ObjectChangeCaseOptions ) {
0 commit comments