-
Notifications
You must be signed in to change notification settings - Fork 0
Make PostgreSQL the sole finance source ACC-66 #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { parseSheetsBatchResponse } from '../../src/finance/parser.ts'; | ||
| import { financeDataV1Schema } from '../../src/finance/runtime.ts'; | ||
| import { z } from 'zod'; | ||
| import type { FinanceDataV1, FinanceValidationResult } from '../../src/finance/types.ts'; | ||
|
|
||
| const sheetsBatchResponseSchema = z.object({ | ||
| spreadsheetId: z.string().min(1).optional(), | ||
| valueRanges: z.array(z.object({ | ||
| range: z.string().min(1).optional(), | ||
| values: z.array(z.array(z.unknown())).optional(), | ||
| }).passthrough()), | ||
| }).passthrough(); | ||
|
|
||
| /** Parses operator JSON without allowing V8 to echo source fragments in an error message. */ | ||
| export function parseFinanceImportJson(contents: string): unknown { | ||
| try { | ||
| return JSON.parse(contents) as unknown; | ||
| } catch { | ||
| throw new Error('Die Importdatei ist kein gültiges JSON.'); | ||
| } | ||
| } | ||
|
|
||
| function isRecord(value: unknown): value is Record<string, unknown> { | ||
| return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
| } | ||
|
|
||
| /** Accepts a Sheets batchGet payload or an already normalized FinanceDataV1 object. */ | ||
| export function parseFinanceImportSource(raw: unknown): FinanceValidationResult { | ||
| if (!isRecord(raw)) { | ||
| return { | ||
| success: false, | ||
| issues: [{ | ||
| tab: '_Meta', | ||
| row: 1, | ||
| column: '(file)', | ||
| expected: 'JSON-Objekt', | ||
| message: 'Die Importdatei muss ein JSON-Objekt sein.', | ||
| }], | ||
| }; | ||
| } | ||
| if ('valueRanges' in raw || 'spreadsheetId' in raw) { | ||
| const sheetsResponse = sheetsBatchResponseSchema.safeParse(raw); | ||
| if (!sheetsResponse.success) { | ||
| return { | ||
| success: false, | ||
| issues: [{ | ||
| tab: '_Meta', | ||
| row: 1, | ||
| column: '(file)', | ||
| expected: 'vollständige Sheets-batchGet-Antwort', | ||
| message: 'Die Importdatei enthält keine gültige Sheets-batchGet-Antwort.', | ||
| }], | ||
| }; | ||
| } | ||
| return parseSheetsBatchResponse(sheetsResponse.data); | ||
| } | ||
| const parsed = financeDataV1Schema.safeParse(raw); | ||
| if (parsed.success) return { success: true, data: parsed.data }; | ||
| return { | ||
| success: false, | ||
| issues: [{ | ||
| tab: '_Meta', | ||
| row: 1, | ||
| column: '(file)', | ||
| expected: 'FinanceDataV1 oder Sheets-batchGet', | ||
| message: 'Die Importdatei entspricht weder Finance Data Schema v1 noch einer Sheets-batchGet-Antwort.', | ||
| }], | ||
| }; | ||
| } | ||
|
|
||
| export function financeImportFingerprint(data: FinanceDataV1) { | ||
| return { | ||
| asOf: data.asOf, | ||
| currency: data.currency, | ||
| salaryDay: data.salaryDay, | ||
| accounts: data.accounts.length, | ||
| accountSnapshots: data.accountSnapshots.length, | ||
| pockets: data.pockets.length, | ||
| pocketSnapshots: data.pocketSnapshots.length, | ||
| budgetItems: data.budgetItems.length, | ||
| debts: data.debts.length, | ||
| debtSnapshots: data.debtSnapshots.length, | ||
| debtMilestones: data.debtMilestones.length, | ||
| reliefMilestones: data.reliefMilestones.length, | ||
| }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the documented normalized
FinanceDataV1input contains duplicate composite-key records, whitespace-only constrained text, or a regex-shaped invalid calendar date, this validation accepts it and PostgreSQL rejects the replacement, causing the operator import to fail instead of returning a validation error.