Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export type PslDiagnosticCode =
| 'PSL_UNSUPPORTED_MODEL_ATTRIBUTE'
| 'PSL_UNSUPPORTED_FIELD_ATTRIBUTE'
| 'PSL_INVALID_RELATION_ATTRIBUTE'
/**
* A quoted arrow-path `through:` value that does not parse as the
* four-segment `"localKey -> Junction.nearColumn -> Junction.farColumn ->
* Target.targetKey"` form.
*/
| 'PSL_ARROW_PATH_MALFORMED'
| 'PSL_INVALID_REFERENTIAL_ACTION'
| 'PSL_INVALID_DEFAULT_VALUE'
| 'PSL_INVALID_ENUM_MEMBER'
Expand Down
12 changes: 12 additions & 0 deletions packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import {
} from './psl-field-resolution';
import { resolveNamedTypeDeclarations } from './psl-named-type-resolution';
import {
type ArrowPath,
applyBackrelationCandidates,
type FkRelationMetadata,
indexFkRelations,
Expand Down Expand Up @@ -568,6 +569,7 @@ function buildModelNodeFromPsl(input: BuildModelNodeInput): BuildModelNodeResult
});
const relationAttribute = getAttribute(field.attributes, 'relation');
let through: ParsedThrough | undefined;
let arrowPath: ArrowPath | undefined;
let inverse: string | undefined;
if (relationAttribute) {
const parsedRelation = interpretRelationAttribute({
Expand Down Expand Up @@ -600,6 +602,7 @@ function buildModelNodeFromPsl(input: BuildModelNodeInput): BuildModelNodeResult
continue;
}
through = parsedRelation.through;
arrowPath = parsedRelation.arrowPath;
inverse = parsedRelation.inverse;
}
if (!attributesValid) {
Expand All @@ -612,6 +615,7 @@ function buildModelNodeFromPsl(input: BuildModelNodeInput): BuildModelNodeResult
field,
targetModelName: field.typeName,
...ifDefined('through', through),
...ifDefined('arrowPath', arrowPath),
...ifDefined('inverse', inverse),
});
}
Expand Down Expand Up @@ -2158,19 +2162,27 @@ export function interpretPslDocumentToSqlContract(
const modelIdColumns = new Map<string, readonly string[]>();
const modelTableNames = new Map<string, string>();
const declaredTableNames = new Set<string>();
// Field-name → storage-column maps per model, so an arrow-path `through:` can
// resolve its path-named columns straight from the declared models.
const modelFieldColumns = new Map<string, ReadonlyMap<string, string>>();
for (const modelNode of modelNodes) {
if (modelNode.id) {
modelIdColumns.set(modelNode.modelName, modelNode.id.columns);
}
modelTableNames.set(modelNode.modelName, modelNode.tableName);
declaredTableNames.add(modelNode.modelName);
declaredTableNames.add(modelNode.tableName);
modelFieldColumns.set(
modelNode.modelName,
new Map(modelNode.fields.map((field) => [field.fieldName, field.columnName])),
);
}
const { synthesizedJunctions } = applyBackrelationCandidates({
backrelationCandidates,
fkRelationsByPair,
fkRelationsByDeclaringModel,
modelIdColumns,
modelFieldColumns,
modelTableNames,
modelNamespaceIds,
declaredTableNames,
Expand Down
Loading
Loading