Skip to content

Commit b967252

Browse files
committed
fix: enhance documentation comments
1 parent ea930ec commit b967252

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/drivers/connection-ws.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,24 @@ export class SQLiteCloudWebsocketConnection extends SQLiteCloudConnection {
143143
}
144144
}
145145

146-
/** Builds the gateway hostname from a core hostname by replacing the last two labels with
147-
* the given `gatewayurl` suffix (default `gateway.sqlite.cloud`). Returns host unchanged
148-
* when it already ends with the suffix (idempotent) or is too short to have a tenant prefix. */
146+
/** Default gateway domain suffix used when `gatewayurl` is not provided. */
147+
const DEFAULT_GATEWAY_DOMAIN = 'gateway.sqlite.cloud'
148+
149+
/** Builds the gateway hostname from a core hostname, swapping its last two labels (the
150+
* TLD) with the given `gatewayurl` suffix.
151+
*
152+
* Example: buildGatewayHost('crvheg7dhk.g4.sqlite.cloud')
153+
* → 'crvheg7dhk.g4.gateway.sqlite.cloud'
154+
*
155+
* Returns `host` unchanged when it already ends with the suffix (idempotent) or when
156+
* it's too short to extract a tenant prefix (eg 'localhost'). */
149157
function buildGatewayHost(host: string, gatewayurl?: string): string {
150158
if (!host) return host
151-
const suffix = gatewayurl || 'gateway.sqlite.cloud'
159+
const suffix = gatewayurl || DEFAULT_GATEWAY_DOMAIN
152160
if (host === suffix || host.endsWith('.' + suffix)) return host
153-
const labels = host.split('.')
154-
if (labels.length < 3) return host
155-
return labels.slice(0, -2).join('.') + '.' + suffix
161+
const parts = host.split('.')
162+
if (parts.length < 3) return host
163+
return parts.slice(0, -2).join('.') + '.' + suffix
156164
}
157165

158166
export default SQLiteCloudWebsocketConnection

src/drivers/types.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,14 @@ export interface SQLiteCloudConfig {
9292

9393
/** True if we should force use of SQLite Cloud Gateway and websocket connections, default: true in browsers, false in node.js */
9494
usewebsocket?: boolean
95-
/** Domain suffix that identifies the gateway environment. Appended to the tenant prefix
96-
* (eg `crvheg7dhk.g4`) to form the gateway hostname the driver connects to. Default:
97-
* `gateway.sqlite.cloud`. */
95+
/** Domain suffix used to build the gateway hostname the driver connects to.
96+
* Default: `gateway.sqlite.cloud`.
97+
*
98+
* Example: with `host: 'crvheg7dhk.g4.sqlite.cloud'` and the default `gatewayurl`,
99+
* the driver opens `wss://crvheg7dhk.g4.gateway.sqlite.cloud:443`. For local
100+
* development, pass a value containing `localhost` (eg `'ws://localhost:4000'`)
101+
* and the driver will route TCP to that target while forwarding `host` as the
102+
* gateway Host header. */
98103
gatewayurl?: string
99104

100105
/** Optional identifier used for verbose logging */

0 commit comments

Comments
 (0)