@ember-data/legacy-compat 5.6.0-alpha.5 → 5.6.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 (50) hide show
  1. package/addon-main.cjs +1 -1
  2. package/dist/-private.js +1 -1
  3. package/dist/builders.js +1 -292
  4. package/dist/index.js +1 -1002
  5. package/dist/utils.js +1 -224
  6. package/package.json +7 -30
  7. package/unstable-preview-types/-private.d.ts +7 -13
  8. package/unstable-preview-types/builders.d.ts +9 -12
  9. package/unstable-preview-types/index.d.ts +2 -149
  10. package/unstable-preview-types/utils.d.ts +9 -138
  11. package/dist/-private-CVvkihLY.js +0 -1188
  12. package/dist/-private-CVvkihLY.js.map +0 -1
  13. package/dist/-private.js.map +0 -1
  14. package/dist/builders.js.map +0 -1
  15. package/dist/index.js.map +0 -1
  16. package/dist/utils.js.map +0 -1
  17. package/unstable-preview-types/-private.d.ts.map +0 -1
  18. package/unstable-preview-types/builders/find-all.d.ts +0 -35
  19. package/unstable-preview-types/builders/find-all.d.ts.map +0 -1
  20. package/unstable-preview-types/builders/find-record.d.ts +0 -56
  21. package/unstable-preview-types/builders/find-record.d.ts.map +0 -1
  22. package/unstable-preview-types/builders/query.d.ts +0 -63
  23. package/unstable-preview-types/builders/query.d.ts.map +0 -1
  24. package/unstable-preview-types/builders/save-record.d.ts +0 -34
  25. package/unstable-preview-types/builders/save-record.d.ts.map +0 -1
  26. package/unstable-preview-types/builders/utils.d.ts +0 -6
  27. package/unstable-preview-types/builders/utils.d.ts.map +0 -1
  28. package/unstable-preview-types/builders.d.ts.map +0 -1
  29. package/unstable-preview-types/index.d.ts.map +0 -1
  30. package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts +0 -49
  31. package/unstable-preview-types/legacy-network-handler/fetch-manager.d.ts.map +0 -1
  32. package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts +0 -5
  33. package/unstable-preview-types/legacy-network-handler/identifier-has-id.d.ts.map +0 -1
  34. package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts +0 -14
  35. package/unstable-preview-types/legacy-network-handler/legacy-data-fetch.d.ts.map +0 -1
  36. package/unstable-preview-types/legacy-network-handler/legacy-data-utils.d.ts +0 -8
  37. package/unstable-preview-types/legacy-network-handler/legacy-data-utils.d.ts.map +0 -1
  38. package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts +0 -5
  39. package/unstable-preview-types/legacy-network-handler/legacy-network-handler.d.ts.map +0 -1
  40. package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts +0 -529
  41. package/unstable-preview-types/legacy-network-handler/minimum-adapter-interface.d.ts.map +0 -1
  42. package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts +0 -226
  43. package/unstable-preview-types/legacy-network-handler/minimum-serializer-interface.d.ts.map +0 -1
  44. package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts +0 -9
  45. package/unstable-preview-types/legacy-network-handler/serializer-response.d.ts.map +0 -1
  46. package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts +0 -91
  47. package/unstable-preview-types/legacy-network-handler/snapshot-record-array.d.ts.map +0 -1
  48. package/unstable-preview-types/legacy-network-handler/snapshot.d.ts +0 -239
  49. package/unstable-preview-types/legacy-network-handler/snapshot.d.ts.map +0 -1
  50. package/unstable-preview-types/utils.d.ts.map +0 -1
package/addon-main.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const { addonShim } = require('@warp-drive/build-config/addon-shim.cjs');
3
+ const { addonShim } = require('@warp-drive/core/addon-shim.cjs');
4
4
 
5
5
  module.exports = addonShim(__dirname);
package/dist/-private.js CHANGED
@@ -1 +1 @@
1
- export { F as FetchManager, S as SaveOp, c as Snapshot, b as SnapshotRecordArray, u as upgradeStore } from "./-private-CVvkihLY.js";
1
+ export * from '@warp-drive/legacy/compat/-private';
package/dist/builders.js CHANGED
@@ -1,292 +1 @@
1
- import { SkipCache } from '@warp-drive/core-types/request';
2
- import { deprecate } from '@ember/debug';
3
- import { dasherize } from '@ember-data/request-utils/string';
4
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
5
- import { ensureStringId, constructResource } from '@ember-data/store/-private';
6
- import { storeFor, recordIdentifierFor } from '@ember-data/store';
7
- function isMaybeIdentifier(maybeIdentifier) {
8
- return Boolean(maybeIdentifier !== null && typeof maybeIdentifier === 'object' && ('id' in maybeIdentifier && 'type' in maybeIdentifier && maybeIdentifier.id && maybeIdentifier.type || maybeIdentifier.lid));
9
- }
10
- function normalizeModelName(type) {
11
- if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_TYPES)) {
12
- const result = dasherize(type);
13
- deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, result === type, {
14
- id: 'ember-data:deprecate-non-strict-types',
15
- until: '6.0',
16
- for: 'ember-data',
17
- since: {
18
- available: '4.13',
19
- enabled: '5.3'
20
- }
21
- });
22
- return result;
23
- }
24
- return type;
25
- }
26
-
27
- /**
28
- This function builds a request config to perform a `findAll` request for the given type.
29
- When passed to `store.request`, this config will result in the same behavior as a `store.findAll` request.
30
- Additionally, it takes the same options as `store.findAll`.
31
-
32
- 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.
33
- 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.
34
- To that end, these builders are deprecated and will be removed in a future version of Ember Data.
35
-
36
- @deprecated
37
- @public
38
- @param {String} type the name of the resource
39
- @param {Object} query a query to be used by the adapter
40
- @param {FindAllBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.findAll
41
- @return {FindAllRequestInput} request config
42
- */
43
- function findAllBuilder(type, options = {}) {
44
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
45
- if (!test) {
46
- throw new Error(`You need to pass a model name to the findAll builder`);
47
- }
48
- })(type) : {};
49
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
50
- if (!test) {
51
- throw new Error(`Model name passed to the findAll builder must be a dasherized string instead of ${type}`);
52
- }
53
- })(typeof type === 'string') : {};
54
- return {
55
- op: 'findAll',
56
- data: {
57
- type: normalizeModelName(type),
58
- options: options || {}
59
- },
60
- cacheOptions: {
61
- [SkipCache]: true
62
- }
63
- };
64
- }
65
-
66
- /**
67
- This function builds a request config to find the record for a given identifier or type and id combination.
68
- When passed to `store.request`, this config will result in the same behavior as a `store.findRecord` request.
69
- Additionally, it takes the same options as `store.findRecord`, with the exception of `preload` (which is unsupported).
70
-
71
- **Example 1**
72
-
73
- ```ts
74
- import { findRecord } from '@ember-data/legacy-compat/builders';
75
- const { content: post } = await store.request<Post>(findRecord<Post>('post', '1'));
76
- ```
77
-
78
- **Example 2**
79
-
80
- `findRecord` can be called with a single identifier argument instead of the combination
81
- of `type` (modelName) and `id` as separate arguments. You may recognize this combo as
82
- the typical pairing from [JSON:API](https://jsonapi.org/format/#document-resource-object-identification)
83
-
84
- ```ts
85
- import { findRecord } from '@ember-data/legacy-compat/builders';
86
- const { content: post } = await store.request<Post>(findRecord<Post>({ type: 'post', id }));
87
- ```
88
-
89
- 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.
90
- 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.
91
- To that end, these builders are deprecated and will be removed in a future version of Ember Data.
92
-
93
- @deprecated
94
- @public
95
- @param {string|object} 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
96
- @param {string|number|object} 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
97
- @param {FindRecordBuilderOptions} [options] - if the first param is a string this will be the optional options for the request. See examples for available options.
98
- @return {FindRecordRequestInput} request config
99
- */
100
- function findRecordBuilder(resource, idOrOptions, options) {
101
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
102
- if (!test) {
103
- throw new Error(`You need to pass a modelName or resource identifier as the first argument to the findRecord builder`);
104
- }
105
- })(resource) : {};
106
- if (isMaybeIdentifier(resource)) {
107
- options = idOrOptions;
108
- } else {
109
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
110
- if (!test) {
111
- throw new Error(`You need to pass a modelName or resource identifier as the first argument to the findRecord builder (passed ${resource})`);
112
- }
113
- })(typeof resource === 'string') : {};
114
- const type = normalizeModelName(resource);
115
- const normalizedId = ensureStringId(idOrOptions);
116
- resource = constructResource(type, normalizedId);
117
- }
118
- options = options || {};
119
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
120
- if (!test) {
121
- throw new Error('findRecord builder does not support options.preload');
122
- }
123
- })(!options.preload) : {};
124
- return {
125
- op: 'findRecord',
126
- data: {
127
- record: resource,
128
- options
129
- },
130
- cacheOptions: {
131
- [SkipCache]: true
132
- }
133
- };
134
- }
135
-
136
- /**
137
- This function builds a request config for a given type and query object.
138
- When passed to `store.request`, this config will result in the same behavior as a `store.query` request.
139
- Additionally, it takes the same options as `store.query`.
140
-
141
- 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.
142
- 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.
143
- To that end, these builders are deprecated and will be removed in a future version of Ember Data.
144
-
145
- @deprecated
146
- @public
147
- @param {String} type the name of the resource
148
- @param {Object} query a query to be used by the adapter
149
- @param {QueryBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.query
150
- @return {QueryRequestInput} request config
151
- */
152
- function queryBuilder(type, query, options = {}) {
153
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
154
- if (!test) {
155
- throw new Error(`You need to pass a model name to the query builder`);
156
- }
157
- })(type) : {};
158
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
159
- if (!test) {
160
- throw new Error(`You need to pass a query hash to the query builder`);
161
- }
162
- })(query) : {};
163
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
164
- if (!test) {
165
- throw new Error(`Model name passed to the query builder must be a dasherized string instead of ${type}`);
166
- }
167
- })(typeof type === 'string') : {};
168
- return {
169
- op: 'query',
170
- data: {
171
- type: normalizeModelName(type),
172
- query,
173
- options: options
174
- },
175
- cacheOptions: {
176
- [SkipCache]: true
177
- }
178
- };
179
- }
180
-
181
- /**
182
- This function builds a request config for a given type and query object.
183
- When passed to `store.request`, this config will result in the same behavior as a `store.queryRecord` request.
184
- Additionally, it takes the same options as `store.queryRecord`.
185
-
186
- 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.
187
- 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.
188
- To that end, these builders are deprecated and will be removed in a future version of Ember Data.
189
-
190
- @deprecated
191
- @public
192
- @param {String} type the name of the resource
193
- @param {Object} query a query to be used by the adapter
194
- @param {QueryBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.query
195
- @return {QueryRecordRequestInput} request config
196
- */
197
-
198
- function queryRecordBuilder(type, query, options) {
199
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
200
- if (!test) {
201
- throw new Error(`You need to pass a model name to the queryRecord builder`);
202
- }
203
- })(type) : {};
204
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
205
- if (!test) {
206
- throw new Error(`You need to pass a query hash to the queryRecord builder`);
207
- }
208
- })(query) : {};
209
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
210
- if (!test) {
211
- throw new Error(`Model name passed to the queryRecord builder must be a dasherized string instead of ${type}`);
212
- }
213
- })(typeof type === 'string') : {};
214
- return {
215
- op: 'queryRecord',
216
- data: {
217
- type: normalizeModelName(type),
218
- query,
219
- options: options || {}
220
- },
221
- cacheOptions: {
222
- [SkipCache]: true
223
- }
224
- };
225
- }
226
- function _resourceIsFullDeleted(identifier, cache) {
227
- return cache.isDeletionCommitted(identifier) || cache.isNew(identifier) && cache.isDeleted(identifier);
228
- }
229
- function resourceIsFullyDeleted(instanceCache, identifier) {
230
- const cache = instanceCache.cache;
231
- return !cache || _resourceIsFullDeleted(identifier, cache);
232
- }
233
-
234
- /**
235
- This function builds a request config for saving the given record (e.g. creating, updating, or deleting the record).
236
- When passed to `store.request`, this config will result in the same behavior as a legacy `store.saveRecord` request.
237
- Additionally, it takes the same options as `store.saveRecord`.
238
-
239
- 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.
240
- 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.
241
- To that end, these builders are deprecated and will be removed in a future version of Ember Data.
242
-
243
- @deprecated
244
- @public
245
- @param {Object} record a record to save
246
- @param {SaveRecordBuilderOptions} options optional, may include `adapterOptions` hash which will be passed to adapter.saveRecord
247
- @return {SaveRecordRequestInput} request config
248
- */
249
- function saveRecordBuilder(record, options = {}) {
250
- const store = storeFor(record);
251
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
252
- if (!test) {
253
- throw new Error(`Unable to initiate save for a record in a disconnected state`);
254
- }
255
- })(store) : {};
256
- const identifier = recordIdentifierFor(record);
257
- if (!identifier) {
258
- // this commonly means we're disconnected
259
- // but just in case we throw here to prevent bad things.
260
- throw new Error(`Record Is Disconnected`);
261
- }
262
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
263
- if (!test) {
264
- throw new Error(`Cannot initiate a save request for an unloaded record: ${identifier.lid}`);
265
- }
266
- })(store._instanceCache.recordIsLoaded(identifier)) : {};
267
- if (resourceIsFullyDeleted(store._instanceCache, identifier)) {
268
- throw new Error('cannot build saveRecord request for deleted record');
269
- }
270
- if (!options) {
271
- options = {};
272
- }
273
- let operation = 'updateRecord';
274
- const cache = store.cache;
275
- if (cache.isNew(identifier)) {
276
- operation = 'createRecord';
277
- } else if (cache.isDeleted(identifier)) {
278
- operation = 'deleteRecord';
279
- }
280
- return {
281
- op: operation,
282
- data: {
283
- options,
284
- record: identifier
285
- },
286
- records: [identifier],
287
- cacheOptions: {
288
- [SkipCache]: true
289
- }
290
- };
291
- }
292
- export { findAllBuilder as findAll, findRecordBuilder as findRecord, queryBuilder as query, queryRecordBuilder as queryRecord, saveRecordBuilder as saveRecord };
1
+ export * from '@warp-drive/legacy/compat/builders';