arktype 0.1.2 → 0.1.3

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 (65) hide show
  1. package/dist/cjs/main.js +127 -15
  2. package/dist/cjs/nodes/branches.js +7 -7
  3. package/dist/cjs/nodes/compose.js +3 -2
  4. package/dist/cjs/nodes/discriminate.js +5 -4
  5. package/dist/cjs/nodes/functors.js +3 -3
  6. package/dist/cjs/nodes/node.js +1 -1
  7. package/dist/cjs/nodes/predicate.js +19 -14
  8. package/dist/cjs/nodes/rules/collapsibleSet.js +3 -4
  9. package/dist/cjs/nodes/rules/objectKind.js +78 -0
  10. package/dist/cjs/nodes/rules/range.js +2 -2
  11. package/dist/cjs/nodes/rules/rules.js +4 -4
  12. package/dist/cjs/parse/definition.js +26 -6
  13. package/dist/cjs/parse/string/shift/operator/bounds.js +1 -1
  14. package/dist/cjs/parse/tuple/morph.js +2 -2
  15. package/dist/cjs/parse/tuple/tuple.js +1 -1
  16. package/dist/cjs/traverse/problems.js +18 -32
  17. package/dist/cjs/traverse/traverse.js +12 -12
  18. package/dist/cjs/utils/domains.js +10 -47
  19. package/dist/cjs/utils/generics.js +1 -3
  20. package/dist/cjs/utils/objectKinds.js +64 -0
  21. package/dist/cjs/utils/size.js +16 -0
  22. package/dist/mjs/main.js +127 -15
  23. package/dist/mjs/nodes/branches.js +7 -7
  24. package/dist/mjs/nodes/compose.js +3 -2
  25. package/dist/mjs/nodes/discriminate.js +6 -5
  26. package/dist/mjs/nodes/functors.js +3 -3
  27. package/dist/mjs/nodes/node.js +1 -1
  28. package/dist/mjs/nodes/predicate.js +20 -15
  29. package/dist/mjs/nodes/rules/collapsibleSet.js +3 -4
  30. package/dist/mjs/nodes/rules/{subdomain.js → objectKind.js} +10 -10
  31. package/dist/mjs/nodes/rules/range.js +1 -1
  32. package/dist/mjs/nodes/rules/rules.js +4 -4
  33. package/dist/mjs/parse/definition.js +27 -7
  34. package/dist/mjs/parse/string/shift/operator/bounds.js +1 -1
  35. package/dist/mjs/parse/tuple/morph.js +2 -2
  36. package/dist/mjs/parse/tuple/tuple.js +1 -1
  37. package/dist/mjs/traverse/problems.js +18 -31
  38. package/dist/mjs/traverse/traverse.js +12 -12
  39. package/dist/mjs/utils/domains.js +9 -42
  40. package/dist/mjs/utils/generics.js +0 -1
  41. package/dist/mjs/utils/objectKinds.js +48 -0
  42. package/dist/mjs/utils/size.js +2 -0
  43. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  44. package/dist/types/main.d.ts +73 -9
  45. package/dist/types/nodes/branches.d.ts +4 -4
  46. package/dist/types/nodes/compose.d.ts +12 -5
  47. package/dist/types/nodes/discriminate.d.ts +3 -2
  48. package/dist/types/nodes/infer.d.ts +11 -10
  49. package/dist/types/nodes/predicate.d.ts +2 -2
  50. package/dist/types/nodes/rules/objectKind.d.ts +15 -0
  51. package/dist/types/nodes/rules/range.d.ts +1 -1
  52. package/dist/types/nodes/rules/rules.d.ts +4 -4
  53. package/dist/types/parse/definition.d.ts +6 -5
  54. package/dist/types/parse/string/ast.d.ts +4 -2
  55. package/dist/types/parse/string/reduce/shared.d.ts +1 -1
  56. package/dist/types/parse/string/shift/operator/bounds.d.ts +1 -1
  57. package/dist/types/traverse/problems.d.ts +25 -41
  58. package/dist/types/traverse/traverse.d.ts +24 -4
  59. package/dist/types/utils/domains.d.ts +11 -37
  60. package/dist/types/utils/generics.d.ts +0 -1
  61. package/dist/types/utils/objectKinds.d.ts +83 -0
  62. package/dist/types/utils/size.d.ts +3 -0
  63. package/package.json +4 -4
  64. package/dist/cjs/nodes/rules/subdomain.js +0 -78
  65. package/dist/types/nodes/rules/subdomain.d.ts +0 -15
@@ -12,9 +12,8 @@ _export(exports, {
12
12
  ArkTypeError: ()=>ArkTypeError,
13
13
  Problem: ()=>Problem,
14
14
  Problems: ()=>Problems,
15
- describeSubdomains: ()=>describeSubdomains,
15
+ describeDomains: ()=>describeDomains,
16
16
  describeBranches: ()=>describeBranches,
17
- subdomainDescriptions: ()=>subdomainDescriptions,
18
17
  DataWrapper: ()=>DataWrapper,
19
18
  defaultProblemWriters: ()=>defaultProblemWriters,
20
19
  compileProblemOptions: ()=>compileProblemOptions
@@ -22,6 +21,7 @@ _export(exports, {
22
21
  const _scannerTs = require("../parse/string/shift/scanner.js");
23
22
  const _domainsTs = require("../utils/domains.js");
24
23
  const _genericsTs = require("../utils/generics.js");
24
+ const _objectKindsTs = require("../utils/objectKinds.js");
25
25
  const _pathsTs = require("../utils/paths.js");
26
26
  const _serializeTs = require("../utils/serialize.js");
27
27
  var _definitions_code, _definitions_code1, _definitions_code2, _clausesByPath, _pathKey;
@@ -97,14 +97,14 @@ class ProblemArray extends Array {
97
97
  }
98
98
  const Problems = ProblemArray;
99
99
  const capitalize = (s)=>s[0].toUpperCase() + s.slice(1);
100
- const describeSubdomains = (subdomains)=>{
101
- if (subdomains.length === 1) {
102
- return subdomainDescriptions[subdomains[0]];
100
+ const describeDomains = (domains)=>{
101
+ if (domains.length === 1) {
102
+ return _domainsTs.domainDescriptions[domains[0]];
103
103
  }
104
- if (subdomains.length === 0) {
104
+ if (domains.length === 0) {
105
105
  return "never";
106
106
  }
107
- return describeBranches(subdomains.map((subdomain)=>subdomainDescriptions[subdomain]));
107
+ return describeBranches(domains.map((objectKind)=>_domainsTs.domainDescriptions[objectKind]));
108
108
  };
109
109
  const describeBranches = (descriptions)=>{
110
110
  let description = "";
@@ -117,23 +117,6 @@ const describeBranches = (descriptions)=>{
117
117
  description += ` or ${descriptions[descriptions.length - 1]}`;
118
118
  return description;
119
119
  };
120
- const subdomainDescriptions = {
121
- bigint: "a bigint",
122
- boolean: "boolean",
123
- null: "null",
124
- number: "a number",
125
- object: "an object",
126
- string: "a string",
127
- symbol: "a symbol",
128
- undefined: "undefined",
129
- Array: "an array",
130
- Function: "a function",
131
- Date: "a Date",
132
- RegExp: "a RegExp",
133
- Error: "an Error",
134
- Map: "a Map",
135
- Set: "a Set"
136
- };
137
120
  class DataWrapper {
138
121
  toString() {
139
122
  return (0, _serializeTs.stringify)(this.value);
@@ -141,18 +124,17 @@ class DataWrapper {
141
124
  get domain() {
142
125
  return (0, _domainsTs.domainOf)(this.value);
143
126
  }
144
- // TODO: object kind?
145
- get subdomain() {
146
- return (0, _domainsTs.subdomainOf)(this.value);
127
+ get objectKind() {
128
+ return (0, _objectKindsTs.objectKindOf)(this.value) ?? "non-object";
147
129
  }
148
130
  get size() {
149
- return (0, _domainsTs.sizeOf)(this.value);
131
+ return typeof this.value === "string" || Array.isArray(this.value) ? this.value.length : typeof this.value === "number" ? this.value : 0;
150
132
  }
151
133
  get units() {
152
- return (0, _domainsTs.unitsOf)(this.value);
134
+ return typeof this.value === "string" ? "characters" : Array.isArray(this.value) ? "items" : "";
153
135
  }
154
136
  get className() {
155
- return (0, _domainsTs.classNameOf)(this.value);
137
+ return Object(this.value).constructor.name;
156
138
  }
157
139
  constructor(value){
158
140
  this.value = value;
@@ -179,13 +161,17 @@ const defaultProblemWriters = compileDefaultProblemWriters({
179
161
  was: (data)=>data.className
180
162
  },
181
163
  domain: {
182
- mustBe: (domain)=>subdomainDescriptions[domain],
164
+ mustBe: (domain)=>_domainsTs.domainDescriptions[domain],
183
165
  was: (data)=>data.domain
184
166
  },
185
167
  domainBranches: {
186
- mustBe: (domains)=>describeSubdomains(domains),
168
+ mustBe: (domains)=>describeDomains(domains),
187
169
  was: (data)=>data.domain
188
170
  },
171
+ objectKind: {
172
+ mustBe: (kind)=>_objectKindsTs.objectKindDescriptions[kind],
173
+ was: (data)=>data.objectKind
174
+ },
189
175
  missing: {
190
176
  mustBe: ()=>"defined",
191
177
  was: ()=>""
@@ -12,7 +12,7 @@ _export(exports, {
12
12
  TraversalState: ()=>TraversalState,
13
13
  traverse: ()=>traverse,
14
14
  checkEntries: ()=>checkEntries,
15
- checkSubdomain: ()=>checkSubdomain
15
+ checkObjectKind: ()=>checkObjectKind
16
16
  });
17
17
  const _discriminateJs = require("../nodes/discriminate.js");
18
18
  const _classJs = require("../nodes/rules/class.js");
@@ -23,6 +23,7 @@ const _rulesJs = require("../nodes/rules/rules.js");
23
23
  const _domainsJs = require("../utils/domains.js");
24
24
  const _errorsJs = require("../utils/errors.js");
25
25
  const _genericsJs = require("../utils/generics.js");
26
+ const _objectKindsJs = require("../utils/objectKinds.js");
26
27
  const _pathsJs = require("../utils/paths.js");
27
28
  const _serializeJs = require("../utils/serialize.js");
28
29
  const _problemsJs = require("./problems.js");
@@ -173,7 +174,6 @@ const createPropChecker = (propKind)=>(data, props, state)=>{
173
174
  state.path.push(propKey);
174
175
  if (!(0, _genericsJs.hasKey)(data, propKey)) {
175
176
  if (propKind !== "optionalProps") {
176
- // TODO: update
177
177
  state.problems.add("missing", undefined, undefined);
178
178
  }
179
179
  } else {
@@ -185,18 +185,18 @@ const createPropChecker = (propKind)=>(data, props, state)=>{
185
185
  };
186
186
  const checkRequiredProps = createPropChecker("requiredProps");
187
187
  const checkOptionalProps = createPropChecker("optionalProps");
188
- const checkSubdomain = (data, rule, state)=>{
189
- const dataSubdomain = (0, _domainsJs.subdomainOf)(data);
188
+ const checkObjectKind = (data, rule, state)=>{
189
+ const dataObjectKind = (0, _objectKindsJs.objectKindOf)(data);
190
190
  if (typeof rule === "string") {
191
- if (dataSubdomain !== rule) {
192
- return state.problems.add("domain", data, rule);
191
+ if (dataObjectKind !== rule) {
192
+ return state.problems.add("objectKind", data, rule);
193
193
  }
194
194
  return;
195
195
  }
196
- if (dataSubdomain !== rule[0]) {
197
- return state.problems.add("domain", data, rule[0]);
196
+ if (dataObjectKind !== rule[0]) {
197
+ return state.problems.add("objectKind", data, rule[0]);
198
198
  }
199
- if (dataSubdomain === "Array" && typeof rule[2] === "number") {
199
+ if (dataObjectKind === "Array" && typeof rule[2] === "number") {
200
200
  const actual = data.length;
201
201
  const expected = rule[2];
202
202
  if (expected !== actual) {
@@ -207,7 +207,7 @@ const checkSubdomain = (data, rule, state)=>{
207
207
  });
208
208
  }
209
209
  }
210
- if (dataSubdomain === "Array" || dataSubdomain === "Set") {
210
+ if (dataObjectKind === "Array" || dataObjectKind === "Set") {
211
211
  let i = 0;
212
212
  for (const item of data){
213
213
  state.path.push(`${i}`);
@@ -216,7 +216,7 @@ const checkSubdomain = (data, rule, state)=>{
216
216
  i++;
217
217
  }
218
218
  } else {
219
- return (0, _errorsJs.throwInternalError)(`Unexpected subdomain entry ${(0, _serializeJs.stringify)(rule)}`);
219
+ return (0, _errorsJs.throwInternalError)(`Unexpected objectKind entry ${(0, _serializeJs.stringify)(rule)}`);
220
220
  }
221
221
  return true;
222
222
  };
@@ -236,7 +236,7 @@ const checkers = {
236
236
  state.problems.add("domain", data, domain);
237
237
  }
238
238
  },
239
- subdomain: checkSubdomain,
239
+ objectKind: checkObjectKind,
240
240
  bound: _rangeJs.checkBound,
241
241
  requiredProps: checkRequiredProps,
242
242
  optionalProps: checkOptionalProps,
@@ -11,57 +11,20 @@ function _export(target, all) {
11
11
  _export(exports, {
12
12
  hasDomain: ()=>hasDomain,
13
13
  domainOf: ()=>domainOf,
14
- subdomainOf: ()=>subdomainOf,
15
- hasSubdomain: ()=>hasSubdomain,
16
- sizeOf: ()=>sizeOf,
17
- unitsOf: ()=>unitsOf,
18
- classNameOf: ()=>classNameOf
14
+ domainDescriptions: ()=>domainDescriptions
19
15
  });
20
- const _genericsTs = require("./generics.js");
21
16
  const hasDomain = (data, domain)=>domainOf(data) === domain;
22
17
  const domainOf = (data)=>{
23
18
  const builtinType = typeof data;
24
19
  return builtinType === "object" ? data === null ? "null" : "object" : builtinType === "function" ? "object" : builtinType;
25
20
  };
26
- const objectSubdomains = {
27
- Array,
28
- Date,
29
- Error,
30
- Function,
31
- Map,
32
- RegExp,
33
- Set,
34
- object: Object
21
+ const domainDescriptions = {
22
+ bigint: "a bigint",
23
+ boolean: "boolean",
24
+ null: "null",
25
+ number: "a number",
26
+ object: "an object",
27
+ string: "a string",
28
+ symbol: "a symbol",
29
+ undefined: "undefined"
35
30
  };
36
- const subdomainOf = (data)=>{
37
- const domain = domainOf(data);
38
- if (domain !== "object") {
39
- return domain;
40
- }
41
- if (Array.isArray(data)) {
42
- return "Array";
43
- }
44
- // The raw result will be something like [object Date]
45
- const prototypeName = Object.prototype.toString.call(data).slice(8, -1);
46
- if ((0, _genericsTs.isKeyOf)(prototypeName, objectSubdomains)) {
47
- return data instanceof objectSubdomains[prototypeName] ? prototypeName : "object";
48
- }
49
- if (prototypeName.endsWith("Error")) {
50
- return data instanceof Error ? "Error" : "object";
51
- }
52
- return "object";
53
- };
54
- const hasSubdomain = (data, subdomain)=>subdomainOf(data) === subdomain;
55
- const sizeOf = (data)=>sizedSubdomains[subdomainOf(data)]?.(data) ?? 0;
56
- const sizedSubdomains = {
57
- number: (data)=>data,
58
- string: (data)=>data.length,
59
- Array: (data)=>data.length
60
- };
61
- const unitsOf = (data)=>sizeUnits[subdomainOf(data)] ?? "";
62
- const sizeUnits = {
63
- number: "",
64
- string: "characters",
65
- Array: "items"
66
- };
67
- const classNameOf = (data)=>Object(data).constructor.name;
@@ -16,8 +16,7 @@ _export(exports, {
16
16
  hasKey: ()=>hasKey,
17
17
  keyCount: ()=>keyCount,
18
18
  hasKeys: ()=>hasKeys,
19
- listFrom: ()=>listFrom,
20
- collapseIfSingleton: ()=>collapseIfSingleton
19
+ listFrom: ()=>listFrom
21
20
  });
22
21
  const _domainsTs = require("./domains.js");
23
22
  const asConst = (t)=>t;
@@ -33,4 +32,3 @@ const hasKeys = (value)=>(0, _domainsTs.hasDomain)(value, "object") ? Object.key
33
32
  const listFrom = (data)=>Array.isArray(data) ? data : [
34
33
  data
35
34
  ];
36
- const collapseIfSingleton = (array)=>array.length === 1 ? array[0] : array;
@@ -0,0 +1,64 @@
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
+ objectKindOf: ()=>objectKindOf,
13
+ hasObjectKind: ()=>hasObjectKind,
14
+ isArray: ()=>isArray,
15
+ objectKindDescriptions: ()=>objectKindDescriptions
16
+ });
17
+ const _domainsTs = require("./domains.js");
18
+ // Built-in object constructors based on a subset of:
19
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
20
+ const defaultObjectKinds = {
21
+ Array,
22
+ Date,
23
+ Error,
24
+ Function,
25
+ Map,
26
+ RegExp,
27
+ Set,
28
+ Object,
29
+ String,
30
+ Number,
31
+ Boolean,
32
+ WeakMap,
33
+ WeakSet,
34
+ Promise
35
+ };
36
+ const objectKindOf = (data, kinds)=>{
37
+ if ((0, _domainsTs.domainOf)(data) !== "object") {
38
+ return undefined;
39
+ }
40
+ const kindSet = kinds ?? defaultObjectKinds;
41
+ let prototype = Object.getPrototypeOf(data);
42
+ while(prototype?.constructor && (!kindSet[prototype.constructor.name] || !(data instanceof kindSet[prototype.constructor.name]))){
43
+ prototype = Object.getPrototypeOf(prototype);
44
+ }
45
+ return prototype?.constructor?.name;
46
+ };
47
+ const hasObjectKind = (data, kind, kinds)=>objectKindOf(data, kinds) === kind;
48
+ const isArray = (data)=>Array.isArray(data);
49
+ const objectKindDescriptions = {
50
+ Object: "an object",
51
+ Array: "an array",
52
+ Function: "a function",
53
+ Date: "a Date",
54
+ RegExp: "a RegExp",
55
+ Error: "an Error",
56
+ Map: "a Map",
57
+ Set: "a Set",
58
+ String: "a String object",
59
+ Number: "a Number object",
60
+ Boolean: "a Boolean object",
61
+ Promise: "a Promise",
62
+ WeakMap: "a WeakMap",
63
+ WeakSet: "a WeakSet"
64
+ };
@@ -0,0 +1,16 @@
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
+ sizeOf: ()=>sizeOf,
13
+ unitsOf: ()=>unitsOf
14
+ });
15
+ const sizeOf = (data)=>typeof data === "string" || Array.isArray(data) ? data.length : typeof data === "number" ? data : 0;
16
+ const unitsOf = (data)=>typeof data === "string" ? "characters" : Array.isArray(data) ? "items" : "";
package/dist/mjs/main.js CHANGED
@@ -89,7 +89,7 @@ const scopeRegistry = {};
89
89
  var _resolutions = /*#__PURE__*/ new WeakMap(), _exports = /*#__PURE__*/ new WeakMap(), _anonymousTypeCount = /*#__PURE__*/ new WeakMap(), _register = /*#__PURE__*/ new WeakSet(), _cacheSpaces = /*#__PURE__*/ new WeakSet(), _initializeContext = /*#__PURE__*/ new WeakSet(), _compiled = /*#__PURE__*/ new WeakMap(), _resolveRecurse = /*#__PURE__*/ new WeakSet();
90
90
  export class Scope {
91
91
  createAnonymousTypeName() {
92
- return `anonymousType${++_classPrivateFieldUpdate(this, _anonymousTypeCount).value}`;
92
+ return `type${++_classPrivateFieldUpdate(this, _anonymousTypeCount).value}`;
93
93
  }
94
94
  get infer() {
95
95
  return chainableNoOpProxy;
@@ -222,10 +222,10 @@ function resolveRecurse(name, onUnresolvable, seen) {
222
222
  }
223
223
  // TODO: merge scope options
224
224
  const initializeType = (definition, opts, scope)=>{
225
- const name = opts.name ?? scope.createAnonymousTypeName();
225
+ const name = opts.name ?? "type";
226
226
  const meta = {
227
227
  name,
228
- id: `${scope.name}.${name}`,
228
+ id: `${scope.name}.${opts.name ? name : scope.createAnonymousTypeName()}`,
229
229
  definition,
230
230
  scope,
231
231
  problems: compileProblemOptions(opts.problems),
@@ -302,7 +302,7 @@ const always = {
302
302
  undefined: true
303
303
  };
304
304
  export const scope = (aliases, opts = {})=>new Scope(aliases, opts);
305
- const ts = scope({
305
+ const tsKeywords = scope({
306
306
  any: [
307
307
  "node",
308
308
  always
@@ -384,21 +384,130 @@ const ts = scope({
384
384
  {
385
385
  undefined: true
386
386
  }
387
- ],
388
- // TODO: Add remaining JS object types
387
+ ]
388
+ }, {
389
+ name: "ts",
390
+ standard: false
391
+ });
392
+ const tsKeywordsSpace = tsKeywords.compile();
393
+ const jsObjects = scope({
389
394
  Function: [
390
395
  "node",
391
396
  {
392
397
  object: {
393
- subdomain: "Function"
398
+ objectKind: "Function"
399
+ }
400
+ }
401
+ ],
402
+ Array: [
403
+ "node",
404
+ {
405
+ object: {
406
+ objectKind: "Array"
407
+ }
408
+ }
409
+ ],
410
+ Date: [
411
+ "node",
412
+ {
413
+ object: {
414
+ objectKind: "Date"
415
+ }
416
+ }
417
+ ],
418
+ Error: [
419
+ "node",
420
+ {
421
+ object: {
422
+ objectKind: "Error"
423
+ }
424
+ }
425
+ ],
426
+ Map: [
427
+ "node",
428
+ {
429
+ object: {
430
+ objectKind: "Map"
431
+ }
432
+ }
433
+ ],
434
+ RegExp: [
435
+ "node",
436
+ {
437
+ object: {
438
+ objectKind: "RegExp"
439
+ }
440
+ }
441
+ ],
442
+ Set: [
443
+ "node",
444
+ {
445
+ object: {
446
+ objectKind: "Set"
447
+ }
448
+ }
449
+ ],
450
+ Object: [
451
+ "node",
452
+ {
453
+ object: {
454
+ objectKind: "Object"
455
+ }
456
+ }
457
+ ],
458
+ String: [
459
+ "node",
460
+ {
461
+ object: {
462
+ objectKind: "String"
463
+ }
464
+ }
465
+ ],
466
+ Number: [
467
+ "node",
468
+ {
469
+ object: {
470
+ objectKind: "Number"
471
+ }
472
+ }
473
+ ],
474
+ Boolean: [
475
+ "node",
476
+ {
477
+ object: {
478
+ objectKind: "Boolean"
479
+ }
480
+ }
481
+ ],
482
+ WeakMap: [
483
+ "node",
484
+ {
485
+ object: {
486
+ objectKind: "WeakMap"
487
+ }
488
+ }
489
+ ],
490
+ WeakSet: [
491
+ "node",
492
+ {
493
+ object: {
494
+ objectKind: "WeakSet"
495
+ }
496
+ }
497
+ ],
498
+ Promise: [
499
+ "node",
500
+ {
501
+ object: {
502
+ objectKind: "Promise"
394
503
  }
395
504
  }
396
505
  ]
397
506
  }, {
398
- name: "ts",
507
+ name: "jsObjects",
399
508
  standard: false
400
509
  });
401
- const tsTypes = ts.compile();
510
+ const jsObjectsSpace = jsObjects.compile();
402
511
  const validation = scope({
403
512
  email: /^(.+)@(.+)\.(.+)$/,
404
513
  alphanumeric: /^[dA-Za-z]+$/,
@@ -417,24 +526,27 @@ const validation = scope({
417
526
  name: "validation",
418
527
  standard: false
419
528
  });
420
- const validationTypes = validation.compile();
529
+ const validationSpace = validation.compile();
421
530
  const standard = scope({}, {
422
531
  name: "standard",
423
532
  includes: [
424
- tsTypes,
425
- validationTypes
533
+ tsKeywordsSpace,
534
+ jsObjectsSpace,
535
+ validationSpace
426
536
  ],
427
537
  standard: false
428
538
  });
429
539
  const standardTypes = standard.compile();
430
540
  export const scopes = {
431
- ts,
541
+ tsKeywords,
542
+ jsObjects,
432
543
  validation,
433
544
  standard
434
545
  };
435
546
  export const spaces = {
436
- ts: tsTypes,
437
- validation: validationTypes,
547
+ tsKeywords: tsKeywordsSpace,
548
+ jsObjects: jsObjectsSpace,
549
+ validation: validationSpace,
438
550
  standard: standardTypes
439
551
  };
440
552
  export const type = scopes.standard.type;
@@ -2,13 +2,13 @@ import { domainOf, hasDomain } from "../utils/domains.js";
2
2
  import { throwInternalError } from "../utils/errors.js";
3
3
  import { isDisjoint, isEquality } from "./compose.js";
4
4
  import { branchIntersection } from "./rules/rules.js";
5
- export const isBranchComparison = (comparison)=>comparison?.lConditions !== undefined;
5
+ export const isBranchComparison = (comparison)=>comparison?.lBranches !== undefined;
6
6
  export const compareBranches = (lConditions, rConditions, state)=>{
7
7
  const result = {
8
- lConditions,
9
- rConditions,
10
- lSubconditionsOfR: [],
11
- rSubconditionsOfL: [],
8
+ lBranches: lConditions,
9
+ rBranches: rConditions,
10
+ lExtendsR: [],
11
+ rExtendsL: [],
12
12
  equalities: [],
13
13
  distinctIntersections: []
14
14
  };
@@ -28,14 +28,14 @@ export const compareBranches = (lConditions, rConditions, state)=>{
28
28
  // doesn't tell us about any redundancies or add a distinct pair
29
29
  return null;
30
30
  } else if (subresult === l) {
31
- result.lSubconditionsOfR.push(lIndex);
31
+ result.lExtendsR.push(lIndex);
32
32
  // If l is a subtype of the current r branch, intersections
33
33
  // with the remaining branches of r won't lead to distinct
34
34
  // branches, so we set a flag indicating we can skip them.
35
35
  lImpliesR = true;
36
36
  return null;
37
37
  } else if (subresult === r) {
38
- result.rSubconditionsOfL.push(rIndex);
38
+ result.rExtendsL.push(rIndex);
39
39
  // If r is a subtype of the current l branch, it is removed
40
40
  // from pairsByR because future intersections won't lead to
41
41
  // distinct branches.
@@ -46,13 +46,14 @@ export const composeIntersection = (reducer)=>(l, r, state)=>l === undefined ? r
46
46
  export const throwUndefinedOperandsError = ()=>throwInternalError(`Unexpected operation two undefined operands`);
47
47
  export const disjointDescriptionWriters = {
48
48
  domain: ({ l , r })=>`${l.join(", ")} and ${r.join(", ")}`,
49
- subdomain: ({ l , r })=>`${l} and ${r}`,
49
+ objectKind: ({ l , r })=>`${l} and ${r}`,
50
50
  range: ({ l , r })=>`${stringifyRange(l)} and ${stringifyRange(r)}`,
51
51
  class: ({ l , r })=>`classes ${l.name} and ${r.name}`,
52
52
  tupleLength: ({ l , r })=>`tuples of length ${l} and ${r}`,
53
53
  value: ({ l , r })=>`literal values ${serialize(l)} and ${serialize(r)}`,
54
54
  leftAssignability: ({ l , r })=>`literal value ${serialize(l.value)} and ${serialize(r)}`,
55
- rightAssignability: ({ l , r })=>`literal value ${serialize(r.value)} and ${serialize(l)}`
55
+ rightAssignability: ({ l , r })=>`literal value ${serialize(r.value)} and ${serialize(l)}`,
56
+ union: ({ l , r })=>`branches ${serialize(l)} and branches ${serialize(r)}`
56
57
  };
57
58
  export const stringifyRange = (range)=>"limit" in range ? `the range of exactly ${range.limit}` : range.min ? range.max ? `the range bounded by ${range.min.comparator}${range.min.limit} and ${range.max.comparator}${range.max.limit}` : `${range.min.comparator}${range.min.limit}` : range.max ? `${range.max.comparator}${range.max.limit}` : "the unbounded range";
58
59
  var _disjoints = /*#__PURE__*/ new WeakMap();
@@ -1,7 +1,8 @@
1
1
  import { writeUndiscriminatableMorphUnionMessage } from "../parse/string/ast.js";
2
- import { domainOf, hasSubdomain, subdomainOf } from "../utils/domains.js";
2
+ import { domainOf } from "../utils/domains.js";
3
3
  import { throwParseError } from "../utils/errors.js";
4
4
  import { hasKey, isKeyOf, keysOf } from "../utils/generics.js";
5
+ import { isArray, objectKindOf } from "../utils/objectKinds.js";
5
6
  import { Path } from "../utils/paths.js";
6
7
  import { serializePrimitive } from "../utils/serialize.js";
7
8
  import { IntersectionState } from "./compose.js";
@@ -44,7 +45,7 @@ const discriminate = (originalBranches, remainingIndices, discriminants, ctx)=>{
44
45
  };
45
46
  const discriminantKinds = {
46
47
  domain: true,
47
- subdomain: true,
48
+ objectKind: true,
48
49
  value: true
49
50
  };
50
51
  const calculateDiscriminants = (branches, ctx)=>{
@@ -61,7 +62,7 @@ const calculateDiscriminants = (branches, ctx)=>{
61
62
  const intersectionState = new IntersectionState(ctx.type, "|");
62
63
  branchIntersection(branches[lIndex], branches[rIndex], intersectionState);
63
64
  for(const path in intersectionState.disjoints){
64
- // designed to match subdomain path segments like "${number}"
65
+ // designed to match objectKind path segments like "${number}"
65
66
  if (path.includes("${")) {
66
67
  continue;
67
68
  }
@@ -176,9 +177,9 @@ const serializeIfPrimitive = (data)=>{
176
177
  };
177
178
  const caseSerializers = {
178
179
  value: (data)=>serializeIfPrimitive(data) ?? "default",
179
- subdomain: subdomainOf,
180
+ objectKind: (data)=>objectKindOf(data) ?? "default",
180
181
  domain: domainOf
181
182
  };
182
183
  export const serializeCase = (kind, data)=>caseSerializers[kind](data);
183
184
  const branchIncludesMorph = (branch, $)=>"morph" in branch ? true : "props" in branch ? Object.values(branch.props).some((prop)=>nodeIncludesMorph(isOptional(prop) ? prop[1] : prop, $)) : false;
184
- const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).meta.includesMorph : Object.values(node).some((predicate)=>predicate === true ? false : hasSubdomain(predicate, "Array") ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));
185
+ const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).meta.includesMorph : Object.values(node).some((predicate)=>predicate === true ? false : isArray(predicate) ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));
@@ -1,7 +1,7 @@
1
1
  export const functors = {
2
2
  Array: (node)=>({
3
3
  object: {
4
- subdomain: [
4
+ objectKind: [
5
5
  "Array",
6
6
  node
7
7
  ]
@@ -9,7 +9,7 @@ export const functors = {
9
9
  }),
10
10
  Set: (node)=>({
11
11
  object: {
12
- subdomain: [
12
+ objectKind: [
13
13
  "Set",
14
14
  node
15
15
  ]
@@ -17,7 +17,7 @@ export const functors = {
17
17
  }),
18
18
  Map: (k, v)=>({
19
19
  object: {
20
- subdomain: [
20
+ objectKind: [
21
21
  "Map",
22
22
  k,
23
23
  v
@@ -43,7 +43,7 @@ export const union = (l, r, type)=>{
43
43
  }
44
44
  return result;
45
45
  };
46
- const hasImpliedDomain = (flatPredicate)=>flatPredicate[0] && (flatPredicate[0][0] === "subdomain" || flatPredicate[0][0] === "value");
46
+ const hasImpliedDomain = (flatPredicate)=>flatPredicate[0] && (flatPredicate[0][0] === "objectKind" || flatPredicate[0][0] === "value");
47
47
  export const flattenType = (type)=>{
48
48
  const ctx = {
49
49
  type,