@@ -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 =
@@ -420,6 +422,10 @@ export class DocumentConventions {
420422 this . _findCollectionNameForObjectLiteral = value ;
421423 }
422424
425+ public getTypeDescriptorByEntity < T extends object > ( entity : T ) : ObjectTypeDescriptor < T > {
426+ return this . getEntityTypeDescriptor ( entity ) ;
427+ }
428+
423429 public getEntityTypeDescriptor < T extends object > ( entity : T ) : ObjectTypeDescriptor < T > {
424430 if ( TypeUtil . isClass ( entity . constructor ) ) {
425431 return entity . constructor as ClassConstructor ;
@@ -492,7 +498,7 @@ export class DocumentConventions {
492498 * Gets the identity property.
493499 */
494500 public getIdentityProperty ( documentType : DocumentType ) : string {
495- const typeDescriptor = this . findEntityType ( documentType ) ;
501+ const typeDescriptor = this . getJsTypeByDocumentType ( documentType ) ;
496502 return this . _registeredIdPropertyNames . get ( typeDescriptor )
497503 || CONSTANTS . Documents . Metadata . ID_PROPERTY ;
498504 }
@@ -594,10 +600,6 @@ export class DocumentConventions {
594600 }
595601 }
596602
597- // TODO:
598- // public get registeredTypeDescriptors() {
599- // return this._registeredTypeDescriptors;
600- // }
601603 public get knownEntityTypesByName ( ) {
602604 return this . _knownEntityTypes ;
603605 }
@@ -606,6 +608,12 @@ export class DocumentConventions {
606608 return Array . from ( this . _knownEntityTypes . values ( ) ) ;
607609 }
608610
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+
609617 public registerEntityType ( entityType : ObjectTypeDescriptor ) : this;
610618 public registerEntityType ( entityType : ObjectTypeDescriptor , name : string ) : this;
611619 public registerEntityType ( entityType : ObjectTypeDescriptor , name ?: string ) : this {
@@ -622,26 +630,36 @@ export class DocumentConventions {
622630 return this ;
623631 }
624632
633+ public tryRegisterJsType ( docType : DocumentType ) : this {
634+ return this . tryRegisterEntityType ( docType ) ;
635+ }
636+
625637 public tryRegisterEntityType ( docType : DocumentType ) : this {
626638 if ( TypeUtil . isObjectTypeDescriptor ( docType ) ) {
627- this . registerEntityType ( docType as ObjectTypeDescriptor ) ;
639+ this . registerJsType ( docType as ObjectTypeDescriptor ) ;
628640 }
629641
630642 return this ;
631643 }
632644
633- public findEntityType < T extends object > ( documentType : DocumentType < T > ) : ObjectTypeDescriptor < T > ;
634- public findEntityType < T extends object > ( typeName : string ) : ObjectTypeDescriptor < T > ;
635- 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 > {
636649 if ( ! docTypeOrTypeName ) {
637650 return null ;
638651 }
639652
640- if ( typeof ( docTypeOrTypeName ) !== "string" ) {
641- 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 ;
642660 }
643661
644- return this . _knownEntityTypes . get ( docTypeOrTypeName ) as ObjectLiteralDescriptor < T > ;
662+ return docTypeOrTypeName as ObjectTypeDescriptor < T > ;
645663 }
646664
647665 public transformObjectKeysToRemoteFieldNameConvention ( obj : object , opts ?: ObjectChangeCaseOptions ) {
0 commit comments