@warp-drive-mirror/utilities 5.8.0-beta.0 → 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 (74) hide show
  1. package/README.md +16 -25
  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/handlers/meta-doc.d.ts +1 -1
  6. package/declarations/-private/json-api/find-record.d.ts +37 -18
  7. package/declarations/-private/json-api/query.d.ts +3 -6
  8. package/declarations/-private/json-api/save-record.d.ts +45 -10
  9. package/declarations/-private/json-api/serialize.d.ts +15 -1
  10. package/declarations/-private/rest/find-record.d.ts +5 -8
  11. package/declarations/-private/rest/query.d.ts +2 -2
  12. package/declarations/-private/rest/save-record.d.ts +2 -2
  13. package/dist/active-record.js +2 -0
  14. package/dist/handlers.js +3 -3
  15. package/dist/json-api.js +94 -26
  16. package/dist/rest.js +2 -2
  17. package/dist/string.js +428 -1
  18. package/dist/unpkg/dev/-private.js +7 -0
  19. package/dist/unpkg/dev/active-record.js +394 -0
  20. package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +22 -0
  21. package/dist/unpkg/dev/derivations.js +30 -0
  22. package/dist/unpkg/dev/handlers.js +316 -0
  23. package/dist/unpkg/dev/index.js +362 -0
  24. package/dist/unpkg/dev/inflect-BEv8WqY1.js +343 -0
  25. package/dist/unpkg/dev/json-api.js +740 -0
  26. package/dist/unpkg/dev/rest.js +392 -0
  27. package/dist/unpkg/dev/string.js +1 -0
  28. package/dist/unpkg/dev-deprecated/-private.js +7 -0
  29. package/dist/unpkg/dev-deprecated/active-record.js +394 -0
  30. package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +22 -0
  31. package/dist/unpkg/dev-deprecated/derivations.js +30 -0
  32. package/dist/unpkg/dev-deprecated/handlers.js +316 -0
  33. package/dist/unpkg/dev-deprecated/index.js +362 -0
  34. package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +343 -0
  35. package/dist/unpkg/dev-deprecated/json-api.js +740 -0
  36. package/dist/unpkg/dev-deprecated/rest.js +392 -0
  37. package/dist/unpkg/dev-deprecated/string.js +1 -0
  38. package/dist/unpkg/prod/-private.js +7 -0
  39. package/dist/unpkg/prod/active-record.js +366 -0
  40. package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +22 -0
  41. package/dist/unpkg/prod/derivations.js +30 -0
  42. package/dist/unpkg/prod/handlers.js +305 -0
  43. package/dist/unpkg/prod/index.js +239 -0
  44. package/dist/unpkg/prod/inflect-Dh9dyEYx.js +333 -0
  45. package/dist/unpkg/prod/json-api.js +702 -0
  46. package/dist/unpkg/prod/rest.js +364 -0
  47. package/dist/unpkg/prod/string.js +1 -0
  48. package/dist/unpkg/prod-deprecated/-private.js +7 -0
  49. package/dist/unpkg/prod-deprecated/active-record.js +366 -0
  50. package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +22 -0
  51. package/dist/unpkg/prod-deprecated/derivations.js +30 -0
  52. package/dist/unpkg/prod-deprecated/handlers.js +305 -0
  53. package/dist/unpkg/prod-deprecated/index.js +239 -0
  54. package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +333 -0
  55. package/dist/unpkg/prod-deprecated/json-api.js +702 -0
  56. package/dist/unpkg/prod-deprecated/rest.js +364 -0
  57. package/dist/unpkg/prod-deprecated/string.js +1 -0
  58. package/logos/README.md +2 -2
  59. package/logos/logo-yellow-slab.svg +1 -0
  60. package/logos/word-mark-black.svg +1 -0
  61. package/logos/word-mark-white.svg +1 -0
  62. package/package.json +13 -5
  63. package/logos/NCC-1701-a-blue.svg +0 -4
  64. package/logos/NCC-1701-a-gold.svg +0 -4
  65. package/logos/NCC-1701-a-gold_100.svg +0 -1
  66. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  67. package/logos/NCC-1701-a.svg +0 -4
  68. package/logos/docs-badge.svg +0 -2
  69. package/logos/ember-data-logo-dark.svg +0 -12
  70. package/logos/ember-data-logo-light.svg +0 -12
  71. package/logos/social1.png +0 -0
  72. package/logos/social2.png +0 -0
  73. package/logos/warp-drive-logo-dark.svg +0 -4
  74. package/logos/warp-drive-logo-gold.svg +0 -4
package/README.md CHANGED
@@ -1,25 +1,24 @@
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
- [![Discord Community Server](https://img.shields.io/badge/Discord-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
15
+ )
16
+ [![WarpDrive Discord Server](https://img.shields.io/badge/WarpDrive-grey?logo=discord&logoColor=fdb155)](https://discord.gg/PHBbnWJx5S
21
17
  )
22
18
 
19
+ # @warp-drive-mirror/utilities
20
+
21
+
23
22
  <br>
24
23
 
25
24
  <p align="center">
@@ -28,14 +27,6 @@ Utilities that Apps building with <em>Warp</em><strong>Drive</strong> may find u
28
27
 
29
28
  <br>
30
29
 
31
- ## Installation
32
-
33
- ```sh
34
- pnpm add -E @warp-drive-mirror/utilities
35
- ```
36
-
37
- <br>
38
-
39
30
  ## Documentation
40
31
 
41
32
  *Get Started* → [Guides](https://docs.warp-drive.io)
@@ -45,7 +36,7 @@ pnpm add -E @warp-drive-mirror/utilities
45
36
 
46
37
  ## Code of Conduct
47
38
 
48
- 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.
49
40
 
50
41
  <br>
51
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;
@@ -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 {JSON:API} format additional processing may be needed.
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
- * **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/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.prototype);
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 {JSON:API} format additional processing may be needed.
221
+ * is not in {json:api} format additional processing may be needed.
222
222
  *
223
223
  * @group Handlers
224
224
  */