@mx-space/cli 0.2.3 → 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.
- package/README.md +14 -0
- package/ROADMAP.md +6 -0
- package/bin/mxs.cjs +5 -5
- package/dist/{Lexical.dev-CMevU1DO.mjs → Lexical.dev-rcxzwpir.mjs} +0 -2
- package/dist/{Lexical.node-BR9e7Cyk.mjs → Lexical.node-BUsI9gWr.mjs} +1 -3
- package/dist/{Lexical.prod-PUD-z9fY.mjs → Lexical.prod-C8HtkSD6.mjs} +0 -2
- package/dist/{LexicalClipboard.dev-DZC2zppG.mjs → LexicalClipboard.dev-BpqRwTLP.mjs} +5 -7
- package/dist/{LexicalClipboard.node-e5G1wVGb.mjs → LexicalClipboard.node-CO-MCKx5.mjs} +1 -3
- package/dist/{LexicalClipboard.prod-DE2azzIb.mjs → LexicalClipboard.prod-B_xdeiAC.mjs} +5 -7
- package/dist/{LexicalCodeCore.dev-gs--x55I.mjs → LexicalCodeCore.dev-7_cexm39.mjs} +2 -4
- package/dist/{LexicalCodeCore.prod-DPHOnyEj.mjs → LexicalCodeCore.prod-Bd6WFHcO.mjs} +2 -4
- package/dist/{LexicalDragon.dev-CVe8bzVN.mjs → LexicalDragon.dev-gBP8WSRS.mjs} +2 -4
- package/dist/{LexicalDragon.node-c7EHvcnK.mjs → LexicalDragon.node-OG6G55nl.mjs} +1 -3
- package/dist/{LexicalDragon.prod-D6KvqyLD.mjs → LexicalDragon.prod-DP-_Q8cv.mjs} +2 -4
- package/dist/{LexicalExtension.dev-PDo8HyEw.mjs → LexicalExtension.dev-DVbjljrm.mjs} +2 -4
- package/dist/{LexicalExtension.node-BKzjRb-0.mjs → LexicalExtension.node-CF3EAPN7.mjs} +1 -3
- package/dist/{LexicalExtension.prod-D0x_lX7q.mjs → LexicalExtension.prod-DklHHErZ.mjs} +2 -4
- package/dist/{LexicalHeadless.dev-DBKcW82j.mjs → LexicalHeadless.dev-DdWLM7Nl.mjs} +1 -3
- package/dist/{LexicalHeadless.prod-D4nEh7cR.mjs → LexicalHeadless.prod-CoiiTDzR.mjs} +1 -3
- package/dist/{LexicalHtml.dev-vsWW05es.mjs → LexicalHtml.dev-C3ZSWBFZ.mjs} +3 -5
- package/dist/{LexicalHtml.node-CpibAfba.mjs → LexicalHtml.node-D0TD152E.mjs} +1 -3
- package/dist/{LexicalHtml.prod-Bqz-3WAp.mjs → LexicalHtml.prod-CX47X0zl.mjs} +3 -5
- package/dist/{LexicalLink.dev-BO0J0B1E.mjs → LexicalLink.dev-BS1Bf-yD.mjs} +3 -5
- package/dist/{LexicalLink.prod-D66AhUCZ.mjs → LexicalLink.prod-B_crkoHP.mjs} +3 -5
- package/dist/{LexicalList.dev-DVGTWRk0.mjs → LexicalList.dev-OMqmcnQ-.mjs} +3 -5
- package/dist/{LexicalList.prod-Bao7NGl7.mjs → LexicalList.prod-CpL1s8vS.mjs} +3 -5
- package/dist/{LexicalMarkdown.dev-CRWkZwlp.mjs → LexicalMarkdown.dev-BHSdx_Gr.mjs} +3 -5
- package/dist/{LexicalMarkdown.prod-tGG6js4r.mjs → LexicalMarkdown.prod-C-S7Ii6-.mjs} +3 -5
- package/dist/{LexicalRichText.dev-DPXfQePC.mjs → LexicalRichText.dev-Bz9A_WbM.mjs} +5 -7
- package/dist/{LexicalRichText.node-BEkm_YwY.mjs → LexicalRichText.node-DDpwfE-P.mjs} +4 -6
- package/dist/{LexicalRichText.prod-DlfudC5w.mjs → LexicalRichText.prod-C8qXACDL.mjs} +5 -7
- package/dist/{LexicalSelection.dev-BVTArZ-b.mjs → LexicalSelection.dev-CQ380fnD.mjs} +1 -3
- package/dist/{LexicalSelection.node-CQ8iTYsz.mjs → LexicalSelection.node-DesBMjIE.mjs} +1 -3
- package/dist/{LexicalSelection.prod-BZKGGs-G.mjs → LexicalSelection.prod-D2jivCDB.mjs} +1 -3
- package/dist/{LexicalTable.dev-C-AOEpJn.mjs → LexicalTable.dev-Ca7mQ7Jk.mjs} +4 -6
- package/dist/{LexicalTable.prod-Cyn0qWxZ.mjs → LexicalTable.prod-DyPAcC7y.mjs} +4 -6
- package/dist/{LexicalUtils.dev-DRRDyAlS.mjs → LexicalUtils.dev-HxM8F0g6.mjs} +2 -4
- package/dist/{LexicalUtils.node-Dz-HANi6.mjs → LexicalUtils.node-lCWjRjoG.mjs} +1 -3
- package/dist/{LexicalUtils.prod-CmeHwh8W.mjs → LexicalUtils.prod-Bti5w4ki.mjs} +2 -4
- package/dist/bin/mxs.d.mts +2 -929
- package/dist/bin/mxs.mjs +2 -3596
- package/dist/esm-BKxzBG1f.mjs +2 -0
- package/dist/esm-DO9hVR8S.mjs +37652 -0
- package/dist/index.d.mts +1492 -374
- package/dist/index.mjs +2 -11
- package/dist/mxs-BUOk42XP.mjs +30444 -0
- package/dist/mxs-CM8-6uAr.d.mts +4 -0
- package/package.json +7 -2
- package/dist/Lexical.dev-CMevU1DO.mjs.map +0 -1
- package/dist/Lexical.node-BR9e7Cyk.mjs.map +0 -1
- package/dist/Lexical.prod-PUD-z9fY.mjs.map +0 -1
- package/dist/LexicalClipboard.dev-DZC2zppG.mjs.map +0 -1
- package/dist/LexicalClipboard.node-e5G1wVGb.mjs.map +0 -1
- package/dist/LexicalClipboard.prod-DE2azzIb.mjs.map +0 -1
- package/dist/LexicalCodeCore.dev-gs--x55I.mjs.map +0 -1
- package/dist/LexicalCodeCore.prod-DPHOnyEj.mjs.map +0 -1
- package/dist/LexicalDragon.dev-CVe8bzVN.mjs.map +0 -1
- package/dist/LexicalDragon.node-c7EHvcnK.mjs.map +0 -1
- package/dist/LexicalDragon.prod-D6KvqyLD.mjs.map +0 -1
- package/dist/LexicalExtension.dev-PDo8HyEw.mjs.map +0 -1
- package/dist/LexicalExtension.node-BKzjRb-0.mjs.map +0 -1
- package/dist/LexicalExtension.prod-D0x_lX7q.mjs.map +0 -1
- package/dist/LexicalHeadless.dev-DBKcW82j.mjs.map +0 -1
- package/dist/LexicalHeadless.prod-D4nEh7cR.mjs.map +0 -1
- package/dist/LexicalHtml.dev-vsWW05es.mjs.map +0 -1
- package/dist/LexicalHtml.node-CpibAfba.mjs.map +0 -1
- package/dist/LexicalHtml.prod-Bqz-3WAp.mjs.map +0 -1
- package/dist/LexicalLink.dev-BO0J0B1E.mjs.map +0 -1
- package/dist/LexicalLink.prod-D66AhUCZ.mjs.map +0 -1
- package/dist/LexicalList.dev-DVGTWRk0.mjs.map +0 -1
- package/dist/LexicalList.prod-Bao7NGl7.mjs.map +0 -1
- package/dist/LexicalMarkdown.dev-CRWkZwlp.mjs.map +0 -1
- package/dist/LexicalMarkdown.prod-tGG6js4r.mjs.map +0 -1
- package/dist/LexicalRichText.dev-DPXfQePC.mjs.map +0 -1
- package/dist/LexicalRichText.node-BEkm_YwY.mjs.map +0 -1
- package/dist/LexicalRichText.prod-DlfudC5w.mjs.map +0 -1
- package/dist/LexicalSelection.dev-BVTArZ-b.mjs.map +0 -1
- package/dist/LexicalSelection.node-CQ8iTYsz.mjs.map +0 -1
- package/dist/LexicalSelection.prod-BZKGGs-G.mjs.map +0 -1
- package/dist/LexicalTable.dev-C-AOEpJn.mjs.map +0 -1
- package/dist/LexicalTable.prod-Cyn0qWxZ.mjs.map +0 -1
- package/dist/LexicalUtils.dev-DRRDyAlS.mjs.map +0 -1
- package/dist/LexicalUtils.node-Dz-HANi6.mjs.map +0 -1
- package/dist/LexicalUtils.prod-CmeHwh8W.mjs.map +0 -1
- package/dist/auth-CAKmTDpF.mjs +0 -211
- package/dist/auth-CAKmTDpF.mjs.map +0 -1
- package/dist/bin/mxs.mjs.map +0 -1
- package/dist/config-store-B8_9iStL.mjs +0 -166
- package/dist/config-store-B8_9iStL.mjs.map +0 -1
- package/dist/create-5wbU7IQh.mjs +0 -23
- package/dist/create-5wbU7IQh.mjs.map +0 -1
- package/dist/create-Bs6K7AyQ.mjs +0 -23
- package/dist/create-Bs6K7AyQ.mjs.map +0 -1
- package/dist/create-DBReocgJ.mjs +0 -24
- package/dist/create-DBReocgJ.mjs.map +0 -1
- package/dist/create-DGVaE0_S.mjs +0 -19
- package/dist/create-DGVaE0_S.mjs.map +0 -1
- package/dist/create-lLFZuMsz.mjs +0 -23
- package/dist/create-lLFZuMsz.mjs.map +0 -1
- package/dist/delete-6tkhHQDp.mjs +0 -22
- package/dist/delete-6tkhHQDp.mjs.map +0 -1
- package/dist/delete-CRFxitDN.mjs +0 -31
- package/dist/delete-CRFxitDN.mjs.map +0 -1
- package/dist/delete-DU2Hvsy8.mjs +0 -22
- package/dist/delete-DU2Hvsy8.mjs.map +0 -1
- package/dist/delete-nJmHtvfq.mjs +0 -31
- package/dist/delete-nJmHtvfq.mjs.map +0 -1
- package/dist/delete-tJhXI8s4.mjs +0 -22
- package/dist/delete-tJhXI8s4.mjs.map +0 -1
- package/dist/dist-DJF1Ntdn.mjs +0 -810
- package/dist/dist-DJF1Ntdn.mjs.map +0 -1
- package/dist/document-output-BFJdwPV0.mjs +0 -200
- package/dist/document-output-BFJdwPV0.mjs.map +0 -1
- package/dist/edit-BMjTbPQO.mjs +0 -40
- package/dist/edit-BMjTbPQO.mjs.map +0 -1
- package/dist/edit-BnEmMmv6.mjs +0 -80
- package/dist/edit-BnEmMmv6.mjs.map +0 -1
- package/dist/edit-C4vRSmRy.mjs +0 -79
- package/dist/edit-C4vRSmRy.mjs.map +0 -1
- package/dist/edit-CQsW5gnk.mjs +0 -86
- package/dist/edit-CQsW5gnk.mjs.map +0 -1
- package/dist/editor-BIw1ALTF.mjs +0 -42
- package/dist/editor-BIw1ALTF.mjs.map +0 -1
- package/dist/envelope-overlays-DXXygxdF.mjs +0 -26
- package/dist/envelope-overlays-DXXygxdF.mjs.map +0 -1
- package/dist/get-B3Y5hAAO.mjs +0 -10
- package/dist/get-B3Y5hAAO.mjs.map +0 -1
- package/dist/get-C5fmd5Vf.mjs +0 -14
- package/dist/get-C5fmd5Vf.mjs.map +0 -1
- package/dist/get-Cdp2tmwz.mjs +0 -28
- package/dist/get-Cdp2tmwz.mjs.map +0 -1
- package/dist/get-D18ChSKU.mjs +0 -10
- package/dist/get-D18ChSKU.mjs.map +0 -1
- package/dist/get-NSHTGu4Y.mjs +0 -13
- package/dist/get-NSHTGu4Y.mjs.map +0 -1
- package/dist/get-XBPJr95m.mjs +0 -14
- package/dist/get-XBPJr95m.mjs.map +0 -1
- package/dist/list-B6703n9X.mjs +0 -10
- package/dist/list-B6703n9X.mjs.map +0 -1
- package/dist/list-BtNocJhc.mjs +0 -14
- package/dist/list-BtNocJhc.mjs.map +0 -1
- package/dist/list-C9dXrU9H.mjs +0 -10
- package/dist/list-C9dXrU9H.mjs.map +0 -1
- package/dist/list-CcwcYZgN.mjs +0 -10
- package/dist/list-CcwcYZgN.mjs.map +0 -1
- package/dist/list-Ctc8b5gT.mjs +0 -10
- package/dist/list-Ctc8b5gT.mjs.map +0 -1
- package/dist/list-b60JzCTw.mjs +0 -15
- package/dist/list-b60JzCTw.mjs.map +0 -1
- package/dist/litexml-codec-CfIxcPG0.mjs +0 -13451
- package/dist/litexml-codec-CfIxcPG0.mjs.map +0 -1
- package/dist/login-bZx4HaVs.mjs +0 -591
- package/dist/login-bZx4HaVs.mjs.map +0 -1
- package/dist/logout-C0Dzitsu.mjs +0 -18
- package/dist/logout-C0Dzitsu.mjs.map +0 -1
- package/dist/ls-wMiTXZPQ.mjs +0 -33
- package/dist/ls-wMiTXZPQ.mjs.map +0 -1
- package/dist/mark-Dh9BErsf.mjs +0 -29
- package/dist/mark-Dh9BErsf.mjs.map +0 -1
- package/dist/onboarding-Bw_I8qpf.mjs +0 -214
- package/dist/onboarding-Bw_I8qpf.mjs.map +0 -1
- package/dist/output-D2dDlyV2.d.mts +0 -16
- package/dist/output-vzequvhd.mjs +0 -163
- package/dist/output-vzequvhd.mjs.map +0 -1
- package/dist/payload-CO4zbNr8.mjs +0 -547
- package/dist/payload-CO4zbNr8.mjs.map +0 -1
- package/dist/profile-CNe2uWJi.mjs +0 -172
- package/dist/profile-CNe2uWJi.mjs.map +0 -1
- package/dist/publish-CzzucXQq.mjs +0 -23
- package/dist/publish-CzzucXQq.mjs.map +0 -1
- package/dist/publish-DRQkpxsz.mjs +0 -23
- package/dist/publish-DRQkpxsz.mjs.map +0 -1
- package/dist/resolve-BYg5Gees.mjs +0 -23
- package/dist/resolve-BYg5Gees.mjs.map +0 -1
- package/dist/resolve-BlpMdnaM.mjs +0 -16
- package/dist/resolve-BlpMdnaM.mjs.map +0 -1
- package/dist/resolve-CUsHGcb-.mjs +0 -119
- package/dist/resolve-CUsHGcb-.mjs.map +0 -1
- package/dist/resolve-helpers-CoHYa2uk.mjs +0 -30
- package/dist/resolve-helpers-CoHYa2uk.mjs.map +0 -1
- package/dist/resolve-jdb1VqAG.mjs +0 -26
- package/dist/resolve-jdb1VqAG.mjs.map +0 -1
- package/dist/rm-D-2iW1Cr.mjs +0 -33
- package/dist/rm-D-2iW1Cr.mjs.map +0 -1
- package/dist/run-Dnax6uhZ.mjs +0 -130
- package/dist/run-Dnax6uhZ.mjs.map +0 -1
- package/dist/self-update-CZywTwGd.mjs +0 -1610
- package/dist/self-update-CZywTwGd.mjs.map +0 -1
- package/dist/set-Dk28LAy5.mjs +0 -43
- package/dist/set-Dk28LAy5.mjs.map +0 -1
- package/dist/shared-d0_6ZPn_.mjs +0 -50
- package/dist/shared-d0_6ZPn_.mjs.map +0 -1
- package/dist/show-DScu6mXz.mjs +0 -39
- package/dist/show-DScu6mXz.mjs.map +0 -1
- package/dist/status-8F6tgphP.mjs +0 -23
- package/dist/status-8F6tgphP.mjs.map +0 -1
- package/dist/update-B1LGxV0n.mjs +0 -30
- package/dist/update-B1LGxV0n.mjs.map +0 -1
- package/dist/update-CXetpFT3.mjs +0 -28
- package/dist/update-CXetpFT3.mjs.map +0 -1
- package/dist/update-Dr4BW8U-.mjs +0 -30
- package/dist/update-Dr4BW8U-.mjs.map +0 -1
- package/dist/update-bqcHRJPC.mjs +0 -36
- package/dist/update-bqcHRJPC.mjs.map +0 -1
- package/dist/update-dBtzzmkN.mjs +0 -37
- package/dist/update-dBtzzmkN.mjs.map +0 -1
- package/dist/use-D7eKESSW.mjs +0 -29
- package/dist/use-D7eKESSW.mjs.map +0 -1
- package/dist/whoami-CKSNd6zL.mjs +0 -22
- package/dist/whoami-CKSNd6zL.mjs.map +0 -1
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { c as MxsErrorCode, s as MxsError } from "./output-vzequvhd.mjs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { promises } from "node:fs";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
//#region src/core/config-dir.ts
|
|
6
|
-
function getConfigDir() {
|
|
7
|
-
const xdg = process.env.XDG_CONFIG_HOME;
|
|
8
|
-
const base = xdg && xdg.length > 0 ? xdg : path.join(os.homedir(), ".config");
|
|
9
|
-
return path.join(base, "mxs");
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/core/profile.ts
|
|
13
|
-
const PROFILE_NAME_RE = /^[\d_a-z-]{1,32}$/;
|
|
14
|
-
const RESERVED_PROFILE_NAMES = new Set(["current"]);
|
|
15
|
-
function validateProfileName(name) {
|
|
16
|
-
if (!name || name.length === 0) throw new MxsError({
|
|
17
|
-
code: MxsErrorCode.ValidationFailed,
|
|
18
|
-
message: "profile name must not be empty"
|
|
19
|
-
});
|
|
20
|
-
if (RESERVED_PROFILE_NAMES.has(name)) throw new MxsError({
|
|
21
|
-
code: MxsErrorCode.ValidationFailed,
|
|
22
|
-
message: `profile name '${name}' is reserved`
|
|
23
|
-
});
|
|
24
|
-
if (!PROFILE_NAME_RE.test(name)) throw new MxsError({
|
|
25
|
-
code: MxsErrorCode.ValidationFailed,
|
|
26
|
-
message: `profile name '${name}' is invalid; must match ^[a-z0-9_-]{1,32}$`
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function getProfilesDir() {
|
|
30
|
-
return path.join(getConfigDir(), "profiles");
|
|
31
|
-
}
|
|
32
|
-
function getCurrentPath() {
|
|
33
|
-
return path.join(getConfigDir(), "current");
|
|
34
|
-
}
|
|
35
|
-
function getProfileDir(name) {
|
|
36
|
-
return path.join(getProfilesDir(), name);
|
|
37
|
-
}
|
|
38
|
-
function getProfileConfigPath(name) {
|
|
39
|
-
return path.join(getProfileDir(name), "config.json");
|
|
40
|
-
}
|
|
41
|
-
function getProfileCredentialsPath(name) {
|
|
42
|
-
return path.join(getProfileDir(name), "credentials.json");
|
|
43
|
-
}
|
|
44
|
-
async function listProfiles() {
|
|
45
|
-
const dir = getProfilesDir();
|
|
46
|
-
let entries;
|
|
47
|
-
try {
|
|
48
|
-
entries = await promises.readdir(dir, { withFileTypes: true });
|
|
49
|
-
} catch (err) {
|
|
50
|
-
if (err?.code === "ENOENT") return [];
|
|
51
|
-
throw err;
|
|
52
|
-
}
|
|
53
|
-
return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name).sort();
|
|
54
|
-
}
|
|
55
|
-
async function getCurrentProfile() {
|
|
56
|
-
const p = getCurrentPath();
|
|
57
|
-
try {
|
|
58
|
-
const name = (await promises.readFile(p, "utf8")).trim();
|
|
59
|
-
return name.length > 0 ? name : null;
|
|
60
|
-
} catch (err) {
|
|
61
|
-
if (err?.code === "ENOENT") return null;
|
|
62
|
-
throw err;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async function setCurrentProfile(name) {
|
|
66
|
-
validateProfileName(name);
|
|
67
|
-
const dir = getProfileDir(name);
|
|
68
|
-
try {
|
|
69
|
-
if (!(await promises.stat(dir)).isDirectory()) throw new MxsError({
|
|
70
|
-
code: MxsErrorCode.ValidationFailed,
|
|
71
|
-
message: `profile '${name}' does not exist`
|
|
72
|
-
});
|
|
73
|
-
} catch (err) {
|
|
74
|
-
if (err instanceof MxsError) throw err;
|
|
75
|
-
if (err?.code === "ENOENT") throw new MxsError({
|
|
76
|
-
code: MxsErrorCode.ValidationFailed,
|
|
77
|
-
message: `profile '${name}' does not exist`
|
|
78
|
-
});
|
|
79
|
-
throw err;
|
|
80
|
-
}
|
|
81
|
-
await promises.writeFile(getCurrentPath(), `${name}\n`, { encoding: "utf8" });
|
|
82
|
-
}
|
|
83
|
-
async function readJsonIfExists(p) {
|
|
84
|
-
try {
|
|
85
|
-
const raw = await promises.readFile(p, "utf8");
|
|
86
|
-
return JSON.parse(raw);
|
|
87
|
-
} catch (err) {
|
|
88
|
-
if (err?.code === "ENOENT") return null;
|
|
89
|
-
if (err instanceof SyntaxError) throw new MxsError({
|
|
90
|
-
code: MxsErrorCode.Generic,
|
|
91
|
-
message: `failed to parse ${p}: ${err.message}`
|
|
92
|
-
});
|
|
93
|
-
throw err;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
async function ensureProfileDir(name) {
|
|
97
|
-
const dir = getProfileDir(name);
|
|
98
|
-
await promises.mkdir(dir, {
|
|
99
|
-
recursive: true,
|
|
100
|
-
mode: 448
|
|
101
|
-
});
|
|
102
|
-
try {
|
|
103
|
-
await promises.chmod(dir, 448);
|
|
104
|
-
} catch {}
|
|
105
|
-
}
|
|
106
|
-
async function readProfileConfig(name) {
|
|
107
|
-
return await readJsonIfExists(getProfileConfigPath(name)) ?? {};
|
|
108
|
-
}
|
|
109
|
-
async function writeProfileConfig(name, cfg) {
|
|
110
|
-
await ensureProfileDir(name);
|
|
111
|
-
const p = getProfileConfigPath(name);
|
|
112
|
-
await promises.writeFile(p, JSON.stringify(cfg, null, 2), { mode: 420 });
|
|
113
|
-
try {
|
|
114
|
-
await promises.chmod(p, 420);
|
|
115
|
-
} catch {}
|
|
116
|
-
}
|
|
117
|
-
async function readProfileCredentials(name) {
|
|
118
|
-
const p = getProfileCredentialsPath(name);
|
|
119
|
-
const data = await readJsonIfExists(p);
|
|
120
|
-
if (data) await enforceProfileCredentialsMode(p);
|
|
121
|
-
return data;
|
|
122
|
-
}
|
|
123
|
-
async function writeProfileCredentials(name, creds) {
|
|
124
|
-
await ensureProfileDir(name);
|
|
125
|
-
const p = getProfileCredentialsPath(name);
|
|
126
|
-
await promises.writeFile(p, JSON.stringify(creds, null, 2), { mode: 384 });
|
|
127
|
-
await promises.chmod(p, 384);
|
|
128
|
-
}
|
|
129
|
-
async function deleteProfileCredentials(name) {
|
|
130
|
-
const p = getProfileCredentialsPath(name);
|
|
131
|
-
try {
|
|
132
|
-
await promises.unlink(p);
|
|
133
|
-
} catch (err) {
|
|
134
|
-
if (err?.code !== "ENOENT") throw err;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
async function removeProfile(name) {
|
|
138
|
-
const dir = getProfileDir(name);
|
|
139
|
-
try {
|
|
140
|
-
await promises.stat(dir);
|
|
141
|
-
} catch (err) {
|
|
142
|
-
if (err?.code === "ENOENT") throw new MxsError({
|
|
143
|
-
code: MxsErrorCode.ResourceNotFound,
|
|
144
|
-
message: `profile '${name}' does not exist`
|
|
145
|
-
});
|
|
146
|
-
throw err;
|
|
147
|
-
}
|
|
148
|
-
await promises.rm(dir, {
|
|
149
|
-
recursive: true,
|
|
150
|
-
force: true
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
async function enforceProfileCredentialsMode(p) {
|
|
154
|
-
let stats;
|
|
155
|
-
try {
|
|
156
|
-
stats = await promises.stat(p);
|
|
157
|
-
} catch (err) {
|
|
158
|
-
if (err?.code === "ENOENT") return false;
|
|
159
|
-
throw err;
|
|
160
|
-
}
|
|
161
|
-
const mode = stats.mode & 511;
|
|
162
|
-
if (mode !== 384) {
|
|
163
|
-
process.stderr.write(`mxs: credentials file ${p} had mode ${mode.toString(8)}; chmod 600\n`);
|
|
164
|
-
await promises.chmod(p, 384);
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
//#endregion
|
|
170
|
-
export { getProfileCredentialsPath as a, listProfiles as c, removeProfile as d, setCurrentProfile as f, getConfigDir as g, writeProfileCredentials as h, getProfileConfigPath as i, readProfileConfig as l, writeProfileConfig as m, getCurrentPath as n, getProfileDir as o, validateProfileName as p, getCurrentProfile as r, getProfilesDir as s, deleteProfileCredentials as t, readProfileCredentials as u };
|
|
171
|
-
|
|
172
|
-
//# sourceMappingURL=profile-CNe2uWJi.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profile-CNe2uWJi.mjs","names":["fs"],"sources":["../src/core/config-dir.ts","../src/core/profile.ts"],"sourcesContent":["import os from 'node:os'\nimport path from 'node:path'\n\nexport function getConfigDir(): string {\n const xdg = process.env.XDG_CONFIG_HOME\n const base = xdg && xdg.length > 0 ? xdg : path.join(os.homedir(), '.config')\n return path.join(base, 'mxs')\n}\n","import { type Dirent, promises as fs } from 'node:fs'\nimport path from 'node:path'\n\nimport { getConfigDir } from './config-dir'\nimport type { ConfigShape, CredentialsShape } from './config-store'\nimport { MxsError, MxsErrorCode } from './errors'\n\nexport { getConfigDir }\n\nexport const PROFILE_NAME_RE = /^[\\d_a-z-]{1,32}$/\n\nexport const RESERVED_PROFILE_NAMES = new Set(['current'])\n\nexport function validateProfileName(name: string): void {\n if (!name || name.length === 0) {\n throw new MxsError({\n code: MxsErrorCode.ValidationFailed,\n message: 'profile name must not be empty',\n })\n }\n if (RESERVED_PROFILE_NAMES.has(name)) {\n throw new MxsError({\n code: MxsErrorCode.ValidationFailed,\n message: `profile name '${name}' is reserved`,\n })\n }\n if (!PROFILE_NAME_RE.test(name)) {\n throw new MxsError({\n code: MxsErrorCode.ValidationFailed,\n message: `profile name '${name}' is invalid; must match ^[a-z0-9_-]{1,32}$`,\n })\n }\n}\n\nexport function getProfilesDir(): string {\n return path.join(getConfigDir(), 'profiles')\n}\n\nexport function getCurrentPath(): string {\n return path.join(getConfigDir(), 'current')\n}\n\nexport function getProfileDir(name: string): string {\n return path.join(getProfilesDir(), name)\n}\n\nexport function getProfileConfigPath(name: string): string {\n return path.join(getProfileDir(name), 'config.json')\n}\n\nexport function getProfileCredentialsPath(name: string): string {\n return path.join(getProfileDir(name), 'credentials.json')\n}\n\nexport async function listProfiles(): Promise<string[]> {\n const dir = getProfilesDir()\n let entries: Dirent[]\n try {\n entries = await fs.readdir(dir, { withFileTypes: true })\n } catch (err: any) {\n if (err?.code === 'ENOENT') return []\n throw err\n }\n return entries\n .filter((e) => e.isDirectory() && !e.name.startsWith('.'))\n .map((e) => e.name)\n .sort()\n}\n\nexport async function getCurrentProfile(): Promise<string | null> {\n const p = getCurrentPath()\n try {\n const raw = await fs.readFile(p, 'utf8')\n const name = raw.trim()\n return name.length > 0 ? name : null\n } catch (err: any) {\n if (err?.code === 'ENOENT') return null\n throw err\n }\n}\n\nexport async function setCurrentProfile(name: string): Promise<void> {\n validateProfileName(name)\n const dir = getProfileDir(name)\n try {\n const stat = await fs.stat(dir)\n if (!stat.isDirectory()) {\n throw new MxsError({\n code: MxsErrorCode.ValidationFailed,\n message: `profile '${name}' does not exist`,\n })\n }\n } catch (err: any) {\n if (err instanceof MxsError) throw err\n if (err?.code === 'ENOENT') {\n throw new MxsError({\n code: MxsErrorCode.ValidationFailed,\n message: `profile '${name}' does not exist`,\n })\n }\n throw err\n }\n await fs.writeFile(getCurrentPath(), `${name}\\n`, { encoding: 'utf8' })\n}\n\nasync function readJsonIfExists<T>(p: string): Promise<T | null> {\n try {\n const raw = await fs.readFile(p, 'utf8')\n return JSON.parse(raw) as T\n } catch (err: any) {\n if (err?.code === 'ENOENT') return null\n if (err instanceof SyntaxError) {\n throw new MxsError({\n code: MxsErrorCode.Generic,\n message: `failed to parse ${p}: ${err.message}`,\n })\n }\n throw err\n }\n}\n\nasync function ensureProfileDir(name: string): Promise<void> {\n const dir = getProfileDir(name)\n await fs.mkdir(dir, { recursive: true, mode: 0o700 })\n try {\n await fs.chmod(dir, 0o700)\n } catch {}\n}\n\nexport type ProfileConfigShape = ConfigShape\nexport type ProfileCredentialsShape = CredentialsShape\n\nexport async function readProfileConfig(\n name: string,\n): Promise<ProfileConfigShape> {\n const data = await readJsonIfExists<ProfileConfigShape>(\n getProfileConfigPath(name),\n )\n return data ?? {}\n}\n\nexport async function writeProfileConfig(\n name: string,\n cfg: ProfileConfigShape,\n): Promise<void> {\n await ensureProfileDir(name)\n const p = getProfileConfigPath(name)\n await fs.writeFile(p, JSON.stringify(cfg, null, 2), { mode: 0o644 })\n try {\n await fs.chmod(p, 0o644)\n } catch {}\n}\n\nexport async function readProfileCredentials(\n name: string,\n): Promise<ProfileCredentialsShape | null> {\n const p = getProfileCredentialsPath(name)\n const data = await readJsonIfExists<ProfileCredentialsShape>(p)\n if (data) {\n await enforceProfileCredentialsMode(p)\n }\n return data\n}\n\nexport async function writeProfileCredentials(\n name: string,\n creds: ProfileCredentialsShape,\n): Promise<void> {\n await ensureProfileDir(name)\n const p = getProfileCredentialsPath(name)\n await fs.writeFile(p, JSON.stringify(creds, null, 2), { mode: 0o600 })\n await fs.chmod(p, 0o600)\n}\n\nexport async function deleteProfileCredentials(name: string): Promise<void> {\n const p = getProfileCredentialsPath(name)\n try {\n await fs.unlink(p)\n } catch (err: any) {\n if (err?.code !== 'ENOENT') throw err\n }\n}\n\nexport async function removeProfile(name: string): Promise<void> {\n const dir = getProfileDir(name)\n try {\n await fs.stat(dir)\n } catch (err: any) {\n if (err?.code === 'ENOENT') {\n throw new MxsError({\n code: MxsErrorCode.ResourceNotFound,\n message: `profile '${name}' does not exist`,\n })\n }\n throw err\n }\n await fs.rm(dir, { recursive: true, force: true })\n}\n\nasync function enforceProfileCredentialsMode(p: string): Promise<boolean> {\n let stats\n try {\n stats = await fs.stat(p)\n } catch (err: any) {\n if (err?.code === 'ENOENT') return false\n throw err\n }\n const mode = stats.mode & 0o777\n if (mode !== 0o600) {\n process.stderr.write(\n `mxs: credentials file ${p} had mode ${mode.toString(8)}; chmod 600\\n`,\n )\n await fs.chmod(p, 0o600)\n return true\n }\n return false\n}\n"],"mappings":";;;;;AAGA,SAAgB,eAAuB;CACrC,MAAM,MAAM,QAAQ,IAAI;CACxB,MAAM,OAAO,OAAO,IAAI,SAAS,IAAI,MAAM,KAAK,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;CACxE,IAAI;CACJ,IAAI;EACF,QAAQ,MAAMA,SAAG,KAAK,CAAC;CACzB,SAAS,KAAU;EACjB,IAAI,KAAK,SAAS,UAAU,OAAO;EACnC,MAAM;CACR;CACA,MAAM,OAAO,MAAM,OAAO;CAC1B,IAAI,SAAS,KAAO;EAClB,QAAQ,OAAO,MACb,yBAAyB,EAAE,YAAY,KAAK,SAAS,CAAC,EAAE,cAC1D;EACA,MAAMA,SAAG,MAAM,GAAG,GAAK;EACvB,OAAO;CACT;CACA,OAAO;AACT"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { i as emitSuccess } from "./output-vzequvhd.mjs";
|
|
2
|
-
import { n as resolveContext, t as buildApiClient } from "./shared-d0_6ZPn_.mjs";
|
|
3
|
-
import { t as resolvePostId } from "./resolve-jdb1VqAG.mjs";
|
|
4
|
-
//#region src/commands/post/publish.ts
|
|
5
|
-
async function run(slugOrId, publish, flags, out) {
|
|
6
|
-
const client = buildApiClient(await resolveContext(flags, out), flags);
|
|
7
|
-
const id = await resolvePostId(client, slugOrId);
|
|
8
|
-
if (flags.dryRun) {
|
|
9
|
-
emitSuccess({ would_set: {
|
|
10
|
-
id,
|
|
11
|
-
isPublished: publish
|
|
12
|
-
} }, out);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
emitSuccess((await client.request(`/posts/${id}`, {
|
|
16
|
-
method: "PATCH",
|
|
17
|
-
body: { isPublished: publish }
|
|
18
|
-
})).data, out);
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
export { run };
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=publish-CzzucXQq.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publish-CzzucXQq.mjs","names":[],"sources":["../src/commands/post/publish.ts"],"sourcesContent":["import { emitSuccess, type OutputOptions } from '../../core/output'\nimport { buildApiClient, type GlobalFlags, resolveContext } from '../internal/shared'\nimport { resolvePostId } from './resolve'\n\nexport async function run(\n slugOrId: string,\n publish: boolean,\n flags: GlobalFlags,\n out: OutputOptions,\n) {\n const ctx = await resolveContext(flags, out)\n const client = buildApiClient(ctx, flags)\n const id = await resolvePostId(client, slugOrId)\n if (flags.dryRun) {\n emitSuccess({ would_set: { id, isPublished: publish } }, out)\n return\n }\n const res = await client.request(`/posts/${id}`, {\n method: 'PATCH',\n body: { isPublished: publish },\n })\n emitSuccess(res.data, out)\n}\n"],"mappings":";;;;AAIA,eAAsB,IACpB,UACA,SACA,OACA,KACA;CAEA,MAAM,SAAS,eAAe,MADZ,eAAe,OAAO,GAAG,GACR,KAAK;CACxC,MAAM,KAAK,MAAM,cAAc,QAAQ,QAAQ;CAC/C,IAAI,MAAM,QAAQ;EAChB,YAAY,EAAE,WAAW;GAAE;GAAI,aAAa;EAAQ,EAAE,GAAG,GAAG;EAC5D;CACF;CAKA,aAAY,MAJM,OAAO,QAAQ,UAAU,MAAM;EAC/C,QAAQ;EACR,MAAM,EAAE,aAAa,QAAQ;CAC/B,CAAC,GACe,MAAM,GAAG;AAC3B"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { i as emitSuccess } from "./output-vzequvhd.mjs";
|
|
2
|
-
import { n as resolveContext, t as buildApiClient } from "./shared-d0_6ZPn_.mjs";
|
|
3
|
-
import { t as resolveNoteId } from "./resolve-BYg5Gees.mjs";
|
|
4
|
-
//#region src/commands/note/publish.ts
|
|
5
|
-
async function run(slugOrId, publish, flags, out) {
|
|
6
|
-
const client = buildApiClient(await resolveContext(flags, out), flags);
|
|
7
|
-
const id = await resolveNoteId(client, slugOrId);
|
|
8
|
-
if (flags.dryRun) {
|
|
9
|
-
emitSuccess({ would_set: {
|
|
10
|
-
id,
|
|
11
|
-
isPublished: publish
|
|
12
|
-
} }, out);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
emitSuccess((await client.request(`/notes/${id}/publish`, {
|
|
16
|
-
method: "PATCH",
|
|
17
|
-
body: { isPublished: publish }
|
|
18
|
-
})).data, out);
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
export { run };
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=publish-DRQkpxsz.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publish-DRQkpxsz.mjs","names":[],"sources":["../src/commands/note/publish.ts"],"sourcesContent":["import { emitSuccess, type OutputOptions } from '../../core/output'\nimport {\n buildApiClient,\n type GlobalFlags,\n resolveContext,\n} from '../internal/shared'\nimport { resolveNoteId } from './resolve'\n\nexport async function run(\n slugOrId: string,\n publish: boolean,\n flags: GlobalFlags,\n out: OutputOptions,\n) {\n const ctx = await resolveContext(flags, out)\n const client = buildApiClient(ctx, flags)\n const id = await resolveNoteId(client, slugOrId)\n if (flags.dryRun) {\n emitSuccess({ would_set: { id, isPublished: publish } }, out)\n return\n }\n const res = await client.request(`/notes/${id}/publish`, {\n method: 'PATCH',\n body: { isPublished: publish },\n })\n emitSuccess(res.data, out)\n}\n"],"mappings":";;;;AAQA,eAAsB,IACpB,UACA,SACA,OACA,KACA;CAEA,MAAM,SAAS,eAAe,MADZ,eAAe,OAAO,GAAG,GACR,KAAK;CACxC,MAAM,KAAK,MAAM,cAAc,QAAQ,QAAQ;CAC/C,IAAI,MAAM,QAAQ;EAChB,YAAY,EAAE,WAAW;GAAE;GAAI,aAAa;EAAQ,EAAE,GAAG,GAAG;EAC5D;CACF;CAKA,aAAY,MAJM,OAAO,QAAQ,UAAU,GAAG,WAAW;EACvD,QAAQ;EACR,MAAM,EAAE,aAAa,QAAQ;CAC/B,CAAC,GACe,MAAM,GAAG;AAC3B"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { c as MxsErrorCode, s as MxsError } from "./output-vzequvhd.mjs";
|
|
2
|
-
import { r as isSnowflakeId } from "./resolve-CUsHGcb-.mjs";
|
|
3
|
-
//#region src/commands/note/resolve.ts
|
|
4
|
-
async function resolveNoteId(client, slugOrId) {
|
|
5
|
-
if (isSnowflakeId(slugOrId)) return slugOrId;
|
|
6
|
-
if (/^\d+$/.test(slugOrId)) {
|
|
7
|
-
const res = await client.request(`/notes/nid/${encodeURIComponent(slugOrId)}`, { query: { single: "1" } });
|
|
8
|
-
const id = res.data?.data?.id ?? res.data?.id;
|
|
9
|
-
if (!id) throw new MxsError({
|
|
10
|
-
code: MxsErrorCode.ResourceNotFound,
|
|
11
|
-
message: `note not found: ${slugOrId}`
|
|
12
|
-
});
|
|
13
|
-
return id;
|
|
14
|
-
}
|
|
15
|
-
throw new MxsError({
|
|
16
|
-
code: MxsErrorCode.ValidationFailed,
|
|
17
|
-
message: `invalid note reference: ${slugOrId} (use snowflake id or numeric nid)`
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
export { resolveNoteId as t };
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=resolve-BYg5Gees.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-BYg5Gees.mjs","names":[],"sources":["../src/commands/note/resolve.ts"],"sourcesContent":["import type { ApiClient } from '../../core/api-client'\nimport { MxsError, MxsErrorCode } from '../../core/errors'\nimport { isSnowflakeId } from '../../core/resolve'\n\ninterface NidEnvelope {\n data?: { id?: string }\n id?: string\n}\n\nexport async function resolveNoteId(\n client: ApiClient,\n slugOrId: string,\n): Promise<string> {\n if (isSnowflakeId(slugOrId)) return slugOrId\n if (/^\\d+$/.test(slugOrId)) {\n const res = await client.request<NidEnvelope>(\n `/notes/nid/${encodeURIComponent(slugOrId)}`,\n { query: { single: '1' } },\n )\n const id = res.data?.data?.id ?? res.data?.id\n if (!id) {\n throw new MxsError({\n code: MxsErrorCode.ResourceNotFound,\n message: `note not found: ${slugOrId}`,\n })\n }\n return id\n }\n throw new MxsError({\n code: MxsErrorCode.ValidationFailed,\n message: `invalid note reference: ${slugOrId} (use snowflake id or numeric nid)`,\n })\n}\n"],"mappings":";;;AASA,eAAsB,cACpB,QACA,UACiB;CACjB,IAAI,cAAc,QAAQ,GAAG,OAAO;CACpC,IAAI,QAAQ,KAAK,QAAQ,GAAG;EAC1B,MAAM,MAAM,MAAM,OAAO,QACvB,cAAc,mBAAmB,QAAQ,KACzC,EAAE,OAAO,EAAE,QAAQ,IAAI,EAAE,CAC3B;EACA,MAAM,KAAK,IAAI,MAAM,MAAM,MAAM,IAAI,MAAM;EAC3C,IAAI,CAAC,IACH,MAAM,IAAI,SAAS;GACjB,MAAM,aAAa;GACnB,SAAS,mBAAmB;EAC9B,CAAC;EAEH,OAAO;CACT;CACA,MAAM,IAAI,SAAS;EACjB,MAAM,aAAa;EACnB,SAAS,2BAA2B,SAAS;CAC/C,CAAC;AACH"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { c as MxsErrorCode, s as MxsError } from "./output-vzequvhd.mjs";
|
|
2
|
-
import { r as isSnowflakeId } from "./resolve-CUsHGcb-.mjs";
|
|
3
|
-
//#region src/commands/category/resolve.ts
|
|
4
|
-
async function resolveCategoryId(client, slugOrId) {
|
|
5
|
-
if (isSnowflakeId(slugOrId)) return slugOrId;
|
|
6
|
-
const id = (await client.request(`/categories/${encodeURIComponent(slugOrId)}`)).data?.data?.id;
|
|
7
|
-
if (!id) throw new MxsError({
|
|
8
|
-
code: MxsErrorCode.ResourceNotFound,
|
|
9
|
-
message: `category not found: ${slugOrId}`
|
|
10
|
-
});
|
|
11
|
-
return id;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
export { resolveCategoryId as t };
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=resolve-BlpMdnaM.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-BlpMdnaM.mjs","names":[],"sources":["../src/commands/category/resolve.ts"],"sourcesContent":["import type { ApiClient } from '../../core/api-client'\nimport { MxsError, MxsErrorCode } from '../../core/errors'\nimport { isSnowflakeId } from '../../core/resolve'\n\ninterface CategoryEnvelope {\n data?: { id?: string }\n}\n\nexport async function resolveCategoryId(\n client: ApiClient,\n slugOrId: string,\n): Promise<string> {\n if (isSnowflakeId(slugOrId)) return slugOrId\n const res = await client.request<CategoryEnvelope>(\n `/categories/${encodeURIComponent(slugOrId)}`,\n )\n const id = res.data?.data?.id\n if (!id) {\n throw new MxsError({\n code: MxsErrorCode.ResourceNotFound,\n message: `category not found: ${slugOrId}`,\n })\n }\n return id\n}\n"],"mappings":";;;AAQA,eAAsB,kBACpB,QACA,UACiB;CACjB,IAAI,cAAc,QAAQ,GAAG,OAAO;CAIpC,MAAM,MAAK,MAHO,OAAO,QACvB,eAAe,mBAAmB,QAAQ,GAC5C,GACe,MAAM,MAAM;CAC3B,IAAI,CAAC,IACH,MAAM,IAAI,SAAS;EACjB,MAAM,aAAa;EACnB,SAAS,uBAAuB;CAClC,CAAC;CAEH,OAAO;AACT"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { c as MxsErrorCode, s as MxsError } from "./output-vzequvhd.mjs";
|
|
2
|
-
//#region src/core/resolve.ts
|
|
3
|
-
const SNOWFLAKE_RE = /^\d{15,}$/;
|
|
4
|
-
function isSnowflakeId(value) {
|
|
5
|
-
return SNOWFLAKE_RE.test(value);
|
|
6
|
-
}
|
|
7
|
-
var NameResolver = class {
|
|
8
|
-
fetchers;
|
|
9
|
-
cache = /* @__PURE__ */ new Map();
|
|
10
|
-
ttlMs;
|
|
11
|
-
constructor(fetchers, { ttlMs = 6e4 } = {}) {
|
|
12
|
-
this.fetchers = fetchers;
|
|
13
|
-
this.ttlMs = ttlMs;
|
|
14
|
-
}
|
|
15
|
-
async resolveCategory(value) {
|
|
16
|
-
return this.resolveWith("category", value, this.fetchers.fetchCategories);
|
|
17
|
-
}
|
|
18
|
-
async resolveTopic(value) {
|
|
19
|
-
return this.resolveWith("topic", value, this.fetchers.fetchTopics);
|
|
20
|
-
}
|
|
21
|
-
invalidate(kind) {
|
|
22
|
-
if (!kind) {
|
|
23
|
-
this.cache.clear();
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
this.cache.delete(kind);
|
|
27
|
-
}
|
|
28
|
-
async resolveWith(kind, value, fetcher) {
|
|
29
|
-
if (isSnowflakeId(value)) return value;
|
|
30
|
-
if (!fetcher) throw new MxsError({
|
|
31
|
-
code: MxsErrorCode.ValidationFailed,
|
|
32
|
-
message: `cannot resolve ${kind}: no fetcher configured`
|
|
33
|
-
});
|
|
34
|
-
const items = await this.load(kind, fetcher);
|
|
35
|
-
const hit = matchItem(items, value);
|
|
36
|
-
if (hit) return hit.id;
|
|
37
|
-
const suggestions = fuzzySuggest(items, value);
|
|
38
|
-
throw new MxsError({
|
|
39
|
-
code: MxsErrorCode.ValidationFailed,
|
|
40
|
-
message: `${kind} "${value}" not found`,
|
|
41
|
-
details: { issues: [{
|
|
42
|
-
path: ["meta", kind],
|
|
43
|
-
message: "not found",
|
|
44
|
-
...suggestions.length ? { suggestions } : {}
|
|
45
|
-
}] },
|
|
46
|
-
hint: kind === "category" ? "run `mxs category list` to see available categories" : "run `mxs topic list` to see available topics"
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async load(kind, fetcher) {
|
|
50
|
-
const cached = this.cache.get(kind);
|
|
51
|
-
const now = Date.now();
|
|
52
|
-
if (cached && cached.expiresAt > now) return cached.items;
|
|
53
|
-
const items = await fetcher();
|
|
54
|
-
this.cache.set(kind, {
|
|
55
|
-
items,
|
|
56
|
-
expiresAt: now + this.ttlMs
|
|
57
|
-
});
|
|
58
|
-
return items;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
function matchItem(items, value) {
|
|
62
|
-
const bySlug = items.find((i) => i.slug && i.slug === value);
|
|
63
|
-
if (bySlug) return bySlug;
|
|
64
|
-
const byName = items.find((i) => i.name && i.name === value);
|
|
65
|
-
if (byName) return byName;
|
|
66
|
-
const lower = value.toLowerCase();
|
|
67
|
-
const byNameCi = items.find((i) => i.name && i.name.toLowerCase() === lower);
|
|
68
|
-
if (byNameCi) return byNameCi;
|
|
69
|
-
const bySlugCi = items.find((i) => i.slug && i.slug.toLowerCase() === lower);
|
|
70
|
-
if (bySlugCi) return bySlugCi;
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
function levenshtein(a, b) {
|
|
74
|
-
if (a === b) return 0;
|
|
75
|
-
if (!a.length) return b.length;
|
|
76
|
-
if (!b.length) return a.length;
|
|
77
|
-
const m = a.length;
|
|
78
|
-
const n = b.length;
|
|
79
|
-
let prev = Array.from({ length: n + 1 });
|
|
80
|
-
let curr = Array.from({ length: n + 1 });
|
|
81
|
-
for (let j = 0; j <= n; j++) prev[j] = j;
|
|
82
|
-
for (let i = 1; i <= m; i++) {
|
|
83
|
-
curr[0] = i;
|
|
84
|
-
for (let j = 1; j <= n; j++) {
|
|
85
|
-
const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
|
|
86
|
-
curr[j] = Math.min((curr[j - 1] ?? 0) + 1, (prev[j] ?? 0) + 1, (prev[j - 1] ?? 0) + cost);
|
|
87
|
-
}
|
|
88
|
-
[prev, curr] = [curr, prev];
|
|
89
|
-
}
|
|
90
|
-
return prev[n] ?? 0;
|
|
91
|
-
}
|
|
92
|
-
function fuzzySuggest(items, value, maxDistance = 2) {
|
|
93
|
-
const lower = value.toLowerCase();
|
|
94
|
-
const scored = [];
|
|
95
|
-
for (const item of items) {
|
|
96
|
-
const candidates = [];
|
|
97
|
-
if (item.name) candidates.push(item.name);
|
|
98
|
-
if (item.slug) candidates.push(item.slug);
|
|
99
|
-
let best = Number.POSITIVE_INFINITY;
|
|
100
|
-
let label = item.name ?? item.slug ?? item.id;
|
|
101
|
-
for (const c of candidates) {
|
|
102
|
-
const d = levenshtein(c.toLowerCase(), lower);
|
|
103
|
-
if (d < best) {
|
|
104
|
-
best = d;
|
|
105
|
-
label = c;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (best <= maxDistance) scored.push({
|
|
109
|
-
label,
|
|
110
|
-
score: best
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
scored.sort((a, b) => a.score - b.score);
|
|
114
|
-
return scored.slice(0, 3).map((s) => s.label);
|
|
115
|
-
}
|
|
116
|
-
//#endregion
|
|
117
|
-
export { matchItem as a, levenshtein as i, fuzzySuggest as n, isSnowflakeId as r, NameResolver as t };
|
|
118
|
-
|
|
119
|
-
//# sourceMappingURL=resolve-CUsHGcb-.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-CUsHGcb-.mjs","names":[],"sources":["../src/core/resolve.ts"],"sourcesContent":["import { MxsError, MxsErrorCode } from './errors'\n\nexport interface ResolvableItem {\n id: string\n slug?: string\n name?: string\n}\n\nexport interface ResolverFetchers {\n fetchCategories?: () => Promise<ResolvableItem[]>\n fetchTopics?: () => Promise<ResolvableItem[]>\n}\n\ninterface CacheEntry {\n expiresAt: number\n items: ResolvableItem[]\n}\n\nconst SNOWFLAKE_RE = /^\\d{15,}$/\n\nexport function isSnowflakeId(value: string): boolean {\n return SNOWFLAKE_RE.test(value)\n}\n\nexport class NameResolver {\n private cache = new Map<string, CacheEntry>()\n private ttlMs: number\n\n constructor(\n private fetchers: ResolverFetchers,\n { ttlMs = 60_000 }: { ttlMs?: number } = {},\n ) {\n this.ttlMs = ttlMs\n }\n\n async resolveCategory(value: string): Promise<string> {\n return this.resolveWith('category', value, this.fetchers.fetchCategories)\n }\n\n async resolveTopic(value: string): Promise<string> {\n return this.resolveWith('topic', value, this.fetchers.fetchTopics)\n }\n\n invalidate(kind?: string): void {\n if (!kind) {\n this.cache.clear()\n return\n }\n this.cache.delete(kind)\n }\n\n private async resolveWith(\n kind: 'category' | 'topic',\n value: string,\n fetcher: (() => Promise<ResolvableItem[]>) | undefined,\n ): Promise<string> {\n if (isSnowflakeId(value)) return value\n if (!fetcher) {\n throw new MxsError({\n code: MxsErrorCode.ValidationFailed,\n message: `cannot resolve ${kind}: no fetcher configured`,\n })\n }\n const items = await this.load(kind, fetcher)\n const hit = matchItem(items, value)\n if (hit) return hit.id\n const suggestions = fuzzySuggest(items, value)\n throw new MxsError({\n code: MxsErrorCode.ValidationFailed,\n message: `${kind} \"${value}\" not found`,\n details: {\n issues: [\n {\n path: ['meta', kind],\n message: 'not found',\n ...(suggestions.length ? { suggestions } : {}),\n },\n ],\n },\n hint:\n kind === 'category'\n ? 'run `mxs category list` to see available categories'\n : 'run `mxs topic list` to see available topics',\n })\n }\n\n private async load(\n kind: string,\n fetcher: () => Promise<ResolvableItem[]>,\n ): Promise<ResolvableItem[]> {\n const cached = this.cache.get(kind)\n const now = Date.now()\n if (cached && cached.expiresAt > now) return cached.items\n const items = await fetcher()\n this.cache.set(kind, { items, expiresAt: now + this.ttlMs })\n return items\n }\n}\n\nexport function matchItem(\n items: ReadonlyArray<ResolvableItem>,\n value: string,\n): ResolvableItem | null {\n const bySlug = items.find((i) => i.slug && i.slug === value)\n if (bySlug) return bySlug\n const byName = items.find((i) => i.name && i.name === value)\n if (byName) return byName\n const lower = value.toLowerCase()\n const byNameCi = items.find((i) => i.name && i.name.toLowerCase() === lower)\n if (byNameCi) return byNameCi\n const bySlugCi = items.find((i) => i.slug && i.slug.toLowerCase() === lower)\n if (bySlugCi) return bySlugCi\n return null\n}\n\nexport function levenshtein(a: string, b: string): number {\n if (a === b) return 0\n if (!a.length) return b.length\n if (!b.length) return a.length\n const m = a.length\n const n = b.length\n let prev = Array.from<number>({ length: n + 1 })\n let curr = Array.from<number>({ length: n + 1 })\n for (let j = 0; j <= n; j++) prev[j] = j\n for (let i = 1; i <= m; i++) {\n curr[0] = i\n for (let j = 1; j <= n; j++) {\n const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1\n curr[j] = Math.min(\n (curr[j - 1] ?? 0) + 1,\n (prev[j] ?? 0) + 1,\n (prev[j - 1] ?? 0) + cost,\n )\n }\n ;[prev, curr] = [curr, prev]\n }\n return prev[n] ?? 0\n}\n\nexport function fuzzySuggest(\n items: ReadonlyArray<ResolvableItem>,\n value: string,\n maxDistance = 2,\n): string[] {\n const lower = value.toLowerCase()\n const scored: { label: string; score: number }[] = []\n for (const item of items) {\n const candidates: string[] = []\n if (item.name) candidates.push(item.name)\n if (item.slug) candidates.push(item.slug)\n let best = Number.POSITIVE_INFINITY\n let label = item.name ?? item.slug ?? item.id\n for (const c of candidates) {\n const d = levenshtein(c.toLowerCase(), lower)\n if (d < best) {\n best = d\n label = c\n }\n }\n if (best <= maxDistance) scored.push({ label, score: best })\n }\n scored.sort((a, b) => a.score - b.score)\n return scored.slice(0, 3).map((s) => s.label)\n}\n"],"mappings":";;AAkBA,MAAM,eAAe;AAErB,SAAgB,cAAc,OAAwB;CACpD,OAAO,aAAa,KAAK,KAAK;AAChC;AAEA,IAAa,eAAb,MAA0B;CAKd;CAJV,wBAAgB,IAAI,IAAwB;CAC5C;CAEA,YACE,UACA,EAAE,QAAQ,QAA+B,CAAC,GAC1C;EAFQ,KAAA,WAAA;EAGR,KAAK,QAAQ;CACf;CAEA,MAAM,gBAAgB,OAAgC;EACpD,OAAO,KAAK,YAAY,YAAY,OAAO,KAAK,SAAS,eAAe;CAC1E;CAEA,MAAM,aAAa,OAAgC;EACjD,OAAO,KAAK,YAAY,SAAS,OAAO,KAAK,SAAS,WAAW;CACnE;CAEA,WAAW,MAAqB;EAC9B,IAAI,CAAC,MAAM;GACT,KAAK,MAAM,MAAM;GACjB;EACF;EACA,KAAK,MAAM,OAAO,IAAI;CACxB;CAEA,MAAc,YACZ,MACA,OACA,SACiB;EACjB,IAAI,cAAc,KAAK,GAAG,OAAO;EACjC,IAAI,CAAC,SACH,MAAM,IAAI,SAAS;GACjB,MAAM,aAAa;GACnB,SAAS,kBAAkB,KAAK;EAClC,CAAC;EAEH,MAAM,QAAQ,MAAM,KAAK,KAAK,MAAM,OAAO;EAC3C,MAAM,MAAM,UAAU,OAAO,KAAK;EAClC,IAAI,KAAK,OAAO,IAAI;EACpB,MAAM,cAAc,aAA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;AAC9C"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { t as NameResolver } from "./resolve-CUsHGcb-.mjs";
|
|
2
|
-
//#region src/commands/internal/resolve-helpers.ts
|
|
3
|
-
function buildResolver(client) {
|
|
4
|
-
return new NameResolver({
|
|
5
|
-
fetchCategories: async () => {
|
|
6
|
-
const res = await client.request("/categories");
|
|
7
|
-
const data = Array.isArray(res.data) ? res.data : res.data?.data;
|
|
8
|
-
return Array.isArray(data) ? data : [];
|
|
9
|
-
},
|
|
10
|
-
fetchTopics: async () => {
|
|
11
|
-
const res = await client.request("/topics/all");
|
|
12
|
-
const data = Array.isArray(res.data) ? res.data : res.data?.data;
|
|
13
|
-
return Array.isArray(data) ? data : [];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
async function resolveCategoryRefs(payload, resolver) {
|
|
18
|
-
const nameRef = payload.__categoryName;
|
|
19
|
-
delete payload.__categoryName;
|
|
20
|
-
if (typeof nameRef === "string" && nameRef.length > 0 && !payload.categoryId) payload.categoryId = await resolver.resolveCategory(nameRef);
|
|
21
|
-
}
|
|
22
|
-
async function resolveTopicRefs(payload, resolver) {
|
|
23
|
-
const nameRef = payload.__topicName;
|
|
24
|
-
delete payload.__topicName;
|
|
25
|
-
if (typeof nameRef === "string" && nameRef.length > 0 && !payload.topicId) payload.topicId = await resolver.resolveTopic(nameRef);
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
export { resolveCategoryRefs as n, resolveTopicRefs as r, buildResolver as t };
|
|
29
|
-
|
|
30
|
-
//# sourceMappingURL=resolve-helpers-CoHYa2uk.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-helpers-CoHYa2uk.mjs","names":[],"sources":["../src/commands/internal/resolve-helpers.ts"],"sourcesContent":["import type { ApiClient } from '../../core/api-client'\nimport { NameResolver, type ResolvableItem } from '../../core/resolve'\n\nexport function buildResolver(client: ApiClient): NameResolver {\n return new NameResolver({\n fetchCategories: async () => {\n const res = await client.request<\n { data: ResolvableItem[] } | ResolvableItem[]\n >('/categories')\n const data = Array.isArray(res.data) ? res.data : res.data?.data\n return Array.isArray(data) ? data : []\n },\n fetchTopics: async () => {\n const res = await client.request<\n { data: ResolvableItem[] } | ResolvableItem[]\n >('/topics/all')\n const data = Array.isArray(res.data) ? res.data : res.data?.data\n return Array.isArray(data) ? data : []\n },\n })\n}\n\nexport async function resolveCategoryRefs(\n payload: Record<string, unknown>,\n resolver: NameResolver,\n): Promise<void> {\n const nameRef = payload.__categoryName\n delete payload.__categoryName\n if (\n typeof nameRef === 'string' &&\n nameRef.length > 0 &&\n !payload.categoryId\n ) {\n payload.categoryId = await resolver.resolveCategory(nameRef)\n }\n}\n\nexport async function resolveTopicRefs(\n payload: Record<string, unknown>,\n resolver: NameResolver,\n): Promise<void> {\n const nameRef = payload.__topicName\n delete payload.__topicName\n if (typeof nameRef === 'string' && nameRef.length > 0 && !payload.topicId) {\n payload.topicId = await resolver.resolveTopic(nameRef)\n }\n}\n"],"mappings":";;AAGA,SAAgB,cAAc,QAAiC;CAC7D,OAAO,IAAI,aAAa;EACtB,iBAAiB,YAAY;GAC3B,MAAM,MAAM,MAAM,OAAO,QAEvB,aAAa;GACf,MAAM,OAAO,MAAM,QAAQ,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,MAAM;GAC5D,OAAO,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC;EACvC;EACA,aAAa,YAAY;GACvB,MAAM,MAAM,MAAM,OAAO,QAEvB,aAAa;GACf,MAAM,OAAO,MAAM,QAAQ,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,MAAM;GAC5D,OAAO,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC;EACvC;CACF,CAAC;AACH;AAEA,eAAsB,oBACpB,SACA,UACe;CACf,MAAM,UAAU,QAAQ;CACxB,OAAO,QAAQ;CACf,IACE,OAAO,YAAY,YACnB,QAAQ,SAAS,KACjB,CAAC,QAAQ,YAET,QAAQ,aAAa,MAAM,SAAS,gBAAgB,OAAO;AAE/D;AAEA,eAAsB,iBACpB,SACA,UACe;CACf,MAAM,UAAU,QAAQ;CACxB,OAAO,QAAQ;CACf,IAAI,OAAO,YAAY,YAAY,QAAQ,SAAS,KAAK,CAAC,QAAQ,SAChE,QAAQ,UAAU,MAAM,SAAS,aAAa,OAAO;AAEzD"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { c as MxsErrorCode, s as MxsError } from "./output-vzequvhd.mjs";
|
|
2
|
-
import { r as isSnowflakeId } from "./resolve-CUsHGcb-.mjs";
|
|
3
|
-
//#region src/commands/post/resolve.ts
|
|
4
|
-
async function resolvePostReadPath(client, slugOrId) {
|
|
5
|
-
if (isSnowflakeId(slugOrId)) return `/posts/${slugOrId}`;
|
|
6
|
-
const path = (await client.request(`/posts/get-url/${encodeURIComponent(slugOrId)}`)).data?.path;
|
|
7
|
-
if (!path) throw new MxsError({
|
|
8
|
-
code: MxsErrorCode.ResourceNotFound,
|
|
9
|
-
message: `post not found: ${slugOrId}`
|
|
10
|
-
});
|
|
11
|
-
return `/posts${path.startsWith("/") ? path : `/${path}`}`;
|
|
12
|
-
}
|
|
13
|
-
async function resolvePostId(client, slugOrId) {
|
|
14
|
-
if (isSnowflakeId(slugOrId)) return slugOrId;
|
|
15
|
-
const path = await resolvePostReadPath(client, slugOrId);
|
|
16
|
-
const res = await client.request(path);
|
|
17
|
-
if (!res.data?.id) throw new MxsError({
|
|
18
|
-
code: MxsErrorCode.ResourceNotFound,
|
|
19
|
-
message: `post not found: ${slugOrId}`
|
|
20
|
-
});
|
|
21
|
-
return res.data.id;
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
export { resolvePostReadPath as n, resolvePostId as t };
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=resolve-jdb1VqAG.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-jdb1VqAG.mjs","names":[],"sources":["../src/commands/post/resolve.ts"],"sourcesContent":["import type { ApiClient } from '../../core/api-client'\nimport { MxsError, MxsErrorCode } from '../../core/errors'\nimport { isSnowflakeId } from '../../core/resolve'\n\ninterface PostSlugUrl {\n path?: string\n}\n\ninterface PostIdResult {\n id?: string\n}\n\nexport async function resolvePostReadPath(\n client: ApiClient,\n slugOrId: string,\n): Promise<string> {\n if (isSnowflakeId(slugOrId)) return `/posts/${slugOrId}`\n\n const resolved = await client.request<PostSlugUrl>(\n `/posts/get-url/${encodeURIComponent(slugOrId)}`,\n )\n const path = resolved.data?.path\n if (!path) {\n throw new MxsError({\n code: MxsErrorCode.ResourceNotFound,\n message: `post not found: ${slugOrId}`,\n })\n }\n return `/posts${path.startsWith('/') ? path : `/${path}`}`\n}\n\nexport async function resolvePostId(\n client: ApiClient,\n slugOrId: string,\n): Promise<string> {\n if (isSnowflakeId(slugOrId)) return slugOrId\n\n const path = await resolvePostReadPath(client, slugOrId)\n const res = await client.request<PostIdResult>(path)\n if (!res.data?.id) {\n throw new MxsError({\n code: MxsErrorCode.ResourceNotFound,\n message: `post not found: ${slugOrId}`,\n })\n }\n return res.data.id\n}\n"],"mappings":";;;AAYA,eAAsB,oBACpB,QACA,UACiB;CACjB,IAAI,cAAc,QAAQ,GAAG,OAAO,UAAU;CAK9C,MAAM,QAAO,MAHU,OAAO,QAC5B,kBAAkB,mBAAmB,QAAQ,GAC/C,GACsB,MAAM;CAC5B,IAAI,CAAC,MACH,MAAM,IAAI,SAAS;EACjB,MAAM,aAAa;EACnB,SAAS,mBAAmB;CAC9B,CAAC;CAEH,OAAO,SAAS,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI;AACpD;AAEA,eAAsB,cACpB,QACA,UACiB;CACjB,IAAI,cAAc,QAAQ,GAAG,OAAO;CAEpC,MAAM,OAAO,MAAM,oBAAoB,QAAQ,QAAQ;CACvD,MAAM,MAAM,MAAM,OAAO,QAAsB,IAAI;CACnD,IAAI,CAAC,IAAI,MAAM,IACb,MAAM,IAAI,SAAS;EACjB,MAAM,aAAa;EACnB,SAAS,mBAAmB;CAC9B,CAAC;CAEH,OAAO,IAAI,KAAK;AAClB"}
|
package/dist/rm-D-2iW1Cr.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { n as ue, r as q } from "./dist-DJF1Ntdn.mjs";
|
|
2
|
-
import { c as MxsErrorCode, r as emitInfo, s as MxsError } from "./output-vzequvhd.mjs";
|
|
3
|
-
import { d as removeProfile, n as getCurrentPath, p as validateProfileName, r as getCurrentProfile } from "./profile-CNe2uWJi.mjs";
|
|
4
|
-
import { promises } from "node:fs";
|
|
5
|
-
//#region src/commands/profile/rm.ts
|
|
6
|
-
async function run(name, opts, _flags, out) {
|
|
7
|
-
validateProfileName(name);
|
|
8
|
-
const current = await getCurrentProfile();
|
|
9
|
-
if (current === name && !opts.force) throw new MxsError({
|
|
10
|
-
code: MxsErrorCode.ValidationFailed,
|
|
11
|
-
message: `profile '${name}' is currently active; pass --force to remove it`,
|
|
12
|
-
hint: "switch to another profile first with `mxs profile use <name>`"
|
|
13
|
-
});
|
|
14
|
-
if (!opts.force) {
|
|
15
|
-
if (!process.stdin.isTTY) throw new MxsError({
|
|
16
|
-
code: MxsErrorCode.ValidationFailed,
|
|
17
|
-
message: `cannot remove profile '${name}' non-interactively`,
|
|
18
|
-
hint: "pass --force to confirm removal in a non-interactive context"
|
|
19
|
-
});
|
|
20
|
-
const confirmed = await ue({ message: `Remove profile '${name}'? This cannot be undone.` });
|
|
21
|
-
if (q(confirmed) || !confirmed) return;
|
|
22
|
-
}
|
|
23
|
-
await removeProfile(name);
|
|
24
|
-
emitInfo(`mxs: profile '${name}' removed`, out);
|
|
25
|
-
if (current === name) {
|
|
26
|
-
await promises.rm(getCurrentPath(), { force: true });
|
|
27
|
-
emitInfo("mxs: cleared active profile pointer", out);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
|
-
export { run };
|
|
32
|
-
|
|
33
|
-
//# sourceMappingURL=rm-D-2iW1Cr.mjs.map
|
package/dist/rm-D-2iW1Cr.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rm-D-2iW1Cr.mjs","names":["confirm","isCancel","fs"],"sources":["../src/commands/profile/rm.ts"],"sourcesContent":["import { promises as fs } from 'node:fs'\n\nimport { confirm, isCancel } from '@clack/prompts'\n\nimport { MxsError, MxsErrorCode } from '../../core/errors'\nimport { emitInfo, type OutputOptions } from '../../core/output'\nimport {\n getCurrentPath,\n getCurrentProfile,\n removeProfile,\n validateProfileName,\n} from '../../core/profile'\nimport type { GlobalFlags } from '../internal/shared'\n\nexport interface RmOpts {\n force?: boolean\n}\n\nexport async function run(\n name: string,\n opts: RmOpts,\n _flags: GlobalFlags,\n out: OutputOptions,\n) {\n validateProfileName(name)\n\n const current = await getCurrentProfile()\n if (current === name && !opts.force) {\n throw new MxsError({\n code: MxsErrorCode.ValidationFailed,\n message: `profile '${name}' is currently active; pass --force to remove it`,\n hint: 'switch to another profile first with `mxs profile use <name>`',\n })\n }\n\n if (!opts.force) {\n if (!process.stdin.isTTY) {\n throw new MxsError({\n code: MxsErrorCode.ValidationFailed,\n message: `cannot remove profile '${name}' non-interactively`,\n hint: 'pass --force to confirm removal in a non-interactive context',\n })\n }\n const confirmed = await confirm({\n message: `Remove profile '${name}'? This cannot be undone.`,\n })\n if (isCancel(confirmed) || !confirmed) {\n return\n }\n }\n\n await removeProfile(name)\n emitInfo(`mxs: profile '${name}' removed`, out)\n\n if (current === name) {\n // clear the stale active-profile pointer so subsequent commands don't\n // hit profile.not_found on a profile that no longer exists\n await fs.rm(getCurrentPath(), { force: true })\n emitInfo('mxs: cleared active profile pointer', out)\n }\n}\n"],"mappings":";;;;;AAkBA,eAAsB,IACpB,MACA,MACA,QACA,KACA;CACA,oBAAoB,IAAI;CAExB,MAAM,UAAU,MAAM,kBAAkB;CACxC,IAAI,YAAY,QAAQ,CAAC,KAAK,OAC5B,MAAM,IAAI,SAAS;EACjB,MAAM,aAAa;EACnB,SAAS,YAAY,KAAK;EAC1B,MAAM;CACR,CAAC;CAGH,IAAI,CAAC,KAAK,OAAO;EACf,IAAI,CAAC,QAAQ,MAAM,OACjB,MAAM,IAAI,SAAS;GACjB,MAAM,aAAa;GACnB,SAAS,0BAA0B,KAAK;GACxC,MAAM;EACR,CAAC;EAEH,MAAM,YAAY,MAAMA,GAAQ,EAC9B,SAAS,mBAAmB,KAAK,2BACnC,CAAC;EACD,IAAIC,EAAS,SAAS,KAAK,CAAC,WAC1B;CAEJ;CAEA,MAAM,cAAc,IAAI;CACxB,SAAS,iBAAiB,KAAK,YAAY,GAAG;CAE9C,IAAI,YAAY,MAAM;EAGpB,MAAMC,SAAG,GAAG,eAAe,GAAG,EAAE,OAAO,KAAK,CAAC;EAC7C,SAAS,uCAAuC,GAAG;CACrD;AACF"}
|