From 87530a675f66bfd4552a34255bbe6ac9bee33597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?MJ=E2=98=94?= Date: Tue, 19 Sep 2023 11:19:29 -0700 Subject: [PATCH] chore: update types, use Enum --- .../cli/src/commands/sandbox/sandbox_command.ts | 3 +-- packages/client-config/API.md | 13 ++++++++++--- packages/client-config/src/get_config_path.ts | 12 ++++++++---- packages/sandbox/API.md | 5 ++--- packages/sandbox/src/file_watching_sandbox.test.ts | 7 ++++--- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/commands/sandbox/sandbox_command.ts b/packages/cli/src/commands/sandbox/sandbox_command.ts index 8d8fc8ecf8..cff7fc7d2a 100644 --- a/packages/cli/src/commands/sandbox/sandbox_command.ts +++ b/packages/cli/src/commands/sandbox/sandbox_command.ts @@ -1,11 +1,10 @@ import { ArgumentsCamelCase, Argv, CommandModule } from 'yargs'; +import { formatChoices } from '@aws-amplify/client-config'; import { SandboxDeleteCommand } from './sandbox-delete/sandbox_delete_command.js'; import fs from 'fs'; import { AmplifyPrompter } from '../prompter/amplify_prompts.js'; import { SandboxSingletonFactory } from '@aws-amplify/sandbox'; -export const formatChoices = ['js', 'json', 'ts'] as const; - export type SandboxCommandOptions = { dirToWatch: string | undefined; exclude: string[] | undefined; diff --git a/packages/client-config/API.md b/packages/client-config/API.md index 166c3d6b38..5194ad449b 100644 --- a/packages/client-config/API.md +++ b/packages/client-config/API.md @@ -32,10 +32,17 @@ export type ClientConfig = Partial Promise; @@ -44,7 +51,7 @@ export const generateClientConfig: (credentialProvider: AwsCredentialIdentityPro export const generateClientConfigToFile: (credentialProvider: AwsCredentialIdentityProvider, backendIdentifier: BackendIdentifier, targetPath: string) => Promise; // @public -export const getConfigPath: (out: string | undefined, format?: FormatOption) => string; +export const getConfigPath: (out: string | undefined, format: (typeof formatChoices)[number] | undefined) => string; // @public export type GraphqlClientConfig = { diff --git a/packages/client-config/src/get_config_path.ts b/packages/client-config/src/get_config_path.ts index ad88f32c88..10e6efe65d 100644 --- a/packages/client-config/src/get_config_path.ts +++ b/packages/client-config/src/get_config_path.ts @@ -1,8 +1,12 @@ import path from 'path'; -export const formatChoices = ['js', 'json', 'ts'] as const; export const configFileName = 'amplifyconfiguration'; -export type FormatOption = (typeof formatChoices)[number]; +export enum FormatOption { + JS = 'js', + JSON = 'json', + TS = 'ts', +} +export const formatChoices = Object.values(FormatOption); /** * Get path to config file @@ -12,11 +16,11 @@ export type FormatOption = (typeof formatChoices)[number]; */ export const getConfigPath = ( out: string | undefined, - format: FormatOption = 'js' + format: (typeof formatChoices)[number] | undefined ) => { const defaultArgs = { out: process.cwd(), - format: 'js', + format: FormatOption.JS, }; let targetPath: string; diff --git a/packages/sandbox/API.md b/packages/sandbox/API.md index 2606ca8e48..2bb72b7475 100644 --- a/packages/sandbox/API.md +++ b/packages/sandbox/API.md @@ -4,8 +4,7 @@ ```ts -// @public (undocumented) -export const formatChoices: readonly ["js", "json", "ts"]; +import { formatChoices } from '@aws-amplify/client-config'; // @public export type Sandbox = { @@ -24,7 +23,7 @@ export type SandboxOptions = { dir?: string; exclude?: string[]; name?: string; - format?: (typeof formatChoices)[number]; + format?: typeof formatChoices[number]; profile?: string; clientConfigFilePath?: string; }; diff --git a/packages/sandbox/src/file_watching_sandbox.test.ts b/packages/sandbox/src/file_watching_sandbox.test.ts index f1960fb1d3..d32c88eb2f 100644 --- a/packages/sandbox/src/file_watching_sandbox.test.ts +++ b/packages/sandbox/src/file_watching_sandbox.test.ts @@ -1,5 +1,6 @@ import { afterEach, beforeEach, describe, it, mock } from 'node:test'; import watcher from '@parcel/watcher'; +import { FormatOption } from '@aws-amplify/client-config'; import { FileWatchingSandbox } from './file_watching_sandbox.js'; import assert from 'node:assert'; import { AmplifySandboxExecutor } from './sandbox_executor.js'; @@ -251,7 +252,7 @@ describe('Sandbox with user provided app name', () => { dir: 'testDir', exclude: ['exclude1', 'exclude2'], name: 'customSandboxName', - format: 'ts', + format: FormatOption.TS, clientConfigFilePath: path.join('test', 'location'), }); if ( @@ -370,7 +371,7 @@ describe('Sandbox with absolute output path', () => { dir: 'testDir', exclude: ['exclude1', 'exclude2'], name: 'customSandboxName', - format: 'json', + format: FormatOption.JSON, clientConfigFilePath: path.join('test', 'location'), profile: 'amplify-sandbox', }); @@ -455,7 +456,7 @@ describe('Sandbox ignoring paths in .gitignore', () => { dir: 'testDir', exclude: ['customer_exclude1', 'customer_exclude2'], name: 'customSandboxName', - format: 'ts', + format: FormatOption.TS, clientConfigFilePath: '', }); if (