generation

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

package generation provides the ability to generate resource, handler, and typescript permissions and metadata code from a resource file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v0.0.10

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, resourcePackageDir, migrationSourceURL string, generatorOptions ...ClientOption) (*Client, error)

func (*Client) Close added in v0.0.10

func (c *Client) Close()

func (*Client) RunGeneration added in v0.0.10

func (c *Client) RunGeneration() error

type ClientOption added in v0.0.10

type ClientOption func(*Client) error

func CaserInitialismOverrides added in v0.0.10

func CaserInitialismOverrides(overrides map[string]bool) ClientOption

func GenerateHandlers added in v0.0.10

func GenerateHandlers(targetDir string, overrides map[string][]HandlerType) ClientOption

func GenerateRoutes added in v0.0.13

func GenerateRoutes(targetDir, targetPackage, routePrefix string) ClientOption

func GenerateTypescriptMetadata added in v0.0.10

func GenerateTypescriptMetadata(rc *resource.Collection, targetDir string) ClientOption

func GenerateTypescriptPermission added in v0.0.10

func GenerateTypescriptPermission(rc *resource.Collection, targetDir string) ClientOption

func WithConsolidatedHandlers added in v0.0.13

func WithConsolidatedHandlers(route string, resources ...string) ClientOption

func WithPluralOverrides added in v0.0.10

func WithPluralOverrides(overrides map[string]string) ClientOption

func WithTypescriptOverrides added in v0.0.13

func WithTypescriptOverrides(overrides map[string]string) ClientOption

func WithoutConsolidatedHandlers added in v0.0.13

func WithoutConsolidatedHandlers(route string, resources ...string) ClientOption

type ColumnMeta added in v0.0.13

type ColumnMeta struct {
	ColumnName         string
	ConstraintTypes    []ConstraintType
	IsPrimaryKey       bool
	IsForeignKey       bool
	SpannerType        string
	IsNullable         bool
	IsIndex            bool
	IsUniqueIndex      bool
	OrdinalPosition    int64
	KeyOrdinalPosition int64
	ReferencedTable    string
	ReferencedColumn   string
}

type ConstraintType

type ConstraintType string
const (
	PrimaryKey ConstraintType = "PRIMARY KEY"
	ForeignKey ConstraintType = "FOREIGN KEY"
)

type FieldInfo added in v0.0.13

type FieldInfo struct {
	Parent      *ResourceInfo
	Name        string
	SpannerName string
	GoType      string

	Conditions []string // Contains auxiliary tags like `immutable`. Determines JSON tag in handler generation.

	Required           bool
	IsPrimaryKey       bool
	IsForeignKey       bool
	IsIndex            bool
	IsUniqueIndex      bool
	OrdinalPosition    int64 // Position of column in the table definition
	KeyOrdinalPosition int64 // Position of primary or foreign key in a compound key definition
	IsEnumerated       bool
	ReferencedResource string
	ReferencedField    string
	// contains filtered or unexported fields
}

func (*FieldInfo) IndexTag added in v0.0.13

func (f *FieldInfo) IndexTag() string

func (*FieldInfo) IsImmutable added in v0.0.13

func (f *FieldInfo) IsImmutable() bool

func (*FieldInfo) IsView added in v0.0.13

func (f *FieldInfo) IsView() bool

func (*FieldInfo) JSONTag added in v0.0.13

func (f *FieldInfo) JSONTag() string

func (*FieldInfo) JSONTagForPatch added in v0.0.13

func (f *FieldInfo) JSONTagForPatch() string

func (*FieldInfo) ListPermTag added in v0.0.13

func (f *FieldInfo) ListPermTag() string

func (*FieldInfo) PatchPermTag added in v0.0.13

func (f *FieldInfo) PatchPermTag() string

func (*FieldInfo) QueryTag added in v0.0.13

func (f *FieldInfo) QueryTag() string

func (*FieldInfo) ReadPermTag added in v0.0.13

func (f *FieldInfo) ReadPermTag() string

func (*FieldInfo) TypescriptDataType added in v0.0.13

func (f *FieldInfo) TypescriptDataType() string

func (*FieldInfo) TypescriptDisplayType added in v0.0.13

func (f *FieldInfo) TypescriptDisplayType() string

func (*FieldInfo) UniqueIndexTag added in v0.0.13

func (f *FieldInfo) UniqueIndexTag() string

type GeneratedFileDeleteMethod added in v0.0.9

type GeneratedFileDeleteMethod int
const (
	// Used to remove files with the genPrefix value instead of reading the contents of the file.
	Prefix GeneratedFileDeleteMethod = iota
	// Used to remove files that contain the header comment "// Code generated by resourcegeneration. DO NOT EDIT."
	HeaderComment
)

type HandlerType

type HandlerType string
const (
	List  HandlerType = "list"
	Read  HandlerType = "read"
	Patch HandlerType = "patch"
)

func (HandlerType) Method added in v0.0.13

func (h HandlerType) Method() string

type InformationSchemaResult

type InformationSchemaResult struct {
	TableName            string  `spanner:"TABLE_NAME"`
	ColumnName           string  `spanner:"COLUMN_NAME"`
	ConstraintName       *string `spanner:"CONSTRAINT_NAME"`
	IsPrimaryKey         bool    `spanner:"IS_PRIMARY_KEY"`
	IsForeignKey         bool    `spanner:"IS_FOREIGN_KEY"`
	ReferencedTable      *string `spanner:"REFERENCED_TABLE"`
	ReferencedColumn     *string `spanner:"REFERENCED_COLUMN"`
	SpannerType          string  `spanner:"SPANNER_TYPE"`
	IsNullable           bool    `spanner:"IS_NULLABLE"`
	IsView               bool    `spanner:"IS_VIEW"`
	IsIndex              bool    `spanner:"IS_INDEX"`
	IsUniqueIndex        bool    `spanner:"IS_UNIQUE_INDEX"`
	GenerationExpression *string `spanner:"GENERATION_EXPRESSION"`
	OrdinalPosition      int64   `spanner:"ORDINAL_POSITION"`
	KeyOrdinalPosition   int64   `spanner:"KEY_ORDINAL_POSITION"`
}

type OptionType

type OptionType string
const (
	Regenerate OptionType = "regenerate"
	NoGenerate OptionType = "nogenerate"
)

type PatchType

type PatchType string
const (
	CreatePatch PatchType = "Create"
	UpdatePatch PatchType = "Update"
)

type ResourceInfo added in v0.0.13

type ResourceInfo struct {
	Name   string
	Fields []*FieldInfo

	IsView                bool // Determines how CreatePatch is rendered in resource generation.
	HasCompoundPrimaryKey bool // Determines how CreatePatchSet is rendered in resource generation.
	IsConsolidated        bool
	// contains filtered or unexported fields
}

func (*ResourceInfo) SearchIndexes added in v0.0.13

func (r *ResourceInfo) SearchIndexes() []*searchIndex

type TableMetadata

type TableMetadata struct {
	Columns       map[string]ColumnMeta
	SearchIndexes map[string][]*expressionField
	IsView        bool
	PkCount       int
}

Jump to

Keyboard shortcuts

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