@cloudquery/plugin-sdk-javascript
Version:
This is the high-level package to use for developing CloudQuery plugins in JavaScript
57 lines • 1.54 kB
JavaScript
import { Utf8 as ArrowString } from '@apache-arrow/esnext-esm';
import { FormatError } from '../errors/errors.js';
import { isInvalid, NULL_VALUE } from './util.js';
export class Text {
_valid = false;
_value = null;
constructor(v) {
this.value = v;
return this;
}
get dataType() {
return new ArrowString();
}
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') {
this._value = value;
this._valid = true;
return;
}
if (value instanceof Uint8Array) {
this._value = new TextDecoder().decode(value);
this._valid = true;
return;
}
if (value instanceof Text) {
this._value = value.value;
this._valid = value.valid;
return;
}
if (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) {
this._value = value.toString();
this._valid = true;
return;
}
throw new FormatError(`Unable to set Text from value`, { props: { value } });
}
toString() {
if (this._valid) {
return this._value;
}
return NULL_VALUE;
}
}
//# sourceMappingURL=text.js.map