@gravitee/gamma-modules-sdk 1.0.0-alpha.2-feat-dev-mock-middleware.89c1bf9 → 1.0.0-alpha.2-feat-dev-mock-middleware.da494cc
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/dev.d.ts +0 -10
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +12 -50
- package/package.json +1 -1
package/dist/dev.d.ts
CHANGED
|
@@ -9,14 +9,6 @@ export interface OpenApiMockOptions {
|
|
|
9
9
|
orgId?: string;
|
|
10
10
|
envId?: string;
|
|
11
11
|
}
|
|
12
|
-
/** @deprecated Use createOpenApiMockMiddleware instead. */
|
|
13
|
-
export interface DevMockMiddlewareOptions {
|
|
14
|
-
moduleId: string;
|
|
15
|
-
fixturesDir: string;
|
|
16
|
-
routes: Record<string, string>;
|
|
17
|
-
orgId?: string;
|
|
18
|
-
envId?: string;
|
|
19
|
-
}
|
|
20
12
|
/**
|
|
21
13
|
* Creates a Connect-compatible middleware that reads OpenAPI specs and serves
|
|
22
14
|
* mock responses for all declared paths. Fixtures override spec examples.
|
|
@@ -33,6 +25,4 @@ export interface DevMockMiddlewareOptions {
|
|
|
33
25
|
* ```
|
|
34
26
|
*/
|
|
35
27
|
export declare function createOpenApiMockMiddleware(options: OpenApiMockOptions): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
|
36
|
-
/** @deprecated Use createOpenApiMockMiddleware instead. */
|
|
37
|
-
export declare function createDevMockMiddleware(options: DevMockMiddlewareOptions): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
|
38
28
|
//# sourceMappingURL=dev.d.ts.map
|
package/dist/dev.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAM5D,MAAM,WAAW,kBAAkB;IACjC,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,uGAAuG;IACvG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAM5D,MAAM,WAAW,kBAAkB;IACjC,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,uGAAuG;IACvG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,kBAAkB,IAM7D,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,MAAM,IAAI,UAkFpE"}
|
package/dist/dev.js
CHANGED
|
@@ -3934,7 +3934,7 @@ function Xn(e, t, n) {
|
|
|
3934
3934
|
//#endregion
|
|
3935
3935
|
//#region src/dev.ts
|
|
3936
3936
|
function Zn(e) {
|
|
3937
|
-
let { specs: t, fixturesDir: n, orgId: r = "DEFAULT" } = e, i =
|
|
3937
|
+
let { specs: t, fixturesDir: n, orgId: r = "DEFAULT" } = e, i = er(t);
|
|
3938
3938
|
return (e, t, a) => {
|
|
3939
3939
|
let { pathname: o, searchParams: s } = new URL(e.url ?? "/", `http://${e.headers.host}`), c = (e.method ?? "GET").toLowerCase();
|
|
3940
3940
|
if (o === "/gamma/ui/bootstrap") {
|
|
@@ -3948,7 +3948,7 @@ function Zn(e) {
|
|
|
3948
3948
|
a();
|
|
3949
3949
|
return;
|
|
3950
3950
|
}
|
|
3951
|
-
let l =
|
|
3951
|
+
let l = tr(i, o.slice(6), c);
|
|
3952
3952
|
if (!l) {
|
|
3953
3953
|
a();
|
|
3954
3954
|
return;
|
|
@@ -3959,7 +3959,7 @@ function Zn(e) {
|
|
|
3959
3959
|
return;
|
|
3960
3960
|
}
|
|
3961
3961
|
if (c === "post" || c === "put") {
|
|
3962
|
-
|
|
3962
|
+
$n(e, (e) => {
|
|
3963
3963
|
$(t, {
|
|
3964
3964
|
id: crypto.randomUUID(),
|
|
3965
3965
|
...e,
|
|
@@ -3969,16 +3969,16 @@ function Zn(e) {
|
|
|
3969
3969
|
});
|
|
3970
3970
|
return;
|
|
3971
3971
|
}
|
|
3972
|
-
let f = "id" in d, p =
|
|
3972
|
+
let f = "id" in d, p = nr(u.specPath, n), m = d.id && u.specPath.includes("{id}/") ? d.id : void 0;
|
|
3973
3973
|
if (f && !m) {
|
|
3974
|
-
let e =
|
|
3974
|
+
let e = Qn(p).find((e) => e.id === d.id);
|
|
3975
3975
|
e ? $(t, e) : $(t, {
|
|
3976
3976
|
code: "NOT_FOUND",
|
|
3977
3977
|
message: "Not found"
|
|
3978
3978
|
}, 404);
|
|
3979
3979
|
return;
|
|
3980
3980
|
}
|
|
3981
|
-
let h =
|
|
3981
|
+
let h = Qn(p), g = m ? h.filter((e) => e.parentId === m) : h, _ = (s.get("q") ?? "").trim().toLowerCase();
|
|
3982
3982
|
_ && (g = g.filter((e) => JSON.stringify(e.definition ?? e).toLowerCase().includes(_)));
|
|
3983
3983
|
let v = Number(s.get("page")) || 1, y = Number(s.get("perPage")) || 20, b = (v - 1) * y;
|
|
3984
3984
|
$(t, {
|
|
@@ -3991,55 +3991,17 @@ function Zn(e) {
|
|
|
3991
3991
|
});
|
|
3992
3992
|
};
|
|
3993
3993
|
}
|
|
3994
|
-
function Qn(e) {
|
|
3995
|
-
let { moduleId: n, fixturesDir: r, routes: i, orgId: a = "DEFAULT", envId: o = "DEFAULT" } = e, s = `/gamma/organizations/${a}/environments/${o}/modules/${n}/catalog`;
|
|
3996
|
-
return (e, n, o) => {
|
|
3997
|
-
let { pathname: c, searchParams: l } = new URL(e.url ?? "/", `http://${e.headers.host}`);
|
|
3998
|
-
if (c === "/gamma/ui/bootstrap") {
|
|
3999
|
-
$(n, {
|
|
4000
|
-
gammaBaseURL: "/gamma",
|
|
4001
|
-
organizationId: a
|
|
4002
|
-
});
|
|
4003
|
-
return;
|
|
4004
|
-
}
|
|
4005
|
-
if (!c.startsWith(s)) {
|
|
4006
|
-
o();
|
|
4007
|
-
return;
|
|
4008
|
-
}
|
|
4009
|
-
let u = c.slice(s.length), d = i[u];
|
|
4010
|
-
if (d) {
|
|
4011
|
-
let e = Number(l.get("page")) || 1, i = Number(l.get("perPage")) || 25, a = (l.get("q") ?? "").trim().toLowerCase(), o = $n(t(r, d));
|
|
4012
|
-
a && (o = o.filter((e) => JSON.stringify(e.definition ?? e).toLowerCase().includes(a)));
|
|
4013
|
-
let s = (e - 1) * i;
|
|
4014
|
-
$(n, {
|
|
4015
|
-
data: o.slice(s, s + i),
|
|
4016
|
-
pagination: {
|
|
4017
|
-
page: e,
|
|
4018
|
-
perPage: i,
|
|
4019
|
-
totalCount: o.length
|
|
4020
|
-
}
|
|
4021
|
-
});
|
|
4022
|
-
return;
|
|
4023
|
-
}
|
|
4024
|
-
for (let [e, a] of Object.entries(i)) if (u.startsWith(e + "/")) {
|
|
4025
|
-
let i = u.slice(e.length + 1), o = $n(t(r, a)).find((e) => e.id === i);
|
|
4026
|
-
o ? $(n, o) : $(n, { error: "Not found" }, 404);
|
|
4027
|
-
return;
|
|
4028
|
-
}
|
|
4029
|
-
$(n, { error: "Not found" }, 404);
|
|
4030
|
-
};
|
|
4031
|
-
}
|
|
4032
3994
|
function $(e, t, n = 200) {
|
|
4033
3995
|
e.writeHead(n, { "Content-Type": "application/json" }), e.end(JSON.stringify(t));
|
|
4034
3996
|
}
|
|
4035
|
-
function
|
|
3997
|
+
function Qn(t) {
|
|
4036
3998
|
try {
|
|
4037
3999
|
return JSON.parse(e(t, "utf-8"));
|
|
4038
4000
|
} catch {
|
|
4039
4001
|
return [];
|
|
4040
4002
|
}
|
|
4041
4003
|
}
|
|
4042
|
-
function
|
|
4004
|
+
function $n(e, t) {
|
|
4043
4005
|
let n = [];
|
|
4044
4006
|
e.on("data", (e) => n.push(e)), e.on("end", () => {
|
|
4045
4007
|
try {
|
|
@@ -4049,7 +4011,7 @@ function er(e, t) {
|
|
|
4049
4011
|
}
|
|
4050
4012
|
});
|
|
4051
4013
|
}
|
|
4052
|
-
function
|
|
4014
|
+
function er(t) {
|
|
4053
4015
|
let n = [];
|
|
4054
4016
|
for (let r of t) {
|
|
4055
4017
|
let t = e(r, "utf-8"), i = (r.endsWith(".json") ? JSON.parse(t) : Xn(t)).paths ?? {};
|
|
@@ -4070,7 +4032,7 @@ function tr(t) {
|
|
|
4070
4032
|
}
|
|
4071
4033
|
return n.sort((e, t) => t.segments.length - e.segments.length), n;
|
|
4072
4034
|
}
|
|
4073
|
-
function
|
|
4035
|
+
function tr(e, t, n) {
|
|
4074
4036
|
let r = t.split("/").filter(Boolean);
|
|
4075
4037
|
for (let t of e) {
|
|
4076
4038
|
if (t.segments.length !== r.length || !t.methods.includes(n)) continue;
|
|
@@ -4090,7 +4052,7 @@ function nr(e, t, n) {
|
|
|
4090
4052
|
}
|
|
4091
4053
|
return null;
|
|
4092
4054
|
}
|
|
4093
|
-
function
|
|
4055
|
+
function nr(e, n) {
|
|
4094
4056
|
if (!n) return "";
|
|
4095
4057
|
let r = e.split("/").filter((e) => e && !e.startsWith("{")), i = r[r.length - 1], a = r[r.length - 2], o = i;
|
|
4096
4058
|
return a && [
|
|
@@ -4100,4 +4062,4 @@ function rr(e, n) {
|
|
|
4100
4062
|
].includes(i) && (o = `mcp-${i}`), t(n, `${o}.json`);
|
|
4101
4063
|
}
|
|
4102
4064
|
//#endregion
|
|
4103
|
-
export {
|
|
4065
|
+
export { Zn as createOpenApiMockMiddleware };
|
package/package.json
CHANGED