type_map.go 1.18 KB
Newer Older
1 2 3
package schema

import (
tavit ohanian's avatar
tavit ohanian committed
4
	ld "gitlab.dms3.io/ld/go-ld-prime"
tavit ohanian's avatar
tavit ohanian committed
5
	schemadmt "gitlab.dms3.io/ld/go-ld-prime/schema/dmt"
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
)

type TypeMap struct {
	name TypeName
	dmt  schemadmt.TypeMap
	ts   *TypeSystem
}

// -- schema.Type interface satisfaction -->

var _ Type = (*TypeMap)(nil)

func (t *TypeMap) _Type() {}

func (t *TypeMap) TypeSystem() *TypeSystem {
	return t.ts
}

24 25
func (TypeMap) TypeKind() TypeKind {
	return TypeKind_Map
26 27 28 29 30 31
}

func (t *TypeMap) Name() TypeName {
	return t.name
}

tavit ohanian's avatar
tavit ohanian committed
32 33
func (t TypeMap) RepresentationBehavior() ld.Kind {
	return ld.Kind_Map
34 35 36 37 38 39 40
}

// -- specific to TypeMap -->

// KeyType returns the Type of the map keys.
//
// Note that map keys will must always be some type which is representable as a
41
// string in the LD Data Model (e.g. either TypeString or TypeEnum).
42 43 44 45 46 47 48 49 50 51 52 53 54 55
func (t *TypeMap) KeyType() Type {
	return t.ts.types[t.dmt.FieldKeyType().TypeReference()]
}

// ValueType returns the Type of the map values.
func (t *TypeMap) ValueType() Type {
	return t.ts.types[t.dmt.FieldValueType().TypeReference()]
}

// ValueIsNullable returns a bool describing if the map values are permitted
// to be null.
func (t *TypeMap) ValueIsNullable() bool {
	return t.dmt.FieldValueNullable().Bool()
}