@mermanjs/node-wasm 0.10.0-alpha.1 → 0.10.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.
- package/CHANGELOG.md +54 -2
- package/README.md +28 -15
- package/THIRD_PARTY_LICENSES/d3-path/LICENSE +13 -0
- package/THIRD_PARTY_LICENSES/eclipse-elk/LICENSE.md +1 -2
- package/THIRD_PARTY_LICENSES/elkjs/LICENSE.md +1 -2
- package/THIRD_PARTY_LICENSES/rust-cargo-dependencies.json +91 -162
- package/THIRD_PARTY_NOTICES.md +57 -39
- package/artifact/merman_node.cjs +53 -44
- package/artifact/merman_node_bg.wasm +0 -0
- package/dist/engine.mjs +50 -137
- package/dist/errors.mjs +52 -20
- package/dist/generated/binding-contract.mjs +8 -1
- package/dist/index.d.ts +127 -0
- package/package.json +1 -1
package/dist/engine.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
parseRuntimeCatalogJsonText,
|
|
13
13
|
parseTransportJsonText,
|
|
14
14
|
sameJsonValue,
|
|
15
|
+
snapshotTransportJsonValue,
|
|
15
16
|
} from "./errors.mjs";
|
|
16
17
|
import {
|
|
17
18
|
BINDING_OPTION_GROUP_SPECS,
|
|
@@ -87,6 +88,16 @@ const COMPILED_PREREQUISITES_BY_OPERATION_ID = new Map(
|
|
|
87
88
|
const KNOWN_OUTPUT_CONTRACT_BY_ID = new Map(
|
|
88
89
|
NODE_WIRE_CONTRACT.artifact.output_contracts.map((contract) => [contract.id, contract]),
|
|
89
90
|
);
|
|
91
|
+
const THEME_AUTHORING_INPUT_LIMITS = Object.freeze({
|
|
92
|
+
...NODE_TRANSPORT_LIMITS.metadata,
|
|
93
|
+
max_utf8_bytes: NODE_TRANSPORT_FIELD_LIMITS.source_utf8_bytes,
|
|
94
|
+
max_string_utf8_bytes: NODE_TRANSPORT_FIELD_LIMITS.source_utf8_bytes,
|
|
95
|
+
});
|
|
96
|
+
const THEME_AUTHORING_RESULT_LIMITS = Object.freeze({
|
|
97
|
+
...NODE_TRANSPORT_LIMITS.metadata,
|
|
98
|
+
max_utf8_bytes: NODE_TRANSPORT_FIELD_LIMITS.data_utf8_bytes,
|
|
99
|
+
max_string_utf8_bytes: NODE_TRANSPORT_FIELD_LIMITS.data_utf8_bytes,
|
|
100
|
+
});
|
|
90
101
|
const MAX_OPERATION_TIMEOUT_MS = 0xffff_ffff;
|
|
91
102
|
const MERMAN_ENGINE_CONSTRUCTION_TOKEN = Symbol("MermanEngine construction");
|
|
92
103
|
|
|
@@ -149,11 +160,16 @@ function encodeIconPacks(packs) {
|
|
|
149
160
|
|
|
150
161
|
export function normalizeBindingOptions(value = {}) {
|
|
151
162
|
if (!isPlainObject(value)) throw new TypeError("bindingOptions must be a plain object.");
|
|
152
|
-
const normalized =
|
|
163
|
+
const normalized = snapshotTransportJsonValue(
|
|
164
|
+
value,
|
|
165
|
+
"bindingOptions",
|
|
166
|
+
NODE_TRANSPORT_LIMITS.binding_options,
|
|
167
|
+
);
|
|
153
168
|
normalized.version ??= BINDING_OPTIONS_SCHEMA_VERSION;
|
|
154
169
|
if (normalized.version !== BINDING_OPTIONS_SCHEMA_VERSION) {
|
|
170
|
+
const version = typeof normalized.version === "object" ? "non-scalar" : normalized.version;
|
|
155
171
|
throw new RangeError(
|
|
156
|
-
`Unsupported binding options schema version \`${
|
|
172
|
+
`Unsupported binding options schema version \`${version}\`; expected ${BINDING_OPTIONS_SCHEMA_VERSION}.`,
|
|
157
173
|
);
|
|
158
174
|
}
|
|
159
175
|
normalized.runtime_policy ??= "deterministic";
|
|
@@ -162,13 +178,16 @@ export function normalizeBindingOptions(value = {}) {
|
|
|
162
178
|
"bindingOptions.runtime_policy must be `deterministic` for @mermanjs/node.",
|
|
163
179
|
);
|
|
164
180
|
}
|
|
165
|
-
normalized.resources ??=
|
|
181
|
+
normalized.resources ??= Object.create(null);
|
|
166
182
|
if (!isPlainObject(normalized.resources)) {
|
|
167
183
|
throw new TypeError("bindingOptions.resources must be a plain object.");
|
|
168
184
|
}
|
|
169
185
|
normalized.resources.profile ??= "interactive";
|
|
170
186
|
if (!RESOURCE_PROFILES.has(normalized.resources.profile)) {
|
|
171
|
-
|
|
187
|
+
const profile = typeof normalized.resources.profile === "object"
|
|
188
|
+
? "non-scalar"
|
|
189
|
+
: normalized.resources.profile;
|
|
190
|
+
throw new RangeError(`Unknown resource profile \`${profile}\`.`);
|
|
172
191
|
}
|
|
173
192
|
if (normalized.environment !== undefined) {
|
|
174
193
|
if (!isPlainObject(normalized.environment)) {
|
|
@@ -250,6 +269,33 @@ export class MermanEngine {
|
|
|
250
269
|
);
|
|
251
270
|
}
|
|
252
271
|
|
|
272
|
+
materializeTheme(input, options = {}) {
|
|
273
|
+
return this.#themeAuthoring("materialize-theme-json", input, options);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
describeThemeSupport(query, options = {}) {
|
|
277
|
+
return this.#themeAuthoring("describe-theme-support-json", query, options);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
exportThemePreset(presetId, options = {}) {
|
|
281
|
+
if (typeof presetId !== "string") {
|
|
282
|
+
return Promise.reject(new TypeError("theme preset ID must be a string."));
|
|
283
|
+
}
|
|
284
|
+
return this.#themeAuthoring("export-theme-preset-json", presetId, options);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async #themeAuthoring(operationId, input, options) {
|
|
288
|
+
const source = typeof input === "string"
|
|
289
|
+
? input
|
|
290
|
+
: encodeTransportJson(input, "theme authoring input", THEME_AUTHORING_INPUT_LIMITS);
|
|
291
|
+
const json = await this.#execute(
|
|
292
|
+
{ operationId, source, optionsJson: options.optionsJson },
|
|
293
|
+
{ signal: options.signal, timeoutMs: options.timeoutMs },
|
|
294
|
+
false,
|
|
295
|
+
);
|
|
296
|
+
return parseTransportJsonText(json, "theme authoring result", THEME_AUTHORING_RESULT_LIMITS);
|
|
297
|
+
}
|
|
298
|
+
|
|
253
299
|
metadataJson(id) {
|
|
254
300
|
this.#executor.assertOpen();
|
|
255
301
|
if (typeof id !== "string" || id.length === 0) {
|
|
@@ -1242,139 +1288,6 @@ function sortedUniqueFieldIdentifiers(value, field) {
|
|
|
1242
1288
|
return value;
|
|
1243
1289
|
}
|
|
1244
1290
|
|
|
1245
|
-
function cloneBoundedJsonValue(root, label) {
|
|
1246
|
-
const limits = NODE_TRANSPORT_LIMITS.binding_options;
|
|
1247
|
-
const active = new WeakSet();
|
|
1248
|
-
const clone = jsonContainerClone(root, label);
|
|
1249
|
-
const stack = [{ depth: 1, source: root, target: clone, exiting: false }];
|
|
1250
|
-
let members = 0;
|
|
1251
|
-
let tokens = 1;
|
|
1252
|
-
|
|
1253
|
-
while (stack.length > 0) {
|
|
1254
|
-
const frame = stack.pop();
|
|
1255
|
-
if (frame.exiting) {
|
|
1256
|
-
active.delete(frame.source);
|
|
1257
|
-
continue;
|
|
1258
|
-
}
|
|
1259
|
-
if (active.has(frame.source)) {
|
|
1260
|
-
throw new TypeError(`${label} must not contain cyclic references.`);
|
|
1261
|
-
}
|
|
1262
|
-
if (frame.depth > limits.max_depth) {
|
|
1263
|
-
throw new RangeError(`${label} exceeds the structural depth limit ${limits.max_depth}.`);
|
|
1264
|
-
}
|
|
1265
|
-
active.add(frame.source);
|
|
1266
|
-
stack.push({ ...frame, exiting: true });
|
|
1267
|
-
|
|
1268
|
-
const entries = jsonContainerEntries(
|
|
1269
|
-
frame.source,
|
|
1270
|
-
label,
|
|
1271
|
-
limits.max_members - members,
|
|
1272
|
-
limits.max_members,
|
|
1273
|
-
);
|
|
1274
|
-
members += entries.length;
|
|
1275
|
-
if (members > limits.max_members) {
|
|
1276
|
-
throw new RangeError(`${label} exceeds the member-work limit ${limits.max_members}.`);
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
1280
|
-
const [key, child] = entries[index];
|
|
1281
|
-
assertUtf8Field(key, `${label} object key`, limits.max_string_utf8_bytes);
|
|
1282
|
-
tokens += 1;
|
|
1283
|
-
if (tokens > limits.max_tokens) {
|
|
1284
|
-
throw new RangeError(`${label} exceeds the token-work limit ${limits.max_tokens}.`);
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
if (child === null || typeof child === "boolean") {
|
|
1288
|
-
defineJsonValue(frame.target, key, child);
|
|
1289
|
-
} else if (typeof child === "string") {
|
|
1290
|
-
assertUtf8Field(child, `${label}.${key}`, limits.max_string_utf8_bytes);
|
|
1291
|
-
defineJsonValue(frame.target, key, child);
|
|
1292
|
-
} else if (typeof child === "number") {
|
|
1293
|
-
if (!Number.isFinite(child)) {
|
|
1294
|
-
throw new TypeError(`${label}.${key} must be a finite JSON number.`);
|
|
1295
|
-
}
|
|
1296
|
-
defineJsonValue(frame.target, key, child);
|
|
1297
|
-
} else if (typeof child === "object") {
|
|
1298
|
-
const childClone = jsonContainerClone(child, `${label}.${key}`);
|
|
1299
|
-
defineJsonValue(frame.target, key, childClone);
|
|
1300
|
-
stack.push({
|
|
1301
|
-
depth: frame.depth + 1,
|
|
1302
|
-
source: child,
|
|
1303
|
-
target: childClone,
|
|
1304
|
-
exiting: false,
|
|
1305
|
-
});
|
|
1306
|
-
} else {
|
|
1307
|
-
throw new TypeError(`${label}.${key} is not a JSON wire value.`);
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
return clone;
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
|
-
function jsonContainerClone(value, label) {
|
|
1315
|
-
if (Array.isArray(value)) return [];
|
|
1316
|
-
if (!isPlainObject(value)) {
|
|
1317
|
-
throw new TypeError(`${label} must contain only arrays and plain objects.`);
|
|
1318
|
-
}
|
|
1319
|
-
return Object.getPrototypeOf(value) === null ? Object.create(null) : {};
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
function jsonContainerEntries(value, label, remainingMembers, maxMembers) {
|
|
1323
|
-
if (Array.isArray(value)) {
|
|
1324
|
-
if (value.length > remainingMembers) {
|
|
1325
|
-
throw new RangeError(`${label} exceeds the member-work limit ${maxMembers}.`);
|
|
1326
|
-
}
|
|
1327
|
-
const keys = Reflect.ownKeys(value);
|
|
1328
|
-
if (keys.some((key) => typeof key === "symbol")) {
|
|
1329
|
-
throw new TypeError(`${label} must not contain symbol keys.`);
|
|
1330
|
-
}
|
|
1331
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
1332
|
-
if (!Object.hasOwn(value, index)) {
|
|
1333
|
-
throw new TypeError(`${label} arrays must not contain holes.`);
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
if (keys.length !== value.length + 1) {
|
|
1337
|
-
throw new TypeError(`${label} arrays must not contain custom properties.`);
|
|
1338
|
-
}
|
|
1339
|
-
const entries = new Array(value.length);
|
|
1340
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
1341
|
-
const key = String(index);
|
|
1342
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1343
|
-
if (!descriptor?.enumerable || !("value" in descriptor)) {
|
|
1344
|
-
throw new TypeError(`${label}.${key} must be an enumerable data property.`);
|
|
1345
|
-
}
|
|
1346
|
-
entries[index] = [key, descriptor.value];
|
|
1347
|
-
}
|
|
1348
|
-
return entries;
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
const entries = [];
|
|
1352
|
-
for (const key of Reflect.ownKeys(value)) {
|
|
1353
|
-
if (typeof key === "symbol") {
|
|
1354
|
-
throw new TypeError(`${label} must not contain symbol keys.`);
|
|
1355
|
-
}
|
|
1356
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1357
|
-
if (!descriptor?.enumerable || !("value" in descriptor)) {
|
|
1358
|
-
throw new TypeError(`${label}.${key} must be an enumerable data property.`);
|
|
1359
|
-
}
|
|
1360
|
-
entries.push([key, descriptor.value]);
|
|
1361
|
-
}
|
|
1362
|
-
return entries;
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
function defineJsonValue(target, key, value) {
|
|
1366
|
-
if (Array.isArray(target)) {
|
|
1367
|
-
target[Number(key)] = value;
|
|
1368
|
-
return;
|
|
1369
|
-
}
|
|
1370
|
-
Object.defineProperty(target, key, {
|
|
1371
|
-
configurable: true,
|
|
1372
|
-
enumerable: true,
|
|
1373
|
-
value,
|
|
1374
|
-
writable: true,
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
1291
|
function isPlainObject(value) {
|
|
1379
1292
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1380
1293
|
const prototype = Object.getPrototypeOf(value);
|
package/dist/errors.mjs
CHANGED
|
@@ -207,7 +207,7 @@ export function encodeTransportJson(value, label, limits) {
|
|
|
207
207
|
}
|
|
208
208
|
let boundedValue;
|
|
209
209
|
try {
|
|
210
|
-
boundedValue =
|
|
210
|
+
boundedValue = snapshotTransportJsonValue(value, label, limits);
|
|
211
211
|
} catch (cause) {
|
|
212
212
|
if (cause instanceof MermanInvalidTransportError) throw cause;
|
|
213
213
|
throw new MermanInvalidTransportError(
|
|
@@ -224,18 +224,21 @@ export function encodeTransportJson(value, label, limits) {
|
|
|
224
224
|
cause,
|
|
225
225
|
);
|
|
226
226
|
}
|
|
227
|
-
// JSON.stringify guarantees syntax for the controlled clone; retain all wire-limit checks.
|
|
228
227
|
assertTransportJsonTextLimits(text, label, limits);
|
|
229
228
|
return text;
|
|
230
229
|
}
|
|
231
230
|
|
|
232
|
-
function
|
|
233
|
-
|
|
231
|
+
export function snapshotTransportJsonValue(value, label, limits) {
|
|
232
|
+
if (!limits || typeof limits !== "object") {
|
|
233
|
+
throw new TypeError(`Missing Node wire limits for ${label}.`);
|
|
234
|
+
}
|
|
235
|
+
const budget = { label, max: limits.max_utf8_bytes, used: 0, members: 0, tokens: 0 };
|
|
234
236
|
const active = new WeakSet();
|
|
235
237
|
return cloneJsonWireValue(value, label, limits, budget, active, 1);
|
|
236
238
|
}
|
|
237
239
|
|
|
238
240
|
function cloneJsonWireValue(value, label, limits, budget, active, depth) {
|
|
241
|
+
addJsonWireToken(budget, limits);
|
|
239
242
|
if (value === null) {
|
|
240
243
|
addJsonWireBytes(budget, 4);
|
|
241
244
|
return null;
|
|
@@ -245,7 +248,7 @@ function cloneJsonWireValue(value, label, limits, budget, active, depth) {
|
|
|
245
248
|
return value;
|
|
246
249
|
}
|
|
247
250
|
if (typeof value === "string") {
|
|
248
|
-
addJsonStringWireBytes(value, label, budget);
|
|
251
|
+
addJsonStringWireBytes(value, label, limits, budget);
|
|
249
252
|
return value;
|
|
250
253
|
}
|
|
251
254
|
if (typeof value === "number") {
|
|
@@ -283,16 +286,19 @@ function cloneJsonWireValue(value, label, limits, budget, active, depth) {
|
|
|
283
286
|
}
|
|
284
287
|
|
|
285
288
|
function cloneJsonWireArray(value, label, limits, budget, active, depth) {
|
|
289
|
+
addJsonWireMembers(budget, limits, value.length);
|
|
286
290
|
const keys = Reflect.ownKeys(value);
|
|
287
291
|
if (keys.some((key) => typeof key === "symbol")) {
|
|
288
292
|
throw new TypeError(`${label} must not contain symbol keys.`);
|
|
289
293
|
}
|
|
294
|
+
if (keys.length < value.length + 1) {
|
|
295
|
+
throw new TypeError(`${label} arrays must not contain holes.`);
|
|
296
|
+
}
|
|
290
297
|
if (keys.length !== value.length + 1) {
|
|
291
298
|
throw new TypeError(`${label} arrays must not contain custom properties.`);
|
|
292
299
|
}
|
|
293
300
|
|
|
294
|
-
const clone = [];
|
|
295
|
-
Object.defineProperty(clone, "toJSON", { value: undefined });
|
|
301
|
+
const clone = Object.setPrototypeOf([], null);
|
|
296
302
|
addJsonWireBytes(budget, 1);
|
|
297
303
|
for (let index = 0; index < value.length; index += 1) {
|
|
298
304
|
if (!Object.hasOwn(value, index)) {
|
|
@@ -317,10 +323,12 @@ function cloneJsonWireArray(value, label, limits, budget, active, depth) {
|
|
|
317
323
|
}
|
|
318
324
|
|
|
319
325
|
function cloneJsonWireObject(value, label, limits, budget, active, depth) {
|
|
326
|
+
const keys = Reflect.ownKeys(value);
|
|
327
|
+
addJsonWireMembers(budget, limits, keys.length);
|
|
320
328
|
const clone = Object.create(null);
|
|
321
329
|
addJsonWireBytes(budget, 1);
|
|
322
330
|
let member = 0;
|
|
323
|
-
for (const key of
|
|
331
|
+
for (const key of keys) {
|
|
324
332
|
if (typeof key === "symbol") {
|
|
325
333
|
throw new TypeError(`${label} must not contain symbol keys.`);
|
|
326
334
|
}
|
|
@@ -329,7 +337,8 @@ function cloneJsonWireObject(value, label, limits, budget, active, depth) {
|
|
|
329
337
|
throw new TypeError(`${label}.${key} must be an enumerable data property.`);
|
|
330
338
|
}
|
|
331
339
|
if (member > 0) addJsonWireBytes(budget, 1);
|
|
332
|
-
|
|
340
|
+
addJsonWireToken(budget, limits);
|
|
341
|
+
addJsonStringWireBytes(key, `${label} object key`, limits, budget);
|
|
333
342
|
addJsonWireBytes(budget, 1);
|
|
334
343
|
const child = cloneJsonWireValue(
|
|
335
344
|
descriptor.value,
|
|
@@ -351,12 +360,33 @@ function cloneJsonWireObject(value, label, limits, budget, active, depth) {
|
|
|
351
360
|
return clone;
|
|
352
361
|
}
|
|
353
362
|
|
|
354
|
-
function
|
|
363
|
+
function addJsonWireMembers(budget, limits, count) {
|
|
364
|
+
if (count > limits.max_members - budget.members) {
|
|
365
|
+
throw new MermanInvalidTransportError(
|
|
366
|
+
`Merman transport ${budget.label} exceeds the member-work limit ${limits.max_members}.`,
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
budget.members += count;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function addJsonWireToken(budget, limits) {
|
|
373
|
+
budget.tokens += 1;
|
|
374
|
+
if (budget.tokens > limits.max_tokens) {
|
|
375
|
+
throw new MermanInvalidTransportError(
|
|
376
|
+
`Merman transport ${budget.label} exceeds the token-work limit ${limits.max_tokens}.`,
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function addJsonStringWireBytes(value, label, limits, budget) {
|
|
382
|
+
let utf8Bytes = 0;
|
|
355
383
|
addJsonWireBytes(budget, 1);
|
|
356
384
|
for (let index = 0; index < value.length; index += 1) {
|
|
357
385
|
const codeUnit = value.charCodeAt(index);
|
|
386
|
+
let characterBytes = utf8LengthOfCodeUnit(codeUnit);
|
|
387
|
+
let wireBytes = characterBytes;
|
|
358
388
|
if (codeUnit === 0x22 || codeUnit === 0x5c) {
|
|
359
|
-
|
|
389
|
+
wireBytes = 2;
|
|
360
390
|
} else if (
|
|
361
391
|
codeUnit === 0x08 ||
|
|
362
392
|
codeUnit === 0x09 ||
|
|
@@ -364,13 +394,9 @@ function addJsonStringWireBytes(value, label, budget) {
|
|
|
364
394
|
codeUnit === 0x0c ||
|
|
365
395
|
codeUnit === 0x0d
|
|
366
396
|
) {
|
|
367
|
-
|
|
397
|
+
wireBytes = 2;
|
|
368
398
|
} else if (codeUnit <= 0x1f) {
|
|
369
|
-
|
|
370
|
-
} else if (codeUnit <= 0x7f) {
|
|
371
|
-
addJsonWireBytes(budget, 1);
|
|
372
|
-
} else if (codeUnit <= 0x7ff) {
|
|
373
|
-
addJsonWireBytes(budget, 2);
|
|
399
|
+
wireBytes = 6;
|
|
374
400
|
} else if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
|
|
375
401
|
const low = value.charCodeAt(index + 1);
|
|
376
402
|
if (!(low >= 0xdc00 && low <= 0xdfff)) {
|
|
@@ -378,15 +404,21 @@ function addJsonStringWireBytes(value, label, budget) {
|
|
|
378
404
|
`Merman transport ${label} contains an isolated UTF-16 surrogate.`,
|
|
379
405
|
);
|
|
380
406
|
}
|
|
381
|
-
|
|
407
|
+
characterBytes = 4;
|
|
408
|
+
wireBytes = 4;
|
|
382
409
|
index += 1;
|
|
383
410
|
} else if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {
|
|
384
411
|
throw new MermanInvalidTransportError(
|
|
385
412
|
`Merman transport ${label} contains an isolated UTF-16 surrogate.`,
|
|
386
413
|
);
|
|
387
|
-
} else {
|
|
388
|
-
addJsonWireBytes(budget, 3);
|
|
389
414
|
}
|
|
415
|
+
utf8Bytes += characterBytes;
|
|
416
|
+
if (utf8Bytes > limits.max_string_utf8_bytes) {
|
|
417
|
+
throw new MermanInvalidTransportError(
|
|
418
|
+
`Merman transport ${label} contains a string exceeding the ${limits.max_string_utf8_bytes}-byte field limit.`,
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
addJsonWireBytes(budget, wireBytes);
|
|
390
422
|
}
|
|
391
423
|
addJsonWireBytes(budget, 1);
|
|
392
424
|
}
|
|
@@ -443,7 +443,7 @@ export const BINDING_OPERATION_METADATA_CONTRACT = {
|
|
|
443
443
|
],
|
|
444
444
|
"theme_execution_evidence_versions": [
|
|
445
445
|
{
|
|
446
|
-
"version":
|
|
446
|
+
"version": 2,
|
|
447
447
|
"fields": [
|
|
448
448
|
{
|
|
449
449
|
"name": "version",
|
|
@@ -501,6 +501,13 @@ export const BINDING_OPERATION_METADATA_CONTRACT = {
|
|
|
501
501
|
"integer_width_bits": null,
|
|
502
502
|
"open_value": true
|
|
503
503
|
},
|
|
504
|
+
{
|
|
505
|
+
"name": "materialized_theme",
|
|
506
|
+
"json_type": "string-or-null",
|
|
507
|
+
"required": true,
|
|
508
|
+
"integer_width_bits": null,
|
|
509
|
+
"open_value": false
|
|
510
|
+
},
|
|
504
511
|
{
|
|
505
512
|
"name": "diagnostics",
|
|
506
513
|
"json_type": "array",
|
package/dist/index.d.ts
CHANGED
|
@@ -16,9 +16,125 @@ export interface MermanBindingOptions {
|
|
|
16
16
|
profile?: MermanResourceProfile;
|
|
17
17
|
limits?: Record<string, number>;
|
|
18
18
|
};
|
|
19
|
+
/** A supplied selection replaces the complete constructor theme; null clears it. */
|
|
20
|
+
theme?: DiagramThemeSelection | null;
|
|
19
21
|
[key: string]: unknown;
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
export type ThemeAppearance = "light" | "dark";
|
|
25
|
+
export type ThemeJsonValue =
|
|
26
|
+
| string | number | boolean | null
|
|
27
|
+
| ThemeJsonValue[]
|
|
28
|
+
| { [key: string]: ThemeJsonValue };
|
|
29
|
+
export type ThemeJsonObject = { [key: string]: ThemeJsonValue };
|
|
30
|
+
|
|
31
|
+
/** Editable JSON sections are validated by the shared Rust theme compiler. */
|
|
32
|
+
export interface ThemeDesignV1 {
|
|
33
|
+
tokens?: Record<string, ThemeJsonValue>;
|
|
34
|
+
styles?: Record<string, ThemeJsonValue>;
|
|
35
|
+
rules?: ThemeJsonObject[];
|
|
36
|
+
palettes?: Record<string, ThemeJsonValue>;
|
|
37
|
+
canvas?: ThemeJsonObject;
|
|
38
|
+
typography?: ThemeJsonObject;
|
|
39
|
+
mermaid?: ThemeJsonObject;
|
|
40
|
+
assets?: ThemeJsonObject;
|
|
41
|
+
requirements?: ThemeJsonObject;
|
|
42
|
+
appearances?: Partial<Record<ThemeAppearance, ThemeAppearanceOverridesV1>>;
|
|
43
|
+
default_appearance?: ThemeAppearance;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type ThemeAppearanceOverridesV1 =
|
|
47
|
+
Omit<ThemeDesignV1, "appearances" | "default_appearance" | "assets" | "requirements">;
|
|
48
|
+
|
|
49
|
+
export type ThemeRecipeV1 = {
|
|
50
|
+
schema_version: 1;
|
|
51
|
+
preset?: never;
|
|
52
|
+
spec?: never;
|
|
53
|
+
recipe?: never;
|
|
54
|
+
appearance?: never;
|
|
55
|
+
} & (
|
|
56
|
+
| { kind: "design"; design: ThemeDesignV1; complete_spec?: never }
|
|
57
|
+
| { kind: "complete_spec"; complete_spec: ThemeJsonObject; design?: never }
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export type DiagramThemeSelection =
|
|
61
|
+
| ThemeRecipeV1
|
|
62
|
+
| ({ kind?: never; schema_version?: never; design?: never; complete_spec?: never } & (
|
|
63
|
+
| { preset: string; appearance?: ThemeAppearance; recipe?: never; spec?: never }
|
|
64
|
+
| { recipe: ThemeRecipeV1; appearance?: ThemeAppearance; preset?: never; spec?: never }
|
|
65
|
+
| { spec: ThemeJsonObject; preset?: never; recipe?: never; appearance?: never }
|
|
66
|
+
));
|
|
67
|
+
|
|
68
|
+
export type ThemeAuthoringRequestV1 =
|
|
69
|
+
| { schema_version: 1; action: "inspect"; recipe: ThemeRecipeV1; appearance?: never }
|
|
70
|
+
| { schema_version: 1; action: "materialize"; recipe: ThemeRecipeV1; appearance?: ThemeAppearance };
|
|
71
|
+
export type ThemeAuthoringInput = ThemeDesignV1 | ThemeAuthoringRequestV1 | string;
|
|
72
|
+
|
|
73
|
+
export interface ThemeDesignReferenceUse {
|
|
74
|
+
token: string;
|
|
75
|
+
path: string;
|
|
76
|
+
domain: ThemeJsonObject;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface ThemeRecipeReferenceUseV1 extends ThemeDesignReferenceUse {
|
|
80
|
+
token_path: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface MaterializedThemeWireV1 {
|
|
84
|
+
schema_version: 1;
|
|
85
|
+
authoring_schema_version: 1;
|
|
86
|
+
expansion_version: 1;
|
|
87
|
+
spec_schema_version: 1;
|
|
88
|
+
spec: ThemeJsonObject;
|
|
89
|
+
references?: ThemeDesignReferenceUse[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface ThemeRecipeInspectionV1 {
|
|
93
|
+
schema_version: 1;
|
|
94
|
+
recipe_schema_version: 1;
|
|
95
|
+
supported_appearances: ThemeAppearance[];
|
|
96
|
+
default_appearance: ThemeAppearance | null;
|
|
97
|
+
appearances: {
|
|
98
|
+
appearance: ThemeAppearance | null;
|
|
99
|
+
references: ThemeRecipeReferenceUseV1[];
|
|
100
|
+
}[];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface MaterializedThemeRecipeV1 {
|
|
104
|
+
schema_version: 1;
|
|
105
|
+
recipe_schema_version: 1;
|
|
106
|
+
supported_appearances: ThemeAppearance[];
|
|
107
|
+
default_appearance: ThemeAppearance | null;
|
|
108
|
+
effective_appearance: ThemeAppearance | null;
|
|
109
|
+
spec: ThemeJsonObject;
|
|
110
|
+
references: ThemeRecipeReferenceUseV1[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type ThemeAuthoringResult =
|
|
114
|
+
| MaterializedThemeWireV1 | ThemeRecipeInspectionV1 | MaterializedThemeRecipeV1;
|
|
115
|
+
export type ThemeAuthoringResultFor<Input extends ThemeAuthoringInput> =
|
|
116
|
+
Input extends { action: "inspect" } ? ThemeRecipeInspectionV1
|
|
117
|
+
: Input extends { action: "materialize" } ? MaterializedThemeRecipeV1
|
|
118
|
+
: Input extends string ? ThemeAuthoringResult : MaterializedThemeWireV1;
|
|
119
|
+
|
|
120
|
+
export interface ThemeSupportQueryV1 {
|
|
121
|
+
schema_version: 1;
|
|
122
|
+
family: string;
|
|
123
|
+
output: string;
|
|
124
|
+
subject:
|
|
125
|
+
| { kind: "rule"; target: string; facet: string }
|
|
126
|
+
| { kind: "ordinal-palette"; target: string }
|
|
127
|
+
| { kind: "base-typography"; property: string };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ThemeCapabilityDescriptorV1 {
|
|
131
|
+
schema_version: 1;
|
|
132
|
+
claim_revision: number;
|
|
133
|
+
query: ThemeSupportQueryV1;
|
|
134
|
+
state: "unconditional" | "conditional" | "not-applicable" | "unsupported" | "unverified" | (string & {});
|
|
135
|
+
reason_ids: string[];
|
|
136
|
+
}
|
|
137
|
+
|
|
22
138
|
/** One host-loaded Iconify pack, admitted once into an immutable engine-local registry. */
|
|
23
139
|
export interface MermanIconPack {
|
|
24
140
|
json: string;
|
|
@@ -201,6 +317,17 @@ export declare class MermanEngine {
|
|
|
201
317
|
source: string,
|
|
202
318
|
options?: Omit<RenderSvgOptions, "signal">,
|
|
203
319
|
): string;
|
|
320
|
+
/** Raw strings preserve duplicate-field admission and source paths in Rust. */
|
|
321
|
+
materializeTheme<Input extends ThemeAuthoringInput>(
|
|
322
|
+
input: Input,
|
|
323
|
+
options?: RenderSvgOptions,
|
|
324
|
+
): Promise<ThemeAuthoringResultFor<Input>>;
|
|
325
|
+
describeThemeSupport(
|
|
326
|
+
query: ThemeSupportQueryV1 | string,
|
|
327
|
+
options?: RenderSvgOptions,
|
|
328
|
+
): Promise<ThemeCapabilityDescriptorV1>;
|
|
329
|
+
/** Exports the complete editable design, including every declared appearance. */
|
|
330
|
+
exportThemePreset(presetId: string, options?: RenderSvgOptions): Promise<ThemeRecipeV1>;
|
|
204
331
|
metadataJson(id: string): string;
|
|
205
332
|
executeOperation(
|
|
206
333
|
request: MermanOperationRequest,
|