@persql/sdk 1.0.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/dist/{chunk-ZRZANHPI.js → chunk-YZEQFTCX.js} +60 -3
- package/dist/chunk-YZEQFTCX.js.map +1 -0
- package/dist/cli.cjs +59 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +59 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-ZRZANHPI.js.map +0 -1
package/dist/cli.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -802,6 +802,55 @@ var PerSQLDatabase = class {
|
|
|
802
802
|
}
|
|
803
803
|
};
|
|
804
804
|
}
|
|
805
|
+
/**
|
|
806
|
+
* Long-poll for row-changes on this database. Returns immediately
|
|
807
|
+
* if changes newer than `since` are already buffered; otherwise
|
|
808
|
+
* blocks server-side for up to `waitMs` (default 25s, max 25s).
|
|
809
|
+
*
|
|
810
|
+
* Most callers want `changes()` instead — an async iterator that
|
|
811
|
+
* loops `waitForChanges` forever, surfacing each batch as it
|
|
812
|
+
* arrives.
|
|
813
|
+
*/
|
|
814
|
+
async waitForChanges(opts = {}) {
|
|
815
|
+
if (this.client.local) {
|
|
816
|
+
throw new Error(
|
|
817
|
+
"PerSQL: waitForChanges requires the DO change ring \u2014 not available in local mode."
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
const qs = new URLSearchParams();
|
|
821
|
+
if (typeof opts.since === "number") qs.set("since", String(opts.since));
|
|
822
|
+
if (typeof opts.waitMs === "number") qs.set("waitMs", String(opts.waitMs));
|
|
823
|
+
if (opts.tables && opts.tables.length > 0) qs.set("tables", opts.tables.join(","));
|
|
824
|
+
const q = qs.toString();
|
|
825
|
+
return this.client.request(
|
|
826
|
+
"GET",
|
|
827
|
+
`/v1/db/${this.namespace}/${this.slug}/changes${q ? `?${q}` : ""}`
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Async-iterator change feed. Loops `waitForChanges` forever and
|
|
832
|
+
* yields one batch per server response. Pass an `AbortSignal` to
|
|
833
|
+
* stop the loop cleanly.
|
|
834
|
+
*
|
|
835
|
+
* ```ts
|
|
836
|
+
* const ctl = new AbortController();
|
|
837
|
+
* for await (const batch of db.changes({ signal: ctl.signal })) {
|
|
838
|
+
* for (const c of batch.changes) console.log(c.kind, c.table);
|
|
839
|
+
* }
|
|
840
|
+
* ```
|
|
841
|
+
*/
|
|
842
|
+
async *changes(opts = {}) {
|
|
843
|
+
let cursor = opts.since ?? 0;
|
|
844
|
+
while (!opts.signal?.aborted) {
|
|
845
|
+
const batch = await this.waitForChanges({
|
|
846
|
+
since: cursor,
|
|
847
|
+
waitMs: opts.waitMs,
|
|
848
|
+
tables: opts.tables
|
|
849
|
+
});
|
|
850
|
+
cursor = batch.cursor;
|
|
851
|
+
yield batch;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
805
854
|
/**
|
|
806
855
|
* Returns the callback shape `drizzle-orm/sqlite-proxy` expects.
|
|
807
856
|
* Pair with `drizzle()` from that module to get a typed,
|
|
@@ -838,7 +887,7 @@ var PerSQLDatabase = class {
|
|
|
838
887
|
* `execute`/`invoke` callbacks, which call `runTool` internally).
|
|
839
888
|
*/
|
|
840
889
|
asTool(name = "persql_query") {
|
|
841
|
-
const description = `Run a SQL query against the PerSQL database "${this.namespace}/${this.slug}".
|
|
890
|
+
const description = `Run a SQL query against the PerSQL database "${this.namespace}/${this.slug}". A single result is capped at 100,000 rows and the query errors above that \u2014 add a LIMIT for large tables. Use parameter binding (?) to avoid injection.`;
|
|
842
891
|
const inputSchema = {
|
|
843
892
|
type: "object",
|
|
844
893
|
properties: {
|
|
@@ -849,7 +898,10 @@ var PerSQLDatabase = class {
|
|
|
849
898
|
description: "Positional parameters for the SQL statement"
|
|
850
899
|
}
|
|
851
900
|
},
|
|
852
|
-
required: ["sql"]
|
|
901
|
+
required: ["sql"],
|
|
902
|
+
// OpenAI strict function-calling rejects a schema without this; the
|
|
903
|
+
// per-table asTools() schemas already set it. Keep them consistent.
|
|
904
|
+
additionalProperties: false
|
|
853
905
|
};
|
|
854
906
|
const execute = (input) => this.runTool({
|
|
855
907
|
sql: String(input.sql ?? ""),
|
|
@@ -1808,6 +1860,11 @@ var PerSQLProposals = class {
|
|
|
1808
1860
|
* rows, and returns a single-use `executionToken` valid for 10 min
|
|
1809
1861
|
* (override with `ttlSec`, max 1 hour). Nothing is mutated until
|
|
1810
1862
|
* `apply()` is called.
|
|
1863
|
+
*
|
|
1864
|
+
* Local mode keeps the token in-process: single-use still holds, but
|
|
1865
|
+
* `estimatedAffectedRows` is always `null` (no server estimator) and a
|
|
1866
|
+
* stale/unknown token throws a plain `Error` rather than the HTTP
|
|
1867
|
+
* 404/403 of the server path.
|
|
1811
1868
|
*/
|
|
1812
1869
|
async propose(sql, opts = {}) {
|
|
1813
1870
|
if (this.client.local) {
|