@mocktomata/io-remote 9.2.4 → 10.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/esm/errors.d.ts +6 -4
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +11 -7
- package/esm/errors.js.map +1 -1
- package/esm/index.d.ts +3 -3
- package/esm/index.js +3 -3
- package/esm/io.d.ts +4 -2
- package/esm/io.d.ts.map +1 -1
- package/esm/io.internal.d.ts +6 -4
- package/esm/io.internal.d.ts.map +1 -1
- package/esm/io.internal.js +41 -37
- package/esm/io.internal.js.map +1 -1
- package/esm/io.js +13 -6
- package/esm/io.js.map +1 -1
- package/esm/io.mock.d.ts +6 -4
- package/esm/io.mock.d.ts.map +1 -1
- package/esm/io.mock.js +63 -79
- package/esm/io.mock.js.map +1 -1
- package/esm/io.types.d.ts +7 -5
- package/esm/io.types.d.ts.map +1 -1
- package/esm/io.types.js +0 -1
- package/esm/platform.d.ts +2 -0
- package/esm/platform.d.ts.map +1 -1
- package/esm/platform.js +6 -2
- package/esm/platform.js.map +1 -1
- package/esm/server_info.d.ts +8 -6
- package/esm/server_info.d.ts.map +1 -1
- package/esm/server_info.js +12 -10
- package/esm/server_info.js.map +1 -1
- package/esm/url.d.ts +2 -0
- package/esm/url.d.ts.map +1 -1
- package/esm/url.js +6 -2
- package/esm/url.js.map +1 -1
- package/package.json +33 -36
- package/ts/errors.ts +5 -2
- package/ts/index.ts +1 -1
- package/ts/io.internal.ts +3 -3
- package/ts/io.mock.ts +7 -6
- package/ts/server_info.ts +2 -5
- package/cjs/errors.d.ts +0 -7
- package/cjs/errors.d.ts.map +0 -1
- package/cjs/errors.js +0 -12
- package/cjs/errors.js.map +0 -1
- package/cjs/index.d.ts +0 -3
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -19
- package/cjs/index.js.map +0 -1
- package/cjs/io.d.ts +0 -4
- package/cjs/io.d.ts.map +0 -1
- package/cjs/io.internal.d.ts +0 -8
- package/cjs/io.internal.d.ts.map +0 -1
- package/cjs/io.internal.js +0 -43
- package/cjs/io.internal.js.map +0 -1
- package/cjs/io.js +0 -15
- package/cjs/io.js.map +0 -1
- package/cjs/io.mock.d.ts +0 -9
- package/cjs/io.mock.d.ts.map +0 -1
- package/cjs/io.mock.js +0 -112
- package/cjs/io.mock.js.map +0 -1
- package/cjs/io.types.d.ts +0 -9
- package/cjs/io.types.d.ts.map +0 -1
- package/cjs/io.types.js +0 -3
- package/cjs/io.types.js.map +0 -1
- package/cjs/package.json +0 -1
- package/cjs/platform.d.ts +0 -2
- package/cjs/platform.d.ts.map +0 -1
- package/cjs/platform.js +0 -31
- package/cjs/platform.js.map +0 -1
- package/cjs/server_info.d.ts +0 -10
- package/cjs/server_info.d.ts.map +0 -1
- package/cjs/server_info.js +0 -16
- package/cjs/server_info.js.map +0 -1
- package/cjs/url.d.ts +0 -2
- package/cjs/url.d.ts.map +0 -1
- package/cjs/url.js +0 -8
- package/cjs/url.js.map +0 -1
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js.map +0 -1
- package/esm/io.types.js.map +0 -1
package/esm/errors.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { MocktomataError } from
|
|
2
|
-
import { ModuleError } from
|
|
1
|
+
import { MocktomataError } from "@mocktomata/framework";
|
|
2
|
+
import { ModuleError } from "iso-error";
|
|
3
|
+
//#region ts/errors.d.ts
|
|
3
4
|
export declare class ServiceNotAvailable extends MocktomataError {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
url: string;
|
|
6
|
+
constructor(url: string, options?: ModuleError.Options);
|
|
6
7
|
}
|
|
8
|
+
//#endregion
|
|
7
9
|
//# sourceMappingURL=errors.d.ts.map
|
package/esm/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../ts/errors.ts"],"mappings":";;;qBAEa,4BAA4B;EAEhC;EAAA,YAAA,aACP,UAAU,YAAY"}
|
package/esm/errors.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { MocktomataError } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
1
|
+
import { MocktomataError } from "@mocktomata/framework";
|
|
2
|
+
//#region ts/errors.ts
|
|
3
|
+
var ServiceNotAvailable = class extends MocktomataError {
|
|
4
|
+
constructor(url, options) {
|
|
5
|
+
super(`Unable to connect to server at ${url}`, options);
|
|
6
|
+
this.url = url;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ServiceNotAvailable };
|
|
11
|
+
|
|
8
12
|
//# sourceMappingURL=errors.js.map
|
package/esm/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../ts/errors.ts"],"sourcesContent":["import { MocktomataError } from '@mocktomata/framework'\nimport type { ModuleError } from 'iso-error'\nexport class ServiceNotAvailable extends MocktomataError {\n\tconstructor(\n\t\tpublic url: string,\n\t\toptions?: ModuleError.Options\n\t) {\n\t\tsuper(`Unable to connect to server at ${url}`, options)\n\t}\n}\n"],"mappings":";;AAEA,IAAa,sBAAb,cAAyC,gBAAgB;CACxD,YACC,KACA,SACC;EACD,MAAM,kCAAkC,OAAO,OAAO;EAH/C,KAAA,MAAA;CAIR;AACD"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ServiceNotAvailable } from "./errors.js";
|
|
2
|
+
import { createIO } from "./io.js";
|
|
3
|
+
export { ServiceNotAvailable, createIO };
|
package/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ServiceNotAvailable } from "./errors.js";
|
|
2
|
+
import { createIO } from "./io.js";
|
|
3
|
+
export { ServiceNotAvailable, createIO };
|
package/esm/io.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { IOOptions } from "./io.types.js";
|
|
2
|
+
import { Mocktomata } from "@mocktomata/framework";
|
|
3
|
+
//#region ts/io.d.ts
|
|
3
4
|
export declare function createIO(options: IOOptions): Promise<Mocktomata.IO>;
|
|
5
|
+
//#endregion
|
|
4
6
|
//# sourceMappingURL=io.d.ts.map
|
package/esm/io.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.d.ts","
|
|
1
|
+
{"version":3,"file":"io.d.ts","names":[],"sources":["../ts/io.ts"],"mappings":";;;wBAMsB,SAAS,SAAS,YAAY,QAAQ,WAAW"}
|
package/esm/io.internal.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { IOOptions } from "./io.types.js";
|
|
2
|
+
import { Mocktomata, SpecPlugin } from "@mocktomata/framework";
|
|
3
|
+
//#region ts/io.internal.d.ts
|
|
3
4
|
export type Context = {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
fetch: (url: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
6
|
+
importModule(moduleSpecifier: string): Promise<SpecPlugin.Module>;
|
|
6
7
|
};
|
|
7
8
|
export declare function createIOInternal(ctx: Context, options: IOOptions): Promise<Mocktomata.IO>;
|
|
9
|
+
//#endregion
|
|
8
10
|
//# sourceMappingURL=io.internal.d.ts.map
|
package/esm/io.internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.internal.d.ts","
|
|
1
|
+
{"version":3,"file":"io.internal.d.ts","names":[],"sources":["../ts/io.internal.ts"],"mappings":";;;YAKY;EACX,QAAQ,KAAK,aAAa,OAAO,gBAAgB,QAAQ;EACzD,aAAa,0BAA0B,QAAQ,WAAW;;wBAGrC,iBAAiB,KAAK,SAAS,SAAS,YAAY,QAAQ,WAAW"}
|
package/esm/io.internal.js
CHANGED
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getServerInfo } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
import { buildUrl } from "./url.js";
|
|
2
|
+
import { getServerInfo } from "./server_info.js";
|
|
3
|
+
import { SpecNotFound, json } from "@mocktomata/framework";
|
|
4
|
+
//#region ts/io.internal.ts
|
|
5
|
+
async function createIOInternal(ctx, options) {
|
|
6
|
+
return {
|
|
7
|
+
async loadConfig() {
|
|
8
|
+
const info = await getServerInfo(ctx, options);
|
|
9
|
+
const url = buildUrl(info.url, "config");
|
|
10
|
+
return (await ctx.fetch(url)).json();
|
|
11
|
+
},
|
|
12
|
+
async loadPlugin(name) {
|
|
13
|
+
return ctx.importModule(name);
|
|
14
|
+
},
|
|
15
|
+
async readSpec(specName, specRelativePath) {
|
|
16
|
+
const info = await getServerInfo(ctx, options);
|
|
17
|
+
const id = btoa(json.stringify({
|
|
18
|
+
specName,
|
|
19
|
+
specRelativePath
|
|
20
|
+
}));
|
|
21
|
+
const response = await ctx.fetch(buildUrl(info.url, `specs/${id}`));
|
|
22
|
+
if (response.status === 404) throw new SpecNotFound(id, specRelativePath);
|
|
23
|
+
return response.json();
|
|
24
|
+
},
|
|
25
|
+
async writeSpec(specName, specRelativePath, record) {
|
|
26
|
+
const info = await getServerInfo(ctx, options);
|
|
27
|
+
const id = btoa(json.stringify({
|
|
28
|
+
specName,
|
|
29
|
+
specRelativePath
|
|
30
|
+
}));
|
|
31
|
+
const response = await ctx.fetch(buildUrl(info.url, `specs/${id}`), {
|
|
32
|
+
method: "POST",
|
|
33
|
+
body: json.stringify(record)
|
|
34
|
+
});
|
|
35
|
+
// istanbul ignore next
|
|
36
|
+
if (!response.ok) throw new Error(`failed to write spec: ${response.statusText}`);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
38
39
|
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { createIOInternal };
|
|
42
|
+
|
|
39
43
|
//# sourceMappingURL=io.internal.js.map
|
package/esm/io.internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.internal.js","
|
|
1
|
+
{"version":3,"file":"io.internal.js","names":[],"sources":["../ts/io.internal.ts"],"sourcesContent":["import { json, type Mocktomata, SpecNotFound, type SpecPlugin, type SpecRecord } from '@mocktomata/framework'\nimport type { IOOptions } from './io.types.js'\nimport { getServerInfo } from './server_info.js'\nimport { buildUrl } from './url.js'\n\nexport type Context = {\n\tfetch: (url: RequestInfo, init?: RequestInit) => Promise<Response>\n\timportModule(moduleSpecifier: string): Promise<SpecPlugin.Module>\n}\n\nexport async function createIOInternal(ctx: Context, options: IOOptions): Promise<Mocktomata.IO> {\n\treturn {\n\t\tasync loadConfig() {\n\t\t\tconst info = await getServerInfo(ctx, options)\n\t\t\t// @TODO add browser config?\n\t\t\tconst url = buildUrl(info.url, 'config')\n\t\t\tconst response = await ctx.fetch(url)\n\t\t\treturn response.json()\n\t\t},\n\t\tasync loadPlugin(name: string): Promise<SpecPlugin.Module> {\n\t\t\treturn ctx.importModule(name)\n\t\t},\n\t\tasync readSpec(specName: string, specRelativePath: string): Promise<SpecRecord> {\n\t\t\tconst info = await getServerInfo(ctx, options)\n\t\t\tconst id = btoa(json.stringify({ specName, specRelativePath }))\n\t\t\tconst response = await ctx.fetch(buildUrl(info.url, `specs/${id}`))\n\t\t\tif (response.status === 404) {\n\t\t\t\tthrow new SpecNotFound(id, specRelativePath)\n\t\t\t}\n\t\t\treturn response.json()\n\t\t},\n\t\tasync writeSpec(specName, specRelativePath, record) {\n\t\t\tconst info = await getServerInfo(ctx, options)\n\t\t\tconst id = btoa(json.stringify({ specName, specRelativePath }))\n\t\t\tconst response = await ctx.fetch(buildUrl(info.url, `specs/${id}`), {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tbody: json.stringify(record)\n\t\t\t})\n\t\t\t// istanbul ignore next\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`failed to write spec: ${response.statusText}`)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;AAUA,eAAsB,iBAAiB,KAAc,SAA4C;CAChG,OAAO;EACN,MAAM,aAAa;GAClB,MAAM,OAAO,MAAM,cAAc,KAAK,OAAO;GAE7C,MAAM,MAAM,SAAS,KAAK,KAAK,QAAQ;GAEvC,QAAO,MADgB,IAAI,MAAM,GAAG,EAAA,CACpB,KAAK;EACtB;EACA,MAAM,WAAW,MAA0C;GAC1D,OAAO,IAAI,aAAa,IAAI;EAC7B;EACA,MAAM,SAAS,UAAkB,kBAA+C;GAC/E,MAAM,OAAO,MAAM,cAAc,KAAK,OAAO;GAC7C,MAAM,KAAK,KAAK,KAAK,UAAU;IAAE;IAAU;GAAiB,CAAC,CAAC;GAC9D,MAAM,WAAW,MAAM,IAAI,MAAM,SAAS,KAAK,KAAK,SAAS,IAAI,CAAC;GAClE,IAAI,SAAS,WAAW,KACvB,MAAM,IAAI,aAAa,IAAI,gBAAgB;GAE5C,OAAO,SAAS,KAAK;EACtB;EACA,MAAM,UAAU,UAAU,kBAAkB,QAAQ;GACnD,MAAM,OAAO,MAAM,cAAc,KAAK,OAAO;GAC7C,MAAM,KAAK,KAAK,KAAK,UAAU;IAAE;IAAU;GAAiB,CAAC,CAAC;GAC9D,MAAM,WAAW,MAAM,IAAI,MAAM,SAAS,KAAK,KAAK,SAAS,IAAI,GAAG;IACnE,QAAQ;IACR,MAAM,KAAK,UAAU,MAAM;GAC5B,CAAC;;GAED,IAAI,CAAC,SAAS,IACb,MAAM,IAAI,MAAM,yBAAyB,SAAS,YAAY;EAEhE;CACD;AACD"}
|
package/esm/io.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { createIOInternal } from "./io.internal.js";
|
|
2
|
+
import { importModule } from "./platform.js";
|
|
3
|
+
import fetch from "cross-fetch";
|
|
4
|
+
//#region ts/io.ts
|
|
5
|
+
async function createIO(options) {
|
|
6
|
+
// istanbul ignore next
|
|
7
|
+
return createIOInternal({
|
|
8
|
+
fetch,
|
|
9
|
+
importModule
|
|
10
|
+
}, options);
|
|
7
11
|
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { createIO };
|
|
14
|
+
|
|
8
15
|
//# sourceMappingURL=io.js.map
|
package/esm/io.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.js","
|
|
1
|
+
{"version":3,"file":"io.js","names":[],"sources":["../ts/io.ts"],"sourcesContent":["import type { Mocktomata } from '@mocktomata/framework'\nimport fetch from 'cross-fetch'\nimport { createIOInternal } from './io.internal.js'\nimport type { IOOptions } from './io.types.js'\nimport { importModule } from './platform.js'\n\nexport async function createIO(options: IOOptions): Promise<Mocktomata.IO> {\n\t// istanbul ignore next\n\treturn createIOInternal({ fetch, importModule }, options)\n}\n"],"mappings":";;;;AAMA,eAAsB,SAAS,SAA4C;;CAE1E,OAAO,iBAAiB;EAAE;EAAO;CAAa,GAAG,OAAO;AACzD"}
|
package/esm/io.mock.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Context } from "./io.internal.js";
|
|
2
|
+
//#region ts/io.mock.d.ts
|
|
2
3
|
export declare function newMemoryContext({ url }?: {
|
|
3
|
-
|
|
4
|
+
url: string;
|
|
4
5
|
}): Context;
|
|
5
6
|
export declare function createFakeServerFetch(): ((url: RequestInfo, init?: RequestInit) => Promise<Response>) & {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
specs: Record<string, any>;
|
|
8
|
+
scenarios: Record<string, any>;
|
|
8
9
|
};
|
|
10
|
+
//#endregion
|
|
9
11
|
//# sourceMappingURL=io.mock.d.ts.map
|
package/esm/io.mock.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.mock.d.ts","
|
|
1
|
+
{"version":3,"file":"io.mock.d.ts","names":[],"sources":["../ts/io.mock.ts"],"mappings":";;wBAKgB,mBAAmB;;IAA2C;wBA+B9D,2BAAqB,KAUvB,aAAW,OAAS,gBAAW,QAAA"}
|
package/esm/io.mock.js
CHANGED
|
@@ -1,84 +1,68 @@
|
|
|
1
|
-
import { json } from
|
|
2
|
-
import * as f from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
};
|
|
1
|
+
import { json } from "@mocktomata/framework";
|
|
2
|
+
import * as f from "cross-fetch";
|
|
3
|
+
//#region ts/io.mock.ts
|
|
4
|
+
function newMemoryContext({ url } = { url: "http://localhost:3789" }) {
|
|
5
|
+
const store = {
|
|
6
|
+
info: {
|
|
7
|
+
name: "mocktomata",
|
|
8
|
+
version: "8.0.4",
|
|
9
|
+
url
|
|
10
|
+
},
|
|
11
|
+
config: {
|
|
12
|
+
ecmaVersion: "es2015",
|
|
13
|
+
plugins: []
|
|
14
|
+
},
|
|
15
|
+
modules: {}
|
|
16
|
+
};
|
|
17
|
+
const urlBase = store.info.url;
|
|
18
|
+
return {
|
|
19
|
+
async fetch(url) {
|
|
20
|
+
switch (true) {
|
|
21
|
+
case url === `${urlBase}/api/info`: return new Response(JSON.stringify(store.info));
|
|
22
|
+
case url === `${urlBase}/api/config`: return new Response(JSON.stringify(store.config));
|
|
23
|
+
default: throw new Error(`not supported: ${url}`);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
async importModule(moduleSpecifier) {
|
|
27
|
+
return store.modules[moduleSpecifier];
|
|
28
|
+
}
|
|
29
|
+
};
|
|
32
30
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
if (specs[specName])
|
|
63
|
-
return new f.Response(json.stringify(specs[specName]));
|
|
64
|
-
else
|
|
65
|
-
return new f.Response(undefined, { status: 404 });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// istanbul ignore next
|
|
69
|
-
console.error(url);
|
|
70
|
-
// istanbul ignore next
|
|
71
|
-
return new f.Response(undefined, { status: 404 });
|
|
72
|
-
}, {
|
|
73
|
-
specs,
|
|
74
|
-
scenarios
|
|
75
|
-
});
|
|
31
|
+
function createFakeServerFetch() {
|
|
32
|
+
const specs = { exist: { actions: [] } };
|
|
33
|
+
return Object.assign(async (url, init) => {
|
|
34
|
+
const uri = extractUri(url);
|
|
35
|
+
if (uri === "api/info") return new f.Response(json.stringify({
|
|
36
|
+
url: "http://localhost:3999",
|
|
37
|
+
version: "1.0"
|
|
38
|
+
}));
|
|
39
|
+
if (uri === "api/config") return new f.Response(json.stringify({ plugins: ["@mocktomata/plugin-fixture-dummy"] }));
|
|
40
|
+
if (uri.startsWith("api/specs/")) {
|
|
41
|
+
const id = /api\/specs\/(.*)/.exec(uri)[1];
|
|
42
|
+
const { specName } = json.parse(atob(id));
|
|
43
|
+
if (init && init.method === "POST") {
|
|
44
|
+
specs[specName] = json.parse(init.body);
|
|
45
|
+
return new f.Response(void 0);
|
|
46
|
+
}
|
|
47
|
+
if (specs[specName]) return new f.Response(json.stringify(specs[specName]));
|
|
48
|
+
return new f.Response(void 0, { status: 404 });
|
|
49
|
+
}
|
|
50
|
+
// istanbul ignore next
|
|
51
|
+
console.error(url);
|
|
52
|
+
// istanbul ignore next
|
|
53
|
+
return new f.Response(void 0, { status: 404 });
|
|
54
|
+
}, {
|
|
55
|
+
specs,
|
|
56
|
+
scenarios: { exist: { scenario: "exist" } }
|
|
57
|
+
});
|
|
76
58
|
}
|
|
77
59
|
function extractUri(url) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return match[1];
|
|
60
|
+
const match = /https?:\/\/\w*:\d+\/(.*)/.exec(url);
|
|
61
|
+
// istanbul ignore next
|
|
62
|
+
if (!match) throw match;
|
|
63
|
+
return match[1];
|
|
83
64
|
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { createFakeServerFetch, newMemoryContext };
|
|
67
|
+
|
|
84
68
|
//# sourceMappingURL=io.mock.js.map
|
package/esm/io.mock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.mock.js","
|
|
1
|
+
{"version":3,"file":"io.mock.js","names":[],"sources":["../ts/io.mock.ts"],"sourcesContent":["import { type Config, json, type SpecPlugin } from '@mocktomata/framework'\nimport * as f from 'cross-fetch'\nimport type { Context } from './io.internal.js'\nimport type { ServerInfo } from './server_info.js'\n\nexport function newMemoryContext({ url } = { url: 'http://localhost:3789' }): Context {\n\tconst store = {\n\t\tinfo: {\n\t\t\tname: 'mocktomata',\n\t\t\tversion: '8.0.4',\n\t\t\turl\n\t\t} satisfies ServerInfo,\n\t\tconfig: {\n\t\t\tecmaVersion: 'es2015',\n\t\t\tplugins: []\n\t\t} satisfies Config.Input,\n\t\tmodules: {} as Record<string, SpecPlugin.Module>\n\t}\n\tconst urlBase = store.info.url\n\treturn {\n\t\tasync fetch(url) {\n\t\t\tswitch (true) {\n\t\t\t\tcase url === `${urlBase}/api/info`:\n\t\t\t\t\treturn new Response(JSON.stringify(store.info))\n\t\t\t\tcase url === `${urlBase}/api/config`:\n\t\t\t\t\treturn new Response(JSON.stringify(store.config))\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(`not supported: ${url}`)\n\t\t\t}\n\t\t},\n\t\tasync importModule(moduleSpecifier) {\n\t\t\treturn store.modules[moduleSpecifier]\n\t\t}\n\t}\n}\n\nexport function createFakeServerFetch() {\n\tconst specs: Record<string, any> = {\n\t\texist: { actions: [] }\n\t}\n\n\tconst scenarios: Record<string, any> = {\n\t\texist: { scenario: 'exist' }\n\t}\n\n\treturn Object.assign(\n\t\tasync (url: RequestInfo, init?: RequestInit) => {\n\t\t\tconst uri = extractUri(url as string)\n\t\t\tif (uri === 'api/info') {\n\t\t\t\treturn new f.Response(\n\t\t\t\t\tjson.stringify({\n\t\t\t\t\t\turl: 'http://localhost:3999',\n\t\t\t\t\t\tversion: '1.0'\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (uri === 'api/config') {\n\t\t\t\treturn new f.Response(\n\t\t\t\t\tjson.stringify({\n\t\t\t\t\t\tplugins: ['@mocktomata/plugin-fixture-dummy']\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t\t// istanbul ignore next\n\t\t\t}\n\t\t\tif (uri.startsWith('api/specs/')) {\n\t\t\t\tconst id = /api\\/specs\\/(.*)/.exec(uri)![1]\n\t\t\t\tconst { specName } = json.parse(atob(id))\n\t\t\t\tif (init && init.method === 'POST') {\n\t\t\t\t\tspecs[specName] = json.parse(init.body as string)\n\t\t\t\t\treturn new f.Response(undefined)\n\t\t\t\t}\n\t\t\t\tif (specs[specName]) return new f.Response(json.stringify(specs[specName]))\n\t\t\t\treturn new f.Response(undefined, { status: 404 })\n\t\t\t}\n\t\t\t// istanbul ignore next\n\t\t\tconsole.error(url)\n\t\t\t// istanbul ignore next\n\t\t\treturn new f.Response(undefined, { status: 404 })\n\t\t},\n\t\t{\n\t\t\tspecs,\n\t\t\tscenarios\n\t\t}\n\t)\n}\n\nfunction extractUri(url: string) {\n\tconst match = /https?:\\/\\/\\w*:\\d+\\/(.*)/.exec(url)\n\t// istanbul ignore next\n\tif (!match) throw match\n\treturn match[1]\n}\n"],"mappings":";;;AAKA,SAAgB,iBAAiB,EAAE,QAAQ,EAAE,KAAK,wBAAwB,GAAY;CACrF,MAAM,QAAQ;EACb,MAAM;GACL,MAAM;GACN,SAAS;GACT;EACD;EACA,QAAQ;GACP,aAAa;GACb,SAAS,CAAC;EACX;EACA,SAAS,CAAC;CACX;CACA,MAAM,UAAU,MAAM,KAAK;CAC3B,OAAO;EACN,MAAM,MAAM,KAAK;GAChB,QAAQ,MAAR;IACC,KAAK,QAAQ,GAAG,QAAQ,YACvB,OAAO,IAAI,SAAS,KAAK,UAAU,MAAM,IAAI,CAAC;IAC/C,KAAK,QAAQ,GAAG,QAAQ,cACvB,OAAO,IAAI,SAAS,KAAK,UAAU,MAAM,MAAM,CAAC;IACjD,SACC,MAAM,IAAI,MAAM,kBAAkB,KAAK;GACzC;EACD;EACA,MAAM,aAAa,iBAAiB;GACnC,OAAO,MAAM,QAAQ;EACtB;CACD;AACD;AAEA,SAAgB,wBAAwB;CACvC,MAAM,QAA6B,EAClC,OAAO,EAAE,SAAS,CAAC,EAAE,EACtB;CAMA,OAAO,OAAO,OACb,OAAO,KAAkB,SAAuB;EAC/C,MAAM,MAAM,WAAW,GAAa;EACpC,IAAI,QAAQ,YACX,OAAO,IAAI,EAAE,SACZ,KAAK,UAAU;GACd,KAAK;GACL,SAAS;EACV,CAAC,CACF;EAED,IAAI,QAAQ,cACX,OAAO,IAAI,EAAE,SACZ,KAAK,UAAU,EACd,SAAS,CAAC,kCAAkC,EAC7C,CAAC,CACF;EAGD,IAAI,IAAI,WAAW,YAAY,GAAG;GACjC,MAAM,KAAK,mBAAmB,KAAK,GAAG,CAAC,CAAE;GACzC,MAAM,EAAE,aAAa,KAAK,MAAM,KAAK,EAAE,CAAC;GACxC,IAAI,QAAQ,KAAK,WAAW,QAAQ;IACnC,MAAM,YAAY,KAAK,MAAM,KAAK,IAAc;IAChD,OAAO,IAAI,EAAE,SAAS,KAAA,CAAS;GAChC;GACA,IAAI,MAAM,WAAW,OAAO,IAAI,EAAE,SAAS,KAAK,UAAU,MAAM,SAAS,CAAC;GAC1E,OAAO,IAAI,EAAE,SAAS,KAAA,GAAW,EAAE,QAAQ,IAAI,CAAC;EACjD;;EAEA,QAAQ,MAAM,GAAG;;EAEjB,OAAO,IAAI,EAAE,SAAS,KAAA,GAAW,EAAE,QAAQ,IAAI,CAAC;CACjD,GACA;EACC;EACA,WAAA,EAvCD,OAAO,EAAE,UAAU,QAAQ,EAuClB;CACT,CACD;AACD;AAEA,SAAS,WAAW,KAAa;CAChC,MAAM,QAAQ,2BAA2B,KAAK,GAAG;;CAEjD,IAAI,CAAC,OAAO,MAAM;CAClB,OAAO,MAAM;AACd"}
|
package/esm/io.types.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Log } from "@mocktomata/framework";
|
|
2
|
+
//#region ts/io.types.d.ts
|
|
2
3
|
export type ServiceOptions = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* URL to the mocktomata service.
|
|
6
|
+
*/
|
|
7
|
+
url: string;
|
|
7
8
|
};
|
|
8
9
|
export type IOOptions = ServiceOptions & Log.Context;
|
|
10
|
+
//#endregion
|
|
9
11
|
//# sourceMappingURL=io.types.d.ts.map
|
package/esm/io.types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.types.d.ts","
|
|
1
|
+
{"version":3,"file":"io.types.d.ts","names":[],"sources":["../ts/io.types.ts"],"mappings":";;YAEY;;;;EAIX;;YAGW,YAAY,iBAAiB,IAAI"}
|
package/esm/io.types.js
CHANGED
package/esm/platform.d.ts
CHANGED
package/esm/platform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","
|
|
1
|
+
{"version":3,"file":"platform.d.ts","names":[],"sources":["../ts/platform.ts"],"mappings":";wBAAgB,aAAa,0BAAuB"}
|
package/esm/platform.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region ts/platform.ts
|
|
2
|
+
function importModule(moduleSpecifier) {
|
|
3
|
+
return import(moduleSpecifier);
|
|
3
4
|
}
|
|
5
|
+
//#endregion
|
|
6
|
+
export { importModule };
|
|
7
|
+
|
|
4
8
|
//# sourceMappingURL=platform.js.map
|
package/esm/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","
|
|
1
|
+
{"version":3,"file":"platform.js","names":[],"sources":["../ts/platform.ts"],"sourcesContent":["export function importModule(moduleSpecifier: string) {\n\treturn import(moduleSpecifier)\n}\n"],"mappings":";AAAA,SAAgB,aAAa,iBAAyB;CACrD,OAAO,OAAO;AACf"}
|
package/esm/server_info.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { ServiceOptions } from "./io.types.js";
|
|
2
|
+
import { Context } from "./io.internal.js";
|
|
3
|
+
//#region ts/server_info.d.ts
|
|
3
4
|
export type ServerInfo = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
url: string;
|
|
8
|
+
plugins?: string[];
|
|
8
9
|
};
|
|
9
10
|
export declare function getServerInfo({ fetch }: Pick<Context, 'fetch'>, { url }: ServiceOptions): Promise<ServerInfo>;
|
|
11
|
+
//#endregion
|
|
10
12
|
//# sourceMappingURL=server_info.d.ts.map
|
package/esm/server_info.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server_info.d.ts","
|
|
1
|
+
{"version":3,"file":"server_info.d.ts","names":[],"sources":["../ts/server_info.ts"],"mappings":";;;YAKY;EACX;EACA;EACA;EAEA;;wBAGqB,gBAAgB,SAAS,KAAK,qBAAqB,OAAO,iBAAiB,QAAQ"}
|
package/esm/server_info.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { ServiceNotAvailable } from
|
|
2
|
-
import { buildUrl } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
1
|
+
import { ServiceNotAvailable } from "./errors.js";
|
|
2
|
+
import { buildUrl } from "./url.js";
|
|
3
|
+
//#region ts/server_info.ts
|
|
4
|
+
async function getServerInfo({ fetch }, { url }) {
|
|
5
|
+
try {
|
|
6
|
+
return (await fetch(buildUrl(url, "info"))).json();
|
|
7
|
+
} catch (e) {
|
|
8
|
+
throw e.code === "ECONNREFUSED" ? new ServiceNotAvailable(url) : e;
|
|
9
|
+
}
|
|
11
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getServerInfo };
|
|
13
|
+
|
|
12
14
|
//# sourceMappingURL=server_info.js.map
|
package/esm/server_info.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server_info.js","
|
|
1
|
+
{"version":3,"file":"server_info.js","names":[],"sources":["../ts/server_info.ts"],"sourcesContent":["import { ServiceNotAvailable } from './errors.js'\nimport type { Context } from './io.internal.js'\nimport type { ServiceOptions } from './io.types.js'\nimport { buildUrl } from './url.js'\n\nexport type ServerInfo = {\n\tname: string\n\tversion: string\n\turl: string\n\t// TODO: server not returning plugins\n\tplugins?: string[]\n}\n\nexport async function getServerInfo({ fetch }: Pick<Context, 'fetch'>, { url }: ServiceOptions): Promise<ServerInfo> {\n\ttry {\n\t\tconst response = await fetch(buildUrl(url, 'info'))\n\t\treturn response.json()\n\t} catch (e: any) {\n\t\tthrow e.code === 'ECONNREFUSED' ? new ServiceNotAvailable(url) : e\n\t}\n}\n"],"mappings":";;;AAaA,eAAsB,cAAc,EAAE,SAAiC,EAAE,OAA4C;CACpH,IAAI;EAEH,QAAO,MADgB,MAAM,SAAS,KAAK,MAAM,CAAC,EAAA,CAClC,KAAK;CACtB,SAAS,GAAQ;EAChB,MAAM,EAAE,SAAS,iBAAiB,IAAI,oBAAoB,GAAG,IAAI;CAClE;AACD"}
|
package/esm/url.d.ts
CHANGED
package/esm/url.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","
|
|
1
|
+
{"version":3,"file":"url.d.ts","names":[],"sources":["../ts/url.ts"],"mappings":";wBAAgB,SAAS,iBAAiB"}
|
package/esm/url.js
CHANGED
package/esm/url.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.js","
|
|
1
|
+
{"version":3,"file":"url.js","names":[],"sources":["../ts/url.ts"],"sourcesContent":["export function buildUrl(urlBase: string, path: string) {\n\treturn `${urlBase}/api/${path}`\n}\n"],"mappings":";AAAA,SAAgB,SAAS,SAAiB,MAAc;CACvD,OAAO,GAAG,QAAQ,OAAO;AAC1B"}
|