UNPKG

@devcycle/nodejs-server-sdk

Version:

The DevCycle NodeJS Server SDK used for feature management.

48 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pbSDKVariableTransform = pbSDKVariableTransform; const types_1 = require("@devcycle/types"); const bucketing_assembly_script_1 = require("@devcycle/bucketing-assembly-script"); function getVariableTypeFromPB(variable) { switch (variable.type) { case bucketing_assembly_script_1.ProtobufTypes.VariableType_PB.Boolean: return { type: types_1.VariableType.boolean, value: variable.boolValue, }; case bucketing_assembly_script_1.ProtobufTypes.VariableType_PB.Number: return { type: types_1.VariableType.number, value: variable.doubleValue, }; case bucketing_assembly_script_1.ProtobufTypes.VariableType_PB.String: return { type: types_1.VariableType.string, value: variable.stringValue, }; case bucketing_assembly_script_1.ProtobufTypes.VariableType_PB.JSON: return { type: types_1.VariableType.json, value: JSON.parse(variable.stringValue), }; default: throw new Error(`Unknown variable type: ${variable.type}`); } } function pbSDKVariableTransform(variable) { const { type, value } = getVariableTypeFromPB(variable); return { _id: variable._id, type, key: variable.key, value, evalReason: !variable.evalReason || variable.evalReason.isNull ? null : variable.evalReason, _feature: !variable._feature || variable._feature.isNull ? null : variable._feature.value, eval: variable.eval, }; } //# sourceMappingURL=pbTypeHelpers.js.map