@ember-data/store 4.10.0-alpha.2 → 4.10.0-alpha.21
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.
- package/addon/-private.js +1 -0
- package/addon/-private.js.map +1 -0
- package/addon/index-12e1fcb9.js +7660 -0
- package/addon/index-12e1fcb9.js.map +1 -0
- package/addon/index.js +1 -0
- package/addon/index.js.map +1 -0
- package/addon-main.js +90 -0
- package/package.json +44 -15
- package/addon/-private/caches/identifier-cache.ts +0 -686
- package/addon/-private/caches/instance-cache.ts +0 -695
- package/addon/-private/caches/record-data-for.ts +0 -34
- package/addon/-private/index.ts +0 -59
- package/addon/-private/legacy-model-support/record-reference.ts +0 -240
- package/addon/-private/legacy-model-support/schema-definition-service.ts +0 -148
- package/addon/-private/legacy-model-support/shim-model-class.ts +0 -97
- package/addon/-private/managers/record-array-manager.ts +0 -379
- package/addon/-private/managers/record-data-manager.ts +0 -845
- package/addon/-private/managers/record-data-store-wrapper.ts +0 -425
- package/addon/-private/managers/record-notification-manager.ts +0 -111
- package/addon/-private/network/fetch-manager.ts +0 -567
- package/addon/-private/network/finders.js +0 -104
- package/addon/-private/network/request-cache.ts +0 -132
- package/addon/-private/network/snapshot-record-array.ts +0 -209
- package/addon/-private/network/snapshot.ts +0 -563
- package/addon/-private/proxies/promise-proxies.ts +0 -228
- package/addon/-private/proxies/promise-proxy-base.js +0 -7
- package/addon/-private/record-arrays/identifier-array.ts +0 -929
- package/addon/-private/store-service.ts +0 -2896
- package/addon/-private/utils/coerce-id.ts +0 -41
- package/addon/-private/utils/common.js +0 -65
- package/addon/-private/utils/construct-resource.ts +0 -61
- package/addon/-private/utils/identifer-debug-consts.ts +0 -3
- package/addon/-private/utils/is-non-empty-string.ts +0 -3
- package/addon/-private/utils/normalize-model-name.ts +0 -21
- package/addon/-private/utils/promise-record.ts +0 -15
- package/addon/-private/utils/serializer-response.ts +0 -86
- package/addon/-private/utils/uuid-polyfill.ts +0 -73
- package/addon/index.ts +0 -14
- package/index.js +0 -49
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
FindRecordQuery,
|
|
3
|
-
Operation,
|
|
4
|
-
Request,
|
|
5
|
-
RequestState,
|
|
6
|
-
SaveRecordMutation,
|
|
7
|
-
} from '@ember-data/types/q/fetch-manager';
|
|
8
|
-
import type { RecordIdentifier, StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
9
|
-
|
|
10
|
-
const Touching: unique symbol = Symbol('touching');
|
|
11
|
-
export const RequestPromise: unique symbol = Symbol('promise');
|
|
12
|
-
|
|
13
|
-
interface InternalRequest extends RequestState {
|
|
14
|
-
[Touching]: RecordIdentifier[];
|
|
15
|
-
[RequestPromise]?: Promise<any>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type RecordOperation = FindRecordQuery | SaveRecordMutation;
|
|
19
|
-
|
|
20
|
-
function hasRecordIdentifier(op: Operation): op is RecordOperation {
|
|
21
|
-
return 'recordIdentifier' in op;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default class RequestCache {
|
|
25
|
-
_pending: { [lid: string]: InternalRequest[] } = Object.create(null);
|
|
26
|
-
_done: Map<StableRecordIdentifier, InternalRequest[]> = new Map();
|
|
27
|
-
_subscriptions: { [lid: string]: Function[] } = Object.create(null);
|
|
28
|
-
|
|
29
|
-
enqueue(promise: Promise<any>, queryRequest: Request) {
|
|
30
|
-
let query = queryRequest.data[0];
|
|
31
|
-
if (hasRecordIdentifier(query)) {
|
|
32
|
-
let lid = query.recordIdentifier.lid;
|
|
33
|
-
let type = query.op === 'saveRecord' ? ('mutation' as const) : ('query' as const);
|
|
34
|
-
if (!this._pending[lid]) {
|
|
35
|
-
this._pending[lid] = [];
|
|
36
|
-
}
|
|
37
|
-
let request: InternalRequest = {
|
|
38
|
-
state: 'pending',
|
|
39
|
-
request: queryRequest,
|
|
40
|
-
type,
|
|
41
|
-
} as InternalRequest;
|
|
42
|
-
request[Touching] = [query.recordIdentifier];
|
|
43
|
-
request[RequestPromise] = promise;
|
|
44
|
-
this._pending[lid].push(request);
|
|
45
|
-
this._triggerSubscriptions(request);
|
|
46
|
-
promise.then(
|
|
47
|
-
(result) => {
|
|
48
|
-
this._dequeue(lid, request);
|
|
49
|
-
let finalizedRequest = {
|
|
50
|
-
state: 'fulfilled',
|
|
51
|
-
request: queryRequest,
|
|
52
|
-
type,
|
|
53
|
-
response: { data: result },
|
|
54
|
-
} as InternalRequest;
|
|
55
|
-
finalizedRequest[Touching] = request[Touching];
|
|
56
|
-
this._addDone(finalizedRequest);
|
|
57
|
-
this._triggerSubscriptions(finalizedRequest);
|
|
58
|
-
},
|
|
59
|
-
(error) => {
|
|
60
|
-
this._dequeue(lid, request);
|
|
61
|
-
let finalizedRequest = {
|
|
62
|
-
state: 'rejected',
|
|
63
|
-
request: queryRequest,
|
|
64
|
-
type,
|
|
65
|
-
response: { data: error },
|
|
66
|
-
} as InternalRequest;
|
|
67
|
-
finalizedRequest[Touching] = request[Touching];
|
|
68
|
-
this._addDone(finalizedRequest);
|
|
69
|
-
this._triggerSubscriptions(finalizedRequest);
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
_triggerSubscriptions(req: InternalRequest) {
|
|
76
|
-
req[Touching].forEach((identifier) => {
|
|
77
|
-
if (this._subscriptions[identifier.lid]) {
|
|
78
|
-
this._subscriptions[identifier.lid].forEach((callback) => callback(req));
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
_dequeue(lid: string, request: InternalRequest) {
|
|
84
|
-
this._pending[lid] = this._pending[lid].filter((req) => req !== request);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
_addDone(request: InternalRequest) {
|
|
88
|
-
request[Touching].forEach((identifier) => {
|
|
89
|
-
// TODO add support for multiple
|
|
90
|
-
let requestDataOp = request.request.data[0].op;
|
|
91
|
-
let requests = this._done.get(identifier);
|
|
92
|
-
|
|
93
|
-
if (requests) {
|
|
94
|
-
requests = requests.filter((req) => {
|
|
95
|
-
// TODO add support for multiple
|
|
96
|
-
let data;
|
|
97
|
-
if (req.request.data instanceof Array) {
|
|
98
|
-
data = req.request.data[0];
|
|
99
|
-
} else {
|
|
100
|
-
data = req.request.data;
|
|
101
|
-
}
|
|
102
|
-
return data.op !== requestDataOp;
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
requests = requests || [];
|
|
106
|
-
requests.push(request);
|
|
107
|
-
this._done.set(identifier, requests);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
subscribeForRecord(identifier: RecordIdentifier, callback: (requestState: RequestState) => void) {
|
|
112
|
-
if (!this._subscriptions[identifier.lid]) {
|
|
113
|
-
this._subscriptions[identifier.lid] = [];
|
|
114
|
-
}
|
|
115
|
-
this._subscriptions[identifier.lid].push(callback);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
getPendingRequestsForRecord(identifier: RecordIdentifier): RequestState[] {
|
|
119
|
-
if (this._pending[identifier.lid]) {
|
|
120
|
-
return this._pending[identifier.lid];
|
|
121
|
-
}
|
|
122
|
-
return [];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
getLastRequestForRecord(identifier: RecordIdentifier): RequestState | null {
|
|
126
|
-
let requests = this._done.get(identifier);
|
|
127
|
-
if (requests) {
|
|
128
|
-
return requests[requests.length - 1];
|
|
129
|
-
}
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
@module @ember-data/store
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { deprecate } from '@ember/debug';
|
|
6
|
-
|
|
7
|
-
import { DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS } from '@ember-data/private-build-infra/deprecations';
|
|
8
|
-
import type { ModelSchema } from '@ember-data/types/q/ds-model';
|
|
9
|
-
import { StableRecordIdentifier } from '@ember-data/types/q/identifier';
|
|
10
|
-
import type { FindOptions } from '@ember-data/types/q/store';
|
|
11
|
-
import type { Dict } from '@ember-data/types/q/utils';
|
|
12
|
-
|
|
13
|
-
import type IdentifierArray from '../record-arrays/identifier-array';
|
|
14
|
-
import { SOURCE } from '../record-arrays/identifier-array';
|
|
15
|
-
import Store from '../store-service';
|
|
16
|
-
import type Snapshot from './snapshot';
|
|
17
|
-
/**
|
|
18
|
-
SnapshotRecordArray is not directly instantiable.
|
|
19
|
-
Instances are provided to consuming application's
|
|
20
|
-
adapters for certain requests.
|
|
21
|
-
|
|
22
|
-
@class SnapshotRecordArray
|
|
23
|
-
@public
|
|
24
|
-
*/
|
|
25
|
-
export default class SnapshotRecordArray {
|
|
26
|
-
declare _snapshots: Snapshot[] | null;
|
|
27
|
-
declare _recordArray: IdentifierArray;
|
|
28
|
-
declare _type: ModelSchema | null;
|
|
29
|
-
declare __store: Store;
|
|
30
|
-
|
|
31
|
-
declare length: number;
|
|
32
|
-
declare adapterOptions?: Dict<unknown>;
|
|
33
|
-
declare include?: string;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
SnapshotRecordArray is not directly instantiable.
|
|
37
|
-
Instances are provided to consuming application's
|
|
38
|
-
adapters and serializers for certain requests.
|
|
39
|
-
|
|
40
|
-
@method constructor
|
|
41
|
-
@private
|
|
42
|
-
@constructor
|
|
43
|
-
@param {RecordArray} recordArray
|
|
44
|
-
@param options
|
|
45
|
-
*/
|
|
46
|
-
constructor(store: Store, recordArray: IdentifierArray, options: FindOptions = {}) {
|
|
47
|
-
this.__store = store;
|
|
48
|
-
/**
|
|
49
|
-
An array of snapshots
|
|
50
|
-
@private
|
|
51
|
-
@property _snapshots
|
|
52
|
-
@type {Array}
|
|
53
|
-
*/
|
|
54
|
-
this._snapshots = null;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
An array of records
|
|
58
|
-
@private
|
|
59
|
-
@property _recordArray
|
|
60
|
-
@type {Array}
|
|
61
|
-
*/
|
|
62
|
-
this._recordArray = recordArray;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
Number of records in the array
|
|
66
|
-
|
|
67
|
-
Example
|
|
68
|
-
|
|
69
|
-
```app/adapters/post.js
|
|
70
|
-
import JSONAPIAdapter from '@ember-data/adapter/json-api';
|
|
71
|
-
|
|
72
|
-
export default class PostAdapter extends JSONAPIAdapter {
|
|
73
|
-
shouldReloadAll(store, snapshotRecordArray) {
|
|
74
|
-
return !snapshotRecordArray.length;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
@property length
|
|
80
|
-
@public
|
|
81
|
-
@type {Number}
|
|
82
|
-
*/
|
|
83
|
-
this.length = recordArray.length as unknown as number; // deal with computedProperty shennanigans
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
A hash of adapter options passed into the store method for this request.
|
|
87
|
-
|
|
88
|
-
Example
|
|
89
|
-
|
|
90
|
-
```app/adapters/post.js
|
|
91
|
-
import MyCustomAdapter from './custom-adapter';
|
|
92
|
-
|
|
93
|
-
export default class PostAdapter extends MyCustomAdapter {
|
|
94
|
-
findAll(store, type, sinceToken, snapshotRecordArray) {
|
|
95
|
-
if (snapshotRecordArray.adapterOptions.subscribe) {
|
|
96
|
-
// ...
|
|
97
|
-
}
|
|
98
|
-
// ...
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
@property adapterOptions
|
|
104
|
-
@public
|
|
105
|
-
@type {Object}
|
|
106
|
-
*/
|
|
107
|
-
this.adapterOptions = options.adapterOptions;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
The relationships to include for this request.
|
|
111
|
-
|
|
112
|
-
Example
|
|
113
|
-
|
|
114
|
-
```app/adapters/application.js
|
|
115
|
-
import Adapter from '@ember-data/adapter';
|
|
116
|
-
|
|
117
|
-
export default class ApplicationAdapter extends Adapter {
|
|
118
|
-
findAll(store, type, snapshotRecordArray) {
|
|
119
|
-
let url = `/${type.modelName}?include=${encodeURIComponent(snapshotRecordArray.include)}`;
|
|
120
|
-
|
|
121
|
-
return fetch(url).then((response) => response.json())
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
@property include
|
|
127
|
-
@public
|
|
128
|
-
@type {String|Array}
|
|
129
|
-
*/
|
|
130
|
-
this.include = options.include;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
The type of the underlying records for the snapshots in the array, as a Model
|
|
135
|
-
@property type
|
|
136
|
-
@deprecated
|
|
137
|
-
@public
|
|
138
|
-
@type {Model}
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
The modelName of the underlying records for the snapshots in the array, as a Model
|
|
143
|
-
@property modelName
|
|
144
|
-
@public
|
|
145
|
-
@type {Model}
|
|
146
|
-
*/
|
|
147
|
-
get modelName() {
|
|
148
|
-
return this._recordArray.modelName;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
Get snapshots of the underlying record array
|
|
153
|
-
|
|
154
|
-
Example
|
|
155
|
-
|
|
156
|
-
```app/adapters/post.js
|
|
157
|
-
import JSONAPIAdapter from '@ember-data/adapter/json-api';
|
|
158
|
-
|
|
159
|
-
export default class PostAdapter extends JSONAPIAdapter {
|
|
160
|
-
shouldReloadAll(store, snapshotArray) {
|
|
161
|
-
let snapshots = snapshotArray.snapshots();
|
|
162
|
-
|
|
163
|
-
return snapshots.any(function(ticketSnapshot) {
|
|
164
|
-
let timeDiff = moment().diff(ticketSnapshot.attr('lastAccessedAt'), 'minutes');
|
|
165
|
-
if (timeDiff > 20) {
|
|
166
|
-
return true;
|
|
167
|
-
} else {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
@method snapshots
|
|
176
|
-
@public
|
|
177
|
-
@return {Array} Array of snapshots
|
|
178
|
-
*/
|
|
179
|
-
snapshots() {
|
|
180
|
-
if (this._snapshots !== null) {
|
|
181
|
-
return this._snapshots;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const { _instanceCache } = this.__store;
|
|
185
|
-
this._snapshots = this._recordArray[SOURCE].map((identifier: StableRecordIdentifier) =>
|
|
186
|
-
_instanceCache.createSnapshot(identifier)
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
return this._snapshots;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS) {
|
|
194
|
-
Object.defineProperty(SnapshotRecordArray.prototype, 'type', {
|
|
195
|
-
get() {
|
|
196
|
-
deprecate(
|
|
197
|
-
`Using SnapshotRecordArray.type to access the ModelClass for a record is deprecated. Use store.modelFor(<modelName>) instead.`,
|
|
198
|
-
false,
|
|
199
|
-
{
|
|
200
|
-
id: 'ember-data:deprecate-snapshot-model-class-access',
|
|
201
|
-
until: '5.0',
|
|
202
|
-
for: 'ember-data',
|
|
203
|
-
since: { available: '4.5.0', enabled: '4.5.0' },
|
|
204
|
-
}
|
|
205
|
-
);
|
|
206
|
-
return this._recordArray.type;
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
}
|