cuelang.org/go@v0.13.0/cue/build/file.go (about)

     1  // Copyright 2020 CUE Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package build
    16  
    17  import "cuelang.org/go/cue/errors"
    18  
    19  // Note: the json tags in File correspond directly to names
    20  // used in the encoding/filetypes package, which unmarshals
    21  // results from CUE into a build.File.
    22  
    23  // A File represents a file that is part of the build process.
    24  type File struct {
    25  	Filename string `json:"filename"`
    26  
    27  	Encoding       Encoding       `json:"encoding,omitempty"`
    28  	Interpretation Interpretation `json:"interpretation,omitempty"`
    29  	Form           Form           `json:"form,omitempty"`
    30  	// Tags holds key-value pairs relating to the encoding
    31  	// conventions to use for the file.
    32  	Tags map[string]string `json:"tags,omitempty"` // e.g. code+lang=go
    33  
    34  	// BoolTags holds boolean-valued tags relating to the
    35  	// encoding conventions to use for the file.
    36  	BoolTags map[string]bool `json:"boolTags,omitempty"`
    37  
    38  	ExcludeReason errors.Error `json:"-"`
    39  	Source        interface{}  `json:"-"` // TODO: swap out with concrete type.
    40  }
    41  
    42  // A Encoding indicates a file format for representing a program.
    43  type Encoding string
    44  
    45  const (
    46  	CUE         Encoding = "cue"
    47  	JSON        Encoding = "json"
    48  	YAML        Encoding = "yaml"
    49  	TOML        Encoding = "toml"
    50  	XML         Encoding = "xml"
    51  	JSONL       Encoding = "jsonl"
    52  	Text        Encoding = "text"
    53  	Binary      Encoding = "binary"
    54  	Protobuf    Encoding = "proto"
    55  	TextProto   Encoding = "textproto"
    56  	BinaryProto Encoding = "pb"
    57  
    58  	Code Encoding = "code" // Programming languages
    59  )
    60  
    61  // An Interpretation determines how a certain program should be interpreted.
    62  // For instance, data may be interpreted as describing a schema, which itself
    63  // can be converted to a CUE schema.
    64  type Interpretation string
    65  
    66  const (
    67  	// Auto interprets the underlying data file as data, JSON Schema or OpenAPI,
    68  	// depending on the existence of certain marker fields.
    69  	//
    70  	// JSON Schema is identified by a top-level "$schema" field with a URL
    71  	// of the form "https?://json-schema.org/.*schema#?".
    72  	//
    73  	// OpenAPI is identified by the existence of a top-level field "openapi"
    74  	// with a major semantic version of 3, as well as the existence of
    75  	// the info.title and info.version fields.
    76  	//
    77  	// In all other cases, the underlying data is interpreted as is.
    78  	Auto         Interpretation = "auto"
    79  	JSONSchema   Interpretation = "jsonschema"
    80  	OpenAPI      Interpretation = "openapi"
    81  	ProtobufJSON Interpretation = "pb"
    82  )
    83  
    84  // A Form specifies the form in which a program should be represented.
    85  type Form string
    86  
    87  const (
    88  	Full   Form = "full"
    89  	Schema Form = "schema"
    90  	Struct Form = "struct"
    91  	Final  Form = "final" // picking default values, may be non-concrete
    92  	Graph  Form = "graph" // Data only, but allow references
    93  	DAG    Form = "dag"   // Like graph, but don't allow cycles
    94  	Data   Form = "data"  // always final
    95  )