Skip to content

Commit 72efa22

Browse files
authored
fix: Properly encode uuid (#59)
1 parent e8bb0a0 commit 72efa22

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/scalar/uuid.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FixedSizeBinary } from '@apache-arrow/esnext-esm';
2-
import { validate } from 'uuid';
2+
import { parse, stringify } from 'uuid';
33

44
import { Nullable } from '../schema/types.js';
55

@@ -33,14 +33,15 @@ export class UUID implements Scalar<Nullable<Uint8Array>> {
3333
}
3434

3535
if (typeof value === 'string') {
36-
this._value = new TextEncoder().encode(value);
37-
this._valid = validate(value);
36+
// parse throws on invalid uuids
37+
this._value = parse(value);
38+
this._valid = true;
3839
return;
3940
}
4041

4142
if (value instanceof Uint8Array) {
4243
this._value = value;
43-
this._valid = validate(new TextDecoder().decode(value));
44+
this._valid = true;
4445
return;
4546
}
4647

@@ -51,8 +52,9 @@ export class UUID implements Scalar<Nullable<Uint8Array>> {
5152
}
5253

5354
if (typeof value!.toString === 'function' && value!.toString !== Object.prototype.toString) {
54-
this._value = Buffer.from(value!.toString());
55-
this._valid = validate(value!.toString());
55+
// parse throws on invalid uuids
56+
this._value = parse(value!.toString());
57+
this._valid = true;
5658
return;
5759
}
5860

@@ -61,7 +63,7 @@ export class UUID implements Scalar<Nullable<Uint8Array>> {
6163

6264
public toString() {
6365
if (this._valid) {
64-
return new TextDecoder().decode(this._value);
66+
return stringify(this._value!);
6567
}
6668

6769
return NULL_VALUE;

0 commit comments

Comments
 (0)