@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.
Files changed (150) hide show
  1. package/cjs-dist/string.cjs +448 -0
  2. package/cjs-dist/string.cjs.map +1 -0
  3. package/declarations/-private.d.ts +12 -1
  4. package/declarations/-private.d.ts.map +1 -0
  5. package/declarations/active-record.d.ts +260 -3
  6. package/declarations/active-record.d.ts.map +1 -0
  7. package/declarations/derivations.d.ts +26 -23
  8. package/declarations/derivations.d.ts.map +1 -0
  9. package/declarations/handlers.d.ts +282 -9
  10. package/declarations/handlers.d.ts.map +1 -0
  11. package/declarations/index-BeMAuqgZ.d.ts +462 -0
  12. package/declarations/index-BeMAuqgZ.d.ts.map +1 -0
  13. package/declarations/index.d.ts +2 -208
  14. package/declarations/json-api.d.ts +496 -5
  15. package/declarations/json-api.d.ts.map +1 -0
  16. package/declarations/rest.d.ts +258 -3
  17. package/declarations/rest.d.ts.map +1 -0
  18. package/declarations/string.d.ts +164 -13
  19. package/declarations/string.d.ts.map +1 -0
  20. package/dist/-private.js +2 -6
  21. package/dist/active-record.js +254 -379
  22. package/dist/active-record.js.map +1 -0
  23. package/dist/builder-utils-BkXwUT0x.js +16 -0
  24. package/dist/builder-utils-BkXwUT0x.js.map +1 -0
  25. package/dist/derivations.js +26 -26
  26. package/dist/derivations.js.map +1 -0
  27. package/dist/handlers.js +240 -283
  28. package/dist/handlers.js.map +1 -0
  29. package/dist/index.js +357 -335
  30. package/dist/index.js.map +1 -0
  31. package/dist/inflections-DzBsjJqj.js +80 -0
  32. package/dist/inflections-DzBsjJqj.js.map +1 -0
  33. package/dist/json-api.js +470 -706
  34. package/dist/json-api.js.map +1 -0
  35. package/dist/rest.js +254 -377
  36. package/dist/rest.js.map +1 -0
  37. package/dist/string-CWmAluxh.js +290 -0
  38. package/dist/string-CWmAluxh.js.map +1 -0
  39. package/dist/string.js +2 -427
  40. package/dist/unpkg/dev/-private.js +2 -6
  41. package/dist/unpkg/dev/active-record.js +253 -378
  42. package/dist/unpkg/dev/active-record.js.map +1 -0
  43. package/dist/unpkg/dev/builder-utils-BkXwUT0x.js +16 -0
  44. package/dist/unpkg/dev/builder-utils-BkXwUT0x.js.map +1 -0
  45. package/dist/unpkg/dev/derivations.js +26 -26
  46. package/dist/unpkg/dev/derivations.js.map +1 -0
  47. package/dist/unpkg/dev/handlers.js +238 -282
  48. package/dist/unpkg/dev/handlers.js.map +1 -0
  49. package/dist/unpkg/dev/index.js +356 -336
  50. package/dist/unpkg/dev/index.js.map +1 -0
  51. package/dist/unpkg/dev/inflections-DzBsjJqj.js +80 -0
  52. package/dist/unpkg/dev/inflections-DzBsjJqj.js.map +1 -0
  53. package/dist/unpkg/dev/json-api.js +469 -706
  54. package/dist/unpkg/dev/json-api.js.map +1 -0
  55. package/dist/unpkg/dev/rest.js +253 -376
  56. package/dist/unpkg/dev/rest.js.map +1 -0
  57. package/dist/unpkg/dev/string-j4ur-TDs.js +289 -0
  58. package/dist/unpkg/dev/string-j4ur-TDs.js.map +1 -0
  59. package/dist/unpkg/dev/string.js +3 -1
  60. package/dist/unpkg/dev-deprecated/-private.js +2 -6
  61. package/dist/unpkg/dev-deprecated/active-record.js +253 -378
  62. package/dist/unpkg/dev-deprecated/active-record.js.map +1 -0
  63. package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js +16 -0
  64. package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
  65. package/dist/unpkg/dev-deprecated/derivations.js +26 -26
  66. package/dist/unpkg/dev-deprecated/derivations.js.map +1 -0
  67. package/dist/unpkg/dev-deprecated/handlers.js +238 -282
  68. package/dist/unpkg/dev-deprecated/handlers.js.map +1 -0
  69. package/dist/unpkg/dev-deprecated/index.js +356 -336
  70. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  71. package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js +80 -0
  72. package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js.map +1 -0
  73. package/dist/unpkg/dev-deprecated/json-api.js +469 -706
  74. package/dist/unpkg/dev-deprecated/json-api.js.map +1 -0
  75. package/dist/unpkg/dev-deprecated/rest.js +253 -376
  76. package/dist/unpkg/dev-deprecated/rest.js.map +1 -0
  77. package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js +289 -0
  78. package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +1 -0
  79. package/dist/unpkg/dev-deprecated/string.js +3 -1
  80. package/dist/unpkg/prod/-private.js +2 -6
  81. package/dist/unpkg/prod/active-record.js +236 -351
  82. package/dist/unpkg/prod/active-record.js.map +1 -0
  83. package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +16 -0
  84. package/dist/unpkg/prod/builder-utils-BkXwUT0x.js.map +1 -0
  85. package/dist/unpkg/prod/derivations.js +26 -26
  86. package/dist/unpkg/prod/derivations.js.map +1 -0
  87. package/dist/unpkg/prod/handlers.js +231 -272
  88. package/dist/unpkg/prod/handlers.js.map +1 -0
  89. package/dist/unpkg/prod/index.js +265 -215
  90. package/dist/unpkg/prod/index.js.map +1 -0
  91. package/dist/unpkg/prod/inflections-DzBsjJqj.js +80 -0
  92. package/dist/unpkg/prod/inflections-DzBsjJqj.js.map +1 -0
  93. package/dist/unpkg/prod/json-api.js +446 -669
  94. package/dist/unpkg/prod/json-api.js.map +1 -0
  95. package/dist/unpkg/prod/rest.js +236 -349
  96. package/dist/unpkg/prod/rest.js.map +1 -0
  97. package/dist/unpkg/prod/string-T1ahjLdj.js +283 -0
  98. package/dist/unpkg/prod/string-T1ahjLdj.js.map +1 -0
  99. package/dist/unpkg/prod/string.js +3 -1
  100. package/dist/unpkg/prod-deprecated/-private.js +2 -6
  101. package/dist/unpkg/prod-deprecated/active-record.js +236 -351
  102. package/dist/unpkg/prod-deprecated/active-record.js.map +1 -0
  103. package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js +16 -0
  104. package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
  105. package/dist/unpkg/prod-deprecated/derivations.js +26 -26
  106. package/dist/unpkg/prod-deprecated/derivations.js.map +1 -0
  107. package/dist/unpkg/prod-deprecated/handlers.js +231 -272
  108. package/dist/unpkg/prod-deprecated/handlers.js.map +1 -0
  109. package/dist/unpkg/prod-deprecated/index.js +265 -215
  110. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  111. package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js +80 -0
  112. package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js.map +1 -0
  113. package/dist/unpkg/prod-deprecated/json-api.js +446 -669
  114. package/dist/unpkg/prod-deprecated/json-api.js.map +1 -0
  115. package/dist/unpkg/prod-deprecated/rest.js +236 -349
  116. package/dist/unpkg/prod-deprecated/rest.js.map +1 -0
  117. package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js +283 -0
  118. package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +1 -0
  119. package/dist/unpkg/prod-deprecated/string.js +3 -1
  120. package/package.json +11 -10
  121. package/declarations/-private/active-record/find-record.d.ts +0 -64
  122. package/declarations/-private/active-record/query.d.ts +0 -53
  123. package/declarations/-private/active-record/save-record.d.ts +0 -146
  124. package/declarations/-private/builder-utils.d.ts +0 -4
  125. package/declarations/-private/handlers/auto-compress.d.ts +0 -158
  126. package/declarations/-private/handlers/gated.d.ts +0 -19
  127. package/declarations/-private/handlers/meta-doc.d.ts +0 -47
  128. package/declarations/-private/handlers/utils.d.ts +0 -41
  129. package/declarations/-private/json-api/-utils.d.ts +0 -109
  130. package/declarations/-private/json-api/find-record.d.ts +0 -84
  131. package/declarations/-private/json-api/query.d.ts +0 -100
  132. package/declarations/-private/json-api/save-record.d.ts +0 -228
  133. package/declarations/-private/json-api/serialize.d.ts +0 -70
  134. package/declarations/-private/rest/find-record.d.ts +0 -62
  135. package/declarations/-private/rest/query.d.ts +0 -53
  136. package/declarations/-private/rest/save-record.d.ts +0 -146
  137. package/declarations/-private/string/inflect.d.ts +0 -82
  138. package/declarations/-private/string/inflections.d.ts +0 -9
  139. package/declarations/-private/string/transform.d.ts +0 -77
  140. package/dist/builder-utils-Donkk-BZ.js +0 -22
  141. package/dist/inflect-BSG696t-.js +0 -344
  142. package/dist/string.cjs +0 -430
  143. package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +0 -22
  144. package/dist/unpkg/dev/inflect-BEv8WqY1.js +0 -343
  145. package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +0 -22
  146. package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +0 -343
  147. package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +0 -22
  148. package/dist/unpkg/prod/inflect-Dh9dyEYx.js +0 -333
  149. package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +0 -22
  150. package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +0 -333
@@ -1,392 +1,269 @@
1
- import { buildBaseURL, buildQueryParams } from './index.js';
2
- import { p as pluralize, g as camelize } from "./inflect-BEv8WqY1.js";
3
- import { e as extractCacheOptions, c as copyForwardUrlOptions } from "./builder-utils-Donkk-BZ.js";
4
- import { recordIdentifierFor } from '@warp-drive/core';
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-j4ur-TDs.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
- const identifier = typeof arg1 === 'string' ? {
62
- type: arg1,
63
- id: arg2
64
- } : arg1;
65
- const options = (typeof arg1 === 'string' ? arg3 : arg2) || {};
66
- const cacheOptions = extractCacheOptions(options);
67
- const urlOptions = {
68
- identifier,
69
- op: 'findRecord',
70
- resourcePath: pluralize(camelize(identifier.type))
71
- };
72
- copyForwardUrlOptions(urlOptions, options);
73
- const url = buildBaseURL(urlOptions);
74
- const headers = new Headers();
75
- headers.append('Accept', 'application/json;charset=utf-8');
76
- return {
77
- url: options.include?.length ? `${url}?${buildQueryParams({
78
- include: options.include
79
- }, options.urlParamsSettings)}` : url,
80
- method: 'GET',
81
- headers,
82
- cacheOptions,
83
- op: 'findRecord',
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
- /** @deprecated use {@link ReactiveDataDocument} instead */
89
-
90
- /**
91
- * Builds request options to query for resources, usually by a primary
92
- * type, configured for the url and header expectations of most REST APIs.
93
- *
94
- * **Basic Usage**
95
- *
96
- * ```ts
97
- * import { query } from '@warp-drive/utilities/rest';
98
- *
99
- * const data = await store.request(query('person'));
100
- * ```
101
- *
102
- * **With Query Params**
103
- *
104
- * ```ts
105
- * import { query } from '@warp-drive/utilities/rest';
106
- *
107
- * const options = query('person', { include: ['pets', 'friends'] });
108
- * const data = await store.request(options);
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
  }
55
+
56
+ //#endregion
57
+ //#region src/-private/rest/save-record.ts
162
58
  function isExisting(identifier) {
163
- return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;
59
+ return "id" in identifier && identifier.id !== null && "type" in identifier && identifier.type !== null;
164
60
  }
165
-
166
61
  /**
167
- * Builds request options to delete record for resources,
168
- * configured for the url, method and header expectations of REST APIs.
169
- *
170
- * **Basic Usage**
171
- *
172
- * ```ts
173
- * import { deleteRecord } from '@warp-drive/utilities/rest';
174
- *
175
- * const person = store.peekRecord('person', '1');
176
- *
177
- * // mark record as deleted
178
- * store.deleteRecord(person);
179
- *
180
- * // persist deletion
181
- * const data = await store.request(deleteRecord(person));
182
- * ```
183
- *
184
- * **Supplying Options to Modify the Request Behavior**
185
- *
186
- * The following options are supported:
187
- *
188
- * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
189
- * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
190
- * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
191
- * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
192
- * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
193
- * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
194
- * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
195
- * defaulting to `false` if none is configured.
196
- * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
197
- *
198
- * ```ts
199
- * import { deleteRecord } from '@warp-drive/utilities/rest';
200
- *
201
- * const person = store.peekRecord('person', '1');
202
- *
203
- * // mark record as deleted
204
- * store.deleteRecord(person);
205
- *
206
- * // persist deletion
207
- * const options = deleteRecord(person, { namespace: 'api/v1' });
208
- * const data = await store.request(options);
209
- * ```
210
- *
211
- * @public
212
- * @param record
213
- * @param options
214
- */
215
-
62
+ * Builds request options to delete record for resources,
63
+ * configured for the url, method and header expectations of REST APIs.
64
+ *
65
+ * **Basic Usage**
66
+ *
67
+ * ```ts
68
+ * import { deleteRecord } from '@warp-drive/utilities/rest';
69
+ *
70
+ * const person = store.peekRecord('person', '1');
71
+ *
72
+ * // mark record as deleted
73
+ * store.deleteRecord(person);
74
+ *
75
+ * // persist deletion
76
+ * const data = await store.request(deleteRecord(person));
77
+ * ```
78
+ *
79
+ * **Supplying Options to Modify the Request Behavior**
80
+ *
81
+ * The following options are supported:
82
+ *
83
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
84
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
85
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
86
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
87
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
88
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
89
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
90
+ * defaulting to `false` if none is configured.
91
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
92
+ *
93
+ * ```ts
94
+ * import { deleteRecord } from '@warp-drive/utilities/rest';
95
+ *
96
+ * const person = store.peekRecord('person', '1');
97
+ *
98
+ * // mark record as deleted
99
+ * store.deleteRecord(person);
100
+ *
101
+ * // persist deletion
102
+ * const options = deleteRecord(person, { namespace: 'api/v1' });
103
+ * const data = await store.request(options);
104
+ * ```
105
+ *
106
+ * @public
107
+ * @param record
108
+ * @param options
109
+ */
216
110
  function deleteRecord(record, options = {}) {
217
- const identifier = recordIdentifierFor(record);
218
- (test => {
219
- if (!test) {
220
- throw new Error(`Expected to be given a record instance`);
221
- }
222
- })(identifier);
223
- (test => {
224
- if (!test) {
225
- throw new Error(`Cannot delete a record that does not have an associated type and id.`);
226
- }
227
- })(isExisting(identifier));
228
- const urlOptions = {
229
- identifier: identifier,
230
- op: 'deleteRecord',
231
- resourcePath: pluralize(camelize(identifier.type))
232
- };
233
- copyForwardUrlOptions(urlOptions, options);
234
- const url = buildBaseURL(urlOptions);
235
- const headers = new Headers();
236
- headers.append('Accept', 'application/json;charset=utf-8');
237
- return {
238
- url,
239
- method: 'DELETE',
240
- headers,
241
- op: 'deleteRecord',
242
- data: {
243
- record: identifier
244
- },
245
- records: [identifier]
246
- };
111
+ const identifier = recordIdentifierFor(record);
112
+ ((test) => {
113
+ if (!test) throw new Error(`Expected to be given a record instance`);
114
+ })(identifier);
115
+ ((test) => {
116
+ if (!test) throw new Error(`Cannot delete a record that does not have an associated type and id.`);
117
+ })(isExisting(identifier));
118
+ const urlOptions = {
119
+ identifier,
120
+ op: "deleteRecord",
121
+ resourcePath: pluralize(camelize(identifier.type))
122
+ };
123
+ copyForwardUrlOptions(urlOptions, options);
124
+ const url = buildBaseURL(urlOptions);
125
+ const headers = new Headers();
126
+ headers.append("Accept", "application/json;charset=utf-8");
127
+ return {
128
+ url,
129
+ method: "DELETE",
130
+ headers,
131
+ op: "deleteRecord",
132
+ data: { record: identifier },
133
+ records: [identifier]
134
+ };
247
135
  }
248
-
249
136
  /**
250
- * Builds request options to create new record for resources,
251
- * configured for the url, method and header expectations of most REST APIs.
252
- *
253
- * **Basic Usage**
254
- *
255
- * ```ts
256
- * import { createRecord } from '@warp-drive/utilities/rest';
257
- *
258
- * const person = store.createRecord('person', { name: 'Ted' });
259
- * const data = await store.request(createRecord(person));
260
- * ```
261
- *
262
- * **Supplying Options to Modify the Request Behavior**
263
- *
264
- * The following options are supported:
265
- *
266
- * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
267
- * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
268
- * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
269
- * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
270
- * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
271
- * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
272
- * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
273
- * defaulting to `false` if none is configured.
274
- * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
275
- *
276
- * ```ts
277
- * import { createRecord } from '@warp-drive/utilities/rest';
278
- *
279
- * const person = store.createRecord('person', { name: 'Ted' });
280
- * const options = createRecord(person, { namespace: 'api/v1' });
281
- * const data = await store.request(options);
282
- * ```
283
- *
284
- * @public
285
- * @param record
286
- * @param options
287
- */
288
-
137
+ * Builds request options to create new record for resources,
138
+ * configured for the url, method and header expectations of most REST APIs.
139
+ *
140
+ * **Basic Usage**
141
+ *
142
+ * ```ts
143
+ * import { createRecord } from '@warp-drive/utilities/rest';
144
+ *
145
+ * const person = store.createRecord('person', { name: 'Ted' });
146
+ * const data = await store.request(createRecord(person));
147
+ * ```
148
+ *
149
+ * **Supplying Options to Modify the Request Behavior**
150
+ *
151
+ * The following options are supported:
152
+ *
153
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
154
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
155
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
156
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
157
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
158
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
159
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
160
+ * defaulting to `false` if none is configured.
161
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
162
+ *
163
+ * ```ts
164
+ * import { createRecord } from '@warp-drive/utilities/rest';
165
+ *
166
+ * const person = store.createRecord('person', { name: 'Ted' });
167
+ * const options = createRecord(person, { namespace: 'api/v1' });
168
+ * const data = await store.request(options);
169
+ * ```
170
+ *
171
+ * @public
172
+ * @param record
173
+ * @param options
174
+ */
289
175
  function createRecord(record, options = {}) {
290
- const identifier = recordIdentifierFor(record);
291
- (test => {
292
- if (!test) {
293
- throw new Error(`Expected to be given a record instance`);
294
- }
295
- })(identifier);
296
- const urlOptions = {
297
- identifier: identifier,
298
- op: 'createRecord',
299
- resourcePath: pluralize(camelize(identifier.type))
300
- };
301
- copyForwardUrlOptions(urlOptions, options);
302
- const url = buildBaseURL(urlOptions);
303
- const headers = new Headers();
304
- headers.append('Accept', 'application/json;charset=utf-8');
305
- return {
306
- url,
307
- method: 'POST',
308
- headers,
309
- op: 'createRecord',
310
- data: {
311
- record: identifier
312
- },
313
- records: [identifier]
314
- };
176
+ const identifier = recordIdentifierFor(record);
177
+ ((test) => {
178
+ if (!test) throw new Error(`Expected to be given a record instance`);
179
+ })(identifier);
180
+ const urlOptions = {
181
+ identifier,
182
+ op: "createRecord",
183
+ resourcePath: pluralize(camelize(identifier.type))
184
+ };
185
+ copyForwardUrlOptions(urlOptions, options);
186
+ const url = buildBaseURL(urlOptions);
187
+ const headers = new Headers();
188
+ headers.append("Accept", "application/json;charset=utf-8");
189
+ return {
190
+ url,
191
+ method: "POST",
192
+ headers,
193
+ op: "createRecord",
194
+ data: { record: identifier },
195
+ records: [identifier]
196
+ };
315
197
  }
316
-
317
198
  /**
318
- * Builds request options to update existing record for resources,
319
- * configured for the url, method and header expectations of most REST APIs.
320
- *
321
- * **Basic Usage**
322
- *
323
- * ```ts
324
- * import { updateRecord } from '@warp-drive/utilities/rest';
325
- *
326
- * const person = store.peekRecord('person', '1');
327
- * person.name = 'Chris';
328
- * const data = await store.request(updateRecord(person));
329
- * ```
330
- *
331
- * **Supplying Options to Modify the Request Behavior**
332
- *
333
- * The following options are supported:
334
- *
335
- * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
336
- * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
337
- * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
338
- * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
339
- * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
340
- * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
341
- * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
342
- * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
343
- * defaulting to `false` if none is configured.
344
- * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
345
- *
346
- * ```ts
347
- * import { updateRecord } from '@warp-drive/utilities/rest';
348
- *
349
- * const person = store.peekRecord('person', '1');
350
- * person.name = 'Chris';
351
- * const options = updateRecord(person, { patch: true });
352
- * const data = await store.request(options);
353
- * ```
354
- *
355
- * @public
356
- * @param record
357
- * @param options
358
- */
359
-
199
+ * Builds request options to update existing record for resources,
200
+ * configured for the url, method and header expectations of most REST APIs.
201
+ *
202
+ * **Basic Usage**
203
+ *
204
+ * ```ts
205
+ * import { updateRecord } from '@warp-drive/utilities/rest';
206
+ *
207
+ * const person = store.peekRecord('person', '1');
208
+ * person.name = 'Chris';
209
+ * const data = await store.request(updateRecord(person));
210
+ * ```
211
+ *
212
+ * **Supplying Options to Modify the Request Behavior**
213
+ *
214
+ * The following options are supported:
215
+ *
216
+ * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
217
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
218
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
219
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
220
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
221
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
222
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
223
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
224
+ * defaulting to `false` if none is configured.
225
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
226
+ *
227
+ * ```ts
228
+ * import { updateRecord } from '@warp-drive/utilities/rest';
229
+ *
230
+ * const person = store.peekRecord('person', '1');
231
+ * person.name = 'Chris';
232
+ * const options = updateRecord(person, { patch: true });
233
+ * const data = await store.request(options);
234
+ * ```
235
+ *
236
+ * @public
237
+ * @param record
238
+ * @param options
239
+ */
360
240
  function updateRecord(record, options = {}) {
361
- const identifier = recordIdentifierFor(record);
362
- (test => {
363
- if (!test) {
364
- throw new Error(`Expected to be given a record instance`);
365
- }
366
- })(identifier);
367
- (test => {
368
- if (!test) {
369
- throw new Error(`Cannot update a record that does not have an associated type and id.`);
370
- }
371
- })(isExisting(identifier));
372
- const urlOptions = {
373
- identifier: identifier,
374
- op: 'updateRecord',
375
- resourcePath: pluralize(camelize(identifier.type))
376
- };
377
- copyForwardUrlOptions(urlOptions, options);
378
- const url = buildBaseURL(urlOptions);
379
- const headers = new Headers();
380
- headers.append('Accept', 'application/json;charset=utf-8');
381
- return {
382
- url,
383
- method: options.patch ? 'PATCH' : 'PUT',
384
- headers,
385
- op: 'updateRecord',
386
- data: {
387
- record: identifier
388
- },
389
- records: [identifier]
390
- };
241
+ const identifier = recordIdentifierFor(record);
242
+ ((test) => {
243
+ if (!test) throw new Error(`Expected to be given a record instance`);
244
+ })(identifier);
245
+ ((test) => {
246
+ if (!test) throw new Error(`Cannot update a record that does not have an associated type and id.`);
247
+ })(isExisting(identifier));
248
+ const urlOptions = {
249
+ identifier,
250
+ op: "updateRecord",
251
+ resourcePath: pluralize(camelize(identifier.type))
252
+ };
253
+ copyForwardUrlOptions(urlOptions, options);
254
+ const url = buildBaseURL(urlOptions);
255
+ const headers = new Headers();
256
+ headers.append("Accept", "application/json;charset=utf-8");
257
+ return {
258
+ url,
259
+ method: options.patch ? "PATCH" : "PUT",
260
+ headers,
261
+ op: "updateRecord",
262
+ data: { record: identifier },
263
+ records: [identifier]
264
+ };
391
265
  }
392
- export { createRecord, deleteRecord, findRecord, query, updateRecord };
266
+
267
+ //#endregion
268
+ export { createRecord, deleteRecord, findRecord, query, updateRecord };
269
+ //# sourceMappingURL=rest.js.map