@mica-js/document 0.4.0 → 0.6.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-CX-ElHak.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);
@@ -709,6 +204,7 @@ var PROPERTY_TYPES = [
709
204
  "enum",
710
205
  "image",
711
206
  "binary",
207
+ "disk",
712
208
  "firmware",
713
209
  "program"
714
210
  ];
@@ -750,6 +246,11 @@ var TYPE_FIELDS = {
750
246
  "maxBytes",
751
247
  "extensions"
752
248
  ],
249
+ disk: [
250
+ ...COMMON_FIELDS,
251
+ "maxBytes",
252
+ "access"
253
+ ],
753
254
  firmware: [
754
255
  ...COMMON_FIELDS,
755
256
  "maxBytes",
@@ -851,10 +352,22 @@ function readPropertyDescriptor(value, path, diagnostics) {
851
352
  }
852
353
  case "image":
853
354
  case "binary":
355
+ case "disk":
854
356
  case "firmware": {
855
357
  const maxBytes = readCount(value, "maxBytes", path, diagnostics);
856
358
  if (maxBytes === "invalid") failed = true;
857
- else if (maxBytes !== void 0) draft.maxBytes = maxBytes;
359
+ else if (type === "disk" && maxBytes === 0) {
360
+ report(diagnostics, "package/invalid-manifest", "maxBytes must be positive.", [...path, "maxBytes"]);
361
+ failed = true;
362
+ } else if (maxBytes !== void 0) draft.maxBytes = maxBytes;
363
+ if (type === "disk" && hasOwn(value, "access")) {
364
+ const access = value["access"];
365
+ if (access === "read-only" || access === "read-write") draft.access = access;
366
+ else {
367
+ report(diagnostics, "package/invalid-manifest", "Invalid disk access mode.", [...path, "access"]);
368
+ failed = true;
369
+ }
370
+ }
858
371
  if (type === "image") {
859
372
  const maxPixels = readCount(value, "maxPixels", path, diagnostics);
860
373
  if (maxPixels === "invalid") failed = true;
@@ -1175,6 +688,7 @@ function checkDefault(value, descriptor, path, diagnostics) {
1175
688
  const allowed = (descriptor.options ?? []).map((option) => option.value);
1176
689
  return typeof value === "string" && allowed.includes(value) ? { value } : fail(`Default must be one of ${allowed.map((entry) => JSON.stringify(entry)).join(", ")}.`);
1177
690
  }
691
+ case "disk": return fail("A disk default must be null. Bind a device-data image on the instance.");
1178
692
  case "image":
1179
693
  case "binary": {
1180
694
  const reference = checkPackageReference(value, path, diagnostics);
@@ -1914,116 +1428,6 @@ function readPackageFilePath(value, key, path, diagnostics, extensions, code, re
1914
1428
  return file;
1915
1429
  }
1916
1430
  //#endregion
1917
- //#region src/fused/resource.ts
1918
- var RESOURCE_MODES = ["asset", "package"];
1919
- /** Reads one instance property value; `undefined` when it does not match the contract. */
1920
- function readPropertyValue(value, path, diagnostics) {
1921
- if (value === null || typeof value === "string" || typeof value === "boolean") return value;
1922
- if (typeof value === "number") {
1923
- if (!Number.isFinite(value)) {
1924
- report(diagnostics, "schema/invalid-value", "Numeric property values must be finite.", path);
1925
- return;
1926
- }
1927
- return value;
1928
- }
1929
- if (isRecord(value)) return readReference$1(value, path, diagnostics);
1930
- report(diagnostics, "schema/invalid-type", "Property value must be a scalar, a resource reference, a firmware reference or null.", path);
1931
- }
1932
- function readReference$1(value, path, diagnostics) {
1933
- const mode = readStringField(value, "mode", path, diagnostics, true, { nonEmpty: true });
1934
- if (mode === void 0) return;
1935
- if (mode === "project") return readProjectReference(value, path, diagnostics);
1936
- if (!RESOURCE_MODES.includes(mode)) {
1937
- report(diagnostics, "schema/invalid-value", "Field \"mode\" must be \"asset\", \"package\" or \"project\".", [...path, "mode"]);
1938
- return;
1939
- }
1940
- return readResourceReference(value, mode, path, diagnostics);
1941
- }
1942
- function readProjectReference(value, path, diagnostics) {
1943
- forbidUnknownFields(value, [
1944
- "mode",
1945
- "projectId",
1946
- "name",
1947
- "addressSpace",
1948
- "loadAddress"
1949
- ], path, diagnostics);
1950
- const projectId = readStringField(value, "projectId", path, diagnostics, true, { nonEmpty: true });
1951
- const overrides = readAddressOverrides(value, path, diagnostics);
1952
- if (projectId === void 0 || overrides === void 0) return;
1953
- const name = readStringField(value, "name", path, diagnostics, false, { nonEmpty: true });
1954
- return {
1955
- mode: "project",
1956
- projectId,
1957
- ...name === void 0 ? {} : { name },
1958
- ...overrides
1959
- };
1960
- }
1961
- function readResourceReference(value, mode, path, diagnostics) {
1962
- const hasOverrides = hasOwn(value, "addressSpace") || hasOwn(value, "loadAddress");
1963
- const fields = mode === "asset" ? [
1964
- "assetId",
1965
- "name",
1966
- "mode"
1967
- ] : ["src", "mode"];
1968
- forbidUnknownFields(value, hasOverrides ? [
1969
- ...fields,
1970
- "addressSpace",
1971
- "loadAddress"
1972
- ] : fields, path, diagnostics);
1973
- if (mode === "asset") {
1974
- const assetId = readStringField(value, "assetId", path, diagnostics, true, { nonEmpty: true });
1975
- const name = readStringField(value, "name", path, diagnostics, true, { nonEmpty: true });
1976
- const overrides = readAddressOverrides(value, path, diagnostics);
1977
- if (assetId === void 0 || name === void 0 || overrides === void 0) return void 0;
1978
- return {
1979
- mode,
1980
- assetId,
1981
- name,
1982
- ...overrides
1983
- };
1984
- }
1985
- const src = readStringField(value, "src", path, diagnostics, true, { nonEmpty: true });
1986
- if (src === void 0) return;
1987
- const srcProblem = resourceSrcProblem(mode, src);
1988
- if (srcProblem !== void 0) {
1989
- report(diagnostics, "schema/invalid-value", `Field "src" ${srcProblem}.`, [...path, "src"]);
1990
- return;
1991
- }
1992
- if (!hasOverrides) return {
1993
- src,
1994
- mode
1995
- };
1996
- const overrides = readAddressOverrides(value, path, diagnostics);
1997
- if (overrides === void 0) return;
1998
- return {
1999
- src,
2000
- mode: "package",
2001
- ...overrides
2002
- };
2003
- }
2004
- /** Reads optional `addressSpace` / `loadAddress` overrides of a firmware reference. */
2005
- function readAddressOverrides(value, path, diagnostics) {
2006
- const addressSpace = readStringField(value, "addressSpace", path, diagnostics, false, { nonEmpty: true });
2007
- const loadAddress = readIntegerField(value, "loadAddress", path, diagnostics, false);
2008
- if (loadAddress !== void 0 && loadAddress < 0) {
2009
- report(diagnostics, "schema/invalid-value", "Field \"loadAddress\" must be a non-negative safe integer.", [...path, "loadAddress"]);
2010
- return;
2011
- }
2012
- if (hasOwn(value, "addressSpace") && addressSpace === void 0) return;
2013
- if (hasOwn(value, "loadAddress") && loadAddress === void 0) return;
2014
- return {
2015
- ...addressSpace === void 0 ? {} : { addressSpace },
2016
- ...loadAddress === void 0 ? {} : { loadAddress }
2017
- };
2018
- }
2019
- /** Payload problem of a resource `src` for its mode, or `undefined` when it is well formed. */
2020
- function resourceSrcProblem(mode, src) {
2021
- switch (mode) {
2022
- case "package": return packagePathProblem(src);
2023
- case "asset": return src.length === 0 ? "must not be empty" : void 0;
2024
- }
2025
- }
2026
- //#endregion
2027
1431
  //#region src/fused/types/document.ts
2028
1432
  /** Version of the fused schematic document contract (RFC 0024). */
2029
1433
  var FUSED_DOCUMENT_VERSION = 2;
@@ -2135,46 +1539,6 @@ function readCollection(value, key, path, diagnostics, readItem) {
2135
1539
  failed
2136
1540
  };
2137
1541
  }
2138
- function readDependencies(value, path, diagnostics) {
2139
- if (value === void 0) return;
2140
- const dependencies = Object.create(null);
2141
- let failed = false;
2142
- for (const [deviceId, raw] of Object.entries(value)) {
2143
- const dependencyPath = [...path, deviceId];
2144
- const idProblem = deviceIdProblem(deviceId);
2145
- if (idProblem !== void 0) {
2146
- report(diagnostics, "schema/invalid-value", `Dependency key ${JSON.stringify(deviceId)} ${idProblem}.`, dependencyPath);
2147
- failed = true;
2148
- continue;
2149
- }
2150
- if (!isRecord(raw)) {
2151
- report(diagnostics, "schema/invalid-type", "Dependency must be an object.", dependencyPath);
2152
- failed = true;
2153
- continue;
2154
- }
2155
- forbidUnknownFields(raw, ["version", "integrity"], dependencyPath, diagnostics);
2156
- const version = readStringField(raw, "version", dependencyPath, diagnostics, true, { nonEmpty: true });
2157
- if (version !== void 0 && !isSemVer(version)) {
2158
- report(diagnostics, "schema/invalid-value", "Dependency \"version\" must be a full SemVer version.", [...dependencyPath, "version"]);
2159
- failed = true;
2160
- }
2161
- const integrity = readStringField(raw, "integrity", dependencyPath, diagnostics, true, { nonEmpty: true });
2162
- const integrityIssue = integrity === void 0 ? void 0 : integrityProblem(integrity);
2163
- if (integrityIssue !== void 0) {
2164
- report(diagnostics, "schema/invalid-value", `Dependency "integrity" ${integrityIssue}.`, [...dependencyPath, "integrity"]);
2165
- failed = true;
2166
- }
2167
- if (version === void 0 || integrity === void 0 || integrityIssue !== void 0) {
2168
- failed = true;
2169
- continue;
2170
- }
2171
- dependencies[deviceId] = {
2172
- version,
2173
- integrity
2174
- };
2175
- }
2176
- return failed ? void 0 : dependencies;
2177
- }
2178
1542
  function readInstance(raw, path, diagnostics) {
2179
1543
  if (!isRecord(raw)) {
2180
1544
  report(diagnostics, "schema/invalid-type", "Instance must be an object.", path);
@@ -2254,29 +1618,6 @@ function readPlacement(raw, path, diagnostics) {
2254
1618
  ...height === void 0 ? {} : { height }
2255
1619
  };
2256
1620
  }
2257
- function readProperties(raw, path, diagnostics) {
2258
- if (!isRecord(raw)) {
2259
- report(diagnostics, "schema/invalid-type", "Field \"properties\" must be an object.", path);
2260
- return;
2261
- }
2262
- const properties = Object.create(null);
2263
- let failed = false;
2264
- for (const [key, value] of Object.entries(raw)) {
2265
- const entryPath = [...path, key];
2266
- if (!isMemberKey(key)) {
2267
- report(diagnostics, "schema/invalid-value", `Property key ${JSON.stringify(key)} must match [A-Za-z][A-Za-z0-9]*.`, entryPath);
2268
- failed = true;
2269
- continue;
2270
- }
2271
- const property = readPropertyValue(value, entryPath, diagnostics);
2272
- if (property === void 0) {
2273
- failed = true;
2274
- continue;
2275
- }
2276
- properties[key] = property;
2277
- }
2278
- return failed ? void 0 : properties;
2279
- }
2280
1621
  function readInstanceDisplay(raw, path, diagnostics) {
2281
1622
  if (!isRecord(raw)) {
2282
1623
  report(diagnostics, "schema/invalid-type", "Field \"display\" must be an object.", path);
@@ -2873,6 +2214,6 @@ function reportVoltageConflicts(keys, voltages, diagnostics) {
2873
2214
  if (conflict !== void 0) report(diagnostics, "net/reference-conflict", `Net has conflicting ideal voltages ${String(first.voltage)} and ${String(conflict.voltage)}.`, conflict.path);
2874
2215
  }
2875
2216
  //#endregion
2876
- 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 };
2877
2218
 
2878
2219
  //# sourceMappingURL=index.js.map