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 1
1
import { FixedSizeBinary } from '@apache-arrow/esnext-esm' ;
2
- import { validate } from 'uuid' ;
2
+ import { parse , stringify } from 'uuid' ;
3
3
4
4
import { Nullable } from '../schema/types.js' ;
5
5
@@ -33,14 +33,15 @@ export class UUID implements Scalar<Nullable<Uint8Array>> {
33
33
}
34
34
35
35
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 ;
38
39
return ;
39
40
}
40
41
41
42
if ( value instanceof Uint8Array ) {
42
43
this . _value = value ;
43
- this . _valid = validate ( new TextDecoder ( ) . decode ( value ) ) ;
44
+ this . _valid = true ;
44
45
return ;
45
46
}
46
47
@@ -51,8 +52,9 @@ export class UUID implements Scalar<Nullable<Uint8Array>> {
51
52
}
52
53
53
54
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 ;
56
58
return ;
57
59
}
58
60
@@ -61,7 +63,7 @@ export class UUID implements Scalar<Nullable<Uint8Array>> {
61
63
62
64
public toString ( ) {
63
65
if ( this . _valid ) {
64
- return new TextDecoder ( ) . decode ( this . _value ) ;
66
+ return stringify ( this . _value ! ) ;
65
67
}
66
68
67
69
return NULL_VALUE ;
You can’t perform that action at this time.
0 commit comments