@warp-drive/utilities 5.9.0-alpha.2 → 5.9.0-alpha.21
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/cjs-dist/string.cjs +448 -0
- package/cjs-dist/string.cjs.map +1 -0
- package/declarations/-private.d.ts +12 -1
- package/declarations/-private.d.ts.map +1 -0
- package/declarations/active-record.d.ts +260 -3
- package/declarations/active-record.d.ts.map +1 -0
- package/declarations/derivations.d.ts +26 -23
- package/declarations/derivations.d.ts.map +1 -0
- package/declarations/handlers.d.ts +282 -9
- package/declarations/handlers.d.ts.map +1 -0
- package/declarations/index-BeMAuqgZ.d.ts +462 -0
- package/declarations/index-BeMAuqgZ.d.ts.map +1 -0
- package/declarations/index.d.ts +2 -208
- package/declarations/json-api.d.ts +496 -5
- package/declarations/json-api.d.ts.map +1 -0
- package/declarations/rest.d.ts +258 -3
- package/declarations/rest.d.ts.map +1 -0
- package/declarations/string.d.ts +164 -13
- package/declarations/string.d.ts.map +1 -0
- package/dist/-private.js +2 -6
- package/dist/active-record.js +254 -379
- package/dist/active-record.js.map +1 -0
- package/dist/builder-utils-BkXwUT0x.js +16 -0
- package/dist/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/derivations.js +26 -26
- package/dist/derivations.js.map +1 -0
- package/dist/handlers.js +240 -283
- package/dist/handlers.js.map +1 -0
- package/dist/index.js +357 -335
- package/dist/index.js.map +1 -0
- package/dist/inflections-DzBsjJqj.js +80 -0
- package/dist/inflections-DzBsjJqj.js.map +1 -0
- package/dist/json-api.js +470 -706
- package/dist/json-api.js.map +1 -0
- package/dist/rest.js +254 -377
- package/dist/rest.js.map +1 -0
- package/dist/string-CWmAluxh.js +290 -0
- package/dist/string-CWmAluxh.js.map +1 -0
- package/dist/string.js +2 -427
- package/dist/unpkg/dev/-private.js +2 -6
- package/dist/unpkg/dev/active-record.js +253 -378
- package/dist/unpkg/dev/active-record.js.map +1 -0
- package/dist/unpkg/dev/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/dev/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/dev/derivations.js +26 -26
- package/dist/unpkg/dev/derivations.js.map +1 -0
- package/dist/unpkg/dev/handlers.js +238 -282
- package/dist/unpkg/dev/handlers.js.map +1 -0
- package/dist/unpkg/dev/index.js +356 -336
- package/dist/unpkg/dev/index.js.map +1 -0
- package/dist/unpkg/dev/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/dev/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/dev/json-api.js +469 -706
- package/dist/unpkg/dev/json-api.js.map +1 -0
- package/dist/unpkg/dev/rest.js +253 -376
- package/dist/unpkg/dev/rest.js.map +1 -0
- package/dist/unpkg/dev/string-j4ur-TDs.js +289 -0
- package/dist/unpkg/dev/string-j4ur-TDs.js.map +1 -0
- package/dist/unpkg/dev/string.js +3 -1
- package/dist/unpkg/dev-deprecated/-private.js +2 -6
- package/dist/unpkg/dev-deprecated/active-record.js +253 -378
- package/dist/unpkg/dev-deprecated/active-record.js.map +1 -0
- package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/dev-deprecated/derivations.js +26 -26
- package/dist/unpkg/dev-deprecated/derivations.js.map +1 -0
- package/dist/unpkg/dev-deprecated/handlers.js +238 -282
- package/dist/unpkg/dev-deprecated/handlers.js.map +1 -0
- package/dist/unpkg/dev-deprecated/index.js +356 -336
- package/dist/unpkg/dev-deprecated/index.js.map +1 -0
- package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/dev-deprecated/json-api.js +469 -706
- package/dist/unpkg/dev-deprecated/json-api.js.map +1 -0
- package/dist/unpkg/dev-deprecated/rest.js +253 -376
- package/dist/unpkg/dev-deprecated/rest.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js +289 -0
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string.js +3 -1
- package/dist/unpkg/prod/-private.js +2 -6
- package/dist/unpkg/prod/active-record.js +236 -351
- package/dist/unpkg/prod/active-record.js.map +1 -0
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/prod/derivations.js +26 -26
- package/dist/unpkg/prod/derivations.js.map +1 -0
- package/dist/unpkg/prod/handlers.js +231 -272
- package/dist/unpkg/prod/handlers.js.map +1 -0
- package/dist/unpkg/prod/index.js +265 -215
- package/dist/unpkg/prod/index.js.map +1 -0
- package/dist/unpkg/prod/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/prod/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/prod/json-api.js +446 -669
- package/dist/unpkg/prod/json-api.js.map +1 -0
- package/dist/unpkg/prod/rest.js +236 -349
- package/dist/unpkg/prod/rest.js.map +1 -0
- package/dist/unpkg/prod/string-T1ahjLdj.js +283 -0
- package/dist/unpkg/prod/string-T1ahjLdj.js.map +1 -0
- package/dist/unpkg/prod/string.js +3 -1
- package/dist/unpkg/prod-deprecated/-private.js +2 -6
- package/dist/unpkg/prod-deprecated/active-record.js +236 -351
- package/dist/unpkg/prod-deprecated/active-record.js.map +1 -0
- package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/prod-deprecated/derivations.js +26 -26
- package/dist/unpkg/prod-deprecated/derivations.js.map +1 -0
- package/dist/unpkg/prod-deprecated/handlers.js +231 -272
- package/dist/unpkg/prod-deprecated/handlers.js.map +1 -0
- package/dist/unpkg/prod-deprecated/index.js +265 -215
- package/dist/unpkg/prod-deprecated/index.js.map +1 -0
- package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/prod-deprecated/json-api.js +446 -669
- package/dist/unpkg/prod-deprecated/json-api.js.map +1 -0
- package/dist/unpkg/prod-deprecated/rest.js +236 -349
- package/dist/unpkg/prod-deprecated/rest.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js +283 -0
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string.js +3 -1
- package/package.json +11 -10
- package/declarations/-private/active-record/find-record.d.ts +0 -64
- package/declarations/-private/active-record/query.d.ts +0 -53
- package/declarations/-private/active-record/save-record.d.ts +0 -146
- package/declarations/-private/builder-utils.d.ts +0 -4
- package/declarations/-private/handlers/auto-compress.d.ts +0 -158
- package/declarations/-private/handlers/gated.d.ts +0 -19
- package/declarations/-private/handlers/meta-doc.d.ts +0 -47
- package/declarations/-private/handlers/utils.d.ts +0 -41
- package/declarations/-private/json-api/-utils.d.ts +0 -109
- package/declarations/-private/json-api/find-record.d.ts +0 -84
- package/declarations/-private/json-api/query.d.ts +0 -100
- package/declarations/-private/json-api/save-record.d.ts +0 -228
- package/declarations/-private/json-api/serialize.d.ts +0 -70
- package/declarations/-private/rest/find-record.d.ts +0 -62
- package/declarations/-private/rest/query.d.ts +0 -53
- package/declarations/-private/rest/save-record.d.ts +0 -146
- package/declarations/-private/string/inflect.d.ts +0 -82
- package/declarations/-private/string/inflections.d.ts +0 -9
- package/declarations/-private/string/transform.d.ts +0 -77
- package/dist/builder-utils-Donkk-BZ.js +0 -22
- package/dist/inflect-BSG696t-.js +0 -344
- package/dist/string.cjs +0 -430
- package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/dev/inflect-BEv8WqY1.js +0 -343
- package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +0 -343
- package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/prod/inflect-Dh9dyEYx.js +0 -333
- package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +0 -333
|
@@ -1,5 +1,496 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { t as BuildURLConfig } from "./index-BeMAuqgZ.js";
|
|
2
|
+
import { ReactiveDataDocument } from "@warp-drive/core/reactive";
|
|
3
|
+
import { TypeFromInstance, TypedRecordInstance } from "@warp-drive/core/types/record";
|
|
4
|
+
import { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, FindRecordOptions, FindRecordRequestOptions, PostQueryRequestOptions, QueryRequestOptions, RemotelyAccessibleIdentifier, UpdateRequestOptions } from "@warp-drive/core/types/request";
|
|
5
|
+
import { QueryParamsSource } from "@warp-drive/core/types/params";
|
|
6
|
+
import { ReactiveDataDocument as ReactiveDataDocument$1 } from "@warp-drive/core/reactive.js";
|
|
7
|
+
import { Cache } from "@warp-drive/core/types/cache";
|
|
8
|
+
import { ResourceKey } from "@warp-drive/core/types/identifier";
|
|
9
|
+
import { Value } from "@warp-drive/core/types/json/raw";
|
|
10
|
+
import { InnerRelationshipDocument, ResourceObject } from "@warp-drive/core/types/spec/json-api-raw";
|
|
11
|
+
//#region src/-private/json-api/find-record.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Builds request options to fetch a single resource by a known id or identifier
|
|
14
|
+
* configured for the url and header expectations of most JSON:API APIs.
|
|
15
|
+
*
|
|
16
|
+
* :::tabs
|
|
17
|
+
*
|
|
18
|
+
* == Basic Usage
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { findRecord } from '@warp-drive/utilities/json-api';
|
|
22
|
+
* import type { Person } from '#/data/types';
|
|
23
|
+
*
|
|
24
|
+
* const result = await store.request(
|
|
25
|
+
* findRecord<Person>('person', '1')
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* == With Options
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { findRecord } from '@warp-drive/utilities/json-api';
|
|
33
|
+
* import type { Person } from '#/data/types';
|
|
34
|
+
*
|
|
35
|
+
* const data = await store.request(
|
|
36
|
+
* findRecord<Person>(
|
|
37
|
+
* 'person', '1',
|
|
38
|
+
* { include: ['pets', 'friends'] }
|
|
39
|
+
* )
|
|
40
|
+
* );
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* == With an Identifier
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { findRecord } from '@warp-drive/utilities/json-api';
|
|
47
|
+
* import type { Person } from '#/data/types';
|
|
48
|
+
*
|
|
49
|
+
* const data = await store.request(
|
|
50
|
+
* findRecord<Person>(
|
|
51
|
+
* { type: 'person', id: '1' },
|
|
52
|
+
* { include: ['pets', 'friends'] }
|
|
53
|
+
* )
|
|
54
|
+
* );
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* :::
|
|
58
|
+
*
|
|
59
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
60
|
+
*
|
|
61
|
+
* The following options are supported:
|
|
62
|
+
*
|
|
63
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
64
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
65
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
66
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
67
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
68
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
69
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
70
|
+
* defaulting to `false` if none is configured.
|
|
71
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { findRecord } from '@warp-drive/utilities/json-api';
|
|
75
|
+
*
|
|
76
|
+
* const data = await store.request(
|
|
77
|
+
* findRecord(
|
|
78
|
+
* 'person', '1',
|
|
79
|
+
* { include: ['pets', 'friends'] },
|
|
80
|
+
* { namespace: 'api/v2' }
|
|
81
|
+
* )
|
|
82
|
+
* );
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
88
|
+
declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
89
|
+
declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
90
|
+
declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/-private/json-api/query.d.ts
|
|
93
|
+
/**
|
|
94
|
+
* Builds request options to query for resources, usually by a primary
|
|
95
|
+
* type, configured for the url and header expectations of most JSON:API APIs.
|
|
96
|
+
*
|
|
97
|
+
* The key difference between this and `postQuery` is that this method will send the query
|
|
98
|
+
* as query params in the url of a "GET" request instead of as the JSON body of a "POST"
|
|
99
|
+
* request.
|
|
100
|
+
*
|
|
101
|
+
* **Basic Usage**
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { query } from '@warp-drive/utilities/json-api';
|
|
105
|
+
*
|
|
106
|
+
* const data = await store.request(query('person'));
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* **With Query Params**
|
|
110
|
+
*
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { query } from '@warp-drive/utilities/json-api';
|
|
113
|
+
*
|
|
114
|
+
* const options = query('person', { include: ['pets', 'friends'] });
|
|
115
|
+
* const data = await store.request(options);
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
119
|
+
*
|
|
120
|
+
* The following options are supported:
|
|
121
|
+
*
|
|
122
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
123
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
124
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
125
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
126
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
127
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
128
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
129
|
+
* defaulting to `false` if none is configured.
|
|
130
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
131
|
+
*
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { query } from '@warp-drive/utilities/json-api';
|
|
134
|
+
*
|
|
135
|
+
* const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
|
|
136
|
+
* const data = await store.request(options);
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
declare function query<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
142
|
+
declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
143
|
+
/**
|
|
144
|
+
* Builds request options to query for resources, usually by a primary
|
|
145
|
+
* type, configured for the url and header expectations of most JSON:API APIs.
|
|
146
|
+
*
|
|
147
|
+
* The key difference between this and `query` is that this method will send the query
|
|
148
|
+
* as the JSON body of a "POST" request instead of as query params in the url of a "GET"
|
|
149
|
+
* request.
|
|
150
|
+
*
|
|
151
|
+
* A CacheKey is generated from the url and query params, and used to cache the response
|
|
152
|
+
* in the store.
|
|
153
|
+
*
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { postQuery } from '@warp-drive/utilities/json-api';
|
|
156
|
+
*
|
|
157
|
+
* const options = postQuery('person', { include: ['pets', 'friends'] });
|
|
158
|
+
* const data = await store.request(options);
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
162
|
+
*
|
|
163
|
+
* The following options are supported:
|
|
164
|
+
*
|
|
165
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
166
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
167
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
168
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
169
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
170
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
171
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
172
|
+
* defaulting to `false` if none is configured.
|
|
173
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
174
|
+
*
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { postQuery } from '@warp-drive/utilities/json-api';
|
|
177
|
+
*
|
|
178
|
+
* const options = postQuery('person', { include: ['pets', 'friends'] }, { reload: true });
|
|
179
|
+
* const data = await store.request(options);
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @public
|
|
183
|
+
* @param type - the name of the resource type to query
|
|
184
|
+
* @param query - the query params to send with the request
|
|
185
|
+
* @param options - options to modify the request behavior
|
|
186
|
+
*/
|
|
187
|
+
declare function postQuery<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
188
|
+
declare function postQuery(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions;
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/-private/json-api/save-record.d.ts
|
|
191
|
+
/**
|
|
192
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Request Body**
|
|
193
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
194
|
+
* desired and correctly formatted data is sent with the request.
|
|
195
|
+
* :::
|
|
196
|
+
*
|
|
197
|
+
* Builds request options to delete record for resources,
|
|
198
|
+
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
199
|
+
*
|
|
200
|
+
* **Basic Usage**
|
|
201
|
+
*
|
|
202
|
+
* ```ts
|
|
203
|
+
* import { deleteRecord } from '@warp-drive/utilities/json-api';
|
|
204
|
+
*
|
|
205
|
+
* const person = store.peekRecord('person', '1');
|
|
206
|
+
*
|
|
207
|
+
* // mark record as deleted
|
|
208
|
+
* store.deleteRecord(person);
|
|
209
|
+
*
|
|
210
|
+
* // persist deletion
|
|
211
|
+
* const data = await store.request(deleteRecord(person));
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
215
|
+
*
|
|
216
|
+
* The following options are supported:
|
|
217
|
+
*
|
|
218
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
219
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
220
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
221
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
222
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
223
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
224
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
225
|
+
* defaulting to `false` if none is configured.
|
|
226
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
227
|
+
*
|
|
228
|
+
* ```ts
|
|
229
|
+
* import { deleteRecord } from '@warp-drive/utilities/json-api';
|
|
230
|
+
*
|
|
231
|
+
* const person = store.peekRecord('person', '1');
|
|
232
|
+
*
|
|
233
|
+
* // mark record as deleted
|
|
234
|
+
* store.deleteRecord(person);
|
|
235
|
+
*
|
|
236
|
+
* // persist deletion
|
|
237
|
+
* const options = deleteRecord(person, { namespace: 'api/v1' });
|
|
238
|
+
* const data = await store.request(options);
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* @public
|
|
242
|
+
* @param record
|
|
243
|
+
* @param options
|
|
244
|
+
*/
|
|
245
|
+
declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
|
|
246
|
+
declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
|
|
247
|
+
/**
|
|
248
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
|
|
249
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
250
|
+
* desired and correctly formatted data is sent with the request.
|
|
251
|
+
* :::
|
|
252
|
+
*
|
|
253
|
+
* Builds request options to create new record for resources,
|
|
254
|
+
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
255
|
+
*
|
|
256
|
+
* **Basic Usage**
|
|
257
|
+
*
|
|
258
|
+
* ```ts
|
|
259
|
+
* import { cacheKeyFor } from '@warp-drive/core';
|
|
260
|
+
* import { createRecord } from '@warp-drive/utilities/json-api';
|
|
261
|
+
* import type { Person } from '#/data/types';
|
|
262
|
+
*
|
|
263
|
+
* const person = store.createRecord<Person>('person', { name: 'Ted' });
|
|
264
|
+
* const init = createRecord(person);
|
|
265
|
+
* init.body = JSON.stringify(
|
|
266
|
+
* {
|
|
267
|
+
* // it's likely you will want to transform this data
|
|
268
|
+
* // somewhat
|
|
269
|
+
* data: store.cache.peek(cacheKeyFor(person))
|
|
270
|
+
* }
|
|
271
|
+
* );
|
|
272
|
+
* const data = await store.request(init);
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
276
|
+
*
|
|
277
|
+
* The following options are supported:
|
|
278
|
+
*
|
|
279
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
280
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
281
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
282
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
283
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
284
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
285
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
286
|
+
* defaulting to `false` if none is configured.
|
|
287
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
288
|
+
*
|
|
289
|
+
* ```ts
|
|
290
|
+
* import { createRecord } from '@warp-drive/utilities/json-api';
|
|
291
|
+
*
|
|
292
|
+
* const person = store.createRecord('person', { name: 'Ted' });
|
|
293
|
+
* const options = createRecord(person, { namespace: 'api/v1' });
|
|
294
|
+
* const data = await store.request(options);
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @public
|
|
298
|
+
* @param record
|
|
299
|
+
* @param options
|
|
300
|
+
*/
|
|
301
|
+
declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
|
|
302
|
+
declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
|
|
303
|
+
/**
|
|
304
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
|
|
305
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
306
|
+
* desired and correctly formatted data is sent with the request.
|
|
307
|
+
* :::
|
|
308
|
+
*
|
|
309
|
+
* Builds request options to update existing record for resources,
|
|
310
|
+
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
311
|
+
*
|
|
312
|
+
* **Example Usage**
|
|
313
|
+
*
|
|
314
|
+
* ```ts
|
|
315
|
+
* import { cacheKeyFor } from '@warp-drive/core';
|
|
316
|
+
* import { updateRecord } from '@warp-drive/utilities/json-api';
|
|
317
|
+
* import type { EditablePerson } from '#/data/types';
|
|
318
|
+
*
|
|
319
|
+
* const mutable = await checkout<EditablePerson>(person);
|
|
320
|
+
* mutable.name = 'Chris';
|
|
321
|
+
* const init = updateRecord(mutable);
|
|
322
|
+
*
|
|
323
|
+
* init.body = JSON.stringify(
|
|
324
|
+
* // it's likely you will want to transform this data
|
|
325
|
+
* // somewhat, or serialize only specific properties instead
|
|
326
|
+
* serializePatch(store.cache, cacheKeyFor(mutable))
|
|
327
|
+
* );
|
|
328
|
+
* const data = await store.request(init);
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
*
|
|
332
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
333
|
+
*
|
|
334
|
+
* The following options are supported:
|
|
335
|
+
*
|
|
336
|
+
* - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
|
|
337
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
338
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
339
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
340
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
341
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
342
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
343
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
344
|
+
* defaulting to `false` if none is configured.
|
|
345
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
346
|
+
*
|
|
347
|
+
* ```ts
|
|
348
|
+
* import { updateRecord } from '@warp-drive/utilities/json-api';
|
|
349
|
+
*
|
|
350
|
+
* const person = store.peekRecord('person', '1');
|
|
351
|
+
* person.name = 'Chris';
|
|
352
|
+
* const options = updateRecord(person, { patch: true });
|
|
353
|
+
* const data = await store.request(options);
|
|
354
|
+
* ```
|
|
355
|
+
*
|
|
356
|
+
* @public
|
|
357
|
+
* @param record
|
|
358
|
+
* @param options
|
|
359
|
+
*/
|
|
360
|
+
declare function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(record: T, options?: ConstrainedRequestOptions & {
|
|
361
|
+
patch?: boolean;
|
|
362
|
+
}): UpdateRequestOptions<ReactiveDataDocument$1<RT>, T>;
|
|
363
|
+
declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
364
|
+
patch?: boolean;
|
|
365
|
+
}): UpdateRequestOptions;
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/-private/json-api/serialize.d.ts
|
|
368
|
+
type ChangedRelationshipData = InnerRelationshipDocument;
|
|
369
|
+
type JsonApiResourcePatch = {
|
|
370
|
+
type: string;
|
|
371
|
+
id: string;
|
|
372
|
+
attributes?: Record<string, Value>;
|
|
373
|
+
relationships?: Record<string, ChangedRelationshipData>;
|
|
374
|
+
} | {
|
|
375
|
+
type: string;
|
|
376
|
+
id: null;
|
|
377
|
+
lid: string;
|
|
378
|
+
attributes?: Record<string, Value>;
|
|
379
|
+
relationships?: Record<string, ChangedRelationshipData>;
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
|
|
383
|
+
*
|
|
384
|
+
* While this may come as a surprise, they are intended to serialize cache state for more
|
|
385
|
+
* generalized usage. {json:api} has a large variance in acceptable shapes, and only your
|
|
386
|
+
* app can ensure that the body is correctly formatted and contains all necessary data.
|
|
387
|
+
* :::
|
|
388
|
+
*
|
|
389
|
+
* Serializes the current state of a resource or array of resources for use with POST or PUT requests.
|
|
390
|
+
*
|
|
391
|
+
* @public
|
|
392
|
+
* @param cache - the cache to serialize the resource(s) from
|
|
393
|
+
* @param identifiers - the resource(s) to serialize
|
|
394
|
+
* @return an object with a `data` property containing the serialized resource(s)
|
|
395
|
+
*/
|
|
396
|
+
declare function serializeResources(cache: Cache, identifiers: ResourceKey): {
|
|
397
|
+
/**
|
|
398
|
+
* The serialized resource.
|
|
399
|
+
*/
|
|
400
|
+
data: ResourceObject;
|
|
401
|
+
};
|
|
402
|
+
declare function serializeResources(cache: Cache, identifiers: ResourceKey[]): {
|
|
403
|
+
/**
|
|
404
|
+
* The serialized resources.
|
|
405
|
+
*/
|
|
406
|
+
data: ResourceObject[];
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
|
|
410
|
+
*
|
|
411
|
+
* While this may come as a surprise, they are intended to serialize cache state for more
|
|
412
|
+
* generalized usage. {json:api} has a large variance in acceptable shapes, and only your
|
|
413
|
+
* app can ensure that the body is correctly formatted and contains all necessary data.
|
|
414
|
+
* :::
|
|
415
|
+
*
|
|
416
|
+
* Serializes changes to a resource. Useful for use with building bodies for PATCH requests.
|
|
417
|
+
*
|
|
418
|
+
* Only attributes which are changed are serialized.
|
|
419
|
+
* Only relationships which are changed are serialized.
|
|
420
|
+
*
|
|
421
|
+
* Collection relationships serialize the collection as a whole.
|
|
422
|
+
*
|
|
423
|
+
* If you would like to serialize updates to a collection more granularly
|
|
424
|
+
* (for instance, as operations) request the diff from the store and
|
|
425
|
+
* serialize as desired:
|
|
426
|
+
*
|
|
427
|
+
* ```ts
|
|
428
|
+
* const relationshipDiffMap = cache.changedRelationships(identifier);
|
|
429
|
+
* ```
|
|
430
|
+
*
|
|
431
|
+
* @public
|
|
432
|
+
* @param cache - the cache to serialize the resource's changes from
|
|
433
|
+
* @param identifier - the resource whose changes should be serialized
|
|
434
|
+
* @return an object with a `data` property containing the serialized resource patch
|
|
435
|
+
*/
|
|
436
|
+
declare function serializePatch(cache: Cache, identifier: ResourceKey): {
|
|
437
|
+
/**
|
|
438
|
+
* The serialized resource patch.
|
|
439
|
+
*/
|
|
440
|
+
data: JsonApiResourcePatch;
|
|
441
|
+
};
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/-private/json-api/-utils.d.ts
|
|
444
|
+
interface JSONAPIConfig extends BuildURLConfig {
|
|
445
|
+
profiles?: {
|
|
446
|
+
pagination?: string;
|
|
447
|
+
[key: string]: string | undefined;
|
|
448
|
+
};
|
|
449
|
+
extensions?: {
|
|
450
|
+
atomic?: string;
|
|
451
|
+
[key: string]: string | undefined;
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Allows setting extensions and profiles to be used in the `Accept` header.
|
|
456
|
+
*
|
|
457
|
+
* Extensions and profiles are keyed by their namespace with the value being
|
|
458
|
+
* their URI.
|
|
459
|
+
*
|
|
460
|
+
* Example:
|
|
461
|
+
*
|
|
462
|
+
* ```ts
|
|
463
|
+
* setBuildURLConfig({
|
|
464
|
+
* extensions: {
|
|
465
|
+
* atomic: 'https://jsonapi.org/ext/atomic'
|
|
466
|
+
* },
|
|
467
|
+
* profiles: {
|
|
468
|
+
* pagination: 'https://jsonapi.org/profiles/ethanresnick/cursor-pagination'
|
|
469
|
+
* }
|
|
470
|
+
* });
|
|
471
|
+
* ```
|
|
472
|
+
*
|
|
473
|
+
* This also sets the global configuration for `buildBaseURL`
|
|
474
|
+
* for host and namespace values for the global coniguration
|
|
475
|
+
* done via `import { setBuildURLConfig } from '@warp-drive/utilities';`
|
|
476
|
+
*
|
|
477
|
+
* These values may still be overridden by passing
|
|
478
|
+
* them to buildBaseURL directly.
|
|
479
|
+
*
|
|
480
|
+
* This method may be called as many times as needed
|
|
481
|
+
*
|
|
482
|
+
* ```ts
|
|
483
|
+
* type BuildURLConfig = {
|
|
484
|
+
* host: string;
|
|
485
|
+
* namespace: string'
|
|
486
|
+
* }
|
|
487
|
+
* ```
|
|
488
|
+
*
|
|
489
|
+
* @public
|
|
490
|
+
* @param {BuildURLConfig} config
|
|
491
|
+
* @return {void}
|
|
492
|
+
*/
|
|
493
|
+
declare function setBuildURLConfig(config: JSONAPIConfig): void;
|
|
494
|
+
//#endregion
|
|
495
|
+
export { createRecord, deleteRecord, findRecord, postQuery, query, serializePatch, serializeResources, setBuildURLConfig, updateRecord };
|
|
496
|
+
//# sourceMappingURL=json-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-api.d.ts","names":[],"sources":["../src/-private/json-api/find-record.ts","../src/-private/json-api/query.ts","../src/-private/json-api/save-record.ts","../src/-private/json-api/serialize.ts","../src/-private/json-api/-utils.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwFgB,WAAW,GACzB,YAAY,6BAA6B,iBAAiB,KAC1D,UAAU,oBACT,yBAAyB,qBAAqB,IAAI;iBACrC,WACd,YAAY,8BACZ,UAAU,oBACT;iBACa,WAAW,GACzB,MAAM,iBAAiB,IACvB,YACA,UAAU,oBACT,yBAAyB,qBAAqB,IAAI;iBACrC,WAAW,cAAc,YAAY,UAAU,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCvCnE,MAAM,UAAU,qBAC9B,MAAM,iBAAiB,IACvB,QAAQ,mBACR,UAAU,4BACT,oBAAoB,qBAAqB;iBAC5B,MACd,cACA,QAAQ,mBACR,UAAU,4BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0Ea,UAAU,GACxB,MAAM,iBAAiB,IACvB,QAAQ,mBACR,UAAU,4BACT,wBAAwB,qBAAqB;iBAChC,UACd,cACA,QAAQ,mBACR,UAAU,4BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBC1Ea,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;iBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoFpE,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;iBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsFpE,aAAa,UAAU,qBAAqB,WAAW,sBAAsB,GAC3F,QAAQ,GACR,UAAU;EAA8B;IACvC,qBAAqB,uBAAqB,KAAK;iBAClC,aACd,iBACA,UAAU;EAA8B;IACvC;;;KC5PE,0BAA0B;KAEnB;EAEN;EACA;EACA,aAAa,eAAe;EAC5B,gBAAgB,eAAe;;EAG/B;EACA;EACA;EACA,aAAa,eAAe;EAC5B,gBAAgB,eAAe;;;;;;;;;;;;;;;;;iBAkBrB,mBACd,OAAO,OACP,aAAa;;;;EAKb,MAAM;;iBAEQ,mBACd,OAAO,OACP,aAAa;;;;EAKb,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqGQ,eACd,OAAO,OACP,YAAY;;;;EAMZ,MAAM;;;;UC/JS,sBAAsB;EACrC;IACE;;;EAGF;IACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDY,kBAAkB,QAAQ"}
|