File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 11import { FixedSizeBinary } from '@apache-arrow/esnext-esm' ;
2- import { validate } from 'uuid' ;
2+ import { parse , stringify } from 'uuid' ;
33
44import { 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 ;
You can’t perform that action at this time.
0 commit comments