@bunbase-ae/js 3.0.1-next.406.cb900dd → 3.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.
- package/package.json +1 -1
- package/src/admin.ts +65 -0
package/package.json
CHANGED
package/src/admin.ts
CHANGED
|
@@ -1307,6 +1307,40 @@ export interface CreateNamedQueryInput {
|
|
|
1307
1307
|
|
|
1308
1308
|
export type UpdateNamedQueryInput = Partial<Omit<CreateNamedQueryInput, "name">>;
|
|
1309
1309
|
|
|
1310
|
+
// ─── Query Advisor (#481) ──────────────────────────────────────────────────────
|
|
1311
|
+
|
|
1312
|
+
export interface QueryAdvisorCandidate {
|
|
1313
|
+
/** Normalized RPC + filter/sort shape — never raw values. */
|
|
1314
|
+
signature: string;
|
|
1315
|
+
tenant_id: string | null;
|
|
1316
|
+
call_count: number;
|
|
1317
|
+
total_duration_ms: number;
|
|
1318
|
+
avg_duration_ms: number;
|
|
1319
|
+
p50_ms: number;
|
|
1320
|
+
p99_ms: number;
|
|
1321
|
+
last_seen: number;
|
|
1322
|
+
cache_hit_estimate: number;
|
|
1323
|
+
projected_savings_ms: number;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
export interface AdvisorListResult {
|
|
1327
|
+
/** False when the advisor is disabled — render the "Enable" CTA. */
|
|
1328
|
+
enabled: boolean;
|
|
1329
|
+
candidates: QueryAdvisorCandidate[];
|
|
1330
|
+
settings: { enabled: boolean; sampleRate: number; retentionDays: number; topK: number };
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
export interface PromoteAdvisorInput {
|
|
1334
|
+
name: string;
|
|
1335
|
+
description?: string | null;
|
|
1336
|
+
sql: string;
|
|
1337
|
+
params?: Record<string, NamedQueryParamDef>;
|
|
1338
|
+
access?: NamedQueryAccessRule;
|
|
1339
|
+
result_cache_ttl_s?: number;
|
|
1340
|
+
/** The originating advisor signature. Stamped so the suggestion disappears. */
|
|
1341
|
+
signature: string;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1310
1344
|
class AdminNamedQueriesClient {
|
|
1311
1345
|
constructor(private readonly http: HttpClient) {}
|
|
1312
1346
|
|
|
@@ -1375,6 +1409,37 @@ class AdminNamedQueriesClient {
|
|
|
1375
1409
|
"/api/v1/admin/queries/install-starter",
|
|
1376
1410
|
);
|
|
1377
1411
|
}
|
|
1412
|
+
|
|
1413
|
+
// ─── Query Advisor (#481) ────────────────────────────────────────────────────
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* List the top hot read-pattern candidates the advisor suggests promoting
|
|
1417
|
+
* into named queries, ranked by projected savings. `enabled` is false (with
|
|
1418
|
+
* an empty list) when the advisor is turned off — surface the "Enable" CTA.
|
|
1419
|
+
*/
|
|
1420
|
+
async advisorList(opts: { tenantId?: string | null } = {}): Promise<AdvisorListResult> {
|
|
1421
|
+
const qs =
|
|
1422
|
+
opts.tenantId !== undefined && opts.tenantId !== null
|
|
1423
|
+
? `?tenant_id=${encodeURIComponent(opts.tenantId)}`
|
|
1424
|
+
: "";
|
|
1425
|
+
return this.http.request<AdvisorListResult>("GET", `/api/v1/admin/queries/advisor${qs}`);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/** Enable the Query Advisor at runtime (existing-deployment opt-in). */
|
|
1429
|
+
async advisorEnable(): Promise<{ enabled: boolean }> {
|
|
1430
|
+
return this.http.request<{ enabled: boolean }>("POST", "/api/v1/admin/queries/advisor/enable");
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
/**
|
|
1434
|
+
* Promote a captured signature into a named query. SQL/params are best-effort
|
|
1435
|
+
* pre-filled by the caller (Studio derives them from the signature). Once
|
|
1436
|
+
* promoted, the advisor stops suggesting that signature.
|
|
1437
|
+
*/
|
|
1438
|
+
async advisorPromote(input: PromoteAdvisorInput): Promise<NamedQuery> {
|
|
1439
|
+
return this.http.request<NamedQuery>("POST", "/api/v1/admin/queries/advisor/promote", {
|
|
1440
|
+
body: input,
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1378
1443
|
}
|
|
1379
1444
|
|
|
1380
1445
|
// ─── Write hooks ──────────────────────────────────────────────────────────────
|