@zhin.js/command 1.0.4 → 1.0.6
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/command-index.js +11 -4
- package/lib/definition.js +9 -4
- package/package.json +4 -4
- package/src/command-index.ts +10 -4
- package/src/definition.ts +7 -4
package/lib/command-index.js
CHANGED
|
@@ -133,11 +133,18 @@ export function isCommandIndex(value) {
|
|
|
133
133
|
return !!value && typeof value === 'object'
|
|
134
134
|
&& value.$projection === 'zhin.command-index/1';
|
|
135
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* 命令运行时名 = 插件树路径段(instanceKey,去掉 root)以 `.` 连接后,再与命令
|
|
138
|
+
* 文件路径首段以 `.` 连接;命令内部嵌套段仍为空格分隔。Root 插件无前缀。
|
|
139
|
+
* 例:`root/qq` + `endpoint/list` → `qq.endpoint list`;
|
|
140
|
+
* `root/b/a` + `foo` → `b.a.foo`;root + `foo` → `foo`。
|
|
141
|
+
*/
|
|
136
142
|
function runtimeSegments(owner, localName) {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
const localSegments = localName.split('/');
|
|
144
|
+
if (owner === 'root')
|
|
145
|
+
return localSegments;
|
|
146
|
+
const prefix = owner.slice('root/'.length).split('/').join('.');
|
|
147
|
+
return [`${prefix}.${localSegments[0]}`, ...localSegments.slice(1)];
|
|
141
148
|
}
|
|
142
149
|
function assertParameterSegment(segments, parameter, source) {
|
|
143
150
|
const dynamicSegments = segments.filter((segment) => segment.startsWith('$'));
|
package/lib/definition.js
CHANGED
|
@@ -140,14 +140,19 @@ function parseTarget(target) {
|
|
|
140
140
|
const parts = target.split(':').filter(Boolean);
|
|
141
141
|
if (parts.length < 2)
|
|
142
142
|
return undefined;
|
|
143
|
-
const kind = parts
|
|
143
|
+
const [kind, ...rest] = parts;
|
|
144
|
+
if (!kind)
|
|
145
|
+
return undefined;
|
|
146
|
+
const lastPart = parts.at(-1);
|
|
147
|
+
if (!lastPart)
|
|
148
|
+
return undefined;
|
|
144
149
|
if (kind === 'channel' && parts.length >= 3) {
|
|
145
|
-
return { type: 'channel', id:
|
|
150
|
+
return { type: 'channel', id: lastPart };
|
|
146
151
|
}
|
|
147
152
|
if (kind === 'temp' && parts.length >= 3) {
|
|
148
|
-
return { type: 'private', id:
|
|
153
|
+
return { type: 'private', id: lastPart };
|
|
149
154
|
}
|
|
150
|
-
return { type: kind, id:
|
|
155
|
+
return { type: kind, id: rest.join(':') };
|
|
151
156
|
}
|
|
152
157
|
function isCommandScene(value) {
|
|
153
158
|
if (!value || typeof value !== 'object')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/command",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Convention-based Command Feature for Zhin Plugin Runtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"segment-matcher": "^1.0.5",
|
|
21
|
-
"@zhin.js/feature-kit": "1.0.
|
|
22
|
-
"@zhin.js/plugin-runtime": "1.1.
|
|
21
|
+
"@zhin.js/feature-kit": "1.0.5",
|
|
22
|
+
"@zhin.js/plugin-runtime": "1.1.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/node": "^26.1.
|
|
25
|
+
"@types/node": "^26.1.2",
|
|
26
26
|
"typescript": "^6.0.3"
|
|
27
27
|
},
|
|
28
28
|
"zhin": {
|
package/src/command-index.ts
CHANGED
|
@@ -207,11 +207,17 @@ export function isCommandIndex(value: unknown): value is CommandIndex {
|
|
|
207
207
|
&& (value as { readonly $projection?: unknown }).$projection === 'zhin.command-index/1';
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
+
/**
|
|
211
|
+
* 命令运行时名 = 插件树路径段(instanceKey,去掉 root)以 `.` 连接后,再与命令
|
|
212
|
+
* 文件路径首段以 `.` 连接;命令内部嵌套段仍为空格分隔。Root 插件无前缀。
|
|
213
|
+
* 例:`root/qq` + `endpoint/list` → `qq.endpoint list`;
|
|
214
|
+
* `root/b/a` + `foo` → `b.a.foo`;root + `foo` → `foo`。
|
|
215
|
+
*/
|
|
210
216
|
function runtimeSegments(owner: string, localName: string): string[] {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return [
|
|
217
|
+
const localSegments = localName.split('/');
|
|
218
|
+
if (owner === 'root') return localSegments;
|
|
219
|
+
const prefix = owner.slice('root/'.length).split('/').join('.');
|
|
220
|
+
return [`${prefix}.${localSegments[0]}`, ...localSegments.slice(1)];
|
|
215
221
|
}
|
|
216
222
|
|
|
217
223
|
function assertParameterSegment(
|
package/src/definition.ts
CHANGED
|
@@ -312,14 +312,17 @@ function resolveRoles(
|
|
|
312
312
|
function parseTarget(target: string): { readonly type: string; readonly id: string } | undefined {
|
|
313
313
|
const parts = target.split(':').filter(Boolean);
|
|
314
314
|
if (parts.length < 2) return undefined;
|
|
315
|
-
const kind = parts
|
|
315
|
+
const [kind, ...rest] = parts;
|
|
316
|
+
if (!kind) return undefined;
|
|
317
|
+
const lastPart = parts.at(-1);
|
|
318
|
+
if (!lastPart) return undefined;
|
|
316
319
|
if (kind === 'channel' && parts.length >= 3) {
|
|
317
|
-
return { type: 'channel', id:
|
|
320
|
+
return { type: 'channel', id: lastPart };
|
|
318
321
|
}
|
|
319
322
|
if (kind === 'temp' && parts.length >= 3) {
|
|
320
|
-
return { type: 'private', id:
|
|
323
|
+
return { type: 'private', id: lastPart };
|
|
321
324
|
}
|
|
322
|
-
return { type: kind
|
|
325
|
+
return { type: kind, id: rest.join(':') };
|
|
323
326
|
}
|
|
324
327
|
|
|
325
328
|
function isCommandScene(value: unknown): value is CommandScene {
|