UNPKG

@cerbos/http

Version:

Client library for interacting with the Cerbos policy decision point service over HTTP from browser-based applications

119 lines 4.13 kB
"use strict"; // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // source: cerbos/schema/v1/schema.proto Object.defineProperty(exports, "__esModule", { value: true }); exports.Schema = exports.ValidationError = exports.ValidationError_Source = exports.protobufPackage = void 0; exports.validationError_SourceFromJSON = validationError_SourceFromJSON; exports.validationError_SourceToJSON = validationError_SourceToJSON; /* eslint-disable */ exports.protobufPackage = "cerbos.schema.v1"; var ValidationError_Source; (function (ValidationError_Source) { ValidationError_Source[ValidationError_Source["SOURCE_UNSPECIFIED"] = 0] = "SOURCE_UNSPECIFIED"; ValidationError_Source[ValidationError_Source["SOURCE_PRINCIPAL"] = 1] = "SOURCE_PRINCIPAL"; ValidationError_Source[ValidationError_Source["SOURCE_RESOURCE"] = 2] = "SOURCE_RESOURCE"; })(ValidationError_Source || (exports.ValidationError_Source = ValidationError_Source = {})); function validationError_SourceFromJSON(object) { switch (object) { case 0: case "SOURCE_UNSPECIFIED": return ValidationError_Source.SOURCE_UNSPECIFIED; case 1: case "SOURCE_PRINCIPAL": return ValidationError_Source.SOURCE_PRINCIPAL; case 2: case "SOURCE_RESOURCE": return ValidationError_Source.SOURCE_RESOURCE; default: throw new globalThis.Error("Unrecognized enum value " + object + " for enum ValidationError_Source"); } } function validationError_SourceToJSON(object) { switch (object) { case ValidationError_Source.SOURCE_UNSPECIFIED: return "SOURCE_UNSPECIFIED"; case ValidationError_Source.SOURCE_PRINCIPAL: return "SOURCE_PRINCIPAL"; case ValidationError_Source.SOURCE_RESOURCE: return "SOURCE_RESOURCE"; default: throw new globalThis.Error("Unrecognized enum value " + object + " for enum ValidationError_Source"); } } exports.ValidationError = { fromJSON(object) { return { path: isSet(object.path) ? globalThis.String(object.path) : "", message: isSet(object.message) ? globalThis.String(object.message) : "", source: isSet(object.source) ? validationError_SourceFromJSON(object.source) : 0, }; }, toJSON(message) { const obj = {}; if (message.path !== "") { obj.path = message.path; } if (message.message !== "") { obj.message = message.message; } if (message.source !== 0) { obj.source = validationError_SourceToJSON(message.source); } return obj; }, }; exports.Schema = { fromJSON(object) { return { id: isSet(object.id) ? globalThis.String(object.id) : "", definition: isSet(object.definition) ? bytesFromBase64(object.definition) : new Uint8Array(0), }; }, toJSON(message) { const obj = {}; if (message.id !== "") { obj.id = message.id; } if (message.definition.length !== 0) { obj.definition = base64FromBytes(message.definition); } return obj; }, }; function bytesFromBase64(b64) { if (globalThis.Buffer) { return Uint8Array.from(globalThis.Buffer.from(b64, "base64")); } else { const bin = globalThis.atob(b64); const arr = new Uint8Array(bin.length); for (let i = 0; i < bin.length; ++i) { arr[i] = bin.charCodeAt(i); } return arr; } } function base64FromBytes(arr) { if (globalThis.Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin = []; arr.forEach((byte) => { bin.push(globalThis.String.fromCharCode(byte)); }); return globalThis.btoa(bin.join("")); } } function isSet(value) { return value !== null && value !== undefined; } //# sourceMappingURL=schema.js.map