feat(generator): enhance buildBrowserEntrypointResult with validation flow
- Add page context validation step with deps.validatePageContext - Change validation failure status from 'error' to 'blocked' - Add row normalization partial detection - Use buildArtifact for all return paths consistently - Add COLUMNS and REPORT_NAME constants for buildArtifact - Export determineArtifactStatus, COLUMNS, REPORT_NAME in module.exports 🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
@@ -291,6 +291,10 @@ const STATIC_PARAMS = {static_params_json};
|
|||||||
|
|
||||||
const COLUMN_DEFS = {column_defs_json};
|
const COLUMN_DEFS = {column_defs_json};
|
||||||
|
|
||||||
|
const COLUMNS = {columns_json};
|
||||||
|
|
||||||
|
const REPORT_NAME = '{scene_id}';
|
||||||
|
|
||||||
function normalizePayload(payload) {{
|
function normalizePayload(payload) {{
|
||||||
if (typeof payload === 'string') {{
|
if (typeof payload === 'string') {{
|
||||||
try {{ return JSON.parse(payload); }} catch (_) {{ return {{}}; }}
|
try {{ return JSON.parse(payload); }} catch (_) {{ return {{}}; }}
|
||||||
@@ -404,44 +408,59 @@ const defaultDeps = {{
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
async function buildBrowserEntrypointResult(args, deps = defaultDeps) {{
|
async function buildBrowserEntrypointResult(args, deps = defaultDeps) {{
|
||||||
|
// 1. Parameter validation
|
||||||
const validation = validateArgs(args);
|
const validation = validateArgs(args);
|
||||||
if (!validation.valid) {{
|
if (!validation.valid) {{
|
||||||
return {{
|
return buildArtifact({{
|
||||||
type: 'report-artifact',
|
status: 'blocked',
|
||||||
report_name: '{scene_id}',
|
blockedReason: 'validation_failed',
|
||||||
status: 'error',
|
reasons: validation.errors,
|
||||||
error: 'Validation failed: ' + validation.errors.join(', '),
|
|
||||||
column_defs: COLUMN_DEFS,
|
|
||||||
columns: {columns_json},
|
|
||||||
rows: [],
|
rows: [],
|
||||||
counts: {{ detail_rows: 0 }},
|
args
|
||||||
partial_reasons: [],
|
}});
|
||||||
reasons: validation.errors
|
|
||||||
}};
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
try {{
|
// 2. Page context validation
|
||||||
const rawData = await (deps.queryData ? deps.queryData(args) : Promise.resolve([]));
|
const pageValidation = typeof deps.validatePageContext === 'function'
|
||||||
const rows = normalizeRows(rawData);
|
? deps.validatePageContext(args)
|
||||||
return buildArtifact({{ args, rows }});
|
: {{ ok: true }};
|
||||||
}} catch (error) {{
|
if (!pageValidation?.ok) {{
|
||||||
return {{
|
return buildArtifact({{
|
||||||
type: 'report-artifact',
|
status: 'blocked',
|
||||||
report_name: '{scene_id}',
|
blockedReason: pageValidation?.reason || 'page_context_mismatch',
|
||||||
status: 'error',
|
reasons: [pageValidation?.reason || 'page_context_mismatch'],
|
||||||
error: error.message,
|
|
||||||
column_defs: COLUMN_DEFS,
|
|
||||||
columns: {columns_json},
|
|
||||||
rows: [],
|
rows: [],
|
||||||
counts: {{ detail_rows: 0 }},
|
args
|
||||||
partial_reasons: [],
|
}});
|
||||||
reasons: [error.message]
|
|
||||||
}};
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
// 3. Data fetching
|
||||||
|
const reasons = [];
|
||||||
|
let rawData = null;
|
||||||
|
try {{
|
||||||
|
rawData = await (deps.queryData ? deps.queryData(args) : Promise.resolve([]));
|
||||||
|
}} catch (error) {{
|
||||||
|
return buildArtifact({{
|
||||||
|
status: 'error',
|
||||||
|
fatalError: error.message,
|
||||||
|
reasons: ['api_query_failed:' + error.message],
|
||||||
|
rows: [],
|
||||||
|
args
|
||||||
|
}});
|
||||||
|
}}
|
||||||
|
|
||||||
|
// 4. Row normalization
|
||||||
|
const rows = normalizeRows(rawData);
|
||||||
|
if (rows.length === 0 && Array.isArray(rawData) && rawData.length > 0) {{
|
||||||
|
reasons.push('row_normalization_partial');
|
||||||
|
}}
|
||||||
|
|
||||||
|
// 5. Build artifact
|
||||||
|
return buildArtifact({{ reasons, rows, args }});
|
||||||
}}
|
}}
|
||||||
|
|
||||||
if (typeof module !== 'undefined') {{
|
if (typeof module !== 'undefined') {{
|
||||||
module.exports = {{ buildBrowserEntrypointResult, normalizePayload, validateArgs, buildRequest, normalizeRows, buildArtifact, API_ENDPOINTS, STATIC_PARAMS, COLUMN_DEFS }};
|
module.exports = {{ buildBrowserEntrypointResult, normalizePayload, validateArgs, buildRequest, normalizeRows, buildArtifact, determineArtifactStatus, API_ENDPOINTS, STATIC_PARAMS, COLUMN_DEFS, COLUMNS, REPORT_NAME }};
|
||||||
}}
|
}}
|
||||||
|
|
||||||
if (typeof args !== 'undefined') {{
|
if (typeof args !== 'undefined') {{
|
||||||
|
|||||||
Reference in New Issue
Block a user