@astrojs/db 0.20.0 → 0.21.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 CHANGED
@@ -35,4 +35,4 @@ Copyright (c) 2023–present [Astro][astro]
35
35
  [community]: https://github.com/withastro/.github/blob/main/COMMUNITY_GUIDE.md
36
36
  [discord]: https://astro.build/chat/
37
37
  [issues]: https://github.com/withastro/astro/issues
38
- [astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
38
+ [astro-integration]: https://docs.astro.build/en/guides/integrations/
@@ -5,5 +5,6 @@ export declare function hasPrimaryKey(column: DBColumn): boolean;
5
5
  export declare class AstroDbError extends AstroError {
6
6
  name: string;
7
7
  }
8
- export declare function isDbError(err: unknown): err is LibsqlError;
8
+ export declare function getDbError(err: unknown): LibsqlError | undefined;
9
+ export declare function isDbError(err: unknown): boolean;
9
10
  export declare function pathToFileURL(path: string): URL;
@@ -45,4 +45,4 @@ export declare const TRUE: import("drizzle-orm").SQL<unknown>;
45
45
  export declare const FALSE: import("drizzle-orm").SQL<unknown>;
46
46
  export { and, asc, avg, avgDistinct, between, count, countDistinct, desc, eq, exists, gt, gte, ilike, inArray, isNotNull, isNull, like, lt, lte, max, min, ne, not, notBetween, notExists, notIlike, notInArray, or, sql, sum, sumDistinct, } from 'drizzle-orm';
47
47
  export { alias } from 'drizzle-orm/sqlite-core';
48
- export { isDbError } from './utils.js';
48
+ export { getDbError, isDbError } from './utils.js';
@@ -1,6 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import colors from "piccolore";
3
- import { isDbError } from "../../../../runtime/utils.js";
3
+ import { getDbError } from "../../../../runtime/utils.js";
4
4
  import {
5
5
  EXEC_DEFAULT_EXPORT_ERROR,
6
6
  EXEC_ERROR,
@@ -56,7 +56,8 @@ async function cmd({
56
56
  await mod.default();
57
57
  console.info(`${colors.green("\u2714")} File run successfully.`);
58
58
  } catch (e) {
59
- if (isDbError(e)) throw new Error(EXEC_ERROR(e.message));
59
+ const dbError = getDbError(e);
60
+ if (dbError) throw new Error(EXEC_ERROR(dbError.message));
60
61
  else throw e;
61
62
  }
62
63
  }
@@ -1,11 +1,11 @@
1
1
  import { stripVTControlCharacters } from "node:util";
2
- import deepDiff from "deep-diff";
2
+ import diff from "microdiff";
3
3
  import { sql } from "drizzle-orm";
4
4
  import { SQLiteAsyncDialect } from "drizzle-orm/sqlite-core";
5
5
  import { customAlphabet } from "nanoid";
6
6
  import color from "piccolore";
7
7
  import { isSerializedSQL } from "../../runtime/types.js";
8
- import { hasPrimaryKey, isDbError } from "../../runtime/utils.js";
8
+ import { getDbError, hasPrimaryKey } from "../../runtime/utils.js";
9
9
  import { MIGRATION_VERSION } from "../consts.js";
10
10
  import { createClient } from "../db-client/libsql-node.js";
11
11
  import { RENAME_COLUMN_ERROR, RENAME_TABLE_ERROR } from "../errors.js";
@@ -87,7 +87,7 @@ async function getTableChangeQueries({
87
87
  const updated = getUpdatedColumns(oldTable.columns, newTable.columns);
88
88
  const added = getAdded(oldTable.columns, newTable.columns);
89
89
  const dropped = getDropped(oldTable.columns, newTable.columns);
90
- const hasForeignKeyChanges = Boolean(deepDiff(oldTable.foreignKeys, newTable.foreignKeys));
90
+ const hasForeignKeyChanges = diff(oldTable.foreignKeys ?? [], newTable.foreignKeys ?? []).length > 0;
91
91
  if (!hasForeignKeyChanges && isEmpty(updated) && isEmpty(added) && isEmpty(dropped)) {
92
92
  return {
93
93
  queries: getChangeIndexQueries({
@@ -264,7 +264,7 @@ function getUpdated(oldObj, newObj) {
264
264
  for (const [key, value] of Object.entries(newObj)) {
265
265
  const oldValue = oldObj[key];
266
266
  if (!oldValue) continue;
267
- if (deepDiff(oldValue, value)) updated[key] = value;
267
+ if (diff(oldValue, value).length > 0) updated[key] = value;
268
268
  }
269
269
  return updated;
270
270
  }
@@ -282,8 +282,8 @@ function getUpdatedColumns(oldColumns, newColumns) {
282
282
  oldColumn = asNewColumn.data;
283
283
  }
284
284
  }
285
- const diff = deepDiff(oldColumn, newColumn);
286
- if (diff) {
285
+ const diffResult = diff(oldColumn, newColumn);
286
+ if (diffResult.length > 0) {
287
287
  updated[key] = { old: oldColumn, new: newColumn };
288
288
  }
289
289
  }
@@ -320,13 +320,14 @@ async function getDbCurrentSnapshot(appToken, remoteUrl) {
320
320
  );
321
321
  return JSON.parse(res.snapshot);
322
322
  } catch (error) {
323
- if (isDbError(error) && // If the schema was never pushed to the database yet the table won't exist.
323
+ const dbError = getDbError(error);
324
+ if (dbError && // If the schema was never pushed to the database yet the table won't exist.
324
325
  // Treat a missing snapshot table as an empty table.
325
326
  // When connecting to a remote database in that condition
326
327
  // the query will fail with the following error code and message.
327
- (error.code === "SQLITE_UNKNOWN" && error.message === "SQLITE_UNKNOWN: SQLite error: no such table: _astro_db_snapshot" || // When connecting to a local or in-memory database that does not have a snapshot table yet
328
+ (dbError.code === "SQLITE_UNKNOWN" && dbError.message === "SQLITE_UNKNOWN: SQLite error: no such table: _astro_db_snapshot" || // When connecting to a local or in-memory database that does not have a snapshot table yet
328
329
  // the query will fail with the following error code and message.
329
- error.code === "SQLITE_ERROR" && error.message === "SQLITE_ERROR: no such table: _astro_db_snapshot")) {
330
+ dbError.code === "SQLITE_ERROR" && dbError.message === "SQLITE_ERROR: no such table: _astro_db_snapshot")) {
330
331
  return;
331
332
  }
332
333
  throw error;
@@ -27,7 +27,7 @@ function printHelp({
27
27
  message.push(
28
28
  linebreak(),
29
29
  ` ${colors.bgGreen(colors.black(` ${commandName} `))} ${colors.green(
30
- `v${"0.20.0"}`
30
+ `v${"0.21.0"}`
31
31
  )} ${headline}`
32
32
  );
33
33
  }
@@ -10,7 +10,7 @@ import {
10
10
  } from "vite";
11
11
  import parseArgs from "yargs-parser";
12
12
  import * as z from "zod/v4";
13
- import { AstroDbError, isDbError } from "../../runtime/utils.js";
13
+ import { AstroDbError, getDbError } from "../../runtime/utils.js";
14
14
  import { CONFIG_FILE_NAMES, DB_PATH, VIRTUAL_MODULE_ID } from "../consts.js";
15
15
  import { EXEC_DEFAULT_EXPORT_ERROR, EXEC_ERROR } from "../errors.js";
16
16
  import { resolveDbConfig } from "../load-file.js";
@@ -186,8 +186,9 @@ async function executeSeedFile({
186
186
  try {
187
187
  await mod.default();
188
188
  } catch (e) {
189
- if (isDbError(e)) {
190
- throw new AstroDbError(EXEC_ERROR(e.message));
189
+ const dbError = getDbError(e);
190
+ if (dbError) {
191
+ throw new AstroDbError(EXEC_ERROR(dbError.message));
191
192
  }
192
193
  throw e;
193
194
  }
@@ -5,5 +5,6 @@ export declare function hasPrimaryKey(column: DBColumn): boolean;
5
5
  export declare class AstroDbError extends AstroError {
6
6
  name: string;
7
7
  }
8
- export declare function isDbError(err: unknown): err is LibsqlError;
8
+ export declare function getDbError(err: unknown): LibsqlError | undefined;
9
+ export declare function isDbError(err: unknown): boolean;
9
10
  export declare function pathToFileURL(path: string): URL;
@@ -7,8 +7,16 @@ const isWindows = process?.platform === "win32";
7
7
  class AstroDbError extends AstroError {
8
8
  name = "Astro DB Error";
9
9
  }
10
+ function getDbError(err) {
11
+ if (err instanceof LibsqlError) return err;
12
+ if (err instanceof Error && err.libsqlError === true) return err;
13
+ if (err instanceof Error && err.cause != null && err.cause !== err) {
14
+ return getDbError(err.cause);
15
+ }
16
+ return void 0;
17
+ }
10
18
  function isDbError(err) {
11
- return err instanceof LibsqlError || err instanceof Error && err.libsqlError === true;
19
+ return getDbError(err) !== void 0;
12
20
  }
13
21
  function slash(path) {
14
22
  const isExtendedLengthPath = path.startsWith("\\\\?\\");
@@ -29,6 +37,7 @@ function pathToFileURL(path) {
29
37
  }
30
38
  export {
31
39
  AstroDbError,
40
+ getDbError,
32
41
  hasPrimaryKey,
33
42
  isDbError,
34
43
  pathToFileURL
@@ -68,7 +68,7 @@ import {
68
68
  sumDistinct
69
69
  } from "drizzle-orm";
70
70
  import { alias } from "drizzle-orm/sqlite-core";
71
- import { isDbError } from "./utils.js";
71
+ import { getDbError, isDbError } from "./utils.js";
72
72
  export {
73
73
  FALSE,
74
74
  NOW,
@@ -87,6 +87,7 @@ export {
87
87
  desc,
88
88
  eq,
89
89
  exists,
90
+ getDbError,
90
91
  gt,
91
92
  gte,
92
93
  ilike,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/db",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Add libSQL support to your Astro site",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -65,21 +65,20 @@
65
65
  "dependencies": {
66
66
  "@clack/prompts": "^1.0.1",
67
67
  "@libsql/client": "^0.17.0",
68
- "deep-diff": "^1.0.2",
69
- "drizzle-orm": "^0.42.0",
68
+ "drizzle-orm": "^0.45.2",
69
+ "microdiff": "^1.5.0",
70
70
  "nanoid": "^5.1.6",
71
71
  "piccolore": "^0.1.3",
72
72
  "yargs-parser": "^22.0.0",
73
73
  "zod": "^4.3.6"
74
74
  },
75
75
  "devDependencies": {
76
- "@types/deep-diff": "^1.0.5",
77
76
  "@types/yargs-parser": "^21.0.3",
78
77
  "cheerio": "1.2.0",
79
78
  "expect-type": "^1.3.0",
80
79
  "typescript": "^5.9.3",
81
- "vite": "^7.3.1",
82
- "astro": "6.0.0",
80
+ "vite": "^7.3.2",
81
+ "astro": "6.1.10",
83
82
  "astro-scripts": "0.0.14"
84
83
  },
85
84
  "scripts": {
@@ -88,7 +87,8 @@
88
87
  "build:ci": "astro-scripts build \"src/**/*.ts\"",
89
88
  "dev": "astro-scripts dev \"src/**/*.ts\"",
90
89
  "test": "pnpm run test:integration && pnpm run test:types",
91
- "test:integration": "astro-scripts test \"test/**/*.test.js\"",
92
- "test:types": "tsc --project test/types/tsconfig.json"
90
+ "test:integration": "astro-scripts test \"test/**/*.test.ts\"",
91
+ "test:types": "tsc --project test/types/tsconfig.json",
92
+ "typecheck:tests": "tsc --build tsconfig.test.json"
93
93
  }
94
94
  }
package/virtual.d.ts CHANGED
@@ -12,6 +12,7 @@ declare module 'astro:db' {
12
12
  export const defineDb: RuntimeConfig['defineDb'];
13
13
  export const defineTable: RuntimeConfig['defineTable'];
14
14
  export const isDbError: RuntimeConfig['isDbError'];
15
+ export const getDbError: RuntimeConfig['getDbError'];
15
16
 
16
17
  export const eq: RuntimeConfig['eq'];
17
18
  export const gt: RuntimeConfig['gt'];