@@ -2,54 +2,28 @@ namespace $ {
2
2
3
3
export class $mol_rest_message extends $mol_object {
4
4
5
- channel ( ) : $mol_rest_channel_http {
6
- return null !
7
- }
8
-
9
- input ( ) {
10
- return this . channel ( ) . input ( )
11
- }
5
+ port ! : $mol_rest_port
12
6
13
7
@ $mol_mem
14
8
method ( ) {
15
- return this . input ( ) . method ?? 'POST'
9
+ return 'POST'
16
10
}
17
11
18
12
@ $mol_mem
19
13
uri ( ) {
20
- const addr = this . input ( ) . socket ?. localAddress ?? 'localhost'
21
- const port = this . input ( ) . socket ?. localPort ?? '80'
22
- return new URL ( this . input ( ) . url ! , `http://[${ addr } ]:${ port } /` )
14
+ return new URL ( `rest://localhost/` )
23
15
}
24
16
25
17
@ $mol_mem
26
18
type ( ) {
27
- return ( this . input ( ) . headers [ 'content-type' ] ?? ' application/octet-stream' ) as $mol_rest_channel_mime
19
+ return ' application/octet-stream' as $mol_rest_port_mime
28
20
}
29
21
30
22
@ $mol_mem
31
- data ( ) : string | Uint8Array | object {
32
-
33
- const consume = $mol_wire_sync ( $node [ 'stream/consumers' ] )
34
-
35
- if ( this . type ( ) . startsWith ( 'text/' ) ) {
36
- const text = consume . text ( this . input ( ) )
37
- if ( this . type ( ) === 'text/html' ) {
38
- return $mol_dom_parse ( text , 'application/xhtml+xml' ) . documentElement
39
- }
40
- return text
41
- } else {
42
-
43
- if ( this . type ( ) === 'application/json' ) {
44
- return consume . json ( this . input ( ) )
45
- } else {
46
- return new Uint8Array ( consume . arrayBuffer ( this . input ( ) ) )
47
- }
48
-
49
- }
50
-
23
+ data ( ) : null | string | Uint8Array | Element | object {
24
+ return null
51
25
}
52
-
26
+
53
27
@ $mol_mem
54
28
bin ( ) {
55
29
let data = this . data ( )
@@ -71,35 +45,47 @@ namespace $ {
71
45
reply (
72
46
data : null | string | Uint8Array | Element | object ,
73
47
meta ?: {
74
- type ?: $mol_rest_channel_mime ,
48
+ type ?: $mol_rest_port_mime ,
75
49
code ?: $mol_rest_code ,
76
50
} ,
77
51
) {
78
- const channel = this . channel ( )
79
- if ( meta ?. code ) channel . send_code ( meta . code )
80
- if ( meta ?. type ) channel . send_type ( meta . type )
81
- channel . send_data ( data )
52
+ if ( meta ?. code ) this . port . send_code ( meta . code )
53
+ if ( meta ?. type ) this . port . send_type ( meta . type )
54
+ this . port . send_data ( data )
82
55
}
83
56
84
57
@ $mol_action
85
58
route ( uri : URL ) {
86
59
return $mol_rest_message . make ( {
60
+ port : this . port ,
61
+ method : ( ) => this . method ( ) ,
87
62
uri : $mol_const ( uri ) ,
63
+ type : ( ) => this . type ( ) ,
88
64
data : ( ) => this . data ( ) ,
89
- method : ( ) => this . method ( ) ,
90
- channel : ( ) => this . channel ( ) ,
91
65
} )
92
66
}
93
67
94
68
@ $mol_action
95
- static from (
96
- channel : $mol_rest_channel_http ,
69
+ derive (
70
+ method : string ,
71
+ data : null | string | Uint8Array | Element | object ,
97
72
) {
98
- return this . make ( {
99
- channel : $mol_const ( channel ) ,
73
+ return $mol_rest_message . make ( {
74
+ port : this . port ,
75
+ method : $mol_const ( method ) ,
76
+ uri : ( ) => this . uri ( ) ,
77
+ data : $mol_const ( data ) ,
100
78
} )
101
79
}
102
80
81
+ @ $mol_action < any , any >
82
+ public static make < This extends typeof $mol_object > (
83
+ this : This ,
84
+ config : Partial < InstanceType < This > > ,
85
+ ) {
86
+ return super . make ( config ) as InstanceType < This >
87
+ }
88
+
103
89
}
104
90
105
91
}
0 commit comments