@starci/eslint-canon-be 3.18.3 → 3.19.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.
Files changed (208) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/comments.js +1 -1
  3. package/dist/explicit-surface.js +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/jwt-alg.js +1 -1
  6. package/dist/lib/edition.d.ts +1 -1
  7. package/dist/lib/edition.js +1 -1
  8. package/dist/lib/hfs.d.ts +0 -6
  9. package/dist/lib/hfs.js +7 -5
  10. package/dist/lib/runtime-root.d.ts +6 -1
  11. package/dist/lib/runtime-root.js +8 -2
  12. package/dist/lib/subject-values.js +1 -1
  13. package/dist/module-layering.js +2 -2
  14. package/dist/project-graph.js +1 -1
  15. package/dist/third-party-owner.js +1 -1
  16. package/package.json +3 -1
  17. package/runtime/bundle.json +1 -190
  18. package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
  19. package/runtime/scripts/hfs/project-graph.mjs +6 -6
  20. package/runtime/scripts/hfs/project-rule.mjs +3 -3
  21. package/runtime/config.example.yaml +0 -194
  22. package/runtime/engine/by-code-unit.mjs +0 -12
  23. package/runtime/engine/config.mjs +0 -461
  24. package/runtime/engine/invalid-config.mjs +0 -15
  25. package/runtime/engine/model-config.mjs +0 -112
  26. package/runtime/engine/orca-config.mjs +0 -34
  27. package/runtime/engine/plain-object.mjs +0 -5
  28. package/runtime/engine/release-config.mjs +0 -32
  29. package/runtime/engine/removed-vocabulary.mjs +0 -27
  30. package/runtime/engine/resources-config.mjs +0 -59
  31. package/runtime/engine/runtime-root.mjs +0 -138
  32. package/runtime/engine/secrets.mjs +0 -202
  33. package/runtime/engine/sonar-config.mjs +0 -24
  34. package/runtime/engine/temp-root.mjs +0 -26
  35. package/runtime/engine/yaml.mjs +0 -161
  36. package/runtime/knowledge/grammars/index.yaml +0 -114
  37. package/runtime/knowledge/hfs/canon-pins.yaml +0 -716
  38. package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
  39. package/runtime/knowledge/hfs/rules.yaml +0 -6760
  40. package/runtime/knowledge/hfs/slots.yaml +0 -2783
  41. package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
  42. package/runtime/knowledge/sonar-gate.yaml +0 -151
  43. package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
  44. package/runtime/modules/models/registry.yaml +0 -221
  45. package/runtime/modules/models/runtimes.yaml +0 -556
  46. package/runtime/modules/models/tiers.yaml +0 -66
  47. package/runtime/scripts/api/git/cat-file.mjs +0 -4
  48. package/runtime/scripts/api/git/config-get.mjs +0 -9
  49. package/runtime/scripts/api/git/diff.mjs +0 -4
  50. package/runtime/scripts/api/git/lib.mjs +0 -80
  51. package/runtime/scripts/api/git/ls-files.mjs +0 -5
  52. package/runtime/scripts/api/git/ls-tree.mjs +0 -4
  53. package/runtime/scripts/api/git/merge-base.mjs +0 -8
  54. package/runtime/scripts/api/git/remote.mjs +0 -4
  55. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
  56. package/runtime/scripts/api/git/show.mjs +0 -5
  57. package/runtime/scripts/api/git/tag.mjs +0 -4
  58. package/runtime/scripts/hfs/allows.mjs +0 -77
  59. package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
  60. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
  61. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
  62. package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
  63. package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
  64. package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
  65. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
  66. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
  67. package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
  68. package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
  69. package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
  70. package/runtime/scripts/hfs/architecture/config.mjs +0 -407
  71. package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
  72. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
  73. package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
  74. package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
  75. package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
  76. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
  77. package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
  78. package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
  79. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
  80. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
  81. package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
  82. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
  83. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
  84. package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
  85. package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
  86. package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
  87. package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
  88. package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
  89. package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
  90. package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
  91. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
  92. package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
  93. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
  94. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
  95. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
  96. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
  97. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
  98. package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
  99. package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
  100. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
  101. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
  102. package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
  103. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
  104. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
  105. package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
  106. package/runtime/scripts/hfs/architecture/index.mjs +0 -402
  107. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
  108. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
  109. package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
  110. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
  111. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
  112. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
  113. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
  114. package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
  115. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
  116. package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
  117. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
  118. package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
  119. package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
  120. package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
  121. package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
  122. package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
  123. package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
  124. package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
  125. package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
  126. package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
  127. package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
  128. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
  129. package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
  130. package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
  131. package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
  132. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
  133. package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
  134. package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
  135. package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
  136. package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
  137. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
  138. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
  139. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
  140. package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
  141. package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
  142. package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
  143. package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
  144. package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
  145. package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
  146. package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
  147. package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
  148. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
  149. package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
  150. package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
  151. package/runtime/scripts/hfs/edition-slots.mjs +0 -80
  152. package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
  153. package/runtime/scripts/hfs/linear-text.mjs +0 -30
  154. package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
  155. package/runtime/scripts/hfs/param-names.mjs +0 -13
  156. package/runtime/scripts/hfs/path-findings.mjs +0 -167
  157. package/runtime/scripts/hfs/repo-identity.mjs +0 -89
  158. package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
  159. package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
  160. package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
  161. package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
  162. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
  163. package/runtime/scripts/hfs/rules/read.mjs +0 -45
  164. package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
  165. package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
  166. package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
  167. package/runtime/scripts/hfs/slot-classify.mjs +0 -69
  168. package/runtime/scripts/hfs/slot-errors.mjs +0 -12
  169. package/runtime/scripts/hfs/slot-imports.mjs +0 -98
  170. package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
  171. package/runtime/scripts/hfs/slot-match.mjs +0 -164
  172. package/runtime/scripts/hfs/slot-path.mjs +0 -6
  173. package/runtime/scripts/hfs/slot-required.mjs +0 -95
  174. package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
  175. package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
  176. package/runtime/scripts/hfs/slots.mjs +0 -306
  177. package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
  178. package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
  179. package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
  180. package/runtime/scripts/hfs/view.mjs +0 -180
  181. package/runtime/scripts/lib/declaration-surface.mjs +0 -166
  182. package/runtime/scripts/lib/dockerfile.mjs +0 -164
  183. package/runtime/scripts/lib/env.mjs +0 -18
  184. package/runtime/scripts/lib/event-contract.mjs +0 -102
  185. package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
  186. package/runtime/scripts/lib/git.mjs +0 -35
  187. package/runtime/scripts/lib/glob.mjs +0 -32
  188. package/runtime/scripts/lib/grammar-lint.mjs +0 -57
  189. package/runtime/scripts/lib/i18n.mjs +0 -82
  190. package/runtime/scripts/lib/in-order.mjs +0 -90
  191. package/runtime/scripts/lib/json-clone.mjs +0 -70
  192. package/runtime/scripts/lib/json.mjs +0 -44
  193. package/runtime/scripts/lib/language.mjs +0 -233
  194. package/runtime/scripts/lib/list.mjs +0 -26
  195. package/runtime/scripts/lib/mutation-fence.mjs +0 -20
  196. package/runtime/scripts/lib/package-at.mjs +0 -62
  197. package/runtime/scripts/lib/path-key.mjs +0 -124
  198. package/runtime/scripts/lib/read-text.mjs +0 -47
  199. package/runtime/scripts/lib/regex.mjs +0 -3
  200. package/runtime/scripts/lib/rule-packs.mjs +0 -243
  201. package/runtime/scripts/lib/same-text.mjs +0 -4
  202. package/runtime/scripts/lib/secret-patterns.mjs +0 -230
  203. package/runtime/scripts/lib/sops-envelope.mjs +0 -212
  204. package/runtime/scripts/lib/stack-services.mjs +0 -191
  205. package/runtime/scripts/lib/ts-analysis.mjs +0 -39
  206. package/runtime/scripts/lib/ts-ast.mjs +0 -63
  207. package/runtime/scripts/lib/walk.mjs +0 -45
  208. package/runtime/scripts/lib/yaml-cached.mjs +0 -14
@@ -1,76 +0,0 @@
1
- import path from 'node:path';
2
- import { HOLE, tokenizeSql } from './sql-tokens.mjs';
3
- import { machineKit } from './machine-ast.mjs';
4
- /**
5
- * R181 `sql-returning` (BE_SQL_RETURNING_SHAPE). TypeORM's `EntityManager.query` returns an UPDATE or DELETE with RETURNING as
6
- * `[rows, affectedCount]`, not as rows (an INSERT ... RETURNING returns rows), so a caller that reads the result as rows silently reads
7
- * the wrong thing and no unit spec that stubs the SQL can see it. Every `sql` tagged template (the tag declared in platform/database) of a
8
- * `<name>.sql.ts` file in a capability's `persistence/` is read with the tokenizer of sql-tokens.mjs, split into statements at top-level
9
- * semicolons, and a statement that STARTS with UPDATE or DELETE and carries RETURNING at the top level is refused: write it as
10
- * `WITH changed AS (UPDATE ... RETURNING ...) SELECT ... FROM changed`, which returns rows. A RETURNING inside a parenthesised CTE is the
11
- * wrapped form and passes; so does INSERT ... RETURNING and any statement without RETURNING.
12
- */
13
- export const SQL_RETURNING_RULE_IDS = ['BE_SQL_RETURNING_SHAPE'];
14
- const RULE = 'BE_SQL_RETURNING_SHAPE';
15
- function closeStatement(state) {
16
- if (state.verb && state.returning)
17
- state.found.push(state.verb);
18
- state.verb = null;
19
- state.returning = false;
20
- }
21
- /** Folds one token into the statement state: parenthesis depth, statement ends and the top-level words. */
22
- function readToken(state, token) {
23
- if (token.t === 'punct') {
24
- if (token.v === '(')
25
- state.depth += 1;
26
- else if (token.v === ')')
27
- state.depth = Math.max(0, state.depth - 1);
28
- else if (token.v === ';' && state.depth === 0)
29
- closeStatement(state);
30
- return;
31
- }
32
- if (state.depth !== 0 || token.t !== 'word')
33
- return;
34
- if (state.verb === null)
35
- state.verb = token.up; // a word token always carries its upper-case spelling
36
- else if (token.up === 'RETURNING')
37
- state.returning = true;
38
- }
39
- /** The leading verbs of the top-level statements of `text` that RETURN from an UPDATE or DELETE without a wrapping SELECT. */
40
- function unwrappedReturning(text) {
41
- const state = { found: [], depth: 0, verb: null, returning: false };
42
- for (const token of tokenizeSql(text))
43
- readToken(state, token);
44
- closeStatement(state);
45
- return state.found.filter(verb => verb === 'UPDATE' || verb === 'DELETE');
46
- }
47
- /** The SQL text of a tagged template, each substitution replaced by a HOLE marker. */
48
- function templateText(ts, template) {
49
- return ts.isNoSubstitutionTemplateLiteral(template) ? template.text
50
- : template.head.text + template.templateSpans.map(span => HOLE + span.literal.text).join('');
51
- }
52
- const isDatabaseTag = (kit, checker, node) => {
53
- const home = kit.declarationsOf(checker, node.tag).map(kit.ownerOfDeclaration).find(Boolean);
54
- return home?.tier === 'platform' && home?.name === 'database';
55
- };
56
- const returningViolation = (kit, file, node, verb) => ({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message: `${verb} ... RETURNING in ${file.rel} is returned by EntityManager.query as [rows, affectedCount], not as rows, so a caller reading rows reads the wrong value. Wrap it: WITH changed AS (${verb} ... RETURNING ...) SELECT ... FROM changed.`, verb });
57
- export function checkSqlReturning(input) {
58
- const { graph } = input;
59
- const kit = machineKit(input);
60
- const { ts } = kit;
61
- const violations = [];
62
- let templates = 0;
63
- for (const file of graph.files.values()) {
64
- if (file.slot !== 'be.persistence' || !path.posix.basename(file.rel).endsWith('.sql.ts') || !file.owner)
65
- continue;
66
- const checker = kit.checkerOf(file.sourceFile);
67
- kit.walk(file.sourceFile, node => {
68
- if (!ts.isTaggedTemplateExpression(node) || !isDatabaseTag(kit, checker, node))
69
- return;
70
- templates += 1;
71
- for (const verb of unwrappedReturning(templateText(ts, node.template)))
72
- violations.push(returningViolation(kit, file, node, verb));
73
- });
74
- }
75
- return { violations, coverage: { status: 'checked', templates } };
76
- }
@@ -1,117 +0,0 @@
1
- /** Token forms shared by SQL relation scanning and conservative singleton-value proofs. */
2
- /** Whether a token can spell an SQL identifier. */
3
- export const isName = (token) => Boolean(token && (token.t === 'word' || token.t === 'ident'));
4
- /** The identifier spelling after SQL word folding. */
5
- export const nameOf = (token) => (token.t === 'word' ? token.v.toLowerCase() : token.v);
6
- /** Whether a token is the named SQL keyword. */
7
- export const isWord = (token, up) => token?.t === 'word' && token.up === up;
8
- // The scalar-cast grammar proves only these builtin targets, unqualified or explicitly under pg_catalog.
9
- const SCALAR_CAST_TYPES = new Set(['uuid', 'text']);
10
- /** Depth of each token (the depth before it when it is `(`, after it when it is `)`). */
11
- export function depths(tokens) {
12
- let depth = 0;
13
- return tokens.map(token => {
14
- if (token.v === ')' && token.t === 'punct')
15
- depth -= 1;
16
- const here = depth;
17
- if (token.v === '(' && token.t === 'punct')
18
- depth += 1;
19
- return here;
20
- });
21
- }
22
- /** The closing parenthesis of a token group, or the final token when unmatched. */
23
- export function matching(tokens, open) {
24
- let depth = 0;
25
- for (let i = open; i < tokens.length; i += 1) {
26
- if (tokens[i].t !== 'punct')
27
- continue;
28
- if (tokens[i].v === '(')
29
- depth += 1;
30
- else if (tokens[i].v === ')') {
31
- depth -= 1;
32
- if (depth === 0)
33
- return i;
34
- }
35
- }
36
- return tokens.length - 1;
37
- }
38
- function unparenthesized(tokens) {
39
- let part = tokens;
40
- while (part[0]?.v === '(' && part.at(-1)?.v === ')' && matching(part, 0) === part.length - 1)
41
- part = part.slice(1, -1);
42
- return part;
43
- }
44
- function keyColumn(tokens, qualifiers) {
45
- const part = unparenthesized(tokens);
46
- if (singletonValue(part))
47
- return null;
48
- if (part.length === 1 && isName(part[0]))
49
- return nameOf(part[0]);
50
- if (part.length === 3 && isName(part[0]) && part[1]?.v === '.' && isName(part[2]) && qualifiers.has(nameOf(part[0])))
51
- return nameOf(part[2]);
52
- return null;
53
- }
54
- function scalarCastType(tokens) {
55
- if (tokens.length === 1 && isName(tokens[0]))
56
- return SCALAR_CAST_TYPES.has(nameOf(tokens[0]));
57
- return tokens.length === 3 && isName(tokens[0]) && nameOf(tokens[0]) === 'pg_catalog' && tokens[1]?.v === '.'
58
- && isName(tokens[2]) && SCALAR_CAST_TYPES.has(nameOf(tokens[2]));
59
- }
60
- /** SQL CAST is a scalar wrapper; its operand is still inspected separately for row dependence or set-returning calls. */
61
- function castParts(tokens, start = 0) {
62
- if (!isWord(tokens[start], 'CAST') || tokens[start + 1]?.v !== '(')
63
- return null;
64
- const end = matching(tokens, start + 1);
65
- if (tokens[end]?.v !== ')')
66
- return null;
67
- const inside = tokens.slice(start + 2, end);
68
- const level = depths(inside);
69
- const separator = inside.findIndex((token, index) => level[index] === 0 && isWord(token, 'AS'));
70
- if (separator < 1 || separator === inside.length - 1)
71
- return null;
72
- return { value: inside.slice(0, separator), type: inside.slice(separator + 1), next: end + 1 };
73
- }
74
- /** A scalar atom, optionally cast through the supported builtin grammar, proves a row-independent equality value. */
75
- function singletonValue(tokens) {
76
- const part = unparenthesized(tokens);
77
- if (part.length === 2 && ['+', '-'].includes(part[0].v) && part[1]?.t === 'number')
78
- return true;
79
- if (part.length === 1) {
80
- const [token] = part;
81
- return ['param', 'string', 'number'].includes(token.t) || isWord(token, 'NULL') || isWord(token, 'TRUE') || isWord(token, 'FALSE');
82
- }
83
- const cast = castParts(part);
84
- if (cast && cast.next === part.length && scalarCastType(cast.type))
85
- return singletonValue(cast.value);
86
- const level = depths(part);
87
- for (let index = part.length - 1; index > 0; index -= 1) {
88
- if (level[index] === 0 && part[index].v === '::')
89
- return scalarCastType(part.slice(index + 1)) && singletonValue(part.slice(0, index));
90
- }
91
- return false;
92
- }
93
- /** Key columns equated to proven row-independent singleton values in either operand order. */
94
- export function equalityColumns(conjunct, qualifiers) {
95
- const found = new Set();
96
- const part = unparenthesized(conjunct);
97
- const level = depths(part);
98
- const equals = part.findIndex((token, index) => level[index] === 0 && token.t === 'punct' && token.v === '=');
99
- if (equals < 0)
100
- return found;
101
- const left = part.slice(0, equals);
102
- const right = part.slice(equals + 1);
103
- const leftColumn = keyColumn(left, qualifiers);
104
- const rightColumn = keyColumn(right, qualifiers);
105
- if (leftColumn && singletonValue(right))
106
- found.add(leftColumn);
107
- if (rightColumn && singletonValue(left))
108
- found.add(rightColumn);
109
- return found;
110
- }
111
- /** Whether a call position is SQL CAST through the supported scalar type grammar. */
112
- export function scalarCastAt(tokens, index) {
113
- if (tokens[index - 1]?.v === '.')
114
- return false;
115
- const cast = castParts(tokens, index);
116
- return Boolean(cast && scalarCastType(cast.type));
117
- }