@wirecat/cli-core 0.738.0 → 0.740.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 +59 -0
- package/dist/attachments/ocr.d.ts +2 -0
- package/dist/attachments/ocr.js +2 -1
- package/dist/attachments/tesseract.d.ts +11 -0
- package/dist/attachments/tesseract.js +82 -0
- package/dist/cli/documents/file-edit.js +79 -34
- package/dist/cli/documents/file-update.d.ts +5 -0
- package/dist/cli/documents/index.d.ts +2 -1
- package/dist/cli/documents/index.js +2 -1
- package/dist/cli/documents/library.d.ts +12 -0
- package/dist/cli/documents/library.js +33 -3
- package/dist/cli/documents/manifest/manifest.d.ts +10 -0
- package/dist/cli/documents/manifest/manifest.js +9 -1
- package/dist/cli/documents/manifest/source.d.ts +4 -1
- package/dist/cli/documents/manifest/source.js +67 -1
- package/dist/cli/documents/rekey.d.ts +22 -0
- package/dist/cli/documents/rekey.js +25 -0
- package/dist/documents/file-mirror-model.d.ts +4 -1
- package/dist/documents/index.d.ts +1 -0
- package/dist/documents/index.js +1 -0
- package/dist/documents/model.d.ts +8 -0
- package/dist/errors/reasons.js +6 -15
- package/dist/errors/sftp-reasons.d.ts +5 -0
- package/dist/errors/sftp-reasons.js +15 -0
- package/dist/office/create.d.ts +38 -7
- package/dist/office/create.js +84 -20
- package/dist/office/index.d.ts +1 -1
- package/dist/services/documents/file-text.d.ts +6 -1
- package/dist/services/documents/file-text.js +29 -11
- package/dist/services/documents/ingestion.d.ts +5 -0
- package/dist/services/documents/ingestion.js +21 -1
- package/dist/services/documents/plan.js +151 -102
- package/dist/services/documents/ports.d.ts +3 -0
- package/dist/services/documents/scans.d.ts +42 -0
- package/dist/services/documents/scans.js +136 -0
- package/dist/services/documents/sync.js +57 -4
- package/dist/services/files/guarded-write.d.ts +6 -0
- package/dist/services/files/guarded-write.js +7 -1
- package/dist/services/files/mirror.js +2 -3
- package/dist/store/sqlite/file-note-rekey.d.ts +8 -0
- package/dist/store/sqlite/file-note-rekey.js +47 -0
- package/dist/store/sqlite/notes.d.ts +7 -2
- package/dist/store/sqlite/notes.js +4 -1
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
5
5
|
import { eachMirror, heldCheck } from "../documents/mirrors.js";
|
|
6
6
|
import { assertNoLink, localTemp, replaceLocal, safePath, skippedName, } from "../documents/push.js";
|
|
7
7
|
import { excludedBy } from "./exclusions.js";
|
|
8
|
+
import { ownConflict } from "./guarded-write.js";
|
|
8
9
|
import { listRemote } from "./listing.js";
|
|
9
10
|
import { ancestors, copyName, freeSpace, gigabytes, linkFree, MAX_FILES, renameLocal, scan, shortOfSpace, spareFor, trashLocal, under, whole, } from "./local-files.js";
|
|
10
11
|
import { mergeable, mergeText } from "./text-merge.js";
|
|
@@ -747,9 +748,7 @@ export const syncFileMirror = async (options) => {
|
|
|
747
748
|
break;
|
|
748
749
|
}
|
|
749
750
|
if (failure.code === "conflict")
|
|
750
|
-
conflict(step, failure.
|
|
751
|
-
? failure.message
|
|
752
|
-
: `the ${options.remote} file changed during the sync`);
|
|
751
|
+
conflict(step, ownConflict(failure) !== undefined ? failure.message : `the ${options.remote} file changed during the sync`);
|
|
753
752
|
else
|
|
754
753
|
result.errors.push({ path: step.path, code: failure.code, message: failure.message });
|
|
755
754
|
// Not retried: the next listing shows whether it landed, and adopts it when it did.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CacheDatabase } from "../driver.js";
|
|
2
|
+
/**
|
|
3
|
+
* Readies the document at `from` to move to `target`, the path of the id its source gave the file after a replace, so
|
|
4
|
+
* it keeps its id and with it the tags, the notes about it and its links. A sync that ran between the replace and this
|
|
5
|
+
* call took the document out at `from` and filed the file anew at `target`: the new text joins the old document, the
|
|
6
|
+
* new one goes, and the old one is live again. False when nothing was ever at `from`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const foldRekeyed: (database: CacheDatabase, folder: number, from: string, target: string, at: number) => boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { keepRevision, logDocumentChange } from "./document-history.js";
|
|
2
|
+
import { deleteDocumentRow } from "./evidence-signature.js";
|
|
3
|
+
const CONTENT = ["title", "body", "front_matter", "content_hash", "metadata", "language"];
|
|
4
|
+
const documentAt = (database, folder, path) => {
|
|
5
|
+
const place = database
|
|
6
|
+
.prepare("SELECT document_id FROM files WHERE account_id = ? AND external_id = ? AND kind <> 'folder'")
|
|
7
|
+
.get(folder, path);
|
|
8
|
+
return place?.document_id != null
|
|
9
|
+
? database.prepare("SELECT * FROM documents WHERE id = ?").get(Number(place.document_id))
|
|
10
|
+
: database.prepare("SELECT * FROM documents WHERE account_id = ? AND external_id = ?").get(folder, path);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Readies the document at `from` to move to `target`, the path of the id its source gave the file after a replace, so
|
|
14
|
+
* it keeps its id and with it the tags, the notes about it and its links. A sync that ran between the replace and this
|
|
15
|
+
* call took the document out at `from` and filed the file anew at `target`: the new text joins the old document, the
|
|
16
|
+
* new one goes, and the old one is live again. False when nothing was ever at `from`.
|
|
17
|
+
*/
|
|
18
|
+
export const foldRekeyed = (database, folder, from, target, at) => {
|
|
19
|
+
const old = documentAt(database, folder, from);
|
|
20
|
+
if (!old)
|
|
21
|
+
return false;
|
|
22
|
+
const id = Number(old.id);
|
|
23
|
+
const filed = documentAt(database, folder, target);
|
|
24
|
+
if (filed && Number(filed.id) !== id) {
|
|
25
|
+
// A catalog entry not read yet has no text; the old document's stays until the next read.
|
|
26
|
+
if (filed.body != null) {
|
|
27
|
+
if ((old.body ?? "") !== "" && old.deleted_at == null)
|
|
28
|
+
keepRevision(database, old, at);
|
|
29
|
+
database
|
|
30
|
+
.prepare(`UPDATE documents SET ${CONTENT.map((column) => `${column} = ?`).join(", ")}, revision = revision + 1, ` +
|
|
31
|
+
"updated_at = ? WHERE id = ?")
|
|
32
|
+
.run(...CONTENT.map((column) => filed[column] ?? null), at, id);
|
|
33
|
+
}
|
|
34
|
+
deleteDocumentRow(database, Number(filed.id), at);
|
|
35
|
+
database
|
|
36
|
+
.prepare("DELETE FROM files WHERE account_id = ? AND external_id = ? AND kind <> 'folder'")
|
|
37
|
+
.run(folder, target);
|
|
38
|
+
}
|
|
39
|
+
if (old.deleted_at != null) {
|
|
40
|
+
database.prepare("UPDATE documents SET deleted_at = NULL, removal = NULL WHERE id = ?").run(id);
|
|
41
|
+
database
|
|
42
|
+
.prepare("UPDATE files SET deleted_at = NULL WHERE account_id = ? AND external_id = ? AND kind <> 'folder'")
|
|
43
|
+
.run(folder, from);
|
|
44
|
+
logDocumentChange(database, id, "restored", at);
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
};
|
|
@@ -137,8 +137,13 @@ export interface NotesStore extends NoteSearch, ImportedDocuments, AddedSources,
|
|
|
137
137
|
note: Note;
|
|
138
138
|
changed: boolean;
|
|
139
139
|
}>;
|
|
140
|
-
/**
|
|
141
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Moves a file note to a new path in its folder, keeping its id, links and tags; a gone note at `to` is dropped.
|
|
142
|
+
* `fold` is for a source that gave the file a new id: see `foldRekeyed`.
|
|
143
|
+
*/
|
|
144
|
+
renameFileNote(folderId: string, from: string, to: string, options?: {
|
|
145
|
+
fold?: boolean;
|
|
146
|
+
}): Promise<Note>;
|
|
142
147
|
/**
|
|
143
148
|
* Sets the time the source dates each note at these paths (ISO 8601), the note's `modifiedAt`, without counting
|
|
144
149
|
* as an edit: text, revision and `updatedAt` stay. Answers how many notes it changed.
|
|
@@ -13,6 +13,7 @@ import { documentHistoryOver, keepRevision, logDocumentChange, removeDocument }
|
|
|
13
13
|
import { encodeDocumentMetadata, languageOf } from "./document-metadata.js";
|
|
14
14
|
import { deleteDocumentRow, forgetEvidenceToRow } from "./evidence-signature.js";
|
|
15
15
|
import { fileNoteRow } from "./file-note.js";
|
|
16
|
+
import { foldRekeyed } from "./file-note-rekey.js";
|
|
16
17
|
import { PREFERRED_FILE, syncFile } from "./files.js";
|
|
17
18
|
import { importedDocumentWhere } from "./imported-documents.js";
|
|
18
19
|
import { LINK_KINDS, LINK_ORIGINS, linkKind, RELATION_KINDS } from "./link-kinds.js";
|
|
@@ -456,10 +457,12 @@ export const notesStoreOver = (context) => {
|
|
|
456
457
|
followPreferred(id, at);
|
|
457
458
|
return { note: noteAt(id, folder, path), changed: !same };
|
|
458
459
|
}),
|
|
459
|
-
renameFileNote: async (folderId, from, to) => write(database, () => {
|
|
460
|
+
renameFileNote: async (folderId, from, to, options) => write(database, () => {
|
|
460
461
|
const folder = Number(folderRow(folderId, true).id);
|
|
461
462
|
const target = textOf(to, "a note's path", 4096);
|
|
462
463
|
const at = now();
|
|
464
|
+
if (options?.fold)
|
|
465
|
+
foldRekeyed(database, folder, from, target, at);
|
|
463
466
|
const place = fileAt(folder, from, true);
|
|
464
467
|
const legacy = database
|
|
465
468
|
.prepare("SELECT id FROM documents WHERE account_id = ? AND external_id = ? AND deleted_at IS NULL")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.740.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|