@zhqi9277/marina-db 0.1.0 → 0.1.2

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
@@ -36,6 +36,16 @@ Marina manages eight local database engines for development, covering SQL, docum
36
36
 
37
37
  Run `marina remote` for an overview or `marina remote <db>` for the full list of published builds for your operating system and architecture. [Published catalog](https://github.com/zhqi9277/marina-db/blob/engine-catalog/manifest.json) · [Engine packages](https://github.com/zhqi9277/marina-db/releases)
38
38
 
39
+ ## Desktop app
40
+
41
+ Marina also ships as a desktop app for macOS, Windows and Linux. Download the installer for your system from [Desktop releases](https://github.com/zhqi9277/marina-db/releases?q=desktop-v):
42
+
43
+ - **macOS** — `Marina-<version>-mac-arm64.dmg` for Apple Silicon, `Marina-<version>-mac-x64.dmg` for Intel Macs. Open the disk image and drag Marina into Applications.
44
+ - **Windows** — `Marina-<version>-win-x64.exe`. The installer asks for the program folder and a data directory: it defaults to `D:\Marina` when a `D:` drive exists, otherwise `%LOCALAPPDATA%\Marina`.
45
+ - **Linux** — `Marina-<version>-linux-x64.AppImage`. Make it executable and run it; there is no install step.
46
+
47
+ The installers are not code-signed yet: on macOS, right-click Marina and choose Open the first time; on Windows, pick "More info → Run anyway" in SmartScreen. The app keeps database files in its data directory and only uses the network to download engines, fetch the version catalog and check for updates. Set `MARINA_DESKTOP_UPDATES=off` to turn update checks off.
48
+
39
49
  ## Quick start
40
50
 
41
51
  You'll need Node.js **18.17 or newer** and `tar` on your PATH. Install Marina from npm, then install Redis 7, start it, and check the connection.
@@ -211,6 +221,10 @@ Changes to Milvus packaging on `main` check for missing Linux x64 and macOS ARM6
211
221
 
212
222
  Report bugs and feature requests in [GitHub Issues](https://github.com/zhqi9277/marina-db/issues).
213
223
 
224
+ ### Release the CLI
225
+
226
+ Every push to `main` that changes `bin/`, `src/`, `assets/`, `package.json`, or a README runs the tests, bumps the patch version, tags the commit, publishes to npm with provenance, and creates a GitHub Release with generated notes. Add `#minor` or `#major` to the commit message for a larger bump, or `[skip release]` to skip publishing. To choose the bump yourself, open **Actions → Release → Run workflow**. The workflow needs an `NPM_TOKEN` repository secret. Engine releases (`engines-*`) are separate and unaffected.
227
+
214
228
  ## License
215
229
 
216
230
  Marina is released under the [MIT License](./LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhqi9277/marina-db",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "homepage": "https://github.com/zhqi9277/marina-db",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,6 +17,12 @@
17
17
  "scripts": {
18
18
  "marina": "node bin/marina.js",
19
19
  "test": "node --test test/*.mjs",
20
+ "desktop:ui:install": "pnpm --dir desktop/ui install",
21
+ "desktop:ui:dev": "pnpm --dir desktop/ui dev",
22
+ "desktop:ui:build": "pnpm --dir desktop/ui build",
23
+ "desktop:ui:test": "pnpm --dir desktop/ui test",
24
+ "desktop:shell:install": "pnpm --dir desktop install",
25
+ "desktop:shell:start": "pnpm --dir desktop start",
20
26
  "smoke:e2e": "node test/e2e/smoke.mjs"
21
27
  },
22
28
  "keywords": [
package/src/cli.js CHANGED
@@ -446,17 +446,28 @@ async function cmdStatus(flags, args) {
446
446
  }
447
447
 
448
448
  async function cmdLogs(flags, args) {
449
- const { ctx } = resolveRef(requireRef(args, flags));
449
+ const ref = requireRef(args, flags);
450
+ const { ctx } = resolveRef(ref);
450
451
  const lines = Number(flags.lines || 60);
451
452
  const file = ctx.logFile;
452
- if (!fs.existsSync(file)) return warn(`no log yet at ${file}`);
453
+ if (!fs.existsSync(file)) {
454
+ if (flags.json) return jsonOut({ ref, lines, text: '' });
455
+ return warn(`no log yet at ${file}`);
456
+ }
453
457
  const content = fs.readFileSync(file, 'utf8').trimEnd().split('\n');
454
- out(content.slice(-lines).join('\n'));
458
+ const text = content.slice(-lines).join('\n');
459
+ if (flags.json) return jsonOut({ ref, lines, text });
460
+ out(text);
455
461
  }
456
462
 
457
463
  async function cmdConfig(flags, args) {
458
- const { ctx } = resolveRef(requireRef(args, flags));
459
- if (!ctx.confFile) return info('this engine has no marina-managed config file');
464
+ const ref = requireRef(args, flags);
465
+ const { ctx } = resolveRef(ref);
466
+ if (!ctx.confFile) {
467
+ if (flags.json) return jsonOut({ ref, path: null });
468
+ return info('this engine has no marina-managed config file');
469
+ }
470
+ if (flags.json) return jsonOut({ ref, path: ctx.confFile, exists: fs.existsSync(ctx.confFile) });
460
471
  out(ctx.confFile);
461
472
  if (!fs.existsSync(ctx.confFile)) warn('file does not exist yet — marina install --force');
462
473
  }
@@ -472,7 +483,9 @@ async function cmdPort(flags, args) {
472
483
  if (!result.restarted) hint(`start with: marina start ${ctx.key}@${ctx.major}`);
473
484
  return;
474
485
  }
475
- out(String(state.portOf(engine.key, ctx.major, engine.defaultPort)));
486
+ const port = state.portOf(engine.key, ctx.major, engine.defaultPort);
487
+ if (flags.json) return jsonOut({ ref, port });
488
+ out(String(port));
476
489
  }
477
490
 
478
491
  async function cmdAuth(flags, args) {
@@ -79,13 +79,26 @@ export async function sha256File(file) {
79
79
  * Download `url` to `dest`, verifying sha256 (when provided).
80
80
  * Resumes a previous `.part` file when the server supports ranges.
81
81
  */
82
- export async function downloadFile(url, dest, { sha256, size, label = path.basename(dest), retries = 2 } = {}) {
82
+ export async function downloadFile(url, dest, { sha256, size, label = path.basename(dest), retries = 2, onProgress } = {}) {
83
83
  fs.mkdirSync(path.dirname(dest), { recursive: true });
84
84
 
85
+ const emitProgress = (phase, received, total = 0, speed = 0) => {
86
+ if (!onProgress) return;
87
+ onProgress({
88
+ phase,
89
+ label,
90
+ received,
91
+ total,
92
+ percent: total ? Math.min(100, Math.floor((received / total) * 100)) : 0,
93
+ speed,
94
+ });
95
+ };
96
+
85
97
  if (fs.existsSync(dest) && sha256) {
86
98
  const got = await sha256File(dest);
87
99
  if (got === sha256 && (size == null || fs.statSync(dest).size === size)) {
88
100
  info(`${label} already in cache (sha256 ok)`);
101
+ emitProgress('done', size ?? 0, size ?? 0);
89
102
  return dest;
90
103
  }
91
104
  fs.rmSync(dest, { force: true });
@@ -114,11 +127,18 @@ export async function downloadFile(url, dest, { sha256, size, label = path.basen
114
127
  const totalBytes = size ?? (Number(range?.[2]) || (bytes ? start + bytes : 0));
115
128
  const bar = progress(label, totalBytes);
116
129
  let received = start;
130
+ const started = Date.now();
131
+ const speed = () => {
132
+ const secs = (Date.now() - started) / 1000;
133
+ return secs > 0.5 ? received / 1048576 / secs : 0;
134
+ };
135
+ emitProgress('start', received, totalBytes);
117
136
  try {
118
137
  await pipeline(res, new Transform({
119
138
  transform(chunk, _encoding, callback) {
120
139
  received += chunk.length;
121
140
  bar.update(received);
141
+ emitProgress('download', received, totalBytes, speed());
122
142
  callback(null, chunk);
123
143
  },
124
144
  }), fs.createWriteStream(part, { flags: resumed ? 'a' : 'w' }));
@@ -131,6 +151,7 @@ export async function downloadFile(url, dest, { sha256, size, label = path.basen
131
151
  throw new Error(`incomplete download for ${label}: received ${received} of ${totalBytes} bytes`);
132
152
  }
133
153
 
154
+ emitProgress('verify', received, totalBytes, speed());
134
155
  if (sha256) {
135
156
  const got = await sha256File(part);
136
157
  if (got !== sha256) {
@@ -139,6 +160,7 @@ export async function downloadFile(url, dest, { sha256, size, label = path.basen
139
160
  }
140
161
  }
141
162
  fs.renameSync(part, dest);
163
+ emitProgress('done', received, totalBytes, speed());
142
164
  return dest;
143
165
  } catch (e) {
144
166
  lastErr = e;
@@ -61,7 +61,7 @@ export async function resolveTarget(ref, { file = null, version = null } = {}) {
61
61
  return { ...entry, engine, channel: 'catalog' };
62
62
  }
63
63
 
64
- export async function fetchPackage(target) {
64
+ export async function fetchPackage(target, { onProgress } = {}) {
65
65
  if (target.file) {
66
66
  mkdirp(cacheDir(target.engine.key, target.version));
67
67
  const dest = path.join(cacheDir(target.engine.key, target.version), path.basename(target.file));
@@ -80,7 +80,7 @@ export async function fetchPackage(target) {
80
80
  throw new Error('invalid artifact file name: ' + name);
81
81
  }
82
82
  const dest = path.join(cacheDir(target.engine.key, target.version), name);
83
- await downloadFile(url, dest, { sha256: target.sha256, size: target.size, label: name });
83
+ await downloadFile(url, dest, { sha256: target.sha256, size: target.size, label: name, onProgress });
84
84
  return { tarball: dest, sha256: target.sha256 };
85
85
  }
86
86
 
@@ -158,7 +158,7 @@ async function installTarget(target, opts, port) {
158
158
  : `${target.indexSource} · ${target.urls[0]}`;
159
159
  info(`${engine.label} ${version} ${color.gray(`(${origin})`)}`);
160
160
 
161
- const { tarball, sha256 } = await fetchPackage(target);
161
+ const { tarball, sha256 } = await fetchPackage(target, { onProgress: opts.onProgress });
162
162
  const pending = pendingInstallFile(engine, major, version);
163
163
  const interrupted = fs.existsSync(pending);
164
164
  const wasInstalled = isInstalled(engine, major, version);
@@ -19,6 +19,11 @@ export { systemdEscape, xmlEscape };
19
19
  export const CLI = fileURLToPath(new URL('../bin/marina.js', import.meta.url));
20
20
  export const NODE = process.execPath;
21
21
 
22
+ let command = { node: NODE, cli: CLI };
23
+ export function configureAutostart({ node = command.node, cli = command.cli } = {}) {
24
+ command = { node, cli };
25
+ }
26
+
22
27
  export const idOf = (ctx) => `${ctx.key}:${ctx.major}`;
23
28
 
24
29
  export function isEnabled(ctx) {
@@ -35,11 +40,11 @@ function requireUnitTarget() {
35
40
  return target;
36
41
  }
37
42
 
38
- export function renderUnit(ids, target = unitTarget()) {
43
+ export function renderUnit(ids, target = unitTarget(), { node = command.node, cli = command.cli } = {}) {
39
44
  const backend = backendFor(target);
40
45
  if (!backend) throw new Error('autostart is not available on this host');
41
46
  const log = path.join(dirs.root, 'logs', 'autostart.log');
42
- return backend.renderUnit(ids, target, { node: NODE, cli: CLI, log, home: path.resolve(dirs.root) });
47
+ return backend.renderUnit(ids, target, { node, cli, log, home: path.resolve(dirs.root) });
43
48
  }
44
49
 
45
50
  function run(cmd, args) {
@@ -164,7 +164,8 @@ export function tailLog(ctx, lines = 12) {
164
164
  const file = ctx.engine.logFile?.(ctx) || ctx.logFile;
165
165
  try {
166
166
  const content = fs.readFileSync(file, 'utf8').trimEnd().split('\n');
167
- return content.slice(-lines).join('\n');
167
+ const take = Number.isSafeInteger(lines) && lines > 0 ? content.slice(-lines) : content;
168
+ return take.join('\n');
168
169
  } catch {
169
170
  return '';
170
171
  }
package/src/ui/console.js CHANGED
@@ -19,17 +19,24 @@ export const sym = {
19
19
  };
20
20
 
21
21
  let quietMode = false;
22
+ let outputChannel = null;
22
23
  export function setQuiet(v) { quietMode = !!v; }
23
24
  export function isQuiet() { return quietMode; }
25
+ export function setOutputChannel(channel) { outputChannel = channel; }
24
26
 
25
- export const out = (...a) => process.stdout.write(a.join(' ') + '\n');
26
- export const err = (...a) => process.stderr.write(a.join(' ') + '\n');
27
+ function emit(level, stream, rendered, message = rendered) {
28
+ if (outputChannel) return outputChannel({ level, stream, message });
29
+ (stream === 'stderr' ? process.stderr : process.stdout).write(rendered + '\n');
30
+ }
31
+
32
+ export const out = (...a) => emit('out', 'stdout', a.join(' '));
33
+ export const err = (...a) => emit('err', 'stderr', a.join(' '));
27
34
 
28
- export function info(msg) { if (!quietMode) out(`${sym.dot} ${msg}`); }
29
- export function ok(msg) { if (!quietMode) out(`${sym.ok} ${msg}`); }
30
- export function warn(msg) { if (!quietMode) err(`${sym.warn} ${color.yellow(msg)}`); }
31
- export function fail(msg) { err(`${sym.fail} ${color.red(msg)}`); }
32
- export function hint(msg) { if (!quietMode) out(color.gray(` ${msg}`)); }
35
+ export function info(msg) { if (!quietMode) emit('info', 'stdout', `${sym.dot} ${msg}`, msg); }
36
+ export function ok(msg) { if (!quietMode) emit('ok', 'stdout', `${sym.ok} ${msg}`, msg); }
37
+ export function warn(msg) { if (!quietMode) emit('warn', 'stderr', `${sym.warn} ${color.yellow(msg)}`, msg); }
38
+ export function fail(msg) { emit('fail', 'stderr', `${sym.fail} ${color.red(msg)}`, msg); }
39
+ export function hint(msg) { if (!quietMode) emit('hint', 'stdout', color.gray(` ${msg}`), msg); }
33
40
 
34
41
  // ---- tables ----------------------------------------------------------------
35
42
  export function table(headers, rows, { align = [] } = {}) {