@apilift/cli 1.8.4 → 1.8.5-dev.1793874283.5437ac7adf07f08697e7a937255d5a5084b0b25d
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/apilift.js
CHANGED
|
@@ -42422,6 +42422,26 @@ var init_credentials2 = __esm({
|
|
|
42422
42422
|
// src/discovery/api-observation.ts
|
|
42423
42423
|
import { createHash as createHash9 } from "node:crypto";
|
|
42424
42424
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
42425
|
+
function observationValidators(schema, name, property) {
|
|
42426
|
+
const signature = canonicalJson(schema);
|
|
42427
|
+
let compiler = inputCompilers.get(schema);
|
|
42428
|
+
if (!compiler || compiler.signature !== signature) {
|
|
42429
|
+
const ajv6 = new import__5.default({ strict: false, validateFormats: true });
|
|
42430
|
+
(0, import_ajv_formats2.default)(ajv6);
|
|
42431
|
+
compiler = { signature, ajv: ajv6, validators: /* @__PURE__ */ new Map() };
|
|
42432
|
+
inputCompilers.set(schema, compiler);
|
|
42433
|
+
}
|
|
42434
|
+
let compiled = compiler.validators.get(name);
|
|
42435
|
+
if (!compiled) {
|
|
42436
|
+
const shared = { ...object5(schema.$defs) ? { $defs: schema.$defs } : {}, ...object5(schema.definitions) ? { definitions: schema.definitions } : {} };
|
|
42437
|
+
compiled = {
|
|
42438
|
+
validate: compiler.ajv.compile({ ...shared, ...property }),
|
|
42439
|
+
...property.contentMediaType === "application/json" && object5(property.contentSchema) ? { content: compiler.ajv.compile({ ...shared, ...property.contentSchema }) } : {}
|
|
42440
|
+
};
|
|
42441
|
+
compiler.validators.set(name, compiled);
|
|
42442
|
+
}
|
|
42443
|
+
return compiled;
|
|
42444
|
+
}
|
|
42425
42445
|
function compileObservation(raw, definition2, load2) {
|
|
42426
42446
|
if (!object5(raw) || typeof raw.file !== "string" || !raw.file || Object.keys(raw).some((k) => !["file", "path", "unordered", "unorderedAt", "sha256"].includes(k))) throw Error("Observation needs file and optional path, unordered, unorderedAt and sha256");
|
|
42427
42447
|
if (raw.path !== void 0 && typeof raw.path !== "string" || raw.unordered !== void 0 && typeof raw.unordered !== "boolean") throw Error("Observation path must be a JSON Pointer and unordered a boolean");
|
|
@@ -42438,13 +42458,11 @@ function compileObservation(raw, definition2, load2) {
|
|
|
42438
42458
|
if (!object5(record3) || record3.method !== request2.method || typeof record3.path !== "string" || !object5(record3.query) || !Number.isInteger(record3.status) || Number(record3.status) < 200 || Number(record3.status) >= 300 || !Object.hasOwn(record3, "body")) throw Error("Observation needs the matching method, path, query, successful status and body");
|
|
42439
42459
|
const schema = object5(definition2.inputs) ? definition2.inputs : { type: "object", properties: {} };
|
|
42440
42460
|
const properties = object5(schema.properties) ? schema.properties : {};
|
|
42441
|
-
const ajv6 = new import__5.default({ strict: false, validateFormats: true });
|
|
42442
|
-
(0, import_ajv_formats2.default)(ajv6);
|
|
42443
42461
|
const inputs = {};
|
|
42444
42462
|
const input2 = (name, value2, encoding) => {
|
|
42445
42463
|
const property = properties[name];
|
|
42446
42464
|
if (!object5(property)) throw Error(`Observed input ${name} has no schema`);
|
|
42447
|
-
const
|
|
42465
|
+
const { validate: validate2, content } = observationValidators(schema, name, property);
|
|
42448
42466
|
const candidates = [value2];
|
|
42449
42467
|
if (typeof value2 === "string") {
|
|
42450
42468
|
if (["json", "json-content"].includes(String(encoding))) {
|
|
@@ -42457,7 +42475,6 @@ function compileObservation(raw, definition2, load2) {
|
|
|
42457
42475
|
if (/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/u.test(value2)) candidates.push(Number(value2));
|
|
42458
42476
|
if (value2 === "true" || value2 === "false") candidates.push(value2 === "true");
|
|
42459
42477
|
}
|
|
42460
|
-
const content = property.contentMediaType === "application/json" && object5(property.contentSchema) ? ajv6.compile({ ...object5(schema.$defs) ? { $defs: schema.$defs } : {}, ...object5(schema.definitions) ? { definitions: schema.definitions } : {}, ...property.contentSchema }) : void 0;
|
|
42461
42478
|
const matching = candidates.filter((candidate2) => {
|
|
42462
42479
|
if (!validate2(candidate2)) return false;
|
|
42463
42480
|
if (content && typeof candidate2 === "string") {
|
|
@@ -42518,13 +42535,15 @@ function jsonObservationCases(definition2, compiled) {
|
|
|
42518
42535
|
}
|
|
42519
42536
|
return variants;
|
|
42520
42537
|
}
|
|
42521
|
-
var import__5, import_ajv_formats2, object5, pointer5;
|
|
42538
|
+
var import__5, import_ajv_formats2, object5, inputCompilers, pointer5;
|
|
42522
42539
|
var init_api_observation = __esm({
|
|
42523
42540
|
"src/discovery/api-observation.ts"() {
|
|
42524
42541
|
"use strict";
|
|
42525
42542
|
import__5 = __toESM(require__(), 1);
|
|
42526
42543
|
import_ajv_formats2 = __toESM(require_dist(), 1);
|
|
42544
|
+
init_json();
|
|
42527
42545
|
object5 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
42546
|
+
inputCompilers = /* @__PURE__ */ new WeakMap();
|
|
42528
42547
|
pointer5 = (root2, path2) => {
|
|
42529
42548
|
if (path2 !== "" && (!path2.startsWith("/") || /~(?![01])/u.test(path2))) throw Error("Observation projection must be a JSON Pointer");
|
|
42530
42549
|
let value = root2;
|
|
@@ -46761,9 +46780,24 @@ var init_response_examples = __esm({
|
|
|
46761
46780
|
|
|
46762
46781
|
// src/discovery/input-coverage.ts
|
|
46763
46782
|
import { isDeepStrictEqual as isDeepStrictEqual6 } from "node:util";
|
|
46783
|
+
function rememberCompilation(key, valid2) {
|
|
46784
|
+
if (key === void 0) return;
|
|
46785
|
+
if (documentedCompilations.size >= 32) documentedCompilations.delete(documentedCompilations.keys().next().value);
|
|
46786
|
+
documentedCompilations.set(key, valid2);
|
|
46787
|
+
}
|
|
46764
46788
|
function inputCoverageIssues(schema, successfulInputs, policy = "observed") {
|
|
46765
46789
|
if (!object26(schema)) return [];
|
|
46766
46790
|
const issues = [];
|
|
46791
|
+
let compilationKey;
|
|
46792
|
+
if (policy === "documented") {
|
|
46793
|
+
try {
|
|
46794
|
+
const key = canonicalJson(schema);
|
|
46795
|
+
if (Buffer.byteLength(key) <= 64 * 1024) compilationKey = key;
|
|
46796
|
+
} catch {
|
|
46797
|
+
}
|
|
46798
|
+
const compiled = compilationKey === void 0 ? void 0 : documentedCompilations.get(compilationKey);
|
|
46799
|
+
if (compiled !== void 0) return compiled ? [] : compilationIssues();
|
|
46800
|
+
}
|
|
46767
46801
|
const ajv6 = new import__14.default({ strict: false, allErrors: false, validateFormats: true });
|
|
46768
46802
|
(0, import_ajv_formats11.default)(ajv6);
|
|
46769
46803
|
const root2 = { ...schema };
|
|
@@ -46777,9 +46811,13 @@ function inputCoverageIssues(schema, successfulInputs, policy = "observed") {
|
|
|
46777
46811
|
ajv6.addSchema({ ...references2(root2), $id: rootId }, rootId);
|
|
46778
46812
|
ajv6.getSchema(rootId);
|
|
46779
46813
|
} catch {
|
|
46780
|
-
|
|
46814
|
+
rememberCompilation(compilationKey, false);
|
|
46815
|
+
return compilationIssues();
|
|
46816
|
+
}
|
|
46817
|
+
if (policy === "documented") {
|
|
46818
|
+
rememberCompilation(compilationKey, true);
|
|
46819
|
+
return [];
|
|
46781
46820
|
}
|
|
46782
|
-
if (policy === "documented") return [];
|
|
46783
46821
|
const validators = /* @__PURE__ */ new Map();
|
|
46784
46822
|
const valid2 = (candidate2, value) => {
|
|
46785
46823
|
try {
|
|
@@ -46917,7 +46955,7 @@ function inputCoverageIssues(schema, successfulInputs, policy = "observed") {
|
|
|
46917
46955
|
walk(root2, examples, "/definition/inputs", /* @__PURE__ */ new Set(), 0);
|
|
46918
46956
|
return issues;
|
|
46919
46957
|
}
|
|
46920
|
-
var import__14, import_ajv_formats11, object26, escape5;
|
|
46958
|
+
var import__14, import_ajv_formats11, object26, escape5, documentedCompilations, compilationIssues;
|
|
46921
46959
|
var init_input_coverage = __esm({
|
|
46922
46960
|
"src/discovery/input-coverage.ts"() {
|
|
46923
46961
|
"use strict";
|
|
@@ -46926,6 +46964,8 @@ var init_input_coverage = __esm({
|
|
|
46926
46964
|
import_ajv_formats11 = __toESM(require_dist(), 1);
|
|
46927
46965
|
object26 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
46928
46966
|
escape5 = (value) => value.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
46967
|
+
documentedCompilations = /* @__PURE__ */ new Map();
|
|
46968
|
+
compilationIssues = () => [{ path: "/definition/inputs", message: "Input evidence cannot be checked until the input schema compiles" }];
|
|
46929
46969
|
}
|
|
46930
46970
|
});
|
|
46931
46971
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apilift/cli",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.5-dev.1793874283.5437ac7adf07f08697e7a937255d5a5084b0b25d",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=24.16.0 <27"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "5437ac7adf07f08697e7a937255d5a5084b0b25d",
|
|
41
41
|
"repository": {
|
|
42
42
|
"type": "git",
|
|
43
43
|
"url": "git+https://github.com/egor-sergeev/apilift.git",
|