From 840bc2a9395990d95b2cbdb4915fbd7265f1daa6 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Fri, 2 Aug 2024 02:32:43 -0700 Subject: [PATCH 1/6] fix: enhance translatedVariableDictionary Signed-off-by: sunrabbit123 --- src/bill/getBillList.ts | 2 +- src/constant/index.ts | 72 +---------- .../translatedVariableDictionary.spec.ts | 98 +++++++++++++++ src/constant/translatedVariableDictionary.ts | 114 ++++++++++++++++++ 4 files changed, 214 insertions(+), 72 deletions(-) create mode 100644 src/constant/translatedVariableDictionary.spec.ts create mode 100644 src/constant/translatedVariableDictionary.ts diff --git a/src/bill/getBillList.ts b/src/bill/getBillList.ts index 9d36dbd..b55cedc 100644 --- a/src/bill/getBillList.ts +++ b/src/bill/getBillList.ts @@ -96,5 +96,5 @@ export const getBillList = async ({ page, take, ...rest }: Argument) => { PROC_DT: rest.resolutionDate, } ); - return res.TVBPMBILL11[1].row.map(transform); + return res[command][1].row.map(transform); }; diff --git a/src/constant/index.ts b/src/constant/index.ts index 4e85c48..5c3bae0 100644 --- a/src/constant/index.ts +++ b/src/constant/index.ts @@ -1,71 +1 @@ -/** - * @description if you modify this properties, you should upgrade the minor version because it will be a break changes - * @ignore `~명`과 같은 이름을 지칭하는 변수의 경우 `Name`으로 끝나야함, 예외적으로 구분명은 `Division`으로 끝남 - * @ignore `~코드`와 같은 이름을 지칭하는 변수의 경우 `Code`로 끝나야함 - * @ignore `~일자`와 같은 이름을 지칭하는 변수의 경우 `Date`로 끝나야함 - * @ignore `~구분`과 같은 이름을 지칭하는 변수의 경우 `Division`으로 끝나야함, 만약 `구분명`이라면 `Division`을 사용 - * @ignore `~처리`과 같은 이름을 지칭하는 변수의 경우 `Process`으로 끝나야함 - * @ignore `~상정`과 같은 이름을 지칭하는 변수의 경우 `Present`으로 끝나야함 - * @ignore `~회부`과 같은 이름을 지칭하는 변수의 경우 `Submit`으로 끝나야함 - * @ignore `~의결`과 같은 이름을 지칭하는 변수의 경우 `Resolution`으로 끝나야함 - */ -export const translatedVariableDictionary = { - 국회의원코드: 'lawmakerCode', - 국회의원명: 'lawmakerName', - 국회의원한자명: 'lawmakerChineseName', - 국회의원영문명: 'lawmakerEnglishName', - 생일구분코드: 'birthdayDivisionCode', - 생일일자: 'birthday', - 직책명: 'dutyName', - 정당명: 'politicalPartyName', - 선거구명: 'electoralDistrictName', - 선거구구분명: 'electoralDistrictDivisionName', - 위원회명: 'committeeName', - 소속위원회명: 'belongingCommitteeName', - 재선구분명: 'reElectionClassificationDivision', - 당선대수: 'electionCongress', - 성별: 'gender', - 전화번호: 'phoneNumber', - 국회의원이메일주소: 'email', - 국회의원홈페이지URL: 'homepage', - 보좌관: 'aide', - 비서관: 'seniorSecretary', - 비서: 'secretary', - 약력: 'profile', - 사무실호실: 'officeRoom', - 사진: 'picture', - - // 의안 관련 추가 - 의안ID: 'billID', - 의안번호: 'billNumber', - 대: 'age', - 의안명: 'billName', - 제안자: 'proposer', - 제안자구분: 'proposerDivision', - 제안일: 'proposeDate', - 소관위코드: 'jurisdictionCommitteeCode', - 소관위: 'jurisdictionCommittee', - 소관위회부일: 'jurisdictionCommitteeSubmitDate', - 위원회심사_처리일: 'committeeReviewProcessDate', - 의안상세정보_URL: 'billDetailUrl', - 대표발의자: 'leadProposer', - 법사위처리결과: 'legislationAndJudiciaryCommitteeProcessResult', - 법사위처리일: 'legislationAndJudiciaryCommitteeProcessDate', - 법사위상정일: 'legislationAndJudiciaryCommitteePresentDate', - 법사위회부일: 'legislationAndJudiciaryCommitteeSubmitDate', - 소관위처리결과: 'jurisdictionCommitteeProcessResult', - 소관위처리일: 'jurisdictionCommitteeProcessDate', - 소관위상정일: 'jurisdictionCommitteePresentDate', - 대표발의자코드: 'leadProposerCode', - 본회의심의결과: 'plenarySessionReviewResult', - 의결일: 'resolutionDate', - 일정_종류: 'scheduleType', - 일정_내용: 'scheduleContent', - 일정_일자: 'scheduleDate', - 일정_시간: 'scheduleTime', - 회의_구분: 'conferenceDivision', - 회의_회기: 'conferenceSession', - 회의_차수: 'conferenceDegree', - 행사_주체자: 'eventInstitution', - 행사_장소: 'eventPlace', -} as const; +export { translatedVariableDictionary } from './translatedVariableDictionary'; diff --git a/src/constant/translatedVariableDictionary.spec.ts b/src/constant/translatedVariableDictionary.spec.ts new file mode 100644 index 0000000..41fa751 --- /dev/null +++ b/src/constant/translatedVariableDictionary.spec.ts @@ -0,0 +1,98 @@ +import { describe, it, expectTypeOf, expect } from 'vitest'; +import { + firstLetterLowerCase, + FirstLetterLowerCase, + MergeString, + translatedVariableDictionary, + variable, +} from './translatedVariableDictionary'; + +describe('MergeString', () => { + it('should merge an array of strings into a single string', () => { + // Test with a single string + expectTypeOf>().toEqualTypeOf<'hello'>(); + + // Test with two strings + expectTypeOf>().toEqualTypeOf<'helloworld'>(); + + // Test with multiple strings + expectTypeOf>().toEqualTypeOf<'helloworld123'>(); + + // Test with an empty array (should never happen) + expectTypeOf>().toEqualTypeOf(); + }); +}); + +describe('FirstLetterLowerCase', () => { + it('should convert the first letter of a string to lowercase', () => { + // Test with an uppercase string + expectTypeOf>().toEqualTypeOf<'hELLO'>(); + + // Test with a mixed-case string + expectTypeOf>().toEqualTypeOf<'helloWorld'>(); + + // Test with a single-letter string + expectTypeOf>().toEqualTypeOf<'a'>(); + + // Test with an empty string (should return the same string) + expectTypeOf>().toEqualTypeOf<''>(); + }); +}); + +describe('firstLetterLowerCase', () => { + it('should convert the first letter of a string to lowercase', () => { + // Test with an uppercase string + expect(firstLetterLowerCase('HELLO')).toBe('hELLO'); + + // Test with a mixed-case string + expect(firstLetterLowerCase('HelloWorld')).toBe('helloWorld'); + + // Test with a single-letter string + expect(firstLetterLowerCase('A')).toBe('a'); + + // Test with an empty string + expect(firstLetterLowerCase('')).toBe(''); + }); +}); + +describe('variable', () => { + it('should merge and format strings correctly', () => { + // Test with a single string + expect(variable`hello`).toBe('hello'); + + // Test with two strings + expect(variable`hello${'world'}`).toBe('helloworld'); + + // Test with multiple strings and formatting + expect(variable`hello${'World'}${'123'}`).toBe('helloWorld123'); + + // Test with an empty template string + expect(variable``).toBe(''); + + // Test with strings that should have their first letter lowercased + expect(variable`Hello${'World'}`).toBe('helloWorld'); + }); +}); + +describe('translatedVariableDictionary', () => { + it('should have correct types', () => { + // Test the type of the entire object + expectTypeOf(translatedVariableDictionary).toEqualTypeOf(); + + // Test the types of individual properties + expectTypeOf(translatedVariableDictionary.국회의원코드).toEqualTypeOf<'lawmakerCode'>(); + expect(translatedVariableDictionary.국회의원코드).toBe('lawmakerCode'); + + expectTypeOf(translatedVariableDictionary.국회의원명).toEqualTypeOf<'lawmakerName'>(); + expect(translatedVariableDictionary.국회의원명).toBe('lawmakerName'); + + expectTypeOf(translatedVariableDictionary.국회의원한자명).toEqualTypeOf<'lawmakerChineseName'>(); + expect(translatedVariableDictionary.국회의원한자명).toBe('lawmakerChineseName'); + + expectTypeOf(translatedVariableDictionary.국회의원영문명).toEqualTypeOf<'lawmakerEnglishName'>(); + expect(translatedVariableDictionary.국회의원영문명).toBe('lawmakerEnglishName'); + + expectTypeOf(translatedVariableDictionary.생일구분코드).toEqualTypeOf<'birthdayDivisionCode'>(); + expect(translatedVariableDictionary.생일구분코드).toBe('birthdayDivisionCode'); + }); +}); diff --git a/src/constant/translatedVariableDictionary.ts b/src/constant/translatedVariableDictionary.ts new file mode 100644 index 0000000..d3bdb6e --- /dev/null +++ b/src/constant/translatedVariableDictionary.ts @@ -0,0 +1,114 @@ +export type MergeString> = T extends [infer Word extends string] + ? `${Word}` + : T extends [infer First extends string, infer Last extends string] + ? `${First}${Last}` + : T extends [infer First extends string, ...infer Rest extends string[]] + ? `${First}${MergeString}` + : never; + +export type FirstLetterLowerCase = T extends `${infer First}${infer Rest}` + ? `${Lowercase}${Rest}` + : T; + +export const firstLetterLowerCase = (str: T) => + `${str.charAt(0).toLowerCase()}${str.slice(1)}` as FirstLetterLowerCase; + +export const variable = >(_template: TemplateStringsArray, ...args: T) => + args.reduce((prev, cur, idx) => { + return idx === 0 ? firstLetterLowerCase(cur) : `${prev}${cur}`; + }, '') as T extends [infer First extends string, ...infer Rest extends ReadonlyArray] + ? MergeString<[FirstLetterLowerCase, ...Rest]> + : MergeString; + +/** + * @description if you modify this properties, you should upgrade the minor version because it will be a break changes + */ + +const 국회의원 = 'Lawmaker'; +const 코드 = 'Code'; +const 명 = 'Name'; +const 한자명 = `Chinese${명}`; +const 영문명 = `English${명}`; +const 구분 = 'Division'; +const 구분명 = `${구분}`; +const 생일 = 'Birthday'; +const 직책 = 'Duty'; +const 정당 = 'PoliticalParty'; +const 선거구 = 'ElectoralDistrict'; +const 위원회 = 'Committee'; +const 소속위원회 = 'BelongingCommittee'; +const 선거 = 'Election'; +const 재선 = `Re${선거}`; +const 의안 = `Bill`; +const 번호 = 'Number'; +const 제안자 = 'Proposer'; +const 대표발의자 = `Lead${제안자}`; +const 소관위원회 = `Jurisdiction${위원회}`; +const 법제사법위원회 = `LegislationAndJudiciary${위원회}`; +const 처리 = 'Process'; +const 일자 = `Date`; +const 처리결과 = `${처리}Result`; +const 처리일 = `${처리}${일자}`; +const 회부일 = `Submit${일자}`; +const 상정일 = `Present${일자}`; + +export const translatedVariableDictionary = { + 국회의원코드: variable`${국회의원}${코드}`, + 국회의원명: variable`${국회의원}${명}`, + 국회의원한자명: variable`${국회의원}${한자명}`, + 국회의원영문명: variable`${국회의원}${영문명}`, + 생일구분코드: variable`${생일}${구분}${코드}`, + 생일일자: variable`${생일}`, + 직책명: variable`${직책}${명}`, + 정당명: variable`${정당}${명}`, + 선거구명: variable`${선거구}${명}`, + 선거구구분명: variable`${선거구}${구분명}`, + 위원회명: variable`${위원회}${명}`, + 소속위원회명: variable`${소속위원회}${명}`, + 재선구분명: variable`${재선}${구분명}`, + 당선대수: variable`${선거}Congress`, + 성별: 'gender', + 전화번호: 'phoneNumber', + 국회의원이메일주소: 'email', + 국회의원홈페이지URL: 'homepage', + 보좌관: 'aide', + 비서관: 'seniorSecretary', + 비서: 'secretary', + 약력: 'profile', + 사무실호실: 'officeRoom', + 사진: 'picture', + + 의안ID: variable`${의안}ID`, + 의안번호: variable`${의안}${번호}`, + 대: 'age', + 의안명: variable`${의안}${명}`, + 제안자, + 제안자구분: variable`${제안자}${구분}`, + 제안일: 'proposeDate', + 소관위코드: variable`${소관위원회}${코드}`, + 소관위: variable`${소관위원회}`, + 소관위회부일: variable`${소관위원회}${회부일}`, + 위원회심사_처리일: `${위원회}Review${처리일}`, + 의안상세정보_URL: variable`${의안}DetailUrl`, + 대표발의자: variable`${대표발의자}`, + 법사위처리결과: variable`${법제사법위원회}${처리결과}`, + 법사위처리일: variable`${법제사법위원회}${처리일}`, + 법사위상정일: variable`${법제사법위원회}${상정일}`, + 법사위회부일: variable`${법제사법위원회}${회부일}`, + 소관위처리결과: variable`${소관위원회}${처리결과}`, + 소관위처리일: variable`${소관위원회}${처리일}`, + 소관위상정일: variable`${소관위원회}${상정일}`, + 대표발의자코드: variable`${대표발의자}${코드}`, + 본회의심의결과: 'plenarySessionReviewResult', + 의결일: 'resolutionDate', + + 일정_종류: 'scheduleType', + 일정_내용: 'scheduleContent', + 일정_일자: 'scheduleDate', + 일정_시간: 'scheduleTime', + 회의_구분: 'conferenceDivision', + 회의_회기: 'conferenceSession', + 회의_차수: 'conferenceDegree', + 행사_주체자: 'eventInstitution', + 행사_장소: 'eventPlace', +} as const; From 108621f6fde7e54e92d6e782ea015cb2fb645e16 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Mon, 5 Aug 2024 02:54:27 -0700 Subject: [PATCH 2/6] fix Signed-off-by: sunrabbit123 --- src/bill/index.spec.ts | 9 ------- .../translatedVariableDictionary.spec.ts | 6 +++++ src/constant/translatedVariableDictionary.ts | 24 +++++++++++++++---- src/lawmaker/getLawmakerList.ts | 2 +- 4 files changed, 26 insertions(+), 15 deletions(-) delete mode 100644 src/bill/index.spec.ts diff --git a/src/bill/index.spec.ts b/src/bill/index.spec.ts deleted file mode 100644 index 46c7995..0000000 --- a/src/bill/index.spec.ts +++ /dev/null @@ -1,9 +0,0 @@ -// src/bill/index.spec.ts -import { describe, it, expect } from 'vitest'; -import { getBillList } from './index'; - -describe('bill index.ts', () => { - it('should export getBillList', () => { - expect(getBillList).toBeDefined(); - }); -}); diff --git a/src/constant/translatedVariableDictionary.spec.ts b/src/constant/translatedVariableDictionary.spec.ts index 41fa751..bd3d011 100644 --- a/src/constant/translatedVariableDictionary.spec.ts +++ b/src/constant/translatedVariableDictionary.spec.ts @@ -94,5 +94,11 @@ describe('translatedVariableDictionary', () => { expectTypeOf(translatedVariableDictionary.생일구분코드).toEqualTypeOf<'birthdayDivisionCode'>(); expect(translatedVariableDictionary.생일구분코드).toBe('birthdayDivisionCode'); + + expectTypeOf(translatedVariableDictionary.당선대수).toEqualTypeOf<'electionCongress'>(); + expect(translatedVariableDictionary.당선대수).toBe('electionCongress'); + + expectTypeOf(translatedVariableDictionary.위원회심사_처리일).toEqualTypeOf<'committeeReviewProcessDate'>(); + expect(translatedVariableDictionary.위원회심사_처리일).toBe('committeeReviewProcessDate'); }); }); diff --git a/src/constant/translatedVariableDictionary.ts b/src/constant/translatedVariableDictionary.ts index d3bdb6e..24177ff 100644 --- a/src/constant/translatedVariableDictionary.ts +++ b/src/constant/translatedVariableDictionary.ts @@ -10,16 +10,30 @@ export type FirstLetterLowerCase = T extends `${infer First}${ ? `${Lowercase}${Rest}` : T; +const isEmpty = (args?: string): args is '' | undefined => args === '' || args == null; + export const firstLetterLowerCase = (str: T) => `${str.charAt(0).toLowerCase()}${str.slice(1)}` as FirstLetterLowerCase; -export const variable = >(_template: TemplateStringsArray, ...args: T) => - args.reduce((prev, cur, idx) => { - return idx === 0 ? firstLetterLowerCase(cur) : `${prev}${cur}`; - }, '') as T extends [infer First extends string, ...infer Rest extends ReadonlyArray] +export const variable = >(_template: TemplateStringsArray, ...args: T) => { + return (args.reduce((prev, cur, idx) => { + if (idx !== 0) { + return `${prev}${_template[idx]}${cur}`; + } + const prefix = _template[idx]; + + if (isEmpty(prefix)) { + return `${prev}${firstLetterLowerCase(cur)}`; + } + + return `${prev}${firstLetterLowerCase(prefix)}${cur}`; + }, '') + _template[args.length]) as T extends [ + infer First extends string, + ...infer Rest extends ReadonlyArray, + ] ? MergeString<[FirstLetterLowerCase, ...Rest]> : MergeString; - +}; /** * @description if you modify this properties, you should upgrade the minor version because it will be a break changes */ diff --git a/src/lawmaker/getLawmakerList.ts b/src/lawmaker/getLawmakerList.ts index f4c1e4e..8542c6c 100644 --- a/src/lawmaker/getLawmakerList.ts +++ b/src/lawmaker/getLawmakerList.ts @@ -1,6 +1,6 @@ import { callOpenApi } from '../functional'; import { PaginationType } from '../types/callOpenApi'; -import { translatedVariableDictionary } from '../constant/index'; +import { translatedVariableDictionary } from '../constant'; interface Lawmaker { NAAS_CD: string; // 국회의원코드 From 24d7fe8520799be87ecb175fca9b321e194ec755 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Wed, 7 Aug 2024 00:28:27 -0700 Subject: [PATCH 3/6] refactor: enhance translated dictionary Signed-off-by: sunrabbit123 --- package.json | 1 + .../translatedVariableDictionary.spec.ts | 86 +++----- src/constant/translatedVariableDictionary.ts | 184 ++++++++---------- yarn.lock | 8 + 4 files changed, 113 insertions(+), 166 deletions(-) diff --git a/package.json b/package.json index 26c7228..a328787 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "eslint": "^9.7.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-jsdoc": "^48.7.0", + "hotscript": "^1.0.13", "prettier": "^3.3.3", "tsup": "^8.2.3", "typescript": "^5.5.3", diff --git a/src/constant/translatedVariableDictionary.spec.ts b/src/constant/translatedVariableDictionary.spec.ts index bd3d011..ee9c36a 100644 --- a/src/constant/translatedVariableDictionary.spec.ts +++ b/src/constant/translatedVariableDictionary.spec.ts @@ -1,76 +1,34 @@ import { describe, it, expectTypeOf, expect } from 'vitest'; -import { - firstLetterLowerCase, - FirstLetterLowerCase, - MergeString, - translatedVariableDictionary, - variable, -} from './translatedVariableDictionary'; +import { translatedVariableDictionary, variable } from './translatedVariableDictionary'; +import * as H from 'hotscript'; -describe('MergeString', () => { - it('should merge an array of strings into a single string', () => { - // Test with a single string - expectTypeOf>().toEqualTypeOf<'hello'>(); - - // Test with two strings - expectTypeOf>().toEqualTypeOf<'helloworld'>(); - - // Test with multiple strings - expectTypeOf>().toEqualTypeOf<'helloworld123'>(); - - // Test with an empty array (should never happen) - expectTypeOf>().toEqualTypeOf(); +describe('variable function', () => { + it('should return correct variable name for single argument', () => { + const result = variable('test'); + expect(result).toBe('test'); }); -}); -describe('FirstLetterLowerCase', () => { - it('should convert the first letter of a string to lowercase', () => { - // Test with an uppercase string - expectTypeOf>().toEqualTypeOf<'hELLO'>(); - - // Test with a mixed-case string - expectTypeOf>().toEqualTypeOf<'helloWorld'>(); - - // Test with a single-letter string - expectTypeOf>().toEqualTypeOf<'a'>(); - - // Test with an empty string (should return the same string) - expectTypeOf>().toEqualTypeOf<''>(); + it('should return correct variable name for multiple arguments', () => { + const result = variable('foo', 'bar', 'baz'); + expect(result).toBe('fooBarBaz'); }); -}); -describe('firstLetterLowerCase', () => { - it('should convert the first letter of a string to lowercase', () => { - // Test with an uppercase string - expect(firstLetterLowerCase('HELLO')).toBe('hELLO'); - - // Test with a mixed-case string - expect(firstLetterLowerCase('HelloWorld')).toBe('helloWorld'); - - // Test with a single-letter string - expect(firstLetterLowerCase('A')).toBe('a'); - - // Test with an empty string - expect(firstLetterLowerCase('')).toBe(''); + it('should handle string arguments correctly', () => { + const result = variable('Hello', 'World'); + expect(result).toBe('helloWorld'); }); -}); -describe('variable', () => { - it('should merge and format strings correctly', () => { - // Test with a single string - expect(variable`hello`).toBe('hello'); - - // Test with two strings - expect(variable`hello${'world'}`).toBe('helloworld'); - - // Test with multiple strings and formatting - expect(variable`hello${'World'}${'123'}`).toBe('helloWorld123'); - - // Test with an empty template string - expect(variable``).toBe(''); + it('should return correct type for single argument', () => { + const result: H.Call = variable('test'); + expect(typeof result).toBe('string'); + }); - // Test with strings that should have their first letter lowercased - expect(variable`Hello${'World'}`).toBe('helloWorld'); + it('should return correct type for multiple arguments', () => { + const result: H.Pipe< + ['foo', 'bar', 'baz'], + [H.Tuples.Map, H.Tuples.Join<''>, H.Strings.Uncapitalize] + > = variable('foo', 'bar', 'baz'); + expect(typeof result).toBe('string'); }); }); diff --git a/src/constant/translatedVariableDictionary.ts b/src/constant/translatedVariableDictionary.ts index 24177ff..fae9493 100644 --- a/src/constant/translatedVariableDictionary.ts +++ b/src/constant/translatedVariableDictionary.ts @@ -1,86 +1,66 @@ -export type MergeString> = T extends [infer Word extends string] - ? `${Word}` - : T extends [infer First extends string, infer Last extends string] - ? `${First}${Last}` - : T extends [infer First extends string, ...infer Rest extends string[]] - ? `${First}${MergeString}` - : never; +import * as H from 'hotscript'; -export type FirstLetterLowerCase = T extends `${infer First}${infer Rest}` - ? `${Lowercase}${Rest}` - : T; - -const isEmpty = (args?: string): args is '' | undefined => args === '' || args == null; - -export const firstLetterLowerCase = (str: T) => - `${str.charAt(0).toLowerCase()}${str.slice(1)}` as FirstLetterLowerCase; - -export const variable = >(_template: TemplateStringsArray, ...args: T) => { - return (args.reduce((prev, cur, idx) => { - if (idx !== 0) { - return `${prev}${_template[idx]}${cur}`; - } - const prefix = _template[idx]; - - if (isEmpty(prefix)) { - return `${prev}${firstLetterLowerCase(cur)}`; - } - - return `${prev}${firstLetterLowerCase(prefix)}${cur}`; - }, '') + _template[args.length]) as T extends [ - infer First extends string, - ...infer Rest extends ReadonlyArray, - ] - ? MergeString<[FirstLetterLowerCase, ...Rest]> - : MergeString; -}; /** * @description if you modify this properties, you should upgrade the minor version because it will be a break changes */ -const 국회의원 = 'Lawmaker'; -const 코드 = 'Code'; -const 명 = 'Name'; -const 한자명 = `Chinese${명}`; -const 영문명 = `English${명}`; -const 구분 = 'Division'; +export const variable = >(...args: Args) => + args.reduce( + (prev, cur, idx) => + idx === 0 + ? `${cur.charAt(0).toLowerCase()}${cur.slice(1)}` + : `${prev}${cur.charAt(0).toUpperCase()}${cur.slice(1)}`, + '' + ) as H.Pipe, H.Tuples.Join<''>, H.Strings.Uncapitalize]>; + +const 국회의원 = 'lawmaker'; +const 코드 = 'code'; +const 명 = 'name'; +const 한자명 = variable(`chinese`, 명); +const 영문명 = variable(`english`, 명); +const 구분 = 'division'; const 구분명 = `${구분}`; -const 생일 = 'Birthday'; -const 직책 = 'Duty'; -const 정당 = 'PoliticalParty'; -const 선거구 = 'ElectoralDistrict'; -const 위원회 = 'Committee'; -const 소속위원회 = 'BelongingCommittee'; -const 선거 = 'Election'; -const 재선 = `Re${선거}`; -const 의안 = `Bill`; -const 번호 = 'Number'; -const 제안자 = 'Proposer'; -const 대표발의자 = `Lead${제안자}`; -const 소관위원회 = `Jurisdiction${위원회}`; -const 법제사법위원회 = `LegislationAndJudiciary${위원회}`; -const 처리 = 'Process'; -const 일자 = `Date`; -const 처리결과 = `${처리}Result`; -const 처리일 = `${처리}${일자}`; -const 회부일 = `Submit${일자}`; -const 상정일 = `Present${일자}`; +const 생일 = 'birthday'; +const 직책 = 'duty'; +const 정당 = 'politicalParty'; +const 선거구 = 'electoralDistrict'; +const 위원회 = 'committee'; +const 소속위원회 = 'belongingCommittee'; +const 선거 = 'election'; +const 재선 = variable(`re`, 선거); +const 의안 = `bill`; +const 번호 = 'number'; +const 제안자 = 'proposer'; +const 대표발의자 = variable(`lead`, 제안자); +const 소관위원회 = variable(`jurisdiction`, 위원회); +const 법제사법위원회 = variable(`legislationAndJudiciary`, 위원회); +const 처리 = 'process'; +const 일자 = `date`; +const 처리결과 = variable(처리, `result`); +const 처리일 = variable(처리, 일자); +const 회부일 = variable(`submit`, 일자); +const 상정일 = variable(`present`, 일자); + +const 일정 = 'schedule'; +const 시간 = 'time'; +const 회의 = 'conference'; +const 행사 = 'event;'; export const translatedVariableDictionary = { - 국회의원코드: variable`${국회의원}${코드}`, - 국회의원명: variable`${국회의원}${명}`, - 국회의원한자명: variable`${국회의원}${한자명}`, - 국회의원영문명: variable`${국회의원}${영문명}`, - 생일구분코드: variable`${생일}${구분}${코드}`, - 생일일자: variable`${생일}`, - 직책명: variable`${직책}${명}`, - 정당명: variable`${정당}${명}`, - 선거구명: variable`${선거구}${명}`, - 선거구구분명: variable`${선거구}${구분명}`, - 위원회명: variable`${위원회}${명}`, - 소속위원회명: variable`${소속위원회}${명}`, - 재선구분명: variable`${재선}${구분명}`, - 당선대수: variable`${선거}Congress`, + 국회의원코드: variable(국회의원, 코드), + 국회의원명: variable(국회의원, 명), + 국회의원한자명: variable(국회의원, 한자명), + 국회의원영문명: variable(국회의원, 영문명), + 생일구분코드: variable(생일, 구분, 코드), + 생일일자: variable(생일), + 직책명: variable(직책, 명), + 정당명: variable(정당, 명), + 선거구명: variable(선거구, 명), + 선거구구분명: variable(선거구, 구분명), + 위원회명: variable(위원회, 명), + 소속위원회명: variable(소속위원회, 명), + 재선구분명: variable(재선, 구분명), + 당선대수: variable(선거, 'congress'), 성별: 'gender', 전화번호: 'phoneNumber', 국회의원이메일주소: 'email', @@ -92,37 +72,37 @@ export const translatedVariableDictionary = { 사무실호실: 'officeRoom', 사진: 'picture', - 의안ID: variable`${의안}ID`, - 의안번호: variable`${의안}${번호}`, + 의안ID: variable(의안, 'ID'), + 의안번호: variable(의안, 번호), 대: 'age', - 의안명: variable`${의안}${명}`, + 의안명: variable(의안, 명), 제안자, - 제안자구분: variable`${제안자}${구분}`, + 제안자구분: variable(제안자, 구분), 제안일: 'proposeDate', - 소관위코드: variable`${소관위원회}${코드}`, - 소관위: variable`${소관위원회}`, - 소관위회부일: variable`${소관위원회}${회부일}`, - 위원회심사_처리일: `${위원회}Review${처리일}`, - 의안상세정보_URL: variable`${의안}DetailUrl`, - 대표발의자: variable`${대표발의자}`, - 법사위처리결과: variable`${법제사법위원회}${처리결과}`, - 법사위처리일: variable`${법제사법위원회}${처리일}`, - 법사위상정일: variable`${법제사법위원회}${상정일}`, - 법사위회부일: variable`${법제사법위원회}${회부일}`, - 소관위처리결과: variable`${소관위원회}${처리결과}`, - 소관위처리일: variable`${소관위원회}${처리일}`, - 소관위상정일: variable`${소관위원회}${상정일}`, - 대표발의자코드: variable`${대표발의자}${코드}`, + 소관위코드: variable(소관위원회, 코드), + 소관위: variable(소관위원회), + 소관위회부일: variable(소관위원회, 회부일), + 위원회심사_처리일: variable(위원회, 'review', 처리일), + 의안상세정보_URL: variable(의안, 'detailUrl'), + 대표발의자: variable(대표발의자), + 법사위처리결과: variable(법제사법위원회, 처리결과), + 법사위처리일: variable(법제사법위원회, 처리일), + 법사위상정일: variable(법제사법위원회, 상정일), + 법사위회부일: variable(법제사법위원회, 회부일), + 소관위처리결과: variable(소관위원회, 처리결과), + 소관위처리일: variable(소관위원회, 처리일), + 소관위상정일: variable(소관위원회, 상정일), + 대표발의자코드: variable(대표발의자, 코드), 본회의심의결과: 'plenarySessionReviewResult', 의결일: 'resolutionDate', - 일정_종류: 'scheduleType', - 일정_내용: 'scheduleContent', - 일정_일자: 'scheduleDate', - 일정_시간: 'scheduleTime', - 회의_구분: 'conferenceDivision', - 회의_회기: 'conferenceSession', - 회의_차수: 'conferenceDegree', - 행사_주체자: 'eventInstitution', - 행사_장소: 'eventPlace', + 일정_종류: variable(일정, 'type'), + 일정_내용: variable(일정, 'content'), + 일정_일자: variable(일정, 일자), + 일정_시간: variable(일정, 시간), + 회의_구분: variable(회의, 구분), + 회의_회기: variable(회의, 'session'), + 회의_차수: variable(회의, 'degree'), + 행사_주체자: variable(행사, 'institution'), + 행사_장소: variable(행사, 'place'), } as const; diff --git a/yarn.lock b/yarn.lock index fb9543b..bcfb01f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1218,6 +1218,7 @@ __metadata: eslint: "npm:^9.7.0" eslint-config-prettier: "npm:^9.1.0" eslint-plugin-jsdoc: "npm:^48.7.0" + hotscript: "npm:^1.0.13" prettier: "npm:^3.3.3" tsup: "npm:^8.2.3" typescript: "npm:^5.5.3" @@ -2215,6 +2216,13 @@ __metadata: languageName: node linkType: hard +"hotscript@npm:^1.0.13": + version: 1.0.13 + resolution: "hotscript@npm:1.0.13" + checksum: 10c0/423ea2aa437befeeffc32ea5a364b0d833f442fecdd7531c6fe8dc3df092c58d31145f757ad505ec7629ce4bb0eb8ff58889c8a58fe36312f975ff682f5cd422 + languageName: node + linkType: hard + "html-escaper@npm:^2.0.0": version: 2.0.2 resolution: "html-escaper@npm:2.0.2" From f0e532d864ea6125a4cf87fc2d7ae9a9a03a5447 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Wed, 7 Aug 2024 00:44:51 -0700 Subject: [PATCH 4/6] fix: typo Signed-off-by: sunrabbit123 --- src/constant/translatedVariableDictionary.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constant/translatedVariableDictionary.ts b/src/constant/translatedVariableDictionary.ts index fae9493..91613ab 100644 --- a/src/constant/translatedVariableDictionary.ts +++ b/src/constant/translatedVariableDictionary.ts @@ -44,7 +44,7 @@ const 상정일 = variable(`present`, 일자); const 일정 = 'schedule'; const 시간 = 'time'; const 회의 = 'conference'; -const 행사 = 'event;'; +const 행사 = 'event'; export const translatedVariableDictionary = { 국회의원코드: variable(국회의원, 코드), From 1b6f6fd5a1838cc415bd0a58e6e86bb89aaf9984 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Thu, 8 Aug 2024 18:48:29 -0700 Subject: [PATCH 5/6] fix: enhance translatedVariableDictionary Signed-off-by: sunrabbit123 --- src/bill/getBillList.ts | 72 ++++++++---- src/constant/index.ts | 2 +- .../translatedVariableDictionary.spec.ts | 62 ---------- src/constant/translatedVariableDictionary.ts | 108 ------------------ .../translatedVariableDictionary/index.ts | 95 +++++++++++++++ .../translatedVariableDictionary.spec.ts | 69 +++++++++++ .../translatedVariableDictionary/variable.ts | 10 ++ src/lawmaker/getLawmakerList.ts | 75 ++++++++---- .../getNationalAssemblySchedule.ts | 33 ++++-- 9 files changed, 295 insertions(+), 231 deletions(-) delete mode 100644 src/constant/translatedVariableDictionary.spec.ts delete mode 100644 src/constant/translatedVariableDictionary.ts create mode 100644 src/constant/translatedVariableDictionary/index.ts create mode 100644 src/constant/translatedVariableDictionary/translatedVariableDictionary.spec.ts create mode 100644 src/constant/translatedVariableDictionary/variable.ts diff --git a/src/bill/getBillList.ts b/src/bill/getBillList.ts index b55cedc..9d9904b 100644 --- a/src/bill/getBillList.ts +++ b/src/bill/getBillList.ts @@ -1,6 +1,30 @@ import { callOpenApi } from '../functional'; import { PaginationType } from '../types/callOpenApi'; -import { translatedVariableDictionary } from '../constant'; +import { + 대, + 대표발의자, + 대표발의자코드, + 법사위상정일, + 법사위처리결과, + 법사위처리일, + 법사위회부일, + 본회의심의결과, + 소관위, + 소관위상정일, + 소관위처리결과, + 소관위처리일, + 소관위코드, + 소관위회부일, + 위원회심사_처리일, + 의결일, + 의안ID, + 의안명, + 의안번호, + 의안상세정보_URL, + 제안일, + 제안자, + 제안자구분, +} from '../constant'; // https://open.assembly.go.kr/portal/data/service/selectAPIServicePage.do/O4K6HM0012064I15889 // 법률안 심사 및 처리(의안검색) 구현 @@ -51,29 +75,29 @@ type Argument = { const command = 'TVBPMBILL11'; const transform = (v: Row) => ({ - [translatedVariableDictionary['의안ID']]: v.BILL_ID, - [translatedVariableDictionary['의안번호']]: v.BILL_NO, - [translatedVariableDictionary['대']]: v.AGE, - [translatedVariableDictionary['의안명']]: v.BILL_NAME, - [translatedVariableDictionary['제안자']]: v.PROPOSER, - [translatedVariableDictionary['제안자구분']]: v.PROPOSER_KIND, - [translatedVariableDictionary['제안일']]: v.PROPOSE_DT, - [translatedVariableDictionary['소관위코드']]: v.CURR_COMMITTEE_ID, - [translatedVariableDictionary['소관위']]: v.CURR_COMMITTEE, - [translatedVariableDictionary['소관위회부일']]: v.COMMITTEE_DT, - [translatedVariableDictionary['위원회심사_처리일']]: v.COMMITTEE_PROC_DT, - [translatedVariableDictionary['의안상세정보_URL']]: v.LINK_URL, - [translatedVariableDictionary['대표발의자']]: v.RST_PROPOSER, - [translatedVariableDictionary['법사위처리결과']]: v.LAW_PROC_RESULT_CD, - [translatedVariableDictionary['법사위처리일']]: v.LAW_PROC_DT, - [translatedVariableDictionary['법사위상정일']]: v.LAW_PRESENT_DT, - [translatedVariableDictionary['법사위회부일']]: v.LAW_SUBMIT_DT, - [translatedVariableDictionary['소관위처리결과']]: v.CMT_PROC_RESULT_CD, - [translatedVariableDictionary['소관위처리일']]: v.CMT_PROC_DT, - [translatedVariableDictionary['소관위상정일']]: v.CMT_PRESENT_DT, - [translatedVariableDictionary['대표발의자코드']]: v.RST_MONA_CD, - [translatedVariableDictionary['본회의심의결과']]: v.PROC_RESULT_CD, - [translatedVariableDictionary['의결일']]: v.PROC_DT, + [의안ID]: v.BILL_ID, + [의안번호]: v.BILL_NO, + [대]: v.AGE, + [의안명]: v.BILL_NAME, + [제안자]: v.PROPOSER, + [제안자구분]: v.PROPOSER_KIND, + [제안일]: v.PROPOSE_DT, + [소관위코드]: v.CURR_COMMITTEE_ID, + [소관위]: v.CURR_COMMITTEE, + [소관위회부일]: v.COMMITTEE_DT, + [위원회심사_처리일]: v.COMMITTEE_PROC_DT, + [의안상세정보_URL]: v.LINK_URL, + [대표발의자]: v.RST_PROPOSER, + [법사위처리결과]: v.LAW_PROC_RESULT_CD, + [법사위처리일]: v.LAW_PROC_DT, + [법사위상정일]: v.LAW_PRESENT_DT, + [법사위회부일]: v.LAW_SUBMIT_DT, + [소관위처리결과]: v.CMT_PROC_RESULT_CD, + [소관위처리일]: v.CMT_PROC_DT, + [소관위상정일]: v.CMT_PRESENT_DT, + [대표발의자코드]: v.RST_MONA_CD, + [본회의심의결과]: v.PROC_RESULT_CD, + [의결일]: v.PROC_DT, }); /** diff --git a/src/constant/index.ts b/src/constant/index.ts index 5c3bae0..e6ce9b0 100644 --- a/src/constant/index.ts +++ b/src/constant/index.ts @@ -1 +1 @@ -export { translatedVariableDictionary } from './translatedVariableDictionary'; +export * from './translatedVariableDictionary'; diff --git a/src/constant/translatedVariableDictionary.spec.ts b/src/constant/translatedVariableDictionary.spec.ts deleted file mode 100644 index ee9c36a..0000000 --- a/src/constant/translatedVariableDictionary.spec.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { describe, it, expectTypeOf, expect } from 'vitest'; -import { translatedVariableDictionary, variable } from './translatedVariableDictionary'; -import * as H from 'hotscript'; - -describe('variable function', () => { - it('should return correct variable name for single argument', () => { - const result = variable('test'); - expect(result).toBe('test'); - }); - - it('should return correct variable name for multiple arguments', () => { - const result = variable('foo', 'bar', 'baz'); - expect(result).toBe('fooBarBaz'); - }); - - it('should handle string arguments correctly', () => { - const result = variable('Hello', 'World'); - expect(result).toBe('helloWorld'); - }); - - it('should return correct type for single argument', () => { - const result: H.Call = variable('test'); - expect(typeof result).toBe('string'); - }); - - it('should return correct type for multiple arguments', () => { - const result: H.Pipe< - ['foo', 'bar', 'baz'], - [H.Tuples.Map, H.Tuples.Join<''>, H.Strings.Uncapitalize] - > = variable('foo', 'bar', 'baz'); - expect(typeof result).toBe('string'); - }); -}); - -describe('translatedVariableDictionary', () => { - it('should have correct types', () => { - // Test the type of the entire object - expectTypeOf(translatedVariableDictionary).toEqualTypeOf(); - - // Test the types of individual properties - expectTypeOf(translatedVariableDictionary.국회의원코드).toEqualTypeOf<'lawmakerCode'>(); - expect(translatedVariableDictionary.국회의원코드).toBe('lawmakerCode'); - - expectTypeOf(translatedVariableDictionary.국회의원명).toEqualTypeOf<'lawmakerName'>(); - expect(translatedVariableDictionary.국회의원명).toBe('lawmakerName'); - - expectTypeOf(translatedVariableDictionary.국회의원한자명).toEqualTypeOf<'lawmakerChineseName'>(); - expect(translatedVariableDictionary.국회의원한자명).toBe('lawmakerChineseName'); - - expectTypeOf(translatedVariableDictionary.국회의원영문명).toEqualTypeOf<'lawmakerEnglishName'>(); - expect(translatedVariableDictionary.국회의원영문명).toBe('lawmakerEnglishName'); - - expectTypeOf(translatedVariableDictionary.생일구분코드).toEqualTypeOf<'birthdayDivisionCode'>(); - expect(translatedVariableDictionary.생일구분코드).toBe('birthdayDivisionCode'); - - expectTypeOf(translatedVariableDictionary.당선대수).toEqualTypeOf<'electionCongress'>(); - expect(translatedVariableDictionary.당선대수).toBe('electionCongress'); - - expectTypeOf(translatedVariableDictionary.위원회심사_처리일).toEqualTypeOf<'committeeReviewProcessDate'>(); - expect(translatedVariableDictionary.위원회심사_처리일).toBe('committeeReviewProcessDate'); - }); -}); diff --git a/src/constant/translatedVariableDictionary.ts b/src/constant/translatedVariableDictionary.ts deleted file mode 100644 index 91613ab..0000000 --- a/src/constant/translatedVariableDictionary.ts +++ /dev/null @@ -1,108 +0,0 @@ -import * as H from 'hotscript'; - -/** - * @description if you modify this properties, you should upgrade the minor version because it will be a break changes - */ - -export const variable = >(...args: Args) => - args.reduce( - (prev, cur, idx) => - idx === 0 - ? `${cur.charAt(0).toLowerCase()}${cur.slice(1)}` - : `${prev}${cur.charAt(0).toUpperCase()}${cur.slice(1)}`, - '' - ) as H.Pipe, H.Tuples.Join<''>, H.Strings.Uncapitalize]>; - -const 국회의원 = 'lawmaker'; -const 코드 = 'code'; -const 명 = 'name'; -const 한자명 = variable(`chinese`, 명); -const 영문명 = variable(`english`, 명); -const 구분 = 'division'; -const 구분명 = `${구분}`; -const 생일 = 'birthday'; -const 직책 = 'duty'; -const 정당 = 'politicalParty'; -const 선거구 = 'electoralDistrict'; -const 위원회 = 'committee'; -const 소속위원회 = 'belongingCommittee'; -const 선거 = 'election'; -const 재선 = variable(`re`, 선거); -const 의안 = `bill`; -const 번호 = 'number'; -const 제안자 = 'proposer'; -const 대표발의자 = variable(`lead`, 제안자); -const 소관위원회 = variable(`jurisdiction`, 위원회); -const 법제사법위원회 = variable(`legislationAndJudiciary`, 위원회); -const 처리 = 'process'; -const 일자 = `date`; -const 처리결과 = variable(처리, `result`); -const 처리일 = variable(처리, 일자); -const 회부일 = variable(`submit`, 일자); -const 상정일 = variable(`present`, 일자); - -const 일정 = 'schedule'; -const 시간 = 'time'; -const 회의 = 'conference'; -const 행사 = 'event'; - -export const translatedVariableDictionary = { - 국회의원코드: variable(국회의원, 코드), - 국회의원명: variable(국회의원, 명), - 국회의원한자명: variable(국회의원, 한자명), - 국회의원영문명: variable(국회의원, 영문명), - 생일구분코드: variable(생일, 구분, 코드), - 생일일자: variable(생일), - 직책명: variable(직책, 명), - 정당명: variable(정당, 명), - 선거구명: variable(선거구, 명), - 선거구구분명: variable(선거구, 구분명), - 위원회명: variable(위원회, 명), - 소속위원회명: variable(소속위원회, 명), - 재선구분명: variable(재선, 구분명), - 당선대수: variable(선거, 'congress'), - 성별: 'gender', - 전화번호: 'phoneNumber', - 국회의원이메일주소: 'email', - 국회의원홈페이지URL: 'homepage', - 보좌관: 'aide', - 비서관: 'seniorSecretary', - 비서: 'secretary', - 약력: 'profile', - 사무실호실: 'officeRoom', - 사진: 'picture', - - 의안ID: variable(의안, 'ID'), - 의안번호: variable(의안, 번호), - 대: 'age', - 의안명: variable(의안, 명), - 제안자, - 제안자구분: variable(제안자, 구분), - 제안일: 'proposeDate', - 소관위코드: variable(소관위원회, 코드), - 소관위: variable(소관위원회), - 소관위회부일: variable(소관위원회, 회부일), - 위원회심사_처리일: variable(위원회, 'review', 처리일), - 의안상세정보_URL: variable(의안, 'detailUrl'), - 대표발의자: variable(대표발의자), - 법사위처리결과: variable(법제사법위원회, 처리결과), - 법사위처리일: variable(법제사법위원회, 처리일), - 법사위상정일: variable(법제사법위원회, 상정일), - 법사위회부일: variable(법제사법위원회, 회부일), - 소관위처리결과: variable(소관위원회, 처리결과), - 소관위처리일: variable(소관위원회, 처리일), - 소관위상정일: variable(소관위원회, 상정일), - 대표발의자코드: variable(대표발의자, 코드), - 본회의심의결과: 'plenarySessionReviewResult', - 의결일: 'resolutionDate', - - 일정_종류: variable(일정, 'type'), - 일정_내용: variable(일정, 'content'), - 일정_일자: variable(일정, 일자), - 일정_시간: variable(일정, 시간), - 회의_구분: variable(회의, 구분), - 회의_회기: variable(회의, 'session'), - 회의_차수: variable(회의, 'degree'), - 행사_주체자: variable(행사, 'institution'), - 행사_장소: variable(행사, 'place'), -} as const; diff --git a/src/constant/translatedVariableDictionary/index.ts b/src/constant/translatedVariableDictionary/index.ts new file mode 100644 index 0000000..399a6a2 --- /dev/null +++ b/src/constant/translatedVariableDictionary/index.ts @@ -0,0 +1,95 @@ +/** + * @description if you modify this properties, you should upgrade the minor version because it will be a break changes + */ + +import { variable } from './variable'; + +const 국회의원 = 'lawmaker'; +const 코드 = 'code'; +const 명 = 'name'; +const 한자명 = variable(`chinese`, 명); +const 영문명 = variable(`english`, 명); +const 구분 = 'division'; +const 구분명 = `${구분}`; +const 생일 = 'birthday'; +const 직책 = 'duty'; +const 정당 = 'politicalParty'; +const 선거구 = 'electoralDistrict'; +const 위원회 = 'committee'; +const 소속위원회 = 'belongingCommittee'; +const 선거 = 'election'; +const 재선 = variable(`re`, 선거); +const 의안 = `bill`; +const 번호 = 'number'; +const 소관위원회 = variable(`jurisdiction`, 위원회); +const 법제사법위원회 = variable(`legislationAndJudiciary`, 위원회); +const 처리 = 'process'; +const 일자 = `date`; +const 처리결과 = variable(처리, `result`); +const 처리일 = variable(처리, 일자); +const 회부일 = variable(`submit`, 일자); +const 상정일 = variable(`present`, 일자); + +const 일정 = 'schedule'; +const 시간 = 'time'; +const 회의 = 'conference'; +const 행사 = 'event'; + +export const 국회의원코드 = variable(국회의원, 코드); +export const 국회의원명 = variable(국회의원, 명); +export const 국회의원한자명 = variable(국회의원, 한자명); +export const 국회의원영문명 = variable(국회의원, 영문명); +export const 생일구분코드 = variable(생일, 구분, 코드); +export const 생일일자 = variable(생일); +export const 직책명 = variable(직책, 명); +export const 정당명 = variable(정당, 명); +export const 선거구명 = variable(선거구, 명); +export const 선거구구분명 = variable(선거구, 구분명); +export const 위원회명 = variable(위원회, 명); +export const 소속위원회명 = variable(소속위원회, 명); +export const 재선구분명 = variable(재선, 구분명); +export const 당선대수 = variable(선거, 'congress'); +export const 성별 = 'gender'; +export const 전화번호 = 'phoneNumber'; +export const 국회의원이메일주소 = 'email'; +export const 국회의원홈페이지URL = 'homepage'; +export const 보좌관 = 'aide'; +export const 비서관 = 'seniorSecretary'; +export const 비서 = 'secretary'; +export const 약력 = 'profile'; +export const 사무실호실 = 'officeRoom'; +export const 사진 = 'picture'; + +export const 의안ID = variable(의안, 'ID'); +export const 의안번호 = variable(의안, 번호); +export const 대 = 'age'; +export const 의안명 = variable(의안, 명); +export const 제안자 = variable('proposer'); +export const 대표발의자 = variable(`lead`, 제안자); +export const 제안자구분 = variable(제안자, 구분); +export const 제안일 = 'proposeDate'; +export const 소관위코드 = variable(소관위원회, 코드); +export const 소관위 = variable(소관위원회); +export const 소관위회부일 = variable(소관위원회, 회부일); +export const 위원회심사_처리일 = variable(위원회, 'review', 처리일); +export const 의안상세정보_URL = variable(의안, 'detailUrl'); +export const 법사위처리결과 = variable(법제사법위원회, 처리결과); +export const 법사위처리일 = variable(법제사법위원회, 처리일); +export const 법사위상정일 = variable(법제사법위원회, 상정일); +export const 법사위회부일 = variable(법제사법위원회, 회부일); +export const 소관위처리결과 = variable(소관위원회, 처리결과); +export const 소관위처리일 = variable(소관위원회, 처리일); +export const 소관위상정일 = variable(소관위원회, 상정일); +export const 대표발의자코드 = variable(대표발의자, 코드); +export const 본회의심의결과 = 'plenarySessionReviewResult'; +export const 의결일 = 'resolutionDate'; + +export const 일정_종류 = variable(일정, 'type'); +export const 일정_내용 = variable(일정, 'content'); +export const 일정_일자 = variable(일정, 일자); +export const 일정_시간 = variable(일정, 시간); +export const 회의_구분 = variable(회의, 구분); +export const 회의_회기 = variable(회의, 'session'); +export const 회의_차수 = variable(회의, 'degree'); +export const 행사_주체자 = variable(행사, 'institution'); +export const 행사_장소 = variable(행사, 'place'); diff --git a/src/constant/translatedVariableDictionary/translatedVariableDictionary.spec.ts b/src/constant/translatedVariableDictionary/translatedVariableDictionary.spec.ts new file mode 100644 index 0000000..2f5517a --- /dev/null +++ b/src/constant/translatedVariableDictionary/translatedVariableDictionary.spec.ts @@ -0,0 +1,69 @@ +import { describe, it, expectTypeOf, expect } from 'vitest'; +import * as H from 'hotscript'; + +import { + 국회의원명, + 국회의원영문명, + 국회의원코드, + 국회의원한자명, + 당선대수, + 생일구분코드, + 위원회심사_처리일, +} from './index'; +import { variable } from './variable'; + +describe('variable function', () => { + it('should return correct variable name for single argument', () => { + const result = variable('test'); + expect(result).toBe('test'); + }); + + it('should return correct variable name for multiple arguments', () => { + const result = variable('foo', 'bar', 'baz'); + expect(result).toBe('fooBarBaz'); + }); + + it('should handle string arguments correctly', () => { + const result = variable('Hello', 'World'); + expect(result).toBe('helloWorld'); + }); + + it('should return correct type for single argument', () => { + const result: H.Call = variable('test'); + expect(typeof result).toBe('string'); + }); + + it('should return correct type for multiple arguments', () => { + const result: H.Pipe< + ['foo', 'bar', 'baz'], + [H.Tuples.Map, H.Tuples.Join<''>, H.Strings.Uncapitalize] + > = variable('foo', 'bar', 'baz'); + expect(typeof result).toBe('string'); + }); +}); + +describe('translatedVariableDictionary', () => { + it('should have correct types', () => { + // Test the types of individual properties + expectTypeOf(국회의원코드).toEqualTypeOf<'lawmakerCode'>(); + expect(국회의원코드).toBe('lawmakerCode'); + + expectTypeOf(국회의원명).toEqualTypeOf<'lawmakerName'>(); + expect(국회의원명).toBe('lawmakerName'); + + expectTypeOf(국회의원한자명).toEqualTypeOf<'lawmakerChineseName'>(); + expect(국회의원한자명).toBe('lawmakerChineseName'); + + expectTypeOf(국회의원영문명).toEqualTypeOf<'lawmakerEnglishName'>(); + expect(국회의원영문명).toBe('lawmakerEnglishName'); + + expectTypeOf(생일구분코드).toEqualTypeOf<'birthdayDivisionCode'>(); + expect(생일구분코드).toBe('birthdayDivisionCode'); + + expectTypeOf(당선대수).toEqualTypeOf<'electionCongress'>(); + expect(당선대수).toBe('electionCongress'); + + expectTypeOf(위원회심사_처리일).toEqualTypeOf<'committeeReviewProcessDate'>(); + expect(위원회심사_처리일).toBe('committeeReviewProcessDate'); + }); +}); diff --git a/src/constant/translatedVariableDictionary/variable.ts b/src/constant/translatedVariableDictionary/variable.ts new file mode 100644 index 0000000..4a9e253 --- /dev/null +++ b/src/constant/translatedVariableDictionary/variable.ts @@ -0,0 +1,10 @@ +import * as H from 'hotscript'; + +export const variable = >(...args: Args) => + args.reduce( + (prev, cur, idx) => + idx === 0 + ? `${cur.charAt(0).toLowerCase()}${cur.slice(1)}` + : `${prev}${cur.charAt(0).toUpperCase()}${cur.slice(1)}`, + '' + ) as H.Pipe, H.Tuples.Join<''>, H.Strings.Uncapitalize]>; diff --git a/src/lawmaker/getLawmakerList.ts b/src/lawmaker/getLawmakerList.ts index 8542c6c..a6831ce 100644 --- a/src/lawmaker/getLawmakerList.ts +++ b/src/lawmaker/getLawmakerList.ts @@ -1,6 +1,31 @@ import { callOpenApi } from '../functional'; import { PaginationType } from '../types/callOpenApi'; -import { translatedVariableDictionary } from '../constant'; +import { + 국회의원명, + 국회의원영문명, + 국회의원이메일주소, + 국회의원코드, + 국회의원한자명, + 국회의원홈페이지URL, + 당선대수, + 보좌관, + 비서, + 비서관, + 사무실호실, + 사진, + 생일구분코드, + 생일일자, + 선거구구분명, + 선거구명, + 성별, + 소속위원회명, + 약력, + 위원회명, + 재선구분명, + 전화번호, + 정당명, + 직책명, +} from '../constant'; interface Lawmaker { NAAS_CD: string; // 국회의원코드 @@ -43,30 +68,30 @@ type Argument = { const command = 'ALLNAMEMBER'; const transform = (v: Row) => ({ - [translatedVariableDictionary['국회의원코드']]: v.NAAS_CD, - [translatedVariableDictionary['국회의원명']]: v.NAAS_NM, - [translatedVariableDictionary['국회의원한자명']]: v.NAAS_CH_NM, - [translatedVariableDictionary['국회의원영문명']]: v.NAAS_EN_NM, - [translatedVariableDictionary['생일구분코드']]: v.BIRDY_DIV_CD, - [translatedVariableDictionary['생일일자']]: v.BIRDY_DT, - [translatedVariableDictionary['직책명']]: v.DTY_NM, - [translatedVariableDictionary['정당명']]: v.PLPT_NM, - [translatedVariableDictionary['선거구명']]: v.ELECD_NM, - [translatedVariableDictionary['선거구구분명']]: v.ELECD_DIV_NM, - [translatedVariableDictionary['위원회명']]: v.CMIT_NM, - [translatedVariableDictionary['소속위원회명']]: v.BLNG_CMIT_NM, - [translatedVariableDictionary['재선구분명']]: v.RLCT_DIV_NM, - [translatedVariableDictionary['당선대수']]: v.GTELT_ERACO, // 당선대수 - [translatedVariableDictionary['성별']]: v.NTR_DIV, - [translatedVariableDictionary['전화번호']]: v.NAAS_TEL_NO, - [translatedVariableDictionary['국회의원이메일주소']]: v.NAAS_EMAIL_ADDR, - [translatedVariableDictionary['국회의원홈페이지URL']]: v.NAAS_HP_URL, - [translatedVariableDictionary['보좌관']]: v.AIDE_NM, - [translatedVariableDictionary['비서관']]: v.CHF_SCRT_NM, - [translatedVariableDictionary['비서']]: v.SCRT_NM, - [translatedVariableDictionary['약력']]: v.BRF_HST, - [translatedVariableDictionary['사무실호실']]: v.OFFM_RNUM_NO, - [translatedVariableDictionary['사진']]: v.NAAS_PIC, + [국회의원코드]: v.NAAS_CD, + [국회의원명]: v.NAAS_NM, + [국회의원한자명]: v.NAAS_CH_NM, + [국회의원영문명]: v.NAAS_EN_NM, + [생일구분코드]: v.BIRDY_DIV_CD, + [생일일자]: v.BIRDY_DT, + [직책명]: v.DTY_NM, + [정당명]: v.PLPT_NM, + [선거구명]: v.ELECD_NM, + [선거구구분명]: v.ELECD_DIV_NM, + [위원회명]: v.CMIT_NM, + [소속위원회명]: v.BLNG_CMIT_NM, + [재선구분명]: v.RLCT_DIV_NM, + [당선대수]: v.GTELT_ERACO, // 당선대수 + [성별]: v.NTR_DIV, + [전화번호]: v.NAAS_TEL_NO, + [국회의원이메일주소]: v.NAAS_EMAIL_ADDR, + [국회의원홈페이지URL]: v.NAAS_HP_URL, + [보좌관]: v.AIDE_NM, + [비서관]: v.CHF_SCRT_NM, + [비서]: v.SCRT_NM, + [약력]: v.BRF_HST, + [사무실호실]: v.OFFM_RNUM_NO, + [사진]: v.NAAS_PIC, }); /** diff --git a/src/national-assembly/getNationalAssemblySchedule.ts b/src/national-assembly/getNationalAssemblySchedule.ts index 4fd6ee1..e2e19d9 100644 --- a/src/national-assembly/getNationalAssemblySchedule.ts +++ b/src/national-assembly/getNationalAssemblySchedule.ts @@ -1,4 +1,15 @@ -import { translatedVariableDictionary } from '../constant'; +import { + 위원회명, + 일정_내용, + 일정_시간, + 일정_일자, + 일정_종류, + 행사_장소, + 행사_주체자, + 회의_구분, + 회의_차수, + 회의_회기, +} from '../constant'; import { callOpenApi } from '../functional'; import { PaginationType } from '../types/callOpenApi'; @@ -27,16 +38,16 @@ type Argument = { const command = 'ALLSCHEDULE'; const transform = (v: Row) => ({ - [translatedVariableDictionary['일정_종류']]: v.SCH_KIND, - [translatedVariableDictionary['일정_내용']]: v.SCH_CN, - [translatedVariableDictionary['일정_일자']]: v.SCH_DT, - [translatedVariableDictionary['일정_시간']]: v.SCH_TM, - [translatedVariableDictionary['회의_구분']]: v.CONF_DIV, - [translatedVariableDictionary['위원회명']]: v.CMIT_NM, - [translatedVariableDictionary['회의_회기']]: v.CONF_SESS, - [translatedVariableDictionary['회의_차수']]: v.CONF_DGR, - [translatedVariableDictionary['행사_주체자']]: v.EV_INST_NM, - [translatedVariableDictionary['행사_장소']]: v.EV_PLC, + [일정_종류]: v.SCH_KIND, + [일정_내용]: v.SCH_CN, + [일정_일자]: v.SCH_DT, + [일정_시간]: v.SCH_TM, + [회의_구분]: v.CONF_DIV, + [위원회명]: v.CMIT_NM, + [회의_회기]: v.CONF_SESS, + [회의_차수]: v.CONF_DGR, + [행사_주체자]: v.EV_INST_NM, + [행사_장소]: v.EV_PLC, }); /** * @description call https://open.assembly.go.kr/portal/data/service/selectAPIServicePage.do/OOWY4R001216HX11437 From 1b97b953999b438afbda89ed88478f6066ced043 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Thu, 8 Aug 2024 18:50:57 -0700 Subject: [PATCH 6/6] fix: test error Signed-off-by: sunrabbit123 --- src/bill/getBillList.spec.ts | 73 ++++++++++++------- src/lawmaker/getLawmakerList.spec.ts | 72 ++++++++++++------ .../getNationalAssemblySchedule.spec.ts | 33 ++++++--- 3 files changed, 118 insertions(+), 60 deletions(-) diff --git a/src/bill/getBillList.spec.ts b/src/bill/getBillList.spec.ts index 240efb7..9974eff 100644 --- a/src/bill/getBillList.spec.ts +++ b/src/bill/getBillList.spec.ts @@ -1,7 +1,31 @@ import { describe, it, expect, vi } from 'vitest'; import { getBillList } from './getBillList'; import { callOpenApi } from '../functional'; -import { translatedVariableDictionary } from '../constant'; +import { + 대, + 대표발의자, + 대표발의자코드, + 법사위상정일, + 법사위처리결과, + 법사위처리일, + 법사위회부일, + 본회의심의결과, + 소관위, + 소관위상정일, + 소관위처리결과, + 소관위처리일, + 소관위코드, + 소관위회부일, + 위원회심사_처리일, + 의결일, + 의안ID, + 의안명, + 의안번호, + 의안상세정보_URL, + 제안일, + 제안자, + 제안자구분, +} from '../constant'; vi.mock('../functional', () => ({ callOpenApi: vi.fn(), @@ -50,30 +74,29 @@ describe('getBillList', () => { expect(bills).toHaveLength(1); expect(bills[0]).toEqual({ - [translatedVariableDictionary['의안ID']]: 'PRC_K2S4R0S4Q3P0L0K9J0J9I5Q7P2Q4O6', - [translatedVariableDictionary['의안번호']]: '2126707', - [translatedVariableDictionary['대']]: '21', - [translatedVariableDictionary['의안명']]: '문화다양성의 보호와 증진에 관한 법률 일부개정법률안', - [translatedVariableDictionary['제안자']]: '이자스민의원 등 10인', - [translatedVariableDictionary['제안자구분']]: '의원', - [translatedVariableDictionary['제안일']]: '2024-05-29', - [translatedVariableDictionary['소관위코드']]: '9700513', - [translatedVariableDictionary['소관위']]: '문화체육관광위원회', - [translatedVariableDictionary['소관위회부일']]: '2024-05-29', - [translatedVariableDictionary['위원회심사_처리일']]: null, - [translatedVariableDictionary['의안상세정보_URL']]: - 'https://likms.assembly.go.kr/bill/billDetail.do?billId=PRC_K2S4R0S4Q3P0L0K9J0J9I5Q7P2Q4O6', - [translatedVariableDictionary['대표발의자']]: '이자스민', - [translatedVariableDictionary['법사위처리결과']]: null, - [translatedVariableDictionary['법사위처리일']]: null, - [translatedVariableDictionary['법사위상정일']]: null, - [translatedVariableDictionary['법사위회부일']]: null, - [translatedVariableDictionary['소관위처리결과']]: null, - [translatedVariableDictionary['소관위처리일']]: null, - [translatedVariableDictionary['소관위상정일']]: null, - [translatedVariableDictionary['대표발의자코드']]: 'SZ51175J', - [translatedVariableDictionary['본회의심의결과']]: '임기만료폐기', - [translatedVariableDictionary['의결일']]: '2024-05-29', + [의안ID]: 'PRC_K2S4R0S4Q3P0L0K9J0J9I5Q7P2Q4O6', + [의안번호]: '2126707', + [대]: '21', + [의안명]: '문화다양성의 보호와 증진에 관한 법률 일부개정법률안', + [제안자]: '이자스민의원 등 10인', + [제안자구분]: '의원', + [제안일]: '2024-05-29', + [소관위코드]: '9700513', + [소관위]: '문화체육관광위원회', + [소관위회부일]: '2024-05-29', + [위원회심사_처리일]: null, + [의안상세정보_URL]: 'https://likms.assembly.go.kr/bill/billDetail.do?billId=PRC_K2S4R0S4Q3P0L0K9J0J9I5Q7P2Q4O6', + [대표발의자]: '이자스민', + [법사위처리결과]: null, + [법사위처리일]: null, + [법사위상정일]: null, + [법사위회부일]: null, + [소관위처리결과]: null, + [소관위처리일]: null, + [소관위상정일]: null, + [대표발의자코드]: 'SZ51175J', + [본회의심의결과]: '임기만료폐기', + [의결일]: '2024-05-29', }); }); diff --git a/src/lawmaker/getLawmakerList.spec.ts b/src/lawmaker/getLawmakerList.spec.ts index 1f5aeb1..79d10de 100644 --- a/src/lawmaker/getLawmakerList.spec.ts +++ b/src/lawmaker/getLawmakerList.spec.ts @@ -1,7 +1,31 @@ import { describe, it, expect, vi } from 'vitest'; import { getLawmakerList } from './getLawmakerList'; import { callOpenApi } from '../functional'; -import { translatedVariableDictionary } from '../constant'; +import { + 국회의원명, + 국회의원영문명, + 국회의원이메일주소, + 국회의원코드, + 국회의원한자명, + 국회의원홈페이지URL, + 보좌관, + 비서, + 비서관, + 사무실호실, + 사진, + 생일구분코드, + 생일일자, + 선거구구분명, + 선거구명, + 성별, + 소속위원회명, + 약력, + 위원회명, + 재선구분명, + 전화번호, + 정당명, + 직책명, +} from '../constant'; vi.mock('../functional', () => ({ callOpenApi: vi.fn(), @@ -50,29 +74,29 @@ describe('getLawmakerList', () => { expect(lawmakers).toHaveLength(1); expect(lawmakers[0]).toEqual({ - [translatedVariableDictionary['국회의원코드']]: '1234', - [translatedVariableDictionary['국회의원명']]: 'John Doe', - [translatedVariableDictionary['국회의원한자명']]: '张三', - [translatedVariableDictionary['국회의원영문명']]: 'John Doe', - [translatedVariableDictionary['생일구분코드']]: '1', - [translatedVariableDictionary['생일일자']]: '1990-01-01', - [translatedVariableDictionary['직책명']]: 'Lawmaker', - [translatedVariableDictionary['정당명']]: 'Democratic Party', - [translatedVariableDictionary['선거구명']]: 'District A', - [translatedVariableDictionary['선거구구분명']]: 'District', - [translatedVariableDictionary['위원회명']]: 'Committee A', - [translatedVariableDictionary['소속위원회명']]: 'Committee A', - [translatedVariableDictionary['재선구분명']]: 'First-term', - [translatedVariableDictionary['성별']]: 'Male', - [translatedVariableDictionary['전화번호']]: '123-456-7890', - [translatedVariableDictionary['국회의원이메일주소']]: 'john.doe@example.com', - [translatedVariableDictionary['국회의원홈페이지URL']]: 'https://example.com/john-doe', - [translatedVariableDictionary['보좌관']]: 'Jane Smith', - [translatedVariableDictionary['비서관']]: 'Bob Johnson', - [translatedVariableDictionary['비서']]: 'Alice Williams', - [translatedVariableDictionary['약력']]: 'John Doe is a lawmaker.', - [translatedVariableDictionary['사무실호실']]: '123', - [translatedVariableDictionary['사진']]: 'https://example.com/john-doe.jpg', + [국회의원코드]: '1234', + [국회의원명]: 'John Doe', + [국회의원한자명]: '张三', + [국회의원영문명]: 'John Doe', + [생일구분코드]: '1', + [생일일자]: '1990-01-01', + [직책명]: 'Lawmaker', + [정당명]: 'Democratic Party', + [선거구명]: 'District A', + [선거구구분명]: 'District', + [위원회명]: 'Committee A', + [소속위원회명]: 'Committee A', + [재선구분명]: 'First-term', + [성별]: 'Male', + [전화번호]: '123-456-7890', + [국회의원이메일주소]: 'john.doe@example.com', + [국회의원홈페이지URL]: 'https://example.com/john-doe', + [보좌관]: 'Jane Smith', + [비서관]: 'Bob Johnson', + [비서]: 'Alice Williams', + [약력]: 'John Doe is a lawmaker.', + [사무실호실]: '123', + [사진]: 'https://example.com/john-doe.jpg', }); }); it('should return an empty list when no lawmakers are found', async () => { diff --git a/src/national-assembly/getNationalAssemblySchedule.spec.ts b/src/national-assembly/getNationalAssemblySchedule.spec.ts index f7865a8..fbe6656 100644 --- a/src/national-assembly/getNationalAssemblySchedule.spec.ts +++ b/src/national-assembly/getNationalAssemblySchedule.spec.ts @@ -1,7 +1,18 @@ import { describe, it, expect, vi } from 'vitest'; import { getNationalAssemblySchedule } from './getNationalAssemblySchedule'; import { callOpenApi } from '../functional'; -import { translatedVariableDictionary } from '../constant'; +import { + 위원회명, + 일정_내용, + 일정_시간, + 일정_일자, + 일정_종류, + 행사_장소, + 행사_주체자, + 회의_구분, + 회의_차수, + 회의_회기, +} from '../constant'; vi.mock('../functional', () => ({ callOpenApi: vi.fn(), @@ -37,16 +48,16 @@ describe('getNationalAssemblySchedule', () => { expect(schedules).toHaveLength(1); expect(schedules[0]).toEqual({ - [translatedVariableDictionary['일정_종류']]: 'Meeting', - [translatedVariableDictionary['일정_내용']]: 'Committee Meeting', - [translatedVariableDictionary['일정_일자']]: '2023-05-01', - [translatedVariableDictionary['일정_시간']]: '09:00', - [translatedVariableDictionary['회의_구분']]: 'Regular', - [translatedVariableDictionary['위원회명']]: 'Committee A', - [translatedVariableDictionary['회의_회기']]: '1', - [translatedVariableDictionary['회의_차수']]: '1', - [translatedVariableDictionary['행사_주체자']]: 'National Assembly', - [translatedVariableDictionary['행사_장소']]: 'Room 123', + [일정_종류]: 'Meeting', + [일정_내용]: 'Committee Meeting', + [일정_일자]: '2023-05-01', + [일정_시간]: '09:00', + [회의_구분]: 'Regular', + [위원회명]: 'Committee A', + [회의_회기]: '1', + [회의_차수]: '1', + [행사_주체자]: 'National Assembly', + [행사_장소]: 'Room 123', }); });