-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix(core): make AmplifyOutputs category types as unknown #14153
base: main
Are you sure you want to change the base?
Changes from 5 commits
8b8c2a7
08dde45
990e987
5da2834
3d55d3c
dd75f4e
c63d1d6
d0f6eb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "aws-amplify/adapter-core/internals", | ||
"types": "../../dist/esm/adapter-core/internals.d.ts", | ||
"main": "../../dist/cjs/adapter-core/internals.js", | ||
"module": "../../dist/esm/adapter-core/internals.mjs", | ||
"sideEffects": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export { | ||
LegacyConfig, | ||
AmplifyOutputsUnknown, | ||
} from '@aws-amplify/core/internals/utils'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ import { | |
} from './singleton/Auth/types'; | ||
import { NotificationsConfig } from './singleton/Notifications/types'; | ||
import { | ||
AmplifyOutputs, | ||
AmplifyOutputsAnalyticsProperties, | ||
AmplifyOutputsAuthProperties, | ||
AmplifyOutputsCustomProperties, | ||
|
@@ -28,6 +27,7 @@ import { | |
AmplifyOutputsNotificationsProperties, | ||
AmplifyOutputsStorageBucketProperties, | ||
AmplifyOutputsStorageProperties, | ||
AmplifyOutputsUnknown, | ||
} from './singleton/AmplifyOutputs/types'; | ||
import { | ||
AnalyticsConfig, | ||
|
@@ -40,10 +40,10 @@ import { | |
} from './singleton/types'; | ||
|
||
export function isAmplifyOutputs( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sanity check: have we verified this change wouldnt affect if someone extracted type by using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In the example above post our change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
config: ResourcesConfig | LegacyConfig | AmplifyOutputs, | ||
): config is AmplifyOutputs { | ||
config: ResourcesConfig | LegacyConfig | AmplifyOutputsUnknown, | ||
): config is AmplifyOutputsUnknown { | ||
// version format initially will be '1' but is expected to be something like x.y where x is major and y minor version | ||
const { version } = config as AmplifyOutputs; | ||
const { version } = config as AmplifyOutputsUnknown; | ||
|
||
if (!version) { | ||
return false; | ||
|
@@ -291,32 +291,44 @@ function parseNotifications( | |
} | ||
|
||
export function parseAmplifyOutputs( | ||
amplifyOutputs: AmplifyOutputs, | ||
amplifyOutputs: AmplifyOutputsUnknown, | ||
): ResourcesConfig { | ||
const resourcesConfig: ResourcesConfig = {}; | ||
|
||
if (amplifyOutputs.storage) { | ||
resourcesConfig.Storage = parseStorage(amplifyOutputs.storage); | ||
resourcesConfig.Storage = parseStorage( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont think type casting is the best way here. IMO we should add guard rails in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, a type predicate should allow us to drop tha casting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. discussed async, decided to go ahead with type casting in this PR with a follow-up item to add run-time checks during parsing |
||
amplifyOutputs.storage as AmplifyOutputsStorageProperties, | ||
); | ||
} | ||
|
||
if (amplifyOutputs.auth) { | ||
resourcesConfig.Auth = parseAuth(amplifyOutputs.auth); | ||
resourcesConfig.Auth = parseAuth( | ||
amplifyOutputs.auth as AmplifyOutputsAuthProperties, | ||
); | ||
} | ||
|
||
if (amplifyOutputs.analytics) { | ||
resourcesConfig.Analytics = parseAnalytics(amplifyOutputs.analytics); | ||
resourcesConfig.Analytics = parseAnalytics( | ||
amplifyOutputs.analytics as AmplifyOutputsAnalyticsProperties, | ||
); | ||
} | ||
|
||
if (amplifyOutputs.geo) { | ||
resourcesConfig.Geo = parseGeo(amplifyOutputs.geo); | ||
resourcesConfig.Geo = parseGeo( | ||
amplifyOutputs.geo as AmplifyOutputsGeoProperties, | ||
); | ||
} | ||
|
||
if (amplifyOutputs.data) { | ||
resourcesConfig.API = parseData(amplifyOutputs.data); | ||
resourcesConfig.API = parseData( | ||
amplifyOutputs.data as AmplifyOutputsDataProperties, | ||
); | ||
} | ||
|
||
if (amplifyOutputs.custom) { | ||
const customConfig = parseCustom(amplifyOutputs.custom); | ||
const customConfig = parseCustom( | ||
amplifyOutputs.custom as AmplifyOutputsCustomProperties, | ||
); | ||
|
||
if (customConfig && 'Events' in customConfig) { | ||
resourcesConfig.API = { ...resourcesConfig.API, ...customConfig }; | ||
|
@@ -325,7 +337,7 @@ export function parseAmplifyOutputs( | |
|
||
if (amplifyOutputs.notifications) { | ||
resourcesConfig.Notifications = parseNotifications( | ||
amplifyOutputs.notifications, | ||
amplifyOutputs.notifications as AmplifyOutputsNotificationsProperties, | ||
); | ||
} | ||
|
||
|
@@ -383,22 +395,10 @@ function createBucketInfoMap( | |
); | ||
} | ||
|
||
const sanitizedPaths = paths | ||
? Object.entries(paths).reduce< | ||
Record<string, Record<string, string[] | undefined>> | ||
>((acc, [key, value]) => { | ||
if (value !== undefined) { | ||
acc[key] = value; | ||
} | ||
|
||
return acc; | ||
}, {}) | ||
: undefined; | ||
|
||
mappedBuckets[name] = { | ||
bucketName, | ||
region, | ||
paths: sanitizedPaths, | ||
paths, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed previously added type narrowing |
||
}; | ||
}, | ||
); | ||
|
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.
Shouldn't be publicly exposed, updated for internal use via
'aws-amplify/adapter-core/internals'