-
Notifications
You must be signed in to change notification settings - Fork 37
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
RFE: Make pusher/puller interface lower level #575
Comments
Needs some API design. Pull: We currently have: function callPuller(
puller: Puller,
url: string,
body: PullRequest,
auth: string,
requestID: string,
): Promise<PullerResult>;
type PullerResult = {
response?: PullResponse;
httpRequestInfo: HTTPRequestInfo;
};
type HTTPRequestInfo = {
httpStatusCode: number;
errorMessage: string;
};
export type Puller = (request: Request) => Promise<PullerResult>;
export type PullRequest = {
clientID: string;
cookie: ReadonlyJSONValue;
lastMutationID: number;
pullVersion: number;
// schema_version can optionally be used by the customer's app
// to indicate to the data layer what format of Client View the
// app understands.
schemaVersion: string;
}; push: We currently have: function callPusher(
pusher: Pusher,
url: string,
body: PushRequest,
auth: string,
requestID: string,
): Promise<HTTPRequestInfo>;
type Pusher = (request: Request) => Promise<HTTPRequestInfo>;
type PushRequest = {
clientID: string;
mutations: Mutation[];
pushVersion: number;
schemaVersion: string;
}; Strawman: Use We need a new name for these options though... |
I think that we should not pass |
Also no reason to pass URL or to need a result from pull. So I would suggest:
|
looks good! some reactions
type PullResult =
| { result: 'ok', response: PullResponse }
| { result: 'error', errorMessage: string }; In current form, what happens if status code is 200 but you have an error code or are missing a response? Or if status code is 500 but you have a response? |
Sure. Fair point!
The current internal API is somewhat crufty and out of date. The At a basic level, Replicache does not care at all what the response to Similarly Replicache does not care what the response to The only way errors or other responses matter in these two requests is for developer debugging. Since the contents of HTTP responses are displayed in the network pane and errors are color-coded, we encourage developers to use 4xx, 5xx appropriately and return useful error responses. But that's entirely for their own benefit, it doesn't matter to Replicache. |
This is hard to do as a non-breaking change for a patch release because there's a lot of cruft in the existing push/pull support, but here's my proposal for doing this as a breaking change (maybe for 9.0). Big picture:
Do the above as a breaking change (e.g., for 9.0) so that we don't have to maintain all the old code paths. They have gotten pretty intricate and it would be a lot of work to maintain them. type ReplicacheOptions = {
...
push?: Push;
pull?: Pull;
...
};
/**
* Implements the push operation for Replicache sync.
*
* In case of error, either return false or throw. Thrown errors
* will be re-thrown and bubble up to top of JS context. In either
* case, Replicache will exponentially backoff using the parameters
* from ReplicacheOptions.requestOptions.
*/
type Push = (req: PushRequest) => Promise<boolean>;
/**
* Implements the pull operation for Replicache sync.
*
* In case of error, either return null or throw. Thrown errors
* will be re-thrown and bubble up to top of JS context. In either
* case, Replicache will exponentially backoff using the parameters
* from ReplicacheOptions.requestOptions.
*/
type Pull = (req: PullRequest) => Promise<PullResponse|null>;
type PushRequest = TodaysPushRequest & { requestID: string; };
type PullRequest = TodaysPullRequest & { requestID: string; }; So to transition after this change, a user who uses pushURL today would do:
... similar changes for users who use pullURL/pusher/puller. |
Looks good to me but I think we should maybe have some default implementations; |
@arv bumping this it comes up all the time. So annoying. |
On second thought we should probably wait until we integrate Reflect as that's going to affect this interface most likely. |
That makes sense. Let's hold off on this until then. |
This was implemented in Replicache 13. |
See discussion: https://discord.com/channels/830183651022471199/830183651022471202/879401020923478016
The text was updated successfully, but these errors were encountered: