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

Added interface type for Cloudflare pipelines binding #2654

Merged
merged 2 commits into from
Sep 5, 2024

Conversation

hhoughgg
Copy link
Contributor

@hhoughgg hhoughgg commented Sep 4, 2024

No description provided.

@hhoughgg hhoughgg requested review from a team as code owners September 4, 2024 15:36
@@ -11,3 +11,18 @@ export abstract class PipelineTransform {
*/
public transformJson(data: object[]): Promise<object[]>;
}

export type PipelineResponse = {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for commenting on API design here given that the code is probably already written, but what is this return type communicating that wouldn't be equally-well communicated by a rejected promise / thrown Error?

In what cases will success be false? In what cases will error be filled in vs the Promise being rejected?

I'd have expected send to just return a Promise<void> unless there was something more than success/error to be returned.

Copy link
Member

Choose a reason for hiding this comment

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

For example that's what the Queues send() method returns: https://github.com/cloudflare/workerd/blob/main/src/workerd/api/queue.h#L68

* @param data The data to be send
* @returns A promise containing the outcome of the send
*/
send(data: object[]): Promise<PipelineResponse>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why an object - not every object is serializable? Does this cause issues with writing objects out to storage / consuming from a non-JS system?

How does this fit with Queues?

struct MessageSendRequest {
jsg::JsRef<jsg::JsValue> body;
// contentType determines the serialization format of the message.
jsg::Optional<kj::String> contentType;
// The number of seconds to delay the delivery of the message being sent.
jsg::Optional<int> delaySeconds;
JSG_STRUCT(body, contentType, delaySeconds);
JSG_STRUCT_TS_OVERRIDE(MessageSendRequest<Body = unknown> {
body: Body;
contentType?: QueueContentType;
});
// NOTE: Any new fields added to SendOptions must also be added here.
};
kj::Promise<void> send(jsg::Lock& js, jsg::JsValue body, jsg::Optional<SendOptions> options);
kj::Promise<void> sendBatch(jsg::Lock& js,
jsg::Sequence<MessageSendRequest> batch,
jsg::Optional<SendBatchOptions> options);
JSG_RESOURCE_TYPE(WorkerQueue) {
JSG_METHOD(send);
JSG_METHOD(sendBatch);
JSG_TS_ROOT();
JSG_TS_OVERRIDE(Queue<Body = unknown> {
send(message: Body, options?: QueueSendOptions): Promise<void>;
sendBatch(messages
: Iterable<MessageSendRequest<Body>>, options ?: QueueSendBatchOptions)
: Promise<void>;
});
JSG_TS_DEFINE(type QueueContentType = "text" | "bytes" | "json" | "v8");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will act in the same way as a queue send in that the object must be structured cloneable since this is an RPC call. The only difference is the limit is 1mb instead of 128kb. https://developers.cloudflare.com/queues/configuration/javascript-apis/#queue

I think the idea behind using an object is that we want to make sure all the data in Pipelines is a row style layout. Rows can also be represented in other languages no problem and conversions of rows/columns to other formats is a well worn path.

Copy link

github-actions bot commented Sep 4, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@oliy
Copy link
Contributor

oliy commented Sep 5, 2024

I have read the CLA Document and I hereby sign the CLA

I have read the CLA Document and I hereby sign the CLA

@oliy
Copy link
Contributor

oliy commented Sep 5, 2024

recheck

@fhanau
Copy link
Collaborator

fhanau commented Sep 5, 2024

@oliy Not sure why the CLA approval didn't work – maybe try commenting without the leading quote?

@oliy
Copy link
Contributor

oliy commented Sep 5, 2024

I have read the CLA Document and I hereby sign the CLA

@oliy
Copy link
Contributor

oliy commented Sep 5, 2024

recheck

github-actions bot added a commit that referenced this pull request Sep 5, 2024
@a-robinson a-robinson merged commit 4faf04b into cloudflare:main Sep 5, 2024
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants