arktype 0.1.4 → 0.2.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.
- package/README.md +1 -1
- package/dist/api.cjs +4 -3
- package/dist/api.d.ts +3 -2
- package/dist/api.mjs +2 -1
- package/dist/cjs/nodes/node.js +20 -2
- package/dist/cjs/nodes/predicate.js +2 -0
- package/dist/cjs/nodes/rules/regex.js +4 -42
- package/dist/cjs/nodes/rules/rules.js +15 -11
- package/dist/cjs/parse/definition.js +2 -2
- package/dist/cjs/parse/tuple/morph.js +7 -6
- package/dist/cjs/scopes/cache.js +39 -0
- package/dist/cjs/scopes/jsObjects.js +133 -0
- package/dist/cjs/{main.js → scopes/scope.js} +31 -364
- package/dist/cjs/scopes/standard.js +44 -0
- package/dist/cjs/scopes/tsKeywords.js +113 -0
- package/dist/cjs/scopes/type.js +70 -0
- package/dist/cjs/scopes/validation.js +64 -0
- package/dist/cjs/traverse/problems.js +50 -74
- package/dist/cjs/traverse/traverse.js +25 -3
- package/dist/cjs/utils/numericLiterals.js +1 -0
- package/dist/mjs/nodes/node.js +20 -2
- package/dist/mjs/nodes/predicate.js +1 -0
- package/dist/mjs/nodes/rules/regex.js +3 -41
- package/dist/mjs/nodes/rules/rules.js +16 -12
- package/dist/mjs/parse/definition.js +1 -1
- package/dist/mjs/parse/tuple/morph.js +7 -6
- package/dist/mjs/scopes/cache.js +25 -0
- package/dist/mjs/scopes/jsObjects.js +119 -0
- package/dist/mjs/{main.js → scopes/scope.js} +15 -344
- package/dist/mjs/scopes/standard.js +27 -0
- package/dist/mjs/scopes/tsKeywords.js +99 -0
- package/dist/mjs/scopes/type.js +56 -0
- package/dist/mjs/scopes/validation.js +51 -0
- package/dist/mjs/traverse/problems.js +49 -73
- package/dist/mjs/traverse/traverse.js +26 -4
- package/dist/mjs/utils/numericLiterals.js +1 -1
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/types/nodes/compose.d.ts +1 -1
- package/dist/types/nodes/infer.d.ts +4 -4
- package/dist/types/nodes/node.d.ts +11 -7
- package/dist/types/nodes/predicate.d.ts +43 -54
- package/dist/types/nodes/rules/range.d.ts +1 -1
- package/dist/types/nodes/rules/regex.d.ts +1 -11
- package/dist/types/nodes/rules/rules.d.ts +2 -10
- package/dist/types/parse/definition.d.ts +1 -1
- package/dist/types/parse/string/ast.d.ts +2 -1
- package/dist/types/parse/string/reduce/dynamic.d.ts +1 -1
- package/dist/types/parse/string/reduce/shared.d.ts +1 -1
- package/dist/types/parse/string/reduce/static.d.ts +1 -1
- package/dist/types/parse/string/shift/operand/unenclosed.d.ts +1 -1
- package/dist/types/parse/string/shift/operator/bounds.d.ts +1 -1
- package/dist/types/parse/tuple/morph.d.ts +1 -1
- package/dist/types/parse/tuple/narrow.d.ts +1 -1
- package/dist/types/parse/tuple/tuple.d.ts +1 -1
- package/dist/types/scopes/cache.d.ts +14 -0
- package/dist/types/scopes/jsObjects.d.ts +36 -0
- package/dist/types/scopes/scope.d.ts +76 -0
- package/dist/types/scopes/standard.d.ts +280 -0
- package/dist/types/scopes/tsKeywords.d.ts +32 -0
- package/dist/types/scopes/type.d.ts +53 -0
- package/dist/types/scopes/validation.d.ts +21 -0
- package/dist/types/traverse/problems.d.ts +29 -32
- package/dist/types/traverse/traverse.d.ts +10 -8
- package/dist/types/utils/numericLiterals.d.ts +1 -0
- package/package.json +2 -2
- package/dist/types/main.d.ts +0 -324
|
@@ -12,20 +12,15 @@ _export(exports, {
|
|
|
12
12
|
Scope: ()=>Scope,
|
|
13
13
|
writeShallowCycleErrorMessage: ()=>writeShallowCycleErrorMessage,
|
|
14
14
|
scope: ()=>scope,
|
|
15
|
-
|
|
16
|
-
spaces: ()=>spaces,
|
|
17
|
-
type: ()=>type,
|
|
18
|
-
writeDuplicateAliasesMessage: ()=>writeDuplicateAliasesMessage,
|
|
19
|
-
isType: ()=>isType
|
|
15
|
+
writeDuplicateAliasesMessage: ()=>writeDuplicateAliasesMessage
|
|
20
16
|
});
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
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
|
-
|
|
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
|
|
111
|
+
return _chainableNoOpProxyTs.chainableNoOpProxy;
|
|
116
112
|
}
|
|
117
113
|
compile() {
|
|
118
|
-
if (!
|
|
114
|
+
if (!spaceRegistry[this.name]) {
|
|
119
115
|
for(const name in this.aliases){
|
|
120
116
|
this.resolve(name);
|
|
121
117
|
}
|
|
122
|
-
|
|
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,
|
|
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,
|
|
177
|
-
result.flat = (0,
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
219
|
+
return onUnresolvable === "throw" ? (0, _errorsTs.throwInternalError)(`Unexpectedly failed to resolve alias '${name}'`) : undefined;
|
|
226
220
|
}
|
|
227
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,70 @@
|
|
|
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(type);
|
|
55
|
+
const out = (0, _traverseTs.traverse)(data, type.flat, state);
|
|
56
|
+
return state.problems.length ? {
|
|
57
|
+
data,
|
|
58
|
+
problems: state.problems
|
|
59
|
+
} : {
|
|
60
|
+
data,
|
|
61
|
+
out
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}[name];
|
|
65
|
+
// we need to assign this to a variable before returning so we can reference
|
|
66
|
+
// it in namedTraverse
|
|
67
|
+
const type = Object.assign(namedTraverse, root);
|
|
68
|
+
return type;
|
|
69
|
+
};
|
|
70
|
+
const isType = (value)=>value?.infer === _chainableNoOpProxyTs.chainableNoOpProxy;
|