{"version":3,"file":"columnResolver.cjs","names":["getAxisId","extractPObjectId","matchAxisId"],"sources":["../../../src/components/PlDataTable/columnResolver.ts"],"sourcesContent":["import type {\n  AxisId,\n  ColumnUniversalId,\n  PObjectId,\n  PTableColumnId,\n  PTableColumnIdColumn,\n} from \"@milaboratories/pl-model-common\";\nimport { extractPObjectId, getAxisId, matchAxisId } from \"@milaboratories/pl-model-common\";\nimport type { ColumnRecipe } from \"../../columns\";\n\n/**\n * Resolves a user-supplied PTableColumnId against the discovered set of\n * columns and axes. For column refs, accepts either the full recipe id (rich\n * {@link ColumnUniversalId}) or the bare {@link PObjectId} and returns a ref\n * carrying the recipe's full id — the same id that appears as the leaf in the\n * emitted SpecQuery, so engine-side dedup is consistent with the resolver's\n * view. Axis refs are checked against the union of axes spanned by the\n * columns and pass through unchanged on hit.\n * Returns `undefined` when the reference cannot be matched.\n */\nexport type ColumnResolver = (ref: PTableColumnId) => PTableColumnId | undefined;\n\nexport function createColumnResolver(columns: ColumnRecipe[]): ColumnResolver {\n  const axisIds: AxisId[] = [];\n  for (const c of columns) {\n    for (const ax of c.getSpec().axesSpec) {\n      axisIds.push(getAxisId(ax));\n    }\n  }\n\n  const byFullId = new Map<ColumnUniversalId, ColumnRecipe>();\n  const byPObjectId = new Map<PObjectId, ColumnRecipe>();\n  for (const c of columns) {\n    byFullId.set(c.id, c);\n    const pid = extractPObjectId(c.id);\n    if (!byPObjectId.has(pid)) byPObjectId.set(pid, c);\n  }\n\n  return (ref: PTableColumnId): PTableColumnId | undefined => {\n    if (ref.type === \"axis\") {\n      return axisIds.some((a) => matchAxisId(ref.id, a)) ? ref : undefined;\n    }\n    const pid = tryExtractPObjectId(ref.id);\n    const hit = byFullId.get(ref.id) ?? (pid === undefined ? undefined : byPObjectId.get(pid));\n    if (hit === undefined) return undefined;\n    return { type: \"column\", id: hit.id } satisfies PTableColumnIdColumn;\n  };\n}\n\n/** {@link extractPObjectId} for a stored reference: an id it cannot parse resolves to\n *  nothing, so the one entry is dropped instead of failing the whole table. */\nfunction tryExtractPObjectId(id: ColumnUniversalId): PObjectId | undefined {\n  try {\n    return extractPObjectId(id);\n  } catch {\n    return undefined;\n  }\n}\n"],"mappings":";;AAsBA,SAAgB,qBAAqB,SAAyC;CAC5E,MAAM,UAAoB,CAAC;CAC3B,KAAK,MAAM,KAAK,SACd,KAAK,MAAM,MAAM,EAAE,QAAQ,CAAC,CAAC,UAC3B,QAAQ,MAAA,GAAKA,gCAAAA,UAAAA,CAAU,EAAE,CAAC;CAI9B,MAAM,2BAAW,IAAI,IAAqC;CAC1D,MAAM,8BAAc,IAAI,IAA6B;CACrD,KAAK,MAAM,KAAK,SAAS;EACvB,SAAS,IAAI,EAAE,IAAI,CAAC;EACpB,MAAM,OAAA,GAAMC,gCAAAA,iBAAAA,CAAiB,EAAE,EAAE;EACjC,IAAI,CAAC,YAAY,IAAI,GAAG,GAAG,YAAY,IAAI,KAAK,CAAC;CACnD;CAEA,QAAQ,QAAoD;EAC1D,IAAI,IAAI,SAAS,QACf,OAAO,QAAQ,MAAM,OAAA,GAAMC,gCAAAA,YAAAA,CAAY,IAAI,IAAI,CAAC,CAAC,IAAI,MAAM,KAAA;EAE7D,MAAM,MAAM,oBAAoB,IAAI,EAAE;EACtC,MAAM,MAAM,SAAS,IAAI,IAAI,EAAE,MAAM,QAAQ,KAAA,IAAY,KAAA,IAAY,YAAY,IAAI,GAAG;EACxF,IAAI,QAAQ,KAAA,GAAW,OAAO,KAAA;EAC9B,OAAO;GAAE,MAAM;GAAU,IAAI,IAAI;EAAG;CACtC;AACF;;;AAIA,SAAS,oBAAoB,IAA8C;CACzE,IAAI;EACF,QAAA,GAAOD,gCAAAA,iBAAAA,CAAiB,EAAE;CAC5B,QAAQ;EACN;CACF;AACF"}