@gcoredev/proxy-wasm-sdk-as 1.0.1 → 1.1.0

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/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # WebAssembly for Proxies (AssemblyScript SDK)
2
2
 
3
-
4
3
  [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/G-Core/proxy-wasm-sdk-as/deploy.yaml)](https://github.com/G-Core/proxy-wasm-sdk-as)
5
4
  [![GitHub commit activity](https://img.shields.io/github/commit-activity/t/G-Core/proxy-wasm-sdk-as)](https://github.com/G-Core/proxy-wasm-sdk-as)
6
5
  [![GitHub top language](https://img.shields.io/github/languages/top/G-Core/proxy-wasm-sdk-as)](https://github.com/G-Core/proxy-wasm-sdk-as)
@@ -8,8 +7,9 @@
8
7
  [![NPM Version](https://img.shields.io/npm/v/@gcoredev/proxy-wasm-sdk-as)](https://www.npmjs.com/package/@gcoredev/proxy-wasm-sdk-as)
9
8
 
10
9
  This is a friendly fork of https://github.com/Kong/proxy-wasm-assemblyscript-sdk/,
11
- temporarily mantained to address an incompatibility between the AssemblyScript
12
- SDK and the Rust SDK.
10
+ mantained to address an incompatibility between the AssemblyScript SDK and the Rust SDK,
11
+
12
+ It also adds some FastEdge specific functionality.
13
13
 
14
14
  ## How to use this SDK
15
15
 
@@ -32,21 +32,21 @@ the options passed to `asc` compiler:
32
32
  }
33
33
  ```
34
34
 
35
- Add `"@gcoredev/proxy-wasm-sdk-as": "0.0.1"` to your dependencies then run `npm install`.
35
+ Add `"@gcoredev/proxy-wasm-sdk-as": "^1.0.2"` to your dependencies then run `npm install`.
36
36
 
37
37
  ## Hello, World
38
38
 
39
39
  Copy this into assembly/index.ts:
40
40
 
41
41
  ```ts
42
- export * from "@gcoredev/proxy-wasm-sdk-as/proxy";
42
+ export * from "@gcoredev/proxy-wasm-sdk-as/assembly/proxy";
43
43
  import {
44
44
  RootContext,
45
45
  Context,
46
46
  registerRootContext,
47
47
  FilterHeadersStatusValues,
48
48
  stream_context,
49
- } from "@gcoredev/proxy-wasm-sdk-as";
49
+ } from "@gcoredev/proxy-wasm-sdk-as/assembly";
50
50
 
51
51
  class AddHeaderRoot extends RootContext {
52
52
  createContext(context_id: u32): Context {
@@ -77,7 +77,7 @@ registerRootContext((context_id: u32) => {
77
77
  }, "add_header");
78
78
  ```
79
79
 
80
- ## build
80
+ ## Build
81
81
 
82
82
  To build, simply run:
83
83
 
@@ -85,25 +85,17 @@ To build, simply run:
85
85
  npm run asbuild
86
86
  ```
87
87
 
88
- build results will be in the build folder. `untouched.wasm` and `optimized.wasm` are the compiled
89
- file that we will use (you only need one of them, if unsure use `optimized.wasm`).
88
+ build results will be in the build folder. `debug.wasm` and `release.wasm` are the compiled
89
+ file that we will use (you only need one of them, if unsure use `release.wasm`).
90
90
 
91
91
  ## Run
92
92
 
93
- Configure envoy with your filter:
94
-
95
- ```yaml
96
- - name: envoy.filters.http.wasm
97
- config:
98
- config:
99
- name: "add_header"
100
- root_id: "add_header"
101
- configuration: "what ever you want"
102
- vm_config:
103
- vm_id: "my_vm_id"
104
- runtime: "envoy.wasm.runtime.v8"
105
- code:
106
- local:
107
- filename: /PATH/TO/CODE/build/optimized.wasm
108
- allow_precompiled: false
109
- ```
93
+ These binaries can then be uploaded and attached to your CDN applications within the FastEdge UI portal.
94
+
95
+ For some binaries (the above example for instance) you can test localy using envoy.
96
+
97
+ Please see [Envoy.md](./ENVOY.md)
98
+
99
+ ## Examples
100
+
101
+ For more examples on how to use this `proxy-wasm-sdk-as` please see our [examples repo](https://github.com/G-Core/FastEdge-examples/tree/main/assemblyscript)
@@ -1,4 +1,12 @@
1
- import { getBaseContext, getContext, getRootContext, ensureContext, ensureRootContext, deleteContext, PeerTypeValues } from "./runtime";
1
+ import {
2
+ getBaseContext,
3
+ getContext,
4
+ getRootContext,
5
+ ensureContext,
6
+ ensureRootContext,
7
+ deleteContext,
8
+ PeerTypeValues,
9
+ } from "./runtime";
2
10
 
3
11
  ///// CALLS IN
4
12
  type FilterStatus = i32;
@@ -10,17 +18,26 @@ type GrpcStatus = i32;
10
18
  type WasmOnDoneResult = u32;
11
19
 
12
20
  // Calls in.
13
- export function proxy_abi_version_0_2_1(): void { }
21
+ export function proxy_abi_version_0_2_1(): void {}
14
22
 
15
- export function proxy_on_vm_start(root_context_id: u32, configuration_size: u32): u32 {
23
+ export function proxy_on_vm_start(
24
+ root_context_id: u32,
25
+ configuration_size: u32
26
+ ): u32 {
16
27
  let root_context = getRootContext(root_context_id);
17
28
  return root_context.onStart(configuration_size) ? 1 : 0;
18
29
  }
19
- export function proxy_validate_configuration(root_context_id: u32, configuration_size: u32): u32 {
30
+ export function proxy_validate_configuration(
31
+ root_context_id: u32,
32
+ configuration_size: u32
33
+ ): u32 {
20
34
  let root_context = getRootContext(root_context_id);
21
35
  return root_context.validateConfiguration(configuration_size) ? 1 : 0;
22
36
  }
23
- export function proxy_on_configure(root_context_id: u32, configuration_size: u32): u32 {
37
+ export function proxy_on_configure(
38
+ root_context_id: u32,
39
+ configuration_size: u32
40
+ ): u32 {
24
41
  let root_context = getRootContext(root_context_id);
25
42
  return root_context.onConfigure(configuration_size) ? 1 : 0;
26
43
  }
@@ -28,7 +45,11 @@ export function proxy_on_tick(root_context_id: u32): void {
28
45
  let root_context = getRootContext(root_context_id);
29
46
  root_context.onTick();
30
47
  }
31
- export function proxy_on_foreign_function(root_context_id: u32, function_id: u32, data_size: u32): void {
48
+ export function proxy_on_foreign_function(
49
+ root_context_id: u32,
50
+ function_id: u32,
51
+ data_size: u32
52
+ ): void {
32
53
  // TODO: implement me
33
54
  }
34
55
 
@@ -37,7 +58,10 @@ export function proxy_on_queue_ready(root_context_id: u32, token: u32): void {
37
58
  root_context.onQueueReady(token);
38
59
  }
39
60
  // Stream calls.
40
- export function proxy_on_context_create(context_id: u32, root_context_id: u32): void {
61
+ export function proxy_on_context_create(
62
+ context_id: u32,
63
+ root_context_id: u32
64
+ ): void {
41
65
  if (root_context_id != 0) {
42
66
  ensureContext(context_id, root_context_id);
43
67
  } else {
@@ -45,77 +69,159 @@ export function proxy_on_context_create(context_id: u32, root_context_id: u32):
45
69
  }
46
70
  }
47
71
 
48
- export function proxy_on_request_headers(context_id: u32, headers: u32, end_of_stream: u32): FilterHeadersStatus {
72
+ export function proxy_on_request_headers(
73
+ context_id: u32,
74
+ headers: u32,
75
+ end_of_stream: u32
76
+ ): FilterHeadersStatus {
49
77
  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 {
78
+ return ctx.onRequestHeaders(
79
+ headers,
80
+ end_of_stream != 0
81
+ ) as FilterHeadersStatus;
82
+ }
83
+ export function proxy_on_request_body(
84
+ context_id: u32,
85
+ body_buffer_length: u32,
86
+ end_of_stream: u32
87
+ ): FilterDataStatus {
53
88
  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 {
89
+ return ctx.onRequestBody(
90
+ body_buffer_length,
91
+ end_of_stream != 0
92
+ ) as FilterDataStatus;
93
+ }
94
+ export function proxy_on_request_trailers(
95
+ context_id: u32,
96
+ trailers: u32
97
+ ): FilterTrailersStatus {
57
98
  let ctx = getContext(context_id);
58
99
  return ctx.onRequestTrailers(trailers) as FilterTrailersStatus;
59
100
  }
60
- export function proxy_on_request_metadata(context_id: u32, nelements: u32): FilterMetadataStatus {
101
+ export function proxy_on_request_metadata(
102
+ context_id: u32,
103
+ nelements: u32
104
+ ): FilterMetadataStatus {
61
105
  let ctx = getContext(context_id);
62
106
  return ctx.onRequestMetadata(nelements) as FilterMetadataStatus;
63
107
  }
64
- export function proxy_on_response_headers(context_id: u32, headers: u32, end_of_stream: u32): FilterHeadersStatus {
108
+ export function proxy_on_response_headers(
109
+ context_id: u32,
110
+ headers: u32,
111
+ end_of_stream: u32
112
+ ): FilterHeadersStatus {
65
113
  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 {
114
+ return ctx.onResponseHeaders(
115
+ headers,
116
+ end_of_stream != 0
117
+ ) as FilterHeadersStatus;
118
+ }
119
+ export function proxy_on_response_body(
120
+ context_id: u32,
121
+ body_buffer_length: u32,
122
+ end_of_stream: u32
123
+ ): FilterDataStatus {
69
124
  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 {
125
+ return ctx.onResponseBody(
126
+ body_buffer_length,
127
+ end_of_stream != 0
128
+ ) as FilterDataStatus;
129
+ }
130
+ export function proxy_on_response_trailers(
131
+ context_id: u32,
132
+ trailers: u32
133
+ ): FilterTrailersStatus {
73
134
  let ctx = getContext(context_id);
74
135
  return ctx.onResponseTrailers(trailers) as FilterTrailersStatus;
75
136
  }
76
- export function proxy_on_response_metadata(context_id: u32, nelements: u32): FilterMetadataStatus {
137
+ export function proxy_on_response_metadata(
138
+ context_id: u32,
139
+ nelements: u32
140
+ ): FilterMetadataStatus {
77
141
  let ctx = getContext(context_id);
78
142
  return ctx.onResponseMetadata(nelements) as FilterMetadataStatus;
79
143
  }
80
144
 
81
145
  // HTTP/gRPC.
82
- export function proxy_on_http_call_response(context_id: u32, token: u32, headers: u32, body_size: u32, trailers: u32): void {
146
+ export function proxy_on_http_call_response(
147
+ context_id: u32,
148
+ token: u32,
149
+ headers: u32,
150
+ body_size: u32,
151
+ trailers: u32
152
+ ): void {
83
153
  let ctx = getRootContext(context_id);
84
154
  ctx.onHttpCallResponse(token, headers, body_size, trailers);
85
155
  }
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)
156
+ export function proxy_on_grpc_receive_initial_metadata(
157
+ context_id: u32,
158
+ token: u32,
159
+ headers: u32
160
+ ): void {
161
+ getRootContext(context_id).on_grpc_receive_initial_metadata(token, headers);
162
+ }
163
+ export function proxy_on_grpc_trailing_metadata(
164
+ context_id: u32,
165
+ token: u32,
166
+ trailers: u32
167
+ ): void {
168
+ getRootContext(context_id).on_grpc_trailing_metadata(token, trailers);
169
+ }
170
+ export function proxy_on_grpc_receive(
171
+ context_id: u32,
172
+ token: u32,
173
+ response_size: u32
174
+ ): void {
175
+ getRootContext(context_id).on_grpc_receive(token, response_size);
176
+ }
177
+ export function proxy_on_grpc_close(
178
+ context_id: u32,
179
+ token: u32,
180
+ status_code: u32
181
+ ): void {
182
+ getRootContext(context_id).on_grpc_close(token, status_code);
97
183
  }
98
184
 
99
185
  // 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);
186
+ export function proxy_on_downstream_data(
187
+ context_id: u32,
188
+ body_buffer_length: u32,
189
+ end_of_stream: u32
190
+ ): FilterStatus {
191
+ let ctx = getContext(context_id);
192
+ return ctx.onDownstreamData(
193
+ body_buffer_length,
194
+ end_of_stream != 0
195
+ ) as FilterStatus;
196
+ }
197
+ export function proxy_on_upstream_data(
198
+ context_id: u32,
199
+ body_buffer_length: u32,
200
+ end_of_stream: u32
201
+ ): FilterStatus {
202
+ let ctx = getContext(context_id);
203
+ return ctx.onUpstreamData(
204
+ body_buffer_length,
205
+ end_of_stream != 0
206
+ ) as FilterStatus;
207
+ }
208
+ export function proxy_on_upstream_connection_close(
209
+ context_id: u32,
210
+ peer_type: u32
211
+ ): void {
212
+ let ctx = getContext(context_id);
213
+ ctx.onUpstreamConnectionClose(peer_type as PeerTypeValues);
111
214
  }
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);
215
+ export function proxy_on_downstream_connection_close(
216
+ context_id: u32,
217
+ peer_type: u32
218
+ ): void {
219
+ let ctx = getContext(context_id);
220
+ ctx.onDownstreamConnectionClose(peer_type as PeerTypeValues);
115
221
  }
116
222
  export function proxy_on_new_connection(context_id: u32): FilterStatus {
117
- let ctx = getContext(context_id);
118
- return ctx.onNewConnection() as FilterStatus;
223
+ let ctx = getContext(context_id);
224
+ return ctx.onNewConnection() as FilterStatus;
119
225
  }
120
226
 
121
227
  // The stream/vm has completed.
@@ -0,0 +1,82 @@
1
+ import * as imports from "./imports";
2
+
3
+ import {
4
+ get_current_time_nanoseconds,
5
+ globalArrayBufferReference,
6
+ LogLevelValues,
7
+ } from "./runtime";
8
+
9
+ let logLevel: LogLevelValues = LogLevelValues.info;
10
+
11
+ function setLogLevel(level: LogLevelValues): void {
12
+ logLevel = level;
13
+ }
14
+
15
+ function log(level: LogLevelValues, logMessage: string): void {
16
+ // Temporary fix for proxy_log not being implemented in fastedge:
17
+ // relies on @assemblyscript/wasi-shim to print to standard output
18
+ if (level >= logLevel) {
19
+ process.stdout.write(logMessage + "\n");
20
+ }
21
+ }
22
+
23
+ function getCurrentTime(): u64 {
24
+ return get_current_time_nanoseconds() / 1_000_000; // Convert nanoseconds to milliseconds
25
+ }
26
+
27
+ function getEnvVar(key: string): string {
28
+ const hasKey = process.env.has(key);
29
+ if (hasKey) {
30
+ return process.env.get(key);
31
+ }
32
+ return "";
33
+ }
34
+
35
+ function getSecretVar(key: string): string {
36
+ const buffer = String.UTF8.encode(key);
37
+ const status = imports.proxy_get_secret(
38
+ changetype<usize>(buffer),
39
+ buffer.byteLength,
40
+ globalArrayBufferReference.bufferPtr(),
41
+ globalArrayBufferReference.sizePtr()
42
+ );
43
+ if (status != 0) {
44
+ // Something went wrong - returns 0 with an empty ArrayBuffer if not found
45
+ return "";
46
+ }
47
+ const arrBuff = globalArrayBufferReference.toArrayBuffer();
48
+ if (arrBuff.byteLength == 0) {
49
+ return ""; // Not found
50
+ }
51
+ return String.UTF8.decode(arrBuff);
52
+ }
53
+
54
+ function getSecretVarEffectiveAt(key: string, at: u32): string {
55
+ const buffer = String.UTF8.encode(key);
56
+ const status = imports.proxy_get_effective_at_secret(
57
+ changetype<usize>(buffer),
58
+ buffer.byteLength,
59
+ at,
60
+ globalArrayBufferReference.bufferPtr(),
61
+ globalArrayBufferReference.sizePtr()
62
+ );
63
+ if (status != 0) {
64
+ // Something went wrong - returns 0 with an empty ArrayBuffer if not found
65
+ return "";
66
+ }
67
+ const arrBuff = globalArrayBufferReference.toArrayBuffer();
68
+ if (arrBuff.byteLength == 0) {
69
+ return ""; // Not found
70
+ }
71
+ return String.UTF8.decode(arrBuff);
72
+ }
73
+
74
+ export {
75
+ getCurrentTime,
76
+ getEnvVar,
77
+ getSecretVar,
78
+ getSecretVarEffectiveAt,
79
+ log,
80
+ LogLevelValues,
81
+ setLogLevel,
82
+ };
@@ -124,6 +124,10 @@ export declare function proxy_get_buffer_bytes(typ: BufferType, start: u32, leng
124
124
  // @ts-ignore: decorator
125
125
  @external("env", "proxy_get_buffer_status")
126
126
  export declare function proxy_get_buffer_status(typ: BufferType, length_ptr: ptr<usize>, flags_ptr: ptr<u32>): WasmResult;
127
+ // @ts-ignore: decorator
128
+ @external("env", "proxy_set_buffer_bytes")
129
+ export declare function proxy_set_buffer_bytes(typ: BufferType, start: u32, length: u32, ptr: ptr<ptr<char>>, size: ptr<usize>): WasmResult;
130
+
127
131
 
128
132
  // HTTP
129
133
  // @ts-ignore: decorator
@@ -173,3 +177,27 @@ export declare function proxy_call_foreign_function(function_name: ptr<char>,
173
177
  name_size: size_t, arguments: ptr<char>,
174
178
  arguments_size: size_t, results: ptr<ptr<char>>,
175
179
  results_size: ptr<size_t>): WasmResult;
180
+
181
+ // FastEdge HOST Apis
182
+
183
+ // Secrets
184
+ // @ts-ignore: decorator
185
+ @external("env", "proxy_get_secret")
186
+ export declare function proxy_get_secret(
187
+ key_data: usize,
188
+ key_size: usize,
189
+ return_value_data: usize,
190
+ return_value_size: usize
191
+ ): u32;
192
+
193
+
194
+ // @ts-ignore: decorator
195
+ @external("env", "proxy_get_effective_at_secret")
196
+ export declare function proxy_get_effective_at_secret(
197
+ key_data: usize,
198
+ key_size: usize,
199
+ at: u32,
200
+ return_value_data: usize,
201
+ return_value_size: usize
202
+ ): u32;
203
+
package/assembly/index.ts CHANGED
@@ -1,15 +1,51 @@
1
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
2
+ BaseContext,
3
+ BufferTypeValues,
4
+ call_foreign_function,
5
+ Context,
6
+ continue_request,
7
+ continue_response,
8
+ Counter,
9
+ dequeue_shared_queue,
10
+ enqueue_shared_queue,
11
+ FilterDataStatusValues,
12
+ FilterHeadersStatusValues,
13
+ FilterMetadataStatusValues,
14
+ FilterStatusValues,
15
+ FilterTrailersStatusValues,
16
+ Gauge,
17
+ get_buffer_bytes,
18
+ get_current_time_nanoseconds,
19
+ get_property,
20
+ get_shared_data,
21
+ GetSharedData,
22
+ GrpcStatusValues,
23
+ HeaderPair,
24
+ Headers,
25
+ Histogram,
26
+ HttpCallback,
27
+ log,
28
+ LogLevelValues,
29
+ makeHeaderPair,
30
+ proxy_set_effective_context,
31
+ register_shared_queue,
32
+ registerRootContext,
33
+ resolve_shared_queue,
34
+ RootContext,
35
+ send_http_response,
36
+ send_local_response,
37
+ set_buffer_bytes,
38
+ set_property,
39
+ set_shared_data,
40
+ set_tick_period_milliseconds,
41
+ stream_context,
42
+ WasmResultValues,
15
43
  } from "./runtime";
44
+
45
+ export {
46
+ getCurrentTime,
47
+ getEnvVar,
48
+ getSecretVar,
49
+ getSecretVarEffectiveAt,
50
+ setLogLevel,
51
+ } from "./fastedge";
@@ -1,6 +1,8 @@
1
1
  import * as imports from "./imports";
2
2
  import { free } from "./malloc";
3
3
 
4
+ import { log as wasiLog } from "./fastedge";
5
+
4
6
  // abort function.
5
7
  // use with:
6
8
  // --use abort=index/abort_proc_exit
@@ -69,7 +71,7 @@ class ArrayBufferReference {
69
71
  }
70
72
  }
71
73
 
72
- var globalArrayBufferReference = new ArrayBufferReference();
74
+ export const globalArrayBufferReference = new ArrayBufferReference();
73
75
  let globalU32Ref = new Reference<u32>();
74
76
  let globalLogLevelRef = new Reference<imports.LogLevel>();
75
77
  let globalU64Ref = new Reference<u64>();
@@ -217,8 +219,11 @@ export enum StreamTypeValues {
217
219
  export function log(level: LogLevelValues, logMessage: string): void {
218
220
  // from the docs:
219
221
  // Like JavaScript, AssemblyScript stores strings in UTF-16 encoding represented by the API as UCS-2,
220
- let buffer = String.UTF8.encode(logMessage);
221
- imports.proxy_log(level as imports.LogLevel, changetype<usize>(buffer), buffer.byteLength);
222
+ // let buffer = String.UTF8.encode(logMessage);
223
+ // imports.proxy_log(level as imports.LogLevel, changetype<usize>(buffer), buffer.byteLength);
224
+
225
+ // Temporary fix for proxy_log not being implemented in fastedge:
226
+ wasiLog(level, logMessage);
222
227
  }
223
228
 
224
229
  export function logLevel(): LogLevelValues {
@@ -251,8 +256,12 @@ export function get_current_time_nanoseconds(): u64 {
251
256
 
252
257
  export function get_property(path: string): ArrayBuffer {
253
258
  let buffer = String.UTF8.encode(path);
254
- CHECK_RESULT(imports.proxy_get_property(changetype<usize>(buffer), buffer.byteLength, globalArrayBufferReference.bufferPtr(), globalArrayBufferReference.sizePtr()));
255
- return globalArrayBufferReference.toArrayBuffer();
259
+ const result = imports.proxy_get_property(changetype<usize>(buffer), buffer.byteLength, globalArrayBufferReference.bufferPtr(), globalArrayBufferReference.sizePtr());
260
+ CHECK_RESULT(result);
261
+ if (result == WasmResultValues.Ok) {
262
+ return globalArrayBufferReference.toArrayBuffer();
263
+ }
264
+ return new ArrayBuffer(0); // result == WasmResultValues.NotFound
256
265
  }
257
266
 
258
267
  export function set_property(path: string, data: ArrayBuffer): WasmResultValues {
@@ -622,6 +631,12 @@ export function get_buffer_bytes(typ: BufferTypeValues, start: u32, length: u32)
622
631
  return new ArrayBuffer(0);
623
632
  }
624
633
 
634
+ export function set_buffer_bytes(typ: BufferTypeValues, start: u32, length: u32, value: ArrayBuffer): WasmResultValues {
635
+ const result = imports.proxy_set_buffer_bytes(typ, start, length, changetype<usize>(value), value.byteLength);
636
+ wasiLog(LogLevelValues.info, 'Farq: setBuffer result: ' + result.toString());
637
+ return result
638
+ }
639
+
625
640
  // returning tuples is not supported.
626
641
  class BufferStatusResult {
627
642
  result: WasmResultValues;
@@ -1112,3 +1127,5 @@ export function registerRootContext(
1112
1127
  name: string): void {
1113
1128
  root_context_factory = context_factory;
1114
1129
  }
1130
+
1131
+
package/package.json CHANGED
@@ -7,6 +7,7 @@
7
7
  "docs": "typedoc"
8
8
  },
9
9
  "devDependencies": {
10
+ "@assemblyscript/wasi-shim": "^0.1.0",
10
11
  "@semantic-release/changelog": "^6.0.3",
11
12
  "assemblyscript": "^0.27.34",
12
13
  "http-server": "^14.1.1",
@@ -16,7 +17,7 @@
16
17
  },
17
18
  "name": "@gcoredev/proxy-wasm-sdk-as",
18
19
  "description": "Use this SDK to write extensions for the proxy WASM ABI",
19
- "version": "1.0.1",
20
+ "version": "1.1.0",
20
21
  "main": "assembly/index.ts",
21
22
  "directories": {
22
23
  "doc": "docs"