@rex0220/kintone-sql-tools 3.75.0 → 3.77.0
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/README.md +50 -1
- package/dist-cli/ksql.js +17542 -235
- package/dist-engine/index.cjs +15 -15
- package/dist-engine/index.mjs +15 -15
- package/dist-engine/ksql-engine.umd.js +15 -15
- package/dist-engine/meta/bundle-baseline.json +7 -7
- package/dist-engine/meta/cjs.json +9 -9
- package/dist-engine/meta/esm.json +9 -9
- package/dist-engine/meta/umd.json +9 -9
- package/dist-flow/export/types.d.ts +56 -0
- package/dist-flow/flow-library/exportSinks.d.ts +5 -0
- package/dist-flow/flow-library/index.d.ts +2 -1
- package/dist-flow/flow-library/publicTypes.d.ts +32 -0
- package/dist-flow/index.cjs +15 -11
- package/dist-flow/index.mjs +15 -11
- package/dist-flow/meta/cjs.json +178 -12
- package/dist-flow/meta/esm.json +182 -12
- package/dist-mcp/ksql-mcp.js +29 -6
- package/dist-mcpb/ksql-mcp.mcpb +0 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -188,6 +188,10 @@ Options:
|
|
|
188
188
|
--var <name=value> Override a DECLARE variable (repeatable; not for secrets)
|
|
189
189
|
--import-csv <name=path> Supply named CSV and enable IMPORT (repeatable)
|
|
190
190
|
--import-json <name=path> Supply named JSON and enable IMPORT (repeatable)
|
|
191
|
+
--export-csv <name=path> Export temp table #<name> as RFC 4180 CSV after the batch succeeds (repeatable)
|
|
192
|
+
--export-csv <path> Export the result of a single SELECT as CSV (no name; path must not contain '=')
|
|
193
|
+
--export-encoding <type> CSV export encoding: utf8 | sjis (default: utf8; unrepresentable characters fail)
|
|
194
|
+
--export-timezone <zone> IANA timezone for DATETIME cells in CSV export (default: keep UTC)
|
|
191
195
|
--format <type> Output format: table | json | jsonl | csv | markdown | md
|
|
192
196
|
(batch + json: prints one JSON envelope for the whole batch)
|
|
193
197
|
--max-records <n> Max records to fetch (default: 500)
|
|
@@ -238,6 +242,12 @@ Options:
|
|
|
238
242
|
```
|
|
239
243
|
<!-- END_HELP_SYNC -->
|
|
240
244
|
|
|
245
|
+
`--export-csv` の引数規則: 最初の `=` で `name` と `path` に分割し、`=` を含む引数は必ず名前付き(左辺が temp table
|
|
246
|
+
識別子でなければ ArgumentError。`C:\...` の `:` は区切りではない)。名前なし `<path>` は単文 SELECT のときだけ・1 件だけで、
|
|
247
|
+
`=` を含む path には使えない。同じ名前・同じ path の重複、`--output` と同じ path、`--dry-run` との併用は実行前に拒否。
|
|
248
|
+
SQL 全文が成功した後にだけ全 sink を serialize し、同一 directory の一時 file → fsync → close → rename で書く
|
|
249
|
+
(失敗時は旧 file 維持・一時 file 削除)。既存 file を他プロセスが開いている Windows では `EPERM` で失敗し旧 file が残る。
|
|
250
|
+
|
|
241
251
|
## 最低限のトラブルシュート
|
|
242
252
|
|
|
243
253
|
1. `ArgumentError: no APPxxx found...`
|
|
@@ -267,7 +277,7 @@ npm パッケージは 2 つのサブパスを **semver 対象の公開 API**
|
|
|
267
277
|
| サブパス | 用途 | 主な export |
|
|
268
278
|
|---|---|---|
|
|
269
279
|
| `@rex0220/kintone-sql-tools/engine` | **read-only** のクエリ実行(ダッシュボード等)。書込 API は構造的に遮断 | `runQuery` / `runBatch` / `explainQuery` / `createReadonlyKintoneClient` / `KsqlEngineError` / `version` |
|
|
270
|
-
| `@rex0220/kintone-sql-tools/flow` | **Flow dialect 1**(→ [言語リファレンス §27](docs/ksql_language_reference.md))のスクリプト解析・検証・**文単位実行**(バッチランナー向け・書込可能) | `parseScript` / `validateScript` / `explainScript`(`asOf`/`timezone` 注入可) / `createExecutionContext`(`onChunkWritten`
|
|
280
|
+
| `@rex0220/kintone-sql-tools/flow` | **Flow dialect 1**(→ [言語リファレンス §27](docs/ksql_language_reference.md))のスクリプト解析・検証・**文単位実行**(バッチランナー向け・書込可能) | `parseScript` / `validateScript` / `explainScript`(`asOf`/`timezone` 注入可) / `createExecutionContext`(`onChunkWritten` 書込チャンク通知・`onImportSourceMaterialized` IMPORT receipt) / `executeStatement` / `previewStatement`(dry-run 差分プレビュー・書込 0 回) / `disposeExecutionContext` / `createImportSourceResolver` / `FlowImportProviderError` / `createKintoneClient` / `isDmlResult`(`FlowDmlResult` 型ガード) / `version` |
|
|
271
281
|
|
|
272
282
|
バッチ実行ランナー **kSQL Flow**(`/flow` API を使った公式ランナー・別リポジトリ): https://github.com/rex0220/ksql-flow
|
|
273
283
|
|
|
@@ -308,6 +318,10 @@ const importSource = createImportSourceResolver([{
|
|
|
308
318
|
const parsed = parseScript(sql, capability);
|
|
309
319
|
const ctx = createExecutionContext({
|
|
310
320
|
...capability, client, statements: parsed.statements, meta: parsed.meta, importSource,
|
|
321
|
+
onImportSourceMaterialized(info) {
|
|
322
|
+
// { statementIndex, name, kind, rows, encoding }
|
|
323
|
+
inputFiles.push(info);
|
|
324
|
+
},
|
|
311
325
|
});
|
|
312
326
|
```
|
|
313
327
|
|
|
@@ -317,6 +331,41 @@ path解決、通常ファイル・symlink・allowlist・hash検査、open/read
|
|
|
317
331
|
engineはpathを受け取りません。providerは `FlowImportProviderError` でread不能または通常ファイル外を
|
|
318
332
|
分類でき、その他のsource境界エラーも `StatementResult.error.code` の安定codeで返ります。
|
|
319
333
|
|
|
334
|
+
`onImportSourceMaterialized` はdecode・raw materialize成功直後、projection・validation・
|
|
335
|
+
`ON ERROR SKIP` の選別・mutationより前に1回awaitされます。CSVの `rows` はheaderを除く
|
|
336
|
+
RFC 4180 data record数(subtable CSVは継続行を含む)、JSONはtop-level record数です。
|
|
337
|
+
CSVの `encoding` は上記優先順位の解決後、JSONは `"utf8"` です。callbackがthrow/rejectすると
|
|
338
|
+
当該文はerrorになり、その文のmutation APIは0回です。通知objectのkeyは
|
|
339
|
+
`statementIndex` / `name` / `kind` / `rows` / `encoding` の5つだけです。
|
|
340
|
+
|
|
341
|
+
CSV export(B179)は temp table を名前付きシンクとして事前宣言し、全文実行後に serialize します。
|
|
342
|
+
engine は path を持たず bytes と receipt を返すだけで、file 書込みと sha256 は呼出側の責務です:
|
|
343
|
+
|
|
344
|
+
```ts
|
|
345
|
+
import {
|
|
346
|
+
createExecutionContext, executeStatement, exportSinkStatus, serializeExportSink,
|
|
347
|
+
serializeSelectResultAsCsv, disposeExecutionContext,
|
|
348
|
+
} from "@rex0220/kintone-sql-tools/flow";
|
|
349
|
+
|
|
350
|
+
const ctx = createExecutionContext({
|
|
351
|
+
client, script: "CREATE TEMP TABLE #export AS SELECT code, amount FROM APP1; UPDATE APP1 SET 状態 = '済' WHERE ...",
|
|
352
|
+
exportSinks: [{ name: "export" }], // #export の CREATE TEMP TABLE がちょうど 1 文なければ同期 throw
|
|
353
|
+
});
|
|
354
|
+
for (const statement of statements) await executeStatement(statement, ctx); // EXIT 後の skipped も回収
|
|
355
|
+
if (exportSinkStatus(ctx, "export") === "materialized") { // not-created = EXIT で未生成(file を作らない)
|
|
356
|
+
const csv = serializeExportSink(ctx, "export", { encoding: "utf8", timezone: "Asia/Tokyo" });
|
|
357
|
+
// csv.data (Uint8Array) を書く/sha256 を取る。csv.receipt = { rows, columns, bytes, encoding }
|
|
358
|
+
}
|
|
359
|
+
await disposeExecutionContext(ctx);
|
|
360
|
+
// 単文 SELECT: serializeSelectResultAsCsv(await executeStatement(stmt, ctx))
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
CSV は RFC 4180(CRLF・header あり・BOM なし)。複数値は LF 連結、user 系は `code`、SUBTABLE / FILE 列は
|
|
364
|
+
`ExportSinkUnsupportedColumnError`、計算列の指数表記は 10 進展開、DATETIME は `timezone` 指定時だけ offset 付き。
|
|
365
|
+
Shift_JIS は `encoding: "sjis"` と `encoder: { encoding: "sjis", encode(text) }` の注入で、encoder は表現不能文字で
|
|
366
|
+
throw する義務を負います(encoding-japanese / iconv-lite は黙って `?` 置換するため、encode → decode → 完全一致検査を
|
|
367
|
+
wrapper で行ってください)。
|
|
368
|
+
|
|
320
369
|
読取上限は既定 10,000 件(`maxRecords`)です。一時テーブルの実体化には**独立の** `tempTableMaxRows`(既定 10,000 行・超過は常にエラー)が適用されるため、大きなバッチでは両方を併せて指定してください:
|
|
321
370
|
|
|
322
371
|
```ts
|