UNPKG

@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

79 lines (67 loc) 2 kB
// Code generated by protoc-gen-ts_proto. DO NOT EDIT. // source: cerbos/policy/v1/policy.proto /* eslint-disable */ export const protobufPackage = "cerbos.policy.v1"; export interface SourceAttributes { attributes: { [key: string]: any | undefined }; } export interface SourceAttributes_AttributesEntry { key: string; value: any | undefined; } export const SourceAttributes: MessageFns<SourceAttributes> = { fromJSON(object: any): SourceAttributes { return { attributes: isObject(object.attributes) ? Object.entries(object.attributes).reduce<{ [key: string]: any | undefined; }>((acc, [key, value]) => { acc[key] = value as any | undefined; return acc; }, {}) : {}, }; }, toJSON(message: SourceAttributes): unknown { const obj: any = {}; if (message.attributes) { const entries = Object.entries(message.attributes); if (entries.length > 0) { obj.attributes = {}; entries.forEach(([k, v]) => { obj.attributes[k] = v; }); } } return obj; }, }; export const SourceAttributes_AttributesEntry: MessageFns<SourceAttributes_AttributesEntry> = { fromJSON(object: any): SourceAttributes_AttributesEntry { return { key: isSet(object.key) ? globalThis.String(object.key) : "", value: isSet(object?.value) ? object.value : undefined, }; }, toJSON(message: SourceAttributes_AttributesEntry): unknown { const obj: any = {}; if (message.key !== "") { obj.key = message.key; } if (message.value !== undefined) { obj.value = message.value; } return obj; }, }; function isObject(value: any): boolean { return typeof value === "object" && value !== null; } function isSet(value: any): boolean { return value !== null && value !== undefined; } export interface MessageFns<T> { fromJSON(object: any): T; toJSON(message: T): unknown; }