@timeax/form-palette 0.0.7 → 0.0.9

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,5 +1,5 @@
1
- import { AxiosResponse } from 'axios';
2
1
  import { Page } from './../../../../node_modules/@inertiajs/core/types/types.d';
2
+ import { AxiosResponse, AxiosRequestConfig } from 'axios';
3
3
 
4
4
  /**
5
5
  * HTTP methods supported by the core adapter layer.
@@ -89,17 +89,6 @@ interface AdapterResult<Ok = unknown> {
89
89
  * @template Err Type of the "error" payload.
90
90
  */
91
91
  interface AdapterConfig<Body = unknown, Ok = unknown, Err = unknown> {
92
- /**
93
- * HTTP method / intent used by the adapter.
94
- */
95
- method: Method;
96
- /**
97
- * Fully-resolved URL or route string.
98
- *
99
- * The core is responsible for resolving named routes, base URLs, etc.,
100
- * before handing control to the adapter.
101
- */
102
- url: string;
103
92
  /**
104
93
  * Request body payload built by the core.
105
94
  *
@@ -152,7 +141,77 @@ interface Adapters {
152
141
  */
153
142
  err: unknown;
154
143
  };
144
+ axios: {
145
+ /**
146
+ * What adapter.send() resolves with for Axios.
147
+ */
148
+ ok: AxiosResponse<unknown>;
149
+ /**
150
+ * What callbacks.onError receives for Axios.
151
+ *
152
+ * We pass the *payload* (e.g. response.data), not the raw AxiosError,
153
+ * so Form Palette's autoErr branch can see `.errors`.
154
+ */
155
+ err: unknown;
156
+ /**
157
+ * Extra public props exposed on CoreProps when adapter="axios".
158
+ *
159
+ * These are set on the Core shell and then used by createAxiosAdapter.
160
+ */
161
+ props: {
162
+ /**
163
+ * Request URL for this form.
164
+ * Required when using the axios adapter.
165
+ */
166
+ url: string;
167
+ /**
168
+ * HTTP method to use for this form.
169
+ * Optional: the adapter/Core can still default to "post".
170
+ */
171
+ method?: Method;
172
+ /**
173
+ * Base Axios request config merged into every request.
174
+ *
175
+ * Useful for baseURL, headers, withCredentials, params,
176
+ * timeout, etc. Per-call overrides still go through the
177
+ * `options` parameter of submit/send/run.
178
+ */
179
+ config?: AxiosRequestConfig<any>;
180
+ };
181
+ };
182
+ inertia: {
183
+ /**
184
+ * What adapter.send() resolves with for Inertia.
185
+ * This is the Page object passed to onSuccess.
186
+ */
187
+ ok: Page<any>;
188
+ /**
189
+ * What callbacks.onError receives for Inertia.
190
+ *
191
+ * We shape this as `{ errors: ErrorBag }` so Form Palette's
192
+ * autoErr branch can see `.errors`.
193
+ */
194
+ err: {
195
+ errors: Record<string, string | string[]>;
196
+ } | unknown;
197
+ /**
198
+ * Extra public props exposed on CoreProps when adapter="inertia".
199
+ */
200
+ props: {
201
+ /**
202
+ * Target URL / route for the Inertia visit.
203
+ */
204
+ url: string;
205
+ /**
206
+ * HTTP method to use for the visit.
207
+ */
208
+ method?: Method;
209
+ };
210
+ };
155
211
  }
212
+ type AdapterProps<K extends AdapterKey> = Adapters[K] extends {
213
+ props: infer P;
214
+ } ? P : {};
156
215
  /**
157
216
  * Union of all adapter keys known to the core.
158
217
  *
@@ -181,7 +240,7 @@ type AdapterSubmit<K extends AdapterKey> = AdapterOk<K>;
181
240
  * @template K Adapter key.
182
241
  * @template Body Outbound payload type.
183
242
  */
184
- type NamedAdapterConfig<K extends AdapterKey, Body = unknown> = AdapterConfig<Body, AdapterOk<K>, AdapterError<K>>;
243
+ type NamedAdapterConfig<K extends AdapterKey, Body = unknown> = AdapterConfig<Body, AdapterOk<K>, AdapterError<K>> & AdapterProps<K>;
185
244
  /**
186
245
  * AdapterFactory specialised for a named adapter key K.
187
246
  *
@@ -220,45 +279,8 @@ declare function getAdapter<K extends AdapterKey>(key: K): NamedAdapterFactory<K
220
279
  declare function hasAdapter(key: AdapterKey): boolean;
221
280
 
222
281
  declare const createAxiosAdapter: NamedAdapterFactory<"axios">;
223
- declare module "@/schema/adapter" {
224
- interface Adapters {
225
- axios: {
226
- /**
227
- * What adapter.send() resolves with for Axios.
228
- */
229
- ok: AxiosResponse<unknown>;
230
- /**
231
- * What callbacks.onError receives for Axios.
232
- *
233
- * We pass the *payload* (e.g. response.data), not the raw AxiosError,
234
- * so Form Palette's autoErr branch can see `.errors`.
235
- */
236
- err: unknown;
237
- };
238
- }
239
- }
240
282
 
241
283
  declare const createInertiaAdapter: NamedAdapterFactory<"inertia">;
242
- declare module "@/schema/adapter" {
243
- interface Adapters {
244
- inertia: {
245
- /**
246
- * What adapter.send() resolves with for Inertia.
247
- * This is the Page object passed to onSuccess.
248
- */
249
- ok: Page<any>;
250
- /**
251
- * What callbacks.onError receives for Inertia.
252
- *
253
- * We shape this as `{ errors: ErrorBag }` so Form Palette's
254
- * autoErr branch can see `.errors`.
255
- */
256
- err: {
257
- errors: Record<string, string | string[]>;
258
- } | unknown;
259
- };
260
- }
261
- }
262
284
 
263
285
  /**
264
286
  * Register the Axios adapter under the "axios" key.
@@ -289,4 +311,4 @@ declare function registerInertiaAdapter(): Promise<void>;
289
311
  */
290
312
  declare function registerKnownAdapter(key: AdapterKey): Promise<void>;
291
313
 
292
- export { type AdapterCallbacks, type AdapterConfig, type AdapterError, type AdapterFactory, type AdapterKey, type AdapterOk, type AdapterResult, type AdapterSubmit, type Adapters, type Method, type NamedAdapterConfig, type NamedAdapterFactory, createAxiosAdapter, createInertiaAdapter, getAdapter, hasAdapter, localAdapter, registerAdapter, registerAxiosAdapter, registerInertiaAdapter, registerKnownAdapter };
314
+ export { type AdapterCallbacks, type AdapterConfig, type AdapterError, type AdapterFactory, type AdapterKey, type AdapterOk, type AdapterProps, type AdapterResult, type AdapterSubmit, type Adapters, type Method, type NamedAdapterConfig, type NamedAdapterFactory, createAxiosAdapter, createInertiaAdapter, getAdapter, hasAdapter, localAdapter, registerAdapter, registerAxiosAdapter, registerInertiaAdapter, registerKnownAdapter };
@@ -1,5 +1,5 @@
1
- import { AxiosResponse } from 'axios';
2
1
  import { Page } from './../../../../node_modules/@inertiajs/core/types/types.d';
2
+ import { AxiosResponse, AxiosRequestConfig } from 'axios';
3
3
 
4
4
  /**
5
5
  * HTTP methods supported by the core adapter layer.
@@ -89,17 +89,6 @@ interface AdapterResult<Ok = unknown> {
89
89
  * @template Err Type of the "error" payload.
90
90
  */
91
91
  interface AdapterConfig<Body = unknown, Ok = unknown, Err = unknown> {
92
- /**
93
- * HTTP method / intent used by the adapter.
94
- */
95
- method: Method;
96
- /**
97
- * Fully-resolved URL or route string.
98
- *
99
- * The core is responsible for resolving named routes, base URLs, etc.,
100
- * before handing control to the adapter.
101
- */
102
- url: string;
103
92
  /**
104
93
  * Request body payload built by the core.
105
94
  *
@@ -152,7 +141,77 @@ interface Adapters {
152
141
  */
153
142
  err: unknown;
154
143
  };
144
+ axios: {
145
+ /**
146
+ * What adapter.send() resolves with for Axios.
147
+ */
148
+ ok: AxiosResponse<unknown>;
149
+ /**
150
+ * What callbacks.onError receives for Axios.
151
+ *
152
+ * We pass the *payload* (e.g. response.data), not the raw AxiosError,
153
+ * so Form Palette's autoErr branch can see `.errors`.
154
+ */
155
+ err: unknown;
156
+ /**
157
+ * Extra public props exposed on CoreProps when adapter="axios".
158
+ *
159
+ * These are set on the Core shell and then used by createAxiosAdapter.
160
+ */
161
+ props: {
162
+ /**
163
+ * Request URL for this form.
164
+ * Required when using the axios adapter.
165
+ */
166
+ url: string;
167
+ /**
168
+ * HTTP method to use for this form.
169
+ * Optional: the adapter/Core can still default to "post".
170
+ */
171
+ method?: Method;
172
+ /**
173
+ * Base Axios request config merged into every request.
174
+ *
175
+ * Useful for baseURL, headers, withCredentials, params,
176
+ * timeout, etc. Per-call overrides still go through the
177
+ * `options` parameter of submit/send/run.
178
+ */
179
+ config?: AxiosRequestConfig<any>;
180
+ };
181
+ };
182
+ inertia: {
183
+ /**
184
+ * What adapter.send() resolves with for Inertia.
185
+ * This is the Page object passed to onSuccess.
186
+ */
187
+ ok: Page<any>;
188
+ /**
189
+ * What callbacks.onError receives for Inertia.
190
+ *
191
+ * We shape this as `{ errors: ErrorBag }` so Form Palette's
192
+ * autoErr branch can see `.errors`.
193
+ */
194
+ err: {
195
+ errors: Record<string, string | string[]>;
196
+ } | unknown;
197
+ /**
198
+ * Extra public props exposed on CoreProps when adapter="inertia".
199
+ */
200
+ props: {
201
+ /**
202
+ * Target URL / route for the Inertia visit.
203
+ */
204
+ url: string;
205
+ /**
206
+ * HTTP method to use for the visit.
207
+ */
208
+ method?: Method;
209
+ };
210
+ };
155
211
  }
212
+ type AdapterProps<K extends AdapterKey> = Adapters[K] extends {
213
+ props: infer P;
214
+ } ? P : {};
156
215
  /**
157
216
  * Union of all adapter keys known to the core.
158
217
  *
@@ -181,7 +240,7 @@ type AdapterSubmit<K extends AdapterKey> = AdapterOk<K>;
181
240
  * @template K Adapter key.
182
241
  * @template Body Outbound payload type.
183
242
  */
184
- type NamedAdapterConfig<K extends AdapterKey, Body = unknown> = AdapterConfig<Body, AdapterOk<K>, AdapterError<K>>;
243
+ type NamedAdapterConfig<K extends AdapterKey, Body = unknown> = AdapterConfig<Body, AdapterOk<K>, AdapterError<K>> & AdapterProps<K>;
185
244
  /**
186
245
  * AdapterFactory specialised for a named adapter key K.
187
246
  *
@@ -220,45 +279,8 @@ declare function getAdapter<K extends AdapterKey>(key: K): NamedAdapterFactory<K
220
279
  declare function hasAdapter(key: AdapterKey): boolean;
221
280
 
222
281
  declare const createAxiosAdapter: NamedAdapterFactory<"axios">;
223
- declare module "@/schema/adapter" {
224
- interface Adapters {
225
- axios: {
226
- /**
227
- * What adapter.send() resolves with for Axios.
228
- */
229
- ok: AxiosResponse<unknown>;
230
- /**
231
- * What callbacks.onError receives for Axios.
232
- *
233
- * We pass the *payload* (e.g. response.data), not the raw AxiosError,
234
- * so Form Palette's autoErr branch can see `.errors`.
235
- */
236
- err: unknown;
237
- };
238
- }
239
- }
240
282
 
241
283
  declare const createInertiaAdapter: NamedAdapterFactory<"inertia">;
242
- declare module "@/schema/adapter" {
243
- interface Adapters {
244
- inertia: {
245
- /**
246
- * What adapter.send() resolves with for Inertia.
247
- * This is the Page object passed to onSuccess.
248
- */
249
- ok: Page<any>;
250
- /**
251
- * What callbacks.onError receives for Inertia.
252
- *
253
- * We shape this as `{ errors: ErrorBag }` so Form Palette's
254
- * autoErr branch can see `.errors`.
255
- */
256
- err: {
257
- errors: Record<string, string | string[]>;
258
- } | unknown;
259
- };
260
- }
261
- }
262
284
 
263
285
  /**
264
286
  * Register the Axios adapter under the "axios" key.
@@ -289,4 +311,4 @@ declare function registerInertiaAdapter(): Promise<void>;
289
311
  */
290
312
  declare function registerKnownAdapter(key: AdapterKey): Promise<void>;
291
313
 
292
- export { type AdapterCallbacks, type AdapterConfig, type AdapterError, type AdapterFactory, type AdapterKey, type AdapterOk, type AdapterResult, type AdapterSubmit, type Adapters, type Method, type NamedAdapterConfig, type NamedAdapterFactory, createAxiosAdapter, createInertiaAdapter, getAdapter, hasAdapter, localAdapter, registerAdapter, registerAxiosAdapter, registerInertiaAdapter, registerKnownAdapter };
314
+ export { type AdapterCallbacks, type AdapterConfig, type AdapterError, type AdapterFactory, type AdapterKey, type AdapterOk, type AdapterProps, type AdapterResult, type AdapterSubmit, type Adapters, type Method, type NamedAdapterConfig, type NamedAdapterFactory, createAxiosAdapter, createInertiaAdapter, getAdapter, hasAdapter, localAdapter, registerAdapter, registerAxiosAdapter, registerInertiaAdapter, registerKnownAdapter };
package/dist/adapters.js CHANGED
@@ -13125,7 +13125,7 @@ function normalizeInertiaError(raw) {
13125
13125
  return raw;
13126
13126
  }
13127
13127
  var createInertiaAdapter = (config3) => {
13128
- const { method, url, data, callbacks } = config3;
13128
+ const { method = "post", url, data, callbacks } = config3;
13129
13129
  const upperMethod = method.toUpperCase();
13130
13130
  function buildOptions(resolve, reject, extraOptions) {
13131
13131
  const merged = {