@astrojs/db 0.8.3 → 0.8.4
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/_internal/runtime/utils.d.ts +4 -0
- package/dist/core/cli/commands/link/index.js +2 -1
- package/dist/core/cli/commands/push/index.js +2 -1
- package/dist/core/cli/migration-queries.js +2 -1
- package/dist/core/cli/print-help.js +1 -1
- package/dist/core/tokens.js +2 -1
- package/dist/core/utils.d.ts +0 -4
- package/dist/core/utils.js +1 -11
- package/dist/runtime/db-client.js +1 -1
- package/dist/runtime/utils.d.ts +4 -0
- package/dist/runtime/utils.js +12 -0
- package/package.json +1 -1
- package/dist/_internal/core/utils.d.ts +0 -19
|
@@ -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
|
|
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
|
|
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
|
|
23
|
+
import { getRemoteDatabaseUrl } from "../utils.js";
|
|
23
24
|
const sqlite = new SQLiteAsyncDialect();
|
|
24
25
|
const genTempTableName = customAlphabet("abcdefghijklmnopqrstuvwxyz", 10);
|
|
25
26
|
async function getMigrationQueries({
|
package/dist/core/tokens.js
CHANGED
|
@@ -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
|
|
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 {
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -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;
|
package/dist/core/utils.js
CHANGED
|
@@ -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 "
|
|
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,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
|
-
};
|