@@ -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 =
@@ -162,6 +163,15 @@ export class DocumentConventions {
162163 this . _remoteEntityFieldNameConvention = val ;
163164 }
164165
166+ public set useOptimisticConcurrency ( val ) {
167+ this . _assertNotFrozen ( ) ;
168+ this . _useOptimisticConcurrency = val ;
169+ }
170+
171+ public get useOptimisticConcurrency ( ) {
172+ return this . _useOptimisticConcurrency ;
173+ }
174+
165175 public deserializeEntityFromJson ( documentType : ObjectTypeDescriptor , document : object ) : object {
166176 try {
167177 const typeName = documentType ? documentType . name : null ;
@@ -412,6 +422,10 @@ export class DocumentConventions {
412422 this . _findCollectionNameForObjectLiteral = value ;
413423 }
414424
425+ public getTypeDescriptorByEntity < T extends object > ( entity : T ) : ObjectTypeDescriptor < T > {
426+ return this . getEntityTypeDescriptor ( entity ) ;
427+ }
428+
415429 public getEntityTypeDescriptor < T extends object > ( entity : T ) : ObjectTypeDescriptor < T > {
416430 if ( TypeUtil . isClass ( entity . constructor ) ) {
417431 return entity . constructor as ClassConstructor ;
@@ -457,10 +471,6 @@ export class DocumentConventions {
457471 return this ;
458472 }
459473
460- //TODO public registerEntityTypeChecker(typeChecker: ObjectLiteralDescriptor) {
461- // this._registeredTypeDescriptors.push(typeChecker);
462- // }
463-
464474 public registerEntityIdPropertyName ( ctorOrTypeChecker : ObjectTypeDescriptor , idProperty : string ) {
465475 this . _registeredIdPropertyNames . set ( ctorOrTypeChecker , idProperty ) ;
466476 }
@@ -488,7 +498,7 @@ export class DocumentConventions {
488498 * Gets the identity property.
489499 */
490500 public getIdentityProperty ( documentType : DocumentType ) : string {
491- const typeDescriptor = this . findEntityType ( documentType ) ;
501+ const typeDescriptor = this . getJsTypeByDocumentType ( documentType ) ;
492502 return this . _registeredIdPropertyNames . get ( typeDescriptor )
493503 || CONSTANTS . Documents . Metadata . ID_PROPERTY ;
494504 }
@@ -590,10 +600,6 @@ export class DocumentConventions {
590600 }
591601 }
592602
593- // TODO:
594- // public get registeredTypeDescriptors() {
595- // return this._registeredTypeDescriptors;
596- // }
597603 public get knownEntityTypesByName ( ) {
598604 return this . _knownEntityTypes ;
599605 }
@@ -602,6 +608,12 @@ export class DocumentConventions {
602608 return Array . from ( this . _knownEntityTypes . values ( ) ) ;
603609 }
604610
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+
605617 public registerEntityType ( entityType : ObjectTypeDescriptor ) : this;
606618 public registerEntityType ( entityType : ObjectTypeDescriptor , name : string ) : this;
607619 public registerEntityType ( entityType : ObjectTypeDescriptor , name ?: string ) : this {
@@ -618,26 +630,36 @@ export class DocumentConventions {
618630 return this ;
619631 }
620632
633+ public tryRegisterJsType ( docType : DocumentType ) : this {
634+ return this . tryRegisterEntityType ( docType ) ;
635+ }
636+
621637 public tryRegisterEntityType ( docType : DocumentType ) : this {
622638 if ( TypeUtil . isObjectTypeDescriptor ( docType ) ) {
623- this . registerEntityType ( docType as ObjectTypeDescriptor ) ;
639+ this . registerJsType ( docType as ObjectTypeDescriptor ) ;
624640 }
625641
626642 return this ;
627643 }
628644
629- public findEntityType < T extends object > ( documentType : DocumentType < T > ) : ObjectTypeDescriptor < T > ;
630- public findEntityType < T extends object > ( typeName : string ) : ObjectTypeDescriptor < T > ;
631- 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 > {
632649 if ( ! docTypeOrTypeName ) {
633650 return null ;
634651 }
635652
636- if ( typeof ( docTypeOrTypeName ) !== "string" ) {
637- 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 ;
638660 }
639661
640- return this . _knownEntityTypes . get ( docTypeOrTypeName ) as ObjectLiteralDescriptor < T > ;
662+ return docTypeOrTypeName as ObjectTypeDescriptor < T > ;
641663 }
642664
643665 public transformObjectKeysToRemoteFieldNameConvention ( obj : object , opts ?: ObjectChangeCaseOptions ) {
0 commit comments