@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.
@@ -332,6 +332,30 @@ var COMPILE_DEPTH_LIMIT = 512;
332
332
  */
333
333
  var COMPILE_NODE_LIMIT = 16384;
334
334
  /**
335
+ * The maximum number of object keys one compiled presence mask carries, frozen.
336
+ *
337
+ * @remarks
338
+ * A compiled object plan decides which declared keys a value carries. The keys
339
+ * it asks about are fixed when the plan is built, so the plan assigns each one a
340
+ * bit position once and a call ORs one bit per own key it finds and compares the
341
+ * result against the full mask — no per-call collection, and one integer compare
342
+ * instead of one membership dispatch per declared key.
343
+ *
344
+ * The bound is the width a JavaScript bitwise operand has: `1 << position`
345
+ * evaluates on a 32-bit signed integer, so positions run `0` through `30` and a
346
+ * mask stays positive. A declaration with more keys than this is ordinary
347
+ * authoring rather than an attack, so it is answered rather than refused:
348
+ * {@link ContractCompiler} builds no position record for it and its compiled
349
+ * guard, parser, auditor, and reporter decide presence from a collected key
350
+ * vocabulary instead. Both branches answer identically; only the cost differs.
351
+ *
352
+ * @example
353
+ * ```ts
354
+ * PRESENCE_MASK_LIMIT // 31
355
+ * ```
356
+ */
357
+ var PRESENCE_MASK_LIMIT = 31;
358
+ /**
335
359
  * The maximum number of nodes one JSON snapshot may produce, frozen.
336
360
  *
337
361
  * @remarks
@@ -2396,6 +2420,9 @@ function readArrayEntries(value) {
2396
2420
  const length = value.length;
2397
2421
  if (!INTRINSICS.safe(length) || length < 0 || length > 2 ** 32 - 1) throw new INTRINSICS.error("Array length is outside the native array domain");
2398
2422
  const collected = [];
2423
+ const keys = [];
2424
+ let ascending = true;
2425
+ let previous = -1;
2399
2426
  const members = INTRINSICS.members(value);
2400
2427
  for (let position = 0; position < members.length; position += 1) {
2401
2428
  const key = members[position];
@@ -2403,16 +2430,19 @@ function readArrayEntries(value) {
2403
2430
  const index = INTRINSICS.numeric(key);
2404
2431
  if (INTRINSICS.integer(index) && index >= 0 && index < 2 ** 32 - 1 && INTRINSICS.text(index) === key) {
2405
2432
  if (index >= length) throw new INTRINSICS.error("Array index views disagree");
2433
+ if (index <= previous) ascending = false;
2434
+ previous = index;
2406
2435
  collected[collected.length] = index;
2436
+ keys[keys.length] = key;
2407
2437
  }
2408
2438
  }
2409
- const indices = sortValues(collected);
2439
+ const indices = ascending ? collected : sortValues(collected);
2410
2440
  const entries = new INTRINSICS.list(length);
2411
2441
  for (let position = 0; position < indices.length; position += 1) {
2412
2442
  const index = indices[position];
2413
2443
  if (index === void 0) continue;
2414
- const key = INTRINSICS.text(index);
2415
- if (!INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
2444
+ const key = ascending ? keys[position] : INTRINSICS.text(index);
2445
+ if (key === void 0 || !INTRINSICS.own(value, key)) throw new INTRINSICS.error("Array index views disagree");
2416
2446
  entries[index] = value[index];
2417
2447
  }
2418
2448
  return INTRINSICS.freeze({
@@ -6502,28 +6532,38 @@ var ContractCompiler = class ContractCompiler {
6502
6532
  static #weakMap = WeakMap;
6503
6533
  static #visits = 0;
6504
6534
  static #scope = 0;
6535
+ static #emptyStack = [];
6536
+ static #emptyNodes = [];
6537
+ static #emptyOrder = [];
6538
+ static #emptySchemas = [];
6539
+ static #emptyGuards = [];
6540
+ static #emptyParsers = [];
6541
+ static #emptyAudits = [];
6542
+ static #emptyReports = [];
6543
+ static #emptySeeds = [];
6544
+ static {
6545
+ INTRINSICS.freeze(ContractCompiler.#emptyStack);
6546
+ INTRINSICS.freeze(ContractCompiler.#emptyNodes);
6547
+ INTRINSICS.freeze(ContractCompiler.#emptyOrder);
6548
+ INTRINSICS.freeze(ContractCompiler.#emptySchemas);
6549
+ INTRINSICS.freeze(ContractCompiler.#emptyGuards);
6550
+ INTRINSICS.freeze(ContractCompiler.#emptyParsers);
6551
+ INTRINSICS.freeze(ContractCompiler.#emptyAudits);
6552
+ INTRINSICS.freeze(ContractCompiler.#emptyReports);
6553
+ INTRINSICS.freeze(ContractCompiler.#emptySeeds);
6554
+ }
6505
6555
  #source;
6506
6556
  #state;
6507
6557
  #stack;
6508
- #emptyStack;
6509
6558
  #nodes;
6510
- #emptyNodes;
6511
6559
  #index;
6512
- #emptyIndex;
6513
6560
  #order;
6514
- #emptyOrder;
6515
6561
  #schemas;
6516
- #emptySchemas;
6517
6562
  #guards;
6518
- #emptyGuards;
6519
6563
  #parsers;
6520
- #emptyParsers;
6521
6564
  #audits;
6522
- #emptyAudits;
6523
6565
  #reports;
6524
- #emptyReports;
6525
6566
  #seeds;
6526
- #emptySeeds;
6527
6567
  #schema;
6528
6568
  #guard;
6529
6569
  #parser;
@@ -6540,25 +6580,15 @@ var ContractCompiler = class ContractCompiler {
6540
6580
  this.#source = shape;
6541
6581
  this.#state = { phase: "ready" };
6542
6582
  this.#stack = [];
6543
- this.#emptyStack = [];
6544
6583
  this.#nodes = [];
6545
- this.#emptyNodes = [];
6546
6584
  this.#index = new ContractCompiler.#weakMap();
6547
- this.#emptyIndex = new ContractCompiler.#weakMap();
6548
6585
  this.#order = [];
6549
- this.#emptyOrder = [];
6550
6586
  this.#schemas = [];
6551
- this.#emptySchemas = [];
6552
6587
  this.#guards = [];
6553
- this.#emptyGuards = [];
6554
6588
  this.#parsers = [];
6555
- this.#emptyParsers = [];
6556
6589
  this.#audits = [];
6557
- this.#emptyAudits = [];
6558
6590
  this.#reports = [];
6559
- this.#emptyReports = [];
6560
6591
  this.#seeds = [];
6561
- this.#emptySeeds = [];
6562
6592
  this.#schema = void 0;
6563
6593
  this.#guard = void 0;
6564
6594
  this.#parser = void 0;
@@ -6680,16 +6710,16 @@ var ContractCompiler = class ContractCompiler {
6680
6710
  }
6681
6711
  #release() {
6682
6712
  this.#source = void 0;
6683
- this.#stack = this.#emptyStack;
6684
- this.#nodes = this.#emptyNodes;
6685
- this.#index = this.#emptyIndex;
6686
- this.#order = this.#emptyOrder;
6687
- this.#schemas = this.#emptySchemas;
6688
- this.#guards = this.#emptyGuards;
6689
- this.#parsers = this.#emptyParsers;
6690
- this.#audits = this.#emptyAudits;
6691
- this.#reports = this.#emptyReports;
6692
- this.#seeds = this.#emptySeeds;
6713
+ this.#stack = ContractCompiler.#emptyStack;
6714
+ this.#nodes = ContractCompiler.#emptyNodes;
6715
+ this.#index = void 0;
6716
+ this.#order = ContractCompiler.#emptyOrder;
6717
+ this.#schemas = ContractCompiler.#emptySchemas;
6718
+ this.#guards = ContractCompiler.#emptyGuards;
6719
+ this.#parsers = ContractCompiler.#emptyParsers;
6720
+ this.#audits = ContractCompiler.#emptyAudits;
6721
+ this.#reports = ContractCompiler.#emptyReports;
6722
+ this.#seeds = ContractCompiler.#emptySeeds;
6693
6723
  }
6694
6724
  #prepare() {
6695
6725
  if (this.#nodes.length > 0) return;
@@ -6709,6 +6739,14 @@ var ContractCompiler = class ContractCompiler {
6709
6739
  this.#source = void 0;
6710
6740
  }
6711
6741
  #discover(root) {
6742
+ const known = this.#index;
6743
+ if (known === void 0) throw new ContractError("ContractCompiler: the prepared index is unavailable", {
6744
+ code: "structure",
6745
+ context: {
6746
+ path: [],
6747
+ shape: "contract"
6748
+ }
6749
+ });
6712
6750
  this.#stack[this.#stack.length] = {
6713
6751
  operation: "enter",
6714
6752
  shape: root
@@ -6723,10 +6761,10 @@ var ContractCompiler = class ContractCompiler {
6723
6761
  continue;
6724
6762
  }
6725
6763
  const shape = frame.shape;
6726
- if (INTRINSICS.apply(INTRINSICS.recall, this.#index, [shape]) !== void 0) continue;
6764
+ if (INTRINSICS.apply(INTRINSICS.recall, known, [shape]) !== void 0) continue;
6727
6765
  const index = this.#nodes.length;
6728
6766
  this.#nodes[index] = shape;
6729
- INTRINSICS.apply(INTRINSICS.retain, this.#index, [shape, index]);
6767
+ INTRINSICS.apply(INTRINSICS.retain, known, [shape, index]);
6730
6768
  this.#stack[this.#stack.length] = {
6731
6769
  operation: "exit",
6732
6770
  index
@@ -6782,7 +6820,15 @@ var ContractCompiler = class ContractCompiler {
6782
6820
  }
6783
6821
  }
6784
6822
  #locate(shape) {
6785
- const index = INTRINSICS.apply(INTRINSICS.recall, this.#index, [shape]);
6823
+ const known = this.#index;
6824
+ if (known === void 0) throw new ContractError("ContractCompiler: the prepared index is unavailable", {
6825
+ code: "structure",
6826
+ context: {
6827
+ path: [],
6828
+ shape: "contract"
6829
+ }
6830
+ });
6831
+ const index = INTRINSICS.apply(INTRINSICS.recall, known, [shape]);
6786
6832
  if (index === void 0) throw new ContractError("ContractCompiler: a structural child is not in the prepared index", {
6787
6833
  code: "structure",
6788
6834
  context: {
@@ -6814,7 +6860,9 @@ var ContractCompiler = class ContractCompiler {
6814
6860
  }
6815
6861
  #trackGuard(plan) {
6816
6862
  let filled = 0;
6817
- let memo = new ContractCompiler.#weakMap();
6863
+ let memo;
6864
+ let slot;
6865
+ let kept = false;
6818
6866
  return (value) => {
6819
6867
  if (!isObject(value)) return plan(value);
6820
6868
  const opened = ContractCompiler.#scope === 0;
@@ -6825,13 +6873,27 @@ var ContractCompiler = class ContractCompiler {
6825
6873
  try {
6826
6874
  const scope = ContractCompiler.#scope;
6827
6875
  if (filled !== scope) {
6828
- memo = new ContractCompiler.#weakMap();
6876
+ memo = void 0;
6877
+ slot = void 0;
6878
+ kept = false;
6829
6879
  filled = scope;
6830
6880
  }
6831
- const recalled = INTRINSICS.apply(INTRINSICS.recall, memo, [value]);
6832
- if (recalled !== void 0) return recalled;
6881
+ if (slot === value) return kept;
6882
+ if (memo !== void 0) {
6883
+ const recalled = INTRINSICS.apply(INTRINSICS.recall, memo, [value]);
6884
+ if (recalled !== void 0) return recalled;
6885
+ }
6833
6886
  const answer = plan(value);
6834
- INTRINSICS.apply(INTRINSICS.retain, memo, [value, answer]);
6887
+ if (slot === void 0) {
6888
+ slot = value;
6889
+ kept = answer;
6890
+ } else {
6891
+ if (memo === void 0) {
6892
+ memo = new ContractCompiler.#weakMap();
6893
+ INTRINSICS.apply(INTRINSICS.retain, memo, [slot, kept]);
6894
+ }
6895
+ INTRINSICS.apply(INTRINSICS.retain, memo, [value, answer]);
6896
+ }
6835
6897
  return answer;
6836
6898
  } finally {
6837
6899
  if (opened) ContractCompiler.#scope = 0;
@@ -6840,7 +6902,9 @@ var ContractCompiler = class ContractCompiler {
6840
6902
  }
6841
6903
  #trackFaults(plan) {
6842
6904
  let filled = 0;
6843
- let memo = new ContractCompiler.#weakMap();
6905
+ let memo;
6906
+ let slot;
6907
+ let kept;
6844
6908
  return (value, path) => {
6845
6909
  if (!isObject(value)) return plan(value, path);
6846
6910
  const opened = ContractCompiler.#scope === 0;
@@ -6851,13 +6915,27 @@ var ContractCompiler = class ContractCompiler {
6851
6915
  try {
6852
6916
  const scope = ContractCompiler.#scope;
6853
6917
  if (filled !== scope) {
6854
- memo = new ContractCompiler.#weakMap();
6918
+ memo = void 0;
6919
+ slot = void 0;
6920
+ kept = void 0;
6855
6921
  filled = scope;
6856
6922
  }
6857
- const recalled = INTRINSICS.apply(INTRINSICS.recall, memo, [value]);
6858
- if (recalled !== void 0) return recalled;
6923
+ if (slot === value && kept !== void 0) return kept;
6924
+ if (memo !== void 0) {
6925
+ const recalled = INTRINSICS.apply(INTRINSICS.recall, memo, [value]);
6926
+ if (recalled !== void 0) return recalled;
6927
+ }
6859
6928
  const answer = plan(value, path);
6860
- if (answer.length === 0) INTRINSICS.apply(INTRINSICS.retain, memo, [value, answer]);
6929
+ if (slot === void 0) {
6930
+ slot = value;
6931
+ kept = answer.length === 0 ? answer : void 0;
6932
+ } else if (answer.length === 0) {
6933
+ if (memo === void 0) {
6934
+ memo = new ContractCompiler.#weakMap();
6935
+ if (kept !== void 0) INTRINSICS.apply(INTRINSICS.retain, memo, [slot, kept]);
6936
+ }
6937
+ INTRINSICS.apply(INTRINSICS.retain, memo, [value, answer]);
6938
+ }
6861
6939
  return answer;
6862
6940
  } finally {
6863
6941
  if (opened) ContractCompiler.#scope = 0;
@@ -7052,16 +7130,37 @@ var ContractCompiler = class ContractCompiler {
7052
7130
  for (let optionalIndex = 0; optionalIndex < optionalKeys.length; optionalIndex += 1) if (optionalKeys[optionalIndex] === key) optional = true;
7053
7131
  if (!optional) required[required.length] = key;
7054
7132
  }
7133
+ const maskable = required.length <= 31;
7134
+ const positions = INTRINSICS.create(null);
7135
+ let full = 0;
7136
+ if (maskable) for (let keyIndex = 0; keyIndex < required.length; keyIndex += 1) {
7137
+ const key = required[keyIndex];
7138
+ if (key === void 0) continue;
7139
+ positions[key] = keyIndex;
7140
+ full |= 1 << keyIndex;
7141
+ }
7055
7142
  return (value) => {
7056
7143
  if (!isRecord(value)) return false;
7057
7144
  const keys = enumerableKeys(value);
7058
7145
  if (keys === void 0) return false;
7059
7146
  const outcome = attempt(() => {
7060
- const present = collectMembers(keys);
7061
- for (let keyIndex = 0; keyIndex < required.length; keyIndex += 1) {
7062
- const key = required[keyIndex];
7063
- if (key === void 0) continue;
7064
- if (!matchesMember(present, key)) return false;
7147
+ if (maskable) {
7148
+ let seen = 0;
7149
+ for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7150
+ const key = keys[keyIndex];
7151
+ if (key === void 0) continue;
7152
+ if (!INTRINSICS.own(positions, key)) continue;
7153
+ const position = positions[key];
7154
+ if (position !== void 0) seen |= 1 << position;
7155
+ }
7156
+ if (seen !== full) return false;
7157
+ } else {
7158
+ const present = collectMembers(keys);
7159
+ for (let keyIndex = 0; keyIndex < required.length; keyIndex += 1) {
7160
+ const key = required[keyIndex];
7161
+ if (key === void 0) continue;
7162
+ if (!matchesMember(present, key)) return false;
7163
+ }
7065
7164
  }
7066
7165
  for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7067
7166
  const key = keys[keyIndex];
@@ -7218,6 +7317,13 @@ var ContractCompiler = class ContractCompiler {
7218
7317
  subject: "object",
7219
7318
  context: { shape: "object" }
7220
7319
  });
7320
+ const maskable = entries.length <= 31;
7321
+ const positions = INTRINSICS.create(null);
7322
+ if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7323
+ const entry = entries[entryIndex];
7324
+ if (entry === void 0) continue;
7325
+ positions[entry.key] = entryIndex;
7326
+ }
7221
7327
  const extra = owned.additionalProperties;
7222
7328
  const additional = extra === void 0 || extra === false || extra === true ? void 0 : this.#parserAt(extra);
7223
7329
  const open = extra === true || additional !== void 0;
@@ -7227,12 +7333,20 @@ var ContractCompiler = class ContractCompiler {
7227
7333
  const keys = enumerableKeys(record);
7228
7334
  if (keys === void 0) return void 0;
7229
7335
  const outcome = attempt(() => {
7230
- const present = collectMembers(keys);
7336
+ const present = maskable ? void 0 : collectMembers(keys);
7337
+ let seen = 0;
7338
+ if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7339
+ const key = keys[keyIndex];
7340
+ if (key === void 0) continue;
7341
+ if (!INTRINSICS.own(positions, key)) continue;
7342
+ const position = positions[key];
7343
+ if (position !== void 0) seen |= 1 << position;
7344
+ }
7231
7345
  const result = INTRINSICS.create(null);
7232
7346
  for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7233
7347
  const entry = entries[entryIndex];
7234
7348
  if (entry === void 0) continue;
7235
- if (!matchesMember(present, entry.key)) {
7349
+ if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
7236
7350
  if (entry.optional) continue;
7237
7351
  return;
7238
7352
  }
@@ -7347,6 +7461,7 @@ var ContractCompiler = class ContractCompiler {
7347
7461
  switch (owned.type) {
7348
7462
  case "string": {
7349
7463
  const node = owned;
7464
+ const refined = owned.min !== void 0 || owned.max !== void 0 || owned.pattern !== void 0;
7350
7465
  return (value, path) => {
7351
7466
  if (!isString(value)) return [{
7352
7467
  reason: "type",
@@ -7354,12 +7469,13 @@ var ContractCompiler = class ContractCompiler {
7354
7469
  expected: "string",
7355
7470
  received: preview(value)
7356
7471
  }];
7357
- return createStringFaults(node, value, path);
7472
+ return refined ? createStringFaults(node, value, path) : [];
7358
7473
  };
7359
7474
  }
7360
7475
  case "number": {
7361
7476
  const node = owned;
7362
7477
  const kind = owned.integer === true ? "integer" : "number";
7478
+ const refined = owned.integer === true || owned.min !== void 0 || owned.max !== void 0;
7363
7479
  return (value, path) => {
7364
7480
  if (!isFiniteNumber(value)) return [{
7365
7481
  reason: "type",
@@ -7367,7 +7483,7 @@ var ContractCompiler = class ContractCompiler {
7367
7483
  expected: kind,
7368
7484
  received: preview(value)
7369
7485
  }];
7370
- return createNumberFaults(node, value, path);
7486
+ return refined ? createNumberFaults(node, value, path) : [];
7371
7487
  };
7372
7488
  }
7373
7489
  case "boolean": return (value, path) => isBoolean(value) ? [] : [{
@@ -7453,6 +7569,15 @@ var ContractCompiler = class ContractCompiler {
7453
7569
  const extra = owned.additionalProperties;
7454
7570
  const closed = extra === void 0 || extra === false;
7455
7571
  const additional = closed || extra === true ? void 0 : this.#auditAt(extra);
7572
+ const planned = attempt(() => collectMembers(declaredKeys));
7573
+ const declared = planned.success ? planned.value : void 0;
7574
+ const maskable = entries.length <= 31;
7575
+ const positions = INTRINSICS.create(null);
7576
+ if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7577
+ const entry = entries[entryIndex];
7578
+ if (entry === void 0) continue;
7579
+ positions[entry.key] = entryIndex;
7580
+ }
7456
7581
  return (value, path) => {
7457
7582
  if (isObject(value)) readValue(() => INTRINSICS.parent(value), "compileAuditor", {
7458
7583
  subject: "object",
@@ -7477,13 +7602,21 @@ var ContractCompiler = class ContractCompiler {
7477
7602
  });
7478
7603
  const faults = [];
7479
7604
  const outcome = attempt(() => {
7480
- const present = collectMembers(keys);
7481
- const declared = collectMembers(declaredKeys);
7605
+ const present = maskable ? void 0 : collectMembers(keys);
7606
+ const vocabulary = declared ?? collectMembers(declaredKeys);
7607
+ let seen = 0;
7608
+ if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7609
+ const key = keys[keyIndex];
7610
+ if (key === void 0) continue;
7611
+ if (!INTRINSICS.own(positions, key)) continue;
7612
+ const position = positions[key];
7613
+ if (position !== void 0) seen |= 1 << position;
7614
+ }
7482
7615
  for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7483
7616
  const entry = entries[entryIndex];
7484
7617
  if (entry === void 0) continue;
7485
7618
  if (faults.length >= 64) return;
7486
- if (!matchesMember(present, entry.key)) {
7619
+ if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
7487
7620
  if (!entry.optional) faults[faults.length] = {
7488
7621
  reason: "missing",
7489
7622
  path: pathOf(path, entry.key),
@@ -7497,7 +7630,7 @@ var ContractCompiler = class ContractCompiler {
7497
7630
  const key = keys[keyIndex];
7498
7631
  if (key === void 0) continue;
7499
7632
  if (faults.length >= 64) return;
7500
- if (matchesMember(declared, key)) continue;
7633
+ if (matchesMember(vocabulary, key)) continue;
7501
7634
  if (closed) {
7502
7635
  faults[faults.length] = {
7503
7636
  reason: "extra",
@@ -7540,8 +7673,11 @@ var ContractCompiler = class ContractCompiler {
7540
7673
  const plan = plans[index2];
7541
7674
  if (plan === void 0) continue;
7542
7675
  const variantFaults = plan(value, path);
7676
+ if (variantFaults.length === 0) {
7677
+ if (!exclusive) return [];
7678
+ matched += 1;
7679
+ }
7543
7680
  perVariant[perVariant.length] = variantFaults;
7544
- if (variantFaults.length === 0) matched += 1;
7545
7681
  }
7546
7682
  if (exclusive) {
7547
7683
  if (matched === 1) return [];
@@ -7550,7 +7686,7 @@ var ContractCompiler = class ContractCompiler {
7550
7686
  path,
7551
7687
  matched
7552
7688
  }];
7553
- } else if (matched > 0) return [];
7689
+ }
7554
7690
  const closest = selectClosestFaults(perVariant);
7555
7691
  const report = [exclusive ? {
7556
7692
  reason: "oneOf",
@@ -7615,6 +7751,7 @@ var ContractCompiler = class ContractCompiler {
7615
7751
  switch (owned.type) {
7616
7752
  case "string": {
7617
7753
  const node = owned;
7754
+ const refined = owned.min !== void 0 || owned.max !== void 0 || owned.pattern !== void 0;
7618
7755
  return (value, path) => {
7619
7756
  const parsed = parseString(value);
7620
7757
  if (parsed === void 0) return [{
@@ -7623,12 +7760,13 @@ var ContractCompiler = class ContractCompiler {
7623
7760
  expected: "string",
7624
7761
  received: preview(value)
7625
7762
  }];
7626
- return createStringFaults(node, parsed, path);
7763
+ return refined ? createStringFaults(node, parsed, path) : [];
7627
7764
  };
7628
7765
  }
7629
7766
  case "number": {
7630
7767
  const node = owned;
7631
7768
  const kind = owned.integer === true ? "integer" : "number";
7769
+ const refined = owned.integer === true || owned.min !== void 0 || owned.max !== void 0;
7632
7770
  return (value, path) => {
7633
7771
  const parsed = parseNumber(value);
7634
7772
  if (parsed === void 0) return [{
@@ -7637,7 +7775,7 @@ var ContractCompiler = class ContractCompiler {
7637
7775
  expected: kind,
7638
7776
  received: preview(value)
7639
7777
  }];
7640
- return createNumberFaults(node, parsed, path);
7778
+ return refined ? createNumberFaults(node, parsed, path) : [];
7641
7779
  };
7642
7780
  }
7643
7781
  case "boolean": return (value, path) => parseBoolean(value) === void 0 ? [{
@@ -7695,6 +7833,7 @@ var ContractCompiler = class ContractCompiler {
7695
7833
  }
7696
7834
  case "object": {
7697
7835
  const entries = [];
7836
+ const names = [];
7698
7837
  const keyList = INTRINSICS.keys(owned.properties);
7699
7838
  for (let keyIndex = 0; keyIndex < keyList.length; keyIndex += 1) {
7700
7839
  const key = keyList[keyIndex];
@@ -7709,10 +7848,20 @@ var ContractCompiler = class ContractCompiler {
7709
7848
  optional,
7710
7849
  kind: shapeToKind(inner)
7711
7850
  };
7851
+ names[names.length] = key;
7712
7852
  }
7713
7853
  const extra = owned.additionalProperties;
7714
7854
  const tail = extra === void 0 || extra === true || extra === false ? void 0 : this.#reportAt(extra);
7715
7855
  const open = extra === true || tail !== void 0;
7856
+ const planned = attempt(() => collectMembers(names));
7857
+ const known = planned.success ? planned.value : void 0;
7858
+ const maskable = entries.length <= 31;
7859
+ const positions = INTRINSICS.create(null);
7860
+ if (maskable) for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7861
+ const entry = entries[entryIndex];
7862
+ if (entry === void 0) continue;
7863
+ positions[entry.key] = entryIndex;
7864
+ }
7716
7865
  return (value, path) => {
7717
7866
  if (!isRecord(value)) return [{
7718
7867
  reason: "type",
@@ -7730,14 +7879,21 @@ var ContractCompiler = class ContractCompiler {
7730
7879
  }];
7731
7880
  const faults = [];
7732
7881
  if (!attempt(() => {
7733
- const present = collectMembers(keys);
7734
- const known = collectMembers([]);
7882
+ const present = maskable ? void 0 : collectMembers(keys);
7883
+ const vocabulary = known ?? collectMembers(names);
7884
+ let seen = 0;
7885
+ if (present === void 0) for (let keyIndex = 0; keyIndex < keys.length; keyIndex += 1) {
7886
+ const key = keys[keyIndex];
7887
+ if (key === void 0) continue;
7888
+ if (!INTRINSICS.own(positions, key)) continue;
7889
+ const position = positions[key];
7890
+ if (position !== void 0) seen |= 1 << position;
7891
+ }
7735
7892
  for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
7736
7893
  const entry = entries[entryIndex];
7737
7894
  if (entry === void 0) continue;
7738
7895
  if (faults.length >= 64) return;
7739
- admitMember(known, entry.key);
7740
- if (!matchesMember(present, entry.key)) {
7896
+ if (present === void 0 ? (seen & 1 << entryIndex) === 0 : !matchesMember(present, entry.key)) {
7741
7897
  if (!entry.optional) faults[faults.length] = {
7742
7898
  reason: "missing",
7743
7899
  path: pathOf(path, entry.key),
@@ -7760,7 +7916,7 @@ var ContractCompiler = class ContractCompiler {
7760
7916
  const key = keys[keyIndex];
7761
7917
  if (key === void 0) continue;
7762
7918
  if (faults.length >= 64) return;
7763
- if (matchesMember(known, key)) continue;
7919
+ if (matchesMember(vocabulary, key)) continue;
7764
7920
  const observed = record[key];
7765
7921
  if (tail !== void 0) appendEntries(faults, tail(observed, pathOf(path, key)));
7766
7922
  }
@@ -7789,7 +7945,9 @@ var ContractCompiler = class ContractCompiler {
7789
7945
  for (let index2 = 0; index2 < plans.length; index2 += 1) {
7790
7946
  const plan = plans[index2];
7791
7947
  if (plan === void 0) continue;
7792
- perVariant[perVariant.length] = plan(value, path);
7948
+ const variantFaults = plan(value, path);
7949
+ if (!exclusive && variantFaults.length === 0) return [];
7950
+ perVariant[perVariant.length] = variantFaults;
7793
7951
  }
7794
7952
  const closest = selectClosestFaults(perVariant);
7795
7953
  if (exclusive) {
@@ -7814,7 +7972,6 @@ var ContractCompiler = class ContractCompiler {
7814
7972
  matched
7815
7973
  }];
7816
7974
  }
7817
- for (let index2 = 0; index2 < perVariant.length; index2 += 1) if (perVariant[index2]?.length === 0) return [];
7818
7975
  const report = [{
7819
7976
  reason: "variant",
7820
7977
  path,
@@ -10357,6 +10514,6 @@ function schemaToShape(schema) {
10357
10514
  }, "schemaToShape");
10358
10515
  }
10359
10516
  //#endregion
10360
- export { CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, PREVIEW_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildSampleMemo, buildShapeFromNode, canonicalStringify, canonicalizeValue, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, compareValues, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createArrayFaults, createContract, createNumberFaults, createStringFaults, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isValidISOInstant, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, rawShape, readArrayEntries, readGuardShape, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShapeDepth, valueToSchema, whereOf };
10517
+ export { CLONE_NODE_LIMIT, COMPILE_DEPTH_LIMIT, COMPILE_NODE_LIMIT, CONTRACT_ERROR_BRAND, ContractCompiler, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, INTRINSICS, JSONCloner, JSON_SCHEMA_TYPES, PRESENCE_MASK_LIMIT, PREVIEW_LIMIT, SchemaCloner, ShapeCloner, ShapeValidator, admitMember, admitVisited, andOf, appendEntries, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildSampleMemo, buildShapeFromNode, canonicalStringify, canonicalizeValue, classifyFormat, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, collectEntries, collectMembers, compareValues, compileAuditor, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, contain, createArrayFaults, createContract, createNumberFaults, createStringFaults, deriveLengthBounds, deriveRangeBounds, drawRandom, encodeLeaf, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isBoundedJSONRecord, isBoundedJSONValue, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isLiteralValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNonNegativeInteger, isNonNegativeNumber, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isValidISOInstant, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, jsonShape, keyOf, lazyOf, limitEntries, literalOf, literalShape, mapOf, matchOf, matchesJSONDepth, matchesJSONValue, matchesMember, matchesPattern, matchesRecordBrand, matchesVisited, notOf, nullShape, nullableOf, nullableShape, numberShape, objectOf, objectShape, omitOf, omitVisited, oneOfShape, optionalOf, optionalShape, orOf, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pathOf, pickOf, pinMembers, preview, rawShape, readArrayEntries, readGuardShape, readMapEntries, readOptions, readPattern, readPatternFlags, readPatternSource, readSampleMemo, readSetEntries, readValue, recordOf, recordShape, refuseExpansion, resolveField, retainDepth, samplesToFormat, samplesToSchema, sanitizeBudget, sanitizeDepth, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, selectClosestFaults, setOf, shapeToKind, sortValues, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShapeDepth, valueToSchema, whereOf };
10361
10518
 
10362
10519
  //# sourceMappingURL=index.js.map