@mnaoumov/obsidian-lib 10.3.0 → 10.4.1

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.
Files changed (51) hide show
  1. package/command-handlers/undo-bulk-operation-command-handler/package.json +6 -0
  2. package/components/bulk-operation-commit-component/package.json +6 -0
  3. package/dist/lib/cjs/__merged.cjs +42 -1
  4. package/dist/lib/cjs/__merged.d.cts +5 -0
  5. package/dist/lib/cjs/bulk-operation-progress.cjs +120 -0
  6. package/dist/lib/cjs/bulk-operation-progress.d.cts +33 -0
  7. package/dist/lib/cjs/bulk-operation.cjs +220 -0
  8. package/dist/lib/cjs/bulk-operation.d.cts +237 -0
  9. package/dist/lib/cjs/command-handlers/index.cjs +4 -1
  10. package/dist/lib/cjs/command-handlers/index.d.cts +1 -0
  11. package/dist/lib/cjs/command-handlers/undo-bulk-operation-command-handler.cjs +164 -0
  12. package/dist/lib/cjs/command-handlers/undo-bulk-operation-command-handler.d.cts +51 -0
  13. package/dist/lib/cjs/components/bulk-operation-commit-component.cjs +337 -0
  14. package/dist/lib/cjs/components/bulk-operation-commit-component.d.cts +152 -0
  15. package/dist/lib/cjs/components/index.cjs +4 -1
  16. package/dist/lib/cjs/components/index.d.cts +1 -0
  17. package/dist/lib/cjs/data-stores/local-data-store.cjs +2 -3
  18. package/dist/lib/cjs/desktop-bulk-operation-git.cjs +534 -0
  19. package/dist/lib/cjs/desktop-bulk-operation-git.d.cts +196 -0
  20. package/dist/lib/cjs/generated-during-build.cjs +1 -1
  21. package/dist/lib/cjs/i18n/locales/en.cjs +10 -1
  22. package/dist/lib/cjs/i18n/locales/en.d.cts +9 -0
  23. package/dist/lib/cjs/i18n/locales/translations-map.d.cts +9 -0
  24. package/dist/lib/cjs/index.cjs +10 -1
  25. package/dist/lib/cjs/index.d.cts +3 -0
  26. package/dist/lib/cjs/loop.cjs +3 -1
  27. package/dist/lib/esm/__merged.d.mts +5 -0
  28. package/dist/lib/esm/__merged.mjs +43 -1
  29. package/dist/lib/esm/bulk-operation-progress.d.mts +33 -0
  30. package/dist/lib/esm/bulk-operation-progress.mjs +31 -0
  31. package/dist/lib/esm/bulk-operation.d.mts +237 -0
  32. package/dist/lib/esm/bulk-operation.mjs +125 -0
  33. package/dist/lib/esm/command-handlers/index.d.mts +1 -0
  34. package/dist/lib/esm/command-handlers/index.mjs +3 -1
  35. package/dist/lib/esm/command-handlers/undo-bulk-operation-command-handler.d.mts +51 -0
  36. package/dist/lib/esm/command-handlers/undo-bulk-operation-command-handler.mjs +76 -0
  37. package/dist/lib/esm/components/bulk-operation-commit-component.d.mts +152 -0
  38. package/dist/lib/esm/components/bulk-operation-commit-component.mjs +245 -0
  39. package/dist/lib/esm/components/index.d.mts +1 -0
  40. package/dist/lib/esm/components/index.mjs +3 -1
  41. package/dist/lib/esm/data-stores/local-data-store.mjs +2 -3
  42. package/dist/lib/esm/desktop-bulk-operation-git.d.mts +196 -0
  43. package/dist/lib/esm/desktop-bulk-operation-git.mjs +463 -0
  44. package/dist/lib/esm/generated-during-build.mjs +1 -1
  45. package/dist/lib/esm/i18n/locales/en.d.mts +9 -0
  46. package/dist/lib/esm/i18n/locales/en.mjs +10 -1
  47. package/dist/lib/esm/i18n/locales/translations-map.d.mts +9 -0
  48. package/dist/lib/esm/index.d.mts +3 -0
  49. package/dist/lib/esm/index.mjs +7 -1
  50. package/dist/lib/esm/loop.mjs +3 -1
  51. package/package.json +2 -1
@@ -0,0 +1,196 @@
1
+ /// <reference path="./library-references.d.mts" />
2
+ /**
3
+ * @file
4
+ *
5
+ * The desktop half of bulk-operation git commits: drives the system `git` CLI to wrap a bulk operation in commits,
6
+ * guarded by a lease lock in the repo's git directory.
7
+ *
8
+ * The system CLI is used rather than a bundled implementation because it honors the repo's own config, hooks
9
+ * and clean/smudge filters, git-annex's among them, and because `git revert` is the whole undo story.
10
+ *
11
+ * Every command runs with the vault folder as its working directory and `.` as its pathspec, so when the vault is a
12
+ * subfolder of a larger repo only the vault's changes are committed.
13
+ *
14
+ * Desktop-only (`node:child_process`, `node:fs`, `node:os`), but inert to import on mobile: nothing here touches a
15
+ * Node builtin until a function is called.
16
+ */
17
+ import type { BulkOperationCommit } from './bulk-operation.mjs';
18
+ /**
19
+ * Constructor parameters for {@link BulkOperationGitRepo}.
20
+ */
21
+ export interface BulkOperationGitRepoConstructorParams {
22
+ /**
23
+ * The absolute path of the repo's git directory, where the lease lock lives.
24
+ */
25
+ readonly gitDirectory: string;
26
+ /**
27
+ * How long to wait for another operation's lock before giving up.
28
+ *
29
+ * @default `600_000`
30
+ */
31
+ readonly lockWaitTimeoutInMilliseconds?: number;
32
+ /**
33
+ * The absolute path of the folder whose changes are committed: the vault root.
34
+ */
35
+ readonly workingDirectory: string;
36
+ }
37
+ /**
38
+ * Parameters for {@link BulkOperationGitRepo.runBulkOperation}.
39
+ *
40
+ * @typeParam T - The type of the operation's result.
41
+ */
42
+ export interface BulkOperationGitRepoRunBulkOperationParams<T> {
43
+ /**
44
+ * Runs the bulk operation.
45
+ *
46
+ * @returns The operation's result.
47
+ */
48
+ readonly operation: () => Promise<T>;
49
+ /**
50
+ * The id of the plugin running the operation.
51
+ */
52
+ readonly pluginId: string;
53
+ /**
54
+ * Waits for the follow-ups the operation set off (rename handlers, link updates, the metadata cache) to finish, so
55
+ * their changes land in the operation's commit.
56
+ */
57
+ readonly settle: () => Promise<void>;
58
+ /**
59
+ * A one-line description of the operation, used in the commit subject.
60
+ */
61
+ readonly summary: string;
62
+ }
63
+ /**
64
+ * The result of {@link BulkOperationGitRepo.runBulkOperation}.
65
+ *
66
+ * @typeParam T - The type of the operation's result.
67
+ */
68
+ export interface GitBulkOperationResult<T> {
69
+ /**
70
+ * The hash of the commit recording the operation, or `null` when the operation changed nothing.
71
+ */
72
+ readonly commitSha: null | string;
73
+ /**
74
+ * The operation id, such as `OP12`.
75
+ */
76
+ readonly operationId: string;
77
+ /**
78
+ * The operation's result.
79
+ */
80
+ readonly result: T;
81
+ }
82
+ /**
83
+ * The result of {@link BulkOperationGitRepo.revertBulkOperationCommit}.
84
+ */
85
+ export interface GitRevertResult {
86
+ /**
87
+ * Whether the revert stopped on a conflict, leaving the repo mid-revert for the user to resolve.
88
+ */
89
+ readonly isConflict: boolean;
90
+ /**
91
+ * What git printed.
92
+ */
93
+ readonly output: string;
94
+ }
95
+ /**
96
+ * A git repo holding a vault, driven to wrap bulk operations in commits.
97
+ */
98
+ export declare class BulkOperationGitRepo {
99
+ /**
100
+ * The absolute path of the repo's git directory.
101
+ */
102
+ readonly gitDirectory: string;
103
+ /**
104
+ * The absolute path of the folder whose changes are committed.
105
+ */
106
+ readonly workingDirectory: string;
107
+ private readonly lockFilePath;
108
+ private readonly lockWaitTimeoutInMilliseconds;
109
+ private ownLock;
110
+ /**
111
+ * Creates a new instance. Use {@link BulkOperationGitRepo.open} to find the repo of a folder.
112
+ *
113
+ * @param params - The constructor parameters.
114
+ */
115
+ constructor(params: BulkOperationGitRepoConstructorParams);
116
+ /**
117
+ * Finds the git repo a folder belongs to.
118
+ *
119
+ * @param workingDirectory - The folder, normally the vault root.
120
+ * @returns The repo, or `null` when the folder is not inside a git work tree or `git` cannot be run.
121
+ */
122
+ static open(workingDirectory: string): Promise<BulkOperationGitRepo | null>;
123
+ /**
124
+ * Refuses to go on when the repo routes files through git-annex but `git-annex` cannot be run, since a
125
+ * plain `git add` would then put the large files into git itself.
126
+ */
127
+ assertCanCommitLargeFiles(): Promise<void>;
128
+ /**
129
+ * Lists the bulk-operation commits a plugin made on the current branch, newest first.
130
+ *
131
+ * @param pluginId - The plugin id.
132
+ * @returns The commits.
133
+ */
134
+ listBulkOperationCommits(pluginId: string): Promise<BulkOperationCommit[]>;
135
+ /**
136
+ * Commits whatever a stale lock's operation left behind as `OP<n> interrupted` and removes the lock.
137
+ *
138
+ * @returns The id of the recovered operation, or `null` when there was no stale lock.
139
+ */
140
+ recoverStaleLock(): Promise<null | string>;
141
+ /**
142
+ * Reverts a bulk-operation commit with `git revert --no-edit`.
143
+ *
144
+ * Whatever is pending is committed first, so the revert starts from a clean tree. A conflict is NOT aborted: the
145
+ * repo is left mid-revert for the user to resolve.
146
+ *
147
+ * @param commit - The commit to revert.
148
+ * @returns Whether the revert stopped on a conflict, and what git printed.
149
+ */
150
+ revertBulkOperationCommit(commit: BulkOperationCommit): Promise<GitRevertResult>;
151
+ /**
152
+ * Runs a bulk operation between two commits.
153
+ *
154
+ * Takes the lease lock, commits whatever is pending as `chore: before OP<n>`, runs the operation, waits for its
155
+ * follow-ups to settle, commits the result as `OP<n>: <summary>` and releases the lock. An operation that throws
156
+ * still gets its partial changes committed, as `OP<n> interrupted`, before the error is rethrown.
157
+ *
158
+ * @typeParam T - The type of the operation's result.
159
+ * @param params - The parameters.
160
+ * @returns The operation's result, its id and the hash of its commit.
161
+ */
162
+ runBulkOperation<T>(params: BulkOperationGitRepoRunBulkOperationParams<T>): Promise<GitBulkOperationResult<T>>;
163
+ private acquireLock;
164
+ private allocateOperationId;
165
+ private commitOperation;
166
+ private commitPending;
167
+ private commitStaged;
168
+ private createThrottledHeartbeat;
169
+ private findNextOperationId;
170
+ private heartbeat;
171
+ private isOwnLock;
172
+ private isStale;
173
+ private readLock;
174
+ private recover;
175
+ private releaseLock;
176
+ private runGit;
177
+ private stageAll;
178
+ private tryCreateLock;
179
+ private writeLock;
180
+ }
181
+ /**
182
+ * An error thrown when a `git` command fails.
183
+ */
184
+ export declare class GitCommandError extends Error {
185
+ readonly gitArguments: readonly string[];
186
+ readonly exitCode: number;
187
+ readonly stderr: string;
188
+ /**
189
+ * Creates a new instance.
190
+ *
191
+ * @param gitArguments - The arguments `git` was run with.
192
+ * @param exitCode - The exit code.
193
+ * @param stderr - What `git` printed to stderr.
194
+ */
195
+ constructor(gitArguments: readonly string[], exitCode: number, stderr: string);
196
+ }