Skip to content

refactor(client): build every kind's client on one generic MeshObjectClient and hal.Links - #114

Merged
grubmeshi merged 1 commit into
mainfrom
generic-mesh-object-client
Nov 25, 2026
Merged

grubmeshi merged 1 commit into
mainfrom
generic-mesh-object-client

Conversation

@grubmeshi

Copy link
Copy Markdown
Collaborator

What it does

  • Every kind's client is a type alias for one of three generic interfaces. Each interface adds to the one before:
    • MeshObjectReadOnlyClient[M, Filter]: Read, List, ListSeq
    • MeshObjectImmutableClient[M, Filter]: + Create, Delete
    • MeshObjectClient[M, Filter]: + Update
  • The alias uses the level that the API docs offer for the kind:
    • read-only: EventLog, BuildingBlockRun
    • immutable: Tenant, ProjectGroupBinding, ProjectUserBinding, WorkspaceUserBinding
    • full: every other kind, User and WorkspaceUserGroup included
  • One implementation struct serves all three levels. List reads every page. ListSeq reads a page only when the caller asks for an object of it.
  • An action is a method of the object type. The method follows a link of _links through hal.Links, so that the rel, the HTTP method, the payload and the result type are written in one place:
    • MeshBuildingBlockV2.TriggerRun(ctx) (MeshBuildingBlockV2, error), Purge(ctx) error
    • MeshBuildingBlockRun.Abort(ctx) error, Approve(ctx, predecessorRunUuid string) error, Reject(ctx) error, Predecessor(ctx) (MeshBuildingBlockRun, error), Logs(ctx) (MeshBuildingBlockRunLogs, error)
  • Links stays public, and a missing link is hal.ErrNoLink. A link to another origin than the endpoint is refused.
  • client.Raw, client/internal and the per-kind methods such as ReadFunc and GetLogs are gone. Ids are strings. client.Client.HttpClient sends any other request.
  • The user and workspace user group clients from main use the generic client. A workspace user group has the id NewMeshWorkspaceUserGroupId(workspace, name), as a project does.
  • The polymorph package reads and writes a struct by its type property, for the implementation of a definition version. The building block runner types are an enum.

Review carefully

  • client/meshobject.go (the three levels, paging, followLink) and client/types/hal/link.go.
  • The level of each alias against the API docs.
  • client/types/polymorph.

Mechanical

The kind files (alias plus meshObjectId), the command adaptations in cmd/, and the test updates. This removes the temporary glue of http-do-request.

Breaking for the Terraform provider

The Mesh…Client interfaces change shape, and the action methods replace TriggerRun, Delete(…, purge) and GetLogs.

Place in the stack

5 of 6. Base: apidocs-etag. Next: feature/single-go-bin-runner.

🤖 Generated with Claude Code

@meshcloud-gh-actions

meshcloud-gh-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Coverage of the acceptance run against the meshStack backend, on e2b4e86b3273b1cf5a0b2971e5ffbfab7e1235ef.

Scope Coverage
Unit tests 79.4%
Acceptance tests 57.1%
Combined 83.8%
Uncovered functions
client/api_key.go:18: MeshApiKey.meshObjectId 0.0%
client/api_key_permissions.go:20: ApiKeyPermissions.AllCodes 0.0%
client/api_key_permissions.go:33: ApiKeyPermissions.WorkspaceCodes 0.0%
client/api_key_permissions.go:263: AllApiKeyPermissions 0.0%
client/api_key_permissions.go:267: WorkspacePermissionCodes 0.0%
client/binding_status.go:18: *MeshGroupBindingStatus.WaitsForApproval 0.0%
client/binding_status.go:22: *MeshUserBindingStatus.WaitsForApproval 0.0%
client/building_block_definition.go:68: MeshBuildingBlockDefinitionApprovalPolicies.NothingRequiresApproval 0.0%
client/building_block_definition.go:79: DisabledSchedule 0.0%
client/building_block_definition.go:86: MeshBuildingBlockDefinitionSchedule.IsDisabled 0.0%
client/building_block_definition.go:90: MeshBuildingBlockDefinitionSpec.HasNeutralPolicies 0.0%
client/building_block_definition.go:94: MeshBuildingBlockDefinitionSpec.WithNeutralPolicies 0.0%
client/building_block_definition.go:148: MeshBuildingBlockDefinition.meshObjectId 0.0%
client/building_block_definition_version.go:99: MeshBuildingBlockType.TagInputTargets 0.0%
client/building_block_definition_version.go:220: MeshBuildingBlockDefinitionVersion.meshObjectId 0.0%
client/building_block_definition_version.go:223: MeshBuildingBlockDefinitionVersion.meshObjectNoSortQuery 0.0%
client/building_block_run.go:57: MeshBuildingBlockRun.Abort 0.0%
client/building_block_run.go:80: MeshBuildingBlockRun.meshObjectId 0.0%
client/building_block_runner.go:67: MeshBuildingBlockRunner.meshObjectId 0.0%
client/building_block_v2.go:200: MeshBuildingBlockV2.Purge 0.0%
client/building_block_v2.go:246: *MeshBuildingBlockV2.IsWaitingForInput 0.0%
client/building_block_v2.go:265: *MeshBuildingBlockV2.DeletionSuccessful 0.0%
client/building_block_v2.go:286: MeshBuildingBlockV2.meshObjectId 0.0%
client/building_block_v2.go:290: *MeshBuildingBlockV2.uuidOrUnknown 0.0%
client/event_log.go:68: MeshEventLog.meshObjectId 0.0%
... and 62 more

covdata func names a method without its receiver, so an entry can belong to an implementation nothing selects rather than to a function the tests never reached. Open the file and line before reading one as a coverage gap.

@grubmeshi
grubmeshi added this pull request to stack #115 November 25, 2026 10:25
@grubmeshi
grubmeshi force-pushed the generic-mesh-object-client branch from 901026c to 3f976f2 Compare November 25, 2026 11:36
…Client and hal.Links

Every kind's client is a type alias for one of three interfaces, each of which adds to the one
before: MeshObjectReadOnlyClient[M, Filter] with Read, List and ListSeq,
MeshObjectImmutableClient[M, Filter] with Create and Delete, and MeshObjectClient[M, Filter] with
Update. The alias takes what the API docs offer: event logs and building block runs are read-only;
tenants and the project bindings and workspace user bindings are immutable; every other kind,
users and workspace user groups included, has the full client. One implementation serves all
three. List collects every page, and ListSeq reads a page only when the caller asks for an
object of it.

An action of an object is a method of its type that follows a link of its _links through
hal.Links, so that the rel, the method, the payload and the result are stated once:
MeshBuildingBlockV2.TriggerRun and Purge, and MeshBuildingBlockRun.Abort, Approve, Reject,
Predecessor and Logs. A link to another origin than the endpoint is refused. client.Raw and the
per-kind methods such as ReadFunc and GetLogs are gone, and ids are strings.

The polymorph package reads and writes a struct by its type property, as the implementation of a
definition version needs. The building block runner types are an enum.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@grubmeshi
grubmeshi force-pushed the generic-mesh-object-client branch from 3f976f2 to e2b4e86 Compare November 25, 2026 12:22
@sonarqubecloud

Copy link
Copy Markdown

@j0g3sc j0g3sc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, nice assigning these generic clients matching the API conventions by design now. Did not go through all changes in detail but lgtm

Base automatically changed from apidocs-etag to main November 25, 2026 15:20
@grubmeshi
grubmeshi merged commit e2b4e86 into main Nov 25, 2026
15 of 25 checks passed
@grubmeshi
grubmeshi deleted the generic-mesh-object-client branch November 25, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants