@zhin.js/runtime 1.0.3 → 1.0.5
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/lib/config-composer.js +26 -0
- package/lib/package-resolver.js +31 -2
- package/package.json +12 -12
package/lib/config-composer.js
CHANGED
|
@@ -116,10 +116,36 @@ export class ConfigComposer {
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
+
const FRAMEWORK_ROLE_SCHEMA = Object.freeze({
|
|
120
|
+
master: Object.freeze({
|
|
121
|
+
type: ['string', 'number'],
|
|
122
|
+
description: 'Endpoint owner (framework-level master role)',
|
|
123
|
+
}),
|
|
124
|
+
trusted: Object.freeze({
|
|
125
|
+
type: 'array',
|
|
126
|
+
items: Object.freeze({ type: ['string', 'number'] }),
|
|
127
|
+
description: 'Trusted user ID list (framework-level trusted role)',
|
|
128
|
+
}),
|
|
129
|
+
});
|
|
130
|
+
function hasArrayEndpoints(props) {
|
|
131
|
+
const ep = props.endpoints;
|
|
132
|
+
if (!ep || typeof ep !== 'object')
|
|
133
|
+
return false;
|
|
134
|
+
return ep.type === 'array';
|
|
135
|
+
}
|
|
119
136
|
async function composeNode(node, ownSchemas) {
|
|
120
137
|
const own = await readOwnSchema(node);
|
|
121
138
|
ownSchemas.set(node.id, own);
|
|
122
139
|
const properties = { ...schemaProperties(own) };
|
|
140
|
+
// Adapter plugins (schemas declaring array-typed `endpoints`) get
|
|
141
|
+
// framework-level `master` / `trusted` injected when not already declared.
|
|
142
|
+
if (hasArrayEndpoints(properties)) {
|
|
143
|
+
for (const [key, schema] of Object.entries(FRAMEWORK_ROLE_SCHEMA)) {
|
|
144
|
+
if (!Object.hasOwn(properties, key)) {
|
|
145
|
+
properties[key] = schema;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
123
149
|
for (const child of node.children) {
|
|
124
150
|
if (Object.hasOwn(properties, child.instanceKey)) {
|
|
125
151
|
throw new ConfigSchemaCollisionError(node.id, child.instanceKey);
|
package/lib/package-resolver.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { access, readFile, readdir, realpath } from 'node:fs/promises';
|
|
2
|
-
import { dirname, join, resolve } from 'node:path';
|
|
2
|
+
import { dirname, extname, join, relative, resolve } from 'node:path';
|
|
3
3
|
import { parsePackageJson } from './manifest.js';
|
|
4
4
|
export class PackageResolutionError extends Error {
|
|
5
5
|
request;
|
|
@@ -93,7 +93,17 @@ export class NodePackageResolver {
|
|
|
93
93
|
return cached;
|
|
94
94
|
const file = join(normalized, 'package.json');
|
|
95
95
|
const content = await readFile(file, 'utf8');
|
|
96
|
-
const
|
|
96
|
+
const parsedPackageJson = parsePackageJson(JSON.parse(content), file);
|
|
97
|
+
const entry = await resolveRuntimeEntry(normalized, parsedPackageJson.zhin.entry, source);
|
|
98
|
+
const packageJson = entry === parsedPackageJson.zhin.entry
|
|
99
|
+
? parsedPackageJson
|
|
100
|
+
: Object.freeze({
|
|
101
|
+
...parsedPackageJson,
|
|
102
|
+
zhin: Object.freeze({
|
|
103
|
+
...parsedPackageJson.zhin,
|
|
104
|
+
entry,
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
97
107
|
const result = Object.freeze({
|
|
98
108
|
name: packageJson.name,
|
|
99
109
|
root: normalized,
|
|
@@ -104,6 +114,25 @@ export class NodePackageResolver {
|
|
|
104
114
|
return result;
|
|
105
115
|
}
|
|
106
116
|
}
|
|
117
|
+
async function resolveRuntimeEntry(packageRoot, declaredEntry, source) {
|
|
118
|
+
const declared = resolve(packageRoot, declaredEntry);
|
|
119
|
+
const extension = extname(declared);
|
|
120
|
+
const base = declared.slice(0, -extension.length);
|
|
121
|
+
const sourceCandidates = extension === '.js'
|
|
122
|
+
? [`${base}.ts`, `${base}.tsx`]
|
|
123
|
+
: [declared];
|
|
124
|
+
const javascriptCandidates = extension === '.ts' || extension === '.tsx'
|
|
125
|
+
? [`${base}.js`, join(packageRoot, 'lib', `${base.slice(packageRoot.length + 1)}.js`)]
|
|
126
|
+
: [declared];
|
|
127
|
+
const candidates = source === 'node_modules'
|
|
128
|
+
? [...javascriptCandidates, ...sourceCandidates]
|
|
129
|
+
: [...sourceCandidates, ...javascriptCandidates];
|
|
130
|
+
for (const candidate of new Set(candidates)) {
|
|
131
|
+
if (await exists(candidate))
|
|
132
|
+
return `./${relative(packageRoot, candidate).replaceAll('\\', '/')}`;
|
|
133
|
+
}
|
|
134
|
+
return declaredEntry;
|
|
135
|
+
}
|
|
107
136
|
function declaredDependency(request, pkg) {
|
|
108
137
|
const specification = (pkg.dependencies?.[request]
|
|
109
138
|
?? pkg.optionalDependencies?.[request]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/runtime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Static Plugin graph, generation transaction and HMR Root runtime for Zhin.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"ajv": "8.18.0",
|
|
20
20
|
"semver": "7.8.5",
|
|
21
|
-
"@zhin.js/feature-kit": "1.0.
|
|
21
|
+
"@zhin.js/feature-kit": "1.0.4",
|
|
22
22
|
"@zhin.js/plugin-runtime": "1.1.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^26.1.0",
|
|
26
26
|
"typescript": "^6.0.3",
|
|
27
|
-
"@zhin.js/adapter": "1.1.
|
|
28
|
-
"@zhin.js/agent-feature": "1.0.
|
|
29
|
-
"@zhin.js/command": "1.0.
|
|
30
|
-
"@zhin.js/component": "1.0.
|
|
31
|
-
"@zhin.js/layout": "1.0.
|
|
32
|
-
"@zhin.js/mcp-feature": "1.0.
|
|
33
|
-
"@zhin.js/middleware": "1.0.
|
|
34
|
-
"@zhin.js/page": "1.0.
|
|
35
|
-
"@zhin.js/skill": "1.0.
|
|
36
|
-
"@zhin.js/tool": "1.0.
|
|
27
|
+
"@zhin.js/adapter": "1.1.2",
|
|
28
|
+
"@zhin.js/agent-feature": "1.0.4",
|
|
29
|
+
"@zhin.js/command": "1.0.4",
|
|
30
|
+
"@zhin.js/component": "1.0.4",
|
|
31
|
+
"@zhin.js/layout": "1.0.4",
|
|
32
|
+
"@zhin.js/mcp-feature": "1.0.4",
|
|
33
|
+
"@zhin.js/middleware": "1.0.4",
|
|
34
|
+
"@zhin.js/page": "1.0.4",
|
|
35
|
+
"@zhin.js/skill": "1.0.4",
|
|
36
|
+
"@zhin.js/tool": "1.0.4"
|
|
37
37
|
},
|
|
38
38
|
"repository": {
|
|
39
39
|
"type": "git",
|