soma-core 2.2.6 → 2.2.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 (59) hide show
  1. package/core/build/compiler/soma-precompile.js +66 -10
  2. package/core/client/container/IContainerAdapter.ts +4 -0
  3. package/core/client/container/SomaContainerAdapter.ts +43 -2
  4. package/core/client/data/data-object-resolver.ts +7 -3
  5. package/core/client/engine/event-engine.ts +28 -3
  6. package/core/client/engine/soma-bootstrap.ts +2 -1
  7. package/core/client/infra/notify/DefaultNotifyService.ts +2 -2
  8. package/core/client/parser/confirm-spec.ts +99 -6
  9. package/core/client/parser/data-config-parser.ts +1 -1
  10. package/core/client/parser/pipeline-parser.ts +2 -1
  11. package/core/client/render-ports/hide-transition.ts +9 -0
  12. package/core/client/render-ports/index.ts +4 -0
  13. package/core/client/render-ports/notify-renderer.ts +2 -1
  14. package/core/index.ts +16 -4
  15. package/core/server/api/load-host-service.ts +3 -0
  16. package/core/server/api/paged-list.ts +259 -0
  17. package/core/server/host/empty-host-bootstrap.mjs +3 -0
  18. package/core/server/host/host-assembly.ts +3 -0
  19. package/core/server/host/source-aliases.cjs +345 -0
  20. package/core/server/host/source-aliases.ts +32 -0
  21. package/core/server/host/source-packages.cjs +1 -0
  22. package/core/server/infra/cache/ServerFileCache.ts +4 -1
  23. package/core/server/node.ts +10 -0
  24. package/core/server/runtime-space/inject.ts +4 -1
  25. package/core/shared/core-diagnostic-codes.ts +6 -0
  26. package/core/shared/data-declaration-checks.ts +29 -3
  27. package/core/shared/registry-generated/diagnostic-registry-index.ts +5 -0
  28. package/core/shared/registry-generated/diagnostic-registry.ts +35 -0
  29. package/core/shared/registry-generated/limits.ts +18 -2
  30. package/core/shared/registry-generated/std-grammar.ts +1 -1
  31. package/core/shared/types/data-config.types.ts +3 -1
  32. package/core/shared/types/event.types.ts +9 -0
  33. package/dist/browser/soma-runtime.js +169 -19
  34. package/dist/core/index.cjs +190 -19
  35. package/dist/host-native/aot-builder.cjs +284 -0
  36. package/dist/host-native/native-server.cjs +344 -10
  37. package/dist/lsp/component-tree.cjs +66 -10
  38. package/dist/types/client/container/IContainerAdapter.d.ts +3 -0
  39. package/dist/types/client/container/SomaContainerAdapter.d.ts +5 -0
  40. package/dist/types/client/data/data-object-resolver.d.ts +2 -0
  41. package/dist/types/client/parser/confirm-spec.d.ts +27 -3
  42. package/dist/types/client/render-ports/hide-transition.d.ts +9 -0
  43. package/dist/types/client/render-ports/index.d.ts +4 -0
  44. package/dist/types/client/render-ports/notify-renderer.d.ts +2 -1
  45. package/dist/types/index.d.ts +4 -4
  46. package/dist/types/server/api/paged-list.d.ts +101 -0
  47. package/dist/types/server/host/source-aliases.d.cts +53 -0
  48. package/dist/types/server/host/source-aliases.d.ts +30 -0
  49. package/dist/types/server/host/source-packages.d.cts +2 -0
  50. package/dist/types/server/node.d.ts +1 -0
  51. package/dist/types/shared/core-diagnostic-codes.d.ts +1 -1
  52. package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +30 -0
  53. package/dist/types/shared/registry-generated/limits.d.ts +14 -0
  54. package/dist/types/shared/registry-generated/std-grammar.d.ts +1 -1
  55. package/dist/types/shared/types/data-config.types.d.ts +3 -1
  56. package/dist/types/shared/types/event.types.d.ts +8 -0
  57. package/host-native/src/aot-builder.ts +23 -0
  58. package/host-native/styles/globals.css +30 -28
  59. package/package.json +13 -2
@@ -447,6 +447,7 @@ var require_source_packages = __commonJS({
447
447
  SOMA_SOURCE_PACKAGES_ENV,
448
448
  getSomaHostSourceRoot: getSomaHostSourceRoot2,
449
449
  getSomaHostApiRoot: getSomaHostApiRoot2,
450
+ resolveSafeChildRoot,
450
451
  clearSomaAssetSourcesCache,
451
452
  getSomaAssetSources,
452
453
  listSomaSourcePackageNames,
@@ -458,6 +459,274 @@ var require_source_packages = __commonJS({
458
459
  }
459
460
  });
460
461
 
462
+ // core/server/host/source-aliases.cjs
463
+ var require_source_aliases = __commonJS({
464
+ "core/server/host/source-aliases.cjs"(exports2, module2) {
465
+ "use strict";
466
+ var fs2 = require("node:fs");
467
+ var path2 = require("node:path");
468
+ var nodeModule = require("node:module");
469
+ var { getSomaHostApiRoot: getSomaHostApiRoot2, getSomaHostSourceRoot: getSomaHostSourceRoot2, resolveSafeChildRoot } = require_source_packages();
470
+ var CODE_INVALID = "CORE-HOST-ALIAS-INVALID";
471
+ var CODE_RESERVED = "CORE-HOST-ALIAS-RESERVED";
472
+ var CODE_SHADOW = "CORE-HOST-ALIAS-SHADOW";
473
+ var CODE_DUPLICATE = "CORE-HOST-ALIAS-DUPLICATE";
474
+ var CODE_TSCONFIG_DRIFT = "CORE-HOST-ALIAS-TSCONFIG-DRIFT";
475
+ var ALIAS_NAME_RE = /^[A-Za-z0-9_][A-Za-z0-9._-]*$/;
476
+ var RESERVED_NAMES = /* @__PURE__ */ new Set(["server-only", "node_modules", "soma"]);
477
+ var BUILTIN_WITH_SUBPATH = new Set(
478
+ nodeModule.builtinModules.filter((m) => m.includes("/")).map((m) => m.slice(0, m.indexOf("/")))
479
+ );
480
+ var MAX_CACHE = 64;
481
+ var resolveCache = /* @__PURE__ */ new Map();
482
+ var warned = /* @__PURE__ */ new Set();
483
+ function clearSomaSourceRootCache() {
484
+ resolveCache.clear();
485
+ warned.clear();
486
+ }
487
+ function readJson(filePath) {
488
+ try {
489
+ if (!fs2.existsSync(filePath)) return null;
490
+ return JSON.parse(fs2.readFileSync(filePath, "utf8"));
491
+ } catch {
492
+ return null;
493
+ }
494
+ }
495
+ function readTsconfig(filePath) {
496
+ let raw;
497
+ try {
498
+ raw = fs2.readFileSync(filePath, "utf8");
499
+ } catch {
500
+ return null;
501
+ }
502
+ const stripped = raw.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
503
+ try {
504
+ return JSON.parse(stripped);
505
+ } catch {
506
+ return null;
507
+ }
508
+ }
509
+ function reservedReason(name) {
510
+ if (name === "soma" || name.startsWith("soma-")) return "\u4E0E soma \u516C\u5F00\u5305\u540D\u7A7A\u95F4\u51B2\u7A81";
511
+ if (RESERVED_NAMES.has(name)) return "\u662F\u4FDD\u7559\u540D";
512
+ if (BUILTIN_WITH_SUBPATH.has(name)) return `\u4F1A\u52AB\u6301 Node \u5185\u7F6E\u5B50\u8DEF\u5F84\uFF08\u5982 ${name}/...\uFF09`;
513
+ return null;
514
+ }
515
+ function realInside(parent, child) {
516
+ try {
517
+ const p = fs2.realpathSync(parent);
518
+ const c = fs2.realpathSync(child);
519
+ return c === p || c.startsWith(`${p}${path2.sep}`);
520
+ } catch {
521
+ return false;
522
+ }
523
+ }
524
+ function resolveSomaSourceRoots(hostDir, env = process.env) {
525
+ let normalizedHostDir = path2.resolve(hostDir);
526
+ if (!fs2.existsSync(path2.join(normalizedHostDir, "package.json"))) {
527
+ for (let dir = path2.dirname(normalizedHostDir); ; dir = path2.dirname(dir)) {
528
+ if (fs2.existsSync(path2.join(dir, "package.json"))) {
529
+ normalizedHostDir = dir;
530
+ break;
531
+ }
532
+ if (path2.dirname(dir) === dir) break;
533
+ }
534
+ }
535
+ const packageJsonPath = path2.join(normalizedHostDir, "package.json");
536
+ const stat = fs2.statSync(packageJsonPath, { throwIfNoEntry: false });
537
+ const cacheKey = `${normalizedHostDir}\0${env?.SOMA_API_DIR ?? ""}\0${env?.SOMA_WEB_DIR ?? ""}\0${stat ? `${stat.mtimeMs}:${stat.size}` : "none"}`;
538
+ const cached = resolveCache.get(cacheKey);
539
+ if (cached) return cached;
540
+ const result = compute(normalizedHostDir, env, readJson(packageJsonPath));
541
+ if (resolveCache.size >= MAX_CACHE) resolveCache.delete(resolveCache.keys().next().value);
542
+ resolveCache.set(cacheKey, result);
543
+ return result;
544
+ }
545
+ function compute(hostDir, env, packageJson) {
546
+ const diagnostics = [];
547
+ const raw = packageJson?.soma?.sourceRoots;
548
+ const empty = { declared: false, entries: [], aliases: {}, diagnostics };
549
+ if (raw === void 0 || raw === null) return empty;
550
+ const invalid = (message) => diagnostics.push({ code: CODE_INVALID, severity: "error", message: `soma.sourceRoots ${message}` });
551
+ const candidates = [];
552
+ let firstRoot = null;
553
+ const addRoot = (rootDir) => {
554
+ if (firstRoot === null) firstRoot = rootDir;
555
+ let children;
556
+ try {
557
+ children = fs2.readdirSync(rootDir, { withFileTypes: true });
558
+ } catch {
559
+ invalid(`\u7684\u6E90\u7801\u6839\u4E0D\u53EF\u8BFB\uFF1A${rootDir}`);
560
+ return;
561
+ }
562
+ for (const entry of children.sort((a, b) => a.name.localeCompare(b.name))) {
563
+ const full = path2.join(rootDir, entry.name);
564
+ const isDir = entry.isDirectory() || entry.isSymbolicLink() && fs2.statSync(full, { throwIfNoEntry: false })?.isDirectory();
565
+ if (!isDir || entry.name.startsWith(".") || entry.name === "node_modules" || !ALIAS_NAME_RE.test(entry.name)) continue;
566
+ candidates.push({ name: entry.name, dir: full });
567
+ }
568
+ };
569
+ const safeRoot = (rel) => {
570
+ if (typeof rel !== "string" || !rel.trim() || rel.includes("\0")) {
571
+ invalid("\u7684\u8DEF\u5F84\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32");
572
+ return null;
573
+ }
574
+ const resolved = path2.resolve(hostDir, rel.trim());
575
+ const safe = resolveSafeChildRoot(hostDir, rel);
576
+ if (safe !== resolved || !fs2.existsSync(safe) || !fs2.statSync(safe).isDirectory() || !realInside(hostDir, safe)) {
577
+ invalid(`\u7684\u8DEF\u5F84 "${rel}" \u5FC5\u987B\u662F\u5BBF\u4E3B\u76EE\u5F55\u5185\u5DF2\u5B58\u5728\u7684\u76EE\u5F55`);
578
+ return null;
579
+ }
580
+ return safe;
581
+ };
582
+ if (raw === "auto") {
583
+ const apiRoot = getSomaHostApiRoot2(hostDir, env);
584
+ addRoot(apiRoot);
585
+ } else if (typeof raw === "string" || Array.isArray(raw)) {
586
+ for (const rel of Array.isArray(raw) ? raw : [raw]) {
587
+ const root = safeRoot(rel);
588
+ if (root) addRoot(root);
589
+ }
590
+ } else if (typeof raw === "object") {
591
+ for (const [name, rel] of Object.entries(raw)) {
592
+ if (!ALIAS_NAME_RE.test(name)) {
593
+ diagnostics.push({ code: CODE_INVALID, severity: "error", name, message: `\u522B\u540D "${name}" \u4E0D\u5408\u6CD5\uFF08\u53EA\u5141\u8BB8\u5B57\u6BCD\u6570\u5B57 _ . -\uFF0C\u4E14\u4E0D\u542B\u659C\u6760\uFF09` });
594
+ continue;
595
+ }
596
+ const dir = safeRoot(rel);
597
+ if (dir) candidates.push({ name, dir });
598
+ }
599
+ } else {
600
+ invalid('\u5FC5\u987B\u662F "auto"\u3001\u76EE\u5F55\u5B57\u7B26\u4E32\u3001\u5B57\u7B26\u4E32\u6570\u7EC4\u6216\u300C\u522B\u540D \u2192 \u76EE\u5F55\u300D\u5BF9\u8C61');
601
+ return { ...empty, declared: true };
602
+ }
603
+ const entries = [];
604
+ const taken = /* @__PURE__ */ new Map();
605
+ for (const candidate of candidates) {
606
+ const reason = reservedReason(candidate.name);
607
+ if (reason) {
608
+ diagnostics.push({
609
+ code: CODE_RESERVED,
610
+ severity: "error",
611
+ name: candidate.name,
612
+ message: `\u6E90\u7801\u6839\u522B\u540D "${candidate.name}" ${reason}\uFF0C\u8BF7\u628A\u8BE5\u76EE\u5F55\u6539\u540D\u6216\u79FB\u51FA\u6E90\u7801\u6839`
613
+ });
614
+ continue;
615
+ }
616
+ if (taken.has(candidate.name)) {
617
+ diagnostics.push({
618
+ code: CODE_DUPLICATE,
619
+ severity: "warning",
620
+ name: candidate.name,
621
+ message: `\u6E90\u7801\u6839\u522B\u540D "${candidate.name}" \u540C\u65F6\u51FA\u73B0\u5728 ${taken.get(candidate.name)} \u4E0E ${candidate.dir}\uFF0C\u5148\u58F0\u660E\u8005\u751F\u6548`
622
+ });
623
+ continue;
624
+ }
625
+ taken.set(candidate.name, candidate.dir);
626
+ entries.push(candidate);
627
+ }
628
+ for (const { name, dir } of entries) {
629
+ const installed = path2.join(hostDir, "node_modules", name);
630
+ const installedStat = fs2.lstatSync(installed, { throwIfNoEntry: false });
631
+ if (!installedStat) continue;
632
+ let same = false;
633
+ try {
634
+ same = fs2.realpathSync(installed) === fs2.realpathSync(dir);
635
+ } catch {
636
+ same = false;
637
+ }
638
+ if (!same) {
639
+ diagnostics.push({
640
+ code: CODE_SHADOW,
641
+ severity: "warning",
642
+ name,
643
+ message: `\u6E90\u7801\u6839\u522B\u540D "${name}" \u906E\u853D\u4E86\u5DF2\u5B89\u88C5\u7684\u5305 node_modules/${name}\uFF1A\u5BBF\u4E3B\u4EE3\u7801\u91CC\u7684 "${name}/..." \u4E00\u5F8B\u89E3\u6790\u5230 ${dir}\uFF08\u58F0\u660E\u7684\u522B\u540D\u4F18\u5148\u4E8E\u5DF2\u88C5\u5305\uFF09`
644
+ });
645
+ }
646
+ }
647
+ if (firstRoot !== null) {
648
+ const tsconfig = readTsconfig(path2.join(hostDir, "tsconfig.json"));
649
+ const baseUrl = tsconfig?.compilerOptions?.baseUrl;
650
+ if (typeof baseUrl === "string" && path2.resolve(hostDir, baseUrl) !== path2.resolve(firstRoot)) {
651
+ diagnostics.push({
652
+ code: CODE_TSCONFIG_DRIFT,
653
+ severity: "warning",
654
+ message: `tsconfig.json \u7684 baseUrl\uFF08${baseUrl}\uFF09\u4E0E soma.sourceRoots \u7684\u6E90\u7801\u6839\uFF08${path2.relative(hostDir, firstRoot) || "."}\uFF09\u4E0D\u4E00\u81F4\uFF1A\u7F16\u8F91\u5668\u4E0E\u8FD0\u884C\u671F\u4F1A\u89E3\u6790\u5230\u4E0D\u540C\u76EE\u5F55`
655
+ });
656
+ }
657
+ }
658
+ const aliases = {};
659
+ for (const { name, dir } of entries) aliases[name] = dir;
660
+ return { declared: true, entries, aliases, diagnostics };
661
+ }
662
+ function formatDiagnostic(d) {
663
+ return `[soma-core][${d.code}] ${d.message}`;
664
+ }
665
+ function getSomaSourceRootAliases2(hostDir, env = process.env) {
666
+ const resolved = resolveSomaSourceRoots(hostDir, env);
667
+ const errors = resolved.diagnostics.filter((d) => d.severity === "error");
668
+ if (errors.length > 0) {
669
+ const error = new Error(errors.map(formatDiagnostic).join("\n"));
670
+ error.code = errors[0].code;
671
+ error.diagnostics = errors;
672
+ throw error;
673
+ }
674
+ for (const d of resolved.diagnostics) {
675
+ const key = `${path2.resolve(hostDir)}\0${d.code}\0${d.name ?? ""}\0${d.message}`;
676
+ if (warned.has(key)) continue;
677
+ warned.add(key);
678
+ console.warn(`[soma-core][\u5F15\u64CE] ${d.code} ${d.message}`);
679
+ }
680
+ return { ...resolved.aliases };
681
+ }
682
+ function matchSomaSourceRoot2(aliases, specifier) {
683
+ if (typeof specifier !== "string") return null;
684
+ const slash = specifier.indexOf("/");
685
+ if (slash <= 0) return null;
686
+ const name = specifier.slice(0, slash);
687
+ const dir = Object.prototype.hasOwnProperty.call(aliases, name) ? aliases[name] : void 0;
688
+ if (dir === void 0) return null;
689
+ return { name, dir, subpath: specifier.slice(slash + 1) };
690
+ }
691
+ function somaSourceRootFilter2(aliases) {
692
+ const names = Object.keys(aliases);
693
+ if (names.length === 0) return null;
694
+ return new RegExp(`^(?:${names.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})/`);
695
+ }
696
+ function somaViteAliases(hostDir, env = process.env) {
697
+ return Object.entries(getSomaSourceRootAliases2(hostDir, env)).map(([name, dir]) => ({
698
+ find: new RegExp(`^${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/`),
699
+ replacement: `${dir.split(path2.sep).join("/")}/`
700
+ }));
701
+ }
702
+ var HOST_BOOTSTRAP_SPECIFIER = "@soma-host/bootstrap/soma-bootstrap";
703
+ var HOST_BOOTSTRAP_CANDIDATES = ["soma-bootstrap.ts", "soma-bootstrap.js", "soma-bootstrap.mjs"];
704
+ function somaViteHostAliases(hostDir, env = process.env) {
705
+ const sourceRoot = getSomaHostSourceRoot2(path2.resolve(hostDir), env);
706
+ const found = HOST_BOOTSTRAP_CANDIDATES.map((name) => path2.join(sourceRoot, "bootstrap", name)).find((file) => fs2.existsSync(file));
707
+ const target = found ?? path2.join(__dirname, "empty-host-bootstrap.mjs");
708
+ return [
709
+ ...somaViteAliases(hostDir, env),
710
+ { find: new RegExp(`^${HOST_BOOTSTRAP_SPECIFIER}$`), replacement: target.split(path2.sep).join("/") }
711
+ ];
712
+ }
713
+ module2.exports = {
714
+ somaViteHostAliases,
715
+ CODE_INVALID,
716
+ CODE_RESERVED,
717
+ CODE_SHADOW,
718
+ CODE_DUPLICATE,
719
+ CODE_TSCONFIG_DRIFT,
720
+ clearSomaSourceRootCache,
721
+ resolveSomaSourceRoots,
722
+ getSomaSourceRootAliases: getSomaSourceRootAliases2,
723
+ matchSomaSourceRoot: matchSomaSourceRoot2,
724
+ somaSourceRootFilter: somaSourceRootFilter2,
725
+ somaViteAliases
726
+ };
727
+ }
728
+ });
729
+
461
730
  // host-native/src/aot-builder.ts
462
731
  var aot_builder_exports = {};
463
732
  __export(aot_builder_exports, {
@@ -478,6 +747,19 @@ function toPascalCase(str) {
478
747
 
479
748
  // host-native/src/aot-builder.ts
480
749
  var import_source_packages = __toESM(require_source_packages());
750
+ var import_source_aliases = __toESM(require_source_aliases());
751
+ function registerSourceRootResolve(build, hostDir, env) {
752
+ const aliases = (0, import_source_aliases.getSomaSourceRootAliases)(hostDir, env);
753
+ const filter = (0, import_source_aliases.somaSourceRootFilter)(aliases);
754
+ if (!filter) return;
755
+ const nodeModulesSegment = `${import_node_path.default.sep}node_modules${import_node_path.default.sep}`;
756
+ build.onResolve({ filter }, (args) => {
757
+ if (args.importer.includes(nodeModulesSegment)) return void 0;
758
+ const hit = (0, import_source_aliases.matchSomaSourceRoot)(aliases, args.path);
759
+ if (!hit) return void 0;
760
+ return { path: resolveModuleFile(hit.dir, hit.subpath) };
761
+ });
762
+ }
481
763
  function resolveModuleFile(baseDir, subpath) {
482
764
  const target = subpath ? import_node_path.default.resolve(baseDir, subpath) : import_node_path.default.resolve(baseDir);
483
765
  for (const ext of ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]) {
@@ -569,6 +851,7 @@ function createBrowserClientPlugin(options) {
569
851
  }
570
852
  return { path: target };
571
853
  });
854
+ registerSourceRootResolve(build, hostDir);
572
855
  build.onResolve({ filter: /core\/client\/engine\// }, (args) => {
573
856
  if (!args.importer.includes("soma-core")) {
574
857
  throw new Error(
@@ -817,6 +1100,7 @@ async function buildServerAot(options) {
817
1100
  const subpath = args.path.replace(/^@soma-host\/?/, "");
818
1101
  return { path: resolveModuleFile(webRoot, subpath) };
819
1102
  });
1103
+ registerSourceRootResolve(build, hostDir, options.env);
820
1104
  build.onResolve({ filter: /^@soma-api(?:\/.*)?$/ }, (args) => {
821
1105
  const subpath = args.path.replace(/^@soma-api\/?/, "");
822
1106
  return { path: resolveModuleFile(apiRoot, subpath) };