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