From 1681c03df073ea605aa204ba139731f015ab0cd7 Mon Sep 17 00:00:00 2001 From: yicr Date: Mon, 11 Nov 2024 16:59:19 +0900 Subject: [PATCH 1/3] feat!: naming type changed --- src/index.ts | 12 ++++++------ test/naming.test.ts | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9a4126a..2cb20ff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,8 +10,8 @@ import * as crypto from 'crypto'; export namespace ResourceNaming { export enum NamingType { - NO, DEFAULT, + AUTO, CUSTOM, } @@ -20,8 +20,8 @@ export namespace ResourceNaming { // [key: string]: string; // } - export interface NoNaming { - readonly type: NamingType.NO; + export interface AutoNaming { + readonly type: NamingType.AUTO; } export interface DefaultNaming { @@ -72,9 +72,9 @@ export namespace ResourceNaming { switch (resourceNaming.naming.type) { case ResourceNaming.NamingType.CUSTOM: return resourceNaming.naming.names[name as keyof {[key: string]: string}]; - case ResourceNaming.NamingType.DEFAULT: + case ResourceNaming.NamingType.AUTO: return value; - case ResourceNaming.NamingType.NO: + case ResourceNaming.NamingType.DEFAULT: return undefined; } // if (ResourceNaming.isNamingType(resourceNaming.naming.type)) { @@ -98,7 +98,7 @@ export namespace ResourceNaming { } interface NamingOptions { - readonly naming: ResourceNaming.NoNaming | ResourceNaming.DefaultNaming | { + readonly naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming | { readonly type: ResourceNaming.NamingType.CUSTOM; readonly names: {[key: string]: string}; }; diff --git a/test/naming.test.ts b/test/naming.test.ts index dd57b66..e98b6f2 100644 --- a/test/naming.test.ts +++ b/test/naming.test.ts @@ -10,7 +10,7 @@ import { ResourceNaming } from '../src'; //} export interface NamingOptions { - readonly naming: ResourceNaming.NoNaming | ResourceNaming.DefaultNaming | { + readonly naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming | { type: ResourceNaming.NamingType.CUSTOM; names: { functionName: string; @@ -30,10 +30,10 @@ describe('ResouceNaming Testing', () => { // type Names = 'functionName' | 'roleName'; - it('Is Naming Default include Randmon String', () => { + it('Is Naming Auto generate include Randmon String', () => { const options: NamingOptions = { naming: { - type: ResourceNaming.NamingType.DEFAULT, + type: ResourceNaming.NamingType.AUTO, }, }; const naming = ResourceNaming.naming(options, defaultNaming); @@ -42,10 +42,10 @@ describe('ResouceNaming Testing', () => { }); }); - it('Is Naming undefined', () => { + it('Is Naming Default(undefined)', () => { const options: NamingOptions = { naming: { - type: ResourceNaming.NamingType.NO, + type: ResourceNaming.NamingType.DEFAULT, }, }; const naming = ResourceNaming.naming(options, defaultNaming); From 7ba3587701b2a02b605697d2fbf21845a1c414df Mon Sep 17 00:00:00 2001 From: yicr Date: Mon, 11 Nov 2024 17:12:31 +0900 Subject: [PATCH 2/3] feat!: Reversed the order of arguments --- src/index.ts | 7 ++++--- test/naming.test.ts | 26 +++++++++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2cb20ff..9efbd8f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -65,15 +65,16 @@ export namespace ResourceNaming { // } //export function naming(resourceNaming: NamingOptions, defaultNaming: {[p: string]: string | undefined}) { - export function naming(resourceNaming: NamingOptions, defaultNaming: {[p: string]: string}) { + export function naming(autoNaming: {[p: string]: string}, resourceNaming?: NamingOptions) { const names = Object.fromEntries( - Object.entries(defaultNaming).map(([name, value]) => { + Object.entries(autoNaming).map(([name, value]) => { return [name, (() => { - switch (resourceNaming.naming.type) { + switch (resourceNaming?.naming.type) { case ResourceNaming.NamingType.CUSTOM: return resourceNaming.naming.names[name as keyof {[key: string]: string}]; case ResourceNaming.NamingType.AUTO: return value; + default: case ResourceNaming.NamingType.DEFAULT: return undefined; } diff --git a/test/naming.test.ts b/test/naming.test.ts index e98b6f2..a4975e7 100644 --- a/test/naming.test.ts +++ b/test/naming.test.ts @@ -23,7 +23,7 @@ describe('ResouceNaming Testing', () => { const random = ResourceNaming.createRandomString('ResourceName'); - const defaultNaming = { + const autoNaming = { functionName: `${random}-func`, functionRoleName: `${random}-func-exc-role`, }; @@ -36,9 +36,18 @@ describe('ResouceNaming Testing', () => { type: ResourceNaming.NamingType.AUTO, }, }; - const naming = ResourceNaming.naming(options, defaultNaming); + const naming = ResourceNaming.naming(autoNaming, options); expect(naming).toEqual({ - names: defaultNaming, + names: autoNaming, + }); + }); + + it('Is Naming none', () => { + expect(ResourceNaming.naming(autoNaming)).toEqual({ + names: { + functionName: undefined, + roleName: undefined, + }, }); }); @@ -48,13 +57,20 @@ describe('ResouceNaming Testing', () => { type: ResourceNaming.NamingType.DEFAULT, }, }; - const naming = ResourceNaming.naming(options, defaultNaming); + const naming = ResourceNaming.naming(autoNaming, options); expect(naming).toEqual({ names: { functionName: undefined, roleName: undefined, }, }); + // option + expect(ResourceNaming.naming(autoNaming)).toEqual({ + names: { + functionName: undefined, + roleName: undefined, + }, + }); }); it('Is Namings', () => { @@ -67,7 +83,7 @@ describe('ResouceNaming Testing', () => { }, }, }; - const naming = ResourceNaming.naming(options, defaultNaming); + const naming = ResourceNaming.naming(autoNaming, options); expect(naming).toEqual({ names: { functionName: 'example-function', From a96ec9440123361e251a394c728218c1114a8e7b Mon Sep 17 00:00:00 2001 From: yicr Date: Mon, 11 Nov 2024 17:17:12 +0900 Subject: [PATCH 3/3] chore(docs): update auto generated api document --- API.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/API.md b/API.md index 63ef8aa..df76e4c 100644 --- a/API.md +++ b/API.md @@ -3,25 +3,25 @@ ## Structs -### DefaultNaming +### AutoNaming -#### Initializer +#### Initializer ```typescript import { ResourceNaming } from '@gammarers/aws-resource-naming' -const defaultNaming: ResourceNaming.DefaultNaming = { ... } +const autoNaming: ResourceNaming.AutoNaming = { ... } ``` #### Properties | **Name** | **Type** | **Description** | | --- | --- | --- | -| type | @gammarers/aws-resource-naming.ResourceNaming.NamingType | *No description.* | +| type | @gammarers/aws-resource-naming.ResourceNaming.NamingType | *No description.* | --- -##### `type`Required +##### `type`Required ```typescript public readonly type: NamingType; @@ -31,25 +31,25 @@ public readonly type: NamingType; --- -### NoNaming +### DefaultNaming -#### Initializer +#### Initializer ```typescript import { ResourceNaming } from '@gammarers/aws-resource-naming' -const noNaming: ResourceNaming.NoNaming = { ... } +const defaultNaming: ResourceNaming.DefaultNaming = { ... } ``` #### Properties | **Name** | **Type** | **Description** | | --- | --- | --- | -| type | @gammarers/aws-resource-naming.ResourceNaming.NamingType | *No description.* | +| type | @gammarers/aws-resource-naming.ResourceNaming.NamingType | *No description.* | --- -##### `type`Required +##### `type`Required ```typescript public readonly type: NamingType; @@ -69,18 +69,18 @@ public readonly type: NamingType; | **Name** | **Description** | | --- | --- | -| NO | *No description.* | | DEFAULT | *No description.* | +| AUTO | *No description.* | | CUSTOM | *No description.* | --- -##### `NO` +##### `DEFAULT` --- -##### `DEFAULT` +##### `AUTO` ---