@tinycloud/sdk-services 2.3.0-beta.6 → 2.3.0-beta.7
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/index.cjs +38 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -3
- package/dist/index.js.map +1 -1
- package/dist/sql/index.cjs +38 -3
- package/dist/sql/index.cjs.map +1 -1
- package/dist/sql/index.d.cts +2 -0
- package/dist/sql/index.d.ts +2 -0
- package/dist/sql/index.js +38 -3
- package/dist/sql/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1670,7 +1670,7 @@ var SQLService = class extends BaseService {
|
|
|
1670
1670
|
try {
|
|
1671
1671
|
const response = await this.invokeSQL(
|
|
1672
1672
|
dbName,
|
|
1673
|
-
SQLAction.READ,
|
|
1673
|
+
this.actionForSql(sql, SQLAction.READ),
|
|
1674
1674
|
{ action: "query", sql, params: params ?? [] },
|
|
1675
1675
|
options?.signal
|
|
1676
1676
|
);
|
|
@@ -1700,7 +1700,7 @@ var SQLService = class extends BaseService {
|
|
|
1700
1700
|
}
|
|
1701
1701
|
const response = await this.invokeSQL(
|
|
1702
1702
|
dbName,
|
|
1703
|
-
SQLAction.WRITE,
|
|
1703
|
+
this.actionForSql(sql, SQLAction.WRITE),
|
|
1704
1704
|
body,
|
|
1705
1705
|
options?.signal
|
|
1706
1706
|
);
|
|
@@ -1722,7 +1722,7 @@ var SQLService = class extends BaseService {
|
|
|
1722
1722
|
try {
|
|
1723
1723
|
const response = await this.invokeSQL(
|
|
1724
1724
|
dbName,
|
|
1725
|
-
|
|
1725
|
+
this.actionForSqlBatch(statements),
|
|
1726
1726
|
{ action: "batch", statements },
|
|
1727
1727
|
options?.signal
|
|
1728
1728
|
);
|
|
@@ -1799,6 +1799,14 @@ var SQLService = class extends BaseService {
|
|
|
1799
1799
|
signal: this.combineSignals(signal)
|
|
1800
1800
|
});
|
|
1801
1801
|
}
|
|
1802
|
+
actionForSql(sql, fallback) {
|
|
1803
|
+
return firstSqlToken(sql) === "pragma" ? SQLAction.ADMIN : fallback;
|
|
1804
|
+
}
|
|
1805
|
+
actionForSqlBatch(statements) {
|
|
1806
|
+
return statements.some(
|
|
1807
|
+
(statement) => this.actionForSql(statement.sql, SQLAction.WRITE) === SQLAction.ADMIN
|
|
1808
|
+
) ? SQLAction.ADMIN : SQLAction.WRITE;
|
|
1809
|
+
}
|
|
1802
1810
|
async handleErrorResponse(response, operation) {
|
|
1803
1811
|
const errorText = await response.text();
|
|
1804
1812
|
let errorBody = {};
|
|
@@ -1844,6 +1852,33 @@ var SQLService = class extends BaseService {
|
|
|
1844
1852
|
}
|
|
1845
1853
|
};
|
|
1846
1854
|
SQLService.serviceName = "sql";
|
|
1855
|
+
function firstSqlToken(sql) {
|
|
1856
|
+
let index = 0;
|
|
1857
|
+
while (index < sql.length) {
|
|
1858
|
+
while (index < sql.length && /\s/.test(sql[index])) {
|
|
1859
|
+
index++;
|
|
1860
|
+
}
|
|
1861
|
+
if (sql.startsWith("--", index)) {
|
|
1862
|
+
const newline = sql.indexOf("\n", index + 2);
|
|
1863
|
+
if (newline === -1) {
|
|
1864
|
+
return void 0;
|
|
1865
|
+
}
|
|
1866
|
+
index = newline + 1;
|
|
1867
|
+
continue;
|
|
1868
|
+
}
|
|
1869
|
+
if (sql.startsWith("/*", index)) {
|
|
1870
|
+
const end = sql.indexOf("*/", index + 2);
|
|
1871
|
+
if (end === -1) {
|
|
1872
|
+
return void 0;
|
|
1873
|
+
}
|
|
1874
|
+
index = end + 2;
|
|
1875
|
+
continue;
|
|
1876
|
+
}
|
|
1877
|
+
break;
|
|
1878
|
+
}
|
|
1879
|
+
const match = /^[A-Za-z_]+/.exec(sql.slice(index));
|
|
1880
|
+
return match?.[0].toLowerCase();
|
|
1881
|
+
}
|
|
1847
1882
|
|
|
1848
1883
|
// src/duckdb/DuckDbDatabaseHandle.ts
|
|
1849
1884
|
var DuckDbDatabaseHandle = class {
|