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`
---
diff --git a/src/index.ts b/src/index.ts
index 9a4126a..9efbd8f 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 {
@@ -65,16 +65,17 @@ 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.DEFAULT:
+ case ResourceNaming.NamingType.AUTO:
return value;
- case ResourceNaming.NamingType.NO:
+ default:
+ case ResourceNaming.NamingType.DEFAULT:
return undefined;
}
// if (ResourceNaming.isNamingType(resourceNaming.naming.type)) {
@@ -98,7 +99,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..a4975e7 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;
@@ -23,38 +23,54 @@ describe('ResouceNaming Testing', () => {
const random = ResourceNaming.createRandomString('ResourceName');
- const defaultNaming = {
+ const autoNaming = {
functionName: `${random}-func`,
functionRoleName: `${random}-func-exc-role`,
};
// 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);
+ 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,
+ },
});
});
- 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);
+ 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',