@compivia/plugin-sdk 0.0.1280 → 0.0.1298

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/dist/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from "./slug.js";
5
5
  export * from "./define.js";
6
6
  export * from "./parse-manifest.js";
7
7
  export * from "./settings.js";
8
+ export * from "./registry.js";
package/dist/index.js CHANGED
@@ -276,6 +276,64 @@ function mergePluginSettings(machine, user) {
276
276
  }
277
277
  return result;
278
278
  }
279
+
280
+ // src/registry.ts
281
+ function buildContributionRegistry(input) {
282
+ const builtinByKey = /* @__PURE__ */ new Map();
283
+ for (const { entry } of input.builtins) {
284
+ if (builtinByKey.has(entry.key)) {
285
+ throw new Error(`duplicate builtin contribution: ${entry.key}`);
286
+ }
287
+ builtinByKey.set(entry.key, entry);
288
+ }
289
+ const pluginsByKey = /* @__PURE__ */ new Map();
290
+ for (const plugin of input.plugins) {
291
+ const group = pluginsByKey.get(plugin.key);
292
+ if (group === void 0) {
293
+ pluginsByKey.set(plugin.key, [plugin]);
294
+ } else {
295
+ group.push(plugin);
296
+ }
297
+ }
298
+ const conflictList = [];
299
+ const excluded = /* @__PURE__ */ new Set();
300
+ for (const [key, group] of pluginsByKey) {
301
+ const builtin = builtinByKey.get(key);
302
+ const first = group[0];
303
+ if (first === void 0 || builtin === void 0 && group.length === 1) continue;
304
+ const sources = builtin === void 0 ? [] : ["builtin"];
305
+ for (let i = 0; i < group.length; i += 1) sources.push("plugin");
306
+ conflictList.push({
307
+ kind: first.kind,
308
+ id: first.id,
309
+ sources,
310
+ packages: group.map((p) => p.package ?? "").sort(compareStrings)
311
+ });
312
+ for (const plugin of group) excluded.add(plugin);
313
+ }
314
+ conflictList.sort((a, b) => compareStrings(`${a.kind}:${a.id}`, `${b.kind}:${b.id}`));
315
+ const activeBuiltins = input.builtins.filter((b) => b.active).map((b) => b.entry);
316
+ const availableBuiltins = input.builtins.filter((b) => !b.active).map((b) => b.entry);
317
+ const activePlugins = input.plugins.filter((p) => !excluded.has(p)).sort((a, b) => compareStrings(a.package ?? "", b.package ?? "") || compareStrings(a.id, b.id));
318
+ const active = [...activeBuiltins, ...activePlugins];
319
+ const listOf = (kind) => active.filter((e) => e.kind === kind);
320
+ const availableOf = (kind) => availableBuiltins.filter((e) => e.kind === kind);
321
+ const getOf = (kind, id) => listOf(kind).find((e) => e.id === id);
322
+ return {
323
+ list: listOf,
324
+ get: getOf,
325
+ has: (kind, id) => getOf(kind, id) !== void 0,
326
+ ids: (kind) => new Set(listOf(kind).map((e) => e.id)),
327
+ available: availableOf,
328
+ conflicts: () => conflictList,
329
+ skipped: () => input.skipped ?? []
330
+ };
331
+ }
332
+ function compareStrings(a, b) {
333
+ if (a < b) return -1;
334
+ if (a > b) return 1;
335
+ return 0;
336
+ }
279
337
  export {
280
338
  CONTRIBUTION_ID_PATTERN,
281
339
  CONTRIBUTION_KEY_PATTERN,
@@ -283,6 +341,7 @@ export {
283
341
  PLUGIN_API_VERSION,
284
342
  PluginManifestError,
285
343
  SUPPORTED_PLUGIN_API_VERSIONS,
344
+ buildContributionRegistry,
286
345
  contributionKey,
287
346
  defineHarness,
288
347
  defineReporter,
@@ -0,0 +1,56 @@
1
+ import type { PluginContributionKind } from "./const.js";
2
+ /** Источник вклада: встроенный манифест или установленный плагин. */
3
+ export type ContributionSource = "builtin" | "plugin";
4
+ /** Вклад одного вида. `key` — канонический ключ `kind:id`, как в enable-записях. */
5
+ export type ContributionEntry<K extends PluginContributionKind = PluginContributionKind> = {
6
+ kind: K;
7
+ id: string;
8
+ key: `${K}:${string}`;
9
+ source: ContributionSource;
10
+ package?: string;
11
+ version?: string;
12
+ name?: string;
13
+ declarations?: Record<string, unknown>;
14
+ };
15
+ /** Конфликт id внутри вида: встроенный с плагинным или плагин с плагином. */
16
+ export type ContributionConflict = {
17
+ kind: PluginContributionKind;
18
+ id: string;
19
+ sources: ContributionSource[];
20
+ packages: string[];
21
+ };
22
+ /** Установленный, но не активный вклад (для `plugin list` и диагностики). */
23
+ export type SkippedContribution = {
24
+ kind: PluginContributionKind;
25
+ id: string;
26
+ package: string;
27
+ reason: string;
28
+ };
29
+ /** Реестр вкладов всех видов: только чтение, собран один раз на старте. */
30
+ export interface ContributionRegistry {
31
+ /** Активные вклады вида: сначала встроенные (порядок входа), затем плагинные (по package, id). */
32
+ list<K extends PluginContributionKind>(kind: K): readonly ContributionEntry<K>[];
33
+ get<K extends PluginContributionKind>(kind: K, id: string): ContributionEntry<K> | undefined;
34
+ has<K extends PluginContributionKind>(kind: K, id: string): boolean;
35
+ ids<K extends PluginContributionKind>(kind: K): ReadonlySet<string>;
36
+ /** Встроенные вклады, не активные на машине (подсказки «найден, не включён»). */
37
+ available<K extends PluginContributionKind>(kind: K): readonly ContributionEntry<K>[];
38
+ /** Конфликты id; плагинные записи конфликта исключены из `list`. */
39
+ conflicts(): readonly ContributionConflict[];
40
+ skipped(): readonly SkippedContribution[];
41
+ }
42
+ /**
43
+ * Собирает реестр из встроенных манифестов и включённых плагинных вкладов.
44
+ * Чистая функция: без I/O, результат не зависит от порядка `plugins`.
45
+ * Конфликт (встроенный+плагинный или плагинный+плагинный) исключает плагинные
46
+ * записи; встроенный остаётся по своему флагу активности. Дубликат внутри
47
+ * `builtins` — ошибка программиста и бросает `Error`.
48
+ */
49
+ export declare function buildContributionRegistry(input: {
50
+ builtins: ReadonlyArray<{
51
+ entry: ContributionEntry;
52
+ active: boolean;
53
+ }>;
54
+ plugins: readonly ContributionEntry[];
55
+ skipped?: readonly SkippedContribution[];
56
+ }): ContributionRegistry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compivia/plugin-sdk",
3
- "version": "0.0.1280",
3
+ "version": "0.0.1298",
4
4
  "description": "SDK for authoring Compivia plugins (harness and reporter contributions)",
5
5
  "keywords": [
6
6
  "compivia",