claude-code-jsonl-generator 0.1.3-beta.10 → 0.1.3-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +2 -3
- package/dist/cli.js +2 -3
- package/dist/{emit-guards-DWNOOQCB.cjs → emit-guards-BKEtrVDH.cjs} +5 -10
- package/dist/{emit-guards-CSDZc-iy.js → emit-guards-DSL78hvA.js} +5 -9
- package/dist/{emit-guards-CSDZc-iy.js.map → emit-guards-DSL78hvA.js.map} +1 -1
- package/dist/index.cjs +2 -3
- package/dist/index.d.cts +0 -10
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_emit_guards = require("./emit-guards-
|
|
2
|
+
const require_emit_guards = require("./emit-guards-BKEtrVDH.cjs");
|
|
3
3
|
let node_fs_promises = require("node:fs/promises");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
node_path = require_emit_guards.__toESM(node_path, 1);
|
|
6
|
-
|
|
6
|
+
// src/cli.ts
|
|
7
7
|
/**
|
|
8
8
|
* 引数を解釈する。`--corpus <dir> --out <parser/src/generated>`。
|
|
9
9
|
*
|
|
@@ -52,4 +52,3 @@ main().catch((error) => {
|
|
|
52
52
|
console.error(error);
|
|
53
53
|
process.exit(1);
|
|
54
54
|
});
|
|
55
|
-
//#endregion
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as inferShape, n as emitInterface, r as pascalCase, s as scanCorpus, t as emitGuardFunction } from "./emit-guards-
|
|
2
|
+
import { a as inferShape, n as emitInterface, r as pascalCase, s as scanCorpus, t as emitGuardFunction } from "./emit-guards-DSL78hvA.js";
|
|
3
3
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
|
|
5
|
+
// src/cli.ts
|
|
6
6
|
/**
|
|
7
7
|
* 引数を解釈する。`--corpus <dir> --out <parser/src/generated>`。
|
|
8
8
|
*
|
|
@@ -51,7 +51,6 @@ main().catch((error) => {
|
|
|
51
51
|
console.error(error);
|
|
52
52
|
process.exit(1);
|
|
53
53
|
});
|
|
54
|
-
//#endregion
|
|
55
54
|
export {};
|
|
56
55
|
|
|
57
56
|
//# sourceMappingURL=cli.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -19,13 +19,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
19
|
value: mod,
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
|
-
//#endregion
|
|
23
22
|
let node_fs_promises = require("node:fs/promises");
|
|
24
23
|
let node_fs = require("node:fs");
|
|
25
24
|
let node_readline = require("node:readline");
|
|
26
25
|
let node_path = require("node:path");
|
|
27
26
|
node_path = __toESM(node_path, 1);
|
|
28
|
-
|
|
27
|
+
// src/scanner.ts
|
|
29
28
|
/**
|
|
30
29
|
* `.jsonl` ファイルを再帰収集する。
|
|
31
30
|
*
|
|
@@ -87,8 +86,7 @@ async function scanCorpus(corpusDir, maxSamplesPerType = 5e3) {
|
|
|
87
86
|
typelessLines
|
|
88
87
|
};
|
|
89
88
|
}
|
|
90
|
-
|
|
91
|
-
//#region src/infer.ts
|
|
89
|
+
// src/infer.ts
|
|
92
90
|
/**
|
|
93
91
|
* JSON 値の種別を返す。
|
|
94
92
|
*
|
|
@@ -149,8 +147,7 @@ function inferShape(samples, options = {}) {
|
|
|
149
147
|
fields
|
|
150
148
|
};
|
|
151
149
|
}
|
|
152
|
-
|
|
153
|
-
//#region src/emit-types.ts
|
|
150
|
+
// src/emit-types.ts
|
|
154
151
|
/** JS 識別子として安全な名前かどうかを判定する正規表現。 */
|
|
155
152
|
const IDENTIFIER_RE$1 = /^[A-Za-z_$][\w$]*$/;
|
|
156
153
|
/** シングルクォート文字列リテラルとして安全になるよう `'` をエスケープする。 */
|
|
@@ -216,8 +213,7 @@ function emitInterface(interfaceName, type, shape) {
|
|
|
216
213
|
lines.push("}");
|
|
217
214
|
return lines.join("\n");
|
|
218
215
|
}
|
|
219
|
-
|
|
220
|
-
//#region src/emit-guards.ts
|
|
216
|
+
// src/emit-guards.ts
|
|
221
217
|
/** JS 識別子として安全な名前かどうかを判定する正規表現。 */
|
|
222
218
|
const IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
|
|
223
219
|
/** シングルクォート文字列リテラルとして安全になるよう `'` をエスケープする。 */
|
|
@@ -261,7 +257,6 @@ function emitGuardFunction(fnName, type, shape) {
|
|
|
261
257
|
`}`
|
|
262
258
|
].join("\n");
|
|
263
259
|
}
|
|
264
|
-
//#endregion
|
|
265
260
|
Object.defineProperty(exports, "__toESM", {
|
|
266
261
|
enumerable: true,
|
|
267
262
|
get: function() {
|
|
@@ -2,7 +2,7 @@ import { readdir, stat } from "node:fs/promises";
|
|
|
2
2
|
import { createReadStream } from "node:fs";
|
|
3
3
|
import { createInterface } from "node:readline";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
|
|
5
|
+
// src/scanner.ts
|
|
6
6
|
/**
|
|
7
7
|
* `.jsonl` ファイルを再帰収集する。
|
|
8
8
|
*
|
|
@@ -64,8 +64,7 @@ async function scanCorpus(corpusDir, maxSamplesPerType = 5e3) {
|
|
|
64
64
|
typelessLines
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
//#region src/infer.ts
|
|
67
|
+
// src/infer.ts
|
|
69
68
|
/**
|
|
70
69
|
* JSON 値の種別を返す。
|
|
71
70
|
*
|
|
@@ -126,8 +125,7 @@ function inferShape(samples, options = {}) {
|
|
|
126
125
|
fields
|
|
127
126
|
};
|
|
128
127
|
}
|
|
129
|
-
|
|
130
|
-
//#region src/emit-types.ts
|
|
128
|
+
// src/emit-types.ts
|
|
131
129
|
/** JS 識別子として安全な名前かどうかを判定する正規表現。 */
|
|
132
130
|
const IDENTIFIER_RE$1 = /^[A-Za-z_$][\w$]*$/;
|
|
133
131
|
/** シングルクォート文字列リテラルとして安全になるよう `'` をエスケープする。 */
|
|
@@ -193,8 +191,7 @@ function emitInterface(interfaceName, type, shape) {
|
|
|
193
191
|
lines.push("}");
|
|
194
192
|
return lines.join("\n");
|
|
195
193
|
}
|
|
196
|
-
|
|
197
|
-
//#region src/emit-guards.ts
|
|
194
|
+
// src/emit-guards.ts
|
|
198
195
|
/** JS 識別子として安全な名前かどうかを判定する正規表現。 */
|
|
199
196
|
const IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
|
|
200
197
|
/** シングルクォート文字列リテラルとして安全になるよう `'` をエスケープする。 */
|
|
@@ -238,7 +235,6 @@ function emitGuardFunction(fnName, type, shape) {
|
|
|
238
235
|
`}`
|
|
239
236
|
].join("\n");
|
|
240
237
|
}
|
|
241
|
-
//#endregion
|
|
242
238
|
export { inferShape as a, tsTypeOf as i, emitInterface as n, jsonKind as o, pascalCase as r, scanCorpus as s, emitGuardFunction as t };
|
|
243
239
|
|
|
244
|
-
//# sourceMappingURL=emit-guards-
|
|
240
|
+
//# sourceMappingURL=emit-guards-DSL78hvA.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-guards-CSDZc-iy.js","names":["IDENTIFIER_RE","escapeSingleQuote"],"sources":["../src/scanner.ts","../src/infer.ts","../src/emit-types.ts","../src/emit-guards.ts"],"sourcesContent":["import { readdir, stat } from 'node:fs/promises'\nimport { createReadStream } from 'node:fs'\nimport { createInterface } from 'node:readline'\nimport path from 'node:path'\n\n/** スキャン結果。 */\nexport interface ScanResult {\n /** type 文字列 → その type の生 JSON オブジェクト配列。 */\n samplesByType: Map<string, Record<string, unknown>[]>\n /** 走査した有効行数 (パース成功)。 */\n totalLines: number\n /** JSON 構文エラー行数。 */\n malformedLines: number\n /** type フィールドを持たない/文字列でない行数。 */\n typelessLines: number\n}\n\n/**\n * `.jsonl` ファイルを再帰収集する。\n *\n * @param dir - 起点ディレクトリ\n * @returns 絶対パス配列\n */\nasync function collectJsonlFiles(dir: string): Promise<string[]> {\n const out: string[] = []\n for (const entry of await readdir(dir)) {\n const full = path.join(dir, entry)\n const st = await stat(full)\n if (st.isDirectory()) {\n out.push(...(await collectJsonlFiles(full)))\n } else if (entry.endsWith('.jsonl')) {\n out.push(full)\n }\n }\n return out\n}\n\n/**\n * コーパスを走査し type ごとに生サンプルを集約する。\n *\n * @param corpusDir - コーパスのルートディレクトリ\n * @param maxSamplesPerType - type ごとの保持上限 (メモリ保護、既定 5000)\n */\nexport async function scanCorpus(\n corpusDir: string,\n maxSamplesPerType = 5000\n): Promise<ScanResult> {\n const samplesByType = new Map<string, Record<string, unknown>[]>()\n let totalLines = 0\n let malformedLines = 0\n let typelessLines = 0\n\n for (const file of await collectJsonlFiles(corpusDir)) {\n const rl = createInterface({\n input: createReadStream(file, { encoding: 'utf8' }),\n crlfDelay: Infinity,\n })\n for await (const raw of rl) {\n if (raw.trim() === '') continue\n let obj: unknown\n try {\n obj = JSON.parse(raw)\n } catch {\n malformedLines += 1\n continue\n }\n totalLines += 1\n if (\n typeof obj !== 'object' || obj === null || Array.isArray(obj) ||\n typeof (obj as Record<string, unknown>).type !== 'string'\n ) {\n typelessLines += 1\n continue\n }\n const record = obj as Record<string, unknown>\n const type = record.type as string\n const bucket = samplesByType.get(type) ?? []\n if (bucket.length < maxSamplesPerType) {\n bucket.push(record)\n samplesByType.set(type, bucket)\n }\n }\n }\n\n return { samplesByType, totalLines, malformedLines, typelessLines }\n}\n","/** JSON 値の種別。 */\nexport type JsonKind = 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object'\n\n/**\n * JSON 値の種別を返す。\n *\n * @param v - 対象値\n */\nexport function jsonKind(v: unknown): JsonKind {\n if (v === null) return 'null'\n if (Array.isArray(v)) return 'array'\n const t = typeof v\n if ((['string', 'number', 'boolean'] as string[]).includes(t)) {\n return t as 'string' | 'number' | 'boolean'\n }\n return 'object'\n}\n\n/** 1 フィールドの推論結果。 */\nexport interface FieldShape {\n /** 全サンプルに存在したか。 */\n required: boolean\n /** 観測された JSON 種別集合。 */\n kinds: Set<JsonKind>\n /** 観測された文字列リテラル集合 (閾値以下のときのみ)。 */\n literals?: Set<string>\n}\n\n/** 1 type (または content ブロック) の推論結果。 */\nexport interface Shape {\n /** サンプル総数。 */\n count: number\n /** フィールド名 → 推論結果。 */\n fields: Map<string, FieldShape>\n}\n\n/** `InferOptions.maxLiterals` 省略時の既定値。 */\nconst DEFAULT_MAX_LITERALS = 20\n\n/** 推論オプション。 */\nexport interface InferOptions {\n /** 文字列リテラルを列挙として保持する上限。超えたら literals を破棄。既定は `DEFAULT_MAX_LITERALS`。 */\n maxLiterals?: number\n}\n\n/**\n * 同一 type のサンプル群からフィールド形状を推論する。\n *\n * @param samples - 生 JSON オブジェクト配列\n * @param options - 推論オプション\n */\nexport function inferShape(\n samples: Record<string, unknown>[],\n options: InferOptions = {}\n): Shape {\n const maxLiterals = options.maxLiterals ?? DEFAULT_MAX_LITERALS\n const count = samples.length\n const presence = new Map<string, number>()\n const kinds = new Map<string, Set<JsonKind>>()\n const literals = new Map<string, Set<string> | null>()\n\n for (const sample of samples) {\n for (const [key, value] of Object.entries(sample)) {\n presence.set(key, (presence.get(key) ?? 0) + 1)\n\n const kset = kinds.get(key) ?? new Set<JsonKind>()\n const kind = jsonKind(value)\n kset.add(kind)\n kinds.set(key, kset)\n\n // 文字列リテラル収集 (null は「破棄済み」マーカー)\n const cur = literals.get(key)\n if (cur === null) {\n // すでに破棄済み\n } else if (kind === 'string') {\n const set = cur ?? new Set<string>()\n set.add(value as string)\n if (set.size > maxLiterals) {\n literals.set(key, null)\n } else {\n literals.set(key, set)\n }\n }\n }\n }\n\n const fields = new Map<string, FieldShape>()\n for (const [key, seen] of presence) {\n const lit = literals.get(key)\n const kindSet = kinds.get(key) ?? new Set<JsonKind>()\n // 全て文字列だった場合のみ literals を採用する\n const allString = kindSet.size === 1 && kindSet.has('string')\n fields.set(key, {\n required: seen === count,\n kinds: kindSet,\n literals: allString && lit ? lit : undefined,\n })\n }\n\n return { count, fields }\n}\n","import type { JsonKind, Shape } from './infer'\n\n/** JS 識別子として安全な名前かどうかを判定する正規表現。 */\nconst IDENTIFIER_RE = /^[A-Za-z_$][\\w$]*$/\n\n/** シングルクォート文字列リテラルとして安全になるよう `'` をエスケープする。 */\nfunction escapeSingleQuote(s: string): string {\n return s.replaceAll('\\'', String.raw`\\'`)\n}\n\n/**\n * 観測種別集合 (と任意のリテラル集合) を TypeScript 型文字列に写像する。\n *\n * @param kinds - 観測された JSON 種別\n * @param literals - 文字列リテラル集合 (あれば)\n */\nexport function tsTypeOf(kinds: Set<JsonKind>, literals?: Set<string>): string {\n const parts: string[] = []\n const mapped: Record<JsonKind, string> = {\n string: 'string',\n number: 'number',\n boolean: 'boolean',\n null: 'null',\n array: 'unknown[]',\n object: 'Record<string, unknown>',\n }\n // 文字列リテラルが与えられていれば開いた union にする\n if (literals && literals.size > 0 && kinds.has('string')) {\n const lits = [...literals].toSorted().map((s) => `'${escapeSingleQuote(s)}'`)\n parts.push(`${lits.join(' | ')} | (string & {})`)\n } else if (kinds.has('string')) {\n parts.push('string')\n }\n for (const k of ['number', 'boolean', 'array', 'object', 'null'] as JsonKind[]) {\n if (kinds.has(k)) parts.push(mapped[k])\n }\n // 重複除去して結合\n return [...new Set(parts)].join(' | ')\n}\n\n/** JS 識別子として安全ならそのまま、そうでなければクォートする。 */\nfunction propKey(name: string): string {\n return IDENTIFIER_RE.test(name) ? name : `'${escapeSingleQuote(name)}'`\n}\n\n/** interface 名として使うため type 文字列を PascalCase 化する (エミッタ内部用)。 */\nexport function pascalCase(type: string): string {\n return type\n .split(/[-_]/)\n .map((p) => p.charAt(0).toUpperCase() + p.slice(1))\n .join('')\n}\n\n/**\n * 1 type の interface 文字列を生成する。\n *\n * @param interfaceName - 出力する interface 名 (例 LastPromptEntry)\n * @param type - 判別子文字列 (例 last-prompt)\n * @param shape - 推論結果\n */\nexport function emitInterface(\n interfaceName: string,\n type: string,\n shape: Shape\n): string {\n const lines: string[] = [\n `export interface ${interfaceName} {`,\n ` _kind: 'known'`,\n ` type: '${escapeSingleQuote(type)}'`,\n ]\n for (const [name, field] of shape.fields) {\n if (name === 'type') continue\n const opt = field.required ? '' : '?'\n const tsType = tsTypeOf(field.kinds, field.literals)\n lines.push(` ${propKey(name)}${opt}: ${tsType}`)\n }\n lines.push('}')\n return lines.join('\\n')\n}\n","import type { JsonKind, Shape } from './infer'\n\n/** JS 識別子として安全な名前かどうかを判定する正規表現。 */\nconst IDENTIFIER_RE = /^[A-Za-z_$][\\w$]*$/\n\n/** シングルクォート文字列リテラルとして安全になるよう `'` をエスケープする。 */\nfunction escapeSingleQuote(s: string): string {\n return s.replaceAll('\\'', String.raw`\\'`)\n}\n\n/** 単一種別の required フィールドに対する検査式を返す。 */\nfunction checkExpr(name: string, kinds: Set<JsonKind>): string | undefined {\n const access = `v.${IDENTIFIER_RE.test(name) ? name : `['${escapeSingleQuote(name)}']`}`\n // object|null → isObject or null 許容\n const hasNull = kinds.has('null')\n const nonNull = [...kinds].filter((k) => k !== 'null')\n if (nonNull.length !== 1) {\n // 複数種別が混在する場合は存在確認のみ (過剰厳格を避ける)\n return `'${escapeSingleQuote(name)}' in v`\n }\n const kind = nonNull[0]\n const base: Partial<Record<JsonKind, string>> = {\n string: `isString(${access})`,\n number: `isNumber(${access})`,\n boolean: `isBoolean(${access})`,\n object: `isObject(${access})`,\n array: `Array.isArray(${access})`,\n }\n const expr = base[kind]\n if (expr === undefined) return `'${escapeSingleQuote(name)}' in v`\n return hasNull ? `(${access} === null || ${expr})` : expr\n}\n\n/**\n * 1 type のガード関数文字列を生成する。required フィールドのみ検査する。\n *\n * @param fnName - 関数名 (例 isMode)\n * @param type - 判別子\n * @param shape - 推論結果\n */\nexport function emitGuardFunction(\n fnName: string,\n type: string,\n shape: Shape\n): string {\n const checks: string[] = [\n `isObject(v)`,\n `v.type === '${escapeSingleQuote(type)}'`,\n ]\n for (const [name, field] of shape.fields) {\n if (name === 'type' || !field.required) continue\n const expr = checkExpr(name, field.kinds)\n if (expr) checks.push(expr)\n }\n return [\n `function ${fnName}(v: unknown): boolean {`,\n ` return ${checks.join(' &&\\n ')}`,\n `}`,\n ].join('\\n')\n}\n"],"mappings":";;;;;;;;;;;AAuBA,eAAe,kBAAkB,KAAgC;CAC/D,MAAM,MAAgB,CAAC;CACvB,KAAK,MAAM,SAAS,MAAM,QAAQ,GAAG,GAAG;EACtC,MAAM,OAAO,KAAK,KAAK,KAAK,KAAK;EAEjC,KAAI,MADa,KAAK,IAAI,EAAA,CACnB,YAAY,GACjB,IAAI,KAAK,GAAI,MAAM,kBAAkB,IAAI,CAAE;OACtC,IAAI,MAAM,SAAS,QAAQ,GAChC,IAAI,KAAK,IAAI;CAEjB;CACA,OAAO;AACT;;;;;;;AAQA,eAAsB,WACpB,WACA,oBAAoB,KACC;CACrB,MAAM,gCAAgB,IAAI,IAAuC;CACjE,IAAI,aAAa;CACjB,IAAI,iBAAiB;CACrB,IAAI,gBAAgB;CAEpB,KAAK,MAAM,QAAQ,MAAM,kBAAkB,SAAS,GAAG;EACrD,MAAM,KAAK,gBAAgB;GACzB,OAAO,iBAAiB,MAAM,EAAE,UAAU,OAAO,CAAC;GAClD,WAAW;EACb,CAAC;EACD,WAAW,MAAM,OAAO,IAAI;GAC1B,IAAI,IAAI,KAAK,MAAM,IAAI;GACvB,IAAI;GACJ,IAAI;IACF,MAAM,KAAK,MAAM,GAAG;GACtB,QAAQ;IACN,kBAAkB;IAClB;GACF;GACA,cAAc;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,aAAa,OAAO;EAC7B,QAAQ,YAAY,OAAO;EAC3B,OAAO,iBAAiB,OAAO;CAEjB,EAAE;CAClB,IAAI,SAAS,KAAA,GAAW,OAAO,IAAI,kBAAkB,IAAI,EAAE;CAC3D,OAAO,UAAU,IAAI,OAAO,eAAe,KAAK,KAAK;AACvD;;;;;;;;AASA,SAAgB,kBACd,QACA,MACA,OACQ;CACR,MAAM,SAAmB,CACvB,eACA,eAAe,kBAAkB,IAAI,EAAE,EACzC;CACA,KAAK,MAAM,CAAC,MAAM,UAAU,MAAM,QAAQ;EACxC,IAAI,SAAS,UAAU,CAAC,MAAM,UAAU;EACxC,MAAM,OAAO,UAAU,MAAM,MAAM,KAAK;EACxC,IAAI,MAAM,OAAO,KAAK,IAAI;CAC5B;CACA,OAAO;EACL,YAAY,OAAO;EACnB,YAAY,OAAO,KAAK,WAAW;EACnC;CACF,CAAC,CAAC,KAAK,IAAI;AACb"}
|
|
1
|
+
{"version":3,"file":"emit-guards-DSL78hvA.js","names":["IDENTIFIER_RE","escapeSingleQuote"],"sources":["../src/scanner.ts","../src/infer.ts","../src/emit-types.ts","../src/emit-guards.ts"],"sourcesContent":["import { readdir, stat } from 'node:fs/promises'\nimport { createReadStream } from 'node:fs'\nimport { createInterface } from 'node:readline'\nimport path from 'node:path'\n\n/** スキャン結果。 */\nexport interface ScanResult {\n /** type 文字列 → その type の生 JSON オブジェクト配列。 */\n samplesByType: Map<string, Record<string, unknown>[]>\n /** 走査した有効行数 (パース成功)。 */\n totalLines: number\n /** JSON 構文エラー行数。 */\n malformedLines: number\n /** type フィールドを持たない/文字列でない行数。 */\n typelessLines: number\n}\n\n/**\n * `.jsonl` ファイルを再帰収集する。\n *\n * @param dir - 起点ディレクトリ\n * @returns 絶対パス配列\n */\nasync function collectJsonlFiles(dir: string): Promise<string[]> {\n const out: string[] = []\n for (const entry of await readdir(dir)) {\n const full = path.join(dir, entry)\n const st = await stat(full)\n if (st.isDirectory()) {\n out.push(...(await collectJsonlFiles(full)))\n } else if (entry.endsWith('.jsonl')) {\n out.push(full)\n }\n }\n return out\n}\n\n/**\n * コーパスを走査し type ごとに生サンプルを集約する。\n *\n * @param corpusDir - コーパスのルートディレクトリ\n * @param maxSamplesPerType - type ごとの保持上限 (メモリ保護、既定 5000)\n */\nexport async function scanCorpus(\n corpusDir: string,\n maxSamplesPerType = 5000\n): Promise<ScanResult> {\n const samplesByType = new Map<string, Record<string, unknown>[]>()\n let totalLines = 0\n let malformedLines = 0\n let typelessLines = 0\n\n for (const file of await collectJsonlFiles(corpusDir)) {\n const rl = createInterface({\n input: createReadStream(file, { encoding: 'utf8' }),\n crlfDelay: Infinity,\n })\n for await (const raw of rl) {\n if (raw.trim() === '') continue\n let obj: unknown\n try {\n obj = JSON.parse(raw)\n } catch {\n malformedLines += 1\n continue\n }\n totalLines += 1\n if (\n typeof obj !== 'object' || obj === null || Array.isArray(obj) ||\n typeof (obj as Record<string, unknown>).type !== 'string'\n ) {\n typelessLines += 1\n continue\n }\n const record = obj as Record<string, unknown>\n const type = record.type as string\n const bucket = samplesByType.get(type) ?? []\n if (bucket.length < maxSamplesPerType) {\n bucket.push(record)\n samplesByType.set(type, bucket)\n }\n }\n }\n\n return { samplesByType, totalLines, malformedLines, typelessLines }\n}\n","/** JSON 値の種別。 */\nexport type JsonKind = 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object'\n\n/**\n * JSON 値の種別を返す。\n *\n * @param v - 対象値\n */\nexport function jsonKind(v: unknown): JsonKind {\n if (v === null) return 'null'\n if (Array.isArray(v)) return 'array'\n const t = typeof v\n if ((['string', 'number', 'boolean'] as string[]).includes(t)) {\n return t as 'string' | 'number' | 'boolean'\n }\n return 'object'\n}\n\n/** 1 フィールドの推論結果。 */\nexport interface FieldShape {\n /** 全サンプルに存在したか。 */\n required: boolean\n /** 観測された JSON 種別集合。 */\n kinds: Set<JsonKind>\n /** 観測された文字列リテラル集合 (閾値以下のときのみ)。 */\n literals?: Set<string>\n}\n\n/** 1 type (または content ブロック) の推論結果。 */\nexport interface Shape {\n /** サンプル総数。 */\n count: number\n /** フィールド名 → 推論結果。 */\n fields: Map<string, FieldShape>\n}\n\n/** `InferOptions.maxLiterals` 省略時の既定値。 */\nconst DEFAULT_MAX_LITERALS = 20\n\n/** 推論オプション。 */\nexport interface InferOptions {\n /** 文字列リテラルを列挙として保持する上限。超えたら literals を破棄。既定は `DEFAULT_MAX_LITERALS`。 */\n maxLiterals?: number\n}\n\n/**\n * 同一 type のサンプル群からフィールド形状を推論する。\n *\n * @param samples - 生 JSON オブジェクト配列\n * @param options - 推論オプション\n */\nexport function inferShape(\n samples: Record<string, unknown>[],\n options: InferOptions = {}\n): Shape {\n const maxLiterals = options.maxLiterals ?? DEFAULT_MAX_LITERALS\n const count = samples.length\n const presence = new Map<string, number>()\n const kinds = new Map<string, Set<JsonKind>>()\n const literals = new Map<string, Set<string> | null>()\n\n for (const sample of samples) {\n for (const [key, value] of Object.entries(sample)) {\n presence.set(key, (presence.get(key) ?? 0) + 1)\n\n const kset = kinds.get(key) ?? new Set<JsonKind>()\n const kind = jsonKind(value)\n kset.add(kind)\n kinds.set(key, kset)\n\n // 文字列リテラル収集 (null は「破棄済み」マーカー)\n const cur = literals.get(key)\n if (cur === null) {\n // すでに破棄済み\n } else if (kind === 'string') {\n const set = cur ?? new Set<string>()\n set.add(value as string)\n if (set.size > maxLiterals) {\n literals.set(key, null)\n } else {\n literals.set(key, set)\n }\n }\n }\n }\n\n const fields = new Map<string, FieldShape>()\n for (const [key, seen] of presence) {\n const lit = literals.get(key)\n const kindSet = kinds.get(key) ?? new Set<JsonKind>()\n // 全て文字列だった場合のみ literals を採用する\n const allString = kindSet.size === 1 && kindSet.has('string')\n fields.set(key, {\n required: seen === count,\n kinds: kindSet,\n literals: allString && lit ? lit : undefined,\n })\n }\n\n return { count, fields }\n}\n","import type { JsonKind, Shape } from './infer'\n\n/** JS 識別子として安全な名前かどうかを判定する正規表現。 */\nconst IDENTIFIER_RE = /^[A-Za-z_$][\\w$]*$/\n\n/** シングルクォート文字列リテラルとして安全になるよう `'` をエスケープする。 */\nfunction escapeSingleQuote(s: string): string {\n return s.replaceAll('\\'', String.raw`\\'`)\n}\n\n/**\n * 観測種別集合 (と任意のリテラル集合) を TypeScript 型文字列に写像する。\n *\n * @param kinds - 観測された JSON 種別\n * @param literals - 文字列リテラル集合 (あれば)\n */\nexport function tsTypeOf(kinds: Set<JsonKind>, literals?: Set<string>): string {\n const parts: string[] = []\n const mapped: Record<JsonKind, string> = {\n string: 'string',\n number: 'number',\n boolean: 'boolean',\n null: 'null',\n array: 'unknown[]',\n object: 'Record<string, unknown>',\n }\n // 文字列リテラルが与えられていれば開いた union にする\n if (literals && literals.size > 0 && kinds.has('string')) {\n const lits = [...literals].toSorted().map((s) => `'${escapeSingleQuote(s)}'`)\n parts.push(`${lits.join(' | ')} | (string & {})`)\n } else if (kinds.has('string')) {\n parts.push('string')\n }\n for (const k of ['number', 'boolean', 'array', 'object', 'null'] as JsonKind[]) {\n if (kinds.has(k)) parts.push(mapped[k])\n }\n // 重複除去して結合\n return [...new Set(parts)].join(' | ')\n}\n\n/** JS 識別子として安全ならそのまま、そうでなければクォートする。 */\nfunction propKey(name: string): string {\n return IDENTIFIER_RE.test(name) ? name : `'${escapeSingleQuote(name)}'`\n}\n\n/** interface 名として使うため type 文字列を PascalCase 化する (エミッタ内部用)。 */\nexport function pascalCase(type: string): string {\n return type\n .split(/[-_]/)\n .map((p) => p.charAt(0).toUpperCase() + p.slice(1))\n .join('')\n}\n\n/**\n * 1 type の interface 文字列を生成する。\n *\n * @param interfaceName - 出力する interface 名 (例 LastPromptEntry)\n * @param type - 判別子文字列 (例 last-prompt)\n * @param shape - 推論結果\n */\nexport function emitInterface(\n interfaceName: string,\n type: string,\n shape: Shape\n): string {\n const lines: string[] = [\n `export interface ${interfaceName} {`,\n ` _kind: 'known'`,\n ` type: '${escapeSingleQuote(type)}'`,\n ]\n for (const [name, field] of shape.fields) {\n if (name === 'type') continue\n const opt = field.required ? '' : '?'\n const tsType = tsTypeOf(field.kinds, field.literals)\n lines.push(` ${propKey(name)}${opt}: ${tsType}`)\n }\n lines.push('}')\n return lines.join('\\n')\n}\n","import type { JsonKind, Shape } from './infer'\n\n/** JS 識別子として安全な名前かどうかを判定する正規表現。 */\nconst IDENTIFIER_RE = /^[A-Za-z_$][\\w$]*$/\n\n/** シングルクォート文字列リテラルとして安全になるよう `'` をエスケープする。 */\nfunction escapeSingleQuote(s: string): string {\n return s.replaceAll('\\'', String.raw`\\'`)\n}\n\n/** 単一種別の required フィールドに対する検査式を返す。 */\nfunction checkExpr(name: string, kinds: Set<JsonKind>): string | undefined {\n const access = `v.${IDENTIFIER_RE.test(name) ? name : `['${escapeSingleQuote(name)}']`}`\n // object|null → isObject or null 許容\n const hasNull = kinds.has('null')\n const nonNull = [...kinds].filter((k) => k !== 'null')\n if (nonNull.length !== 1) {\n // 複数種別が混在する場合は存在確認のみ (過剰厳格を避ける)\n return `'${escapeSingleQuote(name)}' in v`\n }\n const kind = nonNull[0]\n const base: Partial<Record<JsonKind, string>> = {\n string: `isString(${access})`,\n number: `isNumber(${access})`,\n boolean: `isBoolean(${access})`,\n object: `isObject(${access})`,\n array: `Array.isArray(${access})`,\n }\n const expr = base[kind]\n if (expr === undefined) return `'${escapeSingleQuote(name)}' in v`\n return hasNull ? `(${access} === null || ${expr})` : expr\n}\n\n/**\n * 1 type のガード関数文字列を生成する。required フィールドのみ検査する。\n *\n * @param fnName - 関数名 (例 isMode)\n * @param type - 判別子\n * @param shape - 推論結果\n */\nexport function emitGuardFunction(\n fnName: string,\n type: string,\n shape: Shape\n): string {\n const checks: string[] = [\n `isObject(v)`,\n `v.type === '${escapeSingleQuote(type)}'`,\n ]\n for (const [name, field] of shape.fields) {\n if (name === 'type' || !field.required) continue\n const expr = checkExpr(name, field.kinds)\n if (expr) checks.push(expr)\n }\n return [\n `function ${fnName}(v: unknown): boolean {`,\n ` return ${checks.join(' &&\\n ')}`,\n `}`,\n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AAM,MAAM,KAAK;EACxC,IAAI,MAAM,OAAO,KAAK,IAAI;CAC5B;CACA,OAAO;EACL,YAAY,OAAO;EACnB,YAAY,OAAO,KAAK,WAAW;EACnC;CACF,CAAC,CAAC,KAAK,IAAI;AACb"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_emit_guards = require("./emit-guards-
|
|
2
|
+
const require_emit_guards = require("./emit-guards-BKEtrVDH.cjs");
|
|
3
3
|
let zod = require("zod");
|
|
4
|
-
|
|
4
|
+
// src/schemas.ts
|
|
5
5
|
const entryBase = {
|
|
6
6
|
cwd: zod.z.string(),
|
|
7
7
|
entrypoint: zod.z.string(),
|
|
@@ -207,7 +207,6 @@ const KNOWN_TYPES = Object.keys(entrySchemas);
|
|
|
207
207
|
function knownTypeSchema(type) {
|
|
208
208
|
return entrySchemas[type];
|
|
209
209
|
}
|
|
210
|
-
//#endregion
|
|
211
210
|
exports.KNOWN_TYPES = KNOWN_TYPES;
|
|
212
211
|
exports.emitGuardFunction = require_emit_guards.emitGuardFunction;
|
|
213
212
|
exports.emitInterface = require_emit_guards.emitInterface;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
//#region src/scanner.d.ts
|
|
3
2
|
/** スキャン結果。 */
|
|
4
3
|
interface ScanResult {
|
|
5
4
|
/** type 文字列 → その type の生 JSON オブジェクト配列。 */
|
|
@@ -18,8 +17,6 @@ interface ScanResult {
|
|
|
18
17
|
* @param maxSamplesPerType - type ごとの保持上限 (メモリ保護、既定 5000)
|
|
19
18
|
*/
|
|
20
19
|
export declare function scanCorpus(corpusDir: string, maxSamplesPerType?: number): Promise<ScanResult>;
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/infer.d.ts
|
|
23
20
|
/** JSON 値の種別。 */
|
|
24
21
|
type JsonKind = 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object';
|
|
25
22
|
/**
|
|
@@ -56,8 +53,6 @@ interface InferOptions {
|
|
|
56
53
|
* @param options - 推論オプション
|
|
57
54
|
*/
|
|
58
55
|
export declare function inferShape(samples: Record<string, unknown>[], options?: InferOptions): Shape;
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/schemas.d.ts
|
|
61
56
|
/** type 文字列 → 公開 zod スキーマ。 */
|
|
62
57
|
export declare const entrySchemas: {
|
|
63
58
|
readonly assistant: z.ZodObject<{
|
|
@@ -285,8 +280,6 @@ export declare const KNOWN_TYPES: string[];
|
|
|
285
280
|
* @param type - 判別子
|
|
286
281
|
*/
|
|
287
282
|
export declare function knownTypeSchema(type: string): z.ZodType | undefined;
|
|
288
|
-
//#endregion
|
|
289
|
-
//#region src/emit-types.d.ts
|
|
290
283
|
/**
|
|
291
284
|
* 観測種別集合 (と任意のリテラル集合) を TypeScript 型文字列に写像する。
|
|
292
285
|
*
|
|
@@ -304,8 +297,6 @@ export declare function pascalCase(type: string): string;
|
|
|
304
297
|
* @param shape - 推論結果
|
|
305
298
|
*/
|
|
306
299
|
export declare function emitInterface(interfaceName: string, type: string, shape: Shape): string;
|
|
307
|
-
//#endregion
|
|
308
|
-
//#region src/emit-guards.d.ts
|
|
309
300
|
/**
|
|
310
301
|
* 1 type のガード関数文字列を生成する。required フィールドのみ検査する。
|
|
311
302
|
*
|
|
@@ -314,6 +305,5 @@ export declare function emitInterface(interfaceName: string, type: string, shape
|
|
|
314
305
|
* @param shape - 推論結果
|
|
315
306
|
*/
|
|
316
307
|
export declare function emitGuardFunction(fnName: string, type: string, shape: Shape): string;
|
|
317
|
-
//#endregion
|
|
318
308
|
export type { FieldShape, InferOptions, JsonKind, ScanResult, Shape };
|
|
319
309
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/scanner.ts","../src/infer.ts","../src/schemas.ts","../src/emit-types.ts","../src/emit-guards.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/scanner.ts","../src/infer.ts","../src/schemas.ts","../src/emit-types.ts","../src/emit-guards.ts"],"mappings":";;UAMiB;;EAEf,eAAe,YAAY;;EAE3B;;EAEA;;EAEA;;;;;;;;wBA6BoB,WACpB,mBACA,6BACC,QAAQ;;KC7CC;;;;;;wBAOI,SAAS,aAAa;;UAWrB;;EAEf;;EAEA,OAAO,IAAI;;EAEX,WAAW;;;UAII;;EAEf;;EAEA,QAAQ,YAAY;;;UAOL;;EAEf;;;;;;;;wBASc,WACd,SAAS,2BACT,UAAS,eACR;;qBCuFU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkBA;;;;;;wBAOG,gBAAgB,eAAe,EAAE;;;;;;;wBCtJjC,SAAS,OAAO,IAAI,WAAW,WAAW;;wBA8B1C,WAAW;;;;;;;;wBAcX,cACd,uBACA,cACA,OAAO;;;;;;;;wBCvBO,kBACd,gBACA,cACA,OAAO"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
//#region src/scanner.d.ts
|
|
3
2
|
/** スキャン結果。 */
|
|
4
3
|
interface ScanResult {
|
|
5
4
|
/** type 文字列 → その type の生 JSON オブジェクト配列。 */
|
|
@@ -18,8 +17,6 @@ interface ScanResult {
|
|
|
18
17
|
* @param maxSamplesPerType - type ごとの保持上限 (メモリ保護、既定 5000)
|
|
19
18
|
*/
|
|
20
19
|
export declare function scanCorpus(corpusDir: string, maxSamplesPerType?: number): Promise<ScanResult>;
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/infer.d.ts
|
|
23
20
|
/** JSON 値の種別。 */
|
|
24
21
|
type JsonKind = 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object';
|
|
25
22
|
/**
|
|
@@ -56,8 +53,6 @@ interface InferOptions {
|
|
|
56
53
|
* @param options - 推論オプション
|
|
57
54
|
*/
|
|
58
55
|
export declare function inferShape(samples: Record<string, unknown>[], options?: InferOptions): Shape;
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/schemas.d.ts
|
|
61
56
|
/** type 文字列 → 公開 zod スキーマ。 */
|
|
62
57
|
export declare const entrySchemas: {
|
|
63
58
|
readonly assistant: z.ZodObject<{
|
|
@@ -285,8 +280,6 @@ export declare const KNOWN_TYPES: string[];
|
|
|
285
280
|
* @param type - 判別子
|
|
286
281
|
*/
|
|
287
282
|
export declare function knownTypeSchema(type: string): z.ZodType | undefined;
|
|
288
|
-
//#endregion
|
|
289
|
-
//#region src/emit-types.d.ts
|
|
290
283
|
/**
|
|
291
284
|
* 観測種別集合 (と任意のリテラル集合) を TypeScript 型文字列に写像する。
|
|
292
285
|
*
|
|
@@ -304,8 +297,6 @@ export declare function pascalCase(type: string): string;
|
|
|
304
297
|
* @param shape - 推論結果
|
|
305
298
|
*/
|
|
306
299
|
export declare function emitInterface(interfaceName: string, type: string, shape: Shape): string;
|
|
307
|
-
//#endregion
|
|
308
|
-
//#region src/emit-guards.d.ts
|
|
309
300
|
/**
|
|
310
301
|
* 1 type のガード関数文字列を生成する。required フィールドのみ検査する。
|
|
311
302
|
*
|
|
@@ -314,6 +305,5 @@ export declare function emitInterface(interfaceName: string, type: string, shape
|
|
|
314
305
|
* @param shape - 推論結果
|
|
315
306
|
*/
|
|
316
307
|
export declare function emitGuardFunction(fnName: string, type: string, shape: Shape): string;
|
|
317
|
-
//#endregion
|
|
318
308
|
export type { FieldShape, InferOptions, JsonKind, ScanResult, Shape };
|
|
319
309
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/scanner.ts","../src/infer.ts","../src/schemas.ts","../src/emit-types.ts","../src/emit-guards.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/scanner.ts","../src/infer.ts","../src/schemas.ts","../src/emit-types.ts","../src/emit-guards.ts"],"mappings":";;UAMiB;;EAEf,eAAe,YAAY;;EAE3B;;EAEA;;EAEA;;;;;;;;wBA6BoB,WACpB,mBACA,6BACC,QAAQ;;KC7CC;;;;;;wBAOI,SAAS,aAAa;;UAWrB;;EAEf;;EAEA,OAAO,IAAI;;EAEX,WAAW;;;UAII;;EAEf;;EAEA,QAAQ,YAAY;;;UAOL;;EAEf;;;;;;;;wBASc,WACd,SAAS,2BACT,UAAS,eACR;;qBCuFU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkBA;;;;;;wBAOG,gBAAgB,eAAe,EAAE;;;;;;;wBCtJjC,SAAS,OAAO,IAAI,WAAW,WAAW;;wBA8B1C,WAAW;;;;;;;;wBAcX,cACd,uBACA,cACA,OAAO;;;;;;;;wBCvBO,kBACd,gBACA,cACA,OAAO"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as inferShape, i as tsTypeOf, n as emitInterface, o as jsonKind, r as pascalCase, s as scanCorpus, t as emitGuardFunction } from "./emit-guards-
|
|
1
|
+
import { a as inferShape, i as tsTypeOf, n as emitInterface, o as jsonKind, r as pascalCase, s as scanCorpus, t as emitGuardFunction } from "./emit-guards-DSL78hvA.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
3
|
+
// src/schemas.ts
|
|
4
4
|
const entryBase = {
|
|
5
5
|
cwd: z.string(),
|
|
6
6
|
entrypoint: z.string(),
|
|
@@ -206,7 +206,6 @@ const KNOWN_TYPES = Object.keys(entrySchemas);
|
|
|
206
206
|
function knownTypeSchema(type) {
|
|
207
207
|
return entrySchemas[type];
|
|
208
208
|
}
|
|
209
|
-
//#endregion
|
|
210
209
|
export { KNOWN_TYPES, emitGuardFunction, emitInterface, entrySchemas, inferShape, jsonKind, knownTypeSchema, pascalCase, scanCorpus, tsTypeOf };
|
|
211
210
|
|
|
212
211
|
//# sourceMappingURL=index.js.map
|