File tree 2 files changed +16
-5
lines changed
2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -76,16 +76,17 @@ export function escape_ident(str: string): string {
76
76
! ( code > 96 && code < 123 ) && // lower alpha (a-z)
77
77
! ( code === 95 ) // underscore (_)
78
78
) {
79
- return `⟨${ str . replaceAll ( "⟩" , "⟩" ) } ⟩` ;
79
+ return `⟨${ str . replaceAll ( "⟩" , "\\ ⟩" ) } ⟩` ;
80
80
}
81
81
}
82
82
83
83
return str ;
84
84
}
85
85
86
86
export function isOnlyNumbers ( str : string ) : boolean {
87
- const parsed = Number . parseInt ( str ) ;
88
- return ! Number . isNaN ( parsed ) && parsed . toString ( ) === str ;
87
+ const stripped = str . replace ( "_" , "" ) ;
88
+ const parsed = Number . parseInt ( stripped ) ;
89
+ return ! Number . isNaN ( parsed ) && parsed . toString ( ) === stripped ;
89
90
}
90
91
91
92
export function isValidIdPart ( v : unknown ) : v is RecordIdValue {
@@ -105,7 +106,7 @@ export function isValidIdPart(v: unknown): v is RecordIdValue {
105
106
106
107
export function escape_id_part ( id : RecordIdValue ) : string {
107
108
return id instanceof Uuid
108
- ? `d "${ id } "`
109
+ ? `u "${ id } "`
109
110
: typeof id === "string"
110
111
? escape_ident ( id )
111
112
: typeof id === "bigint" || typeof id === "number"
Original file line number Diff line number Diff line change 1
1
import { describe , expect , test } from "bun:test" ;
2
- import { RecordId } from "../../src" ;
2
+ import { RecordId , Uuid } from "../../src" ;
3
3
4
4
describe ( "record ids" , ( ) => {
5
5
test ( "toString()" , ( ) => {
6
6
expect ( new RecordId ( "table" , 123 ) . toString ( ) ) . toBe ( "table:123" ) ;
7
7
expect ( new RecordId ( "table" , "123" ) . toString ( ) ) . toBe ( "table:⟨123⟩" ) ;
8
+ expect ( new RecordId ( "table" , "123_456" ) . toString ( ) ) . toBe ( "table:⟨123_456⟩" ) ;
8
9
expect ( new RecordId ( "table" , "test" ) . toString ( ) ) . toBe ( "table:test" ) ;
9
10
expect ( new RecordId ( "table" , "complex-ident" ) . toString ( ) ) . toBe (
10
11
"table:⟨complex-ident⟩" ,
11
12
) ;
13
+ expect ( new RecordId ( "table" , "⟩" ) . toString ( ) ) . toBe ( "table:⟨\\⟩⟩" ) ;
12
14
expect ( new RecordId ( "complex-table" , "complex-ident" ) . toString ( ) ) . toBe (
13
15
"⟨complex-table⟩:⟨complex-ident⟩" ,
14
16
) ;
15
17
18
+ // UUID
19
+ expect (
20
+ new RecordId (
21
+ "table" ,
22
+ new Uuid ( "d2f72714-a387-487a-8eae-451330796ff4" ) ,
23
+ ) . toString ( ) ,
24
+ ) . toBe ( 'table:u"d2f72714-a387-487a-8eae-451330796ff4"' ) ;
25
+
16
26
// Bigint
17
27
expect ( new RecordId ( "table" , 9223372036854775807n ) . toString ( ) ) . toBe (
18
28
"table:9223372036854775807" ,
You can’t perform that action at this time.
0 commit comments