@rex0220/kintone-sql-tools 2.9.0 → 2.10.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/dist-cli/ksql.js +81 -17
- package/dist-mcp/ksql-mcp.js +82 -18
- package/dist-mcpb/ksql-mcp.mcpb +0 -0
- package/package.json +1 -1
package/dist-cli/ksql.js
CHANGED
|
@@ -449,6 +449,9 @@ function isJapanese(cp) {
|
|
|
449
449
|
return cp >= 12352 && cp <= 12543 || cp >= 13312 && cp <= 40959 || cp >= 63744 && cp <= 64255 || cp >= 65281 && cp <= 65376;
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
+
// src/types/ast.ts
|
|
453
|
+
var NO_FROM_CTE_NAME = "__NO_FROM__";
|
|
454
|
+
|
|
452
455
|
// src/parser/parser.ts
|
|
453
456
|
var MAX_BATCH_STATEMENTS = 20;
|
|
454
457
|
var FUNC_CALL_PREFIX_KINDS = /* @__PURE__ */ new Set([
|
|
@@ -962,7 +965,7 @@ var Parser = class {
|
|
|
962
965
|
const distinct = this.consume("DISTINCT" /* DISTINCT */);
|
|
963
966
|
const columns = this.parseSelectColumns();
|
|
964
967
|
const hasFrom = this.consume("FROM" /* FROM */);
|
|
965
|
-
const from = hasFrom ? this.parseTableRef() : { appId: 0, alias: null, cteName:
|
|
968
|
+
const from = hasFrom ? this.parseTableRef() : { appId: 0, alias: null, cteName: NO_FROM_CTE_NAME };
|
|
966
969
|
const joins = hasFrom ? this.parseJoins() : [];
|
|
967
970
|
const where = this.consume("WHERE" /* WHERE */) ? this.parseWhereExpr() : null;
|
|
968
971
|
let groupBy = [];
|
|
@@ -2350,7 +2353,7 @@ function hasWhereClause(stmt) {
|
|
|
2350
2353
|
function isNoFromSelectStatement(stmt) {
|
|
2351
2354
|
if (!stmt || typeof stmt !== "object") return false;
|
|
2352
2355
|
const obj = stmt;
|
|
2353
|
-
return obj.type === "SELECT" && obj.from?.appId === 0 && obj.from?.cteName ===
|
|
2356
|
+
return obj.type === "SELECT" && obj.from?.appId === 0 && obj.from?.cteName === NO_FROM_CTE_NAME;
|
|
2354
2357
|
}
|
|
2355
2358
|
function getInsertValuesCount(stmt) {
|
|
2356
2359
|
if (!stmt || typeof stmt !== "object") return null;
|
|
@@ -4519,6 +4522,7 @@ async function fetchAll(fetcher, app, query, fields, options = {}) {
|
|
|
4519
4522
|
let windowOffset = 0;
|
|
4520
4523
|
const cursorQuery0 = buildCursorQuery(query, cursorId);
|
|
4521
4524
|
const first = await fetchPage(fetcher, app, cursorQuery0, fetchFields, pageSize, windowOffset);
|
|
4525
|
+
notifySearchAborted(first, options);
|
|
4522
4526
|
allRecords.push(...first.records);
|
|
4523
4527
|
if (allRecords.length > maxRecords) {
|
|
4524
4528
|
if (onLimit === "truncate") {
|
|
@@ -4562,6 +4566,7 @@ async function fetchAll(fetcher, app, query, fields, options = {}) {
|
|
|
4562
4566
|
(offset) => fetchPage(fetcher, app, cq, fetchFields, pageSize, offset)
|
|
4563
4567
|
)
|
|
4564
4568
|
);
|
|
4569
|
+
for (const response of responses) notifySearchAborted(response, options);
|
|
4565
4570
|
let done = false;
|
|
4566
4571
|
for (const res of responses) {
|
|
4567
4572
|
allRecords.push(...res.records);
|
|
@@ -4590,6 +4595,9 @@ async function fetchAll(fetcher, app, query, fields, options = {}) {
|
|
|
4590
4595
|
}
|
|
4591
4596
|
return allRecords;
|
|
4592
4597
|
}
|
|
4598
|
+
function notifySearchAborted(response, options) {
|
|
4599
|
+
if (response.searchAborted) options.onSearchAborted?.();
|
|
4600
|
+
}
|
|
4593
4601
|
function extractIds(records) {
|
|
4594
4602
|
return records.map((r) => {
|
|
4595
4603
|
const raw = r["$id"]?.value;
|
|
@@ -4646,7 +4654,8 @@ async function fetchRecordsForSharedPlan(getRecords, app, query, fields, options
|
|
|
4646
4654
|
maxRecords: options.maxRecords,
|
|
4647
4655
|
parallel: options.parallel,
|
|
4648
4656
|
onLimit: options.onLimit ?? "error",
|
|
4649
|
-
onTruncate: options.onTruncate
|
|
4657
|
+
onTruncate: options.onTruncate,
|
|
4658
|
+
onSearchAborted: options.onSearchAborted
|
|
4650
4659
|
});
|
|
4651
4660
|
return {
|
|
4652
4661
|
records,
|
|
@@ -5259,13 +5268,32 @@ function toFlatString(value) {
|
|
|
5259
5268
|
}
|
|
5260
5269
|
|
|
5261
5270
|
// src/execute.ts
|
|
5271
|
+
var SEARCH_ABORTED_WARNING = "\u691C\u7D22\u304C 10 \u4E07\u4EF6\u3067\u6253\u3061\u5207\u3089\u308C\u3001\u7D50\u679C\u304C\u6B20\u843D\u3057\u305F\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002";
|
|
5272
|
+
var SearchAbortedError = class extends Error {
|
|
5273
|
+
constructor() {
|
|
5274
|
+
super("SearchAbortedError: kintone \u306E\u691C\u7D22\u304C 10 \u4E07\u4EF6\u3067\u6253\u3061\u5207\u3089\u308C\u305F\u305F\u3081\u3001\u5B8C\u5168\u306A\u5BFE\u8C61\u96C6\u5408\u3092\u78BA\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002");
|
|
5275
|
+
this.name = "SearchAbortedError";
|
|
5276
|
+
}
|
|
5277
|
+
};
|
|
5262
5278
|
async function execute(sql, client, options = {}) {
|
|
5279
|
+
const startedAt = Date.now();
|
|
5280
|
+
const stmt = parseSql(sql);
|
|
5263
5281
|
const metrics = createEmptyMetrics();
|
|
5264
5282
|
const countedClient = wrapClientWithMetrics(client, metrics);
|
|
5265
|
-
const
|
|
5266
|
-
const
|
|
5283
|
+
const collector = { aborted: false };
|
|
5284
|
+
const guardedClient = wrapClientWithSearchAbort(
|
|
5285
|
+
countedClient,
|
|
5286
|
+
collector,
|
|
5287
|
+
!isSelectLikeStatement(stmt)
|
|
5288
|
+
);
|
|
5289
|
+
const result = await executeParsedStatement(
|
|
5290
|
+
stmt,
|
|
5291
|
+
guardedClient,
|
|
5292
|
+
options,
|
|
5293
|
+
options.cacheContext ?? "default"
|
|
5294
|
+
);
|
|
5267
5295
|
metrics.elapsedMs = Date.now() - startedAt;
|
|
5268
|
-
return { ...result, metrics };
|
|
5296
|
+
return { ...attachSearchAbortWarning(result, collector), metrics };
|
|
5269
5297
|
}
|
|
5270
5298
|
function createEmptyMetrics() {
|
|
5271
5299
|
return {
|
|
@@ -5314,10 +5342,27 @@ function wrapClientWithMetrics(client, metrics) {
|
|
|
5314
5342
|
}
|
|
5315
5343
|
};
|
|
5316
5344
|
}
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5345
|
+
function wrapClientWithSearchAbort(client, collector, failClosed) {
|
|
5346
|
+
return {
|
|
5347
|
+
...client,
|
|
5348
|
+
getRecords: async (params) => {
|
|
5349
|
+
const response = await client.getRecords(params);
|
|
5350
|
+
if (response.searchAborted) {
|
|
5351
|
+
collector.aborted = true;
|
|
5352
|
+
if (failClosed) throw new SearchAbortedError();
|
|
5353
|
+
}
|
|
5354
|
+
return response;
|
|
5355
|
+
}
|
|
5356
|
+
};
|
|
5357
|
+
}
|
|
5358
|
+
function isSelectLikeStatement(stmt) {
|
|
5359
|
+
return stmt.type === "SELECT" || stmt.type === "UNION" || stmt.type === "WITH";
|
|
5360
|
+
}
|
|
5361
|
+
function attachSearchAbortWarning(result, collector) {
|
|
5362
|
+
if (!collector.aborted || result.type !== "SELECT") return result;
|
|
5363
|
+
const warnings = new Set(result.warnings ?? []);
|
|
5364
|
+
warnings.add(SEARCH_ABORTED_WARNING);
|
|
5365
|
+
return { ...result, warnings: [...warnings] };
|
|
5321
5366
|
}
|
|
5322
5367
|
async function executeParsedStatement(stmt, client, options, cacheContext) {
|
|
5323
5368
|
const unresolved = findVariableRef(stmt);
|
|
@@ -5430,10 +5475,19 @@ async function executeBatch(sql, client, options = {}) {
|
|
|
5430
5475
|
targetAppId: info.targetAppId
|
|
5431
5476
|
})
|
|
5432
5477
|
} : batchOptions;
|
|
5478
|
+
const searchAbortCollector = { aborted: false };
|
|
5479
|
+
const statementClient = wrapClientWithSearchAbort(
|
|
5480
|
+
countedClient,
|
|
5481
|
+
searchAbortCollector,
|
|
5482
|
+
info.statementType !== "SELECT" && info.statementType !== "UNION" && info.statementType !== "WITH"
|
|
5483
|
+
);
|
|
5433
5484
|
const outcome = await runWithDeadline(
|
|
5434
|
-
executeBatchStatement(statements[i], info,
|
|
5485
|
+
executeBatchStatement(statements[i], info, statementClient, stmtOptions, cacheContext, tempTables, variables),
|
|
5435
5486
|
remaining
|
|
5436
5487
|
);
|
|
5488
|
+
if (outcome.result) {
|
|
5489
|
+
outcome.result = attachSearchAbortWarning(outcome.result, searchAbortCollector);
|
|
5490
|
+
}
|
|
5437
5491
|
results.push({ ...base, status: "success", ...outcome });
|
|
5438
5492
|
} catch (e) {
|
|
5439
5493
|
results.push({ ...base, status: "error", error: toBatchStatementError(e) });
|
|
@@ -5764,7 +5818,7 @@ async function executeSelect(stmt, client, options, cacheContext, cteCache) {
|
|
|
5764
5818
|
}
|
|
5765
5819
|
}
|
|
5766
5820
|
function isNoFromSelect(stmt) {
|
|
5767
|
-
return stmt.from.appId === 0 && stmt.from.cteName ===
|
|
5821
|
+
return stmt.from.appId === 0 && stmt.from.cteName === NO_FROM_CTE_NAME;
|
|
5768
5822
|
}
|
|
5769
5823
|
function arithHasFieldRef(node) {
|
|
5770
5824
|
if (node.type === "FIELD_REF") return true;
|
|
@@ -6225,7 +6279,7 @@ async function executeQueryWithCte(query, client, options, cteCache, cacheContex
|
|
|
6225
6279
|
const rows = query.all ? combined : deduplicateRows(combined, leftCols);
|
|
6226
6280
|
return { type: "SELECT", rows, columns: leftCols, rowCount: rows.length };
|
|
6227
6281
|
}
|
|
6228
|
-
const hasCteRef = query.from.cteName != null || query.joins.some((j) => j.table.cteName != null);
|
|
6282
|
+
const hasCteRef = query.from.cteName != null && query.from.cteName !== NO_FROM_CTE_NAME || query.joins.some((j) => j.table.cteName != null);
|
|
6229
6283
|
if (!hasCteRef) {
|
|
6230
6284
|
return executeSelect(query, client, options, cacheContext, cteCache);
|
|
6231
6285
|
}
|
|
@@ -8269,10 +8323,11 @@ function detectSortKind(fieldType, calcFormat) {
|
|
|
8269
8323
|
}
|
|
8270
8324
|
|
|
8271
8325
|
// src/cli/nodeKintoneClient.ts
|
|
8326
|
+
var SEARCH_ABORTED_HEADER_VALUE = "Filter aborted because of too many search results";
|
|
8272
8327
|
function createNodeKintoneClient(baseUrl, tokenResolver) {
|
|
8273
8328
|
const normalizedBaseUrl = baseUrl.replace(/\/+$/, "");
|
|
8274
8329
|
const apiBasePath = tokenResolver.guestSpaceId && tokenResolver.guestSpaceId > 0 ? `/k/guest/${tokenResolver.guestSpaceId}/v1` : "/k/v1";
|
|
8275
|
-
async function
|
|
8330
|
+
async function requestJsonResponse(path, init, appIdForToken) {
|
|
8276
8331
|
const headers = new Headers(init.headers ?? {});
|
|
8277
8332
|
if (tokenResolver.auth.type === "token") {
|
|
8278
8333
|
headers.set("X-Cybozu-API-Token", tokenResolver.auth.resolveToken(appIdForToken));
|
|
@@ -8320,7 +8375,14 @@ function createNodeKintoneClient(baseUrl, tokenResolver) {
|
|
|
8320
8375
|
if (tokenResolver.debug) {
|
|
8321
8376
|
tokenResolver.log?.(`[debug] response status=${res.status}`);
|
|
8322
8377
|
}
|
|
8323
|
-
|
|
8378
|
+
const warning = res.headers.get("X-Cybozu-Warning") ?? "";
|
|
8379
|
+
return {
|
|
8380
|
+
body: await res.json(),
|
|
8381
|
+
searchAborted: warning.includes(SEARCH_ABORTED_HEADER_VALUE)
|
|
8382
|
+
};
|
|
8383
|
+
}
|
|
8384
|
+
async function requestJson(path, init, appIdForToken) {
|
|
8385
|
+
return (await requestJsonResponse(path, init, appIdForToken)).body;
|
|
8324
8386
|
}
|
|
8325
8387
|
function shouldRetryWithRecordNumberOrder(path, bodyText) {
|
|
8326
8388
|
if (!path.includes("/v1/records.json?")) return false;
|
|
@@ -8354,11 +8416,12 @@ function createNodeKintoneClient(baseUrl, tokenResolver) {
|
|
|
8354
8416
|
}
|
|
8355
8417
|
const path = `${apiBasePath}/records.json?${qs}`;
|
|
8356
8418
|
try {
|
|
8357
|
-
|
|
8419
|
+
const response = await requestJsonResponse(
|
|
8358
8420
|
path,
|
|
8359
8421
|
{ method: "GET" },
|
|
8360
8422
|
params.app
|
|
8361
8423
|
);
|
|
8424
|
+
return response.searchAborted ? { ...response.body, searchAborted: true } : response.body;
|
|
8362
8425
|
} catch (err) {
|
|
8363
8426
|
const msg = err instanceof Error ? err.message : String(err);
|
|
8364
8427
|
if (!shouldRetryWithRecordNumberOrder(path, msg)) throw err;
|
|
@@ -8366,11 +8429,12 @@ function createNodeKintoneClient(baseUrl, tokenResolver) {
|
|
|
8366
8429
|
if (tokenResolver.debug) {
|
|
8367
8430
|
tokenResolver.log?.("[debug] retry with fallback query order by \u30EC\u30B3\u30FC\u30C9\u756A\u53F7 asc");
|
|
8368
8431
|
}
|
|
8369
|
-
|
|
8432
|
+
const response = await requestJsonResponse(
|
|
8370
8433
|
retryPath,
|
|
8371
8434
|
{ method: "GET" },
|
|
8372
8435
|
params.app
|
|
8373
8436
|
);
|
|
8437
|
+
return response.searchAborted ? { ...response.body, searchAborted: true } : response.body;
|
|
8374
8438
|
}
|
|
8375
8439
|
},
|
|
8376
8440
|
async postRecords(_params) {
|
package/dist-mcp/ksql-mcp.js
CHANGED
|
@@ -31362,6 +31362,9 @@ function isJapanese(cp) {
|
|
|
31362
31362
|
return cp >= 12352 && cp <= 12543 || cp >= 13312 && cp <= 40959 || cp >= 63744 && cp <= 64255 || cp >= 65281 && cp <= 65376;
|
|
31363
31363
|
}
|
|
31364
31364
|
|
|
31365
|
+
// src/types/ast.ts
|
|
31366
|
+
var NO_FROM_CTE_NAME = "__NO_FROM__";
|
|
31367
|
+
|
|
31365
31368
|
// src/parser/parser.ts
|
|
31366
31369
|
var MAX_BATCH_STATEMENTS = 20;
|
|
31367
31370
|
var FUNC_CALL_PREFIX_KINDS = /* @__PURE__ */ new Set([
|
|
@@ -31875,7 +31878,7 @@ var Parser = class {
|
|
|
31875
31878
|
const distinct = this.consume("DISTINCT" /* DISTINCT */);
|
|
31876
31879
|
const columns = this.parseSelectColumns();
|
|
31877
31880
|
const hasFrom = this.consume("FROM" /* FROM */);
|
|
31878
|
-
const from = hasFrom ? this.parseTableRef() : { appId: 0, alias: null, cteName:
|
|
31881
|
+
const from = hasFrom ? this.parseTableRef() : { appId: 0, alias: null, cteName: NO_FROM_CTE_NAME };
|
|
31879
31882
|
const joins = hasFrom ? this.parseJoins() : [];
|
|
31880
31883
|
const where = this.consume("WHERE" /* WHERE */) ? this.parseWhereExpr() : null;
|
|
31881
31884
|
let groupBy = [];
|
|
@@ -33263,7 +33266,7 @@ function hasWhereClause(stmt) {
|
|
|
33263
33266
|
function isNoFromSelectStatement(stmt) {
|
|
33264
33267
|
if (!stmt || typeof stmt !== "object") return false;
|
|
33265
33268
|
const obj = stmt;
|
|
33266
|
-
return obj.type === "SELECT" && obj.from?.appId === 0 && obj.from?.cteName ===
|
|
33269
|
+
return obj.type === "SELECT" && obj.from?.appId === 0 && obj.from?.cteName === NO_FROM_CTE_NAME;
|
|
33267
33270
|
}
|
|
33268
33271
|
function getInsertValuesCount(stmt) {
|
|
33269
33272
|
if (!stmt || typeof stmt !== "object") return null;
|
|
@@ -35420,6 +35423,7 @@ async function fetchAll(fetcher, app, query, fields, options = {}) {
|
|
|
35420
35423
|
let windowOffset = 0;
|
|
35421
35424
|
const cursorQuery0 = buildCursorQuery(query, cursorId);
|
|
35422
35425
|
const first = await fetchPage(fetcher, app, cursorQuery0, fetchFields, pageSize, windowOffset);
|
|
35426
|
+
notifySearchAborted(first, options);
|
|
35423
35427
|
allRecords.push(...first.records);
|
|
35424
35428
|
if (allRecords.length > maxRecords2) {
|
|
35425
35429
|
if (onLimit2 === "truncate") {
|
|
@@ -35463,6 +35467,7 @@ async function fetchAll(fetcher, app, query, fields, options = {}) {
|
|
|
35463
35467
|
(offset) => fetchPage(fetcher, app, cq, fetchFields, pageSize, offset)
|
|
35464
35468
|
)
|
|
35465
35469
|
);
|
|
35470
|
+
for (const response of responses) notifySearchAborted(response, options);
|
|
35466
35471
|
let done = false;
|
|
35467
35472
|
for (const res of responses) {
|
|
35468
35473
|
allRecords.push(...res.records);
|
|
@@ -35491,6 +35496,9 @@ async function fetchAll(fetcher, app, query, fields, options = {}) {
|
|
|
35491
35496
|
}
|
|
35492
35497
|
return allRecords;
|
|
35493
35498
|
}
|
|
35499
|
+
function notifySearchAborted(response, options) {
|
|
35500
|
+
if (response.searchAborted) options.onSearchAborted?.();
|
|
35501
|
+
}
|
|
35494
35502
|
function extractIds(records) {
|
|
35495
35503
|
return records.map((r) => {
|
|
35496
35504
|
const raw = r["$id"]?.value;
|
|
@@ -35547,7 +35555,8 @@ async function fetchRecordsForSharedPlan(getRecords, app, query, fields, options
|
|
|
35547
35555
|
maxRecords: options.maxRecords,
|
|
35548
35556
|
parallel: options.parallel,
|
|
35549
35557
|
onLimit: options.onLimit ?? "error",
|
|
35550
|
-
onTruncate: options.onTruncate
|
|
35558
|
+
onTruncate: options.onTruncate,
|
|
35559
|
+
onSearchAborted: options.onSearchAborted
|
|
35551
35560
|
});
|
|
35552
35561
|
return {
|
|
35553
35562
|
records,
|
|
@@ -36160,13 +36169,32 @@ function toFlatString(value) {
|
|
|
36160
36169
|
}
|
|
36161
36170
|
|
|
36162
36171
|
// src/execute.ts
|
|
36172
|
+
var SEARCH_ABORTED_WARNING = "\u691C\u7D22\u304C 10 \u4E07\u4EF6\u3067\u6253\u3061\u5207\u3089\u308C\u3001\u7D50\u679C\u304C\u6B20\u843D\u3057\u305F\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002";
|
|
36173
|
+
var SearchAbortedError = class extends Error {
|
|
36174
|
+
constructor() {
|
|
36175
|
+
super("SearchAbortedError: kintone \u306E\u691C\u7D22\u304C 10 \u4E07\u4EF6\u3067\u6253\u3061\u5207\u3089\u308C\u305F\u305F\u3081\u3001\u5B8C\u5168\u306A\u5BFE\u8C61\u96C6\u5408\u3092\u78BA\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002");
|
|
36176
|
+
this.name = "SearchAbortedError";
|
|
36177
|
+
}
|
|
36178
|
+
};
|
|
36163
36179
|
async function execute(sql, client, options = {}) {
|
|
36180
|
+
const startedAt = Date.now();
|
|
36181
|
+
const stmt = parseSql(sql);
|
|
36164
36182
|
const metrics = createEmptyMetrics();
|
|
36165
36183
|
const countedClient = wrapClientWithMetrics(client, metrics);
|
|
36166
|
-
const
|
|
36167
|
-
const
|
|
36184
|
+
const collector = { aborted: false };
|
|
36185
|
+
const guardedClient = wrapClientWithSearchAbort(
|
|
36186
|
+
countedClient,
|
|
36187
|
+
collector,
|
|
36188
|
+
!isSelectLikeStatement(stmt)
|
|
36189
|
+
);
|
|
36190
|
+
const result = await executeParsedStatement(
|
|
36191
|
+
stmt,
|
|
36192
|
+
guardedClient,
|
|
36193
|
+
options,
|
|
36194
|
+
options.cacheContext ?? "default"
|
|
36195
|
+
);
|
|
36168
36196
|
metrics.elapsedMs = Date.now() - startedAt;
|
|
36169
|
-
return { ...result, metrics };
|
|
36197
|
+
return { ...attachSearchAbortWarning(result, collector), metrics };
|
|
36170
36198
|
}
|
|
36171
36199
|
function createEmptyMetrics() {
|
|
36172
36200
|
return {
|
|
@@ -36215,10 +36243,27 @@ function wrapClientWithMetrics(client, metrics) {
|
|
|
36215
36243
|
}
|
|
36216
36244
|
};
|
|
36217
36245
|
}
|
|
36218
|
-
|
|
36219
|
-
|
|
36220
|
-
|
|
36221
|
-
|
|
36246
|
+
function wrapClientWithSearchAbort(client, collector, failClosed) {
|
|
36247
|
+
return {
|
|
36248
|
+
...client,
|
|
36249
|
+
getRecords: async (params) => {
|
|
36250
|
+
const response = await client.getRecords(params);
|
|
36251
|
+
if (response.searchAborted) {
|
|
36252
|
+
collector.aborted = true;
|
|
36253
|
+
if (failClosed) throw new SearchAbortedError();
|
|
36254
|
+
}
|
|
36255
|
+
return response;
|
|
36256
|
+
}
|
|
36257
|
+
};
|
|
36258
|
+
}
|
|
36259
|
+
function isSelectLikeStatement(stmt) {
|
|
36260
|
+
return stmt.type === "SELECT" || stmt.type === "UNION" || stmt.type === "WITH";
|
|
36261
|
+
}
|
|
36262
|
+
function attachSearchAbortWarning(result, collector) {
|
|
36263
|
+
if (!collector.aborted || result.type !== "SELECT") return result;
|
|
36264
|
+
const warnings = new Set(result.warnings ?? []);
|
|
36265
|
+
warnings.add(SEARCH_ABORTED_WARNING);
|
|
36266
|
+
return { ...result, warnings: [...warnings] };
|
|
36222
36267
|
}
|
|
36223
36268
|
async function executeParsedStatement(stmt, client, options, cacheContext) {
|
|
36224
36269
|
const unresolved = findVariableRef(stmt);
|
|
@@ -36331,10 +36376,19 @@ async function executeBatch(sql, client, options = {}) {
|
|
|
36331
36376
|
targetAppId: info.targetAppId
|
|
36332
36377
|
})
|
|
36333
36378
|
} : batchOptions;
|
|
36379
|
+
const searchAbortCollector = { aborted: false };
|
|
36380
|
+
const statementClient = wrapClientWithSearchAbort(
|
|
36381
|
+
countedClient,
|
|
36382
|
+
searchAbortCollector,
|
|
36383
|
+
info.statementType !== "SELECT" && info.statementType !== "UNION" && info.statementType !== "WITH"
|
|
36384
|
+
);
|
|
36334
36385
|
const outcome = await runWithDeadline(
|
|
36335
|
-
executeBatchStatement(statements[i], info,
|
|
36386
|
+
executeBatchStatement(statements[i], info, statementClient, stmtOptions, cacheContext, tempTables, variables),
|
|
36336
36387
|
remaining
|
|
36337
36388
|
);
|
|
36389
|
+
if (outcome.result) {
|
|
36390
|
+
outcome.result = attachSearchAbortWarning(outcome.result, searchAbortCollector);
|
|
36391
|
+
}
|
|
36338
36392
|
results.push({ ...base, status: "success", ...outcome });
|
|
36339
36393
|
} catch (e) {
|
|
36340
36394
|
results.push({ ...base, status: "error", error: toBatchStatementError(e) });
|
|
@@ -36665,7 +36719,7 @@ async function executeSelect(stmt, client, options, cacheContext, cteCache) {
|
|
|
36665
36719
|
}
|
|
36666
36720
|
}
|
|
36667
36721
|
function isNoFromSelect(stmt) {
|
|
36668
|
-
return stmt.from.appId === 0 && stmt.from.cteName ===
|
|
36722
|
+
return stmt.from.appId === 0 && stmt.from.cteName === NO_FROM_CTE_NAME;
|
|
36669
36723
|
}
|
|
36670
36724
|
function arithHasFieldRef(node) {
|
|
36671
36725
|
if (node.type === "FIELD_REF") return true;
|
|
@@ -37126,7 +37180,7 @@ async function executeQueryWithCte(query, client, options, cteCache, cacheContex
|
|
|
37126
37180
|
const rows = query.all ? combined : deduplicateRows(combined, leftCols);
|
|
37127
37181
|
return { type: "SELECT", rows, columns: leftCols, rowCount: rows.length };
|
|
37128
37182
|
}
|
|
37129
|
-
const hasCteRef = query.from.cteName != null || query.joins.some((j) => j.table.cteName != null);
|
|
37183
|
+
const hasCteRef = query.from.cteName != null && query.from.cteName !== NO_FROM_CTE_NAME || query.joins.some((j) => j.table.cteName != null);
|
|
37130
37184
|
if (!hasCteRef) {
|
|
37131
37185
|
return executeSelect(query, client, options, cacheContext, cteCache);
|
|
37132
37186
|
}
|
|
@@ -39163,10 +39217,11 @@ function detectSortKind(fieldType, calcFormat) {
|
|
|
39163
39217
|
}
|
|
39164
39218
|
|
|
39165
39219
|
// src/cli/nodeKintoneClient.ts
|
|
39220
|
+
var SEARCH_ABORTED_HEADER_VALUE = "Filter aborted because of too many search results";
|
|
39166
39221
|
function createNodeKintoneClient(baseUrl, tokenResolver) {
|
|
39167
39222
|
const normalizedBaseUrl = baseUrl.replace(/\/+$/, "");
|
|
39168
39223
|
const apiBasePath = tokenResolver.guestSpaceId && tokenResolver.guestSpaceId > 0 ? `/k/guest/${tokenResolver.guestSpaceId}/v1` : "/k/v1";
|
|
39169
|
-
async function
|
|
39224
|
+
async function requestJsonResponse(path, init, appIdForToken) {
|
|
39170
39225
|
const headers = new Headers(init.headers ?? {});
|
|
39171
39226
|
if (tokenResolver.auth.type === "token") {
|
|
39172
39227
|
headers.set("X-Cybozu-API-Token", tokenResolver.auth.resolveToken(appIdForToken));
|
|
@@ -39214,7 +39269,14 @@ function createNodeKintoneClient(baseUrl, tokenResolver) {
|
|
|
39214
39269
|
if (tokenResolver.debug) {
|
|
39215
39270
|
tokenResolver.log?.(`[debug] response status=${res.status}`);
|
|
39216
39271
|
}
|
|
39217
|
-
|
|
39272
|
+
const warning = res.headers.get("X-Cybozu-Warning") ?? "";
|
|
39273
|
+
return {
|
|
39274
|
+
body: await res.json(),
|
|
39275
|
+
searchAborted: warning.includes(SEARCH_ABORTED_HEADER_VALUE)
|
|
39276
|
+
};
|
|
39277
|
+
}
|
|
39278
|
+
async function requestJson(path, init, appIdForToken) {
|
|
39279
|
+
return (await requestJsonResponse(path, init, appIdForToken)).body;
|
|
39218
39280
|
}
|
|
39219
39281
|
function shouldRetryWithRecordNumberOrder(path, bodyText) {
|
|
39220
39282
|
if (!path.includes("/v1/records.json?")) return false;
|
|
@@ -39248,11 +39310,12 @@ function createNodeKintoneClient(baseUrl, tokenResolver) {
|
|
|
39248
39310
|
}
|
|
39249
39311
|
const path = `${apiBasePath}/records.json?${qs}`;
|
|
39250
39312
|
try {
|
|
39251
|
-
|
|
39313
|
+
const response = await requestJsonResponse(
|
|
39252
39314
|
path,
|
|
39253
39315
|
{ method: "GET" },
|
|
39254
39316
|
params.app
|
|
39255
39317
|
);
|
|
39318
|
+
return response.searchAborted ? { ...response.body, searchAborted: true } : response.body;
|
|
39256
39319
|
} catch (err) {
|
|
39257
39320
|
const msg = err instanceof Error ? err.message : String(err);
|
|
39258
39321
|
if (!shouldRetryWithRecordNumberOrder(path, msg)) throw err;
|
|
@@ -39260,11 +39323,12 @@ function createNodeKintoneClient(baseUrl, tokenResolver) {
|
|
|
39260
39323
|
if (tokenResolver.debug) {
|
|
39261
39324
|
tokenResolver.log?.("[debug] retry with fallback query order by \u30EC\u30B3\u30FC\u30C9\u756A\u53F7 asc");
|
|
39262
39325
|
}
|
|
39263
|
-
|
|
39326
|
+
const response = await requestJsonResponse(
|
|
39264
39327
|
retryPath,
|
|
39265
39328
|
{ method: "GET" },
|
|
39266
39329
|
params.app
|
|
39267
39330
|
);
|
|
39331
|
+
return response.searchAborted ? { ...response.body, searchAborted: true } : response.body;
|
|
39268
39332
|
}
|
|
39269
39333
|
},
|
|
39270
39334
|
async postRecords(_params) {
|
|
@@ -40822,7 +40886,7 @@ Options:
|
|
|
40822
40886
|
-h, --help Show help
|
|
40823
40887
|
`);
|
|
40824
40888
|
}
|
|
40825
|
-
var SERVER_VERSION = true ? "2.
|
|
40889
|
+
var SERVER_VERSION = true ? "2.10.0" : "0.0.0-dev";
|
|
40826
40890
|
function createServer(args) {
|
|
40827
40891
|
const server = new McpServer({
|
|
40828
40892
|
name: "ksql-mcp",
|
package/dist-mcpb/ksql-mcp.mcpb
CHANGED
|
Binary file
|