All files / packages/value/src null.ts

78.57% Statements 11/14
75% Branches 6/8
80% Functions 4/5
78.57% Lines 11/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63                      76x 68x     8x           15x                             17x       17x 13x     4x           2x 1x               2x      
import { create } from '@bufbuild/protobuf'
import * as wkt from '@bufbuild/protobuf/wkt'
import * as Ydb from '@ydbjs/api/value'
 
import { type Type, TypeKind } from './type.js'
import type { Value } from './value.js'
 
export class NullType implements Type {
	#typeInstance?: Ydb.Type
 
	constructor() {
		if (NullType.instance) {
			return NullType.instance
		}
 
		NullType.instance = this
	}
 
	private static instance: NullType
 
	get kind(): TypeKind.NULL {
		return TypeKind.NULL
	}
 
	encode(): Ydb.Type {
		if (!this.#typeInstance) {
			this.#typeInstance = create(Ydb.TypeSchema, {
				type: { case: 'nullType', value: wkt.NullValue.NULL_VALUE },
			})
		}
 
		return this.#typeInstance
	}
}
 
export class Null implements Value<NullType> {
	readonly type: NullType = new NullType()
	#valueInstance?: Ydb.Value
 
	constructor() {
		if (Null.instance) {
			return Null.instance
		}
 
		Null.instance = this
	}
 
	private static instance: Null
 
	encode(): Ydb.Value {
		if (!this.#valueInstance) {
			this.#valueInstance = create(Ydb.ValueSchema, {
				value: {
					case: 'nullFlagValue',
					value: wkt.NullValue.NULL_VALUE,
				},
			})
		}
 
		return this.#valueInstance
	}
}