From 825e0124f7d881ca45c17e58d24187faa5264ae5 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 4 Dec 2023 13:18:34 +0100 Subject: [PATCH] resolve import cycle --- src/utilities/caching/caches.ts | 6 ++++++ src/utilities/common/canonicalStringify.ts | 6 ++++-- src/utilities/graphql/print.ts | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/utilities/caching/caches.ts b/src/utilities/caching/caches.ts index 808768fc959..648d92178ce 100644 --- a/src/utilities/caching/caches.ts +++ b/src/utilities/caching/caches.ts @@ -23,6 +23,9 @@ function schedule(cache: CommonCache) { */ export class CleanWeakCache extends WeakCache { + constructor(max: number, dispose?: (value: V) => void) { + super(max, dispose); + } set(key: K, value: V) { schedule(this); return super.set(key, value); @@ -40,6 +43,9 @@ export class CleanWeakCache extends WeakCache { */ export class CleanStrongCache extends StrongCache { + constructor(max: number, dispose?: (value: V) => void) { + super(max, dispose); + } set(key: K, value: V) { schedule(this); return super.set(key, value); diff --git a/src/utilities/common/canonicalStringify.ts b/src/utilities/common/canonicalStringify.ts index 239ec8496aa..8a550cdd400 100644 --- a/src/utilities/common/canonicalStringify.ts +++ b/src/utilities/common/canonicalStringify.ts @@ -1,4 +1,4 @@ -import { CleanStrongCache } from "../../utilities/index.js"; +import { CleanStrongCache, cacheSizes } from "../../utilities/caching/index.js"; /** * Like JSON.stringify, but with object keys always sorted in the same order. @@ -26,7 +26,9 @@ export const canonicalStringify = Object.assign( // Clearing the sortingMap will reclaim all cached memory, without // affecting the logical results of canonicalStringify, but potentially // sacrificing performance until the cache is refilled. - sortingMap = new CleanStrongCache(); + sortingMap = new CleanStrongCache( + cacheSizes.canonicalStringify + ); }, } ); diff --git a/src/utilities/graphql/print.ts b/src/utilities/graphql/print.ts index f8474aa00ec..4615f906271 100644 --- a/src/utilities/graphql/print.ts +++ b/src/utilities/graphql/print.ts @@ -1,6 +1,6 @@ import type { ASTNode } from "graphql"; import { print as origPrint } from "graphql"; -import { CleanWeakCache, cacheSizes } from "../../utilities/index.js"; +import { CleanWeakCache, cacheSizes } from "../caching/index.js"; let printCache!: CleanWeakCache; export const print = Object.assign(