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 COLUMNS = {columns_json};
|
||||
|
||||
const REPORT_NAME = '{scene_id}';
|
||||
|
||||
function normalizePayload(payload) {{
|
||||
if (typeof payload === 'string') {{
|
||||
try {{ return JSON.parse(payload); }} catch (_) {{ return {{}}; }}
|
||||
@@ -404,44 +408,59 @@ const defaultDeps = {{
|
||||
}};
|
||||
|
||||
async function buildBrowserEntrypointResult(args, deps = defaultDeps) {{
|
||||
// 1. Parameter validation
|
||||
const validation = validateArgs(args);
|
||||
if (!validation.valid) {{
|
||||
return {{
|
||||
type: 'report-artifact',
|
||||
report_name: '{scene_id}',
|
||||
status: 'error',
|
||||
error: 'Validation failed: ' + validation.errors.join(', '),
|
||||
column_defs: COLUMN_DEFS,
|
||||
columns: {columns_json},
|
||||
return buildArtifact({{
|
||||
status: 'blocked',
|
||||
blockedReason: 'validation_failed',
|
||||
reasons: validation.errors,
|
||||
rows: [],
|
||||
counts: {{ detail_rows: 0 }},
|
||||
partial_reasons: [],
|
||||
reasons: validation.errors
|
||||
}};
|
||||
args
|
||||
}});
|
||||
}}
|
||||
|
||||
|
||||
// 2. Page context validation
|
||||
const pageValidation = typeof deps.validatePageContext === 'function'
|
||||
? deps.validatePageContext(args)
|
||||
: {{ ok: true }};
|
||||
if (!pageValidation?.ok) {{
|
||||
return buildArtifact({{
|
||||
status: 'blocked',
|
||||
blockedReason: pageValidation?.reason || 'page_context_mismatch',
|
||||
reasons: [pageValidation?.reason || 'page_context_mismatch'],
|
||||
rows: [],
|
||||
args
|
||||
}});
|
||||
}}
|
||||
|
||||
// 3. Data fetching
|
||||
const reasons = [];
|
||||
let rawData = null;
|
||||
try {{
|
||||
const rawData = await (deps.queryData ? deps.queryData(args) : Promise.resolve([]));
|
||||
const rows = normalizeRows(rawData);
|
||||
return buildArtifact({{ args, rows }});
|
||||
rawData = await (deps.queryData ? deps.queryData(args) : Promise.resolve([]));
|
||||
}} catch (error) {{
|
||||
return {{
|
||||
type: 'report-artifact',
|
||||
report_name: '{scene_id}',
|
||||
return buildArtifact({{
|
||||
status: 'error',
|
||||
error: error.message,
|
||||
column_defs: COLUMN_DEFS,
|
||||
columns: {columns_json},
|
||||
fatalError: error.message,
|
||||
reasons: ['api_query_failed:' + error.message],
|
||||
rows: [],
|
||||
counts: {{ detail_rows: 0 }},
|
||||
partial_reasons: [],
|
||||
reasons: [error.message]
|
||||
}};
|
||||
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') {{
|
||||
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') {{
|
||||
|
||||
Reference in New Issue
Block a user