Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changes/feat-folders-list-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Added

- **`folders list` of a documents CLI names each chosen folder.** A row has `name`, the folder's name when `folders add`
kept it, and `path` when the CLI gives `folderPath` to `documentLibraryCommands`. A folder shown only by its id
(ydisk's `resource_id`) now has words. A CLI that lists its own folders still answers `{ id }`.
2 changes: 1 addition & 1 deletion src/cli/documents/folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface DocumentFolderCommands {
/** Checks the folder with the provider and keeps it in the selected profile; refuses one that is not a folder. */
add(input: string): Promise<{ id: string; name: string }>
/** The selected profile's chosen folders, narrowed by `id:`. */
list(filter: Record<string, string>): { id: string }[]
list(filter: Record<string, string>): { id: string; name?: string; path?: string }[]
/** Forgets the folder; answers its id. */
remove(input: string): string
/** Adds the CLI's own `folders browse`, which help then lists between `list` and `remove`. */
Expand Down
5 changes: 4 additions & 1 deletion src/cli/documents/library.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const definition = (source: FeedlessDocumentSource, words: DocumentWords = WORDS
? (source as unknown as { byPath(path: string): Promise<SourceFile> }).byPath(input)
: source.metadata(input),
isFolder,
folderPath: (file) => `/${file.name}`,
row: (file, reference) => ({ id: file.id, name: file.name, url: file.url, reference }),
textLimit: 100_000,
maxEntries: 1_000,
Expand Down Expand Up @@ -104,7 +105,9 @@ describe("documentLibraryCommands over a source without a change feed", () => {
expect(JSON.parse((await cli(["folders", "add", "root"])).stdout)).toMatchObject({
item: { id: "root", added: true },
})
expect(JSON.parse((await cli(["folders", "list"])).stdout).items).toEqual([{ id: "root" }])
expect(JSON.parse((await cli(["folders", "list"])).stdout).items).toEqual([
{ id: "root", name: "root", path: "/root" },
])
expect(JSON.parse((await cli(["sync"])).stdout).item).toMatchObject({ saved: 2, removed: 0 })
source.put({ ...source.files.get("a"), version: "2" } as SourceFile, "a new budget line")
source.remove("b")
Expand Down
8 changes: 7 additions & 1 deletion src/cli/documents/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export interface DocumentLibraryOptions<M extends SourceFile> {
coverage: string
/** The accounts a document names, for `identities list`; none when the provider shows none. */
people?: DocumentKnowledgePort["people"]
/** Where a chosen folder is at the provider, for `folders list`: a Disk path. Unset: the answer has no path. */
folderPath?(folder: M): string | undefined
/** The CLI's own `folders browse`. */
browse?(folders: Command, tools: DocumentLibraryTools<M>): void
}
Expand Down Expand Up @@ -425,7 +427,11 @@ export const documentLibraryCommands = <M extends SourceFile>(options: DocumentL
list: (filter) =>
roots()
.filter((id) => filter.id === undefined || filter.id === id)
.map((id) => ({ id })),
.map((id) => {
const file = files().folders().files?.[id]
const path = file ? options.folderPath?.(file) : undefined
return { id, ...(file ? { name: file.name } : {}), ...(path ? { path } : {}) }
}),
remove: (input) => {
const id = options.idOf(input)
const chosen = files().folders()
Expand Down
8 changes: 7 additions & 1 deletion src/cli/documents/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ const registry = (
),
})

export const folderRow = v.strictObject({ id: v.string() })
export const folderRow = v.strictObject({
id: v.string(),
/** The folder as `folders add` named it; left out for a folder chosen before its name was kept. */
name: v.optional(v.string()),
/** Where the provider says it is, when the CLI gives a `folderPath`: a Disk path. */
path: v.optional(v.string()),
})
export const mirrorRow = v.strictObject({ id: v.string(), path: v.string(), folder: v.string() })
export const tagRow = v.strictObject({ tag: v.string() })
export const linkRow = v.looseObject({
Expand Down
Loading