@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/README.md +42 -14
- package/dist/{aggregates-BPpzRHGH.d.cts → aggregates-BFOBBZkW.d.cts} +1 -1
- package/dist/{aggregates-BPpzRHGH.d.ts → aggregates-BFOBBZkW.d.ts} +1 -1
- package/dist/edge.cjs +25 -8
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.cts +2 -2
- package/dist/edge.d.ts +2 -2
- package/dist/edge.js +25 -8
- package/dist/edge.js.map +1 -1
- package/dist/gen/cli/generate.cjs +29 -13
- package/dist/gen/cli/generate.cjs.map +1 -1
- package/dist/index.cjs +25 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +25 -8
- package/dist/index.js.map +1 -1
- package/dist/schema/cli/schema.cjs +24 -7
- package/dist/schema/cli/schema.cjs.map +1 -1
- package/package.json +1 -1
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.
|
|
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
|
-
|
|
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
|
-
|
|
2133
|
-
|
|
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
|
|
2137
|
-
|
|
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
|
-
|
|
2158
|
+
cachedCfgs.clear();
|
|
2142
2159
|
}
|
|
2143
2160
|
return {
|
|
2144
2161
|
init(config) {
|