Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cloudflare_workers/lib/interop/cache_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
library cache;

import 'package:js/js.dart' as js;
import 'package:js_bindings/js_bindings.dart' as interop;
import 'package:typings/core.dart' as interop;

@js.JS('default')
external interop.Cache get defaultCache;
91 changes: 32 additions & 59 deletions packages/cloudflare_workers/lib/interop/durable_object_interop.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:js_util' as js_util;
import 'package:js/js.dart';
import 'package:js/js_util.dart';
import 'package:js_bindings/js_bindings.dart' as interop;
import 'package:typings/core.dart' as interop;
import 'package:edge_runtime/src/interop/promise_interop.dart';
import 'package:edge_runtime/src/interop/utils_interop.dart';

Expand Down Expand Up @@ -30,8 +30,7 @@ extension PropsDurableObject on DurableObject {
js_util.setProperty(this, 'env', env);
}

set fetch(
Promise<interop.Response> Function(interop.Request request) function) {
set fetch(Promise<interop.Response> Function(interop.Request request) function) {
js_util.setProperty(this, 'fetch', function);
}

Expand All @@ -52,47 +51,40 @@ class DurableObjectStorage {
}

extension PropsDurableObjectStorage on DurableObjectStorage {
Future<dynamic> get(/* String | List<String> */ dynamic keys,
DurableObjectGetOptions options) async {
Future<dynamic> get(
/* String | List<String> */ dynamic keys, DurableObjectGetOptions options) async {
return js_util.promiseToFuture(
js_util.callMethod(this, 'get', [keys, options]),
);
}

Future<dynamic> put(
String key, dynamic value, DurableObjectPutOptions options) {
Future<dynamic> put(String key, dynamic value, DurableObjectPutOptions options) {
var newValue = value;
if (value is Map || value is Iterable) {
newValue = jsify(value);
}
return js_util.promiseToFuture(
js_util.callMethod(this, 'put', [key, newValue, options]));
return js_util.promiseToFuture(js_util.callMethod(this, 'put', [key, newValue, options]));
}

Future<void> putEntries<T>(
Map<Object, T> entries, DurableObjectPutOptions options) =>
js_util.promiseToFuture(
js_util.callMethod(this, 'put', [jsify(entries), options]));
Future<void> putEntries<T>(Map<Object, T> entries, DurableObjectPutOptions options) =>
js_util.promiseToFuture(js_util.callMethod(this, 'put', [jsify(entries), options]));

Future<bool> delete<T>(String key, DurableObjectPutOptions options) => js_util
.promiseToFuture(js_util.callMethod(this, 'delete', [key, options]));
Future<bool> delete<T>(String key, DurableObjectPutOptions options) =>
js_util.promiseToFuture(js_util.callMethod(this, 'delete', [key, options]));

Future<void> deleteAll(DurableObjectPutOptions options) =>
js_util.promiseToFuture(js_util.callMethod(this, 'deleteAll', [options]));

Future<bool> deleteEntries<T>(Iterable<String> keys,
[DurableObjectPutOptions? options]) =>
js_util
.promiseToFuture(js_util.callMethod(this, 'delete', [keys, options]));
Future<bool> deleteEntries<T>(Iterable<String> keys, [DurableObjectPutOptions? options]) =>
js_util.promiseToFuture(js_util.callMethod(this, 'delete', [keys, options]));

Future<Map<Object, T>> list<T>([DurableObjectListOptions? options]) =>
js_util.promiseToFuture(js_util.callMethod(this, 'list', [options]));

Future<int?> getAlarm([DurableObjectGetAlarmOptions? options]) =>
js_util.promiseToFuture(js_util.callMethod(this, 'getAlarm', [options]));

Future<void> setAlarm(DateTime scheduled,
[DurableObjectSetAlarmOptions? options]) =>
Future<void> setAlarm(DateTime scheduled, [DurableObjectSetAlarmOptions? options]) =>
js_util.promiseToFuture(js_util.callMethod(this, 'setAlarm', [
scheduled.millisecondsSinceEpoch,
options,
Expand All @@ -103,11 +95,9 @@ extension PropsDurableObjectStorage on DurableObjectStorage {
options,
]));

Future<void> sync() =>
js_util.promiseToFuture(js_util.callMethod(this, 'sync', []));
Future<void> sync() => js_util.promiseToFuture(js_util.callMethod(this, 'sync', []));

Future<void> transaction(
Future<void> Function(DurableObjectTransaction tsx) callback) {
Future<void> transaction(Future<void> Function(DurableObjectTransaction tsx) callback) {
return js_util.promiseToFuture(
js_util.callMethod(this, 'transaction', [
allowInterop((tsx) async {
Expand All @@ -127,8 +117,7 @@ class DurableObjectGetOptions {

extension PropsDurableObjectGetOptions on DurableObjectGetOptions {
set allowConcurrency(bool? allowConcurrency) {
js_util.setProperty(
this, 'allowConcurrency', allowConcurrency ?? jsUndefined);
js_util.setProperty(this, 'allowConcurrency', allowConcurrency ?? jsUndefined);
}

set noCache(bool? noCache) {
Expand All @@ -145,8 +134,7 @@ class DurableObjectGetAlarmOptions {

extension PropsDurableObjectGetAlarmOptions on DurableObjectGetAlarmOptions {
set allowConcurrency(bool? allowConcurrency) {
js_util.setProperty(
this, 'allowConcurrency', allowConcurrency ?? jsUndefined);
js_util.setProperty(this, 'allowConcurrency', allowConcurrency ?? jsUndefined);
}
}

Expand All @@ -159,13 +147,11 @@ class DurableObjectSetAlarmOptions {

extension PropsDurableObjectSetAlarmOptions on DurableObjectSetAlarmOptions {
set allowConcurrency(bool? allowConcurrency) {
js_util.setProperty(
this, 'allowConcurrency', allowConcurrency ?? jsUndefined);
js_util.setProperty(this, 'allowConcurrency', allowConcurrency ?? jsUndefined);
}

set allowUnconfirmed(bool? allowUnconfirmed) {
js_util.setProperty(
this, 'allowUnconfirmed', allowUnconfirmed ?? jsUndefined);
js_util.setProperty(this, 'allowUnconfirmed', allowUnconfirmed ?? jsUndefined);
}
}

Expand All @@ -178,13 +164,11 @@ class DurableObjectPutOptions {

extension PropsDurableObjectPutOptions on DurableObjectPutOptions {
set allowConcurrency(bool? allowConcurrency) {
js_util.setProperty(
this, 'allowConcurrency', allowConcurrency ?? jsUndefined);
js_util.setProperty(this, 'allowConcurrency', allowConcurrency ?? jsUndefined);
}

set allowUnconfirmed(bool? allowUnconfirmed) {
js_util.setProperty(
this, 'allowUnconfirmed', allowUnconfirmed ?? jsUndefined);
js_util.setProperty(this, 'allowUnconfirmed', allowUnconfirmed ?? jsUndefined);
}

set noCache(bool? noCache) {
Expand Down Expand Up @@ -225,8 +209,7 @@ extension PropsDurableObjectListOptions on DurableObjectListOptions {
}

set allowConcurrency(bool? allowConcurrency) {
js_util.setProperty(
this, 'allowConcurrency', allowConcurrency ?? jsUndefined);
js_util.setProperty(this, 'allowConcurrency', allowConcurrency ?? jsUndefined);
}

set noCache(bool? noCache) {
Expand Down Expand Up @@ -262,8 +245,7 @@ extension PropsDurableObjectState on DurableObjectState {

DurableObjectStorage get storage => js_util.getProperty(this, 'storage');

void waitUntil(Future<void> f) =>
js_util.callMethod(this, 'waitUntil', [futureToPromise(f)]);
void waitUntil(Future<void> f) => js_util.callMethod(this, 'waitUntil', [futureToPromise(f)]);

Future<T> blockConcurrencyWhile<T>(Future<T> Function() callback) {
return js_util.promiseToFuture(
Expand All @@ -284,15 +266,11 @@ class DurableObjectNamespace {
}

extension PropsDurableObjectNamespace on DurableObjectNamespace {
DurableObjectId newUniqueId(
[DurableObjectNamespaceNewUniqueIdOptions? options]) =>
DurableObjectId newUniqueId([DurableObjectNamespaceNewUniqueIdOptions? options]) =>
js_util.callMethod(this, 'newUniqueId', [options]);
DurableObjectId idFromName(String name) =>
js_util.callMethod(this, 'idFromName', [name]);
DurableObjectId idFromString(String id) =>
js_util.callMethod(this, 'idFromString', [id]);
DurableObjectStub get(DurableObjectId id) =>
js_util.callMethod(this, 'get', [id]);
DurableObjectId idFromName(String name) => js_util.callMethod(this, 'idFromName', [name]);
DurableObjectId idFromString(String id) => js_util.callMethod(this, 'idFromString', [id]);
DurableObjectStub get(DurableObjectId id) => js_util.callMethod(this, 'get', [id]);
}

@anonymous
Expand All @@ -304,8 +282,7 @@ class DurableObjectId {

extension PropsDurableObjectId on DurableObjectId {
String get name => js_util.getProperty(this, 'name');
bool equals(DurableObjectId other) =>
js_util.callMethod(this, 'equals', [other]);
bool equals(DurableObjectId other) => js_util.callMethod(this, 'equals', [other]);
String mToString() => js_util.callMethod(this, 'toString', []);
}

Expand All @@ -318,10 +295,8 @@ class Fetcher {

extension PropsFetcher on Fetcher {
// TODO RequestInit<RequestInitCfProperties>
Future<interop.Response> fetch(interop.Request resource,
[interop.RequestInit? init]) =>
js_util
.promiseToFuture(js_util.callMethod(this, 'fetch', [resource, init]));
Future<interop.Response> fetch(interop.Request resource, [interop.RequestInit? init]) =>
js_util.promiseToFuture(js_util.callMethod(this, 'fetch', [resource, init]));

Socket connect(String address, [SocketOptions? options]) =>
js_util.callMethod(this, 'connect', [address, options]);
Expand All @@ -335,10 +310,8 @@ class Socket {
}

extension PropsSocket on Socket {
Future<interop.ReadableStream> get readable =>
js_util.getProperty(this, 'readable');
Future<interop.ReadableStream> get writable =>
js_util.getProperty(this, 'writable');
Future<interop.ReadableStream> get readable => js_util.getProperty(this, 'readable');
Future<interop.ReadableStream> get writable => js_util.getProperty(this, 'writable');
Future<bool> get closed => js_util.getProperty(this, 'closed');
Future<void> close() => js_util.callMethod(this, 'close', []);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:js_util' as js_util;
import 'package:js/js.dart';

import 'package:js_bindings/js_bindings.dart' as interop;
import 'package:typings/core.dart' as interop;

@anonymous
@JS()
Expand All @@ -17,8 +17,7 @@ extension PropsEmailMessage on EmailMessage {
interop.ReadableStream get raw => js_util.getProperty(this, 'raw');
int get rawSize => js_util.getProperty(this, 'rawSize');

void setReject(String reason) =>
js_util.callMethod(this, 'setReject', [reason]);
Future<void> forward(String to, [interop.Headers? headers]) => js_util
.promiseToFuture(js_util.callMethod(this, 'forward', [to, headers]));
void setReject(String reason) => js_util.callMethod(this, 'setReject', [reason]);
Future<void> forward(String to, [interop.Headers? headers]) =>
js_util.promiseToFuture(js_util.callMethod(this, 'forward', [to, headers]));
}
17 changes: 6 additions & 11 deletions packages/cloudflare_workers/lib/interop/html_rewriter_interop.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:js_util' as js_util;
import 'package:js/js.dart';
import 'package:js_bindings/js_bindings.dart' as interop;
import 'package:typings/core.dart' as interop;
import 'package:edge_runtime/src/interop/promise_interop.dart';

typedef HandlerMethod<T> = Promise<void> Function(T type);
Expand Down Expand Up @@ -152,17 +152,14 @@ extension PropsElement on Element {
bool get removed => js_util.getProperty(this, 'removed');
String get namespaceURI => js_util.getProperty(this, 'namespaceURI');

String? getAttribute(String name) =>
js_util.callMethod(this, 'getAttribute', [name]);
String? getAttribute(String name) => js_util.callMethod(this, 'getAttribute', [name]);

bool hasAttribute(String name) =>
js_util.callMethod(this, 'hasAttribute', [name]);
bool hasAttribute(String name) => js_util.callMethod(this, 'hasAttribute', [name]);

Element setAttribute(String name, String value) =>
js_util.callMethod(this, 'setAttribute', [name, value]);

Element removeAttribute(String name) =>
js_util.callMethod(this, 'removeAttribute', [name]);
Element removeAttribute(String name) => js_util.callMethod(this, 'removeAttribute', [name]);

Element before(String text, [ContentOptions? options]) =>
js_util.callMethod(this, 'before', [text, options]);
Expand All @@ -181,14 +178,12 @@ extension PropsElement on Element {

Element remove() => js_util.callMethod(this, 'remove', []);

Element removeAndKeepContent() =>
js_util.callMethod(this, 'removeAndKeepContent', []);
Element removeAndKeepContent() => js_util.callMethod(this, 'removeAndKeepContent', []);

Element setInnerContent(String text, [ContentOptions? options]) =>
js_util.callMethod(this, 'setInnerContent', [text, options]);

void onEndTag(dynamic handler) =>
js_util.callMethod(this, 'onEndTag', [handler]);
void onEndTag(dynamic handler) => js_util.callMethod(this, 'onEndTag', [handler]);
}

@anonymous
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:js_util' as js_util;
import 'package:js/js.dart';
import 'package:js_bindings/js_bindings.dart' as interop;
import 'package:typings/core.dart' as interop;
import 'package:edge_runtime/src/interop/utils_interop.dart';

extension CloudflareWorkersRequestInteropExtension on interop.RequestInit {
Expand Down Expand Up @@ -45,11 +45,11 @@ extension PropsCloudflareRequestInit on CloudflareRequestInit {
js_util.setProperty(this, 'apps', value ?? jsUndefined);
}

set image(dynamic? value) {
set image(dynamic value) {
js_util.setProperty(this, 'image', value ?? jsUndefined);
}

set minify(dynamic? value) {
set minify(dynamic value) {
js_util.setProperty(this, 'minify', value ?? jsUndefined);
}

Expand All @@ -73,8 +73,7 @@ class RequestInitCfPropertiesImageMinify {
external factory RequestInitCfPropertiesImageMinify();
}

extension PropsRequestInitCfPropertiesImageMinify
on RequestInitCfPropertiesImageMinify {
extension PropsRequestInitCfPropertiesImageMinify on RequestInitCfPropertiesImageMinify {
set javascript(bool? value) {
js_util.setProperty(this, 'javascript', value ?? jsUndefined);
}
Expand Down Expand Up @@ -130,8 +129,7 @@ class RequestInitCfPropertiesImageDraw extends BasicImageTransformations {
});
}

extension PropsRequestInitCfPropertiesImageDraw
on RequestInitCfPropertiesImageDraw {
extension PropsRequestInitCfPropertiesImageDraw on RequestInitCfPropertiesImageDraw {
set opacity(num? value) {
js_util.setProperty(this, 'opacity', value ?? jsUndefined);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:js_util' as js_util;
import 'package:js/js.dart';
import 'package:js_bindings/js_bindings.dart' as interop;
import 'package:typings/core.dart' as interop;

extension CloudflareWorkersRequestInteropExtension on interop.Request {
IncomingRequestCfProperties get cf => js_util.getProperty(this, 'cf');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import 'dart:js_util' as js_util;
import 'package:edge_runtime/edge_runtime.dart';
import 'package:js/js.dart';
import 'package:edge_runtime/src/interop/promise_interop.dart';
import 'package:edge_runtime/src/request.dart';
import 'package:edge_runtime/src/response.dart';
import 'package:edge_runtime/src/request.dart';

import 'package:js_bindings/js_bindings.dart' as interop;
import 'package:typings/core.dart' as interop;
import '../interop/environment_interop.dart' as interop;
import '../interop/scheduled_event_interop.dart' as interop;
import '../interop/email_message_interop.dart' as interop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import 'durable_object_state.dart';
abstract class DurableObject {
final interop.DurableObject _delegate;

DurableObjectState get state =>
durableObjectStateFromJsObject(_delegate.state);
DurableObjectState get state => durableObjectStateFromJsObject(_delegate.state);

Environment get env => environmentFromJsObject(_delegate.env);

Expand Down
Loading