Skip to content

Commit

Permalink
Merge pull request #13 from gammarers/feature/interface-to-type
Browse files Browse the repository at this point in the history
feat: interface to type
  • Loading branch information
yicr authored Nov 27, 2024
2 parents 061c9a1 + cfba1fb commit 9b27726
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 68 deletions.
57 changes: 0 additions & 57 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ export enum ResourceNamingType {
CUSTOM = 'Custom',
}

export interface ResourceAutoNaming {
export type ResourceAutoNaming = {
readonly type: ResourceNamingType.AUTO;
}

export interface ResourceDefaultNaming {
export type ResourceDefaultNaming = {
readonly type: ResourceNamingType.DEFAULT;
}

export type ResourceNamingOptions =
ResourceAutoNaming | ResourceDefaultNaming | {type: ResourceNamingType.CUSTOM; [key: string]: string};

export namespace ResourceNaming {

//export interface Naming {}
Expand Down Expand Up @@ -82,7 +79,7 @@ export namespace ResourceNaming {
// resourceNaming?: {
// naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming | {type: ResourceNaming.NamingType.CUSTOM; names: {[key: string]: string}};
// }) {
resourceNaming?: ResourceNamingOptions) {
resourceNaming?: ResourceAutoNaming | ResourceDefaultNaming | {type: ResourceNamingType.CUSTOM; [key: string]: string}) {
return Object.fromEntries(
Object.entries(autoNaming).map(([name, value]) => {
return [name, (() => {
Expand Down
15 changes: 10 additions & 5 deletions test/naming.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ResourceNaming, ResourceNamingOptions, ResourceNamingType } from '../src';
import { ResourceAutoNaming, ResourceDefaultNaming, ResourceNaming, ResourceNamingType } from '../src';

//interface Names extends ResourceNaming.Naming {
// readonly functionName: string;
Expand All @@ -18,10 +18,15 @@ describe('ResouceNaming Testing', () => {
functionRoleName: `${random}-func-exc-role`,
};

// type Names = 'functionName' | 'roleName';
type CustomNaming = {
readonly type: ResourceNamingType.CUSTOM;
readonly functionName: 'example-function';
readonly functionRoleName: 'example-role';
}
type ResourceNamingOption = ResourceDefaultNaming | ResourceAutoNaming | CustomNaming;

it('Is Naming Auto generate include Randmon String', () => {
const options: ResourceNamingOptions = {
const options: ResourceNamingOption = {
type: ResourceNamingType.AUTO,
};
const naming = ResourceNaming.naming(autoNaming, options);
Expand All @@ -36,7 +41,7 @@ describe('ResouceNaming Testing', () => {
});

it('Is Naming Default(undefined)', () => {
const options: ResourceNamingOptions = {
const options: ResourceNamingOption = {
type: ResourceNamingType.DEFAULT,
};
const naming = ResourceNaming.naming(autoNaming, options);
Expand All @@ -47,7 +52,7 @@ describe('ResouceNaming Testing', () => {
});

it('Is Namings', () => {
const options: ResourceNamingOptions = {
const options: ResourceNamingOption = {
type: ResourceNamingType.CUSTOM,
functionName: 'example-function',
functionRoleName: 'example-role',
Expand Down

0 comments on commit 9b27726

Please sign in to comment.