Skip to content

fix: enhance translatedVariableDictionary (#17) #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/bill/getBillList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
9 changes: 0 additions & 9 deletions src/bill/index.spec.ts

This file was deleted.

72 changes: 1 addition & 71 deletions src/constant/index.ts
Original file line number Diff line number Diff line change
@@ -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';
62 changes: 62 additions & 0 deletions src/constant/translatedVariableDictionary.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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<H.Strings.CamelCase, 'test'> = 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.Strings.Capitalize>, 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<typeof translatedVariableDictionary>();

// 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');
});
});
108 changes: 108 additions & 0 deletions src/constant/translatedVariableDictionary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
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 extends Array<string>>(...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<Args, [H.Tuples.Map<H.Strings.Capitalize>, 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;
2 changes: 1 addition & 1 deletion src/lawmaker/getLawmakerList.ts
Original file line number Diff line number Diff line change
@@ -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; // 국회의원코드
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading