@@ -45,7 +45,6 @@ export class DocumentConventions {
4545 private _frozen : boolean ;
4646 private _originalConfiguration : ClientConfiguration ;
4747 private _idPropertyCache : Map < ObjectTypeDescriptor , string > = new Map ( ) ; //TODO: is it used?
48- // TODO: private _saveEnumsAsIntegers: number;
4948 private _identityPartsSeparator : string ;
5049 private _disableTopologyUpdates : boolean ;
5150
@@ -80,11 +79,12 @@ export class DocumentConventions {
8079 this . _identityPartsSeparator = "/" ;
8180
8281 this . _findIdentityPropertyNameFromCollectionName = ( ) => "id" ;
82+
8383 this . _findJsType = ( id : string , doc : object ) => {
8484 const metadata = doc [ CONSTANTS . Documents . Metadata . KEY ] ;
8585 if ( metadata ) {
8686 const jsType = metadata [ CONSTANTS . Documents . Metadata . RAVEN_JS_TYPE ] as string ;
87- return this . _knownEntityTypes . get ( jsType ) || null ;
87+ return this . getJsTypeByDocumentType ( jsType ) ;
8888 }
8989
9090 return null ;
@@ -95,11 +95,12 @@ export class DocumentConventions {
9595 return null ;
9696 }
9797
98- if ( TypeUtil . isFunction ( ctorOrTypeChecker [ "isType" ] ) ) {
99- return ( ctorOrTypeChecker as ObjectLiteralDescriptor ) . name ;
98+ const name = ( ctorOrTypeChecker as ClassConstructor ) . name ;
99+ if ( name === "Object" ) {
100+ return null ;
100101 }
101102
102- return ( ctorOrTypeChecker as ClassConstructor ) . name ;
103+ return name ;
103104 } ;
104105
105106 this . _transformClassCollectionNameToDocumentIdPrefix =
@@ -421,6 +422,10 @@ export class DocumentConventions {
421422 this . _findCollectionNameForObjectLiteral = value ;
422423 }
423424
425+ public getTypeDescriptorByEntity < T extends object > ( entity : T ) : ObjectTypeDescriptor < T > {
426+ return this . getEntityTypeDescriptor ( entity ) ;
427+ }
428+
424429 public getEntityTypeDescriptor < T extends object > ( entity : T ) : ObjectTypeDescriptor < T > {
425430 if ( TypeUtil . isClass ( entity . constructor ) ) {
426431 return entity . constructor as ClassConstructor ;
@@ -497,7 +502,7 @@ export class DocumentConventions {
497502 * Gets the identity property.
498503 */
499504 public getIdentityProperty ( documentType : DocumentType ) : string {
500- const typeDescriptor = this . findEntityType ( documentType ) ;
505+ const typeDescriptor = this . getJsTypeByDocumentType ( documentType ) ;
501506 return this . _registeredIdPropertyNames . get ( typeDescriptor )
502507 || CONSTANTS . Documents . Metadata . ID_PROPERTY ;
503508 }
@@ -599,10 +604,6 @@ export class DocumentConventions {
599604 }
600605 }
601606
602- // TODO:
603- // public get registeredTypeDescriptors() {
604- // return this._registeredTypeDescriptors;
605- // }
606607 public get knownEntityTypesByName ( ) {
607608 return this . _knownEntityTypes ;
608609 }
@@ -611,6 +612,12 @@ export class DocumentConventions {
611612 return Array . from ( this . _knownEntityTypes . values ( ) ) ;
612613 }
613614
615+ public registerJsType ( entityType : ObjectTypeDescriptor ) : this;
616+ public registerJsType ( entityType : ObjectTypeDescriptor , name : string ) : this;
617+ public registerJsType ( entityType : ObjectTypeDescriptor , name ?: string ) : this {
618+ return this . registerEntityType ( entityType , name ) ;
619+ }
620+
614621 public registerEntityType ( entityType : ObjectTypeDescriptor ) : this;
615622 public registerEntityType ( entityType : ObjectTypeDescriptor , name : string ) : this;
616623 public registerEntityType ( entityType : ObjectTypeDescriptor , name ?: string ) : this {
@@ -627,26 +634,36 @@ export class DocumentConventions {
627634 return this ;
628635 }
629636
637+ public tryRegisterJsType ( docType : DocumentType ) : this {
638+ return this . tryRegisterEntityType ( docType ) ;
639+ }
640+
630641 public tryRegisterEntityType ( docType : DocumentType ) : this {
631642 if ( TypeUtil . isObjectTypeDescriptor ( docType ) ) {
632- this . registerEntityType ( docType as ObjectTypeDescriptor ) ;
643+ this . registerJsType ( docType as ObjectTypeDescriptor ) ;
633644 }
634645
635646 return this ;
636647 }
637648
638- public findEntityType < T extends object > ( documentType : DocumentType < T > ) : ObjectTypeDescriptor < T > ;
639- public findEntityType < T extends object > ( typeName : string ) : ObjectTypeDescriptor < T > ;
640- public findEntityType < T extends object > ( docTypeOrTypeName : string | DocumentType < T > ) : ObjectTypeDescriptor < T > {
649+ public getJsTypeByDocumentType < T extends object > ( documentType : DocumentType < T > ) : ObjectTypeDescriptor < T > ;
650+ public getJsTypeByDocumentType < T extends object > ( typeName : string ) : ObjectTypeDescriptor < T > ;
651+ public getJsTypeByDocumentType < T extends object > (
652+ docTypeOrTypeName : string | DocumentType < T > ) : ObjectTypeDescriptor < T > {
641653 if ( ! docTypeOrTypeName ) {
642654 return null ;
643655 }
644656
645- if ( typeof ( docTypeOrTypeName ) !== "string" ) {
646- return docTypeOrTypeName as ObjectTypeDescriptor < T > ;
657+ if ( typeof ( docTypeOrTypeName ) === "string" ) {
658+ return this . _knownEntityTypes . get (
659+ docTypeOrTypeName ) as ObjectLiteralDescriptor < T > || null ;
660+ }
661+
662+ if ( docTypeOrTypeName . name === "Object" ) {
663+ return null ;
647664 }
648665
649- return this . _knownEntityTypes . get ( docTypeOrTypeName ) as ObjectLiteralDescriptor < T > ;
666+ return docTypeOrTypeName as ObjectTypeDescriptor < T > ;
650667 }
651668
652669 public transformObjectKeysToRemoteFieldNameConvention ( obj : object , opts ?: ObjectChangeCaseOptions ) {
0 commit comments