@warp-drive-mirror/utilities 5.8.0-alpha.3 → 5.8.0-alpha.32

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 (182) hide show
  1. package/README.md +14 -26
  2. package/declarations/-private/active-record/find-record.d.ts +5 -6
  3. package/declarations/-private/active-record/query.d.ts +2 -2
  4. package/declarations/-private/active-record/save-record.d.ts +2 -2
  5. package/declarations/-private/handlers/meta-doc.d.ts +1 -1
  6. package/declarations/-private/json-api/find-record.d.ts +37 -18
  7. package/declarations/-private/json-api/query.d.ts +3 -6
  8. package/declarations/-private/json-api/save-record.d.ts +45 -10
  9. package/declarations/-private/json-api/serialize.d.ts +15 -1
  10. package/declarations/-private/rest/find-record.d.ts +5 -8
  11. package/declarations/-private/rest/query.d.ts +2 -2
  12. package/declarations/-private/rest/save-record.d.ts +2 -2
  13. package/dist/active-record.js +2 -0
  14. package/dist/handlers.js +3 -3
  15. package/dist/json-api.js +94 -26
  16. package/dist/rest.js +2 -2
  17. package/dist/string.js +428 -1
  18. package/dist/unpkg/dev/-private.js +7 -0
  19. package/dist/unpkg/dev/active-record.js +395 -0
  20. package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +22 -0
  21. package/dist/unpkg/dev/declarations/-private/active-record/find-record.d.ts +64 -0
  22. package/dist/unpkg/dev/declarations/-private/active-record/query.d.ts +53 -0
  23. package/dist/unpkg/dev/declarations/-private/active-record/save-record.d.ts +146 -0
  24. package/dist/unpkg/dev/declarations/-private/builder-utils.d.ts +4 -0
  25. package/dist/unpkg/dev/declarations/-private/handlers/auto-compress.d.ts +158 -0
  26. package/dist/unpkg/dev/declarations/-private/handlers/gated.d.ts +19 -0
  27. package/dist/unpkg/dev/declarations/-private/handlers/meta-doc.d.ts +47 -0
  28. package/dist/unpkg/dev/declarations/-private/handlers/utils.d.ts +41 -0
  29. package/dist/unpkg/dev/declarations/-private/json-api/-utils.d.ts +109 -0
  30. package/dist/unpkg/dev/declarations/-private/json-api/find-record.d.ts +84 -0
  31. package/dist/unpkg/dev/declarations/-private/json-api/query.d.ts +100 -0
  32. package/dist/unpkg/dev/declarations/-private/json-api/save-record.d.ts +228 -0
  33. package/dist/unpkg/dev/declarations/-private/json-api/serialize.d.ts +70 -0
  34. package/dist/unpkg/dev/declarations/-private/rest/find-record.d.ts +62 -0
  35. package/dist/unpkg/dev/declarations/-private/rest/query.d.ts +53 -0
  36. package/dist/unpkg/dev/declarations/-private/rest/save-record.d.ts +146 -0
  37. package/dist/unpkg/dev/declarations/-private/string/inflect.d.ts +82 -0
  38. package/dist/unpkg/dev/declarations/-private/string/inflections.d.ts +9 -0
  39. package/dist/unpkg/dev/declarations/-private/string/transform.d.ts +77 -0
  40. package/dist/unpkg/dev/declarations/-private.d.ts +1 -0
  41. package/dist/unpkg/dev/declarations/active-record.d.ts +3 -0
  42. package/dist/unpkg/dev/declarations/derivations.d.ts +27 -0
  43. package/dist/unpkg/dev/declarations/handlers.d.ts +10 -0
  44. package/dist/unpkg/dev/declarations/index.d.ts +208 -0
  45. package/dist/unpkg/dev/declarations/json-api.d.ts +5 -0
  46. package/dist/unpkg/dev/declarations/rest.d.ts +3 -0
  47. package/dist/unpkg/dev/declarations/string.d.ts +14 -0
  48. package/dist/unpkg/dev/derivations.js +30 -0
  49. package/dist/unpkg/dev/handlers.js +317 -0
  50. package/dist/unpkg/dev/index.js +361 -0
  51. package/dist/unpkg/dev/inflect-BSG696t-.js +344 -0
  52. package/dist/unpkg/dev/json-api.js +740 -0
  53. package/dist/unpkg/dev/rest.js +393 -0
  54. package/dist/unpkg/dev/string.js +1 -0
  55. package/dist/unpkg/dev-deprecated/-private.js +7 -0
  56. package/dist/unpkg/dev-deprecated/active-record.js +395 -0
  57. package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +22 -0
  58. package/dist/unpkg/dev-deprecated/declarations/-private/active-record/find-record.d.ts +64 -0
  59. package/dist/unpkg/dev-deprecated/declarations/-private/active-record/query.d.ts +53 -0
  60. package/dist/unpkg/dev-deprecated/declarations/-private/active-record/save-record.d.ts +146 -0
  61. package/dist/unpkg/dev-deprecated/declarations/-private/builder-utils.d.ts +4 -0
  62. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/auto-compress.d.ts +158 -0
  63. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/gated.d.ts +19 -0
  64. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/meta-doc.d.ts +47 -0
  65. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/utils.d.ts +41 -0
  66. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/-utils.d.ts +109 -0
  67. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/find-record.d.ts +84 -0
  68. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/query.d.ts +100 -0
  69. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/save-record.d.ts +228 -0
  70. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/serialize.d.ts +70 -0
  71. package/dist/unpkg/dev-deprecated/declarations/-private/rest/find-record.d.ts +62 -0
  72. package/dist/unpkg/dev-deprecated/declarations/-private/rest/query.d.ts +53 -0
  73. package/dist/unpkg/dev-deprecated/declarations/-private/rest/save-record.d.ts +146 -0
  74. package/dist/unpkg/dev-deprecated/declarations/-private/string/inflect.d.ts +82 -0
  75. package/dist/unpkg/dev-deprecated/declarations/-private/string/inflections.d.ts +9 -0
  76. package/dist/unpkg/dev-deprecated/declarations/-private/string/transform.d.ts +77 -0
  77. package/dist/unpkg/dev-deprecated/declarations/-private.d.ts +1 -0
  78. package/dist/unpkg/dev-deprecated/declarations/active-record.d.ts +3 -0
  79. package/dist/unpkg/dev-deprecated/declarations/derivations.d.ts +27 -0
  80. package/dist/unpkg/dev-deprecated/declarations/handlers.d.ts +10 -0
  81. package/dist/unpkg/dev-deprecated/declarations/index.d.ts +208 -0
  82. package/dist/unpkg/dev-deprecated/declarations/json-api.d.ts +5 -0
  83. package/dist/unpkg/dev-deprecated/declarations/rest.d.ts +3 -0
  84. package/dist/unpkg/dev-deprecated/declarations/string.d.ts +14 -0
  85. package/dist/unpkg/dev-deprecated/derivations.js +30 -0
  86. package/dist/unpkg/dev-deprecated/handlers.js +317 -0
  87. package/dist/unpkg/dev-deprecated/index.js +361 -0
  88. package/dist/unpkg/dev-deprecated/inflect-BSG696t-.js +344 -0
  89. package/dist/unpkg/dev-deprecated/json-api.js +740 -0
  90. package/dist/unpkg/dev-deprecated/rest.js +393 -0
  91. package/dist/unpkg/dev-deprecated/string.js +1 -0
  92. package/dist/unpkg/prod/-private.js +7 -0
  93. package/dist/unpkg/prod/active-record.js +395 -0
  94. package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +22 -0
  95. package/dist/unpkg/prod/declarations/-private/active-record/find-record.d.ts +64 -0
  96. package/dist/unpkg/prod/declarations/-private/active-record/query.d.ts +53 -0
  97. package/dist/unpkg/prod/declarations/-private/active-record/save-record.d.ts +146 -0
  98. package/dist/unpkg/prod/declarations/-private/builder-utils.d.ts +4 -0
  99. package/dist/unpkg/prod/declarations/-private/handlers/auto-compress.d.ts +158 -0
  100. package/dist/unpkg/prod/declarations/-private/handlers/gated.d.ts +19 -0
  101. package/dist/unpkg/prod/declarations/-private/handlers/meta-doc.d.ts +47 -0
  102. package/dist/unpkg/prod/declarations/-private/handlers/utils.d.ts +41 -0
  103. package/dist/unpkg/prod/declarations/-private/json-api/-utils.d.ts +109 -0
  104. package/dist/unpkg/prod/declarations/-private/json-api/find-record.d.ts +84 -0
  105. package/dist/unpkg/prod/declarations/-private/json-api/query.d.ts +100 -0
  106. package/dist/unpkg/prod/declarations/-private/json-api/save-record.d.ts +228 -0
  107. package/dist/unpkg/prod/declarations/-private/json-api/serialize.d.ts +70 -0
  108. package/dist/unpkg/prod/declarations/-private/rest/find-record.d.ts +62 -0
  109. package/dist/unpkg/prod/declarations/-private/rest/query.d.ts +53 -0
  110. package/dist/unpkg/prod/declarations/-private/rest/save-record.d.ts +146 -0
  111. package/dist/unpkg/prod/declarations/-private/string/inflect.d.ts +82 -0
  112. package/dist/unpkg/prod/declarations/-private/string/inflections.d.ts +9 -0
  113. package/dist/unpkg/prod/declarations/-private/string/transform.d.ts +77 -0
  114. package/dist/unpkg/prod/declarations/-private.d.ts +1 -0
  115. package/dist/unpkg/prod/declarations/active-record.d.ts +3 -0
  116. package/dist/unpkg/prod/declarations/derivations.d.ts +27 -0
  117. package/dist/unpkg/prod/declarations/handlers.d.ts +10 -0
  118. package/dist/unpkg/prod/declarations/index.d.ts +208 -0
  119. package/dist/unpkg/prod/declarations/json-api.d.ts +5 -0
  120. package/dist/unpkg/prod/declarations/rest.d.ts +3 -0
  121. package/dist/unpkg/prod/declarations/string.d.ts +14 -0
  122. package/dist/unpkg/prod/derivations.js +30 -0
  123. package/dist/unpkg/prod/handlers.js +317 -0
  124. package/dist/unpkg/prod/index.js +361 -0
  125. package/dist/unpkg/prod/inflect-BSG696t-.js +344 -0
  126. package/dist/unpkg/prod/json-api.js +740 -0
  127. package/dist/unpkg/prod/rest.js +393 -0
  128. package/dist/unpkg/prod/string.js +1 -0
  129. package/dist/unpkg/prod-deprecated/-private.js +7 -0
  130. package/dist/unpkg/prod-deprecated/active-record.js +395 -0
  131. package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +22 -0
  132. package/dist/unpkg/prod-deprecated/declarations/-private/active-record/find-record.d.ts +64 -0
  133. package/dist/unpkg/prod-deprecated/declarations/-private/active-record/query.d.ts +53 -0
  134. package/dist/unpkg/prod-deprecated/declarations/-private/active-record/save-record.d.ts +146 -0
  135. package/dist/unpkg/prod-deprecated/declarations/-private/builder-utils.d.ts +4 -0
  136. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/auto-compress.d.ts +158 -0
  137. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/gated.d.ts +19 -0
  138. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/meta-doc.d.ts +47 -0
  139. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/utils.d.ts +41 -0
  140. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/-utils.d.ts +109 -0
  141. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/find-record.d.ts +84 -0
  142. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/query.d.ts +100 -0
  143. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/save-record.d.ts +228 -0
  144. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/serialize.d.ts +70 -0
  145. package/dist/unpkg/prod-deprecated/declarations/-private/rest/find-record.d.ts +62 -0
  146. package/dist/unpkg/prod-deprecated/declarations/-private/rest/query.d.ts +53 -0
  147. package/dist/unpkg/prod-deprecated/declarations/-private/rest/save-record.d.ts +146 -0
  148. package/dist/unpkg/prod-deprecated/declarations/-private/string/inflect.d.ts +82 -0
  149. package/dist/unpkg/prod-deprecated/declarations/-private/string/inflections.d.ts +9 -0
  150. package/dist/unpkg/prod-deprecated/declarations/-private/string/transform.d.ts +77 -0
  151. package/dist/unpkg/prod-deprecated/declarations/-private.d.ts +1 -0
  152. package/dist/unpkg/prod-deprecated/declarations/active-record.d.ts +3 -0
  153. package/dist/unpkg/prod-deprecated/declarations/derivations.d.ts +27 -0
  154. package/dist/unpkg/prod-deprecated/declarations/handlers.d.ts +10 -0
  155. package/dist/unpkg/prod-deprecated/declarations/index.d.ts +208 -0
  156. package/dist/unpkg/prod-deprecated/declarations/json-api.d.ts +5 -0
  157. package/dist/unpkg/prod-deprecated/declarations/rest.d.ts +3 -0
  158. package/dist/unpkg/prod-deprecated/declarations/string.d.ts +14 -0
  159. package/dist/unpkg/prod-deprecated/derivations.js +30 -0
  160. package/dist/unpkg/prod-deprecated/handlers.js +317 -0
  161. package/dist/unpkg/prod-deprecated/index.js +361 -0
  162. package/dist/unpkg/prod-deprecated/inflect-BSG696t-.js +344 -0
  163. package/dist/unpkg/prod-deprecated/json-api.js +740 -0
  164. package/dist/unpkg/prod-deprecated/rest.js +393 -0
  165. package/dist/unpkg/prod-deprecated/string.js +1 -0
  166. package/logos/README.md +2 -2
  167. package/logos/logo-yellow-slab.svg +1 -0
  168. package/logos/word-mark-black.svg +1 -0
  169. package/logos/word-mark-white.svg +1 -0
  170. package/package.json +4 -4
  171. package/logos/NCC-1701-a-blue.svg +0 -4
  172. package/logos/NCC-1701-a-gold.svg +0 -4
  173. package/logos/NCC-1701-a-gold_100.svg +0 -1
  174. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  175. package/logos/NCC-1701-a.svg +0 -4
  176. package/logos/docs-badge.svg +0 -2
  177. package/logos/ember-data-logo-dark.svg +0 -12
  178. package/logos/ember-data-logo-light.svg +0 -12
  179. package/logos/social1.png +0 -0
  180. package/logos/social2.png +0 -0
  181. package/logos/warp-drive-logo-dark.svg +0 -4
  182. package/logos/warp-drive-logo-gold.svg +0 -4
@@ -0,0 +1,393 @@
1
+ import { buildBaseURL, buildQueryParams } from './index.js';
2
+ import { p as pluralize, g as camelize } from "./inflect-BSG696t-.js";
3
+ import { e as extractCacheOptions, c as copyForwardUrlOptions } from "./builder-utils-Donkk-BZ.js";
4
+ import { recordIdentifierFor } from '@warp-drive-mirror/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 REST APIs.
10
+ *
11
+ * **Basic Usage**
12
+ *
13
+ * ```ts
14
+ * import { findRecord } from '@warp-drive-mirror/utilities/rest';
15
+ *
16
+ * const data = await store.request(findRecord('person', '1'));
17
+ * ```
18
+ *
19
+ * **With Options**
20
+ *
21
+ * ```ts
22
+ * import { findRecord } from '@warp-drive-mirror/utilities/rest';
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-mirror/utilities/rest';
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 camelCasing 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-mirror/utilities/rest';
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
+ */
60
+
61
+ function findRecord(arg1, arg2, arg3) {
62
+ const identifier = typeof arg1 === 'string' ? {
63
+ type: arg1,
64
+ id: arg2
65
+ } : arg1;
66
+ const options = (typeof arg1 === 'string' ? arg3 : arg2) || {};
67
+ const cacheOptions = extractCacheOptions(options);
68
+ const urlOptions = {
69
+ identifier,
70
+ op: 'findRecord',
71
+ resourcePath: pluralize(camelize(identifier.type))
72
+ };
73
+ copyForwardUrlOptions(urlOptions, options);
74
+ const url = buildBaseURL(urlOptions);
75
+ const headers = new Headers();
76
+ headers.append('Accept', 'application/json;charset=utf-8');
77
+ return {
78
+ url: options.include?.length ? `${url}?${buildQueryParams({
79
+ include: options.include
80
+ }, options.urlParamsSettings)}` : url,
81
+ method: 'GET',
82
+ headers,
83
+ cacheOptions,
84
+ op: 'findRecord',
85
+ records: [identifier]
86
+ };
87
+ }
88
+
89
+ /** @deprecated use {@link ReactiveDataDocument} instead */
90
+
91
+ /**
92
+ * Builds request options to query for resources, usually by a primary
93
+ * type, configured for the url and header expectations of most REST APIs.
94
+ *
95
+ * **Basic Usage**
96
+ *
97
+ * ```ts
98
+ * import { query } from '@warp-drive-mirror/utilities/rest';
99
+ *
100
+ * const data = await store.request(query('person'));
101
+ * ```
102
+ *
103
+ * **With Query Params**
104
+ *
105
+ * ```ts
106
+ * import { query } from '@warp-drive-mirror/utilities/rest';
107
+ *
108
+ * const options = query('person', { include: ['pets', 'friends'] });
109
+ * const data = await store.request(options);
110
+ * ```
111
+ *
112
+ * **Supplying Options to Modify the Request Behavior**
113
+ *
114
+ * The following options are supported:
115
+ *
116
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
117
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
118
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
119
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
120
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
121
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
122
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
123
+ * defaulting to `false` if none is configured.
124
+ * - `urlParamsSettings` - an object containing options for how to serialize the query params (see `buildQueryParams`)
125
+ *
126
+ * ```ts
127
+ * import { query } from '@warp-drive-mirror/utilities/rest';
128
+ *
129
+ * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
130
+ * const data = await store.request(options);
131
+ * ```
132
+ *
133
+ * @public
134
+ * @param identifier
135
+ * @param query
136
+ * @param options
137
+ */
138
+
139
+ function query(type,
140
+ // eslint-disable-next-line @typescript-eslint/no-shadow
141
+ query = {}, options = {}) {
142
+ const cacheOptions = extractCacheOptions(options);
143
+ const urlOptions = {
144
+ identifier: {
145
+ type
146
+ },
147
+ op: 'query',
148
+ resourcePath: pluralize(camelize(type))
149
+ };
150
+ copyForwardUrlOptions(urlOptions, options);
151
+ const url = buildBaseURL(urlOptions);
152
+ const headers = new Headers();
153
+ headers.append('Accept', 'application/json;charset=utf-8');
154
+ const queryString = buildQueryParams(query, options.urlParamsSettings);
155
+ return {
156
+ url: queryString ? `${url}?${queryString}` : url,
157
+ method: 'GET',
158
+ headers,
159
+ cacheOptions,
160
+ op: 'query'
161
+ };
162
+ }
163
+ function isExisting(identifier) {
164
+ return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;
165
+ }
166
+
167
+ /**
168
+ * Builds request options to delete record for resources,
169
+ * configured for the url, method and header expectations of REST APIs.
170
+ *
171
+ * **Basic Usage**
172
+ *
173
+ * ```ts
174
+ * import { deleteRecord } from '@warp-drive-mirror/utilities/rest';
175
+ *
176
+ * const person = store.peekRecord('person', '1');
177
+ *
178
+ * // mark record as deleted
179
+ * store.deleteRecord(person);
180
+ *
181
+ * // persist deletion
182
+ * const data = await store.request(deleteRecord(person));
183
+ * ```
184
+ *
185
+ * **Supplying Options to Modify the Request Behavior**
186
+ *
187
+ * The following options are supported:
188
+ *
189
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
190
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
191
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
192
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
193
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
194
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
195
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
196
+ * defaulting to `false` if none is configured.
197
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
198
+ *
199
+ * ```ts
200
+ * import { deleteRecord } from '@warp-drive-mirror/utilities/rest';
201
+ *
202
+ * const person = store.peekRecord('person', '1');
203
+ *
204
+ * // mark record as deleted
205
+ * store.deleteRecord(person);
206
+ *
207
+ * // persist deletion
208
+ * const options = deleteRecord(person, { namespace: 'api/v1' });
209
+ * const data = await store.request(options);
210
+ * ```
211
+ *
212
+ * @public
213
+ * @param record
214
+ * @param options
215
+ */
216
+
217
+ function deleteRecord(record, options = {}) {
218
+ const identifier = recordIdentifierFor(record);
219
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
220
+ if (!test) {
221
+ throw new Error(`Expected to be given a record instance`);
222
+ }
223
+ })(identifier) : {};
224
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
225
+ if (!test) {
226
+ throw new Error(`Cannot delete a record that does not have an associated type and id.`);
227
+ }
228
+ })(isExisting(identifier)) : {};
229
+ const urlOptions = {
230
+ identifier: identifier,
231
+ op: 'deleteRecord',
232
+ resourcePath: pluralize(camelize(identifier.type))
233
+ };
234
+ copyForwardUrlOptions(urlOptions, options);
235
+ const url = buildBaseURL(urlOptions);
236
+ const headers = new Headers();
237
+ headers.append('Accept', 'application/json;charset=utf-8');
238
+ return {
239
+ url,
240
+ method: 'DELETE',
241
+ headers,
242
+ op: 'deleteRecord',
243
+ data: {
244
+ record: identifier
245
+ },
246
+ records: [identifier]
247
+ };
248
+ }
249
+
250
+ /**
251
+ * Builds request options to create new record for resources,
252
+ * configured for the url, method and header expectations of most REST APIs.
253
+ *
254
+ * **Basic Usage**
255
+ *
256
+ * ```ts
257
+ * import { createRecord } from '@warp-drive-mirror/utilities/rest';
258
+ *
259
+ * const person = store.createRecord('person', { name: 'Ted' });
260
+ * const data = await store.request(createRecord(person));
261
+ * ```
262
+ *
263
+ * **Supplying Options to Modify the Request Behavior**
264
+ *
265
+ * The following options are supported:
266
+ *
267
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
268
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
269
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
270
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
271
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
272
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
273
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
274
+ * defaulting to `false` if none is configured.
275
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
276
+ *
277
+ * ```ts
278
+ * import { createRecord } from '@warp-drive-mirror/utilities/rest';
279
+ *
280
+ * const person = store.createRecord('person', { name: 'Ted' });
281
+ * const options = createRecord(person, { namespace: 'api/v1' });
282
+ * const data = await store.request(options);
283
+ * ```
284
+ *
285
+ * @public
286
+ * @param record
287
+ * @param options
288
+ */
289
+
290
+ function createRecord(record, options = {}) {
291
+ const identifier = recordIdentifierFor(record);
292
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
293
+ if (!test) {
294
+ throw new Error(`Expected to be given a record instance`);
295
+ }
296
+ })(identifier) : {};
297
+ const urlOptions = {
298
+ identifier: identifier,
299
+ op: 'createRecord',
300
+ resourcePath: pluralize(camelize(identifier.type))
301
+ };
302
+ copyForwardUrlOptions(urlOptions, options);
303
+ const url = buildBaseURL(urlOptions);
304
+ const headers = new Headers();
305
+ headers.append('Accept', 'application/json;charset=utf-8');
306
+ return {
307
+ url,
308
+ method: 'POST',
309
+ headers,
310
+ op: 'createRecord',
311
+ data: {
312
+ record: identifier
313
+ },
314
+ records: [identifier]
315
+ };
316
+ }
317
+
318
+ /**
319
+ * Builds request options to update existing record for resources,
320
+ * configured for the url, method and header expectations of most REST APIs.
321
+ *
322
+ * **Basic Usage**
323
+ *
324
+ * ```ts
325
+ * import { updateRecord } from '@warp-drive-mirror/utilities/rest';
326
+ *
327
+ * const person = store.peekRecord('person', '1');
328
+ * person.name = 'Chris';
329
+ * const data = await store.request(updateRecord(person));
330
+ * ```
331
+ *
332
+ * **Supplying Options to Modify the Request Behavior**
333
+ *
334
+ * The following options are supported:
335
+ *
336
+ * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
337
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
338
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
339
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
340
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
341
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
342
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
343
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
344
+ * defaulting to `false` if none is configured.
345
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
346
+ *
347
+ * ```ts
348
+ * import { updateRecord } from '@warp-drive-mirror/utilities/rest';
349
+ *
350
+ * const person = store.peekRecord('person', '1');
351
+ * person.name = 'Chris';
352
+ * const options = updateRecord(person, { patch: true });
353
+ * const data = await store.request(options);
354
+ * ```
355
+ *
356
+ * @public
357
+ * @param record
358
+ * @param options
359
+ */
360
+
361
+ function updateRecord(record, options = {}) {
362
+ const identifier = recordIdentifierFor(record);
363
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
364
+ if (!test) {
365
+ throw new Error(`Expected to be given a record instance`);
366
+ }
367
+ })(identifier) : {};
368
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
369
+ if (!test) {
370
+ throw new Error(`Cannot update a record that does not have an associated type and id.`);
371
+ }
372
+ })(isExisting(identifier)) : {};
373
+ const urlOptions = {
374
+ identifier: identifier,
375
+ op: 'updateRecord',
376
+ resourcePath: pluralize(camelize(identifier.type))
377
+ };
378
+ copyForwardUrlOptions(urlOptions, options);
379
+ const url = buildBaseURL(urlOptions);
380
+ const headers = new Headers();
381
+ headers.append('Accept', 'application/json;charset=utf-8');
382
+ return {
383
+ url,
384
+ method: options.patch ? 'PATCH' : 'PUT',
385
+ headers,
386
+ op: 'updateRecord',
387
+ data: {
388
+ record: identifier
389
+ },
390
+ records: [identifier]
391
+ };
392
+ }
393
+ export { createRecord, deleteRecord, findRecord, query, updateRecord };
@@ -0,0 +1 @@
1
+ export { g as camelize, h as capitalize, d as clear, e as clearRules, f as dasherize, i as irregular, l as loadIrregular, c as loadUncountable, b as plural, p as pluralize, r as resetToDefaults, k as setMaxLRUCacheSize, a as singular, s as singularize, u as uncountable, j as underscore } from "./inflect-BSG696t-.js";
@@ -0,0 +1,7 @@
1
+ const defaultRules = {
2
+ plurals: [[/$/, 's'], [/s$/i, 's'], [/^(ax|test)is$/i, '$1es'], [/(octop|vir)us$/i, '$1i'], [/(octop|vir)i$/i, '$1i'], [/(alias|status|bonus)$/i, '$1es'], [/(bu)s$/i, '$1ses'], [/(buffal|tomat)o$/i, '$1oes'], [/([ti])um$/i, '$1a'], [/([ti])a$/i, '$1a'], [/sis$/i, 'ses'], [/(?:([^f])fe|([lr])f)$/i, '$1$2ves'], [/(hive)$/i, '$1s'], [/([^aeiouy]|qu)y$/i, '$1ies'], [/(x|ch|ss|sh)$/i, '$1es'], [/(matr|vert|ind)(?:ix|ex)$/i, '$1ices'], [/^(m|l)ouse$/i, '$1ice'], [/^(m|l)ice$/i, '$1ice'], [/^(ox)$/i, '$1en'], [/^(oxen)$/i, '$1'], [/(quiz)$/i, '$1zes']],
3
+ singular: [[/s$/i, ''], [/(ss)$/i, '$1'], [/(n)ews$/i, '$1ews'], [/([ti])a$/i, '$1um'], [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1sis'], [/(^analy)(sis|ses)$/i, '$1sis'], [/([^f])ves$/i, '$1fe'], [/(hive)s$/i, '$1'], [/(tive)s$/i, '$1'], [/([lr])ves$/i, '$1f'], [/([^aeiouy]|qu)ies$/i, '$1y'], [/(s)eries$/i, '$1eries'], [/(m)ovies$/i, '$1ovie'], [/(x|ch|ss|sh)es$/i, '$1'], [/^(m|l)ice$/i, '$1ouse'], [/(bus)(es)?$/i, '$1'], [/(o)es$/i, '$1'], [/(shoe)s$/i, '$1'], [/(cris|test)(is|es)$/i, '$1is'], [/^(a)x[ie]s$/i, '$1xis'], [/(octop|vir)(us|i)$/i, '$1us'], [/(alias|status|bonus)(es)?$/i, '$1'], [/^(ox)en/i, '$1'], [/(vert|ind)ices$/i, '$1ex'], [/(matr)ices$/i, '$1ix'], [/(quiz)zes$/i, '$1'], [/(database)s$/i, '$1']],
4
+ irregularPairs: [['person', 'people'], ['man', 'men'], ['child', 'children'], ['sex', 'sexes'], ['move', 'moves'], ['cow', 'kine'], ['zombie', 'zombies']],
5
+ uncountable: ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'police']
6
+ };
7
+ export { defaultRules as InflectionRuleDefaults };