@persql/sdk 0.1.0 → 1.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/README.md +3 -3
- package/dist/{chunk-CDNTQOBK.js → chunk-YZEQFTCX.js} +414 -159
- package/dist/chunk-YZEQFTCX.js.map +1 -0
- package/dist/cli.cjs +411 -156
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +417 -162
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +318 -128
- package/dist/index.d.ts +318 -128
- package/dist/index.js +7 -7
- package/package.json +1 -1
- package/dist/chunk-CDNTQOBK.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -71,8 +71,8 @@ interface PerSQLOptions {
|
|
|
71
71
|
* Run against a local SQLite file (via the `better-sqlite3` peer
|
|
72
72
|
* dependency) instead of the HTTP API. Pass `":memory:"` for an
|
|
73
73
|
* in-memory test database. When set, `token` is not required and
|
|
74
|
-
* network features (`
|
|
75
|
-
*
|
|
74
|
+
* network features (`subscribe`) throw — they have no local
|
|
75
|
+
* equivalent.
|
|
76
76
|
*
|
|
77
77
|
* ```ts
|
|
78
78
|
* const persql = new PerSQL({ local: ":memory:" });
|
|
@@ -199,10 +199,73 @@ interface TableInfo {
|
|
|
199
199
|
name: string;
|
|
200
200
|
rowCount: number;
|
|
201
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Per-statement assertion attached to a `batch` entry. Evaluated
|
|
204
|
+
* server-side inside the same transactionSync as the statement —
|
|
205
|
+
* a violation throws, which rolls a transactional batch back. For
|
|
206
|
+
* non-transactional batches, the rest of the batch does not run.
|
|
207
|
+
*
|
|
208
|
+
* Use this to write defensive multi-step writes without a follow-up
|
|
209
|
+
* read: `UPDATE … WHERE id = ?` with `expect: { rowsWritten: 1 }`
|
|
210
|
+
* fails fast if zero rows match.
|
|
211
|
+
*
|
|
212
|
+
* Shape mirrors `@persql/shared`'s `BatchExpect`. Inlined here so the
|
|
213
|
+
* published npm package has no monorepo-only deps.
|
|
214
|
+
*/
|
|
215
|
+
interface BatchExpect {
|
|
216
|
+
/** Result has exactly this many rows. */
|
|
217
|
+
rows?: number;
|
|
218
|
+
rowsAtLeast?: number;
|
|
219
|
+
rowsAtMost?: number;
|
|
220
|
+
/** Statement wrote exactly this many rows. */
|
|
221
|
+
rowsWritten?: number;
|
|
222
|
+
rowsWrittenAtLeast?: number;
|
|
223
|
+
rowsWrittenAtMost?: number;
|
|
224
|
+
}
|
|
202
225
|
interface Statement {
|
|
203
226
|
sql: string;
|
|
204
227
|
params?: unknown[];
|
|
228
|
+
expect?: BatchExpect;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Returned by `client.me()` — the bearer token's namespace, scope, and
|
|
232
|
+
* current prepaid balance. Agents call this to learn what they're
|
|
233
|
+
* allowed to touch and how much credit remains before the gate returns
|
|
234
|
+
* 402.
|
|
235
|
+
*/
|
|
236
|
+
interface WhoamiInfo {
|
|
237
|
+
namespaceId: string;
|
|
238
|
+
namespaceSlug: string;
|
|
239
|
+
tokenId: string;
|
|
240
|
+
role: "admin" | "readwrite" | "readonly";
|
|
241
|
+
scopes: unknown[];
|
|
242
|
+
tableScope: string[] | null;
|
|
243
|
+
balanceUsdMicros: number | null;
|
|
205
244
|
}
|
|
245
|
+
/** Output of `db.sampleTable(...)`. */
|
|
246
|
+
interface TableSample {
|
|
247
|
+
table: string;
|
|
248
|
+
rowCount: number;
|
|
249
|
+
rows: Array<Record<string, unknown>>;
|
|
250
|
+
columns: Array<{
|
|
251
|
+
name: string;
|
|
252
|
+
type: string;
|
|
253
|
+
pk: boolean;
|
|
254
|
+
notNull: boolean;
|
|
255
|
+
nullCount: number;
|
|
256
|
+
distinctCount: number;
|
|
257
|
+
min: unknown;
|
|
258
|
+
max: unknown;
|
|
259
|
+
}>;
|
|
260
|
+
}
|
|
261
|
+
/** Output of `db.validate(...)`. */
|
|
262
|
+
type ValidateResult = {
|
|
263
|
+
ok: true;
|
|
264
|
+
} | {
|
|
265
|
+
ok: false;
|
|
266
|
+
error: string;
|
|
267
|
+
errorDetail?: SqlErrorDetail;
|
|
268
|
+
};
|
|
206
269
|
declare class PerSQLError extends Error {
|
|
207
270
|
status: number;
|
|
208
271
|
detail?: SqlErrorDetail;
|
|
@@ -249,6 +312,14 @@ declare class PerSQL {
|
|
|
249
312
|
constructor(opts: PerSQLOptions);
|
|
250
313
|
/** Close the local SQLite connection (no-op in HTTP mode). */
|
|
251
314
|
close(): void;
|
|
315
|
+
/**
|
|
316
|
+
* Resolve the bearer token's namespace + live usage. Use this once
|
|
317
|
+
* per agent run so you know the slug to put in URLs and how much
|
|
318
|
+
* monthly budget / prepaid balance remains before a 402.
|
|
319
|
+
*
|
|
320
|
+
* Throws in local mode — no server, nothing to ask.
|
|
321
|
+
*/
|
|
322
|
+
me(): Promise<WhoamiInfo>;
|
|
252
323
|
/**
|
|
253
324
|
* Redeem a handoff token (`phand_…`) for a regular PerSQL client
|
|
254
325
|
* scoped to the handed-off (database, branch, role). Single use:
|
|
@@ -275,10 +346,42 @@ declare class PerSQL {
|
|
|
275
346
|
database(namespace: string, slug: string): PerSQLDatabase;
|
|
276
347
|
/** @internal */
|
|
277
348
|
request<T>(method: "GET" | "POST" | "PUT" | "DELETE", path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
|
|
278
|
-
/** @internal — raw
|
|
279
|
-
requestRaw<T>(method: "PUT" | "POST", path: string, body: ArrayBuffer | Blob | ReadableStream | string, contentType?: string): Promise<T>;
|
|
280
|
-
/** @internal — raw fetch returning the underlying Response (used by blob GET). */
|
|
349
|
+
/** @internal — raw fetch returning the underlying Response. */
|
|
281
350
|
fetchRaw(method: "GET", path: string): Promise<Response>;
|
|
351
|
+
/**
|
|
352
|
+
* File a support ticket directly from your SDK code. Tickets land in
|
|
353
|
+
* the customer console at `/support`; staff reply from the admin
|
|
354
|
+
* app. Useful for agents and background jobs that hit a PerSQL
|
|
355
|
+
* error and want a human to see it.
|
|
356
|
+
*
|
|
357
|
+
* ```ts
|
|
358
|
+
* try {
|
|
359
|
+
* await db.query("UPDATE ...");
|
|
360
|
+
* } catch (err) {
|
|
361
|
+
* await persql.support.createTicket({
|
|
362
|
+
* subject: "Branch merge keeps 500ing",
|
|
363
|
+
* body: "Repro: ...",
|
|
364
|
+
* error: err,
|
|
365
|
+
* });
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
get support(): SupportClient;
|
|
370
|
+
}
|
|
371
|
+
interface CreateSupportTicketOptions {
|
|
372
|
+
subject: string;
|
|
373
|
+
body: string;
|
|
374
|
+
/** Optional error to attach for triage (PerSQLError or any throwable). */
|
|
375
|
+
error?: unknown;
|
|
376
|
+
/** Caller-supplied extras merged into the ticket's diagnostic context. */
|
|
377
|
+
errorContext?: Record<string, unknown>;
|
|
378
|
+
}
|
|
379
|
+
declare class SupportClient {
|
|
380
|
+
private readonly client;
|
|
381
|
+
constructor(client: PerSQL);
|
|
382
|
+
createTicket(opts: CreateSupportTicketOptions): Promise<{
|
|
383
|
+
id: string;
|
|
384
|
+
}>;
|
|
282
385
|
}
|
|
283
386
|
declare class PerSQLDatabase {
|
|
284
387
|
private readonly client;
|
|
@@ -291,6 +394,22 @@ declare class PerSQLDatabase {
|
|
|
291
394
|
batch<T = Record<string, unknown>>(statements: Statement[], options?: BatchOptions): Promise<QueryResult<T>[]>;
|
|
292
395
|
/** Convenience for a transactional batch. */
|
|
293
396
|
transaction<T = Record<string, unknown>>(statements: Statement[], options?: Omit<BatchOptions, "transaction">): Promise<QueryResult<T>[]>;
|
|
397
|
+
/**
|
|
398
|
+
* Mint a short-lived session JWT for an end user. The server (which
|
|
399
|
+
* holds the bearer token) calls this and hands the resulting token
|
|
400
|
+
* to an untrusted client (browser, mobile app, agent run). The
|
|
401
|
+
* client uses the JWT to call this database's published `/p/*`
|
|
402
|
+
* endpoints on behalf of `userId`. TTL defaults to 1 hour; max 24h.
|
|
403
|
+
*/
|
|
404
|
+
createSession(opts: {
|
|
405
|
+
userId: string;
|
|
406
|
+
email?: string;
|
|
407
|
+
expiresIn?: number;
|
|
408
|
+
}): Promise<{
|
|
409
|
+
token: string;
|
|
410
|
+
expiresAt: string;
|
|
411
|
+
expiresIn: number;
|
|
412
|
+
}>;
|
|
294
413
|
/**
|
|
295
414
|
* Engine telemetry — recent /v1/query and /v1/batch calls issued
|
|
296
415
|
* against this database. Backed by the in-DO `_persql_meta_query_log`
|
|
@@ -361,19 +480,39 @@ declare class PerSQLDatabase {
|
|
|
361
480
|
parent: number;
|
|
362
481
|
detail: string;
|
|
363
482
|
}>>;
|
|
483
|
+
/**
|
|
484
|
+
* Parse + bind-check a SQL statement without executing it. Faster
|
|
485
|
+
* and cheaper than running the query just to catch unknown columns
|
|
486
|
+
* or wrong param counts.
|
|
487
|
+
*
|
|
488
|
+
* Returns `{ ok: true }` on success or `{ ok: false, error, errorDetail }`
|
|
489
|
+
* with the same `errorDetail` envelope as `PerSQLError.detail`.
|
|
490
|
+
*/
|
|
491
|
+
validate(sql: string, params?: unknown[]): Promise<ValidateResult>;
|
|
492
|
+
/**
|
|
493
|
+
* Compact text rendering of the database's schema — one line per
|
|
494
|
+
* table with columns, types, PKs, and FK arrows inlined. Designed
|
|
495
|
+
* to stuff into an LLM prompt with minimum token overhead. See
|
|
496
|
+
* `db.describe()` for the structured form.
|
|
497
|
+
*/
|
|
498
|
+
describeCompact(): Promise<string>;
|
|
499
|
+
/**
|
|
500
|
+
* First N rows of a table plus per-column stats (null count,
|
|
501
|
+
* distinct count, min, max). One call to size up an unfamiliar
|
|
502
|
+
* table — replaces a hand-rolled `SELECT *`, `COUNT(*)`, and
|
|
503
|
+
* `PRAGMA table_info` sequence.
|
|
504
|
+
*
|
|
505
|
+
* `n` defaults to 10 and is capped at 100.
|
|
506
|
+
*/
|
|
507
|
+
sampleTable(table: string, opts?: {
|
|
508
|
+
n?: number;
|
|
509
|
+
}): Promise<TableSample>;
|
|
364
510
|
/**
|
|
365
511
|
* Introspect the database schema. Returns one entry per user table
|
|
366
512
|
* with column definitions, suitable for codegen tools (the
|
|
367
513
|
* `persql-codegen` CLI uses this to emit Drizzle schema files).
|
|
368
514
|
*/
|
|
369
515
|
schema(): Promise<DatabaseSchema>;
|
|
370
|
-
/**
|
|
371
|
-
* Per-database semantic search via Cloudflare Vectorize. Use
|
|
372
|
-
* `vectors.upsert` to embed and store rows; `vectors.query` to
|
|
373
|
-
* retrieve the most similar by free text. Embeddings are computed
|
|
374
|
-
* server-side using bge-base-en-v1.5 (768 dim, cosine distance).
|
|
375
|
-
*/
|
|
376
|
-
get vectors(): PerSQLVectors;
|
|
377
516
|
/**
|
|
378
517
|
* Manage preview/PR-style branches of this database. Each branch is
|
|
379
518
|
* its own DO with its own SQLite file; create-or-reset by ref is
|
|
@@ -388,6 +527,12 @@ declare class PerSQLDatabase {
|
|
|
388
527
|
* namespace member decides; on approve, runs the original SQL.
|
|
389
528
|
*/
|
|
390
529
|
get approvals(): PerSQLApprovals;
|
|
530
|
+
/**
|
|
531
|
+
* Manage the require_approval / deny rules for this database. Reads
|
|
532
|
+
* are open to any bearer with read access; create + delete require
|
|
533
|
+
* an admin-role bearer token.
|
|
534
|
+
*/
|
|
535
|
+
get approvalRules(): PerSQLApprovalRules;
|
|
391
536
|
/**
|
|
392
537
|
* Pre-flight a write before running it. `propose()` validates the
|
|
393
538
|
* SQL via EXPLAIN, estimates affected rows, and returns a single-use
|
|
@@ -397,13 +542,6 @@ declare class PerSQLDatabase {
|
|
|
397
542
|
* executionToken in-process.
|
|
398
543
|
*/
|
|
399
544
|
get proposals(): PerSQLProposals;
|
|
400
|
-
/**
|
|
401
|
-
* Per-database BLOB storage backed by R2. Use this for anything
|
|
402
|
-
* larger than a SQLite cell (images, PDFs, model weights). Each
|
|
403
|
-
* database has its own private namespace; keys may be hierarchical
|
|
404
|
-
* (`avatars/2025/foo.jpg`) but never start with `/`.
|
|
405
|
-
*/
|
|
406
|
-
get blob(): PerSQLBlob;
|
|
407
545
|
/**
|
|
408
546
|
* Subscribe to row-changes via WebSocket — the SQL equivalent of
|
|
409
547
|
* Postgres `LISTEN`. The callback fires once per write that
|
|
@@ -426,6 +564,56 @@ declare class PerSQLDatabase {
|
|
|
426
564
|
* server.
|
|
427
565
|
*/
|
|
428
566
|
subscribe(options: SubscribeOptions): () => void;
|
|
567
|
+
/**
|
|
568
|
+
* Long-poll for row-changes on this database. Returns immediately
|
|
569
|
+
* if changes newer than `since` are already buffered; otherwise
|
|
570
|
+
* blocks server-side for up to `waitMs` (default 25s, max 25s).
|
|
571
|
+
*
|
|
572
|
+
* Most callers want `changes()` instead — an async iterator that
|
|
573
|
+
* loops `waitForChanges` forever, surfacing each batch as it
|
|
574
|
+
* arrives.
|
|
575
|
+
*/
|
|
576
|
+
waitForChanges(opts?: {
|
|
577
|
+
since?: number;
|
|
578
|
+
waitMs?: number;
|
|
579
|
+
tables?: string[];
|
|
580
|
+
}): Promise<{
|
|
581
|
+
changes: Array<{
|
|
582
|
+
seq: number;
|
|
583
|
+
ts: number;
|
|
584
|
+
table: string;
|
|
585
|
+
kind: SubscribeChangeKind;
|
|
586
|
+
}>;
|
|
587
|
+
cursor: number;
|
|
588
|
+
restarted: boolean;
|
|
589
|
+
}>;
|
|
590
|
+
/**
|
|
591
|
+
* Async-iterator change feed. Loops `waitForChanges` forever and
|
|
592
|
+
* yields one batch per server response. Pass an `AbortSignal` to
|
|
593
|
+
* stop the loop cleanly.
|
|
594
|
+
*
|
|
595
|
+
* ```ts
|
|
596
|
+
* const ctl = new AbortController();
|
|
597
|
+
* for await (const batch of db.changes({ signal: ctl.signal })) {
|
|
598
|
+
* for (const c of batch.changes) console.log(c.kind, c.table);
|
|
599
|
+
* }
|
|
600
|
+
* ```
|
|
601
|
+
*/
|
|
602
|
+
changes(opts?: {
|
|
603
|
+
since?: number;
|
|
604
|
+
tables?: string[];
|
|
605
|
+
waitMs?: number;
|
|
606
|
+
signal?: AbortSignal;
|
|
607
|
+
}): AsyncGenerator<{
|
|
608
|
+
changes: Array<{
|
|
609
|
+
seq: number;
|
|
610
|
+
ts: number;
|
|
611
|
+
table: string;
|
|
612
|
+
kind: SubscribeChangeKind;
|
|
613
|
+
}>;
|
|
614
|
+
cursor: number;
|
|
615
|
+
restarted: boolean;
|
|
616
|
+
}>;
|
|
429
617
|
/**
|
|
430
618
|
* Returns the callback shape `drizzle-orm/sqlite-proxy` expects.
|
|
431
619
|
* Pair with `drizzle()` from that module to get a typed,
|
|
@@ -444,50 +632,15 @@ declare class PerSQLDatabase {
|
|
|
444
632
|
*/
|
|
445
633
|
driver(): SqliteProxyDriver;
|
|
446
634
|
/**
|
|
447
|
-
* Returns a tool definition
|
|
448
|
-
*
|
|
635
|
+
* Returns a single SQL-query tool definition in every shape PerSQL
|
|
636
|
+
* supports (Anthropic, OpenAI Chat, Vercel AI SDK, Mastra, LangChain,
|
|
637
|
+
* OpenAI Agents SDK). Same input contract as `asTools()` — the only
|
|
638
|
+
* difference is one fat `query` tool instead of typed-per-table tools.
|
|
639
|
+
*
|
|
640
|
+
* Pair the format-specific fields with `runTool` (or use the bundled
|
|
641
|
+
* `execute`/`invoke` callbacks, which call `runTool` internally).
|
|
449
642
|
*/
|
|
450
|
-
asTool(name?: string):
|
|
451
|
-
anthropic: {
|
|
452
|
-
name: string;
|
|
453
|
-
description: string;
|
|
454
|
-
input_schema: {
|
|
455
|
-
type: string;
|
|
456
|
-
properties: {
|
|
457
|
-
sql: {
|
|
458
|
-
type: string;
|
|
459
|
-
description: string;
|
|
460
|
-
};
|
|
461
|
-
params: {
|
|
462
|
-
type: string;
|
|
463
|
-
items: {};
|
|
464
|
-
description: string;
|
|
465
|
-
};
|
|
466
|
-
};
|
|
467
|
-
required: string[];
|
|
468
|
-
};
|
|
469
|
-
};
|
|
470
|
-
openai: {
|
|
471
|
-
type: "function";
|
|
472
|
-
function: {
|
|
473
|
-
name: string;
|
|
474
|
-
description: string;
|
|
475
|
-
parameters: {
|
|
476
|
-
type: string;
|
|
477
|
-
properties: {
|
|
478
|
-
sql: {
|
|
479
|
-
type: string;
|
|
480
|
-
};
|
|
481
|
-
params: {
|
|
482
|
-
type: string;
|
|
483
|
-
items: {};
|
|
484
|
-
};
|
|
485
|
-
};
|
|
486
|
-
required: string[];
|
|
487
|
-
};
|
|
488
|
-
};
|
|
489
|
-
};
|
|
490
|
-
};
|
|
643
|
+
asTool(name?: string): SingleToolBundle;
|
|
491
644
|
/**
|
|
492
645
|
* Executes a tool-call payload returned from the model. Pair with `asTool`.
|
|
493
646
|
*/
|
|
@@ -539,6 +692,20 @@ interface OpenAiTool {
|
|
|
539
692
|
parameters: Record<string, unknown>;
|
|
540
693
|
};
|
|
541
694
|
}
|
|
695
|
+
interface SingleToolBundle {
|
|
696
|
+
/** Anthropic shape — pass as one entry of `tools` to messages.create. */
|
|
697
|
+
anthropic: AnthropicTool;
|
|
698
|
+
/** OpenAI Chat shape — pass as one entry of `tools` to chat.completions.create. */
|
|
699
|
+
openai: OpenAiTool;
|
|
700
|
+
/** Vercel AI SDK shape — spread into `streamText({ tools: { ...db.asTool().aiSdk() } })`. */
|
|
701
|
+
aiSdk: () => Record<string, AiSdkTool>;
|
|
702
|
+
/** Mastra shape — wrap with `createTool()` if you need the Mastra envelope. */
|
|
703
|
+
mastra: () => Record<string, MastraTool>;
|
|
704
|
+
/** LangChain/LangGraph shape — pass to `DynamicStructuredTool` or use `invoke` directly. */
|
|
705
|
+
langchain: () => LangChainTool[];
|
|
706
|
+
/** OpenAI Agents SDK shape — hand to `Agent({ tools: [...] })`. */
|
|
707
|
+
openaiAgents: () => OpenAiAgentsTool[];
|
|
708
|
+
}
|
|
542
709
|
interface DatabaseToolBundle {
|
|
543
710
|
/** Tool definitions in Anthropic shape — pass as `tools` to messages.create. */
|
|
544
711
|
anthropic: AnthropicTool[];
|
|
@@ -622,71 +789,6 @@ interface SubscribeOptions {
|
|
|
622
789
|
onError?: (error: Error) => void;
|
|
623
790
|
onClose?: () => void;
|
|
624
791
|
}
|
|
625
|
-
interface BlobListItem {
|
|
626
|
-
key: string;
|
|
627
|
-
sizeBytes: number;
|
|
628
|
-
etag: string;
|
|
629
|
-
uploadedAt: string;
|
|
630
|
-
contentType?: string;
|
|
631
|
-
}
|
|
632
|
-
interface BlobListResponse {
|
|
633
|
-
items: BlobListItem[];
|
|
634
|
-
truncated: boolean;
|
|
635
|
-
cursor?: string;
|
|
636
|
-
}
|
|
637
|
-
declare class PerSQLBlob {
|
|
638
|
-
private readonly client;
|
|
639
|
-
private readonly namespace;
|
|
640
|
-
private readonly slug;
|
|
641
|
-
constructor(client: PerSQL, namespace: string, slug: string);
|
|
642
|
-
/** Upload a blob. Body can be ArrayBuffer, Blob, ReadableStream, or string. */
|
|
643
|
-
put(key: string, body: ArrayBuffer | Blob | ReadableStream | string, opts?: {
|
|
644
|
-
contentType?: string;
|
|
645
|
-
}): Promise<{
|
|
646
|
-
key: string;
|
|
647
|
-
sizeBytes: number;
|
|
648
|
-
etag: string;
|
|
649
|
-
}>;
|
|
650
|
-
/** Fetch a blob. Returns null if missing. */
|
|
651
|
-
get(key: string): Promise<Response | null>;
|
|
652
|
-
/** Delete a blob. */
|
|
653
|
-
delete(key: string): Promise<void>;
|
|
654
|
-
/** List blobs by prefix. */
|
|
655
|
-
list(opts?: {
|
|
656
|
-
prefix?: string;
|
|
657
|
-
cursor?: string;
|
|
658
|
-
limit?: number;
|
|
659
|
-
}): Promise<BlobListResponse>;
|
|
660
|
-
}
|
|
661
|
-
interface VectorUpsertItem {
|
|
662
|
-
id: string;
|
|
663
|
-
text: string;
|
|
664
|
-
metadata?: Record<string, string | number | boolean>;
|
|
665
|
-
}
|
|
666
|
-
interface VectorMatch {
|
|
667
|
-
id: string;
|
|
668
|
-
score: number;
|
|
669
|
-
metadata: Record<string, unknown>;
|
|
670
|
-
}
|
|
671
|
-
declare class PerSQLVectors {
|
|
672
|
-
private readonly client;
|
|
673
|
-
private readonly namespace;
|
|
674
|
-
private readonly slug;
|
|
675
|
-
constructor(client: PerSQL, namespace: string, slug: string);
|
|
676
|
-
/** Embed and upsert up to 100 items in one call. */
|
|
677
|
-
upsert(items: VectorUpsertItem[]): Promise<{
|
|
678
|
-
count: number;
|
|
679
|
-
}>;
|
|
680
|
-
/** Top-K nearest neighbours by free-text query. */
|
|
681
|
-
query(text: string, opts?: {
|
|
682
|
-
topK?: number;
|
|
683
|
-
filter?: Record<string, string | number | boolean>;
|
|
684
|
-
}): Promise<VectorMatch[]>;
|
|
685
|
-
/** Delete vectors by id. Up to 1000 ids per call. */
|
|
686
|
-
delete(ids: string[]): Promise<{
|
|
687
|
-
count: number;
|
|
688
|
-
}>;
|
|
689
|
-
}
|
|
690
792
|
/**
|
|
691
793
|
* Database row as returned by /v1 list/upsert branch responses.
|
|
692
794
|
* Mirrors the `Database` DTO from @persql/shared but kept narrow on
|
|
@@ -770,11 +872,67 @@ interface ProposeOptions {
|
|
|
770
872
|
params?: unknown[];
|
|
771
873
|
ttlSec?: number;
|
|
772
874
|
}
|
|
875
|
+
interface ApprovalStatus {
|
|
876
|
+
status: "pending" | "approved" | "denied";
|
|
877
|
+
hits: ApprovalRuleHit[];
|
|
878
|
+
createdAt: string;
|
|
879
|
+
expiresAt: string;
|
|
880
|
+
decidedAt: string | null;
|
|
881
|
+
}
|
|
882
|
+
interface PollApprovalOptions {
|
|
883
|
+
/** Default 2000ms. */
|
|
884
|
+
intervalMs?: number;
|
|
885
|
+
/** Default 10 minutes. */
|
|
886
|
+
timeoutMs?: number;
|
|
887
|
+
/** Cancellation signal. */
|
|
888
|
+
signal?: AbortSignal;
|
|
889
|
+
}
|
|
890
|
+
interface SubscribeApprovalOptions {
|
|
891
|
+
onApprovalRequired?: (event: ApprovalEvent) => void;
|
|
892
|
+
onApprovalResolved?: (event: ApprovalEvent) => void;
|
|
893
|
+
/** Poll interval. Default 5000ms. */
|
|
894
|
+
intervalMs?: number;
|
|
895
|
+
/** Cancellation signal. */
|
|
896
|
+
signal?: AbortSignal;
|
|
897
|
+
/** Logged-by-default error sink. */
|
|
898
|
+
onError?: (err: Error) => void;
|
|
899
|
+
}
|
|
900
|
+
interface ApprovalEvent {
|
|
901
|
+
approvalToken: string;
|
|
902
|
+
status: "pending" | "approved" | "denied";
|
|
903
|
+
hits: ApprovalRuleHit[];
|
|
904
|
+
}
|
|
773
905
|
declare class PerSQLApprovals {
|
|
774
906
|
private readonly client;
|
|
775
907
|
private readonly namespace;
|
|
776
908
|
private readonly slug;
|
|
909
|
+
private readonly seen;
|
|
777
910
|
constructor(client: PerSQL, namespace: string, slug: string);
|
|
911
|
+
/**
|
|
912
|
+
* Look up the status of an approval token without consuming it. The
|
|
913
|
+
* bearer must match the one that minted the original 403; cross-bearer
|
|
914
|
+
* lookup returns 403.
|
|
915
|
+
*/
|
|
916
|
+
get(approvalToken: string): Promise<ApprovalStatus>;
|
|
917
|
+
/**
|
|
918
|
+
* Poll until a reviewer decides (or the token expires). Resolves with
|
|
919
|
+
* the final status — `approved` is your green light for `redeem()`.
|
|
920
|
+
*/
|
|
921
|
+
poll(approvalToken: string, opts?: PollApprovalOptions): Promise<ApprovalStatus>;
|
|
922
|
+
/**
|
|
923
|
+
* Long-running poll subscription for new approval events on this
|
|
924
|
+
* database. Returns a `stop()` handle. Webhook delivery is the push
|
|
925
|
+
* path (events `approval_required` / `approval_resolved`); subscribe
|
|
926
|
+
* is the pull fallback for clients that can't host a webhook.
|
|
927
|
+
*
|
|
928
|
+
* Today this iterates over a known set of tokens supplied by the
|
|
929
|
+
* caller; an SDK-only client that wants discovery should pair this
|
|
930
|
+
* with the webhook path. Pass tokens you already hold (e.g. from a
|
|
931
|
+
* prior `ApprovalRequiredError`).
|
|
932
|
+
*/
|
|
933
|
+
subscribe(tokens: string[], opts: SubscribeApprovalOptions): {
|
|
934
|
+
stop: () => void;
|
|
935
|
+
};
|
|
778
936
|
/**
|
|
779
937
|
* Redeem an approved approvalToken. The bearer must be the same one
|
|
780
938
|
* that minted it, and the request must target the same database.
|
|
@@ -782,6 +940,33 @@ declare class PerSQLApprovals {
|
|
|
782
940
|
*/
|
|
783
941
|
redeem<T = Record<string, unknown>>(approvalToken: string): Promise<QueryResult<T> | QueryResult<T>[]>;
|
|
784
942
|
}
|
|
943
|
+
interface ApprovalRule {
|
|
944
|
+
id: string;
|
|
945
|
+
databaseId: string;
|
|
946
|
+
tableGlob: string;
|
|
947
|
+
action: "require_approval" | "deny";
|
|
948
|
+
note: string | null;
|
|
949
|
+
createdById: string;
|
|
950
|
+
createdAt: string;
|
|
951
|
+
}
|
|
952
|
+
interface CreateApprovalRuleInput {
|
|
953
|
+
tableGlob: string;
|
|
954
|
+
action: "require_approval" | "deny";
|
|
955
|
+
note?: string;
|
|
956
|
+
}
|
|
957
|
+
declare class PerSQLApprovalRules {
|
|
958
|
+
private readonly client;
|
|
959
|
+
private readonly namespace;
|
|
960
|
+
private readonly slug;
|
|
961
|
+
constructor(client: PerSQL, namespace: string, slug: string);
|
|
962
|
+
list(): Promise<ApprovalRule[]>;
|
|
963
|
+
/** Requires an admin-role bearer token. */
|
|
964
|
+
create(input: CreateApprovalRuleInput): Promise<ApprovalRule>;
|
|
965
|
+
/** Requires an admin-role bearer token. */
|
|
966
|
+
delete(ruleId: string): Promise<{
|
|
967
|
+
deleted: true;
|
|
968
|
+
}>;
|
|
969
|
+
}
|
|
785
970
|
declare class PerSQLProposals {
|
|
786
971
|
private readonly client;
|
|
787
972
|
private readonly namespace;
|
|
@@ -792,6 +977,11 @@ declare class PerSQLProposals {
|
|
|
792
977
|
* rows, and returns a single-use `executionToken` valid for 10 min
|
|
793
978
|
* (override with `ttlSec`, max 1 hour). Nothing is mutated until
|
|
794
979
|
* `apply()` is called.
|
|
980
|
+
*
|
|
981
|
+
* Local mode keeps the token in-process: single-use still holds, but
|
|
982
|
+
* `estimatedAffectedRows` is always `null` (no server estimator) and a
|
|
983
|
+
* stale/unknown token throws a plain `Error` rather than the HTTP
|
|
984
|
+
* 404/403 of the server path.
|
|
795
985
|
*/
|
|
796
986
|
propose(sql: string, opts?: ProposeOptions): Promise<ProposalPlan>;
|
|
797
987
|
/**
|
|
@@ -923,4 +1113,4 @@ type SqliteProxyDriver = (sql: string, params: unknown[], method: "all" | "run"
|
|
|
923
1113
|
rows: unknown;
|
|
924
1114
|
}>;
|
|
925
1115
|
|
|
926
|
-
export { type AiSdkTool, type AnthropicTool, ApprovalRequiredError, type ApprovalRuleHit, type
|
|
1116
|
+
export { type AiSdkTool, type AnthropicTool, type ApprovalEvent, ApprovalRequiredError, type ApprovalRule, type ApprovalRuleHit, type ApprovalStatus, type BatchExpect, type BatchOptions, type BranchInfo, type BranchMergeMode, type BranchMergeOptions, type BranchMergePlanStep, type BranchMergeResult, type BranchUpsertOptions, type ClaimBranchOptions, type ClaimedBranch, type CreateApprovalRuleInput, type CreateSupportTicketOptions, type DatabaseSchema, type DatabaseToolBundle, type DescribeBundle, type HandoffClaim, type LangChainTool, type MastraTool, type OpenAiAgentsTool, type OpenAiTool, PerSQL, PerSQLApprovalRules, PerSQLApprovals, PerSQLBranches, PerSQLDatabase, PerSQLError, type PerSQLOptions, PerSQLProposals, type PollApprovalOptions, type ProposalPlan, type ProposeOptions, type QueryLogEntry, type QueryOptions, type QueryResult, RateLimitError, type RawQueryResult, type SchemaDoctorReport, type SchemaSearchResponse, type SingleToolBundle, type SqlErrorDetail, type SqlErrorKind, type SqliteProxyDriver, type Statement, type SubscribeApprovalOptions, type SubscribeChange, type SubscribeChangeKind, type SubscribeOptions, SupportClient, type TableInfo, type TableSample, type ValidateResult, type WhoamiInfo };
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ApprovalRequiredError,
|
|
3
3
|
PerSQL,
|
|
4
|
+
PerSQLApprovalRules,
|
|
4
5
|
PerSQLApprovals,
|
|
5
|
-
PerSQLBlob,
|
|
6
6
|
PerSQLBranches,
|
|
7
7
|
PerSQLDatabase,
|
|
8
8
|
PerSQLError,
|
|
9
9
|
PerSQLProposals,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from "./chunk-
|
|
10
|
+
RateLimitError,
|
|
11
|
+
SupportClient
|
|
12
|
+
} from "./chunk-YZEQFTCX.js";
|
|
13
13
|
export {
|
|
14
14
|
ApprovalRequiredError,
|
|
15
15
|
PerSQL,
|
|
16
|
+
PerSQLApprovalRules,
|
|
16
17
|
PerSQLApprovals,
|
|
17
|
-
PerSQLBlob,
|
|
18
18
|
PerSQLBranches,
|
|
19
19
|
PerSQLDatabase,
|
|
20
20
|
PerSQLError,
|
|
21
21
|
PerSQLProposals,
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
RateLimitError,
|
|
23
|
+
SupportClient
|
|
24
24
|
};
|
|
25
25
|
//# sourceMappingURL=index.js.map
|