UNPKG

@cloudquery/plugin-sdk-javascript

Version:

This is the high-level package to use for developing CloudQuery plugins in JavaScript

59 lines 1.65 kB
import { FixedSizeBinary } from '@apache-arrow/esnext-esm'; import { parse, stringify } from 'uuid'; import { FormatError } from '../errors/errors.js'; import { isInvalid, NULL_VALUE } from './util.js'; export class UUID { _valid = false; _value = null; constructor(v) { this.value = v; } get dataType() { return new FixedSizeBinary(16); } get valid() { return this._valid; } get value() { if (!this._valid) { return null; } return this._value; } set value(value) { if (isInvalid(value)) { this._valid = false; return; } if (typeof value === 'string') { // parse throws on invalid uuids this._value = parse(value); this._valid = true; return; } if (value instanceof Uint8Array) { this._value = value; this._valid = true; return; } if (value instanceof UUID) { this._value = value.value; this._valid = value.valid; return; } if (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) { // parse throws on invalid uuids this._value = parse(value.toString()); this._valid = true; return; } throw new FormatError(`Unable to set UUID from value`, { props: { value } }); } toString() { if (this._valid) { return stringify(this._value); } return NULL_VALUE; } } //# sourceMappingURL=uuid.js.map