@powerlines/plugin-prisma 0.4.30 → 0.4.32

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.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/dist/client-generator-AkVOcQPr.mjs +146 -0
  3. package/dist/client-generator-BAc2oiYI.cjs +152 -0
  4. package/dist/client-generator-RH_xLnP1.cjs +152 -0
  5. package/dist/client-generator-cWEc7gzT.mjs +146 -0
  6. package/dist/get-schema-Dq1-Jwvo.cjs +138 -0
  7. package/dist/helpers/client-generator.cjs +4 -0
  8. package/dist/helpers/client-generator.mjs +3 -0
  9. package/dist/helpers/get-schema.cjs +2 -80
  10. package/dist/helpers/get-schema.mjs +24 -4
  11. package/dist/helpers/index.cjs +6 -4
  12. package/dist/helpers/index.mjs +3 -2
  13. package/dist/helpers/schema-creator.cjs +1 -1
  14. package/dist/helpers/typed-sql.cjs +38 -0
  15. package/dist/helpers/typed-sql.mjs +36 -0
  16. package/dist/index.cjs +71 -42
  17. package/dist/index.mjs +68 -38
  18. package/dist/types/index.cjs +2 -0
  19. package/dist/types/index.mjs +3 -0
  20. package/package.json +45 -249
  21. package/dist/_virtual/_rolldown/runtime.cjs +0 -29
  22. package/dist/_virtual/_rolldown/runtime.mjs +0 -3
  23. package/dist/api/client/client.gen.cjs +0 -176
  24. package/dist/api/client/client.gen.mjs +0 -175
  25. package/dist/api/client/index.cjs +0 -15
  26. package/dist/api/client/index.mjs +0 -7
  27. package/dist/api/client/types.gen.cjs +0 -0
  28. package/dist/api/client/types.gen.mjs +0 -1
  29. package/dist/api/client/utils.gen.cjs +0 -187
  30. package/dist/api/client/utils.gen.mjs +0 -179
  31. package/dist/api/client.gen.cjs +0 -10
  32. package/dist/api/client.gen.mjs +0 -9
  33. package/dist/api/core/auth.gen.cjs +0 -13
  34. package/dist/api/core/auth.gen.mjs +0 -11
  35. package/dist/api/core/bodySerializer.gen.cjs +0 -36
  36. package/dist/api/core/bodySerializer.gen.mjs +0 -32
  37. package/dist/api/core/params.gen.cjs +0 -66
  38. package/dist/api/core/params.gen.mjs +0 -64
  39. package/dist/api/core/pathSerializer.gen.cjs +0 -88
  40. package/dist/api/core/pathSerializer.gen.mjs +0 -81
  41. package/dist/api/core/queryKeySerializer.gen.cjs +0 -67
  42. package/dist/api/core/queryKeySerializer.gen.mjs +0 -63
  43. package/dist/api/core/serverSentEvents.gen.cjs +0 -96
  44. package/dist/api/core/serverSentEvents.gen.mjs +0 -94
  45. package/dist/api/core/types.gen.cjs +0 -0
  46. package/dist/api/core/types.gen.mjs +0 -1
  47. package/dist/api/core/utils.gen.cjs +0 -82
  48. package/dist/api/core/utils.gen.mjs +0 -78
  49. package/dist/api/sdk.gen.cjs +0 -405
  50. package/dist/api/sdk.gen.mjs +0 -404
  51. package/dist/api/types.gen.cjs +0 -0
  52. package/dist/api/types.gen.mjs +0 -1
  53. package/dist/generator.cjs +0 -15
  54. package/dist/generator.mjs +0 -15
  55. package/dist/helpers/prisma-postgres.cjs +0 -17
  56. package/dist/helpers/prisma-postgres.mjs +0 -15
@@ -1,179 +0,0 @@
1
- import { jsonBodySerializer } from "../core/bodySerializer.gen.mjs";
2
- import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer.gen.mjs";
3
- import { getUrl } from "../core/utils.gen.mjs";
4
- import { getAuthToken } from "../core/auth.gen.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
- default:
84
- options.headers.set(name, token);
85
- break;
86
- }
87
- }
88
- };
89
- const buildUrl = (options) => getUrl({
90
- baseUrl: options.baseUrl,
91
- path: options.path,
92
- query: options.query,
93
- querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
94
- url: options.url
95
- });
96
- const mergeConfigs = (a, b) => {
97
- const config = {
98
- ...a,
99
- ...b
100
- };
101
- if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
102
- config.headers = mergeHeaders(a.headers, b.headers);
103
- return config;
104
- };
105
- const headersEntries = (headers) => {
106
- const entries = [];
107
- headers.forEach((value, key) => {
108
- entries.push([key, value]);
109
- });
110
- return entries;
111
- };
112
- const mergeHeaders = (...headers) => {
113
- const mergedHeaders = new Headers();
114
- for (const header of headers) {
115
- if (!header) continue;
116
- const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
117
- for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
118
- else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
119
- else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
120
- }
121
- return mergedHeaders;
122
- };
123
- var Interceptors = class {
124
- fns = [];
125
- clear() {
126
- this.fns = [];
127
- }
128
- eject(id) {
129
- const index = this.getInterceptorIndex(id);
130
- if (this.fns[index]) this.fns[index] = null;
131
- }
132
- exists(id) {
133
- const index = this.getInterceptorIndex(id);
134
- return Boolean(this.fns[index]);
135
- }
136
- getInterceptorIndex(id) {
137
- if (typeof id === "number") return this.fns[id] ? id : -1;
138
- return this.fns.indexOf(id);
139
- }
140
- update(id, fn) {
141
- const index = this.getInterceptorIndex(id);
142
- if (this.fns[index]) {
143
- this.fns[index] = fn;
144
- return id;
145
- }
146
- return false;
147
- }
148
- use(fn) {
149
- this.fns.push(fn);
150
- return this.fns.length - 1;
151
- }
152
- };
153
- const createInterceptors = () => ({
154
- error: new Interceptors(),
155
- request: new Interceptors(),
156
- response: new Interceptors()
157
- });
158
- const defaultQuerySerializer = createQuerySerializer({
159
- allowReserved: false,
160
- array: {
161
- explode: true,
162
- style: "form"
163
- },
164
- object: {
165
- explode: true,
166
- style: "deepObject"
167
- }
168
- });
169
- const defaultHeaders = { "Content-Type": "application/json" };
170
- const createConfig = (override = {}) => ({
171
- ...jsonBodySerializer,
172
- headers: defaultHeaders,
173
- parseAs: "auto",
174
- querySerializer: defaultQuerySerializer,
175
- ...override
176
- });
177
-
178
- //#endregion
179
- export { buildUrl, createConfig, createInterceptors, createQuerySerializer, getParseAs, mergeConfigs, mergeHeaders, setAuthParams };
@@ -1,10 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_api_client_utils_gen = require('./client/utils.gen.cjs');
3
- const require_api_client_client_gen = require('./client/client.gen.cjs');
4
- require('./client/index.cjs');
5
-
6
- //#region src/api/client.gen.ts
7
- const client = require_api_client_client_gen.createClient(require_api_client_utils_gen.createConfig({ throwOnError: true }));
8
-
9
- //#endregion
10
- exports.client = client;
@@ -1,9 +0,0 @@
1
- import { createConfig } from "./client/utils.gen.mjs";
2
- import { createClient } from "./client/client.gen.mjs";
3
- import "./client/index.mjs";
4
-
5
- //#region src/api/client.gen.ts
6
- const client = createClient(createConfig({ throwOnError: true }));
7
-
8
- //#endregion
9
- export { client };
@@ -1,13 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- //#region src/api/core/auth.gen.ts
4
- const getAuthToken = async (auth, callback) => {
5
- const token = typeof callback === "function" ? await callback(auth) : callback;
6
- if (!token) return;
7
- if (auth.scheme === "bearer") return `Bearer ${token}`;
8
- if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
9
- return token;
10
- };
11
-
12
- //#endregion
13
- exports.getAuthToken = getAuthToken;
@@ -1,11 +0,0 @@
1
- //#region src/api/core/auth.gen.ts
2
- const getAuthToken = async (auth, callback) => {
3
- const token = typeof callback === "function" ? await callback(auth) : callback;
4
- if (!token) return;
5
- if (auth.scheme === "bearer") return `Bearer ${token}`;
6
- if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
7
- return token;
8
- };
9
-
10
- //#endregion
11
- export { getAuthToken };
@@ -1,36 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- //#region src/api/core/bodySerializer.gen.ts
4
- const serializeFormDataPair = (data, key, value) => {
5
- if (typeof value === "string" || value instanceof Blob) data.append(key, value);
6
- else if (value instanceof Date) data.append(key, value.toISOString());
7
- else data.append(key, JSON.stringify(value));
8
- };
9
- const serializeUrlSearchParamsPair = (data, key, value) => {
10
- if (typeof value === "string") data.append(key, value);
11
- else data.append(key, JSON.stringify(value));
12
- };
13
- const formDataBodySerializer = { bodySerializer: (body) => {
14
- const data = new FormData();
15
- Object.entries(body).forEach(([key, value]) => {
16
- if (value === void 0 || value === null) return;
17
- if (Array.isArray(value)) value.forEach((v) => serializeFormDataPair(data, key, v));
18
- else serializeFormDataPair(data, key, value);
19
- });
20
- return data;
21
- } };
22
- const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
23
- const urlSearchParamsBodySerializer = { bodySerializer: (body) => {
24
- const data = new URLSearchParams();
25
- Object.entries(body).forEach(([key, value]) => {
26
- if (value === void 0 || value === null) return;
27
- if (Array.isArray(value)) value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
28
- else serializeUrlSearchParamsPair(data, key, value);
29
- });
30
- return data.toString();
31
- } };
32
-
33
- //#endregion
34
- exports.formDataBodySerializer = formDataBodySerializer;
35
- exports.jsonBodySerializer = jsonBodySerializer;
36
- exports.urlSearchParamsBodySerializer = urlSearchParamsBodySerializer;
@@ -1,32 +0,0 @@
1
- //#region src/api/core/bodySerializer.gen.ts
2
- const serializeFormDataPair = (data, key, value) => {
3
- if (typeof value === "string" || value instanceof Blob) data.append(key, value);
4
- else if (value instanceof Date) data.append(key, value.toISOString());
5
- else data.append(key, JSON.stringify(value));
6
- };
7
- const serializeUrlSearchParamsPair = (data, key, value) => {
8
- if (typeof value === "string") data.append(key, value);
9
- else data.append(key, JSON.stringify(value));
10
- };
11
- const formDataBodySerializer = { bodySerializer: (body) => {
12
- const data = new FormData();
13
- Object.entries(body).forEach(([key, value]) => {
14
- if (value === void 0 || value === null) return;
15
- if (Array.isArray(value)) value.forEach((v) => serializeFormDataPair(data, key, v));
16
- else serializeFormDataPair(data, key, value);
17
- });
18
- return data;
19
- } };
20
- const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
21
- const urlSearchParamsBodySerializer = { bodySerializer: (body) => {
22
- const data = new URLSearchParams();
23
- Object.entries(body).forEach(([key, value]) => {
24
- if (value === void 0 || value === null) return;
25
- if (Array.isArray(value)) value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
26
- else serializeUrlSearchParamsPair(data, key, value);
27
- });
28
- return data.toString();
29
- } };
30
-
31
- //#endregion
32
- export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer };
@@ -1,66 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- //#region src/api/core/params.gen.ts
4
- const extraPrefixes = Object.entries({
5
- $body_: "body",
6
- $headers_: "headers",
7
- $path_: "path",
8
- $query_: "query"
9
- });
10
- const buildKeyMap = (fields, map) => {
11
- if (!map) map = /* @__PURE__ */ new Map();
12
- for (const config of fields) if ("in" in config) {
13
- if (config.key) map.set(config.key, {
14
- in: config.in,
15
- map: config.map
16
- });
17
- } else if ("key" in config) map.set(config.key, { map: config.map });
18
- else if (config.args) buildKeyMap(config.args, map);
19
- return map;
20
- };
21
- const stripEmptySlots = (params) => {
22
- for (const [slot, value] of Object.entries(params)) if (value && typeof value === "object" && !Object.keys(value).length) delete params[slot];
23
- };
24
- const buildClientParams = (args, fields) => {
25
- const params = {
26
- body: {},
27
- headers: {},
28
- path: {},
29
- query: {}
30
- };
31
- const map = buildKeyMap(fields);
32
- let config;
33
- for (const [index, arg] of args.entries()) {
34
- if (fields[index]) config = fields[index];
35
- if (!config) continue;
36
- if ("in" in config) if (config.key) {
37
- const field = map.get(config.key);
38
- const name = field.map || config.key;
39
- if (field.in) params[field.in][name] = arg;
40
- } else params.body = arg;
41
- else for (const [key, value] of Object.entries(arg ?? {})) {
42
- const field = map.get(key);
43
- if (field) if (field.in) {
44
- const name = field.map || key;
45
- params[field.in][name] = value;
46
- } else params[field.map] = value;
47
- else {
48
- const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
49
- if (extra) {
50
- const [prefix, slot] = extra;
51
- params[slot][key.slice(prefix.length)] = value;
52
- } else if ("allowExtra" in config && config.allowExtra) {
53
- for (const [slot, allowed] of Object.entries(config.allowExtra)) if (allowed) {
54
- params[slot][key] = value;
55
- break;
56
- }
57
- }
58
- }
59
- }
60
- }
61
- stripEmptySlots(params);
62
- return params;
63
- };
64
-
65
- //#endregion
66
- exports.buildClientParams = buildClientParams;
@@ -1,64 +0,0 @@
1
- //#region src/api/core/params.gen.ts
2
- const extraPrefixes = Object.entries({
3
- $body_: "body",
4
- $headers_: "headers",
5
- $path_: "path",
6
- $query_: "query"
7
- });
8
- const buildKeyMap = (fields, map) => {
9
- if (!map) map = /* @__PURE__ */ new Map();
10
- for (const config of fields) if ("in" in config) {
11
- if (config.key) map.set(config.key, {
12
- in: config.in,
13
- map: config.map
14
- });
15
- } else if ("key" in config) map.set(config.key, { map: config.map });
16
- else if (config.args) buildKeyMap(config.args, map);
17
- return map;
18
- };
19
- const stripEmptySlots = (params) => {
20
- for (const [slot, value] of Object.entries(params)) if (value && typeof value === "object" && !Object.keys(value).length) delete params[slot];
21
- };
22
- const buildClientParams = (args, fields) => {
23
- const params = {
24
- body: {},
25
- headers: {},
26
- path: {},
27
- query: {}
28
- };
29
- const map = buildKeyMap(fields);
30
- let config;
31
- for (const [index, arg] of args.entries()) {
32
- if (fields[index]) config = fields[index];
33
- if (!config) continue;
34
- if ("in" in config) if (config.key) {
35
- const field = map.get(config.key);
36
- const name = field.map || config.key;
37
- if (field.in) params[field.in][name] = arg;
38
- } else params.body = arg;
39
- else for (const [key, value] of Object.entries(arg ?? {})) {
40
- const field = map.get(key);
41
- if (field) if (field.in) {
42
- const name = field.map || key;
43
- params[field.in][name] = value;
44
- } else params[field.map] = value;
45
- else {
46
- const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
47
- if (extra) {
48
- const [prefix, slot] = extra;
49
- params[slot][key.slice(prefix.length)] = value;
50
- } else if ("allowExtra" in config && config.allowExtra) {
51
- for (const [slot, allowed] of Object.entries(config.allowExtra)) if (allowed) {
52
- params[slot][key] = value;
53
- break;
54
- }
55
- }
56
- }
57
- }
58
- }
59
- stripEmptySlots(params);
60
- return params;
61
- };
62
-
63
- //#endregion
64
- export { buildClientParams };
@@ -1,88 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- //#region src/api/core/pathSerializer.gen.ts
4
- const separatorArrayExplode = (style) => {
5
- switch (style) {
6
- case "label": return ".";
7
- case "matrix": return ";";
8
- case "simple": return ",";
9
- default: return "&";
10
- }
11
- };
12
- const separatorArrayNoExplode = (style) => {
13
- switch (style) {
14
- case "form": return ",";
15
- case "pipeDelimited": return "|";
16
- case "spaceDelimited": return "%20";
17
- default: return ",";
18
- }
19
- };
20
- const separatorObjectExplode = (style) => {
21
- switch (style) {
22
- case "label": return ".";
23
- case "matrix": return ";";
24
- case "simple": return ",";
25
- default: return "&";
26
- }
27
- };
28
- const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
29
- if (!explode) {
30
- const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
31
- switch (style) {
32
- case "label": return `.${joinedValues}`;
33
- case "matrix": return `;${name}=${joinedValues}`;
34
- case "simple": return joinedValues;
35
- default: return `${name}=${joinedValues}`;
36
- }
37
- }
38
- const separator = separatorArrayExplode(style);
39
- const joinedValues = value.map((v) => {
40
- if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
41
- return serializePrimitiveParam({
42
- allowReserved,
43
- name,
44
- value: v
45
- });
46
- }).join(separator);
47
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
48
- };
49
- const serializePrimitiveParam = ({ allowReserved, name, value }) => {
50
- if (value === void 0 || value === null) return "";
51
- if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
52
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
53
- };
54
- const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
55
- if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
56
- if (style !== "deepObject" && !explode) {
57
- let values = [];
58
- Object.entries(value).forEach(([key, v]) => {
59
- values = [
60
- ...values,
61
- key,
62
- allowReserved ? v : encodeURIComponent(v)
63
- ];
64
- });
65
- const joinedValues = values.join(",");
66
- switch (style) {
67
- case "form": return `${name}=${joinedValues}`;
68
- case "label": return `.${joinedValues}`;
69
- case "matrix": return `;${name}=${joinedValues}`;
70
- default: return joinedValues;
71
- }
72
- }
73
- const separator = separatorObjectExplode(style);
74
- const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
75
- allowReserved,
76
- name: style === "deepObject" ? `${name}[${key}]` : key,
77
- value: v
78
- })).join(separator);
79
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
80
- };
81
-
82
- //#endregion
83
- exports.separatorArrayExplode = separatorArrayExplode;
84
- exports.separatorArrayNoExplode = separatorArrayNoExplode;
85
- exports.separatorObjectExplode = separatorObjectExplode;
86
- exports.serializeArrayParam = serializeArrayParam;
87
- exports.serializeObjectParam = serializeObjectParam;
88
- exports.serializePrimitiveParam = serializePrimitiveParam;
@@ -1,81 +0,0 @@
1
- //#region src/api/core/pathSerializer.gen.ts
2
- const separatorArrayExplode = (style) => {
3
- switch (style) {
4
- case "label": return ".";
5
- case "matrix": return ";";
6
- case "simple": return ",";
7
- default: return "&";
8
- }
9
- };
10
- const separatorArrayNoExplode = (style) => {
11
- switch (style) {
12
- case "form": return ",";
13
- case "pipeDelimited": return "|";
14
- case "spaceDelimited": return "%20";
15
- default: return ",";
16
- }
17
- };
18
- const separatorObjectExplode = (style) => {
19
- switch (style) {
20
- case "label": return ".";
21
- case "matrix": return ";";
22
- case "simple": return ",";
23
- default: return "&";
24
- }
25
- };
26
- const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
27
- if (!explode) {
28
- const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
29
- switch (style) {
30
- case "label": return `.${joinedValues}`;
31
- case "matrix": return `;${name}=${joinedValues}`;
32
- case "simple": return joinedValues;
33
- default: return `${name}=${joinedValues}`;
34
- }
35
- }
36
- const separator = separatorArrayExplode(style);
37
- const joinedValues = value.map((v) => {
38
- if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
39
- return serializePrimitiveParam({
40
- allowReserved,
41
- name,
42
- value: v
43
- });
44
- }).join(separator);
45
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
46
- };
47
- const serializePrimitiveParam = ({ allowReserved, name, value }) => {
48
- if (value === void 0 || value === null) return "";
49
- if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
50
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
51
- };
52
- const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
53
- if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
54
- if (style !== "deepObject" && !explode) {
55
- let values = [];
56
- Object.entries(value).forEach(([key, v]) => {
57
- values = [
58
- ...values,
59
- key,
60
- allowReserved ? v : encodeURIComponent(v)
61
- ];
62
- });
63
- const joinedValues = values.join(",");
64
- switch (style) {
65
- case "form": return `${name}=${joinedValues}`;
66
- case "label": return `.${joinedValues}`;
67
- case "matrix": return `;${name}=${joinedValues}`;
68
- default: return joinedValues;
69
- }
70
- }
71
- const separator = separatorObjectExplode(style);
72
- const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
73
- allowReserved,
74
- name: style === "deepObject" ? `${name}[${key}]` : key,
75
- value: v
76
- })).join(separator);
77
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
78
- };
79
-
80
- //#endregion
81
- export { separatorArrayExplode, separatorArrayNoExplode, separatorObjectExplode, serializeArrayParam, serializeObjectParam, serializePrimitiveParam };
@@ -1,67 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- //#region src/api/core/queryKeySerializer.gen.ts
4
- /**
5
- * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
6
- */
7
- const queryKeyJsonReplacer = (_key, value) => {
8
- if (value === void 0 || typeof value === "function" || typeof value === "symbol") return;
9
- if (typeof value === "bigint") return value.toString();
10
- if (value instanceof Date) return value.toISOString();
11
- return value;
12
- };
13
- /**
14
- * Safely stringifies a value and parses it back into a JsonValue.
15
- */
16
- const stringifyToJsonValue = (input) => {
17
- try {
18
- const json = JSON.stringify(input, queryKeyJsonReplacer);
19
- if (json === void 0) return;
20
- return JSON.parse(json);
21
- } catch {
22
- return;
23
- }
24
- };
25
- /**
26
- * Detects plain objects (including objects with a null prototype).
27
- */
28
- const isPlainObject = (value) => {
29
- if (value === null || typeof value !== "object") return false;
30
- const prototype = Object.getPrototypeOf(value);
31
- return prototype === Object.prototype || prototype === null;
32
- };
33
- /**
34
- * Turns URLSearchParams into a sorted JSON object for deterministic keys.
35
- */
36
- const serializeSearchParams = (params) => {
37
- const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b));
38
- const result = {};
39
- for (const [key, value] of entries) {
40
- const existing = result[key];
41
- if (existing === void 0) {
42
- result[key] = value;
43
- continue;
44
- }
45
- if (Array.isArray(existing)) existing.push(value);
46
- else result[key] = [existing, value];
47
- }
48
- return result;
49
- };
50
- /**
51
- * Normalizes any accepted value into a JSON-friendly shape for query keys.
52
- */
53
- const serializeQueryKeyValue = (value) => {
54
- if (value === null) return null;
55
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
56
- if (value === void 0 || typeof value === "function" || typeof value === "symbol") return;
57
- if (typeof value === "bigint") return value.toString();
58
- if (value instanceof Date) return value.toISOString();
59
- if (Array.isArray(value)) return stringifyToJsonValue(value);
60
- if (typeof URLSearchParams !== "undefined" && value instanceof URLSearchParams) return serializeSearchParams(value);
61
- if (isPlainObject(value)) return stringifyToJsonValue(value);
62
- };
63
-
64
- //#endregion
65
- exports.queryKeyJsonReplacer = queryKeyJsonReplacer;
66
- exports.serializeQueryKeyValue = serializeQueryKeyValue;
67
- exports.stringifyToJsonValue = stringifyToJsonValue;