@astrojs/db 0.8.3 → 0.8.5

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.
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 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.
3
+ */
4
+ export declare function safeFetch(url: Parameters<typeof fetch>[0], options?: Parameters<typeof fetch>[1], onNotOK?: (response: Response) => void | Promise<void>): Promise<Response>;
@@ -5,9 +5,10 @@ import { slug } from "github-slugger";
5
5
  import { bgRed, cyan } from "kleur/colors";
6
6
  import ora from "ora";
7
7
  import prompts from "prompts";
8
+ import { safeFetch } from "../../../../runtime/utils.js";
8
9
  import { MISSING_SESSION_ID_ERROR } from "../../../errors.js";
9
10
  import { PROJECT_ID_FILE, getSessionIdFromFile } from "../../../tokens.js";
10
- import { getAstroStudioUrl, safeFetch } from "../../../utils.js";
11
+ import { getAstroStudioUrl } from "../../../utils.js";
11
12
  async function cmd() {
12
13
  const sessionToken = await getSessionIdFromFile();
13
14
  if (!sessionToken) {
@@ -1,7 +1,8 @@
1
+ import { safeFetch } from "../../../../runtime/utils.js";
1
2
  import { MIGRATION_VERSION } from "../../../consts.js";
2
3
  import { getManagedAppTokenOrExit } from "../../../tokens.js";
3
4
  import {} from "../../../types.js";
4
- import { getRemoteDatabaseUrl, safeFetch } from "../../../utils.js";
5
+ import { getRemoteDatabaseUrl } from "../../../utils.js";
5
6
  import {
6
7
  createCurrentSnapshot,
7
8
  createEmptySnapshot,
@@ -14,12 +14,13 @@ import {
14
14
  schemaTypeToSqlType
15
15
  } from "../../runtime/queries.js";
16
16
  import { isSerializedSQL } from "../../runtime/types.js";
17
+ import { safeFetch } from "../../runtime/utils.js";
17
18
  import { MIGRATION_VERSION } from "../consts.js";
18
19
  import { RENAME_COLUMN_ERROR, RENAME_TABLE_ERROR } from "../errors.js";
19
20
  import { columnSchema } from "../schemas.js";
20
21
  import {
21
22
  } from "../types.js";
22
- import { getRemoteDatabaseUrl, safeFetch } from "../utils.js";
23
+ import { getRemoteDatabaseUrl } from "../utils.js";
23
24
  const sqlite = new SQLiteAsyncDialect();
24
25
  const genTempTableName = customAlphabet("abcdefghijklmnopqrstuvwxyz", 10);
25
26
  async function getMigrationQueries({
@@ -27,7 +27,7 @@ function printHelp({
27
27
  message.push(
28
28
  linebreak(),
29
29
  ` ${bgGreen(black(` ${commandName} `))} ${green(
30
- `v${"0.8.3"}`
30
+ `v${"0.8.5"}`
31
31
  )} ${headline}`
32
32
  );
33
33
  }
@@ -94,7 +94,7 @@ function getStudioVirtualModContents({
94
94
  return `
95
95
  import {asDrizzleTable, createRemoteDatabaseClient} from ${RUNTIME_IMPORT};
96
96
 
97
- export const db = await createRemoteDatabaseClient(${JSON.stringify(
97
+ export const db = await createRemoteDatabaseClient(process.env.ASTRO_STUDIO_APP_TOKEN ?? ${JSON.stringify(
98
98
  appToken
99
99
  // Respect runtime env for user overrides in SSR
100
100
  )}, import.meta.env.ASTRO_STUDIO_REMOTE_DB_URL ?? ${JSON.stringify(getRemoteDatabaseUrl())});
@@ -33,7 +33,7 @@ async function setUpEnvTs({
33
33
  typesEnvContents = `${dbTypeReference}
34
34
  ${typesEnvContents}`;
35
35
  await writeFile(envTsPath, typesEnvContents, "utf-8");
36
- logger.info(`${cyan(bold("[astro:db]"))} Added ${bold(envTsPathRelativetoRoot)} types`);
36
+ logger.info(`Added ${bold(envTsPathRelativetoRoot)} types`);
37
37
  }
38
38
  }
39
39
  }
@@ -4,8 +4,9 @@ import { join } from "node:path";
4
4
  import { pathToFileURL } from "node:url";
5
5
  import { green } from "kleur/colors";
6
6
  import ora from "ora";
7
+ import { safeFetch } from "../runtime/utils.js";
7
8
  import { MISSING_PROJECT_ID_ERROR, MISSING_SESSION_ID_ERROR } from "./errors.js";
8
- import { getAstroStudioEnv, getAstroStudioUrl, safeFetch } from "./utils.js";
9
+ import { getAstroStudioEnv, getAstroStudioUrl } from "./utils.js";
9
10
  const SESSION_LOGIN_FILE = pathToFileURL(join(homedir(), ".astro", "session-token"));
10
11
  const PROJECT_ID_FILE = pathToFileURL(join(process.cwd(), ".astro", "link"));
11
12
  class ManagedLocalAppToken {
@@ -6,10 +6,6 @@ export declare function getRemoteDatabaseUrl(): string;
6
6
  export declare function getAstroStudioUrl(): string;
7
7
  export declare function getDbDirectoryUrl(root: URL | string): URL;
8
8
  export declare function defineDbIntegration(integration: AstroDbIntegration): AstroIntegration;
9
- /**
10
- * 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.
11
- */
12
- export declare function safeFetch(url: Parameters<typeof fetch>[0], options?: Parameters<typeof fetch>[1], onNotOK?: (response: Response) => void | Promise<void>): Promise<Response>;
13
9
  export type Result<T> = {
14
10
  success: true;
15
11
  data: T;
@@ -17,20 +17,10 @@ function getDbDirectoryUrl(root) {
17
17
  function defineDbIntegration(integration) {
18
18
  return integration;
19
19
  }
20
- async function safeFetch(url, options = {}, onNotOK = () => {
21
- throw new Error(`Request to ${url} returned a non-OK status code.`);
22
- }) {
23
- const response = await fetch(url, options);
24
- if (!response.ok) {
25
- await onNotOK(response);
26
- }
27
- return response;
28
- }
29
20
  export {
30
21
  defineDbIntegration,
31
22
  getAstroStudioEnv,
32
23
  getAstroStudioUrl,
33
24
  getDbDirectoryUrl,
34
- getRemoteDatabaseUrl,
35
- safeFetch
25
+ getRemoteDatabaseUrl
36
26
  };
@@ -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 { safeFetch } from "../core/utils.js";
5
+ import { safeFetch } from "./utils.js";
6
6
  const isWebContainer = !!process.versions?.webcontainer;
7
7
  function createLocalDatabaseClient({ dbUrl }) {
8
8
  const url = isWebContainer ? "file:content.db" : dbUrl;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 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.
3
+ */
4
+ export declare function safeFetch(url: Parameters<typeof fetch>[0], options?: Parameters<typeof fetch>[1], onNotOK?: (response: Response) => void | Promise<void>): Promise<Response>;
@@ -0,0 +1,12 @@
1
+ async function safeFetch(url, options = {}, onNotOK = () => {
2
+ throw new Error(`Request to ${url} returned a non-OK status code.`);
3
+ }) {
4
+ const response = await fetch(url, options);
5
+ if (!response.ok) {
6
+ await onNotOK(response);
7
+ }
8
+ return response;
9
+ }
10
+ export {
11
+ safeFetch
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/db",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -80,8 +80,8 @@
80
80
  "mocha": "^10.2.0",
81
81
  "typescript": "^5.2.2",
82
82
  "vite": "^5.1.4",
83
- "astro": "4.5.4",
84
- "astro-scripts": "0.0.14"
83
+ "astro-scripts": "0.0.14",
84
+ "astro": "4.5.4"
85
85
  },
86
86
  "scripts": {
87
87
  "types:config": "tsc -p ./tsconfig.config-types.json",
@@ -1,19 +0,0 @@
1
- import type { AstroConfig, AstroIntegration } from 'astro';
2
- import type { AstroDbIntegration } from './types.js';
3
- export type VitePlugin = Required<AstroConfig['vite']>['plugins'][number];
4
- export declare function getAstroStudioEnv(envMode?: string): Record<`ASTRO_STUDIO_${string}`, string>;
5
- export declare function getRemoteDatabaseUrl(): string;
6
- export declare function getAstroStudioUrl(): string;
7
- export declare function getDbDirectoryUrl(root: URL | string): URL;
8
- export declare function defineDbIntegration(integration: AstroDbIntegration): AstroIntegration;
9
- /**
10
- * 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.
11
- */
12
- export declare function safeFetch(url: Parameters<typeof fetch>[0], options?: Parameters<typeof fetch>[1], onNotOK?: (response: Response) => void | Promise<void>): Promise<Response>;
13
- export type Result<T> = {
14
- success: true;
15
- data: T;
16
- } | {
17
- success: false;
18
- data: unknown;
19
- };