grpc-web-from-object
Advanced tools
Comparing version 2.0.3 to 2.1.0
# Changelog | ||
## [2.1.0](https://github.com/infodusha/grpc-web-from-object/compare/v2.0.3...v2.1.0) (2023-02-05) | ||
### Features | ||
* validate missing factory ([9cdacd3](https://github.com/infodusha/grpc-web-from-object/commit/9cdacd3dcde582ea57b21155b8611ede259dcb23)) | ||
* validate missing properties ([ba17bfd](https://github.com/infodusha/grpc-web-from-object/commit/ba17bfd0b6e8eed35d160be1a804a52625a22136)) | ||
## [2.0.3](https://github.com/infodusha/grpc-web-from-object/compare/v2.0.2...v2.0.3) (2023-02-03) | ||
@@ -4,0 +12,0 @@ |
@@ -8,2 +8,3 @@ "use strict"; | ||
const instance = new MessageType(); | ||
validateMissingProps(instance, data); | ||
for (const [key, value] of Object.entries(data)) { | ||
@@ -29,2 +30,3 @@ if (value === null) { | ||
else { | ||
validateMissingFactory(key, value); | ||
setValue(instance, key, value); | ||
@@ -49,1 +51,22 @@ } | ||
} | ||
function validateMissingProps(instance, data) { | ||
const dataSetters = Object.keys(data).map((key) => getSetter(key)); | ||
const instanceSetters = Object.keys(Object.getPrototypeOf(instance)).filter((key) => key.startsWith('set')); | ||
for (const key of instanceSetters) { | ||
if (!dataSetters.includes(key) && instance['clear' + key.slice(3)] === undefined) { | ||
const prop = key.slice(3, 4).toLowerCase() + key.slice(4); | ||
throw new Error(`Missing property '${prop}'`); | ||
} | ||
} | ||
} | ||
function validateMissingFactory(key, value) { | ||
if (Array.isArray(value)) { | ||
for (const v of value) { | ||
validateMissingFactory(key, v); | ||
} | ||
return; | ||
} | ||
if (typeof value === 'object') { | ||
throw new Error(`Missing factory for '${key}'`); | ||
} | ||
} |
{ | ||
"name": "grpc-web-from-object", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "fromObject method for grpc-web", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
20054
88