chkit 0.1.0-beta.5

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 (114) hide show
  1. package/README.md +43 -0
  2. package/dist/bin/chkit.d.ts +3 -0
  3. package/dist/bin/chkit.d.ts.map +1 -0
  4. package/dist/bin/chkit.js +337 -0
  5. package/dist/bin/chkit.js.map +1 -0
  6. package/dist/bin/commands/check.d.ts +2 -0
  7. package/dist/bin/commands/check.d.ts.map +1 -0
  8. package/dist/bin/commands/check.js +123 -0
  9. package/dist/bin/commands/check.js.map +1 -0
  10. package/dist/bin/commands/codegen.d.ts +2 -0
  11. package/dist/bin/commands/codegen.d.ts.map +1 -0
  12. package/dist/bin/commands/codegen.js +25 -0
  13. package/dist/bin/commands/codegen.js.map +1 -0
  14. package/dist/bin/commands/drift.d.ts +22 -0
  15. package/dist/bin/commands/drift.d.ts.map +1 -0
  16. package/dist/bin/commands/drift.js +170 -0
  17. package/dist/bin/commands/drift.js.map +1 -0
  18. package/dist/bin/commands/generate/output.d.ts +8 -0
  19. package/dist/bin/commands/generate/output.d.ts.map +1 -0
  20. package/dist/bin/commands/generate/output.js +58 -0
  21. package/dist/bin/commands/generate/output.js.map +1 -0
  22. package/dist/bin/commands/generate/plan-pipeline.d.ts +7 -0
  23. package/dist/bin/commands/generate/plan-pipeline.d.ts.map +1 -0
  24. package/dist/bin/commands/generate/plan-pipeline.js +139 -0
  25. package/dist/bin/commands/generate/plan-pipeline.js.map +1 -0
  26. package/dist/bin/commands/generate/rename-mappings.d.ts +29 -0
  27. package/dist/bin/commands/generate/rename-mappings.d.ts.map +1 -0
  28. package/dist/bin/commands/generate/rename-mappings.js +207 -0
  29. package/dist/bin/commands/generate/rename-mappings.js.map +1 -0
  30. package/dist/bin/commands/generate.d.ts +2 -0
  31. package/dist/bin/commands/generate.d.ts.map +1 -0
  32. package/dist/bin/commands/generate.js +137 -0
  33. package/dist/bin/commands/generate.js.map +1 -0
  34. package/dist/bin/commands/init.d.ts +2 -0
  35. package/dist/bin/commands/init.d.ts.map +1 -0
  36. package/dist/bin/commands/init.js +12 -0
  37. package/dist/bin/commands/init.js.map +1 -0
  38. package/dist/bin/commands/migrate.d.ts +2 -0
  39. package/dist/bin/commands/migrate.d.ts.map +1 -0
  40. package/dist/bin/commands/migrate.js +262 -0
  41. package/dist/bin/commands/migrate.js.map +1 -0
  42. package/dist/bin/commands/plugin-like.d.ts +38 -0
  43. package/dist/bin/commands/plugin-like.d.ts.map +1 -0
  44. package/dist/bin/commands/plugin-like.js +101 -0
  45. package/dist/bin/commands/plugin-like.js.map +1 -0
  46. package/dist/bin/commands/plugin.d.ts +2 -0
  47. package/dist/bin/commands/plugin.d.ts.map +1 -0
  48. package/dist/bin/commands/plugin.js +92 -0
  49. package/dist/bin/commands/plugin.js.map +1 -0
  50. package/dist/bin/commands/pull.d.ts +2 -0
  51. package/dist/bin/commands/pull.d.ts.map +1 -0
  52. package/dist/bin/commands/pull.js +25 -0
  53. package/dist/bin/commands/pull.js.map +1 -0
  54. package/dist/bin/commands/status.d.ts +2 -0
  55. package/dist/bin/commands/status.d.ts.map +1 -0
  56. package/dist/bin/commands/status.js +42 -0
  57. package/dist/bin/commands/status.js.map +1 -0
  58. package/dist/bin/commands/typegen.d.ts +2 -0
  59. package/dist/bin/commands/typegen.d.ts.map +1 -0
  60. package/dist/bin/commands/typegen.js +25 -0
  61. package/dist/bin/commands/typegen.js.map +1 -0
  62. package/dist/bin/config.d.ts +26 -0
  63. package/dist/bin/config.d.ts.map +1 -0
  64. package/dist/bin/config.js +59 -0
  65. package/dist/bin/config.js.map +1 -0
  66. package/dist/bin/json-output.d.ts +8 -0
  67. package/dist/bin/json-output.d.ts.map +1 -0
  68. package/dist/bin/json-output.js +21 -0
  69. package/dist/bin/json-output.js.map +1 -0
  70. package/dist/bin/lib.d.ts +7 -0
  71. package/dist/bin/lib.d.ts.map +1 -0
  72. package/dist/bin/lib.js +7 -0
  73. package/dist/bin/lib.js.map +1 -0
  74. package/dist/bin/migration-store.d.ts +24 -0
  75. package/dist/bin/migration-store.d.ts.map +1 -0
  76. package/dist/bin/migration-store.js +96 -0
  77. package/dist/bin/migration-store.js.map +1 -0
  78. package/dist/bin/plugin-runtime.d.ts +37 -0
  79. package/dist/bin/plugin-runtime.d.ts.map +1 -0
  80. package/dist/bin/plugin-runtime.js +264 -0
  81. package/dist/bin/plugin-runtime.js.map +1 -0
  82. package/dist/bin/safety-markers.d.ts +24 -0
  83. package/dist/bin/safety-markers.d.ts.map +1 -0
  84. package/dist/bin/safety-markers.js +94 -0
  85. package/dist/bin/safety-markers.js.map +1 -0
  86. package/dist/bin/schema-loader.d.ts +3 -0
  87. package/dist/bin/schema-loader.d.ts.map +1 -0
  88. package/dist/bin/schema-loader.js +6 -0
  89. package/dist/bin/schema-loader.js.map +1 -0
  90. package/dist/bin/table-scope.d.ts +39 -0
  91. package/dist/bin/table-scope.d.ts.map +1 -0
  92. package/dist/bin/table-scope.js +167 -0
  93. package/dist/bin/table-scope.js.map +1 -0
  94. package/dist/bin/version.d.ts +2 -0
  95. package/dist/bin/version.d.ts.map +1 -0
  96. package/dist/bin/version.js +2 -0
  97. package/dist/bin/version.js.map +1 -0
  98. package/dist/drift-diff.d.ts +8 -0
  99. package/dist/drift-diff.d.ts.map +1 -0
  100. package/dist/drift-diff.js +46 -0
  101. package/dist/drift-diff.js.map +1 -0
  102. package/dist/drift.d.ts +65 -0
  103. package/dist/drift.d.ts.map +1 -0
  104. package/dist/drift.js +209 -0
  105. package/dist/drift.js.map +1 -0
  106. package/dist/index.d.ts +2 -0
  107. package/dist/index.d.ts.map +1 -0
  108. package/dist/index.js +2 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/plugins.d.ts +103 -0
  111. package/dist/plugins.d.ts.map +1 -0
  112. package/dist/plugins.js +10 -0
  113. package/dist/plugins.js.map +1 -0
  114. package/package.json +28 -0
@@ -0,0 +1,25 @@
1
+ import { buildPluginLikeContext, runPluginLikeCommand } from './plugin-like.js';
2
+ export async function cmdTypegen(args) {
3
+ const context = await buildPluginLikeContext({
4
+ args,
5
+ command: 'typegen',
6
+ handleInvalidPluginOptions: true,
7
+ });
8
+ if (!context)
9
+ return;
10
+ const pluginName = 'typegen';
11
+ const commandName = 'typegen';
12
+ await runPluginLikeCommand({
13
+ context,
14
+ pluginName,
15
+ commandName,
16
+ commandArgs: context.commandArgs,
17
+ missingPluginMessage() {
18
+ return 'Typegen plugin is not configured. Add a plugin with manifest.name "typegen" to config.plugins.';
19
+ },
20
+ missingCommandMessage({ availableCommands }) {
21
+ return `Typegen plugin is configured but does not expose command "${commandName}". Available: ${availableCommands.length > 0 ? availableCommands.join(', ') : '(none)'}.`;
22
+ },
23
+ });
24
+ }
25
+ //# sourceMappingURL=typegen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typegen.js","sourceRoot":"","sources":["../../../src/bin/commands/typegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAE/E,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAc;IAC7C,MAAM,OAAO,GAAG,MAAM,sBAAsB,CAAC;QAC3C,IAAI;QACJ,OAAO,EAAE,SAAS;QAClB,0BAA0B,EAAE,IAAI;KACjC,CAAC,CAAA;IACF,IAAI,CAAC,OAAO;QAAE,OAAM;IAEpB,MAAM,UAAU,GAAG,SAAS,CAAA;IAC5B,MAAM,WAAW,GAAG,SAAS,CAAA;IAC7B,MAAM,oBAAoB,CAAC;QACzB,OAAO;QACP,UAAU;QACV,WAAW;QACX,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,oBAAoB;YAClB,OAAO,gGAAgG,CAAA;QACzG,CAAC;QACD,qBAAqB,CAAC,EAAE,iBAAiB,EAAE;YACzC,OAAO,6DAA6D,WAAW,iBAAiB,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAA;QAC3K,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type ChxConfigEnv, type ResolvedChxConfig } from '@chkit/core';
2
+ export declare const DEFAULT_CONFIG_FILE = "clickhouse.config.ts";
3
+ export interface CommandContext {
4
+ config: ResolvedChxConfig;
5
+ configPath: string;
6
+ dirs: {
7
+ outDir: string;
8
+ migrationsDir: string;
9
+ metaDir: string;
10
+ };
11
+ jsonMode: boolean;
12
+ }
13
+ export declare function parseArg(flag: string, args: string[]): string | undefined;
14
+ export declare function hasFlag(flag: string, args: string[]): boolean;
15
+ export declare function loadConfig(configPathArg?: string, env?: ChxConfigEnv): Promise<{
16
+ config: ResolvedChxConfig;
17
+ path: string;
18
+ }>;
19
+ export declare function writeIfMissing(filePath: string, content: string): Promise<void>;
20
+ export declare function resolveDirs(config: ResolvedChxConfig): {
21
+ outDir: string;
22
+ migrationsDir: string;
23
+ metaDir: string;
24
+ };
25
+ export declare function getCommandContext(args: string[]): Promise<CommandContext>;
26
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/bin/config.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,YAAY,EAGjB,KAAK,iBAAiB,EACvB,MAAM,aAAa,CAAA;AAEpB,eAAO,MAAM,mBAAmB,yBAAyB,CAAA;AAEzD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,iBAAiB,CAAA;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;IAChE,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAIzE;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAE7D;AAMD,wBAAsB,UAAU,CAC9B,aAAa,CAAC,EAAE,MAAM,EACtB,GAAG,GAAE,YAAiB,GACrB,OAAO,CAAC;IAAE,MAAM,EAAE,iBAAiB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAoBtD;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrF;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAKjH;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAU/E"}
@@ -0,0 +1,59 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { mkdir, writeFile } from 'node:fs/promises';
3
+ import { dirname, resolve } from 'node:path';
4
+ import process from 'node:process';
5
+ import { pathToFileURL } from 'node:url';
6
+ import { resolveConfig, } from '@chkit/core';
7
+ export const DEFAULT_CONFIG_FILE = 'clickhouse.config.ts';
8
+ export function parseArg(flag, args) {
9
+ const idx = args.indexOf(flag);
10
+ if (idx === -1)
11
+ return undefined;
12
+ return args[idx + 1];
13
+ }
14
+ export function hasFlag(flag, args) {
15
+ return args.includes(flag);
16
+ }
17
+ function isConfigFunction(candidate) {
18
+ return typeof candidate === 'function';
19
+ }
20
+ export async function loadConfig(configPathArg, env = {}) {
21
+ const configPath = resolve(process.cwd(), configPathArg ?? DEFAULT_CONFIG_FILE);
22
+ if (!existsSync(configPath)) {
23
+ throw new Error(`Config not found at ${configPath}. Run 'chkit init' first.`);
24
+ }
25
+ const mod = await import(pathToFileURL(configPath).href);
26
+ const candidate = (mod.default ?? mod.config);
27
+ if (!candidate) {
28
+ throw new Error(`Config file ${configPath} must export a default/config object or a function via defineConfig.`);
29
+ }
30
+ const userConfig = isConfigFunction(candidate) ? await candidate(env) : candidate;
31
+ return {
32
+ config: resolveConfig(userConfig),
33
+ path: configPath,
34
+ };
35
+ }
36
+ export async function writeIfMissing(filePath, content) {
37
+ if (existsSync(filePath))
38
+ return;
39
+ await mkdir(dirname(filePath), { recursive: true });
40
+ await writeFile(filePath, content, 'utf8');
41
+ }
42
+ export function resolveDirs(config) {
43
+ const outDir = resolve(process.cwd(), config.outDir);
44
+ const migrationsDir = resolve(process.cwd(), config.migrationsDir);
45
+ const metaDir = resolve(process.cwd(), config.metaDir);
46
+ return { outDir, migrationsDir, metaDir };
47
+ }
48
+ export async function getCommandContext(args) {
49
+ const configPath = parseArg('--config', args);
50
+ const jsonMode = hasFlag('--json', args);
51
+ const loaded = await loadConfig(configPath);
52
+ return {
53
+ config: loaded.config,
54
+ configPath: loaded.path,
55
+ dirs: resolveDirs(loaded.config),
56
+ jsonMode,
57
+ };
58
+ }
59
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/bin/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EACL,aAAa,GAMd,MAAM,aAAa,CAAA;AAEpB,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAA;AASzD,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,I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,KAAK,UAAU,cAAc,CAAC,QAAgB,EAAE,OAAe;IACpE,IAAI,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAM;IAChC,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACnD,MAAM,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAC5C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAyB;IACnD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IACpD,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,aAAa,CAAC,CAAA;IAClE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;IACtD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,CAAA;AAC3C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAc;IACpD,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IACxC,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAA;IAC3C,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,UAAU,EAAE,MAAM,CAAC,IAAI;QACvB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;QAChC,QAAQ;KACT,CAAA;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ export type Command = 'init' | 'generate' | 'codegen' | 'migrate' | 'status' | 'drift' | 'check' | 'plugin' | 'help' | 'version';
2
+ export declare function printOutput(value: unknown, jsonMode: boolean): void;
3
+ export declare function jsonPayload<T extends object>(command: Command, payload: T): T & {
4
+ command: Command;
5
+ schemaVersion: number;
6
+ };
7
+ export declare function emitJson<T extends object>(command: Command, payload: T): void;
8
+ //# sourceMappingURL=json-output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-output.d.ts","sourceRoot":"","sources":["../../src/bin/json-output.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GACf,MAAM,GACN,UAAU,GACV,SAAS,GACT,SAAS,GACT,QAAQ,GACR,OAAO,GACP,OAAO,GACP,QAAQ,GACR,MAAM,GACN,SAAS,CAAA;AAIb,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAQnE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG;IAC/E,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;CACtB,CAMA;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAE7E"}
@@ -0,0 +1,21 @@
1
+ const JSON_CONTRACT_VERSION = 1;
2
+ export function printOutput(value, jsonMode) {
3
+ if (jsonMode) {
4
+ console.log(JSON.stringify(value, null, 2));
5
+ return;
6
+ }
7
+ if (typeof value === 'string') {
8
+ console.log(value);
9
+ }
10
+ }
11
+ export function jsonPayload(command, payload) {
12
+ return {
13
+ command,
14
+ schemaVersion: JSON_CONTRACT_VERSION,
15
+ ...payload,
16
+ };
17
+ }
18
+ export function emitJson(command, payload) {
19
+ printOutput(jsonPayload(command, payload), true);
20
+ }
21
+ //# sourceMappingURL=json-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-output.js","sourceRoot":"","sources":["../../src/bin/json-output.ts"],"names":[],"mappings":"AAYA,MAAM,qBAAqB,GAAG,CAAC,CAAA;AAE/B,MAAM,UAAU,WAAW,CAAC,KAAc,EAAE,QAAiB;IAC3D,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;QAC3C,OAAM;IACR,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAmB,OAAgB,EAAE,OAAU;IAIxE,OAAO;QACL,OAAO;QACP,aAAa,EAAE,qBAAqB;QACpC,GAAG,OAAO;KACX,CAAA;AACH,CAAC;AAED,MAAM,UAAU,QAAQ,CAAmB,OAAgB,EAAE,OAAU;IACrE,WAAW,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;AAClD,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { CLI_VERSION } from './version.js';
2
+ export { DEFAULT_CONFIG_FILE, getCommandContext, hasFlag, loadConfig, parseArg, resolveDirs, writeIfMissing, type CommandContext, } from './config.js';
3
+ export { checksumSQL, findChecksumMismatches, listMigrations, parseJSONOrThrow, readJournal, readSnapshot, summarizePlan, writeJournal, type ChecksumMismatch, type MigrationJournal, type MigrationJournalEntry, } from './migration-store.js';
4
+ export { emitJson, jsonPayload, printOutput, type Command } from './json-output.js';
5
+ export { collectDestructiveOperationMarkers, extractMigrationOperationSummaries, extractDestructiveOperationSummaries, extractExecutableStatements, migrationContainsDangerOperation, parseOperationLine, type MigrationOperationSummary, type DestructiveOperationMarker, } from './safety-markers.js';
6
+ export { loadSchemaDefinitions } from './schema-loader.js';
7
+ //# sourceMappingURL=lib.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/bin/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,OAAO,EACP,UAAU,EACV,QAAQ,EACR,WAAW,EACX,cAAc,EACd,KAAK,cAAc,GACpB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACnF,OAAO,EACL,kCAAkC,EAClC,kCAAkC,EAClC,oCAAoC,EACpC,2BAA2B,EAC3B,gCAAgC,EAChC,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,GAChC,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,7 @@
1
+ export { CLI_VERSION } from './version.js';
2
+ export { DEFAULT_CONFIG_FILE, getCommandContext, hasFlag, loadConfig, parseArg, resolveDirs, writeIfMissing, } from './config.js';
3
+ export { checksumSQL, findChecksumMismatches, listMigrations, parseJSONOrThrow, readJournal, readSnapshot, summarizePlan, writeJournal, } from './migration-store.js';
4
+ export { emitJson, jsonPayload, printOutput } from './json-output.js';
5
+ export { collectDestructiveOperationMarkers, extractMigrationOperationSummaries, extractDestructiveOperationSummaries, extractExecutableStatements, migrationContainsDangerOperation, parseOperationLine, } from './safety-markers.js';
6
+ export { loadSchemaDefinitions } from './schema-loader.js';
7
+ //# sourceMappingURL=lib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/bin/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,OAAO,EACP,UAAU,EACV,QAAQ,EACR,WAAW,EACX,cAAc,GAEf,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,GAIb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAgB,MAAM,kBAAkB,CAAA;AACnF,OAAO,EACL,kCAAkC,EAClC,kCAAkC,EAClC,oCAAoC,EACpC,2BAA2B,EAC3B,gCAAgC,EAChC,kBAAkB,GAGnB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,24 @@
1
+ import { type MigrationOperation, type Snapshot } from '@chkit/core';
2
+ export interface MigrationJournalEntry {
3
+ name: string;
4
+ appliedAt: string;
5
+ checksum: string;
6
+ }
7
+ export interface MigrationJournal {
8
+ version: 1;
9
+ applied: MigrationJournalEntry[];
10
+ }
11
+ export interface ChecksumMismatch {
12
+ name: string;
13
+ expected: string;
14
+ actual: string;
15
+ }
16
+ export declare function parseJSONOrThrow<T>(raw: string, filePath: string, kind: string): T;
17
+ export declare function readSnapshot(metaDir: string): Promise<Snapshot | null>;
18
+ export declare function summarizePlan(operations: MigrationOperation[]): string[];
19
+ export declare function readJournal(metaDir: string): Promise<MigrationJournal>;
20
+ export declare function writeJournal(metaDir: string, journal: MigrationJournal): Promise<void>;
21
+ export declare function listMigrations(migrationsDir: string): Promise<string[]>;
22
+ export declare function findChecksumMismatches(migrationsDir: string, journal: MigrationJournal): Promise<ChecksumMismatch[]>;
23
+ export declare function checksumSQL(value: string): string;
24
+ //# sourceMappingURL=migration-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"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M,GAAG,MAAM,CAEjD"}
@@ -0,0 +1,96 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { existsSync } from 'node:fs';
3
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
4
+ import { join } from 'node:path';
5
+ import fg from 'fast-glob';
6
+ import { canonicalizeDefinitions } from '@chkit/core';
7
+ export function parseJSONOrThrow(raw, filePath, kind) {
8
+ try {
9
+ return JSON.parse(raw);
10
+ }
11
+ catch {
12
+ throw new Error(`Invalid ${kind} JSON at ${filePath}. Fix or remove the file and retry.`);
13
+ }
14
+ }
15
+ export async function readSnapshot(metaDir) {
16
+ const file = join(metaDir, 'snapshot.json');
17
+ if (!existsSync(file))
18
+ return null;
19
+ const raw = await readFile(file, 'utf8');
20
+ const parsed = parseJSONOrThrow(raw, file, 'snapshot');
21
+ return {
22
+ version: 1,
23
+ generatedAt: parsed.generatedAt ?? '',
24
+ definitions: canonicalizeDefinitions(parsed.definitions ?? []),
25
+ };
26
+ }
27
+ export function summarizePlan(operations) {
28
+ return operations.map((op) => `${op.type} [${op.risk}] ${op.key}`);
29
+ }
30
+ export async function readJournal(metaDir) {
31
+ const file = join(metaDir, 'journal.json');
32
+ if (!existsSync(file))
33
+ return { version: 1, applied: [] };
34
+ const raw = await readFile(file, 'utf8');
35
+ const parsed = parseJSONOrThrow(raw, file, 'journal');
36
+ const normalizedApplied = [];
37
+ for (const item of parsed.applied ?? []) {
38
+ if (typeof item === 'string') {
39
+ normalizedApplied.push({
40
+ name: item,
41
+ appliedAt: '',
42
+ checksum: '',
43
+ });
44
+ continue;
45
+ }
46
+ if (!item || typeof item !== 'object')
47
+ continue;
48
+ if (typeof item.name !== 'string')
49
+ continue;
50
+ normalizedApplied.push({
51
+ name: item.name,
52
+ appliedAt: typeof item.appliedAt === 'string' ? item.appliedAt : '',
53
+ checksum: typeof item.checksum === 'string' ? item.checksum : '',
54
+ });
55
+ }
56
+ return {
57
+ version: 1,
58
+ applied: normalizedApplied,
59
+ };
60
+ }
61
+ export async function writeJournal(metaDir, journal) {
62
+ await mkdir(metaDir, { recursive: true });
63
+ const file = join(metaDir, 'journal.json');
64
+ await writeFile(file, `${JSON.stringify(journal, null, 2)}\n`, 'utf8');
65
+ }
66
+ export async function listMigrations(migrationsDir) {
67
+ const files = await fg('*.sql', { cwd: migrationsDir, onlyFiles: true });
68
+ return files.sort();
69
+ }
70
+ function checksum(value) {
71
+ return createHash('sha256').update(value, 'utf8').digest('hex');
72
+ }
73
+ export async function findChecksumMismatches(migrationsDir, journal) {
74
+ const mismatches = [];
75
+ for (const entry of journal.applied) {
76
+ if (!entry.checksum)
77
+ continue;
78
+ const fullPath = join(migrationsDir, entry.name);
79
+ if (!existsSync(fullPath))
80
+ continue;
81
+ const sql = await readFile(fullPath, 'utf8');
82
+ const actual = checksum(sql);
83
+ if (actual !== entry.checksum) {
84
+ mismatches.push({
85
+ name: entry.name,
86
+ expected: entry.checksum,
87
+ actual,
88
+ });
89
+ }
90
+ }
91
+ return mismatches;
92
+ }
93
+ export function checksumSQL(value) {
94
+ return checksum(value);
95
+ }
96
+ //# sourceMappingURL=migration-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-store.js","sourceRoot":"","sources":["../../src/bin/migration-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,MAAM,WAAW,CAAA;AAE1B,OAAO,EAAE,uBAAuB,EAAiE,MAAM,aAAa,CAAA;AAmBpH,MAAM,UAAU,gBAAgB,CAAI,GAAW,EAAE,QAAgB,EAAE,IAAY;IAC7E,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAM,CAAA;I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SchemaDefinition } from '@chkit/core';
2
+ import type { ChxOnCheckContext, ChxOnCheckResult, ChxOnAfterApplyContext, ChxOnBeforeApplyContext, ChxOnConfigLoadedContext, ChxOnPlanCreatedContext, ChxOnSchemaLoadedContext, ChxPlugin, ChxPluginCommand, ChxPluginCommandContext } from '../plugins.js';
3
+ import type { TableScope } from './table-scope.js';
4
+ interface LoadedPlugin {
5
+ options: Record<string, unknown>;
6
+ plugin: ChxPlugin;
7
+ }
8
+ export interface PluginRuntime {
9
+ plugins: ReadonlyArray<LoadedPlugin>;
10
+ getCommand(pluginName: string, commandName: string): {
11
+ command: ChxPluginCommand;
12
+ plugin: LoadedPlugin;
13
+ } | null;
14
+ runOnConfigLoaded(context: Omit<ChxOnConfigLoadedContext, 'options' | 'tableScope'> & {
15
+ tableScope?: TableScope;
16
+ }): Promise<void>;
17
+ runOnSchemaLoaded(context: ChxOnSchemaLoadedContext): Promise<SchemaDefinition[]>;
18
+ runOnPlanCreated(context: Omit<ChxOnPlanCreatedContext, 'plan' | 'tableScope'> & {
19
+ tableScope?: TableScope;
20
+ }, plan: MigrationPlan): Promise<MigrationPlan>;
21
+ runOnBeforeApply(context: ChxOnBeforeApplyContext): Promise<string[]>;
22
+ runOnAfterApply(context: ChxOnAfterApplyContext): Promise<void>;
23
+ runOnCheck(context: Omit<ChxOnCheckContext, 'options' | 'tableScope'> & {
24
+ tableScope?: TableScope;
25
+ }): Promise<ChxOnCheckResult[]>;
26
+ runOnCheckReport(results: ChxOnCheckResult[], print: (line: string) => void): Promise<void>;
27
+ runPluginCommand(pluginName: string, commandName: string, context: Omit<ChxPluginCommandContext, 'pluginName' | 'options' | 'tableScope'> & {
28
+ tableScope?: TableScope;
29
+ }): Promise<number>;
30
+ }
31
+ export declare function loadPluginRuntime(input: {
32
+ config: ResolvedChxConfig;
33
+ configPath: string;
34
+ cliVersion: string;
35
+ }): Promise<PluginRuntime>;
36
+ export {};
37
+ //# sourceMappingURL=plugin-runtime.d.ts.map
@@ -0,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AC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IACrE,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/D,UAAU,CACR,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,YAAY,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,UAAU,CAAA;KAAE,GACvF,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAA;IAC9B,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3F,gBAAgB,CACd,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,IAAI,CAAC,uBAAuB,EAAE,YAAY,GAAG,SAAS,GAAG,YAAY,CAAC,GAAG;QAChF,UAAU,CAAC,EAAE,UAAU,CAAA;KACxB,GACA,OAAO,CAAC,MAAM,CAAC,CAAA;CACnB;AA+FD,wBAAsB,iBAAiB,CAAC,KAAK,EAAE;IAC7C,MAAM,EAAE,iBAAiB,CAAA;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAC,aAAa,CAAC,CAyKzB"}
@@ -0,0 +1,264 @@
1
+ import { resolve } from 'node:path';
2
+ import { pathToFileURL } from 'node:url';
3
+ import { canonicalizeDefinitions, } from '@chkit/core';
4
+ import { isInlinePluginRegistration } from '../plugins.js';
5
+ const UNFILTERED_TABLE_SCOPE = {
6
+ enabled: false,
7
+ matchedTables: [],
8
+ matchCount: 0,
9
+ };
10
+ function parseCliMajor(version) {
11
+ const major = Number(version.split('.')[0] ?? Number.NaN);
12
+ if (!Number.isInteger(major) || major < 0) {
13
+ throw new Error(`Invalid CLI version "${version}" while loading plugins.`);
14
+ }
15
+ return major;
16
+ }
17
+ function normalizePluginRegistration(entry) {
18
+ if (typeof entry === 'string') {
19
+ return {
20
+ kind: 'legacy',
21
+ resolvePath: entry,
22
+ enabled: true,
23
+ options: {},
24
+ };
25
+ }
26
+ if (isInlinePluginRegistration(entry)) {
27
+ return {
28
+ kind: 'inline',
29
+ resolvePath: '',
30
+ inlinePlugin: entry.plugin,
31
+ nameHint: entry.name,
32
+ enabled: entry.enabled !== false,
33
+ options: entry.options ?? {},
34
+ };
35
+ }
36
+ const legacy = entry;
37
+ return {
38
+ kind: 'legacy',
39
+ resolvePath: legacy.resolve,
40
+ nameHint: legacy.name,
41
+ enabled: legacy.enabled !== false,
42
+ options: legacy.options ?? {},
43
+ };
44
+ }
45
+ function formatPluginError(pluginName, hook, error) {
46
+ const message = error instanceof Error ? error.message : String(error);
47
+ return new Error(`Plugin "${pluginName}" failed in ${hook}: ${message}`);
48
+ }
49
+ function validatePlugin(cliVersion, plugin, sourcePath) {
50
+ const name = plugin.manifest.name;
51
+ if (!name || name.trim().length === 0) {
52
+ throw new Error(`Plugin at ${sourcePath} has an empty manifest.name.`);
53
+ }
54
+ if (plugin.manifest.apiVersion !== 1) {
55
+ throw new Error(`Plugin "${name}" requires apiVersion=${String(plugin.manifest.apiVersion)} but CLI supports apiVersion=1.`);
56
+ }
57
+ const compatibility = plugin.manifest.compatibility?.cli;
58
+ if (!compatibility)
59
+ return;
60
+ const cliMajor = parseCliMajor(cliVersion);
61
+ if (compatibility.minMajor !== undefined && cliMajor < compatibility.minMajor) {
62
+ throw new Error(`Plugin "${name}" is incompatible with CLI ${cliVersion}. Requires cli major >= ${compatibility.minMajor}.`);
63
+ }
64
+ if (compatibility.maxMajor !== undefined && cliMajor > compatibility.maxMajor) {
65
+ throw new Error(`Plugin "${name}" is incompatible with CLI ${cliVersion}. Requires cli major <= ${compatibility.maxMajor}.`);
66
+ }
67
+ }
68
+ async function importPluginModule(absolutePath) {
69
+ const mod = (await import(pathToFileURL(absolutePath).href));
70
+ const candidate = (mod.default ?? mod.plugin);
71
+ if (!candidate || typeof candidate !== 'object') {
72
+ throw new Error(`Plugin module ${absolutePath} must export default definePlugin(...)`);
73
+ }
74
+ if (!candidate.manifest || typeof candidate.manifest !== 'object') {
75
+ throw new Error(`Plugin module ${absolutePath} is missing manifest.`);
76
+ }
77
+ return candidate;
78
+ }
79
+ export async function loadPluginRuntime(input) {
80
+ const registrations = input.config.plugins ?? [];
81
+ const loaded = [];
82
+ const byName = new Map();
83
+ const configDir = resolve(input.configPath, '..');
84
+ for (const registration of registrations) {
85
+ const normalized = normalizePluginRegistration(registration);
86
+ if (!normalized.enabled)
87
+ continue;
88
+ const plugin = normalized.kind === 'inline'
89
+ ? normalized.inlinePlugin
90
+ : await importPluginModule(resolve(configDir, normalized.resolvePath));
91
+ if (!plugin)
92
+ continue;
93
+ const sourceLabel = normalized.kind === 'inline'
94
+ ? `inline registration${normalized.nameHint ? ` (${normalized.nameHint})` : ''}`
95
+ : resolve(configDir, normalized.resolvePath);
96
+ validatePlugin(input.cliVersion, plugin, sourceLabel);
97
+ if (normalized.nameHint && normalized.nameHint !== plugin.manifest.name) {
98
+ throw new Error(`Plugin name mismatch for ${sourceLabel}: configured "${normalized.nameHint}" but manifest is "${plugin.manifest.name}".`);
99
+ }
100
+ if (byName.has(plugin.manifest.name)) {
101
+ throw new Error(`Duplicate plugin name "${plugin.manifest.name}" in config.plugins.`);
102
+ }
103
+ const item = {
104
+ plugin,
105
+ options: normalized.options,
106
+ };
107
+ loaded.push(item);
108
+ byName.set(plugin.manifest.name, item);
109
+ }
110
+ return {
111
+ plugins: loaded,
112
+ getCommand(pluginName, commandName) {
113
+ const item = byName.get(pluginName);
114
+ if (!item)
115
+ return null;
116
+ const command = (item.plugin.commands ?? []).find((entry) => entry.name === commandName);
117
+ if (!command)
118
+ return null;
119
+ return { plugin: item, command };
120
+ },
121
+ async runOnConfigLoaded(context) {
122
+ const tableScope = context.tableScope ?? UNFILTERED_TABLE_SCOPE;
123
+ for (const item of loaded) {
124
+ const hook = item.plugin.hooks?.onConfigLoaded;
125
+ if (!hook)
126
+ continue;
127
+ try {
128
+ await hook({ ...context, options: item.options, tableScope });
129
+ }
130
+ catch (error) {
131
+ throw formatPluginError(item.plugin.manifest.name, 'onConfigLoaded', error);
132
+ }
133
+ }
134
+ },
135
+ async runOnSchemaLoaded(context) {
136
+ let definitions = context.definitions;
137
+ for (const item of loaded) {
138
+ const hook = item.plugin.hooks?.onSchemaLoaded;
139
+ if (!hook)
140
+ continue;
141
+ try {
142
+ const next = await hook({ ...context, definitions });
143
+ if (Array.isArray(next)) {
144
+ definitions = canonicalizeDefinitions(next);
145
+ }
146
+ }
147
+ catch (error) {
148
+ throw formatPluginError(item.plugin.manifest.name, 'onSchemaLoaded', error);
149
+ }
150
+ }
151
+ return definitions;
152
+ },
153
+ async runOnPlanCreated(context, initialPlan) {
154
+ const tableScope = context.tableScope ?? UNFILTERED_TABLE_SCOPE;
155
+ let plan = initialPlan;
156
+ for (const item of loaded) {
157
+ const hook = item.plugin.hooks?.onPlanCreated;
158
+ if (!hook)
159
+ continue;
160
+ try {
161
+ const next = await hook({ ...context, tableScope, plan });
162
+ if (next)
163
+ plan = next;
164
+ }
165
+ catch (error) {
166
+ throw formatPluginError(item.plugin.manifest.name, 'onPlanCreated', error);
167
+ }
168
+ }
169
+ return plan;
170
+ },
171
+ async runOnBeforeApply(context) {
172
+ let statements = context.statements;
173
+ for (const item of loaded) {
174
+ const hook = item.plugin.hooks?.onBeforeApply;
175
+ if (!hook)
176
+ continue;
177
+ try {
178
+ const result = await hook({ ...context, statements });
179
+ if (result?.statements)
180
+ statements = result.statements;
181
+ }
182
+ catch (error) {
183
+ throw formatPluginError(item.plugin.manifest.name, 'onBeforeApply', error);
184
+ }
185
+ }
186
+ return statements;
187
+ },
188
+ async runOnAfterApply(context) {
189
+ for (const item of loaded) {
190
+ const hook = item.plugin.hooks?.onAfterApply;
191
+ if (!hook)
192
+ continue;
193
+ try {
194
+ await hook(context);
195
+ }
196
+ catch (error) {
197
+ throw formatPluginError(item.plugin.manifest.name, 'onAfterApply', error);
198
+ }
199
+ }
200
+ },
201
+ async runOnCheck(context) {
202
+ const tableScope = context.tableScope ?? UNFILTERED_TABLE_SCOPE;
203
+ const results = [];
204
+ for (const item of loaded) {
205
+ const hook = item.plugin.hooks?.onCheck;
206
+ if (!hook)
207
+ continue;
208
+ try {
209
+ const result = await hook({ ...context, options: item.options, tableScope });
210
+ if (!result)
211
+ continue;
212
+ results.push({
213
+ plugin: result.plugin || item.plugin.manifest.name,
214
+ evaluated: result.evaluated,
215
+ ok: result.ok,
216
+ findings: result.findings,
217
+ metadata: result.metadata,
218
+ });
219
+ }
220
+ catch (error) {
221
+ throw formatPluginError(item.plugin.manifest.name, 'onCheck', error);
222
+ }
223
+ }
224
+ return results;
225
+ },
226
+ async runOnCheckReport(results, print) {
227
+ for (const result of results) {
228
+ const item = byName.get(result.plugin);
229
+ if (!item)
230
+ continue;
231
+ const hook = item.plugin.hooks?.onCheckReport;
232
+ if (!hook)
233
+ continue;
234
+ try {
235
+ await hook({ result, print });
236
+ }
237
+ catch (error) {
238
+ throw formatPluginError(item.plugin.manifest.name, 'onCheckReport', error);
239
+ }
240
+ }
241
+ },
242
+ async runPluginCommand(pluginName, commandName, context) {
243
+ const item = byName.get(pluginName);
244
+ if (!item)
245
+ return 1;
246
+ const command = (item.plugin.commands ?? []).find((entry) => entry.name === commandName);
247
+ if (!command)
248
+ return 1;
249
+ try {
250
+ const code = await command.run({
251
+ ...context,
252
+ pluginName,
253
+ options: item.options,
254
+ tableScope: context.tableScope ?? UNFILTERED_TABLE_SCOPE,
255
+ });
256
+ return typeof code === 'number' ? code : 0;
257
+ }
258
+ catch (error) {
259
+ throw formatPluginError(item.plugin.manifest.name, `command:${commandName}`, error);
260
+ }
261
+ },
262
+ };
263
+ }
264
+ //# sourceMappingURL=plugin-runtime.js.map