@ember-data/store 4.5.0-beta.0 → 4.5.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 (64) hide show
  1. package/addon/-private/{system/backburner.js → backburner.js} +0 -0
  2. package/addon/-private/{system/coerce-id.ts → coerce-id.ts} +0 -0
  3. package/addon/-private/{system/store/common.js → common.js} +0 -0
  4. package/addon/-private/{system/core-store.ts → core-store.ts} +467 -1253
  5. package/addon/-private/{system/errors-utils.js → errors-utils.js} +7 -6
  6. package/addon/-private/{system/fetch-manager.ts → fetch-manager.ts} +72 -42
  7. package/addon/-private/finders.js +107 -0
  8. package/addon/-private/identifer-debug-consts.ts +3 -0
  9. package/addon/-private/{identifiers/cache.ts → identifier-cache.ts} +26 -14
  10. package/addon/-private/{system/identity-map.ts → identity-map.ts} +2 -1
  11. package/addon/-private/index.ts +17 -17
  12. package/addon/-private/instance-cache.ts +387 -0
  13. package/addon/-private/{system/store/internal-model-factory.ts → internal-model-factory.ts} +25 -19
  14. package/addon/-private/{system/internal-model-map.ts → internal-model-map.ts} +9 -5
  15. package/addon/-private/model/internal-model.ts +602 -0
  16. package/addon/-private/{system/references/record.ts → model/record-reference.ts} +23 -36
  17. package/addon/-private/{system/model → model}/shim-model-class.ts +19 -14
  18. package/addon/-private/{system/normalize-model-name.ts → normalize-model-name.ts} +0 -0
  19. package/addon/-private/{system/promise-proxies.ts → promise-proxies.ts} +12 -5
  20. package/addon/-private/{system/promise-proxy-base.js → promise-proxy-base.js} +0 -0
  21. package/addon/-private/{system/record-array-manager.ts → record-array-manager.ts} +19 -18
  22. package/addon/-private/{system/record-arrays → record-arrays}/adapter-populated-record-array.ts +11 -10
  23. package/addon/-private/{system/record-arrays → record-arrays}/record-array.ts +37 -19
  24. package/addon/-private/record-data-for.ts +39 -0
  25. package/addon/-private/{system/store/record-data-store-wrapper.ts → record-data-store-wrapper.ts} +21 -26
  26. package/addon/-private/{system/record-notification-manager.ts → record-notification-manager.ts} +8 -3
  27. package/addon/-private/{system/request-cache.ts → request-cache.ts} +5 -6
  28. package/addon/-private/{system/schema-definition-service.ts → schema-definition-service.ts} +30 -14
  29. package/addon/-private/{system/store/serializer-response.ts → serializer-response.ts} +7 -6
  30. package/addon/-private/{system/snapshot-record-array.ts → snapshot-record-array.ts} +27 -8
  31. package/addon/-private/{system/snapshot.ts → snapshot.ts} +54 -39
  32. package/addon/-private/utils/construct-resource.ts +7 -3
  33. package/addon/-private/utils/promise-record.ts +9 -18
  34. package/addon/-private/{system/weak-cache.ts → weak-cache.ts} +2 -2
  35. package/addon/index.ts +1 -0
  36. package/package.json +21 -20
  37. package/addon/-private/identifiers/is-stable-identifier.ts +0 -18
  38. package/addon/-private/identifiers/utils/uuid-v4.ts +0 -80
  39. package/addon/-private/system/ds-model-store.ts +0 -136
  40. package/addon/-private/system/model/internal-model.ts +0 -1303
  41. package/addon/-private/system/model/states.js +0 -736
  42. package/addon/-private/system/record-arrays.ts +0 -8
  43. package/addon/-private/system/record-data-for.ts +0 -54
  44. package/addon/-private/system/references/belongs-to.ts +0 -406
  45. package/addon/-private/system/references/has-many.ts +0 -487
  46. package/addon/-private/system/references/reference.ts +0 -205
  47. package/addon/-private/system/references.js +0 -9
  48. package/addon/-private/system/store/finders.js +0 -412
  49. package/addon/-private/ts-interfaces/ds-model.ts +0 -50
  50. package/addon/-private/ts-interfaces/ember-data-json-api.ts +0 -145
  51. package/addon/-private/ts-interfaces/fetch-manager.ts +0 -44
  52. package/addon/-private/ts-interfaces/identifier.ts +0 -246
  53. package/addon/-private/ts-interfaces/minimum-adapter-interface.ts +0 -584
  54. package/addon/-private/ts-interfaces/minimum-serializer-interface.ts +0 -257
  55. package/addon/-private/ts-interfaces/promise-proxies.ts +0 -3
  56. package/addon/-private/ts-interfaces/record-data-json-api.ts +0 -29
  57. package/addon/-private/ts-interfaces/record-data-record-wrapper.ts +0 -46
  58. package/addon/-private/ts-interfaces/record-data-schemas.ts +0 -45
  59. package/addon/-private/ts-interfaces/record-data-store-wrapper.ts +0 -56
  60. package/addon/-private/ts-interfaces/record-data.ts +0 -72
  61. package/addon/-private/ts-interfaces/record-instance.ts +0 -18
  62. package/addon/-private/ts-interfaces/schema-definition-service.ts +0 -12
  63. package/addon/-private/ts-interfaces/store.ts +0 -10
  64. package/addon/-private/ts-interfaces/utils.ts +0 -6
@@ -1,246 +0,0 @@
1
- /**
2
- @module @ember-data/store
3
- */
4
- import type { ExistingResourceObject, ResourceIdentifierObject } from './ember-data-json-api';
5
-
6
- export type ResourceData = ResourceIdentifierObject | ExistingResourceObject;
7
- export type IdentifierBucket = 'record';
8
-
9
- // provided for additional debuggability
10
- export const DEBUG_CLIENT_ORIGINATED: unique symbol = Symbol('record-originated-on-client');
11
- export const DEBUG_IDENTIFIER_BUCKET: unique symbol = Symbol('identifier-bucket');
12
-
13
- export interface Identifier {
14
- lid: string;
15
- clientId?: string;
16
- }
17
-
18
- export interface ExistingRecordIdentifier extends Identifier {
19
- id: string;
20
- type: string;
21
- }
22
-
23
- export interface NewRecordIdentifier extends Identifier {
24
- id: string | null;
25
- type: string;
26
- }
27
-
28
- /**
29
- * An Identifier specific to a record which may or may not
30
- * be present in the cache.
31
- *
32
- * The absence of an `id` DOES NOT indicate that this
33
- * Identifier is for a new client-created record as it
34
- * may also indicate that it was generated for a secondary
35
- * index and the primary `id` index is not yet known.
36
- *
37
- * @internal
38
- */
39
- export type RecordIdentifier = ExistingRecordIdentifier | NewRecordIdentifier;
40
-
41
- /**
42
- * Used when an Identifier is known to be the stable version
43
- *
44
- * @internal
45
- */
46
- export interface StableIdentifier extends Identifier {
47
- [DEBUG_IDENTIFIER_BUCKET]?: string;
48
- }
49
-
50
- /**
51
- * Used when a StableRecordIdentifier was not created locally as part
52
- * of a call to store.createRecord
53
- *
54
- * Distinguishing between this Identifier and one for a client created
55
- * record that was created with an ID is generally speaking not possible
56
- * at runtime, so anything with an ID typically narrows to this.
57
- *
58
- * @internal
59
- */
60
- export interface StableExistingRecordIdentifier extends StableIdentifier {
61
- id: string;
62
- type: string;
63
- [DEBUG_CLIENT_ORIGINATED]?: boolean;
64
- }
65
- /**
66
- * Used when a StableRecordIdentifier was created locally
67
- * (by a call to store.createRecord).
68
- *
69
- * It is possible in rare circumstances to have a StableRecordIdentifier
70
- * that is not for a new record but does not have an ID. This would
71
- * happen if a user intentionally created one for use with a secondary-index
72
- * prior to the record having been fully loaded.
73
- *
74
- * @internal
75
- */
76
- export interface StableNewRecordIdentifier extends StableIdentifier {
77
- id: string | null;
78
- type: string;
79
- [DEBUG_CLIENT_ORIGINATED]?: boolean;
80
- }
81
-
82
- /**
83
- * A referentially stable object with a unique string (lid) that can be used
84
- * as a reference to data in the cache.
85
- *
86
- * Every record instance has a unique identifier, and identifiers may refer
87
- * to data that has never been loaded (for instance, in an async relationship).
88
- *
89
- * @class StableRecordIdentifier
90
- * @public
91
- */
92
-
93
- /**
94
- * A string representing a unique identity.
95
- *
96
- * @property {string} lid
97
- * @public
98
- */
99
- /**
100
- * the primary resource `type` or `modelName` this identity belongs to.
101
- *
102
- * @property {string} type
103
- * @public
104
- */
105
- /**
106
- * the primary id for the record this identity belongs to. `null`
107
- * if not yet assigned an id.
108
- *
109
- * @property {string | null} id
110
- * @public
111
- */
112
- export type StableRecordIdentifier = StableExistingRecordIdentifier | StableNewRecordIdentifier;
113
-
114
- /**
115
- Configures how unique identifier lid strings are generated by @ember-data/store.
116
-
117
- This configuration MUST occur prior to the store instance being created.
118
-
119
- Takes a method which can expect to receive various data as its first argument
120
- and the name of a bucket as its second argument. Currently the second
121
- argument will always be `record` data should conform to a `json-api`
122
- `Resource` interface, but will be the normalized json data for a single
123
- resource that has been given to the store.
124
-
125
- The method must return a unique (to at-least the given bucket) string identifier
126
- for the given data as a string to be used as the `lid` of an `Identifier` token.
127
-
128
- This method will only be called by either `getOrCreateRecordIdentifier` or
129
- `createIdentifierForNewRecord` when an identifier for the supplied data
130
- is not already known via `lid` or `type + id` combo and one needs to be
131
- generated or retrieved from a proprietary cache.
132
-
133
- `data` will be the same data argument provided to `getOrCreateRecordIdentifier`
134
- and in the `createIdentifierForNewRecord` case will be an object with
135
- only `type` as a key.
136
-
137
- ```ts
138
- import { setIdentifierGenerationMethod } form '@ember-data/store';
139
-
140
- export function initialize(applicationInstance) {
141
- // note how `count` here is now scoped to the application instance
142
- // for our generation method by being inside the closure provided
143
- // by the initialize function
144
- let count = 0;
145
-
146
- setIdentifierGenerationMethod((resource, bucket) => {
147
- return resource.lid || `my-key-${count++}`;
148
- });
149
- }
150
-
151
- export default {
152
- name: 'configure-ember-data-identifiers',
153
- initialize
154
- };
155
- ```
156
-
157
- @method setIdentifierGenerationMethod
158
- @for @ember-data/store
159
- @param method
160
- @public
161
- @static
162
- */
163
- export type GenerationMethod = (data: ResourceData | { type: string }, bucket: IdentifierBucket) => string;
164
-
165
- /**
166
- Configure a callback for when the identifier cache encounters new resource
167
- data for an existing resource.
168
-
169
- This configuration MUST occur prior to the store instance being created.
170
-
171
- ```js
172
- import { setIdentifierUpdateMethod } from '@ember-data/store';
173
- ```
174
-
175
- Takes a method which can expect to receive an existing `Identifier` alongside
176
- some new data to consider as a second argument. This is an opportunity
177
- for secondary lookup tables and caches associated with the identifier
178
- to be amended.
179
-
180
- This method is called everytime `updateRecordIdentifier` is called and
181
- with the same arguments. It provides the opportunity to update secondary
182
- lookup tables for existing identifiers.
183
-
184
- It will always be called after an identifier created with `createIdentifierForNewRecord`
185
- has been committed, or after an update to the `record` a `RecordIdentifier`
186
- is assigned to has been committed. Committed here meaning that the server
187
- has acknowledged the update (for instance after a call to `.save()`)
188
-
189
- If `id` has not previously existed, it will be assigned to the `Identifier`
190
- prior to this `UpdateMethod` being called; however, calls to the parent method
191
- `updateRecordIdentifier` that attempt to change the `id` or calling update
192
- without providing an `id` when one is missing will throw an error.
193
-
194
- @method setIdentifierUpdateMethod
195
- @for @ember-data/store
196
- @param method
197
- @public
198
- @static
199
- */
200
-
201
- export type UpdateMethod = {
202
- (identifier: StableRecordIdentifier, newData: ResourceData, bucket: 'record'): void;
203
- (identifier: StableIdentifier, newData: unknown, bucket: never): void;
204
- };
205
-
206
- /**
207
- Configure a callback for when the identifier cache is going to release an identifier.
208
-
209
- This configuration MUST occur prior to the store instance being created.
210
-
211
- ```js
212
- import { setIdentifierForgetMethod } from '@ember-data/store';
213
- ```
214
-
215
- Takes method which can expect to receive an existing `Identifier` that should be eliminated
216
- from any secondary lookup tables or caches that the user has populated for it.
217
-
218
- @method setIdentifierForgetMethod
219
- @for @ember-data/store
220
- @param method
221
- @public
222
- @static
223
- */
224
- export type ForgetMethod = (identifier: StableIdentifier | StableRecordIdentifier, bucket: IdentifierBucket) => void;
225
-
226
- /**
227
- Configure a callback for when the identifier cache is being torn down.
228
-
229
- This configuration MUST occur prior to the store instance being created.
230
-
231
- ```js
232
- import { setIdentifierResetMethod } from '@ember-data/store';
233
- ```
234
-
235
- Takes a method which can expect to be called when the parent application is destroyed.
236
-
237
- If you have properly used a WeakMap to encapsulate the state of your customization
238
- to the application instance, you may not need to implement the `resetMethod`.
239
-
240
- @method setIdentifierResetMethod
241
- @for @ember-data/store
242
- @param method
243
- @public
244
- @static
245
- */
246
- export type ResetMethod = () => void;