@ember-data/store 4.3.0 → 4.4.0-alpha.10

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 (35) hide show
  1. package/addon/-private/index.ts +1 -1
  2. package/addon/-private/system/core-store.ts +134 -147
  3. package/addon/-private/system/ds-model-store.ts +1 -10
  4. package/addon/-private/system/fetch-manager.ts +48 -21
  5. package/addon/-private/system/model/internal-model.ts +263 -192
  6. package/addon/-private/system/model/states.js +5 -41
  7. package/addon/-private/system/promise-proxies.ts +132 -0
  8. package/addon/-private/system/promise-proxy-base.js +7 -0
  9. package/addon/-private/system/{record-array-manager.js → record-array-manager.ts} +87 -60
  10. package/addon/-private/system/record-arrays/adapter-populated-record-array.ts +129 -0
  11. package/addon/-private/system/record-arrays/{record-array.js → record-array.ts} +96 -75
  12. package/addon/-private/system/record-data-for.ts +2 -0
  13. package/addon/-private/system/references/belongs-to.ts +3 -2
  14. package/addon/-private/system/references/has-many.ts +4 -2
  15. package/addon/-private/system/schema-definition-service.ts +2 -2
  16. package/addon/-private/system/snapshot-record-array.ts +12 -11
  17. package/addon/-private/system/snapshot.ts +24 -7
  18. package/addon/-private/system/store/common.js +24 -1
  19. package/addon/-private/system/store/finders.js +53 -5
  20. package/addon/-private/system/store/internal-model-factory.ts +8 -7
  21. package/addon/-private/system/store/record-data-store-wrapper.ts +7 -2
  22. package/addon/-private/system/store/serializer-response.ts +85 -0
  23. package/addon/-private/ts-interfaces/ds-model.ts +15 -7
  24. package/addon/-private/ts-interfaces/ember-data-json-api.ts +3 -0
  25. package/addon/-private/ts-interfaces/minimum-adapter-interface.ts +19 -20
  26. package/addon/-private/ts-interfaces/minimum-serializer-interface.ts +27 -6
  27. package/addon/-private/ts-interfaces/record-data.ts +4 -1
  28. package/addon/-private/ts-interfaces/record-instance.ts +3 -1
  29. package/addon/-private/ts-interfaces/store.ts +1 -0
  30. package/addon/-private/utils/promise-record.ts +3 -3
  31. package/index.js +3 -0
  32. package/package.json +7 -6
  33. package/addon/-private/system/promise-proxies.js +0 -90
  34. package/addon/-private/system/record-arrays/adapter-populated-record-array.js +0 -95
  35. package/addon/-private/system/store/serializer-response.js +0 -71
@@ -1,90 +0,0 @@
1
- import ArrayProxy from '@ember/array/proxy';
2
- import { reads } from '@ember/object/computed';
3
- import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
4
- import ObjectProxy from '@ember/object/proxy';
5
-
6
- import { Promise } from 'rsvp';
7
-
8
- /**
9
- @module @ember-data/store
10
- */
11
-
12
- /**
13
- A `PromiseArray` is an object that acts like both an `Ember.Array`
14
- and a promise. When the promise is resolved the resulting value
15
- will be set to the `PromiseArray`'s `content` property. This makes
16
- it easy to create data bindings with the `PromiseArray` that will be
17
- updated when the promise resolves.
18
-
19
- This class should not be imported and instantiated directly.
20
-
21
- For more information see the [Ember.PromiseProxyMixin
22
- documentation](/ember/release/classes/PromiseProxyMixin).
23
-
24
- Example
25
-
26
- ```javascript
27
- let promiseArray = PromiseArray.create({
28
- promise: $.getJSON('/some/remote/data.json')
29
- });
30
-
31
- promiseArray.get('length'); // 0
32
-
33
- promiseArray.then(function() {
34
- promiseArray.get('length'); // 100
35
- });
36
- ```
37
-
38
- @class PromiseArray
39
- @public
40
- @extends Ember.ArrayProxy
41
- @uses Ember.PromiseProxyMixin
42
- */
43
- export const PromiseArray = ArrayProxy.extend(PromiseProxyMixin, {
44
- meta: reads('content.meta'),
45
- });
46
-
47
- /**
48
- A `PromiseObject` is an object that acts like both an `EmberObject`
49
- and a promise. When the promise is resolved, then the resulting value
50
- will be set to the `PromiseObject`'s `content` property. This makes
51
- it easy to create data bindings with the `PromiseObject` that will
52
- be updated when the promise resolves.
53
-
54
- This class should not be imported and instantiated directly.
55
-
56
- For more information see the [Ember.PromiseProxyMixin
57
- documentation](/ember/release/classes/PromiseProxyMixin.html).
58
-
59
- Example
60
-
61
- ```javascript
62
- let promiseObject = PromiseObject.create({
63
- promise: $.getJSON('/some/remote/data.json')
64
- });
65
-
66
- promiseObject.get('name'); // null
67
-
68
- promiseObject.then(function() {
69
- promiseObject.get('name'); // 'Tomster'
70
- });
71
- ```
72
-
73
- @class PromiseObject
74
- @public
75
- @extends Ember.ObjectProxy
76
- @uses Ember.PromiseProxyMixin
77
- */
78
- export let PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
79
-
80
- export function promiseObject(promise, label) {
81
- return PromiseObject.create({
82
- promise: Promise.resolve(promise, label),
83
- });
84
- }
85
-
86
- export function promiseArray(promise, label) {
87
- return PromiseArray.create({
88
- promise: Promise.resolve(promise, label),
89
- });
90
- }
@@ -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
- }