@web-ts-toolkit/access-router-client 0.3.0 → 0.5.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 (6) hide show
  1. package/README.md +39 -12
  2. package/index.d.mts +221 -194
  3. package/index.d.ts +221 -194
  4. package/index.js +785 -905
  5. package/index.mjs +781 -902
  6. 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,195 @@ 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
+ declare class ModelService<T extends Document> extends Service {
236
+ private _modelName;
237
+ private _queryPath;
238
+ private _mutationPath;
239
+ private _handleCallbacks;
240
+ private _defaults;
241
+ constructor({ axios, modelName, basePath, queryPath, mutationPath, onSuccess, onFailure, throwOnError }: Props$1, defaults?: Defaults);
242
+ list<TData extends Partial<T> = T>(args?: ListArgs, options?: ListOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ListModelResponse<T, TData>>;
243
+ 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>>>;
244
+ create<TData extends Partial<T> = T>(data: object, options?: CreateOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ModelResponse<T, TData>>;
245
+ 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>>>;
246
+ upsert<TData extends Partial<T> = T>(data: object, options?: UpsertOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ModelResponse<T, TData>>;
247
+ 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>>>;
248
+ delete(identifier: string, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<Response<string, string>>;
249
+ new<TData extends Partial<T> = T>(axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ModelResponse<T, TData>>;
250
+ distinct(field: string, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<Response<string[], string[]>>;
251
+ distinctAdvanced(field: string, conditions: FilterQuery<T>, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<Response<string[], string[]>>;
252
+ count(axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<Response<number, number>>;
253
+ countAdvanced(filter: FilterQuery<T>, args?: {
254
+ access?: 'list' | 'read';
255
+ }, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<Response<number, number>>;
256
+ read<TData extends Partial<T> = T>(identifier: string, options?: ReadOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ModelResponse<T, TData>>;
257
+ 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>>>;
258
+ 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>>>;
259
+ update<TData extends Partial<T> = T>(identifier: string, data: object, options?: UpdateOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & LazyRequest<ModelResponse<T, TData>>;
260
+ 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>>>;
261
+ id(id: string): {
262
+ subs: <S = T>(field: keyof T) => {
263
+ list: (axiosRequestConfig?: AxiosRequestConfig<any> & {
264
+ throwOnError?: boolean;
265
+ }) => ModelPromiseMeta & LazyRequest<ListModelResponse<S>>;
266
+ listAdvanced: <TData extends Partial<S> = never, TSelect extends readonly string[] = readonly string[]>(filter?: FilterQuery<S>, args?: {
267
+ select?: TSelect;
268
+ }, axiosRequestConfig?: AxiosRequestConfig<any> & {
269
+ throwOnError?: boolean;
270
+ }) => ModelPromiseMeta & LazyRequest<ListModelResponse<S, ResolvedSelectedShape<S, TSelect, TData>>>;
271
+ read: (subId: string, axiosRequestConfig?: AxiosRequestConfig<any> & {
272
+ throwOnError?: boolean;
273
+ }) => ModelPromiseMeta & LazyRequest<ModelResponse<S>>;
274
+ readAdvanced: <TData extends Partial<S> = never, TSelect_1 extends readonly string[] = readonly string[]>(subId: string, args?: {
275
+ select?: TSelect_1;
276
+ populate?: unknown;
277
+ }, axiosRequestConfig?: AxiosRequestConfig<any> & {
278
+ throwOnError?: boolean;
279
+ }) => ModelPromiseMeta & LazyRequest<ModelResponse<S, ResolvedSelectedShape<S, TSelect_1, TData>>>;
280
+ update: (subId: string, data: object, axiosRequestConfig?: AxiosRequestConfig<any> & {
281
+ throwOnError?: boolean;
282
+ }) => ModelPromiseMeta & LazyRequest<ModelResponse<S>>;
283
+ bulkUpdate: (data: object[], axiosRequestConfig?: AxiosRequestConfig<any> & {
284
+ throwOnError?: boolean;
285
+ }) => ModelPromiseMeta & LazyRequest<ListModelResponse<S>>;
286
+ create: (data: object, axiosRequestConfig?: AxiosRequestConfig<any> & {
287
+ throwOnError?: boolean;
288
+ }) => ModelPromiseMeta & LazyRequest<ModelResponse<S>>;
289
+ delete: (subId: string, axiosRequestConfig?: AxiosRequestConfig<any> & {
290
+ throwOnError?: boolean;
291
+ }) => ModelPromiseMeta & LazyRequest<Response<string, string>>;
292
+ };
293
+ fetch: (args?: ReadAdvancedArgs, options?: ReadAdvancedOptions, axiosRequestConfig?: RequestConfig$1) => ModelRequest<ModelResponse<T, Partial<T>>>;
294
+ };
295
+ }
296
+
297
+ type RequestConfig = AxiosRequestConfig & AdditionalReqConfig;
298
+ interface Props {
299
+ axios: AxiosInstance;
300
+ dataName: string;
301
+ basePath: string;
302
+ queryPath: string;
303
+ onSuccess: ResponseCallback;
304
+ onFailure: ResponseCallback;
305
+ throwOnError: boolean;
306
+ }
307
+ declare class DataService<T> extends Service {
308
+ private _dataName;
309
+ private _queryPath;
310
+ private _handleCallbacks;
311
+ private _defaults;
312
+ constructor({ axios, dataName, basePath, queryPath, onSuccess, onFailure, throwOnError }: Props, defaults?: DataDefaults);
313
+ list<TData extends Partial<T> = T>(args?: DataListArgs, options?: DataListOptions, axiosRequestConfig?: RequestConfig): DataPromiseMeta & LazyRequest<ListDataResponse<TData>>;
314
+ 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>>>;
315
+ read<TData extends Partial<T> = T>(identifier: string, options?: DataReadOptions, axiosRequestConfig?: RequestConfig): DataPromiseMeta & LazyRequest<DataResponse<TData>>;
316
+ 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>>>;
317
+ 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>>>;
318
+ }
319
+
320
+ declare class Model<T extends Document, TData extends Partial<T> = T> {
321
+ private _data;
322
+ private _snapshot;
323
+ private readonly _service;
324
+ private modifiedPaths;
325
+ constructor(data: TData, adapter: ModelService<T>);
326
+ static create<T, TData extends Partial<T> = T>(data: TData, adapter: ModelService<T>): Model<T, TData> & TData;
327
+ save(reqConfig?: AxiosRequestConfig): Promise<any>;
328
+ isDirty(path?: keyof TData | string): boolean;
329
+ markModified(path: keyof TData | string): this;
330
+ get<TKey extends keyof TData>(path: TKey): TData[TKey];
331
+ get(path: string): unknown;
332
+ set<TKey extends keyof TData>(path: TKey, value: TData[TKey]): this;
333
+ set(path: string, value: unknown): this;
334
+ assign(partial: Partial<TData>): this;
335
+ reset(): this;
336
+ toObject(): TData;
337
+ toJSON(): TData;
338
+ private updateModel;
339
+ private replaceData;
340
+ private initializeDirtyState;
341
+ private prepareData;
342
+ private defineHiddenDataProp;
343
+ private defineHiddenAdapterProp;
344
+ private definePublicDataProps;
345
+ private trackModified;
346
+ private normalizePath;
347
+ }
348
+
189
349
  type AnyArray<T> = T[] | ReadonlyArray<T>;
190
350
  type Unpacked<T> = T extends (infer U)[] ? U : T extends ReadonlyArray<infer U> ? U : T;
191
351
  type ApplyBasicQueryCasting<T> = T | T[] | (T extends (infer U)[] ? U : unknown) | unknown;
@@ -236,6 +396,13 @@ type QuerySelector<T> = {
236
396
  $options?: T extends string ? string : never;
237
397
  };
238
398
 
399
+ /**
400
+ * Wraps a lazy promise function with optional metadata.
401
+ * The promise is only created when `.then()`, `.catch()`, `.finally()`, or `.exec()` is called.
402
+ * Metadata properties are merged onto the returned object via `Object.assign`.
403
+ */
404
+ declare const wrapLazyPromise: <T, M = undefined>(promiseFn: () => Promise<T>, meta?: M) => M & LazyRequest<T>;
405
+
239
406
  type KeyValueProjection<TKey extends string = string> = Partial<Record<TKey, 1 | -1>>;
240
407
  type Projection = readonly string[] | string | KeyValueProjection;
241
408
  type SelectableKey<T> = Extract<keyof T, string>;
@@ -306,6 +473,7 @@ interface RootModelQueryMeta {
306
473
  data?: unknown;
307
474
  args?: Record<string, unknown>;
308
475
  options?: Record<string, unknown>;
476
+ order?: number;
309
477
  sqOptions?: SubQueryOptions;
310
478
  }
311
479
  interface RootDataQueryMeta {
@@ -317,17 +485,9 @@ interface RootDataQueryMeta {
317
485
  data?: unknown;
318
486
  args?: Record<string, unknown>;
319
487
  options?: Record<string, unknown>;
488
+ order?: number;
320
489
  }
321
490
  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
491
  interface ModelPromiseMeta {
332
492
  __op: string;
333
493
  __query: RootModelQueryMeta;
@@ -337,6 +497,7 @@ interface ModelPromiseMeta {
337
497
  interface LazyRequest<T> extends Promise<T> {
338
498
  exec(): Promise<T>;
339
499
  }
500
+ type ModelRequest<T> = ModelPromiseMeta & LazyRequest<T>;
340
501
  type DataResponse<T> = Response<T, T>;
341
502
  type ArrayDataResponse<T> = Response<T[], T[]>;
342
503
  type ListDataResponse<T> = ArrayDataResponse<T> & {
@@ -348,158 +509,14 @@ interface DataPromiseMeta {
348
509
  __requestConfig?: AxiosRequestConfig;
349
510
  __service?: DataService<unknown>;
350
511
  }
351
- declare const wrapLazyPromise: <T, M = undefined>(promiseFn: () => Promise<T>, meta?: M) => M & LazyRequest<T>;
512
+ type DataRequest<T> = DataPromiseMeta & LazyRequest<T>;
513
+
352
514
  type ResponseCallback = (res: unknown) => void;
353
515
  interface WrapOptions {
354
516
  queryParams?: Record<string, unknown>;
355
517
  pathParams?: Record<string, string | number>;
356
518
  }
357
519
 
358
- interface ResultError {
359
- success: boolean;
360
- raw: unknown;
361
- data: unknown;
362
- message: string;
363
- status: number;
364
- headers: Record<string, unknown>;
365
- }
366
- declare class Service {
367
- protected _axios: AxiosInstance;
368
- protected _basePath: string;
369
- constructor(axios: AxiosInstance, basePath: string);
370
- protected handleSuccess(res: AxiosResponse<unknown, unknown>, extra?: {}): Response<unknown>;
371
- protected handleError<T extends ResultError>(error: {
372
- response?: {
373
- status: number;
374
- headers: Record<string, unknown>;
375
- data: unknown;
376
- };
377
- request?: unknown;
378
- message?: string;
379
- }): T;
380
- wrapGet<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
381
- wrapPost<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
382
- wrapPut<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
383
- wrapPatch<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
384
- wrapDelete<T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig): (options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<AxiosResponse<T, any, {}>>;
385
- updateHeaders(headers: AxiosRequestConfig['headers'], { ignoreCache }: {
386
- ignoreCache?: boolean;
387
- }): AxiosHeaders | (Partial<axios.RawAxiosHeaders & {
388
- Accept: axios.AxiosHeaderValue;
389
- "Content-Length": axios.AxiosHeaderValue;
390
- "User-Agent": axios.AxiosHeaderValue;
391
- "Content-Encoding": axios.AxiosHeaderValue;
392
- Authorization: axios.AxiosHeaderValue;
393
- Location: axios.AxiosHeaderValue;
394
- } & {
395
- 'Content-Type': axios.AxiosHeaderValue;
396
- }> & Partial<{
397
- get: AxiosHeaders;
398
- delete: AxiosHeaders;
399
- head: AxiosHeaders;
400
- options: AxiosHeaders;
401
- post: AxiosHeaders;
402
- put: AxiosHeaders;
403
- patch: AxiosHeaders;
404
- purge: AxiosHeaders;
405
- link: AxiosHeaders;
406
- unlink: AxiosHeaders;
407
- query: AxiosHeaders;
408
- } & {
409
- common: AxiosHeaders;
410
- }>);
411
- }
412
- declare class ServiceError extends Error {
413
- success: boolean;
414
- raw: unknown;
415
- data: unknown;
416
- status: number;
417
- headers: Record<string, unknown>;
418
- constructor(result: ResultError);
419
- }
420
-
421
- type RequestConfig$1 = AxiosRequestConfig & AdditionalReqConfig;
422
- interface Props$1 {
423
- axios: AxiosInstance;
424
- modelName: string;
425
- basePath: string;
426
- queryPath: string;
427
- mutationPath: string;
428
- onSuccess: ResponseCallback;
429
- onFailure: ResponseCallback;
430
- throwOnError: boolean;
431
- }
432
- declare class ModelService<T extends Document> extends Service {
433
- private _modelName;
434
- private _queryPath;
435
- private _mutationPath;
436
- private _handleCallbacks;
437
- private _defaults;
438
- constructor({ axios, modelName, basePath, queryPath, mutationPath, onSuccess, onFailure, throwOnError }: Props$1, defaults?: Defaults);
439
- list<TData extends Partial<T> = T>(args?: ListArgs, options?: ListOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ListModelResponse<T, TData>>;
440
- listAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: ListAdvancedArgs<TSelect>, options?: ListAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ListModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
441
- read<TData extends Partial<T> = T>(identifier: string, options?: ReadOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ModelResponse<T, TData>>;
442
- readAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(identifier: string, args?: ReadAdvancedArgs<TSelect>, options?: ReadAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
443
- readAdvancedFilter<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: ReadAdvancedArgs<TSelect>, options?: ReadAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
444
- new<TData extends Partial<T> = T>(axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ModelResponse<T, TData>>;
445
- create<TData extends Partial<T> = T>(data: object, options?: CreateOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ModelResponse<T, TData>>;
446
- createAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(data: object, args?: CreateAdvancedArgs<TSelect>, options?: CreateAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
447
- update<TData extends Partial<T> = T>(identifier: string, data: object, options?: UpdateOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ModelResponse<T, TData>>;
448
- updateAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(identifier: string, data: object, args?: UpdateAdvancedArgs<TSelect>, options?: UpdateAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
449
- upsert<TData extends Partial<T> = T>(data: object, options?: UpsertOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ModelResponse<T, TData>>;
450
- upsertAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(data: object, args?: UpsertAdvancedArgs<TSelect>, options?: UpsertAdvancedOptions, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<ModelResponse<T, ResolvedSelectedShape<T, TSelect, TData>>>;
451
- delete(identifier: string, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<Response<string, string>>;
452
- distinct(field: string, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<Response<string[], string[]>>;
453
- distinctAdvanced(field: string, conditions: FilterQuery<T>, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<Response<string[], string[]>>;
454
- count(axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<Response<number, number>>;
455
- countAdvanced(filter: FilterQuery<T>, args?: {
456
- access?: string;
457
- }, axiosRequestConfig?: RequestConfig$1): ModelPromiseMeta & Promise<Response<number, number>>;
458
- id(id: string): {
459
- subs: <S = T>(field: keyof T) => {
460
- list: (axiosRequestConfig?: RequestConfig$1) => ModelPromiseMeta & Promise<ListModelResponse<S>>;
461
- listAdvanced: <TData extends Partial<S> | never = never, TSelect extends readonly string[] = readonly string[]>(filter?: FilterQuery<S>, args?: {
462
- select?: TSelect;
463
- }, axiosRequestConfig?: RequestConfig$1) => ModelPromiseMeta & Promise<ListModelResponse<S, ResolvedSelectedShape<S, TSelect, TData>>>;
464
- read: (subId: string, axiosRequestConfig?: RequestConfig$1) => ModelPromiseMeta & Promise<ModelResponse<S>>;
465
- readAdvanced: <TData extends Partial<S> | never = never, TSelect_1 extends readonly string[] = readonly string[]>(subId: string, args?: {
466
- select?: TSelect_1;
467
- populate?: unknown;
468
- }, axiosRequestConfig?: RequestConfig$1) => ModelPromiseMeta & Promise<ModelResponse<S, ResolvedSelectedShape<S, TSelect_1, TData>>>;
469
- update: (subId: string, data: object, axiosRequestConfig?: RequestConfig$1) => ModelPromiseMeta & Promise<ModelResponse<S>>;
470
- bulkUpdate: (data: object[], _options?: object, axiosRequestConfig?: RequestConfig$1) => ModelPromiseMeta & Promise<ListModelResponse<S>>;
471
- create: (data: object, axiosRequestConfig?: RequestConfig$1) => ModelPromiseMeta & Promise<ModelResponse<S>>;
472
- delete: (subId: string, axiosRequestConfig?: RequestConfig$1) => ModelPromiseMeta & Promise<Response<string, string>>;
473
- };
474
- fetch: (args?: ReadAdvancedArgs, options?: ReadAdvancedOptions, axiosRequestConfig?: RequestConfig$1) => ModelPromiseMeta & Promise<ModelResponse<T, Partial<T>>>;
475
- };
476
- private processListResult;
477
- }
478
-
479
- type RequestConfig = AxiosRequestConfig & AdditionalReqConfig;
480
- interface Props {
481
- axios: AxiosInstance;
482
- dataName: string;
483
- basePath: string;
484
- queryPath: string;
485
- onSuccess: ResponseCallback;
486
- onFailure: ResponseCallback;
487
- throwOnError: boolean;
488
- }
489
- declare class DataService<T> extends Service {
490
- private _dataName;
491
- private _queryPath;
492
- private _handleCallbacks;
493
- private _defaults;
494
- constructor({ axios, dataName, basePath, queryPath, onSuccess, onFailure, throwOnError }: Props, defaults?: DataDefaults);
495
- list<TData extends Partial<T> = T>(args?: DataListArgs, options?: DataListOptions, axiosRequestConfig?: RequestConfig): DataPromiseMeta & Promise<ListDataResponse<TData>>;
496
- listAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: DataListAdvancedArgs<TSelect>, options?: DataListAdvancedOptions, axiosRequestConfig?: RequestConfig): DataPromiseMeta & Promise<ListDataResponse<ResolvedSelectedShape<T, TSelect, TData>>>;
497
- read<TData extends Partial<T> = T>(identifier: string, options?: DataReadOptions, axiosRequestConfig?: RequestConfig): DataPromiseMeta & Promise<DataResponse<TData>>;
498
- readAdvanced<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(identifier: string, args?: DataReadAdvancedArgs<TSelect>, options?: DataReadAdvancedOptions, axiosRequestConfig?: RequestConfig): DataPromiseMeta & Promise<DataResponse<ResolvedSelectedShape<T, TSelect, TData>>>;
499
- readAdvancedFilter<TData extends Partial<T> | never = never, TSelect extends Projection = Projection>(filter: FilterQuery<T>, args?: DataReadAdvancedArgs<TSelect>, options?: DataReadAdvancedOptions, axiosRequestConfig?: RequestConfig): DataPromiseMeta & Promise<DataResponse<ResolvedSelectedShape<T, TSelect, TData>>>;
500
- private processListResult;
501
- }
502
-
503
520
  interface AdapterOptions {
504
521
  rootRouterPath?: string;
505
522
  onSuccess?: ResponseCallback;
@@ -528,25 +545,35 @@ declare function createAdapter(axiosConfig?: AxiosRequestConfig, adapterOptions?
528
545
  axios: axios.AxiosInstance;
529
546
  createModelService: <T>({ modelName, basePath, queryPath, mutationPath, onSuccess, onFailure, throwOnError, }: ModelServiceOptions, defaults?: Defaults) => ModelService<T>;
530
547
  createDataService: <T>({ dataName, basePath, queryPath, onSuccess, onFailure, throwOnError }: DataServiceOptions, defaults?: DataDefaults) => DataService<T>;
531
- wrapGet: <T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig) => (options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
532
- wrapPost: <T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
533
- wrapPut: <T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
534
- wrapPatch: <T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
535
- wrapDelete: <T = unknown>(url: string, defaultAxiosRequestConfig?: AxiosRequestConfig) => (options?: WrapOptions, axiosRequestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
536
- group: <T extends ((ModelPromiseMeta | DataPromiseMeta) & LazyRequest<unknown>)[]>(...proms: T) => Promise<{ [K in keyof T]: T[K] extends Promise<infer U> ? U : never; }>;
548
+ wrapGet: <T = unknown>(url: string, defaultConfig?: AxiosRequestConfig) => (options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
549
+ wrapPost: <T = unknown>(url: string, defaultConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
550
+ wrapPut: <T = unknown>(url: string, defaultConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
551
+ wrapPatch: <T = unknown>(url: string, defaultConfig?: AxiosRequestConfig) => (data?: unknown, options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
552
+ wrapDelete: <T = unknown>(url: string, defaultConfig?: AxiosRequestConfig) => (options?: WrapOptions, requestConfig?: AxiosRequestConfig) => Promise<axios.AxiosResponse<T, any, {}>>;
553
+ group: <T extends readonly (ModelRequest<unknown> | DataRequest<unknown>)[]>(...proms: T) => Promise<{ [K in keyof T]: Awaited<T[K]>; }>;
537
554
  }>;
538
555
 
556
+ declare enum CustomHeaders {
557
+ TotalCount = "wtt-total-count",
558
+ ReturnedCount = "wtt-returned-count",
559
+ Page = "wtt-page",
560
+ PageSize = "wtt-page-size",
561
+ TotalPages = "wtt-total-pages",
562
+ HasNextPage = "wtt-has-next-page",
563
+ HasPreviousPage = "wtt-has-previous-page"
564
+ }
565
+
539
566
  declare function replaceItemById<T extends {
540
567
  _id: string;
541
- }>(items: T[], newItem: T, options?: {
568
+ }>(items: T[], targetItem: T, options?: {
542
569
  merge: boolean;
543
570
  }): T[];
544
571
  declare function removeItemById<T extends {
545
572
  _id: string;
546
- }>(items: T[], newItem: T): T[];
573
+ }>(items: T[], targetItem: T): T[];
547
574
 
548
575
  declare const _default: {
549
576
  createAdapter: typeof createAdapter;
550
577
  };
551
578
 
552
- export { type ArrayDataResponse, type ArrayModelResponse, type DataPromiseMeta, type DataResponse, DataService, type Document, type FilterQuery, type Include, type KeyValueProjection, type LazyRequest, type ListDataResponse, type ListModelResponse, Model, type ModelPromiseMeta, 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 };
579
+ 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, _default as default, removeItemById, replaceItemById, wrapLazyPromise };