@astrale-os/sdk 0.5.0-beta.99 → 0.6.0-beta.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.
- package/README.md +165 -2
- package/dist/application/action/action.d.ts +7 -4
- package/dist/application/action/authoring.d.ts +2 -1
- package/dist/application/action/context.d.ts +18 -13
- package/dist/application/action/define.d.ts +5 -1
- package/dist/application/action/define.js +6 -1
- package/dist/application/action/index.d.ts +2 -1
- package/dist/application/dependency/index.d.ts +1 -0
- package/dist/application/dependency/invoker.d.ts +26 -0
- package/dist/application/error/error.d.ts +23 -0
- package/dist/application/error/error.js +87 -0
- package/dist/application/error/index.d.ts +2 -0
- package/dist/application/error/index.js +1 -0
- package/dist/application/index.d.ts +2 -2
- package/dist/application/integration/authentication.d.ts +10 -0
- package/dist/application/integration/authentication.typecheck.js +18 -0
- package/dist/application/integration/client.d.ts +2 -0
- package/dist/application/integration/client.js +19 -2
- package/dist/application/integration/index.d.ts +1 -0
- package/dist/application/integration/operation.d.ts +3 -0
- package/dist/application/mutation/authoring/builder.js +2 -2
- package/dist/application/mutation/authoring/endpoint.d.ts +3 -3
- package/dist/application/mutation/authoring/endpoint.js +9 -0
- package/dist/application/mutation/failure.js +13 -7
- package/dist/application/mutation/index.d.ts +1 -0
- package/dist/application/requirements/{profiles.d.ts → core.d.ts} +5 -3
- package/dist/application/requirements/{profiles.js → core.js} +6 -6
- package/dist/application/requirements/index.d.ts +4 -4
- package/dist/application/requirements/index.js +5 -5
- package/dist/application/requirements/requirement.d.ts +3 -2
- package/dist/application/runtime/authoring.d.ts +1 -0
- package/dist/application/runtime/callables.js +2 -2
- package/dist/application/runtime/declarations.d.ts +43 -0
- package/dist/application/runtime/define.d.ts +2 -1
- package/dist/application/view/index.d.ts +1 -1
- package/dist/application/view/route.d.ts +4 -0
- package/dist/application/view/route.js +5 -1
- package/dist/application/workflow/authoring.d.ts +1 -0
- package/dist/application/workflow/context.d.ts +2 -1
- package/dist/application/workflow/define.d.ts +5 -1
- package/dist/application/workflow/define.js +6 -1
- package/dist/application/workflow/index.d.ts +1 -0
- package/dist/application/workflow/runner/runner.d.ts +3 -2
- package/dist/application/workflow/workflow.d.ts +4 -3
- package/dist/deployment/adapter/adapter.d.ts +12 -7
- package/dist/deployment/adapter/define.d.ts +5 -2
- package/dist/deployment/adapter/define.js +15 -17
- package/dist/deployment/adapter/deploy/context.d.ts +6 -0
- package/dist/deployment/adapter/deploy/result.d.ts +2 -0
- package/dist/deployment/adapter/index.d.ts +2 -3
- package/dist/deployment/adapter/index.js +1 -1
- package/dist/deployment/adapter/prepare/context.d.ts +13 -5
- package/dist/deployment/authoring.d.ts +1 -1
- package/dist/deployment/build/compile.js +21 -19
- package/dist/deployment/build/frontend/compilation.d.ts +2 -1
- package/dist/deployment/build/frontend/compilation.js +1 -0
- package/dist/deployment/build/material.js +5 -5
- package/dist/deployment/deploy.d.ts +10 -4
- package/dist/deployment/deploy.js +5 -5
- package/dist/deployment/deployment.d.ts +8 -5
- package/dist/deployment/deployment.js +10 -1
- package/dist/deployment/index.d.ts +5 -4
- package/dist/deployment/index.js +3 -2
- package/dist/deployment/release/addressing.d.ts +6 -2
- package/dist/deployment/release/addressing.js +9 -4
- package/dist/deployment/release/publication/callables.js +1 -1
- package/dist/deployment/release/publication/index.d.ts +1 -1
- package/dist/deployment/release/publication/index.js +1 -1
- package/dist/deployment/release/publication/routes.js +1 -1
- package/dist/deployment/release/publication/seal.d.ts +0 -1
- package/dist/deployment/release/publication/seal.js +4 -5
- package/dist/deployment/release/publication/views.js +2 -1
- package/dist/deployment/verify/preflight/artifact.js +1 -1
- package/dist/deployment/verify/readiness/deployment.js +7 -3
- package/dist/deployment/verify/readiness/identity.js +1 -1
- package/dist/deployment/verify/readiness/publication.js +2 -2
- package/dist/execution/identity/authentication.js +0 -1
- package/dist/execution/identity/exchange.d.ts +1 -0
- package/dist/execution/identity/exchange.js +1 -1
- package/dist/execution/identity/jwks.js +1 -1
- package/dist/execution/invocation/admission/authentication.d.ts +6 -3
- package/dist/execution/invocation/admission/authentication.js +16 -6
- package/dist/execution/invocation/admission/authority.d.ts +2 -2
- package/dist/execution/invocation/dependency/bind.d.ts +5 -0
- package/dist/execution/invocation/dependency/bind.js +68 -0
- package/dist/execution/invocation/dependency/index.d.ts +1 -0
- package/dist/execution/invocation/dependency/index.js +1 -0
- package/dist/execution/invocation/dispatch/action.js +19 -2
- package/dist/execution/invocation/dispatch/context.d.ts +4 -4
- package/dist/execution/invocation/dispatch/context.js +29 -9
- package/dist/execution/invocation/dispatch/workflow.js +17 -4
- package/dist/execution/invocation/integration/authentication.d.ts +5 -0
- package/dist/execution/invocation/integration/authentication.js +53 -0
- package/dist/execution/invocation/integration/call.d.ts +7 -1
- package/dist/execution/invocation/integration/call.js +8 -3
- package/dist/execution/invocation/integration/clients.d.ts +2 -2
- package/dist/execution/invocation/integration/clients.js +2 -2
- package/dist/execution/invocation/lifecycle/active.js +30 -5
- package/dist/execution/invocation/result/errors.d.ts +1 -0
- package/dist/execution/invocation/result/errors.js +15 -10
- package/dist/execution/service/create.js +3 -1
- package/dist/execution/service/service.d.ts +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/platform/auth/index.d.ts +1 -1
- package/dist/platform/auth/index.js +0 -1
- package/dist/platform/graph/alias.d.ts +6 -0
- package/dist/platform/graph/alias.js +6 -0
- package/dist/platform/graph/document/index.d.ts +2 -1
- package/dist/platform/graph/document/index.js +2 -1
- package/dist/platform/graph/index.d.ts +2 -1
- package/dist/platform/graph/index.js +2 -1
- package/dist/platform/schema/class-authoring.d.ts +37 -0
- package/dist/platform/schema/class-authoring.js +20 -0
- package/dist/platform/schema/class-icon.d.ts +15 -0
- package/dist/platform/schema/class-icon.js +46 -0
- package/dist/platform/schema/error.d.ts +11 -0
- package/dist/platform/schema/error.js +34 -0
- package/dist/platform/schema/errors/index.d.ts +3 -0
- package/dist/platform/schema/errors/index.js +2 -0
- package/dist/platform/schema/icons/index.d.ts +2 -0
- package/dist/platform/schema/icons/index.js +2 -0
- package/dist/platform/schema/index.d.ts +20 -13
- package/dist/platform/schema/index.js +9 -4
- package/dist/platform/schema/kernel.d.ts +22 -0
- package/dist/platform/schema/kernel.js +5 -0
- package/dist/platform/schema/node-id.d.ts +3 -0
- package/dist/platform/schema/node-id.js +6 -0
- package/dist/platform/schema/property.d.ts +12 -0
- package/dist/platform/schema/property.js +3 -0
- package/dist/platform/schema/schema-authoring.d.ts +48 -0
- package/dist/platform/schema/schema-authoring.js +3 -0
- package/dist/platform/schema/state-property.d.ts +11 -0
- package/dist/platform/schema/state-property.js +3 -0
- package/dist/project/admit.d.ts +4 -0
- package/dist/project/admit.js +22 -0
- package/dist/project/define.d.ts +12 -0
- package/dist/project/define.js +106 -0
- package/dist/project/index.d.ts +4 -0
- package/dist/project/index.js +2 -0
- package/dist/project/project.d.ts +24 -0
- package/dist/project/project.js +1 -0
- package/dist/testing/dataset/admission.d.ts +13 -0
- package/dist/testing/dataset/admission.js +107 -0
- package/dist/testing/dataset/builder.d.ts +42 -0
- package/dist/testing/dataset/builder.js +127 -0
- package/dist/testing/dataset/codec.d.ts +6 -0
- package/dist/testing/dataset/codec.js +113 -0
- package/dist/testing/dataset/dataset.d.ts +58 -0
- package/dist/testing/dataset/dataset.js +2 -0
- package/dist/testing/dataset/define.d.ts +33 -0
- package/dist/testing/dataset/define.js +105 -0
- package/dist/testing/dataset/index.d.ts +8 -0
- package/dist/testing/dataset/index.js +4 -0
- package/dist/testing/dataset/references.d.ts +14 -0
- package/dist/testing/dataset/references.js +56 -0
- package/dist/testing/index.d.ts +9 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/load.d.ts +14 -0
- package/dist/testing/load.js +44 -0
- package/dist/testing/reference.d.ts +11 -0
- package/dist/testing/reference.js +19 -0
- package/dist/testing/tests.d.ts +12 -0
- package/dist/testing/tests.js +31 -0
- package/dist/tooling/cli/arguments.d.ts +7 -4
- package/dist/tooling/cli/arguments.js +82 -107
- package/dist/tooling/cli/astrale/authority.d.ts +5 -0
- package/dist/tooling/cli/astrale/authority.js +11 -0
- package/dist/tooling/cli/astrale/executable.d.ts +2 -0
- package/dist/tooling/cli/astrale/executable.js +47 -0
- package/dist/tooling/cli/astrale/failure.d.ts +6 -0
- package/dist/tooling/cli/astrale/failure.js +48 -0
- package/dist/tooling/cli/astrale/instance.d.ts +11 -0
- package/dist/tooling/cli/astrale/instance.js +52 -0
- package/dist/tooling/cli/astrale/process.d.ts +13 -0
- package/dist/tooling/cli/astrale/process.js +94 -0
- package/dist/tooling/cli/astrale/version.d.ts +18 -0
- package/dist/tooling/cli/astrale/version.js +55 -0
- package/dist/tooling/cli/bun.js +1 -1
- package/dist/tooling/cli/credential.d.ts +2 -0
- package/dist/tooling/cli/credential.js +57 -0
- package/dist/tooling/cli/development/candidate.d.ts +25 -0
- package/dist/tooling/cli/development/candidate.js +176 -0
- package/dist/tooling/cli/development/deployment.d.ts +16 -0
- package/dist/tooling/cli/development/deployment.js +39 -0
- package/dist/tooling/cli/development/develop.d.ts +4 -3
- package/dist/tooling/cli/development/develop.js +125 -289
- package/dist/tooling/cli/development/lease.d.ts +18 -0
- package/dist/tooling/cli/development/lease.js +163 -0
- package/dist/tooling/cli/development/lifecycle.js +4 -0
- package/dist/tooling/cli/development/project-imports.d.ts +22 -0
- package/dist/tooling/cli/development/project-imports.js +39 -0
- package/dist/tooling/cli/development/project-lock.d.ts +3 -4
- package/dist/tooling/cli/development/project-lock.js +14 -166
- package/dist/tooling/cli/development/release-evidence.d.ts +4 -0
- package/dist/tooling/cli/development/release-evidence.js +10 -0
- package/dist/tooling/cli/development/report.d.ts +6 -0
- package/dist/tooling/cli/development/report.js +14 -0
- package/dist/tooling/cli/development/source-watch.js +53 -5
- package/dist/tooling/cli/development/sources.d.ts +7 -0
- package/dist/tooling/cli/development/sources.js +48 -0
- package/dist/tooling/cli/development/target-lock.d.ts +16 -0
- package/dist/tooling/cli/development/target-lock.js +68 -0
- package/dist/tooling/cli/development/view.d.ts +28 -0
- package/dist/tooling/cli/development/view.js +151 -0
- package/dist/tooling/cli/environment-release.d.ts +21 -0
- package/dist/tooling/cli/environment-release.js +46 -0
- package/dist/tooling/cli/evidence.d.ts +11 -0
- package/dist/tooling/cli/evidence.js +53 -0
- package/dist/tooling/cli/help.js +78 -34
- package/dist/tooling/cli/index.d.ts +1 -1
- package/dist/tooling/cli/index.js +1 -1
- package/dist/tooling/cli/installation/index.d.ts +2 -0
- package/dist/tooling/cli/installation/index.js +1 -0
- package/dist/tooling/cli/installation/observation.d.ts +10 -0
- package/dist/tooling/cli/installation/observation.js +44 -0
- package/dist/tooling/cli/installation/reconcile.d.ts +32 -0
- package/dist/tooling/cli/installation/reconcile.js +122 -0
- package/dist/tooling/cli/orchestrate.js +84 -44
- package/dist/tooling/cli/project.d.ts +17 -0
- package/dist/tooling/cli/project.js +18 -0
- package/dist/tooling/cli/test.d.ts +12 -0
- package/dist/tooling/cli/test.js +47 -0
- package/dist/tooling/cli/upgrade/index.d.ts +6 -0
- package/dist/tooling/cli/upgrade/index.js +115 -0
- package/dist/tooling/cli/upgrade/manifest.d.ts +18 -0
- package/dist/tooling/cli/upgrade/manifest.js +77 -0
- package/dist/tooling/cli/upgrade/process.d.ts +2 -0
- package/dist/tooling/cli/upgrade/process.js +57 -0
- package/dist/tooling/linter/adapters/typescript/imports.js +2 -0
- package/dist/tooling/linter/adapters/typescript/index.d.ts +1 -0
- package/dist/tooling/linter/adapters/typescript/index.js +1 -0
- package/dist/tooling/linter/adapters/typescript/query-collection-type.js +4 -51
- package/dist/tooling/linter/adapters/typescript/type-analysis.d.ts +9 -0
- package/dist/tooling/linter/adapters/typescript/type-analysis.js +55 -0
- package/dist/tooling/linter/implementations/source/callable-requirements.d.ts +28 -0
- package/dist/tooling/linter/implementations/source/callable-requirements.js +234 -0
- package/dist/tooling/linter/implementations/source/dependencies.d.ts +2 -0
- package/dist/tooling/linter/implementations/source/dependencies.js +219 -0
- package/dist/tooling/linter/implementations/source/global.js +52 -2
- package/dist/tooling/linter/implementations/source/mutations.js +520 -38
- package/dist/tooling/linter/implementations/source/providers.js +19 -164
- package/dist/tooling/linter/implementations/source/schema.js +454 -2
- package/dist/tooling/linter/implementations/source/verifiers.js +2 -0
- package/dist/tooling/linter/implementations/source/workflows.js +8 -35
- package/dist/tooling/linter/policy/generated.js +2 -2
- package/dist/tooling/linter/requirements/registry.js +9 -3
- package/dist/tooling/packaging/declarations/normalize.js +3 -38
- package/dist/tooling/packaging/declarations/paths.d.ts +5 -0
- package/dist/tooling/packaging/declarations/paths.js +38 -0
- package/dist/tooling/packaging/finalize.d.ts +13 -0
- package/dist/tooling/packaging/finalize.js +62 -0
- package/dist/tooling/packaging/index.d.ts +2 -0
- package/dist/tooling/packaging/index.js +1 -0
- package/dist/tooling/packaging/javascript.d.ts +3 -0
- package/dist/tooling/packaging/javascript.js +45 -2
- package/dist/tooling/packaging/packaging.d.ts +2 -5
- package/dist/tooling/packaging/packaging.js +6 -30
- package/package.json +42 -12
- package/CHANGELOG.md +0 -1506
- package/dist/deployment/adapter/development/context.d.ts +0 -18
- package/dist/deployment/adapter/development/index.d.ts +0 -4
- package/dist/deployment/adapter/development/input.d.ts +0 -6
- package/dist/deployment/adapter/development/placement.d.ts +0 -15
- package/dist/deployment/adapter/development/session.d.ts +0 -9
- /package/dist/{deployment/adapter/development → application/dependency}/index.js +0 -0
- /package/dist/{deployment/adapter/development/context.js → application/dependency/invoker.js} +0 -0
- /package/dist/{deployment/adapter/development/input.js → application/integration/authentication.js} +0 -0
- /package/dist/{deployment/adapter/development/placement.js → application/integration/authentication.typecheck.d.ts} +0 -0
- /package/dist/{deployment/adapter/development/session.js → application/runtime/declarations.js} +0 -0
|
@@ -1,10 +1,94 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { isLocalAlias } from '../../../../platform/graph/alias.js';
|
|
3
|
+
import { expressionType, importedSymbol, propertyChain, staticText, unwrap, visit, } from '../../adapters/typescript/index.js';
|
|
4
|
+
import { ambiguity, callback, calls, DSL_MODULES, definitionOriginAmbiguity, definitionObjects, domainProjectorEvidence, forbiddenIoImport, hasForbiddenGlobalCall, production, violation, } from './shared.js';
|
|
4
5
|
import { stateMachineIdentity, statePropertyIdentity } from './state-machine.js';
|
|
5
6
|
const FORBIDDEN_LAYERS = new Set(['integrations', 'functions', 'providers', 'queries']);
|
|
6
7
|
const FORBIDDEN_CALLS = new Set(['invoke', 'query', 'retry', 'run', 'submit']);
|
|
7
8
|
export const mutationRules = [
|
|
9
|
+
{
|
|
10
|
+
id: 'MUT-PLAN-REQ',
|
|
11
|
+
ruleRevision: '9201a4e5799f62cc8df37d281d1f02516132632e33b4a82187c399780bdfe340',
|
|
12
|
+
evaluate(project) {
|
|
13
|
+
const evidence = [];
|
|
14
|
+
const targets = [];
|
|
15
|
+
for (const file of production(project, 'mutations')) {
|
|
16
|
+
const builderScopes = mutationBuilderScopes(file);
|
|
17
|
+
visit(file.source, (node) => {
|
|
18
|
+
if (!ts.isCallExpression(node))
|
|
19
|
+
return;
|
|
20
|
+
const operation = mutationBuilderOperation(node, builderScopes);
|
|
21
|
+
if (operation === undefined)
|
|
22
|
+
return;
|
|
23
|
+
const classOperation = classOperationForBuilder(operation);
|
|
24
|
+
if (classOperation === undefined)
|
|
25
|
+
return;
|
|
26
|
+
const input = staticObject(node.arguments[0]);
|
|
27
|
+
const selectedClass = input && assignedValue(input, 'class');
|
|
28
|
+
const target = selectedClass && dependencyClassTarget(selectedClass);
|
|
29
|
+
if (selectedClass !== undefined && target !== undefined) {
|
|
30
|
+
targets.push({ file, node: selectedClass, ...target, operation: classOperation });
|
|
31
|
+
}
|
|
32
|
+
else if (selectedClass && expressionSelectsDependency(selectedClass)) {
|
|
33
|
+
evidence.push(ambiguity(file, selectedClass, 'Mutation plan selects a foreign Class dynamically, so its Application requirement cannot be proven.'));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const identityCalls = [];
|
|
38
|
+
for (const file of production(project, 'functions')) {
|
|
39
|
+
visit(file.source, (node) => {
|
|
40
|
+
if (ts.isCallExpression(node) && kernelProvisionCall(node)) {
|
|
41
|
+
identityCalls.push({ file, node, syscall: 'provision' });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
for (const node of kernelRegisterCalls(file))
|
|
45
|
+
identityCalls.push({ file, node, syscall: 'register' });
|
|
46
|
+
}
|
|
47
|
+
if (targets.length === 0 && identityCalls.length === 0)
|
|
48
|
+
return evidence;
|
|
49
|
+
const requirements = applicationPlanRequirements(project);
|
|
50
|
+
for (const target of targets) {
|
|
51
|
+
const key = classRequirementKey(target.dependency, target.className, target.operation);
|
|
52
|
+
if (requirements.classes.has(key))
|
|
53
|
+
continue;
|
|
54
|
+
evidence.push(requirements.indeterminate
|
|
55
|
+
? ambiguity(target.file, target.node, `Application Class requirements are opaque for dependency ${target.dependency} Class ${target.className}.`)
|
|
56
|
+
: violation(target.file, target.node, `Mutation plan dependency ${target.dependency} Class ${target.className} lacks Application ${target.operation} authority.`));
|
|
57
|
+
}
|
|
58
|
+
for (const invocation of identityCalls) {
|
|
59
|
+
if (!requirements.functions.has(invocation.syscall)) {
|
|
60
|
+
const name = invocation.syscall === 'register' ? 'Register' : 'Provision';
|
|
61
|
+
evidence.push(requirements.indeterminate
|
|
62
|
+
? ambiguity(invocation.file, invocation.node, `Application Function requirements are opaque for Kernel ${name}.`)
|
|
63
|
+
: violation(invocation.file, invocation.node, `Kernel ${name} invocation lacks the exact Application Function requirement.`));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return evidence;
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: 'MUT-LOCAL-ALIAS',
|
|
71
|
+
ruleRevision: '9c2a55b932a3f63428701b0d613c4f8c8015a2444bd42f922bdc4921850c37cb',
|
|
72
|
+
evaluate(project) {
|
|
73
|
+
const evidence = [];
|
|
74
|
+
for (const file of production(project, 'mutations')) {
|
|
75
|
+
const builderScopes = mutationBuilderScopes(file);
|
|
76
|
+
visit(file.source, (node) => {
|
|
77
|
+
if (!ts.isCallExpression(node) ||
|
|
78
|
+
mutationBuilderMember(node, builderScopes) !== 'createNode') {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const input = staticObject(node.arguments[0]);
|
|
82
|
+
const alias = input && assignedValue(input, 'as');
|
|
83
|
+
const literal = alias && staticText(alias);
|
|
84
|
+
if (alias === undefined || literal === undefined || isLocalAlias(literal))
|
|
85
|
+
return;
|
|
86
|
+
evidence.push(violation(file, alias, `Mutation createNode local alias ${JSON.stringify(literal)} is invalid; use 1-64 ASCII letters, digits, or underscores and start with a letter.`));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return evidence;
|
|
90
|
+
},
|
|
91
|
+
},
|
|
8
92
|
{
|
|
9
93
|
id: 'MUT-STATE-INITIAL',
|
|
10
94
|
ruleRevision: 'd88f178994e9ad56d14f50ad5ffdff398413e42a690985c5ddc669c0f293d9bb',
|
|
@@ -120,7 +204,15 @@ export const mutationRules = [
|
|
|
120
204
|
const setValue = assignedValue(props, 'set');
|
|
121
205
|
const set = staticObject(setValue);
|
|
122
206
|
if (setValue !== undefined && !set) {
|
|
123
|
-
|
|
207
|
+
const typed = typedPatchMachineProperties(project, file, setValue, selected);
|
|
208
|
+
if (typed === undefined) {
|
|
209
|
+
evidence.push(ambiguity(file, setValue, 'Mutation updateNode set patch is dynamic and may bypass a StateMachine transition.'));
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
for (const property of typed) {
|
|
213
|
+
evidence.push(violation(file, setValue, `Mutation updateNode patch type permits machine-backed property ${property}; use transition for one atomic compare-and-set.`));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
124
216
|
}
|
|
125
217
|
if (set && hasSpread(set)) {
|
|
126
218
|
evidence.push(ambiguity(file, set, 'Mutation updateNode set patch contains a spread that may bypass a StateMachine transition.'));
|
|
@@ -313,11 +405,15 @@ export const mutationRules = [
|
|
|
313
405
|
const build = object && callback(object, 'build');
|
|
314
406
|
if (!build)
|
|
315
407
|
continue;
|
|
408
|
+
const builderName = build.parameters[1]?.name;
|
|
316
409
|
visitOwnBody(build, (node) => {
|
|
317
410
|
if (!ts.isCallExpression(node))
|
|
318
411
|
return;
|
|
319
412
|
const symbol = importedSymbol(file, node.expression);
|
|
320
413
|
const chain = propertyChain(node.expression);
|
|
414
|
+
if (builderName && ts.isIdentifier(builderName) && chain?.[0] === builderName.text) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
321
417
|
const name = symbol?.name;
|
|
322
418
|
if (name && FORBIDDEN_CALLS.has(name)) {
|
|
323
419
|
evidence.push(violation(file, node, `Mutation definition invokes ${name}.`));
|
|
@@ -368,6 +464,43 @@ function staticStringArray(expression) {
|
|
|
368
464
|
}
|
|
369
465
|
return strings;
|
|
370
466
|
}
|
|
467
|
+
function typedPatchMachineProperties(project, file, expression, machineProperties) {
|
|
468
|
+
const resolved = expressionType(project, file, expression);
|
|
469
|
+
if (resolved === undefined)
|
|
470
|
+
return undefined;
|
|
471
|
+
const properties = typePropertyNames(resolved.checker, resolved.type);
|
|
472
|
+
if (properties === undefined)
|
|
473
|
+
return undefined;
|
|
474
|
+
return [...machineProperties.keys()].filter((name) => properties.has(name));
|
|
475
|
+
}
|
|
476
|
+
function typePropertyNames(checker, type) {
|
|
477
|
+
if (type.flags &
|
|
478
|
+
(ts.TypeFlags.Any |
|
|
479
|
+
ts.TypeFlags.Unknown |
|
|
480
|
+
ts.TypeFlags.Never |
|
|
481
|
+
ts.TypeFlags.Null |
|
|
482
|
+
ts.TypeFlags.Undefined)) {
|
|
483
|
+
return undefined;
|
|
484
|
+
}
|
|
485
|
+
if (type.isUnionOrIntersection()) {
|
|
486
|
+
const properties = new Set();
|
|
487
|
+
for (const member of type.types) {
|
|
488
|
+
const names = typePropertyNames(checker, member);
|
|
489
|
+
if (names === undefined)
|
|
490
|
+
return undefined;
|
|
491
|
+
for (const name of names)
|
|
492
|
+
properties.add(name);
|
|
493
|
+
}
|
|
494
|
+
return properties;
|
|
495
|
+
}
|
|
496
|
+
const apparent = checker.getApparentType(type);
|
|
497
|
+
if (apparent.getStringIndexType() !== undefined ||
|
|
498
|
+
apparent.getNumberIndexType() !== undefined ||
|
|
499
|
+
!(apparent.flags & ts.TypeFlags.Object)) {
|
|
500
|
+
return undefined;
|
|
501
|
+
}
|
|
502
|
+
return new Set(apparent.getProperties().map(({ name }) => name));
|
|
503
|
+
}
|
|
371
504
|
function mutationBuilderScopes(file) {
|
|
372
505
|
const mutable = new Map();
|
|
373
506
|
const pending = [];
|
|
@@ -387,6 +520,16 @@ function mutationBuilderScopes(file) {
|
|
|
387
520
|
if (build && builder && ts.isIdentifier(builder))
|
|
388
521
|
add(build, builder);
|
|
389
522
|
}
|
|
523
|
+
visit(file.source, (node) => {
|
|
524
|
+
if (!ts.isCallExpression(node) || !mutationAstBuild(file, node))
|
|
525
|
+
return;
|
|
526
|
+
const build = node.arguments[0] && unwrap(node.arguments[0]);
|
|
527
|
+
if (build &&
|
|
528
|
+
(ts.isArrowFunction(build) || ts.isFunctionExpression(build)) &&
|
|
529
|
+
ts.isIdentifier(build.parameters[0]?.name)) {
|
|
530
|
+
add(build, build.parameters[0].name);
|
|
531
|
+
}
|
|
532
|
+
});
|
|
390
533
|
const richBuilderTypes = new Set();
|
|
391
534
|
for (const sourceImport of file.imports) {
|
|
392
535
|
if (sourceImport.specifier !== '@astrale-os/sdk' &&
|
|
@@ -446,6 +589,15 @@ function mutationBuilderScopes(file) {
|
|
|
446
589
|
}
|
|
447
590
|
return mutable;
|
|
448
591
|
}
|
|
592
|
+
function mutationAstBuild(file, call) {
|
|
593
|
+
const expression = unwrap(call.expression);
|
|
594
|
+
if (!ts.isPropertyAccessExpression(expression) || expression.name.text !== 'build')
|
|
595
|
+
return false;
|
|
596
|
+
const owner = unwrap(expression.expression);
|
|
597
|
+
const symbol = importedSymbol(file, owner);
|
|
598
|
+
return (symbol?.name === 'MutationAST' &&
|
|
599
|
+
(symbol.module === '@astrale-os/sdk' || symbol.module === '@astrale-os/sdk/mutation'));
|
|
600
|
+
}
|
|
449
601
|
function mutationBuilderMember(call, scopes) {
|
|
450
602
|
const owner = containingFunction(call);
|
|
451
603
|
const builders = owner && scopes.get(owner);
|
|
@@ -468,6 +620,249 @@ function mutationBuilderMember(call, scopes) {
|
|
|
468
620
|
return undefined;
|
|
469
621
|
return destructuredBuilderMember(expression, builders);
|
|
470
622
|
}
|
|
623
|
+
function mutationBuilderOperation(call, scopes) {
|
|
624
|
+
const owner = containingFunction(call);
|
|
625
|
+
const builders = owner && scopes.get(owner);
|
|
626
|
+
if (!owner || !builders)
|
|
627
|
+
return undefined;
|
|
628
|
+
const chain = propertyChain(call.expression);
|
|
629
|
+
if (!chain || chain.length < 2)
|
|
630
|
+
return mutationBuilderMember(call, scopes);
|
|
631
|
+
const root = firstIdentifier(unwrap(call.expression));
|
|
632
|
+
if (!root || !builders.has(identifierDeclaration(root)))
|
|
633
|
+
return undefined;
|
|
634
|
+
return chain.slice(1).join('.');
|
|
635
|
+
}
|
|
636
|
+
function firstIdentifier(expression) {
|
|
637
|
+
let current = expression;
|
|
638
|
+
while (ts.isPropertyAccessExpression(current) || ts.isElementAccessExpression(current)) {
|
|
639
|
+
current = unwrap(current.expression);
|
|
640
|
+
}
|
|
641
|
+
return ts.isIdentifier(current) ? current : undefined;
|
|
642
|
+
}
|
|
643
|
+
function classOperationForBuilder(operation) {
|
|
644
|
+
switch (operation) {
|
|
645
|
+
case 'createNode':
|
|
646
|
+
case 'createEdge':
|
|
647
|
+
return 'create';
|
|
648
|
+
case 'expect.node':
|
|
649
|
+
case 'expect.edge':
|
|
650
|
+
return 'read';
|
|
651
|
+
case 'updateNode':
|
|
652
|
+
case 'updateEdge':
|
|
653
|
+
case 'transition':
|
|
654
|
+
return 'update';
|
|
655
|
+
case 'deleteNode':
|
|
656
|
+
case 'deleteEdge':
|
|
657
|
+
return 'delete';
|
|
658
|
+
default:
|
|
659
|
+
return undefined;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function dependencyClassTarget(expression) {
|
|
663
|
+
const chain = staticPropertyChain(expression);
|
|
664
|
+
if (!chain)
|
|
665
|
+
return undefined;
|
|
666
|
+
const dependency = chain.indexOf('dependencies');
|
|
667
|
+
const suffix = chain.at(-1) === 'key' ? chain.slice(0, -1) : chain;
|
|
668
|
+
if (dependency < 0 || suffix.length !== dependency + 4 || suffix[dependency + 2] !== 'classes') {
|
|
669
|
+
return undefined;
|
|
670
|
+
}
|
|
671
|
+
return { dependency: suffix[dependency + 1], className: suffix[dependency + 3] };
|
|
672
|
+
}
|
|
673
|
+
function expressionSelectsDependency(expression) {
|
|
674
|
+
const chain = staticPropertyChain(expression);
|
|
675
|
+
return chain?.includes('dependencies') ?? false;
|
|
676
|
+
}
|
|
677
|
+
function kernelProvisionCall(call) {
|
|
678
|
+
const chain = propertyChain(call.expression);
|
|
679
|
+
if (chain?.length === 4 &&
|
|
680
|
+
chain[0] === 'kernel' &&
|
|
681
|
+
chain[1] === 'self' &&
|
|
682
|
+
chain[2] === 'auth' &&
|
|
683
|
+
chain[3] === 'provision') {
|
|
684
|
+
const root = firstIdentifier(unwrap(call.expression));
|
|
685
|
+
return root !== undefined && parameterProperty(root, 'kernel');
|
|
686
|
+
}
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
/** Only context-owned Client calls in publicly resolved SDK handlers, not lookalike objects. */
|
|
690
|
+
function kernelRegisterCalls(file) {
|
|
691
|
+
const result = [];
|
|
692
|
+
for (const { call: factory, origin } of [
|
|
693
|
+
...calls(file, 'defineAction'),
|
|
694
|
+
...calls(file, 'defineWorkflow'),
|
|
695
|
+
]) {
|
|
696
|
+
if (origin !== 'resolved')
|
|
697
|
+
continue;
|
|
698
|
+
const definition = ts.isCallExpression(factory.parent) && factory.parent.expression === factory
|
|
699
|
+
? factory.parent
|
|
700
|
+
: factory;
|
|
701
|
+
const argument = definition.arguments.at(-1);
|
|
702
|
+
const handler = argument && unwrap(argument);
|
|
703
|
+
if (!handler || (!ts.isArrowFunction(handler) && !ts.isFunctionExpression(handler)))
|
|
704
|
+
continue;
|
|
705
|
+
const parameter = handler.parameters[0]?.name;
|
|
706
|
+
if (!parameter)
|
|
707
|
+
continue;
|
|
708
|
+
const roots = [];
|
|
709
|
+
if (ts.isIdentifier(parameter))
|
|
710
|
+
roots.push({ declaration: parameter, prefix: [parameter.text, 'client'] });
|
|
711
|
+
else if (ts.isObjectBindingPattern(parameter)) {
|
|
712
|
+
for (const element of parameter.elements) {
|
|
713
|
+
const property = element.propertyName ?? element.name;
|
|
714
|
+
if (ts.isIdentifier(element.name) &&
|
|
715
|
+
ts.isIdentifier(property) &&
|
|
716
|
+
property.text === 'client')
|
|
717
|
+
roots.push({ declaration: element.name, prefix: [element.name.text] });
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
visit(handler, (node) => {
|
|
721
|
+
if (!ts.isCallExpression(node))
|
|
722
|
+
return;
|
|
723
|
+
const chain = propertyChain(node.expression);
|
|
724
|
+
const root = firstIdentifier(unwrap(node.expression));
|
|
725
|
+
if (!chain || !root)
|
|
726
|
+
return;
|
|
727
|
+
if (roots.some(({ declaration, prefix }) => identifierDeclaration(root) === declaration &&
|
|
728
|
+
chain.join('.') === [...prefix, 'auth', 'register'].join('.')))
|
|
729
|
+
result.push(node);
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
return result;
|
|
733
|
+
}
|
|
734
|
+
function parameterProperty(use, sourceName) {
|
|
735
|
+
const binding = identifierDeclaration(use);
|
|
736
|
+
if (binding === undefined)
|
|
737
|
+
return false;
|
|
738
|
+
if (ts.isParameter(binding.parent) && binding.parent.name === binding) {
|
|
739
|
+
return binding.text === sourceName;
|
|
740
|
+
}
|
|
741
|
+
const element = binding.parent;
|
|
742
|
+
if (!ts.isBindingElement(element) ||
|
|
743
|
+
element.name !== binding ||
|
|
744
|
+
!ts.isObjectBindingPattern(element.parent) ||
|
|
745
|
+
!ts.isParameter(element.parent.parent)) {
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
const property = element.propertyName ?? element.name;
|
|
749
|
+
return (ts.isIdentifier(property) || ts.isStringLiteral(property)) && property.text === sourceName;
|
|
750
|
+
}
|
|
751
|
+
function applicationPlanRequirements(project) {
|
|
752
|
+
const applicationPath = project.policy.rootFiles.find(({ id }) => id === 'application')?.sourcePath;
|
|
753
|
+
const file = applicationPath && project.filesByPath.get(applicationPath);
|
|
754
|
+
if (!file)
|
|
755
|
+
return emptyPlanRequirements(true);
|
|
756
|
+
const applications = [];
|
|
757
|
+
visit(file.source, (node) => {
|
|
758
|
+
if (!ts.isCallExpression(node))
|
|
759
|
+
return;
|
|
760
|
+
const symbol = importedSymbol(file, node.expression);
|
|
761
|
+
if (symbol?.name === 'defineApplication' &&
|
|
762
|
+
(symbol.module === '@astrale-os/sdk' || symbol.module === '@astrale-os/sdk/application')) {
|
|
763
|
+
applications.push(node);
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
if (applications.length !== 1)
|
|
767
|
+
return emptyPlanRequirements(true);
|
|
768
|
+
const input = staticObject(applications[0].arguments[0]);
|
|
769
|
+
const requirementValue = input && assignedValue(input, 'requirements');
|
|
770
|
+
if (requirementValue === undefined)
|
|
771
|
+
return emptyPlanRequirements(false);
|
|
772
|
+
const requirementCall = staticCall(requirementValue);
|
|
773
|
+
const requirementSymbol = requirementCall && importedSymbol(file, requirementCall.expression);
|
|
774
|
+
if (!requirementCall ||
|
|
775
|
+
requirementSymbol?.name !== 'requirements' ||
|
|
776
|
+
(requirementSymbol.module !== '@astrale-os/sdk' &&
|
|
777
|
+
requirementSymbol.module !== '@astrale-os/sdk/application')) {
|
|
778
|
+
return emptyPlanRequirements(true);
|
|
779
|
+
}
|
|
780
|
+
const definition = staticObject(requirementCall.arguments[0]);
|
|
781
|
+
if (!definition)
|
|
782
|
+
return emptyPlanRequirements(requirementCall.arguments[0] !== undefined);
|
|
783
|
+
const functions = new Set();
|
|
784
|
+
const classes = new Set();
|
|
785
|
+
let indeterminate = false;
|
|
786
|
+
const functionValues = staticArray(assignedValue(definition, 'functions'));
|
|
787
|
+
if (assignedValue(definition, 'functions') !== undefined && !functionValues)
|
|
788
|
+
indeterminate = true;
|
|
789
|
+
for (const value of functionValues?.elements ?? []) {
|
|
790
|
+
if (!ts.isExpression(value)) {
|
|
791
|
+
indeterminate = true;
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
const chain = staticPropertyChain(value);
|
|
795
|
+
if (chain?.at(-2) !== 'functions' || chain.at(-1) === undefined)
|
|
796
|
+
indeterminate = true;
|
|
797
|
+
else
|
|
798
|
+
functions.add(chain.at(-1));
|
|
799
|
+
}
|
|
800
|
+
const classValues = staticArray(assignedValue(definition, 'classes'));
|
|
801
|
+
if (assignedValue(definition, 'classes') !== undefined && !classValues)
|
|
802
|
+
indeterminate = true;
|
|
803
|
+
for (const value of classValues?.elements ?? []) {
|
|
804
|
+
if (!ts.isExpression(value)) {
|
|
805
|
+
indeterminate = true;
|
|
806
|
+
continue;
|
|
807
|
+
}
|
|
808
|
+
const object = staticObject(value);
|
|
809
|
+
const selected = object && assignedValue(object, 'class');
|
|
810
|
+
const target = selected && resolvedDependencyClassTarget(file, selected);
|
|
811
|
+
const operationValue = object && assignedValue(object, 'operations');
|
|
812
|
+
const operations = operationValue && staticStringArray(operationValue);
|
|
813
|
+
if (!target || !operations || operations.length === 0) {
|
|
814
|
+
indeterminate = true;
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
for (const { value: operation } of operations) {
|
|
818
|
+
if (operation === 'create' ||
|
|
819
|
+
operation === 'read' ||
|
|
820
|
+
operation === 'update' ||
|
|
821
|
+
operation === 'delete') {
|
|
822
|
+
classes.add(classRequirementKey(target.dependency, target.className, operation));
|
|
823
|
+
}
|
|
824
|
+
else if (operation !== 'traverse') {
|
|
825
|
+
indeterminate = true;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
return { functions, classes, indeterminate };
|
|
830
|
+
}
|
|
831
|
+
function emptyPlanRequirements(indeterminate) {
|
|
832
|
+
return { functions: new Set(), classes: new Set(), indeterminate };
|
|
833
|
+
}
|
|
834
|
+
function staticCall(expression) {
|
|
835
|
+
const value = unwrap(expression);
|
|
836
|
+
if (ts.isIdentifier(value)) {
|
|
837
|
+
const initializer = visibleConstInitializer(value);
|
|
838
|
+
return initializer && staticCall(initializer);
|
|
839
|
+
}
|
|
840
|
+
return ts.isCallExpression(value) ? value : undefined;
|
|
841
|
+
}
|
|
842
|
+
function resolvedDependencyClassTarget(file, expression) {
|
|
843
|
+
let current = unwrap(expression);
|
|
844
|
+
const selector = [];
|
|
845
|
+
while (ts.isPropertyAccessExpression(current)) {
|
|
846
|
+
selector.unshift(current.name.text);
|
|
847
|
+
current = unwrap(current.expression);
|
|
848
|
+
}
|
|
849
|
+
if (selector.length !== 4 ||
|
|
850
|
+
selector[0] !== 'dependencies' ||
|
|
851
|
+
selector[2] !== 'classes' ||
|
|
852
|
+
!ts.isCallExpression(current)) {
|
|
853
|
+
return undefined;
|
|
854
|
+
}
|
|
855
|
+
const resolve = unwrap(current.expression);
|
|
856
|
+
if (!ts.isPropertyAccessExpression(resolve) || resolve.name.text !== 'resolve')
|
|
857
|
+
return undefined;
|
|
858
|
+
const schema = importedSymbol(file, resolve.expression);
|
|
859
|
+
if (schema?.name !== 'schema' || schema.module !== '@astrale-os/sdk/schema')
|
|
860
|
+
return undefined;
|
|
861
|
+
return { dependency: selector[1], className: selector[3] };
|
|
862
|
+
}
|
|
863
|
+
function classRequirementKey(dependency, className, operation) {
|
|
864
|
+
return `${dependency}\0${className}\0${operation}`;
|
|
865
|
+
}
|
|
471
866
|
function destructuredBuilderMember(callee, builders) {
|
|
472
867
|
const calleeBinding = identifierDeclaration(callee);
|
|
473
868
|
const element = calleeBinding?.parent;
|
|
@@ -643,7 +1038,8 @@ function machinePropertiesByClass(project) {
|
|
|
643
1038
|
ambiguousByClass.set(owner, names);
|
|
644
1039
|
mutableByClass.delete(owner);
|
|
645
1040
|
}
|
|
646
|
-
|
|
1041
|
+
const topology = classTopology(project);
|
|
1042
|
+
inheritMachineProperties(topology.parents, mutableByClass, ambiguousByClass);
|
|
647
1043
|
for (const file of production(project, 'schema')) {
|
|
648
1044
|
for (const definition of definitionObjects(file, 'defineSchema', undefined, DSL_MODULES, 1)) {
|
|
649
1045
|
if (definition.origin !== 'resolved')
|
|
@@ -693,34 +1089,10 @@ function machinePropertiesByClass(project) {
|
|
|
693
1089
|
all,
|
|
694
1090
|
byClass: mutableByClass,
|
|
695
1091
|
ambiguousByClass,
|
|
1092
|
+
...topology,
|
|
696
1093
|
};
|
|
697
1094
|
}
|
|
698
|
-
function inheritMachineProperties(
|
|
699
|
-
const parents = new Map();
|
|
700
|
-
for (const file of production(project, 'schema')) {
|
|
701
|
-
visit(file.source, (node) => {
|
|
702
|
-
if (!ts.isCallExpression(node))
|
|
703
|
-
return;
|
|
704
|
-
const symbol = importedSymbol(file, node.expression);
|
|
705
|
-
if (symbol?.name !== 'nodeClass' || !DSL_MODULES.has(symbol.module))
|
|
706
|
-
return;
|
|
707
|
-
const owner = containingVariableName(node);
|
|
708
|
-
const object = staticObject(node.arguments[0]);
|
|
709
|
-
const extended = object && staticArray(assignedValue(object, 'extends'));
|
|
710
|
-
if (owner === undefined || extended === undefined)
|
|
711
|
-
return;
|
|
712
|
-
const names = parents.get(owner) ?? new Set();
|
|
713
|
-
for (const expression of extended.elements) {
|
|
714
|
-
if (!ts.isExpression(expression))
|
|
715
|
-
continue;
|
|
716
|
-
const chain = staticPropertyChain(expression);
|
|
717
|
-
const name = chain?.at(-1);
|
|
718
|
-
if (name !== undefined)
|
|
719
|
-
names.add(name);
|
|
720
|
-
}
|
|
721
|
-
parents.set(owner, names);
|
|
722
|
-
});
|
|
723
|
-
}
|
|
1095
|
+
function inheritMachineProperties(parents, byClass, ambiguousByClass) {
|
|
724
1096
|
let changed = true;
|
|
725
1097
|
while (changed) {
|
|
726
1098
|
changed = false;
|
|
@@ -762,6 +1134,42 @@ function inheritMachineProperties(project, byClass, ambiguousByClass) {
|
|
|
762
1134
|
}
|
|
763
1135
|
}
|
|
764
1136
|
}
|
|
1137
|
+
function classTopology(project) {
|
|
1138
|
+
const classes = new Set();
|
|
1139
|
+
const abstractClasses = new Set();
|
|
1140
|
+
const parents = new Map();
|
|
1141
|
+
for (const file of production(project, 'schema')) {
|
|
1142
|
+
visit(file.source, (node) => {
|
|
1143
|
+
if (!ts.isCallExpression(node))
|
|
1144
|
+
return;
|
|
1145
|
+
const symbol = importedSymbol(file, node.expression);
|
|
1146
|
+
if (symbol?.name !== 'nodeClass' || !DSL_MODULES.has(symbol.module))
|
|
1147
|
+
return;
|
|
1148
|
+
const owner = containingVariableName(node);
|
|
1149
|
+
const object = staticObject(node.arguments[0]);
|
|
1150
|
+
if (owner === undefined || object === undefined)
|
|
1151
|
+
return;
|
|
1152
|
+
classes.add(owner);
|
|
1153
|
+
if (assignedValue(object, 'abstract')?.kind === ts.SyntaxKind.TrueKeyword) {
|
|
1154
|
+
abstractClasses.add(owner);
|
|
1155
|
+
}
|
|
1156
|
+
const extended = staticArray(assignedValue(object, 'extends'));
|
|
1157
|
+
if (extended === undefined)
|
|
1158
|
+
return;
|
|
1159
|
+
const names = parents.get(owner) ?? new Set();
|
|
1160
|
+
for (const expression of extended.elements) {
|
|
1161
|
+
if (!ts.isExpression(expression))
|
|
1162
|
+
continue;
|
|
1163
|
+
const chain = propertyChain(expression) ?? staticPropertyChain(expression);
|
|
1164
|
+
const name = chain?.at(-1);
|
|
1165
|
+
if (name !== undefined)
|
|
1166
|
+
names.add(name);
|
|
1167
|
+
}
|
|
1168
|
+
parents.set(owner, names);
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
return { classes, abstractClasses, parents };
|
|
1172
|
+
}
|
|
765
1173
|
function containingVariableName(node) {
|
|
766
1174
|
let current = node;
|
|
767
1175
|
while (current && !ts.isSourceFile(current)) {
|
|
@@ -774,15 +1182,83 @@ function containingVariableName(node) {
|
|
|
774
1182
|
}
|
|
775
1183
|
function propertiesForClass(input, properties) {
|
|
776
1184
|
const selectedClass = assignedValue(input, 'class');
|
|
777
|
-
const
|
|
778
|
-
if (
|
|
779
|
-
return { kind: 'ambiguous' };
|
|
780
|
-
const className = chain.at(-1);
|
|
781
|
-
if ((properties.ambiguousByClass.get(className)?.size ?? 0) > 0) {
|
|
1185
|
+
const selection = selectedClass && selectedClassNames(selectedClass);
|
|
1186
|
+
if (selection === undefined || !closedClassSelection(selection, properties)) {
|
|
782
1187
|
return { kind: 'ambiguous' };
|
|
783
1188
|
}
|
|
784
|
-
const
|
|
785
|
-
|
|
1189
|
+
const resolved = new Map();
|
|
1190
|
+
let hasMachineProperty = false;
|
|
1191
|
+
for (const className of selection) {
|
|
1192
|
+
if ((properties.ambiguousByClass.get(className)?.size ?? 0) > 0) {
|
|
1193
|
+
return { kind: 'ambiguous' };
|
|
1194
|
+
}
|
|
1195
|
+
const selected = properties.byClass.get(className);
|
|
1196
|
+
if (selected === undefined)
|
|
1197
|
+
continue;
|
|
1198
|
+
hasMachineProperty = true;
|
|
1199
|
+
for (const [name, identity] of selected) {
|
|
1200
|
+
const prior = resolved.get(name);
|
|
1201
|
+
if (prior !== undefined && prior !== identity)
|
|
1202
|
+
return { kind: 'ambiguous' };
|
|
1203
|
+
resolved.set(name, identity);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
return hasMachineProperty ? { kind: 'resolved', properties: resolved } : { kind: 'absent' };
|
|
1207
|
+
}
|
|
1208
|
+
function selectedClassNames(expression, seen = new Set()) {
|
|
1209
|
+
const value = unwrap(expression);
|
|
1210
|
+
if (ts.isConditionalExpression(value)) {
|
|
1211
|
+
const whenTrue = selectedClassNames(value.whenTrue, seen);
|
|
1212
|
+
const whenFalse = selectedClassNames(value.whenFalse, seen);
|
|
1213
|
+
return whenTrue && whenFalse ? new Set([...whenTrue, ...whenFalse]) : undefined;
|
|
1214
|
+
}
|
|
1215
|
+
if (ts.isIdentifier(value)) {
|
|
1216
|
+
if (seen.has(value.text))
|
|
1217
|
+
return undefined;
|
|
1218
|
+
const initializer = visibleConstInitializer(value);
|
|
1219
|
+
if (initializer !== undefined) {
|
|
1220
|
+
const next = new Set(seen);
|
|
1221
|
+
next.add(value.text);
|
|
1222
|
+
return selectedClassNames(initializer, next);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
const chain = staticPropertyChain(value);
|
|
1226
|
+
if (!chain || chain.length < 2)
|
|
1227
|
+
return undefined;
|
|
1228
|
+
const className = chain.at(-1) === 'key' ? chain.at(-2) : chain.at(-1);
|
|
1229
|
+
return className === undefined ? undefined : new Set([className]);
|
|
1230
|
+
}
|
|
1231
|
+
function closedClassSelection(selection, topology) {
|
|
1232
|
+
if (selection.size === 0)
|
|
1233
|
+
return false;
|
|
1234
|
+
if (selection.size === 1)
|
|
1235
|
+
return true;
|
|
1236
|
+
if ([...selection].some((name) => !topology.classes.has(name)))
|
|
1237
|
+
return false;
|
|
1238
|
+
if ([...selection].some((name) => topology.abstractClasses.has(name)))
|
|
1239
|
+
return false;
|
|
1240
|
+
for (const ancestor of topology.abstractClasses) {
|
|
1241
|
+
if (![...selection].every((name) => ancestorsOf(name, topology.parents).has(ancestor))) {
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
const descendants = [...topology.classes].filter((name) => !topology.abstractClasses.has(name) && ancestorsOf(name, topology.parents).has(ancestor));
|
|
1245
|
+
if (descendants.length === selection.size && descendants.every((name) => selection.has(name))) {
|
|
1246
|
+
return true;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
return false;
|
|
1250
|
+
}
|
|
1251
|
+
function ancestorsOf(className, parents) {
|
|
1252
|
+
const ancestors = new Set();
|
|
1253
|
+
const pending = [...(parents.get(className) ?? [])];
|
|
1254
|
+
while (pending.length > 0) {
|
|
1255
|
+
const parent = pending.pop();
|
|
1256
|
+
if (ancestors.has(parent))
|
|
1257
|
+
continue;
|
|
1258
|
+
ancestors.add(parent);
|
|
1259
|
+
pending.push(...(parents.get(parent) ?? []));
|
|
1260
|
+
}
|
|
1261
|
+
return ancestors;
|
|
786
1262
|
}
|
|
787
1263
|
function hasMachineCandidates(properties) {
|
|
788
1264
|
return properties.all.size > 0 || properties.ambiguousByClass.size > 0;
|
|
@@ -828,7 +1304,13 @@ function staticPropertyName(property) {
|
|
|
828
1304
|
ts.isNumericLiteral(property.name)) {
|
|
829
1305
|
return property.name.text;
|
|
830
1306
|
}
|
|
831
|
-
|
|
1307
|
+
if (!ts.isComputedPropertyName(property.name))
|
|
1308
|
+
return undefined;
|
|
1309
|
+
const literal = staticText(property.name.expression);
|
|
1310
|
+
if (literal !== undefined)
|
|
1311
|
+
return literal;
|
|
1312
|
+
const chain = staticPropertyChain(property.name.expression);
|
|
1313
|
+
return chain?.at(-1) === 'key' ? chain.at(-2) : undefined;
|
|
832
1314
|
}
|
|
833
1315
|
function initialIdentity(project, file, expression, seen = new Set()) {
|
|
834
1316
|
const value = unwrap(expression);
|