Skip to content

Commit ba2cc53

Browse files
authored
Merge pull request #24 from jcdcdev/dev/v15
15.1.2
2 parents 36fa329 + 9eb3a69 commit ba2cc53

File tree

11 files changed

+1090
-1091
lines changed

11 files changed

+1090
-1091
lines changed

src/Umbraco.Community.SimpleTrees.Client/package-lock.json

Lines changed: 849 additions & 1002 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Umbraco.Community.SimpleTrees.Client/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"devDependencies": {
1313
"lit": "^3.3.1",
1414
"@hey-api/client-fetch": "^0.13.1",
15-
"@hey-api/openapi-ts": "^0.82.4",
15+
"@hey-api/openapi-ts": "^0.86.1",
1616
"@umbraco-cms/backoffice": "^15.4.4",
17-
"typescript": "^5.9.2",
18-
"vite": "^7.1.4"
17+
"typescript": "^5.9.3",
18+
"vite": "^7.1.11"
1919
},
2020
"volta": {
2121
"node": "22.12.0"
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
import type { ClientOptions } from './types.gen';
4-
import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from './client';
3+
import { type ClientOptions, type Config, createClient, createConfig } from './client';
4+
import type { ClientOptions as ClientOptions2 } from './types.gen';
55

66
/**
77
* The `createClientConfig()` function will be called on client initialization
@@ -11,9 +11,9 @@ import { type Config, type ClientOptions as DefaultClientOptions, createClient,
1111
* `setConfig()`. This is useful for example if you're using Next.js
1212
* to ensure your client always has the correct values.
1313
*/
14-
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
14+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
1515

16-
export const client = createClient(createConfig<ClientOptions>({
16+
export const client = createClient(createConfig<ClientOptions2>({
1717
baseUrl: 'http://localhost:54813',
1818
throwOnError: true
19-
}));
19+
}));

src/Umbraco.Community.SimpleTrees.Client/src/api/client/client.gen.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { createSseClient } from '../core/serverSentEvents.gen';
44
import type { HttpMethod } from '../core/types.gen';
5+
import { getValidRequestBody } from '../core/utils.gen';
56
import type {
67
Client,
78
Config,
@@ -85,7 +86,7 @@ export const createClient = (config: Config = {}): Client => {
8586

8687
let request = new Request(url, requestInit);
8788

88-
for (const fn of interceptors.request._fns) {
89+
for (const fn of interceptors.request.fns) {
8990
if (fn) {
9091
request = await fn(request, opts);
9192
}
@@ -96,7 +97,7 @@ export const createClient = (config: Config = {}): Client => {
9697
const _fetch = opts.fetch!;
9798
let response = await _fetch(request);
9899

99-
for (const fn of interceptors.response._fns) {
100+
for (const fn of interceptors.response.fns) {
100101
if (fn) {
101102
response = await fn(response, request, opts);
102103
}
@@ -191,7 +192,7 @@ export const createClient = (config: Config = {}): Client => {
191192
const error = jsonError ?? textError;
192193
let finalError = error;
193194

194-
for (const fn of interceptors.error._fns) {
195+
for (const fn of interceptors.error.fns) {
195196
if (fn) {
196197
finalError = (await fn(error, response, request, opts)) as string;
197198
}
@@ -212,26 +213,6 @@ export const createClient = (config: Config = {}): Client => {
212213
};
213214
};
214215

215-
function getValidRequestBody(options: ResolvedRequestOptions) {
216-
const hasBody = options.body !== undefined;
217-
const isSerializedBody = hasBody && options.bodySerializer;
218-
219-
if (isSerializedBody) {
220-
const hasSerializedBody =
221-
options.serializedBody !== undefined && options.serializedBody !== '';
222-
223-
return hasSerializedBody ? options.serializedBody : null;
224-
}
225-
226-
// plain/text body
227-
if (hasBody) {
228-
return options.body;
229-
}
230-
231-
// no body was provided
232-
return undefined;
233-
}
234-
235216
const makeMethodFn =
236217
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
237218
request({ ...options, method });
@@ -246,7 +227,7 @@ export const createClient = (config: Config = {}): Client => {
246227
method,
247228
onRequest: async (url, init) => {
248229
let request = new Request(url, init);
249-
for (const fn of interceptors.request._fns) {
230+
for (const fn of interceptors.request.fns) {
250231
if (fn) {
251232
request = await fn(request, opts);
252233
}

src/Umbraco.Community.SimpleTrees.Client/src/api/client/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export {
88
urlSearchParamsBodySerializer,
99
} from '../core/bodySerializer.gen';
1010
export { buildClientParams } from '../core/params.gen';
11+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
1112
export { createClient } from './client.gen';
1213
export type {
1314
Client,

src/Umbraco.Community.SimpleTrees.Client/src/api/client/utils.gen.ts

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,27 @@ export const mergeConfigs = (a: Config, b: Config): Config => {
183183
return config;
184184
};
185185

186+
const headersEntries = (headers: Headers): Array<[string, string]> => {
187+
const entries: Array<[string, string]> = [];
188+
headers.forEach((value, key) => {
189+
entries.push([key, value]);
190+
});
191+
return entries;
192+
};
193+
186194
export const mergeHeaders = (
187195
...headers: Array<Required<Config>['headers'] | undefined>
188196
): Headers => {
189197
const mergedHeaders = new Headers();
190198
for (const header of headers) {
191-
if (!header || typeof header !== 'object') {
199+
if (!header) {
192200
continue;
193201
}
194202

195203
const iterator =
196-
header instanceof Headers ? header.entries() : Object.entries(header);
204+
header instanceof Headers
205+
? headersEntries(header)
206+
: Object.entries(header);
197207

198208
for (const [key, value] of iterator) {
199209
if (value === null) {
@@ -234,67 +244,61 @@ type ResInterceptor<Res, Req, Options> = (
234244
) => Res | Promise<Res>;
235245

236246
class Interceptors<Interceptor> {
237-
_fns: (Interceptor | null)[];
247+
fns: Array<Interceptor | null> = [];
238248

239-
constructor() {
240-
this._fns = [];
249+
clear(): void {
250+
this.fns = [];
241251
}
242252

243-
clear() {
244-
this._fns = [];
245-
}
246-
247-
getInterceptorIndex(id: number | Interceptor): number {
248-
if (typeof id === 'number') {
249-
return this._fns[id] ? id : -1;
250-
} else {
251-
return this._fns.indexOf(id);
253+
eject(id: number | Interceptor): void {
254+
const index = this.getInterceptorIndex(id);
255+
if (this.fns[index]) {
256+
this.fns[index] = null;
252257
}
253258
}
254-
exists(id: number | Interceptor) {
259+
260+
exists(id: number | Interceptor): boolean {
255261
const index = this.getInterceptorIndex(id);
256-
return !!this._fns[index];
262+
return Boolean(this.fns[index]);
257263
}
258264

259-
eject(id: number | Interceptor) {
260-
const index = this.getInterceptorIndex(id);
261-
if (this._fns[index]) {
262-
this._fns[index] = null;
265+
getInterceptorIndex(id: number | Interceptor): number {
266+
if (typeof id === 'number') {
267+
return this.fns[id] ? id : -1;
263268
}
269+
return this.fns.indexOf(id);
264270
}
265271

266-
update(id: number | Interceptor, fn: Interceptor) {
272+
update(
273+
id: number | Interceptor,
274+
fn: Interceptor,
275+
): number | Interceptor | false {
267276
const index = this.getInterceptorIndex(id);
268-
if (this._fns[index]) {
269-
this._fns[index] = fn;
277+
if (this.fns[index]) {
278+
this.fns[index] = fn;
270279
return id;
271-
} else {
272-
return false;
273280
}
281+
return false;
274282
}
275283

276-
use(fn: Interceptor) {
277-
this._fns = [...this._fns, fn];
278-
return this._fns.length - 1;
284+
use(fn: Interceptor): number {
285+
this.fns.push(fn);
286+
return this.fns.length - 1;
279287
}
280288
}
281289

282-
// `createInterceptors()` response, meant for external use as it does not
283-
// expose internals
284290
export interface Middleware<Req, Res, Err, Options> {
285-
error: Pick<
286-
Interceptors<ErrInterceptor<Err, Res, Req, Options>>,
287-
'eject' | 'use'
288-
>;
289-
request: Pick<Interceptors<ReqInterceptor<Req, Options>>, 'eject' | 'use'>;
290-
response: Pick<
291-
Interceptors<ResInterceptor<Res, Req, Options>>,
292-
'eject' | 'use'
293-
>;
291+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
292+
request: Interceptors<ReqInterceptor<Req, Options>>;
293+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
294294
}
295295

296-
// do not add `Middleware` as return type so we can use _fns internally
297-
export const createInterceptors = <Req, Res, Err, Options>() => ({
296+
export const createInterceptors = <Req, Res, Err, Options>(): Middleware<
297+
Req,
298+
Res,
299+
Err,
300+
Options
301+
> => ({
298302
error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
299303
request: new Interceptors<ReqInterceptor<Req, Options>>(),
300304
response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
/**
4+
* JSON-friendly union that mirrors what Pinia Colada can hash.
5+
*/
6+
export type JsonValue =
7+
| null
8+
| string
9+
| number
10+
| boolean
11+
| JsonValue[]
12+
| { [key: string]: JsonValue };
13+
14+
/**
15+
* Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
16+
*/
17+
export const queryKeyJsonReplacer = (_key: string, value: unknown) => {
18+
if (
19+
value === undefined ||
20+
typeof value === 'function' ||
21+
typeof value === 'symbol'
22+
) {
23+
return undefined;
24+
}
25+
if (typeof value === 'bigint') {
26+
return value.toString();
27+
}
28+
if (value instanceof Date) {
29+
return value.toISOString();
30+
}
31+
return value;
32+
};
33+
34+
/**
35+
* Safely stringifies a value and parses it back into a JsonValue.
36+
*/
37+
export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => {
38+
try {
39+
const json = JSON.stringify(input, queryKeyJsonReplacer);
40+
if (json === undefined) {
41+
return undefined;
42+
}
43+
return JSON.parse(json) as JsonValue;
44+
} catch {
45+
return undefined;
46+
}
47+
};
48+
49+
/**
50+
* Detects plain objects (including objects with a null prototype).
51+
*/
52+
const isPlainObject = (value: unknown): value is Record<string, unknown> => {
53+
if (value === null || typeof value !== 'object') {
54+
return false;
55+
}
56+
const prototype = Object.getPrototypeOf(value as object);
57+
return prototype === Object.prototype || prototype === null;
58+
};
59+
60+
/**
61+
* Turns URLSearchParams into a sorted JSON object for deterministic keys.
62+
*/
63+
const serializeSearchParams = (params: URLSearchParams): JsonValue => {
64+
const entries = Array.from(params.entries()).sort(([a], [b]) =>
65+
a.localeCompare(b),
66+
);
67+
const result: Record<string, JsonValue> = {};
68+
69+
for (const [key, value] of entries) {
70+
const existing = result[key];
71+
if (existing === undefined) {
72+
result[key] = value;
73+
continue;
74+
}
75+
76+
if (Array.isArray(existing)) {
77+
(existing as string[]).push(value);
78+
} else {
79+
result[key] = [existing, value];
80+
}
81+
}
82+
83+
return result;
84+
};
85+
86+
/**
87+
* Normalizes any accepted value into a JSON-friendly shape for query keys.
88+
*/
89+
export const serializeQueryKeyValue = (
90+
value: unknown,
91+
): JsonValue | undefined => {
92+
if (value === null) {
93+
return null;
94+
}
95+
96+
if (
97+
typeof value === 'string' ||
98+
typeof value === 'number' ||
99+
typeof value === 'boolean'
100+
) {
101+
return value;
102+
}
103+
104+
if (
105+
value === undefined ||
106+
typeof value === 'function' ||
107+
typeof value === 'symbol'
108+
) {
109+
return undefined;
110+
}
111+
112+
if (typeof value === 'bigint') {
113+
return value.toString();
114+
}
115+
116+
if (value instanceof Date) {
117+
return value.toISOString();
118+
}
119+
120+
if (Array.isArray(value)) {
121+
return stringifyToJsonValue(value);
122+
}
123+
124+
if (
125+
typeof URLSearchParams !== 'undefined' &&
126+
value instanceof URLSearchParams
127+
) {
128+
return serializeSearchParams(value);
129+
}
130+
131+
if (isPlainObject(value)) {
132+
return stringifyToJsonValue(value);
133+
}
134+
135+
return undefined;
136+
};

0 commit comments

Comments
 (0)