@warp-drive/utilities 5.6.0-alpha.11
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/CHANGELOG.md +1 -0
- package/LICENSE.md +23 -0
- package/README.md +54 -0
- package/addon-main.cjs +5 -0
- package/declarations/-private/active-record/find-record.d.ts +66 -0
- package/declarations/-private/active-record/find-record.d.ts.map +1 -0
- package/declarations/-private/active-record/query.d.ts +54 -0
- package/declarations/-private/active-record/query.d.ts.map +1 -0
- package/declarations/-private/active-record/save-record.d.ts +144 -0
- package/declarations/-private/active-record/save-record.d.ts.map +1 -0
- package/declarations/-private/builder-utils.d.ts +5 -0
- package/declarations/-private/builder-utils.d.ts.map +1 -0
- package/declarations/-private/handlers/auto-compress.d.ts +153 -0
- package/declarations/-private/handlers/auto-compress.d.ts.map +1 -0
- package/declarations/-private/json-api/-utils.d.ts +110 -0
- package/declarations/-private/json-api/-utils.d.ts.map +1 -0
- package/declarations/-private/json-api/find-record.d.ts +66 -0
- package/declarations/-private/json-api/find-record.d.ts.map +1 -0
- package/declarations/-private/json-api/find-record.type-test.d.ts +2 -0
- package/declarations/-private/json-api/find-record.type-test.d.ts.map +1 -0
- package/declarations/-private/json-api/query.d.ts +104 -0
- package/declarations/-private/json-api/query.d.ts.map +1 -0
- package/declarations/-private/json-api/query.type-test.d.ts +2 -0
- package/declarations/-private/json-api/query.type-test.d.ts.map +1 -0
- package/declarations/-private/json-api/save-record.d.ts +191 -0
- package/declarations/-private/json-api/save-record.d.ts.map +1 -0
- package/declarations/-private/json-api/serialize.d.ts +57 -0
- package/declarations/-private/json-api/serialize.d.ts.map +1 -0
- package/declarations/-private/rest/find-record.d.ts +66 -0
- package/declarations/-private/rest/find-record.d.ts.map +1 -0
- package/declarations/-private/rest/query.d.ts +54 -0
- package/declarations/-private/rest/query.d.ts.map +1 -0
- package/declarations/-private/rest/save-record.d.ts +144 -0
- package/declarations/-private/rest/save-record.d.ts.map +1 -0
- package/declarations/-private/string/inflect.d.ts +105 -0
- package/declarations/-private/string/inflect.d.ts.map +1 -0
- package/declarations/-private/string/inflections.d.ts +10 -0
- package/declarations/-private/string/inflections.d.ts.map +1 -0
- package/declarations/-private/string/transform.d.ts +89 -0
- package/declarations/-private/string/transform.d.ts.map +1 -0
- package/declarations/-private.d.ts +2 -0
- package/declarations/-private.d.ts.map +1 -0
- package/declarations/active-record.d.ts +71 -0
- package/declarations/active-record.d.ts.map +1 -0
- package/declarations/handlers.d.ts +8 -0
- package/declarations/handlers.d.ts.map +1 -0
- package/declarations/index.d.ts +255 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/json-api.d.ts +51 -0
- package/declarations/json-api.d.ts.map +1 -0
- package/declarations/rest.d.ts +51 -0
- package/declarations/rest.d.ts.map +1 -0
- package/declarations/string.d.ts +14 -0
- package/declarations/string.d.ts.map +1 -0
- package/dist/-private.js +7 -0
- package/dist/-private.js.map +1 -0
- package/dist/active-record.js +393 -0
- package/dist/active-record.js.map +1 -0
- package/dist/builder-utils-Donkk-BZ.js +22 -0
- package/dist/builder-utils-Donkk-BZ.js.map +1 -0
- package/dist/handlers.js +141 -0
- package/dist/handlers.js.map +1 -0
- package/dist/index.js +403 -0
- package/dist/index.js.map +1 -0
- package/dist/inflect-C1laviCe.js +376 -0
- package/dist/inflect-C1laviCe.js.map +1 -0
- package/dist/json-api.js +671 -0
- package/dist/json-api.js.map +1 -0
- package/dist/rest.js +393 -0
- package/dist/rest.js.map +1 -0
- package/dist/string.js +1 -0
- package/dist/string.js.map +1 -0
- package/logos/NCC-1701-a-blue.svg +4 -0
- package/logos/NCC-1701-a-gold.svg +4 -0
- package/logos/NCC-1701-a-gold_100.svg +1 -0
- package/logos/NCC-1701-a-gold_base-64.txt +1 -0
- package/logos/NCC-1701-a.svg +4 -0
- package/logos/README.md +4 -0
- package/logos/docs-badge.svg +2 -0
- package/logos/ember-data-logo-dark.svg +12 -0
- package/logos/ember-data-logo-light.svg +12 -0
- package/logos/github-header.svg +444 -0
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +4 -0
- package/logos/warp-drive-logo-gold.svg +4 -0
- package/package.json +68 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @warp-drive/utilities changelog
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2025 Ember.js and contributors
|
|
4
|
+
Copyright (c) 2011-2017 Tilde, Inc. and contributors
|
|
5
|
+
Copyright (c) 2011 LivingSocial Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<img
|
|
3
|
+
class="project-logo"
|
|
4
|
+
src="./logos/github-header.svg#gh-light-mode-only"
|
|
5
|
+
alt="WarpDrive | Boldly go where no app has gone before"
|
|
6
|
+
title="WarpDrive | Boldly go where no app has gone before"
|
|
7
|
+
/>
|
|
8
|
+
<img
|
|
9
|
+
class="project-logo"
|
|
10
|
+
src="./logos/github-header.svg#gh-dark-mode-only"
|
|
11
|
+
alt="WarpDrive | Boldly go where no app has gone before"
|
|
12
|
+
title="WarpDrive | Boldly go where no app has gone before"
|
|
13
|
+
/>
|
|
14
|
+
</h1>
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+

|
|
18
|
+

|
|
19
|
+
[](https://docs.warp-drive.io)
|
|
20
|
+
[](https://discord.gg/zT3asNS
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
<br>
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
Utilities that Apps building with <em>Warp</em><strong>Drive</strong> may find useful.
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<br>
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
pnpm add -E @warp-drive/utilities
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
<br>
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
*Get Started* → [Guides](https://docs.warp-drive.io)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
<br>
|
|
45
|
+
|
|
46
|
+
## Code of Conduct
|
|
47
|
+
|
|
48
|
+
Refer to the [Code of Conduct](https://github.com/emberjs/data/blob/main/CODE_OF_CONDUCT.md) for community guidelines and inclusivity.
|
|
49
|
+
|
|
50
|
+
<br>
|
|
51
|
+
|
|
52
|
+
### License
|
|
53
|
+
|
|
54
|
+
This project is licensed under the [MIT License](LICENSE.md).
|
package/addon-main.cjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { TypeFromInstance } from '@warp-drive/core/types/record';
|
|
2
|
+
import type { FindRecordOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from '@warp-drive/core/types/request';
|
|
3
|
+
import type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';
|
|
4
|
+
export type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, 'data'> & {
|
|
5
|
+
data: T;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Builds request options to fetch a single resource by a known id or identifier
|
|
9
|
+
* configured for the url and header expectations of most ActiveRecord APIs.
|
|
10
|
+
*
|
|
11
|
+
* **Basic Usage**
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { findRecord } from '@warp-drive/utilities/active-record';
|
|
15
|
+
*
|
|
16
|
+
* const data = await store.request(findRecord('person', '1'));
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* **With Options**
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { findRecord } from '@warp-drive/utilities/active-record';
|
|
23
|
+
*
|
|
24
|
+
* const options = findRecord('person', '1', { include: ['pets', 'friends'] });
|
|
25
|
+
* const data = await store.request(options);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* **With an Identifier**
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { findRecord } from '@warp-drive/utilities/active-record';
|
|
32
|
+
*
|
|
33
|
+
* const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });
|
|
34
|
+
* const data = await store.request(options);
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
38
|
+
*
|
|
39
|
+
* The following options are supported:
|
|
40
|
+
*
|
|
41
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
42
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
43
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type
|
|
44
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
45
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
46
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
47
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
48
|
+
* defaulting to `false` if none is configured.
|
|
49
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { findRecord } from '@warp-drive/utilities/active-record';
|
|
53
|
+
*
|
|
54
|
+
* const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
|
|
55
|
+
* const data = await store.request(options);
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
* @param identifier
|
|
60
|
+
* @param options
|
|
61
|
+
*/
|
|
62
|
+
export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
|
|
63
|
+
export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
64
|
+
export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
|
|
65
|
+
export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
66
|
+
//# sourceMappingURL=find-record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-record.d.ts","sourceRoot":"","sources":["../../../src/-private/active-record/find-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EACV,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAMvF,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC;AAEpG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,UAAU,EAAE,4BAA4B,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAC7D,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,wBAAwB,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5D,wBAAgB,UAAU,CACxB,UAAU,EAAE,4BAA4B,EACxC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,wBAAwB,CAAC;AAC5B,wBAAgB,UAAU,CAAC,CAAC,EAC1B,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,wBAAwB,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { QueryParamsSource } from '@warp-drive/core/types/params';
|
|
2
|
+
import type { TypeFromInstance } from '@warp-drive/core/types/record';
|
|
3
|
+
import type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive/core/types/request';
|
|
4
|
+
import type { CollectionResourceDataDocument } from '@warp-drive/core/types/spec/document';
|
|
5
|
+
/**
|
|
6
|
+
* Builds request options to query for resources, usually by a primary
|
|
7
|
+
* type, configured for the url and header expectations of most ActiveRecord APIs.
|
|
8
|
+
*
|
|
9
|
+
* **Basic Usage**
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { query } from '@warp-drive/utilities/active-record';
|
|
13
|
+
*
|
|
14
|
+
* const data = await store.request(query('person'));
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* **With Query Params**
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { query } from '@warp-drive/utilities/active-record';
|
|
21
|
+
*
|
|
22
|
+
* const options = query('person', { include: ['pets', 'friends'] });
|
|
23
|
+
* const data = await store.request(options);
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
27
|
+
*
|
|
28
|
+
* The following options are supported:
|
|
29
|
+
*
|
|
30
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
31
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
32
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type
|
|
33
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
34
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
35
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
36
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
37
|
+
* defaulting to `false` if none is configured.
|
|
38
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { query } from '@warp-drive/utilities/active-record';
|
|
42
|
+
*
|
|
43
|
+
* const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
|
|
44
|
+
* const data = await store.request(options);
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
* @param identifier
|
|
49
|
+
* @param query
|
|
50
|
+
* @param options
|
|
51
|
+
*/
|
|
52
|
+
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T>, T>;
|
|
53
|
+
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
54
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/-private/active-record/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrG,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAM3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACrB,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,KAAK,CAAC,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,yBAAyB,GAClC,mBAAmB,CAAC,8BAA8B,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7D,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,yBAAyB,GAClC,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { TypedRecordInstance } from '@warp-drive/core/types/record';
|
|
2
|
+
import type { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, UpdateRequestOptions } from '@warp-drive/core/types/request';
|
|
3
|
+
import type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';
|
|
4
|
+
/**
|
|
5
|
+
* Builds request options to delete record for resources,
|
|
6
|
+
* configured for the url, method and header expectations of ActiveRecord APIs.
|
|
7
|
+
*
|
|
8
|
+
* **Basic Usage**
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { deleteRecord } from '@warp-drive/utilities/active-record';
|
|
12
|
+
*
|
|
13
|
+
* const person = store.peekRecord('person', '1');
|
|
14
|
+
*
|
|
15
|
+
* // mark record as deleted
|
|
16
|
+
* store.deleteRecord(person);
|
|
17
|
+
*
|
|
18
|
+
* // persist deletion
|
|
19
|
+
* const data = await store.request(deleteRecord(person));
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
23
|
+
*
|
|
24
|
+
* The following options are supported:
|
|
25
|
+
*
|
|
26
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
27
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
28
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
29
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
30
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
31
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
32
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
33
|
+
* defaulting to `false` if none is configured.
|
|
34
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { deleteRecord } from '@warp-drive/utilities/active-record';
|
|
38
|
+
*
|
|
39
|
+
* const person = store.peekRecord('person', '1');
|
|
40
|
+
*
|
|
41
|
+
* // mark record as deleted
|
|
42
|
+
* store.deleteRecord(person);
|
|
43
|
+
*
|
|
44
|
+
* // persist deletion
|
|
45
|
+
* const options = deleteRecord(person, { namespace: 'api/v1' });
|
|
46
|
+
* const data = await store.request(options);
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
* @param record
|
|
51
|
+
* @param options
|
|
52
|
+
*/
|
|
53
|
+
export declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
|
|
54
|
+
export declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
|
|
55
|
+
/**
|
|
56
|
+
* Builds request options to create new record for resources,
|
|
57
|
+
* configured for the url, method and header expectations of most ActiveRecord APIs.
|
|
58
|
+
*
|
|
59
|
+
* **Basic Usage**
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { createRecord } from '@warp-drive/utilities/active-record';
|
|
63
|
+
*
|
|
64
|
+
* const person = store.createRecord('person', { name: 'Ted' });
|
|
65
|
+
* const data = await store.request(createRecord(person));
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
69
|
+
*
|
|
70
|
+
* The following options are supported:
|
|
71
|
+
*
|
|
72
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
73
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
74
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
75
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
76
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
77
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
78
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
79
|
+
* defaulting to `false` if none is configured.
|
|
80
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
81
|
+
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { createRecord } from '@warp-drive/utilities/active-record';
|
|
84
|
+
*
|
|
85
|
+
* const person = store.createRecord('person', { name: 'Ted' });
|
|
86
|
+
* const options = createRecord(person, { namespace: 'api/v1' });
|
|
87
|
+
* const data = await store.request(options);
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
* @param record
|
|
92
|
+
* @param options
|
|
93
|
+
*/
|
|
94
|
+
export declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
|
|
95
|
+
export declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
|
|
96
|
+
/**
|
|
97
|
+
* Builds request options to update existing record for resources,
|
|
98
|
+
* configured for the url, method and header expectations of most ActiveRecord APIs.
|
|
99
|
+
*
|
|
100
|
+
* **Basic Usage**
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { updateRecord } from '@warp-drive/utilities/active-record';
|
|
104
|
+
*
|
|
105
|
+
* const person = store.peekRecord('person', '1');
|
|
106
|
+
* person.name = 'Chris';
|
|
107
|
+
* const data = await store.request(updateRecord(person));
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
111
|
+
*
|
|
112
|
+
* The following options are supported:
|
|
113
|
+
*
|
|
114
|
+
* - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
|
|
115
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
116
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
117
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
118
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
119
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
120
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
121
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
122
|
+
* defaulting to `false` if none is configured.
|
|
123
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
124
|
+
*
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { updateRecord } from '@warp-drive/utilities/active-record';
|
|
127
|
+
*
|
|
128
|
+
* const person = store.peekRecord('person', '1');
|
|
129
|
+
* person.name = 'Chris';
|
|
130
|
+
* const options = updateRecord(person, { patch: true });
|
|
131
|
+
* const data = await store.request(options);
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @public
|
|
135
|
+
* @param record
|
|
136
|
+
* @param options
|
|
137
|
+
*/
|
|
138
|
+
export declare function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(record: T, options?: ConstrainedRequestOptions & {
|
|
139
|
+
patch?: boolean;
|
|
140
|
+
}): UpdateRequestOptions<SingleResourceDataDocument<RT>, T>;
|
|
141
|
+
export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
142
|
+
patch?: boolean;
|
|
143
|
+
}): UpdateRequestOptions;
|
|
144
|
+
//# sourceMappingURL=save-record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save-record.d.ts","sourceRoot":"","sources":["../../../src/-private/active-record/save-record.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAevF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;AACzG,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC;AA8BzG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;AACzG,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC;AA6BzG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,mBAAmB,EAAE,EAAE,SAAS,mBAAmB,GAAG,CAAC,EAC5F,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,yBAAyB,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACxD,oBAAoB,CAAC,0BAA0B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3D,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,yBAAyB,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACxD,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CacheOptions, ConstrainedRequestOptions } from '@warp-drive/core/types/request';
|
|
2
|
+
import type { UrlOptions } from '../index.ts';
|
|
3
|
+
export declare function copyForwardUrlOptions(urlOptions: UrlOptions, options: ConstrainedRequestOptions): void;
|
|
4
|
+
export declare function extractCacheOptions(options: ConstrainedRequestOptions): CacheOptions;
|
|
5
|
+
//# sourceMappingURL=builder-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder-utils.d.ts","sourceRoot":"","sources":["../../src/-private/builder-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE9F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,yBAAyB,GAAG,IAAI,CAUtG;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,yBAAyB,GAAG,YAAY,CASpF"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { Future, Handler, NextFn } from '@warp-drive/core/request';
|
|
2
|
+
import type { RequestContext } from '@warp-drive/core/types/request';
|
|
3
|
+
export declare const SupportsRequestStreams: boolean;
|
|
4
|
+
interface Constraints {
|
|
5
|
+
/**
|
|
6
|
+
* The minimum size at which to compress blobs
|
|
7
|
+
*
|
|
8
|
+
* @default 1000
|
|
9
|
+
*/
|
|
10
|
+
Blob?: number;
|
|
11
|
+
/**
|
|
12
|
+
* The minimum size at which to compress array buffers
|
|
13
|
+
*
|
|
14
|
+
* @default 1000
|
|
15
|
+
*/
|
|
16
|
+
ArrayBuffer?: number;
|
|
17
|
+
/**
|
|
18
|
+
* The minimum size at which to compress typed arrays
|
|
19
|
+
*
|
|
20
|
+
* @default 1000
|
|
21
|
+
*/
|
|
22
|
+
TypedArray?: number;
|
|
23
|
+
/**
|
|
24
|
+
* The minimum size at which to compress data views
|
|
25
|
+
*
|
|
26
|
+
* @default 1000
|
|
27
|
+
*/
|
|
28
|
+
DataView?: number;
|
|
29
|
+
/**
|
|
30
|
+
* The minimum size at which to compress strings
|
|
31
|
+
*
|
|
32
|
+
* @default 1000
|
|
33
|
+
*/
|
|
34
|
+
String?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Options for configuring the AutoCompress handler.
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
interface CompressionOptions {
|
|
41
|
+
/**
|
|
42
|
+
* The compression format to use. Must be a valid
|
|
43
|
+
* compression format supported by [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
|
|
44
|
+
*
|
|
45
|
+
* The default is `gzip`.
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
format?: CompressionFormat;
|
|
49
|
+
/**
|
|
50
|
+
* Some browsers support `ReadableStream` as a request body. This option
|
|
51
|
+
* enables passing the compression stream as the request body instead of
|
|
52
|
+
* the final compressed body when the browser supports doing so.
|
|
53
|
+
*
|
|
54
|
+
* This comes with several caveats:
|
|
55
|
+
*
|
|
56
|
+
* - the request will be put into `duplex: 'half'` mode. This should be
|
|
57
|
+
* transparent to you, but it is worth noting.
|
|
58
|
+
* - the request mode cannot be `no-cors` as requests with a `ReadableStream`
|
|
59
|
+
* have no content length and thus are a new form of request that triggers
|
|
60
|
+
* cors requirements and a preflight request.
|
|
61
|
+
* - http/1.x is not supported.
|
|
62
|
+
*
|
|
63
|
+
* For additional reading about the restrictions of using `ReadableStream`
|
|
64
|
+
* as a request body, see the [Chromium Documentation](https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#restrictions)
|
|
65
|
+
*
|
|
66
|
+
* Streaming can be enabled per-request in browsers which support it by
|
|
67
|
+
* setting `request.options.allowStreaming` to `true`.
|
|
68
|
+
*
|
|
69
|
+
* Streaming can be forced even when the browser does not support it by setting
|
|
70
|
+
* `request.options.forceStreaming` to `true`. This is useful if later handlers
|
|
71
|
+
* in the chain can handle the request body as a stream.
|
|
72
|
+
*
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
allowStreaming?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* If `true`, the request will be forced into streaming mode even
|
|
78
|
+
* if the browser does not support it. This is useful if later handlers
|
|
79
|
+
* in the chain can handle the request body as a stream.
|
|
80
|
+
*
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
forceStreaming?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The constraints for the request body. This is used to determine
|
|
86
|
+
* whether to compress the request body or not.
|
|
87
|
+
*
|
|
88
|
+
* The defaults are:
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* {
|
|
92
|
+
* Blob: 1000, // blob.size
|
|
93
|
+
* ArrayBuffer: 1000, // buffer.byteLength
|
|
94
|
+
* TypedArray: 1000, // array.byteLength
|
|
95
|
+
* DataView: 1000, // view.byteLength
|
|
96
|
+
* String: 1000, // string.length
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* The following body types are never compressed unless explicitly
|
|
101
|
+
* configured by the request:
|
|
102
|
+
* - `FormData`
|
|
103
|
+
* - `URLSearchParams`
|
|
104
|
+
* - `ReadableStream`
|
|
105
|
+
*
|
|
106
|
+
* A request.options.compress value of `false` will disable
|
|
107
|
+
* compression for a request body of any type. While a value of
|
|
108
|
+
* `true` will enable compression for the request.
|
|
109
|
+
*
|
|
110
|
+
* An undefined value will use the default, a value of `0` will
|
|
111
|
+
* enable compression for all values, and a value of `-1` will
|
|
112
|
+
* disable compression.
|
|
113
|
+
*
|
|
114
|
+
*/
|
|
115
|
+
constraints?: Constraints;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A request handler that automatically compresses the request body
|
|
119
|
+
* if the request body is a string, array buffer, blob, or form data.
|
|
120
|
+
*
|
|
121
|
+
* This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
|
|
122
|
+
*
|
|
123
|
+
* The compression format as well as the kinds of data to compress can be
|
|
124
|
+
* configured using the `format` and `constraints` options.
|
|
125
|
+
*
|
|
126
|
+
* ```diff
|
|
127
|
+
* +import { AutoCompress } from '@ember-data/request-utils/handlers';
|
|
128
|
+
* import Fetch from '@ember-data/request/fetch';
|
|
129
|
+
* import RequestManager from '@ember-data/request';
|
|
130
|
+
* import Store from '@ember-data/store';
|
|
131
|
+
*
|
|
132
|
+
* class AppStore extends Store {
|
|
133
|
+
* requestManager = new RequestManager()
|
|
134
|
+
* .use([
|
|
135
|
+
* + new AutoCompress(),
|
|
136
|
+
* Fetch
|
|
137
|
+
* ]);
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @class AutoCompress
|
|
142
|
+
* @public
|
|
143
|
+
* @since 5.5.0
|
|
144
|
+
*/
|
|
145
|
+
export declare class AutoCompress implements Handler {
|
|
146
|
+
options: Required<CompressionOptions> & {
|
|
147
|
+
constraints: Required<Constraints>;
|
|
148
|
+
};
|
|
149
|
+
constructor(options?: CompressionOptions);
|
|
150
|
+
request<T>({ request }: RequestContext, next: NextFn<T>): Promise<T> | Future<T>;
|
|
151
|
+
}
|
|
152
|
+
export {};
|
|
153
|
+
//# sourceMappingURL=auto-compress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-compress.d.ts","sourceRoot":"","sources":["../../../src/-private/handlers/auto-compress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAMjF,eAAO,MAAM,sBAAsB,SAc/B,CAAC;AAEL,UAAU,WAAW;IACnB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,UAAU,kBAAkB;IAC1B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAE3B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAWD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,YAAa,YAAW,OAAO;IAClC,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GAAG;QAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAA;KAAE,CAAC;gBAE3E,OAAO,GAAE,kBAAuB;IAU5C,OAAO,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;CA2DjF"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { QueryParamsSource } from '@warp-drive/core/types/params';
|
|
2
|
+
import type { BuildURLConfig } from '../../index.ts';
|
|
3
|
+
export interface JSONAPIConfig extends BuildURLConfig {
|
|
4
|
+
profiles?: {
|
|
5
|
+
pagination?: string;
|
|
6
|
+
[key: string]: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
extensions?: {
|
|
9
|
+
atomic?: string;
|
|
10
|
+
[key: string]: string | undefined;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare let CONFIG: JSONAPIConfig;
|
|
14
|
+
export declare let ACCEPT_HEADER_VALUE: string;
|
|
15
|
+
/**
|
|
16
|
+
* Allows setting extensions and profiles to be used in the `Accept` header.
|
|
17
|
+
*
|
|
18
|
+
* Extensions and profiles are keyed by their namespace with the value being
|
|
19
|
+
* their URI.
|
|
20
|
+
*
|
|
21
|
+
* Example:
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* setBuildURLConfig({
|
|
25
|
+
* extensions: {
|
|
26
|
+
* atomic: 'https://jsonapi.org/ext/atomic'
|
|
27
|
+
* },
|
|
28
|
+
* profiles: {
|
|
29
|
+
* pagination: 'https://jsonapi.org/profiles/ethanresnick/cursor-pagination'
|
|
30
|
+
* }
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* This also sets the global configuration for `buildBaseURL`
|
|
35
|
+
* for host and namespace values for the global coniguration
|
|
36
|
+
* done via `import { setBuildURLConfig } from '@warp-drive/utilities';`
|
|
37
|
+
*
|
|
38
|
+
* These values may still be overridden by passing
|
|
39
|
+
* them to buildBaseURL directly.
|
|
40
|
+
*
|
|
41
|
+
* This method may be called as many times as needed
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* type BuildURLConfig = {
|
|
45
|
+
* host: string;
|
|
46
|
+
* namespace: string'
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
* @param {BuildURLConfig} config
|
|
52
|
+
* @return {void}
|
|
53
|
+
*/
|
|
54
|
+
export declare function setBuildURLConfig(config: JSONAPIConfig): void;
|
|
55
|
+
interface RelatedObject {
|
|
56
|
+
[key: string]: string | string[] | RelatedObject;
|
|
57
|
+
}
|
|
58
|
+
export type JsonApiQuery = {
|
|
59
|
+
include?: string | string[] | RelatedObject;
|
|
60
|
+
fields?: Record<string, string | string[]>;
|
|
61
|
+
page?: {
|
|
62
|
+
size?: number;
|
|
63
|
+
after?: string;
|
|
64
|
+
before?: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Sorts query params by both key and value, returning a query params string
|
|
69
|
+
*
|
|
70
|
+
* Treats `included` specially, splicing it into an array if it is a string and sorting the array.
|
|
71
|
+
* - If `included` is an object we build paths dynamically for you
|
|
72
|
+
* Treats `fields` specially, building JSON:API partial fields params from an object
|
|
73
|
+
* Treats `page` specially, building cursor-pagination profile page params from an object
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const params = buildQueryParams({
|
|
77
|
+
* include: {
|
|
78
|
+
* company: {
|
|
79
|
+
* locations: 'address'
|
|
80
|
+
* }
|
|
81
|
+
* },
|
|
82
|
+
* fields: {
|
|
83
|
+
* company: ['name', 'ticker'],
|
|
84
|
+
* person: 'name'
|
|
85
|
+
* },
|
|
86
|
+
* page: {
|
|
87
|
+
* size: 10,
|
|
88
|
+
* after: 'abc',
|
|
89
|
+
* }
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* // => 'fields[company]=name,ticker&fields[person]=name&include=company.locations,company.locations.address&page[after]=abc&page[size]=10'
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* Options:
|
|
96
|
+
* - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
|
|
97
|
+
*
|
|
98
|
+
* 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
|
|
99
|
+
* 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
|
|
100
|
+
* 'repeat': appends the key for every value e.g. `ids=1&ids=2`
|
|
101
|
+
* 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
* @param {URLSearchParams | Object} params
|
|
105
|
+
* @param {Object} [options]
|
|
106
|
+
* @return {String} A sorted query params string without the leading `?`
|
|
107
|
+
*/
|
|
108
|
+
export declare function buildQueryParams(query: JsonApiQuery | QueryParamsSource): string;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"-utils.d.ts","sourceRoot":"","sources":["../../../src/-private/json-api/-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD,MAAM,WAAW,aAAc,SAAQ,cAAc;IACnD,QAAQ,CAAC,EAAE;QACT,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KACnC,CAAC;IACF,UAAU,CAAC,EAAE;QACX,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KACnC,CAAC;CACH;AAID,eAAO,IAAI,MAAM,EAAE,aAA8B,CAAC;AAClD,eAAO,IAAI,mBAAmB,QAA6B,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAqB7D;AAED,UAAU,aAAa;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,CAAC;CAClD;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,CAAC;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC3C,IAAI,CAAC,EAAE;QACL,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAuCF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,iBAAiB,GAAG,MAAM,CA0DhF"}
|