feat(contracts): clients tolerate union members they don't know yet #15951
Mergedjuliusmarmingemerged 3 commits into
main fromrefs/pull/15951/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- packages/contracts/src/baseSchemas.ts line 225OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -115,0 +205,21 @@205+ * Whether a raw, undecoded value carries a `tag` this build does not know206+ * among `members`. For checks outside a {@link ForwardCompatibleUnion}, such207+ * as an envelope that must skip a payload of an unknown kind.208+ */209+export const hasUnknownUnionTag = (210+ members: ReadonlyArray<Schema.Top & { readonly fields: object }>,211+ tag: string,212+): ((value: unknown) => boolean) => {213+ const known = knownTags(members, tag);214+ return (value) =>215+ typeof value === "object" &&216+ value !== null &&217+ tag in value &&218+ !known.has((value as Record<string, unknown>)[tag] as string);219+};220+221+/** Whether a decoded {@link ForwardCompatibleUnion} value is a member this build does not know. */222+export const isUnknownUnionMember = <A>(223+ value: A,224+): value is Extract<A, UnknownUnionMember<string>> =>225+ typeof value === "object" && value !== null && "_unknown" in value && value._unknown === true;
juliusmarminge merged thisca3f973
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed