@baack-software/baack-ts-tasks 0.0.0-stage → 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.
Files changed (229) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +158 -2
  3. package/dist/activity.d.ts +20 -0
  4. package/dist/activity.d.ts.map +1 -0
  5. package/dist/activity.js +75 -0
  6. package/dist/activity.js.map +1 -0
  7. package/dist/blockers.d.ts +28 -0
  8. package/dist/blockers.d.ts.map +1 -0
  9. package/dist/blockers.js +134 -0
  10. package/dist/blockers.js.map +1 -0
  11. package/dist/conflicts.d.ts +50 -0
  12. package/dist/conflicts.d.ts.map +1 -0
  13. package/dist/conflicts.js +73 -0
  14. package/dist/conflicts.js.map +1 -0
  15. package/dist/draft.d.ts +45 -0
  16. package/dist/draft.d.ts.map +1 -0
  17. package/dist/draft.js +155 -0
  18. package/dist/draft.js.map +1 -0
  19. package/dist/errors.d.ts +30 -0
  20. package/dist/errors.d.ts.map +1 -0
  21. package/dist/errors.js +37 -0
  22. package/dist/errors.js.map +1 -0
  23. package/dist/index.d.ts +11 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +11 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/react/TaskActivity.d.ts +15 -0
  28. package/dist/react/TaskActivity.d.ts.map +1 -0
  29. package/dist/react/TaskActivity.js +60 -0
  30. package/dist/react/TaskActivity.js.map +1 -0
  31. package/dist/react/TaskBoard.d.ts +38 -0
  32. package/dist/react/TaskBoard.d.ts.map +1 -0
  33. package/dist/react/TaskBoard.js +85 -0
  34. package/dist/react/TaskBoard.js.map +1 -0
  35. package/dist/react/TaskConflicts.d.ts +26 -0
  36. package/dist/react/TaskConflicts.d.ts.map +1 -0
  37. package/dist/react/TaskConflicts.js +87 -0
  38. package/dist/react/TaskConflicts.js.map +1 -0
  39. package/dist/react/TaskCreateForm.d.ts +13 -0
  40. package/dist/react/TaskCreateForm.d.ts.map +1 -0
  41. package/dist/react/TaskCreateForm.js +68 -0
  42. package/dist/react/TaskCreateForm.js.map +1 -0
  43. package/dist/react/TaskEditor.d.ts +33 -0
  44. package/dist/react/TaskEditor.d.ts.map +1 -0
  45. package/dist/react/TaskEditor.js +172 -0
  46. package/dist/react/TaskEditor.js.map +1 -0
  47. package/dist/react/TaskFilters.d.ts +15 -0
  48. package/dist/react/TaskFilters.d.ts.map +1 -0
  49. package/dist/react/TaskFilters.js +48 -0
  50. package/dist/react/TaskFilters.js.map +1 -0
  51. package/dist/react/TaskView.d.ts +30 -0
  52. package/dist/react/TaskView.d.ts.map +1 -0
  53. package/dist/react/TaskView.js +108 -0
  54. package/dist/react/TaskView.js.map +1 -0
  55. package/dist/react/TasksAbout.d.ts +24 -0
  56. package/dist/react/TasksAbout.d.ts.map +1 -0
  57. package/dist/react/TasksAbout.js +82 -0
  58. package/dist/react/TasksAbout.js.map +1 -0
  59. package/dist/react/copy.d.ts +154 -0
  60. package/dist/react/copy.d.ts.map +1 -0
  61. package/dist/react/copy.js +173 -0
  62. package/dist/react/copy.js.map +1 -0
  63. package/dist/react/fields.d.ts +36 -0
  64. package/dist/react/fields.d.ts.map +1 -0
  65. package/dist/react/fields.js +21 -0
  66. package/dist/react/fields.js.map +1 -0
  67. package/dist/react/hooks.d.ts +9 -0
  68. package/dist/react/hooks.d.ts.map +1 -0
  69. package/dist/react/hooks.js +31 -0
  70. package/dist/react/hooks.js.map +1 -0
  71. package/dist/react/index.d.ts +13 -0
  72. package/dist/react/index.d.ts.map +1 -0
  73. package/dist/react/index.js +13 -0
  74. package/dist/react/index.js.map +1 -0
  75. package/dist/react/parts.d.ts +55 -0
  76. package/dist/react/parts.d.ts.map +1 -0
  77. package/dist/react/parts.js +92 -0
  78. package/dist/react/parts.js.map +1 -0
  79. package/dist/react/ui/alert.d.ts +11 -0
  80. package/dist/react/ui/alert.d.ts.map +1 -0
  81. package/dist/react/ui/alert.js +29 -0
  82. package/dist/react/ui/alert.js.map +1 -0
  83. package/dist/react/ui/avatar.d.ts +12 -0
  84. package/dist/react/ui/avatar.d.ts.map +1 -0
  85. package/dist/react/ui/avatar.js +24 -0
  86. package/dist/react/ui/avatar.js.map +1 -0
  87. package/dist/react/ui/badge.d.ts +10 -0
  88. package/dist/react/ui/badge.d.ts.map +1 -0
  89. package/dist/react/ui/badge.js +26 -0
  90. package/dist/react/ui/badge.js.map +1 -0
  91. package/dist/react/ui/button.d.ts +11 -0
  92. package/dist/react/ui/button.d.ts.map +1 -0
  93. package/dist/react/ui/button.js +37 -0
  94. package/dist/react/ui/button.js.map +1 -0
  95. package/dist/react/ui/card.d.ts +12 -0
  96. package/dist/react/ui/card.d.ts.map +1 -0
  97. package/dist/react/ui/card.js +26 -0
  98. package/dist/react/ui/card.js.map +1 -0
  99. package/dist/react/ui/input.d.ts +4 -0
  100. package/dist/react/ui/input.d.ts.map +1 -0
  101. package/dist/react/ui/input.js +8 -0
  102. package/dist/react/ui/input.js.map +1 -0
  103. package/dist/react/ui/label.d.ts +5 -0
  104. package/dist/react/ui/label.d.ts.map +1 -0
  105. package/dist/react/ui/label.js +10 -0
  106. package/dist/react/ui/label.js.map +1 -0
  107. package/dist/react/ui/radio-group.d.ts +6 -0
  108. package/dist/react/ui/radio-group.d.ts.map +1 -0
  109. package/dist/react/ui/radio-group.js +12 -0
  110. package/dist/react/ui/radio-group.js.map +1 -0
  111. package/dist/react/ui/select.d.ts +16 -0
  112. package/dist/react/ui/select.d.ts.map +1 -0
  113. package/dist/react/ui/select.js +37 -0
  114. package/dist/react/ui/select.js.map +1 -0
  115. package/dist/react/ui/separator.d.ts +5 -0
  116. package/dist/react/ui/separator.d.ts.map +1 -0
  117. package/dist/react/ui/separator.js +10 -0
  118. package/dist/react/ui/separator.js.map +1 -0
  119. package/dist/react/ui/sheet.d.ts +15 -0
  120. package/dist/react/ui/sheet.d.ts.map +1 -0
  121. package/dist/react/ui/sheet.js +38 -0
  122. package/dist/react/ui/sheet.js.map +1 -0
  123. package/dist/react/ui/skeleton.d.ts +3 -0
  124. package/dist/react/ui/skeleton.d.ts.map +1 -0
  125. package/dist/react/ui/skeleton.js +7 -0
  126. package/dist/react/ui/skeleton.js.map +1 -0
  127. package/dist/react/ui/table.d.ts +11 -0
  128. package/dist/react/ui/table.d.ts.map +1 -0
  129. package/dist/react/ui/table.js +29 -0
  130. package/dist/react/ui/table.js.map +1 -0
  131. package/dist/react/ui/tabs.d.ts +12 -0
  132. package/dist/react/ui/tabs.d.ts.map +1 -0
  133. package/dist/react/ui/tabs.js +31 -0
  134. package/dist/react/ui/tabs.js.map +1 -0
  135. package/dist/react/ui/textarea.d.ts +4 -0
  136. package/dist/react/ui/textarea.d.ts.map +1 -0
  137. package/dist/react/ui/textarea.js +8 -0
  138. package/dist/react/ui/textarea.js.map +1 -0
  139. package/dist/react/ui/toggle-group.d.ts +11 -0
  140. package/dist/react/ui/toggle-group.d.ts.map +1 -0
  141. package/dist/react/ui/toggle-group.js +25 -0
  142. package/dist/react/ui/toggle-group.js.map +1 -0
  143. package/dist/react/ui/toggle.d.ts +10 -0
  144. package/dist/react/ui/toggle.d.ts.map +1 -0
  145. package/dist/react/ui/toggle.js +27 -0
  146. package/dist/react/ui/toggle.js.map +1 -0
  147. package/dist/refs.d.ts +16 -0
  148. package/dist/refs.d.ts.map +1 -0
  149. package/dist/refs.js +43 -0
  150. package/dist/refs.js.map +1 -0
  151. package/dist/server/index.d.ts +4 -0
  152. package/dist/server/index.d.ts.map +1 -0
  153. package/dist/server/index.js +4 -0
  154. package/dist/server/index.js.map +1 -0
  155. package/dist/server/recipes.d.ts +39 -0
  156. package/dist/server/recipes.d.ts.map +1 -0
  157. package/dist/server/recipes.js +81 -0
  158. package/dist/server/recipes.js.map +1 -0
  159. package/dist/server/webhooks.d.ts +135 -0
  160. package/dist/server/webhooks.d.ts.map +1 -0
  161. package/dist/server/webhooks.js +243 -0
  162. package/dist/server/webhooks.js.map +1 -0
  163. package/dist/store.d.ts +124 -0
  164. package/dist/store.d.ts.map +1 -0
  165. package/dist/store.js +443 -0
  166. package/dist/store.js.map +1 -0
  167. package/dist/task-client.d.ts +137 -0
  168. package/dist/task-client.d.ts.map +1 -0
  169. package/dist/task-client.js +271 -0
  170. package/dist/task-client.js.map +1 -0
  171. package/dist/tasks.d.ts +84 -0
  172. package/dist/tasks.d.ts.map +1 -0
  173. package/dist/tasks.js +208 -0
  174. package/dist/tasks.js.map +1 -0
  175. package/dist/time.d.ts +15 -0
  176. package/dist/time.d.ts.map +1 -0
  177. package/dist/time.js +34 -0
  178. package/dist/time.js.map +1 -0
  179. package/dist/types.d.ts +74 -0
  180. package/dist/types.d.ts.map +1 -0
  181. package/dist/types.js +9 -0
  182. package/dist/types.js.map +1 -0
  183. package/package.json +101 -4
  184. package/src/activity.ts +86 -0
  185. package/src/blockers.ts +134 -0
  186. package/src/conflicts.ts +115 -0
  187. package/src/draft.ts +162 -0
  188. package/src/errors.ts +40 -0
  189. package/src/index.ts +10 -0
  190. package/src/react/TaskActivity.tsx +187 -0
  191. package/src/react/TaskBoard.tsx +264 -0
  192. package/src/react/TaskConflicts.tsx +217 -0
  193. package/src/react/TaskCreateForm.tsx +165 -0
  194. package/src/react/TaskEditor.tsx +485 -0
  195. package/src/react/TaskFilters.tsx +122 -0
  196. package/src/react/TaskView.tsx +291 -0
  197. package/src/react/TasksAbout.tsx +226 -0
  198. package/src/react/copy.tsx +253 -0
  199. package/src/react/fields.tsx +104 -0
  200. package/src/react/hooks.ts +41 -0
  201. package/src/react/index.ts +12 -0
  202. package/src/react/parts.tsx +176 -0
  203. package/src/react/ui/README.md +6 -0
  204. package/src/react/ui/alert.tsx +75 -0
  205. package/src/react/ui/avatar.tsx +109 -0
  206. package/src/react/ui/badge.tsx +48 -0
  207. package/src/react/ui/button.tsx +66 -0
  208. package/src/react/ui/card.tsx +102 -0
  209. package/src/react/ui/input.tsx +18 -0
  210. package/src/react/ui/label.tsx +23 -0
  211. package/src/react/ui/radio-group.tsx +41 -0
  212. package/src/react/ui/select.tsx +189 -0
  213. package/src/react/ui/separator.tsx +27 -0
  214. package/src/react/ui/sheet.tsx +145 -0
  215. package/src/react/ui/skeleton.tsx +13 -0
  216. package/src/react/ui/table.tsx +113 -0
  217. package/src/react/ui/tabs.tsx +89 -0
  218. package/src/react/ui/textarea.tsx +17 -0
  219. package/src/react/ui/toggle-group.tsx +89 -0
  220. package/src/react/ui/toggle.tsx +44 -0
  221. package/src/refs.ts +49 -0
  222. package/src/server/index.ts +3 -0
  223. package/src/server/recipes.ts +107 -0
  224. package/src/server/webhooks.ts +369 -0
  225. package/src/store.ts +538 -0
  226. package/src/task-client.ts +373 -0
  227. package/src/tasks.ts +263 -0
  228. package/src/time.ts +35 -0
  229. package/src/types.ts +101 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,159 @@
1
- # Temporary Holding Version
1
+ # baack-ts-tasks
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript tools for [Baack](https://www.baack.co) tasks, built on
4
+ [`@baack-software/baack-ts-client`](https://github.com/Baack-Software/baack-ts-client): a typed task API, helpers for
5
+ building task views, a task store for UIs, and shadcn/ui task components for React, used first by the Baack console. See [docs/PLAN.md](docs/PLAN.md).
6
+
7
+ ## Usage
8
+
9
+ ```ts
10
+ import { BaackClient } from '@baack-software/baack-ts-client';
11
+ import { TaskClient, byUrgency, filterTasks, groupTasks, isOverdue, toTimestamp } from '@baack-software/baack-ts-tasks';
12
+
13
+ const tasks = new TaskClient(new BaackClient({ baseUrl: 'https://api.baack.co', credentials: 'include' }));
14
+
15
+ // List a company's tasks, with the identities and projects for names and pickers.
16
+ const { tasks: all, identities, projects } = await tasks.list({ owner: companyUrn });
17
+
18
+ // Work with them without further requests.
19
+ const mine = filterTasks(all, { assignee: [me], open: true }).sort(byUrgency);
20
+ const overdue = all.filter((task) => isOverdue(task));
21
+ const board = groupTasks(all, 'status'); // every status as a column, in order
22
+
23
+ // Change them. Each update reads the task and sends it whole with the change, since the API stores what an update
24
+ // sends; `actor` attributes the change in the activity log.
25
+ const task = await tasks.create({ owner: companyUrn, title: 'Welcome your new customer', dueTimestamp: toTimestamp(due) });
26
+ await tasks.setStatus(task, 'IN_PROGRESS', { actor: me });
27
+ await tasks.addBlocker(task, otherTaskUrn, { actor: me });
28
+ await tasks.comment(task, 'Called them, waiting to hear back', { actor: me });
29
+ const logs = await tasks.allLogs(task); // newest first
30
+ ```
31
+
32
+ ### Store
33
+
34
+ `@baack-software/baack-ts-tasks/store` holds a company's tasks for a UI. Changes show at once, and roll back if the
35
+ server refuses them, without disturbing other changes still in flight. A short while after each write the store reads
36
+ the task again, since the server can change it after accepting. `subscribe` and `getState` fit React's
37
+ `useSyncExternalStore`.
38
+
39
+ ```ts
40
+ import { TaskStore, selectGroups, selectName } from '@baack-software/baack-ts-tasks/store';
41
+
42
+ const store = new TaskStore(tasks, { owner: companyUrn, actor: me });
43
+ store.subscribe(() => {
44
+ const state = store.getState(); // a new object on every change
45
+ render(selectGroups(state, 'status', { assignee: [me] }, byUrgency), (urn) => selectName(state, urn));
46
+ });
47
+ await store.load();
48
+
49
+ await store.setStatus(urn, 'COMPLETED'); // shown straight away; rolled back and rethrown on failure
50
+ await store.addBlocker(urn, otherUrn); // builds on changes still in flight
51
+ await store.loadLogs(urn); // state.logs.get(urn), newest first; loadMoreLogs for older
52
+ await store.comment(urn, 'Done, thanks all'); // shown at the top of the log
53
+ ```
54
+
55
+ Workflows can't be listed through the API, so name the ones the app uses: `new TaskStore(tasks, { owner, workflows:
56
+ [workflowUrn] })` loads them into `state.workflows`. `groupByStage(tasks, workflow)` makes columns of its stages in
57
+ order, and `groupByWorkflow(tasks, workflows)` a column per workflow (a task's workflow is the one its stage is in).
58
+ `TaskView` offers both as board groupings, Workflow and each workflow's stages, and a Stage picker in the editor. Its
59
+ board columns are sorted open first, then by priority, due date and title (`byPriorityThenDue`).
60
+
61
+ ### Conflicting edits
62
+
63
+ Updates replace the stored task, so a change made from a stale copy would undo what someone else saved since. Pass the
64
+ copy the person was looking at as `base`, and the update keeps everything they didn't change:
65
+
66
+ - A field they changed that someone else also changed since `base` is a conflict: the update throws
67
+ `TaskConflictError` with each field's base, theirs and mine values, and the task as it is now, and saves nothing.
68
+ `resolveConflicts(changes, choices)` keeps "mine" or "theirs" per field; update again against `current`.
69
+ - Fields only someone else changed are kept and reported to `onChangedElsewhere`.
70
+ - List changes (blockers, associations) are applied as additions and removals, so they never conflict.
71
+
72
+ ```ts
73
+ try {
74
+ await tasks.update(task, { title }, { base: task, onChangedElsewhere: (fields) => notify(fields) });
75
+ } catch (error) {
76
+ if (!(error instanceof TaskConflictError)) throw error;
77
+ const choices = await askPerson(error.conflicts); // { title: 'mine' } or { title: 'theirs' }
78
+ await tasks.update(error.current, resolveConflicts({ title }, choices), { base: error.current });
79
+ }
80
+ ```
81
+
82
+ `TaskStore.update` does this for you, with what it shows as the base: on a conflict it shows the task as it is now,
83
+ and fields others changed go in `state.changedElsewhere` until `dismissChangedElsewhere`. `TaskEditor` turns a
84
+ conflict into a panel to keep mine or use theirs for each field. The API doesn't check versions on write yet, so a
85
+ change saved in the moment between the read and the write can still be lost.
86
+
87
+ ### React components
88
+
89
+ `@baack-software/baack-ts-tasks/react` has the task UI built from shadcn/ui (style `radix-nova`): `TaskView` (the
90
+ whole view, on a `TaskStore`), and the parts it is made of for apps that compose their own: `TaskBoard`, `TaskTable`,
91
+ `TaskFilters`, `TaskEditor`, `TaskConflicts`, `TaskActivity`, `TaskCreateForm`, and badges, due dates and avatars. The parts take plain
92
+ props and callbacks, so any data layer (the store, TanStack Query, …) can drive them. The editor relates a task to
93
+ people, other tasks, and any companies and content in its `directory` (`TaskView` takes them as `related`, since the
94
+ store doesn't load them).
95
+
96
+ `TasksAbout` is the panel for a console page about one thing: `<TasksAbout store={store} about={{ kind: 'company',
97
+ urn }} onOpen={…} />` lists its open tasks, most urgent first, shows completed ones on request, and has a quick-add
98
+ whose task is related to it (`kind` is `identity`, `company`, `entity`, `task` or `project`). The API can't search by
99
+ association yet, so it filters the store's tasks; share one store across a page's panels.
100
+
101
+ ```tsx
102
+ import { TaskCopyProvider, TaskView } from '@baack-software/baack-ts-tasks/react';
103
+
104
+ <TaskCopyProvider entity={copyEntity /* optional */}>
105
+ <TaskView store={store} me={myIdentityUrn} />
106
+ </TaskCopyProvider>
107
+ ```
108
+
109
+ - **Theme.** The components use the shadcn CSS variables (`--primary`, `--muted`, `--border`, …), so they take the
110
+ host app's theme. Tailwind must scan the package: `@source "../node_modules/@baack-software/baack-ts-tasks/dist";`.
111
+ - **Copy.** Every label, heading and message is a Baack text item rendered with `baack-ts-components`, with an en-GB
112
+ placeholder until content exists. Pass the content entity to `TaskCopyProvider` to replace or translate it; the
113
+ Baack editor can edit it in place. `TASK_COPY` lists every item name and placeholder.
114
+ - **Peers.** React 19, and `@baack-software/baack-ts-components` for the copy.
115
+
116
+ Try it with a fake API: `npm run demo`. Add `?layout=table`, `?group=workflowStage`, `?task=t-hero` or `?theme=dark`
117
+ to the URL; `?about=co-acme` shows a page about a company with its `TasksAbout` panel; with `?task=t-hero&conflict`,
118
+ someone else edits the task shortly after loading, so changing its title shows a conflict.
119
+
120
+ Timestamps are UTC without a zone. Use `parseTimestamp`, `toTimestamp`, `toLocalInput` and `fromLocalInput` rather
121
+ than `new Date(timestamp)`, which reads them as local time.
122
+
123
+ ### Server: webhooks and automations
124
+
125
+ `@baack-software/baack-ts-tasks/server` is for webhook endpoints and scheduled jobs, with a token that can write
126
+ tasks, so never in a browser. It uses Web Crypto and the Fetch API types, so it runs on Node 20+, Deno, Bun and edge
127
+ runtimes.
128
+
129
+ ```ts
130
+ import { webhookHandler, taskFromWebhook, unblockOnCompletion, welcomeNewCompany } from '@baack-software/baack-ts-tasks/server';
131
+
132
+ // A Fetch API handler: verifies the signature, skips retries already handled, then runs onEvent.
133
+ export const POST = webhookHandler({
134
+ secret: process.env.BAACK_WEBHOOK_SECRET!,
135
+ onEvent: async ({ event }) => {
136
+ await welcomeNewCompany(event, tasks, { owner: companyUrn }); // on COMPANY CREATE
137
+ await unblockOnCompletion(event, tasks); // on TASK UPDATE to a finished status
138
+ },
139
+ });
140
+ ```
141
+
142
+ A delivery's `Signature` is a base64 HMAC-SHA256, keyed with the subscription's secret, over the raw body, then the
143
+ `Last-Modified` timestamp, then the `Idempotency-Key` (the trigger's URN), as `Signed-Headers` lists them.
144
+ `verifyWebhook({ body, headers }, secret)` checks it on its own; pass the body exactly as received, since
145
+ re-serialised JSON won't match. Events carry no task, so `taskFromWebhook` reads it (`null` once deleted). Retries
146
+ reuse the idempotency key: the handler remembers keys in memory by default; pass an `idempotency` store backed by
147
+ your database when several processes receive deliveries. `signWebhook` signs a body the same way, for tests and for
148
+ replaying deliveries locally. `overdueTasks(tasks, owner)` and `byAssignee` are for a nightly reminder job.
149
+
150
+ ## Development
151
+
152
+ The client is linked from `../baack-ts-client` while both change; build it there first.
153
+
154
+ ```sh
155
+ npm install
156
+ npm test
157
+ npm run typecheck
158
+ npm run build
159
+ ```
@@ -0,0 +1,20 @@
1
+ import type { TaskLog } from '@baack-software/baack-ts-client';
2
+ import type { Activity } from './types.ts';
3
+ /** What happened, as a short sentence without the subject, e.g. "Status set to In progress". */
4
+ export declare const ACTIVITY_LABELS: Readonly<Record<Activity, string>>;
5
+ /** A readable label for an activity, falling back to the raw value in lower case for activities added later. */
6
+ export declare function activityLabel(activity: string): string;
7
+ /** Whether the log entry is a comment rather than a recorded change. */
8
+ export declare function isComment(log: Pick<TaskLog, 'activity'>): boolean;
9
+ /** A comment and the replies to it, oldest reply first. */
10
+ export interface CommentThread {
11
+ comment: TaskLog;
12
+ replies: TaskLog[];
13
+ }
14
+ /**
15
+ * Groups comments into threads by `replyTo`, most recently active thread first. Expects `logs` newest first, as the
16
+ * API returns them.
17
+ * A reply whose parent is not in `logs` (for example on an older page) starts its own thread.
18
+ */
19
+ export declare function commentThreads(logs: readonly TaskLog[]): CommentThread[];
20
+ //# sourceMappingURL=activity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity.d.ts","sourceRoot":"","sources":["../src/activity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,gGAAgG;AAChG,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAqC9D,CAAC;AAEF,gHAAgH;AAChH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wEAAwE;AACxE,wBAAgB,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,OAAO,CAEjE;AAED,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,aAAa,EAAE,CAqBxE"}
@@ -0,0 +1,75 @@
1
+ /** What happened, as a short sentence without the subject, e.g. "Status set to In progress". */
2
+ export const ACTIVITY_LABELS = {
3
+ CREATED: 'Created',
4
+ STATUS_UNDEFINED: 'Status set to Undefined',
5
+ STATUS_PENDING: 'Status set to Pending',
6
+ STATUS_IN_PROGRESS: 'Status set to In progress',
7
+ STATUS_BLOCKED: 'Status set to Blocked',
8
+ STATUS_COMPLETED: 'Status set to Completed',
9
+ STATUS_COMPL_ETED: 'Status set to Completed',
10
+ STATUS_CLOSED: 'Status set to Closed',
11
+ PRIORITY_NONE: 'Priority set to None',
12
+ PRIORITY_LOW: 'Priority set to Low',
13
+ PRIORITY_MEDIUM: 'Priority set to Medium',
14
+ PRIORITY_HIGH: 'Priority set to High',
15
+ PRIORITY_CRITICAL: 'Priority set to Critical',
16
+ WORKFLOW_STAGE_SET: 'Moved to a workflow stage',
17
+ WORKFLOW_STAGE_UNSET: 'Removed from its workflow stage',
18
+ COMMENT_ADDED: 'Commented',
19
+ WORK_TASK_ASSOCIATION_ADDED: 'Related task added',
20
+ WORK_TASK_ASSOCIATION_REMOVED: 'Related task removed',
21
+ WORK_TASK_BLOCKER_ADDED: 'Blocker added',
22
+ WORK_TASK_BLOCKER_REMOVED: 'Blocker removed',
23
+ WORK_TASK_BLOCKING_ADDED: 'Now blocking a task',
24
+ WORK_TASK_BLOCKING_REMOVED: 'No longer blocking a task',
25
+ WORK_TASK_ENTITY_ADDED: 'Content added',
26
+ WORK_TASK_ENTITY_REMOVED: 'Content removed',
27
+ WORK_TASK_IDENTITY_ADDED: 'Person added',
28
+ WORK_TASK_IDENTITY_REMOVED: 'Person removed',
29
+ WORK_TASK_COMPANY_ADDED: 'Company added',
30
+ WORK_TASK_COMPANY_REMOVED: 'Company removed',
31
+ WORK_PROJECT_SET: 'Added to a project',
32
+ WORK_PROJECT_UNSET: 'Removed from its project',
33
+ ASSIGNED: 'Assigned',
34
+ UNASSIGNED: 'Unassigned',
35
+ TITLE_UPDATED: 'Title changed',
36
+ DESCRIPTION_UPDATED: 'Description changed',
37
+ DUE_DATE_UPDATED: 'Due date changed',
38
+ DUE_DATE_UNSET: 'Due date removed',
39
+ };
40
+ /** A readable label for an activity, falling back to the raw value in lower case for activities added later. */
41
+ export function activityLabel(activity) {
42
+ return ACTIVITY_LABELS[activity] ?? activity.toLowerCase().replaceAll('_', ' ');
43
+ }
44
+ /** Whether the log entry is a comment rather than a recorded change. */
45
+ export function isComment(log) {
46
+ return log.activity === 'COMMENT_ADDED';
47
+ }
48
+ /**
49
+ * Groups comments into threads by `replyTo`, most recently active thread first. Expects `logs` newest first, as the
50
+ * API returns them.
51
+ * A reply whose parent is not in `logs` (for example on an older page) starts its own thread.
52
+ */
53
+ export function commentThreads(logs) {
54
+ const comments = logs.filter(isComment);
55
+ const byUrn = new Map(comments.map((log) => [log.urn, log]));
56
+ const rootOf = (log) => {
57
+ const seen = new Set();
58
+ let current = log;
59
+ while (current.replyTo && byUrn.has(current.replyTo.urn) && !seen.has(current.urn)) {
60
+ seen.add(current.urn);
61
+ current = byUrn.get(current.replyTo.urn);
62
+ }
63
+ return current;
64
+ };
65
+ const threads = new Map();
66
+ for (const log of comments) {
67
+ const root = rootOf(log);
68
+ const thread = threads.get(root.urn) ?? { comment: root, replies: [] };
69
+ if (root !== log)
70
+ thread.replies.unshift(log);
71
+ threads.set(root.urn, thread);
72
+ }
73
+ return [...threads.values()];
74
+ }
75
+ //# sourceMappingURL=activity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity.js","sourceRoot":"","sources":["../src/activity.ts"],"names":[],"mappings":"AAGA,gGAAgG;AAChG,MAAM,CAAC,MAAM,eAAe,GAAuC;IACjE,OAAO,EAAE,SAAS;IAClB,gBAAgB,EAAE,yBAAyB;IAC3C,cAAc,EAAE,uBAAuB;IACvC,kBAAkB,EAAE,2BAA2B;IAC/C,cAAc,EAAE,uBAAuB;IACvC,gBAAgB,EAAE,yBAAyB;IAC3C,iBAAiB,EAAE,yBAAyB;IAC5C,aAAa,EAAE,sBAAsB;IACrC,aAAa,EAAE,sBAAsB;IACrC,YAAY,EAAE,qBAAqB;IACnC,eAAe,EAAE,wBAAwB;IACzC,aAAa,EAAE,sBAAsB;IACrC,iBAAiB,EAAE,0BAA0B;IAC7C,kBAAkB,EAAE,2BAA2B;IAC/C,oBAAoB,EAAE,iCAAiC;IACvD,aAAa,EAAE,WAAW;IAC1B,2BAA2B,EAAE,oBAAoB;IACjD,6BAA6B,EAAE,sBAAsB;IACrD,uBAAuB,EAAE,eAAe;IACxC,yBAAyB,EAAE,iBAAiB;IAC5C,wBAAwB,EAAE,qBAAqB;IAC/C,0BAA0B,EAAE,2BAA2B;IACvD,sBAAsB,EA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CAAC,GAAG,CAAC,EAAE,CAAC;YACnF,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACtB,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAE,CAAC;QAC5C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IACjD,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QACvE,IAAI,IAAI,KAAK,GAAG;YAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { Task } from '@baack-software/baack-ts-client';
2
+ import type { RefLike } from './types.ts';
3
+ /** Finds a task by URN, for example from a store or a `Map`. */
4
+ export type TaskLookup = (urn: string) => Task | undefined;
5
+ /** A lookup over a list of tasks. */
6
+ export declare function lookupFrom(tasks: Iterable<Task>): TaskLookup;
7
+ /**
8
+ * The URNs of the tasks blocking `task` that are still open. A blocker the lookup doesn't know counts as open, since
9
+ * the task may be blocked by work the reader can't see.
10
+ */
11
+ export declare function openBlockers(task: Task, lookup: TaskLookup): string[];
12
+ /** Whether every task blocking `task` is done, so work can start. */
13
+ export declare function isUnblocked(task: Task, lookup: TaskLookup): boolean;
14
+ /**
15
+ * Blocking edges among `tasks`, from each task to the tasks it blocks. Reads both `blocking` and `blockedBy`, so an
16
+ * edge recorded on only one side still counts.
17
+ */
18
+ export declare function blockingGraph(tasks: Iterable<Task>): Map<string, Set<string>>;
19
+ /** A cycle of blocking tasks as a list of URNs (the first task blocks the second, and so on, back to the first), or undefined. */
20
+ export declare function findBlockingCycle(tasks: Iterable<Task>): string[] | undefined;
21
+ /** Whether making `blocker` block `task` would create a cycle, given the current `tasks`. */
22
+ export declare function wouldCreateCycle(tasks: Iterable<Task>, task: RefLike, blocker: RefLike): boolean;
23
+ /**
24
+ * Tasks in an order where each comes after the tasks blocking it, keeping the given order otherwise. Tasks in a
25
+ * cycle are placed at the end in their given order.
26
+ */
27
+ export declare function dependencyOrder(tasks: readonly Task[]): Task[];
28
+ //# sourceMappingURL=blockers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blockers.d.ts","sourceRoot":"","sources":["../src/blockers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAG5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,gEAAgE;AAChE,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,SAAS,CAAC;AAE3D,qCAAqC;AACrC,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,UAAU,CAI5D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,EAAE,CAOrE;AAED,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAEnE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAa7E;AAED,kIAAkI;AAClI,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,GAAG,SAAS,CA4B7E;AAED,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAkBhG;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,IAAI,EAAE,CAyB9D"}
@@ -0,0 +1,134 @@
1
+ import { urnOf } from "./refs.js";
2
+ import { isOpen } from "./tasks.js";
3
+ /** A lookup over a list of tasks. */
4
+ export function lookupFrom(tasks) {
5
+ const byUrn = new Map();
6
+ for (const task of tasks)
7
+ byUrn.set(task.urn, task);
8
+ return (urn) => byUrn.get(urn);
9
+ }
10
+ /**
11
+ * The URNs of the tasks blocking `task` that are still open. A blocker the lookup doesn't know counts as open, since
12
+ * the task may be blocked by work the reader can't see.
13
+ */
14
+ export function openBlockers(task, lookup) {
15
+ return (task.blockedBy ?? [])
16
+ .map((blocker) => blocker.urn)
17
+ .filter((urn) => {
18
+ const blocker = lookup(urn);
19
+ return blocker === undefined || isOpen(blocker);
20
+ });
21
+ }
22
+ /** Whether every task blocking `task` is done, so work can start. */
23
+ export function isUnblocked(task, lookup) {
24
+ return openBlockers(task, lookup).length === 0;
25
+ }
26
+ /**
27
+ * Blocking edges among `tasks`, from each task to the tasks it blocks. Reads both `blocking` and `blockedBy`, so an
28
+ * edge recorded on only one side still counts.
29
+ */
30
+ export function blockingGraph(tasks) {
31
+ const graph = new Map();
32
+ const edge = (from, to) => {
33
+ const targets = graph.get(from) ?? new Set();
34
+ targets.add(to);
35
+ graph.set(from, targets);
36
+ };
37
+ for (const task of tasks) {
38
+ if (!graph.has(task.urn))
39
+ graph.set(task.urn, new Set());
40
+ for (const blocked of task.blocking ?? [])
41
+ edge(task.urn, blocked.urn);
42
+ for (const blocker of task.blockedBy ?? [])
43
+ edge(blocker.urn, task.urn);
44
+ }
45
+ return graph;
46
+ }
47
+ /** A cycle of blocking tasks as a list of URNs (the first task blocks the second, and so on, back to the first), or undefined. */
48
+ export function findBlockingCycle(tasks) {
49
+ const graph = blockingGraph(tasks);
50
+ const state = new Map();
51
+ const path = [];
52
+ const visit = (urn) => {
53
+ state.set(urn, 'visiting');
54
+ path.push(urn);
55
+ for (const next of graph.get(urn) ?? []) {
56
+ const seen = state.get(next);
57
+ if (seen === 'visiting')
58
+ return path.slice(path.indexOf(next));
59
+ if (seen === undefined) {
60
+ const cycle = visit(next);
61
+ if (cycle)
62
+ return cycle;
63
+ }
64
+ }
65
+ path.pop();
66
+ state.set(urn, 'done');
67
+ return undefined;
68
+ };
69
+ for (const urn of graph.keys()) {
70
+ if (state.get(urn) === undefined) {
71
+ const cycle = visit(urn);
72
+ if (cycle)
73
+ return cycle;
74
+ }
75
+ }
76
+ return undefined;
77
+ }
78
+ /** Whether making `blocker` block `task` would create a cycle, given the current `tasks`. */
79
+ export function wouldCreateCycle(tasks, task, blocker) {
80
+ const from = urnOf(blocker);
81
+ const to = urnOf(task);
82
+ if (from === to)
83
+ return true;
84
+ // A cycle appears when the blocker is already reachable from the task it would block.
85
+ const graph = blockingGraph(tasks);
86
+ const queue = [to];
87
+ const seen = new Set(queue);
88
+ for (let urn = queue.shift(); urn !== undefined; urn = queue.shift()) {
89
+ for (const next of graph.get(urn) ?? []) {
90
+ if (next === from)
91
+ return true;
92
+ if (!seen.has(next)) {
93
+ seen.add(next);
94
+ queue.push(next);
95
+ }
96
+ }
97
+ }
98
+ return false;
99
+ }
100
+ /**
101
+ * Tasks in an order where each comes after the tasks blocking it, keeping the given order otherwise. Tasks in a
102
+ * cycle are placed at the end in their given order.
103
+ */
104
+ export function dependencyOrder(tasks) {
105
+ const known = new Set(tasks.map((task) => task.urn));
106
+ const graph = blockingGraph(tasks);
107
+ const waiting = new Map(tasks.map((task) => [task.urn, 0]));
108
+ for (const [from, targets] of graph) {
109
+ if (!known.has(from))
110
+ continue;
111
+ for (const to of targets)
112
+ if (known.has(to))
113
+ waiting.set(to, (waiting.get(to) ?? 0) + 1);
114
+ }
115
+ const ordered = [];
116
+ const placed = new Set();
117
+ let progress = true;
118
+ while (progress) {
119
+ progress = false;
120
+ for (const task of tasks) {
121
+ if (placed.has(task.urn) || waiting.get(task.urn) !== 0)
122
+ continue;
123
+ ordered.push(task);
124
+ placed.add(task.urn);
125
+ progress = true;
126
+ for (const to of graph.get(task.urn) ?? []) {
127
+ if (known.has(to))
128
+ waiting.set(to, (waiting.get(to) ?? 0) - 1);
129
+ }
130
+ }
131
+ }
132
+ return [...ordered, ...tasks.filter((task) => !placed.has(task.urn))];
133
+ }
134
+ //# sourceMappingURL=blockers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blockers.js","sourceRoot":"","sources":["../src/blockers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAMpC,qCAAqC;AACrC,MAAM,UAAU,UAAU,CAAC,KAAqB;IAC9C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;IACtC,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACpD,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAU,EAAE,MAAkB;IACzD,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC;SAC1B,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;SAC7B,MAAM,CAAC,CAAC,GAAG,E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