@rex0220/kintone-sql-tools 2.6.0 → 2.7.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 CHANGED
@@ -4236,7 +4236,8 @@ var SELECTION_IN_FIELD_TYPES = /* @__PURE__ */ new Set([
4236
4236
  "DROP_DOWN",
4237
4237
  "RADIO_BUTTON",
4238
4238
  "CHECK_BOX",
4239
- "MULTI_SELECT"
4239
+ "MULTI_SELECT",
4240
+ "STATUS"
4240
4241
  ]);
4241
4242
  function isSelectionInComparison(expr, options) {
4242
4243
  if (!isSelectionInCandidate(expr, options)) return false;
@@ -4887,6 +4888,7 @@ function createEmptyMetrics() {
4887
4888
  deleteCalls: 0,
4888
4889
  fieldCalls: 0,
4889
4890
  appsCalls: 0,
4891
+ processStatusCalls: 0,
4890
4892
  fetchedRows: 0,
4891
4893
  elapsedMs: 0
4892
4894
  };
@@ -4918,6 +4920,10 @@ function wrapClientWithMetrics(client, metrics) {
4918
4920
  getFields: (appId) => {
4919
4921
  metrics.fieldCalls += 1;
4920
4922
  return client.getFields(appId);
4923
+ },
4924
+ getProcessStatuses: (appId) => {
4925
+ metrics.processStatusCalls += 1;
4926
+ return client.getProcessStatuses(appId);
4921
4927
  }
4922
4928
  };
4923
4929
  }
@@ -5524,22 +5530,36 @@ function extractMainTypedPushdownCandidate(stmt) {
5524
5530
  return extractTypedPushdownCandidates(stmt.where, { tableAlias: stmt.from.alias });
5525
5531
  }
5526
5532
  async function loadTypedPushdownMeta(stmt, client, cacheContext) {
5527
- const appIds = /* @__PURE__ */ new Set();
5528
- if (extractMainTypedPushdownCandidate(stmt) !== null) appIds.add(stmt.from.appId);
5533
+ const candidatesByApp = /* @__PURE__ */ new Map();
5534
+ const addCandidate = (appId, candidate) => {
5535
+ if (candidate === null) return;
5536
+ const existing = candidatesByApp.get(appId);
5537
+ if (existing) existing.push(candidate);
5538
+ else candidatesByApp.set(appId, [candidate]);
5539
+ };
5540
+ addCandidate(stmt.from.appId, extractMainTypedPushdownCandidate(stmt));
5529
5541
  if (stmt.where !== null) {
5530
5542
  for (const join2 of stmt.joins) {
5531
5543
  if (!join2.table.alias || join2.table.subtableCode || join2.table.cteName !== null) continue;
5532
5544
  const candidate = extractTypedPushdownCandidates(stmt.where, {
5533
5545
  tableAlias: join2.table.alias
5534
5546
  });
5535
- if (candidate !== null) appIds.add(join2.table.appId);
5547
+ addCandidate(join2.table.appId, candidate);
5536
5548
  }
5537
5549
  }
5538
- const entries = await Promise.all([...appIds].map(async (appId) => {
5550
+ const entries = await Promise.all([...candidatesByApp.entries()].map(async ([appId, candidates]) => {
5539
5551
  const [fieldTypes, fieldOptions] = await Promise.all([
5540
5552
  getFieldTypeMap(appId, client, cacheContext),
5541
5553
  getFieldOptionSetMapByApp(appId, client, cacheContext)
5542
5554
  ]);
5555
+ const statusFields = collectCandidateFieldCodes(candidates).filter((fieldCode) => fieldTypes.get(fieldCode) === "STATUS");
5556
+ if (statusFields.length > 0) {
5557
+ const process2 = await getProcessStatusesCached(appId, client, cacheContext);
5558
+ if (process2.enable && process2.states.length > 0) {
5559
+ const states = new Set(process2.states);
5560
+ for (const fieldCode of statusFields) fieldOptions.set(fieldCode, states);
5561
+ }
5562
+ }
5543
5563
  return [appId, fieldTypes, fieldOptions];
5544
5564
  }));
5545
5565
  return {
@@ -5547,6 +5567,23 @@ async function loadTypedPushdownMeta(stmt, client, cacheContext) {
5547
5567
  fieldOptionsByApp: new Map(entries.map(([appId, , fieldOptions]) => [appId, fieldOptions]))
5548
5568
  };
5549
5569
  }
5570
+ function collectCandidateFieldCodes(candidates) {
5571
+ const fields = /* @__PURE__ */ new Set();
5572
+ const visit = (expr) => {
5573
+ if (expr.type === "BINARY") {
5574
+ if (expr.left.type === "FIELD") fields.add(expr.left.field);
5575
+ return;
5576
+ }
5577
+ if (expr.type === "LOGICAL") {
5578
+ visit(expr.left);
5579
+ visit(expr.right);
5580
+ return;
5581
+ }
5582
+ if (expr.type === "GROUP" || expr.type === "NOT") visit(expr.expr);
5583
+ };
5584
+ for (const candidate of candidates) visit(candidate);
5585
+ return [...fields];
5586
+ }
5550
5587
  function collectTypedInFieldRefs(expr, out) {
5551
5588
  if (expr === null) return;
5552
5589
  switch (expr.type) {
@@ -6172,6 +6209,7 @@ var fieldTypeCache = /* @__PURE__ */ new Map();
6172
6209
  var optionOrderCache = /* @__PURE__ */ new Map();
6173
6210
  var sortKindCache = /* @__PURE__ */ new Map();
6174
6211
  var fieldInfoCache = /* @__PURE__ */ new Map();
6212
+ var processStatusCache = /* @__PURE__ */ new Map();
6175
6213
  function getScopedCacheValue(root, cacheContext, appId) {
6176
6214
  return root.get(cacheContext)?.get(appId);
6177
6215
  }
@@ -6193,6 +6231,13 @@ async function getFieldsCached(appId, client, cacheContext) {
6193
6231
  setScopedCacheValue(fieldInfoCache, cacheContext, appId, loading);
6194
6232
  return loading;
6195
6233
  }
6234
+ async function getProcessStatusesCached(appId, client, cacheContext) {
6235
+ const cached = getScopedCacheValue(processStatusCache, cacheContext, appId);
6236
+ if (cached) return cached;
6237
+ const loading = client.getProcessStatuses(appId);
6238
+ setScopedCacheValue(processStatusCache, cacheContext, appId, loading);
6239
+ return loading;
6240
+ }
6196
6241
  async function getFieldTypeMap(appId, client, cacheContext) {
6197
6242
  const cached = getScopedCacheValue(fieldTypeCache, cacheContext, appId);
6198
6243
  if (cached) return cached;
@@ -7861,6 +7906,7 @@ function withRequestGate(client, gate) {
7861
7906
  getRecords: (params) => gate.runReadOnly(() => client.getRecords(params)),
7862
7907
  getApps: () => gate.runReadOnly(() => client.getApps()),
7863
7908
  getFields: (appId) => gate.runReadOnly(() => client.getFields(appId)),
7909
+ getProcessStatuses: (appId) => gate.runReadOnly(() => client.getProcessStatuses(appId)),
7864
7910
  postRecords: (params) => gate.runMutation(() => client.postRecords(params)),
7865
7911
  putRecords: (params) => gate.runMutation(() => client.putRecords(params)),
7866
7912
  deleteRecords: (params) => gate.runMutation(() => client.deleteRecords(params))
@@ -8095,6 +8141,16 @@ function createNodeKintoneClient(baseUrl, tokenResolver) {
8095
8141
  appId
8096
8142
  );
8097
8143
  return flattenFormFieldProperties(res.properties);
8144
+ },
8145
+ async getProcessStatuses(appId) {
8146
+ const qs = new URLSearchParams();
8147
+ qs.set("app", String(appId));
8148
+ qs.set("lang", "user");
8149
+ const res = await requestJson(`${apiBasePath}/app/status.json?${qs.toString()}`, { method: "GET" }, appId);
8150
+ return {
8151
+ enable: res.enable,
8152
+ states: Object.values(res.states ?? {}).map((state) => state.name)
8153
+ };
8098
8154
  }
8099
8155
  };
8100
8156
  }
@@ -9182,7 +9238,10 @@ function createDryRunClient() {
9182
9238
  putRecords: notUsed,
9183
9239
  deleteRecords: notUsed,
9184
9240
  getApps: notUsed,
9185
- getFields: notUsed
9241
+ getFields: notUsed,
9242
+ async getProcessStatuses() {
9243
+ return { enable: false, states: [] };
9244
+ }
9186
9245
  };
9187
9246
  }
9188
9247
  async function runDiagnosticRecordGet(params) {
@@ -10199,6 +10258,13 @@ async function run() {
10199
10258
  if (!routed) throw new Error(`AuthError: profile "${pName}" is not resolved for APP${appId}.`);
10200
10259
  return routed.getFields(binding.appId);
10201
10260
  },
10261
+ getProcessStatuses: (appId) => {
10262
+ const binding = appBindingByMappedApp.get(appId) ?? { appId, profile: profileName.toLowerCase() };
10263
+ const pName = binding.profile;
10264
+ const routed = profileClientMap.get(pName);
10265
+ if (!routed) throw new Error(`AuthError: profile "${pName}" is not resolved for APP${appId}.`);
10266
+ return routed.getProcessStatuses(binding.appId);
10267
+ },
10202
10268
  getApps: () => defaultClient.getApps()
10203
10269
  };
10204
10270
  }
@@ -35137,7 +35137,8 @@ var SELECTION_IN_FIELD_TYPES = /* @__PURE__ */ new Set([
35137
35137
  "DROP_DOWN",
35138
35138
  "RADIO_BUTTON",
35139
35139
  "CHECK_BOX",
35140
- "MULTI_SELECT"
35140
+ "MULTI_SELECT",
35141
+ "STATUS"
35141
35142
  ]);
35142
35143
  function isSelectionInComparison(expr, options) {
35143
35144
  if (!isSelectionInCandidate(expr, options)) return false;
@@ -35788,6 +35789,7 @@ function createEmptyMetrics() {
35788
35789
  deleteCalls: 0,
35789
35790
  fieldCalls: 0,
35790
35791
  appsCalls: 0,
35792
+ processStatusCalls: 0,
35791
35793
  fetchedRows: 0,
35792
35794
  elapsedMs: 0
35793
35795
  };
@@ -35819,6 +35821,10 @@ function wrapClientWithMetrics(client, metrics) {
35819
35821
  getFields: (appId) => {
35820
35822
  metrics.fieldCalls += 1;
35821
35823
  return client.getFields(appId);
35824
+ },
35825
+ getProcessStatuses: (appId) => {
35826
+ metrics.processStatusCalls += 1;
35827
+ return client.getProcessStatuses(appId);
35822
35828
  }
35823
35829
  };
35824
35830
  }
@@ -36425,22 +36431,36 @@ function extractMainTypedPushdownCandidate(stmt) {
36425
36431
  return extractTypedPushdownCandidates(stmt.where, { tableAlias: stmt.from.alias });
36426
36432
  }
36427
36433
  async function loadTypedPushdownMeta(stmt, client, cacheContext) {
36428
- const appIds = /* @__PURE__ */ new Set();
36429
- if (extractMainTypedPushdownCandidate(stmt) !== null) appIds.add(stmt.from.appId);
36434
+ const candidatesByApp = /* @__PURE__ */ new Map();
36435
+ const addCandidate = (appId, candidate) => {
36436
+ if (candidate === null) return;
36437
+ const existing = candidatesByApp.get(appId);
36438
+ if (existing) existing.push(candidate);
36439
+ else candidatesByApp.set(appId, [candidate]);
36440
+ };
36441
+ addCandidate(stmt.from.appId, extractMainTypedPushdownCandidate(stmt));
36430
36442
  if (stmt.where !== null) {
36431
36443
  for (const join of stmt.joins) {
36432
36444
  if (!join.table.alias || join.table.subtableCode || join.table.cteName !== null) continue;
36433
36445
  const candidate = extractTypedPushdownCandidates(stmt.where, {
36434
36446
  tableAlias: join.table.alias
36435
36447
  });
36436
- if (candidate !== null) appIds.add(join.table.appId);
36448
+ addCandidate(join.table.appId, candidate);
36437
36449
  }
36438
36450
  }
36439
- const entries = await Promise.all([...appIds].map(async (appId) => {
36451
+ const entries = await Promise.all([...candidatesByApp.entries()].map(async ([appId, candidates]) => {
36440
36452
  const [fieldTypes, fieldOptions] = await Promise.all([
36441
36453
  getFieldTypeMap(appId, client, cacheContext),
36442
36454
  getFieldOptionSetMapByApp(appId, client, cacheContext)
36443
36455
  ]);
36456
+ const statusFields = collectCandidateFieldCodes(candidates).filter((fieldCode) => fieldTypes.get(fieldCode) === "STATUS");
36457
+ if (statusFields.length > 0) {
36458
+ const process4 = await getProcessStatusesCached(appId, client, cacheContext);
36459
+ if (process4.enable && process4.states.length > 0) {
36460
+ const states = new Set(process4.states);
36461
+ for (const fieldCode of statusFields) fieldOptions.set(fieldCode, states);
36462
+ }
36463
+ }
36444
36464
  return [appId, fieldTypes, fieldOptions];
36445
36465
  }));
36446
36466
  return {
@@ -36448,6 +36468,23 @@ async function loadTypedPushdownMeta(stmt, client, cacheContext) {
36448
36468
  fieldOptionsByApp: new Map(entries.map(([appId, , fieldOptions]) => [appId, fieldOptions]))
36449
36469
  };
36450
36470
  }
36471
+ function collectCandidateFieldCodes(candidates) {
36472
+ const fields = /* @__PURE__ */ new Set();
36473
+ const visit = (expr) => {
36474
+ if (expr.type === "BINARY") {
36475
+ if (expr.left.type === "FIELD") fields.add(expr.left.field);
36476
+ return;
36477
+ }
36478
+ if (expr.type === "LOGICAL") {
36479
+ visit(expr.left);
36480
+ visit(expr.right);
36481
+ return;
36482
+ }
36483
+ if (expr.type === "GROUP" || expr.type === "NOT") visit(expr.expr);
36484
+ };
36485
+ for (const candidate of candidates) visit(candidate);
36486
+ return [...fields];
36487
+ }
36451
36488
  function collectTypedInFieldRefs(expr, out) {
36452
36489
  if (expr === null) return;
36453
36490
  switch (expr.type) {
@@ -37073,6 +37110,7 @@ var fieldTypeCache = /* @__PURE__ */ new Map();
37073
37110
  var optionOrderCache = /* @__PURE__ */ new Map();
37074
37111
  var sortKindCache = /* @__PURE__ */ new Map();
37075
37112
  var fieldInfoCache = /* @__PURE__ */ new Map();
37113
+ var processStatusCache = /* @__PURE__ */ new Map();
37076
37114
  function getScopedCacheValue(root, cacheContext, appId) {
37077
37115
  return root.get(cacheContext)?.get(appId);
37078
37116
  }
@@ -37094,6 +37132,13 @@ async function getFieldsCached(appId, client, cacheContext) {
37094
37132
  setScopedCacheValue(fieldInfoCache, cacheContext, appId, loading);
37095
37133
  return loading;
37096
37134
  }
37135
+ async function getProcessStatusesCached(appId, client, cacheContext) {
37136
+ const cached2 = getScopedCacheValue(processStatusCache, cacheContext, appId);
37137
+ if (cached2) return cached2;
37138
+ const loading = client.getProcessStatuses(appId);
37139
+ setScopedCacheValue(processStatusCache, cacheContext, appId, loading);
37140
+ return loading;
37141
+ }
37097
37142
  async function getFieldTypeMap(appId, client, cacheContext) {
37098
37143
  const cached2 = getScopedCacheValue(fieldTypeCache, cacheContext, appId);
37099
37144
  if (cached2) return cached2;
@@ -38755,6 +38800,7 @@ function withRequestGate(client, gate) {
38755
38800
  getRecords: (params) => gate.runReadOnly(() => client.getRecords(params)),
38756
38801
  getApps: () => gate.runReadOnly(() => client.getApps()),
38757
38802
  getFields: (appId) => gate.runReadOnly(() => client.getFields(appId)),
38803
+ getProcessStatuses: (appId) => gate.runReadOnly(() => client.getProcessStatuses(appId)),
38758
38804
  postRecords: (params) => gate.runMutation(() => client.postRecords(params)),
38759
38805
  putRecords: (params) => gate.runMutation(() => client.putRecords(params)),
38760
38806
  deleteRecords: (params) => gate.runMutation(() => client.deleteRecords(params))
@@ -38989,6 +39035,16 @@ function createNodeKintoneClient(baseUrl, tokenResolver) {
38989
39035
  appId
38990
39036
  );
38991
39037
  return flattenFormFieldProperties(res.properties);
39038
+ },
39039
+ async getProcessStatuses(appId) {
39040
+ const qs = new URLSearchParams();
39041
+ qs.set("app", String(appId));
39042
+ qs.set("lang", "user");
39043
+ const res = await requestJson(`${apiBasePath}/app/status.json?${qs.toString()}`, { method: "GET" }, appId);
39044
+ return {
39045
+ enable: res.enable,
39046
+ states: Object.values(res.states ?? {}).map((state) => state.name)
39047
+ };
38992
39048
  }
38993
39049
  };
38994
39050
  }
@@ -39496,6 +39552,12 @@ async function createKsqlRuntime(serverOptions, input) {
39496
39552
  if (!routed) throw new Error(`AuthError: profile "${binding.profile}" is not resolved for APP${appId}.`);
39497
39553
  return routed.getFields(binding.appId);
39498
39554
  },
39555
+ getProcessStatuses: (appId) => {
39556
+ const binding = resolveRuntimeBinding(runtimeContext.sqlContext, appId);
39557
+ const routed = runtimeContext.clientsByProfile.get(binding.profile);
39558
+ if (!routed) throw new Error(`AuthError: profile "${binding.profile}" is not resolved for APP${appId}.`);
39559
+ return routed.getProcessStatuses(binding.appId);
39560
+ },
39499
39561
  getApps: () => defaultClient.getApps()
39500
39562
  };
39501
39563
  const gatedClient = withRequestGate(
@@ -39720,7 +39782,10 @@ function noOpClient() {
39720
39782
  putRecords: fail,
39721
39783
  deleteRecords: fail,
39722
39784
  getApps: fail,
39723
- getFields: fail
39785
+ getFields: fail,
39786
+ async getProcessStatuses() {
39787
+ return { enable: false, states: [] };
39788
+ }
39724
39789
  };
39725
39790
  }
39726
39791
  function getServerConfigPath(serverOptions) {
@@ -40451,7 +40516,7 @@ Options:
40451
40516
  -h, --help Show help
40452
40517
  `);
40453
40518
  }
40454
- var SERVER_VERSION = true ? "2.6.0" : "0.0.0-dev";
40519
+ var SERVER_VERSION = true ? "2.7.0" : "0.0.0-dev";
40455
40520
  function createServer(args) {
40456
40521
  const server = new McpServer({
40457
40522
  name: "ksql-mcp",
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rex0220/kintone-sql-tools",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "kintone SQL plugin, CLI, and MCP tools (ksql)",
5
5
  "publishConfig": {
6
6
  "access": "public"