1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! Changeset command implementations for Node.js bindings.
//!
//! # What
//!
//! This module implements the changeset NAPI functions that manage the changeset
//! workflow. Changesets track intended changes before they are applied as version
//! bumps, enabling better release management and changelog generation.
//!
//! # How
//!
//! The module provides the following functions:
//!
//! - `changesetAdd`: Creates a new changeset for the current branch
//! - `changesetUpdate`: Updates an existing changeset with new packages or commits
//! - `changesetList`: Lists all pending changesets in the workspace
//! - `changesetShow`: Shows details of a specific changeset
//! - `changesetRemove`: Removes a changeset
//! - `changesetHistory`: Queries archived changeset history
//! - `changesetCheck`: Checks if the current branch has a changeset
//!
//! Each function:
//! 1. Validates the input parameters
//! 2. Calls the appropriate `execute_*` function from `sublime_cli_tools`
//! 3. Captures the JSON output
//! 4. Returns a `JsonResponse<T>` with the result
//!
//! # Why
//!
//! Changesets are the core of the version management workflow. They allow
//! developers to document their changes as they work, and then batch those
//! changes into coordinated version bumps and releases.
//!
//! # Examples
//!
//! ```typescript
//! import {
//! changesetAdd,
//! changesetUpdate,
//! changesetList,
//! changesetShow,
//! changesetRemove,
//! changesetHistory,
//! changesetCheck
//! } from '@websublime/workspace-tools';
//!
//! // Add a new changeset
//! const addResult = await changesetAdd({
//! root: '.',
//! packages: ['@scope/core', '@scope/utils'],
//! bumpType: 'minor',
//! message: 'Add new feature'
//! });
//!
//! // Update an existing changeset
//! const updateResult = await changesetUpdate({
//! root: '.',
//! branch: 'feature/xyz',
//! addCommits: true
//! });
//!
//! // List all pending changesets
//! const listResult = await changesetList({ root: '.' });
//! if (listResult.success) {
//! for (const cs of listResult.data.changesets) {
//! console.log(`${cs.branch}: ${cs.packages.join(', ')} (${cs.bump})`);
//! }
//! }
//!
//! // Show a specific changeset
//! const showResult = await changesetShow({
//! root: '.',
//! branch: 'feature/xyz'
//! });
//!
//! // Check if current branch has a changeset
//! const checkResult = await changesetCheck({ root: '.' });
//! if (checkResult.success && !checkResult.data.hasChangeset) {
//! console.log('No changeset found for current branch');
//! }
//!
//! // Query changeset history
//! const historyResult = await changesetHistory({
//! root: '.',
//! package: '@scope/core',
//! limit: 10
//! });
//! ```
// TODO: will be implemented on story 4.2-4.8 - Changeset Commands
//
// Implementation outline for changesetAdd:
//
// #[napi]
// pub async fn changeset_add(params: ChangesetAddParams) -> JsonResponse<ChangesetAddData> {
// // 1. Validate parameters
// if let Err(e) = validate_root(¶ms.root) {
// return JsonResponse::from_error_info(e);
// }
// if let Err(e) = validate_packages_not_empty(¶ms.packages) {
// return JsonResponse::from_error_info(e);
// }
// if let Err(e) = validate_bump_type(¶ms.bump_type) {
// return JsonResponse::from_error_info(e);
// }
// if let Err(e) = validate_message_not_empty(¶ms.message, "message") {
// return JsonResponse::from_error_info(e);
// }
//
// // 2. Create ChangesetCreateArgs from params
// // 3. Create Output with JSON format for capturing
// // 4. Call execute_add from CLI (commands/changeset/add.rs)
// // 5. Parse JSON response
// // 6. Return JsonResponse::success(data) or JsonResponse::error(msg)
// }
//
// Implementation outline for changesetUpdate:
//
// #[napi]
// pub async fn changeset_update(params: ChangesetUpdateParams) -> JsonResponse<ChangesetUpdateData> {
// // Similar pattern: validate, create args, execute, parse, return
// }
//
// Implementation outline for changesetList:
//
// #[napi]
// pub async fn changeset_list(params: ChangesetListParams) -> JsonResponse<ChangesetListData> {
// // Similar pattern: validate root, execute_list, parse, return
// }
//
// Implementation outline for changesetShow:
//
// #[napi]
// pub async fn changeset_show(params: ChangesetShowParams) -> JsonResponse<ChangesetShowData> {
// // Similar pattern: validate root and branch, execute_show, parse, return
// }
//
// Implementation outline for changesetRemove:
//
// #[napi]
// pub async fn changeset_remove(params: ChangesetRemoveParams) -> JsonResponse<ChangesetRemoveData> {
// // Similar pattern: validate root and branch, execute_remove, parse, return
// }
//
// Implementation outline for changesetHistory:
//
// #[napi]
// pub async fn changeset_history(params: ChangesetHistoryParams) -> JsonResponse<ChangesetHistoryData> {
// // Similar pattern: validate root, execute_history with filters, parse, return
// }
//
// Implementation outline for changesetCheck:
//
// #[napi]
// pub async fn changeset_check(params: ChangesetCheckParams) -> JsonResponse<ChangesetCheckData> {
// // Similar pattern: validate root, execute_check, parse, return
// }