@sinclair/typebox-codegen
Advanced tools
@@ -53,2 +53,9 @@ "use strict"; | ||
| } | ||
| /** | ||
| * Check if the type need to be wrapped in an api chain (`type(...).some()`) | ||
| * Instead of string. | ||
| */ | ||
| function IsApiChain(type) { | ||
| return type.indexOf('type(') === 0; | ||
| } | ||
| function ConstructUnionOrIntersect(types, operator) { | ||
@@ -65,4 +72,20 @@ function Reduce(types) { | ||
| else { | ||
| const mapped = types.map((type) => Unwrap(type)).join(` ${operator} `); | ||
| return Wrap(mapped); | ||
| // For some cases arktype cannot construct types from string literals, | ||
| // i.e `{ [key: string]: any } | undefined` to `'{} | undefined'`. | ||
| // Instead, create api chain `type({}).or('undefined')`. | ||
| const [left, ...right] = types; | ||
| if (IsApiChain(left)) { | ||
| let chainOperator = null; | ||
| if (operator === '&') { | ||
| chainOperator = 'intersect'; | ||
| } | ||
| else if (operator === '|') { | ||
| chainOperator = 'or'; | ||
| } | ||
| return [left, ...right.map((v) => `${chainOperator}(${v})`)].join('.'); | ||
| } | ||
| else { | ||
| const mapped = types.map((type) => Unwrap(type)).join(` ${operator} `); | ||
| return Wrap(mapped); | ||
| } | ||
| } | ||
@@ -173,3 +196,4 @@ } | ||
| const buffer = []; | ||
| buffer.push(`{\n${properties}\n}`); | ||
| buffer.push(`type({\n${properties}\n})`); | ||
| import_references.add('type'); | ||
| return buffer.join(`\n`); | ||
@@ -294,2 +318,3 @@ } | ||
| const emitted_types = new Set(); | ||
| const import_references = new Set(); | ||
| function Generate(model) { | ||
@@ -309,3 +334,5 @@ reference_map.clear(); | ||
| } | ||
| buffer.unshift(`import { scope } from 'arktype'`, ''); | ||
| const imports = ['scope', ...import_references].join(','); | ||
| buffer.unshift(`import { ${imports} } from 'arktype'`, ''); | ||
| import_references.clear(); | ||
| return index_1.Formatter.Format(buffer.join('\n')); | ||
@@ -312,0 +339,0 @@ } |
+1
-1
| { | ||
| "name": "@sinclair/typebox-codegen", | ||
| "version": "0.11.0", | ||
| "version": "0.11.1", | ||
| "description": "Code Generation Tools for TypeBox", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
163251
0.68%3583
0.76%