From 0a5c1480c8321affa4f8d38ef6f1195fc3339744 Mon Sep 17 00:00:00 2001 From: Vinicius Date: Mon, 15 Jul 2024 17:52:35 -0300 Subject: [PATCH 1/6] fix(toJSON): get the generic type T for toJSON response related --- packages/realm/src/JSONCacheMap.ts | 6 +++--- packages/realm/src/Object.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/realm/src/JSONCacheMap.ts b/packages/realm/src/JSONCacheMap.ts index 6893461601..47f9e95254 100644 --- a/packages/realm/src/JSONCacheMap.ts +++ b/packages/realm/src/JSONCacheMap.ts @@ -19,8 +19,8 @@ import { DefaultObject, INTERNAL, RealmObject } from "./internal"; /** @internal */ -export class JSONCacheMap extends Map> { - add(object: RealmObject, value: DefaultObject) { +export class JSONCacheMap extends Map> { + add(object: RealmObject, value: T) { const tableKey = object[INTERNAL].table.key; let cachedMap = this.get(tableKey); if (!cachedMap) { @@ -29,7 +29,7 @@ export class JSONCacheMap extends Map> { } cachedMap.set(object._objectKey(), value); } - find(object: RealmObject) { + find(object: RealmObject) { return this.get(object[INTERNAL].table.key)?.get(object._objectKey()); } } diff --git a/packages/realm/src/Object.ts b/packages/realm/src/Object.ts index 4e96620f0e..503b840627 100644 --- a/packages/realm/src/Object.ts +++ b/packages/realm/src/Object.ts @@ -382,9 +382,9 @@ export class RealmObject; /** @internal */ - toJSON(_?: string, cache = new JSONCacheMap()): DefaultObject { + toJSON(_?: string, cache = new JSONCacheMap>()): T | Partial { // Construct a reference-id of table-name & primaryKey if it exists, or fall back to objectId. // Check if current objectId has already processed, to keep object references the same. @@ -392,7 +392,7 @@ export class RealmObject = {}; cache.add(this, result); // Move all enumerable keys to result, triggering any specific toJSON implementation in the process. for (const key in this) { @@ -402,7 +402,7 @@ export class RealmObject Date: Mon, 15 Jul 2024 17:56:45 -0300 Subject: [PATCH 2/6] fix(lint): lint --- packages/realm/src/Object.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/realm/src/Object.ts b/packages/realm/src/Object.ts index 503b840627..4ddf97a226 100644 --- a/packages/realm/src/Object.ts +++ b/packages/realm/src/Object.ts @@ -402,7 +402,7 @@ export class RealmObject Date: Tue, 16 Jul 2024 14:43:05 -0300 Subject: [PATCH 3/6] fix(return): return the generic type T --- packages/realm/src/Object.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/realm/src/Object.ts b/packages/realm/src/Object.ts index 4ddf97a226..29543357f0 100644 --- a/packages/realm/src/Object.ts +++ b/packages/realm/src/Object.ts @@ -382,9 +382,9 @@ export class RealmObject; + toJSON(_?: string, cache?: unknown): T; /** @internal */ - toJSON(_?: string, cache = new JSONCacheMap>()): T | Partial { + toJSON(_?: string, cache = new JSONCacheMap()): T { // Construct a reference-id of table-name & primaryKey if it exists, or fall back to objectId. // Check if current objectId has already processed, to keep object references the same. @@ -392,7 +392,7 @@ export class RealmObject = {}; + const result = {} as T; cache.add(this, result); // Move all enumerable keys to result, triggering any specific toJSON implementation in the process. for (const key in this) { From ff9e13bd5ccb9b92db404547f98847ffe76d29e7 Mon Sep 17 00:00:00 2001 From: Vinicius Date: Wed, 17 Jul 2024 08:20:26 -0300 Subject: [PATCH 4/6] fix(toJSON): return realm ommited types from generic return --- packages/realm/src/Object.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/realm/src/Object.ts b/packages/realm/src/Object.ts index 29543357f0..248dce49b1 100644 --- a/packages/realm/src/Object.ts +++ b/packages/realm/src/Object.ts @@ -382,9 +382,9 @@ export class RealmObject; /** @internal */ - toJSON(_?: string, cache = new JSONCacheMap()): T { + toJSON(_?: string, cache = new JSONCacheMap()): OmittedRealmTypes { // Construct a reference-id of table-name & primaryKey if it exists, or fall back to objectId. // Check if current objectId has already processed, to keep object references the same. From c98e65b7913f0ae82d4ff8ec7bccb1b52253feab Mon Sep 17 00:00:00 2001 From: Vinicius Date: Wed, 17 Jul 2024 08:27:24 -0300 Subject: [PATCH 5/6] feat(toJSON): accept Unmanaged generic type as toJSON return function --- packages/realm/src/Object.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/realm/src/Object.ts b/packages/realm/src/Object.ts index 248dce49b1..d3f20ec465 100644 --- a/packages/realm/src/Object.ts +++ b/packages/realm/src/Object.ts @@ -382,9 +382,9 @@ export class RealmObject; + toJSON(_?: string, cache?: unknown): OmittedRealmTypes>; /** @internal */ - toJSON(_?: string, cache = new JSONCacheMap()): OmittedRealmTypes { + toJSON(_?: string, cache = new JSONCacheMap()): OmittedRealmTypes> { // Construct a reference-id of table-name & primaryKey if it exists, or fall back to objectId. // Check if current objectId has already processed, to keep object references the same. From 1959c4b4347e867116f64b231542ce200c55e23b Mon Sep 17 00:00:00 2001 From: Vinicius Date: Tue, 6 Aug 2024 10:12:58 -0300 Subject: [PATCH 6/6] fix(type): ommited type --- packages/realm/src/Object.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/realm/src/Object.ts b/packages/realm/src/Object.ts index d3f20ec465..248dce49b1 100644 --- a/packages/realm/src/Object.ts +++ b/packages/realm/src/Object.ts @@ -382,9 +382,9 @@ export class RealmObject>; + toJSON(_?: string, cache?: unknown): OmittedRealmTypes; /** @internal */ - toJSON(_?: string, cache = new JSONCacheMap()): OmittedRealmTypes> { + toJSON(_?: string, cache = new JSONCacheMap()): OmittedRealmTypes { // Construct a reference-id of table-name & primaryKey if it exists, or fall back to objectId. // Check if current objectId has already processed, to keep object references the same.