@antelopejs/dms 0.20.0 → 0.20.2

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 (171) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +21 -14
  3. package/bin/control/backend-mode.test.mjs +41 -1
  4. package/bin/control/backend-records.test.mjs +154 -100
  5. package/bin/control/backend.mjs +1 -1
  6. package/bin/control/backend.test.mjs +4 -1
  7. package/bin/control/base.mjs +6 -1
  8. package/bin/control/build-key-refusals.test.mjs +8 -8
  9. package/bin/control/build-key.mjs +8 -6
  10. package/bin/control/build-key.test.mjs +3 -2
  11. package/bin/control/build-layout.test.mjs +5 -4
  12. package/bin/control/forwarder.test.mjs +19 -11
  13. package/bin/control/helpers/fake-run.mjs +59 -60
  14. package/bin/control/helpers/key-fixture.mjs +1 -1
  15. package/bin/control/helpers/pids.mjs +10 -0
  16. package/bin/control/helpers/tree.mjs +4 -4
  17. package/bin/control/journey.test.mjs +32 -32
  18. package/bin/control/mongo-server.test.mjs +64 -19
  19. package/bin/control/mongo.mjs +12 -3
  20. package/bin/control/namespaces.test.mjs +50 -31
  21. package/bin/control/processes.mjs +13 -1
  22. package/bin/control/processes.test.mjs +98 -64
  23. package/bin/control/renderer.test.mjs +2 -2
  24. package/bin/control/run-ports.test.mjs +24 -9
  25. package/bin/control/stack.mjs +16 -3
  26. package/bin/control/tab.test.mjs +1 -1
  27. package/bin/control/verify/formal.test.mjs +2 -2
  28. package/checks/dms-components.d.mts +38 -0
  29. package/data/mockup-spec.schema.json +4 -2
  30. package/data/module-store/catalog.json +1 -7
  31. package/dist/builder.js +2 -1
  32. package/dist/builder.js.map +1 -1
  33. package/dist/crons/cleanup-user-invites.js +7 -1
  34. package/dist/crons/cleanup-user-invites.js.map +1 -1
  35. package/dist/dev/module-update-notifications.js +2 -4
  36. package/dist/dev/module-update-notifications.js.map +1 -1
  37. package/dist/implementations/dms/dev-handshake.js +2 -5
  38. package/dist/implementations/dms/dev-handshake.js.map +1 -1
  39. package/dist/implementations/dms-auth/index.d.ts +3 -4
  40. package/dist/implementations/dms-auth/index.js +20 -4
  41. package/dist/implementations/dms-auth/index.js.map +1 -1
  42. package/dist/implementations/dms-auth/token-session.d.ts +2 -2
  43. package/dist/implementations/dms-auth/token-session.js +1 -4
  44. package/dist/implementations/dms-auth/token-session.js.map +1 -1
  45. package/dist/implementations/dms-base/bulk-selection.js +1 -1
  46. package/dist/implementations/dms-base/bulk-selection.js.map +1 -1
  47. package/dist/implementations/dms-base/footer-summary.js +1 -1
  48. package/dist/implementations/dms-base/footer-summary.js.map +1 -1
  49. package/dist/implementations/dms-base/search-route.d.ts +12 -3
  50. package/dist/implementations/dms-base/search-route.js +8 -4
  51. package/dist/implementations/dms-base/search-route.js.map +1 -1
  52. package/dist/implementations/dms-base/table-view.js +38 -16
  53. package/dist/implementations/dms-base/table-view.js.map +1 -1
  54. package/dist/implementations/dms-builder/engine/connection-access-config.js +2 -7
  55. package/dist/implementations/dms-builder/engine/connection-access-config.js.map +1 -1
  56. package/dist/implementations/dms-builder/engine/database-access.d.ts +1 -0
  57. package/dist/implementations/dms-builder/engine/database-access.js +14 -2
  58. package/dist/implementations/dms-builder/engine/database-access.js.map +1 -1
  59. package/dist/implementations/dms-builder/engine/driver-packages.js +4 -18
  60. package/dist/implementations/dms-builder/engine/driver-packages.js.map +1 -1
  61. package/dist/implementations/dms-builder/engine/file-paths.d.ts +3 -0
  62. package/dist/implementations/dms-builder/engine/file-paths.js +18 -0
  63. package/dist/implementations/dms-builder/engine/file-paths.js.map +1 -0
  64. package/dist/implementations/dms-builder/engine/index.d.ts +3 -0
  65. package/dist/implementations/dms-builder/engine/index.js +3 -0
  66. package/dist/implementations/dms-builder/engine/index.js.map +1 -1
  67. package/dist/implementations/dms-builder/engine/inherited-variables.d.ts +2 -0
  68. package/dist/implementations/dms-builder/engine/inherited-variables.js +19 -0
  69. package/dist/implementations/dms-builder/engine/inherited-variables.js.map +1 -0
  70. package/dist/implementations/dms-builder/engine/map-resources.js +1 -1
  71. package/dist/implementations/dms-builder/engine/map-resources.js.map +1 -1
  72. package/dist/implementations/dms-builder/engine/modules.js +3 -5
  73. package/dist/implementations/dms-builder/engine/modules.js.map +1 -1
  74. package/dist/implementations/dms-builder/engine/placement.js +2 -1
  75. package/dist/implementations/dms-builder/engine/placement.js.map +1 -1
  76. package/dist/implementations/dms-builder/engine/probe-client.d.ts +4 -0
  77. package/dist/implementations/dms-builder/engine/probe-client.js +11 -2
  78. package/dist/implementations/dms-builder/engine/probe-client.js.map +1 -1
  79. package/dist/implementations/dms-builder/engine/probe-mongodb.js +92 -36
  80. package/dist/implementations/dms-builder/engine/probe-mongodb.js.map +1 -1
  81. package/dist/implementations/dms-builder/engine/probe-mysql.js +54 -1
  82. package/dist/implementations/dms-builder/engine/probe-mysql.js.map +1 -1
  83. package/dist/implementations/dms-builder/engine/probe-postgres.js +95 -11
  84. package/dist/implementations/dms-builder/engine/probe-postgres.js.map +1 -1
  85. package/dist/implementations/dms-builder/engine/project-config-ops.js +2 -1
  86. package/dist/implementations/dms-builder/engine/project-config-ops.js.map +1 -1
  87. package/dist/implementations/dms-builder/engine/project-env.js +5 -0
  88. package/dist/implementations/dms-builder/engine/project-env.js.map +1 -1
  89. package/dist/implementations/dms-builder/engine/project-scaffold.d.ts +1 -8
  90. package/dist/implementations/dms-builder/engine/project-scaffold.js +55 -18
  91. package/dist/implementations/dms-builder/engine/project-scaffold.js.map +1 -1
  92. package/dist/implementations/dms-builder/engine/scram-bound.d.ts +5 -0
  93. package/dist/implementations/dms-builder/engine/scram-bound.js +60 -0
  94. package/dist/implementations/dms-builder/engine/scram-bound.js.map +1 -0
  95. package/dist/implementations/dms-builder/engine/theme-app-config.d.ts +1 -1
  96. package/dist/implementations/dms-builder/engine/theme-app-config.js +96 -22
  97. package/dist/implementations/dms-builder/engine/theme-app-config.js.map +1 -1
  98. package/dist/mcp/page-verify/page-probe.d.ts +12 -12
  99. package/dist/mcp/project-files.js +2 -8
  100. package/dist/mcp/project-files.js.map +1 -1
  101. package/dist/mcp/tools/preview-blocks.js +8 -24
  102. package/dist/mcp/tools/preview-blocks.js.map +1 -1
  103. package/dist/mcp/tools/typecheck.js +2 -5
  104. package/dist/mcp/tools/typecheck.js.map +1 -1
  105. package/dist/mockup/json-schema.js +2 -2
  106. package/dist/mockup/json-schema.js.map +1 -1
  107. package/dist/mockup/sketch-allowlist.d.ts +11 -0
  108. package/dist/mockup/sketch-allowlist.js +368 -0
  109. package/dist/mockup/sketch-allowlist.js.map +1 -0
  110. package/dist/mockup/sketch-css.d.ts +3 -0
  111. package/dist/mockup/sketch-css.js +306 -0
  112. package/dist/mockup/sketch-css.js.map +1 -0
  113. package/dist/mockup/sketch-html.d.ts +7 -0
  114. package/dist/mockup/sketch-html.js +243 -0
  115. package/dist/mockup/sketch-html.js.map +1 -0
  116. package/dist/mockup/sketch-limits.d.ts +1 -0
  117. package/dist/mockup/sketch-limits.js +5 -0
  118. package/dist/mockup/sketch-limits.js.map +1 -0
  119. package/dist/mockup/sketch-scan.d.ts +1 -0
  120. package/dist/mockup/sketch-scan.js +136 -0
  121. package/dist/mockup/sketch-scan.js.map +1 -0
  122. package/dist/mockup/sketch-tokens.d.ts +22 -0
  123. package/dist/mockup/sketch-tokens.js +42 -0
  124. package/dist/mockup/sketch-tokens.js.map +1 -0
  125. package/dist/mockup/sketch.d.ts +19 -1
  126. package/dist/mockup/sketch.js +78 -94
  127. package/dist/mockup/sketch.js.map +1 -1
  128. package/dist/routes/auth/logout.d.ts +2 -2
  129. package/dist/routes/auth/logout.js +3 -9
  130. package/dist/routes/auth/logout.js.map +1 -1
  131. package/dist/routes/auth/refresh.js +6 -8
  132. package/dist/routes/auth/refresh.js.map +1 -1
  133. package/dist/routes/auth/switch-tenant.js +8 -11
  134. package/dist/routes/auth/switch-tenant.js.map +1 -1
  135. package/dist/routes/auth.js +1 -1
  136. package/dist/routes/auth.js.map +1 -1
  137. package/dist/store/registry.js +2 -4
  138. package/dist/store/registry.js.map +1 -1
  139. package/dist/store/tarball.js +12 -6
  140. package/dist/store/tarball.js.map +1 -1
  141. package/dist/utils/index.d.ts +1 -0
  142. package/dist/utils/index.js +1 -0
  143. package/dist/utils/index.js.map +1 -1
  144. package/dist/utils/owner-only-file.d.ts +1 -0
  145. package/dist/utils/owner-only-file.js +60 -0
  146. package/dist/utils/owner-only-file.js.map +1 -0
  147. package/dist/utils/package-manager/index.d.ts +1 -0
  148. package/dist/utils/package-manager/index.js +18 -0
  149. package/dist/utils/package-manager/index.js.map +1 -0
  150. package/dist/utils/package-manager.d.ts +12 -0
  151. package/dist/utils/package-manager.js +28 -0
  152. package/dist/utils/package-manager.js.map +1 -0
  153. package/frontend-vue/build/backend-boundary.ts +84 -79
  154. package/frontend-vue/layers/dms-auth/app/middleware/auth.ts +11 -7
  155. package/frontend-vue/layers/dms-layout/app/composables/useHeaderActions.ts +4 -4
  156. package/frontend-vue/layers/dms-layout/i18n/locales/layout-en-GB.json +0 -4
  157. package/frontend-vue/layers/dms-layout/i18n/locales/layout-fr-FR.json +0 -4
  158. package/frontend-vue/layers/dms-ui/app/build/utils/sketch.ts +9 -0
  159. package/frontend-vue/package.json +1 -1
  160. package/frontend-vue/scripts/check-autoimport-boundaries.mjs +12 -7
  161. package/frontend-vue/scripts/check-dms-components.mjs +519 -0
  162. package/frontend-vue/scripts/check-invariants.mjs +7 -1
  163. package/frontend-vue/scripts/dms-components-dependencies.mjs +89 -0
  164. package/frontend-vue/scripts/test-dms-components.mjs +255 -0
  165. package/package.json +32 -17
  166. package/skills/dms/REFERENCE.md +1 -1
  167. package/skills/dms/SKILL.md +1 -1
  168. package/skills/dms-module/SKILL.md +1 -1
  169. package/skills/dms-module/cases.json +3 -3
  170. package/skills/dms-project/SKILL.md +1 -1
  171. package/skills/dms-project/scripts/dms-dev.sh +1 -1
@@ -1,6 +1,6 @@
1
1
  import { readFileSync, globSync } from "node:fs";
2
2
  import { createRequire } from "node:module";
3
- import { dirname, join, relative, resolve, basename } from "node:path";
3
+ import { dirname, join, relative, resolve, basename, sep } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import ts from "typescript";
6
6
  import { parse } from "vue/compiler-sfc";
@@ -8,6 +8,7 @@ import { parse } from "vue/compiler-sfc";
8
8
  const frontend = resolve(dirname(fileURLToPath(import.meta.url)), "..");
9
9
  const root = resolve(frontend, "../../..");
10
10
  const require = createRequire(import.meta.url);
11
+ const posixPath = (path) => path.split(sep).join("/");
11
12
  const rules = require("../../../../.dependency-cruiser/frontend.cjs").forbidden;
12
13
  const importer = createRequire(require.resolve("unplugin-auto-import"));
13
14
  const { scanDirExports } = importer("unimport");
@@ -64,7 +65,8 @@ const globs = autoImportDirectories(
64
65
  );
65
66
  const owners = new Map();
66
67
  const components = new Map();
67
- function own(name, file, registry = owners) {
68
+ function own(name, path, registry = owners) {
69
+ const file = posixPath(path);
68
70
  const layer = /\/layers\/dms-([^/]+)\//.exec(file)?.[1];
69
71
  if (!layer) return;
70
72
  const entries = registry.get(name) ?? new Set();
@@ -210,7 +212,7 @@ for (const file of globSync(
210
212
  text = [descriptor.script?.content, descriptor.scriptSetup?.content]
211
213
  .filter(Boolean)
212
214
  .join("\n");
213
- templateOffsets.set(file + ".audit.ts", text.length);
215
+ templateOffsets.set(posixPath(file) + ".audit.ts", text.length);
214
216
  text +=
215
217
  "\n" +
216
218
  tags
@@ -227,7 +229,7 @@ for (const file of globSync(
227
229
  )
228
230
  .join("\n");
229
231
  }
230
- sources.set(file + ".audit.ts", text + "\nexport {};");
232
+ sources.set(posixPath(file) + ".audit.ts", text + "\nexport {};");
231
233
  }
232
234
  const options = { noLib: true, noResolve: true };
233
235
  const host = ts.createCompilerHost(options);
@@ -245,21 +247,24 @@ function matches(condition, path) {
245
247
  }
246
248
  let failures = 0;
247
249
  function checkOwner(caller, name, owner) {
250
+ const target = posixPath(relative(root, owner));
248
251
  for (const rule of rules) {
249
252
  if (
250
253
  rule.to.dependencyTypes?.includes("local") ||
251
254
  !matches(rule.from, caller) ||
252
- !matches(rule.to, relative(root, owner))
255
+ !matches(rule.to, target)
253
256
  )
254
257
  continue;
255
258
  console.error(
256
- `FAIL auto-import boundary ${caller} ${rule.name} ${name} -> ${relative(root, owner)}`,
259
+ `FAIL auto-import boundary ${caller} ${rule.name} ${name} -> ${target}`,
257
260
  );
258
261
  failures++;
259
262
  }
260
263
  }
261
264
  for (const file of program.getSourceFiles()) {
262
- const caller = relative(root, file.fileName.replace(/\.audit\.ts$/, ""));
265
+ const caller = posixPath(
266
+ relative(root, file.fileName.replace(/\.audit\.ts$/, "")),
267
+ );
263
268
  const visit = (node) => {
264
269
  const registry =
265
270
  node.pos >= (templateOffsets.get(file.fileName) ?? Infinity)
@@ -0,0 +1,519 @@
1
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
+ import { join, relative, resolve, sep } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import {
5
+ addCommand,
6
+ dependencies,
7
+ RENDERER,
8
+ rendererComponentNames,
9
+ } from "./dms-components-dependencies.mjs";
10
+
11
+ const DMS_PREFIX = "Dms";
12
+ const DMS_LAYERS = fileURLToPath(new URL("../layers", import.meta.url));
13
+ const DMS_NAME = /^(?:Dms[A-Z]|dms-[a-z])/;
14
+ const SKIP = new Set(["node_modules", "dist", "tests", "test", "fixtures"]);
15
+ const SKIPPED_FILE = /\.(?:test|spec|d)\.[cm]?ts$/;
16
+ const ELEMENT = 1;
17
+ const COMPONENT_TAG = 1;
18
+ const ATTRIBUTE = 6;
19
+
20
+ const COMPONENT_FILE = /\/app\/(?:build\/)?components\/(?:.*\/)?([^/]+)\.vue$/;
21
+ const PAGE_FILE = /\/app\/custom-pages\/(.+?)(?:\/index)?\.vue$/;
22
+ const LAYOUT_FILE = /\/app\/custom-layouts\/(.+)\.vue$/;
23
+
24
+ /** Layer files dms.frontend.ts leaves out of its component globs. */
25
+ const UNREGISTERED_DMS_FILES = new Set([
26
+ "dms-ui/app/components/form/components/ImagePresentation.vue",
27
+ "dms-ui/app/build/components/table/TableBody.vue",
28
+ ]);
29
+
30
+ /** The second names dms.frontend.ts registers some components under. */
31
+ const DMS_ALIASES = {
32
+ ActivityFeed: "ActivityFeedBlock",
33
+ SectionPanel: "SectionBlock",
34
+ FieldRow: "FieldRowBlock",
35
+ };
36
+
37
+ /** A file path as dms.frontend.ts names its component: `notice-banner.vue` is `NoticeBanner`. */
38
+ function pascalCase(name) {
39
+ return name
40
+ .replace(/\.vue$/, "")
41
+ .split(/[./_-]+/)
42
+ .filter(Boolean)
43
+ .map((part) => `${part[0].toUpperCase()}${part.slice(1)}`)
44
+ .join("");
45
+ }
46
+
47
+ /** The last name Vue's `resolveComponent` tries for a tag: `dms-card-panel` is `DmsCardPanel`. */
48
+ function vueName(name) {
49
+ const camel = name.replace(/-(\w)/g, (_, letter) => letter.toUpperCase());
50
+ return `${camel.charAt(0).toUpperCase()}${camel.slice(1)}`;
51
+ }
52
+
53
+ /** A component name as the renderer's `resolveDmsComponent` compares it. */
54
+ function componentKey(name) {
55
+ return name
56
+ .replace(/^lazy/i, "")
57
+ .replace(/[^a-z0-9]/gi, "")
58
+ .toLowerCase();
59
+ }
60
+
61
+ /** A layout name as the renderer's `registerLayout` compares it. */
62
+ function layoutKey(name) {
63
+ return name
64
+ .replace(/^lazy/i, "")
65
+ .replace(/^dms[-_]?/i, "")
66
+ .replace(/[^a-z0-9]/gi, "")
67
+ .toLowerCase();
68
+ }
69
+
70
+ function files(root, keep) {
71
+ if (!existsSync(root)) return [];
72
+ return readdirSync(root, { withFileTypes: true }).flatMap((entry) => {
73
+ if (entry.name.startsWith(".") || SKIP.has(entry.name)) return [];
74
+ const path = join(root, entry.name);
75
+ if (entry.isDirectory()) return files(path, keep);
76
+ return keep(path) ? [path] : [];
77
+ });
78
+ }
79
+
80
+ /**
81
+ * The components and layouts a `dms.frontend.ts` registers from the `.vue`
82
+ * files under `root`, before its prefix: the file name of a component under
83
+ * `app/components/` or `app/build/components/`, the path below
84
+ * `app/custom-pages/` of a custom page, the path below `app/custom-layouts/`
85
+ * of a layout.
86
+ */
87
+ function registeredFiles(root, skip = new Set()) {
88
+ const components = [];
89
+ const layouts = [];
90
+ for (const path of files(root, (file) => file.endsWith(".vue"))) {
91
+ const file = relative(root, path).split(sep).join("/");
92
+ if (skip.has(file)) continue;
93
+ const component = (COMPONENT_FILE.exec(`/${file}`) ??
94
+ PAGE_FILE.exec(`/${file}`))?.[1];
95
+ if (component) components.push(pascalCase(component));
96
+ const layout = LAYOUT_FILE.exec(`/${file}`)?.[1];
97
+ if (layout) layouts.push(layout);
98
+ }
99
+ return { components, layouts };
100
+ }
101
+
102
+ /**
103
+ * The names the installed `@antelopejs/dms` registers, as its
104
+ * `dms.frontend.ts` does: each component with its `Dms` prefix and aliases,
105
+ * and each layout.
106
+ */
107
+ export function dmsRegistrations() {
108
+ const { components, layouts } = registeredFiles(
109
+ DMS_LAYERS,
110
+ UNREGISTERED_DMS_FILES,
111
+ );
112
+ return {
113
+ components: new Set(
114
+ components.flatMap((name) =>
115
+ [name, DMS_ALIASES[name]]
116
+ .filter(Boolean)
117
+ .map((registered) => DMS_PREFIX + registered),
118
+ ),
119
+ ),
120
+ layouts: new Set(layouts),
121
+ };
122
+ }
123
+
124
+ function parseScript(file, source, ts) {
125
+ return ts.createSourceFile(
126
+ file,
127
+ source,
128
+ ts.ScriptTarget.Latest,
129
+ true,
130
+ ts.ScriptKind.TS,
131
+ );
132
+ }
133
+
134
+ function unwrap(node, ts) {
135
+ let inner = node;
136
+ while (
137
+ ts.isParenthesizedExpression(inner) ||
138
+ ts.isAsExpression(inner) ||
139
+ ts.isSatisfiesExpression(inner) ||
140
+ ts.isNonNullExpression(inner) ||
141
+ ts.isTypeAssertionExpression(inner)
142
+ )
143
+ inner = inner.expression;
144
+ return inner;
145
+ }
146
+
147
+ function literalText(node, ts) {
148
+ return ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)
149
+ ? node.text
150
+ : undefined;
151
+ }
152
+
153
+ function bindingNames(name, ts) {
154
+ if (ts.isIdentifier(name)) return [name.text];
155
+ return name.elements.flatMap((element) =>
156
+ ts.isOmittedExpression(element) ? [] : bindingNames(element.name, ts),
157
+ );
158
+ }
159
+
160
+ /**
161
+ * What the statements of one scope declare under `name`: the text of a
162
+ * `const` holding a string, `{}` for any other declaration, or nothing.
163
+ */
164
+ function declaredIn(statements, name, ts) {
165
+ for (const statement of statements) {
166
+ if (ts.isVariableStatement(statement))
167
+ for (const declaration of statement.declarationList.declarations) {
168
+ if (!bindingNames(declaration.name, ts).includes(name)) continue;
169
+ const constant =
170
+ statement.declarationList.flags & ts.NodeFlags.Const &&
171
+ ts.isIdentifier(declaration.name) &&
172
+ declaration.initializer;
173
+ return {
174
+ text: constant
175
+ ? literalText(unwrap(declaration.initializer, ts), ts)
176
+ : undefined,
177
+ };
178
+ }
179
+ const imported = ts.isImportDeclaration(statement)
180
+ ? [
181
+ statement.importClause?.name,
182
+ ...(statement.importClause?.namedBindings?.elements ?? []),
183
+ ]
184
+ : [statement.name];
185
+ if (
186
+ imported.some((binding) => nameOf(binding?.name ?? binding, ts) === name)
187
+ )
188
+ return {};
189
+ }
190
+ return undefined;
191
+ }
192
+
193
+ function shadows(scope, name, ts) {
194
+ const loop =
195
+ (ts.isForStatement(scope) ||
196
+ ts.isForOfStatement(scope) ||
197
+ ts.isForInStatement(scope)) &&
198
+ scope.initializer &&
199
+ ts.isVariableDeclarationList(scope.initializer);
200
+ const declarations = [
201
+ ...(ts.isFunctionLike(scope) ? scope.parameters : []),
202
+ ...(loop ? scope.initializer.declarations : []),
203
+ ...(ts.isCatchClause(scope) && scope.variableDeclaration
204
+ ? [scope.variableDeclaration]
205
+ : []),
206
+ ];
207
+ return declarations.some((declaration) =>
208
+ bindingNames(declaration.name, ts).includes(name),
209
+ );
210
+ }
211
+
212
+ /** The string the `const` that `identifier` refers to holds, when the nearest declaration of its name is one. */
213
+ function constantFor(identifier, ts) {
214
+ for (let scope = identifier.parent; scope; scope = scope.parent) {
215
+ if (shadows(scope, identifier.text, ts)) return undefined;
216
+ if (
217
+ ts.isBlock(scope) ||
218
+ ts.isSourceFile(scope) ||
219
+ ts.isModuleBlock(scope)
220
+ ) {
221
+ const declared = declaredIn(scope.statements, identifier.text, ts);
222
+ if (declared) return declared.text;
223
+ }
224
+ }
225
+ return undefined;
226
+ }
227
+
228
+ /** A string literal, or a `const` of the same file in scope holding one. */
229
+ function stringOf(node, ts) {
230
+ if (!node) return undefined;
231
+ const value = unwrap(node, ts);
232
+ return ts.isIdentifier(value)
233
+ ? constantFor(value, ts)
234
+ : literalText(value, ts);
235
+ }
236
+
237
+ function nameOf(node, ts) {
238
+ if (!node) return undefined;
239
+ if (ts.isIdentifier(node) || ts.isStringLiteral(node)) return node.text;
240
+ if (ts.isPropertyAccessExpression(node)) return node.name.text;
241
+ return undefined;
242
+ }
243
+
244
+ function isBanner(object, ts) {
245
+ const keys = new Set(object.properties.map((p) => nameOf(p.name, ts)));
246
+ return keys.has("key") && keys.has("variant");
247
+ }
248
+
249
+ /**
250
+ * What a node names by string: a component Vue resolves (`resolveComponent`),
251
+ * one an interface-dms builder takes (`CustomComponent`, `new
252
+ * ComponentBuilder`, a `componentName` property, a layout banner's
253
+ * `component`), or one the layer registers.
254
+ */
255
+ function namedString(node, ts) {
256
+ const callee =
257
+ (ts.isCallExpression(node) || ts.isNewExpression(node)) &&
258
+ nameOf(node.expression, ts);
259
+ const argument = callee && node.arguments?.[0];
260
+ if (callee === "resolveComponent") return { kind: "vue", node: argument };
261
+ if (
262
+ callee === "CustomComponent" ||
263
+ (callee === "ComponentBuilder" && ts.isNewExpression(node))
264
+ )
265
+ return { kind: "builder", node: argument };
266
+ if (callee === "registerComponent" || callee === "registerLayout")
267
+ return { kind: callee, node: argument, unprefixed: unprefixed(node, ts) };
268
+ if (ts.isShorthandPropertyAssignment(node))
269
+ return nameOf(node.name, ts) === "componentName"
270
+ ? { kind: "componentName", node: node.name }
271
+ : undefined;
272
+ if (!ts.isPropertyAssignment(node)) return undefined;
273
+ const property = nameOf(node.name, ts);
274
+ if (property === "componentName")
275
+ return { kind: "componentName", node: node.initializer };
276
+ return property === "component" && isBanner(node.parent, ts)
277
+ ? { kind: "builder", node: node.initializer }
278
+ : undefined;
279
+ }
280
+
281
+ /** Whether a `registerComponent` call passes `{ prefix: false }`. */
282
+ function unprefixed(call, ts) {
283
+ const options = call.arguments?.[2];
284
+ return Boolean(
285
+ options &&
286
+ ts.isObjectLiteralExpression(options) &&
287
+ options.properties.some(
288
+ (property) =>
289
+ ts.isPropertyAssignment(property) &&
290
+ nameOf(property.name, ts) === "prefix" &&
291
+ property.initializer.kind === ts.SyntaxKind.FalseKeyword,
292
+ ),
293
+ );
294
+ }
295
+
296
+ /** The component names a script names by string, with the offset of each. */
297
+ function scriptStrings(tree, ts) {
298
+ const found = [];
299
+ const visit = (node) => {
300
+ const named = namedString(node, ts);
301
+ const name = named && stringOf(named.node, ts);
302
+ if (name)
303
+ found.push({
304
+ kind: named.kind,
305
+ name,
306
+ unprefixed: named.unprefixed,
307
+ offset: named.node.getStart(tree),
308
+ });
309
+ ts.forEachChild(node, visit);
310
+ };
311
+ visit(tree);
312
+ return found;
313
+ }
314
+
315
+ function lineAt(source, offset) {
316
+ return source.slice(0, offset).split("\n").length;
317
+ }
318
+
319
+ /** The names a script declares at its top level, which its template may use as tags. */
320
+ function scriptBindings(tree, ts) {
321
+ return tree.statements.flatMap((statement) => {
322
+ if (ts.isImportDeclaration(statement)) {
323
+ const clause = statement.importClause;
324
+ if (!clause || clause.isTypeOnly) return [];
325
+ const named = clause.namedBindings;
326
+ return [
327
+ ...(clause.name ? [clause.name.text] : []),
328
+ ...(named && ts.isNamedImports(named)
329
+ ? named.elements
330
+ .filter((element) => !element.isTypeOnly)
331
+ .map((element) => element.name.text)
332
+ : []),
333
+ ];
334
+ }
335
+ if (ts.isVariableStatement(statement))
336
+ return statement.declarationList.declarations.flatMap((declaration) =>
337
+ bindingNames(declaration.name, ts),
338
+ );
339
+ return (ts.isFunctionDeclaration(statement) ||
340
+ ts.isClassDeclaration(statement)) &&
341
+ statement.name
342
+ ? [statement.name.text]
343
+ : [];
344
+ });
345
+ }
346
+
347
+ function templateUses(node) {
348
+ const children = (node.children ?? []).flatMap(templateUses);
349
+ if (node.type !== ELEMENT) return children;
350
+ const is = node.props.find(
351
+ (prop) => prop.type === ATTRIBUTE && prop.name === "is" && prop.value,
352
+ );
353
+ const tag = node.tagType === COMPONENT_TAG ? node.tag : undefined;
354
+ const name = node.tag === "component" ? is?.value.content : tag;
355
+ return name
356
+ ? [{ kind: "vue", name, line: node.loc.start.line }, ...children]
357
+ : children;
358
+ }
359
+
360
+ /** What one source file names by string or tag, with the line of each. */
361
+ function fileStrings({ file, source }, tools) {
362
+ if (!file.endsWith(".vue"))
363
+ return scriptStrings(parseScript(file, source, tools.ts), tools.ts).map(
364
+ ({ offset, ...use }) => ({ ...use, file, line: lineAt(source, offset) }),
365
+ );
366
+ const { descriptor, errors } = tools.parse(source, { filename: file });
367
+ if (errors.length)
368
+ throw new Error(`Cannot parse ${file}: ${errors.join(", ")}`);
369
+ const scripts = [descriptor.script, descriptor.scriptSetup]
370
+ .filter(Boolean)
371
+ .map((block) => ({
372
+ block,
373
+ tree: parseScript(file, block.content, tools.ts),
374
+ }));
375
+ const bound = new Set(
376
+ scripts.flatMap(({ tree }) => scriptBindings(tree, tools.ts)).map(vueName),
377
+ );
378
+ const tags = descriptor.template?.ast
379
+ ? templateUses(descriptor.template.ast).filter(
380
+ ({ name }) => !bound.has(vueName(name)),
381
+ )
382
+ : [];
383
+ return [
384
+ ...tags.map((use) => ({ ...use, file })),
385
+ ...scripts.flatMap(({ block, tree }) =>
386
+ scriptStrings(tree, tools.ts).map(({ offset, ...use }) => ({
387
+ ...use,
388
+ file,
389
+ line: lineAt(source, block.loc.start.offset + offset),
390
+ })),
391
+ ),
392
+ ];
393
+ }
394
+
395
+ /**
396
+ * The `componentPrefix` of the layer's `dms.frontend.ts`: the first one
397
+ * written as a string, or as a `const` of that file holding one.
398
+ */
399
+ function layerPrefix(layer, ts) {
400
+ const entry = join(layer, "dms.frontend.ts");
401
+ if (!existsSync(entry)) return "";
402
+ const tree = parseScript(entry, readFileSync(entry, "utf8"), ts);
403
+ const declared = [];
404
+ const visit = (node) => {
405
+ if (
406
+ (ts.isPropertyAssignment(node) ||
407
+ ts.isShorthandPropertyAssignment(node)) &&
408
+ nameOf(node.name, ts) === "componentPrefix"
409
+ )
410
+ declared.push(stringOf(node.initializer ?? node.name, ts));
411
+ ts.forEachChild(node, visit);
412
+ };
413
+ visit(tree);
414
+ const prefix = declared.find((value) => value !== undefined);
415
+ if (declared.length && prefix === undefined)
416
+ throw new Error(
417
+ `${entry}: write componentPrefix as a string, or a const of that file holding one, so that the DMS component check reads it`,
418
+ );
419
+ return prefix ?? "";
420
+ }
421
+
422
+ function readSources(roots, pattern) {
423
+ return roots
424
+ .flatMap((root) => {
425
+ if (!existsSync(root)) throw new Error(`No such source: ${root}`);
426
+ return statSync(root).isDirectory()
427
+ ? files(root, (path) => pattern.test(path) && !SKIPPED_FILE.test(path))
428
+ : [root];
429
+ })
430
+ .map((file) => ({ file, source: readFileSync(file, "utf8") }));
431
+ }
432
+
433
+ /** The names Vue and the renderer resolve, from dms, the renderer and the layer. */
434
+ async function knownNames(root, layerStrings, tools) {
435
+ const dms = dmsRegistrations();
436
+ const prefix = layerPrefix(root, tools.ts);
437
+ const own = registeredFiles(root);
438
+ const registered = (kind) => layerStrings.filter((use) => use.kind === kind);
439
+ const tags = new Set([
440
+ ...dms.components,
441
+ ...(await rendererComponentNames(tools.rendererGlobals)),
442
+ ...own.components.map((name) => prefix + name),
443
+ ...registered("registerComponent").map((use) =>
444
+ use.unprefixed || !prefix ? use.name : prefix + vueName(use.name),
445
+ ),
446
+ ]);
447
+ return {
448
+ tags,
449
+ components: new Set([...tags].map(componentKey)),
450
+ layouts: new Set(
451
+ [
452
+ ...dms.layouts,
453
+ ...own.layouts,
454
+ ...registered("registerLayout").map(({ name }) => name),
455
+ ].map(layoutKey),
456
+ ),
457
+ };
458
+ }
459
+
460
+ function isKnown({ kind, name }, known) {
461
+ if (kind === "vue")
462
+ return known.tags.has(name) || known.tags.has(vueName(name));
463
+ return (
464
+ known.components.has(componentKey(name)) ||
465
+ (kind === "componentName" && known.layouts.has(layoutKey(name)))
466
+ );
467
+ }
468
+
469
+ /**
470
+ * Every place the layer names a `Dms` component that neither the installed
471
+ * `@antelopejs/dms`, the installed `@antelopejs/dms-frontend` nor the layer
472
+ * registers: a tag, static `is` or `resolveComponent` string in one of its
473
+ * files, or a string an interface-dms builder takes as a component name in
474
+ * the layer or in `sources` (the module's backend directories). Vue renders
475
+ * an unknown tag as an empty element, with no error. Each diagnostic names
476
+ * the file, the line and the name.
477
+ */
478
+ export async function checkDmsComponents(options) {
479
+ return (await inspect(options)).diagnostics;
480
+ }
481
+
482
+ async function inspect({ layer, sources = [] }) {
483
+ const root = resolve(layer);
484
+ const tools = dependencies(root);
485
+ const layerFiles = readSources([root], /\.(?:vue|[cm]?ts)$/);
486
+ const layerStrings = layerFiles.flatMap((file) => fileStrings(file, tools));
487
+ const known = await knownNames(root, layerStrings, tools);
488
+ const read = new Set(layerFiles.map(({ file }) => file));
489
+ const sourceStrings = readSources(
490
+ sources.map((source) => resolve(source)),
491
+ /\.[cm]?ts$/,
492
+ )
493
+ .filter(({ file }) => !read.has(file))
494
+ .flatMap((file) => fileStrings(file, tools));
495
+ const diagnostics = [...layerStrings, ...sourceStrings]
496
+ .filter(({ kind }) => ["vue", "builder", "componentName"].includes(kind))
497
+ .filter((use) => DMS_NAME.test(use.name) && !isKnown(use, known))
498
+ .map(
499
+ ({ file, line, name }) =>
500
+ `${relative(process.cwd(), file)}:${line}: \`${name}\` is no component the installed @antelopejs/dms, @antelopejs/dms-frontend or this layer registers`,
501
+ );
502
+ return { diagnostics, root, rendererMissing: !tools.rendererGlobals };
503
+ }
504
+
505
+ /**
506
+ * Rejects with every diagnostic of {@link checkDmsComponents}, one per line.
507
+ * When `@antelopejs/dms-frontend` is not installed, the last line says that
508
+ * the components its renderer registers count as unknown, and how to add it.
509
+ */
510
+ export async function assertDmsComponents(options) {
511
+ const { diagnostics, root, rendererMissing } = await inspect(options);
512
+ if (!diagnostics.length) return;
513
+ const note = rendererMissing
514
+ ? [
515
+ `${RENDERER} is not installed in ${root}, so the components its renderer registers, such as DmsLink, count as unknown. If the layer uses one, run in ${root}: ${addCommand([RENDERER])}`,
516
+ ]
517
+ : [];
518
+ throw new Error([...diagnostics, ...note].join("\n"));
519
+ }
@@ -6,6 +6,8 @@ import { brotliDecompressSync } from "node:zlib";
6
6
  import { z } from "zod";
7
7
  import { assertApiErrorPresentation } from "./check-api-error-presentation.mjs";
8
8
  import "./test-api-error-presentation.mjs";
9
+ import { assertDmsComponents } from "./check-dms-components.mjs";
10
+ import "./test-dms-components.mjs";
9
11
  import "./check-autoimport-boundaries.mjs";
10
12
  import "./test-autoimport-boundaries.mjs";
11
13
  import "./check-page-invariants.mjs";
@@ -356,6 +358,10 @@ function checkGeistNarrowSpace() {
356
358
 
357
359
  for (const [name, check] of [
358
360
  ["API error presentation", () => assertApiErrorPresentation([LAYERS_DIR])],
361
+ [
362
+ "DMS components",
363
+ () => assertDmsComponents({ layer: ROOT, sources: [join(ROOT, "../src")] }),
364
+ ],
359
365
  ["core error fallback", checkCoreErrorFallback],
360
366
  ["translated accessible names", checkAccessibleNames],
361
367
  ["layer plugin registration", checkPluginRegistration],
@@ -369,7 +375,7 @@ for (const [name, check] of [
369
375
  ["onboarding page meta", checkOnboardingPageMeta],
370
376
  ]) {
371
377
  try {
372
- check();
378
+ await check();
373
379
  console.log(`PASS ${name}`);
374
380
  } catch (error) {
375
381
  console.error(`FAIL ${name}`);