@wirecat/cli-core 0.606.0 → 0.608.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 +196 -0
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/reads.js +5 -0
- package/dist/cli/app-mcp-command.d.ts +6 -2
- package/dist/cli/app-mcp-command.js +11 -2
- package/dist/cli/csv.d.ts +10 -0
- package/dist/cli/csv.js +22 -0
- package/dist/cli/early-refusal.d.ts +10 -0
- package/dist/cli/early-refusal.js +19 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/profile-token.d.ts +29 -0
- package/dist/cli/profile-token.js +65 -0
- package/dist/cli/program.js +4 -2
- package/dist/crm/cli/csv.d.ts +23 -0
- package/dist/crm/cli/csv.js +135 -0
- package/dist/crm/cli/index.d.ts +1 -1
- package/dist/crm/cli/index.js +33 -21
- package/dist/crm/cli/pipeline-view.d.ts +3 -0
- package/dist/crm/cli/pipeline-view.js +36 -0
- package/dist/crm/writes.d.ts +6 -4
- package/dist/crm/writes.js +17 -13
- package/dist/documents.d.ts +2 -0
- package/dist/documents.js +2 -0
- package/dist/domain/business.d.ts +79 -0
- package/dist/domain/business.js +42 -0
- package/dist/domain/finance.d.ts +2 -0
- package/dist/domain/finance.js +2 -2
- package/dist/domain/google-documents.d.ts +2 -0
- package/dist/domain/google-documents.js +3 -1
- package/dist/domain/money.d.ts +2 -0
- package/dist/domain/money.js +11 -3
- package/dist/domain/providers.d.ts +36 -1
- package/dist/domain/providers.js +69 -7
- package/dist/domain/record-fields.d.ts +42 -0
- package/dist/domain/record-fields.js +122 -0
- package/dist/domain/record-types.d.ts +489 -16
- package/dist/domain/record-types.js +374 -7
- package/dist/domain/records.d.ts +96 -5
- package/dist/domain/records.js +178 -32
- package/dist/domain/ref-summaries.js +5 -0
- package/dist/domain/references.d.ts +1 -1
- package/dist/domain/references.js +5 -0
- package/dist/domain/vcard.d.ts +25 -0
- package/dist/domain/vcard.js +267 -0
- package/dist/entities/deal.d.ts +14 -0
- package/dist/entities/deal.js +3 -0
- package/dist/entities/index.d.ts +12 -0
- package/dist/errors/reasons.js +63 -4
- package/dist/fetch/addresses.d.ts +5 -0
- package/dist/fetch/addresses.js +76 -0
- package/dist/fetch/page.d.ts +64 -0
- package/dist/fetch/page.js +256 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/dist/meetings/calendar-text.d.ts +1 -1
- package/dist/meetings/calendar-text.js +4 -0
- package/dist/meetings/event-store.d.ts +2 -2
- package/dist/search/account-list.d.ts +4 -0
- package/dist/search/account-list.js +19 -8
- package/dist/search/query.js +2 -2
- package/dist/services/events-search.js +2 -2
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/ingest.d.ts +56 -8
- package/dist/services/ingest.js +95 -61
- package/dist/services/messages-search.js +3 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/notes-search.js +1 -0
- package/dist/services/proposals/kinds/contracts.d.ts +4 -0
- package/dist/services/proposals/kinds/contracts.js +9 -0
- package/dist/services/proposals/kinds/finance.d.ts +4 -0
- package/dist/services/proposals/kinds/finance.js +14 -35
- package/dist/services/proposals/kinds/orders.js +7 -30
- package/dist/services/proposals/kinds/shared.d.ts +27 -1
- package/dist/services/proposals/kinds/shared.js +34 -0
- package/dist/services/proposals/kinds/source-review.d.ts +4 -0
- package/dist/services/proposals/kinds/source-review.js +45 -0
- package/dist/services/proposals/kinds/subscriptions.d.ts +9 -0
- package/dist/services/proposals/kinds/subscriptions.js +24 -0
- package/dist/services/proposals/kinds/transactions.d.ts +4 -0
- package/dist/services/proposals/kinds/transactions.js +10 -0
- package/dist/services/proposals/registry.js +9 -0
- package/dist/services/search-all-meetings.js +2 -2
- package/dist/services/search-all.js +4 -3
- package/dist/services/search-kind.js +3 -3
- package/dist/store/decisions.js +5 -1
- package/dist/store/index.d.ts +14 -3
- package/dist/store/index.js +3 -0
- package/dist/store/people.js +1 -1
- package/dist/store/source-review.d.ts +64 -0
- package/dist/store/source-review.js +7 -0
- package/dist/store/sqlite/accounts.d.ts +1 -1
- package/dist/store/sqlite/accounts.js +24 -1
- package/dist/store/sqlite/added-sources.d.ts +82 -0
- package/dist/store/sqlite/added-sources.js +237 -0
- package/dist/store/sqlite/business-contracts.d.ts +90 -0
- package/dist/store/sqlite/business-contracts.js +182 -0
- package/dist/store/sqlite/calendar-events.js +7 -3
- package/dist/store/sqlite/calendar-forget.js +3 -0
- package/dist/store/sqlite/calendar.d.ts +21 -1
- package/dist/store/sqlite/calendar.js +27 -7
- package/dist/store/sqlite/chat-rekey.js +7 -0
- package/dist/store/sqlite/chats.d.ts +3 -1
- package/dist/store/sqlite/chats.js +15 -1
- package/dist/store/sqlite/crm-rows.d.ts +44 -0
- package/dist/store/sqlite/crm-rows.js +195 -0
- package/dist/store/sqlite/crm.d.ts +2 -11
- package/dist/store/sqlite/crm.js +11 -166
- package/dist/store/sqlite/deals.d.ts +4 -8
- package/dist/store/sqlite/deals.js +5 -3
- package/dist/store/sqlite/document-transfer/snapshot.js +2 -2
- package/dist/store/sqlite/emails.js +2 -0
- package/dist/store/sqlite/entity-types.d.ts +14 -9
- package/dist/store/sqlite/entity-types.js +4 -10
- package/dist/store/sqlite/evidence-signature.d.ts +114 -0
- package/dist/store/sqlite/evidence-signature.js +349 -0
- package/dist/store/sqlite/evidence-sources.d.ts +2 -1
- package/dist/store/sqlite/evidence-sources.js +7 -3
- package/dist/store/sqlite/facts.d.ts +7 -2
- package/dist/store/sqlite/facts.js +21 -5
- package/dist/store/sqlite/finance.d.ts +18 -105
- package/dist/store/sqlite/finance.js +100 -219
- package/dist/store/sqlite/knowledge.d.ts +8 -2
- package/dist/store/sqlite/knowledge.js +65 -71
- package/dist/store/sqlite/labelled.d.ts +3 -0
- package/dist/store/sqlite/labelled.js +11 -0
- package/dist/store/sqlite/link-kinds.d.ts +2 -0
- package/dist/store/sqlite/link-kinds.js +2 -0
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/memories.d.ts +23 -9
- package/dist/store/sqlite/memories.js +41 -13
- package/dist/store/sqlite/messages.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +103 -0
- package/dist/store/sqlite/money-lines.d.ts +48 -0
- package/dist/store/sqlite/money-lines.js +76 -0
- package/dist/store/sqlite/money-transactions.d.ts +132 -0
- package/dist/store/sqlite/money-transactions.js +295 -0
- package/dist/store/sqlite/notes.d.ts +11 -2
- package/dist/store/sqlite/notes.js +20 -25
- package/dist/store/sqlite/orders.d.ts +36 -6
- package/dist/store/sqlite/orders.js +126 -46
- package/dist/store/sqlite/payment-facts.js +1 -1
- package/dist/store/sqlite/private-people.js +2 -0
- package/dist/store/sqlite/products.d.ts +78 -0
- package/dist/store/sqlite/products.js +131 -0
- package/dist/store/sqlite/project-transfer/records.js +26 -1
- package/dist/store/sqlite/project-transfer/snapshot.js +5 -3
- package/dist/store/sqlite/proposed-actions.d.ts +1 -1
- package/dist/store/sqlite/proposed-actions.js +24 -7
- package/dist/store/sqlite/providers.d.ts +0 -4
- package/dist/store/sqlite/providers.js +20 -2
- package/dist/store/sqlite/record-matching.d.ts +80 -0
- package/dist/store/sqlite/record-matching.js +264 -0
- package/dist/store/sqlite/record-projection.d.ts +89 -0
- package/dist/store/sqlite/record-projection.js +50 -0
- package/dist/store/sqlite/record-projectors-direct.d.ts +17 -0
- package/dist/store/sqlite/record-projectors-direct.js +125 -0
- package/dist/store/sqlite/record-projectors-money.d.ts +26 -0
- package/dist/store/sqlite/record-projectors-money.js +214 -0
- package/dist/store/sqlite/record-projectors-phone.d.ts +28 -0
- package/dist/store/sqlite/record-projectors-phone.js +212 -0
- package/dist/store/sqlite/record-projectors.d.ts +3 -44
- package/dist/store/sqlite/record-projectors.js +7 -67
- package/dist/store/sqlite/record-relations.d.ts +24 -0
- package/dist/store/sqlite/record-relations.js +92 -0
- package/dist/store/sqlite/record-remap.d.ts +12 -0
- package/dist/store/sqlite/record-remap.js +92 -0
- package/dist/store/sqlite/record-run.d.ts +71 -0
- package/dist/store/sqlite/record-run.js +179 -0
- package/dist/store/sqlite/record-settling.d.ts +9 -0
- package/dist/store/sqlite/record-settling.js +74 -0
- package/dist/store/sqlite/record-stamps.d.ts +13 -0
- package/dist/store/sqlite/record-stamps.js +30 -0
- package/dist/store/sqlite/record-writes.d.ts +43 -0
- package/dist/store/sqlite/record-writes.js +307 -0
- package/dist/store/sqlite/records.d.ts +52 -42
- package/dist/store/sqlite/records.js +123 -353
- package/dist/store/sqlite/ref-summaries.d.ts +6 -5
- package/dist/store/sqlite/ref-summaries.js +60 -8
- package/dist/store/sqlite/refunds.d.ts +31 -0
- package/dist/store/sqlite/refunds.js +112 -0
- package/dist/store/sqlite/reviewed.d.ts +109 -0
- package/dist/store/sqlite/reviewed.js +173 -0
- package/dist/store/sqlite/schema.d.ts +2840 -83
- package/dist/store/sqlite/schema.js +256 -1
- package/dist/store/sqlite/source-review-marks.d.ts +54 -0
- package/dist/store/sqlite/source-review-marks.js +143 -0
- package/dist/store/sqlite/source-review.d.ts +54 -0
- package/dist/store/sqlite/source-review.js +221 -0
- package/dist/store/sqlite/stage-amounts.d.ts +14 -0
- package/dist/store/sqlite/stage-amounts.js +23 -0
- package/dist/store/sqlite/subscriptions.d.ts +135 -0
- package/dist/store/sqlite/subscriptions.js +294 -0
- package/dist/store/sqlite/text-input.d.ts +3 -0
- package/dist/store/sqlite/text-input.js +13 -0
- package/dist/store/sqlite/things.js +2 -9
- package/dist/store/sqlite/transaction.d.ts +15 -0
- package/dist/store/sqlite/transaction.js +57 -0
- package/dist/store/sqlite/wallets.d.ts +88 -0
- package/dist/store/sqlite/wallets.js +143 -0
- package/dist/store/store-errors.d.ts +1 -0
- package/dist/store/store-errors.js +45 -0
- package/dist/store/store.d.ts +16 -1
- package/dist/store/store.js +30 -6
- package/package.json +5 -2
- package/schemas/examples/records-business.jsonl +11 -0
- package/schemas/records-envelope.v1.schema.json +1160 -5
|
@@ -5,7 +5,18 @@ export declare const KINDS: readonly ["messages", "mail", "notes", "documents",
|
|
|
5
5
|
export type Kind = (typeof KINDS)[number];
|
|
6
6
|
export interface ProviderEntry {
|
|
7
7
|
name: Provider;
|
|
8
|
+
/** The first of `kinds`: what a build that knows one kind per provider reads. */
|
|
8
9
|
kind: Kind;
|
|
10
|
+
/**
|
|
11
|
+
* Every kind its accounts hold, `kind` first: one phone account holds SMS and calls, so an account group naming it
|
|
12
|
+
* once reaches both. Left out, `[kind]`.
|
|
13
|
+
*/
|
|
14
|
+
kinds?: readonly Kind[];
|
|
15
|
+
/**
|
|
16
|
+
* Its accounts hold only what an import wrote: no messenger or calendar syncs them, so a records import may write
|
|
17
|
+
* messages and events there. Fixed by the first entry of its name; a later one may not turn it on.
|
|
18
|
+
*/
|
|
19
|
+
imported?: boolean;
|
|
9
20
|
aliases: readonly string[];
|
|
10
21
|
/** The CLI that wrote the entry (`zm`, `drive`). One CLI may write several providers, so it is not an alias. */
|
|
11
22
|
command?: string;
|
|
@@ -40,7 +51,15 @@ export declare const folderProviderOf: (format: "obsidian" | "markdown") => "obs
|
|
|
40
51
|
*/
|
|
41
52
|
export declare const DOCUMENT_ACCOUNT_PROVIDERS: readonly ["google-drive"];
|
|
42
53
|
export declare const isDocumentAccountProvider: (provider: string) => boolean;
|
|
43
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* What the owner adds by hand (`saveAddedSource`): one account, `owner`. Neither a folder nor a documents account, so no
|
|
56
|
+
* folder can be bound to it and no sync deletes a source whose file is gone.
|
|
57
|
+
*/
|
|
58
|
+
export declare const ADDED_PROVIDER = "added";
|
|
59
|
+
export declare const ADDED_ACCOUNT = "owner";
|
|
60
|
+
/** Documents `d` outside the added sources: a folder file joined to one would delete it when the file goes. */
|
|
61
|
+
export declare const notAdded = "d.account_id NOT IN (SELECT id FROM accounts WHERE provider = 'added')";
|
|
62
|
+
/** A folder, a documents account or the added sources, in SQL over an `accounts` row's `provider` column. */
|
|
44
63
|
export declare const filesAccountSql: (column?: string) => string;
|
|
45
64
|
/** Notes written in memo have no account row; this is their account. */
|
|
46
65
|
export declare const INTERNAL_NOTES = "internal";
|
|
@@ -48,6 +67,9 @@ export declare const INTERNAL_NOTES = "internal";
|
|
|
48
67
|
export declare const UNKNOWN_PROVIDER = "unknown provider \u2014 run its CLI once";
|
|
49
68
|
/** An entry as a CLI or the store gives it, checked: anything else is a `validation_error`. */
|
|
50
69
|
export declare const providerEntryOf: (value: unknown) => ProviderEntry;
|
|
70
|
+
export declare const kindsOfEntry: (entry: Pick<ProviderEntry, "kind" | "kinds">) => readonly Kind[];
|
|
71
|
+
/** Both lists, the known one's order first: an older build writes the first kind only, and drops none. */
|
|
72
|
+
export declare const unitedKinds: (known: readonly Kind[], entry: readonly Kind[]) => readonly Kind[];
|
|
51
73
|
/** The built-ins and the entries the store or the CLI running gave; what `kindOf` and `providerNamed` read. */
|
|
52
74
|
export declare const providers: () => readonly ProviderEntry[];
|
|
53
75
|
/**
|
|
@@ -67,5 +89,18 @@ export declare const isKind: (word: string) => word is Kind;
|
|
|
67
89
|
export declare const providerNamed: (word: string) => ProviderEntry | undefined;
|
|
68
90
|
/** The kind of a provider the registry knows; `undefined` for one no entry names, which a search skips. */
|
|
69
91
|
export declare const kindIn: (provider: Provider) => Kind | undefined;
|
|
92
|
+
/** Every kind a provider's accounts hold, its `kind` first; empty for one no entry names. */
|
|
93
|
+
export declare const kindsIn: (provider: Provider) => readonly Kind[];
|
|
94
|
+
/**
|
|
95
|
+
* Whether an entry may carry `imported`, beside one stored before (`held`): never for a built-in a sync writes, only
|
|
96
|
+
* as the first entry of its name, and never dropped once given. Answers the flag to store.
|
|
97
|
+
*/
|
|
98
|
+
export declare const importedOf: (entry: ProviderEntry, held: ProviderEntry | undefined) => boolean;
|
|
99
|
+
/** Whether a provider's accounts hold only what imports wrote: the one place a records import writes messages and events. */
|
|
100
|
+
export declare const isImportedProvider: (provider: Provider) => boolean;
|
|
101
|
+
/** Whether a provider's accounts hold `kind`: what a search lane picks its accounts by. */
|
|
102
|
+
export declare const holdsKind: (provider: Provider, kind: Kind) => boolean;
|
|
103
|
+
/** `holdsKind`, with a provider no entry names counted as a messenger, as `kindOf` counts it. */
|
|
104
|
+
export declare const holdsKindOf: (provider: Provider, kind: Kind) => boolean;
|
|
70
105
|
/** A provider the registry does not list counts as a messenger here; a search asks `kindIn` and skips it. */
|
|
71
106
|
export declare const kindOf: (provider: Provider) => Kind;
|
package/dist/domain/providers.js
CHANGED
|
@@ -17,7 +17,10 @@ export const PROVIDERS = [
|
|
|
17
17
|
{ name: "notes", kind: "notes", aliases: [] },
|
|
18
18
|
{ name: "local", kind: "notes", aliases: [] },
|
|
19
19
|
{ name: "obsidian", kind: "notes", aliases: [] },
|
|
20
|
+
{ name: "added", kind: "notes", aliases: [] },
|
|
20
21
|
{ name: "zoom", kind: "meetings", aliases: [] },
|
|
22
|
+
// A phone export's records: its SMS and its calls in the one account the import names.
|
|
23
|
+
{ name: "phone", kind: "messages", kinds: ["messages", "events"], aliases: [], imported: true },
|
|
21
24
|
];
|
|
22
25
|
const LABELS = {
|
|
23
26
|
telegram: "Telegram",
|
|
@@ -27,6 +30,7 @@ const LABELS = {
|
|
|
27
30
|
whatsapp: "WhatsApp",
|
|
28
31
|
"whatsapp-bot": "WhatsApp bot",
|
|
29
32
|
"google-drive": "Google Drive",
|
|
33
|
+
added: "added by hand",
|
|
30
34
|
email: "mail",
|
|
31
35
|
};
|
|
32
36
|
/** How a text names a provider to a person: `MAX`, not `max`. */
|
|
@@ -49,8 +53,16 @@ export const folderProviderOf = (format) => format === "markdown" ? "local" : "o
|
|
|
49
53
|
*/
|
|
50
54
|
export const DOCUMENT_ACCOUNT_PROVIDERS = ["google-drive"];
|
|
51
55
|
export const isDocumentAccountProvider = (provider) => DOCUMENT_ACCOUNT_PROVIDERS.includes(provider);
|
|
52
|
-
/**
|
|
53
|
-
|
|
56
|
+
/**
|
|
57
|
+
* What the owner adds by hand (`saveAddedSource`): one account, `owner`. Neither a folder nor a documents account, so no
|
|
58
|
+
* folder can be bound to it and no sync deletes a source whose file is gone.
|
|
59
|
+
*/
|
|
60
|
+
export const ADDED_PROVIDER = "added";
|
|
61
|
+
export const ADDED_ACCOUNT = "owner";
|
|
62
|
+
/** Documents `d` outside the added sources: a folder file joined to one would delete it when the file goes. */
|
|
63
|
+
export const notAdded = `d.account_id NOT IN (SELECT id FROM accounts WHERE provider = '${ADDED_PROVIDER}')`;
|
|
64
|
+
/** A folder, a documents account or the added sources, in SQL over an `accounts` row's `provider` column. */
|
|
65
|
+
export const filesAccountSql = (column = "provider") => `${column} IN (${[...FOLDER_PROVIDERS, ...DOCUMENT_ACCOUNT_PROVIDERS, ADDED_PROVIDER].map((name) => `'${name}'`).join(", ")})`;
|
|
54
66
|
/** Notes written in memo have no account row; this is their account. */
|
|
55
67
|
export const INTERNAL_NOTES = "internal";
|
|
56
68
|
/** The reason a search gives for an account whose provider no entry names. */
|
|
@@ -78,30 +90,50 @@ const opensOf = (value, named) => {
|
|
|
78
90
|
export const providerEntryOf = (value) => {
|
|
79
91
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
80
92
|
return invalid("a provider entry is an object");
|
|
81
|
-
const { name, kind, aliases = [], command, opens } = value;
|
|
93
|
+
const { name, kind, kinds, aliases = [], command, opens, imported } = value;
|
|
82
94
|
const named = wordOf(name, "a provider's name");
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
const isKindWord = (one) => typeof one === "string" && KINDS.includes(one);
|
|
96
|
+
const given = kinds === undefined ? [kind] : Array.isArray(kinds) && kinds.length > 0 ? kinds : [undefined];
|
|
97
|
+
for (const one of given)
|
|
98
|
+
if (!isKindWord(one))
|
|
99
|
+
invalid(`provider ${named}'s kind is one of ${KINDS.join(", ")} — not ${JSON.stringify(one)}`);
|
|
100
|
+
const list = [...new Set(given)];
|
|
101
|
+
if (kind !== undefined && kind !== list[0])
|
|
102
|
+
invalid(`provider ${named}'s kind is the first of its kinds`);
|
|
85
103
|
if (!Array.isArray(aliases))
|
|
86
104
|
invalid(`provider ${named}'s aliases are a list`);
|
|
105
|
+
if (imported !== undefined && typeof imported !== "boolean")
|
|
106
|
+
invalid(`provider ${named}'s imported is true or false`);
|
|
87
107
|
return {
|
|
88
108
|
name: named,
|
|
89
|
-
kind:
|
|
109
|
+
kind: list[0],
|
|
110
|
+
...(list.length > 1 ? { kinds: list } : {}),
|
|
111
|
+
...(imported === true ? { imported: true } : {}),
|
|
90
112
|
aliases: [...new Set(aliases.map((alias) => wordOf(alias, `an alias of ${named}`)))],
|
|
91
113
|
...(command === undefined ? {} : { command: wordOf(command, `the command of ${named}`) }),
|
|
92
114
|
...(opens === undefined ? {} : { opens: opensOf(opens, named) }),
|
|
93
115
|
};
|
|
94
116
|
};
|
|
95
|
-
const
|
|
117
|
+
export const kindsOfEntry = (entry) => entry.kinds ?? [entry.kind];
|
|
118
|
+
const describe = (entry) => `${entry.name} (${kindsOfEntry(entry).join(", ")}${entry.command ? `, from ${entry.command}` : ""})`;
|
|
119
|
+
/** Both lists, the known one's order first: an older build writes the first kind only, and drops none. */
|
|
120
|
+
export const unitedKinds = (known, entry) => [
|
|
121
|
+
...new Set([...known, ...entry]),
|
|
122
|
+
];
|
|
96
123
|
const wordsOf = ({ name, aliases }) => [name, ...aliases];
|
|
97
124
|
/** `entry` joined to `known`: the same name keeps one entry with both entries' aliases; a clash is an error. */
|
|
98
125
|
const joined = (known, entry) => {
|
|
99
126
|
const same = known.find(({ name }) => name === entry.name);
|
|
127
|
+
const kinds = same ? unitedKinds(kindsOfEntry(same), kindsOfEntry(entry)) : kindsOfEntry(entry);
|
|
100
128
|
if (same && same.kind !== entry.kind)
|
|
101
129
|
invalid(`two provider entries disagree on the kind: ${describe(same)} and ${describe(entry)}`);
|
|
130
|
+
// A messenger's entry turned import-only would let an import write into its chats.
|
|
131
|
+
if (same && entry.imported === true && same.imported !== true)
|
|
132
|
+
invalid(`provider ${entry.name} is synced, so an entry cannot make it import-only`);
|
|
102
133
|
const merged = same
|
|
103
134
|
? {
|
|
104
135
|
...same,
|
|
136
|
+
...(kinds.length > 1 ? { kinds } : {}),
|
|
105
137
|
aliases: [...new Set([...same.aliases, ...entry.aliases])],
|
|
106
138
|
...(entry.command ? { command: entry.command } : {}),
|
|
107
139
|
...(entry.opens ? { opens: { ...same.opens, ...entry.opens } } : {}),
|
|
@@ -156,5 +188,35 @@ export const providerNamed = (word) => {
|
|
|
156
188
|
};
|
|
157
189
|
/** The kind of a provider the registry knows; `undefined` for one no entry names, which a search skips. */
|
|
158
190
|
export const kindIn = (provider) => isFolderProvider(provider) ? "notes" : registry.find(({ name }) => name === provider)?.kind;
|
|
191
|
+
/** Every kind a provider's accounts hold, its `kind` first; empty for one no entry names. */
|
|
192
|
+
export const kindsIn = (provider) => {
|
|
193
|
+
if (isFolderProvider(provider))
|
|
194
|
+
return ["notes"];
|
|
195
|
+
const entry = registry.find(({ name }) => name === provider);
|
|
196
|
+
return entry ? kindsOfEntry(entry) : [];
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Whether an entry may carry `imported`, beside one stored before (`held`): never for a built-in a sync writes, only
|
|
200
|
+
* as the first entry of its name, and never dropped once given. Answers the flag to store.
|
|
201
|
+
*/
|
|
202
|
+
export const importedOf = (entry, held) => {
|
|
203
|
+
const builtIn = PROVIDERS.find(({ name }) => name === entry.name);
|
|
204
|
+
if (builtIn) {
|
|
205
|
+
if (entry.imported === true && builtIn.imported !== true)
|
|
206
|
+
invalid(`provider ${entry.name} is synced, so an entry cannot make it import-only`);
|
|
207
|
+
return builtIn.imported === true;
|
|
208
|
+
}
|
|
209
|
+
if (held === undefined)
|
|
210
|
+
return entry.imported === true;
|
|
211
|
+
if (entry.imported === true && held.imported !== true)
|
|
212
|
+
invalid(`provider ${entry.name} was registered without imported: an entry cannot make it import-only later`);
|
|
213
|
+
return held.imported === true;
|
|
214
|
+
};
|
|
215
|
+
/** Whether a provider's accounts hold only what imports wrote: the one place a records import writes messages and events. */
|
|
216
|
+
export const isImportedProvider = (provider) => registry.find(({ name }) => name === provider)?.imported === true;
|
|
217
|
+
/** Whether a provider's accounts hold `kind`: what a search lane picks its accounts by. */
|
|
218
|
+
export const holdsKind = (provider, kind) => kindsIn(provider).includes(kind);
|
|
219
|
+
/** `holdsKind`, with a provider no entry names counted as a messenger, as `kindOf` counts it. */
|
|
220
|
+
export const holdsKindOf = (provider, kind) => kindIn(provider) === undefined ? kind === "messages" : holdsKind(provider, kind);
|
|
159
221
|
/** A provider the registry does not list counts as a messenger here; a search asks `kindIn` and skips it. */
|
|
160
222
|
export const kindOf = (provider) => kindIn(provider) ?? "messages";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSON Schema 2020-12 subset the records envelope uses for a type's `fields`, and a check that gives the verdict a
|
|
3
|
+
* standard validator gives (`record-fields.test.ts` holds the two to the same fixtures) plus the place and a reason.
|
|
4
|
+
*/
|
|
5
|
+
type JsonType = "string" | "integer" | "boolean" | "array" | "object" | "null";
|
|
6
|
+
export interface FieldSchema {
|
|
7
|
+
type?: JsonType | readonly JsonType[];
|
|
8
|
+
description?: string;
|
|
9
|
+
enum?: readonly (string | null)[];
|
|
10
|
+
pattern?: string;
|
|
11
|
+
minLength?: number;
|
|
12
|
+
maxLength?: number;
|
|
13
|
+
minimum?: number;
|
|
14
|
+
maximum?: number;
|
|
15
|
+
maxItems?: number;
|
|
16
|
+
items?: FieldSchema;
|
|
17
|
+
properties?: Record<string, FieldSchema>;
|
|
18
|
+
required?: readonly string[];
|
|
19
|
+
additionalProperties?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const DECIMAL_PATTERN = "^[0-9]{1,16}(\\.[0-9]{1,6})?$";
|
|
22
|
+
export declare const text: (description?: string, maxLength?: number) => FieldSchema;
|
|
23
|
+
export declare const decimal: (description: string) => FieldSchema;
|
|
24
|
+
export declare const signedDecimal: (description: string) => FieldSchema;
|
|
25
|
+
export declare const day: (description: string) => FieldSchema;
|
|
26
|
+
/** ISO 8601 with its offset: a phone's time without one would be read in whatever zone the importer runs in. */
|
|
27
|
+
export declare const instant: (description: string) => FieldSchema;
|
|
28
|
+
export declare const enumOf: (values: readonly string[], description?: string) => FieldSchema;
|
|
29
|
+
export declare const currency: FieldSchema;
|
|
30
|
+
/** An object whose known keys are typed, each but the required ones also `null`; any other key is kept as sent. */
|
|
31
|
+
export declare const objectOf: (properties: Record<string, FieldSchema>, { required, description }?: {
|
|
32
|
+
required?: readonly string[];
|
|
33
|
+
description?: string;
|
|
34
|
+
}) => FieldSchema;
|
|
35
|
+
export declare const arrayOf: (item: FieldSchema, maxItems: number, description: string) => FieldSchema;
|
|
36
|
+
export declare const isObject: (value: unknown) => value is Record<string, unknown>;
|
|
37
|
+
/** The first place `value` breaks `schema`, as path segments below the checked value, and why; nothing when it fits. */
|
|
38
|
+
export declare const fieldError: (schema: FieldSchema, value: unknown, at?: (string | number)[]) => {
|
|
39
|
+
at: (string | number)[];
|
|
40
|
+
message: string;
|
|
41
|
+
} | undefined;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export const DECIMAL_PATTERN = "^[0-9]{1,16}(\\.[0-9]{1,6})?$";
|
|
2
|
+
const SIGNED_DECIMAL = "^-?[0-9]{1,16}(\\.[0-9]{1,6})?$";
|
|
3
|
+
const DAY = "^[0-9]{4}-[0-9]{2}-[0-9]{2}$";
|
|
4
|
+
const INSTANT = "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}(:[0-9]{2}(\\.[0-9]{1,9})?)?(Z|[+-][0-9]{2}:[0-9]{2})$";
|
|
5
|
+
export const text = (description, maxLength = 2000) => ({
|
|
6
|
+
type: "string",
|
|
7
|
+
minLength: 1,
|
|
8
|
+
maxLength,
|
|
9
|
+
...(description ? { description } : {}),
|
|
10
|
+
});
|
|
11
|
+
export const decimal = (description) => ({ type: "string", pattern: DECIMAL_PATTERN, description });
|
|
12
|
+
export const signedDecimal = (description) => ({
|
|
13
|
+
type: "string",
|
|
14
|
+
pattern: SIGNED_DECIMAL,
|
|
15
|
+
description,
|
|
16
|
+
});
|
|
17
|
+
export const day = (description) => ({ type: "string", pattern: DAY, description });
|
|
18
|
+
/** ISO 8601 with its offset: a phone's time without one would be read in whatever zone the importer runs in. */
|
|
19
|
+
export const instant = (description) => ({ type: "string", pattern: INSTANT, description });
|
|
20
|
+
export const enumOf = (values, description) => ({
|
|
21
|
+
type: "string",
|
|
22
|
+
enum: values,
|
|
23
|
+
...(description ? { description } : {}),
|
|
24
|
+
});
|
|
25
|
+
export const currency = { type: "string", pattern: "^[A-Za-z]{3}$", description: "ISO 4217 code" };
|
|
26
|
+
/** A key a source may also send as `null`, as v1 read a missing value. */
|
|
27
|
+
const nullable = (schema) => {
|
|
28
|
+
if (schema.type === undefined)
|
|
29
|
+
return schema;
|
|
30
|
+
const types = typeof schema.type === "string" ? [schema.type] : [...schema.type];
|
|
31
|
+
return {
|
|
32
|
+
...schema,
|
|
33
|
+
type: types.includes("null") ? types : [...types, "null"],
|
|
34
|
+
...(schema.enum ? { enum: [...schema.enum, null] } : {}),
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/** An object whose known keys are typed, each but the required ones also `null`; any other key is kept as sent. */
|
|
38
|
+
export const objectOf = (properties, { required, description } = {}) => ({
|
|
39
|
+
type: "object",
|
|
40
|
+
...(description ? { description } : {}),
|
|
41
|
+
properties: Object.fromEntries(Object.entries(properties).map(([key, schema]) => [key, required?.includes(key) ? schema : nullable(schema)])),
|
|
42
|
+
...(required?.length ? { required } : {}),
|
|
43
|
+
additionalProperties: true,
|
|
44
|
+
});
|
|
45
|
+
export const arrayOf = (item, maxItems, description) => ({
|
|
46
|
+
type: "array",
|
|
47
|
+
items: item,
|
|
48
|
+
maxItems,
|
|
49
|
+
description,
|
|
50
|
+
});
|
|
51
|
+
export const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52
|
+
const typeOf = (value) => {
|
|
53
|
+
if (Array.isArray(value))
|
|
54
|
+
return "array";
|
|
55
|
+
if (value === null)
|
|
56
|
+
return "null";
|
|
57
|
+
if (typeof value === "number")
|
|
58
|
+
return Number.isInteger(value) ? "integer" : "number";
|
|
59
|
+
if (typeof value === "string")
|
|
60
|
+
return "string";
|
|
61
|
+
if (typeof value === "boolean")
|
|
62
|
+
return "boolean";
|
|
63
|
+
return typeof value === "object" ? "object" : "other";
|
|
64
|
+
};
|
|
65
|
+
const WHAT = {
|
|
66
|
+
string: "text",
|
|
67
|
+
integer: "a whole number",
|
|
68
|
+
boolean: "true or false",
|
|
69
|
+
array: "a list",
|
|
70
|
+
object: "an object",
|
|
71
|
+
null: "null",
|
|
72
|
+
};
|
|
73
|
+
/** The first place `value` breaks `schema`, as path segments below the checked value, and why; nothing when it fits. */
|
|
74
|
+
export const fieldError = (schema, value, at = []) => {
|
|
75
|
+
const name = at.length ? `fields.${at.join(".")}` : "fields";
|
|
76
|
+
if (schema.type !== undefined) {
|
|
77
|
+
const allowed = typeof schema.type === "string" ? [schema.type] : schema.type;
|
|
78
|
+
if (!allowed.includes(typeOf(value)))
|
|
79
|
+
return { at, message: `${name} is ${allowed.map((one) => WHAT[one]).join(" or ")}` };
|
|
80
|
+
}
|
|
81
|
+
if (schema.enum && !schema.enum.includes(value))
|
|
82
|
+
return { at, message: `${name} is one of ${schema.enum.filter((one) => one !== null).join(", ")}` };
|
|
83
|
+
if (typeof value === "string") {
|
|
84
|
+
// JSON Schema counts code points, not UTF-16 units, and never trims.
|
|
85
|
+
const length = [...value].length;
|
|
86
|
+
if (schema.minLength !== undefined && length < schema.minLength)
|
|
87
|
+
return { at, message: `${name} takes at least ${schema.minLength} characters` };
|
|
88
|
+
if (schema.maxLength !== undefined && length > schema.maxLength)
|
|
89
|
+
return { at, message: `${name} takes at most ${schema.maxLength} characters` };
|
|
90
|
+
if (schema.pattern !== undefined && !new RegExp(schema.pattern, "u").test(value))
|
|
91
|
+
return { at, message: `${name} does not have the form ${schema.description ?? schema.pattern}` };
|
|
92
|
+
}
|
|
93
|
+
if (typeof value === "number") {
|
|
94
|
+
if (schema.minimum !== undefined && value < schema.minimum)
|
|
95
|
+
return { at, message: `${name} is ${schema.minimum} or more` };
|
|
96
|
+
if (schema.maximum !== undefined && value > schema.maximum)
|
|
97
|
+
return { at, message: `${name} is ${schema.maximum} or less` };
|
|
98
|
+
}
|
|
99
|
+
if (Array.isArray(value)) {
|
|
100
|
+
if (schema.maxItems !== undefined && value.length > schema.maxItems)
|
|
101
|
+
return { at, message: `${name} holds at most ${schema.maxItems} items` };
|
|
102
|
+
if (schema.items)
|
|
103
|
+
for (const [index, item] of value.entries()) {
|
|
104
|
+
const found = fieldError(schema.items, item, [...at, index]);
|
|
105
|
+
if (found)
|
|
106
|
+
return found;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (isObject(value)) {
|
|
110
|
+
for (const key of schema.required ?? [])
|
|
111
|
+
if (!Object.hasOwn(value, key))
|
|
112
|
+
return { at: [...at, key], message: `${name}.${key} is required` };
|
|
113
|
+
for (const [key, property] of Object.entries(schema.properties ?? {})) {
|
|
114
|
+
if (!Object.hasOwn(value, key))
|
|
115
|
+
continue;
|
|
116
|
+
const found = fieldError(property, value[key], [...at, key]);
|
|
117
|
+
if (found)
|
|
118
|
+
return found;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
};
|