metadata.d.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /// <reference types="node" />
  2. /// <reference types="node" />
  3. /// <reference types="node" />
  4. import * as http2 from 'http2';
  5. export type MetadataValue = string | Buffer;
  6. export type MetadataObject = Map<string, MetadataValue[]>;
  7. export interface MetadataOptions {
  8. idempotentRequest?: boolean;
  9. waitForReady?: boolean;
  10. cacheableRequest?: boolean;
  11. corked?: boolean;
  12. }
  13. /**
  14. * A class for storing metadata. Keys are normalized to lowercase ASCII.
  15. */
  16. export declare class Metadata {
  17. protected internalRepr: MetadataObject;
  18. private options;
  19. constructor(options?: MetadataOptions);
  20. /**
  21. * Sets the given value for the given key by replacing any other values
  22. * associated with that key. Normalizes the key.
  23. * @param key The key to whose value should be set.
  24. * @param value The value to set. Must be a buffer if and only
  25. * if the normalized key ends with '-bin'.
  26. */
  27. set(key: string, value: MetadataValue): void;
  28. /**
  29. * Adds the given value for the given key by appending to a list of previous
  30. * values associated with that key. Normalizes the key.
  31. * @param key The key for which a new value should be appended.
  32. * @param value The value to add. Must be a buffer if and only
  33. * if the normalized key ends with '-bin'.
  34. */
  35. add(key: string, value: MetadataValue): void;
  36. /**
  37. * Removes the given key and any associated values. Normalizes the key.
  38. * @param key The key whose values should be removed.
  39. */
  40. remove(key: string): void;
  41. /**
  42. * Gets a list of all values associated with the key. Normalizes the key.
  43. * @param key The key whose value should be retrieved.
  44. * @return A list of values associated with the given key.
  45. */
  46. get(key: string): MetadataValue[];
  47. /**
  48. * Gets a plain object mapping each key to the first value associated with it.
  49. * This reflects the most common way that people will want to see metadata.
  50. * @return A key/value mapping of the metadata.
  51. */
  52. getMap(): {
  53. [key: string]: MetadataValue;
  54. };
  55. /**
  56. * Clones the metadata object.
  57. * @return The newly cloned object.
  58. */
  59. clone(): Metadata;
  60. /**
  61. * Merges all key-value pairs from a given Metadata object into this one.
  62. * If both this object and the given object have values in the same key,
  63. * values from the other Metadata object will be appended to this object's
  64. * values.
  65. * @param other A Metadata object.
  66. */
  67. merge(other: Metadata): void;
  68. setOptions(options: MetadataOptions): void;
  69. getOptions(): MetadataOptions;
  70. /**
  71. * Creates an OutgoingHttpHeaders object that can be used with the http2 API.
  72. */
  73. toHttp2Headers(): http2.OutgoingHttpHeaders;
  74. /**
  75. * This modifies the behavior of JSON.stringify to show an object
  76. * representation of the metadata map.
  77. */
  78. toJSON(): {
  79. [key: string]: MetadataValue[];
  80. };
  81. /**
  82. * Returns a new Metadata object based fields in a given IncomingHttpHeaders
  83. * object.
  84. * @param headers An IncomingHttpHeaders object.
  85. */
  86. static fromHttp2Headers(headers: http2.IncomingHttpHeaders): Metadata;
  87. }