@thornfe/jql2iql 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 thornfe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,248 @@
1
+ # @thornfe/jql2iql
2
+
3
+ ## Quick Start
4
+
5
+ ### Basic Usage
6
+
7
+ ```typescript
8
+ import { jql2iql, transformFieldsToConstantsMap } from '@thornfe/jql2iql';
9
+
10
+ // Prepare field mappings
11
+ const fields = [/* your raw field data */];
12
+ const fieldTypes = [/* your field type data */];
13
+ const constantsMap = transformFieldsToConstantsMap({
14
+ fields,
15
+ fieldTypes
16
+ });
17
+
18
+ // Convert JQL to IQL
19
+ const jql = 'project = SCRUM AND status = "In Progress"';
20
+ const iql = jql2iql(jql, constantsMap);
21
+ console.log(iql); // "所属空间" = "SCRUM" and "状态" = "In Progress"
22
+ ```
23
+
24
+ ### Advanced Usage
25
+
26
+ ```typescript
27
+ import {
28
+ parseJQL,
29
+ astToIQL,
30
+ transformFieldsToConstantsMap,
31
+ type ConstantsMap,
32
+ type RawField,
33
+ type FieldTypeInfo
34
+ } from '@thornfe/jql2iql';
35
+
36
+ // Step 1: Prepare your field mappings
37
+ const fields: RawField[] = [
38
+ {
39
+ key: 'workspace',
40
+ name: '所属空间',
41
+ objectId: 'field-001',
42
+ fieldType: { objectId: 'IJ9nXcXYKB' }
43
+ },
44
+ // ... more fields
45
+ ];
46
+
47
+ const fieldTypes: FieldTypeInfo[] = [
48
+ {
49
+ key: 'Workspace',
50
+ name: '空间',
51
+ objectId: 'IJ9nXcXYKB'
52
+ },
53
+ // ... more field types
54
+ ];
55
+
56
+ const constantsMap: ConstantsMap = transformFieldsToConstantsMap({
57
+ fields,
58
+ fieldTypes,
59
+ projectMap: { 'SCRUM': '敏捷项目' },
60
+ versionMap: { 'v1.0': ['version-id-1'] }
61
+ });
62
+
63
+ // Step 2: Parse JQL to AST
64
+ const jql = 'assignee = currentUser() AND priority in (High, Critical)';
65
+ const ast = parseJQL(jql);
66
+
67
+ // Step 3: Convert AST to IQL
68
+ const iql = astToIQL(ast, constantsMap);
69
+ console.log(iql);
70
+ ```
71
+
72
+ ## 📖 API Documentation
73
+
74
+ ### Main Functions
75
+
76
+ #### `jql2iql(jqlText: string, constantsMap: ConstantsMap): string`
77
+
78
+ Convert JQL query string to IQL query string.
79
+
80
+ **Parameters:**
81
+ - `jqlText`: JQL query string
82
+ - `constantsMap`: Field and value mappings
83
+
84
+ **Returns:** IQL query string
85
+
86
+ #### `parseJQL(jqlText: string): ASTNode | null`
87
+
88
+ Parse JQL query string into AST.
89
+
90
+ **Parameters:**
91
+ - `jqlText`: JQL query string
92
+
93
+ **Returns:** AST node or null if parsing fails
94
+
95
+ #### `astToIQL(ast: ASTNode, constantsMap: ConstantsMap): string`
96
+
97
+ Convert AST to IQL query string.
98
+
99
+ **Parameters:**
100
+ - `ast`: AST node from parseJQL
101
+ - `constantsMap`: Field and value mappings
102
+
103
+ **Returns:** IQL query string
104
+
105
+ #### `transformFieldsToConstantsMap(options: TransformOptions): ConstantsMap`
106
+
107
+ Transform raw field data into constants map for conversion.
108
+
109
+ **Parameters:**
110
+ - `options`: Transform options object
111
+ - `fields`: Array of raw field objects
112
+ - `fieldTypes`: Array of field type objects
113
+ - `projectMap`: (Optional) Project key to name mapping
114
+ - `versionMap`: (Optional) Version name to ID mapping
115
+
116
+ **Returns:** ConstantsMap object
117
+
118
+ **Example:**
119
+ ```typescript
120
+ const constantsMap = transformFieldsToConstantsMap({
121
+ fields: rawFields,
122
+ fieldTypes: fieldTypes,
123
+ projectMap: { 'PROJ': 'Project Name' },
124
+ versionMap: { 'v1.0': ['10000'] }
125
+ });
126
+ ```
127
+
128
+ ### Types
129
+
130
+ #### `ConstantsMap`
131
+
132
+ ```typescript
133
+ interface ConstantsMap {
134
+ projectMap?: Record<string, string>;
135
+ versionMap?: Record<string, string[]>;
136
+ component?: Record<string, string>;
137
+ cascade?: Record<string, string>;
138
+ fieldMap?: JiraFieldMap;
139
+ }
140
+ ```
141
+
142
+ #### `RawField`
143
+
144
+ ```typescript
145
+ interface RawField {
146
+ key: string;
147
+ name: string;
148
+ objectId: string;
149
+ fieldType: {
150
+ objectId: string;
151
+ };
152
+ data?: {
153
+ customData?: Array<{
154
+ label?: string;
155
+ value?: string;
156
+ title?: string;
157
+ }>;
158
+ };
159
+ }
160
+ ```
161
+
162
+ ## 🔧 Supported Features
163
+
164
+ ### Operators
165
+
166
+ - **Comparison**: `=`, `!=`, `>`, `>=`, `<`, `<=`
167
+ - **Contains**: `~` (contains), `!~` (not contains)
168
+ - **Set**: `in`, `not in`
169
+ - **Null**: `is`, `is not`
170
+ - **Logic**: `AND`, `OR`, `NOT`
171
+
172
+ ### Functions
173
+
174
+ - `currentUser()` - Current user
175
+ - `membersOf(group)` - Members of a user group
176
+ - `cascadeOption(value)` - Cascade option value
177
+
178
+ ### Field Types
179
+
180
+ - User fields (assignee, reporter, creator, etc.)
181
+ - Date fields (created, updated, custom dates)
182
+ - Text fields (summary, description, etc.)
183
+ - Number fields (story points, custom numbers)
184
+ - Select fields (status, priority, custom selects)
185
+ - Multi-select fields (labels, components, versions)
186
+ - Cascade fields
187
+ - User group fields
188
+
189
+ ### Special Features
190
+
191
+ - `ORDER BY` clause support
192
+ - Custom field mapping
193
+ - Enum value mapping
194
+ - Version and component mapping
195
+ - Empty/null value handling
196
+
197
+ ## 🧪 Development
198
+
199
+ ```bash
200
+ # Install dependencies
201
+ pnpm install
202
+
203
+ # Run tests
204
+ pnpm test
205
+
206
+ # Watch mode
207
+ pnpm test:watch
208
+
209
+ # Build
210
+ pnpm build
211
+
212
+ # Run benchmark
213
+ pnpm benchmark
214
+ ```
215
+
216
+ ## 📝 Examples
217
+
218
+ ### Basic Queries
219
+
220
+ ```typescript
221
+ // Simple equality
222
+ jql2iql('status = "In Progress"', constantsMap)
223
+ // → "状态" = "In Progress"
224
+
225
+ // Multiple conditions
226
+ jql2iql('project = SCRUM AND assignee = currentUser()', constantsMap)
227
+ // → "所属空间" = "SCRUM" and "负责人" = "currentUser()"
228
+
229
+ // IN operator
230
+ jql2iql('priority in (High, Critical)', constantsMap)
231
+ // → "优先级" in ["High", "Critical"]
232
+ ```
233
+
234
+ ### Complex Queries
235
+
236
+ ```typescript
237
+ // Logical operators
238
+ jql2iql('(status = Open OR status = "In Progress") AND assignee = currentUser()', constantsMap)
239
+
240
+ // Date queries
241
+ jql2iql('created >= -7d AND updated <= -1d', constantsMap)
242
+
243
+ // User group
244
+ jql2iql('assignee in membersOf("developers")', constantsMap)
245
+
246
+ // ORDER BY
247
+ jql2iql('status = Open ORDER BY priority DESC, created ASC', constantsMap)
248
+ ```