tsbuffer-validator
Advanced tools
Comparing version 0.3.3 to 0.3.4
{ | ||
"name": "tsbuffer-validator", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Validator for TSBuffer values", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,2 +13,3 @@ import { TSBufferProto, TSBufferSchema } from "tsbuffer-schema"; | ||
isTypeReference(schema: TSBufferSchema): schema is TypeReference; | ||
extendsUnionFields(unionFields: string[], schemas: TSBufferSchema[]): void; | ||
/** | ||
@@ -15,0 +16,0 @@ * 将interface及其引用转换为展平的schema |
@@ -94,2 +94,29 @@ "use strict"; | ||
}; | ||
ProtoHelper.prototype.extendsUnionFields = function (unionFields, schemas) { | ||
for (var i = 0, len = schemas.length; i < len; ++i) { | ||
var schema = schemas[i]; | ||
if (this.isTypeReference(schema)) { | ||
schema = this.parseReference(schema); | ||
} | ||
// Interface及其Ref 加入interfaces | ||
if (this.isInterface(schema)) { | ||
var flat = this.getFlatInterfaceSchema(schema); | ||
flat.properties.forEach(function (v) { | ||
if (unionFields.binarySearch(v.name) === -1) { | ||
unionFields.binaryInsert(v.name); | ||
} | ||
}); | ||
if (flat.indexSignature) { | ||
var is = "[[" + flat.indexSignature.keyType + "]]"; | ||
if (unionFields.binarySearch(is) === -1) { | ||
unionFields.binaryInsert(is); | ||
} | ||
} | ||
} | ||
// Intersection/Union 递归合并unionFields | ||
else if (schema.type === 'Intersection' || schema.type === 'Union') { | ||
var sub = this.extendsUnionFields(unionFields, schema.members.map(function (v) { return v.type; })); | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -96,0 +123,0 @@ * 将interface及其引用转换为展平的schema |
@@ -45,3 +45,2 @@ import { TSBufferSchema, TSBufferProto } from 'tsbuffer-schema'; | ||
validateIntersectionType(value: any, schema: IntersectionTypeSchema, unionFields?: string[]): ValidateResult; | ||
private _extendsUnionFields; | ||
private _isNumberKey; | ||
@@ -48,0 +47,0 @@ private _validateInterfaceOrReference; |
@@ -257,3 +257,3 @@ "use strict"; | ||
if (!unionFields) { | ||
this._extendsUnionFields(unionFields = [], schema.members.map(function (v) { return v.type; })); | ||
this.protoHelper.extendsUnionFields(unionFields = [], schema.members.map(function (v) { return v.type; })); | ||
} | ||
@@ -290,3 +290,3 @@ // 有一成功则成功 | ||
if (!unionFields) { | ||
this._extendsUnionFields(unionFields = [], schema.members.map(function (v) { return v.type; })); | ||
this.protoHelper.extendsUnionFields(unionFields = [], schema.members.map(function (v) { return v.type; })); | ||
} | ||
@@ -322,29 +322,2 @@ // 有一失败则失败 | ||
}; | ||
TSBufferValidator.prototype._extendsUnionFields = function (unionFields, schemas) { | ||
for (var i = 0, len = schemas.length; i < len; ++i) { | ||
var schema = schemas[i]; | ||
if (this.protoHelper.isTypeReference(schema)) { | ||
schema = this.protoHelper.parseReference(schema); | ||
} | ||
// Interface及其Ref 加入interfaces | ||
if (this.protoHelper.isInterface(schema)) { | ||
var flat = this.protoHelper.getFlatInterfaceSchema(schema); | ||
flat.properties.forEach(function (v) { | ||
if (unionFields.binarySearch(v.name) === -1) { | ||
unionFields.binaryInsert(v.name); | ||
} | ||
}); | ||
if (flat.indexSignature) { | ||
var is = "[[" + flat.indexSignature.keyType + "]]"; | ||
if (unionFields.binarySearch(is) === -1) { | ||
unionFields.binaryInsert(is); | ||
} | ||
} | ||
} | ||
// Intersection/Union 递归合并unionFields | ||
else if (schema.type === 'Intersection' || schema.type === 'Union') { | ||
var sub = this._extendsUnionFields(unionFields, schema.members.map(function (v) { return v.type; })); | ||
} | ||
} | ||
}; | ||
TSBufferValidator.prototype._isNumberKey = function (key) { | ||
@@ -351,0 +324,0 @@ var int = parseInt(key); |
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
131047