-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprotocol.dart
55 lines (45 loc) · 1.56 KB
/
protocol.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/// Custom requests used by this package to manage locks in shared workers.
@JS()
library;
import 'dart:js_interop';
import 'package:sqlite3_web/protocol_utils.dart' as proto;
enum CustomDatabaseMessageKind {
requestSharedLock,
requestExclusiveLock,
releaseLock,
lockObtained,
getAutoCommit,
executeInTransaction,
executeBatchInTransaction,
}
extension type CustomDatabaseMessage._raw(JSObject _) implements JSObject {
external factory CustomDatabaseMessage._({
required JSString rawKind,
JSString rawSql,
JSArray rawParameters,
JSArrayBuffer typeInfo,
});
factory CustomDatabaseMessage(CustomDatabaseMessageKind kind,
[String? sql, List<Object?> parameters = const []]) {
final rawSql = (sql ?? '').toJS;
// Serializing parameters this way is backwards-compatible with dartify()
// on the other end, but a bit more efficient while also suppporting sound
// communcation between dart2js workers and dart2wasm clients.
// Older workers ignore the typeInfo, but that's not a problem.
final (rawParameters, typeInfo) = proto.serializeParameters(parameters);
return CustomDatabaseMessage._(
rawKind: kind.name.toJS,
rawSql: rawSql,
rawParameters: rawParameters,
typeInfo: typeInfo,
);
}
external JSString get rawKind;
external JSString get rawSql;
external JSArray get rawParameters;
/// Not set in earlier versions of this package.
external JSArrayBuffer? get typeInfo;
CustomDatabaseMessageKind get kind {
return CustomDatabaseMessageKind.values.byName(rawKind.toDart);
}
}