@onyx.dev/onyx-database 2.0.1 → 2.1.1

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.
@@ -233,7 +233,6 @@ async function resolveConfig(input) {
233
233
  const maxRetries = retryConfig.maxRetries ?? 3;
234
234
  const retryInitialDelayMs = retryConfig.initialDelayMs ?? 300;
235
235
  const missing = [];
236
- if (!databaseId) missing.push("databaseId");
237
236
  if (!apiKey) missing.push("apiKey");
238
237
  if (!apiSecret) missing.push("apiSecret");
239
238
  if (missing.length) {
@@ -2256,20 +2255,38 @@ var AiChatClientImpl = class {
2256
2255
  }
2257
2256
  };
2258
2257
  function createOnyxFacade(resolveConfig2) {
2259
- let cachedCfg = null;
2258
+ const cachedCfgs = /* @__PURE__ */ new Map();
2259
+ const cacheKey = (databaseId, apiKey) => {
2260
+ const id = typeof databaseId === "string" && databaseId.trim() !== "" ? databaseId.trim() : null;
2261
+ const key = typeof apiKey === "string" && apiKey.trim() !== "" ? apiKey.trim() : null;
2262
+ return id && key ? `${id}-${key}` : null;
2263
+ };
2260
2264
  function resolveConfigWithCache(config) {
2261
2265
  const ttl = config?.ttl ?? DEFAULT_CACHE_TTL;
2262
2266
  const now = Date.now();
2263
- if (cachedCfg && cachedCfg.expires > now) {
2264
- return cachedCfg.promise;
2267
+ const hintKey = cacheKey(config?.databaseId, config?.apiKey) ?? "__default__";
2268
+ const existing = cachedCfgs.get(hintKey);
2269
+ if (existing && existing.expires > now) {
2270
+ return existing.promise;
2265
2271
  }
2272
+ if (existing) cachedCfgs.delete(hintKey);
2266
2273
  const { ttl: _ttl, requestLoggingEnabled: _reqLog, responseLoggingEnabled: _resLog, ...rest } = config ?? {};
2267
- const promise = resolveConfig2(rest);
2268
- cachedCfg = { promise, expires: now + ttl };
2274
+ const expires = now + ttl;
2275
+ const promise = resolveConfig2(rest).then((resolved) => {
2276
+ const resolvedKey = cacheKey(resolved.databaseId, resolved.apiKey) ?? hintKey;
2277
+ const nextExpires = Date.now() + ttl;
2278
+ cachedCfgs.set(resolvedKey, { promise, expires: nextExpires });
2279
+ if (resolvedKey !== hintKey) {
2280
+ const stale = cachedCfgs.get(hintKey);
2281
+ if (stale && stale.promise === promise) cachedCfgs.delete(hintKey);
2282
+ }
2283
+ return resolved;
2284
+ });
2285
+ cachedCfgs.set(hintKey, { promise, expires });
2269
2286
  return promise;
2270
2287
  }
2271
2288
  function clearCacheConfig() {
2272
- cachedCfg = null;
2289
+ cachedCfgs.clear();
2273
2290
  }
2274
2291
  return {
2275
2292
  init(config) {