import * as __ctHelpers from "commontools"; /** * Regression test for array.length access inside computed(). * * This mimics the pattern from default-app.tsx where: * - allCharms comes from wish<{ allCharms: MentionableCharm[] }> * - computed(() => allCharms.length) accesses .length on an OpaqueRef * * The fix ensures the schema is { type: "array", items: { not: true, asOpaque: true } } * rather than { type: "object", properties: { length: { type: "number" } } } */ import { computed, NAME, pattern, UI, wish } from "commontools"; interface Charm { id: string; name: string; } export default pattern(() => { const { allCharms } = wish<{ allCharms: Charm[]; }>({ query: "/" }, { type: "object", properties: { allCharms: { type: "array", items: { $ref: "#/$defs/Charm" } } }, required: ["allCharms"], $defs: { Charm: { type: "object", properties: { id: { type: "string" }, name: { type: "string" } }, required: ["id", "name"] } } } as const satisfies __ctHelpers.JSONSchema).result; return { [NAME]: __ctHelpers.derive({ type: "object", properties: { allCharms: { type: "object", properties: { length: { type: "number" } }, required: ["length"] } }, required: ["allCharms"] } as const satisfies __ctHelpers.JSONSchema, { type: "string" } as const satisfies __ctHelpers.JSONSchema, { allCharms: { length: allCharms.length } }, ({ allCharms }) => `Charms (${allCharms.length})`), [UI]: (
Count: {__ctHelpers.derive({ type: "object", properties: { allCharms: { type: "object", properties: { length: { type: "number" } }, required: ["length"] } }, required: ["allCharms"] } as const satisfies __ctHelpers.JSONSchema, { type: "number" } as const satisfies __ctHelpers.JSONSchema, { allCharms: { length: allCharms.length } }, ({ allCharms }) => allCharms.length)}
), }; }, false as const satisfies __ctHelpers.JSONSchema, { type: "object", properties: { $NAME: { type: "string", asOpaque: true }, $UI: { $ref: "#/$defs/JSXElement" } }, required: ["$NAME", "$UI"], $defs: { JSXElement: { anyOf: [{ $ref: "https://commonfabric.org/schemas/vnode.json" }, { type: "object", properties: {} }, { $ref: "#/$defs/UIRenderable", asOpaque: true }] }, UIRenderable: { type: "object", properties: { $UI: { $ref: "https://commonfabric.org/schemas/vnode.json" } }, required: ["$UI"] } } } as const satisfies __ctHelpers.JSONSchema); // @ts-ignore: Internals function h(...args: any[]) { return __ctHelpers.h.apply(null, args); } // @ts-ignore: Internals h.fragment = __ctHelpers.h.fragment;