@ember-data/store 4.8.0-alpha.2 → 4.8.0-alpha.3
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/-debug/index.js +1 -1
- package/addon/-private/{identifier-cache.ts → caches/identifier-cache.ts} +83 -8
- package/addon/-private/caches/instance-cache.ts +759 -0
- package/addon/-private/{record-data-for.ts → caches/record-data-for.ts} +2 -2
- package/addon/-private/index.ts +12 -15
- package/addon/-private/{model → legacy-model-support}/record-reference.ts +3 -3
- package/addon/-private/{schema-definition-service.ts → legacy-model-support/schema-definition-service.ts} +4 -5
- package/addon/-private/{model → legacy-model-support}/shim-model-class.ts +2 -2
- package/addon/-private/{record-array-manager.ts → managers/record-array-manager.ts} +16 -44
- package/addon/-private/{record-data-store-wrapper.ts → managers/record-data-store-wrapper.ts} +34 -56
- package/addon/-private/managers/record-notification-manager.ts +96 -0
- package/addon/-private/{fetch-manager.ts → network/fetch-manager.ts} +18 -16
- package/addon/-private/{finders.js → network/finders.js} +4 -12
- package/addon/-private/{request-cache.ts → network/request-cache.ts} +0 -0
- package/addon/-private/{snapshot-record-array.ts → network/snapshot-record-array.ts} +3 -3
- package/addon/-private/{snapshot.ts → network/snapshot.ts} +24 -31
- package/addon/-private/{promise-proxies.ts → proxies/promise-proxies.ts} +4 -4
- package/addon/-private/{promise-proxy-base.js → proxies/promise-proxy-base.js} +0 -0
- package/addon/-private/record-arrays/adapter-populated-record-array.ts +9 -11
- package/addon/-private/record-arrays/record-array.ts +16 -14
- package/addon/-private/{core-store.ts → store-service.ts} +186 -127
- package/addon/-private/{coerce-id.ts → utils/coerce-id.ts} +1 -1
- package/addon/-private/{common.js → utils/common.js} +1 -2
- package/addon/-private/utils/construct-resource.ts +2 -2
- package/addon/-private/{identifer-debug-consts.ts → utils/identifer-debug-consts.ts} +0 -0
- package/addon/-private/{normalize-model-name.ts → utils/normalize-model-name.ts} +0 -0
- package/addon/-private/utils/promise-record.ts +3 -3
- package/addon/-private/{serializer-response.ts → utils/serializer-response.ts} +2 -2
- package/addon/-private/{weak-cache.ts → utils/weak-cache.ts} +0 -0
- package/package.json +5 -5
- package/addon/-private/identity-map.ts +0 -54
- package/addon/-private/instance-cache.ts +0 -387
- package/addon/-private/internal-model-factory.ts +0 -359
- package/addon/-private/internal-model-map.ts +0 -121
- package/addon/-private/model/internal-model.ts +0 -600
- package/addon/-private/record-notification-manager.ts +0 -73
package/addon/-debug/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { DEBUG } from '@glimmer/env';
|
|
|
9
9
|
relationship (specified via `relationshipMeta`) of the `record`.
|
|
10
10
|
|
|
11
11
|
This utility should only be used internally, as both record parameters must
|
|
12
|
-
be
|
|
12
|
+
be stable record identifiers and the `relationshipMeta` needs to be the meta
|
|
13
13
|
information about the relationship, retrieved via
|
|
14
14
|
`record.relationshipFor(key)`.
|
|
15
15
|
*/
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { assert, warn } from '@ember/debug';
|
|
5
5
|
import { DEBUG } from '@glimmer/env';
|
|
6
6
|
|
|
7
|
+
import { LOG_IDENTIFIERS } from '@ember-data/private-build-infra/debugging';
|
|
7
8
|
import type { ExistingResourceObject, ResourceIdentifierObject } from '@ember-data/types/q/ember-data-json-api';
|
|
8
9
|
import type {
|
|
9
10
|
ForgetMethod,
|
|
@@ -18,11 +19,11 @@ import type {
|
|
|
18
19
|
} from '@ember-data/types/q/identifier';
|
|
19
20
|
import type { ConfidentDict } from '@ember-data/types/q/utils';
|
|
20
21
|
|
|
21
|
-
import coerceId from '
|
|
22
|
-
import { DEBUG_CLIENT_ORIGINATED, DEBUG_IDENTIFIER_BUCKET } from '
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import WeakCache from '
|
|
22
|
+
import coerceId from '../utils/coerce-id';
|
|
23
|
+
import { DEBUG_CLIENT_ORIGINATED, DEBUG_IDENTIFIER_BUCKET } from '../utils/identifer-debug-consts';
|
|
24
|
+
import isNonEmptyString from '../utils/is-non-empty-string';
|
|
25
|
+
import normalizeModelName from '../utils/normalize-model-name';
|
|
26
|
+
import WeakCache from '../utils/weak-cache';
|
|
26
27
|
|
|
27
28
|
const IDENTIFIERS = new WeakSet();
|
|
28
29
|
|
|
@@ -141,8 +142,8 @@ export class IdentifierCache {
|
|
|
141
142
|
/**
|
|
142
143
|
* Internal hook to allow management of merge conflicts with identifiers.
|
|
143
144
|
*
|
|
144
|
-
* we allow late binding of this private internal merge so that
|
|
145
|
-
* can insert itself here to handle elimination of duplicates
|
|
145
|
+
* we allow late binding of this private internal merge so that
|
|
146
|
+
* the cache can insert itself here to handle elimination of duplicates
|
|
146
147
|
*
|
|
147
148
|
* @method __configureMerge
|
|
148
149
|
* @private
|
|
@@ -172,6 +173,10 @@ export class IdentifierCache {
|
|
|
172
173
|
throw new Error(`The supplied identifier ${resource} does not belong to this store instance`);
|
|
173
174
|
}
|
|
174
175
|
}
|
|
176
|
+
if (LOG_IDENTIFIERS) {
|
|
177
|
+
// eslint-disable-next-line no-console
|
|
178
|
+
console.log(`Identifiers: Peeked Identifier was already Stable ${String(resource)}`);
|
|
179
|
+
}
|
|
175
180
|
return resource;
|
|
176
181
|
}
|
|
177
182
|
|
|
@@ -179,9 +184,18 @@ export class IdentifierCache {
|
|
|
179
184
|
let identifier: StableRecordIdentifier | undefined = lid !== null ? this._cache.lids[lid] : undefined;
|
|
180
185
|
|
|
181
186
|
if (identifier !== undefined) {
|
|
187
|
+
if (LOG_IDENTIFIERS) {
|
|
188
|
+
// eslint-disable-next-line no-console
|
|
189
|
+
console.log(`Identifiers: cache HIT ${identifier}`, resource);
|
|
190
|
+
}
|
|
182
191
|
return identifier;
|
|
183
192
|
}
|
|
184
193
|
|
|
194
|
+
if (LOG_IDENTIFIERS) {
|
|
195
|
+
// eslint-disable-next-line no-console
|
|
196
|
+
console.groupCollapsed(`Identifiers: ${shouldGenerate ? 'Generating' : 'Peeking'} Identifier`, resource);
|
|
197
|
+
}
|
|
198
|
+
|
|
185
199
|
if (shouldGenerate === false) {
|
|
186
200
|
if (!('type' in resource) || !('id' in resource) || !resource.type || !resource.id) {
|
|
187
201
|
return;
|
|
@@ -211,6 +225,10 @@ export class IdentifierCache {
|
|
|
211
225
|
// we have definitely not seen this resource before
|
|
212
226
|
// so we allow the user configured `GenerationMethod` to tell us
|
|
213
227
|
let newLid = this._generate(resource, 'record');
|
|
228
|
+
if (LOG_IDENTIFIERS) {
|
|
229
|
+
// eslint-disable-next-line no-console
|
|
230
|
+
console.log(`Identifiers: lid ${newLid} determined for resource`, resource);
|
|
231
|
+
}
|
|
214
232
|
|
|
215
233
|
// we do this _even_ when `lid` is present because secondary lookups
|
|
216
234
|
// may need to be populated, but we enforce not giving us something
|
|
@@ -247,6 +265,17 @@ export class IdentifierCache {
|
|
|
247
265
|
// TODO exists temporarily to support `peekAll`
|
|
248
266
|
// but likely to move
|
|
249
267
|
keyOptions._allIdentifiers.push(identifier);
|
|
268
|
+
|
|
269
|
+
if (LOG_IDENTIFIERS && shouldGenerate) {
|
|
270
|
+
// eslint-disable-next-line no-console
|
|
271
|
+
console.log(`Identifiers: generated ${String(identifier)} for`, resource);
|
|
272
|
+
if (resource[DEBUG_IDENTIFIER_BUCKET]) {
|
|
273
|
+
// eslint-disable-next-line no-console
|
|
274
|
+
console.trace(
|
|
275
|
+
`[WARNING] Identifiers: generated a new identifier from a previously used identifier. This is likely a bug.`
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
250
279
|
}
|
|
251
280
|
|
|
252
281
|
// populate our own secondary lookup table
|
|
@@ -266,6 +295,15 @@ export class IdentifierCache {
|
|
|
266
295
|
}
|
|
267
296
|
}
|
|
268
297
|
|
|
298
|
+
if (LOG_IDENTIFIERS) {
|
|
299
|
+
if (!identifier && !shouldGenerate) {
|
|
300
|
+
// eslint-disable-next-line no-console
|
|
301
|
+
console.log(`Identifiers: cache MISS`, resource);
|
|
302
|
+
}
|
|
303
|
+
// eslint-disable-next-line no-console
|
|
304
|
+
console.groupEnd();
|
|
305
|
+
}
|
|
306
|
+
|
|
269
307
|
return identifier;
|
|
270
308
|
}
|
|
271
309
|
|
|
@@ -334,6 +372,11 @@ export class IdentifierCache {
|
|
|
334
372
|
// TODO move this outta here?
|
|
335
373
|
keyOptions._allIdentifiers.push(identifier);
|
|
336
374
|
|
|
375
|
+
if (LOG_IDENTIFIERS) {
|
|
376
|
+
// eslint-disable-next-line no-console
|
|
377
|
+
console.log(`Identifiers: createded identifier ${String(identifier)} for newly generated resource`, data);
|
|
378
|
+
}
|
|
379
|
+
|
|
337
380
|
return identifier;
|
|
338
381
|
}
|
|
339
382
|
|
|
@@ -378,7 +421,21 @@ export class IdentifierCache {
|
|
|
378
421
|
|
|
379
422
|
if (existingIdentifier) {
|
|
380
423
|
let keyOptions = getTypeIndex(this._cache.types, identifier.type);
|
|
381
|
-
|
|
424
|
+
let generatedIdentifier = identifier;
|
|
425
|
+
identifier = this._mergeRecordIdentifiers(
|
|
426
|
+
keyOptions,
|
|
427
|
+
generatedIdentifier,
|
|
428
|
+
existingIdentifier,
|
|
429
|
+
data,
|
|
430
|
+
newId as string
|
|
431
|
+
);
|
|
432
|
+
if (LOG_IDENTIFIERS) {
|
|
433
|
+
// eslint-disable-next-line no-console
|
|
434
|
+
console.log(
|
|
435
|
+
`Identifiers: merged identifiers ${generatedIdentifier.lid} and ${existingIdentifier.lid} for resource into ${identifier.lid}`,
|
|
436
|
+
data
|
|
437
|
+
);
|
|
438
|
+
}
|
|
382
439
|
}
|
|
383
440
|
|
|
384
441
|
let id = identifier.id;
|
|
@@ -387,12 +444,22 @@ export class IdentifierCache {
|
|
|
387
444
|
|
|
388
445
|
// add to our own secondary lookup table
|
|
389
446
|
if (id !== newId && newId !== null) {
|
|
447
|
+
if (LOG_IDENTIFIERS) {
|
|
448
|
+
// eslint-disable-next-line no-console
|
|
449
|
+
console.log(
|
|
450
|
+
`Identifiers: updated id for identifier ${identifier.lid} from '${id}' to '${newId}' for resource`,
|
|
451
|
+
data
|
|
452
|
+
);
|
|
453
|
+
}
|
|
390
454
|
let keyOptions = getTypeIndex(this._cache.types, identifier.type);
|
|
391
455
|
keyOptions.id[newId] = identifier;
|
|
392
456
|
|
|
393
457
|
if (id !== null) {
|
|
394
458
|
delete keyOptions.id[id];
|
|
395
459
|
}
|
|
460
|
+
} else if (LOG_IDENTIFIERS) {
|
|
461
|
+
// eslint-disable-next-line no-console
|
|
462
|
+
console.log(`Identifiers: updated identifier ${identifier.lid} resource`, data);
|
|
396
463
|
}
|
|
397
464
|
|
|
398
465
|
return identifier;
|
|
@@ -454,6 +521,10 @@ export class IdentifierCache {
|
|
|
454
521
|
|
|
455
522
|
IDENTIFIERS.delete(identifierObject);
|
|
456
523
|
this._forget(identifier, 'record');
|
|
524
|
+
if (LOG_IDENTIFIERS) {
|
|
525
|
+
// eslint-disable-next-line no-console
|
|
526
|
+
console.log(`Identifiers: released identifier ${identifierObject.lid}`);
|
|
527
|
+
}
|
|
457
528
|
}
|
|
458
529
|
|
|
459
530
|
destroy() {
|
|
@@ -507,6 +578,10 @@ function makeStableRecordIdentifier(
|
|
|
507
578
|
let { type, id, lid } = recordIdentifier;
|
|
508
579
|
return `${clientOriginated ? '[CLIENT_ORIGINATED] ' : ''}${type}:${id} (${lid})`;
|
|
509
580
|
},
|
|
581
|
+
toJSON() {
|
|
582
|
+
let { type, id, lid } = recordIdentifier;
|
|
583
|
+
return { type, id, lid };
|
|
584
|
+
},
|
|
510
585
|
};
|
|
511
586
|
wrapper[DEBUG_CLIENT_ORIGINATED] = clientOriginated;
|
|
512
587
|
wrapper[DEBUG_IDENTIFIER_BUCKET] = bucket;
|