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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | 1668x 1668x 2476x 1399x 1392x 1399x 1620x 1620x 1620x 849x 848x 849x 15x 11x 2x 1x 2x 1x 1x 2x 1x 2x 1x 1x 330x 320x 14x 13x 13x 7x 6x 42x 40x 40x 4x 3x 9x 5x 138x 133x 404x 399x 5x 4x 4x 3x 6x 5x 5x 5x 5x 5x 5x 2x 4x 3x 3x 1x 4x 3x 3x 1x 2x 1x 6x 5x 5x 1x 4x 3x | import { type MessageInitShape, create } from '@bufbuild/protobuf'
import type { GenMessage } from '@bufbuild/protobuf/codegenv1'
import type { TZDate } from '@date-fns/tz'
import * as Ydb from '@ydbjs/api/value'
import { type GenericDateConstructor, formatISO9075 } from 'date-fns'
import { type Type, TypeKind } from './type.js'
import { bigIntsFromUuid, uuidFromBigInts } from './uuid.js'
import { type Value } from './value.js'
export class PrimitiveType implements Type {
declare id: Ydb.Type_PrimitiveTypeId
#type: MessageInitShape<GenMessage<Ydb.Type>>
#typeInstance?: Ydb.Type
constructor(typeId: Ydb.Type_PrimitiveTypeId) {
this.#type = { type: { case: 'typeId', value: typeId } }
Object.defineProperty(this, 'id', {
value: typeId,
writable: false,
enumerable: false,
configurable: false,
})
}
get kind(): TypeKind.PRIMITIVE {
return TypeKind.PRIMITIVE
}
encode(): Ydb.Type {
if (!this.#typeInstance) {
this.#typeInstance = create(Ydb.TypeSchema, this.#type)
}
return this.#typeInstance
}
}
export class Primitive implements Value<PrimitiveType> {
type: PrimitiveType
value: unknown
// oxlint-disable no-unused-private-class-members
#value: MessageInitShape<GenMessage<Ydb.Value>>
#valueInstance?: Ydb.Value
constructor(value: MessageInitShape<GenMessage<Ydb.Value>>, type: PrimitiveType) {
this.type = type
this.value = value?.value?.value
this.#value = value
}
encode(): Ydb.Value {
if (!this.#valueInstance) {
this.#valueInstance = create(Ydb.ValueSchema, this.#value)
}
return this.#valueInstance
}
}
export class BoolType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.BOOL)
}
}
export class Bool extends Primitive implements Value<BoolType> {
constructor(value: boolean) {
super({ value: { case: 'boolValue', value: value } }, new BoolType())
}
static from(value: boolean): Bool {
return new Bool(value)
}
}
export class Int8Type extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.INT8)
}
}
export class Int8 extends Primitive implements Value<Int8Type> {
constructor(value: number) {
super({ value: { case: 'int32Value', value: value } }, new Int8Type())
}
}
export class Uint8Type extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.UINT8)
}
}
export class Uint8 extends Primitive implements Value<Uint8Type> {
constructor(value: number) {
Iif (value < 0) {
throw new Error('Value must be greater than or equal to 0')
}
super({ value: { case: 'uint32Value', value: value } }, new Uint8Type())
}
}
export class Int16Type extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.INT16)
}
}
export class Int16 extends Primitive implements Value<Int16Type> {
constructor(value: number) {
super({ value: { case: 'int32Value', value: value } }, new Int16Type())
}
}
export class Uint16Type extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.UINT16)
}
}
export class Uint16 extends Primitive implements Value<Uint16Type> {
constructor(value: number) {
Iif (value < 0) {
throw new Error('Value must be greater than or equal to 0')
}
super({ value: { case: 'uint32Value', value: value } }, new Uint16Type())
}
}
export class Int32Type extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.INT32)
}
}
export class Int32 extends Primitive implements Value<Int32Type> {
constructor(value: number) {
super({ value: { case: 'int32Value', value: value } }, new Int32Type())
}
}
export class Uint32Type extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.UINT32)
}
}
export class Uint32 extends Primitive implements Value<Uint32Type> {
constructor(value: number) {
Iif (value < 0) {
throw new Error('Value must be greater than or equal to 0')
}
super({ value: { case: 'uint32Value', value: value } }, new Uint32Type())
}
}
export class Int64Type extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.INT64)
}
}
export class Int64 extends Primitive implements Value<Int64Type> {
constructor(value: bigint) {
super({ value: { case: 'int64Value', value: value } }, new Int64Type())
}
}
export class Uint64Type extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.UINT64)
}
}
export class Uint64 extends Primitive implements Value<Uint64Type> {
constructor(value: bigint) {
Iif (value < BigInt(0)) {
throw new Error('Value must be greater than or equal to 0')
}
super({ value: { case: 'uint64Value', value: value } }, new Uint64Type())
}
}
export class FloatType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.FLOAT)
}
}
export class Float extends Primitive implements Value<FloatType> {
constructor(value: number) {
super({ value: { case: 'floatValue', value: value } }, new FloatType())
}
}
export class DoubleType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.DOUBLE)
}
}
export class Double extends Primitive implements Value<DoubleType> {
constructor(value: number) {
super({ value: { case: 'doubleValue', value: value } }, new DoubleType())
}
}
export class BytesType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.STRING)
}
}
export class Bytes extends Primitive implements Value<BytesType> {
constructor(value: Uint8Array) {
super({ value: { case: 'bytesValue', value: value } }, new BytesType())
}
}
export class TextType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.UTF8)
}
}
export class Text extends Primitive implements Value<TextType> {
constructor(value: string) {
super({ value: { case: 'textValue', value: value } }, new TextType())
}
}
export class Utf8Type extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.UTF8)
}
}
export class Utf8 extends Primitive implements Value<Utf8Type> {
constructor(value: string) {
super({ value: { case: 'textValue', value: value } }, new Utf8Type())
}
}
export class JsonType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.JSON)
}
}
export class Json extends Primitive implements Value<JsonType> {
constructor(value: string) {
super({ value: { case: 'textValue', value: value } }, new JsonType())
}
}
export class YsonType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.YSON)
}
}
export class Yson extends Primitive implements Value<YsonType> {
constructor(value: Uint8Array) {
super({ value: { case: 'bytesValue', value: value } }, new YsonType())
}
}
export class UuidType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.UUID)
}
}
export class Uuid extends Primitive implements Value<UuidType> {
low128: bigint = 0n
high128: bigint = 0n
constructor(value: string) {
let { low128, high128 } = bigIntsFromUuid(value)
super({ value: { case: 'low128', value: low128 }, high128 }, new UuidType())
this.low128 = low128
this.high128 = high128
}
override toString(): string {
return uuidFromBigInts(this.low128, this.high128)
}
}
export class DateType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.DATE)
}
}
export class Date extends Primitive implements Value<DateType> {
constructor(value: InstanceType<GenericDateConstructor>) {
let datesFromEpoch = Math.floor(value.getTime() / (24 * 60 * 60 * 1000))
super({ value: { case: 'uint32Value', value: datesFromEpoch } }, new DateType())
}
}
export class TzDateType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.TZ_DATE)
}
}
export class TzDate extends Primitive implements Value<TzDateType> {
constructor(value: TZDate) {
let date = formatISO9075(value, { representation: 'date' })
super(
{
value: {
case: 'textValue',
value: `${date},${value.timeZone}`,
},
},
new TzDateType()
)
}
}
export class DatetimeType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.DATETIME)
}
}
export class Datetime extends Primitive implements Value<DatetimeType> {
constructor(value: InstanceType<GenericDateConstructor>) {
let secondsFromEpoch = Math.floor(value.getTime() / 1000)
super({ value: { case: 'uint32Value', value: secondsFromEpoch } }, new DatetimeType())
}
}
export class TzDatetimeType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.TZ_DATETIME)
}
}
export class TzDatetime extends Primitive implements Value<TzDatetimeType> {
constructor(value: TZDate) {
let date = formatISO9075(value, { representation: 'date' })
let time = formatISO9075(value, { representation: 'time' })
super(
{
value: {
case: 'textValue',
value: `${date}T${time},${value.timeZone}`,
},
},
new TzDatetimeType()
)
}
}
export class IntervalType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.INTERVAL)
}
}
export class Interval extends Primitive implements Value<IntervalType> {
constructor(value: number) {
super({ value: { case: 'int32Value', value: value } }, new IntervalType())
}
}
export class TimestampType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.TIMESTAMP)
}
}
export class Timestamp extends Primitive implements Value<TimestampType> {
constructor(value: InstanceType<GenericDateConstructor>) {
let microSecondsFromEpoch = BigInt(value.getTime()) * 1000n
super({ value: { case: 'uint64Value', value: microSecondsFromEpoch } }, new TimestampType())
}
}
export class TzTimestampType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.TZ_TIMESTAMP)
}
}
export class TzTimestamp extends Primitive implements Value<TzTimestampType> {
constructor(value: TZDate) {
let date = formatISO9075(value, { representation: 'date' })
let time = formatISO9075(value, { representation: 'time' })
let micro = value.getMilliseconds() * 1000
super(
{
value: {
case: 'textValue',
value: `${date}T${time}.${micro},${value.timeZone}`,
},
},
new TzTimestampType()
)
}
}
export class JsonDocumentType extends PrimitiveType {
constructor() {
super(Ydb.Type_PrimitiveTypeId.JSON_DOCUMENT)
}
}
export class JsonDocument extends Primitive implements Value<JsonDocumentType> {
constructor(value: string) {
super({ value: { case: 'textValue', value: value } }, new JsonDocumentType())
}
}
|