transcoding.d.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Copyright 2020 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { JSONObject, JSONValue } from 'proto3-json-serializer';
  17. import { Field } from 'protobufjs';
  18. import { google } from '../protos/http';
  19. export interface TranscodedRequest {
  20. httpMethod: 'get' | 'post' | 'put' | 'patch' | 'delete';
  21. url: string;
  22. queryString: string;
  23. data: string | {};
  24. }
  25. declare const httpOptionName = "(google.api.http)";
  26. type allowedOptions = '(google.api.method_signature)';
  27. export type ParsedOptionsType = Array<{
  28. [httpOptionName]?: google.api.IHttpRule;
  29. } & {
  30. [option in allowedOptions]?: {} | string | number;
  31. }>;
  32. export declare function getField(request: JSONObject, field: string, allowObjects?: boolean): JSONValue | undefined;
  33. export declare function deepCopyWithoutMatchedFields(request: JSONObject, fieldsToSkip: Set<string>, fullNamePrefix?: string): JSONObject;
  34. export declare function deleteField(request: JSONObject, field: string): void;
  35. export declare function buildQueryStringComponents(request: JSONObject, prefix?: string): string[];
  36. export declare function encodeWithSlashes(str: string): string;
  37. export declare function encodeWithoutSlashes(str: string): string;
  38. export declare function applyPattern(pattern: string, fieldValue: string): string | undefined;
  39. interface MatchResult {
  40. matchedFields: string[];
  41. url: string;
  42. }
  43. export declare function match(request: JSONObject, pattern: string): MatchResult | undefined;
  44. export declare function flattenObject(request: JSONObject): JSONObject;
  45. export declare function isProto3OptionalField(field: Field): any;
  46. export declare function transcode(request: JSONObject, parsedOptions: ParsedOptionsType): TranscodedRequest | undefined;
  47. export declare function overrideHttpRules(httpRules: Array<google.api.IHttpRule>, protoJson: protobuf.Root): void;
  48. export {};