@baclet/cli 0.1.3 → 0.1.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/README.md CHANGED
@@ -26,12 +26,13 @@ Node.js 18 or later is required.
26
26
  | --- | --- |
27
27
  | `baclet login [--qr\|--link]` | Authorize this machine with a QR code, a link, or both. |
28
28
  | `baclet logout` | Remove local credentials and revoke the CLI token. |
29
- | `baclet whoami` | Show the authorized account. |
29
+ | `baclet whoami` | Show the authorized user's name and email. |
30
30
  | `baclet init [--publishable-key KEY]` | Create `baclet.config.ts`, selecting a project when logged in. |
31
31
  | `baclet projects list` | List projects you can access. |
32
32
  | `baclet db status` | Print the schema diff without applying it. |
33
33
  | `baclet db push [--yes]` | Apply the schema diff after confirmation. |
34
34
  | `baclet db migrate [--yes]` | Alias for `db push`. |
35
+ | `baclet --version` | Print the CLI version. |
35
36
 
36
37
  ## Login
37
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baclet/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "BACLET command line tool for authentication and schema pushes",
5
5
  "type": "module",
6
6
  "bin": {
@@ -74,6 +74,6 @@ export async function whoami() {
74
74
  const creds = await requireCredentials();
75
75
  const payload = await request({ method: "GET", path: "/api/v1/me", token: creds.accessToken });
76
76
  const profile = payload.user || payload;
77
- console.log(`${profile.fullName || profile.email} <${profile.email}>`);
78
- console.log(`User ID: ${profile.id}`);
77
+ const name = profile.full_name || profile.fullName || profile.email;
78
+ console.log(name === profile.email ? profile.email : `${name} <${profile.email}>`);
79
79
  }
package/src/config.js CHANGED
@@ -31,6 +31,21 @@ function isModel(value) {
31
31
  return !!value && typeof value === "object" && typeof value.name === "string" && !!value.fields && typeof value.fields === "object";
32
32
  }
33
33
 
34
+ function columnName(field) {
35
+ if (!field || field.includes("_") || field.toLowerCase() === field) return field;
36
+ return field.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
37
+ }
38
+
39
+ function normalizeModel(model) {
40
+ const fields = {};
41
+ for (const [name, field] of Object.entries(model.fields)) {
42
+ fields[columnName(name)] = field;
43
+ }
44
+ if (!fields.created_at) fields.created_at = { type: "timestamp", default: { expr: "now()" } };
45
+ if (!fields.updated_at) fields.updated_at = { type: "timestamp", default: { expr: "now()" } };
46
+ return { ...model, fields };
47
+ }
48
+
34
49
  export async function loadProject(cwd = process.cwd()) {
35
50
  const configPath = await findConfig(cwd);
36
51
  const root = path.dirname(configPath);
@@ -82,9 +97,10 @@ export async function loadProject(cwd = process.cwd()) {
82
97
  for (const module of Object.values(namespace)) {
83
98
  for (const value of Object.values(module)) {
84
99
  if (!isModel(value)) continue;
85
- if (seen.has(value.name)) throw new Error(`Duplicate model name "${value.name}".`);
86
- seen.add(value.name);
87
- models.push(value);
100
+ const model = normalizeModel(value);
101
+ if (seen.has(model.name)) throw new Error(`Duplicate model name "${model.name}".`);
102
+ seen.add(model.name);
103
+ models.push(model);
88
104
  }
89
105
  }
90
106
  if (!models.length) throw new Error("No models found. Export defineModel(...) objects from your model files.");
package/src/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
2
3
  import { login, logout, whoami } from "./commands/auth.js";
3
4
  import { init, listProjects, dbStatus, dbPush } from "./commands/project.js";
4
5
 
6
+ const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
7
+
5
8
  const help = `BACLET CLI
6
9
 
7
10
  Usage:
@@ -13,11 +16,8 @@ Usage:
13
16
  baclet db status Show the schema diff without applying it
14
17
  baclet db push [--yes] Apply the schema to your project database
15
18
  baclet db migrate [--yes] Alias for db push
19
+ baclet --version Print the CLI version
16
20
  baclet --help Show this message
17
-
18
- Environment:
19
- BACLET_API_URL API base URL (default https://api.baclet.app)
20
- BACLET_DASHBOARD_URL Dashboard URL (default https://baclet.app)
21
21
  `;
22
22
 
23
23
  async function main() {
@@ -34,6 +34,10 @@ async function main() {
34
34
  if (args[0] === "status") return dbStatus();
35
35
  if (args[0] === "push" || args[0] === "migrate") return dbPush(args.slice(1));
36
36
  throw new Error("Usage: baclet db status|push|migrate");
37
+ case "--version":
38
+ case "-v":
39
+ process.stdout.write(`${version}\n`);
40
+ return;
37
41
  case "--help":
38
42
  case "-h":
39
43
  case undefined: