File: types.cue

package info (click to toggle)
golang-github-cue-lang-cue 0.12.0.-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,072 kB
  • sloc: sh: 57; makefile: 17
file content (368 lines) | stat: -rw-r--r-- 8,474 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
// Copyright 2020 CUE Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package build

// This file describes how various cross-cutting modes influence default
// settings.
//
// It is used by types.go to compile a cue.Value, which is then
// used by the rest of the package to determine settings.

// A File corresponds to a Go build.File.
#File: {
	filename?:       string // only filled in FromFile, but not in ParseFile
	encoding!:       #Encoding
	interpretation?: #Interpretation
	form?:           #Form
	// Note: tags includes values for non-boolean tags only.
	tags?: [string]: string
	boolTags?: [string]: bool
}

// Default is the file used for stdin and stdout. The settings depend
// on the file mode.
#Default: #FileInfo & {
	filename: *"-" | string
}

// A FileInfo defines how a file is encoded and interpreted.
#FileInfo: {
	#File

	// For each of these fields it is explained what a true value means
	// for encoding/decoding.

	data:          *true | false // include/allow regular fields
	references:    *true | false // don't resolve/allow references
	cycles:        *true | false // cycles are permitted
	definitions?:  bool          // include/allow definition fields
	optional?:     bool          // include/allow definition fields
	constraints?:  bool          // include/allow constraints
	keepDefaults?: bool          // select/allow default values
	incomplete?:   bool          // permit incomplete values
	imports?:      bool          // don't expand/allow imports
	stream?:       bool          // permit streaming
	docs?:         bool          // show/allow docs
	attributes?:   bool          // include/allow attributes
}

// fileForExtVanilla holds the extensions supported in
// input mode with scope="" - the most common form
// of file type to evaluate.
//
// It's also used as a source of truth for all known file
// extensions as all modes define attributes for
// all file extensions. If that ever changed, we'd need
// to change this.
fileForExtVanilla: modes.input.extensions

// modes sets defaults for different operational modes.
// The key corresponds to the Go internal/filetypes.Mode type.
modes: [string]: {
	// FileInfo holds the base file information for this mode.
	// This will be unified with information derived from the
	// file extension and any filetype tags explicitly provided.
	FileInfo!: #FileInfo

	// Default holds the base file information for standard input
	// or output, where we don't have any file extension available.
	Default!: #Default
}

// input defines modes for input, such as import, eval, vet or def.
// In input mode, settings flags are interpreted as what is allowed to occur
// in the input. The default settings, therefore, tend to be permissive.
modes: input: {
	Default: {
		encoding: *"cue" | _
	}
	FileInfo: {
		docs:       *true | false
		attributes: *true | false
	}
	encodings: cue: {
		*forms.schema | _
	}
	extensions: ".json": interpretation: *"auto" | _
	extensions: ".yaml": interpretation: *"auto" | _
	extensions: ".yml": interpretation:  *"auto" | _
	extensions: ".toml": interpretation: *"auto" | _
}

modes: export: {
	Default: {
		encoding: *"json" | _
	}
	FileInfo: {
		docs:       true | *false
		attributes: true | *false
	}
	encodings: cue: forms.data
}

// eval is a legacy mode
modes: eval: {
	Default: {
		encoding: *"cue" | _
	}
	FileInfo: {
		docs:       true | *false
		attributes: true | *false
	}
	encodings: cue: forms.final
}

modes: def: {
	Default: {
		encoding: *"cue" | _
	}
	FileInfo: {
		docs:       *true | false
		attributes: *true | false
	}
	encodings: cue: forms.schema
}

// A Encoding indicates a file format for representing a program.
#Encoding: !="" // | error("no encoding specified")

// An Interpretation determines how a certain program should be interpreted.
// For instance, data may be interpreted as describing a schema, which itself
// can be converted to a CUE schema.
// This corresponds to the Go cue/build.Interpretation type.
#Interpretation: string

// A Form specifies the form in which a program should be represented.
// It corresponds to the Go cue/build.Form type.
#Form: string

modes: [string]: {
	// extensions maps a file extension to its associated default file properties.
	extensions: {
		// "":           _
		".cue":       tagInfo.cue
		".json":      tagInfo.json
		".jsonl":     tagInfo.jsonl
		".ldjson":    tagInfo.jsonl
		".ndjson":    tagInfo.jsonl
		".yaml":      tagInfo.yaml
		".yml":       tagInfo.yaml
		".toml":      tagInfo.toml
		".txt":       tagInfo.text
		".go":        tagInfo.go
		".wasm":      tagInfo.binary
		".proto":     tagInfo.proto
		".textproto": tagInfo.textproto
		".textpb":    tagInfo.textproto // perhaps also pbtxt

		// TODO: jsonseq,
		// ".pb":        tagInfo.binpb // binarypb
	}

	// encodings: "": error("no encoding specified")

	encodings: cue: {
		stream: false
	}

	encodings: json: {
		forms.data
		stream:     *false | true
		docs:       false
		attributes: false
	}

	encodings: yaml: {
		forms.graph
		stream: false | *true
	}

	encodings: jsonl: {
		forms.data
		stream: true
	}

	encodings: text: {
		forms.data
		stream: false
	}

	encodings: binary: {
		forms.data
		stream: false
	}

	encodings: toml: {
		forms.data
		stream: false
	}

	encodings: proto: {
		forms.schema
		encoding: "proto"
	}

	encodings: textproto: {
		forms.data
		encoding: "textproto"
		stream:   false
	}

	encodings: binarypb: {
		forms.data
		encoding: "binarypb"
		stream:   false
	}

	encodings: code: {
		forms.schema
		stream: false
	}
}

// forms defines schema for all forms. It does not include the form ID.
forms: [Name=string]: #FileInfo

forms: schema: {
	form: *"schema" | "final" | "graph"

	stream:       true | *false
	incomplete:   *true | false
	definitions:  *true | false
	optional:     *true | false
	constraints:  *true | false
	keepDefaults: *true | false
	imports:      *true | false
}

forms: final: {
	form: "final"
	forms.schema

	keepDefaults: false
	optional:     false
}

forms: graph: {
	form: *"graph" | "dag" | "data"
	data: true

	incomplete:   false
	definitions:  false
	optional:     false
	constraints:  false
	keepDefaults: false
	imports:      false
}

forms: dag: {
	form: !="graph"
	forms.graph

	cycles: false
}

forms: data: {
	form: !="dag"
	forms.dag

	constraints: false
	references:  false
	cycles:      false
	imports:     false
	optional:    false
}

interpretations: [Name=string]: #FileInfo & {
	interpretation: Name
}

interpretations: auto: forms.schema

interpretations: jsonschema: {
	forms.schema
	encoding: *"json" | _
	boolTags: {
		strict:         *false | bool
		strictKeywords: *strict | bool
		// TODO(v0.12): enable strictFeatures by default
		strictFeatures: *strict | bool
	}
}

interpretations: openapi: {
	forms.schema
	encoding: *"json" | _
	boolTags: {
		strict:         *false | bool
		strictKeywords: *strict | bool
		strictFeatures: *strict | bool
	}
}

interpretations: pb: {
	forms.data
	stream: true
}

// tagInfo maps command line tags to file properties.
tagInfo: {
	schema: form: "schema"
	graph: form:  "graph"
	dag: form:    "dag"
	data: form:   "data"

	cue: encoding:       "cue"
	json: encoding:      "json"
	jsonl: encoding:     "jsonl"
	yaml: encoding:      "yaml"
	toml: encoding:      "toml"
	proto: encoding:     "proto"
	textproto: encoding: "textproto"
	// "binpb":  encodings.binproto

	// pb is used either to indicate binary encoding, or to indicate
	pb: *{
		encoding:       "binarypb"
		interpretation: ""
	} | {
		encoding:       !="binarypb"
		interpretation: "pb"
	}

	text: {
		encoding: "text"
		form:     "data"
	}
	binary: {
		encoding: "binary"
		form:     "data"
	}
	go: {
		encoding:       "code"
		interpretation: ""
		tags: lang: "go"
	}
	code: {
		encoding:       "code"
		interpretation: ""
		tags: lang: *"" | string
	}
	auto: interpretations.auto & {
		encoding: *"json" | string
	}
	jsonschema: interpretations.jsonschema
	openapi:    interpretations.openapi
}