How to use the @jsii/spec.isPrimitiveTypeReference function in @jsii/spec

To help you get started, we’ve selected a few @jsii/spec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / jsii / packages / jsii-pacmak / lib / targets / dotnet / dotnetgenerator.ts View on Github external
private isOptionalPrimitive(optionalValue: spec.OptionalValue | undefined): boolean {
    if (!optionalValue || !optionalValue.optional) {
      return false;
    }

    // If the optional type is an enum then we need to flag it as ?
    const typeref = optionalValue.type as spec.NamedTypeReference;
    let isOptionalEnum = false;
    if (typeref && typeref.fqn) {
      const type = this.findType(typeref.fqn);
      isOptionalEnum = type.kind === spec.TypeKind.Enum;
    }

    return (spec.isPrimitiveTypeReference(optionalValue.type)
            // In .NET, string or object is a reference type, and can be nullable
            && optionalValue.type.primitive !== spec.PrimitiveType.String
            && optionalValue.type.primitive !== spec.PrimitiveType.Any
            && optionalValue.type.primitive !== spec.PrimitiveType.Json) // Json is not a primitive in .NET
            || isOptionalEnum;
  }
github aws / jsii / packages / jsii-pacmak / lib / targets / dotnet / dotnettyperesolver.ts View on Github external
public toDotNetType(typeref: spec.TypeReference): string {
    if (spec.isPrimitiveTypeReference(typeref)) {
      return this.toDotNetPrimitive(typeref.primitive);
    } else if (spec.isCollectionTypeReference(typeref)) {
      return this.toDotNetCollection(typeref);
    } else if (spec.isNamedTypeReference(typeref)) {
      return this.toNativeFqn(typeref.fqn);
    } else if (typeref.union) {
      return 'object';
    }
    throw new Error(`Invalid type reference: ${JSON.stringify(typeref)}`);

  }
github aws / jsii / packages / jsii-reflect / lib / type-ref.ts View on Github external
public get primitive(): string | undefined {
    if (!jsii.isPrimitiveTypeReference(this.spec)) {
      return undefined;
    }

    return this.spec.primitive;
  }
github aws / jsii / packages / @jsii / kernel / lib / serialization.ts View on Github external
export function serializationType(typeRef: OptionalValueOrVoid, lookup: TypeLookup): TypeSerialization[] {
  if (typeRef == null) { throw new Error("Kernel error: expected type information, got 'undefined'"); }
  if (typeRef === 'void') { return [{ serializationClass: SerializationClass.Void, typeRef }]; }
  if (spec.isPrimitiveTypeReference(typeRef.type)) {
    switch (typeRef.type.primitive) {
      case spec.PrimitiveType.Any: return [{ serializationClass: SerializationClass.Any, typeRef }];
      case spec.PrimitiveType.Date: return [{ serializationClass: SerializationClass.Date, typeRef }];
      case spec.PrimitiveType.Json: return [{ serializationClass: SerializationClass.Json, typeRef }];
      case spec.PrimitiveType.Boolean:
      case spec.PrimitiveType.Number:
      case spec.PrimitiveType.String:
        return [{ serializationClass: SerializationClass.Scalar, typeRef }];
    }

    throw new Error('Unknown primitive type');
  }
  if (spec.isCollectionTypeReference(typeRef.type)) {
    return [{
      serializationClass: typeRef.type.collection.kind === spec.CollectionKind.Array ? SerializationClass.Array : SerializationClass.Map,
      typeRef