@jskit-ai/architecture-inspector 0.1.11 → 0.1.13

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 CHANGED
@@ -76,12 +76,14 @@ Each discovery supplies `id`, `adapter`, `surface`, `mode`, `registrations`,
76
76
  it returns. Anything else is reported as `CONTROLLER_UNRESOLVED`.
77
77
  `--api-base-path /api` prefixes these paths.
78
78
  - Actual `CrudListScreen` / `CrudAddEditScreen` uses whose bound screen comes from
79
- the matching JSKIT composable can connect to exported `defineCrudJsonApiFeature`
79
+ the matching JSKIT composable can connect to exported `defineCrudFeature`
80
80
  controller declarations. The resource must resolve through indexed imports and
81
- named re-exports to a literal `defineCrudResource` namespace and enabled
82
- operations. Scope includes the explicit HTTP application identity, declared
83
- surface and API suffix; the key uses `jskit.crud` resource operations rather
84
- than claiming a fully expanded runtime URL. Custom clients, transport/resource
81
+ named re-exports to a literal `defineCrudContract` declaration with literal
82
+ enabled operations, and a literal namespace or, without one, a table
83
+ resource whose `defineTableResource` name is literal. Scope includes the
84
+ explicit HTTP application identity, declared surface and API suffix; the key
85
+ uses `jskit.crud` resource operations rather than claiming a fully expanded
86
+ runtime URL. Custom clients, transport/resource
85
87
  overrides, dynamic operations and disabled routes do not create guessed links.
86
88
  This shows declared entry points; runtime provider activation is not proven.
87
89
  Each such entry operation carries the `actionId` its route runs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/architecture-inspector",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Static Vue architecture inspector for the portable architecture-inspection command contract.",
5
5
  "type": "module",
6
6
  "files": [
@@ -18,11 +18,11 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/parser": "^7.29.9",
21
- "@jskit-ai/kernel": "0.2.13",
22
21
  "@vue/compiler-sfc": "^3.5.44",
23
22
  "typescript": "^6.0.3"
24
23
  },
25
24
  "peerDependencies": {
25
+ "@jskit-ai/kernel": "0.2.15",
26
26
  "vue-router": "^5.3.1"
27
27
  },
28
28
  "engines": {
@@ -3,7 +3,8 @@ import { isFunctionLike, unwrapExpression } from "./functions.js";
3
3
 
4
4
  const FEATURE_PACKAGE = "@jskit-ai/kernel";
5
5
  const CRUD_PACKAGE = "@jskit-ai/crud-core";
6
- const CRUD_RESOURCE_PACKAGE = "@jskit-ai/resource-crud-core";
6
+ const CRUD_CONTRACT_PACKAGE = "@jskit-ai/resource-crud-core";
7
+ const TABLE_RESOURCE_PACKAGE = "@jskit-ai/resource-core";
7
8
  // How many arrays, spreads, conditionals, calls and functions an action
8
9
  // definition may sit under in a feature's actions() result: enough for a
9
10
  // flagged spread of a create*Actions call whose definitions are each frozen.
@@ -36,7 +37,7 @@ function bindFeatures({ calls, symbols, evaluator }) {
36
37
  const crudDeclarations = [];
37
38
  for (const call of calls) {
38
39
  const callee = unwrapExpression(call.expression);
39
- if (ts.isIdentifier(callee) && symbols.isImportOf(callee, CRUD_PACKAGE, ["defineCrudJsonApiFeature"])) {
40
+ if (ts.isIdentifier(callee) && symbols.isImportOf(callee, CRUD_PACKAGE, ["defineCrudFeature"])) {
40
41
  const config = objectLiteral(call.arguments[0], symbols);
41
42
  if (config) {
42
43
  crudDeclarations.push(config);
@@ -238,20 +239,34 @@ function collectCrudActions(declarations, { symbols, evaluator }) {
238
239
  return actions;
239
240
  }
240
241
 
241
- // The literal namespace of a CRUD declaration's `defineCrudResource` resource.
242
- function crudNamespace(config, { symbols, evaluator }) {
243
- let resource = unwrapExpression(memberValue(memberNamed(config, "resource")));
244
- for (let depth = 0; resource && ts.isIdentifier(resource) && depth < MAX_OBJECT_DEPTH; depth += 1) {
245
- const declaration = symbols.declarationOf(resource);
246
- resource = declaration && ts.isVariableDeclaration(declaration) ? unwrapExpression(declaration.initializer) : null;
242
+ // The call an expression's value comes from, through variable declarations,
243
+ // when that call is `name` imported from `packageName`.
244
+ function factoryCall(expression, packageName, name, symbols) {
245
+ let value = unwrapExpression(expression);
246
+ for (let depth = 0; value && ts.isIdentifier(value) && depth < MAX_OBJECT_DEPTH; depth += 1) {
247
+ const declaration = symbols.declarationOf(value);
248
+ value = declaration && ts.isVariableDeclaration(declaration) ? unwrapExpression(declaration.initializer) : null;
247
249
  }
248
- const callee = resource && ts.isCallExpression(resource) ? unwrapExpression(resource.expression) : null;
249
- if (!callee || !ts.isIdentifier(callee) || !symbols.isImportOf(callee, CRUD_RESOURCE_PACKAGE, ["defineCrudResource"])) {
250
+ const callee = value && ts.isCallExpression(value) ? unwrapExpression(value.expression) : null;
251
+ return callee && ts.isIdentifier(callee) && symbols.isImportOf(callee, packageName, [name]) ? value : null;
252
+ }
253
+
254
+ // The literal namespace of a CRUD declaration's `defineCrudContract` contract:
255
+ // its own `namespace`, else the `name` of the table resource it is built on.
256
+ function crudNamespace(config, { symbols, evaluator }) {
257
+ const contract = factoryCall(memberValue(memberNamed(config, "crud")), CRUD_CONTRACT_PACKAGE, "defineCrudContract", symbols);
258
+ if (!contract) {
250
259
  return null;
251
260
  }
252
- const definition = objectLiteral(resource.arguments[0], symbols);
253
- const namespace = definition && evaluator.evaluateLiteral(memberValue(memberNamed(definition, "namespace")));
254
- return namespace?.trim() || null;
261
+ const definition = contract.arguments[1] ? objectLiteral(contract.arguments[1], symbols) : null;
262
+ const declared = definition && memberNamed(definition, "namespace");
263
+ if (declared) {
264
+ return evaluator.evaluateLiteral(memberValue(declared))?.trim() || null;
265
+ }
266
+ const table = factoryCall(contract.arguments[0], TABLE_RESOURCE_PACKAGE, "defineTableResource", symbols);
267
+ const tableDefinition = table && objectLiteral(table.arguments[0], symbols);
268
+ const name = tableDefinition && evaluator.evaluateLiteral(memberValue(memberNamed(tableDefinition, "name")));
269
+ return name?.trim() || null;
255
270
  }
256
271
 
257
272
  // Action definitions inside each feature's actions() result: object literals
@@ -15,8 +15,9 @@ const RESOLVE_EXTENSIONS = Object.freeze([".vue", ".js", ".ts", "/index.js", "/i
15
15
 
16
16
  // Framework sources whose declarations this inspector reads statically.
17
17
  const SOURCES = Object.freeze({
18
- crudResource: "@jskit-ai/resource-crud-core/shared/crudResource",
19
- crudJsonApiFeature: "@jskit-ai/crud-core/server/defineCrudJsonApiFeature",
18
+ crudContract: "@jskit-ai/resource-crud-core/shared/crudContract",
19
+ tableResource: "@jskit-ai/resource-core/shared/tableResource",
20
+ crudFeature: "@jskit-ai/crud-core/server/defineCrudFeature",
20
21
  kernelFeatures: "@jskit-ai/kernel/server/features",
21
22
  kernelHttp: "@jskit-ai/kernel/server/http",
22
23
  crudListScreen: "@jskit-ai/http-web/client/components/CrudListScreen",
package/src/vue/pages.js CHANGED
@@ -33,9 +33,9 @@ function pageTitle(file) {
33
33
  return name === "index" ? path.posix.basename(path.posix.dirname(file)) : name;
34
34
  }
35
35
 
36
- // Follows an expression through local bindings, imports and re-exports to a
37
- // literal defineCrudResource declaration.
38
- async function resolveCrudResource(inspection, module, node, seen = new Set()) {
36
+ // Follows an expression through local bindings, imports and re-exports to the
37
+ // call that made its value, and the module that call is in.
38
+ async function resolveCall(inspection, module, node, seen = new Set()) {
39
39
  if (!node || seen.size >= MAX_RESOURCE_HOPS) {
40
40
  return null;
41
41
  }
@@ -47,56 +47,78 @@ async function resolveCrudResource(inspection, module, node, seen = new Set()) {
47
47
  const next = new Set([...seen, identity]);
48
48
  const imported = module.imports.get(node.name);
49
49
  if (!imported) {
50
- return resolveCrudResource(inspection, module, module.bindings.get(node.name), next);
50
+ return resolveCall(inspection, module, module.bindings.get(node.name), next);
51
51
  }
52
52
  const target = resolveImport(inspection, module.path, imported.source);
53
53
  const owner = target && await loadModule(inspection, target);
54
- return owner ? resolveExportedCrudResource(inspection, owner, imported.imported, next) : null;
54
+ return owner ? resolveExportedCall(inspection, owner, imported.imported, next) : null;
55
55
  }
56
- if (node.type !== "CallExpression" || node.callee.type !== "Identifier") {
56
+ return node.type === "CallExpression" && node.callee.type === "Identifier" ? { module, node } : null;
57
+ }
58
+
59
+ async function resolveExportedCall(inspection, module, name, seen) {
60
+ const entry = module.exports.get(name);
61
+ if (!entry) {
62
+ return null;
63
+ }
64
+ if (!entry.source) {
65
+ return resolveCall(inspection, module, { type: "Identifier", name: entry.local }, seen);
66
+ }
67
+ const identity = `${module.path}:export:${name}`;
68
+ if (seen.has(identity) || seen.size >= MAX_RESOURCE_HOPS) {
57
69
  return null;
58
70
  }
71
+ const target = resolveImport(inspection, module.path, entry.source);
72
+ const owner = target && await loadModule(inspection, target);
73
+ return owner ? resolveExportedCall(inspection, owner, entry.local, new Set([...seen, identity])) : null;
74
+ }
75
+
76
+ // The node record of a call to `imported` from `source`, unless a local binding shadows it.
77
+ function factoryRecord({ module, node }, source, imported) {
59
78
  const factory = module.imports.get(node.callee.name);
60
79
  const record = findRecord(module, node);
61
- const isFactory = factory?.source === SOURCES.crudResource && factory.imported === "defineCrudResource";
62
- if (!isFactory || !record || isShadowed(record, node.callee.name)) {
80
+ return factory?.source === source && factory.imported === imported && record && !isShadowed(record, node.callee.name)
81
+ ? record
82
+ : null;
83
+ }
84
+
85
+ // The literal name of the table resource an expression stands for.
86
+ async function resolveTableResourceName(inspection, module, node) {
87
+ const call = await resolveCall(inspection, module, node);
88
+ if (!call || !factoryRecord(call, SOURCES.tableResource, "defineTableResource")) {
89
+ return undefined;
90
+ }
91
+ const definition = bindingNode(call.node.arguments[0], call.module.bindings);
92
+ return staticValue(objectProperty(definition, "name"), call.module.bindings);
93
+ }
94
+
95
+ // The namespace and operations of the literal defineCrudContract declaration
96
+ // an expression stands for. Its namespace is its own, else its table resource's name.
97
+ async function resolveCrudResource(inspection, module, node) {
98
+ const call = await resolveCall(inspection, module, node);
99
+ const record = call && factoryRecord(call, SOURCES.crudContract, "defineCrudContract");
100
+ if (!record) {
63
101
  return null;
64
102
  }
65
- const config = bindingNode(node.arguments[0], module.bindings);
66
- if (config?.type !== "ObjectExpression" || !hasOnlyStaticProperties(config)) {
103
+ const config = call.node.arguments[1] ? bindingNode(call.node.arguments[1], call.module.bindings) : null;
104
+ if (config && (config.type !== "ObjectExpression" || !hasOnlyStaticProperties(config))) {
67
105
  return null;
68
106
  }
69
- const namespace = staticValue(objectProperty(config, "namespace"), module.bindings);
70
- const declaredOperations = objectProperty(config, "crudOperations");
71
- const operations = declaredOperations ? staticValue(declaredOperations, module.bindings) : [...CRUD_RESOURCE_OPERATIONS];
107
+ const declaredNamespace = objectProperty(config, "namespace");
108
+ const namespace = declaredNamespace
109
+ ? staticValue(declaredNamespace, call.module.bindings)
110
+ : await resolveTableResourceName(inspection, call.module, call.node.arguments[0]);
111
+ const declaredOperations = objectProperty(config, "operations");
112
+ const operations = declaredOperations ? staticValue(declaredOperations, call.module.bindings) : [...CRUD_RESOURCE_OPERATIONS];
72
113
  if (typeof namespace !== "string" || !namespace.trim()) {
73
114
  return null;
74
115
  }
75
116
  if (!Array.isArray(operations) || !operations.length || !operations.every((name) => CRUD_RESOURCE_OPERATIONS.includes(name))) {
76
117
  return null;
77
118
  }
78
- if (objectProperty(config, "operations")) {
79
- return null;
80
- }
81
- return { namespace: namespace.trim(), operations, evidence: sourceEvidence(module, node, record.offset) };
119
+ return { namespace: namespace.trim(), operations, evidence: sourceEvidence(call.module, call.node, record.offset) };
82
120
  }
83
121
 
84
- async function resolveExportedCrudResource(inspection, module, name, seen) {
85
- const entry = module.exports.get(name);
86
- if (!entry) {
87
- return null;
88
- }
89
- if (!entry.source) {
90
- return resolveCrudResource(inspection, module, { type: "Identifier", name: entry.local }, seen);
91
- }
92
- const identity = `${module.path}:export:${name}`;
93
- if (seen.has(identity) || seen.size >= MAX_RESOURCE_HOPS) {
94
- return null;
95
- }
96
- const target = resolveImport(inspection, module.path, entry.source);
97
- const owner = target && await loadModule(inspection, target);
98
- return owner ? resolveExportedCrudResource(inspection, owner, entry.local, new Set([...seen, identity])) : null;
99
- }
100
122
 
101
123
  function crudOperationKey(inspection, surface, namespace, operation, apiSuffix) {
102
124
  return {
package/src/vue/routes.js CHANGED
@@ -58,7 +58,7 @@ async function recordCrudController(inspection, { module, file, record }) {
58
58
  return;
59
59
  }
60
60
  const factory = module.imports.get(node.callee.name);
61
- if (factory?.source !== SOURCES.crudJsonApiFeature || factory.imported !== "defineCrudJsonApiFeature") {
61
+ if (factory?.source !== SOURCES.crudFeature || factory.imported !== "defineCrudFeature") {
62
62
  return;
63
63
  }
64
64
  if (record.ancestors.some(isFunctionNode)) {
@@ -69,7 +69,7 @@ async function recordCrudController(inspection, { module, file, record }) {
69
69
  warn(inspection, "CRUD_CONTROLLER_UNRESOLVED", "A CRUD controller declaration is dynamic.", file);
70
70
  return;
71
71
  }
72
- const resource = await resolveCrudResource(inspection, module, objectProperty(config, "resource"));
72
+ const resource = await resolveCrudResource(inspection, module, objectProperty(config, "crud"));
73
73
  const surface = staticValue(objectProperty(config, "surface"), module.bindings);
74
74
  const routes = objectProperty(config, "routes");
75
75
  if (routes && staticValue(routes, module.bindings) === false) {