@warp-drive-mirror/utilities 5.8.0-alpha.9 → 5.8.0-beta.1
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/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/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 +394 -0
- package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/dev/derivations.js +30 -0
- package/dist/unpkg/dev/handlers.js +316 -0
- package/dist/unpkg/dev/index.js +362 -0
- package/dist/unpkg/dev/inflect-BEv8WqY1.js +343 -0
- package/dist/unpkg/dev/json-api.js +740 -0
- package/dist/unpkg/dev/rest.js +392 -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 +394 -0
- package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/dev-deprecated/derivations.js +30 -0
- package/dist/unpkg/dev-deprecated/handlers.js +316 -0
- package/dist/unpkg/dev-deprecated/index.js +362 -0
- package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +343 -0
- package/dist/unpkg/dev-deprecated/json-api.js +740 -0
- package/dist/unpkg/dev-deprecated/rest.js +392 -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 +366 -0
- package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/prod/derivations.js +30 -0
- package/dist/unpkg/prod/handlers.js +305 -0
- package/dist/unpkg/prod/index.js +239 -0
- package/dist/unpkg/prod/inflect-Dh9dyEYx.js +333 -0
- package/dist/unpkg/prod/json-api.js +702 -0
- package/dist/unpkg/prod/rest.js +364 -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 +366 -0
- package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/prod-deprecated/derivations.js +30 -0
- package/dist/unpkg/prod-deprecated/handlers.js +305 -0
- package/dist/unpkg/prod-deprecated/index.js +239 -0
- package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +333 -0
- package/dist/unpkg/prod-deprecated/json-api.js +702 -0
- package/dist/unpkg/prod-deprecated/rest.js +364 -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 +12 -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;
|
|
@@ -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/json-api.js
CHANGED
|
@@ -74,32 +74,49 @@ function setBuildURLConfig(config) {
|
|
|
74
74
|
* Builds request options to fetch a single resource by a known id or identifier
|
|
75
75
|
* configured for the url and header expectations of most JSON:API APIs.
|
|
76
76
|
*
|
|
77
|
-
*
|
|
77
|
+
* :::tabs
|
|
78
|
+
*
|
|
79
|
+
* == Basic Usage
|
|
78
80
|
*
|
|
79
81
|
* ```ts
|
|
80
82
|
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
83
|
+
* import type { Person } from '#/data/types';
|
|
81
84
|
*
|
|
82
|
-
* const
|
|
85
|
+
* const result = await store.request(
|
|
86
|
+
* findRecord<Person>('person', '1')
|
|
87
|
+
* );
|
|
83
88
|
* ```
|
|
84
89
|
*
|
|
85
|
-
*
|
|
90
|
+
* == With Options
|
|
86
91
|
*
|
|
87
92
|
* ```ts
|
|
88
93
|
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* const data = await store.request(
|
|
94
|
+
* import type { Person } from '#/data/types';
|
|
95
|
+
*
|
|
96
|
+
* const data = await store.request(
|
|
97
|
+
* findRecord<Person>(
|
|
98
|
+
* 'person', '1',
|
|
99
|
+
* { include: ['pets', 'friends'] }
|
|
100
|
+
* )
|
|
101
|
+
* );
|
|
92
102
|
* ```
|
|
93
103
|
*
|
|
94
|
-
*
|
|
104
|
+
* == With an Identifier
|
|
95
105
|
*
|
|
96
106
|
* ```ts
|
|
97
107
|
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* const data = await store.request(
|
|
108
|
+
* import type { Person } from '#/data/types';
|
|
109
|
+
*
|
|
110
|
+
* const data = await store.request(
|
|
111
|
+
* findRecord<Person>(
|
|
112
|
+
* { type: 'person', id: '1' },
|
|
113
|
+
* { include: ['pets', 'friends'] }
|
|
114
|
+
* )
|
|
115
|
+
* );
|
|
101
116
|
* ```
|
|
102
117
|
*
|
|
118
|
+
* :::
|
|
119
|
+
*
|
|
103
120
|
* **Supplying Options to Modify the Request Behavior**
|
|
104
121
|
*
|
|
105
122
|
* The following options are supported:
|
|
@@ -117,13 +134,16 @@ function setBuildURLConfig(config) {
|
|
|
117
134
|
* ```ts
|
|
118
135
|
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
119
136
|
*
|
|
120
|
-
* const
|
|
121
|
-
*
|
|
137
|
+
* const data = await store.request(
|
|
138
|
+
* findRecord(
|
|
139
|
+
* 'person', '1',
|
|
140
|
+
* { include: ['pets', 'friends'] },
|
|
141
|
+
* { namespace: 'api/v2' }
|
|
142
|
+
* )
|
|
143
|
+
* );
|
|
122
144
|
* ```
|
|
123
145
|
*
|
|
124
146
|
* @public
|
|
125
|
-
* @param identifier
|
|
126
|
-
* @param options
|
|
127
147
|
*/
|
|
128
148
|
|
|
129
149
|
function findRecord(arg1, arg2, arg3) {
|
|
@@ -154,6 +174,8 @@ function findRecord(arg1, arg2, arg3) {
|
|
|
154
174
|
};
|
|
155
175
|
}
|
|
156
176
|
|
|
177
|
+
/** @deprecated use {@link ReactiveDataDocument} */
|
|
178
|
+
|
|
157
179
|
/**
|
|
158
180
|
* Builds request options to query for resources, usually by a primary
|
|
159
181
|
* type, configured for the url and header expectations of most JSON:API APIs.
|
|
@@ -201,9 +223,6 @@ function findRecord(arg1, arg2, arg3) {
|
|
|
201
223
|
* ```
|
|
202
224
|
*
|
|
203
225
|
* @public
|
|
204
|
-
* @param identifier
|
|
205
|
-
* @param query
|
|
206
|
-
* @param options
|
|
207
226
|
*/
|
|
208
227
|
|
|
209
228
|
function query(type,
|
|
@@ -307,6 +326,11 @@ function isExisting(identifier) {
|
|
|
307
326
|
}
|
|
308
327
|
|
|
309
328
|
/**
|
|
329
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Request Body**
|
|
330
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
331
|
+
* desired and correctly formatted data is sent with the request.
|
|
332
|
+
* :::
|
|
333
|
+
*
|
|
310
334
|
* Builds request options to delete record for resources,
|
|
311
335
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
312
336
|
*
|
|
@@ -390,16 +414,31 @@ function deleteRecord(record, options = {}) {
|
|
|
390
414
|
}
|
|
391
415
|
|
|
392
416
|
/**
|
|
417
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
|
|
418
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
419
|
+
* desired and correctly formatted data is sent with the request.
|
|
420
|
+
* :::
|
|
421
|
+
*
|
|
393
422
|
* Builds request options to create new record for resources,
|
|
394
423
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
395
424
|
*
|
|
396
425
|
* **Basic Usage**
|
|
397
426
|
*
|
|
398
427
|
* ```ts
|
|
428
|
+
* import { cacheKeyFor } from '@warp-drive-mirror/core';
|
|
399
429
|
* import { createRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* const
|
|
430
|
+
* import type { Person } from '#/data/types';
|
|
431
|
+
*
|
|
432
|
+
* const person = store.createRecord<Person>('person', { name: 'Ted' });
|
|
433
|
+
* const init = createRecord(person);
|
|
434
|
+
* init.body = JSON.stringify(
|
|
435
|
+
* {
|
|
436
|
+
* // it's likely you will want to transform this data
|
|
437
|
+
* // somewhat
|
|
438
|
+
* data: store.cache.peek(cacheKeyFor(person))
|
|
439
|
+
* }
|
|
440
|
+
* );
|
|
441
|
+
* const data = await store.request(init);
|
|
403
442
|
* ```
|
|
404
443
|
*
|
|
405
444
|
* **Supplying Options to Modify the Request Behavior**
|
|
@@ -458,19 +497,34 @@ function createRecord(record, options = {}) {
|
|
|
458
497
|
}
|
|
459
498
|
|
|
460
499
|
/**
|
|
500
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
|
|
501
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
502
|
+
* desired and correctly formatted data is sent with the request.
|
|
503
|
+
* :::
|
|
504
|
+
*
|
|
461
505
|
* Builds request options to update existing record for resources,
|
|
462
506
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
463
507
|
*
|
|
464
|
-
* **
|
|
508
|
+
* **Example Usage**
|
|
465
509
|
*
|
|
466
510
|
* ```ts
|
|
511
|
+
* import { cacheKeyFor } from '@warp-drive-mirror/core';
|
|
467
512
|
* import { updateRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
513
|
+
* import type { EditablePerson } from '#/data/types';
|
|
514
|
+
*
|
|
515
|
+
* const mutable = await checkout<EditablePerson>(person);
|
|
516
|
+
* mutable.name = 'Chris';
|
|
517
|
+
* const init = updateRecord(mutable);
|
|
518
|
+
*
|
|
519
|
+
* init.body = JSON.stringify(
|
|
520
|
+
* // it's likely you will want to transform this data
|
|
521
|
+
* // somewhat, or serialize only specific properties instead
|
|
522
|
+
* serializePatch(store.cache, cacheKeyFor(mutable))
|
|
523
|
+
* );
|
|
524
|
+
* const data = await store.request(init);
|
|
472
525
|
* ```
|
|
473
526
|
*
|
|
527
|
+
*
|
|
474
528
|
* **Supplying Options to Modify the Request Behavior**
|
|
475
529
|
*
|
|
476
530
|
* The following options are supported:
|
|
@@ -534,6 +588,13 @@ function updateRecord(record, options = {}) {
|
|
|
534
588
|
}
|
|
535
589
|
|
|
536
590
|
/**
|
|
591
|
+
* :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
|
|
592
|
+
*
|
|
593
|
+
* While this may come as a surprise, they are intended to serialize cache state for more
|
|
594
|
+
* generalized usage. {json:api} has a large variance in acceptable shapes, and only your
|
|
595
|
+
* app can ensure that the body is correctly formatted and contains all necessary data.
|
|
596
|
+
* :::
|
|
597
|
+
*
|
|
537
598
|
* Serializes the current state of a resource or array of resources for use with POST or PUT requests.
|
|
538
599
|
*
|
|
539
600
|
* @public
|
|
@@ -606,7 +667,14 @@ function _serializeResource(cache, identifier) {
|
|
|
606
667
|
}
|
|
607
668
|
|
|
608
669
|
/**
|
|
609
|
-
*
|
|
670
|
+
* :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
|
|
671
|
+
*
|
|
672
|
+
* While this may come as a surprise, they are intended to serialize cache state for more
|
|
673
|
+
* generalized usage. {json:api} has a large variance in acceptable shapes, and only your
|
|
674
|
+
* app can ensure that the body is correctly formatted and contains all necessary data.
|
|
675
|
+
* :::
|
|
676
|
+
*
|
|
677
|
+
* Serializes changes to a resource. Useful for use with building bodies for PATCH requests.
|
|
610
678
|
*
|
|
611
679
|
* Only attributes which are changed are serialized.
|
|
612
680
|
* Only relationships which are changed are serialized.
|