soma-kit 0.1.11 → 0.1.13

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 (376) hide show
  1. package/README.md +106 -112
  2. package/bin/soma-kit.mjs +32 -2
  3. package/bin/soma.mjs +22 -0
  4. package/package.json +14 -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 +929 -37
  8. package/spec/generated/kit-page.schema.json +1684 -161
  9. package/spec/kit-grammar.json +1176 -584
  10. package/spec/kit-grammar.schema.json +1971 -393
  11. package/src/app/app-config.ts +449 -347
  12. package/src/app/component-gate.ts +283 -28
  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 +176 -33
  16. package/src/app/define-kit-view.ts +104 -0
  17. package/src/app/dev-diagnostic.ts +5 -0
  18. package/src/app/envelope.ts +1 -161
  19. package/src/app/index.ts +29 -6
  20. package/src/app/kit-view-context.ts +439 -0
  21. package/src/app/notify-renderer.ts +1 -115
  22. package/src/app/paged-list-adapter.ts +1 -240
  23. package/src/app/render-ports.ts +18 -0
  24. package/src/app/server-pages.ts +11 -3
  25. package/src/app/server.ts +530 -103
  26. package/src/app/submit.types.ts +1 -1
  27. package/src/app/theme-endpoint.ts +63 -0
  28. package/src/app/theme-runtime-shared.ts +1 -0
  29. package/src/app/theme-runtime.ts +667 -0
  30. package/src/base/action-busy.ts +103 -6
  31. package/src/base/action-gate.ts +4 -255
  32. package/src/base/action-slots.ts +58 -0
  33. package/src/base/alert.ts +5 -3
  34. package/src/base/anchored-layer.ts +50 -0
  35. package/src/base/avatar.ts +2 -2
  36. package/src/base/button.ts +99 -37
  37. package/src/base/cascader.ts +11 -12
  38. package/src/base/check-core.ts +9 -1
  39. package/src/base/checkbox.ts +2 -1
  40. package/src/base/choice.ts +49 -28
  41. package/src/base/class-candidates.ts +17 -0
  42. package/src/base/color-picker.ts +16 -11
  43. package/src/base/combobox.ts +5 -3
  44. package/src/base/command-palette.ts +10 -6
  45. package/src/base/context-menu.ts +10 -7
  46. package/src/base/countdown.ts +1 -1
  47. package/src/base/date-range.ts +32 -18
  48. package/src/base/date.ts +135 -28
  49. package/src/base/delta.ts +72 -0
  50. package/src/base/divider.ts +2 -2
  51. package/src/base/end-edge.ts +49 -0
  52. package/src/base/fab.ts +12 -5
  53. package/src/base/gap-value.ts +148 -0
  54. package/src/base/hint-tips.ts +170 -0
  55. package/src/base/icons.ts +8 -0
  56. package/src/base/illustrations.ts +94 -0
  57. package/src/base/image.ts +1 -1
  58. package/src/base/index.ts +35 -11
  59. package/src/base/input.ts +42 -13
  60. package/src/base/kbd.ts +3 -1
  61. package/src/base/link.ts +4 -4
  62. package/src/base/listbox-core.ts +56 -35
  63. package/src/base/loading-gate.ts +186 -0
  64. package/src/base/mentions.ts +7 -6
  65. package/src/base/menu-button.ts +28 -12
  66. package/src/base/menu-core.ts +41 -8
  67. package/src/base/motion/aura.ts +2 -2
  68. package/src/base/motion/hover-3d.ts +3 -3
  69. package/src/base/motion/hover-gallery.ts +2 -2
  70. package/src/base/motion/marquee.ts +3 -3
  71. package/src/base/motion/text-rotate.ts +2 -2
  72. package/src/base/number.ts +93 -80
  73. package/src/base/otp.ts +9 -5
  74. package/src/base/overlay-runtime.ts +235 -0
  75. package/src/base/permission-gate.ts +6 -0
  76. package/src/base/popover.ts +48 -16
  77. package/src/base/popup.ts +143 -19
  78. package/src/base/portal-core.ts +4 -0
  79. package/src/base/price-text.ts +2 -2
  80. package/src/base/progress.ts +2 -2
  81. package/src/base/qr-code.ts +4 -4
  82. package/src/base/qty-stepper.ts +14 -8
  83. package/src/base/radio.ts +2 -1
  84. package/src/base/range.ts +21 -4
  85. package/src/base/rating.ts +12 -7
  86. package/src/base/reason-tip.ts +150 -0
  87. package/src/base/segmented.ts +27 -21
  88. package/src/base/select.ts +4 -3
  89. package/src/base/shared.ts +387 -49
  90. package/src/base/state-panel.ts +346 -0
  91. package/src/base/status-tone.ts +27 -0
  92. package/src/base/sticky-edge.ts +116 -0
  93. package/src/base/swap.ts +10 -7
  94. package/src/base/switch.ts +11 -6
  95. package/src/base/tag-input.ts +20 -16
  96. package/src/base/tag.ts +68 -34
  97. package/src/base/text.ts +80 -18
  98. package/src/base/textarea.ts +37 -11
  99. package/src/base/time-picker.ts +18 -13
  100. package/src/base/tree-select.ts +21 -12
  101. package/src/base/trend-tone.ts +9 -0
  102. package/src/base/upload.ts +48 -14
  103. package/src/base/view-transition.ts +77 -0
  104. package/src/base/virtual-list.ts +107 -1
  105. package/src/biz/approval-desk/compile.ts +23 -41
  106. package/src/biz/approval-desk/shell.ts +11 -8
  107. package/src/biz/auth-panel/compile.ts +37 -52
  108. package/src/biz/auth-panel/index.ts +1 -1
  109. package/src/biz/auth-panel/shell.ts +5 -4
  110. package/src/biz/category-crud/compile.ts +23 -37
  111. package/src/biz/category-crud/shell.ts +2 -1
  112. package/src/biz/checkout-page/compile.ts +22 -5
  113. package/src/biz/checkout-page/shell.ts +4 -3
  114. package/src/biz/compose.ts +13 -27
  115. package/src/biz/define.ts +5 -4
  116. package/src/biz/import-wizard/compile.ts +22 -26
  117. package/src/biz/import-wizard/hub.ts +126 -61
  118. package/src/biz/import-wizard/shell.ts +5 -4
  119. package/src/biz/index.ts +3 -3
  120. package/src/biz/landing-page/compile.ts +19 -3
  121. package/src/biz/link/hub.ts +69 -22
  122. package/src/biz/link/shared.ts +127 -119
  123. package/src/biz/master-sub/compile.ts +127 -48
  124. package/src/biz/master-sub/index.ts +5 -2
  125. package/src/biz/master-sub/shell.ts +95 -18
  126. package/src/biz/multi-board/compile.ts +38 -50
  127. package/src/biz/multi-board/index.ts +18 -1
  128. package/src/biz/multi-board/shell.ts +32 -20
  129. package/src/biz/notification-center/compile.ts +21 -33
  130. package/src/biz/notification-center/shell.ts +6 -4
  131. package/src/biz/page-templates/domain-templates.ts +80 -13
  132. package/src/biz/page-templates/result-page/compile.ts +11 -2
  133. package/src/biz/page-templates/result-page/shell.ts +2 -1
  134. package/src/biz/page-templates/shared.ts +34 -36
  135. package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
  136. package/src/biz/record-detail/compile.ts +48 -43
  137. package/src/biz/record-detail/index.ts +11 -1
  138. package/src/biz/record-detail/shell.ts +8 -6
  139. package/src/biz/settings-center/compile.ts +7 -5
  140. package/src/biz/settings-center/shell.ts +6 -4
  141. package/src/biz/shared/action-host.ts +97 -211
  142. package/src/biz/shared/compile-helpers.ts +98 -0
  143. package/src/biz/shared/coordinator.ts +472 -92
  144. package/src/biz/shared/index.ts +13 -2
  145. package/src/biz/shared/object-aliases.ts +154 -0
  146. package/src/biz/shared/overlay-compile.ts +239 -0
  147. package/src/biz/shared/overlay-shell.ts +209 -0
  148. package/src/biz/shared/pipes.ts +50 -31
  149. package/src/biz/shared/remove-wire.ts +14 -0
  150. package/src/biz/shared/runtime-hub.ts +226 -24
  151. package/src/biz/single-form/compile.ts +16 -37
  152. package/src/biz/single-form/shell.ts +4 -3
  153. package/src/biz/standard-crud/compile.ts +72 -255
  154. package/src/biz/standard-crud/shell.ts +21 -99
  155. package/src/biz/step-form/compile.ts +26 -97
  156. package/src/biz/step-form/hub.ts +34 -41
  157. package/src/biz/step-form/shell.ts +5 -5
  158. package/src/biz/types.ts +4 -3
  159. package/src/cli/core-imports.ts +54 -0
  160. package/src/cli/kit-cli.ts +254 -25
  161. package/src/cli/kit-init.ts +227 -0
  162. package/src/cli/layout-cli.ts +167 -0
  163. package/src/cli/migrate/index.ts +10 -0
  164. package/src/cli/migrate/migrate.ts +248 -0
  165. package/src/cli/migrate/text-utils.ts +306 -0
  166. package/src/cli/migrate/theme-map.ts +104 -0
  167. package/src/cli/migrate/ts-rules.ts +235 -0
  168. package/src/cli/migrate/types.ts +95 -0
  169. package/src/cli/migrate/view-skeleton.ts +159 -0
  170. package/src/cli/migrate/yaml-report.ts +376 -0
  171. package/src/cli/migrate/yaml-rules.ts +465 -0
  172. package/src/cli/service-endpoint-check.ts +425 -0
  173. package/src/cli/source-path-check.d.mts +17 -0
  174. package/src/cli/source-path-check.mjs +334 -0
  175. package/src/cli/view-writes.ts +761 -0
  176. package/src/compile/action-host-attach.ts +21 -29
  177. package/src/compile/closed-set.ts +570 -0
  178. package/src/compile/compile-page.ts +267 -76
  179. package/src/compile/component-candidates.ts +13 -2
  180. package/src/compile/hints.ts +30 -1
  181. package/src/compile/index.ts +1 -0
  182. package/src/compile/kit-error.ts +1 -0
  183. package/src/compile/layout-lint/engine.ts +82 -0
  184. package/src/compile/layout-lint/index.ts +55 -0
  185. package/src/compile/layout-lint/rules-composition.ts +218 -0
  186. package/src/compile/layout-lint/rules-form.ts +192 -0
  187. package/src/compile/layout-lint/rules-table.ts +194 -0
  188. package/src/compile/layout-lint/score.ts +52 -0
  189. package/src/compile/layout-lint/types.ts +51 -0
  190. package/src/compile/locate.ts +21 -1
  191. package/src/compile/parse.ts +370 -41
  192. package/src/compile/redirect.ts +6 -2
  193. package/src/compile/remove-guard.ts +10 -7
  194. package/src/compile/styles.ts +63 -2
  195. package/src/compile/types.ts +31 -3
  196. package/src/compile/view-check.ts +284 -0
  197. package/src/data/amount-breakdown.ts +8 -3
  198. package/src/data/anchor-nav.ts +2 -2
  199. package/src/data/approval-flow.ts +3 -3
  200. package/src/data/assignment-picker.ts +92 -55
  201. package/src/data/async-result-panel.ts +111 -9
  202. package/src/data/breadcrumbs.ts +5 -4
  203. package/src/data/calendar.ts +24 -27
  204. package/src/data/carousel.ts +13 -8
  205. package/src/data/chart.ts +183 -44
  206. package/src/data/checklist.ts +20 -7
  207. package/src/data/code-view.ts +12 -6
  208. package/src/data/comment-thread.ts +7 -4
  209. package/src/data/confirm-dialog.ts +81 -18
  210. package/src/data/context-menu.ts +29 -37
  211. package/src/data/d9-util.ts +2 -18
  212. package/src/data/diff.ts +4 -2
  213. package/src/data/dock.ts +3 -3
  214. package/src/data/embed.ts +233 -30
  215. package/src/data/field-mapper.ts +35 -30
  216. package/src/data/flow-editor-contract.ts +8 -1
  217. package/src/data/flow-editor.ts +113 -108
  218. package/src/data/flow-node-options.ts +120 -0
  219. package/src/data/flow-remote-options.ts +0 -103
  220. package/src/data/footer.ts +2 -2
  221. package/src/data/form-draft-registry.ts +2 -4
  222. package/src/data/gantt.ts +19 -19
  223. package/src/data/hero.ts +4 -3
  224. package/src/data/image-viewer.ts +27 -30
  225. package/src/data/index.ts +5 -2
  226. package/src/data/item-list.ts +48 -31
  227. package/src/data/kanban.ts +82 -52
  228. package/src/data/media-grid.ts +20 -20
  229. package/src/data/mega-menu.ts +6 -4
  230. package/src/data/menu-dom.ts +4 -2
  231. package/src/data/menu.ts +47 -15
  232. package/src/data/mockup.ts +10 -6
  233. package/src/data/modal-dialog.ts +49 -25
  234. package/src/data/navbar.ts +12 -7
  235. package/src/data/notice-list.ts +268 -0
  236. package/src/data/notify-renderer.ts +250 -0
  237. package/src/data/object-form.ts +1360 -666
  238. package/src/data/outcome-watch.ts +61 -2
  239. package/src/data/pager.ts +80 -34
  240. package/src/data/permission-matrix.ts +52 -31
  241. package/src/data/permission-tree.ts +71 -44
  242. package/src/data/pricing-table.ts +30 -14
  243. package/src/data/prompt-dialog.ts +124 -194
  244. package/src/data/reaction-bar.ts +83 -92
  245. package/src/data/read-rollback.ts +73 -0
  246. package/src/data/record-card.ts +26 -5
  247. package/src/data/record-picker.ts +104 -55
  248. package/src/data/redirect.ts +32 -32
  249. package/src/data/remote-options.ts +13 -6
  250. package/src/data/request-console.ts +5 -3
  251. package/src/data/resident.ts +2 -1
  252. package/src/data/result-panel.ts +8 -4
  253. package/src/data/rich-text.ts +61 -55
  254. package/src/data/row-editor.ts +362 -76
  255. package/src/data/rule-builder.ts +26 -20
  256. package/src/data/shape-util.ts +27 -9
  257. package/src/data/stat-group.ts +392 -109
  258. package/src/data/static-lazy.ts +1 -0
  259. package/src/data/static-registry.ts +24 -11
  260. package/src/data/steps.ts +10 -5
  261. package/src/data/survey.ts +27 -32
  262. package/src/data/system-switcher.ts +3 -3
  263. package/src/data/text-action-button.ts +17 -0
  264. package/src/data/timeline.ts +19 -8
  265. package/src/data/tour-guide.ts +23 -30
  266. package/src/data/transfer.ts +62 -38
  267. package/src/data/tree-table.ts +152 -78
  268. package/src/data/tree.ts +49 -36
  269. package/src/data/trend-line.ts +6 -24
  270. package/src/data/virtual-rows.ts +133 -82
  271. package/src/data/watermark.ts +2 -2
  272. package/src/data/wrap.ts +63 -38
  273. package/src/data/wrapped-candidates.ts +10 -0
  274. package/src/frames/blank-frame.ts +1 -0
  275. package/src/frames/index.ts +2 -2
  276. package/src/frames/page-bar.ts +26 -24
  277. package/src/frames/page-header.ts +14 -5
  278. package/src/frames/page-status.ts +9 -7
  279. package/src/frames/shared.ts +36 -25
  280. package/src/frames/single-frame.ts +1 -0
  281. package/src/frames/split-frame/shell.ts +6 -6
  282. package/src/frames/split-frame/wiring.ts +2 -2
  283. package/src/frames/tabs-frame/shell.ts +4 -14
  284. package/src/frames/tabs-frame/wiring.ts +5 -8
  285. package/src/frames/top-main-frame.ts +3 -2
  286. package/src/frames/types.ts +13 -2
  287. package/src/frames/workspace-frame/extras.ts +21 -5
  288. package/src/frames/workspace-frame/index.ts +1 -1
  289. package/src/frames/workspace-frame/shell.ts +3 -2
  290. package/src/frames/workspace-frame/state.ts +13 -6
  291. package/src/frames/workspace-frame/view.ts +250 -48
  292. package/src/generated/kit-grammar-runtime.ts +645 -397
  293. package/src/generated/page-origin.ts +0 -11
  294. package/src/i18n/kit-text.ts +84 -29
  295. package/src/i18n/resolve-text-refs.ts +22 -6
  296. package/src/index.ts +2 -1
  297. package/src/object-renderer/action-gate.ts +11 -147
  298. package/src/object-renderer/arrange.ts +112 -84
  299. package/src/object-renderer/collapse-wiring.ts +2 -2
  300. package/src/object-renderer/collection-expand.ts +2 -2
  301. package/src/object-renderer/collection-parts.ts +401 -104
  302. package/src/object-renderer/collection-table.ts +287 -45
  303. package/src/object-renderer/collection.ts +258 -104
  304. package/src/object-renderer/compile-data.ts +112 -102
  305. package/src/object-renderer/crud-bridge.ts +32 -0
  306. package/src/object-renderer/defaults.ts +38 -16
  307. package/src/object-renderer/display-checks.ts +4 -25
  308. package/src/object-renderer/emit-events.ts +224 -176
  309. package/src/object-renderer/emit-object.ts +15 -2
  310. package/src/object-renderer/emit-static.ts +533 -151
  311. package/src/object-renderer/field-value.ts +593 -396
  312. package/src/object-renderer/filter-reload.ts +70 -0
  313. package/src/object-renderer/form-detail.ts +111 -2
  314. package/src/object-renderer/form-notify.ts +45 -0
  315. package/src/object-renderer/index.ts +26 -0
  316. package/src/object-renderer/key-field.ts +12 -0
  317. package/src/object-renderer/layout-facts.ts +386 -0
  318. package/src/object-renderer/layout-plan.ts +132 -0
  319. package/src/object-renderer/layout-plan.types.ts +22 -0
  320. package/src/object-renderer/linkage.ts +7 -270
  321. package/src/object-renderer/merge-class.ts +18 -1
  322. package/src/object-renderer/parts.ts +252 -1
  323. package/src/object-renderer/path-pick.ts +27 -0
  324. package/src/object-renderer/render-object.ts +456 -89
  325. package/src/object-renderer/request-actions.ts +232 -249
  326. package/src/object-renderer/skeleton.ts +58 -19
  327. package/src/object-renderer/table-actions.ts +319 -111
  328. package/src/object-renderer/table-summary.ts +2 -2
  329. package/src/object-renderer/table-tools.ts +429 -94
  330. package/src/object-renderer/types.ts +204 -127
  331. package/src/object-renderer/view-binding.ts +393 -0
  332. package/src/page-target/ai-surface.ts +37 -0
  333. package/src/page-target/compile.ts +48 -8
  334. package/src/page-target/index.ts +8 -1
  335. package/src/page-target/intent-schema.ts +165 -28
  336. package/src/page-target/target.ts +262 -51
  337. package/src/page-target/writer-policy.ts +14 -3
  338. package/src/recipes/container.ts +210 -0
  339. package/src/recipes/control.ts +277 -0
  340. package/src/recipes/index.ts +312 -0
  341. package/src/recipes/nowrap.ts +16 -0
  342. package/src/recipes/overlay.ts +240 -0
  343. package/src/recipes/placeholder.ts +79 -0
  344. package/src/recipes/rail-grid.ts +45 -0
  345. package/src/recipes/slot-align.ts +56 -0
  346. package/src/recipes/state.ts +99 -0
  347. package/src/recipes/status.ts +139 -0
  348. package/src/recipes/surface.ts +40 -0
  349. package/src/recipes/table-row.ts +88 -0
  350. package/src/recipes/title-row.ts +37 -0
  351. package/src/recipes/typography.ts +99 -0
  352. package/src/shared/action-field-guard.ts +41 -0
  353. package/src/shared/confirm-decl.ts +118 -0
  354. package/src/shared/envelope.ts +207 -0
  355. package/src/shared/escape.ts +57 -0
  356. package/src/shared/kit-error.ts +21 -0
  357. package/src/shared/paged-list-adapter.ts +15 -0
  358. package/src/shared/path-guard.ts +127 -0
  359. package/src/shared/theme-runtime-shared.ts +180 -0
  360. package/src/shared/view-info.ts +10 -0
  361. package/src/theme/index.ts +13 -0
  362. package/src/theme/kit-theme-text.ts +1 -1
  363. package/src/theme/kit-theme.css +407 -10
  364. package/src/theme/kit-theme.tpl +407 -10
  365. package/src/theme/nine-dim-structure.ts +247 -0
  366. package/src/theme/surface-layers.ts +101 -0
  367. package/src/theme/theme-tokens.ts +130 -84
  368. package/src/theme/theme-types.ts +103 -0
  369. package/src/theme/typography.ts +17 -17
  370. package/src/biz/shared/step-values.ts +0 -25
  371. package/src/biz/step-form/steps-ref.ts +0 -112
  372. package/src/data/options-bus.ts +0 -24
  373. package/src/object-renderer/adopt-gate.ts +0 -333
  374. package/src/object-renderer/field-policy.ts +0 -89
  375. package/src/object-renderer/outcome-draft.ts +0 -61
  376. package/src/theme/nine-dim-palettes.ts +0 -1473
@@ -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
+ }