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