@antelopejs/dms-automation 0.3.1 → 0.4.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.
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, ref, watch } from 'vue'
2
+ import { computed, ref } from 'vue'
3
3
  import {
4
4
  builderRunUrl,
5
5
  opensInBuilder,
@@ -40,13 +40,6 @@ const runId = computed(() => {
40
40
  return typeof q === 'string' ? q : Array.isArray(q) ? (q[0] ?? null) : null
41
41
  })
42
42
 
43
- const run = ref<RunDetail | null>(null)
44
- const loading = ref(true)
45
- /** Why the run did not load: no id given, no such run, or another error. */
46
- const failure = ref<{ reason: 'noRun' | 'notFound' | 'error'; message?: string } | null>(null)
47
- const tab = ref('steps')
48
- const pathOnly = ref(false)
49
-
50
43
  const HTTP_NOT_FOUND = 404
51
44
 
52
45
  function statusOf(e: unknown): number | undefined {
@@ -54,28 +47,24 @@ function statusOf(e: unknown): number | undefined {
54
47
  return error.statusCode ?? error.response?.status
55
48
  }
56
49
 
57
- async function load() {
58
- if (!runId.value) {
59
- run.value = null
60
- failure.value = { reason: 'noRun' }
61
- loading.value = false
62
- return
63
- }
64
- loading.value = true
65
- try {
66
- run.value = await runs.getRun(runId.value)
67
- failure.value = null
68
- } catch (e) {
69
- run.value = null
70
- failure.value = statusOf(e) === HTTP_NOT_FOUND
71
- ? { reason: 'notFound' }
72
- : { reason: 'error', message: describeApiError(e) }
73
- } finally {
74
- loading.value = false
75
- }
76
- }
50
+ const runRead = runs.readRun(runId)
51
+ // Until another run's read answers, the run on screen stays; a run that did
52
+ // not load shows why instead.
53
+ const run = computed<RunDetail | null>(() => (runRead.error.value ? null : runRead.data.value))
54
+ const loading = computed(() => runRead.pending.value)
55
+ /** Why the run did not load: no id given, no such run, or another error. */
56
+ const failure = computed<{ reason: 'noRun' | 'notFound' | 'error'; message?: string } | null>(() => {
57
+ if (!runId.value) return { reason: 'noRun' }
58
+ const error = runRead.error.value
59
+ if (!error) return null
60
+ return statusOf(error) === HTTP_NOT_FOUND ? { reason: 'notFound' } : { reason: 'error', message: describeApiError(error) }
61
+ })
62
+ const tab = ref('steps')
63
+ const pathOnly = ref(false)
77
64
 
78
- watch(runId, () => void load(), { immediate: true })
65
+ function load() {
66
+ void runRead.refresh()
67
+ }
79
68
 
80
69
  const names = computed(() => {
81
70
  const map = new Map<string, StepName>()
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, nextTick, onMounted, ref, useTemplateRef, watch } from 'vue'
2
+ import { computed, nextTick, ref, useTemplateRef, watch } from 'vue'
3
3
  import { isIconName } from './IconPicker.vue'
4
4
  import { queryString } from '../utils/automation'
5
5
 
@@ -77,12 +77,6 @@ const toast = useToast()
77
77
  const { t } = useI18n()
78
78
  const { confirm } = useConfirm()
79
79
 
80
- const items = ref<TemplateRow[]>([])
81
- /** How many templates exist, when the server sent fewer than that. */
82
- const total = ref(0)
83
- const loading = ref(true)
84
- const loadError = ref<string | null>(null)
85
- const selectedId = ref<string | null>(null)
86
80
  const search = ref('')
87
81
  const detail = useTemplateRef<HTMLElement>('detail')
88
82
  const list = useTemplateRef<HTMLElement>('list')
@@ -92,48 +86,49 @@ const formDescription = ref('')
92
86
  const formIcon = ref(DEFAULT_ICON)
93
87
  const saving = ref(false)
94
88
 
95
- const usages = ref<TemplateUsages>(NO_USAGES)
96
- const usagesLoading = ref(false)
97
- const procedures = ref<Map<string, ProcedureSummary>>(new Map())
98
-
99
89
  function queryTemplate(): string | null {
100
90
  return queryString(route.query.template)
101
91
  }
102
92
 
103
- async function loadList() {
104
- loading.value = true
105
- try {
106
- const { results: list, total: count } = await $authFetch<{ results: TemplateRow[]; total: number }>(`${props.apiUrl}/templates`)
107
- items.value = list
108
- total.value = count
109
- const wanted = selectedId.value ?? queryTemplate()
110
- selectedId.value = list.some((x) => x._id === wanted) ? wanted : (sortedItems.value[0]?._id ?? null)
111
- loadError.value = null
112
- } catch (e) {
113
- loadError.value = describeApiError(e)
114
- } finally {
115
- loading.value = false
116
- }
93
+ // The templates, and the state of the procedures placing them, read with
94
+ // the page.
95
+ const listRead = useApiData<{ results: TemplateRow[]; total: number }>(`${props.apiUrl}/templates`)
96
+ const summaryRead = useApiData<ProcedureSummary[]>(`${props.apiUrl}/procedures/summary`)
97
+ const items = computed(() => listRead.data.value?.results ?? [])
98
+ /** How many templates exist, when the server sent fewer than that. */
99
+ const total = computed(() => listRead.data.value?.total ?? 0)
100
+ const loading = computed(() => listRead.pending.value)
101
+ const loadError = computed(() => (listRead.error.value ? describeApiError(listRead.error.value) : null))
102
+ const procedures = computed(() => new Map((summaryRead.data.value ?? []).map((p) => [p.procedureId, p])))
103
+
104
+ function loadList() {
105
+ void listRead.refresh()
117
106
  }
118
107
 
119
- async function loadProcedures() {
120
- try {
121
- const rows = await $authFetch<ProcedureSummary[]>(`${props.apiUrl}/procedures/summary`)
122
- procedures.value = new Map(rows.map((p) => [p.procedureId, p]))
123
- } catch {
124
- procedures.value = new Map()
125
- }
108
+ /** Shows a write at once: the list's data is replaced, never changed in place. */
109
+ function replaceListed(change: (rows: TemplateRow[]) => TemplateRow[]) {
110
+ const listed = listRead.data.value
111
+ if (!listed) return
112
+ const results = change(listed.results)
113
+ listRead.data.value = { results, total: Math.max(0, listed.total + results.length - listed.results.length) }
126
114
  }
127
115
 
128
- onMounted(() => {
129
- void loadList()
130
- void loadProcedures()
116
+ const sortedItems = computed(() => [...items.value].sort((a, b) => a.name.localeCompare(b.name)))
117
+ // The template picked in this view, else the URL's (`?template=`).
118
+ const picked = ref<string | null>(null)
119
+ /** The template shown: the one picked, else the first by name. */
120
+ const selectedId = computed<string | null>(() => {
121
+ const wanted = picked.value ?? queryTemplate()
122
+ return items.value.some((x) => x._id === wanted) ? wanted : (sortedItems.value[0]?._id ?? null)
131
123
  })
132
-
133
124
  const selected = computed(() => items.value.find((x) => x._id === selectedId.value) ?? null)
125
+
126
+ // Where the template shown is used, read with it.
127
+ const usagesRead = useApiData<TemplateUsages>(() => (selectedId.value ? `${props.apiUrl}/templates/${selectedId.value}/usages` : null))
128
+ const usages = computed(() => (usagesRead.placeholder.value || usagesRead.error.value ? NO_USAGES : (usagesRead.data.value ?? NO_USAGES)))
129
+ const usagesLoading = computed(() => usagesRead.pending.value && (usagesRead.placeholder.value || !usagesRead.data.value))
134
130
  const templateNames = computed(() => new Map(items.value.map((x) => [x._id, x.name])))
135
131
 
136
- const sortedItems = computed(() => [...items.value].sort((a, b) => a.name.localeCompare(b.name)))
137
132
  const filteredItems = computed(() => {
138
133
  const q = search.value.trim().toLowerCase()
139
134
  if (!q) return sortedItems.value
@@ -154,13 +149,15 @@ const dirty = computed(() => {
154
149
  const form = useTemplateRef<HTMLElement>('form')
155
150
  const { confirmLeave } = useUnsavedChanges({ dirty, element: form })
156
151
 
152
+ // The form starts from the template shown: awaited, the server renders it
153
+ // filled in, and the browser starts from the same values.
154
+ await listRead
157
155
  watch(
158
156
  selected,
159
157
  (s) => {
160
158
  formName.value = s?.name ?? ''
161
159
  formDescription.value = s?.description ?? ''
162
160
  formIcon.value = s?.icon || DEFAULT_ICON
163
- void loadUsages()
164
161
  },
165
162
  { immediate: true },
166
163
  )
@@ -171,7 +168,7 @@ watch(selectedId, (id) => {
171
168
 
172
169
  async function select(id: string) {
173
170
  if (id === selectedId.value || !(await confirmLeave())) return
174
- selectedId.value = id
171
+ picked.value = id
175
172
  // Below the two-column width the detail sits under the list: bring it into view.
176
173
  await nextTick()
177
174
  if (detail.value && list.value && detail.value.offsetTop > list.value.offsetTop) {
@@ -183,24 +180,6 @@ function backToList() {
183
180
  list.value?.scrollIntoView({ behavior: 'smooth', block: 'start' })
184
181
  }
185
182
 
186
- async function fetchUsages(id: string): Promise<TemplateUsages> {
187
- return await $authFetch<TemplateUsages>(`${props.apiUrl}/templates/${id}/usages`)
188
- }
189
-
190
- async function loadUsages() {
191
- const s = selected.value
192
- usages.value = NO_USAGES
193
- if (!s) return
194
- usagesLoading.value = true
195
- try {
196
- usages.value = await fetchUsages(s._id)
197
- } catch {
198
- usages.value = NO_USAGES
199
- } finally {
200
- usagesLoading.value = false
201
- }
202
- }
203
-
204
183
  /** One line per procedure or template placing it, with how many times. */
205
184
  const usageRows = computed(() => {
206
185
  const rows = new Map<string, { kind: 'procedure' | 'template'; id: string; first: TemplateUsage | TemplateNesting; count: number }>()
@@ -261,8 +240,7 @@ async function onSave() {
261
240
  subgraph: s.subgraph ?? { nodes: [], triggerEdges: [], dataEdges: [] },
262
241
  },
263
242
  })
264
- const index = items.value.findIndex((x) => x._id === s._id)
265
- if (index >= 0) items.value[index] = { ...s, ...updated, usageCount: s.usageCount }
243
+ replaceListed((rows) => rows.map((x) => (x._id === s._id ? { ...s, ...updated, usageCount: s.usageCount } : x)))
266
244
  toast.add({ title: t('dms_automation.templates.saved', { name: updated.name }), color: 'success', icon: 'i-ph-check-circle' })
267
245
  } catch (e) {
268
246
  if (errorCode(e) === 'name-taken') {
@@ -288,12 +266,10 @@ async function onDelete() {
288
266
  const s = selected.value
289
267
  if (!s) return
290
268
  // Counted now, not when the list loaded: a usage added since is forked too.
291
- let fresh: TemplateUsages
292
- try {
293
- fresh = await fetchUsages(s._id)
294
- usages.value = fresh
295
- } catch (e) {
296
- toast.add({ title: t('dms_automation.templates.deleteError'), description: errorMessage(e), color: 'error', icon: 'i-ph-warning' })
269
+ await usagesRead.refresh()
270
+ const fresh = usagesRead.data.value
271
+ 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' })
297
273
  return
298
274
  }
299
275
  const count = fresh.procedures.length + fresh.templates.length
@@ -315,15 +291,14 @@ async function onDelete() {
315
291
  color: 'error',
316
292
  icon: 'i-ph-warning',
317
293
  })
318
- await loadUsages()
294
+ await usagesRead.refresh()
319
295
  return
320
296
  }
321
297
  toast.add({ title: t('dms_automation.templates.deleted', { name: s.name }), color: 'success', icon: 'i-ph-check-circle' })
322
- items.value = items.value.filter((x) => x._id !== s._id)
323
- total.value = Math.max(0, total.value - 1)
324
- selectedId.value = sortedItems.value[0]?._id ?? null
325
- // Forking may have changed other templates' graphs and usage counts.
326
- void loadList()
298
+ // Gone from the list at once (the detail moves to the first template); the
299
+ // page's refresh on the templates topic reads the forked graphs and usage
300
+ // counts again.
301
+ replaceListed((rows) => rows.filter((x) => x._id !== s._id))
327
302
  }
328
303
 
329
304
  /** "1 procedure", "2 procedures and 1 template": who places the template. */
@@ -1,15 +1,5 @@
1
- <script lang="ts">
2
- interface WebhookBase {
3
- url: string
4
- configured: boolean
5
- }
6
-
7
- // Every endpoint shown is on the same origin: it is asked for once.
8
- let baseRequest: Promise<WebhookBase | null> | undefined
9
- </script>
10
-
11
1
  <script setup lang="ts">
12
- import { computed, onMounted, ref } from 'vue'
2
+ import { computed } from 'vue'
13
3
 
14
4
  // The full URL a webhook trigger is called on — the API server's public
15
5
  // origin and the trigger's path — with a copy button, and a curl example.
@@ -17,6 +7,11 @@ import { computed, onMounted, ref } from 'vue'
17
7
  // Until the origin is known, or if it can't be, no URL is offered to copy:
18
8
  // the path alone would be a wrong address to hand to another service.
19
9
 
10
+ interface WebhookBase {
11
+ url: string
12
+ configured: boolean
13
+ }
14
+
20
15
  const props = withDefaults(
21
16
  defineProps<{
22
17
  path: string
@@ -27,19 +22,14 @@ const props = withDefaults(
27
22
  { method: 'POST', apiUrl: '/api/automation', compact: false },
28
23
  )
29
24
 
30
- const { $authFetch } = useAuthFetch()
31
-
32
- const base = ref<WebhookBase | null>(null)
33
- const status = ref<'loading' | 'ready' | 'error'>('loading')
34
-
35
- onMounted(async () => {
36
- baseRequest ??= $authFetch<WebhookBase>(`${props.apiUrl}/library/webhook-base`).catch(() => {
37
- baseRequest = undefined
38
- return null
39
- })
40
- base.value = await baseRequest
41
- status.value = base.value ? 'ready' : 'error'
42
- })
25
+ // Every endpoint shown is on the same origin: the endpoints of a page share
26
+ // one read, made with the page.
27
+ const baseRead = useApiData<WebhookBase>(`${props.apiUrl}/library/webhook-base`)
28
+ const base = computed(() => baseRead.data.value)
29
+ // A failure kept while it is tried again still shows the skeleton.
30
+ const status = computed<'loading' | 'ready' | 'error'>(() =>
31
+ base.value ? 'ready' : baseRead.error.value && baseRead.status.value !== 'pending' ? 'error' : 'loading',
32
+ )
43
33
 
44
34
  const url = computed(() => `${base.value?.url ?? ''}${props.path}`)
45
35
  const method = computed(() => (props.method || 'POST').toUpperCase())
@@ -55,11 +55,10 @@ export interface PaletteBlock {
55
55
  template?: TemplateSummary;
56
56
  }
57
57
 
58
- export function useAutomationNodeKinds() {
59
- const { $authFetch } = useAuthFetch();
60
- return {
61
- async list(): Promise<NodeKindEntry[]> {
62
- return await $authFetch<NodeKindEntry[]>("/api/automation/node-kinds");
63
- },
64
- };
58
+ /**
59
+ * The node kinds and their UI metadata, read with the page: the builder's
60
+ * canvas, palette and inspector draw every block from them.
61
+ */
62
+ export function useAutomationNodeKinds(apiUrl = "/api/automation") {
63
+ return useApiData<NodeKindEntry[]>(`${apiUrl}/node-kinds`);
65
64
  }
@@ -1,3 +1,4 @@
1
+ import { type MaybeRefOrGetter, toValue } from "vue";
1
2
  import type { StepName, TriggerSummary } from "../utils/describe";
2
3
 
3
4
  export type LogLevel = "info" | "warn" | "error";
@@ -121,7 +122,7 @@ export interface RunDetail {
121
122
  procedureVersion?: number | null;
122
123
  procedureName: string;
123
124
  durationMs: number;
124
- /** The log, when the run carries it; else read with `getLogs`. */
125
+ /** The log, when the run carries it; else read with `readLogs`. */
125
126
  logs?: RunLog;
126
127
  logCount?: number;
127
128
  logTruncated?: number;
@@ -186,6 +187,12 @@ export function opensInBuilder(run: RunDetail): boolean {
186
187
  return !!run.procedure && run.kind !== "test";
187
188
  }
188
189
 
190
+ /** How a run read follows the page, as `useApiData` takes it. */
191
+ export interface RunReadOptions {
192
+ /** `false` for a read the page's refreshes leave alone. */
193
+ refreshOnPageRefresh?: boolean;
194
+ }
195
+
189
196
  /** The run endpoints the drawer, the trace and the builder share. */
190
197
  export function useAutomationRuns(apiUrl = "/api/automation") {
191
198
  const { $authFetch } = useAuthFetch();
@@ -194,12 +201,30 @@ export function useAutomationRuns(apiUrl = "/api/automation") {
194
201
  const runUrl = (id: string) => `${apiUrl}/runs/${encodeURIComponent(id)}`;
195
202
 
196
203
  return {
204
+ /** One run, read with the page: nothing while `id` is empty. */
205
+ readRun(
206
+ id: MaybeRefOrGetter<string | null | undefined>,
207
+ options?: RunReadOptions,
208
+ ) {
209
+ return useApiData<RunDetail>(() => {
210
+ const value = toValue(id);
211
+ return value ? runUrl(value) : null;
212
+ }, options);
213
+ },
214
+ /** A run's log, read while `id` is set: nothing while it is empty. */
215
+ readLogs(
216
+ id: MaybeRefOrGetter<string | null | undefined>,
217
+ options?: RunReadOptions,
218
+ ) {
219
+ return useApiData<RunLog>(() => {
220
+ const value = toValue(id);
221
+ return value ? `${runUrl(value)}/logs` : null;
222
+ }, options);
223
+ },
224
+ /** One run, for the builder's lookups chained to a click or a write. */
197
225
  getRun(id: string): Promise<RunDetail> {
198
226
  return $authFetch<RunDetail>(runUrl(id));
199
227
  },
200
- getLogs(id: string): Promise<RunLog> {
201
- return $authFetch<RunLog>(`${runUrl(id)}/logs`);
202
- },
203
228
  rerun(id: string): Promise<RerunResult> {
204
229
  return $authFetch<RerunResult>(`${runUrl(id)}/rerun`, {
205
230
  method: "POST",
@@ -16,6 +16,8 @@
16
16
  "vue": "^3.5.18"
17
17
  },
18
18
  "devDependencies": {
19
+ "@antelopejs/dms": ">=0.9.0 <1.0.0",
20
+ "@antelopejs/dms-frontend": ">=0.6.0 <0.7.0",
19
21
  "@antelopejs/tooling-configs": ">=0.0.7 <1.0.0",
20
22
  "@eslint/js": "^9.0.0",
21
23
  "@nuxt/ui": "4.10.0",
@@ -29,7 +31,7 @@
29
31
  "vue-tsc": "^3.1.1"
30
32
  },
31
33
  "engines": {
32
- "@antelopejs/dms-frontend": ">=0.5.0 <0.6.0"
34
+ "@antelopejs/dms-frontend": ">=0.6.0 <0.7.0"
33
35
  },
34
36
  "packageManager": "pnpm@10.6.5"
35
37
  }