| 1 |
import { ScalarType } from "../descriptors.js"; |
| 2 |
/** |
| 3 |
* ScalarValue maps from a scalar field type to a TypeScript value type. |
| 4 |
*/ |
| 5 |
export type ScalarValue<T = ScalarType, LongAsString extends boolean = false> = T extends ScalarType.STRING ? string : T extends ScalarType.INT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.SINT32 ? number : T extends ScalarType.FIXED32 ? number : T extends ScalarType.SFIXED32 ? number : T extends ScalarType.FLOAT ? number : T extends ScalarType.DOUBLE ? number : T extends ScalarType.INT64 ? LongAsString extends true ? string : bigint : T extends ScalarType.SINT64 ? LongAsString extends true ? string : bigint : T extends ScalarType.SFIXED64 ? LongAsString extends true ? string : bigint : T extends ScalarType.UINT64 ? LongAsString extends true ? string : bigint : T extends ScalarType.FIXED64 ? LongAsString extends true ? string : bigint : T extends ScalarType.BOOL ? boolean : T extends ScalarType.BYTES ? Uint8Array : never; |
| 6 |
/** |
| 7 |
* Returns true if both scalar values are equal. |
| 8 |
* |
| 9 |
* For float and double, values are compared following IEEE semantics: -0 |
| 10 |
* equals 0, and NaN does not equal NaN. This is value equality, not identity. |
| 11 |
* |
| 12 |
* It deliberately differs from isScalarZeroValue, which treats -0 as distinct |
| 13 |
* from 0. A value can equal the zero value without being a zero value |
| 14 |
* (scalarEquals(DOUBLE, -0, 0) is true while isScalarZeroValue(DOUBLE, -0) is |
| 15 |
* false) so this function must not be used to derive implicit presence. |
| 16 |
*/ |
| 17 |
export declare function scalarEquals(type: ScalarType, a: ScalarValue | undefined, b: ScalarValue | undefined): boolean; |
| 18 |
/** |
| 19 |
* Returns the zero value for the given scalar type, the value a field of this |
| 20 |
* type has when unset: 0 for numeric types, "" for strings, false for |
| 21 |
* booleans, and an empty Uint8Array for bytes. For 64-bit integer types, the |
| 22 |
* result is "0" when longAsString is true, otherwise 0n. |
| 23 |
* |
| 24 |
* This is the type's zero value, not a proto2 custom field default. For float |
| 25 |
* and double it is +0; isScalarZeroValue treats only +0, not -0, as this value. |
| 26 |
*/ |
| 27 |
export declare function scalarZeroValue<T extends ScalarType, LongAsString extends boolean>(type: T, longAsString: LongAsString): ScalarValue<T, LongAsString>; |
| 28 |
/** |
| 29 |
* Returns true if the value is the zero value for the given scalar type: `0` |
| 30 |
* for numeric types, `false` for booleans, `""` for strings, and an empty |
| 31 |
* Uint8Array for bytes. |
| 32 |
* |
| 33 |
* This is the implicit-presence default check. A singular field with implicit |
| 34 |
* presence is treated as unset, and omitted from the wire, when its value is |
| 35 |
* the zero value. With explicit presence, or in repeated and map fields, |
| 36 |
* presence is structural and this function does not apply. |
| 37 |
* |
| 38 |
* Note that -0 is NOT a zero value for float and double: under implicit |
| 39 |
* presence, +0 is omitted from the wire but -0 is written, following the |
| 40 |
* proto3 specification. As a result this can disagree with scalarEquals, which |
| 41 |
* compares by value and treats -0 as equal to 0. |
| 42 |
*/ |
| 43 |
export declare function isScalarZeroValue(type: ScalarType, value: unknown): boolean; |