cuelang.org/go@v0.10.1/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  // A File represents a file that is part of the build process.
    20  type File struct {
    21  	Filename string `json:"filename"`
    22  
    23  	Encoding       Encoding          `json:"encoding,omitempty"`
    24  	Interpretation Interpretation    `json:"interpretation,omitempty"`
    25  	Form           Form              `json:"form,omitempty"`
    26  	Tags           map[string]string `json:"tags,omitempty"` // code=go
    27  
    28  	ExcludeReason errors.Error `json:"-"`
    29  	Source        interface{}  `json:"-"` // TODO: swap out with concrete type.
    30  }
    31  
    32  // A Encoding indicates a file format for representing a program.
    33  type Encoding string
    34  
    35  const (
    36  	CUE         Encoding = "cue"
    37  	JSON        Encoding = "json"
    38  	YAML        Encoding = "yaml"
    39  	TOML        Encoding = "toml"
    40  	JSONL       Encoding = "jsonl"
    41  	Text        Encoding = "text"
    42  	Binary      Encoding = "binary"
    43  	Protobuf    Encoding = "proto"
    44  	TextProto   Encoding = "textproto"
    45  	BinaryProto Encoding = "pb"
    46  
    47  	Code Encoding = "code" // Programming languages
    48  )
    49  
    50  // An Interpretation determines how a certain program should be interpreted.
    51  // For instance, data may be interpreted as describing a schema, which itself
    52  // can be converted to a CUE schema.
    53  type Interpretation string
    54  
    55  const (
    56  	// Auto interprets the underlying data file as data, JSON Schema or OpenAPI,
    57  	// depending on the existence of certain marker fields.
    58  	//
    59  	// JSON Schema is identified by a top-level "$schema" field with a URL
    60  	// of the form "https?://json-schema.org/.*schema#?".
    61  	//
    62  	// OpenAPI is identified by the existence of a top-level field "openapi"
    63  	// with a major semantic version of 3, as well as the existence of
    64  	// the info.title and info.version fields.
    65  	//
    66  	// In all other cases, the underlying data is interpreted as is.
    67  	Auto         Interpretation = "auto"
    68  	JSONSchema   Interpretation = "jsonschema"
    69  	OpenAPI      Interpretation = "openapi"
    70  	ProtobufJSON Interpretation = "pb"
    71  )
    72  
    73  // A Form specifies the form in which a program should be represented.
    74  type Form string
    75  
    76  const (
    77  	Full   Form = "full"
    78  	Schema Form = "schema"
    79  	Struct Form = "struct"
    80  	Final  Form = "final" // picking default values, may be non-concrete
    81  	Graph  Form = "graph" // Data only, but allow references
    82  	DAG    Form = "dag"   // Like graph, but don't allow cycles
    83  	Data   Form = "data"  // always final
    84  )