@astrojs/db 0.10.1 → 0.10.3

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.
@@ -15,17 +15,19 @@ async function cmd() {
15
15
  console.error(MISSING_SESSION_ID_ERROR);
16
16
  process.exit(1);
17
17
  }
18
- const getWorkspaceIdAsync = getWorkspaceId();
18
+ const getWorkspaceIdAsync = getWorkspaceId().catch((err) => {
19
+ return err;
20
+ });
19
21
  await promptBegin();
20
22
  const isLinkExisting = await promptLinkExisting();
21
23
  if (isLinkExisting) {
22
- const workspaceId = await getWorkspaceIdAsync;
24
+ const workspaceId = unwrapWorkspaceId(await getWorkspaceIdAsync);
23
25
  const existingProjectData = await promptExistingProjectName({ workspaceId });
24
26
  return await linkProject(existingProjectData.id);
25
27
  }
26
28
  const isLinkNew = await promptLinkNew();
27
29
  if (isLinkNew) {
28
- const workspaceId = await getWorkspaceIdAsync;
30
+ const workspaceId = unwrapWorkspaceId(await getWorkspaceIdAsync);
29
31
  const newProjectName = await promptNewProjectName();
30
32
  const newProjectRegion = await promptNewProjectRegion();
31
33
  const spinner = ora("Creating new project...").start();
@@ -57,7 +59,7 @@ async function getWorkspaceId() {
57
59
  },
58
60
  (res) => {
59
61
  if (res.status === 401) {
60
- console.error(
62
+ throw new Error(
61
63
  `${bgRed("Unauthorized")}
62
64
 
63
65
  Are you logged in?
@@ -67,19 +69,23 @@ async function getWorkspaceId() {
67
69
 
68
70
  `
69
71
  );
70
- process.exit(1);
71
72
  }
72
- console.error(`Failed to fetch user workspace: ${res.status} ${res.statusText}`);
73
- process.exit(1);
73
+ throw new Error(`Failed to fetch user workspace: ${res.status} ${res.statusText}`);
74
74
  }
75
75
  );
76
76
  const { data, success } = await response.json();
77
77
  if (!success) {
78
- console.error(`Failed to fetch user's workspace.`);
79
- process.exit(1);
78
+ throw new Error(`Failed to fetch user's workspace.`);
80
79
  }
81
80
  return data[0].id;
82
81
  }
82
+ function unwrapWorkspaceId(workspaceId) {
83
+ if (typeof workspaceId !== "string") {
84
+ console.error(workspaceId.message);
85
+ process.exit(1);
86
+ }
87
+ return workspaceId;
88
+ }
83
89
  async function createNewProject({
84
90
  workspaceId,
85
91
  name,
@@ -1,3 +1,4 @@
1
+ import prompts from "prompts";
1
2
  import { safeFetch } from "../../../../runtime/utils.js";
2
3
  import { MIGRATION_VERSION } from "../../../consts.js";
3
4
  import { getManagedAppTokenOrExit } from "../../../tokens.js";
@@ -31,6 +32,16 @@ async function cmd({
31
32
  console.log(`Database schema is out of date.`);
32
33
  }
33
34
  if (isForceReset) {
35
+ const { begin } = await prompts({
36
+ type: "confirm",
37
+ name: "begin",
38
+ message: `Reset your database? All of your data will be erased and your schema created from scratch.`,
39
+ initial: false
40
+ });
41
+ if (!begin) {
42
+ console.log("Canceled.");
43
+ process.exit(0);
44
+ }
34
45
  console.log(`Force-pushing to the database. All existing data will be erased.`);
35
46
  } else if (confirmations.length > 0) {
36
47
  console.log("\n" + formatDataLossMessage(confirmations) + "\n");
@@ -41,9 +41,9 @@ async function getMigrationQueries({
41
41
  Object.entries(droppedTables).filter(([, table]) => !table.deprecated)
42
42
  );
43
43
  if (!isEmpty(addedTables) && !isEmpty(notDeprecatedDroppedTables)) {
44
- throw new Error(
45
- RENAME_TABLE_ERROR(Object.keys(addedTables)[0], Object.keys(notDeprecatedDroppedTables)[0])
46
- );
44
+ const oldTable = Object.keys(notDeprecatedDroppedTables)[0];
45
+ const newTable = Object.keys(addedTables)[0];
46
+ throw new Error(RENAME_TABLE_ERROR(oldTable, newTable));
47
47
  }
48
48
  for (const [tableName, table] of Object.entries(addedTables)) {
49
49
  queries.push(getCreateTableQuery(tableName, table));
@@ -27,7 +27,7 @@ function printHelp({
27
27
  message.push(
28
28
  linebreak(),
29
29
  ` ${bgGreen(black(` ${commandName} `))} ${green(
30
- `v${"0.10.1"}`
30
+ `v${"0.10.3"}`
31
31
  )} ${headline}`
32
32
  );
33
33
  }
@@ -14,9 +14,13 @@ const MISSING_EXECUTE_PATH_ERROR = `${red(
14
14
  )} Provide a path by running ${cyan("astro db execute <path>")}
15
15
  `;
16
16
  const RENAME_TABLE_ERROR = (oldTable, newTable) => {
17
- return red("\u25B6 Potential table rename detected: " + oldTable + ", " + newTable) + `
17
+ return red("\u25B6 Potential table rename detected: " + oldTable + " -> " + newTable) + `
18
18
  You cannot add and remove tables in the same schema update batch.
19
- To resolve, add a 'deprecated: true' flag to '${oldTable}' instead.`;
19
+
20
+ 1. Use "deprecated: true" to deprecate a table before renaming.
21
+ 2. Use "--force-reset" to ignore this warning and reset the database (deleting all of your data).
22
+
23
+ Visit https://docs.astro.build/en/guides/astro-db/#renaming-tables to learn more.`;
20
24
  };
21
25
  const RENAME_COLUMN_ERROR = (oldSelector, newSelector) => {
22
26
  return red("\u25B6 Potential column rename detected: " + oldSelector + ", " + newSelector) + `
@@ -10,6 +10,7 @@ const resolved = {
10
10
  };
11
11
  function vitePluginDb(params) {
12
12
  const srcDirPath = normalizePath(fileURLToPath(params.srcDir));
13
+ const dbDirPath = normalizePath(fileURLToPath(getDbDirectoryUrl(params.root)));
13
14
  let command = "build";
14
15
  return {
15
16
  name: "astro:db",
@@ -25,7 +26,7 @@ function vitePluginDb(params) {
25
26
  const importer = rawImporter ? await this.resolve(rawImporter) : null;
26
27
  if (!importer)
27
28
  return resolved.virtual;
28
- if (importer.id.startsWith(srcDirPath)) {
29
+ if (importer.id.startsWith(srcDirPath) && !importer.id.startsWith(dbDirPath)) {
29
30
  return resolved.seedVirtual;
30
31
  }
31
32
  return resolved.virtual;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/db",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
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.16",
84
+ "astro": "4.5.18",
85
85
  "astro-scripts": "0.0.14"
86
86
  },
87
87
  "scripts": {