npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@konomi-app/kintone-schema-generator

v0.1.0

Published

kintoneアプリのフィールド定義からZodスキーマを自動生成するCLIツール・ライブラリ

Downloads

103

Readme

kintone-schema-generator

kintone アプリのフィールド定義から Zod スキーマを自動生成する CLI ツール・ライブラリ。

インストール

# npm
npm install kintone-schema-generator

# pnpm
pnpm add kintone-schema-generator

# yarn
yarn add kintone-schema-generator

必要な環境変数

KINTONE_BASE_URL=https://xxx.cybozu.com
KINTONE_USERNAME=your-username
KINTONE_PASSWORD=your-password

# オプション: Basic認証が必要な場合
KINTONE_BASIC_USERNAME=basic-username
KINTONE_BASIC_PASSWORD=basic-password

CLI での使用方法

基本的な使用方法

# パッケージをインストール後
npx kintone-schema-generate <APP_ID> <OUTPUT_NAME> [OPTIONS]

# 例: アプリID 123 のスキーマを生成
npx kintone-schema-generate 123 customers
# -> ./src/lib/kintone/schemas/customers.ts が生成される

# フル機能(ビュー、プロセス管理なども含む)
npx kintone-schema-generate 123 customers --full

# 出力先を指定
npx kintone-schema-generate 123 customers --output ./schemas

# Zodのimportパスをカスタマイズ
npx kintone-schema-generate 123 customers --zod-import zod/v4

オプション

| オプション | 説明 | | ----------------- | -------------------------------------------------------------------- | | --full | フィールド定義に加え、ビュー、プロセス管理、フィールド定数なども生成 | | --preview | 未反映の設定(プレビュー)を取得 | | --verbose, -v | 詳細なログを出力 | | --output, -o | 出力先ディレクトリ(デフォルト: ./src/lib/kintone/schemas) | | --zod-import | Zod の import パス(デフォルト: zod) |

ライブラリとしての使用方法

スキーマの生成

import { generateSchema } from 'kintone-schema-generator';

const result = await generateSchema(
  {
    baseUrl: 'https://xxx.cybozu.com',
    username: 'your-username',
    password: 'your-password',
  },
  '123', // アプリID
  'customers', // 出力名
  {
    full: true, // フル機能を有効化
    verbose: true, // 詳細ログ
    zodImportPath: 'zod', // Zodのimportパス
  }
);

console.log(result.code); // 生成されたTypeScriptコード
console.log(result.schemaName); // スキーマ名(例: Customers)
console.log(result.fieldCount); // フィールド数

フィールド定義からスキーマコードを生成(API を使わない場合)

import { generateSchemaCode, KintoneClient } from 'kintone-schema-generator';

// フィールド定義を取得
const client = new KintoneClient({
  baseUrl: 'https://xxx.cybozu.com',
  username: 'your-username',
  password: 'your-password',
});
const fields = await client.getFormFields('123');

// スキーマコードを生成
const result = generateSchemaCode('123', 'customers', fields, {
  full: true,
  zodImportPath: 'zod',
});

console.log(result.code);

KintoneClient の使用

このパッケージには、kintone REST API のクライアントも含まれています。

import { KintoneClient } from 'kintone-schema-generator/client';

const client = new KintoneClient({
  baseUrl: 'https://xxx.cybozu.com',
  username: 'your-username',
  password: 'your-password',
});

// レコードを取得
const records = await client.getRecords('123', {
  query: 'status = "完了"',
});

// レコードを追加
const ids = await client.addRecords('123', [{ field1: { value: 'value1' } }]);

// フィールド定義を取得
const fields = await client.getFormFields('123');

生成されるスキーマの例

import { z } from 'zod';

/**
 * レコード取得時のスキーマ(全フィールド)
 */
export const CustomersRecordSchema = z.object({
  /** 顧客名 */
  customerName: z.object({ type: z.literal('SINGLE_LINE_TEXT'), value: z.string() }),
  /** ステータス */
  status: z.object({
    type: z.literal('DROP_DOWN'),
    value: z.union([z.literal(''), z.enum(['新規', '対応中', '完了'])]),
  }),
  // ...
  $id: z.object({ type: z.literal('__ID__'), value: z.string() }),
  $revision: z.object({ type: z.literal('__REVISION__'), value: z.string() }),
});

export type CustomersRecord = z.infer<typeof CustomersRecordSchema>;

/**
 * レコード新規作成用のスキーマ
 */
export const NewCustomersRecordSchema = z.object({
  customerName: z.object({ value: z.string() }),
  status: z
    .object({ value: z.union([z.literal(''), z.enum(['新規', '対応中', '完了'])]) })
    .optional(),
  // ...
});

export type NewCustomersRecord = z.infer<typeof NewCustomersRecordSchema>;

--full オプションで追加されるエクスポート

| エクスポート | 説明 | | -------------------------- | ------------------------------------------ | | CUSTOMERS_APP_ID | アプリ ID | | CUSTOMERS_APP_NAME | アプリ名 | | CUSTOMERS_FIELDS | フィールド情報の定数 | | CUSTOMERS_FIELD_CODES | フィールドコード一覧 | | getCustomersFieldLabel() | フィールドコードからラベルを取得 | | CustomersStatusSchema | ステータスの型(プロセス管理が有効な場合) | | CUSTOMERS_STATUS_ACTIONS | ステータス別アクション | | CustomersViewNameSchema | ビュー名の型 | | CUSTOMERS_VIEWS | ビュー情報 | | CustomersQuery | クエリビルダーヘルパー |