@prisma-next/psl-parser 0.14.0-dev.9 → 0.14.0-dev.90

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 (60) hide show
  1. package/dist/{declarations-D9h_ihD3.mjs → declarations-DR6To8_k.mjs} +295 -55
  2. package/dist/declarations-DR6To8_k.mjs.map +1 -0
  3. package/dist/format.d.mts +1 -1
  4. package/dist/format.mjs +2 -2
  5. package/dist/index.d.mts +115 -107
  6. package/dist/index.d.mts.map +1 -1
  7. package/dist/index.mjs +437 -60
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/interpret.d.mts +39 -0
  10. package/dist/interpret.d.mts.map +1 -0
  11. package/dist/interpret.mjs +25 -0
  12. package/dist/interpret.mjs.map +1 -0
  13. package/dist/{parse-BjZ1LPe6.d.mts → parse-BazJr7Ye.d.mts} +128 -51
  14. package/dist/parse-BazJr7Ye.d.mts.map +1 -0
  15. package/dist/{parse-DhEV6av6.mjs → parse-CdeXr0T3.mjs} +28 -7
  16. package/dist/parse-CdeXr0T3.mjs.map +1 -0
  17. package/dist/symbol-table-C-AH04Ug.d.mts +127 -0
  18. package/dist/symbol-table-C-AH04Ug.d.mts.map +1 -0
  19. package/dist/syntax.d.mts +20 -2
  20. package/dist/syntax.d.mts.map +1 -1
  21. package/dist/syntax.mjs +43 -3
  22. package/dist/syntax.mjs.map +1 -0
  23. package/package.json +10 -7
  24. package/src/attribute-spec/combinators/bool.ts +19 -0
  25. package/src/attribute-spec/combinators/diagnostic.ts +15 -0
  26. package/src/attribute-spec/combinators/entity-ref.ts +24 -0
  27. package/src/attribute-spec/combinators/field-ref.ts +36 -0
  28. package/src/attribute-spec/combinators/func-call.ts +65 -0
  29. package/src/attribute-spec/combinators/identifier.ts +16 -0
  30. package/src/attribute-spec/combinators/int.ts +35 -0
  31. package/src/attribute-spec/combinators/list.ts +43 -0
  32. package/src/attribute-spec/combinators/num.ts +26 -0
  33. package/src/attribute-spec/combinators/one-of.ts +29 -0
  34. package/src/attribute-spec/combinators/record.ts +43 -0
  35. package/src/attribute-spec/combinators/str.ts +19 -0
  36. package/src/attribute-spec/field-attribute.ts +27 -0
  37. package/src/attribute-spec/interpret.ts +177 -0
  38. package/src/attribute-spec/model-attribute.ts +27 -0
  39. package/src/attribute-spec/optional.ts +8 -0
  40. package/src/attribute-spec/types.ts +72 -0
  41. package/src/block-reconstruction.ts +1 -0
  42. package/src/exports/index.ts +34 -0
  43. package/src/exports/interpret.ts +2 -0
  44. package/src/exports/syntax.ts +25 -5
  45. package/src/interpret.ts +67 -0
  46. package/src/parse.ts +23 -5
  47. package/src/resolve.ts +4 -1
  48. package/src/source-file.ts +25 -0
  49. package/src/syntax/ast/attributes.ts +5 -6
  50. package/src/syntax/ast/declarations.ts +51 -26
  51. package/src/syntax/ast/expressions.ts +12 -13
  52. package/src/syntax/ast/identifier.ts +2 -3
  53. package/src/syntax/ast/qualified-name.ts +28 -19
  54. package/src/syntax/ast/type-annotation.ts +4 -5
  55. package/src/syntax/ast-helpers.ts +27 -3
  56. package/src/syntax/navigation.ts +55 -0
  57. package/src/syntax/red.ts +317 -42
  58. package/dist/declarations-D9h_ihD3.mjs.map +0 -1
  59. package/dist/parse-BjZ1LPe6.d.mts.map +0 -1
  60. package/dist/parse-DhEV6av6.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/attribute-helpers.ts","../src/extension-block.ts","../src/resolve.ts","../src/block-reconstruction.ts","../src/symbol-table.ts"],"sourcesContent":["import type { PslAttribute } from '@prisma-next/framework-components/psl-ast';\n\nexport function getPositionalArgument(attribute: PslAttribute, index = 0): string | undefined {\n const entries = attribute.args.filter((arg) => arg.kind === 'positional');\n return entries[index]?.value;\n}\n\nexport function parseQuotedStringLiteral(value: string): string | undefined {\n const trimmed = value.trim();\n const match = trimmed.match(/^(['\"])(.*)\\1$/);\n if (!match) return undefined;\n return match[2] ?? '';\n}\n","import {\n type AuthoringPslBlockDescriptor,\n type AuthoringPslBlockDescriptorNamespace,\n isAuthoringPslBlockDescriptor,\n} from '@prisma-next/framework-components/authoring';\nimport type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport {\n makePslNamespace,\n makePslNamespaceEntries,\n type PslDiagnostic,\n type PslModel,\n type PslSpan,\n UNSPECIFIED_PSL_NAMESPACE_ID,\n validateExtensionBlock,\n} from '@prisma-next/framework-components/psl-ast';\nimport type { SourceFile } from './source-file';\nimport type { BlockSymbol, ModelSymbol, SymbolTable } from './symbol-table';\n\nexport function findBlockDescriptor(\n descriptors: AuthoringPslBlockDescriptorNamespace | undefined,\n keyword: string,\n): AuthoringPslBlockDescriptor | undefined {\n if (descriptors === undefined) return undefined;\n for (const value of Object.values(descriptors)) {\n if (value === undefined) continue;\n if (isAuthoringPslBlockDescriptor(value)) {\n if (value.keyword === keyword) return value;\n continue;\n }\n const nested = findBlockDescriptor(value, keyword);\n if (nested !== undefined) return nested;\n }\n return undefined;\n}\n\nexport function validateExtensionBlockFromSymbol(input: {\n readonly block: BlockSymbol;\n readonly descriptor: AuthoringPslBlockDescriptor;\n readonly symbolTable: SymbolTable;\n readonly sourceFile: SourceFile;\n readonly sourceId: string;\n readonly codecLookup: CodecLookup;\n}): readonly PslDiagnostic[] {\n const refCtx = buildRefResolutionContext(input.symbolTable, input.block);\n return validateExtensionBlock(\n input.block.block,\n input.descriptor,\n input.sourceId,\n input.codecLookup,\n refCtx,\n );\n}\n\nconst ZERO_SPAN: PslSpan = {\n start: { offset: 0, line: 1, column: 1 },\n end: { offset: 0, line: 1, column: 1 },\n};\n\nfunction buildRefResolutionContext(\n symbolTable: SymbolTable,\n block: BlockSymbol,\n): {\n ownerNamespace: ReturnType<typeof makePslNamespace>;\n allNamespaces: readonly ReturnType<typeof makePslNamespace>[];\n} {\n const unspecifiedNamespace = makeNamespace(\n UNSPECIFIED_PSL_NAMESPACE_ID,\n Object.values(symbolTable.topLevel.models),\n );\n const namedNamespaces = Object.values(symbolTable.topLevel.namespaces).map((namespace) =>\n makeNamespace(namespace.name, Object.values(namespace.models)),\n );\n const allNamespaces = [unspecifiedNamespace, ...namedNamespaces];\n const ownerNamespaceName = findOwnerNamespaceName(symbolTable, block);\n const ownerNamespace =\n allNamespaces.find((namespace) => namespace.name === ownerNamespaceName) ??\n unspecifiedNamespace;\n return { ownerNamespace, allNamespaces };\n}\n\nfunction makeNamespace(\n name: string,\n models: readonly ModelSymbol[],\n): ReturnType<typeof makePslNamespace> {\n const modelStubs: PslModel[] = models.map((model) => ({\n kind: 'model',\n name: model.name,\n fields: [],\n attributes: [],\n span: ZERO_SPAN,\n }));\n return makePslNamespace({\n kind: 'namespace',\n name,\n entries: makePslNamespaceEntries(modelStubs, [], []),\n span: ZERO_SPAN,\n });\n}\n\nfunction findOwnerNamespaceName(symbolTable: SymbolTable, block: BlockSymbol): string {\n for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {\n if (Object.values(namespace.blocks).some((candidate) => candidate === block)) {\n return namespace.name;\n }\n }\n return UNSPECIFIED_PSL_NAMESPACE_ID;\n}\n","import type { PslSpan } from '@prisma-next/framework-components/psl-ast';\nimport type { Position, Range, SourceFile } from './source-file';\nimport type {\n AttributeArgListAst,\n FieldAttributeAst,\n ModelAttributeAst,\n} from './syntax/ast/attributes';\nimport type { ExpressionAst } from './syntax/ast/expressions';\nimport type { QualifiedNameAst } from './syntax/ast/qualified-name';\nimport type { TypeAnnotationAst } from './syntax/ast/type-annotation';\nimport { printSyntax } from './syntax/ast-helpers';\nimport type { SyntaxNode } from './syntax/red';\n\nexport interface ResolvedAttributeArg {\n readonly kind: 'positional' | 'named';\n readonly name?: string;\n readonly value: string;\n readonly span: PslSpan;\n}\n\nexport interface ResolvedAttribute {\n readonly name: string;\n readonly args: readonly ResolvedAttributeArg[];\n readonly span: PslSpan;\n}\n\nexport interface ResolvedTypeConstructorCall {\n readonly path: readonly string[];\n readonly args: readonly ResolvedAttributeArg[];\n readonly span: PslSpan;\n}\n\nexport function readResolvedAttribute(\n attribute: FieldAttributeAst | ModelAttributeAst,\n sourceFile: SourceFile,\n): ResolvedAttribute {\n return {\n name: attributeName(attribute.name()),\n args: readResolvedArgList(attribute.argList(), sourceFile),\n span: nodePslSpan(attribute.syntax, sourceFile),\n };\n}\n\nexport function readResolvedAttributes(\n attributes: Iterable<FieldAttributeAst | ModelAttributeAst>,\n sourceFile: SourceFile,\n): readonly ResolvedAttribute[] {\n return Array.from(attributes, (attribute) => readResolvedAttribute(attribute, sourceFile));\n}\n\nexport function readResolvedConstructorCall(\n annotation: TypeAnnotationAst | undefined,\n sourceFile: SourceFile,\n): ResolvedTypeConstructorCall | undefined {\n const argList = annotation?.argList();\n if (annotation === undefined || argList === undefined) return undefined;\n return {\n path: annotation.name()?.path() ?? [],\n args: readResolvedArgList(argList, sourceFile),\n span: nodePslSpan(annotation.syntax, sourceFile),\n };\n}\n\nfunction readResolvedArgList(\n argList: AttributeArgListAst | undefined,\n sourceFile: SourceFile,\n): readonly ResolvedAttributeArg[] {\n if (argList === undefined) return [];\n const args: ResolvedAttributeArg[] = [];\n for (const arg of argList.args()) {\n const name = arg.name()?.name();\n args.push({\n kind: name !== undefined ? 'named' : 'positional',\n ...(name !== undefined ? { name } : {}),\n value: renderExpression(arg.value()),\n span: nodePslSpan(arg.syntax, sourceFile),\n });\n }\n return args;\n}\n\nfunction attributeName(name: QualifiedNameAst | undefined): string {\n return name?.path().join('.') ?? '';\n}\n\nfunction renderExpression(expression: ExpressionAst | undefined): string {\n if (expression === undefined) return '';\n return printSyntax(expression.syntax).trim();\n}\n\nexport function nodePslSpan(node: SyntaxNode, sourceFile: SourceFile): PslSpan {\n const start = node.offset;\n const end = start + node.green.textLength;\n return {\n start: offsetToPslPosition(start, sourceFile),\n end: offsetToPslPosition(end, sourceFile),\n };\n}\n\n/** Unsupported-top-level-block diagnostics are anchored to the keyword token. */\nexport function keywordPslSpan(node: SyntaxNode, keyword: string, sourceFile: SourceFile): PslSpan {\n const start = node.offset;\n const end = start + keyword.length;\n return {\n start: offsetToPslPosition(start, sourceFile),\n end: offsetToPslPosition(end, sourceFile),\n };\n}\n\nexport function rangeToPslSpan(range: Range, sourceFile: SourceFile): PslSpan {\n return {\n start: offsetToPslPosition(sourceFile.offsetAt(range.start), sourceFile),\n end: offsetToPslPosition(sourceFile.offsetAt(range.end), sourceFile),\n };\n}\n\nfunction offsetToPslPosition(offset: number, sourceFile: SourceFile): PslSpan['start'] {\n const position: Position = sourceFile.positionAt(offset);\n return { offset, line: position.line + 1, column: position.character + 1 };\n}\n","import type { AuthoringPslBlockDescriptor } from '@prisma-next/framework-components/authoring';\nimport type {\n PslBlockParam,\n PslExtensionBlock,\n PslExtensionBlockAttribute,\n PslExtensionBlockParamValue,\n PslSpan,\n} from '@prisma-next/framework-components/psl-ast';\nimport type { ParseDiagnostic } from './parse';\nimport { nodePslSpan } from './resolve';\nimport type { SourceFile } from './source-file';\nimport type { GenericBlockDeclarationAst, KeyValuePairAst } from './syntax/ast/declarations';\nimport { ArrayLiteralAst, type ExpressionAst } from './syntax/ast/expressions';\nimport { printSyntax } from './syntax/ast-helpers';\n\n/**\n * Descriptor-free and unknown parameters become `value` stubs so validation can\n * report them via key-set comparison. Duplicate member names are first-wins.\n */\nexport function reconstructExtensionBlock(\n node: GenericBlockDeclarationAst,\n descriptor: AuthoringPslBlockDescriptor | undefined,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): PslExtensionBlock {\n const keyword = node.keyword()?.text ?? '';\n const blockName = node.name()?.name() ?? '';\n\n const blockAttributes: PslExtensionBlockAttribute[] = [];\n for (const attribute of node.attributes()) {\n const name = attribute.name()?.path().join('.') ?? '';\n const args = Array.from(attribute.argList()?.args() ?? [], (arg) => {\n const value = arg.value();\n return {\n kind: 'positional' as const,\n value: value === undefined ? '' : printSyntax(value.syntax).trim(),\n span: nodePslSpan(arg.syntax, sourceFile),\n };\n });\n blockAttributes.push({\n name,\n args,\n span: nodePslSpan(attribute.syntax, sourceFile),\n });\n }\n\n const parameters: Record<string, PslExtensionBlockParamValue> = {};\n for (const entry of node.entries()) {\n const key = entry.key()?.name();\n if (key === undefined) continue;\n const span = nodePslSpan(entry.syntax, sourceFile);\n if (Object.hasOwn(parameters, key)) {\n diagnostics.push({\n code: 'PSL_EXTENSION_DUPLICATE_PARAMETER',\n message: `Duplicate parameter \"${key}\" in \"${keyword}\" block \"${blockName}\"; first occurrence wins`,\n range: {\n start: sourceFile.positionAt(entry.syntax.offset),\n end: sourceFile.positionAt(entry.syntax.offset + entry.syntax.green.textLength),\n },\n });\n continue;\n }\n parameters[key] = reconstructParamValue(\n entry,\n descriptor?.parameters[key],\n span,\n sourceFile,\n diagnostics,\n );\n }\n\n return {\n kind: descriptor?.discriminator ?? keyword,\n name: blockName,\n parameters,\n blockAttributes,\n span: nodePslSpan(node.syntax, sourceFile),\n };\n}\n\nfunction reconstructParamValue(\n entry: KeyValuePairAst,\n param: PslBlockParam | undefined,\n span: PslSpan,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): PslExtensionBlockParamValue {\n const value = entry.value();\n if (value === undefined) {\n return { kind: 'bare', span };\n }\n return reconstructFromExpression(value, param, span, sourceFile, diagnostics);\n}\n\nfunction reconstructFromExpression(\n value: ExpressionAst,\n param: PslBlockParam | undefined,\n span: PslSpan,\n sourceFile: SourceFile,\n diagnostics?: ParseDiagnostic[],\n): PslExtensionBlockParamValue {\n const raw = printSyntax(value.syntax).trim();\n if (param?.kind === 'list') {\n const array = ArrayLiteralAst.cast(value.syntax);\n if (!array) {\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `List parameter expects an array literal, got ${raw}`,\n range: {\n start: sourceFile.positionAt(value.syntax.offset),\n end: sourceFile.positionAt(value.syntax.offset + value.syntax.green.textLength),\n },\n });\n return { kind: 'value', raw, span };\n }\n\n const items: PslExtensionBlockParamValue[] = [];\n for (const element of array.elements()) {\n items.push(\n reconstructFromExpression(\n element,\n param.of,\n nodePslSpan(element.syntax, sourceFile),\n sourceFile,\n diagnostics,\n ),\n );\n }\n return { kind: 'list', items, span };\n }\n switch (param?.kind) {\n case 'ref':\n return { kind: 'ref', identifier: raw, span };\n case 'option':\n return { kind: 'option', token: raw, span };\n default:\n return { kind: 'value', raw, span };\n }\n}\n","import type { AuthoringPslBlockDescriptorNamespace } from '@prisma-next/framework-components/authoring';\nimport type { PslExtensionBlock, PslSpan } from '@prisma-next/framework-components/psl-ast';\nimport { reconstructExtensionBlock } from './block-reconstruction';\nimport { findBlockDescriptor } from './extension-block';\nimport type { ParseDiagnostic } from './parse';\nimport {\n nodePslSpan,\n type ResolvedAttribute,\n type ResolvedTypeConstructorCall,\n readResolvedAttributes,\n readResolvedConstructorCall,\n} from './resolve';\nimport type { Range, SourceFile } from './source-file';\nimport {\n CompositeTypeDeclarationAst,\n type DocumentAst,\n type FieldDeclarationAst,\n GenericBlockDeclarationAst,\n ModelDeclarationAst,\n type NamedTypeDeclarationAst,\n NamespaceDeclarationAst,\n TypesBlockAst,\n} from './syntax/ast/declarations';\nimport type { IdentifierAst } from './syntax/ast/identifier';\nimport type { SyntaxNode } from './syntax/red';\n\nexport type {\n ResolvedAttribute,\n ResolvedAttributeArg,\n ResolvedTypeConstructorCall,\n} from './resolve';\n\nexport interface SymbolTable {\n readonly topLevel: TopLevelScope;\n}\n\nexport interface TopLevelScope {\n readonly namespaces: Record<string, NamespaceSymbol>;\n readonly scalars: Record<string, ScalarSymbol>;\n readonly typeAliases: Record<string, TypeAliasSymbol>;\n readonly blocks: Record<string, BlockSymbol>;\n readonly models: Record<string, ModelSymbol>;\n readonly compositeTypes: Record<string, CompositeTypeSymbol>;\n}\n\nexport interface NamespaceSymbol {\n readonly kind: 'namespace';\n readonly name: string;\n readonly node: NamespaceDeclarationAst;\n readonly span: PslSpan;\n readonly models: Record<string, ModelSymbol>;\n readonly compositeTypes: Record<string, CompositeTypeSymbol>;\n readonly blocks: Record<string, BlockSymbol>;\n}\n\nexport interface ModelSymbol {\n readonly kind: 'model';\n readonly name: string;\n readonly node: ModelDeclarationAst;\n readonly span: PslSpan;\n readonly fields: Record<string, FieldSymbol>;\n readonly attributes: readonly ResolvedAttribute[];\n}\n\nexport interface CompositeTypeSymbol {\n readonly kind: 'compositeType';\n readonly name: string;\n readonly node: CompositeTypeDeclarationAst;\n readonly span: PslSpan;\n readonly fields: Record<string, FieldSymbol>;\n readonly attributes: readonly ResolvedAttribute[];\n}\n\nexport interface BlockSymbol {\n readonly kind: 'block';\n readonly name: string;\n readonly keyword: string;\n readonly node: GenericBlockDeclarationAst;\n readonly span: PslSpan;\n /** Resolved once so consumers do not independently classify block parameters. */\n readonly block: PslExtensionBlock;\n}\n\nexport interface ResolvedNamedTypeBinding {\n readonly baseType?: string;\n readonly typeConstructor?: ResolvedTypeConstructorCall;\n readonly isConstructor: boolean;\n readonly attributes: readonly ResolvedAttribute[];\n}\n\nexport interface ScalarSymbol extends ResolvedNamedTypeBinding {\n readonly kind: 'scalar';\n readonly name: string;\n readonly node: NamedTypeDeclarationAst;\n readonly span: PslSpan;\n}\n\nexport interface TypeAliasSymbol extends ResolvedNamedTypeBinding {\n readonly kind: 'typeAlias';\n readonly name: string;\n readonly node: NamedTypeDeclarationAst;\n readonly span: PslSpan;\n}\n\nexport interface FieldSymbol {\n readonly kind: 'field';\n readonly name: string;\n readonly node: FieldDeclarationAst;\n readonly span: PslSpan;\n readonly typeName: string;\n readonly typeNamespaceId?: string;\n readonly typeContractSpaceId?: string;\n readonly optional: boolean;\n readonly list: boolean;\n readonly typeConstructor?: ResolvedTypeConstructorCall;\n readonly attributes: readonly ResolvedAttribute[];\n /** Prevents cascading unsupported-type diagnostics after invalid qualification. */\n readonly malformedType?: boolean;\n}\n\nexport interface BuildSymbolTableOptions {\n readonly document: DocumentAst;\n readonly sourceFile: SourceFile;\n readonly scalarTypes: readonly string[];\n readonly pslBlockDescriptors: AuthoringPslBlockDescriptorNamespace;\n}\n\nexport interface SymbolTableResult {\n readonly table: SymbolTable;\n readonly diagnostics: readonly ParseDiagnostic[];\n}\n\n/**\n * Owns duplicate-declaration detection for all PSL scopes; downstream consumers\n * should consume first-wins symbols rather than re-emitting duplicate diagnostics.\n */\nexport function buildSymbolTable(options: BuildSymbolTableOptions): SymbolTableResult {\n const { document, sourceFile, scalarTypes, pslBlockDescriptors } = options;\n const diagnostics: ParseDiagnostic[] = [];\n const scalarSet = new Set(scalarTypes);\n\n const namespaces: Record<string, NamespaceSymbol> = {};\n const scalars: Record<string, ScalarSymbol> = {};\n const typeAliases: Record<string, TypeAliasSymbol> = {};\n const blocks: Record<string, BlockSymbol> = {};\n const models: Record<string, ModelSymbol> = {};\n const compositeTypes: Record<string, CompositeTypeSymbol> = {};\n const topLevelNames = new Set<string>();\n\n const claim = (taken: Set<string>, name: IdentifierAst | undefined): string | undefined => {\n const text = name?.name();\n if (text === undefined) return undefined;\n if (taken.has(text)) {\n const range = nameRange(name, sourceFile);\n if (range) {\n diagnostics.push({\n code: 'PSL_DUPLICATE_DECLARATION',\n message: `Duplicate declaration of \"${text}\"`,\n range,\n });\n }\n return undefined;\n }\n taken.add(text);\n return text;\n };\n\n for (const declaration of document.declarations()) {\n if (declaration instanceof ModelDeclarationAst) {\n const name = claim(topLevelNames, declaration.name());\n if (name !== undefined) models[name] = buildModel(name, declaration, sourceFile, diagnostics);\n } else if (declaration instanceof CompositeTypeDeclarationAst) {\n const name = claim(topLevelNames, declaration.name());\n if (name !== undefined) {\n compositeTypes[name] = buildCompositeType(name, declaration, sourceFile, diagnostics);\n }\n } else if (declaration instanceof GenericBlockDeclarationAst) {\n const name = claim(topLevelNames, declaration.name());\n if (name !== undefined) {\n blocks[name] = buildBlock(name, declaration, sourceFile, pslBlockDescriptors, diagnostics);\n }\n } else if (declaration instanceof NamespaceDeclarationAst) {\n const name = claim(topLevelNames, declaration.name());\n if (name !== undefined) {\n namespaces[name] = buildNamespace(\n name,\n declaration,\n diagnostics,\n sourceFile,\n pslBlockDescriptors,\n );\n }\n } else if (declaration instanceof TypesBlockAst) {\n for (const binding of declaration.declarations()) {\n const name = claim(topLevelNames, binding.name());\n if (name === undefined) continue;\n const resolved = resolveNamedTypeBinding(binding, sourceFile);\n const span = nodePslSpan(binding.syntax, sourceFile);\n if (isScalarBinding(binding, scalarSet)) {\n scalars[name] = { kind: 'scalar', name, node: binding, span, ...resolved };\n } else {\n typeAliases[name] = { kind: 'typeAlias', name, node: binding, span, ...resolved };\n }\n }\n }\n }\n\n const table: SymbolTable = {\n topLevel: { namespaces, scalars, typeAliases, blocks, models, compositeTypes },\n };\n return { table, diagnostics };\n}\n\nfunction buildModel(\n name: string,\n node: ModelDeclarationAst,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): ModelSymbol {\n return {\n kind: 'model',\n name,\n node,\n span: nodePslSpan(node.syntax, sourceFile),\n fields: buildFields(name, node.fields(), sourceFile, diagnostics),\n attributes: readResolvedAttributes(node.attributes(), sourceFile),\n };\n}\n\nfunction buildCompositeType(\n name: string,\n node: CompositeTypeDeclarationAst,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): CompositeTypeSymbol {\n return {\n kind: 'compositeType',\n name,\n node,\n span: nodePslSpan(node.syntax, sourceFile),\n fields: buildFields(name, node.fields(), sourceFile, diagnostics),\n attributes: readResolvedAttributes(node.attributes(), sourceFile),\n };\n}\n\nfunction buildBlock(\n name: string,\n node: GenericBlockDeclarationAst,\n sourceFile: SourceFile,\n pslBlockDescriptors: AuthoringPslBlockDescriptorNamespace,\n diagnostics: ParseDiagnostic[],\n): BlockSymbol {\n const keyword = node.keyword()?.text ?? '';\n const descriptor = findBlockDescriptor(pslBlockDescriptors, keyword);\n return {\n kind: 'block',\n name,\n keyword,\n node,\n span: nodePslSpan(node.syntax, sourceFile),\n block: reconstructExtensionBlock(node, descriptor, sourceFile, diagnostics),\n };\n}\n\nfunction buildNamespace(\n name: string,\n node: NamespaceDeclarationAst,\n diagnostics: ParseDiagnostic[],\n sourceFile: SourceFile,\n pslBlockDescriptors: AuthoringPslBlockDescriptorNamespace,\n): NamespaceSymbol {\n const models: Record<string, ModelSymbol> = {};\n const compositeTypes: Record<string, CompositeTypeSymbol> = {};\n const blocks: Record<string, BlockSymbol> = {};\n const taken = new Set<string>();\n\n for (const member of node.declarations()) {\n const memberName = member.name()?.name();\n if (memberName === undefined) continue;\n if (taken.has(memberName)) {\n const range = nameRange(member.name(), sourceFile);\n if (range) {\n diagnostics.push({\n code: 'PSL_DUPLICATE_DECLARATION',\n message: `Duplicate declaration of \"${memberName}\"`,\n range,\n });\n }\n continue;\n }\n taken.add(memberName);\n if (member instanceof ModelDeclarationAst) {\n models[memberName] = buildModel(memberName, member, sourceFile, diagnostics);\n } else if (member instanceof CompositeTypeDeclarationAst) {\n compositeTypes[memberName] = buildCompositeType(memberName, member, sourceFile, diagnostics);\n } else if (member instanceof GenericBlockDeclarationAst) {\n blocks[memberName] = buildBlock(\n memberName,\n member,\n sourceFile,\n pslBlockDescriptors,\n diagnostics,\n );\n }\n }\n\n return {\n kind: 'namespace',\n name,\n node,\n span: nodePslSpan(node.syntax, sourceFile),\n models,\n compositeTypes,\n blocks,\n };\n}\n\nfunction buildFields(\n ownerName: string,\n fields: Iterable<FieldDeclarationAst>,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): Record<string, FieldSymbol> {\n const result: Record<string, FieldSymbol> = {};\n for (const field of fields) {\n const nameNode = field.name();\n const name = nameNode?.name();\n if (name === undefined) continue;\n if (Object.hasOwn(result, name)) {\n const range = nameRange(nameNode, sourceFile);\n if (range) {\n diagnostics.push({\n code: 'PSL_DUPLICATE_DECLARATION',\n message: `Duplicate declaration of \"${name}\"`,\n range,\n });\n }\n continue;\n }\n result[name] = buildField(ownerName, name, field, sourceFile, diagnostics);\n }\n return result;\n}\n\nfunction buildField(\n ownerName: string,\n name: string,\n node: FieldDeclarationAst,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): FieldSymbol {\n const attributes = readResolvedAttributes(node.attributes(), sourceFile);\n const span = nodePslSpan(node.syntax, sourceFile);\n const annotation = node.typeAnnotation();\n const typeName = annotation?.name();\n\n if (typeName?.isOverQualified()) {\n const path = typeName.path();\n diagnostics.push({\n code: 'PSL_INVALID_QUALIFIED_TYPE',\n message: `Field \"${ownerName}.${name}\" has an invalid qualified type \"${path.join('.')}\"; use at most one namespace qualifier (e.g. \"ns.TypeName\")`,\n range: nodeRange(typeName.syntax, sourceFile),\n });\n return {\n kind: 'field',\n name,\n node,\n span,\n typeName: path[path.length - 1] ?? '',\n optional: false,\n list: false,\n malformedType: true,\n attributes,\n };\n }\n\n const typeConstructor = annotation?.isConstructor()\n ? readResolvedConstructorCall(annotation, sourceFile)\n : undefined;\n const typeNamespaceId = typeName?.namespace()?.name();\n const typeContractSpaceId = typeName?.space()?.name();\n\n return {\n kind: 'field',\n name,\n node,\n span,\n typeName: typeName?.identifier()?.name() ?? '',\n ...(typeNamespaceId !== undefined ? { typeNamespaceId } : {}),\n ...(typeContractSpaceId !== undefined ? { typeContractSpaceId } : {}),\n optional: annotation?.isOptional() ?? false,\n list: annotation?.isList() ?? false,\n ...(typeConstructor !== undefined ? { typeConstructor } : {}),\n attributes,\n };\n}\n\nfunction resolveNamedTypeBinding(\n node: NamedTypeDeclarationAst,\n sourceFile: SourceFile,\n): {\n baseType?: string;\n typeConstructor?: ResolvedTypeConstructorCall;\n isConstructor: boolean;\n attributes: readonly ResolvedAttribute[];\n} {\n const annotation = node.typeAnnotation();\n const isConstructor = annotation?.isConstructor() ?? false;\n const baseType = annotation?.name()?.identifier()?.name();\n const typeConstructor = readResolvedConstructorCall(annotation, sourceFile);\n return {\n isConstructor,\n ...(!isConstructor && baseType !== undefined ? { baseType } : {}),\n ...(typeConstructor !== undefined ? { typeConstructor } : {}),\n attributes: readResolvedAttributes(node.attributes(), sourceFile),\n };\n}\n\nfunction isScalarBinding(node: NamedTypeDeclarationAst, scalarTypes: Set<string>): boolean {\n const annotation = node.typeAnnotation();\n if (annotation === undefined || annotation.isConstructor()) return false;\n const base = annotation.name()?.identifier()?.name();\n return base !== undefined && scalarTypes.has(base);\n}\n\nfunction nameRange(name: IdentifierAst | undefined, sourceFile: SourceFile): Range | undefined {\n if (name === undefined) return undefined;\n for (const token of name.syntax.tokens()) {\n if (token.kind === 'Ident') {\n return {\n start: sourceFile.positionAt(token.offset),\n end: sourceFile.positionAt(token.offset + token.text.length),\n };\n }\n }\n return undefined;\n}\n\nfunction nodeRange(node: SyntaxNode, sourceFile: SourceFile): Range {\n const start = node.offset;\n const end = start + node.green.textLength;\n return {\n start: sourceFile.positionAt(start),\n end: sourceFile.positionAt(end),\n };\n}\n"],"mappings":";;;;AAEA,SAAgB,sBAAsB,WAAyB,QAAQ,GAAuB;CAE5F,OADgB,UAAU,KAAK,QAAQ,QAAQ,IAAI,SAAS,YAC/C,CAAC,CAAC,MAAM,EAAE;AACzB;AAEA,SAAgB,yBAAyB,OAAmC;CAE1E,MAAM,QADU,MAAM,KACF,CAAC,CAAC,MAAM,gBAAgB;CAC5C,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,OAAO,MAAM,MAAM;AACrB;;;ACMA,SAAgB,oBACd,aACA,SACyC;CACzC,IAAI,gBAAgB,KAAA,GAAW,OAAO,KAAA;CACtC,KAAK,MAAM,SAAS,OAAO,OAAO,WAAW,GAAG;EAC9C,IAAI,UAAU,KAAA,GAAW;EACzB,IAAI,8BAA8B,KAAK,GAAG;GACxC,IAAI,MAAM,YAAY,SAAS,OAAO;GACtC;EACF;EACA,MAAM,SAAS,oBAAoB,OAAO,OAAO;EACjD,IAAI,WAAW,KAAA,GAAW,OAAO;CACnC;AAEF;AAEA,SAAgB,iCAAiC,OAOpB;CAC3B,MAAM,SAAS,0BAA0B,MAAM,aAAa,MAAM,KAAK;CACvE,OAAO,uBACL,MAAM,MAAM,OACZ,MAAM,YACN,MAAM,UACN,MAAM,aACN,MACF;AACF;AAEA,MAAM,YAAqB;CACzB,OAAO;EAAE,QAAQ;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ators/diagnostic.ts","../src/attribute-spec/combinators/bool.ts","../src/attribute-spec/combinators/entity-ref.ts","../src/attribute-spec/combinators/field-ref.ts","../src/attribute-spec/interpret.ts","../src/attribute-spec/combinators/func-call.ts","../src/attribute-spec/combinators/identifier.ts","../src/attribute-spec/combinators/int.ts","../src/attribute-spec/combinators/list.ts","../src/attribute-spec/combinators/num.ts","../src/attribute-spec/combinators/one-of.ts","../src/attribute-spec/combinators/record.ts","../src/attribute-spec/combinators/str.ts","../src/attribute-spec/field-attribute.ts","../src/attribute-spec/model-attribute.ts","../src/attribute-spec/optional.ts","../src/extension-block.ts","../src/block-reconstruction.ts","../src/symbol-table.ts"],"sourcesContent":["import type { PslAttribute } from '@prisma-next/framework-components/psl-ast';\n\nexport function getPositionalArgument(attribute: PslAttribute, index = 0): string | undefined {\n const entries = attribute.args.filter((arg) => arg.kind === 'positional');\n return entries[index]?.value;\n}\n\nexport function parseQuotedStringLiteral(value: string): string | undefined {\n const trimmed = value.trim();\n const match = trimmed.match(/^(['\"])(.*)\\1$/);\n if (!match) return undefined;\n return match[2] ?? '';\n}\n","import type { PslSpan } from '@prisma-next/framework-components/psl-ast';\nimport type { Position, Range, SourceFile } from './source-file';\nimport type {\n AttributeArgListAst,\n FieldAttributeAst,\n ModelAttributeAst,\n} from './syntax/ast/attributes';\nimport type { ExpressionAst } from './syntax/ast/expressions';\nimport type { QualifiedNameAst } from './syntax/ast/qualified-name';\nimport type { TypeAnnotationAst } from './syntax/ast/type-annotation';\nimport { printSyntax } from './syntax/ast-helpers';\nimport type { SyntaxNode } from './syntax/red';\n\nexport interface ResolvedAttributeArg {\n readonly kind: 'positional' | 'named';\n readonly name?: string;\n readonly value: string;\n readonly expression?: ExpressionAst;\n readonly span: PslSpan;\n}\n\nexport interface ResolvedAttribute {\n readonly name: string;\n readonly args: readonly ResolvedAttributeArg[];\n readonly span: PslSpan;\n}\n\nexport interface ResolvedTypeConstructorCall {\n readonly path: readonly string[];\n readonly args: readonly ResolvedAttributeArg[];\n readonly span: PslSpan;\n}\n\nexport function readResolvedAttribute(\n attribute: FieldAttributeAst | ModelAttributeAst,\n sourceFile: SourceFile,\n): ResolvedAttribute {\n return {\n name: attributeName(attribute.name()),\n args: readResolvedArgList(attribute.argList(), sourceFile),\n span: nodePslSpan(attribute.syntax, sourceFile),\n };\n}\n\nexport function readResolvedAttributes(\n attributes: Iterable<FieldAttributeAst | ModelAttributeAst>,\n sourceFile: SourceFile,\n): readonly ResolvedAttribute[] {\n return Array.from(attributes, (attribute) => readResolvedAttribute(attribute, sourceFile));\n}\n\nexport function readResolvedConstructorCall(\n annotation: TypeAnnotationAst | undefined,\n sourceFile: SourceFile,\n): ResolvedTypeConstructorCall | undefined {\n const argList = annotation?.argList();\n if (annotation === undefined || argList === undefined) return undefined;\n return {\n path: annotation.name()?.path() ?? [],\n args: readResolvedArgList(argList, sourceFile),\n span: nodePslSpan(annotation.syntax, sourceFile),\n };\n}\n\nfunction readResolvedArgList(\n argList: AttributeArgListAst | undefined,\n sourceFile: SourceFile,\n): readonly ResolvedAttributeArg[] {\n if (argList === undefined) return [];\n const args: ResolvedAttributeArg[] = [];\n for (const arg of argList.args()) {\n const name = arg.name()?.name();\n const expression = arg.value();\n args.push({\n kind: name !== undefined ? 'named' : 'positional',\n ...(name !== undefined ? { name } : {}),\n value: renderExpression(expression),\n ...(expression !== undefined ? { expression } : {}),\n span: nodePslSpan(arg.syntax, sourceFile),\n });\n }\n return args;\n}\n\nfunction attributeName(name: QualifiedNameAst | undefined): string {\n return name?.path().join('.') ?? '';\n}\n\nfunction renderExpression(expression: ExpressionAst | undefined): string {\n if (expression === undefined) return '';\n return printSyntax(expression.syntax).trim();\n}\n\nexport function nodePslSpan(node: SyntaxNode, sourceFile: SourceFile): PslSpan {\n const start = node.offset;\n const end = start + node.green.textLength;\n return {\n start: offsetToPslPosition(start, sourceFile),\n end: offsetToPslPosition(end, sourceFile),\n };\n}\n\n/** Unsupported-top-level-block diagnostics are anchored to the keyword token. */\nexport function keywordPslSpan(node: SyntaxNode, keyword: string, sourceFile: SourceFile): PslSpan {\n const start = node.offset;\n const end = start + keyword.length;\n return {\n start: offsetToPslPosition(start, sourceFile),\n end: offsetToPslPosition(end, sourceFile),\n };\n}\n\nexport function rangeToPslSpan(range: Range, sourceFile: SourceFile): PslSpan {\n return {\n start: offsetToPslPosition(sourceFile.offsetAt(range.start), sourceFile),\n end: offsetToPslPosition(sourceFile.offsetAt(range.end), sourceFile),\n };\n}\n\nfunction offsetToPslPosition(offset: number, sourceFile: SourceFile): PslSpan['start'] {\n const position: Position = sourceFile.positionAt(offset);\n return { offset, line: position.line + 1, column: position.character + 1 };\n}\n","import type { PslDiagnostic, PslDiagnosticCode } from '@prisma-next/framework-components/psl-ast';\nimport { nodePslSpan } from '../../resolve';\nimport type { AstNode } from '../../syntax/ast-helpers';\nimport type { InterpretCtx } from '../types';\n\nexport const ATTRIBUTE_DIAGNOSTIC_CODE: PslDiagnosticCode = 'PSL_INVALID_ATTRIBUTE_SYNTAX';\n\nexport function leafDiagnostic(ctx: InterpretCtx, node: AstNode, message: string): PslDiagnostic {\n return {\n code: ATTRIBUTE_DIAGNOSTIC_CODE,\n message,\n sourceId: ctx.sourceId,\n span: nodePslSpan(node.syntax, ctx.sourceFile),\n };\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { BooleanLiteralExprAst } from '../../syntax/ast/expressions';\nimport type { ArgType } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\nexport function bool(): ArgType<boolean> {\n return {\n kind: 'bool',\n label: 'boolean',\n parse: (arg, ctx): Result<boolean, readonly PslDiagnostic[]> => {\n if (arg instanceof BooleanLiteralExprAst) {\n const value = arg.value();\n if (value !== undefined) return ok(value);\n }\n return notOk([leafDiagnostic(ctx, arg, 'Expected a boolean literal')]);\n },\n };\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { IdentifierAst } from '../../syntax/ast/identifier';\nimport type { ArgType } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\n// A bare model-name reference. Existence of a model with this name is resolved\n// downstream (e.g. `resolvePolymorphism`), not here.\nexport function entityRef(): ArgType<string> {\n return {\n kind: 'entityRef',\n label: 'model name',\n parse: (arg, ctx): Result<string, readonly PslDiagnostic[]> => {\n if (!(arg instanceof IdentifierAst)) {\n return notOk([leafDiagnostic(ctx, arg, 'Expected a model name')]);\n }\n const name = arg.name();\n if (name === undefined) {\n return notOk([leafDiagnostic(ctx, arg, 'Expected a model name')]);\n }\n return ok(name);\n },\n };\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { IdentifierAst } from '../../syntax/ast/identifier';\nimport type { ArgType } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\nexport type FieldRefScope = 'self' | 'referenced';\n\nexport interface FieldRefArgType extends ArgType<string> {\n readonly scope: FieldRefScope;\n}\n\nexport function fieldRef(scope: FieldRefScope): FieldRefArgType {\n return {\n kind: 'fieldRef',\n label: 'field name',\n scope,\n parse: (arg, ctx): Result<string, readonly PslDiagnostic[]> => {\n if (!(arg instanceof IdentifierAst)) {\n return notOk([leafDiagnostic(ctx, arg, 'Expected a field name')]);\n }\n const name = arg.name();\n if (name === undefined) {\n return notOk([leafDiagnostic(ctx, arg, 'Expected a field name')]);\n }\n const model = scope === 'self' ? ctx.selfModel : ctx.resolveReferencedModel();\n // A referenced model in another space can't be resolved here (resolveReferencedModel returns undefined); skip the existence check — it runs where that model is known.\n if (model !== undefined && !Object.hasOwn(model.fields, name)) {\n return notOk([\n leafDiagnostic(ctx, arg, `Field \"${name}\" does not exist on model \"${model.name}\"`),\n ]);\n }\n return ok(name);\n },\n };\n}\n","import type { PslDiagnostic, PslSpan } from '@prisma-next/framework-components/psl-ast';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { nodePslSpan } from '../resolve';\nimport type { FieldAttributeAst, ModelAttributeAst } from '../syntax/ast/attributes';\nimport type { AttributeArgAst } from '../syntax/ast/expressions';\nimport { ATTRIBUTE_DIAGNOSTIC_CODE } from './combinators/diagnostic';\nimport type {\n ArgType,\n AttributeSpec,\n InterpretCtx,\n OptionalArgType,\n Param,\n PositionalParam,\n} from './types';\n\n// The positional/named argument-binding for an attribute or a function call. `name` labels the\n// callee in binding diagnostics (`Attribute \"<name>\" …`); `span` anchors the arity diagnostics\n// (too-many / missing) that have no per-argument node to point at.\nexport interface ArgBindingSpec {\n readonly name: string;\n readonly positional: readonly PositionalParam<unknown>[];\n readonly named: Readonly<Record<string, Param<unknown>>>;\n}\n\nexport function interpretArgs(\n args: Iterable<AttributeArgAst>,\n spec: ArgBindingSpec,\n ctx: InterpretCtx,\n span: PslSpan,\n): Result<Record<string, unknown>, readonly PslDiagnostic[]> {\n const diagnostics: PslDiagnostic[] = [];\n\n const output: Record<string, unknown> = {};\n const seen = new Set<string>();\n let positionalSlot = 0;\n let reportedExcess = false;\n\n for (const arg of args) {\n const name = arg.name()?.name();\n\n let key: string;\n let param: Param<unknown>;\n if (name === undefined) {\n const posParam = spec.positional[positionalSlot];\n if (posParam === undefined) {\n if (!reportedExcess) {\n diagnostics.push(\n diagnostic(\n `Attribute \"${spec.name}\" received too many positional arguments`,\n ctx,\n span,\n ),\n );\n reportedExcess = true;\n }\n continue;\n }\n positionalSlot += 1;\n key = posParam.key;\n param = posParam.type;\n } else {\n const namedParam = Object.hasOwn(spec.named, name) ? spec.named[name] : undefined;\n if (namedParam === undefined) {\n diagnostics.push(\n diagnostic(\n `Attribute \"${spec.name}\" received unknown argument \"${name}\"`,\n ctx,\n nodePslSpan(arg.syntax, ctx.sourceFile),\n ),\n );\n continue;\n }\n key = name;\n param = namedParam;\n }\n\n if (seen.has(key)) {\n diagnostics.push(\n diagnostic(\n `Attribute \"${spec.name}\" received duplicate argument \"${key}\"`,\n ctx,\n nodePslSpan(arg.syntax, ctx.sourceFile),\n ),\n );\n continue;\n }\n seen.add(key);\n const result = parseArgValue(arg, param, ctx, diagnostics);\n if (result.ok) output[key] = result.value;\n }\n\n const finalized = new Set<string>();\n const finalizeAbsentKey = (\n key: string,\n positionalParam: Param<unknown> | undefined,\n namedParam: Param<unknown> | undefined,\n ): void => {\n if (finalized.has(key) || seen.has(key)) return;\n finalized.add(key);\n const effective = namedParam ?? positionalParam;\n if (effective === undefined) return;\n if (isOptionalArgType(effective)) {\n if (effective.hasDefault) output[key] = effective.defaultValue;\n return;\n }\n diagnostics.push(\n diagnostic(`Attribute \"${spec.name}\" is missing required argument \"${key}\"`, ctx, span),\n );\n };\n\n for (const param of spec.positional) {\n const namedParam = Object.hasOwn(spec.named, param.key) ? spec.named[param.key] : undefined;\n finalizeAbsentKey(param.key, param.type, namedParam);\n }\n for (const key of Object.keys(spec.named)) {\n finalizeAbsentKey(key, undefined, spec.named[key]);\n }\n\n if (diagnostics.length > 0) {\n return notOk<readonly PslDiagnostic[]>(diagnostics);\n }\n return ok(output);\n}\n\nexport function interpretAttribute<Out>(\n attrNode: FieldAttributeAst | ModelAttributeAst,\n spec: AttributeSpec<Out>,\n ctx: InterpretCtx,\n): Result<Out, readonly PslDiagnostic[]> {\n const attributeSpan = nodePslSpan(attrNode.syntax, ctx.sourceFile);\n const bound = interpretArgs(attrNode.argList()?.args() ?? [], spec, ctx, attributeSpan);\n if (!bound.ok) return notOk<readonly PslDiagnostic[]>(bound.failure);\n\n const value = blindCast<\n Out,\n 'The engine builds the output object structurally from the spec; TypeScript cannot relate the dynamically-keyed record to the spec-inferred output type.'\n >(bound.value);\n if (spec.refine !== undefined) {\n const refineDiagnostics = spec.refine(value, ctx);\n if (refineDiagnostics.length > 0) {\n return notOk<readonly PslDiagnostic[]>(refineDiagnostics);\n }\n }\n return ok(value);\n}\n\nfunction parseArgValue(\n arg: AttributeArgAst,\n argType: ArgType<unknown>,\n ctx: InterpretCtx,\n diagnostics: PslDiagnostic[],\n): Result<unknown, readonly PslDiagnostic[]> {\n const value = arg.value();\n if (value === undefined) {\n const missing = diagnostic(\n 'Attribute argument is missing a value',\n ctx,\n nodePslSpan(arg.syntax, ctx.sourceFile),\n );\n diagnostics.push(missing);\n return notOk<readonly PslDiagnostic[]>([missing]);\n }\n const result = argType.parse(value, ctx);\n if (!result.ok) {\n for (const failure of result.failure) diagnostics.push(failure);\n }\n return result;\n}\n\nfunction isOptionalArgType(param: Param<unknown>): param is OptionalArgType<unknown> {\n return 'optional' in param && param.optional === true;\n}\n\nfunction diagnostic(message: string, ctx: InterpretCtx, span: PslSpan): PslDiagnostic {\n return { code: ATTRIBUTE_DIAGNOSTIC_CODE, message, sourceId: ctx.sourceId, span };\n}\n","import type { PslDiagnostic, PslSpan } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { nodePslSpan } from '../../resolve';\nimport type { ExpressionAst } from '../../syntax/ast/expressions';\nimport { FunctionCallAst } from '../../syntax/ast/expressions';\nimport { interpretArgs } from '../interpret';\nimport type { ArgType, InterpretCtx, Param, PositionalParam } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\n// The argument signature of a pinned function call — the same positional/named shape an attribute\n// spec uses. Omitted groups default to empty, so a nullary call needs neither key.\nexport interface FuncCallSig {\n readonly positional?: readonly PositionalParam<unknown>[];\n readonly named?: Readonly<Record<string, Param<unknown>>>;\n}\n\nexport interface TypedFuncCall {\n readonly fn: string;\n readonly span: PslSpan;\n readonly args: Readonly<Record<string, unknown>>;\n}\n\n// A name-pinned function-call argument — `funcCall('now', {})` matches `now()`, parsing the call's\n// arguments through `sig`.\nexport function funcCall(name: string, sig: FuncCallSig): ArgType<TypedFuncCall> {\n return {\n kind: 'funcCall',\n label: 'function call',\n parse: (arg, ctx): Result<TypedFuncCall, readonly PslDiagnostic[]> => {\n const guard = matchCallee(arg, name, ctx);\n if (!guard.ok) return guard;\n const span = nodePslSpan(guard.value.syntax, ctx.sourceFile);\n const bound = interpretArgs(\n guard.value.args(),\n { name, positional: sig.positional ?? [], named: sig.named ?? {} },\n ctx,\n span,\n );\n if (!bound.ok) return notOk<readonly PslDiagnostic[]>(bound.failure);\n return ok({ fn: name, span, args: bound.value });\n },\n };\n}\n\nfunction matchCallee(\n arg: ExpressionAst,\n name: string,\n ctx: InterpretCtx,\n): Result<FunctionCallAst, readonly PslDiagnostic[]> {\n if (!(arg instanceof FunctionCallAst)) {\n return notOk([leafDiagnostic(ctx, arg, 'Expected a function call')]);\n }\n const qname = arg.name();\n if (qname === undefined || qname.dot() !== undefined || qname.colon() !== undefined) {\n return notOk([leafDiagnostic(ctx, arg, 'Expected a function call')]);\n }\n const calleeName = qname.identifier()?.token()?.text;\n if (calleeName === undefined) {\n return notOk([leafDiagnostic(ctx, arg, 'Expected a function call')]);\n }\n if (calleeName !== name) {\n return notOk([leafDiagnostic(ctx, arg, `Expected ${name}()`)]);\n }\n return ok(arg);\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { IdentifierAst } from '../../syntax/ast/identifier';\nimport type { ArgType } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\nexport function identifier<const N extends string>(name: N): ArgType<N> {\n return {\n kind: 'identifier',\n label: name,\n parse: (arg, ctx): Result<N, readonly PslDiagnostic[]> => {\n if (arg instanceof IdentifierAst && arg.name() === name) return ok(name);\n return notOk([leafDiagnostic(ctx, arg, `Expected ${name}`)]);\n },\n };\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { NumberLiteralExprAst } from '../../syntax/ast/expressions';\nimport type { ArgType } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\n// An integer literal reduced to its numeric value. Passing `min`/`max` additionally rejects\n// out-of-range integers with a distinct range message, leaving the integer-only check intact.\nexport function int(opts?: { min?: number; max?: number }): ArgType<number> {\n const min = opts?.min;\n const max = opts?.max;\n return {\n kind: 'int',\n label: 'integer',\n parse: (arg, ctx): Result<number, readonly PslDiagnostic[]> => {\n if (arg instanceof NumberLiteralExprAst) {\n const value = arg.value();\n if (value !== undefined && Number.isInteger(value)) {\n if ((min === undefined || value >= min) && (max === undefined || value <= max)) {\n return ok(value);\n }\n return notOk([leafDiagnostic(ctx, arg, rangeMessage(min, max))]);\n }\n }\n return notOk([leafDiagnostic(ctx, arg, 'Expected an integer literal')]);\n },\n };\n}\n\nfunction rangeMessage(min: number | undefined, max: number | undefined): string {\n if (min !== undefined && max !== undefined)\n return `Expected an integer between ${min} and ${max}`;\n if (min !== undefined) return `Expected an integer greater than or equal to ${min}`;\n return `Expected an integer less than or equal to ${max}`;\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { ArrayLiteralAst, type ExpressionAst } from '../../syntax/ast/expressions';\nimport type { ArgType } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\nexport interface ListOptions {\n readonly nonEmpty?: boolean;\n readonly unique?: boolean;\n}\n\nexport function list<T>(of: ArgType<T>, opts?: ListOptions): ArgType<T[]> {\n return {\n kind: 'list',\n label: `${of.label}[]`,\n parse: (arg, ctx): Result<T[], readonly PslDiagnostic[]> => {\n if (!(arg instanceof ArrayLiteralAst)) {\n return notOk([leafDiagnostic(ctx, arg, `Expected a list of ${of.label}`)]);\n }\n const diagnostics: PslDiagnostic[] = [];\n const parsed: { node: ExpressionAst; value: T }[] = [];\n let count = 0;\n for (const element of arg.elements()) {\n count += 1;\n const result = of.parse(element, ctx);\n if (result.ok) parsed.push({ node: element, value: result.value });\n else diagnostics.push(...result.failure);\n }\n if (opts?.nonEmpty === true && count === 0) {\n diagnostics.push(leafDiagnostic(ctx, arg, 'Expected a non-empty list'));\n }\n if (opts?.unique === true) {\n const seen = new Set<T>();\n for (const { node, value } of parsed) {\n if (seen.has(value)) diagnostics.push(leafDiagnostic(ctx, node, 'Duplicate list entry'));\n else seen.add(value);\n }\n }\n if (diagnostics.length > 0) return notOk(diagnostics);\n return ok(parsed.map((entry) => entry.value));\n },\n };\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { NumberLiteralExprAst } from '../../syntax/ast/expressions';\nimport type { ArgType } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\n// A general number literal — any number, including floats — reduced to its numeric value.\n// Passing `value` pins the combinator to that single literal (`num(4)` matches only `4`),\n// mirroring how `identifier(name)` pins a bare identifier. Use `int()` when only integer\n// literals are allowed.\nexport function num(): ArgType<number>;\nexport function num(value: number): ArgType<number>;\nexport function num(value?: number): ArgType<number> {\n return {\n kind: 'num',\n label: value === undefined ? 'number' : String(value),\n parse: (arg, ctx): Result<number, readonly PslDiagnostic[]> => {\n if (arg instanceof NumberLiteralExprAst) {\n const parsed = arg.value();\n if (parsed !== undefined && (value === undefined || parsed === value)) return ok(parsed);\n }\n const message = value === undefined ? 'Expected a number literal' : `Expected ${value}`;\n return notOk([leafDiagnostic(ctx, arg, message)]);\n },\n };\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport type { ArgType, OutOf } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\nexport function oneOf<Alts extends readonly [ArgType<unknown>, ...ArgType<unknown>[]]>(\n ...alts: Alts\n): ArgType<OutOf<Alts[number]>> {\n const label = alts.map((alt) => alt.label).join(' | ');\n return {\n kind: 'oneOf',\n label,\n parse: (arg, ctx): Result<OutOf<Alts[number]>, readonly PslDiagnostic[]> => {\n for (const alt of alts) {\n const result = alt.parse(arg, ctx);\n if (result.ok) {\n return ok(\n blindCast<\n OutOf<Alts[number]>,\n 'The matched value comes from an alternative whose output type is a member of the union, but iterating the tuple widens each element to ArgType<unknown>, erasing that relationship.'\n >(result.value),\n );\n }\n }\n return notOk([leafDiagnostic(ctx, arg, `Expected one of: ${label}`)]);\n },\n };\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { ObjectLiteralExprAst } from '../../syntax/ast/expressions';\nimport type { ArgType } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\nexport function record<T>(of: ArgType<T>): ArgType<Record<string, T>> {\n return {\n kind: 'record',\n label: `{ [key]: ${of.label} }`,\n parse: (arg, ctx): Result<Record<string, T>, readonly PslDiagnostic[]> => {\n if (!(arg instanceof ObjectLiteralExprAst)) {\n return notOk([leafDiagnostic(ctx, arg, 'Expected an object literal')]);\n }\n const diagnostics: PslDiagnostic[] = [];\n const result: Record<string, T> = {};\n for (const field of arg.fields()) {\n const key = field.keyName();\n if (key === undefined) {\n diagnostics.push(leafDiagnostic(ctx, field, 'Expected a key'));\n continue;\n }\n const value = field.value();\n if (value === undefined) {\n diagnostics.push(leafDiagnostic(ctx, field, `Expected a value for key \"${key}\"`));\n continue;\n }\n const parsed = of.parse(value, ctx);\n if (!parsed.ok) {\n diagnostics.push(...parsed.failure);\n continue;\n }\n if (Object.hasOwn(result, key)) {\n diagnostics.push(leafDiagnostic(ctx, field, `Duplicate key \"${key}\"`));\n continue;\n }\n result[key] = parsed.value;\n }\n if (diagnostics.length > 0) return notOk(diagnostics);\n return ok(result);\n },\n };\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { StringLiteralExprAst } from '../../syntax/ast/expressions';\nimport type { ArgType } from '../types';\nimport { leafDiagnostic } from './diagnostic';\n\nexport function str(): ArgType<string> {\n return {\n kind: 'str',\n label: 'string',\n parse: (arg, ctx): Result<string, readonly PslDiagnostic[]> => {\n if (arg instanceof StringLiteralExprAst) {\n const value = arg.value();\n if (value !== undefined) return ok(value);\n }\n return notOk([leafDiagnostic(ctx, arg, 'Expected a string literal')]);\n },\n };\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport type { AttributeOut, AttributeSpec, InterpretCtx, Param, PositionalParam } from './types';\n\ninterface FieldAttributeConfig<\n Pos extends readonly PositionalParam[],\n Named extends Record<string, Param<unknown>>,\n> {\n readonly positional?: Pos;\n readonly named?: Named;\n readonly refine?: (\n parsed: AttributeOut<Pos, Named>,\n ctx: InterpretCtx,\n ) => readonly PslDiagnostic[];\n}\n\nexport function fieldAttribute<\n const Pos extends readonly PositionalParam[] = readonly [],\n const Named extends Record<string, Param<unknown>> = Record<never, never>,\n>(name: string, config: FieldAttributeConfig<Pos, Named>): AttributeSpec<AttributeOut<Pos, Named>> {\n return {\n level: 'field',\n name,\n positional: config.positional ?? [],\n named: config.named ?? {},\n ...(config.refine !== undefined ? { refine: config.refine } : {}),\n };\n}\n","import type { PslDiagnostic } from '@prisma-next/framework-components/psl-ast';\nimport type { AttributeOut, AttributeSpec, InterpretCtx, Param, PositionalParam } from './types';\n\ninterface ModelAttributeConfig<\n Pos extends readonly PositionalParam[],\n Named extends Record<string, Param<unknown>>,\n> {\n readonly positional?: Pos;\n readonly named?: Named;\n readonly refine?: (\n parsed: AttributeOut<Pos, Named>,\n ctx: InterpretCtx,\n ) => readonly PslDiagnostic[];\n}\n\nexport function modelAttribute<\n const Pos extends readonly PositionalParam[] = readonly [],\n const Named extends Record<string, Param<unknown>> = Record<never, never>,\n>(name: string, config: ModelAttributeConfig<Pos, Named>): AttributeSpec<AttributeOut<Pos, Named>> {\n return {\n level: 'model',\n name,\n positional: config.positional ?? [],\n named: config.named ?? {},\n ...(config.refine !== undefined ? { refine: config.refine } : {}),\n };\n}\n","import type { ArgType, OptionalArgType } from './types';\n\nexport function optional<T>(type: ArgType<T>, ...rest: [defaultValue: T] | []): OptionalArgType<T> {\n if (rest.length === 0) {\n return { ...type, optional: true, hasDefault: false };\n }\n return { ...type, optional: true, hasDefault: true, defaultValue: rest[0] };\n}\n","import {\n type AuthoringPslBlockDescriptor,\n type AuthoringPslBlockDescriptorNamespace,\n isAuthoringPslBlockDescriptor,\n} from '@prisma-next/framework-components/authoring';\nimport type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport {\n makePslNamespace,\n makePslNamespaceEntries,\n type PslDiagnostic,\n type PslModel,\n type PslSpan,\n UNSPECIFIED_PSL_NAMESPACE_ID,\n validateExtensionBlock,\n} from '@prisma-next/framework-components/psl-ast';\nimport type { SourceFile } from './source-file';\nimport type { BlockSymbol, ModelSymbol, SymbolTable } from './symbol-table';\n\nexport function findBlockDescriptor(\n descriptors: AuthoringPslBlockDescriptorNamespace | undefined,\n keyword: string,\n): AuthoringPslBlockDescriptor | undefined {\n if (descriptors === undefined) return undefined;\n for (const value of Object.values(descriptors)) {\n if (value === undefined) continue;\n if (isAuthoringPslBlockDescriptor(value)) {\n if (value.keyword === keyword) return value;\n continue;\n }\n const nested = findBlockDescriptor(value, keyword);\n if (nested !== undefined) return nested;\n }\n return undefined;\n}\n\nexport function validateExtensionBlockFromSymbol(input: {\n readonly block: BlockSymbol;\n readonly descriptor: AuthoringPslBlockDescriptor;\n readonly symbolTable: SymbolTable;\n readonly sourceFile: SourceFile;\n readonly sourceId: string;\n readonly codecLookup: CodecLookup;\n}): readonly PslDiagnostic[] {\n const refCtx = buildRefResolutionContext(input.symbolTable, input.block);\n return validateExtensionBlock(\n input.block.block,\n input.descriptor,\n input.sourceId,\n input.codecLookup,\n refCtx,\n );\n}\n\nconst ZERO_SPAN: PslSpan = {\n start: { offset: 0, line: 1, column: 1 },\n end: { offset: 0, line: 1, column: 1 },\n};\n\nfunction buildRefResolutionContext(\n symbolTable: SymbolTable,\n block: BlockSymbol,\n): {\n ownerNamespace: ReturnType<typeof makePslNamespace>;\n allNamespaces: readonly ReturnType<typeof makePslNamespace>[];\n} {\n const unspecifiedNamespace = makeNamespace(\n UNSPECIFIED_PSL_NAMESPACE_ID,\n Object.values(symbolTable.topLevel.models),\n );\n const namedNamespaces = Object.values(symbolTable.topLevel.namespaces).map((namespace) =>\n makeNamespace(namespace.name, Object.values(namespace.models)),\n );\n const allNamespaces = [unspecifiedNamespace, ...namedNamespaces];\n const ownerNamespaceName = findOwnerNamespaceName(symbolTable, block);\n const ownerNamespace =\n allNamespaces.find((namespace) => namespace.name === ownerNamespaceName) ??\n unspecifiedNamespace;\n return { ownerNamespace, allNamespaces };\n}\n\nfunction makeNamespace(\n name: string,\n models: readonly ModelSymbol[],\n): ReturnType<typeof makePslNamespace> {\n const modelStubs: PslModel[] = models.map((model) => ({\n kind: 'model',\n name: model.name,\n fields: [],\n attributes: [],\n span: ZERO_SPAN,\n }));\n return makePslNamespace({\n kind: 'namespace',\n name,\n entries: makePslNamespaceEntries(modelStubs, [], []),\n span: ZERO_SPAN,\n });\n}\n\nfunction findOwnerNamespaceName(symbolTable: SymbolTable, block: BlockSymbol): string {\n for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {\n if (Object.values(namespace.blocks).some((candidate) => candidate === block)) {\n return namespace.name;\n }\n }\n return UNSPECIFIED_PSL_NAMESPACE_ID;\n}\n","import type { AuthoringPslBlockDescriptor } from '@prisma-next/framework-components/authoring';\nimport type {\n PslBlockParam,\n PslExtensionBlock,\n PslExtensionBlockAttribute,\n PslExtensionBlockParamValue,\n PslSpan,\n} from '@prisma-next/framework-components/psl-ast';\nimport type { ParseDiagnostic } from './parse';\nimport { nodePslSpan } from './resolve';\nimport type { SourceFile } from './source-file';\nimport type { GenericBlockDeclarationAst, KeyValuePairAst } from './syntax/ast/declarations';\nimport { ArrayLiteralAst, type ExpressionAst } from './syntax/ast/expressions';\nimport { printSyntax } from './syntax/ast-helpers';\n\n/**\n * Descriptor-free and unknown parameters become `value` stubs so validation can\n * report them via key-set comparison. Duplicate member names are first-wins.\n */\nexport function reconstructExtensionBlock(\n node: GenericBlockDeclarationAst,\n descriptor: AuthoringPslBlockDescriptor | undefined,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): PslExtensionBlock {\n const keyword = node.keyword()?.text ?? '';\n const blockName = node.name()?.name() ?? '';\n\n const blockAttributes: PslExtensionBlockAttribute[] = [];\n for (const attribute of node.attributes()) {\n const name = attribute.name()?.path().join('.') ?? '';\n const args = Array.from(attribute.argList()?.args() ?? [], (arg) => {\n const value = arg.value();\n return {\n kind: 'positional' as const,\n value: value === undefined ? '' : printSyntax(value.syntax).trim(),\n span: nodePslSpan(arg.syntax, sourceFile),\n };\n });\n blockAttributes.push({\n name,\n args,\n span: nodePslSpan(attribute.syntax, sourceFile),\n });\n }\n\n const parameters: Record<string, PslExtensionBlockParamValue> = {};\n for (const entry of node.entries()) {\n const key = entry.key()?.name();\n if (key === undefined) continue;\n const span = nodePslSpan(entry.syntax, sourceFile);\n if (Object.hasOwn(parameters, key)) {\n diagnostics.push({\n code: 'PSL_EXTENSION_DUPLICATE_PARAMETER',\n message: `Duplicate parameter \"${key}\" in \"${keyword}\" block \"${blockName}\"; first occurrence wins`,\n range: {\n start: sourceFile.positionAt(entry.syntax.offset),\n end: sourceFile.positionAt(entry.syntax.offset + entry.syntax.green.textLength),\n },\n });\n continue;\n }\n parameters[key] = reconstructParamValue(\n entry,\n descriptor?.parameters[key],\n span,\n sourceFile,\n diagnostics,\n );\n }\n\n return {\n kind: descriptor?.discriminator ?? keyword,\n keyword,\n name: blockName,\n parameters,\n blockAttributes,\n span: nodePslSpan(node.syntax, sourceFile),\n };\n}\n\nfunction reconstructParamValue(\n entry: KeyValuePairAst,\n param: PslBlockParam | undefined,\n span: PslSpan,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): PslExtensionBlockParamValue {\n const value = entry.value();\n if (value === undefined) {\n return { kind: 'bare', span };\n }\n return reconstructFromExpression(value, param, span, sourceFile, diagnostics);\n}\n\nfunction reconstructFromExpression(\n value: ExpressionAst,\n param: PslBlockParam | undefined,\n span: PslSpan,\n sourceFile: SourceFile,\n diagnostics?: ParseDiagnostic[],\n): PslExtensionBlockParamValue {\n const raw = printSyntax(value.syntax).trim();\n if (param?.kind === 'list') {\n const array = ArrayLiteralAst.cast(value.syntax);\n if (!array) {\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `List parameter expects an array literal, got ${raw}`,\n range: {\n start: sourceFile.positionAt(value.syntax.offset),\n end: sourceFile.positionAt(value.syntax.offset + value.syntax.green.textLength),\n },\n });\n return { kind: 'value', raw, span };\n }\n\n const items: PslExtensionBlockParamValue[] = [];\n for (const element of array.elements()) {\n items.push(\n reconstructFromExpression(\n element,\n param.of,\n nodePslSpan(element.syntax, sourceFile),\n sourceFile,\n diagnostics,\n ),\n );\n }\n return { kind: 'list', items, span };\n }\n switch (param?.kind) {\n case 'ref':\n return { kind: 'ref', identifier: raw, span };\n case 'option':\n return { kind: 'option', token: raw, span };\n default:\n return { kind: 'value', raw, span };\n }\n}\n","import type { AuthoringPslBlockDescriptorNamespace } from '@prisma-next/framework-components/authoring';\nimport type { PslExtensionBlock, PslSpan } from '@prisma-next/framework-components/psl-ast';\nimport { reconstructExtensionBlock } from './block-reconstruction';\nimport { findBlockDescriptor } from './extension-block';\nimport type { ParseDiagnostic } from './parse';\nimport {\n nodePslSpan,\n type ResolvedAttribute,\n type ResolvedTypeConstructorCall,\n readResolvedAttributes,\n readResolvedConstructorCall,\n} from './resolve';\nimport type { Range, SourceFile } from './source-file';\nimport {\n CompositeTypeDeclarationAst,\n type DocumentAst,\n type FieldDeclarationAst,\n GenericBlockDeclarationAst,\n ModelDeclarationAst,\n type NamedTypeDeclarationAst,\n NamespaceDeclarationAst,\n TypesBlockAst,\n} from './syntax/ast/declarations';\nimport type { IdentifierAst } from './syntax/ast/identifier';\nimport type { SyntaxNode } from './syntax/red';\n\nexport type {\n ResolvedAttribute,\n ResolvedAttributeArg,\n ResolvedTypeConstructorCall,\n} from './resolve';\n\nexport interface SymbolTable {\n readonly topLevel: TopLevelScope;\n}\n\nexport interface TopLevelScope {\n readonly namespaces: Record<string, NamespaceSymbol>;\n readonly scalars: Record<string, ScalarSymbol>;\n readonly typeAliases: Record<string, TypeAliasSymbol>;\n readonly blocks: Record<string, BlockSymbol>;\n readonly models: Record<string, ModelSymbol>;\n readonly compositeTypes: Record<string, CompositeTypeSymbol>;\n}\n\nexport interface NamespaceSymbol {\n readonly kind: 'namespace';\n readonly name: string;\n readonly node: NamespaceDeclarationAst;\n readonly span: PslSpan;\n readonly models: Record<string, ModelSymbol>;\n readonly compositeTypes: Record<string, CompositeTypeSymbol>;\n readonly blocks: Record<string, BlockSymbol>;\n}\n\nexport interface ModelSymbol {\n readonly kind: 'model';\n readonly name: string;\n readonly node: ModelDeclarationAst;\n readonly span: PslSpan;\n readonly fields: Record<string, FieldSymbol>;\n readonly attributes: readonly ResolvedAttribute[];\n}\n\nexport interface CompositeTypeSymbol {\n readonly kind: 'compositeType';\n readonly name: string;\n readonly node: CompositeTypeDeclarationAst;\n readonly span: PslSpan;\n readonly fields: Record<string, FieldSymbol>;\n readonly attributes: readonly ResolvedAttribute[];\n}\n\nexport interface BlockSymbol {\n readonly kind: 'block';\n readonly name: string;\n readonly keyword: string;\n readonly node: GenericBlockDeclarationAst;\n readonly span: PslSpan;\n /** Resolved once so consumers do not independently classify block parameters. */\n readonly block: PslExtensionBlock;\n}\n\nexport interface ResolvedNamedTypeBinding {\n readonly baseType?: string;\n readonly typeConstructor?: ResolvedTypeConstructorCall;\n readonly isConstructor: boolean;\n readonly attributes: readonly ResolvedAttribute[];\n}\n\nexport interface ScalarSymbol extends ResolvedNamedTypeBinding {\n readonly kind: 'scalar';\n readonly name: string;\n readonly node: NamedTypeDeclarationAst;\n readonly span: PslSpan;\n}\n\nexport interface TypeAliasSymbol extends ResolvedNamedTypeBinding {\n readonly kind: 'typeAlias';\n readonly name: string;\n readonly node: NamedTypeDeclarationAst;\n readonly span: PslSpan;\n}\n\nexport interface FieldSymbol {\n readonly kind: 'field';\n readonly name: string;\n readonly node: FieldDeclarationAst;\n readonly span: PslSpan;\n readonly typeName: string;\n readonly typeNamespaceId?: string;\n readonly typeContractSpaceId?: string;\n readonly optional: boolean;\n readonly list: boolean;\n readonly typeConstructor?: ResolvedTypeConstructorCall;\n readonly attributes: readonly ResolvedAttribute[];\n /** Prevents cascading unsupported-type diagnostics after invalid qualification. */\n readonly malformedType?: boolean;\n}\n\nexport interface BuildSymbolTableOptions {\n readonly document: DocumentAst;\n readonly sourceFile: SourceFile;\n readonly scalarTypes: readonly string[];\n readonly pslBlockDescriptors: AuthoringPslBlockDescriptorNamespace;\n}\n\nexport interface SymbolTableResult {\n readonly table: SymbolTable;\n readonly diagnostics: readonly ParseDiagnostic[];\n}\n\n/**\n * Owns duplicate-declaration detection for all PSL scopes; downstream consumers\n * should consume first-wins symbols rather than re-emitting duplicate diagnostics.\n */\nexport function buildSymbolTable(options: BuildSymbolTableOptions): SymbolTableResult {\n const { document, sourceFile, scalarTypes, pslBlockDescriptors } = options;\n const diagnostics: ParseDiagnostic[] = [];\n const scalarSet = new Set(scalarTypes);\n\n const namespaces: Record<string, NamespaceSymbol> = {};\n const scalars: Record<string, ScalarSymbol> = {};\n const typeAliases: Record<string, TypeAliasSymbol> = {};\n const blocks: Record<string, BlockSymbol> = {};\n const models: Record<string, ModelSymbol> = {};\n const compositeTypes: Record<string, CompositeTypeSymbol> = {};\n const topLevelNames = new Set<string>();\n\n const claim = (taken: Set<string>, name: IdentifierAst | undefined): string | undefined => {\n const text = name?.name();\n if (text === undefined) return undefined;\n if (taken.has(text)) {\n const range = nameRange(name, sourceFile);\n if (range) {\n diagnostics.push({\n code: 'PSL_DUPLICATE_DECLARATION',\n message: `Duplicate declaration of \"${text}\"`,\n range,\n });\n }\n return undefined;\n }\n taken.add(text);\n return text;\n };\n\n for (const declaration of document.declarations()) {\n if (declaration instanceof ModelDeclarationAst) {\n const name = claim(topLevelNames, declaration.name());\n if (name !== undefined) models[name] = buildModel(name, declaration, sourceFile, diagnostics);\n } else if (declaration instanceof CompositeTypeDeclarationAst) {\n const name = claim(topLevelNames, declaration.name());\n if (name !== undefined) {\n compositeTypes[name] = buildCompositeType(name, declaration, sourceFile, diagnostics);\n }\n } else if (declaration instanceof GenericBlockDeclarationAst) {\n const name = claim(topLevelNames, declaration.name());\n if (name !== undefined) {\n blocks[name] = buildBlock(name, declaration, sourceFile, pslBlockDescriptors, diagnostics);\n }\n } else if (declaration instanceof NamespaceDeclarationAst) {\n const name = claim(topLevelNames, declaration.name());\n if (name !== undefined) {\n namespaces[name] = buildNamespace(\n name,\n declaration,\n diagnostics,\n sourceFile,\n pslBlockDescriptors,\n );\n }\n } else if (declaration instanceof TypesBlockAst) {\n for (const binding of declaration.declarations()) {\n const name = claim(topLevelNames, binding.name());\n if (name === undefined) continue;\n const resolved = resolveNamedTypeBinding(binding, sourceFile);\n const span = nodePslSpan(binding.syntax, sourceFile);\n if (isScalarBinding(binding, scalarSet)) {\n scalars[name] = { kind: 'scalar', name, node: binding, span, ...resolved };\n } else {\n typeAliases[name] = { kind: 'typeAlias', name, node: binding, span, ...resolved };\n }\n }\n }\n }\n\n const table: SymbolTable = {\n topLevel: { namespaces, scalars, typeAliases, blocks, models, compositeTypes },\n };\n return { table, diagnostics };\n}\n\nfunction buildModel(\n name: string,\n node: ModelDeclarationAst,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): ModelSymbol {\n return {\n kind: 'model',\n name,\n node,\n span: nodePslSpan(node.syntax, sourceFile),\n fields: buildFields(name, node.fields(), sourceFile, diagnostics),\n attributes: readResolvedAttributes(node.attributes(), sourceFile),\n };\n}\n\nfunction buildCompositeType(\n name: string,\n node: CompositeTypeDeclarationAst,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): CompositeTypeSymbol {\n return {\n kind: 'compositeType',\n name,\n node,\n span: nodePslSpan(node.syntax, sourceFile),\n fields: buildFields(name, node.fields(), sourceFile, diagnostics),\n attributes: readResolvedAttributes(node.attributes(), sourceFile),\n };\n}\n\nfunction buildBlock(\n name: string,\n node: GenericBlockDeclarationAst,\n sourceFile: SourceFile,\n pslBlockDescriptors: AuthoringPslBlockDescriptorNamespace,\n diagnostics: ParseDiagnostic[],\n): BlockSymbol {\n const keyword = node.keyword()?.text ?? '';\n const descriptor = findBlockDescriptor(pslBlockDescriptors, keyword);\n return {\n kind: 'block',\n name,\n keyword,\n node,\n span: nodePslSpan(node.syntax, sourceFile),\n block: reconstructExtensionBlock(node, descriptor, sourceFile, diagnostics),\n };\n}\n\nfunction buildNamespace(\n name: string,\n node: NamespaceDeclarationAst,\n diagnostics: ParseDiagnostic[],\n sourceFile: SourceFile,\n pslBlockDescriptors: AuthoringPslBlockDescriptorNamespace,\n): NamespaceSymbol {\n const models: Record<string, ModelSymbol> = {};\n const compositeTypes: Record<string, CompositeTypeSymbol> = {};\n const blocks: Record<string, BlockSymbol> = {};\n const taken = new Set<string>();\n\n for (const member of node.declarations()) {\n const memberName = member.name()?.name();\n if (memberName === undefined) continue;\n if (taken.has(memberName)) {\n const range = nameRange(member.name(), sourceFile);\n if (range) {\n diagnostics.push({\n code: 'PSL_DUPLICATE_DECLARATION',\n message: `Duplicate declaration of \"${memberName}\"`,\n range,\n });\n }\n continue;\n }\n taken.add(memberName);\n if (member instanceof ModelDeclarationAst) {\n models[memberName] = buildModel(memberName, member, sourceFile, diagnostics);\n } else if (member instanceof CompositeTypeDeclarationAst) {\n compositeTypes[memberName] = buildCompositeType(memberName, member, sourceFile, diagnostics);\n } else if (member instanceof GenericBlockDeclarationAst) {\n blocks[memberName] = buildBlock(\n memberName,\n member,\n sourceFile,\n pslBlockDescriptors,\n diagnostics,\n );\n }\n }\n\n return {\n kind: 'namespace',\n name,\n node,\n span: nodePslSpan(node.syntax, sourceFile),\n models,\n compositeTypes,\n blocks,\n };\n}\n\nfunction buildFields(\n ownerName: string,\n fields: Iterable<FieldDeclarationAst>,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): Record<string, FieldSymbol> {\n const result: Record<string, FieldSymbol> = {};\n for (const field of fields) {\n const nameNode = field.name();\n const name = nameNode?.name();\n if (name === undefined) continue;\n if (Object.hasOwn(result, name)) {\n const range = nameRange(nameNode, sourceFile);\n if (range) {\n diagnostics.push({\n code: 'PSL_DUPLICATE_DECLARATION',\n message: `Duplicate declaration of \"${name}\"`,\n range,\n });\n }\n continue;\n }\n result[name] = buildField(ownerName, name, field, sourceFile, diagnostics);\n }\n return result;\n}\n\nfunction buildField(\n ownerName: string,\n name: string,\n node: FieldDeclarationAst,\n sourceFile: SourceFile,\n diagnostics: ParseDiagnostic[],\n): FieldSymbol {\n const attributes = readResolvedAttributes(node.attributes(), sourceFile);\n const span = nodePslSpan(node.syntax, sourceFile);\n const annotation = node.typeAnnotation();\n const typeName = annotation?.name();\n\n if (typeName?.isOverQualified()) {\n const path = typeName.path();\n diagnostics.push({\n code: 'PSL_INVALID_QUALIFIED_TYPE',\n message: `Field \"${ownerName}.${name}\" has an invalid qualified type \"${path.join('.')}\"; use at most one namespace qualifier (e.g. \"ns.TypeName\")`,\n range: nodeRange(typeName.syntax, sourceFile),\n });\n return {\n kind: 'field',\n name,\n node,\n span,\n typeName: path[path.length - 1] ?? '',\n optional: false,\n list: false,\n malformedType: true,\n attributes,\n };\n }\n\n const typeConstructor = annotation?.isConstructor()\n ? readResolvedConstructorCall(annotation, sourceFile)\n : undefined;\n const typeNamespaceId = typeName?.namespace()?.name();\n const typeContractSpaceId = typeName?.space()?.name();\n\n return {\n kind: 'field',\n name,\n node,\n span,\n typeName: typeName?.identifier()?.name() ?? '',\n ...(typeNamespaceId !== undefined ? { typeNamespaceId } : {}),\n ...(typeContractSpaceId !== undefined ? { typeContractSpaceId } : {}),\n optional: annotation?.isOptional() ?? false,\n list: annotation?.isList() ?? false,\n ...(typeConstructor !== undefined ? { typeConstructor } : {}),\n attributes,\n };\n}\n\nfunction resolveNamedTypeBinding(\n node: NamedTypeDeclarationAst,\n sourceFile: SourceFile,\n): {\n baseType?: string;\n typeConstructor?: ResolvedTypeConstructorCall;\n isConstructor: boolean;\n attributes: readonly ResolvedAttribute[];\n} {\n const annotation = node.typeAnnotation();\n const isConstructor = annotation?.isConstructor() ?? false;\n const baseType = annotation?.name()?.identifier()?.name();\n const typeConstructor = readResolvedConstructorCall(annotation, sourceFile);\n return {\n isConstructor,\n ...(!isConstructor && baseType !== undefined ? { baseType } : {}),\n ...(typeConstructor !== undefined ? { typeConstructor } : {}),\n attributes: readResolvedAttributes(node.attributes(), sourceFile),\n };\n}\n\nfunction isScalarBinding(node: NamedTypeDeclarationAst, scalarTypes: Set<string>): boolean {\n const annotation = node.typeAnnotation();\n if (annotation === undefined || annotation.isConstructor()) return false;\n const base = annotation.name()?.identifier()?.name();\n return base !== undefined && scalarTypes.has(base);\n}\n\nfunction nameRange(name: IdentifierAst | undefined, sourceFile: SourceFile): Range | undefined {\n if (name === undefined) return undefined;\n for (const token of name.syntax.tokens()) {\n if (token.kind === 'Ident') {\n return {\n start: sourceFile.positionAt(token.offset),\n end: sourceFile.positionAt(token.offset + token.text.length),\n };\n }\n }\n return undefined;\n}\n\nfunction nodeRange(node: SyntaxNode, sourceFile: SourceFile): Range {\n const start = node.offset;\n const end = start + node.green.textLength;\n return {\n start: sourceFile.positionAt(start),\n end: sourceFile.positionAt(end),\n };\n}\n"],"mappings":";;;;;;AAEA,SAAgB,sBAAsB,WAAyB,QAAQ,GAAuB;CAE5F,OADgB,UAAU,KAAK,QAAQ,QAAQ,IAAI,SAAS,YAC/C,CAAC,CAAC,MAAM,EAAE;AACzB;AAEA,SAAgB,yBAAyB,OAAmC;CAE1E,MAAM,QADU,MAAM,KACF,CAAC,CAAC,MAAM,gBAAgB;CAC5C,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,OAAO,MAAM,MAAM;AACrB;;;ACqBA,SAAgB,sBACd,WACA,YACmB;CACnB,OAAO;EACL,MAAM,cAAc,UAAU,KAAK,CAAC;EACpC,MAAM,oBAAoB,UAAU,QAAQ,GAAG,UAAU;EAC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AM,QAAQ,KAAK;CACnB,MAAM,MAAM,QAAQ,KAAK,MAAM;CAC/B,OAAO;EACL,OAAO,WAAW,WAAW,KAAK;EAClC,KAAK,WAAW,WAAW,GAAG;CAChC;AACF"}
@@ -0,0 +1,39 @@
1
+ import { c as DocumentAst, et as SourceFile } from "./parse-BazJr7Ye.mjs";
2
+ import { l as SymbolTable } from "./symbol-table-C-AH04Ug.mjs";
3
+ import { Result } from "@prisma-next/utils/result";
4
+ import { ContractSourceContext, ContractSourceDiagnostic, ContractSourceDiagnostics, ContractSourceProvider, PslContractSourceProvider } from "@prisma-next/config/config-types";
5
+ import { Contract } from "@prisma-next/contract/types";
6
+
7
+ //#region src/interpret.d.ts
8
+ /**
9
+ * Lets editor tooling that already parses incrementally (e.g. the language
10
+ * server) hand cached artifacts to the interpreter instead of forcing a
11
+ * disk re-parse.
12
+ */
13
+ interface PslInterpretInput {
14
+ readonly document: DocumentAst;
15
+ readonly sourceFile: SourceFile;
16
+ readonly symbolTable: SymbolTable;
17
+ readonly sourceId: string;
18
+ }
19
+ /**
20
+ * Declared here — the authoring layer that owns `DocumentAst` / `SourceFile` /
21
+ * `SymbolTable` — because `@prisma-next/config` (core) cannot name authoring
22
+ * types. `interpret` must not read disk or `context.resolvedInputs` — those
23
+ * are load-path concerns.
24
+ */
25
+ interface PslInterpretCapable extends PslContractSourceProvider {
26
+ interpret(input: PslInterpretInput, context: ContractSourceContext): Result<Contract, ContractSourceDiagnostics>;
27
+ }
28
+ /**
29
+ * Merges caller-side diagnostics (e.g. parse / symbol-table findings) into an
30
+ * interpretation result. The authored headline is deliberately uniform — it
31
+ * reports how many errors the schema has, never which pipeline stage found
32
+ * them.
33
+ */
34
+ declare function withSeedDiagnostics(result: Result<Contract, ContractSourceDiagnostics>, seedDiagnostics: readonly ContractSourceDiagnostic[]): Result<Contract, ContractSourceDiagnostics>;
35
+ /** The single seam that narrows a contract source to the interpret capability. */
36
+ declare function hasPslInterpreter(source: ContractSourceProvider): source is PslInterpretCapable;
37
+ //#endregion
38
+ export { type PslInterpretCapable, type PslInterpretInput, hasPslInterpreter, withSeedDiagnostics };
39
+ //# sourceMappingURL=interpret.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpret.d.mts","names":[],"sources":["../src/interpret.ts"],"mappings":";;;;;;;;AAkBA;;;;UAAiB,iBAAA;EAAA,SACN,QAAA,EAAU,WAAA;EAAA,SACV,UAAA,EAAY,UAAA;EAAA,SACZ,WAAA,EAAa,WAAA;EAAA,SACb,QAAA;AAAA;;;;;;;UASM,mBAAA,SAA4B,yBAAA;EAC3C,SAAA,CACE,KAAA,EAAO,iBAAA,EACP,OAAA,EAAS,qBAAA,GACR,MAAA,CAAO,QAAA,EAAU,yBAAA;AAAA;;;;;;;iBASN,mBAAA,CACd,MAAA,EAAQ,MAAA,CAAO,QAAA,EAAU,yBAAA,GACzB,eAAA,WAA0B,wBAAA,KACzB,MAAA,CAAO,QAAA,EAAU,yBAAA;;iBAeJ,iBAAA,CAAkB,MAAA,EAAQ,sBAAA,GAAyB,MAAA,IAAU,mBAAmB"}
@@ -0,0 +1,25 @@
1
+ import { notOk } from "@prisma-next/utils/result";
2
+ //#region src/interpret.ts
3
+ /**
4
+ * Merges caller-side diagnostics (e.g. parse / symbol-table findings) into an
5
+ * interpretation result. The authored headline is deliberately uniform — it
6
+ * reports how many errors the schema has, never which pipeline stage found
7
+ * them.
8
+ */
9
+ function withSeedDiagnostics(result, seedDiagnostics) {
10
+ if (seedDiagnostics.length === 0) return result;
11
+ const diagnostics = result.ok ? seedDiagnostics : [...seedDiagnostics, ...result.failure.diagnostics];
12
+ return notOk({
13
+ summary: `Schema has ${diagnostics.length} error${diagnostics.length === 1 ? "" : "s"}`,
14
+ diagnostics,
15
+ ...result.ok || result.failure.meta === void 0 ? {} : { meta: result.failure.meta }
16
+ });
17
+ }
18
+ /** The single seam that narrows a contract source to the interpret capability. */
19
+ function hasPslInterpreter(source) {
20
+ return source.sourceFormat === "psl" && "interpret" in source && typeof source.interpret === "function";
21
+ }
22
+ //#endregion
23
+ export { hasPslInterpreter, withSeedDiagnostics };
24
+
25
+ //# sourceMappingURL=interpret.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpret.mjs","names":[],"sources":["../src/interpret.ts"],"sourcesContent":["import type {\n ContractSourceContext,\n ContractSourceDiagnostic,\n ContractSourceDiagnostics,\n ContractSourceProvider,\n PslContractSourceProvider,\n} from '@prisma-next/config/config-types';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { notOk, type Result } from '@prisma-next/utils/result';\nimport type { SourceFile } from './source-file';\nimport type { SymbolTable } from './symbol-table';\nimport type { DocumentAst } from './syntax/ast/declarations';\n\n/**\n * Lets editor tooling that already parses incrementally (e.g. the language\n * server) hand cached artifacts to the interpreter instead of forcing a\n * disk re-parse.\n */\nexport interface PslInterpretInput {\n readonly document: DocumentAst;\n readonly sourceFile: SourceFile;\n readonly symbolTable: SymbolTable;\n readonly sourceId: string;\n}\n\n/**\n * Declared here — the authoring layer that owns `DocumentAst` / `SourceFile` /\n * `SymbolTable` — because `@prisma-next/config` (core) cannot name authoring\n * types. `interpret` must not read disk or `context.resolvedInputs` — those\n * are load-path concerns.\n */\nexport interface PslInterpretCapable extends PslContractSourceProvider {\n interpret(\n input: PslInterpretInput,\n context: ContractSourceContext,\n ): Result<Contract, ContractSourceDiagnostics>;\n}\n\n/**\n * Merges caller-side diagnostics (e.g. parse / symbol-table findings) into an\n * interpretation result. The authored headline is deliberately uniform — it\n * reports how many errors the schema has, never which pipeline stage found\n * them.\n */\nexport function withSeedDiagnostics(\n result: Result<Contract, ContractSourceDiagnostics>,\n seedDiagnostics: readonly ContractSourceDiagnostic[],\n): Result<Contract, ContractSourceDiagnostics> {\n if (seedDiagnostics.length === 0) {\n return result;\n }\n const diagnostics = result.ok\n ? seedDiagnostics\n : [...seedDiagnostics, ...result.failure.diagnostics];\n return notOk({\n summary: `Schema has ${diagnostics.length} error${diagnostics.length === 1 ? '' : 's'}`,\n diagnostics,\n ...(result.ok || result.failure.meta === undefined ? {} : { meta: result.failure.meta }),\n });\n}\n\n/** The single seam that narrows a contract source to the interpret capability. */\nexport function hasPslInterpreter(source: ContractSourceProvider): source is PslInterpretCapable {\n return (\n source.sourceFormat === 'psl' && 'interpret' in source && typeof source.interpret === 'function'\n );\n}\n"],"mappings":";;;;;;;;AA4CA,SAAgB,oBACd,QACA,iBAC6C;CAC7C,IAAI,gBAAgB,WAAW,GAC7B,OAAO;CAET,MAAM,cAAc,OAAO,KACvB,kBACA,CAAC,GAAG,iBAAiB,GAAG,OAAO,QAAQ,WAAW;CACtD,OAAO,MAAM;EACX,SAAS,cAAc,YAAY,OAAO,QAAQ,YAAY,WAAW,IAAI,KAAK;EAClF;EACA,GAAI,OAAO,MAAM,OAAO,QAAQ,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,OAAO,QAAQ,KAAK;CACxF,CAAC;AACH;;AAGA,SAAgB,kBAAkB,QAA+D;CAC/F,OACE,OAAO,iBAAiB,SAAS,eAAe,UAAU,OAAO,OAAO,cAAc;AAE1F"}