arktype 0.5.0 → 0.6.0

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 (82) hide show
  1. package/dist/api.cjs +4 -2
  2. package/dist/api.d.ts +1 -1
  3. package/dist/api.mjs +1 -1
  4. package/dist/cjs/nodes/branch.js +21 -21
  5. package/dist/cjs/nodes/discriminate.js +2 -2
  6. package/dist/cjs/nodes/node.js +13 -18
  7. package/dist/cjs/nodes/predicate.js +1 -6
  8. package/dist/cjs/nodes/rules/props.js +39 -0
  9. package/dist/cjs/nodes/rules/rules.js +5 -2
  10. package/dist/cjs/parse/ast/config.js +15 -0
  11. package/dist/cjs/parse/ast/distributableFunction.js +1 -1
  12. package/dist/cjs/parse/ast/keyof.js +1 -1
  13. package/dist/cjs/parse/ast/morph.js +3 -3
  14. package/dist/cjs/{nodes/infer.js → parse/ast/node.js} +0 -0
  15. package/dist/cjs/parse/ast/tuple.js +2 -1
  16. package/dist/cjs/parse/definition.js +2 -2
  17. package/dist/cjs/parse/string/reduce/dynamic.js +2 -2
  18. package/dist/cjs/parse/string/shift/operand/unenclosed.js +1 -1
  19. package/dist/cjs/parse/string/string.js +3 -3
  20. package/dist/cjs/scopes/{standard.js → ark.js} +9 -8
  21. package/dist/cjs/scopes/expressions.js +9 -9
  22. package/dist/cjs/scopes/scope.js +73 -63
  23. package/dist/cjs/scopes/type.js +10 -29
  24. package/dist/cjs/scopes/validation/creditCard.js +47 -0
  25. package/dist/cjs/scopes/validation/date.js +63 -0
  26. package/dist/cjs/scopes/validation/validation.js +90 -0
  27. package/dist/cjs/traverse/problems.js +45 -16
  28. package/dist/cjs/traverse/traverse.js +63 -26
  29. package/dist/cjs/utils/serialize.js +3 -3
  30. package/dist/mjs/nodes/branch.js +2 -2
  31. package/dist/mjs/nodes/discriminate.js +2 -2
  32. package/dist/mjs/nodes/node.js +13 -19
  33. package/dist/mjs/nodes/predicate.js +1 -5
  34. package/dist/mjs/nodes/rules/props.js +39 -0
  35. package/dist/mjs/nodes/rules/rules.js +5 -2
  36. package/dist/mjs/parse/ast/config.js +7 -0
  37. package/dist/mjs/parse/ast/distributableFunction.js +1 -1
  38. package/dist/mjs/parse/ast/keyof.js +1 -1
  39. package/dist/mjs/parse/ast/morph.js +4 -4
  40. package/dist/mjs/{nodes/infer.js → parse/ast/node.js} +0 -0
  41. package/dist/mjs/parse/ast/tuple.js +2 -1
  42. package/dist/mjs/parse/definition.js +2 -2
  43. package/dist/mjs/parse/string/reduce/dynamic.js +2 -2
  44. package/dist/mjs/parse/string/shift/operand/unenclosed.js +1 -1
  45. package/dist/mjs/parse/string/string.js +3 -3
  46. package/dist/mjs/scopes/{standard.js → ark.js} +8 -7
  47. package/dist/mjs/scopes/expressions.js +9 -9
  48. package/dist/mjs/scopes/scope.js +69 -63
  49. package/dist/mjs/scopes/type.js +10 -29
  50. package/dist/mjs/scopes/validation/creditCard.js +34 -0
  51. package/dist/mjs/scopes/validation/date.js +49 -0
  52. package/dist/mjs/scopes/validation/validation.js +76 -0
  53. package/dist/mjs/traverse/problems.js +42 -15
  54. package/dist/mjs/traverse/traverse.js +64 -27
  55. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  56. package/dist/types/nodes/branch.d.ts +6 -6
  57. package/dist/types/nodes/node.d.ts +10 -5
  58. package/dist/types/nodes/predicate.d.ts +2 -6
  59. package/dist/types/nodes/rules/props.d.ts +15 -0
  60. package/dist/types/nodes/rules/rules.d.ts +2 -2
  61. package/dist/types/parse/ast/ast.d.ts +1 -1
  62. package/dist/types/parse/ast/config.d.ts +10 -0
  63. package/dist/types/parse/ast/divisor.d.ts +3 -3
  64. package/dist/types/parse/ast/narrow.d.ts +6 -6
  65. package/dist/types/{nodes/infer.d.ts → parse/ast/node.d.ts} +12 -12
  66. package/dist/types/parse/ast/tuple.d.ts +4 -3
  67. package/dist/types/scopes/{standard.d.ts → ark.d.ts} +12 -4
  68. package/dist/types/scopes/expressions.d.ts +3 -3
  69. package/dist/types/scopes/scope.d.ts +19 -7
  70. package/dist/types/scopes/type.d.ts +20 -12
  71. package/dist/types/scopes/validation/creditCard.d.ts +2 -0
  72. package/dist/types/scopes/validation/date.d.ts +23 -0
  73. package/dist/types/scopes/validation/validation.d.ts +26 -0
  74. package/dist/types/traverse/problems.d.ts +14 -8
  75. package/dist/types/traverse/traverse.d.ts +13 -3
  76. package/dist/types/utils/generics.d.ts +5 -5
  77. package/dist/types/utils/paths.d.ts +1 -1
  78. package/dist/types/utils/unionToTuple.d.ts +2 -2
  79. package/package.json +7 -7
  80. package/dist/cjs/scopes/validation.js +0 -79
  81. package/dist/mjs/scopes/validation.js +0 -66
  82. package/dist/types/scopes/validation.d.ts +0 -25
package/dist/api.cjs CHANGED
@@ -10,7 +10,9 @@ function _export(target, all) {
10
10
  }
11
11
  _export(exports, {
12
12
  scope: ()=>_scopeTs.scope,
13
- type: ()=>_standardTs.type,
13
+ type: ()=>_arkTs.type,
14
+ ark: ()=>_arkTs.arktypes,
15
+ arkScope: ()=>_arkTs.ark,
14
16
  intersection: ()=>_expressionsTs.intersection,
15
17
  union: ()=>_expressionsTs.union,
16
18
  arrayOf: ()=>_expressionsTs.arrayOf,
@@ -23,6 +25,6 @@ _export(exports, {
23
25
  Problem: ()=>_problemsTs.Problem
24
26
  });
25
27
  const _scopeTs = require("./cjs/scopes/scope.js");
26
- const _standardTs = require("./cjs/scopes/standard.js");
28
+ const _arkTs = require("./cjs/scopes/ark.js");
27
29
  const _expressionsTs = require("./cjs/scopes/expressions.js");
28
30
  const _problemsTs = require("./cjs/traverse/problems.js");
package/dist/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { scope } from "./types/scopes/scope.js"
2
- export { type } from "./types/scopes/standard.js"
2
+ export { type, arktypes as ark, ark as arkScope } from "./types/scopes/ark.js"
3
3
  export {
4
4
  intersection,
5
5
  union,
package/dist/api.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  export { scope } from "./mjs/scopes/scope.js";
2
- export { type } from "./mjs/scopes/standard.js";
2
+ export { type, arktypes as ark, ark as arkScope } from "./mjs/scopes/ark.js";
3
3
  export { intersection, union, arrayOf, instanceOf, valueOf, morph, narrow, keyOf } from "./mjs/scopes/expressions.js";
4
4
  export { Problems, Problem } from "./mjs/traverse/problems.js";
@@ -11,15 +11,15 @@ function _export(target, all) {
11
11
  _export(exports, {
12
12
  isBranchComparison: ()=>isBranchComparison,
13
13
  compareBranches: ()=>compareBranches,
14
- isMorphBranch: ()=>isMorphBranch,
14
+ isTransformationBranch: ()=>isTransformationBranch,
15
15
  flattenBranch: ()=>flattenBranch,
16
16
  branchIntersection: ()=>branchIntersection
17
17
  });
18
- const _intersectionJs = require("../parse/ast/intersection.js");
19
- const _domainsJs = require("../utils/domains.js");
20
- const _errorsJs = require("../utils/errors.js");
21
- const _composeJs = require("./compose.js");
22
- const _rulesJs = require("./rules/rules.js");
18
+ const _intersectionTs = require("../parse/ast/intersection.js");
19
+ const _domainsTs = require("../utils/domains.js");
20
+ const _errorsTs = require("../utils/errors.js");
21
+ const _composeTs = require("./compose.js");
22
+ const _rulesTs = require("./rules/rules.js");
23
23
  const isBranchComparison = (comparison)=>comparison?.lBranches !== undefined;
24
24
  const compareBranches = (lConditions, rConditions, state)=>{
25
25
  const result = {
@@ -42,7 +42,7 @@ const compareBranches = (lConditions, rConditions, state)=>{
42
42
  }
43
43
  const r = rPairs.condition;
44
44
  const subresult = branchIntersection(l, r, state);
45
- if ((0, _composeJs.isDisjoint)(subresult)) {
45
+ if ((0, _composeTs.isDisjoint)(subresult)) {
46
46
  // doesn't tell us about any redundancies or add a distinct pair
47
47
  return null;
48
48
  } else if (subresult === l) {
@@ -59,7 +59,7 @@ const compareBranches = (lConditions, rConditions, state)=>{
59
59
  // distinct branches.
60
60
  rPairs.distinct = null;
61
61
  return null;
62
- } else if ((0, _composeJs.isEquality)(subresult)) {
62
+ } else if ((0, _composeTs.isEquality)(subresult)) {
63
63
  // Combination of l and r subtype cases.
64
64
  result.equalities.push([
65
65
  lIndex,
@@ -68,13 +68,13 @@ const compareBranches = (lConditions, rConditions, state)=>{
68
68
  lImpliesR = true;
69
69
  rPairs.distinct = null;
70
70
  return null;
71
- } else if ((0, _domainsJs.hasDomain)(subresult, "object")) {
71
+ } else if ((0, _domainsTs.hasDomain)(subresult, "object")) {
72
72
  // Neither branch is a subtype of the other, return
73
73
  // the result of the intersection as a candidate
74
74
  // branch for the final union
75
75
  return subresult;
76
76
  }
77
- return (0, _errorsJs.throwInternalError)(`Unexpected predicate intersection result of type '${(0, _domainsJs.domainOf)(subresult)}'`);
77
+ return (0, _errorsTs.throwInternalError)(`Unexpected predicate intersection result of type '${(0, _domainsTs.domainOf)(subresult)}'`);
78
78
  });
79
79
  if (!lImpliesR) {
80
80
  for(let i = 0; i < pairs.length; i++){
@@ -87,10 +87,10 @@ const compareBranches = (lConditions, rConditions, state)=>{
87
87
  result.distinctIntersections = pairs.flatMap((pairs)=>pairs.distinct ?? []);
88
88
  return result;
89
89
  };
90
- const isMorphBranch = (branch)=>"morph" in branch;
90
+ const isTransformationBranch = (branch)=>"rules" in branch;
91
91
  const flattenBranch = (branch, ctx)=>{
92
- if (isMorphBranch(branch)) {
93
- const result = (0, _rulesJs.flattenRules)(branch.rules, ctx);
92
+ if (isTransformationBranch(branch)) {
93
+ const result = (0, _rulesTs.flattenRules)(branch.rules, ctx);
94
94
  if (branch.morph) {
95
95
  if (typeof branch.morph === "function") {
96
96
  result.push([
@@ -108,31 +108,31 @@ const flattenBranch = (branch, ctx)=>{
108
108
  }
109
109
  return result;
110
110
  }
111
- return (0, _rulesJs.flattenRules)(branch, ctx);
111
+ return (0, _rulesTs.flattenRules)(branch, ctx);
112
112
  };
113
113
  const rulesOf = (branch)=>branch.rules ?? branch;
114
114
  const branchIntersection = (l, r, state)=>{
115
115
  const lRules = rulesOf(l);
116
116
  const rRules = rulesOf(r);
117
- const rulesResult = (0, _rulesJs.rulesIntersection)(lRules, rRules, state);
117
+ const rulesResult = (0, _rulesTs.rulesIntersection)(lRules, rRules, state);
118
118
  if ("morph" in l) {
119
119
  if ("morph" in r) {
120
120
  if (l.morph === r.morph) {
121
- return (0, _composeJs.isEquality)(rulesResult) || (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
121
+ return (0, _composeTs.isEquality)(rulesResult) || (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
122
122
  rules: rulesResult,
123
123
  morph: l.morph
124
124
  };
125
125
  }
126
- return state.lastOperator === "&" ? (0, _errorsJs.throwParseError)((0, _intersectionJs.writeImplicitNeverMessage)(state.path, "Intersection", "of morphs")) : {};
126
+ return state.lastOperator === "&" ? (0, _errorsTs.throwParseError)((0, _intersectionTs.writeImplicitNeverMessage)(state.path, "Intersection", "of morphs")) : {};
127
127
  }
128
- return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
129
- rules: (0, _composeJs.isEquality)(rulesResult) ? l.rules : rulesResult,
128
+ return (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
129
+ rules: (0, _composeTs.isEquality)(rulesResult) ? l.rules : rulesResult,
130
130
  morph: l.morph
131
131
  };
132
132
  }
133
133
  if ("morph" in r) {
134
- return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
135
- rules: (0, _composeJs.isEquality)(rulesResult) ? r.rules : rulesResult,
134
+ return (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
135
+ rules: (0, _composeTs.isEquality)(rulesResult) ? r.rules : rulesResult,
136
136
  morph: r.morph
137
137
  };
138
138
  }
@@ -37,7 +37,7 @@ const discriminate = (originalBranches, remainingIndices, discriminants, ctx)=>{
37
37
  return [
38
38
  [
39
39
  "branches",
40
- remainingIndices.map((i)=>branchIncludesMorph(originalBranches[i], ctx.type.meta.scope) ? (0, _errorsTs.throwParseError)((0, _unionTs.writeUndiscriminatableMorphUnionMessage)(`${ctx.path}`)) : (0, _branchTs.flattenBranch)(originalBranches[i], ctx))
40
+ remainingIndices.map((i)=>branchIncludesMorph(originalBranches[i], ctx.type.scope) ? (0, _errorsTs.throwParseError)((0, _unionTs.writeUndiscriminatableMorphUnionMessage)(`${ctx.path}`)) : (0, _branchTs.flattenBranch)(originalBranches[i], ctx))
41
41
  ]
42
42
  ];
43
43
  }
@@ -259,4 +259,4 @@ const serializeData = {
259
259
  };
260
260
  const serializeCase = (kind, data)=>serializeData[kind](data);
261
261
  const branchIncludesMorph = (branch, $)=>"morph" in branch ? true : "props" in branch ? Object.values(branch.props).some((prop)=>nodeIncludesMorph((0, _propsTs.propToNode)(prop), $)) : false;
262
- const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).meta.includesMorph : Object.values(node).some((predicate)=>predicate === true ? false : (0, _objectKindsTs.isArray)(predicate) ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));
262
+ const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).includesMorph : Object.values(node).some((predicate)=>predicate === true ? false : (0, _objectKindsTs.isArray)(predicate) ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));
@@ -15,6 +15,7 @@ _export(exports, {
15
15
  flattenType: ()=>flattenType,
16
16
  flattenNode: ()=>flattenNode,
17
17
  isLiteralNode: ()=>isLiteralNode,
18
+ resolutionExtendsDomain: ()=>resolutionExtendsDomain,
18
19
  toArrayNode: ()=>toArrayNode
19
20
  });
20
21
  const _intersectionTs = require("../parse/ast/intersection.js");
@@ -26,8 +27,8 @@ const _predicateTs = require("./predicate.js");
26
27
  const _propsTs = require("./rules/props.js");
27
28
  const nodeIntersection = (l, r, state)=>{
28
29
  state.domain = undefined;
29
- const lResolution = state.type.meta.scope.resolveNode(l);
30
- const rResolution = state.type.meta.scope.resolveNode(r);
30
+ const lResolution = state.type.scope.resolveNode(l);
31
+ const rResolution = state.type.scope.resolveNode(r);
31
32
  const result = resolutionIntersection(lResolution, rResolution, state);
32
33
  if (typeof result === "object" && !(0, _genericsTs.hasKeys)(result)) {
33
34
  return (0, _genericsTs.hasKeys)(state.disjoints) ? (0, _composeTs.anonymousDisjoint)() : state.addDisjoint("domain", (0, _genericsTs.objectKeysOf)(lResolution), (0, _genericsTs.objectKeysOf)(rResolution));
@@ -51,8 +52,8 @@ const rootIntersection = (l, r, type)=>{
51
52
  return (0, _composeTs.isDisjoint)(result) ? (0, _errorsTs.throwParseError)((0, _intersectionTs.compileDisjointReasonsMessage)(state.disjoints)) : (0, _composeTs.isEquality)(result) ? l : result;
52
53
  };
53
54
  const rootUnion = (l, r, type)=>{
54
- const lResolution = type.meta.scope.resolveNode(l);
55
- const rResolution = type.meta.scope.resolveNode(r);
55
+ const lResolution = type.scope.resolveNode(l);
56
+ const rResolution = type.scope.resolveNode(r);
56
57
  const result = {};
57
58
  const domains = (0, _genericsTs.objectKeysOf)({
58
59
  ...lResolution,
@@ -70,11 +71,11 @@ const flattenType = (type)=>{
70
71
  path: new _pathsTs.Path(),
71
72
  lastDomain: "undefined"
72
73
  };
73
- return type.meta.config ? [
74
+ return type.config ? [
74
75
  [
75
76
  "config",
76
77
  {
77
- config: type.meta.config,
78
+ config: (0, _genericsTs.entriesOf)(type.config),
78
79
  node: flattenNode(type.node, ctx)
79
80
  }
80
81
  ]
@@ -82,17 +83,7 @@ const flattenType = (type)=>{
82
83
  };
83
84
  const flattenNode = (node, ctx)=>{
84
85
  if (typeof node === "string") {
85
- const resolution = ctx.type.meta.scope.resolve(node);
86
- const updatedScopeConfig = resolution.meta.scope !== ctx.type.meta.scope && resolution.meta.scope.config;
87
- return updatedScopeConfig ? [
88
- [
89
- "config",
90
- {
91
- config: updatedScopeConfig,
92
- node: resolution.flat
93
- }
94
- ]
95
- ] : resolution.flat;
86
+ return ctx.type.scope.resolve(node).flat;
96
87
  }
97
88
  const domains = (0, _genericsTs.objectKeysOf)(node);
98
89
  if (domains.length === 1) {
@@ -124,7 +115,11 @@ const flattenNode = (node, ctx)=>{
124
115
  ];
125
116
  };
126
117
  const isLiteralNode = (node, domain)=>{
127
- return (0, _predicateTs.resolutionExtendsDomain)(node, domain) && (0, _predicateTs.isLiteralCondition)(node[domain]);
118
+ return resolutionExtendsDomain(node, domain) && (0, _predicateTs.isLiteralCondition)(node[domain]);
119
+ };
120
+ const resolutionExtendsDomain = (resolution, domain)=>{
121
+ const domains = (0, _genericsTs.objectKeysOf)(resolution);
122
+ return domains.length === 1 && domains[0] === domain;
128
123
  };
129
124
  const toArrayNode = (node)=>({
130
125
  object: {
@@ -13,8 +13,7 @@ _export(exports, {
13
13
  predicateIntersection: ()=>predicateIntersection,
14
14
  predicateUnion: ()=>predicateUnion,
15
15
  flattenPredicate: ()=>flattenPredicate,
16
- isLiteralCondition: ()=>isLiteralCondition,
17
- resolutionExtendsDomain: ()=>resolutionExtendsDomain
16
+ isLiteralCondition: ()=>isLiteralCondition
18
17
  });
19
18
  const _genericsTs = require("../utils/generics.js");
20
19
  const _objectKindsTs = require("../utils/objectKinds.js");
@@ -86,7 +85,3 @@ const flattenPredicate = (predicate, context)=>{
86
85
  return (0, _objectKindsTs.isArray)(predicate) ? (0, _discriminateTs.flattenBranches)(predicate, context) : (0, _branchTs.flattenBranch)(predicate, context);
87
86
  };
88
87
  const isLiteralCondition = (predicate)=>typeof predicate === "object" && "value" in predicate;
89
- const resolutionExtendsDomain = (resolution, domain)=>{
90
- const domains = (0, _genericsTs.objectKeysOf)(resolution);
91
- return domains.length === 1 && domains[0] === domain;
92
- };
@@ -83,6 +83,11 @@ const propKeysIntersection = (0, _composeTs.composeKeyedIntersection)((propKey,
83
83
  onEmpty: "bubble"
84
84
  });
85
85
  const flattenProps = (entries, props, ctx)=>{
86
+ const keyConfig = ctx.type.config?.keys ?? ctx.type.scope.config.keys;
87
+ return keyConfig === "loose" ? flattenLooseProps(entries, props, ctx) : flattenPropsRecord(keyConfig, entries, props, ctx);
88
+ };
89
+ const flattenLooseProps = (entries, props, ctx)=>{
90
+ // if we don't care about extraneous keys, flatten props so we can iterate over the definitions directly
86
91
  for(const k in props){
87
92
  const prop = props[k];
88
93
  ctx.path.push(k);
@@ -119,3 +124,37 @@ const flattenProps = (entries, props, ctx)=>{
119
124
  ctx.path.pop();
120
125
  }
121
126
  };
127
+ const flattenPropsRecord = (kind, entries, props, ctx)=>{
128
+ const result = {
129
+ required: {},
130
+ optional: {}
131
+ };
132
+ // if we need to keep track of extraneous keys, either to add problems or
133
+ // remove them, store the props as a Record to optimize for presence
134
+ // checking as we iterate over the data
135
+ for(const k in props){
136
+ const prop = props[k];
137
+ ctx.path.push(k);
138
+ if (k === mappedKeys.index) {
139
+ result.index = (0, _nodeTs.flattenNode)(propToNode(prop), ctx);
140
+ } else if (isOptional(prop)) {
141
+ result.optional[k] = (0, _nodeTs.flattenNode)(prop[1], ctx);
142
+ } else if (isPrerequisite(prop)) {
143
+ // we still have to push prerequisite props as normal entries so they can be checked first
144
+ entries.push([
145
+ "prerequisiteProp",
146
+ [
147
+ k,
148
+ (0, _nodeTs.flattenNode)(prop[1], ctx)
149
+ ]
150
+ ]);
151
+ } else {
152
+ result.required[k] = (0, _nodeTs.flattenNode)(prop, ctx);
153
+ }
154
+ ctx.path.pop();
155
+ }
156
+ entries.push([
157
+ `${kind}Props`,
158
+ result
159
+ ]);
160
+ };
@@ -86,8 +86,9 @@ const ruleFlatteners = {
86
86
  }
87
87
  };
88
88
  const precedenceMap = {
89
+ // Config: Applies before any checks
90
+ config: -1,
89
91
  // Critical: No other checks are performed if these fail
90
- config: 0,
91
92
  domain: 0,
92
93
  value: 0,
93
94
  domains: 0,
@@ -104,6 +105,8 @@ const precedenceMap = {
104
105
  // is invalid
105
106
  prerequisiteProp: 2,
106
107
  // Deep: Performed if all shallow checks pass, even if one or more deep checks fail
108
+ distilledProps: 3,
109
+ strictProps: 3,
107
110
  requiredProp: 3,
108
111
  optionalProp: 3,
109
112
  indexProp: 3,
@@ -112,7 +115,7 @@ const precedenceMap = {
112
115
  // Morph: Only performed if all validation passes
113
116
  morph: 5
114
117
  };
115
- const literalSatisfiesRules = (data, rules, state)=>!state.type.meta.scope.type([
118
+ const literalSatisfiesRules = (data, rules, state)=>!state.type.scope.type([
116
119
  "node",
117
120
  {
118
121
  [state.domain]: rules
@@ -0,0 +1,15 @@
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 parseConfigTuple = (def, ctx)=>{
10
+ const anonymousType = ctx.type.scope.type(def[0], {
11
+ name: ctx.type.scope.getAnonymousTypeName(ctx),
12
+ ...def[2]
13
+ });
14
+ return anonymousType.name;
15
+ };
@@ -18,7 +18,7 @@ const _genericsTs = require("../../utils/generics.js");
18
18
  const _serializeTs = require("../../utils/serialize.js");
19
19
  const writeMalformedDistributableFunctionMessage = (def)=>`Expected a Function or Record<Domain, Function> operand (${(0, _serializeTs.stringify)(def)} was invalid)`;
20
20
  const distributeFunctionToNode = (distributableFunction, inputNode, ctx, ruleKey)=>{
21
- const domains = (0, _genericsTs.objectKeysOf)(ctx.type.meta.scope.resolveNode(inputNode));
21
+ const domains = (0, _genericsTs.objectKeysOf)(ctx.type.scope.resolveNode(inputNode));
22
22
  if (!(0, _domainsTs.hasDomain)(distributableFunction, "object")) {
23
23
  return (0, _errorsTs.throwParseError)(writeMalformedDistributableFunctionMessage(distributableFunction));
24
24
  }
@@ -29,7 +29,7 @@ const arrayIndexNumberBranch = (0, _freezeTs.deepFreeze)({
29
29
  divisor: 1
30
30
  });
31
31
  const parseKeyOfTuple = (def, ctx)=>{
32
- const resolution = ctx.type.meta.scope.resolveNode((0, _definitionTs.parseDefinition)(def[1], ctx));
32
+ const resolution = ctx.type.scope.resolveNode((0, _definitionTs.parseDefinition)(def[1], ctx));
33
33
  const predicateKeys = (0, _genericsTs.objectKeysOf)(resolution).map((domain)=>keysOfPredicate(domain, resolution[domain]));
34
34
  const sharedKeys = sharedKeysOf(predicateKeys);
35
35
  if (!sharedKeys.length) {
@@ -21,9 +21,9 @@ const parseMorphTuple = (def, ctx)=>{
21
21
  if (typeof def[2] !== "function") {
22
22
  return (0, _errorsTs.throwParseError)(writeMalformedMorphExpressionMessage(def[2]));
23
23
  }
24
- const resolution = ctx.type.meta.scope.resolveNode((0, _definitionTs.parseDefinition)(def[0], ctx));
24
+ const resolution = ctx.type.scope.resolveNode((0, _definitionTs.parseDefinition)(def[0], ctx));
25
25
  const morph = def[2];
26
- ctx.type.meta.includesMorph = true;
26
+ ctx.type.includesMorph = true;
27
27
  let domain;
28
28
  const result = {};
29
29
  for(domain in resolution){
@@ -41,7 +41,7 @@ const parseMorphTuple = (def, ctx)=>{
41
41
  }
42
42
  return result;
43
43
  };
44
- const applyMorph = (branch, morph)=>(0, _branchTs.isMorphBranch)(branch) ? {
44
+ const applyMorph = (branch, morph)=>(0, _branchTs.isTransformationBranch)(branch) ? {
45
45
  ...branch,
46
46
  morph: branch.morph ? Array.isArray(branch.morph) ? [
47
47
  ...branch.morph,
File without changes
@@ -17,6 +17,7 @@ const _domainsTs = require("../../utils/domains.js");
17
17
  const _errorsTs = require("../../utils/errors.js");
18
18
  const _definitionTs = require("../definition.js");
19
19
  const _unenclosedTs = require("../string/shift/operand/unenclosed.js");
20
+ const _configTs = require("./config.js");
20
21
  const _keyofTs = require("./keyof.js");
21
22
  const _morphTs = require("./morph.js");
22
23
  const _narrowTs = require("./narrow.js");
@@ -69,7 +70,7 @@ const indexOneParsers = {
69
70
  "[]": parseArrayTuple,
70
71
  "=>": _narrowTs.parseNarrowTuple,
71
72
  "|>": _morphTs.parseMorphTuple,
72
- ":": ()=>({})
73
+ ":": _configTs.parseConfigTuple
73
74
  };
74
75
  const prefixParsers = {
75
76
  keyof: _keyofTs.parseKeyOfTuple,
@@ -44,12 +44,12 @@ const parseDefinition = (def, ctx)=>{
44
44
  };
45
45
  case "Function":
46
46
  if ((0, _typeTs.isType)(def)) {
47
- return def.node;
47
+ return ctx.type.scope.addAnonymous(def, ctx);
48
48
  }
49
49
  if (isThunk(def)) {
50
50
  const returned = def();
51
51
  if ((0, _typeTs.isType)(returned)) {
52
- return returned.node;
52
+ return ctx.type.scope.addAnonymous(returned, ctx);
53
53
  }
54
54
  }
55
55
  return (0, _errorsTs.throwParseError)(writeBadDefinitionTypeMessage("Function"));
@@ -22,7 +22,7 @@ class DynamicState {
22
22
  }
23
23
  resolveRoot() {
24
24
  this.assertHasRoot();
25
- return this.ctx.type.meta.scope.resolveNode(this.root);
25
+ return this.ctx.type.scope.resolveNode(this.root);
26
26
  }
27
27
  rootToString() {
28
28
  this.assertHasRoot();
@@ -30,7 +30,7 @@ class DynamicState {
30
30
  }
31
31
  ejectRootIfLimit() {
32
32
  this.assertHasRoot();
33
- const resolution = typeof this.root === "string" ? this.ctx.type.meta.scope.resolveNode(this.root) : this.root;
33
+ const resolution = typeof this.root === "string" ? this.ctx.type.scope.resolveNode(this.root) : this.root;
34
34
  if ((0, _nodeTs.isLiteralNode)(resolution, "number")) {
35
35
  const limit = resolution.number.value;
36
36
  this.root = undefined;
@@ -21,7 +21,7 @@ const parseUnenclosed = (s)=>{
21
21
  s.setRoot(unenclosedToNode(s, token));
22
22
  };
23
23
  const unenclosedToNode = (s, token)=>{
24
- if (s.ctx.type.meta.scope.addReferenceIfResolvable(token, s.ctx)) {
24
+ if (s.ctx.type.scope.addReferenceIfResolvable(token, s.ctx)) {
25
25
  return token;
26
26
  }
27
27
  return maybeParseUnenclosedLiteral(token) ?? s.error(token === "" ? writeMissingOperandMessage(s) : writeUnresolvableMessage(token));
@@ -17,14 +17,14 @@ const _nodeTs = require("../../nodes/node.js");
17
17
  const _dynamicTs = require("./reduce/dynamic.js");
18
18
  const _operandTs = require("./shift/operand/operand.js");
19
19
  const _operatorTs = require("./shift/operator/operator.js");
20
- const parseString = (def, ctx)=>ctx.type.meta.scope.parseCache.get(def) ?? ctx.type.meta.scope.parseCache.set(def, maybeNaiveParse(def, ctx) ?? fullStringParse(def, ctx));
20
+ const parseString = (def, ctx)=>ctx.type.scope.parseCache.get(def) ?? ctx.type.scope.parseCache.set(def, maybeNaiveParse(def, ctx) ?? fullStringParse(def, ctx));
21
21
  const maybeNaiveParse = (def, ctx)=>{
22
- if (ctx.type.meta.scope.addReferenceIfResolvable(def, ctx)) {
22
+ if (ctx.type.scope.addReferenceIfResolvable(def, ctx)) {
23
23
  return def;
24
24
  }
25
25
  if (def.endsWith("[]")) {
26
26
  const elementDef = def.slice(0, -2);
27
- if (ctx.type.meta.scope.addReferenceIfResolvable(def, ctx)) {
27
+ if (ctx.type.scope.addReferenceIfResolvable(def, ctx)) {
28
28
  return (0, _nodeTs.toArrayNode)(elementDef);
29
29
  }
30
30
  }
@@ -9,8 +9,8 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- standardScope: ()=>standardScope,
13
- standard: ()=>standard,
12
+ ark: ()=>ark,
13
+ arktypes: ()=>arktypes,
14
14
  scopes: ()=>scopes,
15
15
  spaces: ()=>spaces,
16
16
  type: ()=>type
@@ -18,8 +18,8 @@ _export(exports, {
18
18
  const _jsObjectsTs = require("./jsObjects.js");
19
19
  const _scopeTs = require("./scope.js");
20
20
  const _tsKeywordsTs = require("./tsKeywords.js");
21
- const _validationTs = require("./validation.js");
22
- const standardScope = (0, _scopeTs.scope)({}, {
21
+ const _validationTs = require("./validation/validation.js");
22
+ const ark = (0, _scopeTs.scope)({}, {
23
23
  name: "standard",
24
24
  includes: [
25
25
  _tsKeywordsTs.tsKeywords,
@@ -28,17 +28,18 @@ const standardScope = (0, _scopeTs.scope)({}, {
28
28
  ],
29
29
  standard: false
30
30
  });
31
- const standard = standardScope.compile();
31
+ const arktypes = ark.compile();
32
32
  const scopes = {
33
+ root: _scopeTs.rootScope,
33
34
  tsKeywords: _tsKeywordsTs.tsKeywordsScope,
34
35
  jsObjects: _jsObjectsTs.jsObjectsScope,
35
36
  validation: _validationTs.validationScope,
36
- standard: standardScope
37
+ ark
37
38
  };
38
39
  const spaces = {
39
40
  tsKeywords: _tsKeywordsTs.tsKeywords,
40
41
  jsObjects: _jsObjectsTs.jsObjects,
41
42
  validation: _validationTs.validation,
42
- standard
43
+ ark: arktypes
43
44
  };
44
- const type = scopes.standard.type;
45
+ const type = ark.type;
@@ -18,12 +18,12 @@ _export(exports, {
18
18
  narrow: ()=>narrow,
19
19
  morph: ()=>morph
20
20
  });
21
- const _standardTs = require("./standard.js");
22
- const intersection = _standardTs.scopes.standard.intersection;
23
- const union = _standardTs.scopes.standard.union;
24
- const arrayOf = _standardTs.scopes.standard.arrayOf;
25
- const keyOf = _standardTs.scopes.standard.keyOf;
26
- const instanceOf = _standardTs.scopes.standard.instanceOf;
27
- const valueOf = _standardTs.scopes.standard.valueOf;
28
- const narrow = _standardTs.scopes.standard.narrow;
29
- const morph = _standardTs.scopes.standard.morph;
21
+ const _arkTs = require("./ark.js");
22
+ const intersection = _arkTs.scopes.ark.intersection;
23
+ const union = _arkTs.scopes.ark.union;
24
+ const arrayOf = _arkTs.scopes.ark.arrayOf;
25
+ const keyOf = _arkTs.scopes.ark.keyOf;
26
+ const instanceOf = _arkTs.scopes.ark.instanceOf;
27
+ const valueOf = _arkTs.scopes.ark.valueOf;
28
+ const narrow = _arkTs.scopes.ark.narrow;
29
+ const morph = _arkTs.scopes.ark.morph;