@scalar/blocks 0.5.0 → 0.5.2
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/CHANGELOG.md +20 -0
- package/dist/code-example/components/CodeExample.vue.d.ts +2 -0
- package/dist/code-example/components/CodeExample.vue.d.ts.map +1 -1
- package/dist/code-example/components/CodeExample.vue.js +1 -1
- package/dist/code-example/components/CodeExample.vue.js.map +1 -1
- package/dist/code-example/components/CodeExample.vue.script.js +71 -68
- package/dist/code-example/components/CodeExample.vue.script.js.map +1 -1
- package/dist/code-example/helpers/generate-client-options.d.ts.map +1 -1
- package/dist/code-example/helpers/generate-client-options.js.map +1 -1
- package/dist/code-example/helpers/generate-code-snippet.d.ts.map +1 -1
- package/dist/code-example/helpers/generate-code-snippet.js +25 -24
- package/dist/code-example/helpers/generate-code-snippet.js.map +1 -1
- package/dist/code-example/helpers/get-clients.d.ts.map +1 -1
- package/dist/code-example/helpers/get-clients.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/operation-to-har.d.ts +1 -1
- package/dist/code-example/helpers/operation-to-har/operation-to-har.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/operation-to-har.js +3 -5
- package/dist/code-example/helpers/operation-to-har/operation-to-har.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-body.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-body.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts +6 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.js +105 -123
- package/dist/code-example/helpers/operation-to-har/process-parameters.js.map +1 -1
- package/dist/code-example/mount.d.ts.map +1 -1
- package/dist/code-example/mount.js +1 -1
- package/dist/code-example/mount.js.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/schema/SchemaObjectProperties.vue.js.map +1 -1
- package/dist/schema/SchemaObjectProperties.vue.script.js +1 -1
- package/dist/schema/SchemaObjectProperties.vue.script.js.map +1 -1
- package/dist/schema/SchemaProperty.vue.d.ts.map +1 -1
- package/dist/schema/SchemaProperty.vue.js +1 -1
- package/dist/schema/SchemaProperty.vue.js.map +1 -1
- package/dist/schema/SchemaProperty.vue.script.js +6 -3
- package/dist/schema/SchemaProperty.vue.script.js.map +1 -1
- package/dist/schema/helpers/has-complex-array-items.d.ts.map +1 -1
- package/dist/schema/helpers/has-complex-array-items.js +6 -2
- package/dist/schema/helpers/has-complex-array-items.js.map +1 -1
- package/dist/schema/helpers/merge-all-of-schemas.d.ts.map +1 -1
- package/dist/schema/helpers/merge-all-of-schemas.js +2 -2
- package/dist/schema/helpers/merge-all-of-schemas.js.map +1 -1
- package/dist/schema/helpers/partition-all-of-compositions.d.ts.map +1 -1
- package/dist/schema/helpers/partition-all-of-compositions.js +39 -27
- package/dist/schema/helpers/partition-all-of-compositions.js.map +1 -1
- package/dist/schema/helpers/schema-name.js +1 -1
- package/dist/schema/helpers/schema-name.js.map +1 -1
- package/dist/schema/localization/locales/zh-tw.d.ts +59 -0
- package/dist/schema/localization/locales/zh-tw.d.ts.map +1 -0
- package/dist/schema/localization/locales/zh-tw.js +60 -0
- package/dist/schema/localization/locales/zh-tw.js.map +1 -0
- package/dist/schema/localization/translations.d.ts +57 -0
- package/dist/schema/localization/translations.d.ts.map +1 -1
- package/dist/schema/localization/translations.js +5 -3
- package/dist/schema/localization/translations.js.map +1 -1
- package/dist/schema/types.d.ts +2 -0
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/style.css +14 -46
- package/dist/styles/schema-tree.css +3 -1
- package/dist/vue-styles.css +1 -1
- package/package.json +9 -9
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { getResolvedRef as e } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
2
|
-
import { deSerializeParameter as t,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { deSerializeParameter as t, filterDisabledProperties as n, getExampleFromSchema as r, isParamDisabled as i, serializeContentValue as a, serializeCookieStyle as o, serializeDeepObjectStyle as s, serializeFormStyle as c, serializeFormStyleForCookies as l, serializePipeDelimitedStyle as u, serializeSimpleStyle as d, serializeSpaceDelimitedStyle as f } from "@scalar/workspace-store/request-example";
|
|
3
|
+
import { getCookieSerializationError as p } from "@scalar/helpers/http/get-cookie-serialization-error";
|
|
4
|
+
import { isObjectLike as m } from "@scalar/helpers/object/is-object";
|
|
5
|
+
import { assertReservedPathUrl as h, serializeReservedPathParameter as g } from "@scalar/workspace-store/helpers/encode-path-parameter";
|
|
6
|
+
import { getParameterExample as _ } from "@scalar/workspace-store/helpers/get-parameter-example";
|
|
7
|
+
import { getQuerystringParameter as v, serializeQuerystringParameter as y } from "@scalar/workspace-store/helpers/querystring-parameter";
|
|
6
8
|
//#region src/code-example/helpers/operation-to-har/process-parameters.ts
|
|
7
|
-
var
|
|
9
|
+
var b = class extends Error {}, x = (t) => (t ?? []).map((t) => e(t)).filter((e) => e !== void 0), S = (e) => "allowReserved" in e && e.allowReserved !== void 0 ? e.allowReserved : "schema" in e && e.schema && typeof e.schema == "object" && "allowReserved" in e.schema ? e.schema.allowReserved === !0 : !1, C = (e) => {
|
|
8
10
|
if (e.in === "header") return {
|
|
9
11
|
style: "simple",
|
|
10
12
|
explode: "explode" in e && e.explode !== void 0 && e.explode
|
|
@@ -27,67 +29,70 @@ var g = (t) => (t ?? []).map((t) => e(t)).filter((e) => e !== void 0), _ = (e) =
|
|
|
27
29
|
style: n,
|
|
28
30
|
explode: "explode" in e && e.explode !== void 0 ? e.explode : n === "form"
|
|
29
31
|
};
|
|
30
|
-
},
|
|
31
|
-
let
|
|
32
|
-
if (
|
|
33
|
-
if (
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
}, w = (a, o, s) => {
|
|
33
|
+
let c = _(a, o), l = c.example, u = a.in === "query" && !c.serialized && !c.mediaSerialized ? l?.["x-scalar-disabled-properties"] : void 0;
|
|
34
|
+
if (u) return n(t(c.value, a), u, i(a, l, s));
|
|
35
|
+
if (i(a, l, s)) return;
|
|
36
|
+
if (c.value !== void 0) return t(c.value, a);
|
|
37
|
+
if (!("schema" in a) || !a.schema) return;
|
|
38
|
+
let d = a.in === "path" ? { emptyString: `{${a.name}}` } : {}, f = e(a.schema);
|
|
39
|
+
return f ? r(f, d) : void 0;
|
|
40
|
+
}, T = ({ harRequest: e, parameters: t, example: n, defaultDisabled: r, openapiVersion: m }) => {
|
|
41
|
+
let T = [...e.headers], D = [...e.queryString], O = [...e.cookies], k = [], A = e.url, j = !1, M = [], N = [], P = (e, t, n) => {
|
|
42
|
+
S(n) ? M.push(`${encodeURIComponent(e)}=${t}`) : D.push({
|
|
43
|
+
name: e,
|
|
44
|
+
value: t
|
|
45
|
+
});
|
|
46
|
+
}, F = x(t);
|
|
47
|
+
for (let e of F) {
|
|
40
48
|
if (!e.in || !e.name) continue;
|
|
41
49
|
if (e.in === "querystring") {
|
|
42
|
-
let t =
|
|
50
|
+
let t = v(e, n, { defaultDisabled: r });
|
|
43
51
|
if (t) {
|
|
44
|
-
let e =
|
|
45
|
-
|
|
52
|
+
let e = A.indexOf("#"), n = e === -1 ? "" : A.slice(e), r = (e === -1 ? A : A.slice(0, e)).split("?")[0], i = y(t);
|
|
53
|
+
A = `${r}${i ? `?${i}` : ""}${n}`;
|
|
46
54
|
}
|
|
47
55
|
continue;
|
|
48
56
|
}
|
|
49
|
-
let t =
|
|
50
|
-
if (t.serialized && !
|
|
57
|
+
let t = _(e, n);
|
|
58
|
+
if (t.serialized && !i(e, t.example, r)) {
|
|
51
59
|
let n = String(t.value);
|
|
52
60
|
switch (e.in) {
|
|
53
61
|
case "path":
|
|
54
|
-
|
|
62
|
+
A = A.replaceAll(`{${e.name}}`, () => n);
|
|
55
63
|
break;
|
|
56
64
|
case "query":
|
|
57
|
-
|
|
65
|
+
M.push(n);
|
|
58
66
|
break;
|
|
59
67
|
case "header":
|
|
60
|
-
|
|
68
|
+
T.push({
|
|
61
69
|
name: e.name,
|
|
62
70
|
value: n
|
|
63
71
|
});
|
|
64
72
|
break;
|
|
65
73
|
case "cookie":
|
|
66
|
-
|
|
74
|
+
N.push(n);
|
|
67
75
|
break;
|
|
68
76
|
}
|
|
69
77
|
continue;
|
|
70
78
|
}
|
|
71
|
-
if (t.mediaSerialized && !
|
|
79
|
+
if (t.mediaSerialized && !i(e, t.example, r)) {
|
|
72
80
|
let n = String(t.value);
|
|
73
81
|
switch (e.in) {
|
|
74
82
|
case "query":
|
|
75
|
-
|
|
76
|
-
name: e.name,
|
|
77
|
-
value: v(n, e)
|
|
78
|
-
});
|
|
83
|
+
P(e.name, n, e);
|
|
79
84
|
break;
|
|
80
85
|
case "header":
|
|
81
|
-
|
|
86
|
+
T.push({
|
|
82
87
|
name: e.name,
|
|
83
88
|
value: n
|
|
84
89
|
});
|
|
85
90
|
break;
|
|
86
91
|
case "path":
|
|
87
|
-
|
|
92
|
+
A = A.replaceAll(`{${e.name}}`, () => encodeURIComponent(n));
|
|
88
93
|
break;
|
|
89
94
|
case "cookie":
|
|
90
|
-
|
|
95
|
+
O.push({
|
|
91
96
|
name: e.name,
|
|
92
97
|
value: n
|
|
93
98
|
});
|
|
@@ -95,141 +100,118 @@ var g = (t) => (t ?? []).map((t) => e(t)).filter((e) => e !== void 0), _ = (e) =
|
|
|
95
100
|
}
|
|
96
101
|
continue;
|
|
97
102
|
}
|
|
98
|
-
let
|
|
99
|
-
if (
|
|
100
|
-
let { style:
|
|
103
|
+
let h = w(e, n, r);
|
|
104
|
+
if (h === void 0) continue;
|
|
105
|
+
let { style: x, explode: S } = C(e);
|
|
101
106
|
switch (e.in) {
|
|
102
|
-
case "path":
|
|
103
|
-
|
|
107
|
+
case "path": {
|
|
108
|
+
let t = m?.startsWith("3.2.") && "schema" in e && e.allowReserved === !0;
|
|
109
|
+
j ||= !!t;
|
|
110
|
+
let n = t ? g(e.name, {
|
|
111
|
+
value: h,
|
|
112
|
+
style: x,
|
|
113
|
+
explode: S
|
|
114
|
+
}) : void 0;
|
|
115
|
+
A = n === void 0 ? E(A, e, h, x, S) : A.replaceAll(`{${e.name}}`, () => n);
|
|
104
116
|
break;
|
|
117
|
+
}
|
|
105
118
|
case "query":
|
|
106
119
|
if ("content" in e && e.content) {
|
|
107
|
-
let t =
|
|
108
|
-
|
|
109
|
-
name: e.name,
|
|
110
|
-
value: v(t, e)
|
|
111
|
-
});
|
|
120
|
+
let t = a(h, Object.keys(e.content)[0] ?? "application/json");
|
|
121
|
+
P(e.name, t, e);
|
|
112
122
|
break;
|
|
113
123
|
}
|
|
114
|
-
switch (
|
|
124
|
+
switch (x) {
|
|
115
125
|
case "form": {
|
|
116
|
-
let t =
|
|
117
|
-
if (Array.isArray(t)) for (let n of t)
|
|
118
|
-
|
|
119
|
-
x.push({
|
|
120
|
-
name: t,
|
|
121
|
-
value: v(String(n.value), e)
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
else x.push({
|
|
125
|
-
name: e.name,
|
|
126
|
-
value: v(String(t), e)
|
|
127
|
-
});
|
|
126
|
+
let t = c(h, S);
|
|
127
|
+
if (Array.isArray(t)) for (let n of t) P(n.key || e.name, String(n.value), e);
|
|
128
|
+
else P(e.name, String(t), e);
|
|
128
129
|
break;
|
|
129
130
|
}
|
|
130
131
|
case "spaceDelimited": {
|
|
131
|
-
let t =
|
|
132
|
-
|
|
133
|
-
name: e.name,
|
|
134
|
-
value: v(t, e)
|
|
135
|
-
});
|
|
132
|
+
let t = f(h);
|
|
133
|
+
P(e.name, t, e);
|
|
136
134
|
break;
|
|
137
135
|
}
|
|
138
136
|
case "pipeDelimited": {
|
|
139
|
-
let t =
|
|
140
|
-
|
|
141
|
-
name: e.name,
|
|
142
|
-
value: v(t, e)
|
|
143
|
-
});
|
|
137
|
+
let t = u(h);
|
|
138
|
+
P(e.name, t, e);
|
|
144
139
|
break;
|
|
145
140
|
}
|
|
146
141
|
case "deepObject":
|
|
147
|
-
if (Array.isArray(
|
|
148
|
-
let t =
|
|
149
|
-
if (Array.isArray(t)) for (let n of t)
|
|
150
|
-
|
|
151
|
-
x.push({
|
|
152
|
-
name: t,
|
|
153
|
-
value: v(String(n.value), e)
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
else x.push({
|
|
157
|
-
name: e.name,
|
|
158
|
-
value: v(String(t), e)
|
|
159
|
-
});
|
|
142
|
+
if (Array.isArray(h)) {
|
|
143
|
+
let t = c(h, !0);
|
|
144
|
+
if (Array.isArray(t)) for (let n of t) P(n.key || e.name, String(n.value), e);
|
|
145
|
+
else P(e.name, String(t), e);
|
|
160
146
|
} else {
|
|
161
|
-
let t =
|
|
162
|
-
for (let n of t)
|
|
163
|
-
name: n.key,
|
|
164
|
-
value: v(n.value, e)
|
|
165
|
-
});
|
|
147
|
+
let t = s(e.name, h);
|
|
148
|
+
for (let n of t) P(n.key, n.value, e);
|
|
166
149
|
}
|
|
167
150
|
break;
|
|
168
|
-
default:
|
|
169
|
-
name: e.name,
|
|
170
|
-
value: v(String(g), e)
|
|
171
|
-
});
|
|
151
|
+
default: P(e.name, String(h), e);
|
|
172
152
|
}
|
|
173
153
|
break;
|
|
174
154
|
case "header": {
|
|
175
|
-
let t =
|
|
176
|
-
|
|
155
|
+
let t = d(h, S);
|
|
156
|
+
T.push({
|
|
177
157
|
name: e.name,
|
|
178
158
|
value: String(t)
|
|
179
159
|
});
|
|
180
160
|
break;
|
|
181
161
|
}
|
|
182
162
|
case "cookie": {
|
|
183
|
-
|
|
184
|
-
|
|
163
|
+
let [t, n] = (m ?? "").split("."), r = t === "3" && n === "2" && !("content" in e) ? p(e, h) : void 0;
|
|
164
|
+
if (r) throw new b(r);
|
|
165
|
+
if (x === "cookie") {
|
|
166
|
+
k.push(...o(e.name, h, S));
|
|
185
167
|
break;
|
|
186
168
|
}
|
|
187
|
-
let
|
|
188
|
-
if (Array.isArray(
|
|
189
|
-
let
|
|
190
|
-
|
|
191
|
-
name:
|
|
169
|
+
let i = l(h, S);
|
|
170
|
+
if (Array.isArray(i)) for (let t of i) {
|
|
171
|
+
let n = t.key || e.name, r = t.value === null ? "null" : String(t.value);
|
|
172
|
+
O.push({
|
|
173
|
+
name: n,
|
|
192
174
|
value: r
|
|
193
175
|
});
|
|
194
176
|
}
|
|
195
177
|
else {
|
|
196
|
-
let
|
|
197
|
-
|
|
178
|
+
let t = i === null ? "null" : String(i);
|
|
179
|
+
O.push({
|
|
198
180
|
name: e.name,
|
|
199
|
-
value:
|
|
181
|
+
value: t
|
|
200
182
|
});
|
|
201
183
|
}
|
|
202
184
|
break;
|
|
203
185
|
}
|
|
204
186
|
}
|
|
205
187
|
}
|
|
206
|
-
if (
|
|
188
|
+
if (k.length || N.length) {
|
|
207
189
|
let e = [
|
|
208
|
-
...
|
|
209
|
-
...
|
|
210
|
-
...
|
|
211
|
-
].join("; "), t =
|
|
212
|
-
t ?
|
|
190
|
+
...O.map((e) => `${encodeURIComponent(e.name)}=${encodeURIComponent(e.value)}`),
|
|
191
|
+
...k.map((e) => `${e.name}=${e.value}`),
|
|
192
|
+
...N
|
|
193
|
+
].join("; "), t = T.find((e) => e.name.toLowerCase() === "cookie");
|
|
194
|
+
t ? T.splice(T.indexOf(t), 1, {
|
|
213
195
|
...t,
|
|
214
196
|
value: t.value ? `${t.value}; ${e}` : e
|
|
215
|
-
}) :
|
|
197
|
+
}) : T.push({
|
|
216
198
|
name: "Cookie",
|
|
217
199
|
value: e
|
|
218
200
|
});
|
|
219
201
|
}
|
|
220
|
-
if (
|
|
221
|
-
let e =
|
|
222
|
-
|
|
202
|
+
if (M.length) {
|
|
203
|
+
let e = A.indexOf("#"), t = e < 0 ? "" : A.slice(e), n = e < 0 ? A : A.slice(0, e);
|
|
204
|
+
A = `${n}${n.includes("?") ? "&" : "?"}${M.join("&")}${t}`;
|
|
223
205
|
}
|
|
224
|
-
return {
|
|
225
|
-
url:
|
|
226
|
-
headers:
|
|
227
|
-
queryString:
|
|
228
|
-
cookies:
|
|
229
|
-
hasCookieStyleEntries:
|
|
230
|
-
...
|
|
206
|
+
return j && h(A), {
|
|
207
|
+
url: A,
|
|
208
|
+
headers: T,
|
|
209
|
+
queryString: D,
|
|
210
|
+
cookies: k.length || N.length ? [] : O,
|
|
211
|
+
hasCookieStyleEntries: k.length > 0 || N.length > 0,
|
|
212
|
+
...M.length ? { hasSerializedQuery: !0 } : {}
|
|
231
213
|
};
|
|
232
|
-
},
|
|
214
|
+
}, E = (e, t, n, r, i) => {
|
|
233
215
|
switch (r) {
|
|
234
216
|
case "matrix":
|
|
235
217
|
if (i) {
|
|
@@ -237,14 +219,14 @@ var g = (t) => (t ?? []).map((t) => e(t)).filter((e) => e !== void 0), _ = (e) =
|
|
|
237
219
|
let r = n.map((e) => `${t.name}=${e}`).join(";");
|
|
238
220
|
return e.replace(`{;${t.name}}`, `;${r}`);
|
|
239
221
|
}
|
|
240
|
-
if (
|
|
222
|
+
if (m(n)) {
|
|
241
223
|
let r = Object.entries(n).map(([e, t]) => `${e}=${t}`).join(";");
|
|
242
224
|
return e.replace(`{;${t.name}}`, `;${r}`);
|
|
243
225
|
}
|
|
244
226
|
return e.replace(`{;${t.name}}`, `;${t.name}=${n}`);
|
|
245
227
|
}
|
|
246
228
|
if (Array.isArray(n)) return e.replace(`{;${t.name}}`, `;${t.name}=${n.join(",")}`);
|
|
247
|
-
if (
|
|
229
|
+
if (m(n)) {
|
|
248
230
|
let r = Object.entries(n).map(([e, t]) => `${e},${t}`).join(",");
|
|
249
231
|
return e.replace(`{;${t.name}}`, `;${t.name}=${r}`);
|
|
250
232
|
}
|
|
@@ -252,26 +234,26 @@ var g = (t) => (t ?? []).map((t) => e(t)).filter((e) => e !== void 0), _ = (e) =
|
|
|
252
234
|
case "label":
|
|
253
235
|
if (i) {
|
|
254
236
|
if (Array.isArray(n)) return e.replace(`{.${t.name}}`, `.${n.join(".")}`);
|
|
255
|
-
if (
|
|
237
|
+
if (m(n)) {
|
|
256
238
|
let r = Object.entries(n).map(([e, t]) => `${e}=${t}`).join(".");
|
|
257
239
|
return e.replace(`{.${t.name}}`, `.${r}`);
|
|
258
240
|
}
|
|
259
241
|
return e.replace(`{.${t.name}}`, `.${n}`);
|
|
260
242
|
}
|
|
261
243
|
if (Array.isArray(n)) return e.replace(`{.${t.name}}`, `.${n.join(",")}`);
|
|
262
|
-
if (
|
|
244
|
+
if (m(n)) {
|
|
263
245
|
let r = Object.entries(n).map(([e, t]) => `${e},${t}`).join(",");
|
|
264
246
|
return e.replace(`{.${t.name}}`, `.${r}`);
|
|
265
247
|
}
|
|
266
248
|
return e.replace(`{.${t.name}}`, `.${n}`);
|
|
267
249
|
case "simple": {
|
|
268
|
-
let r =
|
|
250
|
+
let r = d(n, i);
|
|
269
251
|
return e.replace(`{${t.name}}`, String(r));
|
|
270
252
|
}
|
|
271
253
|
default: return e.replace(`{${t.name}}`, String(n));
|
|
272
254
|
}
|
|
273
255
|
};
|
|
274
256
|
//#endregion
|
|
275
|
-
export {
|
|
257
|
+
export { b as CookieSerializationError, T as processParameters };
|
|
276
258
|
|
|
277
259
|
//# sourceMappingURL=process-parameters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-parameters.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-parameters.ts"],"sourcesContent":["import { isObjectLike } from '@scalar/helpers/object/is-object'\nimport { getParameterExample } from '@scalar/workspace-store/helpers/get-parameter-example'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n getQuerystringParameter,\n serializeQuerystringParameter,\n} from '@scalar/workspace-store/helpers/querystring-parameter'\nimport {\n deSerializeParameter,\n getExampleFromSchema,\n isParamDisabled,\n serializeContentValue,\n serializeCookieStyle,\n serializeDeepObjectStyle,\n serializeFormStyle,\n serializeFormStyleForCookies,\n serializePipeDelimitedStyle,\n serializeSimpleStyle,\n serializeSpaceDelimitedStyle,\n} from '@scalar/workspace-store/request-example'\nimport type { OperationObject, ParameterObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport type { Request as HarRequest } from 'har-format'\n\ntype ProcessedParameters = {\n /** Named serialized examples already embedded in the URL. */\n hasSerializedQuery?: boolean\n url: string\n headers: HarRequest['headers']\n queryString: HarRequest['queryString']\n cookies: HarRequest['cookies']\n /** Whether serialized cookie-style values require a complete Cookie header. */\n hasCookieStyleEntries: boolean\n}\n\n/** Ensures we don't have any references in the parameters */\nconst deReferenceParams = (params: OperationObject['parameters']): ParameterObject[] =>\n (params ?? []).map((param) => getResolvedRef(param)).filter((param) => param !== undefined)\n\n/** Whether the parameter allows reserved characters (from param or schema). */\nconst isAllowReserved = (param: ParameterObject): boolean => {\n if ('allowReserved' in param && param.allowReserved !== undefined) {\n return param.allowReserved\n }\n if ('schema' in param && param.schema && typeof param.schema === 'object' && 'allowReserved' in param.schema) {\n return (param.schema as { allowReserved?: boolean }).allowReserved === true\n }\n return false\n}\n\n/** URL encode a value if allowReserved is not set to true. */\nconst encodeQueryValue = (value: string, param: ParameterObject): string => {\n if (isAllowReserved(param)) {\n return value\n }\n return encodeURIComponent(value)\n}\n\n/**\n * Get the style and explode values for a parameter according to OpenAPI 3.1.1 specification.\n * Handles defaults and validation for parameter location restrictions.\n */\nconst getParameterStyleAndExplode = (param: ParameterObject): { style: string; explode: boolean } => {\n // Headers only support 'simple' style\n if (param.in === 'header') {\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : false\n return { style: 'simple', explode }\n }\n\n // Cookies default to form for compatibility and also support cookie style.\n if (param.in === 'cookie') {\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : true\n return { style: 'style' in param && param.style === 'cookie' ? 'cookie' : 'form', explode }\n }\n\n const defaultStyle = {\n path: 'simple',\n query: 'form',\n querystring: 'form',\n header: 'simple',\n cookie: 'form',\n }[param.in]\n\n // Use provided style or default based on location\n const style = 'style' in param && param.style ? param.style : defaultStyle\n\n // Determine explode value: use provided value or default based on style\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : style === 'form'\n\n return { style, explode }\n}\n\n/**\n * Extract the value for a parameter from example data or schema.\n * Prioritizes example data over schema examples.\n * Returns null if the parameter is disabled so we can skip it.\n */\nconst getParameterValue = (param: ParameterObject, example: string | undefined, defaultDisabled: boolean): unknown => {\n // Try to get value from example first\n const selected = getParameterExample(param, example)\n const exampleValue = selected.example\n\n // If the parameter is disabled, return undefined so we can skip it.\n if (isParamDisabled(param, exampleValue, defaultDisabled)) {\n return undefined\n }\n\n // If the example value is set, return it.\n if (selected.value !== undefined) {\n return deSerializeParameter(selected.value, param)\n }\n\n // Fall back to schema example if available\n if (!('schema' in param) || !param.schema) {\n return undefined\n }\n\n const options = param.in === 'path' ? { emptyString: `{${param.name}}` } : {}\n const schema = getResolvedRef(param.schema)\n return schema ? getExampleFromSchema(schema, options) : undefined\n}\n\n/**\n * Process OpenAPI parameters and return the updated properties.\n * Handles path, query, and header parameters with various styles and explode options.\n *\n * @see https://spec.openapis.org/oas/latest.html#style-values\n */\nexport const processParameters = ({\n harRequest,\n parameters,\n example,\n defaultDisabled,\n}: {\n harRequest: HarRequest\n parameters: OperationObject['parameters']\n /** The name of the example to use */\n example?: string | undefined\n /** Whether to disable parameters by default. */\n defaultDisabled: boolean\n}): ProcessedParameters => {\n // Create copies of the arrays to avoid modifying the input\n const newHeaders = [...harRequest.headers]\n const newQueryString = [...harRequest.queryString]\n const newCookies = [...harRequest.cookies]\n const cookieStyleEntries: HarRequest['cookies'] = []\n let newUrl = harRequest.url\n const serializedQuery: string[] = []\n const serializedCookies: string[] = []\n\n // Filter out references\n const deReferencedParams = deReferenceParams(parameters)\n\n for (const param of deReferencedParams) {\n if (!param.in || !param.name) {\n continue\n }\n\n if (param.in === 'querystring') {\n const querystring = getQuerystringParameter(param, example, { defaultDisabled })\n if (querystring) {\n const hashIndex = newUrl.indexOf('#')\n const hash = hashIndex === -1 ? '' : newUrl.slice(hashIndex)\n const base = (hashIndex === -1 ? newUrl : newUrl.slice(0, hashIndex)).split('?')[0]\n const query = serializeQuerystringParameter(querystring)\n newUrl = `${base}${query ? `?${query}` : ''}${hash}`\n }\n continue\n }\n\n const selected = getParameterExample(param, example)\n if (selected.serialized && !isParamDisabled(param, selected.example, defaultDisabled)) {\n const wireValue = String(selected.value)\n switch (param.in) {\n case 'path':\n newUrl = newUrl.replaceAll(`{${param.name}}`, () => wireValue)\n break\n case 'query':\n serializedQuery.push(wireValue)\n break\n case 'header':\n newHeaders.push({ name: param.name, value: wireValue })\n break\n case 'cookie':\n serializedCookies.push(wireValue)\n break\n }\n continue\n }\n if (selected.mediaSerialized && !isParamDisabled(param, selected.example, defaultDisabled)) {\n const text = String(selected.value)\n switch (param.in) {\n case 'query':\n newQueryString.push({ name: param.name, value: encodeQueryValue(text, param) })\n break\n case 'header':\n newHeaders.push({ name: param.name, value: text })\n break\n case 'path':\n newUrl = newUrl.replaceAll(`{${param.name}}`, () => encodeURIComponent(text))\n break\n case 'cookie':\n newCookies.push({ name: param.name, value: text })\n break\n }\n continue\n }\n const paramValue = getParameterValue(param, example, defaultDisabled)\n if (paramValue === undefined) {\n continue\n }\n\n const { style, explode } = getParameterStyleAndExplode(param)\n\n switch (param.in) {\n case 'path': {\n newUrl = processPathParameters(newUrl, param, paramValue, style, explode)\n break\n }\n\n case 'query': {\n // Content type parameters should be serialized according to the parameter's own content type\n if ('content' in param && param.content) {\n // We grab the first for now but eventually we should support selecting the content type per parameter\n const paramContentType = Object.keys(param.content)[0] ?? 'application/json'\n const serializedValue = serializeContentValue(paramValue, paramContentType)\n newQueryString.push({ name: param.name, value: encodeQueryValue(serializedValue, param) })\n break\n }\n\n // Handle query parameters\n switch (style) {\n case 'form': {\n const serialized = serializeFormStyle(paramValue, explode)\n\n // If serialized is an array of key-value pairs (exploded object or array)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n newQueryString.push({ name: key, value: encodeQueryValue(String(entry.value), param) })\n }\n }\n // Otherwise, convert to string\n else {\n newQueryString.push({ name: param.name, value: encodeQueryValue(String(serialized), param) })\n }\n break\n }\n case 'spaceDelimited': {\n const serialized = serializeSpaceDelimitedStyle(paramValue)\n newQueryString.push({ name: param.name, value: encodeQueryValue(serialized, param) })\n break\n }\n case 'pipeDelimited': {\n const serialized = serializePipeDelimitedStyle(paramValue)\n newQueryString.push({ name: param.name, value: encodeQueryValue(serialized, param) })\n break\n }\n case 'deepObject': {\n // OAS marks deepObject-on-array and deepObject+explode:false as undefined.\n // Mirror process-body: fall back to form/explode:true for arrays and always\n // invoke the serializer for objects so authors get useful output instead of\n // a silently-dropped parameter.\n if (Array.isArray(paramValue)) {\n const serialized = serializeFormStyle(paramValue, true)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n newQueryString.push({ name: key, value: encodeQueryValue(String(entry.value), param) })\n }\n } else {\n newQueryString.push({ name: param.name, value: encodeQueryValue(String(serialized), param) })\n }\n } else {\n const entries = serializeDeepObjectStyle(param.name, paramValue)\n for (const entry of entries) {\n newQueryString.push({ name: entry.key, value: encodeQueryValue(entry.value, param) })\n }\n }\n break\n }\n\n // Default to form style\n default:\n newQueryString.push({ name: param.name, value: encodeQueryValue(String(paramValue), param) })\n }\n break\n }\n\n // Headers only support 'simple' style according to OpenAPI 3.1.1\n // For arrays, simple style always produces comma-separated values regardless of explode\n // The explode parameter only affects object serialization\n case 'header': {\n const serialized = serializeSimpleStyle(paramValue, explode)\n newHeaders.push({ name: param.name, value: String(serialized) })\n break\n }\n\n // Keep cookie style separate so snippet generators cannot percent-encode it.\n case 'cookie': {\n if (style === 'cookie') {\n cookieStyleEntries.push(...serializeCookieStyle(param.name, paramValue, explode))\n break\n }\n const serialized = serializeFormStyleForCookies(paramValue, explode)\n\n // If serialized is an array of key-value pairs (exploded object or array)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n const value = entry.value === null ? 'null' : String(entry.value)\n newCookies.push({ name: key, value })\n }\n }\n // Otherwise, convert to string\n else {\n const value = serialized === null ? 'null' : String(serialized)\n newCookies.push({ name: param.name, value })\n }\n break\n }\n }\n }\n\n // HAR cookie entries are encoded by snippet generators. Use a complete header\n // when cookie style is present, preserving legacy encoding for other cookies.\n if (cookieStyleEntries.length || serializedCookies.length) {\n const cookieValue = [\n ...newCookies.map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`),\n ...cookieStyleEntries.map((cookie) => `${cookie.name}=${cookie.value}`),\n ...serializedCookies,\n ].join('; ')\n const existing = newHeaders.find((header) => header.name.toLowerCase() === 'cookie')\n if (existing) {\n newHeaders.splice(newHeaders.indexOf(existing), 1, {\n ...existing,\n value: existing.value ? `${existing.value}; ${cookieValue}` : cookieValue,\n })\n } else {\n newHeaders.push({ name: 'Cookie', value: cookieValue })\n }\n }\n\n if (serializedQuery.length) {\n const hashIndex = newUrl.indexOf('#')\n const hash = hashIndex < 0 ? '' : newUrl.slice(hashIndex)\n const base = hashIndex < 0 ? newUrl : newUrl.slice(0, hashIndex)\n newUrl = `${base}${base.includes('?') ? '&' : '?'}${serializedQuery.join('&')}${hash}`\n }\n\n return {\n url: newUrl,\n headers: newHeaders,\n queryString: newQueryString,\n cookies: cookieStyleEntries.length || serializedCookies.length ? [] : newCookies,\n hasCookieStyleEntries: cookieStyleEntries.length > 0 || serializedCookies.length > 0,\n ...(serializedQuery.length ? { hasSerializedQuery: true } : {}),\n }\n}\n\n/**\n * Process path parameters according to OpenAPI specification.\n * Handles matrix, label, and simple styles with explode options.\n *\n * @param url - The URL to process\n * @param param - The parameter object\n * @param paramValue - The value of the parameter\n * @param style - The style of the parameter (matrix, label, simple)\n * @param explode - Whether to explode the parameter\n * @returns The updated URL with processed path parameters\n */\nconst processPathParameters = (\n url: string,\n param: ParameterObject,\n paramValue: unknown,\n style: string,\n explode: boolean,\n): string => {\n switch (style) {\n case 'matrix': {\n if (explode) {\n // Matrix explode array: ;color=blue;color=black;color=brown\n if (Array.isArray(paramValue)) {\n const values = paramValue.map((v: unknown) => `${param.name}=${v}`).join(';')\n return url.replace(`{;${param.name}}`, `;${values}`)\n }\n\n // Matrix explode object: ;R=100;G=200;B=150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k}=${v}`)\n .join(';')\n return url.replace(`{;${param.name}}`, `;${values}`)\n }\n\n // Matrix explode primitive: ;color=blue\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`)\n }\n\n // Matrix no explode array: ;color=blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue.join(',')}`)\n }\n\n // Matrix no explode object: ;color=R,100,G,200,B,150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n return url.replace(`{;${param.name}}`, `;${param.name}=${values}`)\n }\n\n // Matrix no explode primitive: ;color=blue\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`)\n }\n case 'label': {\n if (explode) {\n // Label explode array: .blue.black.brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{.${param.name}}`, `.${paramValue.join('.')}`)\n }\n\n // Label explode object: .R=100.G=200.B=150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k}=${v}`)\n .join('.')\n\n return url.replace(`{.${param.name}}`, `.${values}`)\n }\n\n // Label explode primitive: .blue\n return url.replace(`{.${param.name}}`, `.${paramValue}`)\n }\n\n // Label no explode array: .blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{.${param.name}}`, `.${paramValue.join(',')}`)\n }\n\n // Label no explode object: .R,100,G,200,B,150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n\n return url.replace(`{.${param.name}}`, `.${values}`)\n }\n\n // Label no explode primitive: .blue\n return url.replace(`{.${param.name}}`, `.${paramValue}`)\n }\n\n case 'simple': {\n const serialized = serializeSimpleStyle(paramValue, explode)\n return url.replace(`{${param.name}}`, String(serialized))\n }\n\n // Default to simple style\n default:\n return url.replace(`{${param.name}}`, String(paramValue))\n }\n}\n"],"mappings":";;;;;;AAmCA,IAAM,KAAqB,OACxB,KAAU,CAAC,EAAA,CAAG,KAAK,MAAU,EAAe,CAAK,CAAC,CAAC,CAAC,QAAQ,MAAU,MAAU,KAAA,CAAS,GAGtF,KAAmB,MACnB,mBAAmB,KAAS,EAAM,kBAAkB,KAAA,IAC/C,EAAM,gBAEX,YAAY,KAAS,EAAM,UAAU,OAAO,EAAM,UAAW,YAAY,mBAAmB,EAAM,SAC5F,EAAM,OAAuC,kBAAkB,KAElE,IAIH,KAAoB,GAAe,MACnC,EAAgB,CAAK,IAChB,IAEF,mBAAmB,CAAK,GAO3B,KAA+B,MAAgE;CAEnG,IAAI,EAAM,OAAO,UAEf,OAAO;EAAE,OAAO;EAAU,SADV,aAAa,KAAS,EAAM,YAAY,KAAA,KAAY,EAAM;CACxC;CAIpC,IAAI,EAAM,OAAO,UAAU;EACzB,IAAM,IAAU,aAAa,KAAS,EAAM,YAAY,KAAA,IAAY,EAAM,UAAU;EACpF,OAAO;GAAE,OAAO,WAAW,KAAS,EAAM,UAAU,WAAW,WAAW;GAAQ;EAAQ;CAC5F;CAEA,IAAM,IAAe;EACnB,MAAM;EACN,OAAO;EACP,aAAa;EACb,QAAQ;EACR,QAAQ;CACV,EAAE,EAAM,KAGF,IAAQ,WAAW,KAAS,EAAM,QAAQ,EAAM,QAAQ;CAK9D,OAAO;EAAE;EAAO,SAFA,aAAa,KAAS,EAAM,YAAY,KAAA,IAAY,EAAM,UAAU,MAAU;CAEtE;AAC1B,GAOM,KAAqB,GAAwB,GAA6B,MAAsC;CAEpH,IAAM,IAAW,EAAoB,GAAO,CAAO,GAC7C,IAAe,EAAS;CAG9B,IAAI,EAAgB,GAAO,GAAc,CAAe,GACtD;CAIF,IAAI,EAAS,UAAU,KAAA,G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example/helpers/operation-to-har/process-parameters.ts"],"sourcesContent":["import { getCookieSerializationError } from '@scalar/helpers/http/get-cookie-serialization-error'\nimport { isObjectLike } from '@scalar/helpers/object/is-object'\nimport {\n assertReservedPathUrl,\n serializeReservedPathParameter,\n} from '@scalar/workspace-store/helpers/encode-path-parameter'\nimport { getParameterExample } from '@scalar/workspace-store/helpers/get-parameter-example'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n getQuerystringParameter,\n serializeQuerystringParameter,\n} from '@scalar/workspace-store/helpers/querystring-parameter'\nimport {\n deSerializeParameter,\n filterDisabledProperties,\n getExampleFromSchema,\n isParamDisabled,\n serializeContentValue,\n serializeCookieStyle,\n serializeDeepObjectStyle,\n serializeFormStyle,\n serializeFormStyleForCookies,\n serializePipeDelimitedStyle,\n serializeSimpleStyle,\n serializeSpaceDelimitedStyle,\n} from '@scalar/workspace-store/request-example'\nimport type { OperationObject, ParameterObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport type { Request as HarRequest } from 'har-format'\n\n/** An invalid cookie declaration that authors can repair before generating a sample. */\nexport class CookieSerializationError extends Error {}\n\ntype ProcessedParameters = {\n /** Named serialized examples already embedded in the URL. */\n hasSerializedQuery?: boolean\n url: string\n headers: HarRequest['headers']\n queryString: HarRequest['queryString']\n cookies: HarRequest['cookies']\n /** Whether serialized cookie-style values require a complete Cookie header. */\n hasCookieStyleEntries: boolean\n}\n\n/** Ensures we don't have any references in the parameters */\nconst deReferenceParams = (params: OperationObject['parameters']): ParameterObject[] =>\n (params ?? []).map((param) => getResolvedRef(param)).filter((param) => param !== undefined)\n\n/** Whether the parameter allows reserved characters (from param or schema). */\nconst isAllowReserved = (param: ParameterObject): boolean => {\n if ('allowReserved' in param && param.allowReserved !== undefined) {\n return param.allowReserved\n }\n if ('schema' in param && param.schema && typeof param.schema === 'object' && 'allowReserved' in param.schema) {\n return (param.schema as { allowReserved?: boolean }).allowReserved === true\n }\n return false\n}\n\n/**\n * Get the style and explode values for a parameter according to OpenAPI 3.1.1 specification.\n * Handles defaults and validation for parameter location restrictions.\n */\nconst getParameterStyleAndExplode = (param: ParameterObject): { style: string; explode: boolean } => {\n // Headers only support 'simple' style\n if (param.in === 'header') {\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : false\n return { style: 'simple', explode }\n }\n\n // Cookies default to form for compatibility and also support cookie style.\n if (param.in === 'cookie') {\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : true\n return { style: 'style' in param && param.style === 'cookie' ? 'cookie' : 'form', explode }\n }\n\n const defaultStyle = {\n path: 'simple',\n query: 'form',\n querystring: 'form',\n header: 'simple',\n cookie: 'form',\n }[param.in]\n\n // Use provided style or default based on location\n const style = 'style' in param && param.style ? param.style : defaultStyle\n\n // Determine explode value: use provided value or default based on style\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : style === 'form'\n\n return { style, explode }\n}\n\n/**\n * Extract the value for a parameter from example data or schema.\n * Prioritizes example data over schema examples.\n * Returns null if the parameter is disabled so we can skip it.\n */\nconst getParameterValue = (param: ParameterObject, example: string | undefined, defaultDisabled: boolean): unknown => {\n // Try to get value from example first\n const selected = getParameterExample(param, example)\n const exampleValue = selected.example\n\n const propertyStates =\n param.in === 'query' && !selected.serialized && !selected.mediaSerialized\n ? exampleValue?.['x-scalar-disabled-properties']\n : undefined\n if (propertyStates) {\n return filterDisabledProperties(\n deSerializeParameter(selected.value, param),\n propertyStates,\n isParamDisabled(param, exampleValue, defaultDisabled),\n )\n }\n\n // If the parameter is disabled, return undefined so we can skip it.\n if (isParamDisabled(param, exampleValue, defaultDisabled)) {\n return undefined\n }\n\n // If the example value is set, return it.\n if (selected.value !== undefined) {\n return deSerializeParameter(selected.value, param)\n }\n\n // Fall back to schema example if available\n if (!('schema' in param) || !param.schema) {\n return undefined\n }\n\n const options = param.in === 'path' ? { emptyString: `{${param.name}}` } : {}\n const schema = getResolvedRef(param.schema)\n return schema ? getExampleFromSchema(schema, options) : undefined\n}\n\n/**\n * Process OpenAPI parameters and return the updated properties.\n * Handles path, query, and header parameters with various styles and explode options.\n *\n * @see https://spec.openapis.org/oas/latest.html#style-values\n */\nexport const processParameters = ({\n harRequest,\n parameters,\n example,\n defaultDisabled,\n openapiVersion,\n}: {\n harRequest: HarRequest\n parameters: OperationObject['parameters']\n /** The name of the example to use */\n example?: string | undefined\n /** Whether to disable parameters by default. */\n defaultDisabled: boolean\n /** Originating API description version. */\n openapiVersion?: string\n}): ProcessedParameters => {\n // Create copies of the arrays to avoid modifying the input\n const newHeaders = [...harRequest.headers]\n const newQueryString = [...harRequest.queryString]\n const newCookies = [...harRequest.cookies]\n const cookieStyleEntries: HarRequest['cookies'] = []\n let newUrl = harRequest.url\n let hasReservedPathParameter = false\n const serializedQuery: string[] = []\n const serializedCookies: string[] = []\n\n const appendQueryParameter = (name: string, value: string, param: ParameterObject): void => {\n if (isAllowReserved(param)) {\n // HTTP clients cannot infer reserved expansion from a HAR name/value pair.\n serializedQuery.push(`${encodeURIComponent(name)}=${value}`)\n } else {\n newQueryString.push({ name, value })\n }\n }\n\n // Filter out references\n const deReferencedParams = deReferenceParams(parameters)\n\n for (const param of deReferencedParams) {\n if (!param.in || !param.name) {\n continue\n }\n\n if (param.in === 'querystring') {\n const querystring = getQuerystringParameter(param, example, { defaultDisabled })\n if (querystring) {\n const hashIndex = newUrl.indexOf('#')\n const hash = hashIndex === -1 ? '' : newUrl.slice(hashIndex)\n const base = (hashIndex === -1 ? newUrl : newUrl.slice(0, hashIndex)).split('?')[0]\n const query = serializeQuerystringParameter(querystring)\n newUrl = `${base}${query ? `?${query}` : ''}${hash}`\n }\n continue\n }\n\n const selected = getParameterExample(param, example)\n if (selected.serialized && !isParamDisabled(param, selected.example, defaultDisabled)) {\n const wireValue = String(selected.value)\n switch (param.in) {\n case 'path':\n newUrl = newUrl.replaceAll(`{${param.name}}`, () => wireValue)\n break\n case 'query':\n serializedQuery.push(wireValue)\n break\n case 'header':\n newHeaders.push({ name: param.name, value: wireValue })\n break\n case 'cookie':\n serializedCookies.push(wireValue)\n break\n }\n continue\n }\n if (selected.mediaSerialized && !isParamDisabled(param, selected.example, defaultDisabled)) {\n const text = String(selected.value)\n switch (param.in) {\n case 'query':\n appendQueryParameter(param.name, text, param)\n break\n case 'header':\n newHeaders.push({ name: param.name, value: text })\n break\n case 'path':\n newUrl = newUrl.replaceAll(`{${param.name}}`, () => encodeURIComponent(text))\n break\n case 'cookie':\n newCookies.push({ name: param.name, value: text })\n break\n }\n continue\n }\n const paramValue = getParameterValue(param, example, defaultDisabled)\n if (paramValue === undefined) {\n continue\n }\n\n const { style, explode } = getParameterStyleAndExplode(param)\n\n switch (param.in) {\n case 'path': {\n const allowReserved = openapiVersion?.startsWith('3.2.') && 'schema' in param && param.allowReserved === true\n hasReservedPathParameter ||= Boolean(allowReserved)\n const pathValue = allowReserved\n ? serializeReservedPathParameter(param.name, { value: paramValue, style, explode })\n : undefined\n newUrl =\n pathValue === undefined\n ? processPathParameters(newUrl, param, paramValue, style, explode)\n : newUrl.replaceAll(`{${param.name}}`, () => pathValue)\n break\n }\n\n case 'query': {\n // Content type parameters should be serialized according to the parameter's own content type\n if ('content' in param && param.content) {\n // We grab the first for now but eventually we should support selecting the content type per parameter\n const paramContentType = Object.keys(param.content)[0] ?? 'application/json'\n const serializedValue = serializeContentValue(paramValue, paramContentType)\n appendQueryParameter(param.name, serializedValue, param)\n break\n }\n\n // Handle query parameters\n switch (style) {\n case 'form': {\n const serialized = serializeFormStyle(paramValue, explode)\n\n // If serialized is an array of key-value pairs (exploded object or array)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n appendQueryParameter(key, String(entry.value), param)\n }\n }\n // Otherwise, convert to string\n else {\n appendQueryParameter(param.name, String(serialized), param)\n }\n break\n }\n case 'spaceDelimited': {\n const serialized = serializeSpaceDelimitedStyle(paramValue)\n appendQueryParameter(param.name, serialized, param)\n break\n }\n case 'pipeDelimited': {\n const serialized = serializePipeDelimitedStyle(paramValue)\n appendQueryParameter(param.name, serialized, param)\n break\n }\n case 'deepObject': {\n // OAS marks deepObject-on-array and deepObject+explode:false as undefined.\n // Mirror process-body: fall back to form/explode:true for arrays and always\n // invoke the serializer for objects so authors get useful output instead of\n // a silently-dropped parameter.\n if (Array.isArray(paramValue)) {\n const serialized = serializeFormStyle(paramValue, true)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n appendQueryParameter(key, String(entry.value), param)\n }\n } else {\n appendQueryParameter(param.name, String(serialized), param)\n }\n } else {\n const entries = serializeDeepObjectStyle(param.name, paramValue)\n for (const entry of entries) {\n appendQueryParameter(entry.key, entry.value, param)\n }\n }\n break\n }\n\n // Default to form style\n default:\n appendQueryParameter(param.name, String(paramValue), param)\n }\n break\n }\n\n // Headers only support 'simple' style according to OpenAPI 3.1.1\n // For arrays, simple style always produces comma-separated values regardless of explode\n // The explode parameter only affects object serialization\n case 'header': {\n const serialized = serializeSimpleStyle(paramValue, explode)\n newHeaders.push({ name: param.name, value: String(serialized) })\n break\n }\n\n // Keep cookie style separate so snippet generators cannot percent-encode it.\n case 'cookie': {\n const [major, minor] = (openapiVersion ?? '').split('.')\n const error =\n major === '3' && minor === '2' && !('content' in param)\n ? getCookieSerializationError(param, paramValue)\n : undefined\n if (error) {\n throw new CookieSerializationError(error)\n }\n if (style === 'cookie') {\n cookieStyleEntries.push(...serializeCookieStyle(param.name, paramValue, explode))\n break\n }\n const serialized = serializeFormStyleForCookies(paramValue, explode)\n\n // If serialized is an array of key-value pairs (exploded object or array)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n const value = entry.value === null ? 'null' : String(entry.value)\n newCookies.push({ name: key, value })\n }\n }\n // Otherwise, convert to string\n else {\n const value = serialized === null ? 'null' : String(serialized)\n newCookies.push({ name: param.name, value })\n }\n break\n }\n }\n }\n\n // HAR cookie entries are encoded by snippet generators. Use a complete header\n // when cookie style is present, preserving legacy encoding for other cookies.\n if (cookieStyleEntries.length || serializedCookies.length) {\n const cookieValue = [\n ...newCookies.map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`),\n ...cookieStyleEntries.map((cookie) => `${cookie.name}=${cookie.value}`),\n ...serializedCookies,\n ].join('; ')\n const existing = newHeaders.find((header) => header.name.toLowerCase() === 'cookie')\n if (existing) {\n newHeaders.splice(newHeaders.indexOf(existing), 1, {\n ...existing,\n value: existing.value ? `${existing.value}; ${cookieValue}` : cookieValue,\n })\n } else {\n newHeaders.push({ name: 'Cookie', value: cookieValue })\n }\n }\n\n if (serializedQuery.length) {\n const hashIndex = newUrl.indexOf('#')\n const hash = hashIndex < 0 ? '' : newUrl.slice(hashIndex)\n const base = hashIndex < 0 ? newUrl : newUrl.slice(0, hashIndex)\n newUrl = `${base}${base.includes('?') ? '&' : '?'}${serializedQuery.join('&')}${hash}`\n }\n\n if (hasReservedPathParameter) {\n assertReservedPathUrl(newUrl)\n }\n\n return {\n url: newUrl,\n headers: newHeaders,\n queryString: newQueryString,\n cookies: cookieStyleEntries.length || serializedCookies.length ? [] : newCookies,\n hasCookieStyleEntries: cookieStyleEntries.length > 0 || serializedCookies.length > 0,\n ...(serializedQuery.length ? { hasSerializedQuery: true } : {}),\n }\n}\n\n/**\n * Process path parameters according to OpenAPI specification.\n * Handles matrix, label, and simple styles with explode options.\n *\n * @param url - The URL to process\n * @param param - The parameter object\n * @param paramValue - The value of the parameter\n * @param style - The style of the parameter (matrix, label, simple)\n * @param explode - Whether to explode the parameter\n * @returns The updated URL with processed path parameters\n */\nconst processPathParameters = (\n url: string,\n param: ParameterObject,\n paramValue: unknown,\n style: string,\n explode: boolean,\n): string => {\n switch (style) {\n case 'matrix': {\n if (explode) {\n // Matrix explode array: ;color=blue;color=black;color=brown\n if (Array.isArray(paramValue)) {\n const values = paramValue.map((v: unknown) => `${param.name}=${v}`).join(';')\n return url.replace(`{;${param.name}}`, `;${values}`)\n }\n\n // Matrix explode object: ;R=100;G=200;B=150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k}=${v}`)\n .join(';')\n return url.replace(`{;${param.name}}`, `;${values}`)\n }\n\n // Matrix explode primitive: ;color=blue\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`)\n }\n\n // Matrix no explode array: ;color=blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue.join(',')}`)\n }\n\n // Matrix no explode object: ;color=R,100,G,200,B,150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n return url.replace(`{;${param.name}}`, `;${param.name}=${values}`)\n }\n\n // Matrix no explode primitive: ;color=blue\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`)\n }\n case 'label': {\n if (explode) {\n // Label explode array: .blue.black.brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{.${param.name}}`, `.${paramValue.join('.')}`)\n }\n\n // Label explode object: .R=100.G=200.B=150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k}=${v}`)\n .join('.')\n\n return url.replace(`{.${param.name}}`, `.${values}`)\n }\n\n // Label explode primitive: .blue\n return url.replace(`{.${param.name}}`, `.${paramValue}`)\n }\n\n // Label no explode array: .blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{.${param.name}}`, `.${paramValue.join(',')}`)\n }\n\n // Label no explode object: .R,100,G,200,B,150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n\n return url.replace(`{.${param.name}}`, `.${values}`)\n }\n\n // Label no explode primitive: .blue\n return url.replace(`{.${param.name}}`, `.${paramValue}`)\n }\n\n case 'simple': {\n const serialized = serializeSimpleStyle(paramValue, explode)\n return url.replace(`{${param.name}}`, String(serialized))\n }\n\n // Default to simple style\n default:\n return url.replace(`{${param.name}}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3D,OAAO,EAAI,QAAQ,IAAI,EAAM,KAAK,IAAI,OAAO,CAAU,CAAC;EAC1D;EAGA,SACE,OAAO,EAAI,QAAQ,IAAI,EAAM,KAAK,IAAI,OAAO,CAAU,CAAC;CAC5D;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/code-example/mount.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAOpE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AACzF,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAMjH,MAAM,MAAM,wBAAwB,GAAG;IACrC,uFAAuF;IACvF,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,yEAAyE;IACzE,KAAK,EAAE,cAAc,CAAA;IACrB,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAA;IACZ,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,iDAAiD;IACjD,cAAc,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAA;IACzC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;IACpC;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,oDAAoD;IACpD,eAAe,CAAC,EAAE,0BAA0B,EAAE,CAAA;IAC9C;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;
|
|
1
|
+
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/code-example/mount.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAOpE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AACzF,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAMjH,MAAM,MAAM,wBAAwB,GAAG;IACrC,uFAAuF;IACvF,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,yEAAyE;IACzE,KAAK,EAAE,cAAc,CAAA;IACrB,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAA;IACZ,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,iDAAiD;IACjD,cAAc,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAA;IACzC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;IACpC;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,oDAAoD;IACpD,eAAe,CAAC,EAAE,0BAA0B,EAAE,CAAA;IAC9C;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAkBD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,IAAI,WAAW,GAAG,MAAM,EAAE,SAAS,wBAAwB;;;CA4I5F,CAAA"}
|
|
@@ -9,7 +9,7 @@ import { getPathItemOperation as l } from "@scalar/workspace-store/helpers/for-e
|
|
|
9
9
|
import { getFirstServer as u } from "@scalar/workspace-store/helpers/get-first-server";
|
|
10
10
|
import { generateClientMutators as d } from "@scalar/workspace-store/mutators";
|
|
11
11
|
//#region src/code-example/mount.ts
|
|
12
|
-
var f = (e) =>
|
|
12
|
+
var f = (e) => e === !0 ? "scalar-app dark-mode" : e === !1 ? "scalar-app light-mode" : "scalar-app", p = (p, m) => {
|
|
13
13
|
let h = typeof p == "string" ? document.querySelector(p) : p;
|
|
14
14
|
if (!h) throw Error(`Element not found: ${p}`);
|
|
15
15
|
let g = a(), _ = e(), v = d(m.store), y = g.on("workspace:update:selected-client", (e) => v.workspace().workspace.updateSelectedClient(e)), b = g.on("workspace:update:selected-example", (e) => v.workspace().workspace.updateSelectedExample(e)), x = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.js","names":[],"sources":["../../src/code-example/mount.ts"],"sourcesContent":["import { ScalarTeleportRoot } from '@scalar/components/teleport'\nimport type { AvailableClients } from '@scalar/snippetz'\nimport type { WorkspaceStore } from '@scalar/workspace-store/client'\nimport { createWorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { getPathItemOperation } from '@scalar/workspace-store/helpers/for-each-path-item-operation'\nimport { getFirstServer } from '@scalar/workspace-store/helpers/get-first-server'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { EXTERNAL_EXAMPLES } from '@scalar/workspace-store/helpers/use-external-examples'\nimport { generateClientMutators } from '@scalar/workspace-store/mutators'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { createApp, h, reactive } from 'vue'\n\nimport CodeExample, { type CodeExampleProps } from './components/CodeExample.vue'\nimport { generateClientOptions } from './helpers/generate-client-options'\n\nexport type CreateCodeExampleOptions = {\n /** Localized status text shown when the selected example has no linked code sample. */\n codeSampleUnavailable?: string\n /** Localized accessible name for the focusable code sample scroller. */\n codeSampleLabel?: string\n /** Workspace store that holds the OpenAPI document(s) to render from. */\n store: WorkspaceStore\n /** Path of the operation to render, e.g. '/users/{id}'. */\n path: string\n /** HTTP method of the operation to render. */\n method: string\n /** Pre-selected client ID, e.g. 'shell/curl'. */\n selectedClient?: AvailableClients[number]\n /**\n * Server object override used to build the example request.\n *\n * When omitted, the server is derived from the active document (operation,\n * then path item, then document level), mirroring the API reference. Pass\n * `null` to force \"no server\".\n */\n selectedServer?: ServerObject | null\n /**\n * Pre-selected example key for parameters and the request body.\n *\n * The store is the source of truth once an example is picked, so\n * `x-scalar-default-example` wins over this initial seed and the selection\n * round-trips through the store like the client selection does.\n */\n selectedExample?: string\n /** Security schemes applicable to the operation. */\n securitySchemes?: SecuritySchemeObjectSecret[]\n /**\n * Force a color mode on the rendered block.\n *\n * When omitted, the block inherits the ambient theme of the host page.\n * Pass `true` for dark mode or `false` for light mode.\n */\n darkMode?: boolean\n}\n\n/**\n * Builds the wrapper classes for the mounted block.\n *\n * The `.scalar-app` class scopes the Tailwind utilities, and the optional\n * color-mode class lets consumers pin the block to dark or light.\n */\nconst getWrapperClass = (darkMode: boolean | undefined): string =>\n ['scalar-app', darkMode === true ? 'dark-mode' : darkMode === false ? 'light-mode' : ''].filter(Boolean).join(' ')\n\n/**\n * Mount the CodeExample block to a DOM element without Vue.\n *\n * The consumer creates and controls their own workspace store,\n * then passes it in along with the path and method to render.\n */\nexport const createCodeExample = (el: HTMLElement | string, options: CreateCodeExampleOptions) => {\n const element = typeof el === 'string' ? document.querySelector(el) : el\n if (!element) {\n throw new Error(`Element not found: ${el}`)\n }\n\n const eventBus = createWorkspaceEventBus()\n const clientOptions = generateClientOptions()\n\n // Persist client changes back to the store. The block emits\n // `workspace:update:selected-client` on its private bus when the user picks a\n // client; without this subscription the choice would never reach the store\n // and `x-scalar-default-client` (the source of truth read below) would stay\n // stale, so the selection would not survive a re-render or be shared with\n // other blocks reading from the same store.\n const mutators = generateClientMutators(options.store)\n const unsubscribeClient = eventBus.on('workspace:update:selected-client', (payload) =>\n mutators.workspace().workspace.updateSelectedClient(payload),\n )\n\n // Persist example changes back to the store as well, mirroring the client\n // round-trip above. The block emits `workspace:update:selected-example` when\n // the user picks an example; without this the choice would never reach\n // `x-scalar-default-example` (read below) and would neither survive a\n // re-render nor sync to other blocks reading from the same store.\n const unsubscribeExample = eventBus.on('workspace:update:selected-example', (payload) =>\n mutators.workspace().workspace.updateSelectedExample(payload),\n )\n\n type OperationContext = { operation: OperationObject; server: ServerObject | null }\n\n /**\n * Resolve the operation and its effective server from the active document.\n *\n * The server is resolved from the same document the operation came from\n * (operation, then path item, then document level), so a snippet never pairs\n * an operation with a server URL from a different spec.\n */\n const resolveContext = (): OperationContext | undefined => {\n // The active document may be an AsyncAPI document, which has no `paths`.\n const activeDocument = options.store.workspace.activeDocument\n if (!activeDocument || !('paths' in activeDocument)) {\n return undefined\n }\n const pathItem = getResolvedRef(activeDocument.paths?.[options.path])\n const operation = getResolvedRef(getPathItemOperation(pathItem, options.method))\n if (!operation) {\n return undefined\n }\n const server = getFirstServer(operation.servers ?? null, pathItem?.servers ?? null, activeDocument.servers ?? null)\n return { operation, server }\n }\n\n // Fail loudly if the path and method do not point at an operation in the store,\n // mirroring the \"element not found\" guard above.\n if (!resolveContext()) {\n throw new Error(`Operation not found: ${options.method.toUpperCase()} ${options.path}`)\n }\n\n // Remember the last context that resolved so a transient miss (e.g. the active\n // document is swapped to one without this path or method after mount) keeps\n // rendering the previous operation, paired with the server it actually came\n // from, instead of feeding `undefined` to the block.\n let lastContext: OperationContext | undefined\n\n /** Current operation + server, falling back to the last good resolution on a transient miss. */\n const currentContext = (): OperationContext => {\n const context = resolveContext()\n if (context) {\n lastContext = context\n }\n return (context ?? lastContext) as OperationContext\n }\n\n // Props are getters so the block tracks the reactive store (active document,\n // `x-scalar-default-client`, `x-scalar-default-example`) live. Change the\n // client, example, or server through the store to drive re-renders.\n const props = reactive<CodeExampleProps>({\n get codeSampleUnavailable() {\n return options.codeSampleUnavailable\n },\n get codeSampleLabel() {\n return options.codeSampleLabel\n },\n get operation(): OperationObject {\n return currentContext().operation\n },\n get method() {\n return options.method\n },\n get path() {\n return options.path\n },\n clientOptions,\n eventBus,\n get securitySchemes() {\n return options.securitySchemes ?? []\n },\n get selectedClient() {\n // The store is the source of truth once the user picks a client, so it\n // wins over the initial `options.selectedClient` seed and the selection\n // round-trips through the subscription above.\n return options.store.workspace['x-scalar-default-client'] ?? options.selectedClient\n },\n get selectedExample() {\n // Same as the client: the store wins over the initial seed so the example\n // selection survives re-renders and syncs across blocks.\n return options.store.workspace['x-scalar-default-example'] ?? options.selectedExample\n },\n get selectedServer() {\n // An explicit option wins (including an explicit `null` for \"no server\");\n // otherwise derive it from the same document the operation resolved from.\n return options.selectedServer !== undefined ? options.selectedServer : currentContext().server\n },\n })\n\n // Render the operation path in the header by default. The reference renders\n // this via the `#header` slot too, so the standalone block matches its look.\n const renderHeader = () => h('span', { class: 'font-code text-c-2 min-w-0 truncate' }, options.path)\n\n // Wrap the block in its own teleport root so floating UI (the client picker\n // popover) renders inside the themed `.scalar-app` wrapper instead of escaping\n // to `body`, where it would miss the color-mode variables and lose its styling.\n const app = createApp(() =>\n h('div', { class: getWrapperClass(options.darkMode) }, [\n h(ScalarTeleportRoot, null, { default: () => h(CodeExample, props, { header: renderHeader }) }),\n ]),\n )\n\n app.provide(EXTERNAL_EXAMPLES, () => options.store.externalExamples())\n app.mount(element)\n\n return {\n app,\n destroy: () => {\n unsubscribeClient()\n unsubscribeExample()\n app.unmount()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;AA8DA,IAAM,KAAmB,MACvB,CAAC,cAAc,MAAa,KAAO,cAAc,MAAa,KAAQ,eAAe,EAAE,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,GAQtG,KAAqB,GAA0B,MAAsC;CAChG,IAAM,IAAU,OAAO,KAAO,WAAW,SAAS,cAAc,CAAE,IAAI;CACtE,IAAI,CAAC,GACH,MAAU,MAAM,sBAAsB,GAAI;CAG5C,IAAM,IAAW,EAAwB,GACnC,IAAgB,EAAsB,GAQtC,IAAW,EAAuB,EAAQ,KAAK,GAC/C,IAAoB,EAAS,GAAG,qCAAqC,MACzE,EAAS,UAAU,CAAC,CAAC,UAAU,qBAAqB,CAAO,CAC7D,GAOM,IAAqB,EAAS,GAAG,sCAAsC,MAC3E,EAAS,UAAU,CAAC,CAAC,UAAU,sBAAsB,CAAO,CAC9D,GA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MAAM,EAAE,eAAe,EAAE,GAAa,GAAO,EAAE,QAAQ,EAAa,CAAC,EAAE,CAAC,CAChG,CAAC,CACH;CAKA,OAHA,EAAI,QAAQ,SAAyB,EAAQ,MAAM,iBAAiB,CAAC,GACrE,EAAI,MAAM,CAAO,GAEV;EACL;EACA,eAAe;GAGb,AAFA,EAAkB,GAClB,EAAmB,GACnB,EAAI,QAAQ;EACd;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"mount.js","names":[],"sources":["../../src/code-example/mount.ts"],"sourcesContent":["import { ScalarTeleportRoot } from '@scalar/components/teleport'\nimport type { AvailableClients } from '@scalar/snippetz'\nimport type { WorkspaceStore } from '@scalar/workspace-store/client'\nimport { createWorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { getPathItemOperation } from '@scalar/workspace-store/helpers/for-each-path-item-operation'\nimport { getFirstServer } from '@scalar/workspace-store/helpers/get-first-server'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { EXTERNAL_EXAMPLES } from '@scalar/workspace-store/helpers/use-external-examples'\nimport { generateClientMutators } from '@scalar/workspace-store/mutators'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { createApp, h, reactive } from 'vue'\n\nimport CodeExample, { type CodeExampleProps } from './components/CodeExample.vue'\nimport { generateClientOptions } from './helpers/generate-client-options'\n\nexport type CreateCodeExampleOptions = {\n /** Localized status text shown when the selected example has no linked code sample. */\n codeSampleUnavailable?: string\n /** Localized accessible name for the focusable code sample scroller. */\n codeSampleLabel?: string\n /** Workspace store that holds the OpenAPI document(s) to render from. */\n store: WorkspaceStore\n /** Path of the operation to render, e.g. '/users/{id}'. */\n path: string\n /** HTTP method of the operation to render. */\n method: string\n /** Pre-selected client ID, e.g. 'shell/curl'. */\n selectedClient?: AvailableClients[number]\n /**\n * Server object override used to build the example request.\n *\n * When omitted, the server is derived from the active document (operation,\n * then path item, then document level), mirroring the API reference. Pass\n * `null` to force \"no server\".\n */\n selectedServer?: ServerObject | null\n /**\n * Pre-selected example key for parameters and the request body.\n *\n * The store is the source of truth once an example is picked, so\n * `x-scalar-default-example` wins over this initial seed and the selection\n * round-trips through the store like the client selection does.\n */\n selectedExample?: string\n /** Security schemes applicable to the operation. */\n securitySchemes?: SecuritySchemeObjectSecret[]\n /**\n * Force a color mode on the rendered block.\n *\n * When omitted, the block inherits the ambient theme of the host page.\n * Pass `true` for dark mode or `false` for light mode.\n */\n darkMode?: boolean\n}\n\n/**\n * Builds the wrapper classes for the mounted block.\n *\n * The `.scalar-app` class scopes the Tailwind utilities, and the optional\n * color-mode class lets consumers pin the block to dark or light.\n */\nconst getWrapperClass = (darkMode: boolean | undefined): string => {\n if (darkMode === true) {\n return 'scalar-app dark-mode'\n }\n if (darkMode === false) {\n return 'scalar-app light-mode'\n }\n return 'scalar-app'\n}\n\n/**\n * Mount the CodeExample block to a DOM element without Vue.\n *\n * The consumer creates and controls their own workspace store,\n * then passes it in along with the path and method to render.\n */\nexport const createCodeExample = (el: HTMLElement | string, options: CreateCodeExampleOptions) => {\n const element = typeof el === 'string' ? document.querySelector(el) : el\n if (!element) {\n throw new Error(`Element not found: ${el}`)\n }\n\n const eventBus = createWorkspaceEventBus()\n const clientOptions = generateClientOptions()\n\n // Persist client changes back to the store. The block emits\n // `workspace:update:selected-client` on its private bus when the user picks a\n // client; without this subscription the choice would never reach the store\n // and `x-scalar-default-client` (the source of truth read below) would stay\n // stale, so the selection would not survive a re-render or be shared with\n // other blocks reading from the same store.\n const mutators = generateClientMutators(options.store)\n const unsubscribeClient = eventBus.on('workspace:update:selected-client', (payload) =>\n mutators.workspace().workspace.updateSelectedClient(payload),\n )\n\n // Persist example changes back to the store as well, mirroring the client\n // round-trip above. The block emits `workspace:update:selected-example` when\n // the user picks an example; without this the choice would never reach\n // `x-scalar-default-example` (read below) and would neither survive a\n // re-render nor sync to other blocks reading from the same store.\n const unsubscribeExample = eventBus.on('workspace:update:selected-example', (payload) =>\n mutators.workspace().workspace.updateSelectedExample(payload),\n )\n\n type OperationContext = { operation: OperationObject; server: ServerObject | null }\n\n /**\n * Resolve the operation and its effective server from the active document.\n *\n * The server is resolved from the same document the operation came from\n * (operation, then path item, then document level), so a snippet never pairs\n * an operation with a server URL from a different spec.\n */\n const resolveContext = (): OperationContext | undefined => {\n // The active document may be an AsyncAPI document, which has no `paths`.\n const activeDocument = options.store.workspace.activeDocument\n if (!activeDocument || !('paths' in activeDocument)) {\n return undefined\n }\n const pathItem = getResolvedRef(activeDocument.paths?.[options.path])\n const operation = getResolvedRef(getPathItemOperation(pathItem, options.method))\n if (!operation) {\n return undefined\n }\n const server = getFirstServer(operation.servers ?? null, pathItem?.servers ?? null, activeDocument.servers ?? null)\n return { operation, server }\n }\n\n // Fail loudly if the path and method do not point at an operation in the store,\n // mirroring the \"element not found\" guard above.\n if (!resolveContext()) {\n throw new Error(`Operation not found: ${options.method.toUpperCase()} ${options.path}`)\n }\n\n // Remember the last context that resolved so a transient miss (e.g. the active\n // document is swapped to one without this path or method after mount) keeps\n // rendering the previous operation, paired with the server it actually came\n // from, instead of feeding `undefined` to the block.\n let lastContext: OperationContext | undefined\n\n /** Current operation + server, falling back to the last good resolution on a transient miss. */\n const currentContext = (): OperationContext => {\n const context = resolveContext()\n if (context) {\n lastContext = context\n }\n return (context ?? lastContext) as OperationContext\n }\n\n // Props are getters so the block tracks the reactive store (active document,\n // `x-scalar-default-client`, `x-scalar-default-example`) live. Change the\n // client, example, or server through the store to drive re-renders.\n const props = reactive<CodeExampleProps>({\n get codeSampleUnavailable() {\n return options.codeSampleUnavailable\n },\n get codeSampleLabel() {\n return options.codeSampleLabel\n },\n get operation(): OperationObject {\n return currentContext().operation\n },\n get method() {\n return options.method\n },\n get path() {\n return options.path\n },\n clientOptions,\n eventBus,\n get securitySchemes() {\n return options.securitySchemes ?? []\n },\n get selectedClient() {\n // The store is the source of truth once the user picks a client, so it\n // wins over the initial `options.selectedClient` seed and the selection\n // round-trips through the subscription above.\n return options.store.workspace['x-scalar-default-client'] ?? options.selectedClient\n },\n get selectedExample() {\n // Same as the client: the store wins over the initial seed so the example\n // selection survives re-renders and syncs across blocks.\n return options.store.workspace['x-scalar-default-example'] ?? options.selectedExample\n },\n get selectedServer() {\n // An explicit option wins (including an explicit `null` for \"no server\");\n // otherwise derive it from the same document the operation resolved from.\n return options.selectedServer !== undefined ? options.selectedServer : currentContext().server\n },\n })\n\n // Render the operation path in the header by default. The reference renders\n // this via the `#header` slot too, so the standalone block matches its look.\n const renderHeader = () => h('span', { class: 'font-code text-c-2 min-w-0 truncate' }, options.path)\n\n // Wrap the block in its own teleport root so floating UI (the client picker\n // popover) renders inside the themed `.scalar-app` wrapper instead of escaping\n // to `body`, where it would miss the color-mode variables and lose its styling.\n const app = createApp(() =>\n h('div', { class: getWrapperClass(options.darkMode) }, [\n h(ScalarTeleportRoot, null, { default: () => h(CodeExample, props, { header: renderHeader }) }),\n ]),\n )\n\n app.provide(EXTERNAL_EXAMPLES, () => options.store.externalExamples())\n app.mount(element)\n\n return {\n app,\n destroy: () => {\n unsubscribeClient()\n unsubscribeExample()\n app.unmount()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;AA8DA,IAAM,KAAmB,MACnB,MAAa,KACR,yBAEL,MAAa,KACR,0BAEF,cASI,KAAqB,GAA0B,MAAsC;CAChG,IAAM,IAAU,OAAO,KAAO,WAAW,SAAS,cAAc,CAAE,IAAI;CACtE,IAAI,CAAC,GACH,MAAU,MAAM,sBAAsB,GAAI;CAG5C,IAAM,IAAW,EAAwB,GACnC,IAAgB,EAAsB,GAQtC,IAAW,EAAuB,EAAQ,KAAK,GAC/C,IAAoB,EAAS,GAAG,qCAAqC,MACzE,EAAS,UAAU,CAAC,CAAC,UAAU,qBAAqB,CAAO,CAC7D,GAOM,IAAqB,EAAS,GAAG,sCAAsC,MAC3E,EAAS,UAAU,CAAC,CAAC,UAAU,sB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