@antelopejs/dms-automation 0.7.0 → 0.8.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 (246) hide show
  1. package/README.md +19 -5
  2. package/dist/cluster/bus.js +8 -6
  3. package/dist/cluster/bus.js.map +1 -1
  4. package/dist/cluster/leader.js.map +1 -1
  5. package/dist/data/procedures-query.d.ts +19 -0
  6. package/dist/data/procedures-query.js +105 -0
  7. package/dist/data/procedures-query.js.map +1 -0
  8. package/dist/data/procedures-table.d.ts +4 -20
  9. package/dist/data/procedures-table.js +10 -106
  10. package/dist/data/procedures-table.js.map +1 -1
  11. package/dist/data/runs-table.js.map +1 -1
  12. package/dist/db/models/automation_template.model.d.ts +2 -4
  13. package/dist/db/models/automation_template.model.js +13 -14
  14. package/dist/db/models/automation_template.model.js.map +1 -1
  15. package/dist/db/models/procedure_run.model.js.map +1 -1
  16. package/dist/db/models/stats.model.js.map +1 -1
  17. package/dist/db/tables/procedure_run.table.d.ts +2 -1
  18. package/dist/db/tables/procedure_run.table.js.map +1 -1
  19. package/dist/implementations/dms-automation/index.js.map +1 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/pages/category.js.map +1 -1
  22. package/dist/pages/index.js.map +1 -1
  23. package/dist/pages/overview.js.map +1 -1
  24. package/dist/pages/procedures.js.map +1 -1
  25. package/dist/pages/runs.js.map +1 -1
  26. package/dist/pages/shared.js +1 -1
  27. package/dist/pages/shared.js.map +1 -1
  28. package/dist/realtime.d.ts +2 -1
  29. package/dist/realtime.js.map +1 -1
  30. package/dist/routes/action-types.d.ts +2 -1
  31. package/dist/routes/action-types.js.map +1 -1
  32. package/dist/routes/deleteConfirm.js +4 -3
  33. package/dist/routes/deleteConfirm.js.map +1 -1
  34. package/dist/routes/graphSchema.d.ts +2 -1
  35. package/dist/routes/graphSchema.js +8 -7
  36. package/dist/routes/graphSchema.js.map +1 -1
  37. package/dist/routes/procedureChecks.js +5 -5
  38. package/dist/routes/procedureChecks.js.map +1 -1
  39. package/dist/routes/procedureRuns.d.ts +2 -2
  40. package/dist/routes/procedureRuns.js +1 -1
  41. package/dist/routes/procedureRuns.js.map +1 -1
  42. package/dist/routes/procedures.d.ts +14 -13
  43. package/dist/routes/procedures.js +2 -1
  44. package/dist/routes/procedures.js.map +1 -1
  45. package/dist/routes/requests.d.ts +11 -5
  46. package/dist/routes/requests.js.map +1 -1
  47. package/dist/routes/runs.d.ts +7 -7
  48. package/dist/routes/runs.js +5 -3
  49. package/dist/routes/runs.js.map +1 -1
  50. package/dist/routes/stats.js.map +1 -1
  51. package/dist/routes/templates.d.ts +3 -2
  52. package/dist/routes/templates.js +2 -1
  53. package/dist/routes/templates.js.map +1 -1
  54. package/dist/routes/trigger-types.d.ts +2 -1
  55. package/dist/routes/trigger-types.js.map +1 -1
  56. package/dist/routes/typeConfigShared.d.ts +2 -1
  57. package/dist/routes/typeConfigShared.js.map +1 -1
  58. package/dist/runtime/armErrors.d.ts +0 -1
  59. package/dist/runtime/armErrors.js +0 -7
  60. package/dist/runtime/armErrors.js.map +1 -1
  61. package/dist/runtime/boundRunLog.d.ts +1 -0
  62. package/dist/runtime/boundRunLog.js +11 -11
  63. package/dist/runtime/boundRunLog.js.map +1 -1
  64. package/dist/runtime/builtins/actions/http.js +16 -9
  65. package/dist/runtime/builtins/actions/http.js.map +1 -1
  66. package/dist/runtime/builtins/actions/log.js.map +1 -1
  67. package/dist/runtime/builtins/data/boolean.js +4 -5
  68. package/dist/runtime/builtins/data/boolean.js.map +1 -1
  69. package/dist/runtime/builtins/data/compare.js +8 -10
  70. package/dist/runtime/builtins/data/compare.js.map +1 -1
  71. package/dist/runtime/builtins/data/constant.js +1 -1
  72. package/dist/runtime/builtins/data/constant.js.map +1 -1
  73. package/dist/runtime/builtins/data/json.js +4 -5
  74. package/dist/runtime/builtins/data/json.js.map +1 -1
  75. package/dist/runtime/builtins/data/math.js +4 -4
  76. package/dist/runtime/builtins/data/math.js.map +1 -1
  77. package/dist/runtime/builtins/data/object.js +12 -17
  78. package/dist/runtime/builtins/data/object.js.map +1 -1
  79. package/dist/runtime/builtins/data/string.js +13 -18
  80. package/dist/runtime/builtins/data/string.js.map +1 -1
  81. package/dist/runtime/builtins/nodes/action.js +5 -2
  82. package/dist/runtime/builtins/nodes/action.js.map +1 -1
  83. package/dist/runtime/builtins/nodes/data.js +2 -2
  84. package/dist/runtime/builtins/nodes/data.js.map +1 -1
  85. package/dist/runtime/builtins/nodes/delay.js +2 -2
  86. package/dist/runtime/builtins/nodes/delay.js.map +1 -1
  87. package/dist/runtime/builtins/nodes/forRange.js +2 -2
  88. package/dist/runtime/builtins/nodes/forRange.js.map +1 -1
  89. package/dist/runtime/builtins/nodes/foreach.js +2 -2
  90. package/dist/runtime/builtins/nodes/foreach.js.map +1 -1
  91. package/dist/runtime/builtins/nodes/groupInput.js +2 -2
  92. package/dist/runtime/builtins/nodes/groupInput.js.map +1 -1
  93. package/dist/runtime/builtins/nodes/groupOutput.js +2 -2
  94. package/dist/runtime/builtins/nodes/groupOutput.js.map +1 -1
  95. package/dist/runtime/builtins/nodes/if.js +2 -2
  96. package/dist/runtime/builtins/nodes/if.js.map +1 -1
  97. package/dist/runtime/builtins/nodes/parallel.js +2 -2
  98. package/dist/runtime/builtins/nodes/parallel.js.map +1 -1
  99. package/dist/runtime/builtins/nodes/retry.js +5 -4
  100. package/dist/runtime/builtins/nodes/retry.js.map +1 -1
  101. package/dist/runtime/builtins/nodes/setVariable.js +2 -2
  102. package/dist/runtime/builtins/nodes/setVariable.js.map +1 -1
  103. package/dist/runtime/builtins/nodes/switch.js +2 -2
  104. package/dist/runtime/builtins/nodes/switch.js.map +1 -1
  105. package/dist/runtime/builtins/nodes/trigger.js +2 -2
  106. package/dist/runtime/builtins/nodes/trigger.js.map +1 -1
  107. package/dist/runtime/builtins/nodes/tryCatch.js +2 -2
  108. package/dist/runtime/builtins/nodes/tryCatch.js.map +1 -1
  109. package/dist/runtime/builtins/triggers/cron.d.ts +2 -1
  110. package/dist/runtime/builtins/triggers/cron.js +5 -7
  111. package/dist/runtime/builtins/triggers/cron.js.map +1 -1
  112. package/dist/runtime/builtins/triggers/webhook.d.ts +6 -5
  113. package/dist/runtime/builtins/triggers/webhook.js +9 -6
  114. package/dist/runtime/builtins/triggers/webhook.js.map +1 -1
  115. package/dist/runtime/declaredProcedures.d.ts +2 -2
  116. package/dist/runtime/declaredProcedures.js +3 -2
  117. package/dist/runtime/declaredProcedures.js.map +1 -1
  118. package/dist/runtime/describe.js +11 -10
  119. package/dist/runtime/describe.js.map +1 -1
  120. package/dist/runtime/executor.js +10 -7
  121. package/dist/runtime/executor.js.map +1 -1
  122. package/dist/runtime/flatten.d.ts +1 -1
  123. package/dist/runtime/flatten.js +1 -1
  124. package/dist/runtime/flatten.js.map +1 -1
  125. package/dist/runtime/graphIssues.js +24 -22
  126. package/dist/runtime/graphIssues.js.map +1 -1
  127. package/dist/runtime/graphVersion.d.ts +1 -1
  128. package/dist/runtime/graphVersion.js +2 -1
  129. package/dist/runtime/graphVersion.js.map +1 -1
  130. package/dist/runtime/nodeKinds.d.ts +3 -2
  131. package/dist/runtime/nodeKinds.js.map +1 -1
  132. package/dist/runtime/reconcile.d.ts +3 -0
  133. package/dist/runtime/reconcile.js +178 -0
  134. package/dist/runtime/reconcile.js.map +1 -0
  135. package/dist/runtime/resolveInputs.d.ts +4 -2
  136. package/dist/runtime/resolveInputs.js +13 -12
  137. package/dist/runtime/resolveInputs.js.map +1 -1
  138. package/dist/runtime/resolveSubgraph.js +4 -5
  139. package/dist/runtime/resolveSubgraph.js.map +1 -1
  140. package/dist/runtime/retention.js.map +1 -1
  141. package/dist/runtime/runProcedure.d.ts +1 -1
  142. package/dist/runtime/runProcedure.js +2 -1
  143. package/dist/runtime/runProcedure.js.map +1 -1
  144. package/dist/runtime/schedule.js +3 -0
  145. package/dist/runtime/schedule.js.map +1 -1
  146. package/dist/runtime/schemaProperties.d.ts +11 -0
  147. package/dist/runtime/schemaProperties.js +7 -0
  148. package/dist/runtime/schemaProperties.js.map +1 -0
  149. package/dist/runtime/serialQueue.d.ts +1 -1
  150. package/dist/runtime/serialQueue.js +4 -4
  151. package/dist/runtime/serialQueue.js.map +1 -1
  152. package/dist/runtime/subscriptions.js +21 -180
  153. package/dist/runtime/subscriptions.js.map +1 -1
  154. package/dist/runtime/subwalk.js.map +1 -1
  155. package/dist/runtime/templateCacheState.d.ts +6 -0
  156. package/dist/runtime/templateCacheState.js +10 -0
  157. package/dist/runtime/templateCacheState.js.map +1 -0
  158. package/dist/runtime/templateUsages.js +4 -5
  159. package/dist/runtime/templateUsages.js.map +1 -1
  160. package/dist/runtime/topo.js +2 -4
  161. package/dist/runtime/topo.js.map +1 -1
  162. package/dist/runtime/trace.js +12 -9
  163. package/dist/runtime/trace.js.map +1 -1
  164. package/dist/runtime/triggerHandles.d.ts +3 -0
  165. package/dist/runtime/triggerHandles.js +8 -0
  166. package/dist/runtime/triggerHandles.js.map +1 -1
  167. package/dist/runtime/typeOrigin.js +12 -1
  168. package/dist/runtime/typeOrigin.js.map +1 -1
  169. package/dist/runtime/validate.js.map +1 -1
  170. package/dist/runtime/validateTemplate.js.map +1 -1
  171. package/dist/runtime/withTimeout.js.map +1 -1
  172. package/dist/runtime/wording.js +12 -8
  173. package/dist/runtime/wording.js.map +1 -1
  174. package/dist/stats/health-banner.js.map +1 -1
  175. package/dist/stats/health.js.map +1 -1
  176. package/dist/stats/kpi.js +1 -1
  177. package/dist/stats/kpi.js.map +1 -1
  178. package/dist/stats/overview.js +2 -1
  179. package/dist/stats/overview.js.map +1 -1
  180. package/dist/types/dataValue.d.ts +8 -0
  181. package/dist/types/dataValue.js +36 -0
  182. package/dist/types/dataValue.js.map +1 -0
  183. package/dist/types/graph.d.ts +8 -1
  184. package/dist/types/graph.js +8 -0
  185. package/dist/types/graph.js.map +1 -1
  186. package/dist/types/guards.d.ts +8 -0
  187. package/dist/types/guards.js +35 -0
  188. package/dist/types/guards.js.map +1 -0
  189. package/frontend-vue/app/build/components/editor/EditorBanners.vue +120 -0
  190. package/frontend-vue/app/build/components/editor/EditorChoiceModal.vue +44 -0
  191. package/frontend-vue/app/build/components/editor/EditorForkModal.vue +51 -0
  192. package/frontend-vue/app/build/components/editor/EditorHeader.vue +146 -0
  193. package/frontend-vue/app/build/components/editor/EditorSaveTemplateModal.vue +105 -0
  194. package/frontend-vue/app/build/components/editor/NodeInspectorDocs.vue +28 -0
  195. package/frontend-vue/app/build/components/editor/NodeInspectorRun.vue +48 -0
  196. package/frontend-vue/app/build/composables/editor/useBuilderMount.ts +129 -0
  197. package/frontend-vue/app/build/composables/editor/useBuilderSave.ts +256 -0
  198. package/frontend-vue/app/build/composables/editor/useBuilderShortcuts.ts +270 -0
  199. package/frontend-vue/app/build/composables/editor/useDraftProblems.ts +288 -0
  200. package/frontend-vue/app/build/composables/editor/useEditorContext.ts +388 -0
  201. package/frontend-vue/app/build/composables/editor/useEditorLoad.ts +158 -0
  202. package/frontend-vue/app/build/composables/editor/useForkToLocal.ts +193 -0
  203. package/frontend-vue/app/build/composables/editor/useGraphHistory.ts +113 -0
  204. package/frontend-vue/app/build/composables/editor/useGroupEditing.ts +445 -0
  205. package/frontend-vue/app/build/composables/editor/usePalette.ts +41 -0
  206. package/frontend-vue/app/build/composables/editor/useProcedureActions.ts +96 -0
  207. package/frontend-vue/app/build/composables/editor/useRunOverlay.ts +466 -0
  208. package/frontend-vue/app/build/composables/editor/useSaveAsTemplate.ts +172 -0
  209. package/frontend-vue/app/build/composables/editor/useSavedTriggers.ts +100 -0
  210. package/frontend-vue/app/build/composables/editor/useSubgraphNavigation.ts +270 -0
  211. package/frontend-vue/app/build/composables/editor/useUnsavedGuards.ts +233 -0
  212. package/frontend-vue/app/build/composables/graphCanvas/connect.ts +273 -0
  213. package/frontend-vue/app/build/composables/graphCanvas/edgeEvents.ts +172 -0
  214. package/frontend-vue/app/build/composables/graphCanvas/edges.ts +55 -0
  215. package/frontend-vue/app/build/composables/graphCanvas/handles.ts +181 -0
  216. package/frontend-vue/app/build/composables/graphCanvas/linkMenu.ts +123 -0
  217. package/frontend-vue/app/build/composables/graphCanvas/nodeData.ts +222 -0
  218. package/frontend-vue/app/build/composables/graphCanvas/placement.ts +248 -0
  219. package/frontend-vue/app/build/composables/graphCanvas/selection.ts +150 -0
  220. package/frontend-vue/app/build/composables/graphCanvas/types.ts +188 -0
  221. package/frontend-vue/app/build/composables/graphCanvas/view.ts +230 -0
  222. package/frontend-vue/app/build/types/editor.ts +94 -0
  223. package/frontend-vue/app/build/utils/editor/apiErrors.ts +74 -0
  224. package/frontend-vue/app/build/utils/editor/graphShape.ts +68 -0
  225. package/frontend-vue/app/build/utils/editor/groupPlan.ts +322 -0
  226. package/frontend-vue/app/build/utils/editor/groupPorts.ts +210 -0
  227. package/frontend-vue/app/build/utils/editor/keyboard.ts +22 -0
  228. package/frontend-vue/app/build/utils/inspectorFields.ts +117 -0
  229. package/frontend-vue/app/build/utils/templates.ts +88 -0
  230. package/frontend-vue/app/components/AttentionList.vue +2 -6
  231. package/frontend-vue/app/components/Catalog.vue +2 -1
  232. package/frontend-vue/app/components/Editor/GraphCanvas.vue +78 -1337
  233. package/frontend-vue/app/components/Editor/NodeInspector.vue +31 -123
  234. package/frontend-vue/app/components/Editor.vue +134 -3484
  235. package/frontend-vue/app/components/Templates.vue +14 -84
  236. package/frontend-vue/build/backend-boundary.ts +122 -0
  237. package/frontend-vue/dms.frontend.build.ts +2 -0
  238. package/frontend-vue/eslint-rules/index.mjs +103 -0
  239. package/frontend-vue/eslint.config.mjs +15 -0
  240. package/frontend-vue/package.json +7 -4
  241. package/frontend-vue/pnpm-lock.yaml +73 -59
  242. package/frontend-vue/tests/api-error-presentation.test.cjs +257 -0
  243. package/frontend-vue/tests/helpers/setup.cjs +44 -0
  244. package/package.json +4 -4
  245. package/skills/dms-automation/SKILL.md +2 -2
  246. package/skills/dms-automation/cases.json +58 -0
@@ -2,6 +2,14 @@
2
2
  import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'
3
3
  import { isIconName } from './IconPicker.vue'
4
4
  import { queryString } from '../utils/automation'
5
+ import {
6
+ schemaTypeOf,
7
+ usageRowsOf,
8
+ type ProcedureSummary,
9
+ type TemplateRow,
10
+ type TemplateUsage,
11
+ type TemplateUsages,
12
+ } from '../build/utils/templates'
5
13
 
6
14
  // The library's templates: reusable groups other procedures place as linked
7
15
  // blocks. The detail edits the name, icon and description, lists the ports
@@ -9,52 +17,6 @@ import { queryString } from '../utils/automation'
9
17
  // other templates; deleting forks every usage into a local group so they keep
10
18
  // working. The picked template is kept in the URL (`?template=`).
11
19
 
12
- interface JsonSchema {
13
- type?: string | string[]
14
- [key: string]: unknown
15
- }
16
-
17
- interface TemplatePort {
18
- name: string
19
- kind: 'data' | 'trigger'
20
- direction: 'in' | 'out'
21
- schema?: JsonSchema
22
- }
23
-
24
- interface TemplateRow {
25
- _id: string
26
- name: string
27
- description: string
28
- icon: string
29
- ports: TemplatePort[]
30
- subgraph: unknown
31
- usageCount?: number
32
- updated_at?: string
33
- }
34
-
35
- interface TemplateUsage {
36
- procedureId: string
37
- nodeId: string
38
- groupPath: string[]
39
- }
40
-
41
- interface TemplateNesting {
42
- templateId: string
43
- nodeId: string
44
- groupPath: string[]
45
- }
46
-
47
- interface TemplateUsages {
48
- procedures: TemplateUsage[]
49
- templates: TemplateNesting[]
50
- }
51
-
52
- interface ProcedureSummary {
53
- procedureId: string
54
- name: string
55
- status: 'failing' | 'degraded' | 'healthy' | 'paused' | 'draft'
56
- }
57
-
58
20
  const props = defineProps<{
59
21
  apiUrl: string
60
22
  builderUrl: string
@@ -74,6 +36,7 @@ const { $authFetch } = useAuthFetch()
74
36
  const route = useDmsRoute()
75
37
  const router = useDmsRouter()
76
38
  const toast = useToast()
39
+ const { presentError } = useApiErrorPresenter()
77
40
  const { t } = useI18n()
78
41
  const { confirm } = useConfirm()
79
42
 
@@ -181,20 +144,7 @@ function backToList() {
181
144
  }
182
145
 
183
146
  /** One line per procedure or template placing it, with how many times. */
184
- const usageRows = computed(() => {
185
- const rows = new Map<string, { kind: 'procedure' | 'template'; id: string; first: TemplateUsage | TemplateNesting; count: number }>()
186
- for (const usage of usages.value.procedures) {
187
- const row = rows.get(`p:${usage.procedureId}`)
188
- if (row) row.count++
189
- else rows.set(`p:${usage.procedureId}`, { kind: 'procedure', id: usage.procedureId, first: usage, count: 1 })
190
- }
191
- for (const nesting of usages.value.templates) {
192
- const row = rows.get(`t:${nesting.templateId}`)
193
- if (row) row.count++
194
- else rows.set(`t:${nesting.templateId}`, { kind: 'template', id: nesting.templateId, first: nesting, count: 1 })
195
- }
196
- return [...rows.values()]
197
- })
147
+ const usageRows = computed(() => usageRowsOf(usages.value))
198
148
 
199
149
  const NAME_ID = 'template-name'
200
150
  const NAME_MAX = 200
@@ -205,8 +155,6 @@ watch(formName, () => fieldErrors.clear('name'))
205
155
 
206
156
  interface RefusalBody {
207
157
  code?: string
208
- error?: string
209
- issues?: { path?: (string | number)[]; message?: string }[]
210
158
  }
211
159
 
212
160
  /** The `code` a refused request answered with, if any. */
@@ -214,13 +162,6 @@ function errorCode(e: unknown): string | undefined {
214
162
  return (e as { data?: RefusalBody }).data?.code
215
163
  }
216
164
 
217
- /** What the server said was wrong, rather than the request's raw status line. */
218
- function errorMessage(e: unknown): string {
219
- const body = (e as { data?: RefusalBody }).data
220
- const issues = body?.issues?.map((i) => (i.path?.length ? `${i.path.join('.')}: ${i.message}` : i.message)).filter(Boolean)
221
- return issues?.length ? issues.join(' · ') : (body?.error ?? describeApiError(e))
222
- }
223
-
224
165
  async function onSave() {
225
166
  const s = selected.value
226
167
  if (!s) return
@@ -247,7 +188,7 @@ async function onSave() {
247
188
  await fieldErrors.setError('name', t('dms_automation.templates.nameTaken'))
248
189
  return
249
190
  }
250
- toast.add({ title: t('dms_automation.templates.saveError'), description: errorMessage(e), color: 'error', icon: 'i-ph-warning' })
191
+ presentError(e, { fallbackKey: 'dms_automation.templates.saveError' })
251
192
  } finally {
252
193
  saving.value = false
253
194
  }
@@ -269,7 +210,7 @@ async function onDelete() {
269
210
  await usagesRead.refresh()
270
211
  const fresh = usagesRead.data.value
271
212
  if (usagesRead.error.value || !fresh) {
272
- toast.add({ title: t('dms_automation.templates.deleteError'), description: errorMessage(usagesRead.error.value), color: 'error', icon: 'i-ph-warning' })
213
+ presentError(usagesRead.error.value, { fallbackKey: 'dms_automation.templates.deleteError' })
273
214
  return
274
215
  }
275
216
  const count = fresh.procedures.length + fresh.templates.length
@@ -285,11 +226,8 @@ async function onDelete() {
285
226
  await $authFetch(`${props.apiUrl}/templates/${s._id}?force=1`, { method: 'DELETE' })
286
227
  } catch (e) {
287
228
  const kept = errorCode(e) === 'fork-incomplete'
288
- toast.add({
289
- title: kept ? t('dms_automation.templates.forkIncomplete') : t('dms_automation.templates.deleteError'),
290
- description: kept ? t('dms_automation.templates.forkIncompleteHint') : errorMessage(e),
291
- color: 'error',
292
- icon: 'i-ph-warning',
229
+ presentError(e, {
230
+ fallbackKey: kept ? 'dms_automation.templates.forkIncompleteHint' : 'dms_automation.templates.deleteError',
293
231
  })
294
232
  await usagesRead.refresh()
295
233
  return
@@ -311,14 +249,6 @@ function ownersOf(found: TemplateUsages): string {
311
249
  ].filter(Boolean)
312
250
  return parts.length === 2 ? t('dms_automation.templates.ownersAnd', { first: parts[0], second: parts[1] }) : parts[0]!
313
251
  }
314
-
315
- function schemaTypeOf(p: TemplatePort): string {
316
- if (p.kind !== 'data') return '—'
317
- const type = p.schema?.type
318
- if (typeof type === 'string') return type
319
- if (Array.isArray(type)) return type.join(' | ')
320
- return 'any'
321
- }
322
252
  </script>
323
253
 
324
254
  <template>
@@ -0,0 +1,122 @@
1
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
2
+ import { dirname, isAbsolute, join, relative, sep } from "node:path";
3
+ import type { DmsVitePluginEntry } from "#dms/frontend-build";
4
+
5
+ type VitePlugin = Extract<DmsVitePluginEntry, { name: string }>;
6
+
7
+ const BACKEND_PACKAGE = "@antelopejs/dms-automation";
8
+ const BACKEND_SOURCE = "src";
9
+ const QUERY_OR_HASH = /[?#].*$/;
10
+
11
+ const backendRoots = new Map<string, string | null>();
12
+
13
+ /** Whether a parsed manifest names its package. */
14
+ function isNamedManifest(value: unknown): value is { name: string } {
15
+ return (
16
+ typeof value === "object" &&
17
+ value !== null &&
18
+ "name" in value &&
19
+ typeof value.name === "string"
20
+ );
21
+ }
22
+
23
+ /** The package name a `package.json` declares, or `undefined`. */
24
+ function packageName(manifest: string): string | undefined {
25
+ try {
26
+ const parsed: unknown = JSON.parse(readFileSync(manifest, "utf8"));
27
+ return isNamedManifest(parsed) ? parsed.name : undefined;
28
+ } catch {
29
+ return undefined;
30
+ }
31
+ }
32
+
33
+ /** The directory of the backend package that holds `directory`, or null. */
34
+ function backendRoot(directory: string): string | null {
35
+ const known = backendRoots.get(directory);
36
+ if (known !== undefined) {
37
+ return known;
38
+ }
39
+ const manifest = join(directory, "package.json");
40
+ const parent = dirname(directory);
41
+ let root: string | null = null;
42
+ if (existsSync(manifest)) {
43
+ root = packageName(manifest) === BACKEND_PACKAGE ? directory : null;
44
+ } else if (parent !== directory) {
45
+ root = backendRoot(parent);
46
+ }
47
+ backendRoots.set(directory, root);
48
+ return root;
49
+ }
50
+
51
+ /**
52
+ * The real path of a resolved module id when it lies under the `src`
53
+ * directory of the backend package, or `undefined`. The package that owns the
54
+ * file decides, not a path, so the answer is the same in the repository and in
55
+ * the build workspace. Virtual ids and ids that are not files are ignored.
56
+ */
57
+ function backendSourceFile(id: string): string | undefined {
58
+ const path = id.replace(QUERY_OR_HASH, "");
59
+ if (!isAbsolute(path)) {
60
+ return undefined;
61
+ }
62
+ let real: string;
63
+ try {
64
+ real = realpathSync(path);
65
+ } catch {
66
+ return undefined;
67
+ }
68
+ const root = backendRoot(dirname(real));
69
+ if (root === null) {
70
+ return undefined;
71
+ }
72
+ return relative(root, real).split(sep)[0] === BACKEND_SOURCE
73
+ ? real
74
+ : undefined;
75
+ }
76
+
77
+ /**
78
+ * Fails the build and the dev server when a module of the frontend resolves to
79
+ * a file under the `src` of the backend package: the browser reaches the
80
+ * backend only through its HTTP interface. It checks what the whole resolution
81
+ * chain returns, an id marked external included, so an alias is seen through
82
+ * and a symlink the resolver returns is followed to its real path, and it runs
83
+ * before the other plugins (`enforce: "pre"`). Vite builds workers with their
84
+ * own plugin list, so the plugin adds itself there too.
85
+ *
86
+ * antelopejs-sync writes this file from `@antelopejs/tooling-configs` and
87
+ * restores it on every run: change the plugin in the pack, not here.
88
+ */
89
+ export function backendBoundary(): VitePlugin {
90
+ return {
91
+ ...boundaryCheck(),
92
+ config: () => ({ worker: { plugins: () => [boundaryCheck()] } }),
93
+ };
94
+ }
95
+
96
+ /** The check alone, as a worker build runs it. */
97
+ function boundaryCheck(): VitePlugin {
98
+ return {
99
+ name: `${BACKEND_PACKAGE}:backend-boundary`,
100
+ enforce: "pre",
101
+ async resolveId(source, importer, options) {
102
+ const resolved = await this.resolve(source, importer, {
103
+ ...options,
104
+ skipSelf: true,
105
+ });
106
+ if (resolved === null) {
107
+ return resolved;
108
+ }
109
+ const file = backendSourceFile(resolved.id);
110
+ if (file === undefined) {
111
+ return resolved;
112
+ }
113
+ const from =
114
+ importer === undefined
115
+ ? "an entry point"
116
+ : importer.replace(QUERY_OR_HASH, "");
117
+ return this.error(
118
+ `Backend boundary: ${from} imports ${file}, which is under the src of ${BACKEND_PACKAGE}. The frontend reaches the backend only through its HTTP interface.`,
119
+ );
120
+ },
121
+ };
122
+ }
@@ -1,7 +1,9 @@
1
1
  import { defineDmsFrontendBuild } from "#dms/frontend-build";
2
+ import { backendBoundary } from "./build/backend-boundary.ts";
2
3
 
3
4
  // The layer's public helpers, auto-imported in its own components: nothing is
4
5
  // auto-imported from a module that does not list its folders here.
5
6
  export default defineDmsFrontendBuild((build) => {
6
7
  build.registerAutoImports(["app/composables", "app/utils"]);
8
+ build.registerVitePlugins(() => [backendBoundary()]);
7
9
  });
@@ -0,0 +1,103 @@
1
+ const BLANK = /^\s*$/;
2
+ const ROW_TOKEN = /\{\{[^}]*\}\}/g;
3
+ const BARE_BRACES = /\{[^}]*\}/;
4
+
5
+ /**
6
+ * The end of what precedes `element` in its parent: the previous sibling that
7
+ * is not blank text, or the parent's start tag.
8
+ */
9
+ function precedingEnd(element) {
10
+ const siblings = element.parent.children;
11
+ const index = siblings.indexOf(element);
12
+ const previous = siblings
13
+ .slice(0, index)
14
+ .reverse()
15
+ .find((node) => !(node.type === "VText" && BLANK.test(node.value)));
16
+ return previous ? previous.range[1] : element.parent.startTag.range[1];
17
+ }
18
+
19
+ /**
20
+ * A comment between the branches of a `v-if` chain hydrates with a mismatch:
21
+ * the development compiler moves it into the next branch, which then renders
22
+ * as a fragment, while the server's production compile drops it and renders
23
+ * the bare element.
24
+ */
25
+ const noCommentBeforeElse = {
26
+ meta: {
27
+ type: "problem",
28
+ schema: [],
29
+ messages: {
30
+ misplaced:
31
+ "A template comment before `v-else-if` or `v-else` hydrates with a mismatch. Put it inside the branch's element, or into the script.",
32
+ },
33
+ },
34
+ create(context) {
35
+ const { defineTemplateBodyVisitor } = context.sourceCode.parserServices;
36
+ if (!defineTemplateBodyVisitor) return {};
37
+ const comments = context.sourceCode.ast.templateBody?.comments ?? [];
38
+ return defineTemplateBodyVisitor({
39
+ VElement(element) {
40
+ const continues = element.startTag.attributes.some(
41
+ (attribute) =>
42
+ attribute.directive &&
43
+ (attribute.key.name.name === "else" ||
44
+ attribute.key.name.name === "else-if"),
45
+ );
46
+ if (!continues) return;
47
+ const from = precedingEnd(element);
48
+ for (const comment of comments) {
49
+ if (comment.range[0] >= from && comment.range[1] <= element.range[0])
50
+ context.report({ loc: comment.loc, messageId: "misplaced" });
51
+ }
52
+ },
53
+ });
54
+ },
55
+ };
56
+
57
+ /** The `confirmFrom` call a node makes, if it does. */
58
+ function isConfirmFromCall(node) {
59
+ const { callee } = node;
60
+ return (
61
+ (callee.type === "Identifier" && callee.name === "confirmFrom") ||
62
+ (callee.type === "MemberExpression" &&
63
+ !callee.computed &&
64
+ callee.property.name === "confirmFrom")
65
+ );
66
+ }
67
+
68
+ /**
69
+ * The host's `confirmFrom(url, ...)` fills only the `{{row.X}}` tokens of the
70
+ * URL from its `params`. Any other token (`{id}`) reaches the API as it is,
71
+ * `%7Bid%7D`, and the dialog never opens.
72
+ */
73
+ const confirmFromRowTokens = {
74
+ meta: {
75
+ type: "problem",
76
+ schema: [],
77
+ messages: {
78
+ bareToken:
79
+ "`confirmFrom` fills only `{{row.X}}` tokens: write the fill-in of this URL as one, or interpolate it.",
80
+ },
81
+ },
82
+ create(context) {
83
+ const check = (node) => {
84
+ const [url] = node.arguments;
85
+ if (!isConfirmFromCall(node) || url?.type !== "TemplateLiteral") return;
86
+ const text = url.quasis.map((part) => part.value.raw).join("");
87
+ if (BARE_BRACES.test(text.replace(ROW_TOKEN, "")))
88
+ context.report({ node: url, messageId: "bareToken" });
89
+ };
90
+ const { defineTemplateBodyVisitor } = context.sourceCode.parserServices;
91
+ const script = { CallExpression: check };
92
+ return defineTemplateBodyVisitor
93
+ ? defineTemplateBodyVisitor(script, script)
94
+ : script;
95
+ },
96
+ };
97
+
98
+ export default {
99
+ rules: {
100
+ "no-comment-before-else": noCommentBeforeElse,
101
+ "confirm-from-row-tokens": confirmFromRowTokens,
102
+ },
103
+ };
@@ -2,11 +2,16 @@ import eslint from "@eslint/js";
2
2
  import ts from "typescript-eslint";
3
3
  import vue from "eslint-plugin-vue";
4
4
  import globals from "globals";
5
+ import automation from "./eslint-rules/index.mjs";
5
6
 
6
7
  export default ts.config(
7
8
  { ignores: ["dist/**", "node_modules/**"] },
8
9
  eslint.configs.recommended,
9
10
  ...vue.configs["flat/essential"],
11
+ {
12
+ files: ["tests/**/*.cjs"],
13
+ languageOptions: { globals: globals.node },
14
+ },
10
15
  {
11
16
  files: ["**/*.{ts,vue}"],
12
17
  languageOptions: {
@@ -21,4 +26,14 @@ export default ts.config(
21
26
  },
22
27
  },
23
28
  { files: ["**/*.ts"], languageOptions: { parser: ts.parser } },
29
+ {
30
+ files: ["app/**/*.{ts,vue}"],
31
+ plugins: { automation },
32
+ rules: { "automation/confirm-from-row-tokens": "error" },
33
+ },
34
+ {
35
+ files: ["app/**/*.vue"],
36
+ plugins: { automation },
37
+ rules: { "automation/no-comment-before-else": "error" },
38
+ },
24
39
  );
@@ -8,7 +8,8 @@
8
8
  "build": "pnpm --dir \"${DMS_FRONTEND_WORKSPACE:?Set DMS_FRONTEND_WORKSPACE to the generated Inertia workspace}\" build",
9
9
  "typecheck": "pnpm --dir \"${DMS_FRONTEND_WORKSPACE:?Set DMS_FRONTEND_WORKSPACE to the generated Inertia workspace}\" typecheck",
10
10
  "format": "prettier --write .",
11
- "lint": "eslint . --max-warnings=3",
11
+ "test": "node --test tests/*.test.cjs",
12
+ "lint": "eslint . --max-warnings=3 && node node_modules/@antelopejs/dms/frontend-vue/scripts/check-api-error-presentation.mjs app",
12
13
  "lint:fix": "eslint . --fix"
13
14
  },
14
15
  "dependencies": {
@@ -16,8 +17,8 @@
16
17
  "vue": "^3.5.18"
17
18
  },
18
19
  "devDependencies": {
19
- "@antelopejs/dms": ">=0.11.0 <1.0.0",
20
- "@antelopejs/dms-frontend": ">=0.9.0 <0.10.0",
20
+ "@antelopejs/dms": ">=0.13.1 <1.0.0",
21
+ "@antelopejs/dms-frontend": ">=0.9.2 <0.10.0",
21
22
  "@antelopejs/tooling-configs": ">=0.0.9 <1.0.0",
22
23
  "@eslint/js": "^9.0.0",
23
24
  "@nuxt/ui": "4.10.0",
@@ -28,10 +29,12 @@
28
29
  "prettier-plugin-tailwindcss": "^0.6.11",
29
30
  "typescript": "^5.8.2",
30
31
  "typescript-eslint": "^8.0.0",
32
+ "vite": "^8.3.4",
33
+ "vue-eslint-parser": "^10.3.0",
31
34
  "vue-tsc": "^3.1.1"
32
35
  },
33
36
  "engines": {
34
- "@antelopejs/dms-frontend": ">=0.9.0 <0.10.0"
37
+ "@antelopejs/dms-frontend": ">=0.9.2 <0.10.0"
35
38
  },
36
39
  "packageManager": "pnpm@10.6.5"
37
40
  }