Kindsys: Replace DefForGen with kindsys.Kind (#62642)

* Kindsys: Replace DeclForGen with kindsys.Kind

DeclForGen was always unnecessary - it just wasn't obvious on initial
implementation, when we were focused on generating unique types for each
core kind. This removes it, considerably simplifying interactions with
kindsys - virtually everything now just relies on kindsys.Kind and its
derived interfaces.

* Removed unused jenny

* Rename params in jennies
This commit is contained in:
sam boyer
2023-01-31 19:40:15 -05:00
committed by GitHub
parent 0f0a53fbbb
commit 30b4205521
25 changed files with 273 additions and 543 deletions
+11 -47
View File
@@ -23,33 +23,30 @@ const rootrel string = "kinds/dashboard"
// TODO standard generated docs
type Kind struct {
kindsys.Core
lin thema.ConvergentLineage[*Dashboard]
jcodec vmux.Codec
valmux vmux.ValueMux[*Dashboard]
def kindsys.Def[kindsys.CoreProperties]
}
// type guard
// type guard - ensure generated Kind type satisfies the kindsys.Core interface
var _ kindsys.Core = &Kind{}
// TODO standard generated docs
func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
def, err := kindsys.LoadCoreKind(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{
def: def,
}
lin, err := def.Some().BindKindLineage(rt, opts...)
def, err := kindsys.LoadCoreKindDef(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{}
k.Core, err = kindsys.BindCore(rt, def, opts...)
if err != nil {
return nil, err
}
// Get the thema.Schema that the meta says is in the current version (which
// codegen ensures is always the latest)
cursch := thema.SchemaP(lin, k.def.Properties.CurrentVersion)
cursch := thema.SchemaP(k.Core.Lineage(), def.Properties.CurrentVersion)
tsch, err := thema.BindType[*Dashboard](cursch, &Dashboard{})
if err != nil {
// Should be unreachable, modulo bugs in the Thema->Go code generator
@@ -62,22 +59,8 @@ func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
return k, nil
}
// TODO standard generated docs
func (k *Kind) Name() string {
return "dashboard"
}
// TODO standard generated docs
func (k *Kind) MachineName() string {
return "dashboard"
}
// TODO standard generated docs
func (k *Kind) Lineage() thema.Lineage {
return k.lin
}
// TODO standard generated docs
// ConvergentLineage returns the same [thema.Lineage] as Lineage, but bound (see [thema.BindType])
// to the the Dashboard type generated from the current schema, v0.0.
func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*Dashboard] {
return k.lin
}
@@ -92,22 +75,3 @@ func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*Dashboard] {
func (k *Kind) JSONValueMux(b []byte) (*Dashboard, thema.TranslationLacunas, error) {
return k.valmux(b)
}
// TODO standard generated docs
func (k *Kind) Maturity() kindsys.Maturity {
return k.def.Properties.Maturity
}
// Def returns the [kindsys.Def] containing both CUE and Go representations of the
// dashboard declaration in .cue files.
func (k *Kind) Def() kindsys.Def[kindsys.CoreProperties] {
return k.def
}
// Props returns a [kindsys.SomeKindProps], with underlying type [kindsys.CoreProperties],
// representing the static properties declared in the dashboard kind.
//
// This method is identical to calling Def().Props. It is provided to satisfy [kindsys.Interface].
func (k *Kind) Props() kindsys.SomeKindProperties {
return k.def.Properties
}
+11 -47
View File
@@ -23,33 +23,30 @@ const rootrel string = "kinds/librarypanel"
// TODO standard generated docs
type Kind struct {
kindsys.Core
lin thema.ConvergentLineage[*LibraryPanel]
jcodec vmux.Codec
valmux vmux.ValueMux[*LibraryPanel]
def kindsys.Def[kindsys.CoreProperties]
}
// type guard
// type guard - ensure generated Kind type satisfies the kindsys.Core interface
var _ kindsys.Core = &Kind{}
// TODO standard generated docs
func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
def, err := kindsys.LoadCoreKind(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{
def: def,
}
lin, err := def.Some().BindKindLineage(rt, opts...)
def, err := kindsys.LoadCoreKindDef(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{}
k.Core, err = kindsys.BindCore(rt, def, opts...)
if err != nil {
return nil, err
}
// Get the thema.Schema that the meta says is in the current version (which
// codegen ensures is always the latest)
cursch := thema.SchemaP(lin, k.def.Properties.CurrentVersion)
cursch := thema.SchemaP(k.Core.Lineage(), def.Properties.CurrentVersion)
tsch, err := thema.BindType[*LibraryPanel](cursch, &LibraryPanel{})
if err != nil {
// Should be unreachable, modulo bugs in the Thema->Go code generator
@@ -62,22 +59,8 @@ func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
return k, nil
}
// TODO standard generated docs
func (k *Kind) Name() string {
return "librarypanel"
}
// TODO standard generated docs
func (k *Kind) MachineName() string {
return "librarypanel"
}
// TODO standard generated docs
func (k *Kind) Lineage() thema.Lineage {
return k.lin
}
// TODO standard generated docs
// ConvergentLineage returns the same [thema.Lineage] as Lineage, but bound (see [thema.BindType])
// to the the LibraryPanel type generated from the current schema, v0.0.
func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*LibraryPanel] {
return k.lin
}
@@ -92,22 +75,3 @@ func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*LibraryPanel] {
func (k *Kind) JSONValueMux(b []byte) (*LibraryPanel, thema.TranslationLacunas, error) {
return k.valmux(b)
}
// TODO standard generated docs
func (k *Kind) Maturity() kindsys.Maturity {
return k.def.Properties.Maturity
}
// Def returns the [kindsys.Def] containing both CUE and Go representations of the
// librarypanel declaration in .cue files.
func (k *Kind) Def() kindsys.Def[kindsys.CoreProperties] {
return k.def
}
// Props returns a [kindsys.SomeKindProps], with underlying type [kindsys.CoreProperties],
// representing the static properties declared in the librarypanel kind.
//
// This method is identical to calling Def().Props. It is provided to satisfy [kindsys.Interface].
func (k *Kind) Props() kindsys.SomeKindProperties {
return k.def.Properties
}
+11 -47
View File
@@ -23,33 +23,30 @@ const rootrel string = "kinds/playlist"
// TODO standard generated docs
type Kind struct {
kindsys.Core
lin thema.ConvergentLineage[*Playlist]
jcodec vmux.Codec
valmux vmux.ValueMux[*Playlist]
def kindsys.Def[kindsys.CoreProperties]
}
// type guard
// type guard - ensure generated Kind type satisfies the kindsys.Core interface
var _ kindsys.Core = &Kind{}
// TODO standard generated docs
func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
def, err := kindsys.LoadCoreKind(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{
def: def,
}
lin, err := def.Some().BindKindLineage(rt, opts...)
def, err := kindsys.LoadCoreKindDef(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{}
k.Core, err = kindsys.BindCore(rt, def, opts...)
if err != nil {
return nil, err
}
// Get the thema.Schema that the meta says is in the current version (which
// codegen ensures is always the latest)
cursch := thema.SchemaP(lin, k.def.Properties.CurrentVersion)
cursch := thema.SchemaP(k.Core.Lineage(), def.Properties.CurrentVersion)
tsch, err := thema.BindType[*Playlist](cursch, &Playlist{})
if err != nil {
// Should be unreachable, modulo bugs in the Thema->Go code generator
@@ -62,22 +59,8 @@ func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
return k, nil
}
// TODO standard generated docs
func (k *Kind) Name() string {
return "playlist"
}
// TODO standard generated docs
func (k *Kind) MachineName() string {
return "playlist"
}
// TODO standard generated docs
func (k *Kind) Lineage() thema.Lineage {
return k.lin
}
// TODO standard generated docs
// ConvergentLineage returns the same [thema.Lineage] as Lineage, but bound (see [thema.BindType])
// to the the Playlist type generated from the current schema, v0.0.
func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*Playlist] {
return k.lin
}
@@ -92,22 +75,3 @@ func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*Playlist] {
func (k *Kind) JSONValueMux(b []byte) (*Playlist, thema.TranslationLacunas, error) {
return k.valmux(b)
}
// TODO standard generated docs
func (k *Kind) Maturity() kindsys.Maturity {
return k.def.Properties.Maturity
}
// Def returns the [kindsys.Def] containing both CUE and Go representations of the
// playlist declaration in .cue files.
func (k *Kind) Def() kindsys.Def[kindsys.CoreProperties] {
return k.def
}
// Props returns a [kindsys.SomeKindProps], with underlying type [kindsys.CoreProperties],
// representing the static properties declared in the playlist kind.
//
// This method is identical to calling Def().Props. It is provided to satisfy [kindsys.Interface].
func (k *Kind) Props() kindsys.SomeKindProperties {
return k.def.Properties
}
+11 -47
View File
@@ -23,33 +23,30 @@ const rootrel string = "kinds/preferences"
// TODO standard generated docs
type Kind struct {
kindsys.Core
lin thema.ConvergentLineage[*Preferences]
jcodec vmux.Codec
valmux vmux.ValueMux[*Preferences]
def kindsys.Def[kindsys.CoreProperties]
}
// type guard
// type guard - ensure generated Kind type satisfies the kindsys.Core interface
var _ kindsys.Core = &Kind{}
// TODO standard generated docs
func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
def, err := kindsys.LoadCoreKind(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{
def: def,
}
lin, err := def.Some().BindKindLineage(rt, opts...)
def, err := kindsys.LoadCoreKindDef(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{}
k.Core, err = kindsys.BindCore(rt, def, opts...)
if err != nil {
return nil, err
}
// Get the thema.Schema that the meta says is in the current version (which
// codegen ensures is always the latest)
cursch := thema.SchemaP(lin, k.def.Properties.CurrentVersion)
cursch := thema.SchemaP(k.Core.Lineage(), def.Properties.CurrentVersion)
tsch, err := thema.BindType[*Preferences](cursch, &Preferences{})
if err != nil {
// Should be unreachable, modulo bugs in the Thema->Go code generator
@@ -62,22 +59,8 @@ func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
return k, nil
}
// TODO standard generated docs
func (k *Kind) Name() string {
return "preferences"
}
// TODO standard generated docs
func (k *Kind) MachineName() string {
return "preferences"
}
// TODO standard generated docs
func (k *Kind) Lineage() thema.Lineage {
return k.lin
}
// TODO standard generated docs
// ConvergentLineage returns the same [thema.Lineage] as Lineage, but bound (see [thema.BindType])
// to the the Preferences type generated from the current schema, v0.0.
func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*Preferences] {
return k.lin
}
@@ -92,22 +75,3 @@ func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*Preferences] {
func (k *Kind) JSONValueMux(b []byte) (*Preferences, thema.TranslationLacunas, error) {
return k.valmux(b)
}
// TODO standard generated docs
func (k *Kind) Maturity() kindsys.Maturity {
return k.def.Properties.Maturity
}
// Def returns the [kindsys.Def] containing both CUE and Go representations of the
// preferences declaration in .cue files.
func (k *Kind) Def() kindsys.Def[kindsys.CoreProperties] {
return k.def
}
// Props returns a [kindsys.SomeKindProps], with underlying type [kindsys.CoreProperties],
// representing the static properties declared in the preferences kind.
//
// This method is identical to calling Def().Props. It is provided to satisfy [kindsys.Interface].
func (k *Kind) Props() kindsys.SomeKindProperties {
return k.def.Properties
}
@@ -23,33 +23,30 @@ const rootrel string = "kinds/publicdashboard"
// TODO standard generated docs
type Kind struct {
kindsys.Core
lin thema.ConvergentLineage[*PublicDashboard]
jcodec vmux.Codec
valmux vmux.ValueMux[*PublicDashboard]
def kindsys.Def[kindsys.CoreProperties]
}
// type guard
// type guard - ensure generated Kind type satisfies the kindsys.Core interface
var _ kindsys.Core = &Kind{}
// TODO standard generated docs
func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
def, err := kindsys.LoadCoreKind(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{
def: def,
}
lin, err := def.Some().BindKindLineage(rt, opts...)
def, err := kindsys.LoadCoreKindDef(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{}
k.Core, err = kindsys.BindCore(rt, def, opts...)
if err != nil {
return nil, err
}
// Get the thema.Schema that the meta says is in the current version (which
// codegen ensures is always the latest)
cursch := thema.SchemaP(lin, k.def.Properties.CurrentVersion)
cursch := thema.SchemaP(k.Core.Lineage(), def.Properties.CurrentVersion)
tsch, err := thema.BindType[*PublicDashboard](cursch, &PublicDashboard{})
if err != nil {
// Should be unreachable, modulo bugs in the Thema->Go code generator
@@ -62,22 +59,8 @@ func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
return k, nil
}
// TODO standard generated docs
func (k *Kind) Name() string {
return "publicdashboard"
}
// TODO standard generated docs
func (k *Kind) MachineName() string {
return "publicdashboard"
}
// TODO standard generated docs
func (k *Kind) Lineage() thema.Lineage {
return k.lin
}
// TODO standard generated docs
// ConvergentLineage returns the same [thema.Lineage] as Lineage, but bound (see [thema.BindType])
// to the the PublicDashboard type generated from the current schema, v0.0.
func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*PublicDashboard] {
return k.lin
}
@@ -92,22 +75,3 @@ func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*PublicDashboard] {
func (k *Kind) JSONValueMux(b []byte) (*PublicDashboard, thema.TranslationLacunas, error) {
return k.valmux(b)
}
// TODO standard generated docs
func (k *Kind) Maturity() kindsys.Maturity {
return k.def.Properties.Maturity
}
// Def returns the [kindsys.Def] containing both CUE and Go representations of the
// publicdashboard declaration in .cue files.
func (k *Kind) Def() kindsys.Def[kindsys.CoreProperties] {
return k.def
}
// Props returns a [kindsys.SomeKindProps], with underlying type [kindsys.CoreProperties],
// representing the static properties declared in the publicdashboard kind.
//
// This method is identical to calling Def().Props. It is provided to satisfy [kindsys.Interface].
func (k *Kind) Props() kindsys.SomeKindProperties {
return k.def.Properties
}
@@ -23,33 +23,30 @@ const rootrel string = "kinds/serviceaccount"
// TODO standard generated docs
type Kind struct {
kindsys.Core
lin thema.ConvergentLineage[*ServiceAccount]
jcodec vmux.Codec
valmux vmux.ValueMux[*ServiceAccount]
def kindsys.Def[kindsys.CoreProperties]
}
// type guard
// type guard - ensure generated Kind type satisfies the kindsys.Core interface
var _ kindsys.Core = &Kind{}
// TODO standard generated docs
func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
def, err := kindsys.LoadCoreKind(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{
def: def,
}
lin, err := def.Some().BindKindLineage(rt, opts...)
def, err := kindsys.LoadCoreKindDef(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{}
k.Core, err = kindsys.BindCore(rt, def, opts...)
if err != nil {
return nil, err
}
// Get the thema.Schema that the meta says is in the current version (which
// codegen ensures is always the latest)
cursch := thema.SchemaP(lin, k.def.Properties.CurrentVersion)
cursch := thema.SchemaP(k.Core.Lineage(), def.Properties.CurrentVersion)
tsch, err := thema.BindType[*ServiceAccount](cursch, &ServiceAccount{})
if err != nil {
// Should be unreachable, modulo bugs in the Thema->Go code generator
@@ -62,22 +59,8 @@ func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
return k, nil
}
// TODO standard generated docs
func (k *Kind) Name() string {
return "serviceaccount"
}
// TODO standard generated docs
func (k *Kind) MachineName() string {
return "serviceaccount"
}
// TODO standard generated docs
func (k *Kind) Lineage() thema.Lineage {
return k.lin
}
// TODO standard generated docs
// ConvergentLineage returns the same [thema.Lineage] as Lineage, but bound (see [thema.BindType])
// to the the ServiceAccount type generated from the current schema, v0.0.
func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*ServiceAccount] {
return k.lin
}
@@ -92,22 +75,3 @@ func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*ServiceAccount] {
func (k *Kind) JSONValueMux(b []byte) (*ServiceAccount, thema.TranslationLacunas, error) {
return k.valmux(b)
}
// TODO standard generated docs
func (k *Kind) Maturity() kindsys.Maturity {
return k.def.Properties.Maturity
}
// Def returns the [kindsys.Def] containing both CUE and Go representations of the
// serviceaccount declaration in .cue files.
func (k *Kind) Def() kindsys.Def[kindsys.CoreProperties] {
return k.def
}
// Props returns a [kindsys.SomeKindProps], with underlying type [kindsys.CoreProperties],
// representing the static properties declared in the serviceaccount kind.
//
// This method is identical to calling Def().Props. It is provided to satisfy [kindsys.Interface].
func (k *Kind) Props() kindsys.SomeKindProperties {
return k.def.Properties
}
+11 -47
View File
@@ -23,33 +23,30 @@ const rootrel string = "kinds/team"
// TODO standard generated docs
type Kind struct {
kindsys.Core
lin thema.ConvergentLineage[*Team]
jcodec vmux.Codec
valmux vmux.ValueMux[*Team]
def kindsys.Def[kindsys.CoreProperties]
}
// type guard
// type guard - ensure generated Kind type satisfies the kindsys.Core interface
var _ kindsys.Core = &Kind{}
// TODO standard generated docs
func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
def, err := kindsys.LoadCoreKind(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{
def: def,
}
lin, err := def.Some().BindKindLineage(rt, opts...)
def, err := kindsys.LoadCoreKindDef(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
k := &Kind{}
k.Core, err = kindsys.BindCore(rt, def, opts...)
if err != nil {
return nil, err
}
// Get the thema.Schema that the meta says is in the current version (which
// codegen ensures is always the latest)
cursch := thema.SchemaP(lin, k.def.Properties.CurrentVersion)
cursch := thema.SchemaP(k.Core.Lineage(), def.Properties.CurrentVersion)
tsch, err := thema.BindType[*Team](cursch, &Team{})
if err != nil {
// Should be unreachable, modulo bugs in the Thema->Go code generator
@@ -62,22 +59,8 @@ func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
return k, nil
}
// TODO standard generated docs
func (k *Kind) Name() string {
return "team"
}
// TODO standard generated docs
func (k *Kind) MachineName() string {
return "team"
}
// TODO standard generated docs
func (k *Kind) Lineage() thema.Lineage {
return k.lin
}
// TODO standard generated docs
// ConvergentLineage returns the same [thema.Lineage] as Lineage, but bound (see [thema.BindType])
// to the the Team type generated from the current schema, v0.0.
func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*Team] {
return k.lin
}
@@ -92,22 +75,3 @@ func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*Team] {
func (k *Kind) JSONValueMux(b []byte) (*Team, thema.TranslationLacunas, error) {
return k.valmux(b)
}
// TODO standard generated docs
func (k *Kind) Maturity() kindsys.Maturity {
return k.def.Properties.Maturity
}
// Def returns the [kindsys.Def] containing both CUE and Go representations of the
// team declaration in .cue files.
func (k *Kind) Def() kindsys.Def[kindsys.CoreProperties] {
return k.def
}
// Props returns a [kindsys.SomeKindProps], with underlying type [kindsys.CoreProperties],
// representing the static properties declared in the team kind.
//
// This method is identical to calling Def().Props. It is provided to satisfy [kindsys.Interface].
func (k *Kind) Props() kindsys.SomeKindProperties {
return k.def.Properties
}