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
157
158
159
160
161
162
163
164
165
166
167
168
//! # `sublime_node_tools`
//!
//! Node.js bindings for Sublime Workspace CLI Tools via napi-rs.
//!
//! ## What
//!
//! This crate provides Node.js bindings via napi-rs for the workspace-tools CLI,
//! exposing 23 execute functions as native JavaScript/TypeScript functions. It enables
//! Node.js and TypeScript applications to use workspace-tools functionality
//! programmatically without spawning CLI processes.
//!
//! ## How
//!
//! The crate uses `#[napi]` macros to:
//! - Define async functions callable from Node.js
//! - Convert Rust types to JavaScript objects via `#[napi(object)]`
//! - Generate TypeScript definitions automatically
//!
//! ### Architecture Overview
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────────┐
//! │ JavaScript/TypeScript │
//! │ │
//! │ const result = await status({ root: "/path/to/project" }); │
//! │ │
//! │ if (result.success) { │
//! │ console.log(result.data.packages); // ← Native JS objects │
//! │ } else { │
//! │ console.error(result.error.code); // ← "EVALIDATION" │
//! │ } │
//! └────────────────────────────────┬────────────────────────────────────┘
//! │
//! ▼
//! ┌─────────────────────────────────────────────────────────────────────┐
//! │ NAPI Layer (crates/node/) │
//! │ │
//! │ 1. Parameter validation (validation.rs) │
//! │ 2. Conversion JS → Rust structs │
//! │ 3. Call execute_* functions from CLI │
//! │ 4. Capture JSON output │
//! │ 5. Parse and convert to NAPI structs │
//! │ 6. Return ApiResponse<T> │
//! └────────────────────────────────┬────────────────────────────────────┘
//! │
//! ▼
//! ┌─────────────────────────────────────────────────────────────────────┐
//! │ CLI Layer (crates/cli/) │
//! │ │
//! │ execute_status(), execute_init(), execute_changeset_add(), ... │
//! └─────────────────────────────────────────────────────────────────────┘
//! ```
//!
//! ### Module Structure
//!
//! - **`error`**: Error handling with Node.js-style error codes (EVALIDATION, EGIT, etc.)
//! - **`validation`**: Parameter validation before CLI execution
//! - **`response`**: `ApiResponse<T>` wrapper for consistent success/error responses
//! - **`types`**: NAPI-compatible structs for parameters and responses
//! - **`commands`**: Implementation of all 23 NAPI functions
//!
//! ## Why
//!
//! Enables Node.js/TypeScript applications to use workspace-tools functionality
//! programmatically without spawning CLI processes, with:
//!
//! - **Full type safety**: TypeScript definitions are auto-generated
//! - **Native performance**: Direct function calls instead of process spawning
//! - **Structured responses**: `ApiResponse<T>` with success/error handling
//! - **Node.js-style errors**: Familiar error codes like ENOENT, EVALIDATION
//!
//! ## Examples
//!
//! ### Basic Usage
//!
//! ```typescript
//! import { status, changesetAdd, bumpPreview } from '@websublime/workspace-tools';
//!
//! // Get workspace status
//! const result = await status({ root: '.' });
//! if (result.success) {
//! console.log(result.data.packages);
//! } else {
//! console.error(`Error [${result.error.code}]: ${result.error.message}`);
//! }
//! ```
//!
//! ### Error Handling
//!
//! ```typescript
//! import { changesetAdd } from '@websublime/workspace-tools';
//!
//! const result = await changesetAdd({
//! root: '.',
//! packages: ['@scope/pkg1'],
//! bumpType: 'minor',
//! message: 'Add new feature'
//! });
//!
//! if (!result.success) {
//! switch (result.error.code) {
//! case 'EVALIDATION':
//! console.error('Invalid parameters:', result.error.message);
//! break;
//! case 'EGIT':
//! console.error('Git error:', result.error.message);
//! break;
//! default:
//! console.error('Unexpected error:', result.error.message);
//! }
//! }
//! ```
extern crate napi_derive;
pub
pub
pub
pub
pub
// Re-export NAPI functions from commands module
// TODO: will be implemented on story 3.2 (status command)
// TODO: will be implemented on story 3.4 (init command)
// TODO: will be implemented on story 4.2-4.8 (changeset commands)
// TODO: will be implemented on story 5.2-5.4 (bump commands)
// TODO: will be implemented on story 6.3 (execute command)
// TODO: will be implemented on story 7.2-7.3 (config commands)
// TODO: will be implemented on story 8.2-8.4 (upgrade commands)
// TODO: will be implemented on story 9.1-9.3 (remaining commands)
/// Version of the crate.
pub const VERSION: &str = env!;
/// Returns the version of the crate.
///
/// This function is exposed to Node.js and returns the current version
/// of the `sublime_node_tools` crate.
///
/// # Returns
///
/// A string containing the semantic version of the crate.
///
/// # Examples
///
/// ```typescript
/// import { getVersion } from '@websublime/workspace-tools';
///
/// console.log(`Using workspace-tools version: ${getVersion()}`);
/// ```