@astrojs/db 0.11.1 → 0.11.2
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.
|
@@ -2,7 +2,7 @@ import { createClient } from "@libsql/client";
|
|
|
2
2
|
import { drizzle as drizzleLibsql } from "drizzle-orm/libsql";
|
|
3
3
|
import { drizzle as drizzleProxy } from "drizzle-orm/sqlite-proxy";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
5
|
+
import { DetailedLibsqlError, safeFetch } from "./utils.js";
|
|
6
6
|
const isWebContainer = !!process.versions?.webcontainer;
|
|
7
7
|
function applyTransactionNotSupported(db) {
|
|
8
8
|
Object.assign(db, {
|
|
@@ -54,7 +54,10 @@ function createRemoteDatabaseClient(appToken, remoteDbURL) {
|
|
|
54
54
|
const json = await res.json();
|
|
55
55
|
remoteResult = remoteResultSchema.parse(json);
|
|
56
56
|
} catch (e) {
|
|
57
|
-
throw new
|
|
57
|
+
throw new DetailedLibsqlError({
|
|
58
|
+
message: await getUnexpectedResponseMessage(res),
|
|
59
|
+
code: KNOWN_ERROR_CODES.SQL_QUERY_FAILED
|
|
60
|
+
});
|
|
58
61
|
}
|
|
59
62
|
if (method === "run") return remoteResult;
|
|
60
63
|
const rowValues = [];
|
|
@@ -89,7 +92,10 @@ function createRemoteDatabaseClient(appToken, remoteDbURL) {
|
|
|
89
92
|
const json = await res.json();
|
|
90
93
|
remoteResults = z.array(remoteResultSchema).parse(json);
|
|
91
94
|
} catch (e) {
|
|
92
|
-
throw new
|
|
95
|
+
throw new DetailedLibsqlError({
|
|
96
|
+
message: await getUnexpectedResponseMessage(res),
|
|
97
|
+
code: KNOWN_ERROR_CODES.SQL_QUERY_FAILED
|
|
98
|
+
});
|
|
93
99
|
}
|
|
94
100
|
let results = [];
|
|
95
101
|
for (const [idx, rawResult] of remoteResults.entries()) {
|
|
@@ -125,21 +131,24 @@ const KNOWN_ERROR_CODES = {
|
|
|
125
131
|
SQL_QUERY_FAILED: "SQL_QUERY_FAILED"
|
|
126
132
|
};
|
|
127
133
|
const getUnexpectedResponseMessage = async (response) => `Unexpected response from remote database:
|
|
128
|
-
(Status ${response.status}) ${await response.text()}`;
|
|
134
|
+
(Status ${response.status}) ${await response.clone().text()}`;
|
|
129
135
|
async function parseRemoteError(response) {
|
|
130
136
|
let error;
|
|
131
137
|
try {
|
|
132
|
-
error = errorSchema.parse(await response.json()).error;
|
|
138
|
+
error = errorSchema.parse(await response.clone().json()).error;
|
|
133
139
|
} catch (e) {
|
|
134
|
-
return new
|
|
140
|
+
return new DetailedLibsqlError({
|
|
141
|
+
message: await getUnexpectedResponseMessage(response),
|
|
142
|
+
code: KNOWN_ERROR_CODES.SQL_QUERY_FAILED
|
|
143
|
+
});
|
|
135
144
|
}
|
|
136
|
-
let
|
|
137
|
-
|
|
145
|
+
let baseDetails = error.details?.replace(/.*SQLite error: /, "") ?? "Error querying remote database.";
|
|
146
|
+
const details = baseDetails.slice(baseDetails.indexOf(":") + 1).trim();
|
|
138
147
|
let hint = `See the Astro DB guide for query and push instructions: https://docs.astro.build/en/guides/astro-db/#query-your-database`;
|
|
139
148
|
if (error.code === KNOWN_ERROR_CODES.SQL_QUERY_FAILED && details.includes("no such table")) {
|
|
140
149
|
hint = `Did you run \`astro db push\` to push your latest table schemas?`;
|
|
141
150
|
}
|
|
142
|
-
return new
|
|
151
|
+
return new DetailedLibsqlError({ message: details, code: error.code, hint });
|
|
143
152
|
}
|
|
144
153
|
export {
|
|
145
154
|
createLocalDatabaseClient,
|
package/dist/runtime/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LibsqlError } from '@libsql/client';
|
|
1
2
|
import { AstroError } from 'astro/errors';
|
|
2
3
|
/**
|
|
3
4
|
* Small wrapper around fetch that throws an error if the response is not OK. Allows for custom error handling as well through the onNotOK callback.
|
|
@@ -6,4 +7,15 @@ export declare function safeFetch(url: Parameters<typeof fetch>[0], options?: Pa
|
|
|
6
7
|
export declare class AstroDbError extends AstroError {
|
|
7
8
|
name: string;
|
|
8
9
|
}
|
|
10
|
+
export declare class DetailedLibsqlError extends LibsqlError {
|
|
11
|
+
name: string;
|
|
12
|
+
hint?: string;
|
|
13
|
+
constructor({ message, code, hint, rawCode, cause, }: {
|
|
14
|
+
message: string;
|
|
15
|
+
code: string;
|
|
16
|
+
hint?: string;
|
|
17
|
+
rawCode?: number;
|
|
18
|
+
cause?: Error;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
9
21
|
export declare function pathToFileURL(path: string): URL;
|
package/dist/runtime/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LibsqlError } from "@libsql/client";
|
|
1
2
|
import { AstroError } from "astro/errors";
|
|
2
3
|
const isWindows = process?.platform === "win32";
|
|
3
4
|
async function safeFetch(url, options = {}, onNotOK = () => {
|
|
@@ -12,6 +13,20 @@ async function safeFetch(url, options = {}, onNotOK = () => {
|
|
|
12
13
|
class AstroDbError extends AstroError {
|
|
13
14
|
name = "Astro DB Error";
|
|
14
15
|
}
|
|
16
|
+
class DetailedLibsqlError extends LibsqlError {
|
|
17
|
+
name = "Astro DB Error";
|
|
18
|
+
hint;
|
|
19
|
+
constructor({
|
|
20
|
+
message,
|
|
21
|
+
code,
|
|
22
|
+
hint,
|
|
23
|
+
rawCode,
|
|
24
|
+
cause
|
|
25
|
+
}) {
|
|
26
|
+
super(message, code, rawCode, cause);
|
|
27
|
+
this.hint = hint;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
15
30
|
function slash(path) {
|
|
16
31
|
const isExtendedLengthPath = path.startsWith("\\\\?\\");
|
|
17
32
|
if (isExtendedLengthPath) {
|
|
@@ -31,6 +46,7 @@ function pathToFileURL(path) {
|
|
|
31
46
|
}
|
|
32
47
|
export {
|
|
33
48
|
AstroDbError,
|
|
49
|
+
DetailedLibsqlError,
|
|
34
50
|
pathToFileURL,
|
|
35
51
|
safeFetch
|
|
36
52
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/db",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "Add libSQL and Astro Studio support to your Astro site",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -84,12 +84,12 @@
|
|
|
84
84
|
"@types/mocha": "^10.0.6",
|
|
85
85
|
"@types/prompts": "^2.4.9",
|
|
86
86
|
"@types/yargs-parser": "^21.0.3",
|
|
87
|
-
"chai": "^5.1.
|
|
87
|
+
"chai": "^5.1.1",
|
|
88
88
|
"cheerio": "1.0.0-rc.12",
|
|
89
89
|
"mocha": "^10.4.0",
|
|
90
90
|
"typescript": "^5.4.5",
|
|
91
91
|
"vite": "^5.2.11",
|
|
92
|
-
"astro": "4.8.
|
|
92
|
+
"astro": "4.8.4",
|
|
93
93
|
"astro-scripts": "0.0.14"
|
|
94
94
|
},
|
|
95
95
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { sql, eq, gt, gte, lt, lte, ne, isNull, isNotNull, inArray, notInArray, exists, notExists, between, notBetween, like, notIlike, not, asc, desc, and, or, } from 'drizzle-orm';
|
package/dist/runtime/drizzle.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
sql,
|
|
3
|
-
eq,
|
|
4
|
-
gt,
|
|
5
|
-
gte,
|
|
6
|
-
lt,
|
|
7
|
-
lte,
|
|
8
|
-
ne,
|
|
9
|
-
isNull,
|
|
10
|
-
isNotNull,
|
|
11
|
-
inArray,
|
|
12
|
-
notInArray,
|
|
13
|
-
exists,
|
|
14
|
-
notExists,
|
|
15
|
-
between,
|
|
16
|
-
notBetween,
|
|
17
|
-
like,
|
|
18
|
-
notIlike,
|
|
19
|
-
not,
|
|
20
|
-
asc,
|
|
21
|
-
desc,
|
|
22
|
-
and,
|
|
23
|
-
or
|
|
24
|
-
} from "drizzle-orm";
|
|
25
|
-
export {
|
|
26
|
-
and,
|
|
27
|
-
asc,
|
|
28
|
-
between,
|
|
29
|
-
desc,
|
|
30
|
-
eq,
|
|
31
|
-
exists,
|
|
32
|
-
gt,
|
|
33
|
-
gte,
|
|
34
|
-
inArray,
|
|
35
|
-
isNotNull,
|
|
36
|
-
isNull,
|
|
37
|
-
like,
|
|
38
|
-
lt,
|
|
39
|
-
lte,
|
|
40
|
-
ne,
|
|
41
|
-
not,
|
|
42
|
-
notBetween,
|
|
43
|
-
notExists,
|
|
44
|
-
notIlike,
|
|
45
|
-
notInArray,
|
|
46
|
-
or,
|
|
47
|
-
sql
|
|
48
|
-
};
|