@rex0220/kintone-sql-tools 3.68.0 → 3.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist-cli/ksql.js +318 -59
- package/dist-engine/index.cjs +16 -16
- package/dist-engine/index.mjs +16 -16
- package/dist-engine/ksql-engine.umd.js +16 -16
- package/dist-engine/meta/bundle-baseline.json +10 -10
- package/dist-engine/meta/cjs.json +100 -43
- package/dist-engine/meta/esm.json +100 -43
- package/dist-engine/meta/umd.json +100 -43
- package/dist-flow/flow-library/errors.d.ts +6 -0
- package/dist-flow/flow-library/index.d.ts +12 -0
- package/dist-flow/flow-library/publicTypes.d.ts +225 -0
- package/dist-flow/flow-library/writableClient.d.ts +2 -0
- package/dist-flow/index.cjs +18 -0
- package/dist-flow/index.mjs +18 -0
- package/dist-flow/meta/cjs.json +2333 -0
- package/dist-flow/meta/esm.json +2343 -0
- package/dist-flow/types/ast.d.ts +881 -0
- package/dist-mcp/ksql-mcp.js +674 -157
- package/dist-mcpb/ksql-mcp.mcpb +0 -0
- package/package.json +12 -3
|
@@ -0,0 +1,881 @@
|
|
|
1
|
+
/** FROM なし SELECT を AST 上で表す予約 cteName。 */
|
|
2
|
+
export declare const NO_FROM_CTE_NAME = "__NO_FROM__";
|
|
3
|
+
export type Statement = SelectStatement | UnionStatement | WithStatement | InsertStatement | InsertSelectStatement | UpsertStatement | UpsertSelectStatement | UpdateStatement | DeleteStatement | ReorderStatement | ValidateStatement | ShowAppsStatement | DescribeStatement | ExplainStatement | CreateTempTableStatement | DropTempTableStatement | SetVariableStatement | DeclareVariableStatement | AssertStatement | ExitStatement | ImportStatement;
|
|
4
|
+
/** SHOW APPS — アプリ一覧 */
|
|
5
|
+
export interface ShowAppsStatement {
|
|
6
|
+
type: "SHOW_APPS";
|
|
7
|
+
}
|
|
8
|
+
/** DESCRIBE APP100 — フィールド定義一覧 */
|
|
9
|
+
export interface DescribeStatement {
|
|
10
|
+
type: "DESCRIBE";
|
|
11
|
+
appId: number;
|
|
12
|
+
}
|
|
13
|
+
/** EXPLAIN SELECT / INSERT / UPDATE / DELETE / UPSERT / REORDER ... — 実行計画表示 */
|
|
14
|
+
export interface ExplainStatement {
|
|
15
|
+
type: "EXPLAIN";
|
|
16
|
+
query: SelectStatement | UnionStatement | WithStatement | InsertStatement | InsertSelectStatement | UpsertStatement | UpsertSelectStatement | UpdateStatement | DeleteStatement | ReorderStatement | ValidateStatement | ImportStatement;
|
|
17
|
+
}
|
|
18
|
+
/** Existing-record constraint audit. This statement never writes to kintone. */
|
|
19
|
+
export type ValidateTarget = {
|
|
20
|
+
kind: "FIELD";
|
|
21
|
+
field: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "SUBTABLE";
|
|
24
|
+
subtableCode: string;
|
|
25
|
+
children: string[];
|
|
26
|
+
};
|
|
27
|
+
export interface ValidateStatement {
|
|
28
|
+
type: "VALIDATE";
|
|
29
|
+
appId: number;
|
|
30
|
+
/** Explicit audit targets. Omitted means constraints plus every NUMBER, including subtable children. */
|
|
31
|
+
targets?: ValidateTarget[];
|
|
32
|
+
/** Aggregate violations by record, subtable, field, and error code. */
|
|
33
|
+
summary?: true;
|
|
34
|
+
where: WhereExpr | null;
|
|
35
|
+
checkGroups?: CheckGroup[];
|
|
36
|
+
/** Batch-scoped materialization destination. */
|
|
37
|
+
errorTable?: string;
|
|
38
|
+
}
|
|
39
|
+
/** CREATE TEMP TABLE #name AS SELECT ... — SELECT 結果をバッチ内一時テーブルとして実体化 */
|
|
40
|
+
export interface CreateTempTableStatement {
|
|
41
|
+
type: "CREATE_TEMP_TABLE";
|
|
42
|
+
name: string;
|
|
43
|
+
query: SelectStatement | UnionStatement | WithStatement;
|
|
44
|
+
}
|
|
45
|
+
/** DROP TEMP TABLE #name — 一時テーブルの明示破棄(バッチ終了時は自動破棄) */
|
|
46
|
+
export interface DropTempTableStatement {
|
|
47
|
+
type: "DROP_TEMP_TABLE";
|
|
48
|
+
name: string;
|
|
49
|
+
}
|
|
50
|
+
export interface SetVariableStatement {
|
|
51
|
+
type: "SET_VARIABLE";
|
|
52
|
+
/** @ を除き、小文字へ正規化した名前 */
|
|
53
|
+
name: string;
|
|
54
|
+
expr: ScalarExpr | ArrayLiteral;
|
|
55
|
+
}
|
|
56
|
+
export interface DeclareVariableStatement {
|
|
57
|
+
type: "DECLARE_VARIABLE";
|
|
58
|
+
/** @ を除き、小文字へ正規化した名前 */
|
|
59
|
+
name: string;
|
|
60
|
+
/** 明示された相対日付トークン型。注釈なし DECLARE では存在しない。 */
|
|
61
|
+
annotation?: "RELATIVE_DATE";
|
|
62
|
+
/** 外部注入が無い場合だけ評価する既定値式 */
|
|
63
|
+
default: Exclude<ScalarExpr, ScalarSubquery> | RelativeDateFunction;
|
|
64
|
+
}
|
|
65
|
+
/** SET RHS 専用。ScalarArithExpr はパーサーがフィールド参照を拒否する。 */
|
|
66
|
+
export type ScalarExpr = StringLiteral | NumberLiteral | VariableRef | LegacyKintoneFunction | StringFuncExpr | ScalarArithExpr | ScalarSubquery;
|
|
67
|
+
export type ScalarArithExpr = LegacyArithExpr;
|
|
68
|
+
/** ASSERT の比較演算子(BETWEEN は AssertStatement.op で表現) */
|
|
69
|
+
export type AssertCompareOp = "=" | "!=" | "<>" | "<" | "<=" | ">" | ">=";
|
|
70
|
+
/**
|
|
71
|
+
* ASSERT のオペランド。
|
|
72
|
+
* リテラル・算術式・スカラーサブクエリのみ(FROM コンテキストが無いため
|
|
73
|
+
* フィールド参照は不可。ArithExpr の葉も NUMBER に限る — パーサで検証)
|
|
74
|
+
*/
|
|
75
|
+
export type AssertOperand = NumberLiteral | StringLiteral | VariableRef | ScalarSubquery | LegacyArithExpr;
|
|
76
|
+
/**
|
|
77
|
+
* ASSERT <式> <比較演算子> <式> / ASSERT <式> BETWEEN <式> AND <式>
|
|
78
|
+
*
|
|
79
|
+
* op が比較演算子のとき right を使い、BETWEEN のとき low / high を使う。
|
|
80
|
+
*/
|
|
81
|
+
export interface AssertStatement {
|
|
82
|
+
type: "ASSERT";
|
|
83
|
+
left: AssertOperand;
|
|
84
|
+
op: AssertCompareOp | "BETWEEN";
|
|
85
|
+
right: AssertOperand | null;
|
|
86
|
+
low: AssertOperand | null;
|
|
87
|
+
high: AssertOperand | null;
|
|
88
|
+
/** 条件部の正規化テキスト(AssertError の "assertion failed: ..." メッセージ用) */
|
|
89
|
+
text: string;
|
|
90
|
+
/** dialect 1: 不成立でも警告として続行する。 */
|
|
91
|
+
warn?: boolean;
|
|
92
|
+
/** dialect 1: 利用者向けのアサーションメッセージ。 */
|
|
93
|
+
message?: string;
|
|
94
|
+
}
|
|
95
|
+
/** dialect 1: 条件成立時にバッチを正常終了する。 */
|
|
96
|
+
export interface ExitStatement {
|
|
97
|
+
type: "EXIT";
|
|
98
|
+
left: AssertOperand;
|
|
99
|
+
op: AssertCompareOp | "BETWEEN";
|
|
100
|
+
right: AssertOperand | null;
|
|
101
|
+
low: AssertOperand | null;
|
|
102
|
+
high: AssertOperand | null;
|
|
103
|
+
/** 条件部の正規化テキスト。 */
|
|
104
|
+
text: string;
|
|
105
|
+
message: string;
|
|
106
|
+
}
|
|
107
|
+
/** WITH name AS (query) の1定義 */
|
|
108
|
+
export interface CteDefinition {
|
|
109
|
+
name: string;
|
|
110
|
+
query: SelectStatement | UnionStatement | ShowAppsStatement | DescribeStatement | GenerateSeriesStatement;
|
|
111
|
+
/** B53: present only for WITH RECURSIVE definitions. Ordinary CTE shapes stay unchanged. */
|
|
112
|
+
columnAliases?: string[];
|
|
113
|
+
recursiveSpec?: RecursiveCteSpec;
|
|
114
|
+
}
|
|
115
|
+
export interface RecursiveCteCycleSpec {
|
|
116
|
+
column: string;
|
|
117
|
+
markColumn: string;
|
|
118
|
+
markValue: string;
|
|
119
|
+
defaultValue: string;
|
|
120
|
+
exposePath: false;
|
|
121
|
+
}
|
|
122
|
+
export interface RecursiveCteSpec {
|
|
123
|
+
seed: SelectStatement;
|
|
124
|
+
recursiveTerm: SelectStatement;
|
|
125
|
+
unionAll: true;
|
|
126
|
+
cycle: RecursiveCteCycleSpec | null;
|
|
127
|
+
}
|
|
128
|
+
export type GenerateSeriesArgument = NumberLiteral | StringLiteral | VariableRef;
|
|
129
|
+
/** WITH name AS (GENERATE_SERIES(...)) — input record を持たない系列 CTE。 */
|
|
130
|
+
export interface GenerateSeriesStatement {
|
|
131
|
+
type: "GENERATE_SERIES";
|
|
132
|
+
args: GenerateSeriesArgument[];
|
|
133
|
+
columnAlias: string;
|
|
134
|
+
}
|
|
135
|
+
export interface WithStatement {
|
|
136
|
+
type: "WITH";
|
|
137
|
+
ctes: CteDefinition[];
|
|
138
|
+
query: SelectStatement | UnionStatement;
|
|
139
|
+
/** B53: omitted for ordinary WITH statements to preserve their public AST shape. */
|
|
140
|
+
recursive?: true;
|
|
141
|
+
}
|
|
142
|
+
export interface UnionStatement {
|
|
143
|
+
type: "UNION";
|
|
144
|
+
all: boolean;
|
|
145
|
+
left: SelectStatement | UnionStatement;
|
|
146
|
+
right: SelectStatement;
|
|
147
|
+
}
|
|
148
|
+
export interface SelectStatement {
|
|
149
|
+
type: "SELECT";
|
|
150
|
+
distinct: boolean;
|
|
151
|
+
columns: SelectColumn[];
|
|
152
|
+
from: TableRef;
|
|
153
|
+
joins: JoinClause[];
|
|
154
|
+
where: WhereExpr | null;
|
|
155
|
+
groupBy: GroupByKey[];
|
|
156
|
+
/** B65 grouping-set syntax only. Absent for ordinary GROUP BY compatibility. */
|
|
157
|
+
grouping?: GroupingSpec;
|
|
158
|
+
having: WhereExpr | null;
|
|
159
|
+
orderMode: "CANONICAL" | "KINTONE_NATIVE";
|
|
160
|
+
orderBy: OrderByItem[];
|
|
161
|
+
limit: number | null;
|
|
162
|
+
offset: number | null;
|
|
163
|
+
}
|
|
164
|
+
/** SELECT 句の各カラム */
|
|
165
|
+
export type SelectColumn = WildcardColumn | ParentWildcardColumn | FieldColumn | LiteralColumn | AggregateColumn | AggArithColumn | ArithColumn | CaseColumn | StringFuncColumn | ScalarValueColumn | GroupingColumn | WindowColumn | ScalarSubqueryColumn | VariableColumn;
|
|
166
|
+
/** SELECT 列別名の SQL 上の表記。照合には引き続き alias の正規形を使う。 */
|
|
167
|
+
export interface SelectAliasDisplay {
|
|
168
|
+
aliasDisplay?: string;
|
|
169
|
+
}
|
|
170
|
+
/** Batch-only SELECT column. Always resolved before execution. */
|
|
171
|
+
export interface VariableColumn extends SelectAliasDisplay {
|
|
172
|
+
type: "VARIABLE_COL";
|
|
173
|
+
name: string;
|
|
174
|
+
/** Ordinary variables require an alias; dialect-1 as-of calls may omit it. */
|
|
175
|
+
alias: string | null;
|
|
176
|
+
}
|
|
177
|
+
export interface WildcardColumn {
|
|
178
|
+
type: "WILDCARD";
|
|
179
|
+
}
|
|
180
|
+
/** 親フィールド一括展開(サブテーブル専用): _p.* */
|
|
181
|
+
export interface ParentWildcardColumn {
|
|
182
|
+
type: "PARENT_WILDCARD";
|
|
183
|
+
}
|
|
184
|
+
export interface FieldColumn extends SelectAliasDisplay {
|
|
185
|
+
type: "FIELD";
|
|
186
|
+
field: Identifier;
|
|
187
|
+
alias: string | null;
|
|
188
|
+
}
|
|
189
|
+
export interface LiteralColumn extends SelectAliasDisplay {
|
|
190
|
+
type: "LITERAL_COL";
|
|
191
|
+
value: string;
|
|
192
|
+
alias: string | null;
|
|
193
|
+
}
|
|
194
|
+
export interface AggregateColumn extends SelectAliasDisplay {
|
|
195
|
+
type: "AGGREGATE";
|
|
196
|
+
func: AggregateFunc;
|
|
197
|
+
distinct: boolean;
|
|
198
|
+
arg: WildcardColumn | AggregateArgExpr;
|
|
199
|
+
separator?: string;
|
|
200
|
+
alias: string | null;
|
|
201
|
+
}
|
|
202
|
+
export type AggregateFunc = "COUNT" | "SUM" | "AVG" | "MAX" | "MIN" | "GROUP_CONCAT" | "STDDEV_POP" | "STDDEV_SAMP" | "VAR_POP" | "VAR_SAMP" | "MEDIAN" | "MODE";
|
|
203
|
+
export type WindowFunc = "ROW_NUMBER" | "RANK" | "DENSE_RANK";
|
|
204
|
+
export type WindowAggFunc = "SUM" | "COUNT" | "AVG" | "MIN" | "MAX";
|
|
205
|
+
export type ValueWindowFunc = "LAG" | "LEAD";
|
|
206
|
+
export type WindowFrameUnit = "ROWS" | "RANGE";
|
|
207
|
+
export interface WindowFrame {
|
|
208
|
+
unit: WindowFrameUnit;
|
|
209
|
+
source: "DEFAULT" | "EXPLICIT";
|
|
210
|
+
}
|
|
211
|
+
/** 順位系ウィンドウ関数。v1 は出力名の衝突を避けるため alias 必須。 */
|
|
212
|
+
export interface RankingWindowColumn extends SelectAliasDisplay {
|
|
213
|
+
type: "WINDOW_COL";
|
|
214
|
+
windowKind?: "RANKING";
|
|
215
|
+
func: WindowFunc;
|
|
216
|
+
partitionBy: FieldRef[];
|
|
217
|
+
orderBy: OrderByItem[];
|
|
218
|
+
alias: string;
|
|
219
|
+
}
|
|
220
|
+
/** B125 Phase 1 の集計ウィンドウ関数。 */
|
|
221
|
+
export interface AggregateWindowColumn extends SelectAliasDisplay {
|
|
222
|
+
type: "WINDOW_COL";
|
|
223
|
+
windowKind: "AGGREGATE";
|
|
224
|
+
aggFunc: WindowAggFunc;
|
|
225
|
+
arg: WildcardColumn | AggregateArgExpr;
|
|
226
|
+
frame: WindowFrame | null;
|
|
227
|
+
partitionBy: FieldRef[];
|
|
228
|
+
orderBy: OrderByItem[];
|
|
229
|
+
alias: string;
|
|
230
|
+
}
|
|
231
|
+
/** B128 Phase 2a の値参照ウィンドウ関数。 */
|
|
232
|
+
export interface ValueWindowColumn extends SelectAliasDisplay {
|
|
233
|
+
type: "WINDOW_COL";
|
|
234
|
+
windowKind: "VALUE";
|
|
235
|
+
valueFunc: ValueWindowFunc;
|
|
236
|
+
arg: ScalarValueExpr;
|
|
237
|
+
offset: number;
|
|
238
|
+
partitionBy: FieldRef[];
|
|
239
|
+
orderBy: OrderByItem[];
|
|
240
|
+
alias: string;
|
|
241
|
+
}
|
|
242
|
+
export type WindowColumn = RankingWindowColumn | AggregateWindowColumn | ValueWindowColumn;
|
|
243
|
+
/** windowKind 未設定の既存 AST も順位系として扱う。 */
|
|
244
|
+
export declare function isRankingWindow(column: WindowColumn): column is RankingWindowColumn;
|
|
245
|
+
export declare function isAggregateWindow(column: WindowColumn): column is AggregateWindowColumn;
|
|
246
|
+
export declare function isValueWindow(column: WindowColumn): column is ValueWindowColumn;
|
|
247
|
+
/** SELECT 句の算術式カラム: field * 1.1 AS alias / 2 * field / (a+b)*c */
|
|
248
|
+
export interface ArithColumn extends SelectAliasDisplay {
|
|
249
|
+
type: "ARITH_COL";
|
|
250
|
+
expr: ArithNode;
|
|
251
|
+
alias: string | null;
|
|
252
|
+
}
|
|
253
|
+
export type StringFuncName = "UPPER" | "LOWER" | "TRIM" | "LTRIM" | "RTRIM" | "LENGTH" | "LENGTH_CHAR" | "SUBSTRING" | "CONCAT" | "REPLACE" | "TRANSLATE" | "COALESCE" | "REGEXP_LIKE" | "REGEXP_REPLACE" | "REGEXP_SUBSTR" | "NULLIF" | "ISNULL" | "LEFT" | "RIGHT" | "INSTR" | "LPAD" | "RPAD" | "GREATEST" | "LEAST" | "ROUND" | "FLOOR" | "CEIL" | "TRUNCATE" | "CAST" | "FORMAT" | "YEAR" | "MONTH" | "DAY" | "DAYOFWEEK" | "QUARTER" | "WEEK" | "DATE_FORMAT" | "DATEDIFF" | "DATE_ADD" | "LAST_DAY" | "ABS" | "MOD" | "POWER" | "SQRT" | "CURRENT_DATE" | "CURRENT_TIMESTAMP";
|
|
254
|
+
/** 文字列関数の引数。集約入り関数の既存構文は AggOperand で保持する。 */
|
|
255
|
+
export type StringFuncArg = ScalarValueExpr | AggOperand;
|
|
256
|
+
export interface StringFuncExpr {
|
|
257
|
+
type: "STRING_FUNC";
|
|
258
|
+
func: StringFuncName;
|
|
259
|
+
args: StringFuncArg[];
|
|
260
|
+
}
|
|
261
|
+
/** SELECT 句の文字列関数カラム */
|
|
262
|
+
export interface StringFuncColumn extends SelectAliasDisplay {
|
|
263
|
+
type: "STRFUNC_COL";
|
|
264
|
+
expr: StringFuncExpr;
|
|
265
|
+
alias: string | null;
|
|
266
|
+
}
|
|
267
|
+
/** SELECT 句の汎用スカラー値式カラム。 */
|
|
268
|
+
export interface ScalarValueColumn extends SelectAliasDisplay {
|
|
269
|
+
type: "SCALAR_VALUE_COL";
|
|
270
|
+
expr: ScalarValueExpr;
|
|
271
|
+
alias: string | null;
|
|
272
|
+
}
|
|
273
|
+
/** B65 aggregate-context discriminator. Kept out of the general scalar union. */
|
|
274
|
+
export interface GroupingRef {
|
|
275
|
+
type: "GROUPING_REF";
|
|
276
|
+
field: FieldRef;
|
|
277
|
+
}
|
|
278
|
+
export interface GroupingColumn extends SelectAliasDisplay {
|
|
279
|
+
type: "GROUPING_COL";
|
|
280
|
+
ref: GroupingRef;
|
|
281
|
+
alias: string | null;
|
|
282
|
+
}
|
|
283
|
+
/** スカラーサブクエリ: (SELECT ...) — 1行1列の値を返す */
|
|
284
|
+
export interface ScalarSubquery {
|
|
285
|
+
type: "SCALAR_SUBQUERY";
|
|
286
|
+
query: SelectStatement;
|
|
287
|
+
}
|
|
288
|
+
/** SELECT 句のスカラーサブクエリカラム: (SELECT ...) [AS alias] */
|
|
289
|
+
export interface ScalarSubqueryColumn extends SelectAliasDisplay {
|
|
290
|
+
type: "SCALAR_SUBQUERY_COL";
|
|
291
|
+
query: SelectStatement;
|
|
292
|
+
alias: string | null;
|
|
293
|
+
}
|
|
294
|
+
/** CASE WHEN の THEN / ELSE 結果値 */
|
|
295
|
+
export type CaseResult = ArrayLiteral | ScalarValueExpr | ArithNode | AggregateRef | AggArithExpr;
|
|
296
|
+
export interface CaseWhenClause {
|
|
297
|
+
condition: WhereExpr;
|
|
298
|
+
result: CaseResult;
|
|
299
|
+
}
|
|
300
|
+
export interface CaseWhenExpr {
|
|
301
|
+
type: "CASE_WHEN";
|
|
302
|
+
branches: CaseWhenClause[];
|
|
303
|
+
elseResult: CaseResult | null;
|
|
304
|
+
}
|
|
305
|
+
/** SELECT 句の CASE WHEN カラム */
|
|
306
|
+
export interface CaseColumn extends SelectAliasDisplay {
|
|
307
|
+
type: "CASE_COL";
|
|
308
|
+
expr: CaseWhenExpr;
|
|
309
|
+
alias: string | null;
|
|
310
|
+
}
|
|
311
|
+
/** FROM または JOIN で参照するテーブル(kintone アプリ または CTE) */
|
|
312
|
+
export interface TableRef {
|
|
313
|
+
appId: number;
|
|
314
|
+
alias: string | null;
|
|
315
|
+
cteName: string | null;
|
|
316
|
+
subtableCode?: string | null;
|
|
317
|
+
}
|
|
318
|
+
export type JoinType = "INNER" | "LEFT" | "RIGHT" | "CROSS";
|
|
319
|
+
export type JoinClause = {
|
|
320
|
+
type: "INNER" | "LEFT" | "RIGHT";
|
|
321
|
+
table: TableRef;
|
|
322
|
+
on: JoinCondition;
|
|
323
|
+
} | {
|
|
324
|
+
type: "CROSS";
|
|
325
|
+
table: TableRef;
|
|
326
|
+
on: null;
|
|
327
|
+
};
|
|
328
|
+
/** ON a.field = b.field 形式のみサポート(Phase 1) */
|
|
329
|
+
export interface JoinCondition {
|
|
330
|
+
left: QualifiedIdentifier;
|
|
331
|
+
right: QualifiedIdentifier;
|
|
332
|
+
}
|
|
333
|
+
/** テーブルエイリアス付き識別子 */
|
|
334
|
+
export interface QualifiedIdentifier {
|
|
335
|
+
tableAlias: string | null;
|
|
336
|
+
field: string;
|
|
337
|
+
}
|
|
338
|
+
export type WhereExpr = BinaryExpr | NullCheckExpr | LogicalExpr | NotExpr | GroupExpr | ExistsExpr | BooleanPredicate;
|
|
339
|
+
/** Internal predicate produced while resolving an empty array variable. */
|
|
340
|
+
export interface BooleanPredicate {
|
|
341
|
+
type: "BOOLEAN";
|
|
342
|
+
value: boolean;
|
|
343
|
+
}
|
|
344
|
+
/** EXISTS (SELECT ...) / NOT EXISTS (SELECT ...) */
|
|
345
|
+
export interface ExistsExpr {
|
|
346
|
+
type: "EXISTS";
|
|
347
|
+
not: boolean;
|
|
348
|
+
query: SelectStatement;
|
|
349
|
+
}
|
|
350
|
+
/** 二項比較 */
|
|
351
|
+
export interface BinaryExpr {
|
|
352
|
+
type: "BINARY";
|
|
353
|
+
op: CompareOp;
|
|
354
|
+
left: FieldValue;
|
|
355
|
+
right: SqlValue;
|
|
356
|
+
}
|
|
357
|
+
export type CompareOp = "=" | "!=" | "<>" | ">" | "<" | ">=" | "<=" | "LIKE" | "NOT_LIKE" | "KLIKE" | "NOT_KLIKE" | "IN" | "NOT_IN";
|
|
358
|
+
/** IS NULL / IS NOT NULL */
|
|
359
|
+
export interface NullCheckExpr {
|
|
360
|
+
type: "NULL_CHECK";
|
|
361
|
+
field: FieldValue;
|
|
362
|
+
not: boolean;
|
|
363
|
+
}
|
|
364
|
+
/** AND / OR */
|
|
365
|
+
export interface LogicalExpr {
|
|
366
|
+
type: "LOGICAL";
|
|
367
|
+
op: "AND" | "OR";
|
|
368
|
+
left: WhereExpr;
|
|
369
|
+
right: WhereExpr;
|
|
370
|
+
}
|
|
371
|
+
/** NOT */
|
|
372
|
+
export interface NotExpr {
|
|
373
|
+
type: "NOT";
|
|
374
|
+
expr: WhereExpr;
|
|
375
|
+
}
|
|
376
|
+
/** 括弧グループ */
|
|
377
|
+
export interface GroupExpr {
|
|
378
|
+
type: "GROUP";
|
|
379
|
+
expr: WhereExpr;
|
|
380
|
+
}
|
|
381
|
+
/** WHERE の左辺 */
|
|
382
|
+
export type FieldValue = FieldRef | AggregateFieldValue | FuncFieldValue | ArithFieldValue | CaseFieldValue | GroupingFieldValue;
|
|
383
|
+
/** 通常のフィールド参照: [alias.]field */
|
|
384
|
+
export interface FieldRef {
|
|
385
|
+
type: "FIELD";
|
|
386
|
+
tableAlias: string | null;
|
|
387
|
+
field: string;
|
|
388
|
+
/** SELECT CASE 条件・HAVING で合成フィールド名へ変換した集計の評価情報。 */
|
|
389
|
+
aggregateRef?: AggregateRef;
|
|
390
|
+
}
|
|
391
|
+
/** HAVING 左辺に直接書かれた集計算術式。 */
|
|
392
|
+
export interface AggregateFieldValue {
|
|
393
|
+
type: "AGG_FIELD";
|
|
394
|
+
expr: AggOperand;
|
|
395
|
+
}
|
|
396
|
+
/** 関数呼び出しを LEFT に持つ WHERE 式: UPPER(f) = '...' / LENGTH(f) > 5 */
|
|
397
|
+
export interface FuncFieldValue {
|
|
398
|
+
type: "FUNC_FIELD";
|
|
399
|
+
expr: StringFuncExpr;
|
|
400
|
+
}
|
|
401
|
+
/** 算術式を LEFT に持つ WHERE 式: 金額 * 1.1 > 10000 / (a + b) * c < 100 */
|
|
402
|
+
export interface ArithFieldValue {
|
|
403
|
+
type: "ARITH_FIELD";
|
|
404
|
+
expr: ArithNode;
|
|
405
|
+
}
|
|
406
|
+
/** CASE WHEN を LEFT に持つ WHERE 式: CASE WHEN ... END = '高額' */
|
|
407
|
+
export interface CaseFieldValue {
|
|
408
|
+
type: "CASE_FIELD";
|
|
409
|
+
expr: CaseWhenExpr;
|
|
410
|
+
}
|
|
411
|
+
export interface GroupingFieldValue {
|
|
412
|
+
type: "GROUPING_FIELD";
|
|
413
|
+
ref: GroupingRef;
|
|
414
|
+
}
|
|
415
|
+
/** WHERE の右辺(リテラル・kintone 関数・算術式・CASE WHEN) */
|
|
416
|
+
export type SqlValue = StringLiteral | NumberLiteral | VariableRef | ArrayLiteral | KintoneFunction | InList | SubqueryInList | ArithSqlValue | CaseSqlValue | ScalarSubquery | VariableInList;
|
|
417
|
+
/** バッチ変数参照。name は @ を除いた小文字。 */
|
|
418
|
+
export interface VariableRef {
|
|
419
|
+
type: "VARIABLE";
|
|
420
|
+
name: string;
|
|
421
|
+
}
|
|
422
|
+
/** Parenthesis-free IN @list batch reference. */
|
|
423
|
+
export interface VariableInList {
|
|
424
|
+
type: "VARIABLE_IN_LIST";
|
|
425
|
+
name: string;
|
|
426
|
+
}
|
|
427
|
+
/** 配列リテラル: ['val1', 'val2'] — INSERT VALUES / UPDATE SET 専用 */
|
|
428
|
+
export interface ArrayLiteral {
|
|
429
|
+
type: "ARRAY";
|
|
430
|
+
elements: StringLiteral[];
|
|
431
|
+
}
|
|
432
|
+
/** 算術式を RIGHT に持つ WHERE 式: WHERE 税込 = 金額 * 1.1 */
|
|
433
|
+
export interface ArithSqlValue {
|
|
434
|
+
type: "ARITH_VALUE";
|
|
435
|
+
expr: ArithNode;
|
|
436
|
+
}
|
|
437
|
+
/** CASE WHEN を RIGHT に持つ式: WHERE 分類 = CASE WHEN ... END */
|
|
438
|
+
/** または UPDATE SET 列 = CASE WHEN ... END */
|
|
439
|
+
export interface CaseSqlValue {
|
|
440
|
+
type: "CASE_VALUE";
|
|
441
|
+
expr: CaseWhenExpr;
|
|
442
|
+
}
|
|
443
|
+
export interface StringLiteral {
|
|
444
|
+
type: "STRING";
|
|
445
|
+
value: string;
|
|
446
|
+
/** バッチ変数から解決された値。整数文字列の受理判定にだけ使用する。 */
|
|
447
|
+
fromVariable?: true;
|
|
448
|
+
}
|
|
449
|
+
export interface NumberLiteral {
|
|
450
|
+
type: "NUMBER";
|
|
451
|
+
value: number;
|
|
452
|
+
/** Original SQL lexeme. Parser-produced nodes always provide this. */
|
|
453
|
+
raw?: string;
|
|
454
|
+
}
|
|
455
|
+
export declare function makeNumberLiteral(raw: string): NumberLiteral;
|
|
456
|
+
export declare function numberLiteralText(node: NumberLiteral): string;
|
|
457
|
+
/** Legacy kintone functions. Keep this runtime shape byte-for-byte stable. */
|
|
458
|
+
export interface LegacyKintoneFunction {
|
|
459
|
+
type: "KINTONE_FUNC";
|
|
460
|
+
name: "TODAY" | "NOW" | "LOGINUSER" | "PRIMARY_ORGANIZATION";
|
|
461
|
+
}
|
|
462
|
+
export type RelativeDatePeriodUnit = "DAYS" | "WEEKS" | "MONTHS" | "YEARS";
|
|
463
|
+
export type RelativeDateWeekday = "SUNDAY" | "MONDAY" | "TUESDAY" | "WEDNESDAY" | "THURSDAY" | "FRIDAY" | "SATURDAY";
|
|
464
|
+
export type RelativeDateMonthDay = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31;
|
|
465
|
+
/** Server-only relative date functions accepted only by the WHERE value parser. */
|
|
466
|
+
export type RelativeDateFunction = {
|
|
467
|
+
type: "KINTONE_FUNC";
|
|
468
|
+
name: "YESTERDAY" | "TOMORROW" | "THIS_YEAR" | "LAST_YEAR" | "NEXT_YEAR";
|
|
469
|
+
args: {
|
|
470
|
+
kind: "NONE";
|
|
471
|
+
};
|
|
472
|
+
} | {
|
|
473
|
+
type: "KINTONE_FUNC";
|
|
474
|
+
name: "FROM_TODAY";
|
|
475
|
+
args: {
|
|
476
|
+
kind: "FROM_TODAY";
|
|
477
|
+
offset: number;
|
|
478
|
+
offsetText: string;
|
|
479
|
+
unit: RelativeDatePeriodUnit;
|
|
480
|
+
};
|
|
481
|
+
} | {
|
|
482
|
+
type: "KINTONE_FUNC";
|
|
483
|
+
name: "THIS_WEEK" | "LAST_WEEK" | "NEXT_WEEK";
|
|
484
|
+
args: {
|
|
485
|
+
kind: "WEEK";
|
|
486
|
+
weekday: RelativeDateWeekday | null;
|
|
487
|
+
};
|
|
488
|
+
} | {
|
|
489
|
+
type: "KINTONE_FUNC";
|
|
490
|
+
name: "THIS_MONTH" | "LAST_MONTH" | "NEXT_MONTH";
|
|
491
|
+
args: {
|
|
492
|
+
kind: "MONTH";
|
|
493
|
+
day: RelativeDateMonthDay | "LAST" | null;
|
|
494
|
+
};
|
|
495
|
+
};
|
|
496
|
+
export type KintoneFunction = LegacyKintoneFunction | RelativeDateFunction;
|
|
497
|
+
/** kintone functions supported as singleton IN-list elements. */
|
|
498
|
+
export type InListFunction = Omit<LegacyKintoneFunction, "name"> & {
|
|
499
|
+
name: "LOGINUSER" | "PRIMARY_ORGANIZATION";
|
|
500
|
+
};
|
|
501
|
+
/** IN (v1, v2, ...) */
|
|
502
|
+
export interface InList {
|
|
503
|
+
type: "IN_LIST";
|
|
504
|
+
values: (StringLiteral | NumberLiteral | VariableRef | InListFunction)[];
|
|
505
|
+
}
|
|
506
|
+
/** IN (SELECT ...) / NOT IN (SELECT ...) */
|
|
507
|
+
export interface SubqueryInList {
|
|
508
|
+
type: "SUBQUERY_IN_LIST";
|
|
509
|
+
query: SelectStatement;
|
|
510
|
+
/** サブクエリの結果から取り出す列名(実行時に解決) */
|
|
511
|
+
column: string | null;
|
|
512
|
+
}
|
|
513
|
+
/** GROUP BY のキー */
|
|
514
|
+
export type GroupByKey = {
|
|
515
|
+
type: "FIELD_NAME";
|
|
516
|
+
name: string;
|
|
517
|
+
} | {
|
|
518
|
+
type: "ARITH_KEY";
|
|
519
|
+
expr: ArithNode;
|
|
520
|
+
} | {
|
|
521
|
+
type: "FUNC_KEY";
|
|
522
|
+
expr: StringFuncExpr;
|
|
523
|
+
};
|
|
524
|
+
/** B65 Phase1 grouping items are physical field references only. */
|
|
525
|
+
export type GroupingFieldItem = FieldRef;
|
|
526
|
+
export interface GroupingSet {
|
|
527
|
+
items: GroupingFieldItem[];
|
|
528
|
+
}
|
|
529
|
+
export interface GroupingSpec {
|
|
530
|
+
type: "GROUPING_SETS";
|
|
531
|
+
source: "GROUPING_SETS" | "ROLLUP" | "CUBE";
|
|
532
|
+
allItems: GroupingFieldItem[];
|
|
533
|
+
sets: GroupingSet[];
|
|
534
|
+
}
|
|
535
|
+
export type NormalizedGroupingSpec = {
|
|
536
|
+
type: "NONE";
|
|
537
|
+
} | {
|
|
538
|
+
type: "PLAIN";
|
|
539
|
+
allItems: GroupByKey[];
|
|
540
|
+
sets: readonly [GroupByKey[]];
|
|
541
|
+
} | {
|
|
542
|
+
type: "GROUPING_SETS";
|
|
543
|
+
source: "GROUPING_SETS" | "ROLLUP" | "CUBE";
|
|
544
|
+
allItems: GroupingFieldItem[];
|
|
545
|
+
sets: GroupingSet[];
|
|
546
|
+
};
|
|
547
|
+
/** ORDER BY のソートキー */
|
|
548
|
+
export type OrderByKey = {
|
|
549
|
+
type: "FIELD_NAME";
|
|
550
|
+
name: string;
|
|
551
|
+
} | {
|
|
552
|
+
type: "ARITH_KEY";
|
|
553
|
+
expr: ArithNode;
|
|
554
|
+
} | {
|
|
555
|
+
type: "FUNC_KEY";
|
|
556
|
+
expr: StringFuncExpr;
|
|
557
|
+
} | {
|
|
558
|
+
type: "GROUPING_KEY";
|
|
559
|
+
ref: GroupingRef;
|
|
560
|
+
};
|
|
561
|
+
export interface OrderByItem {
|
|
562
|
+
key: OrderByKey;
|
|
563
|
+
direction: "ASC" | "DESC";
|
|
564
|
+
}
|
|
565
|
+
export interface InsertStatement {
|
|
566
|
+
type: "INSERT";
|
|
567
|
+
appId: number;
|
|
568
|
+
subtableCode?: string | null;
|
|
569
|
+
fields: string[];
|
|
570
|
+
values: InsertRow[];
|
|
571
|
+
applyBlocks?: ApplyBlock[];
|
|
572
|
+
validateOnly?: boolean;
|
|
573
|
+
validationErrorTable?: string | null;
|
|
574
|
+
onErrorSkip?: boolean;
|
|
575
|
+
errorTable?: string;
|
|
576
|
+
rejectLimit?: number | null;
|
|
577
|
+
checkGroups?: CheckGroup[];
|
|
578
|
+
}
|
|
579
|
+
/** 1 行分の値リスト */
|
|
580
|
+
export type InsertRow = (StringLiteral | NumberLiteral | ArrayLiteral | CaseSqlValue)[];
|
|
581
|
+
/**
|
|
582
|
+
* UPSERT INTO APP100 (フィールド1, ...) VALUES (値1, ...) ON DUPLICATE (キーフィールド)
|
|
583
|
+
*
|
|
584
|
+
* キーフィールドの値が一致するレコードが存在すれば UPDATE、なければ INSERT。
|
|
585
|
+
*/
|
|
586
|
+
export interface UpsertStatement {
|
|
587
|
+
type: "UPSERT";
|
|
588
|
+
appId: number;
|
|
589
|
+
fields: string[];
|
|
590
|
+
values: InsertRow[];
|
|
591
|
+
/** ON DUPLICATE (フィールド名) — 重複判定キー */
|
|
592
|
+
keyFields: string[];
|
|
593
|
+
/** 新規親を作成する分岐のサブテーブル初期行操作。省略時は undefined。 */
|
|
594
|
+
onInsertApplyBlocks?: ApplyBlock[];
|
|
595
|
+
/** 既存親を更新する分岐のサブテーブル操作。省略時は undefined。 */
|
|
596
|
+
onUpdateApplyBlocks?: ApplyBlock[];
|
|
597
|
+
validateOnly?: boolean;
|
|
598
|
+
validationErrorTable?: string | null;
|
|
599
|
+
onErrorSkip?: boolean;
|
|
600
|
+
errorTable?: string;
|
|
601
|
+
rejectLimit?: number | null;
|
|
602
|
+
checkGroups?: CheckGroup[];
|
|
603
|
+
}
|
|
604
|
+
export interface UpsertSelectStatement {
|
|
605
|
+
type: "UPSERT_SELECT";
|
|
606
|
+
appId: number;
|
|
607
|
+
fields: string[];
|
|
608
|
+
select: SelectStatement;
|
|
609
|
+
keyFields: string[];
|
|
610
|
+
validateOnly?: boolean;
|
|
611
|
+
validationErrorTable?: string | null;
|
|
612
|
+
onErrorSkip?: boolean;
|
|
613
|
+
errorTable?: string;
|
|
614
|
+
rejectLimit?: number | null;
|
|
615
|
+
checkGroups?: CheckGroup[];
|
|
616
|
+
}
|
|
617
|
+
export interface InsertSelectStatement {
|
|
618
|
+
type: "INSERT_SELECT";
|
|
619
|
+
appId: number;
|
|
620
|
+
fields: string[];
|
|
621
|
+
select: SelectStatement;
|
|
622
|
+
validateOnly?: boolean;
|
|
623
|
+
validationErrorTable?: string | null;
|
|
624
|
+
onErrorSkip?: boolean;
|
|
625
|
+
errorTable?: string;
|
|
626
|
+
rejectLimit?: number | null;
|
|
627
|
+
checkGroups?: CheckGroup[];
|
|
628
|
+
}
|
|
629
|
+
export type ImportEncoding = "utf8" | "sjis";
|
|
630
|
+
export interface CsvDmlSource {
|
|
631
|
+
kind: "CSV";
|
|
632
|
+
sourceName: string;
|
|
633
|
+
/** Omitted means loader metadata, then UTF-8. */
|
|
634
|
+
encoding?: ImportEncoding;
|
|
635
|
+
hasHeader: boolean;
|
|
636
|
+
/** Header mapping policy. POSITION preserves the Phase 1 contract. */
|
|
637
|
+
mappingMode: "POSITION" | "BY_NAME";
|
|
638
|
+
/** BY_NAME-only opt-in for headers absent from the destination form. */
|
|
639
|
+
ignoreUnknownColumns: boolean;
|
|
640
|
+
/** Valid only with NO HEADER. */
|
|
641
|
+
columns?: string[];
|
|
642
|
+
/** CSV-row projection. It is deliberately FROM-less. */
|
|
643
|
+
projection?: SelectStatement;
|
|
644
|
+
}
|
|
645
|
+
export interface JsonDmlSource {
|
|
646
|
+
kind: "JSON";
|
|
647
|
+
sourceName: string;
|
|
648
|
+
}
|
|
649
|
+
export type ImportTarget = {
|
|
650
|
+
kind: "FIELD";
|
|
651
|
+
field: string;
|
|
652
|
+
} | {
|
|
653
|
+
kind: "SUBTABLE";
|
|
654
|
+
subtableCode: string;
|
|
655
|
+
children: string[];
|
|
656
|
+
/** cli-kintone CSV row-id header. JSON deliberately has no row-id input. */
|
|
657
|
+
rowIdSourceHeader?: string;
|
|
658
|
+
};
|
|
659
|
+
/** SELECT remains here so all three DML source paths share one materializer. */
|
|
660
|
+
export type DmlSource = {
|
|
661
|
+
kind: "SELECT";
|
|
662
|
+
query: SelectStatement;
|
|
663
|
+
} | CsvDmlSource | JsonDmlSource;
|
|
664
|
+
export interface ImportStatement {
|
|
665
|
+
type: "IMPORT";
|
|
666
|
+
appId: number;
|
|
667
|
+
fields: string[];
|
|
668
|
+
/** Present for Phase 5 syntax; fields remains the top-level-only compatibility view. */
|
|
669
|
+
targets?: ImportTarget[];
|
|
670
|
+
source: CsvDmlSource | JsonDmlSource;
|
|
671
|
+
/** Dedicated pure-UPDATE mode; absence preserves INSERT/UPSERT behavior. */
|
|
672
|
+
writeMode?: "UPDATE_RECORD_NUMBER";
|
|
673
|
+
/** Exact, case-sensitive CSV header used only for record-number lookup. */
|
|
674
|
+
recordNumberSourceHeader?: string;
|
|
675
|
+
/** CSV-only destructive replacement allow-list. */
|
|
676
|
+
replaceSubtables?: string[];
|
|
677
|
+
/** Presence selects UPSERT; absence selects INSERT. */
|
|
678
|
+
keyFields?: string[];
|
|
679
|
+
validateOnly?: boolean;
|
|
680
|
+
validationErrorTable?: string | null;
|
|
681
|
+
onErrorSkip?: boolean;
|
|
682
|
+
errorTable?: string;
|
|
683
|
+
rejectLimit?: number | null;
|
|
684
|
+
checkGroups?: CheckGroup[];
|
|
685
|
+
}
|
|
686
|
+
export interface UpdateStatement {
|
|
687
|
+
type: "UPDATE";
|
|
688
|
+
appId: number;
|
|
689
|
+
subtableCode?: string | null;
|
|
690
|
+
assignments: Assignment[];
|
|
691
|
+
where: WhereExpr;
|
|
692
|
+
/** UPDATE ... FROM source。未指定時は従来の UPDATE。 */
|
|
693
|
+
from?: UpdateFromSource | null;
|
|
694
|
+
validateOnly?: boolean;
|
|
695
|
+
validationErrorTable?: string | null;
|
|
696
|
+
onErrorSkip?: boolean;
|
|
697
|
+
errorTable?: string;
|
|
698
|
+
rejectLimit?: number | null;
|
|
699
|
+
checkGroups?: CheckGroup[];
|
|
700
|
+
/** UPDATE ... WHERE に続くサブテーブル変更計画。 */
|
|
701
|
+
applyBlocks?: ApplyBlock[];
|
|
702
|
+
}
|
|
703
|
+
export type ApplyBlock = SubtableApplyBlock | MultiValueApplyBlock;
|
|
704
|
+
/** 行操作を持つ SUBTABLE 用 APPLY block。field 型との整合は metadata 解決時に検証する。 */
|
|
705
|
+
export interface SubtableApplyBlock {
|
|
706
|
+
field: string;
|
|
707
|
+
targetKind: "SUBTABLE";
|
|
708
|
+
operations: SubtableApplyOperation[];
|
|
709
|
+
}
|
|
710
|
+
/** 集合要素操作を持つ複数値 field 用 APPLY block。field 型との整合は metadata 解決時に検証する。 */
|
|
711
|
+
export interface MultiValueApplyBlock {
|
|
712
|
+
field: string;
|
|
713
|
+
targetKind: "MULTI_VALUE";
|
|
714
|
+
operations: MultiValueApplyOperation[];
|
|
715
|
+
}
|
|
716
|
+
export type ApplyOperation = SubtableApplyOperation | MultiValueApplyOperation;
|
|
717
|
+
export type SubtableApplyOperation = PatchOperation | AppendOperation | RemoveOperation;
|
|
718
|
+
export type MultiValueApplyOperation = AddOperation | RemoveValueOperation;
|
|
719
|
+
export interface PatchOperation {
|
|
720
|
+
kind: "PATCH";
|
|
721
|
+
assignments: Assignment[];
|
|
722
|
+
selector: RowSelector;
|
|
723
|
+
expectRows?: ExpectRowsGuard;
|
|
724
|
+
}
|
|
725
|
+
/** v1.1 用の構文ノード。Phase 1 では scope validator が実行を拒否する。 */
|
|
726
|
+
export interface AppendOperation {
|
|
727
|
+
kind: "APPEND";
|
|
728
|
+
fields: string[];
|
|
729
|
+
values: InsertRow[];
|
|
730
|
+
}
|
|
731
|
+
/** v1.2 用の構文ノード。Phase 1 では scope validator が実行を拒否する。 */
|
|
732
|
+
export interface RemoveOperation {
|
|
733
|
+
kind: "REMOVE";
|
|
734
|
+
selector: RowSelector;
|
|
735
|
+
expectRows?: ExpectRowsGuard;
|
|
736
|
+
}
|
|
737
|
+
/** 複数値 field の集合へ文字列値を追加する。実 mutation は Phase 15b で接続する。 */
|
|
738
|
+
export interface AddOperation {
|
|
739
|
+
kind: "ADD";
|
|
740
|
+
value: string;
|
|
741
|
+
}
|
|
742
|
+
/** 複数値 field の集合から文字列値を除去する。行 REMOVE とは別 node。 */
|
|
743
|
+
export interface RemoveValueOperation {
|
|
744
|
+
kind: "REMOVE_VALUE";
|
|
745
|
+
value: string;
|
|
746
|
+
}
|
|
747
|
+
export type RowSelector = {
|
|
748
|
+
kind: "WHERE";
|
|
749
|
+
where: WhereExpr;
|
|
750
|
+
} | {
|
|
751
|
+
kind: "ALL_ROWS";
|
|
752
|
+
};
|
|
753
|
+
export type ExpectRowsGuard = {
|
|
754
|
+
kind: "EXACT";
|
|
755
|
+
count: number;
|
|
756
|
+
} | {
|
|
757
|
+
kind: "BETWEEN";
|
|
758
|
+
min: number;
|
|
759
|
+
max: number;
|
|
760
|
+
} | {
|
|
761
|
+
kind: "AT_LEAST";
|
|
762
|
+
count: number;
|
|
763
|
+
} | {
|
|
764
|
+
kind: "AT_MOST";
|
|
765
|
+
count: number;
|
|
766
|
+
};
|
|
767
|
+
export interface CheckGroup {
|
|
768
|
+
rules: CheckRule[];
|
|
769
|
+
}
|
|
770
|
+
export interface CheckRule {
|
|
771
|
+
condition: WhereExpr;
|
|
772
|
+
message: ScalarValueExpr;
|
|
773
|
+
}
|
|
774
|
+
export interface Assignment {
|
|
775
|
+
field: string;
|
|
776
|
+
value: AssignmentValue;
|
|
777
|
+
}
|
|
778
|
+
/** UPDATE ... FROM のソース(v1 は #temp または実アプリのみ)。 */
|
|
779
|
+
export interface UpdateFromSource {
|
|
780
|
+
/** 実アプリ ID。#temp の場合は 0。 */
|
|
781
|
+
appId: number;
|
|
782
|
+
/** #temp 名。実アプリの場合は null。collectRefs が参照を検出する既存キー名を踏襲。 */
|
|
783
|
+
cteName: string | null;
|
|
784
|
+
alias: string;
|
|
785
|
+
/** 更新先の結合キー。v1 のレコード番号結合は "$id"。 */
|
|
786
|
+
targetJoinField: string;
|
|
787
|
+
joinKeyField: string;
|
|
788
|
+
targetFilter: WhereExpr | null;
|
|
789
|
+
}
|
|
790
|
+
/** UPDATE ... FROM の SET 右辺で参照するソース列。 */
|
|
791
|
+
export interface SourceFieldValue {
|
|
792
|
+
type: "SOURCE_FIELD";
|
|
793
|
+
alias: string;
|
|
794
|
+
field: string;
|
|
795
|
+
}
|
|
796
|
+
/** UPDATE SET 専用。文字列関数は行ごとに現在値を参照して評価する。 */
|
|
797
|
+
export type AssignmentValue = SqlValue | LegacyArithExpr | StringFuncExpr | ConcatExpr | ArithExpr | SourceFieldValue;
|
|
798
|
+
export type ArithOp = "+" | "-" | "*" | "/" | "%";
|
|
799
|
+
/**
|
|
800
|
+
* 算術ノード(再帰型)
|
|
801
|
+
* FIELD_REF: フィールド参照
|
|
802
|
+
* NUMBER: 数値リテラル
|
|
803
|
+
* ARITH: ネストした算術式 例: (金額 + 消費税) * 1.1
|
|
804
|
+
* STRING_FUNC: 関数呼び出し結果を数値として使う 例: ROUND(f)/2, LENGTH(s)*100
|
|
805
|
+
* VARIABLE: バッチ変数参照(実行前に数値リテラルへ解決される)
|
|
806
|
+
*/
|
|
807
|
+
export type ArithNode = {
|
|
808
|
+
type: "FIELD_REF";
|
|
809
|
+
field: string;
|
|
810
|
+
} | NumberLiteral | LegacyArithExpr | StringFuncExpr | VariableRef;
|
|
811
|
+
/** 後方互換エイリアス */
|
|
812
|
+
export type ArithOperand = ArithNode;
|
|
813
|
+
export interface LegacyArithExpr {
|
|
814
|
+
type: "ARITH";
|
|
815
|
+
left: ArithNode;
|
|
816
|
+
op: ArithOp;
|
|
817
|
+
right: ArithNode;
|
|
818
|
+
}
|
|
819
|
+
/** 値レベルのスカラー式。比較・述語・集約・サブクエリは含めない。 */
|
|
820
|
+
export type ScalarValueExpr = StringLiteral | NumberLiteral | FieldRef | VariableRef | StringFuncExpr | ArithExpr | ConcatExpr | CaseWhenExpr;
|
|
821
|
+
/** 集計引数。既存 SQL は ArithNode のまま保持し、新規の値式だけ ScalarValueExpr を使う。 */
|
|
822
|
+
export type AggregateArgExpr = ArithNode | ScalarValueExpr;
|
|
823
|
+
/** ScalarValueExpr 専用の算術式。旧 ArithNode/LegacyArithExpr とは分離する。 */
|
|
824
|
+
export interface ArithExpr {
|
|
825
|
+
type: "SCALAR_ARITH";
|
|
826
|
+
left: ScalarValueExpr;
|
|
827
|
+
op: ArithOp;
|
|
828
|
+
right: ScalarValueExpr;
|
|
829
|
+
}
|
|
830
|
+
export interface ConcatExpr {
|
|
831
|
+
type: "CONCAT_OP";
|
|
832
|
+
left: ScalarValueExpr;
|
|
833
|
+
right: ScalarValueExpr;
|
|
834
|
+
}
|
|
835
|
+
/** 仕様上の CaseExpr 名。既存 CASE AST をそのまま再利用する。 */
|
|
836
|
+
export type CaseExpr = CaseWhenExpr;
|
|
837
|
+
export interface DeleteStatement {
|
|
838
|
+
type: "DELETE";
|
|
839
|
+
appId: number;
|
|
840
|
+
subtableCode?: string | null;
|
|
841
|
+
where: WhereExpr;
|
|
842
|
+
}
|
|
843
|
+
export interface ReorderStatement {
|
|
844
|
+
type: "REORDER";
|
|
845
|
+
appId: number;
|
|
846
|
+
subtableCode: string;
|
|
847
|
+
all: boolean;
|
|
848
|
+
by: OrderByItem[];
|
|
849
|
+
where: WhereExpr | null;
|
|
850
|
+
}
|
|
851
|
+
/** 集計算術式のオペランド */
|
|
852
|
+
export type AggOperand = AggregateRef | NumberLiteral | AggGroupKeyRef | VariableRef | AggArithExpr;
|
|
853
|
+
/** ordinary GROUP BY キーとして表記一致を検証済みのフィールド参照。 */
|
|
854
|
+
export interface AggGroupKeyRef {
|
|
855
|
+
type: "AGG_GROUP_KEY";
|
|
856
|
+
field: string;
|
|
857
|
+
tableAlias?: string;
|
|
858
|
+
}
|
|
859
|
+
/** 集計関数への参照(算術式の被演算子として使う) */
|
|
860
|
+
export interface AggregateRef {
|
|
861
|
+
type: "AGG_REF";
|
|
862
|
+
func: AggregateFunc;
|
|
863
|
+
distinct: boolean;
|
|
864
|
+
arg: WildcardColumn | AggregateArgExpr;
|
|
865
|
+
separator?: string;
|
|
866
|
+
}
|
|
867
|
+
/** 集計結果を含む算術式(再帰型) */
|
|
868
|
+
export interface AggArithExpr {
|
|
869
|
+
type: "AGG_ARITH";
|
|
870
|
+
left: AggOperand;
|
|
871
|
+
op: ArithOp;
|
|
872
|
+
right: AggOperand;
|
|
873
|
+
}
|
|
874
|
+
/** SELECT 句の集計算術式カラム: SUM(金額) * 1.1 [AS alias] */
|
|
875
|
+
export interface AggArithColumn extends SelectAliasDisplay {
|
|
876
|
+
type: "ARITH_AGG_COL";
|
|
877
|
+
expr: AggOperand;
|
|
878
|
+
alias: string | null;
|
|
879
|
+
}
|
|
880
|
+
/** クォートなし識別子(日本語含む) */
|
|
881
|
+
export type Identifier = string;
|