@oada/client
Advanced tools
Comparing version 3.1.5 to 3.2.0
@@ -19,6 +19,4 @@ /** | ||
import { WebSocketClient } from './websocket'; | ||
export declare function parseDomain(domain: string): { | ||
export declare function parseDomain(domain: string): URL & { | ||
port: number; | ||
hostname: string; | ||
protocol: string; | ||
protocols: string[]; | ||
@@ -33,2 +31,2 @@ }; | ||
concurrency?: number; | ||
}): Promise<WebSocketClient | HttpClient>; | ||
}): Promise<HttpClient | WebSocketClient>; |
@@ -27,27 +27,21 @@ "use strict"; | ||
function tryDomain(domain) { | ||
const { port, hostname, protocol } = new URL(domain); | ||
switch (protocol) { | ||
const url = new URL(domain); | ||
switch (url.protocol) { | ||
case 'http2:': | ||
return { | ||
port: Number(port) || 80, | ||
hostname, | ||
protocol, | ||
return Object.assign(url, { | ||
port: Number(url.port) || 80, | ||
protocols: ['h2'], | ||
}; | ||
}); | ||
case 'https:': | ||
return { | ||
port: Number(port) || 443, | ||
hostname, | ||
protocol, | ||
return Object.assign(url, { | ||
port: Number(url.port) || 443, | ||
protocols: ['h2', 'http/1.1', 'http/1.0'], | ||
}; | ||
}); | ||
case 'http:': | ||
return { | ||
port: Number(port) || 80, | ||
hostname, | ||
protocol, | ||
return Object.assign(url, { | ||
port: Number(url.port) || 80, | ||
protocols: ['http/1.1', 'http/1.0'], | ||
}; | ||
}); | ||
default: | ||
throw new Error(`Unsupported domain protocol: ${protocol}`); | ||
throw new Error(`Unsupported domain protocol: ${url.protocol}`); | ||
} | ||
@@ -54,0 +48,0 @@ } |
@@ -28,3 +28,3 @@ "use strict"; | ||
const core_1 = require("file-type/core"); | ||
const ksuid_1 = tslib_1.__importDefault(require("ksuid")); | ||
const xksuid_1 = require("xksuid"); | ||
const utils_1 = require("./utils"); | ||
@@ -379,3 +379,3 @@ const http_1 = require("./http"); | ||
// but it's much easier to just make a ksuid and do the tree put | ||
const { string: newkey } = await ksuid_1.default.random(); | ||
const newkey = (0, xksuid_1.generate)(); | ||
return this.put({ ...request, path: (0, node_path_1.join)(path, newkey) }); | ||
@@ -663,3 +663,3 @@ } | ||
// Create unique resource ID | ||
const { string: id } = await ksuid_1.default.random(); | ||
const id = (0, xksuid_1.generate)(); | ||
const resourceId = `resources/${id}`; | ||
@@ -666,0 +666,0 @@ // Append resource ID and content type to object |
@@ -27,4 +27,4 @@ "use strict"; | ||
const debug_1 = tslib_1.__importDefault(require("debug")); | ||
const ksuid_1 = tslib_1.__importDefault(require("ksuid")); | ||
const type_is_1 = tslib_1.__importDefault(require("type-is")); | ||
const media_type_1 = require("media-type"); | ||
const xksuid_1 = require("xksuid"); | ||
const request_1 = require("@oada/types/oada/websockets/request"); | ||
@@ -40,4 +40,8 @@ const utils_1 = require("./utils"); | ||
} | ||
function isJson(contentType) { | ||
const media = (0, media_type_1.fromString)(contentType); | ||
return [media.subtype, media.suffix].includes('json'); | ||
} | ||
async function getBody(result) { | ||
return type_is_1.default.is(result.headers.get('content-type'), ['json', '+json']) | ||
return isJson(result.headers.get('content-type')) | ||
? (await result.json()) | ||
@@ -132,3 +136,3 @@ : buffer_1.Buffer.from(await result.arrayBuffer()); | ||
if (!request.requestId) { | ||
request.requestId = ksuid_1.default.randomSync().string; | ||
request.requestId = (0, xksuid_1.generate)(); | ||
} | ||
@@ -135,0 +139,0 @@ trace('Adding http request w/ id %s to the queue', request.requestId); |
@@ -22,3 +22,2 @@ "use strict"; | ||
/// <reference path="types.d.ts" /> | ||
const url_1 = require("url"); | ||
const client_1 = require("./client"); | ||
@@ -32,4 +31,4 @@ const auto_1 = require("./auto"); | ||
function normalizeDomain(domain) { | ||
const { hostname, protocol, port } = (0, auto_1.parseDomain)(domain); | ||
return (0, url_1.format)({ hostname, protocol, port }); | ||
const url = (0, auto_1.parseDomain)(domain); | ||
return url.toString(); | ||
} | ||
@@ -36,0 +35,0 @@ exports.normalizeDomain = normalizeDomain; |
@@ -27,3 +27,3 @@ "use strict"; | ||
const debug_1 = tslib_1.__importDefault(require("debug")); | ||
const ksuid_1 = tslib_1.__importDefault(require("ksuid")); | ||
const xksuid_1 = require("xksuid"); | ||
const isomorphic_timers_promises_1 = require("isomorphic-timers-promises"); | ||
@@ -127,4 +127,3 @@ const request_1 = require("@oada/types/oada/websockets/request"); | ||
// Send object to the server. | ||
// eslint-disable-next-line unicorn/no-await-expression-member | ||
const requestId = request.requestId ?? (await ksuid_1.default.random()).string; | ||
const requestId = request.requestId ?? (0, xksuid_1.generate)(); | ||
request.requestId = requestId; | ||
@@ -131,0 +130,0 @@ (0, request_1.assert)(request); |
@@ -26,36 +26,25 @@ /** | ||
function tryDomain(domain: string): { | ||
port: number; | ||
hostname: string; | ||
protocol: string; | ||
protocols: string[]; | ||
} { | ||
const { port, hostname, protocol } = new URL(domain); | ||
switch (protocol) { | ||
function tryDomain(domain: string) { | ||
const url = new URL(domain); | ||
switch (url.protocol) { | ||
case 'http2:': | ||
return { | ||
port: Number(port) || 80, | ||
hostname, | ||
protocol, | ||
return Object.assign(url, { | ||
port: Number(url.port) || 80, | ||
protocols: ['h2'], | ||
}; | ||
}); | ||
case 'https:': | ||
return { | ||
port: Number(port) || 443, | ||
hostname, | ||
protocol, | ||
return Object.assign(url, { | ||
port: Number(url.port) || 443, | ||
protocols: ['h2', 'http/1.1', 'http/1.0'], | ||
}; | ||
}); | ||
case 'http:': | ||
return { | ||
port: Number(port) || 80, | ||
hostname, | ||
protocol, | ||
return Object.assign(url, { | ||
port: Number(url.port) || 80, | ||
protocols: ['http/1.1', 'http/1.0'], | ||
}; | ||
}); | ||
default: | ||
throw new Error(`Unsupported domain protocol: ${protocol}`); | ||
throw new Error(`Unsupported domain protocol: ${url.protocol}`); | ||
} | ||
@@ -62,0 +51,0 @@ } |
@@ -26,3 +26,3 @@ /** | ||
import { fromBuffer } from 'file-type/core'; | ||
import ksuid from 'ksuid'; | ||
import { generate as ksuid } from 'xksuid'; | ||
@@ -795,3 +795,3 @@ import { | ||
// Retry on certain errors | ||
const CODES = new Set(<const>['412', '422']); | ||
const CODES = new Set(['412', '422'] as const); | ||
const MAX_RETRIES = 5; | ||
@@ -869,3 +869,3 @@ | ||
// but it's much easier to just make a ksuid and do the tree put | ||
const { string: newkey } = await ksuid.random(); | ||
const newkey = ksuid(); | ||
return this.put({ ...request, path: join(path, newkey) }); | ||
@@ -1040,3 +1040,3 @@ } | ||
// Create unique resource ID | ||
const { string: id } = await ksuid.random(); | ||
const id = ksuid(); | ||
const resourceId = `resources/${id}`; | ||
@@ -1043,0 +1043,0 @@ // Append resource ID and content type to object |
@@ -25,4 +25,4 @@ /** | ||
import debug from 'debug'; | ||
import ksuid from 'ksuid'; | ||
import typeIs from 'type-is'; | ||
import { fromString } from 'media-type'; | ||
import { generate as ksuid } from 'xksuid'; | ||
@@ -56,4 +56,9 @@ import { assert as assertOADASocketRequest } from '@oada/types/oada/websockets/request'; | ||
function isJson(contentType: string) { | ||
const media = fromString(contentType); | ||
return [media.subtype, media.suffix].includes('json'); | ||
} | ||
async function getBody(result: Response): Promise<Body> { | ||
return typeIs.is(result.headers.get('content-type')!, ['json', '+json']) | ||
return isJson(result.headers.get('content-type')!) | ||
? ((await result.json()) as Json) | ||
@@ -168,3 +173,3 @@ : Buffer.from(await result.arrayBuffer()); | ||
if (!request.requestId) { | ||
request.requestId = ksuid.randomSync().string; | ||
request.requestId = ksuid(); | ||
} | ||
@@ -171,0 +176,0 @@ |
@@ -21,4 +21,2 @@ /** | ||
import { format } from 'url'; | ||
import { Config, OADAClient } from './client'; | ||
@@ -33,4 +31,4 @@ import { autoConnection, parseDomain } from './auto'; | ||
export function normalizeDomain(domain: string) { | ||
const { hostname, protocol, port } = parseDomain(domain); | ||
return format({ hostname, protocol, port }); | ||
const url = parseDomain(domain); | ||
return url.toString(); | ||
} | ||
@@ -37,0 +35,0 @@ |
@@ -34,1 +34,22 @@ /** | ||
} | ||
/** | ||
* Generates new (x)KSUID based on current timestamp | ||
* @param {boolean} desc | ||
* @param {number} timestamp ms | ||
* @returns {string} 27 chars KSUID or 28 chars for xKSUID | ||
*/ | ||
declare module 'xksuid' { | ||
export function generate(desc = false, timestamp = Date.now()): string; | ||
} | ||
declare module 'media-type' { | ||
export interface MediaType { | ||
type: string; | ||
subtype: string; | ||
suffix: string; | ||
hasSuffix(): boolean; | ||
asString(): string; | ||
} | ||
export function fromString(contentType: string): MediaType; | ||
} |
@@ -23,3 +23,3 @@ /** | ||
import debug from 'debug'; | ||
import ksuid from 'ksuid'; | ||
import { generate as ksuid } from 'xksuid'; | ||
import { setTimeout } from 'isomorphic-timers-promises'; | ||
@@ -191,4 +191,3 @@ | ||
// Send object to the server. | ||
// eslint-disable-next-line unicorn/no-await-expression-member | ||
const requestId = request.requestId ?? (await ksuid.random()).string; | ||
const requestId = request.requestId ?? ksuid(); | ||
request.requestId = requestId; | ||
@@ -195,0 +194,0 @@ assertOADASocketRequest(request); |
{ | ||
"name": "@oada/client", | ||
"version": "3.1.5", | ||
"version": "3.2.0", | ||
"description": "A lightweight client tool to interact with an OADA-compliant server", | ||
@@ -11,18 +11,16 @@ "repository": "https://github.com/OADA/client", | ||
"browser": { | ||
"./dist/event-iterator": "./dist/event-iterator-browser", | ||
"./dist/fetch": "cross-fetch", | ||
"buffer": "buffer/", | ||
"./dist/event-iterator.js": "./dist/event-iterator-browser.js", | ||
"./dist/fetch.js": "cross-fetch", | ||
"events": false, | ||
"fetch-h2": false, | ||
"path": false, | ||
"resolve-alpn": false, | ||
"ws": false | ||
"path": "path-browserify", | ||
"resolve-alpn": false | ||
}, | ||
"react-native": { | ||
"./dist/event-iterator": "./dist/event-iterator-browser", | ||
"./dist/fetch": "cross-fetch", | ||
"buffer": "buffer/", | ||
"./dist/event-iterator.js": "./dist/event-iterator-browser.js", | ||
"./dist/fetch.js": "cross-fetch", | ||
"events": false, | ||
"fetch-h2": false, | ||
"path": false, | ||
"resolve-alpn": false, | ||
"ws": false | ||
"path": "path-browserify", | ||
"resolve-alpn": false | ||
}, | ||
@@ -37,2 +35,3 @@ "files": [ | ||
"build": "tsc -b", | ||
"bundle": "webpack", | ||
"dev": "tsc -w", | ||
@@ -75,3 +74,3 @@ "prettier": "prettier --write .", | ||
"dependencies": { | ||
"@oada/types": "^1.8.1", | ||
"@oada/types": "^2.0.1", | ||
"abort-controller": "^3.0.0", | ||
@@ -90,11 +89,11 @@ "buffer": "^6.0.3", | ||
"isomorphic-ws": "^4.0.1", | ||
"ksuid": "^3.0.0", | ||
"media-type": "^0.3.1", | ||
"p-queue": "^6.6.2", | ||
"reconnecting-websocket": "^4.4.0", | ||
"resolve-alpn": "^1.2.1", | ||
"supports-color": "^9.2.1", | ||
"supports-color": "^9.2.2", | ||
"tslib": "^2.3.1", | ||
"type-is": "^1.6.18", | ||
"utf-8-validate": "^5.0.9", | ||
"ws": "^8.5.0" | ||
"ws": "^8.5.0", | ||
"xksuid": "^0.0.2" | ||
}, | ||
@@ -106,9 +105,9 @@ "devDependencies": { | ||
"@types/events": "^3.0.0", | ||
"@types/node": "^16.11.26", | ||
"@types/node": "^16.11.27", | ||
"@types/type-is": "^1.6.3", | ||
"@types/uuid": "^8.3.4", | ||
"@types/ws": "^8.5.3", | ||
"@typescript-eslint/eslint-plugin": "^5.16.0", | ||
"@typescript-eslint/parser": "^5.16.0", | ||
"@yarnpkg/sdks": "2.6.0", | ||
"@typescript-eslint/eslint-plugin": "^5.19.0", | ||
"@typescript-eslint/parser": "^5.19.0", | ||
"@yarnpkg/sdks": "3.0.0-rc.2", | ||
"ava": "4.0.0-rc.1", | ||
@@ -118,3 +117,3 @@ "axios": "^0.26.1", | ||
"dotenv": "^16.0.0", | ||
"eslint": "^8.11.0", | ||
"eslint": "^8.13.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
@@ -131,3 +130,3 @@ "eslint-config-xo": "^0.40.0", | ||
"eslint-plugin-i18n-text": "^1.0.1", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-no-constructor-bind": "^2.0.4", | ||
@@ -143,8 +142,13 @@ "eslint-plugin-no-only-tests": "^2.6.0", | ||
"eslint-plugin-security": "^1.4.0", | ||
"eslint-plugin-sonarjs": "^0.12.0", | ||
"eslint-plugin-unicorn": "^41.0.1", | ||
"prettier": "^2.6.0", | ||
"typescript": "4.6.2" | ||
"eslint-plugin-sonarjs": "^0.13.0", | ||
"eslint-plugin-unicorn": "^42.0.0", | ||
"path-browserify": "^1.0.1", | ||
"prettier": "^2.6.2", | ||
"process": "^0.11.10", | ||
"ts-loader": "^9.2.8", | ||
"typescript": "4.6.3", | ||
"webpack": "^5.72.0", | ||
"webpack-cli": "^4.9.2" | ||
}, | ||
"packageManager": "yarn@3.2.0" | ||
} |
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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
209406
4145
47
+ Addedmedia-type@^0.3.1
+ Addedxksuid@^0.0.2
+ Added@oada/types@2.0.1(transitive)
+ Addedajv@8.11.0(transitive)
+ Addedmedia-type@0.3.1(transitive)
+ Addedxksuid@0.0.2(transitive)
- Removedksuid@^3.0.0
- Removedtype-is@^1.6.18
- Removed@oada/types@1.8.1(transitive)
- Removedajv@8.17.1(transitive)
- Removedbase-convert-int-array@1.0.1(transitive)
- Removedfast-uri@3.0.3(transitive)
- Removedksuid@3.0.0(transitive)
- Removedmedia-typer@0.3.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedtype-is@1.6.18(transitive)
Updated@oada/types@^2.0.1
Updatedsupports-color@^9.2.2