@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.
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // package.json
4
4
  var name = "@onyx.dev/onyx-database";
5
- var version = "2.0.1";
5
+ var version = "2.1.1";
6
6
 
7
7
  // src/config/defaults.ts
8
8
  var DEFAULT_BASE_URL = "https://api.onyx.dev";
@@ -228,7 +228,6 @@ async function resolveConfig(input) {
228
228
  const maxRetries = retryConfig.maxRetries ?? 3;
229
229
  const retryInitialDelayMs = retryConfig.initialDelayMs ?? 300;
230
230
  const missing = [];
231
- if (!databaseId) missing.push("databaseId");
232
231
  if (!apiKey) missing.push("apiKey");
233
232
  if (!apiSecret) missing.push("apiSecret");
234
233
  if (missing.length) {
@@ -2125,20 +2124,38 @@ var AiChatClientImpl = class {
2125
2124
  }
2126
2125
  };
2127
2126
  function createOnyxFacade(resolveConfig2) {
2128
- let cachedCfg = null;
2127
+ const cachedCfgs = /* @__PURE__ */ new Map();
2128
+ const cacheKey = (databaseId, apiKey) => {
2129
+ const id = typeof databaseId === "string" && databaseId.trim() !== "" ? databaseId.trim() : null;
2130
+ const key = typeof apiKey === "string" && apiKey.trim() !== "" ? apiKey.trim() : null;
2131
+ return id && key ? `${id}-${key}` : null;
2132
+ };
2129
2133
  function resolveConfigWithCache(config) {
2130
2134
  const ttl = config?.ttl ?? DEFAULT_CACHE_TTL;
2131
2135
  const now = Date.now();
2132
- if (cachedCfg && cachedCfg.expires > now) {
2133
- return cachedCfg.promise;
2136
+ const hintKey = cacheKey(config?.databaseId, config?.apiKey) ?? "__default__";
2137
+ const existing = cachedCfgs.get(hintKey);
2138
+ if (existing && existing.expires > now) {
2139
+ return existing.promise;
2134
2140
  }
2141
+ if (existing) cachedCfgs.delete(hintKey);
2135
2142
  const { ttl: _ttl, requestLoggingEnabled: _reqLog, responseLoggingEnabled: _resLog, ...rest } = config ?? {};
2136
- const promise = resolveConfig2(rest);
2137
- cachedCfg = { promise, expires: now + ttl };
2143
+ const expires = now + ttl;
2144
+ const promise = resolveConfig2(rest).then((resolved) => {
2145
+ const resolvedKey = cacheKey(resolved.databaseId, resolved.apiKey) ?? hintKey;
2146
+ const nextExpires = Date.now() + ttl;
2147
+ cachedCfgs.set(resolvedKey, { promise, expires: nextExpires });
2148
+ if (resolvedKey !== hintKey) {
2149
+ const stale = cachedCfgs.get(hintKey);
2150
+ if (stale && stale.promise === promise) cachedCfgs.delete(hintKey);
2151
+ }
2152
+ return resolved;
2153
+ });
2154
+ cachedCfgs.set(hintKey, { promise, expires });
2138
2155
  return promise;
2139
2156
  }
2140
2157
  function clearCacheConfig() {
2141
- cachedCfg = null;
2158
+ cachedCfgs.clear();
2142
2159
  }
2143
2160
  return {
2144
2161
  init(config) {