@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
package/ts4.1/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
|
package/ts4.0/deleteme.d.ts
DELETED
|
File without changes
|
package/ts4.1/deleteme.d.ts
DELETED
|
File without changes
|