Use model/attribute terminology in CUE files
This commit is contained in:
@@ -4,13 +4,13 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
#Struct: {
|
||||
#Model: {
|
||||
// Each field can be
|
||||
[name=_]: {"name": name} & #StructField
|
||||
[name=_]: {"name": name} & #ModelAttribute
|
||||
}
|
||||
|
||||
// logic in struct fields is a bit different
|
||||
#StructField: {
|
||||
#ModelAttribute: {
|
||||
name: #ident
|
||||
_words: strings.Replace(strings.Replace(name, "_", " ", -1), ".", " ", -1)
|
||||
|
||||
@@ -35,10 +35,10 @@ import (
|
||||
primaryKey: bool | *false
|
||||
ignoreCase: bool | *false
|
||||
|
||||
#StructJsonTag
|
||||
#ModelAttributeJsonTag
|
||||
}
|
||||
|
||||
IdField: #StructField & {
|
||||
IdField: #ModelAttribute & {
|
||||
// Expecting ID field to always have name ID
|
||||
name: "id"
|
||||
expIdent: "ID"
|
||||
@@ -49,7 +49,7 @@ IdField: #StructField & {
|
||||
goType: "uint64"
|
||||
}
|
||||
|
||||
HandleField: #StructField & {
|
||||
HandleField: #ModelAttribute & {
|
||||
// Expecting ID field to always have name handle
|
||||
name: "handle"
|
||||
unique: true
|
||||
@@ -58,17 +58,17 @@ HandleField: #StructField & {
|
||||
goType: "string"
|
||||
}
|
||||
|
||||
SortableTimestampField: #StructField & {
|
||||
SortableTimestampField: #ModelAttribute & {
|
||||
sortable: true
|
||||
goType: "time.Time"
|
||||
}
|
||||
|
||||
SortableTimestampNilField: #StructField & {
|
||||
SortableTimestampNilField: #ModelAttribute & {
|
||||
sortable: true
|
||||
goType: "*time.Time"
|
||||
}
|
||||
|
||||
#StructJsonTag: {
|
||||
#ModelAttributeJsonTag: {
|
||||
name: string
|
||||
|
||||
_specs: {field: string | *name, omitEmpty: bool | *false, "string": bool | *false}
|
||||
@@ -18,11 +18,11 @@ import (
|
||||
// Fully qualified resource name
|
||||
fqrn: string | *(platform + "::" + component + ":" + handle)
|
||||
|
||||
struct: #Struct
|
||||
model: #Model
|
||||
filter: {
|
||||
"expIdent": #expIdent | *"\(expIdent)Filter"
|
||||
|
||||
struct: #Struct
|
||||
model: #Model
|
||||
|
||||
// generate filtering by-nil-state for the specified fields
|
||||
"byNilState": [...string]
|
||||
@@ -86,7 +86,7 @@ import (
|
||||
|
||||
api?: {
|
||||
lookups: [...{
|
||||
_expFields: [ for f in fields {strings.ToTitle(struct[f].expIdent)}]
|
||||
_expFields: [ for f in fields {strings.ToTitle(model[f].expIdent)}]
|
||||
|
||||
"expIdent": "Lookup\(store.expIdent)By" + strings.Join(_expFields, "")
|
||||
description: string | *""
|
||||
|
||||
@@ -20,7 +20,7 @@ _StoreResource: {
|
||||
goSetType: "\(typePkg).\(res.expIdent)Set"
|
||||
goFilterType: "\(typePkg).\(res.filter.expIdent)"
|
||||
|
||||
struct: [ for f in res.struct if f.store {
|
||||
struct: [ for f in res.model if f.store {
|
||||
"ident": f.ident
|
||||
"expIdent": f.expIdent
|
||||
"storeIdent": f.storeIdent
|
||||
@@ -32,17 +32,17 @@ _StoreResource: {
|
||||
|
||||
filter: {
|
||||
// query fields as defined in struct
|
||||
"query": [ for name in res.filter.query {res.struct[name]}],
|
||||
"query": [ for name in res.filter.query {res.model[name]}],
|
||||
|
||||
// filter by nil state as defined in filter
|
||||
"byNilState": [ for name in res.filter.byNilState {res.filter.struct[name]}]
|
||||
"byNilState": [ for name in res.filter.byNilState {res.filter.model[name]}]
|
||||
|
||||
// filter by false as defined in filter
|
||||
"byFalseState": [ for name in res.filter.byFalseState {res.filter.struct[name]}]
|
||||
"byFalseState": [ for name in res.filter.byFalseState {res.filter.model[name]}]
|
||||
|
||||
// filter by value as defined in filter
|
||||
// @todo this should be pulled from the struct
|
||||
"byValue": [ for name in res.filter.byValue {res.filter.struct[name]}]
|
||||
"byValue": [ for name in res.filter.byValue {res.filter.model[name]}]
|
||||
"byLabel": res.features.labels
|
||||
"byFlag": res.features.flags
|
||||
}
|
||||
@@ -67,7 +67,7 @@ _StoreResource: {
|
||||
}
|
||||
|
||||
deleteByPK: {
|
||||
primaryKeys: [ for f in res.struct if f.primaryKey {f} ]
|
||||
primaryKeys: [ for f in res.model if f.primaryKey {f} ]
|
||||
_pkExpNames: strings.Join([ for f in primaryKeys { f.expIdent } ], "")
|
||||
"expFnIdent": "Delete\(res.store.expIdent)By\(_pkExpNames)"
|
||||
}
|
||||
@@ -85,7 +85,7 @@ _StoreResource: {
|
||||
// Copy all relevant fields from the struct
|
||||
"args": [
|
||||
for name in l.fields {
|
||||
let f = res.struct[name]
|
||||
let f = res.model[name]
|
||||
|
||||
"ident": f.ident
|
||||
"storeIdent": f.storeIdent
|
||||
@@ -126,7 +126,7 @@ _StoreResource: {
|
||||
"fnIdent": "sortable\(expIdent)Fields"
|
||||
|
||||
fields: {
|
||||
for f in res.struct if f.sortable || f.unique || f.primaryKey {
|
||||
for f in res.model if f.sortable || f.unique || f.primaryKey {
|
||||
{
|
||||
"\(strings.ToLower(f.name))": f.name
|
||||
"\(strings.ToLower(f.ident))": f.name
|
||||
@@ -140,8 +140,8 @@ _StoreResource: {
|
||||
|
||||
"fnIdent": "collect\(expIdent)CursorValues"
|
||||
|
||||
fields: [ for f in res.struct if f.sortable || f.unique || f.primaryKey {f} ]
|
||||
primaryKeys: [ for f in res.struct if f.primaryKey {f} ]
|
||||
fields: [ for f in res.model if f.sortable || f.unique || f.primaryKey {f} ]
|
||||
primaryKeys: [ for f in res.model if f.primaryKey {f} ]
|
||||
}
|
||||
|
||||
checkConstraints: {
|
||||
@@ -152,9 +152,9 @@ _StoreResource: {
|
||||
checks: [
|
||||
for lookup in res.store.api.lookups if lookup.constraintCheck {
|
||||
lookupFnIdent: lookup.expIdent
|
||||
fields: [ for name in lookup.fields {res.struct[name]}]
|
||||
fields: [ for name in lookup.fields {res.model[name]}]
|
||||
nullConstraint: [
|
||||
for f in res.struct if list.Contains(lookup.nullConstraint, f.name) {
|
||||
for f in res.model if list.Contains(lookup.nullConstraint, f.name) {
|
||||
"expIdent": f.expIdent
|
||||
},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user