@onyx.dev/onyx-database 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2218,20 +2218,38 @@ var AiChatClientImpl = class {
2218
2218
  }
2219
2219
  };
2220
2220
  function createOnyxFacade(resolveConfig2) {
2221
- let cachedCfg = null;
2221
+ const cachedCfgs = /* @__PURE__ */ new Map();
2222
+ const cacheKey = (databaseId, apiKey) => {
2223
+ const id = typeof databaseId === "string" && databaseId.trim() !== "" ? databaseId.trim() : null;
2224
+ const key = typeof apiKey === "string" && apiKey.trim() !== "" ? apiKey.trim() : null;
2225
+ return id && key ? `${id}-${key}` : null;
2226
+ };
2222
2227
  function resolveConfigWithCache(config) {
2223
2228
  const ttl = config?.ttl ?? DEFAULT_CACHE_TTL;
2224
2229
  const now = Date.now();
2225
- if (cachedCfg && cachedCfg.expires > now) {
2226
- return cachedCfg.promise;
2230
+ const hintKey = cacheKey(config?.databaseId, config?.apiKey) ?? "__default__";
2231
+ const existing = cachedCfgs.get(hintKey);
2232
+ if (existing && existing.expires > now) {
2233
+ return existing.promise;
2227
2234
  }
2235
+ if (existing) cachedCfgs.delete(hintKey);
2228
2236
  const { ttl: _ttl, requestLoggingEnabled: _reqLog, responseLoggingEnabled: _resLog, ...rest } = config ?? {};
2229
- const promise = resolveConfig2(rest);
2230
- cachedCfg = { promise, expires: now + ttl };
2237
+ const expires = now + ttl;
2238
+ const promise = resolveConfig2(rest).then((resolved) => {
2239
+ const resolvedKey = cacheKey(resolved.databaseId, resolved.apiKey) ?? hintKey;
2240
+ const nextExpires = Date.now() + ttl;
2241
+ cachedCfgs.set(resolvedKey, { promise, expires: nextExpires });
2242
+ if (resolvedKey !== hintKey) {
2243
+ const stale = cachedCfgs.get(hintKey);
2244
+ if (stale && stale.promise === promise) cachedCfgs.delete(hintKey);
2245
+ }
2246
+ return resolved;
2247
+ });
2248
+ cachedCfgs.set(hintKey, { promise, expires });
2231
2249
  return promise;
2232
2250
  }
2233
2251
  function clearCacheConfig() {
2234
- cachedCfg = null;
2252
+ cachedCfgs.clear();
2235
2253
  }
2236
2254
  return {
2237
2255
  init(config) {