@reddb-io/sdk 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/url.js +21 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reddb-io/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Official embedded RedDB SDK — launches a local red binary over stdio JSON-RPC. Use @reddb-io/client for remote HTTP, gRPC, and RedWire.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"postinstall": "node postinstall.js",
|
|
48
|
-
"test": "node --test test/ask.test.mjs test/cache.test.mjs test/db-helpers.test.mjs test/embedded-only.test.mjs test/helpers.test.mjs test/insert-ids.test.mjs test/kv.test.mjs test/params.test.mjs test/postinstall.test.mjs test/queue.test.mjs test/redwire.params.test.mjs test/transaction.test.mjs && node test/smoke.test.mjs && node test/conformance.test.mjs && node test/readme-examples.test.mjs"
|
|
48
|
+
"test": "node --test test/ask.test.mjs test/cache.test.mjs test/db-helpers.test.mjs test/embedded-only.test.mjs test/helpers.test.mjs test/insert-ids.test.mjs test/kv.test.mjs test/params.test.mjs test/postinstall.test.mjs test/queue.test.mjs test/redwire.params.test.mjs test/transaction.test.mjs test/url.test.mjs && node test/smoke.test.mjs && node test/conformance.test.mjs && node test/readme-examples.test.mjs"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/url.js
CHANGED
|
@@ -153,17 +153,31 @@ export function parseLegacyUrl(uri) {
|
|
|
153
153
|
|| uri.startsWith('reds://')
|
|
154
154
|
) {
|
|
155
155
|
const scheme = uri.split('://', 1)[0]
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
let parsed
|
|
157
|
+
try {
|
|
158
|
+
// Borrow the URL parser via an `https://` authority so userinfo /
|
|
159
|
+
// host / port / query all decode with the standard rules — a naive
|
|
160
|
+
// `hostPort.split(':')` breaks on `reds://user:pass@host:5050`
|
|
161
|
+
// (host becomes `user`, port NaN).
|
|
162
|
+
parsed = new URL('https://' + uri.slice(`${scheme}://`.length))
|
|
163
|
+
} catch (err) {
|
|
164
|
+
throw new RedDBError('UNPARSEABLE_URI', `failed to parse '${uri}': ${err.message}`)
|
|
165
|
+
}
|
|
166
|
+
if (!parsed.hostname) {
|
|
160
167
|
throw new TypeError(`invalid ${scheme}:// URI: missing host in '${uri}'`)
|
|
161
168
|
}
|
|
162
|
-
const legacyKind = scheme === 'reds' ? 'reds' : scheme === 'grpcs' ? 'grpcs' :
|
|
169
|
+
const legacyKind = scheme === 'reds' ? 'reds' : scheme === 'grpcs' ? 'grpcs' : 'grpc'
|
|
170
|
+
const params = parsed.searchParams
|
|
163
171
|
return {
|
|
164
172
|
kind: legacyKind,
|
|
165
|
-
host,
|
|
166
|
-
port:
|
|
173
|
+
host: parsed.hostname,
|
|
174
|
+
port: parsed.port ? Number(parsed.port) : defaultPortFor(legacyKind),
|
|
175
|
+
username: parsed.username ? decodeURIComponent(parsed.username) : undefined,
|
|
176
|
+
password: parsed.password ? decodeURIComponent(parsed.password) : undefined,
|
|
177
|
+
token: params.get('token') ?? undefined,
|
|
178
|
+
apiKey: params.get('apiKey') ?? params.get('api_key') ?? undefined,
|
|
179
|
+
loginUrl: params.get('loginUrl') ?? params.get('login_url') ?? undefined,
|
|
180
|
+
params,
|
|
167
181
|
originalUri: uri,
|
|
168
182
|
}
|
|
169
183
|
}
|