@mocktomata/io-remote 8.0.4 → 9.0.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/cjs/errors.d.ts +1 -5
- package/cjs/errors.d.ts.map +1 -1
- package/cjs/errors.js +3 -11
- package/cjs/errors.js.map +1 -1
- package/cjs/index.d.ts +1 -2
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +1 -2
- package/cjs/index.js.map +1 -1
- package/cjs/io.d.ts +4 -0
- package/cjs/io.d.ts.map +1 -0
- package/cjs/io.internal.d.ts +8 -0
- package/cjs/io.internal.d.ts.map +1 -0
- package/cjs/{createIO.internal.js → io.internal.js} +9 -7
- package/cjs/io.internal.js.map +1 -0
- package/cjs/{createIO.js → io.js} +3 -3
- package/cjs/io.js.map +1 -0
- package/cjs/io.mock.d.ts +9 -0
- package/cjs/io.mock.d.ts.map +1 -0
- package/cjs/io.mock.js +112 -0
- package/cjs/io.mock.js.map +1 -0
- package/cjs/{types.d.ts → io.types.d.ts} +2 -2
- package/cjs/io.types.d.ts.map +1 -0
- package/cjs/{types.js → io.types.js} +1 -1
- package/cjs/io.types.js.map +1 -0
- package/cjs/server_info.d.ts +10 -0
- package/cjs/server_info.d.ts.map +1 -0
- package/cjs/server_info.js +16 -0
- package/cjs/server_info.js.map +1 -0
- package/cjs/{buildUrl.d.ts → url.d.ts} +1 -1
- package/cjs/url.d.ts.map +1 -0
- package/cjs/{buildUrl.js → url.js} +2 -2
- package/cjs/url.js.map +1 -0
- package/esm/errors.d.ts +1 -5
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +1 -8
- package/esm/errors.js.map +1 -1
- package/esm/index.d.ts +1 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -2
- package/esm/index.js.map +1 -1
- package/esm/io.d.ts +4 -0
- package/esm/io.d.ts.map +1 -0
- package/esm/io.internal.d.ts +8 -0
- package/esm/io.internal.d.ts.map +1 -0
- package/esm/{createIO.internal.js → io.internal.js} +6 -4
- package/esm/io.internal.js.map +1 -0
- package/esm/io.js +8 -0
- package/esm/io.js.map +1 -0
- package/esm/io.mock.d.ts +9 -0
- package/esm/io.mock.d.ts.map +1 -0
- package/esm/io.mock.js +84 -0
- package/esm/io.mock.js.map +1 -0
- package/esm/{types.d.ts → io.types.d.ts} +2 -2
- package/esm/io.types.d.ts.map +1 -0
- package/esm/io.types.js +2 -0
- package/esm/io.types.js.map +1 -0
- package/esm/server_info.d.ts +10 -0
- package/esm/server_info.d.ts.map +1 -0
- package/esm/server_info.js +12 -0
- package/esm/server_info.js.map +1 -0
- package/esm/{buildUrl.d.ts → url.d.ts} +1 -1
- package/esm/url.d.ts.map +1 -0
- package/esm/url.js +4 -0
- package/esm/url.js.map +1 -0
- package/package.json +8 -4
- package/ts/errors.ts +1 -8
- package/ts/index.ts +1 -2
- package/ts/{createIO.internal.ts → io.internal.ts} +12 -6
- package/ts/io.mock.ts +91 -0
- package/ts/io.ts +10 -0
- package/ts/{types.ts → io.types.ts} +1 -1
- package/ts/server_info.ts +24 -0
- package/ts/{buildUrl.ts → url.ts} +1 -1
- package/cjs/buildUrl.d.ts.map +0 -1
- package/cjs/buildUrl.js.map +0 -1
- package/cjs/createIO.d.ts +0 -4
- package/cjs/createIO.d.ts.map +0 -1
- package/cjs/createIO.internal.d.ts +0 -5
- package/cjs/createIO.internal.d.ts.map +0 -1
- package/cjs/createIO.internal.js.map +0 -1
- package/cjs/createIO.js.map +0 -1
- package/cjs/getServerInfo.d.ts +0 -16
- package/cjs/getServerInfo.d.ts.map +0 -1
- package/cjs/getServerInfo.js +0 -41
- package/cjs/getServerInfo.js.map +0 -1
- package/cjs/types.d.ts.map +0 -1
- package/cjs/types.internal.d.ts +0 -9
- package/cjs/types.internal.d.ts.map +0 -1
- package/cjs/types.internal.js +0 -3
- package/cjs/types.internal.js.map +0 -1
- package/cjs/types.js.map +0 -1
- package/esm/buildUrl.d.ts.map +0 -1
- package/esm/buildUrl.js +0 -4
- package/esm/buildUrl.js.map +0 -1
- package/esm/createIO.d.ts +0 -4
- package/esm/createIO.d.ts.map +0 -1
- package/esm/createIO.internal.d.ts +0 -5
- package/esm/createIO.internal.d.ts.map +0 -1
- package/esm/createIO.internal.js.map +0 -1
- package/esm/createIO.js +0 -8
- package/esm/createIO.js.map +0 -1
- package/esm/getServerInfo.d.ts +0 -16
- package/esm/getServerInfo.d.ts.map +0 -1
- package/esm/getServerInfo.js +0 -37
- package/esm/getServerInfo.js.map +0 -1
- package/esm/types.d.ts.map +0 -1
- package/esm/types.internal.d.ts +0 -9
- package/esm/types.internal.d.ts.map +0 -1
- package/esm/types.internal.js +0 -2
- package/esm/types.internal.js.map +0 -1
- package/esm/types.js +0 -2
- package/esm/types.js.map +0 -1
- package/ts/createIO.ts +0 -10
- package/ts/getServerInfo.ts +0 -62
- package/ts/types.internal.ts +0 -8
package/esm/getServerInfo.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { buildUrl } from './buildUrl.js';
|
|
2
|
-
import { ServerNotAvailable, ServerNotAvailableAtPortRange } from './errors.js';
|
|
3
|
-
export async function getServerInfo(context, options) {
|
|
4
|
-
return options ? tryGetServerInfo(context, options.url) : lookupServerInfo(context);
|
|
5
|
-
}
|
|
6
|
-
async function lookupServerInfo(context) {
|
|
7
|
-
const { location } = context;
|
|
8
|
-
const url = `${location.protocol}//${location.hostname}`;
|
|
9
|
-
if (location.hostname === 'localhost') {
|
|
10
|
-
return tryGetServerInfoAtPort(context, url, 3698, 3698, 3708);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
return tryGetServerInfo(context, url);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async function tryGetServerInfoAtPort(context, urlBase, port, start, end) {
|
|
17
|
-
if (port >= end) {
|
|
18
|
-
throw new ServerNotAvailableAtPortRange(urlBase, start, end);
|
|
19
|
-
}
|
|
20
|
-
const url = `${urlBase}:${port}`;
|
|
21
|
-
try {
|
|
22
|
-
return await tryGetServerInfo(context, url);
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
return tryGetServerInfoAtPort(context, urlBase, port + 1, start, end);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async function tryGetServerInfo({ fetch }, url) {
|
|
29
|
-
try {
|
|
30
|
-
const response = await fetch(buildUrl(url, 'info'));
|
|
31
|
-
return response.json();
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
throw e.code === 'ECONNREFUSED' ? new ServerNotAvailable(url) : e;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=getServerInfo.js.map
|
package/esm/getServerInfo.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getServerInfo.js","sourceRoot":"","sources":["../ts/getServerInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAmB/E,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAgB,EAAE,OAAwB;IAC7E,OAAO,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;AACpF,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAC5B,MAAM,GAAG,GAAG,GAAG,QAAQ,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,EAAE,CAAA;IACxD,IAAI,QAAQ,CAAC,QAAQ,KAAK,WAAW,EAAE;QACtC,OAAO,sBAAsB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;KAC7D;SAAM;QACN,OAAO,gBAAgB,CAAC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,OAAO,CAAA"}
|
package/esm/types.internal.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.internal.d.ts","sourceRoot":"","sources":["../ts/types.internal.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG;IACrB,KAAK,EAAE,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClE,QAAQ,EAAE;QACT,QAAQ,EAAE,MAAM,CAAA;QAChB,QAAQ,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,YAAY,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;CACnD,CAAA"}
|
package/esm/types.internal.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.internal.js","sourceRoot":"","sources":["../ts/types.internal.ts"],"names":[],"mappings":""}
|
package/esm/types.js
DELETED
package/esm/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":""}
|
package/ts/createIO.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Mocktomata } from '@mocktomata/framework'
|
|
2
|
-
import fetch from 'cross-fetch'
|
|
3
|
-
import { createIOInternal } from './createIO.internal.js'
|
|
4
|
-
import { importModule } from './platform.js'
|
|
5
|
-
import type { CreateIOOptions } from './types.js'
|
|
6
|
-
|
|
7
|
-
export async function createIO(options?: CreateIOOptions): Promise<Mocktomata.IO> {
|
|
8
|
-
// istanbul ignore next
|
|
9
|
-
return createIOInternal({ fetch, location, importModule }, options)
|
|
10
|
-
}
|
package/ts/getServerInfo.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { buildUrl } from './buildUrl.js'
|
|
2
|
-
import { ServerNotAvailable, ServerNotAvailableAtPortRange } from './errors.js'
|
|
3
|
-
import type { ServiceOptions } from './types.js'
|
|
4
|
-
|
|
5
|
-
export type ServerInfo = {
|
|
6
|
-
name: string
|
|
7
|
-
version: string
|
|
8
|
-
url: string
|
|
9
|
-
// TODO: server not returning plugins
|
|
10
|
-
plugins?: string[]
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type Context = {
|
|
14
|
-
fetch: (url: RequestInfo, init?: RequestInit) => Promise<Response>
|
|
15
|
-
location: {
|
|
16
|
-
protocol: string
|
|
17
|
-
hostname: string
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function getServerInfo(context: Context, options?: ServiceOptions): Promise<ServerInfo> {
|
|
22
|
-
return options ? tryGetServerInfo(context, options.url) : lookupServerInfo(context)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function lookupServerInfo(context: Context) {
|
|
26
|
-
const { location } = context
|
|
27
|
-
const url = `${location.protocol}//${location.hostname}`
|
|
28
|
-
if (location.hostname === 'localhost') {
|
|
29
|
-
return tryGetServerInfoAtPort(context, url, 3698, 3698, 3708)
|
|
30
|
-
} else {
|
|
31
|
-
return tryGetServerInfo(context, url)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async function tryGetServerInfoAtPort(
|
|
36
|
-
context: Context,
|
|
37
|
-
urlBase: string,
|
|
38
|
-
port: number,
|
|
39
|
-
start: number,
|
|
40
|
-
end: number
|
|
41
|
-
): Promise<ServerInfo> {
|
|
42
|
-
if (port >= end) {
|
|
43
|
-
throw new ServerNotAvailableAtPortRange(urlBase, start, end)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const url = `${urlBase}:${port}`
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
return await tryGetServerInfo(context, url)
|
|
50
|
-
} catch (e: any) {
|
|
51
|
-
return tryGetServerInfoAtPort(context, urlBase, port + 1, start, end)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async function tryGetServerInfo({ fetch }: Context, url: string): Promise<ServerInfo> {
|
|
56
|
-
try {
|
|
57
|
-
const response = await fetch(buildUrl(url, 'info'))
|
|
58
|
-
return response.json()
|
|
59
|
-
} catch (e: any) {
|
|
60
|
-
throw e.code === 'ECONNREFUSED' ? new ServerNotAvailable(url) : e
|
|
61
|
-
}
|
|
62
|
-
}
|