-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathpinejs-client-core.d.ts
701 lines (627 loc) · 18.7 KB
/
pinejs-client-core.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
import type { WebResourceFile } from 'balena-request';
import type {
AnyObject,
PropsAssignableWithType,
PropsOfType,
StringKeyof,
Dictionary,
ExactlyExtends,
NoInfer,
} from './utils';
export interface WithId {
id: number;
}
export interface PineDeferred {
__id: number;
}
/**
* When not selected-out holds a deferred.
* When expanded hold an array with a single element.
*/
export type ConceptTypeNavigationResource<T extends object> = [T] | number;
export type NavigationResource<T extends object> = [T] | PineDeferred;
export type OptionalNavigationResource<T extends object> =
| []
| [T]
| PineDeferred
| null;
/**
* When expanded holds an array, otherwise the property is not present.
* Selecting is not suggested,
* in that case it holds a deferred to the original resource.
*/
export type ReverseNavigationResource<T extends object> = T[] | undefined;
export type AssociatedResource<T extends object> =
| ConceptTypeNavigationResource<T>
| NavigationResource<T>
| OptionalNavigationResource<T>
| ReverseNavigationResource<T>;
export type InferAssociatedResourceType<T> =
T extends AssociatedResource<object> & any[] ? T[number] : never;
export type SelectableProps<T> =
// This allows us to get proper results when T is any/AnyObject, otherwise this returned never
PropsOfType<T, ReverseNavigationResource<object>> extends StringKeyof<T>
? StringKeyof<T>
: Exclude<
StringKeyof<T>,
PropsOfType<T, ReverseNavigationResource<object>>
>; // This is the normal typed case
export type ExpandableProps<T> = PropsOfType<T, AssociatedResource<object>> &
// TODO: Drop me once Pine unifies ConceptTypeNavigationResource with NavigationResource
PropsAssignableWithType<T, [] | [any] | any[]> &
string;
type SelectedProperty<T, K extends keyof T> =
T[K] extends NavigationResource<any>
? PineDeferred
: T[K] extends OptionalNavigationResource<any>
? PineDeferred | null
: T[K] extends ConceptTypeNavigationResource<any>
? Exclude<T[K], any[]>
: T[K];
type SelectResultObject<T, Props extends keyof T> = {
[P in Props]: SelectedProperty<T, P>;
};
export type TypedSelectResult<
T,
TParams extends ODataOptions<T>,
> = TParams['$select'] extends keyof T
? SelectResultObject<T, TParams['$select']>
: TParams['$select'] extends Array<keyof T>
? SelectResultObject<T, TParams['$select'][number]>
: TParams['$select'] extends '*'
? SelectResultObject<T, SelectableProps<T>>
: undefined extends TParams['$select']
? SelectResultObject<T, SelectableProps<T>>
: never;
type ExpandedProperty<
T,
K extends keyof T,
KOpts extends ODataOptions<InferAssociatedResourceType<T[K]>>,
> =
KOpts extends ODataOptionsWithCount<any>
? number
: T[K] extends NavigationResource<any> | ConceptTypeNavigationResource<any>
? [TypedResult<InferAssociatedResourceType<T[K]>, KOpts>]
: T[K] extends OptionalNavigationResource<any>
? [TypedResult<InferAssociatedResourceType<T[K]>, KOpts>] | []
: T[K] extends ReverseNavigationResource<any>
? Array<TypedResult<InferAssociatedResourceType<T[K]>, KOpts>>
: never;
export type ExpandResultObject<T, Props extends keyof T> = {
[P in Props]: ExpandedProperty<T, P, object>;
};
type ExpandResourceExpandObject<
T,
TResourceExpand extends ResourceExpand<T>,
> = {
[P in keyof TResourceExpand]: ExpandedProperty<
T,
P extends keyof T ? P : never,
Exclude<TResourceExpand[P], undefined>
>;
};
export type TypedExpandResult<T, TParams extends ODataOptions<T>> =
TParams['$expand'] extends ExpandableProps<T>
? ExpandResultObject<T, TParams['$expand']>
: TParams['$expand'] extends ResourceExpand<T>
? keyof TParams['$expand'] extends ExpandableProps<T>
? ExpandResourceExpandObject<T, TParams['$expand']>
: never
: object;
export type TypedResult<T, TParams extends ODataOptions<T> | undefined> =
TParams extends ODataOptionsWithCount<T>
? number
: TParams extends ODataOptions<T>
? Omit<
TypedSelectResult<T, TParams>,
keyof TypedExpandResult<T, TParams>
> &
TypedExpandResult<T, TParams>
: undefined extends TParams
? TypedSelectResult<T, { $select: '*' }>
: never;
export type PostResult<T> = SelectResultObject<
T,
Exclude<StringKeyof<T>, PropsOfType<T, ReverseNavigationResource<object>>>
>;
export type WebResource = {
filename: string;
href: string;
content_type?: string;
content_disposition?: string;
size?: number;
};
// based on https://github.com/balena-io/pinejs-client-js/blob/master/core.d.ts
type RawFilter =
| string
| Array<string | Filter<any>>
| { $string: string; [index: string]: Filter<any> | string };
interface LambdaExpression<T> {
[alias: string]: Filter<T>;
}
interface Lambda<T> {
$alias: string;
$expr:
| LambdaExpression<T>
// It seems that TS atm mixes things up after adding the following UNION rules
// and allows having secondary filter props inside the $expr:LambdaExpression<T>
// that are not props of the T
// See: https://github.com/balena-io/balena-sdk/issues/714
| { 1: number }
| { $and?: Array<LambdaExpression<T>> }
| { $or?: Array<LambdaExpression<T>> }
| { $not?: LambdaExpression<T> };
}
type OrderByDirection = 'asc' | 'desc';
type OrderBy<T> =
| `${string} ${OrderByDirection}` // TODO next major: Change to: `${keyof T & string} ${OrderByDirection}` | [keyof T & string, OrderByDirection]
| Array<OrderBy<T>>
| { [k in keyof T]?: OrderByDirection }
| ({
[k in ExpandableProps<T>]?: {
$count: ODataCountOptions<InferAssociatedResourceType<T[k]>>;
};
} & {
$dir: OrderByDirection;
});
type AssociatedResourceFilter<T> =
T extends NonNullable<ReverseNavigationResource<object>>
? FilterObj<InferAssociatedResourceType<T>>
: FilterObj<InferAssociatedResourceType<T>> | number | null;
type ResourceObjFilterPropValue<T, k extends keyof T> =
T[k] extends AssociatedResource<object>
? AssociatedResourceFilter<T[k]>
: T[k] | FilterExpressions<T[k]> | null;
type ResourceObjFilter<T> = {
[k in keyof T]?: ResourceObjFilterPropValue<T, k>;
};
type Filter<T> = FilterObj<T>;
type FilterObj<T> = ResourceObjFilter<T> | FilterExpressions<T>;
type FilterBaseType = string | number | null | boolean | Date;
type NestedFilter<T> = FilterObj<T> | FilterArray<T> | FilterBaseType;
type FilterArray<T> = Array<NestedFilter<T>>;
type FilterOperationValue<T> =
| NestedFilter<T>
| FilterFunctionExpressions<NestedFilter<T>>;
type FilterFunctionValue<T> = NestedFilter<T>;
type FilterFunctionExpressions<T> = Pick<
FilterExpressions<T>,
FilterFunctionKey
>;
type FilterOperationKey =
| '$ne'
| '$eq'
| '$gt'
| '$ge'
| '$lt'
| '$le'
| '$add'
| '$sub'
| '$mul'
| '$div'
| '$mod';
type FilterFunctionKey =
| '$contains'
| '$endswith'
| '$startswith'
| '$length'
| '$indexof'
| '$substring'
| '$tolower'
| '$toupper'
| '$trim'
| '$concat'
| '$year'
| '$month'
| '$day'
| '$hour'
| '$minute'
| '$second'
| '$fractionalseconds'
| '$date'
| '$time'
| '$totaloffsetminutes'
| '$now'
| '$maxdatetime'
| '$mindatetime'
| '$totalseconds'
| '$round'
| '$floor'
| '$ceiling'
| '$isof'
| '$cast';
interface FilterExpressions<T> {
'@'?: string;
$raw?: RawFilter;
$?: string | string[];
$count?: Filter<T>;
$and?: NestedFilter<T>;
$or?: NestedFilter<T>;
$in?: NestedFilter<T>;
$not?: NestedFilter<T>;
$any?: Lambda<T>;
$all?: Lambda<T>;
// Filter operations
$ne?: FilterOperationValue<T>;
$eq?: FilterOperationValue<T>;
$gt?: FilterOperationValue<T>;
$ge?: FilterOperationValue<T>;
$lt?: FilterOperationValue<T>;
$le?: FilterOperationValue<T>;
$add?: FilterOperationValue<T>;
$sub?: FilterOperationValue<T>;
$mul?: FilterOperationValue<T>;
$div?: FilterOperationValue<T>;
$mod?: FilterOperationValue<T>;
// Filter functions
$contains?: FilterFunctionValue<T>;
$endswith?: FilterFunctionValue<T>;
$startswith?: FilterFunctionValue<T>;
$length?: FilterFunctionValue<T>;
$indexof?: FilterFunctionValue<T>;
$substring?: FilterFunctionValue<T>;
$tolower?: FilterFunctionValue<T>;
$toupper?: FilterFunctionValue<T>;
$trim?: FilterFunctionValue<T>;
$concat?: FilterFunctionValue<T>;
$year?: FilterFunctionValue<T>;
$month?: FilterFunctionValue<T>;
$day?: FilterFunctionValue<T>;
$hour?: FilterFunctionValue<T>;
$minute?: FilterFunctionValue<T>;
$second?: FilterFunctionValue<T>;
$fractionalseconds?: FilterFunctionValue<T>;
$date?: FilterFunctionValue<T>;
$time?: FilterFunctionValue<T>;
$totaloffsetminutes?: FilterFunctionValue<T>;
$now?: FilterFunctionValue<T>;
$maxdatetime?: FilterFunctionValue<T>;
$mindatetime?: FilterFunctionValue<T>;
$totalseconds?: FilterFunctionValue<T>;
$round?: FilterFunctionValue<T>;
$floor?: FilterFunctionValue<T>;
$ceiling?: FilterFunctionValue<T>;
$isof?: FilterFunctionValue<T>;
$cast?: FilterFunctionValue<T>;
}
export type ResourceExpand<T> = {
[k in ExpandableProps<T>]?: ODataOptions<InferAssociatedResourceType<T[k]>>;
};
type ResourceExpandWithSelect<T> = {
[k in ExpandableProps<T>]?: ODataOptionsStrict<
InferAssociatedResourceType<T[k]>
>;
};
type BaseExpand<T> = ResourceExpand<T> | ExpandableProps<T>;
export type Expand<T> = BaseExpand<T> | Array<BaseExpand<T>>;
type ExpandWithSelect<T> =
| ResourceExpandWithSelect<T>
| Array<ResourceExpandWithSelect<T>>;
export type ODataMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
export interface ODataOptionsWithoutCount<T> {
$select?: Array<SelectableProps<T>> | SelectableProps<T> | '*';
$filter?: Filter<T>;
$expand?: Expand<T>;
$orderby?: OrderBy<T>;
$top?: number;
$skip?: number;
}
export type ODataCountOptions<T> = Pick<ODataOptionsWithoutCount<T>, '$filter'>;
export interface ODataOptions<T> extends ODataOptionsWithoutCount<T> {
$count?: ODataCountOptions<T>;
}
export interface ODataOptionsWithCount<T> extends ODataOptionsWithoutCount<T> {
$count: NonNullable<ODataCountOptions<T>>;
}
export type ODataOptionsStrict<T> = Omit<
ODataOptions<T>,
'$select' | '$expand' | '$count'
> &
(
| {
$select: ODataOptions<T>['$select'];
$expand?: ExpandWithSelect<T>;
}
| {
$count: ODataOptionsWithoutCount<T>;
}
);
export type ODataOptionsWithFilter<T> = ODataOptions<T> &
Required<Pick<ODataOptions<T>, '$filter'>>;
export type ReplaceWebResource<K> = K extends WebResource ? WebResourceFile : K;
export type SubmitBody<T> = {
[k in keyof T]?: T[k] extends AssociatedResource<object>
? number | null
: ReplaceWebResource<T[k]>;
};
type BaseResourceId =
| string
| number
| Date
| {
'@': string;
};
type ResourceAlternateKey<T> = SubmitBody<T>;
type ResourceId<T> = BaseResourceId | ResourceAlternateKey<T>;
export interface ParamsObj<T> {
resource?: string;
body?: SubmitBody<T>;
id?: ResourceId<T>;
options?: ODataOptions<T>;
apiPrefix?: string;
method?: ODataMethod;
url?: string;
passthrough?: AnyObject;
passthroughByMethod?: { [method in ODataMethod]: AnyObject };
customOptions?: AnyObject;
}
export interface ParamsObjWithId<T> extends ParamsObj<T> {
id: ResourceId<T>;
}
export interface ParamsObjWithCount<T> extends ParamsObj<T> {
options: { $count: NonNullable<ODataOptions<T>['$count']> };
}
export type ParamsObjStrict<T> = Omit<ParamsObj<T>, 'options'> & {
options: ODataOptionsStrict<T>;
};
export interface ParamsObjWithFilter<T> extends ParamsObj<T> {
options: ODataOptionsWithFilter<T>;
}
export interface GetOrCreateParams<T> extends Omit<ParamsObj<T>, 'method'> {
id: ResourceAlternateKey<T>;
resource: string;
body: SubmitBody<T>;
}
export interface UpsertParams<T>
extends Omit<ParamsObj<T>, 'id' | 'method' | 'options'> {
id: ResourceAlternateKey<T>;
resource: string;
body: SubmitBody<T>;
}
export declare type Primitive = null | string | number | boolean | Date;
export declare type ParameterAlias = Primitive;
export declare type PreparedFn<T extends Dictionary<ParameterAlias>, U, R> = (
parameterAliases?: T,
body?: ParamsObj<R>['body'],
passthrough?: ParamsObj<R>['passthrough'],
) => U;
interface PollOnObj {
unsubscribe: () => void;
}
declare class Poll<T> {
private intervalTime;
private subscribers;
private stopped;
private pollInterval?;
private requestFn;
constructor(requestFn: () => Promise<T>, intervalTime?: number);
setPollInterval(intervalTime: number): void;
runRequest(): Promise<void>;
on(name: 'data', fn: (response: Promise<T>) => void): PollOnObj;
on(name: 'error', fn: (err: any) => void): PollOnObj;
start(): void;
stop(): void;
destroy(): void;
private restartTimeout;
}
export interface SubscribeParams<T> extends ParamsObj<T> {
method?: 'GET';
pollInterval?: number;
}
export interface SubscribeParamsWithCount<T> extends ParamsObjWithCount<T> {
method?: 'GET';
pollInterval?: number;
}
export interface SubscribeParamsWithId<T> extends ParamsObjWithId<T> {
method?: 'GET';
pollInterval?: number;
}
export interface Pine<ResourceTypeMap extends object = object> {
apiPrefix: string;
delete<T>(params: ParamsObjWithId<T> | ParamsObjWithFilter<T>): Promise<'OK'>;
// Fully typed result overloads
get<
R extends keyof ResourceTypeMap,
P extends { resource: R } & ParamsObjWithCount<
ResourceTypeMap[P['resource']]
>,
>(
params: ExactlyExtends<
P,
ParamsObjWithCount<ResourceTypeMap[P['resource']]>
>,
): Promise<number>;
get<
R extends keyof ResourceTypeMap,
P extends { resource: R } & ParamsObjWithId<ResourceTypeMap[P['resource']]>,
>(
params: ExactlyExtends<P, ParamsObjWithId<ResourceTypeMap[P['resource']]>>,
): Promise<
TypedResult<ResourceTypeMap[P['resource']], P['options']> | undefined
>;
get<
R extends keyof ResourceTypeMap,
P extends { resource: R } & ParamsObj<ResourceTypeMap[P['resource']]>,
>(
params: ExactlyExtends<P, ParamsObj<ResourceTypeMap[P['resource']]>>,
): Promise<Array<TypedResult<ResourceTypeMap[P['resource']], P['options']>>>;
// User provided resource type overloads
get<T extends object>(params: ParamsObjWithCount<T>): Promise<number>;
get<T extends object>(params: ParamsObjWithId<T>): Promise<T | undefined>;
get<T extends object>(params: ParamsObj<T>): Promise<T[]>;
get<T extends object, Result>(params: ParamsObj<T>): Promise<Result>;
post<
R extends keyof ResourceTypeMap,
P extends { resource: R } & ParamsObj<ResourceTypeMap[P['resource']]>,
>(
params: ExactlyExtends<P, ParamsObj<ResourceTypeMap[P['resource']]>> & {
body: object;
},
): Promise<PostResult<ResourceTypeMap[P['resource']]>>;
post<T>(
params: ParamsObj<T> & { body: object },
): Promise<PostResult<T & { id: number }>>;
patch<T>(params: ParamsObjWithId<T> | ParamsObjWithFilter<T>): Promise<'OK'>;
upsert<T>(params: UpsertParams<T>): Promise<T | 'OK'>;
getOrCreate<T>(params: GetOrCreateParams<T>): Promise<T>;
prepare<T extends Dictionary<ParameterAlias>, R>(
params: ParamsObjWithCount<R> & {
method?: 'GET';
},
): PreparedFn<T, Promise<number>, R>;
prepare<T extends Dictionary<ParameterAlias>, R>(
params: ParamsObjWithId<R> & {
method?: 'GET';
},
): PreparedFn<T, Promise<R | undefined>, R>;
prepare<T extends Dictionary<ParameterAlias>, R>(
params: ParamsObj<R> & {
method?: 'GET';
},
): PreparedFn<T, Promise<R[]>, R>;
prepare<T extends Dictionary<ParameterAlias>, R>(
params: ParamsObj<R> & {
method: 'POST';
},
): PreparedFn<T, Promise<R & { id: number }>, R>;
prepare<T extends Dictionary<ParameterAlias>, R>(
params: ParamsObj<R> & {
method: 'PATCH' | 'DELETE';
},
): PreparedFn<T, Promise<'OK'>, R>;
subscribe<T>(
params: SubscribeParamsWithCount<T> & {
method?: 'GET';
},
): Poll<number>;
subscribe<T>(
params: SubscribeParamsWithId<T> & {
method?: 'GET';
},
): Poll<T | undefined>;
subscribe<T>(
params: SubscribeParams<T> & {
method?: 'GET';
},
): Poll<T[]>;
subscribe<T>(
params: SubscribeParams<T> & {
method: 'POST';
},
): Poll<T & { id: number }>;
subscribe<T>(
params: SubscribeParams<T> & {
method: 'PATCH' | 'DELETE';
},
): Poll<'OK'>;
}
/**
* A variant that makes $select mandatory, helping to create
* requests that explicitly fetch only what your code needs.
*/
export type PineStrict<ResourceTypeMap extends object = object> = Omit<
Pine,
'get' | 'prepare' | 'subscribe'
> & {
// Fully typed result overloads
get<
R extends keyof ResourceTypeMap,
P extends { resource: R } & ParamsObjWithCount<
ResourceTypeMap[P['resource']]
>,
>(
params: ExactlyExtends<
P,
ParamsObjWithCount<ResourceTypeMap[P['resource']]>
>,
): Promise<number>;
get<
R extends keyof ResourceTypeMap,
P extends { resource: R } & ParamsObjWithId<
ResourceTypeMap[P['resource']]
> &
ParamsObjStrict<ResourceTypeMap[P['resource']]>,
>(
params: ExactlyExtends<
P,
ParamsObjWithId<ResourceTypeMap[P['resource']]> &
ParamsObjStrict<ResourceTypeMap[P['resource']]>
>,
): Promise<
TypedResult<ResourceTypeMap[P['resource']], P['options']> | undefined
>;
get<
R extends keyof ResourceTypeMap,
P extends { resource: R } & ParamsObjStrict<ResourceTypeMap[P['resource']]>,
>(
params: ExactlyExtends<P, ParamsObjStrict<ResourceTypeMap[P['resource']]>>,
): Promise<Array<TypedResult<ResourceTypeMap[P['resource']], P['options']>>>;
// User provided resource type overloads
get<T extends object>(
params: ParamsObjWithCount<NoInfer<T>>,
): Promise<number>;
get<T extends object>(
params: ParamsObjWithId<NoInfer<T>> & ParamsObjStrict<NoInfer<T>>,
): Promise<T | undefined>;
get<T extends object>(params: ParamsObjStrict<NoInfer<T>>): Promise<T[]>;
get<T extends object, Result extends number>(
params: ParamsObj<NoInfer<T>>,
): Promise<Result>;
get<T extends object, Result>(
params: ParamsObjStrict<NoInfer<T>>,
): Promise<Result>;
prepare<T extends Dictionary<ParameterAlias>, R>(
params: ParamsObjWithCount<R> & {
method?: 'GET';
},
): PreparedFn<T, Promise<number>, R>;
prepare<T extends Dictionary<ParameterAlias>, R>(
params: ParamsObjWithId<R> &
ParamsObjStrict<R> & {
method?: 'GET';
},
): PreparedFn<T, Promise<R | undefined>, R>;
prepare<T extends Dictionary<ParameterAlias>, R>(
params: ParamsObj<R> &
ParamsObjStrict<R> & {
method?: 'GET';
},
): PreparedFn<T, Promise<R[]>, R>;
prepare<T extends Dictionary<ParameterAlias>, R>(
params: ParamsObj<R> & {
method: 'POST';
},
): PreparedFn<T, Promise<R & { id: number }>, R>;
prepare<T extends Dictionary<ParameterAlias>, R>(
params: ParamsObj<R> & {
method: 'PATCH' | 'DELETE';
},
): PreparedFn<T, Promise<'OK'>, R>;
subscribe<T>(
params: SubscribeParamsWithCount<T> & {
method?: 'GET';
},
): Poll<number>;
subscribe<T>(
params: SubscribeParamsWithId<T> &
ParamsObjStrict<T> & {
method?: 'GET';
},
): Poll<T | undefined>;
subscribe<T>(
params: SubscribeParams<T> &
ParamsObjStrict<T> & {
method?: 'GET';
},
): Poll<T[]>;
subscribe<T>(
params: SubscribeParams<T> & {
method: 'POST';
},
): Poll<T & { id: number }>;
subscribe<T>(
params: SubscribeParams<T> & {
method: 'PATCH' | 'DELETE';
},
): Poll<'OK'>;
};