Skip to content

Commit

Permalink
chore: Small cleanup to internal core utils (#13140)
Browse files Browse the repository at this point in the history
* chore: Small cleanup to internal core utils

* Update StrictUnion type with description comment
  • Loading branch information
cshfang authored Mar 18, 2024
1 parent 25adcfe commit a254bb6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
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';
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;

/**
* 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

0 comments on commit a254bb6

Please sign in to comment.