@cerbos/embedded
Version:
Client library for interacting with embedded Cerbos policy decision points generated by Cerbos Hub from server-side Node.js and browser-based applications
82 lines • 2.91 kB
JavaScript
;
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// source: cerbos/cloud/epdp/v1/epdp.proto
Object.defineProperty(exports, "__esModule", { value: true });
exports.Metadata_SourceAttributesEntry = exports.Metadata = exports.protobufPackage = void 0;
/* eslint-disable */
const policy_1 = require("../../../policy/v1/policy");
exports.protobufPackage = "cerbos.cloud.epdp.v1";
exports.Metadata = {
fromJSON(object) {
return {
version: isSet(object.version) ? globalThis.String(object.version) : "",
policies: globalThis.Array.isArray(object?.policies)
? object.policies.map((e) => globalThis.String(e))
: [],
buildTimestamp: isSet(object.buildTimestamp)
? globalThis.Number(object.buildTimestamp)
: 0,
commitHash: isSet(object.commitHash)
? globalThis.String(object.commitHash)
: "",
sourceAttributes: isObject(object.sourceAttributes)
? Object.entries(object.sourceAttributes).reduce((acc, [key, value]) => {
acc[key] = policy_1.SourceAttributes.fromJSON(value);
return acc;
}, {})
: {},
};
},
toJSON(message) {
const obj = {};
if (message.version !== "") {
obj.version = message.version;
}
if (message.policies?.length) {
obj.policies = message.policies;
}
if (message.buildTimestamp !== 0) {
obj.buildTimestamp = Math.round(message.buildTimestamp);
}
if (message.commitHash !== "") {
obj.commitHash = message.commitHash;
}
if (message.sourceAttributes) {
const entries = Object.entries(message.sourceAttributes);
if (entries.length > 0) {
obj.sourceAttributes = {};
entries.forEach(([k, v]) => {
obj.sourceAttributes[k] = policy_1.SourceAttributes.toJSON(v);
});
}
}
return obj;
},
};
exports.Metadata_SourceAttributesEntry = {
fromJSON(object) {
return {
key: isSet(object.key) ? globalThis.String(object.key) : "",
value: isSet(object.value)
? policy_1.SourceAttributes.fromJSON(object.value)
: undefined,
};
},
toJSON(message) {
const obj = {};
if (message.key !== "") {
obj.key = message.key;
}
if (message.value !== undefined) {
obj.value = policy_1.SourceAttributes.toJSON(message.value);
}
return obj;
},
};
function isObject(value) {
return typeof value === "object" && value !== null;
}
function isSet(value) {
return value !== null && value !== undefined;
}
//# sourceMappingURL=epdp.js.map