soma-kit 0.1.10 → 0.1.12

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 (302) hide show
  1. package/README.md +103 -110
  2. package/bin/soma-kit.mjs +1 -1
  3. package/bin/soma.mjs +22 -0
  4. package/package.json +13 -7
  5. package/packs/finance/reconcile-board.ts +5 -2
  6. package/packs/finance/reconcile-desk/compile.ts +3 -2
  7. package/spec/generated/kit-app.schema.json +776 -38
  8. package/spec/generated/kit-page.schema.json +1613 -224
  9. package/spec/kit-grammar.json +770 -529
  10. package/spec/kit-grammar.schema.json +1962 -392
  11. package/src/app/app-config.ts +371 -347
  12. package/src/app/component-gate.ts +12 -15
  13. package/src/app/compose-apps.ts +79 -8
  14. package/src/app/define-kit-actions.ts +245 -41
  15. package/src/app/define-kit-app.ts +174 -31
  16. package/src/app/define-kit-view.ts +100 -0
  17. package/src/app/envelope.ts +1 -161
  18. package/src/app/index.ts +13 -2
  19. package/src/app/kit-view-context.ts +290 -0
  20. package/src/app/notify-renderer.ts +1 -115
  21. package/src/app/paged-list-adapter.ts +1 -240
  22. package/src/app/server-pages.ts +8 -2
  23. package/src/app/server.ts +491 -101
  24. package/src/app/submit.types.ts +1 -1
  25. package/src/app/theme-endpoint.ts +63 -0
  26. package/src/app/theme-runtime-shared.ts +1 -0
  27. package/src/app/theme-runtime.ts +663 -0
  28. package/src/base/action-busy.ts +2 -2
  29. package/src/base/action-gate.ts +4 -255
  30. package/src/base/action-slots.ts +47 -0
  31. package/src/base/alert.ts +5 -3
  32. package/src/base/avatar.ts +2 -2
  33. package/src/base/button.ts +46 -29
  34. package/src/base/cascader.ts +11 -12
  35. package/src/base/check-core.ts +1 -1
  36. package/src/base/choice.ts +28 -26
  37. package/src/base/class-candidates.ts +17 -0
  38. package/src/base/color-picker.ts +6 -6
  39. package/src/base/combobox.ts +5 -3
  40. package/src/base/command-palette.ts +9 -5
  41. package/src/base/countdown.ts +1 -1
  42. package/src/base/date-range.ts +25 -11
  43. package/src/base/date.ts +85 -17
  44. package/src/base/divider.ts +2 -2
  45. package/src/base/fab.ts +11 -4
  46. package/src/base/image.ts +1 -1
  47. package/src/base/index.ts +9 -3
  48. package/src/base/input.ts +42 -13
  49. package/src/base/kbd.ts +3 -1
  50. package/src/base/link.ts +4 -4
  51. package/src/base/listbox-core.ts +50 -30
  52. package/src/base/loading-gate.ts +133 -0
  53. package/src/base/mentions.ts +5 -5
  54. package/src/base/menu-button.ts +6 -1
  55. package/src/base/menu-core.ts +4 -0
  56. package/src/base/motion/aura.ts +2 -2
  57. package/src/base/motion/hover-3d.ts +2 -2
  58. package/src/base/motion/hover-gallery.ts +2 -2
  59. package/src/base/motion/marquee.ts +2 -2
  60. package/src/base/motion/text-rotate.ts +2 -2
  61. package/src/base/number.ts +93 -80
  62. package/src/base/otp.ts +4 -1
  63. package/src/base/permission-gate.ts +6 -0
  64. package/src/base/popover.ts +40 -8
  65. package/src/base/popup.ts +79 -14
  66. package/src/base/price-text.ts +2 -2
  67. package/src/base/progress.ts +2 -2
  68. package/src/base/qr-code.ts +4 -4
  69. package/src/base/qty-stepper.ts +9 -3
  70. package/src/base/range.ts +2 -2
  71. package/src/base/rating.ts +1 -1
  72. package/src/base/segmented.ts +4 -0
  73. package/src/base/select.ts +4 -3
  74. package/src/base/shared.ts +221 -29
  75. package/src/base/swap.ts +4 -1
  76. package/src/base/switch.ts +1 -1
  77. package/src/base/tag-input.ts +14 -10
  78. package/src/base/tag.ts +5 -1
  79. package/src/base/text.ts +39 -6
  80. package/src/base/textarea.ts +37 -11
  81. package/src/base/time-picker.ts +12 -9
  82. package/src/base/tree-select.ts +15 -8
  83. package/src/base/upload.ts +34 -5
  84. package/src/base/virtual-list.ts +107 -1
  85. package/src/biz/approval-desk/compile.ts +23 -41
  86. package/src/biz/auth-panel/compile.ts +37 -52
  87. package/src/biz/auth-panel/index.ts +1 -1
  88. package/src/biz/category-crud/compile.ts +22 -36
  89. package/src/biz/checkout-page/compile.ts +21 -5
  90. package/src/biz/compose.ts +13 -27
  91. package/src/biz/define.ts +5 -4
  92. package/src/biz/import-wizard/compile.ts +22 -26
  93. package/src/biz/import-wizard/hub.ts +126 -61
  94. package/src/biz/import-wizard/shell.ts +3 -3
  95. package/src/biz/index.ts +3 -3
  96. package/src/biz/landing-page/compile.ts +19 -3
  97. package/src/biz/link/hub.ts +49 -20
  98. package/src/biz/link/shared.ts +115 -118
  99. package/src/biz/master-sub/compile.ts +31 -44
  100. package/src/biz/multi-board/compile.ts +34 -49
  101. package/src/biz/multi-board/index.ts +18 -1
  102. package/src/biz/multi-board/shell.ts +24 -15
  103. package/src/biz/notification-center/compile.ts +21 -33
  104. package/src/biz/page-templates/domain-templates.ts +80 -13
  105. package/src/biz/page-templates/result-page/compile.ts +11 -2
  106. package/src/biz/page-templates/shared.ts +34 -36
  107. package/src/biz/record-detail/compile.ts +47 -42
  108. package/src/biz/record-detail/index.ts +11 -1
  109. package/src/biz/settings-center/compile.ts +6 -5
  110. package/src/biz/shared/action-host.ts +91 -211
  111. package/src/biz/shared/compile-helpers.ts +80 -0
  112. package/src/biz/shared/coordinator.ts +486 -83
  113. package/src/biz/shared/index.ts +8 -2
  114. package/src/biz/shared/overlay-shell.ts +80 -0
  115. package/src/biz/shared/pipes.ts +43 -30
  116. package/src/biz/shared/remove-key.ts +6 -0
  117. package/src/biz/shared/remove-wire.ts +29 -0
  118. package/src/biz/shared/runtime-hub.ts +216 -24
  119. package/src/biz/single-form/compile.ts +15 -37
  120. package/src/biz/standard-crud/compile.ts +62 -107
  121. package/src/biz/standard-crud/shell.ts +16 -66
  122. package/src/biz/step-form/compile.ts +26 -97
  123. package/src/biz/step-form/hub.ts +34 -41
  124. package/src/biz/types.ts +4 -3
  125. package/src/cli/core-imports.ts +54 -0
  126. package/src/cli/kit-cli.ts +130 -26
  127. package/src/cli/kit-init.ts +222 -0
  128. package/src/cli/service-endpoint-check.ts +425 -0
  129. package/src/cli/source-path-check.d.mts +17 -0
  130. package/src/cli/source-path-check.mjs +334 -0
  131. package/src/cli/view-writes.ts +752 -0
  132. package/src/compile/action-host-attach.ts +21 -29
  133. package/src/compile/closed-set.ts +509 -0
  134. package/src/compile/compile-page.ts +219 -72
  135. package/src/compile/component-candidates.ts +1 -1
  136. package/src/compile/hints.ts +30 -1
  137. package/src/compile/index.ts +1 -0
  138. package/src/compile/kit-error.ts +1 -0
  139. package/src/compile/locate.ts +21 -1
  140. package/src/compile/parse.ts +370 -41
  141. package/src/compile/redirect.ts +6 -2
  142. package/src/compile/styles.ts +35 -2
  143. package/src/compile/types.ts +18 -2
  144. package/src/compile/view-check.ts +151 -0
  145. package/src/data/amount-breakdown.ts +2 -2
  146. package/src/data/anchor-nav.ts +2 -2
  147. package/src/data/approval-flow.ts +2 -2
  148. package/src/data/assignment-picker.ts +40 -29
  149. package/src/data/async-result-panel.ts +62 -6
  150. package/src/data/breadcrumbs.ts +2 -2
  151. package/src/data/calendar.ts +22 -25
  152. package/src/data/carousel.ts +5 -2
  153. package/src/data/chart.ts +42 -34
  154. package/src/data/checklist.ts +2 -2
  155. package/src/data/code-view.ts +4 -2
  156. package/src/data/comment-thread.ts +5 -2
  157. package/src/data/confirm-dialog.ts +10 -0
  158. package/src/data/context-menu.ts +29 -37
  159. package/src/data/d9-util.ts +2 -18
  160. package/src/data/diff.ts +4 -2
  161. package/src/data/dock.ts +2 -2
  162. package/src/data/embed.ts +2 -1
  163. package/src/data/field-mapper.ts +31 -26
  164. package/src/data/flow-editor-contract.ts +1 -1
  165. package/src/data/flow-editor.ts +89 -100
  166. package/src/data/flow-node-options.ts +90 -0
  167. package/src/data/flow-remote-options.ts +0 -103
  168. package/src/data/footer.ts +2 -2
  169. package/src/data/form-draft-registry.ts +2 -4
  170. package/src/data/gantt.ts +14 -17
  171. package/src/data/hero.ts +2 -2
  172. package/src/data/image-viewer.ts +20 -26
  173. package/src/data/index.ts +0 -2
  174. package/src/data/item-list.ts +31 -22
  175. package/src/data/kanban.ts +43 -42
  176. package/src/data/media-grid.ts +14 -19
  177. package/src/data/menu.ts +2 -2
  178. package/src/data/mockup.ts +2 -2
  179. package/src/data/modal-dialog.ts +22 -18
  180. package/src/data/navbar.ts +7 -2
  181. package/src/data/notify-renderer.ts +235 -0
  182. package/src/data/object-form.ts +1036 -648
  183. package/src/data/pager.ts +65 -29
  184. package/src/data/permission-matrix.ts +20 -21
  185. package/src/data/permission-tree.ts +28 -26
  186. package/src/data/pricing-table.ts +9 -3
  187. package/src/data/reaction-bar.ts +77 -88
  188. package/src/data/read-rollback.ts +73 -0
  189. package/src/data/record-card.ts +3 -3
  190. package/src/data/record-picker.ts +93 -50
  191. package/src/data/redirect.ts +32 -32
  192. package/src/data/remote-options.ts +13 -6
  193. package/src/data/request-console.ts +5 -3
  194. package/src/data/resident.ts +2 -1
  195. package/src/data/result-panel.ts +4 -2
  196. package/src/data/rich-text.ts +45 -55
  197. package/src/data/row-editor.ts +285 -52
  198. package/src/data/rule-builder.ts +18 -12
  199. package/src/data/shape-util.ts +4 -0
  200. package/src/data/stat-group.ts +243 -101
  201. package/src/data/static-registry.ts +22 -11
  202. package/src/data/steps.ts +2 -2
  203. package/src/data/survey.ts +24 -29
  204. package/src/data/system-switcher.ts +2 -2
  205. package/src/data/timeline.ts +2 -2
  206. package/src/data/tour-guide.ts +22 -29
  207. package/src/data/transfer.ts +27 -23
  208. package/src/data/tree-table.ts +96 -48
  209. package/src/data/tree.ts +27 -34
  210. package/src/data/trend-line.ts +6 -24
  211. package/src/data/virtual-rows.ts +118 -76
  212. package/src/data/watermark.ts +2 -2
  213. package/src/data/wrap.ts +63 -38
  214. package/src/frames/blank-frame.ts +1 -0
  215. package/src/frames/index.ts +2 -2
  216. package/src/frames/page-bar.ts +12 -11
  217. package/src/frames/page-header.ts +14 -5
  218. package/src/frames/page-status.ts +2 -2
  219. package/src/frames/shared.ts +23 -17
  220. package/src/frames/single-frame.ts +1 -0
  221. package/src/frames/split-frame/shell.ts +5 -5
  222. package/src/frames/split-frame/wiring.ts +2 -2
  223. package/src/frames/tabs-frame/shell.ts +2 -13
  224. package/src/frames/tabs-frame/wiring.ts +4 -8
  225. package/src/frames/top-main-frame.ts +1 -0
  226. package/src/frames/types.ts +13 -2
  227. package/src/frames/workspace-frame/extras.ts +20 -4
  228. package/src/frames/workspace-frame/index.ts +1 -1
  229. package/src/frames/workspace-frame/shell.ts +1 -0
  230. package/src/frames/workspace-frame/state.ts +13 -6
  231. package/src/frames/workspace-frame/view.ts +119 -25
  232. package/src/generated/kit-grammar-runtime.ts +430 -366
  233. package/src/generated/page-origin.ts +0 -11
  234. package/src/i18n/kit-text.ts +23 -27
  235. package/src/index.ts +2 -1
  236. package/src/object-renderer/action-gate.ts +11 -147
  237. package/src/object-renderer/arrange.ts +71 -77
  238. package/src/object-renderer/collapse-wiring.ts +2 -2
  239. package/src/object-renderer/collection-expand.ts +2 -2
  240. package/src/object-renderer/collection-parts.ts +216 -100
  241. package/src/object-renderer/collection-table.ts +180 -42
  242. package/src/object-renderer/collection.ts +95 -79
  243. package/src/object-renderer/compile-data.ts +85 -100
  244. package/src/object-renderer/crud-bridge.ts +32 -0
  245. package/src/object-renderer/defaults.ts +8 -14
  246. package/src/object-renderer/display-checks.ts +3 -24
  247. package/src/object-renderer/emit-events.ts +186 -172
  248. package/src/object-renderer/emit-object.ts +15 -2
  249. package/src/object-renderer/emit-static.ts +174 -132
  250. package/src/object-renderer/field-value.ts +593 -396
  251. package/src/object-renderer/filter-reload.ts +70 -0
  252. package/src/object-renderer/form-detail.ts +112 -2
  253. package/src/object-renderer/index.ts +26 -0
  254. package/src/object-renderer/key-field.ts +12 -0
  255. package/src/object-renderer/linkage.ts +7 -270
  256. package/src/object-renderer/merge-class.ts +18 -1
  257. package/src/object-renderer/path-pick.ts +27 -0
  258. package/src/object-renderer/render-object.ts +405 -86
  259. package/src/object-renderer/request-actions.ts +230 -249
  260. package/src/object-renderer/table-actions.ts +195 -95
  261. package/src/object-renderer/table-summary.ts +2 -2
  262. package/src/object-renderer/table-tools.ts +418 -84
  263. package/src/object-renderer/types.ts +128 -122
  264. package/src/object-renderer/view-binding.ts +196 -0
  265. package/src/page-target/ai-surface.ts +37 -0
  266. package/src/page-target/compile.ts +48 -8
  267. package/src/page-target/index.ts +8 -1
  268. package/src/page-target/intent-schema.ts +154 -28
  269. package/src/page-target/target.ts +257 -50
  270. package/src/page-target/writer-policy.ts +14 -3
  271. package/src/recipes/container.ts +165 -0
  272. package/src/recipes/control.ts +219 -0
  273. package/src/recipes/index.ts +263 -0
  274. package/src/recipes/overlay.ts +182 -0
  275. package/src/recipes/state.ts +70 -0
  276. package/src/recipes/table-row.ts +51 -0
  277. package/src/recipes/typography.ts +87 -0
  278. package/src/shared/action-field-guard.ts +41 -0
  279. package/src/shared/envelope.ts +207 -0
  280. package/src/shared/escape.ts +57 -0
  281. package/src/shared/kit-error.ts +21 -0
  282. package/src/shared/paged-list-adapter.ts +240 -0
  283. package/src/shared/path-guard.ts +127 -0
  284. package/src/shared/theme-runtime-shared.ts +175 -0
  285. package/src/shared/view-info.ts +10 -0
  286. package/src/theme/index.ts +12 -0
  287. package/src/theme/kit-theme-text.ts +1 -1
  288. package/src/theme/kit-theme.css +38 -1
  289. package/src/theme/kit-theme.tpl +38 -1
  290. package/src/theme/nine-dim-structure.ts +77 -0
  291. package/src/theme/surface-layers.ts +97 -0
  292. package/src/theme/theme-tokens.ts +85 -79
  293. package/src/theme/theme-types.ts +71 -0
  294. package/src/theme/typography.ts +17 -17
  295. package/src/biz/shared/step-values.ts +0 -25
  296. package/src/biz/step-form/steps-ref.ts +0 -112
  297. package/src/data/options-bus.ts +0 -24
  298. package/src/data/prompt-dialog.ts +0 -235
  299. package/src/object-renderer/adopt-gate.ts +0 -333
  300. package/src/object-renderer/field-policy.ts +0 -89
  301. package/src/object-renderer/outcome-draft.ts +0 -61
  302. package/src/theme/nine-dim-palettes.ts +0 -1278
@@ -0,0 +1,334 @@
1
+ import ts from 'typescript';
2
+
3
+ const FS_METHODS = new Set([
4
+ 'readFileSync', 'writeFileSync', 'appendFileSync', 'existsSync', 'readdirSync', 'statSync', 'lstatSync',
5
+ 'mkdirSync', 'rmSync', 'unlinkSync', 'copyFileSync', 'renameSync', 'openSync', 'accessSync', 'realpathSync',
6
+ 'readFile', 'writeFile', 'appendFile', 'readdir', 'stat', 'lstat', 'mkdir', 'rm', 'unlink', 'copyFile',
7
+ 'rename', 'open', 'access', 'realpath', 'createReadStream', 'createWriteStream', 'truncate', 'chmod', 'chown',
8
+ ]);
9
+ const HTTP_METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'request']);
10
+ const PATH_METHODS = new Set(['join', 'resolve']);
11
+ const DRIVE_PATH = /^[A-Za-z]:[\\/]/;
12
+
13
+ function moduleKind(moduleName) {
14
+ const normalized = moduleName.replace(/^node:/, '');
15
+ if (normalized === 'fs' || normalized === 'fs/promises') return 'fs';
16
+ if (normalized === 'path') return 'path';
17
+ return undefined;
18
+ }
19
+
20
+ function scopeForVariable(node) {
21
+ const list = node.parent;
22
+ const flags = ts.isVariableDeclarationList(list) ? list.flags : 0;
23
+ const isVar = (flags & ts.NodeFlags.BlockScoped) === 0;
24
+ for (let current = list.parent; current !== undefined; current = current.parent) {
25
+ if (ts.isSourceFile(current) || ts.isBlock(current) || ts.isModuleBlock(current) || ts.isCaseBlock(current)
26
+ || ts.isForStatement(current) || ts.isForInStatement(current) || ts.isForOfStatement(current) || ts.isCatchClause(current)) {
27
+ if (isVar) {
28
+ for (let parent = current.parent; parent !== undefined; parent = parent.parent) {
29
+ if (ts.isFunctionLike(parent) || ts.isSourceFile(parent)) return parent;
30
+ }
31
+ }
32
+ return current;
33
+ }
34
+ if (ts.isFunctionLike(current)) return current;
35
+ }
36
+ return node.getSourceFile();
37
+ }
38
+
39
+ function scopeBindings() {
40
+ return new Map();
41
+ }
42
+
43
+ function addScopeBinding(scopes, scope, name, node, kind) {
44
+ let bindings = scopes.get(scope);
45
+ if (bindings === undefined) { bindings = new Map(); scopes.set(scope, bindings); }
46
+ bindings.set(name, { node, ...(kind !== undefined ? { kind } : {}) });
47
+ }
48
+
49
+ function bindingName(node) {
50
+ return ts.isIdentifier(node) ? node.text : undefined;
51
+ }
52
+
53
+ function bindingIdentifiers(pattern) {
54
+ if (ts.isIdentifier(pattern)) return [{ name: pattern.text, node: pattern }];
55
+ if (ts.isObjectBindingPattern(pattern) || ts.isArrayBindingPattern(pattern)) {
56
+ return pattern.elements.flatMap((element) => ts.isOmittedExpression(element) ? [] : bindingIdentifiers(element.name));
57
+ }
58
+ return [];
59
+ }
60
+
61
+ function bindImport(statement, scopes) {
62
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) return;
63
+ const kind = moduleKind(statement.moduleSpecifier.text);
64
+ if (kind === undefined || statement.importClause?.isTypeOnly) return;
65
+ const scope = statement.getSourceFile();
66
+ const clause = statement.importClause;
67
+ if (clause?.name !== undefined) addScopeBinding(scopes, scope, clause.name.text, clause.name, kind);
68
+ const named = clause?.namedBindings;
69
+ if (named === undefined) return;
70
+ if (ts.isNamespaceImport(named)) {
71
+ addScopeBinding(scopes, scope, named.name.text, named.name, kind);
72
+ return;
73
+ }
74
+ for (const element of named.elements) {
75
+ const original = element.propertyName?.text ?? element.name.text;
76
+ const bindingKind = kind === 'fs'
77
+ ? original === 'promises' ? 'fsPromises' : FS_METHODS.has(original) ? `fsFunction:${original}` : undefined
78
+ : PATH_METHODS.has(original) ? `pathFunction:${original}` : undefined;
79
+ if (bindingKind !== undefined) addScopeBinding(scopes, scope, element.name.text, element.name, bindingKind);
80
+ }
81
+ }
82
+
83
+ function getVisibleBinding(identifier, fromNode, scopes) {
84
+ for (let current = fromNode; current !== undefined; current = current.parent) {
85
+ const bindings = scopes.get(current);
86
+ const binding = bindings?.get(identifier);
87
+ if (binding !== undefined) return binding;
88
+ }
89
+ return undefined;
90
+ }
91
+
92
+ function unwrapModuleExpression(expression) {
93
+ let current = expression;
94
+ while (ts.isAwaitExpression(current) || ts.isParenthesizedExpression(current) || ts.isAsExpression(current)) {
95
+ current = current.expression;
96
+ }
97
+ return current;
98
+ }
99
+
100
+ function initializerModuleKind(initializer) {
101
+ const expression = unwrapModuleExpression(initializer);
102
+ if (!ts.isCallExpression(expression)) return undefined;
103
+ const isRequire = ts.isIdentifier(expression.expression) && expression.expression.text === 'require';
104
+ const isStaticImport = expression.expression.kind === ts.SyntaxKind.ImportKeyword;
105
+ if (!isRequire && !isStaticImport) return undefined;
106
+ const module = expression.arguments[0];
107
+ return module !== undefined && (ts.isStringLiteral(module) || ts.isNoSubstitutionTemplateLiteral(module))
108
+ ? moduleKind(module.text)
109
+ : undefined;
110
+ }
111
+
112
+ function bindVariableDeclaration(node, scopes) {
113
+ const scope = scopeForVariable(node);
114
+ const required = node.initializer === undefined ? undefined : initializerModuleKind(node.initializer);
115
+ for (const binding of bindingIdentifiers(node.name)) addScopeBinding(scopes, scope, binding.name, node, required);
116
+ if (required === undefined || !ts.isObjectBindingPattern(node.name)) return;
117
+ for (const element of node.name.elements) {
118
+ const original = element.propertyName && ts.isIdentifier(element.propertyName)
119
+ ? element.propertyName.text
120
+ : bindingName(element.name);
121
+ const alias = bindingName(element.name);
122
+ if (original === undefined || alias === undefined) continue;
123
+ const kind = required === 'fs'
124
+ ? original === 'promises' ? 'fsPromises' : FS_METHODS.has(original) ? `fsFunction:${original}` : undefined
125
+ : PATH_METHODS.has(original) ? `pathFunction:${original}` : undefined;
126
+ addScopeBinding(scopes, scope, alias, node, kind);
127
+ }
128
+ }
129
+
130
+ function declarationScope(node) {
131
+ for (let current = node.parent; current !== undefined; current = current.parent) {
132
+ if (ts.isSourceFile(current) || ts.isBlock(current) || ts.isModuleBlock(current) || ts.isCaseBlock(current)) return current;
133
+ }
134
+ return node.getSourceFile();
135
+ }
136
+
137
+ function collectScopes(sourceFile) {
138
+ const scopes = scopeBindings();
139
+ for (const statement of sourceFile.statements) bindImport(statement, scopes);
140
+
141
+ const visit = (node) => {
142
+ if (ts.isVariableDeclaration(node) && !ts.isCatchClause(node.parent)) bindVariableDeclaration(node, scopes);
143
+ if (ts.isFunctionLike(node)) {
144
+ for (const parameter of node.parameters) {
145
+ for (const binding of bindingIdentifiers(parameter.name)) addScopeBinding(scopes, node, binding.name, parameter);
146
+ }
147
+ }
148
+ if ((ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.name !== undefined) {
149
+ addScopeBinding(scopes, declarationScope(node), node.name.text, node);
150
+ }
151
+ if ((ts.isFunctionExpression(node) || ts.isClassExpression(node)) && node.name !== undefined) {
152
+ addScopeBinding(scopes, node, node.name.text, node);
153
+ }
154
+ if (ts.isCatchClause(node) && node.variableDeclaration) {
155
+ for (const binding of bindingIdentifiers(node.variableDeclaration.name)) addScopeBinding(scopes, node, binding.name, node.variableDeclaration);
156
+ }
157
+ ts.forEachChild(node, visit);
158
+ };
159
+ visit(sourceFile);
160
+ return scopes;
161
+ }
162
+
163
+ function resolveBindingKind(identifier, fromNode, scopes, seen = new Set()) {
164
+ if (seen.has(identifier)) return undefined;
165
+ seen.add(identifier);
166
+ const binding = getVisibleBinding(identifier, fromNode, scopes);
167
+ if (binding === undefined) return undefined;
168
+ if (binding.kind !== undefined) return binding.kind;
169
+ if (!ts.isVariableDeclaration(binding.node) || binding.node.initializer === undefined) return undefined;
170
+ const init = binding.node.initializer;
171
+ const required = initializerModuleKind(init);
172
+ if (required !== undefined) return required;
173
+ if (ts.isIdentifier(init)) return resolveBindingKind(init.text, binding.node, scopes, seen);
174
+ if (ts.isPropertyAccessExpression(init) && ts.isIdentifier(init.expression)) {
175
+ const ownerKind = resolveBindingKind(init.expression.text, binding.node, scopes, seen);
176
+ if (ownerKind === 'fs' && init.name.text === 'promises') return 'fsPromises';
177
+ if (ownerKind === 'fs' && FS_METHODS.has(init.name.text)) return `fsFunction:${init.name.text}`;
178
+ if (ownerKind === 'path' && PATH_METHODS.has(init.name.text)) return `pathFunction:${init.name.text}`;
179
+ }
180
+ return undefined;
181
+ }
182
+
183
+ function staticString(expression, fromNode, scopes, seen = new Set()) {
184
+ if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) return expression.text;
185
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isSatisfiesExpression(expression)) {
186
+ return staticString(expression.expression, fromNode, scopes, seen);
187
+ }
188
+ if (!ts.isIdentifier(expression) || seen.has(expression.text)) return undefined;
189
+ seen.add(expression.text);
190
+ const binding = getVisibleBinding(expression.text, fromNode, scopes);
191
+ if (binding === undefined || !ts.isVariableDeclaration(binding.node) || binding.node.initializer === undefined) return undefined;
192
+ const flags = ts.isVariableDeclarationList(binding.node.parent) ? binding.node.parent.flags : 0;
193
+ if ((flags & ts.NodeFlags.Const) === 0) return undefined;
194
+ return staticString(binding.node.initializer, binding.node, scopes, seen);
195
+ }
196
+
197
+ function fsPathKind(value) {
198
+ return value.startsWith('/') || value.startsWith('\\') || DRIVE_PATH.test(value) || /^file:/i.test(value) ? 'absolute' : 'relative';
199
+ }
200
+
201
+ function recognizedPathMethod(call, context, scopes) {
202
+ if (!ts.isCallExpression(call)) return undefined;
203
+ const expression = call.expression;
204
+ if (ts.isIdentifier(expression)) {
205
+ const kind = resolveBindingKind(expression.text, context, scopes);
206
+ return kind?.startsWith('pathFunction:') ? kind.slice('pathFunction:'.length) : undefined;
207
+ }
208
+ if (!ts.isPropertyAccessExpression(expression)) return undefined;
209
+ const method = expression.name.text;
210
+ if (!PATH_METHODS.has(method) || !ts.isIdentifier(expression.expression)) return undefined;
211
+ return resolveBindingKind(expression.expression.text, context, scopes) === 'path' ? method : undefined;
212
+ }
213
+
214
+ function analyzeFilePath(expression, context, scopes, seen = new Set()) {
215
+ const value = staticString(expression, context, scopes);
216
+ if (value !== undefined) return { pathKind: fsPathKind(value), value };
217
+
218
+ if (ts.isIdentifier(expression) && !seen.has(expression.text)) {
219
+ seen.add(expression.text);
220
+ const binding = getVisibleBinding(expression.text, context, scopes);
221
+ if (binding === undefined || !ts.isVariableDeclaration(binding.node) || binding.node.initializer === undefined) return undefined;
222
+ const flags = ts.isVariableDeclarationList(binding.node.parent) ? binding.node.parent.flags : 0;
223
+ if ((flags & ts.NodeFlags.Const) === 0) return undefined;
224
+ return analyzeFilePath(binding.node.initializer, binding.node, scopes, seen);
225
+ }
226
+
227
+ const method = recognizedPathMethod(expression, context, scopes);
228
+ if (method === undefined) return undefined;
229
+ const [base, ...parts] = expression.arguments;
230
+ if (base === undefined) return { pathKind: 'relative', value: expression.getText() };
231
+ const baseValue = staticString(base, expression, scopes);
232
+ if (baseValue !== undefined) return { pathKind: fsPathKind(baseValue), value: expression.getText() };
233
+ for (const part of parts) {
234
+ const partValue = staticString(part, expression, scopes);
235
+ if (partValue !== undefined && fsPathKind(partValue) === 'absolute') return { pathKind: 'absolute', value: expression.getText() };
236
+ }
237
+ return { explicitBase: true };
238
+ }
239
+
240
+ function httpCallKind(expression) {
241
+ const chain = propertyChain(expression);
242
+ const method = chain.at(-1);
243
+ if (chain.length === 1 && method === 'fetch') return { callee: 'fetch', allowExternal: true };
244
+ if (chain.length === 2 && chain[0] === 'ctx' && method === 'navigate') return { callee: 'ctx.navigate', allowExternal: false };
245
+ if (HTTP_METHODS.has(method) && chain.at(-2) === 'http' && (chain.length === 2 || (chain.length === 3 && chain[0] === 'ctx'))) {
246
+ return { callee: `${chain.length === 3 ? 'ctx.' : ''}http.${method}`, allowExternal: true };
247
+ }
248
+ return undefined;
249
+ }
250
+
251
+ function propertyChain(node) {
252
+ const segments = [];
253
+ let current = node;
254
+ while (ts.isPropertyAccessExpression(current)) {
255
+ segments.unshift(current.name.text);
256
+ current = current.expression;
257
+ }
258
+ if (ts.isIdentifier(current)) segments.unshift(current.text);
259
+ return segments;
260
+ }
261
+
262
+ function fsCallKind(expression, context, scopes) {
263
+ if (ts.isIdentifier(expression)) {
264
+ const kind = resolveBindingKind(expression.text, context, scopes);
265
+ return kind?.startsWith('fsFunction:') ? kind.slice('fsFunction:'.length) : undefined;
266
+ }
267
+ if (!ts.isPropertyAccessExpression(expression)) return undefined;
268
+ const method = expression.name.text;
269
+ if (!FS_METHODS.has(method)) return undefined;
270
+ if (ts.isIdentifier(expression.expression)) {
271
+ const kind = resolveBindingKind(expression.expression.text, context, scopes);
272
+ return kind === 'fs' || kind === 'fsPromises' ? method : undefined;
273
+ }
274
+ if (ts.isPropertyAccessExpression(expression.expression)
275
+ && ts.isIdentifier(expression.expression.expression)
276
+ && expression.expression.name.text === 'promises'
277
+ && resolveBindingKind(expression.expression.expression.text, context, scopes) === 'fs') return method;
278
+ if (ts.isCallExpression(expression.expression) && initializerModuleKind(expression.expression) === 'fs') return method;
279
+ return undefined;
280
+ }
281
+
282
+ function pathArgumentIndexes(method) {
283
+ if (method === 'copyFile' || method === 'copyFileSync' || method === 'rename' || method === 'renameSync') return [0, 1];
284
+ return [0];
285
+ }
286
+
287
+ function scriptKindFor(fileName) {
288
+ const extension = typeof fileName === 'string' ? /\.([^.\\/]+)$/.exec(fileName)?.[1]?.toLowerCase() : undefined;
289
+ if (extension === 'tsx') return ts.ScriptKind.TSX;
290
+ if (extension === 'jsx') return ts.ScriptKind.JSX;
291
+ if (extension === 'js' || extension === 'mjs' || extension === 'cjs') return ts.ScriptKind.JS;
292
+ return ts.ScriptKind.TS;
293
+ }
294
+
295
+ /** TypeScript AST 扫描器;URL 规则经回调注入,G100 可只消费文件系统结果。 */
296
+ export function scanPathSourceUsages(source, options = {}) {
297
+ const fileName = options.fileName ?? 'source-path-check.ts';
298
+ const sourceFile = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, scriptKindFor(fileName));
299
+ const scopes = collectScopes(sourceFile);
300
+ const issues = [];
301
+
302
+ const visit = (node) => {
303
+ if (ts.isCallExpression(node)) {
304
+ const urlCall = httpCallKind(node.expression);
305
+ const url = node.arguments[0];
306
+ if (urlCall !== undefined && url !== undefined && options.isInvalidUrl !== undefined) {
307
+ const value = staticString(url, node, scopes);
308
+ if (value !== undefined && options.isInvalidUrl(value, urlCall.allowExternal)) {
309
+ issues.push({ kind: 'url', index: node.getStart(sourceFile), callee: urlCall.callee, value });
310
+ }
311
+ }
312
+
313
+ const fsMethod = fsCallKind(node.expression, node, scopes);
314
+ if (fsMethod !== undefined) {
315
+ for (const index of pathArgumentIndexes(fsMethod)) {
316
+ const expression = node.arguments[index];
317
+ if (expression === undefined) continue;
318
+ const result = analyzeFilePath(expression, node, scopes);
319
+ if (result === undefined || result.explicitBase === true) continue;
320
+ issues.push({
321
+ kind: 'filesystem',
322
+ pathKind: result.pathKind,
323
+ index: node.getStart(sourceFile),
324
+ callee: node.expression.getText(sourceFile),
325
+ value: result.value,
326
+ });
327
+ }
328
+ }
329
+ }
330
+ ts.forEachChild(node, visit);
331
+ };
332
+ visit(sourceFile);
333
+ return issues;
334
+ }