function __cfHardenFn(fn: Function) { Object.freeze(fn); const prototype = fn.prototype; if (prototype && typeof prototype === "object") { Object.freeze(prototype); } return fn; } import { __cfHelpers } from "commonfabric"; import { pattern, UI } from "commonfabric"; const define = undefined; const runtimeDeps = undefined; const __cfAmdHooks = undefined; interface Vote { optionId: string; voterName: string; } interface Option { id: string; } interface OptionTally { option: Option; voters: Array<{ name: string; }>; } // FIXTURE: nested-map-derived-collection // Verifies (CT-1778): a reactive collection produced by a non-reactive-origin helper // over reactive parameters — `tallyOptions(options, votes): OptionTally[]` — is // recognized as reactive at array-method-decision time, so a nested `.map` over a // per-item field (`tally.voters.map(...)`) lowers to `.mapWithPattern` instead of being // emitted raw (which throws "OpaqueRef.map(fn) is no longer supported" at runtime, // because the receiver is an OpaqueRef). Before the fix the inner map raced the helper // result's late lift-wrap registration and stayed raw. // // Covers both shapes: // - direct receiver: `ranked = tallyOptions(options, votes)` // - chained derivation: `enriched = enrichTallies(ranked)` (a derived const passed to // another helper), exercising the recursive provenance walk through const args. const tallyOptions = __cfHardenFn((options: Option[], votes: Vote[]): OptionTally[] => options.map((option): OptionTally => ({ option, voters: votes.map((v) => ({ name: v.voterName })), }))); const enrichTallies = __cfHardenFn((tallies: OptionTally[]): OptionTally[] => tallies.map((t): OptionTally => ({ option: t.option, voters: t.voters }))); const __cfLift_1 = __cfHelpers.lift<{ options: Option[]; votes: Vote[]; }, OptionTally[]>(({ options, votes }) => tallyOptions(options, votes), { type: "object", properties: { options: { type: "array", items: { $ref: "#/$defs/Option" } }, votes: { type: "array", items: { $ref: "#/$defs/Vote" } } }, required: ["options", "votes"], $defs: { Vote: { type: "object", properties: { optionId: { type: "string" }, voterName: { type: "string" } }, required: ["optionId", "voterName"] }, Option: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } } as const satisfies __cfHelpers.JSONSchema, { type: "array", items: { $ref: "#/$defs/OptionTally" }, $defs: { OptionTally: { type: "object", properties: { option: { $ref: "#/$defs/Option" }, voters: { type: "array", items: { type: "object", properties: { name: { type: "string" } }, required: ["name"] } } }, required: ["option", "voters"] }, Option: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } } as const satisfies __cfHelpers.JSONSchema); const __cfLift_2 = __cfHelpers.lift<{ ranked: OptionTally[]; }, OptionTally[]>(({ ranked }) => enrichTallies(ranked), { type: "object", properties: { ranked: { type: "array", items: { $ref: "#/$defs/OptionTally" } } }, required: ["ranked"], $defs: { OptionTally: { type: "object", properties: { option: { $ref: "#/$defs/Option" }, voters: { type: "array", items: { type: "object", properties: { name: { type: "string" } }, required: ["name"] } } }, required: ["option", "voters"] }, Option: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } } as const satisfies __cfHelpers.JSONSchema, { type: "array", items: { $ref: "#/$defs/OptionTally" }, $defs: { OptionTally: { type: "object", properties: { option: { $ref: "#/$defs/Option" }, voters: { type: "array", items: { type: "object", properties: { name: { type: "string" } }, required: ["name"] } } }, required: ["option", "voters"] }, Option: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } } as const satisfies __cfHelpers.JSONSchema); const __cfPattern_1 = __cfHelpers.pattern(__cf_pattern_input => { const voter = __cf_pattern_input.key("element"); return {voter.key("name")}; }, { type: "object", properties: { element: { type: "object", properties: { name: { type: "string" } }, required: ["name"] } }, required: ["element"] } as const satisfies __cfHelpers.JSONSchema, { anyOf: [{ $ref: "https://commonfabric.org/schemas/vnode.json" }, { $ref: "#/$defs/UIRenderable" }, { type: "object", properties: {} }], $defs: { UIRenderable: { type: "object", properties: { $UI: { $ref: "https://commonfabric.org/schemas/vnode.json" } }, required: ["$UI"] } } } as const satisfies __cfHelpers.JSONSchema); const __cfPattern_2 = __cfHelpers.pattern(__cf_pattern_input => { const tally = __cf_pattern_input.key("element"); return (