diff --git a/.changeset/cool-gifts-push.md b/.changeset/cool-gifts-push.md new file mode 100644 index 000000000..66b8795d4 --- /dev/null +++ b/.changeset/cool-gifts-push.md @@ -0,0 +1,5 @@ +--- +'@flatfile/plugin-autocast': patch +--- + +Fix for date casting diff --git a/package-lock.json b/package-lock.json index 699863a25..3b1ee71a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12095,7 +12095,7 @@ }, "plugins/autocast": { "name": "@flatfile/plugin-autocast", - "version": "0.2.0", + "version": "0.2.1", "license": "ISC", "dependencies": { "@flatfile/api": "^1.4.9", diff --git a/plugins/autocast/src/autocast.plugin.ts b/plugins/autocast/src/autocast.plugin.ts index b74f06400..f61f56f6a 100644 --- a/plugins/autocast/src/autocast.plugin.ts +++ b/plugins/autocast/src/autocast.plugin.ts @@ -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( @@ -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' ) } } @@ -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] @@ -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 { @@ -107,5 +107,5 @@ export function castDate(value: TPrimitive): TPrimitive { return date.toUTCString() } } - return value + throw new Error(`Failed to cast '${value}' to 'date'`) }