soma-core 1.0.3 → 1.1.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.
- package/app/SomaPageClient.tsx +8 -45
- package/app/[...path]/page.tsx +21 -0
- package/app/api/[...path]/route.ts +86 -77
- package/app/components/SomaHostPage.tsx +133 -0
- package/app/components/SomaHydrationShell.tsx +1 -1
- package/app/layout.tsx +10 -6
- package/app/page.tsx +7 -18
- package/app/soma/[...path]/route.ts +9 -0
- package/app/{api/soma-manifest → soma/manifest}/route.ts +3 -3
- package/app/soma/page/route.ts +29 -0
- package/app/soma/page-object/route.ts +158 -0
- package/app/soma/route.ts +9 -0
- package/bin/soma-mock.mjs +38 -0
- package/core/base/SomaHttpClient.ts +5 -3
- package/core/compiler/full-manifest-builder.ts +84 -69
- package/core/compiler/host-config-sync.cjs +32 -6
- package/core/compiler/soma-manifest-webpack-plugin.js +41 -7
- package/core/engine/soma-headless-page.ts +86 -0
- package/core/host/app-config-composer.ts +90 -0
- package/core/host/host-config-paths.cjs +100 -0
- package/core/host/host-config-paths.ts +132 -0
- package/core/host/invoke-host-request-hook.ts +37 -0
- package/core/host/load-host-domain-class.ts +87 -0
- package/core/host/page-response-mode.cjs +96 -0
- package/core/host/page-response-request.ts +35 -0
- package/core/host/request-origin.ts +18 -0
- package/core/host/resolve-host-request-hook.ts +29 -0
- package/core/host/server-page-assets.ts +193 -0
- package/core/host/soma-domain-loaders.stub.ts +6 -0
- package/core/host/soma-domain-loaders.ts +69 -0
- package/core/host/soma-request-hook-host.stub.ts +4 -0
- package/core/host/source-packages.ts +46 -5
- package/core/index.ts +22 -0
- package/core/infra/http/SomaHttpService.ts +23 -14
- package/core/infra/http/soma-server-request-context.ts +126 -0
- package/core/mock/node/catch-all.mjs +35 -0
- package/core/mock/node/cli.d.mts +58 -0
- package/core/mock/node/cli.mjs +243 -0
- package/core/mock/node/context.mjs +167 -0
- package/core/mock/node/environment-policy.mjs +52 -0
- package/core/mock/node/plugin-loader.mjs +212 -0
- package/core/mock/node/preload.mjs +91 -0
- package/core/mock/node/process-lifecycle.mjs +236 -0
- package/core/mock/node/public.d.mts +110 -0
- package/core/mock/node/public.mjs +4 -0
- package/core/mock/node/registry.mjs +336 -0
- package/core/mock/node/schema-generator.mjs +1310 -0
- package/core/mock/testing/host-harness.d.mts +66 -0
- package/core/mock/testing/host-harness.mjs +276 -0
- package/core/mock/testing/host-runtime.mjs +48 -0
- package/core/runtime/SomaRuntimeServices.ts +5 -1
- package/core/runtime/serialize-page-state.ts +152 -0
- package/dist/cli/soma.js +374 -3
- package/dist/core/index.cjs +2861 -2388
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/base/SomaHttpClient.d.ts +2 -0
- package/dist/types/compiler/full-manifest-builder.d.ts +2 -0
- package/dist/types/engine/soma-headless-page.d.ts +10 -0
- package/dist/types/host/app-config-composer.d.ts +6 -0
- package/dist/types/host/host-config-paths.d.ts +23 -0
- package/dist/types/host/invoke-host-request-hook.d.ts +8 -0
- package/dist/types/host/load-host-domain-class.d.ts +12 -0
- package/dist/types/host/page-response-request.d.ts +9 -0
- package/dist/types/host/request-origin.d.ts +1 -0
- package/dist/types/host/resolve-host-request-hook.d.ts +16 -0
- package/dist/types/host/server-page-assets.d.ts +29 -0
- package/dist/types/host/soma-domain-loaders.d.ts +19 -0
- package/dist/types/host/soma-domain-loaders.stub.d.ts +4 -0
- package/dist/types/host/soma-request-hook-host.stub.d.ts +2 -0
- package/dist/types/host/source-packages.d.ts +4 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/infra/http/SomaHttpService.d.ts +2 -0
- package/dist/types/infra/http/soma-server-request-context.d.ts +5 -0
- package/dist/types/runtime/serialize-page-state.d.ts +10 -0
- package/docs//351/241/265/351/235/242JSON/346/250/241/345/274/217/346/216/245/345/205/245/346/214/207/345/215/227.md +141 -0
- package/global.d.ts +67 -26
- package/middleware.ts +33 -0
- package/next.config.js +109 -23
- package/package.json +39 -9
- package/tsconfig.json +1 -5
- package/app/api/page/route.ts +0 -119
- package/app/loading.tsx +0 -5
package/next.config.js
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const { SomaManifestWebpackPlugin } = require('./core/compiler/soma-manifest-webpack-plugin');
|
|
5
|
+
const {
|
|
6
|
+
resolveHostConfigRoot,
|
|
7
|
+
resolveHostAppConfigPath,
|
|
8
|
+
} = require('./core/host/host-config-paths.cjs');
|
|
9
|
+
const {
|
|
10
|
+
readSomaPageResponseMode,
|
|
11
|
+
} = require('./core/host/page-response-mode.cjs');
|
|
12
|
+
|
|
13
|
+
function readSomaWebpackCacheMode(env = process.env) {
|
|
14
|
+
const mode = env.SOMA_WEBPACK_CACHE_MODE;
|
|
15
|
+
if (mode === undefined) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (mode !== 'memory') {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'[soma-core] Unsupported SOMA_WEBPACK_CACHE_MODE '
|
|
21
|
+
+ JSON.stringify(mode)
|
|
22
|
+
+ '; expected "memory" or leave it unset.',
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return mode;
|
|
26
|
+
}
|
|
5
27
|
|
|
6
28
|
const rawHostDir = process.env.SOMA_HOST_DIR;
|
|
7
29
|
if (!rawHostDir || !String(rawHostDir).trim()) {
|
|
@@ -10,15 +32,68 @@ if (!rawHostDir || !String(rawHostDir).trim()) {
|
|
|
10
32
|
);
|
|
11
33
|
}
|
|
12
34
|
const hostDir = path.resolve(rawHostDir);
|
|
35
|
+
const webpackCacheMode = readSomaWebpackCacheMode();
|
|
36
|
+
const pageResponseConfig = readSomaPageResponseMode(hostDir);
|
|
37
|
+
process.env.SOMA_PAGE_RESPONSE_MODE = pageResponseConfig.mode;
|
|
38
|
+
if (pageResponseConfig.mode === 'json') {
|
|
39
|
+
console.log(
|
|
40
|
+
'[soma-core] pageResponseMode=json enabled from '
|
|
41
|
+
+ (pageResponseConfig.configPath || 'App defaults'),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function readJson(filePath) {
|
|
46
|
+
try {
|
|
47
|
+
if (!fs.existsSync(filePath)) return null;
|
|
48
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function resolveSafeChildRoot(parent, relativePath) {
|
|
55
|
+
const trimmed = typeof relativePath === 'string' ? relativePath.trim() : '';
|
|
56
|
+
if (!trimmed) return parent;
|
|
57
|
+
|
|
58
|
+
const resolved = path.resolve(parent, trimmed);
|
|
59
|
+
if ((resolved === parent || resolved.startsWith(`${parent}${path.sep}`)) && fs.existsSync(resolved)) {
|
|
60
|
+
return resolved;
|
|
61
|
+
}
|
|
62
|
+
return parent;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function readHostSourceRoot() {
|
|
66
|
+
const packageJson = readJson(path.join(hostDir, 'package.json'));
|
|
67
|
+
return resolveSafeChildRoot(hostDir, packageJson?.soma?.hostRoot);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const hostSourceRoot = readHostSourceRoot();
|
|
71
|
+
const hostConfigRoot = resolveHostConfigRoot(hostDir);
|
|
72
|
+
|
|
73
|
+
function resolveOptionalHostSourceFile(relativePath, fallbackPath) {
|
|
74
|
+
const hostFile = path.resolve(hostSourceRoot, relativePath);
|
|
75
|
+
if (fs.existsSync(hostFile)) {
|
|
76
|
+
return hostFile;
|
|
77
|
+
}
|
|
78
|
+
return path.resolve(__dirname, fallbackPath);
|
|
79
|
+
}
|
|
13
80
|
|
|
14
|
-
function
|
|
15
|
-
const hostFile = path.resolve(
|
|
81
|
+
function resolveOptionalHostConfigFile(fileName, fallbackPath) {
|
|
82
|
+
const hostFile = path.resolve(hostConfigRoot, fileName);
|
|
16
83
|
if (fs.existsSync(hostFile)) {
|
|
17
84
|
return hostFile;
|
|
18
85
|
}
|
|
19
86
|
return path.resolve(__dirname, fallbackPath);
|
|
20
87
|
}
|
|
21
88
|
|
|
89
|
+
function resolveHostAppConfigAlias(fallbackPath) {
|
|
90
|
+
const envConfig = resolveHostAppConfigPath(hostDir);
|
|
91
|
+
if (envConfig) {
|
|
92
|
+
return envConfig;
|
|
93
|
+
}
|
|
94
|
+
return path.resolve(__dirname, fallbackPath);
|
|
95
|
+
}
|
|
96
|
+
|
|
22
97
|
function readHostFileDependencyEntries() {
|
|
23
98
|
const packageJsonPath = path.join(hostDir, 'package.json');
|
|
24
99
|
if (!fs.existsSync(packageJsonPath)) {
|
|
@@ -56,6 +131,10 @@ const transpilePackages = [
|
|
|
56
131
|
];
|
|
57
132
|
|
|
58
133
|
const nextConfig = {
|
|
134
|
+
env: {
|
|
135
|
+
SOMA_PAGE_RESPONSE_MODE: pageResponseConfig.mode,
|
|
136
|
+
},
|
|
137
|
+
|
|
59
138
|
experimental: {
|
|
60
139
|
externalDir: true,
|
|
61
140
|
serverComponentsExternalPackages: ['jiti'],
|
|
@@ -63,27 +142,47 @@ const nextConfig = {
|
|
|
63
142
|
|
|
64
143
|
transpilePackages,
|
|
65
144
|
|
|
66
|
-
webpack: (config) => {
|
|
145
|
+
webpack: (config, { dev }) => {
|
|
146
|
+
if (webpackCacheMode === 'memory' && dev) {
|
|
147
|
+
config.cache = { type: 'memory' };
|
|
148
|
+
}
|
|
67
149
|
config.resolve.alias['@'] = __dirname;
|
|
68
150
|
config.resolve.alias['soma-core$'] = path.resolve(__dirname, 'core/index.ts');
|
|
69
151
|
config.resolve.alias['soma-core/base$'] = path.resolve(__dirname, 'core/base/index.ts');
|
|
70
152
|
config.resolve.alias['@core'] = path.resolve(__dirname, 'core');
|
|
71
153
|
for (const entry of hostFileDependencyEntries) {
|
|
72
|
-
|
|
154
|
+
const packageJson = readJson(path.join(entry.root, 'package.json'));
|
|
155
|
+
if (packageJson?.soma?.configRoot) {
|
|
156
|
+
config.resolve.alias[`${entry.name}/config`] = resolveSafeChildRoot(
|
|
157
|
+
entry.root,
|
|
158
|
+
packageJson.soma.configRoot,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
config.resolve.alias[entry.name] = resolveSafeChildRoot(
|
|
162
|
+
entry.root,
|
|
163
|
+
packageJson?.soma?.hostRoot,
|
|
164
|
+
);
|
|
73
165
|
}
|
|
74
|
-
config.resolve.alias['@soma-host/bootstrap/soma-bootstrap'] =
|
|
166
|
+
config.resolve.alias['@soma-host/bootstrap/soma-bootstrap'] = resolveOptionalHostSourceFile(
|
|
75
167
|
'bootstrap/soma-bootstrap.ts',
|
|
76
168
|
'core/host/soma-bootstrap-host.stub.ts',
|
|
77
169
|
);
|
|
78
|
-
config.resolve.alias['@soma-host/
|
|
79
|
-
'
|
|
170
|
+
config.resolve.alias['@soma-host/bootstrap/soma-request-hook'] = resolveOptionalHostSourceFile(
|
|
171
|
+
'bootstrap/soma-request-hook.ts',
|
|
172
|
+
'core/host/soma-request-hook-host.stub.ts',
|
|
173
|
+
);
|
|
174
|
+
config.resolve.alias['@soma-host/bootstrap/soma-domain-loaders'] = resolveOptionalHostSourceFile(
|
|
175
|
+
'bootstrap/soma-domain-loaders.ts',
|
|
176
|
+
'core/host/soma-domain-loaders.stub.ts',
|
|
177
|
+
);
|
|
178
|
+
config.resolve.alias['@soma-host/config/locale.yaml'] = resolveOptionalHostConfigFile(
|
|
179
|
+
'locale.yaml',
|
|
80
180
|
'core/host/locale.stub.ts',
|
|
81
181
|
);
|
|
82
|
-
config.resolve.alias['@soma-host/config/app.config.yaml'] =
|
|
83
|
-
'config/app.config.yaml',
|
|
182
|
+
config.resolve.alias['@soma-host/config/app.config.yaml'] = resolveHostAppConfigAlias(
|
|
84
183
|
'core/host/app-config.stub.ts',
|
|
85
184
|
);
|
|
86
|
-
config.resolve.alias['@soma-host'] =
|
|
185
|
+
config.resolve.alias['@soma-host'] = hostSourceRoot;
|
|
87
186
|
|
|
88
187
|
config.plugins.push(new SomaManifestWebpackPlugin({ hostDir }));
|
|
89
188
|
|
|
@@ -112,19 +211,6 @@ const nextConfig = {
|
|
|
112
211
|
);
|
|
113
212
|
return config;
|
|
114
213
|
},
|
|
115
|
-
|
|
116
|
-
async rewrites() {
|
|
117
|
-
return [
|
|
118
|
-
{
|
|
119
|
-
source: '/:path*.html',
|
|
120
|
-
destination: '/',
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
source: '/:path((?!api|_next|favicon\\.ico)(?![^/]*\\.[a-zA-Z0-9]+$).*)',
|
|
124
|
-
destination: '/',
|
|
125
|
-
},
|
|
126
|
-
];
|
|
127
|
-
},
|
|
128
214
|
};
|
|
129
215
|
|
|
130
216
|
module.exports = nextConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soma-core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "SOMA — Semantic Oriented Modular Architecture. A declarative frontend framework runtime built on Next.js 14+ App Router.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"soma",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"bin": {
|
|
29
29
|
"soma": "bin/soma.cjs",
|
|
30
|
-
"soma-lsp": "bin/soma-lsp.cjs"
|
|
30
|
+
"soma-lsp": "bin/soma-lsp.cjs",
|
|
31
|
+
"soma-mock": "bin/soma-mock.mjs"
|
|
31
32
|
},
|
|
32
33
|
"exports": {
|
|
33
34
|
".": {
|
|
@@ -48,17 +49,40 @@
|
|
|
48
49
|
"import": "./core/diagnostics/SomaTelemetry.ts",
|
|
49
50
|
"require": "./dist/diagnostics/telemetry.cjs",
|
|
50
51
|
"default": "./core/diagnostics/SomaTelemetry.ts"
|
|
52
|
+
},
|
|
53
|
+
"./host/request-hook": {
|
|
54
|
+
"types": "./dist/types/host/resolve-host-request-hook.d.ts",
|
|
55
|
+
"import": "./core/host/resolve-host-request-hook.ts",
|
|
56
|
+
"default": "./core/host/resolve-host-request-hook.ts"
|
|
57
|
+
},
|
|
58
|
+
"./mock/node": {
|
|
59
|
+
"types": "./core/mock/node/public.d.mts",
|
|
60
|
+
"import": "./core/mock/node/public.mjs",
|
|
61
|
+
"default": "./core/mock/node/public.mjs"
|
|
62
|
+
},
|
|
63
|
+
"./mock/node/cli": {
|
|
64
|
+
"types": "./core/mock/node/cli.d.mts",
|
|
65
|
+
"import": "./core/mock/node/cli.mjs",
|
|
66
|
+
"default": "./core/mock/node/cli.mjs"
|
|
67
|
+
},
|
|
68
|
+
"./testing/mock-host": {
|
|
69
|
+
"types": "./core/mock/testing/host-harness.d.mts",
|
|
70
|
+
"import": "./core/mock/testing/host-harness.mjs",
|
|
71
|
+
"default": "./core/mock/testing/host-harness.mjs"
|
|
51
72
|
}
|
|
52
73
|
},
|
|
53
74
|
"files": [
|
|
54
75
|
"bin/soma.cjs",
|
|
55
76
|
"bin/soma-lsp.cjs",
|
|
56
77
|
"bin/soma-sync.cjs",
|
|
78
|
+
"bin/soma-mock.mjs",
|
|
57
79
|
"core/",
|
|
80
|
+
"docs/",
|
|
58
81
|
"editor/",
|
|
59
82
|
"app/",
|
|
60
83
|
"dist/",
|
|
61
84
|
"dist/vscode/",
|
|
85
|
+
"middleware.ts",
|
|
62
86
|
"next.config.js",
|
|
63
87
|
"tailwind.config.ts",
|
|
64
88
|
"postcss.config.js",
|
|
@@ -80,14 +104,18 @@
|
|
|
80
104
|
"build": "next build",
|
|
81
105
|
"start": "next start",
|
|
82
106
|
"lint": "next lint",
|
|
83
|
-
"test": "vitest run",
|
|
107
|
+
"test": "vitest run && npm run test:mock",
|
|
108
|
+
"test:mock": "node --test tests/mock/*.test.mjs",
|
|
109
|
+
"verify:mock-pack": "node scripts/verify-mock-pack.mjs",
|
|
84
110
|
"test:watch": "vitest",
|
|
85
111
|
"typecheck": "tsc --noEmit"
|
|
86
112
|
},
|
|
87
113
|
"dependencies": {
|
|
88
|
-
"
|
|
114
|
+
"ajv": "8.20.0",
|
|
115
|
+
"dompurify": "^3.4.12",
|
|
89
116
|
"jiti": "^1.21.7",
|
|
90
|
-
"js-yaml": "^4.
|
|
117
|
+
"js-yaml": "^4.3.0",
|
|
118
|
+
"msw": "2.15.0",
|
|
91
119
|
"reflect-metadata": "^0.2.1"
|
|
92
120
|
},
|
|
93
121
|
"peerDependencies": {
|
|
@@ -101,7 +129,9 @@
|
|
|
101
129
|
"@types/node": "^20.11.0",
|
|
102
130
|
"@types/react": "^18.3.0",
|
|
103
131
|
"@types/react-dom": "^18.3.0",
|
|
104
|
-
"@
|
|
132
|
+
"@types/ws": "^8.5.13",
|
|
133
|
+
"@vitest/coverage-v8": "^3.2.7",
|
|
134
|
+
"ajv-formats": "3.0.1",
|
|
105
135
|
"autoprefixer": "^10.4.17",
|
|
106
136
|
"esbuild": "^0.25.12",
|
|
107
137
|
"jsdom": "^26.1.0",
|
|
@@ -111,8 +141,8 @@
|
|
|
111
141
|
"react-dom": "^18.3.0",
|
|
112
142
|
"tailwindcss": "^3.4.1",
|
|
113
143
|
"typescript": "^5.3.3",
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
144
|
+
"vite": "6.4.3",
|
|
145
|
+
"vitest": "^3.2.7",
|
|
146
|
+
"ws": "^8.21.0"
|
|
117
147
|
}
|
|
118
148
|
}
|
package/tsconfig.json
CHANGED
|
@@ -20,11 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"paths": {
|
|
22
22
|
"@core/*": ["./core/*"],
|
|
23
|
-
"@/*": ["./*"]
|
|
24
|
-
"@soma-host/config/locale.yaml": ["./tests/fixtures/host/config/locale.stub.ts"],
|
|
25
|
-
"@soma-host/config/app.config.yaml": ["./tests/fixtures/host/config/app.config.stub.ts"],
|
|
26
|
-
"@soma-host/bootstrap/soma-bootstrap": ["./tests/fixtures/host/bootstrap/soma-bootstrap.ts"],
|
|
27
|
-
"@soma-host/*": ["./tests/fixtures/host/*"]
|
|
23
|
+
"@/*": ["./*"]
|
|
28
24
|
},
|
|
29
25
|
"baseUrl": "."
|
|
30
26
|
},
|
package/app/api/page/route.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// URL → html/ui/event files: / → index.html, /a/b → a/b.html; */index.html also maps to short path /a
|
|
2
|
-
|
|
3
|
-
import { existsSync } from 'fs';
|
|
4
|
-
import { join, resolve } from 'path';
|
|
5
|
-
import { NextRequest } from 'next/server';
|
|
6
|
-
import { isSafePageBase, urlPathToCandidates } from '../../../core/compiler/page-base-resolver';
|
|
7
|
-
import { getSomaAssetSources, type SomaAssetSource } from '../../../core/host/source-packages';
|
|
8
|
-
import { ServerFileCache } from '../../../core/infra/cache/ServerFileCache';
|
|
9
|
-
|
|
10
|
-
const cache = ServerFileCache.getInstance();
|
|
11
|
-
|
|
12
|
-
function getHostDir(): string | undefined {
|
|
13
|
-
return process.env.SOMA_HOST_DIR || undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const watchedRoots = new Set<string>();
|
|
17
|
-
|
|
18
|
-
function ensureWatch(root: string) {
|
|
19
|
-
if (watchedRoots.has(root)) return;
|
|
20
|
-
watchedRoots.add(root);
|
|
21
|
-
cache.watchAndInvalidate(root);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function resolvePageSource(sources: SomaAssetSource[], urlPath: string): { source: SomaAssetSource; base: string } | null {
|
|
25
|
-
for (const candidate of urlPathToCandidates(urlPath)) {
|
|
26
|
-
if (!isSafePageBase(candidate)) continue;
|
|
27
|
-
for (const source of sources) {
|
|
28
|
-
const htmlPath = join(source.assetRoot, 'html', `${candidate}.html`);
|
|
29
|
-
if (existsSync(htmlPath)) {
|
|
30
|
-
return { source, base: candidate };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function collectIncludes(sources: SomaAssetSource[]): Record<string, string> {
|
|
38
|
-
const includes: Record<string, string> = {};
|
|
39
|
-
const ordered = [
|
|
40
|
-
...sources.filter((source) => source.type === 'package'),
|
|
41
|
-
...sources.filter((source) => source.type === 'host'),
|
|
42
|
-
];
|
|
43
|
-
for (const source of ordered) {
|
|
44
|
-
const sharedDir = join(source.assetRoot, 'html', 'shared');
|
|
45
|
-
try {
|
|
46
|
-
const files = cache.readDirFiles(sharedDir, '.html');
|
|
47
|
-
const names = cache.readDirNames(sharedDir, '.html');
|
|
48
|
-
for (let i = 0; i < names.length; i++) {
|
|
49
|
-
includes[`shared/${names[i]}`] = files[i];
|
|
50
|
-
}
|
|
51
|
-
} catch {}
|
|
52
|
-
}
|
|
53
|
-
return includes;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export async function GET(req: NextRequest) {
|
|
57
|
-
const hostDir = getHostDir();
|
|
58
|
-
if (!hostDir) {
|
|
59
|
-
return Response.json(
|
|
60
|
-
{ error: 'SOMA_HOST_DIR is not set. Run: npx soma dev from your app root.' },
|
|
61
|
-
{ status: 503 },
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const sources = getSomaAssetSources(hostDir);
|
|
66
|
-
sources.forEach((source) => ensureWatch(source.assetRoot));
|
|
67
|
-
sources.forEach((source) => {
|
|
68
|
-
if (source.codeRoot !== source.assetRoot) {
|
|
69
|
-
ensureWatch(source.codeRoot);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const urlPath = req.nextUrl.searchParams.get('path') || '/';
|
|
74
|
-
const resolvedPage = resolvePageSource(sources, urlPath);
|
|
75
|
-
|
|
76
|
-
if (!resolvedPage) {
|
|
77
|
-
return Response.json({ error: `Page not found: ${urlPath}` }, { status: 404 });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const { source, base } = resolvedPage;
|
|
81
|
-
const htmlPath = join(source.assetRoot, 'html', `${base}.html`);
|
|
82
|
-
const resolvedHtml = resolve(htmlPath);
|
|
83
|
-
const resolvedSourceHtml = resolve(source.assetRoot, 'html');
|
|
84
|
-
if (!resolvedHtml.startsWith(resolvedSourceHtml)) {
|
|
85
|
-
return Response.json({ error: 'Invalid path' }, { status: 400 });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
const html = cache.readFile(htmlPath);
|
|
90
|
-
|
|
91
|
-
let ui: string, event: string, style: string, localeYaml: string, appConfigYaml: string;
|
|
92
|
-
try {
|
|
93
|
-
ui = cache.tryReadFile(join(source.assetRoot, 'ui', `${base}_ui.yaml`));
|
|
94
|
-
event = cache.tryReadFile(join(source.assetRoot, 'event', `${base}_event.yaml`));
|
|
95
|
-
style = cache.tryReadFile(join(source.assetRoot, 'ui', `${base}_style.yaml`));
|
|
96
|
-
localeYaml = cache.tryReadFile(join(hostDir, 'config', 'locale.yaml'));
|
|
97
|
-
appConfigYaml = cache.tryReadFile(join(hostDir, 'config', 'app.config.yaml'));
|
|
98
|
-
} catch (e: any) {
|
|
99
|
-
return Response.json({ error: `Asset read error: ${e.message}` }, { status: 500 });
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const includes = collectIncludes(sources);
|
|
103
|
-
|
|
104
|
-
return Response.json({
|
|
105
|
-
base,
|
|
106
|
-
sourceType: source.type,
|
|
107
|
-
sourcePackage: source.packageName ?? null,
|
|
108
|
-
html,
|
|
109
|
-
ui,
|
|
110
|
-
event,
|
|
111
|
-
styleYaml: style,
|
|
112
|
-
localeYaml,
|
|
113
|
-
appConfigYaml,
|
|
114
|
-
includes,
|
|
115
|
-
});
|
|
116
|
-
} catch (e: any) {
|
|
117
|
-
return Response.json({ error: `Page not found: ${base}.html` }, { status: 404 });
|
|
118
|
-
}
|
|
119
|
-
}
|