archiver-ts 0.3.3 → 0.3.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 (2) hide show
  1. package/dist/index.js +76 -55
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -742,24 +742,24 @@ var S = /* @__PURE__ */ ((e) => (e.Valid = "Valid", e.Removed = "Removed", e.Pro
742
742
  status: S.Protected
743
743
  }, e.LogTail = 15;
744
744
  })(g || (g = {}));
745
- const Vt = () => process.env.ARCHIVER_PATH ?? D(gt(), ".archiver"), $ = Vt();
745
+ const Vt = () => process.env.ARCHIVER_PATH ?? D(gt(), ".archiver"), T = Vt();
746
746
  var f;
747
747
  ((e) => {
748
748
  e.Dir = {
749
- root: $,
750
- vaults: D($, "vaults")
749
+ root: T,
750
+ vaults: D(T, "vaults")
751
751
  }, e.File = {
752
- config: D($, "config.jsonc"),
753
- autoIncr: D($, "auto-incr.jsonc"),
754
- list: D($, "list.jsonl"),
755
- vaults: D($, "vaults.jsonl"),
756
- log: D($, "log.jsonl")
752
+ config: D(T, "config.jsonc"),
753
+ autoIncr: D(T, "auto-incr.jsonc"),
754
+ list: D(T, "list.jsonl"),
755
+ vaults: D(T, "vaults.jsonl"),
756
+ log: D(T, "log.jsonl")
757
757
  };
758
758
  })(f || (f = {}));
759
- var M;
759
+ var O;
760
760
  ((e) => {
761
761
  e.CheckInterval = 1440 * 60 * 1e3, e.Repo = process.env.ARCHIVER_GITHUB_REPO ?? "aldia/archiver", e.Timeout = 1e4;
762
- })(M || (M = {}));
762
+ })(O || (O = {}));
763
763
  const Rt = "archiver", z = (e) => e.toString().padStart(2, "0"), Lt = () => (/* @__PURE__ */ new Date()).toISOString();
764
764
  function we(e = /* @__PURE__ */ new Date()) {
765
765
  const t = e.getFullYear(), a = z(e.getMonth() + 1), i = z(e.getDate()), n = z(e.getHours()), o = z(e.getMinutes()), c = z(e.getSeconds());
@@ -784,7 +784,7 @@ function Re(e) {
784
784
  throw new Error(r("util.parse.error.duplicate_ids"));
785
785
  return t;
786
786
  }
787
- function Tt(e) {
787
+ function $t(e) {
788
788
  if (!e)
789
789
  return { mode: "all" };
790
790
  if (["all", "*", "a"].includes(e.toLowerCase()))
@@ -820,7 +820,7 @@ function le(e) {
820
820
  function j(e) {
821
821
  console.error(`${ne(r("terminal.badge.error"), "red")} ${v.red(e)}`);
822
822
  }
823
- function $t(e, t) {
823
+ function Tt(e, t) {
824
824
  return Array.from({ length: t }, (a, i) => e[i] ?? "");
825
825
  }
826
826
  function B(e, t) {
@@ -829,7 +829,7 @@ function B(e, t) {
829
829
  const a = e.length, i = [];
830
830
  i.push(v.bold(e.join(" "))), i.push(v.dim(e.map((n) => "-".repeat(Math.max(n.length, 3))).join(" ")));
831
831
  for (const n of t)
832
- i.push($t(n, a).join(" "));
832
+ i.push(Tt(n, a).join(" "));
833
833
  return i.join(`
834
834
  `);
835
835
  }
@@ -860,7 +860,7 @@ async function V(e) {
860
860
  if (t.updateCheck === "on") {
861
861
  if (t.lastUpdateCheck) {
862
862
  const a = new Date(t.lastUpdateCheck);
863
- if (!Number.isNaN(a.getTime()) && Date.now() - a.getTime() < M.CheckInterval)
863
+ if (!Number.isNaN(a.getTime()) && Date.now() - a.getTime() < O.CheckInterval)
864
864
  return;
865
865
  }
866
866
  try {
@@ -944,8 +944,8 @@ function Pt(e, t) {
944
944
  })
945
945
  );
946
946
  }
947
- const Mt = v.level;
948
- function Ot(e) {
947
+ const Ot = v.level;
948
+ function Mt(e) {
949
949
  if (typeof e != "string")
950
950
  return;
951
951
  const t = e.trim().toLowerCase();
@@ -953,14 +953,14 @@ function Ot(e) {
953
953
  return t;
954
954
  }
955
955
  function Ft(e, t = process.env) {
956
- return Ot(t.ARCHIVER_STYLE) ?? e;
956
+ return Mt(t.ARCHIVER_STYLE) ?? e;
957
957
  }
958
958
  function jt(e) {
959
959
  if (e === "off") {
960
960
  v.level = 0;
961
961
  return;
962
962
  }
963
- v.level = Math.max(Mt, 1);
963
+ v.level = Math.max(Ot, 1);
964
964
  }
965
965
  function ee(e, t = process.env) {
966
966
  const a = Ft(e.style, t);
@@ -985,10 +985,10 @@ function Yt(e) {
985
985
  function Ht(e = "") {
986
986
  return { value: e, cursor: e.length };
987
987
  }
988
- function Te(e, t) {
988
+ function $e(e, t) {
989
989
  return t === "left" ? P(e.value, e.cursor - 1) : P(e.value, e.cursor + 1);
990
990
  }
991
- function $e(e, t, a) {
991
+ function Te(e, t, a) {
992
992
  if (a.ctrl && a.name === "c")
993
993
  return { state: e, action: "cancel" };
994
994
  if (a.name === "escape")
@@ -996,9 +996,9 @@ function $e(e, t, a) {
996
996
  if (a.name === "return" || a.name === "enter")
997
997
  return { state: e, action: "submit" };
998
998
  if (a.name === "left")
999
- return { state: Te(e, "left"), action: "continue" };
999
+ return { state: $e(e, "left"), action: "continue" };
1000
1000
  if (a.name === "right")
1001
- return { state: Te(e, "right"), action: "continue" };
1001
+ return { state: $e(e, "right"), action: "continue" };
1002
1002
  if (a.name === "home")
1003
1003
  return { state: P(e.value, 0), action: "continue" };
1004
1004
  if (a.name === "end")
@@ -1061,7 +1061,7 @@ function et(e, t, a) {
1061
1061
  return o;
1062
1062
  }
1063
1063
  }
1064
- function O(e, t) {
1064
+ function M(e, t) {
1065
1065
  if (e.length === 0)
1066
1066
  return { options: e, selectedIndex: 0 };
1067
1067
  let a = t === void 0 ? 0 : e.findIndex((i) => Object.is(i.value, t));
@@ -1093,7 +1093,7 @@ function R(e) {
1093
1093
  return v.black.bgWhite(` ${e} `);
1094
1094
  }
1095
1095
  async function Jt(e) {
1096
- const t = O(e.options, e.initialValue);
1096
+ const t = M(e.options, e.initialValue);
1097
1097
  if (e.options.length === 0)
1098
1098
  return null;
1099
1099
  if (!ye())
@@ -1166,7 +1166,7 @@ function Zt(e) {
1166
1166
  return "command.config.vault_item_sep.error.empty";
1167
1167
  }
1168
1168
  function Qt() {
1169
- return !!(process.stdin.isTTY && process.stdout.isTTY && typeof process.stdin.setRawMode == "function");
1169
+ return typeof process.stdin.setRawMode == "function";
1170
1170
  }
1171
1171
  function ea(e) {
1172
1172
  return [
@@ -1174,7 +1174,7 @@ function ea(e) {
1174
1174
  kind: "select",
1175
1175
  key: "updateCheck",
1176
1176
  label: r("command.config.edit.field.update_check"),
1177
- state: O(
1177
+ state: M(
1178
1178
  [
1179
1179
  { value: "on", label: r("common.state.on") },
1180
1180
  { value: "off", label: r("common.state.off") }
@@ -1192,7 +1192,7 @@ function ea(e) {
1192
1192
  kind: "select",
1193
1193
  key: "style",
1194
1194
  label: r("command.config.edit.field.style"),
1195
- state: O(
1195
+ state: M(
1196
1196
  [
1197
1197
  { value: "on", label: r("common.state.on") },
1198
1198
  { value: "off", label: r("common.state.off") }
@@ -1204,7 +1204,7 @@ function ea(e) {
1204
1204
  kind: "select",
1205
1205
  key: "language",
1206
1206
  label: r("command.config.edit.field.language"),
1207
- state: O(
1207
+ state: M(
1208
1208
  [
1209
1209
  { value: "zh", label: "zh" },
1210
1210
  { value: "en", label: "en" }
@@ -1216,7 +1216,7 @@ function ea(e) {
1216
1216
  kind: "select",
1217
1217
  key: "noCommandAction",
1218
1218
  label: r("command.config.edit.field.no_command_action"),
1219
- state: O(
1219
+ state: M(
1220
1220
  [
1221
1221
  { value: "list", label: r("common.action.list") },
1222
1222
  { value: "help", label: r("common.action.help") },
@@ -1272,7 +1272,7 @@ function N(e, t, a, i, n) {
1272
1272
  const x = e[L];
1273
1273
  if (!x)
1274
1274
  continue;
1275
- const T = L === t, re = T ? v.cyan(">") : " ", oe = T ? v.bold(x.label.padEnd(s, " ")) : x.label.padEnd(s, " "), ce = x.kind === "select" ? te(x.state, T) : Ut(x.state, T, r("command.config.edit.input.placeholder"));
1275
+ const $ = L === t, re = $ ? v.cyan(">") : " ", oe = $ ? v.bold(x.label.padEnd(s, " ")) : x.label.padEnd(s, " "), ce = x.kind === "select" ? te(x.state, $) : Ut(x.state, $, r("command.config.edit.input.placeholder"));
1276
1276
  u.push(`${re} ${oe} ${ce}`);
1277
1277
  }
1278
1278
  u.push(""), u.push(`${r("command.config.edit.action_prefix")} ${te(i, d)}`), u.push("");
@@ -1289,7 +1289,7 @@ async function aa(e) {
1289
1289
  if (!Qt())
1290
1290
  throw new Error(r("command.config.edit.error.no_tty"));
1291
1291
  const t = process.stdin, a = ea(e);
1292
- let i = O([
1292
+ let i = M([
1293
1293
  { value: "save", label: r("command.config.edit.action.save") },
1294
1294
  { value: "cancel", label: r("command.config.edit.action.cancel") }
1295
1295
  ]), n = 0, o = "";
@@ -1349,11 +1349,11 @@ async function aa(e) {
1349
1349
  return;
1350
1350
  }
1351
1351
  if (u.name === "left" || u.name === "right") {
1352
- _.kind === "select" ? _.state = q(_.state, u.name) : _.state = $e(_.state, m, u).state, o = "", N(a, n, e, i, o);
1352
+ _.kind === "select" ? _.state = q(_.state, u.name) : _.state = Te(_.state, m, u).state, o = "", N(a, n, e, i, o);
1353
1353
  return;
1354
1354
  }
1355
1355
  if (_.kind === "input") {
1356
- const A = $e(_.state, m, u);
1356
+ const A = Te(_.state, m, u);
1357
1357
  if (_.state = A.state, A.action === "cancel") {
1358
1358
  s(null);
1359
1359
  return;
@@ -1505,7 +1505,7 @@ function fe(e, t) {
1505
1505
  return t === "enter" || t === "restore" ? e.status === y.Archived : !1;
1506
1506
  }
1507
1507
  function be(e, t) {
1508
- return O(
1508
+ return M(
1509
1509
  [
1510
1510
  { value: "enter", label: De("enter"), disabled: !fe(e, "enter") },
1511
1511
  { value: "restore", label: De("restore"), disabled: !fe(e, "restore") }
@@ -1520,7 +1520,7 @@ function Pe(e, t, a) {
1520
1520
  const i = be(e, t), n = q(i, a);
1521
1521
  return H(n)?.value ?? t;
1522
1522
  }
1523
- function Me(e, t, a) {
1523
+ function Oe(e, t, a) {
1524
1524
  return a <= 0 ? 0 : t === "up" ? (e - 1 + a) % a : (e + 1) % a;
1525
1525
  }
1526
1526
  function F(e, t, a, i) {
@@ -1535,20 +1535,20 @@ function F(e, t, a, i) {
1535
1535
  }), s = be(n, a), l = [
1536
1536
  `${r("command.list.interactive.action_prefix")} ${te(s)}`,
1537
1537
  ""
1538
- ], m = Math.max(o - l.length - 2, 2), u = Math.max(Math.floor(m / 2), 1), _ = Math.floor(u / 2), A = Math.max(e.length - u, 0), L = Math.min(Math.max(t - _, 0), A), x = Math.min(L + u, e.length), T = [...l];
1538
+ ], m = Math.max(o - l.length - 2, 2), u = Math.max(Math.floor(m / 2), 1), _ = Math.floor(u / 2), A = Math.max(e.length - u, 0), L = Math.min(Math.max(t - _, 0), A), x = Math.min(L + u, e.length), $ = [...l];
1539
1539
  for (let W = L; W < x; W += 1) {
1540
1540
  const U = e[W];
1541
1541
  if (!U)
1542
1542
  continue;
1543
1543
  const Ce = W === t, dt = Ce ? v.cyan(">") : " ", ut = U.status === y.Archived ? v.green("A") : v.gray("R"), Ee = `${dt} [${String(U.id).padStart(4, " ")}] ${ut} ${U.title}`, Ae = ` ${v.dim(U.path)}`;
1544
- Ce ? (T.push(v.bold(Ee)), T.push(v.cyan(Ae))) : (T.push(Ee), T.push(Ae));
1544
+ Ce ? ($.push(v.bold(Ee)), $.push(v.cyan(Ae))) : ($.push(Ee), $.push(Ae));
1545
1545
  }
1546
1546
  const re = r("command.list.interactive.showing", {
1547
1547
  start: L + 1,
1548
1548
  end: x,
1549
1549
  total: e.length
1550
1550
  }), oe = i ? v.yellow(i) : v.dim(re), ce = Ie({
1551
- contentLines: T,
1551
+ contentLines: $,
1552
1552
  hintLine: c,
1553
1553
  statusLine: oe,
1554
1554
  rows: o
@@ -1571,11 +1571,11 @@ async function la(e) {
1571
1571
  return;
1572
1572
  }
1573
1573
  if (d.name === "up") {
1574
- a = Me(a, "up", e.length), n = "", F(e, a, i, n);
1574
+ a = Oe(a, "up", e.length), n = "", F(e, a, i, n);
1575
1575
  return;
1576
1576
  }
1577
1577
  if (d.name === "down") {
1578
- a = Me(a, "down", e.length), n = "", F(e, a, i, n);
1578
+ a = Oe(a, "down", e.length), n = "", F(e, a, i, n);
1579
1579
  return;
1580
1580
  }
1581
1581
  if (d.name === "left") {
@@ -1783,7 +1783,7 @@ function pa(e, t) {
1783
1783
  ));
1784
1784
  return;
1785
1785
  }
1786
- const n = Tt(a), o = await t.logService.getLogs(n);
1786
+ const n = $t(a), o = await t.logService.getLogs(n);
1787
1787
  if (o.length === 0) {
1788
1788
  E(r("command.log.empty"));
1789
1789
  return;
@@ -1817,7 +1817,7 @@ function pa(e, t) {
1817
1817
  async function Y(e) {
1818
1818
  await p.mkdir(e, { recursive: !0 });
1819
1819
  }
1820
- const C = (e) => p.access(e).then(() => !0).catch(() => !1), Oe = (e) => p.realpath(e).catch(() => h.resolve(e)), _a = (e, t) => h.normalize(e) === h.normalize(t);
1820
+ const C = (e) => p.access(e).then(() => !0).catch(() => !1), Me = (e) => p.realpath(e).catch(() => h.resolve(e)), _a = (e, t) => h.normalize(e) === h.normalize(t);
1821
1821
  function rt(e, t) {
1822
1822
  const a = h.relative(h.resolve(e), h.resolve(t));
1823
1823
  return a.length > 0 && !a.startsWith("..") && !h.isAbsolute(a);
@@ -2230,6 +2230,11 @@ const je = {
2230
2230
  endMarker: "# <<< archiver arv wrapper <<<",
2231
2231
  functionPattern: /(^|\n)\s*(function\s+)?arv\s*(\(\))?\s*\{/m,
2232
2232
  body: `arv() {
2233
+ if [[ ! -t 0 || ! -t 1 ]]; then
2234
+ command arv "$@"
2235
+ return $?
2236
+ fi
2237
+
2233
2238
  local line target status
2234
2239
  while IFS= read -r line; do
2235
2240
  if [[ "$line" == *__ARCHIVER_CD__:* ]]; then
@@ -2255,6 +2260,15 @@ const je = {
2255
2260
  endMarker: "# <<< archiver arv wrapper <<<",
2256
2261
  functionPattern: /(^|\n)\s*function\s+arv\b/m,
2257
2262
  body: `function arv
2263
+ if not test -t 0
2264
+ command arv $argv
2265
+ return $status
2266
+ end
2267
+ if not test -t 1
2268
+ command arv $argv
2269
+ return $status
2270
+ end
2271
+
2258
2272
  set -l target_tmp (mktemp)
2259
2273
  env ARCHIVER_FORCE_INTERACTIVE=1 command arv $argv | while read -l line
2260
2274
  if string match -q "__ARCHIVER_CD__:*" -- $line
@@ -2286,6 +2300,13 @@ end`
2286
2300
  [string[]]$argv
2287
2301
  )
2288
2302
 
2303
+ if ([Console]::IsInputRedirected -or [Console]::IsOutputRedirected) {
2304
+ $app = Get-Command arv -CommandType Application -ErrorAction Stop | Select-Object -First 1
2305
+ & $app.Source @argv
2306
+ $global:LASTEXITCODE = $LASTEXITCODE
2307
+ return
2308
+ }
2309
+
2289
2310
  $target = $null
2290
2311
  $status = 1
2291
2312
  $oldForce = $env:ARCHIVER_FORCE_INTERACTIVE
@@ -2394,10 +2415,10 @@ function Ra(e, t) {
2394
2415
  function La(e) {
2395
2416
  return `'${e.replaceAll("'", "'\\''")}'`;
2396
2417
  }
2397
- function Ta(e) {
2418
+ function $a(e) {
2398
2419
  return `'${e.replaceAll("'", "''")}'`;
2399
2420
  }
2400
- async function $a(e) {
2421
+ async function Ta(e) {
2401
2422
  if (process.platform === "win32") {
2402
2423
  const t = [
2403
2424
  h.join(e, "Documents", "PowerShell", "Microsoft.PowerShell_profile.ps1"),
@@ -2416,7 +2437,7 @@ function G(e, t, a, i) {
2416
2437
  installed: i,
2417
2438
  shell: e,
2418
2439
  profilePath: n,
2419
- reloadCommand: `. ${Ta(t)}`
2440
+ reloadCommand: `. ${$a(t)}`
2420
2441
  } : {
2421
2442
  installed: i,
2422
2443
  shell: e,
@@ -2451,7 +2472,7 @@ async function Na(e = {}) {
2451
2472
  const d = await J(l, Ca);
2452
2473
  return G(o, l, i, d);
2453
2474
  }
2454
- const c = await $a(i);
2475
+ const c = await Ta(i);
2455
2476
  await Y(h.dirname(c));
2456
2477
  const s = await J(c, Ea);
2457
2478
  return G(o, c, i, s);
@@ -3071,7 +3092,7 @@ class Pa {
3071
3092
  };
3072
3093
  }
3073
3094
  async preValidatePutItems(t) {
3074
- const a = [], i = /* @__PURE__ */ new Set(), n = await Oe(f.Dir.root);
3095
+ const a = [], i = /* @__PURE__ */ new Set(), n = await Me(f.Dir.root);
3075
3096
  for (const o of t) {
3076
3097
  const c = h.resolve(o), s = await ae(c);
3077
3098
  if (!s)
@@ -3080,7 +3101,7 @@ class Pa {
3080
3101
  path: o
3081
3102
  })
3082
3103
  );
3083
- const l = await Oe(c);
3104
+ const l = await Me(c);
3084
3105
  if (wa(l, n) || rt(n, l))
3085
3106
  throw new Error(
3086
3107
  r("service.archive.error.path_forbidden_archiver_scope", {
@@ -3115,7 +3136,7 @@ class Pa {
3115
3136
  }
3116
3137
  }
3117
3138
  }
3118
- class Ma {
3139
+ class Oa {
3119
3140
  constructor(t) {
3120
3141
  this.context = t;
3121
3142
  }
@@ -3141,7 +3162,7 @@ function de(e) {
3141
3162
  function I(e, t, a, i) {
3142
3163
  e.push({ level: t, code: a, message: i });
3143
3164
  }
3144
- class Oa {
3165
+ class Ma {
3145
3166
  constructor(t) {
3146
3167
  this.context = t;
3147
3168
  }
@@ -3542,7 +3563,7 @@ class Ba {
3542
3563
  constructor(t) {
3543
3564
  this.currentVersion = ge(t);
3544
3565
  }
3545
- async checkLatest(t = M.Repo) {
3566
+ async checkLatest(t = O.Repo) {
3546
3567
  const a = await this.fetchLatestRelease(t), i = ge(a.tag_name);
3547
3568
  return {
3548
3569
  currentVersion: this.currentVersion,
@@ -3552,7 +3573,7 @@ class Ba {
3552
3573
  publishedAt: a.published_at
3553
3574
  };
3554
3575
  }
3555
- async installLatest(t = M.Repo) {
3576
+ async installLatest(t = O.Repo) {
3556
3577
  const i = (await this.fetchLatestRelease(t)).assets?.find((s) => /install.*\.sh$/i.test(s.name));
3557
3578
  if (!i)
3558
3579
  throw new Error(r("service.update.error.no_install_asset"));
@@ -3560,7 +3581,7 @@ class Ba {
3560
3581
  headers: {
3561
3582
  "user-agent": "archiver-ts"
3562
3583
  },
3563
- signal: AbortSignal.timeout(M.Timeout)
3584
+ signal: AbortSignal.timeout(O.Timeout)
3564
3585
  });
3565
3586
  if (!n.ok)
3566
3587
  throw new Error(
@@ -3584,7 +3605,7 @@ class Ba {
3584
3605
  accept: "application/vnd.github+json",
3585
3606
  "user-agent": "archiver-ts"
3586
3607
  },
3587
- signal: AbortSignal.timeout(M.Timeout)
3608
+ signal: AbortSignal.timeout(O.Timeout)
3588
3609
  });
3589
3610
  if (!i.ok)
3590
3611
  throw new Error(
@@ -3606,7 +3627,7 @@ class Ba {
3606
3627
  async function qa() {
3607
3628
  const e = new Da();
3608
3629
  await e.init();
3609
- const t = new Fa(e), a = new Ma(e), i = new Pa(e, a), n = new ya(e, t), o = new Ha(e), c = new Oa(e), s = "0.3.3", l = new Ba(s);
3630
+ const t = new Fa(e), a = new Oa(e), i = new Pa(e, a), n = new ya(e, t), o = new Ha(e), c = new Ma(e), s = "0.3.4", l = new Ba(s);
3610
3631
  return {
3611
3632
  context: e,
3612
3633
  archiveService: i,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archiver-ts",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "A TypeScript rewrite of Archiver CLI",
5
5
  "description_zh": "用TypeScript重写的Archiver CLI",
6
6
  "type": "module",