studiocms 0.2.0 → 0.3.0

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/cli/add/index.js +4 -3
  3. package/dist/cli/add/tryToInstallPlugins.js +6 -5
  4. package/dist/cli/add/updateStudioCMSConfig.js +3 -4
  5. package/dist/cli/add/validatePlugins.d.ts +1 -2
  6. package/dist/cli/add/validatePlugins.js +15 -9
  7. package/dist/cli/crypto/genJWT/index.js +8 -9
  8. package/dist/cli/init/steps/env.js +2 -2
  9. package/dist/cli/init/steps/next.js +6 -5
  10. package/dist/cli/migrator/index.js +2 -2
  11. package/dist/cli/users/shared.js +2 -2
  12. package/dist/cli/users/steps/createUsers.js +4 -4
  13. package/dist/cli/users/steps/modifyUsers.js +2 -2
  14. package/dist/cli/utils/checkRequiredEnvVars.js +2 -2
  15. package/dist/cli/utils/context.d.ts +1 -3
  16. package/dist/cli/utils/context.js +1 -3
  17. package/dist/cli/utils/logger.js +3 -3
  18. package/dist/cli/utils/user-utils.js +4 -3
  19. package/dist/handlers/setupDbStudio.d.ts +3 -1
  20. package/dist/handlers/setupDbStudio.js +19 -10
  21. package/dist/index.js +1 -15
  22. package/dist/toolbar/db-viewer/studio/connection.d.ts +8 -4
  23. package/dist/toolbar/db-viewer/studio/connection.js +2 -28
  24. package/dist/toolbar/db-viewer/studio/env/libsql.d.ts +7 -0
  25. package/dist/toolbar/db-viewer/studio/env/libsql.js +17 -0
  26. package/dist/toolbar/db-viewer/studio/env/mysql.d.ts +7 -0
  27. package/dist/toolbar/db-viewer/studio/env/mysql.js +23 -0
  28. package/dist/toolbar/db-viewer/studio/env/postgres.d.ts +7 -0
  29. package/dist/toolbar/db-viewer/studio/env/postgres.js +23 -0
  30. package/dist/toolbar/db-viewer/studio/index.js +20 -56
  31. package/dist/toolbar/db-viewer/studio/type.d.ts +1 -2
  32. package/dist/toolbar/db-viewer/studio/virtual-connection/libsql.d.ts +3 -0
  33. package/dist/toolbar/db-viewer/studio/virtual-connection/libsql.js +24 -0
  34. package/dist/toolbar/db-viewer/studio/virtual-connection/mysql.d.ts +3 -0
  35. package/dist/toolbar/db-viewer/studio/virtual-connection/mysql.js +9 -0
  36. package/dist/toolbar/db-viewer/studio/virtual-connection/postgres.d.ts +3 -0
  37. package/dist/toolbar/db-viewer/studio/virtual-connection/postgres.js +9 -0
  38. package/dist/virtual.d.ts +12 -28
  39. package/frontend/layouts/DashboardLayout.astro +1 -1
  40. package/frontend/pages/404.astro +5 -8
  41. package/frontend/pages/studiocms_api/auth/[path].ts +0 -6
  42. package/frontend/scripts/formdata-utils.ts +3 -3
  43. package/package.json +16 -17
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # studiocms
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1254](https://github.com/withstudiocms/studiocms/pull/1254) [`180b959`](https://github.com/withstudiocms/studiocms/commit/180b95972f9d51731eb570685e251532cbae2f62) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Replaces chalk with node:util's styleText
8
+
9
+ - [#1271](https://github.com/withstudiocms/studiocms/pull/1271) [`9a450cb`](https://github.com/withstudiocms/studiocms/commit/9a450cb9167e2f2ea4c197bc812131d2fdeda6c9) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Removes deprecated and unused virtual modules.
10
+
11
+ The following modules have been removed.
12
+
13
+ - `studiocms:astro-config/adapter`
14
+ - `studiocms:auth/utils/getLabelForPermissionLevel`
15
+ - `virtual:studiocms/sdk/env`
16
+
17
+ ### Patch Changes
18
+
19
+ - [#1237](https://github.com/withstudiocms/studiocms/pull/1237) [`fb6c96a`](https://github.com/withstudiocms/studiocms/commit/fb6c96ac6ae25887a0f673618770a67b2deffae6) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update studiocms dependencies
20
+
21
+ - [#1259](https://github.com/withstudiocms/studiocms/pull/1259) [`0525390`](https://github.com/withstudiocms/studiocms/commit/05253906d33a9b7bd12a27cdf2b8c9e9f693177f) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update studiocms dependencies
22
+
23
+ - [#1267](https://github.com/withstudiocms/studiocms/pull/1267) [`d56b066`](https://github.com/withstudiocms/studiocms/commit/d56b066554848d819cc3dd59cfacfbda51565ad5) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update dependency @nanostores/persistent to ^1.3.0
24
+
25
+ - [#1255](https://github.com/withstudiocms/studiocms/pull/1255) [`e12e074`](https://github.com/withstudiocms/studiocms/commit/e12e074e6432398181be1f58f5c89df96a516cbb) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Fix new type issues due to updated clack version
26
+
27
+ - [#1270](https://github.com/withstudiocms/studiocms/pull/1270) [`c9727f7`](https://github.com/withstudiocms/studiocms/commit/c9727f7a218113d68254de825b84ddb926721b56) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Fixes issue with pg and mysql2 being required to be installed when they should be optional
28
+
29
+ - [#1272](https://github.com/withstudiocms/studiocms/pull/1272) [`38e74bb`](https://github.com/withstudiocms/studiocms/commit/38e74bbeec97e054e8545d6665452c5246a1fdd3) Thanks [@RATIU5](https://github.com/RATIU5)! - Fix client regex in frontend to allow for slashes within a slug, but not on the outside. This unblocks creating pages under sub-paths just using the slug (e.g., `docs/getting-started`) and only affects client-side validation.
30
+
31
+ - [#1265](https://github.com/withstudiocms/studiocms/pull/1265) [`6d9b601`](https://github.com/withstudiocms/studiocms/commit/6d9b601b0a29ca2221d47efa65bc1356870e0339) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Removes legacy email domain verification code
32
+
33
+ - [#1231](https://github.com/withstudiocms/studiocms/pull/1231) [`e7b39ef`](https://github.com/withstudiocms/studiocms/commit/e7b39ef6c3e1e2a54201e200b32fb1c02cd5fc3e) Thanks [@Adammatthiesen](https://github.com/Adammatthiesen)! - Fixes default 404 route rendering
34
+
35
+ - Updated dependencies [[`6b826b8`](https://github.com/withstudiocms/studiocms/commit/6b826b80104fe23e35763edf275f1800e5629c32), [`8b46bf5`](https://github.com/withstudiocms/studiocms/commit/8b46bf5861f3ab884bb8cbac1b73a1e97fcabe96), [`f129eec`](https://github.com/withstudiocms/studiocms/commit/f129eec8d0a6f18c446c319dec9925cc31a890b4), [`e12e074`](https://github.com/withstudiocms/studiocms/commit/e12e074e6432398181be1f58f5c89df96a516cbb)]:
36
+ - @withstudiocms/internal_helpers@0.1.1
37
+ - @withstudiocms/effect@0.3.0
38
+ - @withstudiocms/auth-kit@0.1.3
39
+ - @withstudiocms/component-registry@0.1.3
40
+ - @withstudiocms/sdk@0.2.0
41
+
3
42
  ## 0.2.0
4
43
 
5
44
  ### Minor Changes
@@ -1,5 +1,6 @@
1
1
  import { existsSync, promises as fs } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
+ import { styleText } from "node:util";
3
4
  import { cancelled, success } from "@withstudiocms/cli-kit/messages";
4
5
  import { exists, pathToFileURL, resolveRoot } from "@withstudiocms/cli-kit/utils";
5
6
  import { intro, note, outro } from "@withstudiocms/effect/clack";
@@ -130,7 +131,7 @@ const addPlugin = Cli.Command.make(
130
131
  UpdateStudioCMSConfig,
131
132
  genContext
132
133
  ]);
133
- const { cwd, chalk } = context;
134
+ const { cwd } = context;
134
135
  yield* intro("StudioCMS CLI Utilities (add)");
135
136
  const pluginNames = plugin2.map((name) => {
136
137
  const aliasName = ALIASES.get(name);
@@ -149,7 +150,7 @@ const addPlugin = Cli.Command.make(
149
150
  case 2 /* cancelled */: {
150
151
  yield* note(
151
152
  cancelled(
152
- `Dependencies ${chalk.bold("NOT")} installed.`,
153
+ `Dependencies ${styleText("bold", "NOT")} installed.`,
153
154
  "Be sure to install them manually before continuing!"
154
155
  )
155
156
  );
@@ -176,7 +177,7 @@ const addPlugin = Cli.Command.make(
176
177
  }
177
178
  switch (configResult) {
178
179
  case 2 /* cancelled */: {
179
- yield* outro(cancelled(`Your configuration has ${chalk.bold("NOT")} been updated.`));
180
+ yield* outro(cancelled(`Your configuration has ${styleText("bold", "NOT")} been updated.`));
180
181
  break;
181
182
  }
182
183
  case 0 /* none */: {
@@ -1,3 +1,4 @@
1
+ import { styleText } from "node:util";
1
2
  import { exec } from "@withstudiocms/cli-kit/utils";
2
3
  import { askToContinue, note, spinner } from "@withstudiocms/effect/clack";
3
4
  import { detect, resolveCommand } from "package-manager-detector";
@@ -12,7 +13,7 @@ class TryToInstallPlugins extends Effect.Service()(
12
13
  {
13
14
  effect: genLogger("studiocms/cli/add/validatePlugins/TryToInstallPlugins.effect")(function* () {
14
15
  const run = (plugins) => genLogger("studiocms/cli/add/validatePlugins/TryToInstallPlugins.effect.run")(function* () {
15
- const { chalk, cwd } = yield* CliContext;
16
+ const { cwd } = yield* CliContext;
16
17
  const packageManager = yield* Effect.tryPromise(
17
18
  () => detect({
18
19
  cwd,
@@ -37,7 +38,7 @@ class TryToInstallPlugins extends Effect.Service()(
37
38
  const installSpecifiers = (yield* convertPluginsToInstallSpecifiers(plugins)).map(
38
39
  (specifier) => installCommand.command === "deno" ? `npm:${specifier}` : specifier
39
40
  );
40
- const coloredOutput = `${chalk.bold(installCommand.command)} ${installCommand.args.join(" ")} ${chalk.magenta(installSpecifiers.join(" "))}`;
41
+ const coloredOutput = `${styleText("bold", installCommand.command)} ${installCommand.args.join(" ")} ${styleText("magenta", installSpecifiers.join(" "))}`;
41
42
  const boxenMessage = yield* effectBoxen(
42
43
  (boxen) => boxen(coloredOutput, {
43
44
  margin: 0.5,
@@ -49,8 +50,8 @@ class TryToInstallPlugins extends Effect.Service()(
49
50
  ${boxenMessage}
50
51
  `;
51
52
  yield* note(
52
- `${chalk.magenta("StudioCMS will run the following command:")}
53
- ${chalk.dim("If you skip this step, you can always run it yourself later")}
53
+ `${styleText("magenta", "StudioCMS will run the following command:")}
54
+ ${styleText("dim", "If you skip this step, you can always run it yourself later")}
54
55
  ${message}`
55
56
  );
56
57
  if (yield* askToContinue()) {
@@ -83,7 +84,7 @@ ${response.stdout || response.message}
83
84
  `);
84
85
  yield* Console.error(
85
86
  `
86
- ${chalk.yellow("You may want to try:")}
87
+ ${styleText("yellow", "You may want to try:")}
87
88
  - Checking your network connection
88
89
  - Running the package manager command manually
89
90
  - Ensuring you have permissions to install packages
@@ -1,5 +1,6 @@
1
1
  import { promises as fs } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
+ import { styleText } from "node:util";
3
4
  import { askToContinue, note } from "@withstudiocms/effect/clack";
4
5
  import { diffWords } from "diff";
5
6
  import { generateCode } from "magicast";
@@ -15,7 +16,6 @@ class UpdateStudioCMSConfig extends Effect.Service()(
15
16
  const run = (configURL, mod) => genLogger("studiocms/cli/add/updateStudioCMSConfig/UpdateStudioCMSConfig.effect.run")(
16
17
  function* () {
17
18
  const context = yield* CliContext;
18
- const { chalk } = context;
19
19
  const input = yield* Effect.tryPromise(
20
20
  () => fs.readFile(fileURLToPath(configURL), { encoding: "utf-8" })
21
21
  );
@@ -46,7 +46,7 @@ ${boxenMessage}
46
46
  `;
47
47
  yield* note(
48
48
  `
49
- ${chalk.magenta("StudioCMS will make the following changes to your config file:")}
49
+ ${styleText("magenta", "StudioCMS will make the following changes to your config file:")}
50
50
  ${message}`
51
51
  );
52
52
  if (yield* askToContinue()) {
@@ -66,7 +66,6 @@ ${message}`
66
66
  ) {
67
67
  }
68
68
  const getDiffContent = (input, output) => genLogger("studiocms/cli/add/updateStudioCMSConfig.getDiffContentNew")(function* () {
69
- const { chalk } = yield* CliContext;
70
69
  const changes = [];
71
70
  for (const change of diffWords(input, output)) {
72
71
  const lines = change.value.trim().split("\n").slice(0, change.count);
@@ -81,7 +80,7 @@ const getDiffContent = (input, output) => genLogger("studiocms/cli/add/updateStu
81
80
  }
82
81
  let diffed = output;
83
82
  for (const newContent of changes) {
84
- const coloredOutput = newContent.split("\n").map((ln) => ln ? chalk.green(ln) : "").join("\n");
83
+ const coloredOutput = newContent.split("\n").map((ln) => ln ? styleText("green", ln) : "").join("\n");
85
84
  diffed = diffed.replace(newContent, coloredOutput);
86
85
  }
87
86
  return diffed;
@@ -1,9 +1,8 @@
1
1
  import { Effect } from '../../effect.js';
2
- import { CliContext } from '../utils/context.js';
3
2
  import { type PluginInfo } from './index.js';
4
3
  declare const ValidatePlugins_base: Effect.Service.Class<ValidatePlugins, "ValidatePlugins", {
5
4
  readonly effect: Effect.Effect<{
6
- run: (names: string[]) => Effect.Effect<PluginInfo[], import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError | import("@withstudiocms/effect").DeepmergeError | import("@withstudiocms/effect/clack").ClackError, CliContext>;
5
+ run: (names: string[]) => Effect.Effect<PluginInfo[], import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError | import("@withstudiocms/effect").DeepmergeError | import("@withstudiocms/effect/clack").ClackError, never>;
7
6
  }, never, never>;
8
7
  }>;
9
8
  export declare class ValidatePlugins extends ValidatePlugins_base {
@@ -1,19 +1,20 @@
1
+ import { styleText } from "node:util";
1
2
  import { askToContinue, spinner } from "@withstudiocms/effect/clack";
2
3
  import { Effect, genLogger } from "../../effect.js";
3
- import { CliContext } from "../utils/context.js";
4
4
  import { StudioCMSScopes } from "./index.js";
5
5
  import { fetchPackageJson, parsePluginName } from "./npm-utils.js";
6
6
  class ValidatePlugins extends Effect.Service()("ValidatePlugins", {
7
7
  effect: genLogger("studiocms/cli/add/validatePlugins/ValidatePlugins.effect")(function* () {
8
8
  const run = (names) => genLogger("studiocms/cli/add/validatePlugins/ValidatePlugins.effect.run")(function* () {
9
- const { chalk } = yield* CliContext;
10
9
  const spin = yield* spinner();
11
10
  yield* spin.start("Resolving packages...");
12
11
  const entries = [];
13
12
  for (const plugin of names) {
14
13
  const parsed = yield* parsePluginName(plugin);
15
14
  if (!parsed)
16
- throw new Error(`${chalk.bold(plugin)} does not appear to be a valid package name!`);
15
+ throw new Error(
16
+ `${styleText("bold", plugin)} does not appear to be a valid package name!`
17
+ );
17
18
  const { scope, name, tag } = parsed;
18
19
  let pkgJson = {};
19
20
  let pkgType;
@@ -23,14 +24,17 @@ class ValidatePlugins extends Effect.Service()("ValidatePlugins", {
23
24
  const firstPartyPkgCheck = yield* fetchPackageJson(scope, name, tag);
24
25
  if (firstPartyPkgCheck instanceof Error) {
25
26
  if (firstPartyPkgCheck.message) {
26
- yield* spin.message(chalk.yellow(firstPartyPkgCheck.message));
27
+ yield* spin.message(styleText("yellow", firstPartyPkgCheck.message));
27
28
  }
28
29
  yield* spin.message(
29
- chalk.yellow(`${chalk.bold(plugin)} is not an official StudioCMS package.`)
30
+ styleText(
31
+ "yellow",
32
+ `${styleText("bold", plugin)} is not an official StudioCMS package.`
33
+ )
30
34
  );
31
35
  if (!(yield* askToContinue())) {
32
36
  throw new Error(
33
- `No problem! Find our official plugins at ${chalk.magenta("https://docs.studiocms.dev")}`
37
+ `No problem! Find our official plugins at ${styleText("magenta", "https://docs.studiocms.dev")}`
34
38
  );
35
39
  }
36
40
  yield* spin.start("Resolving with third party packages...");
@@ -44,9 +48,11 @@ class ValidatePlugins extends Effect.Service()("ValidatePlugins", {
44
48
  const thirdPartyPkgCheck = yield* fetchPackageJson(scope, name, tag);
45
49
  if (thirdPartyPkgCheck instanceof Error) {
46
50
  if (thirdPartyPkgCheck.message) {
47
- yield* spin.message(chalk.yellow(thirdPartyPkgCheck.message));
51
+ yield* spin.message(styleText("yellow", thirdPartyPkgCheck.message));
48
52
  }
49
- throw new Error(`Unable to fetch ${chalk.bold(plugin)}. Does the package exist?`);
53
+ throw new Error(
54
+ `Unable to fetch ${styleText("bold", plugin)}. Does the package exist?`
55
+ );
50
56
  }
51
57
  pkgJson = thirdPartyPkgCheck;
52
58
  }
@@ -67,7 +73,7 @@ class ValidatePlugins extends Effect.Service()("ValidatePlugins", {
67
73
  const keywords = Array.isArray(pkgJson.keywords) ? pkgJson.keywords : [];
68
74
  if (!keywords.includes("studiocms-plugin")) {
69
75
  throw new Error(
70
- `${chalk.bold(plugin)} doesn't appear to be an StudioCMS Plugin. Find our official plugins at ${chalk.magenta("https://docs.studiocms.dev")}`
76
+ `${styleText("bold", plugin)} doesn't appear to be an StudioCMS Plugin. Find our official plugins at ${styleText("magenta", "https://docs.studiocms.dev")}`
71
77
  );
72
78
  }
73
79
  entries.push({
@@ -10,7 +10,6 @@ import { intro, log, outro, spinner } from "@withstudiocms/effect/clack";
10
10
  import { SignJWT } from "jose";
11
11
  import { importPKCS8 } from "jose/key/import";
12
12
  import { Cli, Effect, genLogger } from "../../../effect.js";
13
- import { genContext } from "../../utils/context.js";
14
13
  import { dateAdd } from "../../utils/dateAdd.js";
15
14
  import { debug } from "../../utils/debugOpt.js";
16
15
  import { StudioCMSCliError } from "../../utils/errors.js";
@@ -57,9 +56,6 @@ const genJWT = Cli.Command.make(
57
56
  logger.debug(`Key file: ${keyFile2}`);
58
57
  logger.debug(`Expiration: ${exp}`);
59
58
  }
60
- if (debug2) logger.debug("Getting context");
61
- const context = yield* genContext;
62
- const { chalk } = context;
63
59
  if (debug2) logger.debug("Init complete, starting...");
64
60
  yield* intro(label("StudioCMS Crypto: Generate JWT", StudioCMSColorwayBg, "bold"));
65
61
  const spin = yield* spinner();
@@ -90,11 +86,14 @@ const genJWT = Cli.Command.make(
90
86
  const base64UrlJwt = yield* convertJwtToBase64Url(jwt);
91
87
  yield* spin.stop("Token Generated.");
92
88
  yield* log.success(
93
- boxen(chalk.bold(`${label("Token Generated!", StudioCMSColorwayInfoBg, "bold")}`), {
94
- ln1: "Your new Token has been generated successfully:",
95
- ln3: `Token: ${chalk.magenta(jwt)}`,
96
- ln5: `Base64Url Token: ${chalk.blue(base64UrlJwt)}`
97
- })
89
+ boxen(
90
+ styleText("bold", `${label("Token Generated!", StudioCMSColorwayInfoBg, "bold")}`),
91
+ {
92
+ ln1: "Your new Token has been generated successfully:",
93
+ ln3: `Token: ${styleText("magenta", jwt)}`,
94
+ ln5: `Base64Url Token: ${styleText("blue", base64UrlJwt)}`
95
+ }
96
+ )
98
97
  );
99
98
  yield* outro(
100
99
  `${label("You can now use this token where needed.", StudioCMSColorwayBg, "bold")} Stuck? Join us on Discord at ${StudioCMSColorway(styleText(["bold", "underline"], "https://chat.studiocms.dev"))}`
@@ -36,7 +36,7 @@ function NumberStringToUndefined(value) {
36
36
  return Number.isNaN(num) ? void 0 : num;
37
37
  }
38
38
  const env = Effect.fn(function* (context, debug, dryRun) {
39
- const { chalk, cwd, pCancel, pOnCancel } = context;
39
+ const { cwd, pCancel, pOnCancel } = context;
40
40
  const debugLogger = yield* buildDebugLogger(debug);
41
41
  yield* debugLogger("Running env...");
42
42
  let _env = false;
@@ -436,7 +436,7 @@ const env = Effect.fn(function* (context, debug, dryRun) {
436
436
  });
437
437
  } else if (_env) {
438
438
  context.tasks.push({
439
- title: chalk.dim("Creating environment file..."),
439
+ title: styleText("dim", "Creating environment file..."),
440
440
  task: async (message) => {
441
441
  try {
442
442
  await fs.writeFile(path.join(cwd, ".env"), envFileContent, {
@@ -22,7 +22,7 @@ const runCmdMap = {
22
22
  pnpm: "pnpm run"
23
23
  };
24
24
  const next = (debug) => genLogger("studiocms/cli/init/steps/next")(function* () {
25
- const [{ chalk, packageManager }, debugLogger] = yield* Effect.all([
25
+ const [{ packageManager }, debugLogger] = yield* Effect.all([
26
26
  CliContext,
27
27
  buildDebugLogger(debug)
28
28
  ]);
@@ -33,13 +33,14 @@ const next = (debug) => genLogger("studiocms/cli/init/steps/next")(function* ()
33
33
  debugLogger("Running next steps fn..."),
34
34
  log.success(
35
35
  boxen(
36
- chalk.bold(
36
+ styleText(
37
+ "bold",
37
38
  `${label("Init Complete!", StudioCMSColorwayInfoBg, "bold")} Get started with StudioCMS:`
38
39
  ),
39
40
  {
40
- ln1: `Ensure your ${chalk.cyanBright(".env")} file is configured correctly.`,
41
- ln3: `Run ${chalk.cyan(`${runCmd} studiocms migrate`)} to sync your database schema.`,
42
- ln4: `Run ${chalk.cyan(devCmd)} to start the dev server. ${chalk.cyanBright("CTRL+C")} to stop.`
41
+ ln1: `Ensure your ${styleText("cyanBright", ".env")} file is configured correctly.`,
42
+ ln3: `Run ${styleText("cyan", `${runCmd} studiocms migrate`)} to sync your database schema.`,
43
+ ln4: `Run ${styleText("cyan", devCmd)} to start the dev server. ${styleText("cyanBright", "CTRL+C")} to stop.`
43
44
  }
44
45
  )
45
46
  )
@@ -143,11 +143,11 @@ const migratorCMD = Cli.Command.make(
143
143
  const migrationTotal = status3.length;
144
144
  const appliedMigrations = status3.filter((m) => m.executedAt).length;
145
145
  const migrationPercent = appliedMigrations / migrationTotal * 100;
146
- const migrationTotalColor = migrationPercent === 100 ? context.chalk.green : migrationPercent > 50 ? context.chalk.yellow : context.chalk.red;
146
+ const migrationTotalColor = migrationPercent === 100 ? (text) => styleText("green", text) : migrationPercent > 50 ? (text) => styleText("yellow", text) : (text) => styleText("red", text);
147
147
  const labelParts = [
148
148
  label("Migration Status", StudioCMSColorwayInfoBg, "black"),
149
149
  label(
150
- `(${context.chalk.green(appliedMigrations.toString())}/${migrationTotalColor(migrationTotal.toString())}) Applied`,
150
+ `(${styleText("green", appliedMigrations.toString())}/${migrationTotalColor(migrationTotal.toString())}) Applied`,
151
151
  (text) => styleText("bold", text),
152
152
  "black"
153
153
  )
@@ -1,6 +1,6 @@
1
+ import { styleText } from "node:util";
1
2
  import { Effect } from "@withstudiocms/effect";
2
3
  import { log } from "@withstudiocms/effect/clack";
3
- import chalk from "chalk";
4
4
  const validateInputOrRePrompt = Effect.fn("validateInputOrRePrompt")(function* (opts) {
5
5
  const { prompt, checkEffect } = opts;
6
6
  while (true) {
@@ -12,7 +12,7 @@ const validateInputOrRePrompt = Effect.fn("validateInputOrRePrompt")(function* (
12
12
  if (checkResult === true) {
13
13
  return input;
14
14
  }
15
- yield* log.error(chalk.red(`Invalid input: ${checkResult}`));
15
+ yield* log.error(styleText("red", `Invalid input: ${checkResult}`));
16
16
  }
17
17
  });
18
18
  export {
@@ -50,7 +50,7 @@ const createUsers = Effect.fn(function* (context, _debug, dryRun) {
50
50
  message: "Username",
51
51
  placeholder: "johndoe",
52
52
  validate: (user) => {
53
- const u = user.trim();
53
+ const u = user?.trim();
54
54
  const isUser = currentUsers.find(({ username: username2 }) => username2 === u);
55
55
  if (isUser) return "Username is already in use, please try another one";
56
56
  return void 0;
@@ -90,7 +90,7 @@ const createUsers = Effect.fn(function* (context, _debug, dryRun) {
90
90
  message: "E-Mail Address",
91
91
  placeholder: "john@doe.tld",
92
92
  validate: (email2) => {
93
- const e = email2.trim().toLowerCase();
93
+ const e = email2?.trim().toLowerCase();
94
94
  const emailSchema = z.string().email({ message: "Email address is invalid" });
95
95
  const response = emailSchema.safeParse(e);
96
96
  if (!response.success) return response.error.message;
@@ -121,7 +121,7 @@ const createUsers = Effect.fn(function* (context, _debug, dryRun) {
121
121
  );
122
122
  const { confirmPassword, email, name, newPassword, rank, username } = inputData;
123
123
  if (newPassword !== confirmPassword) {
124
- yield* log.error(context.chalk.red("Passwords do not match, exiting..."));
124
+ yield* log.error(styleText("red", "Passwords do not match, exiting..."));
125
125
  return yield* context.exit(1);
126
126
  }
127
127
  const newUserId = crypto.randomUUID();
@@ -166,7 +166,7 @@ const createUsers = Effect.fn(function* (context, _debug, dryRun) {
166
166
  message("Failed to create user or assign permissions");
167
167
  return await runEffect(context.exit(1));
168
168
  }
169
- message(context.chalk.green("User created successfully!"));
169
+ message(styleText("green", "User created successfully!"));
170
170
  } catch (error) {
171
171
  await runEffect(log.error(`Failed to create user: ${error.message}`));
172
172
  return await runEffect(context.exit(1));
@@ -80,7 +80,7 @@ const modifyUsers = Effect.fn(function* (context, _debug, dryRun) {
80
80
  message: "Enter the new username",
81
81
  placeholder: "johndoe",
82
82
  validate: (user) => {
83
- const u = user.trim();
83
+ const u = user?.trim();
84
84
  const isUser = currentUsers.find(({ username }) => username === u);
85
85
  if (isUser) return "Username is already in use, please try another one";
86
86
  return void 0;
@@ -119,7 +119,7 @@ const modifyUsers = Effect.fn(function* (context, _debug, dryRun) {
119
119
  const newDisplayName = yield* text({
120
120
  message: "Enter new display name",
121
121
  placeholder: currentUsers.find((u) => u.id === userSelection)?.name || "John Doe",
122
- validate: (v) => v.trim().length === 0 ? "Display name cannot be empty" : void 0
122
+ validate: (v) => v?.trim().length === 0 ? "Display name cannot be empty" : void 0
123
123
  });
124
124
  if (typeof newDisplayName === "symbol") {
125
125
  return yield* context.pCancel(newDisplayName);
@@ -1,5 +1,5 @@
1
+ import { styleText } from "node:util";
1
2
  import { log } from "@withstudiocms/effect/clack";
2
- import chalk from "chalk";
3
3
  import { Effect } from "../../effect.js";
4
4
  const checkRequiredEnvVarsEffect = Effect.fn(function* (envVars) {
5
5
  const missingVars = [];
@@ -11,7 +11,7 @@ const checkRequiredEnvVarsEffect = Effect.fn(function* (envVars) {
11
11
  });
12
12
  if (missingVars.length > 0) {
13
13
  yield* log.error(
14
- `${chalk.red.bold("Missing environment variables:")} ${missingVars.map((v) => chalk.red(v)).join(", ")}`
14
+ `${styleText(["red", "bold"], "Missing environment variables:")} ${missingVars.map((v) => styleText("red", v)).join(", ")}`
15
15
  );
16
16
  return yield* Effect.try(() => process.exit(1));
17
17
  }
@@ -1,15 +1,13 @@
1
1
  import { type ClackError, type Task } from '@withstudiocms/effect/clack';
2
- import chalk from 'chalk';
3
2
  import { Context, Effect, Layer, Option } from '../../effect.js';
4
3
  export interface BaseContext {
5
- chalk: typeof chalk;
6
4
  cwd: string;
7
5
  packageManager: string;
8
6
  username: string;
9
7
  tasks: Task[];
10
8
  pCancel(val: symbol): Effect.Effect<void, ClackError, never>;
11
9
  pOnCancel(): Effect.Effect<void, ClackError, never>;
12
- exit(code: number): Effect.Effect<undefined, never, never>;
10
+ exit(code: number): Effect.Effect<void, never, never>;
13
11
  }
14
12
  declare const CliContext_base: Context.TagClass<CliContext, "CliContext", BaseContext>;
15
13
  export declare class CliContext extends CliContext_base {
@@ -1,7 +1,6 @@
1
1
  import { detectPackageManager } from "@withstudiocms/cli-kit/context";
2
2
  import { cancelMessage, getName } from "@withstudiocms/cli-kit/messages";
3
3
  import { cancel, isCancel } from "@withstudiocms/effect/clack";
4
- import chalk from "chalk";
5
4
  import { Context, Effect, genLogger, Layer, Option } from "../../effect.js";
6
5
  class CliContext extends Context.Tag("CliContext")() {
7
6
  static makeLayer = (context) => Layer.succeed(this, this.of(context));
@@ -18,9 +17,8 @@ const genContext = genLogger("studiocms/cli/utils/context.genContext")(function*
18
17
  );
19
18
  const cwd = process.cwd();
20
19
  const username = yield* Effect.tryPromise(() => getName());
21
- const exit = (code) => Effect.try(() => process.exit(code)).pipe(Effect.catchAll(() => Effect.succeed(void 0)));
20
+ const exit = (code) => Effect.try(() => process.exit(code)).pipe(Effect.catchAll(() => Effect.void));
22
21
  const context = {
23
- chalk,
24
22
  cwd,
25
23
  packageManager,
26
24
  username,
@@ -1,6 +1,6 @@
1
+ import { styleText } from "node:util";
1
2
  import { supportsColor } from "@withstudiocms/cli-kit/colors";
2
3
  import { date } from "@withstudiocms/cli-kit/messages";
3
- import chalk from "chalk";
4
4
  import { Effect } from "effect";
5
5
  let stdout = process.stdout;
6
6
  function setStdout(writable) {
@@ -14,7 +14,7 @@ const logger = {
14
14
  send(`DEBUG [${date}]: ${message}`);
15
15
  return;
16
16
  }
17
- send(`${chalk.blue.bold(`DEBUG [${date}]:`)} ${message}`);
17
+ send(`${styleText(["blue", "bold"], `DEBUG [${date}]:`)} ${message}`);
18
18
  }
19
19
  };
20
20
  const buildDebugLogger = Effect.fn(function* (debug) {
@@ -25,7 +25,7 @@ const buildDebugLogger = Effect.fn(function* (debug) {
25
25
  send(`DEBUG [${date}]: ${message}`);
26
26
  return;
27
27
  }
28
- send(`${chalk.blue.bold(`DEBUG [${date}]:`)} ${message}`);
28
+ send(`${styleText(["blue", "bold"], `DEBUG [${date}]:`)} ${message}`);
29
29
  })
30
30
  );
31
31
  });
@@ -1,16 +1,17 @@
1
+ import { styleText } from "node:util";
1
2
  import { makeScrypt, Password } from "@withstudiocms/auth-kit";
2
3
  import { PasswordModOptions } from "@withstudiocms/auth-kit/config";
3
4
  import { CheckIfUnsafe } from "@withstudiocms/auth-kit/utils/unsafeCheck";
4
- import chalk from "chalk";
5
5
  import dotenv from "dotenv";
6
6
  import { Effect, runEffect } from "../../effect.js";
7
7
  dotenv.config({ quiet: true });
8
8
  let { CMS_ENCRYPTION_KEY } = process.env;
9
9
  if (!CMS_ENCRYPTION_KEY) {
10
10
  console.warn(
11
- `${chalk.yellow.bold("Warning:")} ${chalk.yellow(
11
+ `${styleText(["yellow", "bold"], "Warning:")} ${styleText(
12
+ "yellow",
12
13
  "CMS_ENCRYPTION_KEY is not set... "
13
- )}${chalk.gray("Some commands may be disabled.")}`
14
+ )}${styleText("gray", "Some commands may be disabled.")}`
14
15
  );
15
16
  CMS_ENCRYPTION_KEY = "+URKVIiIM1kmG6g9Znb10g==";
16
17
  }
@@ -1 +1,3 @@
1
- export declare const setupDbStudio: import("astro-integration-kit").HookUtility<"astro:config:setup", [], Promise<void>>;
1
+ export declare const setupDbStudio: import("astro-integration-kit").HookUtility<"astro:config:setup", [opts: {
2
+ dialect: "libsql" | "postgres" | "mysql";
3
+ }], Promise<void>>;
@@ -1,15 +1,24 @@
1
1
  import createPathResolver from "@withstudiocms/internal_helpers/pathResolver";
2
- import { defineUtility } from "astro-integration-kit";
2
+ import { addVirtualImports, defineUtility } from "astro-integration-kit";
3
3
  const { resolve } = createPathResolver(import.meta.url);
4
- const setupDbStudio = defineUtility("astro:config:setup")(async (params) => {
5
- const { addDevToolbarApp } = params;
6
- addDevToolbarApp({
7
- id: "studiocms-db-viewer",
8
- entrypoint: resolve("../toolbar/db-viewer/index.js"),
9
- name: "Database Viewer",
10
- icon: '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6"><path stroke-linecap="round" stroke-linejoin="round" d="M20.25 6.375c0 2.278-3.694 4.125-8.25 4.125S3.75 8.653 3.75 6.375m16.5 0c0-2.278-3.694-4.125-8.25-4.125S3.75 4.097 3.75 6.375m16.5 0v11.25c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125V6.375m16.5 0v3.75m-16.5-3.75v3.75m16.5 0v3.75C20.25 16.153 16.556 18 12 18s-8.25-1.847-8.25-4.125v-3.75m16.5 0c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125" /></svg>'
11
- });
12
- });
4
+ const setupDbStudio = defineUtility("astro:config:setup")(
5
+ async (params, opts) => {
6
+ const { addDevToolbarApp } = params;
7
+ const { dialect } = opts;
8
+ addVirtualImports(params, {
9
+ name: "studiocms:db-studio",
10
+ imports: {
11
+ "virtual:studiocms/db-studio/connection": `export { createConnectionFromConfig } from '${resolve(`../toolbar/db-viewer/studio/virtual-connection/${dialect}.js`)}';`
12
+ }
13
+ });
14
+ addDevToolbarApp({
15
+ id: "studiocms-db-viewer",
16
+ entrypoint: resolve("../toolbar/db-viewer/index.js"),
17
+ name: "Database Viewer",
18
+ icon: '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6"><path stroke-linecap="round" stroke-linejoin="round" d="M20.25 6.375c0 2.278-3.694 4.125-8.25 4.125S3.75 8.653 3.75 6.375m16.5 0c0-2.278-3.694-4.125-8.25-4.125S3.75 4.097 3.75 6.375m16.5 0v11.25c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125V6.375m16.5 0v3.75m-16.5-3.75v3.75m16.5 0v3.75C20.25 16.153 16.556 18 12 18s-8.25-1.847-8.25-4.125v-3.75m16.5 0c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125" /></svg>'
19
+ });
20
+ }
21
+ );
13
22
  export {
14
23
  setupDbStudio
15
24
  };
package/dist/index.js CHANGED
@@ -19,7 +19,6 @@ import { envField } from "astro/config";
19
19
  import { addVirtualImports } from "astro-integration-kit";
20
20
  import dotenv from "dotenv";
21
21
  import { compare as semCompare } from "semver";
22
- import { loadEnv } from "vite";
23
22
  import {
24
23
  AstroConfigImageSettings,
25
24
  AstroConfigViteSettings,
@@ -48,7 +47,6 @@ const { name: pkgName, version: pkgVersion } = readJson(
48
47
  resolve("../package.json")
49
48
  );
50
49
  dotenv.config({ quiet: true });
51
- const env = loadEnv("", process.cwd(), "");
52
50
  const StudioCMSRendererComponentPath = "./virtuals/components/Renderer.astro";
53
51
  const CustomImageComponentPath = "./virtuals/components/CustomImage.astro";
54
52
  const builtInComponents = {
@@ -167,7 +165,6 @@ const studiocms = () => {
167
165
  dynamicWithAstroVirtual,
168
166
  buildDefaultOnlyVirtual,
169
167
  buildLoggerVirtual,
170
- buildNamedMultiExportVirtual,
171
168
  buildVirtualConfig
172
169
  } = VirtualModuleBuilder(resolve);
173
170
  const debugProvider = new DebugInfoProvider({
@@ -183,11 +180,6 @@ const studiocms = () => {
183
180
  "studiocms:plugins": buildDefaultOnlyVirtual(safePluginList),
184
181
  "studiocms:version": buildDefaultOnlyVirtual(pkgVersion),
185
182
  "studiocms:logger": buildLoggerVirtual(verbose),
186
- "virtual:studiocms/sdk/env": buildNamedMultiExportVirtual({
187
- dbUrl: env.ASTRO_DB_REMOTE_URL,
188
- dbSecret: env.ASTRO_DB_APP_TOKEN,
189
- cmsEncryptionKey: env.CMS_ENCRYPTION_KEY
190
- }),
191
183
  "studiocms:lib": dynamicVirtual([
192
184
  "./virtuals/lib/head.js",
193
185
  "./virtuals/lib/headDefaults.js",
@@ -222,9 +214,6 @@ const studiocms = () => {
222
214
  "studiocms:auth/utils/validImages": dynamicVirtual([
223
215
  "./virtuals/auth/validImages/index.js"
224
216
  ]),
225
- "studiocms:auth/utils/getLabelForPermissionLevel": dynamicVirtual([
226
- "./virtuals/auth/getLabelForPermissionLevel.js"
227
- ]),
228
217
  "studiocms:auth/scripts/three": ambientScripts(["./virtuals/auth/scripts/three.js"]),
229
218
  "studiocms:i18n/config": `export default ${JSON.stringify({ ...options.locale.i18n })}`,
230
219
  "studiocms:i18n/virtual": `
@@ -250,16 +239,13 @@ const studiocms = () => {
250
239
  "studiocms:i18n/plugins": dynamicVirtual(["./virtuals/i18n/plugin.js"]),
251
240
  "studiocms:sdk": dynamicVirtual(["./virtuals/sdk/index.js"]),
252
241
  "studiocms:sdk/types": dynamicVirtual(["./virtuals/sdk/types.js"]),
253
- "studiocms:astro-config/adapter": `export const adapter = ${JSON.stringify(
254
- config.adapter?.name || "unknown"
255
- )}`,
256
242
  "studiocms:debug-info": `export const debugInfo = ${JSON.stringify(debugOutput)};export default debugInfo;`,
257
243
  "studiocms:client-scripts/StorageFileBrowser": ambientScripts([
258
244
  "./virtuals/scripts/StorageFileBrowser.js"
259
245
  ])
260
246
  }
261
247
  });
262
- await setupDbStudio(params);
248
+ await setupDbStudio(params, options.db);
263
249
  integrationLogger(
264
250
  logInfo,
265
251
  "Updating Astro Config with StudioCMS Resources and settings..."
@@ -1,5 +1,9 @@
1
- import MySQLDriver from './drivers/mysql.js';
2
- import PostgresDriver from './drivers/postgres.js';
3
- import TursoDriver from './drivers/sqlite.js';
1
+ /**
2
+ * @packageDocumentation
3
+ * @module StudioCMS/Toolbar/DBViewer/Studio/Connection
4
+ *
5
+ * This module is used for providing types for our .d.ts files or the 'virtual:studiocms/db-studio/connection' module.
6
+ */
7
+ import type BaseDriver from './drivers/base.js';
4
8
  import type { JsonConnectionConfig } from './type.js';
5
- export declare function createConnectionFromConfig(configFile: string, config: JsonConnectionConfig): MySQLDriver | PostgresDriver | TursoDriver | undefined;
9
+ export declare function createConnectionFromConfig(_configFile: string, _config: JsonConnectionConfig): BaseDriver | undefined;
@@ -1,31 +1,5 @@
1
- import path from "node:path";
2
- import MySQLDriver from "./drivers/mysql.js";
3
- import PostgresDriver from "./drivers/postgres.js";
4
- import TursoDriver from "./drivers/sqlite.js";
5
- function createConnectionFromConfig(configFile, config) {
6
- const configPath = path.dirname(configFile);
7
- if (config.driver === "sqlite") {
8
- return new TursoDriver({
9
- url: `file:${path.join(configPath, config.connection.file)}`,
10
- attach: config.connection.attach ? Object.entries(config.connection.attach).reduce((a, [key, value]) => {
11
- a[key] = path.join(configPath, value);
12
- return a;
13
- }, {}) : void 0
14
- });
15
- }
16
- if (config.driver === "turso") {
17
- return new TursoDriver({
18
- url: config.connection.url,
19
- attach: config.connection.attach,
20
- token: config.connection.token
21
- });
22
- }
23
- if (config.driver === "mysql") {
24
- return new MySQLDriver(config.connection);
25
- }
26
- if (config.driver === "postgres") {
27
- return new PostgresDriver(config.connection);
28
- }
1
+ function createConnectionFromConfig(_configFile, _config) {
2
+ return void 0;
29
3
  }
30
4
  export {
31
5
  createConnectionFromConfig
@@ -0,0 +1,7 @@
1
+ import { Effect } from 'effect';
2
+ import type { TursoConfig } from '../type.js';
3
+ /**
4
+ * Effect to retrieve Turso (LibSQL) database configuration from environment variables.
5
+ */
6
+ declare const tursoConfig: Effect.Effect<TursoConfig, import("effect/ConfigError").ConfigError, never>;
7
+ export default tursoConfig;
@@ -0,0 +1,17 @@
1
+ import { Config, Effect, Redacted } from "effect";
2
+ const tursoConfig = Effect.gen(function* () {
3
+ const url = yield* Config.redacted("CMS_LIBSQL_URL");
4
+ const authToken = yield* Config.redacted("CMS_LIBSQL_AUTH_TOKEN");
5
+ const config = {
6
+ driver: "turso",
7
+ connection: {
8
+ url: Redacted.value(url),
9
+ token: Redacted.value(authToken)
10
+ }
11
+ };
12
+ return config;
13
+ });
14
+ var libsql_default = tursoConfig;
15
+ export {
16
+ libsql_default as default
17
+ };
@@ -0,0 +1,7 @@
1
+ import { Effect } from 'effect';
2
+ import type { MySqlConfig } from '../type.js';
3
+ /**
4
+ * Effect to retrieve MySQL database configuration from environment variables.
5
+ */
6
+ declare const mysqlConfig: Effect.Effect<MySqlConfig, import("effect/ConfigError").ConfigError, never>;
7
+ export default mysqlConfig;
@@ -0,0 +1,23 @@
1
+ import { Config, Effect, Redacted } from "effect";
2
+ const mysqlConfig = Effect.gen(function* () {
3
+ const database = yield* Config.string("CMS_MYSQL_DATABASE");
4
+ const host = yield* Config.string("CMS_MYSQL_HOST");
5
+ const port = yield* Config.number("CMS_MYSQL_PORT");
6
+ const user = yield* Config.redacted("CMS_MYSQL_USER");
7
+ const password = yield* Config.redacted("CMS_MYSQL_PASSWORD");
8
+ const config = {
9
+ driver: "mysql",
10
+ connection: {
11
+ database,
12
+ host,
13
+ port,
14
+ user: Redacted.value(user),
15
+ password: Redacted.value(password)
16
+ }
17
+ };
18
+ return config;
19
+ });
20
+ var mysql_default = mysqlConfig;
21
+ export {
22
+ mysql_default as default
23
+ };
@@ -0,0 +1,7 @@
1
+ import { Effect } from 'effect';
2
+ import type { PostgresConfig } from '../type.js';
3
+ /**
4
+ * Effect to retrieve Postgres database configuration from environment variables.
5
+ */
6
+ declare const postgresConfig: Effect.Effect<PostgresConfig, import("effect/ConfigError").ConfigError, never>;
7
+ export default postgresConfig;
@@ -0,0 +1,23 @@
1
+ import { Config, Effect, Redacted } from "effect";
2
+ const postgresConfig = Effect.gen(function* () {
3
+ const database = yield* Config.string("CMS_PG_DATABASE");
4
+ const host = yield* Config.string("CMS_PG_HOST");
5
+ const port = yield* Config.number("CMS_PG_PORT");
6
+ const user = yield* Config.redacted("CMS_PG_USER");
7
+ const password = yield* Config.redacted("CMS_PG_PASSWORD");
8
+ const config = {
9
+ driver: "postgres",
10
+ connection: {
11
+ database,
12
+ host,
13
+ port,
14
+ user: Redacted.value(user),
15
+ password: Redacted.value(password)
16
+ }
17
+ };
18
+ return config;
19
+ });
20
+ var postgres_default = postgresConfig;
21
+ export {
22
+ postgres_default as default
23
+ };
@@ -1,73 +1,37 @@
1
1
  import { root } from "astro:config/server";
2
2
  import { db } from "studiocms:config";
3
+ import { createConnectionFromConfig } from "virtual:studiocms/db-studio/connection";
3
4
  import { runEffect } from "@withstudiocms/effect";
4
- import { Config, Effect, Redacted } from "effect";
5
- import { createConnectionFromConfig } from "./connection.js";
5
+ import tursoConfig from "./env/libsql.js";
6
+ import mysqlConfig from "./env/mysql.js";
7
+ import postgresConfig from "./env/postgres.js";
6
8
  export * from "../db-shared-types.js";
7
9
  import { default as default2 } from "./drivers/base.js";
8
10
  export * from "./type.js";
9
11
  async function getDialectConfig() {
12
+ let configEffect;
10
13
  switch (db.dialect) {
11
14
  case "libsql": {
12
- return await runEffect(
13
- Effect.gen(function* () {
14
- const url = yield* Config.redacted("CMS_LIBSQL_URL");
15
- const authToken = yield* Config.redacted("CMS_LIBSQL_AUTH_TOKEN");
16
- const config = {
17
- driver: "turso",
18
- connection: {
19
- url: Redacted.value(url),
20
- token: Redacted.value(authToken)
21
- }
22
- };
23
- return config;
24
- })
25
- );
15
+ configEffect = tursoConfig;
16
+ break;
26
17
  }
27
18
  case "mysql": {
28
- return runEffect(
29
- Effect.gen(function* () {
30
- const database = yield* Config.string("CMS_MYSQL_DATABASE");
31
- const host = yield* Config.string("CMS_MYSQL_HOST");
32
- const port = yield* Config.number("CMS_MYSQL_PORT");
33
- const user = yield* Config.redacted("CMS_MYSQL_USER");
34
- const password = yield* Config.redacted("CMS_MYSQL_PASSWORD");
35
- const config = {
36
- driver: "mysql",
37
- connection: {
38
- database,
39
- host,
40
- port,
41
- user: Redacted.value(user),
42
- password: Redacted.value(password)
43
- }
44
- };
45
- return config;
46
- })
47
- );
19
+ configEffect = mysqlConfig;
20
+ break;
48
21
  }
49
22
  case "postgres": {
50
- return runEffect(
51
- Effect.gen(function* () {
52
- const database = yield* Config.string("CMS_PG_DATABASE");
53
- const host = yield* Config.string("CMS_PG_HOST");
54
- const port = yield* Config.number("CMS_PG_PORT");
55
- const user = yield* Config.redacted("CMS_PG_USER");
56
- const password = yield* Config.redacted("CMS_PG_PASSWORD");
57
- const config = {
58
- driver: "postgres",
59
- connection: {
60
- database,
61
- host,
62
- port,
63
- user: Redacted.value(user),
64
- password: Redacted.value(password)
65
- }
66
- };
67
- return config;
68
- })
69
- );
23
+ configEffect = postgresConfig;
24
+ break;
70
25
  }
26
+ default: {
27
+ throw new Error(`Unsupported database dialect: ${db.dialect}`);
28
+ }
29
+ }
30
+ try {
31
+ const config = await runEffect(configEffect);
32
+ return config;
33
+ } catch (error) {
34
+ throw new Error(`Failed to retrieve database configuration: ${error.message}`);
71
35
  }
72
36
  }
73
37
  async function getDriver() {
@@ -1,4 +1,3 @@
1
- import type { ClientConfig } from 'pg';
2
1
  export interface TursoConfig {
3
2
  driver: 'turso';
4
3
  connection: {
@@ -26,7 +25,7 @@ interface SqliteConfig {
26
25
  }
27
26
  export interface PostgresConfig {
28
27
  driver: 'postgres';
29
- connection: ClientConfig;
28
+ connection: import('pg').ClientConfig;
30
29
  }
31
30
  export type JsonConnectionConfig = TursoConfig | SqliteConfig | MySqlConfig | PostgresConfig;
32
31
  export {};
@@ -0,0 +1,3 @@
1
+ import TursoDriver from '../drivers/sqlite.js';
2
+ import type { JsonConnectionConfig } from '../type.js';
3
+ export declare function createConnectionFromConfig(configFile: string, config: JsonConnectionConfig): TursoDriver | undefined;
@@ -0,0 +1,24 @@
1
+ import path from "node:path";
2
+ import TursoDriver from "../drivers/sqlite.js";
3
+ function createConnectionFromConfig(configFile, config) {
4
+ const configPath = path.dirname(configFile);
5
+ if (config.driver === "sqlite") {
6
+ return new TursoDriver({
7
+ url: `file:${path.join(configPath, config.connection.file)}`,
8
+ attach: config.connection.attach ? Object.entries(config.connection.attach).reduce((a, [key, value]) => {
9
+ a[key] = path.join(configPath, value);
10
+ return a;
11
+ }, {}) : void 0
12
+ });
13
+ }
14
+ if (config.driver === "turso") {
15
+ return new TursoDriver({
16
+ url: config.connection.url,
17
+ attach: config.connection.attach,
18
+ token: config.connection.token
19
+ });
20
+ }
21
+ }
22
+ export {
23
+ createConnectionFromConfig
24
+ };
@@ -0,0 +1,3 @@
1
+ import MySQLDriver from '../drivers/mysql.js';
2
+ import type { JsonConnectionConfig } from '../type.js';
3
+ export declare function createConnectionFromConfig(_configFile: string, config: JsonConnectionConfig): MySQLDriver | undefined;
@@ -0,0 +1,9 @@
1
+ import MySQLDriver from "../drivers/mysql.js";
2
+ function createConnectionFromConfig(_configFile, config) {
3
+ if (config.driver === "mysql") {
4
+ return new MySQLDriver(config.connection);
5
+ }
6
+ }
7
+ export {
8
+ createConnectionFromConfig
9
+ };
@@ -0,0 +1,3 @@
1
+ import PostgresDriver from '../drivers/postgres.js';
2
+ import type { JsonConnectionConfig } from '../type.js';
3
+ export declare function createConnectionFromConfig(_configFile: string, config: JsonConnectionConfig): PostgresDriver | undefined;
@@ -0,0 +1,9 @@
1
+ import PostgresDriver from "../drivers/postgres.js";
2
+ function createConnectionFromConfig(_configFile, config) {
3
+ if (config.driver === "postgres") {
4
+ return new PostgresDriver(config.connection);
5
+ }
6
+ }
7
+ export {
8
+ createConnectionFromConfig
9
+ };
package/dist/virtual.d.ts CHANGED
@@ -30,10 +30,6 @@ declare module 'studiocms:debug-info' {
30
30
  export default debugInfo;
31
31
  }
32
32
 
33
- declare module 'studiocms:astro-config/adapter' {
34
- export const adapter: string;
35
- }
36
-
37
33
  declare module 'studiocms:dashboard/augments/components' {
38
34
  export const componentKeys: string[];
39
35
  }
@@ -302,17 +298,6 @@ declare module 'studiocms:component-registry/runtime' {
302
298
  export type ComponentRegistryEntry =
303
299
  import('@withstudiocms/component-registry/runtime').ComponentRegistryEntry;
304
300
 
305
- /**
306
- * Imports components by their keys from the 'studiocms:markdown-remark/user-components' module.
307
- *
308
- * @param keys - An array of strings representing the keys of the components to import.
309
- * @returns A promise that resolves to an object containing the imported components.
310
- * @throws {MarkdownRemarkError} If any component fails to import, an error is thrown with a prefixed message.
311
- * @deprecated This function is deprecated and will be removed in future versions.
312
- * Use `getRendererComponents` instead for importing components from the component registry.
313
- */
314
- export const importComponentsKeys: typeof import('@withstudiocms/component-registry/runtime').importComponentsKeys;
315
-
316
301
  /**
317
302
  * @returns A promise that resolves to an object containing the imported components.
318
303
  */
@@ -491,13 +476,6 @@ declare module 'studiocms:auth/utils/validImages' {
491
476
  export const validImages: typeof import('./virtuals/auth/validImages/index.js').validImages;
492
477
  }
493
478
 
494
- declare module 'studiocms:auth/utils/getLabelForPermissionLevel' {
495
- /**
496
- * @deprecated Use Translation system under the `@studiocms/dashboard:user-component` entry
497
- */
498
- export const getLabelForPermissionLevel: typeof import('./virtuals/auth/getLabelForPermissionLevel.js').getLabelForPermissionLevel;
499
- }
500
-
501
479
  declare module 'studiocms:auth/scripts/three' {
502
480
  /**
503
481
  * This module should be imported within a script tag.
@@ -588,12 +566,6 @@ declare module 'studiocms:renderer' {
588
566
  export const StudioCMSRenderer: typeof import('./virtuals/components/Renderer.astro').default;
589
567
  }
590
568
 
591
- declare module 'virtual:studiocms/sdk/env' {
592
- export const dbUrl: string;
593
- export const dbSecret: string;
594
- export const cmsEncryptionKey: string;
595
- }
596
-
597
569
  declare module 'virtual:studiocms/sitemaps' {
598
570
  export const sitemaps: string[];
599
571
  }
@@ -647,6 +619,18 @@ declare module 'studiocms:plugins/auth/providers' {
647
619
  export const oAuthProviders: OAuthProviders;
648
620
  }
649
621
 
622
+ declare module 'virtual:studiocms/db-studio/connection' {
623
+ /**
624
+ * Creates a database connection from the provided configuration.
625
+ *
626
+ * @param configFile - The path to the database configuration file.
627
+ * @param config - The database configuration object.
628
+ *
629
+ * @returns The desired database connection for the configured dialect
630
+ */
631
+ export const createConnectionFromConfig: typeof import('./toolbar/db-viewer/studio/connection').createConnectionFromConfig;
632
+ }
633
+
650
634
  interface StudioCMSSecurityLocals {
651
635
  userSessionData: import('./virtuals/auth/types').UserSessionData;
652
636
  emailVerificationEnabled: boolean;
@@ -27,7 +27,7 @@ const makePageTitle = (
27
27
  };
28
28
 
29
29
  interface Props extends ComponentProps<typeof BaseLayout> {
30
- config: DynamicConfigEntry<StudioCMSSiteConfig>;
30
+ config: DynamicConfigEntry<Pick<StudioCMSSiteConfig, 'title' | 'description'>>;
31
31
  sidebar?: false | 'single' | 'double';
32
32
  requiredPermission?: AvailablePermissionRanks | 'none';
33
33
  currentUser: UserSessionData | null;
@@ -1,15 +1,12 @@
1
1
  ---
2
+ import { config } from 'studiocms:config';
2
3
  import '../styles/404.css';
3
4
  import { useTranslations } from 'studiocms:i18n';
4
5
  import { Button } from 'studiocms:ui/components/button';
5
6
  import Layout from '../layouts/DashboardLayout.astro';
6
7
 
7
- const lang = Astro.locals.StudioCMS.defaultLang;
8
+ const lang = config.locale.i18n.defaultLocale;
8
9
  const t = useTranslations(lang, '@studiocms/dashboard:404');
9
-
10
- const { siteConfig: config, security } = Astro.locals.StudioCMS;
11
-
12
- const currentUser = security?.userSessionData ?? null;
13
10
  ---
14
11
 
15
12
  <Layout
@@ -17,9 +14,9 @@ const currentUser = security?.userSessionData ?? null;
17
14
  description={t('description')}
18
15
  sidebar={false}
19
16
  requiredPermission="none"
20
- {lang}
21
- {config}
22
- {currentUser}>
17
+ config={{ data: { title: t('title'), description: t('description') }, id: '' }}
18
+ currentUser={null}
19
+ {lang}>
23
20
  <div class="notfound-container">
24
21
  <div class="notfound">
25
22
  <svg viewBox="0 0 755 792" fill="none" xmlns="http://www.w3.org/2000/svg">
@@ -356,12 +356,6 @@ const router = {
356
356
  if (!checkEmail.success)
357
357
  return yield* badFormDataEntry('Invalid email', checkEmail.error.message);
358
358
 
359
- const invalidEmailDomains: string[] = ['example.com', 'test.com', 'testing.com'];
360
-
361
- if (invalidEmailDomains.includes(checkEmail.data.split('@')[1])) {
362
- return yield* badFormDataEntry('Invalid Email', 'Must be from a valid domain');
363
- }
364
-
365
359
  const { usernameSearch, emailSearch } =
366
360
  yield* sdk.AUTH.user.searchUsersForUsernameOrEmail(username, checkEmail.data);
367
361
 
@@ -29,7 +29,7 @@ function ensureStringArray(val: string | string[] | undefined): string[] {
29
29
  *
30
30
  * Fields:
31
31
  * - `title`: Required string. The title of the page. Must not be empty.
32
- * - `slug`: Required string. Must be lowercase, only contain letters, numbers, and hyphens (no leading/trailing hyphens).
32
+ * - `slug`: Required string. Must be lowercase, only contain letters, numbers, hyphens, and slashes (no leading/trailing hyphens or slashes).
33
33
  * - `description`: Optional string. A description of the page.
34
34
  * - `package`: Required string. The package associated with the page.
35
35
  * - `showOnNav`: Optional boolean (default: false). Whether to show the page in navigation.
@@ -45,9 +45,9 @@ function ensureStringArray(val: string | string[] | undefined): string[] {
45
45
  */
46
46
  export const studioCMSCreatePageDataSchema = z.object({
47
47
  title: z.string().min(1, { message: 'Title is required' }),
48
- slug: z.string().refine((val) => /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(val), {
48
+ slug: z.string().refine((val) => /^[a-z0-9]+(?:[-/][a-z0-9]+)*$/.test(val), {
49
49
  message:
50
- 'Slug must be lowercase and can only contain letters, numbers, and hyphens (no leading/trailing hyphens)',
50
+ 'Slug must be lowercase and can only contain letters, numbers, hyphens, and slashes (no leading/trailing hyphens or slashes)',
51
51
  }),
52
52
  description: z.string().optional(),
53
53
  package: z.string(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "studiocms",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A Community-Driven Astro native CMS. Built from the ground up by the Astro community.",
5
5
  "author": {
6
6
  "name": "withstudiocms",
@@ -222,17 +222,16 @@
222
222
  "type": "module",
223
223
  "dependencies": {
224
224
  "@iconify-json/flat-color-icons": "^1.2.3",
225
- "@iconify-json/simple-icons": "^1.2.66",
225
+ "@iconify-json/simple-icons": "^1.2.68",
226
226
  "@iconify-json/circle-flags": "^1.2.10",
227
- "@inox-tools/runtime-logger": "^0.7.0",
227
+ "@inox-tools/runtime-logger": "^0.7.1",
228
228
  "@nanostores/i18n": "^1.2.2",
229
- "@nanostores/persistent": "^1.2.0",
229
+ "@nanostores/persistent": "^1.3.0",
230
230
  "@outerbase/sdk-transform": "^1.0.8",
231
- "@studiocms/ui": "^1.0.1",
232
- "ace-builds": "^1.43.5",
231
+ "@studiocms/ui": "^1.1.1",
232
+ "ace-builds": "^1.43.6",
233
233
  "astro-integration-kit": "^0.19.1",
234
234
  "boxen": "^8.0.1",
235
- "chalk": "^5.6.2",
236
235
  "diff": "^8.0.3",
237
236
  "dompurify": "^3.3.1",
238
237
  "dotenv": "^17.2.3",
@@ -251,15 +250,15 @@
251
250
  "tinyglobby": "^0.2.15",
252
251
  "ultrahtml": "^1.6.0",
253
252
  "web-vitals": "^5.1.0",
254
- "@withstudiocms/internal_helpers": "^0.1.0",
255
- "@withstudiocms/auth-kit": "^0.1.2",
256
- "@withstudiocms/config-utils": "^0.1.0",
257
- "@withstudiocms/component-registry": "^0.1.2",
253
+ "@withstudiocms/internal_helpers": "^0.1.1",
254
+ "@withstudiocms/component-registry": "^0.1.3",
258
255
  "@withstudiocms/cli-kit": "^0.2.0",
259
- "@withstudiocms/effect": "^0.2.0",
260
- "@withstudiocms/kysely": "^0.2.0",
256
+ "@withstudiocms/auth-kit": "^0.1.3",
257
+ "@withstudiocms/config-utils": "^0.1.0",
258
+ "@withstudiocms/effect": "^0.3.0",
261
259
  "@withstudiocms/template-lang": "^0.1.0",
262
- "@withstudiocms/sdk": "^0.2.0"
260
+ "@withstudiocms/sdk": "^0.2.0",
261
+ "@withstudiocms/kysely": "^0.2.0"
263
262
  },
264
263
  "devDependencies": {
265
264
  "@types/mdast": "^4.0.4",
@@ -274,9 +273,9 @@
274
273
  "peerDependencies": {
275
274
  "@libsql/client": "^0.15.15",
276
275
  "astro": "^5.12.9",
277
- "effect": "^3.19.14",
278
- "pg": "^8.17.1",
279
- "mysql2": "^3.16.0"
276
+ "effect": "^3.19.15",
277
+ "pg": "^8.17.2",
278
+ "mysql2": "^3.16.2"
280
279
  },
281
280
  "peerDependenciesMeta": {
282
281
  "@libsql/client": {