@antelopejs/dms-database 0.3.1 → 0.4.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.
- package/README.md +17 -10
- package/dist/automation/index.js.map +1 -1
- package/dist/automation/tableWatch.d.ts +8 -4
- package/dist/automation/tableWatch.js +35 -8
- package/dist/automation/tableWatch.js.map +1 -1
- package/dist/db/models/diagram_layouts.model.d.ts +7 -5
- package/dist/db/models/diagram_notes.model.d.ts +7 -5
- package/dist/db/models/query_history.model.d.ts +7 -5
- package/dist/db/models/saved_queries.model.d.ts +7 -5
- package/dist/db/tables/query_history.table.d.ts +2 -1
- package/dist/db/tables/query_history.table.js.map +1 -1
- package/dist/db/tables/saved_queries.table.d.ts +2 -1
- package/dist/db/tables/saved_queries.table.js.map +1 -1
- package/dist/i18n/messages.js +5 -2
- package/dist/i18n/messages.js.map +1 -1
- package/dist/module.js +5 -1
- package/dist/module.js.map +1 -1
- package/dist/pages/schemas.js.map +1 -1
- package/dist/routes/data.d.ts +4 -3
- package/dist/routes/data.js +37 -238
- package/dist/routes/data.js.map +1 -1
- package/dist/routes/diagram.js +64 -43
- package/dist/routes/diagram.js.map +1 -1
- package/dist/routes/query.js +51 -53
- package/dist/routes/query.js.map +1 -1
- package/dist/routes/tables.js +13 -7
- package/dist/routes/tables.js.map +1 -1
- package/dist/service/browse.d.ts +37 -0
- package/dist/service/browse.js +135 -0
- package/dist/service/browse.js.map +1 -0
- package/dist/service/fieldDescriptor.d.ts +6 -6
- package/dist/service/fieldDescriptor.js +56 -50
- package/dist/service/fieldDescriptor.js.map +1 -1
- package/dist/service/health.js.map +1 -1
- package/dist/service/introspect.js +45 -40
- package/dist/service/introspect.js.map +1 -1
- package/dist/service/overview.js.map +1 -1
- package/dist/service/queryInspection.d.ts +5 -4
- package/dist/service/queryInspection.js +28 -26
- package/dist/service/queryInspection.js.map +1 -1
- package/dist/service/references.d.ts +1 -1
- package/dist/service/references.js +3 -7
- package/dist/service/references.js.map +1 -1
- package/dist/service/rowEdit.d.ts +4 -0
- package/dist/service/rowEdit.js +80 -0
- package/dist/service/rowEdit.js.map +1 -0
- package/dist/service/schemaFilters.d.ts +1 -1
- package/dist/service/schemaFilters.js.map +1 -1
- package/dist/service/schemaLabels.js +1 -1
- package/dist/service/schemaLabels.js.map +1 -1
- package/dist/service/schemaRegistry.d.ts +1 -1
- package/dist/service/schemaRegistry.js +1 -1
- package/dist/service/schemaRegistry.js.map +1 -1
- package/dist/service/stagedSerialization.d.ts +7 -6
- package/dist/service/stagedSerialization.js +40 -32
- package/dist/service/stagedSerialization.js.map +1 -1
- package/dist/service/types.d.ts +3 -2
- package/dist/types/json.d.ts +8 -0
- package/dist/types/json.js +53 -0
- package/dist/types/json.js.map +1 -0
- package/dist/utils/guards.d.ts +8 -0
- package/dist/utils/guards.js +35 -0
- package/dist/utils/guards.js.map +1 -0
- package/dist/utils/query.d.ts +6 -7
- package/dist/utils/query.js +22 -30
- package/dist/utils/query.js.map +1 -1
- package/dist/utils/requestValidation.d.ts +1 -2
- package/dist/utils/requestValidation.js +4 -9
- package/dist/utils/requestValidation.js.map +1 -1
- package/frontend-vue/app/build/components/DataGridEmpty.vue +89 -0
- package/frontend-vue/app/build/components/DataGridFooter.vue +113 -0
- package/frontend-vue/app/build/components/DataGridReadOnlyBanner.vue +50 -0
- package/frontend-vue/app/build/components/DataGridSaveStatus.vue +73 -0
- package/frontend-vue/app/build/components/DataGridToolbar.vue +72 -0
- package/frontend-vue/app/build/components/DiagramLegend.vue +48 -0
- package/frontend-vue/app/build/components/DiagramSearchBar.vue +82 -0
- package/frontend-vue/app/build/components/DiagramStatusBar.vue +89 -0
- package/frontend-vue/app/build/components/DiagramToolbar.vue +102 -0
- package/frontend-vue/app/build/components/DiagramViewBar.vue +103 -0
- package/frontend-vue/app/build/components/diagramFloat.css +21 -0
- package/frontend-vue/app/build/composables/useDiagramDrag.ts +84 -0
- package/frontend-vue/app/build/composables/useDiagramNotes.ts +146 -0
- package/frontend-vue/app/build/composables/useDiagramSaveStatus.ts +50 -0
- package/frontend-vue/app/build/composables/useDiagramSearch.ts +77 -0
- package/frontend-vue/app/build/composables/useDiagramView.ts +125 -0
- package/frontend-vue/app/build/composables/useElsewhereInstances.ts +94 -0
- package/frontend-vue/app/build/composables/useTableSample.ts +176 -0
- package/frontend-vue/app/build/data/gridData.ts +66 -0
- package/frontend-vue/app/build/data/useStagedSave.ts +13 -20
- package/frontend-vue/app/build/diagram/autosave.ts +3 -3
- package/frontend-vue/app/build/diagram/graph.ts +67 -485
- package/frontend-vue/app/build/diagram/graphModel.ts +368 -0
- package/frontend-vue/app/build/diagram/layout.ts +135 -0
- package/frontend-vue/app/build/query/failures.ts +17 -0
- package/frontend-vue/app/components/DataGrid.vue +64 -358
- package/frontend-vue/app/components/QueryConsole.vue +27 -116
- package/frontend-vue/app/components/SchemaDiagram.vue +118 -678
- package/frontend-vue/app/components/TableInspector.vue +12 -136
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +6 -0
- package/frontend-vue/package.json +46 -45
- package/frontend-vue/pnpm-lock.yaml +51 -16
- package/frontend-vue/tests/apiErrorPresentation.test.ts +83 -0
- package/frontend-vue/tests/backend-boundary.test.ts +134 -0
- package/frontend-vue/tests/clientNavigation.test.ts +5 -7
- package/frontend-vue/tests/fixtures/serverRender.ts +13 -1
- package/frontend-vue/tests/locales.test.ts +16 -89
- package/frontend-vue/tests/queryConsole.test.ts +20 -0
- package/frontend-vue/tests/registration.test.ts +0 -18
- package/frontend-vue/vitest.config.ts +5 -2
- package/package.json +28 -17
- package/skills/dms-database/cases.json +48 -0
|
@@ -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
|
|
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 {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { readdirSync, readFileSync } from 'node:fs'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
1
|
import { baseCompile } from '@intlify/message-compiler'
|
|
4
2
|
import { describe, expect, it } from 'vitest'
|
|
5
3
|
|
|
@@ -7,10 +5,13 @@ import { describe, expect, it } from 'vitest'
|
|
|
7
5
|
// `}` or `|` then fails at runtime, on the page that shows it (S-1). Compile
|
|
8
6
|
// every message of every locale here instead; literals go through `{'@'}`.
|
|
9
7
|
|
|
10
|
-
const LOCALES_DIR = join(import.meta.dirname, '../i18n/locales')
|
|
11
|
-
|
|
12
8
|
type Messages = { [key: string]: string | Messages }
|
|
13
9
|
|
|
10
|
+
const locales = import.meta.glob<Messages>('../i18n/locales/*.json', {
|
|
11
|
+
eager: true,
|
|
12
|
+
import: 'default',
|
|
13
|
+
})
|
|
14
|
+
|
|
14
15
|
function leaves(messages: Messages, prefix = ''): [string, string][] {
|
|
15
16
|
return Object.entries(messages).flatMap(([key, value]) => {
|
|
16
17
|
const path = prefix ? `${prefix}.${key}` : key
|
|
@@ -27,23 +28,21 @@ function compileErrors(message: string): string[] {
|
|
|
27
28
|
return errors
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
const files = readdirSync(LOCALES_DIR).filter((file) => file.endsWith('.json'))
|
|
31
|
-
|
|
32
31
|
describe('locale messages', () => {
|
|
33
32
|
it('finds the locale files', () => {
|
|
34
|
-
expect(
|
|
33
|
+
expect(Object.keys(locales).length).toBeGreaterThan(0)
|
|
35
34
|
})
|
|
36
35
|
|
|
37
|
-
it.each(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
it.each(Object.entries(locales))(
|
|
37
|
+
'compiles every message of %s',
|
|
38
|
+
(_file, messages) => {
|
|
39
|
+
const failures = leaves(messages)
|
|
40
|
+
.map(([key, message]) => ({ key, errors: compileErrors(message) }))
|
|
41
|
+
.filter((entry) => entry.errors.length > 0)
|
|
42
|
+
.map((entry) => `${entry.key}: ${entry.errors.join(', ')}`)
|
|
43
|
+
expect(failures).toEqual([])
|
|
44
|
+
},
|
|
45
|
+
)
|
|
47
46
|
|
|
48
47
|
it('reports an unescaped linked-message sign', () => {
|
|
49
48
|
expect(compileErrors('declares tables with @RegisterTable.')).not.toEqual(
|
|
@@ -54,75 +53,3 @@ describe('locale messages', () => {
|
|
|
54
53
|
)
|
|
55
54
|
})
|
|
56
55
|
})
|
|
57
|
-
|
|
58
|
-
// `<i18n-t>` looks for its component's own messages first; the module's
|
|
59
|
-
// components have none, and vue-i18n warns on each page that renders one
|
|
60
|
-
// ("Not found parent scope"). The module's messages are global: say so.
|
|
61
|
-
const COMPONENTS_DIR = join(import.meta.dirname, '../app')
|
|
62
|
-
|
|
63
|
-
function vueFiles(dir: string): string[] {
|
|
64
|
-
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
65
|
-
const path = join(dir, entry.name)
|
|
66
|
-
if (entry.isDirectory()) return vueFiles(path)
|
|
67
|
-
return entry.name.endsWith('.vue') ? [path] : []
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
describe('translated templates', () => {
|
|
72
|
-
it('reads every <i18n-t> from the global messages', () => {
|
|
73
|
-
const unscoped = vueFiles(COMPONENTS_DIR).flatMap((file) =>
|
|
74
|
-
(readFileSync(file, 'utf8').match(/<i18n-t\b[^>]*>/g) ?? [])
|
|
75
|
-
.filter((tag) => !/\sscope="global"/.test(tag))
|
|
76
|
-
.map((tag) => `${file.slice(COMPONENTS_DIR.length)}: ${tag}`),
|
|
77
|
-
)
|
|
78
|
-
expect(unscoped).toEqual([])
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
// The backend pages name their texts by key: a key left behind in a page, or
|
|
83
|
-
// a page block whose keys were dropped, shows the raw `$dms_database...` path.
|
|
84
|
-
const PAGES_DIR = join(import.meta.dirname, '../../src/pages')
|
|
85
|
-
|
|
86
|
-
function resolves(messages: Messages, key: string): boolean {
|
|
87
|
-
let node: string | Messages | undefined = messages
|
|
88
|
-
for (const part of key.split('.')) {
|
|
89
|
-
if (typeof node !== 'object') return false
|
|
90
|
-
node = node[part]
|
|
91
|
-
}
|
|
92
|
-
return typeof node === 'string'
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
describe('page texts', () => {
|
|
96
|
-
const pageKeys = readdirSync(PAGES_DIR)
|
|
97
|
-
.filter((file) => file.endsWith('.ts'))
|
|
98
|
-
.flatMap((file) => [
|
|
99
|
-
...readFileSync(join(PAGES_DIR, file), 'utf8').matchAll(
|
|
100
|
-
/"\$(dms_database\.[\w.]+)"/g,
|
|
101
|
-
),
|
|
102
|
-
])
|
|
103
|
-
.map(([, key]) => key)
|
|
104
|
-
|
|
105
|
-
it('finds the keys of the pages', () => {
|
|
106
|
-
expect(pageKeys.length).toBeGreaterThan(0)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it.each(files)('translates every key the pages name in %s', (file) => {
|
|
110
|
-
const messages = JSON.parse(
|
|
111
|
-
readFileSync(join(LOCALES_DIR, file), 'utf8'),
|
|
112
|
-
) as Messages
|
|
113
|
-
expect(pageKeys.filter((key) => !resolves(messages, key))).toEqual([])
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('shows no beta notice on the overview', () => {
|
|
117
|
-
const overview = readFileSync(join(PAGES_DIR, 'overview.ts'), 'utf8')
|
|
118
|
-
expect(overview).not.toMatch(/\bBanner\(/)
|
|
119
|
-
for (const file of files) {
|
|
120
|
-
const messages = JSON.parse(
|
|
121
|
-
readFileSync(join(LOCALES_DIR, file), 'utf8'),
|
|
122
|
-
) as Messages
|
|
123
|
-
expect(resolves(messages, 'dms_database.overview.beta.title')).toBe(
|
|
124
|
-
false,
|
|
125
|
-
)
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
})
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
QUERY_METHODS,
|
|
12
12
|
} from '../app/build/query/completion'
|
|
13
13
|
import { latestOrderField } from '../app/build/query/examples'
|
|
14
|
+
import { sqlFailure } from '../app/build/query/failures'
|
|
14
15
|
import {
|
|
15
16
|
closestName,
|
|
16
17
|
replaceName,
|
|
@@ -94,6 +95,25 @@ describe('unknown names', () => {
|
|
|
94
95
|
})
|
|
95
96
|
|
|
96
97
|
describe('query runtime errors', () => {
|
|
98
|
+
it('keeps SQL diagnostics inline but leaves transport failures to the presenter', () => {
|
|
99
|
+
expect(
|
|
100
|
+
sqlFailure({
|
|
101
|
+
statusCode: 400,
|
|
102
|
+
data: { message: 'Unknown table "oders"', durationMs: 7 },
|
|
103
|
+
}),
|
|
104
|
+
).toEqual({ message: 'Unknown table "oders"', durationMs: 7 })
|
|
105
|
+
expect(
|
|
106
|
+
sqlFailure({ statusCode: 400, data: 'Cannot measure this mutation' }),
|
|
107
|
+
).toEqual({ message: 'Cannot measure this mutation', durationMs: null })
|
|
108
|
+
expect(
|
|
109
|
+
sqlFailure({
|
|
110
|
+
statusCode: 403,
|
|
111
|
+
data: { message: 'error.read_only_demo', severity: 'warning' },
|
|
112
|
+
}),
|
|
113
|
+
).toBeNull()
|
|
114
|
+
expect(sqlFailure(new Error('Network error'))).toBeNull()
|
|
115
|
+
})
|
|
116
|
+
|
|
97
117
|
it('names an unknown schema', () => {
|
|
98
118
|
let error: unknown
|
|
99
119
|
try {
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { expect, it, vi } from 'vitest'
|
|
2
|
-
import { readFileSync } from 'node:fs'
|
|
3
2
|
import frontendModule from '../dms.frontend'
|
|
4
3
|
|
|
5
|
-
function source(path: string): string {
|
|
6
|
-
return readFileSync(new URL(path, import.meta.url), 'utf8')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
4
|
it('registers every component under the module prefix the backend names', async () => {
|
|
10
5
|
const registerComponent = vi.fn()
|
|
11
6
|
const registerPage = vi.fn()
|
|
@@ -37,16 +32,3 @@ it('registers every component under the module prefix the backend names', async
|
|
|
37
32
|
expect(names.every((name) => !name.startsWith('Dms'))).toBe(true)
|
|
38
33
|
expect(new Set(names).size).toBe(names.length)
|
|
39
34
|
})
|
|
40
|
-
|
|
41
|
-
it('names every custom component the backend pages render', () => {
|
|
42
|
-
const backend = ['overview', 'schemas', 'diagram', 'data', 'query']
|
|
43
|
-
.map((page) => source(`../../src/pages/${page}.ts`))
|
|
44
|
-
.join('\n')
|
|
45
|
-
const named = [
|
|
46
|
-
...backend.matchAll(/CustomComponent\("DmsDatabase(\w+)"\)/g),
|
|
47
|
-
].map(([, name]) => name)
|
|
48
|
-
expect(named.length).toBeGreaterThan(0)
|
|
49
|
-
for (const name of named) {
|
|
50
|
-
expect(() => source(`../app/components/${name}.vue`)).not.toThrow()
|
|
51
|
-
}
|
|
52
|
-
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolve } from 'node:path'
|
|
2
2
|
import vue from '@vitejs/plugin-vue'
|
|
3
3
|
import { defineConfig } from 'vitest/config'
|
|
4
|
+
import { backendBoundary } from './build/backend-boundary.ts'
|
|
4
5
|
|
|
5
6
|
// The renderer and the DMS core layer the server-render tests run on: the
|
|
6
7
|
// ones the repository installs at its root (`@antelopejs/dms-frontend`,
|
|
@@ -8,7 +9,7 @@ import { defineConfig } from 'vitest/config'
|
|
|
8
9
|
const root = resolve(__dirname, '..', 'node_modules', '@antelopejs')
|
|
9
10
|
|
|
10
11
|
export default defineConfig({
|
|
11
|
-
plugins: [vue()],
|
|
12
|
+
plugins: [vue(), backendBoundary()],
|
|
12
13
|
resolve: {
|
|
13
14
|
alias: {
|
|
14
15
|
'#dms/frontend-module': resolve(
|
|
@@ -31,6 +32,8 @@ export default defineConfig({
|
|
|
31
32
|
// Still Node, but the components compiled for a browser (a client
|
|
32
33
|
// `render`, not the server's `ssrRender`): what a client navigation
|
|
33
34
|
// mounts.
|
|
34
|
-
testTransformMode: {
|
|
35
|
+
testTransformMode: {
|
|
36
|
+
web: ['**/clientNavigation.test.ts', '**/apiErrorPresentation.test.ts'],
|
|
37
|
+
},
|
|
35
38
|
},
|
|
36
39
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/dms-database",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Database console for the AntelopeJS DMS: schemas, relation diagrams, a data browser and an AQL query console.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"admin",
|
|
@@ -45,38 +45,49 @@
|
|
|
45
45
|
"dev:frontend": "pnpm frontend:dev",
|
|
46
46
|
"dev": "ajs project run -w -p playground",
|
|
47
47
|
"generate": "ajs module exports generate",
|
|
48
|
-
"lint:fix": "oxlint --fix
|
|
49
|
-
"lint": "oxlint &&
|
|
48
|
+
"lint:fix": "oxlint --fix && oxfmt . && pnpm --dir frontend-vue lint:fix",
|
|
49
|
+
"lint": "oxlint && pnpm --dir frontend-vue lint && node scripts/check-sources.mts && antelopejs-check-interface-ranges && node node_modules/@antelopejs/dms/frontend-vue/scripts/check-api-error-presentation.mjs frontend-vue/app",
|
|
50
50
|
"typecheck": "tsc --noEmit",
|
|
51
51
|
"format": "oxfmt . && pnpm --dir frontend-vue format",
|
|
52
52
|
"frontend:dev": "cd playground && pnpm frontend:dev",
|
|
53
|
-
"test": "([ -n \"$DMS_PREBUILT\" ] || pnpm run build) && ajs module test .",
|
|
53
|
+
"test": "([ -n \"$DMS_PREBUILT\" ] || pnpm run build) && DMS_PREBUILT=1 ajs module test .",
|
|
54
54
|
"release": "pnpm --dir frontend-vue install --frozen-lockfile && release-it",
|
|
55
55
|
"prepack": "pnpm run build",
|
|
56
56
|
"knip": "knip --dependencies",
|
|
57
57
|
"knip:all": "knip",
|
|
58
58
|
"test:layer": "pnpm --dir frontend-vue test",
|
|
59
|
-
"test:frontend": "ajs dms verify-source --layer node_modules/@antelopejs/dms/frontend-vue --module frontend-vue"
|
|
59
|
+
"test:frontend": "ajs dms verify-source --layer node_modules/@antelopejs/dms/frontend-vue --module frontend-vue",
|
|
60
|
+
"prepare": "if git rev-parse --is-inside-work-tree >/dev/null 2>&1 && command -v lefthook >/dev/null 2>&1; then lefthook install; fi",
|
|
61
|
+
"checks": "antelopejs-checks",
|
|
62
|
+
"size": "antelopejs-check-size",
|
|
63
|
+
"sync": "antelopejs-sync",
|
|
64
|
+
"sync:check": "antelopejs-sync --check",
|
|
65
|
+
"format:check": "oxfmt --check .",
|
|
66
|
+
"suppressions": "antelopejs-suppressions",
|
|
67
|
+
"suppressions:update": "antelopejs-suppressions --update"
|
|
60
68
|
},
|
|
61
69
|
"dependencies": {
|
|
62
|
-
"@antelopejs/interface-api": ">=0.0
|
|
63
|
-
"@antelopejs/interface-api-util": ">=0.
|
|
64
|
-
"@antelopejs/interface-core": ">=0.
|
|
65
|
-
"@antelopejs/interface-database": ">=0.
|
|
66
|
-
"@antelopejs/interface-database-decorators": ">=0.
|
|
67
|
-
"@antelopejs/interface-dms": ">=0.
|
|
70
|
+
"@antelopejs/interface-api": ">=0.3.0 <1.0.0",
|
|
71
|
+
"@antelopejs/interface-api-util": ">=0.3.0 <1.0.0",
|
|
72
|
+
"@antelopejs/interface-core": ">=0.4.0 <1.0.0",
|
|
73
|
+
"@antelopejs/interface-database": ">=0.3.0 <1.0.0",
|
|
74
|
+
"@antelopejs/interface-database-decorators": ">=0.2.0 <1.0.0",
|
|
75
|
+
"@antelopejs/interface-dms": ">=0.12.0 <1.0.0"
|
|
68
76
|
},
|
|
69
77
|
"devDependencies": {
|
|
70
|
-
"@antelopejs/core": "
|
|
71
|
-
"@antelopejs/dms": ">=0.
|
|
72
|
-
"@antelopejs/dms-frontend": ">=0.
|
|
73
|
-
"@antelopejs/
|
|
78
|
+
"@antelopejs/core": "^1.20.0",
|
|
79
|
+
"@antelopejs/dms": ">=0.16.1 <1.0.0",
|
|
80
|
+
"@antelopejs/dms-frontend": ">=0.10.0 <0.11.0",
|
|
81
|
+
"@antelopejs/interface-data-api": ">=0.6.1 <1.0.0",
|
|
82
|
+
"@antelopejs/mongodb": "^1.6.2",
|
|
83
|
+
"@antelopejs/tooling-configs": "^0.2.18",
|
|
74
84
|
"@types/chai": "^5.2.3",
|
|
75
85
|
"@types/mocha": "^10.0.10",
|
|
76
86
|
"@types/node": "^24.0.0",
|
|
77
87
|
"@types/semver": "^7.8.0",
|
|
78
88
|
"chai": "^6.2.2",
|
|
79
89
|
"knip": "^6.34.0",
|
|
90
|
+
"lefthook": "^2.2.2",
|
|
80
91
|
"mocha": "^12.0.0",
|
|
81
92
|
"mongodb-memory-server-core": "^11.2.0",
|
|
82
93
|
"oxfmt": "^0.66.0",
|
|
@@ -88,9 +99,9 @@
|
|
|
88
99
|
"typescript": "^6.0.3"
|
|
89
100
|
},
|
|
90
101
|
"optionalDependencies": {
|
|
91
|
-
"@antelopejs/interface-dms-automation": ">=0.
|
|
102
|
+
"@antelopejs/interface-dms-automation": ">=0.6.0 <1.0.0"
|
|
92
103
|
},
|
|
93
|
-
"packageManager": "pnpm@10.
|
|
104
|
+
"packageManager": "pnpm@10.33.0",
|
|
94
105
|
"antelopeJs": {
|
|
95
106
|
"baseUrl": "dist",
|
|
96
107
|
"implements": [],
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"cases": [
|
|
4
|
+
{
|
|
5
|
+
"id": "database-aql-console",
|
|
6
|
+
"area": "modules",
|
|
7
|
+
"style": "clean",
|
|
8
|
+
"prompt": "Run an AQL query on the orders table from the dashboard.",
|
|
9
|
+
"expect": {
|
|
10
|
+
"skills": ["dms-database"],
|
|
11
|
+
"acceptable": ["database-interface", "dms"]
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": "dms-database-missing-table-casual",
|
|
16
|
+
"area": "modules",
|
|
17
|
+
"style": "casual",
|
|
18
|
+
"prompt": "my new table is missing from the dms database console",
|
|
19
|
+
"expect": {
|
|
20
|
+
"skills": ["dms-database"],
|
|
21
|
+
"acceptable": ["dms", "database-decorators-interface"],
|
|
22
|
+
"mustMention": ["RegisterSchema", "RegisterTable"]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": "dms-database-table-watch",
|
|
27
|
+
"area": "modules",
|
|
28
|
+
"style": "clean",
|
|
29
|
+
"prompt": "Run an automation procedure whenever a row is inserted into the orders table of the shop schema. Which trigger type do I pick, and what does it require from the database? Keep it short, no project config.",
|
|
30
|
+
"expect": {
|
|
31
|
+
"skills": ["dms-database"],
|
|
32
|
+
"acceptable": ["dms-automation", "dms"],
|
|
33
|
+
"mustMention": ["database.table-watch"]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "dms-database-not-aql-code",
|
|
38
|
+
"area": "modules",
|
|
39
|
+
"style": "clean",
|
|
40
|
+
"prompt": "In my module code, how do I write a chainable AQL query that joins orders to customers and sums the totals?",
|
|
41
|
+
"expect": {
|
|
42
|
+
"skills": ["database-interface"],
|
|
43
|
+
"acceptable": ["database-decorators-interface"],
|
|
44
|
+
"avoid": ["dms-database"]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|