@wirecat/attio-cli 0.7.0 → 0.9.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/CHANGELOG.md +22 -0
- package/README.md +2 -2
- package/dist/activities.d.ts.map +1 -1
- package/dist/activities.js +2 -1
- package/dist/activities.js.map +1 -1
- package/dist/bin/attio.js +2 -2
- package/dist/bundle/agent-C3SZOGZS.js +38 -0
- package/dist/bundle/{all-profiles-63N3EQ46.js → all-profiles-673VSTRG.js} +7 -7
- package/dist/bundle/{anthropic-B4W7MZQE.js → anthropic-V4RZS5XM.js} +3 -3
- package/dist/bundle/{app-server-EXNGTHWO.js → app-server-CTEDPA5H.js} +55 -56
- package/dist/bundle/attio.js +3 -3
- package/dist/bundle/{bun-OPDGMZZQ.js → bun-F4M4KCNA.js} +2 -2
- package/dist/bundle/{bun-sqlite-NBAY7FR2.js → bun-sqlite-33JTNHCK.js} +4 -4
- package/dist/bundle/{chunk-L72WUJAS.js → chunk-2R2EX5I6.js} +2 -2
- package/dist/bundle/{chunk-SCI7QEHF.js → chunk-5EH7S4RM.js} +7 -7
- package/dist/bundle/{chunk-V57E7PJQ.js → chunk-5WY6RURV.js} +4 -4
- package/dist/bundle/{chunk-X5UPBSTP.js → chunk-6E5QWCBK.js} +1 -1
- package/dist/bundle/{chunk-RQORQN2V.js → chunk-6V7ZUJI6.js} +51 -51
- package/dist/bundle/{chunk-UDSL3MUU.js → chunk-AOKAYQSJ.js} +14 -9
- package/dist/bundle/{chunk-VB7FZOYX.js → chunk-AQ5RIOUE.js} +1 -1
- package/dist/bundle/{chunk-J6GVVISK.js → chunk-B4DVW2BA.js} +7 -7
- package/dist/bundle/{chunk-VZ5PPYDG.js → chunk-C7JPYWYQ.js} +1 -1
- package/dist/bundle/{chunk-JIGEJZ4I.js → chunk-DBHZ7TQ7.js} +3696 -2811
- package/dist/bundle/{chunk-DPD4FMHN.js → chunk-E2L4R6EI.js} +3 -3
- package/dist/bundle/{chunk-YNGU36GW.js → chunk-EDWRHVHD.js} +11 -11
- package/dist/bundle/{chunk-4RSWOPKL.js → chunk-EV6B3GHM.js} +7 -7
- package/dist/bundle/{chunk-OYEVYOCL.js → chunk-FBWECICU.js} +5 -5
- package/dist/bundle/{chunk-JG6LCSEX.js → chunk-FFER7KJI.js} +12 -12
- package/dist/bundle/{chunk-3HC5F3P7.js → chunk-FTH6WGYO.js} +1 -1
- package/dist/bundle/{chunk-MCLQTCGH.js → chunk-G3PK5BZB.js} +34 -14
- package/dist/bundle/{chunk-NISH4UXM.js → chunk-G46PNDWL.js} +1 -1
- package/dist/bundle/{chunk-LKH3UKLO.js → chunk-G6NY7LFB.js} +3 -3
- package/dist/bundle/{chunk-V7IF2K3P.js → chunk-GLU36VKA.js} +2 -2
- package/dist/bundle/{chunk-Q7ICVP25.js → chunk-GZ7WBU5Y.js} +1 -1
- package/dist/bundle/{chunk-XQGN2D44.js → chunk-HMYBAVIE.js} +3 -3
- package/dist/bundle/{chunk-P7G5HFY3.js → chunk-HOJJPSLU.js} +2 -2
- package/dist/bundle/{chunk-WOPVBRPV.js → chunk-HUAHLO6N.js} +1 -1
- package/dist/bundle/{chunk-NB7EOAUZ.js → chunk-ISQ23VKV.js} +1 -1
- package/dist/bundle/{chunk-M4AC55ZB.js → chunk-J2LSOG3A.js} +205 -172
- package/dist/bundle/{chunk-5WD22IXQ.js → chunk-K5L77R7P.js} +2 -2
- package/dist/bundle/chunk-KKRFVN4X.js +1835 -0
- package/dist/bundle/{chunk-IA7LLLEI.js → chunk-KLRCTMES.js} +2 -2
- package/dist/bundle/{chunk-GGMAIIVE.js → chunk-KYRYD4CR.js} +1 -1
- package/dist/bundle/{chunk-2QDUP74I.js → chunk-L5QLKUQR.js} +33 -33
- package/dist/bundle/{chunk-GTEX4IUO.js → chunk-MFSWMNSZ.js} +4 -4
- package/dist/bundle/{chunk-3MSHGNVE.js → chunk-MYK2F5LD.js} +20 -12
- package/dist/bundle/{chunk-7Z53MLQP.js → chunk-NBNQLNVV.js} +2 -2
- package/dist/bundle/{chunk-LM3W7YOM.js → chunk-O3DZDITT.js} +3 -3
- package/dist/bundle/{chunk-2XBDILVW.js → chunk-OEEWVKJX.js} +1 -1
- package/dist/bundle/{chunk-L45WN3AR.js → chunk-P5XYQZVW.js} +2 -2
- package/dist/bundle/{chunk-TTF5DP4V.js → chunk-P6OJKJJS.js} +6 -6
- package/dist/bundle/{chunk-6TD3DCWC.js → chunk-P6S3ZRVW.js} +2 -2
- package/dist/bundle/{chunk-UKHF37ZU.js → chunk-QBJRK733.js} +20 -20
- package/dist/bundle/{chunk-QSJKSPWF.js → chunk-QBYE26ZC.js} +2 -2
- package/dist/bundle/{chunk-APARYILG.js → chunk-R2CEA7MK.js} +13 -13
- package/dist/bundle/{chunk-ZZD2YPOX.js → chunk-SKUY7JDA.js} +14 -6
- package/dist/bundle/{chunk-4RBMCXZT.js → chunk-T35IOBPJ.js} +28 -24
- package/dist/bundle/{chunk-3YM4B2GT.js → chunk-T3W4V4A6.js} +1 -1
- package/dist/bundle/{chunk-WXQGA6XK.js → chunk-TB3LN5G2.js} +2 -2
- package/dist/bundle/{chunk-4N7PP76S.js → chunk-TCT5D2X2.js} +1 -1
- package/dist/bundle/{chunk-YWDFYQOU.js → chunk-TES7MB6I.js} +1 -1
- package/dist/bundle/{chunk-DURNR4RO.js → chunk-U7UTYALA.js} +7 -7
- package/dist/bundle/{chunk-PAEKXVJW.js → chunk-UOWHMOU3.js} +6 -6
- package/dist/bundle/{chunk-5JKTVAXX.js → chunk-UXDUWGX6.js} +3 -0
- package/dist/bundle/{chunk-FH6OEGGN.js → chunk-V5I3QHDU.js} +14 -13
- package/dist/bundle/{chunk-KVTNYRDO.js → chunk-VCDIKCFE.js} +5 -5
- package/dist/bundle/{chunk-RDVTHFPP.js → chunk-VJHUMB7U.js} +4 -4
- package/dist/bundle/{chunk-PMQ7GP6X.js → chunk-W4KLHM2K.js} +5 -5
- package/dist/bundle/{chunk-HZ3C4WXD.js → chunk-W5LKEOGN.js} +1 -1
- package/dist/bundle/{chunk-PLPBEWD4.js → chunk-WLDZWHSF.js} +2 -2
- package/dist/bundle/{chunk-DM7KWVDZ.js → chunk-WQEEYEWO.js} +10 -10
- package/dist/bundle/{chunk-AATTOFNY.js → chunk-WRF6TY63.js} +96 -620
- package/dist/bundle/{chunk-EY36BTKZ.js → chunk-WXYOELRI.js} +2 -2
- package/dist/bundle/{chunk-EVUMQKV7.js → chunk-WZBPUOWM.js} +2 -2
- package/dist/bundle/chunk-XGNZD52X.js +592 -0
- package/dist/bundle/{chunk-FOP6G45D.js → chunk-YQH4J6YZ.js} +9 -9
- package/dist/bundle/{chunk-6K4Z6CAM.js → chunk-Z7Y2I5YR.js} +447 -399
- package/dist/bundle/{chunk-T4J7XFXT.js → chunk-ZBCC7MBN.js} +62 -58
- package/dist/bundle/command-contract-ZL67KMYL.js +37 -0
- package/dist/bundle/{command-server-entry-3NPPABQQ.js → command-server-entry-COR2VDRU.js} +22 -22
- package/dist/bundle/{decode-26M7XE2B.js → decode-33SGRQM6.js} +3 -3
- package/dist/bundle/{echarts-O3TNDAXJ.js → echarts-QMAA7HH5.js} +2 -2
- package/dist/bundle/{embed-XJLEAWXE.js → embed-W4ZBXPWD.js} +4 -4
- package/dist/bundle/{embedder-OEL6PXEH.js → embedder-73CCZC52.js} +7 -7
- package/dist/bundle/{first-run-CIXGBXY6.js → first-run-MOSUMMVX.js} +7 -8
- package/dist/bundle/first-screen-GUXBF3SL.js +38 -0
- package/dist/bundle/{instructions-AMH5RWVJ.js → instructions-4H7UREH2.js} +1 -1
- package/dist/bundle/{meeting-combined-DMVGQNJ7.js → meeting-combined-QMIZOBBJ.js} +11 -11
- package/dist/bundle/{meeting-model-2THAT7OH.js → meeting-model-2UYVGXD5.js} +9 -9
- package/dist/bundle/{meeting-semantic-Q6XYFYUD.js → meeting-semantic-LEJPUIN3.js} +3 -3
- package/dist/bundle/{node-EGMCBAO7.js → node-P3PUHKYH.js} +2 -2
- package/dist/bundle/{node-sqlite-2SWWGW6H.js → node-sqlite-UHPODTKB.js} +5 -5
- package/dist/bundle/{oauth-V5LGTXF2.js → oauth-T3DWL7OV.js} +5 -5
- package/dist/bundle/{open-25EKOTZA.js → open-ODWX32PF.js} +3 -3
- package/dist/bundle/{openai-VX3OLIHM.js → openai-GSXXHKPX.js} +13 -13
- package/dist/bundle/{process-SGHEN6MQ.js → process-AFIXYXWL.js} +1 -1
- package/dist/bundle/{program-F37JH2SO.js → program-SXSUG335.js} +2209 -1081
- package/dist/bundle/{prompt-2VSPX5S7.js → prompt-GVTYTFK7.js} +3 -3
- package/dist/bundle/{recognize-NA5XUFKK.js → recognize-XDSZEZP5.js} +2 -2
- package/dist/bundle/{remote-BOME6XOE.js → remote-ZWZKMEY6.js} +7 -7
- package/dist/bundle/{rerank-NG3XMFCV.js → rerank-OBZQ54NL.js} +5 -5
- package/dist/bundle/{serve-MR67OBED.js → serve-NY5MUTNW.js} +7 -7
- package/dist/bundle/{server-OP2HJNXD.js → server-JK334V5Y.js} +47 -48
- package/dist/bundle/server-VOPYQCUD.js +79 -0
- package/dist/bundle/{sqlite-runtime-V5U6F5EB.js → sqlite-runtime-2NHF4S6G.js} +4 -4
- package/dist/bundle/{state-L4MWAATO.js → state-YGWZZWPM.js} +4 -4
- package/dist/bundle/{store-CXZFRG5D.js → store-LRQUTFJR.js} +46 -37
- package/dist/bundle/{store-2ALTEH55.js → store-ND6KU4RI.js} +16 -16
- package/dist/bundle/store-maintenance-command-GLYGQM2V.js +66 -0
- package/dist/bundle/surface-P53WLLXP.js +65 -0
- package/dist/hooks.d.ts +1 -8
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +50 -49
- package/dist/hooks.js.map +1 -1
- package/dist/links.d.ts +10 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +7 -0
- package/dist/links.js.map +1 -0
- package/dist/meetings.d.ts +57 -0
- package/dist/meetings.d.ts.map +1 -0
- package/dist/meetings.js +96 -0
- package/dist/meetings.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/skills/attio-cli/SKILL.md +3 -1
- package/dist/bundle/agent-GUXXSLT5.js +0 -38
- package/dist/bundle/chunk-2JHVQMVC.js +0 -16
- package/dist/bundle/chunk-RRTMPSQR.js +0 -29
- package/dist/bundle/chunk-SSA6JBPA.js +0 -778
- package/dist/bundle/command-contract-KCCW4LNI.js +0 -37
- package/dist/bundle/first-screen-5FK4D45F.js +0 -38
- package/dist/bundle/server-4BWAGJQO.js +0 -80
- package/dist/bundle/store-maintenance-command-LC55DRQA.js +0 -67
- package/dist/bundle/surface-3GRJ7473.js +0 -66
|
@@ -0,0 +1,1835 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_STEMMERS,
|
|
5
|
+
createStemmer,
|
|
6
|
+
normalize
|
|
7
|
+
} from "./chunk-AOKAYQSJ.js";
|
|
8
|
+
import {
|
|
9
|
+
PRIORITY_LABELS,
|
|
10
|
+
TASK_STATES,
|
|
11
|
+
TASK_TYPES,
|
|
12
|
+
kindsOfEntry,
|
|
13
|
+
priorityBand,
|
|
14
|
+
providers,
|
|
15
|
+
tagOf
|
|
16
|
+
} from "./chunk-XGNZD52X.js";
|
|
17
|
+
import {
|
|
18
|
+
OPERATORS_BY_TYPE,
|
|
19
|
+
QUERY_LIMITS,
|
|
20
|
+
dayBoundary,
|
|
21
|
+
parseLucene,
|
|
22
|
+
queryAstSchema,
|
|
23
|
+
queryError,
|
|
24
|
+
validateQuery,
|
|
25
|
+
walkQuery
|
|
26
|
+
} from "./chunk-6V7ZUJI6.js";
|
|
27
|
+
import {
|
|
28
|
+
safeParse
|
|
29
|
+
} from "./chunk-S4UUN6LD.js";
|
|
30
|
+
import {
|
|
31
|
+
CliError,
|
|
32
|
+
isCliError
|
|
33
|
+
} from "./chunk-S6JG4YUH.js";
|
|
34
|
+
import {
|
|
35
|
+
__name
|
|
36
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
37
|
+
|
|
38
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/store/sqlite/task-keys.js
|
|
39
|
+
import { createHash } from "node:crypto";
|
|
40
|
+
var TASK_KEY_PREFIXES = {
|
|
41
|
+
question: "Q",
|
|
42
|
+
request: "REQ",
|
|
43
|
+
mention: "M",
|
|
44
|
+
promise: "PR"
|
|
45
|
+
};
|
|
46
|
+
var typedKey = /* @__PURE__ */ __name((database, kind) => {
|
|
47
|
+
const prefix = TASK_KEY_PREFIXES[kind];
|
|
48
|
+
const next = database.prepare("INSERT INTO task_key_counters (prefix, tasks_count) VALUES (?, 1) ON CONFLICT (prefix) DO UPDATE SET tasks_count = tasks_count + 1 RETURNING tasks_count");
|
|
49
|
+
const taken = database.prepare("SELECT 1 FROM tasks WHERE key = ?");
|
|
50
|
+
for (; ; ) {
|
|
51
|
+
const key = `${prefix}-${Number(next.get(prefix)?.tasks_count)}`;
|
|
52
|
+
if (!taken.get(key))
|
|
53
|
+
return key;
|
|
54
|
+
}
|
|
55
|
+
}, "typedKey");
|
|
56
|
+
var INBOX_KEY_LENGTH = 10;
|
|
57
|
+
var inboxKey = /* @__PURE__ */ __name((account) => `IN${createHash("sha256").update(account).digest("hex").slice(0, 8).toUpperCase()}`, "inboxKey");
|
|
58
|
+
var linkInbox = /* @__PURE__ */ __name((database, account, accountId) => {
|
|
59
|
+
database.prepare("UPDATE projects SET account_id = ? WHERE key = ? AND account_id IS NULL").run(accountId, inboxKey(account));
|
|
60
|
+
}, "linkInbox");
|
|
61
|
+
var taskAccountOf = /* @__PURE__ */ __name((database, rowId) => {
|
|
62
|
+
const row = database.prepare("SELECT p.key, p.name FROM tasks t JOIN projects p ON p.id = t.project_id WHERE t.id = ?").get(rowId);
|
|
63
|
+
return row && String(row.key) === inboxKey(String(row.name)) ? String(row.name) : void 0;
|
|
64
|
+
}, "taskAccountOf");
|
|
65
|
+
|
|
66
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/search/task-signature.js
|
|
67
|
+
var DAY = 864e5;
|
|
68
|
+
var CURRENCY = [
|
|
69
|
+
[/^(₽|руб.*|р\.?|rub)$/u, "RUB"],
|
|
70
|
+
[/^(€|eur|евро|euros?)$/u, "EUR"],
|
|
71
|
+
[/^(\$|usd|долл.*|dollars?)$/u, "USD"]
|
|
72
|
+
];
|
|
73
|
+
var currencyOf = /* @__PURE__ */ __name((word) => word ? CURRENCY.find(([pattern]) => pattern.test(word))?.[1] ?? null : null, "currencyOf");
|
|
74
|
+
var SEPARATORS = String.raw`[ \u00a0\u2009\u202f.,]`;
|
|
75
|
+
var NUMBER = String.raw`\d{1,3}(?:${SEPARATORS}\d{3})+(?:[.,]\d{1,2})?|\d+(?:[.,]\d+)?`;
|
|
76
|
+
var AMOUNT = new RegExp(String.raw`(?<![\p{L}\p{N}])([$€₽])?\s?(${NUMBER})(?:([кk])(?![\p{L}])|\s?(тыс\.?|тысяч\p{L}*))?(?![\p{N}])\s?(₽|руб\p{L}*\.?|р\.|р(?![\p{L}])|rub|eur|евро|€|\$|usd|долл\p{L}*|dollars?|euros?)?(?![\p{L}])`, "gu");
|
|
77
|
+
var GROUPED = new RegExp(String.raw`^(\d{1,3}(?:${SEPARATORS}\d{3})+)([.,]\d{1,2})?$`, "u");
|
|
78
|
+
var amountValue = /* @__PURE__ */ __name((number, thousands) => {
|
|
79
|
+
const grouped = GROUPED.exec(number);
|
|
80
|
+
const plain = grouped ? `${(grouped[1] ?? "").replace(new RegExp(SEPARATORS, "gu"), "")}${(grouped[2] ?? "").replace(",", ".")}` : number.replace(",", ".");
|
|
81
|
+
return Math.round(Number(plain) * (thousands ? 1e3 : 1) * 100) / 100;
|
|
82
|
+
}, "amountValue");
|
|
83
|
+
var amountsOf = /* @__PURE__ */ __name((text) => {
|
|
84
|
+
const found = [];
|
|
85
|
+
for (const [, before, number = "", short, long, after] of text.toLowerCase().matchAll(AMOUNT)) {
|
|
86
|
+
const thousands = (short ?? long) !== void 0;
|
|
87
|
+
if (!before && !after && !thousands)
|
|
88
|
+
continue;
|
|
89
|
+
found.push({ value: amountValue(number, thousands), currency: currencyOf(before ?? after?.replace(/\.$/u, "")) });
|
|
90
|
+
}
|
|
91
|
+
return found;
|
|
92
|
+
}, "amountsOf");
|
|
93
|
+
var amountOf = /* @__PURE__ */ __name((text) => amountsOf(text)[0] ?? null, "amountOf");
|
|
94
|
+
var RU_WEEKDAYS = ["\u0432\u043E\u0441\u043A\u0440\u0435\u0441\u0435\u043D", "\u043F\u043E\u043D\u0435\u0434\u0435\u043B\u044C\u043D\u0438\u043A", "\u0432\u0442\u043E\u0440\u043D\u0438\u043A", "\u0441\u0440\u0435\u0434", "\u0447\u0435\u0442\u0432\u0435\u0440\u0433", "\u043F\u044F\u0442\u043D\u0438\u0446", "\u0441\u0443\u0431\u0431\u043E\u0442"];
|
|
95
|
+
var EN_WEEKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
96
|
+
var ES_WEEKDAYS = ["domingo", "lunes", "martes", "miercoles", "jueves", "viernes", "sabado"];
|
|
97
|
+
var WEEKDAY_WORDS = `\u043F\u043E\u043D\u0435\u0434\u0435\u043B\u044C\u043D\u0438\u043A[\u0430\u0435\u0443]?|\u0432\u0442\u043E\u0440\u043D\u0438\u043A[\u0430\u0435\u0443]?|\u0441\u0440\u0435\u0434[\u0430\u0435\u0443\u044B]|\u0447\u0435\u0442\u0432\u0435\u0440\u0433[\u0430\u0435\u0443]?|\u043F\u044F\u0442\u043D\u0438\u0446[\u0430\u0435\u0443\u044B]|\u0441\u0443\u0431\u0431\u043E\u0442[\u0430\u0435\u0443\u044B]|\u0432\u043E\u0441\u043A\u0440\u0435\u0441\u0435\u043D\u044C[\u0435\u044F\u044E]|${EN_WEEKDAYS.join("|")}|(?<!los )(?:${ES_WEEKDAYS.join("|")})`;
|
|
98
|
+
var ES_MONTHS = [
|
|
99
|
+
"enero",
|
|
100
|
+
"febrero",
|
|
101
|
+
"marzo",
|
|
102
|
+
"abril",
|
|
103
|
+
"mayo",
|
|
104
|
+
"junio",
|
|
105
|
+
"julio",
|
|
106
|
+
"agosto",
|
|
107
|
+
"sep?tiembre",
|
|
108
|
+
"octubre",
|
|
109
|
+
"noviembre",
|
|
110
|
+
"diciembre"
|
|
111
|
+
];
|
|
112
|
+
var MONTHS = [
|
|
113
|
+
/^(январ[ьяею]|jan(uary)?)$/u,
|
|
114
|
+
/^(феврал[ьяею]|feb(ruary)?)$/u,
|
|
115
|
+
/^(март[ауе]?|mar(ch)?)$/u,
|
|
116
|
+
/^(апрел[ьяею]|apr(il)?)$/u,
|
|
117
|
+
/^(ма[яеию]|may)$/u,
|
|
118
|
+
/^(июн[ьяею]|june?)$/u,
|
|
119
|
+
/^(июл[ьяею]|july?)$/u,
|
|
120
|
+
/^(август[ауе]?|aug(ust)?)$/u,
|
|
121
|
+
/^(сентябр[ьяею]|sept?(ember)?)$/u,
|
|
122
|
+
/^(октябр[ьяею]|oct(ober)?)$/u,
|
|
123
|
+
/^(ноябр[ьяею]|nov(ember)?)$/u,
|
|
124
|
+
/^(декабр[ьяею]|dec(ember)?)$/u
|
|
125
|
+
];
|
|
126
|
+
var monthIndex = /* @__PURE__ */ __name((word) => MONTHS.findIndex((month) => month.test(word)), "monthIndex");
|
|
127
|
+
var esMonth = /* @__PURE__ */ __name((word = "") => ES_MONTHS.findIndex((month) => new RegExp(`^${month}$`, "u").test(word)), "esMonth");
|
|
128
|
+
var dayOf = /* @__PURE__ */ __name((ms) => {
|
|
129
|
+
const date = new Date(ms);
|
|
130
|
+
return Math.floor(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) / DAY);
|
|
131
|
+
}, "dayOf");
|
|
132
|
+
var dateDay = /* @__PURE__ */ __name((year, month, day) => Math.floor(Date.UTC(year, month, day) / DAY), "dateDay");
|
|
133
|
+
var monthDate = /* @__PURE__ */ __name((year, word = "", day = "") => {
|
|
134
|
+
const month = monthIndex(word);
|
|
135
|
+
return month < 0 || Number(day) > 31 ? void 0 : dateDay(year, month, Number(day));
|
|
136
|
+
}, "monthDate");
|
|
137
|
+
var nthDay = /* @__PURE__ */ __name((day, now) => {
|
|
138
|
+
const date = new Date(now * DAY);
|
|
139
|
+
const sameMonth = dateDay(date.getUTCFullYear(), date.getUTCMonth(), day);
|
|
140
|
+
return sameMonth >= now ? sameMonth : dateDay(date.getUTCFullYear(), date.getUTCMonth() + 1, day);
|
|
141
|
+
}, "nthDay");
|
|
142
|
+
var monthEnd = /* @__PURE__ */ __name((now) => {
|
|
143
|
+
const date = new Date(now * DAY);
|
|
144
|
+
return dateDay(date.getUTCFullYear(), date.getUTCMonth() + 1, 0);
|
|
145
|
+
}, "monthEnd");
|
|
146
|
+
var nextWeekday = /* @__PURE__ */ __name((word, now) => {
|
|
147
|
+
const target = Math.max(RU_WEEKDAYS.findIndex((stem) => word.startsWith(stem)), EN_WEEKDAYS.indexOf(word), ES_WEEKDAYS.indexOf(word));
|
|
148
|
+
let day = now + 1;
|
|
149
|
+
while (new Date(day * DAY).getUTCDay() !== target)
|
|
150
|
+
day++;
|
|
151
|
+
return day;
|
|
152
|
+
}, "nextWeekday");
|
|
153
|
+
var words = /* @__PURE__ */ __name((source) => new RegExp(`(?<![\\p{L}\\p{N}])(?:${source})(?![\\p{L}\\p{N}])`, "gu"), "words");
|
|
154
|
+
var ES_DAY = "(3[01]|[12]\\d|0?[1-9])";
|
|
155
|
+
var DUE_PATTERNS = [
|
|
156
|
+
[words("\u043F\u043E\u0441\u043B\u0435\u0437\u0430\u0432\u0442\u0440\u0430|pasado manana"), (_, now) => now + 2],
|
|
157
|
+
// `por la mañana` and `esta mañana` are a morning, not tomorrow.
|
|
158
|
+
[words("\u0437\u0430\u0432\u0442\u0440\u0430|tomorrow|(?<!(?:la|esta|cada|una) )manana"), (_, now) => now + 1],
|
|
159
|
+
[words("\u0441\u0435\u0433\u043E\u0434\u043D\u044F|today|hoy"), (_, now) => now],
|
|
160
|
+
[words("(\\d{1,2})\\.(\\d{2})"), (m, _, year) => dateDay(year, Number(m[2]) - 1, Number(m[1]))],
|
|
161
|
+
[words("(\\d{1,2})(?:st|nd|rd|th)?\\s+(\\p{L}+)"), (m, _, year) => monthDate(year, m[2], m[1])],
|
|
162
|
+
[words("(\\p{L}+)\\.?\\s+(\\d{1,2})"), (m, _, year) => monthDate(year, m[1], m[2])],
|
|
163
|
+
[
|
|
164
|
+
words("(?:\u0434\u043E|\u043A|by|until|before|on|deadline)\\s+(?:the\\s+)?(\\d{1,2})(?:-?(?:\u0433\u043E|\u0435|\u0447\u0438\u0441\u043B\u0430)|\\s+\u0447\u0438\u0441\u043B\u0430|st|nd|rd|th)"),
|
|
165
|
+
(m, now) => nthDay(Number(m[1]), now)
|
|
166
|
+
],
|
|
167
|
+
[words(`${ES_DAY}\\s+de\\s+(${ES_MONTHS.join("|")})`), (m, _, year) => dateDay(year, esMonth(m[2]), Number(m[1]))],
|
|
168
|
+
// Spanish has no ordinal suffix, so a bare day counts only when no month follows: `antes del 5 de mayo` is May 5.
|
|
169
|
+
[
|
|
170
|
+
words(`(?:(?:antes del|hasta el|para el|el)\\s+dia|antes del|hasta el|para el)\\s+${ES_DAY}(?![.,/]\\d|\\s*%|\\s+del?\\s)`),
|
|
171
|
+
(m, now) => nthDay(Number(m[1]), now)
|
|
172
|
+
],
|
|
173
|
+
[words("\u043A\u043E\u043D\u0446\u0430 \u043C\u0435\u0441\u044F\u0446\u0430|end of (?:the )?month|fin(?:al)? del? mes"), (_, now) => monthEnd(now)],
|
|
174
|
+
[words(`(${WEEKDAY_WORDS})`), (m, now) => nextWeekday(m[1] ?? "", now)]
|
|
175
|
+
];
|
|
176
|
+
var dueDayOf = /* @__PURE__ */ __name((text, createdMs) => {
|
|
177
|
+
const now = dayOf(createdMs);
|
|
178
|
+
const year = new Date(createdMs).getFullYear();
|
|
179
|
+
let best;
|
|
180
|
+
for (const [pattern, resolve] of DUE_PATTERNS)
|
|
181
|
+
for (const match of text.matchAll(pattern)) {
|
|
182
|
+
const day = resolve(match, now, year);
|
|
183
|
+
if (day === void 0 || Number.isNaN(day))
|
|
184
|
+
continue;
|
|
185
|
+
if (!best || (match.index ?? 0) < best.index)
|
|
186
|
+
best = { index: match.index ?? 0, day };
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
return best?.day ?? null;
|
|
190
|
+
}, "dueDayOf");
|
|
191
|
+
|
|
192
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/search/task-similarity.js
|
|
193
|
+
var DAY2 = 864e5;
|
|
194
|
+
var STOP_WORDS = new Set([
|
|
195
|
+
// Russian and English as the test set ran them, already folded (пожалуйста → пожалуиста).
|
|
196
|
+
"\u0438 \u0432 \u0432\u043E \u043D\u0435 \u0447\u0442\u043E \u043E\u043D \u043D\u0430 \u044F \u0441 \u0441\u043E \u043A\u0430\u043A \u0430 \u0442\u043E \u0432\u0441\u0435 \u043E\u043D\u0430 \u0442\u0430\u043A \u0435\u0433\u043E \u043D\u043E \u0434\u0430 \u0442\u044B \u043A \u0443 \u0436\u0435 \u0432\u044B \u0437\u0430 \u0431\u044B \u043F\u043E \u0442\u043E\u043B\u044C\u043A\u043E \u0435\u0435 \u043C\u043D\u0435 \u0431\u044B\u043B\u043E \u0432\u043E\u0442 \u043E\u0442",
|
|
197
|
+
"\u043C\u0435\u043D\u044F \u0435\u0449\u0435 \u043D\u0435\u0442 \u043E \u0438\u0437 \u0435\u043C\u0443 \u0442\u0435\u043F\u0435\u0440\u044C \u043A\u043E\u0433\u0434\u0430 \u0434\u0430\u0436\u0435 \u043D\u0443 \u043B\u0438 \u0435\u0441\u043B\u0438 \u0443\u0436\u0435 \u0438\u043B\u0438 \u043D\u0438 \u0431\u044B\u0442\u044C \u0431\u044B\u043B \u043D\u0435\u0433\u043E \u0434\u043E \u0432\u0430\u0441 \u043D\u0438\u0431\u0443\u0434\u044C \u043E\u043F\u044F\u0442\u044C \u0443\u0436 \u0432\u0430\u043C \u0432\u0435\u0434\u044C",
|
|
198
|
+
"\u0442\u0430\u043C \u043F\u043E\u0442\u043E\u043C \u0441\u0435\u0431\u044F \u043D\u0438\u0447\u0435\u0433\u043E \u0435\u0439 \u043C\u043E\u0436\u0435\u0442 \u043E\u043D\u0438 \u0442\u0443\u0442 \u0433\u0434\u0435 \u0435\u0441\u0442\u044C \u043D\u0430\u0434\u043E \u043D\u0435\u0439 \u0434\u043B\u044F \u043C\u044B \u0442\u0435\u0431\u044F \u0438\u0445 \u0447\u0435\u043C \u0431\u044B\u043B\u0430 \u0441\u0430\u043C \u0447\u0442\u043E\u0431 \u0431\u0435\u0437 \u0447\u0435\u0433\u043E \u0440\u0430\u0437 \u0442\u043E\u0436\u0435",
|
|
199
|
+
"\u0441\u0435\u0431\u0435 \u043F\u043E\u0434 \u0431\u0443\u0434\u0435\u0442 \u0436 \u0442\u043E\u0433\u0434\u0430 \u043A\u0442\u043E \u044D\u0442\u043E\u0442 \u0442\u043E\u0433\u043E \u043F\u043E\u0442\u043E\u043C\u0443 \u044D\u0442\u043E\u0433\u043E \u043A\u0430\u043A\u043E\u0439 \u0441\u043E\u0432\u0441\u0435\u043C \u043D\u0438\u043C \u0437\u0434\u0435\u0441\u044C \u044D\u0442\u043E\u043C \u043E\u0434\u0438\u043D \u043F\u043E\u0447\u0442\u0438 \u043C\u043E\u0438 \u0442\u0435\u043C \u0447\u0442\u043E\u0431\u044B \u043D\u0435\u0435",
|
|
200
|
+
"\u0441\u0435\u0439\u0447\u0430\u0441 \u0431\u044B\u043B\u0438 \u043A\u0443\u0434\u0430 \u0437\u0430\u0447\u0435\u043C \u0432\u0441\u0435\u0445 \u043C\u043E\u0436\u043D\u043E \u043F\u0440\u0438 \u043E\u0431 \u0434\u0440\u0443\u0433\u043E\u0439 \u0445\u043E\u0442\u044C \u043F\u043E\u0441\u043B\u0435 \u043D\u0430\u0434 \u0431\u043E\u043B\u044C\u0448\u0435 \u0442\u043E\u0442 \u0447\u0435\u0440\u0435\u0437 \u044D\u0442\u0438 \u043D\u0430\u0441 \u043F\u0440\u043E \u0432\u0441\u0435\u0433\u043E \u043D\u0438\u0445 \u043A\u0430\u043A\u0430\u044F",
|
|
201
|
+
"\u043C\u043D\u043E\u0433\u043E \u0442\u0440\u0438 \u044D\u0442\u0443 \u043C\u043E\u044F \u0441\u0432\u043E\u044E \u044D\u0442\u043E\u0439 \u043F\u0435\u0440\u0435\u0434 \u0438\u043C \u0432\u0441\u0435\u0433\u0434\u0430 \u043C\u0435\u0436\u0434\u0443 \u043F\u043E\u0436\u0430\u043B\u0443\u0438\u0441\u0442\u0430 \u043F\u043B\u0438\u0437",
|
|
202
|
+
"i me my we our you your he him his she her it its they them their what which who this that these those am",
|
|
203
|
+
"is are was were be been being have has had do does did a an the and but if or because as until while of at",
|
|
204
|
+
"by for with about against between into through during before after above below to from up down in out on off",
|
|
205
|
+
"over under again further then once here there when where why how all any both each few more most other some",
|
|
206
|
+
"such no nor not only own same so than too very s t can will just don should now please pls hi hey",
|
|
207
|
+
// Spanish, not in the test set (it had no Spanish task); English look-alikes (son, hay, todo) left out.
|
|
208
|
+
"de la que el en y o u e los las del al lo le les se su sus mi mis tu te ti yo nos un una unos unas por para",
|
|
209
|
+
"con sin sobre entre hasta desde como mas pero muy ya si ni este esta esto estos estas ese esa eso es ser fue",
|
|
210
|
+
"ha han porque cuando donde tambien favor"
|
|
211
|
+
].join(" ").split(" "));
|
|
212
|
+
var joinDigitGroups = /* @__PURE__ */ __name((text) => text.replace(/(\d)[ \u00a0\u202f,](?=\d{3}(?!\d))/gu, "$1"), "joinDigitGroups");
|
|
213
|
+
var taskWordsOf = /* @__PURE__ */ __name((text) => normalize(joinDigitGroups(text)), "taskWordsOf");
|
|
214
|
+
var defaultStemmer = createStemmer(DEFAULT_STEMMERS);
|
|
215
|
+
var taskStemsOf = /* @__PURE__ */ __name((text, stemmer) => new Set(stemmer.explain(joinDigitGroups(text)).filter(({ word }) => !STOP_WORDS.has(normalize(word))).map(({ stem }) => stem)), "taskStemsOf");
|
|
216
|
+
var trigramsOf = /* @__PURE__ */ __name((text) => {
|
|
217
|
+
const grams = /* @__PURE__ */ new Set();
|
|
218
|
+
for (let at = 0; at + 3 <= text.length; at++)
|
|
219
|
+
grams.add(text.slice(at, at + 3));
|
|
220
|
+
return grams;
|
|
221
|
+
}, "trigramsOf");
|
|
222
|
+
var prepareTask = /* @__PURE__ */ __name((task, stemmer = defaultStemmer) => {
|
|
223
|
+
const description = task.description ?? "";
|
|
224
|
+
const createdMs = task.createdAt.getTime();
|
|
225
|
+
const signatureText = normalize(joinDigitGroups(`${description}
|
|
226
|
+
${task.title}`));
|
|
227
|
+
const { message } = task;
|
|
228
|
+
const messageText = message === void 0 ? "" : normalize(joinDigitGroups(message.text));
|
|
229
|
+
const amountIn = /* @__PURE__ */ __name(() => amountOf(signatureText) ?? (message === void 0 ? null : amountOf(messageText)), "amountIn");
|
|
230
|
+
const dueIn = /* @__PURE__ */ __name(() => dueDayOf(signatureText, createdMs) ?? (message === void 0 ? null : dueDayOf(messageText, message.sentAt.getTime())), "dueIn");
|
|
231
|
+
return {
|
|
232
|
+
stems: taskStemsOf(`${task.title}
|
|
233
|
+
${description}${message === void 0 ? "" : `
|
|
234
|
+
${message.text}`}`, stemmer),
|
|
235
|
+
trigrams: trigramsOf(normalize(joinDigitGroups(task.title))),
|
|
236
|
+
...task.person === void 0 ? {} : { person: task.person },
|
|
237
|
+
...task.category === void 0 ? {} : { category: task.category },
|
|
238
|
+
amount: task.amount === void 0 ? amountIn() : task.amount,
|
|
239
|
+
dueDay: task.due === void 0 ? dueIn() : task.due === null ? null : dayOf(task.due.getTime()),
|
|
240
|
+
createdMs
|
|
241
|
+
};
|
|
242
|
+
}, "prepareTask");
|
|
243
|
+
var TASK_SIMILARITY_WEIGHTS = {
|
|
244
|
+
text: {
|
|
245
|
+
high: { weight: 5, why: "Jaccard \u2265 0.6: 11 / 18; +5 estimated on both halves" },
|
|
246
|
+
middle: { weight: 5, why: "Jaccard 0.3\u20130.6: 54 / 102; reminders are short, so worth as much as \u2265 0.6" },
|
|
247
|
+
low: { weight: -2, why: "Jaccard < 0.3: 15 / 4493" }
|
|
248
|
+
},
|
|
249
|
+
person: {
|
|
250
|
+
same: { weight: 1, why: "80 / 2149; candidates come mostly from the same-person lookup, so most share it" },
|
|
251
|
+
different: { weight: -3, why: "0 / 2293; no duplicate showed it, first-draft value kept" },
|
|
252
|
+
unknown: { weight: 0, why: "0 / 171; no duplicate showed it, first-draft value kept" }
|
|
253
|
+
},
|
|
254
|
+
amount: {
|
|
255
|
+
equal: { weight: 6, why: "20 / 13; the least stable weight: +10 on half A, +6 on half B" },
|
|
256
|
+
different: { weight: -4, why: "0 / 849; no duplicate showed it, first-draft value kept" },
|
|
257
|
+
missing: { weight: 0, why: "60 / 3751" }
|
|
258
|
+
},
|
|
259
|
+
category: {
|
|
260
|
+
same: { weight: 1, why: "80 / 2667" },
|
|
261
|
+
different: { weight: -1, why: "0 / 1946; no duplicate showed it, first-draft value kept" },
|
|
262
|
+
unknown: { weight: 0, why: "not in the set: every task there had a category" }
|
|
263
|
+
},
|
|
264
|
+
due: {
|
|
265
|
+
near: { weight: 4, why: "\u2264 2 days apart: 26 / 126" },
|
|
266
|
+
far: { weight: -1, why: "more than 2 days apart: 4 / 707" },
|
|
267
|
+
missing: { weight: 0, why: "50 / 3780" }
|
|
268
|
+
},
|
|
269
|
+
reply: {
|
|
270
|
+
yes: {
|
|
271
|
+
weight: 2,
|
|
272
|
+
why: "real chats: wrong 11 times in 13 among shown pairs; +2 lifted shown-pair precision on both labelled sets"
|
|
273
|
+
},
|
|
274
|
+
no: { weight: 0, why: "74 / 4608" }
|
|
275
|
+
},
|
|
276
|
+
time: {
|
|
277
|
+
near: { weight: 2, why: "\u2264 3 days apart: 69 / 888" },
|
|
278
|
+
weeks: { weight: -2, why: "4\u201314 days apart: 8 / 2456" },
|
|
279
|
+
far: { weight: -3, why: "more than 14 days apart: 3 / 1269" }
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
var TASK_SIMILARITY_BANDS = { likely: 10, maybe: 5 };
|
|
283
|
+
var overlap = /* @__PURE__ */ __name((a, b) => {
|
|
284
|
+
let shared = 0;
|
|
285
|
+
for (const item of a)
|
|
286
|
+
if (b.has(item))
|
|
287
|
+
shared++;
|
|
288
|
+
const all = a.size + b.size - shared;
|
|
289
|
+
return { shared, all, jaccard: a.size && b.size ? shared / all : 0 };
|
|
290
|
+
}, "overlap");
|
|
291
|
+
var LEVEL_REASONS = {
|
|
292
|
+
person: { same: "same person", different: "different person" },
|
|
293
|
+
amount: { equal: "same amount", different: "different amount" }
|
|
294
|
+
};
|
|
295
|
+
var weightOf = /* @__PURE__ */ __name((field2, level) => TASK_SIMILARITY_WEIGHTS[field2][level].weight, "weightOf");
|
|
296
|
+
var plural = /* @__PURE__ */ __name((count, word) => `${count} ${word}${count === 1 ? "" : "s"}`, "plural");
|
|
297
|
+
var bandOf = /* @__PURE__ */ __name((score) => score >= TASK_SIMILARITY_BANDS.likely ? "likely" : score >= TASK_SIMILARITY_BANDS.maybe ? "maybe" : "different", "bandOf");
|
|
298
|
+
var compareTasks = /* @__PURE__ */ __name((a, b, { replyChain = false } = {}) => {
|
|
299
|
+
const stems = overlap(a.stems, b.stems);
|
|
300
|
+
const trigrams = overlap(a.trigrams, b.trigrams).jaccard;
|
|
301
|
+
const text = Math.max(stems.jaccard, trigrams);
|
|
302
|
+
const days = Math.abs(a.createdMs - b.createdMs) / DAY2;
|
|
303
|
+
const dueApart = a.dueDay !== null && b.dueDay !== null ? Math.abs(a.dueDay - b.dueDay) : null;
|
|
304
|
+
const levels = {
|
|
305
|
+
text: text >= 0.6 ? "high" : text >= 0.3 ? "middle" : "low",
|
|
306
|
+
person: a.person && b.person ? a.person === b.person ? "same" : "different" : "unknown",
|
|
307
|
+
amount: a.amount && b.amount ? a.amount.value === b.amount.value && (a.amount.currency === b.amount.currency || !a.amount.currency || !b.amount.currency) ? "equal" : "different" : "missing",
|
|
308
|
+
category: a.category && b.category ? a.category === b.category ? "same" : "different" : "unknown",
|
|
309
|
+
due: dueApart === null ? "missing" : dueApart <= 2 ? "near" : "far",
|
|
310
|
+
reply: replyChain ? "yes" : "no",
|
|
311
|
+
time: days <= 3 ? "near" : days <= 14 ? "weeks" : "far"
|
|
312
|
+
};
|
|
313
|
+
const score = weightOf("text", levels.text) + weightOf("person", levels.person) + weightOf("amount", levels.amount) + weightOf("category", levels.category) + weightOf("due", levels.due) + weightOf("reply", levels.reply) + weightOf("time", levels.time);
|
|
314
|
+
const textReason = stems.jaccard >= trigrams ? `${stems.shared} of ${plural(stems.all, "stem")} shared` : `titles ${Math.round(trigrams * 100)}% alike letter by letter`;
|
|
315
|
+
const reasons = [
|
|
316
|
+
LEVEL_REASONS.person[levels.person],
|
|
317
|
+
LEVEL_REASONS.amount[levels.amount],
|
|
318
|
+
dueApart === null ? void 0 : dueApart === 0 ? "same due date" : `due ${plural(dueApart, "day")} apart`,
|
|
319
|
+
replyChain ? "in one reply chain" : void 0,
|
|
320
|
+
textReason
|
|
321
|
+
].filter((reason) => reason !== void 0);
|
|
322
|
+
return {
|
|
323
|
+
score,
|
|
324
|
+
band: bandOf(score),
|
|
325
|
+
levels,
|
|
326
|
+
reasons,
|
|
327
|
+
text: { sharedStems: stems.shared, allStems: stems.all, stems: stems.jaccard, trigrams }
|
|
328
|
+
};
|
|
329
|
+
}, "compareTasks");
|
|
330
|
+
var compareViews = /* @__PURE__ */ __name((a, b, options = {}) => {
|
|
331
|
+
let best;
|
|
332
|
+
for (const one of a)
|
|
333
|
+
for (const other of b) {
|
|
334
|
+
const scored = compareTasks(one, other, options);
|
|
335
|
+
if (!best || scored.score > best.score)
|
|
336
|
+
best = scored;
|
|
337
|
+
}
|
|
338
|
+
if (!best)
|
|
339
|
+
throw new Error("compareViews needs at least one view on each side");
|
|
340
|
+
return best;
|
|
341
|
+
}, "compareViews");
|
|
342
|
+
var rankCandidates = /* @__PURE__ */ __name((views, candidates) => candidates.map(({ id, views: candidate, replyChain, subjectViews }) => ({
|
|
343
|
+
id,
|
|
344
|
+
...compareViews(subjectViews ?? views, candidate, replyChain === void 0 ? {} : { replyChain })
|
|
345
|
+
})).sort((a, b) => b.score - a.score), "rankCandidates");
|
|
346
|
+
|
|
347
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/store/sqlite/merged-persons.js
|
|
348
|
+
var SEPARATIONS = ["unlink", "split", "undo-merge"];
|
|
349
|
+
var mergeSql = /* @__PURE__ */ __name((event) => `(${event}.from_person_id IS NOT NULL AND ${event}.from_person_id <> ${event}.to_person_id AND ${event}.method NOT IN (${SEPARATIONS.map((method) => `'${method}'`).join(", ")}) AND NOT EXISTS (SELECT 1 FROM identity_link_events stay WHERE stay.to_person_id = ${event}.from_person_id AND stay.identity_id <> ${event}.identity_id AND stay.id < ${event}.id AND stay.id = (SELECT max(s.id) FROM identity_link_events s WHERE s.identity_id = stay.identity_id AND s.id < ${event}.id) AND NOT EXISTS (SELECT 1 FROM identity_link_events went WHERE went.identity_id = stay.identity_id AND went.from_person_id = ${event}.from_person_id AND went.to_person_id = ${event}.to_person_id AND went.id = (SELECT min(w.id) FROM identity_link_events w WHERE w.identity_id = stay.identity_id AND w.id > ${event}.id))))`, "mergeSql");
|
|
350
|
+
var mergedAwaySql = /* @__PURE__ */ __name((person) => `(${person}.owner = 0 AND NOT EXISTS (SELECT 1 FROM identity_links ml WHERE ml.person_id = ${person}.id) AND (EXISTS (SELECT 1 FROM identity_link_events me WHERE me.from_person_id = ${person}.id AND ${mergeSql("me")}) OR EXISTS (SELECT 1 FROM sender_bot_moves mb WHERE mb.from_person_id = ${person}.id AND mb.to_bot_id IS NOT NULL)))`, "mergedAwaySql");
|
|
351
|
+
var LATEST_MOVE = /* @__PURE__ */ __name((person) => `(SELECT e.to_person_id FROM identity_link_events e WHERE e.from_person_id = ${person}.id AND ${mergeSql("e")}
|
|
352
|
+
ORDER BY e.id DESC LIMIT 1)`, "LATEST_MOVE");
|
|
353
|
+
var currentPerson = /* @__PURE__ */ __name((database, pk) => {
|
|
354
|
+
const seen = /* @__PURE__ */ new Set();
|
|
355
|
+
let at = pk;
|
|
356
|
+
while (!seen.has(at)) {
|
|
357
|
+
seen.add(at);
|
|
358
|
+
const next = database.prepare(`SELECT ${LATEST_MOVE("p")} AS next FROM persons p WHERE p.id = ? AND ${mergedAwaySql("p")}`).get(at);
|
|
359
|
+
if (next?.next == null)
|
|
360
|
+
return at;
|
|
361
|
+
at = Number(next.next);
|
|
362
|
+
}
|
|
363
|
+
return at;
|
|
364
|
+
}, "currentPerson");
|
|
365
|
+
var samePersons = /* @__PURE__ */ __name((database, pk) => {
|
|
366
|
+
const found = [currentPerson(database, pk)];
|
|
367
|
+
const into = database.prepare(`SELECT p.id FROM persons p WHERE p.id IN (SELECT from_person_id FROM identity_link_events WHERE to_person_id = ?)
|
|
368
|
+
AND ${mergedAwaySql("p")} AND ${LATEST_MOVE("p")} = ?`);
|
|
369
|
+
for (let at = 0; at < found.length; at++) {
|
|
370
|
+
const target = found[at];
|
|
371
|
+
for (const row of into.all(target, target))
|
|
372
|
+
if (!found.includes(Number(row.id)))
|
|
373
|
+
found.push(Number(row.id));
|
|
374
|
+
}
|
|
375
|
+
return found;
|
|
376
|
+
}, "samePersons");
|
|
377
|
+
var idsOf = /* @__PURE__ */ __name((database, type, id) => JSON.stringify(type === "person" ? samePersons(database, id) : [id]), "idsOf");
|
|
378
|
+
|
|
379
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/store/sqlite/task-board.js
|
|
380
|
+
var TASK_SORTS = ["priority", "due", "created", "updated", "key", "state"];
|
|
381
|
+
var field = /* @__PURE__ */ __name((name, type, example, more = {}) => ({
|
|
382
|
+
name,
|
|
383
|
+
type,
|
|
384
|
+
operators: OPERATORS_BY_TYPE[type],
|
|
385
|
+
example,
|
|
386
|
+
...more
|
|
387
|
+
}), "field");
|
|
388
|
+
var PROJECT_TASK_FIELDS = [
|
|
389
|
+
field("state", "enum", "state:todo", { values: TASK_STATES }),
|
|
390
|
+
field("kind", "enum", "kind:bug", { values: TASK_TYPES }),
|
|
391
|
+
field("project", "kw", "project:HRB", {
|
|
392
|
+
relation: "a project by its key or project:<id>; project:* is every project, and lists project tasks only"
|
|
393
|
+
}),
|
|
394
|
+
field("assignee", "kw", 'assignee:"person:12"', {
|
|
395
|
+
relation: "who does it: any, none, or a person (person:12 in quotes, or the bare 12)"
|
|
396
|
+
}),
|
|
397
|
+
field("priority", "kw", "priority:high", {
|
|
398
|
+
operators: ["term", "range", "wildcard"],
|
|
399
|
+
relation: "low, medium, high, critical or none; a range of labels or of the 0\u20131 number: priority:[high TO critical]"
|
|
400
|
+
}),
|
|
401
|
+
field("agent", "kw", "agent:hermes", { relation: "the agent working on it, by name; none or any" }),
|
|
402
|
+
field("parent", "kw", "parent:HRB-1", { relation: "the subtasks of a task, by its key; none or any" }),
|
|
403
|
+
field("related", "ref", 'related:"deal:7"', {
|
|
404
|
+
operators: ["term", "phrase"],
|
|
405
|
+
relation: "the tasks of a deal, lead or organization: its project's tasks and those its CRM stages opened; an organization's are its projects', its deals' and its leads'"
|
|
406
|
+
}),
|
|
407
|
+
field("due", "time", "due:[today TO 2026-12-31]", {
|
|
408
|
+
relation: "the due date; today, tomorrow and yesterday are your calendar days; NOT due:* has none"
|
|
409
|
+
}),
|
|
410
|
+
field("overdue", "bool", "overdue:true", { relation: "open work due before today" }),
|
|
411
|
+
field("when", "enum", "when:today", {
|
|
412
|
+
values: ["overdue", "today", "upcoming", "later", "none"],
|
|
413
|
+
relation: "the due date as a board groups it: overdue (open work due before today), today, upcoming (the next 7 days after today), later, or none"
|
|
414
|
+
}),
|
|
415
|
+
field("created", "time", "created:>=30d", { relation: "when it was opened" }),
|
|
416
|
+
field("closed", "time", "closed:>=14d", { relation: "when it was done or dismissed" }),
|
|
417
|
+
field("ready", "bool", "ready:true", { relation: "open work whose blocked-by tasks are all done" }),
|
|
418
|
+
field("text", "txt", "text:invoice", { relation: "words of the title and description; a bare word means this" })
|
|
419
|
+
];
|
|
420
|
+
var OPEN = "t.status NOT IN ('done', 'dismissed')";
|
|
421
|
+
var OWNER_PROJECTS = `SELECT id FROM projects WHERE deleted_at IS NULL AND length(key) <> ${INBOX_KEY_LENGTH}`;
|
|
422
|
+
var ASSIGNED = "SELECT 1 FROM task_assignments a WHERE a.task_id = t.id AND a.assignee_type = 'person' AND a.role = 'assignee'";
|
|
423
|
+
var UNFINISHED_BLOCKER = "SELECT 1 FROM links l LEFT JOIN tasks b ON b.id = l.to_id LEFT JOIN projects bp ON bp.id = b.project_id WHERE l.from_type = 'task' AND l.to_type = 'task' AND l.kind = 'blocked-by' AND l.from_id = t.id AND l.confirmed = 1 AND l.anchor IS NULL AND (b.id IS NULL OR b.deleted_at IS NOT NULL OR bp.deleted_at IS NOT NULL OR b.status <> 'done')";
|
|
424
|
+
var wordsMatch = /* @__PURE__ */ __name((node) => {
|
|
425
|
+
const words2 = taskWordsOf(node.value.replaceAll("*", " ")).split(/\s+/).filter((word) => /[\p{L}\p{N}]/u.test(word));
|
|
426
|
+
if (words2.length === 0)
|
|
427
|
+
return void 0;
|
|
428
|
+
const quoted3 = /* @__PURE__ */ __name((text) => `"${text.replaceAll('"', '""')}"`, "quoted");
|
|
429
|
+
return `normalized_text : (${node.operator === "phrase" ? quoted3(words2.join(" ")) : words2.map((word) => `${quoted3(word)}*`).join(" AND ")})`;
|
|
430
|
+
}, "wordsMatch");
|
|
431
|
+
var projectWhere = /* @__PURE__ */ __name((node) => {
|
|
432
|
+
if (node.operator === "wildcard" && node.value === "*")
|
|
433
|
+
return { sql: `t.project_id IN (${OWNER_PROJECTS})`, params: [] };
|
|
434
|
+
const id = /^project:(\d+)$/.exec(node.value.trim())?.[1];
|
|
435
|
+
if (id !== void 0)
|
|
436
|
+
return { sql: "t.project_id = ?", params: [Number(id)] };
|
|
437
|
+
const key = node.value.trim().toUpperCase();
|
|
438
|
+
return {
|
|
439
|
+
sql: `t.project_id IN (SELECT id FROM projects WHERE key ${node.operator === "wildcard" ? "GLOB" : "="} ?)`,
|
|
440
|
+
params: [key]
|
|
441
|
+
};
|
|
442
|
+
}, "projectWhere");
|
|
443
|
+
var assigneeWhere = /* @__PURE__ */ __name((database, node) => {
|
|
444
|
+
const value = node.value.trim().toLowerCase();
|
|
445
|
+
if (value === "any" || node.operator === "wildcard" && value === "*")
|
|
446
|
+
return { sql: `EXISTS (${ASSIGNED})`, params: [] };
|
|
447
|
+
if (value === "none")
|
|
448
|
+
return { sql: `NOT EXISTS (${ASSIGNED})`, params: [] };
|
|
449
|
+
const id = /^(?:person:)?(\d+)$/.exec(value)?.[1];
|
|
450
|
+
if (id === void 0)
|
|
451
|
+
throw new CliError("validation_error", `assignee: takes any, none or "person:<id>", not "${node.value}"`);
|
|
452
|
+
return {
|
|
453
|
+
sql: `EXISTS (${ASSIGNED} AND a.assignee_id IN (SELECT value FROM json_each(?)))`,
|
|
454
|
+
params: [idsOf(database, "person", Number(id))]
|
|
455
|
+
};
|
|
456
|
+
}, "assigneeWhere");
|
|
457
|
+
var bound = /* @__PURE__ */ __name((value, side, node) => {
|
|
458
|
+
const word = value.trim().toLowerCase();
|
|
459
|
+
if (word === "*")
|
|
460
|
+
return void 0;
|
|
461
|
+
if (PRIORITY_LABELS.includes(word))
|
|
462
|
+
return priorityBand(word)[side];
|
|
463
|
+
const number = Number(word);
|
|
464
|
+
if (word === "" || !Number.isFinite(number) || number < 0 || number > 1)
|
|
465
|
+
throw new CliError("validation_error", `priority: takes ${PRIORITY_LABELS.join(", ")}, none, or 0 to 1, not "${node.value}"`);
|
|
466
|
+
return number;
|
|
467
|
+
}, "bound");
|
|
468
|
+
var priorityWhere = /* @__PURE__ */ __name((node) => {
|
|
469
|
+
const score = "t.priority_score";
|
|
470
|
+
if (node.operator === "wildcard") {
|
|
471
|
+
if (node.value === "*")
|
|
472
|
+
return { sql: `${score} IS NOT NULL`, params: [] };
|
|
473
|
+
throw new CliError("validation_error", "priority: takes a label, none, or a range");
|
|
474
|
+
}
|
|
475
|
+
if (node.operator !== "range") {
|
|
476
|
+
const word = node.value.trim().toLowerCase();
|
|
477
|
+
if (word === "none")
|
|
478
|
+
return { sql: `${score} IS NULL`, params: [] };
|
|
479
|
+
if (!PRIORITY_LABELS.includes(word))
|
|
480
|
+
throw new CliError("validation_error", `priority: takes ${PRIORITY_LABELS.join(", ")} or none; a number goes in a range`);
|
|
481
|
+
const { from, to } = priorityBand(word);
|
|
482
|
+
return { sql: `${score} >= ? AND ${score} ${to === 1 ? "<=" : "<"} ?`, params: [from, to] };
|
|
483
|
+
}
|
|
484
|
+
const lower = bound(node.value, "from", node);
|
|
485
|
+
const upperWord = (node.upper ?? "*").trim().toLowerCase();
|
|
486
|
+
const upper = bound(upperWord, "to", node);
|
|
487
|
+
const labelUpper = PRIORITY_LABELS.includes(upperWord);
|
|
488
|
+
const parts = [`${score} IS NOT NULL`];
|
|
489
|
+
const params = [];
|
|
490
|
+
if (lower !== void 0) {
|
|
491
|
+
parts.push(`${score} ${node.lower_inclusive === false ? ">" : ">="} ?`);
|
|
492
|
+
params.push(lower);
|
|
493
|
+
}
|
|
494
|
+
if (upper !== void 0) {
|
|
495
|
+
parts.push(`${score} ${labelUpper ? upper === 1 ? "<=" : "<" : node.upper_inclusive === false ? "<" : "<="} ?`);
|
|
496
|
+
params.push(upper);
|
|
497
|
+
}
|
|
498
|
+
return { sql: parts.join(" AND "), params };
|
|
499
|
+
}, "priorityWhere");
|
|
500
|
+
var agentWhere = /* @__PURE__ */ __name((node) => {
|
|
501
|
+
const value = node.value.trim().toLowerCase();
|
|
502
|
+
if (value === "none")
|
|
503
|
+
return { sql: "t.agent IS NULL", params: [] };
|
|
504
|
+
if (value === "any" || node.operator === "wildcard" && value === "*")
|
|
505
|
+
return { sql: "t.agent IS NOT NULL", params: [] };
|
|
506
|
+
return node.operator === "wildcard" ? { sql: "lower(t.agent) GLOB ?", params: [value] } : { sql: "lower(t.agent) = ?", params: [value] };
|
|
507
|
+
}, "agentWhere");
|
|
508
|
+
var parentWhere = /* @__PURE__ */ __name((node) => {
|
|
509
|
+
const value = node.value.trim();
|
|
510
|
+
if (value.toLowerCase() === "none")
|
|
511
|
+
return { sql: "t.parent_id IS NULL", params: [] };
|
|
512
|
+
if (value.toLowerCase() === "any")
|
|
513
|
+
return { sql: "t.parent_id IS NOT NULL", params: [] };
|
|
514
|
+
const key = value.replace(/^task:/, "");
|
|
515
|
+
return {
|
|
516
|
+
sql: "t.parent_id IN (SELECT id FROM tasks WHERE key = ? OR package_id = ? UNION SELECT task_id FROM task_events WHERE kind = 'project' AND json_extract(changes, '$.key[0]') = ?)",
|
|
517
|
+
params: [key.toUpperCase(), key, key.toUpperCase()]
|
|
518
|
+
};
|
|
519
|
+
}, "parentWhere");
|
|
520
|
+
var PROJECTS_OF_DEALS = /* @__PURE__ */ __name((table, by) => `SELECT project_id FROM ${table} WHERE ${by} = ? AND deleted_at IS NULL AND project_id IS NOT NULL`, "PROJECTS_OF_DEALS");
|
|
521
|
+
var REFS_OF_DEALS = /* @__PURE__ */ __name((table, kind) => `SELECT '${kind}:' || id FROM ${table} WHERE organization_id = ? AND deleted_at IS NULL`, "REFS_OF_DEALS");
|
|
522
|
+
var relatedWhere = /* @__PURE__ */ __name((node) => {
|
|
523
|
+
const [, kind, id] = /^(deal|lead|organization):(\d+)$/.exec(node.value.trim().toLowerCase()) ?? [];
|
|
524
|
+
if (kind === void 0 || id === void 0)
|
|
525
|
+
throw new CliError("validation_error", `related: takes "deal:<id>", "lead:<id>" or "organization:<id>", not "${node.value}"`);
|
|
526
|
+
const number = Number(id);
|
|
527
|
+
if (kind === "organization")
|
|
528
|
+
return {
|
|
529
|
+
sql: `(t.project_id IN (SELECT id FROM projects WHERE organization_id = ? AND deleted_at IS NULL UNION ${PROJECTS_OF_DEALS("deals", "organization_id")} UNION ${PROJECTS_OF_DEALS("leads", "organization_id")}) OR t.source_group IN (${REFS_OF_DEALS("deals", "deal")} UNION ${REFS_OF_DEALS("leads", "lead")}))`,
|
|
530
|
+
params: [number, number, number, number, number]
|
|
531
|
+
};
|
|
532
|
+
const table = kind === "deal" ? "deals" : "leads";
|
|
533
|
+
return {
|
|
534
|
+
sql: `(t.source_group = ? OR t.project_id IN (${PROJECTS_OF_DEALS(table, "id")}))`,
|
|
535
|
+
params: [`${kind}:${number}`, number]
|
|
536
|
+
};
|
|
537
|
+
}, "relatedWhere");
|
|
538
|
+
var truth = /* @__PURE__ */ __name((node, sql) => ({
|
|
539
|
+
sql: node.value.toLowerCase() === "true" ? sql : `NOT (${sql})`,
|
|
540
|
+
params: []
|
|
541
|
+
}), "truth");
|
|
542
|
+
var SPAN = { start: 0, end: 0 };
|
|
543
|
+
var UPCOMING_DAYS = 7;
|
|
544
|
+
var dayIn = /* @__PURE__ */ __name((at, zone, ahead) => {
|
|
545
|
+
const date = /* @__PURE__ */ new Date(`${new Intl.DateTimeFormat("en-CA", { timeZone: zone, year: "numeric", month: "2-digit", day: "2-digit" }).format(at)}T00:00:00Z`);
|
|
546
|
+
date.setUTCDate(date.getUTCDate() + ahead);
|
|
547
|
+
return dayBoundary(date.toISOString().slice(0, 10), zone, false, SPAN);
|
|
548
|
+
}, "dayIn");
|
|
549
|
+
var dueGroups = /* @__PURE__ */ __name((now, zone) => {
|
|
550
|
+
const today = dayIn(now, zone, 0);
|
|
551
|
+
const tomorrow = dayIn(now, zone, 1);
|
|
552
|
+
const after = dayIn(now, zone, UPCOMING_DAYS + 1);
|
|
553
|
+
return {
|
|
554
|
+
overdue: `${OPEN} AND t.due_at IS NOT NULL AND t.due_at < ${today}`,
|
|
555
|
+
today: `t.due_at >= ${today} AND t.due_at < ${tomorrow}`,
|
|
556
|
+
upcoming: `t.due_at >= ${tomorrow} AND t.due_at < ${after}`,
|
|
557
|
+
later: `t.due_at >= ${after}`,
|
|
558
|
+
none: "t.due_at IS NULL"
|
|
559
|
+
};
|
|
560
|
+
}, "dueGroups");
|
|
561
|
+
var projectTaskColumns = /* @__PURE__ */ __name((now, zone, database) => ({
|
|
562
|
+
state: { type: "enum", sql: "t.status" },
|
|
563
|
+
kind: { type: "enum", sql: "t.type" },
|
|
564
|
+
project: { where: projectWhere },
|
|
565
|
+
assignee: { where: /* @__PURE__ */ __name((node) => assigneeWhere(database, node), "where") },
|
|
566
|
+
priority: { where: priorityWhere },
|
|
567
|
+
agent: { where: agentWhere },
|
|
568
|
+
parent: { where: parentWhere },
|
|
569
|
+
related: { where: relatedWhere },
|
|
570
|
+
due: { type: "time", sql: "t.due_at" },
|
|
571
|
+
created: { type: "time", sql: "t.created_at" },
|
|
572
|
+
closed: { type: "time", sql: "t.closed_at" },
|
|
573
|
+
overdue: { where: /* @__PURE__ */ __name((node) => truth(node, dueGroups(now, zone).overdue), "where") },
|
|
574
|
+
when: {
|
|
575
|
+
where: /* @__PURE__ */ __name((node) => {
|
|
576
|
+
const group = dueGroups(now, zone)[node.value.toLowerCase()];
|
|
577
|
+
if (group === void 0)
|
|
578
|
+
throw new CliError("validation_error", "when is overdue, today, upcoming, later or none");
|
|
579
|
+
return { sql: group, params: [] };
|
|
580
|
+
}, "where")
|
|
581
|
+
},
|
|
582
|
+
ready: { where: /* @__PURE__ */ __name((node) => truth(node, `${OPEN} AND NOT EXISTS (${UNFINISHED_BLOCKER})`), "where") },
|
|
583
|
+
text: {
|
|
584
|
+
where: /* @__PURE__ */ __name((node) => {
|
|
585
|
+
const match = wordsMatch(node);
|
|
586
|
+
const byKey = { sql: "t.key = ?", params: [node.value.trim().toUpperCase()] };
|
|
587
|
+
if (match === void 0)
|
|
588
|
+
return byKey;
|
|
589
|
+
return {
|
|
590
|
+
sql: `(t.id IN (SELECT rowid FROM task_words WHERE task_words MATCH ?) OR ${byKey.sql})`,
|
|
591
|
+
params: [match, ...byKey.params]
|
|
592
|
+
};
|
|
593
|
+
}, "where")
|
|
594
|
+
}
|
|
595
|
+
}), "projectTaskColumns");
|
|
596
|
+
var PROJECT_SCOPE = `t.deleted_at IS NULL AND t.project_id IN (${OWNER_PROJECTS})`;
|
|
597
|
+
var BOARD_SCOPE = "t.deleted_at IS NULL AND t.project_id IN (SELECT id FROM projects WHERE deleted_at IS NULL)";
|
|
598
|
+
var STATE_ORDER = `CASE t.status ${TASK_STATES.map((state, at) => `WHEN '${state}' THEN ${at}`).join(" ")} END`;
|
|
599
|
+
var boardOrder = /* @__PURE__ */ __name((sort, descending) => {
|
|
600
|
+
const direction = descending ? "DESC" : "ASC";
|
|
601
|
+
const first = {
|
|
602
|
+
priority: ["t.priority_score IS NULL", `t.priority_score ${descending ? "ASC" : "DESC"}`],
|
|
603
|
+
due: ["t.due_at IS NULL", `t.due_at ${direction}`],
|
|
604
|
+
created: [`t.created_at ${direction}`],
|
|
605
|
+
updated: [`t.updated_at ${direction}`],
|
|
606
|
+
key: [`(SELECT key FROM projects WHERE id = t.project_id) ${direction}`, `t.number ${direction}`],
|
|
607
|
+
state: [`${STATE_ORDER} ${direction}`]
|
|
608
|
+
}[sort];
|
|
609
|
+
return [...first, "t.priority_score IS NULL", "t.priority_score DESC", "t.created_at", "t.id"].join(", ");
|
|
610
|
+
}, "boardOrder");
|
|
611
|
+
var withoutField = /* @__PURE__ */ __name((query, name) => {
|
|
612
|
+
if (query === void 0)
|
|
613
|
+
return void 0;
|
|
614
|
+
const strip = /* @__PURE__ */ __name((node) => {
|
|
615
|
+
if (walkQuery(node).every((leaf) => leaf.field === name))
|
|
616
|
+
return void 0;
|
|
617
|
+
if (node.kind === "predicate" || node.clauses.some((clause) => clause.occur === "should"))
|
|
618
|
+
return node;
|
|
619
|
+
const clauses = node.clauses.flatMap((clause) => {
|
|
620
|
+
const kept = strip(clause.node);
|
|
621
|
+
return kept === void 0 ? [] : [{ ...clause, node: kept }];
|
|
622
|
+
});
|
|
623
|
+
return clauses.length === 0 ? void 0 : { ...node, clauses };
|
|
624
|
+
}, "strip");
|
|
625
|
+
const root = strip(query.root);
|
|
626
|
+
return root === void 0 ? void 0 : { ...query, root };
|
|
627
|
+
}, "withoutField");
|
|
628
|
+
var TASK_PEOPLE = `WITH merged AS (SELECT json_extract(value, '$[0]') AS id, json_extract(value, '$[1]') AS now FROM json_each(?)), counts AS (SELECT coalesce(m.now, a.assignee_id) AS person, count(DISTINCT t.id) AS n FROM task_assignments a JOIN tasks t ON t.id = a.task_id AND t.deleted_at IS NULL LEFT JOIN merged m ON m.id = a.assignee_id WHERE a.assignee_type = 'person' GROUP BY 1) SELECT p.id, p.name, p.owner, coalesce(c.n, 0) AS n FROM persons p LEFT JOIN counts c ON c.person = p.id WHERE NOT ${mergedAwaySql("p")} ORDER BY p.owner DESC, n DESC, p.name IS NULL, p.name COLLATE NOCASE, p.id LIMIT ?`;
|
|
629
|
+
var mergedAssignees = /* @__PURE__ */ __name((database) => JSON.stringify(database.prepare(`SELECT DISTINCT a.assignee_id AS id FROM task_assignments a JOIN persons p ON p.id = a.assignee_id WHERE a.assignee_type = 'person' AND ${mergedAwaySql("p")}`).all().map(({ id }) => [Number(id), currentPerson(database, Number(id))])), "mergedAssignees");
|
|
630
|
+
|
|
631
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/store/sqlite/person-ties.js
|
|
632
|
+
var SMALL_GROUP_MEMBERS = 10;
|
|
633
|
+
var PERSON_TIES = ["chat", "small-group", "mail", "meeting", "crm", "phone-book"];
|
|
634
|
+
var ALWAYS_SHOWN = ["owner", "added", "task"];
|
|
635
|
+
var crmProviders = /* @__PURE__ */ __name(() => providers().filter((entry) => kindsOfEntry(entry).includes("crm")).map(({ name }) => name), "crmProviders");
|
|
636
|
+
var quoted = /* @__PURE__ */ __name((value) => `'${value.replaceAll("'", "''")}'`, "quoted");
|
|
637
|
+
var GROUP_SIZE = "coalesce(c.participants_count, (SELECT mc.listed_count FROM member_counts mc WHERE mc.chat_id = c.id ORDER BY mc.date DESC LIMIT 1))";
|
|
638
|
+
var chatPeople = /* @__PURE__ */ __name((where, few) => {
|
|
639
|
+
const members = `SELECT m.identity_id FROM chats c JOIN chat_members m ON m.chat_id = c.id WHERE ${where}`;
|
|
640
|
+
if (few)
|
|
641
|
+
return `(l.identity_id IN (${members}) OR EXISTS (SELECT 1 FROM messages s JOIN chats c ON c.id = s.chat_id WHERE s.sender_identity_id = l.identity_id AND s.outgoing IS NOT 1 AND ${where}))`;
|
|
642
|
+
return `l.identity_id IN (${members} UNION SELECT s.sender_identity_id FROM chats c JOIN messages s ON s.chat_id = c.id WHERE ${where} AND s.sender_identity_id IS NOT NULL AND s.outgoing IS NOT 1)`;
|
|
643
|
+
}, "chatPeople");
|
|
644
|
+
var among = /* @__PURE__ */ __name((identities) => `l.identity_id IN (${identities})`, "among");
|
|
645
|
+
var OWNERS_CRM_PEOPLE = "SELECT id FROM persons WHERE owner = 1 UNION SELECT e.from_person_id FROM identity_link_events e JOIN identity_links l ON l.identity_id = e.identity_id JOIN persons p ON p.id = l.person_id AND p.owner = 1";
|
|
646
|
+
var crmTie = /* @__PURE__ */ __name((crm) => {
|
|
647
|
+
if (crm.length === 0)
|
|
648
|
+
return "SELECT NULL WHERE 0";
|
|
649
|
+
const providers2 = crm.map(quoted).join(", ");
|
|
650
|
+
const contacts = `SELECT d.to_id FROM links d JOIN links o ON o.from_type = d.from_type AND o.from_id = d.from_id AND o.kind = 'related-to' AND o.role = 'owner' AND o.to_type = 'person' AND o.deleted_at IS NULL WHERE d.from_type IN ('deal', 'lead') AND d.kind = 'related-to' AND d.to_type = 'person' AND d.role IS NOT 'owner' AND d.deleted_at IS NULL AND o.to_id IN (${OWNERS_CRM_PEOPLE})`;
|
|
651
|
+
return `SELECT id FROM identities WHERE provider IN (${providers2}) AND external_id LIKE '%/user/%' UNION SELECT l.identity_id FROM identity_links l WHERE l.person_id IN (${contacts}) UNION SELECT e.identity_id FROM identity_link_events e WHERE e.from_person_id IN (${contacts}) AND ${mergeSql("e")}`;
|
|
652
|
+
}, "crmTie");
|
|
653
|
+
var tieIdentities = /* @__PURE__ */ __name((few) => {
|
|
654
|
+
const crm = crmProviders();
|
|
655
|
+
return {
|
|
656
|
+
chat: chatPeople("c.kind = 'dialog'", few),
|
|
657
|
+
"small-group": chatPeople(`c.kind = 'group' AND ${GROUP_SIZE} <= ${SMALL_GROUP_MEMBERS}`, few),
|
|
658
|
+
// NEED-2342 A: the owner wrote to them; mail they sent, a newsletter included, is no tie.
|
|
659
|
+
mail: among("SELECT r.identity_id FROM emails e JOIN email_recipients r ON r.email_id = e.id WHERE e.outgoing = 1 AND e.deleted_at IS NULL AND e.draft IS NOT 1 AND r.identity_id IS NOT NULL"),
|
|
660
|
+
meeting: among("SELECT identity_id FROM meeting_participants UNION ALL SELECT identity_id FROM calendar_entry_participants WHERE resource = 0 AND identity_id IS NOT NULL"),
|
|
661
|
+
crm: among(crmTie(crm)),
|
|
662
|
+
"phone-book": among("SELECT identity_id FROM account_identities WHERE address_book = 1")
|
|
663
|
+
};
|
|
664
|
+
}, "tieIdentities");
|
|
665
|
+
var reasonRows = /* @__PURE__ */ __name((only) => [
|
|
666
|
+
...Object.entries(tieIdentities(only !== "")).map(([tie, holds]) => `SELECT l.person_id AS person, '${tie}' AS tie FROM identity_links l WHERE ${holds}${only}`),
|
|
667
|
+
"SELECT entity_id, 'crm' FROM records WHERE entity_type = 'person' AND deleted_at IS NULL AND entity_id IS NOT NULL",
|
|
668
|
+
"SELECT id, 'owner' FROM persons WHERE owner = 1",
|
|
669
|
+
`SELECT p.id, 'added' FROM persons p WHERE NOT EXISTS (SELECT 1 FROM identity_links l WHERE l.person_id = p.id) AND NOT ${mergedAwaySql("p")}`,
|
|
670
|
+
"SELECT coalesce(json_extract(m.value, '$[1]'), a.assignee_id), 'task' FROM task_assignments a JOIN tasks t ON t.id = a.task_id AND t.deleted_at IS NULL LEFT JOIN json_each(?) m ON json_extract(m.value, '$[0]') = a.assignee_id WHERE a.assignee_type = 'person'"
|
|
671
|
+
].join(" UNION ALL "), "reasonRows");
|
|
672
|
+
var ORDER = [...ALWAYS_SHOWN, ...PERSON_TIES];
|
|
673
|
+
var shownReasons = /* @__PURE__ */ __name((database, people) => {
|
|
674
|
+
const found = /* @__PURE__ */ new Map();
|
|
675
|
+
const scoped = people !== void 0;
|
|
676
|
+
const sql = scoped ? `WITH only(id) AS (SELECT value FROM json_each(?)) SELECT DISTINCT person, tie FROM (${reasonRows(" AND l.person_id IN (SELECT id FROM only)")}) WHERE person IN (SELECT id FROM only)` : `SELECT DISTINCT person, tie FROM (${reasonRows("")})`;
|
|
677
|
+
for (const row of database.prepare(sql).all(...scoped ? [JSON.stringify(people)] : [], mergedAssignees(database))) {
|
|
678
|
+
const person = Number(row.person);
|
|
679
|
+
const reasons = found.get(person) ?? /* @__PURE__ */ new Set();
|
|
680
|
+
reasons.add(row.tie);
|
|
681
|
+
found.set(person, reasons);
|
|
682
|
+
}
|
|
683
|
+
return new Map([...found].map(([person, reasons]) => [person, ORDER.filter((one) => reasons.has(one))]));
|
|
684
|
+
}, "shownReasons");
|
|
685
|
+
|
|
686
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/domain/addresses.js
|
|
687
|
+
var EMAIL_ADDRESS = /^[^\s@]+@[^\s@]+\.[^\s@]+$/u;
|
|
688
|
+
var isEmailAddress = /* @__PURE__ */ __name((value) => EMAIL_ADDRESS.test(value), "isEmailAddress");
|
|
689
|
+
var ROLE_ADDRESS_WORDS = {
|
|
690
|
+
noReply: ["noreply", "no-reply", "donotreply", "do-not-reply", "mailer-daemon", "bounce", "bounces"],
|
|
691
|
+
shared: [
|
|
692
|
+
"info",
|
|
693
|
+
"hello",
|
|
694
|
+
"hi",
|
|
695
|
+
"contact",
|
|
696
|
+
"contacts",
|
|
697
|
+
"support",
|
|
698
|
+
"help",
|
|
699
|
+
"helpdesk",
|
|
700
|
+
"service",
|
|
701
|
+
"sales",
|
|
702
|
+
"office",
|
|
703
|
+
"admin",
|
|
704
|
+
"team",
|
|
705
|
+
"billing",
|
|
706
|
+
"accounts",
|
|
707
|
+
"accounting",
|
|
708
|
+
"invoices",
|
|
709
|
+
"finance",
|
|
710
|
+
"hr",
|
|
711
|
+
"jobs",
|
|
712
|
+
"careers",
|
|
713
|
+
"press",
|
|
714
|
+
"media",
|
|
715
|
+
"marketing",
|
|
716
|
+
"partners",
|
|
717
|
+
"legal",
|
|
718
|
+
"privacy",
|
|
719
|
+
"security",
|
|
720
|
+
"abuse",
|
|
721
|
+
"postmaster",
|
|
722
|
+
"webmaster",
|
|
723
|
+
"mail",
|
|
724
|
+
"inbox",
|
|
725
|
+
"enquiries",
|
|
726
|
+
"inquiries",
|
|
727
|
+
"booking",
|
|
728
|
+
"reservations",
|
|
729
|
+
"orders",
|
|
730
|
+
"feedback",
|
|
731
|
+
"newsletter",
|
|
732
|
+
"notifications",
|
|
733
|
+
"alerts"
|
|
734
|
+
]
|
|
735
|
+
};
|
|
736
|
+
var bare = /* @__PURE__ */ __name((word) => word.replace(/[.\-_]/gu, ""), "bare");
|
|
737
|
+
var NO_REPLY = new Set(ROLE_ADDRESS_WORDS.noReply.map(bare));
|
|
738
|
+
var ROLE = new Set([...ROLE_ADDRESS_WORDS.shared, ...ROLE_ADDRESS_WORDS.noReply].map(bare));
|
|
739
|
+
var PART_ONLY = /* @__PURE__ */ new Set(["bounce", "bounces"]);
|
|
740
|
+
var NOTIFY = /* @__PURE__ */ new Set(["notify", "notification", "notifications", "alert", "alerts"]);
|
|
741
|
+
var localPart = /* @__PURE__ */ __name((address) => {
|
|
742
|
+
const local2 = address.trim().toLowerCase().split("@")[0] ?? "";
|
|
743
|
+
return local2.split("+")[0] ?? "";
|
|
744
|
+
}, "localPart");
|
|
745
|
+
var localWord = /* @__PURE__ */ __name((address) => bare(localPart(address)), "localWord");
|
|
746
|
+
var SEPARATORS2 = /[.\-_]/u;
|
|
747
|
+
var partsOf = /* @__PURE__ */ __name((address) => localPart(address).split(SEPARATORS2), "partsOf");
|
|
748
|
+
var NO_REPLY_PARTS = ROLE_ADDRESS_WORDS.noReply.map((word) => `.${word.split(SEPARATORS2).join(".")}.`);
|
|
749
|
+
var isNoReplyAddress = /* @__PURE__ */ __name((address) => {
|
|
750
|
+
const word = localWord(address);
|
|
751
|
+
const parts = `.${partsOf(address).join(".")}.`;
|
|
752
|
+
if (NO_REPLY_PARTS.some((one) => parts.includes(one)))
|
|
753
|
+
return true;
|
|
754
|
+
return [...NO_REPLY].some((one) => !PART_ONLY.has(one) && (word.startsWith(one) || word.endsWith(one)));
|
|
755
|
+
}, "isNoReplyAddress");
|
|
756
|
+
var isRoleAddress = /* @__PURE__ */ __name((address) => ROLE.has(localWord(address)) || isNoReplyAddress(address), "isRoleAddress");
|
|
757
|
+
var PERSON_LIKE = /* @__PURE__ */ new Set(["hr"]);
|
|
758
|
+
var isPersonLikeRoleAddress = /* @__PURE__ */ __name((address) => PERSON_LIKE.has(localWord(address)), "isPersonLikeRoleAddress");
|
|
759
|
+
var isNotificationAddress = /* @__PURE__ */ __name((address) => partsOf(address).some((part) => NOTIFY.has(part)), "isNotificationAddress");
|
|
760
|
+
|
|
761
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/store/sqlite/sender-signals.js
|
|
762
|
+
var REACHES = ["direct", "group", "broadcast"];
|
|
763
|
+
var DISCUSSION_SENDERS = 3;
|
|
764
|
+
var reachOfOne = /* @__PURE__ */ __name((mail) => {
|
|
765
|
+
if (mail.discussionList)
|
|
766
|
+
return { reach: "group", signal: "discussion-list" };
|
|
767
|
+
if (mail.oneClick)
|
|
768
|
+
return { reach: "broadcast", signal: "one-click-unsubscribe" };
|
|
769
|
+
if (mail.feedbackId)
|
|
770
|
+
return { reach: "broadcast", signal: "feedback-id" };
|
|
771
|
+
if (mail.bulk)
|
|
772
|
+
return { reach: "broadcast", signal: "bulk-mail" };
|
|
773
|
+
if (mail.recipients === 0)
|
|
774
|
+
return { reach: "broadcast", signal: "undisclosed-recipients" };
|
|
775
|
+
if (mail.recipients !== null && mail.recipients > SMALL_GROUP_MEMBERS)
|
|
776
|
+
return { reach: "group", signal: "many-recipients" };
|
|
777
|
+
return { reach: "direct" };
|
|
778
|
+
}, "reachOfOne");
|
|
779
|
+
var most = /* @__PURE__ */ __name((mail, holds) => mail.filter(holds).length * 2 > mail.length, "most");
|
|
780
|
+
var senderSignalsOf = /* @__PURE__ */ __name((mail, { addresses, ownerWrote, chatted }) => {
|
|
781
|
+
const signals = /* @__PURE__ */ new Set();
|
|
782
|
+
if (mail.length > 0 && most(mail, (one) => one.autoSubmitted))
|
|
783
|
+
signals.add("auto-submitted");
|
|
784
|
+
if (mail.length > 0 && most(mail, (one) => one.nullReturnPath))
|
|
785
|
+
signals.add("null-return-path");
|
|
786
|
+
if (addresses.some(isNoReplyAddress))
|
|
787
|
+
signals.add("no-reply");
|
|
788
|
+
const votes = /* @__PURE__ */ new Map();
|
|
789
|
+
for (const one of mail) {
|
|
790
|
+
const { reach: reach2, signal } = reachOfOne(one);
|
|
791
|
+
votes.set(reach2, (votes.get(reach2) ?? 0) + 1);
|
|
792
|
+
if (signal !== void 0)
|
|
793
|
+
signals.add(signal);
|
|
794
|
+
}
|
|
795
|
+
const voted = [...REACHES].reverse().reduce((best, reach2) => {
|
|
796
|
+
const n = votes.get(reach2) ?? 0;
|
|
797
|
+
return n > 0 && (best === null || n > (votes.get(best) ?? 0)) ? reach2 : best;
|
|
798
|
+
}, null);
|
|
799
|
+
const reach = ownerWrote ? "direct" : voted ?? (chatted ? "direct" : null);
|
|
800
|
+
return { signals: [...signals], reach };
|
|
801
|
+
}, "senderSignalsOf");
|
|
802
|
+
var LIST_ID = `coalesce(json_extract(e.headers, '$."list-id"'), json_extract(e.metadata, '$.listId'))`;
|
|
803
|
+
var LIST_SENDERS = `SELECT DISTINCT ${LIST_ID} AS list, e.from_address AS address FROM emails e WHERE e.from_address IS NOT NULL AND ${LIST_ID} IN (SELECT value FROM json_each(?))`;
|
|
804
|
+
var senderKey = /* @__PURE__ */ __name((address) => address.toLowerCase().replace(/\+[^@]*@/, "@"), "senderKey");
|
|
805
|
+
var sentMailOf = /* @__PURE__ */ __name((database, people, holder = "person") => {
|
|
806
|
+
const found = /* @__PURE__ */ new Map();
|
|
807
|
+
if (people.length === 0)
|
|
808
|
+
return found;
|
|
809
|
+
const held = holder === "person" ? { owner: "l.person_id", join: "identity_links l" } : { owner: "l.bot_id", join: "sender_bot_identities l" };
|
|
810
|
+
const rows = database.prepare(`SELECT ${held.owner} AS person, ${LIST_ID} AS list, json_extract(e.headers, '$."auto-submitted"') IS NOT NULL AS auto, json_extract(e.headers, '$."null-return-path"') IS 1 AS null_return, json_extract(e.headers, '$."list-unsubscribe-post"') IS 1 AS one_click, json_extract(e.headers, '$."feedback-id"') IS 1 AS feedback, EXISTS (SELECT 1 FROM email_mailboxes m JOIN mailboxes b ON b.id = m.mailbox_id WHERE m.email_id = e.id AND b.kind = 'bulk') AS bulk, CASE WHEN json_extract(e.metadata, '$.rule') IS NOT NULL THEN NULL ELSE (SELECT count(*) FROM email_recipients r WHERE r.email_id = e.id AND r.role IN ('to', 'cc')) END AS recipients FROM emails e JOIN ${held.join} ON l.identity_id = e.from_identity_id WHERE e.outgoing IS NOT 1 AND e.deleted_at IS NULL AND ${held.owner} IN (SELECT value FROM json_each(?))`).all(JSON.stringify(people));
|
|
811
|
+
const lists = [...new Set(rows.flatMap((row) => typeof row.list === "string" ? [row.list] : []))];
|
|
812
|
+
const senders = /* @__PURE__ */ new Map();
|
|
813
|
+
if (lists.length > 0)
|
|
814
|
+
for (const row of database.prepare(LIST_SENDERS).all(JSON.stringify(lists))) {
|
|
815
|
+
const list = String(row.list);
|
|
816
|
+
const held2 = senders.get(list) ?? /* @__PURE__ */ new Set();
|
|
817
|
+
held2.add(senderKey(String(row.address)));
|
|
818
|
+
senders.set(list, held2);
|
|
819
|
+
}
|
|
820
|
+
for (const row of rows) {
|
|
821
|
+
const person = Number(row.person);
|
|
822
|
+
const held2 = found.get(person) ?? [];
|
|
823
|
+
held2.push({
|
|
824
|
+
autoSubmitted: Number(row.auto) === 1,
|
|
825
|
+
nullReturnPath: Number(row.null_return) === 1,
|
|
826
|
+
oneClick: Number(row.one_click) === 1,
|
|
827
|
+
feedbackId: Number(row.feedback) === 1,
|
|
828
|
+
bulk: Number(row.bulk) === 1,
|
|
829
|
+
discussionList: typeof row.list === "string" && (senders.get(row.list)?.size ?? 0) >= DISCUSSION_SENDERS,
|
|
830
|
+
recipients: row.recipients == null ? null : Number(row.recipients)
|
|
831
|
+
});
|
|
832
|
+
found.set(person, held2);
|
|
833
|
+
}
|
|
834
|
+
return found;
|
|
835
|
+
}, "sentMailOf");
|
|
836
|
+
|
|
837
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/search/fusion.js
|
|
838
|
+
var RRF_K = 60;
|
|
839
|
+
var fuseRanked = /* @__PURE__ */ __name((lists, facts) => {
|
|
840
|
+
const rows = lists.flatMap((list) => list.map((item, rank) => ({ item, vote: 1 / (RRF_K + rank + 1), ...facts(item) })));
|
|
841
|
+
const ranking = rows.some(({ ranked }) => ranked);
|
|
842
|
+
return rows.sort((a, b) => Number(b.exact === true) - Number(a.exact === true) || (ranking ? Number(b.ranked) - Number(a.ranked) || b.vote - a.vote : 0) || b.at - a.at).map(({ item }) => item);
|
|
843
|
+
}, "fuseRanked");
|
|
844
|
+
|
|
845
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/search/lucene/types.js
|
|
846
|
+
var QUERY_VERSION = 1;
|
|
847
|
+
var QUERY_LIMITS2 = {
|
|
848
|
+
...QUERY_LIMITS,
|
|
849
|
+
pattern: 1024,
|
|
850
|
+
states: 1e4,
|
|
851
|
+
expansions: 1e4,
|
|
852
|
+
candidates: 5e4,
|
|
853
|
+
bodyBytes: 8388608,
|
|
854
|
+
milliseconds: 2e3,
|
|
855
|
+
work: 1e7
|
|
856
|
+
};
|
|
857
|
+
var SEARCH_QUERY = {
|
|
858
|
+
command: "search",
|
|
859
|
+
guide: "https://github.com/WireCatLabs/cli-core/blob/main/docs/search/query-language.md"
|
|
860
|
+
};
|
|
861
|
+
var MESSAGE_PARSING = { ...SEARCH_QUERY, proximity: true };
|
|
862
|
+
var MOST_WORDS_APART = 50;
|
|
863
|
+
function searchError(reason, span, alternative) {
|
|
864
|
+
queryError(reason, span, alternative, SEARCH_QUERY);
|
|
865
|
+
}
|
|
866
|
+
__name(searchError, "searchError");
|
|
867
|
+
var ANSWER_MS = 1e3;
|
|
868
|
+
var searchTimeLimit = /* @__PURE__ */ __name((deadline, now = Date.now()) => deadline?.explicit ? Math.max(QUERY_LIMITS2.milliseconds, deadline.endsAt - now - ANSWER_MS) : void 0, "searchTimeLimit");
|
|
869
|
+
function outOfTime(limitMs = QUERY_LIMITS2.milliseconds) {
|
|
870
|
+
throw new CliError("timeout", `search stopped at its time limit of ${limitMs / 1e3}s \u2014 the query is valid; add chat: or date: to search less of the store`, { reason: "query.time-limit", budget: "time", limit_ms: limitMs, complete: false });
|
|
871
|
+
}
|
|
872
|
+
__name(outOfTime, "outOfTime");
|
|
873
|
+
var isQueryLimit = /* @__PURE__ */ __name((error) => isCliError(error) && (error.details.reason === "query.too-large" || error.details.reason === "query.time-limit"), "isQueryLimit");
|
|
874
|
+
var SQLITE_TOO_LARGE = /nested too deep|too many terms in compound SELECT|Expression tree is too large|parser stack overflow/;
|
|
875
|
+
var sqliteLimit = /* @__PURE__ */ __name((error) => {
|
|
876
|
+
if (error instanceof Error && SQLITE_TOO_LARGE.test(error.message))
|
|
877
|
+
exhausted("nodes");
|
|
878
|
+
return error;
|
|
879
|
+
}, "sqliteLimit");
|
|
880
|
+
function exhausted(budget) {
|
|
881
|
+
throw new CliError("validation_error", `search exceeded its ${budget} budget \u2014 narrow the chat or date range`, {
|
|
882
|
+
reason: "query.too-large",
|
|
883
|
+
budget,
|
|
884
|
+
complete: false
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
__name(exhausted, "exhausted");
|
|
888
|
+
function tooWideTerm([term], budget) {
|
|
889
|
+
if (term === void 0)
|
|
890
|
+
exhausted(budget);
|
|
891
|
+
const part = term.replace(/[*?]+/gu, " ").trim().split(/\s+/u).sort((a, b) => b.length - a.length)[0] ?? term;
|
|
892
|
+
throw new CliError("validation_error", `search exceeded its ${budget} budget: ${term} is checked word by word, and too many messages hold it \u2014 write *${part}* (any word holding it, read from the index), more of the word, or add chat: or date:`, { reason: "query.too-large", budget, term, complete: false });
|
|
893
|
+
}
|
|
894
|
+
__name(tooWideTerm, "tooWideTerm");
|
|
895
|
+
|
|
896
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/mail/mail-types.js
|
|
897
|
+
var MAIL_TYPES = [
|
|
898
|
+
"auto_reply",
|
|
899
|
+
"security",
|
|
900
|
+
"calendar",
|
|
901
|
+
"travel",
|
|
902
|
+
"event_ticket",
|
|
903
|
+
"order",
|
|
904
|
+
"shipping",
|
|
905
|
+
"bill",
|
|
906
|
+
"social_notification",
|
|
907
|
+
"discussion_list",
|
|
908
|
+
"newsletter",
|
|
909
|
+
"promotion",
|
|
910
|
+
"system_alert",
|
|
911
|
+
"account_notice",
|
|
912
|
+
"personal",
|
|
913
|
+
"other"
|
|
914
|
+
];
|
|
915
|
+
var AUTOMATED_SENDER = /^(no-?reply|do-?not-?reply|donotreply|notifications?|notify|alerts?|mailer-daemon|postmaster|bounces?|automated|system|accounts?|security|billing|receipts?|orders?|shipping|support|service|updates?)([+._-].*)?@/i;
|
|
916
|
+
var MARKETING_SENDER = /^(news(letters?)?|marketing|promo(tions?)?|offers?|deals?|sales|hello|hi|team|info|digest)([+._-].*)?@/i;
|
|
917
|
+
var local = /* @__PURE__ */ __name((words2) => new RegExp(`^(${words2})([+._-].*)?@`, "i"), "local");
|
|
918
|
+
var MAILER_DAEMON = local("mailer-daemon|postmaster");
|
|
919
|
+
var SECURITY_SENDER = local("security|account-?security|verify|verification|auth|2fa|otp|login|signin|password");
|
|
920
|
+
var ORDER_SENDER = local("orders?|receipts?|order-?confirm(ation)?|purchases?");
|
|
921
|
+
var SHIPPING_SENDER = local("shipping|shipments?|tracking|deliver(y|ies)|dispatch");
|
|
922
|
+
var BILL_SENDER = local("billing|invoices?|payments?|statements?");
|
|
923
|
+
var ALERT_SENDER = local("alerts?|alertmanager|monitoring|monitor|cron|root|ci|builds?|jenkins|nagios|zabbix|sentry");
|
|
924
|
+
var NEWS_SENDER = local("news(letters?)?|digest|editors?|weekly");
|
|
925
|
+
var AUTO_REPLY_SUBJECT = /^(auto(matic)?[ -]?(reply|response)|out of (the )?office|abwesenheit|réponse automatique|respuesta automática|автоответ|автоматический ответ|undeliverable|undelivered mail|delivery status notification|mail delivery (failed|subsystem)|returned mail|failure notice|не доставлено)/iu;
|
|
926
|
+
var SECURITY_SUBJECT = /\b(verification code|security code|one[- ]time (pass)?code|sign[- ]?in (attempt|alert|code)|new (sign[- ]?in|login|device)|log[- ]?in (attempt|alert|code)|password (reset|change)|reset your password|two[- ]factor|2-step|confirm your (email|account)|verify your (email|account|identity))\b|код (подтверждения|для входа|безопасности)|вход в (аккаунт|учётную|учетную)|сброс пароля|código de (verificación|seguridad|acceso)|restablecer (tu |la )?contraseña|inicio de sesión/iu;
|
|
927
|
+
var TRAVEL_SUBJECT = /\b(boarding pass|e-?ticket|itinerary|flight (confirmation|booking|reservation)|booking confirm(ation|ed)|check[- ]in (now|is open|online))\b|посадочный талон|маршрутная квитанция|tarjeta de embarque|confirmación de (reserva|vuelo)/iu;
|
|
928
|
+
var EVENT_SUBJECT = /\b(your tickets?|ticket confirmation|tickets? for)\b|билеты? на|tus entradas|entradas para/iu;
|
|
929
|
+
var ORDER_SUBJECT = /\b(order (confirmation|confirmed|received|#|no\.?|number)|your order|thank(s| you) for your (order|purchase)|purchase confirmation|your receipt|receipt for|payment receipt)\b|ваш заказ|заказ (№|#|оформлен|принят)|tu pedido|confirmación de (pedido|compra)/iu;
|
|
930
|
+
var SHIPPING_SUBJECT = /\b(has (been )?shipped|out for delivery|has been delivered|on (its|the) way|tracking (number|info)|track your (order|package|parcel)|shipment|dispatched)\b|отправлен|доставлен|посылк|tu (pedido|paquete) (ha sido enviado|está en camino)|en camino/iu;
|
|
931
|
+
var BILL_SUBJECT = /\b(invoice|statement (is )?(ready|available)|your (monthly |account )?statement|payment (due|reminder|received|confirmation|failed)|bill (is )?(ready|due)|your bill)\b|сч[её]т (на оплату|№|#)|выписка|квитанция|factura|extracto|recibo de pago/iu;
|
|
932
|
+
var ALERT_SUBJECT = /^\[(firing|resolved|alert)|\b(build (failed|passed|fixed|broken)|pipeline (failed|succeeded)|cron <|is down|downtime)\b/iu;
|
|
933
|
+
var PROMOTION_SUBJECT = /\d+\s?%|\b(sale|discount|deals?|offers?|coupon|promo(code)?|free shipping|black friday|cyber monday|limited time|last chance)\b|скидк|распродаж|промокод|descuento|oferta|rebajas|cupón/iu;
|
|
934
|
+
var NEWS_SUBJECT = /\b(newsletter|digest|weekly|monthly|issue\s?#?\d+|edition)\b|рассылка|дайджест|boletín/iu;
|
|
935
|
+
var REPORT_PARTS = /* @__PURE__ */ new Set(["message/delivery-status", "message/disposition-notification"]);
|
|
936
|
+
var CALENDAR_PARTS = /* @__PURE__ */ new Set(["text/calendar", "application/ics"]);
|
|
937
|
+
var TRAVEL_SCHEMA = /^(Flight|Train|Bus|Lodging|RentalCar|Taxi|Boat)Reservation$/;
|
|
938
|
+
var schemaOf = /* @__PURE__ */ __name((types, wanted) => types.find((one) => typeof wanted === "string" ? one === wanted : wanted.test(one)), "schemaOf");
|
|
939
|
+
var mailTypeOf = /* @__PURE__ */ __name((input) => {
|
|
940
|
+
const { headers } = input;
|
|
941
|
+
const from = input.from ?? "";
|
|
942
|
+
const subject = input.subject ?? "";
|
|
943
|
+
const oneClick = headers["list-unsubscribe-post"] === true;
|
|
944
|
+
const feedbackId = headers["feedback-id"] === true;
|
|
945
|
+
const listUnsubscribe = headers["list-unsubscribe"] === true;
|
|
946
|
+
const listId = typeof headers["list-id"] === "string";
|
|
947
|
+
const precedence = typeof headers.precedence === "string" ? headers.precedence : "";
|
|
948
|
+
const bulkPrecedence = precedence === "bulk" || precedence === "junk";
|
|
949
|
+
const autoSubmitted = headers["auto-submitted"] !== void 0;
|
|
950
|
+
const discussion = listId ? input.listSenders >= DISCUSSION_SENDERS : precedence === "list" && !feedbackId && !MARKETING_SENDER.test(from);
|
|
951
|
+
const mass = listUnsubscribe || bulkPrecedence || listId || oneClick;
|
|
952
|
+
const transactional = !mass && !feedbackId;
|
|
953
|
+
const noReply = from !== "" && isNoReplyAddress(from);
|
|
954
|
+
const person = input.ownerWrote && !input.bot;
|
|
955
|
+
const trusted = headers.dmarc !== "fail" && headers.dkim !== "fail";
|
|
956
|
+
const weak = !person && !oneClick && !listId;
|
|
957
|
+
const reach = reachOfOne({
|
|
958
|
+
autoSubmitted,
|
|
959
|
+
nullReturnPath: headers["null-return-path"] === true,
|
|
960
|
+
oneClick,
|
|
961
|
+
feedbackId,
|
|
962
|
+
bulk: mass || precedence === "list",
|
|
963
|
+
discussionList: discussion,
|
|
964
|
+
recipients: input.recipients
|
|
965
|
+
}).reach;
|
|
966
|
+
const typed = /* @__PURE__ */ __name((type, signal) => ({ type, reach, signal }), "typed");
|
|
967
|
+
const schema = /* @__PURE__ */ __name((wanted) => schemaOf(input.schemaTypes, wanted), "schema");
|
|
968
|
+
const report = input.parts.find((part) => REPORT_PARTS.has(part));
|
|
969
|
+
if (report !== void 0)
|
|
970
|
+
return typed("auto_reply", report);
|
|
971
|
+
if (MAILER_DAEMON.test(from))
|
|
972
|
+
return typed("auto_reply", "mailer-daemon");
|
|
973
|
+
if (!mass && AUTO_REPLY_SUBJECT.test(subject))
|
|
974
|
+
return typed("auto_reply", "auto-reply-subject");
|
|
975
|
+
if (weak && trusted && SECURITY_SENDER.test(from))
|
|
976
|
+
return typed("security", "security-address");
|
|
977
|
+
if (weak && trusted && SECURITY_SUBJECT.test(subject))
|
|
978
|
+
return typed("security", "security-subject");
|
|
979
|
+
const calendar = input.parts.find((part) => CALENDAR_PARTS.has(part));
|
|
980
|
+
if (calendar !== void 0)
|
|
981
|
+
return typed("calendar", calendar);
|
|
982
|
+
const travel = schema(TRAVEL_SCHEMA);
|
|
983
|
+
if (travel !== void 0)
|
|
984
|
+
return typed("travel", `schema:${travel}`);
|
|
985
|
+
if (weak && TRAVEL_SUBJECT.test(subject))
|
|
986
|
+
return typed("travel", "travel-subject");
|
|
987
|
+
if (weak && transactional && input.sector === "airline")
|
|
988
|
+
return typed("travel", "sector:airline");
|
|
989
|
+
if (schema("EventReservation") !== void 0)
|
|
990
|
+
return typed("event_ticket", "schema:EventReservation");
|
|
991
|
+
if (weak && EVENT_SUBJECT.test(subject))
|
|
992
|
+
return typed("event_ticket", "ticket-subject");
|
|
993
|
+
if (schema("Order") !== void 0)
|
|
994
|
+
return typed("order", "schema:Order");
|
|
995
|
+
if (weak && ORDER_SENDER.test(from))
|
|
996
|
+
return typed("order", "order-address");
|
|
997
|
+
if (weak && ORDER_SUBJECT.test(subject) && !SHIPPING_SUBJECT.test(subject))
|
|
998
|
+
return typed("order", "order-subject");
|
|
999
|
+
if (schema("ParcelDelivery") !== void 0)
|
|
1000
|
+
return typed("shipping", "schema:ParcelDelivery");
|
|
1001
|
+
if (weak && SHIPPING_SENDER.test(from))
|
|
1002
|
+
return typed("shipping", "shipping-address");
|
|
1003
|
+
if (weak && SHIPPING_SUBJECT.test(subject))
|
|
1004
|
+
return typed("shipping", "shipping-subject");
|
|
1005
|
+
if (weak && transactional && input.sector === "delivery")
|
|
1006
|
+
return typed("shipping", "sector:delivery");
|
|
1007
|
+
if (schema("Invoice") !== void 0)
|
|
1008
|
+
return typed("bill", "schema:Invoice");
|
|
1009
|
+
if (weak && BILL_SENDER.test(from))
|
|
1010
|
+
return typed("bill", "bill-address");
|
|
1011
|
+
if (weak && BILL_SUBJECT.test(subject))
|
|
1012
|
+
return typed("bill", "bill-subject");
|
|
1013
|
+
if (!person && input.sector === "social")
|
|
1014
|
+
return typed("social_notification", "sector:social");
|
|
1015
|
+
if (discussion)
|
|
1016
|
+
return typed("discussion_list", listId ? "discussion-list" : "precedence-list");
|
|
1017
|
+
const automated = AUTOMATED_SENDER.test(from) && !MARKETING_SENDER.test(from);
|
|
1018
|
+
if (listUnsubscribe && !oneClick && !feedbackId && !bulkPrecedence && automated)
|
|
1019
|
+
return typed("account_notice", "automated-address");
|
|
1020
|
+
if (mass || feedbackId) {
|
|
1021
|
+
if (PROMOTION_SUBJECT.test(subject))
|
|
1022
|
+
return typed("promotion", "promotion-subject");
|
|
1023
|
+
if (MARKETING_SENDER.test(from) && !NEWS_SENDER.test(from))
|
|
1024
|
+
return typed("promotion", "marketing-address");
|
|
1025
|
+
if (listId)
|
|
1026
|
+
return typed("newsletter", "list-id");
|
|
1027
|
+
if (NEWS_SENDER.test(from))
|
|
1028
|
+
return typed("newsletter", "newsletter-address");
|
|
1029
|
+
if (NEWS_SUBJECT.test(subject))
|
|
1030
|
+
return typed("newsletter", "newsletter-subject");
|
|
1031
|
+
if (input.sector === "news")
|
|
1032
|
+
return typed("newsletter", "sector:news");
|
|
1033
|
+
if (!input.bot && !noReply)
|
|
1034
|
+
return typed("newsletter", "person-sender");
|
|
1035
|
+
return typed("promotion", oneClick ? "one-click-unsubscribe" : feedbackId ? "feedback-id" : "bulk-mail");
|
|
1036
|
+
}
|
|
1037
|
+
if (!person && (ALERT_SENDER.test(from) || ALERT_SUBJECT.test(subject)))
|
|
1038
|
+
return typed("system_alert", ALERT_SENDER.test(from) ? "alert-address" : "alert-subject");
|
|
1039
|
+
if (!person && autoSubmitted)
|
|
1040
|
+
return typed("account_notice", "auto-submitted");
|
|
1041
|
+
if (!person && noReply)
|
|
1042
|
+
return typed("account_notice", "no-reply");
|
|
1043
|
+
if (!person && AUTOMATED_SENDER.test(from))
|
|
1044
|
+
return typed("account_notice", "automated-address");
|
|
1045
|
+
if (person)
|
|
1046
|
+
return typed("personal", "owner-wrote");
|
|
1047
|
+
if (!input.bot && headers["null-return-path"] !== true)
|
|
1048
|
+
return typed("personal", "person");
|
|
1049
|
+
return typed("other", null);
|
|
1050
|
+
}, "mailTypeOf");
|
|
1051
|
+
var JSON_LD_OPEN = /<script[^>]*type\s*=\s*["']?application\/ld\+json[^>]*>/gi;
|
|
1052
|
+
var ITEM_TYPE = /\bitemtype\s*=\s*["']?https?:\/\/schema\.org\/([A-Za-z]+)/gi;
|
|
1053
|
+
var LD_TYPE = /"@type"\s*:\s*"(?:https?:\/\/schema\.org\/)?([A-Za-z]+)"/g;
|
|
1054
|
+
var schemaTypesOf = /* @__PURE__ */ __name((html) => {
|
|
1055
|
+
if (html === null || html === "")
|
|
1056
|
+
return [];
|
|
1057
|
+
const found = /* @__PURE__ */ new Set();
|
|
1058
|
+
for (const open of html.matchAll(JSON_LD_OPEN)) {
|
|
1059
|
+
const start = open.index + open[0].length;
|
|
1060
|
+
const end = html.indexOf("</script>", start);
|
|
1061
|
+
if (end === -1)
|
|
1062
|
+
break;
|
|
1063
|
+
for (const [, type] of html.slice(start, end).matchAll(LD_TYPE))
|
|
1064
|
+
found.add(type);
|
|
1065
|
+
}
|
|
1066
|
+
for (const [, type] of html.matchAll(ITEM_TYPE))
|
|
1067
|
+
found.add(type);
|
|
1068
|
+
return [...found];
|
|
1069
|
+
}, "schemaTypesOf");
|
|
1070
|
+
|
|
1071
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/search/lucene/registry.js
|
|
1072
|
+
var FIELD_VERSION = 2;
|
|
1073
|
+
var UNITS = {
|
|
1074
|
+
"": 1,
|
|
1075
|
+
b: 1,
|
|
1076
|
+
k: 1024,
|
|
1077
|
+
kb: 1024,
|
|
1078
|
+
m: 1024 ** 2,
|
|
1079
|
+
mb: 1024 ** 2,
|
|
1080
|
+
g: 1024 ** 3,
|
|
1081
|
+
gb: 1024 ** 3
|
|
1082
|
+
};
|
|
1083
|
+
var parseBytes = /* @__PURE__ */ __name((value, span) => {
|
|
1084
|
+
const [, amount, unit] = /^(\d+(?:\.\d+)?)\s*([a-z]*)$/iu.exec(value.trim()) ?? [];
|
|
1085
|
+
const scale = UNITS[unit?.toLowerCase() ?? ""];
|
|
1086
|
+
if (amount === void 0 || scale === void 0)
|
|
1087
|
+
searchError("query.invalid-size", span, "use bytes or KB/MB/GB, e.g. 10MB");
|
|
1088
|
+
return Math.round(Number(amount) * scale);
|
|
1089
|
+
}, "parseBytes");
|
|
1090
|
+
var filled = /* @__PURE__ */ __name((node) => {
|
|
1091
|
+
if (node.value === "")
|
|
1092
|
+
searchError("query.missing-value", node.span);
|
|
1093
|
+
}, "filled");
|
|
1094
|
+
var validateSize = /* @__PURE__ */ __name((node) => {
|
|
1095
|
+
for (const bound2 of node.operator === "range" ? [node.value, node.upper] : [node.value])
|
|
1096
|
+
if (bound2 !== void 0 && bound2 !== "*")
|
|
1097
|
+
parseBytes(bound2, node.span);
|
|
1098
|
+
}, "validateSize");
|
|
1099
|
+
var validateTag = /* @__PURE__ */ __name((node) => {
|
|
1100
|
+
if (node.operator === "wildcard" ? !/^[a-z0-9*?-]{1,32}$/iu.test(node.value) : tagOf(node.value) === void 0)
|
|
1101
|
+
searchError("query.invalid-tag", node.span, "a tag is 1-32 letters a-z, digits and hyphens");
|
|
1102
|
+
}, "validateTag");
|
|
1103
|
+
var validateMentioned = /* @__PURE__ */ __name((node) => {
|
|
1104
|
+
if (!/^(?:person|organization|document):[1-9]\d*$/u.test(node.value))
|
|
1105
|
+
searchError("query.invalid-reference", node.span, "use person:<uid>, organization:<id> or document:<id>, quoted");
|
|
1106
|
+
}, "validateMentioned");
|
|
1107
|
+
var validateTopic = /* @__PURE__ */ __name((node) => {
|
|
1108
|
+
if (!/^\d+$/u.test(node.value))
|
|
1109
|
+
searchError("query.invalid-topic", node.span, "use a thread id in one chat");
|
|
1110
|
+
}, "validateTopic");
|
|
1111
|
+
var terms = ["term", "phrase"];
|
|
1112
|
+
var names = [...terms, "wildcard"];
|
|
1113
|
+
var NAMES = "account-scoped: an id or contact: reference as is; with * or ? a pattern over alias, name, @username (up to 50); else a name";
|
|
1114
|
+
var QUERY_FIELDS = [
|
|
1115
|
+
{
|
|
1116
|
+
name: "text",
|
|
1117
|
+
example: "invoice",
|
|
1118
|
+
index: "message_stems \u222A message_words; wildcard and regex: message_words",
|
|
1119
|
+
aliases: [],
|
|
1120
|
+
type: "txt",
|
|
1121
|
+
operators: ["term", "phrase", "wildcard", "regex"],
|
|
1122
|
+
normalization: "Snowball 3.1.1 by script (Cyrillic, Latin; the store's search_stemmers), then v1",
|
|
1123
|
+
support: "A1"
|
|
1124
|
+
},
|
|
1125
|
+
{
|
|
1126
|
+
name: "exact",
|
|
1127
|
+
example: "exact:invoice",
|
|
1128
|
+
index: "message_words",
|
|
1129
|
+
aliases: [],
|
|
1130
|
+
type: "txt",
|
|
1131
|
+
operators: ["term", "phrase", "wildcard", "regex"],
|
|
1132
|
+
normalization: "NFKD/marks/NFC/lowercase v1",
|
|
1133
|
+
support: "A1"
|
|
1134
|
+
},
|
|
1135
|
+
{
|
|
1136
|
+
name: "body",
|
|
1137
|
+
example: "body:/.*invoice.*/",
|
|
1138
|
+
index: "messages.text / bounded postfilter",
|
|
1139
|
+
aliases: [],
|
|
1140
|
+
type: "txt",
|
|
1141
|
+
operators: ["term", "phrase", "wildcard", "regex"],
|
|
1142
|
+
normalization: "raw, case-sensitive",
|
|
1143
|
+
support: "A1"
|
|
1144
|
+
},
|
|
1145
|
+
{
|
|
1146
|
+
name: "from",
|
|
1147
|
+
example: "from:Alice*",
|
|
1148
|
+
index: "identities / sender index",
|
|
1149
|
+
aliases: ["sender"],
|
|
1150
|
+
type: "kw",
|
|
1151
|
+
operators: names,
|
|
1152
|
+
normalization: NAMES,
|
|
1153
|
+
support: "A1"
|
|
1154
|
+
},
|
|
1155
|
+
...["to", "cc", "bcc"].map((name) => ({
|
|
1156
|
+
name,
|
|
1157
|
+
example: `${name}:"Alice Synthetic"`,
|
|
1158
|
+
index: "email_recipients",
|
|
1159
|
+
aliases: [],
|
|
1160
|
+
type: "kw",
|
|
1161
|
+
operators: names,
|
|
1162
|
+
normalization: `${NAMES}; mail only`,
|
|
1163
|
+
support: "A1"
|
|
1164
|
+
})),
|
|
1165
|
+
{
|
|
1166
|
+
name: "subject",
|
|
1167
|
+
example: 'subject:"quarterly planning"',
|
|
1168
|
+
index: "email_words, then the subject",
|
|
1169
|
+
aliases: [],
|
|
1170
|
+
type: "txt",
|
|
1171
|
+
operators: [...terms, "wildcard"],
|
|
1172
|
+
normalization: "every word, folded as text is; mail only",
|
|
1173
|
+
support: "A1",
|
|
1174
|
+
validate: filled
|
|
1175
|
+
},
|
|
1176
|
+
{
|
|
1177
|
+
name: "mailbox",
|
|
1178
|
+
example: 'mailbox:INBOX OR mailbox:"[Gmail]/Sent Mail"',
|
|
1179
|
+
index: "email_mailboxes",
|
|
1180
|
+
aliases: [],
|
|
1181
|
+
type: "kw",
|
|
1182
|
+
operators: [...terms, "wildcard"],
|
|
1183
|
+
normalization: "a folder or label by its id (ASCII case folded) or name (case folded in any script); mail only",
|
|
1184
|
+
support: "A1"
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
name: "label",
|
|
1188
|
+
example: "label:Projects",
|
|
1189
|
+
index: "email_mailboxes",
|
|
1190
|
+
aliases: [],
|
|
1191
|
+
type: "kw",
|
|
1192
|
+
operators: [...terms, "wildcard"],
|
|
1193
|
+
normalization: "the same as mailbox:; mail only",
|
|
1194
|
+
support: "A1"
|
|
1195
|
+
},
|
|
1196
|
+
{
|
|
1197
|
+
name: "list",
|
|
1198
|
+
example: "list:github.com",
|
|
1199
|
+
index: "emails.headers list-id",
|
|
1200
|
+
aliases: [],
|
|
1201
|
+
type: "kw",
|
|
1202
|
+
operators: terms,
|
|
1203
|
+
normalization: "the List-Id of a mailing list, lower case; a domain matches every list under it; mail only",
|
|
1204
|
+
support: "A1",
|
|
1205
|
+
validate: filled
|
|
1206
|
+
},
|
|
1207
|
+
{
|
|
1208
|
+
name: "is",
|
|
1209
|
+
example: "is:unread",
|
|
1210
|
+
index: "emails.read / emails.flagged / messages.starred",
|
|
1211
|
+
aliases: [],
|
|
1212
|
+
type: "enum",
|
|
1213
|
+
operators: terms,
|
|
1214
|
+
normalization: "lowercase; read and unread are mail only; starred is a flagged email or a message the owner starred; an unknown state matches neither read nor unread",
|
|
1215
|
+
support: "A1",
|
|
1216
|
+
values: ["unread", "read", "starred"]
|
|
1217
|
+
},
|
|
1218
|
+
{
|
|
1219
|
+
name: "type",
|
|
1220
|
+
example: "type:order OR type:bill",
|
|
1221
|
+
index: "emails.mail_type (emails_by_mail_type)",
|
|
1222
|
+
aliases: [],
|
|
1223
|
+
type: "enum",
|
|
1224
|
+
operators: terms,
|
|
1225
|
+
normalization: "lowercase; what one email is, apart from its sender; mail not typed yet is typed before the search; mail only",
|
|
1226
|
+
support: "A1",
|
|
1227
|
+
values: MAIL_TYPES
|
|
1228
|
+
},
|
|
1229
|
+
{
|
|
1230
|
+
name: "reach",
|
|
1231
|
+
example: "reach:direct",
|
|
1232
|
+
index: "emails.reach",
|
|
1233
|
+
aliases: [],
|
|
1234
|
+
type: "enum",
|
|
1235
|
+
operators: terms,
|
|
1236
|
+
normalization: "lowercase; how one email reached the owner; mail only",
|
|
1237
|
+
support: "A1",
|
|
1238
|
+
values: REACHES
|
|
1239
|
+
},
|
|
1240
|
+
{
|
|
1241
|
+
name: "chat",
|
|
1242
|
+
example: "chat:*fixture*",
|
|
1243
|
+
index: "chats / message time index",
|
|
1244
|
+
aliases: [],
|
|
1245
|
+
type: "kw",
|
|
1246
|
+
operators: names,
|
|
1247
|
+
normalization: "account-scoped: an id or chat: reference as is; with * or ? a pattern over title, @username (up to 50); else a title",
|
|
1248
|
+
support: "A1"
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
name: "date",
|
|
1252
|
+
example: "date:[2026-01-01 TO 2026-02-01}",
|
|
1253
|
+
index: "messages.sent_at",
|
|
1254
|
+
aliases: [],
|
|
1255
|
+
type: "time",
|
|
1256
|
+
operators: [...terms, "range"],
|
|
1257
|
+
normalization: "ISO/calendar timezone; today, yesterday, 30m/2h/7d ago",
|
|
1258
|
+
support: "A1"
|
|
1259
|
+
},
|
|
1260
|
+
{
|
|
1261
|
+
name: "source",
|
|
1262
|
+
example: "source:internal",
|
|
1263
|
+
index: "notes (internal) / documents (file)",
|
|
1264
|
+
aliases: [],
|
|
1265
|
+
type: "enum",
|
|
1266
|
+
operators: terms,
|
|
1267
|
+
normalization: "lowercase; notes only: internal is written in memo, file is from a notes folder",
|
|
1268
|
+
support: "A1",
|
|
1269
|
+
values: ["internal", "file"]
|
|
1270
|
+
},
|
|
1271
|
+
{
|
|
1272
|
+
name: "kind",
|
|
1273
|
+
example: "kind:private",
|
|
1274
|
+
index: "chats.kind / peerKind metadata",
|
|
1275
|
+
aliases: [],
|
|
1276
|
+
type: "enum",
|
|
1277
|
+
operators: terms,
|
|
1278
|
+
normalization: "lowercase",
|
|
1279
|
+
support: "A1",
|
|
1280
|
+
values: ["private", "saved", "bot", "service", "group", "channel", "unknown"]
|
|
1281
|
+
},
|
|
1282
|
+
{
|
|
1283
|
+
name: "muted",
|
|
1284
|
+
example: "muted:false",
|
|
1285
|
+
index: "chats.muted / chats.muted_until",
|
|
1286
|
+
aliases: [],
|
|
1287
|
+
type: "enum",
|
|
1288
|
+
operators: terms,
|
|
1289
|
+
normalization: "lowercase; true is a chat the owner muted, until the mute runs out; false is every other chat",
|
|
1290
|
+
support: "A1",
|
|
1291
|
+
values: ["true", "false"]
|
|
1292
|
+
},
|
|
1293
|
+
{
|
|
1294
|
+
name: "participants_count",
|
|
1295
|
+
example: "participants_count<10",
|
|
1296
|
+
index: "chats.participants_count",
|
|
1297
|
+
aliases: [],
|
|
1298
|
+
type: "num",
|
|
1299
|
+
operators: [...terms, "range"],
|
|
1300
|
+
normalization: "a whole number; a chat whose size the messenger never told matches no value",
|
|
1301
|
+
support: "A1"
|
|
1302
|
+
},
|
|
1303
|
+
{
|
|
1304
|
+
name: "has",
|
|
1305
|
+
example: "has:file",
|
|
1306
|
+
index: "attachments / messages_fts links / message_transcripts",
|
|
1307
|
+
aliases: [],
|
|
1308
|
+
type: "enum",
|
|
1309
|
+
operators: terms,
|
|
1310
|
+
normalization: "lowercase",
|
|
1311
|
+
support: "A1",
|
|
1312
|
+
values: [
|
|
1313
|
+
"text",
|
|
1314
|
+
"attachment",
|
|
1315
|
+
"link",
|
|
1316
|
+
"file",
|
|
1317
|
+
"photo",
|
|
1318
|
+
"image",
|
|
1319
|
+
"video",
|
|
1320
|
+
"audio",
|
|
1321
|
+
"voice",
|
|
1322
|
+
"sticker",
|
|
1323
|
+
"contact",
|
|
1324
|
+
"location",
|
|
1325
|
+
"poll",
|
|
1326
|
+
"transcript"
|
|
1327
|
+
]
|
|
1328
|
+
},
|
|
1329
|
+
{
|
|
1330
|
+
name: "topic",
|
|
1331
|
+
example: "chat:7 AND topic:42",
|
|
1332
|
+
index: "messages.thread_native_id",
|
|
1333
|
+
aliases: [],
|
|
1334
|
+
type: "kw",
|
|
1335
|
+
operators: terms,
|
|
1336
|
+
normalization: "string id, one chat required",
|
|
1337
|
+
support: "A1",
|
|
1338
|
+
validate: validateTopic
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
name: "in",
|
|
1342
|
+
example: "in:bots",
|
|
1343
|
+
index: "accounts.provider",
|
|
1344
|
+
aliases: [],
|
|
1345
|
+
type: "kw",
|
|
1346
|
+
operators: terms,
|
|
1347
|
+
normalization: "lowercase provider/account class",
|
|
1348
|
+
support: "A1"
|
|
1349
|
+
},
|
|
1350
|
+
{
|
|
1351
|
+
name: "preset",
|
|
1352
|
+
example: "preset:secret",
|
|
1353
|
+
index: "bounded local candidate detector",
|
|
1354
|
+
aliases: [],
|
|
1355
|
+
type: "enum",
|
|
1356
|
+
operators: terms,
|
|
1357
|
+
normalization: "versioned candidate detector",
|
|
1358
|
+
support: "A1",
|
|
1359
|
+
values: [
|
|
1360
|
+
"password",
|
|
1361
|
+
"code",
|
|
1362
|
+
"api-key",
|
|
1363
|
+
"secret",
|
|
1364
|
+
"card",
|
|
1365
|
+
"bank",
|
|
1366
|
+
"passport",
|
|
1367
|
+
"phone",
|
|
1368
|
+
"email",
|
|
1369
|
+
"telegram-link",
|
|
1370
|
+
"url",
|
|
1371
|
+
"contact",
|
|
1372
|
+
"location"
|
|
1373
|
+
]
|
|
1374
|
+
},
|
|
1375
|
+
{
|
|
1376
|
+
name: "filename",
|
|
1377
|
+
example: "filename:*.pdf",
|
|
1378
|
+
index: "attachments.name / bounded postfilter",
|
|
1379
|
+
aliases: [],
|
|
1380
|
+
type: "kw",
|
|
1381
|
+
operators: [...terms, "wildcard", "regex"],
|
|
1382
|
+
normalization: "NFKD/marks/NFC/lowercase v1, whole name",
|
|
1383
|
+
support: "A2"
|
|
1384
|
+
},
|
|
1385
|
+
{
|
|
1386
|
+
name: "mime",
|
|
1387
|
+
example: 'mime:"application/pdf" OR mime:image',
|
|
1388
|
+
index: "attachments.mime / bounded postfilter",
|
|
1389
|
+
aliases: [],
|
|
1390
|
+
type: "kw",
|
|
1391
|
+
operators: [...terms, "wildcard"],
|
|
1392
|
+
normalization: "lowercase; a value without / matches the first part; only where the messenger reports a type",
|
|
1393
|
+
support: "A2"
|
|
1394
|
+
},
|
|
1395
|
+
{
|
|
1396
|
+
name: "size",
|
|
1397
|
+
example: "size>10MB",
|
|
1398
|
+
index: "attachments.size",
|
|
1399
|
+
aliases: [],
|
|
1400
|
+
type: "kw",
|
|
1401
|
+
operators: [...terms, "range"],
|
|
1402
|
+
normalization: "bytes; KB/MB/GB are 1024-based",
|
|
1403
|
+
support: "A2",
|
|
1404
|
+
validate: validateSize
|
|
1405
|
+
},
|
|
1406
|
+
{
|
|
1407
|
+
name: "content",
|
|
1408
|
+
example: "content:invoice",
|
|
1409
|
+
index: "attachment_words",
|
|
1410
|
+
aliases: [],
|
|
1411
|
+
type: "txt",
|
|
1412
|
+
operators: [...terms, "wildcard"],
|
|
1413
|
+
normalization: "NFKD/marks/NFC/lowercase v1; the text of files attachments extract read or an agent wrote",
|
|
1414
|
+
support: "A2",
|
|
1415
|
+
validate: filled
|
|
1416
|
+
},
|
|
1417
|
+
{
|
|
1418
|
+
name: "transcript",
|
|
1419
|
+
example: "transcript:invoice",
|
|
1420
|
+
index: "attachment_words \u222A transcript_stems; garbled spellings from transcript_words_vocab",
|
|
1421
|
+
aliases: [],
|
|
1422
|
+
type: "txt",
|
|
1423
|
+
operators: [...terms, "wildcard"],
|
|
1424
|
+
normalization: "any form of the word (Snowball), widened to spellings speech recognition garbles; what a voice message said",
|
|
1425
|
+
support: "A2",
|
|
1426
|
+
validate: filled
|
|
1427
|
+
},
|
|
1428
|
+
...[
|
|
1429
|
+
[
|
|
1430
|
+
"title",
|
|
1431
|
+
'title:"quarterly report"',
|
|
1432
|
+
"documents.metadata, then the title column; chats.title_folded; email_words, then the subject",
|
|
1433
|
+
"every word, folded as text is: of a note's or a file's title, inside a chat's title, of a mail's subject (as subject:)",
|
|
1434
|
+
"txt"
|
|
1435
|
+
],
|
|
1436
|
+
[
|
|
1437
|
+
"site",
|
|
1438
|
+
"site:wikipedia",
|
|
1439
|
+
"documents.metadata (og:site_name)",
|
|
1440
|
+
"contained, folded as text is; notes and files only",
|
|
1441
|
+
"kw"
|
|
1442
|
+
],
|
|
1443
|
+
[
|
|
1444
|
+
"lang",
|
|
1445
|
+
"lang:ru",
|
|
1446
|
+
"documents.metadata (html lang)",
|
|
1447
|
+
"language tag or its prefix, lowercase; notes and files only",
|
|
1448
|
+
"kw"
|
|
1449
|
+
],
|
|
1450
|
+
[
|
|
1451
|
+
"author",
|
|
1452
|
+
"author:ivanov",
|
|
1453
|
+
"documents.metadata (meta author, JSON-LD)",
|
|
1454
|
+
"contained, folded as text is; notes and files only",
|
|
1455
|
+
"kw"
|
|
1456
|
+
],
|
|
1457
|
+
[
|
|
1458
|
+
"keyword",
|
|
1459
|
+
"keyword:invoices",
|
|
1460
|
+
"documents.metadata (meta keywords)",
|
|
1461
|
+
"whole keyword, folded as text is; notes and files only",
|
|
1462
|
+
"kw"
|
|
1463
|
+
]
|
|
1464
|
+
].map(([name, example, index, normalization, type]) => ({
|
|
1465
|
+
name,
|
|
1466
|
+
example,
|
|
1467
|
+
index,
|
|
1468
|
+
aliases: [],
|
|
1469
|
+
type,
|
|
1470
|
+
operators: terms,
|
|
1471
|
+
normalization,
|
|
1472
|
+
support: "A2",
|
|
1473
|
+
validate: filled
|
|
1474
|
+
})),
|
|
1475
|
+
...[
|
|
1476
|
+
[
|
|
1477
|
+
"phone",
|
|
1478
|
+
'phone:"8 900 000-00-01"',
|
|
1479
|
+
"a phone found in the text, written any way; a number without + is read in phone_countries"
|
|
1480
|
+
],
|
|
1481
|
+
["email", "email:ana@example.com", "an address found in the text, lower-cased"],
|
|
1482
|
+
["url", 'url:"https://example.com/a"', "a link found in the text, without utm_*, fbclid and the fragment"],
|
|
1483
|
+
["domain", "domain:google.com", "the site of a link or an address in the text; docs.google.com means google.com"],
|
|
1484
|
+
[
|
|
1485
|
+
"link",
|
|
1486
|
+
'link:"click?id=1"',
|
|
1487
|
+
"a part of a link, quoted; Latin letters in any case; in mail also the body of a letter with a tracking link"
|
|
1488
|
+
]
|
|
1489
|
+
].map(([name, example, normalization]) => ({
|
|
1490
|
+
name,
|
|
1491
|
+
example,
|
|
1492
|
+
index: "mentions (kind, value) / (domain); in mail a tracking link is kept as its site",
|
|
1493
|
+
aliases: [],
|
|
1494
|
+
type: "kw",
|
|
1495
|
+
operators: terms,
|
|
1496
|
+
normalization,
|
|
1497
|
+
support: "A2",
|
|
1498
|
+
validate: filled
|
|
1499
|
+
})),
|
|
1500
|
+
{
|
|
1501
|
+
name: "mentions",
|
|
1502
|
+
example: 'mentions:"person:12"',
|
|
1503
|
+
index: "mentions (target_type, target_id)",
|
|
1504
|
+
aliases: [],
|
|
1505
|
+
type: "kw",
|
|
1506
|
+
operators: terms,
|
|
1507
|
+
normalization: "a person (by name, phone or address), an organization or a document, linked; quoted",
|
|
1508
|
+
support: "A2",
|
|
1509
|
+
validate: validateMentioned
|
|
1510
|
+
},
|
|
1511
|
+
{
|
|
1512
|
+
name: "tag",
|
|
1513
|
+
example: "tag:work",
|
|
1514
|
+
index: "tags: the message, its chat or its sender",
|
|
1515
|
+
aliases: [],
|
|
1516
|
+
type: "kw",
|
|
1517
|
+
operators: [...terms, "wildcard"],
|
|
1518
|
+
normalization: "lowercase a-z, 0-9 and -, 1-32 characters",
|
|
1519
|
+
support: "A2",
|
|
1520
|
+
validate: validateTag
|
|
1521
|
+
}
|
|
1522
|
+
];
|
|
1523
|
+
var MESSAGES = { entity: "message", backend: "sql", fields: QUERY_FIELDS };
|
|
1524
|
+
var NEAR_FIELDS = /* @__PURE__ */ new Set(["text", "exact", "transcript", "content"]);
|
|
1525
|
+
var CANONICAL = new Map(QUERY_FIELDS.flatMap(({ name, aliases }) => aliases.map((alias) => [alias, name])));
|
|
1526
|
+
var isPresence = /* @__PURE__ */ __name((node) => node.operator === "wildcard" && node.value === "*", "isPresence");
|
|
1527
|
+
var PRESENCE = /* @__PURE__ */ new Set(["from", "to", "cc", "bcc", "subject", "title", "topic", "participants_count"]);
|
|
1528
|
+
var ALWAYS = /* @__PURE__ */ new Set(["chat", "date"]);
|
|
1529
|
+
var EVERY_DATE = { operator: "range", value: "*", upper: "*", lower_inclusive: true, upper_inclusive: true };
|
|
1530
|
+
var PRESENCE_INSTEAD = {
|
|
1531
|
+
text: "has:text",
|
|
1532
|
+
exact: "has:text",
|
|
1533
|
+
body: "has:text",
|
|
1534
|
+
content: "has:file",
|
|
1535
|
+
transcript: "has:transcript",
|
|
1536
|
+
size: "has:attachment",
|
|
1537
|
+
url: "has:link",
|
|
1538
|
+
link: "has:link",
|
|
1539
|
+
domain: "has:link"
|
|
1540
|
+
};
|
|
1541
|
+
var CONTAINED = /* @__PURE__ */ new Set(["title", "site", "author"]);
|
|
1542
|
+
var notPresent = /* @__PURE__ */ __name((node) => searchError("query.unsupported-operator", node.span, `${node.field}:* asks whether ${node.field} has a value, which search answers for ${[...PRESENCE, ...ALWAYS].join(", ")}${PRESENCE_INSTEAD[node.field] ? `; write ${PRESENCE_INSTEAD[node.field]}` : ""}`), "notPresent");
|
|
1543
|
+
var canonical = /* @__PURE__ */ __name((node) => {
|
|
1544
|
+
if (node.kind === "boolean") {
|
|
1545
|
+
const clauses = node.clauses.map((clause) => {
|
|
1546
|
+
const inner = canonical(clause.node);
|
|
1547
|
+
return inner === clause.node ? clause : { ...clause, node: inner };
|
|
1548
|
+
});
|
|
1549
|
+
return clauses.every((clause, at) => clause === node.clauses[at]) ? node : { ...node, clauses };
|
|
1550
|
+
}
|
|
1551
|
+
const field2 = CANONICAL.get(node.field);
|
|
1552
|
+
if (node.field !== "_exists_")
|
|
1553
|
+
return field2 ? { ...node, field: field2 } : node;
|
|
1554
|
+
const { implicit: _, ...rest } = node;
|
|
1555
|
+
return { ...rest, field: CANONICAL.get(node.value) ?? node.value, operator: "wildcard", value: "*" };
|
|
1556
|
+
}, "canonical");
|
|
1557
|
+
var everyDate = /* @__PURE__ */ __name((node) => node.kind === "boolean" ? { ...node, clauses: node.clauses.map((clause) => ({ ...clause, node: everyDate(clause.node) })) } : isPresence(node) && ALWAYS.has(node.field) ? { kind: "predicate", field: "date", ...EVERY_DATE, span: node.span } : node, "everyDate");
|
|
1558
|
+
var validateFields = /* @__PURE__ */ __name((written, { presence = false } = {}) => {
|
|
1559
|
+
const root = canonical(written.root);
|
|
1560
|
+
const ast = root === written.root ? written : { ...written, root };
|
|
1561
|
+
for (const node of walkQuery(ast.root)) {
|
|
1562
|
+
if (presence && isPresence(node)) {
|
|
1563
|
+
if (PRESENCE.has(node.field) || ALWAYS.has(node.field))
|
|
1564
|
+
continue;
|
|
1565
|
+
const known = QUERY_FIELDS.find(({ name }) => name === node.field);
|
|
1566
|
+
if (known && (!known.operators.includes("wildcard") || PRESENCE_INSTEAD[node.field]))
|
|
1567
|
+
notPresent(node);
|
|
1568
|
+
}
|
|
1569
|
+
const field2 = QUERY_FIELDS.find(({ name }) => name === node.field);
|
|
1570
|
+
if (!field2 && ["after", "before"].includes(node.field)) {
|
|
1571
|
+
const plain = ["term", "phrase"].includes(node.operator) && /^[\w:.+-]+$/u.test(node.value);
|
|
1572
|
+
searchError("query.legacy-date-field", node.span, plain ? `use date${node.field === "after" ? ">=" : "<"}${node.value}` : "use date>=YYYY-MM-DD or date:[a TO b]");
|
|
1573
|
+
}
|
|
1574
|
+
if (node.slop !== void 0 && !NEAR_FIELDS.has(node.field))
|
|
1575
|
+
searchError("query.unsupported-operator", node.span, `"a b"~N takes words: ${[...NEAR_FIELDS].join(", ")}`);
|
|
1576
|
+
if (node.slop !== void 0 && node.slop > MOST_WORDS_APART)
|
|
1577
|
+
searchError("query.invalid-number", node.span, `words at most ${MOST_WORDS_APART} apart: "a b"~${MOST_WORDS_APART}`);
|
|
1578
|
+
if (field2 && node.operator === "wildcard" && !field2.operators.includes("wildcard")) {
|
|
1579
|
+
const part = node.value.replace(/[*?]/gu, "");
|
|
1580
|
+
searchError("query.unsupported-operator", node.span, `${field2.name} takes ${field2.operators.join(", ")}` + (CONTAINED.has(field2.name) && part ? `; ${field2.name}:${part} already finds it inside a word` : ""));
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
const valid = validateQuery(ast, MESSAGES, SEARCH_QUERY);
|
|
1584
|
+
return presence ? { ...valid, root: everyDate(valid.root) } : valid;
|
|
1585
|
+
}, "validateFields");
|
|
1586
|
+
var record = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value), "record");
|
|
1587
|
+
var validSpan = /* @__PURE__ */ __name((value) => record(value) && Number.isInteger(value.start) && Number.isInteger(value.end) && Number(value.start) >= 0 && Number(value.end) >= Number(value.start) && Number(value.end) <= QUERY_LIMITS2.bytes, "validSpan");
|
|
1588
|
+
var validateAst = /* @__PURE__ */ __name((input, options = {}) => {
|
|
1589
|
+
const failure = { start: 0, end: 0 };
|
|
1590
|
+
if (!record(input) || input.version !== 1 || input.language !== "lucene-v1")
|
|
1591
|
+
searchError("query.unsupported-version", failure);
|
|
1592
|
+
let count = 0;
|
|
1593
|
+
let bytes = 0;
|
|
1594
|
+
const measure = /* @__PURE__ */ __name((value, depth) => {
|
|
1595
|
+
if (++count > QUERY_LIMITS2.nodes || depth > QUERY_LIMITS2.depth)
|
|
1596
|
+
searchError("query.too-large", failure);
|
|
1597
|
+
if (!record(value) || !validSpan(value.span))
|
|
1598
|
+
searchError("query.invalid-ast", failure);
|
|
1599
|
+
if (Array.isArray(value.clauses)) {
|
|
1600
|
+
if (value.clauses.length === 0)
|
|
1601
|
+
searchError("query.invalid-ast", value.span);
|
|
1602
|
+
for (const clause of value.clauses)
|
|
1603
|
+
measure(record(clause) ? clause.node : void 0, depth + 1);
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
for (const text of [value.field, value.value, value.upper])
|
|
1607
|
+
if (typeof text === "string")
|
|
1608
|
+
bytes += new TextEncoder().encode(text).length;
|
|
1609
|
+
if (bytes > QUERY_LIMITS2.bytes)
|
|
1610
|
+
searchError("query.too-large", value.span);
|
|
1611
|
+
}, "measure");
|
|
1612
|
+
measure(input.root, 1);
|
|
1613
|
+
const parsed = safeParse(queryAstSchema, input);
|
|
1614
|
+
if (!parsed.success)
|
|
1615
|
+
searchError("query.invalid-ast", failure);
|
|
1616
|
+
const open = walkQuery(parsed.output.root).find((node) => node.operator === "range" && (node.upper === void 0 || node.lower_inclusive === void 0 || node.upper_inclusive === void 0));
|
|
1617
|
+
if (open)
|
|
1618
|
+
searchError("query.invalid-ast", open.span);
|
|
1619
|
+
return validateFields(parsed.output, options);
|
|
1620
|
+
}, "validateAst");
|
|
1621
|
+
|
|
1622
|
+
// node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/search/lucene/plain.js
|
|
1623
|
+
var REPAIRED = /* @__PURE__ */ new Set([
|
|
1624
|
+
"query.invalid-syntax",
|
|
1625
|
+
"query.unclosed-literal",
|
|
1626
|
+
"query.unsupported-operator",
|
|
1627
|
+
"query.invalid-escape"
|
|
1628
|
+
]);
|
|
1629
|
+
var SEARCH_FIELDS = /* @__PURE__ */ new Set([
|
|
1630
|
+
...QUERY_FIELDS.flatMap(({ name, aliases }) => [name, ...aliases]),
|
|
1631
|
+
"after",
|
|
1632
|
+
"before",
|
|
1633
|
+
"_exists_"
|
|
1634
|
+
]);
|
|
1635
|
+
var FIELD_PREFIX = /^[+-]?([\p{L}\p{N}_.]+)(?:[:=]|[<>]=?)/u;
|
|
1636
|
+
var FIELD_NAME = /^[a-z][a-z_]{2,}$/u;
|
|
1637
|
+
var LISTED_BY = "this search has no such field; a list filters by it:";
|
|
1638
|
+
var ELSEWHERE = {
|
|
1639
|
+
status: `${LISTED_BY} tasks list status:open, deals list status:won`,
|
|
1640
|
+
stage: `${LISTED_BY} deals list stage:<value>`,
|
|
1641
|
+
pipeline: `${LISTED_BY} deals list pipeline:<value>`,
|
|
1642
|
+
priority: `${LISTED_BY} tasks list priority:<value>`,
|
|
1643
|
+
assignee: `${LISTED_BY} tasks list assignee:<value>`,
|
|
1644
|
+
project: `${LISTED_BY} tasks list project:<value>`,
|
|
1645
|
+
due: `${LISTED_BY} tasks list due:<value>`,
|
|
1646
|
+
name: "a person's name is from: (who wrote) or mentions: here"
|
|
1647
|
+
};
|
|
1648
|
+
var unknownField = /* @__PURE__ */ __name((field2, written, span, fields) => searchError("query.unknown-field", span, `${ELSEWHERE[field2] ?? `fields here: ${[...fields].filter((one) => FIELD_NAME.test(one)).join(", ")}`}; to find the words as written, quote them: "${written}"`), "unknownField");
|
|
1649
|
+
var space = /* @__PURE__ */ __name((c) => c !== void 0 && /[ \t\n\r\u3000]/u.test(c), "space");
|
|
1650
|
+
var quoted2 = /* @__PURE__ */ __name((text) => {
|
|
1651
|
+
let out = "";
|
|
1652
|
+
for (let at = 0; at < text.length; at++) {
|
|
1653
|
+
const c = text[at];
|
|
1654
|
+
if (c === "\\" && at + 1 < text.length && (text[at + 1] !== "u" || /^u[0-9a-fA-F]{4}/u.test(text.slice(at + 1)))) {
|
|
1655
|
+
out += c + text[at + 1];
|
|
1656
|
+
at++;
|
|
1657
|
+
} else
|
|
1658
|
+
out += c === '"' || c === "\\" ? `\\${c}` : c;
|
|
1659
|
+
}
|
|
1660
|
+
return `"${out}"`;
|
|
1661
|
+
}, "quoted");
|
|
1662
|
+
var literal = /* @__PURE__ */ __name((word, keepParens, fields) => {
|
|
1663
|
+
const prefix = FIELD_PREFIX.exec(word);
|
|
1664
|
+
const field2 = prefix && fields.has(prefix[1] ?? "") ? prefix[0] : "";
|
|
1665
|
+
const rest = word.slice(field2.length);
|
|
1666
|
+
const opening = keepParens ? (field2 ? /^\(*/u : /^[(+-]*/u).exec(rest)?.[0] ?? "" : "";
|
|
1667
|
+
const closing = keepParens ? /\)*$/u.exec(rest.slice(opening.length))?.[0] ?? "" : "";
|
|
1668
|
+
const body = rest.slice(opening.length, rest.length - closing.length);
|
|
1669
|
+
if (!body)
|
|
1670
|
+
return keepParens ? literal(word, false, fields) : `${field2}${quoted2(rest)}`;
|
|
1671
|
+
return `${field2}${opening}${quoted2(body)}${closing}`;
|
|
1672
|
+
}, "literal");
|
|
1673
|
+
var wordAround = /* @__PURE__ */ __name((text, at) => {
|
|
1674
|
+
let start = at;
|
|
1675
|
+
while (start > 0 && !space(text[start - 1]))
|
|
1676
|
+
start--;
|
|
1677
|
+
let end = at;
|
|
1678
|
+
while (end < text.length && !space(text[end]))
|
|
1679
|
+
end++;
|
|
1680
|
+
return { start, end };
|
|
1681
|
+
}, "wordAround");
|
|
1682
|
+
var everyWordLiteral = /* @__PURE__ */ __name((text, fields) => text.replace(/[^ \t\n\r\u3000]+/gu, (word) => literal(word, false, fields)), "everyWordLiteral");
|
|
1683
|
+
var refusal = /* @__PURE__ */ __name((refuse) => {
|
|
1684
|
+
try {
|
|
1685
|
+
return refuse();
|
|
1686
|
+
} catch (error) {
|
|
1687
|
+
return { refused: error };
|
|
1688
|
+
}
|
|
1689
|
+
}, "refusal");
|
|
1690
|
+
var read = /* @__PURE__ */ __name((text, fields) => {
|
|
1691
|
+
try {
|
|
1692
|
+
const leaves = walkQuery(parseLucene(text, MESSAGE_PARSING).root);
|
|
1693
|
+
const unknown = leaves.find(({ field: field2 }) => !fields.has(field2));
|
|
1694
|
+
if (unknown && FIELD_NAME.test(unknown.field) && unknown.value && !unknown.value.startsWith("/"))
|
|
1695
|
+
return refusal(() => unknownField(unknown.field, text.slice(unknown.span.start, unknown.span.end), unknown.span, fields));
|
|
1696
|
+
if (unknown)
|
|
1697
|
+
return { at: text.lastIndexOf(unknown.field, unknown.span.start) };
|
|
1698
|
+
const questions = leaves.flatMap(({ implicit, operator, value, span }) => {
|
|
1699
|
+
const mark = /^[^*?]*[^*?\\]\?+$/u.test(value) && implicit && operator === "wildcard" ? /\?+$/u.exec(value) : null;
|
|
1700
|
+
return mark ? [span.end - mark[0].length] : [];
|
|
1701
|
+
});
|
|
1702
|
+
if (questions.length)
|
|
1703
|
+
return { questions };
|
|
1704
|
+
const wordless = leaves.filter(({ implicit, operator, value }) => implicit && (operator === "term" || operator === "phrase") && !/[\p{L}\p{N}]/u.test(value));
|
|
1705
|
+
const words2 = wordless.length < leaves.length;
|
|
1706
|
+
return { wordless: words2 ? wordless : [], words: words2 };
|
|
1707
|
+
} catch (error) {
|
|
1708
|
+
const details = isCliError(error) ? error.details : void 0;
|
|
1709
|
+
if (!details?.span || !REPAIRED.has(details.reason ?? ""))
|
|
1710
|
+
throw error;
|
|
1711
|
+
if (/^~\d/u.test(text.slice(details.span.start)))
|
|
1712
|
+
throw error;
|
|
1713
|
+
const at = details.span.start;
|
|
1714
|
+
const boost = /^\^\d+(?:\.\d+)?/u.exec(text.slice(at))?.[0];
|
|
1715
|
+
if (boost && at > 0 && !space(text[at - 1])) {
|
|
1716
|
+
const { start } = wordAround(text, at);
|
|
1717
|
+
const written = text.slice(start, at + boost.length);
|
|
1718
|
+
return refusal(() => searchError("query.unsupported-operator", { start, end: at + boost.length }, `boost ${boost} is not supported \u2014 drop it: ${text.slice(start, at)}, or quote the text to find it as written: ${quoted2(written)}`));
|
|
1719
|
+
}
|
|
1720
|
+
return { at };
|
|
1721
|
+
}
|
|
1722
|
+
}, "read");
|
|
1723
|
+
var without = /* @__PURE__ */ __name((text, leaves) => [...leaves].sort((a, b) => b.span.start - a.span.start).reduce((left, { span }) => left.slice(0, span.start) + left.slice(span.end), text).trim(), "without");
|
|
1724
|
+
var plainQuery = /* @__PURE__ */ __name((text, fields = SEARCH_FIELDS) => {
|
|
1725
|
+
if (text.trim() && !/[\p{L}\p{N}*]/u.test(text))
|
|
1726
|
+
throw new CliError("validation_error", `search needs a letter or a digit to look for; ${JSON.stringify(text)} has none`);
|
|
1727
|
+
let current = text;
|
|
1728
|
+
let whole = false;
|
|
1729
|
+
for (let tries = 0; tries <= 64; tries++) {
|
|
1730
|
+
let reading;
|
|
1731
|
+
try {
|
|
1732
|
+
reading = read(current, fields);
|
|
1733
|
+
} catch {
|
|
1734
|
+
return text;
|
|
1735
|
+
}
|
|
1736
|
+
if ("refused" in reading)
|
|
1737
|
+
throw reading.refused;
|
|
1738
|
+
if ("questions" in reading) {
|
|
1739
|
+
current = reading.questions.sort((a, b) => b - a).reduce((left, at) => left.slice(0, at) + left.slice(at).replace(/^\?+/u, (marks) => "\\?".repeat(marks.length)), current);
|
|
1740
|
+
continue;
|
|
1741
|
+
}
|
|
1742
|
+
if ("wordless" in reading) {
|
|
1743
|
+
if (!reading.words && current !== text)
|
|
1744
|
+
return text;
|
|
1745
|
+
if (!reading.wordless.length)
|
|
1746
|
+
return current;
|
|
1747
|
+
current = without(current, reading.wordless);
|
|
1748
|
+
continue;
|
|
1749
|
+
}
|
|
1750
|
+
const word = reading.at < 0 || reading.at >= current.length ? void 0 : wordAround(current, reading.at);
|
|
1751
|
+
const paren = "()".includes(current[reading.at] ?? "");
|
|
1752
|
+
const repaired = word ? current.slice(0, word.start) + literal(current.slice(word.start, word.end), !paren, fields) + current.slice(word.end) : current;
|
|
1753
|
+
if (repaired !== current) {
|
|
1754
|
+
current = repaired;
|
|
1755
|
+
continue;
|
|
1756
|
+
}
|
|
1757
|
+
if (whole)
|
|
1758
|
+
return text;
|
|
1759
|
+
whole = true;
|
|
1760
|
+
current = everyWordLiteral(text, fields);
|
|
1761
|
+
}
|
|
1762
|
+
return text;
|
|
1763
|
+
}, "plainQuery");
|
|
1764
|
+
|
|
1765
|
+
export {
|
|
1766
|
+
QUERY_VERSION,
|
|
1767
|
+
QUERY_LIMITS2 as QUERY_LIMITS,
|
|
1768
|
+
SEARCH_QUERY,
|
|
1769
|
+
MESSAGE_PARSING,
|
|
1770
|
+
searchError,
|
|
1771
|
+
searchTimeLimit,
|
|
1772
|
+
outOfTime,
|
|
1773
|
+
isQueryLimit,
|
|
1774
|
+
sqliteLimit,
|
|
1775
|
+
exhausted,
|
|
1776
|
+
tooWideTerm,
|
|
1777
|
+
isEmailAddress,
|
|
1778
|
+
isNoReplyAddress,
|
|
1779
|
+
isRoleAddress,
|
|
1780
|
+
isPersonLikeRoleAddress,
|
|
1781
|
+
isNotificationAddress,
|
|
1782
|
+
SEPARATIONS,
|
|
1783
|
+
mergeSql,
|
|
1784
|
+
mergedAwaySql,
|
|
1785
|
+
currentPerson,
|
|
1786
|
+
samePersons,
|
|
1787
|
+
idsOf,
|
|
1788
|
+
amountsOf,
|
|
1789
|
+
dueDayOf,
|
|
1790
|
+
STOP_WORDS,
|
|
1791
|
+
taskWordsOf,
|
|
1792
|
+
taskStemsOf,
|
|
1793
|
+
prepareTask,
|
|
1794
|
+
compareViews,
|
|
1795
|
+
rankCandidates,
|
|
1796
|
+
TASK_KEY_PREFIXES,
|
|
1797
|
+
typedKey,
|
|
1798
|
+
INBOX_KEY_LENGTH,
|
|
1799
|
+
inboxKey,
|
|
1800
|
+
linkInbox,
|
|
1801
|
+
taskAccountOf,
|
|
1802
|
+
TASK_SORTS,
|
|
1803
|
+
PROJECT_TASK_FIELDS,
|
|
1804
|
+
dueGroups,
|
|
1805
|
+
projectTaskColumns,
|
|
1806
|
+
PROJECT_SCOPE,
|
|
1807
|
+
BOARD_SCOPE,
|
|
1808
|
+
boardOrder,
|
|
1809
|
+
withoutField,
|
|
1810
|
+
TASK_PEOPLE,
|
|
1811
|
+
mergedAssignees,
|
|
1812
|
+
SMALL_GROUP_MEMBERS,
|
|
1813
|
+
PERSON_TIES,
|
|
1814
|
+
ALWAYS_SHOWN,
|
|
1815
|
+
shownReasons,
|
|
1816
|
+
REACHES,
|
|
1817
|
+
senderSignalsOf,
|
|
1818
|
+
LIST_ID,
|
|
1819
|
+
LIST_SENDERS,
|
|
1820
|
+
senderKey,
|
|
1821
|
+
sentMailOf,
|
|
1822
|
+
MAIL_TYPES,
|
|
1823
|
+
mailTypeOf,
|
|
1824
|
+
schemaTypesOf,
|
|
1825
|
+
FIELD_VERSION,
|
|
1826
|
+
parseBytes,
|
|
1827
|
+
QUERY_FIELDS,
|
|
1828
|
+
isPresence,
|
|
1829
|
+
PRESENCE,
|
|
1830
|
+
validateFields,
|
|
1831
|
+
validateAst,
|
|
1832
|
+
plainQuery,
|
|
1833
|
+
RRF_K,
|
|
1834
|
+
fuseRanked
|
|
1835
|
+
};
|