web3-validator
Advanced tools
Comparing version 2.0.5-dev.f943944.0 to 2.0.5
@@ -148,2 +148,3 @@ "use strict"; | ||
type: 'array', | ||
$id: abiName, | ||
items: [], | ||
@@ -162,3 +163,3 @@ maxItems: arraySizes[i], | ||
else if (lastSchema.items.length === 0) { | ||
lastSchema.items = childSchema; | ||
lastSchema.items = [childSchema]; | ||
} // lastSchema.items is a non-empty Scheme array, append 'childSchema' | ||
@@ -177,13 +178,3 @@ else { | ||
const arraySize = arraySizes[0]; | ||
const item = { | ||
$id: abiName, | ||
type: 'array', | ||
items: (0, exports.abiSchemaToJsonSchema)(abiComponents, abiName), | ||
maxItems: arraySize, | ||
minItems: arraySize, | ||
}; | ||
if (arraySize < 0) { | ||
delete item.maxItems; | ||
delete item.minItems; | ||
} | ||
const item = Object.assign({ type: 'array', $id: abiName, items: (0, exports.abiSchemaToJsonSchema)(abiComponents, abiName) }, (arraySize >= 0 && { minItems: arraySize, maxItems: arraySize })); | ||
lastSchema.items.push(item); | ||
@@ -193,13 +184,3 @@ } | ||
const arraySize = arraySizes[0]; | ||
const item = { | ||
type: 'array', | ||
$id: abiName, | ||
items: convertEthType(String(baseType)), | ||
minItems: arraySize, | ||
maxItems: arraySize, | ||
}; | ||
if (arraySize < 0) { | ||
delete item.maxItems; | ||
delete item.minItems; | ||
} | ||
const item = Object.assign({ type: 'array', $id: abiName, items: convertEthType(abiType) }, (arraySize >= 0 && { minItems: arraySize, maxItems: arraySize })); | ||
lastSchema.items.push(item); | ||
@@ -213,3 +194,3 @@ } | ||
// Nested object | ||
lastSchema.items.items.push(Object.assign({ $id: abiName }, convertEthType(abiType))); | ||
lastSchema.items.push(Object.assign({ $id: abiName }, convertEthType(abiType))); | ||
} | ||
@@ -216,0 +197,0 @@ lastSchema = schema; |
@@ -45,3 +45,5 @@ "use strict"; | ||
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' && (schema === null || schema === void 0 ? void 0 : schema.items)) { | ||
if (Array.isArray(schema.items) && schema.items.length > 0) { | ||
if (Array.isArray(schema.items) && schema.items.length > 1 | ||
&& schema.maxItems !== undefined | ||
&& new Set(schema.items.map((item) => item.$id)).size === schema.items.length) { | ||
const arr = []; | ||
@@ -56,3 +58,7 @@ for (const item of schema.items) { | ||
} | ||
return zod_1.z.array(convertToZod(schema.items)); | ||
const nextSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items; | ||
let zodArraySchema = zod_1.z.array(convertToZod(nextSchema)); | ||
zodArraySchema = schema.minItems !== undefined ? zodArraySchema.min(schema.minItems) : zodArraySchema; | ||
zodArraySchema = schema.maxItems !== undefined ? zodArraySchema.max(schema.maxItems) : zodArraySchema; | ||
return zodArraySchema; | ||
} | ||
@@ -59,0 +65,0 @@ if (schema.oneOf && Array.isArray(schema.oneOf)) { |
@@ -144,2 +144,3 @@ /* | ||
type: 'array', | ||
$id: abiName, | ||
items: [], | ||
@@ -158,3 +159,3 @@ maxItems: arraySizes[i], | ||
else if (lastSchema.items.length === 0) { | ||
lastSchema.items = childSchema; | ||
lastSchema.items = [childSchema]; | ||
} // lastSchema.items is a non-empty Scheme array, append 'childSchema' | ||
@@ -173,13 +174,3 @@ else { | ||
const arraySize = arraySizes[0]; | ||
const item = { | ||
$id: abiName, | ||
type: 'array', | ||
items: abiSchemaToJsonSchema(abiComponents, abiName), | ||
maxItems: arraySize, | ||
minItems: arraySize, | ||
}; | ||
if (arraySize < 0) { | ||
delete item.maxItems; | ||
delete item.minItems; | ||
} | ||
const item = Object.assign({ type: 'array', $id: abiName, items: abiSchemaToJsonSchema(abiComponents, abiName) }, (arraySize >= 0 && { minItems: arraySize, maxItems: arraySize })); | ||
lastSchema.items.push(item); | ||
@@ -189,13 +180,3 @@ } | ||
const arraySize = arraySizes[0]; | ||
const item = { | ||
type: 'array', | ||
$id: abiName, | ||
items: convertEthType(String(baseType)), | ||
minItems: arraySize, | ||
maxItems: arraySize, | ||
}; | ||
if (arraySize < 0) { | ||
delete item.maxItems; | ||
delete item.minItems; | ||
} | ||
const item = Object.assign({ type: 'array', $id: abiName, items: convertEthType(abiType) }, (arraySize >= 0 && { minItems: arraySize, maxItems: arraySize })); | ||
lastSchema.items.push(item); | ||
@@ -209,3 +190,3 @@ } | ||
// Nested object | ||
lastSchema.items.items.push(Object.assign({ $id: abiName }, convertEthType(abiType))); | ||
lastSchema.items.push(Object.assign({ $id: abiName }, convertEthType(abiType))); | ||
} | ||
@@ -212,0 +193,0 @@ lastSchema = schema; |
@@ -39,3 +39,5 @@ /* | ||
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' && (schema === null || schema === void 0 ? void 0 : schema.items)) { | ||
if (Array.isArray(schema.items) && schema.items.length > 0) { | ||
if (Array.isArray(schema.items) && schema.items.length > 1 | ||
&& schema.maxItems !== undefined | ||
&& new Set(schema.items.map((item) => item.$id)).size === schema.items.length) { | ||
const arr = []; | ||
@@ -50,3 +52,7 @@ for (const item of schema.items) { | ||
} | ||
return z.array(convertToZod(schema.items)); | ||
const nextSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items; | ||
let zodArraySchema = z.array(convertToZod(nextSchema)); | ||
zodArraySchema = schema.minItems !== undefined ? zodArraySchema.min(schema.minItems) : zodArraySchema; | ||
zodArraySchema = schema.maxItems !== undefined ? zodArraySchema.max(schema.maxItems) : zodArraySchema; | ||
return zodArraySchema; | ||
} | ||
@@ -53,0 +59,0 @@ if (schema.oneOf && Array.isArray(schema.oneOf)) { |
{ | ||
"name": "web3-validator", | ||
"version": "2.0.5-dev.f943944.0+f943944", | ||
"version": "2.0.5", | ||
"description": "JSON-Schema compatible validator for web3", | ||
@@ -50,4 +50,4 @@ "main": "./lib/commonjs/index.js", | ||
"util": "^0.12.5", | ||
"web3-errors": "1.1.5-dev.f943944.0+f943944", | ||
"web3-types": "1.5.1-dev.f943944.0+f943944", | ||
"web3-errors": "^1.1.4", | ||
"web3-types": "^1.5.0", | ||
"zod": "^3.21.4" | ||
@@ -69,3 +69,3 @@ }, | ||
}, | ||
"gitHead": "f943944b51d977f72d4db959be0e72adbcb68c12" | ||
"gitHead": "7379a3bb3c274eff76c64b2447e95c34282e04fd" | ||
} |
@@ -180,2 +180,3 @@ /* | ||
type: 'array', | ||
$id: abiName, | ||
items: [], | ||
@@ -196,3 +197,3 @@ maxItems: arraySizes[i], | ||
else if (lastSchema.items.length === 0) { | ||
lastSchema.items = childSchema; | ||
lastSchema.items = [childSchema]; | ||
} // lastSchema.items is a non-empty Scheme array, append 'childSchema' | ||
@@ -210,33 +211,21 @@ else { | ||
} else if (baseType === 'tuple' && isArray) { | ||
const arraySize = arraySizes[0]; | ||
const item: JsonSchema = { | ||
$id: abiName, | ||
type: 'array', | ||
items: abiSchemaToJsonSchema(abiComponents, abiName), | ||
maxItems: arraySize, | ||
minItems: arraySize, | ||
}; | ||
const arraySize = arraySizes[0]; | ||
const item: JsonSchema = { | ||
type: 'array', | ||
$id: abiName, | ||
items: abiSchemaToJsonSchema(abiComponents, abiName), | ||
...(arraySize >= 0 && { minItems: arraySize, maxItems: arraySize }), | ||
}; | ||
if (arraySize < 0) { | ||
delete item.maxItems; | ||
delete item.minItems; | ||
} | ||
(lastSchema.items as JsonSchema[]).push(item); | ||
(lastSchema.items as JsonSchema[]).push(item); | ||
} else if (isArray) { | ||
const arraySize = arraySizes[0]; | ||
const item: JsonSchema = { | ||
type: 'array', | ||
$id: abiName, | ||
items: convertEthType(String(baseType)), | ||
minItems: arraySize, | ||
maxItems: arraySize, | ||
}; | ||
const arraySize = arraySizes[0]; | ||
const item: JsonSchema = { | ||
type: 'array', | ||
$id: abiName, | ||
items: convertEthType(abiType), | ||
...(arraySize >= 0 && { minItems: arraySize, maxItems: arraySize }), | ||
}; | ||
if (arraySize < 0) { | ||
delete item.maxItems; | ||
delete item.minItems; | ||
} | ||
(lastSchema.items as JsonSchema[]).push(item); | ||
(lastSchema.items as JsonSchema[]).push(item); | ||
} else if (Array.isArray(lastSchema.items)) { | ||
@@ -247,3 +236,3 @@ // Array of non-tuple items | ||
// Nested object | ||
((lastSchema.items as JsonSchema).items as JsonSchema[]).push({ | ||
(lastSchema.items as JsonSchema[]).push({ | ||
$id: abiName, | ||
@@ -512,2 +501,2 @@ ...convertEthType(abiType), | ||
return data; | ||
} | ||
} |
@@ -47,3 +47,5 @@ /* | ||
if (schema?.type === 'array' && schema?.items) { | ||
if (Array.isArray(schema.items) && schema.items.length > 0) { | ||
if (Array.isArray(schema.items) && schema.items.length > 1 | ||
&& schema.maxItems !== undefined | ||
&& new Set(schema.items.map((item: JsonSchema) => item.$id)).size === schema.items.length) { | ||
const arr: Partial<[ZodTypeAny, ...ZodTypeAny[]]> = []; | ||
@@ -58,3 +60,8 @@ for (const item of schema.items) { | ||
} | ||
return z.array(convertToZod(schema.items as JsonSchema)); | ||
const nextSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items; | ||
let zodArraySchema = z.array(convertToZod(nextSchema)); | ||
zodArraySchema = schema.minItems !== undefined ? zodArraySchema.min(schema.minItems) : zodArraySchema; | ||
zodArraySchema = schema.maxItems !== undefined ? zodArraySchema.max(schema.maxItems) : zodArraySchema; | ||
return zodArraySchema; | ||
} | ||
@@ -61,0 +68,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
0
304235
181
5072
+ Addedweb3-errors@1.3.0(transitive)
+ Addedweb3-types@1.8.0(transitive)
Updatedweb3-errors@^1.1.4
Updatedweb3-types@^1.5.0