@manifest-configuration-language/browser 0.3.10 → 0.3.12

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/README.md CHANGED
@@ -31,14 +31,14 @@ An open project is a Worker-backed session. Call `project.update(files)` with th
31
31
 
32
32
  `project.complete({ entrypoint, position })` returns the MCL language-service candidates for a zero-based UTF-16 position. Completion uses the same local project files as parsing and rendering, including schemas and Helm values schemas. It does not access a Kubernetes API server or any other network service.
33
33
 
34
- `project.definition({ entrypoint, position })` returns a project-relative declaration path and zero-based UTF-16 range for local and imported MCL declarations. `project.hover({ entrypoint, position })` returns declaration syntax, including explicit type annotations and function or rule signatures. `project.references({ entrypoint, position })` returns the declaration and references found in the supplied MCL project. These operations use only project files already supplied to the browser runtime.
34
+ `project.definition({ entrypoint, position })` returns a project-relative declaration path and zero-based UTF-16 range for local and imported MCL declarations. `project.hover({ entrypoint, position })` returns declaration syntax, including explicit type annotations and function or rule signatures. `project.references({ entrypoint, position })` returns the declaration and references found in the supplied MCL project. `project.renameFileImports({ oldPath, newPath, entrypoint })` returns import-path edits needed when an MCL file moves. These operations use only project files already supplied to the browser runtime.
35
35
 
36
- The package exports the completion, definition, hover, references, rename, and source map result types, `maxSourceBytes`, `maxSourceMapBytes`, `maxRenameNameLength`, `maxProjectFiles`, `maxProjectFileBytes`, and `maxProjectBytes` so browser interfaces can consume the runtime's public types and limits. `isValidProjectFileSet(paths)` checks path validity, duplicate paths, and file/directory conflicts before a UI creates or renames project files. `rename()` returns edits for local symbols and exported declarations, including qualified value and type references in the supplied MCL project. It returns no edits when a rename would be ambiguous or collide with an existing exported declaration.
36
+ The package exports the completion, definition, hover, references, rename, file-import rename, and source map result types, `maxSourceBytes`, `maxSourceMapBytes`, `maxRenameNameLength`, `maxProjectFiles`, `maxProjectFileBytes`, and `maxProjectBytes` so browser interfaces can consume the runtime's public types and limits. `isValidProjectFileSet(paths)` checks path validity, duplicate paths, and file/directory conflicts before a UI creates or renames project files. `rename()` returns edits for local symbols and exported declarations, including qualified value and type references in the supplied MCL project. It returns no edits when a rename would be ambiguous or collide with an existing exported declaration. `renameFileImports()` returns an error if any project MCL file has a syntax error because its import references cannot be determined safely.
37
37
 
38
38
  MCL decodes the request into a root-relative `io/fs` filesystem for project files, module imports, schemas, and dependency locks. Kubernetes resource scope checks use built-in metadata and CRDs in the project; unknown resource kinds can still be rendered. The runtime limits are defined in the [protocol schema](https://github.com/manifest-configuration-language/mcl/blob/main/cmd/mcl-wasm/protocol.schema.json). The worker blocks `fetch` after loading the WASM runtime assets, so MCL project evaluation cannot make external network requests.
39
39
 
40
40
  The wire format is described in [`protocol.schema.json`](https://github.com/manifest-configuration-language/mcl/blob/main/cmd/mcl-wasm/protocol.schema.json). Go protocol models are generated with `go generate ./cmd/mcl-wasm`, and the browser package declarations are generated with `npm run generate:protocol`. The browser API declarations reuse the generated operation, diagnostic, and result types. MCL decodes each request into a root-relative `io/fs` project filesystem. Kustomize project overlays and locked Git archives use kyaml's in-memory filesystem, and Helm source loading accepts an `io/fs` filesystem. The Go `wasm_exec.js` runtime supplies its standard browser fallbacks for process, path, and stdout APIs; the Browser SDK does not provide a Node-style project filesystem or require Node polyfills in Vite.
41
41
 
42
- `MclRuntimeError` and lint diagnostics report project-relative paths with UTF-16 start and end positions. Evaluation errors also include related source locations when the Go engine provides them, such as the schema declaration associated with a resource validation error.
42
+ `MclRuntimeError` and lint diagnostics report project-relative paths with UTF-16 start and end positions. Lint diagnostics can also include code actions with project-relative replacement edits; the current `removeUnreachableDefinition` action removes an unreachable declaration. Evaluation errors also include related source locations when the Go engine provides them, such as the schema declaration associated with a resource validation error.
43
43
 
44
44
  The [WebAssembly code size profile](https://github.com/manifest-configuration-language/mcl/blob/main/packages/browser/performance-profile.md) records package-level function body sizes and explains which WebAssembly sections it excludes.
package/dist/mcl.wasm CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/mcl.wasm
3
- size: 96805940 bytes
4
- sha256: f198de23e073d7ec86f321068a82b8461a3358c7d57ebffda0950092e5649442
3
+ size: 96854882 bytes
4
+ sha256: 0a8fc56d414f82aaebc05de2cfacc99c56d894c2fd31b43596665acbf743721c
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifest-configuration-language/browser",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "description": "Run MCL projects in a browser Web Worker using the Go WebAssembly runtime.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/src/index.d.ts CHANGED
@@ -11,6 +11,7 @@ import type {
11
11
  HoverInfo as ProtocolHoverInfo,
12
12
  HoverResult as ProtocolHoverResult,
13
13
  LintDiagnostic as ProtocolLintDiagnostic,
14
+ LintCodeAction as ProtocolLintCodeAction,
14
15
  ParseResult,
15
16
  RelatedLocation as ProtocolRelatedLocation,
16
17
  ReferenceLocation as ProtocolReferenceLocation,
@@ -18,6 +19,7 @@ import type {
18
19
  RenderResult,
19
20
  RenameEdit as ProtocolRenameEdit,
20
21
  RenameResult as ProtocolRenameResult,
22
+ RenameFileImportsResult as ProtocolRenameFileImportsResult,
21
23
  Request as WasmRequest,
22
24
  SourceRange as ProtocolSourceRange,
23
25
  SourceMap as ProtocolSourceMap,
@@ -45,6 +47,7 @@ export type ProjectFiles = Readonly<Record<string, ProjectFile>>;
45
47
  export type MclError = ProtocolError;
46
48
 
47
49
  export type LintDiagnostic = ProtocolLintDiagnostic;
50
+ export type LintCodeAction = ProtocolLintCodeAction;
48
51
  export type CompletionPosition = ProtocolCompletionPosition;
49
52
  export type CompletionItem = ProtocolCompletionItem;
50
53
  export type CompletionResult = ProtocolCompletionResult;
@@ -54,6 +57,7 @@ export type HoverResult = ProtocolHoverResult;
54
57
  export type HoverInfo = ProtocolHoverInfo;
55
58
  export type RenameEdit = ProtocolRenameEdit;
56
59
  export type RenameResult = ProtocolRenameResult;
60
+ export type RenameFileImportsResult = ProtocolRenameFileImportsResult;
57
61
  export type ReferenceLocation = ProtocolReferenceLocation;
58
62
  export type ReferencesResult = ProtocolReferencesResult;
59
63
  export type SourceRange = ProtocolSourceRange;
@@ -69,6 +73,7 @@ export type MclResult =
69
73
  | ({ operation: "hover" } & ProtocolHoverResult)
70
74
  | ({ operation: "references" } & ProtocolReferencesResult)
71
75
  | ({ operation: "rename" } & ProtocolRenameResult)
76
+ | ({ operation: "renameFileImports" } & ProtocolRenameFileImportsResult)
72
77
  | ({ operation: "format" } & FormatResult)
73
78
  | ({ operation: "check" } & CheckResult)
74
79
  | ({ operation: "evaluate" } & EvaluateResult)
@@ -158,6 +163,15 @@ export interface MclRuntime {
158
163
  files: ProjectFiles | undefined,
159
164
  options: RenameRequestOptions,
160
165
  ): Promise<MclResult & { operation: "rename" }>;
166
+ renameFileImports(
167
+ source: string,
168
+ options: FileRenameRequestOptions,
169
+ ): Promise<MclResult & { operation: "renameFileImports" }>;
170
+ renameFileImports(
171
+ source: string,
172
+ files: ProjectFiles | undefined,
173
+ options: FileRenameRequestOptions,
174
+ ): Promise<MclResult & { operation: "renameFileImports" }>;
161
175
  dispose(): void;
162
176
  }
163
177
 
@@ -171,6 +185,9 @@ export interface MclProject {
171
185
  hover(options: ProjectNavigationOptions): Promise<MclResult & { operation: "hover" }>;
172
186
  references(options: ProjectNavigationOptions): Promise<MclResult & { operation: "references" }>;
173
187
  rename(options: ProjectRenameOptions): Promise<MclResult & { operation: "rename" }>;
188
+ renameFileImports(
189
+ options: ProjectFileRenameOptions,
190
+ ): Promise<MclResult & { operation: "renameFileImports" }>;
174
191
  format(options?: ProjectOperationOptions): Promise<MclResult & { operation: "format" }>;
175
192
  check(options?: ProjectOperationOptions): Promise<MclResult & { operation: "check" }>;
176
193
  evaluate(options?: ProjectOperationOptions): Promise<MclResult & { operation: "evaluate" }>;
@@ -200,6 +217,11 @@ export interface ProjectRenameOptions extends ProjectNavigationOptions {
200
217
  newName: string;
201
218
  }
202
219
 
220
+ export interface ProjectFileRenameOptions extends ProjectOperationOptions {
221
+ oldPath: string;
222
+ newPath: string;
223
+ }
224
+
203
225
  export interface PositionRequestOptions extends RequestOptions {
204
226
  entrypoint?: string;
205
227
  position: CompletionPosition;
@@ -209,6 +231,12 @@ export interface RenameRequestOptions extends PositionRequestOptions {
209
231
  newName: string;
210
232
  }
211
233
 
234
+ export interface FileRenameRequestOptions extends RequestOptions {
235
+ entrypoint?: string;
236
+ oldPath: string;
237
+ newPath: string;
238
+ }
239
+
212
240
  export declare class MclRuntimeError extends Error {
213
241
  readonly code: string;
214
242
  readonly path?: string;
package/src/index.js CHANGED
@@ -69,6 +69,7 @@ const operationPriorities = {
69
69
  parse: 20,
70
70
  format: 20,
71
71
  rename: 20,
72
+ renameFileImports: 20,
72
73
  references: 20,
73
74
  definition: 20,
74
75
  completion: 20,
@@ -415,6 +416,19 @@ export function createMclRuntime(options = {}) {
415
416
  position,
416
417
  project,
417
418
  ) {
419
+ if (operation === "renameFileImports") {
420
+ const { oldPath, newPath } = requestOptions;
421
+ if (
422
+ !isValidProjectPath(oldPath) ||
423
+ !oldPath.endsWith(".mcl") ||
424
+ !isValidProjectPath(newPath) ||
425
+ !newPath.endsWith(".mcl")
426
+ ) {
427
+ throw new TypeError("oldPath and newPath must be valid project-relative MCL paths");
428
+ }
429
+ if (oldPath === newPath)
430
+ throw new TypeError("oldPath and newPath must be distinct");
431
+ }
418
432
  const signal = requestOptions.signal;
419
433
  if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
420
434
  const startedAt = performance.now();
@@ -509,6 +523,8 @@ export function createMclRuntime(options = {}) {
509
523
  entrypoint,
510
524
  position,
511
525
  newName: requestOptions.newName,
526
+ oldPath: requestOptions.oldPath,
527
+ newPath: requestOptions.newPath,
512
528
  };
513
529
  if (project) message.projectId = project.id;
514
530
  else message.files = preparedFiles.files;
@@ -674,6 +690,8 @@ export function createMclRuntime(options = {}) {
674
690
  hover: (requestOptions) => runProjectOperation("hover", requestOptions),
675
691
  references: (requestOptions) => runProjectOperation("references", requestOptions),
676
692
  rename: (requestOptions) => runProjectOperation("rename", requestOptions),
693
+ renameFileImports: (requestOptions) =>
694
+ runProjectOperation("renameFileImports", requestOptions),
677
695
  format: (requestOptions) => runProjectOperation("format", requestOptions),
678
696
  check: (requestOptions) => runProjectOperation("check", requestOptions),
679
697
  evaluate: (requestOptions) => runProjectOperation("evaluate", requestOptions),
@@ -740,6 +758,21 @@ export function createMclRuntime(options = {}) {
740
758
  );
741
759
  }
742
760
 
761
+ function runSourceFileRename(source, filesOrOptions, requestOptions) {
762
+ const files = requestOptions === undefined ? undefined : filesOrOptions;
763
+ const options = requestOptions ?? filesOrOptions;
764
+ if (!options?.oldPath || !options?.newPath)
765
+ throw new TypeError("oldPath and newPath are required");
766
+ return execute(
767
+ "renameFileImports",
768
+ source,
769
+ files,
770
+ options,
771
+ options.entrypoint ?? "main.mcl",
772
+ undefined,
773
+ );
774
+ }
775
+
743
776
  return {
744
777
  openProject,
745
778
  warmUp,
@@ -757,6 +790,8 @@ export function createMclRuntime(options = {}) {
757
790
  runSourceNavigation("references", source, filesOrOptions, requestOptions),
758
791
  rename: (source, filesOrOptions, requestOptions) =>
759
792
  runSourceNavigation("rename", source, filesOrOptions, requestOptions),
793
+ renameFileImports: (source, filesOrOptions, requestOptions) =>
794
+ runSourceFileRename(source, filesOrOptions, requestOptions),
760
795
  dispose() {
761
796
  if (disposed) return;
762
797
  disposed = true;
package/src/protocol.d.ts CHANGED
@@ -15,10 +15,13 @@ export type Request = {
15
15
  | "definition"
16
16
  | "hover"
17
17
  | "references"
18
- | "rename";
18
+ | "rename"
19
+ | "renameFileImports";
19
20
  position?: CompletionPosition;
20
21
  newName?: string;
21
- entrypoint?: ProjectPath;
22
+ oldPath?: ProjectPath;
23
+ newPath?: ProjectPath;
24
+ entrypoint?: ProjectPath2;
22
25
  /**
23
26
  * UTF-8 entrypoint source, limited by the runtime.
24
27
  */
@@ -30,10 +33,12 @@ export type Request = {
30
33
  [k: string]: FileInput;
31
34
  };
32
35
  };
36
+ export type ProjectPath = ProjectPath1;
37
+ export type ProjectPath1 = string;
33
38
  /**
34
39
  * Project-relative MCL source path. Defaults to main.mcl.
35
40
  */
36
- export type ProjectPath = string;
41
+ export type ProjectPath2 = string;
37
42
  /**
38
43
  * Binary files omit content and are supplied in the optional second run argument under the same path.
39
44
  */
@@ -42,8 +47,6 @@ export type FileInput = {
42
47
  content?: string;
43
48
  };
44
49
  export type LintResult = LintDiagnostic[];
45
- export type ProjectPath1 = ProjectPath2;
46
- export type ProjectPath2 = string;
47
50
 
48
51
  export interface CompletionPosition {
49
52
  line: number;
@@ -64,7 +67,8 @@ export interface Response {
64
67
  | DefinitionResult
65
68
  | HoverResult
66
69
  | ReferencesResult
67
- | RenameResult;
70
+ | RenameResult
71
+ | RenameFileImportsResult;
68
72
  error?: Error;
69
73
  }
70
74
  export interface ParseResult {
@@ -79,6 +83,23 @@ export interface LintDiagnostic {
79
83
  column: number;
80
84
  endLine: number;
81
85
  endColumn: number;
86
+ actions?: LintCodeAction[];
87
+ }
88
+ export interface LintCodeAction {
89
+ kind: "removeUnreachableDefinition";
90
+ /**
91
+ * @minItems 1
92
+ */
93
+ edits: [RenameEdit, ...RenameEdit[]];
94
+ }
95
+ export interface RenameEdit {
96
+ path: ProjectPath;
97
+ range: SourceRange;
98
+ newText: string;
99
+ }
100
+ export interface SourceRange {
101
+ start: CompletionPosition;
102
+ end: CompletionPosition;
82
103
  }
83
104
  export interface FormatResult {
84
105
  source: string;
@@ -113,12 +134,8 @@ export interface SourceMapEntry {
113
134
  output: SourceRange;
114
135
  sources: SourceMapOrigin[];
115
136
  }
116
- export interface SourceRange {
117
- start: CompletionPosition;
118
- end: CompletionPosition;
119
- }
120
137
  export interface SourceMapOrigin {
121
- path: ProjectPath1;
138
+ path: ProjectPath;
122
139
  range: SourceRange;
123
140
  kind: "mcl" | "mcl-overlay-base" | "mcl-overlay-patch";
124
141
  multiplicity: "unique" | "repeated" | "ambiguous";
@@ -158,16 +175,16 @@ export interface ReferencesResult {
158
175
  references: ReferenceLocation[];
159
176
  }
160
177
  export interface ReferenceLocation {
161
- path: ProjectPath1;
178
+ path: ProjectPath;
162
179
  range: SourceRange;
163
180
  }
164
181
  export interface RenameResult {
165
182
  edits: RenameEdit[];
166
183
  }
167
- export interface RenameEdit {
168
- path: ProjectPath1;
169
- range: SourceRange;
170
- newText: string;
184
+ export interface RenameFileImportsResult {
185
+ oldPath: ProjectPath;
186
+ newPath: ProjectPath;
187
+ edits: RenameEdit[];
171
188
  }
172
189
  export interface Error {
173
190
  code: string;
package/src/worker.js CHANGED
@@ -168,6 +168,8 @@ self.addEventListener("message", async (event) => {
168
168
  operation: message.operation,
169
169
  entrypoint: message.entrypoint,
170
170
  newName: message.newName,
171
+ oldPath: message.oldPath,
172
+ newPath: message.newPath,
171
173
  position: message.position,
172
174
  source: message.source,
173
175
  files: encodedFiles.files,