cuelang.org/go@v0.10.1/internal/mod/modresolve/schema.cue (about)

     1  // Copyright 2024 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  // This aspect of #registry encodes the defaults used by the resolver
    16  // parser. It's kept separate because it's technically bad practice to
    17  // define regular fields as part of a schema, and by defining it this
    18  // way, the pure schema can be read independently as such.
    19  //
    20  // TODO work out a nice way of doing this such that we don't have to
    21  // mirror the fields in #file that mention #registry
    22  #registry: {
    23  	pathEncoding: *"path" | _
    24  }
    25  
    26  // Note: public part of schema (included in help output) starts
    27  // at "// #file" below.
    28  
    29  // #file represents the registry configuration schema.
    30  #file: {
    31  	// moduleRegistries specifies a mapping from module path prefix
    32  	// (excluding any version suffix) to the registry to be used for
    33  	// all modules under that path.
    34  	//
    35  	// A prefix is considered to match if a non-zero number of
    36  	// initial path elements (sequences of non-slash characters) in
    37  	// a module path match the prefix.
    38  	//
    39  	// If there are multiple matching prefixes, the longest
    40  	// is chosen.
    41  	moduleRegistries?: [#modulePath]: #registry
    42  
    43  	// defaultRegistry specifies a fallback registry to be used if no
    44  	// prefix from moduleRegistry matches.
    45  	// If it's not present, a system default will be used.
    46  	defaultRegistry?: #registry
    47  }
    48  
    49  #registry: {
    50  	// registry specifies the registry host name and optionally, the
    51  	// repository prefix to use for all modules in the repository,
    52  	// and the security to use when accessing the host.
    53  	//
    54  	// It is in the form:
    55  	// 	hostname[:port][/repoPrefix][+insecure]
    56  	//
    57  	// The hostname must be specified in square brackets if it's an
    58  	// IPv6 address.
    59  	//
    60  	// Connections will be secure unless explicitly specified
    61  	// otherwise, except for localhost connections which default to
    62  	// insecure.
    63  	//
    64  	// See the doc comment on pathEncoding for details as to how
    65  	// repoPrefix is used to determine the repository to use for a
    66  	// specific module.
    67  	//
    68  	// As a special case, the registry may be "none", indicating
    69  	// that there is no registry for its associated modules.
    70  	// If a module resolves to a "none" registry, the resolver
    71  	// will return an error.
    72  	//
    73  	// Examples:
    74  	//	"localhost:1234"
    75  	//	"myregistry.example/my-modules+secure"
    76  	//	"none"
    77  	registry!: string
    78  
    79  	// pathEncoding specifies how module versions map to
    80  	// repositories within a registry.
    81  	// Possible values are:
    82  	// - "path": the repository is used as a prefix to the unencoded
    83  	// module path. The version of the module is used as a tag.
    84  	// - "hashAsPath": the hex-encoded SHA256 hash of the path is
    85  	// used as a suffix to the above repository value. The version
    86  	// of the module is used as a tag.
    87  	// - "hashAsTag": the repository is used as is: the hex-encoded
    88  	// SHA256 hash of the path followed by a hyphen and the version
    89  	// is used as a tag.
    90  	pathEncoding?: "path" | "hashAsRepo" | "hashAsTag"
    91  
    92  	// prefixForTags specifies an arbitrary prefix that's added to
    93  	// all tags. This can be used to disambiguate tags when there
    94  	// might be some possibility of confusion with tags in use for
    95  	// other purposes.
    96  	prefixForTags?: #tag
    97  
    98  	// TODO we could encode the invariant below in CUE but that
    99  	// would result in poor error messages. With an error builtin,
   100  	// that could perhaps be improved.
   101  
   102  	// stripPrefix specifies that the pattern prefix should be
   103  	// stripped from the module path before using as a repository
   104  	// path. This only applies when pathEncoding is "path".
   105  	stripPrefix?: bool
   106  }
   107  
   108  // TODO more specific schemas below
   109  #modulePath: string
   110  #tag:        string