@ember-data/store 4.4.0-alpha.9 → 4.4.1

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 +147 -134
  2. package/addon/-private/system/ds-model-store.ts +10 -1
  3. package/addon/-private/system/fetch-manager.ts +21 -48
  4. package/addon/-private/system/model/internal-model.ts +192 -263
  5. package/addon/-private/system/model/states.js +41 -5
  6. package/addon/-private/system/{promise-proxies.ts → promise-proxies.js} +21 -31
  7. package/addon/-private/system/{record-array-manager.ts → record-array-manager.js} +60 -87
  8. package/addon/-private/system/record-arrays/adapter-populated-record-array.js +95 -0
  9. package/addon/-private/system/record-arrays/{record-array.ts → record-array.js} +75 -96
  10. package/addon/-private/system/record-data-for.ts +0 -2
  11. package/addon/-private/system/references/belongs-to.ts +2 -3
  12. package/addon/-private/system/references/has-many.ts +2 -4
  13. package/addon/-private/system/schema-definition-service.ts +2 -2
  14. package/addon/-private/system/snapshot-record-array.ts +11 -12
  15. package/addon/-private/system/snapshot.ts +7 -24
  16. package/addon/-private/system/store/common.js +1 -24
  17. package/addon/-private/system/store/finders.js +5 -53
  18. package/addon/-private/system/store/internal-model-factory.ts +7 -8
  19. package/addon/-private/system/store/record-data-store-wrapper.ts +2 -7
  20. package/addon/-private/system/store/serializer-response.js +71 -0
  21. package/addon/-private/ts-interfaces/ds-model.ts +7 -15
  22. package/addon/-private/ts-interfaces/ember-data-json-api.ts +0 -3
  23. package/addon/-private/ts-interfaces/minimum-adapter-interface.ts +20 -19
  24. package/addon/-private/ts-interfaces/minimum-serializer-interface.ts +6 -27
  25. package/addon/-private/ts-interfaces/record-data.ts +1 -4
  26. package/addon/-private/ts-interfaces/record-instance.ts +1 -3
  27. package/addon/-private/ts-interfaces/store.ts +0 -1
  28. package/addon/-private/utils/promise-record.ts +3 -3
  29. package/index.js +0 -3
  30. package/package.json +6 -7
  31. package/addon/-private/system/promise-proxy-base.js +0 -7
  32. package/addon/-private/system/record-arrays/adapter-populated-record-array.ts +0 -129
  33. package/addon/-private/system/store/serializer-response.ts +0 -85
@@ -1,129 +0,0 @@
1
- import type NativeArray from '@ember/array/-private/native-array';
2
- import { assert } from '@ember/debug';
3
-
4
- import type { PromiseArray, RecordArrayManager } from 'ember-data/-private';
5
-
6
- import type { CollectionResourceDocument, Links, Meta, PaginationLinks } from '../../ts-interfaces/ember-data-json-api';
7
- import type { StableRecordIdentifier } from '../../ts-interfaces/identifier';
8
- import type { RecordInstance } from '../../ts-interfaces/record-instance';
9
- import type { FindOptions } from '../../ts-interfaces/store';
10
- import type { Dict } from '../../ts-interfaces/utils';
11
- import type CoreStore from '../core-store';
12
- import { promiseArray } from '../promise-proxies';
13
- import SnapshotRecordArray from '../snapshot-record-array';
14
- import RecordArray from './record-array';
15
-
16
- export interface AdapterPopulatedRecordArrayCreateArgs {
17
- modelName: string;
18
- store: CoreStore;
19
- manager: RecordArrayManager;
20
- content: NativeArray<StableRecordIdentifier>;
21
- isLoaded: boolean;
22
- query?: Dict<unknown>;
23
- meta?: Meta;
24
- links?: Links | PaginationLinks | null;
25
- }
26
-
27
- /**
28
- @module @ember-data/store
29
- */
30
-
31
- /**
32
- Represents an ordered list of records whose order and membership is
33
- determined by the adapter. For example, a query sent to the adapter
34
- may trigger a search on the server, whose results would be loaded
35
- into an instance of the `AdapterPopulatedRecordArray`.
36
-
37
- This class should not be imported and instantiated by consuming applications.
38
-
39
- ---
40
-
41
- If you want to update the array and get the latest records from the
42
- adapter, you can invoke [`update()`](AdapterPopulatedRecordArray/methods/update?anchor=update):
43
-
44
- Example
45
-
46
- ```javascript
47
- // GET /users?isAdmin=true
48
- store.query('user', { isAdmin: true }).then(function(admins) {
49
-
50
- admins.then(function() {
51
- console.log(admins.get("length")); // 42
52
- });
53
-
54
- // somewhere later in the app code, when new admins have been created
55
- // in the meantime
56
- //
57
- // GET /users?isAdmin=true
58
- admins.update().then(function() {
59
- admins.get('isUpdating'); // false
60
- console.log(admins.get("length")); // 123
61
- });
62
-
63
- admins.get('isUpdating'); // true
64
- }
65
- ```
66
-
67
- @class AdapterPopulatedRecordArray
68
- @public
69
- @extends RecordArray
70
- */
71
- export default class AdapterPopulatedRecordArray extends RecordArray {
72
- declare links: Links | PaginationLinks | null;
73
- declare meta: Dict<unknown> | null;
74
- declare query: Dict<unknown> | null;
75
-
76
- init(props?: AdapterPopulatedRecordArrayCreateArgs) {
77
- assert(`Cannot initialize AdapterPopulatedRecordArray with isUpdating`, !props || !('isUpdating' in props));
78
- super.init();
79
- this.query = this.query || null;
80
- this.links = this.links || null;
81
- this.meta = this.meta || null;
82
- }
83
-
84
- replace() {
85
- throw new Error(`The result of a server query (on ${this.modelName}) is immutable.`);
86
- }
87
-
88
- _update(): PromiseArray<RecordInstance, AdapterPopulatedRecordArray> {
89
- const { store, query } = this;
90
-
91
- // TODO save options from initial request?
92
- return promiseArray(store._query(this.modelName, query, this, {}));
93
- }
94
-
95
- _setObjects(identifiers: StableRecordIdentifier[], payload: CollectionResourceDocument) {
96
- // TODO: initial load should not cause change events at all, only
97
- // subsequent. This requires changing the public api of adapter.query, but
98
- // hopefully we can do that soon.
99
- this.content.setObjects(identifiers);
100
-
101
- this.setProperties({
102
- isLoaded: true,
103
- isUpdating: false,
104
- // TODO this assign kills the root reference but a deep-copy would be required
105
- // for both meta and links to actually not be by-ref. We whould likely change
106
- // this to a dev-only deep-freeze.
107
- meta: Object.assign({}, payload.meta),
108
- links: Object.assign({}, payload.links),
109
- });
110
-
111
- this.manager._associateWithRecordArray(identifiers, this);
112
- }
113
-
114
- _createSnapshot(options: FindOptions) {
115
- // this is private for users, but public for ember-data internals
116
- // meta will only be present for an AdapterPopulatedRecordArray
117
- return new SnapshotRecordArray(this, this.meta, options);
118
- }
119
-
120
- /**
121
- @method _setIdentifiers
122
- @param {StableRecordIdentifier[]} identifiers
123
- @param {Object} payload normalized payload
124
- @private
125
- */
126
- _setIdentifiers(identifiers: StableRecordIdentifier[], payload: CollectionResourceDocument): void {
127
- this._setObjects(identifiers, payload);
128
- }
129
- }
@@ -1,85 +0,0 @@
1
- import { assert } from '@ember/debug';
2
- import { DEBUG } from '@glimmer/env';
3
-
4
- import { JsonApiDocument } from '../../ts-interfaces/ember-data-json-api';
5
- import { AdapterPayload } from '../../ts-interfaces/minimum-adapter-interface';
6
- import { MinimumSerializerInterface, RequestType } from '../../ts-interfaces/minimum-serializer-interface';
7
- import CoreStore from '../core-store';
8
- import ShimModelClass from '../model/shim-model-class';
9
-
10
- /**
11
- This is a helper method that validates a JSON API top-level document
12
-
13
- The format of a document is described here:
14
- http://jsonapi.org/format/#document-top-level
15
-
16
- @internal
17
- */
18
- function validateDocumentStructure(doc?: AdapterPayload | JsonApiDocument): asserts doc is JsonApiDocument {
19
- if (DEBUG) {
20
- let errors: string[] = [];
21
- if (!doc || typeof doc !== 'object') {
22
- errors.push('Top level of a JSON API document must be an object');
23
- } else {
24
- if (!('data' in doc) && !('errors' in doc) && !('meta' in doc)) {
25
- errors.push('One or more of the following keys must be present: "data", "errors", "meta".');
26
- } else {
27
- if ('data' in doc && 'errors' in doc) {
28
- errors.push('Top level keys "errors" and "data" cannot both be present in a JSON API document');
29
- }
30
- }
31
- if ('data' in doc) {
32
- if (!(doc.data === null || Array.isArray(doc.data) || typeof doc.data === 'object')) {
33
- errors.push('data must be null, an object, or an array');
34
- }
35
- }
36
- if ('meta' in doc) {
37
- if (typeof doc.meta !== 'object') {
38
- errors.push('meta must be an object');
39
- }
40
- }
41
- if ('errors' in doc) {
42
- if (!Array.isArray(doc.errors)) {
43
- errors.push('errors must be an array');
44
- }
45
- }
46
- if ('links' in doc) {
47
- if (typeof doc.links !== 'object') {
48
- errors.push('links must be an object');
49
- }
50
- }
51
- if ('jsonapi' in doc) {
52
- if (typeof doc.jsonapi !== 'object') {
53
- errors.push('jsonapi must be an object');
54
- }
55
- }
56
- if ('included' in doc) {
57
- if (typeof doc.included !== 'object') {
58
- errors.push('included must be an array');
59
- }
60
- }
61
- }
62
-
63
- assert(
64
- `Response must be normalized to a valid JSON API document:\n\t* ${errors.join('\n\t* ')}`,
65
- errors.length === 0
66
- );
67
- }
68
- }
69
-
70
- export function normalizeResponseHelper(
71
- serializer: MinimumSerializerInterface | null,
72
- store: CoreStore,
73
- modelClass: ShimModelClass,
74
- payload: AdapterPayload,
75
- id: string | null,
76
- requestType: RequestType
77
- ): JsonApiDocument {
78
- let normalizedResponse = serializer
79
- ? serializer.normalizeResponse(store, modelClass, payload, id, requestType)
80
- : payload;
81
-
82
- validateDocumentStructure(normalizedResponse);
83
-
84
- return normalizedResponse;
85
- }