@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
|
@@ -231,7 +231,6 @@ async function resolveConfig(input) {
|
|
|
231
231
|
const maxRetries = retryConfig.maxRetries ?? 3;
|
|
232
232
|
const retryInitialDelayMs = retryConfig.initialDelayMs ?? 300;
|
|
233
233
|
const missing = [];
|
|
234
|
-
if (!databaseId) missing.push("databaseId");
|
|
235
234
|
if (!apiKey) missing.push("apiKey");
|
|
236
235
|
if (!apiSecret) missing.push("apiSecret");
|
|
237
236
|
if (missing.length) {
|
|
@@ -2218,20 +2217,38 @@ var AiChatClientImpl = class {
|
|
|
2218
2217
|
}
|
|
2219
2218
|
};
|
|
2220
2219
|
function createOnyxFacade(resolveConfig2) {
|
|
2221
|
-
|
|
2220
|
+
const cachedCfgs = /* @__PURE__ */ new Map();
|
|
2221
|
+
const cacheKey = (databaseId, apiKey) => {
|
|
2222
|
+
const id = typeof databaseId === "string" && databaseId.trim() !== "" ? databaseId.trim() : null;
|
|
2223
|
+
const key = typeof apiKey === "string" && apiKey.trim() !== "" ? apiKey.trim() : null;
|
|
2224
|
+
return id && key ? `${id}-${key}` : null;
|
|
2225
|
+
};
|
|
2222
2226
|
function resolveConfigWithCache(config) {
|
|
2223
2227
|
const ttl = config?.ttl ?? DEFAULT_CACHE_TTL;
|
|
2224
2228
|
const now = Date.now();
|
|
2225
|
-
|
|
2226
|
-
|
|
2229
|
+
const hintKey = cacheKey(config?.databaseId, config?.apiKey) ?? "__default__";
|
|
2230
|
+
const existing = cachedCfgs.get(hintKey);
|
|
2231
|
+
if (existing && existing.expires > now) {
|
|
2232
|
+
return existing.promise;
|
|
2227
2233
|
}
|
|
2234
|
+
if (existing) cachedCfgs.delete(hintKey);
|
|
2228
2235
|
const { ttl: _ttl, requestLoggingEnabled: _reqLog, responseLoggingEnabled: _resLog, ...rest } = config ?? {};
|
|
2229
|
-
const
|
|
2230
|
-
|
|
2236
|
+
const expires = now + ttl;
|
|
2237
|
+
const promise = resolveConfig2(rest).then((resolved) => {
|
|
2238
|
+
const resolvedKey = cacheKey(resolved.databaseId, resolved.apiKey) ?? hintKey;
|
|
2239
|
+
const nextExpires = Date.now() + ttl;
|
|
2240
|
+
cachedCfgs.set(resolvedKey, { promise, expires: nextExpires });
|
|
2241
|
+
if (resolvedKey !== hintKey) {
|
|
2242
|
+
const stale = cachedCfgs.get(hintKey);
|
|
2243
|
+
if (stale && stale.promise === promise) cachedCfgs.delete(hintKey);
|
|
2244
|
+
}
|
|
2245
|
+
return resolved;
|
|
2246
|
+
});
|
|
2247
|
+
cachedCfgs.set(hintKey, { promise, expires });
|
|
2231
2248
|
return promise;
|
|
2232
2249
|
}
|
|
2233
2250
|
function clearCacheConfig() {
|
|
2234
|
-
|
|
2251
|
+
cachedCfgs.clear();
|
|
2235
2252
|
}
|
|
2236
2253
|
return {
|
|
2237
2254
|
init(config) {
|
|
@@ -2335,7 +2352,7 @@ function normalizeIntrospection(raw) {
|
|
|
2335
2352
|
async function fetchSchemaFromApi(config) {
|
|
2336
2353
|
const db = onyx.init({
|
|
2337
2354
|
baseUrl: config.baseUrl,
|
|
2338
|
-
databaseId: config.databaseId,
|
|
2355
|
+
...config.databaseId ? { databaseId: config.databaseId } : {},
|
|
2339
2356
|
apiKey: config.apiKey,
|
|
2340
2357
|
apiSecret: config.apiSecret,
|
|
2341
2358
|
fetch: config.fetch
|
|
@@ -2358,12 +2375,11 @@ async function generateTypes(options) {
|
|
|
2358
2375
|
if (!schemaInput) {
|
|
2359
2376
|
if (opts.source === "file") throw new Error("Failed to read schema from file");
|
|
2360
2377
|
const cfg = await resolveConfig({});
|
|
2361
|
-
if (!
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
if (!opts.quiet)
|
|
2365
|
-
process__default.default.stderr.write(`[onyx-gen] fetching schema from API for db ${cfg.databaseId}
|
|
2378
|
+
if (!opts.quiet) {
|
|
2379
|
+
const target = cfg.databaseId ? `db ${cfg.databaseId}` : "default database context";
|
|
2380
|
+
process__default.default.stderr.write(`[onyx-gen] fetching schema from API for ${target}
|
|
2366
2381
|
`);
|
|
2382
|
+
}
|
|
2367
2383
|
schemaInput = await fetchSchemaFromApi(cfg);
|
|
2368
2384
|
}
|
|
2369
2385
|
const schema = normalizeIntrospection(schemaInput);
|