@warp-drive/legacy 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 (200) hide show
  1. package/README.md +14 -27
  2. package/declarations/adapter/error.d.ts +7 -7
  3. package/declarations/adapter/json-api.d.ts +2 -2
  4. package/declarations/adapter/rest.d.ts +21 -104
  5. package/declarations/adapter.d.ts +2 -2
  6. package/declarations/compat/builders/find-all.d.ts +6 -6
  7. package/declarations/compat/builders/find-record.d.ts +8 -8
  8. package/declarations/compat/builders/query.d.ts +12 -12
  9. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +16 -24
  10. package/declarations/compat/utils.d.ts +13 -13
  11. package/declarations/compat.d.ts +31 -5
  12. package/declarations/index.d.ts +25 -8
  13. package/declarations/model/-private/legacy-relationships-support.d.ts +2 -2
  14. package/declarations/model/-private/model.d.ts +10 -51
  15. package/declarations/model/-private/promise-many-array.d.ts +0 -18
  16. package/declarations/model/-private/references/belongs-to.d.ts +18 -28
  17. package/declarations/model/-private/references/has-many.d.ts +13 -15
  18. package/declarations/model/migration-support.d.ts +42 -19
  19. package/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  20. package/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  21. package/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  22. package/declarations/model-fragments/index.d.ts +5 -0
  23. package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  24. package/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  25. package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  26. package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  27. package/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  28. package/declarations/model-fragments.d.ts +9 -0
  29. package/declarations/model.d.ts +2 -2
  30. package/declarations/serializer/-private/embedded-records-mixin.d.ts +1 -1
  31. package/declarations/serializer/json-api.d.ts +7 -6
  32. package/declarations/serializer/json.d.ts +3 -3
  33. package/declarations/serializer.d.ts +5 -6
  34. package/dist/{-private-B1pSSN52.js → -private-BG3bMiKp.js} +2 -1
  35. package/dist/adapter/-private.js +1 -1
  36. package/dist/adapter/error.js +9 -9
  37. package/dist/adapter/json-api.js +1 -1
  38. package/dist/adapter/rest.js +33 -117
  39. package/dist/adapter.js +2 -2
  40. package/dist/compat/-private.js +1 -1
  41. package/dist/compat/builders.js +26 -26
  42. package/dist/compat/utils.js +13 -14
  43. package/dist/compat.js +28 -8
  44. package/dist/{errors-COviC59J.js → errors-Cz5KrzBk.js} +113 -120
  45. package/dist/{hooks-Bp8SIQBU.js → hooks-D6diaM34.js} +1 -1
  46. package/dist/index.js +25 -8
  47. package/dist/{json-ksWOHRfq.js → json-ChdEfB0X.js} +12 -27
  48. package/dist/model/-private.js +1 -1
  49. package/dist/model/migration-support.js +55 -25
  50. package/dist/model-for-CqXsIKws.js +221 -0
  51. package/dist/model-fragments.js +76 -0
  52. package/dist/model.js +3 -3
  53. package/dist/{schema-provider-JlCneqZH.js → schema-provider-DJCV_6AF.js} +44 -87
  54. package/dist/{serialize-into-hash-BnYvPex3.js → serialize-into-hash-DPZYoF-i.js} +1 -1
  55. package/dist/serializer/json-api.js +18 -45
  56. package/dist/serializer/json.js +1 -1
  57. package/dist/serializer/rest.js +10 -10
  58. package/dist/serializer.js +5 -6
  59. package/dist/store.js +2 -1
  60. package/dist/unpkg/dev/-private-DtjBbEgy.js +1206 -0
  61. package/dist/unpkg/dev/adapter/-private.js +1 -0
  62. package/dist/unpkg/dev/adapter/error.js +335 -0
  63. package/dist/unpkg/dev/adapter/json-api.js +271 -0
  64. package/dist/unpkg/dev/adapter/rest.js +1171 -0
  65. package/dist/unpkg/dev/adapter.js +1252 -0
  66. package/dist/unpkg/dev/compat/-private.js +1 -0
  67. package/dist/unpkg/dev/compat/builders.js +275 -0
  68. package/dist/unpkg/dev/compat/extensions.js +242 -0
  69. package/dist/unpkg/dev/compat/utils.js +223 -0
  70. package/dist/unpkg/dev/compat.js +1147 -0
  71. package/dist/unpkg/dev/errors-DmGGJr3T.js +2562 -0
  72. package/dist/unpkg/dev/hooks-CkYiE6Ud.js +73 -0
  73. package/dist/unpkg/dev/index.js +197 -0
  74. package/dist/unpkg/dev/json-Cu1LNgmQ.js +1256 -0
  75. package/dist/unpkg/dev/model/-private.js +1 -0
  76. package/dist/unpkg/dev/model/migration-support.js +553 -0
  77. package/dist/unpkg/dev/model-for-CqXsIKws.js +221 -0
  78. package/dist/unpkg/dev/model-fragments.js +76 -0
  79. package/dist/unpkg/dev/model.js +678 -0
  80. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  81. package/dist/unpkg/dev/schema-provider-DDVYxmUV.js +2186 -0
  82. package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +259 -0
  83. package/dist/unpkg/dev/serializer/json-api.js +649 -0
  84. package/dist/unpkg/dev/serializer/json.js +4 -0
  85. package/dist/unpkg/dev/serializer/rest.js +1242 -0
  86. package/dist/unpkg/dev/serializer/transform.js +278 -0
  87. package/dist/unpkg/dev/serializer.js +248 -0
  88. package/dist/unpkg/dev/store.js +637 -0
  89. package/dist/unpkg/dev/util-DvanW33H.js +20 -0
  90. package/dist/unpkg/dev/utils-BhvS1iTS.js +8 -0
  91. package/dist/unpkg/dev-deprecated/-private-DtjBbEgy.js +1206 -0
  92. package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -0
  93. package/dist/unpkg/dev-deprecated/adapter/error.js +335 -0
  94. package/dist/unpkg/dev-deprecated/adapter/json-api.js +271 -0
  95. package/dist/unpkg/dev-deprecated/adapter/rest.js +1171 -0
  96. package/dist/unpkg/dev-deprecated/adapter.js +1252 -0
  97. package/dist/unpkg/dev-deprecated/compat/-private.js +1 -0
  98. package/dist/unpkg/dev-deprecated/compat/builders.js +275 -0
  99. package/dist/unpkg/dev-deprecated/compat/extensions.js +242 -0
  100. package/dist/unpkg/dev-deprecated/compat/utils.js +223 -0
  101. package/dist/unpkg/dev-deprecated/compat.js +1147 -0
  102. package/dist/unpkg/dev-deprecated/errors-Spt6ubMd.js +2565 -0
  103. package/dist/unpkg/dev-deprecated/hooks-DOXegvhL.js +73 -0
  104. package/dist/unpkg/dev-deprecated/index.js +196 -0
  105. package/dist/unpkg/dev-deprecated/json-Cu1LNgmQ.js +1256 -0
  106. package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
  107. package/dist/unpkg/dev-deprecated/model/migration-support.js +570 -0
  108. package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +221 -0
  109. package/dist/unpkg/dev-deprecated/model-fragments.js +76 -0
  110. package/dist/unpkg/dev-deprecated/model.js +682 -0
  111. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  112. package/dist/unpkg/dev-deprecated/schema-provider-BP6_8N-V.js +2211 -0
  113. package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +259 -0
  114. package/dist/unpkg/dev-deprecated/serializer/json-api.js +649 -0
  115. package/dist/unpkg/dev-deprecated/serializer/json.js +4 -0
  116. package/dist/unpkg/dev-deprecated/serializer/rest.js +1242 -0
  117. package/dist/unpkg/dev-deprecated/serializer/transform.js +278 -0
  118. package/dist/unpkg/dev-deprecated/serializer.js +248 -0
  119. package/dist/unpkg/dev-deprecated/store.js +637 -0
  120. package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +24 -0
  121. package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +12 -0
  122. package/dist/unpkg/prod/-private-BdyZaGEh.js +971 -0
  123. package/dist/unpkg/prod/adapter/-private.js +1 -0
  124. package/dist/unpkg/prod/adapter/error.js +330 -0
  125. package/dist/unpkg/prod/adapter/json-api.js +266 -0
  126. package/dist/unpkg/prod/adapter/rest.js +1134 -0
  127. package/dist/unpkg/prod/adapter.js +1219 -0
  128. package/dist/unpkg/prod/compat/-private.js +1 -0
  129. package/dist/unpkg/prod/compat/builders.js +210 -0
  130. package/dist/unpkg/prod/compat/extensions.js +232 -0
  131. package/dist/unpkg/prod/compat/utils.js +218 -0
  132. package/dist/unpkg/prod/compat.js +727 -0
  133. package/dist/unpkg/prod/errors-BGVFCBmi.js +2314 -0
  134. package/dist/unpkg/prod/hooks-BztVA_x0.js +41 -0
  135. package/dist/unpkg/prod/index.js +151 -0
  136. package/dist/unpkg/prod/json-BWrZ5546.js +1243 -0
  137. package/dist/unpkg/prod/model/-private.js +1 -0
  138. package/dist/unpkg/prod/model/migration-support.js +546 -0
  139. package/dist/unpkg/prod/model-for-CqXsIKws.js +221 -0
  140. package/dist/unpkg/prod/model-fragments.js +76 -0
  141. package/dist/unpkg/prod/model.js +593 -0
  142. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  143. package/dist/unpkg/prod/schema-provider-DJtD_8jZ.js +1861 -0
  144. package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +215 -0
  145. package/dist/unpkg/prod/serializer/json-api.js +592 -0
  146. package/dist/unpkg/prod/serializer/json.js +4 -0
  147. package/dist/unpkg/prod/serializer/rest.js +1210 -0
  148. package/dist/unpkg/prod/serializer/transform.js +278 -0
  149. package/dist/unpkg/prod/serializer.js +248 -0
  150. package/dist/unpkg/prod/store.js +505 -0
  151. package/dist/unpkg/prod/util-DvanW33H.js +20 -0
  152. package/dist/unpkg/prod/utils-BhvS1iTS.js +8 -0
  153. package/dist/unpkg/prod-deprecated/-private-BdyZaGEh.js +971 -0
  154. package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -0
  155. package/dist/unpkg/prod-deprecated/adapter/error.js +330 -0
  156. package/dist/unpkg/prod-deprecated/adapter/json-api.js +266 -0
  157. package/dist/unpkg/prod-deprecated/adapter/rest.js +1134 -0
  158. package/dist/unpkg/prod-deprecated/adapter.js +1219 -0
  159. package/dist/unpkg/prod-deprecated/compat/-private.js +1 -0
  160. package/dist/unpkg/prod-deprecated/compat/builders.js +210 -0
  161. package/dist/unpkg/prod-deprecated/compat/extensions.js +232 -0
  162. package/dist/unpkg/prod-deprecated/compat/utils.js +218 -0
  163. package/dist/unpkg/prod-deprecated/compat.js +727 -0
  164. package/dist/unpkg/prod-deprecated/errors-CdDaK81x.js +2317 -0
  165. package/dist/unpkg/prod-deprecated/hooks-yId87yyG.js +41 -0
  166. package/dist/unpkg/prod-deprecated/index.js +150 -0
  167. package/dist/unpkg/prod-deprecated/json-BWrZ5546.js +1243 -0
  168. package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
  169. package/dist/unpkg/prod-deprecated/model/migration-support.js +563 -0
  170. package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +221 -0
  171. package/dist/unpkg/prod-deprecated/model-fragments.js +76 -0
  172. package/dist/unpkg/prod-deprecated/model.js +596 -0
  173. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  174. package/dist/unpkg/prod-deprecated/schema-provider-CjX55uSY.js +1904 -0
  175. package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +215 -0
  176. package/dist/unpkg/prod-deprecated/serializer/json-api.js +592 -0
  177. package/dist/unpkg/prod-deprecated/serializer/json.js +4 -0
  178. package/dist/unpkg/prod-deprecated/serializer/rest.js +1210 -0
  179. package/dist/unpkg/prod-deprecated/serializer/transform.js +278 -0
  180. package/dist/unpkg/prod-deprecated/serializer.js +248 -0
  181. package/dist/unpkg/prod-deprecated/store.js +505 -0
  182. package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +23 -0
  183. package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +11 -0
  184. package/logos/README.md +2 -2
  185. package/logos/logo-yellow-slab.svg +1 -0
  186. package/logos/word-mark-black.svg +1 -0
  187. package/logos/word-mark-white.svg +1 -0
  188. package/package.json +14 -6
  189. package/logos/NCC-1701-a-blue.svg +0 -4
  190. package/logos/NCC-1701-a-gold.svg +0 -4
  191. package/logos/NCC-1701-a-gold_100.svg +0 -1
  192. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  193. package/logos/NCC-1701-a.svg +0 -4
  194. package/logos/docs-badge.svg +0 -2
  195. package/logos/ember-data-logo-dark.svg +0 -12
  196. package/logos/ember-data-logo-light.svg +0 -12
  197. package/logos/social1.png +0 -0
  198. package/logos/social2.png +0 -0
  199. package/logos/warp-drive-logo-dark.svg +0 -4
  200. package/logos/warp-drive-logo-gold.svg +0 -4
@@ -0,0 +1 @@
1
+ export { F as FetchManager, S as SaveOp, c as Snapshot, b as SnapshotRecordArray, u as upgradeStore } from "../-private-DtjBbEgy.js";
@@ -0,0 +1,275 @@
1
+ import { SkipCache } from '@warp-drive/core/types/request';
2
+ import { n as normalizeModelName, i as isMaybeIdentifier } from "../utils-C9PJehtL.js";
3
+ import { ensureStringId, constructResource, assertPrivateStore } from '@warp-drive/core/store/-private';
4
+ import { storeFor, recordIdentifierFor } from '@warp-drive/core';
5
+
6
+ /**
7
+ This function builds a request config to perform a `findAll` request for the given type.
8
+ When passed to `store.request`, this config will result in the same behavior as a `store.findAll` request.
9
+ Additionally, it takes the same options as `store.findAll`.
10
+
11
+ All `@warp-drive/legacy/compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
12
+ This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
13
+ To that end, these builders are deprecated and will be removed in a future version of WarpDrive.
14
+
15
+ @deprecated
16
+ @public
17
+ @param type the name of the resource
18
+ @param query a query to be used by the adapter
19
+ @param options optional, may include `adapterOptions` hash which will be passed to adapter.findAll
20
+ @return request config
21
+ */
22
+
23
+ function findAllBuilder(type, options = {}) {
24
+ (test => {
25
+ if (!test) {
26
+ throw new Error(`You need to pass a model name to the findAll builder`);
27
+ }
28
+ })(type);
29
+ (test => {
30
+ if (!test) {
31
+ throw new Error(`Model name passed to the findAll builder must be a dasherized string instead of ${type}`);
32
+ }
33
+ })(typeof type === 'string');
34
+ return {
35
+ op: 'findAll',
36
+ data: {
37
+ type: normalizeModelName(type),
38
+ options: options || {}
39
+ },
40
+ cacheOptions: {
41
+ [SkipCache]: true
42
+ }
43
+ };
44
+ }
45
+
46
+ /**
47
+ This function builds a request config to find the record for a given identifier or type and id combination.
48
+ When passed to `store.request`, this config will result in the same behavior as a `store.findRecord` request.
49
+ Additionally, it takes the same options as `store.findRecord`, with the exception of `preload` (which is unsupported).
50
+
51
+ **Example 1**
52
+
53
+ ```ts
54
+ import { findRecord } from '@warp-drive/legacy/compat/builders';
55
+ const { content: post } = await store.request<Post>(findRecord<Post>('post', '1'));
56
+ ```
57
+
58
+ **Example 2**
59
+
60
+ `findRecord` can be called with a single identifier argument instead of the combination
61
+ of `type` (modelName) and `id` as separate arguments. You may recognize this combo as
62
+ the typical pairing from [JSON:API](https://jsonapi.org/format/#document-resource-object-identification)
63
+
64
+ ```ts
65
+ import { findRecord } from '@warp-drive/legacy/compat/builders';
66
+ const { content: post } = await store.request<Post>(findRecord<Post>({ type: 'post', id }));
67
+ ```
68
+
69
+ All `@warp-drive/legacy/compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
70
+ This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
71
+ To that end, these builders are deprecated and will be removed in a future version of Warp Drive.
72
+
73
+ @deprecated
74
+ @public
75
+ @param resource - either a string representing the name of the resource or a ResourceIdentifier object containing both the type (a string) and the id (a string) for the record or an lid (a string) of an existing record
76
+ @param id - optional object with options for the request only if the first param is a ResourceIdentifier, else the string id of the record to be retrieved
77
+ @param options - if the first param is a string this will be the optional options for the request. See examples for available options.
78
+ @return request config
79
+ */
80
+
81
+ function findRecordBuilder(resource, idOrOptions, options) {
82
+ (test => {
83
+ if (!test) {
84
+ throw new Error(`You need to pass a modelName or resource identifier as the first argument to the findRecord builder`);
85
+ }
86
+ })(resource);
87
+ if (isMaybeIdentifier(resource)) {
88
+ options = idOrOptions;
89
+ } else {
90
+ (test => {
91
+ if (!test) {
92
+ throw new Error(`You need to pass a modelName or resource identifier as the first argument to the findRecord builder (passed ${resource})`);
93
+ }
94
+ })(typeof resource === 'string');
95
+ const type = normalizeModelName(resource);
96
+ const normalizedId = ensureStringId(idOrOptions);
97
+ resource = constructResource(type, normalizedId);
98
+ }
99
+ options = options || {};
100
+ (test => {
101
+ if (!test) {
102
+ throw new Error('findRecord builder does not support options.preload');
103
+ }
104
+ })(!options.preload);
105
+ return {
106
+ op: 'findRecord',
107
+ data: {
108
+ record: resource,
109
+ options
110
+ },
111
+ cacheOptions: {
112
+ [SkipCache]: true
113
+ }
114
+ };
115
+ }
116
+
117
+ /**
118
+ This function builds a request config for a given type and query object.
119
+ When passed to `store.request`, this config will result in the same behavior as a `store.query` request.
120
+ Additionally, it takes the same options as `store.query`.
121
+
122
+ All `@warp-drive/legacy/compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
123
+ This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
124
+ To that end, these builders are deprecated and will be removed in a future version of WarpDrive.
125
+
126
+ @deprecated
127
+ @public
128
+ @param type the name of the resource
129
+ @param query a query to be used by the adapter
130
+ @param options optional, may include `adapterOptions` hash which will be passed to adapter.query
131
+ @return request config
132
+ */
133
+
134
+ function queryBuilder(type, query, options = {}) {
135
+ (test => {
136
+ if (!test) {
137
+ throw new Error(`You need to pass a model name to the query builder`);
138
+ }
139
+ })(type);
140
+ (test => {
141
+ if (!test) {
142
+ throw new Error(`You need to pass a query hash to the query builder`);
143
+ }
144
+ })(query);
145
+ (test => {
146
+ if (!test) {
147
+ throw new Error(`Model name passed to the query builder must be a dasherized string instead of ${type}`);
148
+ }
149
+ })(typeof type === 'string');
150
+ return {
151
+ op: 'query',
152
+ data: {
153
+ type: normalizeModelName(type),
154
+ query,
155
+ options: options
156
+ },
157
+ cacheOptions: {
158
+ [SkipCache]: true
159
+ }
160
+ };
161
+ }
162
+
163
+ /**
164
+ This function builds a request config for a given type and query object.
165
+ When passed to `store.request`, this config will result in the same behavior as a `store.queryRecord` request.
166
+ Additionally, it takes the same options as `store.queryRecord`.
167
+
168
+ All `@warp-drive/legacy/compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
169
+ This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
170
+ To that end, these builders are deprecated and will be removed in a future version of WarpDrive.
171
+
172
+ @deprecated
173
+ @public
174
+ @param type the name of the resource
175
+ @param query a query to be used by the adapter
176
+ @param options optional, may include `adapterOptions` hash which will be passed to adapter.query
177
+ @return request config
178
+ */
179
+
180
+ function queryRecordBuilder(type, query, options) {
181
+ (test => {
182
+ if (!test) {
183
+ throw new Error(`You need to pass a model name to the queryRecord builder`);
184
+ }
185
+ })(type);
186
+ (test => {
187
+ if (!test) {
188
+ throw new Error(`You need to pass a query hash to the queryRecord builder`);
189
+ }
190
+ })(query);
191
+ (test => {
192
+ if (!test) {
193
+ throw new Error(`Model name passed to the queryRecord builder must be a dasherized string instead of ${type}`);
194
+ }
195
+ })(typeof type === 'string');
196
+ return {
197
+ op: 'queryRecord',
198
+ data: {
199
+ type: normalizeModelName(type),
200
+ query,
201
+ options: options || {}
202
+ },
203
+ cacheOptions: {
204
+ [SkipCache]: true
205
+ }
206
+ };
207
+ }
208
+ function _resourceIsFullDeleted(identifier, cache) {
209
+ return cache.isDeletionCommitted(identifier) || cache.isNew(identifier) && cache.isDeleted(identifier);
210
+ }
211
+ function resourceIsFullyDeleted(instanceCache, identifier) {
212
+ const cache = instanceCache.cache;
213
+ return !cache || _resourceIsFullDeleted(identifier, cache);
214
+ }
215
+
216
+ /**
217
+ This function builds a request config for saving the given record (e.g. creating, updating, or deleting the record).
218
+ When passed to `store.request`, this config will result in the same behavior as a legacy `store.saveRecord` request.
219
+ Additionally, it takes the same options as `store.saveRecord`.
220
+
221
+ All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
222
+ This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
223
+ To that end, these builders are deprecated and will be removed in a future version of Ember Data.
224
+
225
+ @deprecated
226
+ @public
227
+ @param {Object} record a record to save
228
+ @param {SaveRecordBuilderOptions} options optional, may include `adapterOptions` hash which will be passed to adapter.saveRecord
229
+ @return {SaveRecordRequestInput} request config
230
+ */
231
+ function saveRecordBuilder(record, options = {}) {
232
+ const store = storeFor(record, true);
233
+ assertPrivateStore(store);
234
+ (test => {
235
+ if (!test) {
236
+ throw new Error(`Unable to initiate save for a record in a disconnected state`);
237
+ }
238
+ })(store);
239
+ const identifier = recordIdentifierFor(record);
240
+ if (!identifier) {
241
+ // this commonly means we're disconnected
242
+ // but just in case we throw here to prevent bad things.
243
+ throw new Error(`Record Is Disconnected`);
244
+ }
245
+ (test => {
246
+ if (!test) {
247
+ throw new Error(`Cannot initiate a save request for an unloaded record: ${identifier.lid}`);
248
+ }
249
+ })(store._instanceCache.recordIsLoaded(identifier));
250
+ if (resourceIsFullyDeleted(store._instanceCache, identifier)) {
251
+ throw new Error('cannot build saveRecord request for deleted record');
252
+ }
253
+ if (!options) {
254
+ options = {};
255
+ }
256
+ let operation = 'updateRecord';
257
+ const cache = store.cache;
258
+ if (cache.isNew(identifier)) {
259
+ operation = 'createRecord';
260
+ } else if (cache.isDeleted(identifier)) {
261
+ operation = 'deleteRecord';
262
+ }
263
+ return {
264
+ op: operation,
265
+ data: {
266
+ options,
267
+ record: identifier
268
+ },
269
+ records: [identifier],
270
+ cacheOptions: {
271
+ [SkipCache]: true
272
+ }
273
+ };
274
+ }
275
+ export { findAllBuilder as findAll, findRecordBuilder as findRecord, queryBuilder as query, queryRecordBuilder as queryRecord, saveRecordBuilder as saveRecord };
@@ -0,0 +1,242 @@
1
+ import { get, set } from '@ember/object';
2
+ import { compare } from '@ember/utils';
3
+ import Ember from 'ember';
4
+ const EmberObjectFeatures = {};
5
+ const EmberObjectMethods = ['addObserver', 'cacheFor', 'decrementProperty', 'get', 'getProperties', 'incrementProperty', 'notifyPropertyChange', 'removeObserver', 'set', 'setProperties', 'toggleProperty'];
6
+ EmberObjectMethods.forEach(method => {
7
+ EmberObjectFeatures[method] = function delegatedMethod(...args) {
8
+ return Ember[method](this, ...args);
9
+ };
10
+ });
11
+ const EmberObjectArrayExtension = {
12
+ kind: 'array',
13
+ name: 'ember-object',
14
+ features: EmberObjectFeatures
15
+ };
16
+ const EmberObjectExtension = {
17
+ kind: 'object',
18
+ name: 'ember-object',
19
+ features: EmberObjectFeatures
20
+ };
21
+ const EmberArrayLikeFeatures = {
22
+ addObject(obj) {
23
+ const index = this.indexOf(obj);
24
+ if (index === -1) {
25
+ this.push(obj);
26
+ }
27
+ return this;
28
+ },
29
+ addObjects(objs) {
30
+ objs.forEach(obj => {
31
+ const index = this.indexOf(obj);
32
+ if (index === -1) {
33
+ this.push(obj);
34
+ }
35
+ });
36
+ return this;
37
+ },
38
+ popObject() {
39
+ return this.pop();
40
+ },
41
+ pushObject(obj) {
42
+ this.push(obj);
43
+ return obj;
44
+ },
45
+ pushObjects(objs) {
46
+ this.push(...objs);
47
+ return this;
48
+ },
49
+ shiftObject() {
50
+ return this.shift();
51
+ },
52
+ unshiftObject(obj) {
53
+ this.unshift(obj);
54
+ return obj;
55
+ },
56
+ unshiftObjects(objs) {
57
+ this.unshift(...objs);
58
+ return this;
59
+ },
60
+ objectAt(index) {
61
+ //For negative index values go back from the end of the array
62
+ const arrIndex = Math.sign(index) === -1 ? this.length + index : index;
63
+ return this[arrIndex];
64
+ },
65
+ objectsAt(indices) {
66
+ // @ts-expect-error adding MutableArray method
67
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
68
+ return indices.map(index => this.objectAt(index));
69
+ },
70
+ removeAt(index) {
71
+ this.splice(index, 1);
72
+ return this;
73
+ },
74
+ insertAt(index, obj) {
75
+ this.splice(index, 0, obj);
76
+ return this;
77
+ },
78
+ removeObject(obj) {
79
+ const index = this.indexOf(obj);
80
+ if (index !== -1) {
81
+ this.splice(index, 1);
82
+ }
83
+ return this;
84
+ },
85
+ removeObjects(objs) {
86
+ objs.forEach(obj => {
87
+ const index = this.indexOf(obj);
88
+ if (index !== -1) {
89
+ this.splice(index, 1);
90
+ }
91
+ });
92
+ return this;
93
+ },
94
+ toArray() {
95
+ return this.slice();
96
+ },
97
+ replace(idx, amt, objects) {
98
+ if (objects) {
99
+ this.splice(idx, amt, ...objects);
100
+ } else {
101
+ this.splice(idx, amt);
102
+ }
103
+ },
104
+ clear() {
105
+ this.splice(0, this.length);
106
+ return this;
107
+ },
108
+ setObjects(objects) {
109
+ (test => {
110
+ if (!test) {
111
+ throw new Error(`setObjects expects to receive an array as its argument`);
112
+ }
113
+ })(Array.isArray(objects));
114
+ this.splice(0, this.length);
115
+ this.push(...objects);
116
+ return this;
117
+ },
118
+ reverseObjects() {
119
+ this.reverse();
120
+ return this;
121
+ },
122
+ compact() {
123
+ return this.filter(v => v !== null && v !== undefined);
124
+ },
125
+ any(callback, target) {
126
+ return this.some(callback, target);
127
+ },
128
+ isAny(prop, value) {
129
+ const hasValue = arguments.length === 2;
130
+ return this.some(v => hasValue ? v[prop] === value : v[prop] === true);
131
+ },
132
+ isEvery(prop, value) {
133
+ const hasValue = arguments.length === 2;
134
+ return this.every(v => hasValue ? v[prop] === value : v[prop] === true);
135
+ },
136
+ getEach(key) {
137
+ return this.map(value => get(value, key));
138
+ },
139
+ mapBy(key) {
140
+ return this.map(value => get(value, key));
141
+ },
142
+ findBy(key, value) {
143
+ if (arguments.length === 2) {
144
+ return this.find(val => {
145
+ return get(val, key) === value;
146
+ });
147
+ } else {
148
+ return this.find(val => Boolean(get(val, key)));
149
+ }
150
+ },
151
+ filterBy(key, value) {
152
+ if (arguments.length === 2) {
153
+ return this.filter(record => {
154
+ return get(record, key) === value;
155
+ });
156
+ }
157
+ return this.filter(record => {
158
+ return Boolean(get(record, key));
159
+ });
160
+ },
161
+ sortBy(...sortKeys) {
162
+ return this.slice().sort((a, b) => {
163
+ for (let i = 0; i < sortKeys.length; i++) {
164
+ const key = sortKeys[i];
165
+ const propA = get(a, key);
166
+ const propB = get(b, key);
167
+ // return 1 or -1 else continue to the next sortKey
168
+ const compareValue = compare(propA, propB);
169
+ if (compareValue) {
170
+ return compareValue;
171
+ }
172
+ }
173
+ return 0;
174
+ });
175
+ },
176
+ invoke(key, ...args) {
177
+ return this.map(value => value[key](...args));
178
+ },
179
+ addArrayObserver() {},
180
+ removeArrayObserver() {},
181
+ arrayContentWillChange() {},
182
+ arrayContentDidChange() {},
183
+ reject(callback, target) {
184
+ (test => {
185
+ if (!test) {
186
+ throw new Error('`reject` expects a function as first argument.');
187
+ }
188
+ })(typeof callback === 'function');
189
+ return this.filter((...args) => {
190
+ return !callback.apply(target, args);
191
+ });
192
+ },
193
+ rejectBy(key, value) {
194
+ if (arguments.length === 2) {
195
+ return this.filter(record => {
196
+ return get(record, key) !== value;
197
+ });
198
+ }
199
+ return this.filter(record => {
200
+ return !get(record, key);
201
+ });
202
+ },
203
+ setEach(key, value) {
204
+ this.forEach(item => set(item, key, value));
205
+ },
206
+ uniq() {
207
+ return Array.from(new Set(this));
208
+ },
209
+ uniqBy(key) {
210
+ const seen = new Set();
211
+ const result = [];
212
+ this.forEach(item => {
213
+ const value = get(item, key);
214
+ if (seen.has(value)) {
215
+ return;
216
+ }
217
+ seen.add(value);
218
+ result.push(item);
219
+ });
220
+ return result;
221
+ },
222
+ without(value) {
223
+ const newArr = this.slice();
224
+ const index = this.indexOf(value);
225
+ if (index !== -1) {
226
+ newArr.splice(index, 1);
227
+ }
228
+ return newArr;
229
+ },
230
+ get firstObject() {
231
+ return this.at(0);
232
+ },
233
+ get lastObject() {
234
+ return this.at(-1);
235
+ }
236
+ };
237
+ const EmberArrayLikeExtension = {
238
+ kind: 'array',
239
+ name: 'ember-array-like',
240
+ features: EmberArrayLikeFeatures
241
+ };
242
+ export { EmberArrayLikeExtension, EmberObjectArrayExtension, EmberObjectExtension };