Skip to content
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

chore: Small cleanup to internal core utils #13140

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/core/src/libraryUtils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import WordArray from './utils/WordArray';

/*
This file maps top-level exports from `@aws-amplify/core/internals/utils`. These are intended to be internal
utils for use throughout the library.
*/

// Core utilities
export {
generateRandomString,
Expand Down Expand Up @@ -57,7 +58,6 @@ export {
export { Signer } from './Signer';
export {
JWT,
StrictUnion,
CognitoIdentityPoolConfig,
JwtPayload,
AuthStandardAttributeKey,
Expand Down Expand Up @@ -119,10 +119,11 @@ export { Reachability } from './Reachability';
export { USER_AGENT_HEADER } from './constants';
export { fetchAuthSession } from './singleton/apis/internal/fetchAuthSession';
export { AMPLIFY_SYMBOL } from './Hub';
export { StrictUnion } from './types';
export { base64Decoder, base64Encoder } from './utils/convert';
export { getCrypto } from './utils/globalHelpers';
export { cryptoSecureRandomInt } from './utils/cryptoSecureRandomInt';
export { WordArray };
export { WordArray } from './utils/WordArray';

// Hub
export { HubInternal } from './Hub';
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/singleton/Auth/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { StrictUnion } from '../../types';
import { AtLeastOne } from '../types';

// From https://github.com/awslabs/aws-jwt-verify/blob/main/src/safe-json-parse.ts
Expand Down Expand Up @@ -119,12 +120,6 @@ export type CognitoProviderConfig = StrictUnion<
| AuthUserPoolAndIdentityPoolConfig
>;

type UnionKeys<T> = T extends T ? keyof T : never;
type StrictUnionHelper<T, TAll> = T extends any
? T & Partial<Record<Exclude<UnionKeys<TAll>, keyof T>, never>>
: never;
export type StrictUnion<T> = StrictUnionHelper<T, T>;

export interface AuthIdentityPoolConfig {
Cognito: CognitoIdentityPoolConfig & {
userPoolClientId?: never;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/singleton/Auth/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { base64Decoder } from '../../../utils/convert';
import { StrictUnion } from '../../../types';
import {
AuthConfig,
CognitoIdentityPoolConfig,
CognitoUserPoolAndIdentityPoolConfig,
CognitoUserPoolConfig,
JWT,
OAuthConfig,
StrictUnion,
} from '../types';

import { AuthConfigurationErrorCode, assert } from './errorHelpers';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
export * from './core';
export * from './errors';
export * from './storage';
export * from './utils';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit question,
Should these be updated to named exports later on to keep it uniform across all categories

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to it but we do this in various other places as well - including other packages - so I'm not sure this is the right PR to do this in

14 changes: 14 additions & 0 deletions packages/core/src/types/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

type UnionKeys<T> = T extends T ? keyof T : never;

type StrictUnionHelper<T, TAll> = T extends any
? T & Partial<Record<Exclude<UnionKeys<TAll>, keyof T>, never>>
: never;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should we add a comment to explain util function here?

/**
* Makes a union 'strict', such that members are disallowed from including the keys of other members. E.g.,
* `{x: 1, y: 1}` is a valid member of `{x: number} | {y: number}` but not of StrictUnion<{x: number} | {y: number}>.
*/
export type StrictUnion<T> = StrictUnionHelper<T, T>;
2 changes: 1 addition & 1 deletion packages/core/src/utils/WordArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function hexStringify(wordArray: WordArray): string {
return hexChars.join('');
}

export default class WordArray {
export class WordArray {
words: number[] = [];
sigBytes: number;

Expand Down
Loading