Skip to content

Instantly share code, notes, and snippets.

@dixler
Created May 15, 2022 09:53
Show Gist options
  • Save dixler/abe0499bef445ce83d1fe733ac10582a to your computer and use it in GitHub Desktop.
Save dixler/abe0499bef445ce83d1fe733ac10582a to your computer and use it in GitHub Desktop.
putting together a typescript type to represent pulumi package schemas. stashing it for now.
export type Package = {
name:string // Name is the unqualified name of the package (e.g. “aws”, “azure”, “gcp”, “kubernetes”, “random”)
displayName?:string // The human-friendly name of the package.
// TODO: is version not required [https://github.com/pulumi/pulumi-hugo/issues/1508]
version?:string // Version is the version of the package. The version must be valid semver.
description?:string // Description is the description of the package.
keywords?:string[] // Keywords is the list of keywords that are associated with the package, if any. Reserved keywords can be specified that help with categorizing the package in the Pulumi registry. category/<name> and kind/<type> are the only reserved keywords at this time, where <name> can be one of: cloud, database, infrastructure, network, utility, vcs and <type> is either native or component. If the package is a bridged Terraform provider, then don’t include a kind/ label.
homepage?: string // Homepage is the package’s homepage.
license?:string // License indicates which license is used for the package’s contents.
attribution?:string // Attribution allows freeform text attribution of derived work, if needed.
repository?:string // Repository is the URL at which the source for the package can be found.
logoUrl?:string // LogoURL is the URL for the package’s logo, if any.
pluginDownloadURL?:string // PluginDownloadURL is the URL to use to acquire the provider plugin binary, if any. See Authoring & Publishing for more details.
publisher?:string // The name of the person or organization that authored and published the package.
meta?:Metadata // Meta contains information for the importer about this package.
config?:Config // Config describes the set of configuration variables defined by this package.
types?:TypeMap<ComplexType> // Types is a map from type token to ComplexType that describes the set of complex types (ie. object, enum) defined by this package.
provider?:Resource // Provider describes the provider type for this package.
resources?:TypeMap<Resource> // Resources is a map from type token to Resourc that describes the set of resources defined by this package.
functions?:TypeMap<Fn> // Functions is a map from token to Function that describes the set of functions defined by this package.
language?:PackageLanguageMap // Language specifies additional language-specific data about the package.
}
type TypeToken = string
type Language = string
type TypeMap<T> = {[key: TypeToken]: T}
type Metadata = {
moduleFormat?:string // ModuleFormat is a regex that is used by the importer to extract a module name from the module portion of a type token. Packages that use the module format “namespace1/namespace2/…/namespaceN” do not need to specify a format. The regex must define one capturing group that contains the module name, which must be formatted as “namespace1/namespace2/…namespaceN”.
}
interface ComplexType extends ObjectType {
enum?:EnumValue[] // Enum, if present, is the list of possible values for an enum type.
}
type EnumValue = {
name?:string // Name, if present, overrides the name of the enum value that would usually be derived from the value.
description?:string // Description of the enum value.
value?:any // Value is the enum value itself.
deprecationMessage?:string // DeprecationMessage indicates whether or not the value is deprecated.
}
type Config = {
variables?:ConfigPropertyMap // Variables is a map from variable name to Property that describes a package’s configuration variables.
required?:string[] // Required is a list of the names of the package’s required configuration variables.
}
type Alias = {
name?:string // Name is the name portion of the alias, if any.
project?:string // Project is the project portion of the alias, if any.
type?:string // Type is the type portion of the alias, if any.
}
interface Resource extends ObjectType {
inputProperties?:PropertyMap // Description is the description of the property, if any.
requiredInputs?:string[] // RequiredInputs is a list of the names of the resource’s required input properties.
stateInputs?:ObjectType // StateInputs is an optional ObjectType that describes additional inputs that may be necessary to get an existing resource. If this is unset, only an ID is necessary.
aliases?:Alias[] // Aliases is the list of aliases for the resource.
deprecationMessage?:string // DeprecationMessage indicates whether or not the resource is deprecated.
language?:ResourceLanguageMap // Language specifies additional language-specific data about the resource.
isComponent?:boolean // IsComponent indicates whether the resource is a ComponentResource.
// methods map[string]string No Methods maps method names to functions in this schema.
methods?:null // TODO unimplemented
}
type PropertyName = string
type Default = {
environment:string[] // Environment specifies a set of environment variables to probe for a default value.
language?:DefaultLanguageMap // Language specifies additional language-specific data about the default value.
}
type Discriminator = {
propertyName:string // PropertyName is the name of the property in the payload that will hold the discriminator value.
mapping?: DiscriminatorMapping // Mapping is an optional object to hold mappings between payload values and schema names or references.
}
type TypeString = "boolean" | "integer" | "number" | "string" | "array" | "object" | {} & string;
type Type = BaseType | RefType | UnionType
type RefType = {
$ref:PulumiTypeRefs | {} & string // Ref is a reference to a type in this or another document. For example, the built-in Archive, Asset, and Any types are referenced as "pulumi.json#/Archive", "pulumi.json#/Asset", and "pulumi.json#/Any", respectively. A type from this document is referenced as "#/types/pulumi:type:token". A type from another document is referenced as "path#/types/pulumi:type:token", where path is of the form: "/provider/vX.Y.Z/schema.json" or "pulumi.json" or "http[s]://example.com /provider/vX.Y.Z/schema.json". A resource from this document is referenced as “#/resources/pulumi:type:token”. A resource from another document is referenced as "path#/resources/pulumi:type:token", where path is of the form: "/provider/vX.Y.Z/schema.json" or "pulumi.json" or "http[s]://example.com /provider/vX.Y.Z/schema.json".
}
type UnionType = {
oneOf:Type[] // OneOf indicates that values of the type may be one of any of the listed types.
}
type BaseType = {
type:TypeString // Type is the primitive or composite type, if any. May be “boolean”, “integer”, “number”, “string”, “array”, or “object”.
additionalProperties?:Type // AdditionalProperties, if set, describes the element type of an “object” (i.e. a string -> value map).
items?:Type // Items, if set, describes the element type of an array.
oneOf?:Type[] // OneOf indicates that values of the type may be one of any of the listed types.
discriminator?:Discriminator // Discriminator informs the consumer of an alternative schema based on the value associated with it.
plain?:boolean // Plain indicates that when used as an input, this type does not accept eventual values.
}
interface PropertyFields {
description?:string // Description is the description of the property, if any.
const?:any // Const is the constant value for the property, if any. The type of the value must be assignable to the type of the property.
default?:any // Default is the default value for the property, if any. The type of the value must be assignable to the type of the property.
defaultInfo?:Default // DefaultInfo contains additional information about the property’s default value, if any.
deprecationMessage?:string // DeprecationMessage indicates whether or not the property is deprecated.
language?:PropertyLanguageMap // Language specifies additional language-specific data about the property.
secret?:boolean // Secret specifies if the property is secret (default false).
replaceOnChanges?:boolean // ReplaceOnChanges specifies if the associated object should be updated with a replace operation instead of a update operation.
}
interface RefProperty extends RefType, PropertyFields {}
interface BaseProperty extends BaseType, PropertyFields {}
interface UnionProperty extends UnionType, PropertyFields {}
type Property = RefProperty | BaseProperty | UnionProperty
interface BaseProperty extends BaseType {
description?:string // Description is the description of the property, if any.
const?:any // Const is the constant value for the property, if any. The type of the value must be assignable to the type of the property.
default?:any // Default is the default value for the property, if any. The type of the value must be assignable to the type of the property.
defaultInfo?:Default // DefaultInfo contains additional information about the property’s default value, if any.
deprecationMessage?:string // DeprecationMessage indicates whether or not the property is deprecated.
language?:PropertyLanguageMap // Language specifies additional language-specific data about the property.
secret?:boolean // Secret specifies if the property is secret (default false).
replaceOnChanges?:boolean // ReplaceOnChanges specifies if the associated object should be updated with a replace operation instead of a update operation.
}
type PropertyMap = {[key: PropertyName]: Property}
type ConfigPropertyMap = {[key: PropertyName]: Property}
type ObjectType = {
description?:string // Description is the description of the type, if any.
properties?:PropertyMap // Properties, if present, is a map from property name to Property that describes the type’s properties.
type?:string // Type must be “object” if this is an object type, or the underlying type for an enum.
required?:string[] // Required, if present, is a list of the names of an object type’s required properties. These properties must be set for inputs and will always be set for outputs.
language?:ObjectTypeLanguageMap // Language specifies additional language-specific data about the type.
[x: string | number | symbol]: unknown;
}
type Fn = {
description?:string // Description is the description of the function, if any.
inputs?:ObjectType // Inputs is the bag of input values for the function, if any.
outputs?:ObjectType // Outputs is the bag of output values for the function, if any.
deprecationMessage?:string // DeprecationMessage indicates whether or not the function is deprecated.
language?:FunctionLanguageMap // Language specifies additional language-specific data about the function.
[x: string | number | symbol]: unknown;
}
// TODO
type FunctionLanguageMap = any
type ObjectTypeLanguageMap = any
type DefaultLanguageMap = any
type ResourceLanguageMap = any
type PropertyLanguageMap = any
type DiscriminatorMapping = any
type PackageLanguageMap = any
const foo: Fn = {
target: 1
}
/**
* Pulumi.json
*/
type PulumiTypeRefs = "pulumi.json#/Archive" | "pulumi.json#/Asset" | "pulumi.json#/Json" | "pulumi.json#/Any"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment