55 */
66
77import type { CommandItem } from "../models/TaskItem" ;
8- import { getDb } from "../db/lifecycle" ;
8+ import { getDbOrThrow } from "../db/lifecycle" ;
99import {
1010 addTagToCommand ,
1111 removeTagFromCommand ,
@@ -22,16 +22,12 @@ export class TagConfig {
2222 * Loads all tag assignments from SQLite junction table.
2323 */
2424 public load ( ) : void {
25- const dbResult = getDb ( ) ;
26- if ( ! dbResult . ok ) {
27- this . commandTagsMap = new Map ( ) ;
28- return ;
29- }
25+ const handle = getDbOrThrow ( ) ;
3026
31- const tagNames = getAllTagNames ( dbResult . value ) ;
27+ const tagNames = getAllTagNames ( handle ) ;
3228 const map = new Map < string , string [ ] > ( ) ;
3329 for ( const tagName of tagNames ) {
34- const commandIds = getCommandIdsByTag ( { handle : dbResult . value , tagName } ) ;
30+ const commandIds = getCommandIdsByTag ( { handle, tagName } ) ;
3531 for ( const commandId of commandIds ) {
3632 const tags = map . get ( commandId ) ?? [ ] ;
3733 tags . push ( tagName ) ;
@@ -57,23 +53,17 @@ export class TagConfig {
5753 * Gets all tag names.
5854 */
5955 public getTagNames ( ) : string [ ] {
60- const dbResult = getDb ( ) ;
61- if ( ! dbResult . ok ) {
62- return [ ] ;
63- }
64- return getAllTagNames ( dbResult . value ) ;
56+ const handle = getDbOrThrow ( ) ;
57+ return getAllTagNames ( handle ) ;
6558 }
6659
6760 /**
6861 * SPEC: tagging/management
6962 * Adds a task to a tag by creating junction record with exact command ID.
7063 */
7164 public addTaskToTag ( task : CommandItem , tagName : string ) : void {
72- const dbResult = getDb ( ) ;
73- if ( ! dbResult . ok ) {
74- return ;
75- }
76- addTagToCommand ( { handle : dbResult . value , commandId : task . id , tagName } ) ;
65+ const handle = getDbOrThrow ( ) ;
66+ addTagToCommand ( { handle, commandId : task . id , tagName } ) ;
7767 this . load ( ) ;
7868 }
7969
@@ -82,11 +72,8 @@ export class TagConfig {
8272 * Removes a task from a tag by deleting junction record.
8373 */
8474 public removeTaskFromTag ( task : CommandItem , tagName : string ) : void {
85- const dbResult = getDb ( ) ;
86- if ( ! dbResult . ok ) {
87- return ;
88- }
89- removeTagFromCommand ( { handle : dbResult . value , commandId : task . id , tagName } ) ;
75+ const handle = getDbOrThrow ( ) ;
76+ removeTagFromCommand ( { handle, commandId : task . id , tagName } ) ;
9077 this . load ( ) ;
9178 }
9279
@@ -95,23 +82,17 @@ export class TagConfig {
9582 * Gets ordered command IDs for a tag (ordered by display_order).
9683 */
9784 public getOrderedCommandIds ( tagName : string ) : string [ ] {
98- const dbResult = getDb ( ) ;
99- if ( ! dbResult . ok ) {
100- return [ ] ;
101- }
102- return getCommandIdsByTag ( { handle : dbResult . value , tagName } ) ;
85+ const handle = getDbOrThrow ( ) ;
86+ return getCommandIdsByTag ( { handle, tagName } ) ;
10387 }
10488
10589 /**
10690 * SPEC: quick-launch
10791 * Reorders commands for a tag by updating display_order in junction table.
10892 */
10993 public reorderCommands ( tagName : string , orderedCommandIds : string [ ] ) : void {
110- const dbResult = getDb ( ) ;
111- if ( ! dbResult . ok ) {
112- return ;
113- }
114- reorderTagCommands ( { handle : dbResult . value , tagName, orderedCommandIds } ) ;
94+ const handle = getDbOrThrow ( ) ;
95+ reorderTagCommands ( { handle, tagName, orderedCommandIds } ) ;
11596 this . load ( ) ;
11697 }
11798}
0 commit comments