@memberjunction/sql-parser 5.14.0 → 5.15.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mj-placeholder.js","sourceRoot":"","sources":["../src/mj-placeholder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AASxC;;GAEG;AACH,MAAM,OAAO,yBAAyB;IAAtC;QACY,kBAAa,GAAG,CAAC,CAAC;QAClB,kBAAa,GAAG,CAAC,CAAC;QAClB,sBAAiB,GAAG,CAAC,CAAC;QACtB,kBAAa,GAAG,CAAC,CAAC;QAClB,uBAAkB,GAAG,CAAC,CAAC;QACvB,mBAAc,GAAG,CAAC,CAAC;IAoJ/B,CAAC;IAlJG;;;;;;OAMG;IACI,MAAM,CAAC,UAAU,CAAC,GAAW;QAChC,MAAM,QAAQ,GAAG,IAAI,yBAAyB,EAAE,CAAC;QACjD,OAAO,QAAQ,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC;IAEO,kBAAkB,CAAC,GAAW;QAClC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,WAAW,GAAG,IAAI,GAAG,EAA4B,CAAC;QACxD,MAAM,cAAc,GAAc,EAAE,CAAC;QAErC,oDAAoD;QACpD,IAAI,QAAQ,GAAG,EAAE,CAAC;QAElB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACzB,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;gBACjB,KAAK,UAAU;oBACX,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAC;oBACtB,MAAM;gBAEV,KAAK,kBAAkB,CAAC,CAAC,CAAC;oBACtB,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,2BAA2B,CAAC,KAA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AO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC3B,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,wDAAwD;IACxD,yBAAyB;IACzB,wDAAwD;IAEhD,qBAAqB;QACzB,OAAO,UAAU,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC;IACxE,CAAC;IAEO,qBAAqB;QACzB,OAAO,MAAM,CAAC,KAAK,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAChD,CAAC;IAEO,yBAAyB;QAC7B,OAAO,SAAS,MAAM,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC;IAC1E,CAAC;IAEO,qBAAqB;QACzB,OAAO,YAAY,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;IAC3E,CAAC;IAEO,sBAAsB;QAC1B,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,OAAO,GAAG,CAAC;IACf,CAAC;IAEO,0BAA0B;QAC9B,OAAO,SAAS,MAAM,CAAC,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC;IAC3E,CAAC;CACJ"}
@@ -1,6 +1,37 @@
1
1
  /**
2
- * A single table/view reference extracted from SQL.
2
+ * SQLParser — Unified parser for MemberJunction's SQL superset
3
+ *
4
+ * Parses SQL that may contain Nunjucks templates ({{ }}, {% %}), composition
5
+ * tokens ({{query:"..."}}), and standard SQL into a structured AST.
6
+ *
7
+ * Three-pass pipeline:
8
+ * 1. MJLexer tokenizes MJ extensions with position tracking
9
+ * 2. MJPlaceholderSubstitution replaces tokens with SQL-safe placeholders
10
+ * 3. node-sql-parser produces the standard SQL AST
11
+ *
12
+ * The result contains both the SQL AST and the MJ token structure,
13
+ * enabling SQL-level analysis and faithful MJ SQL reconstruction.
3
14
  */
15
+ import NodeSqlParser from 'node-sql-parser';
16
+ import { MJToken, MJTemplateExpr, MJCompositionRef, MJConditionalBlock, MJFilter, PlaceholderEntry, PlaceholderSubstitutionResult, MJParseResult, MJASTWalkResult } from './mj-ast-types.js';
17
+ /** Result of Astify — the full parsed representation of MJ SQL */
18
+ export interface MJAstifyResult {
19
+ /** The node-sql-parser AST of the placeholder-substituted SQL (null if parsing failed) */
20
+ ast: NodeSqlParser.AST | NodeSqlParser.AST[] | null;
21
+ /** MJ token analysis with boolean flags */
22
+ mjParse: MJParseResult;
23
+ /** Map from placeholder string → original MJ token */
24
+ positionMap: Map<string, PlaceholderEntry>;
25
+ /** Tokens that were stripped (block tags, comments) */
26
+ strippedTokens: MJToken[];
27
+ /** The clean SQL that was parsed (for debugging) */
28
+ cleanSQL: string;
29
+ /** Whether AST parsing succeeded */
30
+ astParsed: boolean;
31
+ /** The SQL dialect used */
32
+ dialect: string;
33
+ }
34
+ /** A table/view reference extracted from SQL */
4
35
  export interface SQLTableReference {
5
36
  /** The table or view name as it appears in SQL */
6
37
  TableName: string;
@@ -9,17 +40,34 @@ export interface SQLTableReference {
9
40
  /** The alias used in the query, or the table name if no alias */
10
41
  Alias: string;
11
42
  }
12
- /**
13
- * A column reference extracted from SQL expressions.
14
- */
43
+ /** A column reference extracted from SQL */
15
44
  export interface SQLColumnReference {
16
45
  /** Column name */
17
46
  ColumnName: string;
18
- /** Table alias or name prefix, if qualified (e.g. "t" in "t.Name") */
47
+ /** Table alias or name prefix (e.g., "t" in "t.Name"), or null if unqualified */
19
48
  TableQualifier: string | null;
20
49
  }
50
+ /** Result of extracting CTE definitions from a WITH clause */
51
+ export interface SQLCTEExtraction {
52
+ /** Individual CTE definitions as "name AS (...)" strings, in declaration order */
53
+ CTEDefinitions: string[];
54
+ /** The main statement after all CTE definitions */
55
+ MainStatement: string;
56
+ /** Whether AST parsing was used (true) or regex fallback (false) */
57
+ UsedASTParsing: boolean;
58
+ }
59
+ /** Deterministic parameter info extracted from template expressions */
60
+ export interface MJParameterInfo {
61
+ name: string;
62
+ type: 'string' | 'number' | 'date' | 'boolean' | 'array' | 'unknown';
63
+ isRequired: boolean;
64
+ defaultValue: string | number | null;
65
+ filters: MJFilter[];
66
+ usageLocations: string[];
67
+ }
21
68
  /**
22
- * Complete result of parsing a SQL statement for table and column references.
69
+ * Combined result of parsing SQL for table and column references.
70
+ * This is the original SQLParser.Parse() return type, preserved for backward compatibility.
23
71
  */
24
72
  export interface SQLParseResult {
25
73
  /** All table/view references found (FROM, JOIN, subqueries, CTEs) */
@@ -29,71 +77,212 @@ export interface SQLParseResult {
29
77
  /** Whether parsing succeeded via AST (true) or fell back to regex (false) */
30
78
  UsedASTParsing: boolean;
31
79
  }
80
+ /** Options for Parse() and ParseWithTemplatePreprocessing() methods */
81
+ export interface SQLParseOptions {
82
+ /** The SQL string to parse */
83
+ sql: string;
84
+ /** SQL dialect (default: 'TransactSQL') */
85
+ dialect?: string;
86
+ }
32
87
  /**
33
- * Reusable SQL parsing utility that extracts table/view references and column references
34
- * from SQL statements using node-sql-parser with a regex fallback.
88
+ * Unified parser for MemberJunction's SQL superset.
35
89
  *
36
- * This class has no dependency on MJ Metadata — it returns raw parse results.
37
- * Callers are responsible for cross-referencing against entity metadata.
90
+ * Handles standard SQL, Nunjucks template expressions (`{{ var | filter }}`),
91
+ * Nunjucks block tags (`{% if %}...{% endif %}`), composition tokens
92
+ * (`{{query:"Path/Name(params)"}}`), and template comments (`{# ... #}`).
93
+ *
94
+ * All methods are static — no instance state is needed.
38
95
  */
39
96
  export declare class SQLParser {
40
97
  /**
41
- * Parse a plain SQL statement and extract all table and column references.
42
- * Uses AST parsing with the specified dialect, falls back to regex on failure.
43
- * @param sql The SQL statement to parse
44
- * @param dialect The SQL dialect to use for AST parsing (default: 'TransactSQL')
98
+ * Parse MJ SQL into an extended AST.
99
+ *
100
+ * Pipeline:
101
+ * 1. MJLexer tokenizes MJ extensions
102
+ * 2. MJPlaceholder replaces tokens with SQL-safe placeholders
103
+ * 3. node-sql-parser produces the SQL AST
104
+ *
105
+ * @param sql The MJ SQL string to parse
106
+ * @param dialect SQL dialect ('TransactSQL' | 'PostgresQL', default: 'TransactSQL')
107
+ */
108
+ static Astify(sql: string, dialect?: string): MJAstifyResult;
109
+ /**
110
+ * Reconstruct MJ SQL from an Astify result.
111
+ *
112
+ * For plain SQL: uses node-sql-parser's sqlify for normalized output.
113
+ * For MJ SQL: reconstructs from tokens, preserving all Nunjucks and composition syntax verbatim.
114
+ */
115
+ static Sqlify(result: MJAstifyResult): string;
116
+ /**
117
+ * Parse plain SQL into a node-sql-parser AST.
118
+ * Handles FOR XML multi-directive workaround automatically.
119
+ * Returns null if parsing fails.
120
+ */
121
+ static ParseSQL(sql: string, dialect?: string): NodeSqlParser.AST | NodeSqlParser.AST[] | null;
122
+ /**
123
+ * Convert a node-sql-parser AST (or array of ASTs) back to a SQL string.
124
+ * This is a thin wrapper around node-sql-parser's sqlify.
125
+ */
126
+ static SqlifyAST(ast: NodeSqlParser.AST | NodeSqlParser.AST[], dialect?: string): string;
127
+ /**
128
+ * Convert a single AST expression node to a SQL string.
129
+ * Useful for extracting ORDER BY terms, column expressions, etc.
130
+ *
131
+ * node-sql-parser's exprToSQL always produces backtick-quoted identifiers
132
+ * regardless of dialect. This method converts to the appropriate quoting:
133
+ * - TransactSQL: backticks → square brackets
134
+ * - PostgresQL: backticks → double quotes
135
+ */
136
+ static ExprToSQL(expr: unknown, dialect?: string): string;
137
+ /**
138
+ * Tokenize MJ SQL into an ordered list of tokens.
139
+ * Returns MJ tokens (template expressions, composition refs, block tags, comments)
140
+ * interleaved with SQL_TEXT tokens for the plain SQL segments.
141
+ */
142
+ static Tokenize(sql: string): MJToken[];
143
+ /**
144
+ * Tokenize and return a summary with boolean flags.
145
+ * Useful for quick checks like "does this SQL have MJ extensions?"
146
+ */
147
+ static Analyze(sql: string): MJParseResult;
148
+ /**
149
+ * Replace MJ tokens with SQL-safe placeholders.
150
+ *
151
+ * Context-aware: `sqlString` → string literal, `sqlNumber` → numeric literal,
152
+ * `sqlIdentifier` → bare identifier. Block tags and comments are stripped.
153
+ * Returns a position map for reversing the substitution.
154
+ */
155
+ static Substitute(sql: string): PlaceholderSubstitutionResult;
156
+ /**
157
+ * Parse SQL and extract table + column references.
158
+ * This is the original SQLParser.Parse() method signature.
159
+ * Automatically handles MJ Nunjucks templates via placeholder substitution.
160
+ *
161
+ * @param options Parse options, or just a SQL string for backward compatibility
162
+ */
163
+ static Parse(options: SQLParseOptions | string, dialect?: string): SQLParseResult;
164
+ /**
165
+ * Parse SQL with MJ Nunjucks template preprocessing.
166
+ * This is the original SQLParser.ParseWithTemplatePreprocessing() signature.
167
+ * Now equivalent to Parse() since all methods handle templates automatically.
168
+ *
169
+ * @param options Parse options, or just a SQL string for backward compatibility
170
+ */
171
+ static ParseWithTemplatePreprocessing(options: SQLParseOptions | string, dialect?: string): SQLParseResult;
172
+ /**
173
+ * Extract all table/view references from SQL.
174
+ * Handles Nunjucks templates via placeholder substitution before AST parsing.
175
+ */
176
+ static ExtractTableRefs(sql: string, dialect?: string): SQLTableReference[];
177
+ /**
178
+ * Extract all column references from SQL.
179
+ * Handles Nunjucks templates via placeholder substitution before AST parsing.
180
+ */
181
+ static ExtractColumnRefs(sql: string, dialect?: string): SQLColumnReference[];
182
+ /**
183
+ * Extract CTE definitions from SQL starting with a WITH clause.
184
+ *
185
+ * Given: `WITH A AS (SELECT 1), B AS (SELECT 2) SELECT A.x, B.y FROM A, B`
186
+ * Returns: CTEDefinitions: ["A AS (...)", "B AS (...)"], MainStatement: "SELECT ..."
187
+ *
188
+ * Uses AST parsing first (produces bracket-quoted identifiers for SQL Server),
189
+ * falls back to paren-depth scanning if AST fails (e.g., Nunjucks-templated SQL).
190
+ */
191
+ static ExtractCTEs(sql: string, dialect?: string): SQLCTEExtraction | null;
192
+ /**
193
+ * Extract all {{ variable | filter }} expressions from SQL.
194
+ * Returns structured info for each expression including variable name and filter chain.
45
195
  */
46
- static Parse(sql: string, dialect?: string): SQLParseResult;
196
+ static ExtractTemplateExpressions(sql: string): MJTemplateExpr[];
47
197
  /**
48
- * Parse a SQL statement that may contain Nunjucks template syntax.
49
- * Pre-processes templates into valid SQL before parsing.
50
- * @param sql The SQL statement to parse
51
- * @param dialect The SQL dialect to use for AST parsing (default: 'TransactSQL')
198
+ * Extract all {{query:"..."}} composition references from SQL.
199
+ * Returns structured info including category path, query name, and parsed parameters.
52
200
  */
53
- static ParseWithTemplatePreprocessing(sql: string, dialect?: string): SQLParseResult;
201
+ static ExtractCompositionRefs(sql: string): MJCompositionRef[];
54
202
  /**
55
- * Attempt to parse SQL via node-sql-parser AST.
56
- * Returns null if parsing fails (caller should fall back to regex).
203
+ * Extract conditional blocks, pairing if/elif/else/endif into structured trees.
57
204
  */
58
- private static ParseViaAST;
205
+ static ExtractConditionalBlocks(sql: string): MJConditionalBlock[];
59
206
  /**
60
- * Regex-based fallback for extracting table references from SQL.
61
- * Less accurate than AST but handles edge cases where the parser fails.
207
+ * Extract parameter metadata from template expressions.
208
+ * Infers type from filters, isRequired from conditional block context.
62
209
  */
63
- private static ParseViaRegex;
210
+ static ExtractParameterInfo(sql: string): MJParameterInfo[];
64
211
  /**
65
- * Converts internal maps into the public SQLParseResult shape.
212
+ * Walk the AST from an Astify result and annotate where MJ placeholders appear.
213
+ *
214
+ * Returns an MJASTWalkResult with annotations mapping each placeholder to its
215
+ * SQL clause context (SELECT, WHERE, ORDER BY, etc.) and the resolved MJ node.
216
+ *
217
+ * This enables queries like:
218
+ * - "Which template expressions appear in the WHERE clause?"
219
+ * - "What composition ref is in the FROM clause?"
220
+ * - "Does the ORDER BY reference an MJ token?"
221
+ *
222
+ * @param result The MJAstifyResult from Astify()
223
+ * @returns Walk result with annotations, or empty result if AST parsing failed
66
224
  */
67
- private static BuildResult;
225
+ static WalkAST(result: MJAstifyResult): MJASTWalkResult;
68
226
  /**
69
- * Deduplicates table references by schema.table key, keeping distinct entries.
227
+ * Recursively walks an AST node, checking values against the placeholder map.
70
228
  */
71
- private static DeduplicateTables;
229
+ private static walkASTNode;
72
230
  /**
73
- * Converts raw column reference strings into structured SQLColumnReference objects.
231
+ * Walks any AST value (node, array, or primitive) checking for placeholder matches.
74
232
  */
75
- private static ParseColumnRefs;
233
+ private static walkASTValue;
76
234
  /**
77
- * Recursively extracts table references and column references from SQL AST.
235
+ * Checks if a value matches a placeholder and creates an annotation if so.
78
236
  */
79
- private static ExtractFromAST;
237
+ private static checkPlaceholder;
80
238
  /**
81
- * Extracts table information from a FROM clause item, handling tables and JOINs.
239
+ * Builds the MJASTWalkResult from a flat list of annotations.
82
240
  */
83
- private static ExtractTableFromItem;
241
+ private static buildWalkResult;
84
242
  /**
85
- * Extracts column references from an expression node.
86
- * Also extracts tables from subqueries found in expressions (e.g., EXISTS, IN).
243
+ * Parse SQL safely, returning null on failure.
244
+ *
245
+ * Includes a workaround for node-sql-parser's inability to handle multi-directive
246
+ * FOR XML clauses (e.g., `FOR XML PATH('M'), ROOT('R')`). The parser handles
247
+ * `FOR XML PATH('M')` fine but chokes on the comma-separated directives.
248
+ * We strip the extra directives before parsing and restore them on the AST's `for` property.
87
249
  */
88
- private static ExtractColumnReferences;
250
+ /** Resolves overloaded Parse() args: (string, dialect?) or (options) */
251
+ private static resolveParseArgs;
252
+ private static parseSQL;
89
253
  /**
90
- * Pre-processes Nunjucks templates in SQL to create valid SQL for parsing.
91
- * Replaces Nunjucks syntax with placeholder values.
254
+ * Detects FOR XML clauses that node-sql-parser can't handle and simplifies them.
255
+ *
256
+ * node-sql-parser handles: FOR XML PATH, FOR XML PATH('arg'), FOR XML RAW, FOR XML AUTO
257
+ * node-sql-parser fails on: FOR XML RAW('arg'), and any comma-separated directives
258
+ *
259
+ * Simplifies to a form the parser accepts, preserving the original for restoration.
260
+ * Returns null if no problematic FOR XML pattern is found.
92
261
  */
93
- private static PreProcessNunjucksForParsing;
262
+ private static stripForXmlDirectives;
94
263
  /**
95
- * Regex fallback for Nunjucks preprocessing when rendering fails.
264
+ * Restores the original FOR XML clause text on the AST's `for` property.
265
+ * This ensures that when the AST is inspected (e.g., for isOrderByLegalInCTE checks),
266
+ * the FOR XML presence is correctly detected.
96
267
  */
97
- private static PreProcessNunjucksViaRegex;
268
+ private static restoreForXmlOnAST;
269
+ /** Get clean SQL (MJ tokens replaced with placeholders) for AST parsing */
270
+ private static getCleanSQL;
271
+ private static extractTablesViaAST;
272
+ private static extractTablesViaRegex;
273
+ private static deduplicateTables;
274
+ private static buildColumnRefs;
275
+ private static extractCTEsViaAST;
276
+ private static extractCTEsViaRegex;
277
+ private static skipWhitespace;
278
+ private static findMatchingCloseParen;
279
+ private static walkAST;
280
+ private static walkFromItem;
281
+ private static walkExpression;
282
+ private static inferTypeFromFilters;
283
+ private static extractDefaultValue;
284
+ private static findConditionalVariables;
285
+ private static addConditionVariables;
286
+ private static addNodeToFragment;
98
287
  }
99
288
  //# sourceMappingURL=sql-parser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sql-parser.d.ts","sourceRoot":"","sources":["../src/sql-parser.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,kBAAkB;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,qEAAqE;IACrE,MAAM,EAAE,iBAAiB,EAAE,CAAC;IAC5B,+EAA+E;IAC/E,OAAO,EAAE,kBAAkB,E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