@ember-data/store 4.6.1 → 4.7.0

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 (45) hide show
  1. package/addon/-debug/index.js +35 -13
  2. package/addon/-private/{identifier-cache.ts → caches/identifier-cache.ts} +148 -73
  3. package/addon/-private/caches/instance-cache.ts +690 -0
  4. package/addon/-private/{record-data-for.ts → caches/record-data-for.ts} +2 -7
  5. package/addon/-private/index.ts +44 -24
  6. package/addon/-private/{model → legacy-model-support}/record-reference.ts +15 -13
  7. package/addon/-private/{schema-definition-service.ts → legacy-model-support/schema-definition-service.ts} +13 -9
  8. package/addon/-private/{model → legacy-model-support}/shim-model-class.ts +18 -11
  9. package/addon/-private/managers/record-array-manager.ts +377 -0
  10. package/addon/-private/managers/record-data-manager.ts +845 -0
  11. package/addon/-private/managers/record-data-store-wrapper.ts +421 -0
  12. package/addon/-private/managers/record-notification-manager.ts +109 -0
  13. package/addon/-private/network/fetch-manager.ts +567 -0
  14. package/addon/-private/{finders.js → network/finders.js} +14 -17
  15. package/addon/-private/{request-cache.ts → network/request-cache.ts} +21 -18
  16. package/addon/-private/{snapshot-record-array.ts → network/snapshot-record-array.ts} +14 -31
  17. package/addon/-private/{snapshot.ts → network/snapshot.ts} +40 -49
  18. package/addon/-private/{promise-proxies.ts → proxies/promise-proxies.ts} +76 -15
  19. package/addon/-private/{promise-proxy-base.js → proxies/promise-proxy-base.js} +0 -0
  20. package/addon/-private/record-arrays/identifier-array.ts +924 -0
  21. package/addon/-private/{core-store.ts → store-service.ts} +574 -215
  22. package/addon/-private/{coerce-id.ts → utils/coerce-id.ts} +1 -1
  23. package/addon/-private/{common.js → utils/common.js} +1 -2
  24. package/addon/-private/utils/construct-resource.ts +2 -2
  25. package/addon/-private/{identifer-debug-consts.ts → utils/identifer-debug-consts.ts} +0 -0
  26. package/addon/-private/utils/is-non-empty-string.ts +1 -1
  27. package/addon/-private/{normalize-model-name.ts → utils/normalize-model-name.ts} +1 -3
  28. package/addon/-private/utils/promise-record.ts +5 -6
  29. package/addon/-private/{serializer-response.ts → utils/serializer-response.ts} +2 -2
  30. package/addon/-private/utils/uuid-polyfill.ts +73 -0
  31. package/package.json +12 -8
  32. package/addon/-private/backburner.js +0 -25
  33. package/addon/-private/errors-utils.js +0 -146
  34. package/addon/-private/fetch-manager.ts +0 -597
  35. package/addon/-private/identity-map.ts +0 -54
  36. package/addon/-private/instance-cache.ts +0 -387
  37. package/addon/-private/internal-model-factory.ts +0 -359
  38. package/addon/-private/internal-model-map.ts +0 -121
  39. package/addon/-private/model/internal-model.ts +0 -602
  40. package/addon/-private/record-array-manager.ts +0 -444
  41. package/addon/-private/record-arrays/adapter-populated-record-array.ts +0 -130
  42. package/addon/-private/record-arrays/record-array.ts +0 -318
  43. package/addon/-private/record-data-store-wrapper.ts +0 -243
  44. package/addon/-private/record-notification-manager.ts +0 -73
  45. package/addon/-private/weak-cache.ts +0 -125
@@ -1,125 +0,0 @@
1
- import { DEBUG } from '@glimmer/env';
2
-
3
- import { DEBUG_IDENTIFIER_BUCKET } from './identifer-debug-consts';
4
-
5
- /*
6
- DEBUG only fields. Keeping this in a separate interface
7
- which Typescript then merges with the class definition allow us to
8
- have a DEBUG only property without paying the cost of that field being
9
- present and initialized (usually to void 0) in production.
10
- */
11
- interface WeakCache<K extends object, V> extends WeakMap<K, V> {
12
- _symbol: Symbol;
13
- _fieldName: string;
14
- _expectMsg?: (key: K) => string;
15
- /*
16
- The default Typescript Signature for WeakMap expects obj: K and
17
- returns a boolean. This behavior isn't useful in our common case
18
- where we want to use `has` to narrow by determining whether a
19
- particular object is a key.
20
-
21
- For instance, we use WeakMap key check to determine in some cases
22
- whether an object given to us by a user is a RecordIdentifier or
23
- a Record.
24
- */
25
- has(obj: unknown): obj is K;
26
-
27
- /*
28
- This is an exception to the interface being used for
29
- DEBUG ony fields. In this case, only a few WeakCache's
30
- will utilize the lookup behavior, so paying the cost in
31
- the constructor signature / field initialization seemed
32
- off.
33
- */
34
- _generator?: (key: K) => V;
35
- }
36
-
37
- /**
38
- * @class WeakCache
39
- * @extends WeakMap
40
- * @internal
41
- */
42
- class WeakCache<K extends object, V> extends WeakMap<K, V> {
43
- constructor(_fieldName: string) {
44
- super();
45
- if (DEBUG) {
46
- this._fieldName = _fieldName;
47
- this._symbol = Symbol.for(_fieldName);
48
- }
49
- }
50
-
51
- /**
52
- * Retrieve the value for a key from the WeakCache with the expectation
53
- * that the key exists. Throws the error generated by _expectMsg in DEBUG if
54
- * that key does not exist.
55
- *
56
- * @method getWithError
57
- * @param obj
58
- * @internal
59
- */
60
- getWithError(obj: K): V {
61
- let v = this.get(obj);
62
-
63
- if (DEBUG && v === undefined) {
64
- throw new Error(this._expectMsg!(obj));
65
- }
66
-
67
- return v as V;
68
- }
69
-
70
- /**
71
- * Retrieve the value for a key from the WeakCache, or generate one
72
- * using the configured _generator method if no value is yet present.
73
- *
74
- * @method lookup
75
- * @param obj
76
- * @internal
77
- */
78
- lookup(obj: K): V {
79
- let v = super.get(obj);
80
-
81
- if (v === undefined) {
82
- v = this._generator!(obj);
83
- super.set(obj, v);
84
-
85
- if (DEBUG) {
86
- if (obj[DEBUG_IDENTIFIER_BUCKET] && this._fieldName !== 'identifier-proxy-target') {
87
- const target: K = obj[Symbol.for('identifier-proxy-target') as unknown as string] as K;
88
- target[this._symbol as unknown as string] = v;
89
- } else {
90
- obj[this._symbol as unknown as string] = v;
91
- }
92
- }
93
- }
94
-
95
- return v;
96
- }
97
- }
98
-
99
- class DebugWeakCache<K extends object, V> extends WeakCache<K, V> {
100
- set(obj: K, value: V): this {
101
- if (DEBUG && super.has(obj) && this.get(obj) !== value) {
102
- throw new Error(`${Object.prototype.toString.call(obj)} was already assigned a value for ${this._fieldName}`);
103
- }
104
- if (DEBUG) {
105
- if (obj[DEBUG_IDENTIFIER_BUCKET] && this._fieldName !== 'identifier-proxy-target') {
106
- const target: K = obj[Symbol.for('identifier-proxy-target') as unknown as string] as K;
107
- target[this._symbol as unknown as string] = value;
108
- // TODO the Proxy check here is entirely for ember-m3
109
- // as it's attribute access tests fail since the symbol
110
- // is an unexpected key received by it's proxies.
111
- // we should address this upstream.
112
- } else if (obj.constructor?.toString?.() !== 'MegamorphicModel') {
113
- try {
114
- obj[this._symbol as unknown as string] = value;
115
- } catch {
116
- // some keys are proxies that can't accept symbol values
117
- // for instance records from ember-m3
118
- }
119
- }
120
- }
121
- return super.set(obj, value);
122
- }
123
- }
124
- export type { DebugWeakCache };
125
- export default DEBUG ? DebugWeakCache : WeakCache;