Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Fetcher methods get(), put(), delete() with compat flag. #1770

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
15 changes: 8 additions & 7 deletions src/workerd/api/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,14 @@ class Fetcher: public JsRpcClientProvider {
JSG_METHOD(scheduled);
}

// TODO(soon): Deprecate get/put/delete convenience methods, remove via compat flag. These were
// never documented for service bindings. Extremely old KV bindings relied on them, before
// KV had its own separate API implementation -- anyone with such old KV bindings may have to
// recreate them when updating their compat flags for this removal.
JSG_METHOD(get);
JSG_METHOD(put);
JSG_METHOD_NAMED(delete, delete_);
if (!flags.getFetcherNoGetPutDelete()) {
// These helpers just map to `fetch()` with the corresponding HTTP method. They were never
// documented and probably never should have been defined. We are removing them to make room
// for RPC.
JSG_METHOD(get);
JSG_METHOD(put);
JSG_METHOD_NAMED(delete, delete_);
}

if (flags.getWorkerdExperimental()) {
JSG_WILDCARD_PROPERTY(getRpcMethod);
Expand Down
8 changes: 8 additions & 0 deletions src/workerd/api/tests/js-rpc-flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ export class DurableObjectExample {
foo() {
return 123;
}

fetch(req) {
return new Response(req.method + " " + req.url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return new Response(req.method + " " + req.url);
return new Response(`${req.method} ${req.url}`);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that's an improvement. Don't think it's worth restarting CI, though.

}
}

export default {
async test(ctrl, env, ctx) {
let id = env.ns.idFromName("foo");
let obj = env.ns.get(id);
assert.strictEqual(await obj.foo(), 123);

// Test that the object has the old helper get() method that wraps fetch(). This is deprecated,
// but enabled because this test's compat date is before the date when these went away.
assert.strictEqual(await obj.get("http://foo"), "GET http://foo");
}
}

20 changes: 20 additions & 0 deletions src/workerd/api/tests/js-rpc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ export class MyService extends WorkerEntrypoint {
result.value = callback.foo;
return result;
}

get(a) {
return a + 1;
}
put(a, b) {
return a + b;
}
delete(a) {
return a - 1;
}
}

export class MyActor extends DurableObject {
Expand Down Expand Up @@ -654,6 +664,15 @@ export let testAsyncStackTrace = {
}
}

// Test that get(), put(), and delete() are valid RPC method names, not hijacked by Fetcher.
export let canUseGetPutDelete = {
async test(controller, env, ctx) {
assert.strictEqual(await env.MyService.get(12), 13);
assert.strictEqual(await env.MyService.put(5, 7), 12);
assert.strictEqual(await env.MyService.delete(3), 2);
}
}

function withRealSocket(inner) {
return {
async test(controller, env, ctx) {
Expand All @@ -673,3 +692,4 @@ export let z_promisePipelining_realSocket = withRealSocket(promisePipelining);
export let z_crossContextSharingDoesntWork_realSocket = withRealSocket(crossContextSharingDoesntWork);
export let z_serializeRpcPromiseOrProprety_realSocket = withRealSocket(serializeRpcPromiseOrProprety);
export let z_testAsyncStackTrace_realSocket = withRealSocket(testAsyncStackTrace);
export let z_canUseGetPutDelete_realSocket = withRealSocket(canUseGetPutDelete);
2 changes: 1 addition & 1 deletion src/workerd/api/tests/js-rpc-test.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
(name = "worker", esModule = embed "js-rpc-test.js")
],
compatibilityDate = "2024-01-01",
compatibilityFlags = ["nodejs_compat","experimental"],
compatibilityFlags = ["nodejs_compat","fetcher_no_get_put_delete","experimental"],
bindings = [
(name = "self", service = (name = "js-rpc-test", entrypoint = "nonClass")),
(name = "MyService", service = (name = "js-rpc-test", entrypoint = "MyService")),
Expand Down
12 changes: 12 additions & 0 deletions src/workerd/io/compatibility-date.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,16 @@ struct CompatibilityFlags @0x8f8c1b68151b6cef {
# Python modules are restricted in EWC.
#
# WARNING: Python Workers are still an experimental feature and thus subject to change.

fetcherNoGetPutDelete @44 :Bool
$compatEnableFlag("fetcher_no_get_put_delete")
$compatDisableFlag("fetcher_has_get_put_delete")
$compatEnableDate("2024-03-26");
# Historically, the `Fetcher` type -- which is the type of Service Bindings, and also the parent
# type of Durable Object stubs -- had special methods `get()`, `put()`, and `delete()`, which
# were shortcuts for calling `fetch()` with the corresponding HTTP method. These methods were
# never documented.
#
# To make room for people to define their own RPC methods with these names, this compat flag
# makes them no longer defined.
}
Loading