github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/internal/filetypes/types.cue (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  // This file describes how various cross-cutting modes influence default
    18  // settings.
    19  //
    20  // It is used by gen.go to compile the instance into Go data, which is then
    21  // used by the rest of the package to determine settings.
    22  //
    23  // There
    24  
    25  // A File corresponds to a Go build.File.
    26  #File: {
    27  	filename:        string
    28  	encoding:        #Encoding
    29  	interpretation?: #Interpretation
    30  	form?:           #Form
    31  	tags?: [string]: string
    32  }
    33  
    34  // Default is the file used for stdin and stdout. The settings depend
    35  // on the file mode.
    36  #Default: #File & {
    37  	filename: *"-" | string
    38  }
    39  
    40  // A FileInfo defines how a file is encoded and interpreted.
    41  #FileInfo: {
    42  	#File
    43  
    44  	// For each of these fields it is explained what a true value means
    45  	// for encoding/decoding.
    46  
    47  	data:         *true | false // include/allow regular fields
    48  	references:   *true | false // don't resolve/allow references
    49  	cycles:       *true | false // cycles are permitted
    50  	definitions:  bool          // include/allow definition fields
    51  	optional:     bool          // include/allow definition fields
    52  	constraints:  bool          // include/allow constraints
    53  	keepDefaults: bool          // select/allow default values
    54  	incomplete:   bool          // permit incomplete values
    55  	imports:      bool          // don't expand/allow imports
    56  	stream:       bool          // permit streaming
    57  	docs:         bool          // show/allow docs
    58  	attributes:   bool          // include/allow attributes
    59  }
    60  
    61  // modes sets defaults for different operational modes.
    62  //
    63  // These templates are intended to be unified in at the root of this
    64  // configuration.
    65  modes: _
    66  
    67  // input defines modes for input, such as import, eval, vet or def.
    68  // In input mode, settings flags are interpreted as what is allowed to occur
    69  // in the input. The default settings, therefore, tend to be permissive.
    70  modes: input: {
    71  	#Default: {
    72  		encoding: *"cue" | _
    73  		...
    74  	}
    75  	#FileInfo: x, let x = {
    76  		docs:       *true | false
    77  		attributes: *true | false
    78  	}
    79  	encodings: cue: {
    80  		*forms.schema | _
    81  	}
    82  	extensions: ".json": interpretation: *"auto" | _
    83  	extensions: ".yaml": interpretation: *"auto" | _
    84  	extensions: ".yml": interpretation:  *"auto" | _
    85  }
    86  
    87  modes: export: {
    88  	#Default: {
    89  		encoding: *"json" | _
    90  		...
    91  	}
    92  	#FileInfo: x, let x = {
    93  		docs:       true | *false
    94  		attributes: true | *false
    95  	}
    96  	encodings: cue: {
    97  		*forms.data | _
    98  	}
    99  }
   100  
   101  modes: ouptut: {
   102  	#FileInfo: x, let x = {
   103  		docs:       true | *false
   104  		attributes: true | *false
   105  	}
   106  	encodings: cue: {
   107  		*forms.data | _
   108  	}
   109  }
   110  
   111  // eval is a legacy mode
   112  modes: eval: {
   113  	#Default: {
   114  		encoding: *"cue" | _
   115  		...
   116  	}
   117  	#FileInfo: x, let x = {
   118  		docs:       true | *false
   119  		attributes: true | *false
   120  	}
   121  	encodings: cue: {
   122  		*forms.final | _
   123  	}
   124  }
   125  
   126  modes: def: {
   127  	#Default: {
   128  		encoding: *"cue" | _
   129  		...
   130  	}
   131  	#FileInfo: x, let x = {
   132  		docs:       *true | false
   133  		attributes: *true | false
   134  	}
   135  	encodings: cue: {
   136  		*forms.schema | _
   137  	}
   138  }
   139  
   140  // Extension maps file extensions to default file properties.
   141  extensions: {
   142  	"":           _
   143  	".cue":       tags.cue
   144  	".json":      tags.json
   145  	".jsonl":     tags.jsonl
   146  	".ldjson":    tags.jsonl
   147  	".ndjson":    tags.jsonl
   148  	".yaml":      tags.yaml
   149  	".yml":       tags.yaml
   150  	".txt":       tags.text
   151  	".go":        tags.go
   152  	".proto":     tags.proto
   153  	".textproto": tags.textproto
   154  	".textpb":    tags.textproto // perhaps also pbtxt
   155  
   156  	// TODO: jsonseq,
   157  	// ".pb":        tags.binpb // binarypb
   158  }
   159  
   160  // A Encoding indicates a file format for representing a program.
   161  #Encoding: !="" // | error("no encoding specified")
   162  
   163  // An Interpretation determines how a certain program should be interpreted.
   164  // For instance, data may be interpreted as describing a schema, which itself
   165  // can be converted to a CUE schema.
   166  #Interpretation: string
   167  #Form:           string
   168  
   169  file: #FileInfo & {
   170  
   171  	filename: "foo.json"
   172  	form:     "schema"
   173  }
   174  
   175  // tags maps command line tags to file properties.
   176  tags: {
   177  	schema: form: "schema"
   178  	graph: form:  "graph"
   179  	dag: form:    "dag"
   180  	data: form:   "data"
   181  
   182  	cue: encoding: "cue"
   183  
   184  	json: encoding:      "json"
   185  	jsonl: encoding:     "jsonl"
   186  	yaml: encoding:      "yaml"
   187  	proto: encoding:     "proto"
   188  	textproto: encoding: "textproto"
   189  	// "binpb":  encodings.binproto
   190  
   191  	// pb is used either to indicate binary encoding, or to indicate
   192  	pb: *{
   193  		encoding:       "binarypb"
   194  		interpretation: ""
   195  	} | {
   196  		encoding:       !="binarypb"
   197  		interpretation: "pb"
   198  	}
   199  
   200  	text: {
   201  		encoding: "text"
   202  		form:     "data"
   203  	}
   204  	binary: {
   205  		encoding: "binary"
   206  		form:     "data"
   207  	}
   208  	go: {
   209  		encoding:       "code"
   210  		interpretation: ""
   211  		tags: lang: "go"
   212  	}
   213  	code: {
   214  		encoding:       "code"
   215  		interpretation: ""
   216  		tags: lang: string
   217  	}
   218  
   219  	auto: {
   220  		interpretation: "auto"
   221  		encoding:       *"json" | _
   222  	}
   223  	jsonschema: {
   224  		interpretation: "jsonschema"
   225  		encoding:       *"json" | _
   226  	}
   227  	openapi: {
   228  		interpretation: "openapi"
   229  		encoding:       *"json" | _
   230  	}
   231  }
   232  
   233  // forms defines schema for all forms. It does not include the form ID.
   234  forms: [Name=string]: #FileInfo
   235  
   236  forms: "": _
   237  
   238  forms: schema: {
   239  	form:   *"schema" | "final" | "graph"
   240  	stream: true | *false
   241  
   242  	incomplete:   *true | false
   243  	definitions:  *true | false
   244  	optional:     *true | false
   245  	constraints:  *true | false
   246  	keepDefaults: *true | false
   247  	imports:      *true | false
   248  	optional:     *true | false
   249  }
   250  
   251  forms: final: {
   252  	form: "final"
   253  	forms.schema
   254  
   255  	keepDefaults: false
   256  	optional:     false
   257  }
   258  
   259  forms: graph: {
   260  	form: *"graph" | "dag" | "data"
   261  	data: true
   262  
   263  	incomplete:   false
   264  	definitions:  false
   265  	optional:     false
   266  	constraints:  false
   267  	keepDefaults: false
   268  	imports:      false
   269  }
   270  
   271  forms: dag: {
   272  	form: !="graph"
   273  	forms.graph
   274  
   275  	cycles: false
   276  }
   277  
   278  forms: data: {
   279  	form: !="dag"
   280  	forms.dag
   281  
   282  	constraints: false
   283  	references:  false
   284  	cycles:      false
   285  	imports:     false
   286  	optional:    false
   287  }
   288  
   289  // encodings: "": error("no encoding specified")
   290  
   291  encodings: cue: {
   292  	stream: false
   293  }
   294  
   295  encodings: json: {
   296  	forms.data
   297  	stream:     *false | true
   298  	docs:       false
   299  	attributes: false
   300  }
   301  
   302  encodings: yaml: {
   303  	forms.graph
   304  	stream: false | *true
   305  }
   306  
   307  encodings: jsonl: {
   308  	forms.data
   309  	stream: true
   310  }
   311  
   312  encodings: text: {
   313  	forms.data
   314  	stream: false
   315  }
   316  
   317  encodings: binary: {
   318  	forms.data
   319  	stream: false
   320  }
   321  
   322  encodings: toml: {
   323  	forms.data
   324  	stream: false
   325  }
   326  
   327  encodings: proto: {
   328  	forms.schema
   329  	encoding: "proto"
   330  }
   331  
   332  encodings: textproto: {
   333  	forms.data
   334  	encoding: "textproto"
   335  	stream:   false
   336  }
   337  
   338  encodings: binarypb: {
   339  	forms.data
   340  	encoding: "binarypb"
   341  	stream:   false
   342  }
   343  
   344  // encodings: binproto: {
   345  //  forms.DataEncoding
   346  //  encoding: "binproto"
   347  // }
   348  
   349  encodings: code: {
   350  	forms.schema
   351  	stream: false
   352  }
   353  
   354  interpretations: [Name=string]: #FileInfo
   355  
   356  interpretations: "": _
   357  
   358  interpretations: auto: {
   359  	forms.schema
   360  }
   361  
   362  interpretations: jsonschema: {
   363  	forms.schema
   364  	encoding: *"json" | _
   365  }
   366  
   367  interpretations: openapi: {
   368  	forms.schema
   369  	encoding: *"json" | _
   370  }
   371  
   372  interpretations: pb: {
   373  	forms.data
   374  	stream: true
   375  }