@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.
Files changed (72) hide show
  1. package/README.md +14 -26
  2. package/declarations/-private/active-record/find-record.d.ts +5 -6
  3. package/declarations/-private/active-record/query.d.ts +2 -2
  4. package/declarations/-private/active-record/save-record.d.ts +2 -2
  5. package/declarations/-private/json-api/find-record.d.ts +37 -18
  6. package/declarations/-private/json-api/query.d.ts +3 -6
  7. package/declarations/-private/json-api/save-record.d.ts +45 -10
  8. package/declarations/-private/json-api/serialize.d.ts +15 -1
  9. package/declarations/-private/rest/find-record.d.ts +5 -8
  10. package/declarations/-private/rest/query.d.ts +2 -2
  11. package/declarations/-private/rest/save-record.d.ts +2 -2
  12. package/dist/active-record.js +2 -0
  13. package/dist/json-api.js +94 -26
  14. package/dist/rest.js +2 -2
  15. package/dist/string.js +428 -1
  16. package/dist/unpkg/dev/-private.js +7 -0
  17. package/dist/unpkg/dev/active-record.js +394 -0
  18. package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +22 -0
  19. package/dist/unpkg/dev/derivations.js +30 -0
  20. package/dist/unpkg/dev/handlers.js +316 -0
  21. package/dist/unpkg/dev/index.js +362 -0
  22. package/dist/unpkg/dev/inflect-BEv8WqY1.js +343 -0
  23. package/dist/unpkg/dev/json-api.js +740 -0
  24. package/dist/unpkg/dev/rest.js +392 -0
  25. package/dist/unpkg/dev/string.js +1 -0
  26. package/dist/unpkg/dev-deprecated/-private.js +7 -0
  27. package/dist/unpkg/dev-deprecated/active-record.js +394 -0
  28. package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +22 -0
  29. package/dist/unpkg/dev-deprecated/derivations.js +30 -0
  30. package/dist/unpkg/dev-deprecated/handlers.js +316 -0
  31. package/dist/unpkg/dev-deprecated/index.js +362 -0
  32. package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +343 -0
  33. package/dist/unpkg/dev-deprecated/json-api.js +740 -0
  34. package/dist/unpkg/dev-deprecated/rest.js +392 -0
  35. package/dist/unpkg/dev-deprecated/string.js +1 -0
  36. package/dist/unpkg/prod/-private.js +7 -0
  37. package/dist/unpkg/prod/active-record.js +366 -0
  38. package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +22 -0
  39. package/dist/unpkg/prod/derivations.js +30 -0
  40. package/dist/unpkg/prod/handlers.js +305 -0
  41. package/dist/unpkg/prod/index.js +239 -0
  42. package/dist/unpkg/prod/inflect-Dh9dyEYx.js +333 -0
  43. package/dist/unpkg/prod/json-api.js +702 -0
  44. package/dist/unpkg/prod/rest.js +364 -0
  45. package/dist/unpkg/prod/string.js +1 -0
  46. package/dist/unpkg/prod-deprecated/-private.js +7 -0
  47. package/dist/unpkg/prod-deprecated/active-record.js +366 -0
  48. package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +22 -0
  49. package/dist/unpkg/prod-deprecated/derivations.js +30 -0
  50. package/dist/unpkg/prod-deprecated/handlers.js +305 -0
  51. package/dist/unpkg/prod-deprecated/index.js +239 -0
  52. package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +333 -0
  53. package/dist/unpkg/prod-deprecated/json-api.js +702 -0
  54. package/dist/unpkg/prod-deprecated/rest.js +364 -0
  55. package/dist/unpkg/prod-deprecated/string.js +1 -0
  56. package/logos/README.md +2 -2
  57. package/logos/logo-yellow-slab.svg +1 -0
  58. package/logos/word-mark-black.svg +1 -0
  59. package/logos/word-mark-white.svg +1 -0
  60. package/package.json +12 -4
  61. package/logos/NCC-1701-a-blue.svg +0 -4
  62. package/logos/NCC-1701-a-gold.svg +0 -4
  63. package/logos/NCC-1701-a-gold_100.svg +0 -1
  64. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  65. package/logos/NCC-1701-a.svg +0 -4
  66. package/logos/docs-badge.svg +0 -2
  67. package/logos/ember-data-logo-dark.svg +0 -12
  68. package/logos/ember-data-logo-light.svg +0 -12
  69. package/logos/social1.png +0 -0
  70. package/logos/social2.png +0 -0
  71. package/logos/warp-drive-logo-dark.svg +0 -4
  72. package/logos/warp-drive-logo-gold.svg +0 -4
package/README.md CHANGED
@@ -1,27 +1,23 @@
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
- />
1
+ <p align="center">
8
2
  <img
9
3
  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"
4
+ src="./logos/logo-yellow-slab.svg"
5
+ alt="WarpDrive"
6
+ width="180px"
7
+ title="WarpDrive"
13
8
  />
14
- </h1>
9
+ </p>
15
10
 
16
- ![NPM Stable Version](https://img.shields.io/npm/v/ember-data/latest?label=version&style=flat&color=FFC474)
17
- ![NPM Downloads](https://img.shields.io/npm/dm/ember-data.svg?style=flat&color=FFC474)
18
- ![License](https://img.shields.io/github/license/emberjs/data.svg?style=flat&color=FFC474)
19
- [![Docs](./logos/docs-badge.svg)](https://docs.warp-drive.io)
20
- [![EmberJS Discord Community Server](https://img.shields.io/badge/EmberJS-grey?logo=discord&logoColor=FFC474)](https://discord.gg/zT3asNS
11
+ ![NPM Stable Version](https://img.shields.io/npm/v/ember-data/latest?label=version&style=flat&color=fdb155)
12
+ ![NPM Downloads](https://img.shields.io/npm/dm/ember-data.svg?style=flat&color=fdb155)
13
+ ![License](https://img.shields.io/github/license/warp-drive-data/warp-drive.svg?style=flat&color=fdb155)
14
+ [![EmberJS Discord Community Server](https://img.shields.io/badge/EmberJS-grey?logo=discord&logoColor=fdb155)](https://discord.gg/zT3asNS
21
15
  )
22
- [![WarpDrive Discord Server](https://img.shields.io/badge/WarpDrive-grey?logo=discord&logoColor=FFC474)](https://discord.gg/PHBbnWJx5S
16
+ [![WarpDrive Discord Server](https://img.shields.io/badge/WarpDrive-grey?logo=discord&logoColor=fdb155)](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/emberjs/data/blob/main/CODE_OF_CONDUCT.md) for community guidelines and inclusivity.
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<FindRecordResultDocument<T>, T>;
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<FindRecordResultDocument<T>, T>;
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<CollectionResourceDataDocument<T>>;
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<SingleResourceDataDocument<RT>, T>;
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
- * **Basic Usage**
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 data = await store.request(findRecord('person', '1'));
16
+ * const result = await store.request(
17
+ * findRecord<Person>('person', '1')
18
+ * );
14
19
  * ```
15
20
  *
16
- * **With Options**
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 options = findRecord('person', '1', { include: ['pets', 'friends'] });
22
- * const data = await store.request(options);
27
+ * const data = await store.request(
28
+ * findRecord<Person>(
29
+ * 'person', '1',
30
+ * { include: ['pets', 'friends'] }
31
+ * )
32
+ * );
23
33
  * ```
24
34
  *
25
- * **With an Identifier**
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 options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });
31
- * const data = await store.request(options);
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 options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
52
- * const data = await store.request(options);
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 type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, "data"> & {
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<FindRecordResultDocument<T>, T>;
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<CollectionResourceDataDocument<T>>;
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<CollectionResourceDataDocument<T>>;
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
- * const person = store.createRecord('person', { name: 'Ted' });
65
- * const data = await store.request(createRecord(person));
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
- * **Basic Usage**
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
- * const person = store.peekRecord('person', '1');
106
- * person.name = 'Chris';
107
- * const data = await store.request(updateRecord(person));
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<SingleResourceDataDocument<RT>, T>;
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
- * Serializes changes to a resource for use with PATCH requests.
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 type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, "data"> & {
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<FindRecordResultDocument<T>, T>;
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<CollectionResourceDataDocument<T>>;
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<SingleResourceDataDocument<RT>, T>;
143
+ }): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;
144
144
  export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
145
145
  patch?: boolean;
146
146
  }): UpdateRequestOptions;
@@ -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
- * **Basic Usage**
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 data = await store.request(findRecord('person', '1'));
85
+ * const result = await store.request(
86
+ * findRecord<Person>('person', '1')
87
+ * );
83
88
  * ```
84
89
  *
85
- * **With Options**
90
+ * == With Options
86
91
  *
87
92
  * ```ts
88
93
  * import { findRecord } from '@warp-drive-mirror/utilities/json-api';
89
- *
90
- * const options = findRecord('person', '1', { include: ['pets', 'friends'] });
91
- * const data = await store.request(options);
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
- * **With an Identifier**
104
+ * == With an Identifier
95
105
  *
96
106
  * ```ts
97
107
  * import { findRecord } from '@warp-drive-mirror/utilities/json-api';
98
- *
99
- * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });
100
- * const data = await store.request(options);
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 options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
121
- * const data = await store.request(options);
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
- * const person = store.createRecord('person', { name: 'Ted' });
402
- * const data = await store.request(createRecord(person));
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
- * **Basic Usage**
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
- * const person = store.peekRecord('person', '1');
470
- * person.name = 'Chris';
471
- * const data = await store.request(updateRecord(person));
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
- * Serializes changes to a resource for use with PATCH requests.
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.