@vestra-player/sdk 1.8.0 → 1.10.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/CHANGELOG.md +64 -2
- package/README.md +2 -2
- package/bin/vestra-plugin.mjs +98 -106
- package/capability-scan.json +21 -1
- package/dist/api-requests.d.ts +15 -39
- package/dist/api-requests.js +28 -50
- package/dist/capability-scan.d.ts +1 -1
- package/dist/capability-scan.js +8 -9
- package/dist/condition-table.d.ts +1889 -0
- package/dist/condition-table.js +562 -0
- package/dist/docs-tree.json.gz +0 -0
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +1 -1
- package/dist/i18n-tools.d.ts +7 -0
- package/dist/i18n-tools.js +66 -3
- package/dist/index.d.ts +4 -5
- package/dist/manifest.d.ts +5 -0
- package/dist/manifest.js +9 -24
- package/dist/member-uses.d.ts +61 -0
- package/dist/member-uses.js +160 -0
- package/dist/player-runtime.d.ts +4 -2
- package/dist/player-runtime.js +4 -2
- package/dist/plugin/appearance.d.ts +1 -1
- package/dist/plugin/appearance.js +2 -2
- package/dist/plugin/bindings.d.ts +1 -1
- package/dist/plugin/bindings.js +2 -2
- package/dist/plugin/commands.js +1 -12
- package/dist/plugin/connection.d.ts +38 -8
- package/dist/plugin/connection.js +126 -37
- package/dist/plugin/drops.js +1 -1
- package/dist/plugin/index.d.ts +7 -0
- package/dist/plugin/index.js +22 -15
- package/dist/plugin/media.js +0 -12
- package/dist/plugin/mpv.js +39 -12
- package/dist/plugin/packages.js +1 -2
- package/dist/plugin/player/events.d.ts +17 -7
- package/dist/plugin/player/events.js +26 -9
- package/dist/plugin/player.d.ts +37 -13
- package/dist/plugin/player.js +133 -22
- package/dist/plugin/scope.d.ts +4 -1
- package/dist/plugin/scope.js +8 -0
- package/dist/plugin/services.d.ts +4 -4
- package/dist/plugin/services.js +7 -29
- package/dist/plugin/settings.js +1 -1
- package/dist/plugin/shaders.js +0 -2
- package/dist/plugin/stream.d.ts +2 -1
- package/dist/plugin/stream.js +2 -2
- package/dist/plugin/testing/commands.d.ts +3 -10
- package/dist/plugin/testing/commands.js +24 -37
- package/dist/plugin/testing/index.d.ts +133 -116
- package/dist/plugin/testing/index.js +198 -125
- package/dist/plugin/testing/media.d.ts +6 -0
- package/dist/plugin/testing/media.js +15 -2
- package/dist/plugin/testing/processing.js +1 -1
- package/dist/plugin/testing/services.js +0 -1
- package/dist/plugin/testing/source-events.d.ts +28 -0
- package/dist/plugin/testing/source-events.js +66 -0
- package/dist/plugin/testing/transport.js +5 -0
- package/dist/plugin/testing/triggers.d.ts +82 -0
- package/dist/plugin/testing/triggers.js +448 -0
- package/dist/plugin/timeline.d.ts +5 -6
- package/dist/plugin/timeline.js +7 -11
- package/dist/plugin/triggers.d.ts +55 -0
- package/dist/plugin/triggers.js +233 -0
- package/dist/plugin/types/base.d.ts +77 -87
- package/dist/plugin/types/commands.d.ts +384 -68
- package/dist/plugin/types/packages.d.ts +17 -55
- package/dist/plugin/types/playback.d.ts +382 -152
- package/dist/plugin/types/plugin-wire.d.ts +6 -36
- package/dist/plugin/types/processing.d.ts +10 -49
- package/dist/plugin/types/services.d.ts +11 -70
- package/dist/plugin/types/snapshots.d.ts +7 -60
- package/dist/plugin/types/sources.d.ts +2 -11
- package/dist/plugin/types/subtitles.d.ts +5 -26
- package/dist/plugin/types/ui-content.d.ts +1 -16
- package/dist/plugin/types/ui-layout.d.ts +53 -79
- package/dist/plugin/types/ui-locale.d.ts +5 -23
- package/dist/plugin/types/ui-shell.d.ts +13 -59
- package/dist/plugin/view/layout.js +1 -1
- package/dist/plugin/view.js +0 -2
- package/dist/plugin/when.d.ts +78 -4
- package/dist/plugin/when.js +182 -14
- package/dist/plugin/window.d.ts +1 -1
- package/dist/plugin/window.js +1 -1
- package/dist/plugin/wire-facade.js +1 -2
- package/dist/processing.d.ts +2 -3
- package/dist/protocol.d.ts +14 -0
- package/dist/protocol.js +14 -0
- package/dist/request-queue.js +1 -1
- package/dist/slint-version.d.ts +7 -0
- package/dist/slint-version.js +7 -0
- package/dist/subtitles.d.ts +1 -1
- package/dist/ts-plugin.d.ts +8 -15
- package/dist/ts-plugin.js +3 -141
- package/dist/wire.d.ts +22 -12
- package/dist/wire.js +17 -8
- package/llms.txt +6 -6
- package/package.json +1 -2
- package/dist/capabilities.d.ts +0 -107
- package/dist/capabilities.js +0 -69
- package/dist/capability-check.d.ts +0 -176
- package/dist/capability-check.js +0 -461
- package/dist/capability-rules.d.ts +0 -125
- package/dist/capability-rules.js +0 -192
- package/dist/host-capabilities.d.ts +0 -10
- package/dist/host-capabilities.js +0 -492
package/dist/capability-check.js
DELETED
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
import { ARGUMENT_APIS } from "./api-requests.js";
|
|
2
|
-
import { argumentRequests, memberNeeds, requestsNeed, RULES, } from "./capability-rules.js";
|
|
3
|
-
/** @internal The module plugins import the API types from. */
|
|
4
|
-
export const SDK_MODULE = "@vestra-player/sdk";
|
|
5
|
-
/** @internal The diagnostic code the editor shows (and its quick fix keys on). */
|
|
6
|
-
export const CAPABILITY_DIAGNOSTIC = 95_301;
|
|
7
|
-
/**
|
|
8
|
-
* @internal The warning code the editor shows for a call whose capability
|
|
9
|
-
* the checker cannot read (`plugin.wire.request` with a computed method).
|
|
10
|
-
*/
|
|
11
|
-
export const CAPABILITY_UNCHECKED = 95_302;
|
|
12
|
-
const memberCache = new WeakMap();
|
|
13
|
-
const argumentCache = new WeakMap();
|
|
14
|
-
/**
|
|
15
|
-
* The module `@vestra-player/sdk` as the program resolved it: from the
|
|
16
|
-
* first import or export of it in the program's own (non-declaration) files.
|
|
17
|
-
*/
|
|
18
|
-
function sdkModule(ts, program, checker) {
|
|
19
|
-
for (const file of program.getSourceFiles()) {
|
|
20
|
-
if (file.isDeclarationFile || program.isSourceFileFromExternalLibrary(file))
|
|
21
|
-
continue;
|
|
22
|
-
for (const statement of file.statements) {
|
|
23
|
-
const specifier = ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)
|
|
24
|
-
? statement.moduleSpecifier
|
|
25
|
-
: undefined;
|
|
26
|
-
if (specifier &&
|
|
27
|
-
ts.isStringLiteral(specifier) &&
|
|
28
|
-
specifier.text === SDK_MODULE) {
|
|
29
|
-
const module = checker.getSymbolAtLocation(specifier);
|
|
30
|
-
if (module)
|
|
31
|
-
return module;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
/** The SDK's declarations of the members named (`Interface.member`). */
|
|
38
|
-
function resolveMembers(ts, program, apis) {
|
|
39
|
-
const members = new Map();
|
|
40
|
-
const checker = program.getTypeChecker();
|
|
41
|
-
const module = sdkModule(ts, program, checker);
|
|
42
|
-
if (!module)
|
|
43
|
-
return members;
|
|
44
|
-
const exports = new Map();
|
|
45
|
-
for (const symbol of checker.getExportsOfModule(module))
|
|
46
|
-
exports.set(symbol.name, symbol.flags & ts.SymbolFlags.Alias
|
|
47
|
-
? checker.getAliasedSymbol(symbol)
|
|
48
|
-
: symbol);
|
|
49
|
-
for (const api of apis) {
|
|
50
|
-
const [head, ...path] = api.split(".");
|
|
51
|
-
const root = exports.get(head);
|
|
52
|
-
if (!root || !path.length)
|
|
53
|
-
continue;
|
|
54
|
-
let type = checker.getDeclaredTypeOfSymbol(root);
|
|
55
|
-
let property;
|
|
56
|
-
for (const name of path) {
|
|
57
|
-
property = type?.getProperty(name);
|
|
58
|
-
type = property && checker.getTypeOfSymbol(property);
|
|
59
|
-
}
|
|
60
|
-
for (const declaration of property?.declarations ?? [])
|
|
61
|
-
if (!members.has(declaration))
|
|
62
|
-
members.set(declaration, api);
|
|
63
|
-
}
|
|
64
|
-
return members;
|
|
65
|
-
}
|
|
66
|
-
/** The SDK's declarations of the members in the table. */
|
|
67
|
-
function sdkMembers(ts, program, rules) {
|
|
68
|
-
const cached = memberCache.get(program);
|
|
69
|
-
if (cached && rules === RULES)
|
|
70
|
-
return cached;
|
|
71
|
-
const members = resolveMembers(ts, program, Object.keys(rules.apis));
|
|
72
|
-
if (rules === RULES)
|
|
73
|
-
memberCache.set(program, members);
|
|
74
|
-
return members;
|
|
75
|
-
}
|
|
76
|
-
/** The SDK's declarations of the members of `ARGUMENT_APIS`. */
|
|
77
|
-
function argumentMembers(ts, program) {
|
|
78
|
-
let members = argumentCache.get(program);
|
|
79
|
-
if (!members) {
|
|
80
|
-
members = resolveMembers(ts, program, Object.keys(ARGUMENT_APIS));
|
|
81
|
-
argumentCache.set(program, members);
|
|
82
|
-
}
|
|
83
|
-
return members;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* The strings an expression's type fixes: a string literal, a constant of
|
|
87
|
-
* one, or a union of them (the caller takes one only); `undefined` when
|
|
88
|
-
* the type allows any other.
|
|
89
|
-
*/
|
|
90
|
-
function literalStrings(ts, checker, node) {
|
|
91
|
-
if (!node)
|
|
92
|
-
return undefined;
|
|
93
|
-
if (ts.isStringLiteralLike(node))
|
|
94
|
-
return [node.text];
|
|
95
|
-
const type = checker.getTypeAtLocation(node);
|
|
96
|
-
const parts = type.isUnion() ? type.types : [type];
|
|
97
|
-
const values = [];
|
|
98
|
-
for (const part of parts) {
|
|
99
|
-
if (!part.isStringLiteral())
|
|
100
|
-
return undefined;
|
|
101
|
-
values.push(part.value);
|
|
102
|
-
}
|
|
103
|
-
return values.length ? values : undefined;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* The string fields of a request's parameters that the player's rules may
|
|
107
|
-
* read (`event`, `stage`): those of an object literal whose value is one
|
|
108
|
-
* string the types fix.
|
|
109
|
-
*/
|
|
110
|
-
function stringFields(ts, checker, node) {
|
|
111
|
-
if (!node || !ts.isObjectLiteralExpression(node))
|
|
112
|
-
return undefined;
|
|
113
|
-
const fields = {};
|
|
114
|
-
for (const property of node.properties) {
|
|
115
|
-
if (!ts.isPropertyAssignment(property))
|
|
116
|
-
continue;
|
|
117
|
-
const name = property.name;
|
|
118
|
-
const key = ts.isIdentifier(name) || ts.isStringLiteralLike(name)
|
|
119
|
-
? name.text
|
|
120
|
-
: undefined;
|
|
121
|
-
const values = literalStrings(ts, checker, property.initializer);
|
|
122
|
-
if (key !== undefined && values?.length === 1)
|
|
123
|
-
fields[key] = values[0];
|
|
124
|
-
}
|
|
125
|
-
return Object.keys(fields).length ? fields : undefined;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Every use, in `options.files`, of a member whose capability the manifest
|
|
129
|
-
* does not declare, in file and position order.
|
|
130
|
-
*
|
|
131
|
-
* @internal
|
|
132
|
-
*/
|
|
133
|
-
export function findUndeclaredCapabilities(ts, program, options) {
|
|
134
|
-
return checkCapabilities(ts, program, options).findings;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* The capability check: the uses of members whose capability the manifest does
|
|
138
|
-
* not declare (`findings`, as {@link findUndeclaredCapabilities}), and the
|
|
139
|
-
* calls whose capability depends on a name the checker cannot read
|
|
140
|
-
* (`unchecked`).
|
|
141
|
-
*
|
|
142
|
-
* A call of `plugin.player.on` or `plugin.wire.on` is checked by its event
|
|
143
|
-
* name, one of `plugin.wire.request` by its method name and the string
|
|
144
|
-
* fields of its parameters (`{ event: "…" }`), when the types fix them.
|
|
145
|
-
*
|
|
146
|
-
* @internal
|
|
147
|
-
*/
|
|
148
|
-
export function checkCapabilities(ts, program, options) {
|
|
149
|
-
const rules = options.rules ?? RULES;
|
|
150
|
-
const findings = [];
|
|
151
|
-
const unchecked = [];
|
|
152
|
-
const files = options.files
|
|
153
|
-
.map((file) => program.getSourceFile(file))
|
|
154
|
-
.filter((file) => !!file);
|
|
155
|
-
if (!files.length)
|
|
156
|
-
return { findings, unchecked };
|
|
157
|
-
const members = sdkMembers(ts, program, rules);
|
|
158
|
-
const calls = argumentMembers(ts, program);
|
|
159
|
-
if (!members.size && !calls.size)
|
|
160
|
-
return { findings, unchecked };
|
|
161
|
-
const checker = program.getTypeChecker();
|
|
162
|
-
const apiOf = (table, symbol) => {
|
|
163
|
-
for (const declaration of symbol?.declarations ?? []) {
|
|
164
|
-
const api = table.get(declaration);
|
|
165
|
-
if (api)
|
|
166
|
-
return api;
|
|
167
|
-
}
|
|
168
|
-
return undefined;
|
|
169
|
-
};
|
|
170
|
-
for (const file of files) {
|
|
171
|
-
const position = (name) => {
|
|
172
|
-
const start = name.getStart(file);
|
|
173
|
-
const { line, character } = file.getLineAndCharacterOfPosition(start);
|
|
174
|
-
return {
|
|
175
|
-
file: file.fileName,
|
|
176
|
-
line: line + 1,
|
|
177
|
-
column: character + 1,
|
|
178
|
-
start,
|
|
179
|
-
length: name.getEnd() - start,
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
const missing = (name, api, needs, shown = api) => {
|
|
183
|
-
for (const need of needs) {
|
|
184
|
-
if (options.capabilities.includes(need.capability))
|
|
185
|
-
continue;
|
|
186
|
-
findings.push({
|
|
187
|
-
...position(name),
|
|
188
|
-
api,
|
|
189
|
-
capability: need.capability,
|
|
190
|
-
method: need.method,
|
|
191
|
-
...(need.requiredBy ? { requiredBy: need.requiredBy } : {}),
|
|
192
|
-
message: need.requiredBy
|
|
193
|
-
? `${shown} needs the capability "${need.capability}" (required by "${need.requiredBy}"), which manifest.json does not declare`
|
|
194
|
-
: `${shown} needs the capability "${need.capability}", which manifest.json does not declare`,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
const report = (name, symbol) => {
|
|
199
|
-
const api = apiOf(members, symbol);
|
|
200
|
-
if (!api)
|
|
201
|
-
return;
|
|
202
|
-
missing(name, api, memberNeeds(api, options.capabilities, rules) ?? []);
|
|
203
|
-
};
|
|
204
|
-
/** A call of a member of `ARGUMENT_APIS`, by its name argument. */
|
|
205
|
-
const call = (node) => {
|
|
206
|
-
const callee = node.expression;
|
|
207
|
-
const name = ts.isPropertyAccessExpression(callee)
|
|
208
|
-
? callee.name
|
|
209
|
-
: ts.isElementAccessExpression(callee) &&
|
|
210
|
-
ts.isStringLiteralLike(callee.argumentExpression)
|
|
211
|
-
? callee.argumentExpression
|
|
212
|
-
: undefined;
|
|
213
|
-
if (!name)
|
|
214
|
-
return;
|
|
215
|
-
const api = apiOf(calls, checker.getSymbolAtLocation(name));
|
|
216
|
-
if (!api)
|
|
217
|
-
return;
|
|
218
|
-
const kind = ARGUMENT_APIS[api];
|
|
219
|
-
const values = literalStrings(ts, checker, node.arguments[0]);
|
|
220
|
-
// One name, or not checked: a union could be any of its names at run
|
|
221
|
-
// time, and none of them is known to be used.
|
|
222
|
-
if (values?.length !== 1) {
|
|
223
|
-
unchecked.push({
|
|
224
|
-
...position(name),
|
|
225
|
-
api,
|
|
226
|
-
message: `${api} with ${kind === "event" ? "an event" : "a method"} name that is not one literal: its capability is not checked here (the player checks it)`,
|
|
227
|
-
});
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
const params = kind === "method"
|
|
231
|
-
? stringFields(ts, checker, node.arguments[1])
|
|
232
|
-
: undefined;
|
|
233
|
-
for (const value of values) {
|
|
234
|
-
const requests = argumentRequests(kind, value, params, rules);
|
|
235
|
-
const shown = `${api}(${JSON.stringify(value)})`;
|
|
236
|
-
if (!requests) {
|
|
237
|
-
unchecked.push({
|
|
238
|
-
...position(name),
|
|
239
|
-
api,
|
|
240
|
-
message: `${shown}: the player's capability table has no such method; not checked`,
|
|
241
|
-
});
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
missing(name, api, requestsNeed(requests, options.capabilities, rules), shown);
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
/**
|
|
248
|
-
* A member of `ARGUMENT_APIS` taken other than by a direct call (`const
|
|
249
|
-
* { request } = plugin.wire`, `const on = plugin.player.on`): its calls
|
|
250
|
-
* cannot be followed, so it is unchecked where it is taken.
|
|
251
|
-
*/
|
|
252
|
-
const taken = (name, symbol) => {
|
|
253
|
-
const api = apiOf(calls, symbol);
|
|
254
|
-
if (!api)
|
|
255
|
-
return;
|
|
256
|
-
const access = name.parent;
|
|
257
|
-
const parent = access?.parent;
|
|
258
|
-
if (access &&
|
|
259
|
-
(ts.isPropertyAccessExpression(access) ||
|
|
260
|
-
ts.isElementAccessExpression(access)) &&
|
|
261
|
-
parent &&
|
|
262
|
-
ts.isCallExpression(parent) &&
|
|
263
|
-
parent.expression === access)
|
|
264
|
-
return; // a direct call: `call` checks it
|
|
265
|
-
unchecked.push({
|
|
266
|
-
...position(name),
|
|
267
|
-
api,
|
|
268
|
-
message: `${api} taken other than by a direct call: the calls of it are not checked here (the player checks them)`,
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
const visit = (node) => {
|
|
272
|
-
if (ts.isCallExpression(node))
|
|
273
|
-
call(node);
|
|
274
|
-
if (ts.isPropertyAccessExpression(node)) {
|
|
275
|
-
const symbol = checker.getSymbolAtLocation(node.name);
|
|
276
|
-
report(node.name, symbol);
|
|
277
|
-
taken(node.name, symbol);
|
|
278
|
-
}
|
|
279
|
-
else if (ts.isElementAccessExpression(node) &&
|
|
280
|
-
ts.isStringLiteralLike(node.argumentExpression)) {
|
|
281
|
-
const symbol = checker.getSymbolAtLocation(node.argumentExpression);
|
|
282
|
-
report(node.argumentExpression, symbol);
|
|
283
|
-
taken(node.argumentExpression, symbol);
|
|
284
|
-
}
|
|
285
|
-
else if (ts.isBindingElement(node) &&
|
|
286
|
-
ts.isObjectBindingPattern(node.parent)) {
|
|
287
|
-
const name = node.propertyName ?? node.name;
|
|
288
|
-
const text = ts.isIdentifier(name) || ts.isStringLiteralLike(name)
|
|
289
|
-
? name.text
|
|
290
|
-
: undefined;
|
|
291
|
-
if (text !== undefined) {
|
|
292
|
-
const symbol = checker
|
|
293
|
-
.getTypeAtLocation(node.parent)
|
|
294
|
-
.getProperty(text);
|
|
295
|
-
report(name, symbol);
|
|
296
|
-
taken(name, symbol);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
ts.forEachChild(node, visit);
|
|
300
|
-
};
|
|
301
|
-
visit(file);
|
|
302
|
-
}
|
|
303
|
-
return { findings, unchecked };
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Whether a file belongs to the plugin's production code, given the
|
|
307
|
-
* directory of its `manifest.json`: not in `tests/`, `node_modules/`,
|
|
308
|
-
* `dist/`, `vendor/` or a dot directory (what `vestra-plugin build` leaves
|
|
309
|
-
* out), and not a declaration file.
|
|
310
|
-
*
|
|
311
|
-
* @internal
|
|
312
|
-
*/
|
|
313
|
-
export function isPluginSource(directory, file) {
|
|
314
|
-
const normal = (path) => path.replaceAll("\\", "/").replace(/\/$/, "");
|
|
315
|
-
const base = normal(directory);
|
|
316
|
-
const path = normal(file);
|
|
317
|
-
const caseless = /^[a-z]:\//i.test(path);
|
|
318
|
-
const same = (a, b) => caseless ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
319
|
-
if (!same(path.slice(0, base.length + 1), `${base}/`))
|
|
320
|
-
return false;
|
|
321
|
-
if (/\.d\.[mc]?ts$/.test(path) || !/\.[mc]?tsx?$/.test(path))
|
|
322
|
-
return false;
|
|
323
|
-
const parts = path
|
|
324
|
-
.slice(base.length + 1)
|
|
325
|
-
.split("/")
|
|
326
|
-
.slice(0, -1);
|
|
327
|
-
return !parts.some((part) => part.startsWith(".") ||
|
|
328
|
-
["tests", "node_modules", "dist", "vendor"].includes(part));
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* The edit that adds a capability to a manifest's `capabilities` array, in
|
|
332
|
-
* the array's own layout; `undefined` when the text has no such array.
|
|
333
|
-
*
|
|
334
|
-
* @internal
|
|
335
|
-
*/
|
|
336
|
-
export function addCapabilityEdit(ts, text, capability) {
|
|
337
|
-
const json = ts.parseJsonText("manifest.json", text);
|
|
338
|
-
const root = json.statements[0]?.expression;
|
|
339
|
-
if (!root || !ts.isObjectLiteralExpression(root))
|
|
340
|
-
return undefined;
|
|
341
|
-
const property = root.properties.find((each) => ts.isPropertyAssignment(each) &&
|
|
342
|
-
ts.isStringLiteral(each.name) &&
|
|
343
|
-
each.name.text === "capabilities");
|
|
344
|
-
const array = property?.initializer;
|
|
345
|
-
if (!array || !ts.isArrayLiteralExpression(array))
|
|
346
|
-
return undefined;
|
|
347
|
-
const quoted = JSON.stringify(capability);
|
|
348
|
-
const last = array.elements.at(-1);
|
|
349
|
-
if (!last) {
|
|
350
|
-
const start = array.getStart(json);
|
|
351
|
-
return {
|
|
352
|
-
start,
|
|
353
|
-
length: array.getEnd() - start,
|
|
354
|
-
newText: `[${quoted}]`,
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
const first = array.elements[0];
|
|
358
|
-
const lineStart = text.lastIndexOf("\n", first.getStart(json)) + 1;
|
|
359
|
-
const multiline = text
|
|
360
|
-
.slice(array.getStart(json), first.getStart(json))
|
|
361
|
-
.includes("\n");
|
|
362
|
-
const indent = text.slice(lineStart, first.getStart(json));
|
|
363
|
-
return {
|
|
364
|
-
start: last.getEnd(),
|
|
365
|
-
length: 0,
|
|
366
|
-
// The manifest's own line endings (CRLF on many Windows checkouts).
|
|
367
|
-
newText: multiline
|
|
368
|
-
? `,${text.includes("\r\n") ? "\r\n" : "\n"}${indent}${quoted}`
|
|
369
|
-
: `, ${quoted}`,
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Every use, in `files`, of the SDK members named by `apis`
|
|
374
|
-
* (`Interface.member`), and every request sent by name
|
|
375
|
-
* (`ARGUMENT_APIS`' `method` members: `Wire.request`), in file and position
|
|
376
|
-
* order. The same type-aware resolution as {@link checkCapabilities}, for
|
|
377
|
-
* any list of members: a use is a property access, an element access with
|
|
378
|
-
* a literal name or a destructured property whose symbol is the SDK's
|
|
379
|
-
* declaration of the member. It reads no manifest and no capability rule
|
|
380
|
-
* (the capability scan, `capability-scan.ts`, gives it its own lists).
|
|
381
|
-
*
|
|
382
|
-
* `resolved` is `false` when the program has no import of
|
|
383
|
-
* `@vestra-player/sdk` that resolves: nothing can be found by type then.
|
|
384
|
-
*
|
|
385
|
-
* @internal
|
|
386
|
-
*/
|
|
387
|
-
export function findMemberUses(ts, program, options) {
|
|
388
|
-
const uses = [];
|
|
389
|
-
const requests = [];
|
|
390
|
-
const members = resolveMembers(ts, program, options.apis);
|
|
391
|
-
const senders = resolveMembers(ts, program, Object.entries(ARGUMENT_APIS)
|
|
392
|
-
.filter(([, kind]) => kind === "method")
|
|
393
|
-
.map(([api]) => api));
|
|
394
|
-
const resolved = members.size > 0 || senders.size > 0;
|
|
395
|
-
if (!resolved)
|
|
396
|
-
return { resolved, uses, requests };
|
|
397
|
-
const checker = program.getTypeChecker();
|
|
398
|
-
const apiOf = (table, symbol) => {
|
|
399
|
-
for (const declaration of symbol?.declarations ?? []) {
|
|
400
|
-
const api = table.get(declaration);
|
|
401
|
-
if (api)
|
|
402
|
-
return api;
|
|
403
|
-
}
|
|
404
|
-
return undefined;
|
|
405
|
-
};
|
|
406
|
-
for (const fileName of options.files) {
|
|
407
|
-
const file = program.getSourceFile(fileName);
|
|
408
|
-
if (!file)
|
|
409
|
-
continue;
|
|
410
|
-
const position = (name) => {
|
|
411
|
-
const { line, character } = file.getLineAndCharacterOfPosition(name.getStart(file));
|
|
412
|
-
return { file: file.fileName, line: line + 1, column: character + 1 };
|
|
413
|
-
};
|
|
414
|
-
const seen = (name, symbol) => {
|
|
415
|
-
const api = apiOf(members, symbol);
|
|
416
|
-
if (api)
|
|
417
|
-
uses.push({ ...position(name), api });
|
|
418
|
-
if (!apiOf(senders, symbol))
|
|
419
|
-
return;
|
|
420
|
-
// A direct call with one literal name is a request of that name;
|
|
421
|
-
// anything else (a computed name, the member taken as a value) is a
|
|
422
|
-
// request the scan cannot name.
|
|
423
|
-
const access = name.parent;
|
|
424
|
-
const call = access?.parent;
|
|
425
|
-
const direct = access &&
|
|
426
|
-
(ts.isPropertyAccessExpression(access) ||
|
|
427
|
-
ts.isElementAccessExpression(access)) &&
|
|
428
|
-
call &&
|
|
429
|
-
ts.isCallExpression(call) &&
|
|
430
|
-
call.expression === access
|
|
431
|
-
? call
|
|
432
|
-
: undefined;
|
|
433
|
-
const values = direct
|
|
434
|
-
? literalStrings(ts, checker, direct.arguments[0])
|
|
435
|
-
: undefined;
|
|
436
|
-
requests.push({
|
|
437
|
-
...position(name),
|
|
438
|
-
method: values?.length === 1 ? values[0] : undefined,
|
|
439
|
-
});
|
|
440
|
-
};
|
|
441
|
-
const visit = (node) => {
|
|
442
|
-
if (ts.isPropertyAccessExpression(node))
|
|
443
|
-
seen(node.name, checker.getSymbolAtLocation(node.name));
|
|
444
|
-
else if (ts.isElementAccessExpression(node) &&
|
|
445
|
-
ts.isStringLiteralLike(node.argumentExpression))
|
|
446
|
-
seen(node.argumentExpression, checker.getSymbolAtLocation(node.argumentExpression));
|
|
447
|
-
else if (ts.isBindingElement(node) &&
|
|
448
|
-
ts.isObjectBindingPattern(node.parent)) {
|
|
449
|
-
const name = node.propertyName ?? node.name;
|
|
450
|
-
const text = ts.isIdentifier(name) || ts.isStringLiteralLike(name)
|
|
451
|
-
? name.text
|
|
452
|
-
: undefined;
|
|
453
|
-
if (text !== undefined)
|
|
454
|
-
seen(name, checker.getTypeAtLocation(node.parent).getProperty(text));
|
|
455
|
-
}
|
|
456
|
-
ts.forEachChild(node, visit);
|
|
457
|
-
};
|
|
458
|
-
visit(file);
|
|
459
|
-
}
|
|
460
|
-
return { resolved, uses, requests };
|
|
461
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { ApiRequest } from "./api-requests.ts";
|
|
2
|
-
/**
|
|
3
|
-
* What a request needs, as the player's `capabilities.json` writes it:
|
|
4
|
-
* `null` (nothing), a capability name, a choice by a string parameter, or a
|
|
5
|
-
* choice by whether the plugin declared a capability.
|
|
6
|
-
*
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export type Needs = null | string | {
|
|
10
|
-
readonly param: string;
|
|
11
|
-
readonly cases: Readonly<Record<string, string | null>>;
|
|
12
|
-
readonly otherwise: string | null;
|
|
13
|
-
} | {
|
|
14
|
-
readonly ifDeclared: string;
|
|
15
|
-
readonly then: string;
|
|
16
|
-
readonly otherwise: string;
|
|
17
|
-
};
|
|
18
|
-
/** @internal One RPC method of the player's table (`prefix.*` covers a prefix). */
|
|
19
|
-
export interface HostMethod {
|
|
20
|
-
readonly name: string;
|
|
21
|
-
readonly needs: Needs;
|
|
22
|
-
}
|
|
23
|
-
/** @internal One manifest capability of the player's table. */
|
|
24
|
-
export interface HostCapability {
|
|
25
|
-
readonly name: string;
|
|
26
|
-
readonly label: string;
|
|
27
|
-
readonly risky: boolean;
|
|
28
|
-
/** Only built-in plugins may declare it (absent: `false`). */
|
|
29
|
-
readonly builtinOnly?: boolean;
|
|
30
|
-
readonly requires: readonly string[];
|
|
31
|
-
readonly residency: string;
|
|
32
|
-
readonly methods: readonly HostMethod[];
|
|
33
|
-
}
|
|
34
|
-
/** @internal The player's `src/host/capabilities.json`. */
|
|
35
|
-
export interface HostCapabilities {
|
|
36
|
-
readonly about: string;
|
|
37
|
-
readonly apiVersion: string;
|
|
38
|
-
readonly capabilities: readonly HostCapability[];
|
|
39
|
-
readonly uncapable: readonly HostMethod[];
|
|
40
|
-
}
|
|
41
|
-
/** @internal Both tables; tests pass their own. */
|
|
42
|
-
export interface CapabilityRules {
|
|
43
|
-
readonly host: HostCapabilities;
|
|
44
|
-
readonly apis: Readonly<Record<string, readonly ApiRequest[]>>;
|
|
45
|
-
}
|
|
46
|
-
/** @internal The SDK's rules: the synced player table and `API_REQUESTS`. */
|
|
47
|
-
export declare const RULES: CapabilityRules;
|
|
48
|
-
/**
|
|
49
|
-
* The player's entry for a method, as the player routes it: the exact name
|
|
50
|
-
* first, then the first `prefix.*` entry whose prefix it starts with.
|
|
51
|
-
* `undefined`: the player does not know the method.
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
export declare function hostMethod(method: string, host?: HostCapabilities): HostMethod | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* The capability one request needs, as the player decides it
|
|
58
|
-
* (`capabilities::Route::needs`): `null` for none, `undefined` for a method
|
|
59
|
-
* the player does not know.
|
|
60
|
-
*
|
|
61
|
-
* @param method - The wire method.
|
|
62
|
-
* @param params - Its string parameters that a `Needs::Param` rule reads.
|
|
63
|
-
* @param declared - Whether the plugin declared a capability.
|
|
64
|
-
*
|
|
65
|
-
* @internal
|
|
66
|
-
*/
|
|
67
|
-
export declare function requestNeeds(method: string, params: Readonly<Record<string, string>> | undefined, declared: (capability: string) => boolean, host?: HostCapabilities): string | null | undefined;
|
|
68
|
-
/**
|
|
69
|
-
* One capability a member needs: the request that needs it, and the
|
|
70
|
-
* capability whose `requires` brought it in (absent when the request needs
|
|
71
|
-
* it directly).
|
|
72
|
-
*
|
|
73
|
-
* @internal
|
|
74
|
-
*/
|
|
75
|
-
export interface MemberNeed {
|
|
76
|
-
readonly capability: string;
|
|
77
|
-
readonly method: string;
|
|
78
|
-
readonly requiredBy?: string;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Every capability a member of the plugin API needs with the given manifest:
|
|
82
|
-
* those its requests need and, through `requires`, those they need in turn.
|
|
83
|
-
* `undefined`: the member is not in the table (it needs none).
|
|
84
|
-
*
|
|
85
|
-
* @param api - The member as `Interface.member` (`Player.seek`).
|
|
86
|
-
* @param capabilities - The manifest's capabilities.
|
|
87
|
-
*
|
|
88
|
-
* @internal
|
|
89
|
-
*/
|
|
90
|
-
export declare function memberNeeds(api: string, capabilities: readonly string[], rules?: CapabilityRules): MemberNeed[] | undefined;
|
|
91
|
-
/**
|
|
92
|
-
* The requests of a call to a member of `ARGUMENT_APIS`, given the value of its
|
|
93
|
-
* first argument and the string fields of its second: a subscribed event's
|
|
94
|
-
* `events.subscribe`, nothing for an event that arrives unasked, or the named
|
|
95
|
-
* method. `undefined`: a method the player's table does not know (not checked).
|
|
96
|
-
*
|
|
97
|
-
* @param kind - What the argument names (`ARGUMENT_APIS`).
|
|
98
|
-
* @param name - The event or method name.
|
|
99
|
-
* @param params - String fields of the second argument (`method` only).
|
|
100
|
-
*
|
|
101
|
-
* @internal
|
|
102
|
-
*/
|
|
103
|
-
export declare function argumentRequests(kind: "event" | "method", name: string, params?: Readonly<Record<string, string>>, rules?: CapabilityRules): ApiRequest[] | undefined;
|
|
104
|
-
/**
|
|
105
|
-
* Every capability a list of requests needs with the given manifest (see
|
|
106
|
-
* {@link memberNeeds}).
|
|
107
|
-
*
|
|
108
|
-
* @internal
|
|
109
|
-
*/
|
|
110
|
-
export declare function requestsNeed(requests: readonly ApiRequest[], capabilities: readonly string[], rules?: CapabilityRules): MemberNeed[];
|
|
111
|
-
/**
|
|
112
|
-
* `CAPABILITY_INFO` from the tables: the label, highlight and requirements
|
|
113
|
-
* from the player's table; the members from `API_REQUESTS` (every member a
|
|
114
|
-
* request of which needs the capability, in the table's order; requests
|
|
115
|
-
* marked `also` are left out, as they are documented at the member).
|
|
116
|
-
*
|
|
117
|
-
* @internal
|
|
118
|
-
*/
|
|
119
|
-
export declare function capabilityInfo(rules?: CapabilityRules): Record<string, {
|
|
120
|
-
apis: string[];
|
|
121
|
-
requires: string[];
|
|
122
|
-
label: string;
|
|
123
|
-
risky: boolean;
|
|
124
|
-
builtinOnly: boolean;
|
|
125
|
-
}>;
|