@astrojs/db 0.9.9 → 0.9.11

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.
@@ -35,7 +35,8 @@ async function cmd({
35
35
  virtualModContents = getStudioVirtualModContents({
36
36
  tables: dbConfig.tables ?? {},
37
37
  appToken: appToken.token,
38
- isBuild: false
38
+ isBuild: false,
39
+ output: "server"
39
40
  });
40
41
  } else {
41
42
  virtualModContents = getLocalVirtualModContents({
@@ -27,7 +27,7 @@ function printHelp({
27
27
  message.push(
28
28
  linebreak(),
29
29
  ` ${bgGreen(black(` ${commandName} `))} ${green(
30
- `v${"0.9.9"}`
30
+ `v${"0.9.11"}`
31
31
  )} ${headline}`
32
32
  );
33
33
  }
@@ -6,7 +6,7 @@ import { blue, yellow } from "kleur/colors";
6
6
  import { loadEnv } from "vite";
7
7
  import parseArgs from "yargs-parser";
8
8
  import { SEED_DEV_FILE_NAME } from "../../runtime/queries.js";
9
- import { AstroDbError } from "../../utils.js";
9
+ import { AstroDbError } from "../../runtime/utils.js";
10
10
  import { CONFIG_FILE_NAMES, DB_PATH } from "../consts.js";
11
11
  import { resolveDbConfig } from "../load-file.js";
12
12
  import { getManagedAppTokenOrExit } from "../tokens.js";
@@ -51,7 +51,8 @@ function astroDBIntegration() {
51
51
  appToken: appToken.token,
52
52
  tables,
53
53
  root: config.root,
54
- srcDir: config.srcDir
54
+ srcDir: config.srcDir,
55
+ output: config.output
55
56
  });
56
57
  } else {
57
58
  dbPlugin = vitePluginDb({
@@ -59,7 +60,8 @@ function astroDBIntegration() {
59
60
  tables,
60
61
  seedFiles,
61
62
  root: config.root,
62
- srcDir: config.srcDir
63
+ srcDir: config.srcDir,
64
+ output: config.output
63
65
  });
64
66
  }
65
67
  updateConfig({
@@ -1,3 +1,4 @@
1
+ import type { AstroConfig } from 'astro';
1
2
  import type { DBTables } from '../types.js';
2
3
  import { type VitePlugin } from '../utils.js';
3
4
  export declare const resolved: {
@@ -16,12 +17,14 @@ type VitePluginDBParams = {
16
17
  seedFiles: LateSeedFiles;
17
18
  srcDir: URL;
18
19
  root: URL;
20
+ output: AstroConfig['output'];
19
21
  } | {
20
22
  connectToStudio: true;
21
23
  tables: LateTables;
22
24
  appToken: string;
23
25
  srcDir: URL;
24
26
  root: URL;
27
+ output: AstroConfig['output'];
25
28
  };
26
29
  export declare function vitePluginDb(params: VitePluginDBParams): VitePlugin;
27
30
  export declare function getConfigVirtualModContents(): string;
@@ -31,9 +34,10 @@ export declare function getLocalVirtualModContents({ tables, root, seedFiles, sh
31
34
  root: URL;
32
35
  shouldSeed: boolean;
33
36
  }): string;
34
- export declare function getStudioVirtualModContents({ tables, appToken, isBuild, }: {
37
+ export declare function getStudioVirtualModContents({ tables, appToken, isBuild, output, }: {
35
38
  tables: DBTables;
36
39
  appToken: string;
37
40
  isBuild: boolean;
41
+ output: AstroConfig['output'];
38
42
  }): string;
39
43
  export {};
@@ -37,7 +37,8 @@ function vitePluginDb(params) {
37
37
  return getStudioVirtualModContents({
38
38
  appToken: params.appToken,
39
39
  tables: params.tables.get(),
40
- isBuild: command === "build"
40
+ isBuild: command === "build",
41
+ output: params.output
41
42
  });
42
43
  }
43
44
  return getLocalVirtualModContents({
@@ -95,11 +96,16 @@ ${getStringifiedTableExports(tables)}`;
95
96
  function getStudioVirtualModContents({
96
97
  tables,
97
98
  appToken,
98
- isBuild
99
+ isBuild,
100
+ output
99
101
  }) {
100
102
  function appTokenArg() {
101
103
  if (isBuild) {
102
- return "process.env.ASTRO_STUDIO_APP_TOKEN";
104
+ if (output === "server") {
105
+ return "process.env.ASTRO_STUDIO_APP_TOKEN";
106
+ } else {
107
+ return `process.env.ASTRO_STUDIO_APP_TOKEN ?? ${JSON.stringify(appToken)}`;
108
+ }
103
109
  } else {
104
110
  return JSON.stringify(appToken);
105
111
  }
@@ -2,8 +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 { AstroDbError } from "../utils.js";
6
- import { safeFetch } from "./utils.js";
5
+ import { AstroDbError, safeFetch } from "./utils.js";
7
6
  const isWebContainer = !!process.versions?.webcontainer;
8
7
  function applyTransactionNotSupported(db) {
9
8
  Object.assign(db, {
@@ -2,9 +2,9 @@ import { LibsqlError } from "@libsql/client";
2
2
  import { sql } from "drizzle-orm";
3
3
  import { SQLiteAsyncDialect } from "drizzle-orm/sqlite-core";
4
4
  import {} from "../core/types.js";
5
- import { AstroDbError } from "../utils.js";
6
5
  import { SEED_DEFAULT_EXPORT_ERROR } from "./errors.js";
7
6
  import { getCreateIndexQueries, getCreateTableQuery } from "./queries.js";
7
+ import { AstroDbError } from "./utils.js";
8
8
  const sqlite = new SQLiteAsyncDialect();
9
9
  async function seedLocal({
10
10
  db,
@@ -1,4 +1,8 @@
1
+ import { AstroError } from 'astro/errors';
1
2
  /**
2
3
  * 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
  */
4
5
  export declare function safeFetch(url: Parameters<typeof fetch>[0], options?: Parameters<typeof fetch>[1], onNotOK?: (response: Response) => void | Promise<void>): Promise<Response>;
6
+ export declare class AstroDbError extends AstroError {
7
+ name: string;
8
+ }
@@ -1,3 +1,4 @@
1
+ import { AstroError } from "astro/errors";
1
2
  async function safeFetch(url, options = {}, onNotOK = () => {
2
3
  throw new Error(`Request to ${url} returned a non-OK status code.`);
3
4
  }) {
@@ -7,6 +8,10 @@ async function safeFetch(url, options = {}, onNotOK = () => {
7
8
  }
8
9
  return response;
9
10
  }
11
+ class AstroDbError extends AstroError {
12
+ name = "Astro DB Error";
13
+ }
10
14
  export {
15
+ AstroDbError,
11
16
  safeFetch
12
17
  };
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,2 @@
1
- import { AstroError } from 'astro/errors';
2
1
  export { defineDbIntegration } from './core/utils.js';
3
2
  export { asDrizzleTable } from './runtime/index.js';
4
- export declare class AstroDbError extends AstroError {
5
- name: string;
6
- }
package/dist/utils.js CHANGED
@@ -1,11 +1,6 @@
1
- import { AstroError } from "astro/errors";
2
1
  import { defineDbIntegration } from "./core/utils.js";
3
2
  import { asDrizzleTable } from "./runtime/index.js";
4
- class AstroDbError extends AstroError {
5
- name = "Astro DB Error";
6
- }
7
3
  export {
8
- AstroDbError,
9
4
  asDrizzleTable,
10
5
  defineDbIntegration
11
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/db",
3
- "version": "0.9.9",
3
+ "version": "0.9.11",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -81,7 +81,7 @@
81
81
  "mocha": "^10.2.0",
82
82
  "typescript": "^5.2.2",
83
83
  "vite": "^5.1.4",
84
- "astro": "4.5.13",
84
+ "astro": "4.5.14",
85
85
  "astro-scripts": "0.0.14"
86
86
  },
87
87
  "scripts": {