From a2d8a774ca7ffa6c14e19624505bff8dbd75f9ff Mon Sep 17 00:00:00 2001 From: lirui Date: Mon, 9 Feb 2026 21:54:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20API=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=92=8C=E6=8F=90=E4=BA=A4=E8=AE=BE=E7=BD=AE=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=9B=E6=9B=B4=E6=96=B0=20Excel=20=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=20API=20=E5=AD=97=E6=AE=B5=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=92=8C=E4=BB=BB=E5=8A=A1=E5=8C=85=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/components/ApiConfigModal.svelte | 298 +++++++++++++++++++ src/lib/components/ExcelTable.svelte | 98 +++++- src/lib/components/SubmissionSettings.svelte | 88 ++++++ src/lib/converter.ts | 55 +++- src/lib/types.ts | 42 +++ src/routes/+page.svelte | 135 ++++++++- 6 files changed, 695 insertions(+), 21 deletions(-) create mode 100644 src/lib/components/ApiConfigModal.svelte create mode 100644 src/lib/components/SubmissionSettings.svelte diff --git a/src/lib/components/ApiConfigModal.svelte b/src/lib/components/ApiConfigModal.svelte new file mode 100644 index 0000000..23ff598 --- /dev/null +++ b/src/lib/components/ApiConfigModal.svelte @@ -0,0 +1,298 @@ + + + + + diff --git a/src/lib/components/ExcelTable.svelte b/src/lib/components/ExcelTable.svelte index 67c675d..2747e39 100644 --- a/src/lib/components/ExcelTable.svelte +++ b/src/lib/components/ExcelTable.svelte @@ -1,15 +1,23 @@ + + + + diff --git a/src/lib/converter.ts b/src/lib/converter.ts index 03c38ab..04b3270 100644 --- a/src/lib/converter.ts +++ b/src/lib/converter.ts @@ -1,5 +1,14 @@ import dayjs from 'dayjs'; -import type { MappingConfig, RowData, DataType, MappingTemplate } from './types.js'; +import type { + MappingConfig, + RowData, + DataType, + MappingTemplate, + ApiEnrichmentRule, + SubmissionConfig, + StaticRule, + JobBundle +} from './types.js'; /** * Check if a value is considered empty. @@ -195,3 +204,47 @@ export function exportTemplate(mappings: MappingConfig[]): MappingTemplate { return entry; }); } + +/** + * Convert enabled MappingConfigs to StaticRule format for Job Bundle. + */ +function toStaticRules(mappings: MappingConfig[]): StaticRule[] { + return mappings + .filter((m) => m.enabled) + .map((m) => { + const rule: StaticRule = { + type: 'static', + source: m.source, + target: m.target, + dataType: m.type + }; + if (m.type === 'date' && m.format) rule.format = m.format; + return rule; + }); +} + +/** + * Generate a complete Job Bundle for export. + */ +export function generateJobBundle( + rows: RowData[], + mappings: MappingConfig[], + enrichmentRules: ApiEnrichmentRule[], + submissionConfig: SubmissionConfig +): JobBundle { + const sourceData = convertData(rows, mappings); + const staticRules = toStaticRules(mappings); + + return { + meta: { + version: '1.0.0', + generated_at: new Date().toISOString() + }, + config: { + static_rules: staticRules, + enrichment_rules: enrichmentRules, + submission: submissionConfig + }, + source_data: sourceData + }; +} diff --git a/src/lib/types.ts b/src/lib/types.ts index a315b25..b404ead 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -33,3 +33,45 @@ export type MappingTemplate = Pick< MappingConfig, 'source' | 'target' | 'type' | 'format' | 'excludeIfEmpty' | 'defaultValue' >[]; + +/** Static mapping rule in Job Bundle output */ +export interface StaticRule { + type: 'static'; + source: string; + target: string; + dataType: DataType; + format?: string; +} + +/** Dynamic API enrichment rule */ +export interface ApiEnrichmentRule { + type: 'api_fetch'; + target_key: string; + url_template: string; + method: 'GET' | 'POST'; + headers?: Record; + body_template?: string; + response_path: string; + fallback_value?: unknown; +} + +/** Submission configuration for final data push */ +export interface SubmissionConfig { + target_url: string; + method: 'POST' | 'PUT'; + batch_size: number; +} + +/** Final exported Job Bundle structure */ +export interface JobBundle { + meta: { + version: string; + generated_at: string; + }; + config: { + static_rules: StaticRule[]; + enrichment_rules: ApiEnrichmentRule[]; + submission: SubmissionConfig; + }; + source_data: Record[]; +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 83a84b9..4cd76cb 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,9 +1,11 @@
+
+ + + +
+ + + +
+
{/if} + + +{#if showApiConfig} + { showApiConfig = false; editingRuleIndex = null; }} + /> +{/if} + +{#if showSubmissionSettings} + (showSubmissionSettings = false)} + /> +{/if}