Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@datastax/astra-db-ts

Package Overview
Dependencies
Maintainers
6
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datastax/astra-db-ts - npm Package Compare versions

Comparing version 1.2.1-0 to 1.2.1-1

45

dist/api/fetch/fetch-h2.js

@@ -18,3 +18,3 @@ "use strict";

exports.FetchH2 = void 0;
const fetch_h2_1 = require("fetch-h2");
const errors_1 = require("../../client/errors");
class FetchH2 {

@@ -34,18 +34,29 @@ constructor(options, preferHttp2) {

});
// Sanity check, and shuts up the type checker; should actually never happen
if (options?.httpOptions?.client !== undefined && options?.httpOptions?.client !== 'default') {
throw new Error('FetchH2 client tried to initialize using options for a different client type.');
Object.defineProperty(this, "_timeoutErrorCls", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
try {
// Complicated expression to stop Next.js and such from tracing require and trying to load the fetch-h2 client
const [indirectRequire] = [require].map(x => Math.random() > 10 ? null : x);
const fetchH2 = (options?.fetchH2 ?? indirectRequire('fetch-h2'));
this._http1 = fetchH2.context({
http1: {
keepAlive: options?.http1?.keepAlive,
keepAliveMsecs: options?.http1?.keepAliveMS,
maxSockets: options?.http1?.maxSockets,
maxFreeSockets: options?.http1?.maxFreeSockets,
},
httpsProtocols: ['http1'],
});
this._preferred = (preferHttp2)
? fetchH2.context()
: this._http1;
this._timeoutErrorCls = fetchH2.TimeoutError;
}
this._http1 = (0, fetch_h2_1.context)({
http1: {
keepAlive: options?.httpOptions?.http1?.keepAlive,
keepAliveMsecs: options?.httpOptions?.http1?.keepAliveMS,
maxSockets: options?.httpOptions?.http1?.maxSockets,
maxFreeSockets: options?.httpOptions?.http1?.maxFreeSockets,
},
httpsProtocols: ['http1'],
});
this._preferred = (preferHttp2)
? (0, fetch_h2_1.context)()
: this._http1;
catch (e) {
throw new errors_1.FailedToLoadDefaultClientError(e);
}
}

@@ -68,3 +79,3 @@ async fetch(info) {

catch (e) {
if (e instanceof fetch_h2_1.TimeoutError) {
if (e instanceof this._timeoutErrorCls) {
throw info.mkTimeoutError();

@@ -71,0 +82,0 @@ }

@@ -33,4 +33,9 @@ "use strict";

__exportStar(require("./clients/devops-api-http-client"), exports);
__exportStar(require("./clients/types"), exports);
__exportStar(require("./fetch/fetch-h2"), exports);
__exportStar(require("./fetch/fetch-native"), exports);
__exportStar(require("./fetch/types"), exports);
__exportStar(require("./timeout-managers"), exports);
__exportStar(require("./constants"), exports);
__exportStar(require("./types"), exports);
__exportStar(require("./constants"), exports);
//# sourceMappingURL=index.js.map

@@ -36,3 +36,2 @@ "use strict";

const version_1 = require("../version");
const errors_1 = require("../client/errors");
/**

@@ -233,9 +232,6 @@ * The base class for the {@link DataAPIClient} event emitter to make it properly typed.

try {
// Complicated expression to stop Next.js and such from tracing require and trying to load the fetch-h2 client
const [indirectRequire] = [require].map(x => Math.random() > 10 ? null : x);
const { FetchH2 } = indirectRequire('../api/fetch/fetch-h2');
const preferHttp2 = options?.httpOptions?.preferHttp2
?? getDeprecatedPrefersHttp2(options)
?? true;
return new FetchH2(options, preferHttp2);
return new api_1.FetchH2(options?.httpOptions, preferHttp2);
}

@@ -247,3 +243,3 @@ catch (e) {

else {
throw new errors_1.FailedToLoadDefaultClientError(e);
throw e;
}

@@ -250,0 +246,0 @@ }

@@ -5,3 +5,3 @@ "use strict";

exports.LIB_NAME = 'astra-db-ts';
exports.LIB_VERSION = "1.2.1-0";
exports.LIB_VERSION = "1.2.1-1";
//# sourceMappingURL=version.js.map
{
"name": "@datastax/astra-db-ts",
"version": "1.2.1-0",
"version": "1.2.1-1",
"description": "Astra DB TS Client",

@@ -5,0 +5,0 @@ "contributors": [

@@ -15,2 +15,3 @@ # @datastax/astra-db-ts

- [Non-standard runtime support](#non-standard-runtime-support)
- [HTTP/2 with minification](#http2-with-minification)

@@ -362,1 +363,28 @@ ## Quickstart

Check out the `examples/` subdirectory for some non-standard runtime examples with more info.
## HTTP/2 with minification
Due to the variety of different runtimes JS can run in, `astra-db-ts` does its best to be as flexible as possible.
Unfortunately however, because we need to dynamically require the `fetch-h2` module to test whether it works, the
dynamic import often breaks in minified environments, even if the runtime properly supports HTTP/2.
There is a simple workaround however, consisting of the following steps, if you truly want to use HTTP/2:
1. Install `fetch-h2` as a dependency (`npm i fetch-h2`)
2. Import the `fetch-h2` module in your code as `fetchH2` (e.g. `import * as fetchH2 from 'fetch-h2'`)
3. Set the `httpOptions.fetchH2` option to the imported module when instantiating the client
```typescript
import { DataAPIClient } from '@datastax/astra-db-ts';
import * as fetchH2 from 'fetch-h2';
const client = new DataAPIClient('*TOKEN*', {
httpOptions: { fetchH2 },
});
```
This way, the dynamic import is avoided, and the client will work in minified environments.
Note this is not required if you don't explicitly need HTTP/2 support, as the client will default
to the native fetch implementation instead if importing fails.
(But keep in mind this defaulting will only happen if `httpOptions` is not set at all).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc