@web-ts-toolkit/access-router-client 0.3.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.
- package/LICENSE +201 -0
- package/README.md +45 -0
- package/index.d.mts +552 -0
- package/index.d.ts +552 -0
- package/index.js +2016 -0
- package/index.mjs +1972 -0
- package/package.json +40 -0
package/index.d.mts
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
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
|
+
}
|
|
32
|
+
|
|
33
|
+
interface SubQueryOptions {
|
|
34
|
+
path?: string;
|
|
35
|
+
compact?: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface ListArgs {
|
|
38
|
+
skip?: number;
|
|
39
|
+
limit?: number;
|
|
40
|
+
page?: number;
|
|
41
|
+
pageSize?: number;
|
|
42
|
+
}
|
|
43
|
+
interface ListOptions {
|
|
44
|
+
skim?: boolean;
|
|
45
|
+
includePermissions?: boolean;
|
|
46
|
+
includeCount?: boolean;
|
|
47
|
+
includeExtraHeaders?: boolean;
|
|
48
|
+
ignoreCache?: boolean;
|
|
49
|
+
sq?: SubQueryOptions;
|
|
50
|
+
}
|
|
51
|
+
interface ListAdvancedArgs<TSelect extends Projection = Projection> {
|
|
52
|
+
select?: TSelect;
|
|
53
|
+
populate?: Populate[] | Populate | string;
|
|
54
|
+
include?: Include | Include[];
|
|
55
|
+
sort?: Sort;
|
|
56
|
+
skip?: string | number;
|
|
57
|
+
limit?: string | number;
|
|
58
|
+
page?: string | number;
|
|
59
|
+
pageSize?: string | number;
|
|
60
|
+
tasks?: Task | Task[];
|
|
61
|
+
}
|
|
62
|
+
interface ListAdvancedOptions {
|
|
63
|
+
skim?: boolean;
|
|
64
|
+
includePermissions?: boolean;
|
|
65
|
+
includeCount?: boolean;
|
|
66
|
+
includeExtraHeaders?: boolean;
|
|
67
|
+
ignoreCache?: boolean;
|
|
68
|
+
populateAccess?: PopulateAccess;
|
|
69
|
+
sq?: SubQueryOptions;
|
|
70
|
+
}
|
|
71
|
+
interface ReadOptions {
|
|
72
|
+
includePermissions?: boolean;
|
|
73
|
+
tryList?: boolean;
|
|
74
|
+
ignoreCache?: boolean;
|
|
75
|
+
sq?: SubQueryOptions;
|
|
76
|
+
}
|
|
77
|
+
interface ReadAdvancedArgs<TSelect extends Projection = Projection> {
|
|
78
|
+
select?: TSelect;
|
|
79
|
+
sort?: Sort;
|
|
80
|
+
populate?: Populate[] | Populate | string;
|
|
81
|
+
include?: Include | Include[];
|
|
82
|
+
tasks?: Task | Task[];
|
|
83
|
+
}
|
|
84
|
+
interface ReadAdvancedOptions {
|
|
85
|
+
skim?: boolean;
|
|
86
|
+
includePermissions?: boolean;
|
|
87
|
+
tryList?: boolean;
|
|
88
|
+
populateAccess?: PopulateAccess;
|
|
89
|
+
ignoreCache?: boolean;
|
|
90
|
+
sq?: SubQueryOptions;
|
|
91
|
+
}
|
|
92
|
+
interface CreateOptions {
|
|
93
|
+
includePermissions?: boolean;
|
|
94
|
+
}
|
|
95
|
+
interface CreateAdvancedArgs<TSelect extends Projection = Projection> {
|
|
96
|
+
select?: TSelect;
|
|
97
|
+
populate?: Populate[] | Populate | string;
|
|
98
|
+
tasks?: Task | Task[];
|
|
99
|
+
}
|
|
100
|
+
interface CreateAdvancedOptions {
|
|
101
|
+
includePermissions?: boolean;
|
|
102
|
+
populateAccess?: PopulateAccess;
|
|
103
|
+
}
|
|
104
|
+
interface UpdateOptions {
|
|
105
|
+
returningAll?: boolean;
|
|
106
|
+
}
|
|
107
|
+
interface UpdateAdvancedArgs<TSelect extends Projection = Projection> {
|
|
108
|
+
select?: TSelect;
|
|
109
|
+
populate?: Populate[] | Populate | string;
|
|
110
|
+
tasks?: Task | Task[];
|
|
111
|
+
}
|
|
112
|
+
interface UpdateAdvancedOptions {
|
|
113
|
+
returningAll?: boolean;
|
|
114
|
+
includePermissions?: boolean;
|
|
115
|
+
populateAccess?: PopulateAccess;
|
|
116
|
+
}
|
|
117
|
+
type UpsertOptions = UpdateOptions;
|
|
118
|
+
type UpsertAdvancedArgs<TSelect extends Projection = Projection> = UpdateAdvancedArgs<TSelect>;
|
|
119
|
+
type UpsertAdvancedOptions = UpdateAdvancedOptions;
|
|
120
|
+
interface Defaults {
|
|
121
|
+
listArgs?: ListArgs;
|
|
122
|
+
listOptions?: ListOptions;
|
|
123
|
+
listAdvancedArgs?: ListAdvancedArgs;
|
|
124
|
+
listAdvancedOptions?: ListAdvancedOptions;
|
|
125
|
+
readOptions?: ReadOptions;
|
|
126
|
+
readAdvancedArgs?: ReadAdvancedArgs;
|
|
127
|
+
readAdvancedOptions?: ReadAdvancedOptions;
|
|
128
|
+
createOptions?: CreateOptions;
|
|
129
|
+
createAdvancedArgs?: CreateAdvancedArgs;
|
|
130
|
+
createAdvancedOptions?: CreateAdvancedOptions;
|
|
131
|
+
updateOptions?: UpdateOptions;
|
|
132
|
+
updateAdvancedArgs?: UpdateAdvancedArgs;
|
|
133
|
+
updateAdvancedOptions?: UpdateAdvancedOptions;
|
|
134
|
+
upsertOptions?: UpsertOptions;
|
|
135
|
+
upsertAdvancedArgs?: UpsertAdvancedArgs;
|
|
136
|
+
upsertAdvancedOptions?: UpsertAdvancedOptions;
|
|
137
|
+
}
|
|
138
|
+
interface DataListArgs {
|
|
139
|
+
skip?: number;
|
|
140
|
+
limit?: number;
|
|
141
|
+
page?: number;
|
|
142
|
+
pageSize?: number;
|
|
143
|
+
}
|
|
144
|
+
interface DataListOptions {
|
|
145
|
+
includePermissions?: boolean;
|
|
146
|
+
includeCount?: boolean;
|
|
147
|
+
includeExtraHeaders?: boolean;
|
|
148
|
+
ignoreCache?: boolean;
|
|
149
|
+
}
|
|
150
|
+
interface DataListAdvancedArgs<TSelect extends Projection = Projection> {
|
|
151
|
+
select?: TSelect;
|
|
152
|
+
sort?: Sort;
|
|
153
|
+
skip?: string | number;
|
|
154
|
+
limit?: string | number;
|
|
155
|
+
page?: string | number;
|
|
156
|
+
pageSize?: string | number;
|
|
157
|
+
}
|
|
158
|
+
interface DataListAdvancedOptions {
|
|
159
|
+
includePermissions?: boolean;
|
|
160
|
+
includeCount?: boolean;
|
|
161
|
+
includeExtraHeaders?: boolean;
|
|
162
|
+
ignoreCache?: boolean;
|
|
163
|
+
}
|
|
164
|
+
interface DataReadOptions {
|
|
165
|
+
includePermissions?: boolean;
|
|
166
|
+
ignoreCache?: boolean;
|
|
167
|
+
}
|
|
168
|
+
interface DataReadAdvancedArgs<TSelect extends Projection = Projection> {
|
|
169
|
+
select?: TSelect;
|
|
170
|
+
ignoreCache?: boolean;
|
|
171
|
+
}
|
|
172
|
+
interface DataReadAdvancedOptions {
|
|
173
|
+
includePermissions?: boolean;
|
|
174
|
+
ignoreCache?: boolean;
|
|
175
|
+
}
|
|
176
|
+
interface DataDefaults {
|
|
177
|
+
listArgs?: DataListArgs;
|
|
178
|
+
listOptions?: DataListOptions;
|
|
179
|
+
listAdvancedArgs?: DataListAdvancedArgs;
|
|
180
|
+
listAdvancedOptions?: DataListAdvancedOptions;
|
|
181
|
+
readOptions?: DataReadOptions;
|
|
182
|
+
readAdvancedArgs?: DataReadAdvancedArgs;
|
|
183
|
+
readAdvancedOptions?: DataReadAdvancedOptions;
|
|
184
|
+
}
|
|
185
|
+
interface AdditionalReqConfig {
|
|
186
|
+
throwOnError?: boolean;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
type AnyArray<T> = T[] | ReadonlyArray<T>;
|
|
190
|
+
type Unpacked<T> = T extends (infer U)[] ? U : T extends ReadonlyArray<infer U> ? U : T;
|
|
191
|
+
type ApplyBasicQueryCasting<T> = T | T[] | (T extends (infer U)[] ? U : unknown) | unknown;
|
|
192
|
+
type Condition<T> = ApplyBasicQueryCasting<T> | QuerySelector<ApplyBasicQueryCasting<T>>;
|
|
193
|
+
type _FilterQuery<T> = {
|
|
194
|
+
[P in keyof T]?: Condition<T[P]>;
|
|
195
|
+
} & RootQuerySelector<T>;
|
|
196
|
+
type RootQuerySelector<T> = {
|
|
197
|
+
/** @see https://www.mongodb.com/docs/manual/reference/operator/query/and/#op._S_and */
|
|
198
|
+
$and?: Array<_FilterQuery<T>>;
|
|
199
|
+
/** @see https://www.mongodb.com/docs/manual/reference/operator/query/nor/#op._S_nor */
|
|
200
|
+
$nor?: Array<_FilterQuery<T>>;
|
|
201
|
+
/** @see https://www.mongodb.com/docs/manual/reference/operator/query/or/#op._S_or */
|
|
202
|
+
$or?: Array<_FilterQuery<T>>;
|
|
203
|
+
/** @see https://www.mongodb.com/docs/manual/reference/operator/query/text */
|
|
204
|
+
$text?: {
|
|
205
|
+
$search: string;
|
|
206
|
+
$language?: string;
|
|
207
|
+
$caseSensitive?: boolean;
|
|
208
|
+
$diacriticSensitive?: boolean;
|
|
209
|
+
};
|
|
210
|
+
/** @see https://www.mongodb.com/docs/manual/reference/operator/query/where/#op._S_where */
|
|
211
|
+
$where?: string | ((...args: never[]) => unknown);
|
|
212
|
+
/** @see https://www.mongodb.com/docs/manual/reference/operator/query/comment/#op._S_comment */
|
|
213
|
+
$comment?: string;
|
|
214
|
+
[key: string]: unknown;
|
|
215
|
+
};
|
|
216
|
+
type QuerySelector<T> = {
|
|
217
|
+
$eq?: T;
|
|
218
|
+
$gt?: T;
|
|
219
|
+
$gte?: T;
|
|
220
|
+
$in?: [T] extends AnyArray<unknown> ? Unpacked<T>[] : T[];
|
|
221
|
+
$lt?: T;
|
|
222
|
+
$lte?: T;
|
|
223
|
+
$ne?: T;
|
|
224
|
+
$nin?: [T] extends AnyArray<unknown> ? Unpacked<T>[] : T[];
|
|
225
|
+
$not?: T extends string ? QuerySelector<T> | RegExp : QuerySelector<T>;
|
|
226
|
+
/**
|
|
227
|
+
* When `true`, `$exists` matches the documents that contain the field,
|
|
228
|
+
* including documents where the field value is null.
|
|
229
|
+
*/
|
|
230
|
+
$exists?: boolean;
|
|
231
|
+
$type?: string | number;
|
|
232
|
+
$expr?: unknown;
|
|
233
|
+
$jsonSchema?: unknown;
|
|
234
|
+
$mod?: T extends number ? [number, number] : never;
|
|
235
|
+
$regex?: T extends string ? RegExp | string : never;
|
|
236
|
+
$options?: T extends string ? string : never;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
type KeyValueProjection<TKey extends string = string> = Partial<Record<TKey, 1 | -1>>;
|
|
240
|
+
type Projection = readonly string[] | string | KeyValueProjection;
|
|
241
|
+
type SelectableKey<T> = Extract<keyof T, string>;
|
|
242
|
+
type IsTuple<T extends readonly unknown[]> = number extends T['length'] ? false : true;
|
|
243
|
+
type SelectedKeysFromProjectionArray<T, TSelect> = TSelect extends readonly (infer K)[] ? IsTuple<TSelect> extends true ? Extract<K, SelectableKey<T>> : never : never;
|
|
244
|
+
type SelectedKeysFromProjectionString<T, TSelect> = TSelect extends string ? string extends TSelect ? never : Extract<TSelect, SelectableKey<T>> : never;
|
|
245
|
+
type SelectedKeysFromProjectionObject<T, TSelect> = TSelect extends KeyValueProjection ? string extends keyof TSelect ? never : {
|
|
246
|
+
[K in keyof TSelect]-?: TSelect[K] extends 1 ? Extract<K, SelectableKey<T>> : never;
|
|
247
|
+
}[keyof TSelect] : never;
|
|
248
|
+
type SelectedKeys<T, TSelect> = SelectedKeysFromProjectionArray<T, TSelect> | SelectedKeysFromProjectionString<T, TSelect> | SelectedKeysFromProjectionObject<T, TSelect>;
|
|
249
|
+
type SelectedShape<T, TSelect> = [SelectedKeys<T, TSelect>] extends [never] ? Partial<T> : Pick<T, SelectedKeys<T, TSelect>> & Partial<T>;
|
|
250
|
+
type ResolvedSelectedShape<T, TSelect, TExplicit> = [TExplicit] extends [never] ? SelectedShape<T, TSelect> : TExplicit;
|
|
251
|
+
type SortOrder = -1 | 1 | 'asc' | 'ascending' | 'desc' | 'descending';
|
|
252
|
+
type Sort = string | {
|
|
253
|
+
[key: string]: SortOrder;
|
|
254
|
+
} | [string, SortOrder][] | undefined | null;
|
|
255
|
+
type FilterQuery<T> = _FilterQuery<T>;
|
|
256
|
+
interface Include {
|
|
257
|
+
model: string;
|
|
258
|
+
op: 'list' | 'read' | 'count';
|
|
259
|
+
path: string;
|
|
260
|
+
localField: string;
|
|
261
|
+
foreignField: string;
|
|
262
|
+
filter?: FilterQuery<unknown>;
|
|
263
|
+
args?: Record<string, unknown>;
|
|
264
|
+
options?: Record<string, unknown>;
|
|
265
|
+
}
|
|
266
|
+
type PopulateAccess = 'list' | 'read';
|
|
267
|
+
interface Populate {
|
|
268
|
+
path: string;
|
|
269
|
+
select?: Projection;
|
|
270
|
+
match?: Record<string, unknown> | null;
|
|
271
|
+
access?: PopulateAccess;
|
|
272
|
+
}
|
|
273
|
+
interface Document {
|
|
274
|
+
_id?: string;
|
|
275
|
+
}
|
|
276
|
+
interface Response<T1, T2 = T1> {
|
|
277
|
+
success: boolean;
|
|
278
|
+
raw: T1;
|
|
279
|
+
data: T2;
|
|
280
|
+
message: string;
|
|
281
|
+
status: number;
|
|
282
|
+
headers: Record<string, string>;
|
|
283
|
+
}
|
|
284
|
+
type ModelResponse<T, TData extends Partial<T> = T> = Response<TData, Model<T, TData> & TData>;
|
|
285
|
+
type ArrayModelResponse<T, TData extends Partial<T> = T> = Response<TData[], (Model<T, TData> & TData)[]>;
|
|
286
|
+
type ListModelResponse<T, TData extends Partial<T> = T> = ArrayModelResponse<T, TData> & {
|
|
287
|
+
totalCount: number;
|
|
288
|
+
};
|
|
289
|
+
interface Task {
|
|
290
|
+
type: string;
|
|
291
|
+
args: unknown;
|
|
292
|
+
options: Record<string, unknown>;
|
|
293
|
+
}
|
|
294
|
+
type RootModelOperation = 'new' | 'list' | 'read' | 'create' | 'update' | 'upsert' | 'delete' | 'distinct' | 'count' | 'subList' | 'subRead' | 'subCreate' | 'subUpdate' | 'subBulkUpdate' | 'subDelete';
|
|
295
|
+
type RootDataOperation = 'list' | 'read';
|
|
296
|
+
interface RootModelQueryMeta {
|
|
297
|
+
target: 'model';
|
|
298
|
+
name: string;
|
|
299
|
+
model: string;
|
|
300
|
+
op: RootModelOperation;
|
|
301
|
+
id?: string;
|
|
302
|
+
sub?: string;
|
|
303
|
+
subId?: string;
|
|
304
|
+
field?: string;
|
|
305
|
+
filter?: unknown;
|
|
306
|
+
data?: unknown;
|
|
307
|
+
args?: Record<string, unknown>;
|
|
308
|
+
options?: Record<string, unknown>;
|
|
309
|
+
sqOptions?: SubQueryOptions;
|
|
310
|
+
}
|
|
311
|
+
interface RootDataQueryMeta {
|
|
312
|
+
target: 'data';
|
|
313
|
+
name: string;
|
|
314
|
+
op: RootDataOperation;
|
|
315
|
+
id?: string;
|
|
316
|
+
filter?: unknown;
|
|
317
|
+
data?: unknown;
|
|
318
|
+
args?: Record<string, unknown>;
|
|
319
|
+
options?: Record<string, unknown>;
|
|
320
|
+
}
|
|
321
|
+
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
|
+
interface ModelPromiseMeta {
|
|
332
|
+
__op: string;
|
|
333
|
+
__query: RootModelQueryMeta;
|
|
334
|
+
__requestConfig?: AxiosRequestConfig;
|
|
335
|
+
__service?: ModelService<Document>;
|
|
336
|
+
}
|
|
337
|
+
interface LazyRequest<T> extends Promise<T> {
|
|
338
|
+
exec(): Promise<T>;
|
|
339
|
+
}
|
|
340
|
+
type DataResponse<T> = Response<T, T>;
|
|
341
|
+
type ArrayDataResponse<T> = Response<T[], T[]>;
|
|
342
|
+
type ListDataResponse<T> = ArrayDataResponse<T> & {
|
|
343
|
+
totalCount: number;
|
|
344
|
+
};
|
|
345
|
+
interface DataPromiseMeta {
|
|
346
|
+
__op: string;
|
|
347
|
+
__query: RootDataQueryMeta;
|
|
348
|
+
__requestConfig?: AxiosRequestConfig;
|
|
349
|
+
__service?: DataService<unknown>;
|
|
350
|
+
}
|
|
351
|
+
declare const wrapLazyPromise: <T, M = undefined>(promiseFn: () => Promise<T>, meta?: M) => M & LazyRequest<T>;
|
|
352
|
+
type ResponseCallback = (res: unknown) => void;
|
|
353
|
+
interface WrapOptions {
|
|
354
|
+
queryParams?: Record<string, unknown>;
|
|
355
|
+
pathParams?: Record<string, string | number>;
|
|
356
|
+
}
|
|
357
|
+
|
|
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
|
+
interface AdapterOptions {
|
|
504
|
+
rootRouterPath?: string;
|
|
505
|
+
onSuccess?: ResponseCallback;
|
|
506
|
+
onFailure?: ResponseCallback;
|
|
507
|
+
throwOnError?: boolean;
|
|
508
|
+
cacheTTL?: number;
|
|
509
|
+
}
|
|
510
|
+
interface ModelServiceOptions {
|
|
511
|
+
modelName: string;
|
|
512
|
+
basePath: string;
|
|
513
|
+
queryPath?: string;
|
|
514
|
+
mutationPath?: string;
|
|
515
|
+
onSuccess?: ResponseCallback;
|
|
516
|
+
onFailure?: ResponseCallback;
|
|
517
|
+
throwOnError?: boolean;
|
|
518
|
+
}
|
|
519
|
+
interface DataServiceOptions {
|
|
520
|
+
dataName: string;
|
|
521
|
+
basePath: string;
|
|
522
|
+
queryPath?: string;
|
|
523
|
+
onSuccess?: ResponseCallback;
|
|
524
|
+
onFailure?: ResponseCallback;
|
|
525
|
+
throwOnError?: boolean;
|
|
526
|
+
}
|
|
527
|
+
declare function createAdapter(axiosConfig?: AxiosRequestConfig, adapterOptions?: AdapterOptions): Readonly<{
|
|
528
|
+
axios: axios.AxiosInstance;
|
|
529
|
+
createModelService: <T>({ modelName, basePath, queryPath, mutationPath, onSuccess, onFailure, throwOnError, }: ModelServiceOptions, defaults?: Defaults) => ModelService<T>;
|
|
530
|
+
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; }>;
|
|
537
|
+
}>;
|
|
538
|
+
|
|
539
|
+
declare function replaceItemById<T extends {
|
|
540
|
+
_id: string;
|
|
541
|
+
}>(items: T[], newItem: T, options?: {
|
|
542
|
+
merge: boolean;
|
|
543
|
+
}): T[];
|
|
544
|
+
declare function removeItemById<T extends {
|
|
545
|
+
_id: string;
|
|
546
|
+
}>(items: T[], newItem: T): T[];
|
|
547
|
+
|
|
548
|
+
declare const _default: {
|
|
549
|
+
createAdapter: typeof createAdapter;
|
|
550
|
+
};
|
|
551
|
+
|
|
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 };
|