simplemdg-dev-cli 1.5.1 → 2.4.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.
Files changed (140) hide show
  1. package/README.md +65 -243
  2. package/USER_GUIDE.md +55 -249
  3. package/dist/commands/cds.command.js +69 -60
  4. package/dist/commands/cds.command.js.map +1 -1
  5. package/dist/commands/cf-db.command.d.ts +2 -0
  6. package/dist/commands/cf-db.command.js +606 -0
  7. package/dist/commands/cf-db.command.js.map +1 -0
  8. package/dist/commands/cf.command.js +1625 -198
  9. package/dist/commands/cf.command.js.map +1 -1
  10. package/dist/commands/gitlab.command.d.ts +2 -0
  11. package/dist/commands/gitlab.command.js +351 -0
  12. package/dist/commands/gitlab.command.js.map +1 -0
  13. package/dist/commands/npmrc.command.js +50 -44
  14. package/dist/commands/npmrc.command.js.map +1 -1
  15. package/dist/core/cache.d.ts +1 -1
  16. package/dist/core/cache.js +58 -31
  17. package/dist/core/cache.js.map +1 -1
  18. package/dist/core/cds.js +32 -22
  19. package/dist/core/cds.js.map +1 -1
  20. package/dist/core/cf-env-parser.d.ts +1 -1
  21. package/dist/core/cf-env-parser.js +4 -1
  22. package/dist/core/cf-env-parser.js.map +1 -1
  23. package/dist/core/cf.d.ts +1 -1
  24. package/dist/core/cf.js +46 -31
  25. package/dist/core/cf.js.map +1 -1
  26. package/dist/core/db/db-btp.d.ts +48 -0
  27. package/dist/core/db/db-btp.js +162 -0
  28. package/dist/core/db/db-btp.js.map +1 -0
  29. package/dist/core/db/db-cache.d.ts +35 -0
  30. package/dist/core/db/db-cache.js +164 -0
  31. package/dist/core/db/db-cache.js.map +1 -0
  32. package/dist/core/db/db-connection.d.ts +22 -0
  33. package/dist/core/db/db-connection.js +73 -0
  34. package/dist/core/db/db-connection.js.map +1 -0
  35. package/dist/core/db/db-crypto.d.ts +3 -0
  36. package/dist/core/db/db-crypto.js +54 -0
  37. package/dist/core/db/db-crypto.js.map +1 -0
  38. package/dist/core/db/db-hana-adapter.d.ts +32 -0
  39. package/dist/core/db/db-hana-adapter.js +243 -0
  40. package/dist/core/db/db-hana-adapter.js.map +1 -0
  41. package/dist/core/db/db-metadata.d.ts +25 -0
  42. package/dist/core/db/db-metadata.js +150 -0
  43. package/dist/core/db/db-metadata.js.map +1 -0
  44. package/dist/core/db/db-postgres-adapter.d.ts +30 -0
  45. package/dist/core/db/db-postgres-adapter.js +245 -0
  46. package/dist/core/db/db-postgres-adapter.js.map +1 -0
  47. package/dist/core/db/db-query-files.d.ts +20 -0
  48. package/dist/core/db/db-query-files.js +106 -0
  49. package/dist/core/db/db-query-files.js.map +1 -0
  50. package/dist/core/db/db-query-history.d.ts +5 -0
  51. package/dist/core/db/db-query-history.js +49 -0
  52. package/dist/core/db/db-query-history.js.map +1 -0
  53. package/dist/core/db/db-row.d.ts +22 -0
  54. package/dist/core/db/db-row.js +70 -0
  55. package/dist/core/db/db-row.js.map +1 -0
  56. package/dist/core/db/db-studio-html.d.ts +4 -0
  57. package/dist/core/db/db-studio-html.js +437 -0
  58. package/dist/core/db/db-studio-html.js.map +1 -0
  59. package/dist/core/db/db-studio-server.d.ts +11 -0
  60. package/dist/core/db/db-studio-server.js +465 -0
  61. package/dist/core/db/db-studio-server.js.map +1 -0
  62. package/dist/core/db/db-types.d.ts +174 -0
  63. package/dist/core/db/db-types.js +3 -0
  64. package/dist/core/db/db-types.js.map +1 -0
  65. package/dist/core/db/db-vcap-parser.d.ts +7 -0
  66. package/dist/core/db/db-vcap-parser.js +137 -0
  67. package/dist/core/db/db-vcap-parser.js.map +1 -0
  68. package/dist/core/doctor.d.ts +1 -1
  69. package/dist/core/doctor.js +14 -8
  70. package/dist/core/doctor.js.map +1 -1
  71. package/dist/core/guide.js +31 -26
  72. package/dist/core/guide.js.map +1 -1
  73. package/dist/core/install.d.ts +1 -1
  74. package/dist/core/install.js +17 -11
  75. package/dist/core/install.js.map +1 -1
  76. package/dist/core/navigator.d.ts +17 -0
  77. package/dist/core/navigator.js +140 -0
  78. package/dist/core/navigator.js.map +1 -0
  79. package/dist/core/npmrc.js +29 -16
  80. package/dist/core/npmrc.js.map +1 -1
  81. package/dist/core/process.js +11 -6
  82. package/dist/core/process.js.map +1 -1
  83. package/dist/core/prompts.js +16 -8
  84. package/dist/core/prompts.js.map +1 -1
  85. package/dist/core/repository.d.ts +1 -1
  86. package/dist/core/repository.js +16 -9
  87. package/dist/core/repository.js.map +1 -1
  88. package/dist/core/scanner.d.ts +1 -1
  89. package/dist/core/scanner.js +13 -7
  90. package/dist/core/scanner.js.map +1 -1
  91. package/dist/core/tooling.d.ts +28 -0
  92. package/dist/core/tooling.js +168 -0
  93. package/dist/core/tooling.js.map +1 -0
  94. package/dist/core/types.js +2 -1
  95. package/dist/core/version-conflict.d.ts +2 -2
  96. package/dist/core/version-conflict.js +11 -6
  97. package/dist/core/version-conflict.js.map +1 -1
  98. package/dist/index.js +65 -48
  99. package/dist/index.js.map +1 -1
  100. package/dist/types-local.js +2 -1
  101. package/package.json +12 -6
  102. package/src/commands/cds.command.ts +529 -0
  103. package/src/commands/cf-db.command.ts +636 -0
  104. package/src/commands/cf.command.ts +3345 -0
  105. package/src/commands/gitlab.command.ts +373 -0
  106. package/src/commands/npmrc.command.ts +581 -0
  107. package/src/core/cache.ts +332 -0
  108. package/src/core/cds.ts +278 -0
  109. package/src/core/cf-env-parser.ts +131 -0
  110. package/src/core/cf.ts +271 -0
  111. package/src/core/db/db-btp.ts +207 -0
  112. package/src/core/db/db-cache.ts +215 -0
  113. package/src/core/db/db-connection.ts +79 -0
  114. package/src/core/db/db-crypto.ts +53 -0
  115. package/src/core/db/db-hana-adapter.ts +294 -0
  116. package/src/core/db/db-metadata.ts +174 -0
  117. package/src/core/db/db-postgres-adapter.ts +275 -0
  118. package/src/core/db/db-query-files.ts +130 -0
  119. package/src/core/db/db-query-history.ts +53 -0
  120. package/src/core/db/db-row.ts +93 -0
  121. package/src/core/db/db-studio-html.ts +439 -0
  122. package/src/core/db/db-studio-server.ts +559 -0
  123. package/src/core/db/db-types.ts +195 -0
  124. package/src/core/db/db-vcap-parser.ts +182 -0
  125. package/src/core/doctor.ts +70 -0
  126. package/src/core/guide.ts +261 -0
  127. package/src/core/install.ts +91 -0
  128. package/src/core/navigator.ts +164 -0
  129. package/src/core/npmrc.ts +171 -0
  130. package/src/core/process.ts +75 -0
  131. package/src/core/prompts.ts +225 -0
  132. package/src/core/repository.ts +36 -0
  133. package/src/core/scanner.ts +41 -0
  134. package/src/core/tooling.ts +207 -0
  135. package/src/core/types.ts +152 -0
  136. package/src/core/version-conflict.ts +46 -0
  137. package/src/index.ts +460 -0
  138. package/src/types/external.d.ts +3 -0
  139. package/src/types-local.ts +11 -0
  140. package/tsconfig.json +17 -0
package/README.md CHANGED
@@ -1,283 +1,105 @@
1
- # SimpleMDG Dev CLI Guide
1
+ # SimpleMDG Dev CLI
2
2
 
3
- ## Purpose
3
+ SimpleMDG local development helper for npm install workflows, SAP CAP, Cloud Foundry/BTP, request tracing, GitLab sync, and BTP database exploration.
4
4
 
5
- `simplemdg-dev-cli` helps SimpleMDG developers run common local development and BTP tasks without remembering long commands.
5
+ ## Install local package
6
6
 
7
- Main command:
8
-
9
- ```bash
10
- smdg
11
- ```
12
-
13
- Install:
14
-
15
- ```bash
16
- npm i -g simplemdg-dev-cli@latest
17
- ```
18
-
19
- Open this guide:
20
-
21
- ```bash
22
- smdg guide
23
- ```
24
-
25
- ---
26
-
27
- # Select Usage
28
-
29
- When the CLI shows a select list:
30
-
31
- * Type a few characters to search.
32
- * Use `↑` and `↓` to move.
33
- * Press `Enter` to select.
34
- * If no item matches, some prompts allow using the typed value.
35
-
36
- This is useful for long lists of BTP orgs, spaces, apps, package IDs, CAP profiles, and CDS services.
37
-
38
- ---
39
-
40
- # Common Commands
41
-
42
- ## `smdg npmrc import`
43
-
44
- Import SimpleMDG GitLab package IDs into local cache.
45
-
46
- Use this after downloading the package ID import file from the team.
47
-
48
- ```bash
49
- smdg npmrc import
7
+ ```powershell
8
+ npm install -g .\simplemdg-dev-cli-2.4.0.tgz --force
9
+ smdg -V
50
10
  ```
51
11
 
52
- ## `smdg npmrc create`
12
+ ## Prerequisites & auto-install
53
13
 
54
- Create `.npmrc` for SimpleMDG private npm packages.
14
+ Some commands rely on external CLIs: `cf` (Cloud Foundry), `cds` (SAP CAP), and `git`. The CLI checks for these **before** running an interactive flow — so you are not asked for credentials only to fail at the end. If a tool is missing, it offers to install it via a detected package manager (`choco`/`brew` for `cf`, `winget`/`choco`/`scoop`/`brew`/`apt-get` for `git`, `npm -g` for `@sap/cds-dk`), or prints the official install link when no manager is available. After installing a tool, open a new terminal so PATH refreshes.
55
15
 
56
- ```bash
57
- smdg npmrc create
58
- ```
16
+ ## Main commands
59
17
 
60
- The CLI helps select package name/package ID and token from cache.
61
-
62
- ## `smdg i`
63
-
64
- Install dependencies for the current project.
65
-
66
- ```bash
18
+ ```powershell
67
19
  smdg i
68
- ```
69
-
70
- It can scan variables such as `${SIMPLEMDG_BRANCH}` and ask for replacement values automatically.
71
-
72
- ## `smdg cf login`
73
-
74
- Login to BTP Cloud Foundry.
75
-
76
- ```bash
77
20
  smdg cf login
78
- ```
79
-
80
- The CLI helps select API endpoint, org, and space.
81
-
82
- It can save login information on your local machine so later commands can re-login automatically when the CF session expires.
83
-
84
- ## `smdg cf org`
85
-
86
- Search, list, and switch Cloud Foundry orgs across regions.
87
-
88
- ```bash
89
- smdg cf org
90
- ```
91
-
92
- The CLI scans known BTP region endpoints and shows orgs in one searchable list.
93
-
94
- The list includes region information, for example:
95
-
96
- ```txt
97
- arthrex-dev-simplemdg eu10 · 1 space
98
- alcon-dev-simplemdg br10 · 1 space
99
- ait-dev-simplemdg us21 · 1 space
100
- ```
101
-
102
- Use this when you have many orgs across many BTP regions.
103
-
104
- ## `smdg cf target`
105
-
106
- Show the current Cloud Foundry target.
107
-
108
- ```bash
109
- smdg cf target
110
- ```
111
-
112
- It shows API endpoint, user, org, and space.
113
-
114
- ## `smdg cf apps`
115
-
116
- List BTP apps in the current org and space.
117
-
118
- ```bash
119
21
  smdg cf apps
120
- ```
121
-
122
- The CLI uses cache first for speed and refreshes in the background.
123
-
124
- ## `smdg cf bind`
125
-
126
- Bind the local CAP project to a deployed BTP app service.
127
-
128
- ```bash
129
22
  smdg cf bind
130
- ```
131
-
132
- This helps run `cds bind --to-app-services` and update `.cdsrc-private.json`.
133
-
134
- ## `smdg cf env`
135
-
136
- Export BTP app environment variables to a clean JSON file.
137
-
138
- ```bash
139
23
  smdg cf env
140
- ```
141
-
142
- Useful for creating `default-env.json`.
143
-
144
- ## `smdg cds watch`
145
-
146
- Run CAP locally.
147
-
148
- ```bash
149
- smdg cds watch
150
- ```
151
-
152
- The CLI helps select CAP profile and port.
153
-
154
- ## `smdg cf logs`
155
-
156
- View BTP app logs.
157
-
158
- ```bash
159
24
  smdg cf logs
25
+ smdg cf request-trace
26
+ smdg gitlab login
27
+ smdg gitlab clone
28
+ smdg gitlab pull
29
+ smdg cf db studio
160
30
  ```
161
31
 
162
- It can be used for realtime log monitoring.
163
-
164
- ## `smdg cf debug`
32
+ ## GitLab sync
165
33
 
166
- Debug a deployed BTP Cloud Foundry Node.js app.
34
+ `gitlab` commands are implemented in the same source-code style as the existing CLI: command registration stays in `src/commands`, reusable logic stays close to the command, and cache files are stored under `~/.simplemdg`.
167
35
 
168
- ```bash
169
- smdg cf debug
36
+ ```powershell
37
+ smdg gitlab login
38
+ smdg gitlab groups
39
+ smdg gitlab clone
170
40
  ```
171
41
 
172
- The CLI guides you through:
42
+ The clone/pull flow separates:
173
43
 
174
- * selecting current target or searching orgs across regions
175
- * selecting BTP app
176
- * selecting debug mode
177
- * selecting app instance
178
- * preparing Node.js inspector
179
- * creating VS Code attach config
180
- * opening the CF SSH tunnel
181
-
182
- Recommended mode:
183
-
184
- ```txt
185
- VS Code guided debugging
186
- ```
44
+ - pull/clone a root group
45
+ - pull/clone a single repository
187
46
 
188
- Important VS Code note:
47
+ It uses GitLab API and native `git`, so `ghorg` is not required. Pulling can run multiple repositories in parallel and skips invalid branch refs such as `origin` and `origin/HEAD`.
189
48
 
190
- The debug toolbar buttons such as pause, step over, restart, and stop only appear after VS Code successfully attaches to the running Node.js inspector.
49
+ ## CF DB Studio
191
50
 
192
- Normal flow:
193
-
194
- 1. Run `smdg cf debug`.
195
- 2. Select `VS Code guided debugging`.
196
- 3. First time for an app, select `Set NODE_OPTIONS and restart app`.
197
- 4. Keep the terminal open because it owns the CF SSH tunnel.
198
- 5. In VS Code, open Run and Debug with `Ctrl+Shift+D`.
199
- 6. Select `Attach BTP <app-name>`.
200
- 7. Press `F5` or the green Start Debugging button.
201
- 8. After attach succeeds, the debug toolbar appears.
202
-
203
- Use this mainly in dev/test environments because enabling Node inspector restarts the BTP app.
204
-
205
- ## `smdg cds compline`
206
-
207
- Generate metadata XML from CDS services.
208
-
209
- ```bash
210
- smdg cds compline
211
- ```
51
+ A local, browser-based database explorer (HANA / PostgreSQL) styled after SAP HANA Database Explorer and DBeaver, with deep BTP/Cloud Foundry integration.
212
52
 
213
- The CLI scans CDS services, suggests output XML names, and writes XML using UTF-8 encoding.
214
-
215
- ---
216
-
217
- # Recommended Daily Flow
218
-
219
- ```bash
220
- smdg npmrc create
221
- smdg i
53
+ ```powershell
222
54
  smdg cf login
223
- smdg cf apps
224
- smdg cf bind
225
- smdg cf env
226
- smdg cds watch
55
+ smdg cf db studio
227
56
  ```
228
57
 
229
- For logs:
58
+ Studio starts a local web server bound to `127.0.0.1` only (auto-selects a free port) and opens your browser. It can:
230
59
 
231
- ```bash
232
- smdg cf logs
233
- ```
234
-
235
- For BTP debugging:
60
+ - import database credentials directly from a BTP app's `cf env` (`VCAP_SERVICES`) — no manual copy/paste
61
+ - **add direct connections manually** (host/port/user/password) for databases not behind a CF app, e.g. Neon — like a DBeaver connection
62
+ - detect SAP HANA and PostgreSQL services automatically
63
+ - cache connections locally with the password **encrypted** (never stored in plain text, never sent to the browser)
64
+ - browse schemas, tables, views, columns, indexes, procedures, functions, synonyms (HANA)
65
+ - inspect column metadata incl. type, key, nullable, default, and **comments**
66
+ - open table data with pagination, quick `WHERE` filter, and **click-to-sort** column headers (server-side)
67
+ - **edit data directly in the grid** — double-click a cell to update, insert rows, delete rows; generates parameterized `UPDATE`/`INSERT`/`DELETE` keyed on the primary key (read-only when a table has no PK)
68
+ - run any SQL — including CREATE / ALTER / UPDATE / DDL — across **multiple editor tabs**, with a row-limit selector, execution timing, CSV/JSON export, and clipboard copy
69
+ - generate `SELECT` / `COUNT` / **`CREATE TABLE` DDL** for any object from the explorer
70
+ - save/reload `.sql` query files and keep a query history
71
+ - toggle a **read-only** mode that blocks INSERT/UPDATE/DELETE/DROP/TRUNCATE/ALTER/CREATE/GRANT/REVOKE
72
+ - confirm before running dangerous SQL (DROP, TRUNCATE, ALTER, DELETE/UPDATE without WHERE)
236
73
 
237
- ```bash
238
- smdg cf debug
239
- ```
240
-
241
- For metadata XML:
74
+ ### Commands
242
75
 
243
- ```bash
244
- smdg cds compline
76
+ ```powershell
77
+ smdg cf db studio # open the local browser studio
78
+ smdg cf db add # add a direct connection manually (host/port/user/password)
79
+ smdg cf db import # import a connection from a BTP app's cf env
80
+ smdg cf db connections # list/test/rename/duplicate/remove cached connections
81
+ smdg cf db query # run one SQL query against a cached connection
82
+ smdg cf db console # interactive terminal SQL console (/help for commands)
245
83
  ```
246
84
 
247
- ---
248
-
249
- # Key Features
85
+ In the Studio, click **+ New** in the Connections sidebar to add a direct connection without leaving the browser.
250
86
 
251
- ## Private npm registry helper
87
+ `smdg cf db studio` options: `--port <port>` (preferred port), `--read-only`, `--timeout <ms>`.
252
88
 
253
- Creates `.npmrc` for SimpleMDG GitLab npm packages and caches package IDs with readable names.
89
+ ### Local cache files
254
90
 
255
- ## Smart install helper
256
-
257
- Scans project variables like `${SIMPLEMDG_BRANCH}` and asks for values automatically before install.
258
-
259
- ## Cloud Foundry helper
260
-
261
- Helps with login, target checking, org switching, app list, binding, env export, logs, and debugging.
262
-
263
- ## Across-region org search
264
-
265
- Scans known BTP regions and shows orgs from many regions in one searchable list.
266
-
267
- ## CAP helper
268
-
269
- Helps run `cds watch`, select profiles/ports, and generate CDS metadata XML.
270
-
271
- ## VS Code BTP debugging
272
-
273
- Creates VS Code attach config and opens a CF SSH tunnel to debug BTP Node.js apps from local source code.
274
-
275
- ---
91
+ ```text
92
+ ~/.simplemdg/db-connections.json # connection profiles (passwords encrypted)
93
+ ~/.simplemdg/db-query-history.json # query history
94
+ ~/.simplemdg/db-queries/ # saved .sql query files
95
+ ```
276
96
 
277
- # Notes
97
+ Passwords are encrypted with a key derived from the current machine + user, so a copied cache file cannot be decrypted elsewhere.
278
98
 
279
- Do not commit real secrets to Git.
99
+ ### Database drivers
280
100
 
281
- Files like `.npmrc`, `default-env.json`, and cached passwords may contain sensitive data.
101
+ HANA and PostgreSQL drivers are optional dependencies. If a driver is missing, the studio reports it clearly. Install:
282
102
 
283
- Use saved password only on your own machine.
103
+ ```powershell
104
+ npm i -g pg @sap/hana-client
105
+ ```
package/USER_GUIDE.md CHANGED
@@ -1,283 +1,89 @@
1
- # SimpleMDG Dev CLI Guide
1
+ # SimpleMDG CLI User Guide
2
2
 
3
- ## Purpose
3
+ ## GitLab
4
4
 
5
- `simplemdg-dev-cli` helps SimpleMDG developers run common local development and BTP tasks without remembering long commands.
5
+ Login once:
6
6
 
7
- Main command:
8
-
9
- ```bash
10
- smdg
11
- ```
12
-
13
- Install:
14
-
15
- ```bash
16
- npm i -g simplemdg-dev-cli@latest
17
- ```
18
-
19
- Open this guide:
20
-
21
- ```bash
22
- smdg guide
23
- ```
24
-
25
- ---
26
-
27
- # Select Usage
28
-
29
- When the CLI shows a select list:
30
-
31
- * Type a few characters to search.
32
- * Use `↑` and `↓` to move.
33
- * Press `Enter` to select.
34
- * If no item matches, some prompts allow using the typed value.
35
-
36
- This is useful for long lists of BTP orgs, spaces, apps, package IDs, CAP profiles, and CDS services.
37
-
38
- ---
39
-
40
- # Common Commands
41
-
42
- ## `smdg npmrc import`
43
-
44
- Import SimpleMDG GitLab package IDs into local cache.
45
-
46
- Use this after downloading the package ID import file from the team.
47
-
48
- ```bash
49
- smdg npmrc import
50
- ```
51
-
52
- ## `smdg npmrc create`
53
-
54
- Create `.npmrc` for SimpleMDG private npm packages.
55
-
56
- ```bash
57
- smdg npmrc create
58
- ```
59
-
60
- The CLI helps select package name/package ID and token from cache.
61
-
62
- ## `smdg i`
63
-
64
- Install dependencies for the current project.
65
-
66
- ```bash
67
- smdg i
68
- ```
69
-
70
- It can scan variables such as `${SIMPLEMDG_BRANCH}` and ask for replacement values automatically.
71
-
72
- ## `smdg cf login`
73
-
74
- Login to BTP Cloud Foundry.
75
-
76
- ```bash
77
- smdg cf login
78
- ```
79
-
80
- The CLI helps select API endpoint, org, and space.
81
-
82
- It can save login information on your local machine so later commands can re-login automatically when the CF session expires.
83
-
84
- ## `smdg cf org`
85
-
86
- Search, list, and switch Cloud Foundry orgs across regions.
87
-
88
- ```bash
89
- smdg cf org
7
+ ```powershell
8
+ smdg gitlab login
90
9
  ```
91
10
 
92
- The CLI scans known BTP region endpoints and shows orgs in one searchable list.
11
+ The CLI opens the GitLab token page, tries to detect the copied token from clipboard, validates it, caches it, and approves it for Git Credential Manager.
93
12
 
94
- The list includes region information, for example:
13
+ Clone or pull:
95
14
 
96
- ```txt
97
- arthrex-dev-simplemdg eu10 · 1 space
98
- alcon-dev-simplemdg br10 · 1 space
99
- ait-dev-simplemdg us21 · 1 space
15
+ ```powershell
16
+ smdg gitlab clone
17
+ smdg gitlab pull
100
18
  ```
101
19
 
102
- Use this when you have many orgs across many BTP regions.
20
+ The flow is split clearly:
103
21
 
104
- ## `smdg cf target`
105
-
106
- Show the current Cloud Foundry target.
107
-
108
- ```bash
109
- smdg cf target
110
- ```
22
+ 1. Pull/clone a GitLab group
23
+ 2. Pull/clone a single repository
111
24
 
112
- It shows API endpoint, user, org, and space.
25
+ Then select root group, destination folder, sync action, and parallel jobs.
113
26
 
114
- ## `smdg cf apps`
27
+ ## CF DB Studio
115
28
 
116
- List BTP apps in the current org and space.
29
+ A local database explorer for SAP HANA and PostgreSQL, with one-click import of credentials from BTP apps. The studio runs a web server bound to `127.0.0.1` only and opens your browser.
117
30
 
118
- ```bash
119
- smdg cf apps
120
- ```
31
+ ### Recommended flow
121
32
 
122
- The CLI uses cache first for speed and refreshes in the background.
33
+ 1. Run `smdg cf login` (once; you can save the password for auto re-login)
34
+ 2. Run `smdg cf db studio`
35
+ 3. Open the **BTP Import** tab → **Load CF apps**
36
+ 4. Select an app → its `cf env` is read and database services are detected
37
+ 5. Click **Save+Use** on a detected service → the connection is tested and activated
38
+ 6. Pick the connection in the left sidebar, choose a schema
39
+ 7. Browse tables/views in the Object Explorer, or write SQL in the **SQL Console**
40
+ 8. Run with **Ctrl+Enter**, export to CSV/JSON, save the query, or open table **Data**
123
41
 
124
- ## `smdg cf bind`
42
+ The studio never deploys anything to BTP and never shows the database password.
125
43
 
126
- Bind the local CAP project to a deployed BTP app service.
44
+ ### Studio tabs
127
45
 
128
- ```bash
129
- smdg cf bind
130
- ```
46
+ - **SQL Console** — multiple editor tabs, run (Ctrl+Enter), format, explain (PostgreSQL), row-limit selector, export CSV/JSON, save query
47
+ - **Data Grid** — paginated table data with WHERE filter, click-to-sort headers, export, and inline editing
48
+ - **Metadata** — columns (type, nullable, default, primary key) and indexes
49
+ - **BTP Import** — current CF target, app list, detected services, save/activate
50
+ - **Query Files** — saved `.sql` queries (load, run, rename, delete)
51
+ - **History** — recent queries (click to reload into the editor)
52
+ - **Messages** — log of every action and error
131
53
 
132
- This helps run `cds bind --to-app-services` and update `.cdsrc-private.json`.
54
+ ### Read-only and dangerous SQL
133
55
 
134
- ## `smdg cf env`
56
+ Toggle **Read-only** in the top bar to block INSERT/UPDATE/DELETE/DROP/TRUNCATE/ALTER/CREATE/GRANT/REVOKE. Even in read/write mode, dangerous statements (DROP, TRUNCATE, ALTER, DELETE/UPDATE without WHERE) require confirmation. A "Production-like" badge appears for prod-looking orgs/apps.
135
57
 
136
- Export BTP app environment variables to a clean JSON file.
58
+ ### Terminal alternatives
137
59
 
138
- ```bash
139
- smdg cf env
60
+ ```powershell
61
+ smdg cf db add # add a direct connection manually (host/port/user/password)
62
+ smdg cf db import # interactive import from a BTP app
63
+ smdg cf db connections # manage cached connections
64
+ smdg cf db query # run one SQL query and print/export the result
65
+ smdg cf db console # interactive SQL REPL
140
66
  ```
141
67
 
142
- Useful for creating `default-env.json`.
68
+ ### Direct connections (no CF app)
143
69
 
144
- ## `smdg cds watch`
70
+ Not every database is behind a Cloud Foundry app (for example a Neon PostgreSQL or a standalone HANA Cloud). Add those directly:
145
71
 
146
- Run CAP locally.
72
+ - In the Studio: click **+ New** in the Connections sidebar, fill in type/host/port/database/schema/user/password, click **Test**, then **Save & use**.
73
+ - In the terminal: `smdg cf db add`.
147
74
 
148
- ```bash
149
- smdg cds watch
150
- ```
75
+ Direct connections are cached and encrypted exactly like imported ones, so they reappear next time you open the Studio.
151
76
 
152
- The CLI helps select CAP profile and port.
77
+ Console slash commands: `/connect`, `/schemas`, `/tables`, `/desc TABLE`, `/top TABLE`, `/count TABLE`, `/save NAME`, `/history`, `/export csv|json`, `/full`, `/clear`, `/help`, `/exit`.
153
78
 
154
- ## `smdg cf logs`
79
+ ## DB cache
155
80
 
156
- View BTP app logs.
81
+ Connections are cached under:
157
82
 
158
- ```bash
159
- smdg cf logs
83
+ ```text
84
+ ~/.simplemdg/db-connections.json
160
85
  ```
161
86
 
162
- It can be used for realtime log monitoring.
163
-
164
- ## `smdg cf debug`
165
-
166
- Debug a deployed BTP Cloud Foundry Node.js app.
167
-
168
- ```bash
169
- smdg cf debug
170
- ```
171
-
172
- The CLI guides you through:
173
-
174
- * selecting current target or searching orgs across regions
175
- * selecting BTP app
176
- * selecting debug mode
177
- * selecting app instance
178
- * preparing Node.js inspector
179
- * creating VS Code attach config
180
- * opening the CF SSH tunnel
181
-
182
- Recommended mode:
183
-
184
- ```txt
185
- VS Code guided debugging
186
- ```
187
-
188
- Important VS Code note:
189
-
190
- The debug toolbar buttons such as pause, step over, restart, and stop only appear after VS Code successfully attaches to the running Node.js inspector.
191
-
192
- Normal flow:
193
-
194
- 1. Run `smdg cf debug`.
195
- 2. Select `VS Code guided debugging`.
196
- 3. First time for an app, select `Set NODE_OPTIONS and restart app`.
197
- 4. Keep the terminal open because it owns the CF SSH tunnel.
198
- 5. In VS Code, open Run and Debug with `Ctrl+Shift+D`.
199
- 6. Select `Attach BTP <app-name>`.
200
- 7. Press `F5` or the green Start Debugging button.
201
- 8. After attach succeeds, the debug toolbar appears.
202
-
203
- Use this mainly in dev/test environments because enabling Node inspector restarts the BTP app.
204
-
205
- ## `smdg cds compline`
206
-
207
- Generate metadata XML from CDS services.
208
-
209
- ```bash
210
- smdg cds compline
211
- ```
212
-
213
- The CLI scans CDS services, suggests output XML names, and writes XML using UTF-8 encoding.
214
-
215
- ---
216
-
217
- # Recommended Daily Flow
218
-
219
- ```bash
220
- smdg npmrc create
221
- smdg i
222
- smdg cf login
223
- smdg cf apps
224
- smdg cf bind
225
- smdg cf env
226
- smdg cds watch
227
- ```
228
-
229
- For logs:
230
-
231
- ```bash
232
- smdg cf logs
233
- ```
234
-
235
- For BTP debugging:
236
-
237
- ```bash
238
- smdg cf debug
239
- ```
240
-
241
- For metadata XML:
242
-
243
- ```bash
244
- smdg cds compline
245
- ```
246
-
247
- ---
248
-
249
- # Key Features
250
-
251
- ## Private npm registry helper
252
-
253
- Creates `.npmrc` for SimpleMDG GitLab npm packages and caches package IDs with readable names.
254
-
255
- ## Smart install helper
256
-
257
- Scans project variables like `${SIMPLEMDG_BRANCH}` and asks for values automatically before install.
258
-
259
- ## Cloud Foundry helper
260
-
261
- Helps with login, target checking, org switching, app list, binding, env export, logs, and debugging.
262
-
263
- ## Across-region org search
264
-
265
- Scans known BTP regions and shows orgs from many regions in one searchable list.
266
-
267
- ## CAP helper
268
-
269
- Helps run `cds watch`, select profiles/ports, and generate CDS metadata XML.
270
-
271
- ## VS Code BTP debugging
272
-
273
- Creates VS Code attach config and opens a CF SSH tunnel to debug BTP Node.js apps from local source code.
274
-
275
- ---
276
-
277
- # Notes
278
-
279
- Do not commit real secrets to Git.
280
-
281
- Files like `.npmrc`, `default-env.json`, and cached passwords may contain sensitive data.
87
+ Saved queries live in `~/.simplemdg/db-queries/` and history in `~/.simplemdg/db-query-history.json`.
282
88
 
283
- Use saved password only on your own machine.
89
+ Passwords are encrypted with a key derived from the current Windows user + machine. A cache file copied to another machine cannot be decrypted, and the password is never sent to the browser.