@rex0220/kintone-sql-tools 3.57.0 → 3.59.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
@@ -1169,6 +1169,12 @@ var Parser = class {
1169
1169
  if (upper === "DROP") return this.parseDropTempTable();
1170
1170
  if (upper === "DECLARE") return this.parseDeclareVariable();
1171
1171
  if (upper === "VALIDATE") return this.parseValidate();
1172
+ if (upper === "GENERATE_SERIES") {
1173
+ throw new ParseError(
1174
+ "GENERATE_SERIES \u306F WITH \u306E CTE \u672C\u4F53\u306B\u66F8\u3044\u3066\u304F\u3060\u3055\u3044\u3002\u4F8B: WITH s AS (GENERATE_SERIES(1, 5)) SELECT generate_series FROM s",
1175
+ tok
1176
+ );
1177
+ }
1172
1178
  if (upper === "IMPORT") {
1173
1179
  if (!this.capabilities.import) {
1174
1180
  throw new ParseError("IMPORT is not supported (capability is disabled).", tok);
@@ -1928,6 +1934,8 @@ var Parser = class {
1928
1934
  query2 = this.parseShow();
1929
1935
  } else if (inner === "DESCRIBE" /* DESCRIBE */ || inner === "DESC" /* DESC */) {
1930
1936
  query2 = this.parseDescribe();
1937
+ } else if (inner === "IDENT" /* IDENT */ && this.peek().value.toUpperCase() === "GENERATE_SERIES") {
1938
+ query2 = this.parseGenerateSeries();
1931
1939
  } else {
1932
1940
  query2 = this.tryParseUnionChain(this.parseSelect());
1933
1941
  }
@@ -1939,6 +1947,43 @@ var Parser = class {
1939
1947
  this.cteNames.clear();
1940
1948
  return { type: "WITH", ctes, query };
1941
1949
  }
1950
+ parseGenerateSeries() {
1951
+ const name = this.advance();
1952
+ if (name.kind !== "IDENT" /* IDENT */ || name.value.toUpperCase() !== "GENERATE_SERIES") {
1953
+ throw new ParseError("GENERATE_SERIES \u304C\u5FC5\u8981\u3067\u3059", name);
1954
+ }
1955
+ this.expect("(" /* LPAREN */);
1956
+ const args = [];
1957
+ if (this.peek().kind !== ")" /* RPAREN */) {
1958
+ do {
1959
+ const tok = this.peek();
1960
+ if (tok.kind === "STRING" /* STRING */) {
1961
+ this.advance();
1962
+ args.push({ type: "STRING", value: tok.value });
1963
+ continue;
1964
+ }
1965
+ if (tok.kind === "VARIABLE" /* VARIABLE */) {
1966
+ this.advance();
1967
+ args.push({ type: "VARIABLE", name: tok.value.slice(1).toLowerCase() });
1968
+ continue;
1969
+ }
1970
+ let sign = "";
1971
+ if (tok.kind === "+" /* PLUS */ || tok.kind === "-" /* MINUS */) {
1972
+ sign = tok.kind === "-" /* MINUS */ ? "-" : "+";
1973
+ this.advance();
1974
+ }
1975
+ const number = this.peek();
1976
+ if (number.kind !== "NUMBER" /* NUMBER */) {
1977
+ throw new ParseError("GENERATE_SERIES \u306E\u5F15\u6570\u306B\u306F\u6570\u5024\u3001\u6587\u5B57\u5217\u3001\u307E\u305F\u306F\u30D0\u30C3\u30C1\u5909\u6570\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044", number);
1978
+ }
1979
+ this.advance();
1980
+ args.push(makeNumberLiteral(`${sign}${number.value}`));
1981
+ } while (this.consume("," /* COMMA */));
1982
+ }
1983
+ this.expect(")" /* RPAREN */);
1984
+ const columnAlias = this.consume("AS" /* AS */) ? this.parseIdentifier() : "generate_series";
1985
+ return { type: "GENERATE_SERIES", args, columnAlias };
1986
+ }
1942
1987
  // ----------------------------------------------------------
1943
1988
  // UNION / UNION ALL チェーン
1944
1989
  // ----------------------------------------------------------
@@ -2923,6 +2968,12 @@ var Parser = class {
2923
2968
  // ----------------------------------------------------------
2924
2969
  parseTableRef() {
2925
2970
  const nameTok = this.peek();
2971
+ if (nameTok.kind === "IDENT" /* IDENT */ && nameTok.value.toUpperCase() === "GENERATE_SERIES" && this.peekAt(1).kind === "(" /* LPAREN */) {
2972
+ throw new ParseError(
2973
+ "GENERATE_SERIES \u306F WITH \u306E CTE \u672C\u4F53\u306B\u66F8\u3044\u3066\u304F\u3060\u3055\u3044\u3002\u4F8B: WITH s AS (GENERATE_SERIES(1, 5)) SELECT generate_series FROM s",
2974
+ nameTok
2975
+ );
2976
+ }
2926
2977
  const name = this.parseTableName();
2927
2978
  if (nameTok.kind === "IDENT" /* IDENT */ && name.startsWith("#")) {
2928
2979
  this.tempTableRefs.push(this.prev());
@@ -4698,7 +4749,9 @@ function completeInputReasons(stmt) {
4698
4749
  break;
4699
4750
  case "WITH":
4700
4751
  for (const cte of stmt.ctes) {
4701
- addReasons(reasons, completeInputReasons(cte.query));
4752
+ if (cte.query.type !== "GENERATE_SERIES") {
4753
+ addReasons(reasons, completeInputReasons(cte.query));
4754
+ }
4702
4755
  }
4703
4756
  addReasons(reasons, completeInputReasons(stmt.query));
4704
4757
  break;
@@ -7649,11 +7702,231 @@ function assertStringFunctionArity(func, args) {
7649
7702
  }
7650
7703
  }
7651
7704
 
7705
+ // src/core/generateSeries.ts
7706
+ var GENERATE_SERIES_MAX_ROWS = 1e4;
7707
+ var argumentError = (message) => new Error(`ArgumentError: ${message}`);
7708
+ var isVariable = (arg) => arg.type === "VARIABLE";
7709
+ var isResolvedVariable = (arg) => arg?.type === "STRING" && arg.fromVariable === true;
7710
+ function literalValue(arg) {
7711
+ return arg.type === "NUMBER" ? Number(numberLiteralText(arg)) : arg.value;
7712
+ }
7713
+ function dateParts(value) {
7714
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
7715
+ if (!match) return null;
7716
+ const year = Number(match[1]);
7717
+ const month = Number(match[2]);
7718
+ const day = Number(match[3]);
7719
+ if (year < 1 || year > 9999 || month < 1 || month > 12 || day < 1 || day > 31) return null;
7720
+ const date = /* @__PURE__ */ new Date(0);
7721
+ date.setUTCHours(0, 0, 0, 0);
7722
+ date.setUTCFullYear(year, month - 1, day);
7723
+ return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day ? { year, month, day } : null;
7724
+ }
7725
+ function dateOrdinal(value) {
7726
+ const parts = dateParts(value);
7727
+ const date = /* @__PURE__ */ new Date(0);
7728
+ date.setUTCHours(0, 0, 0, 0);
7729
+ date.setUTCFullYear(parts.year, parts.month - 1, parts.day);
7730
+ return Math.trunc(date.getTime() / 864e5);
7731
+ }
7732
+ function dateFromOrdinal(ordinal) {
7733
+ const date = new Date(ordinal * 864e5);
7734
+ const year = date.getUTCFullYear();
7735
+ if (year < 1 || year > 9999) {
7736
+ throw argumentError("GENERATE_SERIES \u306E\u65E5\u4ED8\u5F15\u6570\u306B\u306F\u5B9F\u5728\u3059\u308B YYYY-MM-DD \u5F62\u5F0F\u306E DATE \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
7737
+ }
7738
+ return `${String(year).padStart(4, "0")}-${String(date.getUTCMonth() + 1).padStart(2, "0")}-${String(date.getUTCDate()).padStart(2, "0")}`;
7739
+ }
7740
+ function parseDateStep(value) {
7741
+ const trimmed = value.trim();
7742
+ const match = /^([+-]?\d+)\s+(day|days)$/i.exec(trimmed);
7743
+ if (!match) {
7744
+ if (/^[+-]?\d+\s+\S+$/i.test(trimmed)) {
7745
+ throw argumentError("GENERATE_SERIES \u306E\u65E5\u4ED8 step \u306F day \u307E\u305F\u306F days \u306E\u307F\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u3059\u3002");
7746
+ }
7747
+ throw argumentError("GENERATE_SERIES \u306E step \u304C\u7CFB\u5217\u306E\u578B\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093\u3002\u6574\u6570\u7CFB\u5217\u306B\u306F\u6574\u6570\u3001DATE \u7CFB\u5217\u306B\u306F day \u5358\u4F4D\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
7748
+ }
7749
+ const step = Number(match[1]);
7750
+ if (!Number.isSafeInteger(step)) {
7751
+ throw argumentError("GENERATE_SERIES \u306E\u6570\u5024\u7CFB\u5217\u306F\u6574\u6570\u306E start\u3001stop\u3001step \u306E\u307F\u3092\u53D7\u3051\u4ED8\u3051\u307E\u3059\u3002");
7752
+ }
7753
+ if (step === 0) throw argumentError("GENERATE_SERIES \u306E\u65E5\u4ED8 step \u306B 0 day \u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002");
7754
+ return step;
7755
+ }
7756
+ function integerValue(value) {
7757
+ if (typeof value === "number") return Number.isSafeInteger(value) ? value : null;
7758
+ if (!/^[+-]?\d+$/.test(value)) return null;
7759
+ const parsed = Number(value);
7760
+ return Number.isSafeInteger(parsed) ? parsed : null;
7761
+ }
7762
+ function integerNumberLiteral(arg) {
7763
+ const decimal = parseExactDecimal(arg.raw ?? String(arg.value));
7764
+ if (decimal === null || decimal.scale > 0) return null;
7765
+ if (decimal.sign === 0) return 0;
7766
+ const digits = decimal.coefficient.length - decimal.scale;
7767
+ if (digits > 16) return null;
7768
+ const magnitude = `${decimal.coefficient}${"0".repeat(-decimal.scale)}`;
7769
+ if (magnitude.length === 16 && magnitude > "9007199254740991") return null;
7770
+ const value = Number(magnitude) * decimal.sign;
7771
+ return Number.isSafeInteger(value) ? value : null;
7772
+ }
7773
+ function isUnsupportedTemporal(value) {
7774
+ return typeof value === "string" && (/^\d{4}-\d{2}-\d{2}T/.test(value) || /^\d{2}:\d{2}(?::\d{2})?$/.test(value));
7775
+ }
7776
+ function countRows(start, stop, step) {
7777
+ if (start === stop) return 1;
7778
+ if (start < stop && step < 0 || start > stop && step > 0) return 0;
7779
+ const distance = step > 0 ? BigInt(stop) - BigInt(start) : BigInt(start) - BigInt(stop);
7780
+ return Number(distance / BigInt(Math.abs(step)) + 1n);
7781
+ }
7782
+ function planResolved(stmt) {
7783
+ if (stmt.args.length < 2 || stmt.args.length > 3) {
7784
+ throw argumentError("GENERATE_SERIES \u306F start\u3001stop \u3068\u7701\u7565\u53EF\u80FD\u306A step \u306E2\u500B\u307E\u305F\u306F3\u500B\u306E\u5F15\u6570\u3092\u53D7\u3051\u4ED8\u3051\u307E\u3059\u3002");
7785
+ }
7786
+ const values = stmt.args.map((arg) => literalValue(arg));
7787
+ ["start", "stop", "step"].forEach((name, index) => {
7788
+ if (values[index] === "") throw argumentError(`GENERATE_SERIES \u306E ${name} \u306B\u7A7A\u6587\u5B57\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002`);
7789
+ });
7790
+ const [startRaw, stopRaw, stepRaw] = values;
7791
+ const [startArg, stopArg, stepArg] = stmt.args;
7792
+ const startDate = typeof startRaw === "string" ? dateParts(startRaw) : null;
7793
+ const stopDate = typeof stopRaw === "string" ? dateParts(stopRaw) : null;
7794
+ const dateLikeStart = typeof startRaw === "string" && /^\d{4}-/.test(startRaw);
7795
+ const dateLikeStop = typeof stopRaw === "string" && /^\d{4}-/.test(stopRaw);
7796
+ if ([startRaw, stopRaw].some(isUnsupportedTemporal)) {
7797
+ throw argumentError("GENERATE_SERIES \u306F Phase 1 \u3067\u306F\u6574\u6570\u3068 DATE \u306E\u307F\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u3059\u3002DATETIME \u3068 TIME \u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093\u3002");
7798
+ }
7799
+ if (startDate || stopDate || dateLikeStart || dateLikeStop || typeof startRaw === "string" && typeof stopRaw === "string" && !(isResolvedVariable(startArg) && isResolvedVariable(stopArg) && integerValue(startRaw) !== null && integerValue(stopRaw) !== null)) {
7800
+ if (!startDate || !stopDate) {
7801
+ if (startDate && typeof stopRaw !== "string" || stopDate && typeof startRaw !== "string") {
7802
+ throw argumentError("GENERATE_SERIES \u306E start \u3068 stop \u306F\u3001\u4E21\u65B9\u3092\u6574\u6570\u307E\u305F\u306F\u4E21\u65B9\u3092 DATE \u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
7803
+ }
7804
+ throw argumentError("GENERATE_SERIES \u306E\u65E5\u4ED8\u5F15\u6570\u306B\u306F\u5B9F\u5728\u3059\u308B YYYY-MM-DD \u5F62\u5F0F\u306E DATE \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
7805
+ }
7806
+ if (stepRaw !== void 0 && typeof stepRaw !== "string") {
7807
+ throw argumentError("GENERATE_SERIES \u306E step \u304C\u7CFB\u5217\u306E\u578B\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093\u3002\u6574\u6570\u7CFB\u5217\u306B\u306F\u6574\u6570\u3001DATE \u7CFB\u5217\u306B\u306F day \u5358\u4F4D\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
7808
+ }
7809
+ const step2 = stepRaw === void 0 ? 1 : parseDateStep(stepRaw);
7810
+ const start2 = startRaw;
7811
+ const stop2 = stopRaw;
7812
+ return { kind: "DATE", start: start2, stop: stop2, step: step2, rowCount: countRows(dateOrdinal(start2), dateOrdinal(stop2), step2) };
7813
+ }
7814
+ const startInteger = startArg.type === "NUMBER" ? integerNumberLiteral(startArg) : isResolvedVariable(startArg) ? integerValue(startRaw) : null;
7815
+ const stopInteger = stopArg.type === "NUMBER" ? integerNumberLiteral(stopArg) : isResolvedVariable(stopArg) ? integerValue(stopRaw) : null;
7816
+ if (startInteger === null || stopInteger === null) {
7817
+ if ((startArg.type === "NUMBER" || isResolvedVariable(startArg)) && (stopArg.type === "NUMBER" || isResolvedVariable(stopArg))) {
7818
+ throw argumentError("GENERATE_SERIES \u306E\u6570\u5024\u7CFB\u5217\u306F\u6574\u6570\u306E start\u3001stop\u3001step \u306E\u307F\u3092\u53D7\u3051\u4ED8\u3051\u307E\u3059\u3002");
7819
+ }
7820
+ throw argumentError("GENERATE_SERIES \u306E start \u3068 stop \u306F\u3001\u4E21\u65B9\u3092\u6574\u6570\u307E\u305F\u306F\u4E21\u65B9\u3092 DATE \u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
7821
+ }
7822
+ const resolvedStep = stepRaw === void 0 ? 1 : stepArg?.type === "NUMBER" ? integerNumberLiteral(stepArg) : isResolvedVariable(stepArg) ? integerValue(stepRaw) : null;
7823
+ if (resolvedStep === null) {
7824
+ if (stepArg?.type === "NUMBER" || isResolvedVariable(stepArg)) {
7825
+ throw argumentError("GENERATE_SERIES \u306E\u6570\u5024\u7CFB\u5217\u306F\u6574\u6570\u306E start\u3001stop\u3001step \u306E\u307F\u3092\u53D7\u3051\u4ED8\u3051\u307E\u3059\u3002");
7826
+ }
7827
+ throw argumentError("GENERATE_SERIES \u306E step \u304C\u7CFB\u5217\u306E\u578B\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093\u3002\u6574\u6570\u7CFB\u5217\u306B\u306F\u6574\u6570\u3001DATE \u7CFB\u5217\u306B\u306F day \u5358\u4F4D\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
7828
+ }
7829
+ const start = startInteger;
7830
+ const stop = stopInteger;
7831
+ const step = resolvedStep;
7832
+ if (step === 0) throw argumentError("GENERATE_SERIES \u306E step \u306B 0 \u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002");
7833
+ return { kind: "INTEGER", start, stop, step, rowCount: countRows(start, stop, step) };
7834
+ }
7835
+ function validateGenerateSeriesStatement(stmt) {
7836
+ if (stmt.args.length < 2 || stmt.args.length > 3) {
7837
+ throw argumentError("GENERATE_SERIES \u306F start\u3001stop \u3068\u7701\u7565\u53EF\u80FD\u306A step \u306E2\u500B\u307E\u305F\u306F3\u500B\u306E\u5F15\u6570\u3092\u53D7\u3051\u4ED8\u3051\u307E\u3059\u3002");
7838
+ }
7839
+ if (stmt.args.some(isVariable)) {
7840
+ ["start", "stop", "step"].forEach((name, index) => {
7841
+ const arg = stmt.args[index];
7842
+ if (arg?.type === "STRING" && arg.value === "") {
7843
+ throw argumentError(`GENERATE_SERIES \u306E ${name} \u306B\u7A7A\u6587\u5B57\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002`);
7844
+ }
7845
+ if (arg?.type === "NUMBER" && integerNumberLiteral(arg) === null) {
7846
+ throw argumentError("GENERATE_SERIES \u306E\u6570\u5024\u7CFB\u5217\u306F\u6574\u6570\u306E start\u3001stop\u3001step \u306E\u307F\u3092\u53D7\u3051\u4ED8\u3051\u307E\u3059\u3002");
7847
+ }
7848
+ if (index < 2 && arg?.type === "STRING") {
7849
+ if (isUnsupportedTemporal(arg.value)) {
7850
+ throw argumentError("GENERATE_SERIES \u306F Phase 1 \u3067\u306F\u6574\u6570\u3068 DATE \u306E\u307F\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u3059\u3002DATETIME \u3068 TIME \u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093\u3002");
7851
+ }
7852
+ if (/^\d{4}-/.test(arg.value) && dateParts(arg.value) === null) {
7853
+ throw argumentError("GENERATE_SERIES \u306E\u65E5\u4ED8\u5F15\u6570\u306B\u306F\u5B9F\u5728\u3059\u308B YYYY-MM-DD \u5F62\u5F0F\u306E DATE \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
7854
+ }
7855
+ }
7856
+ });
7857
+ const step = stmt.args[2];
7858
+ if (step?.type === "NUMBER") {
7859
+ const value = integerNumberLiteral(step);
7860
+ if (value === null) throw argumentError("GENERATE_SERIES \u306E\u6570\u5024\u7CFB\u5217\u306F\u6574\u6570\u306E start\u3001stop\u3001step \u306E\u307F\u3092\u53D7\u3051\u4ED8\u3051\u307E\u3059\u3002");
7861
+ if (value === 0) throw argumentError("GENERATE_SERIES \u306E step \u306B 0 \u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002");
7862
+ } else if (step?.type === "STRING") {
7863
+ parseDateStep(step.value);
7864
+ }
7865
+ return null;
7866
+ }
7867
+ const plan = planResolved(stmt);
7868
+ if (plan.rowCount > GENERATE_SERIES_MAX_ROWS) {
7869
+ throw argumentError(`GENERATE_SERIES \u306E\u751F\u6210\u4EF6\u6570 ${plan.rowCount} \u884C\u304C\u4E0A\u9650 ${GENERATE_SERIES_MAX_ROWS} \u884C\u3092\u8D85\u3048\u3066\u3044\u307E\u3059\u3002`);
7870
+ }
7871
+ return plan.rowCount;
7872
+ }
7873
+ function validateGenerateSeriesInStatement(node) {
7874
+ const visit = (value) => {
7875
+ if (value === null || typeof value !== "object") return;
7876
+ if (Array.isArray(value)) {
7877
+ value.forEach(visit);
7878
+ return;
7879
+ }
7880
+ const obj = value;
7881
+ if (obj.type === "WITH") {
7882
+ let total = 0;
7883
+ let complete = true;
7884
+ for (const cte of obj.ctes) {
7885
+ if (cte.query.type === "GENERATE_SERIES") {
7886
+ const count = validateGenerateSeriesStatement(cte.query);
7887
+ if (count === null) complete = false;
7888
+ else total += count;
7889
+ } else visit(cte.query);
7890
+ }
7891
+ if (complete && total > GENERATE_SERIES_MAX_ROWS) {
7892
+ throw argumentError(`\u3053\u306E WITH \u6587\u306E GENERATE_SERIES \u751F\u6210\u4EF6\u6570\u5408\u8A08 ${total} \u884C\u304C\u4E0A\u9650 ${GENERATE_SERIES_MAX_ROWS} \u884C\u3092\u8D85\u3048\u3066\u3044\u307E\u3059\u3002`);
7893
+ }
7894
+ visit(obj.query);
7895
+ return;
7896
+ }
7897
+ Object.values(obj).forEach(visit);
7898
+ };
7899
+ visit(node);
7900
+ }
7901
+ function resolveGenerateSeries(stmt) {
7902
+ const plan = planResolved(stmt);
7903
+ if (plan.rowCount > GENERATE_SERIES_MAX_ROWS) {
7904
+ throw argumentError(`GENERATE_SERIES \u306E\u751F\u6210\u4EF6\u6570 ${plan.rowCount} \u884C\u304C\u4E0A\u9650 ${GENERATE_SERIES_MAX_ROWS} \u884C\u3092\u8D85\u3048\u3066\u3044\u307E\u3059\u3002`);
7905
+ }
7906
+ const values = [];
7907
+ if (plan.kind === "INTEGER") {
7908
+ let current = plan.start;
7909
+ for (let index = 0; index < plan.rowCount; index++) {
7910
+ values.push(String(current));
7911
+ if (index + 1 < plan.rowCount) {
7912
+ const next = current + plan.step;
7913
+ if (!Number.isSafeInteger(next)) throw argumentError("GENERATE_SERIES \u306E\u6570\u5024\u7CFB\u5217\u306F\u6574\u6570\u306E start\u3001stop\u3001step \u306E\u307F\u3092\u53D7\u3051\u4ED8\u3051\u307E\u3059\u3002");
7914
+ current = next;
7915
+ }
7916
+ }
7917
+ } else {
7918
+ const startOrdinal = dateOrdinal(plan.start);
7919
+ for (let index = 0; index < plan.rowCount; index++) values.push(dateFromOrdinal(startOrdinal + index * plan.step));
7920
+ }
7921
+ return { ...plan, values };
7922
+ }
7923
+
7652
7924
  // src/core/statementValidation.ts
7653
7925
  function validateStatementStatic(stmt) {
7654
7926
  validateStringFunctionArities(stmt);
7655
7927
  validatePrimaryOrganizationDmlStatement(stmt);
7656
7928
  validateKlikeStatement(stmt);
7929
+ validateGenerateSeriesInStatement(stmt);
7657
7930
  }
7658
7931
  function validateStringFunctionArities(stmt) {
7659
7932
  const visit = (value) => {
@@ -10780,11 +11053,11 @@ function validatePostImage(record, fieldIndex, numberPrecision, statementNumber,
10780
11053
  else normalizedRecord[field.code] = { value: preserveCodeObjects(raw, field.fieldType, result.value) };
10781
11054
  }
10782
11055
  for (const [tableCode, children] of fieldIndex.subtables) {
10783
- const sourceRows = record[tableCode]?.value;
10784
- if (!Array.isArray(sourceRows)) continue;
11056
+ const sourceRows2 = record[tableCode]?.value;
11057
+ if (!Array.isArray(sourceRows2)) continue;
10785
11058
  const normalizedRows = normalizedRecord[tableCode]?.value;
10786
- for (let rowIndex = 0; rowIndex < sourceRows.length; rowIndex++) {
10787
- const sourceRow = sourceRows[rowIndex];
11059
+ for (let rowIndex = 0; rowIndex < sourceRows2.length; rowIndex++) {
11060
+ const sourceRow = sourceRows2[rowIndex];
10788
11061
  const normalizedRow = normalizedRows[rowIndex];
10789
11062
  for (const field of children) {
10790
11063
  const raw = sourceRow.value?.[field.code]?.value;
@@ -13539,6 +13812,65 @@ async function deriveEmptyWildcardColumns(fields, subtableCode, loadProcessStatu
13539
13812
  }
13540
13813
 
13541
13814
  // src/engine/process.ts
13815
+ var materializedSelectValues = /* @__PURE__ */ new WeakMap();
13816
+ var sourceRows = /* @__PURE__ */ new WeakMap();
13817
+ function asProcessingRow(source) {
13818
+ if (sourceRows.has(source)) return source;
13819
+ let row;
13820
+ row = new Proxy(source, {
13821
+ get(target, property, receiver) {
13822
+ if (typeof property !== "string" || Object.prototype.hasOwnProperty.call(target, property)) {
13823
+ return Reflect.get(target, property, receiver);
13824
+ }
13825
+ return getMaterializedLookupValue(row, property);
13826
+ },
13827
+ has(target, property) {
13828
+ return Reflect.has(target, property) || typeof property === "string" && getMaterializedLookupValue(row, property) !== void 0;
13829
+ },
13830
+ getOwnPropertyDescriptor(target, property) {
13831
+ const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
13832
+ if (descriptor || typeof property !== "string") return descriptor;
13833
+ const value = getMaterializedLookupValue(row, property);
13834
+ return value === void 0 ? void 0 : { configurable: true, enumerable: false, writable: false, value };
13835
+ }
13836
+ });
13837
+ sourceRows.set(row, source);
13838
+ return row;
13839
+ }
13840
+ function sourceRowForEvaluation(row) {
13841
+ return sourceRows.get(row) ?? row;
13842
+ }
13843
+ function materializedValuesFor(row) {
13844
+ let values = materializedSelectValues.get(row);
13845
+ if (!values) {
13846
+ values = { byColumn: /* @__PURE__ */ new Map(), byLookupKey: /* @__PURE__ */ new Map() };
13847
+ materializedSelectValues.set(row, values);
13848
+ }
13849
+ return values;
13850
+ }
13851
+ function setMaterializedSelectValue(row, columnIndex, value, lookupKeys = []) {
13852
+ const values = materializedValuesFor(row);
13853
+ values.byColumn.set(columnIndex, value);
13854
+ for (const key of lookupKeys) values.byLookupKey.set(key, value);
13855
+ }
13856
+ function getMaterializedSelectValue(row, columnIndex) {
13857
+ return materializedSelectValues.get(row)?.byColumn.get(columnIndex);
13858
+ }
13859
+ function getMaterializedLookupValue(row, key) {
13860
+ return materializedSelectValues.get(row)?.byLookupKey.get(key);
13861
+ }
13862
+ function getLegacyMaterializedValue(row, key) {
13863
+ return materializedSelectValues.has(row) ? void 0 : row[key];
13864
+ }
13865
+ function havingEvaluationRow(row) {
13866
+ const lookups = materializedSelectValues.get(row)?.byLookupKey;
13867
+ if (!lookups || lookups.size === 0) return row;
13868
+ const evaluationRow = { ...row };
13869
+ for (const [key, value] of lookups) evaluationRow[key] = value;
13870
+ const groupingMeta = getGroupingRowMeta(row);
13871
+ if (groupingMeta) attachGroupingRowMeta(evaluationRow, groupingMeta.includedCanonicalIds);
13872
+ return evaluationRow;
13873
+ }
13542
13874
  function flatten(record, alias) {
13543
13875
  const row = {};
13544
13876
  for (const [field, fv] of Object.entries(record)) {
@@ -13643,7 +13975,7 @@ function applyGroupBy(rows, groupByKeys, columns, resolveAggSortKind, resolution
13643
13975
  }
13644
13976
  const result = [];
13645
13977
  for (const groupRows of groups.values()) {
13646
- const outRow = { ...groupRows[0] };
13978
+ const outRow = asProcessingRow({ ...groupRows[0] });
13647
13979
  for (const k of groupByKeys) {
13648
13980
  if (k.type === "ARITH_KEY") {
13649
13981
  outRow[arithColDefaultKey(k.expr)] = String(evalArithExpr(k.expr, groupRows[0]));
@@ -13695,7 +14027,7 @@ function applyGroupingSets(rows, spec, columns, resolveAggSortKind, limits = {})
13695
14027
  }
13696
14028
  const includedCanonicalIds = new Set(set.items.map((item) => item.canonicalId));
13697
14029
  for (const groupRows of buckets) {
13698
- const outRow = { ...groupRows[0] };
14030
+ const outRow = asProcessingRow({ ...groupRows[0] });
13699
14031
  const includedValues = /* @__PURE__ */ new Map();
13700
14032
  for (const item of set.items) {
13701
14033
  if (!includedValues.has(item.canonicalId)) {
@@ -13725,32 +14057,52 @@ function materializeAggregateColumns(outRow, groupRows, columns, resolveAggSortK
13725
14057
  if (col.type === "AGGREGATE") {
13726
14058
  const syntheticKey = aggregateSyntheticName(col.func, col.distinct, col.arg);
13727
14059
  const value = String(evalAggregate(col.func, col.distinct, col.arg, col.separator, groupRows, resolveAggSortKind));
13728
- outRow[col.alias ?? syntheticKey] = value;
13729
- if (col.alias) outRow[syntheticKey] = value;
14060
+ setMaterializedSelectValue(
14061
+ outRow,
14062
+ columnIndex,
14063
+ value,
14064
+ col.alias ? [col.alias, syntheticKey] : [syntheticKey]
14065
+ );
13730
14066
  } else if (col.type === "ARITH_AGG_COL") {
13731
14067
  materializeAggregateDependencies(outRow, groupRows, col.expr, resolveAggSortKind);
13732
14068
  const outputKey = col.alias ?? aggArithDefaultKey(col.expr);
13733
- outRow[outputKey] = String(evalAggArithExpr(col.expr, groupRows, resolveAggSortKind));
14069
+ setMaterializedSelectValue(
14070
+ outRow,
14071
+ columnIndex,
14072
+ String(evalAggArithExpr(col.expr, groupRows, resolveAggSortKind)),
14073
+ [outputKey]
14074
+ );
13734
14075
  } else if (col.type === "STRFUNC_COL" && hasAggregateInStringFuncExpr2(col.expr)) {
13735
14076
  materializeAggregateDependencies(outRow, groupRows, col.expr, resolveAggSortKind);
13736
14077
  const outputKey = col.alias ?? stringFuncDefaultKey(col.expr);
13737
14078
  const resolvedExpr = resolveAggInStringFuncExpr(col.expr, groupRows, resolveAggSortKind);
13738
- outRow[outputKey] = evalStringFunc(resolvedExpr, outRow);
14079
+ setMaterializedSelectValue(outRow, columnIndex, evalStringFunc(resolvedExpr, outRow), [outputKey]);
13739
14080
  } else if (col.type === "SCALAR_VALUE_COL" && scalarValueHasAggregate2(col.expr)) {
13740
14081
  materializeAggregateDependencies(outRow, groupRows, col.expr, resolveAggSortKind);
13741
14082
  const outputKey = col.alias ?? scalarValueDefaultKey(col.expr);
13742
14083
  const resolvedExpr = resolveAggInScalarValue(col.expr, groupRows, resolveAggSortKind);
13743
- outRow[outputKey] = String(evalScalarValueExpr(resolvedExpr, outRow));
14084
+ setMaterializedSelectValue(
14085
+ outRow,
14086
+ columnIndex,
14087
+ String(evalScalarValueExpr(resolvedExpr, outRow)),
14088
+ [outputKey]
14089
+ );
13744
14090
  } else if (col.type === "CASE_COL" && containsAggregate2(col.expr)) {
13745
14091
  materializeAggregateDependencies(outRow, groupRows, col.expr, resolveAggSortKind);
13746
14092
  const resolvedExpr = resolveAggInCaseExpr(col.expr, groupRows, resolveAggSortKind);
13747
14093
  const resolveAggregateSemantics = (field) => field.aggregateRef ? aggregateResultSemantics(field.aggregateRef, resolveAggSortKind) : void 0;
13748
- outRow[caseMaterializedKey(col.alias, columnIndex)] = evalCaseWhen(
14094
+ const value = evalCaseWhen(
13749
14095
  resolvedExpr,
13750
14096
  outRow,
13751
14097
  void 0,
13752
14098
  resolveAggregateSemantics
13753
14099
  );
14100
+ setMaterializedSelectValue(
14101
+ outRow,
14102
+ columnIndex,
14103
+ value,
14104
+ [caseMaterializedKey(col.alias, columnIndex)]
14105
+ );
13754
14106
  }
13755
14107
  }
13756
14108
  }
@@ -13776,8 +14128,8 @@ function materializeAggregateDependencies(outRow, rows, node, resolveAggSortKind
13776
14128
  collectAggregateRefs(node, refs);
13777
14129
  for (const ref of refs) {
13778
14130
  const key = aggregateSyntheticName(ref.func, ref.distinct, ref.arg);
13779
- if (outRow[key] !== void 0) continue;
13780
- outRow[key] = String(evalAggregate(
14131
+ if (getMaterializedLookupValue(outRow, key) !== void 0) continue;
14132
+ const value = String(evalAggregate(
13781
14133
  ref.func,
13782
14134
  ref.distinct,
13783
14135
  ref.arg,
@@ -13785,6 +14137,7 @@ function materializeAggregateDependencies(outRow, rows, node, resolveAggSortKind
13785
14137
  rows,
13786
14138
  resolveAggSortKind
13787
14139
  ));
14140
+ materializedValuesFor(outRow).byLookupKey.set(key, value);
13788
14141
  }
13789
14142
  }
13790
14143
  function evalGroupByKey(key, row, resolution, columns, aliasEvaluationContext) {
@@ -13899,7 +14252,8 @@ function evalAggregate(func, distinct, arg, separator, rows, resolveAggSortKind)
13899
14252
  }
13900
14253
  }
13901
14254
  function aggregateRowValues(func, arg, rows) {
13902
- return rows.map((row) => {
14255
+ return rows.map((processingRow) => {
14256
+ const row = sourceRowForEvaluation(processingRow);
13903
14257
  let strVal;
13904
14258
  if (arg.type === "FIELD_REF") {
13905
14259
  const raw = row[arg.field];
@@ -13980,7 +14334,13 @@ function aggregateResultSemantics(ref, resolver) {
13980
14334
  }
13981
14335
  function applyHaving(rows, having, resolveFieldType, resolveFieldSemantics2) {
13982
14336
  if (having === null) return rows;
13983
- return rows.filter((row) => evalWhere(having, row, resolveFieldType, void 0, resolveFieldSemantics2));
14337
+ return rows.filter((row) => evalWhere(
14338
+ having,
14339
+ havingEvaluationRow(row),
14340
+ resolveFieldType,
14341
+ void 0,
14342
+ resolveFieldSemantics2
14343
+ ));
13984
14344
  }
13985
14345
  function applyDistinct(rows, columns, scalarCache, resolveFieldType, resolveFieldSemantics2) {
13986
14346
  if (rows.length === 0) return rows;
@@ -14092,13 +14452,14 @@ var NUMERIC_ORDER_FUNCTIONS = /* @__PURE__ */ new Set([
14092
14452
  "WEEK"
14093
14453
  ]);
14094
14454
  function evalOrderKey(key, row, aliasEvaluator) {
14455
+ const sourceRow = sourceRowForEvaluation(row);
14095
14456
  switch (key.type) {
14096
14457
  case "FIELD_NAME":
14097
- return aliasEvaluator?.(key.name, row) ?? row[key.name] ?? "";
14458
+ return aliasEvaluator?.(key.name, row) ?? getMaterializedLookupValue(row, key.name) ?? sourceRow[key.name] ?? "";
14098
14459
  case "ARITH_KEY":
14099
- return String(evalArithExpr(key.expr, row));
14460
+ return String(evalArithExpr(key.expr, sourceRow));
14100
14461
  case "FUNC_KEY":
14101
- return evalStringFunc(key.expr, row);
14462
+ return evalStringFunc(key.expr, sourceRow);
14102
14463
  case "GROUPING_KEY":
14103
14464
  return evalGroupingRef(key.ref, row);
14104
14465
  }
@@ -14110,38 +14471,41 @@ function buildOrderByAliasEvaluator(columns, scalarCache, resolveFieldType, reso
14110
14471
  const alias = column.alias;
14111
14472
  switch (column.type) {
14112
14473
  case "FIELD":
14113
- evaluators.set(alias, (row) => resolveFieldRef(row, column.field));
14474
+ evaluators.set(alias, (row) => resolveFieldRef(sourceRowForEvaluation(row), column.field));
14114
14475
  break;
14115
14476
  case "LITERAL_COL":
14116
14477
  evaluators.set(alias, () => column.value);
14117
14478
  break;
14118
14479
  case "AGGREGATE": {
14119
- const source = aggregateSyntheticName(column.func, column.distinct, column.arg);
14120
- evaluators.set(alias, (row) => row[alias] ?? row[source] ?? "0");
14480
+ evaluators.set(alias, (row) => getMaterializedSelectValue(row, columnIndex) ?? "0");
14121
14481
  break;
14122
14482
  }
14123
14483
  case "ARITH_AGG_COL": {
14124
- const source = aggArithDefaultKey(column.expr);
14125
- evaluators.set(alias, (row) => row[alias] ?? row[source] ?? "0");
14484
+ evaluators.set(alias, (row) => getMaterializedSelectValue(row, columnIndex) ?? "0");
14126
14485
  break;
14127
14486
  }
14128
14487
  case "WINDOW_COL":
14129
- evaluators.set(alias, (row) => row[alias] ?? "");
14488
+ evaluators.set(alias, (row) => getMaterializedSelectValue(row, columnIndex) ?? "");
14130
14489
  break;
14131
14490
  case "ARITH_COL":
14132
- evaluators.set(alias, (row) => String(evalArithExpr(column.expr, row)));
14491
+ evaluators.set(alias, (row) => String(evalArithExpr(column.expr, sourceRowForEvaluation(row))));
14133
14492
  break;
14134
14493
  case "STRFUNC_COL": {
14135
14494
  const source = stringFuncDefaultKey(column.expr);
14136
- evaluators.set(alias, (row) => hasAggregateInStringFuncExpr2(column.expr) ? row[alias] ?? row[source] ?? evalStringFunc(column.expr, row, resolveFieldType, resolveFieldSemantics2) : evalStringFunc(column.expr, row, resolveFieldType, resolveFieldSemantics2));
14495
+ evaluators.set(alias, (row) => hasAggregateInStringFuncExpr2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, source) ?? evalStringFunc(column.expr, sourceRowForEvaluation(row), resolveFieldType, resolveFieldSemantics2) : evalStringFunc(column.expr, sourceRowForEvaluation(row), resolveFieldType, resolveFieldSemantics2));
14137
14496
  break;
14138
14497
  }
14139
14498
  case "CASE_COL":
14140
- evaluators.set(alias, (row) => containsAggregate2(column.expr) ? row[alias] ?? "" : evalCaseWhen(column.expr, row, resolveFieldType, resolveFieldSemantics2));
14499
+ evaluators.set(alias, (row) => containsAggregate2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? "" : evalCaseWhen(column.expr, sourceRowForEvaluation(row), resolveFieldType, resolveFieldSemantics2));
14141
14500
  break;
14142
14501
  case "SCALAR_VALUE_COL": {
14143
14502
  const source = scalarValueDefaultKey(column.expr);
14144
- evaluators.set(alias, (row) => scalarValueHasAggregate2(column.expr) ? row[alias] ?? row[source] ?? "" : String(evalScalarValueExpr(column.expr, row, resolveFieldType, resolveFieldSemantics2)));
14503
+ evaluators.set(alias, (row) => scalarValueHasAggregate2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, source) ?? "" : String(evalScalarValueExpr(
14504
+ column.expr,
14505
+ sourceRowForEvaluation(row),
14506
+ resolveFieldType,
14507
+ resolveFieldSemantics2
14508
+ )));
14145
14509
  break;
14146
14510
  }
14147
14511
  case "SCALAR_SUBQUERY_COL":
@@ -14157,9 +14521,10 @@ function buildOrderByAliasEvaluator(columns, scalarCache, resolveFieldType, reso
14157
14521
  return (name, row) => evaluators.get(name)?.(row);
14158
14522
  }
14159
14523
  function applyWindow(rows, columns, optionOrders, sortKinds, fieldSemantics2, resolveAggSortKind) {
14160
- const windows = columns.filter((column) => column.type === "WINDOW_COL");
14524
+ const windows = columns.map((column, columnIndex) => ({ column, columnIndex })).filter((item) => item.column.type === "WINDOW_COL");
14161
14525
  if (rows.length === 0 || windows.length === 0) return rows;
14162
- for (const window of windows) {
14526
+ for (let index = 0; index < rows.length; index++) rows[index] = asProcessingRow(rows[index]);
14527
+ for (const { column: window, columnIndex } of windows) {
14163
14528
  const partitions = /* @__PURE__ */ new Map();
14164
14529
  for (const row of rows) {
14165
14530
  const key = JSON.stringify(window.partitionBy.map((ref) => resolveWindowField(row, ref)));
@@ -14171,11 +14536,11 @@ function applyWindow(rows, columns, optionOrders, sortKinds, fieldSemantics2, re
14171
14536
  const sortedResult = sortDecoratedRows(partition, window.orderBy, optionOrders, sortKinds, fieldSemantics2);
14172
14537
  const sorted = sortedResult.rows;
14173
14538
  if (isAggregateWindow(window)) {
14174
- applyAggregateWindow(window, sortedResult, resolveAggSortKind);
14539
+ applyAggregateWindow(window, columnIndex, sortedResult, resolveAggSortKind);
14175
14540
  continue;
14176
14541
  }
14177
14542
  if (isValueWindow(window)) {
14178
- applyValueWindow(window, sorted);
14543
+ applyValueWindow(window, columnIndex, sorted);
14179
14544
  continue;
14180
14545
  }
14181
14546
  if (!isRankingWindow(window)) {
@@ -14189,27 +14554,32 @@ function applyWindow(rows, columns, optionOrders, sortKinds, fieldSemantics2, re
14189
14554
  denseRank++;
14190
14555
  }
14191
14556
  const value = window.func === "ROW_NUMBER" ? index + 1 : window.func === "RANK" ? rank : denseRank;
14192
- sorted[index].row[window.alias] = String(value);
14557
+ setMaterializedSelectValue(sorted[index].row, columnIndex, String(value), [window.alias]);
14193
14558
  }
14194
14559
  }
14195
14560
  }
14196
14561
  return rows;
14197
14562
  }
14198
14563
  function evaluateValueWindowArg(arg, row) {
14199
- const value = evalScalarValueExprNullable(arg, row);
14564
+ const value = evalScalarValueExprNullable(arg, sourceRowForEvaluation(row));
14200
14565
  if (value === null || value === void 0) return "";
14201
14566
  if (typeof value === "number" && !Number.isFinite(value)) return "";
14202
14567
  return String(value);
14203
14568
  }
14204
- function applyValueWindow(window, sorted) {
14569
+ function applyValueWindow(window, columnIndex, sorted) {
14205
14570
  const values = sorted.map((item) => evaluateValueWindowArg(window.arg, item.row));
14206
14571
  const direction = window.valueFunc === "LAG" ? -1 : 1;
14207
14572
  for (let index = 0; index < sorted.length; index++) {
14208
14573
  const target = index + direction * window.offset;
14209
- sorted[index].row[window.alias] = target >= 0 && target < values.length ? values[target] : "";
14574
+ setMaterializedSelectValue(
14575
+ sorted[index].row,
14576
+ columnIndex,
14577
+ target >= 0 && target < values.length ? values[target] : "",
14578
+ [window.alias]
14579
+ );
14210
14580
  }
14211
14581
  }
14212
- function applyAggregateWindow(window, sortedResult, resolveAggSortKind) {
14582
+ function applyAggregateWindow(window, columnIndex, sortedResult, resolveAggSortKind) {
14213
14583
  const sorted = sortedResult.rows;
14214
14584
  const values = window.arg.type === "WILDCARD" ? null : aggregateRowValues(window.aggFunc, window.arg, sorted.map((item) => item.row));
14215
14585
  const comparison = window.arg.type === "WILDCARD" ? void 0 : resolveAggregateArgSemantics(window.arg, resolveAggSortKind);
@@ -14242,23 +14612,29 @@ function applyAggregateWindow(window, sortedResult, resolveAggSortKind) {
14242
14612
  }
14243
14613
  if (window.frame === null) {
14244
14614
  const finalValue = output[output.length - 1];
14245
- for (const item of sorted) item.row[window.alias] = finalValue;
14615
+ for (const item of sorted) {
14616
+ setMaterializedSelectValue(item.row, columnIndex, finalValue, [window.alias]);
14617
+ }
14246
14618
  return;
14247
14619
  }
14248
14620
  if (window.frame.unit === "RANGE") {
14249
14621
  for (let start = 0; start < sorted.length; ) {
14250
14622
  let end = start;
14251
14623
  while (end + 1 < sorted.length && sortedResult.compare(sorted[end], sorted[end + 1]) === 0) end++;
14252
- for (let index = start; index <= end; index++) sorted[index].row[window.alias] = output[end];
14624
+ for (let index = start; index <= end; index++) {
14625
+ setMaterializedSelectValue(sorted[index].row, columnIndex, output[end], [window.alias]);
14626
+ }
14253
14627
  start = end + 1;
14254
14628
  }
14255
14629
  return;
14256
14630
  }
14257
- for (let index = 0; index < sorted.length; index++) sorted[index].row[window.alias] = output[index];
14631
+ for (let index = 0; index < sorted.length; index++) {
14632
+ setMaterializedSelectValue(sorted[index].row, columnIndex, output[index], [window.alias]);
14633
+ }
14258
14634
  }
14259
14635
  function resolveWindowField(row, ref) {
14260
14636
  const name = ref.tableAlias ? `${ref.tableAlias}.${ref.field}` : ref.field;
14261
- return resolveFieldRef(row, name);
14637
+ return resolveFieldRef(sourceRowForEvaluation(row), name);
14262
14638
  }
14263
14639
  function applyLimit(rows, limit, offset) {
14264
14640
  const start = offset ?? 0;
@@ -14266,41 +14642,42 @@ function applyLimit(rows, limit, offset) {
14266
14642
  return rows.slice(start, start + limit);
14267
14643
  }
14268
14644
  function evaluateSelectColumnValue(column, row, columnIndex, context = {}) {
14645
+ const sourceRow = sourceRowForEvaluation(row);
14269
14646
  switch (column.type) {
14270
14647
  case "VARIABLE_COL":
14271
14648
  throw new Error(`internal error: unresolved SELECT variable @${column.name}`);
14272
14649
  case "WILDCARD": {
14273
- const keys = context.wildcardKeys ?? Object.keys(row);
14650
+ const keys = context.wildcardKeys ?? Object.keys(sourceRow);
14274
14651
  return {
14275
14652
  kind: "EXPANDED",
14276
- entries: keys.map((key) => [key, row[key] !== void 0 ? row[key] : null])
14653
+ entries: keys.map((key) => [key, sourceRow[key] !== void 0 ? sourceRow[key] : null])
14277
14654
  };
14278
14655
  }
14279
14656
  case "PARENT_WILDCARD": {
14280
- const keys = context.parentWildcardKeys ?? Object.keys(row).filter((key) => key.startsWith("_p.")).sort();
14657
+ const keys = context.parentWildcardKeys ?? Object.keys(sourceRow).filter((key) => key.startsWith("_p.")).sort();
14281
14658
  return {
14282
14659
  kind: "EXPANDED",
14283
- entries: keys.map((key) => [key, row[key] !== void 0 ? row[key] : null])
14660
+ entries: keys.map((key) => [key, sourceRow[key] !== void 0 ? sourceRow[key] : null])
14284
14661
  };
14285
14662
  }
14286
14663
  case "FIELD":
14287
- return resolveFieldRef(row, column.field);
14664
+ return resolveFieldRef(sourceRow, column.field);
14288
14665
  case "LITERAL_COL":
14289
14666
  return column.value;
14290
14667
  case "AGGREGATE": {
14291
14668
  const source = aggregateSyntheticName(column.func, column.distinct, column.arg);
14292
- return row[column.alias ?? source] ?? row[source] ?? "0";
14669
+ return getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, column.alias ?? source) ?? getMaterializedLookupValue(row, source) ?? getLegacyMaterializedValue(row, column.alias ?? source) ?? getLegacyMaterializedValue(row, source) ?? "0";
14293
14670
  }
14294
14671
  case "ARITH_AGG_COL": {
14295
14672
  const source = column.alias ?? aggArithDefaultKey(column.expr);
14296
- return row[source] ?? "0";
14673
+ return getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, source) ?? getLegacyMaterializedValue(row, source) ?? "0";
14297
14674
  }
14298
14675
  case "ARITH_COL":
14299
- return String(evalArithExpr(column.expr, row));
14676
+ return String(evalArithExpr(column.expr, sourceRow));
14300
14677
  case "CASE_COL":
14301
- return containsAggregate2(column.expr) ? row[caseMaterializedKey(column.alias, columnIndex)] ?? "" : evalCaseWhen(
14678
+ return containsAggregate2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, caseMaterializedKey(column.alias, columnIndex)) ?? getLegacyMaterializedValue(row, caseMaterializedKey(column.alias, columnIndex)) ?? "" : evalCaseWhen(
14302
14679
  column.expr,
14303
- row,
14680
+ sourceRow,
14304
14681
  context.resolveFieldType,
14305
14682
  context.resolveFieldSemantics
14306
14683
  );
@@ -14308,23 +14685,23 @@ function evaluateSelectColumnValue(column, row, columnIndex, context = {}) {
14308
14685
  return evalGroupingRef(column.ref, row);
14309
14686
  case "STRFUNC_COL": {
14310
14687
  const source = stringFuncDefaultKey(column.expr);
14311
- return hasAggregateInStringFuncExpr2(column.expr) ? row[column.alias ?? source] ?? row[source] ?? evalStringFunc(
14688
+ return hasAggregateInStringFuncExpr2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, column.alias ?? source) ?? getMaterializedLookupValue(row, source) ?? getLegacyMaterializedValue(row, column.alias ?? source) ?? getLegacyMaterializedValue(row, source) ?? evalStringFunc(
14312
14689
  column.expr,
14313
- row,
14690
+ sourceRow,
14314
14691
  context.resolveFieldType,
14315
14692
  context.resolveFieldSemantics
14316
14693
  ) : evalStringFunc(
14317
14694
  column.expr,
14318
- row,
14695
+ sourceRow,
14319
14696
  context.resolveFieldType,
14320
14697
  context.resolveFieldSemantics
14321
14698
  );
14322
14699
  }
14323
14700
  case "SCALAR_VALUE_COL": {
14324
14701
  const source = scalarValueDefaultKey(column.expr);
14325
- return scalarValueHasAggregate2(column.expr) ? row[column.alias ?? source] ?? row[source] ?? "" : String(evalScalarValueExpr(
14702
+ return scalarValueHasAggregate2(column.expr) ? getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, column.alias ?? source) ?? getMaterializedLookupValue(row, source) ?? getLegacyMaterializedValue(row, column.alias ?? source) ?? getLegacyMaterializedValue(row, source) ?? "" : String(evalScalarValueExpr(
14326
14703
  column.expr,
14327
- row,
14704
+ sourceRow,
14328
14705
  context.resolveFieldType,
14329
14706
  context.resolveFieldSemantics
14330
14707
  ));
@@ -14332,7 +14709,7 @@ function evaluateSelectColumnValue(column, row, columnIndex, context = {}) {
14332
14709
  case "SCALAR_SUBQUERY_COL":
14333
14710
  return context.scalarCache?.get(columnIndex) ?? "";
14334
14711
  case "WINDOW_COL":
14335
- return row[column.alias] ?? "";
14712
+ return getMaterializedSelectValue(row, columnIndex) ?? getMaterializedLookupValue(row, column.alias) ?? getLegacyMaterializedValue(row, column.alias) ?? "";
14336
14713
  }
14337
14714
  }
14338
14715
  function buildDistinctTuple(columns, row, context = {}) {
@@ -16426,9 +16803,9 @@ function render(value) {
16426
16803
  function buildImportRecordPayload(top, subtables, rowIdMode) {
16427
16804
  const record = {};
16428
16805
  for (const [code, value] of top) record[code] = { value };
16429
- for (const [tableCode, sourceRows] of subtables) {
16806
+ for (const [tableCode, sourceRows2] of subtables) {
16430
16807
  record[tableCode] = {
16431
- value: sourceRows.map((sourceRow) => ({
16808
+ value: sourceRows2.map((sourceRow) => ({
16432
16809
  ...rowIdMode === "PRESERVE" && sourceRow.rowId ? { id: sourceRow.rowId } : {},
16433
16810
  value: Object.fromEntries([...sourceRow.values].map(([childCode, value]) => [childCode, { value }]))
16434
16811
  }))
@@ -17663,7 +18040,7 @@ function resolveBatchVariableReferencesInternal(node, variables, numericArithmet
17663
18040
  type: "NUMBER",
17664
18041
  value: value.value,
17665
18042
  raw: numericArithmeticOperand === "AGG_ARITH" ? `@${obj["name"]}` : value.raw ?? String(value.value)
17666
- } : { type: "STRING", value: value.value };
18043
+ } : { type: "STRING", value: value.value, fromVariable: true };
17667
18044
  }
17668
18045
  if (obj["type"] === "VARIABLE_COL" && typeof obj["name"] === "string" && typeof obj["alias"] === "string") {
17669
18046
  const value = variables.get(obj["name"]);
@@ -17979,10 +18356,16 @@ function hasDefaultRangeAggregateWindow(stmt) {
17979
18356
  function hasWindowNeedingOrderProof(stmt) {
17980
18357
  return hasDefaultRangeAggregateWindow(stmt) || stmt.columns.some((column) => column.type === "WINDOW_COL" && column.windowKind === "VALUE");
17981
18358
  }
17982
- function canProveTotalWindowOrder(stmt, orderBy, resolveField2, context) {
17983
- if (context !== "DIRECT" || stmt.joins.length > 0 || stmt.from.cteName !== null || stmt.from.subtableCode != null) {
17984
- return false;
18359
+ function canProveTotalWindowOrder(stmt, orderBy, resolveField2, context, generatedColumn) {
18360
+ if (generatedColumn !== void 0 && stmt.joins.length === 0 && stmt.from.cteName !== null) {
18361
+ return orderBy.some((item) => {
18362
+ if (item.key.type !== "FIELD_NAME") return false;
18363
+ const ref = aggregateFieldRef(item.key.name);
18364
+ if (ref.field !== generatedColumn) return false;
18365
+ return ref.tableAlias === null || ref.tableAlias === effectiveTableAlias(stmt.from);
18366
+ });
17985
18367
  }
18368
+ if (context !== "DIRECT" || stmt.joins.length > 0 || stmt.from.cteName !== null || stmt.from.subtableCode != null) return false;
17986
18369
  return orderBy.some((item) => {
17987
18370
  if (item.key.type !== "FIELD_NAME") return false;
17988
18371
  const ref = aggregateFieldRef(item.key.name);
@@ -17991,22 +18374,22 @@ function canProveTotalWindowOrder(stmt, orderBy, resolveField2, context) {
17991
18374
  }
17992
18375
  function tieBreakAdvice(context, kind) {
17993
18376
  if (context !== "DIRECT") {
17994
- return "\u305D\u306E\u8868\u306E\u4E2D\u3067\u4E00\u610F\u306B\u306A\u308B\u5217\uFF08\u5143\u306E\u96C6\u7D04\u306E\u30AD\u30FC\u306A\u3069\uFF09\u3092 ORDER BY \u306B\u542B\u3081\u3066\u304F\u3060\u3055\u3044\u3002\u96C6\u7D04\u7D50\u679C\u306E\u5217\u306F\u4E00\u610F\u3067\u3082\u8A3C\u660E\u3067\u304D\u306A\u3044\u305F\u3081\u3001\u3059\u3067\u306B\u4E00\u610F\u306A\u5834\u5408\u3082\u3053\u306E\u8B66\u544A\u304C\u51FA\u307E\u3059\u3002";
18377
+ return "\u305D\u306E\u8868\u306E\u4E2D\u3067\u4E00\u610F\u306B\u306A\u308B\u5217\uFF08\u5143\u306E\u96C6\u7D04\u306E\u30AD\u30FC\u306A\u3069\uFF09\u3092 ORDER BY \u306B\u542B\u3081\u3066\u304F\u3060\u3055\u3044\u3002\u96C6\u7D04\u7D50\u679C\u306E\u5217\u306F\u4E00\u610F\u3067\u3082\u8A3C\u660E\u3067\u304D\u306A\u3044\u305F\u3081\u3001\u3059\u3067\u306B\u4E00\u610F\u306A\u5834\u5408\u3082\u3053\u306E\u8B66\u544A\u304C\u51FA\u307E\u3059\u3002\u5143\u306E\u96C6\u7D04\u306E\u30AD\u30FC\u3092\u3059\u3079\u3066 ORDER BY \u306B\u542B\u3081\u3066\u3044\u308B\u306A\u3089\u3001\u3053\u306E\u8B66\u544A\u306F\u7121\u8996\u3057\u3066\u69CB\u3044\u307E\u305B\u3093\u3002";
17995
18378
  }
17996
18379
  return kind === "RANGE" ? "ORDER BY \u306B\u30EC\u30B3\u30FC\u30C9\u756A\u53F7\u306A\u3069\u306E\u30BF\u30A4\u30D6\u30EC\u30FC\u30AF\u30AD\u30FC\u3092\u8DB3\u3057\u3066\u304F\u3060\u3055\u3044\u3002" : "\u30EC\u30B3\u30FC\u30C9\u756A\u53F7\u7B49\u3092 ORDER BY \u306B\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\u3002";
17997
18380
  }
17998
- function collectDefaultRangeWindowWarnings(stmt, resolveField2, context) {
18381
+ function collectDefaultRangeWindowWarnings(stmt, resolveField2, context, generatedColumn) {
17999
18382
  const warnings = [];
18000
18383
  for (const column of stmt.columns) {
18001
18384
  if (column.type !== "WINDOW_COL" || column.windowKind !== "AGGREGATE" || column.orderBy.length === 0 || column.frame?.source !== "DEFAULT") continue;
18002
- if (canProveTotalWindowOrder(stmt, column.orderBy, resolveField2, context)) continue;
18385
+ if (canProveTotalWindowOrder(stmt, column.orderBy, resolveField2, context, generatedColumn)) continue;
18003
18386
  warnings.push(
18004
18387
  `${column.alias} \u306F\u65E2\u5B9A\u30D5\u30EC\u30FC\u30E0\uFF08RANGE\uFF09\u3067\u8A55\u4FA1\u3055\u308C\u307E\u3059\u3002ORDER BY \u306E\u5024\u304C\u540C\u3058\u884C\u306F\u3059\u3079\u3066\u540C\u3058\u5024\u306B\u306A\u308A\u307E\u3059\u3002\u884C\u3054\u3068\u306E\u5024\u304C\u5FC5\u8981\u306A\u3089 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW \u3092\u660E\u793A\u3059\u308B\u304B\u3001` + tieBreakAdvice(context, "RANGE")
18005
18388
  );
18006
18389
  }
18007
18390
  for (const column of stmt.columns) {
18008
18391
  if (column.type !== "WINDOW_COL" || column.windowKind !== "VALUE") continue;
18009
- if (canProveTotalWindowOrder(stmt, column.orderBy, resolveField2, context)) continue;
18392
+ if (canProveTotalWindowOrder(stmt, column.orderBy, resolveField2, context, generatedColumn)) continue;
18010
18393
  warnings.push(
18011
18394
  `${column.alias} \u306E ORDER BY \u306F\u5168\u9806\u5E8F\u3067\u306A\u3044\u305F\u3081\u3001\u540C\u9806\u5185\u306E\u524D\u5F8C\u95A2\u4FC2\u306F\u672A\u898F\u5B9A\u3067\u3059\u3002` + tieBreakAdvice(context, "VALUE")
18012
18395
  );
@@ -19937,6 +20320,8 @@ async function executeWith(stmt, client, options, cacheContext, seed, captureCol
19937
20320
  result2 = await executeShowApps(client);
19938
20321
  } else if (cte.query.type === "DESCRIBE") {
19939
20322
  result2 = await executeDescribe(cte.query, client, cacheContext);
20323
+ } else if (cte.query.type === "GENERATE_SERIES") {
20324
+ result2 = executeGenerateSeries(cte.query);
19940
20325
  } else {
19941
20326
  result2 = await executeQueryWithCte(cte.query, client, options, cteCache, cacheContext, true);
19942
20327
  }
@@ -19944,7 +20329,8 @@ async function executeWith(stmt, client, options, cacheContext, seed, captureCol
19944
20329
  cteCache.set(cte.name, {
19945
20330
  rows: result2.rows,
19946
20331
  columns: result2.columns,
19947
- columnMeta: materializedMetaBySelectResult.get(result2)
20332
+ columnMeta: materializedMetaBySelectResult.get(result2),
20333
+ ...cte.query.type === "GENERATE_SERIES" ? { uniqueGeneratedColumn: cte.query.columnAlias } : {}
19948
20334
  });
19949
20335
  }
19950
20336
  const result = await executeQueryWithCte(
@@ -19957,6 +20343,27 @@ async function executeWith(stmt, client, options, cacheContext, seed, captureCol
19957
20343
  );
19958
20344
  return mergeSelectWarnings(result, [...warnings]);
19959
20345
  }
20346
+ function executeGenerateSeries(stmt) {
20347
+ const series = resolveGenerateSeries(stmt);
20348
+ const result = {
20349
+ type: "SELECT",
20350
+ columns: [stmt.columnAlias],
20351
+ rows: series.values.map((value) => ({ [stmt.columnAlias]: value })),
20352
+ rowCount: series.rowCount,
20353
+ warnings: []
20354
+ };
20355
+ const meta = series.kind === "INTEGER" ? {
20356
+ sortKind: "number",
20357
+ fieldType: "NUMBER",
20358
+ semantics: resolveFieldSemantics({ fieldType: "NUMBER" })
20359
+ } : {
20360
+ sortKind: "string",
20361
+ fieldType: "DATE",
20362
+ semantics: resolveFieldSemantics({ fieldType: "DATE" })
20363
+ };
20364
+ materializedMetaBySelectResult.set(result, /* @__PURE__ */ new Map([[stmt.columnAlias, meta]]));
20365
+ return result;
20366
+ }
19960
20367
  async function executeQueryWithCte(query, client, options, cteCache, cacheContext, captureColumnMeta = false, b86PreflightComplete = false) {
19961
20368
  if (!b86PreflightComplete) {
19962
20369
  await preflightB86QueryWithCte(query, client, cteCache, cacheContext);
@@ -20063,7 +20470,8 @@ async function executeFullScanWithCte(stmt, client, options, cteCache, cacheCont
20063
20470
  const defaultRangeWarnings = collectDefaultRangeWindowWarnings(
20064
20471
  stmt,
20065
20472
  choiceAndWindowResolver,
20066
- "DERIVED"
20473
+ "DERIVED",
20474
+ stmt.joins.length === 0 && stmt.from.cteName !== null ? cteCache.get(stmt.from.cteName)?.uniqueGeneratedColumn : void 0
20067
20475
  );
20068
20476
  const maxRecords = options.maxRecords ?? 1e4;
20069
20477
  const warnings = /* @__PURE__ */ new Set();
@@ -20370,10 +20778,10 @@ async function tryFetchJoinRecordsBySourceKeys(stmt, join2, tables, client, maxR
20370
20778
  } else {
20371
20779
  return null;
20372
20780
  }
20373
- const sourceRows = tables.get(sourceAlias);
20374
- if (!sourceRows) return null;
20781
+ const sourceRows2 = tables.get(sourceAlias);
20782
+ if (!sourceRows2) return null;
20375
20783
  const keys = /* @__PURE__ */ new Set();
20376
- for (const row of sourceRows) {
20784
+ for (const row of sourceRows2) {
20377
20785
  const raw = row[sourceField]?.value;
20378
20786
  const txt = toScalarText(raw).trim();
20379
20787
  if (txt.length > 0) keys.add(txt);
@@ -21283,7 +21691,7 @@ async function materializeValidationCandidates(stmt, operation, client, options,
21283
21691
  );
21284
21692
  }
21285
21693
  let rows;
21286
- let sourceRows;
21694
+ let sourceRows2;
21287
21695
  let sourcePresence;
21288
21696
  let sourceRowErrors;
21289
21697
  let evaluationTypes;
@@ -21304,7 +21712,7 @@ async function materializeValidationCandidates(stmt, operation, client, options,
21304
21712
  throw customCheckParseError("CHECK \u4ED8\u304D DML \u30BD\u30FC\u30B9 SELECT \u306E\u51FA\u529B\u540D\u306F\u4E00\u610F\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059");
21305
21713
  }
21306
21714
  assertInsertCheckRefs(stmt, selectResult.columns);
21307
- sourceRows = selectResult.rows;
21715
+ sourceRows2 = selectResult.rows;
21308
21716
  sourcePresence = selectResult.importPresence;
21309
21717
  sourceRowErrors = selectResult.importRowErrors;
21310
21718
  const meta = selectResult.columnMeta;
@@ -21325,7 +21733,7 @@ async function materializeValidationCandidates(stmt, operation, client, options,
21325
21733
  )),
21326
21734
  preErrors: [...sourceRowErrors?.[index] ?? []],
21327
21735
  record: {},
21328
- evaluationRow: sourceRows?.[index] ?? Object.fromEntries(
21736
+ evaluationRow: sourceRows2?.[index] ?? Object.fromEntries(
21329
21737
  stmt.fields.map((field, i) => [field, renderValidationValue(values[i])])
21330
21738
  ),
21331
21739
  evaluationFieldTypes: evaluationTypes
@@ -21621,7 +22029,7 @@ async function resolveUpdateFromMatchedRecords(stmt, from, client, options, cach
21621
22029
  const checkScope = await resolveUpdateFromCheckScope(stmt, from, client, cacheContext, tempTables);
21622
22030
  const sourceFields = [...new Set(stmt.assignments.filter((a) => a.value.type === "SOURCE_FIELD").map((a) => a.value.type === "SOURCE_FIELD" ? a.value.field : "").concat(checkScope.sourceFields))];
21623
22031
  const requiredSourceFields = [.../* @__PURE__ */ new Set([from.joinKeyField, ...sourceFields])];
21624
- const sourceRows = await loadUpdateFromSourceRows(
22032
+ const sourceRows2 = await loadUpdateFromSourceRows(
21625
22033
  from,
21626
22034
  requiredSourceFields,
21627
22035
  sourceFields,
@@ -21632,7 +22040,7 @@ async function resolveUpdateFromMatchedRecords(stmt, from, client, options, cach
21632
22040
  );
21633
22041
  const sourceByKey = /* @__PURE__ */ new Map();
21634
22042
  const sourceQueryByKey = /* @__PURE__ */ new Map();
21635
- for (const row of sourceRows) {
22043
+ for (const row of sourceRows2) {
21636
22044
  if (!Object.prototype.hasOwnProperty.call(row, from.joinKeyField)) {
21637
22045
  throw new Error(`ArgumentError: UPDATE ... FROM source column ${from.joinKeyField} does not exist.`);
21638
22046
  }
@@ -23736,6 +24144,9 @@ async function buildExplainWhereAnalysis(query, client, cacheContext, maxRecords
23736
24144
  }
23737
24145
  if (typed["type"] === "SHOW_APPS") return [...SHOW_APPS_COLUMNS];
23738
24146
  if (typed["type"] === "DESCRIBE") return [...DESCRIBE_COLUMNS];
24147
+ if (typed["type"] === "GENERATE_SERIES") {
24148
+ return [node.columnAlias];
24149
+ }
23739
24150
  throw new Error("ArgumentError: EXPLAIN could not determine the relation output schema.");
23740
24151
  };
23741
24152
  const preflightExplainRelations = async (node) => {
@@ -25029,6 +25440,22 @@ function buildWithPlan(stmt, capabilities, orderPlans, plainGroupByPlans, collec
25029
25440
  "cte"
25030
25441
  ));
25031
25442
  lines.push("");
25443
+ } else if (cte.query.type === "GENERATE_SERIES") {
25444
+ const series = resolveGenerateSeries(cte.query);
25445
+ const step = series.kind === "DATE" ? `${series.step} ${Math.abs(series.step) === 1 ? "day" : "days"}` : String(series.step);
25446
+ lines.push(
25447
+ `[cte: ${cte.name}]`,
25448
+ " source: GENERATE_SERIES",
25449
+ ` column: ${cte.query.columnAlias}`,
25450
+ ` series type: ${series.kind}`,
25451
+ ` start: ${series.start}`,
25452
+ ` stop: ${series.stop}`,
25453
+ ` step: ${step}`,
25454
+ ` rows: ${series.rowCount}`,
25455
+ ` row guard: ${series.rowCount} / ${GENERATE_SERIES_MAX_ROWS}`,
25456
+ " records API: none",
25457
+ ""
25458
+ );
25032
25459
  }
25033
25460
  }
25034
25461
  if (stmt.query.type === "SELECT" || stmt.query.type === "UNION") {
@@ -25979,19 +26406,19 @@ function normalizeSqlAppProfiles(sql, defaultProfile = "dev", resolutionContext)
25979
26406
  var PHYSICAL_APP_KEY_RE = /^APP\d+$/i;
25980
26407
  var NUMERIC_APP_KEY_RE = /^\d+$/;
25981
26408
  var LOGICAL_SQL_KEY_RE = /^LAPP_/i;
25982
- function argumentError(message) {
26409
+ function argumentError2(message) {
25983
26410
  return new Error(`ArgumentError: ${message}`);
25984
26411
  }
25985
26412
  function normalizeLogicalApps(profileName, value) {
25986
26413
  if (value === void 0) return void 0;
25987
26414
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
25988
- throw argumentError(`logicalApps for profile "${profileName}" must be an object.`);
26415
+ throw argumentError2(`logicalApps for profile "${profileName}" must be an object.`);
25989
26416
  }
25990
26417
  const normalized = {};
25991
26418
  const physicalIdOwners = /* @__PURE__ */ new Map();
25992
26419
  for (const [rawName, rawAppId] of Object.entries(value)) {
25993
26420
  if (PHYSICAL_APP_KEY_RE.test(rawName) || NUMERIC_APP_KEY_RE.test(rawName) || LOGICAL_SQL_KEY_RE.test(rawName)) {
25994
- throw argumentError(
26421
+ throw argumentError2(
25995
26422
  `logical app key "${rawName}" in profile "${profileName}" must be a logical name without APP, numeric, or LAPP_ syntax.`
25996
26423
  );
25997
26424
  }
@@ -25999,23 +26426,23 @@ function normalizeLogicalApps(profileName, value) {
25999
26426
  try {
26000
26427
  logicalName = canonicalizeLogicalAppName(rawName);
26001
26428
  } catch {
26002
- throw argumentError(
26429
+ throw argumentError2(
26003
26430
  `logical app key "${rawName}" in profile "${profileName}" must match the logical app name rules.`
26004
26431
  );
26005
26432
  }
26006
26433
  if (Object.prototype.hasOwnProperty.call(normalized, logicalName)) {
26007
- throw argumentError(
26434
+ throw argumentError2(
26008
26435
  `logical app name "${logicalName}" is duplicated after case normalization in profile "${profileName}".`
26009
26436
  );
26010
26437
  }
26011
26438
  if (typeof rawAppId !== "number" || !Number.isSafeInteger(rawAppId) || rawAppId <= 0) {
26012
- throw argumentError(
26439
+ throw argumentError2(
26013
26440
  `physical app ID for logical app "${logicalName}" in profile "${profileName}" must be a positive safe integer.`
26014
26441
  );
26015
26442
  }
26016
26443
  const existingName = physicalIdOwners.get(rawAppId);
26017
26444
  if (existingName !== void 0) {
26018
- throw argumentError(
26445
+ throw argumentError2(
26019
26446
  `logical apps "${existingName}" and "${logicalName}" in profile "${profileName}" map to the same physical app ID ${rawAppId}; physical app aliases are not supported yet.`
26020
26447
  );
26021
26448
  }
@@ -26026,31 +26453,31 @@ function normalizeLogicalApps(profileName, value) {
26026
26453
  }
26027
26454
  function validateKsqlConfig(config) {
26028
26455
  if (config === null || typeof config !== "object" || Array.isArray(config)) {
26029
- throw argumentError("config must be an object.");
26456
+ throw argumentError2("config must be an object.");
26030
26457
  }
26031
26458
  if (config.profiles === void 0) return config;
26032
26459
  if (config.profiles === null || typeof config.profiles !== "object" || Array.isArray(config.profiles)) {
26033
- throw argumentError("profiles must be an object.");
26460
+ throw argumentError2("profiles must be an object.");
26034
26461
  }
26035
26462
  for (const [profileName, profile] of Object.entries(config.profiles)) {
26036
26463
  if (profile === null || typeof profile !== "object" || Array.isArray(profile)) {
26037
- throw argumentError(`profile "${profileName}" must be an object.`);
26464
+ throw argumentError2(`profile "${profileName}" must be an object.`);
26038
26465
  }
26039
26466
  if (profile.allowPhysicalAppRefs !== void 0 && typeof profile.allowPhysicalAppRefs !== "boolean") {
26040
- throw argumentError(`allowPhysicalAppRefs for profile "${profileName}" must be boolean.`);
26467
+ throw argumentError2(`allowPhysicalAppRefs for profile "${profileName}" must be boolean.`);
26041
26468
  }
26042
26469
  const logicalApps = normalizeLogicalApps(profileName, profile.logicalApps);
26043
26470
  if (logicalApps !== void 0) profile.logicalApps = logicalApps;
26044
26471
  if (profile.query?.cursorMaxActive !== void 0) {
26045
26472
  const value = profile.query.cursorMaxActive;
26046
26473
  if (!Number.isSafeInteger(value) || value < 1 || value > 5) {
26047
- throw argumentError(`query.cursorMaxActive for profile "${profileName}" must be an integer from 1 to 5.`);
26474
+ throw argumentError2(`query.cursorMaxActive for profile "${profileName}" must be an integer from 1 to 5.`);
26048
26475
  }
26049
26476
  }
26050
26477
  if (profile.query?.dmlMaxSubtableRows !== void 0) {
26051
26478
  const value = profile.query.dmlMaxSubtableRows;
26052
26479
  if (!Number.isSafeInteger(value) || value <= 0) {
26053
- throw argumentError(`query.dmlMaxSubtableRows for profile "${profileName}" must be a positive safe integer.`);
26480
+ throw argumentError2(`query.dmlMaxSubtableRows for profile "${profileName}" must be a positive safe integer.`);
26054
26481
  }
26055
26482
  }
26056
26483
  }
@@ -26070,7 +26497,7 @@ function createAppResolutionContext(config, defaultProfile) {
26070
26497
  function requireProfile(profileName) {
26071
26498
  const profile = profiles[profileName];
26072
26499
  if (!profile && profileName === defaultProfile) return implicitDefaultProfile;
26073
- if (!profile) throw argumentError(`profile "${profileName}" is not defined.`);
26500
+ if (!profile) throw argumentError2(`profile "${profileName}" is not defined.`);
26074
26501
  return profile;
26075
26502
  }
26076
26503
  return {
@@ -26080,11 +26507,11 @@ function createAppResolutionContext(config, defaultProfile) {
26080
26507
  try {
26081
26508
  logicalName = canonicalizeLogicalAppName(name);
26082
26509
  } catch {
26083
- throw argumentError(`logical app name "${name}" must match the logical app name rules.`);
26510
+ throw argumentError2(`logical app name "${name}" must match the logical app name rules.`);
26084
26511
  }
26085
26512
  const appId = requireProfile(profileName).logicalApps?.[logicalName];
26086
26513
  if (appId === void 0) {
26087
- throw argumentError(`logical app LAPP_${logicalName}@${profileName} is not defined.`);
26514
+ throw argumentError2(`logical app LAPP_${logicalName}@${profileName} is not defined.`);
26088
26515
  }
26089
26516
  return appId;
26090
26517
  },
@@ -26092,7 +26519,7 @@ function createAppResolutionContext(config, defaultProfile) {
26092
26519
  const profileName = profile || defaultProfile;
26093
26520
  if (!profiles[profileName]) return;
26094
26521
  if (requireProfile(profileName).allowPhysicalAppRefs === false) {
26095
- throw argumentError(
26522
+ throw argumentError2(
26096
26523
  `physical app references are not allowed for profile "${profileName}"; use LAPP_<NAME>.`
26097
26524
  );
26098
26525
  }