//#region src/dsl.d.ts /** * ParseResult is the result of a direct parse. */ type ParseResult = { /** * error is the parsing error found, if any. */ error: ParseError | undefined; /** * schema is the fully parsed schema, if no error. */ schema: ParsedSchema | undefined; }; /** * ParseError represents an error raised by the parser. */ type ParseError = { /** * message is the human-readable error message. */ message: string; /** * index is the location of the parse error. */ index: Index; /** * expected is the set of expected regular expression(s) at the index. */ expected: Array; }; /** * parseSchema parses a DSL schema, returning relevant semantic information * or undefined if the parse failed. */ declare const parseSchema: (value: string) => ParsedSchema | undefined; /** * TopLevelDefinition are the types of definitions found at the root of a schema. */ type TopLevelDefinition = ParsedObjectDefinition | ParsedCaveatDefinition | ParsedPartialDefinition | ParsedImportExpression | ParsedUseFlag; /** * parse performs a parse on the schema string, returning the full parse result. */ declare function parse(input: string): ParseResult; /** * ReferenceNode is the node returned by findReferenceNode, along with its parent definition, * if any. */ type ReferenceNode = { node: ParsedRelationRefExpression | TypeRef | undefined; def: TopLevelDefinition; }; /** * findReferenceNode walks the parse tree to find the node matching the given line number and * column position. */ declare function findReferenceNode(schema: ParsedSchema, lineNumber: number, columnPosition: number): ReferenceNode | undefined; type ParsedSchema = { kind: "schema"; stringValue: string; definitions: Array; }; type ParsedUseFlag = { kind: "use"; featureName: string; range: TextRange; }; type ParsedImportExpression = { kind: "import"; path: string; range: TextRange; }; type ParsedCaveatDefinition = { kind: "caveatDef"; name: string; parameters: Array; expression: ParsedCaveatExpression; range: TextRange; }; type ParsedCaveatExpression = { kind: "caveatExpr"; range: TextRange; }; type ParsedCaveatParameter = { kind: "caveatParameter"; name: string; type: ParsedCaveatParameterTypeRef; range: TextRange; }; type ParsedCaveatParameterTypeRef = { kind: "caveatParameterTypeExpr"; name: string; generics: Array; range: TextRange; }; type ParsedObjectDefinition = { kind: "objectDef"; name: string; relations: Array; permissions: Array; partialReferences: Array; range: TextRange; }; type ParsedPartialDefinition = { kind: "partial"; name: string; relations: Array; permissions: Array; partialReferences: Array; range: TextRange; }; type PartialReference = { kind: "partialreference"; name: string; range: TextRange; }; type ParsedRelation = { kind: "relation"; name: string; allowedTypes: TypeExpr; range: TextRange; }; type ParsedExpression = ParsedBinaryExpression | ParsedRelationRefExpression | ParsedArrowExpression | ParsedNamedArrowExpression | ParsedNilExpression; type ParsedArrowExpression = { kind: "arrow"; sourceRelation: ParsedRelationRefExpression; targetRelationOrPermission: string; range: TextRange; }; type ParsedNamedArrowExpression = { kind: "namedarrow"; sourceRelation: ParsedRelationRefExpression; functionName: string; targetRelationOrPermission: string; range: TextRange; }; type ParsedRelationRefExpression = { kind: "relationref"; relationName: string; range: TextRange; }; type ParsedNilExpression = { kind: "nil"; isNil: true; range: TextRange; }; type ParsedBinaryExpression = { kind: "binary"; operator: "union" | "intersection" | "exclusion"; left: ParsedExpression; right: ParsedExpression; range: TextRange; }; type ParsedPermission = { kind: "permission"; name: string; /** * annotatedTypes is the optional `use typechecking` return-type annotation on the * permission (e.g. `permission view: user | group = ...`), or undefined if none was * written. Each annotated type is a plain type reference to a definition. */ annotatedTypes: TypeExpr | undefined; expr: ParsedExpression; range: TextRange; }; type TypeRef = { kind: "typeref"; path: string; relationName: string | undefined; wildcard: boolean; withCaveat: WithCaveat | undefined; withExpiration: WithExpiration | undefined; range: TextRange; }; type WithExpiration = { kind: "withexpiration"; range: TextRange; }; type WithCaveat = { kind: "withcaveat"; path: string; range: TextRange; }; type TypeExpr = { kind: "typeexpr"; types: Array; range: TextRange; }; type Index = { offset: number; line: number; column: number; }; type TextRange = { startIndex: Index; endIndex: Index; }; //#endregion //#region src/resolution.d.ts /** * TypeRefResolution is the result of resolving a type reference. */ type TypeRefResolution = { /** * definition is the definition which is referred by this type reference. */ definition: ParsedObjectDefinition | undefined; /** * relation is the (optional) relation which is referred by this type reference. For refs * without relations, this will be undefined. This will *also* be undefined for unresolvable * refs, so make sure to check the expression to see if it has a relation reference. */ relation: ParsedRelation | undefined; /** * permission is the (optional) permission which is referred by this type reference. For refs * without relations, this will be undefined. This will *also* be undefined for unresolvable * refs, so make sure to check the expression to see if it has a relation reference. */ permission: ParsedPermission | undefined; }; /** * ExpressionResolution is the resolution of a reference in a permission expression. */ type ExpressionResolution = ParsedRelation | ParsedPermission; /** * ResolvedTypeReference is a type reference found in the schema, with resolution attempted. */ type ResolvedTypeReference = { kind: "type"; reference: TypeRef; referencedTypeAndRelation: TypeRefResolution | undefined; }; /** * ResolvedExprReference is a relation reference expression found in the schema, with resolution attempted. */ type ResolvedExprReference = { kind: "expression"; reference: ParsedRelationRefExpression; resolvedRelationOrPermission: ExpressionResolution | undefined; }; /** * ResolvedReference is a found and resolution performed type reference or expression. */ type ResolvedReference = ResolvedTypeReference | ResolvedExprReference; /** * Resolver is a helper class for easily resolving information in a parsed schema. */ declare class Resolver { private definitionsByName; private caveatsByName; private populated; schema: ParsedSchema; constructor(schema: ParsedSchema); private populate; /** * listDefinitions lists all definitions in the resolver. */ listDefinitions(): Array; /** * lookupDefinition returns the definition with the given name, if any, or undefined * if none. */ lookupDefinition(name: string): ResolvedDefinition | undefined; /** * listCaveats returns all resolved caveat definitions in the schema. */ listCaveats(): Array; /** * resolvedReferences returns all the resolved type and expression references in the schema. */ resolvedReferences(): Array; /** * resolveTypeReference attempts to resolve a type reference. */ resolveTypeReference(typeRef: TypeRef): TypeRefResolution | undefined; /** * resolveRelationOrPermission attempts to resolve a relation reference expression. */ resolveRelationOrPermission(current: ParsedRelationRefExpression, def: TopLevelDefinition): ExpressionResolution | undefined; private lookupAndResolveTypeReferences; private lookupAndResolveExprReferences; } declare class ResolvedDefinition { private relationsByName; private permissionByName; definition: ParsedObjectDefinition; constructor(definition: ParsedObjectDefinition); listRelationNames(): Array; listRelations(): Array; listRelationsAndPermissions(): Array; listRelationsAndPermissionNames(): Array; listWithCaveatNames(): Array; lookupRelation(name: string): ParsedRelation | undefined; lookupPermission(name: string): ParsedPermission | undefined; lookupRelationOrPermission(name: string): ParsedRelation | ParsedPermission | undefined; } declare class ResolvedCaveatDefinition { private paramsByName; private name; definition: ParsedCaveatDefinition; constructor(definition: ParsedCaveatDefinition); getName(): string; listParameterNames(): Array; } //#endregion export { type ParsedArrowExpression, type ParsedBinaryExpression, type ParsedExpression, type ParsedObjectDefinition, type ParsedPermission, type ParsedRelation, type ParsedRelationRefExpression, type ParsedSchema, type ResolvedCaveatDefinition, ResolvedDefinition, type ResolvedReference, Resolver, type TextRange, type TypeRef, findReferenceNode, parse, parseSchema }; //# sourceMappingURL=index.d.cts.map