@tokamakdev/platform-ios-arm64 0.1.1-beta.50 → 0.1.1-beta.51
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.
|
@@ -11,12 +11,6 @@ enum {
|
|
|
11
11
|
TOKAMAK_DECISION_USE = 2,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
enum {
|
|
15
|
-
TOKAMAK_DISPATCH_HANDLED = 0,
|
|
16
|
-
TOKAMAK_DISPATCH_UNHANDLED = 1,
|
|
17
|
-
TOKAMAK_DISPATCH_FAILED = 2,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
14
|
typedef struct {
|
|
21
15
|
uint8_t *data;
|
|
22
16
|
size_t len;
|
|
@@ -39,10 +33,10 @@ uint16_t tokamak_runtime_restore_gateway(const void *runtime, char *error,
|
|
|
39
33
|
bool tokamak_runtime_suspend(const void *runtime);
|
|
40
34
|
bool tokamak_runtime_resume(const void *runtime);
|
|
41
35
|
void tokamak_runtime_stop(void *runtime);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
bool tokamak_runtime_call(const void *runtime, const char *name,
|
|
37
|
+
const char *body, uint64_t timeout_ms,
|
|
38
|
+
TokamakBytes *response, char *error,
|
|
39
|
+
size_t error_len);
|
|
46
40
|
|
|
47
41
|
int32_t tokamak_runtime_server_authority(const void *runtime, const char *host,
|
|
48
42
|
TokamakBytes *authority);
|
|
Binary file
|
|
@@ -32,15 +32,15 @@ final class TokamakHost {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
///
|
|
36
|
-
///
|
|
37
|
-
/// `timeout`. Call it on the main thread; `completion` runs on
|
|
38
|
-
/// thread.
|
|
39
|
-
func
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
/// Posts `body`, JSON-serialisable, to the Worker's `/tokamak/<name>`
|
|
36
|
+
/// endpoint and returns the response body. Fails unless the Worker responds
|
|
37
|
+
/// 200 within `timeout`. Call it on the main thread; `completion` runs on
|
|
38
|
+
/// the main thread.
|
|
39
|
+
func call(
|
|
40
|
+
_ name: String,
|
|
41
|
+
body: Any,
|
|
42
42
|
timeout: TimeInterval,
|
|
43
|
-
completion: @escaping (Result<
|
|
43
|
+
completion: @escaping (Result<Data, Error>) -> Void
|
|
44
44
|
) {
|
|
45
45
|
whenStarted { result in
|
|
46
46
|
switch result {
|
|
@@ -48,9 +48,7 @@ final class TokamakHost {
|
|
|
48
48
|
completion(.failure(error))
|
|
49
49
|
case .success(let runtime):
|
|
50
50
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
51
|
-
let outcome = Result {
|
|
52
|
-
try runtime.dispatch(event: event, payload: payload, timeout: timeout)
|
|
53
|
-
}
|
|
51
|
+
let outcome = Result { try runtime.call(name, body: body, timeout: timeout) }
|
|
54
52
|
DispatchQueue.main.async { completion(outcome) }
|
|
55
53
|
}
|
|
56
54
|
}
|
|
@@ -104,14 +102,6 @@ final class TokamakHost {
|
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
104
|
|
|
107
|
-
/// What a Worker event handler did.
|
|
108
|
-
enum TokamakEventOutcome {
|
|
109
|
-
/// The handler's result, decoded from JSON; `NSNull` when it returned nothing.
|
|
110
|
-
case handled(Any)
|
|
111
|
-
/// The Worker has no handler for the event.
|
|
112
|
-
case unhandled
|
|
113
|
-
}
|
|
114
|
-
|
|
115
105
|
/// What a plugin did with a background event, reported to the system.
|
|
116
106
|
enum TokamakBackgroundResult {
|
|
117
107
|
case newData
|
|
@@ -241,49 +231,39 @@ final class RuntimeHandle {
|
|
|
241
231
|
return port
|
|
242
232
|
}
|
|
243
233
|
|
|
244
|
-
///
|
|
245
|
-
/// `timeout` passes.
|
|
246
|
-
func
|
|
247
|
-
guard JSONSerialization.isValidJSONObject([
|
|
248
|
-
throw RuntimeError.runtime("the \(
|
|
234
|
+
/// Posts `body` to the Worker's `/tokamak/<name>` endpoint, blocking until
|
|
235
|
+
/// it responds 200 or `timeout` passes.
|
|
236
|
+
func call(_ name: String, body: Any, timeout: TimeInterval) throws -> Data {
|
|
237
|
+
guard JSONSerialization.isValidJSONObject([body]) else {
|
|
238
|
+
throw RuntimeError.runtime("the \(name) call body is not JSON")
|
|
249
239
|
}
|
|
250
|
-
let
|
|
251
|
-
decoding: try JSONSerialization.data(withJSONObject:
|
|
240
|
+
let body = String(
|
|
241
|
+
decoding: try JSONSerialization.data(withJSONObject: body, options: .fragmentsAllowed),
|
|
252
242
|
as: UTF8.self
|
|
253
243
|
)
|
|
254
|
-
var
|
|
244
|
+
var response = TokamakBytes(data: nil, len: 0)
|
|
255
245
|
var error = [CChar](repeating: 0, count: 1024)
|
|
256
|
-
let
|
|
257
|
-
|
|
246
|
+
let succeeded = name.withCString { name in
|
|
247
|
+
body.withCString { body in
|
|
258
248
|
error.withUnsafeMutableBufferPointer { error in
|
|
259
|
-
|
|
249
|
+
tokamak_runtime_call(
|
|
260
250
|
handle,
|
|
261
|
-
|
|
262
|
-
|
|
251
|
+
name,
|
|
252
|
+
body,
|
|
263
253
|
UInt64(timeout * 1000),
|
|
264
|
-
&
|
|
254
|
+
&response,
|
|
265
255
|
error.baseAddress,
|
|
266
256
|
error.count
|
|
267
257
|
)
|
|
268
258
|
}
|
|
269
259
|
}
|
|
270
260
|
}
|
|
271
|
-
defer { tokamak_bytes_free(
|
|
272
|
-
|
|
273
|
-
case Int32(TOKAMAK_DISPATCH_HANDLED):
|
|
274
|
-
guard let bytes = result.data else {
|
|
275
|
-
throw RuntimeError.runtime("the Worker event result is missing")
|
|
276
|
-
}
|
|
277
|
-
return .handled(
|
|
278
|
-
try JSONSerialization.jsonObject(
|
|
279
|
-
with: Data(bytes: bytes, count: result.len),
|
|
280
|
-
options: .fragmentsAllowed
|
|
281
|
-
))
|
|
282
|
-
case Int32(TOKAMAK_DISPATCH_UNHANDLED):
|
|
283
|
-
return .unhandled
|
|
284
|
-
default:
|
|
261
|
+
defer { tokamak_bytes_free(response) }
|
|
262
|
+
guard succeeded else {
|
|
285
263
|
throw RuntimeError.runtime(String(cString: error))
|
|
286
264
|
}
|
|
265
|
+
guard let bytes = response.data else { return Data() }
|
|
266
|
+
return Data(bytes: bytes, count: response.len)
|
|
287
267
|
}
|
|
288
268
|
|
|
289
269
|
func serverAuthority(
|