@wirecat/cli-core 0.623.0 → 0.625.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 +85 -0
- package/dist/background/backfill.d.ts +1 -1
- package/dist/background/backfill.js +1 -1
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/background/report/stored-templates.d.ts +21 -3
- package/dist/background/report/stored-templates.js +34 -6
- package/dist/background/schedules.d.ts +10 -20
- package/dist/background/schedules.js +8 -162
- package/dist/background/timers.d.ts +19 -0
- package/dist/background/timers.js +175 -0
- package/dist/background/when.d.ts +28 -7
- package/dist/background/when.js +55 -11
- package/dist/calendar/prepare.d.ts +14 -0
- package/dist/cli/app-doctor-command.js +2 -1
- package/dist/cli/envelope.d.ts +28 -0
- package/dist/cli/index.d.ts +3 -2
- package/dist/cli/index.js +3 -2
- package/dist/cli/schedule/schedule-command.d.ts +100 -3
- package/dist/cli/schedule/schedule-command.js +276 -118
- package/dist/cli/templates-command.js +45 -20
- package/dist/domain/display-names.d.ts +5 -2
- package/dist/domain/display-names.js +13 -4
- package/dist/domain/person-kinds.d.ts +9 -0
- package/dist/domain/person-kinds.js +67 -0
- package/dist/domain/records-table.d.ts +61 -0
- package/dist/domain/records-table.js +382 -0
- package/dist/entities/index.d.ts +2 -1
- package/dist/entities/list-results.d.ts +2 -0
- package/dist/entities/list-results.js +2 -0
- package/dist/entities/template.d.ts +1 -1
- package/dist/entities/template.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp/surface.js +23 -2
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/search-harder.d.ts +6 -1
- package/dist/services/search-harder.js +9 -2
- package/dist/store/index.d.ts +2 -1
- package/dist/store/index.js +2 -0
- package/dist/store/people.d.ts +4 -3
- package/dist/store/sqlite/people-list.d.ts +23 -8
- package/dist/store/sqlite/people-list.js +189 -65
- package/package.json +2 -2
- package/parity.json +29 -0
|
@@ -2,19 +2,20 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import { CliError
|
|
5
|
+
import { CliError } from "@wirecat/cli-base";
|
|
6
6
|
import { annotate } from "@wirecat/cli-base/commands";
|
|
7
7
|
import { queryFieldsOf } from "@wirecat/cli-base/query";
|
|
8
8
|
import { Command, Option } from "commander";
|
|
9
9
|
import { checkTemplate, defaultTemplate, REPORT_CHANNELS, renderReport, } from "../background/report/render.js";
|
|
10
|
-
import { checkTemplateSave, previewView, shippedLanguages, TEMPLATE_KEYS, templateKeyOf, } from "../background/report/stored-templates.js";
|
|
10
|
+
import { checkTemplateSave, previewView, reportKeyOf, reportKeysOf, shippedLanguages, TEMPLATE_KEYS, templateKeyOf, } from "../background/report/stored-templates.js";
|
|
11
|
+
import { listSchedules } from "../background/schedules.js";
|
|
11
12
|
import { template } from "../entities/index.js";
|
|
12
13
|
import { agentOf } from "../runs/run-context.js";
|
|
13
14
|
import { openStore } from "../store/store.js";
|
|
14
15
|
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "./effects.js";
|
|
15
16
|
import { itemOf, listOf } from "./envelope.js";
|
|
16
17
|
import { queryTerms, withQuery } from "./list-query.js";
|
|
17
|
-
import { ownerLanguageOf } from "./schedule/schedule-command.js";
|
|
18
|
+
import { ownerLanguageOf, scheduleState } from "./schedule/schedule-command.js";
|
|
18
19
|
const withStore = async (env, work) => {
|
|
19
20
|
const store = await openStore({ env });
|
|
20
21
|
try {
|
|
@@ -53,18 +54,32 @@ const TEMPLATES_QUERY = {
|
|
|
53
54
|
};
|
|
54
55
|
const matching = (rows, terms) => rows.filter((row) => [...terms].every(([field, value]) => String(row[field]).toLowerCase() === value.toLowerCase()));
|
|
55
56
|
/** The key, its message kind and the language, refused when cli-core ships no template in that language. */
|
|
56
|
-
const addressOf = async (key, given, env) => {
|
|
57
|
-
const known = templateKeyOf(key)
|
|
57
|
+
const addressOf = async (key, given, env, state) => {
|
|
58
|
+
const known = templateKeyOf(key) ??
|
|
59
|
+
reportKeyOf(key, [
|
|
60
|
+
...listSchedules(state, { kind: "agent" }).map((one) => one.name),
|
|
61
|
+
// A removed schedule's templates stay in the store, and must still be shown and reset.
|
|
62
|
+
...(await withStore(env, (store) => store.templates.list())).flatMap((row) => row.key.startsWith("report/") ? [row.key.slice("report/".length)] : []),
|
|
63
|
+
]);
|
|
58
64
|
if (!known)
|
|
59
|
-
throw new CliError("validation_error", `no template ${key}; the keys are ${TEMPLATE_KEYS.map((one) => one.key).join(", ")}`, {
|
|
65
|
+
throw new CliError("validation_error", `no template ${key}; the keys are ${TEMPLATE_KEYS.map((one) => one.key).join(", ")}, or report/<schedule> for an agent schedule's digest`, {
|
|
60
66
|
reason: "template.unknown-key",
|
|
61
67
|
});
|
|
62
68
|
const language = (given.locale ?? (await ownerLanguageOf(env))).trim().toLowerCase();
|
|
63
69
|
const languages = shippedLanguages(known.kind);
|
|
64
70
|
if (!languages.includes(language))
|
|
65
71
|
throw new CliError("validation_error", `${key} has templates in ${languages.join(", ")}; a ${language} one would never be used`, { reason: "template.unknown-language" });
|
|
66
|
-
return {
|
|
72
|
+
return {
|
|
73
|
+
address: { key, channel: given.channel, language },
|
|
74
|
+
kind: known.kind,
|
|
75
|
+
channel: given.channel,
|
|
76
|
+
...(known.schedule ? { schedule: known.schedule } : {}),
|
|
77
|
+
};
|
|
67
78
|
};
|
|
79
|
+
/** The stored body that applies to `address`: its own, else the one its digest falls back to; undefined for shipped. */
|
|
80
|
+
const appliedBody = (store, address, kind, schedule) => reportKeysOf(kind, schedule)
|
|
81
|
+
.map((key) => store.templates.get({ ...address, key })?.body)
|
|
82
|
+
.find((body) => body !== undefined);
|
|
68
83
|
const refuseAgent = (env) => {
|
|
69
84
|
// A template decides what every later digest says to the owner; an agent could make it hide or invent things.
|
|
70
85
|
if (agentOf(env))
|
|
@@ -72,7 +87,7 @@ const refuseAgent = (env) => {
|
|
|
72
87
|
reason: "template.owner-only",
|
|
73
88
|
});
|
|
74
89
|
};
|
|
75
|
-
const stateOf = (app, env) =>
|
|
90
|
+
const stateOf = (app, env) => scheduleState({ app, env });
|
|
76
91
|
const historyOf = (store, address) => store.templates.history(address).map((entry) => ({
|
|
77
92
|
id: entry.id,
|
|
78
93
|
saved_at: new Date(entry.savedAt).toISOString(),
|
|
@@ -100,15 +115,21 @@ export const templatesCommand = (app, options) => {
|
|
|
100
115
|
const terms = queryTerms(words, TEMPLATES_QUERY, "templates list");
|
|
101
116
|
const env = options.env();
|
|
102
117
|
const stored = await withStore(env, (store) => store.templates.list());
|
|
103
|
-
const
|
|
104
|
-
const
|
|
118
|
+
const own = [...new Set(stored.map((one) => one.key))].flatMap((key) => {
|
|
119
|
+
const known = reportKeyOf(key, [key.slice("report/".length)]);
|
|
120
|
+
return known?.schedule ? [known] : [];
|
|
121
|
+
});
|
|
122
|
+
const items = [...TEMPLATE_KEYS, ...own].flatMap((known) => REPORT_CHANNELS.flatMap((channel) => shippedLanguages(known.kind).map((language) => {
|
|
123
|
+
const rowOf = (key) => stored.find((one) => one.key === key && one.channel === channel && one.language === language);
|
|
124
|
+
const row = rowOf(known.key);
|
|
125
|
+
const inherited = !row && "schedule" in known && reportKeysOf(known.kind, known.schedule).some((key) => rowOf(key));
|
|
105
126
|
return {
|
|
106
127
|
key: known.key,
|
|
107
128
|
channel,
|
|
108
129
|
language,
|
|
109
130
|
about: known.about,
|
|
110
131
|
renders: true,
|
|
111
|
-
source: row ? "stored" : "default",
|
|
132
|
+
source: row ? "stored" : inherited ? "inherited" : "default",
|
|
112
133
|
updated_at: row ? new Date(row.updatedAt).toISOString() : null,
|
|
113
134
|
updated_by: row?.updatedBy ?? null,
|
|
114
135
|
};
|
|
@@ -127,13 +148,14 @@ export const templatesCommand = (app, options) => {
|
|
|
127
148
|
.addOption(localeOption())
|
|
128
149
|
.action(async function (key, given) {
|
|
129
150
|
const env = options.env();
|
|
130
|
-
const { address, kind, channel } = await addressOf(key, given, env);
|
|
151
|
+
const { address, kind, channel, schedule } = await addressOf(key, given, env, stateOf(app, env));
|
|
131
152
|
const item = await withStore(env, (store) => {
|
|
132
153
|
const row = store.templates.get(address);
|
|
154
|
+
const applied = appliedBody(store, address, kind, schedule);
|
|
133
155
|
return {
|
|
134
156
|
...address,
|
|
135
|
-
source: row ? "stored" : "default",
|
|
136
|
-
body:
|
|
157
|
+
source: row ? "stored" : applied === undefined ? "default" : "inherited",
|
|
158
|
+
body: applied ?? defaultTemplate(kind, channel, address.language),
|
|
137
159
|
updated_at: row ? new Date(row.updatedAt).toISOString() : null,
|
|
138
160
|
updated_by: row?.updatedBy ?? null,
|
|
139
161
|
history: historyOf(store, address),
|
|
@@ -159,9 +181,9 @@ export const templatesCommand = (app, options) => {
|
|
|
159
181
|
.action(async function (key, given) {
|
|
160
182
|
const env = options.env();
|
|
161
183
|
refuseAgent(env);
|
|
162
|
-
const { address, kind, channel } = await addressOf(key, given, env);
|
|
184
|
+
const { address, kind, channel, schedule } = await addressOf(key, given, env, stateOf(app, env));
|
|
163
185
|
const { current, previous } = await withStore(env, (store) => ({
|
|
164
|
-
current: store
|
|
186
|
+
current: appliedBody(store, address, kind, schedule),
|
|
165
187
|
previous: store.templates.history(address, 1)[0]?.body,
|
|
166
188
|
}));
|
|
167
189
|
const effective = current ?? defaultTemplate(kind, channel, address.language);
|
|
@@ -197,6 +219,7 @@ export const templatesCommand = (app, options) => {
|
|
|
197
219
|
body,
|
|
198
220
|
state: stateOf(app, env),
|
|
199
221
|
now: Date.now(),
|
|
222
|
+
...(schedule ? { schedule } : {}),
|
|
200
223
|
});
|
|
201
224
|
const problems = checks.flatMap((check) => check.problems.map((problem) => `${check.against}: ${problem}`));
|
|
202
225
|
if (problems.length > 0)
|
|
@@ -228,10 +251,12 @@ export const templatesCommand = (app, options) => {
|
|
|
228
251
|
.option("--file <file>", "preview this draft instead of the template that applies; - reads stdin")
|
|
229
252
|
.action(async function (key, given) {
|
|
230
253
|
const env = options.env();
|
|
231
|
-
const { address, kind, channel } = await addressOf(key, given, env);
|
|
232
|
-
const stored = given.file === undefined
|
|
254
|
+
const { address, kind, channel, schedule } = await addressOf(key, given, env, stateOf(app, env));
|
|
255
|
+
const stored = given.file === undefined
|
|
256
|
+
? await withStore(env, (store) => appliedBody(store, address, kind, schedule))
|
|
257
|
+
: undefined;
|
|
233
258
|
const body = given.file === undefined ? stored : readFileSync(given.file === "-" ? 0 : given.file, "utf8");
|
|
234
|
-
const { against, view } = previewView(stateOf(app, env), kind, address.language, Date.now());
|
|
259
|
+
const { against, view } = previewView(stateOf(app, env), kind, address.language, Date.now(), schedule);
|
|
235
260
|
const rendering = await renderReport(view, channel, body === undefined ? {} : { template: body });
|
|
236
261
|
const problems = body === undefined ? [] : (await checkTemplate(view, channel, body)).problems;
|
|
237
262
|
options.output(itemOf({
|
|
@@ -255,7 +280,7 @@ export const templatesCommand = (app, options) => {
|
|
|
255
280
|
.action(async function (key, given) {
|
|
256
281
|
const env = options.env();
|
|
257
282
|
refuseAgent(env);
|
|
258
|
-
const { address } = await addressOf(key, given, env);
|
|
283
|
+
const { address } = await addressOf(key, given, env, stateOf(app, env));
|
|
259
284
|
const changed = await withStore(env, (store) => store.templates.reset(address));
|
|
260
285
|
options.diagnostic(changed
|
|
261
286
|
? `${key} ${address.channel} ${address.language} uses the shipped template again`
|
|
@@ -5,8 +5,9 @@ export interface NameFallbacks {
|
|
|
5
5
|
email?: string | null;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* A name as it is shown: no wrapping quotes, no repeated or edge spaces. One with no letter or digit (`!`, `!$`)
|
|
9
|
-
* way to the username, then the phone, then the email; the stored name
|
|
8
|
+
* A name as it is shown: no wrapping quotes, no repeated or edge spaces. One with no letter or digit (`!`, `!$`), or a
|
|
9
|
+
* placeholder such as `null` or «Без имени», gives way to the username, then the phone, then the email; the stored name
|
|
10
|
+
* stays as it came.
|
|
10
11
|
*/
|
|
11
12
|
export declare const displayName: (name: string | null | undefined, fallbacks?: NameFallbacks) => string | null;
|
|
12
13
|
/**
|
|
@@ -14,3 +15,5 @@ export declare const displayName: (name: string | null | undefined, fallbacks?:
|
|
|
14
15
|
* `ivan IVANOV` give one key. `null` for a name with no letter or digit, which matches nobody.
|
|
15
16
|
*/
|
|
16
17
|
export declare const nameKey: (name: string | null | undefined) => string | null;
|
|
18
|
+
/** Whether a shown name has anything to read: not null, not only punctuation. */
|
|
19
|
+
export declare const isReadable: (shown: string | null) => boolean;
|
|
@@ -9,6 +9,8 @@ const QUOTES = [
|
|
|
9
9
|
["`", "`"],
|
|
10
10
|
];
|
|
11
11
|
const READABLE = /[\p{L}\p{N}]/u;
|
|
12
|
+
/** What a source writes when it has no name: no name at all. */
|
|
13
|
+
const PLACEHOLDERS = new Set(["null", "undefined", "none", "без имени", "deleted account", "удалённый аккаунт"]);
|
|
12
14
|
const unquoted = (text) => {
|
|
13
15
|
let at = text.replace(/\s+/gu, " ").trim();
|
|
14
16
|
for (;;) {
|
|
@@ -23,11 +25,13 @@ const given = (value) => {
|
|
|
23
25
|
return text === "" ? undefined : text;
|
|
24
26
|
};
|
|
25
27
|
/**
|
|
26
|
-
* A name as it is shown: no wrapping quotes, no repeated or edge spaces. One with no letter or digit (`!`, `!$`)
|
|
27
|
-
* way to the username, then the phone, then the email; the stored name
|
|
28
|
+
* A name as it is shown: no wrapping quotes, no repeated or edge spaces. One with no letter or digit (`!`, `!$`), or a
|
|
29
|
+
* placeholder such as `null` or «Без имени», gives way to the username, then the phone, then the email; the stored name
|
|
30
|
+
* stays as it came.
|
|
28
31
|
*/
|
|
29
32
|
export const displayName = (name, fallbacks = {}) => {
|
|
30
|
-
const
|
|
33
|
+
const unwrapped = typeof name === "string" ? unquoted(name) : "";
|
|
34
|
+
const cleaned = PLACEHOLDERS.has(unwrapped.toLowerCase()) ? "" : unwrapped;
|
|
31
35
|
if (READABLE.test(cleaned))
|
|
32
36
|
return cleaned;
|
|
33
37
|
const username = given(fallbacks.username);
|
|
@@ -43,8 +47,13 @@ export const displayName = (name, fallbacks = {}) => {
|
|
|
43
47
|
export const nameKey = (name) => {
|
|
44
48
|
if (typeof name !== "string")
|
|
45
49
|
return null;
|
|
46
|
-
const
|
|
50
|
+
const unwrapped = unquoted(name);
|
|
51
|
+
if (PLACEHOLDERS.has(unwrapped.toLowerCase()))
|
|
52
|
+
return null;
|
|
53
|
+
const words = foldName(unwrapped)
|
|
47
54
|
.split(/[^\p{L}\p{N}]+/u)
|
|
48
55
|
.filter((word) => word !== "");
|
|
49
56
|
return words.length === 0 ? null : words.sort().join(" ");
|
|
50
57
|
};
|
|
58
|
+
/** Whether a shown name has anything to read: not null, not only punctuation. */
|
|
59
|
+
export const isReadable = (shown) => shown !== null && READABLE.test(shown);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** What a person in the store is, for a list that shows the useful ones and keeps the noise apart. */
|
|
2
|
+
export declare const PERSON_KINDS: readonly ["person", "organization", "automated", "stranger", "unsorted"];
|
|
3
|
+
export type PersonKind = (typeof PERSON_KINDS)[number];
|
|
4
|
+
/** What decided a kind, besides the ties that make someone a `person`. */
|
|
5
|
+
export type KindSignal = "bot" | "no-reply" | "bulk-mail" | "bulk-never-replied" | "automated-name" | "organization" | "role-address" | "company-name" | "no-tie" | "no-name";
|
|
6
|
+
/** A sender that is a program: «Notifications», «Рассылка», «no-reply». */
|
|
7
|
+
export declare const isAutomatedName: (name: string | null) => boolean;
|
|
8
|
+
/** A legal form or a word only a business calls itself: «ООО Ромашка», «CZECH AIRLINES», «OpenWeather Team». */
|
|
9
|
+
export declare const isCompanyName: (name: string | null) => boolean;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** What a person in the store is, for a list that shows the useful ones and keeps the noise apart. */
|
|
2
|
+
export const PERSON_KINDS = ["person", "organization", "automated", "stranger", "unsorted"];
|
|
3
|
+
const AUTOMATED_WORDS = new Set([
|
|
4
|
+
"noreply",
|
|
5
|
+
"notification",
|
|
6
|
+
"notifications",
|
|
7
|
+
"newsletter",
|
|
8
|
+
"newsletters",
|
|
9
|
+
"digest",
|
|
10
|
+
"alerts",
|
|
11
|
+
"mailer",
|
|
12
|
+
"robot",
|
|
13
|
+
]);
|
|
14
|
+
const AUTOMATED_STEMS = ["уведомлени", "рассылк", "оповещени", "noreply", "donotreply", "робот"];
|
|
15
|
+
const LEGAL_FORMS = new Set(["ооо", "оао", "зао", "пао", "ао", "ип", "llc", "ltd", "limited", "inc", "corp", "gmbh"]);
|
|
16
|
+
const COMPANY_WORDS = new Set([
|
|
17
|
+
"airlines",
|
|
18
|
+
"airways",
|
|
19
|
+
"bank",
|
|
20
|
+
"банк",
|
|
21
|
+
"hotel",
|
|
22
|
+
"hotels",
|
|
23
|
+
"отель",
|
|
24
|
+
"гостиница",
|
|
25
|
+
"hostel",
|
|
26
|
+
"хостел",
|
|
27
|
+
"апартаменты",
|
|
28
|
+
"team",
|
|
29
|
+
"support",
|
|
30
|
+
"поддержка",
|
|
31
|
+
"service",
|
|
32
|
+
"services",
|
|
33
|
+
"сервис",
|
|
34
|
+
"служба",
|
|
35
|
+
"shop",
|
|
36
|
+
"store",
|
|
37
|
+
"магазин",
|
|
38
|
+
"company",
|
|
39
|
+
"компания",
|
|
40
|
+
"agency",
|
|
41
|
+
"агентство",
|
|
42
|
+
"restaurant",
|
|
43
|
+
"ресторан",
|
|
44
|
+
"clinic",
|
|
45
|
+
"клиника",
|
|
46
|
+
"delivery",
|
|
47
|
+
"доставка",
|
|
48
|
+
]);
|
|
49
|
+
const wordsOf = (name) => name
|
|
50
|
+
.toLowerCase()
|
|
51
|
+
.split(/[^\p{L}\p{N}-]+/u)
|
|
52
|
+
.filter((word) => word !== "");
|
|
53
|
+
/** A sender that is a program: «Notifications», «Рассылка», «no-reply». */
|
|
54
|
+
export const isAutomatedName = (name) => {
|
|
55
|
+
if (name === null)
|
|
56
|
+
return false;
|
|
57
|
+
return wordsOf(name).some((word) => {
|
|
58
|
+
const bare = word.includes("-") ? word.replaceAll("-", "") : word;
|
|
59
|
+
return AUTOMATED_WORDS.has(bare) || AUTOMATED_STEMS.some((stem) => bare.startsWith(stem));
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
/** A legal form or a word only a business calls itself: «ООО Ромашка», «CZECH AIRLINES», «OpenWeather Team». */
|
|
63
|
+
export const isCompanyName = (name) => {
|
|
64
|
+
if (name === null)
|
|
65
|
+
return false;
|
|
66
|
+
return wordsOf(name.replaceAll(".", "")).some((word) => LEGAL_FORMS.has(word) || COMPANY_WORDS.has(word));
|
|
67
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type EnvelopeOptions, type EnvelopeSource, type IngestError, type RecordsEnvelope } from "./records.js";
|
|
2
|
+
/** The types a table can carry: an SMS and a call come from a phone's own export, never from a hand-made sheet. */
|
|
3
|
+
export declare const TABLE_RECORD_TYPES: readonly string[];
|
|
4
|
+
export type ColumnShape = "text" | "decimal" | "day" | "instant" | "currency" | "integer" | "boolean" | "list";
|
|
5
|
+
export interface TableColumn {
|
|
6
|
+
/** `external_id`, a field (`total`), a role (`counterparty`) or an item of a list (`lines.amount`). */
|
|
7
|
+
name: string;
|
|
8
|
+
kind: "id" | "field" | "role" | "item";
|
|
9
|
+
required: boolean;
|
|
10
|
+
shape: ColumnShape;
|
|
11
|
+
description: string;
|
|
12
|
+
values?: readonly string[];
|
|
13
|
+
/** A role's target types: one names the target's external id, several take `<type>:<external id>`. */
|
|
14
|
+
targets?: readonly string[];
|
|
15
|
+
/** Several values in the cell, split by `|`. */
|
|
16
|
+
many?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Where a pointer into the envelope came from in the sheet: its line from 1 (the header is 1), and the column. */
|
|
19
|
+
export interface TablePlace {
|
|
20
|
+
line: number;
|
|
21
|
+
column?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface TableEnvelope {
|
|
24
|
+
envelope: RecordsEnvelope;
|
|
25
|
+
/** The sheet's place of a receipt's or an error's pointer, by its longest known prefix. */
|
|
26
|
+
placeOf(pointer: string): TablePlace | undefined;
|
|
27
|
+
}
|
|
28
|
+
export declare class TableError extends Error {
|
|
29
|
+
readonly errors: (IngestError & {
|
|
30
|
+
place?: TablePlace;
|
|
31
|
+
})[];
|
|
32
|
+
constructor(errors: (IngestError & {
|
|
33
|
+
place?: TablePlace;
|
|
34
|
+
})[]);
|
|
35
|
+
}
|
|
36
|
+
/** A type's columns: the external id, its flat fields, one per role, then one per key of each list of items. */
|
|
37
|
+
export declare const recordColumns: (type: string) => TableColumn[];
|
|
38
|
+
/**
|
|
39
|
+
* A file to fill for a type. CSV is the header row alone, with a byte-order mark so Excel reads it as UTF-8; JSON is
|
|
40
|
+
* an envelope of one example record that names every field and role.
|
|
41
|
+
*/
|
|
42
|
+
export declare const recordTemplate: (type: string, format: "csv" | "json", { source, separator }?: {
|
|
43
|
+
source?: Partial<EnvelopeSource>;
|
|
44
|
+
separator?: string;
|
|
45
|
+
}) => string;
|
|
46
|
+
/** RFC 4180 rows; a separator inside quotes, a doubled quote and a line break inside quotes are part of the cell. */
|
|
47
|
+
export declare const csvRows: (text: string, separator: string) => {
|
|
48
|
+
cells: string[];
|
|
49
|
+
line: number;
|
|
50
|
+
}[];
|
|
51
|
+
/** The header's separator: Excel saves `;` where the decimal mark is a comma, as in Russian or Spanish. */
|
|
52
|
+
export declare const csvSeparator: (header: string) => string;
|
|
53
|
+
/**
|
|
54
|
+
* Reads a sheet of one type as an envelope. A row whose `external_id` an earlier row had continues that record: its
|
|
55
|
+
* item columns (`lines.amount`) add one item to the list, as an invoice exported a line a row does.
|
|
56
|
+
*/
|
|
57
|
+
export declare const envelopeOfCsv: (text: string, { type, source, options }: {
|
|
58
|
+
type: string;
|
|
59
|
+
source: EnvelopeSource;
|
|
60
|
+
options?: EnvelopeOptions;
|
|
61
|
+
}) => TableEnvelope;
|