@ember-data-mirror/store 4.13.0-alpha.3 → 4.13.0-alpha.5
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/LICENSE.md +19 -7
- package/README.md +5 -8
- package/dist/{-private-Cy8UqsrK.js → -private-ki-omnNZ.js} +986 -294
- package/dist/-private-ki-omnNZ.js.map +1 -0
- package/dist/-private.js +1 -1
- package/dist/index.js +1 -1
- package/logos/NCC-1701-a-blue.svg +4 -0
- package/logos/NCC-1701-a-gold.svg +4 -0
- package/logos/NCC-1701-a-gold_100.svg +1 -0
- package/logos/NCC-1701-a-gold_base-64.txt +1 -0
- package/logos/NCC-1701-a.svg +4 -0
- package/logos/README.md +4 -0
- package/logos/docs-badge.svg +2 -0
- package/logos/ember-data-logo-dark.svg +12 -0
- package/logos/ember-data-logo-light.svg +12 -0
- package/logos/github-header.svg +444 -0
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +4 -0
- package/logos/warp-drive-logo-gold.svg +4 -0
- package/package.json +32 -42
- package/unstable-preview-types/-private/cache-handler/handler.d.ts +0 -2
- package/unstable-preview-types/-private/cache-handler/handler.d.ts.map +1 -1
- package/unstable-preview-types/-private/caches/identifier-cache.d.ts.map +1 -1
- package/unstable-preview-types/-private/caches/instance-cache.d.ts.map +1 -1
- package/unstable-preview-types/-private/debug/utils.d.ts +9 -0
- package/unstable-preview-types/-private/debug/utils.d.ts.map +1 -0
- package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts +3 -3
- package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts.map +1 -1
- package/unstable-preview-types/-private/managers/cache-manager.d.ts +22 -0
- package/unstable-preview-types/-private/managers/cache-manager.d.ts.map +1 -1
- package/unstable-preview-types/-private/managers/notification-manager.d.ts +3 -2
- package/unstable-preview-types/-private/managers/notification-manager.d.ts.map +1 -1
- package/unstable-preview-types/-private/managers/record-array-manager.d.ts +2 -0
- package/unstable-preview-types/-private/managers/record-array-manager.d.ts.map +1 -1
- package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts +11 -1
- package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts.map +1 -1
- package/unstable-preview-types/-private/record-arrays/many-array.d.ts +199 -0
- package/unstable-preview-types/-private/record-arrays/many-array.d.ts.map +1 -0
- package/unstable-preview-types/-private/store-service.d.ts +64 -9
- package/unstable-preview-types/-private/store-service.d.ts.map +1 -1
- package/unstable-preview-types/-private.d.ts +2 -0
- package/unstable-preview-types/-private.d.ts.map +1 -1
- package/unstable-preview-types/-types/q/cache-capabilities-manager.d.ts +4 -4
- package/unstable-preview-types/-types/q/cache-capabilities-manager.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +24 -25
- package/unstable-preview-types/index.d.ts.map +1 -1
- package/dist/-private-Cy8UqsrK.js.map +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { deprecate, warn, assert } from '@ember/debug';
|
|
2
2
|
import { dasherize } from '@ember-data-mirror/request-utils/string';
|
|
3
3
|
import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { setLogging, getRuntimeConfig } from '@warp-drive-mirror/build-config/runtime';
|
|
5
|
+
import { EnableHydration, SkipCache } from '@warp-drive-mirror/core-types/request';
|
|
6
|
+
import { getOrSetGlobal, peekTransient, setTransient } from '@warp-drive-mirror/core-types/-private';
|
|
6
7
|
import { CACHE_OWNER, DEBUG_STALE_CACHE_OWNER, DEBUG_CLIENT_ORIGINATED, DEBUG_IDENTIFIER_BUCKET } from '@warp-drive-mirror/core-types/identifier';
|
|
7
8
|
import { defineSignal, createSignal, subscribe, createArrayTags, addToTransaction, addTransactionCB } from '@ember-data-mirror/tracking/-private';
|
|
8
9
|
import { _backburner } from '@ember/runloop';
|
|
@@ -15,9 +16,9 @@ import { reads } from '@ember/object/computed';
|
|
|
15
16
|
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
|
|
16
17
|
import ObjectProxy from '@ember/object/proxy';
|
|
17
18
|
function normalizeModelName$1(type) {
|
|
18
|
-
if (macroCondition(getGlobalConfig().
|
|
19
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_NON_STRICT_TYPES)) {
|
|
19
20
|
const result = dasherize(type);
|
|
20
|
-
deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, /* inline-macro-config */getGlobalConfig().
|
|
21
|
+
deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, /* inline-macro-config */getGlobalConfig().WarpDriveMirror.deprecations.DISABLE_6X_DEPRECATIONS ? true : result === type, {
|
|
21
22
|
id: 'ember-data-mirror:deprecate-non-strict-types',
|
|
22
23
|
until: '6.0',
|
|
23
24
|
for: 'ember-data-mirror',
|
|
@@ -36,14 +37,14 @@ function normalizeModelName$1(type) {
|
|
|
36
37
|
*/
|
|
37
38
|
|
|
38
39
|
function coerceId(id) {
|
|
39
|
-
if (macroCondition(getGlobalConfig().
|
|
40
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_NON_STRICT_ID)) {
|
|
40
41
|
let normalized;
|
|
41
42
|
if (id === null || id === undefined || id === '') {
|
|
42
43
|
normalized = null;
|
|
43
44
|
} else {
|
|
44
45
|
normalized = String(id);
|
|
45
46
|
}
|
|
46
|
-
deprecate(`The resource id '<${typeof id}> ${String(id)} ' is not normalized. Update your application code to use '${JSON.stringify(normalized)}' instead.`, /* inline-macro-config */getGlobalConfig().
|
|
47
|
+
deprecate(`The resource id '<${typeof id}> ${String(id)} ' is not normalized. Update your application code to use '${JSON.stringify(normalized)}' instead.`, /* inline-macro-config */getGlobalConfig().WarpDriveMirror.deprecations.DISABLE_6X_DEPRECATIONS ? true : normalized === id, {
|
|
47
48
|
id: 'ember-data-mirror:deprecate-non-strict-id',
|
|
48
49
|
until: '6.0',
|
|
49
50
|
for: 'ember-data-mirror',
|
|
@@ -54,7 +55,7 @@ function coerceId(id) {
|
|
|
54
55
|
});
|
|
55
56
|
return normalized;
|
|
56
57
|
}
|
|
57
|
-
macroCondition(getGlobalConfig().
|
|
58
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
58
59
|
if (!test) {
|
|
59
60
|
throw new Error(`Resource IDs must be a non-empty string or null. Received '${String(id)}'.`);
|
|
60
61
|
}
|
|
@@ -68,7 +69,7 @@ function ensureStringId(id) {
|
|
|
68
69
|
} else if (typeof id === 'number' && !isNaN(id)) {
|
|
69
70
|
normalized = String(id);
|
|
70
71
|
}
|
|
71
|
-
macroCondition(getGlobalConfig().
|
|
72
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
72
73
|
if (!test) {
|
|
73
74
|
throw new Error(`Expected id to be a string or number, received ${String(id)}`);
|
|
74
75
|
}
|
|
@@ -136,21 +137,20 @@ function hasType(resource) {
|
|
|
136
137
|
/**
|
|
137
138
|
@module @ember-data-mirror/store
|
|
138
139
|
*/
|
|
139
|
-
const IDENTIFIERS = getOrSetGlobal('IDENTIFIERS', new Set());
|
|
140
140
|
const DOCUMENTS = getOrSetGlobal('DOCUMENTS', new Set());
|
|
141
141
|
function isStableIdentifier(identifier) {
|
|
142
|
-
return identifier[CACHE_OWNER] !== undefined
|
|
142
|
+
return identifier[CACHE_OWNER] !== undefined;
|
|
143
143
|
}
|
|
144
144
|
function isDocumentIdentifier(identifier) {
|
|
145
145
|
return DOCUMENTS.has(identifier);
|
|
146
146
|
}
|
|
147
147
|
const isFastBoot = typeof FastBoot !== 'undefined';
|
|
148
148
|
const _crypto = isFastBoot ? FastBoot.require('crypto') : globalThis.crypto;
|
|
149
|
-
if (macroCondition(getGlobalConfig().
|
|
149
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.polyfillUUID)) {
|
|
150
150
|
installPolyfill();
|
|
151
151
|
}
|
|
152
152
|
function uuidv4() {
|
|
153
|
-
macroCondition(getGlobalConfig().
|
|
153
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
154
154
|
if (!test) {
|
|
155
155
|
throw new Error('crypto.randomUUID needs to be avaliable. Some browsers incorrectly disallow it in insecure contexts. You maybe want to enable the polyfill: https://github.com/emberjs/data#randomuuid-polyfill');
|
|
156
156
|
}
|
|
@@ -199,7 +199,7 @@ function updateTypeIdMapping(typeMap, identifier, id) {
|
|
|
199
199
|
}
|
|
200
200
|
function defaultUpdateMethod(identifier, data, bucket) {
|
|
201
201
|
if (bucket === 'record') {
|
|
202
|
-
macroCondition(getGlobalConfig().
|
|
202
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
203
203
|
if (!test) {
|
|
204
204
|
throw new Error(`Expected identifier to be a StableRecordIdentifier`);
|
|
205
205
|
}
|
|
@@ -213,7 +213,7 @@ function defaultKeyInfoMethod(resource, known) {
|
|
|
213
213
|
// TODO RFC something to make this configurable
|
|
214
214
|
const id = hasId(resource) ? coerceId(resource.id) : null;
|
|
215
215
|
const type = hasType(resource) ? normalizeModelName$1(resource.type) : known ? known.type : null;
|
|
216
|
-
macroCondition(getGlobalConfig().
|
|
216
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
217
217
|
if (!test) {
|
|
218
218
|
throw new Error(`Expected keyInfoForResource to provide a type for the resource`);
|
|
219
219
|
}
|
|
@@ -228,7 +228,7 @@ function defaultGenerationMethod(data, bucket) {
|
|
|
228
228
|
if (hasLid(data)) {
|
|
229
229
|
return data.lid;
|
|
230
230
|
}
|
|
231
|
-
macroCondition(getGlobalConfig().
|
|
231
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
232
232
|
if (!test) {
|
|
233
233
|
throw new Error(`Cannot generate an identifier for a resource without a type`);
|
|
234
234
|
}
|
|
@@ -248,7 +248,7 @@ function defaultGenerationMethod(data, bucket) {
|
|
|
248
248
|
}
|
|
249
249
|
return null;
|
|
250
250
|
}
|
|
251
|
-
macroCondition(getGlobalConfig().
|
|
251
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
252
252
|
{
|
|
253
253
|
throw new Error(`Unknown bucket ${bucket}`);
|
|
254
254
|
}
|
|
@@ -259,7 +259,7 @@ function defaultMergeMethod(a, _b, _c) {
|
|
|
259
259
|
return a;
|
|
260
260
|
}
|
|
261
261
|
let DEBUG_MAP;
|
|
262
|
-
if (macroCondition(getGlobalConfig().
|
|
262
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
263
263
|
DEBUG_MAP = getOrSetGlobal('DEBUG_MAP', new WeakMap());
|
|
264
264
|
}
|
|
265
265
|
|
|
@@ -317,45 +317,55 @@ class IdentifierCache {
|
|
|
317
317
|
*/
|
|
318
318
|
|
|
319
319
|
_getRecordIdentifier(resource, shouldGenerate) {
|
|
320
|
-
if (macroCondition(getGlobalConfig().
|
|
321
|
-
|
|
322
|
-
|
|
320
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
321
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
322
|
+
// eslint-disable-next-line no-console
|
|
323
|
+
console.groupCollapsed(`Identifiers: ${shouldGenerate ? 'Generating' : 'Peeking'} Identifier`, resource);
|
|
324
|
+
}
|
|
323
325
|
}
|
|
324
326
|
// short circuit if we're already the stable version
|
|
325
327
|
if (isStableIdentifier(resource)) {
|
|
326
|
-
if (macroCondition(getGlobalConfig().
|
|
328
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
327
329
|
// TODO should we instead just treat this case as a new generation skipping the short circuit?
|
|
328
330
|
if (!this._cache.resources.has(resource.lid) || this._cache.resources.get(resource.lid) !== resource) {
|
|
329
331
|
throw new Error(`The supplied identifier ${JSON.stringify(resource)} does not belong to this store instance`);
|
|
330
332
|
}
|
|
331
333
|
}
|
|
332
|
-
if (macroCondition(getGlobalConfig().
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
334
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
335
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
336
|
+
// eslint-disable-next-line no-console
|
|
337
|
+
console.log(`Identifiers: cache HIT - Stable ${resource.lid}`);
|
|
338
|
+
// eslint-disable-next-line no-console
|
|
339
|
+
console.groupEnd();
|
|
340
|
+
}
|
|
337
341
|
}
|
|
338
342
|
return resource;
|
|
339
343
|
}
|
|
340
344
|
|
|
341
345
|
// the resource is unknown, ask the application to identify this data for us
|
|
342
346
|
const lid = this._generate(resource, 'record');
|
|
343
|
-
if (macroCondition(getGlobalConfig().
|
|
344
|
-
|
|
345
|
-
|
|
347
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
348
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
349
|
+
// eslint-disable-next-line no-console
|
|
350
|
+
console.log(`Identifiers: ${lid ? 'no ' : ''}lid ${lid ? lid + ' ' : ''}determined for resource`, resource);
|
|
351
|
+
}
|
|
346
352
|
}
|
|
347
353
|
let identifier = /*#__NOINLINE__*/getIdentifierFromLid(this._cache, lid, resource);
|
|
348
354
|
if (identifier !== null) {
|
|
349
|
-
if (macroCondition(getGlobalConfig().
|
|
350
|
-
|
|
351
|
-
|
|
355
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
356
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
357
|
+
// eslint-disable-next-line no-console
|
|
358
|
+
console.groupEnd();
|
|
359
|
+
}
|
|
352
360
|
}
|
|
353
361
|
return identifier;
|
|
354
362
|
}
|
|
355
363
|
if (shouldGenerate === 0) {
|
|
356
|
-
if (macroCondition(getGlobalConfig().
|
|
357
|
-
|
|
358
|
-
|
|
364
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
365
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
366
|
+
// eslint-disable-next-line no-console
|
|
367
|
+
console.groupEnd();
|
|
368
|
+
}
|
|
359
369
|
}
|
|
360
370
|
return;
|
|
361
371
|
}
|
|
@@ -373,9 +383,11 @@ class IdentifierCache {
|
|
|
373
383
|
identifier = /*#__NOINLINE__*/makeStableRecordIdentifier(keyInfo, 'record', false);
|
|
374
384
|
}
|
|
375
385
|
addResourceToCache(this._cache, identifier);
|
|
376
|
-
if (macroCondition(getGlobalConfig().
|
|
377
|
-
|
|
378
|
-
|
|
386
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
387
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
388
|
+
// eslint-disable-next-line no-console
|
|
389
|
+
console.groupEnd();
|
|
390
|
+
}
|
|
379
391
|
}
|
|
380
392
|
return identifier;
|
|
381
393
|
}
|
|
@@ -415,7 +427,7 @@ class IdentifierCache {
|
|
|
415
427
|
identifier = {
|
|
416
428
|
lid: cacheKey
|
|
417
429
|
};
|
|
418
|
-
if (macroCondition(getGlobalConfig().
|
|
430
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
419
431
|
Object.freeze(identifier);
|
|
420
432
|
}
|
|
421
433
|
DOCUMENTS.add(identifier);
|
|
@@ -461,7 +473,7 @@ class IdentifierCache {
|
|
|
461
473
|
}, 'record', true);
|
|
462
474
|
|
|
463
475
|
// populate our unique table
|
|
464
|
-
if (macroCondition(getGlobalConfig().
|
|
476
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
465
477
|
if (this._cache.resources.has(identifier.lid)) {
|
|
466
478
|
throw new Error(`The lid generated for the new record is not unique as it matches an existing identifier`);
|
|
467
479
|
}
|
|
@@ -469,9 +481,11 @@ class IdentifierCache {
|
|
|
469
481
|
|
|
470
482
|
/*#__NOINLINE__*/
|
|
471
483
|
addResourceToCache(this._cache, identifier);
|
|
472
|
-
if (macroCondition(getGlobalConfig().
|
|
473
|
-
|
|
474
|
-
|
|
484
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
485
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
486
|
+
// eslint-disable-next-line no-console
|
|
487
|
+
console.log(`Identifiers: created identifier ${String(identifier)} for newly generated resource`, data);
|
|
488
|
+
}
|
|
475
489
|
}
|
|
476
490
|
return identifier;
|
|
477
491
|
}
|
|
@@ -518,9 +532,11 @@ class IdentifierCache {
|
|
|
518
532
|
if (hadLid) {
|
|
519
533
|
data.lid = identifier.lid;
|
|
520
534
|
}
|
|
521
|
-
if (macroCondition(getGlobalConfig().
|
|
522
|
-
|
|
523
|
-
|
|
535
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
536
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
537
|
+
// eslint-disable-next-line no-console
|
|
538
|
+
console.log(`Identifiers: merged identifiers ${generatedIdentifier.lid} and ${existingIdentifier.lid} for resource into ${identifier.lid}`, data);
|
|
539
|
+
}
|
|
524
540
|
}
|
|
525
541
|
}
|
|
526
542
|
const id = identifier.id;
|
|
@@ -530,12 +546,14 @@ class IdentifierCache {
|
|
|
530
546
|
|
|
531
547
|
// add to our own secondary lookup table
|
|
532
548
|
if (id !== newId && newId !== null) {
|
|
533
|
-
if (macroCondition(getGlobalConfig().
|
|
534
|
-
|
|
535
|
-
|
|
549
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
550
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
551
|
+
// eslint-disable-next-line no-console
|
|
552
|
+
console.log(`Identifiers: updated id for identifier ${identifier.lid} from '${String(id)}' to '${String(newId)}' for resource`, data);
|
|
553
|
+
}
|
|
536
554
|
}
|
|
537
555
|
const typeSet = this._cache.resourcesByType[identifier.type];
|
|
538
|
-
macroCondition(getGlobalConfig().
|
|
556
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
539
557
|
if (!test) {
|
|
540
558
|
throw new Error(`Expected to find a typeSet for ${identifier.type}`);
|
|
541
559
|
}
|
|
@@ -544,9 +562,11 @@ class IdentifierCache {
|
|
|
544
562
|
if (id !== null) {
|
|
545
563
|
typeSet.id.delete(id);
|
|
546
564
|
}
|
|
547
|
-
} else if (macroCondition(getGlobalConfig().
|
|
548
|
-
|
|
549
|
-
|
|
565
|
+
} else if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
566
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
567
|
+
// eslint-disable-next-line no-console
|
|
568
|
+
console.log(`Identifiers: updated identifier ${identifier.lid} resource`, data);
|
|
569
|
+
}
|
|
550
570
|
}
|
|
551
571
|
return identifier;
|
|
552
572
|
}
|
|
@@ -556,7 +576,7 @@ class IdentifierCache {
|
|
|
556
576
|
* @private
|
|
557
577
|
*/
|
|
558
578
|
_mergeRecordIdentifiers(keyInfo, identifier, existingIdentifier, data) {
|
|
559
|
-
macroCondition(getGlobalConfig().
|
|
579
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
560
580
|
if (!test) {
|
|
561
581
|
throw new Error(`Expected keyInfo to contain an id`);
|
|
562
582
|
}
|
|
@@ -607,7 +627,7 @@ class IdentifierCache {
|
|
|
607
627
|
forgetRecordIdentifier(identifierObject) {
|
|
608
628
|
const identifier = this.getOrCreateRecordIdentifier(identifierObject);
|
|
609
629
|
const typeSet = this._cache.resourcesByType[identifier.type];
|
|
610
|
-
macroCondition(getGlobalConfig().
|
|
630
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
611
631
|
if (!test) {
|
|
612
632
|
throw new Error(`Expected to find a typeSet for ${identifier.type}`);
|
|
613
633
|
}
|
|
@@ -624,15 +644,16 @@ class IdentifierCache {
|
|
|
624
644
|
});
|
|
625
645
|
this._cache.polymorphicLidBackMap.delete(identifier.lid);
|
|
626
646
|
}
|
|
627
|
-
if (macroCondition(getGlobalConfig().
|
|
647
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
628
648
|
identifier[DEBUG_STALE_CACHE_OWNER] = identifier[CACHE_OWNER];
|
|
629
649
|
}
|
|
630
650
|
identifier[CACHE_OWNER] = undefined;
|
|
631
|
-
IDENTIFIERS.delete(identifier);
|
|
632
651
|
this._forget(identifier, 'record');
|
|
633
|
-
if (macroCondition(getGlobalConfig().
|
|
634
|
-
|
|
635
|
-
|
|
652
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
653
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
654
|
+
// eslint-disable-next-line no-console
|
|
655
|
+
console.log(`Identifiers: released identifier ${identifierObject.lid}`);
|
|
656
|
+
}
|
|
636
657
|
}
|
|
637
658
|
}
|
|
638
659
|
destroy() {
|
|
@@ -644,8 +665,7 @@ class IdentifierCache {
|
|
|
644
665
|
}
|
|
645
666
|
}
|
|
646
667
|
function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated) {
|
|
647
|
-
|
|
648
|
-
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
668
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
649
669
|
// we enforce immutability in dev
|
|
650
670
|
// but preserve our ability to do controlled updates to the reference
|
|
651
671
|
let wrapper = {
|
|
@@ -699,7 +719,6 @@ function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated)
|
|
|
699
719
|
});
|
|
700
720
|
wrapper[DEBUG_CLIENT_ORIGINATED] = clientOriginated;
|
|
701
721
|
wrapper[DEBUG_IDENTIFIER_BUCKET] = bucket;
|
|
702
|
-
IDENTIFIERS.add(wrapper);
|
|
703
722
|
DEBUG_MAP.set(wrapper, recordIdentifier);
|
|
704
723
|
wrapper = freeze(wrapper);
|
|
705
724
|
return wrapper;
|
|
@@ -707,7 +726,7 @@ function makeStableRecordIdentifier(recordIdentifier, bucket, clientOriginated)
|
|
|
707
726
|
return recordIdentifier;
|
|
708
727
|
}
|
|
709
728
|
function performRecordIdentifierUpdate(identifier, keyInfo, data, updateFn) {
|
|
710
|
-
if (macroCondition(getGlobalConfig().
|
|
729
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
711
730
|
const {
|
|
712
731
|
id,
|
|
713
732
|
type
|
|
@@ -782,9 +801,11 @@ function detectMerge(cache, keyInfo, identifier, data) {
|
|
|
782
801
|
}
|
|
783
802
|
function getIdentifierFromLid(cache, lid, resource) {
|
|
784
803
|
const identifier = cache.resources.get(lid);
|
|
785
|
-
if (macroCondition(getGlobalConfig().
|
|
786
|
-
|
|
787
|
-
|
|
804
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_IDENTIFIERS)) {
|
|
805
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_IDENTIFIERS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_IDENTIFIERS) {
|
|
806
|
+
// eslint-disable-next-line no-console
|
|
807
|
+
console.log(`Identifiers: cache ${identifier ? 'HIT' : 'MISS'} - Non-Stable ${lid}`, resource);
|
|
808
|
+
}
|
|
788
809
|
}
|
|
789
810
|
return identifier || null;
|
|
790
811
|
}
|
|
@@ -803,6 +824,87 @@ function addResourceToCache(cache, identifier) {
|
|
|
803
824
|
typeSet.id.set(identifier.id, identifier);
|
|
804
825
|
}
|
|
805
826
|
}
|
|
827
|
+
const TEXT_COLORS = {
|
|
828
|
+
TEXT: 'inherit',
|
|
829
|
+
notify: ['white', 'white', 'inherit', 'magenta', 'inherit'],
|
|
830
|
+
'reactive-ui': ['white', 'white', 'inherit', 'magenta', 'inherit'],
|
|
831
|
+
graph: ['white', 'white', 'inherit', 'magenta', 'inherit'],
|
|
832
|
+
request: ['white', 'white', 'inherit', 'magenta', 'inherit'],
|
|
833
|
+
cache: ['white', 'white', 'inherit', 'magenta', 'inherit']
|
|
834
|
+
};
|
|
835
|
+
const BG_COLORS = {
|
|
836
|
+
TEXT: 'transparent',
|
|
837
|
+
notify: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
|
|
838
|
+
'reactive-ui': ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
|
|
839
|
+
graph: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
|
|
840
|
+
request: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
|
|
841
|
+
cache: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent']
|
|
842
|
+
};
|
|
843
|
+
const NOTIFY_BORDER = {
|
|
844
|
+
TEXT: 0,
|
|
845
|
+
notify: [3, 2, 0, 0, 0],
|
|
846
|
+
'reactive-ui': [3, 2, 0, 0, 0],
|
|
847
|
+
graph: [3, 2, 0, 0, 0],
|
|
848
|
+
request: [3, 2, 0, 0, 0],
|
|
849
|
+
cache: [3, 2, 0, 0, 0]
|
|
850
|
+
};
|
|
851
|
+
const LIGHT_DARK_ALT = {
|
|
852
|
+
lightgreen: 'green',
|
|
853
|
+
green: 'lightgreen'
|
|
854
|
+
};
|
|
855
|
+
function badge(isLight, color, bgColor, border) {
|
|
856
|
+
return [`color: ${correctColor(isLight, color)}; background-color: ${correctColor(isLight, bgColor)}; padding: ${border}px ${2 * border}px; border-radius: ${border}px;`, `color: ${TEXT_COLORS.TEXT}; background-color: ${BG_COLORS.TEXT};`];
|
|
857
|
+
}
|
|
858
|
+
function colorForBucket(isLight, scope, bucket) {
|
|
859
|
+
if (scope === 'notify') {
|
|
860
|
+
return bucket === 'added' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'removed' ? badge(isLight, 'red', 'transparent', 0) : badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]);
|
|
861
|
+
}
|
|
862
|
+
if (scope === 'reactive-ui') {
|
|
863
|
+
return bucket === 'created' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'disconnected' ? badge(isLight, 'red', 'transparent', 0) : badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]);
|
|
864
|
+
}
|
|
865
|
+
if (scope === 'cache') {
|
|
866
|
+
return bucket === 'inserted' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'removed' ? badge(isLight, 'red', 'transparent', 0) : badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]);
|
|
867
|
+
}
|
|
868
|
+
return badge(isLight, TEXT_COLORS[scope][3], BG_COLORS[scope][3], NOTIFY_BORDER[scope][3]);
|
|
869
|
+
}
|
|
870
|
+
function logGroup(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
|
|
871
|
+
// eslint-disable-next-line no-console
|
|
872
|
+
console.groupCollapsed(..._log(scope, prefix, subScop1, subScop2, subScop3, subScop4));
|
|
873
|
+
}
|
|
874
|
+
function log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
|
|
875
|
+
// eslint-disable-next-line no-console
|
|
876
|
+
console.log(..._log(scope, prefix, subScop1, subScop2, subScop3, subScop4));
|
|
877
|
+
}
|
|
878
|
+
function correctColor(isLight, color) {
|
|
879
|
+
if (!isLight) {
|
|
880
|
+
return color;
|
|
881
|
+
}
|
|
882
|
+
return color in LIGHT_DARK_ALT ? LIGHT_DARK_ALT[color] : color;
|
|
883
|
+
}
|
|
884
|
+
function isLightMode() {
|
|
885
|
+
if (window?.matchMedia?.('(prefers-color-scheme: light)').matches) {
|
|
886
|
+
return true;
|
|
887
|
+
}
|
|
888
|
+
return false;
|
|
889
|
+
}
|
|
890
|
+
function _log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
|
|
891
|
+
const isLight = isLightMode();
|
|
892
|
+
switch (scope) {
|
|
893
|
+
case 'reactive-ui':
|
|
894
|
+
case 'notify':
|
|
895
|
+
{
|
|
896
|
+
const scopePath = prefix ? `[${prefix}] ${scope}` : scope;
|
|
897
|
+
const path = subScop4 ? `${subScop3}.${subScop4}` : subScop3;
|
|
898
|
+
return [`%c@warp%c-%cdrive%c %c${scopePath}%c %c${subScop1}%c %c${subScop2}%c %c${path}%c`, ...badge(isLight, 'lightgreen', 'transparent', 0), ...badge(isLight, 'magenta', 'transparent', 0), ...badge(isLight, TEXT_COLORS[scope][0], BG_COLORS[scope][0], NOTIFY_BORDER[scope][0]), ...badge(isLight, TEXT_COLORS[scope][1], BG_COLORS[scope][1], NOTIFY_BORDER[scope][1]), ...badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]), ...colorForBucket(isLight, scope, path)];
|
|
899
|
+
}
|
|
900
|
+
case 'cache':
|
|
901
|
+
{
|
|
902
|
+
const scopePath = prefix ? `${scope} (${prefix})` : scope;
|
|
903
|
+
return [`%c@warp%c-%cdrive%c %c${scopePath}%c %c${subScop1}%c %c${subScop2}%c %c${subScop3}%c %c${subScop4}%c`, ...badge(isLight, 'lightgreen', 'transparent', 0), ...badge(isLight, 'magenta', 'transparent', 0), ...badge(isLight, TEXT_COLORS[scope][0], BG_COLORS[scope][0], NOTIFY_BORDER[scope][0]), ...badge(isLight, TEXT_COLORS[scope][1], BG_COLORS[scope][1], NOTIFY_BORDER[scope][1]), ...badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]), ...colorForBucket(isLight, scope, subScop3), ...badge(isLight, TEXT_COLORS[scope][4], BG_COLORS[scope][4], NOTIFY_BORDER[scope][4])];
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return [];
|
|
907
|
+
}
|
|
806
908
|
|
|
807
909
|
/**
|
|
808
910
|
@module @ember-data-mirror/store
|
|
@@ -963,7 +1065,7 @@ class RecordReference {
|
|
|
963
1065
|
if (id !== null) {
|
|
964
1066
|
return this.store.findRecord(this.type, id);
|
|
965
1067
|
}
|
|
966
|
-
macroCondition(getGlobalConfig().
|
|
1068
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
967
1069
|
{
|
|
968
1070
|
throw new Error(`Unable to fetch record of type ${this.type} without an id`);
|
|
969
1071
|
}
|
|
@@ -990,7 +1092,7 @@ class RecordReference {
|
|
|
990
1092
|
reload: true
|
|
991
1093
|
});
|
|
992
1094
|
}
|
|
993
|
-
macroCondition(getGlobalConfig().
|
|
1095
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
994
1096
|
{
|
|
995
1097
|
throw new Error(`Unable to fetch record of type ${this.type} without an id`);
|
|
996
1098
|
}
|
|
@@ -1046,7 +1148,7 @@ class CacheCapabilitiesManager {
|
|
|
1046
1148
|
});
|
|
1047
1149
|
}
|
|
1048
1150
|
notifyChange(identifier, namespace, key) {
|
|
1049
|
-
macroCondition(getGlobalConfig().
|
|
1151
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1050
1152
|
if (!test) {
|
|
1051
1153
|
throw new Error(`Expected a stable identifier`);
|
|
1052
1154
|
}
|
|
@@ -1065,7 +1167,7 @@ class CacheCapabilitiesManager {
|
|
|
1065
1167
|
return this._store.schema;
|
|
1066
1168
|
}
|
|
1067
1169
|
setRecordId(identifier, id) {
|
|
1068
|
-
macroCondition(getGlobalConfig().
|
|
1170
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1069
1171
|
if (!test) {
|
|
1070
1172
|
throw new Error(`Expected a stable identifier`);
|
|
1071
1173
|
}
|
|
@@ -1076,7 +1178,7 @@ class CacheCapabilitiesManager {
|
|
|
1076
1178
|
return Boolean(this._store._instanceCache.peek(identifier));
|
|
1077
1179
|
}
|
|
1078
1180
|
disconnectRecord(identifier) {
|
|
1079
|
-
macroCondition(getGlobalConfig().
|
|
1181
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1080
1182
|
if (!test) {
|
|
1081
1183
|
throw new Error(`Expected a stable identifier`);
|
|
1082
1184
|
}
|
|
@@ -1085,7 +1187,7 @@ class CacheCapabilitiesManager {
|
|
|
1085
1187
|
this._pendingNotifies.delete(identifier);
|
|
1086
1188
|
}
|
|
1087
1189
|
}
|
|
1088
|
-
if (macroCondition(getGlobalConfig().
|
|
1190
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.ENABLE_LEGACY_SCHEMA_SERVICE)) {
|
|
1089
1191
|
CacheCapabilitiesManager.prototype.getSchemaDefinitionService = function () {
|
|
1090
1192
|
// FIXME add deprecation for this
|
|
1091
1193
|
return this._store.schema;
|
|
@@ -1099,7 +1201,7 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA
|
|
|
1099
1201
|
|
|
1100
1202
|
const CacheForIdentifierCache = getOrSetGlobal('CacheForIdentifierCache', new Map());
|
|
1101
1203
|
function setCacheFor(identifier, cache) {
|
|
1102
|
-
macroCondition(getGlobalConfig().
|
|
1204
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1103
1205
|
if (!test) {
|
|
1104
1206
|
throw new Error(`Illegal set of identifier`);
|
|
1105
1207
|
}
|
|
@@ -1149,7 +1251,7 @@ function peekRecordIdentifier(record) {
|
|
|
1149
1251
|
*/
|
|
1150
1252
|
|
|
1151
1253
|
function recordIdentifierFor(record) {
|
|
1152
|
-
macroCondition(getGlobalConfig().
|
|
1254
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1153
1255
|
if (!test) {
|
|
1154
1256
|
throw new Error(`${String(record)} is not a record instantiated by @ember-data-mirror/store`);
|
|
1155
1257
|
}
|
|
@@ -1157,7 +1259,7 @@ function recordIdentifierFor(record) {
|
|
|
1157
1259
|
return RecordCache.get(record);
|
|
1158
1260
|
}
|
|
1159
1261
|
function setRecordIdentifier(record, identifier) {
|
|
1160
|
-
if (macroCondition(getGlobalConfig().
|
|
1262
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
1161
1263
|
if (RecordCache.has(record) && RecordCache.get(record) !== identifier) {
|
|
1162
1264
|
throw new Error(`${String(record)} was already assigned an identifier`);
|
|
1163
1265
|
}
|
|
@@ -1176,7 +1278,7 @@ function setRecordIdentifier(record, identifier) {
|
|
|
1176
1278
|
const StoreMap = getOrSetGlobal('StoreMap', new Map());
|
|
1177
1279
|
function storeFor(record) {
|
|
1178
1280
|
const store = StoreMap.get(record);
|
|
1179
|
-
macroCondition(getGlobalConfig().
|
|
1281
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1180
1282
|
if (!test) {
|
|
1181
1283
|
throw new Error(`A record in a disconnected state cannot utilize the store. This typically means the record has been destroyed, most commonly by unloading it.`);
|
|
1182
1284
|
}
|
|
@@ -1218,7 +1320,7 @@ class InstanceCache {
|
|
|
1218
1320
|
if ('id' in resourceData) {
|
|
1219
1321
|
throw new Error(`Failed to update the 'id' for the RecordIdentifier '${identifier.type}:${String(identifier.id)} (${identifier.lid})' to '${String(resourceData.id)}', because that id is already in use by '${matchedIdentifier.type}:${String(matchedIdentifier.id)} (${matchedIdentifier.lid})'`);
|
|
1220
1322
|
}
|
|
1221
|
-
macroCondition(getGlobalConfig().
|
|
1323
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1222
1324
|
{
|
|
1223
1325
|
throw new Error(`Failed to update the RecordIdentifier '${identifier.type}:${String(identifier.id)} (${identifier.lid})' to merge with the detected duplicate identifier '${matchedIdentifier.type}:${String(matchedIdentifier.id)} (${String(matchedIdentifier.lid)})'`);
|
|
1224
1326
|
}
|
|
@@ -1247,7 +1349,7 @@ class InstanceCache {
|
|
|
1247
1349
|
getRecord(identifier, properties) {
|
|
1248
1350
|
let record = this.__instances.record.get(identifier);
|
|
1249
1351
|
if (!record) {
|
|
1250
|
-
macroCondition(getGlobalConfig().
|
|
1352
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1251
1353
|
if (!test) {
|
|
1252
1354
|
throw new Error(`Cannot create a new record instance while the store is being destroyed`);
|
|
1253
1355
|
}
|
|
@@ -1259,9 +1361,16 @@ class InstanceCache {
|
|
|
1259
1361
|
setCacheFor(record, cache);
|
|
1260
1362
|
StoreMap.set(record, this.store);
|
|
1261
1363
|
this.__instances.record.set(identifier, record);
|
|
1262
|
-
if (macroCondition(getGlobalConfig().
|
|
1263
|
-
|
|
1264
|
-
|
|
1364
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_INSTANCE_CACHE)) {
|
|
1365
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE || globalThis.getWarpDriveRuntimeConfig().debug.LOG_INSTANCE_CACHE) {
|
|
1366
|
+
logGroup('reactive-ui', '', identifier.type, identifier.lid, 'created', '');
|
|
1367
|
+
// eslint-disable-next-line no-console
|
|
1368
|
+
console.log({
|
|
1369
|
+
properties
|
|
1370
|
+
});
|
|
1371
|
+
// eslint-disable-next-line no-console
|
|
1372
|
+
console.groupEnd();
|
|
1373
|
+
}
|
|
1265
1374
|
}
|
|
1266
1375
|
}
|
|
1267
1376
|
return record;
|
|
@@ -1298,7 +1407,7 @@ class InstanceCache {
|
|
|
1298
1407
|
}
|
|
1299
1408
|
disconnect(identifier) {
|
|
1300
1409
|
const record = this.__instances.record.get(identifier);
|
|
1301
|
-
macroCondition(getGlobalConfig().
|
|
1410
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1302
1411
|
if (!test) {
|
|
1303
1412
|
throw new Error('Cannot destroy record while it is still materialized');
|
|
1304
1413
|
}
|
|
@@ -1307,27 +1416,30 @@ class InstanceCache {
|
|
|
1307
1416
|
this.store.identifierCache.forgetRecordIdentifier(identifier);
|
|
1308
1417
|
removeRecordDataFor(identifier);
|
|
1309
1418
|
this.store._requestCache._clearEntries(identifier);
|
|
1310
|
-
if (macroCondition(getGlobalConfig().
|
|
1311
|
-
|
|
1312
|
-
|
|
1419
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_INSTANCE_CACHE)) {
|
|
1420
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE || globalThis.getWarpDriveRuntimeConfig().debug.LOG_INSTANCE_CACHE) {
|
|
1421
|
+
log('reactive-ui', '', identifier.type, identifier.lid, 'disconnected', '');
|
|
1422
|
+
}
|
|
1313
1423
|
}
|
|
1314
1424
|
}
|
|
1315
1425
|
unloadRecord(identifier) {
|
|
1316
|
-
if (macroCondition(getGlobalConfig().
|
|
1426
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
1317
1427
|
const requests = this.store.getRequestStateService().getPendingRequestsForRecord(identifier);
|
|
1318
1428
|
if (requests.some(req => {
|
|
1319
1429
|
return req.type === 'mutation';
|
|
1320
1430
|
})) {
|
|
1321
|
-
macroCondition(getGlobalConfig().
|
|
1431
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1322
1432
|
{
|
|
1323
1433
|
throw new Error(`You can only unload a record which is not inFlight. '${String(identifier)}'`);
|
|
1324
1434
|
}
|
|
1325
1435
|
})() : {};
|
|
1326
1436
|
}
|
|
1327
1437
|
}
|
|
1328
|
-
if (macroCondition(getGlobalConfig().
|
|
1329
|
-
|
|
1330
|
-
|
|
1438
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_INSTANCE_CACHE)) {
|
|
1439
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE || globalThis.getWarpDriveRuntimeConfig().debug.LOG_INSTANCE_CACHE) {
|
|
1440
|
+
// eslint-disable-next-line no-console
|
|
1441
|
+
console.groupCollapsed(`InstanceCache: unloading record for ${String(identifier)}`);
|
|
1442
|
+
}
|
|
1331
1443
|
}
|
|
1332
1444
|
|
|
1333
1445
|
// TODO is this join still necessary?
|
|
@@ -1340,27 +1452,33 @@ class InstanceCache {
|
|
|
1340
1452
|
StoreMap.delete(record);
|
|
1341
1453
|
RecordCache.delete(record);
|
|
1342
1454
|
removeRecordDataFor(record);
|
|
1343
|
-
if (macroCondition(getGlobalConfig().
|
|
1344
|
-
|
|
1345
|
-
|
|
1455
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_INSTANCE_CACHE)) {
|
|
1456
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE || globalThis.getWarpDriveRuntimeConfig().debug.LOG_INSTANCE_CACHE) {
|
|
1457
|
+
// eslint-disable-next-line no-console
|
|
1458
|
+
console.log(`InstanceCache: destroyed record for ${String(identifier)}`);
|
|
1459
|
+
}
|
|
1346
1460
|
}
|
|
1347
1461
|
}
|
|
1348
1462
|
if (cache) {
|
|
1349
1463
|
cache.unloadRecord(identifier);
|
|
1350
1464
|
removeRecordDataFor(identifier);
|
|
1351
|
-
if (macroCondition(getGlobalConfig().
|
|
1352
|
-
|
|
1353
|
-
|
|
1465
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_INSTANCE_CACHE)) {
|
|
1466
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE || globalThis.getWarpDriveRuntimeConfig().debug.LOG_INSTANCE_CACHE) {
|
|
1467
|
+
// eslint-disable-next-line no-console
|
|
1468
|
+
console.log(`InstanceCache: destroyed cache for ${String(identifier)}`);
|
|
1469
|
+
}
|
|
1354
1470
|
}
|
|
1355
1471
|
} else {
|
|
1356
1472
|
this.disconnect(identifier);
|
|
1357
1473
|
}
|
|
1358
1474
|
this.store._requestCache._clearEntries(identifier);
|
|
1359
|
-
if (macroCondition(getGlobalConfig().
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1475
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_INSTANCE_CACHE)) {
|
|
1476
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE || globalThis.getWarpDriveRuntimeConfig().debug.LOG_INSTANCE_CACHE) {
|
|
1477
|
+
// eslint-disable-next-line no-console
|
|
1478
|
+
console.log(`InstanceCache: unloaded RecordData for ${String(identifier)}`);
|
|
1479
|
+
// eslint-disable-next-line no-console
|
|
1480
|
+
console.groupEnd();
|
|
1481
|
+
}
|
|
1364
1482
|
}
|
|
1365
1483
|
});
|
|
1366
1484
|
}
|
|
@@ -1395,7 +1513,7 @@ class InstanceCache {
|
|
|
1395
1513
|
const oldId = identifier.id;
|
|
1396
1514
|
|
|
1397
1515
|
// ID absolutely can't be missing if the oldID is empty (missing Id in response for a new record)
|
|
1398
|
-
macroCondition(getGlobalConfig().
|
|
1516
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1399
1517
|
if (!test) {
|
|
1400
1518
|
throw new Error(`'${type}' was saved to the server, but the response does not have an id and your record does not either.`);
|
|
1401
1519
|
}
|
|
@@ -1403,7 +1521,7 @@ class InstanceCache {
|
|
|
1403
1521
|
|
|
1404
1522
|
// ID absolutely can't be different than oldID if oldID is not null
|
|
1405
1523
|
// TODO this assertion and restriction may not strictly be needed in the identifiers world
|
|
1406
|
-
macroCondition(getGlobalConfig().
|
|
1524
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1407
1525
|
if (!test) {
|
|
1408
1526
|
throw new Error(`Cannot update the id for '${type}:${lid}' from '${String(oldId)}' to '${id}'.`);
|
|
1409
1527
|
}
|
|
@@ -1415,15 +1533,17 @@ class InstanceCache {
|
|
|
1415
1533
|
warn(`Your ${type} record was saved to the server, but the response does not have an id.`, !(oldId !== null && id === null));
|
|
1416
1534
|
return;
|
|
1417
1535
|
}
|
|
1418
|
-
if (macroCondition(getGlobalConfig().
|
|
1419
|
-
|
|
1420
|
-
|
|
1536
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_INSTANCE_CACHE)) {
|
|
1537
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_INSTANCE_CACHE || globalThis.getWarpDriveRuntimeConfig().debug.LOG_INSTANCE_CACHE) {
|
|
1538
|
+
// eslint-disable-next-line no-console
|
|
1539
|
+
console.log(`InstanceCache: updating id to '${id}' for record ${String(identifier)}`);
|
|
1540
|
+
}
|
|
1421
1541
|
}
|
|
1422
1542
|
const existingIdentifier = this.store.identifierCache.peekRecordIdentifier({
|
|
1423
1543
|
type,
|
|
1424
1544
|
id
|
|
1425
1545
|
});
|
|
1426
|
-
macroCondition(getGlobalConfig().
|
|
1546
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1427
1547
|
if (!test) {
|
|
1428
1548
|
throw new Error(`'${type}' was saved to the server, but the response returned the new id '${id}', which has already been used with another record.'`);
|
|
1429
1549
|
}
|
|
@@ -1488,7 +1608,7 @@ function preloadData(store, identifier, preload) {
|
|
|
1488
1608
|
function preloadRelationship(schema, preloadValue) {
|
|
1489
1609
|
const relatedType = schema.type;
|
|
1490
1610
|
if (schema.kind === 'hasMany') {
|
|
1491
|
-
macroCondition(getGlobalConfig().
|
|
1611
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1492
1612
|
if (!test) {
|
|
1493
1613
|
throw new Error('You need to pass in an array to set a hasMany property on a record');
|
|
1494
1614
|
}
|
|
@@ -1497,7 +1617,7 @@ function preloadRelationship(schema, preloadValue) {
|
|
|
1497
1617
|
data: preloadValue.map(value => _convertPreloadRelationshipToJSON(value, relatedType))
|
|
1498
1618
|
};
|
|
1499
1619
|
}
|
|
1500
|
-
macroCondition(getGlobalConfig().
|
|
1620
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
1501
1621
|
if (!test) {
|
|
1502
1622
|
throw new Error('You should not pass in an array to set a belongsTo property on a record');
|
|
1503
1623
|
}
|
|
@@ -1734,7 +1854,9 @@ class CacheManager {
|
|
|
1734
1854
|
peek(identifier) {
|
|
1735
1855
|
return this.#cache.peek(identifier);
|
|
1736
1856
|
}
|
|
1737
|
-
|
|
1857
|
+
peekRemoteState(identifier) {
|
|
1858
|
+
return this.#cache.peekRemoteState(identifier);
|
|
1859
|
+
}
|
|
1738
1860
|
/**
|
|
1739
1861
|
* Peek the Cache for the existing request data associated with
|
|
1740
1862
|
* a cacheable request
|
|
@@ -1957,6 +2079,19 @@ class CacheManager {
|
|
|
1957
2079
|
return this.#cache.getAttr(identifier, propertyName);
|
|
1958
2080
|
}
|
|
1959
2081
|
|
|
2082
|
+
/**
|
|
2083
|
+
* Retrieve the remote state for an attribute from the cache
|
|
2084
|
+
*
|
|
2085
|
+
* @method getRemoteAttr
|
|
2086
|
+
* @public
|
|
2087
|
+
* @param identifier
|
|
2088
|
+
* @param propertyName
|
|
2089
|
+
* @return {unknown}
|
|
2090
|
+
*/
|
|
2091
|
+
getRemoteAttr(identifier, propertyName) {
|
|
2092
|
+
return this.#cache.getRemoteAttr(identifier, propertyName);
|
|
2093
|
+
}
|
|
2094
|
+
|
|
1960
2095
|
/**
|
|
1961
2096
|
* Mutate the data for an attribute in the cache
|
|
1962
2097
|
*
|
|
@@ -2081,6 +2216,19 @@ class CacheManager {
|
|
|
2081
2216
|
return this.#cache.getRelationship(identifier, propertyName);
|
|
2082
2217
|
}
|
|
2083
2218
|
|
|
2219
|
+
/**
|
|
2220
|
+
* Query the cache for the remote state of a relationship property
|
|
2221
|
+
*
|
|
2222
|
+
* @method getRelationship
|
|
2223
|
+
* @public
|
|
2224
|
+
* @param identifier
|
|
2225
|
+
* @param propertyName
|
|
2226
|
+
* @return resource relationship object
|
|
2227
|
+
*/
|
|
2228
|
+
getRemoteRelationship(identifier, propertyName) {
|
|
2229
|
+
return this.#cache.getRemoteRelationship(identifier, propertyName);
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2084
2232
|
// Resource State
|
|
2085
2233
|
// ===============
|
|
2086
2234
|
|
|
@@ -2174,12 +2322,19 @@ function runLoopIsFlushing() {
|
|
|
2174
2322
|
//@ts-expect-error
|
|
2175
2323
|
return !!_backburner.currentInstance && _backburner._autorun !== true;
|
|
2176
2324
|
}
|
|
2325
|
+
function count(label) {
|
|
2326
|
+
// @ts-expect-error
|
|
2327
|
+
// eslint-disable-next-line
|
|
2328
|
+
globalThis.__WarpDriveMetricCountData[label] = (globalThis.__WarpDriveMetricCountData[label] || 0) + 1;
|
|
2329
|
+
}
|
|
2177
2330
|
function _unsubscribe(tokens, token, cache) {
|
|
2178
2331
|
const identifier = tokens.get(token);
|
|
2179
|
-
if (macroCondition(getGlobalConfig().
|
|
2180
|
-
if (
|
|
2181
|
-
|
|
2182
|
-
|
|
2332
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_NOTIFICATIONS)) {
|
|
2333
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_NOTIFICATIONS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_NOTIFICATIONS) {
|
|
2334
|
+
if (!identifier) {
|
|
2335
|
+
// eslint-disable-next-line no-console
|
|
2336
|
+
console.log('Passed unknown unsubscribe token to unsubscribe', identifier);
|
|
2337
|
+
}
|
|
2183
2338
|
}
|
|
2184
2339
|
}
|
|
2185
2340
|
if (identifier) {
|
|
@@ -2238,7 +2393,7 @@ class NotificationManager {
|
|
|
2238
2393
|
*/
|
|
2239
2394
|
|
|
2240
2395
|
subscribe(identifier, callback) {
|
|
2241
|
-
macroCondition(getGlobalConfig().
|
|
2396
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2242
2397
|
if (!test) {
|
|
2243
2398
|
throw new Error(`Expected to receive a stable Identifier to subscribe to`);
|
|
2244
2399
|
}
|
|
@@ -2248,7 +2403,7 @@ class NotificationManager {
|
|
|
2248
2403
|
map = new Map();
|
|
2249
2404
|
this._cache.set(identifier, map);
|
|
2250
2405
|
}
|
|
2251
|
-
const unsubToken = macroCondition(getGlobalConfig().
|
|
2406
|
+
const unsubToken = macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? {
|
|
2252
2407
|
_tokenRef: tokenId++
|
|
2253
2408
|
} : {};
|
|
2254
2409
|
map.set(unsubToken, callback);
|
|
@@ -2281,22 +2436,20 @@ class NotificationManager {
|
|
|
2281
2436
|
*/
|
|
2282
2437
|
|
|
2283
2438
|
notify(identifier, value, key) {
|
|
2284
|
-
macroCondition(getGlobalConfig().
|
|
2439
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2285
2440
|
if (!test) {
|
|
2286
2441
|
throw new Error(`Notify does not accept a key argument for the namespace '${value}'. Received key '${key || ''}'.`);
|
|
2287
2442
|
}
|
|
2288
2443
|
})(!key || value === 'attributes' || value === 'relationships') : {};
|
|
2289
2444
|
if (!isStableIdentifier(identifier) && !isDocumentIdentifier(identifier)) {
|
|
2290
|
-
if (macroCondition(getGlobalConfig().
|
|
2291
|
-
|
|
2292
|
-
|
|
2445
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_NOTIFICATIONS)) {
|
|
2446
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_NOTIFICATIONS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_NOTIFICATIONS) {
|
|
2447
|
+
// eslint-disable-next-line no-console
|
|
2448
|
+
console.log(`Notifying: Expected to receive a stable Identifier to notify '${value}' '${key || ''}' with, but ${String(identifier)} is not in the cache`, identifier);
|
|
2449
|
+
}
|
|
2293
2450
|
}
|
|
2294
2451
|
return false;
|
|
2295
2452
|
}
|
|
2296
|
-
if (macroCondition(getGlobalConfig().WarpDrive.debug.LOG_NOTIFICATIONS)) {
|
|
2297
|
-
// eslint-disable-next-line no-console
|
|
2298
|
-
console.log(`Buffering Notify: ${String(identifier.lid)}\t${value}\t${key || ''}`);
|
|
2299
|
-
}
|
|
2300
2453
|
const hasSubscribers = Boolean(this._cache.get(identifier)?.size);
|
|
2301
2454
|
if (isCacheOperationValue(value) || hasSubscribers) {
|
|
2302
2455
|
let buffer = this._buffered.get(identifier);
|
|
@@ -2305,7 +2458,22 @@ class NotificationManager {
|
|
|
2305
2458
|
this._buffered.set(identifier, buffer);
|
|
2306
2459
|
}
|
|
2307
2460
|
buffer.push([value, key]);
|
|
2308
|
-
|
|
2461
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_METRIC_COUNTS)) {
|
|
2462
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_METRIC_COUNTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_METRIC_COUNTS) {
|
|
2463
|
+
count(`notify ${'type' in identifier ? identifier.type : '<document>'} ${value} ${key}`);
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
if (!this._scheduleNotify()) {
|
|
2467
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_NOTIFICATIONS)) {
|
|
2468
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_NOTIFICATIONS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_NOTIFICATIONS) {
|
|
2469
|
+
log('notify', 'buffered', `${'type' in identifier ? identifier.type : 'document'}`, identifier.lid, `${value}`, key || '');
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
} else if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_METRIC_COUNTS)) {
|
|
2474
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_METRIC_COUNTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_METRIC_COUNTS) {
|
|
2475
|
+
count(`DISCARDED notify ${'type' in identifier ? identifier.type : '<document>'} ${value} ${key}`);
|
|
2476
|
+
}
|
|
2309
2477
|
}
|
|
2310
2478
|
return hasSubscribers;
|
|
2311
2479
|
}
|
|
@@ -2316,14 +2484,15 @@ class NotificationManager {
|
|
|
2316
2484
|
const asyncFlush = this.store._enableAsyncFlush;
|
|
2317
2485
|
if (this._hasFlush) {
|
|
2318
2486
|
if (asyncFlush !== false && !runLoopIsFlushing()) {
|
|
2319
|
-
return;
|
|
2487
|
+
return false;
|
|
2320
2488
|
}
|
|
2321
2489
|
}
|
|
2322
2490
|
if (asyncFlush && !runLoopIsFlushing()) {
|
|
2323
2491
|
this._hasFlush = true;
|
|
2324
|
-
return;
|
|
2492
|
+
return false;
|
|
2325
2493
|
}
|
|
2326
2494
|
this._flush();
|
|
2495
|
+
return true;
|
|
2327
2496
|
}
|
|
2328
2497
|
_flush() {
|
|
2329
2498
|
const buffered = this._buffered;
|
|
@@ -2341,9 +2510,10 @@ class NotificationManager {
|
|
|
2341
2510
|
this._onFlushCB = undefined;
|
|
2342
2511
|
}
|
|
2343
2512
|
_flushNotification(identifier, value, key) {
|
|
2344
|
-
if (macroCondition(getGlobalConfig().
|
|
2345
|
-
|
|
2346
|
-
|
|
2513
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_NOTIFICATIONS)) {
|
|
2514
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_NOTIFICATIONS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_NOTIFICATIONS) {
|
|
2515
|
+
log('notify', '', `${'type' in identifier ? identifier.type : 'document'}`, identifier.lid, `${value}`, key || '');
|
|
2516
|
+
}
|
|
2347
2517
|
}
|
|
2348
2518
|
|
|
2349
2519
|
// TODO for documents this will need to switch based on Identifier kind
|
|
@@ -2465,7 +2635,7 @@ function isAllowedProp(prop) {
|
|
|
2465
2635
|
}
|
|
2466
2636
|
function promiseArray(promise) {
|
|
2467
2637
|
const promiseObjectProxy = _promiseArray(promise);
|
|
2468
|
-
if (macroCondition(!getGlobalConfig().
|
|
2638
|
+
if (macroCondition(!getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
2469
2639
|
return promiseObjectProxy;
|
|
2470
2640
|
}
|
|
2471
2641
|
const handler = {
|
|
@@ -2504,7 +2674,7 @@ function promiseArray(promise) {
|
|
|
2504
2674
|
const ProxySymbolString = String(Symbol.for('PROXY_CONTENT'));
|
|
2505
2675
|
function promiseObject(promise) {
|
|
2506
2676
|
const promiseObjectProxy = _promiseObject(promise);
|
|
2507
|
-
if (macroCondition(!getGlobalConfig().
|
|
2677
|
+
if (macroCondition(!getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
2508
2678
|
return promiseObjectProxy;
|
|
2509
2679
|
}
|
|
2510
2680
|
const handler = {
|
|
@@ -2605,7 +2775,7 @@ function safeForEach(instance, arr, store, callback, target) {
|
|
|
2605
2775
|
}
|
|
2606
2776
|
// clone to prevent mutation
|
|
2607
2777
|
arr = arr.slice();
|
|
2608
|
-
macroCondition(getGlobalConfig().
|
|
2778
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2609
2779
|
if (!test) {
|
|
2610
2780
|
throw new Error('`forEach` expects a function as first argument.');
|
|
2611
2781
|
}
|
|
@@ -2767,7 +2937,7 @@ class IdentifierArray {
|
|
|
2767
2937
|
// array functions must run through Reflect to work properly
|
|
2768
2938
|
// binding via other means will not work.
|
|
2769
2939
|
if (!options.allowMutation) {
|
|
2770
|
-
macroCondition(getGlobalConfig().
|
|
2940
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2771
2941
|
if (!test) {
|
|
2772
2942
|
throw new Error(`Mutating this array of records via ${String(prop)} is not allowed.`);
|
|
2773
2943
|
}
|
|
@@ -2775,7 +2945,7 @@ class IdentifierArray {
|
|
|
2775
2945
|
return;
|
|
2776
2946
|
}
|
|
2777
2947
|
const args = Array.prototype.slice.call(arguments);
|
|
2778
|
-
macroCondition(getGlobalConfig().
|
|
2948
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2779
2949
|
if (!test) {
|
|
2780
2950
|
throw new Error(`Cannot start a new array transaction while a previous transaction is underway`);
|
|
2781
2951
|
}
|
|
@@ -2790,7 +2960,7 @@ class IdentifierArray {
|
|
|
2790
2960
|
return fn;
|
|
2791
2961
|
}
|
|
2792
2962
|
if (isSelfProp(self, prop)) {
|
|
2793
|
-
if (macroCondition(getGlobalConfig().
|
|
2963
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_ARRAY_LIKE)) {
|
|
2794
2964
|
if (prop === 'firstObject') {
|
|
2795
2965
|
deprecateArrayLike(self.DEPRECATED_CLASS_NAME, prop, '[0]');
|
|
2796
2966
|
// @ts-expect-error adding MutableArray method calling index signature
|
|
@@ -2832,7 +3002,7 @@ class IdentifierArray {
|
|
|
2832
3002
|
} else if (transaction) {
|
|
2833
3003
|
return Reflect.set(target, prop, value);
|
|
2834
3004
|
} else {
|
|
2835
|
-
macroCondition(getGlobalConfig().
|
|
3005
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2836
3006
|
{
|
|
2837
3007
|
throw new Error(`unexpected length set`);
|
|
2838
3008
|
}
|
|
@@ -2859,7 +3029,7 @@ class IdentifierArray {
|
|
|
2859
3029
|
if (index === null || index > target.length) {
|
|
2860
3030
|
if (index !== null && transaction) {
|
|
2861
3031
|
const identifier = recordIdentifierFor(value);
|
|
2862
|
-
macroCondition(getGlobalConfig().
|
|
3032
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2863
3033
|
if (!test) {
|
|
2864
3034
|
throw new Error(`Cannot set index ${index} past the end of the array.`);
|
|
2865
3035
|
}
|
|
@@ -2874,7 +3044,7 @@ class IdentifierArray {
|
|
|
2874
3044
|
return false;
|
|
2875
3045
|
}
|
|
2876
3046
|
if (!options.allowMutation) {
|
|
2877
|
-
macroCondition(getGlobalConfig().
|
|
3047
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2878
3048
|
if (!test) {
|
|
2879
3049
|
throw new Error(`Mutating ${String(prop)} on this Array is not allowed.`);
|
|
2880
3050
|
}
|
|
@@ -2882,8 +3052,8 @@ class IdentifierArray {
|
|
|
2882
3052
|
return false;
|
|
2883
3053
|
}
|
|
2884
3054
|
const original = target[index];
|
|
2885
|
-
const newIdentifier = extractIdentifierFromRecord$
|
|
2886
|
-
macroCondition(getGlobalConfig().
|
|
3055
|
+
const newIdentifier = extractIdentifierFromRecord$2(value);
|
|
3056
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2887
3057
|
if (!test) {
|
|
2888
3058
|
throw new Error(`Expected a record`);
|
|
2889
3059
|
}
|
|
@@ -2912,7 +3082,7 @@ class IdentifierArray {
|
|
|
2912
3082
|
return true;
|
|
2913
3083
|
},
|
|
2914
3084
|
deleteProperty(target, prop) {
|
|
2915
|
-
macroCondition(getGlobalConfig().
|
|
3085
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2916
3086
|
if (!test) {
|
|
2917
3087
|
throw new Error(`Deleting keys on managed arrays is disallowed`);
|
|
2918
3088
|
}
|
|
@@ -2923,10 +3093,10 @@ class IdentifierArray {
|
|
|
2923
3093
|
return Reflect.deleteProperty(target, prop);
|
|
2924
3094
|
},
|
|
2925
3095
|
getPrototypeOf() {
|
|
2926
|
-
return
|
|
3096
|
+
return Array.prototype;
|
|
2927
3097
|
}
|
|
2928
3098
|
});
|
|
2929
|
-
if (macroCondition(getGlobalConfig().
|
|
3099
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_A_USAGE)) {
|
|
2930
3100
|
const meta = Ember.meta(this);
|
|
2931
3101
|
meta.hasMixin = mixin => {
|
|
2932
3102
|
deprecate(`Do not call A() on EmberData RecordArrays`, false, {
|
|
@@ -2944,10 +3114,10 @@ class IdentifierArray {
|
|
|
2944
3114
|
}
|
|
2945
3115
|
return false;
|
|
2946
3116
|
};
|
|
2947
|
-
} else if (macroCondition(getGlobalConfig().
|
|
3117
|
+
} else if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
2948
3118
|
const meta = Ember.meta(this);
|
|
2949
3119
|
meta.hasMixin = mixin => {
|
|
2950
|
-
macroCondition(getGlobalConfig().
|
|
3120
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
2951
3121
|
{
|
|
2952
3122
|
throw new Error(`Do not call A() on EmberData RecordArrays`);
|
|
2953
3123
|
}
|
|
@@ -2996,7 +3166,7 @@ class IdentifierArray {
|
|
|
2996
3166
|
is finished.
|
|
2997
3167
|
*/
|
|
2998
3168
|
_update() {
|
|
2999
|
-
macroCondition(getGlobalConfig().
|
|
3169
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3000
3170
|
if (!test) {
|
|
3001
3171
|
throw new Error(`_update cannot be used with this array`);
|
|
3002
3172
|
}
|
|
@@ -3027,7 +3197,7 @@ class IdentifierArray {
|
|
|
3027
3197
|
*/
|
|
3028
3198
|
save() {
|
|
3029
3199
|
const promise = Promise.all(this.map(record => this.store.saveRecord(record))).then(() => this);
|
|
3030
|
-
if (macroCondition(getGlobalConfig().
|
|
3200
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_PROMISE_PROXIES)) {
|
|
3031
3201
|
// @ts-expect-error IdentifierArray is not a MutableArray
|
|
3032
3202
|
return promiseArray(promise);
|
|
3033
3203
|
}
|
|
@@ -3045,7 +3215,7 @@ const desc = {
|
|
|
3045
3215
|
get: function () {
|
|
3046
3216
|
// here to support computed chains
|
|
3047
3217
|
// and {{#each}}
|
|
3048
|
-
if (macroCondition(getGlobalConfig().
|
|
3218
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_COMPUTED_CHAINS)) {
|
|
3049
3219
|
return this;
|
|
3050
3220
|
}
|
|
3051
3221
|
}
|
|
@@ -3053,7 +3223,7 @@ const desc = {
|
|
|
3053
3223
|
compat(desc);
|
|
3054
3224
|
Object.defineProperty(IdentifierArray.prototype, '[]', desc);
|
|
3055
3225
|
defineSignal(IdentifierArray.prototype, 'isUpdating', false);
|
|
3056
|
-
if (macroCondition(getGlobalConfig().
|
|
3226
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_SNAPSHOT_MODEL_CLASS_ACCESS)) {
|
|
3057
3227
|
Object.defineProperty(IdentifierArray.prototype, 'type', {
|
|
3058
3228
|
get() {
|
|
3059
3229
|
deprecate(`Using RecordArray.type to access the ModelClass for a record is deprecated. Use store.modelFor(<modelName>) instead.`, false, {
|
|
@@ -3088,12 +3258,12 @@ class Collection extends IdentifierArray {
|
|
|
3088
3258
|
} = this;
|
|
3089
3259
|
|
|
3090
3260
|
// TODO save options from initial request?
|
|
3091
|
-
macroCondition(getGlobalConfig().
|
|
3261
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3092
3262
|
if (!test) {
|
|
3093
3263
|
throw new Error(`update cannot be used with this array`);
|
|
3094
3264
|
}
|
|
3095
3265
|
})(this.modelName) : {};
|
|
3096
|
-
macroCondition(getGlobalConfig().
|
|
3266
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3097
3267
|
if (!test) {
|
|
3098
3268
|
throw new Error(`update cannot be used with no query`);
|
|
3099
3269
|
}
|
|
@@ -3105,7 +3275,7 @@ class Collection extends IdentifierArray {
|
|
|
3105
3275
|
const promise = store.query(this.modelName, query, {
|
|
3106
3276
|
_recordArray: this
|
|
3107
3277
|
});
|
|
3108
|
-
if (macroCondition(getGlobalConfig().
|
|
3278
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_PROMISE_PROXIES)) {
|
|
3109
3279
|
// @ts-expect-error Collection is not a MutableArray
|
|
3110
3280
|
return promiseArray(promise);
|
|
3111
3281
|
}
|
|
@@ -3123,7 +3293,7 @@ Collection.prototype.query = null;
|
|
|
3123
3293
|
// Ensure instanceof works correctly
|
|
3124
3294
|
//Object.setPrototypeOf(IdentifierArray.prototype, Array.prototype);
|
|
3125
3295
|
|
|
3126
|
-
if (macroCondition(getGlobalConfig().
|
|
3296
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_ARRAY_LIKE)) {
|
|
3127
3297
|
IdentifierArray.prototype.DEPRECATED_CLASS_NAME = 'RecordArray';
|
|
3128
3298
|
Collection.prototype.DEPRECATED_CLASS_NAME = 'RecordArray';
|
|
3129
3299
|
const EmberObjectMethods = ['addObserver', 'cacheFor', 'decrementProperty', 'get', 'getProperties', 'incrementProperty', 'notifyPropertyChange', 'removeObserver', 'set', 'setProperties', 'toggleProperty'];
|
|
@@ -3287,7 +3457,7 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_ARRAY_LIKE
|
|
|
3287
3457
|
// @ts-expect-error adding MutableArray method
|
|
3288
3458
|
IdentifierArray.prototype.setObjects = function (objects) {
|
|
3289
3459
|
deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'setObjects', '`arr.length = 0; arr.push(objects);`');
|
|
3290
|
-
macroCondition(getGlobalConfig().
|
|
3460
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3291
3461
|
if (!test) {
|
|
3292
3462
|
throw new Error(`${this.DEPRECATED_CLASS_NAME}.setObjects expects to receive an array as its argument`);
|
|
3293
3463
|
}
|
|
@@ -3428,7 +3598,7 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_ARRAY_LIKE
|
|
|
3428
3598
|
// @ts-expect-error adding MutableArray method
|
|
3429
3599
|
IdentifierArray.prototype.reject = function (callback, target) {
|
|
3430
3600
|
deprecateArrayLike(this.DEPRECATED_CLASS_NAME, 'reject', 'filter');
|
|
3431
|
-
macroCondition(getGlobalConfig().
|
|
3601
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3432
3602
|
if (!test) {
|
|
3433
3603
|
throw new Error('`reject` expects a function as first argument.');
|
|
3434
3604
|
}
|
|
@@ -3505,8 +3675,8 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_ARRAY_LIKE
|
|
|
3505
3675
|
// @ts-expect-error
|
|
3506
3676
|
IdentifierArray.prototype.lastObject = null;
|
|
3507
3677
|
}
|
|
3508
|
-
function assertRecordPassedToHasMany(record) {
|
|
3509
|
-
macroCondition(getGlobalConfig().
|
|
3678
|
+
function assertRecordPassedToHasMany$1(record) {
|
|
3679
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3510
3680
|
if (!test) {
|
|
3511
3681
|
throw new Error(`All elements of a hasMany relationship must be instances of Model, you passed $${typeof record}`);
|
|
3512
3682
|
}
|
|
@@ -3519,24 +3689,24 @@ function assertRecordPassedToHasMany(record) {
|
|
|
3519
3689
|
}
|
|
3520
3690
|
}()) : {};
|
|
3521
3691
|
}
|
|
3522
|
-
function extractIdentifierFromRecord$
|
|
3692
|
+
function extractIdentifierFromRecord$2(recordOrPromiseRecord) {
|
|
3523
3693
|
if (!recordOrPromiseRecord) {
|
|
3524
3694
|
return null;
|
|
3525
3695
|
}
|
|
3526
|
-
if (isPromiseRecord$
|
|
3696
|
+
if (isPromiseRecord$2(recordOrPromiseRecord)) {
|
|
3527
3697
|
const content = recordOrPromiseRecord.content;
|
|
3528
|
-
macroCondition(getGlobalConfig().
|
|
3698
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3529
3699
|
if (!test) {
|
|
3530
3700
|
throw new Error('You passed in a promise that did not originate from an EmberData relationship. You can only pass promises that come from a belongsTo relationship.');
|
|
3531
3701
|
}
|
|
3532
3702
|
})(content !== undefined && content !== null) : {};
|
|
3533
|
-
assertRecordPassedToHasMany(content);
|
|
3703
|
+
assertRecordPassedToHasMany$1(content);
|
|
3534
3704
|
return recordIdentifierFor(content);
|
|
3535
3705
|
}
|
|
3536
|
-
assertRecordPassedToHasMany(recordOrPromiseRecord);
|
|
3706
|
+
assertRecordPassedToHasMany$1(recordOrPromiseRecord);
|
|
3537
3707
|
return recordIdentifierFor(recordOrPromiseRecord);
|
|
3538
3708
|
}
|
|
3539
|
-
function isPromiseRecord$
|
|
3709
|
+
function isPromiseRecord$2(record) {
|
|
3540
3710
|
return Boolean(typeof record === 'object' && record && 'then' in record);
|
|
3541
3711
|
}
|
|
3542
3712
|
|
|
@@ -3631,6 +3801,9 @@ class RecordArrayManager {
|
|
|
3631
3801
|
sync(array, pending, this._set.get(array));
|
|
3632
3802
|
this._pending.delete(array);
|
|
3633
3803
|
}
|
|
3804
|
+
mutate(mutation) {
|
|
3805
|
+
this.store.cache.mutate(mutation);
|
|
3806
|
+
}
|
|
3634
3807
|
|
|
3635
3808
|
/**
|
|
3636
3809
|
Get the `RecordArray` for a modelName, which contains all loaded records of
|
|
@@ -3894,7 +4067,7 @@ function sync(array, changes, arraySet) {
|
|
|
3894
4067
|
|
|
3895
4068
|
const Touching = getOrSetGlobal('Touching', Symbol('touching'));
|
|
3896
4069
|
const RequestPromise = getOrSetGlobal('RequestPromise', Symbol('promise'));
|
|
3897
|
-
const EMPTY_ARR = macroCondition(getGlobalConfig().
|
|
4070
|
+
const EMPTY_ARR = macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? Object.freeze([]) : [];
|
|
3898
4071
|
function hasRecordIdentifier(op) {
|
|
3899
4072
|
return 'recordIdentifier' in op;
|
|
3900
4073
|
}
|
|
@@ -3965,7 +4138,7 @@ class RequestStateService {
|
|
|
3965
4138
|
throw error;
|
|
3966
4139
|
});
|
|
3967
4140
|
}
|
|
3968
|
-
macroCondition(getGlobalConfig().
|
|
4141
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
3969
4142
|
{
|
|
3970
4143
|
throw new Error(`Expected a well formed query`);
|
|
3971
4144
|
}
|
|
@@ -4102,12 +4275,12 @@ function constructResource(type, id, lid) {
|
|
|
4102
4275
|
if ('id' in resource) {
|
|
4103
4276
|
resource.id = coerceId(resource.id);
|
|
4104
4277
|
}
|
|
4105
|
-
macroCondition(getGlobalConfig().
|
|
4278
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4106
4279
|
if (!test) {
|
|
4107
4280
|
throw new Error('Expected either id or lid to be a valid string');
|
|
4108
4281
|
}
|
|
4109
4282
|
})('id' in resource && isNonEmptyString(resource.id) || isNonEmptyString(resource.lid)) : {};
|
|
4110
|
-
macroCondition(getGlobalConfig().
|
|
4283
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4111
4284
|
if (!test) {
|
|
4112
4285
|
throw new Error('if id is present, the type must be a string');
|
|
4113
4286
|
}
|
|
@@ -4123,7 +4296,7 @@ function constructResource(type, id, lid) {
|
|
|
4123
4296
|
}
|
|
4124
4297
|
throw new Error('Expected either id or lid to be a valid string');
|
|
4125
4298
|
}
|
|
4126
|
-
macroCondition(getGlobalConfig().
|
|
4299
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4127
4300
|
if (!test) {
|
|
4128
4301
|
throw new Error('type must be a string');
|
|
4129
4302
|
}
|
|
@@ -4147,6 +4320,26 @@ function constructResource(type, id, lid) {
|
|
|
4147
4320
|
*/
|
|
4148
4321
|
// this import location is deprecated but breaks in 4.8 and older
|
|
4149
4322
|
|
|
4323
|
+
// @ts-expect-error adding to globalThis
|
|
4324
|
+
globalThis.setWarpDriveLogging = setLogging;
|
|
4325
|
+
|
|
4326
|
+
// @ts-expect-error adding to globalThis
|
|
4327
|
+
globalThis.getWarpDriveRuntimeConfig = getRuntimeConfig;
|
|
4328
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_METRIC_COUNTS)) {
|
|
4329
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_METRIC_COUNTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_METRIC_COUNTS) {
|
|
4330
|
+
// @ts-expect-error
|
|
4331
|
+
// eslint-disable-next-line
|
|
4332
|
+
globalThis.__WarpDriveMetricCountData = globalThis.__WarpDriveMetricCountData || {};
|
|
4333
|
+
|
|
4334
|
+
// @ts-expect-error
|
|
4335
|
+
globalThis.getWarpDriveMetricCounts = () => {
|
|
4336
|
+
// @ts-expect-error
|
|
4337
|
+
// eslint-disable-next-line
|
|
4338
|
+
return globalThis.__WarpDriveMetricCountData;
|
|
4339
|
+
};
|
|
4340
|
+
}
|
|
4341
|
+
}
|
|
4342
|
+
|
|
4150
4343
|
// `AwaitedKeys` is needed here to resolve any promise types like `PromiseBelongsTo`.
|
|
4151
4344
|
|
|
4152
4345
|
/**
|
|
@@ -4191,7 +4384,7 @@ const EmptyClass = class {
|
|
|
4191
4384
|
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
4192
4385
|
constructor(args) {}
|
|
4193
4386
|
};
|
|
4194
|
-
const _BaseClass = macroCondition(dependencySatisfies('ember-source', '*')) ? macroCondition(getGlobalConfig().
|
|
4387
|
+
const _BaseClass = macroCondition(dependencySatisfies('ember-source', '*')) ? macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_STORE_EXTENDS_EMBER_OBJECT) ? importSync('@ember/object') : EmptyClass : EmptyClass;
|
|
4195
4388
|
const BaseClass = _BaseClass.default ? _BaseClass.default : _BaseClass;
|
|
4196
4389
|
if (BaseClass !== EmptyClass) {
|
|
4197
4390
|
deprecate(`The Store class extending from EmberObject is deprecated.
|
|
@@ -4209,7 +4402,7 @@ const app = new EmberApp(defaults, {
|
|
|
4209
4402
|
}
|
|
4210
4403
|
});
|
|
4211
4404
|
\`\`\`
|
|
4212
|
-
`, /* inline-macro-config */getGlobalConfig().
|
|
4405
|
+
`, /* inline-macro-config */getGlobalConfig().WarpDriveMirror.deprecations.DISABLE_6X_DEPRECATIONS, {
|
|
4213
4406
|
id: 'ember-data-mirror:deprecate-store-extends-ember-object',
|
|
4214
4407
|
until: '6.0',
|
|
4215
4408
|
for: 'ember-data-mirror',
|
|
@@ -4274,12 +4467,9 @@ class Store extends BaseClass {
|
|
|
4274
4467
|
* import Fetch from '@ember-data-mirror/request/fetch';
|
|
4275
4468
|
*
|
|
4276
4469
|
* class extends Store {
|
|
4277
|
-
*
|
|
4278
|
-
*
|
|
4279
|
-
*
|
|
4280
|
-
* this.requestManager.use([Fetch]);
|
|
4281
|
-
* this.requestManager.useCache(CacheHandler);
|
|
4282
|
-
* }
|
|
4470
|
+
* requestManager = new RequestManager()
|
|
4471
|
+
* .use([Fetch])
|
|
4472
|
+
* .useCache(CacheHandler);
|
|
4283
4473
|
* }
|
|
4284
4474
|
* ```
|
|
4285
4475
|
*
|
|
@@ -4368,13 +4558,13 @@ class Store extends BaseClass {
|
|
|
4368
4558
|
this.isDestroyed = false;
|
|
4369
4559
|
}
|
|
4370
4560
|
_run(cb) {
|
|
4371
|
-
macroCondition(getGlobalConfig().
|
|
4561
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4372
4562
|
if (!test) {
|
|
4373
4563
|
throw new Error(`EmberData should never encounter a nested run`);
|
|
4374
4564
|
}
|
|
4375
4565
|
})(!this._cbs) : {};
|
|
4376
4566
|
const _cbs = this._cbs = {};
|
|
4377
|
-
if (macroCondition(getGlobalConfig().
|
|
4567
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
4378
4568
|
try {
|
|
4379
4569
|
cb();
|
|
4380
4570
|
if (_cbs.coalesce) {
|
|
@@ -4421,12 +4611,12 @@ class Store extends BaseClass {
|
|
|
4421
4611
|
}
|
|
4422
4612
|
}
|
|
4423
4613
|
_schedule(name, cb) {
|
|
4424
|
-
macroCondition(getGlobalConfig().
|
|
4614
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4425
4615
|
if (!test) {
|
|
4426
4616
|
throw new Error(`EmberData expects to schedule only when there is an active run`);
|
|
4427
4617
|
}
|
|
4428
4618
|
})(!!this._cbs) : {};
|
|
4429
|
-
macroCondition(getGlobalConfig().
|
|
4619
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4430
4620
|
if (!test) {
|
|
4431
4621
|
throw new Error(`EmberData expects only one flush per queue name, cannot schedule ${name}`);
|
|
4432
4622
|
}
|
|
@@ -4449,7 +4639,7 @@ class Store extends BaseClass {
|
|
|
4449
4639
|
return this._requestCache;
|
|
4450
4640
|
}
|
|
4451
4641
|
_getAllPending() {
|
|
4452
|
-
if (macroCondition(getGlobalConfig().
|
|
4642
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
|
|
4453
4643
|
const all = [];
|
|
4454
4644
|
const pending = this._requestCache._pending;
|
|
4455
4645
|
pending.forEach(requests => {
|
|
@@ -4521,33 +4711,37 @@ class Store extends BaseClass {
|
|
|
4521
4711
|
// the user has had the chance to set the prop.
|
|
4522
4712
|
const opts = {
|
|
4523
4713
|
store: this,
|
|
4524
|
-
[EnableHydration]: true
|
|
4714
|
+
[EnableHydration]: requestConfig[EnableHydration] ?? true
|
|
4525
4715
|
};
|
|
4526
4716
|
if (requestConfig.records) {
|
|
4527
4717
|
const identifierCache = this.identifierCache;
|
|
4528
4718
|
opts.records = requestConfig.records.map(r => identifierCache.getOrCreateRecordIdentifier(r));
|
|
4529
4719
|
}
|
|
4530
|
-
if (macroCondition(getGlobalConfig().
|
|
4720
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
|
|
4531
4721
|
if (this.DISABLE_WAITER) {
|
|
4532
4722
|
opts.disableTestWaiter = typeof requestConfig.disableTestWaiter === 'boolean' ? requestConfig.disableTestWaiter : true;
|
|
4533
4723
|
}
|
|
4534
4724
|
}
|
|
4535
|
-
if (macroCondition(getGlobalConfig().
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4725
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_REQUESTS)) {
|
|
4726
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_REQUESTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REQUESTS) {
|
|
4727
|
+
let options;
|
|
4728
|
+
try {
|
|
4729
|
+
options = JSON.parse(JSON.stringify(requestConfig));
|
|
4730
|
+
} catch {
|
|
4731
|
+
options = requestConfig;
|
|
4732
|
+
}
|
|
4733
|
+
// eslint-disable-next-line no-console
|
|
4734
|
+
console.log(`request: [[START]] ${requestConfig.op && !requestConfig.url ? '(LEGACY) ' : ''}${requestConfig.op || '<unknown operation>'} ${requestConfig.url || '<empty url>'} ${requestConfig.method || '<empty method>'}`, options);
|
|
4541
4735
|
}
|
|
4542
|
-
// eslint-disable-next-line no-console
|
|
4543
|
-
console.log(`request: [[START]] ${requestConfig.op && !requestConfig.url ? '(LEGACY) ' : ''}${requestConfig.op || '<unknown operation>'} ${requestConfig.url || '<empty url>'} ${requestConfig.method || '<empty method>'}`, options);
|
|
4544
4736
|
}
|
|
4545
4737
|
const request = Object.assign({}, requestConfig, opts);
|
|
4546
4738
|
const future = this.requestManager.request(request);
|
|
4547
4739
|
future.onFinalize(() => {
|
|
4548
|
-
if (macroCondition(getGlobalConfig().
|
|
4549
|
-
|
|
4550
|
-
|
|
4740
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_REQUESTS)) {
|
|
4741
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_REQUESTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REQUESTS) {
|
|
4742
|
+
// eslint-disable-next-line no-console
|
|
4743
|
+
console.log(`request: [[FINALIZE]] ${requestConfig.op && !requestConfig.url ? '(LEGACY) ' : ''}${requestConfig.op || '<unknown operation>'} ${requestConfig.url || '<empty url>'} ${requestConfig.method || '<empty method>'}`);
|
|
4744
|
+
}
|
|
4551
4745
|
}
|
|
4552
4746
|
// skip flush for legacy belongsTo
|
|
4553
4747
|
if (requestConfig.op === 'findBelongsTo' && !requestConfig.url) {
|
|
@@ -4610,15 +4804,15 @@ class Store extends BaseClass {
|
|
|
4610
4804
|
modelFor(type) {
|
|
4611
4805
|
// FIXME add deprecation and deprecation stripping
|
|
4612
4806
|
// FIXME/TODO update RFC to remove this method
|
|
4613
|
-
if (macroCondition(getGlobalConfig().
|
|
4807
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
4614
4808
|
assertDestroyedStoreOnly(this, 'modelFor');
|
|
4615
4809
|
}
|
|
4616
|
-
macroCondition(getGlobalConfig().
|
|
4810
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4617
4811
|
if (!test) {
|
|
4618
4812
|
throw new Error(`You need to pass <type> to the store's modelFor method`);
|
|
4619
4813
|
}
|
|
4620
4814
|
})(typeof type === 'string' && type.length) : {};
|
|
4621
|
-
macroCondition(getGlobalConfig().
|
|
4815
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4622
4816
|
if (!test) {
|
|
4623
4817
|
throw new Error(`No model was found for '${type}' and no schema handles the type`);
|
|
4624
4818
|
}
|
|
@@ -4654,15 +4848,15 @@ class Store extends BaseClass {
|
|
|
4654
4848
|
*/
|
|
4655
4849
|
|
|
4656
4850
|
createRecord(type, inputProperties) {
|
|
4657
|
-
if (macroCondition(getGlobalConfig().
|
|
4851
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
4658
4852
|
assertDestroyingStore(this, 'createRecord');
|
|
4659
4853
|
}
|
|
4660
|
-
macroCondition(getGlobalConfig().
|
|
4854
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4661
4855
|
if (!test) {
|
|
4662
4856
|
throw new Error(`You need to pass a model name to the store's createRecord method`);
|
|
4663
4857
|
}
|
|
4664
4858
|
})(type) : {};
|
|
4665
|
-
macroCondition(getGlobalConfig().
|
|
4859
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4666
4860
|
if (!test) {
|
|
4667
4861
|
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
|
|
4668
4862
|
}
|
|
@@ -4701,7 +4895,7 @@ class Store extends BaseClass {
|
|
|
4701
4895
|
};
|
|
4702
4896
|
if (resource.id) {
|
|
4703
4897
|
const identifier = this.identifierCache.peekRecordIdentifier(resource);
|
|
4704
|
-
macroCondition(getGlobalConfig().
|
|
4898
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4705
4899
|
if (!test) {
|
|
4706
4900
|
throw new Error(`The id ${String(properties.id)} has already been used with another '${normalizedModelName}' record.`);
|
|
4707
4901
|
}
|
|
@@ -4730,12 +4924,12 @@ class Store extends BaseClass {
|
|
|
4730
4924
|
@param {unknown} record
|
|
4731
4925
|
*/
|
|
4732
4926
|
deleteRecord(record) {
|
|
4733
|
-
if (macroCondition(getGlobalConfig().
|
|
4927
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
4734
4928
|
assertDestroyingStore(this, 'deleteRecord');
|
|
4735
4929
|
}
|
|
4736
4930
|
const identifier = peekRecordIdentifier(record);
|
|
4737
4931
|
const cache = this.cache;
|
|
4738
|
-
macroCondition(getGlobalConfig().
|
|
4932
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4739
4933
|
if (!test) {
|
|
4740
4934
|
throw new Error(`expected the record to be connected to a cache`);
|
|
4741
4935
|
}
|
|
@@ -4753,16 +4947,15 @@ class Store extends BaseClass {
|
|
|
4753
4947
|
This will cause the record to be destroyed and freed up for garbage collection.
|
|
4754
4948
|
Example
|
|
4755
4949
|
```javascript
|
|
4756
|
-
store.findRecord('post', '1')
|
|
4757
|
-
|
|
4758
|
-
});
|
|
4950
|
+
const { content: { data: post } } = await store.request(findRecord({ type: 'post', id: '1' }));
|
|
4951
|
+
store.unloadRecord(post);
|
|
4759
4952
|
```
|
|
4760
4953
|
@method unloadRecord
|
|
4761
4954
|
@public
|
|
4762
4955
|
@param {Model} record
|
|
4763
4956
|
*/
|
|
4764
4957
|
unloadRecord(record) {
|
|
4765
|
-
if (macroCondition(getGlobalConfig().
|
|
4958
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
4766
4959
|
assertDestroyingStore(this, 'unloadRecord');
|
|
4767
4960
|
}
|
|
4768
4961
|
const identifier = peekRecordIdentifier(record);
|
|
@@ -4781,43 +4974,43 @@ class Store extends BaseClass {
|
|
|
4781
4974
|
@private
|
|
4782
4975
|
*/
|
|
4783
4976
|
find(modelName, id, options) {
|
|
4784
|
-
if (macroCondition(getGlobalConfig().
|
|
4977
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
4785
4978
|
assertDestroyingStore(this, 'find');
|
|
4786
4979
|
}
|
|
4787
4980
|
// The default `model` hook in Route calls `find(modelName, id)`,
|
|
4788
4981
|
// that's why we have to keep this method around even though `findRecord` is
|
|
4789
4982
|
// the public way to get a record by modelName and id.
|
|
4790
|
-
macroCondition(getGlobalConfig().
|
|
4983
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4791
4984
|
if (!test) {
|
|
4792
4985
|
throw new Error(`Using store.find(type) has been removed. Use store.findAll(modelName) to retrieve all records for a given type.`);
|
|
4793
4986
|
}
|
|
4794
4987
|
})(arguments.length !== 1) : {};
|
|
4795
|
-
macroCondition(getGlobalConfig().
|
|
4988
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4796
4989
|
if (!test) {
|
|
4797
4990
|
throw new Error(`Calling store.find(modelName, id, { preload: preload }) is no longer supported. Use store.findRecord(modelName, id, { preload: preload }) instead.`);
|
|
4798
4991
|
}
|
|
4799
4992
|
})(!options) : {};
|
|
4800
|
-
macroCondition(getGlobalConfig().
|
|
4993
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4801
4994
|
if (!test) {
|
|
4802
4995
|
throw new Error(`You need to pass the model name and id to the store's find method`);
|
|
4803
4996
|
}
|
|
4804
4997
|
})(arguments.length === 2) : {};
|
|
4805
|
-
macroCondition(getGlobalConfig().
|
|
4998
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4806
4999
|
if (!test) {
|
|
4807
5000
|
throw new Error(`You cannot pass '${id}' as id to the store's find method`);
|
|
4808
5001
|
}
|
|
4809
5002
|
})(typeof id === 'string' || typeof id === 'number') : {};
|
|
4810
|
-
macroCondition(getGlobalConfig().
|
|
5003
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4811
5004
|
if (!test) {
|
|
4812
5005
|
throw new Error(`Calling store.find() with a query object is no longer supported. Use store.query() instead.`);
|
|
4813
5006
|
}
|
|
4814
5007
|
})(typeof id !== 'object') : {};
|
|
4815
|
-
macroCondition(getGlobalConfig().
|
|
5008
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4816
5009
|
if (!test) {
|
|
4817
5010
|
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`);
|
|
4818
5011
|
}
|
|
4819
5012
|
})(typeof modelName === 'string') : {};
|
|
4820
|
-
if (macroCondition(getGlobalConfig().
|
|
5013
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_STORE_FIND)) {
|
|
4821
5014
|
deprecate(`Using store.find is deprecated, use store.findRecord instead. Likely this means you are relying on the implicit store fetching behavior of routes unknowingly.`, false, {
|
|
4822
5015
|
id: 'ember-data-mirror:deprecate-store-find',
|
|
4823
5016
|
since: {
|
|
@@ -4829,7 +5022,7 @@ class Store extends BaseClass {
|
|
|
4829
5022
|
});
|
|
4830
5023
|
return this.findRecord(modelName, id);
|
|
4831
5024
|
}
|
|
4832
|
-
macroCondition(getGlobalConfig().
|
|
5025
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
4833
5026
|
{
|
|
4834
5027
|
throw new Error(`store.find has been removed. Use store.findRecord instead.`);
|
|
4835
5028
|
}
|
|
@@ -5115,10 +5308,10 @@ class Store extends BaseClass {
|
|
|
5115
5308
|
*/
|
|
5116
5309
|
|
|
5117
5310
|
findRecord(resource, id, options) {
|
|
5118
|
-
if (macroCondition(getGlobalConfig().
|
|
5311
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5119
5312
|
assertDestroyingStore(this, 'findRecord');
|
|
5120
5313
|
}
|
|
5121
|
-
macroCondition(getGlobalConfig().
|
|
5314
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5122
5315
|
if (!test) {
|
|
5123
5316
|
throw new Error(`You need to pass a modelName or resource identifier as the first argument to the store's findRecord method`);
|
|
5124
5317
|
}
|
|
@@ -5126,7 +5319,7 @@ class Store extends BaseClass {
|
|
|
5126
5319
|
if (isMaybeIdentifier(resource)) {
|
|
5127
5320
|
options = id;
|
|
5128
5321
|
} else {
|
|
5129
|
-
macroCondition(getGlobalConfig().
|
|
5322
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5130
5323
|
if (!test) {
|
|
5131
5324
|
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${resource}`);
|
|
5132
5325
|
}
|
|
@@ -5158,7 +5351,7 @@ class Store extends BaseClass {
|
|
|
5158
5351
|
[SkipCache]: true
|
|
5159
5352
|
}
|
|
5160
5353
|
});
|
|
5161
|
-
if (macroCondition(getGlobalConfig().
|
|
5354
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_PROMISE_PROXIES)) {
|
|
5162
5355
|
return promiseObject(promise.then(document => {
|
|
5163
5356
|
return document.content;
|
|
5164
5357
|
}));
|
|
@@ -5199,7 +5392,7 @@ class Store extends BaseClass {
|
|
|
5199
5392
|
*/
|
|
5200
5393
|
// TODO @deprecate getReference (and references generally)
|
|
5201
5394
|
getReference(resource, id) {
|
|
5202
|
-
if (macroCondition(getGlobalConfig().
|
|
5395
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5203
5396
|
assertDestroyingStore(this, 'getReference');
|
|
5204
5397
|
}
|
|
5205
5398
|
let resourceIdentifier;
|
|
@@ -5210,7 +5403,7 @@ class Store extends BaseClass {
|
|
|
5210
5403
|
const normalizedId = ensureStringId(id);
|
|
5211
5404
|
resourceIdentifier = constructResource(type, normalizedId);
|
|
5212
5405
|
}
|
|
5213
|
-
macroCondition(getGlobalConfig().
|
|
5406
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5214
5407
|
if (!test) {
|
|
5215
5408
|
throw new Error('getReference expected to receive either a resource identifier or type and id as arguments');
|
|
5216
5409
|
}
|
|
@@ -5262,15 +5455,15 @@ class Store extends BaseClass {
|
|
|
5262
5455
|
// this is basically an "are we not empty" query.
|
|
5263
5456
|
return isLoaded ? this._instanceCache.getRecord(stableIdentifier) : null;
|
|
5264
5457
|
}
|
|
5265
|
-
if (macroCondition(getGlobalConfig().
|
|
5458
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5266
5459
|
assertDestroyingStore(this, 'peekRecord');
|
|
5267
5460
|
}
|
|
5268
|
-
macroCondition(getGlobalConfig().
|
|
5461
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5269
5462
|
if (!test) {
|
|
5270
5463
|
throw new Error(`You need to pass a model name to the store's peekRecord method`);
|
|
5271
5464
|
}
|
|
5272
5465
|
})(identifier) : {};
|
|
5273
|
-
macroCondition(getGlobalConfig().
|
|
5466
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5274
5467
|
if (!test) {
|
|
5275
5468
|
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${String(identifier)}`);
|
|
5276
5469
|
}
|
|
@@ -5305,7 +5498,7 @@ class Store extends BaseClass {
|
|
|
5305
5498
|
@return {Boolean}
|
|
5306
5499
|
*/
|
|
5307
5500
|
hasRecordForId(modelName, id) {
|
|
5308
|
-
if (macroCondition(getGlobalConfig().
|
|
5501
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_HAS_RECORD)) {
|
|
5309
5502
|
deprecate(`store.hasRecordForId has been deprecated in favor of store.peekRecord`, false, {
|
|
5310
5503
|
id: 'ember-data-mirror:deprecate-has-record-for-id',
|
|
5311
5504
|
since: {
|
|
@@ -5315,15 +5508,15 @@ class Store extends BaseClass {
|
|
|
5315
5508
|
until: '5.0',
|
|
5316
5509
|
for: 'ember-data-mirror'
|
|
5317
5510
|
});
|
|
5318
|
-
if (macroCondition(getGlobalConfig().
|
|
5511
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5319
5512
|
assertDestroyingStore(this, 'hasRecordForId');
|
|
5320
5513
|
}
|
|
5321
|
-
macroCondition(getGlobalConfig().
|
|
5514
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5322
5515
|
if (!test) {
|
|
5323
5516
|
throw new Error(`You need to pass a model name to the store's hasRecordForId method`);
|
|
5324
5517
|
}
|
|
5325
5518
|
})(modelName) : {};
|
|
5326
|
-
macroCondition(getGlobalConfig().
|
|
5519
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5327
5520
|
if (!test) {
|
|
5328
5521
|
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${modelName}`);
|
|
5329
5522
|
}
|
|
@@ -5337,7 +5530,7 @@ class Store extends BaseClass {
|
|
|
5337
5530
|
const identifier = this.identifierCache.peekRecordIdentifier(resource);
|
|
5338
5531
|
return Boolean(identifier && this._instanceCache.recordIsLoaded(identifier));
|
|
5339
5532
|
}
|
|
5340
|
-
macroCondition(getGlobalConfig().
|
|
5533
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5341
5534
|
{
|
|
5342
5535
|
throw new Error(`store.hasRecordForId has been removed`);
|
|
5343
5536
|
}
|
|
@@ -5383,20 +5576,20 @@ class Store extends BaseClass {
|
|
|
5383
5576
|
*/
|
|
5384
5577
|
|
|
5385
5578
|
query(type, query, options = {}) {
|
|
5386
|
-
if (macroCondition(getGlobalConfig().
|
|
5579
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5387
5580
|
assertDestroyingStore(this, 'query');
|
|
5388
5581
|
}
|
|
5389
|
-
macroCondition(getGlobalConfig().
|
|
5582
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5390
5583
|
if (!test) {
|
|
5391
5584
|
throw new Error(`You need to pass a model name to the store's query method`);
|
|
5392
5585
|
}
|
|
5393
5586
|
})(type) : {};
|
|
5394
|
-
macroCondition(getGlobalConfig().
|
|
5587
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5395
5588
|
if (!test) {
|
|
5396
5589
|
throw new Error(`You need to pass a query hash to the store's query method`);
|
|
5397
5590
|
}
|
|
5398
5591
|
})(query) : {};
|
|
5399
|
-
macroCondition(getGlobalConfig().
|
|
5592
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5400
5593
|
if (!test) {
|
|
5401
5594
|
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
|
|
5402
5595
|
}
|
|
@@ -5412,7 +5605,7 @@ class Store extends BaseClass {
|
|
|
5412
5605
|
[SkipCache]: true
|
|
5413
5606
|
}
|
|
5414
5607
|
});
|
|
5415
|
-
if (macroCondition(getGlobalConfig().
|
|
5608
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_PROMISE_PROXIES)) {
|
|
5416
5609
|
return promiseArray(promise.then(document => document.content));
|
|
5417
5610
|
}
|
|
5418
5611
|
return promise.then(document => document.content);
|
|
@@ -5501,20 +5694,20 @@ class Store extends BaseClass {
|
|
|
5501
5694
|
*/
|
|
5502
5695
|
|
|
5503
5696
|
queryRecord(type, query, options) {
|
|
5504
|
-
if (macroCondition(getGlobalConfig().
|
|
5697
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5505
5698
|
assertDestroyingStore(this, 'queryRecord');
|
|
5506
5699
|
}
|
|
5507
|
-
macroCondition(getGlobalConfig().
|
|
5700
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5508
5701
|
if (!test) {
|
|
5509
5702
|
throw new Error(`You need to pass a model name to the store's queryRecord method`);
|
|
5510
5703
|
}
|
|
5511
5704
|
})(type) : {};
|
|
5512
|
-
macroCondition(getGlobalConfig().
|
|
5705
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5513
5706
|
if (!test) {
|
|
5514
5707
|
throw new Error(`You need to pass a query hash to the store's queryRecord method`);
|
|
5515
5708
|
}
|
|
5516
5709
|
})(query) : {};
|
|
5517
|
-
macroCondition(getGlobalConfig().
|
|
5710
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5518
5711
|
if (!test) {
|
|
5519
5712
|
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
|
|
5520
5713
|
}
|
|
@@ -5530,7 +5723,7 @@ class Store extends BaseClass {
|
|
|
5530
5723
|
[SkipCache]: true
|
|
5531
5724
|
}
|
|
5532
5725
|
});
|
|
5533
|
-
if (macroCondition(getGlobalConfig().
|
|
5726
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_PROMISE_PROXIES)) {
|
|
5534
5727
|
return promiseObject(promise.then(document => document.content));
|
|
5535
5728
|
}
|
|
5536
5729
|
return promise.then(document => document.content);
|
|
@@ -5684,15 +5877,15 @@ class Store extends BaseClass {
|
|
|
5684
5877
|
*/
|
|
5685
5878
|
|
|
5686
5879
|
findAll(type, options = {}) {
|
|
5687
|
-
if (macroCondition(getGlobalConfig().
|
|
5880
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5688
5881
|
assertDestroyingStore(this, 'findAll');
|
|
5689
5882
|
}
|
|
5690
|
-
macroCondition(getGlobalConfig().
|
|
5883
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5691
5884
|
if (!test) {
|
|
5692
5885
|
throw new Error(`You need to pass a model name to the store's findAll method`);
|
|
5693
5886
|
}
|
|
5694
5887
|
})(type) : {};
|
|
5695
|
-
macroCondition(getGlobalConfig().
|
|
5888
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5696
5889
|
if (!test) {
|
|
5697
5890
|
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
|
|
5698
5891
|
}
|
|
@@ -5707,7 +5900,7 @@ class Store extends BaseClass {
|
|
|
5707
5900
|
[SkipCache]: true
|
|
5708
5901
|
}
|
|
5709
5902
|
});
|
|
5710
|
-
if (macroCondition(getGlobalConfig().
|
|
5903
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_PROMISE_PROXIES)) {
|
|
5711
5904
|
return promiseArray(promise.then(document => document.content));
|
|
5712
5905
|
}
|
|
5713
5906
|
return promise.then(document => document.content);
|
|
@@ -5735,15 +5928,15 @@ class Store extends BaseClass {
|
|
|
5735
5928
|
*/
|
|
5736
5929
|
|
|
5737
5930
|
peekAll(type) {
|
|
5738
|
-
if (macroCondition(getGlobalConfig().
|
|
5931
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5739
5932
|
assertDestroyingStore(this, 'peekAll');
|
|
5740
5933
|
}
|
|
5741
|
-
macroCondition(getGlobalConfig().
|
|
5934
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5742
5935
|
if (!test) {
|
|
5743
5936
|
throw new Error(`You need to pass a model name to the store's peekAll method`);
|
|
5744
5937
|
}
|
|
5745
5938
|
})(type) : {};
|
|
5746
|
-
macroCondition(getGlobalConfig().
|
|
5939
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5747
5940
|
if (!test) {
|
|
5748
5941
|
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
|
|
5749
5942
|
}
|
|
@@ -5765,10 +5958,10 @@ class Store extends BaseClass {
|
|
|
5765
5958
|
*/
|
|
5766
5959
|
|
|
5767
5960
|
unloadAll(type) {
|
|
5768
|
-
if (macroCondition(getGlobalConfig().
|
|
5961
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5769
5962
|
assertDestroyedStoreOnly(this, 'unloadAll');
|
|
5770
5963
|
}
|
|
5771
|
-
macroCondition(getGlobalConfig().
|
|
5964
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5772
5965
|
if (!test) {
|
|
5773
5966
|
throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${String(type)}`);
|
|
5774
5967
|
}
|
|
@@ -5919,7 +6112,7 @@ class Store extends BaseClass {
|
|
|
5919
6112
|
*/
|
|
5920
6113
|
|
|
5921
6114
|
push(data) {
|
|
5922
|
-
if (macroCondition(getGlobalConfig().
|
|
6115
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5923
6116
|
assertDestroyingStore(this, 'push');
|
|
5924
6117
|
}
|
|
5925
6118
|
const pushed = this._push(data, false);
|
|
@@ -5941,17 +6134,19 @@ class Store extends BaseClass {
|
|
|
5941
6134
|
@return {StableRecordIdentifier|Array<StableRecordIdentifier>|null} identifiers for the primary records that had data loaded
|
|
5942
6135
|
*/
|
|
5943
6136
|
_push(jsonApiDoc, asyncFlush) {
|
|
5944
|
-
if (macroCondition(getGlobalConfig().
|
|
6137
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5945
6138
|
assertDestroyingStore(this, '_push');
|
|
5946
6139
|
}
|
|
5947
|
-
if (macroCondition(getGlobalConfig().
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
6140
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_PAYLOADS)) {
|
|
6141
|
+
if (getGlobalConfig().WarpDriveMirror.debug.LOG_PAYLOADS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_PAYLOADS) {
|
|
6142
|
+
try {
|
|
6143
|
+
const data = JSON.parse(JSON.stringify(jsonApiDoc));
|
|
6144
|
+
// eslint-disable-next-line no-console
|
|
6145
|
+
console.log('EmberData | Payload - push', data);
|
|
6146
|
+
} catch {
|
|
6147
|
+
// eslint-disable-next-line no-console
|
|
6148
|
+
console.log('EmberData | Payload - push', jsonApiDoc);
|
|
6149
|
+
}
|
|
5955
6150
|
}
|
|
5956
6151
|
}
|
|
5957
6152
|
if (asyncFlush) {
|
|
@@ -5979,10 +6174,10 @@ class Store extends BaseClass {
|
|
|
5979
6174
|
* @return {Promise<record>}
|
|
5980
6175
|
*/
|
|
5981
6176
|
saveRecord(record, options = {}) {
|
|
5982
|
-
if (macroCondition(getGlobalConfig().
|
|
6177
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
5983
6178
|
assertDestroyingStore(this, 'saveRecord');
|
|
5984
6179
|
}
|
|
5985
|
-
macroCondition(getGlobalConfig().
|
|
6180
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5986
6181
|
if (!test) {
|
|
5987
6182
|
throw new Error(`Unable to initiate save for a record in a disconnected state`);
|
|
5988
6183
|
}
|
|
@@ -5994,7 +6189,7 @@ class Store extends BaseClass {
|
|
|
5994
6189
|
// but just in case we reject here to prevent bad things.
|
|
5995
6190
|
return Promise.reject(new Error(`Record Is Disconnected`));
|
|
5996
6191
|
}
|
|
5997
|
-
macroCondition(getGlobalConfig().
|
|
6192
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
5998
6193
|
if (!test) {
|
|
5999
6194
|
throw new Error(`Cannot initiate a save request for an unloaded record: ${identifier.lid}`);
|
|
6000
6195
|
}
|
|
@@ -6051,7 +6246,7 @@ class Store extends BaseClass {
|
|
|
6051
6246
|
} = this._instanceCache;
|
|
6052
6247
|
if (!cache) {
|
|
6053
6248
|
cache = this._instanceCache.cache = this.createCache(this._instanceCache._storeWrapper);
|
|
6054
|
-
if (macroCondition(getGlobalConfig().
|
|
6249
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
6055
6250
|
cache = new CacheManager(cache);
|
|
6056
6251
|
}
|
|
6057
6252
|
}
|
|
@@ -6075,14 +6270,14 @@ class Store extends BaseClass {
|
|
|
6075
6270
|
return new this(args);
|
|
6076
6271
|
}
|
|
6077
6272
|
}
|
|
6078
|
-
if (macroCondition(getGlobalConfig().
|
|
6273
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.ENABLE_LEGACY_SCHEMA_SERVICE)) {
|
|
6079
6274
|
Store.prototype.getSchemaDefinitionService = function () {
|
|
6080
|
-
macroCondition(getGlobalConfig().
|
|
6275
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6081
6276
|
if (!test) {
|
|
6082
6277
|
throw new Error(`You must registerSchemaDefinitionService with the store to use custom model classes`);
|
|
6083
6278
|
}
|
|
6084
6279
|
})(this._schema) : {};
|
|
6085
|
-
deprecate(`Use \`store.schema\` instead of \`store.getSchemaDefinitionService()\``, /* inline-macro-config */getGlobalConfig().
|
|
6280
|
+
deprecate(`Use \`store.schema\` instead of \`store.getSchemaDefinitionService()\``, /* inline-macro-config */getGlobalConfig().WarpDriveMirror.deprecations.DISABLE_6X_DEPRECATIONS, {
|
|
6086
6281
|
id: 'ember-data-mirror:schema-service-updates',
|
|
6087
6282
|
until: '6.0',
|
|
6088
6283
|
for: 'ember-data-mirror',
|
|
@@ -6094,7 +6289,7 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA
|
|
|
6094
6289
|
return this._schema;
|
|
6095
6290
|
};
|
|
6096
6291
|
Store.prototype.registerSchemaDefinitionService = function (schema) {
|
|
6097
|
-
deprecate(`Use \`store.createSchemaService\` instead of \`store.registerSchemaDefinitionService()\``, /* inline-macro-config */getGlobalConfig().
|
|
6292
|
+
deprecate(`Use \`store.createSchemaService\` instead of \`store.registerSchemaDefinitionService()\``, /* inline-macro-config */getGlobalConfig().WarpDriveMirror.deprecations.DISABLE_6X_DEPRECATIONS, {
|
|
6098
6293
|
id: 'ember-data-mirror:schema-service-updates',
|
|
6099
6294
|
until: '6.0',
|
|
6100
6295
|
for: 'ember-data-mirror',
|
|
@@ -6106,7 +6301,7 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA
|
|
|
6106
6301
|
this._schema = schema;
|
|
6107
6302
|
};
|
|
6108
6303
|
Store.prototype.registerSchema = function (schema) {
|
|
6109
|
-
deprecate(`Use \`store.createSchemaService\` instead of \`store.registerSchema()\``, /* inline-macro-config */getGlobalConfig().
|
|
6304
|
+
deprecate(`Use \`store.createSchemaService\` instead of \`store.registerSchema()\``, /* inline-macro-config */getGlobalConfig().WarpDriveMirror.deprecations.DISABLE_6X_DEPRECATIONS, {
|
|
6110
6305
|
id: 'ember-data-mirror:schema-service-updates',
|
|
6111
6306
|
until: '6.0',
|
|
6112
6307
|
for: 'ember-data-mirror',
|
|
@@ -6120,10 +6315,10 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA
|
|
|
6120
6315
|
}
|
|
6121
6316
|
let assertDestroyingStore;
|
|
6122
6317
|
let assertDestroyedStoreOnly;
|
|
6123
|
-
if (macroCondition(getGlobalConfig().
|
|
6318
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
6124
6319
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
6125
6320
|
assertDestroyingStore = function assertDestroyingStore(store, method) {
|
|
6126
|
-
macroCondition(getGlobalConfig().
|
|
6321
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6127
6322
|
if (!test) {
|
|
6128
6323
|
throw new Error(`Attempted to call store.${method}(), but the store instance has already been destroyed.`);
|
|
6129
6324
|
}
|
|
@@ -6131,7 +6326,7 @@ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
|
6131
6326
|
};
|
|
6132
6327
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
6133
6328
|
assertDestroyedStoreOnly = function assertDestroyedStoreOnly(store, method) {
|
|
6134
|
-
macroCondition(getGlobalConfig().
|
|
6329
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6135
6330
|
if (!test) {
|
|
6136
6331
|
throw new Error(`Attempted to call store.${method}(), but the store instance has already been destroyed.`);
|
|
6137
6332
|
}
|
|
@@ -6145,13 +6340,13 @@ function normalizeProperties(store, identifier, properties) {
|
|
|
6145
6340
|
// assert here
|
|
6146
6341
|
if (properties !== undefined) {
|
|
6147
6342
|
if ('id' in properties) {
|
|
6148
|
-
macroCondition(getGlobalConfig().
|
|
6343
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6149
6344
|
if (!test) {
|
|
6150
6345
|
throw new Error(`expected id to be a string or null`);
|
|
6151
6346
|
}
|
|
6152
6347
|
})(properties.id !== undefined) : {};
|
|
6153
6348
|
}
|
|
6154
|
-
macroCondition(getGlobalConfig().
|
|
6349
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6155
6350
|
if (!test) {
|
|
6156
6351
|
throw new Error(`You passed '${typeof properties}' as properties for record creation instead of an object.`);
|
|
6157
6352
|
}
|
|
@@ -6171,12 +6366,12 @@ function normalizeProperties(store, identifier, properties) {
|
|
|
6171
6366
|
const field = defs.get(prop);
|
|
6172
6367
|
if (!field) continue;
|
|
6173
6368
|
if (field.kind === 'hasMany') {
|
|
6174
|
-
if (macroCondition(getGlobalConfig().
|
|
6369
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
|
|
6175
6370
|
assertRecordsPassedToHasMany(properties[prop]);
|
|
6176
6371
|
}
|
|
6177
|
-
properties[prop] = extractIdentifiersFromRecords(properties[prop]);
|
|
6372
|
+
properties[prop] = extractIdentifiersFromRecords$1(properties[prop]);
|
|
6178
6373
|
} else if (field.kind === 'belongsTo') {
|
|
6179
|
-
properties[prop] = extractIdentifierFromRecord(properties[prop]);
|
|
6374
|
+
properties[prop] = extractIdentifierFromRecord$1(properties[prop]);
|
|
6180
6375
|
}
|
|
6181
6376
|
}
|
|
6182
6377
|
}
|
|
@@ -6184,12 +6379,12 @@ function normalizeProperties(store, identifier, properties) {
|
|
|
6184
6379
|
return properties;
|
|
6185
6380
|
}
|
|
6186
6381
|
function assertRecordsPassedToHasMany(records) {
|
|
6187
|
-
macroCondition(getGlobalConfig().
|
|
6382
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6188
6383
|
if (!test) {
|
|
6189
6384
|
throw new Error(`You must pass an array of records to set a hasMany relationship`);
|
|
6190
6385
|
}
|
|
6191
6386
|
})(Array.isArray(records)) : {};
|
|
6192
|
-
macroCondition(getGlobalConfig().
|
|
6387
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6193
6388
|
if (!test) {
|
|
6194
6389
|
throw new Error(`All elements of a hasMany relationship must be instances of Model, you passed ${records.map(r => `${typeof r}`).join(', ')}`);
|
|
6195
6390
|
}
|
|
@@ -6204,18 +6399,18 @@ function assertRecordsPassedToHasMany(records) {
|
|
|
6204
6399
|
});
|
|
6205
6400
|
}()) : {};
|
|
6206
6401
|
}
|
|
6207
|
-
function extractIdentifiersFromRecords(records) {
|
|
6208
|
-
return records.map(record => extractIdentifierFromRecord(record));
|
|
6402
|
+
function extractIdentifiersFromRecords$1(records) {
|
|
6403
|
+
return records.map(record => extractIdentifierFromRecord$1(record));
|
|
6209
6404
|
}
|
|
6210
|
-
function extractIdentifierFromRecord(recordOrPromiseRecord) {
|
|
6405
|
+
function extractIdentifierFromRecord$1(recordOrPromiseRecord) {
|
|
6211
6406
|
if (!recordOrPromiseRecord) {
|
|
6212
6407
|
return null;
|
|
6213
6408
|
}
|
|
6214
6409
|
const extract = recordIdentifierFor;
|
|
6215
|
-
if (macroCondition(getGlobalConfig().
|
|
6216
|
-
if (isPromiseRecord(recordOrPromiseRecord)) {
|
|
6410
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_PROMISE_PROXIES)) {
|
|
6411
|
+
if (isPromiseRecord$1(recordOrPromiseRecord)) {
|
|
6217
6412
|
const content = recordOrPromiseRecord.content;
|
|
6218
|
-
macroCondition(getGlobalConfig().
|
|
6413
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6219
6414
|
if (!test) {
|
|
6220
6415
|
throw new Error('You passed in a promise that did not originate from an EmberData relationship. You can only pass promises that come from a belongsTo or hasMany relationship to the get call.');
|
|
6221
6416
|
}
|
|
@@ -6234,7 +6429,7 @@ function extractIdentifierFromRecord(recordOrPromiseRecord) {
|
|
|
6234
6429
|
}
|
|
6235
6430
|
return extract(recordOrPromiseRecord);
|
|
6236
6431
|
}
|
|
6237
|
-
function isPromiseRecord(record) {
|
|
6432
|
+
function isPromiseRecord$1(record) {
|
|
6238
6433
|
return typeof record === 'object' && !!record && 'then' in record && typeof record.then === 'function';
|
|
6239
6434
|
}
|
|
6240
6435
|
|
|
@@ -6342,7 +6537,7 @@ class Document {
|
|
|
6342
6537
|
* @return Promise<Document>
|
|
6343
6538
|
*/
|
|
6344
6539
|
fetch(options = {}) {
|
|
6345
|
-
macroCondition(getGlobalConfig().
|
|
6540
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6346
6541
|
if (!test) {
|
|
6347
6542
|
throw new Error(`No self or related link`);
|
|
6348
6543
|
}
|
|
@@ -6621,7 +6816,7 @@ const CacheHandler = {
|
|
|
6621
6816
|
}
|
|
6622
6817
|
store.requestManager._pending.set(context.id, promise);
|
|
6623
6818
|
}
|
|
6624
|
-
macroCondition(getGlobalConfig().
|
|
6819
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6625
6820
|
if (!test) {
|
|
6626
6821
|
throw new Error(`Expected a peeked request to be present`);
|
|
6627
6822
|
}
|
|
@@ -6649,7 +6844,7 @@ function maybeUpdateUiObjects(store, request, options, document, isFromCache) {
|
|
|
6649
6844
|
identifier
|
|
6650
6845
|
} = options;
|
|
6651
6846
|
if (!document) {
|
|
6652
|
-
macroCondition(getGlobalConfig().
|
|
6847
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6653
6848
|
if (!test) {
|
|
6654
6849
|
throw new Error(`The CacheHandler expected response content but none was found`);
|
|
6655
6850
|
}
|
|
@@ -6841,7 +7036,7 @@ function fetchContentAndHydrate(next, context, identifier, priority) {
|
|
|
6841
7036
|
isMut = true;
|
|
6842
7037
|
// TODO should we handle multiple records in request.records by iteratively calling willCommit for each
|
|
6843
7038
|
const record = context.request.data?.record || context.request.records?.[0];
|
|
6844
|
-
macroCondition(getGlobalConfig().
|
|
7039
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6845
7040
|
if (!test) {
|
|
6846
7041
|
throw new Error(`Expected to receive a list of records included in the ${context.request.op} request`);
|
|
6847
7042
|
}
|
|
@@ -6861,7 +7056,7 @@ function fetchContentAndHydrate(next, context, identifier, priority) {
|
|
|
6861
7056
|
if (!isMut) {
|
|
6862
7057
|
return promise;
|
|
6863
7058
|
}
|
|
6864
|
-
macroCondition(getGlobalConfig().
|
|
7059
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
6865
7060
|
if (!test) {
|
|
6866
7061
|
throw new Error(`Expected a mutation`);
|
|
6867
7062
|
}
|
|
@@ -6882,6 +7077,503 @@ function fetchContentAndHydrate(next, context, identifier, priority) {
|
|
|
6882
7077
|
/**
|
|
6883
7078
|
@module @ember-data-mirror/store
|
|
6884
7079
|
*/
|
|
7080
|
+
/**
|
|
7081
|
+
A `ManyArray` is a `MutableArray` that represents the contents of a has-many
|
|
7082
|
+
relationship.
|
|
7083
|
+
|
|
7084
|
+
The `ManyArray` is instantiated lazily the first time the relationship is
|
|
7085
|
+
requested.
|
|
7086
|
+
|
|
7087
|
+
This class is not intended to be directly instantiated by consuming applications.
|
|
7088
|
+
|
|
7089
|
+
### Inverses
|
|
7090
|
+
|
|
7091
|
+
Often, the relationships in Ember Data applications will have
|
|
7092
|
+
an inverse. For example, imagine the following models are
|
|
7093
|
+
defined:
|
|
7094
|
+
|
|
7095
|
+
```app/models/post.js
|
|
7096
|
+
import Model, { hasMany } from '@ember-data-mirror/model';
|
|
7097
|
+
|
|
7098
|
+
export default class PostModel extends Model {
|
|
7099
|
+
@hasMany('comment') comments;
|
|
7100
|
+
}
|
|
7101
|
+
```
|
|
7102
|
+
|
|
7103
|
+
```app/models/comment.js
|
|
7104
|
+
import Model, { belongsTo } from '@ember-data-mirror/model';
|
|
7105
|
+
|
|
7106
|
+
export default class CommentModel extends Model {
|
|
7107
|
+
@belongsTo('post') post;
|
|
7108
|
+
}
|
|
7109
|
+
```
|
|
7110
|
+
|
|
7111
|
+
If you created a new instance of `Post` and added
|
|
7112
|
+
a `Comment` record to its `comments` has-many
|
|
7113
|
+
relationship, you would expect the comment's `post`
|
|
7114
|
+
property to be set to the post that contained
|
|
7115
|
+
the has-many.
|
|
7116
|
+
|
|
7117
|
+
We call the record to which a relationship belongs-to the
|
|
7118
|
+
relationship's _owner_.
|
|
7119
|
+
|
|
7120
|
+
@class ManyArray
|
|
7121
|
+
@public
|
|
7122
|
+
*/
|
|
7123
|
+
class RelatedCollection extends IdentifierArray {
|
|
7124
|
+
/**
|
|
7125
|
+
The loading state of this array
|
|
7126
|
+
@property {Boolean} isLoaded
|
|
7127
|
+
@public
|
|
7128
|
+
*/
|
|
7129
|
+
|
|
7130
|
+
/**
|
|
7131
|
+
`true` if the relationship is polymorphic, `false` otherwise.
|
|
7132
|
+
@property {Boolean} isPolymorphic
|
|
7133
|
+
@private
|
|
7134
|
+
*/
|
|
7135
|
+
|
|
7136
|
+
/**
|
|
7137
|
+
Metadata associated with the request for async hasMany relationships.
|
|
7138
|
+
Example
|
|
7139
|
+
Given that the server returns the following JSON payload when fetching a
|
|
7140
|
+
hasMany relationship:
|
|
7141
|
+
```js
|
|
7142
|
+
{
|
|
7143
|
+
"comments": [{
|
|
7144
|
+
"id": 1,
|
|
7145
|
+
"comment": "This is the first comment",
|
|
7146
|
+
}, {
|
|
7147
|
+
// ...
|
|
7148
|
+
}],
|
|
7149
|
+
"meta": {
|
|
7150
|
+
"page": 1,
|
|
7151
|
+
"total": 5
|
|
7152
|
+
}
|
|
7153
|
+
}
|
|
7154
|
+
```
|
|
7155
|
+
You can then access the meta data via the `meta` property:
|
|
7156
|
+
```js
|
|
7157
|
+
let comments = await post.comments;
|
|
7158
|
+
let meta = comments.meta;
|
|
7159
|
+
// meta.page => 1
|
|
7160
|
+
// meta.total => 5
|
|
7161
|
+
```
|
|
7162
|
+
@property {Object | null} meta
|
|
7163
|
+
@public
|
|
7164
|
+
*/
|
|
7165
|
+
|
|
7166
|
+
/**
|
|
7167
|
+
* Retrieve the links for this relationship
|
|
7168
|
+
*
|
|
7169
|
+
@property {Object | null} links
|
|
7170
|
+
@public
|
|
7171
|
+
*/
|
|
7172
|
+
|
|
7173
|
+
constructor(options) {
|
|
7174
|
+
super(options);
|
|
7175
|
+
this.isLoaded = options.isLoaded || false;
|
|
7176
|
+
this.isAsync = options.isAsync || false;
|
|
7177
|
+
this.isPolymorphic = options.isPolymorphic || false;
|
|
7178
|
+
this.identifier = options.identifier;
|
|
7179
|
+
this.key = options.key;
|
|
7180
|
+
}
|
|
7181
|
+
[MUTATE](target, receiver, prop, args, _SIGNAL) {
|
|
7182
|
+
switch (prop) {
|
|
7183
|
+
case 'length 0':
|
|
7184
|
+
{
|
|
7185
|
+
Reflect.set(target, 'length', 0);
|
|
7186
|
+
mutateReplaceRelatedRecords(this, [], _SIGNAL);
|
|
7187
|
+
return true;
|
|
7188
|
+
}
|
|
7189
|
+
case 'replace cell':
|
|
7190
|
+
{
|
|
7191
|
+
const [index, prior, value] = args;
|
|
7192
|
+
target[index] = value;
|
|
7193
|
+
mutateReplaceRelatedRecord(this, {
|
|
7194
|
+
value,
|
|
7195
|
+
prior,
|
|
7196
|
+
index
|
|
7197
|
+
}, _SIGNAL);
|
|
7198
|
+
return true;
|
|
7199
|
+
}
|
|
7200
|
+
case 'push':
|
|
7201
|
+
{
|
|
7202
|
+
const newValues = extractIdentifiersFromRecords(args);
|
|
7203
|
+
assertNoDuplicates(this, target, currentState => currentState.push(...newValues), `Cannot push duplicates to a hasMany's state.`);
|
|
7204
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
7205
|
+
// dedupe
|
|
7206
|
+
const seen = new Set(target);
|
|
7207
|
+
const unique = new Set();
|
|
7208
|
+
args.forEach(item => {
|
|
7209
|
+
const identifier = recordIdentifierFor(item);
|
|
7210
|
+
if (!seen.has(identifier)) {
|
|
7211
|
+
seen.add(identifier);
|
|
7212
|
+
unique.add(item);
|
|
7213
|
+
}
|
|
7214
|
+
});
|
|
7215
|
+
const newArgs = Array.from(unique);
|
|
7216
|
+
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
7217
|
+
if (newArgs.length) {
|
|
7218
|
+
mutateAddToRelatedRecords(this, {
|
|
7219
|
+
value: extractIdentifiersFromRecords(newArgs)
|
|
7220
|
+
}, _SIGNAL);
|
|
7221
|
+
}
|
|
7222
|
+
return result;
|
|
7223
|
+
}
|
|
7224
|
+
|
|
7225
|
+
// else, no dedupe, error on duplicates
|
|
7226
|
+
const result = Reflect.apply(target[prop], receiver, args);
|
|
7227
|
+
if (newValues.length) {
|
|
7228
|
+
mutateAddToRelatedRecords(this, {
|
|
7229
|
+
value: newValues
|
|
7230
|
+
}, _SIGNAL);
|
|
7231
|
+
}
|
|
7232
|
+
return result;
|
|
7233
|
+
}
|
|
7234
|
+
case 'pop':
|
|
7235
|
+
{
|
|
7236
|
+
const result = Reflect.apply(target[prop], receiver, args);
|
|
7237
|
+
if (result) {
|
|
7238
|
+
mutateRemoveFromRelatedRecords(this, {
|
|
7239
|
+
value: recordIdentifierFor(result)
|
|
7240
|
+
}, _SIGNAL);
|
|
7241
|
+
}
|
|
7242
|
+
return result;
|
|
7243
|
+
}
|
|
7244
|
+
case 'unshift':
|
|
7245
|
+
{
|
|
7246
|
+
const newValues = extractIdentifiersFromRecords(args);
|
|
7247
|
+
assertNoDuplicates(this, target, currentState => currentState.unshift(...newValues), `Cannot unshift duplicates to a hasMany's state.`);
|
|
7248
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
7249
|
+
// dedupe
|
|
7250
|
+
const seen = new Set(target);
|
|
7251
|
+
const unique = new Set();
|
|
7252
|
+
args.forEach(item => {
|
|
7253
|
+
const identifier = recordIdentifierFor(item);
|
|
7254
|
+
if (!seen.has(identifier)) {
|
|
7255
|
+
seen.add(identifier);
|
|
7256
|
+
unique.add(item);
|
|
7257
|
+
}
|
|
7258
|
+
});
|
|
7259
|
+
const newArgs = Array.from(unique);
|
|
7260
|
+
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
7261
|
+
if (newArgs.length) {
|
|
7262
|
+
mutateAddToRelatedRecords(this, {
|
|
7263
|
+
value: extractIdentifiersFromRecords(newArgs),
|
|
7264
|
+
index: 0
|
|
7265
|
+
}, _SIGNAL);
|
|
7266
|
+
}
|
|
7267
|
+
return result;
|
|
7268
|
+
}
|
|
7269
|
+
|
|
7270
|
+
// else, no dedupe, error on duplicates
|
|
7271
|
+
const result = Reflect.apply(target[prop], receiver, args);
|
|
7272
|
+
if (newValues.length) {
|
|
7273
|
+
mutateAddToRelatedRecords(this, {
|
|
7274
|
+
value: newValues,
|
|
7275
|
+
index: 0
|
|
7276
|
+
}, _SIGNAL);
|
|
7277
|
+
}
|
|
7278
|
+
return result;
|
|
7279
|
+
}
|
|
7280
|
+
case 'shift':
|
|
7281
|
+
{
|
|
7282
|
+
const result = Reflect.apply(target[prop], receiver, args);
|
|
7283
|
+
if (result) {
|
|
7284
|
+
mutateRemoveFromRelatedRecords(this, {
|
|
7285
|
+
value: recordIdentifierFor(result),
|
|
7286
|
+
index: 0
|
|
7287
|
+
}, _SIGNAL);
|
|
7288
|
+
}
|
|
7289
|
+
return result;
|
|
7290
|
+
}
|
|
7291
|
+
case 'sort':
|
|
7292
|
+
{
|
|
7293
|
+
const result = Reflect.apply(target[prop], receiver, args);
|
|
7294
|
+
mutateSortRelatedRecords(this, result.map(recordIdentifierFor), _SIGNAL);
|
|
7295
|
+
return result;
|
|
7296
|
+
}
|
|
7297
|
+
case 'splice':
|
|
7298
|
+
{
|
|
7299
|
+
const [start, deleteCount, ...adds] = args;
|
|
7300
|
+
|
|
7301
|
+
// detect a full replace
|
|
7302
|
+
if (start === 0 && deleteCount === this[SOURCE].length) {
|
|
7303
|
+
const newValues = extractIdentifiersFromRecords(adds);
|
|
7304
|
+
assertNoDuplicates(this, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot replace a hasMany's state with a new state that contains duplicates.`);
|
|
7305
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
7306
|
+
// dedupe
|
|
7307
|
+
const current = new Set(adds);
|
|
7308
|
+
const unique = Array.from(current);
|
|
7309
|
+
const uniqueIdentifiers = Array.from(new Set(newValues));
|
|
7310
|
+
const newArgs = [start, deleteCount].concat(unique);
|
|
7311
|
+
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
7312
|
+
mutateReplaceRelatedRecords(this, uniqueIdentifiers, _SIGNAL);
|
|
7313
|
+
return result;
|
|
7314
|
+
}
|
|
7315
|
+
|
|
7316
|
+
// else, no dedupe, error on duplicates
|
|
7317
|
+
const result = Reflect.apply(target[prop], receiver, args);
|
|
7318
|
+
mutateReplaceRelatedRecords(this, newValues, _SIGNAL);
|
|
7319
|
+
return result;
|
|
7320
|
+
}
|
|
7321
|
+
const newValues = extractIdentifiersFromRecords(adds);
|
|
7322
|
+
assertNoDuplicates(this, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot splice a hasMany's state with a new state that contains duplicates.`);
|
|
7323
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
7324
|
+
// dedupe
|
|
7325
|
+
const currentState = target.slice();
|
|
7326
|
+
currentState.splice(start, deleteCount);
|
|
7327
|
+
const seen = new Set(currentState);
|
|
7328
|
+
const unique = [];
|
|
7329
|
+
adds.forEach(item => {
|
|
7330
|
+
const identifier = recordIdentifierFor(item);
|
|
7331
|
+
if (!seen.has(identifier)) {
|
|
7332
|
+
seen.add(identifier);
|
|
7333
|
+
unique.push(item);
|
|
7334
|
+
}
|
|
7335
|
+
});
|
|
7336
|
+
const newArgs = [start, deleteCount, ...unique];
|
|
7337
|
+
const result = Reflect.apply(target[prop], receiver, newArgs);
|
|
7338
|
+
if (deleteCount > 0) {
|
|
7339
|
+
mutateRemoveFromRelatedRecords(this, {
|
|
7340
|
+
value: result.map(recordIdentifierFor),
|
|
7341
|
+
index: start
|
|
7342
|
+
}, _SIGNAL);
|
|
7343
|
+
}
|
|
7344
|
+
if (unique.length > 0) {
|
|
7345
|
+
mutateAddToRelatedRecords(this, {
|
|
7346
|
+
value: extractIdentifiersFromRecords(unique),
|
|
7347
|
+
index: start
|
|
7348
|
+
}, _SIGNAL);
|
|
7349
|
+
}
|
|
7350
|
+
return result;
|
|
7351
|
+
}
|
|
7352
|
+
|
|
7353
|
+
// else, no dedupe, error on duplicates
|
|
7354
|
+
const result = Reflect.apply(target[prop], receiver, args);
|
|
7355
|
+
if (deleteCount > 0) {
|
|
7356
|
+
mutateRemoveFromRelatedRecords(this, {
|
|
7357
|
+
value: result.map(recordIdentifierFor),
|
|
7358
|
+
index: start
|
|
7359
|
+
}, _SIGNAL);
|
|
7360
|
+
}
|
|
7361
|
+
if (newValues.length > 0) {
|
|
7362
|
+
mutateAddToRelatedRecords(this, {
|
|
7363
|
+
value: newValues,
|
|
7364
|
+
index: start
|
|
7365
|
+
}, _SIGNAL);
|
|
7366
|
+
}
|
|
7367
|
+
return result;
|
|
7368
|
+
}
|
|
7369
|
+
default:
|
|
7370
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
7371
|
+
{
|
|
7372
|
+
throw new Error(`unable to convert ${prop} into a transaction that updates the cache state for this record array`);
|
|
7373
|
+
}
|
|
7374
|
+
})() : {};
|
|
7375
|
+
}
|
|
7376
|
+
}
|
|
7377
|
+
notify() {
|
|
7378
|
+
const signal = this[ARRAY_SIGNAL];
|
|
7379
|
+
signal.shouldReset = true;
|
|
7380
|
+
notifyArray(this);
|
|
7381
|
+
}
|
|
7382
|
+
|
|
7383
|
+
/**
|
|
7384
|
+
Reloads all of the records in the manyArray. If the manyArray
|
|
7385
|
+
holds a relationship that was originally fetched using a links url
|
|
7386
|
+
EmberData will revisit the original links url to repopulate the
|
|
7387
|
+
relationship.
|
|
7388
|
+
If the ManyArray holds the result of a `store.query()` reload will
|
|
7389
|
+
re-run the original query.
|
|
7390
|
+
Example
|
|
7391
|
+
```javascript
|
|
7392
|
+
let user = store.peekRecord('user', '1')
|
|
7393
|
+
await login(user);
|
|
7394
|
+
let permissions = await user.permissions;
|
|
7395
|
+
await permissions.reload();
|
|
7396
|
+
```
|
|
7397
|
+
@method reload
|
|
7398
|
+
@public
|
|
7399
|
+
*/
|
|
7400
|
+
reload(options) {
|
|
7401
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
7402
|
+
if (!test) {
|
|
7403
|
+
throw new Error(`Expected the manager for ManyArray to implement reloadHasMany`);
|
|
7404
|
+
}
|
|
7405
|
+
})(typeof this._manager.reloadHasMany === 'function') : {};
|
|
7406
|
+
// TODO this is odd, we don't ask the store for anything else like this?
|
|
7407
|
+
return this._manager.reloadHasMany(this.key, options);
|
|
7408
|
+
}
|
|
7409
|
+
|
|
7410
|
+
/**
|
|
7411
|
+
Saves all of the records in the `ManyArray`.
|
|
7412
|
+
Note: this API can only be used in legacy mode with a configured Adapter.
|
|
7413
|
+
Example
|
|
7414
|
+
```javascript
|
|
7415
|
+
const { content: { data: inbox } } = await store.request(findRecord({ type: 'inbox', id: '1' }));
|
|
7416
|
+
let messages = await inbox.messages;
|
|
7417
|
+
messages.forEach((message) => {
|
|
7418
|
+
message.isRead = true;
|
|
7419
|
+
});
|
|
7420
|
+
messages.save();
|
|
7421
|
+
```
|
|
7422
|
+
@method save
|
|
7423
|
+
@public
|
|
7424
|
+
@return {PromiseArray} promise
|
|
7425
|
+
*/
|
|
7426
|
+
|
|
7427
|
+
/**
|
|
7428
|
+
Create a child record within the owner
|
|
7429
|
+
@method createRecord
|
|
7430
|
+
@public
|
|
7431
|
+
@param {Object} hash
|
|
7432
|
+
@return {Model} record
|
|
7433
|
+
*/
|
|
7434
|
+
createRecord(hash) {
|
|
7435
|
+
const {
|
|
7436
|
+
store
|
|
7437
|
+
} = this;
|
|
7438
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
7439
|
+
if (!test) {
|
|
7440
|
+
throw new Error(`Expected modelName to be set`);
|
|
7441
|
+
}
|
|
7442
|
+
})(this.modelName) : {};
|
|
7443
|
+
const record = store.createRecord(this.modelName, hash);
|
|
7444
|
+
this.push(record);
|
|
7445
|
+
return record;
|
|
7446
|
+
}
|
|
7447
|
+
destroy() {
|
|
7448
|
+
super.destroy(false);
|
|
7449
|
+
}
|
|
7450
|
+
}
|
|
7451
|
+
RelatedCollection.prototype.isAsync = false;
|
|
7452
|
+
RelatedCollection.prototype.isPolymorphic = false;
|
|
7453
|
+
RelatedCollection.prototype.identifier = null;
|
|
7454
|
+
RelatedCollection.prototype.cache = null;
|
|
7455
|
+
RelatedCollection.prototype._inverseIsAsync = false;
|
|
7456
|
+
RelatedCollection.prototype.key = '';
|
|
7457
|
+
RelatedCollection.prototype.DEPRECATED_CLASS_NAME = 'ManyArray';
|
|
7458
|
+
function assertRecordPassedToHasMany(record) {
|
|
7459
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
7460
|
+
if (!test) {
|
|
7461
|
+
throw new Error(`All elements of a hasMany relationship must be instances of Model, you passed ${typeof record}`);
|
|
7462
|
+
}
|
|
7463
|
+
})(function () {
|
|
7464
|
+
try {
|
|
7465
|
+
recordIdentifierFor(record);
|
|
7466
|
+
return true;
|
|
7467
|
+
} catch {
|
|
7468
|
+
return false;
|
|
7469
|
+
}
|
|
7470
|
+
}()) : {};
|
|
7471
|
+
}
|
|
7472
|
+
function extractIdentifiersFromRecords(records) {
|
|
7473
|
+
return records.map(extractIdentifierFromRecord);
|
|
7474
|
+
}
|
|
7475
|
+
function extractIdentifierFromRecord(recordOrPromiseRecord) {
|
|
7476
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_PROMISE_PROXIES)) {
|
|
7477
|
+
if (isPromiseRecord(recordOrPromiseRecord)) {
|
|
7478
|
+
const content = recordOrPromiseRecord.content;
|
|
7479
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
7480
|
+
if (!test) {
|
|
7481
|
+
throw new Error('You passed in a promise that did not originate from an EmberData relationship. You can only pass promises that come from a belongsTo relationship.');
|
|
7482
|
+
}
|
|
7483
|
+
})(content !== undefined && content !== null) : {};
|
|
7484
|
+
deprecate(`You passed in a PromiseProxy to a Relationship API that now expects a resolved value. await the value before setting it.`, false, {
|
|
7485
|
+
id: 'ember-data-mirror:deprecate-promise-proxies',
|
|
7486
|
+
until: '5.0',
|
|
7487
|
+
since: {
|
|
7488
|
+
enabled: '4.7',
|
|
7489
|
+
available: '4.7'
|
|
7490
|
+
},
|
|
7491
|
+
for: 'ember-data-mirror'
|
|
7492
|
+
});
|
|
7493
|
+
assertRecordPassedToHasMany(content);
|
|
7494
|
+
return recordIdentifierFor(content);
|
|
7495
|
+
}
|
|
7496
|
+
}
|
|
7497
|
+
assertRecordPassedToHasMany(recordOrPromiseRecord);
|
|
7498
|
+
return recordIdentifierFor(recordOrPromiseRecord);
|
|
7499
|
+
}
|
|
7500
|
+
function isPromiseRecord(record) {
|
|
7501
|
+
return Boolean(typeof record === 'object' && record && 'then' in record);
|
|
7502
|
+
}
|
|
7503
|
+
function assertNoDuplicates(collection, target, callback, reason) {
|
|
7504
|
+
const state = target.slice();
|
|
7505
|
+
callback(state);
|
|
7506
|
+
if (state.length !== new Set(state).size) {
|
|
7507
|
+
const duplicates = state.filter((currentValue, currentIndex) => state.indexOf(currentValue) !== currentIndex);
|
|
7508
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
|
|
7509
|
+
deprecate(`${reason} This behavior is deprecated. Found duplicates for the following records within the new state provided to \`<${collection.identifier.type}:${collection.identifier.id || collection.identifier.lid}>.${collection.key}\`\n\t- ${Array.from(new Set(duplicates)).map(r => isStableIdentifier(r) ? r.lid : recordIdentifierFor(r).lid).sort((a, b) => a.localeCompare(b)).join('\n\t- ')}`, /* inline-macro-config */getGlobalConfig().WarpDriveMirror.deprecations.DISABLE_6X_DEPRECATIONS, {
|
|
7510
|
+
id: 'ember-data-mirror:deprecate-many-array-duplicates',
|
|
7511
|
+
for: 'ember-data-mirror',
|
|
7512
|
+
until: '6.0',
|
|
7513
|
+
since: {
|
|
7514
|
+
enabled: '5.3',
|
|
7515
|
+
available: '4.13'
|
|
7516
|
+
}
|
|
7517
|
+
});
|
|
7518
|
+
} else {
|
|
7519
|
+
throw new Error(`${reason} Found duplicates for the following records within the new state provided to \`<${collection.identifier.type}:${collection.identifier.id || collection.identifier.lid}>.${collection.key}\`\n\t- ${Array.from(new Set(duplicates)).map(r => isStableIdentifier(r) ? r.lid : recordIdentifierFor(r).lid).sort((a, b) => a.localeCompare(b)).join('\n\t- ')}`);
|
|
7520
|
+
}
|
|
7521
|
+
}
|
|
7522
|
+
}
|
|
7523
|
+
function mutateAddToRelatedRecords(collection, operationInfo, _SIGNAL) {
|
|
7524
|
+
mutate(collection, {
|
|
7525
|
+
op: 'addToRelatedRecords',
|
|
7526
|
+
record: collection.identifier,
|
|
7527
|
+
field: collection.key,
|
|
7528
|
+
...operationInfo
|
|
7529
|
+
}, _SIGNAL);
|
|
7530
|
+
}
|
|
7531
|
+
function mutateRemoveFromRelatedRecords(collection, operationInfo, _SIGNAL) {
|
|
7532
|
+
mutate(collection, {
|
|
7533
|
+
op: 'removeFromRelatedRecords',
|
|
7534
|
+
record: collection.identifier,
|
|
7535
|
+
field: collection.key,
|
|
7536
|
+
...operationInfo
|
|
7537
|
+
}, _SIGNAL);
|
|
7538
|
+
}
|
|
7539
|
+
function mutateReplaceRelatedRecord(collection, operationInfo, _SIGNAL) {
|
|
7540
|
+
mutate(collection, {
|
|
7541
|
+
op: 'replaceRelatedRecord',
|
|
7542
|
+
record: collection.identifier,
|
|
7543
|
+
field: collection.key,
|
|
7544
|
+
...operationInfo
|
|
7545
|
+
}, _SIGNAL);
|
|
7546
|
+
}
|
|
7547
|
+
function mutateReplaceRelatedRecords(collection, value, _SIGNAL) {
|
|
7548
|
+
mutate(collection, {
|
|
7549
|
+
op: 'replaceRelatedRecords',
|
|
7550
|
+
record: collection.identifier,
|
|
7551
|
+
field: collection.key,
|
|
7552
|
+
value
|
|
7553
|
+
}, _SIGNAL);
|
|
7554
|
+
}
|
|
7555
|
+
function mutateSortRelatedRecords(collection, value, _SIGNAL) {
|
|
7556
|
+
mutate(collection, {
|
|
7557
|
+
op: 'sortRelatedRecords',
|
|
7558
|
+
record: collection.identifier,
|
|
7559
|
+
field: collection.key,
|
|
7560
|
+
value
|
|
7561
|
+
}, _SIGNAL);
|
|
7562
|
+
}
|
|
7563
|
+
function mutate(collection, mutation, _SIGNAL) {
|
|
7564
|
+
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
7565
|
+
if (!test) {
|
|
7566
|
+
throw new Error(`Expected the manager for ManyArray to implement mutate`);
|
|
7567
|
+
}
|
|
7568
|
+
})(typeof collection._manager.mutate === 'function') : {};
|
|
7569
|
+
collection._manager.mutate(mutation);
|
|
7570
|
+
addToTransaction(_SIGNAL);
|
|
7571
|
+
}
|
|
7572
|
+
|
|
7573
|
+
/**
|
|
7574
|
+
@module @ember-data-mirror/store
|
|
7575
|
+
*/
|
|
7576
|
+
|
|
6885
7577
|
/**
|
|
6886
7578
|
This method normalizes a modelName into the format EmberData uses
|
|
6887
7579
|
internally by dasherizing it.
|
|
@@ -6895,7 +7587,7 @@ function fetchContentAndHydrate(next, context, identifier, priority) {
|
|
|
6895
7587
|
@return {String} normalizedModelName
|
|
6896
7588
|
*/
|
|
6897
7589
|
function normalizeModelName(modelName) {
|
|
6898
|
-
if (macroCondition(getGlobalConfig().
|
|
7590
|
+
if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_HELPERS)) {
|
|
6899
7591
|
deprecate(`the helper function normalizeModelName is deprecated. You should use model names that are already normalized, or use string helpers of your own. This function is primarily an alias for dasherize from @ember/string.`, false, {
|
|
6900
7592
|
id: 'ember-data-mirror:deprecate-normalize-modelname-helper',
|
|
6901
7593
|
for: 'ember-data-mirror',
|
|
@@ -6909,4 +7601,4 @@ function normalizeModelName(modelName) {
|
|
|
6909
7601
|
}
|
|
6910
7602
|
assert(`normalizeModelName support has been removed`);
|
|
6911
7603
|
}
|
|
6912
|
-
export { ARRAY_SIGNAL as A, CacheHandler as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, _clearCaches as _, setIdentifierGenerationMethod as a, setIdentifierUpdateMethod as b, setIdentifierForgetMethod as c, setIdentifierResetMethod as d, setKeyInfoForResource as e, constructResource as f, coerceId as g, ensureStringId as h, isStableIdentifier as i, Collection as j, notifyArray as k, SOURCE as l, fastPush as m, normalizeModelName as n, removeRecordDataFor as o, peekCache as p, setRecordIdentifier as q, recordIdentifierFor as r, storeFor as s, StoreMap as t, setCacheFor as u };
|
|
7604
|
+
export { ARRAY_SIGNAL as A, CacheHandler as C, IdentifierArray as I, MUTATE as M, RecordArrayManager as R, Store as S, _clearCaches as _, setIdentifierGenerationMethod as a, setIdentifierUpdateMethod as b, setIdentifierForgetMethod as c, setIdentifierResetMethod as d, setKeyInfoForResource as e, constructResource as f, coerceId as g, ensureStringId as h, isStableIdentifier as i, Collection as j, notifyArray as k, SOURCE as l, fastPush as m, normalizeModelName as n, removeRecordDataFor as o, peekCache as p, setRecordIdentifier as q, recordIdentifierFor as r, storeFor as s, StoreMap as t, setCacheFor as u, RelatedCollection as v, log as w, logGroup as x };
|