imdone-core 2.3.3 → 2.3.4
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/_index.md +0 -1
- package/lib/default-filtered-move-position.js +36 -0
- package/lib/index.js +1 -0
- package/lib/mixins/repo-watched-fs-store.js +43 -16
- package/lib/project.js +12 -0
- package/package.json +1 -1
- package/types/default-filtered-move-position.d.ts +7 -0
- package/types/index.d.ts +1 -0
- package/types/project.d.ts +1 -0
- package/.imdone-cli.yml +0 -3
package/_index.md
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function sameTask(left, right) {
|
|
2
|
+
return Boolean(left && right && left.equals(right))
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function resolveDefaultFilteredMovePosition({
|
|
6
|
+
task,
|
|
7
|
+
newList,
|
|
8
|
+
newPosition,
|
|
9
|
+
filteredCards,
|
|
10
|
+
repositoryListCards,
|
|
11
|
+
}) {
|
|
12
|
+
const visibleDestinationCards = filteredCards
|
|
13
|
+
.filter(candidate => candidate.list === newList && !sameTask(candidate, task))
|
|
14
|
+
|
|
15
|
+
if (!Number.isInteger(newPosition)
|
|
16
|
+
|| newPosition < 0
|
|
17
|
+
|| newPosition > visibleDestinationCards.length) {
|
|
18
|
+
throw new RangeError(`Filtered task position is outside ${newList}: ${newPosition}`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const destinationCards = repositoryListCards
|
|
22
|
+
.filter(candidate => !sameTask(candidate, task))
|
|
23
|
+
if (visibleDestinationCards.length === 0) return destinationCards.length
|
|
24
|
+
|
|
25
|
+
const anchor = visibleDestinationCards[
|
|
26
|
+
Math.min(newPosition, visibleDestinationCards.length - 1)
|
|
27
|
+
]
|
|
28
|
+
const anchorPosition = destinationCards.findIndex(candidate => sameTask(candidate, anchor))
|
|
29
|
+
if (anchorPosition < 0) {
|
|
30
|
+
throw new Error(`Filtered task is missing from ${newList}: ${anchor.id}`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return newPosition < visibleDestinationCards.length
|
|
34
|
+
? anchorPosition
|
|
35
|
+
: anchorPosition + 1
|
|
36
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './checksum.js';
|
|
|
5
5
|
export * from './clone.js';
|
|
6
6
|
export * from './config.js';
|
|
7
7
|
export * from './constants.js';
|
|
8
|
+
export * from './default-filtered-move-position.js';
|
|
8
9
|
export * from './default-settings.js';
|
|
9
10
|
export * from './file.js';
|
|
10
11
|
export * from './get-tasks-to-modify.js';
|
|
@@ -19,6 +19,20 @@ export function watchedFileSystemStoreMixin(repo, fs = realFs) {
|
|
|
19
19
|
let initializing = false
|
|
20
20
|
let refreshing = false
|
|
21
21
|
let watcherPaused = false
|
|
22
|
+
const watcherEvents = new Set()
|
|
23
|
+
|
|
24
|
+
function trackWatcherEvent(listener) {
|
|
25
|
+
return (...args) => {
|
|
26
|
+
const event = Promise.resolve().then(() => listener(...args))
|
|
27
|
+
const trackedEvent = event.catch((err) => {
|
|
28
|
+
logger.error('Error processing watcher event')
|
|
29
|
+
logger.error(err)
|
|
30
|
+
repo.emit('watch.error', err)
|
|
31
|
+
})
|
|
32
|
+
watcherEvents.add(trackedEvent)
|
|
33
|
+
void trackedEvent.finally(() => watcherEvents.delete(trackedEvent))
|
|
34
|
+
}
|
|
35
|
+
}
|
|
22
36
|
|
|
23
37
|
function ready() {
|
|
24
38
|
return !initializing && !refreshing
|
|
@@ -80,6 +94,7 @@ export function watchedFileSystemStoreMixin(repo, fs = realFs) {
|
|
|
80
94
|
|
|
81
95
|
repo.destroy = async function () {
|
|
82
96
|
if (repo.watcher) await repo.watcher.close()
|
|
97
|
+
await Promise.allSettled([...watcherEvents])
|
|
83
98
|
await _destroy.apply(repo)
|
|
84
99
|
}
|
|
85
100
|
|
|
@@ -147,7 +162,10 @@ export function watchedFileSystemStoreMixin(repo, fs = realFs) {
|
|
|
147
162
|
persistent: true,
|
|
148
163
|
usePolling: false,
|
|
149
164
|
alwaysStat: true,
|
|
150
|
-
awaitWriteFinish:
|
|
165
|
+
awaitWriteFinish: {
|
|
166
|
+
stabilityThreshold: 200,
|
|
167
|
+
pollInterval: 50,
|
|
168
|
+
},
|
|
151
169
|
atomic: true,
|
|
152
170
|
ignoreInitial: true,
|
|
153
171
|
ignored: (file) => {
|
|
@@ -169,7 +187,7 @@ export function watchedFileSystemStoreMixin(repo, fs = realFs) {
|
|
|
169
187
|
initializing = false
|
|
170
188
|
resolve()
|
|
171
189
|
})
|
|
172
|
-
.on('add', async function (path, stat) {
|
|
190
|
+
.on('add', trackWatcherEvent(async function (path, stat) {
|
|
173
191
|
logger.log('Watcher received add event for file: ' + path)
|
|
174
192
|
if (stat.isDirectory()) return
|
|
175
193
|
let file = repo.getFile(path)
|
|
@@ -192,8 +210,8 @@ export function watchedFileSystemStoreMixin(repo, fs = realFs) {
|
|
|
192
210
|
file = await repo.readFile(file)
|
|
193
211
|
repo.emit('watch.add', file)
|
|
194
212
|
repo.emitFileUpdate(file)
|
|
195
|
-
})
|
|
196
|
-
.on('change', async function (path, stat) {
|
|
213
|
+
}))
|
|
214
|
+
.on('change', trackWatcherEvent(async function (path, stat) {
|
|
197
215
|
logger.log(
|
|
198
216
|
`Watcher received change event for file: ${path} repoPath: ${repo.path}`,
|
|
199
217
|
stat.mtime
|
|
@@ -201,10 +219,10 @@ export function watchedFileSystemStoreMixin(repo, fs = realFs) {
|
|
|
201
219
|
if (!path || stat.isDirectory()) return
|
|
202
220
|
|
|
203
221
|
const relPath = repo.getRelativePath(path)
|
|
204
|
-
if (!initializing && _isImdoneConfig(relPath)) onConfigChange(relPath)
|
|
205
|
-
if (!initializing && _isImdoneIgnore(relPath)) onIgnoreChange(relPath)
|
|
222
|
+
if (!initializing && _isImdoneConfig(relPath)) return onConfigChange(relPath)
|
|
223
|
+
if (!initializing && _isImdoneIgnore(relPath)) return onIgnoreChange(relPath)
|
|
206
224
|
|
|
207
|
-
var file = repo.getFile(path)
|
|
225
|
+
var file = repo.getFile(path)
|
|
208
226
|
const isFile = File.isFile(file)
|
|
209
227
|
// BACKLOG ## Handle the case where the file is not in the repo
|
|
210
228
|
// #urgent #1.12.0
|
|
@@ -216,28 +234,37 @@ export function watchedFileSystemStoreMixin(repo, fs = realFs) {
|
|
|
216
234
|
return
|
|
217
235
|
}
|
|
218
236
|
|
|
219
|
-
const ok = await repo.fileOK(
|
|
237
|
+
const ok = await repo.fileOK(file?.path || path)
|
|
220
238
|
if (!ok) return
|
|
221
239
|
log('Reading file: ' + path)
|
|
222
|
-
if (!isFile)
|
|
240
|
+
if (!isFile) {
|
|
241
|
+
const relativePath = repo.getRelativePath(path)
|
|
242
|
+
file = repo.getFile(relativePath) || new File({
|
|
243
|
+
repoId: repo.getId(),
|
|
244
|
+
filePath: relativePath,
|
|
245
|
+
languages: repo.languages,
|
|
246
|
+
project: repo.project,
|
|
247
|
+
})
|
|
248
|
+
}
|
|
223
249
|
file = await repo.readFile(file)
|
|
224
250
|
repo.emit('watch.change', file)
|
|
225
251
|
repo.emitFileUpdate(file)
|
|
226
|
-
})
|
|
227
|
-
.on('
|
|
252
|
+
}))
|
|
253
|
+
.on('unlink', trackWatcherEvent(async function (path) {
|
|
228
254
|
log('Watcher received unlink event for file: ' + path)
|
|
229
|
-
repo.
|
|
230
|
-
|
|
255
|
+
const relativePath = repo.getRelativePath(path)
|
|
256
|
+
const file = repo.getFile(relativePath) || new File({
|
|
231
257
|
repoId: repo.getId(),
|
|
232
|
-
filePath:
|
|
258
|
+
filePath: relativePath,
|
|
233
259
|
languages: repo.languages,
|
|
234
260
|
project: repo.project,
|
|
235
261
|
})
|
|
236
|
-
|
|
262
|
+
repo.removeFilePath(relativePath)
|
|
263
|
+
log('Removing file: ' + relativePath)
|
|
237
264
|
repo.removeFile(file)
|
|
238
265
|
repo.emit('watch.delete', file)
|
|
239
266
|
repo.emitFileUpdate(file, true)
|
|
240
|
-
})
|
|
267
|
+
}))
|
|
241
268
|
});
|
|
242
269
|
}
|
|
243
270
|
|
package/lib/project.js
CHANGED
|
@@ -21,6 +21,7 @@ import { renderMarkdown, extractWikilinkTopics } from './adapters/markdown.js';
|
|
|
21
21
|
import { getFunctionSignature } from './adapters/parsers/function-parser.js';
|
|
22
22
|
import { format } from './adapters/parsers/content-transformer.js';
|
|
23
23
|
import { logger } from './adapters/logger.js';
|
|
24
|
+
import { resolveDefaultFilteredMovePosition } from './default-filtered-move-position.js';
|
|
24
25
|
|
|
25
26
|
function calculateTotals(lists = []) {
|
|
26
27
|
const totals = {}
|
|
@@ -459,6 +460,17 @@ export class WorkerProject extends Project {
|
|
|
459
460
|
return await this.repo.moveTask({task, newList, newPos})
|
|
460
461
|
}
|
|
461
462
|
|
|
463
|
+
async moveTaskInDefaultFilteredCards(task, newList, newPos) {
|
|
464
|
+
const repositoryPosition = resolveDefaultFilteredMovePosition({
|
|
465
|
+
task,
|
|
466
|
+
newList,
|
|
467
|
+
newPosition: newPos,
|
|
468
|
+
filteredCards: this.getDefaultFilteredCards(),
|
|
469
|
+
repositoryListCards: this.repo.getTasksInList(newList),
|
|
470
|
+
})
|
|
471
|
+
return await this.repo.moveTask({task, newList, newPos: repositoryPosition})
|
|
472
|
+
}
|
|
473
|
+
|
|
462
474
|
getFile(filePath) {
|
|
463
475
|
return this.repo.getFile(filePath)
|
|
464
476
|
}
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./checksum.js";
|
|
|
5
5
|
export * from "./clone.js";
|
|
6
6
|
export * from "./config.js";
|
|
7
7
|
export * from "./constants.js";
|
|
8
|
+
export * from "./default-filtered-move-position.js";
|
|
8
9
|
export * from "./default-settings.js";
|
|
9
10
|
export * from "./file.js";
|
|
10
11
|
export * from "./get-tasks-to-modify.js";
|
package/types/project.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ export class WorkerProject {
|
|
|
79
79
|
addTag(task: any, tag: any): Promise<any>;
|
|
80
80
|
removeTag(task: any, tag: any): Promise<any>;
|
|
81
81
|
moveTask(task: any, newList: any, newPos: any): Promise<any>;
|
|
82
|
+
moveTaskInDefaultFilteredCards(task: any, newList: any, newPos: any): Promise<any>;
|
|
82
83
|
getFile(filePath: any): any;
|
|
83
84
|
getFileForTask(task: any): any;
|
|
84
85
|
rollBackFileForTask(task: any): any;
|
package/.imdone-cli.yml
DELETED