nodejs

package
v3.0.0-...-a5432f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2025 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Pulling out some of the repeated strings tokens into constants would harm readability, so we just ignore the goconst linter's warning.

Pulling out some of the repeated strings tokens into constants would harm readability, so we just ignore the goconst linter's warning.

When GeneratePackage generates TypeScript files, there is a need to track internally which definitions are emitted into these files to re-export them efficiently. This file defines helper structs for this information. The tracking is approximate.

Index

Constants

View Source
const (
	// The minimum version of @codeinfra/codeinfra compatible with the generated SDK.
	MinimumValidSDKVersion   string = "^3.142.0"
	MinimumTypescriptVersion string = "^4.3.5"
	MinimumNodeTypesVersion  string = "^14"
)
View Source
const CodeinfraToken = "codeinfra"

Variables

View Source
var Importer schema.Language = importer(0)

Importer implements schema.Language for NodeJS.

Functions

func GeneratePackage

func GeneratePackage(tool string, pkg *schema.Package,
	extraFiles map[string][]byte, localDependencies map[string]string, localSDK bool,
) (map[string][]byte, error)

func GenerateProgram

func GenerateProgram(program *pcl.Program) (map[string][]byte, hcl.Diagnostics, error)

func GenerateProject

func GenerateProject(
	directory string, project workspace.Project,
	program *pcl.Program, localDependencies map[string]string,
	forceTsc bool,
) error

func LanguageResources

func LanguageResources(pkg *schema.Package) (map[string]LanguageResource, error)

LanguageResources returns a map of resources that can be used by downstream codegen. The map key is the resource schema token.

Types

type DocLanguageHelper

type DocLanguageHelper struct{}

DocLanguageHelper is the NodeJS-specific implementation of the DocLanguageHelper.

func (DocLanguageHelper) GetDocLinkForCodeinfraType

func (d DocLanguageHelper) GetDocLinkForCodeinfraType(pkg *schema.Package, typeName string) string

GetDocLinkForCodeinfraType returns the NodeJS API doc link for a Codeinfra type.

func (DocLanguageHelper) GetDocLinkForFunctionInputOrOutputType

func (d DocLanguageHelper) GetDocLinkForFunctionInputOrOutputType(pkg *schema.Package, modName, typeName string, input bool) string

GetDocLinkForFunctionInputOrOutputType returns the doc link for an input or output type of a Function.

func (DocLanguageHelper) GetDocLinkForResourceInputOrOutputType

func (d DocLanguageHelper) GetDocLinkForResourceInputOrOutputType(pkg *schema.Package, modName, typeName string, input bool) string

GetDocLinkForResourceInputOrOutputType returns the doc link for an input or output type of a Resource.

func (DocLanguageHelper) GetDocLinkForResourceType

func (d DocLanguageHelper) GetDocLinkForResourceType(pkg *schema.Package, modName, typeName string) string

GetDocLinkForResourceType returns the NodeJS API doc for a type belonging to a resource provider.

func (DocLanguageHelper) GetEnumName

func (d DocLanguageHelper) GetEnumName(e *schema.Enum, typeName string) (string, error)

GetEnumName returns the enum name specific to NodeJS.

func (DocLanguageHelper) GetFunctionName

func (d DocLanguageHelper) GetFunctionName(modName string, f *schema.Function) string

func (DocLanguageHelper) GetLanguageTypeString

func (d DocLanguageHelper) GetLanguageTypeString(pkg *schema.Package, moduleName string, t schema.Type, input bool) string

GetLanguageTypeString returns the language-specific type given a Codeinfra schema type.

func (DocLanguageHelper) GetMethodName

func (d DocLanguageHelper) GetMethodName(m *schema.Method) string

func (DocLanguageHelper) GetMethodResultName

func (d DocLanguageHelper) GetMethodResultName(pkg *schema.Package, modName string, r *schema.Resource,
	m *schema.Method,
) string
func (d DocLanguageHelper) GetModuleDocLink(pkg *schema.Package, modName string) (string, string)

GetModuleDocLink returns the display name and the link for a module.

func (DocLanguageHelper) GetPropertyName

func (d DocLanguageHelper) GetPropertyName(p *schema.Property) (string, error)

GetPropertyName returns the property name specific to NodeJS.

func (DocLanguageHelper) GetResourceFunctionResultName

func (d DocLanguageHelper) GetResourceFunctionResultName(modName string, f *schema.Function) string

GetResourceFunctionResultName returns the name of the result type when a function is used to lookup an existing resource.

type LanguageProperty

type LanguageProperty struct {
	ConstValue string // If set, the constant value of the property (e.g., "flowcontrol.apiserver.k8s.io/v1alpha1")
	Name       string // The name of the property (e.g., "FlowSchemaSpec")
	Package    string // The package path containing the property definition (e.g., "outputs.flowcontrol.v1alpha1")
}

LanguageProperty holds information about a resource property to be used by downstream codegen.

type LanguageResource

type LanguageResource struct {
	*schema.Resource

	Name       string             // The resource name (e.g., "FlowSchema")
	Package    string             // The name of the package containing the resource definition (e.g., "flowcontrol.v1alpha1")
	Properties []LanguageProperty // Properties of the resource
}

LanguageResource holds information about a resource to be used by downstream codegen.

type NodeObjectInfo

type NodeObjectInfo struct {
	// List of properties that are required on the input side of a type.
	RequiredInputs []string `json:"requiredInputs"`
	// List of properties that are required on the output side of a type.
	RequiredOutputs []string `json:"requiredOutputs"`
}

NodeObjectInfo contains NodeJS-specific information for an object.

type NodePackageInfo

type NodePackageInfo struct {
	// Custom name for the NPM package.
	PackageName string `json:"packageName,omitempty"`
	// Description for the NPM package.
	PackageDescription string `json:"packageDescription,omitempty"`
	// Readme contains the text for the package's README.md files.
	Readme string `json:"readme,omitempty"`
	// NPM dependencies to add to package.json.
	Dependencies map[string]string `json:"dependencies,omitempty"`
	// NPM dev-dependencies to add to package.json.
	DevDependencies map[string]string `json:"devDependencies,omitempty"`
	// NPM peer-dependencies to add to package.json.
	PeerDependencies map[string]string `json:"peerDependencies,omitempty"`
	// NPM resolutions to add to package.json
	Resolutions map[string]string `json:"resolutions,omitempty"`
	// A specific version of TypeScript to include in package.json.
	TypeScriptVersion string `json:"typescriptVersion,omitempty"`
	// A map containing overrides for module names to package names.
	ModuleToPackage map[string]string `json:"moduleToPackage,omitempty"`
	// Toggle compatibility mode for a specified target.
	Compatibility string `json:"compatibility,omitempty"`
	// Disable support for unions in output types.
	DisableUnionOutputTypes bool `json:"disableUnionOutputTypes,omitempty"`
	// An indicator for whether the package contains enums.
	ContainsEnums bool `json:"containsEnums,omitempty"`
	// A map allowing you to map the name of a provider to the name of the module encapsulating the provider.
	ProviderNameToModuleName map[string]string `json:"providerNameToModuleName,omitempty"`
	// Additional files to include in TypeScript compilation.
	// These paths are added to the `files` section of the
	// generated `tsconfig.json`. A typical use case for this is
	// compiling hand-authored unit test files that check the
	// generated code.
	ExtraTypeScriptFiles []string `json:"extraTypeScriptFiles,omitempty"`
	// Determines whether to make single-return-value methods return an output object or the single value.
	LiftSingleValueMethodReturns bool `json:"liftSingleValueMethodReturns,omitempty"`

	// Respect the Pkg.Version field in the schema
	RespectSchemaVersion bool `json:"respectSchemaVersion,omitempty"`

	// Experimental flag that permits `import type *` style code
	// to be generated to optimize startup time of programs
	// consuming the provider by minimizing the set of Node
	// modules loaded at startup. Turning this on may currently
	// generate non-compiling code for some providers; but if the
	// code compiles it is safe to use. Also, turning this on
	// requires TypeScript 3.8 or higher to compile the generated
	// code.
	UseTypeOnlyReferences bool `json:"useTypeOnlyReferences,omitempty"`
}

NodePackageInfo contains NodeJS-specific information for a package.

Directories

Path Synopsis
Helper code to assist emitting correctly minimally parenthesized TypeScript type literals.
Helper code to assist emitting correctly minimally parenthesized TypeScript type literals.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL