arktype 1.0.27-alpha → 1.1.0-dev-1

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 (194) hide show
  1. package/dist/main.d.ts +1018 -0
  2. package/dist/main.js +1450 -0
  3. package/package.json +36 -108
  4. package/LICENSE +0 -7
  5. package/README.md +0 -351
  6. package/dist/cjs/main.js +0 -38
  7. package/dist/cjs/nodes/branch.js +0 -140
  8. package/dist/cjs/nodes/compose.js +0 -163
  9. package/dist/cjs/nodes/discriminate.js +0 -265
  10. package/dist/cjs/nodes/node.js +0 -139
  11. package/dist/cjs/nodes/predicate.js +0 -86
  12. package/dist/cjs/nodes/rules/class.js +0 -25
  13. package/dist/cjs/nodes/rules/collapsibleSet.js +0 -48
  14. package/dist/cjs/nodes/rules/divisor.js +0 -29
  15. package/dist/cjs/nodes/rules/props.js +0 -167
  16. package/dist/cjs/nodes/rules/range.js +0 -105
  17. package/dist/cjs/nodes/rules/regex.js +0 -26
  18. package/dist/cjs/nodes/rules/rules.js +0 -123
  19. package/dist/cjs/package.json +0 -3
  20. package/dist/cjs/parse/ast/ast.js +0 -4
  21. package/dist/cjs/parse/ast/bound.js +0 -16
  22. package/dist/cjs/parse/ast/config.js +0 -13
  23. package/dist/cjs/parse/ast/distributableFunction.js +0 -48
  24. package/dist/cjs/parse/ast/divisor.js +0 -9
  25. package/dist/cjs/parse/ast/intersection.js +0 -30
  26. package/dist/cjs/parse/ast/keyof.js +0 -111
  27. package/dist/cjs/parse/ast/morph.js +0 -58
  28. package/dist/cjs/parse/ast/narrow.js +0 -22
  29. package/dist/cjs/parse/ast/node.js +0 -4
  30. package/dist/cjs/parse/ast/tuple.js +0 -94
  31. package/dist/cjs/parse/ast/union.js +0 -9
  32. package/dist/cjs/parse/ast/utils.js +0 -4
  33. package/dist/cjs/parse/definition.js +0 -61
  34. package/dist/cjs/parse/record.js +0 -37
  35. package/dist/cjs/parse/string/reduce/dynamic.js +0 -167
  36. package/dist/cjs/parse/string/reduce/shared.js +0 -23
  37. package/dist/cjs/parse/string/reduce/static.js +0 -4
  38. package/dist/cjs/parse/string/shift/operand/enclosed.js +0 -54
  39. package/dist/cjs/parse/string/shift/operand/operand.js +0 -11
  40. package/dist/cjs/parse/string/shift/operand/unenclosed.js +0 -53
  41. package/dist/cjs/parse/string/shift/operator/bounds.js +0 -87
  42. package/dist/cjs/parse/string/shift/operator/divisor.js +0 -35
  43. package/dist/cjs/parse/string/shift/operator/operator.js +0 -26
  44. package/dist/cjs/parse/string/shift/scanner.js +0 -114
  45. package/dist/cjs/parse/string/string.js +0 -43
  46. package/dist/cjs/scopes/ark.js +0 -45
  47. package/dist/cjs/scopes/cache.js +0 -52
  48. package/dist/cjs/scopes/expressions.js +0 -29
  49. package/dist/cjs/scopes/jsObjects.js +0 -93
  50. package/dist/cjs/scopes/scope.js +0 -323
  51. package/dist/cjs/scopes/tsKeywords.js +0 -113
  52. package/dist/cjs/scopes/type.js +0 -50
  53. package/dist/cjs/scopes/validation/creditCard.js +0 -47
  54. package/dist/cjs/scopes/validation/date.js +0 -62
  55. package/dist/cjs/scopes/validation/validation.js +0 -108
  56. package/dist/cjs/traverse/problems.js +0 -281
  57. package/dist/cjs/traverse/traverse.js +0 -390
  58. package/dist/cjs/utils/chainableNoOpProxy.js +0 -23
  59. package/dist/cjs/utils/data.js +0 -53
  60. package/dist/cjs/utils/domains.js +0 -30
  61. package/dist/cjs/utils/errors.js +0 -26
  62. package/dist/cjs/utils/freeze.js +0 -15
  63. package/dist/cjs/utils/generics.js +0 -63
  64. package/dist/cjs/utils/numericLiterals.js +0 -75
  65. package/dist/cjs/utils/objectKinds.js +0 -69
  66. package/dist/cjs/utils/paths.js +0 -32
  67. package/dist/cjs/utils/serialize.js +0 -74
  68. package/dist/cjs/utils/unionToTuple.js +0 -4
  69. package/dist/mjs/main.js +0 -8
  70. package/dist/mjs/nodes/branch.js +0 -123
  71. package/dist/mjs/nodes/compose.js +0 -141
  72. package/dist/mjs/nodes/discriminate.js +0 -250
  73. package/dist/mjs/nodes/node.js +0 -117
  74. package/dist/mjs/nodes/predicate.js +0 -69
  75. package/dist/mjs/nodes/rules/class.js +0 -11
  76. package/dist/mjs/nodes/rules/collapsibleSet.js +0 -34
  77. package/dist/mjs/nodes/rules/divisor.js +0 -15
  78. package/dist/mjs/nodes/rules/props.js +0 -149
  79. package/dist/mjs/nodes/rules/range.js +0 -86
  80. package/dist/mjs/nodes/rules/regex.js +0 -11
  81. package/dist/mjs/nodes/rules/rules.js +0 -106
  82. package/dist/mjs/package.json +0 -3
  83. package/dist/mjs/parse/ast/ast.js +0 -1
  84. package/dist/mjs/parse/ast/bound.js +0 -2
  85. package/dist/mjs/parse/ast/config.js +0 -9
  86. package/dist/mjs/parse/ast/distributableFunction.js +0 -34
  87. package/dist/mjs/parse/ast/divisor.js +0 -1
  88. package/dist/mjs/parse/ast/intersection.js +0 -16
  89. package/dist/mjs/parse/ast/keyof.js +0 -103
  90. package/dist/mjs/parse/ast/morph.js +0 -44
  91. package/dist/mjs/parse/ast/narrow.js +0 -14
  92. package/dist/mjs/parse/ast/node.js +0 -1
  93. package/dist/mjs/parse/ast/tuple.js +0 -80
  94. package/dist/mjs/parse/ast/union.js +0 -1
  95. package/dist/mjs/parse/ast/utils.js +0 -1
  96. package/dist/mjs/parse/definition.js +0 -46
  97. package/dist/mjs/parse/record.js +0 -29
  98. package/dist/mjs/parse/string/reduce/dynamic.js +0 -159
  99. package/dist/mjs/parse/string/reduce/shared.js +0 -6
  100. package/dist/mjs/parse/string/reduce/static.js +0 -1
  101. package/dist/mjs/parse/string/shift/operand/enclosed.js +0 -39
  102. package/dist/mjs/parse/string/shift/operand/operand.js +0 -3
  103. package/dist/mjs/parse/string/shift/operand/unenclosed.js +0 -36
  104. package/dist/mjs/parse/string/shift/operator/bounds.js +0 -70
  105. package/dist/mjs/parse/string/shift/operator/divisor.js +0 -21
  106. package/dist/mjs/parse/string/shift/operator/operator.js +0 -13
  107. package/dist/mjs/parse/string/shift/scanner.js +0 -106
  108. package/dist/mjs/parse/string/string.js +0 -28
  109. package/dist/mjs/scopes/ark.js +0 -28
  110. package/dist/mjs/scopes/cache.js +0 -38
  111. package/dist/mjs/scopes/expressions.js +0 -89
  112. package/dist/mjs/scopes/jsObjects.js +0 -82
  113. package/dist/mjs/scopes/scope.js +0 -303
  114. package/dist/mjs/scopes/tsKeywords.js +0 -116
  115. package/dist/mjs/scopes/type.js +0 -35
  116. package/dist/mjs/scopes/validation/creditCard.js +0 -34
  117. package/dist/mjs/scopes/validation/date.js +0 -48
  118. package/dist/mjs/scopes/validation/validation.js +0 -112
  119. package/dist/mjs/traverse/problems.js +0 -260
  120. package/dist/mjs/traverse/traverse.js +0 -373
  121. package/dist/mjs/utils/chainableNoOpProxy.js +0 -15
  122. package/dist/mjs/utils/data.js +0 -38
  123. package/dist/mjs/utils/domains.js +0 -15
  124. package/dist/mjs/utils/errors.js +0 -10
  125. package/dist/mjs/utils/freeze.js +0 -7
  126. package/dist/mjs/utils/generics.js +0 -38
  127. package/dist/mjs/utils/numericLiterals.js +0 -72
  128. package/dist/mjs/utils/objectKinds.js +0 -55
  129. package/dist/mjs/utils/paths.js +0 -18
  130. package/dist/mjs/utils/serialize.js +0 -58
  131. package/dist/mjs/utils/unionToTuple.js +0 -1
  132. package/dist/tsconfig.temp.tsbuildinfo +0 -1
  133. package/dist/types/main.d.ts +0 -15
  134. package/dist/types/nodes/branch.d.ts +0 -29
  135. package/dist/types/nodes/compose.d.ts +0 -98
  136. package/dist/types/nodes/discriminate.d.ts +0 -26
  137. package/dist/types/nodes/node.d.ts +0 -69
  138. package/dist/types/nodes/predicate.d.ts +0 -18
  139. package/dist/types/nodes/rules/class.d.ts +0 -4
  140. package/dist/types/nodes/rules/collapsibleSet.d.ts +0 -4
  141. package/dist/types/nodes/rules/divisor.d.ts +0 -3
  142. package/dist/types/nodes/rules/props.d.ts +0 -43
  143. package/dist/types/nodes/rules/range.d.ts +0 -34
  144. package/dist/types/nodes/rules/regex.d.ts +0 -5
  145. package/dist/types/nodes/rules/rules.d.ts +0 -33
  146. package/dist/types/parse/ast/ast.d.ts +0 -24
  147. package/dist/types/parse/ast/bound.d.ts +0 -27
  148. package/dist/types/parse/ast/config.d.ts +0 -15
  149. package/dist/types/parse/ast/distributableFunction.d.ts +0 -18
  150. package/dist/types/parse/ast/divisor.d.ts +0 -13
  151. package/dist/types/parse/ast/intersection.d.ts +0 -31
  152. package/dist/types/parse/ast/keyof.d.ts +0 -10
  153. package/dist/types/parse/ast/morph.d.ts +0 -17
  154. package/dist/types/parse/ast/narrow.d.ts +0 -21
  155. package/dist/types/parse/ast/node.d.ts +0 -35
  156. package/dist/types/parse/ast/tuple.d.ts +0 -41
  157. package/dist/types/parse/ast/union.d.ts +0 -17
  158. package/dist/types/parse/ast/utils.d.ts +0 -7
  159. package/dist/types/parse/definition.d.ts +0 -30
  160. package/dist/types/parse/record.d.ts +0 -26
  161. package/dist/types/parse/string/reduce/dynamic.d.ts +0 -34
  162. package/dist/types/parse/string/reduce/shared.d.ts +0 -25
  163. package/dist/types/parse/string/reduce/static.d.ts +0 -130
  164. package/dist/types/parse/string/shift/operand/enclosed.d.ts +0 -28
  165. package/dist/types/parse/string/shift/operand/operand.d.ts +0 -9
  166. package/dist/types/parse/string/shift/operand/unenclosed.d.ts +0 -18
  167. package/dist/types/parse/string/shift/operator/bounds.d.ts +0 -21
  168. package/dist/types/parse/string/shift/operator/divisor.d.ts +0 -13
  169. package/dist/types/parse/string/shift/operator/operator.d.ts +0 -13
  170. package/dist/types/parse/string/shift/scanner.d.ts +0 -89
  171. package/dist/types/parse/string/string.d.ts +0 -25
  172. package/dist/types/scopes/ark.d.ts +0 -208
  173. package/dist/types/scopes/cache.d.ts +0 -14
  174. package/dist/types/scopes/expressions.d.ts +0 -136
  175. package/dist/types/scopes/jsObjects.d.ts +0 -26
  176. package/dist/types/scopes/scope.d.ts +0 -99
  177. package/dist/types/scopes/tsKeywords.d.ts +0 -50
  178. package/dist/types/scopes/type.d.ts +0 -67
  179. package/dist/types/scopes/validation/creditCard.d.ts +0 -2
  180. package/dist/types/scopes/validation/date.d.ts +0 -23
  181. package/dist/types/scopes/validation/validation.d.ts +0 -49
  182. package/dist/types/traverse/problems.d.ts +0 -88
  183. package/dist/types/traverse/traverse.d.ts +0 -55
  184. package/dist/types/utils/chainableNoOpProxy.d.ts +0 -14
  185. package/dist/types/utils/data.d.ts +0 -13
  186. package/dist/types/utils/domains.d.ts +0 -32
  187. package/dist/types/utils/errors.d.ts +0 -6
  188. package/dist/types/utils/freeze.d.ts +0 -2
  189. package/dist/types/utils/generics.d.ts +0 -125
  190. package/dist/types/utils/numericLiterals.d.ts +0 -46
  191. package/dist/types/utils/objectKinds.d.ts +0 -84
  192. package/dist/types/utils/paths.d.ts +0 -9
  193. package/dist/types/utils/serialize.d.ts +0 -37
  194. package/dist/types/utils/unionToTuple.d.ts +0 -11
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- collapsibleListUnion: ()=>collapsibleListUnion,
13
- listUnion: ()=>listUnion
14
- });
15
- const _composeJs = require("../compose.js");
16
- const collapsibleListUnion = (l, r)=>{
17
- if (Array.isArray(l)) {
18
- if (Array.isArray(r)) {
19
- const result = listUnion(l, r);
20
- return result.length === l.length ? result.length === r.length ? (0, _composeJs.equality)() : l : result.length === r.length ? r : result;
21
- }
22
- return l.includes(r) ? l : [
23
- ...l,
24
- r
25
- ];
26
- }
27
- if (Array.isArray(r)) {
28
- return r.includes(l) ? r : [
29
- ...r,
30
- l
31
- ];
32
- }
33
- return l === r ? (0, _composeJs.equality)() : [
34
- l,
35
- r
36
- ];
37
- };
38
- const listUnion = (l, r)=>{
39
- const result = [
40
- ...l
41
- ];
42
- for (const expression of r){
43
- if (!l.includes(expression)) {
44
- result.push(expression);
45
- }
46
- }
47
- return result;
48
- };
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- divisorIntersection: ()=>divisorIntersection,
13
- checkDivisor: ()=>checkDivisor
14
- });
15
- const _composeJs = require("../compose.js");
16
- const divisorIntersection = (0, _composeJs.composeIntersection)((l, r)=>l === r ? (0, _composeJs.equality)() : Math.abs(l * r / greatestCommonDivisor(l, r)));
17
- // https://en.wikipedia.org/wiki/Euclidean_algorithm
18
- const greatestCommonDivisor = (l, r)=>{
19
- let previous;
20
- let greatestCommonDivisor = l;
21
- let current = r;
22
- while(current !== 0){
23
- previous = current;
24
- current = greatestCommonDivisor % current;
25
- greatestCommonDivisor = previous;
26
- }
27
- return greatestCommonDivisor;
28
- };
29
- const checkDivisor = (divisor, state)=>state.data % divisor === 0 || !state.problems.add("divisor", divisor);
@@ -1,167 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- isOptional: ()=>isOptional,
13
- isPrerequisite: ()=>isPrerequisite,
14
- mappedKeys: ()=>mappedKeys,
15
- propToNode: ()=>propToNode,
16
- propsIntersection: ()=>propsIntersection,
17
- flattenProps: ()=>flattenProps
18
- });
19
- const _composeJs = require("../compose.js");
20
- const _nodeJs = require("../node.js");
21
- const isOptional = (prop)=>prop[0] === "?";
22
- const isPrerequisite = (prop)=>prop[0] === "!";
23
- const mappedKeys = {
24
- index: "[index]"
25
- };
26
- const propToNode = (prop)=>isOptional(prop) || isPrerequisite(prop) ? prop[1] : prop;
27
- const getTupleLengthIfPresent = (result)=>{
28
- if (typeof result.length === "object" && isPrerequisite(result.length) && typeof result.length[1] !== "string" && (0, _nodeJs.isLiteralNode)(result.length[1], "number")) {
29
- return result.length[1].number.value;
30
- }
31
- };
32
- const propsIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
33
- const result = propKeysIntersection(l, r, state);
34
- if (typeof result === "symbol") {
35
- return result;
36
- }
37
- const lengthValue = getTupleLengthIfPresent(result);
38
- if (lengthValue === undefined || !(mappedKeys.index in result)) {
39
- return result;
40
- }
41
- // if we are at this point, we have an array with an exact length (i.e.
42
- // a tuple) and an index signature. Intersection each tuple item with
43
- // the index signature node and remove the index signature via a new
44
- // updated result, copied from result to avoid mutating existing references.
45
- const { [mappedKeys.index]: indexProp , ...updatedResult } = result;
46
- const indexNode = propToNode(indexProp);
47
- for(let i = 0; i < lengthValue; i++){
48
- if (!updatedResult[i]) {
49
- updatedResult[i] = indexNode;
50
- continue;
51
- }
52
- const existingNodeAtIndex = propToNode(updatedResult[i]);
53
- state.path.push(`${i}`);
54
- const updatedResultAtIndex = (0, _nodeJs.nodeIntersection)(existingNodeAtIndex, indexNode, state);
55
- state.path.pop();
56
- if ((0, _composeJs.isDisjoint)(updatedResultAtIndex)) {
57
- return updatedResultAtIndex;
58
- } else if (!(0, _composeJs.isEquality)(updatedResultAtIndex) && updatedResultAtIndex !== existingNodeAtIndex) {
59
- updatedResult[i] = updatedResultAtIndex;
60
- }
61
- }
62
- return updatedResult;
63
- });
64
- const propKeysIntersection = (0, _composeJs.composeKeyedIntersection)((propKey, l, r, context)=>{
65
- if (l === undefined) {
66
- return r === undefined ? (0, _composeJs.equality)() : r;
67
- }
68
- if (r === undefined) {
69
- return l;
70
- }
71
- context.path.push(propKey);
72
- const previousLOptional = context.lOptional;
73
- const previousROptional = context.rOptional;
74
- (_context = context).lOptional || (_context.lOptional = isOptional(l));
75
- (_context1 = context).rOptional || (_context1.rOptional = isOptional(r));
76
- const result = (0, _nodeJs.nodeIntersection)(propToNode(l), propToNode(r), context);
77
- const resultIsOptional = context.lOptional && context.rOptional;
78
- context.rOptional = previousROptional;
79
- context.lOptional = previousLOptional;
80
- context.path.pop();
81
- if ((0, _composeJs.isDisjoint)(result) && resultIsOptional) {
82
- var _context, _context1;
83
- // If an optional key has an empty intersection, the type can
84
- // still be satisfied as long as the key is not included. Set
85
- // the node to never rather than invalidating the type.
86
- return {};
87
- }
88
- return result;
89
- }, {
90
- onEmpty: "bubble"
91
- });
92
- const flattenProps = (entries, props, ctx)=>{
93
- const keyConfig = ctx.type.config?.keys ?? ctx.type.scope.config.keys;
94
- return keyConfig === "loose" ? flattenLooseProps(entries, props, ctx) : flattenPropsRecord(keyConfig, entries, props, ctx);
95
- };
96
- const flattenLooseProps = (entries, props, ctx)=>{
97
- // if we don't care about extraneous keys, flatten props so we can iterate over the definitions directly
98
- for(const k in props){
99
- const prop = props[k];
100
- ctx.path.push(k);
101
- if (k === mappedKeys.index) {
102
- entries.push([
103
- "indexProp",
104
- (0, _nodeJs.flattenNode)(propToNode(prop), ctx)
105
- ]);
106
- } else if (isOptional(prop)) {
107
- entries.push([
108
- "optionalProp",
109
- [
110
- k,
111
- (0, _nodeJs.flattenNode)(prop[1], ctx)
112
- ]
113
- ]);
114
- } else if (isPrerequisite(prop)) {
115
- entries.push([
116
- "prerequisiteProp",
117
- [
118
- k,
119
- (0, _nodeJs.flattenNode)(prop[1], ctx)
120
- ]
121
- ]);
122
- } else {
123
- entries.push([
124
- "requiredProp",
125
- [
126
- k,
127
- (0, _nodeJs.flattenNode)(prop, ctx)
128
- ]
129
- ]);
130
- }
131
- ctx.path.pop();
132
- }
133
- };
134
- const flattenPropsRecord = (kind, entries, props, ctx)=>{
135
- const result = {
136
- required: {},
137
- optional: {}
138
- };
139
- // if we need to keep track of extraneous keys, either to add problems or
140
- // remove them, store the props as a Record to optimize for presence
141
- // checking as we iterate over the data
142
- for(const k in props){
143
- const prop = props[k];
144
- ctx.path.push(k);
145
- if (k === mappedKeys.index) {
146
- result.index = (0, _nodeJs.flattenNode)(propToNode(prop), ctx);
147
- } else if (isOptional(prop)) {
148
- result.optional[k] = (0, _nodeJs.flattenNode)(prop[1], ctx);
149
- } else if (isPrerequisite(prop)) {
150
- // we still have to push prerequisite props as normal entries so they can be checked first
151
- entries.push([
152
- "prerequisiteProp",
153
- [
154
- k,
155
- (0, _nodeJs.flattenNode)(prop[1], ctx)
156
- ]
157
- ]);
158
- } else {
159
- result.required[k] = (0, _nodeJs.flattenNode)(prop, ctx);
160
- }
161
- ctx.path.pop();
162
- }
163
- entries.push([
164
- `${kind}Props`,
165
- result
166
- ]);
167
- };
@@ -1,105 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- minComparators: ()=>minComparators,
13
- maxComparators: ()=>maxComparators,
14
- isEqualityRange: ()=>isEqualityRange,
15
- rangeIntersection: ()=>rangeIntersection,
16
- flattenRange: ()=>flattenRange,
17
- checkBound: ()=>checkBound,
18
- compareStrictness: ()=>compareStrictness
19
- });
20
- const _dataJs = require("../../utils/data.js");
21
- const _composeJs = require("../compose.js");
22
- const minComparators = {
23
- ">": true,
24
- ">=": true
25
- };
26
- const maxComparators = {
27
- "<": true,
28
- "<=": true
29
- };
30
- const isEqualityRange = (range)=>"comparator" in range;
31
- const rangeIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
32
- if (isEqualityRange(l)) {
33
- if (isEqualityRange(r)) {
34
- return l.limit === r.limit ? (0, _composeJs.equality)() : state.addDisjoint("range", l, r);
35
- }
36
- return rangeAllows(r, l.limit) ? l : state.addDisjoint("range", l, r);
37
- }
38
- if (isEqualityRange(r)) {
39
- return rangeAllows(l, r.limit) ? r : state.addDisjoint("range", l, r);
40
- }
41
- const stricterMin = compareStrictness("min", l.min, r.min);
42
- const stricterMax = compareStrictness("max", l.max, r.max);
43
- if (stricterMin === "l") {
44
- if (stricterMax === "r") {
45
- return compareStrictness("min", l.min, r.max) === "l" ? state.addDisjoint("range", l, r) : {
46
- min: l.min,
47
- max: r.max
48
- };
49
- }
50
- return l;
51
- }
52
- if (stricterMin === "r") {
53
- if (stricterMax === "l") {
54
- return compareStrictness("max", l.max, r.min) === "l" ? state.addDisjoint("range", l, r) : {
55
- min: r.min,
56
- max: l.max
57
- };
58
- }
59
- return r;
60
- }
61
- return stricterMax === "l" ? l : stricterMax === "r" ? r : (0, _composeJs.equality)();
62
- });
63
- const rangeAllows = (range, n)=>isEqualityRange(range) ? n === range.limit : minAllows(range.min, n) && maxAllows(range.max, n);
64
- const minAllows = (min, n)=>!min || n > min.limit || n === min.limit && !isExclusive(min.comparator);
65
- const maxAllows = (max, n)=>!max || n < max.limit || n === max.limit && !isExclusive(max.comparator);
66
- const flattenRange = (entries, range, ctx)=>{
67
- const units = ctx.lastDomain === "string" ? "characters" : ctx.lastDomain === "object" ? "items long" : undefined;
68
- if (isEqualityRange(range)) {
69
- return entries.push([
70
- "bound",
71
- units ? {
72
- ...range,
73
- units
74
- } : range
75
- ]);
76
- }
77
- if (range.min) {
78
- entries.push([
79
- "bound",
80
- units ? {
81
- ...range.min,
82
- units
83
- } : range.min
84
- ]);
85
- }
86
- if (range.max) {
87
- entries.push([
88
- "bound",
89
- units ? {
90
- ...range.max,
91
- units
92
- } : range.max
93
- ]);
94
- }
95
- };
96
- const checkBound = (bound, state)=>comparatorCheckers[bound.comparator]((0, _dataJs.sizeOf)(state.data), bound.limit) || !state.problems.add("bound", bound);
97
- const comparatorCheckers = {
98
- "<": (size, limit)=>size < limit,
99
- ">": (size, limit)=>size > limit,
100
- "<=": (size, limit)=>size <= limit,
101
- ">=": (size, limit)=>size >= limit,
102
- "==": (size, limit)=>size === limit
103
- };
104
- const compareStrictness = (kind, l, r)=>!l ? !r ? "=" : "r" : !r ? "l" : l.limit === r.limit ? isExclusive(l.comparator) ? isExclusive(r.comparator) ? "=" : "l" : isExclusive(r.comparator) ? "r" : "=" : kind === "min" ? l.limit > r.limit ? "l" : "r" : l.limit < r.limit ? "l" : "r";
105
- const isExclusive = (comparator)=>comparator.length === 1;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- getRegex: ()=>getRegex,
13
- checkRegex: ()=>checkRegex,
14
- regexIntersection: ()=>regexIntersection
15
- });
16
- const _composeJs = require("../compose.js");
17
- const _collapsibleSetJs = require("./collapsibleSet.js");
18
- const regexCache = {};
19
- const getRegex = (source)=>{
20
- if (!regexCache[source]) {
21
- regexCache[source] = new RegExp(source);
22
- }
23
- return regexCache[source];
24
- };
25
- const checkRegex = (source, state)=>getRegex(source).test(state.data) || !state.problems.add("regex", `/${source}/`);
26
- const regexIntersection = (0, _composeJs.composeIntersection)(_collapsibleSetJs.collapsibleListUnion);
@@ -1,123 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- rulesIntersection: ()=>rulesIntersection,
13
- narrowableRulesIntersection: ()=>narrowableRulesIntersection,
14
- flattenRules: ()=>flattenRules,
15
- precedenceMap: ()=>precedenceMap,
16
- literalSatisfiesRules: ()=>literalSatisfiesRules
17
- });
18
- const _genericsJs = require("../../utils/generics.js");
19
- const _composeJs = require("../compose.js");
20
- const _classJs = require("./class.js");
21
- const _collapsibleSetJs = require("./collapsibleSet.js");
22
- const _divisorJs = require("./divisor.js");
23
- const _propsJs = require("./props.js");
24
- const _rangeJs = require("./range.js");
25
- const _regexJs = require("./regex.js");
26
- const rulesIntersection = (l, r, state)=>"value" in l ? "value" in r ? l.value === r.value ? (0, _composeJs.equality)() : state.addDisjoint("value", l.value, r.value) : literalSatisfiesRules(l.value, r, state) ? l : state.addDisjoint("leftAssignability", l, r) : "value" in r ? literalSatisfiesRules(r.value, l, state) ? r : state.addDisjoint("rightAssignability", l, r) : narrowableRulesIntersection(l, r, state);
27
- const narrowIntersection = (0, _composeJs.composeIntersection)(_collapsibleSetJs.collapsibleListUnion);
28
- const narrowableRulesIntersection = (0, _composeJs.composeKeyedIntersection)({
29
- divisor: _divisorJs.divisorIntersection,
30
- regex: _regexJs.regexIntersection,
31
- props: _propsJs.propsIntersection,
32
- class: _classJs.classIntersection,
33
- range: _rangeJs.rangeIntersection,
34
- narrow: narrowIntersection
35
- }, {
36
- onEmpty: "bubble"
37
- });
38
- const flattenRules = (rules, ctx)=>{
39
- const entries = [];
40
- let k;
41
- for(k in rules){
42
- ruleFlatteners[k](entries, rules[k], ctx);
43
- }
44
- // Some entries with the same precedence, e.g. morphs flattened from a list,
45
- // rely on the fact that JS's builtin sort is stable to behave as expected
46
- // when traversed:
47
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
48
- return entries.sort((l, r)=>precedenceMap[l[0]] - precedenceMap[r[0]]);
49
- };
50
- const ruleFlatteners = {
51
- regex: (entries, rule)=>{
52
- for (const source of (0, _genericsJs.listFrom)(rule)){
53
- entries.push([
54
- "regex",
55
- source
56
- ]);
57
- }
58
- },
59
- divisor: (entries, rule)=>{
60
- entries.push([
61
- "divisor",
62
- rule
63
- ]);
64
- },
65
- range: _rangeJs.flattenRange,
66
- class: (entries, rule)=>{
67
- entries.push([
68
- "class",
69
- rule
70
- ]);
71
- },
72
- props: _propsJs.flattenProps,
73
- narrow: (entries, rule)=>{
74
- for (const narrow of (0, _genericsJs.listFrom)(rule)){
75
- entries.push([
76
- "narrow",
77
- narrow
78
- ]);
79
- }
80
- },
81
- value: (entries, rule)=>{
82
- entries.push([
83
- "value",
84
- rule
85
- ]);
86
- }
87
- };
88
- const precedenceMap = {
89
- // Config: Applies before any checks
90
- config: -1,
91
- // Critical: No other checks are performed if these fail
92
- domain: 0,
93
- value: 0,
94
- domains: 0,
95
- branches: 0,
96
- switch: 0,
97
- alias: 0,
98
- class: 0,
99
- // Shallow: All shallow checks will be performed even if one or more fail
100
- regex: 1,
101
- divisor: 1,
102
- bound: 1,
103
- // Prerequisite: These are deep checks with special priority, e.g. the
104
- // length of a tuple, which causes other deep props not to be checked if it
105
- // is invalid
106
- prerequisiteProp: 2,
107
- // Deep: Performed if all shallow checks pass, even if one or more deep checks fail
108
- distilledProps: 3,
109
- strictProps: 3,
110
- requiredProp: 3,
111
- optionalProp: 3,
112
- indexProp: 3,
113
- // Narrow: Only performed if all shallow and deep checks pass
114
- narrow: 4,
115
- // Morph: Only performed if all validation passes
116
- morph: 5
117
- };
118
- const literalSatisfiesRules = (data, rules, state)=>!state.type.scope.type([
119
- "node",
120
- {
121
- [state.domain]: rules
122
- }
123
- ])(data).problems;
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- writeDoubleRightBoundMessage: ()=>writeDoubleRightBoundMessage,
13
- writeUnboundableMessage: ()=>writeUnboundableMessage
14
- });
15
- const writeDoubleRightBoundMessage = (root)=>`Expression ${root} must have at most one right bound`;
16
- const writeUnboundableMessage = (root)=>`Bounded expression ${root} must be a number, string or array`;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "parseConfigTuple", {
6
- enumerable: true,
7
- get: ()=>parseConfigTuple
8
- });
9
- const _definitionJs = require("../definition.js");
10
- const parseConfigTuple = (def, ctx)=>({
11
- node: ctx.type.scope.resolveTypeNode((0, _definitionJs.parseDefinition)(def[0], ctx)),
12
- config: def[2]
13
- });
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- writeMalformedDistributableFunctionMessage: ()=>writeMalformedDistributableFunctionMessage,
13
- distributeFunctionToNode: ()=>distributeFunctionToNode
14
- });
15
- const _domainsJs = require("../../utils/domains.js");
16
- const _errorsJs = require("../../utils/errors.js");
17
- const _genericsJs = require("../../utils/generics.js");
18
- const _serializeJs = require("../../utils/serialize.js");
19
- const writeMalformedDistributableFunctionMessage = (def)=>`Expected a Function or Record<Domain, Function> operand (${(0, _serializeJs.stringify)(def)} was invalid)`;
20
- const distributeFunctionToNode = (distributableFunction, node, ctx, ruleKey)=>{
21
- const domains = (0, _genericsJs.objectKeysOf)(node);
22
- if (!(0, _domainsJs.hasDomain)(distributableFunction, "object")) {
23
- return (0, _errorsJs.throwParseError)(writeMalformedDistributableFunctionMessage(distributableFunction));
24
- }
25
- const distributed = {};
26
- if (typeof distributableFunction === "function") {
27
- const domainFunction = {
28
- [ruleKey]: distributableFunction
29
- };
30
- for (const domain of domains){
31
- distributed[domain] = domainFunction;
32
- }
33
- } else {
34
- for (const domain of domains){
35
- if (distributableFunction[domain] === undefined) {
36
- continue;
37
- }
38
- const functionInDomain = {
39
- [ruleKey]: distributableFunction[domain]
40
- };
41
- if (typeof functionInDomain[ruleKey] !== "function") {
42
- return (0, _errorsJs.throwParseError)(writeMalformedDistributableFunctionMessage(functionInDomain));
43
- }
44
- distributed[domain] = functionInDomain;
45
- }
46
- }
47
- return distributed;
48
- };
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "writeIndivisibleMessage", {
6
- enumerable: true,
7
- get: ()=>writeIndivisibleMessage
8
- });
9
- const writeIndivisibleMessage = (root)=>`Divisibility operand ${root} must be a number`;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- compileDisjointReasonsMessage: ()=>compileDisjointReasonsMessage,
13
- writeImplicitNeverMessage: ()=>writeImplicitNeverMessage
14
- });
15
- const _composeJs = require("../../nodes/compose.js");
16
- const _genericsJs = require("../../utils/generics.js");
17
- const compileDisjointReasonsMessage = (disjoints)=>{
18
- const paths = (0, _genericsJs.objectKeysOf)(disjoints);
19
- if (paths.length === 1) {
20
- const path = paths[0];
21
- return `${path === "/" ? "" : `At ${path}: `}Intersection of ${_composeJs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])} results in an unsatisfiable type`;
22
- }
23
- let message = `
24
- "Intersection results in unsatisfiable types at the following paths:\n`;
25
- for(const path in disjoints){
26
- message += ` ${path}: ${_composeJs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])}\n`;
27
- }
28
- return message;
29
- };
30
- const writeImplicitNeverMessage = (path, operator, description)=>`${path.length ? `At ${path}: ` : ""}${operator} ${description ? `${description} ` : ""}results in an unsatisfiable type`;