serializer.d.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*!
  2. * Copyright 2019 Google Inc. All Rights Reserved.
  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 { DocumentData } from '@google-cloud/firestore';
  17. import * as proto from '../protos/firestore_v1_proto_api';
  18. import { Firestore } from './index';
  19. import { FieldPath } from './path';
  20. import { ApiMapValue, ValidationOptions } from './types';
  21. import api = proto.google.firestore.v1;
  22. /**
  23. * An interface for Firestore types that can be serialized to Protobuf.
  24. *
  25. * @private
  26. * @internal
  27. */
  28. export interface Serializable {
  29. toProto(): api.IValue;
  30. }
  31. /**
  32. * Serializer that is used to convert between JavaScript types and their
  33. * Firestore Protobuf representation.
  34. *
  35. * @private
  36. * @internal
  37. */
  38. export declare class Serializer {
  39. private allowUndefined;
  40. private createReference;
  41. private createInteger;
  42. constructor(firestore: Firestore);
  43. /**
  44. * Encodes a JavaScript object into the Firestore 'Fields' representation.
  45. *
  46. * @private
  47. * @internal
  48. * @param obj The object to encode.
  49. * @returns The Firestore 'Fields' representation
  50. */
  51. encodeFields(obj: DocumentData): ApiMapValue;
  52. /**
  53. * Encodes a JavaScript value into the Firestore 'Value' representation.
  54. *
  55. * @private
  56. * @internal
  57. * @param val The object to encode
  58. * @returns The Firestore Proto or null if we are deleting a field.
  59. */
  60. encodeValue(val: unknown): api.IValue | null;
  61. /**
  62. * @private
  63. */
  64. encodeVector(rawVector: number[]): api.IValue;
  65. /**
  66. * Decodes a single Firestore 'Value' Protobuf.
  67. *
  68. * @private
  69. * @internal
  70. * @param proto A Firestore 'Value' Protobuf.
  71. * @returns The converted JS type.
  72. */
  73. decodeValue(proto: api.IValue): unknown;
  74. /**
  75. * Decodes a google.protobuf.Value
  76. *
  77. * @private
  78. * @internal
  79. * @param proto A Google Protobuf 'Value'.
  80. * @returns The converted JS type.
  81. */
  82. decodeGoogleProtobufValue(proto: proto.google.protobuf.IValue): unknown;
  83. /**
  84. * Decodes a google.protobuf.ListValue
  85. *
  86. * @private
  87. * @internal
  88. * @param proto A Google Protobuf 'ListValue'.
  89. * @returns The converted JS type.
  90. */
  91. decodeGoogleProtobufList(proto: proto.google.protobuf.IListValue | null | undefined): unknown[];
  92. /**
  93. * Decodes a google.protobuf.Struct
  94. *
  95. * @private
  96. * @internal
  97. * @param proto A Google Protobuf 'Struct'.
  98. * @returns The converted JS type.
  99. */
  100. decodeGoogleProtobufStruct(proto: proto.google.protobuf.IStruct | null | undefined): Record<string, unknown>;
  101. }
  102. /**
  103. * Validates a JavaScript value for usage as a Firestore value.
  104. *
  105. * @private
  106. * @internal
  107. * @param arg The argument name or argument index (for varargs methods).
  108. * @param value JavaScript value to validate.
  109. * @param desc A description of the expected type.
  110. * @param path The field path to validate.
  111. * @param options Validation options
  112. * @param level The current depth of the traversal. This is used to decide
  113. * whether undefined values or deletes are allowed.
  114. * @param inArray Whether we are inside an array.
  115. * @throws when the object is invalid.
  116. */
  117. export declare function validateUserInput(arg: string | number, value: unknown, desc: string, options: ValidationOptions, path?: FieldPath, level?: number, inArray?: boolean): void;