@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.
Files changed (115) hide show
  1. package/cjs/errors.d.ts +1 -5
  2. package/cjs/errors.d.ts.map +1 -1
  3. package/cjs/errors.js +3 -11
  4. package/cjs/errors.js.map +1 -1
  5. package/cjs/index.d.ts +1 -2
  6. package/cjs/index.d.ts.map +1 -1
  7. package/cjs/index.js +1 -2
  8. package/cjs/index.js.map +1 -1
  9. package/cjs/io.d.ts +4 -0
  10. package/cjs/io.d.ts.map +1 -0
  11. package/cjs/io.internal.d.ts +8 -0
  12. package/cjs/io.internal.d.ts.map +1 -0
  13. package/cjs/{createIO.internal.js → io.internal.js} +9 -7
  14. package/cjs/io.internal.js.map +1 -0
  15. package/cjs/{createIO.js → io.js} +3 -3
  16. package/cjs/io.js.map +1 -0
  17. package/cjs/io.mock.d.ts +9 -0
  18. package/cjs/io.mock.d.ts.map +1 -0
  19. package/cjs/io.mock.js +112 -0
  20. package/cjs/io.mock.js.map +1 -0
  21. package/cjs/{types.d.ts → io.types.d.ts} +2 -2
  22. package/cjs/io.types.d.ts.map +1 -0
  23. package/cjs/{types.js → io.types.js} +1 -1
  24. package/cjs/io.types.js.map +1 -0
  25. package/cjs/server_info.d.ts +10 -0
  26. package/cjs/server_info.d.ts.map +1 -0
  27. package/cjs/server_info.js +16 -0
  28. package/cjs/server_info.js.map +1 -0
  29. package/cjs/{buildUrl.d.ts → url.d.ts} +1 -1
  30. package/cjs/url.d.ts.map +1 -0
  31. package/cjs/{buildUrl.js → url.js} +2 -2
  32. package/cjs/url.js.map +1 -0
  33. package/esm/errors.d.ts +1 -5
  34. package/esm/errors.d.ts.map +1 -1
  35. package/esm/errors.js +1 -8
  36. package/esm/errors.js.map +1 -1
  37. package/esm/index.d.ts +1 -2
  38. package/esm/index.d.ts.map +1 -1
  39. package/esm/index.js +1 -2
  40. package/esm/index.js.map +1 -1
  41. package/esm/io.d.ts +4 -0
  42. package/esm/io.d.ts.map +1 -0
  43. package/esm/io.internal.d.ts +8 -0
  44. package/esm/io.internal.d.ts.map +1 -0
  45. package/esm/{createIO.internal.js → io.internal.js} +6 -4
  46. package/esm/io.internal.js.map +1 -0
  47. package/esm/io.js +8 -0
  48. package/esm/io.js.map +1 -0
  49. package/esm/io.mock.d.ts +9 -0
  50. package/esm/io.mock.d.ts.map +1 -0
  51. package/esm/io.mock.js +84 -0
  52. package/esm/io.mock.js.map +1 -0
  53. package/esm/{types.d.ts → io.types.d.ts} +2 -2
  54. package/esm/io.types.d.ts.map +1 -0
  55. package/esm/io.types.js +2 -0
  56. package/esm/io.types.js.map +1 -0
  57. package/esm/server_info.d.ts +10 -0
  58. package/esm/server_info.d.ts.map +1 -0
  59. package/esm/server_info.js +12 -0
  60. package/esm/server_info.js.map +1 -0
  61. package/esm/{buildUrl.d.ts → url.d.ts} +1 -1
  62. package/esm/url.d.ts.map +1 -0
  63. package/esm/url.js +4 -0
  64. package/esm/url.js.map +1 -0
  65. package/package.json +8 -4
  66. package/ts/errors.ts +1 -8
  67. package/ts/index.ts +1 -2
  68. package/ts/{createIO.internal.ts → io.internal.ts} +12 -6
  69. package/ts/io.mock.ts +91 -0
  70. package/ts/io.ts +10 -0
  71. package/ts/{types.ts → io.types.ts} +1 -1
  72. package/ts/server_info.ts +24 -0
  73. package/ts/{buildUrl.ts → url.ts} +1 -1
  74. package/cjs/buildUrl.d.ts.map +0 -1
  75. package/cjs/buildUrl.js.map +0 -1
  76. package/cjs/createIO.d.ts +0 -4
  77. package/cjs/createIO.d.ts.map +0 -1
  78. package/cjs/createIO.internal.d.ts +0 -5
  79. package/cjs/createIO.internal.d.ts.map +0 -1
  80. package/cjs/createIO.internal.js.map +0 -1
  81. package/cjs/createIO.js.map +0 -1
  82. package/cjs/getServerInfo.d.ts +0 -16
  83. package/cjs/getServerInfo.d.ts.map +0 -1
  84. package/cjs/getServerInfo.js +0 -41
  85. package/cjs/getServerInfo.js.map +0 -1
  86. package/cjs/types.d.ts.map +0 -1
  87. package/cjs/types.internal.d.ts +0 -9
  88. package/cjs/types.internal.d.ts.map +0 -1
  89. package/cjs/types.internal.js +0 -3
  90. package/cjs/types.internal.js.map +0 -1
  91. package/cjs/types.js.map +0 -1
  92. package/esm/buildUrl.d.ts.map +0 -1
  93. package/esm/buildUrl.js +0 -4
  94. package/esm/buildUrl.js.map +0 -1
  95. package/esm/createIO.d.ts +0 -4
  96. package/esm/createIO.d.ts.map +0 -1
  97. package/esm/createIO.internal.d.ts +0 -5
  98. package/esm/createIO.internal.d.ts.map +0 -1
  99. package/esm/createIO.internal.js.map +0 -1
  100. package/esm/createIO.js +0 -8
  101. package/esm/createIO.js.map +0 -1
  102. package/esm/getServerInfo.d.ts +0 -16
  103. package/esm/getServerInfo.d.ts.map +0 -1
  104. package/esm/getServerInfo.js +0 -37
  105. package/esm/getServerInfo.js.map +0 -1
  106. package/esm/types.d.ts.map +0 -1
  107. package/esm/types.internal.d.ts +0 -9
  108. package/esm/types.internal.d.ts.map +0 -1
  109. package/esm/types.internal.js +0 -2
  110. package/esm/types.internal.js.map +0 -1
  111. package/esm/types.js +0 -2
  112. package/esm/types.js.map +0 -1
  113. package/ts/createIO.ts +0 -10
  114. package/ts/getServerInfo.ts +0 -62
  115. package/ts/types.internal.ts +0 -8
@@ -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
@@ -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,OAAO,EAAE,GAAG,CAAC,CAAA;KACrC;AACF,CAAC;AAED,KAAK,UAAU,sBAAsB,CACpC,OAAgB,EAChB,OAAe,EACf,IAAY,EACZ,KAAa,EACb,GAAW;IAEX,IAAI,IAAI,IAAI,GAAG,EAAE;QAChB,MAAM,IAAI,6BAA6B,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;KAC5D;IAED,MAAM,GAAG,GAAG,GAAG,OAAO,IAAI,IAAI,EAAE,CAAA;IAEhC,IAAI;QACH,OAAO,MAAM,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;KAC3C;IAAC,OAAO,CAAM,EAAE;QAChB,OAAO,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;KACrE;AACF,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,EAAE,KAAK,EAAW,EAAE,GAAW;IAC9D,IAAI;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;QACnD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;KACtB;IAAC,OAAO,CAAM,EAAE;QAChB,MAAM,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,IAAI,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;KACjE;AACF,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAEhD,MAAM,MAAM,cAAc,GAAG;IAC5B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,GAAG,CAAC,OAAO,CAAA"}
@@ -1,9 +0,0 @@
1
- export type Context = {
2
- fetch: (url: RequestInfo, init?: RequestInit) => Promise<Response>;
3
- location: {
4
- protocol: string;
5
- hostname: string;
6
- };
7
- importModule(moduleSpecifier: string): Promise<any>;
8
- };
9
- //# sourceMappingURL=types.internal.d.ts.map
@@ -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"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.internal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.internal.js","sourceRoot":"","sources":["../ts/types.internal.ts"],"names":[],"mappings":""}
package/esm/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
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
- }
@@ -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
- }
@@ -1,8 +0,0 @@
1
- export type Context = {
2
- fetch: (url: RequestInfo, init?: RequestInit) => Promise<Response>
3
- location: {
4
- protocol: string
5
- hostname: string
6
- }
7
- importModule(moduleSpecifier: string): Promise<any>
8
- }