Skip to content

assignArrayItemIds

assignArrayItemIds(props): Record<string, unknown>

Defined in: packages/core/src/fields/array/utils.ts:97

Recursively backfills a stored id onto every object-shaped array item anywhere in data — walking fields the same shape getFieldsInputSchema/validateFields already do: into a group’s own sub-fields, into an array’s items (including a nested array of array), and into each blocks() item’s own matching block-type fields — so an array of groups nested inside a block or another group gets ids too, not just a top-level array field. Pure: returns a new object, never mutates data.

Called by prepareEdit on mergedFields, before the beforeChange hook runs — the one place EVERY write (create, update, the Local API, a project’s own Convex mutation calling prepareEdit directly) passes through, so a caller that skips FormArray’s own id assignment still gets a valid stored id before the write lands. This is WHY the Convex validator accepts id: v.optional(v.string()) rather than requiring one outright (validator.ts’s own doc comment) — optional only for existing, pre-this-step documents; every NEW write is backfilled here regardless.

Record<string, unknown>

The document (or nested object) to backfill ids into.

Record<string, AdminField>

The field map to walk (a collection’s own top-level fields for the entry call, a block type’s own fields or a group’s own fields for a recursive call).

Record<string, unknown>

A new object, structurally identical to data except every object-shaped array item gains an id if it lacked one.