@ofocus/sdk 0.1.0

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.
Files changed (200) hide show
  1. package/README.md +80 -0
  2. package/api-report/ofocus-sdk.api.md +564 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/applescript.d.ts +30 -0
  5. package/dist/applescript.d.ts.map +1 -0
  6. package/dist/applescript.js +142 -0
  7. package/dist/applescript.js.map +1 -0
  8. package/dist/commands/batch.d.ts +23 -0
  9. package/dist/commands/batch.d.ts.map +1 -0
  10. package/dist/commands/batch.js +324 -0
  11. package/dist/commands/batch.js.map +1 -0
  12. package/dist/commands/complete.d.ts +14 -0
  13. package/dist/commands/complete.d.ts.map +1 -0
  14. package/dist/commands/complete.js +37 -0
  15. package/dist/commands/complete.js.map +1 -0
  16. package/dist/commands/create-project.d.ts +6 -0
  17. package/dist/commands/create-project.d.ts.map +1 -0
  18. package/dist/commands/create-project.js +124 -0
  19. package/dist/commands/create-project.js.map +1 -0
  20. package/dist/commands/drop.d.ts +26 -0
  21. package/dist/commands/drop.d.ts.map +1 -0
  22. package/dist/commands/drop.js +62 -0
  23. package/dist/commands/drop.js.map +1 -0
  24. package/dist/commands/folders.d.ts +10 -0
  25. package/dist/commands/folders.d.ts.map +1 -0
  26. package/dist/commands/folders.js +150 -0
  27. package/dist/commands/folders.js.map +1 -0
  28. package/dist/commands/inbox.d.ts +6 -0
  29. package/dist/commands/inbox.d.ts.map +1 -0
  30. package/dist/commands/inbox.js +124 -0
  31. package/dist/commands/inbox.js.map +1 -0
  32. package/dist/commands/perspectives.d.ts +20 -0
  33. package/dist/commands/perspectives.d.ts.map +1 -0
  34. package/dist/commands/perspectives.js +166 -0
  35. package/dist/commands/perspectives.js.map +1 -0
  36. package/dist/commands/projects.d.ts +6 -0
  37. package/dist/commands/projects.d.ts.map +1 -0
  38. package/dist/commands/projects.js +113 -0
  39. package/dist/commands/projects.js.map +1 -0
  40. package/dist/commands/repetition.d.ts +17 -0
  41. package/dist/commands/repetition.d.ts.map +1 -0
  42. package/dist/commands/repetition.js +59 -0
  43. package/dist/commands/repetition.js.map +1 -0
  44. package/dist/commands/review.d.ts +10 -0
  45. package/dist/commands/review.d.ts.map +1 -0
  46. package/dist/commands/review.js +132 -0
  47. package/dist/commands/review.js.map +1 -0
  48. package/dist/commands/search.d.ts +6 -0
  49. package/dist/commands/search.d.ts.map +1 -0
  50. package/dist/commands/search.js +150 -0
  51. package/dist/commands/search.js.map +1 -0
  52. package/dist/commands/subtasks.d.ts +14 -0
  53. package/dist/commands/subtasks.d.ts.map +1 -0
  54. package/dist/commands/subtasks.js +370 -0
  55. package/dist/commands/subtasks.js.map +1 -0
  56. package/dist/commands/tags-crud.d.ts +22 -0
  57. package/dist/commands/tags-crud.d.ts.map +1 -0
  58. package/dist/commands/tags-crud.js +187 -0
  59. package/dist/commands/tags-crud.js.map +1 -0
  60. package/dist/commands/tags.d.ts +6 -0
  61. package/dist/commands/tags.d.ts.map +1 -0
  62. package/dist/commands/tags.js +61 -0
  63. package/dist/commands/tags.js.map +1 -0
  64. package/dist/commands/tasks.d.ts +6 -0
  65. package/dist/commands/tasks.d.ts.map +1 -0
  66. package/dist/commands/tasks.js +160 -0
  67. package/dist/commands/tasks.js.map +1 -0
  68. package/dist/commands/update.d.ts +6 -0
  69. package/dist/commands/update.d.ts.map +1 -0
  70. package/dist/commands/update.js +179 -0
  71. package/dist/commands/update.js.map +1 -0
  72. package/dist/errors.d.ts +38 -0
  73. package/dist/errors.d.ts.map +1 -0
  74. package/dist/errors.js +77 -0
  75. package/dist/errors.js.map +1 -0
  76. package/dist/escape.d.ts +6 -0
  77. package/dist/escape.d.ts.map +1 -0
  78. package/dist/escape.js +8 -0
  79. package/dist/escape.js.map +1 -0
  80. package/dist/index.d.ts +30 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +36 -0
  83. package/dist/index.js.map +1 -0
  84. package/dist/ofocus-sdk.d.ts +608 -0
  85. package/dist/result.d.ts +15 -0
  86. package/dist/result.d.ts.map +1 -0
  87. package/dist/result.js +29 -0
  88. package/dist/result.js.map +1 -0
  89. package/dist/types.d.ts +228 -0
  90. package/dist/types.d.ts.map +1 -0
  91. package/dist/types.js +2 -0
  92. package/dist/types.js.map +1 -0
  93. package/dist/validation.d.ts +57 -0
  94. package/dist/validation.d.ts.map +1 -0
  95. package/dist/validation.js +172 -0
  96. package/dist/validation.js.map +1 -0
  97. package/docs/index.md +30 -0
  98. package/docs/sdk.addtoinbox.md +68 -0
  99. package/docs/sdk.applescriptresult.data.md +11 -0
  100. package/docs/sdk.applescriptresult.error.md +11 -0
  101. package/docs/sdk.applescriptresult.md +92 -0
  102. package/docs/sdk.applescriptresult.success.md +11 -0
  103. package/docs/sdk.clierror.code.md +11 -0
  104. package/docs/sdk.clierror.details.md +11 -0
  105. package/docs/sdk.clierror.md +92 -0
  106. package/docs/sdk.clierror.message.md +11 -0
  107. package/docs/sdk.clioutput.data.md +11 -0
  108. package/docs/sdk.clioutput.error.md +11 -0
  109. package/docs/sdk.clioutput.md +90 -0
  110. package/docs/sdk.clioutput.success.md +11 -0
  111. package/docs/sdk.commandinfo.description.md +11 -0
  112. package/docs/sdk.commandinfo.md +90 -0
  113. package/docs/sdk.commandinfo.name.md +11 -0
  114. package/docs/sdk.commandinfo.usage.md +11 -0
  115. package/docs/sdk.completeresult.completed.md +11 -0
  116. package/docs/sdk.completeresult.md +90 -0
  117. package/docs/sdk.completeresult.taskid.md +11 -0
  118. package/docs/sdk.completeresult.taskname.md +11 -0
  119. package/docs/sdk.completetask.md +52 -0
  120. package/docs/sdk.createerror.md +82 -0
  121. package/docs/sdk.errorcode.md +24 -0
  122. package/docs/sdk.escapeapplescript.md +52 -0
  123. package/docs/sdk.failure.md +52 -0
  124. package/docs/sdk.failuremessage.md +52 -0
  125. package/docs/sdk.inboxoptions.defer.md +11 -0
  126. package/docs/sdk.inboxoptions.due.md +11 -0
  127. package/docs/sdk.inboxoptions.flag.md +11 -0
  128. package/docs/sdk.inboxoptions.md +134 -0
  129. package/docs/sdk.inboxoptions.note.md +11 -0
  130. package/docs/sdk.inboxoptions.tags.md +11 -0
  131. package/docs/sdk.jsonhelpers.md +13 -0
  132. package/docs/sdk.md +471 -0
  133. package/docs/sdk.ofperspective.id.md +11 -0
  134. package/docs/sdk.ofperspective.md +73 -0
  135. package/docs/sdk.ofperspective.name.md +11 -0
  136. package/docs/sdk.ofproject.folderid.md +11 -0
  137. package/docs/sdk.ofproject.foldername.md +11 -0
  138. package/docs/sdk.ofproject.id.md +11 -0
  139. package/docs/sdk.ofproject.md +192 -0
  140. package/docs/sdk.ofproject.name.md +11 -0
  141. package/docs/sdk.ofproject.note.md +11 -0
  142. package/docs/sdk.ofproject.remainingtaskcount.md +11 -0
  143. package/docs/sdk.ofproject.sequential.md +11 -0
  144. package/docs/sdk.ofproject.status.md +11 -0
  145. package/docs/sdk.ofproject.taskcount.md +11 -0
  146. package/docs/sdk.oftag.availabletaskcount.md +11 -0
  147. package/docs/sdk.oftag.id.md +11 -0
  148. package/docs/sdk.oftag.md +124 -0
  149. package/docs/sdk.oftag.name.md +11 -0
  150. package/docs/sdk.oftag.parentid.md +11 -0
  151. package/docs/sdk.oftag.parentname.md +11 -0
  152. package/docs/sdk.oftask.completed.md +11 -0
  153. package/docs/sdk.oftask.completiondate.md +11 -0
  154. package/docs/sdk.oftask.deferdate.md +11 -0
  155. package/docs/sdk.oftask.duedate.md +11 -0
  156. package/docs/sdk.oftask.flagged.md +11 -0
  157. package/docs/sdk.oftask.id.md +11 -0
  158. package/docs/sdk.oftask.md +226 -0
  159. package/docs/sdk.oftask.name.md +11 -0
  160. package/docs/sdk.oftask.note.md +11 -0
  161. package/docs/sdk.oftask.projectid.md +11 -0
  162. package/docs/sdk.oftask.projectname.md +11 -0
  163. package/docs/sdk.oftask.tags.md +11 -0
  164. package/docs/sdk.omnifocusscript.md +52 -0
  165. package/docs/sdk.omnifocusscriptwithhelpers.md +52 -0
  166. package/docs/sdk.parseapplescripterror.md +52 -0
  167. package/docs/sdk.projectqueryoptions.folder.md +11 -0
  168. package/docs/sdk.projectqueryoptions.md +96 -0
  169. package/docs/sdk.projectqueryoptions.sequential.md +11 -0
  170. package/docs/sdk.projectqueryoptions.status.md +11 -0
  171. package/docs/sdk.queryprojects.md +54 -0
  172. package/docs/sdk.querytags.md +54 -0
  173. package/docs/sdk.querytasks.md +54 -0
  174. package/docs/sdk.runapplescript.md +52 -0
  175. package/docs/sdk.runapplescriptfile.md +68 -0
  176. package/docs/sdk.success.md +52 -0
  177. package/docs/sdk.tagqueryoptions.md +58 -0
  178. package/docs/sdk.tagqueryoptions.parent.md +11 -0
  179. package/docs/sdk.taskqueryoptions.available.md +11 -0
  180. package/docs/sdk.taskqueryoptions.completed.md +11 -0
  181. package/docs/sdk.taskqueryoptions.dueafter.md +11 -0
  182. package/docs/sdk.taskqueryoptions.duebefore.md +11 -0
  183. package/docs/sdk.taskqueryoptions.flagged.md +11 -0
  184. package/docs/sdk.taskqueryoptions.md +172 -0
  185. package/docs/sdk.taskqueryoptions.project.md +11 -0
  186. package/docs/sdk.taskqueryoptions.tag.md +11 -0
  187. package/docs/sdk.taskupdateoptions.defer.md +11 -0
  188. package/docs/sdk.taskupdateoptions.due.md +11 -0
  189. package/docs/sdk.taskupdateoptions.flag.md +11 -0
  190. package/docs/sdk.taskupdateoptions.md +172 -0
  191. package/docs/sdk.taskupdateoptions.note.md +11 -0
  192. package/docs/sdk.taskupdateoptions.project.md +11 -0
  193. package/docs/sdk.taskupdateoptions.tags.md +11 -0
  194. package/docs/sdk.taskupdateoptions.title.md +11 -0
  195. package/docs/sdk.updatetask.md +66 -0
  196. package/docs/sdk.validatedatestring.md +54 -0
  197. package/docs/sdk.validateid.md +66 -0
  198. package/docs/sdk.validateprojectname.md +52 -0
  199. package/docs/sdk.validatetags.md +52 -0
  200. package/package.json +51 -0
@@ -0,0 +1,324 @@
1
+ import { success, failure } from "../result.js";
2
+ import { ErrorCode, createError } from "../errors.js";
3
+ import { validateId, validateDateString, validateTags, validateProjectName, validateEstimatedMinutes, validateRepetitionRule, } from "../validation.js";
4
+ import { escapeAppleScript } from "../escape.js";
5
+ import { runAppleScript, omniFocusScriptWithHelpers, } from "../applescript.js";
6
+ import { buildRepetitionRuleScript, buildClearRepetitionScript, } from "./repetition.js";
7
+ // Maximum tasks per batch to avoid AppleScript timeouts
8
+ const MAX_BATCH_SIZE = 50;
9
+ /**
10
+ * Complete multiple tasks in a single operation.
11
+ */
12
+ export async function completeTasks(taskIds) {
13
+ // Validate inputs
14
+ if (taskIds.length === 0) {
15
+ return failure(createError(ErrorCode.VALIDATION_ERROR, "No task IDs provided"));
16
+ }
17
+ for (const id of taskIds) {
18
+ const idError = validateId(id, "task");
19
+ if (idError)
20
+ return failure(idError);
21
+ }
22
+ // Process in chunks if needed
23
+ const chunks = [];
24
+ for (let i = 0; i < taskIds.length; i += MAX_BATCH_SIZE) {
25
+ chunks.push(taskIds.slice(i, i + MAX_BATCH_SIZE));
26
+ }
27
+ const allSucceeded = [];
28
+ const allFailed = [];
29
+ for (const chunk of chunks) {
30
+ const idsJson = JSON.stringify(chunk);
31
+ const script = `
32
+ set taskIdList to ${idsJson}
33
+ set succeededList to {}
34
+ set failedList to {}
35
+
36
+ repeat with taskIdStr in taskIdList
37
+ try
38
+ set theTask to first flattened task whose id is taskIdStr
39
+ set completed of theTask to true
40
+ set taskName to name of theTask
41
+ set end of succeededList to {taskIdStr, taskName}
42
+ on error errMsg
43
+ set end of failedList to {taskIdStr, errMsg}
44
+ end try
45
+ end repeat
46
+
47
+ set output to "{\\"succeeded\\": ["
48
+ set isFirst to true
49
+ repeat with item in succeededList
50
+ if not isFirst then set output to output & ","
51
+ set isFirst to false
52
+ set output to output & "{\\"taskId\\": \\"" & (item 1) & "\\", \\"taskName\\": \\"" & (my escapeJson(item 2 as string)) & "\\"}"
53
+ end repeat
54
+ set output to output & "], \\"failed\\": ["
55
+ set isFirst to true
56
+ repeat with item in failedList
57
+ if not isFirst then set output to output & ","
58
+ set isFirst to false
59
+ set output to output & "{\\"id\\": \\"" & (item 1) & "\\", \\"error\\": \\"" & (my escapeJson(item 2 as string)) & "\\"}"
60
+ end repeat
61
+ set output to output & "]}"
62
+
63
+ return output
64
+ `;
65
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
66
+ if (!result.success) {
67
+ return failure(result.error ??
68
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to complete tasks"));
69
+ }
70
+ if (result.data) {
71
+ allSucceeded.push(...result.data.succeeded);
72
+ allFailed.push(...result.data.failed);
73
+ }
74
+ }
75
+ return success({
76
+ succeeded: allSucceeded,
77
+ failed: allFailed,
78
+ totalSucceeded: allSucceeded.length,
79
+ totalFailed: allFailed.length,
80
+ });
81
+ }
82
+ /**
83
+ * Update multiple tasks with the same properties in a single operation.
84
+ */
85
+ export async function updateTasks(taskIds, options) {
86
+ // Validate inputs
87
+ if (taskIds.length === 0) {
88
+ return failure(createError(ErrorCode.VALIDATION_ERROR, "No task IDs provided"));
89
+ }
90
+ for (const id of taskIds) {
91
+ const idError = validateId(id, "task");
92
+ if (idError)
93
+ return failure(idError);
94
+ }
95
+ if (options.due !== undefined && options.due !== "") {
96
+ const dueError = validateDateString(options.due);
97
+ if (dueError)
98
+ return failure(dueError);
99
+ }
100
+ if (options.defer !== undefined && options.defer !== "") {
101
+ const deferError = validateDateString(options.defer);
102
+ if (deferError)
103
+ return failure(deferError);
104
+ }
105
+ const tagsError = validateTags(options.tags);
106
+ if (tagsError)
107
+ return failure(tagsError);
108
+ const projectError = validateProjectName(options.project);
109
+ if (projectError)
110
+ return failure(projectError);
111
+ const estimateError = validateEstimatedMinutes(options.estimatedMinutes);
112
+ if (estimateError)
113
+ return failure(estimateError);
114
+ const repeatError = validateRepetitionRule(options.repeat);
115
+ if (repeatError)
116
+ return failure(repeatError);
117
+ // Build the update statements
118
+ const updates = [];
119
+ if (options.title !== undefined) {
120
+ updates.push(`set name of theTask to "${escapeAppleScript(options.title)}"`);
121
+ }
122
+ if (options.note !== undefined) {
123
+ updates.push(`set note of theTask to "${escapeAppleScript(options.note)}"`);
124
+ }
125
+ if (options.flag !== undefined) {
126
+ updates.push("set flagged of theTask to " + String(options.flag));
127
+ }
128
+ if (options.due !== undefined) {
129
+ if (options.due === "") {
130
+ updates.push(`set due date of theTask to missing value`);
131
+ }
132
+ else {
133
+ updates.push(`set due date of theTask to date "${options.due}"`);
134
+ }
135
+ }
136
+ if (options.defer !== undefined) {
137
+ if (options.defer === "") {
138
+ updates.push(`set defer date of theTask to missing value`);
139
+ }
140
+ else {
141
+ updates.push(`set defer date of theTask to date "${options.defer}"`);
142
+ }
143
+ }
144
+ if (options.estimatedMinutes !== undefined) {
145
+ updates.push(`set estimated minutes of theTask to ${String(options.estimatedMinutes)}`);
146
+ }
147
+ if (options.clearEstimate === true) {
148
+ updates.push(`set estimated minutes of theTask to missing value`);
149
+ }
150
+ // Handle repetition
151
+ let repetitionScript = "";
152
+ if (options.clearRepeat === true) {
153
+ repetitionScript = buildClearRepetitionScript("theTask");
154
+ }
155
+ else if (options.repeat !== undefined) {
156
+ repetitionScript = buildRepetitionRuleScript("theTask", options.repeat);
157
+ }
158
+ // Handle project assignment
159
+ let projectScript = "";
160
+ if (options.project !== undefined) {
161
+ if (options.project === "") {
162
+ projectScript = `set containing project of theTask to missing value`;
163
+ }
164
+ else {
165
+ projectScript = `
166
+ set theProject to first flattened project whose name is "${escapeAppleScript(options.project)}"
167
+ move theTask to end of tasks of theProject
168
+ `;
169
+ }
170
+ }
171
+ // Handle tags - clear and re-add
172
+ let tagScript = "";
173
+ if (options.tags !== undefined) {
174
+ tagScript = `
175
+ repeat with existingTag in (tags of theTask)
176
+ remove existingTag from tags of theTask
177
+ end repeat
178
+ `;
179
+ for (const tagName of options.tags) {
180
+ tagScript += `
181
+ try
182
+ set theTag to first flattened tag whose name is "${escapeAppleScript(tagName)}"
183
+ add theTag to tags of theTask
184
+ end try
185
+ `;
186
+ }
187
+ }
188
+ const updateScript = updates.join("\n ");
189
+ // Process in chunks if needed
190
+ const chunks = [];
191
+ for (let i = 0; i < taskIds.length; i += MAX_BATCH_SIZE) {
192
+ chunks.push(taskIds.slice(i, i + MAX_BATCH_SIZE));
193
+ }
194
+ const allSucceeded = [];
195
+ const allFailed = [];
196
+ for (const chunk of chunks) {
197
+ const idsJson = JSON.stringify(chunk);
198
+ const script = `
199
+ set taskIdList to ${idsJson}
200
+ set succeededList to {}
201
+ set failedList to {}
202
+
203
+ repeat with taskIdStr in taskIdList
204
+ try
205
+ set theTask to first flattened task whose id is taskIdStr
206
+ ${updateScript}
207
+ ${projectScript}
208
+ ${tagScript}
209
+ ${repetitionScript}
210
+ set taskName to name of theTask
211
+ set end of succeededList to {taskIdStr, taskName}
212
+ on error errMsg
213
+ set end of failedList to {taskIdStr, errMsg}
214
+ end try
215
+ end repeat
216
+
217
+ set output to "{\\"succeeded\\": ["
218
+ set isFirst to true
219
+ repeat with item in succeededList
220
+ if not isFirst then set output to output & ","
221
+ set isFirst to false
222
+ set output to output & "{\\"taskId\\": \\"" & (item 1) & "\\", \\"taskName\\": \\"" & (my escapeJson(item 2 as string)) & "\\"}"
223
+ end repeat
224
+ set output to output & "], \\"failed\\": ["
225
+ set isFirst to true
226
+ repeat with item in failedList
227
+ if not isFirst then set output to output & ","
228
+ set isFirst to false
229
+ set output to output & "{\\"id\\": \\"" & (item 1) & "\\", \\"error\\": \\"" & (my escapeJson(item 2 as string)) & "\\"}"
230
+ end repeat
231
+ set output to output & "]}"
232
+
233
+ return output
234
+ `;
235
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
236
+ if (!result.success) {
237
+ return failure(result.error ??
238
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to update tasks"));
239
+ }
240
+ if (result.data) {
241
+ allSucceeded.push(...result.data.succeeded);
242
+ allFailed.push(...result.data.failed);
243
+ }
244
+ }
245
+ return success({
246
+ succeeded: allSucceeded,
247
+ failed: allFailed,
248
+ totalSucceeded: allSucceeded.length,
249
+ totalFailed: allFailed.length,
250
+ });
251
+ }
252
+ /**
253
+ * Delete multiple tasks permanently in a single operation.
254
+ */
255
+ export async function deleteTasks(taskIds) {
256
+ // Validate inputs
257
+ if (taskIds.length === 0) {
258
+ return failure(createError(ErrorCode.VALIDATION_ERROR, "No task IDs provided"));
259
+ }
260
+ for (const id of taskIds) {
261
+ const idError = validateId(id, "task");
262
+ if (idError)
263
+ return failure(idError);
264
+ }
265
+ // Process in chunks if needed
266
+ const chunks = [];
267
+ for (let i = 0; i < taskIds.length; i += MAX_BATCH_SIZE) {
268
+ chunks.push(taskIds.slice(i, i + MAX_BATCH_SIZE));
269
+ }
270
+ const allSucceeded = [];
271
+ const allFailed = [];
272
+ for (const chunk of chunks) {
273
+ const idsJson = JSON.stringify(chunk);
274
+ const script = `
275
+ set taskIdList to ${idsJson}
276
+ set succeededList to {}
277
+ set failedList to {}
278
+
279
+ repeat with taskIdStr in taskIdList
280
+ try
281
+ set theTask to first flattened task whose id is taskIdStr
282
+ delete theTask
283
+ set end of succeededList to taskIdStr
284
+ on error errMsg
285
+ set end of failedList to {taskIdStr, errMsg}
286
+ end try
287
+ end repeat
288
+
289
+ set output to "{\\"succeeded\\": ["
290
+ set isFirst to true
291
+ repeat with item in succeededList
292
+ if not isFirst then set output to output & ","
293
+ set isFirst to false
294
+ set output to output & "{\\"taskId\\": \\"" & item & "\\"}"
295
+ end repeat
296
+ set output to output & "], \\"failed\\": ["
297
+ set isFirst to true
298
+ repeat with item in failedList
299
+ if not isFirst then set output to output & ","
300
+ set isFirst to false
301
+ set output to output & "{\\"id\\": \\"" & (item 1) & "\\", \\"error\\": \\"" & (my escapeJson(item 2 as string)) & "\\"}"
302
+ end repeat
303
+ set output to output & "]}"
304
+
305
+ return output
306
+ `;
307
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
308
+ if (!result.success) {
309
+ return failure(result.error ??
310
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to delete tasks"));
311
+ }
312
+ if (result.data) {
313
+ allSucceeded.push(...result.data.succeeded);
314
+ allFailed.push(...result.data.failed);
315
+ }
316
+ }
317
+ return success({
318
+ succeeded: allSucceeded,
319
+ failed: allFailed,
320
+ totalSucceeded: allSucceeded.length,
321
+ totalFailed: allFailed.length,
322
+ });
323
+ }
324
+ //# sourceMappingURL=batch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.js","sourceRoot":"","sources":["../../src/commands/batch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACL,cAAc,EACd,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC;AAazB,wDAAwD;AACxD,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAiB;IAEjB,kBAAkB;IAClB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CACZ,WAAW,CAAC,SAAS,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,CAChE,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,UAAU,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACvC,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,8BAA8B;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AC,aAAa,EAAE,wBAAwB,CAAC,CACjE,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;YAChB,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC5C,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;QACb,SAAS,EAAE,YAAY;QACvB,MAAM,EAAE,SAAS;QACjB,cAAc,EAAE,YAAY,CAAC,MAAM;QACnC,WAAW,EAAE,SAAS,CAAC,MAAM;KAC9B,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { CliOutput } from "../types.js";
2
+ /**
3
+ * Result from completing a task.
4
+ */
5
+ export interface CompleteResult {
6
+ taskId: string;
7
+ taskName: string;
8
+ completed: boolean;
9
+ }
10
+ /**
11
+ * Mark a task as complete in OmniFocus.
12
+ */
13
+ export declare function completeTask(taskId: string): Promise<CliOutput<CompleteResult>>;
14
+ //# sourceMappingURL=complete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complete.d.ts","sourceRoot":"","sources":["../../src/commands/complete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAU7C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAmCpC"}
@@ -0,0 +1,37 @@
1
+ import { success, failure } from "../result.js";
2
+ import { ErrorCode, createError } from "../errors.js";
3
+ import { validateId } from "../validation.js";
4
+ import { escapeAppleScript } from "../escape.js";
5
+ import { runAppleScript, omniFocusScriptWithHelpers, } from "../applescript.js";
6
+ /**
7
+ * Mark a task as complete in OmniFocus.
8
+ */
9
+ export async function completeTask(taskId) {
10
+ // Validate task ID
11
+ const idError = validateId(taskId, "task");
12
+ if (idError)
13
+ return failure(idError);
14
+ const script = `
15
+ set theTask to first flattened task whose id is "${escapeAppleScript(taskId)}"
16
+ set completed of theTask to true
17
+
18
+ set taskName to name of theTask
19
+ set taskCompleted to completed of theTask
20
+
21
+ return "{" & ¬
22
+ "\\"taskId\\": \\"${escapeAppleScript(taskId)}\\"," & ¬
23
+ "\\"taskName\\": \\"" & (my escapeJson(taskName)) & "\\"," & ¬
24
+ "\\"completed\\": " & taskCompleted & ¬
25
+ "}"
26
+ `;
27
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
28
+ if (!result.success) {
29
+ return failure(result.error ??
30
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to complete task"));
31
+ }
32
+ if (result.data === undefined) {
33
+ return failure(createError(ErrorCode.UNKNOWN_ERROR, "No result returned"));
34
+ }
35
+ return success(result.data);
36
+ }
37
+ //# sourceMappingURL=complete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complete.js","sourceRoot":"","sources":["../../src/commands/complete.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACL,cAAc,EACd,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAW3B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAc;IAEd,mBAAmB;IACnB,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;IAErC,MAAM,MAAM,GAAG;uDACsC,iBAAiB,CAAC,MAAM,CAAC;;;;;;;0BAOtD,iBAAiB,CAAC,MAAM,CAAC;;;;GAIhD,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,cAAc,CACjC,0BAA0B,CAAC,MAAM,CAAC,CACnC,CAAC;IAEF,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,OAAO,CACZ,MAAM,CAAC,KAAK;YACV,WAAW,CAAC,SAAS,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAClE,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { CliOutput, CreateProjectOptions, OFProject } from "../types.js";
2
+ /**
3
+ * Create a new project in OmniFocus.
4
+ */
5
+ export declare function createProject(name: string, options?: CreateProjectOptions): Promise<CliOutput<OFProject>>;
6
+ //# sourceMappingURL=create-project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-project.d.ts","sourceRoot":"","sources":["../../src/commands/create-project.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAe9E;;GAEG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAqI/B"}
@@ -0,0 +1,124 @@
1
+ import { success, failure } from "../result.js";
2
+ import { ErrorCode, createError } from "../errors.js";
3
+ import { validateProjectName, validateFolderName, validateDateString, validateId, } from "../validation.js";
4
+ import { escapeAppleScript } from "../escape.js";
5
+ import { runAppleScript, omniFocusScriptWithHelpers, } from "../applescript.js";
6
+ /**
7
+ * Create a new project in OmniFocus.
8
+ */
9
+ export async function createProject(name, options = {}) {
10
+ // Validate project name (required for create)
11
+ if (!name || name.trim() === "") {
12
+ return failure(createError(ErrorCode.VALIDATION_ERROR, "Project name cannot be empty"));
13
+ }
14
+ const nameError = validateProjectName(name);
15
+ if (nameError)
16
+ return failure(nameError);
17
+ // Validate optional inputs
18
+ if (options.folderId !== undefined) {
19
+ const folderIdError = validateId(options.folderId, "project");
20
+ if (folderIdError)
21
+ return failure(folderIdError);
22
+ }
23
+ const folderNameError = validateFolderName(options.folderName);
24
+ if (folderNameError)
25
+ return failure(folderNameError);
26
+ if (options.dueDate !== undefined) {
27
+ const dueError = validateDateString(options.dueDate);
28
+ if (dueError)
29
+ return failure(dueError);
30
+ }
31
+ if (options.deferDate !== undefined) {
32
+ const deferError = validateDateString(options.deferDate);
33
+ if (deferError)
34
+ return failure(deferError);
35
+ }
36
+ // Build properties for the new project
37
+ const properties = [`name:"${escapeAppleScript(name)}"`];
38
+ if (options.note !== undefined) {
39
+ properties.push(`note:"${escapeAppleScript(options.note)}"`);
40
+ }
41
+ if (options.sequential !== undefined) {
42
+ properties.push(`sequential:${String(options.sequential)}`);
43
+ }
44
+ if (options.status === "on-hold") {
45
+ properties.push("status:on hold");
46
+ }
47
+ // "active" is the default status, no need to set it explicitly
48
+ if (options.dueDate !== undefined) {
49
+ properties.push(`due date:date "${options.dueDate}"`);
50
+ }
51
+ if (options.deferDate !== undefined) {
52
+ properties.push(`defer date:date "${options.deferDate}"`);
53
+ }
54
+ // Build script based on whether we're placing in a folder
55
+ let findFolder = "";
56
+ let makeProject = "";
57
+ if (options.folderId) {
58
+ findFolder = `set targetFolder to first flattened folder whose id is "${escapeAppleScript(options.folderId)}"`;
59
+ makeProject = `set newProject to make new project at end of projects of targetFolder with properties {${properties.join(", ")}}`;
60
+ }
61
+ else if (options.folderName) {
62
+ findFolder = `set targetFolder to first flattened folder whose name is "${escapeAppleScript(options.folderName)}"`;
63
+ makeProject = `set newProject to make new project at end of projects of targetFolder with properties {${properties.join(", ")}}`;
64
+ }
65
+ else {
66
+ findFolder = "";
67
+ makeProject = `set newProject to make new project with properties {${properties.join(", ")}}`;
68
+ }
69
+ const script = `
70
+ ${findFolder}
71
+ ${makeProject}
72
+
73
+ -- Return the created project info
74
+ set projId to id of newProject
75
+ set projName to name of newProject
76
+ set projNote to note of newProject
77
+ set projSeq to sequential of newProject
78
+
79
+ set projStatus to "active"
80
+ try
81
+ set theStatus to status of newProject
82
+ if theStatus is on hold then
83
+ set projStatus to "on-hold"
84
+ else if theStatus is done then
85
+ set projStatus to "completed"
86
+ else if theStatus is dropped then
87
+ set projStatus to "dropped"
88
+ end if
89
+ end try
90
+
91
+ set folderId to ""
92
+ set folderName to ""
93
+ try
94
+ set f to folder of newProject
95
+ set folderId to id of f
96
+ set folderName to name of f
97
+ end try
98
+
99
+ set taskCount to count of tasks of newProject
100
+ set remainingCount to count of (tasks of newProject where completed is false)
101
+
102
+ return "{" & ¬
103
+ "\\"id\\": \\"" & projId & "\\"," & ¬
104
+ "\\"name\\": \\"" & (my escapeJson(projName)) & "\\"," & ¬
105
+ "\\"note\\": " & (my jsonString(projNote)) & "," & ¬
106
+ "\\"status\\": \\"" & projStatus & "\\"," & ¬
107
+ "\\"sequential\\": " & projSeq & "," & ¬
108
+ "\\"folderId\\": " & (my jsonString(folderId)) & "," & ¬
109
+ "\\"folderName\\": " & (my jsonString(folderName)) & "," & ¬
110
+ "\\"taskCount\\": " & taskCount & "," & ¬
111
+ "\\"remainingTaskCount\\": " & remainingCount & ¬
112
+ "}"
113
+ `;
114
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
115
+ if (!result.success) {
116
+ return failure(result.error ??
117
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to create project"));
118
+ }
119
+ if (result.data === undefined) {
120
+ return failure(createError(ErrorCode.UNKNOWN_ERROR, "No project data returned"));
121
+ }
122
+ return success(result.data);
123
+ }
124
+ //# sourceMappingURL=create-project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-project.js","sourceRoot":"","sources":["../../src/commands/create-project.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACL,cAAc,EACd,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAY,EACZ,UAAgC,EAAE;IAElC,8CAA8C;IAC9C,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAChC,OAAO,OAAO,CACZ,WAAW,CAAC,SAAS,CAAC,gBAAgB,EAAE,8BAA8B,CAAC,CACxE,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,SAAS;QAAE,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;IAEzC,2BAA2B;IAC3B,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC9D,IAAI,aAAa;YAAE,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,eAAe,GAAG,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/D,IAAI,eAAe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AAC"}
@@ -0,0 +1,26 @@
1
+ import type { CliOutput } from "../types.js";
2
+ /**
3
+ * Result from dropping a task.
4
+ */
5
+ export interface DropResult {
6
+ taskId: string;
7
+ taskName: string;
8
+ dropped: boolean;
9
+ }
10
+ /**
11
+ * Result from deleting a task.
12
+ */
13
+ export interface DeleteResult {
14
+ taskId: string;
15
+ deleted: true;
16
+ }
17
+ /**
18
+ * Drop a task in OmniFocus (marks as dropped but keeps history).
19
+ */
20
+ export declare function dropTask(taskId: string): Promise<CliOutput<DropResult>>;
21
+ /**
22
+ * Delete a task permanently from OmniFocus.
23
+ * Note: This cannot be undone.
24
+ */
25
+ export declare function deleteTask(taskId: string): Promise<CliOutput<DeleteResult>>;
26
+ //# sourceMappingURL=drop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drop.d.ts","sourceRoot":"","sources":["../../src/commands/drop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAU7C;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,IAAI,CAAC;CACf;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAmChC;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CA4BlC"}
@@ -0,0 +1,62 @@
1
+ import { success, failure } from "../result.js";
2
+ import { ErrorCode, createError } from "../errors.js";
3
+ import { validateId } from "../validation.js";
4
+ import { escapeAppleScript } from "../escape.js";
5
+ import { runAppleScript, omniFocusScriptWithHelpers, } from "../applescript.js";
6
+ /**
7
+ * Drop a task in OmniFocus (marks as dropped but keeps history).
8
+ */
9
+ export async function dropTask(taskId) {
10
+ // Validate task ID
11
+ const idError = validateId(taskId, "task");
12
+ if (idError)
13
+ return failure(idError);
14
+ const script = `
15
+ set theTask to first flattened task whose id is "${escapeAppleScript(taskId)}"
16
+ set dropped of theTask to true
17
+
18
+ set taskName to name of theTask
19
+ set taskDropped to dropped of theTask
20
+
21
+ return "{" & ¬
22
+ "\\"taskId\\": \\"${escapeAppleScript(taskId)}\\"," & ¬
23
+ "\\"taskName\\": \\"" & (my escapeJson(taskName)) & "\\"," & ¬
24
+ "\\"dropped\\": " & taskDropped & ¬
25
+ "}"
26
+ `;
27
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
28
+ if (!result.success) {
29
+ return failure(result.error ??
30
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to drop task"));
31
+ }
32
+ if (result.data === undefined) {
33
+ return failure(createError(ErrorCode.UNKNOWN_ERROR, "No result returned"));
34
+ }
35
+ return success(result.data);
36
+ }
37
+ /**
38
+ * Delete a task permanently from OmniFocus.
39
+ * Note: This cannot be undone.
40
+ */
41
+ export async function deleteTask(taskId) {
42
+ // Validate task ID
43
+ const idError = validateId(taskId, "task");
44
+ if (idError)
45
+ return failure(idError);
46
+ const script = `
47
+ set theTask to first flattened task whose id is "${escapeAppleScript(taskId)}"
48
+ delete theTask
49
+
50
+ return "{\\"taskId\\": \\"${escapeAppleScript(taskId)}\\", \\"deleted\\": true}"
51
+ `;
52
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
53
+ if (!result.success) {
54
+ return failure(result.error ??
55
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to delete task"));
56
+ }
57
+ if (result.data === undefined) {
58
+ return failure(createError(ErrorCode.UNKNOWN_ERROR, "No result returned"));
59
+ }
60
+ return success(result.data);
61
+ }
62
+ //# sourceMappingURL=drop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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AG,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;IAErC,MAAM,MAAM,GAAG;uDACsC,iBAAiB,CAAC,MAAM,CAAC;;;gCAGhD,iBAAiB,CAAC,MAAM,CAAC;GACtD,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,cAAc,CACjC,0BAA0B,CAAC,MAAM,CAAC,CACnC,CAAC;IAEF,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,OAAO,CACZ,MAAM,CAAC,KAAK;YACV,WAAW,CAAC,SAAS,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAChE,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { CliOutput, CreateFolderOptions, FolderQueryOptions, OFFolder } from "../types.js";
2
+ /**
3
+ * Create a new folder in OmniFocus.
4
+ */
5
+ export declare function createFolder(name: string, options?: CreateFolderOptions): Promise<CliOutput<OFFolder>>;
6
+ /**
7
+ * Query folders from OmniFocus with optional filters.
8
+ */
9
+ export declare function queryFolders(options?: FolderQueryOptions): Promise<CliOutput<OFFolder[]>>;
10
+ //# sourceMappingURL=folders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"folders.d.ts","sourceRoot":"","sources":["../../src/commands/folders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,EACT,MAAM,aAAa,CAAC;AAUrB;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAoF9B;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,CAwEhC"}