@data-client/rest 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +39 -3
- package/dist/index.umd.min.js +1 -1
- package/dist/next.js +39 -3
- package/legacy/OptionsToFunction.js +1 -1
- package/legacy/createResource.js +34 -6
- package/legacy/index.js +1 -1
- package/legacy/next/index.js +1 -1
- package/legacy/resourceExtendable.js +2 -0
- package/legacy/resourceExtensionTypes.js +2 -0
- package/legacy/resourceTypes.js +1 -1
- package/lib/OptionsToFunction.d.ts +1 -1
- package/lib/OptionsToFunction.d.ts.map +1 -1
- package/lib/OptionsToFunction.js +1 -1
- package/lib/RestEndpoint.d.ts +33 -16
- package/lib/createResource.d.ts +2 -96
- package/lib/createResource.d.ts.map +1 -1
- package/lib/createResource.js +40 -4
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/next/index.d.ts +1 -1
- package/lib/next/index.d.ts.map +1 -1
- package/lib/next/index.js +1 -1
- package/lib/resourceExtendable.d.ts +25 -0
- package/lib/resourceExtendable.d.ts.map +1 -0
- package/lib/resourceExtendable.js +2 -0
- package/lib/resourceExtensionTypes.d.ts +33 -0
- package/lib/resourceExtensionTypes.d.ts.map +1 -0
- package/lib/resourceExtensionTypes.js +2 -0
- package/lib/resourceTypes.d.ts +94 -4
- package/lib/resourceTypes.d.ts.map +1 -1
- package/lib/resourceTypes.js +1 -1
- package/package.json +1 -1
- package/src/OptionsToFunction.ts +1 -1
- package/src/RestEndpoint.d.ts +33 -16
- package/src/__tests__/createResource.test.ts +490 -19
- package/src/createResource.ts +54 -126
- package/src/index.ts +2 -1
- package/src/next/index.ts +1 -1
- package/src/resourceExtendable.ts +95 -0
- package/src/resourceExtensionTypes.ts +109 -0
- package/src/resourceTypes.ts +119 -4
- package/ts4.0/RestEndpoint.d.ts +25 -7
- package/ts4.0/createResource.d.ts +2 -108
- package/ts4.0/index.d.ts +2 -2
- package/ts4.0/next/index.d.ts +1 -1
- package/ts4.0/resourceExtendable.d.ts +21 -0
- package/ts4.0/resourceExtensionTypes.d.ts +33 -0
- package/ts4.0/resourceTypes.d.ts +102 -4
- package/ts4.1/OptionsToFunction.d.ts +1 -1
- package/ts4.1/RestEndpoint.d.ts +25 -7
- package/ts4.1/createResource.d.ts +2 -108
- package/ts4.1/index.d.ts +2 -2
- package/ts4.1/next/index.d.ts +1 -1
- package/ts4.1/resourceExtendable.d.ts +21 -0
- package/ts4.1/resourceExtensionTypes.d.ts +33 -0
- package/ts4.1/resourceTypes.d.ts +102 -4
- package/ts4.0/deleteme.d.ts +0 -0
- package/ts4.1/deleteme.d.ts +0 -0
|
@@ -1,113 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Denormalize } from '@data-client/endpoint';
|
|
3
|
-
import { PathArgs, ResourcePath, ShortenPath } from './pathTypes.js';
|
|
4
|
-
import { ResourceGenerics, ResourceOptions } from './resourceTypes.js';
|
|
5
|
-
import { GetEndpoint, MutateEndpoint, PaginationFieldEndpoint, RestTypeNoBody } from './RestEndpoint.js';
|
|
1
|
+
import { ResourceGenerics, ResourceOptions, Resource } from './resourceTypes.js';
|
|
6
2
|
/** Creates collection of Endpoints for common operations on a given data/schema.
|
|
7
3
|
*
|
|
8
4
|
* @see https://resthooks.io/rest/api/createResource
|
|
9
5
|
*/
|
|
10
|
-
export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, optimistic,
|
|
11
|
-
export interface Resource<O extends ResourceGenerics = {
|
|
12
|
-
path: ResourcePath;
|
|
13
|
-
schema: any;
|
|
14
|
-
}> {
|
|
15
|
-
/** Get a singular item
|
|
16
|
-
*
|
|
17
|
-
* @see https://resthooks.io/rest/api/createResource#get
|
|
18
|
-
*/
|
|
19
|
-
get: GetEndpoint<{
|
|
20
|
-
path: O['path'];
|
|
21
|
-
schema: O['schema'];
|
|
22
|
-
}>;
|
|
23
|
-
/** Get a list of item
|
|
24
|
-
*
|
|
25
|
-
* @see https://resthooks.io/rest/api/createResource#getlist
|
|
26
|
-
*/
|
|
27
|
-
getList: 'searchParams' extends keyof O ? GetEndpoint<{
|
|
28
|
-
path: ShortenPath<O['path']>;
|
|
29
|
-
schema: schema.Collection<[
|
|
30
|
-
O['schema']
|
|
31
|
-
]>;
|
|
32
|
-
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
33
|
-
searchParams: O['searchParams'];
|
|
34
|
-
}> : GetEndpoint<{
|
|
35
|
-
path: ShortenPath<O['path']>;
|
|
36
|
-
schema: schema.Collection<[
|
|
37
|
-
O['schema']
|
|
38
|
-
]>;
|
|
39
|
-
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
40
|
-
searchParams: Record<string, number | string | boolean> | undefined;
|
|
41
|
-
}>;
|
|
42
|
-
/** Get a list of item
|
|
43
|
-
*
|
|
44
|
-
* @see https://dataclient.io/rest/api/createResource#getNextPage
|
|
45
|
-
*/
|
|
46
|
-
getNextPage: 'paginationField' extends keyof O ? PaginationFieldEndpoint<'searchParams' extends keyof O ? GetEndpoint<{
|
|
47
|
-
path: ShortenPath<O['path']>;
|
|
48
|
-
schema: schema.Collection<[
|
|
49
|
-
O['schema']
|
|
50
|
-
]>;
|
|
51
|
-
searchParams: O['searchParams'];
|
|
52
|
-
}> : GetEndpoint<{
|
|
53
|
-
path: ShortenPath<O['path']>;
|
|
54
|
-
schema: schema.Collection<[
|
|
55
|
-
O['schema']
|
|
56
|
-
]>;
|
|
57
|
-
searchParams: Record<string, number | string | boolean> | undefined;
|
|
58
|
-
}>, Exclude<O['paginationField'], undefined>> : undefined;
|
|
59
|
-
/** Create a new item (POST)
|
|
60
|
-
*
|
|
61
|
-
* @see https://resthooks.io/rest/api/createResource#create
|
|
62
|
-
*/
|
|
63
|
-
create: 'searchParams' extends keyof O ? MutateEndpoint<{
|
|
64
|
-
path: ShortenPath<O['path']>;
|
|
65
|
-
schema: schema.Collection<[
|
|
66
|
-
O['schema']
|
|
67
|
-
]>['push'];
|
|
68
|
-
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
69
|
-
searchParams: O['searchParams'];
|
|
70
|
-
}> : MutateEndpoint<{
|
|
71
|
-
path: ShortenPath<O['path']>;
|
|
72
|
-
schema: schema.Collection<[
|
|
73
|
-
O['schema']
|
|
74
|
-
]>['push'];
|
|
75
|
-
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
76
|
-
}>;
|
|
77
|
-
/** Update an item (PUT)
|
|
78
|
-
*
|
|
79
|
-
* @see https://resthooks.io/rest/api/createResource#update
|
|
80
|
-
*/
|
|
81
|
-
update: 'body' extends keyof O ? MutateEndpoint<{
|
|
82
|
-
path: O['path'];
|
|
83
|
-
body: O['body'];
|
|
84
|
-
schema: O['schema'];
|
|
85
|
-
}> : MutateEndpoint<{
|
|
86
|
-
path: O['path'];
|
|
87
|
-
body: Partial<Denormalize<O['schema']>>;
|
|
88
|
-
schema: O['schema'];
|
|
89
|
-
}>;
|
|
90
|
-
/** Update an item (PATCH)
|
|
91
|
-
*
|
|
92
|
-
* @see https://resthooks.io/rest/api/createResource#partialupdate
|
|
93
|
-
*/
|
|
94
|
-
partialUpdate: 'body' extends keyof O ? MutateEndpoint<{
|
|
95
|
-
path: O['path'];
|
|
96
|
-
body: Partial<O['body']>;
|
|
97
|
-
schema: O['schema'];
|
|
98
|
-
}> : MutateEndpoint<{
|
|
99
|
-
path: O['path'];
|
|
100
|
-
body: Partial<Denormalize<O['schema']>>;
|
|
101
|
-
schema: O['schema'];
|
|
102
|
-
}>;
|
|
103
|
-
/** Delete an item (DELETE)
|
|
104
|
-
*
|
|
105
|
-
* @see https://resthooks.io/rest/api/createResource#delete
|
|
106
|
-
*/
|
|
107
|
-
delete: RestTypeNoBody<PathArgs<O['path']>, O['schema'] extends schema.EntityInterface & {
|
|
108
|
-
process: any;
|
|
109
|
-
} ? schema.Invalidate<O['schema']> : O['schema'], undefined, Partial<PathArgs<O['path']>>, {
|
|
110
|
-
path: O['path'];
|
|
111
|
-
}>;
|
|
112
|
-
}
|
|
6
|
+
export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, optimistic, ...extraOptions }: Readonly<O> & ResourceOptions): Resource<O>;
|
|
113
7
|
//# sourceMappingURL=createResource.d.ts.map
|
package/ts4.0/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { default as RestEndpoint } from './RestEndpoint.js';
|
|
2
|
-
export type { GetEndpoint, MutateEndpoint, Defaults, RestGenerics, FetchGet, FetchMutate, RestFetch, RestType, RestInstance, KeyofRestEndpoint, RestEndpointConstructorOptions, AddEndpoint, PaginationFieldEndpoint, } from './RestEndpoint.js';
|
|
2
|
+
export type { GetEndpoint, MutateEndpoint, Defaults, RestGenerics, FetchGet, FetchMutate, RestFetch, RestType, RestInstance, KeyofRestEndpoint, RestEndpointConstructorOptions, AddEndpoint, PaginationFieldEndpoint, PaginationEndpoint, } from './RestEndpoint.js';
|
|
3
3
|
export { default as createResource } from './createResource.js';
|
|
4
|
-
export type { Resource } from './
|
|
4
|
+
export type { Resource } from './resourceTypes.js';
|
|
5
5
|
export type { ResourceOptions, ResourceGenerics } from './resourceTypes.js';
|
|
6
6
|
export { default as hookifyResource } from './hookifyResource.js';
|
|
7
7
|
export type { HookResource, HookableEndpointInterface, } from './hookifyResource.js';
|
package/ts4.0/next/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '../RestEndpoint.js';
|
|
2
2
|
export { default as RestEndpoint } from '../RestEndpoint.js';
|
|
3
3
|
export { default as createResource } from '../createResource.js';
|
|
4
|
-
export type { Resource } from '../
|
|
4
|
+
export type { Resource } from '../resourceTypes.js';
|
|
5
5
|
export type { ResourceOptions, ResourceGenerics } from '../resourceTypes.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EndpointInterface, EndpointToFunction } from '@data-client/endpoint';
|
|
2
|
+
import type { ResourcePath } from './pathTypes.js';
|
|
3
|
+
import type { ResourceExtension, ResourceEndpointExtensions, CustomResource, ExtendedResource } from './resourceExtensionTypes.js';
|
|
4
|
+
import type { ResourceGenerics, ResourceInterface } from './resourceTypes.js';
|
|
5
|
+
import type { PartialRestGenerics, RestEndpointExtendOptions, RestExtendedEndpoint, RestInstanceBase } from './RestEndpoint.js';
|
|
6
|
+
export interface Extendable<O extends ResourceGenerics = {
|
|
7
|
+
path: ResourcePath;
|
|
8
|
+
schema: any;
|
|
9
|
+
}> {
|
|
10
|
+
extend<R extends {
|
|
11
|
+
[K in ExtendKey]: RestInstanceBase;
|
|
12
|
+
}, ExtendKey extends Exclude<Extract<keyof R, string>, 'extend'>, ExtendOptions extends PartialRestGenerics | {}>(this: R, key: ExtendKey, options: Readonly<RestEndpointExtendOptions<ExtendOptions, R[ExtendKey], EndpointToFunction<R[ExtendKey]>> & ExtendOptions>): ResourceExtension<R, ExtendKey, ExtendOptions>;
|
|
13
|
+
extend<R extends {
|
|
14
|
+
get: RestInstanceBase;
|
|
15
|
+
}, ExtendKey extends string, ExtendOptions extends PartialRestGenerics | {}>(this: R, key: ExtendKey, options: Readonly<RestEndpointExtendOptions<ExtendOptions, R['get'], EndpointToFunction<R['get']>> & ExtendOptions>): R & {
|
|
16
|
+
[key in ExtendKey]: RestExtendedEndpoint<ExtendOptions, R['get']>;
|
|
17
|
+
};
|
|
18
|
+
extend<R extends ResourceInterface, Get extends PartialRestGenerics = any, GetList extends PartialRestGenerics = any, Update extends PartialRestGenerics = any, PartialUpdate extends PartialRestGenerics = any, Delete extends PartialRestGenerics = any>(this: R, options: ResourceEndpointExtensions<R, Get, GetList, Update, PartialUpdate, Delete>): CustomResource<R, O, Get, GetList, Update, PartialUpdate, Delete>;
|
|
19
|
+
extend<R extends ResourceInterface, T extends Record<string, EndpointInterface>>(this: R, extender: (baseResource: R) => T): ExtendedResource<R, T>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=resourceExtendable.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { EndpointInterface, EndpointToFunction } from '@data-client/endpoint';
|
|
2
|
+
import { OptionsToFunction } from './OptionsToFunction.js';
|
|
3
|
+
import type { ResourcePath } from './pathTypes.js';
|
|
4
|
+
import { Extendable } from './resourceExtendable.js';
|
|
5
|
+
import { ResourceGenerics, ResourceInterface } from './resourceTypes.js';
|
|
6
|
+
import type { PartialRestGenerics, RestExtendedEndpoint, RestInstanceBase, RestEndpointOptions } from './RestEndpoint.js';
|
|
7
|
+
export type ResourceExtension<R extends {
|
|
8
|
+
[K in ExtendKey]: RestInstanceBase;
|
|
9
|
+
}, ExtendKey extends Exclude<Extract<keyof R, string>, 'extend'>, O extends PartialRestGenerics | {}> = {
|
|
10
|
+
[K in keyof R]: K extends ExtendKey ? RestExtendedEndpoint<O, R[K]> : R[K];
|
|
11
|
+
};
|
|
12
|
+
/** Resource with individual endpoints customized
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export interface CustomResource<R extends ResourceInterface, O extends ResourceGenerics = {
|
|
16
|
+
path: ResourcePath;
|
|
17
|
+
schema: any;
|
|
18
|
+
}, Get extends PartialRestGenerics | {} = any, GetList extends PartialRestGenerics | {} = any, Update extends PartialRestGenerics | {} = any, PartialUpdate extends PartialRestGenerics | {} = any, Delete extends PartialRestGenerics | {} = any> extends Extendable<O> {
|
|
19
|
+
get: unknown extends Get ? R['get'] : RestExtendedEndpoint<Get, R['get']>;
|
|
20
|
+
getList: unknown extends GetList ? R['getList'] : RestExtendedEndpoint<GetList, R['getList']>;
|
|
21
|
+
update: unknown extends Update ? R['update'] : RestExtendedEndpoint<Update, R['update']>;
|
|
22
|
+
partialUpdate: unknown extends PartialUpdate ? R['partialUpdate'] : RestExtendedEndpoint<PartialUpdate, R['partialUpdate']>;
|
|
23
|
+
delete: unknown extends Delete ? R['delete'] : RestExtendedEndpoint<Delete, R['delete']>;
|
|
24
|
+
}
|
|
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 PartialRestGenerics = any, GetList extends PartialRestGenerics = any, Update extends PartialRestGenerics = any, PartialUpdate extends PartialRestGenerics = any, Delete extends PartialRestGenerics = any> {
|
|
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>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=resourceExtensionTypes.d.ts.map
|
package/ts4.0/resourceTypes.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import type { schema } from '@data-client/endpoint';
|
|
1
2
|
import type { Schema } from '@data-client/endpoint';
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
3
|
+
import type { Denormalize } from '@data-client/endpoint';
|
|
4
|
+
import type { PathArgs, ResourcePath, ShortenPath } from './pathTypes.js';
|
|
5
|
+
import { Extendable } from './resourceExtendable.js';
|
|
6
|
+
import RestEndpoint, { GetEndpoint, MutateEndpoint, RestInstanceBase, RestTypeNoBody } from './RestEndpoint.js';
|
|
7
|
+
/** The typed (generic) options for a Resource */
|
|
4
8
|
export interface ResourceGenerics {
|
|
5
9
|
/** @see https://resthooks.io/rest/api/createResource#path */
|
|
6
10
|
readonly path: ResourcePath;
|
|
7
11
|
/** @see https://resthooks.io/rest/api/createResource#schema */
|
|
8
12
|
readonly schema: Schema;
|
|
9
|
-
/** @see https://resthooks.io/rest/api/createResource#paginationfield */
|
|
10
|
-
readonly paginationField?: string;
|
|
11
13
|
/** Only used for types */
|
|
12
14
|
/** @see https://dataclient.io/rest/api/createResource#body */
|
|
13
15
|
readonly body?: any;
|
|
@@ -15,6 +17,7 @@ export interface ResourceGenerics {
|
|
|
15
17
|
/** @see https://resthooks.io/rest/api/createResource#searchParams */
|
|
16
18
|
readonly searchParams?: any;
|
|
17
19
|
}
|
|
20
|
+
/** The untyped options for createResource() */
|
|
18
21
|
export interface ResourceOptions {
|
|
19
22
|
/** @see https://resthooks.io/rest/api/createResource#endpoint */
|
|
20
23
|
Endpoint?: typeof RestEndpoint;
|
|
@@ -38,4 +41,99 @@ export interface ResourceOptions {
|
|
|
38
41
|
/** Determines whether to throw or fallback to */
|
|
39
42
|
errorPolicy?(error: any): 'hard' | 'soft' | undefined;
|
|
40
43
|
}
|
|
44
|
+
/** Resources are a collection of methods for a given data model.
|
|
45
|
+
* @see https://resthooks.io/rest/api/createResource
|
|
46
|
+
*/
|
|
47
|
+
export interface Resource<O extends ResourceGenerics = {
|
|
48
|
+
path: ResourcePath;
|
|
49
|
+
schema: any;
|
|
50
|
+
}> extends Extendable<O> {
|
|
51
|
+
/** Get a singular item
|
|
52
|
+
*
|
|
53
|
+
* @see https://resthooks.io/rest/api/createResource#get
|
|
54
|
+
*/
|
|
55
|
+
get: GetEndpoint<{
|
|
56
|
+
path: O['path'];
|
|
57
|
+
schema: O['schema'];
|
|
58
|
+
}>;
|
|
59
|
+
/** Get a list of item
|
|
60
|
+
*
|
|
61
|
+
* @see https://resthooks.io/rest/api/createResource#getlist
|
|
62
|
+
*/
|
|
63
|
+
getList: 'searchParams' extends keyof O ? GetEndpoint<{
|
|
64
|
+
path: ShortenPath<O['path']>;
|
|
65
|
+
schema: schema.Collection<[
|
|
66
|
+
O['schema']
|
|
67
|
+
]>;
|
|
68
|
+
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
69
|
+
searchParams: O['searchParams'];
|
|
70
|
+
}> : GetEndpoint<{
|
|
71
|
+
path: ShortenPath<O['path']>;
|
|
72
|
+
schema: schema.Collection<[
|
|
73
|
+
O['schema']
|
|
74
|
+
]>;
|
|
75
|
+
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
76
|
+
searchParams: Record<string, number | string | boolean> | undefined;
|
|
77
|
+
}>;
|
|
78
|
+
/** Create a new item (POST)
|
|
79
|
+
*
|
|
80
|
+
* @deprecated use Resource.getList.push instead
|
|
81
|
+
*/
|
|
82
|
+
create: 'searchParams' extends keyof O ? MutateEndpoint<{
|
|
83
|
+
path: ShortenPath<O['path']>;
|
|
84
|
+
schema: schema.Collection<[
|
|
85
|
+
O['schema']
|
|
86
|
+
]>['push'];
|
|
87
|
+
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
88
|
+
searchParams: O['searchParams'];
|
|
89
|
+
}> : MutateEndpoint<{
|
|
90
|
+
path: ShortenPath<O['path']>;
|
|
91
|
+
schema: schema.Collection<[
|
|
92
|
+
O['schema']
|
|
93
|
+
]>['push'];
|
|
94
|
+
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
95
|
+
}>;
|
|
96
|
+
/** Update an item (PUT)
|
|
97
|
+
*
|
|
98
|
+
* @see https://resthooks.io/rest/api/createResource#update
|
|
99
|
+
*/
|
|
100
|
+
update: 'body' extends keyof O ? MutateEndpoint<{
|
|
101
|
+
path: O['path'];
|
|
102
|
+
body: O['body'];
|
|
103
|
+
schema: O['schema'];
|
|
104
|
+
}> : MutateEndpoint<{
|
|
105
|
+
path: O['path'];
|
|
106
|
+
body: Partial<Denormalize<O['schema']>>;
|
|
107
|
+
schema: O['schema'];
|
|
108
|
+
}>;
|
|
109
|
+
/** Update an item (PATCH)
|
|
110
|
+
*
|
|
111
|
+
* @see https://resthooks.io/rest/api/createResource#partialupdate
|
|
112
|
+
*/
|
|
113
|
+
partialUpdate: 'body' extends keyof O ? MutateEndpoint<{
|
|
114
|
+
path: O['path'];
|
|
115
|
+
body: Partial<O['body']>;
|
|
116
|
+
schema: O['schema'];
|
|
117
|
+
}> : MutateEndpoint<{
|
|
118
|
+
path: O['path'];
|
|
119
|
+
body: Partial<Denormalize<O['schema']>>;
|
|
120
|
+
schema: O['schema'];
|
|
121
|
+
}>;
|
|
122
|
+
/** Delete an item (DELETE)
|
|
123
|
+
*
|
|
124
|
+
* @see https://resthooks.io/rest/api/createResource#delete
|
|
125
|
+
*/
|
|
126
|
+
delete: RestTypeNoBody<PathArgs<O['path']>, O['schema'] extends schema.EntityInterface & {
|
|
127
|
+
process: any;
|
|
128
|
+
} ? schema.Invalidate<O['schema']> : O['schema'], undefined, Partial<PathArgs<O['path']>>, {
|
|
129
|
+
path: O['path'];
|
|
130
|
+
}>;
|
|
131
|
+
}
|
|
132
|
+
export interface ResourceInterface {
|
|
133
|
+
get: RestInstanceBase;
|
|
134
|
+
getList: RestInstanceBase;
|
|
135
|
+
update: RestInstanceBase;
|
|
136
|
+
partialUpdate: RestInstanceBase;
|
|
137
|
+
delete: RestInstanceBase;
|
|
138
|
+
}
|
|
41
139
|
//# sourceMappingURL=resourceTypes.d.ts.map
|
|
@@ -8,5 +8,5 @@ export type OptionsToFunction<O extends PartialRestGenerics, E extends {
|
|
|
8
8
|
}, F extends FetchFunction> = 'path' extends keyof O ? RestFetch<'searchParams' extends keyof O ? O['searchParams'] & PathArgs<Exclude<O['path'], undefined>> : PathArgs<Exclude<O['path'], undefined>>, OptionsToBodyArgument<'body' extends keyof O ? O : E, 'method' extends keyof O ? O['method'] : E['method']>, O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>> : 'body' extends keyof O ? RestFetch<'searchParams' extends keyof O ? O['searchParams'] & PathArgs<Exclude<E['path'], undefined>> : PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<O, 'method' extends keyof O ? O['method'] : E['method']>, O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>> : 'searchParams' extends keyof O ? RestFetch<O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<E, 'method' extends keyof O ? O['method'] : E['method']>, O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>> : (this: ThisParameterType<F>, ...args: Parameters<F>) => Promise<O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>>;
|
|
9
9
|
export type OptionsToBodyArgument<O extends {
|
|
10
10
|
body?: any;
|
|
11
|
-
}, Method extends string | undefined> = Method extends 'POST' | 'PUT' | 'PATCH' ? 'body' extends keyof O ? O['body'] : any : undefined;
|
|
11
|
+
}, Method extends string | undefined> = Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' ? 'body' extends keyof O ? O['body'] : any : undefined;
|
|
12
12
|
//# sourceMappingURL=OptionsToFunction.d.ts.map
|
package/ts4.1/RestEndpoint.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
import type { EndpointExtraOptions, EndpointInstanceInterface, Schema, FetchFunction, ResolveType,
|
|
2
|
+
import type { EndpointExtraOptions, EndpointInstanceInterface, Schema, FetchFunction, ResolveType, } from '@data-client/endpoint';
|
|
3
3
|
import type { ExtractCollection } from './extractCollection.js';
|
|
4
4
|
import { OptionsToBodyArgument, OptionsToFunction, } from './OptionsToFunction.js';
|
|
5
5
|
import { PathArgs } from './pathTypes.js';
|
|
@@ -12,7 +12,9 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
12
12
|
} = {
|
|
13
13
|
path: string;
|
|
14
14
|
}> extends EndpointInstanceInterface<F, S, M> {
|
|
15
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#body */
|
|
15
16
|
readonly body?: 'body' extends keyof O ? O['body'] : any;
|
|
17
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#searchParams */
|
|
16
18
|
readonly searchParams?: 'searchParams' extends keyof O ? O['searchParams'] : unknown;
|
|
17
19
|
/** Pattern to construct url based on Url Parameters
|
|
18
20
|
* @see https://resthooks.io/rest/api/RestEndpoint#path
|
|
@@ -23,6 +25,7 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
23
25
|
*/
|
|
24
26
|
readonly urlPrefix: string;
|
|
25
27
|
readonly requestInit: RequestInit;
|
|
28
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#method */
|
|
26
29
|
readonly method: (O & {
|
|
27
30
|
method: string;
|
|
28
31
|
})['method'];
|
|
@@ -49,11 +52,10 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
49
52
|
// this is just a hack to handle when no members of PartialRestGenerics are present
|
|
50
53
|
// Note: Using overloading (like paginated did) struggles because typescript does not have a clear way of distinguishing one
|
|
51
54
|
// should be used from the other (due to same problem with every member being partial)
|
|
55
|
+
/** Creates a child endpoint that inherits from this while overriding provided `options`.
|
|
56
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#extend
|
|
57
|
+
*/
|
|
52
58
|
extend<E extends RestInstanceBase, O extends PartialRestGenerics | {}>(this: E, options: Readonly<RestEndpointExtendOptions<O, E, F> & O>): RestExtendedEndpoint<O, E>;
|
|
53
|
-
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, A extends any[]>(this: E, removeCursor: (...args: A) => readonly [
|
|
54
|
-
...Parameters<E>
|
|
55
|
-
]): PaginationEndpoint<E, A>;
|
|
56
|
-
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, C extends string>(this: E, cursorField: C): PaginationFieldEndpoint<E, C>;
|
|
57
59
|
}
|
|
58
60
|
export interface RestInstance<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends true | undefined = true | undefined, O extends {
|
|
59
61
|
path: string;
|
|
@@ -63,12 +65,28 @@ export interface RestInstance<F extends FetchFunction = FetchFunction, S extends
|
|
|
63
65
|
} = {
|
|
64
66
|
path: string;
|
|
65
67
|
}> extends RestInstanceBase<F, S, M, O> {
|
|
68
|
+
/** Endpoint to append the next page extending a list for pagination
|
|
69
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#paginated
|
|
70
|
+
*/
|
|
71
|
+
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, A extends any[]>(this: E, removeCursor: (...args: A) => readonly [
|
|
72
|
+
...Parameters<E>
|
|
73
|
+
]): PaginationEndpoint<E, A>;
|
|
74
|
+
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, C extends string>(this: E, cursorField: C): PaginationFieldEndpoint<E, C>;
|
|
75
|
+
/** Endpoint that pushes (place at end) a newly created entity to this Collection
|
|
76
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#push
|
|
77
|
+
*/
|
|
66
78
|
push: AddEndpoint<F, ExtractCollection<S>['push'], Exclude<O, 'body' | 'method'> & {
|
|
67
79
|
body: OptionsToAdderBodyArgument<O> | OptionsToAdderBodyArgument<O>[] | FormData;
|
|
68
80
|
}>;
|
|
81
|
+
/** Endpoint that unshifts (place at start) a newly created entity to this Collection
|
|
82
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#unshift
|
|
83
|
+
*/
|
|
69
84
|
unshift: AddEndpoint<F, ExtractCollection<S>['unshift'], Exclude<O, 'body' | 'method'> & {
|
|
70
85
|
body: OptionsToAdderBodyArgument<O> | OptionsToAdderBodyArgument<O>[] | FormData;
|
|
71
86
|
}>;
|
|
87
|
+
/** Endpoint that assigns newly created entities to their respective keys in this Collection
|
|
88
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#assign
|
|
89
|
+
*/
|
|
72
90
|
assign: AddEndpoint<F, ExtractCollection<S>, Exclude<O, 'body' | 'method'> & {
|
|
73
91
|
body: Record<string, OptionsToAdderBodyArgument<O>> | FormData;
|
|
74
92
|
}>;
|
|
@@ -138,7 +156,7 @@ export type AddEndpoint<F extends FetchFunction = FetchFunction, S extends Schem
|
|
|
138
156
|
} = {
|
|
139
157
|
path: string;
|
|
140
158
|
body: any;
|
|
141
|
-
}> = RestInstanceBase<RestFetch<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>> : PathArgs<Exclude<O['path'], undefined>>, O['body'], ResolveType<F>>, S, true, O & {
|
|
159
|
+
}> = RestInstanceBase<RestFetch<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>> : PathArgs<Exclude<O['path'], undefined>>, O['body'], ResolveType<F>>, S, true, Omit<O, 'method'> & {
|
|
142
160
|
method: 'POST';
|
|
143
161
|
}>;
|
|
144
162
|
type OptionsBodyDefault<O extends RestGenerics> = 'body' extends keyof O ? O : O['method'] extends 'POST' | 'PUT' | 'PATCH' ? O & {
|
|
@@ -259,5 +277,5 @@ export type MutateEndpoint<O extends {
|
|
|
259
277
|
schema: Schema;
|
|
260
278
|
}> = RestTypeWithBody<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<O['path']> : O['searchParams'] & PathArgs<O['path']> : PathArgs<O['path']>, O['schema'], true, O['body'], any, O & {
|
|
261
279
|
body: any;
|
|
262
|
-
method: 'POST' | 'PUT' | 'PATCH';
|
|
280
|
+
method: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
263
281
|
}>;
|
|
@@ -1,113 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Denormalize } from '@data-client/endpoint';
|
|
3
|
-
import { PathArgs, ResourcePath, ShortenPath } from './pathTypes.js';
|
|
4
|
-
import { ResourceGenerics, ResourceOptions } from './resourceTypes.js';
|
|
5
|
-
import { GetEndpoint, MutateEndpoint, PaginationFieldEndpoint, RestTypeNoBody } from './RestEndpoint.js';
|
|
1
|
+
import { ResourceGenerics, ResourceOptions, Resource } from './resourceTypes.js';
|
|
6
2
|
/** Creates collection of Endpoints for common operations on a given data/schema.
|
|
7
3
|
*
|
|
8
4
|
* @see https://resthooks.io/rest/api/createResource
|
|
9
5
|
*/
|
|
10
|
-
export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, optimistic,
|
|
11
|
-
export interface Resource<O extends ResourceGenerics = {
|
|
12
|
-
path: ResourcePath;
|
|
13
|
-
schema: any;
|
|
14
|
-
}> {
|
|
15
|
-
/** Get a singular item
|
|
16
|
-
*
|
|
17
|
-
* @see https://resthooks.io/rest/api/createResource#get
|
|
18
|
-
*/
|
|
19
|
-
get: GetEndpoint<{
|
|
20
|
-
path: O['path'];
|
|
21
|
-
schema: O['schema'];
|
|
22
|
-
}>;
|
|
23
|
-
/** Get a list of item
|
|
24
|
-
*
|
|
25
|
-
* @see https://resthooks.io/rest/api/createResource#getlist
|
|
26
|
-
*/
|
|
27
|
-
getList: 'searchParams' extends keyof O ? GetEndpoint<{
|
|
28
|
-
path: ShortenPath<O['path']>;
|
|
29
|
-
schema: schema.Collection<[
|
|
30
|
-
O['schema']
|
|
31
|
-
]>;
|
|
32
|
-
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
33
|
-
searchParams: O['searchParams'];
|
|
34
|
-
}> : GetEndpoint<{
|
|
35
|
-
path: ShortenPath<O['path']>;
|
|
36
|
-
schema: schema.Collection<[
|
|
37
|
-
O['schema']
|
|
38
|
-
]>;
|
|
39
|
-
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
40
|
-
searchParams: Record<string, number | string | boolean> | undefined;
|
|
41
|
-
}>;
|
|
42
|
-
/** Get a list of item
|
|
43
|
-
*
|
|
44
|
-
* @see https://dataclient.io/rest/api/createResource#getNextPage
|
|
45
|
-
*/
|
|
46
|
-
getNextPage: 'paginationField' extends keyof O ? PaginationFieldEndpoint<'searchParams' extends keyof O ? GetEndpoint<{
|
|
47
|
-
path: ShortenPath<O['path']>;
|
|
48
|
-
schema: schema.Collection<[
|
|
49
|
-
O['schema']
|
|
50
|
-
]>;
|
|
51
|
-
searchParams: O['searchParams'];
|
|
52
|
-
}> : GetEndpoint<{
|
|
53
|
-
path: ShortenPath<O['path']>;
|
|
54
|
-
schema: schema.Collection<[
|
|
55
|
-
O['schema']
|
|
56
|
-
]>;
|
|
57
|
-
searchParams: Record<string, number | string | boolean> | undefined;
|
|
58
|
-
}>, Exclude<O['paginationField'], undefined>> : undefined;
|
|
59
|
-
/** Create a new item (POST)
|
|
60
|
-
*
|
|
61
|
-
* @see https://resthooks.io/rest/api/createResource#create
|
|
62
|
-
*/
|
|
63
|
-
create: 'searchParams' extends keyof O ? MutateEndpoint<{
|
|
64
|
-
path: ShortenPath<O['path']>;
|
|
65
|
-
schema: schema.Collection<[
|
|
66
|
-
O['schema']
|
|
67
|
-
]>['push'];
|
|
68
|
-
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
69
|
-
searchParams: O['searchParams'];
|
|
70
|
-
}> : MutateEndpoint<{
|
|
71
|
-
path: ShortenPath<O['path']>;
|
|
72
|
-
schema: schema.Collection<[
|
|
73
|
-
O['schema']
|
|
74
|
-
]>['push'];
|
|
75
|
-
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
76
|
-
}>;
|
|
77
|
-
/** Update an item (PUT)
|
|
78
|
-
*
|
|
79
|
-
* @see https://resthooks.io/rest/api/createResource#update
|
|
80
|
-
*/
|
|
81
|
-
update: 'body' extends keyof O ? MutateEndpoint<{
|
|
82
|
-
path: O['path'];
|
|
83
|
-
body: O['body'];
|
|
84
|
-
schema: O['schema'];
|
|
85
|
-
}> : MutateEndpoint<{
|
|
86
|
-
path: O['path'];
|
|
87
|
-
body: Partial<Denormalize<O['schema']>>;
|
|
88
|
-
schema: O['schema'];
|
|
89
|
-
}>;
|
|
90
|
-
/** Update an item (PATCH)
|
|
91
|
-
*
|
|
92
|
-
* @see https://resthooks.io/rest/api/createResource#partialupdate
|
|
93
|
-
*/
|
|
94
|
-
partialUpdate: 'body' extends keyof O ? MutateEndpoint<{
|
|
95
|
-
path: O['path'];
|
|
96
|
-
body: Partial<O['body']>;
|
|
97
|
-
schema: O['schema'];
|
|
98
|
-
}> : MutateEndpoint<{
|
|
99
|
-
path: O['path'];
|
|
100
|
-
body: Partial<Denormalize<O['schema']>>;
|
|
101
|
-
schema: O['schema'];
|
|
102
|
-
}>;
|
|
103
|
-
/** Delete an item (DELETE)
|
|
104
|
-
*
|
|
105
|
-
* @see https://resthooks.io/rest/api/createResource#delete
|
|
106
|
-
*/
|
|
107
|
-
delete: RestTypeNoBody<PathArgs<O['path']>, O['schema'] extends schema.EntityInterface & {
|
|
108
|
-
process: any;
|
|
109
|
-
} ? schema.Invalidate<O['schema']> : O['schema'], undefined, Partial<PathArgs<O['path']>>, {
|
|
110
|
-
path: O['path'];
|
|
111
|
-
}>;
|
|
112
|
-
}
|
|
6
|
+
export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, optimistic, ...extraOptions }: Readonly<O> & ResourceOptions): Resource<O>;
|
|
113
7
|
//# sourceMappingURL=createResource.d.ts.map
|
package/ts4.1/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { default as RestEndpoint } from './RestEndpoint.js';
|
|
2
|
-
export type { GetEndpoint, MutateEndpoint, Defaults, RestGenerics, FetchGet, FetchMutate, RestFetch, RestType, RestInstance, KeyofRestEndpoint, RestEndpointConstructorOptions, AddEndpoint, PaginationFieldEndpoint, } from './RestEndpoint.js';
|
|
2
|
+
export type { GetEndpoint, MutateEndpoint, Defaults, RestGenerics, FetchGet, FetchMutate, RestFetch, RestType, RestInstance, KeyofRestEndpoint, RestEndpointConstructorOptions, AddEndpoint, PaginationFieldEndpoint, PaginationEndpoint, } from './RestEndpoint.js';
|
|
3
3
|
export { default as createResource } from './createResource.js';
|
|
4
|
-
export type { Resource } from './
|
|
4
|
+
export type { Resource } from './resourceTypes.js';
|
|
5
5
|
export type { ResourceOptions, ResourceGenerics } from './resourceTypes.js';
|
|
6
6
|
export { default as hookifyResource } from './hookifyResource.js';
|
|
7
7
|
export type { HookResource, HookableEndpointInterface, } from './hookifyResource.js';
|
package/ts4.1/next/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '../RestEndpoint.js';
|
|
2
2
|
export { default as RestEndpoint } from '../RestEndpoint.js';
|
|
3
3
|
export { default as createResource } from '../createResource.js';
|
|
4
|
-
export type { Resource } from '../
|
|
4
|
+
export type { Resource } from '../resourceTypes.js';
|
|
5
5
|
export type { ResourceOptions, ResourceGenerics } from '../resourceTypes.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EndpointInterface, EndpointToFunction } from '@data-client/endpoint';
|
|
2
|
+
import type { ResourcePath } from './pathTypes.js';
|
|
3
|
+
import type { ResourceExtension, ResourceEndpointExtensions, CustomResource, ExtendedResource } from './resourceExtensionTypes.js';
|
|
4
|
+
import type { ResourceGenerics, ResourceInterface } from './resourceTypes.js';
|
|
5
|
+
import type { PartialRestGenerics, RestEndpointExtendOptions, RestExtendedEndpoint, RestInstanceBase } from './RestEndpoint.js';
|
|
6
|
+
export interface Extendable<O extends ResourceGenerics = {
|
|
7
|
+
path: ResourcePath;
|
|
8
|
+
schema: any;
|
|
9
|
+
}> {
|
|
10
|
+
extend<R extends {
|
|
11
|
+
[K in ExtendKey]: RestInstanceBase;
|
|
12
|
+
}, ExtendKey extends Exclude<Extract<keyof R, string>, 'extend'>, ExtendOptions extends PartialRestGenerics | {}>(this: R, key: ExtendKey, options: Readonly<RestEndpointExtendOptions<ExtendOptions, R[ExtendKey], EndpointToFunction<R[ExtendKey]>> & ExtendOptions>): ResourceExtension<R, ExtendKey, ExtendOptions>;
|
|
13
|
+
extend<R extends {
|
|
14
|
+
get: RestInstanceBase;
|
|
15
|
+
}, ExtendKey extends string, ExtendOptions extends PartialRestGenerics | {}>(this: R, key: ExtendKey, options: Readonly<RestEndpointExtendOptions<ExtendOptions, R['get'], EndpointToFunction<R['get']>> & ExtendOptions>): R & {
|
|
16
|
+
[key in ExtendKey]: RestExtendedEndpoint<ExtendOptions, R['get']>;
|
|
17
|
+
};
|
|
18
|
+
extend<R extends ResourceInterface, Get extends PartialRestGenerics = any, GetList extends PartialRestGenerics = any, Update extends PartialRestGenerics = any, PartialUpdate extends PartialRestGenerics = any, Delete extends PartialRestGenerics = any>(this: R, options: ResourceEndpointExtensions<R, Get, GetList, Update, PartialUpdate, Delete>): CustomResource<R, O, Get, GetList, Update, PartialUpdate, Delete>;
|
|
19
|
+
extend<R extends ResourceInterface, T extends Record<string, EndpointInterface>>(this: R, extender: (baseResource: R) => T): ExtendedResource<R, T>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=resourceExtendable.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { EndpointInterface, EndpointToFunction } from '@data-client/endpoint';
|
|
2
|
+
import { OptionsToFunction } from './OptionsToFunction.js';
|
|
3
|
+
import type { ResourcePath } from './pathTypes.js';
|
|
4
|
+
import { Extendable } from './resourceExtendable.js';
|
|
5
|
+
import { ResourceGenerics, ResourceInterface } from './resourceTypes.js';
|
|
6
|
+
import type { PartialRestGenerics, RestExtendedEndpoint, RestInstanceBase, RestEndpointOptions } from './RestEndpoint.js';
|
|
7
|
+
export type ResourceExtension<R extends {
|
|
8
|
+
[K in ExtendKey]: RestInstanceBase;
|
|
9
|
+
}, ExtendKey extends Exclude<Extract<keyof R, string>, 'extend'>, O extends PartialRestGenerics | {}> = {
|
|
10
|
+
[K in keyof R]: K extends ExtendKey ? RestExtendedEndpoint<O, R[K]> : R[K];
|
|
11
|
+
};
|
|
12
|
+
/** Resource with individual endpoints customized
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export interface CustomResource<R extends ResourceInterface, O extends ResourceGenerics = {
|
|
16
|
+
path: ResourcePath;
|
|
17
|
+
schema: any;
|
|
18
|
+
}, Get extends PartialRestGenerics | {} = any, GetList extends PartialRestGenerics | {} = any, Update extends PartialRestGenerics | {} = any, PartialUpdate extends PartialRestGenerics | {} = any, Delete extends PartialRestGenerics | {} = any> extends Extendable<O> {
|
|
19
|
+
get: unknown extends Get ? R['get'] : RestExtendedEndpoint<Get, R['get']>;
|
|
20
|
+
getList: unknown extends GetList ? R['getList'] : RestExtendedEndpoint<GetList, R['getList']>;
|
|
21
|
+
update: unknown extends Update ? R['update'] : RestExtendedEndpoint<Update, R['update']>;
|
|
22
|
+
partialUpdate: unknown extends PartialUpdate ? R['partialUpdate'] : RestExtendedEndpoint<PartialUpdate, R['partialUpdate']>;
|
|
23
|
+
delete: unknown extends Delete ? R['delete'] : RestExtendedEndpoint<Delete, R['delete']>;
|
|
24
|
+
}
|
|
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 PartialRestGenerics = any, GetList extends PartialRestGenerics = any, Update extends PartialRestGenerics = any, PartialUpdate extends PartialRestGenerics = any, Delete extends PartialRestGenerics = any> {
|
|
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>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=resourceExtensionTypes.d.ts.map
|