@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
package/dist/unpkg/prod/rest.js
CHANGED
|
@@ -1,364 +1,251 @@
|
|
|
1
|
-
import { buildBaseURL, buildQueryParams } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { recordIdentifierFor } from
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Builds request options to fetch a single resource by a known id or identifier
|
|
8
|
-
* configured for the url and header expectations of most REST APIs.
|
|
9
|
-
*
|
|
10
|
-
* **Basic Usage**
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { findRecord } from '@warp-drive/utilities/rest';
|
|
14
|
-
*
|
|
15
|
-
* const data = await store.request(findRecord('person', '1'));
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* **With Options**
|
|
19
|
-
*
|
|
20
|
-
* ```ts
|
|
21
|
-
* import { findRecord } from '@warp-drive/utilities/rest';
|
|
22
|
-
*
|
|
23
|
-
* const options = findRecord('person', '1', { include: ['pets', 'friends'] });
|
|
24
|
-
* const data = await store.request(options);
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* **With an Identifier**
|
|
28
|
-
*
|
|
29
|
-
* ```ts
|
|
30
|
-
* import { findRecord } from '@warp-drive/utilities/rest';
|
|
31
|
-
*
|
|
32
|
-
* const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });
|
|
33
|
-
* const data = await store.request(options);
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* **Supplying Options to Modify the Request Behavior**
|
|
37
|
-
*
|
|
38
|
-
* The following options are supported:
|
|
39
|
-
*
|
|
40
|
-
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
41
|
-
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
42
|
-
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
|
|
43
|
-
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
44
|
-
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
45
|
-
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
46
|
-
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
47
|
-
* defaulting to `false` if none is configured.
|
|
48
|
-
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
49
|
-
*
|
|
50
|
-
* ```ts
|
|
51
|
-
* import { findRecord } from '@warp-drive/utilities/rest';
|
|
52
|
-
*
|
|
53
|
-
* const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
|
|
54
|
-
* const data = await store.request(options);
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
1
|
+
import { buildBaseURL, buildQueryParams } from "./index.js";
|
|
2
|
+
import { f as camelize, s as pluralize } from "./string-T1ahjLdj.js";
|
|
3
|
+
import { n as extractCacheOptions, t as copyForwardUrlOptions } from "./builder-utils-BkXwUT0x.js";
|
|
4
|
+
import { recordIdentifierFor } from "@warp-drive/core";
|
|
59
5
|
|
|
6
|
+
//#region src/-private/rest/find-record.ts
|
|
60
7
|
function findRecord(arg1, arg2, arg3) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
records: [identifier]
|
|
85
|
-
};
|
|
8
|
+
const identifier = typeof arg1 === "string" ? {
|
|
9
|
+
type: arg1,
|
|
10
|
+
id: arg2
|
|
11
|
+
} : arg1;
|
|
12
|
+
const options = (typeof arg1 === "string" ? arg3 : arg2) || {};
|
|
13
|
+
const cacheOptions = extractCacheOptions(options);
|
|
14
|
+
const urlOptions = {
|
|
15
|
+
identifier,
|
|
16
|
+
op: "findRecord",
|
|
17
|
+
resourcePath: pluralize(camelize(identifier.type))
|
|
18
|
+
};
|
|
19
|
+
copyForwardUrlOptions(urlOptions, options);
|
|
20
|
+
const url = buildBaseURL(urlOptions);
|
|
21
|
+
const headers = new Headers();
|
|
22
|
+
headers.append("Accept", "application/json;charset=utf-8");
|
|
23
|
+
return {
|
|
24
|
+
url: options.include?.length ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}` : url,
|
|
25
|
+
method: "GET",
|
|
26
|
+
headers,
|
|
27
|
+
cacheOptions,
|
|
28
|
+
op: "findRecord",
|
|
29
|
+
records: [identifier]
|
|
30
|
+
};
|
|
86
31
|
}
|
|
87
32
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
* ```
|
|
110
|
-
*
|
|
111
|
-
* **Supplying Options to Modify the Request Behavior**
|
|
112
|
-
*
|
|
113
|
-
* The following options are supported:
|
|
114
|
-
*
|
|
115
|
-
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
116
|
-
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
117
|
-
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
|
|
118
|
-
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
119
|
-
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
120
|
-
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
121
|
-
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
122
|
-
* defaulting to `false` if none is configured.
|
|
123
|
-
* - `urlParamsSettings` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
124
|
-
*
|
|
125
|
-
* ```ts
|
|
126
|
-
* import { query } from '@warp-drive/utilities/rest';
|
|
127
|
-
*
|
|
128
|
-
* const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
|
|
129
|
-
* const data = await store.request(options);
|
|
130
|
-
* ```
|
|
131
|
-
*
|
|
132
|
-
* @public
|
|
133
|
-
* @param identifier
|
|
134
|
-
* @param query
|
|
135
|
-
* @param options
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
function query(type,
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
140
|
-
query = {}, options = {}) {
|
|
141
|
-
const cacheOptions = extractCacheOptions(options);
|
|
142
|
-
const urlOptions = {
|
|
143
|
-
identifier: {
|
|
144
|
-
type
|
|
145
|
-
},
|
|
146
|
-
op: 'query',
|
|
147
|
-
resourcePath: pluralize(camelize(type))
|
|
148
|
-
};
|
|
149
|
-
copyForwardUrlOptions(urlOptions, options);
|
|
150
|
-
const url = buildBaseURL(urlOptions);
|
|
151
|
-
const headers = new Headers();
|
|
152
|
-
headers.append('Accept', 'application/json;charset=utf-8');
|
|
153
|
-
const queryString = buildQueryParams(query, options.urlParamsSettings);
|
|
154
|
-
return {
|
|
155
|
-
url: queryString ? `${url}?${queryString}` : url,
|
|
156
|
-
method: 'GET',
|
|
157
|
-
headers,
|
|
158
|
-
cacheOptions,
|
|
159
|
-
op: 'query'
|
|
160
|
-
};
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/-private/rest/query.ts
|
|
35
|
+
function query(type, query = {}, options = {}) {
|
|
36
|
+
const cacheOptions = extractCacheOptions(options);
|
|
37
|
+
const urlOptions = {
|
|
38
|
+
identifier: { type },
|
|
39
|
+
op: "query",
|
|
40
|
+
resourcePath: pluralize(camelize(type))
|
|
41
|
+
};
|
|
42
|
+
copyForwardUrlOptions(urlOptions, options);
|
|
43
|
+
const url = buildBaseURL(urlOptions);
|
|
44
|
+
const headers = new Headers();
|
|
45
|
+
headers.append("Accept", "application/json;charset=utf-8");
|
|
46
|
+
const queryString = buildQueryParams(query, options.urlParamsSettings);
|
|
47
|
+
return {
|
|
48
|
+
url: queryString ? `${url}?${queryString}` : url,
|
|
49
|
+
method: "GET",
|
|
50
|
+
headers,
|
|
51
|
+
cacheOptions,
|
|
52
|
+
op: "query"
|
|
53
|
+
};
|
|
161
54
|
}
|
|
162
55
|
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/-private/rest/save-record.ts
|
|
163
58
|
/**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
59
|
+
* Builds request options to delete record for resources,
|
|
60
|
+
* configured for the url, method and header expectations of REST APIs.
|
|
61
|
+
*
|
|
62
|
+
* **Basic Usage**
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { deleteRecord } from '@warp-drive/utilities/rest';
|
|
66
|
+
*
|
|
67
|
+
* const person = store.peekRecord('person', '1');
|
|
68
|
+
*
|
|
69
|
+
* // mark record as deleted
|
|
70
|
+
* store.deleteRecord(person);
|
|
71
|
+
*
|
|
72
|
+
* // persist deletion
|
|
73
|
+
* const data = await store.request(deleteRecord(person));
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
77
|
+
*
|
|
78
|
+
* The following options are supported:
|
|
79
|
+
*
|
|
80
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
81
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
82
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
83
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
84
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
85
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
86
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
87
|
+
* defaulting to `false` if none is configured.
|
|
88
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { deleteRecord } from '@warp-drive/utilities/rest';
|
|
92
|
+
*
|
|
93
|
+
* const person = store.peekRecord('person', '1');
|
|
94
|
+
*
|
|
95
|
+
* // mark record as deleted
|
|
96
|
+
* store.deleteRecord(person);
|
|
97
|
+
*
|
|
98
|
+
* // persist deletion
|
|
99
|
+
* const options = deleteRecord(person, { namespace: 'api/v1' });
|
|
100
|
+
* const data = await store.request(options);
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
* @param record
|
|
105
|
+
* @param options
|
|
106
|
+
*/
|
|
213
107
|
function deleteRecord(record, options = {}) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
records: [identifier]
|
|
233
|
-
};
|
|
108
|
+
const identifier = recordIdentifierFor(record);
|
|
109
|
+
const urlOptions = {
|
|
110
|
+
identifier,
|
|
111
|
+
op: "deleteRecord",
|
|
112
|
+
resourcePath: pluralize(camelize(identifier.type))
|
|
113
|
+
};
|
|
114
|
+
copyForwardUrlOptions(urlOptions, options);
|
|
115
|
+
const url = buildBaseURL(urlOptions);
|
|
116
|
+
const headers = new Headers();
|
|
117
|
+
headers.append("Accept", "application/json;charset=utf-8");
|
|
118
|
+
return {
|
|
119
|
+
url,
|
|
120
|
+
method: "DELETE",
|
|
121
|
+
headers,
|
|
122
|
+
op: "deleteRecord",
|
|
123
|
+
data: { record: identifier },
|
|
124
|
+
records: [identifier]
|
|
125
|
+
};
|
|
234
126
|
}
|
|
235
|
-
|
|
236
127
|
/**
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
128
|
+
* Builds request options to create new record for resources,
|
|
129
|
+
* configured for the url, method and header expectations of most REST APIs.
|
|
130
|
+
*
|
|
131
|
+
* **Basic Usage**
|
|
132
|
+
*
|
|
133
|
+
* ```ts
|
|
134
|
+
* import { createRecord } from '@warp-drive/utilities/rest';
|
|
135
|
+
*
|
|
136
|
+
* const person = store.createRecord('person', { name: 'Ted' });
|
|
137
|
+
* const data = await store.request(createRecord(person));
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
141
|
+
*
|
|
142
|
+
* The following options are supported:
|
|
143
|
+
*
|
|
144
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
145
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
146
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
147
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
148
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
149
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
150
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
151
|
+
* defaulting to `false` if none is configured.
|
|
152
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
153
|
+
*
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { createRecord } from '@warp-drive/utilities/rest';
|
|
156
|
+
*
|
|
157
|
+
* const person = store.createRecord('person', { name: 'Ted' });
|
|
158
|
+
* const options = createRecord(person, { namespace: 'api/v1' });
|
|
159
|
+
* const data = await store.request(options);
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @public
|
|
163
|
+
* @param record
|
|
164
|
+
* @param options
|
|
165
|
+
*/
|
|
276
166
|
function createRecord(record, options = {}) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
records: [identifier]
|
|
296
|
-
};
|
|
167
|
+
const identifier = recordIdentifierFor(record);
|
|
168
|
+
const urlOptions = {
|
|
169
|
+
identifier,
|
|
170
|
+
op: "createRecord",
|
|
171
|
+
resourcePath: pluralize(camelize(identifier.type))
|
|
172
|
+
};
|
|
173
|
+
copyForwardUrlOptions(urlOptions, options);
|
|
174
|
+
const url = buildBaseURL(urlOptions);
|
|
175
|
+
const headers = new Headers();
|
|
176
|
+
headers.append("Accept", "application/json;charset=utf-8");
|
|
177
|
+
return {
|
|
178
|
+
url,
|
|
179
|
+
method: "POST",
|
|
180
|
+
headers,
|
|
181
|
+
op: "createRecord",
|
|
182
|
+
data: { record: identifier },
|
|
183
|
+
records: [identifier]
|
|
184
|
+
};
|
|
297
185
|
}
|
|
298
|
-
|
|
299
186
|
/**
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
187
|
+
* Builds request options to update existing record for resources,
|
|
188
|
+
* configured for the url, method and header expectations of most REST APIs.
|
|
189
|
+
*
|
|
190
|
+
* **Basic Usage**
|
|
191
|
+
*
|
|
192
|
+
* ```ts
|
|
193
|
+
* import { updateRecord } from '@warp-drive/utilities/rest';
|
|
194
|
+
*
|
|
195
|
+
* const person = store.peekRecord('person', '1');
|
|
196
|
+
* person.name = 'Chris';
|
|
197
|
+
* const data = await store.request(updateRecord(person));
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
201
|
+
*
|
|
202
|
+
* The following options are supported:
|
|
203
|
+
*
|
|
204
|
+
* - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
|
|
205
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
206
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
207
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
208
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
209
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
210
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
211
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
212
|
+
* defaulting to `false` if none is configured.
|
|
213
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
214
|
+
*
|
|
215
|
+
* ```ts
|
|
216
|
+
* import { updateRecord } from '@warp-drive/utilities/rest';
|
|
217
|
+
*
|
|
218
|
+
* const person = store.peekRecord('person', '1');
|
|
219
|
+
* person.name = 'Chris';
|
|
220
|
+
* const options = updateRecord(person, { patch: true });
|
|
221
|
+
* const data = await store.request(options);
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* @public
|
|
225
|
+
* @param record
|
|
226
|
+
* @param options
|
|
227
|
+
*/
|
|
342
228
|
function updateRecord(record, options = {}) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
records: [identifier]
|
|
362
|
-
};
|
|
229
|
+
const identifier = recordIdentifierFor(record);
|
|
230
|
+
const urlOptions = {
|
|
231
|
+
identifier,
|
|
232
|
+
op: "updateRecord",
|
|
233
|
+
resourcePath: pluralize(camelize(identifier.type))
|
|
234
|
+
};
|
|
235
|
+
copyForwardUrlOptions(urlOptions, options);
|
|
236
|
+
const url = buildBaseURL(urlOptions);
|
|
237
|
+
const headers = new Headers();
|
|
238
|
+
headers.append("Accept", "application/json;charset=utf-8");
|
|
239
|
+
return {
|
|
240
|
+
url,
|
|
241
|
+
method: options.patch ? "PATCH" : "PUT",
|
|
242
|
+
headers,
|
|
243
|
+
op: "updateRecord",
|
|
244
|
+
data: { record: identifier },
|
|
245
|
+
records: [identifier]
|
|
246
|
+
};
|
|
363
247
|
}
|
|
364
|
-
|
|
248
|
+
|
|
249
|
+
//#endregion
|
|
250
|
+
export { createRecord, deleteRecord, findRecord, query, updateRecord };
|
|
251
|
+
//# sourceMappingURL=rest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest.js","names":["recordIdentifierFor","buildBaseURL","camelize","pluralize","copyForwardUrlOptions","isExisting","identifier","id","type","deleteRecord","record","options","urlOptions","op","resourcePath","url","headers","Headers","append","method","data","records","createRecord","updateRecord","patch"],"sources":["../../../src/-private/rest/find-record.ts","../../../src/-private/rest/query.ts","../../../src/-private/rest/save-record.ts"],"sourcesContent":["import type { ReactiveDataDocument } from '@warp-drive/core/reactive';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive/core/types/request';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { camelize, pluralize } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to fetch a single resource by a known id or identifier\n * configured for the url and header expectations of most REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/rest';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/rest';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **With an Identifier**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/rest';\n *\n * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/rest';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n */\nexport function findRecord<T>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord<T>(\n arg1: TypeFromInstance<T> | RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T>, T> {\n const identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>> =\n typeof arg1 === 'string' ? { type: arg1, id: arg2 as string } : arg1;\n const options: FindRecordOptions = (typeof arg1 === 'string' ? arg3 : (arg2 as FindRecordOptions)) || {};\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url: options.include?.length\n ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}`\n : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'findRecord',\n records: [identifier],\n };\n}\n\n/** @deprecated use {@link ReactiveDataDocument} instead */\nexport type FindRecordResultDocument<T> = ReactiveDataDocument<T>;\n","import type { ReactiveDataDocument } from '@warp-drive/core/reactive';\nimport type { QueryParamsSource } from '@warp-drive/core/types/params';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive/core/types/request';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { camelize, pluralize } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/rest';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/rest';\n *\n * const options = query('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSettings` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/rest';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function query<T>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<ReactiveDataDocument<T[]>>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(camelize(type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n const queryString = buildQueryParams(query, options.urlParamsSettings);\n\n return {\n url: queryString ? `${url}?${queryString}` : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'query',\n };\n}\n","import { recordIdentifierFor } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { ReactiveDataDocument } from '@warp-drive/core/reactive';\nimport type { PersistedResourceKey, ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive/core/types/request';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { camelize, pluralize } from '../../string';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\n\nfunction isExisting(identifier: ResourceKey): identifier is PersistedResourceKey {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const data = await store.request(deleteRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const options = deleteRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'DELETE',\n headers,\n op: 'deleteRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to create new record for resources,\n * configured for the url, method and header expectations of most REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/rest';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const data = await store.request(createRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/rest';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const options = createRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'POST',\n headers,\n op: 'createRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url, method and header expectations of most REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(updateRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = updateRecord(person, { patch: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: options.patch ? 'PATCH' : 'PUT',\n headers,\n op: 'updateRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n"],"mappings":";;;;;;AA+EA,SAAgB,WACd,MACA,MACA,MACsD;CACtD,MAAM,aACJ,OAAO,SAAS,WAAW;EAAE,MAAM;EAAM,IAAI;CAAe,IAAI;CAClE,MAAM,WAA8B,OAAO,SAAS,WAAW,OAAQ,SAA+B,CAAC;CACvG,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAAmC;EACvC;EACA,IAAI;EACJ,cAAc,UAAU,SAAS,WAAW,IAAI,CAAC;CACnD;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,UAAU;CACnC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACL,KAAK,QAAQ,SAAS,SAClB,GAAG,IAAI,GAAG,iBAAiB,EAAE,SAAS,QAAQ,QAAQ,GAAG,QAAQ,iBAAiB,MAClF;EACJ,QAAQ;EACR;EACA;EACA,IAAI;EACJ,SAAS,CAAC,UAAU;CACtB;AACF;;;;AC5CA,SAAgB,MACd,MAEA,QAA2B,CAAC,GAC5B,UAAqC,CAAC,GACjB;CACrB,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAA8B;EAClC,YAAY,EAAE,KAAK;EACnB,IAAI;EACJ,cAAc,UAAU,SAAS,IAAI,CAAC;CACxC;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,UAAU;CACnC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,OAAO,UAAU,gCAAgC;CACzD,MAAM,cAAc,iBAAiB,OAAO,QAAQ,iBAAiB;CAErE,OAAO;EACL,KAAK,cAAc,GAAG,IAAI,GAAG,gBAAgB;EAC7C,QAAQ;EACR;EACA;EACA,IAAI;CACN;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACjBA,SAAgBS,aAAaC,QAAiBC,UAAqC,CAAC,GAAyB;CAC3G,MAAML,aAAaN,oBAAoBU,MAAM;CAI7C,MAAME,aAAqC;EAC7BN;EACZO,IAAI;EACJC,cAAcX,UAAUD,SAASI,WAAWE,IAAI,CAAC;CACnD;CAEAJ,sBAAsBQ,YAAYD,OAAO;CAEzC,MAAMI,MAAMd,aAAaW,UAAU;CACnC,MAAMI,UAAU,IAAIC,QAAQ;CAC5BD,QAAQE,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACLH;EACAI,QAAQ;EACRH;EACAH,IAAI;EACJO,MAAM,EACJV,QAAQJ,WACV;EACAe,SAAS,CAACf,UAAU;CACtB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAgBgB,aAAaZ,QAAiBC,UAAqC,CAAC,GAAyB;CAC3G,MAAML,aAAaN,oBAAoBU,MAAM;CAG7C,MAAME,aAAqC;EAC7BN;EACZO,IAAI;EACJC,cAAcX,UAAUD,SAASI,WAAWE,IAAI,CAAC;CACnD;CAEAJ,sBAAsBQ,YAAYD,OAAO;CAEzC,MAAMI,MAAMd,aAAaW,UAAU;CACnC,MAAMI,UAAU,IAAIC,QAAQ;CAC5BD,QAAQE,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACLH;EACAI,QAAQ;EACRH;EACAH,IAAI;EACJO,MAAM,EACJV,QAAQJ,WACV;EACAe,SAAS,CAACf,UAAU;CACtB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgBiB,aACdb,QACAC,UAA2D,CAAC,GACtC;CACtB,MAAML,aAAaN,oBAAoBU,MAAM;CAI7C,MAAME,aAAqC;EAC7BN;EACZO,IAAI;EACJC,cAAcX,UAAUD,SAASI,WAAWE,IAAI,CAAC;CACnD;CAEAJ,sBAAsBQ,YAAYD,OAAO;CAEzC,MAAMI,MAAMd,aAAaW,UAAU;CACnC,MAAMI,UAAU,IAAIC,QAAQ;CAC5BD,QAAQE,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACLH;EACAI,QAAQR,QAAQa,QAAQ,UAAU;EAClCR;EACAH,IAAI;EACJO,MAAM,EACJV,QAAQJ,WACV;EACAe,SAAS,CAACf,UAAU;CACtB;AACF"}
|