@ember-data/request-utils 5.4.0-alpha.32 → 5.4.0-alpha.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ember-data/request-utils",
3
3
  "description": "Request Building Utilities for use with EmberData",
4
- "version": "5.4.0-alpha.32",
4
+ "version": "5.4.0-alpha.33",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "author": "Chris Thoburn <runspired@users.noreply.github.com>",
@@ -22,7 +22,7 @@
22
22
  "extends": "../../package.json"
23
23
  },
24
24
  "peerDependencies": {
25
- "@warp-drive/core-types": "0.0.0-alpha.18"
25
+ "@warp-drive/core-types": "0.0.0-alpha.19"
26
26
  },
27
27
  "dependencies": {
28
28
  "ember-cli-babel": "^8.2.0",
@@ -56,8 +56,8 @@
56
56
  "@glimmer/component": "^1.1.2",
57
57
  "@rollup/plugin-babel": "^6.0.4",
58
58
  "@rollup/plugin-node-resolve": "^15.2.3",
59
- "@warp-drive/core-types": "0.0.0-alpha.18",
60
- "@warp-drive/internal-config": "5.4.0-alpha.32",
59
+ "@warp-drive/core-types": "0.0.0-alpha.19",
60
+ "@warp-drive/internal-config": "5.4.0-alpha.33",
61
61
  "ember-source": "~5.6.0",
62
62
  "rollup": "^4.9.6",
63
63
  "typescript": "^5.3.3",
@@ -1,469 +1,472 @@
1
- import type { Cache } from '@warp-drive/core-types/cache';
2
- import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier';
3
- import type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from '@warp-drive/core-types/params';
4
- import type { ImmutableRequestInfo, ResponseInfo } from '@warp-drive/core-types/request';
5
- type Store = {
6
- cache: Cache;
7
- };
8
- /**
9
- * Simple utility function to assist in url building,
10
- * query params, and other common request operations.
11
- *
12
- * These primitives may be used directly or composed
13
- * by request builders to provide a consistent interface
14
- * for building requests.
15
- *
16
- * For instance:
17
- *
18
- * ```ts
19
- * import { buildBaseURL, buildQueryParams } from '@ember-data/request-utils';
20
- *
21
- * const baseURL = buildBaseURL({
22
- * host: 'https://api.example.com',
23
- * namespace: 'api/v1',
24
- * resourcePath: 'emberDevelopers',
25
- * op: 'query',
26
- * identifier: { type: 'ember-developer' }
27
- * });
28
- * const url = `${baseURL}?${buildQueryParams({ name: 'Chris', include:['pets'] })}`;
29
- * // => 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris'
30
- * ```
31
- *
32
- * This is useful, but not as useful as the REST request builder for query which is sugar
33
- * over this (and more!):
34
- *
35
- * ```ts
36
- * import { query } from '@ember-data/rest/request';
37
- *
38
- * const options = query('ember-developer', { name: 'Chris', include:['pets'] });
39
- * // => { url: 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' }
40
- * // Note: options will also include other request options like headers, method, etc.
41
- * ```
42
- *
43
- * @module @ember-data/request-utils
44
- * @main @ember-data/request-utils
45
- * @public
46
- */
47
- export interface BuildURLConfig {
48
- host: string | null;
49
- namespace: string | null;
50
- }
51
- /**
52
- * Sets the global configuration for `buildBaseURL`
53
- * for host and namespace values for the application.
54
- *
55
- * These values may still be overridden by passing
56
- * them to buildBaseURL directly.
57
- *
58
- * This method may be called as many times as needed.
59
- * host values of `''` or `'/'` are equivalent.
60
- *
61
- * Except for the value of `/` as host, host should not
62
- * end with `/`.
63
- *
64
- * namespace should not start or end with a `/`.
65
- *
66
- * ```ts
67
- * type BuildURLConfig = {
68
- * host: string;
69
- * namespace: string'
70
- * }
71
- * ```
72
- *
73
- * Example:
74
- *
75
- * ```ts
76
- * import { setBuildURLConfig } from '@ember-data/request-utils';
77
- *
78
- * setBuildURLConfig({
79
- * host: 'https://api.example.com',
80
- * namespace: 'api/v1'
81
- * });
82
- * ```
83
- *
84
- * @method setBuildURLConfig
85
- * @static
86
- * @public
87
- * @for @ember-data/request-utils
88
- * @param {BuildURLConfig} config
89
- * @return void
90
- */
91
- export declare function setBuildURLConfig(config: BuildURLConfig): void;
92
- export interface FindRecordUrlOptions {
93
- op: 'findRecord';
94
- identifier: {
95
- type: string;
96
- id: string;
97
- };
98
- resourcePath?: string;
99
- host?: string;
100
- namespace?: string;
101
- }
102
- export interface QueryUrlOptions {
103
- op: 'query';
104
- identifier: {
105
- type: string;
106
- };
107
- resourcePath?: string;
108
- host?: string;
109
- namespace?: string;
110
- }
111
- export interface FindManyUrlOptions {
112
- op: 'findMany';
113
- identifiers: {
114
- type: string;
115
- id: string;
116
- }[];
117
- resourcePath?: string;
118
- host?: string;
119
- namespace?: string;
120
- }
121
- export interface FindRelatedCollectionUrlOptions {
122
- op: 'findRelatedCollection';
123
- identifier: {
124
- type: string;
125
- id: string;
126
- };
127
- fieldPath: string;
128
- resourcePath?: string;
129
- host?: string;
130
- namespace?: string;
131
- }
132
- export interface FindRelatedResourceUrlOptions {
133
- op: 'findRelatedRecord';
134
- identifier: {
135
- type: string;
136
- id: string;
137
- };
138
- fieldPath: string;
139
- resourcePath?: string;
140
- host?: string;
141
- namespace?: string;
142
- }
143
- export interface CreateRecordUrlOptions {
144
- op: 'createRecord';
145
- identifier: {
146
- type: string;
147
- };
148
- resourcePath?: string;
149
- host?: string;
150
- namespace?: string;
151
- }
152
- export interface UpdateRecordUrlOptions {
153
- op: 'updateRecord';
154
- identifier: {
155
- type: string;
156
- id: string;
157
- };
158
- resourcePath?: string;
159
- host?: string;
160
- namespace?: string;
161
- }
162
- export interface DeleteRecordUrlOptions {
163
- op: 'deleteRecord';
164
- identifier: {
165
- type: string;
166
- id: string;
167
- };
168
- resourcePath?: string;
169
- host?: string;
170
- namespace?: string;
171
- }
172
- export interface GenericUrlOptions {
173
- resourcePath: string;
174
- host?: string;
175
- namespace?: string;
176
- }
177
- export type UrlOptions = FindRecordUrlOptions | QueryUrlOptions | FindManyUrlOptions | FindRelatedCollectionUrlOptions | FindRelatedResourceUrlOptions | CreateRecordUrlOptions | UpdateRecordUrlOptions | DeleteRecordUrlOptions | GenericUrlOptions;
178
- /**
179
- * Builds a URL for a request based on the provided options.
180
- * Does not include support for building query params (see `buildQueryParams`)
181
- * so that it may be composed cleanly with other query-params strategies.
182
- *
183
- * Usage:
184
- *
185
- * ```ts
186
- * import { buildBaseURL } from '@ember-data/request-utils';
187
- *
188
- * const url = buildBaseURL({
189
- * host: 'https://api.example.com',
190
- * namespace: 'api/v1',
191
- * resourcePath: 'emberDevelopers',
192
- * op: 'query',
193
- * identifier: { type: 'ember-developer' }
194
- * });
195
- *
196
- * // => 'https://api.example.com/api/v1/emberDevelopers'
197
- * ```
198
- *
199
- * On the surface this may seem like a lot of work to do something simple, but
200
- * it is designed to be composable with other utilities and interfaces that the
201
- * average product engineer will never need to see or use.
202
- *
203
- * A few notes:
204
- *
205
- * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.
206
- * - `host` and `namespace` are optional, but if they are not provided, the values globally
207
- * configured via `setBuildURLConfig` will be used.
208
- * - `op` is required and must be one of the following:
209
- * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'
210
- * - Depending on the value of `op`, `identifier` or `identifiers` will be required.
211
- *
212
- * @method buildBaseURL
213
- * @static
214
- * @public
215
- * @for @ember-data/request-utils
216
- * @param urlOptions
217
- * @return string
218
- */
219
- export declare function buildBaseURL(urlOptions: UrlOptions): string;
220
- /**
221
- * filter out keys of an object that have falsy values or point to empty arrays
222
- * returning a new object with only those keys that have truthy values / non-empty arrays
223
- *
224
- * @method filterEmpty
225
- * @static
226
- * @public
227
- * @for @ember-data/request-utils
228
- * @param {Record<string, Serializable>} source object to filter keys with empty values from
229
- * @return {Record<string, Serializable>} A new object with the keys that contained empty values removed
230
- */
231
- export declare function filterEmpty(source: Record<string, Serializable>): Record<string, Serializable>;
232
- /**
233
- * Sorts query params by both key and value returning a new URLSearchParams
234
- * object with the keys inserted in sorted order.
235
- *
236
- * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
237
- *
238
- * Options:
239
- * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
240
- *
241
- * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2`
242
- * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2`
243
- * 'repeat': appends the key for every value e.g. `&ids=1&ids=2`
244
- * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
245
- *
246
- * @method sortQueryParams
247
- * @static
248
- * @public
249
- * @for @ember-data/request-utils
250
- * @param {URLSearchParams | object} params
251
- * @param {object} options
252
- * @return {URLSearchParams} A URLSearchParams with keys inserted in sorted order
253
- */
254
- export declare function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams;
255
- /**
256
- * Sorts query params by both key and value, returning a query params string
257
- *
258
- * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
259
- *
260
- * Options:
261
- * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
262
- *
263
- * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
264
- * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
265
- * 'repeat': appends the key for every value e.g. `ids=1&ids=2`
266
- * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
267
- *
268
- * @method buildQueryParams
269
- * @static
270
- * @public
271
- * @for @ember-data/request-utils
272
- * @param {URLSearchParams | object} params
273
- * @param {object} [options]
274
- * @return {string} A sorted query params string without the leading `?`
275
- */
276
- export declare function buildQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string;
277
- export interface CacheControlValue {
278
- immutable?: boolean;
279
- 'max-age'?: number;
280
- 'must-revalidate'?: boolean;
281
- 'must-understand'?: boolean;
282
- 'no-cache'?: boolean;
283
- 'no-store'?: boolean;
284
- 'no-transform'?: boolean;
285
- 'only-if-cached'?: boolean;
286
- private?: boolean;
287
- 'proxy-revalidate'?: boolean;
288
- public?: boolean;
289
- 's-maxage'?: number;
290
- 'stale-if-error'?: number;
291
- 'stale-while-revalidate'?: number;
292
- }
293
- /**
294
- * Parses a string Cache-Control header value into an object with the following structure:
295
- *
296
- * ```ts
297
- * interface CacheControlValue {
298
- * immutable?: boolean;
299
- * 'max-age'?: number;
300
- * 'must-revalidate'?: boolean;
301
- * 'must-understand'?: boolean;
302
- * 'no-cache'?: boolean;
303
- * 'no-store'?: boolean;
304
- * 'no-transform'?: boolean;
305
- * 'only-if-cached'?: boolean;
306
- * private?: boolean;
307
- * 'proxy-revalidate'?: boolean;
308
- * public?: boolean;
309
- * 's-maxage'?: number;
310
- * 'stale-if-error'?: number;
311
- * 'stale-while-revalidate'?: number;
312
- * }
313
- * ```
314
- * @method parseCacheControl
315
- * @static
316
- * @public
317
- * @for @ember-data/request-utils
318
- * @param {string} header
319
- * @return {CacheControlValue}
320
- */
321
- export declare function parseCacheControl(header: string): CacheControlValue;
322
- export type LifetimesConfig = {
323
- apiCacheSoftExpires: number;
324
- apiCacheHardExpires: number;
325
- };
326
- /**
327
- * A basic LifetimesService that can be added to the Store service.
328
- *
329
- * Determines staleness based on time since the request was last received from the API
330
- * using the `date` header.
331
- *
332
- * Invalidates any request for which `cacheOptions.types` was provided when a createRecord
333
- * request for that type is successful.
334
- *
335
- * This allows the Store's CacheHandler to determine if a request is expired and
336
- * should be refetched upon next request.
337
- *
338
- * The `Fetch` handler provided by `@ember-data/request/fetch` will automatically
339
- * add the `date` header to responses if it is not present.
340
- *
341
- * Note: Date headers do not have millisecond precision, so expiration times should
342
- * generally be larger than 1000ms.
343
- *
344
- * Usage:
345
- *
346
- * ```ts
347
- * import { LifetimesService } from '@ember-data/request-utils';
348
- * import DataStore from '@ember-data/store';
349
- *
350
- * // ...
351
- *
352
- * export class Store extends DataStore {
353
- * constructor(args) {
354
- * super(args);
355
- * this.lifetimes = new LifetimesService({ apiCacheSoftExpires: 30_000, apiCacheHardExpires: 60_000 });
356
- * }
357
- * }
358
- * ```
359
- *
360
- * @class LifetimesService
361
- * @public
362
- * @module @ember-data/request-utils
363
- */
364
- export declare class LifetimesService {
365
- config: LifetimesConfig;
366
- _stores: WeakMap<Store, {
367
- invalidated: Set<string>;
368
- types: Map<string, Set<string>>;
369
- }>;
370
- _getStore(store: Store): {
371
- invalidated: Set<string>;
372
- types: Map<string, Set<string>>;
373
- };
374
- constructor(config: LifetimesConfig);
375
- /**
376
- * Invalidate a request by its identifier for a given store instance.
377
- *
378
- * While the store argument may seem redundant, the lifetimes service
379
- * is designed to be shared across multiple stores / forks
380
- * of the store.
381
- *
382
- * ```ts
383
- * store.lifetimes.invalidateRequest(store, identifier);
384
- * ```
385
- *
386
- * @method invalidateRequest
387
- * @public
388
- * @param {StableDocumentIdentifier} identifier
389
- * @param {Store} store
390
- */
391
- invalidateRequest(identifier: StableDocumentIdentifier, store: Store): void;
392
- /**
393
- * Invalidate all requests associated to a specific type
394
- * for a given store instance.
395
- *
396
- * While the store argument may seem redundant, the lifetimes service
397
- * is designed to be shared across multiple stores / forks
398
- * of the store.
399
- *
400
- * This invalidation is done automatically when using this service
401
- * for both the CacheHandler and the LegacyNetworkHandler.
402
- *
403
- * ```ts
404
- * store.lifetimes.invalidateRequestsForType(store, 'person');
405
- * ```
406
- *
407
- * @method invalidateRequestsForType
408
- * @public
409
- * @param {string} type
410
- * @param {Store} store
411
- */
412
- invalidateRequestsForType(type: string, store: Store): void;
413
- /**
414
- * Invoked when a request has been fulfilled from the configured request handlers.
415
- * This is invoked by the CacheHandler for both foreground and background requests
416
- * once the cache has been updated.
417
- *
418
- * Note, this is invoked by the CacheHandler regardless of whether
419
- * the request has a cache-key.
420
- *
421
- * This method should not be invoked directly by consumers.
422
- *
423
- * @method didRequest
424
- * @public
425
- * @param {ImmutableRequestInfo} request
426
- * @param {ImmutableResponse} response
427
- * @param {Store} store
428
- * @param {StableDocumentIdentifier | null} identifier
429
- * @return {void}
430
- */
431
- didRequest(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier: StableDocumentIdentifier | null, store: Store): void;
432
- /**
433
- * Invoked to determine if the request may be fulfilled from cache
434
- * if possible.
435
- *
436
- * Note, this is only invoked by the CacheHandler if the request has
437
- * a cache-key.
438
- *
439
- * If no cache entry is found or the entry is hard expired,
440
- * the request will be fulfilled from the configured request handlers
441
- * and the cache will be updated before returning the response.
442
- *
443
- * @method isHardExpired
444
- * @public
445
- * @param {StableDocumentIdentifier} identifier
446
- * @param {Store} store
447
- * @return {boolean} true if the request is considered hard expired
448
- */
449
- isHardExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
450
- /**
451
- * Invoked if `isHardExpired` is false to determine if the request
452
- * should be update behind the scenes if cache data is already available.
453
- *
454
- * Note, this is only invoked by the CacheHandler if the request has
455
- * a cache-key.
456
- *
457
- * If true, the request will be fulfilled from cache while a backgrounded
458
- * request is made to update the cache via the configured request handlers.
459
- *
460
- * @method isSoftExpired
461
- * @public
462
- * @param {StableDocumentIdentifier} identifier
463
- * @param {Store} store
464
- * @return {boolean} true if the request is considered soft expired
465
- */
466
- isSoftExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
467
- }
468
- export {};
469
- //# sourceMappingURL=index.d.ts.map
1
+
2
+ declare module '@ember-data/request-utils' {
3
+ import type { Cache } from '@warp-drive/core-types/cache';
4
+ import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier';
5
+ import type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from '@warp-drive/core-types/params';
6
+ import type { ImmutableRequestInfo, ResponseInfo } from '@warp-drive/core-types/request';
7
+ type Store = {
8
+ cache: Cache;
9
+ };
10
+ /**
11
+ * Simple utility function to assist in url building,
12
+ * query params, and other common request operations.
13
+ *
14
+ * These primitives may be used directly or composed
15
+ * by request builders to provide a consistent interface
16
+ * for building requests.
17
+ *
18
+ * For instance:
19
+ *
20
+ * ```ts
21
+ * import { buildBaseURL, buildQueryParams } from '@ember-data/request-utils';
22
+ *
23
+ * const baseURL = buildBaseURL({
24
+ * host: 'https://api.example.com',
25
+ * namespace: 'api/v1',
26
+ * resourcePath: 'emberDevelopers',
27
+ * op: 'query',
28
+ * identifier: { type: 'ember-developer' }
29
+ * });
30
+ * const url = `${baseURL}?${buildQueryParams({ name: 'Chris', include:['pets'] })}`;
31
+ * // => 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris'
32
+ * ```
33
+ *
34
+ * This is useful, but not as useful as the REST request builder for query which is sugar
35
+ * over this (and more!):
36
+ *
37
+ * ```ts
38
+ * import { query } from '@ember-data/rest/request';
39
+ *
40
+ * const options = query('ember-developer', { name: 'Chris', include:['pets'] });
41
+ * // => { url: 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' }
42
+ * // Note: options will also include other request options like headers, method, etc.
43
+ * ```
44
+ *
45
+ * @module @ember-data/request-utils
46
+ * @main @ember-data/request-utils
47
+ * @public
48
+ */
49
+ export interface BuildURLConfig {
50
+ host: string | null;
51
+ namespace: string | null;
52
+ }
53
+ /**
54
+ * Sets the global configuration for `buildBaseURL`
55
+ * for host and namespace values for the application.
56
+ *
57
+ * These values may still be overridden by passing
58
+ * them to buildBaseURL directly.
59
+ *
60
+ * This method may be called as many times as needed.
61
+ * host values of `''` or `'/'` are equivalent.
62
+ *
63
+ * Except for the value of `/` as host, host should not
64
+ * end with `/`.
65
+ *
66
+ * namespace should not start or end with a `/`.
67
+ *
68
+ * ```ts
69
+ * type BuildURLConfig = {
70
+ * host: string;
71
+ * namespace: string'
72
+ * }
73
+ * ```
74
+ *
75
+ * Example:
76
+ *
77
+ * ```ts
78
+ * import { setBuildURLConfig } from '@ember-data/request-utils';
79
+ *
80
+ * setBuildURLConfig({
81
+ * host: 'https://api.example.com',
82
+ * namespace: 'api/v1'
83
+ * });
84
+ * ```
85
+ *
86
+ * @method setBuildURLConfig
87
+ * @static
88
+ * @public
89
+ * @for @ember-data/request-utils
90
+ * @param {BuildURLConfig} config
91
+ * @return void
92
+ */
93
+ export declare function setBuildURLConfig(config: BuildURLConfig): void;
94
+ export interface FindRecordUrlOptions {
95
+ op: 'findRecord';
96
+ identifier: {
97
+ type: string;
98
+ id: string;
99
+ };
100
+ resourcePath?: string;
101
+ host?: string;
102
+ namespace?: string;
103
+ }
104
+ export interface QueryUrlOptions {
105
+ op: 'query';
106
+ identifier: {
107
+ type: string;
108
+ };
109
+ resourcePath?: string;
110
+ host?: string;
111
+ namespace?: string;
112
+ }
113
+ export interface FindManyUrlOptions {
114
+ op: 'findMany';
115
+ identifiers: {
116
+ type: string;
117
+ id: string;
118
+ }[];
119
+ resourcePath?: string;
120
+ host?: string;
121
+ namespace?: string;
122
+ }
123
+ export interface FindRelatedCollectionUrlOptions {
124
+ op: 'findRelatedCollection';
125
+ identifier: {
126
+ type: string;
127
+ id: string;
128
+ };
129
+ fieldPath: string;
130
+ resourcePath?: string;
131
+ host?: string;
132
+ namespace?: string;
133
+ }
134
+ export interface FindRelatedResourceUrlOptions {
135
+ op: 'findRelatedRecord';
136
+ identifier: {
137
+ type: string;
138
+ id: string;
139
+ };
140
+ fieldPath: string;
141
+ resourcePath?: string;
142
+ host?: string;
143
+ namespace?: string;
144
+ }
145
+ export interface CreateRecordUrlOptions {
146
+ op: 'createRecord';
147
+ identifier: {
148
+ type: string;
149
+ };
150
+ resourcePath?: string;
151
+ host?: string;
152
+ namespace?: string;
153
+ }
154
+ export interface UpdateRecordUrlOptions {
155
+ op: 'updateRecord';
156
+ identifier: {
157
+ type: string;
158
+ id: string;
159
+ };
160
+ resourcePath?: string;
161
+ host?: string;
162
+ namespace?: string;
163
+ }
164
+ export interface DeleteRecordUrlOptions {
165
+ op: 'deleteRecord';
166
+ identifier: {
167
+ type: string;
168
+ id: string;
169
+ };
170
+ resourcePath?: string;
171
+ host?: string;
172
+ namespace?: string;
173
+ }
174
+ export interface GenericUrlOptions {
175
+ resourcePath: string;
176
+ host?: string;
177
+ namespace?: string;
178
+ }
179
+ export type UrlOptions = FindRecordUrlOptions | QueryUrlOptions | FindManyUrlOptions | FindRelatedCollectionUrlOptions | FindRelatedResourceUrlOptions | CreateRecordUrlOptions | UpdateRecordUrlOptions | DeleteRecordUrlOptions | GenericUrlOptions;
180
+ /**
181
+ * Builds a URL for a request based on the provided options.
182
+ * Does not include support for building query params (see `buildQueryParams`)
183
+ * so that it may be composed cleanly with other query-params strategies.
184
+ *
185
+ * Usage:
186
+ *
187
+ * ```ts
188
+ * import { buildBaseURL } from '@ember-data/request-utils';
189
+ *
190
+ * const url = buildBaseURL({
191
+ * host: 'https://api.example.com',
192
+ * namespace: 'api/v1',
193
+ * resourcePath: 'emberDevelopers',
194
+ * op: 'query',
195
+ * identifier: { type: 'ember-developer' }
196
+ * });
197
+ *
198
+ * // => 'https://api.example.com/api/v1/emberDevelopers'
199
+ * ```
200
+ *
201
+ * On the surface this may seem like a lot of work to do something simple, but
202
+ * it is designed to be composable with other utilities and interfaces that the
203
+ * average product engineer will never need to see or use.
204
+ *
205
+ * A few notes:
206
+ *
207
+ * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.
208
+ * - `host` and `namespace` are optional, but if they are not provided, the values globally
209
+ * configured via `setBuildURLConfig` will be used.
210
+ * - `op` is required and must be one of the following:
211
+ * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'
212
+ * - Depending on the value of `op`, `identifier` or `identifiers` will be required.
213
+ *
214
+ * @method buildBaseURL
215
+ * @static
216
+ * @public
217
+ * @for @ember-data/request-utils
218
+ * @param urlOptions
219
+ * @return string
220
+ */
221
+ export declare function buildBaseURL(urlOptions: UrlOptions): string;
222
+ /**
223
+ * filter out keys of an object that have falsy values or point to empty arrays
224
+ * returning a new object with only those keys that have truthy values / non-empty arrays
225
+ *
226
+ * @method filterEmpty
227
+ * @static
228
+ * @public
229
+ * @for @ember-data/request-utils
230
+ * @param {Record<string, Serializable>} source object to filter keys with empty values from
231
+ * @return {Record<string, Serializable>} A new object with the keys that contained empty values removed
232
+ */
233
+ export declare function filterEmpty(source: Record<string, Serializable>): Record<string, Serializable>;
234
+ /**
235
+ * Sorts query params by both key and value returning a new URLSearchParams
236
+ * object with the keys inserted in sorted order.
237
+ *
238
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
239
+ *
240
+ * Options:
241
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
242
+ *
243
+ * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2`
244
+ * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2`
245
+ * 'repeat': appends the key for every value e.g. `&ids=1&ids=2`
246
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
247
+ *
248
+ * @method sortQueryParams
249
+ * @static
250
+ * @public
251
+ * @for @ember-data/request-utils
252
+ * @param {URLSearchParams | object} params
253
+ * @param {object} options
254
+ * @return {URLSearchParams} A URLSearchParams with keys inserted in sorted order
255
+ */
256
+ export declare function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams;
257
+ /**
258
+ * Sorts query params by both key and value, returning a query params string
259
+ *
260
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
261
+ *
262
+ * Options:
263
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
264
+ *
265
+ * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
266
+ * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
267
+ * 'repeat': appends the key for every value e.g. `ids=1&ids=2`
268
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
269
+ *
270
+ * @method buildQueryParams
271
+ * @static
272
+ * @public
273
+ * @for @ember-data/request-utils
274
+ * @param {URLSearchParams | object} params
275
+ * @param {object} [options]
276
+ * @return {string} A sorted query params string without the leading `?`
277
+ */
278
+ export declare function buildQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string;
279
+ export interface CacheControlValue {
280
+ immutable?: boolean;
281
+ 'max-age'?: number;
282
+ 'must-revalidate'?: boolean;
283
+ 'must-understand'?: boolean;
284
+ 'no-cache'?: boolean;
285
+ 'no-store'?: boolean;
286
+ 'no-transform'?: boolean;
287
+ 'only-if-cached'?: boolean;
288
+ private?: boolean;
289
+ 'proxy-revalidate'?: boolean;
290
+ public?: boolean;
291
+ 's-maxage'?: number;
292
+ 'stale-if-error'?: number;
293
+ 'stale-while-revalidate'?: number;
294
+ }
295
+ /**
296
+ * Parses a string Cache-Control header value into an object with the following structure:
297
+ *
298
+ * ```ts
299
+ * interface CacheControlValue {
300
+ * immutable?: boolean;
301
+ * 'max-age'?: number;
302
+ * 'must-revalidate'?: boolean;
303
+ * 'must-understand'?: boolean;
304
+ * 'no-cache'?: boolean;
305
+ * 'no-store'?: boolean;
306
+ * 'no-transform'?: boolean;
307
+ * 'only-if-cached'?: boolean;
308
+ * private?: boolean;
309
+ * 'proxy-revalidate'?: boolean;
310
+ * public?: boolean;
311
+ * 's-maxage'?: number;
312
+ * 'stale-if-error'?: number;
313
+ * 'stale-while-revalidate'?: number;
314
+ * }
315
+ * ```
316
+ * @method parseCacheControl
317
+ * @static
318
+ * @public
319
+ * @for @ember-data/request-utils
320
+ * @param {string} header
321
+ * @return {CacheControlValue}
322
+ */
323
+ export declare function parseCacheControl(header: string): CacheControlValue;
324
+ export type LifetimesConfig = {
325
+ apiCacheSoftExpires: number;
326
+ apiCacheHardExpires: number;
327
+ };
328
+ /**
329
+ * A basic LifetimesService that can be added to the Store service.
330
+ *
331
+ * Determines staleness based on time since the request was last received from the API
332
+ * using the `date` header.
333
+ *
334
+ * Invalidates any request for which `cacheOptions.types` was provided when a createRecord
335
+ * request for that type is successful.
336
+ *
337
+ * This allows the Store's CacheHandler to determine if a request is expired and
338
+ * should be refetched upon next request.
339
+ *
340
+ * The `Fetch` handler provided by `@ember-data/request/fetch` will automatically
341
+ * add the `date` header to responses if it is not present.
342
+ *
343
+ * Note: Date headers do not have millisecond precision, so expiration times should
344
+ * generally be larger than 1000ms.
345
+ *
346
+ * Usage:
347
+ *
348
+ * ```ts
349
+ * import { LifetimesService } from '@ember-data/request-utils';
350
+ * import DataStore from '@ember-data/store';
351
+ *
352
+ * // ...
353
+ *
354
+ * export class Store extends DataStore {
355
+ * constructor(args) {
356
+ * super(args);
357
+ * this.lifetimes = new LifetimesService({ apiCacheSoftExpires: 30_000, apiCacheHardExpires: 60_000 });
358
+ * }
359
+ * }
360
+ * ```
361
+ *
362
+ * @class LifetimesService
363
+ * @public
364
+ * @module @ember-data/request-utils
365
+ */
366
+ export declare class LifetimesService {
367
+ config: LifetimesConfig;
368
+ _stores: WeakMap<Store, {
369
+ invalidated: Set<string>;
370
+ types: Map<string, Set<string>>;
371
+ }>;
372
+ _getStore(store: Store): {
373
+ invalidated: Set<string>;
374
+ types: Map<string, Set<string>>;
375
+ };
376
+ constructor(config: LifetimesConfig);
377
+ /**
378
+ * Invalidate a request by its identifier for a given store instance.
379
+ *
380
+ * While the store argument may seem redundant, the lifetimes service
381
+ * is designed to be shared across multiple stores / forks
382
+ * of the store.
383
+ *
384
+ * ```ts
385
+ * store.lifetimes.invalidateRequest(store, identifier);
386
+ * ```
387
+ *
388
+ * @method invalidateRequest
389
+ * @public
390
+ * @param {StableDocumentIdentifier} identifier
391
+ * @param {Store} store
392
+ */
393
+ invalidateRequest(identifier: StableDocumentIdentifier, store: Store): void;
394
+ /**
395
+ * Invalidate all requests associated to a specific type
396
+ * for a given store instance.
397
+ *
398
+ * While the store argument may seem redundant, the lifetimes service
399
+ * is designed to be shared across multiple stores / forks
400
+ * of the store.
401
+ *
402
+ * This invalidation is done automatically when using this service
403
+ * for both the CacheHandler and the LegacyNetworkHandler.
404
+ *
405
+ * ```ts
406
+ * store.lifetimes.invalidateRequestsForType(store, 'person');
407
+ * ```
408
+ *
409
+ * @method invalidateRequestsForType
410
+ * @public
411
+ * @param {string} type
412
+ * @param {Store} store
413
+ */
414
+ invalidateRequestsForType(type: string, store: Store): void;
415
+ /**
416
+ * Invoked when a request has been fulfilled from the configured request handlers.
417
+ * This is invoked by the CacheHandler for both foreground and background requests
418
+ * once the cache has been updated.
419
+ *
420
+ * Note, this is invoked by the CacheHandler regardless of whether
421
+ * the request has a cache-key.
422
+ *
423
+ * This method should not be invoked directly by consumers.
424
+ *
425
+ * @method didRequest
426
+ * @public
427
+ * @param {ImmutableRequestInfo} request
428
+ * @param {ImmutableResponse} response
429
+ * @param {Store} store
430
+ * @param {StableDocumentIdentifier | null} identifier
431
+ * @return {void}
432
+ */
433
+ didRequest(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier: StableDocumentIdentifier | null, store: Store): void;
434
+ /**
435
+ * Invoked to determine if the request may be fulfilled from cache
436
+ * if possible.
437
+ *
438
+ * Note, this is only invoked by the CacheHandler if the request has
439
+ * a cache-key.
440
+ *
441
+ * If no cache entry is found or the entry is hard expired,
442
+ * the request will be fulfilled from the configured request handlers
443
+ * and the cache will be updated before returning the response.
444
+ *
445
+ * @method isHardExpired
446
+ * @public
447
+ * @param {StableDocumentIdentifier} identifier
448
+ * @param {Store} store
449
+ * @return {boolean} true if the request is considered hard expired
450
+ */
451
+ isHardExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
452
+ /**
453
+ * Invoked if `isHardExpired` is false to determine if the request
454
+ * should be update behind the scenes if cache data is already available.
455
+ *
456
+ * Note, this is only invoked by the CacheHandler if the request has
457
+ * a cache-key.
458
+ *
459
+ * If true, the request will be fulfilled from cache while a backgrounded
460
+ * request is made to update the cache via the configured request handlers.
461
+ *
462
+ * @method isSoftExpired
463
+ * @public
464
+ * @param {StableDocumentIdentifier} identifier
465
+ * @param {Store} store
466
+ * @return {boolean} true if the request is considered soft expired
467
+ */
468
+ isSoftExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
469
+ }
470
+ export {};
471
+ //# sourceMappingURL=index.d.ts.map
472
+ }