@vestra-player/sdk 1.7.20 → 1.9.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 +72 -0
- package/README.md +2 -2
- package/bin/vestra-plugin.mjs +139 -100
- package/capability-scan.json +369 -0
- package/dist/api-requests.d.ts +11 -36
- package/dist/api-requests.js +22 -47
- package/dist/capability-scan.d.ts +95 -0
- package/dist/capability-scan.js +249 -0
- package/dist/commands.d.ts +35 -0
- package/dist/commands.js +42 -1
- package/dist/docs-tree.json.gz +0 -0
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +1 -1
- 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/mpv.d.ts +139 -0
- package/dist/mpv.js +496 -0
- package/dist/player-runtime.d.ts +3 -3
- package/dist/player-runtime.js +3 -3
- 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 +6 -14
- package/dist/plugin/connection.d.ts +26 -7
- package/dist/plugin/connection.js +68 -36
- package/dist/plugin/drops.js +1 -1
- package/dist/plugin/index.js +9 -15
- package/dist/plugin/media.js +0 -12
- package/dist/plugin/mpv.d.ts +3 -0
- package/dist/plugin/mpv.js +91 -0
- package/dist/plugin/packages.js +1 -2
- package/dist/plugin/player/events.d.ts +4 -3
- package/dist/plugin/player/events.js +7 -6
- package/dist/plugin/player.d.ts +21 -13
- package/dist/plugin/player.js +56 -21
- package/dist/plugin/scope.d.ts +1 -0
- package/dist/plugin/scope.js +2 -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 +43 -24
- package/dist/plugin/testing/index.d.ts +75 -114
- package/dist/plugin/testing/index.js +83 -102
- package/dist/plugin/testing/mpv.d.ts +7 -0
- package/dist/plugin/testing/mpv.js +90 -0
- package/dist/plugin/testing/processing.js +1 -1
- package/dist/plugin/testing/services.js +0 -1
- package/dist/plugin/timeline.d.ts +2 -3
- package/dist/plugin/timeline.js +4 -8
- package/dist/plugin/types/base.d.ts +49 -88
- package/dist/plugin/types/commands.d.ts +44 -77
- package/dist/plugin/types/packages.d.ts +17 -55
- package/dist/plugin/types/playback.d.ts +302 -135
- 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/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/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 +5 -5
- package/package.json +4 -3
- package/slint/vestra/widgets.slint +12 -4
- package/dist/capabilities.d.ts +0 -107
- package/dist/capabilities.js +0 -69
- package/dist/capability-check.d.ts +0 -133
- package/dist/capability-check.js +0 -371
- 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 -477
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The capability checker: every use of a plugin API member whose capability
|
|
3
|
-
* the plugin's `manifest.json` does not declare. `vestra-plugin check` (and
|
|
4
|
-
* so `build` and `pack`) and the TypeScript language-service plugin
|
|
5
|
-
* (`@vestra-player/sdk/ts-plugin`) both run it; the rule is
|
|
6
|
-
* `capability-rules.ts` (the player's table and the SDK's requests).
|
|
7
|
-
*
|
|
8
|
-
* It is type-aware: a use is a property access, an element access with a
|
|
9
|
-
* literal name or a destructured property whose symbol is the SDK's
|
|
10
|
-
* declaration of a member in the table, however the object was reached
|
|
11
|
-
* (`plugin.player.seek`, `const { player } = plugin; player.seek`, a
|
|
12
|
-
* parameter typed `Player`, a `Panel` from `panels.mount`). Not detected:
|
|
13
|
-
* access with a computed name (`player[name]`), values typed `any` or
|
|
14
|
-
* `unknown`, plain JavaScript without types, members inherited from `View`
|
|
15
|
-
* (their object comes from a call that is checked) and options that need
|
|
16
|
-
* more (a `processed` capture, a file resolver).
|
|
17
|
-
*
|
|
18
|
-
* Members whose capability depends on an argument (`plugin.player.on` and
|
|
19
|
-
* `plugin.wire.on` by event name, `plugin.wire.request` by method name,
|
|
20
|
-
* `ARGUMENT_APIS`) are checked by that argument when its type fixes it to one
|
|
21
|
-
* string (a literal, a constant); otherwise (a computed name, a union of
|
|
22
|
-
* several, the member taken by destructuring or as a value) the call is
|
|
23
|
-
* reported as unchecked ({@link checkCapabilities}), and the player still
|
|
24
|
-
* checks it.
|
|
25
|
-
*
|
|
26
|
-
* The TypeScript module is passed in, never imported: the CLI uses the
|
|
27
|
-
* SDK's own compiler, the editor its TypeScript server's.
|
|
28
|
-
*
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
import type TS from "typescript";
|
|
32
|
-
import type { CapabilityRules } from "./capability-rules.ts";
|
|
33
|
-
/** @internal The module plugins import the API types from. */
|
|
34
|
-
export declare const SDK_MODULE = "@vestra-player/sdk";
|
|
35
|
-
/** @internal The diagnostic code the editor shows (and its quick fix keys on). */
|
|
36
|
-
export declare const CAPABILITY_DIAGNOSTIC = 95301;
|
|
37
|
-
/**
|
|
38
|
-
* @internal The warning code the editor shows for a call whose capability
|
|
39
|
-
* the checker cannot read (`plugin.wire.request` with a computed method).
|
|
40
|
-
*/
|
|
41
|
-
export declare const CAPABILITY_UNCHECKED = 95302;
|
|
42
|
-
/** @internal One use of a member whose capability is not declared. */
|
|
43
|
-
export interface CapabilityFinding {
|
|
44
|
-
/** The source file, as the program names it. */
|
|
45
|
-
readonly file: string;
|
|
46
|
-
/** 1-based line and column of the member's name. */
|
|
47
|
-
readonly line: number;
|
|
48
|
-
readonly column: number;
|
|
49
|
-
/** Offset and length of the member's name in the file. */
|
|
50
|
-
readonly start: number;
|
|
51
|
-
readonly length: number;
|
|
52
|
-
/** The member, `Interface.member` (`Player.seek`). */
|
|
53
|
-
readonly api: string;
|
|
54
|
-
/** The capability to declare. */
|
|
55
|
-
readonly capability: string;
|
|
56
|
-
/** The request that needs it. */
|
|
57
|
-
readonly method: string;
|
|
58
|
-
/** The declared-or-needed capability whose `requires` names it. */
|
|
59
|
-
readonly requiredBy?: string;
|
|
60
|
-
/** One line for people. */
|
|
61
|
-
readonly message: string;
|
|
62
|
-
}
|
|
63
|
-
/** @internal */
|
|
64
|
-
export interface CheckOptions {
|
|
65
|
-
/** The files to check (others in the program are only read for types). */
|
|
66
|
-
readonly files: readonly string[];
|
|
67
|
-
/** The manifest's `capabilities`. */
|
|
68
|
-
readonly capabilities: readonly string[];
|
|
69
|
-
/** Default: the SDK's rules. */
|
|
70
|
-
readonly rules?: CapabilityRules;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* @internal A call whose capability the checker cannot tell: a member of
|
|
74
|
-
* `ARGUMENT_APIS` (`plugin.wire.request`, `player.on`, `wire.on`) whose name
|
|
75
|
-
* argument is not a string the types fix, or a method the player's table does
|
|
76
|
-
* not know. The player still checks it at run time.
|
|
77
|
-
*/
|
|
78
|
-
export interface UncheckedCall {
|
|
79
|
-
readonly file: string;
|
|
80
|
-
/** 1-based line and column of the member's name. */
|
|
81
|
-
readonly line: number;
|
|
82
|
-
readonly column: number;
|
|
83
|
-
/** Offset and length of the member's name in the file. */
|
|
84
|
-
readonly start: number;
|
|
85
|
-
readonly length: number;
|
|
86
|
-
/** The member, `Interface.member` (`Wire.request`). */
|
|
87
|
-
readonly api: string;
|
|
88
|
-
/** One line for people. */
|
|
89
|
-
readonly message: string;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Every use, in `options.files`, of a member whose capability the manifest
|
|
93
|
-
* does not declare, in file and position order.
|
|
94
|
-
*
|
|
95
|
-
* @internal
|
|
96
|
-
*/
|
|
97
|
-
export declare function findUndeclaredCapabilities(ts: typeof TS, program: TS.Program, options: CheckOptions): CapabilityFinding[];
|
|
98
|
-
/**
|
|
99
|
-
* The capability check: the uses of members whose capability the manifest does
|
|
100
|
-
* not declare (`findings`, as {@link findUndeclaredCapabilities}), and the
|
|
101
|
-
* calls whose capability depends on a name the checker cannot read
|
|
102
|
-
* (`unchecked`).
|
|
103
|
-
*
|
|
104
|
-
* A call of `plugin.player.on` or `plugin.wire.on` is checked by its event
|
|
105
|
-
* name, one of `plugin.wire.request` by its method name and the string
|
|
106
|
-
* fields of its parameters (`{ event: "…" }`), when the types fix them.
|
|
107
|
-
*
|
|
108
|
-
* @internal
|
|
109
|
-
*/
|
|
110
|
-
export declare function checkCapabilities(ts: typeof TS, program: TS.Program, options: CheckOptions): {
|
|
111
|
-
findings: CapabilityFinding[];
|
|
112
|
-
unchecked: UncheckedCall[];
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Whether a file belongs to the plugin's production code, given the
|
|
116
|
-
* directory of its `manifest.json`: not in `tests/`, `node_modules/`,
|
|
117
|
-
* `dist/`, `vendor/` or a dot directory (what `vestra-plugin build` leaves
|
|
118
|
-
* out), and not a declaration file.
|
|
119
|
-
*
|
|
120
|
-
* @internal
|
|
121
|
-
*/
|
|
122
|
-
export declare function isPluginSource(directory: string, file: string): boolean;
|
|
123
|
-
/**
|
|
124
|
-
* The edit that adds a capability to a manifest's `capabilities` array, in
|
|
125
|
-
* the array's own layout; `undefined` when the text has no such array.
|
|
126
|
-
*
|
|
127
|
-
* @internal
|
|
128
|
-
*/
|
|
129
|
-
export declare function addCapabilityEdit(ts: typeof TS, text: string, capability: string): {
|
|
130
|
-
start: number;
|
|
131
|
-
length: number;
|
|
132
|
-
newText: string;
|
|
133
|
-
} | undefined;
|
package/dist/capability-check.js
DELETED
|
@@ -1,371 +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
|
-
}
|
|
@@ -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
|
-
}>;
|