@ghostry/fabricator 0.0.13 → 0.0.14

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.
Files changed (105) hide show
  1. package/dist/esm/Bound.js +74 -1
  2. package/dist/esm/Distribution/index.js +103 -2
  3. package/dist/esm/Enumeration/Enumerate.js +10 -5
  4. package/dist/esm/Enumeration/Plan.js +2 -2
  5. package/dist/esm/Error/index.js +96 -27
  6. package/dist/esm/Fabricator/Constructor.js +7 -5
  7. package/dist/esm/Instance/Core.js +3 -0
  8. package/dist/esm/Primitive/array/Admits.js +18 -0
  9. package/dist/esm/Primitive/array/Fabricator.js +20 -2
  10. package/dist/esm/Primitive/array/Registry.js +32 -0
  11. package/dist/esm/Primitive/array/Schema.js +8 -0
  12. package/dist/esm/Primitive/bigint/Admits.js +11 -0
  13. package/dist/esm/Primitive/bigint/Fabricator.js +16 -23
  14. package/dist/esm/Primitive/bigint/Registry.js +17 -6
  15. package/dist/esm/Primitive/bigint/Schema.js +8 -0
  16. package/dist/esm/Primitive/date/Admits.js +22 -0
  17. package/dist/esm/Primitive/date/Defaults.js +27 -1
  18. package/dist/esm/Primitive/date/Fabricator.js +32 -34
  19. package/dist/esm/Primitive/date/Registry.js +80 -13
  20. package/dist/esm/Primitive/date/Schema.js +8 -0
  21. package/dist/esm/Primitive/enum/Fabricator.js +14 -2
  22. package/dist/esm/Primitive/enum/Registry.js +38 -25
  23. package/dist/esm/Primitive/index.js +1 -0
  24. package/dist/esm/Primitive/number/Admits.js +27 -0
  25. package/dist/esm/Primitive/number/Fabricator.js +18 -9
  26. package/dist/esm/Primitive/number/Registry.js +55 -4
  27. package/dist/esm/Primitive/number/Schema.js +10 -3
  28. package/dist/esm/Primitive/object/Fabricator.js +2 -0
  29. package/dist/esm/Primitive/record/Admits.js +42 -0
  30. package/dist/esm/Primitive/record/Fabricator.js +49 -19
  31. package/dist/esm/Primitive/record/Registry.js +29 -0
  32. package/dist/esm/Primitive/record/Schema.js +8 -0
  33. package/dist/esm/Primitive/recursive/Fabricator.js +3 -2
  34. package/dist/esm/Primitive/recursive/Terminate.js +16 -2
  35. package/dist/esm/Primitive/string/Admits.js +26 -0
  36. package/dist/esm/Primitive/string/Capacity.js +81 -0
  37. package/dist/esm/Primitive/string/Fabricator.js +23 -43
  38. package/dist/esm/Primitive/string/Registry.js +31 -9
  39. package/dist/esm/Primitive/string/Schema.js +10 -3
  40. package/dist/esm/Primitive/string/Sources.js +41 -0
  41. package/dist/esm/Primitive/unique/Registry.js +22 -0
  42. package/dist/esm/Primitive/unique/index.js +2 -0
  43. package/dist/esm/Types.js +2 -1
  44. package/dist/esm/Unique/Capacity.js +85 -0
  45. package/dist/esm/Unique/Distinct.js +187 -0
  46. package/dist/esm/Unique/Key.js +70 -0
  47. package/dist/esm/Unique/Override.js +23 -0
  48. package/dist/esm/Unique/Strategy.js +173 -0
  49. package/dist/esm/internal.js +1 -0
  50. package/dist/types/Bound.d.ts +66 -0
  51. package/dist/types/Distribution/index.d.ts +82 -0
  52. package/dist/types/Enumeration/Types.d.ts +10 -1
  53. package/dist/types/Error/index.d.ts +283 -0
  54. package/dist/types/Fabricator/Constructor.d.ts +6 -2
  55. package/dist/types/Fabricator/Types.d.ts +13 -0
  56. package/dist/types/Instance/Types.d.ts +14 -0
  57. package/dist/types/Primitive/array/Admits.d.ts +7 -0
  58. package/dist/types/Primitive/array/Fabricator.d.ts +2 -2
  59. package/dist/types/Primitive/array/Registry.d.ts +38 -1
  60. package/dist/types/Primitive/array/Schema.d.ts +6 -1
  61. package/dist/types/Primitive/array/Types.d.ts +33 -1
  62. package/dist/types/Primitive/bigint/Admits.d.ts +7 -0
  63. package/dist/types/Primitive/bigint/Fabricator.d.ts +3 -1
  64. package/dist/types/Primitive/bigint/Registry.d.ts +20 -0
  65. package/dist/types/Primitive/bigint/Schema.d.ts +9 -1
  66. package/dist/types/Primitive/bigint/Types.d.ts +27 -3
  67. package/dist/types/Primitive/date/Admits.d.ts +7 -0
  68. package/dist/types/Primitive/date/Defaults.d.ts +22 -1
  69. package/dist/types/Primitive/date/Fabricator.d.ts +3 -1
  70. package/dist/types/Primitive/date/Registry.d.ts +47 -11
  71. package/dist/types/Primitive/date/Schema.d.ts +10 -1
  72. package/dist/types/Primitive/date/Types.d.ts +53 -4
  73. package/dist/types/Primitive/enum/Fabricator.d.ts +3 -1
  74. package/dist/types/Primitive/enum/Registry.d.ts +20 -0
  75. package/dist/types/Primitive/enum/Types.d.ts +5 -0
  76. package/dist/types/Primitive/index.d.ts +1 -0
  77. package/dist/types/Primitive/number/Admits.d.ts +9 -0
  78. package/dist/types/Primitive/number/Fabricator.d.ts +3 -1
  79. package/dist/types/Primitive/number/Registry.d.ts +42 -1
  80. package/dist/types/Primitive/number/Schema.d.ts +10 -2
  81. package/dist/types/Primitive/number/Types.d.ts +32 -10
  82. package/dist/types/Primitive/record/Admits.d.ts +18 -0
  83. package/dist/types/Primitive/record/Fabricator.d.ts +2 -2
  84. package/dist/types/Primitive/record/Registry.d.ts +18 -1
  85. package/dist/types/Primitive/record/Schema.d.ts +8 -1
  86. package/dist/types/Primitive/record/Types.d.ts +60 -6
  87. package/dist/types/Primitive/recursive/Terminate.d.ts +7 -0
  88. package/dist/types/Primitive/string/Admits.d.ts +8 -0
  89. package/dist/types/Primitive/string/Capacity.d.ts +36 -0
  90. package/dist/types/Primitive/string/Fabricator.d.ts +3 -1
  91. package/dist/types/Primitive/string/Registry.d.ts +26 -5
  92. package/dist/types/Primitive/string/Schema.d.ts +28 -2
  93. package/dist/types/Primitive/string/Sources.d.ts +16 -0
  94. package/dist/types/Primitive/string/Types.d.ts +35 -15
  95. package/dist/types/Primitive/unique/Registry.d.ts +39 -0
  96. package/dist/types/Primitive/unique/index.d.ts +2 -0
  97. package/dist/types/Types.d.ts +9 -0
  98. package/dist/types/Unique/Capacity.d.ts +29 -0
  99. package/dist/types/Unique/Distinct.d.ts +95 -0
  100. package/dist/types/Unique/Key.d.ts +29 -0
  101. package/dist/types/Unique/Override.d.ts +16 -0
  102. package/dist/types/Unique/Strategy.d.ts +135 -0
  103. package/dist/types/index.d.ts +13 -0
  104. package/dist/types/internal.d.ts +1 -0
  105. package/package.json +2 -2
@@ -23,5 +23,6 @@ export { default as string } from "./string/index.js";
23
23
  export { default as symbol } from "./symbol/index.js";
24
24
  export { default as tuple } from "./tuple/index.js";
25
25
  export { default as undefinable } from "./undefinable/index.js";
26
+ export { default as unique } from "./unique/index.js";
26
27
  export { default as undefined } from "./undefined/index.js";
27
28
  export { __rspack_external__namespace_js_84cb9ec2 as Primitive };
@@ -0,0 +1,27 @@
1
+ import { continuousWithin, discreteWithin, toAdmittedEnds, toFiniteBound } from "../../Bound.js";
2
+ const label = ".admits on a number schema";
3
+ function toAdmits(meta, input) {
4
+ var _input_multipleOf, _meta_admits;
5
+ var _meta_whereby, _meta_whereby1, _meta_admits1;
6
+ const stated = {
7
+ min: null == (_meta_whereby = meta.whereby) ? void 0 : _meta_whereby.min,
8
+ max: null == (_meta_whereby1 = meta.whereby) ? void 0 : _meta_whereby1.max
9
+ };
10
+ const multipleOf = null != (_input_multipleOf = input.multipleOf) ? _input_multipleOf : null == (_meta_admits1 = meta.admits) ? void 0 : _meta_admits1.multipleOf;
11
+ const ends = toAdmittedEnds(label, void 0, null != (_meta_admits = meta.admits) ? _meta_admits : stated, toFabricable(meta, stated), input, (end, given)=>toFiniteBound(label, end, given), meta.integer ? discreteWithin : continuousWithin);
12
+ return void 0 === multipleOf ? ends : {
13
+ ...ends,
14
+ multipleOf
15
+ };
16
+ }
17
+ function toFabricable(meta, stated) {
18
+ if (meta.produce) return;
19
+ if (meta.sequence) return {
20
+ min: {
21
+ value: 1,
22
+ exclusive: false
23
+ }
24
+ };
25
+ return stated;
26
+ }
27
+ export { toAdmits };
@@ -1,13 +1,15 @@
1
1
  import { constrainContinuous, effectiveDiscrete } from "../../Bound.js";
2
2
  import { Distribution, discreteSampler, sampler } from "../../Distribution/index.js";
3
3
  import { toStreamFromTrace } from "../../Random/index.js";
4
- import { Kind, Meta } from "../../Types.js";
4
+ import { Claim, Kind, Meta } from "../../Types.js";
5
+ import { toNumberStrategy } from "../../Unique/Distinct.js";
6
+ import { toLifetimeScope } from "../../Unique/Strategy.js";
5
7
  import { unboundedContinuous, unboundedDiscrete } from "./Defaults.js";
6
8
  import { Schema } from "./Schema.js";
7
9
  function Fabricator(context) {
8
10
  var _ref, _ref1, _range_distribution;
9
11
  var _meta_whereby, _meta_whereby1, _meta_whereby2;
10
- const { schema, algorithm, trace } = context;
12
+ const { schema, algorithm, trace, exhaustion } = context;
11
13
  const meta = schema[Meta];
12
14
  const rehydrated = Schema({
13
15
  ...schema,
@@ -45,13 +47,23 @@ function Fabricator(context) {
45
47
  distribution: null == (_meta_whereby2 = meta.whereby) ? void 0 : _meta_whereby2.distribution
46
48
  };
47
49
  const distribution = null != (_range_distribution = range.distribution) ? _range_distribution : Distribution.uniform();
48
- if (meta.integer) {
49
- const draw = discreteSampler(distribution, effectiveDiscrete(range.min, range.max), stream);
50
+ const draw = meta.integer ? discreteSampler(distribution, effectiveDiscrete(range.min, range.max), stream) : constrainContinuous(sampler(distribution, {
51
+ min: range.min.value,
52
+ max: range.max.value
53
+ }, stream), range.min, range.max);
54
+ if (meta.unique) {
55
+ const scope = toLifetimeScope(toNumberStrategy({
56
+ label: "T.unique.number",
57
+ meta,
58
+ stream,
59
+ draw
60
+ }), exhaustion);
50
61
  return {
51
62
  [Kind]: "number",
52
63
  [Meta]: meta,
53
64
  trace,
54
- fabricate: ()=>draw(),
65
+ fabricate: ()=>scope.draw(),
66
+ [Claim]: scope.claim,
55
67
  schema: rehydrated
56
68
  };
57
69
  }
@@ -59,10 +71,7 @@ function Fabricator(context) {
59
71
  [Kind]: "number",
60
72
  [Meta]: meta,
61
73
  trace,
62
- fabricate: constrainContinuous(sampler(distribution, {
63
- min: range.min.value,
64
- max: range.max.value
65
- }, stream), range.min, range.max),
74
+ fabricate: draw,
66
75
  schema: rehydrated
67
76
  };
68
77
  }
@@ -1,6 +1,8 @@
1
1
  import { assertNonemptyContinuous, assertNonemptyDiscrete, toBound } from "../../Bound.js";
2
2
  import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
3
+ import { toRedraws } from "../../Unique/Strategy.js";
3
4
  import bigint from "../bigint/index.js";
5
+ import { unique } from "../bigint/Registry.js";
4
6
  import { unboundedContinuous, unboundedDiscrete } from "./Defaults.js";
5
7
  import { Schema } from "./Schema.js";
6
8
  function registry() {
@@ -14,7 +16,7 @@ function registry() {
14
16
  whereby: (whereby)=>Schema({
15
17
  [Kind]: "number",
16
18
  [Meta]: {
17
- whereby: toWhereby(whereby, false)
19
+ whereby: toWhereby("T.number", whereby, false)
18
20
  }
19
21
  }),
20
22
  get integer () {
@@ -29,7 +31,7 @@ function registry() {
29
31
  [Kind]: "number",
30
32
  [Meta]: {
31
33
  integer: true,
32
- whereby: toWhereby(whereby, true)
34
+ whereby: toWhereby("T.number", whereby, true)
33
35
  }
34
36
  }),
35
37
  get sequence () {
@@ -47,11 +49,59 @@ function registry() {
47
49
  };
48
50
  }
49
51
  const Registry = registry;
50
- function toWhereby(input, integer) {
52
+ function Registry_unique() {
53
+ return {
54
+ ...Schema({
55
+ [Kind]: "number",
56
+ [Meta]: {
57
+ unique: true
58
+ },
59
+ [Produces]: void 0,
60
+ [Adaptation]: void 0
61
+ }),
62
+ whereby: (whereby)=>Schema({
63
+ [Kind]: "number",
64
+ [Meta]: {
65
+ unique: true,
66
+ whereby: toUniqueWhereby("T.unique.number", whereby, false)
67
+ }
68
+ }),
69
+ get integer () {
70
+ return {
71
+ ...Schema({
72
+ [Kind]: "number",
73
+ [Meta]: {
74
+ integer: true,
75
+ unique: true
76
+ }
77
+ }),
78
+ whereby: (whereby)=>Schema({
79
+ [Kind]: "number",
80
+ [Meta]: {
81
+ integer: true,
82
+ unique: true,
83
+ whereby: toUniqueWhereby("T.unique.number", whereby, true)
84
+ }
85
+ }),
86
+ big: unique
87
+ };
88
+ }
89
+ };
90
+ }
91
+ function toUniqueWhereby(prefix, input, integer) {
92
+ const label = integer ? `${prefix}.integer.whereby` : `${prefix}.whereby`;
93
+ const whereby = toWhereby(prefix, input, integer);
94
+ const redraws = toRedraws(label, input.redraws);
95
+ return void 0 === redraws ? whereby : {
96
+ ...whereby,
97
+ redraws
98
+ };
99
+ }
100
+ function toWhereby(prefix, input, integer) {
51
101
  const min = void 0 === input.min ? void 0 : toBound(input.min);
52
102
  const max = void 0 === input.max ? void 0 : toBound(input.max);
53
103
  const defaults = integer ? unboundedDiscrete : unboundedContinuous;
54
- const label = integer ? "T.number.integer.whereby" : "T.number.whereby";
104
+ const label = integer ? `${prefix}.integer.whereby` : `${prefix}.whereby`;
55
105
  if (integer) assertNonemptyDiscrete(label, null != min ? min : defaults.min, null != max ? max : defaults.max);
56
106
  else assertNonemptyContinuous(label, null != min ? min : defaults.min, null != max ? max : defaults.max);
57
107
  return void 0 === input.distribution ? {
@@ -64,3 +114,4 @@ function toWhereby(input, integer) {
64
114
  };
65
115
  }
66
116
  export default Registry;
117
+ export { Registry_unique as unique };
@@ -1,16 +1,23 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
2
  import { schemaSatisfies } from "../../Schema/Satisfies.js";
3
3
  import { Kind, Meta } from "../../Types.js";
4
+ import { toAdmits } from "./Admits.js";
4
5
  function Schema(schema) {
5
6
  return {
6
7
  ...schema,
7
8
  [Kind]: "number",
8
- as: (produce, hints)=>Schema({
9
+ as: (produce)=>Schema({
9
10
  ...schema,
10
11
  [Meta]: {
11
12
  ...schema[Meta],
12
- produce,
13
- hints
13
+ produce
14
+ }
15
+ }),
16
+ admits: (admitted)=>Schema({
17
+ ...schema,
18
+ [Meta]: {
19
+ ...schema[Meta],
20
+ admits: toAdmits(schema[Meta], admitted)
14
21
  }
15
22
  }),
16
23
  satisfies: schemaSatisfies,
@@ -1,6 +1,7 @@
1
1
  import { FabricatorError } from "../../Error/index.js";
2
2
  import { toStreamFromTrace } from "../../Random/index.js";
3
3
  import { Children, Kind, Meta, Omitted } from "../../Types.js";
4
+ import { recordOverride } from "../../Unique/Override.js";
4
5
  import { isPollutionKey } from "../../Utility/Core.js";
5
6
  import { isObjectComputeFabricator } from "./compute/Fabricator.js";
6
7
  import { isObjectOmittableFabricator } from "./omittable/Fabricator.js";
@@ -57,6 +58,7 @@ function Fabricator(context, fields, hidden = {}) {
57
58
  if (isPollutionKey(k)) throw new FabricatorError.PrototypePollutionError(k);
58
59
  if (visible && overrides && k in overrides) {
59
60
  const value = overrides[k];
61
+ recordOverride(v, value);
60
62
  if (value === Omitted) continue;
61
63
  fabricated[k] = isObjectFabricator(v) ? v.fabricate(value, {
62
64
  validate: false
@@ -0,0 +1,42 @@
1
+ import { discreteWithin, toAdmittedEnds, toFiniteBound } from "../../Bound.js";
2
+ const label = ".admits on a record schema";
3
+ function toAdmits(meta, input) {
4
+ var _ref;
5
+ var _meta_admits;
6
+ return {
7
+ size: toAdmittedEnds(label, "size", null != (_ref = null == (_meta_admits = meta.admits) ? void 0 : _meta_admits.size) ? _ref : toStatedSize(meta), meta.produce ? void 0 : toFabricableSize(meta), input.size, (end, given)=>toFiniteBound(label, end, given), discreteWithin)
8
+ };
9
+ }
10
+ function toStatedSize(meta) {
11
+ if (meta.unique) {
12
+ const { size } = meta.whereby;
13
+ return {
14
+ min: size.min,
15
+ max: size.max
16
+ };
17
+ }
18
+ if (!meta.whereby) return {};
19
+ const { size } = meta.whereby;
20
+ return {
21
+ max: {
22
+ value: size.max,
23
+ exclusive: false
24
+ }
25
+ };
26
+ }
27
+ function toFabricableSize(meta) {
28
+ var _size_minTried;
29
+ if (meta.unique || !meta.whereby) return toStatedSize(meta);
30
+ const { size } = meta.whereby;
31
+ return {
32
+ min: {
33
+ value: (null != (_size_minTried = size.minTried) ? _size_minTried : 0) >= 1 ? 1 : 0,
34
+ exclusive: false
35
+ },
36
+ max: {
37
+ value: size.max,
38
+ exclusive: false
39
+ }
40
+ };
41
+ }
42
+ export { toAdmits, toStatedSize };
@@ -1,6 +1,9 @@
1
+ import { effectiveDiscrete } from "../../Bound.js";
1
2
  import { discreteSampler } from "../../Distribution/index.js";
2
3
  import { toStreamFromTrace } from "../../Random/index.js";
3
4
  import { Children, Kind, Meta } from "../../Types.js";
5
+ import { assertCapacity, toDistinct } from "../../Unique/Distinct.js";
6
+ import { withinCollection } from "../../Unique/Strategy.js";
4
7
  import { Schema } from "./Schema.js";
5
8
  function Fabricator(context, key, value) {
6
9
  const { schema, algorithm, trace } = context;
@@ -25,36 +28,63 @@ function Fabricator(context, key, value) {
25
28
  };
26
29
  }
27
30
  const stream = toStreamFromTrace(algorithm, trace);
28
- const { max, minTried = 0 } = meta.whereby.size;
31
+ const fabricate = meta.unique ? distinctly(key, value, stream, meta.whereby) : collapsing(key, value, stream, meta.whereby);
32
+ return {
33
+ [Kind]: "record",
34
+ [Meta]: meta,
35
+ trace,
36
+ [Children]: {
37
+ key,
38
+ value
39
+ },
40
+ fabricate: fabricate,
41
+ schema: rehydrated
42
+ };
43
+ }
44
+ function collapsing(key, value, stream, whereby) {
45
+ const { max, minTried = 0 } = whereby.size;
29
46
  const drawSize = discreteSampler(void 0, {
30
47
  min: minTried,
31
48
  max
32
49
  }, stream);
33
- const fabricate = ()=>{
50
+ const drawKey = withinCollection("record", key);
51
+ return ()=>{
34
52
  const size = drawSize();
35
53
  const fabricated = {};
36
54
  for(let i = 0; i < size; i++){
37
- const k = key.fabricate();
55
+ const k = drawKey();
38
56
  const v = value.fabricate();
39
- Object.defineProperty(fabricated, k, {
40
- value: v,
41
- enumerable: true,
42
- writable: true,
43
- configurable: true
44
- });
57
+ Fabricator_define(fabricated, k, v);
45
58
  }
46
59
  return fabricated;
47
60
  };
48
- return {
49
- [Kind]: "record",
50
- [Meta]: meta,
51
- trace,
52
- [Children]: {
53
- key,
54
- value
55
- },
56
- fabricate,
57
- schema: rehydrated
61
+ }
62
+ function distinctly(key, value, stream, whereby) {
63
+ const size = effectiveDiscrete(whereby.size.min, whereby.size.max);
64
+ const drawSize = discreteSampler(whereby.size.distribution, size, stream);
65
+ const distinct = toDistinct(key, stream, {
66
+ label: "T.unique.record",
67
+ redraws: whereby.redraws
68
+ });
69
+ assertCapacity("T.unique.record", distinct, size.max);
70
+ return ()=>{
71
+ const count = drawSize();
72
+ const scope = distinct.open();
73
+ const fabricated = {};
74
+ for(let i = 0; i < count; i++){
75
+ const k = scope.draw();
76
+ const v = value.fabricate();
77
+ Fabricator_define(fabricated, k, v);
78
+ }
79
+ return fabricated;
58
80
  };
59
81
  }
82
+ function Fabricator_define(fabricated, k, v) {
83
+ Object.defineProperty(fabricated, k, {
84
+ value: v,
85
+ enumerable: true,
86
+ writable: true,
87
+ configurable: true
88
+ });
89
+ }
60
90
  export { Fabricator };
@@ -1,5 +1,7 @@
1
+ import { toLengthRange } from "../../Bound.js";
1
2
  import { toSchema } from "../../Schema/Core.js";
2
3
  import { Kind, Meta } from "../../Types.js";
4
+ import { toRedraws } from "../../Unique/Strategy.js";
3
5
  import { Schema } from "./Schema.js";
4
6
  function Registry(key, value) {
5
7
  const normalizedKey = toSchema(key);
@@ -23,4 +25,31 @@ function Registry(key, value) {
23
25
  })
24
26
  };
25
27
  }
28
+ function unique(key, value) {
29
+ const normalizedKey = toSchema(key);
30
+ const normalizedValue = toSchema(value);
31
+ return {
32
+ whereby: (whereby)=>Schema({
33
+ [Kind]: "record",
34
+ [Meta]: {
35
+ whereby: toUniqueWhereby(whereby),
36
+ unique: true,
37
+ key: normalizedKey,
38
+ value: normalizedValue
39
+ }
40
+ })
41
+ };
42
+ }
43
+ function toUniqueWhereby(input) {
44
+ const label = "T.unique.record.whereby";
45
+ const size = toLengthRange(input.size, label);
46
+ const redraws = toRedraws(label, input.redraws);
47
+ return void 0 === redraws ? {
48
+ size
49
+ } : {
50
+ size,
51
+ redraws
52
+ };
53
+ }
26
54
  export default Registry;
55
+ export { unique };
@@ -1,6 +1,7 @@
1
1
  import { withAdaptations } from "../../Adapter/Core.js";
2
2
  import { schemaSatisfies } from "../../Schema/Satisfies.js";
3
3
  import { Kind, Meta } from "../../Types.js";
4
+ import { toAdmits } from "./Admits.js";
4
5
  function Schema(schema) {
5
6
  return {
6
7
  ...schema,
@@ -12,6 +13,13 @@ function Schema(schema) {
12
13
  produce
13
14
  }
14
15
  }),
16
+ admits: (admitted)=>Schema({
17
+ ...schema,
18
+ [Meta]: {
19
+ ...schema[Meta],
20
+ admits: toAdmits(schema[Meta], admitted)
21
+ }
22
+ }),
15
23
  satisfies: schemaSatisfies,
16
24
  adapt: (adapter, produce)=>Schema(withAdaptations(schema, adapter, produce))
17
25
  };
@@ -2,7 +2,7 @@ import { toStreamFromTrace } from "../../Random/index.js";
2
2
  import { Kind, Meta } from "../../Types.js";
3
3
  import { Schema } from "./Schema.js";
4
4
  function Fabricator(context, forkSource, make) {
5
- const { schema, algorithm, trace } = context;
5
+ const { schema, algorithm, trace, exhaustion } = context;
6
6
  const meta = schema[Meta];
7
7
  const rehydrated = Schema(schema);
8
8
  const stream = toStreamFromTrace(algorithm, trace);
@@ -19,7 +19,8 @@ function Fabricator(context, forkSource, make) {
19
19
  }),
20
20
  algorithm,
21
21
  fork: privateSource.fork,
22
- self: atMax ? void 0 : ()=>fabricateAt(depth + 1)
22
+ self: atMax ? void 0 : ()=>fabricateAt(depth + 1),
23
+ exhaustion
23
24
  };
24
25
  return make(target, [], context).fabricate();
25
26
  }
@@ -1,6 +1,7 @@
1
1
  import { FabricatorError } from "../../Error/index.js";
2
2
  import { Adaptation, Kind, Meta, Omitted } from "../../Types.js";
3
3
  import { never } from "../../Utility/Core.js";
4
+ import { toStatedSize } from "../record/Admits.js";
4
5
  function terminate(body) {
5
6
  return terminateAt(body, []);
6
7
  }
@@ -11,13 +12,20 @@ function terminateAt(schema, path) {
11
12
  throw new FabricatorError.UnterminableRecursiveError(path);
12
13
  case "array":
13
14
  {
15
+ var _meta_whereby;
14
16
  const s = schema;
15
- return containsSelf(s[Meta].definition) ? emptyArray() : schema;
17
+ if (!containsSelf(s[Meta].definition)) return schema;
18
+ const meta = s[Meta];
19
+ assertEmptiable(path, "length", meta.admits ? meta.admits.length : null == (_meta_whereby = meta.whereby) ? void 0 : _meta_whereby.length);
20
+ return emptyArray();
16
21
  }
17
22
  case "record":
18
23
  {
19
24
  const s = schema;
20
- return containsSelf(s[Meta].key) || containsSelf(s[Meta].value) ? emptyRecord() : schema;
25
+ if (!containsSelf(s[Meta].key) && !containsSelf(s[Meta].value)) return schema;
26
+ const meta = s[Meta];
27
+ assertEmptiable(path, "size", meta.admits ? meta.admits.size : toStatedSize(meta));
28
+ return emptyRecord();
21
29
  }
22
30
  case "choice":
23
31
  {
@@ -214,6 +222,12 @@ function containsSelf(schema) {
214
222
  return never(kind);
215
223
  }
216
224
  }
225
+ function assertEmptiable(path, key, stated) {
226
+ const min = null == stated ? void 0 : stated.min;
227
+ if (!min) return;
228
+ const smallest = min.exclusive ? min.value + 1 : min.value;
229
+ if (smallest > 0) throw new FabricatorError.UnsatisfiableRecursiveBoundError(path, key, smallest);
230
+ }
217
231
  function withMeta(schema, meta) {
218
232
  const adaptations = schema[Adaptation];
219
233
  return adaptations ? {
@@ -0,0 +1,26 @@
1
+ import { discreteWithin, toAdmittedEnds, toFiniteBound } from "../../Bound.js";
2
+ const label = ".admits on a string schema";
3
+ function toAdmits(meta, input) {
4
+ var _input_format, _input_pattern, _ref;
5
+ var _meta_whereby, _meta_admits, _meta_admits1, _meta_admits2;
6
+ const drawn = toEnds(null == (_meta_whereby = meta.whereby) ? void 0 : _meta_whereby.length);
7
+ const format = null != (_input_format = input.format) ? _input_format : null == (_meta_admits = meta.admits) ? void 0 : _meta_admits.format;
8
+ const pattern = null != (_input_pattern = input.pattern) ? _input_pattern : null == (_meta_admits1 = meta.admits) ? void 0 : _meta_admits1.pattern;
9
+ return {
10
+ ...void 0 === format ? {} : {
11
+ format
12
+ },
13
+ ...void 0 === pattern ? {} : {
14
+ pattern
15
+ },
16
+ length: toAdmittedEnds(label, "length", null != (_ref = null == (_meta_admits2 = meta.admits) ? void 0 : _meta_admits2.length) ? _ref : drawn, meta.produce ? void 0 : drawn, input.length, (end, given)=>toFiniteBound(label, end, given), discreteWithin)
17
+ };
18
+ }
19
+ function toEnds(length) {
20
+ if (!length) return {};
21
+ return {
22
+ min: length.min,
23
+ max: length.max
24
+ };
25
+ }
26
+ export { toAdmits };
@@ -0,0 +1,81 @@
1
+ import { effectiveDiscrete } from "../../Bound.js";
2
+ import { isDrawable } from "../../Distribution/index.js";
3
+ import { bmpScalars, toRanges, toSources } from "./Sources.js";
4
+ function toStringDomain(whereby) {
5
+ const characters = merge(toSources(whereby.composition).filter(([weight])=>isDrawable(weight)).flatMap(([, source])=>toRanges(source)));
6
+ const { min, max } = effectiveDiscrete(whereby.length.min, whereby.length.max);
7
+ const one = BigInt(count(characters, 0, 0xffff));
8
+ const two = BigInt(count(characters, 0x10000, 1 / 0));
9
+ const fillers = BigInt(bmpScalars.reduce((total, range)=>total + (range.to - range.from + 1) - count(characters, range.from, range.to), 0));
10
+ let capacity = BigInt(0);
11
+ let [f2, c2] = [
12
+ BigInt(0),
13
+ BigInt(0)
14
+ ];
15
+ let [f1, c1] = [
16
+ BigInt(1),
17
+ BigInt(0)
18
+ ];
19
+ for(let length = 0; length <= max; length++)if (length > 0) {
20
+ const f = one * f1 + two * f2;
21
+ const c = one * (c1 + f1) + two * (c2 + f2);
22
+ const filled = two > BigInt(0) ? fillers * (c1 + f1) : BigInt(0);
23
+ if (length >= min) capacity += f + filled;
24
+ [f2, c2, f1, c1] = [
25
+ f1,
26
+ c1,
27
+ f,
28
+ c
29
+ ];
30
+ } else if (0 === min) capacity += BigInt(1);
31
+ return {
32
+ capacity,
33
+ admits: (value)=>{
34
+ if ("string" != typeof value) return false;
35
+ if (value.length < min || value.length > max) return false;
36
+ let outside = 0;
37
+ for (const char of value)if (!contains(characters, char.codePointAt(0))) {
38
+ if (two === BigInt(0) || !contains(bmpScalars, char.codePointAt(0))) return false;
39
+ outside++;
40
+ }
41
+ return outside <= 1;
42
+ }
43
+ };
44
+ }
45
+ function merge(ranges) {
46
+ const sorted = [
47
+ ...ranges
48
+ ].sort((a, b)=>a.from - b.from);
49
+ const merged = [];
50
+ for (const range of sorted){
51
+ const last = merged[merged.length - 1];
52
+ if (last && range.from <= last.to + 1) merged[merged.length - 1] = {
53
+ from: last.from,
54
+ to: Math.max(last.to, range.to)
55
+ };
56
+ else merged.push(range);
57
+ }
58
+ return merged;
59
+ }
60
+ function count(ranges, from, to) {
61
+ return ranges.reduce((total, range)=>{
62
+ const low = Math.max(range.from, from);
63
+ const high = Math.min(range.to, to);
64
+ return high < low ? total : total + high - low + 1;
65
+ }, 0);
66
+ }
67
+ function contains(ranges, codepoint) {
68
+ let low = 0;
69
+ let high = ranges.length - 1;
70
+ while(low <= high){
71
+ const middle = low + high >> 1;
72
+ const range = ranges[middle];
73
+ if (codepoint < range.from) high = middle - 1;
74
+ else {
75
+ if (!(codepoint > range.to)) return true;
76
+ low = middle + 1;
77
+ }
78
+ }
79
+ return false;
80
+ }
81
+ export { toStringDomain };