@warp-drive-mirror/utilities 5.8.0-alpha.3 → 5.8.0-alpha.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -26
- package/declarations/-private/active-record/find-record.d.ts +5 -6
- package/declarations/-private/active-record/query.d.ts +2 -2
- package/declarations/-private/active-record/save-record.d.ts +2 -2
- package/declarations/-private/handlers/meta-doc.d.ts +1 -1
- package/declarations/-private/json-api/find-record.d.ts +37 -18
- package/declarations/-private/json-api/query.d.ts +3 -6
- package/declarations/-private/json-api/save-record.d.ts +45 -10
- package/declarations/-private/json-api/serialize.d.ts +15 -1
- package/declarations/-private/rest/find-record.d.ts +5 -8
- package/declarations/-private/rest/query.d.ts +2 -2
- package/declarations/-private/rest/save-record.d.ts +2 -2
- package/dist/active-record.js +2 -0
- package/dist/handlers.js +3 -3
- package/dist/json-api.js +94 -26
- package/dist/rest.js +2 -2
- package/dist/string.js +428 -1
- package/dist/unpkg/dev/-private.js +7 -0
- package/dist/unpkg/dev/active-record.js +395 -0
- package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/dev/declarations/-private/active-record/find-record.d.ts +64 -0
- package/dist/unpkg/dev/declarations/-private/active-record/query.d.ts +53 -0
- package/dist/unpkg/dev/declarations/-private/active-record/save-record.d.ts +146 -0
- package/dist/unpkg/dev/declarations/-private/builder-utils.d.ts +4 -0
- package/dist/unpkg/dev/declarations/-private/handlers/auto-compress.d.ts +158 -0
- package/dist/unpkg/dev/declarations/-private/handlers/gated.d.ts +19 -0
- package/dist/unpkg/dev/declarations/-private/handlers/meta-doc.d.ts +47 -0
- package/dist/unpkg/dev/declarations/-private/handlers/utils.d.ts +41 -0
- package/dist/unpkg/dev/declarations/-private/json-api/-utils.d.ts +109 -0
- package/dist/unpkg/dev/declarations/-private/json-api/find-record.d.ts +84 -0
- package/dist/unpkg/dev/declarations/-private/json-api/query.d.ts +100 -0
- package/dist/unpkg/dev/declarations/-private/json-api/save-record.d.ts +228 -0
- package/dist/unpkg/dev/declarations/-private/json-api/serialize.d.ts +70 -0
- package/dist/unpkg/dev/declarations/-private/rest/find-record.d.ts +62 -0
- package/dist/unpkg/dev/declarations/-private/rest/query.d.ts +53 -0
- package/dist/unpkg/dev/declarations/-private/rest/save-record.d.ts +146 -0
- package/dist/unpkg/dev/declarations/-private/string/inflect.d.ts +82 -0
- package/dist/unpkg/dev/declarations/-private/string/inflections.d.ts +9 -0
- package/dist/unpkg/dev/declarations/-private/string/transform.d.ts +77 -0
- package/dist/unpkg/dev/declarations/-private.d.ts +1 -0
- package/dist/unpkg/dev/declarations/active-record.d.ts +3 -0
- package/dist/unpkg/dev/declarations/derivations.d.ts +27 -0
- package/dist/unpkg/dev/declarations/handlers.d.ts +10 -0
- package/dist/unpkg/dev/declarations/index.d.ts +208 -0
- package/dist/unpkg/dev/declarations/json-api.d.ts +5 -0
- package/dist/unpkg/dev/declarations/rest.d.ts +3 -0
- package/dist/unpkg/dev/declarations/string.d.ts +14 -0
- package/dist/unpkg/dev/derivations.js +30 -0
- package/dist/unpkg/dev/handlers.js +317 -0
- package/dist/unpkg/dev/index.js +361 -0
- package/dist/unpkg/dev/inflect-BSG696t-.js +344 -0
- package/dist/unpkg/dev/json-api.js +740 -0
- package/dist/unpkg/dev/rest.js +393 -0
- package/dist/unpkg/dev/string.js +1 -0
- package/dist/unpkg/dev-deprecated/-private.js +7 -0
- package/dist/unpkg/dev-deprecated/active-record.js +395 -0
- package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/active-record/find-record.d.ts +64 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/active-record/query.d.ts +53 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/active-record/save-record.d.ts +146 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/builder-utils.d.ts +4 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/auto-compress.d.ts +158 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/gated.d.ts +19 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/meta-doc.d.ts +47 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/utils.d.ts +41 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/-utils.d.ts +109 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/find-record.d.ts +84 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/query.d.ts +100 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/save-record.d.ts +228 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/serialize.d.ts +70 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/rest/find-record.d.ts +62 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/rest/query.d.ts +53 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/rest/save-record.d.ts +146 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/string/inflect.d.ts +82 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/string/inflections.d.ts +9 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/string/transform.d.ts +77 -0
- package/dist/unpkg/dev-deprecated/declarations/-private.d.ts +1 -0
- package/dist/unpkg/dev-deprecated/declarations/active-record.d.ts +3 -0
- package/dist/unpkg/dev-deprecated/declarations/derivations.d.ts +27 -0
- package/dist/unpkg/dev-deprecated/declarations/handlers.d.ts +10 -0
- package/dist/unpkg/dev-deprecated/declarations/index.d.ts +208 -0
- package/dist/unpkg/dev-deprecated/declarations/json-api.d.ts +5 -0
- package/dist/unpkg/dev-deprecated/declarations/rest.d.ts +3 -0
- package/dist/unpkg/dev-deprecated/declarations/string.d.ts +14 -0
- package/dist/unpkg/dev-deprecated/derivations.js +30 -0
- package/dist/unpkg/dev-deprecated/handlers.js +317 -0
- package/dist/unpkg/dev-deprecated/index.js +361 -0
- package/dist/unpkg/dev-deprecated/inflect-BSG696t-.js +344 -0
- package/dist/unpkg/dev-deprecated/json-api.js +740 -0
- package/dist/unpkg/dev-deprecated/rest.js +393 -0
- package/dist/unpkg/dev-deprecated/string.js +1 -0
- package/dist/unpkg/prod/-private.js +7 -0
- package/dist/unpkg/prod/active-record.js +395 -0
- package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/prod/declarations/-private/active-record/find-record.d.ts +64 -0
- package/dist/unpkg/prod/declarations/-private/active-record/query.d.ts +53 -0
- package/dist/unpkg/prod/declarations/-private/active-record/save-record.d.ts +146 -0
- package/dist/unpkg/prod/declarations/-private/builder-utils.d.ts +4 -0
- package/dist/unpkg/prod/declarations/-private/handlers/auto-compress.d.ts +158 -0
- package/dist/unpkg/prod/declarations/-private/handlers/gated.d.ts +19 -0
- package/dist/unpkg/prod/declarations/-private/handlers/meta-doc.d.ts +47 -0
- package/dist/unpkg/prod/declarations/-private/handlers/utils.d.ts +41 -0
- package/dist/unpkg/prod/declarations/-private/json-api/-utils.d.ts +109 -0
- package/dist/unpkg/prod/declarations/-private/json-api/find-record.d.ts +84 -0
- package/dist/unpkg/prod/declarations/-private/json-api/query.d.ts +100 -0
- package/dist/unpkg/prod/declarations/-private/json-api/save-record.d.ts +228 -0
- package/dist/unpkg/prod/declarations/-private/json-api/serialize.d.ts +70 -0
- package/dist/unpkg/prod/declarations/-private/rest/find-record.d.ts +62 -0
- package/dist/unpkg/prod/declarations/-private/rest/query.d.ts +53 -0
- package/dist/unpkg/prod/declarations/-private/rest/save-record.d.ts +146 -0
- package/dist/unpkg/prod/declarations/-private/string/inflect.d.ts +82 -0
- package/dist/unpkg/prod/declarations/-private/string/inflections.d.ts +9 -0
- package/dist/unpkg/prod/declarations/-private/string/transform.d.ts +77 -0
- package/dist/unpkg/prod/declarations/-private.d.ts +1 -0
- package/dist/unpkg/prod/declarations/active-record.d.ts +3 -0
- package/dist/unpkg/prod/declarations/derivations.d.ts +27 -0
- package/dist/unpkg/prod/declarations/handlers.d.ts +10 -0
- package/dist/unpkg/prod/declarations/index.d.ts +208 -0
- package/dist/unpkg/prod/declarations/json-api.d.ts +5 -0
- package/dist/unpkg/prod/declarations/rest.d.ts +3 -0
- package/dist/unpkg/prod/declarations/string.d.ts +14 -0
- package/dist/unpkg/prod/derivations.js +30 -0
- package/dist/unpkg/prod/handlers.js +317 -0
- package/dist/unpkg/prod/index.js +361 -0
- package/dist/unpkg/prod/inflect-BSG696t-.js +344 -0
- package/dist/unpkg/prod/json-api.js +740 -0
- package/dist/unpkg/prod/rest.js +393 -0
- package/dist/unpkg/prod/string.js +1 -0
- package/dist/unpkg/prod-deprecated/-private.js +7 -0
- package/dist/unpkg/prod-deprecated/active-record.js +395 -0
- package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/active-record/find-record.d.ts +64 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/active-record/query.d.ts +53 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/active-record/save-record.d.ts +146 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/builder-utils.d.ts +4 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/auto-compress.d.ts +158 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/gated.d.ts +19 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/meta-doc.d.ts +47 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/utils.d.ts +41 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/-utils.d.ts +109 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/find-record.d.ts +84 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/query.d.ts +100 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/save-record.d.ts +228 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/serialize.d.ts +70 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/rest/find-record.d.ts +62 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/rest/query.d.ts +53 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/rest/save-record.d.ts +146 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/string/inflect.d.ts +82 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/string/inflections.d.ts +9 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/string/transform.d.ts +77 -0
- package/dist/unpkg/prod-deprecated/declarations/-private.d.ts +1 -0
- package/dist/unpkg/prod-deprecated/declarations/active-record.d.ts +3 -0
- package/dist/unpkg/prod-deprecated/declarations/derivations.d.ts +27 -0
- package/dist/unpkg/prod-deprecated/declarations/handlers.d.ts +10 -0
- package/dist/unpkg/prod-deprecated/declarations/index.d.ts +208 -0
- package/dist/unpkg/prod-deprecated/declarations/json-api.d.ts +5 -0
- package/dist/unpkg/prod-deprecated/declarations/rest.d.ts +3 -0
- package/dist/unpkg/prod-deprecated/declarations/string.d.ts +14 -0
- package/dist/unpkg/prod-deprecated/derivations.js +30 -0
- package/dist/unpkg/prod-deprecated/handlers.js +317 -0
- package/dist/unpkg/prod-deprecated/index.js +361 -0
- package/dist/unpkg/prod-deprecated/inflect-BSG696t-.js +344 -0
- package/dist/unpkg/prod-deprecated/json-api.js +740 -0
- package/dist/unpkg/prod-deprecated/rest.js +393 -0
- package/dist/unpkg/prod-deprecated/string.js +1 -0
- package/logos/README.md +2 -2
- package/logos/logo-yellow-slab.svg +1 -0
- package/logos/word-mark-black.svg +1 -0
- package/logos/word-mark-white.svg +1 -0
- package/package.json +4 -4
- package/logos/NCC-1701-a-blue.svg +0 -4
- package/logos/NCC-1701-a-gold.svg +0 -4
- package/logos/NCC-1701-a-gold_100.svg +0 -1
- package/logos/NCC-1701-a-gold_base-64.txt +0 -1
- package/logos/NCC-1701-a.svg +0 -4
- package/logos/docs-badge.svg +0 -2
- package/logos/ember-data-logo-dark.svg +0 -12
- package/logos/ember-data-logo-light.svg +0 -12
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +0 -4
- package/logos/warp-drive-logo-gold.svg +0 -4
package/README.md
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
<
|
|
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
|
-
/>
|
|
1
|
+
<p align="center">
|
|
8
2
|
<img
|
|
9
3
|
class="project-logo"
|
|
10
|
-
src="./logos/
|
|
11
|
-
alt="WarpDrive
|
|
12
|
-
|
|
4
|
+
src="./logos/logo-yellow-slab.svg"
|
|
5
|
+
alt="WarpDrive"
|
|
6
|
+
width="180px"
|
|
7
|
+
title="WarpDrive"
|
|
13
8
|
/>
|
|
14
|
-
</
|
|
9
|
+
</p>
|
|
15
10
|
|
|
16
|
-
](https://discord.gg/zT3asNS
|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+
[](https://discord.gg/zT3asNS
|
|
21
15
|
)
|
|
22
|
-
[](https://discord.gg/PHBbnWJx5S
|
|
23
17
|
)
|
|
24
18
|
|
|
19
|
+
# @warp-drive-mirror/utilities
|
|
20
|
+
|
|
25
21
|
|
|
26
22
|
<br>
|
|
27
23
|
|
|
@@ -31,14 +27,6 @@ Utilities that Apps building with <em>Warp</em><strong>Drive</strong> may find u
|
|
|
31
27
|
|
|
32
28
|
<br>
|
|
33
29
|
|
|
34
|
-
## Installation
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
pnpm add -E @warp-drive-mirror/utilities
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
<br>
|
|
41
|
-
|
|
42
30
|
## Documentation
|
|
43
31
|
|
|
44
32
|
*Get Started* → [Guides](https://docs.warp-drive.io)
|
|
@@ -48,7 +36,7 @@ pnpm add -E @warp-drive-mirror/utilities
|
|
|
48
36
|
|
|
49
37
|
## Code of Conduct
|
|
50
38
|
|
|
51
|
-
Refer to the [Code of Conduct](https://github.com/
|
|
39
|
+
Refer to the [Code of Conduct](https://github.com/warp-drive-data/warp-drive/blob/main/CODE_OF_CONDUCT.md) for community guidelines and inclusivity.
|
|
52
40
|
|
|
53
41
|
<br>
|
|
54
42
|
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
1
2
|
import type { TypeFromInstance } from "@warp-drive-mirror/core/types/record";
|
|
2
3
|
import type { FindRecordOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from "@warp-drive-mirror/core/types/request";
|
|
3
|
-
import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
4
|
-
export type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, "data"> & {
|
|
5
|
-
data: T;
|
|
6
|
-
};
|
|
7
4
|
/**
|
|
8
5
|
* Builds request options to fetch a single resource by a known id or identifier
|
|
9
6
|
* configured for the url and header expectations of most ActiveRecord APIs.
|
|
@@ -59,7 +56,9 @@ export type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, "d
|
|
|
59
56
|
* @param identifier
|
|
60
57
|
* @param options
|
|
61
58
|
*/
|
|
62
|
-
export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<
|
|
59
|
+
export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
63
60
|
export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
64
|
-
export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<
|
|
61
|
+
export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
65
62
|
export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
63
|
+
/** @deprecated use {@link ReactiveDataDocument} instead */
|
|
64
|
+
export type FindRecordResultDocument<T> = ReactiveDataDocument<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
1
2
|
import type { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
|
|
2
3
|
import type { TypeFromInstance } from "@warp-drive-mirror/core/types/record";
|
|
3
4
|
import type { ConstrainedRequestOptions, QueryRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
4
|
-
import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
5
5
|
/**
|
|
6
6
|
* Builds request options to query for resources, usually by a primary
|
|
7
7
|
* type, configured for the url and header expectations of most ActiveRecord APIs.
|
|
@@ -49,5 +49,5 @@ import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/typ
|
|
|
49
49
|
* @param query
|
|
50
50
|
* @param options
|
|
51
51
|
*/
|
|
52
|
-
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<
|
|
52
|
+
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
53
53
|
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
1
2
|
import type { TypedRecordInstance } from "@warp-drive-mirror/core/types/record";
|
|
2
3
|
import type { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, UpdateRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
3
|
-
import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
4
4
|
/**
|
|
5
5
|
* Builds request options to delete record for resources,
|
|
6
6
|
* configured for the url, method and header expectations of ActiveRecord APIs.
|
|
@@ -140,7 +140,7 @@ export declare function updateRecord<
|
|
|
140
140
|
RT extends TypedRecordInstance = T
|
|
141
141
|
>(record: T, options?: ConstrainedRequestOptions & {
|
|
142
142
|
patch?: boolean;
|
|
143
|
-
}): UpdateRequestOptions<
|
|
143
|
+
}): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;
|
|
144
144
|
export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
145
145
|
patch?: boolean;
|
|
146
146
|
}): UpdateRequestOptions;
|
|
@@ -40,7 +40,7 @@ import type { Handler } from "@warp-drive-mirror/core/request";
|
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
42
|
* Errors are not processed by this handler, so if the request fails and the error response
|
|
43
|
-
* is not in {
|
|
43
|
+
* is not in {json:api} format additional processing may be needed.
|
|
44
44
|
*
|
|
45
45
|
* @group Handlers
|
|
46
46
|
*/
|
|
@@ -1,36 +1,53 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
1
2
|
import type { TypeFromInstance } from "@warp-drive-mirror/core/types/record";
|
|
2
3
|
import type { FindRecordOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from "@warp-drive-mirror/core/types/request";
|
|
3
|
-
import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
4
4
|
/**
|
|
5
5
|
* Builds request options to fetch a single resource by a known id or identifier
|
|
6
6
|
* configured for the url and header expectations of most JSON:API APIs.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* :::tabs
|
|
9
|
+
*
|
|
10
|
+
* == Basic Usage
|
|
9
11
|
*
|
|
10
12
|
* ```ts
|
|
11
13
|
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
14
|
+
* import type { Person } from '#/data/types';
|
|
12
15
|
*
|
|
13
|
-
* const
|
|
16
|
+
* const result = await store.request(
|
|
17
|
+
* findRecord<Person>('person', '1')
|
|
18
|
+
* );
|
|
14
19
|
* ```
|
|
15
20
|
*
|
|
16
|
-
*
|
|
21
|
+
* == With Options
|
|
17
22
|
*
|
|
18
23
|
* ```ts
|
|
19
24
|
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
25
|
+
* import type { Person } from '#/data/types';
|
|
20
26
|
*
|
|
21
|
-
* const
|
|
22
|
-
*
|
|
27
|
+
* const data = await store.request(
|
|
28
|
+
* findRecord<Person>(
|
|
29
|
+
* 'person', '1',
|
|
30
|
+
* { include: ['pets', 'friends'] }
|
|
31
|
+
* )
|
|
32
|
+
* );
|
|
23
33
|
* ```
|
|
24
34
|
*
|
|
25
|
-
*
|
|
35
|
+
* == With an Identifier
|
|
26
36
|
*
|
|
27
37
|
* ```ts
|
|
28
38
|
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
39
|
+
* import type { Person } from '#/data/types';
|
|
29
40
|
*
|
|
30
|
-
* const
|
|
31
|
-
*
|
|
41
|
+
* const data = await store.request(
|
|
42
|
+
* findRecord<Person>(
|
|
43
|
+
* { type: 'person', id: '1' },
|
|
44
|
+
* { include: ['pets', 'friends'] }
|
|
45
|
+
* )
|
|
46
|
+
* );
|
|
32
47
|
* ```
|
|
33
48
|
*
|
|
49
|
+
* :::
|
|
50
|
+
*
|
|
34
51
|
* **Supplying Options to Modify the Request Behavior**
|
|
35
52
|
*
|
|
36
53
|
* The following options are supported:
|
|
@@ -48,18 +65,20 @@ import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/s
|
|
|
48
65
|
* ```ts
|
|
49
66
|
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
50
67
|
*
|
|
51
|
-
* const
|
|
52
|
-
*
|
|
68
|
+
* const data = await store.request(
|
|
69
|
+
* findRecord(
|
|
70
|
+
* 'person', '1',
|
|
71
|
+
* { include: ['pets', 'friends'] },
|
|
72
|
+
* { namespace: 'api/v2' }
|
|
73
|
+
* )
|
|
74
|
+
* );
|
|
53
75
|
* ```
|
|
54
76
|
*
|
|
55
77
|
* @public
|
|
56
|
-
* @param identifier
|
|
57
|
-
* @param options
|
|
58
78
|
*/
|
|
59
|
-
export
|
|
60
|
-
data: T;
|
|
61
|
-
};
|
|
62
|
-
export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
|
|
79
|
+
export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
63
80
|
export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
64
|
-
export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<
|
|
81
|
+
export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
65
82
|
export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
83
|
+
/** @deprecated use {@link ReactiveDataDocument} */
|
|
84
|
+
export type FindRecordResultDocument<T> = ReactiveDataDocument<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
1
2
|
import type { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
|
|
2
3
|
import type { TypedRecordInstance, TypeFromInstance } from "@warp-drive-mirror/core/types/record";
|
|
3
4
|
import type { ConstrainedRequestOptions, PostQueryRequestOptions, QueryRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
4
|
-
import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
5
5
|
/**
|
|
6
6
|
* Builds request options to query for resources, usually by a primary
|
|
7
7
|
* type, configured for the url and header expectations of most JSON:API APIs.
|
|
@@ -49,11 +49,8 @@ import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/typ
|
|
|
49
49
|
* ```
|
|
50
50
|
*
|
|
51
51
|
* @public
|
|
52
|
-
* @param identifier
|
|
53
|
-
* @param query
|
|
54
|
-
* @param options
|
|
55
52
|
*/
|
|
56
|
-
export declare function query<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<
|
|
53
|
+
export declare function query<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
57
54
|
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
58
55
|
/**
|
|
59
56
|
* Builds request options to query for resources, usually by a primary
|
|
@@ -99,5 +96,5 @@ export declare function query(type: string, query?: QueryParamsSource, options?:
|
|
|
99
96
|
* @param query
|
|
100
97
|
* @param options
|
|
101
98
|
*/
|
|
102
|
-
export declare function postQuery<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<
|
|
99
|
+
export declare function postQuery<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
103
100
|
export declare function postQuery(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive.js";
|
|
1
2
|
import type { TypedRecordInstance } from "@warp-drive-mirror/core/types/record";
|
|
2
3
|
import type { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, UpdateRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
3
|
-
import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
4
4
|
/**
|
|
5
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Request Body**
|
|
6
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
7
|
+
* desired and correctly formatted data is sent with the request.
|
|
8
|
+
* :::
|
|
9
|
+
*
|
|
5
10
|
* Builds request options to delete record for resources,
|
|
6
11
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
7
12
|
*
|
|
@@ -53,16 +58,31 @@ import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/s
|
|
|
53
58
|
export declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
|
|
54
59
|
export declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
|
|
55
60
|
/**
|
|
61
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
|
|
62
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
63
|
+
* desired and correctly formatted data is sent with the request.
|
|
64
|
+
* :::
|
|
65
|
+
*
|
|
56
66
|
* Builds request options to create new record for resources,
|
|
57
67
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
58
68
|
*
|
|
59
69
|
* **Basic Usage**
|
|
60
70
|
*
|
|
61
71
|
* ```ts
|
|
72
|
+
* import { cacheKeyFor } from '@warp-drive-mirror/core';
|
|
62
73
|
* import { createRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* const
|
|
74
|
+
* import type { Person } from '#/data/types';
|
|
75
|
+
*
|
|
76
|
+
* const person = store.createRecord<Person>('person', { name: 'Ted' });
|
|
77
|
+
* const init = createRecord(person);
|
|
78
|
+
* init.body = JSON.stringify(
|
|
79
|
+
* {
|
|
80
|
+
* // it's likely you will want to transform this data
|
|
81
|
+
* // somewhat
|
|
82
|
+
* data: store.cache.peek(cacheKeyFor(person))
|
|
83
|
+
* }
|
|
84
|
+
* );
|
|
85
|
+
* const data = await store.request(init);
|
|
66
86
|
* ```
|
|
67
87
|
*
|
|
68
88
|
* **Supplying Options to Modify the Request Behavior**
|
|
@@ -94,19 +114,34 @@ export declare function deleteRecord(record: unknown, options?: ConstrainedReque
|
|
|
94
114
|
export declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
|
|
95
115
|
export declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
|
|
96
116
|
/**
|
|
117
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
|
|
118
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
119
|
+
* desired and correctly formatted data is sent with the request.
|
|
120
|
+
* :::
|
|
121
|
+
*
|
|
97
122
|
* Builds request options to update existing record for resources,
|
|
98
123
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
99
124
|
*
|
|
100
|
-
* **
|
|
125
|
+
* **Example Usage**
|
|
101
126
|
*
|
|
102
127
|
* ```ts
|
|
128
|
+
* import { cacheKeyFor } from '@warp-drive-mirror/core';
|
|
103
129
|
* import { updateRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
130
|
+
* import type { EditablePerson } from '#/data/types';
|
|
131
|
+
*
|
|
132
|
+
* const mutable = await checkout<EditablePerson>(person);
|
|
133
|
+
* mutable.name = 'Chris';
|
|
134
|
+
* const init = updateRecord(mutable);
|
|
135
|
+
*
|
|
136
|
+
* init.body = JSON.stringify(
|
|
137
|
+
* // it's likely you will want to transform this data
|
|
138
|
+
* // somewhat, or serialize only specific properties instead
|
|
139
|
+
* serializePatch(store.cache, cacheKeyFor(mutable))
|
|
140
|
+
* );
|
|
141
|
+
* const data = await store.request(init);
|
|
108
142
|
* ```
|
|
109
143
|
*
|
|
144
|
+
*
|
|
110
145
|
* **Supplying Options to Modify the Request Behavior**
|
|
111
146
|
*
|
|
112
147
|
* The following options are supported:
|
|
@@ -140,7 +175,7 @@ export declare function updateRecord<
|
|
|
140
175
|
RT extends TypedRecordInstance = T
|
|
141
176
|
>(record: T, options?: ConstrainedRequestOptions & {
|
|
142
177
|
patch?: boolean;
|
|
143
|
-
}): UpdateRequestOptions<
|
|
178
|
+
}): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;
|
|
144
179
|
export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
145
180
|
patch?: boolean;
|
|
146
181
|
}): UpdateRequestOptions;
|
|
@@ -16,6 +16,13 @@ export type JsonApiResourcePatch = {
|
|
|
16
16
|
relationships?: Record<string, ChangedRelationshipData>;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
+
* :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
|
|
20
|
+
*
|
|
21
|
+
* While this may come as a surprise, they are intended to serialize cache state for more
|
|
22
|
+
* generalized usage. {json:api} has a large variance in acceptable shapes, and only your
|
|
23
|
+
* app can ensure that the body is correctly formatted and contains all necessary data.
|
|
24
|
+
* :::
|
|
25
|
+
*
|
|
19
26
|
* Serializes the current state of a resource or array of resources for use with POST or PUT requests.
|
|
20
27
|
*
|
|
21
28
|
* @public
|
|
@@ -30,7 +37,14 @@ export declare function serializeResources(cache: Cache, identifiers: ResourceKe
|
|
|
30
37
|
data: ResourceObject[];
|
|
31
38
|
};
|
|
32
39
|
/**
|
|
33
|
-
*
|
|
40
|
+
* :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
|
|
41
|
+
*
|
|
42
|
+
* While this may come as a surprise, they are intended to serialize cache state for more
|
|
43
|
+
* generalized usage. {json:api} has a large variance in acceptable shapes, and only your
|
|
44
|
+
* app can ensure that the body is correctly formatted and contains all necessary data.
|
|
45
|
+
* :::
|
|
46
|
+
*
|
|
47
|
+
* Serializes changes to a resource. Useful for use with building bodies for PATCH requests.
|
|
34
48
|
*
|
|
35
49
|
* Only attributes which are changed are serialized.
|
|
36
50
|
* Only relationships which are changed are serialized.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
1
2
|
import type { TypeFromInstance } from "@warp-drive-mirror/core/types/record";
|
|
2
3
|
import type { FindRecordOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from "@warp-drive-mirror/core/types/request";
|
|
3
|
-
import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
4
4
|
/**
|
|
5
5
|
* Builds request options to fetch a single resource by a known id or identifier
|
|
6
6
|
* configured for the url and header expectations of most REST APIs.
|
|
@@ -53,13 +53,10 @@ import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/s
|
|
|
53
53
|
* ```
|
|
54
54
|
*
|
|
55
55
|
* @public
|
|
56
|
-
* @param identifier
|
|
57
|
-
* @param options
|
|
58
56
|
*/
|
|
59
|
-
export
|
|
60
|
-
data: T;
|
|
61
|
-
};
|
|
62
|
-
export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
|
|
57
|
+
export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
63
58
|
export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
64
|
-
export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<
|
|
59
|
+
export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
65
60
|
export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
61
|
+
/** @deprecated use {@link ReactiveDataDocument} instead */
|
|
62
|
+
export type FindRecordResultDocument<T> = ReactiveDataDocument<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
1
2
|
import type { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
|
|
2
3
|
import type { TypeFromInstance } from "@warp-drive-mirror/core/types/record";
|
|
3
4
|
import type { ConstrainedRequestOptions, QueryRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
4
|
-
import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
5
5
|
/**
|
|
6
6
|
* Builds request options to query for resources, usually by a primary
|
|
7
7
|
* type, configured for the url and header expectations of most REST APIs.
|
|
@@ -49,5 +49,5 @@ import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/typ
|
|
|
49
49
|
* @param query
|
|
50
50
|
* @param options
|
|
51
51
|
*/
|
|
52
|
-
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<
|
|
52
|
+
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
53
53
|
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
1
2
|
import type { TypedRecordInstance } from "@warp-drive-mirror/core/types/record";
|
|
2
3
|
import type { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, UpdateRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
3
|
-
import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
4
4
|
/**
|
|
5
5
|
* Builds request options to delete record for resources,
|
|
6
6
|
* configured for the url, method and header expectations of REST APIs.
|
|
@@ -140,7 +140,7 @@ export declare function updateRecord<
|
|
|
140
140
|
RT extends TypedRecordInstance = T
|
|
141
141
|
>(record: T, options?: ConstrainedRequestOptions & {
|
|
142
142
|
patch?: boolean;
|
|
143
|
-
}): UpdateRequestOptions<
|
|
143
|
+
}): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;
|
|
144
144
|
export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
145
145
|
patch?: boolean;
|
|
146
146
|
}): UpdateRequestOptions;
|
package/dist/active-record.js
CHANGED
|
@@ -88,6 +88,8 @@ function findRecord(arg1, arg2, arg3) {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/** @deprecated use {@link ReactiveDataDocument} instead */
|
|
92
|
+
|
|
91
93
|
/**
|
|
92
94
|
* Builds request options to query for resources, usually by a primary
|
|
93
95
|
* type, configured for the url and header expectations of most ActiveRecord APIs.
|
package/dist/handlers.js
CHANGED
|
@@ -35,7 +35,7 @@ const DEFAULT_CONSTRAINTS = {
|
|
|
35
35
|
DataView: 1000,
|
|
36
36
|
String: 1000
|
|
37
37
|
};
|
|
38
|
-
const TypedArray = Object.getPrototypeOf(Uint8Array
|
|
38
|
+
const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* A request handler that automatically compresses the request body
|
|
@@ -84,7 +84,7 @@ class AutoCompress {
|
|
|
84
84
|
const {
|
|
85
85
|
body
|
|
86
86
|
} = request;
|
|
87
|
-
const shouldCompress = isCompressibleMethod(request.method) && request.options?.compress !== false && (
|
|
87
|
+
const shouldCompress = !!body && isCompressibleMethod(request.method) && request.options?.compress !== false && (
|
|
88
88
|
// prettier-ignore
|
|
89
89
|
request.options?.compress ? true : typeof body === 'string' || body instanceof String ? canCompress('String', constraints, body.length) : body instanceof Blob ? canCompress('Blob', constraints, body.size) : body instanceof ArrayBuffer ? canCompress('ArrayBuffer', constraints, body.byteLength) : body instanceof DataView ? canCompress('DataView', constraints, body.byteLength) : body instanceof TypedArray ? canCompress('TypedArray', constraints, body.byteLength) : false);
|
|
90
90
|
if (!shouldCompress) return next(request);
|
|
@@ -218,7 +218,7 @@ class Gate {
|
|
|
218
218
|
* ```
|
|
219
219
|
*
|
|
220
220
|
* Errors are not processed by this handler, so if the request fails and the error response
|
|
221
|
-
* is not in {
|
|
221
|
+
* is not in {json:api} format additional processing may be needed.
|
|
222
222
|
*
|
|
223
223
|
* @group Handlers
|
|
224
224
|
*/
|