feat(16.2-01): compile, decode and load plugin field types in cabana
- compileFieldTypes builds a per-boot field type registry (alias, core and cross-plugin collisions, element prefix, assets, option keys) passed down the compile functions; settings and relation forms refuse plugin aliases - fields.yaml accepts a plugin alias with the general keys plus the type's options (typeOptions, element, translatable in the schema); CheckOptions runs at boot; CompileFormWithTypes for plugin tests - save decodes plugin values inside the transaction (FormFieldError is a 422, other errors opaque 500) and answers meta.notices (FieldNotice) only when a type reported something; show and save serve values through Load - GET /field-types lists the types with versioned asset URLs; OpenAPI, schema.d.ts, README and docs/backend/field-types.md updated
This commit is contained in:
@@ -55,8 +55,21 @@ func checkReservedSegments(items []controllerRef) error {
|
||||
}
|
||||
|
||||
func compileRegistry(items []controllerRef) (*Registry, error) {
|
||||
return compileRegistryWithTypes(items, nil)
|
||||
}
|
||||
|
||||
// compileRegistryWithTypes compiles every controller with the plugin field
|
||||
// types built by compileFieldTypes for this boot. types is passed down, never
|
||||
// stored in a package variable, so two activations never share a registry.
|
||||
func compileRegistryWithTypes(items []controllerRef, types *fieldTypeRegistry) (*Registry, error) {
|
||||
byID := make(map[string]*CompiledController, len(items))
|
||||
assets := map[string]*pluginAsset{}
|
||||
// Field type scripts and styles are served by the same asset route.
|
||||
for _, file := range types.assets() {
|
||||
if _, exists := assets[file.key]; !exists {
|
||||
assets[file.key] = file
|
||||
}
|
||||
}
|
||||
for _, item := range items {
|
||||
id := item.ctl.ID()
|
||||
if _, exists := byID[id]; exists {
|
||||
@@ -70,11 +83,11 @@ func compileRegistry(items []controllerRef) (*Registry, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
form, err := compileFormIfPresent(item.plugin.ID(), item.ctl, fsys.AdminFS())
|
||||
form, err := compileFormIfPresent(item.plugin.ID(), item.ctl, fsys.AdminFS(), types)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
relations, err := compileRelations(item.plugin.ID(), item.ctl, fsys.AdminFS(), form)
|
||||
relations, err := compileRelationsWithTypes(item.plugin.ID(), item.ctl, fsys.AdminFS(), form, types)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -117,7 +130,7 @@ func compileRegistry(items []controllerRef) (*Registry, error) {
|
||||
}
|
||||
byID[id] = compiled
|
||||
}
|
||||
return &Registry{byID: byID, assets: assets}, nil
|
||||
return &Registry{byID: byID, assets: assets, fieldTypes: types}, nil
|
||||
}
|
||||
|
||||
// operationDeclared reports whether the controller's compiled list and form
|
||||
@@ -209,7 +222,7 @@ func compileContributions(reg *Registry, plugins []party.Plugin) error {
|
||||
if !hasAssets || assets == nil || assets.AdminFS() == nil {
|
||||
return fmt.Errorf("cabana: plugin %s has settings but no AdminFS", plugin.ID())
|
||||
}
|
||||
compiled, err := compileSetting(plugin.ID(), item, assets.AdminFS())
|
||||
compiled, err := compileSettingWithTypes(plugin.ID(), item, assets.AdminFS(), reg.fieldTypes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user