-
Notifications
You must be signed in to change notification settings - Fork 303
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
Added interface type for Cloudflare pipelines binding #2654
Conversation
@@ -11,3 +11,18 @@ export abstract class PipelineTransform { | |||
*/ | |||
public transformJson(data: object[]): Promise<object[]>; | |||
} | |||
|
|||
export type PipelineResponse = { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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?
workerd/src/workerd/api/queue.h
Lines 51 to 87 in c9eca14
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"); | |
} | |
There was a problem hiding this comment.
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.
All contributors have signed the CLA ✍️ ✅ |
d3198dd
to
7d8c7e3
Compare
7d8c7e3
to
02cc862
Compare
I have read the CLA Document and I hereby sign the CLA |
recheck |
@oliy Not sure why the CLA approval didn't work – maybe try commenting without the leading quote? |
I have read the CLA Document and I hereby sign the CLA |
recheck |
No description provided.