@astrojs/db 0.11.3 → 0.11.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.
- package/dist/_internal/runtime/virtual.d.ts +0 -2
- package/dist/core/cli/commands/link/index.d.ts +10 -0
- package/dist/core/cli/commands/link/index.js +23 -11
- package/dist/core/cli/print-help.js +1 -1
- package/dist/runtime/db-client.js +13 -1
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +1 -0
- package/package.json +6 -10
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { LibsqlError } from '@libsql/client';
|
|
2
2
|
import type { ColumnsConfig, DBConfigInput, TableConfig } from '../core/types.js';
|
|
3
|
-
import type { LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
4
|
-
export type Database = Omit<LibSQLDatabase, 'transaction'>;
|
|
5
3
|
export declare function isDbError(err: unknown): err is LibsqlError;
|
|
6
4
|
export declare const column: {
|
|
7
5
|
number: <T extends ({
|
|
@@ -11,10 +11,20 @@ export declare function promptExistingProjectName({ workspaceId }: {
|
|
|
11
11
|
workspaceId: string;
|
|
12
12
|
}): Promise<{
|
|
13
13
|
id: string;
|
|
14
|
+
name: string;
|
|
14
15
|
idName: string;
|
|
15
16
|
}>;
|
|
16
17
|
export declare function promptBegin(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Ask the user if they want to link to an existing Astro Studio project.
|
|
20
|
+
* @returns A `Promise` for the user’s answer: `true` if they answer yes, otherwise `false`.
|
|
21
|
+
*/
|
|
17
22
|
export declare function promptLinkExisting(): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Ask the user if they want to link to a new Astro Studio Project.
|
|
25
|
+
* **Exits the process if they answer no.**
|
|
26
|
+
* @returns A `Promise` for the user’s answer: `true` if they answer yes.
|
|
27
|
+
*/
|
|
18
28
|
export declare function promptLinkNew(): Promise<boolean>;
|
|
19
29
|
export declare function promptNewProjectName(): Promise<string>;
|
|
20
30
|
export declare function promptNewProjectRegion(): Promise<string>;
|
|
@@ -19,19 +19,16 @@ async function cmd() {
|
|
|
19
19
|
console.error(MISSING_SESSION_ID_ERROR);
|
|
20
20
|
process.exit(1);
|
|
21
21
|
}
|
|
22
|
-
const getWorkspaceIdAsync = getWorkspaceId().catch((err) => {
|
|
23
|
-
return err;
|
|
24
|
-
});
|
|
25
22
|
await promptBegin();
|
|
26
23
|
const isLinkExisting = await promptLinkExisting();
|
|
27
24
|
if (isLinkExisting) {
|
|
28
|
-
const workspaceId =
|
|
25
|
+
const workspaceId = await promptWorkspace(sessionToken);
|
|
29
26
|
const existingProjectData = await promptExistingProjectName({ workspaceId });
|
|
30
27
|
return await linkProject(existingProjectData.id);
|
|
31
28
|
}
|
|
32
29
|
const isLinkNew = await promptLinkNew();
|
|
33
30
|
if (isLinkNew) {
|
|
34
|
-
const workspaceId =
|
|
31
|
+
const workspaceId = await promptWorkspace(sessionToken);
|
|
35
32
|
const newProjectName = await promptNewProjectName();
|
|
36
33
|
const newProjectRegion = await promptNewProjectRegion();
|
|
37
34
|
const spinner = ora("Creating new project...").start();
|
|
@@ -50,14 +47,14 @@ async function linkProject(id) {
|
|
|
50
47
|
await writeFile(PROJECT_ID_FILE, `${id}`);
|
|
51
48
|
console.info("Project linked.");
|
|
52
49
|
}
|
|
53
|
-
async function
|
|
50
|
+
async function getWorkspaces(sessionToken) {
|
|
54
51
|
const linkUrl = new URL(getAstroStudioUrl() + "/api/cli/workspaces.list");
|
|
55
52
|
const response = await safeFetch(
|
|
56
53
|
linkUrl,
|
|
57
54
|
{
|
|
58
55
|
method: "POST",
|
|
59
56
|
headers: {
|
|
60
|
-
Authorization: `Bearer ${
|
|
57
|
+
Authorization: `Bearer ${sessionToken}`,
|
|
61
58
|
"Content-Type": "application/json"
|
|
62
59
|
}
|
|
63
60
|
},
|
|
@@ -81,13 +78,28 @@ async function getWorkspaceId() {
|
|
|
81
78
|
if (!success) {
|
|
82
79
|
throw new Error(`Failed to fetch user's workspace.`);
|
|
83
80
|
}
|
|
84
|
-
return data
|
|
81
|
+
return data;
|
|
85
82
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
async function promptWorkspace(sessionToken) {
|
|
84
|
+
const workspaces = await getWorkspaces(sessionToken);
|
|
85
|
+
if (workspaces.length === 0) {
|
|
86
|
+
console.error("No workspaces found.");
|
|
89
87
|
process.exit(1);
|
|
90
88
|
}
|
|
89
|
+
if (workspaces.length === 1) {
|
|
90
|
+
return workspaces[0].id;
|
|
91
|
+
}
|
|
92
|
+
const { workspaceId } = await prompts({
|
|
93
|
+
type: "autocomplete",
|
|
94
|
+
name: "workspaceId",
|
|
95
|
+
message: "Select your workspace:",
|
|
96
|
+
limit: 5,
|
|
97
|
+
choices: workspaces.map((w) => ({ title: w.name, value: w.id }))
|
|
98
|
+
});
|
|
99
|
+
if (typeof workspaceId !== "string") {
|
|
100
|
+
console.log("Canceled.");
|
|
101
|
+
process.exit(0);
|
|
102
|
+
}
|
|
91
103
|
return workspaceId;
|
|
92
104
|
}
|
|
93
105
|
async function createNewProject({
|
|
@@ -59,7 +59,19 @@ function createRemoteDatabaseClient(appToken, remoteDbURL) {
|
|
|
59
59
|
code: KNOWN_ERROR_CODES.SQL_QUERY_FAILED
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
if (method === "run")
|
|
62
|
+
if (method === "run") {
|
|
63
|
+
const rawRows = Array.from(remoteResult.rows);
|
|
64
|
+
remoteResult.rows.toJSON = () => rawRows;
|
|
65
|
+
for (let i = 0; i < remoteResult.rows.length; i++) {
|
|
66
|
+
let row = remoteResult.rows[i];
|
|
67
|
+
let item = {};
|
|
68
|
+
remoteResult.columns.forEach((col, index) => {
|
|
69
|
+
item[col] = row[index];
|
|
70
|
+
});
|
|
71
|
+
remoteResult.rows[i] = item;
|
|
72
|
+
}
|
|
73
|
+
return remoteResult;
|
|
74
|
+
}
|
|
63
75
|
const rowValues = [];
|
|
64
76
|
for (const row of remoteResult.rows) {
|
|
65
77
|
if (row != null && typeof row === "object") {
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ColumnDataType } from 'drizzle-orm';
|
|
2
|
+
import { type LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
2
3
|
import type { DBColumn, DBTable } from '../core/types.js';
|
|
4
|
+
export type Database = Omit<LibSQLDatabase, 'transaction'>;
|
|
3
5
|
export type { Table } from './types.js';
|
|
4
6
|
export { createRemoteDatabaseClient, createLocalDatabaseClient } from './db-client.js';
|
|
5
7
|
export declare function hasPrimaryKey(column: DBColumn): boolean;
|
package/dist/runtime/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/db",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5",
|
|
4
4
|
"description": "Add libSQL and Astro Studio support to your Astro site",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -62,11 +62,11 @@
|
|
|
62
62
|
"astro-integration"
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@libsql/client": "^0.6.
|
|
65
|
+
"@libsql/client": "^0.6.2",
|
|
66
66
|
"async-listen": "^3.0.1",
|
|
67
67
|
"ci-info": "^4.0.0",
|
|
68
68
|
"deep-diff": "^1.0.2",
|
|
69
|
-
"drizzle-orm": "^0.
|
|
69
|
+
"drizzle-orm": "^0.31.2",
|
|
70
70
|
"github-slugger": "^2.0.0",
|
|
71
71
|
"kleur": "^4.1.5",
|
|
72
72
|
"nanoid": "^5.0.7",
|
|
@@ -82,15 +82,12 @@
|
|
|
82
82
|
"@types/chai": "^4.3.16",
|
|
83
83
|
"@types/deep-diff": "^1.0.5",
|
|
84
84
|
"@types/diff": "^5.2.1",
|
|
85
|
-
"@types/mocha": "^10.0.6",
|
|
86
85
|
"@types/prompts": "^2.4.9",
|
|
87
86
|
"@types/yargs-parser": "^21.0.3",
|
|
88
|
-
"chai": "^5.1.1",
|
|
89
87
|
"cheerio": "1.0.0-rc.12",
|
|
90
|
-
"mocha": "^10.4.0",
|
|
91
88
|
"typescript": "^5.4.5",
|
|
92
|
-
"vite": "^5.2.
|
|
93
|
-
"astro": "4.
|
|
89
|
+
"vite": "^5.2.13",
|
|
90
|
+
"astro": "4.10.2",
|
|
94
91
|
"astro-scripts": "0.0.14"
|
|
95
92
|
},
|
|
96
93
|
"scripts": {
|
|
@@ -98,7 +95,6 @@
|
|
|
98
95
|
"build": "astro-scripts build \"src/**/*.ts\" && tsc && pnpm types:virtual",
|
|
99
96
|
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
|
100
97
|
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
101
|
-
"test": "
|
|
102
|
-
"test:match": "mocha --timeout 20000 \"test/*.js\" \"test/unit/*.js\" -g"
|
|
98
|
+
"test": "astro-scripts test \"test/**/*.test.js\""
|
|
103
99
|
}
|
|
104
100
|
}
|