diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5172429 Binary files /dev/null and b/.DS_Store differ diff --git a/Archive.zip b/Archive.zip deleted file mode 100644 index 7c63196..0000000 Binary files a/Archive.zip and /dev/null differ diff --git a/README.md b/README.md index 970efed..08ddb2e 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,9 @@ Campos **nullable** permitem limpar o valor escolhendo "Limpar campo (null)" ou ## Campos PickList -Campos com `presentationType: PickList` (listas de opções customizadas ou do sistema) exibem uma **lista carregada da API** com nomes legíveis (ex: `Conteúdo`). O app envia automaticamente o ID correto (`/C_GenericTaskSetor/`), evitando erros ao digitar o nome manualmente. +Campos com `presentationType: PickList` (listas de opções customizadas ou do sistema) exibem uma **lista carregada da API** com nomes legíveis (ex: `Conteúdo`). O app envia o ID como **string** (`"/C_GenericTaskSetor/Edição"`), não como objeto `{"id":"..."}` — formato exigido pela API do Adaptive Work para PickList. -Campos de **referência** (`ReferenceToObject`, ex: User, Project) continuam exigindo o ID manual ou JSON `{"id":"/Tipo/guid"}`. +Campos de **referência** (`ReferenceToObject`, ex: User, Project) continuam exigindo objeto `{"id":"/Tipo/guid"}` ou `/Tipo/guid` convertido para `{ id }`. ## Variáveis de ambiente @@ -108,7 +108,7 @@ Exemplo resumido: "typeName": "Task", "filter": "Todos", "fieldName": "C_MeuCampo", - "value": { "id": "/C_GenericTaskSetor/abc123" }, + "value": "/C_GenericTaskSetor/Edição", "valueLabel": "Conteúdo (/C_GenericTaskSetor/abc123)" }, "summary": { "total": 10, "updated": 9, "errors": 1 }, diff --git a/src/metadata/field-hints.ts b/src/metadata/field-hints.ts index 5358ce8..b3a8475 100644 --- a/src/metadata/field-hints.ts +++ b/src/metadata/field-hints.ts @@ -25,7 +25,7 @@ export function formatFieldHint(field: FieldDescription): string { if (isPickListField(field)) { lines.push("Tipo: PickList (lista de opções)"); - lines.push("Escolha um valor na lista — não digite o nome exibido manualmente."); + lines.push("Escolha um valor na lista — a API recebe o ID como string (ex: /C_GenericTaskSetor/Edição)."); const refType = (field as { referencedEntities?: string[] }).referencedEntities?.[0]; if (refType) { lines.push(`Opções carregadas de: ${refType}`); diff --git a/src/parse/prompt-picklist.ts b/src/parse/prompt-picklist.ts index ceaef2d..2a13b47 100644 --- a/src/parse/prompt-picklist.ts +++ b/src/parse/prompt-picklist.ts @@ -64,7 +64,7 @@ async function promptPickListSelection( const match = pickListOptions.find((o) => o.id === selectedId); return { - value: { id: selectedId }, + value: selectedId, displayLabel: match ? `${match.label} (${match.id})` : String(selectedId), @@ -95,6 +95,7 @@ async function promptManualEntityValue( } function formatEntityDisplayLabel(value: JsonValue): string | undefined { + if (typeof value === "string") return value; if (value && typeof value === "object" && "id" in value) { const id = (value as { id?: unknown }).id; if (typeof id === "string") return id; diff --git a/src/parse/value.ts b/src/parse/value.ts index e933ea0..ee05bea 100644 --- a/src/parse/value.ts +++ b/src/parse/value.ts @@ -1,5 +1,6 @@ import type { FieldDescription, FieldType, JsonValue } from "@arco/clarizen-lib"; import { getFieldTypeExample } from "../metadata/field-hints.js"; +import { isPickListField } from "../metadata/picklist.js"; export class ValueParseError extends Error { constructor(message: string) { @@ -54,6 +55,29 @@ function parseEntity(raw: string): JsonValue { ); } +/** PickList fields accept the entity ID as a plain string, not `{ id }`. */ +function parsePickListEntityId(raw: string): string { + const trimmed = raw.trim(); + if (trimmed.startsWith("{")) { + try { + const parsed = JSON.parse(trimmed) as Record; + if (typeof parsed.id === "string") { + return parsed.id; + } + throw new ValueParseError('JSON de PickList deve conter "id".'); + } catch (err) { + if (err instanceof ValueParseError) throw err; + throw new ValueParseError(`JSON inválido para PickList: "${raw}"`); + } + } + if (trimmed.startsWith("/")) { + return trimmed; + } + throw new ValueParseError( + `ID de PickList inválido: "${raw}". Use /Tipo/id ou {"id":"/Tipo/id"}`, + ); +} + function parseJsonObject(raw: string, typeName: string): JsonValue { try { return JSON.parse(raw.trim()) as JsonValue; @@ -108,6 +132,10 @@ export function parseFieldValue( throw new ValueParseError("Valor não pode ser vazio."); } + if (isPickListField(field)) { + return parsePickListEntityId(raw); + } + return parseByType(raw, field.type); }