@featurevisor/core
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.3.0](https://github.com/fahad19/featurevisor/compare/v0.2.0...v0.3.0) (2023-03-17) | ||
### Features | ||
* support objects as variables ([#18](https://github.com/fahad19/featurevisor/issues/18)) ([c1b6160](https://github.com/fahad19/featurevisor/commit/c1b61609d299bbf2e46c644c4f09336cdd94e128)) | ||
# [0.2.0](https://github.com/fahad19/featurevisor/compare/v0.1.0...v0.2.0) (2023-03-16) | ||
@@ -8,0 +19,0 @@ |
@@ -96,3 +96,14 @@ "use strict"; | ||
var variableValueJoiSchema = Joi.alternatives() | ||
.try(Joi.string(), Joi.number(), Joi.boolean(), Joi.array().items(Joi.string())) | ||
.try(Joi.string(), Joi.number(), Joi.boolean(), Joi.array().items(Joi.string()), Joi.object().custom(function (value, helper) { | ||
var isFlat = true; | ||
Object.keys(value).forEach(function (key) { | ||
if (typeof value[key] === "object") { | ||
isFlat = false; | ||
} | ||
}); | ||
if (!isFlat) { | ||
throw new Error("object is not flat"); | ||
} | ||
return value; | ||
})) | ||
.allow(""); | ||
@@ -140,3 +151,3 @@ var plainGroupSegment = Joi.string(); | ||
key: Joi.string(), | ||
type: Joi.string().valid("string", "integer", "boolean", "double", "array"), | ||
type: Joi.string().valid("string", "integer", "boolean", "double", "array", "object"), | ||
defaultValue: variableValueJoiSchema, // @TODO: make it stricter based on `type` | ||
@@ -166,7 +177,8 @@ })), | ||
function getTestsJoiSchema(projectConfig) { | ||
var _a, _b; | ||
var testsJoiSchema = Joi.object({ | ||
tests: Joi.array().items(Joi.object({ | ||
description: Joi.string().optional(), | ||
tag: Joi.string(), | ||
environment: Joi.string().valid("production", "staging", "testing", "development"), | ||
tag: (_a = Joi.string()).valid.apply(_a, projectConfig.tags), | ||
environment: (_b = Joi.string()).valid.apply(_b, projectConfig.environments), | ||
features: Joi.array().items(Joi.object({ | ||
@@ -173,0 +185,0 @@ key: Joi.string(), |
@@ -26,2 +26,3 @@ import { Attributes, VariableKey, VariableValue, VariationValue } from "@featurevisor/types"; | ||
export declare function checkIfArraysAreEqual(a: any, b: any): boolean; | ||
export declare function checkIfObjectsAreEqual(a: any, b: any): boolean; | ||
export declare function testProject(rootDirectoryPath: string, projectConfig: ProjectConfig): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.testProject = exports.checkIfArraysAreEqual = void 0; | ||
exports.testProject = exports.checkIfObjectsAreEqual = exports.checkIfArraysAreEqual = void 0; | ||
var fs = require("fs"); | ||
@@ -25,2 +25,20 @@ var path = require("path"); | ||
exports.checkIfArraysAreEqual = checkIfArraysAreEqual; | ||
function checkIfObjectsAreEqual(a, b) { | ||
if (typeof a !== "object" || typeof b !== "object") { | ||
return false; | ||
} | ||
if (a === null || b === null) { | ||
return false; | ||
} | ||
if (Object.keys(a).length !== Object.keys(b).length) { | ||
return false; | ||
} | ||
for (var key in a) { | ||
if (a[key] !== b[key]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
exports.checkIfObjectsAreEqual = checkIfObjectsAreEqual; | ||
function testProject(rootDirectoryPath, projectConfig) { | ||
@@ -82,9 +100,16 @@ var hasError = false; | ||
var actualValue = sdk.getVariable(featureKey, variableKey, assertion.attributes); | ||
var passed = Array.isArray(expectedValue) | ||
? checkIfArraysAreEqual(expectedValue, actualValue) | ||
: expectedValue === actualValue; | ||
var passed; | ||
if (typeof expectedValue === "object") { | ||
passed = checkIfObjectsAreEqual(expectedValue, actualValue); | ||
} | ||
else if (Array.isArray(expectedValue)) { | ||
passed = checkIfArraysAreEqual(expectedValue, actualValue); | ||
} | ||
else { | ||
passed = expectedValue === actualValue; | ||
} | ||
if (!passed) { | ||
hasError = true; | ||
assertionHasError = true; | ||
console.error(" Variable \"".concat(variableKey, "\" failed: expected \"").concat(expectedValue, "\", got \"").concat(actualValue, "\"")); | ||
console.error(" Variable \"".concat(variableKey, "\" failed: expected ").concat(JSON.stringify(expectedValue), ", got \"").concat(JSON.stringify(actualValue), "\"")); | ||
} | ||
@@ -91,0 +116,0 @@ }); |
{ | ||
"name": "@featurevisor/core", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Core package of Featurevisor for Node.js usage", | ||
@@ -44,4 +44,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@featurevisor/sdk": "^0.2.0", | ||
"@featurevisor/types": "^0.2.0", | ||
"@featurevisor/sdk": "^0.3.0", | ||
"@featurevisor/types": "^0.3.0", | ||
"axios": "^1.3.4", | ||
@@ -57,3 +57,3 @@ "joi": "^17.8.3", | ||
}, | ||
"gitHead": "ead531c0af029bedf3ea6fcba64162e44af0f4ea" | ||
"gitHead": "fae6cbf61f8b2f7e89b4faf660f63b37676bab29" | ||
} |
@@ -94,3 +94,23 @@ // for use in node only | ||
const variableValueJoiSchema = Joi.alternatives() | ||
.try(Joi.string(), Joi.number(), Joi.boolean(), Joi.array().items(Joi.string())) | ||
.try( | ||
Joi.string(), | ||
Joi.number(), | ||
Joi.boolean(), | ||
Joi.array().items(Joi.string()), | ||
Joi.object().custom(function (value, helper) { | ||
let isFlat = true; | ||
Object.keys(value).forEach((key) => { | ||
if (typeof value[key] === "object") { | ||
isFlat = false; | ||
} | ||
}); | ||
if (!isFlat) { | ||
throw new Error("object is not flat"); | ||
} | ||
return value; | ||
}), | ||
) | ||
.allow(""); | ||
@@ -161,3 +181,3 @@ | ||
key: Joi.string(), // @TODO: make it unique among siblings | ||
type: Joi.string().valid("string", "integer", "boolean", "double", "array"), | ||
type: Joi.string().valid("string", "integer", "boolean", "double", "array", "object"), | ||
defaultValue: variableValueJoiSchema, // @TODO: make it stricter based on `type` | ||
@@ -202,4 +222,4 @@ }), | ||
description: Joi.string().optional(), | ||
tag: Joi.string(), // @TODO: make it specific | ||
environment: Joi.string().valid("production", "staging", "testing", "development"), // TODO: make it specific | ||
tag: Joi.string().valid(...projectConfig.tags), | ||
environment: Joi.string().valid(...projectConfig.environments), | ||
features: Joi.array().items( | ||
@@ -206,0 +226,0 @@ Joi.object({ |
@@ -62,2 +62,24 @@ import * as fs from "fs"; | ||
export function checkIfObjectsAreEqual(a, b) { | ||
if (typeof a !== "object" || typeof b !== "object") { | ||
return false; | ||
} | ||
if (a === null || b === null) { | ||
return false; | ||
} | ||
if (Object.keys(a).length !== Object.keys(b).length) { | ||
return false; | ||
} | ||
for (const key in a) { | ||
if (a[key] !== b[key]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
export function testProject(rootDirectoryPath: string, projectConfig: ProjectConfig): boolean { | ||
@@ -144,6 +166,12 @@ let hasError = false; | ||
const passed = Array.isArray(expectedValue) | ||
? checkIfArraysAreEqual(expectedValue, actualValue) | ||
: expectedValue === actualValue; | ||
let passed; | ||
if (typeof expectedValue === "object") { | ||
passed = checkIfObjectsAreEqual(expectedValue, actualValue); | ||
} else if (Array.isArray(expectedValue)) { | ||
passed = checkIfArraysAreEqual(expectedValue, actualValue); | ||
} else { | ||
passed = expectedValue === actualValue; | ||
} | ||
if (!passed) { | ||
@@ -154,3 +182,5 @@ hasError = true; | ||
console.error( | ||
` Variable "${variableKey}" failed: expected "${expectedValue}", got "${actualValue}"`, | ||
` Variable "${variableKey}" failed: expected ${JSON.stringify( | ||
expectedValue, | ||
)}, got "${JSON.stringify(actualValue)}"`, | ||
); | ||
@@ -157,0 +187,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
163691
3373
+ Added@featurevisor/sdk@0.3.0(transitive)
+ Added@featurevisor/types@0.3.0(transitive)
- Removed@featurevisor/sdk@0.2.0(transitive)
- Removed@featurevisor/types@0.2.0(transitive)
Updated@featurevisor/sdk@^0.3.0
Updated@featurevisor/types@^0.3.0