@arcticdata/dsh-datarc-assistant 26.39.0 → 26.39.1
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 +45 -10
- package/api-operations.js +404 -0
- package/client.js +452 -87
- package/cordis.patch.yml +4 -4
- package/entry/SKILL.md +34 -0
- package/icon.png +0 -0
- package/index.js +35 -47
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/native-api.mjs +326 -0
- package/native-contracts.js +195 -0
- package/native-execution.js +184 -0
- package/native-runner.mjs +107 -0
- package/native-state.js +67 -0
- package/native-tools.js +241 -0
- package/operations.js +1260 -0
- package/package.json +65 -51
- package/{skills → runtime}/datarc-access-permissions/SKILL.md +30 -30
- package/{skills → runtime}/datarc-access-permissions/references/api.md +31 -31
- package/{skills → runtime}/datarc-access-permissions/references/write-order.md +16 -16
- package/{skills → runtime}/datarc-analysis-report/SKILL.md +125 -125
- package/{skills → runtime}/datarc-analysis-report/agents/openai.yaml +6 -6
- package/{skills → runtime}/datarc-analysis-report/references/analyst-frameworks.md +215 -215
- package/{skills → runtime}/datarc-analysis-report/references/api-contracts.md +478 -478
- package/{skills → runtime}/datarc-analysis-report/references/direct-card-fallback-design.md +66 -66
- package/{skills → runtime}/datarc-analysis-report/references/human-in-the-loop.md +142 -142
- package/{skills → runtime}/datarc-analysis-report/references/loop-personalization-policy.md +138 -138
- package/{skills → runtime}/datarc-analysis-report/references/manifest-example.json +779 -779
- package/{skills → runtime}/datarc-analysis-report/references/narrative-schema.md +160 -160
- package/{skills → runtime}/datarc-analysis-report/references/question-syntax.md +151 -151
- package/{skills → runtime}/datarc-analysis-report/scripts/run_analysis_report.py +2225 -2225
- package/{skills → runtime}/datarc-analysis-report/scripts/run_dataseek_cards.py +1914 -1914
- package/{skills → runtime}/datarc-analysis-report/scripts/test_run_analysis_report.py +5295 -5295
- package/{skills → runtime}/datarc-data-search/SKILL.md +243 -243
- package/{skills → runtime}/datarc-data-search/scripts/calculate.py +116 -116
- package/{skills → runtime}/datarc-data-search/scripts/data-search.mjs +628 -628
- package/{skills/datarc-dataseek-search → runtime/datarc-data-search}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-data-search/scripts/search-result.mjs +211 -211
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/SKILL.md +59 -59
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/references/artifacts.md +36 -36
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/references/equivalence.md +30 -30
- package/{skills/datarc-data-search → runtime/datarc-dataseek-batch-evaluation}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/scripts/dataseek-batch-evaluation.mjs +1020 -1020
- package/{skills → runtime}/datarc-dataseek-search/SKILL.md +96 -96
- package/{skills/datarc-dataseek-batch-evaluation → runtime/datarc-dataseek-search}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-search/scripts/dataseek-search.mjs +257 -257
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/SKILL.md +44 -44
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/evals/evals.json +165 -165
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/dataset.md +77 -77
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/input-and-resolution.md +93 -93
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/interventions.md +64 -64
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/knowledge-and-prompts.md +47 -47
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/rollback.md +11 -11
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/verification-and-rollback.md +95 -95
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/scripts/semantic-debugging.mjs +29 -29
- package/{skills → runtime}/datarc-dataseek-testset-generation/SKILL.md +47 -47
- package/{skills → runtime}/datarc-dataseek-testset-generation/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-testset-generation/scripts/dataseek-testset-generation.mjs +526 -526
- package/{skills → runtime}/datarc-datasource/SKILL.md +97 -97
- package/{skills → runtime}/datarc-oauth/SKILL.md +50 -50
- package/{skills → runtime}/datarc-oauth/scripts/auth.mjs +192 -192
- package/{skills → runtime}/datarc-oauth/scripts/credentials.mjs +237 -237
- package/{skills → runtime}/datarc-report-add-card/SKILL.md +90 -90
- package/{skills → runtime}/datarc-report-add-card/agents/openai.yaml +4 -4
- package/runtime/datarc-report-add-card/scripts/datarc-client.mjs +464 -0
- package/{skills → runtime}/datarc-report-add-card/scripts/report-card.mjs +439 -439
- package/{skills → runtime}/datarc-semantic-alias/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-alias/scripts/alias-plan.mjs +422 -422
- package/{skills → runtime}/datarc-semantic-alias/scripts/alias.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-calibration/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-calibration/scripts/calibration-plan.mjs +683 -683
- package/{skills → runtime}/datarc-semantic-calibration/scripts/calibration.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-core/SKILL.md +12 -12
- package/{skills → runtime}/datarc-semantic-core/scripts/artifact-journal.mjs +853 -830
- package/{skills → runtime}/datarc-semantic-core/scripts/canonical.mjs +48 -48
- package/{skills → runtime}/datarc-semantic-core/scripts/case-model.mjs +608 -608
- package/{skills → runtime}/datarc-semantic-core/scripts/cli.mjs +180 -180
- package/{skills → runtime}/datarc-semantic-core/scripts/datarc-client.mjs +180 -180
- package/{skills → runtime}/datarc-semantic-core/scripts/interpretation-pairs.mjs +57 -57
- package/{skills → runtime}/datarc-semantic-core/scripts/interventions.mjs +693 -693
- package/{skills → runtime}/datarc-semantic-core/scripts/live-resolution.mjs +305 -305
- package/{skills → runtime}/datarc-semantic-core/scripts/model-scope.mjs +49 -49
- package/{skills → runtime}/datarc-semantic-core/scripts/reproduction.mjs +330 -330
- package/{skills → runtime}/datarc-semantic-core/scripts/semantic-cli.mjs +799 -740
- package/{skills → runtime}/datarc-semantic-core/scripts/shared.mjs +312 -312
- package/{skills → runtime}/datarc-semantic-core/scripts/verification.mjs +1111 -1014
- package/{skills → runtime}/datarc-semantic-dataset/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset-plan.mjs +749 -749
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset-preflight.mjs +813 -813
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-knowledge/SKILL.md +38 -38
- package/{skills → runtime}/datarc-semantic-knowledge/references/knowledge-drafts.md +61 -61
- package/{skills → runtime}/datarc-semantic-knowledge/references/knowledge-generation.json +16 -16
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge-draft.mjs +347 -347
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge-plan.mjs +848 -848
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge.mjs +31 -31
- package/{skills → runtime}/datarc-semantic-prompt/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-prompt/scripts/prompt-plan.mjs +598 -447
- package/{skills → runtime}/datarc-semantic-prompt/scripts/prompt.mjs +15 -15
- package/{skills → runtime}/datarc-semantic-synonym/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-synonym/scripts/synonym-plan.mjs +688 -688
- package/{skills → runtime}/datarc-semantic-synonym/scripts/synonym.mjs +11 -11
- package/{skills → runtime}/datarc-viz-analysis-report/SKILL.md +108 -108
- package/{skills → runtime}/datarc-viz-analysis-report/assets/LICENSE-echarts.md +8 -8
- package/{skills → runtime}/datarc-viz-analysis-report/assets/echarts.min.js +45 -45
- package/{skills → runtime}/datarc-viz-analysis-report/references/api-contracts.md +163 -163
- package/{skills → runtime}/datarc-viz-analysis-report/references/derivation-log.md +157 -157
- package/{skills → runtime}/datarc-viz-analysis-report/references/evidence-framework.md +76 -76
- package/{skills → runtime}/datarc-viz-analysis-report/references/html-template.md +92 -92
- package/{skills → runtime}/datarc-viz-analysis-report/references/provenance-format.md +56 -56
- package/{skills → runtime}/datarc-viz-analysis-report/references/question-syntax.md +151 -151
- package/{skills → runtime}/datarc-viz-analysis-report/scripts/render_viz_report.py +1708 -1708
- package/{skills → runtime}/datarc-viz-analysis-report/scripts/test_render_viz_report.py +964 -964
- package/{skills → runtime}/datarc-workspace-configuration/SKILL.md +59 -59
- package/{skills → runtime}/datarc-workspace-configuration/references/artifacts.md +75 -75
- package/{skills → runtime}/datarc-workspace-configuration/references/verification.md +20 -20
- package/{skills → runtime}/datarc-workspace-configuration/scripts/configuration.mjs +722 -662
- package/{skills → runtime}/datarc-workspace-context/SKILL.md +43 -43
- package/{skills → runtime}/datarc-workspace-context/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-context/scripts/datarc-client.mjs +31 -31
- package/{skills → runtime}/datarc-workspace-context/scripts/query-display.mjs +114 -114
- package/{skills → runtime}/datarc-workspace-context/scripts/workspace-context.mjs +58 -58
- package/{skills → runtime}/datarc-workspace-custom-tables/SKILL.md +89 -89
- package/{skills → runtime}/datarc-workspace-custom-tables/scripts/datarc-client.mjs +165 -165
- package/{skills → runtime}/datarc-workspace-custom-tables/scripts/workspace-custom-tables.mjs +601 -601
- package/{skills → runtime}/datarc-workspace-keywords/SKILL.md +197 -197
- package/{skills → runtime}/datarc-workspace-keywords/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-keywords/references/api-fields.md +79 -79
- package/{skills → runtime}/datarc-workspace-keywords/references/derived-measures.md +177 -177
- package/{skills → runtime}/datarc-workspace-keywords/scripts/datarc-client.mjs +145 -145
- package/{skills → runtime}/datarc-workspace-keywords/scripts/workspace-keywords.mjs +2421 -2421
- package/{skills → runtime}/datarc-workspace-membership/SKILL.md +29 -29
- package/{skills → runtime}/datarc-workspace-membership/references/api.md +19 -19
- package/{skills → runtime}/datarc-workspace-modeling/SKILL.md +209 -209
- package/{skills → runtime}/datarc-workspace-modeling/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-modeling/references/join-preview.md +38 -38
- package/{skills → runtime}/datarc-workspace-modeling/references/model-plan.md +300 -300
- package/{skills → runtime}/datarc-workspace-modeling/references/model-tags.md +95 -95
- package/{skills → runtime}/datarc-workspace-modeling/references/modeling-contract.json +29 -29
- package/{skills → runtime}/datarc-workspace-modeling/references/modeling-fixtures.json +2423 -2423
- package/{skills → runtime}/datarc-workspace-modeling/scripts/datarc-client.mjs +137 -137
- package/{skills → runtime}/datarc-workspace-modeling/scripts/workspace-model-tags.mjs +238 -238
- package/{skills → runtime}/datarc-workspace-modeling/scripts/workspace-modeling.mjs +1261 -1261
- package/skills-provider.js +51 -0
- package/workflow-index.json +434 -0
- package/icon.svg +0 -4
- package/skills/datarc-report-add-card/scripts/datarc-client.mjs +0 -464
- package/skills-index.json +0 -194
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
export class DatarcError extends Error {
|
|
5
|
-
constructor(message, code = "DATARC_ERROR", details) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.name = "DatarcError";
|
|
8
|
-
this.code = code;
|
|
9
|
-
this.details = details;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function parseArgs(argv) {
|
|
14
|
-
const result = { _: [] };
|
|
15
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
16
|
-
const value = argv[index];
|
|
17
|
-
if (!value.startsWith("--")) {
|
|
18
|
-
result._.push(value);
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
const key = value.slice(2);
|
|
22
|
-
const next = argv[index + 1];
|
|
23
|
-
if (next === undefined || next.startsWith("--")) result[key] = true;
|
|
24
|
-
else {
|
|
25
|
-
result[key] =
|
|
26
|
-
result[key] === undefined ? next : [].concat(result[key], next);
|
|
27
|
-
index += 1;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function required(args, key) {
|
|
34
|
-
if (args[key] === undefined || args[key] === true || args[key] === "")
|
|
35
|
-
throw new DatarcError(`缺少参数 --${key}`, "INVALID_ARGUMENT");
|
|
36
|
-
return args[key];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export async function readJson(path) {
|
|
40
|
-
const text = path === "-" ? await readStdin() : await readFile(path, "utf8");
|
|
41
|
-
try {
|
|
42
|
-
return JSON.parse(text);
|
|
43
|
-
} catch {
|
|
44
|
-
throw new DatarcError("输入不是有效 JSON", "INVALID_JSON");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function createClient(options = {}) {
|
|
49
|
-
const { endpoint, token } = resolveCredentials(options);
|
|
50
|
-
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
51
|
-
if (!endpoint)
|
|
52
|
-
throw new DatarcError("未配置 DATARC_ENDPOINT", "MISSING_ENDPOINT");
|
|
53
|
-
if (!token) throw new DatarcError("未配置 DATARC_TOKEN", "MISSING_TOKEN");
|
|
54
|
-
async function request(method, path, { query, body } = {}) {
|
|
55
|
-
const url = new URL(`${endpoint}${path}`);
|
|
56
|
-
for (const [key, value] of Object.entries(query ?? {}))
|
|
57
|
-
for (const item of [].concat(value ?? []))
|
|
58
|
-
if (item !== "") url.searchParams.append(key, item);
|
|
59
|
-
let response;
|
|
60
|
-
try {
|
|
61
|
-
response = await fetchImpl(url, {
|
|
62
|
-
method,
|
|
63
|
-
headers: {
|
|
64
|
-
Authorization: token,
|
|
65
|
-
...(body === undefined ? {} : { "Content-Type": "application/json" }),
|
|
66
|
-
},
|
|
67
|
-
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
68
|
-
});
|
|
69
|
-
} catch (error) {
|
|
70
|
-
throw new DatarcError(`网络请求失败:${error.message}`, "NETWORK_ERROR");
|
|
71
|
-
}
|
|
72
|
-
const text = await response.text();
|
|
73
|
-
let payload;
|
|
74
|
-
try {
|
|
75
|
-
payload = text ? JSON.parse(text) : {};
|
|
76
|
-
} catch {
|
|
77
|
-
throw new DatarcError(
|
|
78
|
-
`服务返回非 JSON(HTTP ${response.status})`,
|
|
79
|
-
"INVALID_RESPONSE",
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
if (!response.ok || (payload.status && payload.status !== "SUCCESS"))
|
|
83
|
-
throw new DatarcError(
|
|
84
|
-
payload.message || `请求失败(HTTP ${response.status})`,
|
|
85
|
-
"API_ERROR",
|
|
86
|
-
{
|
|
87
|
-
httpStatus: response.status,
|
|
88
|
-
status: payload.status,
|
|
89
|
-
data: payload.data,
|
|
90
|
-
},
|
|
91
|
-
);
|
|
92
|
-
return payload.data;
|
|
93
|
-
}
|
|
94
|
-
return { request };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function encryptSql(value) {
|
|
98
|
-
const first = Buffer.from(String(value), "utf8").toString("base64url");
|
|
99
|
-
const second = Buffer.from([...first].reverse().join(""), "utf8").toString(
|
|
100
|
-
"base64url",
|
|
101
|
-
);
|
|
102
|
-
return [...second].reverse().join("");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function decryptSql(value) {
|
|
106
|
-
const second = [...String(value)].reverse().join("");
|
|
107
|
-
const firstReversed = Buffer.from(second, "base64url").toString("utf8");
|
|
108
|
-
const first = [...firstReversed].reverse().join("");
|
|
109
|
-
return Buffer.from(first, "base64url").toString("utf8");
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function errorJson(error) {
|
|
113
|
-
return {
|
|
114
|
-
code: error?.code ?? "UNEXPECTED_ERROR",
|
|
115
|
-
message: error?.message ?? String(error),
|
|
116
|
-
...(error?.details ? { details: error.details } : {}),
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export async function runCli(main) {
|
|
121
|
-
try {
|
|
122
|
-
process.stdout.write(
|
|
123
|
-
`${JSON.stringify({ ok: true, data: await main() }, null, 2)}\n`,
|
|
124
|
-
);
|
|
125
|
-
} catch (error) {
|
|
126
|
-
process.stdout.write(
|
|
127
|
-
`${JSON.stringify({ ok: false, error: errorJson(error) }, null, 2)}\n`,
|
|
128
|
-
);
|
|
129
|
-
process.exitCode = 1;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async function readStdin() {
|
|
134
|
-
const chunks = [];
|
|
135
|
-
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
136
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
137
|
-
}
|
|
1
|
+
import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
export class DatarcError extends Error {
|
|
5
|
+
constructor(message, code = "DATARC_ERROR", details) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "DatarcError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.details = details;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function parseArgs(argv) {
|
|
14
|
+
const result = { _: [] };
|
|
15
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
16
|
+
const value = argv[index];
|
|
17
|
+
if (!value.startsWith("--")) {
|
|
18
|
+
result._.push(value);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const key = value.slice(2);
|
|
22
|
+
const next = argv[index + 1];
|
|
23
|
+
if (next === undefined || next.startsWith("--")) result[key] = true;
|
|
24
|
+
else {
|
|
25
|
+
result[key] =
|
|
26
|
+
result[key] === undefined ? next : [].concat(result[key], next);
|
|
27
|
+
index += 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function required(args, key) {
|
|
34
|
+
if (args[key] === undefined || args[key] === true || args[key] === "")
|
|
35
|
+
throw new DatarcError(`缺少参数 --${key}`, "INVALID_ARGUMENT");
|
|
36
|
+
return args[key];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function readJson(path) {
|
|
40
|
+
const text = path === "-" ? await readStdin() : await readFile(path, "utf8");
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(text);
|
|
43
|
+
} catch {
|
|
44
|
+
throw new DatarcError("输入不是有效 JSON", "INVALID_JSON");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createClient(options = {}) {
|
|
49
|
+
const { endpoint, token } = resolveCredentials(options);
|
|
50
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
51
|
+
if (!endpoint)
|
|
52
|
+
throw new DatarcError("未配置 DATARC_ENDPOINT", "MISSING_ENDPOINT");
|
|
53
|
+
if (!token) throw new DatarcError("未配置 DATARC_TOKEN", "MISSING_TOKEN");
|
|
54
|
+
async function request(method, path, { query, body } = {}) {
|
|
55
|
+
const url = new URL(`${endpoint}${path}`);
|
|
56
|
+
for (const [key, value] of Object.entries(query ?? {}))
|
|
57
|
+
for (const item of [].concat(value ?? []))
|
|
58
|
+
if (item !== "") url.searchParams.append(key, item);
|
|
59
|
+
let response;
|
|
60
|
+
try {
|
|
61
|
+
response = await fetchImpl(url, {
|
|
62
|
+
method,
|
|
63
|
+
headers: {
|
|
64
|
+
Authorization: token,
|
|
65
|
+
...(body === undefined ? {} : { "Content-Type": "application/json" }),
|
|
66
|
+
},
|
|
67
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
throw new DatarcError(`网络请求失败:${error.message}`, "NETWORK_ERROR");
|
|
71
|
+
}
|
|
72
|
+
const text = await response.text();
|
|
73
|
+
let payload;
|
|
74
|
+
try {
|
|
75
|
+
payload = text ? JSON.parse(text) : {};
|
|
76
|
+
} catch {
|
|
77
|
+
throw new DatarcError(
|
|
78
|
+
`服务返回非 JSON(HTTP ${response.status})`,
|
|
79
|
+
"INVALID_RESPONSE",
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (!response.ok || (payload.status && payload.status !== "SUCCESS"))
|
|
83
|
+
throw new DatarcError(
|
|
84
|
+
payload.message || `请求失败(HTTP ${response.status})`,
|
|
85
|
+
"API_ERROR",
|
|
86
|
+
{
|
|
87
|
+
httpStatus: response.status,
|
|
88
|
+
status: payload.status,
|
|
89
|
+
data: payload.data,
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
return payload.data;
|
|
93
|
+
}
|
|
94
|
+
return { request };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function encryptSql(value) {
|
|
98
|
+
const first = Buffer.from(String(value), "utf8").toString("base64url");
|
|
99
|
+
const second = Buffer.from([...first].reverse().join(""), "utf8").toString(
|
|
100
|
+
"base64url",
|
|
101
|
+
);
|
|
102
|
+
return [...second].reverse().join("");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function decryptSql(value) {
|
|
106
|
+
const second = [...String(value)].reverse().join("");
|
|
107
|
+
const firstReversed = Buffer.from(second, "base64url").toString("utf8");
|
|
108
|
+
const first = [...firstReversed].reverse().join("");
|
|
109
|
+
return Buffer.from(first, "base64url").toString("utf8");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function errorJson(error) {
|
|
113
|
+
return {
|
|
114
|
+
code: error?.code ?? "UNEXPECTED_ERROR",
|
|
115
|
+
message: error?.message ?? String(error),
|
|
116
|
+
...(error?.details ? { details: error.details } : {}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export async function runCli(main) {
|
|
121
|
+
try {
|
|
122
|
+
process.stdout.write(
|
|
123
|
+
`${JSON.stringify({ ok: true, data: await main() }, null, 2)}\n`,
|
|
124
|
+
);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
process.stdout.write(
|
|
127
|
+
`${JSON.stringify({ ok: false, error: errorJson(error) }, null, 2)}\n`,
|
|
128
|
+
);
|
|
129
|
+
process.exitCode = 1;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function readStdin() {
|
|
134
|
+
const chunks = [];
|
|
135
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
136
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
137
|
+
}
|