github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/nodejs/importer.go (about)

     1  // Copyright 2016-2020, Pulumi Corporation.
     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 nodejs
    16  
    17  import (
    18  	"encoding/json"
    19  
    20  	"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
    21  )
    22  
    23  // Compatibility mode for Kubernetes 2.0 SDK
    24  const kubernetes20 = "kubernetes20"
    25  
    26  // Compatibility mode for tfbridge 2.x SDKs
    27  const tfbridge20 = "tfbridge20"
    28  
    29  // NodePackageInfo contains NodeJS-specific information for a package.
    30  type NodePackageInfo struct {
    31  	// Custom name for the NPM package.
    32  	PackageName string `json:"packageName,omitempty"`
    33  	// Description for the NPM package.
    34  	PackageDescription string `json:"packageDescription,omitempty"`
    35  	// Readme contains the text for the package's README.md files.
    36  	Readme string `json:"readme,omitempty"`
    37  	// NPM dependencies to add to package.json.
    38  	Dependencies map[string]string `json:"dependencies,omitempty"`
    39  	// NPM dev-dependencies to add to package.json.
    40  	DevDependencies map[string]string `json:"devDependencies,omitempty"`
    41  	// NPM peer-dependencies to add to package.json.
    42  	PeerDependencies map[string]string `json:"peerDependencies,omitempty"`
    43  	// NPM resolutions to add to package.json
    44  	Resolutions map[string]string `json:"resolutions,omitempty"`
    45  	// A specific version of TypeScript to include in package.json.
    46  	TypeScriptVersion string `json:"typescriptVersion,omitempty"`
    47  	// A map containing overrides for module names to package names.
    48  	ModuleToPackage map[string]string `json:"moduleToPackage,omitempty"`
    49  	// Toggle compatibility mode for a specified target.
    50  	Compatibility string `json:"compatibility,omitempty"`
    51  	// Disable support for unions in output types.
    52  	DisableUnionOutputTypes bool `json:"disableUnionOutputTypes,omitempty"`
    53  	// An indicator for whether the package contains enums.
    54  	ContainsEnums bool `json:"containsEnums,omitempty"`
    55  	// A map allowing you to map the name of a provider to the name of the module encapsulating the provider.
    56  	ProviderNameToModuleName map[string]string `json:"providerNameToModuleName,omitempty"`
    57  	// The name of the plugin, which might be different from the package name.
    58  	PluginName string `json:"pluginName,omitempty"`
    59  	// The version of the plugin, which might be different from the version of the package..
    60  	PluginVersion string `json:"pluginVersion,omitempty"`
    61  	// Additional files to include in TypeScript compilation.
    62  	// These paths are added to the `files` section of the
    63  	// generated `tsconfig.json`. A typical use case for this is
    64  	// compiling hand-authored unit test files that check the
    65  	// generated code.
    66  	ExtraTypeScriptFiles []string `json:"extraTypeScriptFiles,omitempty"`
    67  	// Determines whether to make single-return-value methods return an output object or the single value.
    68  	LiftSingleValueMethodReturns bool `json:"liftSingleValueMethodReturns,omitempty"`
    69  
    70  	// Respect the Pkg.Version field in the schema
    71  	RespectSchemaVersion bool `json:"respectSchemaVersion,omitempty"`
    72  
    73  	// Experimental flag that permits `import type *` style code
    74  	// to be generated to optimize startup time of programs
    75  	// consuming the provider by minimizing the set of Node
    76  	// modules loaded at startup. Turning this on may currently
    77  	// generate non-compiling code for some providers; but if the
    78  	// code compiles it is safe to use. Also, turning this on
    79  	// requires TypeScript 3.8 or higher to compile the generated
    80  	// code.
    81  	UseTypeOnlyReferences bool `json:"useTypeOnlyReferences,omitempty"`
    82  }
    83  
    84  // NodeObjectInfo contains NodeJS-specific information for an object.
    85  type NodeObjectInfo struct {
    86  	// List of properties that are required on the input side of a type.
    87  	RequiredInputs []string `json:"requiredInputs"`
    88  	// List of properties that are required on the output side of a type.
    89  	RequiredOutputs []string `json:"requiredOutputs"`
    90  }
    91  
    92  // Importer implements schema.Language for NodeJS.
    93  var Importer schema.Language = importer(0)
    94  
    95  type importer int
    96  
    97  // ImportDefaultSpec decodes language-specific metadata associated with a DefaultValue.
    98  func (importer) ImportDefaultSpec(def *schema.DefaultValue, raw json.RawMessage) (interface{}, error) {
    99  	return raw, nil
   100  }
   101  
   102  // ImportPropertySpec decodes language-specific metadata associated with a Property.
   103  func (importer) ImportPropertySpec(property *schema.Property, raw json.RawMessage) (interface{}, error) {
   104  	return raw, nil
   105  }
   106  
   107  // ImportObjectTypeSpec decodes language-specific metadata associated with a ObjectType.
   108  func (importer) ImportObjectTypeSpec(object *schema.ObjectType, raw json.RawMessage) (interface{}, error) {
   109  	var info NodeObjectInfo
   110  	if err := json.Unmarshal([]byte(raw), &info); err != nil {
   111  		return nil, err
   112  	}
   113  	return info, nil
   114  }
   115  
   116  // ImportResourceSpec decodes language-specific metadata associated with a Resource.
   117  func (importer) ImportResourceSpec(resource *schema.Resource, raw json.RawMessage) (interface{}, error) {
   118  	return raw, nil
   119  }
   120  
   121  // ImportFunctionSpec decodes language-specific metadata associated with a Function.
   122  func (importer) ImportFunctionSpec(function *schema.Function, raw json.RawMessage) (interface{}, error) {
   123  	return raw, nil
   124  }
   125  
   126  // ImportPackageSpec decodes language-specific metadata associated with a Package.
   127  func (importer) ImportPackageSpec(pkg *schema.Package, raw json.RawMessage) (interface{}, error) {
   128  	var info NodePackageInfo
   129  	if err := json.Unmarshal([]byte(raw), &info); err != nil {
   130  		return nil, err
   131  	}
   132  	return info, nil
   133  }