@data-client/rest 0.18.1 → 0.18.2
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/CHANGELOG.md +191 -0
- package/dist/index.js +15 -6
- package/dist/index.umd.min.js +1 -1
- package/legacy/RestEndpoint.js +5 -4
- package/legacy/RestEndpointTypes.js +1 -1
- package/legacy/extractCollection.js +3 -1
- package/legacy/paramsToString.js +1 -1
- package/legacy/paramsToString.native.js +1 -1
- package/legacy/pathTypes.js +1 -1
- package/legacy/resource.js +10 -4
- package/legacy/resourceExtendable.js +1 -1
- package/legacy/resourceExtensionTypes.js +1 -1
- package/legacy/resourceTypes.js +1 -1
- package/lib/NetworkError.d.ts.map +1 -1
- package/lib/RestEndpoint.js +5 -4
- package/lib/RestEndpointTypes.d.ts +49 -20
- package/lib/RestEndpointTypes.d.ts.map +1 -1
- package/lib/RestEndpointTypes.js +1 -1
- package/lib/extractCollection.d.ts +8 -1
- package/lib/extractCollection.d.ts.map +1 -1
- package/lib/extractCollection.js +3 -1
- package/lib/paramsToString.d.ts.map +1 -1
- package/lib/paramsToString.js +1 -1
- package/lib/paramsToString.native.d.ts.map +1 -1
- package/lib/paramsToString.native.js +1 -1
- package/lib/pathTypes.d.ts +33 -7
- package/lib/pathTypes.d.ts.map +1 -1
- package/lib/pathTypes.js +1 -1
- package/lib/resource.d.ts +1 -1
- package/lib/resource.d.ts.map +1 -1
- package/lib/resource.js +10 -4
- package/lib/resourceExtendable.d.ts +4 -4
- package/lib/resourceExtendable.d.ts.map +1 -1
- package/lib/resourceExtendable.js +1 -1
- package/lib/resourceExtensionTypes.d.ts +7 -7
- package/lib/resourceExtensionTypes.d.ts.map +1 -1
- package/lib/resourceExtensionTypes.js +1 -1
- package/lib/resourceTypes.d.ts +8 -2
- package/lib/resourceTypes.d.ts.map +1 -1
- package/lib/resourceTypes.js +1 -1
- package/lib/test-fixtures.d.ts +7 -7
- package/lib/test-fixtures.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/RestEndpoint.js +7 -6
- package/src/RestEndpointTypes.ts +116 -53
- package/src/__tests__/RestEndpoint.ts +23 -7
- package/src/__tests__/resource-construction.test.ts +47 -0
- package/src/extractCollection.ts +3 -0
- package/src/paramsToString.native.ts +1 -5
- package/src/paramsToString.ts +1 -5
- package/src/pathTypes.ts +105 -31
- package/src/resource.ts +11 -6
- package/src/resourceExtendable.ts +15 -11
- package/src/resourceExtensionTypes.ts +16 -10
- package/src/resourceTypes.ts +6 -4
- package/ts4.0/RestEndpointTypes.d.ts +57 -22
- package/ts4.0/extractCollection.d.ts +8 -1
- package/ts4.0/mapCollection.d.ts +11 -16
- package/ts4.0/resource.d.ts +1 -1
- package/ts4.0/resourceExtendable.d.ts +4 -4
- package/ts4.0/resourceExtensionTypes.d.ts +7 -7
- package/ts4.0/resourceTypes.d.ts +8 -2
- package/ts4.0/test-fixtures.d.ts +7 -7
- package/ts4.1/RestEndpointTypes.d.ts +57 -22
- package/ts4.1/extractCollection.d.ts +8 -1
- package/ts4.1/mapCollection.d.ts +11 -16
- package/ts4.1/pathTypes.d.ts +33 -7
- package/ts4.1/resource.d.ts +1 -1
- package/ts4.1/resourceExtendable.d.ts +4 -4
- package/ts4.1/resourceExtensionTypes.d.ts +7 -7
- package/ts4.1/resourceTypes.d.ts +8 -2
- package/ts4.1/test-fixtures.d.ts +7 -7
|
@@ -17,6 +17,21 @@ type ContentSchemaGuard<O> = O extends {
|
|
|
17
17
|
} ? {
|
|
18
18
|
schema?: undefined;
|
|
19
19
|
} : {};
|
|
20
|
+
interface RestInstanceExtenders {
|
|
21
|
+
/** Creates a child endpoint that inherits from this while overriding provided `options`.
|
|
22
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#extend
|
|
23
|
+
*/
|
|
24
|
+
extend<E extends RestInstanceBase, ExtendOptions extends ExtendableRestGenerics | {}>(this: E, options: Readonly<RestEndpointExtendOptions<ExtendOptions, E, E['fetch']> & ExtendOptions> & ExtendOptions & ContentSchemaGuard<ExtendOptions>): RestExtendedEndpoint<ExtendOptions, E>;
|
|
25
|
+
}
|
|
26
|
+
interface RestInstancePaginators {
|
|
27
|
+
/** Creates an Endpoint to append the next page extending a list for pagination
|
|
28
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#paginated
|
|
29
|
+
*/
|
|
30
|
+
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, A extends any[]>(this: E, removeCursor: (...args: A) => readonly [
|
|
31
|
+
...Parameters<E>
|
|
32
|
+
]): PaginationEndpoint<E, A>;
|
|
33
|
+
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, C extends string>(this: E, cursorField: C): PaginationFieldEndpoint<E, C>;
|
|
34
|
+
}
|
|
20
35
|
export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends boolean | undefined = boolean | undefined, O extends {
|
|
21
36
|
path: string;
|
|
22
37
|
body?: any;
|
|
@@ -24,7 +39,7 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
24
39
|
method?: string;
|
|
25
40
|
} = {
|
|
26
41
|
path: string;
|
|
27
|
-
}> extends EndpointInstanceInterface<F, S, M
|
|
42
|
+
}> extends EndpointInstanceInterface<F, S, M>, RestInstanceExtenders {
|
|
28
43
|
/** @see https://dataclient.io/rest/api/RestEndpoint#body */
|
|
29
44
|
readonly body?: 'body' extends keyof O ? O['body'] : any;
|
|
30
45
|
/** @see https://dataclient.io/rest/api/RestEndpoint#searchParams */
|
|
@@ -60,7 +75,7 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
60
75
|
/** Prepares RequestInit used in fetch. This is sent to fetchResponse()
|
|
61
76
|
* @see https://dataclient.io/rest/api/RestEndpoint#getRequestInit
|
|
62
77
|
*/
|
|
63
|
-
getRequestInit(this: any, body?: RequestInit['body'] | Record<string, unknown>): Promise<RequestInit> | RequestInit;
|
|
78
|
+
getRequestInit(this: any, body?: RequestInit['body'] | Record<string, unknown> | readonly unknown[]): Promise<RequestInit> | RequestInit;
|
|
64
79
|
/** Called by getRequestInit to determine HTTP Headers
|
|
65
80
|
* @see https://dataclient.io/rest/api/RestEndpoint#getHeaders
|
|
66
81
|
*/
|
|
@@ -81,10 +96,6 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
81
96
|
* @see https://dataclient.io/rest/api/RestEndpoint#testKey
|
|
82
97
|
*/
|
|
83
98
|
testKey(key: string): boolean;
|
|
84
|
-
/** Creates a child endpoint that inherits from this while overriding provided `options`.
|
|
85
|
-
* @see https://dataclient.io/rest/api/RestEndpoint#extend
|
|
86
|
-
*/
|
|
87
|
-
extend<E extends RestInstanceBase, ExtendOptions extends PartialRestGenerics | {}>(this: E, options: Readonly<RestEndpointExtendOptions<ExtendOptions, E, F> & ExtendOptions> & ContentSchemaGuard<ExtendOptions>): RestExtendedEndpoint<ExtendOptions, E>;
|
|
88
99
|
}
|
|
89
100
|
export interface RestInstance<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends boolean | undefined = boolean | undefined, O extends {
|
|
90
101
|
path: string;
|
|
@@ -94,21 +105,18 @@ export interface RestInstance<F extends FetchFunction = FetchFunction, S extends
|
|
|
94
105
|
paginationField?: string;
|
|
95
106
|
} = {
|
|
96
107
|
path: string;
|
|
97
|
-
}> extends RestInstanceBase<F, S, M, O
|
|
98
|
-
/** Creates an Endpoint to append the next page extending a list for pagination
|
|
99
|
-
* @see https://dataclient.io/rest/api/RestEndpoint#paginated
|
|
100
|
-
*/
|
|
101
|
-
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, A extends any[]>(this: E, removeCursor: (...args: A) => readonly [
|
|
102
|
-
...Parameters<E>
|
|
103
|
-
]): PaginationEndpoint<E, A>;
|
|
104
|
-
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, C extends string>(this: E, cursorField: C): PaginationFieldEndpoint<E, C>;
|
|
108
|
+
}> extends RestInstanceBase<F, S, M, O>, RestInstancePaginators {
|
|
105
109
|
/** Concatinate the next page of results (GET)
|
|
106
110
|
* @see https://dataclient.io/rest/api/RestEndpoint#getPage
|
|
107
111
|
*/
|
|
108
|
-
getPage: 'paginationField' extends keyof O ? O['paginationField'] extends string ? PaginationFieldEndpoint<
|
|
112
|
+
getPage: 'paginationField' extends keyof O ? O['paginationField'] extends string ? PaginationFieldEndpoint<([
|
|
113
|
+
keyof F
|
|
114
|
+
] extends [
|
|
115
|
+
never
|
|
116
|
+
] ? (...args: any) => ReturnType<F> : F) & {
|
|
109
117
|
schema: S;
|
|
110
118
|
sideEffect: M;
|
|
111
|
-
} & O, O['paginationField']
|
|
119
|
+
} & O, Extract<O['paginationField'], string>> : undefined : undefined;
|
|
112
120
|
/** Create a new item (POST) and `push` to the end
|
|
113
121
|
* @see https://dataclient.io/rest/api/RestEndpoint#push
|
|
114
122
|
*/
|
|
@@ -146,7 +154,22 @@ export type RestEndpointExtendOptions<O extends PartialRestGenerics, E extends {
|
|
|
146
154
|
path?: string;
|
|
147
155
|
schema?: Schema;
|
|
148
156
|
method?: string;
|
|
149
|
-
}, F extends FetchFunction> = RestEndpointOptions<OptionsToFunction<O, E, F>, 'schema' extends keyof O ? Extract<O['schema'], Schema | undefined> : E['schema']> &
|
|
157
|
+
}, F extends FetchFunction> = RestEndpointOptions<OptionsToFunction<O, E, F>, 'schema' extends keyof O ? Extract<O['schema'], Schema | undefined> : E['schema']> & PartialPick<E, keyof E extends ExtendOmitKeys ? never : Exclude<keyof E, ExtendOmitKeys>>;
|
|
158
|
+
/** Argument I passed to process(), from Parameters<F>.
|
|
159
|
+
* Indexing a union like `[params] | []` or `[params, body] | [body]` (see ParamFetchNoBody/ParamFetchWithBody)
|
|
160
|
+
* merges position-wise, giving `undefined` where some call omits the argument.
|
|
161
|
+
* Endpoints that take no args keep `any`, so process(value, params: any) and similar still compile.
|
|
162
|
+
*/
|
|
163
|
+
type ProcessArg<A extends readonly any[], I extends 0 | 1> = [
|
|
164
|
+
A['length']
|
|
165
|
+
] extends [
|
|
166
|
+
0
|
|
167
|
+
] ? any : A[I];
|
|
168
|
+
type ExtendOmitKeys = KeyofRestEndpoint | keyof PartialRestGenerics | keyof RestEndpointOptions;
|
|
169
|
+
/** Partial<Pick<T, K>> as a single homomorphic mapped type */
|
|
170
|
+
type PartialPick<T, K extends keyof T> = {
|
|
171
|
+
[P in K]?: T[P];
|
|
172
|
+
};
|
|
150
173
|
type OptionsToRestEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase & {
|
|
151
174
|
body?: any;
|
|
152
175
|
paginationField?: string;
|
|
@@ -195,8 +218,12 @@ export type RestExtendedEndpoint<O extends PartialRestGenerics, E extends RestIn
|
|
|
195
218
|
};
|
|
196
219
|
} ? {
|
|
197
220
|
paginationField: E['getPage']['paginationField'];
|
|
198
|
-
} : unknown), RestInstance<(...args: Parameters<E>) => O['process'] extends {} ? Promise<ReturnType<O['process']>> : 'content' extends keyof O ? Promise<ContentReturnType<O['content'] & ContentType>> : ReturnType<E>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], boolean | undefined> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']>> & Omit<O, KeyofRestEndpoint> & Omit<E, KeyofRestEndpoint | keyof O
|
|
199
|
-
|
|
221
|
+
} : unknown), RestInstance<(...args: Parameters<E>) => O['process'] extends {} ? Promise<ReturnType<O['process']>> : 'content' extends keyof O ? Promise<ContentReturnType<O['content'] & ContentType>> : ReturnType<E>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], boolean | undefined> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']>> & (keyof O extends KeyofRestEndpoint ? unknown : Omit<O, KeyofRestEndpoint>) & (keyof E extends KeyofRestEndpoint ? unknown : Omit<E, KeyofRestEndpoint | keyof O>);
|
|
222
|
+
/** PartialRestGenerics without `process`. Options passed to the constructor, extend() and
|
|
223
|
+
* resource().extend() are constrained by this, so RestEndpointOptions' typed `process` member is
|
|
224
|
+
* the only contextual type for process() params.
|
|
225
|
+
*/
|
|
226
|
+
export interface ExtendableRestGenerics {
|
|
200
227
|
/** @see https://dataclient.io/rest/api/RestEndpoint#path */
|
|
201
228
|
readonly path?: string;
|
|
202
229
|
/** @see https://dataclient.io/rest/api/RestEndpoint#schema */
|
|
@@ -211,11 +238,13 @@ export interface PartialRestGenerics {
|
|
|
211
238
|
searchParams?: any;
|
|
212
239
|
/** @see https://dataclient.io/rest/api/RestEndpoint#paginationfield */
|
|
213
240
|
readonly paginationField?: string;
|
|
214
|
-
/** @see https://dataclient.io/rest/api/RestEndpoint#process */
|
|
215
|
-
process?(value: any, ...args: any): any;
|
|
216
241
|
/** @see https://dataclient.io/rest/api/RestEndpoint#content */
|
|
217
242
|
readonly content?: ContentType;
|
|
218
243
|
}
|
|
244
|
+
export interface PartialRestGenerics extends ExtendableRestGenerics {
|
|
245
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#process */
|
|
246
|
+
process?(value: any, ...args: any): any;
|
|
247
|
+
}
|
|
219
248
|
/** Generic types when constructing a RestEndpoint
|
|
220
249
|
*
|
|
221
250
|
* @see https://dataclient.io/rest/api/RestEndpoint#inheritance
|
|
@@ -223,6 +252,10 @@ export interface PartialRestGenerics {
|
|
|
223
252
|
export interface RestGenerics extends PartialRestGenerics {
|
|
224
253
|
readonly path: string;
|
|
225
254
|
}
|
|
255
|
+
/** RestGenerics without `process`; see ExtendableRestGenerics */
|
|
256
|
+
interface ConstructorRestGenerics extends ExtendableRestGenerics {
|
|
257
|
+
readonly path: string;
|
|
258
|
+
}
|
|
226
259
|
export type PaginationEndpoint<E extends FetchFunction & RestGenerics & {
|
|
227
260
|
sideEffect?: boolean | undefined;
|
|
228
261
|
}, A extends any[]> = RestInstanceBase<ParamFetchNoBody<A[0], ResolveType<E>>, E['schema'], E['sideEffect'], Pick<E, 'path' | 'searchParams' | 'body'> & {
|
|
@@ -340,6 +373,8 @@ export interface RestEndpointOptions<F extends FetchFunction = FetchFunction, S
|
|
|
340
373
|
fetch?: F;
|
|
341
374
|
key?(...args: Parameters<F>): string;
|
|
342
375
|
url?(...args: Parameters<F>): string;
|
|
376
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#process */
|
|
377
|
+
process?(value: any, params: ProcessArg<Parameters<F>, 0>, body: ProcessArg<Parameters<F>, 1>, ...rest: any[]): any;
|
|
343
378
|
update?: EndpointUpdateFunction<F, S>;
|
|
344
379
|
}
|
|
345
380
|
export type RestEndpointConstructorOptions<O extends RestGenerics = any> = RestEndpointOptions<RestFetch<unknown extends O ? any : 'searchParams' extends keyof O ? [
|
|
@@ -364,7 +399,7 @@ export interface RestEndpointConstructor {
|
|
|
364
399
|
*
|
|
365
400
|
* @see https://dataclient.io/rest/api/RestEndpoint
|
|
366
401
|
*/
|
|
367
|
-
new <O extends
|
|
402
|
+
new <O extends ConstructorRestGenerics = any>({ method, sideEffect, name, ...options }: RestEndpointConstructorOptions<O> & Readonly<O> & O & ContentSchemaGuard<O>): RestEndpoint<O>;
|
|
368
403
|
readonly prototype: RestInstanceBase;
|
|
369
404
|
}
|
|
370
405
|
export type MethodToSide<M> = M extends string ? M extends 'GET' ? undefined : true : undefined;
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { Schema, schema } from '@data-client/endpoint';
|
|
2
2
|
import { ExtractObject } from './extractObject.js';
|
|
3
3
|
export default function extractCollection<M extends <C extends schema.Collection>(collection: C) => any, S extends Schema | undefined>(s: S, mapper: M): ExtractCollection<S> | undefined;
|
|
4
|
+
/** Searches wrappers like Query and Lazy through their `schema` (Entity classes have a `prototype`) */
|
|
4
5
|
export type ExtractCollection<S extends Schema | undefined> = S extends ({
|
|
5
6
|
push: any;
|
|
6
7
|
unshift: any;
|
|
7
8
|
assign: any;
|
|
8
9
|
remove: any;
|
|
9
10
|
schema: Schema;
|
|
10
|
-
}) ? S : S extends schema.Object<infer T> ? ExtractObject<T> : S extends
|
|
11
|
+
}) ? S : S extends schema.Object<infer T> ? ExtractObject<T> : S extends {
|
|
12
|
+
schema: infer Q;
|
|
13
|
+
denormalize: any;
|
|
14
|
+
prototype?: undefined;
|
|
15
|
+
} ? ExtractObject<{
|
|
16
|
+
schema: Q;
|
|
17
|
+
}> : S extends Exclude<Schema, {
|
|
11
18
|
[K: string]: any;
|
|
12
19
|
}> ? never : S extends {
|
|
13
20
|
[K: string]: Schema;
|
package/ts4.0/mapCollection.d.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { Schema, schema } from '@data-client/endpoint';
|
|
2
|
-
export default function mapCollection<M extends <C extends schema.Collection>(collection: C) => any, S extends Schema | undefined>(s: S, mapper: M): S extends schema.Collection
|
|
3
|
-
[K
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
export type MapObject<M extends (collection: schema.Collection) => any, S extends Record<string, any>> = {
|
|
13
|
-
[K in keyof S]: S[K] extends Schema ? MapCollection<M, S[K]> : S[K];
|
|
14
|
-
};
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=mapCollection.d.ts.map
|
|
1
|
+
import { Schema, schema } from '@data-client/endpoint';
|
|
2
|
+
export default function mapCollection<M extends <C extends schema.Collection>(collection: C) => any, S extends Schema | undefined>(s: S, mapper: M): S extends schema.Collection | schema.Object<any> | {
|
|
3
|
+
[K: string]: any;
|
|
4
|
+
} ? MapCollection<M, S> : S;
|
|
5
|
+
type MapCollection<M extends <C extends schema.Collection>(collection: C) => any, S extends Schema | undefined> = S extends schema.Collection ? ReturnType<M> : S extends schema.Object<infer T> ? MapObject<M, T> : S extends {
|
|
6
|
+
[K: string]: any;
|
|
7
|
+
} ? MapObject<M, S> : never;
|
|
8
|
+
export type MapObject<M extends (collection: schema.Collection) => any, S extends Record<string, any>> = {
|
|
9
|
+
[K in keyof S]: S[K] extends Schema ? MapCollection<M, S[K]> : S[K];
|
|
10
|
+
};
|
|
11
|
+
export {};
|
package/ts4.0/resource.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import { ResourceGenerics, ResourceOptions, Resource } from './resourceTypes.js'
|
|
|
3
3
|
*
|
|
4
4
|
* @see https://dataclient.io/rest/api/resource
|
|
5
5
|
*/
|
|
6
|
-
export default function resource<O extends ResourceGenerics>({ path, schema, Endpoint, Collection, nonFilterArgumentKeys, optimistic, paginationField, ...extraOptions }: Readonly<O> & ResourceOptions): Resource<O>;
|
|
6
|
+
export default function resource<O extends ResourceGenerics>({ path, schema, Endpoint, Collection, nonFilterArgumentKeys, optimistic, paginationField, ...extraOptions }: Readonly<O> & O & ResourceOptions): Resource<O>;
|
|
7
7
|
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -2,20 +2,20 @@ import type { EndpointInterface, EndpointToFunction } from '@data-client/endpoin
|
|
|
2
2
|
import type { ResourcePath } from './pathTypes.js';
|
|
3
3
|
import type { ResourceExtension, ResourceEndpointExtensions, CustomResource, ExtendedResource } from './resourceExtensionTypes.js';
|
|
4
4
|
import type { ResourceGenerics, ResourceInterface } from './resourceTypes.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { ExtendableRestGenerics, RestEndpointExtendOptions, RestExtendedEndpoint, RestInstanceBase } from './RestEndpoint.js';
|
|
6
6
|
export interface Extendable<O extends ResourceGenerics = {
|
|
7
7
|
path: ResourcePath;
|
|
8
8
|
schema: any;
|
|
9
9
|
}> {
|
|
10
10
|
extend<R extends {
|
|
11
11
|
[K in ExtendKey]: RestInstanceBase;
|
|
12
|
-
}, ExtendKey extends Exclude<Extract<keyof R, string>, 'extend'>, ExtendOptions extends
|
|
12
|
+
}, ExtendKey extends Exclude<Extract<keyof R, string>, 'extend'>, ExtendOptions extends ExtendableRestGenerics | {}>(this: R, key: ExtendKey, options: Readonly<RestEndpointExtendOptions<ExtendOptions, R[ExtendKey], EndpointToFunction<R[ExtendKey]>> & ExtendOptions> & ExtendOptions): ResourceExtension<R, ExtendKey, ExtendOptions>;
|
|
13
13
|
extend<R extends {
|
|
14
14
|
get: RestInstanceBase;
|
|
15
|
-
}, ExtendKey extends string, ExtendOptions extends
|
|
15
|
+
}, ExtendKey extends string, ExtendOptions extends ExtendableRestGenerics | {}>(this: R, key: ExtendKey, options: Readonly<RestEndpointExtendOptions<ExtendOptions, R['get'], EndpointToFunction<R['get']>> & ExtendOptions> & ExtendOptions): R & {
|
|
16
16
|
[key in ExtendKey]: RestExtendedEndpoint<ExtendOptions, R['get']>;
|
|
17
17
|
};
|
|
18
|
-
extend<R extends ResourceInterface, Get extends
|
|
18
|
+
extend<R extends ResourceInterface, Get extends ExtendableRestGenerics = {}, GetList extends ExtendableRestGenerics = {}, Update extends ExtendableRestGenerics = {}, PartialUpdate extends ExtendableRestGenerics = {}, Delete extends ExtendableRestGenerics = {}>(this: R, options: ResourceEndpointExtensions<R, Get, GetList, Update, PartialUpdate, Delete>): CustomResource<R, O, Get, GetList, Update, PartialUpdate, Delete> & Omit<R, keyof ResourceInterface | 'extend'>;
|
|
19
19
|
extend<R extends ResourceInterface, T extends Record<string, EndpointInterface>>(this: R, extender: (baseResource: R) => T): ExtendedResource<R, T>;
|
|
20
20
|
}
|
|
21
21
|
//# sourceMappingURL=resourceExtendable.d.ts.map
|
|
@@ -3,7 +3,7 @@ import { OptionsToFunction } from './OptionsToFunction.js';
|
|
|
3
3
|
import type { ResourcePath } from './pathTypes.js';
|
|
4
4
|
import { Extendable } from './resourceExtendable.js';
|
|
5
5
|
import { ResourceGenerics, ResourceInterface } from './resourceTypes.js';
|
|
6
|
-
import type { PartialRestGenerics, RestExtendedEndpoint, RestInstanceBase, RestEndpointOptions } from './RestEndpoint.js';
|
|
6
|
+
import type { ExtendableRestGenerics, PartialRestGenerics, RestExtendedEndpoint, RestInstanceBase, RestEndpointOptions } from './RestEndpoint.js';
|
|
7
7
|
export type ResourceExtension<R extends {
|
|
8
8
|
[K in ExtendKey]: RestInstanceBase;
|
|
9
9
|
}, ExtendKey extends Exclude<Extract<keyof R, string>, 'extend'>, O extends PartialRestGenerics | {}> = {
|
|
@@ -23,11 +23,11 @@ export interface CustomResource<R extends ResourceInterface, O extends ResourceG
|
|
|
23
23
|
delete: unknown extends Delete ? R['delete'] : PartialRestGenerics extends Delete ? R['delete'] : RestExtendedEndpoint<Delete, R['delete']>;
|
|
24
24
|
}
|
|
25
25
|
export type ExtendedResource<R extends ResourceInterface, T extends Record<string, EndpointInterface>> = Omit<R, keyof T> & T;
|
|
26
|
-
export interface ResourceEndpointExtensions<R extends ResourceInterface, Get extends
|
|
27
|
-
readonly get?: RestEndpointOptions<unknown extends Get ? EndpointToFunction<R['get']> : OptionsToFunction<Get, R['get'], EndpointToFunction<R['get']>>, R['get']['schema']> & Readonly<Get
|
|
28
|
-
readonly getList?: RestEndpointOptions<unknown extends GetList ? EndpointToFunction<R['getList']> : OptionsToFunction<GetList, R['getList'], EndpointToFunction<R['getList']>>, R['getList']['schema']> & Readonly<GetList
|
|
29
|
-
readonly update?: RestEndpointOptions<unknown extends Update ? EndpointToFunction<R['update']> : OptionsToFunction<Update, R['update'], EndpointToFunction<R['update']>>, R['update']['schema']> & Readonly<Update
|
|
30
|
-
readonly partialUpdate?: RestEndpointOptions<unknown extends PartialUpdate ? EndpointToFunction<R['partialUpdate']> : OptionsToFunction<PartialUpdate, R['partialUpdate'], EndpointToFunction<R['partialUpdate']>>, R['partialUpdate']['schema']> & Readonly<PartialUpdate
|
|
31
|
-
readonly delete?: RestEndpointOptions<unknown extends Delete ? EndpointToFunction<R['delete']> : OptionsToFunction<Delete, R['delete'], EndpointToFunction<R['delete']>>, R['delete']['schema']> & Readonly<Delete
|
|
26
|
+
export interface ResourceEndpointExtensions<R extends ResourceInterface, Get extends ExtendableRestGenerics = {}, GetList extends ExtendableRestGenerics = {}, Update extends ExtendableRestGenerics = {}, PartialUpdate extends ExtendableRestGenerics = {}, Delete extends ExtendableRestGenerics = {}> {
|
|
27
|
+
readonly get?: RestEndpointOptions<unknown extends Get ? EndpointToFunction<R['get']> : OptionsToFunction<Get, R['get'], EndpointToFunction<R['get']>>, R['get']['schema']> & Readonly<Get> & Get;
|
|
28
|
+
readonly getList?: RestEndpointOptions<unknown extends GetList ? EndpointToFunction<R['getList']> : OptionsToFunction<GetList, R['getList'], EndpointToFunction<R['getList']>>, R['getList']['schema']> & Readonly<GetList> & GetList;
|
|
29
|
+
readonly update?: RestEndpointOptions<unknown extends Update ? EndpointToFunction<R['update']> : OptionsToFunction<Update, R['update'], EndpointToFunction<R['update']>>, R['update']['schema']> & Readonly<Update> & Update;
|
|
30
|
+
readonly partialUpdate?: RestEndpointOptions<unknown extends PartialUpdate ? EndpointToFunction<R['partialUpdate']> : OptionsToFunction<PartialUpdate, R['partialUpdate'], EndpointToFunction<R['partialUpdate']>>, R['partialUpdate']['schema']> & Readonly<PartialUpdate> & PartialUpdate;
|
|
31
|
+
readonly delete?: RestEndpointOptions<unknown extends Delete ? EndpointToFunction<R['delete']> : OptionsToFunction<Delete, R['delete'], EndpointToFunction<R['delete']>>, R['delete']['schema']> & Readonly<Delete> & Delete;
|
|
32
32
|
}
|
|
33
33
|
//# sourceMappingURL=resourceExtensionTypes.d.ts.map
|
package/ts4.0/resourceTypes.d.ts
CHANGED
|
@@ -99,14 +99,14 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
99
99
|
schema: schema.Collection<[
|
|
100
100
|
O['schema']
|
|
101
101
|
]>['push'];
|
|
102
|
-
body:
|
|
102
|
+
body: CreateBody<O> | CreateBody<O>[] | FormData;
|
|
103
103
|
searchParams: O['searchParams'];
|
|
104
104
|
}> : MutateEndpoint<{
|
|
105
105
|
path: ShortenPath<O['path']>;
|
|
106
106
|
schema: schema.Collection<[
|
|
107
107
|
O['schema']
|
|
108
108
|
]>['push'];
|
|
109
|
-
body:
|
|
109
|
+
body: CreateBody<O> | CreateBody<O>[] | FormData;
|
|
110
110
|
}>;
|
|
111
111
|
/** Update an item (PUT)
|
|
112
112
|
*
|
|
@@ -151,4 +151,10 @@ export interface ResourceInterface {
|
|
|
151
151
|
partialUpdate: RestInstanceBase;
|
|
152
152
|
delete: RestInstanceBase;
|
|
153
153
|
}
|
|
154
|
+
/** Matches getList.push's body, since create is getList.push at runtime */
|
|
155
|
+
type CreateBody<O extends {
|
|
156
|
+
body?: any;
|
|
157
|
+
schema: Schema;
|
|
158
|
+
}> = 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
159
|
+
export {};
|
|
154
160
|
//# sourceMappingURL=resourceTypes.d.ts.map
|
package/ts4.0/test-fixtures.d.ts
CHANGED
|
@@ -19,10 +19,10 @@ export declare const articlesPages: {
|
|
|
19
19
|
content: string;
|
|
20
20
|
tags: string[];
|
|
21
21
|
} | {
|
|
22
|
+
tags?: undefined;
|
|
22
23
|
id: number;
|
|
23
24
|
title: string;
|
|
24
25
|
content: string;
|
|
25
|
-
tags?: undefined;
|
|
26
26
|
})[];
|
|
27
27
|
};
|
|
28
28
|
export declare const users: {
|
|
@@ -42,6 +42,7 @@ export declare const nested: ({
|
|
|
42
42
|
email?: undefined;
|
|
43
43
|
};
|
|
44
44
|
} | {
|
|
45
|
+
tags?: undefined;
|
|
45
46
|
id: number;
|
|
46
47
|
title: string;
|
|
47
48
|
content: string;
|
|
@@ -50,7 +51,6 @@ export declare const nested: ({
|
|
|
50
51
|
username: string;
|
|
51
52
|
email: string;
|
|
52
53
|
};
|
|
53
|
-
tags?: undefined;
|
|
54
54
|
})[];
|
|
55
55
|
export declare const moreNested: ({
|
|
56
56
|
id: number;
|
|
@@ -58,11 +58,12 @@ export declare const moreNested: ({
|
|
|
58
58
|
content: string;
|
|
59
59
|
tags: string[];
|
|
60
60
|
author: {
|
|
61
|
+
email?: undefined;
|
|
61
62
|
id: number;
|
|
62
63
|
username: string;
|
|
63
|
-
email?: undefined;
|
|
64
64
|
};
|
|
65
65
|
} | {
|
|
66
|
+
tags?: undefined;
|
|
66
67
|
id: number;
|
|
67
68
|
title: string;
|
|
68
69
|
content: string;
|
|
@@ -71,7 +72,6 @@ export declare const moreNested: ({
|
|
|
71
72
|
username: string;
|
|
72
73
|
email: string;
|
|
73
74
|
};
|
|
74
|
-
tags?: undefined;
|
|
75
75
|
})[];
|
|
76
76
|
export declare const valuesFixture: {
|
|
77
77
|
first: {
|
|
@@ -101,6 +101,7 @@ export declare const paginatedFirstPage: {
|
|
|
101
101
|
email?: undefined;
|
|
102
102
|
};
|
|
103
103
|
} | {
|
|
104
|
+
tags?: undefined;
|
|
104
105
|
id: number;
|
|
105
106
|
title: string;
|
|
106
107
|
content: string;
|
|
@@ -109,7 +110,6 @@ export declare const paginatedFirstPage: {
|
|
|
109
110
|
username: string;
|
|
110
111
|
email: string;
|
|
111
112
|
};
|
|
112
|
-
tags?: undefined;
|
|
113
113
|
})[];
|
|
114
114
|
};
|
|
115
115
|
};
|
|
@@ -121,11 +121,12 @@ export declare const paginatedSecondPage: {
|
|
|
121
121
|
content: string;
|
|
122
122
|
tags: string[];
|
|
123
123
|
author: {
|
|
124
|
+
email?: undefined;
|
|
124
125
|
id: number;
|
|
125
126
|
username: string;
|
|
126
|
-
email?: undefined;
|
|
127
127
|
};
|
|
128
128
|
} | {
|
|
129
|
+
tags?: undefined;
|
|
129
130
|
id: number;
|
|
130
131
|
title: string;
|
|
131
132
|
content: string;
|
|
@@ -134,7 +135,6 @@ export declare const paginatedSecondPage: {
|
|
|
134
135
|
username: string;
|
|
135
136
|
email: string;
|
|
136
137
|
};
|
|
137
|
-
tags?: undefined;
|
|
138
138
|
})[];
|
|
139
139
|
};
|
|
140
140
|
};
|
|
@@ -17,6 +17,21 @@ type ContentSchemaGuard<O> = O extends {
|
|
|
17
17
|
} ? {
|
|
18
18
|
schema?: undefined;
|
|
19
19
|
} : {};
|
|
20
|
+
interface RestInstanceExtenders {
|
|
21
|
+
/** Creates a child endpoint that inherits from this while overriding provided `options`.
|
|
22
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#extend
|
|
23
|
+
*/
|
|
24
|
+
extend<E extends RestInstanceBase, ExtendOptions extends ExtendableRestGenerics | {}>(this: E, options: Readonly<RestEndpointExtendOptions<ExtendOptions, E, E['fetch']> & ExtendOptions> & ExtendOptions & ContentSchemaGuard<ExtendOptions>): RestExtendedEndpoint<ExtendOptions, E>;
|
|
25
|
+
}
|
|
26
|
+
interface RestInstancePaginators {
|
|
27
|
+
/** Creates an Endpoint to append the next page extending a list for pagination
|
|
28
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#paginated
|
|
29
|
+
*/
|
|
30
|
+
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, A extends any[]>(this: E, removeCursor: (...args: A) => readonly [
|
|
31
|
+
...Parameters<E>
|
|
32
|
+
]): PaginationEndpoint<E, A>;
|
|
33
|
+
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, C extends string>(this: E, cursorField: C): PaginationFieldEndpoint<E, C>;
|
|
34
|
+
}
|
|
20
35
|
export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends boolean | undefined = boolean | undefined, O extends {
|
|
21
36
|
path: string;
|
|
22
37
|
body?: any;
|
|
@@ -24,7 +39,7 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
24
39
|
method?: string;
|
|
25
40
|
} = {
|
|
26
41
|
path: string;
|
|
27
|
-
}> extends EndpointInstanceInterface<F, S, M
|
|
42
|
+
}> extends EndpointInstanceInterface<F, S, M>, RestInstanceExtenders {
|
|
28
43
|
/** @see https://dataclient.io/rest/api/RestEndpoint#body */
|
|
29
44
|
readonly body?: 'body' extends keyof O ? O['body'] : any;
|
|
30
45
|
/** @see https://dataclient.io/rest/api/RestEndpoint#searchParams */
|
|
@@ -60,7 +75,7 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
60
75
|
/** Prepares RequestInit used in fetch. This is sent to fetchResponse()
|
|
61
76
|
* @see https://dataclient.io/rest/api/RestEndpoint#getRequestInit
|
|
62
77
|
*/
|
|
63
|
-
getRequestInit(this: any, body?: RequestInit['body'] | Record<string, unknown>): Promise<RequestInit> | RequestInit;
|
|
78
|
+
getRequestInit(this: any, body?: RequestInit['body'] | Record<string, unknown> | readonly unknown[]): Promise<RequestInit> | RequestInit;
|
|
64
79
|
/** Called by getRequestInit to determine HTTP Headers
|
|
65
80
|
* @see https://dataclient.io/rest/api/RestEndpoint#getHeaders
|
|
66
81
|
*/
|
|
@@ -81,10 +96,6 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
81
96
|
* @see https://dataclient.io/rest/api/RestEndpoint#testKey
|
|
82
97
|
*/
|
|
83
98
|
testKey(key: string): boolean;
|
|
84
|
-
/** Creates a child endpoint that inherits from this while overriding provided `options`.
|
|
85
|
-
* @see https://dataclient.io/rest/api/RestEndpoint#extend
|
|
86
|
-
*/
|
|
87
|
-
extend<E extends RestInstanceBase, ExtendOptions extends PartialRestGenerics | {}>(this: E, options: Readonly<RestEndpointExtendOptions<ExtendOptions, E, F> & ExtendOptions> & ContentSchemaGuard<ExtendOptions>): RestExtendedEndpoint<ExtendOptions, E>;
|
|
88
99
|
}
|
|
89
100
|
export interface RestInstance<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends boolean | undefined = boolean | undefined, O extends {
|
|
90
101
|
path: string;
|
|
@@ -94,21 +105,18 @@ export interface RestInstance<F extends FetchFunction = FetchFunction, S extends
|
|
|
94
105
|
paginationField?: string;
|
|
95
106
|
} = {
|
|
96
107
|
path: string;
|
|
97
|
-
}> extends RestInstanceBase<F, S, M, O
|
|
98
|
-
/** Creates an Endpoint to append the next page extending a list for pagination
|
|
99
|
-
* @see https://dataclient.io/rest/api/RestEndpoint#paginated
|
|
100
|
-
*/
|
|
101
|
-
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, A extends any[]>(this: E, removeCursor: (...args: A) => readonly [
|
|
102
|
-
...Parameters<E>
|
|
103
|
-
]): PaginationEndpoint<E, A>;
|
|
104
|
-
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, C extends string>(this: E, cursorField: C): PaginationFieldEndpoint<E, C>;
|
|
108
|
+
}> extends RestInstanceBase<F, S, M, O>, RestInstancePaginators {
|
|
105
109
|
/** Concatinate the next page of results (GET)
|
|
106
110
|
* @see https://dataclient.io/rest/api/RestEndpoint#getPage
|
|
107
111
|
*/
|
|
108
|
-
getPage: 'paginationField' extends keyof O ? O['paginationField'] extends string ? PaginationFieldEndpoint<
|
|
112
|
+
getPage: 'paginationField' extends keyof O ? O['paginationField'] extends string ? PaginationFieldEndpoint<([
|
|
113
|
+
keyof F
|
|
114
|
+
] extends [
|
|
115
|
+
never
|
|
116
|
+
] ? (...args: any) => ReturnType<F> : F) & {
|
|
109
117
|
schema: S;
|
|
110
118
|
sideEffect: M;
|
|
111
|
-
} & O, O['paginationField']
|
|
119
|
+
} & O, Extract<O['paginationField'], string>> : undefined : undefined;
|
|
112
120
|
/** Create a new item (POST) and `push` to the end
|
|
113
121
|
* @see https://dataclient.io/rest/api/RestEndpoint#push
|
|
114
122
|
*/
|
|
@@ -146,7 +154,22 @@ export type RestEndpointExtendOptions<O extends PartialRestGenerics, E extends {
|
|
|
146
154
|
path?: string;
|
|
147
155
|
schema?: Schema;
|
|
148
156
|
method?: string;
|
|
149
|
-
}, F extends FetchFunction> = RestEndpointOptions<OptionsToFunction<O, E, F>, 'schema' extends keyof O ? Extract<O['schema'], Schema | undefined> : E['schema']> &
|
|
157
|
+
}, F extends FetchFunction> = RestEndpointOptions<OptionsToFunction<O, E, F>, 'schema' extends keyof O ? Extract<O['schema'], Schema | undefined> : E['schema']> & PartialPick<E, keyof E extends ExtendOmitKeys ? never : Exclude<keyof E, ExtendOmitKeys>>;
|
|
158
|
+
/** Argument I passed to process(), from Parameters<F>.
|
|
159
|
+
* Indexing a union like `[params] | []` or `[params, body] | [body]` (see ParamFetchNoBody/ParamFetchWithBody)
|
|
160
|
+
* merges position-wise, giving `undefined` where some call omits the argument.
|
|
161
|
+
* Endpoints that take no args keep `any`, so process(value, params: any) and similar still compile.
|
|
162
|
+
*/
|
|
163
|
+
type ProcessArg<A extends readonly any[], I extends 0 | 1> = [
|
|
164
|
+
A['length']
|
|
165
|
+
] extends [
|
|
166
|
+
0
|
|
167
|
+
] ? any : A[I];
|
|
168
|
+
type ExtendOmitKeys = KeyofRestEndpoint | keyof PartialRestGenerics | keyof RestEndpointOptions;
|
|
169
|
+
/** Partial<Pick<T, K>> as a single homomorphic mapped type */
|
|
170
|
+
type PartialPick<T, K extends keyof T> = {
|
|
171
|
+
[P in K]?: T[P];
|
|
172
|
+
};
|
|
150
173
|
type OptionsToRestEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase & {
|
|
151
174
|
body?: any;
|
|
152
175
|
paginationField?: string;
|
|
@@ -195,8 +218,12 @@ export type RestExtendedEndpoint<O extends PartialRestGenerics, E extends RestIn
|
|
|
195
218
|
};
|
|
196
219
|
} ? {
|
|
197
220
|
paginationField: E['getPage']['paginationField'];
|
|
198
|
-
} : unknown), RestInstance<(...args: Parameters<E>) => O['process'] extends {} ? Promise<ReturnType<O['process']>> : 'content' extends keyof O ? Promise<ContentReturnType<O['content'] & ContentType>> : ReturnType<E>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], boolean | undefined> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']>> & Omit<O, KeyofRestEndpoint> & Omit<E, KeyofRestEndpoint | keyof O
|
|
199
|
-
|
|
221
|
+
} : unknown), RestInstance<(...args: Parameters<E>) => O['process'] extends {} ? Promise<ReturnType<O['process']>> : 'content' extends keyof O ? Promise<ContentReturnType<O['content'] & ContentType>> : ReturnType<E>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], boolean | undefined> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']>> & (keyof O extends KeyofRestEndpoint ? unknown : Omit<O, KeyofRestEndpoint>) & (keyof E extends KeyofRestEndpoint ? unknown : Omit<E, KeyofRestEndpoint | keyof O>);
|
|
222
|
+
/** PartialRestGenerics without `process`. Options passed to the constructor, extend() and
|
|
223
|
+
* resource().extend() are constrained by this, so RestEndpointOptions' typed `process` member is
|
|
224
|
+
* the only contextual type for process() params.
|
|
225
|
+
*/
|
|
226
|
+
export interface ExtendableRestGenerics {
|
|
200
227
|
/** @see https://dataclient.io/rest/api/RestEndpoint#path */
|
|
201
228
|
readonly path?: string;
|
|
202
229
|
/** @see https://dataclient.io/rest/api/RestEndpoint#schema */
|
|
@@ -211,11 +238,13 @@ export interface PartialRestGenerics {
|
|
|
211
238
|
searchParams?: any;
|
|
212
239
|
/** @see https://dataclient.io/rest/api/RestEndpoint#paginationfield */
|
|
213
240
|
readonly paginationField?: string;
|
|
214
|
-
/** @see https://dataclient.io/rest/api/RestEndpoint#process */
|
|
215
|
-
process?(value: any, ...args: any): any;
|
|
216
241
|
/** @see https://dataclient.io/rest/api/RestEndpoint#content */
|
|
217
242
|
readonly content?: ContentType;
|
|
218
243
|
}
|
|
244
|
+
export interface PartialRestGenerics extends ExtendableRestGenerics {
|
|
245
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#process */
|
|
246
|
+
process?(value: any, ...args: any): any;
|
|
247
|
+
}
|
|
219
248
|
/** Generic types when constructing a RestEndpoint
|
|
220
249
|
*
|
|
221
250
|
* @see https://dataclient.io/rest/api/RestEndpoint#inheritance
|
|
@@ -223,6 +252,10 @@ export interface PartialRestGenerics {
|
|
|
223
252
|
export interface RestGenerics extends PartialRestGenerics {
|
|
224
253
|
readonly path: string;
|
|
225
254
|
}
|
|
255
|
+
/** RestGenerics without `process`; see ExtendableRestGenerics */
|
|
256
|
+
interface ConstructorRestGenerics extends ExtendableRestGenerics {
|
|
257
|
+
readonly path: string;
|
|
258
|
+
}
|
|
226
259
|
export type PaginationEndpoint<E extends FetchFunction & RestGenerics & {
|
|
227
260
|
sideEffect?: boolean | undefined;
|
|
228
261
|
}, A extends any[]> = RestInstanceBase<ParamFetchNoBody<A[0], ResolveType<E>>, E['schema'], E['sideEffect'], Pick<E, 'path' | 'searchParams' | 'body'> & {
|
|
@@ -340,6 +373,8 @@ export interface RestEndpointOptions<F extends FetchFunction = FetchFunction, S
|
|
|
340
373
|
fetch?: F;
|
|
341
374
|
key?(...args: Parameters<F>): string;
|
|
342
375
|
url?(...args: Parameters<F>): string;
|
|
376
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#process */
|
|
377
|
+
process?(value: any, params: ProcessArg<Parameters<F>, 0>, body: ProcessArg<Parameters<F>, 1>, ...rest: any[]): any;
|
|
343
378
|
update?: EndpointUpdateFunction<F, S>;
|
|
344
379
|
}
|
|
345
380
|
export type RestEndpointConstructorOptions<O extends RestGenerics = any> = RestEndpointOptions<RestFetch<unknown extends O ? any : 'searchParams' extends keyof O ? [
|
|
@@ -364,7 +399,7 @@ export interface RestEndpointConstructor {
|
|
|
364
399
|
*
|
|
365
400
|
* @see https://dataclient.io/rest/api/RestEndpoint
|
|
366
401
|
*/
|
|
367
|
-
new <O extends
|
|
402
|
+
new <O extends ConstructorRestGenerics = any>({ method, sideEffect, name, ...options }: RestEndpointConstructorOptions<O> & Readonly<O> & O & ContentSchemaGuard<O>): RestEndpoint<O>;
|
|
368
403
|
readonly prototype: RestInstanceBase;
|
|
369
404
|
}
|
|
370
405
|
export type MethodToSide<M> = M extends string ? M extends 'GET' ? undefined : true : undefined;
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { Schema, schema } from '@data-client/endpoint';
|
|
2
2
|
import { ExtractObject } from './extractObject.js';
|
|
3
3
|
export default function extractCollection<M extends <C extends schema.Collection>(collection: C) => any, S extends Schema | undefined>(s: S, mapper: M): ExtractCollection<S> | undefined;
|
|
4
|
+
/** Searches wrappers like Query and Lazy through their `schema` (Entity classes have a `prototype`) */
|
|
4
5
|
export type ExtractCollection<S extends Schema | undefined> = S extends ({
|
|
5
6
|
push: any;
|
|
6
7
|
unshift: any;
|
|
7
8
|
assign: any;
|
|
8
9
|
remove: any;
|
|
9
10
|
schema: Schema;
|
|
10
|
-
}) ? S : S extends schema.Object<infer T> ? ExtractObject<T> : S extends
|
|
11
|
+
}) ? S : S extends schema.Object<infer T> ? ExtractObject<T> : S extends {
|
|
12
|
+
schema: infer Q;
|
|
13
|
+
denormalize: any;
|
|
14
|
+
prototype?: undefined;
|
|
15
|
+
} ? ExtractObject<{
|
|
16
|
+
schema: Q;
|
|
17
|
+
}> : S extends Exclude<Schema, {
|
|
11
18
|
[K: string]: any;
|
|
12
19
|
}> ? never : S extends {
|
|
13
20
|
[K: string]: Schema;
|
package/ts4.1/mapCollection.d.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { Schema, schema } from '@data-client/endpoint';
|
|
2
|
-
export default function mapCollection<M extends <C extends schema.Collection>(collection: C) => any, S extends Schema | undefined>(s: S, mapper: M): S extends schema.Collection
|
|
3
|
-
[K
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
export type MapObject<M extends (collection: schema.Collection) => any, S extends Record<string, any>> = {
|
|
13
|
-
[K in keyof S]: S[K] extends Schema ? MapCollection<M, S[K]> : S[K];
|
|
14
|
-
};
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=mapCollection.d.ts.map
|
|
1
|
+
import { Schema, schema } from '@data-client/endpoint';
|
|
2
|
+
export default function mapCollection<M extends <C extends schema.Collection>(collection: C) => any, S extends Schema | undefined>(s: S, mapper: M): S extends schema.Collection | schema.Object<any> | {
|
|
3
|
+
[K: string]: any;
|
|
4
|
+
} ? MapCollection<M, S> : S;
|
|
5
|
+
type MapCollection<M extends <C extends schema.Collection>(collection: C) => any, S extends Schema | undefined> = S extends schema.Collection ? ReturnType<M> : S extends schema.Object<infer T> ? MapObject<M, T> : S extends {
|
|
6
|
+
[K: string]: any;
|
|
7
|
+
} ? MapObject<M, S> : never;
|
|
8
|
+
export type MapObject<M extends (collection: schema.Collection) => any, S extends Record<string, any>> = {
|
|
9
|
+
[K in keyof S]: S[K] extends Schema ? MapCollection<M, S[K]> : S[K];
|
|
10
|
+
};
|
|
11
|
+
export {};
|