@mica-js/document 0.5.0 → 0.7.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.
@@ -1,511 +1,5 @@
1
1
  import { t as isUuidV4 } from "../uuid-DegOw3iI.js";
2
- //#region src/fused/diagnostics.ts
3
- /** JSON Pointer of a field path; segments escape `~` and `/` (RFC 6901). */
4
- function toPointer(path) {
5
- if (path.length === 0) return "";
6
- return `/${path.map((segment) => segment.replace(/~/g, "~0").replace(/\//g, "~1")).join("/")}`;
7
- }
8
- /**
9
- * Thrown when fused device data violates its contract.
10
- *
11
- * `diagnostics` carries every problem found, each with an explicit code and JSON Pointer, so a
12
- * host can report them without re-parsing.
13
- */
14
- var FusedDocumentError = class extends Error {
15
- diagnostics;
16
- constructor(diagnostics) {
17
- super(buildMessage(diagnostics));
18
- this.name = "FusedDocumentError";
19
- this.diagnostics = diagnostics;
20
- }
21
- /** Code of the first diagnostic, for coarse programmatic handling. */
22
- get code() {
23
- return this.diagnostics[0]?.code;
24
- }
25
- /** Field path of the first diagnostic, for coarse programmatic handling. */
26
- get pointer() {
27
- return this.diagnostics[0]?.pointer;
28
- }
29
- };
30
- /** Records one diagnostic for `path` as an error. */
31
- function report(diagnostics, code, message, path) {
32
- diagnostics.push({
33
- severity: "error",
34
- code,
35
- message,
36
- pointer: toPointer(path)
37
- });
38
- }
39
- function buildMessage(diagnostics) {
40
- const errors = diagnostics.filter((diagnostic) => diagnostic.severity === "error");
41
- const [first, ...rest] = errors.length > 0 ? errors : diagnostics;
42
- if (first === void 0) return "Fused device validation failed.";
43
- const location = first.pointer === "" ? "" : ` at ${first.pointer}`;
44
- const suffix = rest.length === 0 ? "" : ` (and ${rest.length} more)`;
45
- return `${first.code}${location}: ${first.message}${suffix}`;
46
- }
47
- //#endregion
48
- //#region src/fused/rules.ts
49
- /** Lexical rules of device identity, versions, paths and member names (RFC 0020 / RFC 0024). */
50
- var NAME_SEGMENT = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
51
- var DEVICE_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*:[a-z0-9]+(?:-[a-z0-9]+)*$/;
52
- var SEMVER = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
53
- var INTEGRITY = /^sha256:[0-9a-f]{64}$/;
54
- var MEMBER_KEY = /^[A-Za-z][A-Za-z0-9]*$/;
55
- var EVENT_KEY = /^onDid[A-Z][A-Za-z0-9]*$/;
56
- var PIN_ID = /^[A-Za-z_][A-Za-z0-9_]*$/;
57
- var CODICON = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
58
- var DESIGNATOR_PREFIX = /^[A-Za-z][A-Za-z0-9]*$/;
59
- var EXTENSION = /^\.[A-Za-z0-9]+$/;
60
- var COLOR = /^#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
61
- var DRIVE_LETTER = /^[A-Za-z]:/;
62
- var URL_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*:/;
63
- /** True when the text carries C0 or DEL control characters. */
64
- function hasControlCharacters(value) {
65
- for (const character of value) {
66
- const code = character.codePointAt(0) ?? 0;
67
- if (code < 32 || code === 127) return true;
68
- }
69
- return false;
70
- }
71
- /** Publisher namespace or device name segment; defaults to `U` for designator prefixes. */
72
- function isNameSegment(value) {
73
- return NAME_SEGMENT.test(value);
74
- }
75
- /** Full `publisher:name` device id (RFC 0020). */
76
- function isDeviceId(value) {
77
- return DEVICE_ID.test(value);
78
- }
79
- /** Problem of a `publisher:name` device id, or `undefined` when it is well formed. */
80
- function deviceIdProblem(value) {
81
- if (value.length === 0) return "must not be empty";
82
- return isDeviceId(value) ? void 0 : "must be a \"publisher:name\" pair of lowercase dash-separated segments";
83
- }
84
- /** Full SemVer version, including prerelease and build metadata (RFC 0020). */
85
- function isSemVer(value) {
86
- return SEMVER.test(value);
87
- }
88
- /** Release identity or file digest: `sha256:` plus 64 lowercase hex digits (RFC 0020). */
89
- function isIntegrity(value) {
90
- return INTEGRITY.test(value);
91
- }
92
- /** Property, method, public type and view id key (RFC 0020). */
93
- function isMemberKey(value) {
94
- return MEMBER_KEY.test(value);
95
- }
96
- /** Event key in `onDidXxx` form (RFC 0020 / RFC 0021). */
97
- function isEventKey(value) {
98
- return EVENT_KEY.test(value);
99
- }
100
- /** Model pin name, matching the DDL identifier form (RFC 0021). */
101
- function isPinId(value) {
102
- return PIN_ID.test(value);
103
- }
104
- /** VS Code Codicons name supplied by the editor (RFC 0020). */
105
- function isCodiconName(value) {
106
- return CODICON.test(value);
107
- }
108
- /** Reference designator prefix (RFC 0020). */
109
- function isDesignatorPrefix(value) {
110
- return DESIGNATOR_PREFIX.test(value);
111
- }
112
- /** `binary` extension filter entry, e.g. `.bin` (RFC 0020). */
113
- function isExtensionFilter(value) {
114
- return EXTENSION.test(value);
115
- }
116
- /** `#RRGGBB` / `#RRGGBBAA` color (RFC 0009). */
117
- function isColor(value) {
118
- return COLOR.test(value);
119
- }
120
- /**
121
- * Package-root relative POSIX file path problem, or `undefined` when it is well formed.
122
- *
123
- * Case sensitivity, empty segments, `.` / `..`, backslashes and absolute paths are rejected
124
- * (RFC 0020).
125
- */
126
- function packagePathProblem(path) {
127
- return relativePathProblem(path, "package root");
128
- }
129
- /** Project-root relative POSIX file path problem, or `undefined` when it is well formed. */
130
- function projectPathProblem(path) {
131
- return relativePathProblem(path, "project root");
132
- }
133
- function relativePathProblem(path, root) {
134
- if (path.length === 0) return "must not be empty";
135
- if (path.startsWith("/")) return `must be relative to the ${root}, not absolute`;
136
- if (DRIVE_LETTER.test(path)) return "must not carry a drive letter";
137
- if (URL_SCHEME.test(path)) return "must not be a URL";
138
- if (path.includes("\\")) return "must use POSIX separators";
139
- if (hasControlCharacters(path)) return "must not contain control characters";
140
- const segments = path.split("/");
141
- if (segments[segments.length - 1] === "") return "must name a file, not a directory";
142
- for (const segment of segments) {
143
- if (segment.length === 0) return "must not contain empty segments";
144
- if (segment === "." || segment === "..") return `must not contain "${segment}" segments`;
145
- }
146
- }
147
- /** Problem of a file name that must end in one of `extensions`, or `undefined` when it does. */
148
- function extensionProblem(path, extensions) {
149
- const lower = path.toLowerCase();
150
- return extensions.map((extension) => extension.toLowerCase()).some((extension) => lower.endsWith(extension)) ? void 0 : `must name a ${extensions.join(" or ")} file`;
151
- }
152
- /** `sha256:` digest problem of a release identity or file digest, or `undefined` when valid. */
153
- function integrityProblem(value) {
154
- return isIntegrity(value) ? void 0 : "must be \"sha256:\" followed by 64 lowercase hexadecimal digits";
155
- }
156
- /** Normalizes `#RRGGBB` / `#RRGGBBAA` to upper case; `undefined` when the text is not a color. */
157
- function normalizeColor(value) {
158
- return isColor(value) ? value.toUpperCase() : void 0;
159
- }
160
- //#endregion
161
- //#region src/fused/json.ts
162
- /**
163
- * Strict JSON reader for the fused contracts.
164
- *
165
- * `JSON.parse` silently keeps the last of two equal keys, which would let a manifest or a `.sch`
166
- * file carry two different values for one field. RFC 0020 and RFC 0024 require rejecting
167
- * duplicate keys, so the parsers decode JSON text with this reader instead. Keys are compared
168
- * after unescaping, so `"a"` and `"\u0061"` are the same key.
169
- */
170
- /** Deepest object/array nesting the reader accepts. */
171
- var STRICT_JSON_MAX_DEPTH = 256;
172
- /**
173
- * Decodes JSON text, rejecting duplicate keys and reporting every problem with a JSON Pointer.
174
- *
175
- * @throws {FusedDocumentError} when the text is not valid JSON or repeats an object key.
176
- */
177
- function parseStrictJson(text) {
178
- const result = decodeStrictJson(text);
179
- if (!result.ok) throw new FusedDocumentError(result.diagnostics);
180
- return result.value;
181
- }
182
- /** Non-throwing form of {@link parseStrictJson}; the caller decides how to surface the problems. */
183
- function decodeStrictJson(text) {
184
- return new Reader(text).decode();
185
- }
186
- var Reader = class {
187
- #text;
188
- #diagnostics = [];
189
- #index = 0;
190
- #failed = false;
191
- constructor(text) {
192
- this.#text = text;
193
- }
194
- decode() {
195
- this.#skipWhitespace();
196
- const value = this.#readValue([], 0);
197
- if (this.#failed) return this.#failure();
198
- this.#skipWhitespace();
199
- if (this.#index !== this.#text.length) {
200
- this.#fail("Unexpected content after the JSON value.");
201
- return this.#failure();
202
- }
203
- if (this.#diagnostics.length > 0) return this.#failure();
204
- return {
205
- ok: true,
206
- value
207
- };
208
- }
209
- #failure() {
210
- return {
211
- ok: false,
212
- diagnostics: this.#diagnostics
213
- };
214
- }
215
- #fail(message) {
216
- if (!this.#failed) report(this.#diagnostics, "json/invalid", `Invalid JSON at offset ${String(this.#index)}: ${message}`, []);
217
- this.#failed = true;
218
- }
219
- #skipWhitespace() {
220
- while (this.#index < this.#text.length) {
221
- const code = this.#text.charCodeAt(this.#index);
222
- if (code !== 32 && code !== 9 && code !== 10 && code !== 13) return;
223
- this.#index += 1;
224
- }
225
- }
226
- #readValue(path, depth) {
227
- this.#skipWhitespace();
228
- if (this.#index >= this.#text.length) return this.#fail("Unexpected end of input; expected a value.");
229
- if (depth > 256) return this.#fail(`Nesting deeper than ${String(256)} is not supported.`);
230
- switch (this.#text[this.#index]) {
231
- case "{": return this.#readObject(path, depth + 1);
232
- case "[": return this.#readArray(path, depth + 1);
233
- case "\"": return this.#readString();
234
- case "t": return this.#readKeyword("true", true);
235
- case "f": return this.#readKeyword("false", false);
236
- case "n": return this.#readKeyword("null", null);
237
- default: return this.#readNumber();
238
- }
239
- }
240
- #readKeyword(keyword, value) {
241
- if (this.#text.startsWith(keyword, this.#index)) {
242
- this.#index += keyword.length;
243
- return value;
244
- }
245
- return this.#fail(`Expected ${keyword}.`);
246
- }
247
- #readNumber() {
248
- NUMBER.lastIndex = this.#index;
249
- const match = NUMBER.exec(this.#text);
250
- if (match === null) return this.#fail("Expected a value.");
251
- this.#index = NUMBER.lastIndex;
252
- return Number(match[0]);
253
- }
254
- #readString() {
255
- this.#index += 1;
256
- let value = "";
257
- let chunkStart = this.#index;
258
- for (;;) {
259
- if (this.#index >= this.#text.length) return this.#fail("Unterminated string.");
260
- const code = this.#text.charCodeAt(this.#index);
261
- if (code === 34) {
262
- value += this.#text.slice(chunkStart, this.#index);
263
- this.#index += 1;
264
- return value;
265
- }
266
- if (code === 92) {
267
- value += this.#text.slice(chunkStart, this.#index);
268
- this.#index += 1;
269
- const escape = this.#readEscape();
270
- if (escape === void 0) return;
271
- value += escape;
272
- chunkStart = this.#index;
273
- continue;
274
- }
275
- if (code < 32) return this.#fail("Control characters must be escaped inside strings.");
276
- this.#index += 1;
277
- }
278
- }
279
- #readEscape() {
280
- if (this.#index >= this.#text.length) return this.#fail("Unterminated escape sequence.");
281
- const character = this.#text[this.#index];
282
- this.#index += 1;
283
- switch (character) {
284
- case "\"": return "\"";
285
- case "\\": return "\\";
286
- case "/": return "/";
287
- case "b": return "\b";
288
- case "f": return "\f";
289
- case "n": return "\n";
290
- case "r": return "\r";
291
- case "t": return " ";
292
- case "u": return this.#readUnicodeEscape();
293
- default: return this.#fail(`Unknown escape sequence "\\${String(character)}".`);
294
- }
295
- }
296
- #readUnicodeEscape() {
297
- const digits = this.#text.slice(this.#index, this.#index + 4);
298
- if (!/^[0-9a-fA-F]{4}$/.test(digits)) return this.#fail("Unicode escapes need exactly four hexadecimal digits.");
299
- this.#index += 4;
300
- return String.fromCharCode(Number.parseInt(digits, 16));
301
- }
302
- #readObject(path, depth) {
303
- this.#index += 1;
304
- const object = {};
305
- const keys = /* @__PURE__ */ new Set();
306
- this.#skipWhitespace();
307
- if (this.#text[this.#index] === "}") {
308
- this.#index += 1;
309
- return object;
310
- }
311
- for (;;) {
312
- this.#skipWhitespace();
313
- if (this.#text[this.#index] !== "\"") return this.#fail("Expected a property name.");
314
- const key = this.#readString();
315
- if (key === void 0) return;
316
- this.#skipWhitespace();
317
- if (this.#text[this.#index] !== ":") return this.#fail("Expected \":\" after the property name.");
318
- this.#index += 1;
319
- const memberPath = [...path, key];
320
- const duplicate = keys.has(key);
321
- if (duplicate) report(this.#diagnostics, "json/duplicate-key", `Duplicate JSON key ${JSON.stringify(key)}; the contract does not allow one key twice.`, memberPath);
322
- else keys.add(key);
323
- const value = this.#readValue(memberPath, depth);
324
- if (this.#failed) return;
325
- if (!duplicate) Object.defineProperty(object, key, {
326
- value,
327
- enumerable: true,
328
- writable: true,
329
- configurable: true
330
- });
331
- this.#skipWhitespace();
332
- const next = this.#text[this.#index];
333
- if (next === ",") {
334
- this.#index += 1;
335
- continue;
336
- }
337
- if (next === "}") {
338
- this.#index += 1;
339
- return object;
340
- }
341
- return this.#fail("Expected \",\" or \"}\" in the object.");
342
- }
343
- }
344
- #readArray(path, depth) {
345
- this.#index += 1;
346
- const array = [];
347
- this.#skipWhitespace();
348
- if (this.#text[this.#index] === "]") {
349
- this.#index += 1;
350
- return array;
351
- }
352
- for (;;) {
353
- const item = this.#readValue([...path, String(array.length)], depth);
354
- if (this.#failed) return;
355
- array.push(item);
356
- this.#skipWhitespace();
357
- const next = this.#text[this.#index];
358
- if (next === ",") {
359
- this.#index += 1;
360
- continue;
361
- }
362
- if (next === "]") {
363
- this.#index += 1;
364
- return array;
365
- }
366
- return this.#fail("Expected \",\" or \"]\" in the array.");
367
- }
368
- }
369
- };
370
- var NUMBER = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/y;
371
- //#endregion
372
- //#region src/fused/read.ts
373
- /** Structural readers shared by the fused parsers; every failure reports code and field path. */
374
- function isRecord(value) {
375
- return typeof value === "object" && value !== null && !Array.isArray(value);
376
- }
377
- function hasOwn(value, key) {
378
- return Object.prototype.hasOwnProperty.call(value, key);
379
- }
380
- function hasErrors(diagnostics) {
381
- return diagnostics.some((diagnostic) => diagnostic.severity === "error");
382
- }
383
- function forbidUnknownFields(value, allowed, path, diagnostics) {
384
- for (const key of Object.keys(value)) if (!allowed.includes(key)) report(diagnostics, "schema/unknown-field", `Unknown field "${key}".`, [...path, key]);
385
- }
386
- /**
387
- * Strings are decoded as strict JSON text, which rejects duplicate keys; any other value is
388
- * validated as-is so callers that already hold a plain object stay supported.
389
- */
390
- function parseJsonInput(input, diagnostics) {
391
- if (typeof input !== "string") return {
392
- ok: true,
393
- value: input
394
- };
395
- const decoded = decodeStrictJson(input);
396
- if (!decoded.ok) {
397
- diagnostics.push(...decoded.diagnostics);
398
- return {
399
- ok: false,
400
- value: void 0
401
- };
402
- }
403
- return {
404
- ok: true,
405
- value: decoded.value
406
- };
407
- }
408
- function readStringField(value, key, path, diagnostics, required = true, options = {}) {
409
- const fieldPath = [...path, key];
410
- if (!hasOwn(value, key)) {
411
- if (required) report(diagnostics, "schema/missing-field", `Missing required field "${key}".`, fieldPath);
412
- return;
413
- }
414
- const field = value[key];
415
- if (typeof field !== "string") {
416
- report(diagnostics, "schema/invalid-type", `Field "${key}" must be a string.`, fieldPath);
417
- return;
418
- }
419
- if (options.nonEmpty === true && field.length === 0) {
420
- report(diagnostics, "schema/invalid-value", `Field "${key}" must not be empty.`, fieldPath);
421
- return;
422
- }
423
- return field;
424
- }
425
- function readNumberField(value, key, path, diagnostics, required = true) {
426
- const fieldPath = [...path, key];
427
- if (!hasOwn(value, key)) {
428
- if (required) report(diagnostics, "schema/missing-field", `Missing required field "${key}".`, fieldPath);
429
- return;
430
- }
431
- const field = value[key];
432
- if (typeof field !== "number") {
433
- report(diagnostics, "schema/invalid-type", `Field "${key}" must be a number.`, fieldPath);
434
- return;
435
- }
436
- if (!Number.isFinite(field)) {
437
- report(diagnostics, "schema/invalid-value", `Field "${key}" must be a finite number.`, fieldPath);
438
- return;
439
- }
440
- return field;
441
- }
442
- function readIntegerField(value, key, path, diagnostics, required = true) {
443
- const field = readNumberField(value, key, path, diagnostics, required);
444
- if (field === void 0) return;
445
- if (!Number.isSafeInteger(field)) {
446
- report(diagnostics, "schema/invalid-value", `Field "${key}" must be a safe integer.`, [...path, key]);
447
- return;
448
- }
449
- return field;
450
- }
451
- function readBooleanField(value, key, path, diagnostics, required = true) {
452
- const fieldPath = [...path, key];
453
- if (!hasOwn(value, key)) {
454
- if (required) report(diagnostics, "schema/missing-field", `Missing required field "${key}".`, fieldPath);
455
- return;
456
- }
457
- const field = value[key];
458
- if (typeof field !== "boolean") {
459
- report(diagnostics, "schema/invalid-type", `Field "${key}" must be a boolean.`, fieldPath);
460
- return;
461
- }
462
- return field;
463
- }
464
- function readObjectField(value, key, path, diagnostics, required = true) {
465
- const fieldPath = [...path, key];
466
- if (!hasOwn(value, key)) {
467
- if (required) report(diagnostics, "schema/missing-field", `Missing required field "${key}".`, fieldPath);
468
- return;
469
- }
470
- const field = value[key];
471
- if (!isRecord(field)) {
472
- report(diagnostics, "schema/invalid-type", `Field "${key}" must be an object.`, fieldPath);
473
- return;
474
- }
475
- return field;
476
- }
477
- function readArrayField(value, key, path, diagnostics, required = true) {
478
- const fieldPath = [...path, key];
479
- if (!hasOwn(value, key)) {
480
- if (required) report(diagnostics, "schema/missing-field", `Missing required field "${key}".`, fieldPath);
481
- return;
482
- }
483
- const field = value[key];
484
- if (!Array.isArray(field)) {
485
- report(diagnostics, "schema/invalid-type", `Field "${key}" must be an array.`, fieldPath);
486
- return;
487
- }
488
- return field;
489
- }
490
- /** Compares two strings by UTF-16 code unit, independent of the host locale. */
491
- function compareStrings(a, b) {
492
- if (a === b) return 0;
493
- return a < b ? -1 : 1;
494
- }
495
- /**
496
- * Records an immutable snapshot of a parsed structure.
497
- *
498
- * Parsers only build plain objects and arrays, so freezing them is safe; array-buffer views are
499
- * left alone because their contents cannot be frozen.
500
- */
501
- function deepFreeze(value) {
502
- if (typeof value !== "object" || value === null || ArrayBuffer.isView(value)) return value;
503
- if (Object.isFrozen(value)) return value;
504
- Object.freeze(value);
505
- for (const entry of Object.values(value)) deepFreeze(entry);
506
- return value;
507
- }
508
- //#endregion
2
+ import { A as isNameSegment, D as isExtensionFilter, E as isEventKey, F as projectPathProblem, I as FusedDocumentError, L as report, M as isSemVer, N as normalizeColor, O as isIntegrity, P as packagePathProblem, S as isCodiconName, T as isDeviceId, _ as decodeStrictJson, a as forbidUnknownFields, b as deviceIdProblem, c as isRecord, d as readBooleanField, f as readIntegerField, g as STRICT_JSON_MAX_DEPTH, h as readStringField, i as deepFreeze, j as isPinId, k as isMemberKey, l as parseJsonInput, m as readObjectField, n as readProperties, o as hasErrors, p as readNumberField, r as compareStrings, s as hasOwn, t as readDependencies, u as readArrayField, v as parseStrictJson, w as isDesignatorPrefix, x as extensionProblem, y as deviceDataPathProblem } from "../instance-data-H002cFE_.js";
509
3
  //#region src/fused/geometry.ts
510
4
  /** Reading and validation of device 2D geometry (RFC 0022). */
511
5
  /**
@@ -693,7 +187,8 @@ function checkPinIds(geometry, declared, path, diagnostics) {
693
187
  const missing = declaredIds.filter((pin) => !geometryIds.includes(pin));
694
188
  const extra = geometryIds.filter((pin) => !declaredIds.includes(pin));
695
189
  if (missing.length === 0 && extra.length === 0) return;
696
- report(diagnostics, "view2d/pin-mismatch", `Geometry pins must match the device pins: ${[missing.length === 0 ? void 0 : `missing ${missing.map(quote).join(", ")}`, extra.length === 0 ? void 0 : `undeclared ${extra.map(quote).join(", ")}`].filter((entry) => entry !== void 0).join("; ")}.`, [...path, "pins"]);
190
+ const details = [missing.length === 0 ? void 0 : `missing ${missing.map(quote).join(", ")}`, extra.length === 0 ? void 0 : `undeclared ${extra.map(quote).join(", ")}`].filter((entry) => entry !== void 0).join("; ");
191
+ report(diagnostics, "view2d/pin-mismatch", `Geometry pins must match the device pins: ${details}.`, [...path, "pins"]);
697
192
  }
698
193
  function quote(value) {
699
194
  return JSON.stringify(value);
@@ -1193,7 +688,7 @@ function checkDefault(value, descriptor, path, diagnostics) {
1193
688
  const allowed = (descriptor.options ?? []).map((option) => option.value);
1194
689
  return typeof value === "string" && allowed.includes(value) ? { value } : fail(`Default must be one of ${allowed.map((entry) => JSON.stringify(entry)).join(", ")}.`);
1195
690
  }
1196
- case "disk": return fail("A disk default must be null. Bind an asset on the instance.");
691
+ case "disk": return fail("A disk default must be null. Bind a deviceData image on the instance.");
1197
692
  case "image":
1198
693
  case "binary": {
1199
694
  const reference = checkPackageReference(value, path, diagnostics);
@@ -1933,116 +1428,6 @@ function readPackageFilePath(value, key, path, diagnostics, extensions, code, re
1933
1428
  return file;
1934
1429
  }
1935
1430
  //#endregion
1936
- //#region src/fused/resource.ts
1937
- var RESOURCE_MODES = ["asset", "package"];
1938
- /** Reads one instance property value; `undefined` when it does not match the contract. */
1939
- function readPropertyValue(value, path, diagnostics) {
1940
- if (value === null || typeof value === "string" || typeof value === "boolean") return value;
1941
- if (typeof value === "number") {
1942
- if (!Number.isFinite(value)) {
1943
- report(diagnostics, "schema/invalid-value", "Numeric property values must be finite.", path);
1944
- return;
1945
- }
1946
- return value;
1947
- }
1948
- if (isRecord(value)) return readReference$1(value, path, diagnostics);
1949
- report(diagnostics, "schema/invalid-type", "Property value must be a scalar, a resource reference, a firmware reference or null.", path);
1950
- }
1951
- function readReference$1(value, path, diagnostics) {
1952
- const mode = readStringField(value, "mode", path, diagnostics, true, { nonEmpty: true });
1953
- if (mode === void 0) return;
1954
- if (mode === "project") return readProjectReference(value, path, diagnostics);
1955
- if (!RESOURCE_MODES.includes(mode)) {
1956
- report(diagnostics, "schema/invalid-value", "Field \"mode\" must be \"asset\", \"package\" or \"project\".", [...path, "mode"]);
1957
- return;
1958
- }
1959
- return readResourceReference(value, mode, path, diagnostics);
1960
- }
1961
- function readProjectReference(value, path, diagnostics) {
1962
- forbidUnknownFields(value, [
1963
- "mode",
1964
- "projectId",
1965
- "name",
1966
- "addressSpace",
1967
- "loadAddress"
1968
- ], path, diagnostics);
1969
- const projectId = readStringField(value, "projectId", path, diagnostics, true, { nonEmpty: true });
1970
- const overrides = readAddressOverrides(value, path, diagnostics);
1971
- if (projectId === void 0 || overrides === void 0) return;
1972
- const name = readStringField(value, "name", path, diagnostics, false, { nonEmpty: true });
1973
- return {
1974
- mode: "project",
1975
- projectId,
1976
- ...name === void 0 ? {} : { name },
1977
- ...overrides
1978
- };
1979
- }
1980
- function readResourceReference(value, mode, path, diagnostics) {
1981
- const hasOverrides = hasOwn(value, "addressSpace") || hasOwn(value, "loadAddress");
1982
- const fields = mode === "asset" ? [
1983
- "assetId",
1984
- "name",
1985
- "mode"
1986
- ] : ["src", "mode"];
1987
- forbidUnknownFields(value, hasOverrides ? [
1988
- ...fields,
1989
- "addressSpace",
1990
- "loadAddress"
1991
- ] : fields, path, diagnostics);
1992
- if (mode === "asset") {
1993
- const assetId = readStringField(value, "assetId", path, diagnostics, true, { nonEmpty: true });
1994
- const name = readStringField(value, "name", path, diagnostics, true, { nonEmpty: true });
1995
- const overrides = readAddressOverrides(value, path, diagnostics);
1996
- if (assetId === void 0 || name === void 0 || overrides === void 0) return void 0;
1997
- return {
1998
- mode,
1999
- assetId,
2000
- name,
2001
- ...overrides
2002
- };
2003
- }
2004
- const src = readStringField(value, "src", path, diagnostics, true, { nonEmpty: true });
2005
- if (src === void 0) return;
2006
- const srcProblem = resourceSrcProblem(mode, src);
2007
- if (srcProblem !== void 0) {
2008
- report(diagnostics, "schema/invalid-value", `Field "src" ${srcProblem}.`, [...path, "src"]);
2009
- return;
2010
- }
2011
- if (!hasOverrides) return {
2012
- src,
2013
- mode
2014
- };
2015
- const overrides = readAddressOverrides(value, path, diagnostics);
2016
- if (overrides === void 0) return;
2017
- return {
2018
- src,
2019
- mode: "package",
2020
- ...overrides
2021
- };
2022
- }
2023
- /** Reads optional `addressSpace` / `loadAddress` overrides of a firmware reference. */
2024
- function readAddressOverrides(value, path, diagnostics) {
2025
- const addressSpace = readStringField(value, "addressSpace", path, diagnostics, false, { nonEmpty: true });
2026
- const loadAddress = readIntegerField(value, "loadAddress", path, diagnostics, false);
2027
- if (loadAddress !== void 0 && loadAddress < 0) {
2028
- report(diagnostics, "schema/invalid-value", "Field \"loadAddress\" must be a non-negative safe integer.", [...path, "loadAddress"]);
2029
- return;
2030
- }
2031
- if (hasOwn(value, "addressSpace") && addressSpace === void 0) return;
2032
- if (hasOwn(value, "loadAddress") && loadAddress === void 0) return;
2033
- return {
2034
- ...addressSpace === void 0 ? {} : { addressSpace },
2035
- ...loadAddress === void 0 ? {} : { loadAddress }
2036
- };
2037
- }
2038
- /** Payload problem of a resource `src` for its mode, or `undefined` when it is well formed. */
2039
- function resourceSrcProblem(mode, src) {
2040
- switch (mode) {
2041
- case "package": return packagePathProblem(src);
2042
- case "asset": return src.length === 0 ? "must not be empty" : void 0;
2043
- }
2044
- }
2045
- //#endregion
2046
1431
  //#region src/fused/types/document.ts
2047
1432
  /** Version of the fused schematic document contract (RFC 0024). */
2048
1433
  var FUSED_DOCUMENT_VERSION = 2;
@@ -2154,46 +1539,6 @@ function readCollection(value, key, path, diagnostics, readItem) {
2154
1539
  failed
2155
1540
  };
2156
1541
  }
2157
- function readDependencies(value, path, diagnostics) {
2158
- if (value === void 0) return;
2159
- const dependencies = Object.create(null);
2160
- let failed = false;
2161
- for (const [deviceId, raw] of Object.entries(value)) {
2162
- const dependencyPath = [...path, deviceId];
2163
- const idProblem = deviceIdProblem(deviceId);
2164
- if (idProblem !== void 0) {
2165
- report(diagnostics, "schema/invalid-value", `Dependency key ${JSON.stringify(deviceId)} ${idProblem}.`, dependencyPath);
2166
- failed = true;
2167
- continue;
2168
- }
2169
- if (!isRecord(raw)) {
2170
- report(diagnostics, "schema/invalid-type", "Dependency must be an object.", dependencyPath);
2171
- failed = true;
2172
- continue;
2173
- }
2174
- forbidUnknownFields(raw, ["version", "integrity"], dependencyPath, diagnostics);
2175
- const version = readStringField(raw, "version", dependencyPath, diagnostics, true, { nonEmpty: true });
2176
- if (version !== void 0 && !isSemVer(version)) {
2177
- report(diagnostics, "schema/invalid-value", "Dependency \"version\" must be a full SemVer version.", [...dependencyPath, "version"]);
2178
- failed = true;
2179
- }
2180
- const integrity = readStringField(raw, "integrity", dependencyPath, diagnostics, true, { nonEmpty: true });
2181
- const integrityIssue = integrity === void 0 ? void 0 : integrityProblem(integrity);
2182
- if (integrityIssue !== void 0) {
2183
- report(diagnostics, "schema/invalid-value", `Dependency "integrity" ${integrityIssue}.`, [...dependencyPath, "integrity"]);
2184
- failed = true;
2185
- }
2186
- if (version === void 0 || integrity === void 0 || integrityIssue !== void 0) {
2187
- failed = true;
2188
- continue;
2189
- }
2190
- dependencies[deviceId] = {
2191
- version,
2192
- integrity
2193
- };
2194
- }
2195
- return failed ? void 0 : dependencies;
2196
- }
2197
1542
  function readInstance(raw, path, diagnostics) {
2198
1543
  if (!isRecord(raw)) {
2199
1544
  report(diagnostics, "schema/invalid-type", "Instance must be an object.", path);
@@ -2273,29 +1618,6 @@ function readPlacement(raw, path, diagnostics) {
2273
1618
  ...height === void 0 ? {} : { height }
2274
1619
  };
2275
1620
  }
2276
- function readProperties(raw, path, diagnostics) {
2277
- if (!isRecord(raw)) {
2278
- report(diagnostics, "schema/invalid-type", "Field \"properties\" must be an object.", path);
2279
- return;
2280
- }
2281
- const properties = Object.create(null);
2282
- let failed = false;
2283
- for (const [key, value] of Object.entries(raw)) {
2284
- const entryPath = [...path, key];
2285
- if (!isMemberKey(key)) {
2286
- report(diagnostics, "schema/invalid-value", `Property key ${JSON.stringify(key)} must match [A-Za-z][A-Za-z0-9]*.`, entryPath);
2287
- failed = true;
2288
- continue;
2289
- }
2290
- const property = readPropertyValue(value, entryPath, diagnostics);
2291
- if (property === void 0) {
2292
- failed = true;
2293
- continue;
2294
- }
2295
- properties[key] = property;
2296
- }
2297
- return failed ? void 0 : properties;
2298
- }
2299
1621
  function readInstanceDisplay(raw, path, diagnostics) {
2300
1622
  if (!isRecord(raw)) {
2301
1623
  report(diagnostics, "schema/invalid-type", "Field \"display\" must be an object.", path);
@@ -2892,6 +2214,6 @@ function reportVoltageConflicts(keys, voltages, diagnostics) {
2892
2214
  if (conflict !== void 0) report(diagnostics, "net/reference-conflict", `Net has conflicting ideal voltages ${String(first.voltage)} and ${String(conflict.voltage)}.`, conflict.path);
2893
2215
  }
2894
2216
  //#endregion
2895
- export { FUSED_DOCUMENT_VERSION, FusedDocumentError, STRICT_JSON_MAX_DEPTH, decodeStrictJson, deriveFusedTopology, isCodiconName, isDeviceId, isEventKey, isIntegrity, isMemberKey, isNameSegment, isPinId, isSemVer, packagePathProblem, parseFusedDocument, parseGeometry2D, parseStrictJson, parseUnifiedManifest, projectPathProblem, validateModelValue };
2217
+ export { FUSED_DOCUMENT_VERSION, FusedDocumentError, STRICT_JSON_MAX_DEPTH, decodeStrictJson, deriveFusedTopology, deviceDataPathProblem, isCodiconName, isDeviceId, isEventKey, isIntegrity, isMemberKey, isNameSegment, isPinId, isSemVer, packagePathProblem, parseFusedDocument, parseGeometry2D, parseStrictJson, parseUnifiedManifest, projectPathProblem, validateModelValue };
2896
2218
 
2897
2219
  //# sourceMappingURL=index.js.map