@rex0220/kintone-sql-tools 3.34.1 → 3.35.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 +103 -13
- package/dist-engine/index.cjs +8 -8
- package/dist-engine/index.mjs +8 -8
- package/dist-engine/ksql-engine.umd.js +8 -8
- package/dist-engine/meta/bundle-baseline.json +10 -10
- package/dist-engine/meta/cjs.json +62 -20
- package/dist-engine/meta/esm.json +62 -20
- package/dist-engine/meta/umd.json +62 -20
- package/dist-mcp/ksql-mcp.js +108 -15
- package/dist-mcpb/ksql-mcp.mcpb +0 -0
- package/package.json +1 -1
package/dist-cli/ksql.js
CHANGED
|
@@ -116,6 +116,7 @@ var KEYWORDS = /* @__PURE__ */ new Map([
|
|
|
116
116
|
["TODAY", "TODAY" /* TODAY */],
|
|
117
117
|
["NOW", "NOW" /* NOW */],
|
|
118
118
|
["LOGINUSER", "LOGINUSER" /* LOGINUSER */],
|
|
119
|
+
["PRIMARY_ORGANIZATION", "PRIMARY_ORGANIZATION" /* PRIMARY_ORGANIZATION */],
|
|
119
120
|
["CASE", "CASE" /* CASE */],
|
|
120
121
|
["WHEN", "WHEN" /* WHEN */],
|
|
121
122
|
["THEN", "THEN" /* THEN */],
|
|
@@ -804,7 +805,8 @@ var RELATIVE_DATE_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
|
804
805
|
var LEGACY_KINTONE_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
805
806
|
"TODAY",
|
|
806
807
|
"NOW",
|
|
807
|
-
"LOGINUSER"
|
|
808
|
+
"LOGINUSER",
|
|
809
|
+
"PRIMARY_ORGANIZATION"
|
|
808
810
|
]);
|
|
809
811
|
var SERVER_ONLY_WHERE_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
810
812
|
...LEGACY_KINTONE_FUNCTION_NAMES,
|
|
@@ -917,7 +919,8 @@ var PARSER_WINDOW_FUNCTION_TOKEN_MAP = Object.freeze({
|
|
|
917
919
|
var PARSER_CONTEXTUAL_FUNCTION_TOKEN_MAP = Object.freeze({
|
|
918
920
|
["TODAY" /* TODAY */]: "TODAY",
|
|
919
921
|
["NOW" /* NOW */]: "NOW",
|
|
920
|
-
["LOGINUSER" /* LOGINUSER */]: "LOGINUSER"
|
|
922
|
+
["LOGINUSER" /* LOGINUSER */]: "LOGINUSER",
|
|
923
|
+
["PRIMARY_ORGANIZATION" /* PRIMARY_ORGANIZATION */]: "PRIMARY_ORGANIZATION"
|
|
921
924
|
});
|
|
922
925
|
function isContextualFunctionToken(kind) {
|
|
923
926
|
return PARSER_CONTEXTUAL_FUNCTION_TOKEN_MAP[kind] !== void 0;
|
|
@@ -974,6 +977,7 @@ var FUNC_CALL_PREFIX_KINDS = /* @__PURE__ */ new Set([
|
|
|
974
977
|
"TODAY" /* TODAY */,
|
|
975
978
|
"NOW" /* NOW */,
|
|
976
979
|
"LOGINUSER" /* LOGINUSER */,
|
|
980
|
+
"PRIMARY_ORGANIZATION" /* PRIMARY_ORGANIZATION */,
|
|
977
981
|
"UPPER" /* UPPER */,
|
|
978
982
|
"LOWER" /* LOWER */,
|
|
979
983
|
"TRIM" /* TRIM */,
|
|
@@ -1219,6 +1223,12 @@ var Parser = class {
|
|
|
1219
1223
|
tok
|
|
1220
1224
|
);
|
|
1221
1225
|
}
|
|
1226
|
+
if (contextualFunction === "PRIMARY_ORGANIZATION") {
|
|
1227
|
+
throw new ParseError(
|
|
1228
|
+
`${context} \u306E\u53F3\u8FBA\u3067 PRIMARY_ORGANIZATION() \u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093\uFF08\u5B9F\u884C\u74B0\u5883\u5171\u901A\u306E\u512A\u5148\u7D44\u7E54\u89E3\u6C7A\u306F\u672A\u5BFE\u5FDC\u3067\u3059\uFF09`,
|
|
1229
|
+
tok
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1222
1232
|
if (contextualFunction !== void 0) {
|
|
1223
1233
|
return this.parseSqlValue();
|
|
1224
1234
|
}
|
|
@@ -3095,6 +3105,23 @@ var Parser = class {
|
|
|
3095
3105
|
if (this.peek().kind === "," /* COMMA */) {
|
|
3096
3106
|
throw new ParseError(mixedLoginUserMessage, this.peek());
|
|
3097
3107
|
}
|
|
3108
|
+
} else if (tok.kind === "PRIMARY_ORGANIZATION" /* PRIMARY_ORGANIZATION */) {
|
|
3109
|
+
const mixedPrimaryOrganizationMessage = "PRIMARY_ORGANIZATION() \u306F IN / NOT IN \u30EA\u30B9\u30C8\u306E\u5358\u72EC\u8981\u7D20\u3068\u3057\u3066\u306E\u307F\u4F7F\u7528\u3067\u304D\u307E\u3059";
|
|
3110
|
+
if (values.length > 0) {
|
|
3111
|
+
throw new ParseError(mixedPrimaryOrganizationMessage, tok);
|
|
3112
|
+
}
|
|
3113
|
+
this.expect(
|
|
3114
|
+
"(" /* LPAREN */,
|
|
3115
|
+
"PRIMARY_ORGANIZATION \u306E\u76F4\u5F8C\u306B\u306F\u7A7A\u5F15\u6570\u306E () \u304C\u5FC5\u8981\u3067\u3059"
|
|
3116
|
+
);
|
|
3117
|
+
this.expect(
|
|
3118
|
+
")" /* RPAREN */,
|
|
3119
|
+
"PRIMARY_ORGANIZATION \u306E\u76F4\u5F8C\u306B\u306F\u7A7A\u5F15\u6570\u306E () \u304C\u5FC5\u8981\u3067\u3059"
|
|
3120
|
+
);
|
|
3121
|
+
values.push({ type: "KINTONE_FUNC", name: "PRIMARY_ORGANIZATION" });
|
|
3122
|
+
if (this.peek().kind === "," /* COMMA */) {
|
|
3123
|
+
throw new ParseError(mixedPrimaryOrganizationMessage, this.peek());
|
|
3124
|
+
}
|
|
3098
3125
|
} else {
|
|
3099
3126
|
throw new ParseError(invalidValueMessage, tok);
|
|
3100
3127
|
}
|
|
@@ -5078,6 +5105,7 @@ function convertKintoneFunc(v) {
|
|
|
5078
5105
|
case "TODAY":
|
|
5079
5106
|
case "NOW":
|
|
5080
5107
|
case "LOGINUSER":
|
|
5108
|
+
case "PRIMARY_ORGANIZATION":
|
|
5081
5109
|
return `${v.name}()`;
|
|
5082
5110
|
}
|
|
5083
5111
|
return convertRelativeDateFunction(v);
|
|
@@ -6416,6 +6444,65 @@ function isSelectObject(value) {
|
|
|
6416
6444
|
return value !== null && typeof value === "object" && value.type === "SELECT";
|
|
6417
6445
|
}
|
|
6418
6446
|
|
|
6447
|
+
// src/core/primaryOrganizationDmlValidation.ts
|
|
6448
|
+
var PrimaryOrganizationDmlValidationError = class extends Error {
|
|
6449
|
+
constructor() {
|
|
6450
|
+
super(
|
|
6451
|
+
"ArgumentError: PRIMARY_ORGANIZATION() \u306F DML \u306E WHERE \u3067\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093"
|
|
6452
|
+
);
|
|
6453
|
+
this.name = "ArgumentError";
|
|
6454
|
+
}
|
|
6455
|
+
};
|
|
6456
|
+
function validatePrimaryOrganizationDmlStatement(stmt) {
|
|
6457
|
+
const target = stmt.type === "EXPLAIN" ? stmt.query : stmt;
|
|
6458
|
+
switch (target.type) {
|
|
6459
|
+
case "UPDATE":
|
|
6460
|
+
case "DELETE":
|
|
6461
|
+
case "UPSERT":
|
|
6462
|
+
case "UPSERT_SELECT":
|
|
6463
|
+
case "INSERT_SELECT":
|
|
6464
|
+
if (hasPrimaryOrganizationInWhere(target)) {
|
|
6465
|
+
throw new PrimaryOrganizationDmlValidationError();
|
|
6466
|
+
}
|
|
6467
|
+
return;
|
|
6468
|
+
default:
|
|
6469
|
+
return;
|
|
6470
|
+
}
|
|
6471
|
+
}
|
|
6472
|
+
function hasPrimaryOrganizationInWhere(node) {
|
|
6473
|
+
let found = false;
|
|
6474
|
+
walkObjects2(node, (obj) => {
|
|
6475
|
+
if (found || !Object.prototype.hasOwnProperty.call(obj, "where")) return;
|
|
6476
|
+
if (containsPrimaryOrganization(obj.where)) found = true;
|
|
6477
|
+
});
|
|
6478
|
+
return found;
|
|
6479
|
+
}
|
|
6480
|
+
function containsPrimaryOrganization(node) {
|
|
6481
|
+
let found = false;
|
|
6482
|
+
walkObjects2(node, (obj) => {
|
|
6483
|
+
if (obj.type === "KINTONE_FUNC" && obj.name === "PRIMARY_ORGANIZATION") {
|
|
6484
|
+
found = true;
|
|
6485
|
+
}
|
|
6486
|
+
});
|
|
6487
|
+
return found;
|
|
6488
|
+
}
|
|
6489
|
+
function walkObjects2(node, visit) {
|
|
6490
|
+
if (Array.isArray(node)) {
|
|
6491
|
+
for (const value of node) walkObjects2(value, visit);
|
|
6492
|
+
return;
|
|
6493
|
+
}
|
|
6494
|
+
if (node === null || typeof node !== "object") return;
|
|
6495
|
+
const obj = node;
|
|
6496
|
+
visit(obj);
|
|
6497
|
+
for (const value of Object.values(obj)) walkObjects2(value, visit);
|
|
6498
|
+
}
|
|
6499
|
+
|
|
6500
|
+
// src/core/statementValidation.ts
|
|
6501
|
+
function validateStatementStatic(stmt) {
|
|
6502
|
+
validatePrimaryOrganizationDmlStatement(stmt);
|
|
6503
|
+
validateKlikeStatement(stmt);
|
|
6504
|
+
}
|
|
6505
|
+
|
|
6419
6506
|
// src/engine/groupingRowMeta.ts
|
|
6420
6507
|
var groupingRowMetaKey = /* @__PURE__ */ Symbol("ksql.groupingRowMeta");
|
|
6421
6508
|
var groupingRefCanonicalIds = /* @__PURE__ */ new WeakMap();
|
|
@@ -6751,9 +6838,9 @@ function analyzeBatch(statements) {
|
|
|
6751
6838
|
}
|
|
6752
6839
|
try {
|
|
6753
6840
|
assertApplyScope("phase15b", stmt);
|
|
6754
|
-
|
|
6841
|
+
validateStatementStatic(stmt);
|
|
6755
6842
|
} catch (error) {
|
|
6756
|
-
if (error instanceof KlikeValidationError) {
|
|
6843
|
+
if (error instanceof KlikeValidationError || error instanceof PrimaryOrganizationDmlValidationError) {
|
|
6757
6844
|
throw new BatchAnalysisError(error.message, index);
|
|
6758
6845
|
}
|
|
6759
6846
|
if (error instanceof Error && /^(UnsupportedError|ArgumentError): APPLY /.test(error.message)) {
|
|
@@ -8014,6 +8101,7 @@ function resolveKintoneFunc(name) {
|
|
|
8014
8101
|
case "NOW":
|
|
8015
8102
|
return now.toISOString();
|
|
8016
8103
|
case "LOGINUSER":
|
|
8104
|
+
case "PRIMARY_ORGANIZATION":
|
|
8017
8105
|
return "";
|
|
8018
8106
|
}
|
|
8019
8107
|
}
|
|
@@ -10968,12 +11056,14 @@ var RELATIVE_DATE_OPERATORS = new Set(RANGE_AND_EQUALITY);
|
|
|
10968
11056
|
var LEGACY_KINTONE_FUNCTION_FIELD_TYPES = /* @__PURE__ */ new Map([
|
|
10969
11057
|
["TODAY", /* @__PURE__ */ new Set(["DATE", "DATETIME", "CREATED_TIME", "UPDATED_TIME"])],
|
|
10970
11058
|
["NOW", /* @__PURE__ */ new Set(["DATETIME", "CREATED_TIME", "UPDATED_TIME"])],
|
|
10971
|
-
["LOGINUSER", /* @__PURE__ */ new Set(["CREATOR", "MODIFIER", "USER_SELECT"])]
|
|
11059
|
+
["LOGINUSER", /* @__PURE__ */ new Set(["CREATOR", "MODIFIER", "USER_SELECT"])],
|
|
11060
|
+
["PRIMARY_ORGANIZATION", /* @__PURE__ */ new Set(["ORGANIZATION_SELECT"])]
|
|
10972
11061
|
]);
|
|
10973
11062
|
var LEGACY_KINTONE_FUNCTION_OPERATORS = /* @__PURE__ */ new Map([
|
|
10974
11063
|
["TODAY", new Set(RANGE_AND_EQUALITY)],
|
|
10975
11064
|
["NOW", new Set(RANGE_AND_EQUALITY)],
|
|
10976
|
-
["LOGINUSER", /* @__PURE__ */ new Set(["in", "not in"])]
|
|
11065
|
+
["LOGINUSER", /* @__PURE__ */ new Set(["in", "not in"])],
|
|
11066
|
+
["PRIMARY_ORGANIZATION", /* @__PURE__ */ new Set(["in", "not in"])]
|
|
10977
11067
|
]);
|
|
10978
11068
|
var EQUALITY_IN = ["=", "!=", "in", "not in"];
|
|
10979
11069
|
var NATIVE_OPERATORS = /* @__PURE__ */ new Map([
|
|
@@ -15666,7 +15756,7 @@ async function executeParsedStatement(stmt, client, options, cacheContext) {
|
|
|
15666
15756
|
}
|
|
15667
15757
|
assertApplyScope("phase15b", stmt);
|
|
15668
15758
|
assertApplyExecutionScope("phase15b", stmt);
|
|
15669
|
-
|
|
15759
|
+
validateStatementStatic(stmt);
|
|
15670
15760
|
if (stmt.type !== "EXPLAIN") {
|
|
15671
15761
|
await validateStatementGroupingPlanning(stmt, client, cacheContext);
|
|
15672
15762
|
}
|
|
@@ -16137,7 +16227,7 @@ function statementHasApplyMutation(statement) {
|
|
|
16137
16227
|
async function executeBatchStatement(stmt, info, client, options, cacheContext, tempTables, variables) {
|
|
16138
16228
|
if (stmt.type === "SET_VARIABLE") {
|
|
16139
16229
|
const resolvedStmt2 = resolveBatchVariableReferences(stmt, variables);
|
|
16140
|
-
|
|
16230
|
+
validateStatementStatic(resolvedStmt2);
|
|
16141
16231
|
await assertRelativeDateExecutionPlan(resolvedStmt2, client, cacheContext);
|
|
16142
16232
|
if (resolvedStmt2.expr.type === "ARRAY") {
|
|
16143
16233
|
variables.set(stmt.name, {
|
|
@@ -16194,7 +16284,7 @@ async function executeBatchStatement(stmt, info, client, options, cacheContext,
|
|
|
16194
16284
|
const resolvedStmt = resolveBatchVariableReferences(stmt, variables);
|
|
16195
16285
|
assertApplyScope("phase15b", resolvedStmt);
|
|
16196
16286
|
assertApplyExecutionScope("phase15b", resolvedStmt);
|
|
16197
|
-
|
|
16287
|
+
validateStatementStatic(resolvedStmt);
|
|
16198
16288
|
await assertRelativeDateExecutionPlan(resolvedStmt, client, cacheContext);
|
|
16199
16289
|
if (resolvedStmt.type === "VALIDATE") {
|
|
16200
16290
|
const result = await executeExistingRecordValidationCore(
|
|
@@ -21950,7 +22040,7 @@ function parseSql(sql, enableImport = false) {
|
|
|
21950
22040
|
const tokens = new Lexer(sql).tokenize();
|
|
21951
22041
|
const stmt = new Parser(tokens, { import: enableImport }).parse();
|
|
21952
22042
|
assertApplyScope("phase15b", stmt);
|
|
21953
|
-
|
|
22043
|
+
validateStatementStatic(stmt);
|
|
21954
22044
|
return stmt;
|
|
21955
22045
|
} catch (e) {
|
|
21956
22046
|
if (e instanceof LexError || e instanceof ParseError) {
|
|
@@ -22553,7 +22643,7 @@ async function buildBatchExplainPlans(sql, client, injectedVariables, cacheConte
|
|
|
22553
22643
|
for (let i = 0; i < statements.length; i++) {
|
|
22554
22644
|
const stmt = statements[i];
|
|
22555
22645
|
const planStmt = stmt.type === "SET_VARIABLE" ? stmt.expr.type === "SCALAR_SUBQUERY" ? { ...stmt, expr: resolveBatchVariableReferences(stmt.expr, variables) } : stmt : resolveBatchVariableReferences(stmt, variables);
|
|
22556
|
-
|
|
22646
|
+
validateStatementStatic(planStmt);
|
|
22557
22647
|
const relativeDatePlan = await resolveRelativeDateExecutionPlan(planStmt, client, invocationCacheContext);
|
|
22558
22648
|
const whereAnalysis = await buildExplainWhereAnalysis(
|
|
22559
22649
|
planStmt,
|
|
@@ -23506,13 +23596,13 @@ var OperationCancelledError = class extends Error {
|
|
|
23506
23596
|
function parseSqlStatement(sql, capabilities = {}) {
|
|
23507
23597
|
const tokens = new Lexer(sql).tokenize();
|
|
23508
23598
|
const stmt = new Parser(tokens, capabilities).parse();
|
|
23509
|
-
|
|
23599
|
+
validateStatementStatic(stmt);
|
|
23510
23600
|
return stmt;
|
|
23511
23601
|
}
|
|
23512
23602
|
function parseSqlStatements(sql, capabilities = {}) {
|
|
23513
23603
|
const tokens = new Lexer(sql).tokenize();
|
|
23514
23604
|
const statements = new Parser(tokens, capabilities).parseStatements();
|
|
23515
|
-
statements.forEach(
|
|
23605
|
+
statements.forEach(validateStatementStatic);
|
|
23516
23606
|
return statements;
|
|
23517
23607
|
}
|
|
23518
23608
|
|