@vestra-player/sdk 1.10.1 → 1.11.0-rc.2

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/bin/vestra-plugin.mjs +1 -131
  3. package/dist/api-requests.d.ts +1 -1
  4. package/dist/api-requests.js +9 -2
  5. package/dist/docs-tree.json.gz +0 -0
  6. package/dist/manifest.d.ts +0 -5
  7. package/dist/manifest.js +1 -8
  8. package/dist/mpv.js +1 -1
  9. package/dist/plugin/appearance.d.ts +2 -2
  10. package/dist/plugin/appearance.js +3 -3
  11. package/dist/plugin/connection.d.ts +38 -28
  12. package/dist/plugin/connection.js +101 -98
  13. package/dist/plugin/index.js +8 -6
  14. package/dist/plugin/passes.js +1 -1
  15. package/dist/plugin/player/events.d.ts +18 -9
  16. package/dist/plugin/player/events.js +36 -11
  17. package/dist/plugin/player.d.ts +45 -28
  18. package/dist/plugin/player.js +77 -68
  19. package/dist/plugin/scope.d.ts +2 -9
  20. package/dist/plugin/scope.js +22 -27
  21. package/dist/plugin/subtitles.d.ts +6 -1
  22. package/dist/plugin/subtitles.js +18 -2
  23. package/dist/plugin/testing/commands.js +1 -1
  24. package/dist/plugin/testing/facts.d.ts +46 -0
  25. package/dist/plugin/testing/facts.js +106 -0
  26. package/dist/plugin/testing/index.d.ts +12 -14
  27. package/dist/plugin/testing/index.js +52 -18
  28. package/dist/plugin/testing/media.js +6 -0
  29. package/dist/plugin/testing/revoke.d.ts +15 -0
  30. package/dist/plugin/testing/revoke.js +13 -0
  31. package/dist/plugin/testing/transport.js +8 -0
  32. package/dist/plugin/timeline.d.ts +2 -2
  33. package/dist/plugin/timeline.js +3 -3
  34. package/dist/plugin/types/base.d.ts +15 -15
  35. package/dist/plugin/types/commands.d.ts +8 -8
  36. package/dist/plugin/types/playback.d.ts +247 -116
  37. package/dist/plugin/types/plugin-wire.d.ts +2 -2
  38. package/dist/plugin/types/processing.d.ts +2 -3
  39. package/dist/plugin/types/subtitles.d.ts +9 -8
  40. package/dist/plugin/types/ui-layout.d.ts +32 -17
  41. package/dist/plugin/types/ui-locale.d.ts +9 -9
  42. package/dist/plugin/types/ui-shell.d.ts +7 -6
  43. package/dist/plugin/view/layout.d.ts +33 -1
  44. package/dist/plugin/view/layout.js +63 -34
  45. package/dist/plugin/window.d.ts +9 -1
  46. package/dist/plugin/window.js +14 -2
  47. package/dist/processing.d.ts +2 -2
  48. package/dist/request-queue.d.ts +7 -3
  49. package/dist/request-queue.js +19 -5
  50. package/dist/ts-plugin.d.ts +3 -4
  51. package/dist/ts-plugin.js +1 -1
  52. package/dist/wire.d.ts +1 -1
  53. package/dist/wire.js +1 -1
  54. package/llms.txt +3 -3
  55. package/package.json +2 -4
  56. package/capability-scan.json +0 -389
  57. package/dist/capability-scan.d.ts +0 -95
  58. package/dist/capability-scan.js +0 -249
  59. package/dist/member-uses.d.ts +0 -61
  60. package/dist/member-uses.js +0 -160
@@ -1,249 +0,0 @@
1
- /**
2
- * The capability scan: which boundary categories a plugin's code uses
3
- * (`player`, `plugins`, `clipboard`, `credentials`, `camera`, `microphone`,
4
- * `screen`, `notifications`), read from its source. `vestra-plugin scan`
5
- * prints the result; the plugin repository's index and the store show it.
6
- *
7
- * The table is `capability-scan.json` at the package's root, maintained by
8
- * hand: every method of the public API is in one category's list or in
9
- * `none`'s, and every request the SDK sends has a category by name or
10
- * prefix (test/capability-scan.test.ts). Nothing here is read at run time;
11
- * since 1.9.0 the scan is the only disclosure (manifests declare nothing).
12
- *
13
- * TypeScript files are scanned by type (`findMemberUses`, member-uses.ts): a member counts
14
- * however its object was reached. JavaScript files have no types and are
15
- * scanned by name, best effort (`scanNamesInto`); the result says which
16
- * way each file was read.
17
- *
18
- * The TypeScript module is passed in, never imported (as in
19
- * member-uses.ts). Node only: it reads the table from disk.
20
- *
21
- * @internal
22
- */
23
- import { readFileSync } from "node:fs";
24
- import { findMemberUses } from "./member-uses.js";
25
- /** @internal The scan's categories, in the order results list them. */
26
- export const SCAN_CATEGORIES = [
27
- "player",
28
- "plugins",
29
- "clipboard",
30
- "credentials",
31
- "camera",
32
- "microphone",
33
- "screen",
34
- "notifications",
35
- ];
36
- /** @internal The version of the result's format (`scan`). */
37
- export const SCAN_FORMAT = 1;
38
- let table;
39
- /**
40
- * `capability-scan.json`, read once from the package's root (one level
41
- * above this module, in `src/` and in `dist/` alike).
42
- *
43
- * @internal
44
- */
45
- export function scanTable() {
46
- table ??= JSON.parse(readFileSync(new URL("../capability-scan.json", import.meta.url), "utf8"));
47
- return table;
48
- }
49
- /** The category of a member; `undefined` for `none` and for unknown names. */
50
- function memberCategories(scan) {
51
- const categories = new Map();
52
- for (const category of SCAN_CATEGORIES)
53
- for (const member of scan.categories[category].members)
54
- categories.set(member, category);
55
- return categories;
56
- }
57
- /**
58
- * The category of a request by name, as the player routes a method: the
59
- * exact name first, then the first `prefix.*` entry it starts with.
60
- * `null`: in `none`; `undefined`: the table does not know the method.
61
- *
62
- * @internal
63
- */
64
- export function requestCategory(method, scan = scanTable()) {
65
- const lists = [
66
- ...SCAN_CATEGORIES.map((category) => [
67
- category,
68
- scan.categories[category].requests,
69
- ]),
70
- [null, scan.none.requests],
71
- ];
72
- for (const [category, requests] of lists)
73
- if (requests.includes(method))
74
- return category;
75
- for (const [category, requests] of lists)
76
- if (requests.some((entry) => entry.endsWith(".*") && method.startsWith(entry.slice(0, -1))))
77
- return category;
78
- return undefined;
79
- }
80
- /** Collects evidence and the requests the scan cannot place. */
81
- class Findings {
82
- evidence = new Map();
83
- unchecked = [];
84
- #scan;
85
- #relative;
86
- constructor(scan, relative) {
87
- this.#scan = scan;
88
- this.#relative = relative;
89
- }
90
- add(category, evidence) {
91
- const list = this.evidence.get(category) ?? [];
92
- this.evidence.set(category, list);
93
- list.push({ ...evidence, file: this.#relative(evidence.file) });
94
- }
95
- request(method, file, line, by) {
96
- if (method === undefined) {
97
- this.unchecked.push({
98
- file: this.#relative(file),
99
- line,
100
- message: "a request whose method name is not one literal string: the scan cannot tell what it asks for",
101
- });
102
- return;
103
- }
104
- const category = requestCategory(method, this.#scan);
105
- if (category === undefined)
106
- this.unchecked.push({
107
- file: this.#relative(file),
108
- line,
109
- message: `a request of ${JSON.stringify(method)}, which capability-scan.json does not list`,
110
- });
111
- else if (category !== null)
112
- this.add(category, { request: method, file, line, by });
113
- }
114
- result() {
115
- const order = (a, b) => a.file.localeCompare(b.file, "en") ||
116
- a.line - b.line ||
117
- (a.member ?? a.request ?? "").localeCompare(b.member ?? b.request ?? "", "en");
118
- const uses = SCAN_CATEGORIES.filter((category) => this.evidence.has(category));
119
- return {
120
- uses,
121
- evidence: Object.fromEntries(uses.map((category) => [
122
- category,
123
- this.evidence.get(category).toSorted(order),
124
- ])),
125
- unchecked: this.unchecked.toSorted((a, b) => a.file.localeCompare(b.file, "en") || a.line - b.line),
126
- };
127
- }
128
- }
129
- /** `Clipboard` → `clipboard`: the name a module has on `plugin`. */
130
- const lowerFirst = (name) => name[0].toLowerCase() + name.slice(1);
131
- /**
132
- * A file's uses, by name (best effort, no types; for JavaScript, and for
133
- * TypeScript that imports no SDK types): a property
134
- * access or a destructured property named as a category's member, on
135
- * something named as the member's interface is on `plugin`
136
- * (`plugin.clipboard.readText`, `clipboard.readText`,
137
- * `const { readText } = plugin.clipboard`; `Clipboard.readText` is on
138
- * `clipboard`); and a call of something named `request` with one string
139
- * literal, as a request by name. Missed: an object reached under another
140
- * name, a computed member name, a member whose interface is not a module
141
- * of `plugin` (`PackageCandidate.install`). A name that only looks like
142
- * one is counted.
143
- */
144
- function scanNamesInto(ts, fileName, text, scan, into) {
145
- // The kind (JavaScript, TypeScript) is the file name's.
146
- const source = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true);
147
- // "clipboard.readText" → category and member.
148
- const pairs = new Map();
149
- for (const [member, category] of memberCategories(scan)) {
150
- const parts = member.split(".");
151
- const name = parts.at(-1);
152
- const owner = parts.length > 2 ? parts.at(-2) : lowerFirst(parts[0]);
153
- pairs.set(`${owner}.${name}`, { category, member });
154
- }
155
- const line = (node) => source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
156
- /** The last name of an expression: `plugin.clipboard` → `clipboard`. */
157
- const lastName = (node) => {
158
- if (!node)
159
- return undefined;
160
- if (ts.isIdentifier(node))
161
- return node.text;
162
- if (ts.isPropertyAccessExpression(node))
163
- return node.name.text;
164
- if (ts.isElementAccessExpression(node) &&
165
- ts.isStringLiteralLike(node.argumentExpression))
166
- return node.argumentExpression.text;
167
- if (ts.isParenthesizedExpression(node) ||
168
- ts.isNonNullExpression(node) ||
169
- ts.isAwaitExpression(node))
170
- return lastName(node.expression);
171
- return undefined;
172
- };
173
- const member = (owner, name, at) => {
174
- const found = owner === undefined ? undefined : pairs.get(`${owner}.${name}`);
175
- if (found)
176
- into.add(found.category, {
177
- member: found.member,
178
- file: fileName,
179
- line: line(at),
180
- by: "names",
181
- });
182
- };
183
- const visit = (node) => {
184
- if (ts.isPropertyAccessExpression(node))
185
- member(lastName(node.expression), node.name.text, node.name);
186
- else if (ts.isElementAccessExpression(node) &&
187
- ts.isStringLiteralLike(node.argumentExpression))
188
- member(lastName(node.expression), node.argumentExpression.text, node.argumentExpression);
189
- else if (ts.isBindingElement(node) &&
190
- ts.isObjectBindingPattern(node.parent)) {
191
- const name = node.propertyName ?? node.name;
192
- const declaration = node.parent.parent;
193
- const from = ts.isVariableDeclaration(declaration) ||
194
- ts.isParameter(declaration) ||
195
- ts.isBindingElement(declaration)
196
- ? ts.isBindingElement(declaration)
197
- ? // `{ clipboard: { readText } }`: the outer property's name.
198
- (declaration.propertyName ?? declaration.name)
199
- : declaration.initializer
200
- : undefined;
201
- if (ts.isIdentifier(name) || ts.isStringLiteralLike(name))
202
- member(lastName(from), name.text, name);
203
- }
204
- if (ts.isCallExpression(node) && lastName(node.expression) === "request") {
205
- const first = node.arguments[0];
206
- into.request(first && ts.isStringLiteralLike(first) ? first.text : undefined, fileName, line(node.expression), "names");
207
- }
208
- ts.forEachChild(node, visit);
209
- };
210
- visit(source);
211
- }
212
- /**
213
- * The categories a plugin's files use.
214
- *
215
- * `resolved` is `false` when there are TypeScript files and the program
216
- * resolves no import of `@vestra-player/sdk` in them (the SDK is not
217
- * installed where the plugin looks, or nothing imports it): the caller
218
- * then scans those files by name too, or reports it.
219
- *
220
- * @param program - A program that has the `typed` files; `undefined` with
221
- * none.
222
- *
223
- * @internal
224
- */
225
- export function scan(ts, program, options) {
226
- const table = options.table ?? scanTable();
227
- const findings = new Findings(table, options.relative ?? ((file) => file));
228
- let resolved = true;
229
- if (program && options.typed.length) {
230
- const categories = memberCategories(table);
231
- const found = findMemberUses(ts, program, {
232
- files: options.typed,
233
- apis: categories.keys(),
234
- });
235
- resolved = found.resolved;
236
- for (const use of found.uses)
237
- findings.add(categories.get(use.api), {
238
- member: use.api,
239
- file: use.file,
240
- line: use.line,
241
- by: "types",
242
- });
243
- for (const request of found.requests)
244
- findings.request(request.method, request.file, request.line, "types");
245
- }
246
- for (const { file, text } of options.named)
247
- scanNamesInto(ts, file, text, table, findings);
248
- return { ...findings.result(), resolved };
249
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Where a plugin's TypeScript uses SDK members: the type-aware resolution
3
- * the capability scan (`capability-scan.ts`) reads a plugin's code with. A
4
- * use is a property access, an element access with a literal name or a
5
- * destructured property whose symbol is the SDK's declaration of a member
6
- * asked for, however the object was reached (`plugin.player.seek`,
7
- * `const { player } = plugin; player.seek`, a parameter typed `Player`, a
8
- * `Panel` from `panels.mount`). Not detected: access with a computed name
9
- * (`player[name]`), values typed `any` or `unknown`, plain JavaScript
10
- * without types.
11
- *
12
- * Requests sent by name (`plugin.wire.request`) are found too, with the
13
- * method when its type fixes it to one string.
14
- *
15
- * The TypeScript module is passed in, never imported: the CLI uses the
16
- * SDK's own compiler.
17
- *
18
- * @internal
19
- */
20
- import type TS from "typescript";
21
- /** @internal The module plugins import the API types from. */
22
- export declare const SDK_MODULE = "@vestra-player/sdk";
23
- /** @internal One use of an SDK member, where {@link findMemberUses} found it. */
24
- export interface MemberUse {
25
- readonly file: string;
26
- /** 1-based line and column of the member's name. */
27
- readonly line: number;
28
- readonly column: number;
29
- /** The member, as it was asked for (`Clipboard.readText`). */
30
- readonly api: string;
31
- }
32
- /**
33
- * @internal A request sent by name (`plugin.wire.request("clipboard.readText")`):
34
- * the method when the types fix it to one string, else `undefined` (a
35
- * computed name, a union of several, the member taken as a value).
36
- */
37
- export interface RequestUse {
38
- readonly file: string;
39
- readonly line: number;
40
- readonly column: number;
41
- readonly method: string | undefined;
42
- }
43
- /**
44
- * Every use, in `files`, of the SDK members named by `apis`
45
- * (`Interface.member`), and every request sent by name (`Wire.request`),
46
- * in file and position order. It reads no manifest (the capability scan,
47
- * `capability-scan.ts`, gives it its lists).
48
- *
49
- * `resolved` is `false` when the program has no import of
50
- * `@vestra-player/sdk` that resolves: nothing can be found by type then.
51
- *
52
- * @internal
53
- */
54
- export declare function findMemberUses(ts: typeof TS, program: TS.Program, options: {
55
- readonly files: readonly string[];
56
- readonly apis: Iterable<string>;
57
- }): {
58
- resolved: boolean;
59
- uses: MemberUse[];
60
- requests: RequestUse[];
61
- };
@@ -1,160 +0,0 @@
1
- /** @internal The module plugins import the API types from. */
2
- export const SDK_MODULE = "@vestra-player/sdk";
3
- /** The members that send a request by the method name they are given. */
4
- const SENDERS = ["Wire.request"];
5
- /**
6
- * The module `@vestra-player/sdk` as the program resolved it: from the
7
- * first import or export of it in the program's own (non-declaration) files.
8
- */
9
- function sdkModule(ts, program, checker) {
10
- for (const file of program.getSourceFiles()) {
11
- if (file.isDeclarationFile || program.isSourceFileFromExternalLibrary(file))
12
- continue;
13
- for (const statement of file.statements) {
14
- const specifier = ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)
15
- ? statement.moduleSpecifier
16
- : undefined;
17
- if (specifier &&
18
- ts.isStringLiteral(specifier) &&
19
- specifier.text === SDK_MODULE) {
20
- const module = checker.getSymbolAtLocation(specifier);
21
- if (module)
22
- return module;
23
- }
24
- }
25
- }
26
- return undefined;
27
- }
28
- /** The SDK's declarations of the members named (`Interface.member`). */
29
- function resolveMembers(ts, program, apis) {
30
- const members = new Map();
31
- const checker = program.getTypeChecker();
32
- const module = sdkModule(ts, program, checker);
33
- if (!module)
34
- return members;
35
- const exports = new Map();
36
- for (const symbol of checker.getExportsOfModule(module))
37
- exports.set(symbol.name, symbol.flags & ts.SymbolFlags.Alias
38
- ? checker.getAliasedSymbol(symbol)
39
- : symbol);
40
- for (const api of apis) {
41
- const [head, ...path] = api.split(".");
42
- const root = exports.get(head);
43
- if (!root || !path.length)
44
- continue;
45
- let type = checker.getDeclaredTypeOfSymbol(root);
46
- let property;
47
- for (const name of path) {
48
- property = type?.getProperty(name);
49
- type = property && checker.getTypeOfSymbol(property);
50
- }
51
- for (const declaration of property?.declarations ?? [])
52
- if (!members.has(declaration))
53
- members.set(declaration, api);
54
- }
55
- return members;
56
- }
57
- /**
58
- * The strings an expression's type fixes: a string literal, a constant of
59
- * one, or a union of them (the caller takes one only); `undefined` when
60
- * the type allows any other.
61
- */
62
- function literalStrings(ts, checker, node) {
63
- if (!node)
64
- return undefined;
65
- if (ts.isStringLiteralLike(node))
66
- return [node.text];
67
- const type = checker.getTypeAtLocation(node);
68
- const parts = type.isUnion() ? type.types : [type];
69
- const values = [];
70
- for (const part of parts) {
71
- if (!part.isStringLiteral())
72
- return undefined;
73
- values.push(part.value);
74
- }
75
- return values.length ? values : undefined;
76
- }
77
- /**
78
- * Every use, in `files`, of the SDK members named by `apis`
79
- * (`Interface.member`), and every request sent by name (`Wire.request`),
80
- * in file and position order. It reads no manifest (the capability scan,
81
- * `capability-scan.ts`, gives it its lists).
82
- *
83
- * `resolved` is `false` when the program has no import of
84
- * `@vestra-player/sdk` that resolves: nothing can be found by type then.
85
- *
86
- * @internal
87
- */
88
- export function findMemberUses(ts, program, options) {
89
- const uses = [];
90
- const requests = [];
91
- const members = resolveMembers(ts, program, options.apis);
92
- const senders = resolveMembers(ts, program, SENDERS);
93
- const resolved = members.size > 0 || senders.size > 0;
94
- if (!resolved)
95
- return { resolved, uses, requests };
96
- const checker = program.getTypeChecker();
97
- const apiOf = (table, symbol) => {
98
- for (const declaration of symbol?.declarations ?? []) {
99
- const api = table.get(declaration);
100
- if (api)
101
- return api;
102
- }
103
- return undefined;
104
- };
105
- for (const fileName of options.files) {
106
- const file = program.getSourceFile(fileName);
107
- if (!file)
108
- continue;
109
- const position = (name) => {
110
- const { line, character } = file.getLineAndCharacterOfPosition(name.getStart(file));
111
- return { file: file.fileName, line: line + 1, column: character + 1 };
112
- };
113
- const seen = (name, symbol) => {
114
- const api = apiOf(members, symbol);
115
- if (api)
116
- uses.push({ ...position(name), api });
117
- if (!apiOf(senders, symbol))
118
- return;
119
- // A direct call with one literal name is a request of that name;
120
- // anything else (a computed name, the member taken as a value) is a
121
- // request the scan cannot name.
122
- const access = name.parent;
123
- const call = access?.parent;
124
- const direct = access &&
125
- (ts.isPropertyAccessExpression(access) ||
126
- ts.isElementAccessExpression(access)) &&
127
- call &&
128
- ts.isCallExpression(call) &&
129
- call.expression === access
130
- ? call
131
- : undefined;
132
- const values = direct
133
- ? literalStrings(ts, checker, direct.arguments[0])
134
- : undefined;
135
- requests.push({
136
- ...position(name),
137
- method: values?.length === 1 ? values[0] : undefined,
138
- });
139
- };
140
- const visit = (node) => {
141
- if (ts.isPropertyAccessExpression(node))
142
- seen(node.name, checker.getSymbolAtLocation(node.name));
143
- else if (ts.isElementAccessExpression(node) &&
144
- ts.isStringLiteralLike(node.argumentExpression))
145
- seen(node.argumentExpression, checker.getSymbolAtLocation(node.argumentExpression));
146
- else if (ts.isBindingElement(node) &&
147
- ts.isObjectBindingPattern(node.parent)) {
148
- const name = node.propertyName ?? node.name;
149
- const text = ts.isIdentifier(name) || ts.isStringLiteralLike(name)
150
- ? name.text
151
- : undefined;
152
- if (text !== undefined)
153
- seen(name, checker.getTypeAtLocation(node.parent).getProperty(text));
154
- }
155
- ts.forEachChild(node, visit);
156
- };
157
- visit(file);
158
- }
159
- return { resolved, uses, requests };
160
- }