Skip to content

Commit

Permalink
Fix date bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Brugger committed Sep 6, 2023
1 parent 9786771 commit 3264753
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-gifts-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@flatfile/plugin-autocast': patch
---

Fix for date casting
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions plugins/autocast/src/autocast.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import api from '@flatfile/api'
import { FlatfileListener, FlatfileEvent } from '@flatfile/listener'
import { BulkRecordHook } from '@flatfile/plugin-record-hook'
import { FlatfileRecord, TPrimitive } from '@flatfile/hooks'
import { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
import { BulkRecordHook } from '@flatfile/plugin-record-hook'
import { logInfo } from '@flatfile/util-common'

export function autocast(
Expand Down Expand Up @@ -42,12 +42,12 @@ export function autocast(
caster &&
typeof originalValue !== field.type
) {
record.computeIfPresent(field.key, caster)

if (originalValue === record.get(field.key)) {
try {
record.computeIfPresent(field.key, caster)
} catch (e) {
record.addError(
field.key,
`Failed to cast '${originalValue}' to '${field.type}'`
e.message || 'Failed to cast value'
)
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ export function castNumber(value: TPrimitive): TPrimitive {
}
}
}
return value
throw new Error(`Failed to cast '${value}' to 'number'`)
}

export const TRUTHY_VALUES = ['1', 'yes', 'true', 'on', 't', 'y', 1]
Expand All @@ -97,7 +97,7 @@ export function castBoolean(value: TPrimitive): TPrimitive {
return false
}
}
return value
throw new Error(`Failed to cast '${value}' to 'boolean'`)
}

export function castDate(value: TPrimitive): TPrimitive {
Expand All @@ -107,5 +107,5 @@ export function castDate(value: TPrimitive): TPrimitive {
return date.toUTCString()
}
}
return value
throw new Error(`Failed to cast '${value}' to 'date'`)
}

0 comments on commit 3264753

Please sign in to comment.