Skip to content

Commit e843267

Browse files
committed
changed(moonapi): take base64url from moonbase, and declare the derived impls.
Signed-off-by: Leo Cheng (heke1228) <chengkelfan@qq.com>
1 parent afc6674 commit e843267

20 files changed

Lines changed: 156 additions & 30 deletions

app.mbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,3 +1427,6 @@ pub fn App::to_asgi(self : App) -> @moonasgi.AsgiApp {
14271427
}
14281428
}
14291429
}
1430+
1431+
///|
1432+
pub extend Method with Eq::{not_equal, equal}

constraint.mbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,6 @@ fn pattern_matches(s : String, p : String) -> Bool {
227227
let re = @string.Regex::Regex(p) catch { _ => return false }
228228
re.execute(s) is Some(_)
229229
}
230+
231+
///|
232+
pub extend Constraint with Eq::{not_equal, equal}

cookie.mbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,6 @@ pub fn delete_cookie(
195195
same_site~,
196196
)
197197
}
198+
199+
///|
200+
pub extend SameSite with Eq::{not_equal, equal}

demo.mbt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,30 @@ pub fn demo_app() -> App {
142142
)
143143
app
144144
}
145+
146+
///|
147+
pub extend Address with Eq::{not_equal, equal}
148+
149+
///|
150+
pub extend Address with ToJson::{to_json}
151+
152+
///|
153+
pub extend Address with ToSchema::{to_schema}
154+
155+
///|
156+
pub extend NewUser with Eq::{not_equal, equal}
157+
158+
///|
159+
pub extend NewUser with ToJson::{to_json}
160+
161+
///|
162+
pub extend NewUser with ToSchema::{to_schema}
163+
164+
///|
165+
pub extend User with Eq::{not_equal, equal}
166+
167+
///|
168+
pub extend User with ToJson::{to_json}
169+
170+
///|
171+
pub extend User with ToSchema::{to_schema}

di_demo.mbt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,15 @@ pub fn greet_app(container : Container[Dep]) -> App {
6363
)
6464
app
6565
}
66+
67+
///|
68+
pub extend GreetReq with Eq::{not_equal, equal}
69+
70+
///|
71+
pub extend GreetReq with FromJson::{from_json}
72+
73+
///|
74+
pub extend GreetReq with ToJson::{to_json}
75+
76+
///|
77+
pub extend Dep with Eq::{not_equal, equal}

endpoint.mbt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,15 @@ fn emit_endpoint(
293293
}
294294
op["responses"] = responses.to_json()
295295
}
296+
297+
///|
298+
pub extend ParamLoc with Eq::{not_equal, equal}
299+
300+
///|
301+
pub extend Param with Eq::{not_equal, equal}
302+
303+
///|
304+
pub extend ResponseSpec with Eq::{not_equal, equal}
305+
306+
///|
307+
pub extend Endpoint with Eq::{not_equal, equal}

examples/09-dependency-injection/moon.pkg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
"moonbitstack/moonapi",
3-
"moonbitstack/moonasgi",
43
"moonbitlang/core/encoding/utf8",
54
}
65

examples/17-sse/moon.pkg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
"moonbitstack/moonapi",
3-
"moonbitstack/moonasgi",
43
"moonbitlang/core/encoding/utf8",
54
}
65

examples/22-docs-ui/moon.pkg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
"moonbitstack/moonapi",
3-
"moonbitstack/moonasgi",
43
}
54

65
pkgtype(kind: "executable")

jwt.mbt

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,15 @@
33
/// remapped to `-`/`_` and trailing `=` dropped — the alphabet JWT uses for its
44
/// header, payload, and signature segments.
55
pub fn base64url_encode(data : Bytes) -> String {
6-
let std = @base64.encode(data[:], padding=false)
7-
let sb = StringBuilder()
8-
for i = 0; i < std.length(); i = i + 1 {
9-
let c = std[i]
10-
if c == '+' {
11-
sb.write_char('-')
12-
} else if c == '/' {
13-
sb.write_char('_')
14-
} else {
15-
sb.write_char(c.unsafe_to_char())
16-
}
17-
}
18-
sb.to_string()
6+
@base64.encode(data[:], kind=Url, padding=false)
197
}
208

219
///|
2210
/// Decode a base64url string (padding optional) back to bytes, remapping
2311
/// `-`/`_` to `+`/`/` first. Lenient about missing padding, the way JWT
2412
/// segments are written.
2513
pub fn base64url_decode(s : String) -> Bytes {
26-
let sb = StringBuilder()
27-
for i = 0; i < s.length(); i = i + 1 {
28-
let c = s[i]
29-
if c == '-' {
30-
sb.write_char('+')
31-
} else if c == '_' {
32-
sb.write_char('/')
33-
} else {
34-
sb.write_char(c.unsafe_to_char())
35-
}
36-
}
37-
@base64.decode_lossy(sb.to_string())
14+
@base64.decode_lossy(s, kind=Url)
3815
}
3916

4017
///|

0 commit comments

Comments
 (0)