scrubbr
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -69,3 +69,3 @@ "use strict"; | ||
} | ||
console.log("" + this.getPrefix() + message); | ||
console.log("".concat(this.getPrefix()).concat(message)); | ||
}; | ||
@@ -76,3 +76,3 @@ Logger.prototype.error = function (message) { | ||
} | ||
console.error("" + this.getPrefix() + message); | ||
console.error("".concat(this.getPrefix()).concat(message)); | ||
}; | ||
@@ -83,3 +83,3 @@ Logger.prototype.warn = function (message) { | ||
} | ||
console.warn("" + this.getPrefix() + message); | ||
console.warn("".concat(this.getPrefix()).concat(message)); | ||
}; | ||
@@ -90,3 +90,3 @@ Logger.prototype.debug = function (message) { | ||
} | ||
console.debug("" + this.getPrefix() + message); | ||
console.debug("".concat(this.getPrefix()).concat(message)); | ||
}; | ||
@@ -93,0 +93,0 @@ return Logger; |
@@ -106,5 +106,5 @@ "use strict"; | ||
if (typeof schema == 'string') { | ||
this.logger.info("Loading typescript file: " + schema); | ||
this.logger.info("Loading typescript file: ".concat(schema)); | ||
if (!fs.existsSync(schema)) { | ||
throw new Error("Could not find schema file at: " + path.resolve(schema)); | ||
throw new Error("Could not find schema file at: ".concat(path.resolve(schema))); | ||
} | ||
@@ -152,3 +152,3 @@ schema = tsj | ||
typeNames.forEach(function (name) { | ||
_this.logger.debug("Adding custom serializer for type: " + name); | ||
_this.logger.debug("Adding custom serializer for type: ".concat(name)); | ||
var serializerList = _this.typeSerializers.get(name) || []; | ||
@@ -211,8 +211,8 @@ serializerList.push(serializer); | ||
if (!schema) { | ||
throw this.error("Could not find the type: " + schemaType); | ||
throw this.error("Could not find the type: ".concat(schemaType)); | ||
} | ||
this.logger.info("Serializing data with TS type: '" + schemaType + "'"); | ||
this.logger.info("Serializing data with TS type: '".concat(schemaType, "'")); | ||
// Merge contexts | ||
context = __assign(__assign({}, this.globalContext), context); | ||
this.logger.debug("Using context: '" + JSON.stringify(context, null, ' ') + "'"); | ||
this.logger.debug("Using context: '".concat(JSON.stringify(context, null, ' '), "'")); | ||
// Create state | ||
@@ -256,12 +256,12 @@ options = __assign(__assign({}, this.options), options); | ||
var filteredNode = {}; | ||
var pathPrefix = state.path ? state.path + "." : ''; | ||
var pathPrefix = state.path ? "".concat(state.path, ".") : ''; | ||
for (var i = 0; i < nodeProps.length; i++) { | ||
var _b = nodeProps[i], name_1 = _b[0], value = _b[1]; | ||
var propSchema = schemaProps[name_1]; | ||
var propPath = "" + pathPrefix + name_1; | ||
state.logger.debug("[PATH] " + propPath); | ||
var propPath = "".concat(pathPrefix).concat(name_1); | ||
state.logger.debug("[PATH] ".concat(propPath)); | ||
var propState = state.createNodeState(value, name_1, propPath, propSchema); | ||
// Property not defined in the schema, do not serialize property | ||
if (!propSchema) { | ||
state.logger.debug("Property '" + name_1 + "' not defined in " + state.schemaType + "."); | ||
state.logger.debug("Property '".concat(name_1, "' not defined in ").concat(state.schemaType, ".")); | ||
continue; | ||
@@ -290,8 +290,8 @@ } | ||
var itemSchema = isTuple ? tupleSchema[i] : listSchema; | ||
var itemPath = state.path + "[" + i + "]"; | ||
state.logger.debug("[PATH] " + itemPath); | ||
var itemPath = "".concat(state.path, "[").concat(i, "]"); | ||
state.logger.debug("[PATH] ".concat(itemPath)); | ||
var itemState = state.createListState(value, i, itemPath, itemSchema); | ||
// Skip items past the tuple length | ||
if (isTuple && i >= tupleSchema.length) { | ||
state.logger.debug("Index " + i + " not defined in tuple"); | ||
state.logger.debug("Index ".concat(i, " not defined in tuple")); | ||
break; | ||
@@ -329,3 +329,3 @@ } | ||
(schemaDef.allOf || schemaDef.anyOf || schemaDef.oneOf)) { | ||
state.logger.debug("'" + state.schemaType + "' appears to be an union type."); | ||
state.logger.debug("'".concat(state.schemaType, "' appears to be an union type.")); | ||
return this.serializeNode(data, state); | ||
@@ -371,3 +371,3 @@ } | ||
else { | ||
state.logger.warn("No type definitions found for '" + typeName + "'"); | ||
state.logger.warn("No type definitions found for '".concat(typeName, "'")); | ||
} | ||
@@ -382,3 +382,3 @@ }); | ||
if (typeNames.length > 1) { | ||
state.logger.debug(typeNames.length + " possible types (" + typeNames + ")."); | ||
state.logger.debug("".concat(typeNames.length, " possible types (").concat(typeNames, ").")); | ||
var minProps_1 = Infinity; | ||
@@ -396,6 +396,6 @@ typeNames.forEach(function (name) { | ||
var others = typeNames.filter(function (n) { return n != chosenType; }); | ||
state.logger.warn("Guessing: Using type '" + chosenType + "', instead of '" + others + "', because it has the fewest properties at object path: '" + state.path + "'.\n(You can explicitly override this selection with the 'useType()' function in a custom serializer)."); | ||
state.logger.warn("Guessing: Using type '".concat(chosenType, "', instead of '").concat(others, "', because it has the fewest properties at object path: '").concat(state.path, "'.\n(You can explicitly override this selection with the 'useType()' function in a custom serializer).")); | ||
} | ||
else { | ||
state.logger.debug("Type: " + chosenType + (dataIsArray ? '[]' : '')); | ||
state.logger.debug("Type: ".concat(chosenType).concat(dataIsArray ? '[]' : '')); | ||
} | ||
@@ -424,3 +424,3 @@ return chosenType; | ||
if (!schemaDef) { | ||
this.error("Could not find a type definition for '" + schemaType + "'", state); | ||
this.error("Could not find a type definition for '".concat(schemaType, "'"), state); | ||
state.schemaType = null; | ||
@@ -445,3 +445,3 @@ state.schemaDef = {}; | ||
} | ||
state.logger.debug("Running " + this.genericSerializers.length + " generic serializers"); | ||
state.logger.debug("Running ".concat(this.genericSerializers.length, " generic serializers")); | ||
var serialized = dataNode; | ||
@@ -452,8 +452,8 @@ for (var i = 0; i < this.genericSerializers.length; i++) { | ||
if (typeof result === 'undefined') { | ||
state.logger.warn("Generic serializer returned 'undefined' at object path: " + state.path); | ||
state.logger.warn("Generic serializer returned 'undefined' at object path: ".concat(state.path)); | ||
} | ||
if (result instanceof helpers_1.UseType) { | ||
state.logger.debug("Overriding type: '" + result.typeName + "'"); | ||
state.logger.debug("Overriding type: '".concat(result.typeName, "'")); | ||
if (result.typeName === state.schemaType) { | ||
state.logger.warn("Trying to override type with the same type ('" + result.typeName + "') at object path: " + state.path); | ||
state.logger.warn("Trying to override type with the same type ('".concat(result.typeName, "') at object path: ").concat(state.path)); | ||
} | ||
@@ -480,3 +480,3 @@ if (typeof result.data !== 'undefined') { | ||
if (!this.getSchemaFor(typeName)) { | ||
this.error("No type named '" + typeName + "'.", state); | ||
this.error("No type named '".concat(typeName, "'."), state); | ||
return dataNode; | ||
@@ -488,3 +488,3 @@ } | ||
} | ||
state.logger.debug("Running " + serializerFns.length + " serializers for type '" + typeName + "'"); | ||
state.logger.debug("Running ".concat(serializerFns.length, " serializers for type '").concat(typeName, "'")); | ||
var serialized = dataNode; | ||
@@ -494,7 +494,7 @@ for (var i = 0; i < serializerFns.length; i++) { | ||
if (typeof result === 'undefined') { | ||
state.logger.warn("Serializer for type '" + typeName + "' returned 'undefined' at object path: " + state.path); | ||
state.logger.warn("Serializer for type '".concat(typeName, "' returned 'undefined' at object path: ").concat(state.path)); | ||
} | ||
// Change type | ||
if (result instanceof helpers_1.UseType) { | ||
state.logger.debug("Overriding type: '" + typeName + "'"); | ||
state.logger.debug("Overriding type: '".concat(typeName, "'")); | ||
// Serialized data | ||
@@ -506,3 +506,3 @@ if (typeof result.data !== 'undefined') { | ||
if (result.typeName === state.schemaType) { | ||
state.logger.warn("Trying to override type with the same type ('" + result.typeName + "') at object path: " + state.path); | ||
state.logger.warn("Trying to override type with the same type ('".concat(result.typeName, "') at object path: ").concat(state.path)); | ||
} | ||
@@ -529,3 +529,3 @@ else { | ||
if (state.seenTypes.includes(typeName)) { | ||
this.error("Scrubbr detected a circular reference with type " + typeName + " at object path: " + state.path, state); | ||
this.error("Scrubbr detected a circular reference with type ".concat(typeName, " at object path: ").concat(state.path), state); | ||
return true; | ||
@@ -532,0 +532,0 @@ } |
{ | ||
"name": "scrubbr", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Serialize and sanitize JSON data using TypeScript.", | ||
@@ -21,4 +21,3 @@ "repository": "https://github.com/jgillick/scrubbr", | ||
"dependencies": { | ||
"ts-json-schema-generator": "^0.93.0", | ||
"ts-node": "^10.0.0" | ||
"ts-json-schema-generator": "^0.93.0" | ||
}, | ||
@@ -29,2 +28,3 @@ "devDependencies": { | ||
"@types/jest": "^26.0.23", | ||
"@types/node": "^17.0.8", | ||
"@typescript-eslint/eslint-plugin": "^4.28.0", | ||
@@ -36,5 +36,6 @@ "@typescript-eslint/parser": "^4.28.0", | ||
"moment": "^2.29.1", | ||
"ts-node": "^10.4.0", | ||
"ts-jest": "^27.0.3", | ||
"typescript": "^4.3.2" | ||
"typescript": "^4.5.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1077287
1
13
- Removedts-node@^10.0.0
- Removed@cspotcode/source-map-support@0.8.1(transitive)
- Removed@jridgewell/resolve-uri@3.1.2(transitive)
- Removed@jridgewell/sourcemap-codec@1.4.15(transitive)
- Removed@jridgewell/trace-mapping@0.3.9(transitive)
- Removed@tsconfig/node10@1.0.11(transitive)
- Removed@tsconfig/node12@1.0.11(transitive)
- Removed@tsconfig/node14@1.0.3(transitive)
- Removed@tsconfig/node16@1.0.4(transitive)
- Removed@types/node@20.14.9(transitive)
- Removedacorn@8.12.0(transitive)
- Removedacorn-walk@8.3.3(transitive)
- Removedarg@4.1.3(transitive)
- Removedcreate-require@1.1.1(transitive)
- Removeddiff@4.0.2(transitive)
- Removedmake-error@1.3.6(transitive)
- Removedts-node@10.9.2(transitive)
- Removedundici-types@5.26.5(transitive)
- Removedv8-compile-cache-lib@3.0.1(transitive)
- Removedyn@3.1.1(transitive)