@wirecat/cli-core 0.719.0 → 0.721.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 +69 -0
- package/dist/attachments/documents.d.ts +5 -0
- package/dist/attachments/documents.js +2 -2
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/config-command.js +8 -2
- package/dist/cli/config-issues.d.ts +3 -1
- package/dist/cli/config-issues.js +9 -2
- package/dist/cli/documents/file-conflicts.d.ts +25 -0
- package/dist/cli/documents/file-conflicts.js +102 -0
- package/dist/cli/documents/file-edit.d.ts +29 -0
- package/dist/cli/documents/file-edit.js +352 -0
- package/dist/cli/documents/file-update.d.ts +43 -0
- package/dist/cli/documents/file-update.js +95 -0
- package/dist/cli/documents/history.d.ts +34 -0
- package/dist/cli/documents/history.js +89 -0
- package/dist/cli/documents/index.d.ts +9 -2
- package/dist/cli/documents/index.js +9 -2
- package/dist/cli/documents/library.js +10 -0
- package/dist/cli/permission-keys.d.ts +6 -0
- package/dist/cli/permission-keys.js +15 -3
- package/dist/cli/service-api.d.ts +1 -1
- package/dist/cli/service-api.js +16 -34
- package/dist/documents/file-mirror-model.d.ts +32 -1
- package/dist/documents/index.d.ts +7 -4
- package/dist/documents/index.js +4 -1
- package/dist/documents/model.d.ts +16 -1
- package/dist/errors/reasons.js +6 -1
- package/dist/office/docx.d.ts +43 -0
- package/dist/office/docx.js +349 -0
- package/dist/office/index.d.ts +2 -0
- package/dist/office/index.js +2 -0
- package/dist/office/package.d.ts +39 -0
- package/dist/office/package.js +98 -0
- package/dist/office/xlsx.d.ts +55 -0
- package/dist/office/xlsx.js +550 -0
- package/dist/office/xml.d.ts +34 -0
- package/dist/office/xml.js +186 -0
- package/dist/office/zip.d.ts +10 -0
- package/dist/office/zip.js +116 -0
- package/dist/services/documents/block-diff.d.ts +13 -3
- package/dist/services/documents/block-diff.js +13 -7
- package/dist/services/documents/ingestion.d.ts +21 -2
- package/dist/services/documents/ingestion.js +29 -2
- package/dist/services/documents/plan.js +16 -7
- package/dist/services/documents/ports.d.ts +2 -0
- package/dist/services/documents/sync.d.ts +1 -0
- package/dist/services/documents/sync.js +9 -4
- package/dist/services/files/conflicts.d.ts +78 -0
- package/dist/services/files/conflicts.js +183 -0
- package/dist/services/files/guarded-write.d.ts +34 -0
- package/dist/services/files/guarded-write.js +42 -0
- package/dist/services/files/listing.d.ts +36 -0
- package/dist/services/files/listing.js +47 -0
- package/dist/services/files/local-files.d.ts +54 -0
- package/dist/services/files/local-files.js +143 -0
- package/dist/services/files/mirror-state.d.ts +14 -0
- package/dist/services/files/mirror-state.js +65 -0
- package/dist/services/files/mirror.d.ts +4 -14
- package/dist/services/files/mirror.js +177 -204
- package/dist/services/files/text-merge.d.ts +27 -0
- package/dist/services/files/text-merge.js +134 -0
- package/dist/services/files/versions.d.ts +36 -9
- package/dist/services/files/versions.js +40 -12
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.js +1 -0
- package/dist/store/people.d.ts +8 -0
- package/dist/store/people.js +2 -0
- package/dist/store/sqlite/account-purge.js +3 -0
- package/dist/store/sqlite/document-history.d.ts +84 -0
- package/dist/store/sqlite/document-history.js +158 -0
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +17 -0
- package/dist/store/sqlite/notes.d.ts +9 -10
- package/dist/store/sqlite/notes.js +33 -21
- package/dist/store/sqlite/person-erase.d.ts +39 -0
- package/dist/store/sqlite/person-erase.js +152 -0
- package/dist/store/sqlite/schema/document-changes.d.ts +136 -0
- package/dist/store/sqlite/schema/document-changes.js +11 -0
- package/dist/store/sqlite/schema.d.ts +65 -0
- package/dist/store/sqlite/schema.js +5 -0
- package/package.json +6 -2
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { addDocumentCatalogCommands } from "./catalog.js";
|
|
2
2
|
import { addLocalDocumentCommands } from "./documents.js";
|
|
3
3
|
import { addDocumentFolderCommands } from "./folders.js";
|
|
4
|
+
import { addDocumentHistoryCommands } from "./history.js";
|
|
4
5
|
import { addDocumentKnowledgeCommands } from "./knowledge.js";
|
|
5
6
|
import { addDocumentMirrorCommands } from "./mirrors.js";
|
|
6
7
|
import { addDocumentSearchCommand } from "./search.js";
|
|
7
8
|
import { addDocumentSyncCommands } from "./sync.js";
|
|
8
9
|
export { addDocumentCatalogCommands, CATALOG_FIELDS, catalogId, catalogOutput, catalogSource, catalogTree, } from "./catalog.js";
|
|
9
10
|
export { addLocalDocumentCommands } from "./documents.js";
|
|
11
|
+
export { fileConflictsCommand } from "./file-conflicts.js";
|
|
12
|
+
export { addFileEditCommands } from "./file-edit.js";
|
|
13
|
+
export { addFileUpdateCommand } from "./file-update.js";
|
|
10
14
|
export { addDocumentFolderCommands } from "./folders.js";
|
|
15
|
+
export { addDocumentHistoryCommands, DOCUMENT_HISTORY_SETTINGS, keepVersionsForDays, } from "./history.js";
|
|
11
16
|
export { addDocumentKnowledgeCommands, } from "./knowledge.js";
|
|
12
17
|
export { addDocumentMirrorCommands } from "./mirrors.js";
|
|
13
18
|
export { documentQueries, FACT_QUERY, factItem, folderRow, IDENTITY_ROLES, identityRow, linkRow, MEMORY_QUERY, MEMORY_SEARCH_QUERY, memoryItem, memorySearch, mirrorRow, tagRow, } from "./queries.js";
|
|
@@ -15,14 +20,16 @@ export { addDocumentSearchCommand } from "./search.js";
|
|
|
15
20
|
export { addDocumentSyncCommands } from "./sync.js";
|
|
16
21
|
export { ageOf, staleCopy } from "./words.js";
|
|
17
22
|
/**
|
|
18
|
-
* `folders`, `sync`, `status`, `documents list|show|export|context`, `
|
|
19
|
-
* when given, `mirrors`, in that order. Answers the `documents` group, for the CLI's live subcommands.
|
|
23
|
+
* `folders`, `sync`, `status`, `documents list|show|export|context`, when given `documents history` and `changes`,
|
|
24
|
+
* `search`, `catalog`, the knowledge groups and, when given, `mirrors`, in that order. Answers the `documents` group, for the CLI's live subcommands.
|
|
20
25
|
*/
|
|
21
26
|
export const addDocumentCommands = (program, options) => {
|
|
22
27
|
const shared = { words: options.words, output: options.output };
|
|
23
28
|
addDocumentFolderCommands(program, { ...shared, ...options.folders });
|
|
24
29
|
addDocumentSyncCommands(program, { ...shared, ...options.sync });
|
|
25
30
|
const documents = addLocalDocumentCommands(program, { ...shared, ...options.documents });
|
|
31
|
+
if (options.history)
|
|
32
|
+
addDocumentHistoryCommands(program, { ...shared, ...options.history });
|
|
26
33
|
addDocumentSearchCommand(program, { ...shared, ...options.search });
|
|
27
34
|
addDocumentCatalogCommands(program, { ...shared, ...options.catalog });
|
|
28
35
|
addDocumentKnowledgeCommands(program, { ...shared, ...options.knowledge });
|
|
@@ -22,6 +22,7 @@ import { ProfileTokenStore } from "../profile-token.js";
|
|
|
22
22
|
import { addDocumentCatalogCommands } from "./catalog.js";
|
|
23
23
|
import { addLocalDocumentCommands } from "./documents.js";
|
|
24
24
|
import { addDocumentFolderCommands } from "./folders.js";
|
|
25
|
+
import { addDocumentHistoryCommands, keepVersionsForDays } from "./history.js";
|
|
25
26
|
import { addDocumentKnowledgeCommands } from "./knowledge.js";
|
|
26
27
|
import { factItem, memoryItem } from "./queries.js";
|
|
27
28
|
import { addDocumentSearchCommand } from "./search.js";
|
|
@@ -351,6 +352,7 @@ export const documentLibraryCommands = (options) => {
|
|
|
351
352
|
errorOf,
|
|
352
353
|
assertHeld,
|
|
353
354
|
storeVersion: app.version,
|
|
355
|
+
keepVersionsForDays: keepVersionsForDays(context().settings),
|
|
354
356
|
...(environmentOf(command()).signal ? { signal: environmentOf(command()).signal } : {}),
|
|
355
357
|
...(rescan ? { rescan } : {}),
|
|
356
358
|
...(budget ? { budget } : {}),
|
|
@@ -421,6 +423,13 @@ export const documentLibraryCommands = (options) => {
|
|
|
421
423
|
},
|
|
422
424
|
lastSync: () => files().state("").read().lastSync,
|
|
423
425
|
},
|
|
426
|
+
history: {
|
|
427
|
+
run: (fn) => {
|
|
428
|
+
const account = principal();
|
|
429
|
+
return withStore(false, (store) => fn(options.ingestion(store).history, account));
|
|
430
|
+
},
|
|
431
|
+
id: (input) => options.idOf(input),
|
|
432
|
+
},
|
|
424
433
|
search: {
|
|
425
434
|
search: (query, searchOptions) => {
|
|
426
435
|
const account = principal();
|
|
@@ -509,6 +518,7 @@ export const documentLibraryCommands = (options) => {
|
|
|
509
518
|
addDocumentFolderCommands(holder, { ...shared, ...groups.folders });
|
|
510
519
|
addDocumentSyncCommands(holder, { ...shared, ...groups.sync });
|
|
511
520
|
addLocalDocumentCommands(holder, { ...shared, ...groups.documents });
|
|
521
|
+
addDocumentHistoryCommands(holder, { ...shared, ...groups.history });
|
|
512
522
|
addDocumentSearchCommand(holder, { ...shared, ...groups.search });
|
|
513
523
|
addDocumentCatalogCommands(holder, { ...shared, ...groups.catalog });
|
|
514
524
|
addDocumentKnowledgeCommands(holder, { ...shared, ...groups.knowledge });
|
|
@@ -35,6 +35,12 @@ export declare const commandPermissions: ({ keyOf, extra, defaults, alsoChecks,
|
|
|
35
35
|
* parents. A key outside it is a typo that would otherwise do nothing (BUG-137).
|
|
36
36
|
*/
|
|
37
37
|
export declare const knownPermissionKeys: (command: Command, keyOf?: PermissionKeySource, extra?: readonly PermissionKey[]) => Set<PermissionKey>;
|
|
38
|
+
/**
|
|
39
|
+
* Old keys of commands that moved, on the group that moved them (the generated `api` group, `api.contacts-list` →
|
|
40
|
+
* `api.contacts.list`): such a key is still refused like any unknown one (WC-CMD-8), and the refusal names the new key.
|
|
41
|
+
*/
|
|
42
|
+
export declare const markRenamedPermissionKeys: (command: Command, renamed: ReadonlyMap<PermissionKey, PermissionKey>) => void;
|
|
43
|
+
export declare const renamedPermissionKeys: (command: Command) => Map<PermissionKey, PermissionKey>;
|
|
38
44
|
/** The known keys one level under the unknown key's parent, to name in the refusal. */
|
|
39
45
|
export declare const knownBeside: (key: PermissionKey, known: ReadonlySet<PermissionKey>) => PermissionKey[];
|
|
40
46
|
export declare const unknownPermissionKeys: (levels: Readonly<Record<PermissionKey, unknown>>, known: ReadonlySet<PermissionKey>) => PermissionKey[];
|
|
@@ -67,6 +67,16 @@ export const knownPermissionKeys = (command, keyOf = (one) => keyForCommand(path
|
|
|
67
67
|
add(key);
|
|
68
68
|
return known;
|
|
69
69
|
};
|
|
70
|
+
const RENAMED = new WeakMap();
|
|
71
|
+
/**
|
|
72
|
+
* Old keys of commands that moved, on the group that moved them (the generated `api` group, `api.contacts-list` →
|
|
73
|
+
* `api.contacts.list`): such a key is still refused like any unknown one (WC-CMD-8), and the refusal names the new key.
|
|
74
|
+
*/
|
|
75
|
+
export const markRenamedPermissionKeys = (command, renamed) => {
|
|
76
|
+
if (renamed.size > 0)
|
|
77
|
+
RENAMED.set(command, renamed);
|
|
78
|
+
};
|
|
79
|
+
export const renamedPermissionKeys = (command) => new Map(everyCommand(rootOf(command)).flatMap((one) => [...(RENAMED.get(one) ?? [])]));
|
|
70
80
|
/** The known keys one level under the unknown key's parent, to name in the refusal. */
|
|
71
81
|
export const knownBeside = (key, known) => {
|
|
72
82
|
const parent = key.split(".").slice(0, -1).join(".");
|
|
@@ -82,7 +92,7 @@ export const unknownPermissionIssues = (command, settings, tool, keyOf) => {
|
|
|
82
92
|
Object.keys(settings.permissions)
|
|
83
93
|
.filter((key) => key !== CEILING_KEY && settings.permissionSources[key] !== "flag")
|
|
84
94
|
.map((key) => ({ key, at: ["profiles", settings.profile, "permissions", key] }));
|
|
85
|
-
return permissionIssues(saved, knownPermissionKeys(command, keyOf), { file: settings.configPath, tool }).map(publicIssue);
|
|
95
|
+
return permissionIssues(saved, knownPermissionKeys(command, keyOf), { file: settings.configPath, tool }, renamedPermissionKeys(command)).map(publicIssue);
|
|
86
96
|
};
|
|
87
97
|
/**
|
|
88
98
|
* A saved key no command checks would do nothing, so the command refuses to run and names the unset that removes
|
|
@@ -94,6 +104,8 @@ export const refuseUnknownPermissionKeys = (command, settings, tool, keyOf) => {
|
|
|
94
104
|
throw new CliError("configuration_error", issueMessage(issues), { permission: issues[0]?.key });
|
|
95
105
|
const flagged = Object.keys(settings.permissions).filter((key) => settings.permissionSources[key] === "flag");
|
|
96
106
|
const [key] = unknownPermissionKeys(Object.fromEntries(flagged.map((one) => [one, true])), knownPermissionKeys(command, keyOf));
|
|
97
|
-
if (key
|
|
98
|
-
|
|
107
|
+
if (key === undefined)
|
|
108
|
+
return;
|
|
109
|
+
const now = renamedPermissionKeys(command).get(key);
|
|
110
|
+
throw new CliError("validation_error", `--permission ${key} names no command${now === undefined ? "" : `: its command moved, so use ${now}`}`, { permission: key });
|
|
99
111
|
};
|
|
@@ -6,7 +6,7 @@ import type * as v from "valibot";
|
|
|
6
6
|
import type { AppIdentity } from "../ports/app.js";
|
|
7
7
|
import type { Level, PermissionKey } from "../sends/permissions.js";
|
|
8
8
|
import { type ApiCommandInput } from "./bot/api.js";
|
|
9
|
-
import type
|
|
9
|
+
import { type ConditionalKey } from "./permission-keys.js";
|
|
10
10
|
import { type ServiceApiManifest } from "./service-api-manifest.js";
|
|
11
11
|
import type { Configuration } from "./settings.js";
|
|
12
12
|
/** A key a call's body implies in a way no flag names, as notion's `agent-batch` with an action `delete`. */
|
package/dist/cli/service-api.js
CHANGED
|
@@ -15,6 +15,7 @@ import { NO_EFFECTS } from "./effects.js";
|
|
|
15
15
|
import { itemOf, listOf, renderAnswer } from "./envelope.js";
|
|
16
16
|
import { queryTerms, termField, withQuery } from "./list-query.js";
|
|
17
17
|
import { terminalAsker } from "./messenger/ask.js";
|
|
18
|
+
import { markRenamedPermissionKeys } from "./permission-keys.js";
|
|
18
19
|
import { manifestBaseUrl, nextPage, parameterValue, signRequest, underBase, } from "./service-api-manifest.js";
|
|
19
20
|
/**
|
|
20
21
|
* The operations the `api` group offers, and why it leaves out the rest: one that answers with a credential needs a
|
|
@@ -38,9 +39,8 @@ const keyOf = (operation) => ["api", ...apiPathOf(operation)].join(".");
|
|
|
38
39
|
/** `contacts list`: what follows `api` on the command line. */
|
|
39
40
|
const pathOf = (operation) => apiPathOf(operation).join(" ");
|
|
40
41
|
/**
|
|
41
|
-
* The key a grouped operation had while `api` was flat, `api.contacts-list`.
|
|
42
|
-
*
|
|
43
|
-
* name (the generator refuses it), so the old key never reaches past its command.
|
|
42
|
+
* The key a grouped operation had while `api` was flat, `api.contacts-list`. It checks nothing now: a config that still
|
|
43
|
+
* names it is refused as an unknown key, and the refusal names the new key (WC-CMD-8).
|
|
44
44
|
*/
|
|
45
45
|
const formerKeyOf = (operation) => {
|
|
46
46
|
const former = `api.${operation.command}`;
|
|
@@ -100,27 +100,18 @@ export const serviceApiKeys = (input, operation, call) => {
|
|
|
100
100
|
*/
|
|
101
101
|
export const serviceApiPermissions = (input) => {
|
|
102
102
|
const checks = new Map();
|
|
103
|
-
const former = [];
|
|
104
103
|
for (const operation of input.manifest.operations) {
|
|
105
|
-
const old = formerKeyOf(operation);
|
|
106
|
-
if (old)
|
|
107
|
-
former.push(old);
|
|
108
104
|
checks.set(pathOf(operation), [
|
|
109
105
|
...permissionsOf(operation).map((permission) => {
|
|
110
106
|
const when = whenOf(permission);
|
|
111
107
|
return when === undefined ? permission.key : { key: permission.key, when };
|
|
112
108
|
}),
|
|
113
109
|
...(input.bodyPermissions?.[operation.command] ?? []).map(({ key, when }) => ({ key, when })),
|
|
114
|
-
...(old ? [{ key: old, when: "while a profile still names this old key" }] : []),
|
|
115
110
|
]);
|
|
116
111
|
}
|
|
117
|
-
const keys = [
|
|
118
|
-
...new Set([...checks.values()]
|
|
119
|
-
.flat()
|
|
120
|
-
.flatMap((one) => (typeof one === "string" ? [one] : former.includes(one.key) ? [] : [one.key]))),
|
|
121
|
-
];
|
|
112
|
+
const keys = [...new Set([...checks.values()].flat().map((one) => (typeof one === "string" ? one : one.key)))];
|
|
122
113
|
return {
|
|
123
|
-
extra:
|
|
114
|
+
extra: keys,
|
|
124
115
|
alsoChecks: (path) => (path[0] === "api" ? (checks.get(path.slice(1).join(" ")) ?? []) : []),
|
|
125
116
|
defaults: {
|
|
126
117
|
...Object.fromEntries(keys.map((key) => [key, "ask"])),
|
|
@@ -252,22 +243,10 @@ const serviceApiCore = (options) => {
|
|
|
252
243
|
throw error;
|
|
253
244
|
}
|
|
254
245
|
};
|
|
255
|
-
/** The old flat key, when the profile names it: on a read only its refusal or its question applies. */
|
|
256
|
-
const formerKeys = (command, operation) => {
|
|
257
|
-
const former = formerKeyOf(operation);
|
|
258
|
-
if (!former)
|
|
259
|
-
return [];
|
|
260
|
-
const { settings, renderer } = baseContext(command, configuration.resolveSettings);
|
|
261
|
-
const level = settings.permissions[former];
|
|
262
|
-
if (level === undefined)
|
|
263
|
-
return [];
|
|
264
|
-
renderer.warn(`permissions name ${former}, the old key of api ${pathOf(operation)}: rename it to ${keyOf(operation)}`);
|
|
265
|
-
return operation.effect === "read" && level !== "deny" && level !== "ask" ? [] : [former];
|
|
266
|
-
};
|
|
267
246
|
/**
|
|
268
247
|
* The refusal `execute` would give, before the body is read: a `deny` stops a call whatever its input, and a missing
|
|
269
|
-
* body must not answer `validation_error` in its place. Only the keys known without the body; the rest
|
|
270
|
-
*
|
|
248
|
+
* body must not answer `validation_error` in its place. Only the keys known without the body; the rest wait for
|
|
249
|
+
* `execute`.
|
|
271
250
|
*/
|
|
272
251
|
const refuseBeforeBody = (command, operation) => {
|
|
273
252
|
const extra = permissionsOf(operation)
|
|
@@ -283,7 +262,6 @@ const serviceApiCore = (options) => {
|
|
|
283
262
|
baseUrlOf,
|
|
284
263
|
defaults,
|
|
285
264
|
exchange,
|
|
286
|
-
formerKeys,
|
|
287
265
|
operationOf,
|
|
288
266
|
readsFreely,
|
|
289
267
|
refuseBeforeBody,
|
|
@@ -292,8 +270,8 @@ const serviceApiCore = (options) => {
|
|
|
292
270
|
};
|
|
293
271
|
};
|
|
294
272
|
export const serviceApiCommand = (options) => {
|
|
295
|
-
const { app, configuration } = options;
|
|
296
|
-
const { operations, baseUrlOf, exchange,
|
|
273
|
+
const { app, configuration, manifest } = options;
|
|
274
|
+
const { operations, baseUrlOf, exchange, operationOf, readsFreely, refuseBeforeBody, signed, write } = serviceApiCore(options);
|
|
297
275
|
const send = async (command, operation, request) => (await exchange(command, operation, request)).answer;
|
|
298
276
|
let schemas;
|
|
299
277
|
const loaded = () => {
|
|
@@ -374,7 +352,7 @@ export const serviceApiCommand = (options) => {
|
|
|
374
352
|
command.hook("preAction", load);
|
|
375
353
|
},
|
|
376
354
|
execute: async (command, operation, input) => {
|
|
377
|
-
const extra =
|
|
355
|
+
const extra = serviceApiKeys(options, operation, input);
|
|
378
356
|
const read = readsFreely(command, operation, extra);
|
|
379
357
|
if (operation.pagination && command.opts().all === true) {
|
|
380
358
|
if (!read)
|
|
@@ -422,6 +400,10 @@ export const serviceApiCommand = (options) => {
|
|
|
422
400
|
group.addCommand(list).addCommand(show);
|
|
423
401
|
for (const child of [...generated.commands])
|
|
424
402
|
group.addCommand(child);
|
|
403
|
+
markRenamedPermissionKeys(group, new Map(manifest.operations.flatMap((operation) => {
|
|
404
|
+
const former = formerKeyOf(operation);
|
|
405
|
+
return former ? [[former, keyOf(operation)]] : [];
|
|
406
|
+
})));
|
|
425
407
|
return group;
|
|
426
408
|
};
|
|
427
409
|
// Code may pass a number, a boolean or a list where a person types text; the check reads the text it stands for.
|
|
@@ -442,7 +424,7 @@ const writerBody = (operation, input, schemas) => {
|
|
|
442
424
|
* can be asked. A read that no key guards goes through `serviceApiCall`.
|
|
443
425
|
*/
|
|
444
426
|
export const serviceApiWriter = (options) => {
|
|
445
|
-
const { baseUrlOf,
|
|
427
|
+
const { baseUrlOf, operationOf, signed, write } = serviceApiCore(options);
|
|
446
428
|
return async (command, name, input, { confirmed } = {}) => {
|
|
447
429
|
const operation = operationOf(name);
|
|
448
430
|
// The api group offers only declared parameters; code must not reach further, as WordPress's `_method` turns a
|
|
@@ -468,6 +450,6 @@ export const serviceApiWriter = (options) => {
|
|
|
468
450
|
throw new CliError("validation_error", problem);
|
|
469
451
|
}
|
|
470
452
|
const request = await signed(command, operation, httpApiRequest(operation, writerBody(operation, input, schemas), baseUrlOf(command)));
|
|
471
|
-
return write(command, operation,
|
|
453
|
+
return write(command, operation, extra, request, confirmed);
|
|
472
454
|
};
|
|
473
455
|
};
|
|
@@ -30,13 +30,17 @@ export interface FileTarget {
|
|
|
30
30
|
* Every file under `root`, with the root folder's own id; undefined when the folder does not exist. `complete` is
|
|
31
31
|
* false when any page was skipped or a cap was hit: a file missing from such a listing is not taken as deleted.
|
|
32
32
|
* Files at paths `excluded` names are listed too, so a file moved there is found by its id, but count toward no cap.
|
|
33
|
+
* An incomplete listing that can go on later returns `next`, its position; given back as `from` in a later run, the
|
|
34
|
+
* listing returns only the files from there on.
|
|
33
35
|
*/
|
|
34
36
|
list(root: string, signal?: AbortSignal, options?: {
|
|
35
37
|
excluded?(path: string): boolean;
|
|
38
|
+
from?: string;
|
|
36
39
|
}): Promise<{
|
|
37
40
|
rootId: string;
|
|
38
41
|
files: RemoteFile[];
|
|
39
42
|
complete: boolean;
|
|
43
|
+
next?: string;
|
|
40
44
|
} | undefined>;
|
|
41
45
|
/**
|
|
42
46
|
* Whether anything is at `path` now, read directly rather than from a listing; false only when the provider says
|
|
@@ -67,6 +71,21 @@ export interface FileEntry {
|
|
|
67
71
|
localSize: number;
|
|
68
72
|
syncedAt: string;
|
|
69
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* A conflict the last sync left: why, when, and the contents it found. A side that deleted the file has no hash. The
|
|
76
|
+
* store keeps all three (`kept`) for a text file the merge could not settle; for other files only the hashes are
|
|
77
|
+
* known, and a resolution reads the sides again.
|
|
78
|
+
*/
|
|
79
|
+
export interface FileConflict {
|
|
80
|
+
reason: string;
|
|
81
|
+
at: string;
|
|
82
|
+
base?: string;
|
|
83
|
+
local?: string;
|
|
84
|
+
remote?: string;
|
|
85
|
+
/** The remote file as the listing saw it. */
|
|
86
|
+
remoteFile?: RemoteFile;
|
|
87
|
+
kept?: boolean;
|
|
88
|
+
}
|
|
70
89
|
export interface FileMirrorState {
|
|
71
90
|
version: 1;
|
|
72
91
|
principal: string;
|
|
@@ -90,9 +109,21 @@ export interface FileMirrorState {
|
|
|
90
109
|
operationId: string;
|
|
91
110
|
created?: boolean;
|
|
92
111
|
}>;
|
|
112
|
+
/**
|
|
113
|
+
* A remote listing that stopped before its end: the files listed so far and where the next run goes on. Cleared once
|
|
114
|
+
* a run completes it, or when it is too old, of another root, or cannot go on.
|
|
115
|
+
*/
|
|
116
|
+
listing?: {
|
|
117
|
+
rootId: string;
|
|
118
|
+
startedAt: string;
|
|
119
|
+
next: string;
|
|
120
|
+
files: RemoteFile[];
|
|
121
|
+
};
|
|
122
|
+
/** The conflicts the last sync left, by path; each sync replaces them, and a resolution removes its own. */
|
|
123
|
+
conflicts?: Record<string, FileConflict>;
|
|
93
124
|
}
|
|
94
125
|
export interface FileMirrorStatePort {
|
|
95
126
|
read(): FileMirrorState;
|
|
96
127
|
save(state: FileMirrorState): void;
|
|
97
128
|
}
|
|
98
|
-
export type FileStepKind = "upload" | "download" | "adopt" | "trash-remote" | "trash-local" | "rename-local" | "keep-both" | "forget" | "conflict" | "unknown";
|
|
129
|
+
export type FileStepKind = "upload" | "download" | "adopt" | "trash-remote" | "trash-local" | "rename-local" | "keep-both" | "merge" | "forget" | "conflict" | "unknown";
|
|
@@ -9,16 +9,19 @@ export { conflictReport, fileMirrorState, type HeldLock, type Mirror, type Mirro
|
|
|
9
9
|
export type { SyncOptions } from "../services/documents/ports.js";
|
|
10
10
|
export { extractDocumentMemories, type ImportedSource, type ProposalOptions } from "../services/documents/proposals.js";
|
|
11
11
|
export { type MirrorAction, type PushConflict, type PushOptions, type PushResult, planPush, pushDocuments, scanLocal, skippedName, } from "../services/documents/push.js";
|
|
12
|
-
export { type SyncResult, syncDocuments } from "../services/documents/sync.js";
|
|
12
|
+
export { KEEP_VERSIONS_FOR_DAYS, type SyncResult, syncDocuments } from "../services/documents/sync.js";
|
|
13
|
+
export { type FileConflictResolution, type FileConflictResolveOptions, type FileConflictVersion, type FileConflictView, listFileConflicts, resolveFileConflict, showFileConflict, } from "../services/files/conflicts.js";
|
|
13
14
|
export { excludedBy, exclusionPattern } from "../services/files/exclusions.js";
|
|
15
|
+
export { type GuardedFileWrite, type GuardedFileWriteResult, guardedFileWrite, } from "../services/files/guarded-write.js";
|
|
14
16
|
export { type FileMirrorOptions, type FileMirrorResult, type FileMirrorSyncOptions, type FileStep, fileMirrorStatus, fileRemoteChanges, fileSyncState, MAX_DELETIONS, MAX_REPLACEMENTS, type MirrorHints, syncFileMirror, syncFileMirrors, } from "../services/files/mirror.js";
|
|
15
|
-
export {
|
|
17
|
+
export { MAX_MERGE_BYTES, mergeable, mergeText, type TextMerge, type TextSegment, } from "../services/files/text-merge.js";
|
|
18
|
+
export { type FileVersion, type FileVersions, fileVersions, restoreFileVersion, type VersionDirection, type VersionEvent, type VersionParts, type VersionRole, } from "../services/files/versions.js";
|
|
16
19
|
export { type Block, blockKey, blockShape, type Inline, type ListKind, normalizeInlines } from "./blocks.js";
|
|
17
20
|
export { catalogFiles } from "./catalog.js";
|
|
18
|
-
export type { Expect, FileEntry, FileMirrorState, FileMirrorStatePort, FileStepKind, FileTarget, RemoteFile, } from "./file-mirror-model.js";
|
|
21
|
+
export type { Expect, FileConflict, FileEntry, FileMirrorState, FileMirrorStatePort, FileStepKind, FileTarget, RemoteFile, } from "./file-mirror-model.js";
|
|
19
22
|
export { htmlToMarkdown, markdownToHtml } from "./html-markdown.js";
|
|
20
23
|
export { markdownBlocks, type PlacedBlock, placedMarkdownBlocks } from "./markdown-blocks.js";
|
|
21
|
-
export type { DocumentSource, FeedlessDocumentSource, IndexedSource, PictureWriter, SourceChange, SourceContent, SourceFile, SourceIndex, SourceSkip, SourceState, SourceStatePort, SourceWalk, SourceWork, TabText, } from "./model.js";
|
|
24
|
+
export type { DocumentSource, FeedlessDocumentSource, IndexedSource, PictureWriter, SourceChange, SourceContent, SourceFile, SourceIndex, SourceRemoval, SourceSkip, SourceState, SourceStatePort, SourceWalk, SourceWork, TabText, } from "./model.js";
|
|
22
25
|
export { feedOf } from "./model.js";
|
|
23
26
|
export type { ConflictPart, DocumentTarget, Keep, LocalDocument, Prepared, PushEntry, Pushed, PushPlan, PushState, PushStatePort, RemoteChange, } from "./push-model.js";
|
|
24
27
|
export { inScope, type SourceQuery, within } from "./scope.js";
|
package/dist/documents/index.js
CHANGED
|
@@ -8,9 +8,12 @@ export { watchMirrors, } from "../services/documents/mirror-watch.js";
|
|
|
8
8
|
export { conflictReport, fileMirrorState, mirrorId, mirrorStatus, syncMirrors, } from "../services/documents/mirrors.js";
|
|
9
9
|
export { extractDocumentMemories } from "../services/documents/proposals.js";
|
|
10
10
|
export { planPush, pushDocuments, scanLocal, skippedName, } from "../services/documents/push.js";
|
|
11
|
-
export { syncDocuments } from "../services/documents/sync.js";
|
|
11
|
+
export { KEEP_VERSIONS_FOR_DAYS, syncDocuments } from "../services/documents/sync.js";
|
|
12
|
+
export { listFileConflicts, resolveFileConflict, showFileConflict, } from "../services/files/conflicts.js";
|
|
12
13
|
export { excludedBy, exclusionPattern } from "../services/files/exclusions.js";
|
|
14
|
+
export { guardedFileWrite, } from "../services/files/guarded-write.js";
|
|
13
15
|
export { fileMirrorStatus, fileRemoteChanges, fileSyncState, MAX_DELETIONS, MAX_REPLACEMENTS, syncFileMirror, syncFileMirrors, } from "../services/files/mirror.js";
|
|
16
|
+
export { MAX_MERGE_BYTES, mergeable, mergeText, } from "../services/files/text-merge.js";
|
|
14
17
|
export { fileVersions, restoreFileVersion, } from "../services/files/versions.js";
|
|
15
18
|
export { blockKey, blockShape, normalizeInlines } from "./blocks.js";
|
|
16
19
|
export { catalogFiles } from "./catalog.js";
|
|
@@ -26,9 +26,20 @@ export interface SourceContent<M extends SourceFile = SourceFile> {
|
|
|
26
26
|
notRead?: string;
|
|
27
27
|
raw?: unknown;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Why a document left the sync's copy. `deleted` only on a direct signal from the source (its trash, a delete event);
|
|
31
|
+
* `unavailable` when the source no longer shows it but may still hold it (a 404 that can mean unshared, lost access);
|
|
32
|
+
* `unsynced` when it left the synced folders.
|
|
33
|
+
*/
|
|
34
|
+
export type SourceRemoval = "deleted" | "unavailable" | "unsynced";
|
|
29
35
|
export interface SourceChange<M extends SourceFile = SourceFile> {
|
|
30
36
|
id: string;
|
|
31
37
|
removed: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* What a removal means. Left out, a removal counts as `unavailable` and the document keeps its text: a removal
|
|
40
|
+
* from a feed can be a lost share as well as a deletion. A source sets `deleted` only when it knows.
|
|
41
|
+
*/
|
|
42
|
+
gone?: "deleted" | "unavailable";
|
|
32
43
|
file?: M;
|
|
33
44
|
}
|
|
34
45
|
/**
|
|
@@ -85,6 +96,8 @@ export interface SourceWork<M extends SourceFile = SourceFile> {
|
|
|
85
96
|
id: string;
|
|
86
97
|
kind: "save" | "remove";
|
|
87
98
|
file?: M;
|
|
99
|
+
/** A removal's reason; a job saved before reasons existed counts as `unavailable`. */
|
|
100
|
+
reason?: SourceRemoval;
|
|
88
101
|
}
|
|
89
102
|
export interface SourceSkip<M extends SourceFile = SourceFile> {
|
|
90
103
|
id: string;
|
|
@@ -137,7 +150,9 @@ export interface SourceIndex<M extends SourceFile = SourceFile> {
|
|
|
137
150
|
import(principal: string, files: M[]): Promise<unknown>;
|
|
138
151
|
};
|
|
139
152
|
save(principal: string, content: SourceContent<M>, hash: string): Promise<string>;
|
|
140
|
-
remove(principal: string, id: string): Promise<void>;
|
|
153
|
+
remove(principal: string, id: string, reason?: SourceRemoval): Promise<void>;
|
|
154
|
+
/** Drops the history older than `before` (ISO 8601); a sync calls it when a pass completes. */
|
|
155
|
+
prune?(principal: string, before: string): Promise<unknown>;
|
|
141
156
|
openPictures(): Promise<PictureWriter>;
|
|
142
157
|
/** Indexes what the sync saved for word search, until `until` says stop; the rest waits for the next search. */
|
|
143
158
|
settle?(options: {
|
package/dist/errors/reasons.js
CHANGED
|
@@ -87,6 +87,7 @@ const PROVIDER_API = [
|
|
|
87
87
|
validation("file.not-a-file", "the path names a folder or another thing that is not a file"),
|
|
88
88
|
["file.denied", "permission_error", "the file cannot be opened: permission denied"],
|
|
89
89
|
validation("file.too-large", "the file is larger than the limit set for this read"),
|
|
90
|
+
validation("file.not-plain-text", "the file's text is extracted on a read; writing it back would replace the file"),
|
|
90
91
|
];
|
|
91
92
|
/** The read-only SFTP client (`./sftp`). */
|
|
92
93
|
const SFTP = [
|
|
@@ -204,6 +205,7 @@ const OTHERS = [
|
|
|
204
205
|
validation("agent.cost-unknown", "the agent reports no cost, so a cost cap cannot stop it"),
|
|
205
206
|
validation("document.changed", "the document changed while it was read; nothing was saved"),
|
|
206
207
|
["document.not-imported", "not_found", "the document is not imported in this source account"],
|
|
208
|
+
["document.version-missing", "not_found", "the local copy holds no such version of the document"],
|
|
207
209
|
["document.not-found", "not_found", "no listed document has that reference"],
|
|
208
210
|
["state.unreadable", "configuration_error", "a sync state file cannot be read; move it away and sync again"],
|
|
209
211
|
["profile.busy", "provider_unavailable", "another sync or write holds this profile's local copy"],
|
|
@@ -257,6 +259,8 @@ const OTHERS = [
|
|
|
257
259
|
"the earlier content could not be kept in the version store, so the sync did not replace it",
|
|
258
260
|
],
|
|
259
261
|
["mirror.remote-changed", "conflict", "the remote file changed since the listing; the next sync settles it"],
|
|
262
|
+
["mirror.local-changed", "conflict", "the local file changed since the conflict was found; nothing was written"],
|
|
263
|
+
["mirror.no-conflict", "not_found", "the path has no recorded conflict; the last sync settled it or never saw one"],
|
|
260
264
|
["upload.mismatch", "conflict", "the uploaded file reads back with other content; the local file changed meanwhile"],
|
|
261
265
|
["download.mismatch", "invalid_response", "the downloaded file has other content than the listing said"],
|
|
262
266
|
["catalog.unavailable", "configuration_error", "the store has no shared catalog for this account"],
|
|
@@ -583,8 +587,9 @@ const OTHERS = [
|
|
|
583
587
|
["person.no-owner", "not_found", "no person is marked as the owner in the store"],
|
|
584
588
|
["person.unknown", "not_found", "the store has no person by that reference; people list gives person:<uid>"],
|
|
585
589
|
["person.no-doubt", "not_found", "nothing about that person is in doubt; people links check lists who is"],
|
|
586
|
-
validation("person.owner", "the owner's own person is not test data"),
|
|
590
|
+
validation("person.owner", "the owner's own person is not test data, and is never deleted"),
|
|
587
591
|
validation("person.no-identity", "a person with no identity is not test data; there is nothing to hide"),
|
|
592
|
+
validation("person.erase-blocked", "an invoice, order, subscription or a row the person wrote still names them; change those first, nothing was deleted"),
|
|
588
593
|
validation("person.from-required", "say whom the identity leaves: --from person:<uid>, or person:me for the owner"),
|
|
589
594
|
[
|
|
590
595
|
"identity.separated",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface DocxParagraph {
|
|
2
|
+
/** Position among the body's paragraphs, table cells included, in document order; edits address it. */
|
|
3
|
+
readonly index: number;
|
|
4
|
+
readonly text: string;
|
|
5
|
+
readonly styleId?: string;
|
|
6
|
+
/** The style's display name from styles.xml, such as "Heading 1". */
|
|
7
|
+
readonly style?: string;
|
|
8
|
+
readonly location: "body" | "table";
|
|
9
|
+
/** Whether `editDocxParagraphs` may replace or delete it; `reason` says why not. */
|
|
10
|
+
readonly editable: boolean;
|
|
11
|
+
readonly reason?: string;
|
|
12
|
+
/** Runs with different formatting: replacing the text collapses them to the first run's formatting. */
|
|
13
|
+
readonly mixedFormatting: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type DocxEdit = {
|
|
16
|
+
readonly index: number;
|
|
17
|
+
readonly text: string;
|
|
18
|
+
}
|
|
19
|
+
/** `insertAfter: -1` puts the paragraph before the first one. `styleFrom` defaults to the neighbour. */
|
|
20
|
+
| {
|
|
21
|
+
readonly insertAfter: number;
|
|
22
|
+
readonly text: string;
|
|
23
|
+
readonly styleFrom?: number;
|
|
24
|
+
} | {
|
|
25
|
+
readonly delete: number;
|
|
26
|
+
};
|
|
27
|
+
export interface EditDocxResult {
|
|
28
|
+
readonly bytes: Uint8Array;
|
|
29
|
+
readonly replaced: number[];
|
|
30
|
+
readonly inserted: number;
|
|
31
|
+
readonly deleted: number[];
|
|
32
|
+
/** Replaced paragraphs whose mixed inline formatting (bold words, links of colour) became the first run's. */
|
|
33
|
+
readonly collapsed: number[];
|
|
34
|
+
}
|
|
35
|
+
/** The body's paragraphs, table cells included, with their style and whether the editor can change them. */
|
|
36
|
+
export declare const readDocxParagraphs: (bytes: Uint8Array) => Promise<DocxParagraph[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Edits paragraph text in place: only document.xml is rewritten, by splicing the edited paragraphs into its original
|
|
39
|
+
* text, and every other zip entry is copied byte for byte. Indexes refer to the document as it was read. A replaced
|
|
40
|
+
* paragraph keeps its properties (style, numbering, alignment) and its first text run's formatting; the rest of its
|
|
41
|
+
* inline formatting collapses to that (listed in `collapsed`).
|
|
42
|
+
*/
|
|
43
|
+
export declare const editDocxParagraphs: (bytes: Uint8Array, edits: readonly DocxEdit[]) => Promise<EditDocxResult>;
|