@tuyau/core 1.2.0 → 1.2.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.
@@ -1,6 +1,6 @@
1
1
  import { UrlFor } from '@adonisjs/http-server/client/url_builder';
2
- import { T as TuyauRegistry, a as TuyauConfiguration, A as AdonisEndpoint, I as InferRoutes, b as TransformApiDefinition, c as InferTree, R as RegistryGroupedByMethod, P as PatternsByMethod, d as RequestArgs, E as EndpointByMethodPattern, e as TuyauPromise, f as ErrorResponseOf, S as StrKeys, M as Method, C as CurrentRouteOptions } from '../index-SVztBh2W.js';
3
- export { g as TuyauError, h as TuyauHTTPError, i as TuyauNetworkError } from '../index-SVztBh2W.js';
2
+ import { T as TuyauRegistry, a as TuyauConfiguration, A as AdonisEndpoint, I as InferRoutes, b as TransformApiDefinition, c as InferTree, R as RegistryGroupedByMethod, P as PatternsByMethod, d as RequestArgs, E as EndpointByMethodPattern, e as TuyauPromise, f as ErrorResponseOf, S as StrKeys, M as Method, C as CurrentRouteOptions } from '../index-BPATPJFD.js';
3
+ export { g as TuyauError, h as TuyauHTTPError, i as TuyauNetworkError } from '../index-BPATPJFD.js';
4
4
  import 'ky';
5
5
 
6
6
  /**
@@ -179,6 +179,7 @@ var TuyauRouter = class _TuyauRouter {
179
179
 
180
180
  // src/client/promise.ts
181
181
  var TuyauPromise = class {
182
+ [Symbol.toStringTag] = "TuyauPromise";
182
183
  #promise;
183
184
  constructor(promise) {
184
185
  this.#promise = promise;
@@ -380,11 +381,13 @@ var Tuyau = class {
380
381
  /**
381
382
  * Checks if an object contains any file uploads
382
383
  */
383
- #hasFile(obj) {
384
- if (!obj) return false;
384
+ #hasFile(obj, depth = 0) {
385
+ if (!obj || depth > 5) return false;
385
386
  return Object.values(obj).some((val) => {
386
- if (Array.isArray(val)) return val.some(this.#isFile);
387
- return this.#isFile(val);
387
+ if (this.#isFile(val)) return true;
388
+ if (Array.isArray(val)) return val.some((item) => this.#isFile(item) || isObject(item) && this.#hasFile(item, depth + 1));
389
+ if (isObject(val)) return this.#hasFile(val, depth + 1);
390
+ return false;
388
391
  });
389
392
  }
390
393
  #getLowercaseMethod(method) {
@@ -1,3 +1,3 @@
1
- export { A as AdonisEndpoint, q as AdonisRegistry, B as BaseRequestOptions, C as CurrentRouteOptions, E as EndpointByMethodPattern, s as EndpointByName, x as EndpointFn, j as EndpointTypes, r as Endpoints, y as EndpointsByMethod, f as ErrorResponseOf, n as ExtractBody, p as ExtractErrorResponse, l as ExtractQuery, m as ExtractQueryForGet, o as ExtractResponse, I as InferRoutes, c as InferTree, N as KnownStatuses, F as MaybeArray, M as Method, K as Path, H as PathWithRegistry, P as PatternsByMethod, Q as QueryParameters, v as RawRequestArgs, z as RegValues, R as RegistryGroupedByMethod, d as RequestArgs, w as ResponseOf, t as ResponseType, L as Route, J as RouteWithRegistry, k as SchemaEndpoint, S as StrKeys, b as TransformApiDefinition, a as TuyauConfiguration, D as TuyauPlugin, T as TuyauRegistry, u as TuyauRequestOptions, U as UnionToIntersection, G as UserRegistry, V as ValueOf } from '../../index-SVztBh2W.js';
1
+ export { A as AdonisEndpoint, q as AdonisRegistry, B as BaseRequestOptions, C as CurrentRouteOptions, E as EndpointByMethodPattern, s as EndpointByName, y as EndpointFn, j as EndpointTypes, r as Endpoints, z as EndpointsByMethod, x as ErrorOf, f as ErrorResponseOf, n as ExtractBody, p as ExtractErrorResponse, l as ExtractQuery, m as ExtractQueryForGet, o as ExtractResponse, I as InferRoutes, c as InferTree, W as KnownStatuses, G as MaybeArray, M as Method, N as NormalizeError, L as Path, J as PathWithRegistry, P as PatternsByMethod, Q as QueryParameters, v as RawRequestArgs, D as RegValues, R as RegistryGroupedByMethod, d as RequestArgs, w as ResponseOf, t as ResponseType, O as Route, K as RouteWithRegistry, k as SchemaEndpoint, S as StrKeys, b as TransformApiDefinition, a as TuyauConfiguration, F as TuyauPlugin, T as TuyauRegistry, u as TuyauRequestOptions, U as UnionToIntersection, H as UserRegistry, V as ValueOf } from '../../index-BPATPJFD.js';
2
2
  import 'ky';
3
3
  import '@adonisjs/http-server/client/url_builder';
@@ -39,6 +39,13 @@ interface SchemaEndpoint {
39
39
  interface AdonisEndpoint extends SchemaEndpoint {
40
40
  tokens: ClientRouteMatchItTokens[];
41
41
  }
42
+ /**
43
+ * Like `Omit` but distributes over union types.
44
+ * Standard `Omit<A | B, K>` collapses to `{}` when A and B have disjoint keys
45
+ * because `keyof (A | B)` returns only common keys. This variant applies
46
+ * `Omit` to each union member individually.
47
+ */
48
+ type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
42
49
  /**
43
50
  * Extract query params from a validator type if it has a 'query' property.
44
51
  * Used in generated registry to separate query params from body for POST/PUT/PATCH/DELETE.
@@ -51,12 +58,12 @@ type ExtractQuery<T> = 'query' extends keyof T ? T extends {
51
58
  * Extract query params for GET/HEAD requests.
52
59
  * Excludes headers, cookies, and params from the validator type since these are not query params.
53
60
  */
54
- type ExtractQueryForGet<T> = Omit<T, 'headers' | 'cookies' | 'params'>;
61
+ type ExtractQueryForGet<T> = DistributiveOmit<T, 'headers' | 'cookies' | 'params'>;
55
62
  /**
56
63
  * Extract body from a validator type, excluding reserved properties.
57
64
  * Excludes 'query', 'params', 'headers', and 'cookies' as these are handled separately by AdonisJS.
58
65
  */
59
- type ExtractBody<T> = Omit<T, 'query' | 'params' | 'headers' | 'cookies'>;
66
+ type ExtractBody<T> = DistributiveOmit<T, 'query' | 'params' | 'headers' | 'cookies'>;
60
67
  /**
61
68
  * Success status codes (2xx)
62
69
  */
@@ -128,19 +135,29 @@ type TuyauRequestOptions = {
128
135
  */
129
136
  type BaseRequestOptions = Omit<Options, 'body' | 'params' | 'searchParams' | 'method' | 'json' | 'prefixUrl'>;
130
137
  /**
131
- * Helper types for optional/required fields - using literal types instead of mapped types
138
+ * Helper types for optional/required fields - using literal types instead of mapped types.
139
+ *
140
+ * When `keyof T` is `never`, we distinguish true empty objects (where `{} extends T`)
141
+ * from union types with disjoint keys (e.g. `{ a: string } | { b: string }`) where
142
+ * `keyof` is also `never` but the type is not empty.
132
143
  */
133
- type ParamsArg<T> = keyof T extends never ? {} : {} extends T ? {
144
+ type ParamsArg<T> = keyof T extends never ? {} extends T ? {} : {
145
+ params: T;
146
+ } : {} extends T ? {
134
147
  params?: T;
135
148
  } : {
136
149
  params: T;
137
150
  };
138
- type QueryArg<T> = keyof T extends never ? {} : {} extends T ? {
151
+ type QueryArg<T> = keyof T extends never ? {} extends T ? {} : {
152
+ query: T;
153
+ } : {} extends T ? {
139
154
  query?: T;
140
155
  } : {
141
156
  query: T;
142
157
  };
143
- type BodyArg<T> = keyof T extends never ? {} : {} extends T ? {
158
+ type BodyArg<T> = keyof T extends never ? {} extends T ? {} : {
159
+ body: T;
160
+ } : {} extends T ? {
144
161
  body?: T;
145
162
  } : {
146
163
  body: T;
@@ -177,6 +194,10 @@ type NormalizeError$1<E> = (E extends {
177
194
  status: number;
178
195
  response: unknown;
179
196
  };
197
+ /**
198
+ * Extracts the typed TuyauError contract from an endpoint.
199
+ */
200
+ type ErrorOf<E extends SchemaEndpoint> = TuyauError<NormalizeError$1<ErrorResponseOf<E>>>;
180
201
  /**
181
202
  * Function type for calling an endpoint
182
203
  */
@@ -256,7 +277,7 @@ declare namespace PathWithRegistry {
256
277
  type Params<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = FilterByMethodPathForRegistry<Reg, M, P>['types']['params'];
257
278
  type Body<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = FilterByMethodPathForRegistry<Reg, M, P>['types']['body'];
258
279
  type Query<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = FilterByMethodPathForRegistry<Reg, M, P>['types']['query'];
259
- type Error<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = TuyauError<NormalizeError$1<ErrorResponseOf<FilterByMethodPathForRegistry<Reg, M, P>>>>;
280
+ type Error<Reg extends Record<string, AdonisEndpoint>, M extends Method, P extends PatternsByMethod<Reg, M>> = ErrorOf<FilterByMethodPathForRegistry<Reg, M, P>>;
260
281
  }
261
282
  /**
262
283
  * Internal type utilities for working with endpoints by route name
@@ -268,7 +289,7 @@ declare namespace RouteWithRegistry {
268
289
  type Params<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = EndpointByNameForRegistry<Reg, Name>['types']['params'];
269
290
  type Body<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = EndpointByNameForRegistry<Reg, Name>['types']['body'];
270
291
  type Query<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = EndpointByNameForRegistry<Reg, Name>['types']['query'];
271
- type Error<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = TuyauError<NormalizeError$1<ErrorResponseOf<EndpointByNameForRegistry<Reg, Name>>>>;
292
+ type Error<Reg extends Record<string, AdonisEndpoint>, Name extends keyof Reg> = ErrorOf<EndpointByNameForRegistry<Reg, Name>>;
272
293
  }
273
294
  /**
274
295
  * Type utilities for working with endpoints by HTTP method and path pattern
@@ -280,7 +301,7 @@ declare namespace Path {
280
301
  type Params<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>['types']['params'];
281
302
  type Body<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>['types']['body'];
282
303
  type Query<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>['types']['query'];
283
- type Error<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = TuyauError<NormalizeError$1<ErrorResponseOf<FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>>>>;
304
+ type Error<M extends Method, P extends PatternsByMethod<UserAdonisRegistry, M>> = ErrorOf<FilterByMethodPathForRegistry<UserAdonisRegistry, M, P>>;
284
305
  }
285
306
  /**
286
307
  * Type utilities for working with endpoints by route name
@@ -292,7 +313,7 @@ declare namespace Route {
292
313
  type Params<Name extends keyof UserAdonisRegistry> = UserEndpointByName<Name>['types']['params'];
293
314
  type Body<Name extends keyof UserAdonisRegistry> = UserEndpointByName<Name>['types']['body'];
294
315
  type Query<Name extends keyof UserAdonisRegistry> = UserEndpointByName<Name>['types']['query'];
295
- type Error<Name extends keyof UserAdonisRegistry> = TuyauError<NormalizeError$1<ErrorResponseOf<UserEndpointByName<Name>>>>;
316
+ type Error<Name extends keyof UserAdonisRegistry> = ErrorOf<UserEndpointByName<Name>>;
296
317
  }
297
318
  /**
298
319
  * Extracts literal status codes from E, filtering out the wide `number` from the fallback.
@@ -416,10 +437,12 @@ type NormalizeError<E> = (E extends {
416
437
  };
417
438
  /**
418
439
  * A promise wrapper that adds `.safe()` for non-throwing error handling.
419
- * Implements PromiseLike so `await` works transparently.
440
+ * Implements Promise so it's fully compatible with TanStack Query and other
441
+ * libraries that expect `Promise<T>` return types.
420
442
  */
421
- declare class TuyauPromise<Data, Errors = unknown> implements PromiseLike<Data> {
443
+ declare class TuyauPromise<Data, Errors = unknown> implements Promise<Data> {
422
444
  #private;
445
+ readonly [Symbol.toStringTag]: string;
423
446
  constructor(promise: Promise<Data>);
424
447
  then<R1 = Data, R2 = never>(onfulfilled?: ((value: Data) => R1 | PromiseLike<R1>) | null, onrejected?: ((reason: any) => R2 | PromiseLike<R2>) | null): Promise<R1 | R2>;
425
448
  catch<R = never>(onrejected?: ((reason: any) => R | PromiseLike<R>) | null): Promise<Data | R>;
@@ -435,4 +458,4 @@ declare class TuyauPromise<Data, Errors = unknown> implements PromiseLike<Data>
435
458
  ] | [data: null, error: TuyauError<NormalizeError<Errors>>]>;
436
459
  }
437
460
 
438
- export { type AdonisEndpoint as A, type BaseRequestOptions as B, type CurrentRouteOptions as C, type TuyauPlugin as D, type EndpointByMethodPattern as E, type MaybeArray as F, type UserRegistry as G, PathWithRegistry as H, type InferRoutes as I, RouteWithRegistry as J, Path as K, Route as L, type Method as M, type KnownStatuses as N, type PatternsByMethod as P, type QueryParameters as Q, type RegistryGroupedByMethod as R, type StrKeys as S, type TuyauRegistry as T, type UnionToIntersection as U, type ValueOf as V, type TuyauConfiguration as a, type TransformApiDefinition as b, type InferTree as c, type RequestArgs as d, TuyauPromise as e, type ErrorResponseOf as f, TuyauError as g, TuyauHTTPError as h, TuyauNetworkError as i, type EndpointTypes as j, type SchemaEndpoint as k, type ExtractQuery as l, type ExtractQueryForGet as m, type ExtractBody as n, type ExtractResponse as o, type ExtractErrorResponse as p, type AdonisRegistry as q, type Endpoints as r, type EndpointByName as s, type ResponseType as t, type TuyauRequestOptions as u, type RawRequestArgs as v, type ResponseOf as w, type EndpointFn as x, type EndpointsByMethod as y, type RegValues as z };
461
+ export { type AdonisEndpoint as A, type BaseRequestOptions as B, type CurrentRouteOptions as C, type RegValues as D, type EndpointByMethodPattern as E, type TuyauPlugin as F, type MaybeArray as G, type UserRegistry as H, type InferRoutes as I, PathWithRegistry as J, RouteWithRegistry as K, Path as L, type Method as M, type NormalizeError$1 as N, Route as O, type PatternsByMethod as P, type QueryParameters as Q, type RegistryGroupedByMethod as R, type StrKeys as S, type TuyauRegistry as T, type UnionToIntersection as U, type ValueOf as V, type KnownStatuses as W, type TuyauConfiguration as a, type TransformApiDefinition as b, type InferTree as c, type RequestArgs as d, TuyauPromise as e, type ErrorResponseOf as f, TuyauError as g, TuyauHTTPError as h, TuyauNetworkError as i, type EndpointTypes as j, type SchemaEndpoint as k, type ExtractQuery as l, type ExtractQueryForGet as m, type ExtractBody as n, type ExtractResponse as o, type ExtractErrorResponse as p, type AdonisRegistry as q, type Endpoints as r, type EndpointByName as s, type ResponseType as t, type TuyauRequestOptions as u, type RawRequestArgs as v, type ResponseOf as w, type ErrorOf as x, type EndpointFn as y, type EndpointsByMethod as z };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tuyau/core",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "description": "E2E typesafe client for AdonisJS",
6
6
  "author": "Julien Ripouteau <julien@ripouteau.com>",
7
7
  "license": "MIT",
@@ -52,12 +52,12 @@
52
52
  "object-to-formdata": "^4.5.1"
53
53
  },
54
54
  "devDependencies": {
55
- "@adonisjs/assembler": "^8.0.0",
55
+ "@adonisjs/assembler": "^8.0.1",
56
56
  "@adonisjs/core": "^7.0.1",
57
57
  "@adonisjs/http-server": "^8.0.0",
58
58
  "@faker-js/faker": "^10.3.0",
59
59
  "@poppinss/ts-exec": "^1.4.4",
60
- "@types/node": "^25.3.3",
60
+ "@types/node": "^25.5.0",
61
61
  "@typescript/analyze-trace": "^0.10.1",
62
62
  "@vinejs/vine": "^4.3.0"
63
63
  },