@embracesql/client
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "@embracesql/client", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Connects to EmbraceSQL over HTTP/S from browser and node.", | ||
@@ -13,5 +13,5 @@ "type": "module", | ||
"dependencies": { | ||
"@embracesql/shared": "^0.1.2" | ||
"@embracesql/shared": "^0.1.3" | ||
}, | ||
"gitHead": "8f9395afff4f331cde0761a283fea630c2d43a4f" | ||
"gitHead": "edeebbd5811d60be38bba6c04df81b7013349f1a" | ||
} |
import { | ||
EmbraceSQLRequest, | ||
EmbraceSQLResponse, | ||
HasHeaders, | ||
InvokeQueryOptions, | ||
sleep, | ||
} from "@embracesql/shared"; | ||
@@ -48,3 +48,3 @@ | ||
Response, | ||
Options extends HasHeaders = HasHeaders, | ||
Options extends InvokeQueryOptions = InvokeQueryOptions, | ||
>( | ||
@@ -67,25 +67,42 @@ request: EmbraceSQLRequest<Parameters, Values, Options>, | ||
}; | ||
const response = await fetch(this.props.url, { | ||
...props, | ||
method: "POST", | ||
cache: "no-cache", | ||
redirect: "follow", | ||
body: JSON.stringify({ | ||
...request, | ||
options: { | ||
// combine client and request options | ||
...(this.props.options ?? {}), | ||
// with request options taking preference | ||
...(request.options ?? {}), | ||
}, | ||
}), | ||
}); | ||
// it'll be JSON back or an exception | ||
return (await response.json()) as unknown as EmbraceSQLResponse< | ||
Response, | ||
Parameters, | ||
Values, | ||
Options | ||
>; | ||
let finalError: Error | undefined = undefined; | ||
for (let retry = 0; retry <= (request?.options?.retries ?? 0); retry += 1) { | ||
try { | ||
// actual trip to the network happens here | ||
const response = await fetch(this.props.url, { | ||
...props, | ||
method: "POST", | ||
cache: "no-cache", | ||
redirect: "follow", | ||
body: JSON.stringify({ | ||
...request, | ||
options: { | ||
// combine client and request options | ||
...(this.props.options ?? {}), | ||
// with request options taking preference | ||
...(request.options ?? {}), | ||
}, | ||
}), | ||
}); | ||
// it'll be JSON back or an exception | ||
return (await response.json()) as unknown as EmbraceSQLResponse< | ||
Response, | ||
Parameters, | ||
Values, | ||
Options | ||
>; | ||
} catch (e) { | ||
finalError = e as Error; | ||
// this is the exponential backoff part | ||
if (retry > 0) { | ||
await sleep(100 * 2 ** retry); | ||
} | ||
} | ||
} | ||
// if we got here, we're past all the retries and it is time to throw | ||
throw finalError; | ||
} | ||
@@ -92,0 +109,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13505
371
Updated@embracesql/shared@^0.1.3