@schmock/cli 1.9.2 → 1.9.5
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/dist/bin.js +27 -8
- package/dist/index.js +27 -8
- package/package.json +3 -3
package/dist/bin.js
CHANGED
|
@@ -5,15 +5,29 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
function __accessProp(key) {
|
|
9
|
+
return this[key];
|
|
10
|
+
}
|
|
11
|
+
var __toESMCache_node;
|
|
12
|
+
var __toESMCache_esm;
|
|
8
13
|
var __toESM = (mod, isNodeMode, target) => {
|
|
14
|
+
var canCache = mod != null && typeof mod === "object";
|
|
15
|
+
if (canCache) {
|
|
16
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
17
|
+
var cached = cache.get(mod);
|
|
18
|
+
if (cached)
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
9
21
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
22
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
23
|
for (let key of __getOwnPropNames(mod))
|
|
12
24
|
if (!__hasOwnProp.call(to, key))
|
|
13
25
|
__defProp(to, key, {
|
|
14
|
-
get: (
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
15
27
|
enumerable: true
|
|
16
28
|
});
|
|
29
|
+
if (canCache)
|
|
30
|
+
cache.set(mod, to);
|
|
17
31
|
return to;
|
|
18
32
|
};
|
|
19
33
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
@@ -23172,7 +23186,7 @@ var require_ajv = __commonJS((exports, module) => {
|
|
|
23172
23186
|
});
|
|
23173
23187
|
|
|
23174
23188
|
// src/cli.ts
|
|
23175
|
-
import { readFileSync
|
|
23189
|
+
import { readFileSync, watch } from "node:fs";
|
|
23176
23190
|
import { createServer as createServer2 } from "node:http";
|
|
23177
23191
|
import { parseArgs } from "node:util";
|
|
23178
23192
|
|
|
@@ -23926,7 +23940,7 @@ function schmock(config) {
|
|
|
23926
23940
|
return callableInstance;
|
|
23927
23941
|
}
|
|
23928
23942
|
// ../openapi/package.json
|
|
23929
|
-
var version = "1.9.
|
|
23943
|
+
var version = "1.9.5";
|
|
23930
23944
|
|
|
23931
23945
|
// ../openapi/src/utils.ts
|
|
23932
23946
|
function isRecord(value) {
|
|
@@ -33325,7 +33339,12 @@ async function parseSpec(source) {
|
|
|
33325
33339
|
const copy = structuredClone(source);
|
|
33326
33340
|
stripRootExtensions(copy);
|
|
33327
33341
|
ensurePathsKey(copy);
|
|
33328
|
-
|
|
33342
|
+
const hasRefs = JSON.stringify(copy).includes('"$ref"');
|
|
33343
|
+
if (hasRefs) {
|
|
33344
|
+
api = await import_swagger_parser.default.dereference(copy);
|
|
33345
|
+
} else {
|
|
33346
|
+
api = copy;
|
|
33347
|
+
}
|
|
33329
33348
|
} else {
|
|
33330
33349
|
throw new Error("Invalid OpenAPI spec: must be a string path or an OpenAPI document object");
|
|
33331
33350
|
}
|
|
@@ -33928,14 +33947,14 @@ function generateResponseBody(schema, seed) {
|
|
|
33928
33947
|
}
|
|
33929
33948
|
|
|
33930
33949
|
// ../openapi/src/seed.ts
|
|
33931
|
-
|
|
33932
|
-
function loadSeed(config, resources) {
|
|
33950
|
+
async function loadSeed(config, resources) {
|
|
33933
33951
|
const result = new Map;
|
|
33934
33952
|
for (const [resourceName, source] of Object.entries(config)) {
|
|
33935
33953
|
const resource = resources.find((r2) => r2.name === resourceName);
|
|
33936
33954
|
if (Array.isArray(source)) {
|
|
33937
33955
|
result.set(resourceName, [...source]);
|
|
33938
33956
|
} else if (typeof source === "string") {
|
|
33957
|
+
const { readFileSync } = await import("node:fs");
|
|
33939
33958
|
const content = readFileSync(source, "utf-8");
|
|
33940
33959
|
let parsed;
|
|
33941
33960
|
try {
|
|
@@ -33966,7 +33985,7 @@ function loadSeed(config, resources) {
|
|
|
33966
33985
|
async function openapi(options) {
|
|
33967
33986
|
const spec = await parseSpec(options.spec);
|
|
33968
33987
|
const { resources, nonCrudPaths } = detectCrudResources(spec.paths);
|
|
33969
|
-
const seedData = options.seed ? loadSeed(options.seed, resources) : new Map;
|
|
33988
|
+
const seedData = options.seed ? await loadSeed(options.seed, resources) : new Map;
|
|
33970
33989
|
const allParsedPaths = new Map;
|
|
33971
33990
|
for (const pp of [...spec.paths]) {
|
|
33972
33991
|
allParsedPaths.set(`${pp.method} ${pp.path}`, pp);
|
|
@@ -34026,7 +34045,7 @@ function isSeedSource(value) {
|
|
|
34026
34045
|
return Array.isArray(value) || typeof value === "string" || typeof value === "object" && value !== null && "count" in value;
|
|
34027
34046
|
}
|
|
34028
34047
|
function loadSeedFile(seedPath) {
|
|
34029
|
-
const raw =
|
|
34048
|
+
const raw = readFileSync(seedPath, "utf-8");
|
|
34030
34049
|
const parsed = JSON.parse(raw);
|
|
34031
34050
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
34032
34051
|
throw new Error(`Seed file must contain a JSON object, got: ${typeof parsed}`);
|
package/dist/index.js
CHANGED
|
@@ -4,15 +4,29 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
7
12
|
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
8
20
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
21
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
22
|
for (let key of __getOwnPropNames(mod))
|
|
11
23
|
if (!__hasOwnProp.call(to, key))
|
|
12
24
|
__defProp(to, key, {
|
|
13
|
-
get: (
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
14
26
|
enumerable: true
|
|
15
27
|
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
16
30
|
return to;
|
|
17
31
|
};
|
|
18
32
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
@@ -23171,7 +23185,7 @@ var require_ajv = __commonJS((exports, module) => {
|
|
|
23171
23185
|
});
|
|
23172
23186
|
|
|
23173
23187
|
// src/cli.ts
|
|
23174
|
-
import { readFileSync
|
|
23188
|
+
import { readFileSync, watch } from "node:fs";
|
|
23175
23189
|
import { createServer as createServer2 } from "node:http";
|
|
23176
23190
|
import { parseArgs } from "node:util";
|
|
23177
23191
|
|
|
@@ -23925,7 +23939,7 @@ function schmock(config) {
|
|
|
23925
23939
|
return callableInstance;
|
|
23926
23940
|
}
|
|
23927
23941
|
// ../openapi/package.json
|
|
23928
|
-
var version = "1.9.
|
|
23942
|
+
var version = "1.9.5";
|
|
23929
23943
|
|
|
23930
23944
|
// ../openapi/src/utils.ts
|
|
23931
23945
|
function isRecord(value) {
|
|
@@ -33324,7 +33338,12 @@ async function parseSpec(source) {
|
|
|
33324
33338
|
const copy = structuredClone(source);
|
|
33325
33339
|
stripRootExtensions(copy);
|
|
33326
33340
|
ensurePathsKey(copy);
|
|
33327
|
-
|
|
33341
|
+
const hasRefs = JSON.stringify(copy).includes('"$ref"');
|
|
33342
|
+
if (hasRefs) {
|
|
33343
|
+
api = await import_swagger_parser.default.dereference(copy);
|
|
33344
|
+
} else {
|
|
33345
|
+
api = copy;
|
|
33346
|
+
}
|
|
33328
33347
|
} else {
|
|
33329
33348
|
throw new Error("Invalid OpenAPI spec: must be a string path or an OpenAPI document object");
|
|
33330
33349
|
}
|
|
@@ -33927,14 +33946,14 @@ function generateResponseBody(schema, seed) {
|
|
|
33927
33946
|
}
|
|
33928
33947
|
|
|
33929
33948
|
// ../openapi/src/seed.ts
|
|
33930
|
-
|
|
33931
|
-
function loadSeed(config, resources) {
|
|
33949
|
+
async function loadSeed(config, resources) {
|
|
33932
33950
|
const result = new Map;
|
|
33933
33951
|
for (const [resourceName, source] of Object.entries(config)) {
|
|
33934
33952
|
const resource = resources.find((r2) => r2.name === resourceName);
|
|
33935
33953
|
if (Array.isArray(source)) {
|
|
33936
33954
|
result.set(resourceName, [...source]);
|
|
33937
33955
|
} else if (typeof source === "string") {
|
|
33956
|
+
const { readFileSync } = await import("node:fs");
|
|
33938
33957
|
const content = readFileSync(source, "utf-8");
|
|
33939
33958
|
let parsed;
|
|
33940
33959
|
try {
|
|
@@ -33965,7 +33984,7 @@ function loadSeed(config, resources) {
|
|
|
33965
33984
|
async function openapi(options) {
|
|
33966
33985
|
const spec = await parseSpec(options.spec);
|
|
33967
33986
|
const { resources, nonCrudPaths } = detectCrudResources(spec.paths);
|
|
33968
|
-
const seedData = options.seed ? loadSeed(options.seed, resources) : new Map;
|
|
33987
|
+
const seedData = options.seed ? await loadSeed(options.seed, resources) : new Map;
|
|
33969
33988
|
const allParsedPaths = new Map;
|
|
33970
33989
|
for (const pp of [...spec.paths]) {
|
|
33971
33990
|
allParsedPaths.set(`${pp.method} ${pp.path}`, pp);
|
|
@@ -34025,7 +34044,7 @@ function isSeedSource(value) {
|
|
|
34025
34044
|
return Array.isArray(value) || typeof value === "string" || typeof value === "object" && value !== null && "count" in value;
|
|
34026
34045
|
}
|
|
34027
34046
|
function loadSeedFile(seedPath) {
|
|
34028
|
-
const raw =
|
|
34047
|
+
const raw = readFileSync(seedPath, "utf-8");
|
|
34029
34048
|
const parsed = JSON.parse(raw);
|
|
34030
34049
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
34031
34050
|
throw new Error(`Seed file must contain a JSON object, got: ${typeof parsed}`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schmock/cli",
|
|
3
3
|
"description": "CLI for running Schmock mock servers from OpenAPI specs",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@schmock/core": "^1.9.
|
|
36
|
-
"@schmock/openapi": "^1.9.
|
|
35
|
+
"@schmock/core": "^1.9.5",
|
|
36
|
+
"@schmock/openapi": "^1.9.5"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@amiceli/vitest-cucumber": "^6.2.0",
|