@web-ts-toolkit/access-router-client 0.4.0 → 0.6.0

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 (7) hide show
  1. package/README.md +39 -12
  2. package/index.d.mts +240 -197
  3. package/index.d.ts +240 -197
  4. package/index.js +785 -909
  5. package/index.mjs +781 -906
  6. package/llms.txt +53 -0
  7. package/package.json +13 -11
package/README.md CHANGED
@@ -1,27 +1,36 @@
1
- # @web-ts-toolkit/access-router-client
1
+ # `@web-ts-toolkit/access-router-client`
2
2
 
3
- `@web-ts-toolkit/access-router-client` is a TypeScript/JavaScript client for `@web-ts-toolkit/access-router` APIs.
3
+ Typed client utilities for `@web-ts-toolkit/access-router` APIs.
4
4
 
5
5
  ## Installation
6
6
 
7
- ```sh
8
- npm install @web-ts-toolkit/access-router-client
9
- ```
10
-
11
7
  ```sh
12
8
  pnpm add @web-ts-toolkit/access-router-client
13
9
  ```
14
10
 
15
- ## Usage
11
+ ## Highlights
12
+
13
+ - typed model and data services
14
+ - lazy requests that can be grouped into one batch call
15
+ - `Model<T>` wrappers with dirty tracking and `save()`
16
+ - normalized response and error handling around Axios
17
+
18
+ ## Quick Start
16
19
 
17
20
  ```ts
18
21
  import { createAdapter } from '@web-ts-toolkit/access-router-client';
19
22
 
23
+ type User = {
24
+ _id?: string;
25
+ name: string;
26
+ role: string;
27
+ };
28
+
20
29
  const adapter = createAdapter({
21
30
  baseURL: 'http://localhost:3000/api',
22
31
  });
23
32
 
24
- const userService = adapter.createModelService<{ _id?: string; name: string; role: string }>({
33
+ const userService = adapter.createModelService<User>({
25
34
  modelName: 'User',
26
35
  basePath: 'users',
27
36
  });
@@ -32,14 +41,32 @@ const listResponse = await userService.listAdvanced(
32
41
  { includeCount: true },
33
42
  );
34
43
 
44
+ const user = await userService.read('user-id-1');
45
+
46
+ user.data.role = 'owner';
47
+ await user.data.save();
48
+
35
49
  const grouped = await adapter.group(
36
50
  userService.readAdvanced('user-id-1', { select: ['name'] }),
37
51
  userService.countAdvanced({ role: 'admin' }),
38
52
  );
39
53
  ```
40
54
 
41
- Notes:
55
+ ## Main Exports
56
+
57
+ - `createAdapter(...)`
58
+ - `ModelService`
59
+ - `DataService`
60
+ - `Model`
61
+ - response and query helper types
62
+
63
+ ## Documentation
64
+
65
+ Full package documentation lives in `website/docs/packages/access-router-client/`.
42
66
 
43
- - model and data service requests use the router paths you configure in `basePath`
44
- - grouped `adapter.group(...)` requests target the root router path, which defaults to `root`
45
- - if your root router uses another path, pass `rootRouterPath` as the second `createAdapter(...)` argument
67
+ - live docs: https://web-ts-toolkit.pages.dev/docs/packages/access-router-client
68
+ - overview: `website/docs/packages/access-router-client/index.md`
69
+ - adapter: `website/docs/packages/access-router-client/adapter.mdx`
70
+ - services: `website/docs/packages/access-router-client/services.mdx`
71
+ - model wrapper: `website/docs/packages/access-router-client/model.mdx`
72
+ - typing and errors: `website/docs/packages/access-router-client/typescript-and-errors.mdx`
package/index.d.mts CHANGED
@@ -1,34 +1,5 @@
1
1
  import * as axios from 'axios';
2
- import { AxiosRequestConfig, AxiosInstance, AxiosResponse, AxiosHeaders } from 'axios';
3
-
4
- declare class Model<T extends Document, TData extends Partial<T> = T> {
5
- private _data;
6
- private _snapshot;
7
- private readonly _service;
8
- private modifiedPaths;
9
- constructor(data: TData, adapter: ModelService<T>);
10
- static create<T, TData extends Partial<T> = T>(data: TData, adapter: ModelService<T>): Model<T, TData> & TData;
11
- save(reqConfig?: AxiosRequestConfig): Promise<any>;
12
- isDirty(path?: keyof TData | string): boolean;
13
- markModified(path: keyof TData | string): this;
14
- get<TKey extends keyof TData>(path: TKey): TData[TKey];
15
- get(path: string): unknown;
16
- set<TKey extends keyof TData>(path: TKey, value: TData[TKey]): this;
17
- set(path: string, value: unknown): this;
18
- assign(partial: Partial<TData>): this;
19
- reset(): this;
20
- toObject(): TData;
21
- toJSON(): TData;
22
- private updateModel;
23
- private replaceData;
24
- private initializeDirtyState;
25
- private prepareData;
26
- private defineHiddenDataProp;
27
- private defineHiddenAdapterProp;
28
- private definePublicDataProps;
29
- private trackModified;
30
- private normalizePath;
31
- }
2
+ import { AxiosInstance, AxiosResponse, AxiosRequestConfig, AxiosHeaders } from 'axios';
32
3
 
33
4
  interface SubQueryOptions {
34
5
  path?: string;
@@ -186,6 +157,210 @@ interface AdditionalReqConfig {
186
157
  throwOnError?: boolean;
187
158
  }
188
159
 
160
+ interface ResultError {
161
+ success: boolean;
162
+ raw: unknown;
163
+ data: unknown;
164
+ message: string;
165
+ status: number;
166
+ headers: Record<string, unknown>;
167
+ }
168
+ declare class Service {
169
+ protected _axios: AxiosInstance;
170
+ protected _basePath: string;
171
+ private _wrap;
172
+ constructor(axios: AxiosInstance, basePath: string);
173
+ protected handleSuccess(res: AxiosResponse<unknown, unknown>, extra?: {}): Response<unknown>;
174
+ protected handleError<T extends ResultError>(error: {
175
+ response?: {
176
+ status: number;
177
+ headers: Record<string, unknown>;
178
+ data: unknown;
179
+ };
180
+ request?: unknown;
181
+ message?: string;
182
+ }): T;
183
+ wrapGet<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
184
+ wrapPost<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (data?: unknown, options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
185
+ wrapPut<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (data?: unknown, options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
186
+ wrapPatch<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (data?: unknown, options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
187
+ wrapDelete<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
188
+ updateHeaders(headers: AxiosRequestConfig['headers'], { ignoreCache }: {
189
+ ignoreCache?: boolean;
190
+ }): AxiosHeaders | (Partial<axios.RawAxiosHeaders & {
191
+ Accept: axios.AxiosHeaderValue;
192
+ "Content-Length": axios.AxiosHeaderValue;
193
+ "User-Agent": axios.AxiosHeaderValue;
194
+ "Content-Encoding": axios.AxiosHeaderValue;
195
+ Authorization: axios.AxiosHeaderValue;
196
+ Location: axios.AxiosHeaderValue;
197
+ } & {
198
+ 'Content-Type': axios.AxiosHeaderValue;
199
+ }> & Partial<{
200
+ get: AxiosHeaders;
201
+ delete: AxiosHeaders;
202
+ head: AxiosHeaders;
203
+ options: AxiosHeaders;
204
+ post: AxiosHeaders;
205
+ put: AxiosHeaders;
206
+ patch: AxiosHeaders;
207
+ purge: AxiosHeaders;
208
+ link: AxiosHeaders;
209
+ unlink: AxiosHeaders;
210
+ query: AxiosHeaders;
211
+ } & {
212
+ common: AxiosHeaders;
213
+ }>);
214
+ }
215
+ declare class ServiceError extends Error {
216
+ success: boolean;
217
+ raw: unknown;
218
+ data: unknown;
219
+ status: number;
220
+ headers: Record<string, unknown>;
221
+ constructor(result: ResultError);
222
+ }
223
+
224
+ type RequestConfig$1 = AxiosRequestConfig & AdditionalReqConfig;
225
+ interface Props$1 {
226
+ axios: AxiosInstance;
227
+ modelName: string;
228
+ basePath: string;
229
+ queryPath: string;
230
+ mutationPath: string;
231
+ onSuccess: ResponseCallback;
232
+ onFailure: ResponseCallback;
233
+ throwOnError: boolean;
234
+ }
235
+ /**
236
+ * Typed client for `access-router` model CRUD routes. Created by
237
+ * `adapter.createModelService<T>(...)`.
238
+ *
239
+ * @example
240
+ * const userService = adapter.createModelService<User>({ modelName: 'User', basePath: 'users' });
241
+ * const user = await userService.read('user-id-1');
242
+ */
243
+ declare class ModelService<T extends Document> extends Service {
244
+ private _modelName;
245
+ private _queryPath;
246
+ private _mutationPath;
247
+ private _handleCallbacks;
248
+ private _defaults;
249
+ constructor({ axios, modelName, basePath, queryPath, mutationPath, onSuccess, onFailure, throwOnError }: Props$1, defaults?: Defaults);
250
+ list<TData extends Partial<T> = T>(args?: ListArgs, options?: ListOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ListModelResponse<T, TData>>;
251
+ listAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: ListAdvancedArgs<TSelect>, options?: ListAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ListModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
252
+ create<TData extends Partial<T> = T>(data: object, options?: CreateOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ModelResponse<T, TData>>;
253
+ createAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(data: object, args?: CreateAdvancedArgs<TSelect>, options?: CreateAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
254
+ upsert<TData extends Partial<T> = T>(data: object, options?: UpsertOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ModelResponse<T, TData>>;
255
+ upsertAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(data: object, args?: UpsertAdvancedArgs<TSelect>, options?: UpsertAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
256
+ delete(identifier: string, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<Response<string, string>>;
257
+ new<TData extends Partial<T> = T>(axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ModelResponse<T, TData>>;
258
+ distinct(field: string, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<Response<string[], string[]>>;
259
+ distinctAdvanced(field: string, conditions: FilterQuery<T>, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<Response<string[], string[]>>;
260
+ count(axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<Response<number, number>>;
261
+ countAdvanced(filter: FilterQuery<T>, args?: {
262
+ access?: 'list' | 'read';
263
+ }, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<Response<number, number>>;
264
+ read<TData extends Partial<T> = T>(identifier: string, options?: ReadOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ModelResponse<T, TData>>;
265
+ readAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(identifier: string, args?: ReadAdvancedArgs<TSelect>, options?: ReadAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
266
+ readAdvancedFilter<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: ReadAdvancedArgs<TSelect>, options?: ReadAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
267
+ update<TData extends Partial<T> = T>(identifier: string, data: object, options?: UpdateOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ModelResponse<T, TData>>;
268
+ updateAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(identifier: string, data: object, args?: UpdateAdvancedArgs<TSelect>, options?: UpdateAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
269
+ id(id: string): {
270
+ subs: <S = T>(field: keyof T) => {
271
+ list: (axiosRequestConfig?: AxiosRequestConfig<any> & {
272
+ throwOnError?: boolean;
273
+ }) => ModelPromiseMeta & LazyRequest<ListModelResponse<S>>;
274
+ listAdvanced: <TData extends Partial<S> = never, TSelect extends readonly string[] = readonly string[]>(filter?: FilterQuery<S>, args?: {
275
+ select?: TSelect;
276
+ }, axiosRequestConfig?: AxiosRequestConfig<any> & {
277
+ throwOnError?: boolean;
278
+ }) => ModelPromiseMeta & LazyRequest<ListModelResponse<S, ResolvedSelectedShape<S, TSelect, TData>>>;
279
+ read: (subId: string, axiosRequestConfig?: AxiosRequestConfig<any> & {
280
+ throwOnError?: boolean;
281
+ }) => ModelPromiseMeta & LazyRequest<ModelResponse<S>>;
282
+ readAdvanced: <TData extends Partial<S> = never, TSelect_1 extends readonly string[] = readonly string[]>(subId: string, args?: {
283
+ select?: TSelect_1;
284
+ populate?: unknown;
285
+ }, axiosRequestConfig?: AxiosRequestConfig<any> & {
286
+ throwOnError?: boolean;
287
+ }) => ModelPromiseMeta & LazyRequest<ModelResponse<S, ResolvedSelectedShape<S, TSelect_1, TData>>>;
288
+ update: (subId: string, data: object, axiosRequestConfig?: AxiosRequestConfig<any> & {
289
+ throwOnError?: boolean;
290
+ }) => ModelPromiseMeta & LazyRequest<ModelResponse<S>>;
291
+ bulkUpdate: (data: object[], axiosRequestConfig?: AxiosRequestConfig<any> & {
292
+ throwOnError?: boolean;
293
+ }) => ModelPromiseMeta & LazyRequest<ListModelResponse<S>>;
294
+ create: (data: object, axiosRequestConfig?: AxiosRequestConfig<any> & {
295
+ throwOnError?: boolean;
296
+ }) => ModelPromiseMeta & LazyRequest<ModelResponse<S>>;
297
+ delete: (subId: string, axiosRequestConfig?: AxiosRequestConfig<any> & {
298
+ throwOnError?: boolean;
299
+ }) => ModelPromiseMeta & LazyRequest<Response<string, string>>;
300
+ };
301
+ fetch: (args?: ReadAdvancedArgs, options?: ReadAdvancedOptions, axiosRequestConfig?: RequestConfig$1) => ModelRequest<ModelResponse<T, Partial<T>>>;
302
+ };
303
+ }
304
+
305
+ type RequestConfig = AxiosRequestConfig & AdditionalReqConfig;
306
+ interface Props {
307
+ axios: AxiosInstance;
308
+ dataName: string;
309
+ basePath: string;
310
+ queryPath: string;
311
+ onSuccess: ResponseCallback;
312
+ onFailure: ResponseCallback;
313
+ throwOnError: boolean;
314
+ }
315
+ /**
316
+ * Typed client for `access-router` in-memory data routes. Created by
317
+ * `adapter.createDataService<T>(...)`.
318
+ *
319
+ * @example
320
+ * const fruitService = adapter.createDataService<Fruit>({ dataName: 'fruit', basePath: 'fruit' });
321
+ */
322
+ declare class DataService<T> extends Service {
323
+ private _dataName;
324
+ private _queryPath;
325
+ private _handleCallbacks;
326
+ private _defaults;
327
+ constructor({ axios, dataName, basePath, queryPath, onSuccess, onFailure, throwOnError }: Props, defaults?: DataDefaults);
328
+ list<TData extends Partial<T> = T>(args?: DataListArgs, options?: DataListOptions, axiosRequestConfig?: RequestConfig): DataPromiseMeta & LazyRequest<ListDataResponse<TData>>;
329
+ listAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: DataListAdvancedArgs<TSelect>, options?: DataListAdvancedOptions, axiosRequestConfig?: RequestConfig): DataRequest<ListDataResponse<ResolvedSelectedShape<T, TSelect, TData>>>;
330
+ read<TData extends Partial<T> = T>(identifier: string, options?: DataReadOptions, axiosRequestConfig?: RequestConfig): DataPromiseMeta & LazyRequest<DataResponse<TData>>;
331
+ readAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(identifier: string, args?: DataReadAdvancedArgs<TSelect>, options?: DataReadAdvancedOptions, axiosRequestConfig?: RequestConfig): DataRequest<DataResponse<ResolvedSelectedShape<T, TSelect, TData>>>;
332
+ readAdvancedFilter<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: DataReadAdvancedArgs<TSelect>, options?: DataReadAdvancedOptions, axiosRequestConfig?: RequestConfig): DataRequest<DataResponse<ResolvedSelectedShape<T, TSelect, TData>>>;
333
+ }
334
+
335
+ declare class Model<T extends Document, TData extends Partial<T> = T> {
336
+ private _data;
337
+ private _snapshot;
338
+ private readonly _service;
339
+ private modifiedPaths;
340
+ constructor(data: TData, adapter: ModelService<T>);
341
+ static create<T, TData extends Partial<T> = T>(data: TData, adapter: ModelService<T>): Model<T, TData> & TData;
342
+ save(reqConfig?: AxiosRequestConfig): Promise<any>;
343
+ isDirty(path?: keyof TData | string): boolean;
344
+ markModified(path: keyof TData | string): this;
345
+ get<TKey extends keyof TData>(path: TKey): TData[TKey];
346
+ get(path: string): unknown;
347
+ set<TKey extends keyof TData>(path: TKey, value: TData[TKey]): this;
348
+ set(path: string, value: unknown): this;
349
+ assign(partial: Partial<TData>): this;
350
+ reset(): this;
351
+ toObject(): TData;
352
+ toJSON(): TData;
353
+ private updateModel;
354
+ private replaceData;
355
+ private initializeDirtyState;
356
+ private prepareData;
357
+ private defineHiddenDataProp;
358
+ private defineHiddenAdapterProp;
359
+ private definePublicDataProps;
360
+ private trackModified;
361
+ private normalizePath;
362
+ }
363
+
189
364
  type AnyArray<T> = T[] | ReadonlyArray<T>;
190
365
  type Unpacked<T> = T extends (infer U)[] ? U : T extends ReadonlyArray<infer U> ? U : T;
191
366
  type ApplyBasicQueryCasting<T> = T | T[] | (T extends (infer U)[] ? U : unknown) | unknown;
@@ -236,6 +411,13 @@ type QuerySelector<T> = {
236
411
  $options?: T extends string ? string : never;
237
412
  };
238
413
 
414
+ /**
415
+ * Wraps a lazy promise function with optional metadata.
416
+ * The promise is only created when `.then()`, `.catch()`, `.finally()`, or `.exec()` is called.
417
+ * Metadata properties are merged onto the returned object via `Object.assign`.
418
+ */
419
+ declare const wrapLazyPromise: <T, M = undefined>(promiseFn: () => Promise<T>, meta?: M) => M & LazyRequest<T>;
420
+
239
421
  type KeyValueProjection<TKey extends string = string> = Partial<Record<TKey, 1 | -1>>;
240
422
  type Projection = readonly string[] | string | KeyValueProjection;
241
423
  type SelectableKey<T> = Extract<keyof T, string>;
@@ -306,6 +488,7 @@ interface RootModelQueryMeta {
306
488
  data?: unknown;
307
489
  args?: Record<string, unknown>;
308
490
  options?: Record<string, unknown>;
491
+ order?: number;
309
492
  sqOptions?: SubQueryOptions;
310
493
  }
311
494
  interface RootDataQueryMeta {
@@ -317,17 +500,9 @@ interface RootDataQueryMeta {
317
500
  data?: unknown;
318
501
  args?: Record<string, unknown>;
319
502
  options?: Record<string, unknown>;
503
+ order?: number;
320
504
  }
321
505
  type RootQueryMeta = RootModelQueryMeta | RootDataQueryMeta;
322
- interface SubQueryMeta {
323
- model: string;
324
- op: 'list' | 'read';
325
- id?: string;
326
- filter?: unknown;
327
- args?: Record<string, unknown>;
328
- options?: Record<string, unknown>;
329
- sqOptions?: SubQueryOptions;
330
- }
331
506
  interface ModelPromiseMeta {
332
507
  __op: string;
333
508
  __query: RootModelQueryMeta;
@@ -350,158 +525,13 @@ interface DataPromiseMeta {
350
525
  __service?: DataService<unknown>;
351
526
  }
352
527
  type DataRequest<T> = DataPromiseMeta & LazyRequest<T>;
353
- declare const wrapLazyPromise: <T, M = undefined>(promiseFn: () => Promise<T>, meta?: M) => M & LazyRequest<T>;
528
+
354
529
  type ResponseCallback = (res: unknown) => void;
355
530
  interface WrapOptions {
356
531
  queryParams?: Record<string, unknown>;
357
532
  pathParams?: Record<string, string | number>;
358
533
  }
359
534
 
360
- interface ResultError {
361
- success: boolean;
362
- raw: unknown;
363
- data: unknown;
364
- message: string;
365
- status: number;
366
- headers: Record<string, unknown>;
367
- }
368
- declare class Service {
369
- protected _axios: AxiosInstance;
370
- protected _basePath: string;
371
- constructor(axios: AxiosInstance, basePath: string);
372
- protected handleSuccess(res: AxiosResponse<unknown, unknown>, extra?: {}): Response<unknown>;
373
- protected handleError<T extends ResultError>(error: {
374
- response?: {
375
- status: number;
376
- headers: Record<string, unknown>;
377
- data: unknown;
378
- };
379
- request?: unknown;
380
- message?: string;
381
- }): T;
382
- wrapGet<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
383
- wrapPost<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
384
- wrapPut<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
385
- wrapPatch<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
386
- wrapDelete<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
387
- updateHeaders(headers: AxiosRequestConfig['headers'], { ignoreCache }: {
388
- ignoreCache?: boolean;
389
- }): AxiosHeaders | (Partial<axios.RawAxiosHeaders & {
390
- Accept: axios.AxiosHeaderValue;
391
- "Content-Length": axios.AxiosHeaderValue;
392
- "User-Agent": axios.AxiosHeaderValue;
393
- "Content-Encoding": axios.AxiosHeaderValue;
394
- Authorization: axios.AxiosHeaderValue;
395
- Location: axios.AxiosHeaderValue;
396
- } & {
397
- 'Content-Type': axios.AxiosHeaderValue;
398
- }> & Partial<{
399
- get: AxiosHeaders;
400
- delete: AxiosHeaders;
401
- head: AxiosHeaders;
402
- options: AxiosHeaders;
403
- post: AxiosHeaders;
404
- put: AxiosHeaders;
405
- patch: AxiosHeaders;
406
- purge: AxiosHeaders;
407
- link: AxiosHeaders;
408
- unlink: AxiosHeaders;
409
- query: AxiosHeaders;
410
- } & {
411
- common: AxiosHeaders;
412
- }>);
413
- }
414
- declare class ServiceError extends Error {
415
- success: boolean;
416
- raw: unknown;
417
- data: unknown;
418
- status: number;
419
- headers: Record<string, unknown>;
420
- constructor(result: ResultError);
421
- }
422
-
423
- type RequestConfig$1 = AxiosRequestConfig & AdditionalReqConfig;
424
- interface Props$1 {
425
- axios: AxiosInstance;
426
- modelName: string;
427
- basePath: string;
428
- queryPath: string;
429
- mutationPath: string;
430
- onSuccess: ResponseCallback;
431
- onFailure: ResponseCallback;
432
- throwOnError: boolean;
433
- }
434
- declare class ModelService<T extends Document> extends Service {
435
- private _modelName;
436
- private _queryPath;
437
- private _mutationPath;
438
- private _handleCallbacks;
439
- private _defaults;
440
- constructor({ axios, modelName, basePath, queryPath, mutationPath, onSuccess, onFailure, throwOnError }: Props$1, defaults?: Defaults);
441
- list<TData extends Partial<T> = T>(args?: ListArgs, options?: ListOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ListModelResponse<T, TData>>;
442
- listAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: ListAdvancedArgs<TSelect>, options?: ListAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ListModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
443
- read<TData extends Partial<T> = T>(identifier: string, options?: ReadOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, TData>>;
444
- readAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(identifier: string, args?: ReadAdvancedArgs<TSelect>, options?: ReadAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
445
- readAdvancedFilter<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: ReadAdvancedArgs<TSelect>, options?: ReadAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
446
- new<TData extends Partial<T> = T>(axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, TData>>;
447
- create<TData extends Partial<T> = T>(data: object, options?: CreateOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, TData>>;
448
- createAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(data: object, args?: CreateAdvancedArgs<TSelect>, options?: CreateAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
449
- update<TData extends Partial<T> = T>(identifier: string, data: object, options?: UpdateOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, TData>>;
450
- updateAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(identifier: string, data: object, args?: UpdateAdvancedArgs<TSelect>, options?: UpdateAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
451
- upsert<TData extends Partial<T> = T>(data: object, options?: UpsertOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, TData>>;
452
- upsertAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(data: object, args?: UpsertAdvancedArgs<TSelect>, options?: UpsertAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelRequest<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
453
- delete(identifier: string, axiosRequestConfig?: RequestConfig$1): ModelRequest<Response<string, string>>;
454
- distinct(field: string, axiosRequestConfig?: RequestConfig$1): ModelRequest<Response<string[], string[]>>;
455
- distinctAdvanced(field: string, conditions: FilterQuery<T>, axiosRequestConfig?: RequestConfig$1): ModelRequest<Response<string[], string[]>>;
456
- count(axiosRequestConfig?: RequestConfig$1): ModelRequest<Response<number, number>>;
457
- countAdvanced(filter: FilterQuery<T>, args?: {
458
- access?: string;
459
- }, axiosRequestConfig?: RequestConfig$1): ModelRequest<Response<number, number>>;
460
- id(id: string): {
461
- subs: <S = T>(field: keyof T) => {
462
- list: (axiosRequestConfig?: RequestConfig$1) => ModelRequest<ListModelResponse<S>>;
463
- listAdvanced: <TData extends Partial<S> | never = never, TSelect extends readonly string[] = readonly string[]>(filter?: FilterQuery<S>, args?: {
464
- select?: TSelect;
465
- }, axiosRequestConfig?: RequestConfig$1) => ModelRequest<ListModelResponse<S, ResolvedSelectedShape<S, TSelect, TData>>>;
466
- read: (subId: string, axiosRequestConfig?: RequestConfig$1) => ModelRequest<ModelResponse<S>>;
467
- readAdvanced: <TData extends Partial<S> | never = never, TSelect_1 extends readonly string[] = readonly string[]>(subId: string, args?: {
468
- select?: TSelect_1;
469
- populate?: unknown;
470
- }, axiosRequestConfig?: RequestConfig$1) => ModelRequest<ModelResponse<S, ResolvedSelectedShape<S, TSelect_1, TData>>>;
471
- update: (subId: string, data: object, axiosRequestConfig?: RequestConfig$1) => ModelRequest<ModelResponse<S>>;
472
- bulkUpdate: (data: object[], _options?: object, axiosRequestConfig?: RequestConfig$1) => ModelRequest<ListModelResponse<S>>;
473
- create: (data: object, axiosRequestConfig?: RequestConfig$1) => ModelRequest<ModelResponse<S>>;
474
- delete: (subId: string, axiosRequestConfig?: RequestConfig$1) => ModelRequest<Response<string, string>>;
475
- };
476
- fetch: (args?: ReadAdvancedArgs, options?: ReadAdvancedOptions, axiosRequestConfig?: RequestConfig$1) => ModelRequest<ModelResponse<T, Partial<T>>>;
477
- };
478
- private processListResult;
479
- }
480
-
481
- type RequestConfig = AxiosRequestConfig & AdditionalReqConfig;
482
- interface Props {
483
- axios: AxiosInstance;
484
- dataName: string;
485
- basePath: string;
486
- queryPath: string;
487
- onSuccess: ResponseCallback;
488
- onFailure: ResponseCallback;
489
- throwOnError: boolean;
490
- }
491
- declare class DataService<T> extends Service {
492
- private _dataName;
493
- private _queryPath;
494
- private _handleCallbacks;
495
- private _defaults;
496
- constructor({ axios, dataName, basePath, queryPath, onSuccess, onFailure, throwOnError }: Props, defaults?: DataDefaults);
497
- list<TData extends Partial<T> = T>(args?: DataListArgs, options?: DataListOptions, axiosRequestConfig?: RequestConfig): DataRequest<ListDataResponse<TData>>;
498
- listAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: DataListAdvancedArgs<TSelect>, options?: DataListAdvancedOptions, axiosRequestConfig?: RequestConfig): DataRequest<ListDataResponse<ResolvedSelectedShape<T, TSelect, TData>>>;
499
- read<TData extends Partial<T> = T>(identifier: string, options?: DataReadOptions, axiosRequestConfig?: RequestConfig): DataRequest<DataResponse<TData>>;
500
- readAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(identifier: string, args?: DataReadAdvancedArgs<TSelect>, options?: DataReadAdvancedOptions, axiosRequestConfig?: RequestConfig): DataRequest<DataResponse<ResolvedSelectedShape<T, TSelect, TData>>>;
501
- readAdvancedFilter<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: DataReadAdvancedArgs<TSelect>, options?: DataReadAdvancedOptions, axiosRequestConfig?: RequestConfig): DataRequest<DataResponse<ResolvedSelectedShape<T, TSelect, TData>>>;
502
- private processListResult;
503
- }
504
-
505
535
  interface AdapterOptions {
506
536
  rootRouterPath?: string;
507
537
  onSuccess?: ResponseCallback;
@@ -526,29 +556,42 @@ interface DataServiceOptions {
526
556
  onFailure?: ResponseCallback;
527
557
  throwOnError?: boolean;
528
558
  }
559
+ /**
560
+ * Creates a typed API adapter for `@web-ts-toolkit/access-router` model and data routes.
561
+ *
562
+ * @example
563
+ * const adapter = createAdapter({ baseURL: 'http://localhost:3000/api' });
564
+ * const userService = adapter.createModelService<User>({ modelName: 'User', basePath: 'users' });
565
+ */
529
566
  declare function createAdapter(axiosConfig?: AxiosRequestConfig, adapterOptions?: AdapterOptions): Readonly<{
530
567
  axios: axios.AxiosInstance;
531
568
  createModelService: <T>({ modelName, basePath, queryPath, mutationPath, onSuccess, onFailure, throwOnError, }: ModelServiceOptions, defaults?: Defaults) => ModelService<T>;
532
569
  createDataService: <T>({ dataName, basePath, queryPath, onSuccess, onFailure, throwOnError }: DataServiceOptions, defaults?: DataDefaults) => DataService<T>;
533
- wrapGet: <T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig) => (options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
534
- wrapPost: <T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
535
- wrapPut: <T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
536
- wrapPatch: <T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
537
- wrapDelete: <T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig) => (options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
570
+ wrapGet: <T = unknown>(url: string, defaultConfig?: AxiosRequestConfig) => (options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
571
+ wrapPost: <T = unknown>(url: string, defaultConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
572
+ wrapPut: <T = unknown>(url: string, defaultConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
573
+ wrapPatch: <T = unknown>(url: string, defaultConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
574
+ wrapDelete: <T = unknown>(url: string, defaultConfig?: AxiosRequestConfig) => (options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
538
575
  group: <T extends readonly (ModelRequest<unknown> | DataRequest<unknown>)[]>(...proms: T) => Promise<{ [K in keyof T]: Awaited<T[K]>; }>;
539
576
  }>;
540
577
 
578
+ declare enum CustomHeaders {
579
+ TotalCount = "wtt-total-count",
580
+ ReturnedCount = "wtt-returned-count",
581
+ Page = "wtt-page",
582
+ PageSize = "wtt-page-size",
583
+ TotalPages = "wtt-total-pages",
584
+ HasNextPage = "wtt-has-next-page",
585
+ HasPreviousPage = "wtt-has-previous-page"
586
+ }
587
+
541
588
  declare function replaceItemById<T extends {
542
589
  _id: string;
543
- }>(items: T[], newItem: T, options?: {
590
+ }>(items: T[], targetItem: T, options?: {
544
591
  merge: boolean;
545
592
  }): T[];
546
593
  declare function removeItemById<T extends {
547
594
  _id: string;
548
- }>(items: T[], newItem: T): T[];
549
-
550
- declare const _default: {
551
- createAdapter: typeof createAdapter;
552
- };
595
+ }>(items: T[], targetItem: T): T[];
553
596
 
554
- export { type ArrayDataResponse, type ArrayModelResponse, type DataPromiseMeta, type DataRequest, type DataResponse, DataService, type Document, type FilterQuery, type Include, type KeyValueProjection, type LazyRequest, type ListDataResponse, type ListModelResponse, Model, type ModelPromiseMeta, type ModelRequest, type ModelResponse, ModelService, type Populate, type PopulateAccess, type Projection, type ResolvedSelectedShape, type Response, type ResponseCallback, type ResultError, type RootDataQueryMeta, type RootModelQueryMeta, type RootQueryMeta, type SelectedKeys, type SelectedShape, Service, ServiceError, type Sort, type SortOrder, type SubQueryMeta, type Task, type WrapOptions, createAdapter, _default as default, removeItemById, replaceItemById, wrapLazyPromise };
597
+ export { type AdditionalReqConfig, type ArrayDataResponse, type ArrayModelResponse, type CreateAdvancedArgs, type CreateAdvancedOptions, type CreateOptions, CustomHeaders, type DataDefaults, type DataListAdvancedArgs, type DataListAdvancedOptions, type DataListArgs, type DataListOptions, type DataPromiseMeta, type DataReadAdvancedArgs, type DataReadAdvancedOptions, type DataReadOptions, type DataRequest, type DataResponse, DataService, type Defaults, type Document, type FilterQuery, type Include, type KeyValueProjection, type LazyRequest, type ListAdvancedArgs, type ListAdvancedOptions, type ListArgs, type ListDataResponse, type ListModelResponse, type ListOptions, Model, type ModelPromiseMeta, type ModelRequest, type ModelResponse, ModelService, type Populate, type PopulateAccess, type Projection, type ReadAdvancedArgs, type ReadAdvancedOptions, type ReadOptions, type ResolvedSelectedShape, type Response, type ResponseCallback, type ResultError, type RootDataQueryMeta, type RootModelQueryMeta, type RootQueryMeta, type SelectedKeys, type SelectedShape, Service, ServiceError, type Sort, type SortOrder, type SubQueryOptions, type Task, type UpdateAdvancedArgs, type UpdateAdvancedOptions, type UpdateOptions, type UpsertAdvancedArgs, type UpsertAdvancedOptions, type UpsertOptions, type WrapOptions, createAdapter, removeItemById, replaceItemById, wrapLazyPromise };