@antelopejs/dms-database 0.3.0 → 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.
Files changed (102) hide show
  1. package/README.md +19 -7
  2. package/dist/automation/index.js.map +1 -1
  3. package/dist/automation/tableWatch.d.ts +3 -2
  4. package/dist/automation/tableWatch.js +9 -6
  5. package/dist/automation/tableWatch.js.map +1 -1
  6. package/dist/db/tables/query_history.table.d.ts +2 -1
  7. package/dist/db/tables/query_history.table.js.map +1 -1
  8. package/dist/db/tables/saved_queries.table.d.ts +2 -1
  9. package/dist/db/tables/saved_queries.table.js.map +1 -1
  10. package/dist/i18n/messages.js.map +1 -1
  11. package/dist/module.js +5 -1
  12. package/dist/module.js.map +1 -1
  13. package/dist/pages/schemas.js.map +1 -1
  14. package/dist/routes/data.d.ts +1 -1
  15. package/dist/routes/data.js +36 -237
  16. package/dist/routes/data.js.map +1 -1
  17. package/dist/routes/diagram.js +61 -42
  18. package/dist/routes/diagram.js.map +1 -1
  19. package/dist/routes/query.js +44 -46
  20. package/dist/routes/query.js.map +1 -1
  21. package/dist/routes/tables.js +13 -7
  22. package/dist/routes/tables.js.map +1 -1
  23. package/dist/service/browse.d.ts +37 -0
  24. package/dist/service/browse.js +135 -0
  25. package/dist/service/browse.js.map +1 -0
  26. package/dist/service/fieldDescriptor.d.ts +6 -6
  27. package/dist/service/fieldDescriptor.js +9 -13
  28. package/dist/service/fieldDescriptor.js.map +1 -1
  29. package/dist/service/health.js.map +1 -1
  30. package/dist/service/introspect.js +13 -12
  31. package/dist/service/introspect.js.map +1 -1
  32. package/dist/service/overview.js.map +1 -1
  33. package/dist/service/queryInspection.d.ts +4 -3
  34. package/dist/service/queryInspection.js +25 -24
  35. package/dist/service/queryInspection.js.map +1 -1
  36. package/dist/service/references.js +2 -6
  37. package/dist/service/references.js.map +1 -1
  38. package/dist/service/rowEdit.d.ts +2 -0
  39. package/dist/service/rowEdit.js +81 -0
  40. package/dist/service/rowEdit.js.map +1 -0
  41. package/dist/service/schemaFilters.d.ts +1 -1
  42. package/dist/service/schemaFilters.js.map +1 -1
  43. package/dist/service/schemaRegistry.js.map +1 -1
  44. package/dist/service/stagedSerialization.d.ts +7 -6
  45. package/dist/service/stagedSerialization.js +29 -21
  46. package/dist/service/stagedSerialization.js.map +1 -1
  47. package/dist/types/json.d.ts +8 -0
  48. package/dist/types/json.js +32 -0
  49. package/dist/types/json.js.map +1 -0
  50. package/dist/utils/guards.d.ts +7 -0
  51. package/dist/utils/guards.js +31 -0
  52. package/dist/utils/guards.js.map +1 -0
  53. package/dist/utils/query.d.ts +6 -7
  54. package/dist/utils/query.js +13 -24
  55. package/dist/utils/query.js.map +1 -1
  56. package/dist/utils/requestValidation.d.ts +1 -2
  57. package/dist/utils/requestValidation.js +4 -9
  58. package/dist/utils/requestValidation.js.map +1 -1
  59. package/frontend-vue/app/build/components/DataGridEmpty.vue +89 -0
  60. package/frontend-vue/app/build/components/DataGridFooter.vue +113 -0
  61. package/frontend-vue/app/build/components/DataGridReadOnlyBanner.vue +50 -0
  62. package/frontend-vue/app/build/components/DataGridSaveStatus.vue +73 -0
  63. package/frontend-vue/app/build/components/DataGridToolbar.vue +72 -0
  64. package/frontend-vue/app/build/components/DiagramLegend.vue +48 -0
  65. package/frontend-vue/app/build/components/DiagramSearchBar.vue +82 -0
  66. package/frontend-vue/app/build/components/DiagramStatusBar.vue +89 -0
  67. package/frontend-vue/app/build/components/DiagramToolbar.vue +102 -0
  68. package/frontend-vue/app/build/components/DiagramViewBar.vue +103 -0
  69. package/frontend-vue/app/build/components/diagramFloat.css +21 -0
  70. package/frontend-vue/app/build/composables/useDiagramDrag.ts +84 -0
  71. package/frontend-vue/app/build/composables/useDiagramNotes.ts +146 -0
  72. package/frontend-vue/app/build/composables/useDiagramSaveStatus.ts +50 -0
  73. package/frontend-vue/app/build/composables/useDiagramSearch.ts +77 -0
  74. package/frontend-vue/app/build/composables/useDiagramView.ts +125 -0
  75. package/frontend-vue/app/build/composables/useElsewhereInstances.ts +94 -0
  76. package/frontend-vue/app/build/composables/useTableSample.ts +176 -0
  77. package/frontend-vue/app/build/data/gridData.ts +66 -0
  78. package/frontend-vue/app/build/data/useStagedSave.ts +13 -20
  79. package/frontend-vue/app/build/diagram/autosave.ts +3 -3
  80. package/frontend-vue/app/build/diagram/graph.ts +67 -485
  81. package/frontend-vue/app/build/diagram/graphModel.ts +368 -0
  82. package/frontend-vue/app/build/diagram/layout.ts +135 -0
  83. package/frontend-vue/app/build/query/failures.ts +17 -0
  84. package/frontend-vue/app/components/DataGrid.vue +64 -358
  85. package/frontend-vue/app/components/QueryConsole.vue +27 -116
  86. package/frontend-vue/app/components/SchemaDiagram.vue +118 -678
  87. package/frontend-vue/app/components/TableInspector.vue +12 -136
  88. package/frontend-vue/build/backend-boundary.ts +122 -0
  89. package/frontend-vue/dms.frontend.build.ts +6 -0
  90. package/frontend-vue/package.json +3 -2
  91. package/frontend-vue/pnpm-lock.yaml +8 -5
  92. package/frontend-vue/tests/apiErrorPresentation.test.ts +83 -0
  93. package/frontend-vue/tests/backend-boundary.test.ts +134 -0
  94. package/frontend-vue/tests/clientNavigation.test.ts +5 -7
  95. package/frontend-vue/tests/fixtures/serverRender.ts +13 -1
  96. package/frontend-vue/tests/locales.test.ts +16 -89
  97. package/frontend-vue/tests/queryConsole.test.ts +20 -0
  98. package/frontend-vue/tests/registration.test.ts +0 -18
  99. package/frontend-vue/vitest.config.ts +5 -2
  100. package/package.json +23 -12
  101. package/skills/dms-database/SKILL.md +1 -1
  102. package/skills/dms-database/cases.json +48 -0
@@ -28,6 +28,7 @@ import {
28
28
  } from '../build/utils/fieldTypes'
29
29
  import { CROSS_INSTANCE_VALUE } from '../build/composables/useDataBrowserTabs'
30
30
  import { ALL_INSTANCES_PARAM, tableLink } from '../build/utils/databaseLinks'
31
+ import { useTableSample } from '../build/composables/useTableSample'
31
32
  import DrawerTabs from './DrawerTabs.vue'
32
33
 
33
34
  // The Schemas page's row drawer (D-07), also opened from the diagram: the
@@ -57,7 +58,6 @@ const NULLISH_KINDS = new Set<FieldDescriptor['kind']>([
57
58
  'any',
58
59
  'unknown',
59
60
  ])
60
- const BROWSE_LIST = '/api/database/browse/list'
61
61
  const BROWSE_COUNT = '/api/database/browse/count'
62
62
 
63
63
  const { t, n } = useI18n()
@@ -273,141 +273,17 @@ const tabs = computed<{ value: InspectorTab; label: string; badge?: number }[]>(
273
273
  ],
274
274
  )
275
275
 
276
- // --- sample row: the latest row, or the next one on demand ---
277
- interface SamplePage {
278
- results: Record<string, unknown>[]
279
- total: number
280
- }
281
-
282
- /**
283
- * The row asked for: its offset in an instance. No instance at offset 0 reads
284
- * the default one, or the first named instance holding rows when the default
285
- * one holds none.
286
- */
287
- interface SampleRequest {
288
- instance: string | null
289
- offset: number
290
- }
291
-
292
- /** A sample read, with the table and the instance it was read from. */
293
- interface SampleRead {
294
- table: string
295
- instance: string | null
296
- page: SamplePage
297
- }
298
-
299
- const requested = shallowRef<SampleRequest>({ instance: null, offset: 0 })
300
-
301
- type ReadSample = (instance: string | null) => Promise<SamplePage>
302
-
303
- async function firstFilledInstance(
304
- read: ReadSample,
305
- ): Promise<{ instance: string | null; page: SamplePage }> {
306
- const page = await read(null)
307
- if (page.total > 0) return { instance: null, page }
308
- for (const instance of schema.value?.instances ?? []) {
309
- const named = await read(instance)
310
- if (named.total > 0) return { instance, page: named }
311
- }
312
- return { instance: null, page }
313
- }
314
-
315
- // Read once the Sample tab shows, in the browser only.
316
- const sampleRead = useApiData<SampleRead>(
317
- () =>
318
- schemaId.value && tableName.value
319
- ? `dms-database:sample:${JSON.stringify([
320
- tableKey.value,
321
- requested.value.instance,
322
- requested.value.offset,
323
- ])}`
324
- : null,
325
- async ({ $authFetch, signal }) => {
326
- const table = tableKey.value
327
- const { instance, offset } = requested.value
328
- const read: ReadSample = (from) =>
329
- $authFetch<SamplePage>(BROWSE_LIST, {
330
- query: {
331
- filter_schema: `is:${schemaId.value}`,
332
- filter_table: `is:${tableName.value}`,
333
- offset,
334
- limit: 1,
335
- ...(from ? { filter_instance: `is:${from}` } : {}),
336
- },
337
- signal,
338
- })
339
- const found =
340
- instance === null && offset === 0
341
- ? await firstFilledInstance(read)
342
- : { instance, page: await read(instance) }
343
- return { table, ...found }
344
- },
345
- {
346
- immediate: false,
347
- server: false,
348
- watch: false,
349
- refreshOnPageRefresh: false,
350
- },
351
- )
352
-
353
- // Another table (a relation followed) shows none of the previous one's row.
354
- const sampleShown = computed(() => {
355
- const value = sampleRead.data.value
356
- return value?.table === tableKey.value ? value : null
357
- })
358
- const sample = computed(() => sampleShown.value?.page.results?.[0] ?? null)
359
- const sampleTotal = computed(() => sampleShown.value?.page.total ?? 0)
360
- const sampleOffset = computed(() => requested.value.offset)
361
- const sampleLoading = computed(() => sampleRead.pending.value)
362
- const sampleFailed = computed(() => sampleRead.status.value === 'error')
363
- // The instance the sample is read from.
364
- const sampleInstance = computed(() => sampleShown.value?.instance ?? null)
365
-
366
- const sampleInstanceLabel = computed(() =>
367
- sampleInstance.value === null
368
- ? t('dms_database.inspector.sample.default_instance')
369
- : t('dms_database.inspector.sample.named_instance', {
370
- name: sampleInstance.value,
371
- }),
372
- )
373
-
374
- function loadSample() {
375
- if (schemaId.value && tableName.value) void sampleRead.execute()
376
- }
377
-
378
- function nextSample() {
379
- const total = sampleTotal.value
380
- requested.value = {
381
- instance: sampleInstance.value,
382
- offset: total > 0 ? (requested.value.offset + 1) % total : 0,
383
- }
384
- loadSample()
385
- }
386
-
387
- // Another table (a relation followed) starts over from its latest row.
388
- watch(tableKey, () => {
389
- requested.value = { instance: null, offset: 0 }
390
- if (tab.value === 'sample' && !loading.value) loadSample()
391
- })
392
-
393
- // The sample waits for the schemas: they name the instances to look in.
394
- onMounted(() =>
395
- watch(
396
- () => tab.value === 'sample' && !loading.value,
397
- (ready) => {
398
- if (ready && !sample.value && !sampleLoading.value) loadSample()
399
- },
400
- { immediate: true },
401
- ),
402
- )
403
-
404
- // The `_instance` tag the store adds to rows of named instances is not a
405
- // column of the table.
406
- const sampleJson = computed(() => {
407
- if (!sample.value) return ''
408
- const { _instance: _tag, ...row } = sample.value
409
- return JSON.stringify(row, null, 2)
410
- })
276
+ const {
277
+ sample,
278
+ sampleTotal,
279
+ sampleOffset,
280
+ sampleLoading,
281
+ sampleFailed,
282
+ sampleInstanceLabel,
283
+ sampleJson,
284
+ loadSample,
285
+ nextSample,
286
+ } = useTableSample({ schemaId, tableName, tableKey, schema, tab, loading })
411
287
 
412
288
  async function copyName() {
413
289
  await copy(tableName.value)
@@ -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-database'
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
+ }
@@ -0,0 +1,6 @@
1
+ import { defineDmsFrontendBuild } from '#dms/frontend-build'
2
+ import { backendBoundary } from './build/backend-boundary.ts'
3
+
4
+ export default defineDmsFrontendBuild((build) => {
5
+ build.registerVitePlugins(() => [backendBoundary()])
6
+ })
@@ -6,7 +6,7 @@
6
6
  "main": "./dms.frontend.ts",
7
7
  "packageManager": "pnpm@10.6.5",
8
8
  "engines": {
9
- "@antelopejs/dms-frontend": ">=0.8.0 <0.9.0"
9
+ "@antelopejs/dms-frontend": ">=0.9.1 <0.10.0"
10
10
  },
11
11
  "scripts": {
12
12
  "dev": "pnpm --dir ../playground frontend:dev",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@antelopejs/interface-core": ">=0.2.4 <1.0.0",
22
- "@antelopejs/interface-database": ">=0.1.10 <1.0.0",
22
+ "@antelopejs/interface-database": ">=0.1.11 <1.0.0",
23
23
  "@codemirror/autocomplete": "^6.18.6",
24
24
  "@codemirror/commands": "^6.8.1",
25
25
  "@codemirror/lang-javascript": "^6.2.4",
@@ -42,6 +42,7 @@
42
42
  "prettier": "^3.5.3",
43
43
  "prettier-plugin-tailwindcss": "^0.6.11",
44
44
  "typescript": "^5.8.2",
45
+ "vite": "^7.3.3",
45
46
  "vitest": "^3.2.4"
46
47
  }
47
48
  }
@@ -12,8 +12,8 @@ importers:
12
12
  specifier: '>=0.2.4 <1.0.0'
13
13
  version: 0.2.4
14
14
  '@antelopejs/interface-database':
15
- specifier: '>=0.1.10 <1.0.0'
16
- version: 0.1.10(@antelopejs/interface-core@0.2.4)
15
+ specifier: '>=0.1.11 <1.0.0'
16
+ version: 0.1.11(@antelopejs/interface-core@0.2.4)
17
17
  '@codemirror/autocomplete':
18
18
  specifier: ^6.18.6
19
19
  version: 6.20.3
@@ -75,6 +75,9 @@ importers:
75
75
  typescript:
76
76
  specifier: ^5.8.2
77
77
  version: 5.9.3
78
+ vite:
79
+ specifier: ^7.3.3
80
+ version: 7.3.3(@types/node@25.7.0)(jiti@2.7.0)(lightningcss@1.32.0)(terser@5.47.1)(yaml@2.9.0)
78
81
  vitest:
79
82
  specifier: ^3.2.4
80
83
  version: 3.2.7(@types/node@25.7.0)(jiti@2.7.0)(lightningcss@1.32.0)(terser@5.47.1)(yaml@2.9.0)
@@ -88,8 +91,8 @@ packages:
88
91
  '@antelopejs/interface-core@0.2.4':
89
92
  resolution: {integrity: sha512-2qF6/KwahCQvvNuC/piUvPWD4wq2Npmco941HMg2/bMBoJKbhMH16WcXXRvPYznNSkU0U+6vqK6KE+2N5NojSA==}
90
93
 
91
- '@antelopejs/interface-database@0.1.10':
92
- resolution: {integrity: sha512-sT46GoSXvFTJpXA94toK1B3V+9YmZxjhyyCLhFNtvbijCehdtJCWILb3CbEnrWIWrlj/NPAKZ6ayH+wxUIdRWw==}
94
+ '@antelopejs/interface-database@0.1.11':
95
+ resolution: {integrity: sha512-uv6mB1Lghmlc9z+oWzntmzD1ZNBAmrj+2+7MItv6zClEolbqw5hfAt8+c3IPq2yLfWDfhpqWme2m0eTwsAm0RQ==}
93
96
  peerDependencies:
94
97
  '@antelopejs/interface-core': '>=0.2.4 <1.0.0'
95
98
 
@@ -3089,7 +3092,7 @@ snapshots:
3089
3092
  dependencies:
3090
3093
  reflect-metadata: 0.2.2
3091
3094
 
3092
- '@antelopejs/interface-database@0.1.10(@antelopejs/interface-core@0.2.4)':
3095
+ '@antelopejs/interface-database@0.1.11(@antelopejs/interface-core@0.2.4)':
3093
3096
  dependencies:
3094
3097
  '@antelopejs/interface-core': 0.2.4
3095
3098
 
@@ -0,0 +1,83 @@
1
+ import { afterEach, expect, it, vi } from 'vitest'
2
+ import * as vue from 'vue'
3
+ import { useApiErrorPresenter } from '#dms-core/app/composables/useApiErrorPresenter'
4
+ import { useDiagramSaveStatus } from '../app/build/composables/useDiagramSaveStatus'
5
+ import { DiagramSync } from '../app/build/diagram/sync'
6
+ import { DiagramAutosave } from '../app/build/diagram/autosave'
7
+
8
+ afterEach(() => vi.unstubAllGlobals())
9
+
10
+ it.each([false, true])(
11
+ 'shows one translated warning for a refused diagram save (already presented %s)',
12
+ async (alreadyPresented) => {
13
+ for (const [name, value] of Object.entries(vue)) vi.stubGlobal(name, value)
14
+ const data = { message: 'error.read_only_demo', severity: 'warning' }
15
+ const error = Object.assign(new Error('Forbidden'), {
16
+ data,
17
+ response: new Response(JSON.stringify(data), {
18
+ status: 403,
19
+ headers: { 'content-type': 'application/json' },
20
+ }),
21
+ })
22
+ const messages = new Map([
23
+ ['error.read_only_demo', 'This demo is read-only.'],
24
+ ['dms_database.diagram.save.error_other', 'Could not save the diagram.'],
25
+ ])
26
+ const notices: { title: string; color: string }[] = []
27
+ vi.stubGlobal('useToast', () => ({
28
+ add: (notice: (typeof notices)[number]) => {
29
+ notices.push(notice)
30
+ return { id: notices.length }
31
+ },
32
+ }))
33
+ vi.stubGlobal('getPluginI18n', () => ({
34
+ i18n: {
35
+ tm: (key: string) => messages.get(key),
36
+ rt: (text: string) => text,
37
+ },
38
+ }))
39
+ const presented = vue.ref(new WeakMap())
40
+ vi.stubGlobal('useDmsState', () => presented)
41
+ vi.stubGlobal('useApiErrorPresenter', useApiErrorPresenter)
42
+ vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
43
+ const core = useApiErrorPresenter()
44
+ const owner = new DiagramSync(
45
+ {
46
+ saveLayout: async () => {
47
+ if (alreadyPresented)
48
+ core.presentError(error, { fallbackKey: 'error.500.description' })
49
+ throw error
50
+ },
51
+ createNote: async () => {
52
+ throw new Error('not used')
53
+ },
54
+ updateNote: async () => {
55
+ throw new Error('not used')
56
+ },
57
+ deleteNote: async () => undefined,
58
+ },
59
+ 'demo',
60
+ )
61
+ const scope = vue.effectScope()
62
+ try {
63
+ const status = scope.run(() => useDiagramSaveStatus(() => null))
64
+ if (!status) throw new Error('Missing save status')
65
+ const autosave = new DiagramAutosave(
66
+ owner,
67
+ () => ({ positions: { orders: { x: 12, y: 24 } }, notes: [] }),
68
+ 10,
69
+ status.statusReporter(owner),
70
+ )
71
+ autosave.schedule()
72
+ await autosave.flush()
73
+ expect(notices).toEqual([
74
+ expect.objectContaining({
75
+ title: 'This demo is read-only.',
76
+ color: 'warning',
77
+ }),
78
+ ])
79
+ } finally {
80
+ scope.stop()
81
+ }
82
+ },
83
+ )
@@ -0,0 +1,134 @@
1
+ import {
2
+ mkdirSync,
3
+ mkdtempSync,
4
+ rmSync,
5
+ symlinkSync,
6
+ writeFileSync,
7
+ } from 'node:fs'
8
+ import { tmpdir } from 'node:os'
9
+ import { join } from 'node:path'
10
+ import { build, type Plugin } from 'vite'
11
+ import { afterEach, beforeEach, expect, it } from 'vitest'
12
+ import { backendBoundary } from '../build/backend-boundary.ts'
13
+
14
+ const BOUNDARY = 'Backend boundary: '
15
+
16
+ let root: string
17
+ beforeEach(() => {
18
+ root = mkdtempSync(join(tmpdir(), 'dms-database-boundary-'))
19
+ mkdirSync(join(root, 'backend/src'), { recursive: true })
20
+ mkdirSync(join(root, 'backend/dist'), { recursive: true })
21
+ mkdirSync(join(root, 'frontend'), { recursive: true })
22
+ writeFileSync(
23
+ join(root, 'backend/package.json'),
24
+ JSON.stringify({ name: '@antelopejs/dms-database' }),
25
+ )
26
+ writeFileSync(join(root, 'backend/src/api.ts'), 'export const api = 1\n')
27
+ writeFileSync(join(root, 'backend/dist/api.ts'), 'export const api = 2\n')
28
+ })
29
+ afterEach(() => rmSync(root, { recursive: true, force: true }))
30
+
31
+ function bundle(entry: string, extra: Plugin[] = []) {
32
+ writeFileSync(join(root, 'frontend/entry.ts'), entry)
33
+ return build({
34
+ root,
35
+ logLevel: 'silent',
36
+ configFile: false,
37
+ plugins: [backendBoundary(), ...extra],
38
+ build: {
39
+ write: false,
40
+ lib: { entry: join(root, 'frontend/entry.ts'), formats: ['es'] },
41
+ },
42
+ })
43
+ }
44
+
45
+ it('fails on an import of the backend source and names both files', async () => {
46
+ const failing = bundle(
47
+ 'import { api } from "../backend/src/api"\nexport default api\n',
48
+ )
49
+ await expect(failing).rejects.toThrow(BOUNDARY)
50
+ await expect(failing).rejects.toThrow(join(root, 'frontend/entry.ts'))
51
+ await expect(failing).rejects.toThrow(join(root, 'backend/src/api.ts'))
52
+ })
53
+
54
+ it('fails on an import nested below the backend source', async () => {
55
+ mkdirSync(join(root, 'backend/src/x/y'), { recursive: true })
56
+ writeFileSync(
57
+ join(root, 'backend/src/x/y/deep.ts'),
58
+ 'export const deep = 1\n',
59
+ )
60
+ const failing = bundle(
61
+ 'import { deep } from "../backend/src/x/y/deep"\nexport default deep\n',
62
+ )
63
+ await expect(failing).rejects.toThrow(BOUNDARY)
64
+ await expect(failing).rejects.toThrow(join(root, 'backend/src/x/y/deep.ts'))
65
+ })
66
+
67
+ it('accepts a backend directory that only starts with src', async () => {
68
+ mkdirSync(join(root, 'backend/srcx'), { recursive: true })
69
+ writeFileSync(join(root, 'backend/srcx/api.ts'), 'export const api = 4\n')
70
+ await expect(
71
+ bundle('import { api } from "../backend/srcx/api"\nexport default api\n'),
72
+ ).resolves.toBeDefined()
73
+ })
74
+
75
+ it('accepts another file of the backend package', async () => {
76
+ await expect(
77
+ bundle('import { api } from "../backend/dist/api"\nexport default api\n'),
78
+ ).resolves.toBeDefined()
79
+ })
80
+
81
+ it('ignores a virtual module', async () => {
82
+ const virtual: Plugin = {
83
+ name: 'virtual-fixture',
84
+ resolveId: (source) => (source === 'virtual:fixture' ? '\0fixture' : null),
85
+ load: (id) => (id === '\0fixture' ? 'export default 1' : null),
86
+ }
87
+ await expect(
88
+ bundle('import one from "virtual:fixture"\nexport default one\n', [
89
+ virtual,
90
+ ]),
91
+ ).resolves.toBeDefined()
92
+ })
93
+
94
+ function resolvingTo(target: () => string): Plugin {
95
+ return {
96
+ name: 'fixture-resolver',
97
+ resolveId: (source) => (source === 'fixture:target' ? target() : null),
98
+ }
99
+ }
100
+
101
+ const IMPORT_TARGET =
102
+ 'import { api } from "fixture:target"\nexport default api\n'
103
+
104
+ it('follows a symlink the resolver returns to the backend source', async () => {
105
+ symlinkSync(
106
+ join(root, 'backend/src/api.ts'),
107
+ join(root, 'frontend/linked.ts'),
108
+ )
109
+ const failing = bundle(IMPORT_TARGET, [
110
+ resolvingTo(() => join(root, 'frontend/linked.ts')),
111
+ ])
112
+ await expect(failing).rejects.toThrow(BOUNDARY)
113
+ await expect(failing).rejects.toThrow(join(root, 'backend/src/api.ts'))
114
+ })
115
+
116
+ it('sees through a query on the resolved id', async () => {
117
+ const failing = bundle(IMPORT_TARGET, [
118
+ resolvingTo(() => `${join(root, 'backend/src/api.ts')}?raw`),
119
+ ])
120
+ await expect(failing).rejects.toThrow(BOUNDARY)
121
+ await expect(failing).rejects.toThrow(join(root, 'backend/src/api.ts'))
122
+ })
123
+
124
+ it('lets the owning package decide, not the directory name', async () => {
125
+ mkdirSync(join(root, 'other/src'), { recursive: true })
126
+ writeFileSync(
127
+ join(root, 'other/package.json'),
128
+ JSON.stringify({ name: '@acme/other' }),
129
+ )
130
+ writeFileSync(join(root, 'other/src/api.ts'), 'export const api = 3\n')
131
+ await expect(
132
+ bundle('import { api } from "../other/src/api"\nexport default api\n'),
133
+ ).resolves.toBeDefined()
134
+ })
@@ -1,14 +1,8 @@
1
- import { describe, expect, it, vi } from 'vitest'
1
+ import { describe, expect, it } from 'vitest'
2
2
  import { browserMount, type BackendRead } from './fixtures/serverRender'
3
3
  import ConnectionStatus from '../app/components/ConnectionStatus.vue'
4
4
  import QueryConsole from '../app/components/QueryConsole.vue'
5
5
 
6
- // The CodeMirror editor mounts on a real DOM, which this mount has not; it
7
- // reads nothing and does not decide when the page lands.
8
- vi.mock('../app/components/QueryBuilderPanel.vue', () => ({
9
- default: { name: 'QueryBuilderPanel', render: () => null },
10
- }))
11
-
12
6
  // A client navigation shows a page once its components' setups settle: the
13
7
  // reads that decide a component's size are awaited there, so the page lands
14
8
  // with them rather than growing (or swapping placeholders) after it.
@@ -74,6 +68,7 @@ describe('client navigation: the page lands with what decides its size', () => {
74
68
  backend.release()
75
69
  await page.shown
76
70
  expect(page.text()).toContain('MongoDB')
71
+ expect(page.errors).toEqual([])
77
72
  })
78
73
 
79
74
  it('query console: the first run examples and the library', async () => {
@@ -89,5 +84,8 @@ describe('client navigation: the page lands with what decides its size', () => {
89
84
  // The examples of the first schema's tables are in the empty result.
90
85
  expect(page.text()).toContain('first_description')
91
86
  expect(page.text()).toContain('shop.orders')
87
+ // The CodeMirror editor mounts on a real DOM, which this mount has not.
88
+ expect(page.errors).toHaveLength(1)
89
+ expect(String(page.errors[0])).toContain('document is not defined')
92
90
  })
93
91
  })
@@ -57,6 +57,12 @@ vi.stubGlobal('useDmsRoute', engine.useDmsRoute)
57
57
  vi.stubGlobal('useDmsRouter', engine.useDmsRouter)
58
58
  const { useApiData } = await import('#dms-core/app/composables/auth/useApiData')
59
59
  vi.stubGlobal('useApiData', useApiData)
60
+ const { useApiErrorPresenter } =
61
+ await import('#dms-core/app/composables/useApiErrorPresenter')
62
+ vi.stubGlobal('useApiErrorPresenter', useApiErrorPresenter)
63
+ vi.stubGlobal('getPluginI18n', () => ({
64
+ i18n: { tm: (key: string) => key, rt: (text: string) => text },
65
+ }))
60
66
  // `useFetchAuth`: the former name of `useApiData`.
61
67
  vi.stubGlobal('useAuthFetch', () => ({ $authFetch, useFetchAuth: useApiData }))
62
68
  vi.stubGlobal('useI18n', () => ({
@@ -217,6 +223,8 @@ export interface BrowserMount {
217
223
  /** What the component shows now (`''` while the navigation waits). */
218
224
  text: () => string
219
225
  reads: BackendRead[]
226
+ /** What the mounted components threw outside a test's own calls. */
227
+ errors: unknown[]
220
228
  }
221
229
 
222
230
  /**
@@ -249,9 +257,13 @@ export function browserMount(
249
257
  app.component('DmsClientOnly', engine.DmsClientOnly)
250
258
  for (const name of UI_COMPONENTS) app.component(name, uiStub(name))
251
259
  app.config.warnHandler = noop
260
+ const errors: unknown[] = []
261
+ app.config.errorHandler = (error) => {
262
+ errors.push(error)
263
+ }
252
264
  const root = mountNode({ tag: 'root' })
253
265
  app.mount(root)
254
- return { shown, text: () => mountText(root), reads }
266
+ return { shown, text: () => mountText(root), reads, errors }
255
267
  }
256
268
 
257
269
  export interface ServerRender {