@orkestrel/contract 0.0.13 → 0.0.15

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.
@@ -333,6 +333,30 @@ var COMPILE_DEPTH_LIMIT = 512;
333
333
  */
334
334
  var COMPILE_NODE_LIMIT = 16384;
335
335
  /**
336
+ * The maximum number of object keys one compiled presence mask carries, frozen.
337
+ *
338
+ * @remarks
339
+ * A compiled object plan decides which declared keys a value carries. The keys
340
+ * it asks about are fixed when the plan is built, so the plan assigns each one a
341
+ * bit position once and a call ORs one bit per own key it finds and compares the
342
+ * result against the full mask — no per-call collection, and one integer compare
343
+ * instead of one membership dispatch per declared key.
344
+ *
345
+ * The bound is the width a JavaScript bitwise operand has: `1 << position`
346
+ * evaluates on a 32-bit signed integer, so positions run `0` through `30` and a
347
+ * mask stays positive. A declaration with more keys than this is ordinary
348
+ * authoring rather than an attack, so it is answered rather than refused:
349
+ * {@link ContractCompiler} builds no position record for it and its compiled
350
+ * guard, parser, auditor, and reporter decide presence from a collected key
351
+ * vocabulary instead. Both branches answer identically; only the cost differs.
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * PRESENCE_MASK_LIMIT // 31
356
+ * ```
357
+ */
358
+ var PRESENCE_MASK_LIMIT = 31;
359
+ /**
336
360
  * The maximum number of nodes one JSON snapshot may produce, frozen.
337
361
  *
338
362
  * @remarks
@@ -2397,6 +2421,9 @@ function readArrayEntries(value) {
2397
2421
  const length = value.length;
2398
2422
  if (!INTRINSICS.safe(length) || length < 0 || length > 2 ** 32 - 1) throw new INTRINSICS.error("Array length is outside the native array domain");
2399
2423
  const collected = [];
2424
+ const keys = [];
2425
+ let ascending = true;
2426
+ let previous = -1;
2400
2427
  const members = INTRINSICS.members(value);
2401
2428
  for (let position = 0; position < members.length; position += 1) {
2402
2429
  const key = members[position];
@@ -2404,16 +2431,19 @@ function readArrayEntries(value) {
2404
2431
  const index = INTRINSICS.numeric(key);
2405
2432
  if (INTRINSICS.integer(index) && index >= 0 && index < 2 ** 32 - 1 && INTRINSICS.text(index) === key) {
2406
2433
  if (index >= length) throw new INTRINSICS.error("Array index views disagree");
2434
+ if (index <= previous) ascending = false;
2435
+ previous = index;
2407
2436
  collected[collected.length] = index;
2437
+ keys[keys.length] = key;
2408
2438
  }
2409
2439
  }
2410
- const indices = sortValues(collected);
2440
+ const indices = ascending ? collected : sortValues(collected);
2411
2441
  const entries = new INTRINSICS.list(length);
2412
2442
  for (let position = 0; position < indices.length; position += 1) {
2413
2443
  const index = indices[position];
2414
2444
  if (index === void 0) continue;
2415
- const key = INTRINSICS.text(index);
2416
- if (!INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
2445
+ const key = ascending ? keys[position] : INTRINSICS.text(index);
2446
+ if (key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
2417
2447
  entries[index] = value[index];
2418
2448
  }
2419
2449
  return INTRINSICS.freeze({
@@ -6503,28 +6533,38 @@ var ContractCompiler = class ContractCompiler {
6503
6533
  static #weakMap = WeakMap;
6504
6534
  static #visits = 0;
6505
6535
  static #scope = 0;
6536
+ static #emptyStack = [];
6537
+ static #emptyNodes = [];
6538
+ static #emptyOrder = [];
6539
+ static #emptySchemas = [];
6540
+ static #emptyGuards = [];
6541
+ static #emptyParsers = [];
6542
+ static #emptyAudits = [];
6543
+ static #emptyReports = [];
6544
+ static #emptySeeds = [];
6545
+ static {
6546
+ INTRINSICS.freeze(ContractCompiler.#emptyStack);
6547
+ INTRINSICS.freeze(ContractCompiler.#emptyNodes);
6548
+ INTRINSICS.freeze(ContractCompiler.#emptyOrder);
6549
+ INTRINSICS.freeze(ContractCompiler.#emptySchemas);
6550
+ INTRINSICS.freeze(ContractCompiler.#emptyGuards);
6551
+ INTRINSICS.freeze(ContractCompiler.#emptyParsers);
6552
+ INTRINSICS.freeze(ContractCompiler.#emptyAudits);
6553
+ INTRINSICS.freeze(ContractCompiler.#emptyReports);
6554
+ INTRINSICS.freeze(ContractCompiler.#emptySeeds);
6555
+ }
6506
6556
  #source;
6507
6557
  #state;
6508
6558
  #stack;
6509
- #emptyStack;
6510
6559
  #nodes;
6511
- #emptyNodes;
6512
6560
  #index;
6513
- #emptyIndex;
6514
6561
  #order;
6515
- #emptyOrder;
6516
6562
  #schemas;
6517
- #emptySchemas;
6518
6563
  #guards;
6519
- #emptyGuards;
6520
6564
  #parsers;
6521
- #emptyParsers;
6522
6565
  #audits;
6523
- #emptyAudits;
6524
6566
  #reports;
6525
- #emptyReports;
6526
6567
  #seeds;
6527
- #emptySeeds;
6528
6568
  #schema;
6529
6569
  #guard;
6530
6570
  #parser;
@@ -6541,25 +6581,15 @@ var ContractCompiler = class ContractCompiler {
6541
6581
  this.#source = shape;
6542
6582
  this.#state = { phase: "ready" };
6543
6583
  this.#stack = [];
6544
- this.#emptyStack = [];
6545
6584
  this.#nodes = [];
6546
- this.#emptyNodes = [];
6547
6585
  this.#index = new ContractCompiler.#weakMap();
6548
- this.#emptyIndex = new ContractCompiler.#weakMap();
6549
6586
  this.#order = [];
6550
- this.#emptyOrder = [];
6551
6587
  this.#schemas = [];
6552
- this.#emptySchemas = [];
6553
6588
  this.#guards = [];
6554
- this.#emptyGuards = [];
6555
6589
  this.#parsers = [];
6556
- this.#emptyParsers = [];
6557
6590
  this.#audits = [];
6558
- this.#emptyAudits = [];
6559
6591
  this.#reports = [];
6560
- this.#emptyReports = [];
6561
6592
  this.#seeds = [];
6562
- this.#emptySeeds = [];
6563
6593
  this.#schema = void 0;
6564
6594
  this.#guard = void 0;
6565
6595
  this.#parser = void 0;
@@ -6681,16 +6711,16 @@ var ContractCompiler = class ContractCompiler {
6681
6711
  }
6682
6712
  #release() {
6683
6713
  this.#source = void 0;
6684
- this.#stack = this.#emptyStack;
6685
- this.#nodes = this.#emptyNodes;
6686
- this.#index = this.#emptyIndex;
6687
- this.#order = this.#emptyOrder;
6688
- this.#schemas = this.#emptySchemas;
6689
- this.#guards = this.#emptyGuards;
6690
- this.#parsers = this.#emptyParsers;
6691
- this.#audits = this.#emptyAudits;
6692
- this.#reports = this.#emptyReports;
6693
- this.#seeds = this.#emptySeeds;
6714
+ this.#stack = ContractCompiler.#emptyStack;
6715
+ this.#nodes = ContractCompiler.#emptyNodes;
6716
+ this.#index = void 0;
6717
+ this.#order = ContractCompiler.#emptyOrder;
6718
+ this.#schemas = ContractCompiler.#emptySchemas;
6719
+ this.#guards = ContractCompiler.#emptyGuards;
6720
+ this.#parsers = ContractCompiler.#emptyParsers;
6721
+ this.#audits = ContractCompiler.#emptyAudits;
6722
+ this.#reports = ContractCompiler.#emptyReports;
6723
+ this.#seeds = ContractCompiler.#emptySeeds;
6694
6724
  }
6695
6725
  #prepare() {
6696
6726
  if (this.#nodes.length > 0) return;
@@ -6710,6 +6740,14 @@ var ContractCompiler = class ContractCompiler {
6710
6740
  this.#source = void 0;
6711
6741
  }
6712
6742
  #discover(root) {
6743
+ const known = this.#index;
6744
+ if (known === void 0) throw new ContractError("ContractCompiler: the prepared index is unavailable", {
6745
+ code: "structure",
6746
+ context: {
6747
+ path: [],
6748
+ shape: "contract"
6749
+ }
6750
+ });
6713
6751
  this.#stack[this.#stack.length] = {
6714
6752
  operation: "enter",
6715
6753
  shape: root
@@ -6724,10 +6762,10 @@ var ContractCompiler = class ContractCompiler {
6724
6762
  continue;
6725
6763
  }
6726
6764
  const shape = frame.shape;
6727
- if (INTRINSICS.apply(INTRINSICS.recall, this.#index, [shape]) !== void 0) continue;
6765
+ if (INTRINSICS.apply(INTRINSICS.recall, known, [shape]) !== void 0) continue;
6728
6766
  const index = this.#nodes.length;
6729
6767
  this.#nodes[index] = shape;
6730
- INTRINSICS.apply(INTRINSICS.retain, this.#index, [shape, index]);
6768
+ INTRINSICS.apply(INTRINSICS.retain, known, [shape, index]);
6731
6769
  this.#stack[this.#stack.length] = {
6732
6770
  operation: "exit",
6733
6771
  index
@@ -6783,7 +6821,15 @@ var ContractCompiler = class ContractCompiler {
6783
6821
  }
6784
6822
  }
6785
6823
  #locate(shape) {
6786
- const index = INTRINSICS.apply(INTRINSICS.recall, this.#index, [shape]);
6824
+ const known = this.#index;
6825
+ if (known === void 0) throw new ContractError("ContractCompiler: the prepared index is unavailable", {
6826
+ code: "structure",
6827
+ context: {
6828
+ path: [],
6829
+ shape: "contract"
6830
+ }
6831
+ });
6832
+ const index = INTRINSICS.apply(INTRINSICS.recall, known, [shape]);
6787
6833
  if (index === void 0) throw new ContractError("ContractCompiler: a structural child is not in the prepared index", {
6788
6834
  code: "structure",
6789
6835
  context: {
@@ -6815,7 +6861,9 @@ var ContractCompiler = class ContractCompiler {
6815
6861
  }
6816
6862
  #trackGuard(plan) {
6817
6863
  let filled = 0;
6818
- let memo = new ContractCompiler.#weakMap();
6864
+ let memo;
6865
+ let slot;
6866
+ let kept = false;
6819
6867
  return (value) => {
6820
6868
  if (!isObject(value)) return plan(value);
6821
6869
  const opened = ContractCompiler.#scope === 0;
@@ -6826,13 +6874,27 @@ var ContractCompiler = class ContractCompiler {
6826
6874
  try {
6827
6875
  const scope = ContractCompiler.#scope;
6828
6876
  if (filled !== scope) {
6829
- memo = new ContractCompiler.#weakMap();
6877
+ memo = void 0;
6878
+ slot = void 0;
6879
+ kept = false;
6830
6880
  filled = scope;
6831
6881
  }
6832
- const recalled = INTRINSICS.apply(INTRINSICS.recall, memo, [value]);
6833
- if (recalled !== void 0) return recalled;
6882
+ if (slot === value) return kept;
6883
+ if (memo !== void 0) {
6884
+ const recalled = INTRINSICS.apply(INTRINSICS.recall, memo, [value]);
6885
+ if (recalled !== void 0) return recalled;
6886
+ }
6834
6887
  const answer = plan(value);
6835
- INTRINSICS.apply(INTRINSICS.retain, memo, [value, answer]);
6888
+ if (slot === void 0) {
6889
+ slot = value;
6890
+ kept = answer;
6891
+ } else {
6892
+ if (memo === void 0) {
6893
+ memo = new ContractCompiler.#weakMap();
6894
+ INTRINSICS.apply(INTRINSICS.retain, memo, [slot, kept]);
6895
+ }
6896
+ INTRINSICS.apply(INTRINSICS.retain, memo, [value, answer]);
6897
+ }
6836
6898
  return answer;
6837
6899
  } finally {
6838
6900
  if (opened) ContractCompiler.#scope = 0;
@@ -6841,7 +6903,9 @@ var ContractCompiler = class ContractCompiler {
6841
6903
  }
6842
6904
  #trackFaults(plan) {
6843
6905
  let filled = 0;
6844
- let memo = new ContractCompiler.#weakMap();
6906
+ let memo;
6907
+ let slot;
6908
+ let kept;
6845
6909
  return (value, path) => {
6846
6910
  if (!isObject(value)) return plan(value, path);
6847
6911
  const opened = ContractCompiler.#scope === 0;
@@ -6852,13 +6916,27 @@ var ContractCompiler = class ContractCompiler {
6852
6916
  try {
6853
6917
  const scope = ContractCompiler.#scope;
6854
6918
  if (filled !== scope) {
6855
- memo = new ContractCompiler.#weakMap();
6919
+ memo = void 0;
6920
+ slot = void 0;
6921
+ kept = void 0;
6856
6922
  filled = scope;
6857
6923
  }
6858
- const recalled = INTRINSICS.apply(INTRINSICS.recall, memo, [value]);
6859
- if (recalled !== void 0) return recalled;
6924
+ if (slot === value && kept !== void 0) return kept;
6925
+ if (memo !== void 0) {
6926
+ const recalled = INTRINSICS.apply(INTRINSICS.recall, memo, [value]);
6927
+ if (recalled !== void 0) return recalled;
6928
+ }
6860
6929
  const answer = plan(value, path);
6861
- if (answer.length === 0) INTRINSICS.apply(INTRINSICS.retain, memo, [value, answer]);
6930
+ if (slot === void 0) {
6931
+ slot = value;
6932
+ kept = answer.length === 0 ? answer : void 0;
6933
+ } else if (answer.length === 0) {
6934
+ if (memo === void 0) {
6935
+ memo = new ContractCompiler.#weakMap();
6936
+ if (kept !== void 0) INTRINSICS.apply(INTRINSICS.retain, memo, [slot, kept]);
6937
+ }
6938
+ INTRINSICS.apply(INTRINSICS.retain, memo, [value, answer]);
6939
+ }
6862
6940
  return answer;
6863
6941
  } finally {
6864
6942
  if (opened) ContractCompiler.#scope = 0;
@@ -7053,16 +7131,37 @@ var ContractCompiler = class ContractCompiler {
7053
7131
  for (let optionalIndex = 0; optionalIndex < optionalKeys.length; optionalIndex += 1) if (optionalKeys[optionalIndex] === key) optional = true;
7054
7132
  if (!optional) required[required.length] = key;
7055
7133
  }
7134
+ const maskable = required.length <= 31;
7135
+ const positions = INTRINSICS.create(null);
7136
+ let full = 0;
7137
+ if (maskable) for (let keyIndex = 0; keyIndex < required.length; keyIndex += 1) {
7138
+ const key = required[keyIndex];
7139
+ if (key === void 0) continue;
7140
+ positions[key] = keyIndex;
7141
+ full |= 1 << keyIndex;
7142
+ }
7056
7143
  return (value) => {
7057
7144
  if (!isRecord(value)) return false;
7058
7145
  const keys = enumerableKeys(value);
7059
7146
  if (keys === void 0) return false;
7060
7147
  const outcome = attempt(() => {
7061
- const present = collectMembers(keys);
7062
- for (let keyIndex = 0; keyIndex < required.length; keyIndex += 1) {
7063
- const key = required[keyIndex];
7064
- if (key === void 0) continue;
7065
- if (!matchesMember(present, key)) return false;
7148
+ if (maskable) {
7149
+ let seen = 0;
7150
+ for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7151
+ const key = keys[keyIndex];
7152
+ if (key === void 0) continue;
7153
+ if (!INTRINSICS.own(positions, key)) continue;
7154
+ const position = positions[key];
7155
+ if (position !== void 0) seen |= 1 << position;
7156
+ }
7157
+ if (seen !== full) return false;
7158
+ } else {
7159
+ const present = collectMembers(keys);
7160
+ for (let keyIndex = 0; keyIndex < required.length; keyIndex += 1) {
7161
+ const key = required[keyIndex];
7162
+ if (key === void 0) continue;
7163
+ if (!matchesMember(present, key)) return false;
7164
+ }
7066
7165
  }
7067
7166
  for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7068
7167
  const key = keys[keyIndex];
@@ -7219,6 +7318,13 @@ var ContractCompiler = class ContractCompiler {
7219
7318
  subject: "object",
7220
7319
  context: { shape: "object" }
7221
7320
  });
7321
+ const maskable = entries.length <= 31;
7322
+ const positions = INTRINSICS.create(null);
7323
+ if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7324
+ const entry = entries[entryIndex];
7325
+ if (entry === void 0) continue;
7326
+ positions[entry.key] = entryIndex;
7327
+ }
7222
7328
  const extra = owned.additionalProperties;
7223
7329
  const additional = extra === void 0 || extra === false || extra === true ? void 0 : this.#parserAt(extra);
7224
7330
  const open = extra === true || additional !== void 0;
@@ -7228,12 +7334,20 @@ var ContractCompiler = class ContractCompiler {
7228
7334
  const keys = enumerableKeys(record);
7229
7335
  if (keys === void 0) return void 0;
7230
7336
  const outcome = attempt(() => {
7231
- const present = collectMembers(keys);
7337
+ const present = maskable ? void 0 : collectMembers(keys);
7338
+ let seen = 0;
7339
+ if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7340
+ const key = keys[keyIndex];
7341
+ if (key === void 0) continue;
7342
+ if (!INTRINSICS.own(positions, key)) continue;
7343
+ const position = positions[key];
7344
+ if (position !== void 0) seen |= 1 << position;
7345
+ }
7232
7346
  const result = INTRINSICS.create(null);
7233
7347
  for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7234
7348
  const entry = entries[entryIndex];
7235
7349
  if (entry === void 0) continue;
7236
- if (!matchesMember(present, entry.key)) {
7350
+ if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
7237
7351
  if (entry.optional) continue;
7238
7352
  return;
7239
7353
  }
@@ -7348,6 +7462,7 @@ var ContractCompiler = class ContractCompiler {
7348
7462
  switch (owned.type) {
7349
7463
  case "string": {
7350
7464
  const node = owned;
7465
+ const refined = owned.min !== void 0 || owned.max !== void 0 || owned.pattern !== void 0;
7351
7466
  return (value, path) => {
7352
7467
  if (!isString(value)) return [{
7353
7468
  reason: "type",
@@ -7355,12 +7470,13 @@ var ContractCompiler = class ContractCompiler {
7355
7470
  expected: "string",
7356
7471
  received: preview(value)
7357
7472
  }];
7358
- return createStringFaults(node, value, path);
7473
+ return refined ? createStringFaults(node, value, path) : [];
7359
7474
  };
7360
7475
  }
7361
7476
  case "number": {
7362
7477
  const node = owned;
7363
7478
  const kind = owned.integer === true ? "integer" : "number";
7479
+ const refined = owned.integer === true || owned.min !== void 0 || owned.max !== void 0;
7364
7480
  return (value, path) => {
7365
7481
  if (!isFiniteNumber(value)) return [{
7366
7482
  reason: "type",
@@ -7368,7 +7484,7 @@ var ContractCompiler = class ContractCompiler {
7368
7484
  expected: kind,
7369
7485
  received: preview(value)
7370
7486
  }];
7371
- return createNumberFaults(node, value, path);
7487
+ return refined ? createNumberFaults(node, value, path) : [];
7372
7488
  };
7373
7489
  }
7374
7490
  case "boolean": return (value, path) => isBoolean(value) ? [] : [{
@@ -7454,6 +7570,15 @@ var ContractCompiler = class ContractCompiler {
7454
7570
  const extra = owned.additionalProperties;
7455
7571
  const closed = extra === void 0 || extra === false;
7456
7572
  const additional = closed || extra === true ? void 0 : this.#auditAt(extra);
7573
+ const planned = attempt(() => collectMembers(declaredKeys));
7574
+ const declared = planned.success ? planned.value : void 0;
7575
+ const maskable = entries.length <= 31;
7576
+ const positions = INTRINSICS.create(null);
7577
+ if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7578
+ const entry = entries[entryIndex];
7579
+ if (entry === void 0) continue;
7580
+ positions[entry.key] = entryIndex;
7581
+ }
7457
7582
  return (value, path) => {
7458
7583
  if (isObject(value)) readValue(() => INTRINSICS.parent(value), "compileAuditor", {
7459
7584
  subject: "object",
@@ -7478,13 +7603,21 @@ var ContractCompiler = class ContractCompiler {
7478
7603
  });
7479
7604
  const faults = [];
7480
7605
  const outcome = attempt(() => {
7481
- const present = collectMembers(keys);
7482
- const declared = collectMembers(declaredKeys);
7606
+ const present = maskable ? void 0 : collectMembers(keys);
7607
+ const vocabulary = declared ?? collectMembers(declaredKeys);
7608
+ let seen = 0;
7609
+ if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7610
+ const key = keys[keyIndex];
7611
+ if (key === void 0) continue;
7612
+ if (!INTRINSICS.own(positions, key)) continue;
7613
+ const position = positions[key];
7614
+ if (position !== void 0) seen |= 1 << position;
7615
+ }
7483
7616
  for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7484
7617
  const entry = entries[entryIndex];
7485
7618
  if (entry === void 0) continue;
7486
7619
  if (faults.length >= 64) return;
7487
- if (!matchesMember(present, entry.key)) {
7620
+ if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
7488
7621
  if (!entry.optional) faults[faults.length] = {
7489
7622
  reason: "missing",
7490
7623
  path: pathOf(path, entry.key),
@@ -7498,7 +7631,7 @@ var ContractCompiler = class ContractCompiler {
7498
7631
  const key = keys[keyIndex];
7499
7632
  if (key === void 0) continue;
7500
7633
  if (faults.length >= 64) return;
7501
- if (matchesMember(declared, key)) continue;
7634
+ if (matchesMember(vocabulary, key)) continue;
7502
7635
  if (closed) {
7503
7636
  faults[faults.length] = {
7504
7637
  reason: "extra",
@@ -7541,8 +7674,11 @@ var ContractCompiler = class ContractCompiler {
7541
7674
  const plan = plans[index2];
7542
7675
  if (plan === void 0) continue;
7543
7676
  const variantFaults = plan(value, path);
7677
+ if (variantFaults.length === 0) {
7678
+ if (!exclusive) return [];
7679
+ matched += 1;
7680
+ }
7544
7681
  perVariant[perVariant.length] = variantFaults;
7545
- if (variantFaults.length === 0) matched += 1;
7546
7682
  }
7547
7683
  if (exclusive) {
7548
7684
  if (matched === 1) return [];
@@ -7551,7 +7687,7 @@ var ContractCompiler = class ContractCompiler {
7551
7687
  path,
7552
7688
  matched
7553
7689
  }];
7554
- } else if (matched > 0) return [];
7690
+ }
7555
7691
  const closest = selectClosestFaults(perVariant);
7556
7692
  const report = [exclusive ? {
7557
7693
  reason: "oneOf",
@@ -7616,6 +7752,7 @@ var ContractCompiler = class ContractCompiler {
7616
7752
  switch (owned.type) {
7617
7753
  case "string": {
7618
7754
  const node = owned;
7755
+ const refined = owned.min !== void 0 || owned.max !== void 0 || owned.pattern !== void 0;
7619
7756
  return (value, path) => {
7620
7757
  const parsed = parseString(value);
7621
7758
  if (parsed === void 0) return [{
@@ -7624,12 +7761,13 @@ var ContractCompiler = class ContractCompiler {
7624
7761
  expected: "string",
7625
7762
  received: preview(value)
7626
7763
  }];
7627
- return createStringFaults(node, parsed, path);
7764
+ return refined ? createStringFaults(node, parsed, path) : [];
7628
7765
  };
7629
7766
  }
7630
7767
  case "number": {
7631
7768
  const node = owned;
7632
7769
  const kind = owned.integer === true ? "integer" : "number";
7770
+ const refined = owned.integer === true || owned.min !== void 0 || owned.max !== void 0;
7633
7771
  return (value, path) => {
7634
7772
  const parsed = parseNumber(value);
7635
7773
  if (parsed === void 0) return [{
@@ -7638,7 +7776,7 @@ var ContractCompiler = class ContractCompiler {
7638
7776
  expected: kind,
7639
7777
  received: preview(value)
7640
7778
  }];
7641
- return createNumberFaults(node, parsed, path);
7779
+ return refined ? createNumberFaults(node, parsed, path) : [];
7642
7780
  };
7643
7781
  }
7644
7782
  case "boolean": return (value, path) => parseBoolean(value) === void 0 ? [{
@@ -7696,6 +7834,7 @@ var ContractCompiler = class ContractCompiler {
7696
7834
  }
7697
7835
  case "object": {
7698
7836
  const entries = [];
7837
+ const names = [];
7699
7838
  const keyList = INTRINSICS.keys(owned.properties);
7700
7839
  for (let keyIndex = 0; keyIndex < keyList.length; keyIndex += 1) {
7701
7840
  const key = keyList[keyIndex];
@@ -7710,10 +7849,20 @@ var ContractCompiler = class ContractCompiler {
7710
7849
  optional,
7711
7850
  kind: shapeToKind(inner)
7712
7851
  };
7852
+ names[names.length] = key;
7713
7853
  }
7714
7854
  const extra = owned.additionalProperties;
7715
7855
  const tail = extra === void 0 || extra === true || extra === false ? void 0 : this.#reportAt(extra);
7716
7856
  const open = extra === true || tail !== void 0;
7857
+ const planned = attempt(() => collectMembers(names));
7858
+ const known = planned.success ? planned.value : void 0;
7859
+ const maskable = entries.length <= 31;
7860
+ const positions = INTRINSICS.create(null);
7861
+ if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7862
+ const entry = entries[entryIndex];
7863
+ if (entry === void 0) continue;
7864
+ positions[entry.key] = entryIndex;
7865
+ }
7717
7866
  return (value, path) => {
7718
7867
  if (!isRecord(value)) return [{
7719
7868
  reason: "type",
@@ -7731,14 +7880,21 @@ var ContractCompiler = class ContractCompiler {
7731
7880
  }];
7732
7881
  const faults = [];
7733
7882
  if (!attempt(() => {
7734
- const present = collectMembers(keys);
7735
- const known = collectMembers([]);
7883
+ const present = maskable ? void 0 : collectMembers(keys);
7884
+ const vocabulary = known ?? collectMembers(names);
7885
+ let seen = 0;
7886
+ if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7887
+ const key = keys[keyIndex];
7888
+ if (key === void 0) continue;
7889
+ if (!INTRINSICS.own(positions, key)) continue;
7890
+ const position = positions[key];
7891
+ if (position !== void 0) seen |= 1 << position;
7892
+ }
7736
7893
  for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7737
7894
  const entry = entries[entryIndex];
7738
7895
  if (entry === void 0) continue;
7739
7896
  if (faults.length >= 64) return;
7740
- admitMember(known, entry.key);
7741
- if (!matchesMember(present, entry.key)) {
7897
+ if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
7742
7898
  if (!entry.optional) faults[faults.length] = {
7743
7899
  reason: "missing",
7744
7900
  path: pathOf(path, entry.key),
@@ -7761,7 +7917,7 @@ var ContractCompiler = class ContractCompiler {
7761
7917
  const key = keys[keyIndex];
7762
7918
  if (key === void 0) continue;
7763
7919
  if (faults.length >= 64) return;
7764
- if (matchesMember(known, key)) continue;
7920
+ if (matchesMember(vocabulary, key)) continue;
7765
7921
  const observed = record[key];
7766
7922
  if (tail !== void 0) appendEntries(faults, tail(observed, pathOf(path, key)));
7767
7923
  }
@@ -7790,7 +7946,9 @@ var ContractCompiler = class ContractCompiler {
7790
7946
  for (let index2 = 0; index2 < plans.length; index2 += 1) {
7791
7947
  const plan = plans[index2];
7792
7948
  if (plan === void 0) continue;
7793
- perVariant[perVariant.length] = plan(value, path);
7949
+ const variantFaults = plan(value, path);
7950
+ if (!exclusive && variantFaults.length === 0) return [];
7951
+ perVariant[perVariant.length] = variantFaults;
7794
7952
  }
7795
7953
  const closest = selectClosestFaults(perVariant);
7796
7954
  if (exclusive) {
@@ -7815,7 +7973,6 @@ var ContractCompiler = class ContractCompiler {
7815
7973
  matched
7816
7974
  }];
7817
7975
  }
7818
- for (let index2 = 0; index2 < perVariant.length; index2 += 1) if (perVariant[index2]?.length === 0) return [];
7819
7976
  const report = [{
7820
7977
  reason: "variant",
7821
7978
  path,
@@ -10375,6 +10532,7 @@ exports.INFER_ENUM_LIMIT = INFER_ENUM_LIMIT;
10375
10532
  exports.INTRINSICS = INTRINSICS;
10376
10533
  exports.JSONCloner = JSONCloner;
10377
10534
  exports.JSON_SCHEMA_TYPES = JSON_SCHEMA_TYPES;
10535
+ exports.PRESENCE_MASK_LIMIT = PRESENCE_MASK_LIMIT;
10378
10536
  exports.PREVIEW_LIMIT = PREVIEW_LIMIT;
10379
10537
  exports.SchemaCloner = SchemaCloner;
10380
10538
  exports.ShapeCloner = ShapeCloner;