@mermanjs/node-wasm 0.10.0-alpha.1 → 0.10.0-alpha.2
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 +25 -2
- package/README.md +4 -5
- 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 +13 -137
- package/dist/errors.mjs +52 -20
- package/dist/generated/binding-contract.mjs +8 -1
- package/package.json +1 -1
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",
|