@gcoredev/proxy-wasm-sdk-as 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 Solo.io, Inc.
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # WebAssembly for Proxies (AssemblyScript SDK)
2
+
3
+ This is a friendly fork of https://github.com/Kong/proxy-wasm-assemblyscript-sdk/,
4
+ temporarily mantained to address an incompatibility between the AssemblyScript
5
+ SDK and the Rust SDK.
6
+
7
+ ## How to use this SDK
8
+
9
+ Create a new project:
10
+
11
+ ```shell
12
+ npm init
13
+ npm install --save-dev assemblyscript
14
+ npx asinit .
15
+ ```
16
+
17
+ Include `"use": "abort=abort_proc_exit"` to the `asconfig.json` file as part of
18
+ the options passed to `asc` compiler:
19
+
20
+ ```json
21
+ {
22
+ "options": {
23
+ "use": "abort=abort_proc_exit"
24
+ }
25
+ }
26
+ ```
27
+
28
+ Add `"@gcoredev/proxy-wasm-sdk-as": "0.0.1"` to your dependencies then run `npm install`.
29
+
30
+ ## Hello, World
31
+
32
+ Copy this into assembly/index.ts:
33
+
34
+ ```ts
35
+ export * from "@gcoredev/proxy-wasm-sdk-as/proxy";
36
+ import {
37
+ RootContext,
38
+ Context,
39
+ registerRootContext,
40
+ FilterHeadersStatusValues,
41
+ stream_context,
42
+ } from "@gcoredev/proxy-wasm-sdk-as";
43
+
44
+ class AddHeaderRoot extends RootContext {
45
+ createContext(context_id: u32): Context {
46
+ return new AddHeader(context_id, this);
47
+ }
48
+ }
49
+
50
+ class AddHeader extends Context {
51
+ constructor(context_id: u32, root_context: AddHeaderRoot) {
52
+ super(context_id, root_context);
53
+ }
54
+ onResponseHeaders(a: u32, end_of_stream: bool): FilterHeadersStatusValues {
55
+ const root_context = this.root_context;
56
+ if (root_context.getConfiguration() == "") {
57
+ stream_context.headers.response.add("hello", "world!");
58
+ } else {
59
+ stream_context.headers.response.add(
60
+ "hello",
61
+ root_context.getConfiguration()
62
+ );
63
+ }
64
+ return FilterHeadersStatusValues.Continue;
65
+ }
66
+ }
67
+
68
+ registerRootContext((context_id: u32) => {
69
+ return new AddHeaderRoot(context_id);
70
+ }, "add_header");
71
+ ```
72
+
73
+ ## build
74
+
75
+ To build, simply run:
76
+
77
+ ```
78
+ npm run asbuild
79
+ ```
80
+
81
+ build results will be in the build folder. `untouched.wasm` and `optimized.wasm` are the compiled
82
+ file that we will use (you only need one of them, if unsure use `optimized.wasm`).
83
+
84
+ ## Run
85
+
86
+ Configure envoy with your filter:
87
+
88
+ ```yaml
89
+ - name: envoy.filters.http.wasm
90
+ config:
91
+ config:
92
+ name: "add_header"
93
+ root_id: "add_header"
94
+ configuration: "what ever you want"
95
+ vm_config:
96
+ vm_id: "my_vm_id"
97
+ runtime: "envoy.wasm.runtime.v8"
98
+ code:
99
+ local:
100
+ filename: /PATH/TO/CODE/build/optimized.wasm
101
+ allow_precompiled: false
102
+ ```
@@ -0,0 +1,138 @@
1
+ import { getBaseContext, getContext, getRootContext, ensureContext, ensureRootContext, deleteContext, PeerTypeValues } from "./runtime";
2
+
3
+ ///// CALLS IN
4
+ type FilterStatus = i32;
5
+ type FilterHeadersStatus = i32;
6
+ type FilterMetadataStatus = i32;
7
+ type FilterTrailersStatus = i32;
8
+ type FilterDataStatus = i32;
9
+ type GrpcStatus = i32;
10
+ type WasmOnDoneResult = u32;
11
+
12
+ // Calls in.
13
+ export function proxy_abi_version_0_2_1(): void { }
14
+
15
+ export function proxy_on_vm_start(root_context_id: u32, configuration_size: u32): u32 {
16
+ let root_context = getRootContext(root_context_id);
17
+ return root_context.onStart(configuration_size) ? 1 : 0;
18
+ }
19
+ export function proxy_validate_configuration(root_context_id: u32, configuration_size: u32): u32 {
20
+ let root_context = getRootContext(root_context_id);
21
+ return root_context.validateConfiguration(configuration_size) ? 1 : 0;
22
+ }
23
+ export function proxy_on_configure(root_context_id: u32, configuration_size: u32): u32 {
24
+ let root_context = getRootContext(root_context_id);
25
+ return root_context.onConfigure(configuration_size) ? 1 : 0;
26
+ }
27
+ export function proxy_on_tick(root_context_id: u32): void {
28
+ let root_context = getRootContext(root_context_id);
29
+ root_context.onTick();
30
+ }
31
+ export function proxy_on_foreign_function(root_context_id: u32, function_id: u32, data_size: u32): void {
32
+ // TODO: implement me
33
+ }
34
+
35
+ export function proxy_on_queue_ready(root_context_id: u32, token: u32): void {
36
+ let root_context = getRootContext(root_context_id);
37
+ root_context.onQueueReady(token);
38
+ }
39
+ // Stream calls.
40
+ export function proxy_on_context_create(context_id: u32, root_context_id: u32): void {
41
+ if (root_context_id != 0) {
42
+ ensureContext(context_id, root_context_id);
43
+ } else {
44
+ ensureRootContext(context_id);
45
+ }
46
+ }
47
+
48
+ export function proxy_on_request_headers(context_id: u32, headers: u32, end_of_stream: u32): FilterHeadersStatus {
49
+ let ctx = getContext(context_id);
50
+ return ctx.onRequestHeaders(headers, end_of_stream != 0) as FilterHeadersStatus;
51
+ }
52
+ export function proxy_on_request_body(context_id: u32, body_buffer_length: u32, end_of_stream: u32): FilterDataStatus {
53
+ let ctx = getContext(context_id);
54
+ return ctx.onRequestBody(body_buffer_length, end_of_stream != 0) as FilterDataStatus;
55
+ }
56
+ export function proxy_on_request_trailers(context_id: u32, trailers: u32): FilterTrailersStatus {
57
+ let ctx = getContext(context_id);
58
+ return ctx.onRequestTrailers(trailers) as FilterTrailersStatus;
59
+ }
60
+ export function proxy_on_request_metadata(context_id: u32, nelements: u32): FilterMetadataStatus {
61
+ let ctx = getContext(context_id);
62
+ return ctx.onRequestMetadata(nelements) as FilterMetadataStatus;
63
+ }
64
+ export function proxy_on_response_headers(context_id: u32, headers: u32, end_of_stream: u32): FilterHeadersStatus {
65
+ let ctx = getContext(context_id);
66
+ return ctx.onResponseHeaders(headers, end_of_stream != 0) as FilterHeadersStatus;
67
+ }
68
+ export function proxy_on_response_body(context_id: u32, body_buffer_length: u32, end_of_stream: u32): FilterDataStatus {
69
+ let ctx = getContext(context_id);
70
+ return ctx.onResponseBody(body_buffer_length, end_of_stream != 0) as FilterDataStatus;
71
+ }
72
+ export function proxy_on_response_trailers(context_id: u32, trailers: u32): FilterTrailersStatus {
73
+ let ctx = getContext(context_id);
74
+ return ctx.onResponseTrailers(trailers) as FilterTrailersStatus;
75
+ }
76
+ export function proxy_on_response_metadata(context_id: u32, nelements: u32): FilterMetadataStatus {
77
+ let ctx = getContext(context_id);
78
+ return ctx.onResponseMetadata(nelements) as FilterMetadataStatus;
79
+ }
80
+
81
+ // HTTP/gRPC.
82
+ export function proxy_on_http_call_response(context_id: u32, token: u32, headers: u32, body_size: u32, trailers: u32): void {
83
+ let ctx = getRootContext(context_id);
84
+ ctx.onHttpCallResponse(token, headers, body_size, trailers);
85
+ }
86
+ export function proxy_on_grpc_receive_initial_metadata(context_id: u32, token: u32, headers: u32): void {
87
+ getRootContext(context_id).on_grpc_receive_initial_metadata(token, headers)
88
+ }
89
+ export function proxy_on_grpc_trailing_metadata(context_id: u32, token: u32, trailers: u32): void {
90
+ getRootContext(context_id).on_grpc_trailing_metadata(token, trailers)
91
+ }
92
+ export function proxy_on_grpc_receive(context_id: u32, token: u32, response_size: u32): void {
93
+ getRootContext(context_id).on_grpc_receive(token, response_size)
94
+ }
95
+ export function proxy_on_grpc_close(context_id: u32, token: u32, status_code: u32): void {
96
+ getRootContext(context_id).on_grpc_close(token, status_code)
97
+ }
98
+
99
+ // NETWORK_FILTER support (TCP and, perhaps one day, UDP).
100
+ export function proxy_on_downstream_data(context_id: u32, body_buffer_length: u32, end_of_stream: u32): FilterStatus {
101
+ let ctx = getContext(context_id);
102
+ return ctx.onDownstreamData(body_buffer_length, end_of_stream != 0) as FilterStatus;
103
+ }
104
+ export function proxy_on_upstream_data(context_id: u32, body_buffer_length: u32, end_of_stream: u32): FilterStatus {
105
+ let ctx = getContext(context_id);
106
+ return ctx.onUpstreamData(body_buffer_length, end_of_stream != 0) as FilterStatus;
107
+ }
108
+ export function proxy_on_upstream_connection_close(context_id: u32, peer_type: u32): void {
109
+ let ctx = getContext(context_id);
110
+ ctx.onUpstreamConnectionClose(peer_type as PeerTypeValues);
111
+ }
112
+ export function proxy_on_downstream_connection_close(context_id: u32, peer_type: u32): void {
113
+ let ctx = getContext(context_id);
114
+ ctx.onDownstreamConnectionClose(peer_type as PeerTypeValues);
115
+ }
116
+ export function proxy_on_new_connection(context_id: u32): FilterStatus {
117
+ let ctx = getContext(context_id);
118
+ return ctx.onNewConnection() as FilterStatus;
119
+ }
120
+
121
+ // The stream/vm has completed.
122
+
123
+ export function proxy_on_done(context_id: u32): u32 {
124
+ let ctx = getBaseContext(context_id);
125
+ return ctx.onDone() ? 1 : 0;
126
+ }
127
+
128
+ // proxy_on_log occurs after proxy_on_done.
129
+ export function proxy_on_log(context_id: u32): void {
130
+ let ctx = getContext(context_id);
131
+ ctx.onLog();
132
+ }
133
+ // The Context in the proxy has been destroyed and no further calls will be coming.
134
+ export function proxy_on_delete(context_id: u32): void {
135
+ let ctx = getBaseContext(context_id);
136
+ ctx.onDelete();
137
+ deleteContext(context_id);
138
+ }
@@ -0,0 +1,175 @@
1
+
2
+ type char = u8;
3
+ type ptr<T> = usize;
4
+ type size_t = usize;
5
+
6
+ export type LogLevel = usize;
7
+ export type WasmResult = u32;
8
+ export type MetricType = i32;
9
+ export type PeerType = i32;
10
+ export type HeaderMapType = i32;
11
+ export type BufferType = i32;
12
+ export type BufferFlags = i32;
13
+ export type StreamType = i32;
14
+
15
+
16
+ // @ts-ignore: decorator
17
+ @external("env", "proxy_get_status")
18
+ // Results status details for any previous ABI call and onGrpcClose.
19
+ export declare function proxy_get_status(status_code_ptr: ptr<u32>, message_ptr: ptr<ptr<char>>, message_size: ptr<usize>): u32;
20
+
21
+ // Logging
22
+ // @ts-ignore: decorator
23
+ @external("env", "proxy_log")
24
+ export declare function proxy_log(level: LogLevel, logMessage: ptr<char>, messageSize: size_t): WasmResult;
25
+ // @ts-ignore: decorator
26
+ @external("env", "proxy_get_log_level")
27
+ export declare function proxy_get_log_level(status_code_ptr: ptr<LogLevel>): WasmResult;
28
+
29
+ // Timer (must be called from a root context, e.g. onStart, onTick).
30
+ // @ts-ignore: decorator
31
+ @external("env", "proxy_set_tick_period_milliseconds")
32
+ export declare function proxy_set_tick_period_milliseconds(millisecond: u32): WasmResult;
33
+
34
+ // Time
35
+ // @ts-ignore: decorator
36
+ @external("env", "proxy_get_current_time_nanoseconds")
37
+ export declare function proxy_get_current_time_nanoseconds(nanoseconds: ptr<u64>): WasmResult;
38
+
39
+ // State accessors
40
+ // @ts-ignore: decorator
41
+ @external("env", "proxy_get_property")
42
+ export declare function proxy_get_property(path_ptr: ptr<char>, path_size: size_t, value_ptr_ptr: ptr<ptr<char>>, value_size_ptr: ptr<usize>): WasmResult;
43
+ // @ts-ignore: decorator
44
+ @external("env", "proxy_set_property")
45
+ export declare function proxy_set_property(path_ptr: ptr<char>, path_size: size_t, value_ptr: ptr<char>, value_size: size_t): WasmResult;
46
+
47
+
48
+ // Continue/Reply/Route
49
+ // @ts-ignore: decorator
50
+ @external("env", "proxy_continue_stream")
51
+ export declare function proxy_continue_stream(stream_type: StreamType): WasmResult;
52
+ // @ts-ignore: decorator
53
+ @external("env", "proxy_close_stream")
54
+ export declare function proxy_close_stream(stream_type: StreamType): WasmResult;
55
+ // @ts-ignore: decorator
56
+ @external("env", "proxy_send_local_response")
57
+ export declare function proxy_send_local_response(response_code: u32, response_code_details_ptr: ptr<char>,
58
+ response_code_details_size: size_t, body_ptr: ptr<char>, body_size: size_t,
59
+ additional_response_header_pairs_ptr: ptr<char>,
60
+ additional_response_header_pairs_size: size_t, grpc_status: u32): WasmResult;
61
+ // @ts-ignore: decorator
62
+ @external("env", "proxy_clear_route_cache")
63
+ export declare function proxy_clear_route_cache(): WasmResult;
64
+
65
+ // SharedData
66
+ // Returns: Ok, NotFound
67
+ // @ts-ignore: decorator
68
+ @external("env", "proxy_get_shared_data")
69
+ export declare function proxy_get_shared_data(key_ptr: ptr<char>, key_size: size_t, value_ptr: ptr<ptr<char>>, value_size: ptr<usize>, cas: ptr<u32>): WasmResult;
70
+ // If cas != 0 and cas != the current cas for 'key' return false, otherwise set the value and
71
+ // return true.
72
+ // Returns: Ok, CasMismatch
73
+ // @ts-ignore: decorator
74
+ @external("env", "proxy_set_shared_data")
75
+ export declare function proxy_set_shared_data(key_ptr: ptr<char>, key_size: size_t, value_ptr: ptr<char>, value_size: size_t, cas: u32): WasmResult;
76
+
77
+ // SharedQueue
78
+ // Note: Registering the same queue_name will overwrite the old registration while preseving any
79
+ // pending data. Consequently it should typically be followed by a call to
80
+ // proxy_dequeue_shared_queue. Returns: Ok
81
+ // @ts-ignore: decorator
82
+ @external("env", "proxy_register_shared_queue")
83
+ export declare function proxy_register_shared_queue(queue_name_ptr: ptr<char>, queue_name_size: size_t, token: ptr<u32>): WasmResult;
84
+ // Returns: Ok, NotFound
85
+ // @ts-ignore: decorator
86
+ @external("env", "proxy_resolve_shared_queue")
87
+ export declare function proxy_resolve_shared_queue(vm_id: ptr<char>, vm_id_size: size_t, queue_name_ptr: ptr<char>, queue_name_size: size_t, token: ptr<u32>): WasmResult;
88
+ // Returns Ok, Empty, NotFound (token not registered).
89
+ // @ts-ignore: decorator
90
+ @external("env", "proxy_dequeue_shared_queue")
91
+ export declare function proxy_dequeue_shared_queue(token: u32, data_ptr: ptr<ptr<char>>, data_size: ptr<usize>): WasmResult;
92
+ // Returns false if the queue was not found and the data was not enqueued.
93
+ // @ts-ignore: decorator
94
+ @external("env", "proxy_enqueue_shared_queue")
95
+ export declare function proxy_enqueue_shared_queue(token: u32, data_ptr: ptr<char>, data_size: size_t): WasmResult;
96
+
97
+ // Headers/Trailers/Metadata Maps
98
+ // @ts-ignore: decorator
99
+ @external("env", "proxy_add_header_map_value")
100
+ export declare function proxy_add_header_map_value(typ: HeaderMapType, key_ptr: ptr<char>, key_size: size_t, value_ptr: ptr<char>, value_size: size_t): WasmResult;
101
+ // @ts-ignore: decorator
102
+ @external("env", "proxy_get_header_map_value")
103
+ export declare function proxy_get_header_map_value(typ: HeaderMapType, key_ptr: ptr<char>, key_size: size_t, value_ptr: ptr<ptr<char>>, value_size: ptr<usize>): WasmResult;
104
+ // @ts-ignore: decorator
105
+ @external("env", "proxy_get_header_map_pairs")
106
+ export declare function proxy_get_header_map_pairs(typ: HeaderMapType, ptr: ptr<ptr<char>>, size: ptr<usize>): WasmResult;
107
+ // @ts-ignore: decorator
108
+ @external("env", "proxy_set_header_map_pairs")
109
+ export declare function proxy_set_header_map_pairs(typ: HeaderMapType, ptr: ptr<char>, size: size_t): WasmResult;
110
+ // @ts-ignore: decorator
111
+ @external("env", "proxy_replace_header_map_value")
112
+ export declare function proxy_replace_header_map_value(typ: HeaderMapType, key_ptr: ptr<char>, key_size: size_t, value_ptr: ptr<char>, value_size: size_t): WasmResult;
113
+ // @ts-ignore: decorator
114
+ @external("env", "proxy_remove_header_map_value")
115
+ export declare function proxy_remove_header_map_value(typ: HeaderMapType, key_ptr: ptr<char>, key_size: size_t): WasmResult;
116
+ // @ts-ignore: decorator
117
+ @external("env", "proxy_get_header_map_size")
118
+ export declare function proxy_get_header_map_size(typ: HeaderMapType, size: ptr<usize>): WasmResult;
119
+
120
+ // Buffer
121
+ // @ts-ignore: decorator
122
+ @external("env", "proxy_get_buffer_bytes")
123
+ export declare function proxy_get_buffer_bytes(typ: BufferType, start: u32, length: u32, ptr: ptr<ptr<char>>, size: ptr<usize>): WasmResult;
124
+ // @ts-ignore: decorator
125
+ @external("env", "proxy_get_buffer_status")
126
+ export declare function proxy_get_buffer_status(typ: BufferType, length_ptr: ptr<usize>, flags_ptr: ptr<u32>): WasmResult;
127
+
128
+ // HTTP
129
+ // @ts-ignore: decorator
130
+ @external("env", "proxy_http_call")
131
+ export declare function proxy_http_call(uri_ptr: ptr<char>, uri_size: size_t, header_pairs_ptr: ptr<void>, header_pairs_size: size_t, body_ptr: ptr<char>, body_size: size_t, trailer_pairs_ptr: ptr<void>, trailer_pairs_size: size_t, timeout_milliseconds: u32, token_ptr: ptr<u32>): WasmResult;
132
+ // gRPC
133
+ // @ts-ignore: decorator
134
+ @external("env", "proxy_grpc_call")
135
+ export declare function proxy_grpc_call(service_ptr: ptr<char>, service_size: size_t, service_name_ptr: ptr<char>, service_name_size: size_t, method_name_ptr: ptr<char>, method_name_size: size_t, request_ptr: ptr<char>, request_size: size_t, timeout_milliseconds: u32, token_ptr: ptr<u32>): WasmResult;
136
+ // @ts-ignore: decorator
137
+ @external("env", "proxy_grpc_stream")
138
+ export declare function proxy_grpc_stream(service_ptr: ptr<char>, service_size: size_t, service_name_ptr: ptr<char>, service_name_size: size_t, method_name_ptr: ptr<char>, method_name_size: size_t, token_ptr: ptr<u32>): WasmResult;
139
+ // @ts-ignore: decorator
140
+ @external("env", "proxy_grpc_cancel")
141
+ export declare function proxy_grpc_cancel(token: u32): WasmResult;
142
+ // @ts-ignore: decorator
143
+ @external("env", "proxy_grpc_close")
144
+ export declare function proxy_grpc_close(token: u32): WasmResult;
145
+ // @ts-ignore: decorator
146
+ @external("env", "proxy_grpc_send")
147
+ export declare function proxy_grpc_send(token: u32, message_ptr: ptr<char>, message_size: size_t, end_stream: u32): WasmResult;
148
+
149
+ // Metrics
150
+ // @ts-ignore: decorator
151
+ @external("env", "proxy_define_metric")
152
+ export declare function proxy_define_metric(type: MetricType, name_ptr: ptr<char>, name_size: size_t, metric_id: ptr<u32>): WasmResult;
153
+ // @ts-ignore: decorator
154
+ @external("env", "proxy_increment_metric")
155
+ export declare function proxy_increment_metric(metric_id: u32, offset: i64): WasmResult;
156
+ // @ts-ignore: decorator
157
+ @external("env", "proxy_record_metric")
158
+ export declare function proxy_record_metric(metric_id: u32, value: u64): WasmResult;
159
+ // @ts-ignore: decorator
160
+ @external("env", "proxy_get_metric")
161
+ export declare function proxy_get_metric(metric_id: u32, result: ptr<u64>): WasmResult;
162
+
163
+ // System
164
+ // @ts-ignore: decorator
165
+ @external("env", "proxy_set_effective_context")
166
+ export declare function proxy_set_effective_context(effective_context_id: u32): WasmResult;
167
+ // @ts-ignore: decorator
168
+ @external("env", "proxy_done")
169
+ export declare function proxy_done(): WasmResult;
170
+ // @ts-ignore: decorator
171
+ @external("env", "proxy_call_foreign_function")
172
+ export declare function proxy_call_foreign_function(function_name: ptr<char>,
173
+ name_size: size_t, arguments: ptr<char>,
174
+ arguments_size: size_t, results: ptr<ptr<char>>,
175
+ results_size: ptr<size_t>): WasmResult;
@@ -0,0 +1,15 @@
1
+ export {
2
+ BaseContext, RootContext, Context, registerRootContext,
3
+ BufferTypeValues, LogLevelValues, WasmResultValues, GrpcStatusValues,
4
+ FilterStatusValues,
5
+ FilterHeadersStatusValues,
6
+ FilterMetadataStatusValues,
7
+ FilterTrailersStatusValues,
8
+ FilterDataStatusValues, stream_context,
9
+ HeaderPair, Headers, makeHeaderPair,
10
+ Gauge, Histogram, Counter, log,
11
+ HttpCallback, send_local_response, send_http_response, continue_request, continue_response,
12
+ proxy_set_effective_context, set_property, get_property, get_shared_data, GetSharedData, set_shared_data, set_tick_period_milliseconds,
13
+ register_shared_queue, resolve_shared_queue, enqueue_shared_queue, dequeue_shared_queue,
14
+ get_buffer_bytes, call_foreign_function, get_current_time_nanoseconds
15
+ } from "./runtime";
@@ -0,0 +1,16 @@
1
+ import {
2
+ __pin,
3
+ __unpin,
4
+ } from "rt/itcms";
5
+
6
+ /// Allow host to allocate memory.
7
+ export function malloc(size: i32): usize {
8
+ let buffer = new ArrayBuffer(size);
9
+ let ptr = changetype<usize>(buffer);
10
+ return __pin(ptr);
11
+ }
12
+
13
+ /// Allow host to free memory.
14
+ export function free(ptr: usize): void {
15
+ __unpin(ptr);
16
+ }
@@ -0,0 +1,2 @@
1
+ export { malloc } from "./malloc";
2
+ export * from "./exports";