Repository navigation
feat(builders): typed factories for 5 discriminated unions (#1386) - #1598
Merged
Merged
Conversation
2 tasks
…oid v5 collision The new factory namespace `previewCreativeResponse` collided with the existing v5 server-helper *function* `previewCreativeResponse` re-exported from `@adcp/sdk` top-level. Adopters who imported `previewCreativeResponse` from the top level and called it as a function would have hit a silent runtime TypeError after this PR. Resolution: - Rename the factory namespace `previewCreativeResponse` → `previewCreative` (no `Response` suffix), matching the existing `urlRender` / `htmlRender` precedent of naming after the wire concept. - Restore the v5 `previewCreativeResponse` top-level re-export from `@adcp/sdk` for backwards compatibility. Adopters mid-migration who imported it and called it as a function continue to work unchanged. - Rename source file `preview-creative-response-builders.ts` → `preview-creative-builders.ts`. - Update SHAPE-GOTCHAS §4, the four reference-adapter migrations, the type-check regression block, the changeset, and the PR body. The 3 underlying typed factory functions (`singlePreviewCreativeResponse`, `batchPreviewCreativeResponse`, `variantPreviewCreativeResponse`) keep their full names — only the grouped `.single` / `.batch` / `.variant` accessor is renamed. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Five new typed-factory namespaces, mirroring the existing
asset-builders/render-builders/format-asset-slot-builderspattern. Each injects the discriminator at the typed-builder level using the
spread-order trick from
asset-builders.ts:34, so adopters can't write amissing-discriminator value at compile time and a runtime cast that smuggles
a conflicting discriminator via
fieldscannot clobber it.activationKeyActivationKey(typediscriminator).segment/.keyValuesignalIdSignalID(sourcediscriminator).catalog/.agentpreviewCreativeresponse_type.single/.batch/.variantbuildCreativeReturnBuildCreativeReturnunion.single/.multi/.singleEnveloped/.multiEnvelopedmediaBuyDeliveryNotificationnotification_typeonGetMediaBuyDeliveryResponse.scheduled/.final/.delayed/.adjusted/.windowUpdateAdapter migrations
Reference adapters now use the new factories where applicable (4 files,
several call sites each):
examples/signals-agent.ts—signal_id× 3,activation_key× 2examples/hello_signals_adapter_marketplace.ts—signal_id× 1,activation_key× 2examples/hello_creative_adapter_template.ts—buildCreative2-arm +previewCreative.singleexamples/hello_creative_adapter_ad_server.ts—buildCreativeshaped envelope +previewCreative.singleThe two
as unknown as PreviewCreativeResponse/as unknown as BuildCreativeSuccesscasts in thead-server adapter are gone — the typed factories return the wire shape directly.
Naming: avoid collision with v5 server helper
The new factory namespace is
previewCreative(notpreviewCreativeResponse)to avoid colliding with the v5 server-helper function of the same name that
is still re-exported at the top level of
@adcp/sdk. Following the existingurlRender/htmlRenderprecedent, the namespace is named after the wireconcept (no
Responsesuffix) and reads naturally:previewCreative.single({...})— "build a preview-creative single response".The top-level
previewCreativeResponsev5 server-helper export is retainedas-is. Adopters who imported
previewCreativeResponseand called it as afunction continue to work unchanged. The new factory namespace is a strictly
additive export under a non-colliding name.
Type-only regression tests
src/lib/server/decisioning/decisioning.type-checks.tsgains five new@ts-expect-errorblocks — one per factory — that pin the discriminatoras non-overridable. If the spread-order trick regresses (e.g. someone
removes the
Omit<>from the parameter type),tsc --noEmitfails.SHAPE-GOTCHAS recommendations
§1, §2, §4, §5 each gain a "Prevent at write time" block referencing the
new factory as the prevent-at-write-time fix.
Test plan
npx tsc --noEmitcleannpm run format:checkcleannpm test— full suite passes@ts-expect-errordirective verified to fire when removedpreviewCreativeResponse(v5 helper function) andpreviewCreative(new factory namespace) coexistCloses #1386.
🤖 Generated with Claude Code