@powerlines/plugin-prisma 0.2.77 → 0.2.78
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/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/api/client/client.gen.cjs +175 -8
- package/dist/api/client/client.gen.mjs +174 -7
- package/dist/api/client/index.cjs +13 -18
- package/dist/api/client/index.mjs +5 -10
- package/dist/api/client/utils.gen.cjs +186 -13
- package/dist/api/client/utils.gen.mjs +178 -5
- package/dist/api/client.gen.cjs +8 -12
- package/dist/api/client.gen.mjs +7 -11
- package/dist/api/core/auth.gen.cjs +11 -2
- package/dist/api/core/auth.gen.mjs +9 -1
- package/dist/api/core/bodySerializer.gen.cjs +34 -4
- package/dist/api/core/bodySerializer.gen.mjs +30 -1
- package/dist/api/core/params.gen.cjs +64 -2
- package/dist/api/core/params.gen.mjs +62 -1
- package/dist/api/core/pathSerializer.gen.cjs +86 -7
- package/dist/api/core/pathSerializer.gen.mjs +79 -1
- package/dist/api/core/queryKeySerializer.gen.cjs +65 -4
- package/dist/api/core/queryKeySerializer.gen.mjs +61 -1
- package/dist/api/core/serverSentEvents.gen.cjs +94 -2
- package/dist/api/core/serverSentEvents.gen.mjs +92 -1
- package/dist/api/core/utils.gen.cjs +80 -6
- package/dist/api/core/utils.gen.mjs +76 -2
- package/dist/api/sdk.gen.cjs +255 -13
- package/dist/api/sdk.gen.mjs +254 -12
- package/dist/api/types.gen.cjs +0 -1
- package/dist/api/types.gen.mjs +0 -2
- package/dist/helpers/get-schema.cjs +80 -2
- package/dist/helpers/get-schema.mjs +76 -1
- package/dist/helpers/index.cjs +6 -6
- package/dist/helpers/index.mjs +3 -3
- package/dist/helpers/prisma-postgres.cjs +15 -2
- package/dist/helpers/prisma-postgres.mjs +13 -1
- package/dist/helpers/schema-creator.cjs +60 -2
- package/dist/helpers/schema-creator.mjs +58 -1
- package/dist/index.cjs +20 -107
- package/dist/index.mjs +8 -96
- package/dist/powerlines/src/plugin-utils/get-config-path.cjs +49 -0
- package/dist/powerlines/src/plugin-utils/get-config-path.mjs +48 -0
- package/dist/powerlines/src/plugin-utils/paths.cjs +36 -0
- package/dist/powerlines/src/plugin-utils/paths.mjs +35 -0
- package/dist/types/index.cjs +0 -3
- package/dist/types/index.mjs +0 -4
- package/dist/types/plugin.cjs +0 -1
- package/dist/types/plugin.mjs +0 -2
- package/dist/types/prisma.cjs +0 -1
- package/dist/types/prisma.mjs +0 -2
- package/package.json +6 -6
- package/dist/auth.gen-BFteuMTV.cjs +0 -17
- package/dist/auth.gen-C4FxE4_3.mjs +0 -11
- package/dist/bodySerializer.gen-BLtxkFoA.cjs +0 -50
- package/dist/bodySerializer.gen-DBXNewIA.mjs +0 -32
- package/dist/client-BlRUW8mL.mjs +0 -1
- package/dist/client-DBAc9HV1.cjs +0 -0
- package/dist/client.gen-COMS1glH.mjs +0 -8
- package/dist/client.gen-CPQm4WCv.mjs +0 -176
- package/dist/client.gen-DPSMNZNm.cjs +0 -181
- package/dist/client.gen-JhYC1fDf.cjs +0 -13
- package/dist/get-schema-CKw6MiKb.mjs +0 -78
- package/dist/get-schema-CqMBOHOd.cjs +0 -118
- package/dist/params.gen-BM1l95BD.mjs +0 -64
- package/dist/params.gen-BtCSnwiV.cjs +0 -70
- package/dist/pathSerializer.gen-BEbuI0Vn.cjs +0 -117
- package/dist/pathSerializer.gen-m7BRzH23.mjs +0 -81
- package/dist/plugin-DE9fKOLA.cjs +0 -0
- package/dist/plugin-EFmNQLKA.mjs +0 -1
- package/dist/prisma-BzQJneyW.cjs +0 -0
- package/dist/prisma-CB-m5c-j.mjs +0 -1
- package/dist/prisma-postgres-CAOpTtWq.mjs +0 -15
- package/dist/prisma-postgres-dGaLzxF3.cjs +0 -21
- package/dist/queryKeySerializer.gen-4TWHHXn3.cjs +0 -81
- package/dist/queryKeySerializer.gen-BMMZAjVN.mjs +0 -63
- package/dist/schema-creator-Cfian3ih.mjs +0 -60
- package/dist/schema-creator-zmlwh4-l.cjs +0 -66
- package/dist/sdk.gen-B2his2jD.mjs +0 -256
- package/dist/sdk.gen-CAWIQ8BM.cjs +0 -261
- package/dist/serverSentEvents.gen-C4apQvDl.mjs +0 -94
- package/dist/serverSentEvents.gen-CiMMmhyQ.cjs +0 -100
- package/dist/types-CmY9-4ff.cjs +0 -0
- package/dist/types-Dbwx-Khg.mjs +0 -1
- package/dist/types.gen-BN-p9nVT.cjs +0 -0
- package/dist/types.gen-CS2KiRfG.mjs +0 -1
- package/dist/utils.gen-Bk2pTkV1.cjs +0 -101
- package/dist/utils.gen-C-7sZa7Z.mjs +0 -180
- package/dist/utils.gen-DATakax-.cjs +0 -227
- package/dist/utils.gen-RO8GxC4i.mjs +0 -78
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
//#region src/api/core/serverSentEvents.gen.ts
|
|
2
|
-
const createSseClient = ({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
|
|
3
|
-
let lastEventId;
|
|
4
|
-
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
5
|
-
const createStream = async function* () {
|
|
6
|
-
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
7
|
-
let attempt = 0;
|
|
8
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
9
|
-
while (true) {
|
|
10
|
-
if (signal.aborted) break;
|
|
11
|
-
attempt++;
|
|
12
|
-
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
13
|
-
if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
|
|
14
|
-
try {
|
|
15
|
-
const requestInit = {
|
|
16
|
-
redirect: "follow",
|
|
17
|
-
...options,
|
|
18
|
-
body: options.serializedBody,
|
|
19
|
-
headers,
|
|
20
|
-
signal
|
|
21
|
-
};
|
|
22
|
-
let request = new Request(url, requestInit);
|
|
23
|
-
if (onRequest) request = await onRequest(url, requestInit);
|
|
24
|
-
const response = await (options.fetch ?? globalThis.fetch)(request);
|
|
25
|
-
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
26
|
-
if (!response.body) throw new Error("No body in SSE response");
|
|
27
|
-
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
28
|
-
let buffer = "";
|
|
29
|
-
const abortHandler = () => {
|
|
30
|
-
try {
|
|
31
|
-
reader.cancel();
|
|
32
|
-
} catch {}
|
|
33
|
-
};
|
|
34
|
-
signal.addEventListener("abort", abortHandler);
|
|
35
|
-
try {
|
|
36
|
-
while (true) {
|
|
37
|
-
const { done, value } = await reader.read();
|
|
38
|
-
if (done) break;
|
|
39
|
-
buffer += value;
|
|
40
|
-
buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
41
|
-
const chunks = buffer.split("\n\n");
|
|
42
|
-
buffer = chunks.pop() ?? "";
|
|
43
|
-
for (const chunk of chunks) {
|
|
44
|
-
const lines = chunk.split("\n");
|
|
45
|
-
const dataLines = [];
|
|
46
|
-
let eventName;
|
|
47
|
-
for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
|
|
48
|
-
else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
|
|
49
|
-
else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
|
|
50
|
-
else if (line.startsWith("retry:")) {
|
|
51
|
-
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
52
|
-
if (!Number.isNaN(parsed)) retryDelay = parsed;
|
|
53
|
-
}
|
|
54
|
-
let data;
|
|
55
|
-
let parsedJson = false;
|
|
56
|
-
if (dataLines.length) {
|
|
57
|
-
const rawData = dataLines.join("\n");
|
|
58
|
-
try {
|
|
59
|
-
data = JSON.parse(rawData);
|
|
60
|
-
parsedJson = true;
|
|
61
|
-
} catch {
|
|
62
|
-
data = rawData;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (parsedJson) {
|
|
66
|
-
if (responseValidator) await responseValidator(data);
|
|
67
|
-
if (responseTransformer) data = await responseTransformer(data);
|
|
68
|
-
}
|
|
69
|
-
onSseEvent?.({
|
|
70
|
-
data,
|
|
71
|
-
event: eventName,
|
|
72
|
-
id: lastEventId,
|
|
73
|
-
retry: retryDelay
|
|
74
|
-
});
|
|
75
|
-
if (dataLines.length) yield data;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
} finally {
|
|
79
|
-
signal.removeEventListener("abort", abortHandler);
|
|
80
|
-
reader.releaseLock();
|
|
81
|
-
}
|
|
82
|
-
break;
|
|
83
|
-
} catch (error) {
|
|
84
|
-
onSseError?.(error);
|
|
85
|
-
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
|
|
86
|
-
await sleep(Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
return { stream: createStream() };
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
//#endregion
|
|
94
|
-
export { createSseClient as t };
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/api/core/serverSentEvents.gen.ts
|
|
3
|
-
const createSseClient = ({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
|
|
4
|
-
let lastEventId;
|
|
5
|
-
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
6
|
-
const createStream = async function* () {
|
|
7
|
-
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
8
|
-
let attempt = 0;
|
|
9
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
10
|
-
while (true) {
|
|
11
|
-
if (signal.aborted) break;
|
|
12
|
-
attempt++;
|
|
13
|
-
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
14
|
-
if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
|
|
15
|
-
try {
|
|
16
|
-
const requestInit = {
|
|
17
|
-
redirect: "follow",
|
|
18
|
-
...options,
|
|
19
|
-
body: options.serializedBody,
|
|
20
|
-
headers,
|
|
21
|
-
signal
|
|
22
|
-
};
|
|
23
|
-
let request = new Request(url, requestInit);
|
|
24
|
-
if (onRequest) request = await onRequest(url, requestInit);
|
|
25
|
-
const response = await (options.fetch ?? globalThis.fetch)(request);
|
|
26
|
-
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
27
|
-
if (!response.body) throw new Error("No body in SSE response");
|
|
28
|
-
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
29
|
-
let buffer = "";
|
|
30
|
-
const abortHandler = () => {
|
|
31
|
-
try {
|
|
32
|
-
reader.cancel();
|
|
33
|
-
} catch {}
|
|
34
|
-
};
|
|
35
|
-
signal.addEventListener("abort", abortHandler);
|
|
36
|
-
try {
|
|
37
|
-
while (true) {
|
|
38
|
-
const { done, value } = await reader.read();
|
|
39
|
-
if (done) break;
|
|
40
|
-
buffer += value;
|
|
41
|
-
buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
42
|
-
const chunks = buffer.split("\n\n");
|
|
43
|
-
buffer = chunks.pop() ?? "";
|
|
44
|
-
for (const chunk of chunks) {
|
|
45
|
-
const lines = chunk.split("\n");
|
|
46
|
-
const dataLines = [];
|
|
47
|
-
let eventName;
|
|
48
|
-
for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
|
|
49
|
-
else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
|
|
50
|
-
else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
|
|
51
|
-
else if (line.startsWith("retry:")) {
|
|
52
|
-
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
53
|
-
if (!Number.isNaN(parsed)) retryDelay = parsed;
|
|
54
|
-
}
|
|
55
|
-
let data;
|
|
56
|
-
let parsedJson = false;
|
|
57
|
-
if (dataLines.length) {
|
|
58
|
-
const rawData = dataLines.join("\n");
|
|
59
|
-
try {
|
|
60
|
-
data = JSON.parse(rawData);
|
|
61
|
-
parsedJson = true;
|
|
62
|
-
} catch {
|
|
63
|
-
data = rawData;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (parsedJson) {
|
|
67
|
-
if (responseValidator) await responseValidator(data);
|
|
68
|
-
if (responseTransformer) data = await responseTransformer(data);
|
|
69
|
-
}
|
|
70
|
-
onSseEvent?.({
|
|
71
|
-
data,
|
|
72
|
-
event: eventName,
|
|
73
|
-
id: lastEventId,
|
|
74
|
-
retry: retryDelay
|
|
75
|
-
});
|
|
76
|
-
if (dataLines.length) yield data;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
} finally {
|
|
80
|
-
signal.removeEventListener("abort", abortHandler);
|
|
81
|
-
reader.releaseLock();
|
|
82
|
-
}
|
|
83
|
-
break;
|
|
84
|
-
} catch (error) {
|
|
85
|
-
onSseError?.(error);
|
|
86
|
-
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
|
|
87
|
-
await sleep(Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
return { stream: createStream() };
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
//#endregion
|
|
95
|
-
Object.defineProperty(exports, 'createSseClient', {
|
|
96
|
-
enumerable: true,
|
|
97
|
-
get: function () {
|
|
98
|
-
return createSseClient;
|
|
99
|
-
}
|
|
100
|
-
});
|
package/dist/types-CmY9-4ff.cjs
DELETED
|
File without changes
|
package/dist/types-Dbwx-Khg.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
const require_pathSerializer_gen = require('./pathSerializer.gen-BEbuI0Vn.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/api/core/utils.gen.ts
|
|
4
|
-
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
5
|
-
const defaultPathSerializer = ({ path, url: _url }) => {
|
|
6
|
-
let url = _url;
|
|
7
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
8
|
-
if (matches) for (const match of matches) {
|
|
9
|
-
let explode = false;
|
|
10
|
-
let name = match.substring(1, match.length - 1);
|
|
11
|
-
let style = "simple";
|
|
12
|
-
if (name.endsWith("*")) {
|
|
13
|
-
explode = true;
|
|
14
|
-
name = name.substring(0, name.length - 1);
|
|
15
|
-
}
|
|
16
|
-
if (name.startsWith(".")) {
|
|
17
|
-
name = name.substring(1);
|
|
18
|
-
style = "label";
|
|
19
|
-
} else if (name.startsWith(";")) {
|
|
20
|
-
name = name.substring(1);
|
|
21
|
-
style = "matrix";
|
|
22
|
-
}
|
|
23
|
-
const value = path[name];
|
|
24
|
-
if (value === void 0 || value === null) continue;
|
|
25
|
-
if (Array.isArray(value)) {
|
|
26
|
-
url = url.replace(match, require_pathSerializer_gen.serializeArrayParam({
|
|
27
|
-
explode,
|
|
28
|
-
name,
|
|
29
|
-
style,
|
|
30
|
-
value
|
|
31
|
-
}));
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (typeof value === "object") {
|
|
35
|
-
url = url.replace(match, require_pathSerializer_gen.serializeObjectParam({
|
|
36
|
-
explode,
|
|
37
|
-
name,
|
|
38
|
-
style,
|
|
39
|
-
value,
|
|
40
|
-
valueOnly: true
|
|
41
|
-
}));
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (style === "matrix") {
|
|
45
|
-
url = url.replace(match, `;${require_pathSerializer_gen.serializePrimitiveParam({
|
|
46
|
-
name,
|
|
47
|
-
value
|
|
48
|
-
})}`);
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
52
|
-
url = url.replace(match, replaceValue);
|
|
53
|
-
}
|
|
54
|
-
return url;
|
|
55
|
-
};
|
|
56
|
-
const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
57
|
-
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
58
|
-
let url = (baseUrl ?? "") + pathUrl;
|
|
59
|
-
if (path) url = defaultPathSerializer({
|
|
60
|
-
path,
|
|
61
|
-
url
|
|
62
|
-
});
|
|
63
|
-
let search = query ? querySerializer(query) : "";
|
|
64
|
-
if (search.startsWith("?")) search = search.substring(1);
|
|
65
|
-
if (search) url += `?${search}`;
|
|
66
|
-
return url;
|
|
67
|
-
};
|
|
68
|
-
function getValidRequestBody(options) {
|
|
69
|
-
const hasBody = options.body !== void 0;
|
|
70
|
-
if (hasBody && options.bodySerializer) {
|
|
71
|
-
if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
|
|
72
|
-
return options.body !== "" ? options.body : null;
|
|
73
|
-
}
|
|
74
|
-
if (hasBody) return options.body;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
//#endregion
|
|
78
|
-
Object.defineProperty(exports, 'PATH_PARAM_RE', {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function () {
|
|
81
|
-
return PATH_PARAM_RE;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
Object.defineProperty(exports, 'defaultPathSerializer', {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function () {
|
|
87
|
-
return defaultPathSerializer;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(exports, 'getUrl', {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function () {
|
|
93
|
-
return getUrl;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(exports, 'getValidRequestBody', {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
get: function () {
|
|
99
|
-
return getValidRequestBody;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { a as serializeObjectParam, i as serializeArrayParam, o as serializePrimitiveParam } from "./pathSerializer.gen-m7BRzH23.mjs";
|
|
2
|
-
import { r as getUrl } from "./utils.gen-RO8GxC4i.mjs";
|
|
3
|
-
import { t as getAuthToken } from "./auth.gen-C4FxE4_3.mjs";
|
|
4
|
-
import { n as jsonBodySerializer } from "./bodySerializer.gen-DBXNewIA.mjs";
|
|
5
|
-
|
|
6
|
-
//#region src/api/client/utils.gen.ts
|
|
7
|
-
const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
8
|
-
const querySerializer = (queryParams) => {
|
|
9
|
-
const search = [];
|
|
10
|
-
if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
|
|
11
|
-
const value = queryParams[name];
|
|
12
|
-
if (value === void 0 || value === null) continue;
|
|
13
|
-
const options = parameters[name] || args;
|
|
14
|
-
if (Array.isArray(value)) {
|
|
15
|
-
const serializedArray = serializeArrayParam({
|
|
16
|
-
allowReserved: options.allowReserved,
|
|
17
|
-
explode: true,
|
|
18
|
-
name,
|
|
19
|
-
style: "form",
|
|
20
|
-
value,
|
|
21
|
-
...options.array
|
|
22
|
-
});
|
|
23
|
-
if (serializedArray) search.push(serializedArray);
|
|
24
|
-
} else if (typeof value === "object") {
|
|
25
|
-
const serializedObject = serializeObjectParam({
|
|
26
|
-
allowReserved: options.allowReserved,
|
|
27
|
-
explode: true,
|
|
28
|
-
name,
|
|
29
|
-
style: "deepObject",
|
|
30
|
-
value,
|
|
31
|
-
...options.object
|
|
32
|
-
});
|
|
33
|
-
if (serializedObject) search.push(serializedObject);
|
|
34
|
-
} else {
|
|
35
|
-
const serializedPrimitive = serializePrimitiveParam({
|
|
36
|
-
allowReserved: options.allowReserved,
|
|
37
|
-
name,
|
|
38
|
-
value
|
|
39
|
-
});
|
|
40
|
-
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return search.join("&");
|
|
44
|
-
};
|
|
45
|
-
return querySerializer;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Infers parseAs value from provided Content-Type header.
|
|
49
|
-
*/
|
|
50
|
-
const getParseAs = (contentType) => {
|
|
51
|
-
if (!contentType) return "stream";
|
|
52
|
-
const cleanContent = contentType.split(";")[0]?.trim();
|
|
53
|
-
if (!cleanContent) return;
|
|
54
|
-
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
|
|
55
|
-
if (cleanContent === "multipart/form-data") return "formData";
|
|
56
|
-
if ([
|
|
57
|
-
"application/",
|
|
58
|
-
"audio/",
|
|
59
|
-
"image/",
|
|
60
|
-
"video/"
|
|
61
|
-
].some((type) => cleanContent.startsWith(type))) return "blob";
|
|
62
|
-
if (cleanContent.startsWith("text/")) return "text";
|
|
63
|
-
};
|
|
64
|
-
const checkForExistence = (options, name) => {
|
|
65
|
-
if (!name) return false;
|
|
66
|
-
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
|
|
67
|
-
return false;
|
|
68
|
-
};
|
|
69
|
-
const setAuthParams = async ({ security, ...options }) => {
|
|
70
|
-
for (const auth of security) {
|
|
71
|
-
if (checkForExistence(options, auth.name)) continue;
|
|
72
|
-
const token = await getAuthToken(auth, options.auth);
|
|
73
|
-
if (!token) continue;
|
|
74
|
-
const name = auth.name ?? "Authorization";
|
|
75
|
-
switch (auth.in) {
|
|
76
|
-
case "query":
|
|
77
|
-
if (!options.query) options.query = {};
|
|
78
|
-
options.query[name] = token;
|
|
79
|
-
break;
|
|
80
|
-
case "cookie":
|
|
81
|
-
options.headers.append("Cookie", `${name}=${token}`);
|
|
82
|
-
break;
|
|
83
|
-
case "header":
|
|
84
|
-
default:
|
|
85
|
-
options.headers.set(name, token);
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
const buildUrl = (options) => getUrl({
|
|
91
|
-
baseUrl: options.baseUrl,
|
|
92
|
-
path: options.path,
|
|
93
|
-
query: options.query,
|
|
94
|
-
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
95
|
-
url: options.url
|
|
96
|
-
});
|
|
97
|
-
const mergeConfigs = (a, b) => {
|
|
98
|
-
const config = {
|
|
99
|
-
...a,
|
|
100
|
-
...b
|
|
101
|
-
};
|
|
102
|
-
if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
103
|
-
config.headers = mergeHeaders(a.headers, b.headers);
|
|
104
|
-
return config;
|
|
105
|
-
};
|
|
106
|
-
const headersEntries = (headers) => {
|
|
107
|
-
const entries = [];
|
|
108
|
-
headers.forEach((value, key) => {
|
|
109
|
-
entries.push([key, value]);
|
|
110
|
-
});
|
|
111
|
-
return entries;
|
|
112
|
-
};
|
|
113
|
-
const mergeHeaders = (...headers) => {
|
|
114
|
-
const mergedHeaders = new Headers();
|
|
115
|
-
for (const header of headers) {
|
|
116
|
-
if (!header) continue;
|
|
117
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
118
|
-
for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
|
|
119
|
-
else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
|
|
120
|
-
else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
121
|
-
}
|
|
122
|
-
return mergedHeaders;
|
|
123
|
-
};
|
|
124
|
-
var Interceptors = class {
|
|
125
|
-
fns = [];
|
|
126
|
-
clear() {
|
|
127
|
-
this.fns = [];
|
|
128
|
-
}
|
|
129
|
-
eject(id) {
|
|
130
|
-
const index = this.getInterceptorIndex(id);
|
|
131
|
-
if (this.fns[index]) this.fns[index] = null;
|
|
132
|
-
}
|
|
133
|
-
exists(id) {
|
|
134
|
-
const index = this.getInterceptorIndex(id);
|
|
135
|
-
return Boolean(this.fns[index]);
|
|
136
|
-
}
|
|
137
|
-
getInterceptorIndex(id) {
|
|
138
|
-
if (typeof id === "number") return this.fns[id] ? id : -1;
|
|
139
|
-
return this.fns.indexOf(id);
|
|
140
|
-
}
|
|
141
|
-
update(id, fn) {
|
|
142
|
-
const index = this.getInterceptorIndex(id);
|
|
143
|
-
if (this.fns[index]) {
|
|
144
|
-
this.fns[index] = fn;
|
|
145
|
-
return id;
|
|
146
|
-
}
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
use(fn) {
|
|
150
|
-
this.fns.push(fn);
|
|
151
|
-
return this.fns.length - 1;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
const createInterceptors = () => ({
|
|
155
|
-
error: new Interceptors(),
|
|
156
|
-
request: new Interceptors(),
|
|
157
|
-
response: new Interceptors()
|
|
158
|
-
});
|
|
159
|
-
const defaultQuerySerializer = createQuerySerializer({
|
|
160
|
-
allowReserved: false,
|
|
161
|
-
array: {
|
|
162
|
-
explode: true,
|
|
163
|
-
style: "form"
|
|
164
|
-
},
|
|
165
|
-
object: {
|
|
166
|
-
explode: true,
|
|
167
|
-
style: "deepObject"
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
const defaultHeaders = { "Content-Type": "application/json" };
|
|
171
|
-
const createConfig = (override = {}) => ({
|
|
172
|
-
...jsonBodySerializer,
|
|
173
|
-
headers: defaultHeaders,
|
|
174
|
-
parseAs: "auto",
|
|
175
|
-
querySerializer: defaultQuerySerializer,
|
|
176
|
-
...override
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
//#endregion
|
|
180
|
-
export { getParseAs as a, setAuthParams as c, createQuerySerializer as i, createConfig as n, mergeConfigs as o, createInterceptors as r, mergeHeaders as s, buildUrl as t };
|