@ember-data/store 4.4.0 → 4.5.0-alpha.2

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 (33) hide show
  1. package/addon/-private/system/core-store.ts +136 -147
  2. package/addon/-private/system/ds-model-store.ts +1 -10
  3. package/addon/-private/system/fetch-manager.ts +48 -21
  4. package/addon/-private/system/model/internal-model.ts +263 -192
  5. package/addon/-private/system/model/states.js +5 -41
  6. package/addon/-private/system/{promise-proxies.js → promise-proxies.ts} +31 -21
  7. package/addon/-private/system/promise-proxy-base.js +7 -0
  8. package/addon/-private/system/{record-array-manager.js → record-array-manager.ts} +87 -60
  9. package/addon/-private/system/record-arrays/adapter-populated-record-array.ts +129 -0
  10. package/addon/-private/system/record-arrays/{record-array.js → record-array.ts} +96 -75
  11. package/addon/-private/system/record-data-for.ts +2 -0
  12. package/addon/-private/system/references/belongs-to.ts +3 -2
  13. package/addon/-private/system/references/has-many.ts +4 -2
  14. package/addon/-private/system/schema-definition-service.ts +2 -2
  15. package/addon/-private/system/snapshot-record-array.ts +12 -11
  16. package/addon/-private/system/snapshot.ts +24 -7
  17. package/addon/-private/system/store/common.js +24 -1
  18. package/addon/-private/system/store/finders.js +53 -5
  19. package/addon/-private/system/store/internal-model-factory.ts +8 -7
  20. package/addon/-private/system/store/record-data-store-wrapper.ts +7 -2
  21. package/addon/-private/system/store/serializer-response.ts +85 -0
  22. package/addon/-private/ts-interfaces/ds-model.ts +15 -7
  23. package/addon/-private/ts-interfaces/ember-data-json-api.ts +3 -0
  24. package/addon/-private/ts-interfaces/minimum-adapter-interface.ts +19 -20
  25. package/addon/-private/ts-interfaces/minimum-serializer-interface.ts +27 -6
  26. package/addon/-private/ts-interfaces/record-data.ts +4 -1
  27. package/addon/-private/ts-interfaces/record-instance.ts +3 -1
  28. package/addon/-private/ts-interfaces/store.ts +1 -0
  29. package/addon/-private/utils/promise-record.ts +3 -3
  30. package/index.js +3 -0
  31. package/package.json +7 -6
  32. package/addon/-private/system/record-arrays/adapter-populated-record-array.js +0 -95
  33. package/addon/-private/system/store/serializer-response.js +0 -71
@@ -1,95 +0,0 @@
1
- import { A } from '@ember/array';
2
- import { get } from '@ember/object';
3
-
4
- import RecordArray from './record-array';
5
-
6
- /**
7
- @module @ember-data/store
8
- */
9
-
10
- /**
11
- Represents an ordered list of records whose order and membership is
12
- determined by the adapter. For example, a query sent to the adapter
13
- may trigger a search on the server, whose results would be loaded
14
- into an instance of the `AdapterPopulatedRecordArray`.
15
-
16
- This class should not be imported and instantiated by consuming applications.
17
-
18
- ---
19
-
20
- If you want to update the array and get the latest records from the
21
- adapter, you can invoke [`update()`](AdapterPopulatedRecordArray/methods/update?anchor=update):
22
-
23
- Example
24
-
25
- ```javascript
26
- // GET /users?isAdmin=true
27
- store.query('user', { isAdmin: true }).then(function(admins) {
28
-
29
- admins.then(function() {
30
- console.log(admins.get("length")); // 42
31
- });
32
-
33
- // somewhere later in the app code, when new admins have been created
34
- // in the meantime
35
- //
36
- // GET /users?isAdmin=true
37
- admins.update().then(function() {
38
- admins.get('isUpdating'); // false
39
- console.log(admins.get("length")); // 123
40
- });
41
-
42
- admins.get('isUpdating'); // true
43
- }
44
- ```
45
-
46
- @class AdapterPopulatedRecordArray
47
- @public
48
- @extends RecordArray
49
- */
50
- export default RecordArray.extend({
51
- init() {
52
- this.set('content', this.get('content') || A());
53
-
54
- this._super(...arguments);
55
- this.query = this.query || null;
56
- this.links = this.links || null;
57
- },
58
-
59
- replace() {
60
- throw new Error(`The result of a server query (on ${this.modelName}) is immutable.`);
61
- },
62
-
63
- _update() {
64
- let store = get(this, 'store');
65
- let query = get(this, 'query');
66
-
67
- return store._query(this.modelName, query, this);
68
- },
69
-
70
- _setObjects(identifiersOrInternalModels, payload) {
71
- // TODO: initial load should not cause change events at all, only
72
- // subsequent. This requires changing the public api of adapter.query, but
73
- // hopefully we can do that soon.
74
- this.get('content').setObjects(identifiersOrInternalModels);
75
-
76
- this.setProperties({
77
- isLoaded: true,
78
- isUpdating: false,
79
- meta: { ...payload.meta },
80
- links: { ...payload.links },
81
- });
82
-
83
- this.manager._associateWithRecordArray(identifiersOrInternalModels, this);
84
- },
85
-
86
- /**
87
- @method _setIdentifiers
88
- @param {StableRecordIdentifier[]} identifiers
89
- @param {Object} payload normalized payload
90
- @private
91
- */
92
- _setIdentifiers(identifiers, payload) {
93
- this._setObjects(identifiers, payload);
94
- },
95
- });
@@ -1,71 +0,0 @@
1
- import { assert } from '@ember/debug';
2
- import { DEBUG } from '@glimmer/env';
3
-
4
- /**
5
- This is a helper method that validates a JSON API top-level document
6
-
7
- The format of a document is described here:
8
- http://jsonapi.org/format/#document-top-level
9
-
10
- @internal
11
- */
12
- export function validateDocumentStructure(doc) {
13
- let errors = [];
14
- if (!doc || typeof doc !== 'object') {
15
- errors.push('Top level of a JSON API document must be an object');
16
- } else {
17
- if (!('data' in doc) && !('errors' in doc) && !('meta' in doc)) {
18
- errors.push('One or more of the following keys must be present: "data", "errors", "meta".');
19
- } else {
20
- if ('data' in doc && 'errors' in doc) {
21
- errors.push('Top level keys "errors" and "data" cannot both be present in a JSON API document');
22
- }
23
- }
24
- if ('data' in doc) {
25
- if (!(doc.data === null || Array.isArray(doc.data) || typeof doc.data === 'object')) {
26
- errors.push('data must be null, an object, or an array');
27
- }
28
- }
29
- if ('meta' in doc) {
30
- if (typeof doc.meta !== 'object') {
31
- errors.push('meta must be an object');
32
- }
33
- }
34
- if ('errors' in doc) {
35
- if (!Array.isArray(doc.errors)) {
36
- errors.push('errors must be an array');
37
- }
38
- }
39
- if ('links' in doc) {
40
- if (typeof doc.links !== 'object') {
41
- errors.push('links must be an object');
42
- }
43
- }
44
- if ('jsonapi' in doc) {
45
- if (typeof doc.jsonapi !== 'object') {
46
- errors.push('jsonapi must be an object');
47
- }
48
- }
49
- if ('included' in doc) {
50
- if (typeof doc.included !== 'object') {
51
- errors.push('included must be an array');
52
- }
53
- }
54
- }
55
-
56
- return errors;
57
- }
58
-
59
- export function normalizeResponseHelper(serializer, store, modelClass, payload, id, requestType) {
60
- let normalizedResponse = serializer.normalizeResponse(store, modelClass, payload, id, requestType);
61
- let validationErrors = [];
62
- if (DEBUG) {
63
- validationErrors = validateDocumentStructure(normalizedResponse);
64
- }
65
- assert(
66
- `normalizeResponse must return a valid JSON API document:\n\t* ${validationErrors.join('\n\t* ')}`,
67
- validationErrors.length === 0
68
- );
69
-
70
- return normalizedResponse;
71
- }