Skip to content

Commit

Permalink
chore(adapter-http) remove custom URL parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Jan 7, 2025
1 parent bbff7f9 commit 3cdc1dc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 51 deletions.
29 changes: 17 additions & 12 deletions packages/node_modules/pouchdb-adapter-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
adapterFun as coreAdapterFun,
explainError,
clone,
parseUri,
bulkGetShim,
nextTick
} from 'pouchdb-utils';
Expand Down Expand Up @@ -79,8 +78,8 @@ function hasUrlPrefix(opts) {
if (!opts.prefix) {
return false;
}
const protocol = parseUri(opts.prefix).protocol;
return protocol === 'http' || protocol === 'https';
const protocol = new URL(opts.prefix).protocol;
return protocol === 'http:' || protocol === 'https:';
}

// Get all the information you possibly can about the URI given by name and
Expand All @@ -94,24 +93,30 @@ function getHost(name, opts) {
name = prefix + encodeURIComponent(dbName);
}

const uri = parseUri(name);
if (uri.user || uri.password) {
uri.auth = {username: uri.user, password: uri.password};
const url = new URL(name);
const uri = {
protocol: url.protocol.replace(/:$/, ''),
host: url.hostname,
port: url.port,
};

if (url.user || url.password) {
host.auth = {username: url.username, password: url.password};

Check failure on line 104 in packages/node_modules/pouchdb-adapter-http/src/index.js

View workflow job for this annotation

GitHub Actions / lint

'host' is not defined
}

// Split the path part of the URI into parts using '/' as the delimiter
// after removing any leading '/' and any trailing '/'
const parts = uri.path.replace(/(^\/|\/$)/g, '').split('/');
const parts = url.pathname.replace(/(^\/|\/$)/g, '').split('/');

uri.db = parts.pop();
host.db = parts.pop();

Check failure on line 111 in packages/node_modules/pouchdb-adapter-http/src/index.js

View workflow job for this annotation

GitHub Actions / lint

'host' is not defined
// Prevent double encoding of URI component
if (uri.db.indexOf('%') === -1) {
uri.db = encodeURIComponent(uri.db);
if (host.db.indexOf('%') === -1) {

Check failure on line 113 in packages/node_modules/pouchdb-adapter-http/src/index.js

View workflow job for this annotation

GitHub Actions / lint

'host' is not defined
host.db = encodeURIComponent(uri.db);

Check failure on line 114 in packages/node_modules/pouchdb-adapter-http/src/index.js

View workflow job for this annotation

GitHub Actions / lint

'host' is not defined
}

uri.path = parts.join('/');
host.path = parts.join('/');

Check failure on line 117 in packages/node_modules/pouchdb-adapter-http/src/index.js

View workflow job for this annotation

GitHub Actions / lint

'host' is not defined

return uri;
return host;

Check failure on line 119 in packages/node_modules/pouchdb-adapter-http/src/index.js

View workflow job for this annotation

GitHub Actions / lint

'host' is not defined
}

// Generate a URL with the host data given by opts and the given path
Expand Down
2 changes: 0 additions & 2 deletions packages/node_modules/pouchdb-for-coverage/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import {
parseUri,
uuid,
rev,
clone,
Expand Down Expand Up @@ -49,7 +48,6 @@ import checkpointer from 'pouchdb-checkpointer';

export default {
blob,
parseUri,
uuid,
rev,
atob,
Expand Down
2 changes: 0 additions & 2 deletions packages/node_modules/pouchdb-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import nextTick from './nextTick';
import normalizeDdocFunctionName from './normalizeDdocFunctionName';
import once from './once';
import parseDdocFunctionName from './parseDdocFunctionName';
import parseUri from './parseUri';
import pick from './pick';
import scopeEval from './scopeEval';
import toPromise from './toPromise';
Expand All @@ -44,7 +43,6 @@ export {
normalizeDdocFunctionName,
once,
parseDdocFunctionName,
parseUri,
pick,
rev,
scopeEval,
Expand Down
35 changes: 0 additions & 35 deletions packages/node_modules/pouchdb-utils/src/parseUri.js

This file was deleted.

0 comments on commit 3cdc1dc

Please sign in to comment.