@warp-drive/legacy 5.6.0-beta.1 → 5.6.0-beta.3

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 (59) hide show
  1. package/declarations/adapter/-private/build-url-mixin.d.ts +0 -13
  2. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -7
  3. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +0 -4
  4. package/declarations/adapter/error.d.ts +2 -3
  5. package/declarations/adapter/rest.d.ts +0 -2
  6. package/declarations/adapter.d.ts +0 -5
  7. package/declarations/compat/builders/find-all.d.ts +2 -2
  8. package/declarations/compat/builders/query.d.ts +2 -2
  9. package/declarations/compat/builders/save-record.d.ts +3 -3
  10. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +24 -17
  11. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -2
  12. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +5 -5
  13. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +3 -8
  14. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +40 -18
  15. package/declarations/compat/legacy-network-handler/snapshot.d.ts +63 -44
  16. package/declarations/compat.d.ts +3 -6
  17. package/declarations/model/-private/attr.d.ts +1 -14
  18. package/declarations/model/-private/belongs-to.d.ts +0 -11
  19. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +2 -14
  20. package/declarations/model/-private/errors.d.ts +0 -6
  21. package/declarations/model/-private/has-many.d.ts +0 -4
  22. package/declarations/model/-private/hooks.d.ts +2 -2
  23. package/declarations/model/-private/legacy-relationships-support.d.ts +18 -27
  24. package/declarations/model/-private/model-for-mixin.d.ts +0 -16
  25. package/declarations/model/-private/model-methods.d.ts +3 -4
  26. package/declarations/model/-private/model.d.ts +14 -67
  27. package/declarations/model/-private/notify-changes.d.ts +2 -2
  28. package/declarations/model/-private/promise-belongs-to.d.ts +0 -6
  29. package/declarations/model/-private/promise-many-array.d.ts +0 -11
  30. package/declarations/model/-private/record-state.d.ts +2 -25
  31. package/declarations/model/-private/references/belongs-to.d.ts +6 -7
  32. package/declarations/model/-private/references/has-many.d.ts +6 -13
  33. package/declarations/model/-private/schema-provider.d.ts +6 -10
  34. package/declarations/model/-private.d.ts +2 -2
  35. package/declarations/model/migration-support.d.ts +11 -53
  36. package/declarations/model.d.ts +1 -1
  37. package/declarations/serializer/json-api.d.ts +0 -1
  38. package/declarations/serializer/json.d.ts +0 -1
  39. package/declarations/serializer/rest.d.ts +0 -1
  40. package/declarations/store/-private.d.ts +223 -0
  41. package/declarations/store.d.ts +3 -0
  42. package/dist/{-private-CKrP0ogQ.js → -private-8UmnAf9J.js} +169 -141
  43. package/dist/adapter/-private.js +1 -1
  44. package/dist/adapter/error.js +66 -0
  45. package/dist/adapter/json-api.js +1 -1
  46. package/dist/adapter/rest.js +2 -2
  47. package/dist/compat/-private.js +1 -1
  48. package/dist/compat/builders.js +4 -23
  49. package/dist/compat.js +7 -2
  50. package/dist/{errors-BX5wowuz.js → errors-8kD2mSe_.js} +66 -36
  51. package/dist/model/-private.js +1 -2
  52. package/dist/model/migration-support.js +96 -11
  53. package/dist/model.js +14 -11
  54. package/dist/{schema-provider-BdQhkT-Q.js → schema-provider-DQu4Rjco.js} +165 -60
  55. package/dist/{serialize-into-hash-Bp58npke.js → serialize-into-hash-CS0MIv4F.js} +2 -1
  56. package/dist/store.js +633 -0
  57. package/dist/util-Dul6TZts.js +35 -0
  58. package/dist/utils-Cqw9eRj5.js +23 -0
  59. package/package.json +15 -15
@@ -2,45 +2,15 @@ import { getOwner } from '@ember/application';
2
2
  import { deprecate } from '@ember/debug';
3
3
  import EmberObject from '@ember/object';
4
4
  import { recordIdentifierFor, storeFor } from '@warp-drive/core';
5
- import { peekCache, notifyInternalSignal, peekInternalSignal, withSignalStore, ARRAY_SIGNAL, recordIdentifierFor as recordIdentifierFor$1, gate, memoized, defineSignal, coerceId, entangleSignal } from '@warp-drive/core/store/-private';
5
+ import { assertPrivateStore, notifyInternalSignal, peekInternalSignal, withSignalStore, recordIdentifierFor as recordIdentifierFor$1, gate, memoized, defineSignal, coerceId, entangleSignal, defineGate } from '@warp-drive/core/store/-private';
6
6
  import { RecordStore } from '@warp-drive/core/types/symbols';
7
- import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-BX5wowuz.js";
8
- import { u as upgradeStore, F as FetchManager } from "./-private-CKrP0ogQ.js";
7
+ import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-8kD2mSe_.js";
8
+ import { u as upgradeStore, F as FetchManager } from "./-private-8UmnAf9J.js";
9
9
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
10
10
  import { cacheFor } from '@ember/object/internals';
11
+ import { Context } from '@warp-drive/core/reactive/-private';
11
12
  import { d as decorateMethodV2 } from "./runtime-BPCpkOf1-BKOwiRJp.js";
12
- import { dasherize } from '@warp-drive/utilities/string';
13
- function isElementDescriptor(args) {
14
- const [maybeTarget, maybeKey, maybeDesc] = args;
15
- return (
16
- // Ensure we have the right number of args
17
- args.length === 3 && (
18
- // Make sure the target is a class or object (prototype)
19
- typeof maybeTarget === 'function' || typeof maybeTarget === 'object' && maybeTarget !== null) &&
20
- // Make sure the key is a string
21
- typeof maybeKey === 'string' && (
22
- // Make sure the descriptor is the right shape
23
- typeof maybeDesc === 'object' && maybeDesc !== null && 'enumerable' in maybeDesc && 'configurable' in maybeDesc ||
24
- // TS compatibility
25
- maybeDesc === undefined)
26
- );
27
- }
28
- function normalizeModelName(type) {
29
- if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_TYPES)) {
30
- const result = dasherize(type);
31
- deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, result === type, {
32
- id: 'ember-data:deprecate-non-strict-types',
33
- until: '6.0',
34
- for: 'ember-data',
35
- since: {
36
- available: '4.13',
37
- enabled: '5.3'
38
- }
39
- });
40
- return result;
41
- }
42
- return type;
43
- }
13
+ import { n as normalizeModelName } from "./util-Dul6TZts.js";
44
14
  function rollbackAttributes() {
45
15
  const {
46
16
  currentState
@@ -48,8 +18,10 @@ function rollbackAttributes() {
48
18
  const {
49
19
  isNew
50
20
  } = currentState;
51
- this[RecordStore]._join(() => {
52
- peekCache(this).rollbackAttrs(recordIdentifierFor(this));
21
+ const store = this[RecordStore];
22
+ assertPrivateStore(store);
23
+ store._join(() => {
24
+ store.cache.rollbackAttrs(recordIdentifierFor(this));
53
25
  this.errors.clear();
54
26
  currentState.cleanErrorRequests();
55
27
  if (isNew) {
@@ -70,6 +42,27 @@ function hasMany(prop) {
70
42
  return lookupLegacySupport(this).referenceFor('hasMany', prop);
71
43
  }
72
44
  function reload(options = {}) {
45
+ if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) {
46
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
47
+ {
48
+ throw new Error(`You cannot use reload() on a record when ENABLE_LEGACY_REQUEST_METHODS is false.`);
49
+ }
50
+ })() : {};
51
+ } else {
52
+ deprecate(`record.reload is deprecated, please use store.request to initiate a request instead.`, false, {
53
+ id: 'warp-drive:deprecate-legacy-request-methods',
54
+ until: '6.0',
55
+ for: '@warp-drive/core',
56
+ url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',
57
+ since: {
58
+ enabled: '5.7',
59
+ available: '5.7'
60
+ }
61
+ });
62
+ return _reload.call(this, options);
63
+ }
64
+ }
65
+ function _reload(options = {}) {
73
66
  options.isReloading = true;
74
67
  options.reload = true;
75
68
  const identifier = recordIdentifierFor(this);
@@ -94,7 +87,7 @@ function reload(options = {}) {
94
87
  return promise;
95
88
  }
96
89
  function changedAttributes() {
97
- return peekCache(this).changedAttrs(recordIdentifierFor(this));
90
+ return this[RecordStore].cache.changedAttrs(recordIdentifierFor(this));
98
91
  }
99
92
  function serialize(options) {
100
93
  upgradeStore(this[RecordStore]);
@@ -107,6 +100,27 @@ function deleteRecord() {
107
100
  }
108
101
  }
109
102
  function save(options) {
103
+ if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) {
104
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
105
+ {
106
+ throw new Error(`You cannot use save() on a record when ENABLE_LEGACY_REQUEST_METHODS is false.`);
107
+ }
108
+ })() : {};
109
+ } else {
110
+ deprecate(`record.save is deprecated, please use store.request to initiate a request instead.`, false, {
111
+ id: 'warp-drive:deprecate-legacy-request-methods',
112
+ until: '6.0',
113
+ for: '@warp-drive/core',
114
+ url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',
115
+ since: {
116
+ enabled: '5.7',
117
+ available: '5.7'
118
+ }
119
+ });
120
+ return _save.call(this, options);
121
+ }
122
+ }
123
+ function _save(options) {
110
124
  let promise;
111
125
  if (this.currentState.isNew && this.currentState.isDeleted) {
112
126
  promise = Promise.resolve(this);
@@ -117,6 +131,27 @@ function save(options) {
117
131
  return promise;
118
132
  }
119
133
  function destroyRecord(options) {
134
+ if (macroCondition(!getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_REQUEST_METHODS)) {
135
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
136
+ {
137
+ throw new Error(`You cannot use destroyRecord() on a record when ENABLE_LEGACY_REQUEST_METHODS is false.`);
138
+ }
139
+ })() : {};
140
+ } else {
141
+ deprecate(`record.destroyRecord is deprecated, please use store.request to initiate a request instead.`, false, {
142
+ id: 'warp-drive:deprecate-legacy-request-methods',
143
+ until: '6.0',
144
+ for: '@warp-drive/core',
145
+ url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',
146
+ since: {
147
+ enabled: '5.7',
148
+ available: '5.7'
149
+ }
150
+ });
151
+ return _destroyRecord.call(this, options);
152
+ }
153
+ }
154
+ function _destroyRecord(options) {
120
155
  const {
121
156
  isNew
122
157
  } = this.currentState;
@@ -183,7 +218,7 @@ function notifyRelationship(identifier, key, record, meta) {
183
218
  return;
184
219
  }
185
220
  if (manyArray) {
186
- notifyInternalSignal(manyArray[ARRAY_SIGNAL]);
221
+ notifyInternalSignal(manyArray[Context].signal);
187
222
 
188
223
  //We need to notifyPropertyChange in the adding case because we need to make sure
189
224
  //we fetch the newly added record in case it is unloaded
@@ -255,11 +290,34 @@ root
255
290
  invalid
256
291
  inFlight
257
292
 
258
- @internal
293
+ @hideconstructor
294
+ @private
259
295
  */
260
296
  class RecordState {
297
+ /** @internal */
298
+
299
+ /** @internal */
300
+
301
+ /** @internal */
302
+
303
+ /** @internal */
304
+
305
+ /** @internal */
306
+
307
+ /** @internal */
308
+
309
+ /** @internal */
310
+
311
+ /** @internal */
312
+
313
+ /** @internal */
314
+
315
+ /** @internal */
316
+
317
+ /** @internal */
318
+
261
319
  constructor(record) {
262
- const store = storeFor(record);
320
+ const store = storeFor(record, false);
263
321
  const identity = recordIdentifierFor$1(record);
264
322
  this.identifier = identity;
265
323
  this.record = record;
@@ -350,7 +408,7 @@ class RecordState {
350
408
 
351
409
  /** @internal */
352
410
  destroy() {
353
- storeFor(this.record).notifications.unsubscribe(this.handler);
411
+ storeFor(this.record, false).notifications.unsubscribe(this.handler);
354
412
  }
355
413
 
356
414
  /** @internal */
@@ -687,7 +745,7 @@ class Model extends EmberObject {
687
745
  super.init(options);
688
746
  this[RecordStore] = store;
689
747
  const identity = _secretInit.identifier;
690
- _secretInit.cb(this, _secretInit.cache, identity, _secretInit.store);
748
+ _secretInit.cb(this, identity, _secretInit.store);
691
749
  this.___recordState = macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? new RecordState(this) : null;
692
750
  this.setProperties(createProps);
693
751
  const notifications = store.notifications;
@@ -696,16 +754,18 @@ class Model extends EmberObject {
696
754
  });
697
755
  }
698
756
 
699
- /** @internal */
757
+ /** @private */
700
758
  // @ts-expect-error destroy should not return a value, but ember's types force it to
701
759
  destroy() {
702
760
  const identifier = recordIdentifierFor(this);
703
761
  this.___recordState?.destroy();
704
- const store = storeFor(this);
762
+ const store = storeFor(this, false);
705
763
  store.notifications.unsubscribe(this.___private_notifications);
706
- LEGACY_SUPPORT.get(this)?.destroy();
707
- LEGACY_SUPPORT.delete(this);
708
- LEGACY_SUPPORT.delete(identifier);
764
+ const support = LEGACY_SUPPORT.get(identifier);
765
+ if (support) {
766
+ support.destroy();
767
+ LEGACY_SUPPORT.delete(identifier);
768
+ }
709
769
  super.destroy();
710
770
  }
711
771
 
@@ -995,6 +1055,7 @@ class Model extends EmberObject {
995
1055
  const normalizedId = coerceId(id);
996
1056
  const identifier = recordIdentifierFor(this);
997
1057
  const didChange = normalizedId !== identifier.id;
1058
+ assertPrivateStore(this.store);
998
1059
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
999
1060
  if (!test) {
1000
1061
  throw new Error(`Cannot set ${identifier.type} record's id to ${id}, because id is already ${identifier.id}`);
@@ -1002,7 +1063,7 @@ class Model extends EmberObject {
1002
1063
  })(!didChange || identifier.id === null) : {};
1003
1064
  if (normalizedId !== null && didChange) {
1004
1065
  this.store._instanceCache.setRecordId(identifier, normalizedId);
1005
- this.store.notifications.notify(identifier, 'identity');
1066
+ this.store.notifications.notify(identifier, 'identity', null);
1006
1067
  }
1007
1068
  }
1008
1069
  toString() {
@@ -1170,8 +1231,8 @@ class Model extends EmberObject {
1170
1231
  }
1171
1232
  ```
1172
1233
  @public
1173
- @param {Function} callback the callback to invoke
1174
- @param {any} binding the value to which the callback's `this` should be bound
1234
+ @param callback the callback to invoke
1235
+ @param binding the value to which the callback's `this` should be bound
1175
1236
  */
1176
1237
  eachRelationship(callback, binding) {
1177
1238
  this.constructor.eachRelationship(callback, binding);
@@ -1180,7 +1241,7 @@ class Model extends EmberObject {
1180
1241
  return this.constructor.relationshipsByName.get(name);
1181
1242
  }
1182
1243
  inverseFor(name) {
1183
- return this.constructor.inverseFor(name, storeFor(this));
1244
+ return this.constructor.inverseFor(name, storeFor(this, false));
1184
1245
  }
1185
1246
  eachAttribute(callback, binding) {
1186
1247
  this.constructor.eachAttribute(callback, binding);
@@ -1242,9 +1303,9 @@ class Model extends EmberObject {
1242
1303
  ```
1243
1304
  Calling `store.modelFor('post').typeForRelationship('comments', store)` will return `Comment`.
1244
1305
  @public
1245
- @param {String} name the name of the relationship
1246
- @param {store} store an instance of Store
1247
- @return {Model} the type of the relationship, or undefined
1306
+ @param name the name of the relationship
1307
+ @param store an instance of Store
1308
+ @return the type of the relationship, or undefined
1248
1309
  */
1249
1310
  static typeForRelationship(name, store) {
1250
1311
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
@@ -1284,9 +1345,9 @@ class Model extends EmberObject {
1284
1345
  store.modelFor('message').inverseFor('owner', store) // { type: 'post', name: 'comments', kind: 'hasMany' }
1285
1346
  ```
1286
1347
  @public
1287
- @param {String} name the name of the relationship
1288
- @param {Store} store
1289
- @return {Object} the inverse relationship, or null
1348
+ @param name the name of the relationship
1349
+ @param store
1350
+ @return the inverse relationship, or null
1290
1351
  */
1291
1352
  static {
1292
1353
  decorateMethodV2(this, "inverseMap", [computeOnce]);
@@ -1917,7 +1978,44 @@ Model.prototype.deleteRecord = deleteRecord;
1917
1978
  Model.prototype.changedAttributes = changedAttributes;
1918
1979
  Model.prototype.rollbackAttributes = rollbackAttributes;
1919
1980
  Model.prototype.reload = reload;
1920
- defineSignal(Model.prototype, 'isReloading', false);
1981
+ defineGate(Model.prototype, 'isReloading', {
1982
+ get() {
1983
+ deprecate(`record.isReloading is deprecated, please use store.request and either <Request> or getRequuestState to keep track of the request state instead.`, false, {
1984
+ id: 'warp-drive:deprecate-legacy-request-methods',
1985
+ until: '6.0',
1986
+ for: '@warp-drive/core',
1987
+ url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',
1988
+ since: {
1989
+ enabled: '5.7',
1990
+ available: '5.7'
1991
+ }
1992
+ });
1993
+ return this._isReloading ?? false;
1994
+ },
1995
+ set(v) {
1996
+ this._isReloading = v;
1997
+ },
1998
+ configurable: true,
1999
+ // @ts-expect-error specially handled prop
2000
+ isLocal: true
2001
+ });
2002
+ function restoreDeprecatedModelRequestBehaviors(ModelKlass) {
2003
+ // @ts-expect-error TS doesn't know how to do `this` function overloads
2004
+ ModelKlass.prototype.save = _save;
2005
+ // @ts-expect-error TS doesn't know how to do `this` function overloads
2006
+ ModelKlass.prototype.destroyRecord = _destroyRecord;
2007
+ ModelKlass.prototype.reload = _reload;
2008
+ defineGate(Model.prototype, 'isReloading', {
2009
+ get() {
2010
+ return this._isReloading ?? false;
2011
+ },
2012
+ set(v) {
2013
+ this._isReloading = v;
2014
+ },
2015
+ // @ts-expect-error specially handled prop
2016
+ isLocal: true
2017
+ });
2018
+ }
1921
2019
 
1922
2020
  // this is required to prevent `init` from passing
1923
2021
  // the values initialized during create to `setUnknownProperty`
@@ -1999,6 +2097,12 @@ function modelForMixin(store, normalizedModelName) {
1999
2097
  return owner.factoryFor(`model:${normalizedModelName}`);
2000
2098
  }
2001
2099
  class ModelSchemaProvider {
2100
+ /** @internal */
2101
+
2102
+ /** @internal */
2103
+
2104
+ /** @internal */
2105
+
2002
2106
  constructor(store) {
2003
2107
  this.store = store;
2004
2108
  this._schemas = new Map();
@@ -2086,6 +2190,7 @@ class ModelSchemaProvider {
2086
2190
  }
2087
2191
  })() : {};
2088
2192
  }
2193
+ /** @internal */
2089
2194
  _loadModelSchema(type) {
2090
2195
  const modelClass = this.store.modelFor(type);
2091
2196
  const attributeMap = modelClass.attributes;
@@ -2232,4 +2337,4 @@ function getModelFactory(store, type) {
2232
2337
  }
2233
2338
  return factory;
2234
2339
  }
2235
- export { Model as M, RecordState as R, save as a, buildSchema as b, reload as c, destroyRecord as d, deleteRecord as e, changedAttributes as f, belongsTo as g, hasMany as h, createSnapshot as i, isElementDescriptor as j, getModelFactory as k, normalizeModelName as n, rollbackAttributes as r, serialize as s, unloadRecord as u };
2340
+ export { Model as M, RecordState as R, _save as _, save as a, buildSchema as b, _reload as c, reload as d, _destroyRecord as e, destroyRecord as f, deleteRecord as g, hasMany as h, changedAttributes as i, belongsTo as j, createSnapshot as k, getModelFactory as l, restoreDeprecatedModelRequestBehaviors as m, rollbackAttributes as r, serialize as s, unloadRecord as u };
@@ -1,7 +1,8 @@
1
1
  import { warn } from '@ember/debug';
2
2
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
3
+ import '@warp-drive/core/reactive/-private';
4
+ import "./-private-8UmnAf9J.js";
3
5
  import '@warp-drive/core/store/-private';
4
- import "./-private-CKrP0ogQ.js";
5
6
  const newline = /\r?\n/;
6
7
  function parseResponseHeaders(headersString) {
7
8
  const headers = Object.create(null);