This commit is contained in:
62
src/js/kintone-rest-api-client.ts
Normal file
62
src/js/kintone-rest-api-client.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { KintoneRestAPIClient } from '@kintone/rest-api-client';
|
||||
|
||||
export const client = new KintoneRestAPIClient();
|
||||
|
||||
export type App = {
|
||||
appId: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type Properties = Awaited<ReturnType<typeof client.app.getFormFields>>['properties'];
|
||||
export type Layout = Awaited<ReturnType<typeof client.app.getFormLayout>>['layout'];
|
||||
|
||||
export type OneOf = Properties[string];
|
||||
export type FieldType = OneOf['type'];
|
||||
|
||||
const typeNames = [
|
||||
'RECORD_NUMBER',
|
||||
'CREATOR',
|
||||
'CREATED_TIME',
|
||||
'MODIFIER',
|
||||
'UPDATED_TIME',
|
||||
'CATEGORY',
|
||||
'STATUS',
|
||||
'STATUS_ASSIGNEE',
|
||||
'SINGLE_LINE_TEXT',
|
||||
'NUMBER',
|
||||
'CALC',
|
||||
'MULTI_LINE_TEXT',
|
||||
'RICH_TEXT',
|
||||
'LINK',
|
||||
'CHECK_BOX',
|
||||
'RADIO_BUTTON',
|
||||
'DROP_DOWN',
|
||||
'MULTI_SELECT',
|
||||
'FILE',
|
||||
'DATE',
|
||||
'TIME',
|
||||
'DATETIME',
|
||||
'USER_SELECT',
|
||||
'ORGANIZATION_SELECT',
|
||||
'GROUP_SELECT',
|
||||
'GROUP',
|
||||
'REFERENCE_TABLE',
|
||||
'SUBTABLE',
|
||||
] as const satisfies readonly FieldType[];
|
||||
|
||||
export const types = typeNames.reduce(
|
||||
(acc, name) => {
|
||||
acc[name] = name;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<(typeof typeNames)[number], (typeof typeNames)[number]>,
|
||||
);
|
||||
|
||||
type ExtractOneOf<T extends FieldType> = Extract<OneOf, { type: T }>;
|
||||
function createTypeGuard<T extends FieldType>(type: T) {
|
||||
return (value: OneOf): value is ExtractOneOf<T> => value?.type === type;
|
||||
}
|
||||
|
||||
export const isType = Object.fromEntries(
|
||||
typeNames.map((typeName) => [typeName, createTypeGuard(typeName as FieldType)]),
|
||||
) as { [K in (typeof typeNames)[number]]: (value: OneOf) => value is ExtractOneOf<K> };
|
||||
Reference in New Issue
Block a user