@hallohuman/hightea 0.1.1 → 0.1.8
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/dist/bin.js +210 -13
- package/dist/chunk-0ab6h39c.js +402 -0
- package/dist/chunk-3qbh10ga.js +12 -0
- package/dist/chunk-5mezgvms.js +139 -0
- package/dist/chunk-99e0mv8w.js +7313 -0
- package/dist/chunk-c8kc1c68.js +78 -0
- package/dist/chunk-d5h204vj.js +14 -0
- package/dist/{chunk-24qdztvs.js → chunk-k2ws7xvy.js} +303 -22
- package/dist/chunk-py45wjd1.js +91 -0
- package/dist/chunk-sbqmqp8e.js +123 -0
- package/dist/chunk-v59kcfmj.js +347 -0
- package/dist/plugin/plugin.json +1 -1
- package/dist/plugin/plugin.mjs +2180 -123
- package/package.json +9 -5
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import"./chunk-0ab6h39c.js";
|
|
2
|
+
import {
|
|
3
|
+
ownerIo,
|
|
4
|
+
sendOwner
|
|
5
|
+
} from "./chunk-sbqmqp8e.js";
|
|
6
|
+
|
|
7
|
+
// src/source.ts
|
|
8
|
+
var USAGE = `hightea source bind --origin https://your-deployment --workspace SLUG --source SOURCE --host HOST [--refresh 1h] [--session-file FILE] [--json]
|
|
9
|
+
` + `hightea source unbind --origin https://your-deployment --workspace SLUG --source SOURCE [--session-file FILE] [--json]
|
|
10
|
+
` + `hightea source set-refresh --origin https://your-deployment --workspace SLUG --source SOURCE --every 1h [--session-file FILE] [--json]
|
|
11
|
+
` + "hightea source show --origin https://your-deployment --workspace SLUG --source SOURCE [--session-file FILE] [--json]";
|
|
12
|
+
function parseRefreshInterval(text) {
|
|
13
|
+
const raw = text.trim().toLowerCase();
|
|
14
|
+
if (raw === "")
|
|
15
|
+
return "INVALID";
|
|
16
|
+
if (raw === "none" || raw === "off")
|
|
17
|
+
return null;
|
|
18
|
+
const match = /^(\d+)(s|m|h|d)$/u.exec(raw);
|
|
19
|
+
if (match === null)
|
|
20
|
+
return "INVALID";
|
|
21
|
+
const unit = { s: 1000, m: 60000, h: 3600000, d: 86400000 }[match[2]];
|
|
22
|
+
const ms = Number(match[1]) * unit;
|
|
23
|
+
return Number.isSafeInteger(ms) && ms > 0 ? ms : "INVALID";
|
|
24
|
+
}
|
|
25
|
+
var BOUND_ELSEWHERE = { SOURCE_BINDING_CONFLICT: 4 };
|
|
26
|
+
function defaults() {
|
|
27
|
+
return ownerIo();
|
|
28
|
+
}
|
|
29
|
+
async function send(target, io, request) {
|
|
30
|
+
if (target.workspace.trim().length === 0 || target.source.trim().length === 0) {
|
|
31
|
+
return { exit: 1, error: `SOURCE_INPUT: --workspace and --source are required.
|
|
32
|
+
${USAGE}` };
|
|
33
|
+
}
|
|
34
|
+
return sendOwner(target, io, {
|
|
35
|
+
...request,
|
|
36
|
+
label: "SOURCE",
|
|
37
|
+
extraExits: BOUND_ELSEWHERE,
|
|
38
|
+
path: `/sources/${encodeURIComponent(target.source)}${request.path}`
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function datasetLine(source) {
|
|
42
|
+
const field = (name) => source[name] === null || source[name] === undefined ? "none" : String(source[name]);
|
|
43
|
+
const listing = source.listing === true ? ", first list running" : source.listing === false ? ", no list running" : "";
|
|
44
|
+
return `${field("status")} on ${field("hostId")} as dataset ${field("dataset")} (freshness ${field("freshness")}${listing})`;
|
|
45
|
+
}
|
|
46
|
+
async function sourceBind(target, io = defaults()) {
|
|
47
|
+
if (target.host.trim().length === 0) {
|
|
48
|
+
io.err(`SOURCE_INPUT: --host is required (the host id that serves the source).
|
|
49
|
+
${USAGE}`);
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
const refreshMs = target.refresh === undefined ? undefined : parseRefreshInterval(target.refresh);
|
|
53
|
+
if (refreshMs === "INVALID" || refreshMs === null) {
|
|
54
|
+
io.err(`SOURCE_INPUT: --refresh takes a whole count and one unit — 30m, 1h, 2d — and a bind never clears a schedule.
|
|
55
|
+
${USAGE}`);
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
const sent = await send(target, io, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
path: "/bind",
|
|
61
|
+
body: refreshMs === undefined ? { hostId: target.host.trim() } : { hostId: target.host.trim(), refreshMs },
|
|
62
|
+
what: "bind"
|
|
63
|
+
});
|
|
64
|
+
if ("error" in sent) {
|
|
65
|
+
io.err(sent.error);
|
|
66
|
+
return sent.exit;
|
|
67
|
+
}
|
|
68
|
+
if (target.json) {
|
|
69
|
+
io.out(JSON.stringify(sent.answer));
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
const source = sent.answer.source ?? {};
|
|
73
|
+
io.out(`bound ${String(source.sourceId ?? target.source)} to ${String(source.hostId ?? target.host)}: ${datasetLine(source)}`);
|
|
74
|
+
io.out("The source's first list fills its dataset; run `hightea source show` to watch its freshness.");
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
async function sourceUnbind(target, io = defaults()) {
|
|
78
|
+
const sent = await send(target, io, { method: "POST", path: "/unbind", what: "unbind" });
|
|
79
|
+
if ("error" in sent) {
|
|
80
|
+
io.err(sent.error);
|
|
81
|
+
return sent.exit;
|
|
82
|
+
}
|
|
83
|
+
if (target.json) {
|
|
84
|
+
io.out(JSON.stringify(sent.answer));
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
const source = sent.answer.source ?? {};
|
|
88
|
+
io.out(`unbound ${String(source.sourceId ?? target.source)} from ${String(source.hostId ?? "its host")}: ${datasetLine(source)}`);
|
|
89
|
+
io.out("Rows kept; rebind refreshes them.");
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
async function sourceShow(target, io = defaults()) {
|
|
93
|
+
const sent = await send(target, io, { method: "GET", path: "", what: "read" });
|
|
94
|
+
if ("error" in sent) {
|
|
95
|
+
io.err(sent.error);
|
|
96
|
+
return sent.exit;
|
|
97
|
+
}
|
|
98
|
+
if (target.json) {
|
|
99
|
+
io.out(JSON.stringify(sent.answer));
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
const source = sent.answer.source ?? {};
|
|
103
|
+
const position = source.position;
|
|
104
|
+
io.out(`${String(source.sourceId ?? target.source)}: ${datasetLine(source)}`);
|
|
105
|
+
io.out(`position ${position === null || position === undefined ? "none" : `${String(position.epoch)}/${String(position.ordinal)}`}, ` + `last error ${source.lastError === null || source.lastError === undefined ? "none" : String(source.lastError)}, ` + `dropped ${String(source.dropped ?? 0)}, duplicates ${String(source.duplicates ?? 0)}`);
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
async function sourceSetRefresh(target, io = defaults()) {
|
|
109
|
+
if (target.every.trim().length === 0) {
|
|
110
|
+
io.err(`SOURCE_INPUT: --every is required (1h, 30m, 2d, or none).
|
|
111
|
+
${USAGE}`);
|
|
112
|
+
return 1;
|
|
113
|
+
}
|
|
114
|
+
const everyMs = parseRefreshInterval(target.every);
|
|
115
|
+
if (everyMs === "INVALID") {
|
|
116
|
+
io.err(`SOURCE_INPUT: --every takes a whole count and one unit — 45s, 30m, 1h, 2d — or none.
|
|
117
|
+
${USAGE}`);
|
|
118
|
+
return 1;
|
|
119
|
+
}
|
|
120
|
+
const sent = await send(target, io, { method: "POST", path: "/schedule", body: { everyMs }, what: "set its refresh interval" });
|
|
121
|
+
if ("error" in sent) {
|
|
122
|
+
io.err(sent.error);
|
|
123
|
+
return sent.exit;
|
|
124
|
+
}
|
|
125
|
+
if (target.json) {
|
|
126
|
+
io.out(JSON.stringify(sent.answer));
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
const source = sent.answer.source ?? {};
|
|
130
|
+
const declared = source.reconcileMs === null || source.reconcileMs === undefined ? "no schedule (refreshes only when the host reports a gap)" : `refresh every ${Math.round(Number(source.reconcileMs) / 60000)} min`;
|
|
131
|
+
io.out(`${String(source.sourceId ?? target.source)}: ${declared}; ${datasetLine(source)}`);
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
sourceBind,
|
|
136
|
+
sourceSetRefresh,
|
|
137
|
+
sourceShow,
|
|
138
|
+
sourceUnbind
|
|
139
|
+
};
|