/** * Handling of types in JSII * * Types will be serialized according to the following table: * * ┬───────────────────────────────────────────────────────────────────────────────────────────────┐ * │ JAVASCRIPT TYPE │ * ┼────────────────┬───────────┬────────────┬───────────────┬───────────────────┬─────────────────┤ * │ undefined/null │ date │ scalar (*) │ array │ JSII-class object │ literal object │ * ├──────────┼────────────┼────────────────┼───────────┼────────────┼───────────────┼───────────────────┼─────────────────┤ * │ DECLARED │ void │ undefined │ undefined │ undefined │ undefined │ undefined │ undefined │ * │ TYPE │ date │ undefined(†) │ { date } │ - │ - │ - │ - │ * │ │ scalar (*) │ undefined(†) │ - │ value │ - │ - │ - │ * │ │ json │ undefined │ string │ value │ array/R(json) │ - │ byvalue/R(json) │ * │ │ enum │ undefined(†) │ - │ { enum } │ - │ - │ - │ * │ │ array of T │ undefined(†) │ - │ - │ array/R(T) │ - │ - │ * │ │ map of T │ undefined(†) │ - │ - │ - │ - │ byvalue/R(T) │ * │ │ interface │ undefined(†) │ - │ - │ - │ { ref } │ { ref: proxy } │ * │ │ struct │ undefined(†) │ - │ - │ - │ - │ byvalue/R(T[k]) │ * │ │ class │ undefined(†) │ - │ - │ - │ { ref } │ { ref: proxy } │ * │ │ any │ undefined │ { date } │ value │ array/R(any) │ { ref } │ byvalue/R(any) │ * └──────────┴────────────┴────────────────┴───────────┴────────────┴───────────────┴───────────────────┴─────────────────┘ * * - (*) scalar means 'string | number | boolean' * - (†) throw if not nullable * - /R(t) recurse with declared type t */ import * as spec from '@jsii/spec'; import { ObjectTable } from './objects'; /** * A specific singleton type to be explicit about a Void type * * In the spec, 'void' is represented as 'undefined'(*), but allowing the * value 'undefined' in function calls has lead to consumers failing to pass * type information that they had, just because they didn't "have to" (the * parameter was optional). * * (*) As in, declaration of a method looks like { returns?: TypeReference } * and the absence of a type means it returns 'void'. */ export type Void = 'void'; /** * A type instance, or Void */ export type OptionalValueOrVoid = spec.OptionalValue | Void; /** * A special FQN that can be used to create empty javascript objects. */ export declare const EMPTY_OBJECT_FQN = "Object"; export declare const SYMBOL_WIRE_TYPE: unique symbol; /** * The type kind, that controls how it will be serialized according to the above table */ export declare const enum SerializationClass { Void = "Void", Date = "Date", Scalar = "Scalar", Json = "Json", Enum = "Enum", Array = "Array", Map = "Map", Struct = "Struct", ReferenceType = "RefType", Any = "Any" } type FindSymbol = (fqn: spec.FQN) => any; type IsVisibleType = (fqn: spec.FQN) => boolean; type LookupType = (fqn: spec.FQN) => spec.Type; export interface SerializerHost { readonly objects: ObjectTable; debug(...args: any[]): void; isVisibleType: IsVisibleType; lookupType: LookupType; findSymbol: FindSymbol; } interface Serializer { serialize(value: unknown, type: OptionalValueOrVoid, host: SerializerHost): any; deserialize(value: unknown, type: OptionalValueOrVoid, host: SerializerHost, options?: { allowNullishMapValue?: boolean; }): any; } export declare const SERIALIZERS: { [k: string]: Serializer; }; export interface TypeSerialization { serializationClass: SerializationClass; typeRef: OptionalValueOrVoid; } /** * From a type reference, return the possible serialization types * * There can be multiple, because the type can be a type union. */ export declare function serializationType(typeRef: OptionalValueOrVoid, lookup: LookupType): TypeSerialization[]; export declare function process(host: SerializerHost, serde: keyof Serializer, value: unknown, type: OptionalValueOrVoid, context: string | (() => string)): any; export declare class SerializationError extends Error { readonly value: unknown; readonly causes: readonly any[]; readonly name: string; constructor(message: string, value: unknown, { isVisibleType }: { readonly isVisibleType: (fqn: string) => boolean; }, causes?: readonly any[], { renderValue }?: { renderValue?: boolean; }); } export {}; //# sourceMappingURL=serialization.d.ts.map