@wirecat/zoom-cli 0.55.0 → 0.57.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 +4 -4
- package/dist/bin/zm.js +35 -5
- package/dist/bundle/all-profiles-EKHWTGOY.js +25 -0
- package/dist/bundle/answer-policy-KH2IFXPN.js +96 -0
- package/dist/bundle/anthropic-VL54IUGF.js +70 -0
- package/dist/bundle/bun-ADJVI4HY.js +169 -0
- package/dist/bundle/bun-sqlite-2SDA3YOT.js +69 -0
- package/dist/bundle/chunk-2IKY7VBH.js +9 -0
- package/dist/bundle/chunk-2WOGZDZG.js +431 -0
- package/dist/bundle/chunk-4R7HYNZS.js +73 -0
- package/dist/bundle/chunk-4VCA7QU3.js +538 -0
- package/dist/bundle/chunk-4YLS4YLS.js +29 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-5F7IOESV.js +281 -0
- package/dist/bundle/chunk-5QESMCQK.js +122 -0
- package/dist/bundle/chunk-6M6FJV5D.js +138 -0
- package/dist/bundle/chunk-6MX5T6AQ.js +17 -0
- package/dist/bundle/chunk-6P3YHT54.js +385 -0
- package/dist/bundle/chunk-7A6PZUDR.js +938 -0
- package/dist/bundle/chunk-7GUG6UZS.js +884 -0
- package/dist/bundle/chunk-7JZJMHQY.js +487 -0
- package/dist/bundle/chunk-A4ETXPMZ.js +98 -0
- package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
- package/dist/bundle/chunk-AE4BOXH7.js +5292 -0
- package/dist/bundle/chunk-AN3GVZTU.js +76 -0
- package/dist/bundle/chunk-BAYNCCNM.js +215 -0
- package/dist/bundle/chunk-BW2WPOXP.js +166 -0
- package/dist/bundle/chunk-BW52AJ4R.js +3387 -0
- package/dist/bundle/chunk-CB5UTASG.js +18 -0
- package/dist/bundle/chunk-CLMXBW53.js +1028 -0
- package/dist/bundle/chunk-DCTXOMOR.js +35 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-EOQFWJJD.js +1095 -0
- package/dist/bundle/chunk-G4R4ZIGD.js +3569 -0
- package/dist/bundle/chunk-G4VZDINN.js +161 -0
- package/dist/bundle/chunk-GARCOIB6.js +409 -0
- package/dist/bundle/chunk-GKMGS7G5.js +1938 -0
- package/dist/bundle/chunk-HCNMFFG3.js +82 -0
- package/dist/bundle/chunk-HG5KRV55.js +1970 -0
- package/dist/bundle/chunk-HKYLSIZ2.js +82 -0
- package/dist/bundle/chunk-HTQTIKWP.js +928 -0
- package/dist/bundle/chunk-I4VQDXFR.js +100 -0
- package/dist/bundle/chunk-ICSKEDPI.js +36139 -0
- package/dist/bundle/chunk-IP4OK7RQ.js +24 -0
- package/dist/bundle/chunk-IVQ6342B.js +2 -0
- package/dist/bundle/chunk-K72SEMYI.js +160 -0
- package/dist/bundle/chunk-LHRCJYFC.js +19 -0
- package/dist/bundle/chunk-LPTIQLDW.js +192 -0
- package/dist/bundle/chunk-LQ3T2ZIX.js +124 -0
- package/dist/bundle/chunk-LSVI3A5X.js +836 -0
- package/dist/bundle/chunk-LW2G4U6W.js +570 -0
- package/dist/bundle/chunk-LXB6ONWC.js +3517 -0
- package/dist/bundle/chunk-LY26NW3I.js +6848 -0
- package/dist/bundle/chunk-MAEFLDHG.js +6092 -0
- package/dist/bundle/chunk-MZH4GDR4.js +45 -0
- package/dist/bundle/chunk-NN5B24KP.js +1109 -0
- package/dist/bundle/chunk-NO7CJEYV.js +22 -0
- package/dist/bundle/chunk-NTDWAAGL.js +18435 -0
- package/dist/bundle/chunk-NW3X3G5X.js +264 -0
- package/dist/bundle/chunk-O66V2WHK.js +48 -0
- package/dist/bundle/chunk-OCGPZHXW.js +25 -0
- package/dist/bundle/chunk-OIHDCGV4.js +151 -0
- package/dist/bundle/chunk-OVSWVPXL.js +8190 -0
- package/dist/bundle/chunk-PIN5RZ3D.js +63 -0
- package/dist/bundle/chunk-QLIB3PEC.js +1146 -0
- package/dist/bundle/chunk-QTR6D5HT.js +58 -0
- package/dist/bundle/chunk-QUJPQMHJ.js +2315 -0
- package/dist/bundle/chunk-R3HPOCZD.js +188 -0
- package/dist/bundle/chunk-RMV4C2YL.js +482 -0
- package/dist/bundle/chunk-RRRBMQ2E.js +844 -0
- package/dist/bundle/chunk-S4S7E54J.js +60 -0
- package/dist/bundle/chunk-SB6WOSHG.js +1109 -0
- package/dist/bundle/chunk-SE75DPBY.js +31 -0
- package/dist/bundle/chunk-SQJ7EH2D.js +97 -0
- package/dist/bundle/chunk-TKCHUT2H.js +422 -0
- package/dist/bundle/chunk-TLQUKHEM.js +193 -0
- package/dist/bundle/chunk-TZ2MKETI.js +100 -0
- package/dist/bundle/chunk-UC44ZMQV.js +78 -0
- package/dist/bundle/chunk-UI5UTMSZ.js +275 -0
- package/dist/bundle/chunk-VPPYYWOH.js +630 -0
- package/dist/bundle/chunk-WJHK5D7Z.js +35612 -0
- package/dist/bundle/chunk-WQ24UC44.js +239 -0
- package/dist/bundle/chunk-X5DFDGWS.js +2 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-YB4DMKYX.js +119 -0
- package/dist/bundle/chunk-Z4TZ6TAF.js +288 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/cli-72EQATJF.js +825 -0
- package/dist/bundle/command-contract-4MHSZUN3.js +38 -0
- package/dist/bundle/config-GFIJK6G2.js +79 -0
- package/dist/bundle/dist-IBNHCQXT.js +136 -0
- package/dist/bundle/dist-XUFQCJXW.js +7577 -0
- package/dist/bundle/echarts-RFTK737T.js +42501 -0
- package/dist/bundle/embed-7QYA2ZZE.js +35 -0
- package/dist/bundle/embedder-YNN6PCHG.js +108 -0
- package/dist/bundle/first-run-EVSRQKZJ.js +23 -0
- package/dist/bundle/first-screen-RG4GUKW7.js +36 -0
- package/dist/bundle/folders-JEPOMYM4.js +13 -0
- package/dist/bundle/instructions-FHNL7CMW.js +9 -0
- package/dist/bundle/main-NYGJXPH7.js +130 -0
- package/dist/bundle/mcp-IXFC2VVR.js +165 -0
- package/dist/bundle/mcp-VGSZDCKK.js +189 -0
- package/dist/bundle/mcp-XKP2PXLS.js +92 -0
- package/dist/bundle/meetings-IBPI4MM4.js +215 -0
- package/dist/bundle/node-P4E63KXA.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-ZMCACJVS.js +176 -0
- package/dist/bundle/node-sqlite-ZNGOBA5Q.js +45 -0
- package/dist/bundle/oauth-Q6LKF7DB.js +17 -0
- package/dist/bundle/open-LJ332Y5O.js +19 -0
- package/dist/bundle/output-file-RYQZ3RTE.js +63 -0
- package/dist/bundle/process-ZPTLNVQS.js +91 -0
- package/dist/bundle/program-IBRQBQ6W.js +5845 -0
- package/dist/bundle/prompt-RT7GUUXH.js +12 -0
- package/dist/bundle/recognize-QXGE7YJH.js +190 -0
- package/dist/bundle/remote-FD4MZQV3.js +26 -0
- package/dist/bundle/rerank-V6AVV755.js +49 -0
- package/dist/bundle/run-log-RE2EI3UU.js +111 -0
- package/dist/bundle/serve-HIJTFAW7.js +19 -0
- package/dist/bundle/server-3QOXOYYL.js +53 -0
- package/dist/bundle/server-WLJCU7KK.js +812 -0
- package/dist/bundle/services-KC5KQFBS.js +330 -0
- package/dist/bundle/speech-5JOXLYDA.js +44 -0
- package/dist/bundle/state-PPGRB3T6.js +33 -0
- package/dist/bundle/store-LODVDPK3.js +141 -0
- package/dist/bundle/store-WB5BICTG.js +124 -0
- package/dist/bundle/store-connection-EG6Z5ITP.js +76 -0
- package/dist/bundle/store-maintenance-command-Q5WMFUZ2.js +54 -0
- package/dist/bundle/streaming-UGFFNOXL.js +15 -0
- package/dist/bundle/tokens-AF5CPY2F.js +17 -0
- package/dist/bundle/zm.js +8 -0
- package/dist/commands.js +2 -2
- package/dist/commands.js.map +1 -1
- package/dist/config-issues.d.ts.map +1 -1
- package/dist/config-issues.js +3 -0
- package/dist/config-issues.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +23 -0
- package/dist/config.js.map +1 -1
- package/dist/contract-overrides.d.ts.map +1 -1
- package/dist/contract-overrides.js +34 -45
- package/dist/contract-overrides.js.map +1 -1
- package/dist/first-screen.js +1 -1
- package/dist/first-screen.js.map +1 -1
- package/dist/mcp-command.d.ts +5 -3
- package/dist/mcp-command.d.ts.map +1 -1
- package/dist/mcp-command.js +73 -15
- package/dist/mcp-command.js.map +1 -1
- package/dist/program-bindings.d.ts.map +1 -1
- package/dist/program-bindings.js +1 -0
- package/dist/program-bindings.js.map +1 -1
- package/dist/recording-archive.d.ts.map +1 -1
- package/dist/recording-archive.js +9 -4
- package/dist/recording-archive.js.map +1 -1
- package/dist/remote-http.d.ts +2 -0
- package/dist/remote-http.d.ts.map +1 -1
- package/dist/remote-http.js +21 -11
- package/dist/remote-http.js.map +1 -1
- package/dist/request-events.d.ts +12 -0
- package/dist/request-events.d.ts.map +1 -1
- package/dist/request-events.js +56 -4
- package/dist/request-events.js.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +4 -1
- package/dist/run.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -5
- package/skills/zoom-cli/SKILL.md +3 -1
|
@@ -0,0 +1,836 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
CliError,
|
|
5
|
+
RegistryError,
|
|
6
|
+
SNAKE_CASE,
|
|
7
|
+
array,
|
|
8
|
+
boolean,
|
|
9
|
+
defineReasons,
|
|
10
|
+
duplicates,
|
|
11
|
+
integer,
|
|
12
|
+
isCliError,
|
|
13
|
+
lazy,
|
|
14
|
+
literal,
|
|
15
|
+
minValue,
|
|
16
|
+
number,
|
|
17
|
+
object,
|
|
18
|
+
optional,
|
|
19
|
+
picklist,
|
|
20
|
+
pipe,
|
|
21
|
+
reference,
|
|
22
|
+
string,
|
|
23
|
+
variant
|
|
24
|
+
} from "./chunk-AE4BOXH7.js";
|
|
25
|
+
import {
|
|
26
|
+
__name
|
|
27
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
28
|
+
|
|
29
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/query/types.js
|
|
30
|
+
var QUERY_LIMITS = {
|
|
31
|
+
bytes: 8192,
|
|
32
|
+
depth: 32,
|
|
33
|
+
nodes: 256
|
|
34
|
+
};
|
|
35
|
+
var spanSchema = object({ start: number(), end: number() });
|
|
36
|
+
var predicateSchema = object({
|
|
37
|
+
kind: literal("predicate"),
|
|
38
|
+
field: string(),
|
|
39
|
+
operator: picklist(["term", "phrase", "wildcard", "regex", "range"]),
|
|
40
|
+
value: string(),
|
|
41
|
+
upper: optional(string()),
|
|
42
|
+
lower_inclusive: optional(boolean()),
|
|
43
|
+
upper_inclusive: optional(boolean()),
|
|
44
|
+
span: spanSchema,
|
|
45
|
+
implicit: optional(literal(true)),
|
|
46
|
+
slop: optional(pipe(number(), integer(), minValue(0)))
|
|
47
|
+
});
|
|
48
|
+
var queryNodeSchema = variant("kind", [
|
|
49
|
+
predicateSchema,
|
|
50
|
+
object({
|
|
51
|
+
kind: literal("boolean"),
|
|
52
|
+
clauses: array(object({ occur: picklist(["must", "should", "must_not"]), node: lazy(() => queryNodeSchema) })),
|
|
53
|
+
span: spanSchema
|
|
54
|
+
})
|
|
55
|
+
]);
|
|
56
|
+
var queryAstSchema = object({
|
|
57
|
+
version: literal(1),
|
|
58
|
+
language: literal("lucene-v1"),
|
|
59
|
+
root: queryNodeSchema
|
|
60
|
+
});
|
|
61
|
+
function queryError(reason, span, alternative, context = {}, details = {}) {
|
|
62
|
+
throw new CliError("validation_error", `${context.command ?? "query"}: ${reason} at position ${span.start + 1}${alternative ? ` \u2014 ${alternative}` : ""}`, {
|
|
63
|
+
reason,
|
|
64
|
+
span,
|
|
65
|
+
...alternative ? { alternative } : {},
|
|
66
|
+
...context.guide ? { guide: context.guide } : {},
|
|
67
|
+
...details
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
__name(queryError, "queryError");
|
|
71
|
+
var walkQuery = /* @__PURE__ */ __name((node) => node.kind === "predicate" ? [node] : node.clauses.flatMap(({ node: node2 }) => walkQuery(node2)), "walkQuery");
|
|
72
|
+
|
|
73
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/query/dates.js
|
|
74
|
+
var timezoneOf = /* @__PURE__ */ __name((given) => {
|
|
75
|
+
const zone = given ?? Intl.DateTimeFormat().resolvedOptions().timeZone ?? "UTC";
|
|
76
|
+
try {
|
|
77
|
+
new Intl.DateTimeFormat("en", { timeZone: zone }).format(0);
|
|
78
|
+
} catch {
|
|
79
|
+
queryError("query.invalid-timezone", { start: 0, end: 0 }, "use an IANA timezone such as Europe/Madrid");
|
|
80
|
+
}
|
|
81
|
+
return zone;
|
|
82
|
+
}, "timezoneOf");
|
|
83
|
+
var calendar = /* @__PURE__ */ __name((value, span) => {
|
|
84
|
+
if (!/^\d{4}-\d{2}-\d{2}$/u.test(value))
|
|
85
|
+
queryError("query.invalid-date", span, "use an ISO date or a quoted timestamp with offset");
|
|
86
|
+
const year = Number(value.slice(0, 4)), month = Number(value.slice(5, 7)), day = Number(value.slice(8, 10));
|
|
87
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
88
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
89
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
90
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day)
|
|
91
|
+
queryError("query.invalid-date", span);
|
|
92
|
+
return date;
|
|
93
|
+
}, "calendar");
|
|
94
|
+
var dayBoundary = /* @__PURE__ */ __name((value, zone, next, span) => {
|
|
95
|
+
const date = calendar(value, span);
|
|
96
|
+
if (next)
|
|
97
|
+
date.setUTCDate(date.getUTCDate() + 1);
|
|
98
|
+
const wanted = date.getUTCFullYear() * 1e4 + (date.getUTCMonth() + 1) * 100 + date.getUTCDate();
|
|
99
|
+
const formatter = new Intl.DateTimeFormat("en-CA", {
|
|
100
|
+
timeZone: zone,
|
|
101
|
+
year: "numeric",
|
|
102
|
+
month: "2-digit",
|
|
103
|
+
day: "2-digit",
|
|
104
|
+
era: "short"
|
|
105
|
+
});
|
|
106
|
+
const dayAt = /* @__PURE__ */ __name((time) => {
|
|
107
|
+
const parts = formatter.formatToParts(time);
|
|
108
|
+
const value2 = /* @__PURE__ */ __name((name) => Number(parts.find((p) => p.type === name)?.value), "value");
|
|
109
|
+
const year = parts.find((p) => p.type === "era")?.value === "BC" ? 1 - value2("year") : value2("year");
|
|
110
|
+
return year * 1e4 + value2("month") * 100 + value2("day");
|
|
111
|
+
}, "dayAt");
|
|
112
|
+
let lo = date.getTime() - 2 * 864e5, hi = date.getTime() + 2 * 864e5;
|
|
113
|
+
while (lo < hi) {
|
|
114
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
115
|
+
if (dayAt(mid) < wanted)
|
|
116
|
+
lo = mid + 1;
|
|
117
|
+
else
|
|
118
|
+
hi = mid;
|
|
119
|
+
}
|
|
120
|
+
if (dayAt(lo) !== wanted)
|
|
121
|
+
queryError("query.invalid-date", span, "this calendar day does not exist in the selected timezone");
|
|
122
|
+
return lo;
|
|
123
|
+
}, "dayBoundary");
|
|
124
|
+
var WALL = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?$/u;
|
|
125
|
+
var wallTime = /* @__PURE__ */ __name((value, zone, span) => {
|
|
126
|
+
const [, year, month, day, hour, minute, second = "0", fraction = "0"] = WALL.exec(value) ?? [];
|
|
127
|
+
if (year === void 0)
|
|
128
|
+
queryError("query.invalid-date", span, "use YYYY-MM-DDTHH:mm, with optional seconds");
|
|
129
|
+
const wanted = Date.UTC(Number(year), Number(month) - 1, Number(day), Number(hour), Number(minute), Number(second), Number(fraction.padEnd(3, "0")));
|
|
130
|
+
const check = new Date(wanted);
|
|
131
|
+
if (check.getUTCDate() !== Number(day) || check.getUTCHours() !== Number(hour) || check.getUTCMinutes() !== Number(minute) || check.getUTCSeconds() !== Number(second))
|
|
132
|
+
queryError("query.invalid-date", span);
|
|
133
|
+
const formatter = new Intl.DateTimeFormat("en-CA", {
|
|
134
|
+
timeZone: zone,
|
|
135
|
+
year: "numeric",
|
|
136
|
+
month: "2-digit",
|
|
137
|
+
day: "2-digit",
|
|
138
|
+
hour: "2-digit",
|
|
139
|
+
minute: "2-digit",
|
|
140
|
+
second: "2-digit",
|
|
141
|
+
hourCycle: "h23"
|
|
142
|
+
});
|
|
143
|
+
const shown = /* @__PURE__ */ __name((instant) => {
|
|
144
|
+
const parts = Object.fromEntries(formatter.formatToParts(instant).map((part) => [part.type, Number(part.value)]));
|
|
145
|
+
return Date.UTC(parts.year ?? 0, (parts.month ?? 1) - 1, parts.day, parts.hour, parts.minute, parts.second) + (instant % 1e3 + 1e3) % 1e3;
|
|
146
|
+
}, "shown");
|
|
147
|
+
const found = /* @__PURE__ */ new Set();
|
|
148
|
+
for (const probe of [wanted - 864e5, wanted, wanted + 864e5]) {
|
|
149
|
+
const candidate = wanted - (shown(probe) - probe);
|
|
150
|
+
if (shown(candidate) === wanted)
|
|
151
|
+
found.add(candidate);
|
|
152
|
+
}
|
|
153
|
+
if (found.size !== 1)
|
|
154
|
+
queryError("query.invalid-date", span, "this local time is skipped or repeated by daylight saving; add an offset");
|
|
155
|
+
return [...found][0];
|
|
156
|
+
}, "wallTime");
|
|
157
|
+
var ZONED = /(?:Z|[+-]\d{2}:?\d{2})$/iu;
|
|
158
|
+
var zonedMoment = /* @__PURE__ */ __name((value, zone, span, { end = false } = {}) => {
|
|
159
|
+
if (/^\d{4}-\d{2}-\d{2}$/u.test(value))
|
|
160
|
+
return dayBoundary(value, zone, end, span) - (end ? 1 : 0);
|
|
161
|
+
if (!ZONED.test(value))
|
|
162
|
+
return wallTime(value, zone, span);
|
|
163
|
+
const time = Date.parse(value);
|
|
164
|
+
if (!/^\d{4}-\d{2}-\d{2}T/u.test(value) || !Number.isFinite(time))
|
|
165
|
+
queryError("query.invalid-date", span);
|
|
166
|
+
calendar(value.slice(0, 10), span);
|
|
167
|
+
return time;
|
|
168
|
+
}, "zonedMoment");
|
|
169
|
+
var AGO = /^(\d+)(m|h|d)$/u;
|
|
170
|
+
var AGO_MS = { m: 6e4, h: 36e5, d: 864e5 };
|
|
171
|
+
var dayOf = /* @__PURE__ */ __name((word, zone, now, span) => {
|
|
172
|
+
const today = new Intl.DateTimeFormat("en-CA", {
|
|
173
|
+
timeZone: zone,
|
|
174
|
+
year: "numeric",
|
|
175
|
+
month: "2-digit",
|
|
176
|
+
day: "2-digit"
|
|
177
|
+
}).format(now);
|
|
178
|
+
if (word === "today")
|
|
179
|
+
return today;
|
|
180
|
+
const date = calendar(today, span);
|
|
181
|
+
date.setUTCDate(date.getUTCDate() - 1);
|
|
182
|
+
return date.toISOString().slice(0, 10);
|
|
183
|
+
}, "dayOf");
|
|
184
|
+
var dateEndpoint = /* @__PURE__ */ __name((value, zone, side, inclusive, span, now = Date.now()) => {
|
|
185
|
+
if (value === "*")
|
|
186
|
+
return { inclusive };
|
|
187
|
+
const word = value.toLowerCase();
|
|
188
|
+
if (word === "today" || word === "yesterday")
|
|
189
|
+
return dateEndpoint(dayOf(word, zone, now, span), zone, side, inclusive, span);
|
|
190
|
+
const [, amount, unit] = AGO.exec(word) ?? [];
|
|
191
|
+
if (amount && unit)
|
|
192
|
+
return { time: now - Number(amount) * (AGO_MS[unit] ?? 0), inclusive };
|
|
193
|
+
if (/^\d{4}-\d{2}-\d{2}$/u.test(value))
|
|
194
|
+
return {
|
|
195
|
+
time: dayBoundary(value, zone, side === "lower" ? !inclusive : inclusive, span),
|
|
196
|
+
inclusive: side === "lower"
|
|
197
|
+
};
|
|
198
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})$/u.test(value))
|
|
199
|
+
queryError("query.invalid-date", span, "use an ISO date, today, yesterday, 30m/2h/7d ago, or a quoted timestamp with offset");
|
|
200
|
+
calendar(value.slice(0, 10), span);
|
|
201
|
+
const time = Date.parse(value);
|
|
202
|
+
if (!Number.isFinite(time) || Number(value.slice(11, 13)) > 23 || Number(value.slice(14, 16)) > 59 || Number(value.slice(17, 19)) > 59)
|
|
203
|
+
queryError("query.invalid-date", span);
|
|
204
|
+
return { time, inclusive };
|
|
205
|
+
}, "dateEndpoint");
|
|
206
|
+
var dateRange = /* @__PURE__ */ __name((lower, upper, lowerInclusive, upperInclusive, zone, span, now = Date.now()) => {
|
|
207
|
+
const since = lower === upper && AGO.test(lower.toLowerCase());
|
|
208
|
+
const lo = dateEndpoint(lower, zone, "lower", lowerInclusive, span, now);
|
|
209
|
+
const hi = dateEndpoint(since ? "*" : upper, zone, "upper", upperInclusive, span, now);
|
|
210
|
+
return {
|
|
211
|
+
...lo.time === void 0 ? {} : { lower: lo.time },
|
|
212
|
+
...hi.time === void 0 ? {} : { upper: hi.time },
|
|
213
|
+
lower_inclusive: lo.inclusive,
|
|
214
|
+
upper_inclusive: hi.inclusive
|
|
215
|
+
};
|
|
216
|
+
}, "dateRange");
|
|
217
|
+
|
|
218
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/query/fields.js
|
|
219
|
+
var FIELD_TYPES = ["kw", "txt", "enum", "num", "time", "bool", "ref"];
|
|
220
|
+
var OPERATORS_BY_TYPE = {
|
|
221
|
+
kw: ["term", "phrase", "wildcard"],
|
|
222
|
+
txt: ["term", "phrase", "wildcard"],
|
|
223
|
+
enum: ["term"],
|
|
224
|
+
num: ["term", "range"],
|
|
225
|
+
time: ["term", "range"],
|
|
226
|
+
bool: ["term"],
|
|
227
|
+
ref: ["term", "phrase"]
|
|
228
|
+
};
|
|
229
|
+
var QUERY_BACKENDS = ["sql", "native"];
|
|
230
|
+
var unwrap = /* @__PURE__ */ __name((schema) => schema.wrapped ? unwrap(schema.wrapped) : schema, "unwrap");
|
|
231
|
+
var REFERENCE_SOURCE = reference.pipe[1].requirement.source;
|
|
232
|
+
var typeOf = /* @__PURE__ */ __name((schema) => {
|
|
233
|
+
const plain = unwrap(schema);
|
|
234
|
+
const actions = plain.pipe ?? [];
|
|
235
|
+
switch (plain.type) {
|
|
236
|
+
case "picklist":
|
|
237
|
+
return { type: "enum", values: (plain.options ?? []).map(String) };
|
|
238
|
+
case "number":
|
|
239
|
+
return { type: "num" };
|
|
240
|
+
case "boolean":
|
|
241
|
+
return { type: "bool" };
|
|
242
|
+
case "string":
|
|
243
|
+
if (actions.some((action) => action.type === "iso_timestamp"))
|
|
244
|
+
return { type: "time" };
|
|
245
|
+
if (actions.some((action) => action.requirement instanceof RegExp && action.requirement.source === REFERENCE_SOURCE))
|
|
246
|
+
return { type: "ref" };
|
|
247
|
+
return { type: "kw" };
|
|
248
|
+
case "array":
|
|
249
|
+
return plain.item ? typeOf(plain.item) : void 0;
|
|
250
|
+
default:
|
|
251
|
+
return void 0;
|
|
252
|
+
}
|
|
253
|
+
}, "typeOf");
|
|
254
|
+
var exampleOf = /* @__PURE__ */ __name((name, type, values) => ({
|
|
255
|
+
kw: `${name}:abc`,
|
|
256
|
+
txt: `${name}:word*`,
|
|
257
|
+
enum: `${name}:${values?.[0] ?? "x"}`,
|
|
258
|
+
num: `${name}>0`,
|
|
259
|
+
time: `${name}>=7d`,
|
|
260
|
+
bool: `${name}:true`,
|
|
261
|
+
ref: `${name}:"note:42"`
|
|
262
|
+
})[type], "exampleOf");
|
|
263
|
+
var queryFieldsOf = /* @__PURE__ */ __name((schema, annotations = {}) => {
|
|
264
|
+
const entries = unwrap(schema).entries ?? {};
|
|
265
|
+
const excluded = new Set(annotations.exclude ?? []);
|
|
266
|
+
const words = new Set(annotations.text ?? []);
|
|
267
|
+
const native = new Set(annotations.native ?? []);
|
|
268
|
+
const finish = /* @__PURE__ */ __name((field) => ({
|
|
269
|
+
...field,
|
|
270
|
+
operators: OPERATORS_BY_TYPE[field.type],
|
|
271
|
+
example: annotations.examples?.[field.name] ?? field.example ?? exampleOf(field.name, field.type, field.values),
|
|
272
|
+
...native.has(field.name) ? { native: true } : {},
|
|
273
|
+
...annotations.validate?.[field.name] ? { validate: annotations.validate[field.name] } : {}
|
|
274
|
+
}), "finish");
|
|
275
|
+
const own = Object.entries(entries).flatMap(([name, entry]) => {
|
|
276
|
+
if (excluded.has(name))
|
|
277
|
+
return [];
|
|
278
|
+
const found = typeOf(entry);
|
|
279
|
+
if (!found)
|
|
280
|
+
return [];
|
|
281
|
+
return [finish({ name, ...found, ...words.has(name) && found.type === "kw" ? { type: "txt" } : {} })];
|
|
282
|
+
});
|
|
283
|
+
const relations = Object.entries(annotations.relations ?? {}).map(([name, relation]) => finish({ name, ...relation }));
|
|
284
|
+
const states = annotations.states ? [
|
|
285
|
+
finish({
|
|
286
|
+
name: "is",
|
|
287
|
+
type: "enum",
|
|
288
|
+
values: Object.keys(annotations.states),
|
|
289
|
+
relation: Object.entries(annotations.states).map(([state, meaning]) => `${state}: ${meaning}`).join("; ")
|
|
290
|
+
})
|
|
291
|
+
] : [];
|
|
292
|
+
return [...own, ...relations, ...states];
|
|
293
|
+
}, "queryFieldsOf");
|
|
294
|
+
|
|
295
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/query/help.js
|
|
296
|
+
var QUERY_SYNTAX = 'field:value \xB7 "a phrase" \xB7 word* \xB7 AND OR NOT \xB7 ( ) \xB7 [a TO b] \xB7 > >= < <=';
|
|
297
|
+
var kindOf = /* @__PURE__ */ __name((field) => field.values ? `${field.type}: ${field.values.join("|")}` : `${field.type}: ${field.operators.join(", ")}`, "kindOf");
|
|
298
|
+
var fieldsHelp = /* @__PURE__ */ __name((registry, guide) => {
|
|
299
|
+
const shown = registry.backend === "native" ? registry.fields.filter((field) => field.native) : registry.fields;
|
|
300
|
+
const rows = shown.map((field) => [field.name, kindOf(field), field.example]);
|
|
301
|
+
const widths = [0, 1].map((at) => Math.max(...rows.map((row) => (row[at] ?? "").length)));
|
|
302
|
+
return [
|
|
303
|
+
"Fields:",
|
|
304
|
+
...rows.map(([name = "", kind = "", example = ""]) => ` ${name.padEnd(widths[0] ?? 0)} ${kind.padEnd(widths[1] ?? 0)} ${example}`.trimEnd()),
|
|
305
|
+
...registry.defaults && registry.defaults.length > 0 ? [`Defaults: ${registry.defaults.join(" ")} \u2014 name the field to change it`] : [],
|
|
306
|
+
`Syntax: ${QUERY_SYNTAX}`,
|
|
307
|
+
...guide ? [`Guide: ${guide}`] : []
|
|
308
|
+
].join("\n");
|
|
309
|
+
}, "fieldsHelp");
|
|
310
|
+
|
|
311
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/query/parser.js
|
|
312
|
+
var whitespace = /* @__PURE__ */ __name((c) => /[ \t\n\r\u3000]/u.test(c), "whitespace");
|
|
313
|
+
var reserved = /* @__PURE__ */ new Set([
|
|
314
|
+
"+",
|
|
315
|
+
"-",
|
|
316
|
+
"!",
|
|
317
|
+
"(",
|
|
318
|
+
")",
|
|
319
|
+
":",
|
|
320
|
+
"=",
|
|
321
|
+
"^",
|
|
322
|
+
"@",
|
|
323
|
+
"<",
|
|
324
|
+
">",
|
|
325
|
+
"[",
|
|
326
|
+
"]",
|
|
327
|
+
'"',
|
|
328
|
+
"{",
|
|
329
|
+
"}",
|
|
330
|
+
"~",
|
|
331
|
+
"\\",
|
|
332
|
+
"/"
|
|
333
|
+
]);
|
|
334
|
+
var decodeEscapes = /* @__PURE__ */ __name((raw, span, fail) => {
|
|
335
|
+
let out = "";
|
|
336
|
+
for (let at = 0; at < raw.length; at++) {
|
|
337
|
+
if (raw[at] !== "\\") {
|
|
338
|
+
out += raw[at];
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (++at >= raw.length)
|
|
342
|
+
fail("query.invalid-escape", span);
|
|
343
|
+
if (raw[at] === "u") {
|
|
344
|
+
const hex = raw.slice(at + 1, at + 5);
|
|
345
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex))
|
|
346
|
+
fail("query.invalid-escape", span);
|
|
347
|
+
out += String.fromCharCode(Number.parseInt(hex, 16));
|
|
348
|
+
at += 4;
|
|
349
|
+
} else
|
|
350
|
+
out += raw[at];
|
|
351
|
+
}
|
|
352
|
+
return out;
|
|
353
|
+
}, "decodeEscapes");
|
|
354
|
+
var tokensOf = /* @__PURE__ */ __name((text, fail = queryError) => {
|
|
355
|
+
const tokens = [];
|
|
356
|
+
let at = 0;
|
|
357
|
+
let range = false;
|
|
358
|
+
while (at < text.length) {
|
|
359
|
+
const start = at;
|
|
360
|
+
const c = text[at] ?? "";
|
|
361
|
+
if (whitespace(c)) {
|
|
362
|
+
at++;
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
let kind = c;
|
|
366
|
+
if (c === '"' || !range && c === "/") {
|
|
367
|
+
at++;
|
|
368
|
+
while (at < text.length && text[at] !== c) {
|
|
369
|
+
if (text[at] === "\\" && (c === '"' || text[at + 1] === "/"))
|
|
370
|
+
at++;
|
|
371
|
+
at++;
|
|
372
|
+
}
|
|
373
|
+
if (at >= text.length)
|
|
374
|
+
fail("query.unclosed-literal", { start, end: at }, c === "/" ? regexHint(text, start) : void 0);
|
|
375
|
+
at++;
|
|
376
|
+
if (c === "/" && /^[dgimsuvy]+(?:$|[ \t\n\r)])/.test(text.slice(at)))
|
|
377
|
+
fail("query.unsupported-regex-flags", { start: at, end: at + 1 }, "Lucene regex does not take JavaScript flags");
|
|
378
|
+
kind = c === '"' ? "quoted" : "regex";
|
|
379
|
+
} else if (range && c !== "]" && c !== "}") {
|
|
380
|
+
while (at < text.length && !whitespace(text[at] ?? "") && !["]", "}"].includes(text[at] ?? ""))
|
|
381
|
+
at++;
|
|
382
|
+
kind = "rangeValue";
|
|
383
|
+
} else if (reserved.has(c)) {
|
|
384
|
+
if (c === "\\") {
|
|
385
|
+
at += 2;
|
|
386
|
+
while (at < text.length && !whitespace(text[at] ?? "") && (!reserved.has(text[at] ?? "") || ["+", "-"].includes(text[at] ?? "")))
|
|
387
|
+
at++;
|
|
388
|
+
kind = "term";
|
|
389
|
+
} else {
|
|
390
|
+
at++;
|
|
391
|
+
if ((c === "<" || c === ">") && text[at] === "=") {
|
|
392
|
+
at++;
|
|
393
|
+
kind += "=";
|
|
394
|
+
}
|
|
395
|
+
if (c === "[" || c === "{")
|
|
396
|
+
range = true;
|
|
397
|
+
if (c === "]" || c === "}")
|
|
398
|
+
range = false;
|
|
399
|
+
}
|
|
400
|
+
} else {
|
|
401
|
+
at++;
|
|
402
|
+
while (at < text.length) {
|
|
403
|
+
const next = text[at] ?? "";
|
|
404
|
+
if (next === "\\") {
|
|
405
|
+
if (at + 1 >= text.length)
|
|
406
|
+
fail("query.invalid-escape", { start: at, end: at + 1 });
|
|
407
|
+
at += 2;
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (next === "@" && new RegExp("^@(?:\\p{L}|[\\p{L}\\p{N}][^\\s@]*\\.[\\p{L}\\p{N}])", "u").test(text.slice(at))) {
|
|
411
|
+
at++;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (whitespace(next) || reserved.has(next) && next !== "+" && next !== "-")
|
|
415
|
+
break;
|
|
416
|
+
at++;
|
|
417
|
+
}
|
|
418
|
+
const raw = text.slice(start, at);
|
|
419
|
+
kind = { AND: "AND", OR: "OR", NOT: "NOT", "&&": "AND", "||": "OR" }[raw] ?? (/^\d+(?:\.\d+)?$/u.test(raw) ? "number" : "term");
|
|
420
|
+
}
|
|
421
|
+
tokens.push({ kind, raw: text.slice(start, at), span: { start, end: at } });
|
|
422
|
+
}
|
|
423
|
+
tokens.push({ kind: "EOF", raw: "", span: { start: at, end: at } });
|
|
424
|
+
return tokens;
|
|
425
|
+
}, "tokensOf");
|
|
426
|
+
var quoteHint = /* @__PURE__ */ __name((text, at) => {
|
|
427
|
+
for (const match of text.matchAll(/(?<=^|[\s(])([\p{L}\p{N}_.-]+):([^\s"()]+)/gu)) {
|
|
428
|
+
const [whole, field, value = ""] = match;
|
|
429
|
+
if (at < match.index || at > match.index + whole.length)
|
|
430
|
+
continue;
|
|
431
|
+
return /[:=/?*~^@<>![\]{}\\]/u.test(value) ? `put the value in quotes: ${field}:"${value}"` : void 0;
|
|
432
|
+
}
|
|
433
|
+
return void 0;
|
|
434
|
+
}, "quoteHint");
|
|
435
|
+
var regexHint = /* @__PURE__ */ __name((text, at) => {
|
|
436
|
+
const word = `${/[^\s()"]*$/u.exec(text.slice(0, at))?.[0] ?? ""}${/^[^\s()"]*/u.exec(text.slice(at))?.[0] ?? ""}`;
|
|
437
|
+
return quoteHint(text, at) ?? `/ starts a regular expression; put the value in quotes: "${word}"`;
|
|
438
|
+
}, "regexHint");
|
|
439
|
+
var parseLucene = /* @__PURE__ */ __name((text, { defaultField = "text", proximity = false, ...context } = {}) => {
|
|
440
|
+
const fail = /* @__PURE__ */ __name((reason, span, alternative) => queryError(reason, span, alternative ?? quoteHint(text, span.start), context), "fail");
|
|
441
|
+
if (text.length > QUERY_LIMITS.bytes || new TextEncoder().encode(text).length > QUERY_LIMITS.bytes)
|
|
442
|
+
fail("query.too-large", { start: 0, end: text.length });
|
|
443
|
+
const tokens = tokensOf(text, fail);
|
|
444
|
+
let at = 0;
|
|
445
|
+
let count = 0;
|
|
446
|
+
let depth = 0;
|
|
447
|
+
const peek = /* @__PURE__ */ __name(() => tokens[at], "peek");
|
|
448
|
+
const take = /* @__PURE__ */ __name(() => tokens[at++], "take");
|
|
449
|
+
const expect = /* @__PURE__ */ __name((kind) => {
|
|
450
|
+
if (peek().kind !== kind)
|
|
451
|
+
fail("query.invalid-syntax", peek().span);
|
|
452
|
+
return take();
|
|
453
|
+
}, "expect");
|
|
454
|
+
const built = /* @__PURE__ */ __name((node) => {
|
|
455
|
+
if (++count > QUERY_LIMITS.nodes)
|
|
456
|
+
fail("query.too-large", node.span);
|
|
457
|
+
return node;
|
|
458
|
+
}, "built");
|
|
459
|
+
const combine = /* @__PURE__ */ __name((clauses, occur) => {
|
|
460
|
+
const first = clauses[0];
|
|
461
|
+
const last = clauses.at(-1);
|
|
462
|
+
if (!first || !last)
|
|
463
|
+
fail("query.invalid-syntax", peek().span);
|
|
464
|
+
if (clauses.length === 1)
|
|
465
|
+
return first;
|
|
466
|
+
return {
|
|
467
|
+
node: built({
|
|
468
|
+
kind: "boolean",
|
|
469
|
+
clauses: clauses.map(({ node, modifier }) => ({ node, occur: modifier ?? occur })),
|
|
470
|
+
span: { start: first.node.span.start, end: last.node.span.end }
|
|
471
|
+
})
|
|
472
|
+
};
|
|
473
|
+
}, "combine");
|
|
474
|
+
const query = /* @__PURE__ */ __name((field, implicit = false) => {
|
|
475
|
+
if (++depth > QUERY_LIMITS.depth)
|
|
476
|
+
fail("query.too-large", peek().span);
|
|
477
|
+
const clauses = [];
|
|
478
|
+
do {
|
|
479
|
+
clauses.push(disjunction(field, implicit));
|
|
480
|
+
} while (!["EOF", ")"].includes(peek().kind));
|
|
481
|
+
const result = combine(clauses, "must");
|
|
482
|
+
depth--;
|
|
483
|
+
if (result.modifier === "must_not")
|
|
484
|
+
return built({ kind: "boolean", clauses: [{ node: result.node, occur: "must_not" }], span: result.node.span });
|
|
485
|
+
return result.node;
|
|
486
|
+
}, "query");
|
|
487
|
+
const disjunction = /* @__PURE__ */ __name((field, implicit) => {
|
|
488
|
+
const clauses = [conjunction(field, implicit)];
|
|
489
|
+
while (peek().kind === "OR") {
|
|
490
|
+
take();
|
|
491
|
+
clauses.push(conjunction(field, implicit));
|
|
492
|
+
}
|
|
493
|
+
return combine(clauses, "should");
|
|
494
|
+
}, "disjunction");
|
|
495
|
+
const conjunction = /* @__PURE__ */ __name((field, implicit) => {
|
|
496
|
+
const clauses = [clause(field, implicit)];
|
|
497
|
+
while (peek().kind === "AND") {
|
|
498
|
+
take();
|
|
499
|
+
clauses.push(clause(field, implicit));
|
|
500
|
+
}
|
|
501
|
+
return combine(clauses, "must");
|
|
502
|
+
}, "conjunction");
|
|
503
|
+
const clause = /* @__PURE__ */ __name((inherited, inheritedImplicit) => {
|
|
504
|
+
let modifier;
|
|
505
|
+
if (["+", "-", "NOT", "!"].includes(peek().kind))
|
|
506
|
+
modifier = take().kind === "+" ? "must" : "must_not";
|
|
507
|
+
let field = inherited;
|
|
508
|
+
let start;
|
|
509
|
+
let implicit = inheritedImplicit;
|
|
510
|
+
if (peek().kind === "term" && [":", "=", "<", ">", "<=", ">="].includes(tokens[at + 1]?.kind ?? "")) {
|
|
511
|
+
const token = take();
|
|
512
|
+
field = decodeEscapes(token.raw, token.span, fail);
|
|
513
|
+
start = token.span.start;
|
|
514
|
+
implicit = false;
|
|
515
|
+
let operator = take();
|
|
516
|
+
if (operator.kind === ":" && ["<", ">", "<=", ">="].includes(peek().kind))
|
|
517
|
+
operator = take();
|
|
518
|
+
if (["<", ">", "<=", ">="].includes(operator.kind)) {
|
|
519
|
+
const value = take();
|
|
520
|
+
if (!["term", "number", "quoted"].includes(value.kind))
|
|
521
|
+
fail("query.invalid-syntax", value.span);
|
|
522
|
+
const decoded = decodeEscapes(value.kind === "quoted" ? value.raw.slice(1, -1) : value.raw, value.span, fail);
|
|
523
|
+
const lower = operator.kind.startsWith(">");
|
|
524
|
+
const node2 = built({
|
|
525
|
+
kind: "predicate",
|
|
526
|
+
field,
|
|
527
|
+
operator: "range",
|
|
528
|
+
value: lower ? decoded : "*",
|
|
529
|
+
upper: lower ? "*" : decoded,
|
|
530
|
+
lower_inclusive: !lower || operator.kind.endsWith("="),
|
|
531
|
+
upper_inclusive: lower || operator.kind.endsWith("="),
|
|
532
|
+
span: { start: token.span.start, end: value.span.end }
|
|
533
|
+
});
|
|
534
|
+
return { node: node2, ...modifier ? { modifier } : {} };
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
let node;
|
|
538
|
+
if (peek().kind === "(") {
|
|
539
|
+
const start2 = take().span.start;
|
|
540
|
+
node = query(field, implicit);
|
|
541
|
+
const end = expect(")").span.end;
|
|
542
|
+
node = { ...node, span: { start: start2, end } };
|
|
543
|
+
} else if (["[", "{"].includes(peek().kind)) {
|
|
544
|
+
const opening = take();
|
|
545
|
+
const lower = take();
|
|
546
|
+
if (!["rangeValue", "quoted"].includes(lower.kind))
|
|
547
|
+
fail("query.invalid-syntax", lower.span);
|
|
548
|
+
const separator = take();
|
|
549
|
+
if (separator.raw !== "TO")
|
|
550
|
+
fail("query.invalid-syntax", separator.span);
|
|
551
|
+
const upper = take();
|
|
552
|
+
if (!["rangeValue", "quoted"].includes(upper.kind))
|
|
553
|
+
fail("query.invalid-syntax", upper.span);
|
|
554
|
+
const closing = take();
|
|
555
|
+
if (!["]", "}"].includes(closing.kind))
|
|
556
|
+
fail("query.invalid-syntax", closing.span);
|
|
557
|
+
const decode = /* @__PURE__ */ __name((t) => decodeEscapes(t.kind === "quoted" ? t.raw.slice(1, -1) : t.raw, t.span, fail), "decode");
|
|
558
|
+
node = built({
|
|
559
|
+
kind: "predicate",
|
|
560
|
+
field,
|
|
561
|
+
operator: "range",
|
|
562
|
+
value: decode(lower),
|
|
563
|
+
upper: decode(upper),
|
|
564
|
+
lower_inclusive: opening.kind === "[",
|
|
565
|
+
upper_inclusive: closing.kind === "]",
|
|
566
|
+
span: { start: start ?? opening.span.start, end: closing.span.end }
|
|
567
|
+
});
|
|
568
|
+
} else {
|
|
569
|
+
const token = take();
|
|
570
|
+
if (!["term", "number", "quoted", "regex"].includes(token.kind))
|
|
571
|
+
fail("query.invalid-syntax", token.span);
|
|
572
|
+
const raw = ["term", "number"].includes(token.kind) ? token.raw : token.raw.slice(1, -1);
|
|
573
|
+
if (field === "fn")
|
|
574
|
+
fail("query.unsupported-operator", token.span, "interval functions are not supported");
|
|
575
|
+
const wildcard = ["term", "number"].includes(token.kind) && /(?<!\\)[*?]/u.test(raw);
|
|
576
|
+
node = built({
|
|
577
|
+
kind: "predicate",
|
|
578
|
+
field,
|
|
579
|
+
operator: token.kind === "regex" ? "regex" : token.kind === "quoted" ? "phrase" : wildcard ? "wildcard" : "term",
|
|
580
|
+
value: token.kind === "regex" || wildcard ? raw : decodeEscapes(raw, token.span, fail),
|
|
581
|
+
span: { start: start ?? token.span.start, end: token.span.end },
|
|
582
|
+
...implicit ? { implicit: true } : {}
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
if (proximity && peek().kind === "~" && node.kind === "predicate" && node.operator === "phrase") {
|
|
586
|
+
take();
|
|
587
|
+
const distance = take();
|
|
588
|
+
if (distance.kind !== "number" || !/^\d+$/u.test(distance.raw))
|
|
589
|
+
fail("query.invalid-syntax", distance.span, 'write the distance as a whole number: "a b"~3');
|
|
590
|
+
node = { ...node, slop: Number(distance.raw), span: { start: node.span.start, end: distance.span.end } };
|
|
591
|
+
}
|
|
592
|
+
if (peek().kind === "~")
|
|
593
|
+
fail("query.unsupported-operator", peek().span, node.kind === "predicate" && node.operator === "phrase" ? "proximity (~) is not supported \u2014 drop the ~ for the exact phrase, or join the words with AND" : "fuzzy matching (~) is not supported \u2014 use a prefix such as word* to catch word forms");
|
|
594
|
+
if (["^", "@"].includes(peek().kind))
|
|
595
|
+
fail("query.unsupported-operator", peek().span, "boost and minimum-should-match are not supported");
|
|
596
|
+
return { node, ...modifier ? { modifier } : {} };
|
|
597
|
+
}, "clause");
|
|
598
|
+
const root = query(defaultField, true);
|
|
599
|
+
expect("EOF");
|
|
600
|
+
if (defaultField === "none") {
|
|
601
|
+
const bare = walkQuery(root).find((node) => node.implicit);
|
|
602
|
+
if (bare)
|
|
603
|
+
queryError("query.bare-word", bare.span, `"${bare.value}" has no field; write field:value`, context, {
|
|
604
|
+
word: bare.value
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
return { version: 1, language: "lucene-v1", root };
|
|
608
|
+
}, "parseLucene");
|
|
609
|
+
var implicitTextTerms = /* @__PURE__ */ __name((text) => {
|
|
610
|
+
const tokens = tokensOf(text);
|
|
611
|
+
if (tokens.some(({ kind }) => ["AND", "OR", "NOT", "+", "-", "!", "(", ")"].includes(kind)))
|
|
612
|
+
return /* @__PURE__ */ new Set();
|
|
613
|
+
return new Set(tokens.flatMap((token, index) => token.kind === "term" && ![":", "=", "<", ">", "<=", ">="].includes(tokens[index - 1]?.kind ?? "") && ![":", "=", "<", ">", "<=", ">="].includes(tokens[index + 1]?.kind ?? "") ? [token.span.start] : []));
|
|
614
|
+
}, "implicitTextTerms");
|
|
615
|
+
|
|
616
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/query/validate.js
|
|
617
|
+
var inContext = /* @__PURE__ */ __name((context, run) => {
|
|
618
|
+
try {
|
|
619
|
+
run();
|
|
620
|
+
} catch (failure) {
|
|
621
|
+
if (!isCliError(failure) || typeof failure.details.reason !== "string" || failure.details.span === void 0)
|
|
622
|
+
throw failure;
|
|
623
|
+
const { reason, span, alternative } = failure.details;
|
|
624
|
+
queryError(reason, span, alternative, context);
|
|
625
|
+
}
|
|
626
|
+
}, "inContext");
|
|
627
|
+
var bounds = /* @__PURE__ */ __name((node) => node.operator === "range" ? [node.value, node.upper ?? "*"].filter((bound) => bound !== "*") : [node.value], "bounds");
|
|
628
|
+
var checkValue = /* @__PURE__ */ __name((field, node, options) => {
|
|
629
|
+
const fail = /* @__PURE__ */ __name((reason, alternative) => queryError(reason, node.span, alternative, options), "fail");
|
|
630
|
+
if (node.value === "" && field.type !== "txt")
|
|
631
|
+
fail("query.missing-value");
|
|
632
|
+
if (node.operator === "wildcard")
|
|
633
|
+
return;
|
|
634
|
+
switch (field.type) {
|
|
635
|
+
case "enum":
|
|
636
|
+
if (!field.values?.includes(node.value.toLowerCase()))
|
|
637
|
+
fail("query.unknown-value", `${field.name} takes ${field.values?.join(", ")}`);
|
|
638
|
+
return;
|
|
639
|
+
case "bool":
|
|
640
|
+
if (!["true", "false"].includes(node.value.toLowerCase()))
|
|
641
|
+
fail("query.unknown-value", `${field.name} takes true, false`);
|
|
642
|
+
return;
|
|
643
|
+
case "num":
|
|
644
|
+
for (const bound of bounds(node))
|
|
645
|
+
if (!Number.isFinite(Number(bound)) || bound.trim() === "")
|
|
646
|
+
fail("query.invalid-number", `${field.name} takes a number`);
|
|
647
|
+
return;
|
|
648
|
+
case "time":
|
|
649
|
+
inContext(options, () => {
|
|
650
|
+
for (const bound of bounds(node))
|
|
651
|
+
dateEndpoint(bound, options.zone ?? "UTC", "lower", true, node.span);
|
|
652
|
+
});
|
|
653
|
+
return;
|
|
654
|
+
default:
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
}, "checkValue");
|
|
658
|
+
var validateQuery = /* @__PURE__ */ __name((ast, registry, options = {}) => {
|
|
659
|
+
const byName = new Map(registry.fields.map((field) => [field.name, field]));
|
|
660
|
+
const visit = /* @__PURE__ */ __name((node, required) => {
|
|
661
|
+
if (node.kind === "boolean") {
|
|
662
|
+
for (const clause of node.clauses)
|
|
663
|
+
visit(clause.node, required && clause.occur === "must");
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
const field = byName.get(node.field);
|
|
667
|
+
if (!field)
|
|
668
|
+
queryError("query.unknown-field", node.span, `no field "${node.field}"`, options, {
|
|
669
|
+
fields: registry.fields.map((one) => one.name)
|
|
670
|
+
});
|
|
671
|
+
if (registry.backend === "native" && !field.native)
|
|
672
|
+
queryError("query.unsupported-field", node.span, `the source cannot filter by ${field.name}`, options, {
|
|
673
|
+
supported: registry.fields.filter((one) => one.native).map((one) => one.name)
|
|
674
|
+
});
|
|
675
|
+
const presence = node.operator === "wildcard" && node.value === "*";
|
|
676
|
+
if (!presence && !field.operators.includes(node.operator))
|
|
677
|
+
queryError("query.unsupported-operator", node.span, `${field.name} takes ${field.operators.join(", ")}`, options);
|
|
678
|
+
if (field.placement === "and" && !required)
|
|
679
|
+
queryError("query.unsupported-placement", node.span, `${field.name} only as a required term, not under OR or NOT`, options);
|
|
680
|
+
if (presence)
|
|
681
|
+
return;
|
|
682
|
+
checkValue(field, node, options);
|
|
683
|
+
if (field.validate)
|
|
684
|
+
inContext(options, () => field.validate?.(node));
|
|
685
|
+
}, "visit");
|
|
686
|
+
visit(ast.root, true);
|
|
687
|
+
return ast;
|
|
688
|
+
}, "validateQuery");
|
|
689
|
+
var fieldsNamed = /* @__PURE__ */ __name((ast) => new Set(walkQuery(ast.root).map((node) => node.field)), "fieldsNamed");
|
|
690
|
+
|
|
691
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/query/registry.js
|
|
692
|
+
var describeQuery = /* @__PURE__ */ __name((registry) => ({
|
|
693
|
+
entity: registry.entity,
|
|
694
|
+
backend: registry.backend,
|
|
695
|
+
fields: registry.fields.map(({ validate: _, ...field }) => field),
|
|
696
|
+
...registry.defaults && registry.defaults.length > 0 ? { defaults: [...registry.defaults] } : {}
|
|
697
|
+
}), "describeQuery");
|
|
698
|
+
var exampleProblems = /* @__PURE__ */ __name((registry) => {
|
|
699
|
+
const syntaxOnly = { ...registry, backend: "sql" };
|
|
700
|
+
const problem = /* @__PURE__ */ __name((text, field) => {
|
|
701
|
+
try {
|
|
702
|
+
const named = walkQuery(validateQuery(parseLucene(text, { defaultField: "none" }), syntaxOnly).root);
|
|
703
|
+
return named.every((node) => node.field === field) ? void 0 : `"${text}" does not name ${field}`;
|
|
704
|
+
} catch (failure) {
|
|
705
|
+
if (!isCliError(failure))
|
|
706
|
+
throw failure;
|
|
707
|
+
return `"${text}": ${failure.message}`;
|
|
708
|
+
}
|
|
709
|
+
}, "problem");
|
|
710
|
+
const defaults = (registry.defaults ?? []).map((term) => {
|
|
711
|
+
const field = term.replace(/^-/, "").split(/[:<>=]/)[0] ?? "";
|
|
712
|
+
return { field, problem: problem(term.replace(/^-/, ""), field) };
|
|
713
|
+
});
|
|
714
|
+
return [
|
|
715
|
+
...registry.fields.map((field) => ({ field: field.name, problem: problem(field.example, field.name) })),
|
|
716
|
+
...defaults
|
|
717
|
+
].filter((entry) => entry.problem !== void 0);
|
|
718
|
+
}, "exampleProblems");
|
|
719
|
+
var defineQuery = /* @__PURE__ */ __name((registry) => {
|
|
720
|
+
const names = registry.fields.map((field) => field.name);
|
|
721
|
+
const problems = [
|
|
722
|
+
...duplicates(names).map((name) => `"${name}" is listed twice`),
|
|
723
|
+
...names.filter((name) => !SNAKE_CASE.test(name)).map((name) => `"${name}" is not snake_case`),
|
|
724
|
+
...exampleProblems(registry).map(({ field, problem }) => `${field}: ${problem}`)
|
|
725
|
+
];
|
|
726
|
+
if (problems.length > 0)
|
|
727
|
+
throw new RegistryError(`${registry.entity} query`, problems);
|
|
728
|
+
return registry;
|
|
729
|
+
}, "defineQuery");
|
|
730
|
+
var SPAN = ["span", "alternative", "guide"];
|
|
731
|
+
var QUERY_REASONS = defineReasons([
|
|
732
|
+
["query.bare-word", "a word in the query has no field", ["word"]],
|
|
733
|
+
["query.invalid-ast", "the query tree is not valid", []],
|
|
734
|
+
["query.invalid-date", "a date in the query cannot be read", []],
|
|
735
|
+
["query.invalid-escape", "an escape in the query is not valid", []],
|
|
736
|
+
["query.invalid-number", "a number in the query cannot be read", []],
|
|
737
|
+
["query.invalid-regex", "a regular expression in the query is not valid", []],
|
|
738
|
+
["query.invalid-syntax", "the query cannot be parsed", []],
|
|
739
|
+
["query.invalid-timezone", "the time zone is not known", []],
|
|
740
|
+
["query.missing-value", "a field in the query has no value", []],
|
|
741
|
+
["query.too-large", "the query is over one of its limits", []],
|
|
742
|
+
["query.unclosed-literal", "a quote or bracket in the query is not closed", []],
|
|
743
|
+
["query.unknown-field", "a field in the query is not known", ["fields"]],
|
|
744
|
+
["query.unknown-value", "a value in the query is not known", []],
|
|
745
|
+
["query.unsupported-field", "this list cannot filter by that field", ["supported"]],
|
|
746
|
+
["query.unsupported-operator", "this field does not take that operator", []],
|
|
747
|
+
["query.unsupported-placement", "this field works only as a required term", []],
|
|
748
|
+
["query.unsupported-regex", "that regular expression is not supported", []],
|
|
749
|
+
["query.unsupported-regex-flags", "regular expression flags are not supported", []],
|
|
750
|
+
["query.unsupported-version", "the query version is not supported", []]
|
|
751
|
+
].map(([reason, message, details]) => ({
|
|
752
|
+
reason,
|
|
753
|
+
code: "validation_error",
|
|
754
|
+
message,
|
|
755
|
+
details: [...SPAN, ...details]
|
|
756
|
+
})));
|
|
757
|
+
|
|
758
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.65.0_commander@15.0.0_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/query/evaluate.js
|
|
759
|
+
var wordsOf = /* @__PURE__ */ __name((text) => text.toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [], "wordsOf");
|
|
760
|
+
var pattern = /* @__PURE__ */ __name((value) => new RegExp(`^${[...value].map((char) => char === "*" ? ".*" : char === "?" ? "." : char.replace(/[.+^${}()|[\]\\]/, "\\$&")).join("")}$`, "iu"), "pattern");
|
|
761
|
+
var present = /* @__PURE__ */ __name((value) => value !== void 0 && value !== null && value !== "", "present");
|
|
762
|
+
var matchOne = /* @__PURE__ */ __name((field, node, value, options) => {
|
|
763
|
+
if (!present(value))
|
|
764
|
+
return false;
|
|
765
|
+
if (node.operator === "wildcard" && node.value === "*")
|
|
766
|
+
return true;
|
|
767
|
+
const text = String(value);
|
|
768
|
+
switch (field.type) {
|
|
769
|
+
case "txt": {
|
|
770
|
+
const words = wordsOf(text);
|
|
771
|
+
if (node.operator === "wildcard")
|
|
772
|
+
return words.some((word) => pattern(node.value).test(word));
|
|
773
|
+
const wanted = wordsOf(node.value);
|
|
774
|
+
return words.some((_, at) => wanted.every((word, offset) => words[at + offset] === word));
|
|
775
|
+
}
|
|
776
|
+
case "num": {
|
|
777
|
+
const number2 = Number(value);
|
|
778
|
+
if (node.operator !== "range")
|
|
779
|
+
return number2 === Number(node.value);
|
|
780
|
+
const { value: lower, upper = "*", lower_inclusive: lowerInclusive, upper_inclusive: upperInclusive } = node;
|
|
781
|
+
return (lower === "*" || (lowerInclusive ? number2 >= Number(lower) : number2 > Number(lower))) && (upper === "*" || (upperInclusive ? number2 <= Number(upper) : number2 < Number(upper)));
|
|
782
|
+
}
|
|
783
|
+
case "time": {
|
|
784
|
+
const time = Date.parse(text);
|
|
785
|
+
const [lower, upper, lowerInclusive, upperInclusive] = node.operator === "range" ? [node.value, node.upper ?? "*", node.lower_inclusive ?? true, node.upper_inclusive ?? true] : [node.value, node.value, true, true];
|
|
786
|
+
const range = dateRange(lower, upper, lowerInclusive, upperInclusive, options.zone ?? "UTC", node.span, options.now);
|
|
787
|
+
return (range.lower === void 0 || (range.lower_inclusive ? time >= range.lower : time > range.lower)) && (range.upper === void 0 || (range.upper_inclusive ? time <= range.upper : time < range.upper));
|
|
788
|
+
}
|
|
789
|
+
default:
|
|
790
|
+
return node.operator === "wildcard" ? pattern(node.value).test(text) : text.toLowerCase() === node.value.toLowerCase();
|
|
791
|
+
}
|
|
792
|
+
}, "matchOne");
|
|
793
|
+
var matches = /* @__PURE__ */ __name((node, item, byName, options) => {
|
|
794
|
+
if (node.kind === "boolean") {
|
|
795
|
+
const by = /* @__PURE__ */ __name((occur) => node.clauses.filter((clause) => clause.occur === occur), "by");
|
|
796
|
+
const [must, should, mustNot] = [by("must"), by("should"), by("must_not")];
|
|
797
|
+
const holds = /* @__PURE__ */ __name((clause) => matches(clause.node, item, byName, options), "holds");
|
|
798
|
+
return must.every(holds) && !mustNot.some(holds) && (should.length === 0 || must.length > 0 || should.some(holds));
|
|
799
|
+
}
|
|
800
|
+
const field = byName.get(node.field);
|
|
801
|
+
if (!field)
|
|
802
|
+
throw new Error(`evaluate: no field "${node.field}"; validate the query first`);
|
|
803
|
+
if (field.relation !== void 0) {
|
|
804
|
+
if (!options.relation)
|
|
805
|
+
throw new Error(`evaluate: "${node.field}" is a relation; pass options.relation`);
|
|
806
|
+
return options.relation(node, item);
|
|
807
|
+
}
|
|
808
|
+
const value = item[node.field];
|
|
809
|
+
return Array.isArray(value) ? value.some((one) => matchOne(field, node, one, options)) : matchOne(field, node, value, options);
|
|
810
|
+
}, "matches");
|
|
811
|
+
var evaluate = /* @__PURE__ */ __name((ast, fields, item, options = {}) => matches(ast.root, item, new Map(fields.map((field) => [field.name, field])), options), "evaluate");
|
|
812
|
+
|
|
813
|
+
export {
|
|
814
|
+
QUERY_LIMITS,
|
|
815
|
+
queryAstSchema,
|
|
816
|
+
queryError,
|
|
817
|
+
walkQuery,
|
|
818
|
+
timezoneOf,
|
|
819
|
+
wallTime,
|
|
820
|
+
zonedMoment,
|
|
821
|
+
dateEndpoint,
|
|
822
|
+
dateRange,
|
|
823
|
+
evaluate,
|
|
824
|
+
FIELD_TYPES,
|
|
825
|
+
OPERATORS_BY_TYPE,
|
|
826
|
+
QUERY_BACKENDS,
|
|
827
|
+
queryFieldsOf,
|
|
828
|
+
fieldsHelp,
|
|
829
|
+
parseLucene,
|
|
830
|
+
implicitTextTerms,
|
|
831
|
+
validateQuery,
|
|
832
|
+
fieldsNamed,
|
|
833
|
+
describeQuery,
|
|
834
|
+
defineQuery,
|
|
835
|
+
QUERY_REASONS
|
|
836
|
+
};
|