@memberjunction/sql-parser 6.2.0-edge.6 → 6.2.0-edge.7

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.
Files changed (286) hide show
  1. package/README.md +392 -0
  2. package/dist/aggregateExpression.d.ts +5 -1
  3. package/dist/aggregateExpression.d.ts.map +1 -1
  4. package/dist/aggregateExpression.js +7 -420
  5. package/dist/aggregateExpression.js.map +1 -1
  6. package/dist/common/analysis.d.ts +48 -0
  7. package/dist/common/analysis.d.ts.map +1 -0
  8. package/dist/common/analysis.js +17 -0
  9. package/dist/common/analysis.js.map +1 -0
  10. package/dist/common/diagnosticCodes.d.ts +96 -0
  11. package/dist/common/diagnosticCodes.d.ts.map +1 -0
  12. package/dist/common/diagnosticCodes.js +99 -0
  13. package/dist/common/diagnosticCodes.js.map +1 -0
  14. package/dist/edit/clauseTransforms.d.ts +40 -0
  15. package/dist/edit/clauseTransforms.d.ts.map +1 -0
  16. package/dist/edit/clauseTransforms.js +161 -0
  17. package/dist/edit/clauseTransforms.js.map +1 -0
  18. package/dist/edit/cteTransforms.d.ts +68 -0
  19. package/dist/edit/cteTransforms.d.ts.map +1 -0
  20. package/dist/edit/cteTransforms.js +127 -0
  21. package/dist/edit/cteTransforms.js.map +1 -0
  22. package/dist/edit/editSet.d.ts +83 -0
  23. package/dist/edit/editSet.d.ts.map +1 -0
  24. package/dist/edit/editSet.js +185 -0
  25. package/dist/edit/editSet.js.map +1 -0
  26. package/dist/edit/transformSupport.d.ts +53 -0
  27. package/dist/edit/transformSupport.d.ts.map +1 -0
  28. package/dist/edit/transformSupport.js +67 -0
  29. package/dist/edit/transformSupport.js.map +1 -0
  30. package/dist/index.d.ts +49 -3
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +24 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/legacy/cteParenScan.d.ts +13 -0
  35. package/dist/legacy/cteParenScan.d.ts.map +1 -0
  36. package/dist/legacy/cteParenScan.js +120 -0
  37. package/dist/legacy/cteParenScan.js.map +1 -0
  38. package/dist/legacy/dialectResolution.d.ts +22 -0
  39. package/dist/legacy/dialectResolution.d.ts.map +1 -0
  40. package/dist/legacy/dialectResolution.js +55 -0
  41. package/dist/legacy/dialectResolution.js.map +1 -0
  42. package/dist/legacy/frozenCTEExtraction.d.ts +10 -0
  43. package/dist/legacy/frozenCTEExtraction.d.ts.map +1 -0
  44. package/dist/legacy/frozenCTEExtraction.js +38 -0
  45. package/dist/legacy/frozenCTEExtraction.js.map +1 -0
  46. package/dist/legacy/legacyExtractors.d.ts +54 -0
  47. package/dist/legacy/legacyExtractors.d.ts.map +1 -0
  48. package/dist/legacy/legacyExtractors.js +245 -0
  49. package/dist/legacy/legacyExtractors.js.map +1 -0
  50. package/dist/legacy/legacyTagContent.d.ts +29 -0
  51. package/dist/legacy/legacyTagContent.d.ts.map +1 -0
  52. package/dist/legacy/legacyTagContent.js +283 -0
  53. package/dist/legacy/legacyTagContent.js.map +1 -0
  54. package/dist/legacy/legacyTemplateExtractors.d.ts +31 -0
  55. package/dist/legacy/legacyTemplateExtractors.d.ts.map +1 -0
  56. package/dist/legacy/legacyTemplateExtractors.js +201 -0
  57. package/dist/legacy/legacyTemplateExtractors.js.map +1 -0
  58. package/dist/legacy/legacyTemplateTokens.d.ts +16 -0
  59. package/dist/legacy/legacyTemplateTokens.d.ts.map +1 -0
  60. package/dist/legacy/legacyTemplateTokens.js +80 -0
  61. package/dist/legacy/legacyTemplateTokens.js.map +1 -0
  62. package/dist/legacy/nodeSqlParserCore.d.ts +34 -0
  63. package/dist/legacy/nodeSqlParserCore.d.ts.map +1 -0
  64. package/dist/legacy/nodeSqlParserCore.js +251 -0
  65. package/dist/legacy/nodeSqlParserCore.js.map +1 -0
  66. package/dist/legacy/nodeSqlRowCap.d.ts +46 -0
  67. package/dist/legacy/nodeSqlRowCap.d.ts.map +1 -0
  68. package/dist/legacy/nodeSqlRowCap.js +72 -0
  69. package/dist/legacy/nodeSqlRowCap.js.map +1 -0
  70. package/dist/legacy/nonQueryReads.d.ts +28 -0
  71. package/dist/legacy/nonQueryReads.d.ts.map +1 -0
  72. package/dist/legacy/nonQueryReads.js +112 -0
  73. package/dist/legacy/nonQueryReads.js.map +1 -0
  74. package/dist/legacy/templateSqlViews.d.ts +32 -0
  75. package/dist/legacy/templateSqlViews.d.ts.map +1 -0
  76. package/dist/legacy/templateSqlViews.js +176 -0
  77. package/dist/legacy/templateSqlViews.js.map +1 -0
  78. package/dist/lexer/sqlTokenTypes.d.ts +67 -0
  79. package/dist/lexer/sqlTokenTypes.d.ts.map +1 -0
  80. package/dist/lexer/sqlTokenTypes.js +2 -0
  81. package/dist/lexer/sqlTokenTypes.js.map +1 -0
  82. package/dist/lexer/sqlTokens.d.ts +53 -0
  83. package/dist/lexer/sqlTokens.d.ts.map +1 -0
  84. package/dist/lexer/sqlTokens.js +267 -0
  85. package/dist/lexer/sqlTokens.js.map +1 -0
  86. package/dist/lexer/templateTagScanner.d.ts +32 -0
  87. package/dist/lexer/templateTagScanner.d.ts.map +1 -0
  88. package/dist/lexer/templateTagScanner.js +69 -0
  89. package/dist/lexer/templateTagScanner.js.map +1 -0
  90. package/dist/orderByAnalyzer.d.ts +5 -0
  91. package/dist/orderByAnalyzer.d.ts.map +1 -1
  92. package/dist/orderByAnalyzer.js +5 -0
  93. package/dist/orderByAnalyzer.js.map +1 -1
  94. package/dist/pagingShape.d.ts +4 -1
  95. package/dist/pagingShape.d.ts.map +1 -1
  96. package/dist/pagingShape.js +4 -1
  97. package/dist/pagingShape.js.map +1 -1
  98. package/dist/sql/analyses/analysisTypes.d.ts +124 -0
  99. package/dist/sql/analyses/analysisTypes.d.ts.map +1 -0
  100. package/dist/sql/analyses/analysisTypes.js +2 -0
  101. package/dist/sql/analyses/analysisTypes.js.map +1 -0
  102. package/dist/sql/analyses/columnAnalyses.d.ts +18 -0
  103. package/dist/sql/analyses/columnAnalyses.d.ts.map +1 -0
  104. package/dist/sql/analyses/columnAnalyses.js +138 -0
  105. package/dist/sql/analyses/columnAnalyses.js.map +1 -0
  106. package/dist/sql/analyses/structureAnalyses.d.ts +31 -0
  107. package/dist/sql/analyses/structureAnalyses.d.ts.map +1 -0
  108. package/dist/sql/analyses/structureAnalyses.js +201 -0
  109. package/dist/sql/analyses/structureAnalyses.js.map +1 -0
  110. package/dist/sql/parser/fromParser.d.ts +45 -0
  111. package/dist/sql/parser/fromParser.d.ts.map +1 -0
  112. package/dist/sql/parser/fromParser.js +342 -0
  113. package/dist/sql/parser/fromParser.js.map +1 -0
  114. package/dist/sql/parser/parseContext.d.ts +72 -0
  115. package/dist/sql/parser/parseContext.d.ts.map +1 -0
  116. package/dist/sql/parser/parseContext.js +197 -0
  117. package/dist/sql/parser/parseContext.js.map +1 -0
  118. package/dist/sql/parser/queryParser.d.ts +45 -0
  119. package/dist/sql/parser/queryParser.d.ts.map +1 -0
  120. package/dist/sql/parser/queryParser.js +267 -0
  121. package/dist/sql/parser/queryParser.js.map +1 -0
  122. package/dist/sql/parser/selectParser.d.ts +47 -0
  123. package/dist/sql/parser/selectParser.d.ts.map +1 -0
  124. package/dist/sql/parser/selectParser.js +353 -0
  125. package/dist/sql/parser/selectParser.js.map +1 -0
  126. package/dist/sql/parser/tailParser.d.ts +25 -0
  127. package/dist/sql/parser/tailParser.d.ts.map +1 -0
  128. package/dist/sql/parser/tailParser.js +180 -0
  129. package/dist/sql/parser/tailParser.js.map +1 -0
  130. package/dist/sql/sqlDiagnosticCodes.d.ts +27 -0
  131. package/dist/sql/sqlDiagnosticCodes.d.ts.map +1 -0
  132. package/dist/sql/sqlDiagnosticCodes.js +25 -0
  133. package/dist/sql/sqlDiagnosticCodes.js.map +1 -0
  134. package/dist/sql/sqlDocument.d.ts +103 -0
  135. package/dist/sql/sqlDocument.d.ts.map +1 -0
  136. package/dist/sql/sqlDocument.js +178 -0
  137. package/dist/sql/sqlDocument.js.map +1 -0
  138. package/dist/sql/sqlExpression.d.ts +74 -0
  139. package/dist/sql/sqlExpression.d.ts.map +1 -0
  140. package/dist/sql/sqlExpression.js +313 -0
  141. package/dist/sql/sqlExpression.js.map +1 -0
  142. package/dist/sql/sqlKeywords.d.ts +38 -0
  143. package/dist/sql/sqlKeywords.d.ts.map +1 -0
  144. package/dist/sql/sqlKeywords.js +85 -0
  145. package/dist/sql/sqlKeywords.js.map +1 -0
  146. package/dist/sql/sqlNodes.d.ts +360 -0
  147. package/dist/sql/sqlNodes.d.ts.map +1 -0
  148. package/dist/sql/sqlNodes.js +2 -0
  149. package/dist/sql/sqlNodes.js.map +1 -0
  150. package/dist/sql/sqlScope.d.ts +108 -0
  151. package/dist/sql/sqlScope.d.ts.map +1 -0
  152. package/dist/sql/sqlScope.js +307 -0
  153. package/dist/sql/sqlScope.js.map +1 -0
  154. package/dist/sql/sqlWalker.d.ts +17 -0
  155. package/dist/sql/sqlWalker.d.ts.map +1 -0
  156. package/dist/sql/sqlWalker.js +113 -0
  157. package/dist/sql/sqlWalker.js.map +1 -0
  158. package/dist/sql/tokenTable.d.ts +58 -0
  159. package/dist/sql/tokenTable.d.ts.map +1 -0
  160. package/dist/sql/tokenTable.js +158 -0
  161. package/dist/sql/tokenTable.js.map +1 -0
  162. package/dist/sql-parser.d.ts +146 -194
  163. package/dist/sql-parser.d.ts.map +1 -1
  164. package/dist/sql-parser.js +173 -1272
  165. package/dist/sql-parser.js.map +1 -1
  166. package/dist/sqlLexer.d.ts +18 -13
  167. package/dist/sqlLexer.d.ts.map +1 -1
  168. package/dist/sqlLexer.js +152 -50
  169. package/dist/sqlLexer.js.map +1 -1
  170. package/dist/sqlShape.d.ts +11 -2
  171. package/dist/sqlShape.d.ts.map +1 -1
  172. package/dist/sqlShape.js +64 -8
  173. package/dist/sqlShape.js.map +1 -1
  174. package/dist/strict/aggregateRenderer.d.ts +28 -0
  175. package/dist/strict/aggregateRenderer.d.ts.map +1 -0
  176. package/dist/strict/aggregateRenderer.js +451 -0
  177. package/dist/strict/aggregateRenderer.js.map +1 -0
  178. package/dist/strict/statementReads.d.ts +34 -0
  179. package/dist/strict/statementReads.d.ts.map +1 -0
  180. package/dist/strict/statementReads.js +252 -0
  181. package/dist/strict/statementReads.js.map +1 -0
  182. package/dist/strict/strictDialect.d.ts +12 -0
  183. package/dist/strict/strictDialect.d.ts.map +1 -0
  184. package/dist/strict/strictDialect.js +37 -0
  185. package/dist/strict/strictDialect.js.map +1 -0
  186. package/dist/strict/strictFragmentValidator.d.ts +68 -0
  187. package/dist/strict/strictFragmentValidator.d.ts.map +1 -0
  188. package/dist/strict/strictFragmentValidator.js +156 -0
  189. package/dist/strict/strictFragmentValidator.js.map +1 -0
  190. package/dist/strict/strictTypes.d.ts +116 -0
  191. package/dist/strict/strictTypes.d.ts.map +1 -0
  192. package/dist/strict/strictTypes.js +2 -0
  193. package/dist/strict/strictTypes.js.map +1 -0
  194. package/dist/strict/treeFacts.d.ts +28 -0
  195. package/dist/strict/treeFacts.d.ts.map +1 -0
  196. package/dist/strict/treeFacts.js +162 -0
  197. package/dist/strict/treeFacts.js.map +1 -0
  198. package/dist/structuralParser.d.ts +2 -0
  199. package/dist/structuralParser.d.ts.map +1 -1
  200. package/dist/structuralParser.js +6 -4
  201. package/dist/structuralParser.js.map +1 -1
  202. package/dist/template/branchEvaluator.d.ts +51 -0
  203. package/dist/template/branchEvaluator.d.ts.map +1 -0
  204. package/dist/template/branchEvaluator.js +194 -0
  205. package/dist/template/branchEvaluator.js.map +1 -0
  206. package/dist/template/branchVariants.d.ts +79 -0
  207. package/dist/template/branchVariants.d.ts.map +1 -0
  208. package/dist/template/branchVariants.js +273 -0
  209. package/dist/template/branchVariants.js.map +1 -0
  210. package/dist/template/compositionParser.d.ts +18 -0
  211. package/dist/template/compositionParser.d.ts.map +1 -0
  212. package/dist/template/compositionParser.js +131 -0
  213. package/dist/template/compositionParser.js.map +1 -0
  214. package/dist/template/compositionPathMatch.d.ts +46 -0
  215. package/dist/template/compositionPathMatch.d.ts.map +1 -0
  216. package/dist/template/compositionPathMatch.js +50 -0
  217. package/dist/template/compositionPathMatch.js.map +1 -0
  218. package/dist/template/compositionReferences.d.ts +26 -0
  219. package/dist/template/compositionReferences.d.ts.map +1 -0
  220. package/dist/template/compositionReferences.js +21 -0
  221. package/dist/template/compositionReferences.js.map +1 -0
  222. package/dist/template/compositionRules.d.ts +42 -0
  223. package/dist/template/compositionRules.d.ts.map +1 -0
  224. package/dist/template/compositionRules.js +132 -0
  225. package/dist/template/compositionRules.js.map +1 -0
  226. package/dist/template/docComments.d.ts +45 -0
  227. package/dist/template/docComments.d.ts.map +1 -0
  228. package/dist/template/docComments.js +115 -0
  229. package/dist/template/docComments.js.map +1 -0
  230. package/dist/template/expressionLexer.d.ts +28 -0
  231. package/dist/template/expressionLexer.d.ts.map +1 -0
  232. package/dist/template/expressionLexer.js +85 -0
  233. package/dist/template/expressionLexer.js.map +1 -0
  234. package/dist/template/expressionParser.d.ts +106 -0
  235. package/dist/template/expressionParser.d.ts.map +1 -0
  236. package/dist/template/expressionParser.js +419 -0
  237. package/dist/template/expressionParser.js.map +1 -0
  238. package/dist/template/expressionTypes.d.ts +111 -0
  239. package/dist/template/expressionTypes.d.ts.map +1 -0
  240. package/dist/template/expressionTypes.js +25 -0
  241. package/dist/template/expressionTypes.js.map +1 -0
  242. package/dist/template/parameterAnalysis.d.ts +81 -0
  243. package/dist/template/parameterAnalysis.d.ts.map +1 -0
  244. package/dist/template/parameterAnalysis.js +130 -0
  245. package/dist/template/parameterAnalysis.js.map +1 -0
  246. package/dist/template/queryLanguage.d.ts +33 -0
  247. package/dist/template/queryLanguage.d.ts.map +1 -0
  248. package/dist/template/queryLanguage.js +56 -0
  249. package/dist/template/queryLanguage.js.map +1 -0
  250. package/dist/template/queryTemplate.d.ts +72 -0
  251. package/dist/template/queryTemplate.d.ts.map +1 -0
  252. package/dist/template/queryTemplate.js +147 -0
  253. package/dist/template/queryTemplate.js.map +1 -0
  254. package/dist/template/sqlPosition.d.ts +24 -0
  255. package/dist/template/sqlPosition.d.ts.map +1 -0
  256. package/dist/template/sqlPosition.js +93 -0
  257. package/dist/template/sqlPosition.js.map +1 -0
  258. package/dist/template/templateNodes.d.ts +114 -0
  259. package/dist/template/templateNodes.d.ts.map +1 -0
  260. package/dist/template/templateNodes.js +38 -0
  261. package/dist/template/templateNodes.js.map +1 -0
  262. package/dist/template/templateTreeBuilder.d.ts +56 -0
  263. package/dist/template/templateTreeBuilder.d.ts.map +1 -0
  264. package/dist/template/templateTreeBuilder.js +302 -0
  265. package/dist/template/templateTreeBuilder.js.map +1 -0
  266. package/dist/template/templateWalker.d.ts +62 -0
  267. package/dist/template/templateWalker.d.ts.map +1 -0
  268. package/dist/template/templateWalker.js +122 -0
  269. package/dist/template/templateWalker.js.map +1 -0
  270. package/dist/template/trailingDocComments.d.ts +35 -0
  271. package/dist/template/trailingDocComments.d.ts.map +1 -0
  272. package/dist/template/trailingDocComments.js +146 -0
  273. package/dist/template/trailingDocComments.js.map +1 -0
  274. package/dist/template/validationTypes.d.ts +77 -0
  275. package/dist/template/validationTypes.d.ts.map +1 -0
  276. package/dist/template/validationTypes.js +2 -0
  277. package/dist/template/validationTypes.js.map +1 -0
  278. package/dist/template/valueRules.d.ts +55 -0
  279. package/dist/template/valueRules.d.ts.map +1 -0
  280. package/dist/template/valueRules.js +238 -0
  281. package/dist/template/valueRules.js.map +1 -0
  282. package/package.json +2 -2
  283. package/dist/ASTDialectAdapter.d.ts +0 -60
  284. package/dist/ASTDialectAdapter.d.ts.map +0 -1
  285. package/dist/ASTDialectAdapter.js +0 -117
  286. package/dist/ASTDialectAdapter.js.map +0 -1
@@ -0,0 +1,131 @@
1
+ import { MakeDiagnostic } from '../common/analysis.js';
2
+ import { MJQueryDiagnosticCodes } from '../common/diagnosticCodes.js';
3
+ import { TemplateExpressionParser } from './expressionParser.js';
4
+ import { WalkExpression } from './expressionTypes.js';
5
+ const COMPOSITION_PREFIX = /^\s*query\s*:/;
6
+ const ARGUMENTS_LOOK = /^\s*[A-Za-z_]\w*\s*=/;
7
+ const MALFORMED_HINT = 'Write {{query:"Category/Path/Name(Arg=Value, …)"}}, with the path in double quotes.';
8
+ /** Whether a `{{ }}` body is a composition token (`query:"…"`). */
9
+ export function IsCompositionBody(body) {
10
+ return COMPOSITION_PREFIX.test(body);
11
+ }
12
+ /**
13
+ * Parses a composition token, `{{query:"Category/Path/Name(Arg=Value, …)"}}`. The path is the
14
+ * text in double quotes. A trailing parenthesised list is the argument list when it is empty or
15
+ * starts with `Name=`; otherwise the parentheses are part of the query name, so a name like
16
+ * `Year-End (2024) Summary` still reads. Argument values use the MJ Query expression grammar.
17
+ */
18
+ export function ParseComposition(token, source) {
19
+ const tag = token.Template;
20
+ if (tag === null)
21
+ return malformed(token.Span, 'This token is not a template tag.');
22
+ const prefix = COMPOSITION_PREFIX.exec(tag.Body);
23
+ const open = prefix ? tag.Body.indexOf('"', prefix[0].length) : -1;
24
+ if (prefix === null || open < 0 || tag.Body.substring(prefix[0].length, open).trim() !== '') {
25
+ return malformed(token.Span, 'A composition token must give the query path in double quotes.');
26
+ }
27
+ const close = tag.Body.indexOf('"', open + 1);
28
+ if (close < 0 || tag.Body.substring(close + 1).trim() !== '') {
29
+ return malformed(token.Span, 'The query path needs a closing double quote, and nothing may follow it.');
30
+ }
31
+ const contentStart = tag.BodySpan.Start + open + 1;
32
+ return parsePathAndArguments(token, source, contentStart, tag.BodySpan.Start + close);
33
+ }
34
+ function parsePathAndArguments(token, source, start, end) {
35
+ const argumentsOpen = findArgumentListOpen(source, start, end);
36
+ const pathEnd = argumentsOpen ?? end;
37
+ const segments = source.substring(start, pathEnd).split('/').map(s => s.trim());
38
+ if (segments.some(s => s.length === 0)) {
39
+ return malformed(token.Span, 'The query path has an empty segment.');
40
+ }
41
+ const parsed = argumentsOpen === null
42
+ ? { Arguments: [], Diagnostics: [] }
43
+ : TemplateExpressionParser.ParseArguments(source, argumentsOpen + 1, lastCloseParen(source, start, end));
44
+ const diagnostics = parsed.Diagnostics.map(d => (d.Code === MJQueryDiagnosticCodes.Syntax
45
+ ? MakeDiagnostic(MJQueryDiagnosticCodes.CompositionMalformed, 'Error', d.Span, d.Message, MALFORMED_HINT)
46
+ : d));
47
+ const node = {
48
+ Kind: 'Composition', Span: token.Span, Token: token,
49
+ FullPath: segments.join('/'), CategoryPath: segments.slice(0, -1).join('/'), Name: segments[segments.length - 1],
50
+ PathSpan: trimmedSpan(source, start, pathEnd),
51
+ Arguments: parsed.Arguments.map(toArgument),
52
+ SqlContext: token.Template?.SqlContext ?? 'Code',
53
+ };
54
+ return { Node: node, Diagnostics: diagnostics };
55
+ }
56
+ /**
57
+ * The offset of the `(` that opens the argument list, or `null` when the path has none. The
58
+ * list is the parenthesised group that ends the path, read outside single-quoted strings.
59
+ */
60
+ function findArgumentListOpen(source, start, end) {
61
+ const closeAt = lastCloseParen(source, start, end);
62
+ if (closeAt < 0)
63
+ return null;
64
+ const opens = [];
65
+ let groupOpen = null;
66
+ for (let i = start; i <= closeAt; i++) {
67
+ const c = source[i];
68
+ if (c === "'")
69
+ i = skipQuoted(source, i, closeAt);
70
+ else if (c === '(')
71
+ opens.push(i);
72
+ else if (c === ')')
73
+ groupOpen = opens.pop() ?? null;
74
+ }
75
+ if (groupOpen === null)
76
+ return null;
77
+ const inner = source.substring(groupOpen + 1, closeAt);
78
+ return inner.trim() === '' || ARGUMENTS_LOOK.test(inner) ? groupOpen : null;
79
+ }
80
+ /** The offset of the final `)` when the path's last non-space character is one; -1 otherwise. */
81
+ function lastCloseParen(source, start, end) {
82
+ let i = end - 1;
83
+ while (i >= start && /\s/.test(source[i]))
84
+ i--;
85
+ return i >= start && source[i] === ')' ? i : -1;
86
+ }
87
+ /** The offset of the closing quote of a single-quoted string opening at `i`, with backslash escapes. */
88
+ function skipQuoted(source, i, limit) {
89
+ let j = i + 1;
90
+ while (j < limit && source[j] !== "'")
91
+ j += source[j] === '\\' ? 2 : 1;
92
+ return j;
93
+ }
94
+ function trimmedSpan(source, start, end) {
95
+ let s = start;
96
+ let e = end;
97
+ while (s < e && /\s/.test(source[s]))
98
+ s++;
99
+ while (e > s && /\s/.test(source[e - 1]))
100
+ e--;
101
+ return { Start: s, End: e };
102
+ }
103
+ function toArgument(argument) {
104
+ const names = referencedNames(argument.Expression);
105
+ return {
106
+ Name: argument.Name, NameSpan: argument.NameSpan, Expression: argument.Expression, Span: argument.Span,
107
+ IsStatic: names.length === 0 && !readsAnyValue(argument.Expression), ReferencedNames: names,
108
+ };
109
+ }
110
+ /** The parameter names an expression reads, in order of first use. */
111
+ function referencedNames(expression) {
112
+ const names = [];
113
+ WalkExpression(expression, node => {
114
+ if (node.Kind === 'Name' && !names.includes(node.Name))
115
+ names.push(node.Name);
116
+ });
117
+ return names;
118
+ }
119
+ /** Whether an expression reads a `Context` token or loop value. */
120
+ function readsAnyValue(expression) {
121
+ let reads = false;
122
+ WalkExpression(expression, node => {
123
+ if (node.Kind === 'Context' || node.Kind === 'LoopMember')
124
+ reads = true;
125
+ });
126
+ return reads;
127
+ }
128
+ function malformed(span, message) {
129
+ return { Node: null, Diagnostics: [MakeDiagnostic(MJQueryDiagnosticCodes.CompositionMalformed, 'Error', span, message, MALFORMED_HINT)] };
130
+ }
131
+ //# sourceMappingURL=compositionParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compositionParser.js","sourceRoot":"","sources":["../../src/template/compositionParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAUtD,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAC3C,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAC9C,MAAM,cAAc,GAAG,qFAAqF,CAAC;AAE7G,mEAAmE;AACnE,MAAM,UAAU,iBAA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,EAAE,IAAI,CAAC,EAAE;QAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY;YAAE,KAAK,GAAG,IAAI,CAAC;IAC5E,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,SAAS,CAAC,IAAU,EAAE,OAAe;IAC1C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,cAAc,CAAC,sBAAsB,CAAC,oBAAoB,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;AAC9I,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * How a composition reference (`{{query:"Category/Path/Name"}}`) finds its query: by the full
3
+ * category path and name, or by a path that is a whole-segment suffix of exactly one query's full
4
+ * category path (`Demos/Active Users` finds `MJ/Demos/Active Users`). A partial path still runs,
5
+ * with a warning; save refuses it. There is no name-only fallback: a reference with no category
6
+ * path finds only a query with no category.
7
+ */
8
+ /** A query a reference can name: its name and category path (`/Sales/Reports/`, `Sales/Reports`). */
9
+ export interface CompositionPathCandidate {
10
+ readonly Name: string;
11
+ readonly CategoryPath?: string | null;
12
+ }
13
+ /** What {@link MatchCompositionPath} found. */
14
+ export type CompositionPathMatch<T extends CompositionPathCandidate> =
15
+ /** Exactly one query has this full category path and name. */
16
+ {
17
+ readonly Kind: 'Exact';
18
+ readonly Target: T;
19
+ }
20
+ /** The path is a whole-segment suffix of exactly one query's category path; `FullPath` is that query's full path. */
21
+ | {
22
+ readonly Kind: 'PartialPath';
23
+ readonly Target: T;
24
+ readonly FullPath: string;
25
+ }
26
+ /** More than one query matches, exactly (`Exact` true) or by suffix. */
27
+ | {
28
+ readonly Kind: 'Ambiguous';
29
+ readonly Exact: boolean;
30
+ readonly Count: number;
31
+ } | {
32
+ readonly Kind: 'NotFound';
33
+ };
34
+ /** The segments of a category path: trimmed, empty ones dropped (`/Sales/ Reports/` → `Sales`, `Reports`). */
35
+ export declare function CompositionPathSegments(path: string | readonly string[] | null | undefined): string[];
36
+ /** A category path in comparable form: its segments joined by `/`, lower case. */
37
+ export declare function NormalizeCompositionCategoryPath(path: string | readonly string[] | null | undefined): string;
38
+ /** A query's full path as a reference writes it: its category segments and name joined by `/`. */
39
+ export declare function CompositionFullPath(candidate: CompositionPathCandidate): string;
40
+ /**
41
+ * Finds the query a reference names among `candidates`.
42
+ * @param categoryPath - The reference's category path, as text or segments; empty for a query with no category.
43
+ * @param name - The reference's query name. Names and segments compare ignoring case and surrounding spaces.
44
+ */
45
+ export declare function MatchCompositionPath<T extends CompositionPathCandidate>(categoryPath: string | readonly string[] | null | undefined, name: string, candidates: readonly T[]): CompositionPathMatch<T>;
46
+ //# sourceMappingURL=compositionPathMatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compositionPathMatch.d.ts","sourceRoot":"","sources":["../../src/template/compositionPathMatch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qGAAqG;AACrG,MAAM,WAAW,wBAAwB;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzC;AAED,+CAA+C;AAC/C,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,wBAAwB;AAC/D,8DAA8D;AAC5D;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE;AAChD,qHAAqH;GACnH;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AACjF,wEAAwE;GACtE;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/E;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAEpC,8GAA8G;AAC9G,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,EAAE,CAGrG;AAED,kFAAkF;AAClF,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAE5G;AAED,kGAAkG;AAClG,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,wBAAwB,GAAG,MAAM,CAE/E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,wBAAwB,EACnE,YAAY,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,EAC3D,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,SAAS,CAAC,EAAE,GACzB,oBAAoB,CAAC,CAAC,CAAC,CAWzB"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * How a composition reference (`{{query:"Category/Path/Name"}}`) finds its query: by the full
3
+ * category path and name, or by a path that is a whole-segment suffix of exactly one query's full
4
+ * category path (`Demos/Active Users` finds `MJ/Demos/Active Users`). A partial path still runs,
5
+ * with a warning; save refuses it. There is no name-only fallback: a reference with no category
6
+ * path finds only a query with no category.
7
+ */
8
+ /** The segments of a category path: trimmed, empty ones dropped (`/Sales/ Reports/` → `Sales`, `Reports`). */
9
+ export function CompositionPathSegments(path) {
10
+ const parts = typeof path === 'string' ? path.split('/') : [...(path ?? [])];
11
+ return parts.map(s => s.trim()).filter(s => s.length > 0);
12
+ }
13
+ /** A category path in comparable form: its segments joined by `/`, lower case. */
14
+ export function NormalizeCompositionCategoryPath(path) {
15
+ return CompositionPathSegments(path).join('/').toLowerCase();
16
+ }
17
+ /** A query's full path as a reference writes it: its category segments and name joined by `/`. */
18
+ export function CompositionFullPath(candidate) {
19
+ return [...CompositionPathSegments(candidate.CategoryPath), candidate.Name].join('/');
20
+ }
21
+ /**
22
+ * Finds the query a reference names among `candidates`.
23
+ * @param categoryPath - The reference's category path, as text or segments; empty for a query with no category.
24
+ * @param name - The reference's query name. Names and segments compare ignoring case and surrounding spaces.
25
+ */
26
+ export function MatchCompositionPath(categoryPath, name, candidates) {
27
+ const wanted = CompositionPathSegments(categoryPath).map(s => s.toLowerCase());
28
+ const named = candidates.filter(c => c.Name.trim().toLowerCase() === name.trim().toLowerCase());
29
+ const exact = named.filter(c => NormalizeCompositionCategoryPath(c.CategoryPath) === wanted.join('/'));
30
+ if (exact.length === 1)
31
+ return { Kind: 'Exact', Target: exact[0] };
32
+ if (exact.length > 1)
33
+ return { Kind: 'Ambiguous', Exact: true, Count: exact.length };
34
+ if (wanted.length === 0)
35
+ return { Kind: 'NotFound' };
36
+ const bySuffix = named.filter(c => isSegmentSuffix(wanted, CompositionPathSegments(c.CategoryPath).map(s => s.toLowerCase())));
37
+ if (bySuffix.length === 1)
38
+ return { Kind: 'PartialPath', Target: bySuffix[0], FullPath: CompositionFullPath(bySuffix[0]) };
39
+ if (bySuffix.length > 1)
40
+ return { Kind: 'Ambiguous', Exact: false, Count: bySuffix.length };
41
+ return { Kind: 'NotFound' };
42
+ }
43
+ /** Whether `suffix` is the last segments of `path`, and shorter than it. */
44
+ function isSegmentSuffix(suffix, path) {
45
+ if (suffix.length >= path.length)
46
+ return false;
47
+ const offset = path.length - suffix.length;
48
+ return suffix.every((segment, i) => segment === path[offset + i]);
49
+ }
50
+ //# sourceMappingURL=compositionPathMatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compositionPathMatch.js","sourceRoot":"","sources":["../../src/template/compositionPathMatch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkBH,8GAA8G;AAC9G,MAAM,UAAU,uBAAuB,CAAC,IAAmD;IACv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MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { Analysis, Span } from '../common/analysis.js';
2
+ import type { SqlTokens } from '../lexer/sqlTokens.js';
3
+ import type { SqlToken } from '../lexer/sqlTokenTypes.js';
4
+ import type { CompositionArgument, CompositionNode, TemplateNode } from './templateNodes.js';
5
+ /** One `{{query:"…"}}` composition, with where it sits in the SQL. */
6
+ export interface CompositionReference {
7
+ /** The category path and query name joined by `/`, such as `Sales/Reports/Top Customers`. */
8
+ readonly FullPath: string;
9
+ /** The category path, or `''` for a query with no category. */
10
+ readonly CategoryPath: string;
11
+ readonly Name: string;
12
+ readonly Span: Span;
13
+ readonly PathSpan: Span;
14
+ /** The arguments as written: each name with its expression, and whether the value is static or reads outer values. */
15
+ readonly Arguments: readonly CompositionArgument[];
16
+ /** The nearest SQL token before the composition, skipping whitespace, comments and block tags; `null` at the start. */
17
+ readonly PrecedingToken: SqlToken | null;
18
+ /** Whether the composition stands where a table source goes (after FROM, JOIN, APPLY, or a comma in a FROM list). */
19
+ readonly InTablePosition: boolean;
20
+ /** Whether it sits inside an `{% if %}` block. */
21
+ readonly InsideConditional: boolean;
22
+ readonly Node: CompositionNode;
23
+ }
24
+ /** Lists the compositions of a template in source order. */
25
+ export declare function FindCompositionReferences(nodes: readonly TemplateNode[], tokens: SqlTokens, complete: boolean): Analysis<readonly CompositionReference[]>;
26
+ //# sourceMappingURL=compositionReferences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compositionReferences.d.ts","sourceRoot":"","sources":["../../src/template/compositionReferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG7F,sEAAsE;AACtE,MAAM,WAAW,oBAAoB;IACjC,6FAA6F;IAC7F,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,sHAAsH;IACtH,QAAQ,CAAC,SAAS,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACnD,uHAAuH;IACvH,QAAQ,CAAC,cAAc,EAAE,QAAQ,GAAG,IAAI,CAAC;IACzC,qHAAqH;IACrH,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,kDAAkD;IAClD,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;CAClC;AAED,4DAA4D;AAC5D,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC,SAAS,oBAAoB,EAAE,CAAC,CAezJ"}
@@ -0,0 +1,21 @@
1
+ import { IsTableSourcePosition, PrecedingSignificantIndex } from './sqlPosition.js';
2
+ import { WalkTemplate } from './templateWalker.js';
3
+ /** Lists the compositions of a template in source order. */
4
+ export function FindCompositionReferences(nodes, tokens, complete) {
5
+ const references = [];
6
+ WalkTemplate(nodes, {
7
+ Node: (node, scope) => {
8
+ if (node.Kind !== 'Composition')
9
+ return;
10
+ const index = tokens.IndexAt(node.Span.Start);
11
+ const before = index < 0 ? -1 : PrecedingSignificantIndex(tokens, index);
12
+ references.push({
13
+ FullPath: node.FullPath, CategoryPath: node.CategoryPath, Name: node.Name, Span: node.Span, PathSpan: node.PathSpan,
14
+ Arguments: node.Arguments, PrecedingToken: before < 0 ? null : tokens.Tokens[before],
15
+ InTablePosition: index >= 0 && IsTableSourcePosition(tokens, index), InsideConditional: scope.Conditional, Node: node,
16
+ });
17
+ },
18
+ });
19
+ return { Value: references, Complete: complete, Diagnostics: [] };
20
+ }
21
+ //# sourceMappingURL=compositionReferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compositionReferences.js","sourceRoot":"","sources":["../../src/template/compositionReferences.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAEpF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAsBnD,4DAA4D;AAC5D,MAAM,UAAU,yBAAyB,CAAC,KAA8B,EAAE,MAAiB,EAAE,QAAiB;IAC1G,MAAM,UAAU,GAA2B,EAAE,CAAC;IAC9C,YAAY,CAAC,KAAK,EAAE;QAChB,IAAI,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAClB,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa;gBAAE,OAAO;YACxC,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC9C,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,yBAAyB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACzE,UAAU,CAAC,IAAI,CAAC;gBACZ,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACnH,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;gBACpF,eAAe,EAAE,KAAK,IAAI,CAAC,IAAI,qBAAqB,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,iBAAiB,EAAE,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI;aACxH,CAAC,CAAC;QACP,CAAC;KACJ,CAAC,CAAC;IACH,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;AACtE,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { Diagnostic } from '../common/analysis.js';
2
+ import type { CompositionReference } from './compositionReferences.js';
3
+ import type { QueryTemplateValidateOptions } from './validationTypes.js';
4
+ /** What {@link CompositionRules.Check} found. */
5
+ export interface CompositionCheck {
6
+ readonly Diagnostics: readonly Diagnostic[];
7
+ /** Whether every composition's target was checked. */
8
+ readonly Complete: boolean;
9
+ }
10
+ /**
11
+ * The save-time rules for compositions: the table-source position, argument names, and (with a
12
+ * resolver) the target's existence, reusability, parameters and cycles. Arguments are explicit,
13
+ * like a function call: an inner parameter that is not passed has no value.
14
+ */
15
+ export declare class CompositionRules {
16
+ private readonly options;
17
+ private readonly diagnostics;
18
+ private readonly outerNames;
19
+ private readonly resolved;
20
+ private constructor();
21
+ /**
22
+ * Applies the composition rules.
23
+ * @param outerNames - The outer query's parameter names (from the template and its declarations).
24
+ */
25
+ static Check(references: readonly CompositionReference[], options: QueryTemplateValidateOptions, outerNames: readonly string[]): CompositionCheck;
26
+ private checkReference;
27
+ /**
28
+ * A reference that found its query by part of the category path: an error at save, so new SQL
29
+ * names the full path, and a warning on refresh, so a stored query keeps running.
30
+ */
31
+ private checkPartialPath;
32
+ private checkDuplicateArguments;
33
+ private checkArguments;
34
+ private missing;
35
+ private implicit;
36
+ /** Follows compositions from the target; reaching the query being validated, or a query twice on one path, is a cycle. */
37
+ private checkCycle;
38
+ private findCycle;
39
+ private resolve;
40
+ private add;
41
+ }
42
+ //# sourceMappingURL=compositionRules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compositionRules.d.ts","sourceRoot":"","sources":["../../src/template/compositionRules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAA4B,MAAM,uBAAuB,CAAC;AAElF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAEvE,OAAO,KAAK,EAA0C,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAEjH,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC9B;AAED;;;;GAIG;AACH,qBAAa,gBAAgB;IAKL,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA+C;IAExE,OAAO;IAIP;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,SAAS,oBAAoB,EAAE,EAAE,OAAO,EAAE,4BAA4B,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB;IAWjJ,OAAO,CAAC,cAAc;IAwBtB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,uBAAuB;IAW/B,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,QAAQ;IAOhB,0HAA0H;IAC1H,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,OAAO;IASf,OAAO,CAAC,GAAG;CAGd"}
@@ -0,0 +1,132 @@
1
+ import { MakeDiagnostic } from '../common/analysis.js';
2
+ import { MJQueryDiagnosticCodes } from '../common/diagnosticCodes.js';
3
+ import { NormalizeCompositionCategoryPath } from './compositionPathMatch.js';
4
+ /**
5
+ * The save-time rules for compositions: the table-source position, argument names, and (with a
6
+ * resolver) the target's existence, reusability, parameters and cycles. Arguments are explicit,
7
+ * like a function call: an inner parameter that is not passed has no value.
8
+ */
9
+ export class CompositionRules {
10
+ constructor(options, outerNames) {
11
+ this.options = options;
12
+ this.diagnostics = [];
13
+ this.resolved = new Map();
14
+ this.outerNames = new Set(outerNames.map(n => n.toLowerCase()));
15
+ }
16
+ /**
17
+ * Applies the composition rules.
18
+ * @param outerNames - The outer query's parameter names (from the template and its declarations).
19
+ */
20
+ static Check(references, options, outerNames) {
21
+ const rules = new CompositionRules(options, outerNames);
22
+ for (const reference of references)
23
+ rules.checkReference(reference);
24
+ const unchecked = references.length > 0 && options.ResolveComposition === undefined;
25
+ if (unchecked) {
26
+ rules.add(MJQueryDiagnosticCodes.CompositionUnchecked, 'Info', references[0].Span, 'No resolver was given, so the composed queries were not checked.', 'Validate with a ResolveComposition callback.');
27
+ }
28
+ return { Diagnostics: rules.diagnostics, Complete: !unchecked };
29
+ }
30
+ checkReference(reference) {
31
+ if (!reference.InTablePosition) {
32
+ this.add(MJQueryDiagnosticCodes.CompositionPosition, 'Error', reference.Span, 'A composition can stand only where a table source goes: after FROM, JOIN or APPLY, or after a comma in a FROM list.', 'Write FROM {{query:"…"}} alias, or JOIN {{query:"…"}} alias ON ….');
33
+ }
34
+ this.checkDuplicateArguments(reference);
35
+ const resolver = this.options.ResolveComposition;
36
+ if (resolver === undefined)
37
+ return;
38
+ const target = this.resolve(resolver, reference.FullPath);
39
+ if (target === null) {
40
+ this.add(MJQueryDiagnosticCodes.CompositionNotFound, 'Error', reference.PathSpan, `No query exists at "${reference.FullPath}".`, 'Give the full category path and query name, e.g. "Sales/Reports/Top Customers".');
41
+ return;
42
+ }
43
+ this.checkPartialPath(reference, target);
44
+ if (!target.Reusable) {
45
+ this.add(MJQueryDiagnosticCodes.CompositionNotReusable, 'Error', reference.PathSpan, `"${reference.FullPath}" is not marked Reusable.`, 'Mark the composed query Reusable, or copy its SQL in.');
46
+ }
47
+ this.checkArguments(reference, target);
48
+ this.checkCycle(reference, resolver);
49
+ }
50
+ /**
51
+ * A reference that found its query by part of the category path: an error at save, so new SQL
52
+ * names the full path, and a warning on refresh, so a stored query keeps running.
53
+ */
54
+ checkPartialPath(reference, target) {
55
+ if (target.FullPath === undefined || NormalizeCompositionCategoryPath(target.FullPath) === NormalizeCompositionCategoryPath(reference.FullPath))
56
+ return;
57
+ const severity = this.options.Mode === 'Refresh' ? 'Warning' : 'Error';
58
+ this.add(MJQueryDiagnosticCodes.CompositionPartialPath, severity, reference.PathSpan, `"${reference.FullPath}" names the query at "${target.FullPath}" by part of its category path.`, `Write the full path: {{query:"${target.FullPath}"}}.`);
59
+ }
60
+ checkDuplicateArguments(reference) {
61
+ const seen = new Set();
62
+ for (const argument of reference.Arguments) {
63
+ const key = argument.Name.toLowerCase();
64
+ if (seen.has(key)) {
65
+ this.add(MJQueryDiagnosticCodes.CompositionDuplicateArgument, 'Error', argument.NameSpan, `"${argument.Name}" is passed twice.`, 'Pass each argument once.');
66
+ }
67
+ seen.add(key);
68
+ }
69
+ }
70
+ checkArguments(reference, target) {
71
+ const passed = new Set(reference.Arguments.map(a => a.Name.toLowerCase()));
72
+ const declared = new Set(target.Parameters.map(p => p.Name.toLowerCase()));
73
+ for (const argument of reference.Arguments) {
74
+ if (declared.has(argument.Name.toLowerCase()))
75
+ continue;
76
+ this.add(MJQueryDiagnosticCodes.CompositionUnknownArgument, 'Error', argument.NameSpan, `"${reference.FullPath}" has no parameter "${argument.Name}".`, `Use one of: ${target.Parameters.map(p => p.Name).join(', ') || '(none)'}.`);
77
+ }
78
+ for (const parameter of target.Parameters) {
79
+ if (passed.has(parameter.Name.toLowerCase()))
80
+ continue;
81
+ if (parameter.IsRequired)
82
+ this.missing(reference, parameter.Name);
83
+ else if (this.outerNames.has(parameter.Name.toLowerCase()))
84
+ this.implicit(reference, parameter.Name);
85
+ }
86
+ }
87
+ missing(reference, name) {
88
+ this.add(MJQueryDiagnosticCodes.CompositionMissingArgument, 'Error', reference.Span, `"${reference.FullPath}" requires "${name}", and it is not passed.`, `Pass it explicitly: (${name}=${name}) or (${name}='value').`);
89
+ }
90
+ implicit(reference, name) {
91
+ const severity = this.options.Mode === 'Refresh' ? 'Warning' : 'Error';
92
+ this.add(MJQueryDiagnosticCodes.CompositionImplicitArgument, severity, reference.Span, `"${name}" is a parameter of both queries but is not passed to "${reference.FullPath}"; values never flow implicitly.`, `Pass it explicitly as (${name}=${name}), or rename one of them.`);
93
+ }
94
+ /** Follows compositions from the target; reaching the query being validated, or a query twice on one path, is a cycle. */
95
+ checkCycle(reference, resolver) {
96
+ const self = this.options.QueryPath?.toLowerCase();
97
+ const path = this.findCycle(reference.FullPath, resolver, self, new Set(), new Set());
98
+ if (path === null)
99
+ return;
100
+ this.add(MJQueryDiagnosticCodes.CompositionCycle, 'Error', reference.Span, `Compositions loop: ${[reference.FullPath, ...path].join(' → ')}.`, 'Remove one of the compositions in the loop.');
101
+ }
102
+ findCycle(fullPath, resolver, self, onPath, done) {
103
+ const key = fullPath.toLowerCase();
104
+ if (key === self)
105
+ return [];
106
+ if (onPath.has(key))
107
+ return [];
108
+ if (done.has(key))
109
+ return null;
110
+ onPath.add(key);
111
+ for (const next of this.resolve(resolver, fullPath)?.Compositions ?? []) {
112
+ const tail = this.findCycle(next, resolver, self, onPath, done);
113
+ if (tail !== null)
114
+ return [next, ...tail];
115
+ }
116
+ onPath.delete(key);
117
+ done.add(key);
118
+ return null;
119
+ }
120
+ resolve(resolver, fullPath) {
121
+ const key = fullPath.toLowerCase();
122
+ if (!this.resolved.has(key)) {
123
+ const target = resolver(fullPath);
124
+ this.resolved.set(key, target && target.Exists ? target : null);
125
+ }
126
+ return this.resolved.get(key) ?? null;
127
+ }
128
+ add(code, severity, span, message, hint) {
129
+ this.diagnostics.push(MakeDiagnostic(code, severity, span, message, hint));
130
+ }
131
+ }
132
+ //# sourceMappingURL=compositionRules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compositionRules.js","sourceRoot":"","sources":["../../src/template/compositionRules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAU7E;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAKzB,YAAqC,OAAqC,EAAE,UAA6B;QAApE,YAAO,GAAP,OAAO,CAA8B;QAJzD,gBAAW,GAAiB,EAAE,CAAC;QAE/B,aAAQ,GAAG,IAAI,GAAG,EAAoC,CAAC;QAGpE,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACpE,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,UAA2C,EAAE,OAAqC,EAAE,UAA6B;QAC1H,MAAM,KAAK,GAAG,IAAI,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACxD,KAAK,MAAM,SAAS,IAAI,UAAU;YAAE,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QACpE,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,kBAAkB,KAAK,SAAS,CAAC;QACpF,IAAI,SAAS,EAAE,CAAC;YACZ,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,oBAAoB,EAAE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IAEO,GAAG,CAAC,IAAY,EAAE,QAA4B,EAAE,IAAU,EAAE,OAAe,EAAE,IAAY;QAC7F,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IAC/E,CAAC;CACJ"}
@@ -0,0 +1,45 @@
1
+ import type { Analysis, Span } from '../common/analysis.js';
2
+ import type { SqlTokens } from '../lexer/sqlTokens.js';
3
+ import type { TemplateNode } from './templateNodes.js';
4
+ /** Where a description came from: a `{# @param / @field #}` header or a trailing `--:` comment. */
5
+ export type DocCommentSource = 'Header' | 'Trailing';
6
+ /** One described parameter or field. */
7
+ export interface DocCommentEntry {
8
+ readonly Name: string;
9
+ readonly Description: string;
10
+ /** The `{type}` written after the tag, such as `string`, or `null`. */
11
+ readonly DeclaredType: string | null;
12
+ readonly Source: DocCommentSource;
13
+ /** The tag line or trailing comment. */
14
+ readonly Span: Span;
15
+ readonly NameSpan: Span;
16
+ }
17
+ /** The descriptions written into a template. */
18
+ export interface TemplateDocComments {
19
+ /** The text before the first tag of the first doc comment, or `null`. */
20
+ readonly Summary: string | null;
21
+ /** `@param` descriptions. */
22
+ readonly Parameters: readonly DocCommentEntry[];
23
+ /** `@field` descriptions and trailing `--:` descriptions, header entries first. */
24
+ readonly Fields: readonly DocCommentEntry[];
25
+ }
26
+ /** Reads the doc comments of a template: `{# @param / @field #}` headers and trailing `--:` comments. */
27
+ export declare class DocCommentReader {
28
+ private readonly diagnostics;
29
+ private readonly parameters;
30
+ private readonly fields;
31
+ private summary;
32
+ private constructor();
33
+ /**
34
+ * Reads every doc comment.
35
+ * @param parameterNames - The template's parameters; an `@param` naming anything else is reported.
36
+ */
37
+ static Read(nodes: readonly TemplateNode[], tokens: SqlTokens, parameterNames: readonly string[]): Analysis<TemplateDocComments>;
38
+ private readHeader;
39
+ private finishTag;
40
+ private parseNamedTag;
41
+ /** Adds an entry unless the name is already described; a second description is reported. */
42
+ private add;
43
+ private checkParameters;
44
+ }
45
+ //# sourceMappingURL=docComments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docComments.d.ts","sourceRoot":"","sources":["../../src/template/docComments.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAc,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAExE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvE,mGAAmG;AACnG,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAErD,wCAAwC;AACxC,MAAM,WAAW,eAAe;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,uEAAuE;IACvE,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;CAC3B;AAED,gDAAgD;AAChD,MAAM,WAAW,mBAAmB;IAChC,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,6BAA6B;IAC7B,QAAQ,CAAC,UAAU,EAAE,SAAS,eAAe,EAAE,CAAC;IAChD,mFAAmF;IACnF,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CAC/C;AAsBD,yGAAyG;AACzG,qBAAa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,OAAO,CAA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