arktype 0.1.4 → 0.3.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 (106) hide show
  1. package/README.md +1 -1
  2. package/dist/api.cjs +4 -3
  3. package/dist/api.d.ts +3 -2
  4. package/dist/api.mjs +2 -1
  5. package/dist/cjs/nodes/{branches.js → branch.js} +56 -10
  6. package/dist/cjs/nodes/compose.js +1 -2
  7. package/dist/cjs/nodes/discriminate.js +7 -13
  8. package/dist/cjs/nodes/node.js +32 -4
  9. package/dist/cjs/nodes/predicate.js +7 -7
  10. package/dist/cjs/nodes/rules/class.js +10 -4
  11. package/dist/cjs/nodes/rules/divisor.js +1 -5
  12. package/dist/cjs/nodes/rules/props.js +75 -25
  13. package/dist/cjs/nodes/rules/range.js +1 -5
  14. package/dist/cjs/nodes/rules/regex.js +2 -44
  15. package/dist/cjs/nodes/rules/rules.js +21 -61
  16. package/dist/cjs/parse/definition.js +2 -2
  17. package/dist/cjs/parse/string/reduce/dynamic.js +1 -2
  18. package/dist/cjs/parse/string/shift/operator/bounds.js +1 -1
  19. package/dist/cjs/parse/string/string.js +2 -2
  20. package/dist/cjs/parse/tuple/keyof.js +37 -18
  21. package/dist/cjs/parse/tuple/morph.js +7 -6
  22. package/dist/cjs/parse/tuple/tuple.js +16 -9
  23. package/dist/cjs/scopes/cache.js +39 -0
  24. package/dist/cjs/scopes/jsObjects.js +133 -0
  25. package/dist/cjs/{main.js → scopes/scope.js} +31 -364
  26. package/dist/cjs/scopes/standard.js +44 -0
  27. package/dist/cjs/scopes/tsKeywords.js +113 -0
  28. package/dist/cjs/scopes/type.js +67 -0
  29. package/dist/cjs/scopes/validation.js +64 -0
  30. package/dist/cjs/traverse/problems.js +55 -95
  31. package/dist/cjs/traverse/traverse.js +127 -134
  32. package/dist/cjs/utils/numericLiterals.js +3 -0
  33. package/dist/cjs/utils/objectKinds.js +1 -2
  34. package/dist/mjs/nodes/{branches.js → branch.js} +45 -2
  35. package/dist/mjs/nodes/compose.js +1 -2
  36. package/dist/mjs/nodes/discriminate.js +6 -12
  37. package/dist/mjs/nodes/node.js +30 -3
  38. package/dist/mjs/nodes/predicate.js +2 -2
  39. package/dist/mjs/nodes/rules/class.js +10 -4
  40. package/dist/mjs/nodes/rules/divisor.js +1 -5
  41. package/dist/mjs/nodes/rules/props.js +74 -27
  42. package/dist/mjs/nodes/rules/range.js +1 -5
  43. package/dist/mjs/nodes/rules/regex.js +1 -43
  44. package/dist/mjs/nodes/rules/rules.js +22 -61
  45. package/dist/mjs/parse/definition.js +1 -1
  46. package/dist/mjs/parse/string/reduce/dynamic.js +2 -3
  47. package/dist/mjs/parse/string/shift/operator/bounds.js +1 -1
  48. package/dist/mjs/parse/string/string.js +2 -2
  49. package/dist/mjs/parse/tuple/keyof.js +38 -19
  50. package/dist/mjs/parse/tuple/morph.js +7 -6
  51. package/dist/mjs/parse/tuple/tuple.js +17 -10
  52. package/dist/mjs/scopes/cache.js +25 -0
  53. package/dist/mjs/scopes/jsObjects.js +119 -0
  54. package/dist/mjs/{main.js → scopes/scope.js} +15 -344
  55. package/dist/mjs/scopes/standard.js +27 -0
  56. package/dist/mjs/scopes/tsKeywords.js +99 -0
  57. package/dist/mjs/scopes/type.js +53 -0
  58. package/dist/mjs/scopes/validation.js +51 -0
  59. package/dist/mjs/traverse/problems.js +55 -95
  60. package/dist/mjs/traverse/traverse.js +129 -135
  61. package/dist/mjs/utils/numericLiterals.js +2 -1
  62. package/dist/mjs/utils/objectKinds.js +1 -1
  63. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  64. package/dist/types/nodes/branch.d.ts +36 -0
  65. package/dist/types/nodes/compose.d.ts +6 -11
  66. package/dist/types/nodes/discriminate.d.ts +1 -1
  67. package/dist/types/nodes/infer.d.ts +16 -15
  68. package/dist/types/nodes/node.d.ts +18 -9
  69. package/dist/types/nodes/predicate.d.ts +18 -57
  70. package/dist/types/nodes/rules/class.d.ts +3 -2
  71. package/dist/types/nodes/rules/divisor.d.ts +2 -1
  72. package/dist/types/nodes/rules/props.d.ts +19 -11
  73. package/dist/types/nodes/rules/range.d.ts +2 -1
  74. package/dist/types/nodes/rules/regex.d.ts +2 -11
  75. package/dist/types/nodes/rules/rules.d.ts +11 -21
  76. package/dist/types/parse/definition.d.ts +1 -1
  77. package/dist/types/parse/string/ast.d.ts +4 -2
  78. package/dist/types/parse/string/reduce/shared.d.ts +1 -1
  79. package/dist/types/parse/string/reduce/static.d.ts +1 -1
  80. package/dist/types/parse/string/shift/operator/bounds.d.ts +1 -1
  81. package/dist/types/parse/string/string.d.ts +1 -1
  82. package/dist/types/parse/tuple/keyof.d.ts +2 -2
  83. package/dist/types/parse/tuple/morph.d.ts +1 -1
  84. package/dist/types/parse/tuple/narrow.d.ts +1 -1
  85. package/dist/types/parse/tuple/tuple.d.ts +1 -1
  86. package/dist/types/scopes/cache.d.ts +14 -0
  87. package/dist/types/scopes/jsObjects.d.ts +36 -0
  88. package/dist/types/scopes/scope.d.ts +76 -0
  89. package/dist/types/scopes/standard.d.ts +280 -0
  90. package/dist/types/scopes/tsKeywords.d.ts +32 -0
  91. package/dist/types/scopes/type.d.ts +47 -0
  92. package/dist/types/scopes/validation.d.ts +21 -0
  93. package/dist/types/traverse/problems.d.ts +35 -53
  94. package/dist/types/traverse/traverse.d.ts +30 -24
  95. package/dist/types/utils/generics.d.ts +0 -1
  96. package/dist/types/utils/numericLiterals.d.ts +2 -0
  97. package/dist/types/utils/objectKinds.d.ts +43 -43
  98. package/package.json +2 -3
  99. package/dist/cjs/nodes/functors.js +0 -35
  100. package/dist/cjs/nodes/rules/objectKind.js +0 -78
  101. package/dist/mjs/nodes/functors.js +0 -27
  102. package/dist/mjs/nodes/rules/objectKind.js +0 -63
  103. package/dist/types/main.d.ts +0 -324
  104. package/dist/types/nodes/branches.d.ts +0 -14
  105. package/dist/types/nodes/functors.d.ts +0 -6
  106. package/dist/types/nodes/rules/objectKind.d.ts +0 -15
@@ -12,20 +12,15 @@ _export(exports, {
12
12
  Scope: ()=>Scope,
13
13
  writeShallowCycleErrorMessage: ()=>writeShallowCycleErrorMessage,
14
14
  scope: ()=>scope,
15
- scopes: ()=>scopes,
16
- spaces: ()=>spaces,
17
- type: ()=>type,
18
- writeDuplicateAliasesMessage: ()=>writeDuplicateAliasesMessage,
19
- isType: ()=>isType
15
+ writeDuplicateAliasesMessage: ()=>writeDuplicateAliasesMessage
20
16
  });
21
- const _nodeJs = require("./nodes/node.js");
22
- const _definitionJs = require("./parse/definition.js");
23
- const _problemsTs = require("./traverse/problems.js");
24
- const _traverseTs = require("./traverse/traverse.js");
25
- const _chainableNoOpProxyJs = require("./utils/chainableNoOpProxy.js");
26
- const _errorsJs = require("./utils/errors.js");
27
- const _freezeTs = require("./utils/freeze.js");
28
- const _pathsTs = require("./utils/paths.js");
17
+ const _nodeTs = require("../nodes/node.js");
18
+ const _definitionTs = require("../parse/definition.js");
19
+ const _chainableNoOpProxyTs = require("../utils/chainableNoOpProxy.js");
20
+ const _errorsTs = require("../utils/errors.js");
21
+ const _pathsTs = require("../utils/paths.js");
22
+ const _cacheTs = require("./cache.js");
23
+ const _typeTs = require("./type.js");
29
24
  function _checkPrivateRedeclaration(obj, privateCollection) {
30
25
  if (privateCollection.has(obj)) {
31
26
  throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -106,20 +101,21 @@ function _classPrivateMethodInit(obj, privateSet) {
106
101
  var _ctx_type_meta;
107
102
  let anonymousScopeCount = 0;
108
103
  const scopeRegistry = {};
109
- 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();
104
+ const spaceRegistry = {};
105
+ 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(), _resolveRecurse = /*#__PURE__*/ new WeakSet();
110
106
  class Scope {
111
107
  createAnonymousTypeSuffix() {
112
108
  return ++_classPrivateFieldUpdate(this, _anonymousTypeCount).value;
113
109
  }
114
110
  get infer() {
115
- return _chainableNoOpProxyJs.chainableNoOpProxy;
111
+ return _chainableNoOpProxyTs.chainableNoOpProxy;
116
112
  }
117
113
  compile() {
118
- if (!_classPrivateFieldGet(this, _compiled)) {
114
+ if (!spaceRegistry[this.name]) {
119
115
  for(const name in this.aliases){
120
116
  this.resolve(name);
121
117
  }
122
- _classPrivateFieldSet(this, _compiled, true);
118
+ spaceRegistry[this.name] = _classPrivateFieldGet(this, _exports).root;
123
119
  }
124
120
  return _classPrivateFieldGet(this, _exports).root;
125
121
  }
@@ -157,31 +153,26 @@ class Scope {
157
153
  writable: true,
158
154
  value: void 0
159
155
  });
160
- _classPrivateFieldInit(this, _compiled, {
161
- writable: true,
162
- value: void 0
163
- });
164
156
  this.aliases = aliases;
165
157
  this.opts = opts;
166
- this.parseCache = new FreezingCache();
167
- _classPrivateFieldSet(this, _resolutions, new Cache());
168
- _classPrivateFieldSet(this, _exports, new Cache());
158
+ this.parseCache = new _cacheTs.FreezingCache();
159
+ _classPrivateFieldSet(this, _resolutions, new _cacheTs.Cache());
160
+ _classPrivateFieldSet(this, _exports, new _cacheTs.Cache());
169
161
  _classPrivateFieldSet(this, _anonymousTypeCount, 0);
170
162
  this.type = (def, opts = {})=>{
171
163
  if (opts.name && this.aliases[opts.name]) {
172
- return (0, _errorsJs.throwParseError)(writeDuplicateAliasesMessage(opts.name));
164
+ return (0, _errorsTs.throwParseError)(writeDuplicateAliasesMessage(opts.name));
173
165
  }
174
- const result = initializeType(def, opts, this);
166
+ const result = (0, _typeTs.initializeType)(def, opts, this);
175
167
  const ctx = _classPrivateMethodGet(this, _initializeContext, initializeContext).call(this, result);
176
- result.node = this.resolveNode((0, _definitionJs.parseDefinition)(def, ctx));
177
- result.flat = (0, _nodeJs.flattenType)(result);
168
+ result.node = this.resolveNode((0, _definitionTs.parseDefinition)(def, ctx));
169
+ result.flat = (0, _nodeTs.flattenType)(result);
178
170
  return result;
179
171
  };
180
- _classPrivateFieldSet(this, _compiled, false);
181
172
  this.name = _classPrivateMethodGet(this, _register, register).call(this, opts);
182
173
  if (opts.standard !== false) {
183
174
  _classPrivateMethodGet(this, _cacheSpaces, cacheSpaces).call(this, [
184
- standardTypes
175
+ spaceRegistry["standard"]
185
176
  ], "imports");
186
177
  }
187
178
  if (opts.imports) {
@@ -190,10 +181,13 @@ class Scope {
190
181
  if (opts.includes) {
191
182
  _classPrivateMethodGet(this, _cacheSpaces, cacheSpaces).call(this, opts.includes, "includes");
192
183
  }
184
+ if (opts.config) {
185
+ this.config = opts.config;
186
+ }
193
187
  }
194
188
  }
195
189
  function register(opts) {
196
- const name = opts.name ? scopeRegistry[opts.name] ? (0, _errorsJs.throwParseError)(`A scope named '${opts.name}' already exists`) : opts.name : `scope${++anonymousScopeCount}`;
190
+ const name = opts.name ? scopeRegistry[opts.name] ? (0, _errorsTs.throwParseError)(`A scope named '${opts.name}' already exists`) : opts.name : `scope${++anonymousScopeCount}`;
197
191
  scopeRegistry[name] = this;
198
192
  return name;
199
193
  }
@@ -201,7 +195,7 @@ function cacheSpaces(spaces, kind) {
201
195
  for (const space of spaces){
202
196
  for(const name in space){
203
197
  if (_classPrivateFieldGet(this, _resolutions).has(name) || name in this.aliases) {
204
- (0, _errorsJs.throwParseError)(writeDuplicateAliasesMessage(name));
198
+ (0, _errorsTs.throwParseError)(writeDuplicateAliasesMessage(name));
205
199
  }
206
200
  _classPrivateFieldGet(this, _resolutions).set(name, space[name]);
207
201
  if (kind === "includes") {
@@ -222,356 +216,29 @@ function resolveRecurse(name, onUnresolvable, seen) {
222
216
  return maybeCacheResult;
223
217
  }
224
218
  if (!this.aliases[name]) {
225
- return onUnresolvable === "throw" ? (0, _errorsJs.throwInternalError)(`Unexpectedly failed to resolve alias '${name}'`) : undefined;
219
+ return onUnresolvable === "throw" ? (0, _errorsTs.throwInternalError)(`Unexpectedly failed to resolve alias '${name}'`) : undefined;
226
220
  }
227
- // TODO: opts?
228
- const type = initializeType(this.aliases[name], {
221
+ const type = (0, _typeTs.initializeType)(this.aliases[name], {
229
222
  name
230
223
  }, this);
231
224
  _classPrivateFieldGet(this, _resolutions).set(name, type);
232
225
  _classPrivateFieldGet(this, _exports).set(name, type);
233
226
  const ctx = _classPrivateMethodGet(this, _initializeContext, initializeContext).call(this, type);
234
- let resolution = (0, _definitionJs.parseDefinition)(type.meta.definition, ctx);
227
+ let resolution = (0, _definitionTs.parseDefinition)(type.meta.definition, ctx);
235
228
  if (typeof resolution === "string") {
236
229
  if (seen.includes(resolution)) {
237
- return (0, _errorsJs.throwParseError)(writeShallowCycleErrorMessage(name, seen));
230
+ return (0, _errorsTs.throwParseError)(writeShallowCycleErrorMessage(name, seen));
238
231
  }
239
232
  seen.push(resolution);
240
233
  resolution = _classPrivateMethodGet(this, _resolveRecurse, resolveRecurse).call(this, resolution, "throw", seen).node;
241
234
  }
242
235
  type.node = resolution;
243
- type.flat = (0, _nodeJs.flattenType)(type);
244
- return type;
245
- }
246
- // TODO: merge scope options
247
- const initializeType = (definition, opts, scope)=>{
248
- const name = opts.name ?? "type";
249
- const meta = {
250
- name,
251
- id: `${scope.name}.${opts.name ? name : `type${scope.createAnonymousTypeSuffix()}`}`,
252
- definition,
253
- scope,
254
- problems: (0, _problemsTs.compileProblemOptions)(opts.problems),
255
- includesMorph: false
256
- };
257
- const root = {
258
- // temporarily initialize node/flat to aliases that will be included in
259
- // the final type in case of cyclic resolutions
260
- node: name,
261
- flat: [
262
- [
263
- "alias",
264
- name
265
- ]
266
- ],
267
- meta,
268
- infer: _chainableNoOpProxyJs.chainableNoOpProxy
269
- };
270
- // dynamically assign a name to the primary traversal function
271
- const namedTraverse = {
272
- [name]: (data)=>{
273
- const state = new _traverseTs.TraversalState(type);
274
- const out = (0, _traverseTs.traverse)(data, type.flat, state);
275
- return state.problems.length ? {
276
- data,
277
- problems: state.problems
278
- } : {
279
- data,
280
- out
281
- };
282
- }
283
- }[name];
284
- // we need to assign this to a variable before returning so we can reference
285
- // it in namedTraverse
286
- const type = Object.assign(namedTraverse, root);
236
+ type.flat = (0, _nodeTs.flattenType)(type);
287
237
  return type;
288
- };
289
- class Cache {
290
- get root() {
291
- return this.cache;
292
- }
293
- has(name) {
294
- return name in this.cache;
295
- }
296
- get(name) {
297
- return this.cache[name];
298
- }
299
- set(name, item) {
300
- this.cache[name] = item;
301
- return item;
302
- }
303
- constructor(){
304
- this.cache = {};
305
- }
306
- }
307
- class FreezingCache extends Cache {
308
- set(name, item) {
309
- this.cache[name] = (0, _freezeTs.deepFreeze)(item);
310
- return item;
311
- }
312
238
  }
313
239
  const writeShallowCycleErrorMessage = (name, seen)=>`Alias '${name}' has a shallow resolution cycle: ${[
314
240
  ...seen,
315
241
  name
316
242
  ].join("=>")}`;
317
- const always = {
318
- bigint: true,
319
- boolean: true,
320
- null: true,
321
- number: true,
322
- object: true,
323
- string: true,
324
- symbol: true,
325
- undefined: true
326
- };
327
243
  const scope = (aliases, opts = {})=>new Scope(aliases, opts);
328
- const tsKeywords = scope({
329
- any: [
330
- "node",
331
- always
332
- ],
333
- bigint: [
334
- "node",
335
- {
336
- bigint: true
337
- }
338
- ],
339
- boolean: [
340
- "node",
341
- {
342
- boolean: true
343
- }
344
- ],
345
- false: [
346
- "node",
347
- {
348
- boolean: {
349
- value: false
350
- }
351
- }
352
- ],
353
- never: [
354
- "node",
355
- {}
356
- ],
357
- null: [
358
- "node",
359
- {
360
- null: true
361
- }
362
- ],
363
- number: [
364
- "node",
365
- {
366
- number: true
367
- }
368
- ],
369
- object: [
370
- "node",
371
- {
372
- object: true
373
- }
374
- ],
375
- string: [
376
- "node",
377
- {
378
- string: true
379
- }
380
- ],
381
- symbol: [
382
- "node",
383
- {
384
- symbol: true
385
- }
386
- ],
387
- true: [
388
- "node",
389
- {
390
- boolean: {
391
- value: true
392
- }
393
- }
394
- ],
395
- unknown: [
396
- "node",
397
- always
398
- ],
399
- void: [
400
- "node",
401
- {
402
- undefined: true
403
- }
404
- ],
405
- undefined: [
406
- "node",
407
- {
408
- undefined: true
409
- }
410
- ]
411
- }, {
412
- name: "ts",
413
- standard: false
414
- });
415
- const tsKeywordsSpace = tsKeywords.compile();
416
- const jsObjects = scope({
417
- Function: [
418
- "node",
419
- {
420
- object: {
421
- objectKind: "Function"
422
- }
423
- }
424
- ],
425
- Array: [
426
- "node",
427
- {
428
- object: {
429
- objectKind: "Array"
430
- }
431
- }
432
- ],
433
- Date: [
434
- "node",
435
- {
436
- object: {
437
- objectKind: "Date"
438
- }
439
- }
440
- ],
441
- Error: [
442
- "node",
443
- {
444
- object: {
445
- objectKind: "Error"
446
- }
447
- }
448
- ],
449
- Map: [
450
- "node",
451
- {
452
- object: {
453
- objectKind: "Map"
454
- }
455
- }
456
- ],
457
- RegExp: [
458
- "node",
459
- {
460
- object: {
461
- objectKind: "RegExp"
462
- }
463
- }
464
- ],
465
- Set: [
466
- "node",
467
- {
468
- object: {
469
- objectKind: "Set"
470
- }
471
- }
472
- ],
473
- Object: [
474
- "node",
475
- {
476
- object: {
477
- objectKind: "Object"
478
- }
479
- }
480
- ],
481
- String: [
482
- "node",
483
- {
484
- object: {
485
- objectKind: "String"
486
- }
487
- }
488
- ],
489
- Number: [
490
- "node",
491
- {
492
- object: {
493
- objectKind: "Number"
494
- }
495
- }
496
- ],
497
- Boolean: [
498
- "node",
499
- {
500
- object: {
501
- objectKind: "Boolean"
502
- }
503
- }
504
- ],
505
- WeakMap: [
506
- "node",
507
- {
508
- object: {
509
- objectKind: "WeakMap"
510
- }
511
- }
512
- ],
513
- WeakSet: [
514
- "node",
515
- {
516
- object: {
517
- objectKind: "WeakSet"
518
- }
519
- }
520
- ],
521
- Promise: [
522
- "node",
523
- {
524
- object: {
525
- objectKind: "Promise"
526
- }
527
- }
528
- ]
529
- }, {
530
- name: "jsObjects",
531
- standard: false
532
- });
533
- const jsObjectsSpace = jsObjects.compile();
534
- const validation = scope({
535
- email: /^(.+)@(.+)\.(.+)$/,
536
- alphanumeric: /^[dA-Za-z]+$/,
537
- alpha: /^[A-Za-z]+$/,
538
- lowercase: /^[a-z]*$/,
539
- uppercase: /^[A-Z]*$/,
540
- integer: [
541
- "node",
542
- {
543
- number: {
544
- divisor: 1
545
- }
546
- }
547
- ]
548
- }, {
549
- name: "validation",
550
- standard: false
551
- });
552
- const validationSpace = validation.compile();
553
- const standard = scope({}, {
554
- name: "standard",
555
- includes: [
556
- tsKeywordsSpace,
557
- jsObjectsSpace,
558
- validationSpace
559
- ],
560
- standard: false
561
- });
562
- const standardTypes = standard.compile();
563
- const scopes = {
564
- tsKeywords,
565
- jsObjects,
566
- validation,
567
- standard
568
- };
569
- const spaces = {
570
- tsKeywords: tsKeywordsSpace,
571
- jsObjects: jsObjectsSpace,
572
- validation: validationSpace,
573
- standard: standardTypes
574
- };
575
- const type = scopes.standard.type;
576
244
  const writeDuplicateAliasesMessage = (name)=>`Alias '${name}' is already defined`;
577
- const isType = (value)=>value?.infer === _chainableNoOpProxyJs.chainableNoOpProxy;
@@ -0,0 +1,44 @@
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
+ standardScope: ()=>standardScope,
13
+ standard: ()=>standard,
14
+ scopes: ()=>scopes,
15
+ spaces: ()=>spaces,
16
+ type: ()=>type
17
+ });
18
+ const _jsObjectsTs = require("./jsObjects.js");
19
+ const _scopeTs = require("./scope.js");
20
+ const _tsKeywordsTs = require("./tsKeywords.js");
21
+ const _validationTs = require("./validation.js");
22
+ const standardScope = (0, _scopeTs.scope)({}, {
23
+ name: "standard",
24
+ includes: [
25
+ _tsKeywordsTs.tsKeywords,
26
+ _jsObjectsTs.jsObjects,
27
+ _validationTs.validation
28
+ ],
29
+ standard: false
30
+ });
31
+ const standard = standardScope.compile();
32
+ const scopes = {
33
+ tsKeywords: _tsKeywordsTs.tsKeywordsScope,
34
+ jsObjects: _jsObjectsTs.jsObjectsScope,
35
+ validation: _validationTs.validationScope,
36
+ standard: standardScope
37
+ };
38
+ const spaces = {
39
+ tsKeywords: _tsKeywordsTs.tsKeywords,
40
+ jsObjects: _jsObjectsTs.jsObjects,
41
+ validation: _validationTs.validation,
42
+ standard
43
+ };
44
+ const type = scopes.standard.type;
@@ -0,0 +1,113 @@
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
+ tsKeywordsScope: ()=>tsKeywordsScope,
13
+ tsKeywords: ()=>tsKeywords
14
+ });
15
+ const _scopeTs = require("./scope.js");
16
+ const always = {
17
+ bigint: true,
18
+ boolean: true,
19
+ null: true,
20
+ number: true,
21
+ object: true,
22
+ string: true,
23
+ symbol: true,
24
+ undefined: true
25
+ };
26
+ const tsKeywordsScope = (0, _scopeTs.scope)({
27
+ any: [
28
+ "node",
29
+ always
30
+ ],
31
+ bigint: [
32
+ "node",
33
+ {
34
+ bigint: true
35
+ }
36
+ ],
37
+ boolean: [
38
+ "node",
39
+ {
40
+ boolean: true
41
+ }
42
+ ],
43
+ false: [
44
+ "node",
45
+ {
46
+ boolean: {
47
+ value: false
48
+ }
49
+ }
50
+ ],
51
+ never: [
52
+ "node",
53
+ {}
54
+ ],
55
+ null: [
56
+ "node",
57
+ {
58
+ null: true
59
+ }
60
+ ],
61
+ number: [
62
+ "node",
63
+ {
64
+ number: true
65
+ }
66
+ ],
67
+ object: [
68
+ "node",
69
+ {
70
+ object: true
71
+ }
72
+ ],
73
+ string: [
74
+ "node",
75
+ {
76
+ string: true
77
+ }
78
+ ],
79
+ symbol: [
80
+ "node",
81
+ {
82
+ symbol: true
83
+ }
84
+ ],
85
+ true: [
86
+ "node",
87
+ {
88
+ boolean: {
89
+ value: true
90
+ }
91
+ }
92
+ ],
93
+ unknown: [
94
+ "node",
95
+ always
96
+ ],
97
+ void: [
98
+ "node",
99
+ {
100
+ undefined: true
101
+ }
102
+ ],
103
+ undefined: [
104
+ "node",
105
+ {
106
+ undefined: true
107
+ }
108
+ ]
109
+ }, {
110
+ name: "ts",
111
+ standard: false
112
+ });
113
+ const tsKeywords = tsKeywordsScope.compile();
@@ -0,0 +1,67 @@
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
+ initializeType: ()=>initializeType,
13
+ isType: ()=>isType
14
+ });
15
+ const _traverseTs = require("../traverse/traverse.js");
16
+ const _chainableNoOpProxyTs = require("../utils/chainableNoOpProxy.js");
17
+ const _genericsTs = require("../utils/generics.js");
18
+ const compileTypeConfig = (opts)=>{
19
+ if (opts === undefined) {
20
+ return;
21
+ }
22
+ const { name , ...config } = opts;
23
+ if ((0, _genericsTs.hasKeys)(config)) {
24
+ return config;
25
+ }
26
+ };
27
+ const initializeType = (definition, opts, scope)=>{
28
+ const name = opts?.name ?? "type";
29
+ const config = compileTypeConfig(opts);
30
+ const meta = {
31
+ name,
32
+ id: `${scope.name}.${opts?.name ? name : `type${scope.createAnonymousTypeSuffix()}`}`,
33
+ definition,
34
+ scope,
35
+ config,
36
+ includesMorph: false
37
+ };
38
+ const root = {
39
+ // temporarily initialize node/flat to aliases that will be included in
40
+ // the final type in case of cyclic resolutions
41
+ node: name,
42
+ flat: [
43
+ [
44
+ "alias",
45
+ name
46
+ ]
47
+ ],
48
+ meta,
49
+ infer: _chainableNoOpProxyTs.chainableNoOpProxy
50
+ };
51
+ // dynamically assign a name to the primary traversal function
52
+ const namedTraverse = {
53
+ [name]: (data)=>{
54
+ const state = new _traverseTs.TraversalState(data, type);
55
+ return (0, _traverseTs.traverse)(type.flat, state) ? {
56
+ data: state.data
57
+ } : {
58
+ problems: state.problems
59
+ };
60
+ }
61
+ }[name];
62
+ // we need to assign this to a variable before returning so we can reference
63
+ // it in namedTraverse
64
+ const type = Object.assign(namedTraverse, root);
65
+ return type;
66
+ };
67
+ const isType = (value)=>value?.infer === _chainableNoOpProxyTs.chainableNoOpProxy;