development

package
v1.36.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 47 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileSchema

func CompileSchema(schema string) (*compiler.CompiledSchema, *devinterface.DeveloperError, error)

CompileSchema compiles a schema into its caveat and namespace definition(s), returning a developer error if the schema could not be compiled. The non-developer error is returned only if an internal errors occurred.

func DistinguishGraphError

func DistinguishGraphError(devContext *DevContext, dispatchError error, source devinterface.DeveloperError_Source, line uint32, column uint32, context string) (*devinterface.DeveloperError, error)

DistinguishGraphError turns an error from a dispatch call into either a user-facing DeveloperError or an internal error, based on the error raised by the dispatcher.

func GenerateValidation

func GenerateValidation(membershipSet *developmentmembership.Set) (string, error)

GenerateValidation generates the validation block based on a membership set.

func GetWarnings added in v1.32.0

func GetWarnings(ctx context.Context, devCtx *DevContext) ([]*devinterface.DeveloperWarning, error)

GetWarnings returns a list of warnings for the given developer context.

func ParseAssertionsYAML

func ParseAssertionsYAML(assertionsYaml string) (*blocks.Assertions, *devinterface.DeveloperError)

ParseAssertionsYAML parses the YAML form of an assertions block.

func ParseExpectedRelationsYAML

func ParseExpectedRelationsYAML(expectedRelationsYaml string) (*blocks.ParsedExpectedRelations, *devinterface.DeveloperError)

ParseExpectedRelationsYAML parses the YAML form of an expected relations block.

func RunAllAssertions

func RunAllAssertions(devContext *DevContext, assertions *blocks.Assertions) ([]*devinterface.DeveloperError, error)

RunAllAssertions runs all assertions found in the given assertions block against the developer context, returning whether any errors occurred.

func RunValidation

RunValidation runs the parsed validation block against the data in the dev context.

Types

type CheckResult added in v1.16.0

type CheckResult struct {
	Permissionship      v1dispatch.ResourceCheckResult_Membership
	MissingCaveatFields []string
	DispatchDebugInfo   *v1dispatch.DebugInformation
	V1DebugInfo         *v1api.DebugInformation
}

CheckResult is the result of a RunCheck operation.

func RunCheck

func RunCheck(devContext *DevContext, resource *core.ObjectAndRelation, subject *core.ObjectAndRelation, caveatContext map[string]any) (CheckResult, error)

RunCheck performs a check against the data in the development context.

Note that it is up to the caller to call DistinguishGraphError on the error if they want to distinguish between user errors and internal errors.

type DevContext

type DevContext struct {
	Ctx            context.Context
	Datastore      datastore.Datastore
	Revision       datastore.Revision
	CompiledSchema *compiler.CompiledSchema
	Dispatcher     dispatch.Dispatcher
}

DevContext holds the various helper types for running the developer calls.

func NewDevContext

func NewDevContext(ctx context.Context, requestContext *devinterface.RequestContext) (*DevContext, *devinterface.DeveloperErrors, error)

NewDevContext creates a new DevContext from the specified request context, parsing and populating the datastore as needed.

func (*DevContext) Dispose

func (dc *DevContext) Dispose()

Dispose disposes of the DevContext and its underlying datastore.

func (*DevContext) RunV1InMemoryService added in v1.16.0

func (dc *DevContext) RunV1InMemoryService() (*grpc.ClientConn, func(), error)

RunV1InMemoryService runs a V1 server in-memory on a buffconn over the given development context and returns a client connection and a function to shutdown the server. It is the responsibility of the caller to call the function to close the server.

type ReferenceType added in v1.31.0

type ReferenceType int

ReferenceType is the type of reference.

const (
	ReferenceTypeUnknown ReferenceType = iota
	ReferenceTypeDefinition
	ReferenceTypeCaveat
	ReferenceTypeRelation
	ReferenceTypePermission
	ReferenceTypeCaveatParameter
)

type Resolver added in v1.31.0

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver resolves references to schema nodes from source positions.

func NewResolver added in v1.31.0

func NewResolver(schema *compiler.CompiledSchema) (*Resolver, error)

NewResolver creates a new resolver for the given schema.

func (*Resolver) ReferenceAtPosition added in v1.31.0

func (r *Resolver) ReferenceAtPosition(source input.Source, position input.Position) (*SchemaReference, error)

ReferenceAtPosition returns the reference to the schema node at the given position in the source, if any.

type SchemaReference added in v1.31.0

type SchemaReference struct {
	// Source is the source of the reference.
	Source input.Source

	// Position is the position of the reference in the source.
	Position input.Position

	// Text is the text of the reference.
	Text string

	// ReferenceType is the type of reference.
	ReferenceType ReferenceType

	// ReferenceMarkdown is the markdown representation of the reference.
	ReferenceMarkdown string

	// TargetSource is the source of the target node, if any.
	TargetSource *input.Source

	// TargetPosition is the position of the target node, if any.
	TargetPosition *input.Position

	// TargetSourceCode is the source code representation of the target, if any.
	TargetSourceCode string

	// TargetNamePositionOffset is the offset from the target position from where the
	// *name* of the target is found.
	TargetNamePositionOffset int
}

SchemaReference represents a reference to a schema node.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL